wa-rpipe.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. /*
  2. * WUSB Wire Adapter
  3. * rpipe management
  4. *
  5. * Copyright (C) 2005-2006 Intel Corporation
  6. * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License version
  10. * 2 as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  20. * 02110-1301, USA.
  21. *
  22. *
  23. * FIXME: docs
  24. *
  25. * RPIPE
  26. *
  27. * Targetted at different downstream endpoints
  28. *
  29. * Descriptor: use to config the remote pipe.
  30. *
  31. * The number of blocks could be dynamic (wBlocks in descriptor is
  32. * 0)--need to schedule them then.
  33. *
  34. * Each bit in wa->rpipe_bm represents if an rpipe is being used or
  35. * not. Rpipes are represented with a 'struct wa_rpipe' that is
  36. * attached to the hcpriv member of a 'struct usb_host_endpoint'.
  37. *
  38. * When you need to xfer data to an endpoint, you get an rpipe for it
  39. * with wa_ep_rpipe_get(), which gives you a reference to the rpipe
  40. * and keeps a single one (the first one) with the endpoint. When you
  41. * are done transferring, you drop that reference. At the end the
  42. * rpipe is always allocated and bound to the endpoint. There it might
  43. * be recycled when not used.
  44. *
  45. * Addresses:
  46. *
  47. * We use a 1:1 mapping mechanism between port address (0 based
  48. * index, actually) and the address. The USB stack knows about this.
  49. *
  50. * USB Stack port number 4 (1 based)
  51. * WUSB code port index 3 (0 based)
  52. * USB Addresss 5 (2 based -- 0 is for default, 1 for root hub)
  53. *
  54. * Now, because we don't use the concept as default address exactly
  55. * like the (wired) USB code does, we need to kind of skip it. So we
  56. * never take addresses from the urb->pipe, but from the
  57. * urb->dev->devnum, to make sure that we always have the right
  58. * destination address.
  59. */
  60. #include <linux/init.h>
  61. #include <asm/atomic.h>
  62. #include <linux/bitmap.h>
  63. #include "wusbhc.h"
  64. #include "wa-hc.h"
  65. #define D_LOCAL 0
  66. #include <linux/uwb/debug.h>
  67. static int __rpipe_get_descr(struct wahc *wa,
  68. struct usb_rpipe_descriptor *descr, u16 index)
  69. {
  70. ssize_t result;
  71. struct device *dev = &wa->usb_iface->dev;
  72. /* Get the RPIPE descriptor -- we cannot use the usb_get_descriptor()
  73. * function because the arguments are different.
  74. */
  75. d_printf(1, dev, "rpipe %u: get descr\n", index);
  76. result = usb_control_msg(
  77. wa->usb_dev, usb_rcvctrlpipe(wa->usb_dev, 0),
  78. USB_REQ_GET_DESCRIPTOR,
  79. USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_RPIPE,
  80. USB_DT_RPIPE<<8, index, descr, sizeof(*descr),
  81. 1000 /* FIXME: arbitrary */);
  82. if (result < 0) {
  83. dev_err(dev, "rpipe %u: get descriptor failed: %d\n",
  84. index, (int)result);
  85. goto error;
  86. }
  87. if (result < sizeof(*descr)) {
  88. dev_err(dev, "rpipe %u: got short descriptor "
  89. "(%zd vs %zd bytes needed)\n",
  90. index, result, sizeof(*descr));
  91. result = -EINVAL;
  92. goto error;
  93. }
  94. result = 0;
  95. error:
  96. return result;
  97. }
  98. /*
  99. *
  100. * The descriptor is assumed to be properly initialized (ie: you got
  101. * it through __rpipe_get_descr()).
  102. */
  103. static int __rpipe_set_descr(struct wahc *wa,
  104. struct usb_rpipe_descriptor *descr, u16 index)
  105. {
  106. ssize_t result;
  107. struct device *dev = &wa->usb_iface->dev;
  108. /* we cannot use the usb_get_descriptor() function because the
  109. * arguments are different.
  110. */
  111. d_printf(1, dev, "rpipe %u: set descr\n", index);
  112. result = usb_control_msg(
  113. wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0),
  114. USB_REQ_SET_DESCRIPTOR,
  115. USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_RPIPE,
  116. USB_DT_RPIPE<<8, index, descr, sizeof(*descr),
  117. HZ / 10);
  118. if (result < 0) {
  119. dev_err(dev, "rpipe %u: set descriptor failed: %d\n",
  120. index, (int)result);
  121. goto error;
  122. }
  123. if (result < sizeof(*descr)) {
  124. dev_err(dev, "rpipe %u: sent short descriptor "
  125. "(%zd vs %zd bytes required)\n",
  126. index, result, sizeof(*descr));
  127. result = -EINVAL;
  128. goto error;
  129. }
  130. result = 0;
  131. error:
  132. return result;
  133. }
  134. static void rpipe_init(struct wa_rpipe *rpipe)
  135. {
  136. kref_init(&rpipe->refcnt);
  137. spin_lock_init(&rpipe->seg_lock);
  138. INIT_LIST_HEAD(&rpipe->seg_list);
  139. }
  140. static unsigned rpipe_get_idx(struct wahc *wa, unsigned rpipe_idx)
  141. {
  142. unsigned long flags;
  143. spin_lock_irqsave(&wa->rpipe_bm_lock, flags);
  144. rpipe_idx = find_next_zero_bit(wa->rpipe_bm, wa->rpipes, rpipe_idx);
  145. if (rpipe_idx < wa->rpipes)
  146. set_bit(rpipe_idx, wa->rpipe_bm);
  147. spin_unlock_irqrestore(&wa->rpipe_bm_lock, flags);
  148. return rpipe_idx;
  149. }
  150. static void rpipe_put_idx(struct wahc *wa, unsigned rpipe_idx)
  151. {
  152. unsigned long flags;
  153. spin_lock_irqsave(&wa->rpipe_bm_lock, flags);
  154. clear_bit(rpipe_idx, wa->rpipe_bm);
  155. spin_unlock_irqrestore(&wa->rpipe_bm_lock, flags);
  156. }
  157. void rpipe_destroy(struct kref *_rpipe)
  158. {
  159. struct wa_rpipe *rpipe = container_of(_rpipe, struct wa_rpipe, refcnt);
  160. u8 index = le16_to_cpu(rpipe->descr.wRPipeIndex);
  161. d_fnstart(1, NULL, "(rpipe %p %u)\n", rpipe, index);
  162. if (rpipe->ep)
  163. rpipe->ep->hcpriv = NULL;
  164. rpipe_put_idx(rpipe->wa, index);
  165. wa_put(rpipe->wa);
  166. kfree(rpipe);
  167. d_fnend(1, NULL, "(rpipe %p %u)\n", rpipe, index);
  168. }
  169. EXPORT_SYMBOL_GPL(rpipe_destroy);
  170. /*
  171. * Locate an idle rpipe, create an structure for it and return it
  172. *
  173. * @wa is referenced and unlocked
  174. * @crs enum rpipe_attr, required endpoint characteristics
  175. *
  176. * The rpipe can be used only sequentially (not in parallel).
  177. *
  178. * The rpipe is moved into the "ready" state.
  179. */
  180. static int rpipe_get_idle(struct wa_rpipe **prpipe, struct wahc *wa, u8 crs,
  181. gfp_t gfp)
  182. {
  183. int result;
  184. unsigned rpipe_idx;
  185. struct wa_rpipe *rpipe;
  186. struct device *dev = &wa->usb_iface->dev;
  187. d_fnstart(3, dev, "(wa %p crs 0x%02x)\n", wa, crs);
  188. rpipe = kzalloc(sizeof(*rpipe), gfp);
  189. if (rpipe == NULL)
  190. return -ENOMEM;
  191. rpipe_init(rpipe);
  192. /* Look for an idle pipe */
  193. for (rpipe_idx = 0; rpipe_idx < wa->rpipes; rpipe_idx++) {
  194. rpipe_idx = rpipe_get_idx(wa, rpipe_idx);
  195. if (rpipe_idx >= wa->rpipes) /* no more pipes :( */
  196. break;
  197. result = __rpipe_get_descr(wa, &rpipe->descr, rpipe_idx);
  198. if (result < 0)
  199. dev_err(dev, "Can't get descriptor for rpipe %u: %d\n",
  200. rpipe_idx, result);
  201. else if ((rpipe->descr.bmCharacteristics & crs) != 0)
  202. goto found;
  203. rpipe_put_idx(wa, rpipe_idx);
  204. }
  205. *prpipe = NULL;
  206. kfree(rpipe);
  207. d_fnend(3, dev, "(wa %p crs 0x%02x) = -ENXIO\n", wa, crs);
  208. return -ENXIO;
  209. found:
  210. set_bit(rpipe_idx, wa->rpipe_bm);
  211. rpipe->wa = wa_get(wa);
  212. *prpipe = rpipe;
  213. d_fnstart(3, dev, "(wa %p crs 0x%02x) = 0\n", wa, crs);
  214. return 0;
  215. }
  216. static int __rpipe_reset(struct wahc *wa, unsigned index)
  217. {
  218. int result;
  219. struct device *dev = &wa->usb_iface->dev;
  220. d_printf(1, dev, "rpipe %u: reset\n", index);
  221. result = usb_control_msg(
  222. wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0),
  223. USB_REQ_RPIPE_RESET,
  224. USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_RPIPE,
  225. 0, index, NULL, 0, 1000 /* FIXME: arbitrary */);
  226. if (result < 0)
  227. dev_err(dev, "rpipe %u: reset failed: %d\n",
  228. index, result);
  229. return result;
  230. }
  231. /*
  232. * Fake companion descriptor for ep0
  233. *
  234. * See WUSB1.0[7.4.4], most of this is zero for bulk/int/ctl
  235. */
  236. static struct usb_wireless_ep_comp_descriptor epc0 = {
  237. .bLength = sizeof(epc0),
  238. .bDescriptorType = USB_DT_WIRELESS_ENDPOINT_COMP,
  239. /* .bMaxBurst = 1, */
  240. .bMaxSequence = 31,
  241. };
  242. /*
  243. * Look for EP companion descriptor
  244. *
  245. * Get there, look for Inara in the endpoint's extra descriptors
  246. */
  247. static struct usb_wireless_ep_comp_descriptor *rpipe_epc_find(
  248. struct device *dev, struct usb_host_endpoint *ep)
  249. {
  250. void *itr;
  251. size_t itr_size;
  252. struct usb_descriptor_header *hdr;
  253. struct usb_wireless_ep_comp_descriptor *epcd;
  254. d_fnstart(3, dev, "(ep %p)\n", ep);
  255. if (ep->desc.bEndpointAddress == 0) {
  256. epcd = &epc0;
  257. goto out;
  258. }
  259. itr = ep->extra;
  260. itr_size = ep->extralen;
  261. epcd = NULL;
  262. while (itr_size > 0) {
  263. if (itr_size < sizeof(*hdr)) {
  264. dev_err(dev, "HW Bug? ep 0x%02x: extra descriptors "
  265. "at offset %zu: only %zu bytes left\n",
  266. ep->desc.bEndpointAddress,
  267. itr - (void *) ep->extra, itr_size);
  268. break;
  269. }
  270. hdr = itr;
  271. if (hdr->bDescriptorType == USB_DT_WIRELESS_ENDPOINT_COMP) {
  272. epcd = itr;
  273. break;
  274. }
  275. if (hdr->bLength > itr_size) {
  276. dev_err(dev, "HW Bug? ep 0x%02x: extra descriptor "
  277. "at offset %zu (type 0x%02x) "
  278. "length %d but only %zu bytes left\n",
  279. ep->desc.bEndpointAddress,
  280. itr - (void *) ep->extra, hdr->bDescriptorType,
  281. hdr->bLength, itr_size);
  282. break;
  283. }
  284. itr += hdr->bLength;
  285. itr_size -= hdr->bDescriptorType;
  286. }
  287. out:
  288. d_fnend(3, dev, "(ep %p) = %p\n", ep, epcd);
  289. return epcd;
  290. }
  291. /*
  292. * Aim an rpipe to its device & endpoint destination
  293. *
  294. * Make sure we change the address to unauthenticathed if the device
  295. * is WUSB and it is not authenticated.
  296. */
  297. static int rpipe_aim(struct wa_rpipe *rpipe, struct wahc *wa,
  298. struct usb_host_endpoint *ep, struct urb *urb, gfp_t gfp)
  299. {
  300. int result = -ENOMSG; /* better code for lack of companion? */
  301. struct device *dev = &wa->usb_iface->dev;
  302. struct usb_device *usb_dev = urb->dev;
  303. struct usb_wireless_ep_comp_descriptor *epcd;
  304. u8 unauth;
  305. d_fnstart(3, dev, "(rpipe %p wa %p ep %p, urb %p)\n",
  306. rpipe, wa, ep, urb);
  307. epcd = rpipe_epc_find(dev, ep);
  308. if (epcd == NULL) {
  309. dev_err(dev, "ep 0x%02x: can't find companion descriptor\n",
  310. ep->desc.bEndpointAddress);
  311. goto error;
  312. }
  313. unauth = usb_dev->wusb && !usb_dev->authenticated ? 0x80 : 0;
  314. __rpipe_reset(wa, le16_to_cpu(rpipe->descr.wRPipeIndex));
  315. atomic_set(&rpipe->segs_available, le16_to_cpu(rpipe->descr.wRequests));
  316. /* FIXME: block allocation system; request with queuing and timeout */
  317. /* FIXME: compute so seg_size > ep->maxpktsize */
  318. rpipe->descr.wBlocks = cpu_to_le16(16); /* given */
  319. /* ep0 maxpktsize is 0x200 (WUSB1.0[4.8.1]) */
  320. rpipe->descr.wMaxPacketSize = cpu_to_le16(ep->desc.wMaxPacketSize);
  321. rpipe->descr.bHSHubAddress = 0; /* reserved: zero */
  322. rpipe->descr.bHSHubPort = wusb_port_no_to_idx(urb->dev->portnum);
  323. /* FIXME: use maximum speed as supported or recommended by device */
  324. rpipe->descr.bSpeed = usb_pipeendpoint(urb->pipe) == 0 ?
  325. UWB_PHY_RATE_53 : UWB_PHY_RATE_200;
  326. d_printf(2, dev, "addr %u (0x%02x) rpipe #%u ep# %u speed %d\n",
  327. urb->dev->devnum, urb->dev->devnum | unauth,
  328. le16_to_cpu(rpipe->descr.wRPipeIndex),
  329. usb_pipeendpoint(urb->pipe), rpipe->descr.bSpeed);
  330. /* see security.c:wusb_update_address() */
  331. if (unlikely(urb->dev->devnum == 0x80))
  332. rpipe->descr.bDeviceAddress = 0;
  333. else
  334. rpipe->descr.bDeviceAddress = urb->dev->devnum | unauth;
  335. rpipe->descr.bEndpointAddress = ep->desc.bEndpointAddress;
  336. /* FIXME: bDataSequence */
  337. rpipe->descr.bDataSequence = 0;
  338. /* FIXME: dwCurrentWindow */
  339. rpipe->descr.dwCurrentWindow = cpu_to_le32(1);
  340. /* FIXME: bMaxDataSequence */
  341. rpipe->descr.bMaxDataSequence = epcd->bMaxSequence - 1;
  342. rpipe->descr.bInterval = ep->desc.bInterval;
  343. /* FIXME: bOverTheAirInterval */
  344. rpipe->descr.bOverTheAirInterval = 0; /* 0 if not isoc */
  345. /* FIXME: xmit power & preamble blah blah */
  346. rpipe->descr.bmAttribute = ep->desc.bmAttributes & 0x03;
  347. /* rpipe->descr.bmCharacteristics RO */
  348. /* FIXME: bmRetryOptions */
  349. rpipe->descr.bmRetryOptions = 15;
  350. /* FIXME: use for assessing link quality? */
  351. rpipe->descr.wNumTransactionErrors = 0;
  352. result = __rpipe_set_descr(wa, &rpipe->descr,
  353. le16_to_cpu(rpipe->descr.wRPipeIndex));
  354. if (result < 0) {
  355. dev_err(dev, "Cannot aim rpipe: %d\n", result);
  356. goto error;
  357. }
  358. result = 0;
  359. error:
  360. d_fnend(3, dev, "(rpipe %p wa %p ep %p urb %p) = %d\n",
  361. rpipe, wa, ep, urb, result);
  362. return result;
  363. }
  364. /*
  365. * Check an aimed rpipe to make sure it points to where we want
  366. *
  367. * We use bit 19 of the Linux USB pipe bitmap for unauth vs auth
  368. * space; when it is like that, we or 0x80 to make an unauth address.
  369. */
  370. static int rpipe_check_aim(const struct wa_rpipe *rpipe, const struct wahc *wa,
  371. const struct usb_host_endpoint *ep,
  372. const struct urb *urb, gfp_t gfp)
  373. {
  374. int result = 0; /* better code for lack of companion? */
  375. struct device *dev = &wa->usb_iface->dev;
  376. struct usb_device *usb_dev = urb->dev;
  377. u8 unauth = (usb_dev->wusb && !usb_dev->authenticated) ? 0x80 : 0;
  378. u8 portnum = wusb_port_no_to_idx(urb->dev->portnum);
  379. d_fnstart(3, dev, "(rpipe %p wa %p ep %p, urb %p)\n",
  380. rpipe, wa, ep, urb);
  381. #define AIM_CHECK(rdf, val, text) \
  382. do { \
  383. if (rpipe->descr.rdf != (val)) { \
  384. dev_err(dev, \
  385. "rpipe aim discrepancy: " #rdf " " text "\n", \
  386. rpipe->descr.rdf, (val)); \
  387. result = -EINVAL; \
  388. WARN_ON(1); \
  389. } \
  390. } while (0)
  391. AIM_CHECK(wMaxPacketSize, cpu_to_le16(ep->desc.wMaxPacketSize),
  392. "(%u vs %u)");
  393. AIM_CHECK(bHSHubPort, portnum, "(%u vs %u)");
  394. AIM_CHECK(bSpeed, usb_pipeendpoint(urb->pipe) == 0 ?
  395. UWB_PHY_RATE_53 : UWB_PHY_RATE_200,
  396. "(%u vs %u)");
  397. AIM_CHECK(bDeviceAddress, urb->dev->devnum | unauth, "(%u vs %u)");
  398. AIM_CHECK(bEndpointAddress, ep->desc.bEndpointAddress, "(%u vs %u)");
  399. AIM_CHECK(bInterval, ep->desc.bInterval, "(%u vs %u)");
  400. AIM_CHECK(bmAttribute, ep->desc.bmAttributes & 0x03, "(%u vs %u)");
  401. #undef AIM_CHECK
  402. return result;
  403. }
  404. #ifndef CONFIG_BUG
  405. #define CONFIG_BUG 0
  406. #endif
  407. /*
  408. * Make sure there is an rpipe allocated for an endpoint
  409. *
  410. * If already allocated, we just refcount it; if not, we get an
  411. * idle one, aim it to the right location and take it.
  412. *
  413. * Attaches to ep->hcpriv and rpipe->ep to ep.
  414. */
  415. int rpipe_get_by_ep(struct wahc *wa, struct usb_host_endpoint *ep,
  416. struct urb *urb, gfp_t gfp)
  417. {
  418. int result = 0;
  419. struct device *dev = &wa->usb_iface->dev;
  420. struct wa_rpipe *rpipe;
  421. u8 eptype;
  422. d_fnstart(3, dev, "(wa %p ep %p urb %p gfp 0x%08x)\n", wa, ep, urb,
  423. gfp);
  424. mutex_lock(&wa->rpipe_mutex);
  425. rpipe = ep->hcpriv;
  426. if (rpipe != NULL) {
  427. if (CONFIG_BUG == 1) {
  428. result = rpipe_check_aim(rpipe, wa, ep, urb, gfp);
  429. if (result < 0)
  430. goto error;
  431. }
  432. __rpipe_get(rpipe);
  433. d_printf(2, dev, "ep 0x%02x: reusing rpipe %u\n",
  434. ep->desc.bEndpointAddress,
  435. le16_to_cpu(rpipe->descr.wRPipeIndex));
  436. } else {
  437. /* hmm, assign idle rpipe, aim it */
  438. result = -ENOBUFS;
  439. eptype = ep->desc.bmAttributes & 0x03;
  440. result = rpipe_get_idle(&rpipe, wa, 1 << eptype, gfp);
  441. if (result < 0)
  442. goto error;
  443. result = rpipe_aim(rpipe, wa, ep, urb, gfp);
  444. if (result < 0) {
  445. rpipe_put(rpipe);
  446. goto error;
  447. }
  448. ep->hcpriv = rpipe;
  449. rpipe->ep = ep;
  450. __rpipe_get(rpipe); /* for caching into ep->hcpriv */
  451. d_printf(2, dev, "ep 0x%02x: using rpipe %u\n",
  452. ep->desc.bEndpointAddress,
  453. le16_to_cpu(rpipe->descr.wRPipeIndex));
  454. }
  455. d_dump(4, dev, &rpipe->descr, sizeof(rpipe->descr));
  456. error:
  457. mutex_unlock(&wa->rpipe_mutex);
  458. d_fnend(3, dev, "(wa %p ep %p urb %p gfp 0x%08x)\n", wa, ep, urb, gfp);
  459. return result;
  460. }
  461. /*
  462. * Allocate the bitmap for each rpipe.
  463. */
  464. int wa_rpipes_create(struct wahc *wa)
  465. {
  466. wa->rpipes = wa->wa_descr->wNumRPipes;
  467. wa->rpipe_bm = kzalloc(BITS_TO_LONGS(wa->rpipes)*sizeof(unsigned long),
  468. GFP_KERNEL);
  469. if (wa->rpipe_bm == NULL)
  470. return -ENOMEM;
  471. return 0;
  472. }
  473. void wa_rpipes_destroy(struct wahc *wa)
  474. {
  475. struct device *dev = &wa->usb_iface->dev;
  476. d_fnstart(3, dev, "(wa %p)\n", wa);
  477. if (!bitmap_empty(wa->rpipe_bm, wa->rpipes)) {
  478. char buf[256];
  479. WARN_ON(1);
  480. bitmap_scnprintf(buf, sizeof(buf), wa->rpipe_bm, wa->rpipes);
  481. dev_err(dev, "BUG: pipes not released on exit: %s\n", buf);
  482. }
  483. kfree(wa->rpipe_bm);
  484. d_fnend(3, dev, "(wa %p)\n", wa);
  485. }
  486. /*
  487. * Release resources allocated for an endpoint
  488. *
  489. * If there is an associated rpipe to this endpoint, Abort any pending
  490. * transfers and put it. If the rpipe ends up being destroyed,
  491. * __rpipe_destroy() will cleanup ep->hcpriv.
  492. *
  493. * This is called before calling hcd->stop(), so you don't need to do
  494. * anything else in there.
  495. */
  496. void rpipe_ep_disable(struct wahc *wa, struct usb_host_endpoint *ep)
  497. {
  498. struct device *dev = &wa->usb_iface->dev;
  499. struct wa_rpipe *rpipe;
  500. d_fnstart(2, dev, "(wa %p ep %p)\n", wa, ep);
  501. mutex_lock(&wa->rpipe_mutex);
  502. rpipe = ep->hcpriv;
  503. if (rpipe != NULL) {
  504. unsigned rc = atomic_read(&rpipe->refcnt.refcount);
  505. int result;
  506. u16 index = le16_to_cpu(rpipe->descr.wRPipeIndex);
  507. if (rc != 1)
  508. d_printf(1, dev, "(wa %p ep %p) rpipe %p refcnt %u\n",
  509. wa, ep, rpipe, rc);
  510. d_printf(1, dev, "rpipe %u: abort\n", index);
  511. result = usb_control_msg(
  512. wa->usb_dev, usb_rcvctrlpipe(wa->usb_dev, 0),
  513. USB_REQ_RPIPE_ABORT,
  514. USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_RPIPE,
  515. 0, index, NULL, 0, 1000 /* FIXME: arbitrary */);
  516. if (result < 0 && result != -ENODEV /* dev is gone */)
  517. d_printf(1, dev, "(wa %p rpipe %u): abort failed: %d\n",
  518. wa, index, result);
  519. rpipe_put(rpipe);
  520. }
  521. mutex_unlock(&wa->rpipe_mutex);
  522. d_fnend(2, dev, "(wa %p ep %p)\n", wa, ep);
  523. return;
  524. }
  525. EXPORT_SYMBOL_GPL(rpipe_ep_disable);