{
return gb_connection_create_range(bundle->intf->hd, bundle,
&bundle->dev, cport_id, protocol_id,
- 0, CPORT_ID_MAX);
+ 0, bundle->intf->hd->num_cports - 1);
}
/*
struct greybus_host_device *greybus_create_hd(struct greybus_host_driver *driver,
struct device *parent,
- size_t buffer_size_max)
+ size_t buffer_size_max,
+ size_t num_cports)
{
struct greybus_host_device *hd;
return NULL;
}
+ if (num_cports == 0 || num_cports > CPORT_ID_MAX) {
+ dev_err(parent, "Invalid number of CPorts: %zu\n", num_cports);
+ return ERR_PTR(-EINVAL);
+ }
+
/*
* Make sure to never allocate messages larger than what the Greybus
* protocol supports.
INIT_LIST_HEAD(&hd->connections);
ida_init(&hd->cport_id_map);
hd->buffer_size_max = buffer_size_max;
+ hd->num_cports = num_cports;
/*
* Initialize AP's SVC protocol connection:
static struct task_struct *apb1_log_task;
static DEFINE_KFIFO(apb1_log_fifo, char, APB1_LOG_SIZE);
+/* Number of CPorts supported by es1 */
+#define CPORT_COUNT 256
+
/*
* Number of CPort IN urbs in flight at any point in time.
* Adjust if we are having stalls in the USB buffer due to not enough urbs in
* of where the data should be sent. Do one last check of
* the target CPort id before filling it in.
*/
- if (!cport_id_valid(cport_id)) {
+ if (!cport_id_valid(hd, cport_id)) {
pr_err("invalid destination cport 0x%02x\n", cport_id);
return -EINVAL;
}
header = urb->transfer_buffer;
cport_id = gb_message_cport_unpack(header);
- if (cport_id_valid(cport_id))
+ if (cport_id_valid(hd, cport_id))
greybus_data_rcvd(hd, cport_id, urb->transfer_buffer,
urb->actual_length);
else
udev = usb_get_dev(interface_to_usbdev(interface));
- hd = greybus_create_hd(&es1_driver, &udev->dev, ES1_GBUF_MSG_SIZE_MAX);
+ hd = greybus_create_hd(&es1_driver, &udev->dev, ES1_GBUF_MSG_SIZE_MAX,
+ CPORT_COUNT);
if (IS_ERR(hd)) {
usb_put_dev(udev);
return PTR_ERR(hd);
static int cport_to_ep(struct es1_ap_dev *es1, u16 cport_id)
{
- if (cport_id >= CPORT_COUNT)
+ if (cport_id >= es1->hd->num_cports)
return 0;
return es1->cport_to_ep[cport_id];
}
{
int i;
- for (i = 0; i < CPORT_COUNT; i++) {
+ for (i = 0; i < es1->hd->num_cports; i++) {
if (es1->cport_to_ep[i] == bulk_ep_set)
return 1;
}
if (bulk_ep_set == 0 || bulk_ep_set >= NUM_BULKS)
return -EINVAL;
- if (cport_id >= CPORT_COUNT)
+ if (cport_id >= es1->hd->num_cports)
return -EINVAL;
if (bulk_ep_set && ep_in_use(es1, bulk_ep_set))
return -EINVAL;
* of where the data should be sent. Do one last check of
* the target CPort id before filling it in.
*/
- if (!cport_id_valid(cport_id)) {
+ if (!cport_id_valid(hd, cport_id)) {
pr_err("invalid destination cport 0x%02x\n", cport_id);
return -EINVAL;
}
header = urb->transfer_buffer;
cport_id = gb_message_cport_unpack(header);
- if (cport_id_valid(cport_id))
+ if (cport_id_valid(hd, cport_id))
greybus_data_rcvd(hd, cport_id, urb->transfer_buffer,
urb->actual_length);
else
udev = usb_get_dev(interface_to_usbdev(interface));
- hd = greybus_create_hd(&es1_driver, &udev->dev, ES1_GBUF_MSG_SIZE_MAX);
+ hd = greybus_create_hd(&es1_driver, &udev->dev, ES1_GBUF_MSG_SIZE_MAX,
+ CPORT_COUNT);
if (IS_ERR(hd)) {
usb_put_dev(udev);
return PTR_ERR(hd);
struct ida cport_id_map;
u8 device_id;
+ /* Number of CPorts supported by the UniPro IP */
+ size_t num_cports;
+
/* Host device buffer constraints */
size_t buffer_size_max;
struct greybus_host_device *greybus_create_hd(struct greybus_host_driver *hd,
struct device *parent,
- size_t buffer_size_max);
+ size_t buffer_size_max,
+ size_t num_cports);
int greybus_endo_setup(struct greybus_host_device *hd, u16 endo_id,
u8 ap_intf_id);
void greybus_remove_hd(struct greybus_host_device *hd);
return dev->type == &greybus_connection_type;
}
-static inline bool cport_id_valid(u16 cport_id)
+static inline bool cport_id_valid(struct greybus_host_device *hd, u16 cport_id)
{
- return cport_id != CPORT_ID_BAD && cport_id <= CPORT_ID_MAX;
+ return cport_id != CPORT_ID_BAD && cport_id < hd->num_cports;
}
#endif /* __KERNEL__ */
bundle_id = GB_CONTROL_BUNDLE_ID;
cport_id = GB_CONTROL_CPORT_ID;
ida_start = 0;
- ida_end = CPORT_ID_MAX;
+ ida_end = intf->hd->num_cports - 1;
} else if (class == GREYBUS_CLASS_SVC) {
protocol_id = GREYBUS_PROTOCOL_SVC;
bundle_id = GB_SVC_BUNDLE_ID;