usbtest.c 65 KB

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