f_sourcesink.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292
  1. /*
  2. * f_sourcesink.c - USB peripheral source/sink configuration driver
  3. *
  4. * Copyright (C) 2003-2008 David Brownell
  5. * Copyright (C) 2008 by Nokia Corporation
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. */
  12. /* #define VERBOSE_DEBUG */
  13. #include <linux/slab.h>
  14. #include <linux/kernel.h>
  15. #include <linux/device.h>
  16. #include <linux/module.h>
  17. #include <linux/usb/composite.h>
  18. #include <linux/err.h>
  19. #include "g_zero.h"
  20. #include "u_f.h"
  21. /*
  22. * SOURCE/SINK FUNCTION ... a primary testing vehicle for USB peripheral
  23. * controller drivers.
  24. *
  25. * This just sinks bulk packets OUT to the peripheral and sources them IN
  26. * to the host, optionally with specific data patterns for integrity tests.
  27. * As such it supports basic functionality and load tests.
  28. *
  29. * In terms of control messaging, this supports all the standard requests
  30. * plus two that support control-OUT tests. If the optional "autoresume"
  31. * mode is enabled, it provides good functional coverage for the "USBCV"
  32. * test harness from USB-IF.
  33. */
  34. struct f_sourcesink {
  35. struct usb_function function;
  36. struct usb_ep *in_ep;
  37. struct usb_ep *out_ep;
  38. struct usb_ep *iso_in_ep;
  39. struct usb_ep *iso_out_ep;
  40. int cur_alt;
  41. unsigned pattern;
  42. unsigned isoc_interval;
  43. unsigned isoc_maxpacket;
  44. unsigned isoc_mult;
  45. unsigned isoc_maxburst;
  46. unsigned buflen;
  47. unsigned bulk_qlen;
  48. unsigned iso_qlen;
  49. };
  50. static inline struct f_sourcesink *func_to_ss(struct usb_function *f)
  51. {
  52. return container_of(f, struct f_sourcesink, function);
  53. }
  54. /*-------------------------------------------------------------------------*/
  55. static struct usb_interface_descriptor source_sink_intf_alt0 = {
  56. .bLength = USB_DT_INTERFACE_SIZE,
  57. .bDescriptorType = USB_DT_INTERFACE,
  58. .bAlternateSetting = 0,
  59. .bNumEndpoints = 2,
  60. .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
  61. /* .iInterface = DYNAMIC */
  62. };
  63. static struct usb_interface_descriptor source_sink_intf_alt1 = {
  64. .bLength = USB_DT_INTERFACE_SIZE,
  65. .bDescriptorType = USB_DT_INTERFACE,
  66. .bAlternateSetting = 1,
  67. .bNumEndpoints = 4,
  68. .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
  69. /* .iInterface = DYNAMIC */
  70. };
  71. /* full speed support: */
  72. static struct usb_endpoint_descriptor fs_source_desc = {
  73. .bLength = USB_DT_ENDPOINT_SIZE,
  74. .bDescriptorType = USB_DT_ENDPOINT,
  75. .bEndpointAddress = USB_DIR_IN,
  76. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  77. };
  78. static struct usb_endpoint_descriptor fs_sink_desc = {
  79. .bLength = USB_DT_ENDPOINT_SIZE,
  80. .bDescriptorType = USB_DT_ENDPOINT,
  81. .bEndpointAddress = USB_DIR_OUT,
  82. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  83. };
  84. static struct usb_endpoint_descriptor fs_iso_source_desc = {
  85. .bLength = USB_DT_ENDPOINT_SIZE,
  86. .bDescriptorType = USB_DT_ENDPOINT,
  87. .bEndpointAddress = USB_DIR_IN,
  88. .bmAttributes = USB_ENDPOINT_XFER_ISOC,
  89. .wMaxPacketSize = cpu_to_le16(1023),
  90. .bInterval = 4,
  91. };
  92. static struct usb_endpoint_descriptor fs_iso_sink_desc = {
  93. .bLength = USB_DT_ENDPOINT_SIZE,
  94. .bDescriptorType = USB_DT_ENDPOINT,
  95. .bEndpointAddress = USB_DIR_OUT,
  96. .bmAttributes = USB_ENDPOINT_XFER_ISOC,
  97. .wMaxPacketSize = cpu_to_le16(1023),
  98. .bInterval = 4,
  99. };
  100. static struct usb_descriptor_header *fs_source_sink_descs[] = {
  101. (struct usb_descriptor_header *) &source_sink_intf_alt0,
  102. (struct usb_descriptor_header *) &fs_sink_desc,
  103. (struct usb_descriptor_header *) &fs_source_desc,
  104. (struct usb_descriptor_header *) &source_sink_intf_alt1,
  105. #define FS_ALT_IFC_1_OFFSET 3
  106. (struct usb_descriptor_header *) &fs_sink_desc,
  107. (struct usb_descriptor_header *) &fs_source_desc,
  108. (struct usb_descriptor_header *) &fs_iso_sink_desc,
  109. (struct usb_descriptor_header *) &fs_iso_source_desc,
  110. NULL,
  111. };
  112. /* high speed support: */
  113. static struct usb_endpoint_descriptor hs_source_desc = {
  114. .bLength = USB_DT_ENDPOINT_SIZE,
  115. .bDescriptorType = USB_DT_ENDPOINT,
  116. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  117. .wMaxPacketSize = cpu_to_le16(512),
  118. };
  119. static struct usb_endpoint_descriptor hs_sink_desc = {
  120. .bLength = USB_DT_ENDPOINT_SIZE,
  121. .bDescriptorType = USB_DT_ENDPOINT,
  122. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  123. .wMaxPacketSize = cpu_to_le16(512),
  124. };
  125. static struct usb_endpoint_descriptor hs_iso_source_desc = {
  126. .bLength = USB_DT_ENDPOINT_SIZE,
  127. .bDescriptorType = USB_DT_ENDPOINT,
  128. .bmAttributes = USB_ENDPOINT_XFER_ISOC,
  129. .wMaxPacketSize = cpu_to_le16(1024),
  130. .bInterval = 4,
  131. };
  132. static struct usb_endpoint_descriptor hs_iso_sink_desc = {
  133. .bLength = USB_DT_ENDPOINT_SIZE,
  134. .bDescriptorType = USB_DT_ENDPOINT,
  135. .bmAttributes = USB_ENDPOINT_XFER_ISOC,
  136. .wMaxPacketSize = cpu_to_le16(1024),
  137. .bInterval = 4,
  138. };
  139. static struct usb_descriptor_header *hs_source_sink_descs[] = {
  140. (struct usb_descriptor_header *) &source_sink_intf_alt0,
  141. (struct usb_descriptor_header *) &hs_source_desc,
  142. (struct usb_descriptor_header *) &hs_sink_desc,
  143. (struct usb_descriptor_header *) &source_sink_intf_alt1,
  144. #define HS_ALT_IFC_1_OFFSET 3
  145. (struct usb_descriptor_header *) &hs_source_desc,
  146. (struct usb_descriptor_header *) &hs_sink_desc,
  147. (struct usb_descriptor_header *) &hs_iso_source_desc,
  148. (struct usb_descriptor_header *) &hs_iso_sink_desc,
  149. NULL,
  150. };
  151. /* super speed support: */
  152. static struct usb_endpoint_descriptor ss_source_desc = {
  153. .bLength = USB_DT_ENDPOINT_SIZE,
  154. .bDescriptorType = USB_DT_ENDPOINT,
  155. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  156. .wMaxPacketSize = cpu_to_le16(1024),
  157. };
  158. static struct usb_ss_ep_comp_descriptor ss_source_comp_desc = {
  159. .bLength = USB_DT_SS_EP_COMP_SIZE,
  160. .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
  161. .bMaxBurst = 0,
  162. .bmAttributes = 0,
  163. .wBytesPerInterval = 0,
  164. };
  165. static struct usb_endpoint_descriptor ss_sink_desc = {
  166. .bLength = USB_DT_ENDPOINT_SIZE,
  167. .bDescriptorType = USB_DT_ENDPOINT,
  168. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  169. .wMaxPacketSize = cpu_to_le16(1024),
  170. };
  171. static struct usb_ss_ep_comp_descriptor ss_sink_comp_desc = {
  172. .bLength = USB_DT_SS_EP_COMP_SIZE,
  173. .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
  174. .bMaxBurst = 0,
  175. .bmAttributes = 0,
  176. .wBytesPerInterval = 0,
  177. };
  178. static struct usb_endpoint_descriptor ss_iso_source_desc = {
  179. .bLength = USB_DT_ENDPOINT_SIZE,
  180. .bDescriptorType = USB_DT_ENDPOINT,
  181. .bmAttributes = USB_ENDPOINT_XFER_ISOC,
  182. .wMaxPacketSize = cpu_to_le16(1024),
  183. .bInterval = 4,
  184. };
  185. static struct usb_ss_ep_comp_descriptor ss_iso_source_comp_desc = {
  186. .bLength = USB_DT_SS_EP_COMP_SIZE,
  187. .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
  188. .bMaxBurst = 0,
  189. .bmAttributes = 0,
  190. .wBytesPerInterval = cpu_to_le16(1024),
  191. };
  192. static struct usb_endpoint_descriptor ss_iso_sink_desc = {
  193. .bLength = USB_DT_ENDPOINT_SIZE,
  194. .bDescriptorType = USB_DT_ENDPOINT,
  195. .bmAttributes = USB_ENDPOINT_XFER_ISOC,
  196. .wMaxPacketSize = cpu_to_le16(1024),
  197. .bInterval = 4,
  198. };
  199. static struct usb_ss_ep_comp_descriptor ss_iso_sink_comp_desc = {
  200. .bLength = USB_DT_SS_EP_COMP_SIZE,
  201. .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
  202. .bMaxBurst = 0,
  203. .bmAttributes = 0,
  204. .wBytesPerInterval = cpu_to_le16(1024),
  205. };
  206. static struct usb_descriptor_header *ss_source_sink_descs[] = {
  207. (struct usb_descriptor_header *) &source_sink_intf_alt0,
  208. (struct usb_descriptor_header *) &ss_source_desc,
  209. (struct usb_descriptor_header *) &ss_source_comp_desc,
  210. (struct usb_descriptor_header *) &ss_sink_desc,
  211. (struct usb_descriptor_header *) &ss_sink_comp_desc,
  212. (struct usb_descriptor_header *) &source_sink_intf_alt1,
  213. #define SS_ALT_IFC_1_OFFSET 5
  214. (struct usb_descriptor_header *) &ss_source_desc,
  215. (struct usb_descriptor_header *) &ss_source_comp_desc,
  216. (struct usb_descriptor_header *) &ss_sink_desc,
  217. (struct usb_descriptor_header *) &ss_sink_comp_desc,
  218. (struct usb_descriptor_header *) &ss_iso_source_desc,
  219. (struct usb_descriptor_header *) &ss_iso_source_comp_desc,
  220. (struct usb_descriptor_header *) &ss_iso_sink_desc,
  221. (struct usb_descriptor_header *) &ss_iso_sink_comp_desc,
  222. NULL,
  223. };
  224. /* function-specific strings: */
  225. static struct usb_string strings_sourcesink[] = {
  226. [0].s = "source and sink data",
  227. { } /* end of list */
  228. };
  229. static struct usb_gadget_strings stringtab_sourcesink = {
  230. .language = 0x0409, /* en-us */
  231. .strings = strings_sourcesink,
  232. };
  233. static struct usb_gadget_strings *sourcesink_strings[] = {
  234. &stringtab_sourcesink,
  235. NULL,
  236. };
  237. /*-------------------------------------------------------------------------*/
  238. static inline struct usb_request *ss_alloc_ep_req(struct usb_ep *ep, int len)
  239. {
  240. struct f_sourcesink *ss = ep->driver_data;
  241. return alloc_ep_req(ep, len, ss->buflen);
  242. }
  243. static void disable_ep(struct usb_composite_dev *cdev, struct usb_ep *ep)
  244. {
  245. int value;
  246. value = usb_ep_disable(ep);
  247. if (value < 0)
  248. DBG(cdev, "disable %s --> %d\n", ep->name, value);
  249. }
  250. void disable_endpoints(struct usb_composite_dev *cdev,
  251. struct usb_ep *in, struct usb_ep *out,
  252. struct usb_ep *iso_in, struct usb_ep *iso_out)
  253. {
  254. disable_ep(cdev, in);
  255. disable_ep(cdev, out);
  256. if (iso_in)
  257. disable_ep(cdev, iso_in);
  258. if (iso_out)
  259. disable_ep(cdev, iso_out);
  260. }
  261. static int
  262. sourcesink_bind(struct usb_configuration *c, struct usb_function *f)
  263. {
  264. struct usb_composite_dev *cdev = c->cdev;
  265. struct f_sourcesink *ss = func_to_ss(f);
  266. int id;
  267. int ret;
  268. /* allocate interface ID(s) */
  269. id = usb_interface_id(c, f);
  270. if (id < 0)
  271. return id;
  272. source_sink_intf_alt0.bInterfaceNumber = id;
  273. source_sink_intf_alt1.bInterfaceNumber = id;
  274. /* allocate bulk endpoints */
  275. ss->in_ep = usb_ep_autoconfig(cdev->gadget, &fs_source_desc);
  276. if (!ss->in_ep) {
  277. autoconf_fail:
  278. ERROR(cdev, "%s: can't autoconfigure on %s\n",
  279. f->name, cdev->gadget->name);
  280. return -ENODEV;
  281. }
  282. ss->out_ep = usb_ep_autoconfig(cdev->gadget, &fs_sink_desc);
  283. if (!ss->out_ep)
  284. goto autoconf_fail;
  285. /* sanity check the isoc module parameters */
  286. if (ss->isoc_interval < 1)
  287. ss->isoc_interval = 1;
  288. if (ss->isoc_interval > 16)
  289. ss->isoc_interval = 16;
  290. if (ss->isoc_mult > 2)
  291. ss->isoc_mult = 2;
  292. if (ss->isoc_maxburst > 15)
  293. ss->isoc_maxburst = 15;
  294. /* fill in the FS isoc descriptors from the module parameters */
  295. fs_iso_source_desc.wMaxPacketSize = ss->isoc_maxpacket > 1023 ?
  296. 1023 : ss->isoc_maxpacket;
  297. fs_iso_source_desc.bInterval = ss->isoc_interval;
  298. fs_iso_sink_desc.wMaxPacketSize = ss->isoc_maxpacket > 1023 ?
  299. 1023 : ss->isoc_maxpacket;
  300. fs_iso_sink_desc.bInterval = ss->isoc_interval;
  301. /* allocate iso endpoints */
  302. ss->iso_in_ep = usb_ep_autoconfig(cdev->gadget, &fs_iso_source_desc);
  303. if (!ss->iso_in_ep)
  304. goto no_iso;
  305. ss->iso_out_ep = usb_ep_autoconfig(cdev->gadget, &fs_iso_sink_desc);
  306. if (!ss->iso_out_ep) {
  307. usb_ep_autoconfig_release(ss->iso_in_ep);
  308. ss->iso_in_ep = NULL;
  309. no_iso:
  310. /*
  311. * We still want to work even if the UDC doesn't have isoc
  312. * endpoints, so null out the alt interface that contains
  313. * them and continue.
  314. */
  315. fs_source_sink_descs[FS_ALT_IFC_1_OFFSET] = NULL;
  316. hs_source_sink_descs[HS_ALT_IFC_1_OFFSET] = NULL;
  317. ss_source_sink_descs[SS_ALT_IFC_1_OFFSET] = NULL;
  318. }
  319. if (ss->isoc_maxpacket > 1024)
  320. ss->isoc_maxpacket = 1024;
  321. /* support high speed hardware */
  322. hs_source_desc.bEndpointAddress = fs_source_desc.bEndpointAddress;
  323. hs_sink_desc.bEndpointAddress = fs_sink_desc.bEndpointAddress;
  324. /*
  325. * Fill in the HS isoc descriptors from the module parameters.
  326. * We assume that the user knows what they are doing and won't
  327. * give parameters that their UDC doesn't support.
  328. */
  329. hs_iso_source_desc.wMaxPacketSize = ss->isoc_maxpacket;
  330. hs_iso_source_desc.wMaxPacketSize |= ss->isoc_mult << 11;
  331. hs_iso_source_desc.bInterval = ss->isoc_interval;
  332. hs_iso_source_desc.bEndpointAddress =
  333. fs_iso_source_desc.bEndpointAddress;
  334. hs_iso_sink_desc.wMaxPacketSize = ss->isoc_maxpacket;
  335. hs_iso_sink_desc.wMaxPacketSize |= ss->isoc_mult << 11;
  336. hs_iso_sink_desc.bInterval = ss->isoc_interval;
  337. hs_iso_sink_desc.bEndpointAddress = fs_iso_sink_desc.bEndpointAddress;
  338. /* support super speed hardware */
  339. ss_source_desc.bEndpointAddress =
  340. fs_source_desc.bEndpointAddress;
  341. ss_sink_desc.bEndpointAddress =
  342. fs_sink_desc.bEndpointAddress;
  343. /*
  344. * Fill in the SS isoc descriptors from the module parameters.
  345. * We assume that the user knows what they are doing and won't
  346. * give parameters that their UDC doesn't support.
  347. */
  348. ss_iso_source_desc.wMaxPacketSize = ss->isoc_maxpacket;
  349. ss_iso_source_desc.bInterval = ss->isoc_interval;
  350. ss_iso_source_comp_desc.bmAttributes = ss->isoc_mult;
  351. ss_iso_source_comp_desc.bMaxBurst = ss->isoc_maxburst;
  352. ss_iso_source_comp_desc.wBytesPerInterval = ss->isoc_maxpacket *
  353. (ss->isoc_mult + 1) * (ss->isoc_maxburst + 1);
  354. ss_iso_source_desc.bEndpointAddress =
  355. fs_iso_source_desc.bEndpointAddress;
  356. ss_iso_sink_desc.wMaxPacketSize = ss->isoc_maxpacket;
  357. ss_iso_sink_desc.bInterval = ss->isoc_interval;
  358. ss_iso_sink_comp_desc.bmAttributes = ss->isoc_mult;
  359. ss_iso_sink_comp_desc.bMaxBurst = ss->isoc_maxburst;
  360. ss_iso_sink_comp_desc.wBytesPerInterval = ss->isoc_maxpacket *
  361. (ss->isoc_mult + 1) * (ss->isoc_maxburst + 1);
  362. ss_iso_sink_desc.bEndpointAddress = fs_iso_sink_desc.bEndpointAddress;
  363. ret = usb_assign_descriptors(f, fs_source_sink_descs,
  364. hs_source_sink_descs, ss_source_sink_descs, NULL);
  365. if (ret)
  366. return ret;
  367. DBG(cdev, "%s speed %s: IN/%s, OUT/%s, ISO-IN/%s, ISO-OUT/%s\n",
  368. (gadget_is_superspeed(c->cdev->gadget) ? "super" :
  369. (gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full")),
  370. f->name, ss->in_ep->name, ss->out_ep->name,
  371. ss->iso_in_ep ? ss->iso_in_ep->name : "<none>",
  372. ss->iso_out_ep ? ss->iso_out_ep->name : "<none>");
  373. return 0;
  374. }
  375. static void
  376. sourcesink_free_func(struct usb_function *f)
  377. {
  378. struct f_ss_opts *opts;
  379. opts = container_of(f->fi, struct f_ss_opts, func_inst);
  380. mutex_lock(&opts->lock);
  381. opts->refcnt--;
  382. mutex_unlock(&opts->lock);
  383. usb_free_all_descriptors(f);
  384. kfree(func_to_ss(f));
  385. }
  386. /* optionally require specific source/sink data patterns */
  387. static int check_read_data(struct f_sourcesink *ss, struct usb_request *req)
  388. {
  389. unsigned i;
  390. u8 *buf = req->buf;
  391. struct usb_composite_dev *cdev = ss->function.config->cdev;
  392. int max_packet_size = le16_to_cpu(ss->out_ep->desc->wMaxPacketSize);
  393. if (ss->pattern == 2)
  394. return 0;
  395. for (i = 0; i < req->actual; i++, buf++) {
  396. switch (ss->pattern) {
  397. /* all-zeroes has no synchronization issues */
  398. case 0:
  399. if (*buf == 0)
  400. continue;
  401. break;
  402. /* "mod63" stays in sync with short-terminated transfers,
  403. * OR otherwise when host and gadget agree on how large
  404. * each usb transfer request should be. Resync is done
  405. * with set_interface or set_config. (We *WANT* it to
  406. * get quickly out of sync if controllers or their drivers
  407. * stutter for any reason, including buffer duplication...)
  408. */
  409. case 1:
  410. if (*buf == (u8)((i % max_packet_size) % 63))
  411. continue;
  412. break;
  413. }
  414. ERROR(cdev, "bad OUT byte, buf[%d] = %d\n", i, *buf);
  415. usb_ep_set_halt(ss->out_ep);
  416. return -EINVAL;
  417. }
  418. return 0;
  419. }
  420. static void reinit_write_data(struct usb_ep *ep, struct usb_request *req)
  421. {
  422. unsigned i;
  423. u8 *buf = req->buf;
  424. int max_packet_size = le16_to_cpu(ep->desc->wMaxPacketSize);
  425. struct f_sourcesink *ss = ep->driver_data;
  426. switch (ss->pattern) {
  427. case 0:
  428. memset(req->buf, 0, req->length);
  429. break;
  430. case 1:
  431. for (i = 0; i < req->length; i++)
  432. *buf++ = (u8) ((i % max_packet_size) % 63);
  433. break;
  434. case 2:
  435. break;
  436. }
  437. }
  438. static void source_sink_complete(struct usb_ep *ep, struct usb_request *req)
  439. {
  440. struct usb_composite_dev *cdev;
  441. struct f_sourcesink *ss = ep->driver_data;
  442. int status = req->status;
  443. /* driver_data will be null if ep has been disabled */
  444. if (!ss)
  445. return;
  446. cdev = ss->function.config->cdev;
  447. switch (status) {
  448. case 0: /* normal completion? */
  449. if (ep == ss->out_ep) {
  450. check_read_data(ss, req);
  451. if (ss->pattern != 2)
  452. memset(req->buf, 0x55, req->length);
  453. }
  454. break;
  455. /* this endpoint is normally active while we're configured */
  456. case -ECONNABORTED: /* hardware forced ep reset */
  457. case -ECONNRESET: /* request dequeued */
  458. case -ESHUTDOWN: /* disconnect from host */
  459. VDBG(cdev, "%s gone (%d), %d/%d\n", ep->name, status,
  460. req->actual, req->length);
  461. if (ep == ss->out_ep)
  462. check_read_data(ss, req);
  463. free_ep_req(ep, req);
  464. return;
  465. case -EOVERFLOW: /* buffer overrun on read means that
  466. * we didn't provide a big enough
  467. * buffer.
  468. */
  469. default:
  470. #if 1
  471. DBG(cdev, "%s complete --> %d, %d/%d\n", ep->name,
  472. status, req->actual, req->length);
  473. #endif
  474. case -EREMOTEIO: /* short read */
  475. break;
  476. }
  477. status = usb_ep_queue(ep, req, GFP_ATOMIC);
  478. if (status) {
  479. ERROR(cdev, "kill %s: resubmit %d bytes --> %d\n",
  480. ep->name, req->length, status);
  481. usb_ep_set_halt(ep);
  482. /* FIXME recover later ... somehow */
  483. }
  484. }
  485. static int source_sink_start_ep(struct f_sourcesink *ss, bool is_in,
  486. bool is_iso, int speed)
  487. {
  488. struct usb_ep *ep;
  489. struct usb_request *req;
  490. int i, size, qlen, status = 0;
  491. if (is_iso) {
  492. switch (speed) {
  493. case USB_SPEED_SUPER:
  494. size = ss->isoc_maxpacket *
  495. (ss->isoc_mult + 1) *
  496. (ss->isoc_maxburst + 1);
  497. break;
  498. case USB_SPEED_HIGH:
  499. size = ss->isoc_maxpacket * (ss->isoc_mult + 1);
  500. break;
  501. default:
  502. size = ss->isoc_maxpacket > 1023 ?
  503. 1023 : ss->isoc_maxpacket;
  504. break;
  505. }
  506. ep = is_in ? ss->iso_in_ep : ss->iso_out_ep;
  507. qlen = ss->iso_qlen;
  508. } else {
  509. ep = is_in ? ss->in_ep : ss->out_ep;
  510. qlen = ss->bulk_qlen;
  511. size = 0;
  512. }
  513. for (i = 0; i < qlen; i++) {
  514. req = ss_alloc_ep_req(ep, size);
  515. if (!req)
  516. return -ENOMEM;
  517. req->complete = source_sink_complete;
  518. if (is_in)
  519. reinit_write_data(ep, req);
  520. else if (ss->pattern != 2)
  521. memset(req->buf, 0x55, req->length);
  522. status = usb_ep_queue(ep, req, GFP_ATOMIC);
  523. if (status) {
  524. struct usb_composite_dev *cdev;
  525. cdev = ss->function.config->cdev;
  526. ERROR(cdev, "start %s%s %s --> %d\n",
  527. is_iso ? "ISO-" : "", is_in ? "IN" : "OUT",
  528. ep->name, status);
  529. free_ep_req(ep, req);
  530. return status;
  531. }
  532. }
  533. return status;
  534. }
  535. static void disable_source_sink(struct f_sourcesink *ss)
  536. {
  537. struct usb_composite_dev *cdev;
  538. cdev = ss->function.config->cdev;
  539. disable_endpoints(cdev, ss->in_ep, ss->out_ep, ss->iso_in_ep,
  540. ss->iso_out_ep);
  541. VDBG(cdev, "%s disabled\n", ss->function.name);
  542. }
  543. static int
  544. enable_source_sink(struct usb_composite_dev *cdev, struct f_sourcesink *ss,
  545. int alt)
  546. {
  547. int result = 0;
  548. int speed = cdev->gadget->speed;
  549. struct usb_ep *ep;
  550. /* one bulk endpoint writes (sources) zeroes IN (to the host) */
  551. ep = ss->in_ep;
  552. result = config_ep_by_speed(cdev->gadget, &(ss->function), ep);
  553. if (result)
  554. return result;
  555. result = usb_ep_enable(ep);
  556. if (result < 0)
  557. return result;
  558. ep->driver_data = ss;
  559. result = source_sink_start_ep(ss, true, false, speed);
  560. if (result < 0) {
  561. fail:
  562. ep = ss->in_ep;
  563. usb_ep_disable(ep);
  564. return result;
  565. }
  566. /* one bulk endpoint reads (sinks) anything OUT (from the host) */
  567. ep = ss->out_ep;
  568. result = config_ep_by_speed(cdev->gadget, &(ss->function), ep);
  569. if (result)
  570. goto fail;
  571. result = usb_ep_enable(ep);
  572. if (result < 0)
  573. goto fail;
  574. ep->driver_data = ss;
  575. result = source_sink_start_ep(ss, false, false, speed);
  576. if (result < 0) {
  577. fail2:
  578. ep = ss->out_ep;
  579. usb_ep_disable(ep);
  580. goto fail;
  581. }
  582. if (alt == 0)
  583. goto out;
  584. /* one iso endpoint writes (sources) zeroes IN (to the host) */
  585. ep = ss->iso_in_ep;
  586. if (ep) {
  587. result = config_ep_by_speed(cdev->gadget, &(ss->function), ep);
  588. if (result)
  589. goto fail2;
  590. result = usb_ep_enable(ep);
  591. if (result < 0)
  592. goto fail2;
  593. ep->driver_data = ss;
  594. result = source_sink_start_ep(ss, true, true, speed);
  595. if (result < 0) {
  596. fail3:
  597. ep = ss->iso_in_ep;
  598. if (ep)
  599. usb_ep_disable(ep);
  600. goto fail2;
  601. }
  602. }
  603. /* one iso endpoint reads (sinks) anything OUT (from the host) */
  604. ep = ss->iso_out_ep;
  605. if (ep) {
  606. result = config_ep_by_speed(cdev->gadget, &(ss->function), ep);
  607. if (result)
  608. goto fail3;
  609. result = usb_ep_enable(ep);
  610. if (result < 0)
  611. goto fail3;
  612. ep->driver_data = ss;
  613. result = source_sink_start_ep(ss, false, true, speed);
  614. if (result < 0) {
  615. usb_ep_disable(ep);
  616. goto fail3;
  617. }
  618. }
  619. out:
  620. ss->cur_alt = alt;
  621. DBG(cdev, "%s enabled, alt intf %d\n", ss->function.name, alt);
  622. return result;
  623. }
  624. static int sourcesink_set_alt(struct usb_function *f,
  625. unsigned intf, unsigned alt)
  626. {
  627. struct f_sourcesink *ss = func_to_ss(f);
  628. struct usb_composite_dev *cdev = f->config->cdev;
  629. disable_source_sink(ss);
  630. return enable_source_sink(cdev, ss, alt);
  631. }
  632. static int sourcesink_get_alt(struct usb_function *f, unsigned intf)
  633. {
  634. struct f_sourcesink *ss = func_to_ss(f);
  635. return ss->cur_alt;
  636. }
  637. static void sourcesink_disable(struct usb_function *f)
  638. {
  639. struct f_sourcesink *ss = func_to_ss(f);
  640. disable_source_sink(ss);
  641. }
  642. /*-------------------------------------------------------------------------*/
  643. static int sourcesink_setup(struct usb_function *f,
  644. const struct usb_ctrlrequest *ctrl)
  645. {
  646. struct usb_configuration *c = f->config;
  647. struct usb_request *req = c->cdev->req;
  648. int value = -EOPNOTSUPP;
  649. u16 w_index = le16_to_cpu(ctrl->wIndex);
  650. u16 w_value = le16_to_cpu(ctrl->wValue);
  651. u16 w_length = le16_to_cpu(ctrl->wLength);
  652. req->length = USB_COMP_EP0_BUFSIZ;
  653. /* composite driver infrastructure handles everything except
  654. * the two control test requests.
  655. */
  656. switch (ctrl->bRequest) {
  657. /*
  658. * These are the same vendor-specific requests supported by
  659. * Intel's USB 2.0 compliance test devices. We exceed that
  660. * device spec by allowing multiple-packet requests.
  661. *
  662. * NOTE: the Control-OUT data stays in req->buf ... better
  663. * would be copying it into a scratch buffer, so that other
  664. * requests may safely intervene.
  665. */
  666. case 0x5b: /* control WRITE test -- fill the buffer */
  667. if (ctrl->bRequestType != (USB_DIR_OUT|USB_TYPE_VENDOR))
  668. goto unknown;
  669. if (w_value || w_index)
  670. break;
  671. /* just read that many bytes into the buffer */
  672. if (w_length > req->length)
  673. break;
  674. value = w_length;
  675. break;
  676. case 0x5c: /* control READ test -- return the buffer */
  677. if (ctrl->bRequestType != (USB_DIR_IN|USB_TYPE_VENDOR))
  678. goto unknown;
  679. if (w_value || w_index)
  680. break;
  681. /* expect those bytes are still in the buffer; send back */
  682. if (w_length > req->length)
  683. break;
  684. value = w_length;
  685. break;
  686. default:
  687. unknown:
  688. VDBG(c->cdev,
  689. "unknown control req%02x.%02x v%04x i%04x l%d\n",
  690. ctrl->bRequestType, ctrl->bRequest,
  691. w_value, w_index, w_length);
  692. }
  693. /* respond with data transfer or status phase? */
  694. if (value >= 0) {
  695. VDBG(c->cdev, "source/sink req%02x.%02x v%04x i%04x l%d\n",
  696. ctrl->bRequestType, ctrl->bRequest,
  697. w_value, w_index, w_length);
  698. req->zero = 0;
  699. req->length = value;
  700. value = usb_ep_queue(c->cdev->gadget->ep0, req, GFP_ATOMIC);
  701. if (value < 0)
  702. ERROR(c->cdev, "source/sink response, err %d\n",
  703. value);
  704. }
  705. /* device either stalls (value < 0) or reports success */
  706. return value;
  707. }
  708. static struct usb_function *source_sink_alloc_func(
  709. struct usb_function_instance *fi)
  710. {
  711. struct f_sourcesink *ss;
  712. struct f_ss_opts *ss_opts;
  713. ss = kzalloc(sizeof(*ss), GFP_KERNEL);
  714. if (!ss)
  715. return NULL;
  716. ss_opts = container_of(fi, struct f_ss_opts, func_inst);
  717. mutex_lock(&ss_opts->lock);
  718. ss_opts->refcnt++;
  719. mutex_unlock(&ss_opts->lock);
  720. ss->pattern = ss_opts->pattern;
  721. ss->isoc_interval = ss_opts->isoc_interval;
  722. ss->isoc_maxpacket = ss_opts->isoc_maxpacket;
  723. ss->isoc_mult = ss_opts->isoc_mult;
  724. ss->isoc_maxburst = ss_opts->isoc_maxburst;
  725. ss->buflen = ss_opts->bulk_buflen;
  726. ss->bulk_qlen = ss_opts->bulk_qlen;
  727. ss->iso_qlen = ss_opts->iso_qlen;
  728. ss->function.name = "source/sink";
  729. ss->function.bind = sourcesink_bind;
  730. ss->function.set_alt = sourcesink_set_alt;
  731. ss->function.get_alt = sourcesink_get_alt;
  732. ss->function.disable = sourcesink_disable;
  733. ss->function.setup = sourcesink_setup;
  734. ss->function.strings = sourcesink_strings;
  735. ss->function.free_func = sourcesink_free_func;
  736. return &ss->function;
  737. }
  738. static inline struct f_ss_opts *to_f_ss_opts(struct config_item *item)
  739. {
  740. return container_of(to_config_group(item), struct f_ss_opts,
  741. func_inst.group);
  742. }
  743. static void ss_attr_release(struct config_item *item)
  744. {
  745. struct f_ss_opts *ss_opts = to_f_ss_opts(item);
  746. usb_put_function_instance(&ss_opts->func_inst);
  747. }
  748. static struct configfs_item_operations ss_item_ops = {
  749. .release = ss_attr_release,
  750. };
  751. static ssize_t f_ss_opts_pattern_show(struct config_item *item, char *page)
  752. {
  753. struct f_ss_opts *opts = to_f_ss_opts(item);
  754. int result;
  755. mutex_lock(&opts->lock);
  756. result = sprintf(page, "%u\n", opts->pattern);
  757. mutex_unlock(&opts->lock);
  758. return result;
  759. }
  760. static ssize_t f_ss_opts_pattern_store(struct config_item *item,
  761. const char *page, size_t len)
  762. {
  763. struct f_ss_opts *opts = to_f_ss_opts(item);
  764. int ret;
  765. u8 num;
  766. mutex_lock(&opts->lock);
  767. if (opts->refcnt) {
  768. ret = -EBUSY;
  769. goto end;
  770. }
  771. ret = kstrtou8(page, 0, &num);
  772. if (ret)
  773. goto end;
  774. if (num != 0 && num != 1 && num != 2) {
  775. ret = -EINVAL;
  776. goto end;
  777. }
  778. opts->pattern = num;
  779. ret = len;
  780. end:
  781. mutex_unlock(&opts->lock);
  782. return ret;
  783. }
  784. CONFIGFS_ATTR(f_ss_opts_, pattern);
  785. static ssize_t f_ss_opts_isoc_interval_show(struct config_item *item, char *page)
  786. {
  787. struct f_ss_opts *opts = to_f_ss_opts(item);
  788. int result;
  789. mutex_lock(&opts->lock);
  790. result = sprintf(page, "%u\n", opts->isoc_interval);
  791. mutex_unlock(&opts->lock);
  792. return result;
  793. }
  794. static ssize_t f_ss_opts_isoc_interval_store(struct config_item *item,
  795. const char *page, size_t len)
  796. {
  797. struct f_ss_opts *opts = to_f_ss_opts(item);
  798. int ret;
  799. u8 num;
  800. mutex_lock(&opts->lock);
  801. if (opts->refcnt) {
  802. ret = -EBUSY;
  803. goto end;
  804. }
  805. ret = kstrtou8(page, 0, &num);
  806. if (ret)
  807. goto end;
  808. if (num > 16) {
  809. ret = -EINVAL;
  810. goto end;
  811. }
  812. opts->isoc_interval = num;
  813. ret = len;
  814. end:
  815. mutex_unlock(&opts->lock);
  816. return ret;
  817. }
  818. CONFIGFS_ATTR(f_ss_opts_, isoc_interval);
  819. static ssize_t f_ss_opts_isoc_maxpacket_show(struct config_item *item, char *page)
  820. {
  821. struct f_ss_opts *opts = to_f_ss_opts(item);
  822. int result;
  823. mutex_lock(&opts->lock);
  824. result = sprintf(page, "%u\n", opts->isoc_maxpacket);
  825. mutex_unlock(&opts->lock);
  826. return result;
  827. }
  828. static ssize_t f_ss_opts_isoc_maxpacket_store(struct config_item *item,
  829. const char *page, size_t len)
  830. {
  831. struct f_ss_opts *opts = to_f_ss_opts(item);
  832. int ret;
  833. u16 num;
  834. mutex_lock(&opts->lock);
  835. if (opts->refcnt) {
  836. ret = -EBUSY;
  837. goto end;
  838. }
  839. ret = kstrtou16(page, 0, &num);
  840. if (ret)
  841. goto end;
  842. if (num > 1024) {
  843. ret = -EINVAL;
  844. goto end;
  845. }
  846. opts->isoc_maxpacket = num;
  847. ret = len;
  848. end:
  849. mutex_unlock(&opts->lock);
  850. return ret;
  851. }
  852. CONFIGFS_ATTR(f_ss_opts_, isoc_maxpacket);
  853. static ssize_t f_ss_opts_isoc_mult_show(struct config_item *item, char *page)
  854. {
  855. struct f_ss_opts *opts = to_f_ss_opts(item);
  856. int result;
  857. mutex_lock(&opts->lock);
  858. result = sprintf(page, "%u\n", opts->isoc_mult);
  859. mutex_unlock(&opts->lock);
  860. return result;
  861. }
  862. static ssize_t f_ss_opts_isoc_mult_store(struct config_item *item,
  863. const char *page, size_t len)
  864. {
  865. struct f_ss_opts *opts = to_f_ss_opts(item);
  866. int ret;
  867. u8 num;
  868. mutex_lock(&opts->lock);
  869. if (opts->refcnt) {
  870. ret = -EBUSY;
  871. goto end;
  872. }
  873. ret = kstrtou8(page, 0, &num);
  874. if (ret)
  875. goto end;
  876. if (num > 2) {
  877. ret = -EINVAL;
  878. goto end;
  879. }
  880. opts->isoc_mult = num;
  881. ret = len;
  882. end:
  883. mutex_unlock(&opts->lock);
  884. return ret;
  885. }
  886. CONFIGFS_ATTR(f_ss_opts_, isoc_mult);
  887. static ssize_t f_ss_opts_isoc_maxburst_show(struct config_item *item, char *page)
  888. {
  889. struct f_ss_opts *opts = to_f_ss_opts(item);
  890. int result;
  891. mutex_lock(&opts->lock);
  892. result = sprintf(page, "%u\n", opts->isoc_maxburst);
  893. mutex_unlock(&opts->lock);
  894. return result;
  895. }
  896. static ssize_t f_ss_opts_isoc_maxburst_store(struct config_item *item,
  897. const char *page, size_t len)
  898. {
  899. struct f_ss_opts *opts = to_f_ss_opts(item);
  900. int ret;
  901. u8 num;
  902. mutex_lock(&opts->lock);
  903. if (opts->refcnt) {
  904. ret = -EBUSY;
  905. goto end;
  906. }
  907. ret = kstrtou8(page, 0, &num);
  908. if (ret)
  909. goto end;
  910. if (num > 15) {
  911. ret = -EINVAL;
  912. goto end;
  913. }
  914. opts->isoc_maxburst = num;
  915. ret = len;
  916. end:
  917. mutex_unlock(&opts->lock);
  918. return ret;
  919. }
  920. CONFIGFS_ATTR(f_ss_opts_, isoc_maxburst);
  921. static ssize_t f_ss_opts_bulk_buflen_show(struct config_item *item, char *page)
  922. {
  923. struct f_ss_opts *opts = to_f_ss_opts(item);
  924. int result;
  925. mutex_lock(&opts->lock);
  926. result = sprintf(page, "%u\n", opts->bulk_buflen);
  927. mutex_unlock(&opts->lock);
  928. return result;
  929. }
  930. static ssize_t f_ss_opts_bulk_buflen_store(struct config_item *item,
  931. const char *page, size_t len)
  932. {
  933. struct f_ss_opts *opts = to_f_ss_opts(item);
  934. int ret;
  935. u32 num;
  936. mutex_lock(&opts->lock);
  937. if (opts->refcnt) {
  938. ret = -EBUSY;
  939. goto end;
  940. }
  941. ret = kstrtou32(page, 0, &num);
  942. if (ret)
  943. goto end;
  944. opts->bulk_buflen = num;
  945. ret = len;
  946. end:
  947. mutex_unlock(&opts->lock);
  948. return ret;
  949. }
  950. CONFIGFS_ATTR(f_ss_opts_, bulk_buflen);
  951. static ssize_t f_ss_opts_bulk_qlen_show(struct config_item *item, char *page)
  952. {
  953. struct f_ss_opts *opts = to_f_ss_opts(item);
  954. int result;
  955. mutex_lock(&opts->lock);
  956. result = sprintf(page, "%u\n", opts->bulk_qlen);
  957. mutex_unlock(&opts->lock);
  958. return result;
  959. }
  960. static ssize_t f_ss_opts_bulk_qlen_store(struct config_item *item,
  961. const char *page, size_t len)
  962. {
  963. struct f_ss_opts *opts = to_f_ss_opts(item);
  964. int ret;
  965. u32 num;
  966. mutex_lock(&opts->lock);
  967. if (opts->refcnt) {
  968. ret = -EBUSY;
  969. goto end;
  970. }
  971. ret = kstrtou32(page, 0, &num);
  972. if (ret)
  973. goto end;
  974. opts->bulk_qlen = num;
  975. ret = len;
  976. end:
  977. mutex_unlock(&opts->lock);
  978. return ret;
  979. }
  980. CONFIGFS_ATTR(f_ss_opts_, bulk_qlen);
  981. static ssize_t f_ss_opts_iso_qlen_show(struct config_item *item, char *page)
  982. {
  983. struct f_ss_opts *opts = to_f_ss_opts(item);
  984. int result;
  985. mutex_lock(&opts->lock);
  986. result = sprintf(page, "%u\n", opts->iso_qlen);
  987. mutex_unlock(&opts->lock);
  988. return result;
  989. }
  990. static ssize_t f_ss_opts_iso_qlen_store(struct config_item *item,
  991. const char *page, size_t len)
  992. {
  993. struct f_ss_opts *opts = to_f_ss_opts(item);
  994. int ret;
  995. u32 num;
  996. mutex_lock(&opts->lock);
  997. if (opts->refcnt) {
  998. ret = -EBUSY;
  999. goto end;
  1000. }
  1001. ret = kstrtou32(page, 0, &num);
  1002. if (ret)
  1003. goto end;
  1004. opts->iso_qlen = num;
  1005. ret = len;
  1006. end:
  1007. mutex_unlock(&opts->lock);
  1008. return ret;
  1009. }
  1010. CONFIGFS_ATTR(f_ss_opts_, iso_qlen);
  1011. static struct configfs_attribute *ss_attrs[] = {
  1012. &f_ss_opts_attr_pattern,
  1013. &f_ss_opts_attr_isoc_interval,
  1014. &f_ss_opts_attr_isoc_maxpacket,
  1015. &f_ss_opts_attr_isoc_mult,
  1016. &f_ss_opts_attr_isoc_maxburst,
  1017. &f_ss_opts_attr_bulk_buflen,
  1018. &f_ss_opts_attr_bulk_qlen,
  1019. &f_ss_opts_attr_iso_qlen,
  1020. NULL,
  1021. };
  1022. static struct config_item_type ss_func_type = {
  1023. .ct_item_ops = &ss_item_ops,
  1024. .ct_attrs = ss_attrs,
  1025. .ct_owner = THIS_MODULE,
  1026. };
  1027. static void source_sink_free_instance(struct usb_function_instance *fi)
  1028. {
  1029. struct f_ss_opts *ss_opts;
  1030. ss_opts = container_of(fi, struct f_ss_opts, func_inst);
  1031. kfree(ss_opts);
  1032. }
  1033. static struct usb_function_instance *source_sink_alloc_inst(void)
  1034. {
  1035. struct f_ss_opts *ss_opts;
  1036. ss_opts = kzalloc(sizeof(*ss_opts), GFP_KERNEL);
  1037. if (!ss_opts)
  1038. return ERR_PTR(-ENOMEM);
  1039. mutex_init(&ss_opts->lock);
  1040. ss_opts->func_inst.free_func_inst = source_sink_free_instance;
  1041. ss_opts->isoc_interval = GZERO_ISOC_INTERVAL;
  1042. ss_opts->isoc_maxpacket = GZERO_ISOC_MAXPACKET;
  1043. ss_opts->bulk_buflen = GZERO_BULK_BUFLEN;
  1044. ss_opts->bulk_qlen = GZERO_SS_BULK_QLEN;
  1045. ss_opts->iso_qlen = GZERO_SS_ISO_QLEN;
  1046. config_group_init_type_name(&ss_opts->func_inst.group, "",
  1047. &ss_func_type);
  1048. return &ss_opts->func_inst;
  1049. }
  1050. DECLARE_USB_FUNCTION(SourceSink, source_sink_alloc_inst,
  1051. source_sink_alloc_func);
  1052. static int __init sslb_modinit(void)
  1053. {
  1054. int ret;
  1055. ret = usb_function_register(&SourceSinkusb_func);
  1056. if (ret)
  1057. return ret;
  1058. ret = lb_modinit();
  1059. if (ret)
  1060. usb_function_unregister(&SourceSinkusb_func);
  1061. return ret;
  1062. }
  1063. static void __exit sslb_modexit(void)
  1064. {
  1065. usb_function_unregister(&SourceSinkusb_func);
  1066. lb_modexit();
  1067. }
  1068. module_init(sslb_modinit);
  1069. module_exit(sslb_modexit);
  1070. MODULE_LICENSE("GPL");