usbtest.c 65 KB

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