f_sourcesink.c 31 KB

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