usbtest.c 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520
  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. /* No BKL needed */
  1549. static int
  1550. usbtest_ioctl(struct usb_interface *intf, unsigned int code, void *buf)
  1551. {
  1552. struct usbtest_dev *dev = usb_get_intfdata(intf);
  1553. struct usb_device *udev = testdev_to_usbdev(dev);
  1554. struct usbtest_param *param = buf;
  1555. int retval = -EOPNOTSUPP;
  1556. struct urb *urb;
  1557. struct scatterlist *sg;
  1558. struct usb_sg_request req;
  1559. struct timeval start;
  1560. unsigned i;
  1561. /* FIXME USBDEVFS_CONNECTINFO doesn't say how fast the device is. */
  1562. pattern = mod_pattern;
  1563. if (code != USBTEST_REQUEST)
  1564. return -EOPNOTSUPP;
  1565. if (param->iterations <= 0)
  1566. return -EINVAL;
  1567. if (mutex_lock_interruptible(&dev->lock))
  1568. return -ERESTARTSYS;
  1569. /* FIXME: What if a system sleep starts while a test is running? */
  1570. /* some devices, like ez-usb default devices, need a non-default
  1571. * altsetting to have any active endpoints. some tests change
  1572. * altsettings; force a default so most tests don't need to check.
  1573. */
  1574. if (dev->info->alt >= 0) {
  1575. int res;
  1576. if (intf->altsetting->desc.bInterfaceNumber) {
  1577. mutex_unlock(&dev->lock);
  1578. return -ENODEV;
  1579. }
  1580. res = set_altsetting(dev, dev->info->alt);
  1581. if (res) {
  1582. dev_err(&intf->dev,
  1583. "set altsetting to %d failed, %d\n",
  1584. dev->info->alt, res);
  1585. mutex_unlock(&dev->lock);
  1586. return res;
  1587. }
  1588. }
  1589. /*
  1590. * Just a bunch of test cases that every HCD is expected to handle.
  1591. *
  1592. * Some may need specific firmware, though it'd be good to have
  1593. * one firmware image to handle all the test cases.
  1594. *
  1595. * FIXME add more tests! cancel requests, verify the data, control
  1596. * queueing, concurrent read+write threads, and so on.
  1597. */
  1598. do_gettimeofday(&start);
  1599. switch (param->test_num) {
  1600. case 0:
  1601. dev_info(&intf->dev, "TEST 0: NOP\n");
  1602. retval = 0;
  1603. break;
  1604. /* Simple non-queued bulk I/O tests */
  1605. case 1:
  1606. if (dev->out_pipe == 0)
  1607. break;
  1608. dev_info(&intf->dev,
  1609. "TEST 1: write %d bytes %u times\n",
  1610. param->length, param->iterations);
  1611. urb = simple_alloc_urb(udev, dev->out_pipe, param->length);
  1612. if (!urb) {
  1613. retval = -ENOMEM;
  1614. break;
  1615. }
  1616. /* FIRMWARE: bulk sink (maybe accepts short writes) */
  1617. retval = simple_io(dev, urb, param->iterations, 0, 0, "test1");
  1618. simple_free_urb(urb);
  1619. break;
  1620. case 2:
  1621. if (dev->in_pipe == 0)
  1622. break;
  1623. dev_info(&intf->dev,
  1624. "TEST 2: read %d bytes %u times\n",
  1625. param->length, param->iterations);
  1626. urb = simple_alloc_urb(udev, dev->in_pipe, param->length);
  1627. if (!urb) {
  1628. retval = -ENOMEM;
  1629. break;
  1630. }
  1631. /* FIRMWARE: bulk source (maybe generates short writes) */
  1632. retval = simple_io(dev, urb, param->iterations, 0, 0, "test2");
  1633. simple_free_urb(urb);
  1634. break;
  1635. case 3:
  1636. if (dev->out_pipe == 0 || param->vary == 0)
  1637. break;
  1638. dev_info(&intf->dev,
  1639. "TEST 3: write/%d 0..%d bytes %u times\n",
  1640. param->vary, param->length, param->iterations);
  1641. urb = simple_alloc_urb(udev, dev->out_pipe, param->length);
  1642. if (!urb) {
  1643. retval = -ENOMEM;
  1644. break;
  1645. }
  1646. /* FIRMWARE: bulk sink (maybe accepts short writes) */
  1647. retval = simple_io(dev, urb, param->iterations, param->vary,
  1648. 0, "test3");
  1649. simple_free_urb(urb);
  1650. break;
  1651. case 4:
  1652. if (dev->in_pipe == 0 || param->vary == 0)
  1653. break;
  1654. dev_info(&intf->dev,
  1655. "TEST 4: read/%d 0..%d bytes %u times\n",
  1656. param->vary, param->length, param->iterations);
  1657. urb = simple_alloc_urb(udev, dev->in_pipe, param->length);
  1658. if (!urb) {
  1659. retval = -ENOMEM;
  1660. break;
  1661. }
  1662. /* FIRMWARE: bulk source (maybe generates short writes) */
  1663. retval = simple_io(dev, urb, param->iterations, param->vary,
  1664. 0, "test4");
  1665. simple_free_urb(urb);
  1666. break;
  1667. /* Queued bulk I/O tests */
  1668. case 5:
  1669. if (dev->out_pipe == 0 || param->sglen == 0)
  1670. break;
  1671. dev_info(&intf->dev,
  1672. "TEST 5: write %d sglists %d entries of %d bytes\n",
  1673. param->iterations,
  1674. param->sglen, param->length);
  1675. sg = alloc_sglist(param->sglen, param->length, 0);
  1676. if (!sg) {
  1677. retval = -ENOMEM;
  1678. break;
  1679. }
  1680. /* FIRMWARE: bulk sink (maybe accepts short writes) */
  1681. retval = perform_sglist(dev, param->iterations, dev->out_pipe,
  1682. &req, sg, param->sglen);
  1683. free_sglist(sg, param->sglen);
  1684. break;
  1685. case 6:
  1686. if (dev->in_pipe == 0 || param->sglen == 0)
  1687. break;
  1688. dev_info(&intf->dev,
  1689. "TEST 6: read %d sglists %d entries of %d bytes\n",
  1690. param->iterations,
  1691. param->sglen, param->length);
  1692. sg = alloc_sglist(param->sglen, param->length, 0);
  1693. if (!sg) {
  1694. retval = -ENOMEM;
  1695. break;
  1696. }
  1697. /* FIRMWARE: bulk source (maybe generates short writes) */
  1698. retval = perform_sglist(dev, param->iterations, dev->in_pipe,
  1699. &req, sg, param->sglen);
  1700. free_sglist(sg, param->sglen);
  1701. break;
  1702. case 7:
  1703. if (dev->out_pipe == 0 || param->sglen == 0 || param->vary == 0)
  1704. break;
  1705. dev_info(&intf->dev,
  1706. "TEST 7: write/%d %d sglists %d entries 0..%d bytes\n",
  1707. param->vary, param->iterations,
  1708. param->sglen, param->length);
  1709. sg = alloc_sglist(param->sglen, param->length, param->vary);
  1710. if (!sg) {
  1711. retval = -ENOMEM;
  1712. break;
  1713. }
  1714. /* FIRMWARE: bulk sink (maybe accepts short writes) */
  1715. retval = perform_sglist(dev, param->iterations, dev->out_pipe,
  1716. &req, sg, param->sglen);
  1717. free_sglist(sg, param->sglen);
  1718. break;
  1719. case 8:
  1720. if (dev->in_pipe == 0 || param->sglen == 0 || param->vary == 0)
  1721. break;
  1722. dev_info(&intf->dev,
  1723. "TEST 8: read/%d %d sglists %d entries 0..%d bytes\n",
  1724. param->vary, param->iterations,
  1725. param->sglen, param->length);
  1726. sg = alloc_sglist(param->sglen, param->length, param->vary);
  1727. if (!sg) {
  1728. retval = -ENOMEM;
  1729. break;
  1730. }
  1731. /* FIRMWARE: bulk source (maybe generates short writes) */
  1732. retval = perform_sglist(dev, param->iterations, dev->in_pipe,
  1733. &req, sg, param->sglen);
  1734. free_sglist(sg, param->sglen);
  1735. break;
  1736. /* non-queued sanity tests for control (chapter 9 subset) */
  1737. case 9:
  1738. retval = 0;
  1739. dev_info(&intf->dev,
  1740. "TEST 9: ch9 (subset) control tests, %d times\n",
  1741. param->iterations);
  1742. for (i = param->iterations; retval == 0 && i--; /* NOP */)
  1743. retval = ch9_postconfig(dev);
  1744. if (retval)
  1745. dev_err(&intf->dev, "ch9 subset failed, "
  1746. "iterations left %d\n", i);
  1747. break;
  1748. /* queued control messaging */
  1749. case 10:
  1750. if (param->sglen == 0)
  1751. break;
  1752. retval = 0;
  1753. dev_info(&intf->dev,
  1754. "TEST 10: queue %d control calls, %d times\n",
  1755. param->sglen,
  1756. param->iterations);
  1757. retval = test_ctrl_queue(dev, param);
  1758. break;
  1759. /* simple non-queued unlinks (ring with one urb) */
  1760. case 11:
  1761. if (dev->in_pipe == 0 || !param->length)
  1762. break;
  1763. retval = 0;
  1764. dev_info(&intf->dev, "TEST 11: unlink %d reads of %d\n",
  1765. param->iterations, param->length);
  1766. for (i = param->iterations; retval == 0 && i--; /* NOP */)
  1767. retval = unlink_simple(dev, dev->in_pipe,
  1768. param->length);
  1769. if (retval)
  1770. dev_err(&intf->dev, "unlink reads failed %d, "
  1771. "iterations left %d\n", retval, i);
  1772. break;
  1773. case 12:
  1774. if (dev->out_pipe == 0 || !param->length)
  1775. break;
  1776. retval = 0;
  1777. dev_info(&intf->dev, "TEST 12: unlink %d writes of %d\n",
  1778. param->iterations, param->length);
  1779. for (i = param->iterations; retval == 0 && i--; /* NOP */)
  1780. retval = unlink_simple(dev, dev->out_pipe,
  1781. param->length);
  1782. if (retval)
  1783. dev_err(&intf->dev, "unlink writes failed %d, "
  1784. "iterations left %d\n", retval, i);
  1785. break;
  1786. /* ep halt tests */
  1787. case 13:
  1788. if (dev->out_pipe == 0 && dev->in_pipe == 0)
  1789. break;
  1790. retval = 0;
  1791. dev_info(&intf->dev, "TEST 13: set/clear %d halts\n",
  1792. param->iterations);
  1793. for (i = param->iterations; retval == 0 && i--; /* NOP */)
  1794. retval = halt_simple(dev);
  1795. if (retval)
  1796. ERROR(dev, "halts failed, iterations left %d\n", i);
  1797. break;
  1798. /* control write tests */
  1799. case 14:
  1800. if (!dev->info->ctrl_out)
  1801. break;
  1802. dev_info(&intf->dev, "TEST 14: %d ep0out, %d..%d vary %d\n",
  1803. param->iterations,
  1804. realworld ? 1 : 0, param->length,
  1805. param->vary);
  1806. retval = ctrl_out(dev, param->iterations,
  1807. param->length, param->vary, 0);
  1808. break;
  1809. /* iso write tests */
  1810. case 15:
  1811. if (dev->out_iso_pipe == 0 || param->sglen == 0)
  1812. break;
  1813. dev_info(&intf->dev,
  1814. "TEST 15: write %d iso, %d entries of %d bytes\n",
  1815. param->iterations,
  1816. param->sglen, param->length);
  1817. /* FIRMWARE: iso sink */
  1818. retval = test_iso_queue(dev, param,
  1819. dev->out_iso_pipe, dev->iso_out, 0);
  1820. break;
  1821. /* iso read tests */
  1822. case 16:
  1823. if (dev->in_iso_pipe == 0 || param->sglen == 0)
  1824. break;
  1825. dev_info(&intf->dev,
  1826. "TEST 16: read %d iso, %d entries of %d bytes\n",
  1827. param->iterations,
  1828. param->sglen, param->length);
  1829. /* FIRMWARE: iso source */
  1830. retval = test_iso_queue(dev, param,
  1831. dev->in_iso_pipe, dev->iso_in, 0);
  1832. break;
  1833. /* FIXME scatterlist cancel (needs helper thread) */
  1834. /* Tests for bulk I/O using DMA mapping by core and odd address */
  1835. case 17:
  1836. if (dev->out_pipe == 0)
  1837. break;
  1838. dev_info(&intf->dev,
  1839. "TEST 17: write odd addr %d bytes %u times core map\n",
  1840. param->length, param->iterations);
  1841. retval = test_unaligned_bulk(
  1842. dev, dev->out_pipe,
  1843. param->length, param->iterations,
  1844. 0, "test17");
  1845. break;
  1846. case 18:
  1847. if (dev->in_pipe == 0)
  1848. break;
  1849. dev_info(&intf->dev,
  1850. "TEST 18: read odd addr %d bytes %u times core map\n",
  1851. param->length, param->iterations);
  1852. retval = test_unaligned_bulk(
  1853. dev, dev->in_pipe,
  1854. param->length, param->iterations,
  1855. 0, "test18");
  1856. break;
  1857. /* Tests for bulk I/O using premapped coherent buffer and odd address */
  1858. case 19:
  1859. if (dev->out_pipe == 0)
  1860. break;
  1861. dev_info(&intf->dev,
  1862. "TEST 19: write odd addr %d bytes %u times premapped\n",
  1863. param->length, param->iterations);
  1864. retval = test_unaligned_bulk(
  1865. dev, dev->out_pipe,
  1866. param->length, param->iterations,
  1867. URB_NO_TRANSFER_DMA_MAP, "test19");
  1868. break;
  1869. case 20:
  1870. if (dev->in_pipe == 0)
  1871. break;
  1872. dev_info(&intf->dev,
  1873. "TEST 20: read odd addr %d bytes %u times premapped\n",
  1874. param->length, param->iterations);
  1875. retval = test_unaligned_bulk(
  1876. dev, dev->in_pipe,
  1877. param->length, param->iterations,
  1878. URB_NO_TRANSFER_DMA_MAP, "test20");
  1879. break;
  1880. /* control write tests with unaligned buffer */
  1881. case 21:
  1882. if (!dev->info->ctrl_out)
  1883. break;
  1884. dev_info(&intf->dev,
  1885. "TEST 21: %d ep0out odd addr, %d..%d vary %d\n",
  1886. param->iterations,
  1887. realworld ? 1 : 0, param->length,
  1888. param->vary);
  1889. retval = ctrl_out(dev, param->iterations,
  1890. param->length, param->vary, 1);
  1891. break;
  1892. /* unaligned iso tests */
  1893. case 22:
  1894. if (dev->out_iso_pipe == 0 || param->sglen == 0)
  1895. break;
  1896. dev_info(&intf->dev,
  1897. "TEST 22: write %d iso odd, %d entries of %d bytes\n",
  1898. param->iterations,
  1899. param->sglen, param->length);
  1900. retval = test_iso_queue(dev, param,
  1901. dev->out_iso_pipe, dev->iso_out, 1);
  1902. break;
  1903. case 23:
  1904. if (dev->in_iso_pipe == 0 || param->sglen == 0)
  1905. break;
  1906. dev_info(&intf->dev,
  1907. "TEST 23: read %d iso odd, %d entries of %d bytes\n",
  1908. param->iterations,
  1909. param->sglen, param->length);
  1910. retval = test_iso_queue(dev, param,
  1911. dev->in_iso_pipe, dev->iso_in, 1);
  1912. break;
  1913. /* unlink URBs from a bulk-OUT queue */
  1914. case 24:
  1915. if (dev->out_pipe == 0 || !param->length || param->sglen < 4)
  1916. break;
  1917. retval = 0;
  1918. dev_info(&intf->dev, "TEST 17: unlink from %d queues of "
  1919. "%d %d-byte writes\n",
  1920. param->iterations, param->sglen, param->length);
  1921. for (i = param->iterations; retval == 0 && i > 0; --i) {
  1922. retval = unlink_queued(dev, dev->out_pipe,
  1923. param->sglen, param->length);
  1924. if (retval) {
  1925. dev_err(&intf->dev,
  1926. "unlink queued writes failed %d, "
  1927. "iterations left %d\n", retval, i);
  1928. break;
  1929. }
  1930. }
  1931. break;
  1932. }
  1933. do_gettimeofday(&param->duration);
  1934. param->duration.tv_sec -= start.tv_sec;
  1935. param->duration.tv_usec -= start.tv_usec;
  1936. if (param->duration.tv_usec < 0) {
  1937. param->duration.tv_usec += 1000 * 1000;
  1938. param->duration.tv_sec -= 1;
  1939. }
  1940. mutex_unlock(&dev->lock);
  1941. return retval;
  1942. }
  1943. /*-------------------------------------------------------------------------*/
  1944. static unsigned force_interrupt;
  1945. module_param(force_interrupt, uint, 0);
  1946. MODULE_PARM_DESC(force_interrupt, "0 = test default; else interrupt");
  1947. #ifdef GENERIC
  1948. static unsigned short vendor;
  1949. module_param(vendor, ushort, 0);
  1950. MODULE_PARM_DESC(vendor, "vendor code (from usb-if)");
  1951. static unsigned short product;
  1952. module_param(product, ushort, 0);
  1953. MODULE_PARM_DESC(product, "product code (from vendor)");
  1954. #endif
  1955. static int
  1956. usbtest_probe(struct usb_interface *intf, const struct usb_device_id *id)
  1957. {
  1958. struct usb_device *udev;
  1959. struct usbtest_dev *dev;
  1960. struct usbtest_info *info;
  1961. char *rtest, *wtest;
  1962. char *irtest, *iwtest;
  1963. udev = interface_to_usbdev(intf);
  1964. #ifdef GENERIC
  1965. /* specify devices by module parameters? */
  1966. if (id->match_flags == 0) {
  1967. /* vendor match required, product match optional */
  1968. if (!vendor || le16_to_cpu(udev->descriptor.idVendor) != (u16)vendor)
  1969. return -ENODEV;
  1970. if (product && le16_to_cpu(udev->descriptor.idProduct) != (u16)product)
  1971. return -ENODEV;
  1972. dev_info(&intf->dev, "matched module params, "
  1973. "vend=0x%04x prod=0x%04x\n",
  1974. le16_to_cpu(udev->descriptor.idVendor),
  1975. le16_to_cpu(udev->descriptor.idProduct));
  1976. }
  1977. #endif
  1978. dev = kzalloc(sizeof(*dev), GFP_KERNEL);
  1979. if (!dev)
  1980. return -ENOMEM;
  1981. info = (struct usbtest_info *) id->driver_info;
  1982. dev->info = info;
  1983. mutex_init(&dev->lock);
  1984. dev->intf = intf;
  1985. /* cacheline-aligned scratch for i/o */
  1986. dev->buf = kmalloc(TBUF_SIZE, GFP_KERNEL);
  1987. if (dev->buf == NULL) {
  1988. kfree(dev);
  1989. return -ENOMEM;
  1990. }
  1991. /* NOTE this doesn't yet test the handful of difference that are
  1992. * visible with high speed interrupts: bigger maxpacket (1K) and
  1993. * "high bandwidth" modes (up to 3 packets/uframe).
  1994. */
  1995. rtest = wtest = "";
  1996. irtest = iwtest = "";
  1997. if (force_interrupt || udev->speed == USB_SPEED_LOW) {
  1998. if (info->ep_in) {
  1999. dev->in_pipe = usb_rcvintpipe(udev, info->ep_in);
  2000. rtest = " intr-in";
  2001. }
  2002. if (info->ep_out) {
  2003. dev->out_pipe = usb_sndintpipe(udev, info->ep_out);
  2004. wtest = " intr-out";
  2005. }
  2006. } else {
  2007. if (info->autoconf) {
  2008. int status;
  2009. status = get_endpoints(dev, intf);
  2010. if (status < 0) {
  2011. WARNING(dev, "couldn't get endpoints, %d\n",
  2012. status);
  2013. return status;
  2014. }
  2015. /* may find bulk or ISO pipes */
  2016. } else {
  2017. if (info->ep_in)
  2018. dev->in_pipe = usb_rcvbulkpipe(udev,
  2019. info->ep_in);
  2020. if (info->ep_out)
  2021. dev->out_pipe = usb_sndbulkpipe(udev,
  2022. info->ep_out);
  2023. }
  2024. if (dev->in_pipe)
  2025. rtest = " bulk-in";
  2026. if (dev->out_pipe)
  2027. wtest = " bulk-out";
  2028. if (dev->in_iso_pipe)
  2029. irtest = " iso-in";
  2030. if (dev->out_iso_pipe)
  2031. iwtest = " iso-out";
  2032. }
  2033. usb_set_intfdata(intf, dev);
  2034. dev_info(&intf->dev, "%s\n", info->name);
  2035. dev_info(&intf->dev, "%s {control%s%s%s%s%s} tests%s\n",
  2036. usb_speed_string(udev->speed),
  2037. info->ctrl_out ? " in/out" : "",
  2038. rtest, wtest,
  2039. irtest, iwtest,
  2040. info->alt >= 0 ? " (+alt)" : "");
  2041. return 0;
  2042. }
  2043. static int usbtest_suspend(struct usb_interface *intf, pm_message_t message)
  2044. {
  2045. return 0;
  2046. }
  2047. static int usbtest_resume(struct usb_interface *intf)
  2048. {
  2049. return 0;
  2050. }
  2051. static void usbtest_disconnect(struct usb_interface *intf)
  2052. {
  2053. struct usbtest_dev *dev = usb_get_intfdata(intf);
  2054. usb_set_intfdata(intf, NULL);
  2055. dev_dbg(&intf->dev, "disconnect\n");
  2056. kfree(dev);
  2057. }
  2058. /* Basic testing only needs a device that can source or sink bulk traffic.
  2059. * Any device can test control transfers (default with GENERIC binding).
  2060. *
  2061. * Several entries work with the default EP0 implementation that's built
  2062. * into EZ-USB chips. There's a default vendor ID which can be overridden
  2063. * by (very) small config EEPROMS, but otherwise all these devices act
  2064. * identically until firmware is loaded: only EP0 works. It turns out
  2065. * to be easy to make other endpoints work, without modifying that EP0
  2066. * behavior. For now, we expect that kind of firmware.
  2067. */
  2068. /* an21xx or fx versions of ez-usb */
  2069. static struct usbtest_info ez1_info = {
  2070. .name = "EZ-USB device",
  2071. .ep_in = 2,
  2072. .ep_out = 2,
  2073. .alt = 1,
  2074. };
  2075. /* fx2 version of ez-usb */
  2076. static struct usbtest_info ez2_info = {
  2077. .name = "FX2 device",
  2078. .ep_in = 6,
  2079. .ep_out = 2,
  2080. .alt = 1,
  2081. };
  2082. /* ezusb family device with dedicated usb test firmware,
  2083. */
  2084. static struct usbtest_info fw_info = {
  2085. .name = "usb test device",
  2086. .ep_in = 2,
  2087. .ep_out = 2,
  2088. .alt = 1,
  2089. .autoconf = 1, /* iso and ctrl_out need autoconf */
  2090. .ctrl_out = 1,
  2091. .iso = 1, /* iso_ep's are #8 in/out */
  2092. };
  2093. /* peripheral running Linux and 'zero.c' test firmware, or
  2094. * its user-mode cousin. different versions of this use
  2095. * different hardware with the same vendor/product codes.
  2096. * host side MUST rely on the endpoint descriptors.
  2097. */
  2098. static struct usbtest_info gz_info = {
  2099. .name = "Linux gadget zero",
  2100. .autoconf = 1,
  2101. .ctrl_out = 1,
  2102. .alt = 0,
  2103. };
  2104. static struct usbtest_info um_info = {
  2105. .name = "Linux user mode test driver",
  2106. .autoconf = 1,
  2107. .alt = -1,
  2108. };
  2109. static struct usbtest_info um2_info = {
  2110. .name = "Linux user mode ISO test driver",
  2111. .autoconf = 1,
  2112. .iso = 1,
  2113. .alt = -1,
  2114. };
  2115. #ifdef IBOT2
  2116. /* this is a nice source of high speed bulk data;
  2117. * uses an FX2, with firmware provided in the device
  2118. */
  2119. static struct usbtest_info ibot2_info = {
  2120. .name = "iBOT2 webcam",
  2121. .ep_in = 2,
  2122. .alt = -1,
  2123. };
  2124. #endif
  2125. #ifdef GENERIC
  2126. /* we can use any device to test control traffic */
  2127. static struct usbtest_info generic_info = {
  2128. .name = "Generic USB device",
  2129. .alt = -1,
  2130. };
  2131. #endif
  2132. static const struct usb_device_id id_table[] = {
  2133. /*-------------------------------------------------------------*/
  2134. /* EZ-USB devices which download firmware to replace (or in our
  2135. * case augment) the default device implementation.
  2136. */
  2137. /* generic EZ-USB FX controller */
  2138. { USB_DEVICE(0x0547, 0x2235),
  2139. .driver_info = (unsigned long) &ez1_info,
  2140. },
  2141. /* CY3671 development board with EZ-USB FX */
  2142. { USB_DEVICE(0x0547, 0x0080),
  2143. .driver_info = (unsigned long) &ez1_info,
  2144. },
  2145. /* generic EZ-USB FX2 controller (or development board) */
  2146. { USB_DEVICE(0x04b4, 0x8613),
  2147. .driver_info = (unsigned long) &ez2_info,
  2148. },
  2149. /* re-enumerated usb test device firmware */
  2150. { USB_DEVICE(0xfff0, 0xfff0),
  2151. .driver_info = (unsigned long) &fw_info,
  2152. },
  2153. /* "Gadget Zero" firmware runs under Linux */
  2154. { USB_DEVICE(0x0525, 0xa4a0),
  2155. .driver_info = (unsigned long) &gz_info,
  2156. },
  2157. /* so does a user-mode variant */
  2158. { USB_DEVICE(0x0525, 0xa4a4),
  2159. .driver_info = (unsigned long) &um_info,
  2160. },
  2161. /* ... and a user-mode variant that talks iso */
  2162. { USB_DEVICE(0x0525, 0xa4a3),
  2163. .driver_info = (unsigned long) &um2_info,
  2164. },
  2165. #ifdef KEYSPAN_19Qi
  2166. /* Keyspan 19qi uses an21xx (original EZ-USB) */
  2167. /* this does not coexist with the real Keyspan 19qi driver! */
  2168. { USB_DEVICE(0x06cd, 0x010b),
  2169. .driver_info = (unsigned long) &ez1_info,
  2170. },
  2171. #endif
  2172. /*-------------------------------------------------------------*/
  2173. #ifdef IBOT2
  2174. /* iBOT2 makes a nice source of high speed bulk-in data */
  2175. /* this does not coexist with a real iBOT2 driver! */
  2176. { USB_DEVICE(0x0b62, 0x0059),
  2177. .driver_info = (unsigned long) &ibot2_info,
  2178. },
  2179. #endif
  2180. /*-------------------------------------------------------------*/
  2181. #ifdef GENERIC
  2182. /* module params can specify devices to use for control tests */
  2183. { .driver_info = (unsigned long) &generic_info, },
  2184. #endif
  2185. /*-------------------------------------------------------------*/
  2186. { }
  2187. };
  2188. MODULE_DEVICE_TABLE(usb, id_table);
  2189. static struct usb_driver usbtest_driver = {
  2190. .name = "usbtest",
  2191. .id_table = id_table,
  2192. .probe = usbtest_probe,
  2193. .unlocked_ioctl = usbtest_ioctl,
  2194. .disconnect = usbtest_disconnect,
  2195. .suspend = usbtest_suspend,
  2196. .resume = usbtest_resume,
  2197. };
  2198. /*-------------------------------------------------------------------------*/
  2199. static int __init usbtest_init(void)
  2200. {
  2201. #ifdef GENERIC
  2202. if (vendor)
  2203. pr_debug("params: vend=0x%04x prod=0x%04x\n", vendor, product);
  2204. #endif
  2205. return usb_register(&usbtest_driver);
  2206. }
  2207. module_init(usbtest_init);
  2208. static void __exit usbtest_exit(void)
  2209. {
  2210. usb_deregister(&usbtest_driver);
  2211. }
  2212. module_exit(usbtest_exit);
  2213. MODULE_DESCRIPTION("USB Core/HCD Testing Driver");
  2214. MODULE_LICENSE("GPL");