f_sourcesink.c 31 KB

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