usbtest.c 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519
  1. #include <linux/kernel.h>
  2. #include <linux/errno.h>
  3. #include <linux/init.h>
  4. #include <linux/slab.h>
  5. #include <linux/mm.h>
  6. #include <linux/module.h>
  7. #include <linux/moduleparam.h>
  8. #include <linux/scatterlist.h>
  9. #include <linux/mutex.h>
  10. #include <linux/usb.h>
  11. /*-------------------------------------------------------------------------*/
  12. /* FIXME make these public somewhere; usbdevfs.h? */
  13. struct usbtest_param {
  14. /* inputs */
  15. unsigned test_num; /* 0..(TEST_CASES-1) */
  16. unsigned iterations;
  17. unsigned length;
  18. unsigned vary;
  19. unsigned sglen;
  20. /* outputs */
  21. struct timeval duration;
  22. };
  23. #define USBTEST_REQUEST _IOWR('U', 100, struct usbtest_param)
  24. /*-------------------------------------------------------------------------*/
  25. #define GENERIC /* let probe() bind using module params */
  26. /* Some devices that can be used for testing will have "real" drivers.
  27. * Entries for those need to be enabled here by hand, after disabling
  28. * that "real" driver.
  29. */
  30. //#define IBOT2 /* grab iBOT2 webcams */
  31. //#define KEYSPAN_19Qi /* grab un-renumerated serial adapter */
  32. /*-------------------------------------------------------------------------*/
  33. struct usbtest_info {
  34. const char *name;
  35. u8 ep_in; /* bulk/intr source */
  36. u8 ep_out; /* bulk/intr sink */
  37. unsigned autoconf:1;
  38. unsigned ctrl_out:1;
  39. unsigned iso:1; /* try iso in/out */
  40. int alt;
  41. };
  42. /* this is accessed only through usbfs ioctl calls.
  43. * one ioctl to issue a test ... one lock per device.
  44. * tests create other threads if they need them.
  45. * urbs and buffers are allocated dynamically,
  46. * and data generated deterministically.
  47. */
  48. struct usbtest_dev {
  49. struct usb_interface *intf;
  50. struct usbtest_info *info;
  51. int in_pipe;
  52. int out_pipe;
  53. int in_iso_pipe;
  54. int out_iso_pipe;
  55. struct usb_endpoint_descriptor *iso_in, *iso_out;
  56. struct mutex lock;
  57. #define TBUF_SIZE 256
  58. u8 *buf;
  59. };
  60. static struct usb_device *testdev_to_usbdev(struct usbtest_dev *test)
  61. {
  62. return interface_to_usbdev(test->intf);
  63. }
  64. /* set up all urbs so they can be used with either bulk or interrupt */
  65. #define INTERRUPT_RATE 1 /* msec/transfer */
  66. #define ERROR(tdev, fmt, args...) \
  67. dev_err(&(tdev)->intf->dev , fmt , ## args)
  68. #define WARNING(tdev, fmt, args...) \
  69. dev_warn(&(tdev)->intf->dev , fmt , ## args)
  70. #define GUARD_BYTE 0xA5
  71. /*-------------------------------------------------------------------------*/
  72. static int
  73. get_endpoints(struct usbtest_dev *dev, struct usb_interface *intf)
  74. {
  75. int tmp;
  76. struct usb_host_interface *alt;
  77. struct usb_host_endpoint *in, *out;
  78. struct usb_host_endpoint *iso_in, *iso_out;
  79. struct usb_device *udev;
  80. for (tmp = 0; tmp < intf->num_altsetting; tmp++) {
  81. unsigned ep;
  82. in = out = NULL;
  83. iso_in = iso_out = NULL;
  84. alt = intf->altsetting + tmp;
  85. /* take the first altsetting with in-bulk + out-bulk;
  86. * ignore other endpoints and altsettings.
  87. */
  88. for (ep = 0; ep < alt->desc.bNumEndpoints; ep++) {
  89. struct usb_host_endpoint *e;
  90. e = alt->endpoint + ep;
  91. switch (e->desc.bmAttributes) {
  92. case USB_ENDPOINT_XFER_BULK:
  93. break;
  94. case USB_ENDPOINT_XFER_ISOC:
  95. if (dev->info->iso)
  96. goto try_iso;
  97. /* FALLTHROUGH */
  98. default:
  99. continue;
  100. }
  101. if (usb_endpoint_dir_in(&e->desc)) {
  102. if (!in)
  103. in = e;
  104. } else {
  105. if (!out)
  106. out = e;
  107. }
  108. continue;
  109. try_iso:
  110. if (usb_endpoint_dir_in(&e->desc)) {
  111. if (!iso_in)
  112. iso_in = e;
  113. } else {
  114. if (!iso_out)
  115. iso_out = e;
  116. }
  117. }
  118. if ((in && out) || iso_in || iso_out)
  119. goto found;
  120. }
  121. return -EINVAL;
  122. found:
  123. udev = testdev_to_usbdev(dev);
  124. if (alt->desc.bAlternateSetting != 0) {
  125. tmp = usb_set_interface(udev,
  126. alt->desc.bInterfaceNumber,
  127. alt->desc.bAlternateSetting);
  128. if (tmp < 0)
  129. return tmp;
  130. }
  131. if (in) {
  132. dev->in_pipe = usb_rcvbulkpipe(udev,
  133. in->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
  134. dev->out_pipe = usb_sndbulkpipe(udev,
  135. out->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
  136. }
  137. if (iso_in) {
  138. dev->iso_in = &iso_in->desc;
  139. dev->in_iso_pipe = usb_rcvisocpipe(udev,
  140. iso_in->desc.bEndpointAddress
  141. & USB_ENDPOINT_NUMBER_MASK);
  142. }
  143. if (iso_out) {
  144. dev->iso_out = &iso_out->desc;
  145. dev->out_iso_pipe = usb_sndisocpipe(udev,
  146. iso_out->desc.bEndpointAddress
  147. & USB_ENDPOINT_NUMBER_MASK);
  148. }
  149. return 0;
  150. }
  151. /*-------------------------------------------------------------------------*/
  152. /* Support for testing basic non-queued I/O streams.
  153. *
  154. * These just package urbs as requests that can be easily canceled.
  155. * Each urb's data buffer is dynamically allocated; callers can fill
  156. * them with non-zero test data (or test for it) when appropriate.
  157. */
  158. static void simple_callback(struct urb *urb)
  159. {
  160. complete(urb->context);
  161. }
  162. static struct urb *usbtest_alloc_urb(
  163. struct usb_device *udev,
  164. int pipe,
  165. unsigned long bytes,
  166. unsigned transfer_flags,
  167. unsigned offset)
  168. {
  169. struct urb *urb;
  170. urb = usb_alloc_urb(0, GFP_KERNEL);
  171. if (!urb)
  172. return urb;
  173. usb_fill_bulk_urb(urb, udev, pipe, NULL, bytes, simple_callback, NULL);
  174. urb->interval = (udev->speed == USB_SPEED_HIGH)
  175. ? (INTERRUPT_RATE << 3)
  176. : INTERRUPT_RATE;
  177. urb->transfer_flags = transfer_flags;
  178. if (usb_pipein(pipe))
  179. urb->transfer_flags |= URB_SHORT_NOT_OK;
  180. if (urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)
  181. urb->transfer_buffer = usb_alloc_coherent(udev, bytes + offset,
  182. GFP_KERNEL, &urb->transfer_dma);
  183. else
  184. urb->transfer_buffer = kmalloc(bytes + offset, GFP_KERNEL);
  185. if (!urb->transfer_buffer) {
  186. usb_free_urb(urb);
  187. return NULL;
  188. }
  189. /* To test unaligned transfers add an offset and fill the
  190. unused memory with a guard value */
  191. if (offset) {
  192. memset(urb->transfer_buffer, GUARD_BYTE, offset);
  193. urb->transfer_buffer += offset;
  194. if (urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)
  195. urb->transfer_dma += offset;
  196. }
  197. /* For inbound transfers use guard byte so that test fails if
  198. data not correctly copied */
  199. memset(urb->transfer_buffer,
  200. usb_pipein(urb->pipe) ? GUARD_BYTE : 0,
  201. bytes);
  202. return urb;
  203. }
  204. static struct urb *simple_alloc_urb(
  205. struct usb_device *udev,
  206. int pipe,
  207. unsigned long bytes)
  208. {
  209. return usbtest_alloc_urb(udev, pipe, bytes, URB_NO_TRANSFER_DMA_MAP, 0);
  210. }
  211. static unsigned pattern;
  212. static unsigned mod_pattern;
  213. module_param_named(pattern, mod_pattern, uint, S_IRUGO | S_IWUSR);
  214. MODULE_PARM_DESC(mod_pattern, "i/o pattern (0 == zeroes)");
  215. static inline void simple_fill_buf(struct urb *urb)
  216. {
  217. unsigned i;
  218. u8 *buf = urb->transfer_buffer;
  219. unsigned len = urb->transfer_buffer_length;
  220. switch (pattern) {
  221. default:
  222. /* FALLTHROUGH */
  223. case 0:
  224. memset(buf, 0, len);
  225. break;
  226. case 1: /* mod63 */
  227. for (i = 0; i < len; i++)
  228. *buf++ = (u8) (i % 63);
  229. break;
  230. }
  231. }
  232. static inline unsigned long buffer_offset(void *buf)
  233. {
  234. return (unsigned long)buf & (ARCH_KMALLOC_MINALIGN - 1);
  235. }
  236. static int check_guard_bytes(struct usbtest_dev *tdev, struct urb *urb)
  237. {
  238. u8 *buf = urb->transfer_buffer;
  239. u8 *guard = buf - buffer_offset(buf);
  240. unsigned i;
  241. for (i = 0; guard < buf; i++, guard++) {
  242. if (*guard != GUARD_BYTE) {
  243. ERROR(tdev, "guard byte[%d] %d (not %d)\n",
  244. i, *guard, GUARD_BYTE);
  245. return -EINVAL;
  246. }
  247. }
  248. return 0;
  249. }
  250. static int simple_check_buf(struct usbtest_dev *tdev, struct urb *urb)
  251. {
  252. unsigned i;
  253. u8 expected;
  254. u8 *buf = urb->transfer_buffer;
  255. unsigned len = urb->actual_length;
  256. int ret = check_guard_bytes(tdev, urb);
  257. if (ret)
  258. return ret;
  259. for (i = 0; i < len; i++, buf++) {
  260. switch (pattern) {
  261. /* all-zeroes has no synchronization issues */
  262. case 0:
  263. expected = 0;
  264. break;
  265. /* mod63 stays in sync with short-terminated transfers,
  266. * or otherwise when host and gadget agree on how large
  267. * each usb transfer request should be. resync is done
  268. * with set_interface or set_config.
  269. */
  270. case 1: /* mod63 */
  271. expected = i % 63;
  272. break;
  273. /* always fail unsupported patterns */
  274. default:
  275. expected = !*buf;
  276. break;
  277. }
  278. if (*buf == expected)
  279. continue;
  280. ERROR(tdev, "buf[%d] = %d (not %d)\n", i, *buf, expected);
  281. return -EINVAL;
  282. }
  283. return 0;
  284. }
  285. static void simple_free_urb(struct urb *urb)
  286. {
  287. unsigned long offset = buffer_offset(urb->transfer_buffer);
  288. if (urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)
  289. usb_free_coherent(
  290. urb->dev,
  291. urb->transfer_buffer_length + offset,
  292. urb->transfer_buffer - offset,
  293. urb->transfer_dma - offset);
  294. else
  295. kfree(urb->transfer_buffer - offset);
  296. usb_free_urb(urb);
  297. }
  298. static int simple_io(
  299. struct usbtest_dev *tdev,
  300. struct urb *urb,
  301. int iterations,
  302. int vary,
  303. int expected,
  304. const char *label
  305. )
  306. {
  307. struct usb_device *udev = urb->dev;
  308. int max = urb->transfer_buffer_length;
  309. struct completion completion;
  310. int retval = 0;
  311. urb->context = &completion;
  312. while (retval == 0 && iterations-- > 0) {
  313. init_completion(&completion);
  314. if (usb_pipeout(urb->pipe)) {
  315. simple_fill_buf(urb);
  316. urb->transfer_flags |= URB_ZERO_PACKET;
  317. }
  318. retval = usb_submit_urb(urb, GFP_KERNEL);
  319. if (retval != 0)
  320. break;
  321. /* NOTE: no timeouts; can't be broken out of by interrupt */
  322. wait_for_completion(&completion);
  323. retval = urb->status;
  324. urb->dev = udev;
  325. if (retval == 0 && usb_pipein(urb->pipe))
  326. retval = simple_check_buf(tdev, urb);
  327. if (vary) {
  328. int len = urb->transfer_buffer_length;
  329. len += vary;
  330. len %= max;
  331. if (len == 0)
  332. len = (vary < max) ? vary : max;
  333. urb->transfer_buffer_length = len;
  334. }
  335. /* FIXME if endpoint halted, clear halt (and log) */
  336. }
  337. urb->transfer_buffer_length = max;
  338. if (expected != retval)
  339. dev_err(&udev->dev,
  340. "%s failed, iterations left %d, status %d (not %d)\n",
  341. label, iterations, retval, expected);
  342. return retval;
  343. }
  344. /*-------------------------------------------------------------------------*/
  345. /* We use scatterlist primitives to test queued I/O.
  346. * Yes, this also tests the scatterlist primitives.
  347. */
  348. static void free_sglist(struct scatterlist *sg, int nents)
  349. {
  350. unsigned i;
  351. if (!sg)
  352. return;
  353. for (i = 0; i < nents; i++) {
  354. if (!sg_page(&sg[i]))
  355. continue;
  356. kfree(sg_virt(&sg[i]));
  357. }
  358. kfree(sg);
  359. }
  360. static struct scatterlist *
  361. alloc_sglist(int nents, int max, int vary)
  362. {
  363. struct scatterlist *sg;
  364. unsigned i;
  365. unsigned size = max;
  366. sg = kmalloc(nents * sizeof *sg, GFP_KERNEL);
  367. if (!sg)
  368. return NULL;
  369. sg_init_table(sg, nents);
  370. for (i = 0; i < nents; i++) {
  371. char *buf;
  372. unsigned j;
  373. buf = kzalloc(size, GFP_KERNEL);
  374. if (!buf) {
  375. free_sglist(sg, i);
  376. return NULL;
  377. }
  378. /* kmalloc pages are always physically contiguous! */
  379. sg_set_buf(&sg[i], buf, size);
  380. switch (pattern) {
  381. case 0:
  382. /* already zeroed */
  383. break;
  384. case 1:
  385. for (j = 0; j < size; j++)
  386. *buf++ = (u8) (j % 63);
  387. break;
  388. }
  389. if (vary) {
  390. size += vary;
  391. size %= max;
  392. if (size == 0)
  393. size = (vary < max) ? vary : max;
  394. }
  395. }
  396. return sg;
  397. }
  398. static int perform_sglist(
  399. struct usbtest_dev *tdev,
  400. unsigned iterations,
  401. int pipe,
  402. struct usb_sg_request *req,
  403. struct scatterlist *sg,
  404. int nents
  405. )
  406. {
  407. struct usb_device *udev = testdev_to_usbdev(tdev);
  408. int retval = 0;
  409. while (retval == 0 && iterations-- > 0) {
  410. retval = usb_sg_init(req, udev, pipe,
  411. (udev->speed == USB_SPEED_HIGH)
  412. ? (INTERRUPT_RATE << 3)
  413. : INTERRUPT_RATE,
  414. sg, nents, 0, GFP_KERNEL);
  415. if (retval)
  416. break;
  417. usb_sg_wait(req);
  418. retval = req->status;
  419. /* FIXME check resulting data pattern */
  420. /* FIXME if endpoint halted, clear halt (and log) */
  421. }
  422. /* FIXME for unlink or fault handling tests, don't report
  423. * failure if retval is as we expected ...
  424. */
  425. if (retval)
  426. ERROR(tdev, "perform_sglist failed, "
  427. "iterations left %d, status %d\n",
  428. iterations, retval);
  429. return retval;
  430. }
  431. /*-------------------------------------------------------------------------*/
  432. /* unqueued control message testing
  433. *
  434. * there's a nice set of device functional requirements in chapter 9 of the
  435. * usb 2.0 spec, which we can apply to ANY device, even ones that don't use
  436. * special test firmware.
  437. *
  438. * we know the device is configured (or suspended) by the time it's visible
  439. * through usbfs. we can't change that, so we won't test enumeration (which
  440. * worked 'well enough' to get here, this time), power management (ditto),
  441. * or remote wakeup (which needs human interaction).
  442. */
  443. static unsigned realworld = 1;
  444. module_param(realworld, uint, 0);
  445. MODULE_PARM_DESC(realworld, "clear to demand stricter spec compliance");
  446. static int get_altsetting(struct usbtest_dev *dev)
  447. {
  448. struct usb_interface *iface = dev->intf;
  449. struct usb_device *udev = interface_to_usbdev(iface);
  450. int retval;
  451. retval = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
  452. USB_REQ_GET_INTERFACE, USB_DIR_IN|USB_RECIP_INTERFACE,
  453. 0, iface->altsetting[0].desc.bInterfaceNumber,
  454. dev->buf, 1, USB_CTRL_GET_TIMEOUT);
  455. switch (retval) {
  456. case 1:
  457. return dev->buf[0];
  458. case 0:
  459. retval = -ERANGE;
  460. /* FALLTHROUGH */
  461. default:
  462. return retval;
  463. }
  464. }
  465. static int set_altsetting(struct usbtest_dev *dev, int alternate)
  466. {
  467. struct usb_interface *iface = dev->intf;
  468. struct usb_device *udev;
  469. if (alternate < 0 || alternate >= 256)
  470. return -EINVAL;
  471. udev = interface_to_usbdev(iface);
  472. return usb_set_interface(udev,
  473. iface->altsetting[0].desc.bInterfaceNumber,
  474. alternate);
  475. }
  476. static int is_good_config(struct usbtest_dev *tdev, int len)
  477. {
  478. struct usb_config_descriptor *config;
  479. if (len < sizeof *config)
  480. return 0;
  481. config = (struct usb_config_descriptor *) tdev->buf;
  482. switch (config->bDescriptorType) {
  483. case USB_DT_CONFIG:
  484. case USB_DT_OTHER_SPEED_CONFIG:
  485. if (config->bLength != 9) {
  486. ERROR(tdev, "bogus config descriptor length\n");
  487. return 0;
  488. }
  489. /* this bit 'must be 1' but often isn't */
  490. if (!realworld && !(config->bmAttributes & 0x80)) {
  491. ERROR(tdev, "high bit of config attributes not set\n");
  492. return 0;
  493. }
  494. if (config->bmAttributes & 0x1f) { /* reserved == 0 */
  495. ERROR(tdev, "reserved config bits set\n");
  496. return 0;
  497. }
  498. break;
  499. default:
  500. return 0;
  501. }
  502. if (le16_to_cpu(config->wTotalLength) == len) /* read it all */
  503. return 1;
  504. if (le16_to_cpu(config->wTotalLength) >= TBUF_SIZE) /* max partial read */
  505. return 1;
  506. ERROR(tdev, "bogus config descriptor read size\n");
  507. return 0;
  508. }
  509. /* sanity test for standard requests working with usb_control_mesg() and some
  510. * of the utility functions which use it.
  511. *
  512. * this doesn't test how endpoint halts behave or data toggles get set, since
  513. * we won't do I/O to bulk/interrupt endpoints here (which is how to change
  514. * halt or toggle). toggle testing is impractical without support from hcds.
  515. *
  516. * this avoids failing devices linux would normally work with, by not testing
  517. * config/altsetting operations for devices that only support their defaults.
  518. * such devices rarely support those needless operations.
  519. *
  520. * NOTE that since this is a sanity test, it's not examining boundary cases
  521. * to see if usbcore, hcd, and device all behave right. such testing would
  522. * involve varied read sizes and other operation sequences.
  523. */
  524. static int ch9_postconfig(struct usbtest_dev *dev)
  525. {
  526. struct usb_interface *iface = dev->intf;
  527. struct usb_device *udev = interface_to_usbdev(iface);
  528. int i, alt, retval;
  529. /* [9.2.3] if there's more than one altsetting, we need to be able to
  530. * set and get each one. mostly trusts the descriptors from usbcore.
  531. */
  532. for (i = 0; i < iface->num_altsetting; i++) {
  533. /* 9.2.3 constrains the range here */
  534. alt = iface->altsetting[i].desc.bAlternateSetting;
  535. if (alt < 0 || alt >= iface->num_altsetting) {
  536. dev_err(&iface->dev,
  537. "invalid alt [%d].bAltSetting = %d\n",
  538. i, alt);
  539. }
  540. /* [real world] get/set unimplemented if there's only one */
  541. if (realworld && iface->num_altsetting == 1)
  542. continue;
  543. /* [9.4.10] set_interface */
  544. retval = set_altsetting(dev, alt);
  545. if (retval) {
  546. dev_err(&iface->dev, "can't set_interface = %d, %d\n",
  547. alt, retval);
  548. return retval;
  549. }
  550. /* [9.4.4] get_interface always works */
  551. retval = get_altsetting(dev);
  552. if (retval != alt) {
  553. dev_err(&iface->dev, "get alt should be %d, was %d\n",
  554. alt, retval);
  555. return (retval < 0) ? retval : -EDOM;
  556. }
  557. }
  558. /* [real world] get_config unimplemented if there's only one */
  559. if (!realworld || udev->descriptor.bNumConfigurations != 1) {
  560. int expected = udev->actconfig->desc.bConfigurationValue;
  561. /* [9.4.2] get_configuration always works
  562. * ... although some cheap devices (like one TI Hub I've got)
  563. * won't return config descriptors except before set_config.
  564. */
  565. retval = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
  566. USB_REQ_GET_CONFIGURATION,
  567. USB_DIR_IN | USB_RECIP_DEVICE,
  568. 0, 0, dev->buf, 1, USB_CTRL_GET_TIMEOUT);
  569. if (retval != 1 || dev->buf[0] != expected) {
  570. dev_err(&iface->dev, "get config --> %d %d (1 %d)\n",
  571. retval, dev->buf[0], expected);
  572. return (retval < 0) ? retval : -EDOM;
  573. }
  574. }
  575. /* there's always [9.4.3] a device descriptor [9.6.1] */
  576. retval = usb_get_descriptor(udev, USB_DT_DEVICE, 0,
  577. dev->buf, sizeof udev->descriptor);
  578. if (retval != sizeof udev->descriptor) {
  579. dev_err(&iface->dev, "dev descriptor --> %d\n", retval);
  580. return (retval < 0) ? retval : -EDOM;
  581. }
  582. /* there's always [9.4.3] at least one config descriptor [9.6.3] */
  583. for (i = 0; i < udev->descriptor.bNumConfigurations; i++) {
  584. retval = usb_get_descriptor(udev, USB_DT_CONFIG, i,
  585. dev->buf, TBUF_SIZE);
  586. if (!is_good_config(dev, retval)) {
  587. dev_err(&iface->dev,
  588. "config [%d] descriptor --> %d\n",
  589. i, retval);
  590. return (retval < 0) ? retval : -EDOM;
  591. }
  592. /* FIXME cross-checking udev->config[i] to make sure usbcore
  593. * parsed it right (etc) would be good testing paranoia
  594. */
  595. }
  596. /* and sometimes [9.2.6.6] speed dependent descriptors */
  597. if (le16_to_cpu(udev->descriptor.bcdUSB) == 0x0200) {
  598. struct usb_qualifier_descriptor *d = NULL;
  599. /* device qualifier [9.6.2] */
  600. retval = usb_get_descriptor(udev,
  601. USB_DT_DEVICE_QUALIFIER, 0, dev->buf,
  602. sizeof(struct usb_qualifier_descriptor));
  603. if (retval == -EPIPE) {
  604. if (udev->speed == USB_SPEED_HIGH) {
  605. dev_err(&iface->dev,
  606. "hs dev qualifier --> %d\n",
  607. retval);
  608. return (retval < 0) ? retval : -EDOM;
  609. }
  610. /* usb2.0 but not high-speed capable; fine */
  611. } else if (retval != sizeof(struct usb_qualifier_descriptor)) {
  612. dev_err(&iface->dev, "dev qualifier --> %d\n", retval);
  613. return (retval < 0) ? retval : -EDOM;
  614. } else
  615. d = (struct usb_qualifier_descriptor *) dev->buf;
  616. /* might not have [9.6.2] any other-speed configs [9.6.4] */
  617. if (d) {
  618. unsigned max = d->bNumConfigurations;
  619. for (i = 0; i < max; i++) {
  620. retval = usb_get_descriptor(udev,
  621. USB_DT_OTHER_SPEED_CONFIG, i,
  622. dev->buf, TBUF_SIZE);
  623. if (!is_good_config(dev, retval)) {
  624. dev_err(&iface->dev,
  625. "other speed config --> %d\n",
  626. retval);
  627. return (retval < 0) ? retval : -EDOM;
  628. }
  629. }
  630. }
  631. }
  632. /* FIXME fetch strings from at least the device descriptor */
  633. /* [9.4.5] get_status always works */
  634. retval = usb_get_status(udev, USB_RECIP_DEVICE, 0, dev->buf);
  635. if (retval != 2) {
  636. dev_err(&iface->dev, "get dev status --> %d\n", retval);
  637. return (retval < 0) ? retval : -EDOM;
  638. }
  639. /* FIXME configuration.bmAttributes says if we could try to set/clear
  640. * the device's remote wakeup feature ... if we can, test that here
  641. */
  642. retval = usb_get_status(udev, USB_RECIP_INTERFACE,
  643. iface->altsetting[0].desc.bInterfaceNumber, dev->buf);
  644. if (retval != 2) {
  645. dev_err(&iface->dev, "get interface status --> %d\n", retval);
  646. return (retval < 0) ? retval : -EDOM;
  647. }
  648. /* FIXME get status for each endpoint in the interface */
  649. return 0;
  650. }
  651. /*-------------------------------------------------------------------------*/
  652. /* use ch9 requests to test whether:
  653. * (a) queues work for control, keeping N subtests queued and
  654. * active (auto-resubmit) for M loops through the queue.
  655. * (b) protocol stalls (control-only) will autorecover.
  656. * it's not like bulk/intr; no halt clearing.
  657. * (c) short control reads are reported and handled.
  658. * (d) queues are always processed in-order
  659. */
  660. struct ctrl_ctx {
  661. spinlock_t lock;
  662. struct usbtest_dev *dev;
  663. struct completion complete;
  664. unsigned count;
  665. unsigned pending;
  666. int status;
  667. struct urb **urb;
  668. struct usbtest_param *param;
  669. int last;
  670. };
  671. #define NUM_SUBCASES 15 /* how many test subcases here? */
  672. struct subcase {
  673. struct usb_ctrlrequest setup;
  674. int number;
  675. int expected;
  676. };
  677. static void ctrl_complete(struct urb *urb)
  678. {
  679. struct ctrl_ctx *ctx = urb->context;
  680. struct usb_ctrlrequest *reqp;
  681. struct subcase *subcase;
  682. int status = urb->status;
  683. reqp = (struct usb_ctrlrequest *)urb->setup_packet;
  684. subcase = container_of(reqp, struct subcase, setup);
  685. spin_lock(&ctx->lock);
  686. ctx->count--;
  687. ctx->pending--;
  688. /* queue must transfer and complete in fifo order, unless
  689. * usb_unlink_urb() is used to unlink something not at the
  690. * physical queue head (not tested).
  691. */
  692. if (subcase->number > 0) {
  693. if ((subcase->number - ctx->last) != 1) {
  694. ERROR(ctx->dev,
  695. "subcase %d completed out of order, last %d\n",
  696. subcase->number, ctx->last);
  697. status = -EDOM;
  698. ctx->last = subcase->number;
  699. goto error;
  700. }
  701. }
  702. ctx->last = subcase->number;
  703. /* succeed or fault in only one way? */
  704. if (status == subcase->expected)
  705. status = 0;
  706. /* async unlink for cleanup? */
  707. else if (status != -ECONNRESET) {
  708. /* some faults are allowed, not required */
  709. if (subcase->expected > 0 && (
  710. ((status == -subcase->expected /* happened */
  711. || status == 0)))) /* didn't */
  712. status = 0;
  713. /* sometimes more than one fault is allowed */
  714. else if (subcase->number == 12 && status == -EPIPE)
  715. status = 0;
  716. else
  717. ERROR(ctx->dev, "subtest %d error, status %d\n",
  718. subcase->number, status);
  719. }
  720. /* unexpected status codes mean errors; ideally, in hardware */
  721. if (status) {
  722. error:
  723. if (ctx->status == 0) {
  724. int i;
  725. ctx->status = status;
  726. ERROR(ctx->dev, "control queue %02x.%02x, err %d, "
  727. "%d left, subcase %d, len %d/%d\n",
  728. reqp->bRequestType, reqp->bRequest,
  729. status, ctx->count, subcase->number,
  730. urb->actual_length,
  731. urb->transfer_buffer_length);
  732. /* FIXME this "unlink everything" exit route should
  733. * be a separate test case.
  734. */
  735. /* unlink whatever's still pending */
  736. for (i = 1; i < ctx->param->sglen; i++) {
  737. struct urb *u = ctx->urb[
  738. (i + subcase->number)
  739. % ctx->param->sglen];
  740. if (u == urb || !u->dev)
  741. continue;
  742. spin_unlock(&ctx->lock);
  743. status = usb_unlink_urb(u);
  744. spin_lock(&ctx->lock);
  745. switch (status) {
  746. case -EINPROGRESS:
  747. case -EBUSY:
  748. case -EIDRM:
  749. continue;
  750. default:
  751. ERROR(ctx->dev, "urb unlink --> %d\n",
  752. status);
  753. }
  754. }
  755. status = ctx->status;
  756. }
  757. }
  758. /* resubmit if we need to, else mark this as done */
  759. if ((status == 0) && (ctx->pending < ctx->count)) {
  760. status = usb_submit_urb(urb, GFP_ATOMIC);
  761. if (status != 0) {
  762. ERROR(ctx->dev,
  763. "can't resubmit ctrl %02x.%02x, err %d\n",
  764. reqp->bRequestType, reqp->bRequest, status);
  765. urb->dev = NULL;
  766. } else
  767. ctx->pending++;
  768. } else
  769. urb->dev = NULL;
  770. /* signal completion when nothing's queued */
  771. if (ctx->pending == 0)
  772. complete(&ctx->complete);
  773. spin_unlock(&ctx->lock);
  774. }
  775. static int
  776. test_ctrl_queue(struct usbtest_dev *dev, struct usbtest_param *param)
  777. {
  778. struct usb_device *udev = testdev_to_usbdev(dev);
  779. struct urb **urb;
  780. struct ctrl_ctx context;
  781. int i;
  782. spin_lock_init(&context.lock);
  783. context.dev = dev;
  784. init_completion(&context.complete);
  785. context.count = param->sglen * param->iterations;
  786. context.pending = 0;
  787. context.status = -ENOMEM;
  788. context.param = param;
  789. context.last = -1;
  790. /* allocate and init the urbs we'll queue.
  791. * as with bulk/intr sglists, sglen is the queue depth; it also
  792. * controls which subtests run (more tests than sglen) or rerun.
  793. */
  794. urb = kcalloc(param->sglen, sizeof(struct urb *), GFP_KERNEL);
  795. if (!urb)
  796. return -ENOMEM;
  797. for (i = 0; i < param->sglen; i++) {
  798. int pipe = usb_rcvctrlpipe(udev, 0);
  799. unsigned len;
  800. struct urb *u;
  801. struct usb_ctrlrequest req;
  802. struct subcase *reqp;
  803. /* sign of this variable means:
  804. * -: tested code must return this (negative) error code
  805. * +: tested code may return this (negative too) error code
  806. */
  807. int expected = 0;
  808. /* requests here are mostly expected to succeed on any
  809. * device, but some are chosen to trigger protocol stalls
  810. * or short reads.
  811. */
  812. memset(&req, 0, sizeof req);
  813. req.bRequest = USB_REQ_GET_DESCRIPTOR;
  814. req.bRequestType = USB_DIR_IN|USB_RECIP_DEVICE;
  815. switch (i % NUM_SUBCASES) {
  816. case 0: /* get device descriptor */
  817. req.wValue = cpu_to_le16(USB_DT_DEVICE << 8);
  818. len = sizeof(struct usb_device_descriptor);
  819. break;
  820. case 1: /* get first config descriptor (only) */
  821. req.wValue = cpu_to_le16((USB_DT_CONFIG << 8) | 0);
  822. len = sizeof(struct usb_config_descriptor);
  823. break;
  824. case 2: /* get altsetting (OFTEN STALLS) */
  825. req.bRequest = USB_REQ_GET_INTERFACE;
  826. req.bRequestType = USB_DIR_IN|USB_RECIP_INTERFACE;
  827. /* index = 0 means first interface */
  828. len = 1;
  829. expected = EPIPE;
  830. break;
  831. case 3: /* get interface status */
  832. req.bRequest = USB_REQ_GET_STATUS;
  833. req.bRequestType = USB_DIR_IN|USB_RECIP_INTERFACE;
  834. /* interface 0 */
  835. len = 2;
  836. break;
  837. case 4: /* get device status */
  838. req.bRequest = USB_REQ_GET_STATUS;
  839. req.bRequestType = USB_DIR_IN|USB_RECIP_DEVICE;
  840. len = 2;
  841. break;
  842. case 5: /* get device qualifier (MAY STALL) */
  843. req.wValue = cpu_to_le16 (USB_DT_DEVICE_QUALIFIER << 8);
  844. len = sizeof(struct usb_qualifier_descriptor);
  845. if (udev->speed != USB_SPEED_HIGH)
  846. expected = EPIPE;
  847. break;
  848. case 6: /* get first config descriptor, plus interface */
  849. req.wValue = cpu_to_le16((USB_DT_CONFIG << 8) | 0);
  850. len = sizeof(struct usb_config_descriptor);
  851. len += sizeof(struct usb_interface_descriptor);
  852. break;
  853. case 7: /* get interface descriptor (ALWAYS STALLS) */
  854. req.wValue = cpu_to_le16 (USB_DT_INTERFACE << 8);
  855. /* interface == 0 */
  856. len = sizeof(struct usb_interface_descriptor);
  857. expected = -EPIPE;
  858. break;
  859. /* NOTE: two consecutive stalls in the queue here.
  860. * that tests fault recovery a bit more aggressively. */
  861. case 8: /* clear endpoint halt (MAY STALL) */
  862. req.bRequest = USB_REQ_CLEAR_FEATURE;
  863. req.bRequestType = USB_RECIP_ENDPOINT;
  864. /* wValue 0 == ep halt */
  865. /* wIndex 0 == ep0 (shouldn't halt!) */
  866. len = 0;
  867. pipe = usb_sndctrlpipe(udev, 0);
  868. expected = EPIPE;
  869. break;
  870. case 9: /* get endpoint status */
  871. req.bRequest = USB_REQ_GET_STATUS;
  872. req.bRequestType = USB_DIR_IN|USB_RECIP_ENDPOINT;
  873. /* endpoint 0 */
  874. len = 2;
  875. break;
  876. case 10: /* trigger short read (EREMOTEIO) */
  877. req.wValue = cpu_to_le16((USB_DT_CONFIG << 8) | 0);
  878. len = 1024;
  879. expected = -EREMOTEIO;
  880. break;
  881. /* NOTE: two consecutive _different_ faults in the queue. */
  882. case 11: /* get endpoint descriptor (ALWAYS STALLS) */
  883. req.wValue = cpu_to_le16(USB_DT_ENDPOINT << 8);
  884. /* endpoint == 0 */
  885. len = sizeof(struct usb_interface_descriptor);
  886. expected = EPIPE;
  887. break;
  888. /* NOTE: sometimes even a third fault in the queue! */
  889. case 12: /* get string 0 descriptor (MAY STALL) */
  890. req.wValue = cpu_to_le16(USB_DT_STRING << 8);
  891. /* string == 0, for language IDs */
  892. len = sizeof(struct usb_interface_descriptor);
  893. /* may succeed when > 4 languages */
  894. expected = EREMOTEIO; /* or EPIPE, if no strings */
  895. break;
  896. case 13: /* short read, resembling case 10 */
  897. req.wValue = cpu_to_le16((USB_DT_CONFIG << 8) | 0);
  898. /* last data packet "should" be DATA1, not DATA0 */
  899. len = 1024 - udev->descriptor.bMaxPacketSize0;
  900. expected = -EREMOTEIO;
  901. break;
  902. case 14: /* short read; try to fill the last packet */
  903. req.wValue = cpu_to_le16((USB_DT_DEVICE << 8) | 0);
  904. /* device descriptor size == 18 bytes */
  905. len = udev->descriptor.bMaxPacketSize0;
  906. if (udev->speed == USB_SPEED_SUPER)
  907. len = 512;
  908. switch (len) {
  909. case 8:
  910. len = 24;
  911. break;
  912. case 16:
  913. len = 32;
  914. break;
  915. }
  916. expected = -EREMOTEIO;
  917. break;
  918. default:
  919. ERROR(dev, "bogus number of ctrl queue testcases!\n");
  920. context.status = -EINVAL;
  921. goto cleanup;
  922. }
  923. req.wLength = cpu_to_le16(len);
  924. urb[i] = u = simple_alloc_urb(udev, pipe, len);
  925. if (!u)
  926. goto cleanup;
  927. reqp = kmalloc(sizeof *reqp, GFP_KERNEL);
  928. if (!reqp)
  929. goto cleanup;
  930. reqp->setup = req;
  931. reqp->number = i % NUM_SUBCASES;
  932. reqp->expected = expected;
  933. u->setup_packet = (char *) &reqp->setup;
  934. u->context = &context;
  935. u->complete = ctrl_complete;
  936. }
  937. /* queue the urbs */
  938. context.urb = urb;
  939. spin_lock_irq(&context.lock);
  940. for (i = 0; i < param->sglen; i++) {
  941. context.status = usb_submit_urb(urb[i], GFP_ATOMIC);
  942. if (context.status != 0) {
  943. ERROR(dev, "can't submit urb[%d], status %d\n",
  944. i, context.status);
  945. context.count = context.pending;
  946. break;
  947. }
  948. context.pending++;
  949. }
  950. spin_unlock_irq(&context.lock);
  951. /* FIXME set timer and time out; provide a disconnect hook */
  952. /* wait for the last one to complete */
  953. if (context.pending > 0)
  954. wait_for_completion(&context.complete);
  955. cleanup:
  956. for (i = 0; i < param->sglen; i++) {
  957. if (!urb[i])
  958. continue;
  959. urb[i]->dev = udev;
  960. kfree(urb[i]->setup_packet);
  961. simple_free_urb(urb[i]);
  962. }
  963. kfree(urb);
  964. return context.status;
  965. }
  966. #undef NUM_SUBCASES
  967. /*-------------------------------------------------------------------------*/
  968. static void unlink1_callback(struct urb *urb)
  969. {
  970. int status = urb->status;
  971. /* we "know" -EPIPE (stall) never happens */
  972. if (!status)
  973. status = usb_submit_urb(urb, GFP_ATOMIC);
  974. if (status) {
  975. urb->status = status;
  976. complete(urb->context);
  977. }
  978. }
  979. static int unlink1(struct usbtest_dev *dev, int pipe, int size, int async)
  980. {
  981. struct urb *urb;
  982. struct completion completion;
  983. int retval = 0;
  984. init_completion(&completion);
  985. urb = simple_alloc_urb(testdev_to_usbdev(dev), pipe, size);
  986. if (!urb)
  987. return -ENOMEM;
  988. urb->context = &completion;
  989. urb->complete = unlink1_callback;
  990. /* keep the endpoint busy. there are lots of hc/hcd-internal
  991. * states, and testing should get to all of them over time.
  992. *
  993. * FIXME want additional tests for when endpoint is STALLing
  994. * due to errors, or is just NAKing requests.
  995. */
  996. retval = usb_submit_urb(urb, GFP_KERNEL);
  997. if (retval != 0) {
  998. dev_err(&dev->intf->dev, "submit fail %d\n", retval);
  999. return retval;
  1000. }
  1001. /* unlinking that should always work. variable delay tests more
  1002. * hcd states and code paths, even with little other system load.
  1003. */
  1004. msleep(jiffies % (2 * INTERRUPT_RATE));
  1005. if (async) {
  1006. while (!completion_done(&completion)) {
  1007. retval = usb_unlink_urb(urb);
  1008. switch (retval) {
  1009. case -EBUSY:
  1010. case -EIDRM:
  1011. /* we can't unlink urbs while they're completing
  1012. * or if they've completed, and we haven't
  1013. * resubmitted. "normal" drivers would prevent
  1014. * resubmission, but since we're testing unlink
  1015. * paths, we can't.
  1016. */
  1017. ERROR(dev, "unlink retry\n");
  1018. continue;
  1019. case 0:
  1020. case -EINPROGRESS:
  1021. break;
  1022. default:
  1023. dev_err(&dev->intf->dev,
  1024. "unlink fail %d\n", retval);
  1025. return retval;
  1026. }
  1027. break;
  1028. }
  1029. } else
  1030. usb_kill_urb(urb);
  1031. wait_for_completion(&completion);
  1032. retval = urb->status;
  1033. simple_free_urb(urb);
  1034. if (async)
  1035. return (retval == -ECONNRESET) ? 0 : retval - 1000;
  1036. else
  1037. return (retval == -ENOENT || retval == -EPERM) ?
  1038. 0 : retval - 2000;
  1039. }
  1040. static int unlink_simple(struct usbtest_dev *dev, int pipe, int len)
  1041. {
  1042. int retval = 0;
  1043. /* test sync and async paths */
  1044. retval = unlink1(dev, pipe, len, 1);
  1045. if (!retval)
  1046. retval = unlink1(dev, pipe, len, 0);
  1047. return retval;
  1048. }
  1049. /*-------------------------------------------------------------------------*/
  1050. struct queued_ctx {
  1051. struct completion complete;
  1052. atomic_t pending;
  1053. unsigned num;
  1054. int status;
  1055. struct urb **urbs;
  1056. };
  1057. static void unlink_queued_callback(struct urb *urb)
  1058. {
  1059. int status = urb->status;
  1060. struct queued_ctx *ctx = urb->context;
  1061. if (ctx->status)
  1062. goto done;
  1063. if (urb == ctx->urbs[ctx->num - 4] || urb == ctx->urbs[ctx->num - 2]) {
  1064. if (status == -ECONNRESET)
  1065. goto done;
  1066. /* What error should we report if the URB completed normally? */
  1067. }
  1068. if (status != 0)
  1069. ctx->status = status;
  1070. done:
  1071. if (atomic_dec_and_test(&ctx->pending))
  1072. complete(&ctx->complete);
  1073. }
  1074. static int unlink_queued(struct usbtest_dev *dev, int pipe, unsigned num,
  1075. unsigned size)
  1076. {
  1077. struct queued_ctx ctx;
  1078. struct usb_device *udev = testdev_to_usbdev(dev);
  1079. void *buf;
  1080. dma_addr_t buf_dma;
  1081. int i;
  1082. int retval = -ENOMEM;
  1083. init_completion(&ctx.complete);
  1084. atomic_set(&ctx.pending, 1); /* One more than the actual value */
  1085. ctx.num = num;
  1086. ctx.status = 0;
  1087. buf = usb_alloc_coherent(udev, size, GFP_KERNEL, &buf_dma);
  1088. if (!buf)
  1089. return retval;
  1090. memset(buf, 0, size);
  1091. /* Allocate and init the urbs we'll queue */
  1092. ctx.urbs = kcalloc(num, sizeof(struct urb *), GFP_KERNEL);
  1093. if (!ctx.urbs)
  1094. goto free_buf;
  1095. for (i = 0; i < num; i++) {
  1096. ctx.urbs[i] = usb_alloc_urb(0, GFP_KERNEL);
  1097. if (!ctx.urbs[i])
  1098. goto free_urbs;
  1099. usb_fill_bulk_urb(ctx.urbs[i], udev, pipe, buf, size,
  1100. unlink_queued_callback, &ctx);
  1101. ctx.urbs[i]->transfer_dma = buf_dma;
  1102. ctx.urbs[i]->transfer_flags = URB_NO_TRANSFER_DMA_MAP;
  1103. }
  1104. /* Submit all the URBs and then unlink URBs num - 4 and num - 2. */
  1105. for (i = 0; i < num; i++) {
  1106. atomic_inc(&ctx.pending);
  1107. retval = usb_submit_urb(ctx.urbs[i], GFP_KERNEL);
  1108. if (retval != 0) {
  1109. dev_err(&dev->intf->dev, "submit urbs[%d] fail %d\n",
  1110. i, retval);
  1111. atomic_dec(&ctx.pending);
  1112. ctx.status = retval;
  1113. break;
  1114. }
  1115. }
  1116. if (i == num) {
  1117. usb_unlink_urb(ctx.urbs[num - 4]);
  1118. usb_unlink_urb(ctx.urbs[num - 2]);
  1119. } else {
  1120. while (--i >= 0)
  1121. usb_unlink_urb(ctx.urbs[i]);
  1122. }
  1123. if (atomic_dec_and_test(&ctx.pending)) /* The extra count */
  1124. complete(&ctx.complete);
  1125. wait_for_completion(&ctx.complete);
  1126. retval = ctx.status;
  1127. free_urbs:
  1128. for (i = 0; i < num; i++)
  1129. usb_free_urb(ctx.urbs[i]);
  1130. kfree(ctx.urbs);
  1131. free_buf:
  1132. usb_free_coherent(udev, size, buf, buf_dma);
  1133. return retval;
  1134. }
  1135. /*-------------------------------------------------------------------------*/
  1136. static int verify_not_halted(struct usbtest_dev *tdev, int ep, struct urb *urb)
  1137. {
  1138. int retval;
  1139. u16 status;
  1140. /* shouldn't look or act halted */
  1141. retval = usb_get_status(urb->dev, USB_RECIP_ENDPOINT, ep, &status);
  1142. if (retval < 0) {
  1143. ERROR(tdev, "ep %02x couldn't get no-halt status, %d\n",
  1144. ep, retval);
  1145. return retval;
  1146. }
  1147. if (status != 0) {
  1148. ERROR(tdev, "ep %02x bogus status: %04x != 0\n", ep, status);
  1149. return -EINVAL;
  1150. }
  1151. retval = simple_io(tdev, urb, 1, 0, 0, __func__);
  1152. if (retval != 0)
  1153. return -EINVAL;
  1154. return 0;
  1155. }
  1156. static int verify_halted(struct usbtest_dev *tdev, int ep, struct urb *urb)
  1157. {
  1158. int retval;
  1159. u16 status;
  1160. /* should look and act halted */
  1161. retval = usb_get_status(urb->dev, USB_RECIP_ENDPOINT, ep, &status);
  1162. if (retval < 0) {
  1163. ERROR(tdev, "ep %02x couldn't get halt status, %d\n",
  1164. ep, retval);
  1165. return retval;
  1166. }
  1167. le16_to_cpus(&status);
  1168. if (status != 1) {
  1169. ERROR(tdev, "ep %02x bogus status: %04x != 1\n", ep, status);
  1170. return -EINVAL;
  1171. }
  1172. retval = simple_io(tdev, urb, 1, 0, -EPIPE, __func__);
  1173. if (retval != -EPIPE)
  1174. return -EINVAL;
  1175. retval = simple_io(tdev, urb, 1, 0, -EPIPE, "verify_still_halted");
  1176. if (retval != -EPIPE)
  1177. return -EINVAL;
  1178. return 0;
  1179. }
  1180. static int test_halt(struct usbtest_dev *tdev, int ep, struct urb *urb)
  1181. {
  1182. int retval;
  1183. /* shouldn't look or act halted now */
  1184. retval = verify_not_halted(tdev, ep, urb);
  1185. if (retval < 0)
  1186. return retval;
  1187. /* set halt (protocol test only), verify it worked */
  1188. retval = usb_control_msg(urb->dev, usb_sndctrlpipe(urb->dev, 0),
  1189. USB_REQ_SET_FEATURE, USB_RECIP_ENDPOINT,
  1190. USB_ENDPOINT_HALT, ep,
  1191. NULL, 0, USB_CTRL_SET_TIMEOUT);
  1192. if (retval < 0) {
  1193. ERROR(tdev, "ep %02x couldn't set halt, %d\n", ep, retval);
  1194. return retval;
  1195. }
  1196. retval = verify_halted(tdev, ep, urb);
  1197. if (retval < 0)
  1198. return retval;
  1199. /* clear halt (tests API + protocol), verify it worked */
  1200. retval = usb_clear_halt(urb->dev, urb->pipe);
  1201. if (retval < 0) {
  1202. ERROR(tdev, "ep %02x couldn't clear halt, %d\n", ep, retval);
  1203. return retval;
  1204. }
  1205. retval = verify_not_halted(tdev, ep, urb);
  1206. if (retval < 0)
  1207. return retval;
  1208. /* NOTE: could also verify SET_INTERFACE clear halts ... */
  1209. return 0;
  1210. }
  1211. static int halt_simple(struct usbtest_dev *dev)
  1212. {
  1213. int ep;
  1214. int retval = 0;
  1215. struct urb *urb;
  1216. urb = simple_alloc_urb(testdev_to_usbdev(dev), 0, 512);
  1217. if (urb == NULL)
  1218. return -ENOMEM;
  1219. if (dev->in_pipe) {
  1220. ep = usb_pipeendpoint(dev->in_pipe) | USB_DIR_IN;
  1221. urb->pipe = dev->in_pipe;
  1222. retval = test_halt(dev, ep, urb);
  1223. if (retval < 0)
  1224. goto done;
  1225. }
  1226. if (dev->out_pipe) {
  1227. ep = usb_pipeendpoint(dev->out_pipe);
  1228. urb->pipe = dev->out_pipe;
  1229. retval = test_halt(dev, ep, urb);
  1230. }
  1231. done:
  1232. simple_free_urb(urb);
  1233. return retval;
  1234. }
  1235. /*-------------------------------------------------------------------------*/
  1236. /* Control OUT tests use the vendor control requests from Intel's
  1237. * USB 2.0 compliance test device: write a buffer, read it back.
  1238. *
  1239. * Intel's spec only _requires_ that it work for one packet, which
  1240. * is pretty weak. Some HCDs place limits here; most devices will
  1241. * need to be able to handle more than one OUT data packet. We'll
  1242. * try whatever we're told to try.
  1243. */
  1244. static int ctrl_out(struct usbtest_dev *dev,
  1245. unsigned count, unsigned length, unsigned vary, unsigned offset)
  1246. {
  1247. unsigned i, j, len;
  1248. int retval;
  1249. u8 *buf;
  1250. char *what = "?";
  1251. struct usb_device *udev;
  1252. if (length < 1 || length > 0xffff || vary >= length)
  1253. return -EINVAL;
  1254. buf = kmalloc(length + offset, GFP_KERNEL);
  1255. if (!buf)
  1256. return -ENOMEM;
  1257. buf += offset;
  1258. udev = testdev_to_usbdev(dev);
  1259. len = length;
  1260. retval = 0;
  1261. /* NOTE: hardware might well act differently if we pushed it
  1262. * with lots back-to-back queued requests.
  1263. */
  1264. for (i = 0; i < count; i++) {
  1265. /* write patterned data */
  1266. for (j = 0; j < len; j++)
  1267. buf[j] = i + j;
  1268. retval = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
  1269. 0x5b, USB_DIR_OUT|USB_TYPE_VENDOR,
  1270. 0, 0, buf, len, USB_CTRL_SET_TIMEOUT);
  1271. if (retval != len) {
  1272. what = "write";
  1273. if (retval >= 0) {
  1274. ERROR(dev, "ctrl_out, wlen %d (expected %d)\n",
  1275. retval, len);
  1276. retval = -EBADMSG;
  1277. }
  1278. break;
  1279. }
  1280. /* read it back -- assuming nothing intervened!! */
  1281. retval = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
  1282. 0x5c, USB_DIR_IN|USB_TYPE_VENDOR,
  1283. 0, 0, buf, len, USB_CTRL_GET_TIMEOUT);
  1284. if (retval != len) {
  1285. what = "read";
  1286. if (retval >= 0) {
  1287. ERROR(dev, "ctrl_out, rlen %d (expected %d)\n",
  1288. retval, len);
  1289. retval = -EBADMSG;
  1290. }
  1291. break;
  1292. }
  1293. /* fail if we can't verify */
  1294. for (j = 0; j < len; j++) {
  1295. if (buf[j] != (u8) (i + j)) {
  1296. ERROR(dev, "ctrl_out, byte %d is %d not %d\n",
  1297. j, buf[j], (u8) i + j);
  1298. retval = -EBADMSG;
  1299. break;
  1300. }
  1301. }
  1302. if (retval < 0) {
  1303. what = "verify";
  1304. break;
  1305. }
  1306. len += vary;
  1307. /* [real world] the "zero bytes IN" case isn't really used.
  1308. * hardware can easily trip up in this weird case, since its
  1309. * status stage is IN, not OUT like other ep0in transfers.
  1310. */
  1311. if (len > length)
  1312. len = realworld ? 1 : 0;
  1313. }
  1314. if (retval < 0)
  1315. ERROR(dev, "ctrl_out %s failed, code %d, count %d\n",
  1316. what, retval, i);
  1317. kfree(buf - offset);
  1318. return retval;
  1319. }
  1320. /*-------------------------------------------------------------------------*/
  1321. /* ISO tests ... mimics common usage
  1322. * - buffer length is split into N packets (mostly maxpacket sized)
  1323. * - multi-buffers according to sglen
  1324. */
  1325. struct iso_context {
  1326. unsigned count;
  1327. unsigned pending;
  1328. spinlock_t lock;
  1329. struct completion done;
  1330. int submit_error;
  1331. unsigned long errors;
  1332. unsigned long packet_count;
  1333. struct usbtest_dev *dev;
  1334. };
  1335. static void iso_callback(struct urb *urb)
  1336. {
  1337. struct iso_context *ctx = urb->context;
  1338. spin_lock(&ctx->lock);
  1339. ctx->count--;
  1340. ctx->packet_count += urb->number_of_packets;
  1341. if (urb->error_count > 0)
  1342. ctx->errors += urb->error_count;
  1343. else if (urb->status != 0)
  1344. ctx->errors += urb->number_of_packets;
  1345. else if (urb->actual_length != urb->transfer_buffer_length)
  1346. ctx->errors++;
  1347. else if (check_guard_bytes(ctx->dev, urb) != 0)
  1348. ctx->errors++;
  1349. if (urb->status == 0 && ctx->count > (ctx->pending - 1)
  1350. && !ctx->submit_error) {
  1351. int status = usb_submit_urb(urb, GFP_ATOMIC);
  1352. switch (status) {
  1353. case 0:
  1354. goto done;
  1355. default:
  1356. dev_err(&ctx->dev->intf->dev,
  1357. "iso resubmit err %d\n",
  1358. status);
  1359. /* FALLTHROUGH */
  1360. case -ENODEV: /* disconnected */
  1361. case -ESHUTDOWN: /* endpoint disabled */
  1362. ctx->submit_error = 1;
  1363. break;
  1364. }
  1365. }
  1366. ctx->pending--;
  1367. if (ctx->pending == 0) {
  1368. if (ctx->errors)
  1369. dev_err(&ctx->dev->intf->dev,
  1370. "iso test, %lu errors out of %lu\n",
  1371. ctx->errors, ctx->packet_count);
  1372. complete(&ctx->done);
  1373. }
  1374. done:
  1375. spin_unlock(&ctx->lock);
  1376. }
  1377. static struct urb *iso_alloc_urb(
  1378. struct usb_device *udev,
  1379. int pipe,
  1380. struct usb_endpoint_descriptor *desc,
  1381. long bytes,
  1382. unsigned offset
  1383. )
  1384. {
  1385. struct urb *urb;
  1386. unsigned i, maxp, packets;
  1387. if (bytes < 0 || !desc)
  1388. return NULL;
  1389. maxp = 0x7ff & usb_endpoint_maxp(desc);
  1390. maxp *= 1 + (0x3 & (usb_endpoint_maxp(desc) >> 11));
  1391. packets = DIV_ROUND_UP(bytes, maxp);
  1392. urb = usb_alloc_urb(packets, GFP_KERNEL);
  1393. if (!urb)
  1394. return urb;
  1395. urb->dev = udev;
  1396. urb->pipe = pipe;
  1397. urb->number_of_packets = packets;
  1398. urb->transfer_buffer_length = bytes;
  1399. urb->transfer_buffer = usb_alloc_coherent(udev, bytes + offset,
  1400. GFP_KERNEL,
  1401. &urb->transfer_dma);
  1402. if (!urb->transfer_buffer) {
  1403. usb_free_urb(urb);
  1404. return NULL;
  1405. }
  1406. if (offset) {
  1407. memset(urb->transfer_buffer, GUARD_BYTE, offset);
  1408. urb->transfer_buffer += offset;
  1409. urb->transfer_dma += offset;
  1410. }
  1411. /* For inbound transfers use guard byte so that test fails if
  1412. data not correctly copied */
  1413. memset(urb->transfer_buffer,
  1414. usb_pipein(urb->pipe) ? GUARD_BYTE : 0,
  1415. bytes);
  1416. for (i = 0; i < packets; i++) {
  1417. /* here, only the last packet will be short */
  1418. urb->iso_frame_desc[i].length = min((unsigned) bytes, maxp);
  1419. bytes -= urb->iso_frame_desc[i].length;
  1420. urb->iso_frame_desc[i].offset = maxp * i;
  1421. }
  1422. urb->complete = iso_callback;
  1423. /* urb->context = SET BY CALLER */
  1424. urb->interval = 1 << (desc->bInterval - 1);
  1425. urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
  1426. return urb;
  1427. }
  1428. static int
  1429. test_iso_queue(struct usbtest_dev *dev, struct usbtest_param *param,
  1430. int pipe, struct usb_endpoint_descriptor *desc, unsigned offset)
  1431. {
  1432. struct iso_context context;
  1433. struct usb_device *udev;
  1434. unsigned i;
  1435. unsigned long packets = 0;
  1436. int status = 0;
  1437. struct urb *urbs[10]; /* FIXME no limit */
  1438. if (param->sglen > 10)
  1439. return -EDOM;
  1440. memset(&context, 0, sizeof context);
  1441. context.count = param->iterations * param->sglen;
  1442. context.dev = dev;
  1443. init_completion(&context.done);
  1444. spin_lock_init(&context.lock);
  1445. memset(urbs, 0, sizeof urbs);
  1446. udev = testdev_to_usbdev(dev);
  1447. dev_info(&dev->intf->dev,
  1448. "... iso period %d %sframes, wMaxPacket %04x\n",
  1449. 1 << (desc->bInterval - 1),
  1450. (udev->speed == USB_SPEED_HIGH) ? "micro" : "",
  1451. usb_endpoint_maxp(desc));
  1452. for (i = 0; i < param->sglen; i++) {
  1453. urbs[i] = iso_alloc_urb(udev, pipe, desc,
  1454. param->length, offset);
  1455. if (!urbs[i]) {
  1456. status = -ENOMEM;
  1457. goto fail;
  1458. }
  1459. packets += urbs[i]->number_of_packets;
  1460. urbs[i]->context = &context;
  1461. }
  1462. packets *= param->iterations;
  1463. dev_info(&dev->intf->dev,
  1464. "... total %lu msec (%lu packets)\n",
  1465. (packets * (1 << (desc->bInterval - 1)))
  1466. / ((udev->speed == USB_SPEED_HIGH) ? 8 : 1),
  1467. packets);
  1468. spin_lock_irq(&context.lock);
  1469. for (i = 0; i < param->sglen; i++) {
  1470. ++context.pending;
  1471. status = usb_submit_urb(urbs[i], GFP_ATOMIC);
  1472. if (status < 0) {
  1473. ERROR(dev, "submit iso[%d], error %d\n", i, status);
  1474. if (i == 0) {
  1475. spin_unlock_irq(&context.lock);
  1476. goto fail;
  1477. }
  1478. simple_free_urb(urbs[i]);
  1479. urbs[i] = NULL;
  1480. context.pending--;
  1481. context.submit_error = 1;
  1482. break;
  1483. }
  1484. }
  1485. spin_unlock_irq(&context.lock);
  1486. wait_for_completion(&context.done);
  1487. for (i = 0; i < param->sglen; i++) {
  1488. if (urbs[i])
  1489. simple_free_urb(urbs[i]);
  1490. }
  1491. /*
  1492. * Isochronous transfers are expected to fail sometimes. As an
  1493. * arbitrary limit, we will report an error if any submissions
  1494. * fail or if the transfer failure rate is > 10%.
  1495. */
  1496. if (status != 0)
  1497. ;
  1498. else if (context.submit_error)
  1499. status = -EACCES;
  1500. else if (context.errors > context.packet_count / 10)
  1501. status = -EIO;
  1502. return status;
  1503. fail:
  1504. for (i = 0; i < param->sglen; i++) {
  1505. if (urbs[i])
  1506. simple_free_urb(urbs[i]);
  1507. }
  1508. return status;
  1509. }
  1510. static int test_unaligned_bulk(
  1511. struct usbtest_dev *tdev,
  1512. int pipe,
  1513. unsigned length,
  1514. int iterations,
  1515. unsigned transfer_flags,
  1516. const char *label)
  1517. {
  1518. int retval;
  1519. struct urb *urb = usbtest_alloc_urb(
  1520. testdev_to_usbdev(tdev), pipe, length, transfer_flags, 1);
  1521. if (!urb)
  1522. return -ENOMEM;
  1523. retval = simple_io(tdev, urb, iterations, 0, 0, label);
  1524. simple_free_urb(urb);
  1525. return retval;
  1526. }
  1527. /*-------------------------------------------------------------------------*/
  1528. /* We only have this one interface to user space, through usbfs.
  1529. * User mode code can scan usbfs to find N different devices (maybe on
  1530. * different busses) to use when testing, and allocate one thread per
  1531. * test. So discovery is simplified, and we have no device naming issues.
  1532. *
  1533. * Don't use these only as stress/load tests. Use them along with with
  1534. * other USB bus activity: plugging, unplugging, mousing, mp3 playback,
  1535. * video capture, and so on. Run different tests at different times, in
  1536. * different sequences. Nothing here should interact with other devices,
  1537. * except indirectly by consuming USB bandwidth and CPU resources for test
  1538. * threads and request completion. But the only way to know that for sure
  1539. * is to test when HC queues are in use by many devices.
  1540. *
  1541. * WARNING: Because usbfs grabs udev->dev.sem before calling this ioctl(),
  1542. * it locks out usbcore in certain code paths. Notably, if you disconnect
  1543. * the device-under-test, khubd will wait block forever waiting for the
  1544. * ioctl to complete ... so that usb_disconnect() can abort the pending
  1545. * urbs and then call usbtest_disconnect(). To abort a test, you're best
  1546. * off just killing the userspace task and waiting for it to exit.
  1547. */
  1548. static int
  1549. usbtest_ioctl(struct usb_interface *intf, unsigned int code, void *buf)
  1550. {
  1551. struct usbtest_dev *dev = usb_get_intfdata(intf);
  1552. struct usb_device *udev = testdev_to_usbdev(dev);
  1553. struct usbtest_param *param = buf;
  1554. int retval = -EOPNOTSUPP;
  1555. struct urb *urb;
  1556. struct scatterlist *sg;
  1557. struct usb_sg_request req;
  1558. struct timeval start;
  1559. unsigned i;
  1560. /* FIXME USBDEVFS_CONNECTINFO doesn't say how fast the device is. */
  1561. pattern = mod_pattern;
  1562. if (code != USBTEST_REQUEST)
  1563. return -EOPNOTSUPP;
  1564. if (param->iterations <= 0)
  1565. return -EINVAL;
  1566. if (mutex_lock_interruptible(&dev->lock))
  1567. return -ERESTARTSYS;
  1568. /* FIXME: What if a system sleep starts while a test is running? */
  1569. /* some devices, like ez-usb default devices, need a non-default
  1570. * altsetting to have any active endpoints. some tests change
  1571. * altsettings; force a default so most tests don't need to check.
  1572. */
  1573. if (dev->info->alt >= 0) {
  1574. int res;
  1575. if (intf->altsetting->desc.bInterfaceNumber) {
  1576. mutex_unlock(&dev->lock);
  1577. return -ENODEV;
  1578. }
  1579. res = set_altsetting(dev, dev->info->alt);
  1580. if (res) {
  1581. dev_err(&intf->dev,
  1582. "set altsetting to %d failed, %d\n",
  1583. dev->info->alt, res);
  1584. mutex_unlock(&dev->lock);
  1585. return res;
  1586. }
  1587. }
  1588. /*
  1589. * Just a bunch of test cases that every HCD is expected to handle.
  1590. *
  1591. * Some may need specific firmware, though it'd be good to have
  1592. * one firmware image to handle all the test cases.
  1593. *
  1594. * FIXME add more tests! cancel requests, verify the data, control
  1595. * queueing, concurrent read+write threads, and so on.
  1596. */
  1597. do_gettimeofday(&start);
  1598. switch (param->test_num) {
  1599. case 0:
  1600. dev_info(&intf->dev, "TEST 0: NOP\n");
  1601. retval = 0;
  1602. break;
  1603. /* Simple non-queued bulk I/O tests */
  1604. case 1:
  1605. if (dev->out_pipe == 0)
  1606. break;
  1607. dev_info(&intf->dev,
  1608. "TEST 1: write %d bytes %u times\n",
  1609. param->length, param->iterations);
  1610. urb = simple_alloc_urb(udev, dev->out_pipe, param->length);
  1611. if (!urb) {
  1612. retval = -ENOMEM;
  1613. break;
  1614. }
  1615. /* FIRMWARE: bulk sink (maybe accepts short writes) */
  1616. retval = simple_io(dev, urb, param->iterations, 0, 0, "test1");
  1617. simple_free_urb(urb);
  1618. break;
  1619. case 2:
  1620. if (dev->in_pipe == 0)
  1621. break;
  1622. dev_info(&intf->dev,
  1623. "TEST 2: read %d bytes %u times\n",
  1624. param->length, param->iterations);
  1625. urb = simple_alloc_urb(udev, dev->in_pipe, param->length);
  1626. if (!urb) {
  1627. retval = -ENOMEM;
  1628. break;
  1629. }
  1630. /* FIRMWARE: bulk source (maybe generates short writes) */
  1631. retval = simple_io(dev, urb, param->iterations, 0, 0, "test2");
  1632. simple_free_urb(urb);
  1633. break;
  1634. case 3:
  1635. if (dev->out_pipe == 0 || param->vary == 0)
  1636. break;
  1637. dev_info(&intf->dev,
  1638. "TEST 3: write/%d 0..%d bytes %u times\n",
  1639. param->vary, param->length, param->iterations);
  1640. urb = simple_alloc_urb(udev, dev->out_pipe, param->length);
  1641. if (!urb) {
  1642. retval = -ENOMEM;
  1643. break;
  1644. }
  1645. /* FIRMWARE: bulk sink (maybe accepts short writes) */
  1646. retval = simple_io(dev, urb, param->iterations, param->vary,
  1647. 0, "test3");
  1648. simple_free_urb(urb);
  1649. break;
  1650. case 4:
  1651. if (dev->in_pipe == 0 || param->vary == 0)
  1652. break;
  1653. dev_info(&intf->dev,
  1654. "TEST 4: read/%d 0..%d bytes %u times\n",
  1655. param->vary, param->length, param->iterations);
  1656. urb = simple_alloc_urb(udev, dev->in_pipe, param->length);
  1657. if (!urb) {
  1658. retval = -ENOMEM;
  1659. break;
  1660. }
  1661. /* FIRMWARE: bulk source (maybe generates short writes) */
  1662. retval = simple_io(dev, urb, param->iterations, param->vary,
  1663. 0, "test4");
  1664. simple_free_urb(urb);
  1665. break;
  1666. /* Queued bulk I/O tests */
  1667. case 5:
  1668. if (dev->out_pipe == 0 || param->sglen == 0)
  1669. break;
  1670. dev_info(&intf->dev,
  1671. "TEST 5: write %d sglists %d entries of %d bytes\n",
  1672. param->iterations,
  1673. param->sglen, param->length);
  1674. sg = alloc_sglist(param->sglen, param->length, 0);
  1675. if (!sg) {
  1676. retval = -ENOMEM;
  1677. break;
  1678. }
  1679. /* FIRMWARE: bulk sink (maybe accepts short writes) */
  1680. retval = perform_sglist(dev, param->iterations, dev->out_pipe,
  1681. &req, sg, param->sglen);
  1682. free_sglist(sg, param->sglen);
  1683. break;
  1684. case 6:
  1685. if (dev->in_pipe == 0 || param->sglen == 0)
  1686. break;
  1687. dev_info(&intf->dev,
  1688. "TEST 6: read %d sglists %d entries of %d bytes\n",
  1689. param->iterations,
  1690. param->sglen, param->length);
  1691. sg = alloc_sglist(param->sglen, param->length, 0);
  1692. if (!sg) {
  1693. retval = -ENOMEM;
  1694. break;
  1695. }
  1696. /* FIRMWARE: bulk source (maybe generates short writes) */
  1697. retval = perform_sglist(dev, param->iterations, dev->in_pipe,
  1698. &req, sg, param->sglen);
  1699. free_sglist(sg, param->sglen);
  1700. break;
  1701. case 7:
  1702. if (dev->out_pipe == 0 || param->sglen == 0 || param->vary == 0)
  1703. break;
  1704. dev_info(&intf->dev,
  1705. "TEST 7: write/%d %d sglists %d entries 0..%d bytes\n",
  1706. param->vary, param->iterations,
  1707. param->sglen, param->length);
  1708. sg = alloc_sglist(param->sglen, param->length, param->vary);
  1709. if (!sg) {
  1710. retval = -ENOMEM;
  1711. break;
  1712. }
  1713. /* FIRMWARE: bulk sink (maybe accepts short writes) */
  1714. retval = perform_sglist(dev, param->iterations, dev->out_pipe,
  1715. &req, sg, param->sglen);
  1716. free_sglist(sg, param->sglen);
  1717. break;
  1718. case 8:
  1719. if (dev->in_pipe == 0 || param->sglen == 0 || param->vary == 0)
  1720. break;
  1721. dev_info(&intf->dev,
  1722. "TEST 8: read/%d %d sglists %d entries 0..%d bytes\n",
  1723. param->vary, param->iterations,
  1724. param->sglen, param->length);
  1725. sg = alloc_sglist(param->sglen, param->length, param->vary);
  1726. if (!sg) {
  1727. retval = -ENOMEM;
  1728. break;
  1729. }
  1730. /* FIRMWARE: bulk source (maybe generates short writes) */
  1731. retval = perform_sglist(dev, param->iterations, dev->in_pipe,
  1732. &req, sg, param->sglen);
  1733. free_sglist(sg, param->sglen);
  1734. break;
  1735. /* non-queued sanity tests for control (chapter 9 subset) */
  1736. case 9:
  1737. retval = 0;
  1738. dev_info(&intf->dev,
  1739. "TEST 9: ch9 (subset) control tests, %d times\n",
  1740. param->iterations);
  1741. for (i = param->iterations; retval == 0 && i--; /* NOP */)
  1742. retval = ch9_postconfig(dev);
  1743. if (retval)
  1744. dev_err(&intf->dev, "ch9 subset failed, "
  1745. "iterations left %d\n", i);
  1746. break;
  1747. /* queued control messaging */
  1748. case 10:
  1749. if (param->sglen == 0)
  1750. break;
  1751. retval = 0;
  1752. dev_info(&intf->dev,
  1753. "TEST 10: queue %d control calls, %d times\n",
  1754. param->sglen,
  1755. param->iterations);
  1756. retval = test_ctrl_queue(dev, param);
  1757. break;
  1758. /* simple non-queued unlinks (ring with one urb) */
  1759. case 11:
  1760. if (dev->in_pipe == 0 || !param->length)
  1761. break;
  1762. retval = 0;
  1763. dev_info(&intf->dev, "TEST 11: unlink %d reads of %d\n",
  1764. param->iterations, param->length);
  1765. for (i = param->iterations; retval == 0 && i--; /* NOP */)
  1766. retval = unlink_simple(dev, dev->in_pipe,
  1767. param->length);
  1768. if (retval)
  1769. dev_err(&intf->dev, "unlink reads failed %d, "
  1770. "iterations left %d\n", retval, i);
  1771. break;
  1772. case 12:
  1773. if (dev->out_pipe == 0 || !param->length)
  1774. break;
  1775. retval = 0;
  1776. dev_info(&intf->dev, "TEST 12: unlink %d writes of %d\n",
  1777. param->iterations, param->length);
  1778. for (i = param->iterations; retval == 0 && i--; /* NOP */)
  1779. retval = unlink_simple(dev, dev->out_pipe,
  1780. param->length);
  1781. if (retval)
  1782. dev_err(&intf->dev, "unlink writes failed %d, "
  1783. "iterations left %d\n", retval, i);
  1784. break;
  1785. /* ep halt tests */
  1786. case 13:
  1787. if (dev->out_pipe == 0 && dev->in_pipe == 0)
  1788. break;
  1789. retval = 0;
  1790. dev_info(&intf->dev, "TEST 13: set/clear %d halts\n",
  1791. param->iterations);
  1792. for (i = param->iterations; retval == 0 && i--; /* NOP */)
  1793. retval = halt_simple(dev);
  1794. if (retval)
  1795. ERROR(dev, "halts failed, iterations left %d\n", i);
  1796. break;
  1797. /* control write tests */
  1798. case 14:
  1799. if (!dev->info->ctrl_out)
  1800. break;
  1801. dev_info(&intf->dev, "TEST 14: %d ep0out, %d..%d vary %d\n",
  1802. param->iterations,
  1803. realworld ? 1 : 0, param->length,
  1804. param->vary);
  1805. retval = ctrl_out(dev, param->iterations,
  1806. param->length, param->vary, 0);
  1807. break;
  1808. /* iso write tests */
  1809. case 15:
  1810. if (dev->out_iso_pipe == 0 || param->sglen == 0)
  1811. break;
  1812. dev_info(&intf->dev,
  1813. "TEST 15: write %d iso, %d entries of %d bytes\n",
  1814. param->iterations,
  1815. param->sglen, param->length);
  1816. /* FIRMWARE: iso sink */
  1817. retval = test_iso_queue(dev, param,
  1818. dev->out_iso_pipe, dev->iso_out, 0);
  1819. break;
  1820. /* iso read tests */
  1821. case 16:
  1822. if (dev->in_iso_pipe == 0 || param->sglen == 0)
  1823. break;
  1824. dev_info(&intf->dev,
  1825. "TEST 16: read %d iso, %d entries of %d bytes\n",
  1826. param->iterations,
  1827. param->sglen, param->length);
  1828. /* FIRMWARE: iso source */
  1829. retval = test_iso_queue(dev, param,
  1830. dev->in_iso_pipe, dev->iso_in, 0);
  1831. break;
  1832. /* FIXME scatterlist cancel (needs helper thread) */
  1833. /* Tests for bulk I/O using DMA mapping by core and odd address */
  1834. case 17:
  1835. if (dev->out_pipe == 0)
  1836. break;
  1837. dev_info(&intf->dev,
  1838. "TEST 17: write odd addr %d bytes %u times core map\n",
  1839. param->length, param->iterations);
  1840. retval = test_unaligned_bulk(
  1841. dev, dev->out_pipe,
  1842. param->length, param->iterations,
  1843. 0, "test17");
  1844. break;
  1845. case 18:
  1846. if (dev->in_pipe == 0)
  1847. break;
  1848. dev_info(&intf->dev,
  1849. "TEST 18: read odd addr %d bytes %u times core map\n",
  1850. param->length, param->iterations);
  1851. retval = test_unaligned_bulk(
  1852. dev, dev->in_pipe,
  1853. param->length, param->iterations,
  1854. 0, "test18");
  1855. break;
  1856. /* Tests for bulk I/O using premapped coherent buffer and odd address */
  1857. case 19:
  1858. if (dev->out_pipe == 0)
  1859. break;
  1860. dev_info(&intf->dev,
  1861. "TEST 19: write odd addr %d bytes %u times premapped\n",
  1862. param->length, param->iterations);
  1863. retval = test_unaligned_bulk(
  1864. dev, dev->out_pipe,
  1865. param->length, param->iterations,
  1866. URB_NO_TRANSFER_DMA_MAP, "test19");
  1867. break;
  1868. case 20:
  1869. if (dev->in_pipe == 0)
  1870. break;
  1871. dev_info(&intf->dev,
  1872. "TEST 20: read odd addr %d bytes %u times premapped\n",
  1873. param->length, param->iterations);
  1874. retval = test_unaligned_bulk(
  1875. dev, dev->in_pipe,
  1876. param->length, param->iterations,
  1877. URB_NO_TRANSFER_DMA_MAP, "test20");
  1878. break;
  1879. /* control write tests with unaligned buffer */
  1880. case 21:
  1881. if (!dev->info->ctrl_out)
  1882. break;
  1883. dev_info(&intf->dev,
  1884. "TEST 21: %d ep0out odd addr, %d..%d vary %d\n",
  1885. param->iterations,
  1886. realworld ? 1 : 0, param->length,
  1887. param->vary);
  1888. retval = ctrl_out(dev, param->iterations,
  1889. param->length, param->vary, 1);
  1890. break;
  1891. /* unaligned iso tests */
  1892. case 22:
  1893. if (dev->out_iso_pipe == 0 || param->sglen == 0)
  1894. break;
  1895. dev_info(&intf->dev,
  1896. "TEST 22: write %d iso odd, %d entries of %d bytes\n",
  1897. param->iterations,
  1898. param->sglen, param->length);
  1899. retval = test_iso_queue(dev, param,
  1900. dev->out_iso_pipe, dev->iso_out, 1);
  1901. break;
  1902. case 23:
  1903. if (dev->in_iso_pipe == 0 || param->sglen == 0)
  1904. break;
  1905. dev_info(&intf->dev,
  1906. "TEST 23: read %d iso odd, %d entries of %d bytes\n",
  1907. param->iterations,
  1908. param->sglen, param->length);
  1909. retval = test_iso_queue(dev, param,
  1910. dev->in_iso_pipe, dev->iso_in, 1);
  1911. break;
  1912. /* unlink URBs from a bulk-OUT queue */
  1913. case 24:
  1914. if (dev->out_pipe == 0 || !param->length || param->sglen < 4)
  1915. break;
  1916. retval = 0;
  1917. dev_info(&intf->dev, "TEST 17: unlink from %d queues of "
  1918. "%d %d-byte writes\n",
  1919. param->iterations, param->sglen, param->length);
  1920. for (i = param->iterations; retval == 0 && i > 0; --i) {
  1921. retval = unlink_queued(dev, dev->out_pipe,
  1922. param->sglen, param->length);
  1923. if (retval) {
  1924. dev_err(&intf->dev,
  1925. "unlink queued writes failed %d, "
  1926. "iterations left %d\n", retval, i);
  1927. break;
  1928. }
  1929. }
  1930. break;
  1931. }
  1932. do_gettimeofday(&param->duration);
  1933. param->duration.tv_sec -= start.tv_sec;
  1934. param->duration.tv_usec -= start.tv_usec;
  1935. if (param->duration.tv_usec < 0) {
  1936. param->duration.tv_usec += 1000 * 1000;
  1937. param->duration.tv_sec -= 1;
  1938. }
  1939. mutex_unlock(&dev->lock);
  1940. return retval;
  1941. }
  1942. /*-------------------------------------------------------------------------*/
  1943. static unsigned force_interrupt;
  1944. module_param(force_interrupt, uint, 0);
  1945. MODULE_PARM_DESC(force_interrupt, "0 = test default; else interrupt");
  1946. #ifdef GENERIC
  1947. static unsigned short vendor;
  1948. module_param(vendor, ushort, 0);
  1949. MODULE_PARM_DESC(vendor, "vendor code (from usb-if)");
  1950. static unsigned short product;
  1951. module_param(product, ushort, 0);
  1952. MODULE_PARM_DESC(product, "product code (from vendor)");
  1953. #endif
  1954. static int
  1955. usbtest_probe(struct usb_interface *intf, const struct usb_device_id *id)
  1956. {
  1957. struct usb_device *udev;
  1958. struct usbtest_dev *dev;
  1959. struct usbtest_info *info;
  1960. char *rtest, *wtest;
  1961. char *irtest, *iwtest;
  1962. udev = interface_to_usbdev(intf);
  1963. #ifdef GENERIC
  1964. /* specify devices by module parameters? */
  1965. if (id->match_flags == 0) {
  1966. /* vendor match required, product match optional */
  1967. if (!vendor || le16_to_cpu(udev->descriptor.idVendor) != (u16)vendor)
  1968. return -ENODEV;
  1969. if (product && le16_to_cpu(udev->descriptor.idProduct) != (u16)product)
  1970. return -ENODEV;
  1971. dev_info(&intf->dev, "matched module params, "
  1972. "vend=0x%04x prod=0x%04x\n",
  1973. le16_to_cpu(udev->descriptor.idVendor),
  1974. le16_to_cpu(udev->descriptor.idProduct));
  1975. }
  1976. #endif
  1977. dev = kzalloc(sizeof(*dev), GFP_KERNEL);
  1978. if (!dev)
  1979. return -ENOMEM;
  1980. info = (struct usbtest_info *) id->driver_info;
  1981. dev->info = info;
  1982. mutex_init(&dev->lock);
  1983. dev->intf = intf;
  1984. /* cacheline-aligned scratch for i/o */
  1985. dev->buf = kmalloc(TBUF_SIZE, GFP_KERNEL);
  1986. if (dev->buf == NULL) {
  1987. kfree(dev);
  1988. return -ENOMEM;
  1989. }
  1990. /* NOTE this doesn't yet test the handful of difference that are
  1991. * visible with high speed interrupts: bigger maxpacket (1K) and
  1992. * "high bandwidth" modes (up to 3 packets/uframe).
  1993. */
  1994. rtest = wtest = "";
  1995. irtest = iwtest = "";
  1996. if (force_interrupt || udev->speed == USB_SPEED_LOW) {
  1997. if (info->ep_in) {
  1998. dev->in_pipe = usb_rcvintpipe(udev, info->ep_in);
  1999. rtest = " intr-in";
  2000. }
  2001. if (info->ep_out) {
  2002. dev->out_pipe = usb_sndintpipe(udev, info->ep_out);
  2003. wtest = " intr-out";
  2004. }
  2005. } else {
  2006. if (info->autoconf) {
  2007. int status;
  2008. status = get_endpoints(dev, intf);
  2009. if (status < 0) {
  2010. WARNING(dev, "couldn't get endpoints, %d\n",
  2011. status);
  2012. return status;
  2013. }
  2014. /* may find bulk or ISO pipes */
  2015. } else {
  2016. if (info->ep_in)
  2017. dev->in_pipe = usb_rcvbulkpipe(udev,
  2018. info->ep_in);
  2019. if (info->ep_out)
  2020. dev->out_pipe = usb_sndbulkpipe(udev,
  2021. info->ep_out);
  2022. }
  2023. if (dev->in_pipe)
  2024. rtest = " bulk-in";
  2025. if (dev->out_pipe)
  2026. wtest = " bulk-out";
  2027. if (dev->in_iso_pipe)
  2028. irtest = " iso-in";
  2029. if (dev->out_iso_pipe)
  2030. iwtest = " iso-out";
  2031. }
  2032. usb_set_intfdata(intf, dev);
  2033. dev_info(&intf->dev, "%s\n", info->name);
  2034. dev_info(&intf->dev, "%s {control%s%s%s%s%s} tests%s\n",
  2035. usb_speed_string(udev->speed),
  2036. info->ctrl_out ? " in/out" : "",
  2037. rtest, wtest,
  2038. irtest, iwtest,
  2039. info->alt >= 0 ? " (+alt)" : "");
  2040. return 0;
  2041. }
  2042. static int usbtest_suspend(struct usb_interface *intf, pm_message_t message)
  2043. {
  2044. return 0;
  2045. }
  2046. static int usbtest_resume(struct usb_interface *intf)
  2047. {
  2048. return 0;
  2049. }
  2050. static void usbtest_disconnect(struct usb_interface *intf)
  2051. {
  2052. struct usbtest_dev *dev = usb_get_intfdata(intf);
  2053. usb_set_intfdata(intf, NULL);
  2054. dev_dbg(&intf->dev, "disconnect\n");
  2055. kfree(dev);
  2056. }
  2057. /* Basic testing only needs a device that can source or sink bulk traffic.
  2058. * Any device can test control transfers (default with GENERIC binding).
  2059. *
  2060. * Several entries work with the default EP0 implementation that's built
  2061. * into EZ-USB chips. There's a default vendor ID which can be overridden
  2062. * by (very) small config EEPROMS, but otherwise all these devices act
  2063. * identically until firmware is loaded: only EP0 works. It turns out
  2064. * to be easy to make other endpoints work, without modifying that EP0
  2065. * behavior. For now, we expect that kind of firmware.
  2066. */
  2067. /* an21xx or fx versions of ez-usb */
  2068. static struct usbtest_info ez1_info = {
  2069. .name = "EZ-USB device",
  2070. .ep_in = 2,
  2071. .ep_out = 2,
  2072. .alt = 1,
  2073. };
  2074. /* fx2 version of ez-usb */
  2075. static struct usbtest_info ez2_info = {
  2076. .name = "FX2 device",
  2077. .ep_in = 6,
  2078. .ep_out = 2,
  2079. .alt = 1,
  2080. };
  2081. /* ezusb family device with dedicated usb test firmware,
  2082. */
  2083. static struct usbtest_info fw_info = {
  2084. .name = "usb test device",
  2085. .ep_in = 2,
  2086. .ep_out = 2,
  2087. .alt = 1,
  2088. .autoconf = 1, /* iso and ctrl_out need autoconf */
  2089. .ctrl_out = 1,
  2090. .iso = 1, /* iso_ep's are #8 in/out */
  2091. };
  2092. /* peripheral running Linux and 'zero.c' test firmware, or
  2093. * its user-mode cousin. different versions of this use
  2094. * different hardware with the same vendor/product codes.
  2095. * host side MUST rely on the endpoint descriptors.
  2096. */
  2097. static struct usbtest_info gz_info = {
  2098. .name = "Linux gadget zero",
  2099. .autoconf = 1,
  2100. .ctrl_out = 1,
  2101. .alt = 0,
  2102. };
  2103. static struct usbtest_info um_info = {
  2104. .name = "Linux user mode test driver",
  2105. .autoconf = 1,
  2106. .alt = -1,
  2107. };
  2108. static struct usbtest_info um2_info = {
  2109. .name = "Linux user mode ISO test driver",
  2110. .autoconf = 1,
  2111. .iso = 1,
  2112. .alt = -1,
  2113. };
  2114. #ifdef IBOT2
  2115. /* this is a nice source of high speed bulk data;
  2116. * uses an FX2, with firmware provided in the device
  2117. */
  2118. static struct usbtest_info ibot2_info = {
  2119. .name = "iBOT2 webcam",
  2120. .ep_in = 2,
  2121. .alt = -1,
  2122. };
  2123. #endif
  2124. #ifdef GENERIC
  2125. /* we can use any device to test control traffic */
  2126. static struct usbtest_info generic_info = {
  2127. .name = "Generic USB device",
  2128. .alt = -1,
  2129. };
  2130. #endif
  2131. static const struct usb_device_id id_table[] = {
  2132. /*-------------------------------------------------------------*/
  2133. /* EZ-USB devices which download firmware to replace (or in our
  2134. * case augment) the default device implementation.
  2135. */
  2136. /* generic EZ-USB FX controller */
  2137. { USB_DEVICE(0x0547, 0x2235),
  2138. .driver_info = (unsigned long) &ez1_info,
  2139. },
  2140. /* CY3671 development board with EZ-USB FX */
  2141. { USB_DEVICE(0x0547, 0x0080),
  2142. .driver_info = (unsigned long) &ez1_info,
  2143. },
  2144. /* generic EZ-USB FX2 controller (or development board) */
  2145. { USB_DEVICE(0x04b4, 0x8613),
  2146. .driver_info = (unsigned long) &ez2_info,
  2147. },
  2148. /* re-enumerated usb test device firmware */
  2149. { USB_DEVICE(0xfff0, 0xfff0),
  2150. .driver_info = (unsigned long) &fw_info,
  2151. },
  2152. /* "Gadget Zero" firmware runs under Linux */
  2153. { USB_DEVICE(0x0525, 0xa4a0),
  2154. .driver_info = (unsigned long) &gz_info,
  2155. },
  2156. /* so does a user-mode variant */
  2157. { USB_DEVICE(0x0525, 0xa4a4),
  2158. .driver_info = (unsigned long) &um_info,
  2159. },
  2160. /* ... and a user-mode variant that talks iso */
  2161. { USB_DEVICE(0x0525, 0xa4a3),
  2162. .driver_info = (unsigned long) &um2_info,
  2163. },
  2164. #ifdef KEYSPAN_19Qi
  2165. /* Keyspan 19qi uses an21xx (original EZ-USB) */
  2166. /* this does not coexist with the real Keyspan 19qi driver! */
  2167. { USB_DEVICE(0x06cd, 0x010b),
  2168. .driver_info = (unsigned long) &ez1_info,
  2169. },
  2170. #endif
  2171. /*-------------------------------------------------------------*/
  2172. #ifdef IBOT2
  2173. /* iBOT2 makes a nice source of high speed bulk-in data */
  2174. /* this does not coexist with a real iBOT2 driver! */
  2175. { USB_DEVICE(0x0b62, 0x0059),
  2176. .driver_info = (unsigned long) &ibot2_info,
  2177. },
  2178. #endif
  2179. /*-------------------------------------------------------------*/
  2180. #ifdef GENERIC
  2181. /* module params can specify devices to use for control tests */
  2182. { .driver_info = (unsigned long) &generic_info, },
  2183. #endif
  2184. /*-------------------------------------------------------------*/
  2185. { }
  2186. };
  2187. MODULE_DEVICE_TABLE(usb, id_table);
  2188. static struct usb_driver usbtest_driver = {
  2189. .name = "usbtest",
  2190. .id_table = id_table,
  2191. .probe = usbtest_probe,
  2192. .unlocked_ioctl = usbtest_ioctl,
  2193. .disconnect = usbtest_disconnect,
  2194. .suspend = usbtest_suspend,
  2195. .resume = usbtest_resume,
  2196. };
  2197. /*-------------------------------------------------------------------------*/
  2198. static int __init usbtest_init(void)
  2199. {
  2200. #ifdef GENERIC
  2201. if (vendor)
  2202. pr_debug("params: vend=0x%04x prod=0x%04x\n", vendor, product);
  2203. #endif
  2204. return usb_register(&usbtest_driver);
  2205. }
  2206. module_init(usbtest_init);
  2207. static void __exit usbtest_exit(void)
  2208. {
  2209. usb_deregister(&usbtest_driver);
  2210. }
  2211. module_exit(usbtest_exit);
  2212. MODULE_DESCRIPTION("USB Core/HCD Testing Driver");
  2213. MODULE_LICENSE("GPL");