blob: 39f49f1ad22f287e58df631077a9a1506381707b [file] [log] [blame]
David Brownelle5760fd2008-06-19 17:55:35 -07001/*
2 * f_loopback.c - USB peripheral loopback 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.
David Brownelle5760fd2008-06-19 17:55:35 -070011 */
12
13/* #define VERBOSE_DEBUG */
14
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090015#include <linux/slab.h>
David Brownelle5760fd2008-06-19 17:55:35 -070016#include <linux/kernel.h>
David Brownelle5760fd2008-06-19 17:55:35 -070017#include <linux/device.h>
Sebastian Andrzej Siewiorcf9a08a2012-12-23 21:10:01 +010018#include <linux/module.h>
19#include <linux/err.h>
20#include <linux/usb/composite.h>
David Brownelle5760fd2008-06-19 17:55:35 -070021
22#include "g_zero.h"
Andrzej Pietrasiewicz1efd54e2013-11-07 08:41:26 +010023#include "u_f.h"
David Brownelle5760fd2008-06-19 17:55:35 -070024
25/*
26 * LOOPBACK FUNCTION ... a testing vehicle for USB peripherals,
27 *
28 * This takes messages of various sizes written OUT to a device, and loops
29 * them back so they can be read IN from it. It has been used by certain
30 * test applications. It supports limited testing of data queueing logic.
31 *
32 *
33 * This is currently packaged as a configuration driver, which can't be
34 * combined with other functions to make composite devices. However, it
35 * can be combined with other independent configurations.
36 */
37struct f_loopback {
38 struct usb_function function;
39
40 struct usb_ep *in_ep;
41 struct usb_ep *out_ep;
42};
43
44static inline struct f_loopback *func_to_loop(struct usb_function *f)
45{
46 return container_of(f, struct f_loopback, function);
47}
48
Sebastian Andrzej Siewiorcf9a08a2012-12-23 21:10:01 +010049static unsigned qlen;
50static unsigned buflen;
David Brownelle5760fd2008-06-19 17:55:35 -070051
52/*-------------------------------------------------------------------------*/
53
54static struct usb_interface_descriptor loopback_intf = {
55 .bLength = sizeof loopback_intf,
56 .bDescriptorType = USB_DT_INTERFACE,
57
58 .bNumEndpoints = 2,
59 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
60 /* .iInterface = DYNAMIC */
61};
62
63/* full speed support: */
64
David Brownell7e75bc02008-08-18 17:41:31 -070065static struct usb_endpoint_descriptor fs_loop_source_desc = {
David Brownelle5760fd2008-06-19 17:55:35 -070066 .bLength = USB_DT_ENDPOINT_SIZE,
67 .bDescriptorType = USB_DT_ENDPOINT,
68
69 .bEndpointAddress = USB_DIR_IN,
70 .bmAttributes = USB_ENDPOINT_XFER_BULK,
71};
72
David Brownell7e75bc02008-08-18 17:41:31 -070073static struct usb_endpoint_descriptor fs_loop_sink_desc = {
David Brownelle5760fd2008-06-19 17:55:35 -070074 .bLength = USB_DT_ENDPOINT_SIZE,
75 .bDescriptorType = USB_DT_ENDPOINT,
76
77 .bEndpointAddress = USB_DIR_OUT,
78 .bmAttributes = USB_ENDPOINT_XFER_BULK,
79};
80
81static struct usb_descriptor_header *fs_loopback_descs[] = {
82 (struct usb_descriptor_header *) &loopback_intf,
David Brownell7e75bc02008-08-18 17:41:31 -070083 (struct usb_descriptor_header *) &fs_loop_sink_desc,
84 (struct usb_descriptor_header *) &fs_loop_source_desc,
David Brownelle5760fd2008-06-19 17:55:35 -070085 NULL,
86};
87
88/* high speed support: */
89
David Brownell7e75bc02008-08-18 17:41:31 -070090static struct usb_endpoint_descriptor hs_loop_source_desc = {
David Brownelle5760fd2008-06-19 17:55:35 -070091 .bLength = USB_DT_ENDPOINT_SIZE,
92 .bDescriptorType = USB_DT_ENDPOINT,
93
94 .bmAttributes = USB_ENDPOINT_XFER_BULK,
Harvey Harrison551509d2009-02-11 14:11:36 -080095 .wMaxPacketSize = cpu_to_le16(512),
David Brownelle5760fd2008-06-19 17:55:35 -070096};
97
David Brownell7e75bc02008-08-18 17:41:31 -070098static struct usb_endpoint_descriptor hs_loop_sink_desc = {
David Brownelle5760fd2008-06-19 17:55:35 -070099 .bLength = USB_DT_ENDPOINT_SIZE,
100 .bDescriptorType = USB_DT_ENDPOINT,
101
102 .bmAttributes = USB_ENDPOINT_XFER_BULK,
Harvey Harrison551509d2009-02-11 14:11:36 -0800103 .wMaxPacketSize = cpu_to_le16(512),
David Brownelle5760fd2008-06-19 17:55:35 -0700104};
105
106static struct usb_descriptor_header *hs_loopback_descs[] = {
107 (struct usb_descriptor_header *) &loopback_intf,
David Brownell7e75bc02008-08-18 17:41:31 -0700108 (struct usb_descriptor_header *) &hs_loop_source_desc,
109 (struct usb_descriptor_header *) &hs_loop_sink_desc,
David Brownelle5760fd2008-06-19 17:55:35 -0700110 NULL,
111};
112
Amit Blay57c97c02011-07-03 17:29:31 +0300113/* super speed support: */
114
115static struct usb_endpoint_descriptor ss_loop_source_desc = {
116 .bLength = USB_DT_ENDPOINT_SIZE,
117 .bDescriptorType = USB_DT_ENDPOINT,
118
119 .bmAttributes = USB_ENDPOINT_XFER_BULK,
120 .wMaxPacketSize = cpu_to_le16(1024),
121};
122
Jingoo Han80024182013-12-16 18:40:49 +0900123static struct usb_ss_ep_comp_descriptor ss_loop_source_comp_desc = {
Amit Blay57c97c02011-07-03 17:29:31 +0300124 .bLength = USB_DT_SS_EP_COMP_SIZE,
125 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
126 .bMaxBurst = 0,
127 .bmAttributes = 0,
128 .wBytesPerInterval = 0,
129};
130
131static struct usb_endpoint_descriptor ss_loop_sink_desc = {
132 .bLength = USB_DT_ENDPOINT_SIZE,
133 .bDescriptorType = USB_DT_ENDPOINT,
134
135 .bmAttributes = USB_ENDPOINT_XFER_BULK,
136 .wMaxPacketSize = cpu_to_le16(1024),
137};
138
Jingoo Han80024182013-12-16 18:40:49 +0900139static struct usb_ss_ep_comp_descriptor ss_loop_sink_comp_desc = {
Amit Blay57c97c02011-07-03 17:29:31 +0300140 .bLength = USB_DT_SS_EP_COMP_SIZE,
141 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
142 .bMaxBurst = 0,
143 .bmAttributes = 0,
144 .wBytesPerInterval = 0,
145};
146
147static struct usb_descriptor_header *ss_loopback_descs[] = {
148 (struct usb_descriptor_header *) &loopback_intf,
149 (struct usb_descriptor_header *) &ss_loop_source_desc,
150 (struct usb_descriptor_header *) &ss_loop_source_comp_desc,
151 (struct usb_descriptor_header *) &ss_loop_sink_desc,
152 (struct usb_descriptor_header *) &ss_loop_sink_comp_desc,
153 NULL,
154};
155
David Brownelle5760fd2008-06-19 17:55:35 -0700156/* function-specific strings: */
157
158static struct usb_string strings_loopback[] = {
159 [0].s = "loop input to output",
160 { } /* end of list */
161};
162
163static struct usb_gadget_strings stringtab_loop = {
164 .language = 0x0409, /* en-us */
165 .strings = strings_loopback,
166};
167
168static struct usb_gadget_strings *loopback_strings[] = {
169 &stringtab_loop,
170 NULL,
171};
172
173/*-------------------------------------------------------------------------*/
174
Sebastian Andrzej Siewiorcf9a08a2012-12-23 21:10:01 +0100175static int loopback_bind(struct usb_configuration *c, struct usb_function *f)
David Brownelle5760fd2008-06-19 17:55:35 -0700176{
177 struct usb_composite_dev *cdev = c->cdev;
178 struct f_loopback *loop = func_to_loop(f);
179 int id;
Sebastian Andrzej Siewior10287ba2012-10-22 22:15:06 +0200180 int ret;
David Brownelle5760fd2008-06-19 17:55:35 -0700181
182 /* allocate interface ID(s) */
183 id = usb_interface_id(c, f);
184 if (id < 0)
185 return id;
186 loopback_intf.bInterfaceNumber = id;
187
Sebastian Andrzej Siewior78f46f02012-12-23 21:09:59 +0100188 id = usb_string_id(cdev);
189 if (id < 0)
190 return id;
191 strings_loopback[0].id = id;
192 loopback_intf.iInterface = id;
193
David Brownelle5760fd2008-06-19 17:55:35 -0700194 /* allocate endpoints */
195
David Brownell7e75bc02008-08-18 17:41:31 -0700196 loop->in_ep = usb_ep_autoconfig(cdev->gadget, &fs_loop_source_desc);
David Brownelle5760fd2008-06-19 17:55:35 -0700197 if (!loop->in_ep) {
198autoconf_fail:
199 ERROR(cdev, "%s: can't autoconfigure on %s\n",
200 f->name, cdev->gadget->name);
201 return -ENODEV;
202 }
203 loop->in_ep->driver_data = cdev; /* claim */
204
David Brownell7e75bc02008-08-18 17:41:31 -0700205 loop->out_ep = usb_ep_autoconfig(cdev->gadget, &fs_loop_sink_desc);
David Brownelle5760fd2008-06-19 17:55:35 -0700206 if (!loop->out_ep)
207 goto autoconf_fail;
208 loop->out_ep->driver_data = cdev; /* claim */
209
210 /* support high speed hardware */
Sebastian Andrzej Siewior10287ba2012-10-22 22:15:06 +0200211 hs_loop_source_desc.bEndpointAddress =
212 fs_loop_source_desc.bEndpointAddress;
213 hs_loop_sink_desc.bEndpointAddress = fs_loop_sink_desc.bEndpointAddress;
David Brownelle5760fd2008-06-19 17:55:35 -0700214
Amit Blay57c97c02011-07-03 17:29:31 +0300215 /* support super speed hardware */
Sebastian Andrzej Siewior10287ba2012-10-22 22:15:06 +0200216 ss_loop_source_desc.bEndpointAddress =
217 fs_loop_source_desc.bEndpointAddress;
218 ss_loop_sink_desc.bEndpointAddress = fs_loop_sink_desc.bEndpointAddress;
219
220 ret = usb_assign_descriptors(f, fs_loopback_descs, hs_loopback_descs,
221 ss_loopback_descs);
222 if (ret)
223 return ret;
Amit Blay57c97c02011-07-03 17:29:31 +0300224
David Brownelle5760fd2008-06-19 17:55:35 -0700225 DBG(cdev, "%s speed %s: IN/%s, OUT/%s\n",
Amit Blay57c97c02011-07-03 17:29:31 +0300226 (gadget_is_superspeed(c->cdev->gadget) ? "super" :
227 (gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full")),
David Brownelle5760fd2008-06-19 17:55:35 -0700228 f->name, loop->in_ep->name, loop->out_ep->name);
229 return 0;
230}
231
Sebastian Andrzej Siewiorcf9a08a2012-12-23 21:10:01 +0100232static void lb_free_func(struct usb_function *f)
David Brownelle5760fd2008-06-19 17:55:35 -0700233{
Andrzej Pietrasiewiczc0501f42013-11-07 08:41:27 +0100234 struct f_lb_opts *opts;
235
236 opts = container_of(f->fi, struct f_lb_opts, func_inst);
237
238 mutex_lock(&opts->lock);
239 opts->refcnt--;
240 mutex_unlock(&opts->lock);
241
Sebastian Andrzej Siewior10287ba2012-10-22 22:15:06 +0200242 usb_free_all_descriptors(f);
David Brownelle5760fd2008-06-19 17:55:35 -0700243 kfree(func_to_loop(f));
244}
245
246static void loopback_complete(struct usb_ep *ep, struct usb_request *req)
247{
248 struct f_loopback *loop = ep->driver_data;
249 struct usb_composite_dev *cdev = loop->function.config->cdev;
250 int status = req->status;
251
252 switch (status) {
253
254 case 0: /* normal completion? */
255 if (ep == loop->out_ep) {
David Brownelle5760fd2008-06-19 17:55:35 -0700256 req->zero = (req->actual < req->length);
257 req->length = req->actual;
David Brownelle5760fd2008-06-19 17:55:35 -0700258 }
259
260 /* queue the buffer for some later OUT packet */
261 req->length = buflen;
Felipe Balbie0857ce2014-10-13 15:30:52 -0500262 status = usb_ep_queue(ep, req, GFP_ATOMIC);
David Brownelle5760fd2008-06-19 17:55:35 -0700263 if (status == 0)
264 return;
265
266 /* "should never get here" */
267 /* FALLTHROUGH */
268
269 default:
270 ERROR(cdev, "%s loop complete --> %d, %d/%d\n", ep->name,
271 status, req->actual, req->length);
272 /* FALLTHROUGH */
273
274 /* NOTE: since this driver doesn't maintain an explicit record
275 * of requests it submitted (just maintains qlen count), we
276 * rely on the hardware driver to clean up on disconnect or
277 * endpoint disable.
278 */
279 case -ECONNABORTED: /* hardware forced ep reset */
280 case -ECONNRESET: /* request dequeued */
281 case -ESHUTDOWN: /* disconnect from host */
282 free_ep_req(ep, req);
283 return;
284 }
285}
286
287static void disable_loopback(struct f_loopback *loop)
288{
289 struct usb_composite_dev *cdev;
290
291 cdev = loop->function.config->cdev;
Felipe Balbi2c247802015-03-11 10:00:05 -0500292 disable_endpoints(cdev, loop->in_ep, loop->out_ep, NULL, NULL);
David Brownelle5760fd2008-06-19 17:55:35 -0700293 VDBG(cdev, "%s disabled\n", loop->function.name);
294}
295
Andrzej Pietrasiewicz1efd54e2013-11-07 08:41:26 +0100296static inline struct usb_request *lb_alloc_ep_req(struct usb_ep *ep, int len)
297{
298 return alloc_ep_req(ep, len, buflen);
299}
300
Felipe Balbie0857ce2014-10-13 15:30:52 -0500301static int enable_endpoint(struct usb_composite_dev *cdev, struct f_loopback *loop,
302 struct usb_ep *ep)
David Brownelle5760fd2008-06-19 17:55:35 -0700303{
David Brownelle5760fd2008-06-19 17:55:35 -0700304 struct usb_request *req;
305 unsigned i;
Felipe Balbie0857ce2014-10-13 15:30:52 -0500306 int result;
David Brownelle5760fd2008-06-19 17:55:35 -0700307
Felipe Balbie0857ce2014-10-13 15:30:52 -0500308 /*
309 * one endpoint writes data back IN to the host while another endpoint
310 * just reads OUT packets
311 */
Tatyana Brokhmanea2a1df2011-06-28 16:33:50 +0300312 result = config_ep_by_speed(cdev->gadget, &(loop->function), ep);
313 if (result)
314 goto fail0;
Tatyana Brokhman72c973d2011-06-28 16:33:48 +0300315 result = usb_ep_enable(ep);
Felipe Balbie0857ce2014-10-13 15:30:52 -0500316 if (result < 0)
317 goto fail0;
David Brownelle5760fd2008-06-19 17:55:35 -0700318 ep->driver_data = loop;
319
Felipe Balbie0857ce2014-10-13 15:30:52 -0500320 /*
321 * allocate a bunch of read buffers and queue them all at once.
David Brownelle5760fd2008-06-19 17:55:35 -0700322 * we buffer at most 'qlen' transfers; fewer if any need more
323 * than 'buflen' bytes each.
324 */
325 for (i = 0; i < qlen && result == 0; i++) {
Andrzej Pietrasiewicz1efd54e2013-11-07 08:41:26 +0100326 req = lb_alloc_ep_req(ep, 0);
Felipe Balbie0857ce2014-10-13 15:30:52 -0500327 if (!req)
328 goto fail1;
329
330 req->complete = loopback_complete;
331 result = usb_ep_queue(ep, req, GFP_ATOMIC);
332 if (result) {
333 ERROR(cdev, "%s queue req --> %d\n",
334 ep->name, result);
335 goto fail1;
David Brownelle5760fd2008-06-19 17:55:35 -0700336 }
337 }
338
Felipe Balbie0857ce2014-10-13 15:30:52 -0500339 return 0;
340
341fail1:
342 usb_ep_disable(ep);
343
344fail0:
345 return result;
346}
347
348static int
349enable_loopback(struct usb_composite_dev *cdev, struct f_loopback *loop)
350{
351 int result = 0;
352
353 result = enable_endpoint(cdev, loop, loop->in_ep);
354 if (result)
355 return result;
356
357 result = enable_endpoint(cdev, loop, loop->out_ep);
358 if (result)
359 return result;
360
David Brownelle5760fd2008-06-19 17:55:35 -0700361 DBG(cdev, "%s enabled\n", loop->function.name);
362 return result;
363}
364
365static int loopback_set_alt(struct usb_function *f,
366 unsigned intf, unsigned alt)
367{
368 struct f_loopback *loop = func_to_loop(f);
369 struct usb_composite_dev *cdev = f->config->cdev;
370
371 /* we know alt is zero */
372 if (loop->in_ep->driver_data)
373 disable_loopback(loop);
374 return enable_loopback(cdev, loop);
375}
376
377static void loopback_disable(struct usb_function *f)
378{
379 struct f_loopback *loop = func_to_loop(f);
380
381 disable_loopback(loop);
382}
383
Sebastian Andrzej Siewiorcf9a08a2012-12-23 21:10:01 +0100384static struct usb_function *loopback_alloc(struct usb_function_instance *fi)
David Brownelle5760fd2008-06-19 17:55:35 -0700385{
386 struct f_loopback *loop;
Sebastian Andrzej Siewiorcf9a08a2012-12-23 21:10:01 +0100387 struct f_lb_opts *lb_opts;
David Brownelle5760fd2008-06-19 17:55:35 -0700388
389 loop = kzalloc(sizeof *loop, GFP_KERNEL);
390 if (!loop)
Sebastian Andrzej Siewiorcf9a08a2012-12-23 21:10:01 +0100391 return ERR_PTR(-ENOMEM);
392
393 lb_opts = container_of(fi, struct f_lb_opts, func_inst);
Andrzej Pietrasiewiczc0501f42013-11-07 08:41:27 +0100394
395 mutex_lock(&lb_opts->lock);
396 lb_opts->refcnt++;
397 mutex_unlock(&lb_opts->lock);
398
Sebastian Andrzej Siewiorcf9a08a2012-12-23 21:10:01 +0100399 buflen = lb_opts->bulk_buflen;
400 qlen = lb_opts->qlen;
401 if (!qlen)
402 qlen = 32;
David Brownelle5760fd2008-06-19 17:55:35 -0700403
404 loop->function.name = "loopback";
David Brownelle5760fd2008-06-19 17:55:35 -0700405 loop->function.bind = loopback_bind;
David Brownelle5760fd2008-06-19 17:55:35 -0700406 loop->function.set_alt = loopback_set_alt;
407 loop->function.disable = loopback_disable;
Sebastian Andrzej Siewiorcf9a08a2012-12-23 21:10:01 +0100408 loop->function.strings = loopback_strings;
David Brownelle5760fd2008-06-19 17:55:35 -0700409
Sebastian Andrzej Siewiorcf9a08a2012-12-23 21:10:01 +0100410 loop->function.free_func = lb_free_func;
411
412 return &loop->function;
David Brownelle5760fd2008-06-19 17:55:35 -0700413}
Sebastian Andrzej Siewiorcf9a08a2012-12-23 21:10:01 +0100414
Andrzej Pietrasiewiczc0501f42013-11-07 08:41:27 +0100415static inline struct f_lb_opts *to_f_lb_opts(struct config_item *item)
416{
417 return container_of(to_config_group(item), struct f_lb_opts,
418 func_inst.group);
419}
420
421CONFIGFS_ATTR_STRUCT(f_lb_opts);
422CONFIGFS_ATTR_OPS(f_lb_opts);
423
424static void lb_attr_release(struct config_item *item)
425{
426 struct f_lb_opts *lb_opts = to_f_lb_opts(item);
427
428 usb_put_function_instance(&lb_opts->func_inst);
429}
430
431static struct configfs_item_operations lb_item_ops = {
432 .release = lb_attr_release,
433 .show_attribute = f_lb_opts_attr_show,
434 .store_attribute = f_lb_opts_attr_store,
435};
436
437static ssize_t f_lb_opts_qlen_show(struct f_lb_opts *opts, char *page)
438{
439 int result;
440
441 mutex_lock(&opts->lock);
442 result = sprintf(page, "%d", opts->qlen);
443 mutex_unlock(&opts->lock);
444
445 return result;
446}
447
448static ssize_t f_lb_opts_qlen_store(struct f_lb_opts *opts,
449 const char *page, size_t len)
450{
451 int ret;
452 u32 num;
453
454 mutex_lock(&opts->lock);
455 if (opts->refcnt) {
456 ret = -EBUSY;
457 goto end;
458 }
459
460 ret = kstrtou32(page, 0, &num);
461 if (ret)
462 goto end;
463
464 opts->qlen = num;
465 ret = len;
466end:
467 mutex_unlock(&opts->lock);
468 return ret;
469}
470
471static struct f_lb_opts_attribute f_lb_opts_qlen =
472 __CONFIGFS_ATTR(qlen, S_IRUGO | S_IWUSR,
473 f_lb_opts_qlen_show,
474 f_lb_opts_qlen_store);
475
476static ssize_t f_lb_opts_bulk_buflen_show(struct f_lb_opts *opts, char *page)
477{
478 int result;
479
480 mutex_lock(&opts->lock);
481 result = sprintf(page, "%d", opts->bulk_buflen);
482 mutex_unlock(&opts->lock);
483
484 return result;
485}
486
487static ssize_t f_lb_opts_bulk_buflen_store(struct f_lb_opts *opts,
488 const char *page, size_t len)
489{
490 int ret;
491 u32 num;
492
493 mutex_lock(&opts->lock);
494 if (opts->refcnt) {
495 ret = -EBUSY;
496 goto end;
497 }
498
499 ret = kstrtou32(page, 0, &num);
500 if (ret)
501 goto end;
502
503 opts->bulk_buflen = num;
504 ret = len;
505end:
506 mutex_unlock(&opts->lock);
507 return ret;
508}
509
510static struct f_lb_opts_attribute f_lb_opts_bulk_buflen =
511 __CONFIGFS_ATTR(buflen, S_IRUGO | S_IWUSR,
512 f_lb_opts_bulk_buflen_show,
513 f_lb_opts_bulk_buflen_store);
514
515static struct configfs_attribute *lb_attrs[] = {
516 &f_lb_opts_qlen.attr,
517 &f_lb_opts_bulk_buflen.attr,
518 NULL,
519};
520
521static struct config_item_type lb_func_type = {
522 .ct_item_ops = &lb_item_ops,
523 .ct_attrs = lb_attrs,
524 .ct_owner = THIS_MODULE,
525};
526
Sebastian Andrzej Siewiorcf9a08a2012-12-23 21:10:01 +0100527static void lb_free_instance(struct usb_function_instance *fi)
528{
529 struct f_lb_opts *lb_opts;
530
531 lb_opts = container_of(fi, struct f_lb_opts, func_inst);
532 kfree(lb_opts);
533}
534
535static struct usb_function_instance *loopback_alloc_instance(void)
536{
537 struct f_lb_opts *lb_opts;
538
539 lb_opts = kzalloc(sizeof(*lb_opts), GFP_KERNEL);
540 if (!lb_opts)
541 return ERR_PTR(-ENOMEM);
Andrzej Pietrasiewiczc0501f42013-11-07 08:41:27 +0100542 mutex_init(&lb_opts->lock);
Sebastian Andrzej Siewiorcf9a08a2012-12-23 21:10:01 +0100543 lb_opts->func_inst.free_func_inst = lb_free_instance;
Andrzej Pietrasiewiczc0501f42013-11-07 08:41:27 +0100544 lb_opts->bulk_buflen = GZERO_BULK_BUFLEN;
545 lb_opts->qlen = GZERO_QLEN;
546
547 config_group_init_type_name(&lb_opts->func_inst.group, "",
548 &lb_func_type);
549
Sebastian Andrzej Siewiorcf9a08a2012-12-23 21:10:01 +0100550 return &lb_opts->func_inst;
551}
552DECLARE_USB_FUNCTION(Loopback, loopback_alloc_instance, loopback_alloc);
553
554int __init lb_modinit(void)
555{
556 int ret;
557
558 ret = usb_function_register(&Loopbackusb_func);
559 if (ret)
560 return ret;
561 return ret;
562}
563void __exit lb_modexit(void)
564{
565 usb_function_unregister(&Loopbackusb_func);
566}
567
568MODULE_LICENSE("GPL");