13 #define pr_fmt(fmt) "g_ffs: " fmt
15 #include <linux/module.h>
24 #if defined CONFIG_USB_FUNCTIONFS_ETH || defined CONFIG_USB_FUNCTIONFS_RNDIS
25 # if defined USB_ETH_RNDIS
28 # ifdef CONFIG_USB_FUNCTIONFS_RNDIS
29 # define USB_ETH_RNDIS y
41 # ifdef CONFIG_USB_FUNCTIONFS_ETH
45 # define gether_cleanup() do { } while (0)
46 # define gether_setup(gadget, hostaddr) ((int)0)
47 # define gfs_hostaddr NULL
52 #define DRIVER_NAME "g_ffs"
53 #define DRIVER_DESC "USB Function Filesystem"
54 #define DRIVER_VERSION "24 Aug 2004"
60 #define GFS_VENDOR_ID 0x1d6b
61 #define GFS_PRODUCT_ID 0x0105
63 #define GFS_MAX_DEVS 10
75 .bLength =
sizeof gfs_dev_desc,
86 static unsigned int func_num;
118 #ifdef CONFIG_USB_FUNCTIONFS_RNDIS
119 { .s =
"FunctionFS + RNDIS" },
121 #ifdef CONFIG_USB_FUNCTIONFS_ETH
122 { .s =
"FunctionFS + ECM" },
124 #ifdef CONFIG_USB_FUNCTIONFS_GENERIC
125 { .s =
"FunctionFS" },
133 .strings = gfs_strings,
142 #ifdef CONFIG_USB_FUNCTIONFS_RNDIS
144 .eth = rndis_bind_config,
148 #ifdef CONFIG_USB_FUNCTIONFS_ETH
150 .eth = eth_bind_config,
154 #ifdef CONFIG_USB_FUNCTIONFS_GENERIC
166 .dev = &gfs_dev_desc,
167 .strings = gfs_dev_strings,
170 .unbind = gfs_unbind,
174 static unsigned int missing_funcs;
175 static bool gfs_ether_setup;
176 static bool gfs_registered;
177 static bool gfs_single_func;
180 static int __init gfs_init(
void)
187 gfs_single_func =
true;
191 ffs_tab = kcalloc(func_num,
sizeof *ffs_tab,
GFP_KERNEL);
195 if (!gfs_single_func)
196 for (i = 0; i < func_num; i++)
197 ffs_tab[i].
name = func_names[i];
199 missing_funcs = func_num;
201 return functionfs_init();
205 static void __exit gfs_exit(
void)
212 gfs_registered =
false;
214 functionfs_cleanup();
221 static struct gfs_ffs_obj *gfs_find_dev(
const char *dev_name)
230 for (i = 0; i < func_num; i++)
237 static int functionfs_ready_callback(
struct ffs_data *
ffs)
258 if (--missing_funcs) {
263 if (gfs_registered) {
267 gfs_registered =
true;
271 gfs_registered =
false;
278 static void functionfs_closed_callback(
struct ffs_data *ffs)
294 gfs_registered =
false;
300 static void *functionfs_acquire_dev_callback(
const char *dev_name)
307 ffs_dev = gfs_find_dev(dev_name);
309 ffs_dev = ERR_PTR(-
ENODEV);
314 ffs_dev = ERR_PTR(-
EBUSY);
353 gfs_ether_setup =
true;
360 for (i = func_num; --
i; ) {
361 ret = functionfs_bind(ffs_tab[i].ffs_data, cdev);
363 while (++i < func_num)
364 functionfs_unbind(ffs_tab[i].ffs_data);
373 c->
c.label = gfs_strings[
sid].
s;
374 c->
c.iConfiguration = gfs_strings[
sid].
id;
375 c->
c.bConfigurationValue = 1 +
i;
386 for (i = 0; i < func_num; i++)
387 functionfs_unbind(ffs_tab[i].ffs_data);
391 gfs_ether_setup =
false;
414 gfs_ether_setup =
false;
416 for (i = func_num; --
i; )
417 if (ffs_tab[i].ffs_data)
418 functionfs_unbind(ffs_tab[i].ffs_data);
437 if (gadget_is_otg(c->
cdev->gadget)) {
448 for (i = 0; i < func_num; i++) {
449 ret = functionfs_bind_config(c->
cdev, c, ffs_tab[i].
ffs_data);
470 #ifdef CONFIG_USB_FUNCTIONFS_ETH
474 return can_support_ecm(c->
cdev->gadget)