62 #include <linux/bitmap.h>
63 #include <linux/slab.h>
64 #include <linux/export.h>
69 static int __rpipe_get_descr(
struct wahc *wa,
85 dev_err(dev,
"rpipe %u: get descriptor failed: %d\n",
89 if (result <
sizeof(*descr)) {
90 dev_err(dev,
"rpipe %u: got short descriptor "
91 "(%zd vs %zd bytes needed)\n",
92 index, result,
sizeof(*descr));
107 static int __rpipe_set_descr(
struct wahc *wa,
123 dev_err(dev,
"rpipe %u: set descriptor failed: %d\n",
127 if (result <
sizeof(*descr)) {
128 dev_err(dev,
"rpipe %u: sent short descriptor "
129 "(%zd vs %zd bytes required)\n",
130 index, result,
sizeof(*descr));
141 static void rpipe_init(
struct wa_rpipe *rpipe)
143 kref_init(&rpipe->
refcnt);
148 static unsigned rpipe_get_idx(
struct wahc *wa,
unsigned rpipe_idx)
154 if (rpipe_idx < wa->rpipes)
161 static void rpipe_put_idx(
struct wahc *wa,
unsigned rpipe_idx)
177 rpipe_put_idx(rpipe->
wa, index);
193 static int rpipe_get_idle(
struct wa_rpipe **prpipe,
struct wahc *wa,
u8 crs,
201 rpipe = kzalloc(
sizeof(*rpipe), gfp);
207 for (rpipe_idx = 0; rpipe_idx < wa->
rpipes; rpipe_idx++) {
208 rpipe_idx = rpipe_get_idx(wa, rpipe_idx);
209 if (rpipe_idx >= wa->
rpipes)
211 result = __rpipe_get_descr(wa, &rpipe->
descr, rpipe_idx);
213 dev_err(dev,
"Can't get descriptor for rpipe %u: %d\n",
215 else if ((rpipe->
descr.bmCharacteristics & crs) != 0)
217 rpipe_put_idx(wa, rpipe_idx);
225 rpipe->
wa = wa_get(wa);
230 static int __rpipe_reset(
struct wahc *wa,
unsigned index)
239 0, index,
NULL, 0, 1000 );
241 dev_err(dev,
"rpipe %u: reset failed: %d\n",
252 .bLength =
sizeof(epc0),
264 struct device *dev,
struct usb_host_endpoint *ep)
271 if (ep->desc.bEndpointAddress == 0) {
276 itr_size = ep->extralen;
278 while (itr_size > 0) {
279 if (itr_size <
sizeof(*hdr)) {
280 dev_err(dev,
"HW Bug? ep 0x%02x: extra descriptors "
281 "at offset %zu: only %zu bytes left\n",
282 ep->
desc.bEndpointAddress,
283 itr - (
void *) ep->extra, itr_size);
292 dev_err(dev,
"HW Bug? ep 0x%02x: extra descriptor "
293 "at offset %zu (type 0x%02x) "
294 "length %d but only %zu bytes left\n",
295 ep->
desc.bEndpointAddress,
313 static int rpipe_aim(
struct wa_rpipe *rpipe,
struct wahc *wa,
314 struct usb_host_endpoint *ep,
struct urb *
urb,
gfp_t gfp)
318 struct usb_device *usb_dev = urb->dev;
322 epcd = rpipe_epc_find(dev, ep);
324 dev_err(dev,
"ep 0x%02x: can't find companion descriptor\n",
325 ep->
desc.bEndpointAddress);
328 unauth = usb_dev->wusb && !usb_dev->authenticated ? 0x80 : 0;
336 rpipe->
descr.bHSHubAddress = 0;
337 rpipe->
descr.bHSHubPort = wusb_port_no_to_idx(urb->dev->portnum);
339 rpipe->
descr.bSpeed = usb_pipeendpoint(urb->pipe) == 0 ?
342 dev_dbg(dev,
"addr %u (0x%02x) rpipe #%u ep# %u speed %d\n",
343 urb->dev->devnum, urb->dev->devnum | unauth,
345 usb_pipeendpoint(urb->pipe), rpipe->
descr.bSpeed);
348 if (
unlikely(urb->dev->devnum == 0x80))
349 rpipe->
descr.bDeviceAddress = 0;
351 rpipe->
descr.bDeviceAddress = urb->dev->devnum | unauth;
352 rpipe->
descr.bEndpointAddress = ep->desc.bEndpointAddress;
354 rpipe->
descr.bDataSequence = 0;
359 rpipe->
descr.bInterval = ep->desc.bInterval;
361 rpipe->
descr.bOverTheAirInterval = 0;
363 rpipe->
descr.bmAttribute = ep->desc.bmAttributes & 0x03;
366 rpipe->
descr.bmRetryOptions = 15;
368 rpipe->
descr.wNumTransactionErrors = 0;
369 result = __rpipe_set_descr(wa, &rpipe->
descr,
372 dev_err(dev,
"Cannot aim rpipe: %d\n", result);
386 static int rpipe_check_aim(
const struct wa_rpipe *rpipe,
const struct wahc *wa,
387 const struct usb_host_endpoint *ep,
388 const struct urb *urb,
gfp_t gfp)
392 struct usb_device *usb_dev = urb->dev;
393 u8 unauth = (usb_dev->wusb && !usb_dev->authenticated) ? 0x80 : 0;
394 u8 portnum = wusb_port_no_to_idx(urb->dev->portnum);
396 #define AIM_CHECK(rdf, val, text) \
398 if (rpipe->descr.rdf != (val)) { \
400 "rpipe aim discrepancy: " #rdf " " text "\n", \
401 rpipe->descr.rdf, (val)); \
433 struct urb *urb,
gfp_t gfp)
444 result = rpipe_check_aim(rpipe, wa, ep, urb, gfp);
449 dev_dbg(dev,
"ep 0x%02x: reusing rpipe %u\n",
450 ep->
desc.bEndpointAddress,
455 eptype = ep->desc.bmAttributes & 0x03;
456 result = rpipe_get_idle(&rpipe, wa, 1 << eptype, gfp);
459 result = rpipe_aim(rpipe, wa, ep, urb, gfp);
467 dev_dbg(dev,
"ep 0x%02x: using rpipe %u\n",
468 ep->
desc.bEndpointAddress,
497 dev_err(dev,
"BUG: pipes not released on exit: %s\n", buf);
525 0, index,
NULL, 0, 1000 );