usbtest.c 66 KB

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