#define APB1_LOG_SIZE SZ_16K
-/* Number of bulk in and bulk out couple */
-#define NUM_BULKS 1
-
-/* Expected number of bulk out endpoints */
-#define NUM_BULKS_OUT NUM_BULKS
-
-/* Expected number of bulk in endpoints (including ARPC endpoint) */
-#define NUM_BULKS_IN (NUM_BULKS + 1)
-
/*
* 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
/* Number of CPort OUT urbs in flight at any point in time.
* Adjust if we get messages saying we are out of urbs in the system log.
*/
-#define NUM_CPORT_OUT_URB (8 * NUM_BULKS)
+#define NUM_CPORT_OUT_URB 8
/*
* Number of ARPC in urbs in flight at any point in time.
u8 *buffer[NUM_CPORT_IN_URB];
};
-/*
- * @endpoint: bulk out endpoint for CPort data
- */
-struct es2_cport_out {
- __u8 endpoint;
-};
-
/**
* es2_ap_dev - ES2 USB Bridge to AP structure
* @usb_dev: pointer to the USB device we are.
* @hd: pointer to our gb_host_device structure
* @cport_in: endpoint, urbs and buffer for cport in messages
- * @cport_out: endpoint for for cport out messages
+ * @cport_out_endpoint: endpoint for for cport out messages
* @cport_out_urb: array of urbs for the CPort out messages
* @cport_out_urb_busy: array of flags to see if the @cport_out_urb is busy or
* not.
struct usb_interface *usb_intf;
struct gb_host_device *hd;
- struct es2_cport_in cport_in[NUM_BULKS];
- struct es2_cport_out cport_out[NUM_BULKS];
+ struct es2_cport_in cport_in;
+ __u8 cport_out_endpoint;
struct urb *cport_out_urb[NUM_CPORT_OUT_URB];
bool cport_out_urb_busy[NUM_CPORT_OUT_URB];
bool cport_out_urb_cancelled[NUM_CPORT_OUT_URB];
usb_fill_bulk_urb(urb, udev,
usb_sndbulkpipe(udev,
- es2->cport_out[0].endpoint),
+ es2->cport_out_endpoint),
message->buffer, buffer_size,
cport_out_callback, message);
urb->transfer_flags |= URB_ZERO_PACKET;
static void es2_destroy(struct es2_ap_dev *es2)
{
struct usb_device *udev;
- int bulk_in;
+ struct urb *urb;
int i;
debugfs_remove(es2->apb_log_enable_dentry);
/* Tear down everything! */
for (i = 0; i < NUM_CPORT_OUT_URB; ++i) {
- struct urb *urb = es2->cport_out_urb[i];
-
- if (!urb)
- break;
+ urb = es2->cport_out_urb[i];
usb_kill_urb(urb);
usb_free_urb(urb);
es2->cport_out_urb[i] = NULL;
}
for (i = 0; i < NUM_ARPC_IN_URB; ++i) {
- struct urb *urb = es2->arpc_urb[i];
-
- if (!urb)
- break;
- usb_free_urb(urb);
+ usb_free_urb(es2->arpc_urb[i]);
kfree(es2->arpc_buffer[i]);
es2->arpc_buffer[i] = NULL;
}
- for (bulk_in = 0; bulk_in < NUM_BULKS; bulk_in++) {
- struct es2_cport_in *cport_in = &es2->cport_in[bulk_in];
-
- for (i = 0; i < NUM_CPORT_IN_URB; ++i) {
- struct urb *urb = cport_in->urb[i];
-
- if (!urb)
- break;
- usb_free_urb(urb);
- kfree(cport_in->buffer[i]);
- cport_in->buffer[i] = NULL;
- }
+ for (i = 0; i < NUM_CPORT_IN_URB; ++i) {
+ usb_free_urb(es2->cport_in.urb[i]);
+ kfree(es2->cport_in.buffer[i]);
+ es2->cport_in.buffer[i] = NULL;
}
/* release reserved CDSI0 and CDSI1 cports */
struct usb_device *udev;
struct usb_host_interface *iface_desc;
struct usb_endpoint_descriptor *endpoint;
- int bulk_in = 0;
- int bulk_out = 0;
+ __u8 ep_addr;
int retval;
int i;
int num_cports;
+ bool bulk_out_found = false;
+ bool bulk_in_found = false;
+ bool arpc_in_found = false;
udev = usb_get_dev(interface_to_usbdev(interface));
iface_desc = interface->cur_altsetting;
for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
endpoint = &iface_desc->endpoint[i].desc;
+ ep_addr = endpoint->bEndpointAddress;
if (usb_endpoint_is_bulk_in(endpoint)) {
- if (bulk_in < NUM_BULKS)
- es2->cport_in[bulk_in].endpoint =
- endpoint->bEndpointAddress;
- else
- es2->arpc_endpoint_in =
- endpoint->bEndpointAddress;
- bulk_in++;
- } else if (usb_endpoint_is_bulk_out(endpoint)) {
- es2->cport_out[bulk_out++].endpoint =
- endpoint->bEndpointAddress;
- } else {
- dev_err(&udev->dev,
- "Unknown endpoint type found, address 0x%02x\n",
- endpoint->bEndpointAddress);
+ if (!bulk_in_found) {
+ es2->cport_in.endpoint = ep_addr;
+ bulk_in_found = true;
+ } else if (!arpc_in_found) {
+ es2->arpc_endpoint_in = ep_addr;
+ arpc_in_found = true;
+ } else {
+ dev_warn(&udev->dev,
+ "Unused bulk IN endpoint found: 0x%02x\n",
+ ep_addr);
+ }
+ continue;
+ }
+ if (usb_endpoint_is_bulk_out(endpoint)) {
+ if (!bulk_out_found) {
+ es2->cport_out_endpoint = ep_addr;
+ bulk_out_found = true;
+ } else {
+ dev_warn(&udev->dev,
+ "Unused bulk OUT endpoint found: 0x%02x\n",
+ ep_addr);
+ }
+ continue;
}
+ dev_warn(&udev->dev,
+ "Unknown endpoint type found, address 0x%02x\n",
+ ep_addr);
}
- if (bulk_in != NUM_BULKS_IN || bulk_out != NUM_BULKS_OUT) {
+ if (!bulk_in_found || !arpc_in_found || !bulk_out_found) {
dev_err(&udev->dev, "Not enough endpoints found in device, aborting!\n");
retval = -ENODEV;
goto error;
}
/* Allocate buffers for our cport in messages */
- for (bulk_in = 0; bulk_in < NUM_BULKS; bulk_in++) {
- struct es2_cport_in *cport_in = &es2->cport_in[bulk_in];
-
- for (i = 0; i < NUM_CPORT_IN_URB; ++i) {
- struct urb *urb;
- u8 *buffer;
+ for (i = 0; i < NUM_CPORT_IN_URB; ++i) {
+ struct urb *urb;
+ u8 *buffer;
- urb = usb_alloc_urb(0, GFP_KERNEL);
- if (!urb) {
- retval = -ENOMEM;
- goto error;
- }
- cport_in->urb[i] = urb;
+ urb = usb_alloc_urb(0, GFP_KERNEL);
+ if (!urb) {
+ retval = -ENOMEM;
+ goto error;
+ }
+ es2->cport_in.urb[i] = urb;
- buffer = kmalloc(ES2_GBUF_MSG_SIZE_MAX, GFP_KERNEL);
- if (!buffer) {
- retval = -ENOMEM;
- goto error;
- }
+ buffer = kmalloc(ES2_GBUF_MSG_SIZE_MAX, GFP_KERNEL);
+ if (!buffer) {
+ retval = -ENOMEM;
+ goto error;
+ }
- usb_fill_bulk_urb(urb, udev,
- usb_rcvbulkpipe(udev,
- cport_in->endpoint),
- buffer, ES2_GBUF_MSG_SIZE_MAX,
- cport_in_callback, hd);
+ usb_fill_bulk_urb(urb, udev,
+ usb_rcvbulkpipe(udev, es2->cport_in.endpoint),
+ buffer, ES2_GBUF_MSG_SIZE_MAX,
+ cport_in_callback, hd);
- cport_in->buffer[i] = buffer;
- }
+ es2->cport_in.buffer[i] = buffer;
}
/* Allocate buffers for ARPC in messages */
if (retval)
goto err_disable_arpc_in;
- for (i = 0; i < NUM_BULKS; ++i) {
- retval = es2_cport_in_enable(es2, &es2->cport_in[i]);
- if (retval)
- goto err_disable_cport_in;
- }
+ retval = es2_cport_in_enable(es2, &es2->cport_in);
+ if (retval)
+ goto err_hd_del;
return 0;
-err_disable_cport_in:
- for (--i; i >= 0; --i)
- es2_cport_in_disable(es2, &es2->cport_in[i]);
+err_hd_del:
gb_hd_del(hd);
err_disable_arpc_in:
es2_arpc_in_disable(es2);
static void ap_disconnect(struct usb_interface *interface)
{
struct es2_ap_dev *es2 = usb_get_intfdata(interface);
- int i;
gb_hd_del(es2->hd);
- for (i = 0; i < NUM_BULKS; ++i)
- es2_cport_in_disable(es2, &es2->cport_in[i]);
+ es2_cport_in_disable(es2, &es2->cport_in);
es2_arpc_in_disable(es2);
es2_destroy(es2);