2 * f_sourcesink.c - USB peripheral source/sink configuration driver
4 * Copyright (C) 2003-2008 David Brownell
5 * Copyright (C) 2008 by Nokia Corporation
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.
13 /* #define VERBOSE_DEBUG */
15 #include <linux/slab.h>
16 #include <linux/kernel.h>
17 #include <linux/device.h>
18 #include <linux/module.h>
19 #include <linux/usb/composite.h>
20 #include <linux/err.h>
23 #include "gadget_chips.h"
26 #define USB_MS_TO_SS_INTERVAL(x) USB_MS_TO_HS_INTERVAL(x)
36 * SOURCE/SINK FUNCTION ... a primary testing vehicle for USB peripheral
39 * This just sinks bulk packets OUT to the peripheral and sources them IN
40 * to the host, optionally with specific data patterns for integrity tests.
41 * As such it supports basic functionality and load tests.
43 * In terms of control messaging, this supports all the standard requests
44 * plus two that support control-OUT tests. If the optional "autoresume"
45 * mode is enabled, it provides good functional coverage for the "USBCV"
46 * test harness from USB-IF.
48 * Note that because this doesn't queue more than one request at a time,
49 * some other function must be used to test queueing logic. The network
50 * link (g_ether) is the best overall option for that, since its TX and RX
51 * queues are relatively independent, will receive a range of packet sizes,
52 * and can often be made to run out completely. Those issues are important
53 * when stress testing peripheral controller drivers.
56 * This is currently packaged as a configuration driver, which can't be
57 * combined with other functions to make composite devices. However, it
58 * can be combined with other independent configurations.
61 struct usb_function function
;
64 struct usb_ep
*out_ep
;
65 struct usb_ep
*iso_in_ep
;
66 struct usb_ep
*iso_out_ep
;
67 struct usb_ep
*int_in_ep
;
68 struct usb_ep
*int_out_ep
;
72 static inline struct f_sourcesink
*func_to_ss(struct usb_function
*f
)
74 return container_of(f
, struct f_sourcesink
, function
);
77 static unsigned pattern
;
78 static unsigned isoc_interval
;
79 static unsigned isoc_maxpacket
;
80 static unsigned isoc_mult
;
81 static unsigned isoc_maxburst
;
82 static unsigned int_interval
; /* In ms */
83 static unsigned int_maxpacket
;
84 static unsigned int_mult
;
85 static unsigned int_maxburst
;
86 static unsigned buflen
;
88 /*-------------------------------------------------------------------------*/
90 static struct usb_interface_descriptor source_sink_intf_alt0
= {
91 .bLength
= USB_DT_INTERFACE_SIZE
,
92 .bDescriptorType
= USB_DT_INTERFACE
,
94 .bAlternateSetting
= 0,
96 .bInterfaceClass
= USB_CLASS_VENDOR_SPEC
,
97 /* .iInterface = DYNAMIC */
100 static struct usb_interface_descriptor source_sink_intf_alt1
= {
101 .bLength
= USB_DT_INTERFACE_SIZE
,
102 .bDescriptorType
= USB_DT_INTERFACE
,
104 .bAlternateSetting
= 1,
106 .bInterfaceClass
= USB_CLASS_VENDOR_SPEC
,
107 /* .iInterface = DYNAMIC */
110 static struct usb_interface_descriptor source_sink_intf_alt2
= {
111 .bLength
= USB_DT_INTERFACE_SIZE
,
112 .bDescriptorType
= USB_DT_INTERFACE
,
114 .bAlternateSetting
= 2,
116 .bInterfaceClass
= USB_CLASS_VENDOR_SPEC
,
117 /* .iInterface = DYNAMIC */
120 /* full speed support: */
122 static struct usb_endpoint_descriptor fs_source_desc
= {
123 .bLength
= USB_DT_ENDPOINT_SIZE
,
124 .bDescriptorType
= USB_DT_ENDPOINT
,
126 .bEndpointAddress
= USB_DIR_IN
,
127 .bmAttributes
= USB_ENDPOINT_XFER_BULK
,
130 static struct usb_endpoint_descriptor fs_sink_desc
= {
131 .bLength
= USB_DT_ENDPOINT_SIZE
,
132 .bDescriptorType
= USB_DT_ENDPOINT
,
134 .bEndpointAddress
= USB_DIR_OUT
,
135 .bmAttributes
= USB_ENDPOINT_XFER_BULK
,
138 static struct usb_endpoint_descriptor fs_iso_source_desc
= {
139 .bLength
= USB_DT_ENDPOINT_SIZE
,
140 .bDescriptorType
= USB_DT_ENDPOINT
,
142 .bEndpointAddress
= USB_DIR_IN
,
143 .bmAttributes
= USB_ENDPOINT_XFER_ISOC
,
144 .wMaxPacketSize
= cpu_to_le16(1023),
148 static struct usb_endpoint_descriptor fs_iso_sink_desc
= {
149 .bLength
= USB_DT_ENDPOINT_SIZE
,
150 .bDescriptorType
= USB_DT_ENDPOINT
,
152 .bEndpointAddress
= USB_DIR_OUT
,
153 .bmAttributes
= USB_ENDPOINT_XFER_ISOC
,
154 .wMaxPacketSize
= cpu_to_le16(1023),
158 static struct usb_endpoint_descriptor fs_int_source_desc
= {
159 .bLength
= USB_DT_ENDPOINT_SIZE
,
160 .bDescriptorType
= USB_DT_ENDPOINT
,
162 .bEndpointAddress
= USB_DIR_IN
,
163 .bmAttributes
= USB_ENDPOINT_XFER_INT
,
164 .wMaxPacketSize
= cpu_to_le16(64),
165 .bInterval
= GZERO_INT_INTERVAL
,
168 static struct usb_endpoint_descriptor fs_int_sink_desc
= {
169 .bLength
= USB_DT_ENDPOINT_SIZE
,
170 .bDescriptorType
= USB_DT_ENDPOINT
,
172 .bEndpointAddress
= USB_DIR_OUT
,
173 .bmAttributes
= USB_ENDPOINT_XFER_INT
,
174 .wMaxPacketSize
= cpu_to_le16(64),
175 .bInterval
= GZERO_INT_INTERVAL
,
178 static struct usb_descriptor_header
*fs_source_sink_descs
[] = {
179 (struct usb_descriptor_header
*) &source_sink_intf_alt0
,
180 (struct usb_descriptor_header
*) &fs_sink_desc
,
181 (struct usb_descriptor_header
*) &fs_source_desc
,
182 (struct usb_descriptor_header
*) &source_sink_intf_alt1
,
183 #define FS_ALT_IFC_1_OFFSET 3
184 (struct usb_descriptor_header
*) &fs_sink_desc
,
185 (struct usb_descriptor_header
*) &fs_source_desc
,
186 (struct usb_descriptor_header
*) &fs_iso_sink_desc
,
187 (struct usb_descriptor_header
*) &fs_iso_source_desc
,
188 (struct usb_descriptor_header
*) &source_sink_intf_alt2
,
189 #define FS_ALT_IFC_2_OFFSET 8
190 (struct usb_descriptor_header
*) &fs_int_sink_desc
,
191 (struct usb_descriptor_header
*) &fs_int_source_desc
,
195 /* high speed support: */
197 static struct usb_endpoint_descriptor hs_source_desc
= {
198 .bLength
= USB_DT_ENDPOINT_SIZE
,
199 .bDescriptorType
= USB_DT_ENDPOINT
,
201 .bmAttributes
= USB_ENDPOINT_XFER_BULK
,
202 .wMaxPacketSize
= cpu_to_le16(512),
205 static struct usb_endpoint_descriptor hs_sink_desc
= {
206 .bLength
= USB_DT_ENDPOINT_SIZE
,
207 .bDescriptorType
= USB_DT_ENDPOINT
,
209 .bmAttributes
= USB_ENDPOINT_XFER_BULK
,
210 .wMaxPacketSize
= cpu_to_le16(512),
213 static struct usb_endpoint_descriptor hs_iso_source_desc
= {
214 .bLength
= USB_DT_ENDPOINT_SIZE
,
215 .bDescriptorType
= USB_DT_ENDPOINT
,
217 .bmAttributes
= USB_ENDPOINT_XFER_ISOC
,
218 .wMaxPacketSize
= cpu_to_le16(1024),
222 static struct usb_endpoint_descriptor hs_iso_sink_desc
= {
223 .bLength
= USB_DT_ENDPOINT_SIZE
,
224 .bDescriptorType
= USB_DT_ENDPOINT
,
226 .bmAttributes
= USB_ENDPOINT_XFER_ISOC
,
227 .wMaxPacketSize
= cpu_to_le16(1024),
231 static struct usb_endpoint_descriptor hs_int_source_desc
= {
232 .bLength
= USB_DT_ENDPOINT_SIZE
,
233 .bDescriptorType
= USB_DT_ENDPOINT
,
235 .bmAttributes
= USB_ENDPOINT_XFER_INT
,
236 .wMaxPacketSize
= cpu_to_le16(1024),
237 .bInterval
= USB_MS_TO_HS_INTERVAL(GZERO_INT_INTERVAL
),
240 static struct usb_endpoint_descriptor hs_int_sink_desc
= {
241 .bLength
= USB_DT_ENDPOINT_SIZE
,
242 .bDescriptorType
= USB_DT_ENDPOINT
,
244 .bmAttributes
= USB_ENDPOINT_XFER_INT
,
245 .wMaxPacketSize
= cpu_to_le16(1024),
246 .bInterval
= USB_MS_TO_HS_INTERVAL(GZERO_INT_INTERVAL
),
249 static struct usb_descriptor_header
*hs_source_sink_descs
[] = {
250 (struct usb_descriptor_header
*) &source_sink_intf_alt0
,
251 (struct usb_descriptor_header
*) &hs_source_desc
,
252 (struct usb_descriptor_header
*) &hs_sink_desc
,
253 (struct usb_descriptor_header
*) &source_sink_intf_alt1
,
254 #define HS_ALT_IFC_1_OFFSET 3
255 (struct usb_descriptor_header
*) &hs_source_desc
,
256 (struct usb_descriptor_header
*) &hs_sink_desc
,
257 (struct usb_descriptor_header
*) &hs_iso_source_desc
,
258 (struct usb_descriptor_header
*) &hs_iso_sink_desc
,
259 (struct usb_descriptor_header
*) &source_sink_intf_alt2
,
260 #define HS_ALT_IFC_2_OFFSET 8
261 (struct usb_descriptor_header
*) &hs_int_source_desc
,
262 (struct usb_descriptor_header
*) &hs_int_sink_desc
,
266 /* super speed support: */
268 static struct usb_endpoint_descriptor ss_source_desc
= {
269 .bLength
= USB_DT_ENDPOINT_SIZE
,
270 .bDescriptorType
= USB_DT_ENDPOINT
,
272 .bmAttributes
= USB_ENDPOINT_XFER_BULK
,
273 .wMaxPacketSize
= cpu_to_le16(1024),
276 static struct usb_ss_ep_comp_descriptor ss_source_comp_desc
= {
277 .bLength
= USB_DT_SS_EP_COMP_SIZE
,
278 .bDescriptorType
= USB_DT_SS_ENDPOINT_COMP
,
282 .wBytesPerInterval
= 0,
285 static struct usb_endpoint_descriptor ss_sink_desc
= {
286 .bLength
= USB_DT_ENDPOINT_SIZE
,
287 .bDescriptorType
= USB_DT_ENDPOINT
,
289 .bmAttributes
= USB_ENDPOINT_XFER_BULK
,
290 .wMaxPacketSize
= cpu_to_le16(1024),
293 static struct usb_ss_ep_comp_descriptor ss_sink_comp_desc
= {
294 .bLength
= USB_DT_SS_EP_COMP_SIZE
,
295 .bDescriptorType
= USB_DT_SS_ENDPOINT_COMP
,
299 .wBytesPerInterval
= 0,
302 static struct usb_endpoint_descriptor ss_iso_source_desc
= {
303 .bLength
= USB_DT_ENDPOINT_SIZE
,
304 .bDescriptorType
= USB_DT_ENDPOINT
,
306 .bmAttributes
= USB_ENDPOINT_XFER_ISOC
,
307 .wMaxPacketSize
= cpu_to_le16(1024),
311 static struct usb_ss_ep_comp_descriptor ss_iso_source_comp_desc
= {
312 .bLength
= USB_DT_SS_EP_COMP_SIZE
,
313 .bDescriptorType
= USB_DT_SS_ENDPOINT_COMP
,
317 .wBytesPerInterval
= cpu_to_le16(1024),
320 static struct usb_endpoint_descriptor ss_iso_sink_desc
= {
321 .bLength
= USB_DT_ENDPOINT_SIZE
,
322 .bDescriptorType
= USB_DT_ENDPOINT
,
324 .bmAttributes
= USB_ENDPOINT_XFER_ISOC
,
325 .wMaxPacketSize
= cpu_to_le16(1024),
329 static struct usb_ss_ep_comp_descriptor ss_iso_sink_comp_desc
= {
330 .bLength
= USB_DT_SS_EP_COMP_SIZE
,
331 .bDescriptorType
= USB_DT_SS_ENDPOINT_COMP
,
335 .wBytesPerInterval
= cpu_to_le16(1024),
338 static struct usb_endpoint_descriptor ss_int_source_desc
= {
339 .bLength
= USB_DT_ENDPOINT_SIZE
,
340 .bDescriptorType
= USB_DT_ENDPOINT
,
342 .bmAttributes
= USB_ENDPOINT_XFER_INT
,
343 .wMaxPacketSize
= cpu_to_le16(1024),
344 .bInterval
= USB_MS_TO_SS_INTERVAL(GZERO_INT_INTERVAL
),
347 static struct usb_ss_ep_comp_descriptor ss_int_source_comp_desc
= {
348 .bLength
= USB_DT_SS_EP_COMP_SIZE
,
349 .bDescriptorType
= USB_DT_SS_ENDPOINT_COMP
,
353 .wBytesPerInterval
= cpu_to_le16(1024),
356 static struct usb_endpoint_descriptor ss_int_sink_desc
= {
357 .bLength
= USB_DT_ENDPOINT_SIZE
,
358 .bDescriptorType
= USB_DT_ENDPOINT
,
360 .bmAttributes
= USB_ENDPOINT_XFER_INT
,
361 .wMaxPacketSize
= cpu_to_le16(1024),
362 .bInterval
= USB_MS_TO_SS_INTERVAL(GZERO_INT_INTERVAL
),
365 static struct usb_ss_ep_comp_descriptor ss_int_sink_comp_desc
= {
366 .bLength
= USB_DT_SS_EP_COMP_SIZE
,
367 .bDescriptorType
= USB_DT_SS_ENDPOINT_COMP
,
371 .wBytesPerInterval
= cpu_to_le16(1024),
374 static struct usb_descriptor_header
*ss_source_sink_descs
[] = {
375 (struct usb_descriptor_header
*) &source_sink_intf_alt0
,
376 (struct usb_descriptor_header
*) &ss_source_desc
,
377 (struct usb_descriptor_header
*) &ss_source_comp_desc
,
378 (struct usb_descriptor_header
*) &ss_sink_desc
,
379 (struct usb_descriptor_header
*) &ss_sink_comp_desc
,
380 (struct usb_descriptor_header
*) &source_sink_intf_alt1
,
381 #define SS_ALT_IFC_1_OFFSET 5
382 (struct usb_descriptor_header
*) &ss_source_desc
,
383 (struct usb_descriptor_header
*) &ss_source_comp_desc
,
384 (struct usb_descriptor_header
*) &ss_sink_desc
,
385 (struct usb_descriptor_header
*) &ss_sink_comp_desc
,
386 (struct usb_descriptor_header
*) &ss_iso_source_desc
,
387 (struct usb_descriptor_header
*) &ss_iso_source_comp_desc
,
388 (struct usb_descriptor_header
*) &ss_iso_sink_desc
,
389 (struct usb_descriptor_header
*) &ss_iso_sink_comp_desc
,
390 (struct usb_descriptor_header
*) &source_sink_intf_alt2
,
391 #define SS_ALT_IFC_2_OFFSET 14
392 (struct usb_descriptor_header
*) &ss_int_source_desc
,
393 (struct usb_descriptor_header
*) &ss_int_source_comp_desc
,
394 (struct usb_descriptor_header
*) &ss_int_sink_desc
,
395 (struct usb_descriptor_header
*) &ss_int_sink_comp_desc
,
399 /* function-specific strings: */
401 static struct usb_string strings_sourcesink
[] = {
402 [0].s
= "source and sink data",
403 { } /* end of list */
406 static struct usb_gadget_strings stringtab_sourcesink
= {
407 .language
= 0x0409, /* en-us */
408 .strings
= strings_sourcesink
,
411 static struct usb_gadget_strings
*sourcesink_strings
[] = {
412 &stringtab_sourcesink
,
416 /*-------------------------------------------------------------------------*/
417 static const char *get_ep_string(enum eptype ep_type
)
433 static inline struct usb_request
*ss_alloc_ep_req(struct usb_ep
*ep
, int len
)
435 return alloc_ep_req(ep
, len
, buflen
);
438 void free_ep_req(struct usb_ep
*ep
, struct usb_request
*req
)
441 usb_ep_free_request(ep
, req
);
444 static void disable_ep(struct usb_composite_dev
*cdev
, struct usb_ep
*ep
)
448 if (ep
->driver_data
) {
449 value
= usb_ep_disable(ep
);
451 DBG(cdev
, "disable %s --> %d\n",
453 ep
->driver_data
= NULL
;
457 void disable_endpoints(struct usb_composite_dev
*cdev
,
458 struct usb_ep
*in
, struct usb_ep
*out
,
459 struct usb_ep
*iso_in
, struct usb_ep
*iso_out
,
460 struct usb_ep
*int_in
, struct usb_ep
*int_out
)
462 disable_ep(cdev
, in
);
463 disable_ep(cdev
, out
);
465 disable_ep(cdev
, iso_in
);
467 disable_ep(cdev
, iso_out
);
469 disable_ep(cdev
, int_in
);
471 disable_ep(cdev
, int_out
);
475 sourcesink_bind(struct usb_configuration
*c
, struct usb_function
*f
)
477 struct usb_composite_dev
*cdev
= c
->cdev
;
478 struct f_sourcesink
*ss
= func_to_ss(f
);
482 /* allocate interface ID(s) */
483 id
= usb_interface_id(c
, f
);
486 source_sink_intf_alt0
.bInterfaceNumber
= id
;
487 source_sink_intf_alt1
.bInterfaceNumber
= id
;
488 source_sink_intf_alt2
.bInterfaceNumber
= id
;
490 /* allocate bulk endpoints */
491 ss
->in_ep
= usb_ep_autoconfig(cdev
->gadget
, &fs_source_desc
);
494 ERROR(cdev
, "%s: can't autoconfigure on %s\n",
495 f
->name
, cdev
->gadget
->name
);
498 ss
->in_ep
->driver_data
= cdev
; /* claim */
500 ss
->out_ep
= usb_ep_autoconfig(cdev
->gadget
, &fs_sink_desc
);
503 ss
->out_ep
->driver_data
= cdev
; /* claim */
505 /* sanity check the isoc module parameters */
506 if (isoc_interval
< 1)
508 if (isoc_interval
> 16)
512 if (isoc_maxburst
> 15)
515 /* fill in the FS isoc descriptors from the module parameters */
516 fs_iso_source_desc
.wMaxPacketSize
= isoc_maxpacket
> 1023 ?
517 1023 : isoc_maxpacket
;
518 fs_iso_source_desc
.bInterval
= isoc_interval
;
519 fs_iso_sink_desc
.wMaxPacketSize
= isoc_maxpacket
> 1023 ?
520 1023 : isoc_maxpacket
;
521 fs_iso_sink_desc
.bInterval
= isoc_interval
;
523 /* allocate iso endpoints */
524 ss
->iso_in_ep
= usb_ep_autoconfig(cdev
->gadget
, &fs_iso_source_desc
);
527 ss
->iso_in_ep
->driver_data
= cdev
; /* claim */
529 ss
->iso_out_ep
= usb_ep_autoconfig(cdev
->gadget
, &fs_iso_sink_desc
);
530 if (ss
->iso_out_ep
) {
531 ss
->iso_out_ep
->driver_data
= cdev
; /* claim */
533 ss
->iso_in_ep
->driver_data
= NULL
;
534 ss
->iso_in_ep
= NULL
;
537 * We still want to work even if the UDC doesn't have isoc
538 * endpoints, so null out the alt interface that contains
541 fs_source_sink_descs
[FS_ALT_IFC_1_OFFSET
] = NULL
;
542 hs_source_sink_descs
[HS_ALT_IFC_1_OFFSET
] = NULL
;
543 ss_source_sink_descs
[SS_ALT_IFC_1_OFFSET
] = NULL
;
546 if (isoc_maxpacket
> 1024)
547 isoc_maxpacket
= 1024;
549 /* sanity check the interrupt module parameters */
550 if (int_interval
< 1)
552 if (int_interval
> 4096)
556 if (int_maxburst
> 15)
559 /* fill in the FS interrupt descriptors from the module parameters */
560 fs_int_source_desc
.wMaxPacketSize
= int_maxpacket
> 64 ?
562 fs_int_source_desc
.bInterval
= int_interval
> 255 ?
564 fs_int_sink_desc
.wMaxPacketSize
= int_maxpacket
> 64 ?
566 fs_int_sink_desc
.bInterval
= int_interval
> 255 ?
569 /* allocate int endpoints */
570 ss
->int_in_ep
= usb_ep_autoconfig(cdev
->gadget
, &fs_int_source_desc
);
573 ss
->int_in_ep
->driver_data
= cdev
; /* claim */
575 ss
->int_out_ep
= usb_ep_autoconfig(cdev
->gadget
, &fs_int_sink_desc
);
576 if (ss
->int_out_ep
) {
577 ss
->int_out_ep
->driver_data
= cdev
; /* claim */
579 ss
->int_in_ep
->driver_data
= NULL
;
580 ss
->int_in_ep
= NULL
;
582 fs_source_sink_descs
[FS_ALT_IFC_2_OFFSET
] = NULL
;
583 hs_source_sink_descs
[HS_ALT_IFC_2_OFFSET
] = NULL
;
584 ss_source_sink_descs
[SS_ALT_IFC_2_OFFSET
] = NULL
;
587 if (int_maxpacket
> 1024)
588 int_maxpacket
= 1024;
590 /* support high speed hardware */
591 hs_source_desc
.bEndpointAddress
= fs_source_desc
.bEndpointAddress
;
592 hs_sink_desc
.bEndpointAddress
= fs_sink_desc
.bEndpointAddress
;
595 * Fill in the HS isoc and interrupt descriptors from the module
596 * parameters. We assume that the user knows what they are doing and
597 * won't give parameters that their UDC doesn't support.
599 hs_iso_source_desc
.wMaxPacketSize
= isoc_maxpacket
;
600 hs_iso_source_desc
.wMaxPacketSize
|= isoc_mult
<< 11;
601 hs_iso_source_desc
.bInterval
= isoc_interval
;
602 hs_iso_source_desc
.bEndpointAddress
=
603 fs_iso_source_desc
.bEndpointAddress
;
605 hs_iso_sink_desc
.wMaxPacketSize
= isoc_maxpacket
;
606 hs_iso_sink_desc
.wMaxPacketSize
|= isoc_mult
<< 11;
607 hs_iso_sink_desc
.bInterval
= isoc_interval
;
608 hs_iso_sink_desc
.bEndpointAddress
= fs_iso_sink_desc
.bEndpointAddress
;
610 hs_int_source_desc
.wMaxPacketSize
= int_maxpacket
;
611 hs_int_source_desc
.wMaxPacketSize
|= int_mult
<< 11;
612 hs_int_source_desc
.bInterval
= USB_MS_TO_HS_INTERVAL(int_interval
);
613 hs_int_source_desc
.bEndpointAddress
=
614 fs_int_source_desc
.bEndpointAddress
;
616 hs_int_sink_desc
.wMaxPacketSize
= int_maxpacket
;
617 hs_int_sink_desc
.wMaxPacketSize
|= int_mult
<< 11;
618 hs_int_sink_desc
.bInterval
= USB_MS_TO_HS_INTERVAL(int_interval
);
619 hs_int_sink_desc
.bEndpointAddress
= fs_int_sink_desc
.bEndpointAddress
;
621 /* support super speed hardware */
622 ss_source_desc
.bEndpointAddress
=
623 fs_source_desc
.bEndpointAddress
;
624 ss_sink_desc
.bEndpointAddress
=
625 fs_sink_desc
.bEndpointAddress
;
628 * Fill in the SS isoc and interrupt descriptors from the module
629 * parameters. We assume that the user knows what they are doing and
630 * won't give parameters that their UDC doesn't support.
632 ss_iso_source_desc
.wMaxPacketSize
= isoc_maxpacket
;
633 ss_iso_source_desc
.bInterval
= isoc_interval
;
634 ss_iso_source_comp_desc
.bmAttributes
= isoc_mult
;
635 ss_iso_source_comp_desc
.bMaxBurst
= isoc_maxburst
;
636 ss_iso_source_comp_desc
.wBytesPerInterval
=
637 isoc_maxpacket
* (isoc_mult
+ 1) * (isoc_maxburst
+ 1);
638 ss_iso_source_desc
.bEndpointAddress
=
639 fs_iso_source_desc
.bEndpointAddress
;
641 ss_iso_sink_desc
.wMaxPacketSize
= isoc_maxpacket
;
642 ss_iso_sink_desc
.bInterval
= isoc_interval
;
643 ss_iso_sink_comp_desc
.bmAttributes
= isoc_mult
;
644 ss_iso_sink_comp_desc
.bMaxBurst
= isoc_maxburst
;
645 ss_iso_sink_comp_desc
.wBytesPerInterval
=
646 isoc_maxpacket
* (isoc_mult
+ 1) * (isoc_maxburst
+ 1);
647 ss_iso_sink_desc
.bEndpointAddress
= fs_iso_sink_desc
.bEndpointAddress
;
649 ss_int_source_desc
.wMaxPacketSize
= int_maxpacket
;
650 ss_int_source_desc
.bInterval
= USB_MS_TO_SS_INTERVAL(int_interval
);
651 ss_int_source_comp_desc
.bmAttributes
= int_mult
;
652 ss_int_source_comp_desc
.bMaxBurst
= int_maxburst
;
653 ss_int_source_comp_desc
.wBytesPerInterval
=
654 int_maxpacket
* (int_mult
+ 1) * (int_maxburst
+ 1);
655 ss_int_source_desc
.bEndpointAddress
=
656 fs_int_source_desc
.bEndpointAddress
;
658 ss_int_sink_desc
.wMaxPacketSize
= int_maxpacket
;
659 ss_int_sink_desc
.bInterval
= USB_MS_TO_SS_INTERVAL(int_interval
);
660 ss_int_sink_comp_desc
.bmAttributes
= int_mult
;
661 ss_int_sink_comp_desc
.bMaxBurst
= int_maxburst
;
662 ss_int_sink_comp_desc
.wBytesPerInterval
=
663 int_maxpacket
* (int_mult
+ 1) * (int_maxburst
+ 1);
664 ss_int_sink_desc
.bEndpointAddress
= fs_int_sink_desc
.bEndpointAddress
;
666 ret
= usb_assign_descriptors(f
, fs_source_sink_descs
,
667 hs_source_sink_descs
, ss_source_sink_descs
);
671 DBG(cdev
, "%s speed %s: IN/%s, OUT/%s, ISO-IN/%s, ISO-OUT/%s, "
672 "INT-IN/%s, INT-OUT/%s\n",
673 (gadget_is_superspeed(c
->cdev
->gadget
) ? "super" :
674 (gadget_is_dualspeed(c
->cdev
->gadget
) ? "dual" : "full")),
675 f
->name
, ss
->in_ep
->name
, ss
->out_ep
->name
,
676 ss
->iso_in_ep
? ss
->iso_in_ep
->name
: "<none>",
677 ss
->iso_out_ep
? ss
->iso_out_ep
->name
: "<none>",
678 ss
->int_in_ep
? ss
->int_in_ep
->name
: "<none>",
679 ss
->int_out_ep
? ss
->int_out_ep
->name
: "<none>");
684 sourcesink_free_func(struct usb_function
*f
)
686 struct f_ss_opts
*opts
;
688 opts
= container_of(f
->fi
, struct f_ss_opts
, func_inst
);
690 mutex_lock(&opts
->lock
);
692 mutex_unlock(&opts
->lock
);
694 usb_free_all_descriptors(f
);
695 kfree(func_to_ss(f
));
698 /* optionally require specific source/sink data patterns */
699 static int check_read_data(struct f_sourcesink
*ss
, struct usb_request
*req
)
703 struct usb_composite_dev
*cdev
= ss
->function
.config
->cdev
;
708 for (i
= 0; i
< req
->actual
; i
++, buf
++) {
711 /* all-zeroes has no synchronization issues */
717 /* "mod63" stays in sync with short-terminated transfers,
718 * OR otherwise when host and gadget agree on how large
719 * each usb transfer request should be. Resync is done
720 * with set_interface or set_config. (We *WANT* it to
721 * get quickly out of sync if controllers or their drivers
722 * stutter for any reason, including buffer duplication...)
725 if (*buf
== (u8
)(i
% 63))
729 ERROR(cdev
, "bad OUT byte, buf[%d] = %d\n", i
, *buf
);
730 usb_ep_set_halt(ss
->out_ep
);
736 static void reinit_write_data(struct usb_ep
*ep
, struct usb_request
*req
)
743 memset(req
->buf
, 0, req
->length
);
746 for (i
= 0; i
< req
->length
; i
++)
747 *buf
++ = (u8
) (i
% 63);
754 static void source_sink_complete(struct usb_ep
*ep
, struct usb_request
*req
)
756 struct usb_composite_dev
*cdev
;
757 struct f_sourcesink
*ss
= ep
->driver_data
;
758 int status
= req
->status
;
760 /* driver_data will be null if ep has been disabled */
764 cdev
= ss
->function
.config
->cdev
;
768 case 0: /* normal completion? */
769 if (ep
== ss
->out_ep
) {
770 check_read_data(ss
, req
);
772 memset(req
->buf
, 0x55, req
->length
);
776 /* this endpoint is normally active while we're configured */
777 case -ECONNABORTED
: /* hardware forced ep reset */
778 case -ECONNRESET
: /* request dequeued */
779 case -ESHUTDOWN
: /* disconnect from host */
780 VDBG(cdev
, "%s gone (%d), %d/%d\n", ep
->name
, status
,
781 req
->actual
, req
->length
);
782 if (ep
== ss
->out_ep
)
783 check_read_data(ss
, req
);
784 free_ep_req(ep
, req
);
787 case -EOVERFLOW
: /* buffer overrun on read means that
788 * we didn't provide a big enough
793 DBG(cdev
, "%s complete --> %d, %d/%d\n", ep
->name
,
794 status
, req
->actual
, req
->length
);
796 case -EREMOTEIO
: /* short read */
800 status
= usb_ep_queue(ep
, req
, GFP_ATOMIC
);
802 ERROR(cdev
, "kill %s: resubmit %d bytes --> %d\n",
803 ep
->name
, req
->length
, status
);
805 /* FIXME recover later ... somehow */
809 static int source_sink_start_ep(struct f_sourcesink
*ss
, bool is_in
,
810 enum eptype ep_type
, int speed
)
813 struct usb_request
*req
;
816 for (i
= 0; i
< 8; i
++) {
820 case USB_SPEED_SUPER
:
821 size
= isoc_maxpacket
* (isoc_mult
+ 1) *
825 size
= isoc_maxpacket
* (isoc_mult
+ 1);
828 size
= isoc_maxpacket
> 1023 ?
829 1023 : isoc_maxpacket
;
832 ep
= is_in
? ss
->iso_in_ep
: ss
->iso_out_ep
;
833 req
= ss_alloc_ep_req(ep
, size
);
837 case USB_SPEED_SUPER
:
838 size
= int_maxpacket
* (int_mult
+ 1) *
842 size
= int_maxpacket
* (int_mult
+ 1);
845 size
= int_maxpacket
> 1023 ?
846 1023 : int_maxpacket
;
849 ep
= is_in
? ss
->int_in_ep
: ss
->int_out_ep
;
850 req
= ss_alloc_ep_req(ep
, size
);
853 ep
= is_in
? ss
->in_ep
: ss
->out_ep
;
854 req
= ss_alloc_ep_req(ep
, 0);
861 req
->complete
= source_sink_complete
;
863 reinit_write_data(ep
, req
);
864 else if (pattern
!= 2)
865 memset(req
->buf
, 0x55, req
->length
);
867 status
= usb_ep_queue(ep
, req
, GFP_ATOMIC
);
869 struct usb_composite_dev
*cdev
;
871 cdev
= ss
->function
.config
->cdev
;
872 ERROR(cdev
, "start %s%s %s --> %d\n",
873 get_ep_string(ep_type
), is_in
? "IN" : "OUT",
875 free_ep_req(ep
, req
);
878 if (!(ep_type
== EP_ISOC
))
885 static void disable_source_sink(struct f_sourcesink
*ss
)
887 struct usb_composite_dev
*cdev
;
889 cdev
= ss
->function
.config
->cdev
;
890 disable_endpoints(cdev
, ss
->in_ep
, ss
->out_ep
, ss
->iso_in_ep
,
891 ss
->iso_out_ep
, ss
->int_in_ep
, ss
->int_out_ep
);
892 VDBG(cdev
, "%s disabled\n", ss
->function
.name
);
896 enable_source_sink(struct usb_composite_dev
*cdev
, struct f_sourcesink
*ss
,
900 int speed
= cdev
->gadget
->speed
;
904 /* Configure for periodic interrupt endpoint */
907 result
= config_ep_by_speed(cdev
->gadget
,
908 &(ss
->function
), ep
);
912 result
= usb_ep_enable(ep
);
916 ep
->driver_data
= ss
;
917 result
= source_sink_start_ep(ss
, true, EP_INTERRUPT
,
924 ep
->driver_data
= NULL
;
931 * one interrupt endpoint reads (sinks) anything OUT (from the
936 result
= config_ep_by_speed(cdev
->gadget
,
937 &(ss
->function
), ep
);
941 result
= usb_ep_enable(ep
);
945 ep
->driver_data
= ss
;
946 result
= source_sink_start_ep(ss
, false, EP_INTERRUPT
,
951 ep
->driver_data
= NULL
;
959 /* one bulk endpoint writes (sources) zeroes IN (to the host) */
961 result
= config_ep_by_speed(cdev
->gadget
, &(ss
->function
), ep
);
964 result
= usb_ep_enable(ep
);
967 ep
->driver_data
= ss
;
969 result
= source_sink_start_ep(ss
, true, EP_BULK
, speed
);
974 ep
->driver_data
= NULL
;
978 /* one bulk endpoint reads (sinks) anything OUT (from the host) */
980 result
= config_ep_by_speed(cdev
->gadget
, &(ss
->function
), ep
);
983 result
= usb_ep_enable(ep
);
986 ep
->driver_data
= ss
;
988 result
= source_sink_start_ep(ss
, false, EP_BULK
, speed
);
993 ep
->driver_data
= NULL
;
1000 /* one iso endpoint writes (sources) zeroes IN (to the host) */
1003 result
= config_ep_by_speed(cdev
->gadget
, &(ss
->function
), ep
);
1006 result
= usb_ep_enable(ep
);
1009 ep
->driver_data
= ss
;
1011 result
= source_sink_start_ep(ss
, true, EP_ISOC
, speed
);
1017 ep
->driver_data
= NULL
;
1023 /* one iso endpoint reads (sinks) anything OUT (from the host) */
1024 ep
= ss
->iso_out_ep
;
1026 result
= config_ep_by_speed(cdev
->gadget
, &(ss
->function
), ep
);
1029 result
= usb_ep_enable(ep
);
1032 ep
->driver_data
= ss
;
1034 result
= source_sink_start_ep(ss
, false, EP_ISOC
, speed
);
1037 ep
->driver_data
= NULL
;
1045 DBG(cdev
, "%s enabled, alt intf %d\n", ss
->function
.name
, alt
);
1049 static int sourcesink_set_alt(struct usb_function
*f
,
1050 unsigned intf
, unsigned alt
)
1052 struct f_sourcesink
*ss
= func_to_ss(f
);
1053 struct usb_composite_dev
*cdev
= f
->config
->cdev
;
1055 if (ss
->in_ep
->driver_data
)
1056 disable_source_sink(ss
);
1057 else if (alt
== 2 && ss
->int_in_ep
->driver_data
)
1058 disable_source_sink(ss
);
1059 return enable_source_sink(cdev
, ss
, alt
);
1062 static int sourcesink_get_alt(struct usb_function
*f
, unsigned intf
)
1064 struct f_sourcesink
*ss
= func_to_ss(f
);
1069 static void sourcesink_disable(struct usb_function
*f
)
1071 struct f_sourcesink
*ss
= func_to_ss(f
);
1073 disable_source_sink(ss
);
1076 /*-------------------------------------------------------------------------*/
1078 static int sourcesink_setup(struct usb_function
*f
,
1079 const struct usb_ctrlrequest
*ctrl
)
1081 struct usb_configuration
*c
= f
->config
;
1082 struct usb_request
*req
= c
->cdev
->req
;
1083 int value
= -EOPNOTSUPP
;
1084 u16 w_index
= le16_to_cpu(ctrl
->wIndex
);
1085 u16 w_value
= le16_to_cpu(ctrl
->wValue
);
1086 u16 w_length
= le16_to_cpu(ctrl
->wLength
);
1088 req
->length
= USB_COMP_EP0_BUFSIZ
;
1090 /* composite driver infrastructure handles everything except
1091 * the two control test requests.
1093 switch (ctrl
->bRequest
) {
1096 * These are the same vendor-specific requests supported by
1097 * Intel's USB 2.0 compliance test devices. We exceed that
1098 * device spec by allowing multiple-packet requests.
1100 * NOTE: the Control-OUT data stays in req->buf ... better
1101 * would be copying it into a scratch buffer, so that other
1102 * requests may safely intervene.
1104 case 0x5b: /* control WRITE test -- fill the buffer */
1105 if (ctrl
->bRequestType
!= (USB_DIR_OUT
|USB_TYPE_VENDOR
))
1107 if (w_value
|| w_index
)
1109 /* just read that many bytes into the buffer */
1110 if (w_length
> req
->length
)
1114 case 0x5c: /* control READ test -- return the buffer */
1115 if (ctrl
->bRequestType
!= (USB_DIR_IN
|USB_TYPE_VENDOR
))
1117 if (w_value
|| w_index
)
1119 /* expect those bytes are still in the buffer; send back */
1120 if (w_length
> req
->length
)
1128 "unknown control req%02x.%02x v%04x i%04x l%d\n",
1129 ctrl
->bRequestType
, ctrl
->bRequest
,
1130 w_value
, w_index
, w_length
);
1133 /* respond with data transfer or status phase? */
1135 VDBG(c
->cdev
, "source/sink req%02x.%02x v%04x i%04x l%d\n",
1136 ctrl
->bRequestType
, ctrl
->bRequest
,
1137 w_value
, w_index
, w_length
);
1139 req
->length
= value
;
1140 value
= usb_ep_queue(c
->cdev
->gadget
->ep0
, req
, GFP_ATOMIC
);
1142 ERROR(c
->cdev
, "source/sink response, err %d\n",
1146 /* device either stalls (value < 0) or reports success */
1150 static struct usb_function
*source_sink_alloc_func(
1151 struct usb_function_instance
*fi
)
1153 struct f_sourcesink
*ss
;
1154 struct f_ss_opts
*ss_opts
;
1156 ss
= kzalloc(sizeof(*ss
), GFP_KERNEL
);
1160 ss_opts
= container_of(fi
, struct f_ss_opts
, func_inst
);
1162 mutex_lock(&ss_opts
->lock
);
1164 mutex_unlock(&ss_opts
->lock
);
1166 pattern
= ss_opts
->pattern
;
1167 isoc_interval
= ss_opts
->isoc_interval
;
1168 isoc_maxpacket
= ss_opts
->isoc_maxpacket
;
1169 isoc_mult
= ss_opts
->isoc_mult
;
1170 isoc_maxburst
= ss_opts
->isoc_maxburst
;
1171 int_interval
= ss_opts
->int_interval
;
1172 int_maxpacket
= ss_opts
->int_maxpacket
;
1173 int_mult
= ss_opts
->int_mult
;
1174 int_maxburst
= ss_opts
->int_maxburst
;
1175 buflen
= ss_opts
->bulk_buflen
;
1177 ss
->function
.name
= "source/sink";
1178 ss
->function
.bind
= sourcesink_bind
;
1179 ss
->function
.set_alt
= sourcesink_set_alt
;
1180 ss
->function
.get_alt
= sourcesink_get_alt
;
1181 ss
->function
.disable
= sourcesink_disable
;
1182 ss
->function
.setup
= sourcesink_setup
;
1183 ss
->function
.strings
= sourcesink_strings
;
1185 ss
->function
.free_func
= sourcesink_free_func
;
1187 return &ss
->function
;
1190 static inline struct f_ss_opts
*to_f_ss_opts(struct config_item
*item
)
1192 return container_of(to_config_group(item
), struct f_ss_opts
,
1196 CONFIGFS_ATTR_STRUCT(f_ss_opts
);
1197 CONFIGFS_ATTR_OPS(f_ss_opts
);
1199 static void ss_attr_release(struct config_item
*item
)
1201 struct f_ss_opts
*ss_opts
= to_f_ss_opts(item
);
1203 usb_put_function_instance(&ss_opts
->func_inst
);
1206 static struct configfs_item_operations ss_item_ops
= {
1207 .release
= ss_attr_release
,
1208 .show_attribute
= f_ss_opts_attr_show
,
1209 .store_attribute
= f_ss_opts_attr_store
,
1212 static ssize_t
f_ss_opts_pattern_show(struct f_ss_opts
*opts
, char *page
)
1216 mutex_lock(&opts
->lock
);
1217 result
= sprintf(page
, "%u", opts
->pattern
);
1218 mutex_unlock(&opts
->lock
);
1223 static ssize_t
f_ss_opts_pattern_store(struct f_ss_opts
*opts
,
1224 const char *page
, size_t len
)
1229 mutex_lock(&opts
->lock
);
1235 ret
= kstrtou8(page
, 0, &num
);
1239 if (num
!= 0 && num
!= 1 && num
!= 2) {
1244 opts
->pattern
= num
;
1247 mutex_unlock(&opts
->lock
);
1251 static struct f_ss_opts_attribute f_ss_opts_pattern
=
1252 __CONFIGFS_ATTR(pattern
, S_IRUGO
| S_IWUSR
,
1253 f_ss_opts_pattern_show
,
1254 f_ss_opts_pattern_store
);
1256 static ssize_t
f_ss_opts_isoc_interval_show(struct f_ss_opts
*opts
, char *page
)
1260 mutex_lock(&opts
->lock
);
1261 result
= sprintf(page
, "%u", opts
->isoc_interval
);
1262 mutex_unlock(&opts
->lock
);
1267 static ssize_t
f_ss_opts_isoc_interval_store(struct f_ss_opts
*opts
,
1268 const char *page
, size_t len
)
1273 mutex_lock(&opts
->lock
);
1279 ret
= kstrtou8(page
, 0, &num
);
1288 opts
->isoc_interval
= num
;
1291 mutex_unlock(&opts
->lock
);
1295 static struct f_ss_opts_attribute f_ss_opts_isoc_interval
=
1296 __CONFIGFS_ATTR(isoc_interval
, S_IRUGO
| S_IWUSR
,
1297 f_ss_opts_isoc_interval_show
,
1298 f_ss_opts_isoc_interval_store
);
1300 static ssize_t
f_ss_opts_isoc_maxpacket_show(struct f_ss_opts
*opts
, char *page
)
1304 mutex_lock(&opts
->lock
);
1305 result
= sprintf(page
, "%u", opts
->isoc_maxpacket
);
1306 mutex_unlock(&opts
->lock
);
1311 static ssize_t
f_ss_opts_isoc_maxpacket_store(struct f_ss_opts
*opts
,
1312 const char *page
, size_t len
)
1317 mutex_lock(&opts
->lock
);
1323 ret
= kstrtou16(page
, 0, &num
);
1332 opts
->isoc_maxpacket
= num
;
1335 mutex_unlock(&opts
->lock
);
1339 static struct f_ss_opts_attribute f_ss_opts_isoc_maxpacket
=
1340 __CONFIGFS_ATTR(isoc_maxpacket
, S_IRUGO
| S_IWUSR
,
1341 f_ss_opts_isoc_maxpacket_show
,
1342 f_ss_opts_isoc_maxpacket_store
);
1344 static ssize_t
f_ss_opts_isoc_mult_show(struct f_ss_opts
*opts
, char *page
)
1348 mutex_lock(&opts
->lock
);
1349 result
= sprintf(page
, "%u", opts
->isoc_mult
);
1350 mutex_unlock(&opts
->lock
);
1355 static ssize_t
f_ss_opts_isoc_mult_store(struct f_ss_opts
*opts
,
1356 const char *page
, size_t len
)
1361 mutex_lock(&opts
->lock
);
1367 ret
= kstrtou8(page
, 0, &num
);
1376 opts
->isoc_mult
= num
;
1379 mutex_unlock(&opts
->lock
);
1383 static struct f_ss_opts_attribute f_ss_opts_isoc_mult
=
1384 __CONFIGFS_ATTR(isoc_mult
, S_IRUGO
| S_IWUSR
,
1385 f_ss_opts_isoc_mult_show
,
1386 f_ss_opts_isoc_mult_store
);
1388 static ssize_t
f_ss_opts_isoc_maxburst_show(struct f_ss_opts
*opts
, char *page
)
1392 mutex_lock(&opts
->lock
);
1393 result
= sprintf(page
, "%u", opts
->isoc_maxburst
);
1394 mutex_unlock(&opts
->lock
);
1399 static ssize_t
f_ss_opts_isoc_maxburst_store(struct f_ss_opts
*opts
,
1400 const char *page
, size_t len
)
1405 mutex_lock(&opts
->lock
);
1411 ret
= kstrtou8(page
, 0, &num
);
1420 opts
->isoc_maxburst
= num
;
1423 mutex_unlock(&opts
->lock
);
1427 static struct f_ss_opts_attribute f_ss_opts_isoc_maxburst
=
1428 __CONFIGFS_ATTR(isoc_maxburst
, S_IRUGO
| S_IWUSR
,
1429 f_ss_opts_isoc_maxburst_show
,
1430 f_ss_opts_isoc_maxburst_store
);
1432 static ssize_t
f_ss_opts_bulk_buflen_show(struct f_ss_opts
*opts
, char *page
)
1436 mutex_lock(&opts
->lock
);
1437 result
= sprintf(page
, "%u", opts
->bulk_buflen
);
1438 mutex_unlock(&opts
->lock
);
1443 static ssize_t
f_ss_opts_bulk_buflen_store(struct f_ss_opts
*opts
,
1444 const char *page
, size_t len
)
1449 mutex_lock(&opts
->lock
);
1455 ret
= kstrtou32(page
, 0, &num
);
1459 opts
->bulk_buflen
= num
;
1462 mutex_unlock(&opts
->lock
);
1466 static struct f_ss_opts_attribute f_ss_opts_bulk_buflen
=
1467 __CONFIGFS_ATTR(buflen
, S_IRUGO
| S_IWUSR
,
1468 f_ss_opts_bulk_buflen_show
,
1469 f_ss_opts_bulk_buflen_store
);
1471 static ssize_t
f_ss_opts_int_interval_show(struct f_ss_opts
*opts
, char *page
)
1475 mutex_lock(&opts
->lock
);
1476 result
= sprintf(page
, "%u", opts
->int_interval
);
1477 mutex_unlock(&opts
->lock
);
1482 static ssize_t
f_ss_opts_int_interval_store(struct f_ss_opts
*opts
,
1483 const char *page
, size_t len
)
1488 mutex_lock(&opts
->lock
);
1494 ret
= kstrtou32(page
, 0, &num
);
1503 opts
->int_interval
= num
;
1506 mutex_unlock(&opts
->lock
);
1510 static struct f_ss_opts_attribute f_ss_opts_int_interval
=
1511 __CONFIGFS_ATTR(int_interval
, S_IRUGO
| S_IWUSR
,
1512 f_ss_opts_int_interval_show
,
1513 f_ss_opts_int_interval_store
);
1515 static ssize_t
f_ss_opts_int_maxpacket_show(struct f_ss_opts
*opts
, char *page
)
1519 mutex_lock(&opts
->lock
);
1520 result
= sprintf(page
, "%u", opts
->int_maxpacket
);
1521 mutex_unlock(&opts
->lock
);
1526 static ssize_t
f_ss_opts_int_maxpacket_store(struct f_ss_opts
*opts
,
1527 const char *page
, size_t len
)
1532 mutex_lock(&opts
->lock
);
1538 ret
= kstrtou16(page
, 0, &num
);
1547 opts
->int_maxpacket
= num
;
1550 mutex_unlock(&opts
->lock
);
1554 static struct f_ss_opts_attribute f_ss_opts_int_maxpacket
=
1555 __CONFIGFS_ATTR(int_maxpacket
, S_IRUGO
| S_IWUSR
,
1556 f_ss_opts_int_maxpacket_show
,
1557 f_ss_opts_int_maxpacket_store
);
1559 static ssize_t
f_ss_opts_int_mult_show(struct f_ss_opts
*opts
, char *page
)
1563 mutex_lock(&opts
->lock
);
1564 result
= sprintf(page
, "%u", opts
->int_mult
);
1565 mutex_unlock(&opts
->lock
);
1570 static ssize_t
f_ss_opts_int_mult_store(struct f_ss_opts
*opts
,
1571 const char *page
, size_t len
)
1576 mutex_lock(&opts
->lock
);
1582 ret
= kstrtou8(page
, 0, &num
);
1591 opts
->int_mult
= num
;
1594 mutex_unlock(&opts
->lock
);
1598 static struct f_ss_opts_attribute f_ss_opts_int_mult
=
1599 __CONFIGFS_ATTR(int_mult
, S_IRUGO
| S_IWUSR
,
1600 f_ss_opts_int_mult_show
,
1601 f_ss_opts_int_mult_store
);
1603 static ssize_t
f_ss_opts_int_maxburst_show(struct f_ss_opts
*opts
, char *page
)
1607 mutex_lock(&opts
->lock
);
1608 result
= sprintf(page
, "%u", opts
->int_maxburst
);
1609 mutex_unlock(&opts
->lock
);
1614 static ssize_t
f_ss_opts_int_maxburst_store(struct f_ss_opts
*opts
,
1615 const char *page
, size_t len
)
1620 mutex_lock(&opts
->lock
);
1626 ret
= kstrtou8(page
, 0, &num
);
1635 opts
->int_maxburst
= num
;
1638 mutex_unlock(&opts
->lock
);
1642 static struct f_ss_opts_attribute f_ss_opts_int_maxburst
=
1643 __CONFIGFS_ATTR(int_maxburst
, S_IRUGO
| S_IWUSR
,
1644 f_ss_opts_int_maxburst_show
,
1645 f_ss_opts_int_maxburst_store
);
1647 static struct configfs_attribute
*ss_attrs
[] = {
1648 &f_ss_opts_pattern
.attr
,
1649 &f_ss_opts_isoc_interval
.attr
,
1650 &f_ss_opts_isoc_maxpacket
.attr
,
1651 &f_ss_opts_isoc_mult
.attr
,
1652 &f_ss_opts_isoc_maxburst
.attr
,
1653 &f_ss_opts_bulk_buflen
.attr
,
1654 &f_ss_opts_int_interval
.attr
,
1655 &f_ss_opts_int_maxpacket
.attr
,
1656 &f_ss_opts_int_mult
.attr
,
1657 &f_ss_opts_int_maxburst
.attr
,
1661 static struct config_item_type ss_func_type
= {
1662 .ct_item_ops
= &ss_item_ops
,
1663 .ct_attrs
= ss_attrs
,
1664 .ct_owner
= THIS_MODULE
,
1667 static void source_sink_free_instance(struct usb_function_instance
*fi
)
1669 struct f_ss_opts
*ss_opts
;
1671 ss_opts
= container_of(fi
, struct f_ss_opts
, func_inst
);
1675 static struct usb_function_instance
*source_sink_alloc_inst(void)
1677 struct f_ss_opts
*ss_opts
;
1679 ss_opts
= kzalloc(sizeof(*ss_opts
), GFP_KERNEL
);
1681 return ERR_PTR(-ENOMEM
);
1682 mutex_init(&ss_opts
->lock
);
1683 ss_opts
->func_inst
.free_func_inst
= source_sink_free_instance
;
1684 ss_opts
->isoc_interval
= GZERO_ISOC_INTERVAL
;
1685 ss_opts
->isoc_maxpacket
= GZERO_ISOC_MAXPACKET
;
1686 ss_opts
->bulk_buflen
= GZERO_BULK_BUFLEN
;
1687 ss_opts
->int_interval
= GZERO_INT_INTERVAL
;
1688 ss_opts
->int_maxpacket
= GZERO_INT_MAXPACKET
;
1690 config_group_init_type_name(&ss_opts
->func_inst
.group
, "",
1693 return &ss_opts
->func_inst
;
1695 DECLARE_USB_FUNCTION(SourceSink
, source_sink_alloc_inst
,
1696 source_sink_alloc_func
);
1698 static int __init
sslb_modinit(void)
1702 ret
= usb_function_register(&SourceSinkusb_func
);
1707 usb_function_unregister(&SourceSinkusb_func
);
1710 static void __exit
sslb_modexit(void)
1712 usb_function_unregister(&SourceSinkusb_func
);
1715 module_init(sslb_modinit
);
1716 module_exit(sslb_modexit
);
1718 MODULE_LICENSE("GPL");