Michal Nazarewicz | 5ab54cf | 2010-11-12 14:29:28 +0100 | [diff] [blame] | 1 | /* |
| 2 | * g_ffs.c -- user mode file system API for USB composite function controllers |
| 3 | * |
| 4 | * Copyright (C) 2010 Samsung Electronics |
Michal Nazarewicz | 54b8360 | 2012-01-13 15:05:16 +0100 | [diff] [blame] | 5 | * Author: Michal Nazarewicz <mina86@mina86.com> |
Michal Nazarewicz | 5ab54cf | 2010-11-12 14:29:28 +0100 | [diff] [blame] | 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. |
Michal Nazarewicz | 5ab54cf | 2010-11-12 14:29:28 +0100 | [diff] [blame] | 11 | */ |
| 12 | |
Michal Nazarewicz | aa02f17 | 2010-11-17 17:09:47 +0100 | [diff] [blame] | 13 | #define pr_fmt(fmt) "g_ffs: " fmt |
| 14 | |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 15 | #include <linux/module.h> |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 16 | /* |
| 17 | * kbuild is not very cooperative with respect to linking separately |
| 18 | * compiled library objects into one module. So for now we won't use |
| 19 | * separate compilation ... ensuring init/exit sections work to shrink |
| 20 | * the runtime footprint, and giving us at least some parts of what |
| 21 | * a "gcc --combine ... part1.c part2.c part3.c ... " build would. |
| 22 | */ |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 23 | #if defined CONFIG_USB_FUNCTIONFS_ETH || defined CONFIG_USB_FUNCTIONFS_RNDIS |
Andrzej Pietrasiewicz | 85aec59 | 2013-12-03 15:15:25 +0100 | [diff] [blame] | 24 | #include <linux/netdevice.h> |
| 25 | |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 26 | # if defined USB_ETH_RNDIS |
| 27 | # undef USB_ETH_RNDIS |
| 28 | # endif |
| 29 | # ifdef CONFIG_USB_FUNCTIONFS_RNDIS |
| 30 | # define USB_ETH_RNDIS y |
| 31 | # endif |
| 32 | |
Andrzej Pietrasiewicz | f212ad4 | 2013-12-03 15:15:23 +0100 | [diff] [blame] | 33 | # include "u_ecm.h" |
Andrzej Pietrasiewicz | 85aec59 | 2013-12-03 15:15:25 +0100 | [diff] [blame] | 34 | # include "u_gether.h" |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 35 | # ifdef USB_ETH_RNDIS |
Andrzej Pietrasiewicz | 6e257b1 | 2013-12-03 15:15:27 +0100 | [diff] [blame] | 36 | # include "u_rndis.h" |
Andrzej Pietrasiewicz | cbbd14a | 2013-05-24 10:23:02 +0200 | [diff] [blame] | 37 | # include "rndis.h" |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 38 | # endif |
Andrzej Pietrasiewicz | f1a1823 | 2013-05-23 09:22:03 +0200 | [diff] [blame] | 39 | # include "u_ether.h" |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 40 | |
Andrzej Pietrasiewicz | f212ad4 | 2013-12-03 15:15:23 +0100 | [diff] [blame] | 41 | USB_ETHERNET_MODULE_PARAMETERS(); |
| 42 | |
Michal Nazarewicz | f8dae53 | 2010-06-25 16:29:27 +0200 | [diff] [blame] | 43 | # ifdef CONFIG_USB_FUNCTIONFS_ETH |
Andrzej Pietrasiewicz | 6e257b1 | 2013-12-03 15:15:27 +0100 | [diff] [blame] | 44 | static int eth_bind_config(struct usb_configuration *c); |
Andrzej Pietrasiewicz | f212ad4 | 2013-12-03 15:15:23 +0100 | [diff] [blame] | 45 | static struct usb_function_instance *fi_ecm; |
| 46 | static struct usb_function *f_ecm; |
Andrzej Pietrasiewicz | 85aec59 | 2013-12-03 15:15:25 +0100 | [diff] [blame] | 47 | static struct usb_function_instance *fi_geth; |
| 48 | static struct usb_function *f_geth; |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 49 | # endif |
Andrzej Pietrasiewicz | 6e257b1 | 2013-12-03 15:15:27 +0100 | [diff] [blame] | 50 | # ifdef CONFIG_USB_FUNCTIONFS_RNDIS |
| 51 | static int bind_rndis_config(struct usb_configuration *c); |
| 52 | static struct usb_function_instance *fi_rndis; |
| 53 | static struct usb_function *f_rndis; |
| 54 | # endif |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 55 | #endif |
| 56 | |
| 57 | #include "f_fs.c" |
| 58 | |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 59 | #define DRIVER_NAME "g_ffs" |
| 60 | #define DRIVER_DESC "USB Function Filesystem" |
| 61 | #define DRIVER_VERSION "24 Aug 2004" |
| 62 | |
| 63 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 64 | MODULE_AUTHOR("Michal Nazarewicz"); |
| 65 | MODULE_LICENSE("GPL"); |
| 66 | |
Michal Nazarewicz | fc19de6 | 2010-08-12 17:43:48 +0200 | [diff] [blame] | 67 | #define GFS_VENDOR_ID 0x1d6b /* Linux Foundation */ |
| 68 | #define GFS_PRODUCT_ID 0x0105 /* FunctionFS Gadget */ |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 69 | |
Andrzej Pietrasiewicz | 581791f | 2012-05-14 15:51:52 +0200 | [diff] [blame] | 70 | #define GFS_MAX_DEVS 10 |
| 71 | |
Sebastian Andrzej Siewior | 7d16e8d | 2012-09-10 15:01:53 +0200 | [diff] [blame] | 72 | USB_GADGET_COMPOSITE_OPTIONS(); |
| 73 | |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 74 | static struct usb_device_descriptor gfs_dev_desc = { |
| 75 | .bLength = sizeof gfs_dev_desc, |
| 76 | .bDescriptorType = USB_DT_DEVICE, |
| 77 | |
| 78 | .bcdUSB = cpu_to_le16(0x0200), |
| 79 | .bDeviceClass = USB_CLASS_PER_INTERFACE, |
| 80 | |
Michal Nazarewicz | fc19de6 | 2010-08-12 17:43:48 +0200 | [diff] [blame] | 81 | .idVendor = cpu_to_le16(GFS_VENDOR_ID), |
| 82 | .idProduct = cpu_to_le16(GFS_PRODUCT_ID), |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 83 | }; |
| 84 | |
Andrzej Pietrasiewicz | 581791f | 2012-05-14 15:51:52 +0200 | [diff] [blame] | 85 | static char *func_names[GFS_MAX_DEVS]; |
| 86 | static unsigned int func_num; |
| 87 | |
Michal Nazarewicz | fc19de6 | 2010-08-12 17:43:48 +0200 | [diff] [blame] | 88 | module_param_named(bDeviceClass, gfs_dev_desc.bDeviceClass, byte, 0644); |
| 89 | MODULE_PARM_DESC(bDeviceClass, "USB Device class"); |
| 90 | module_param_named(bDeviceSubClass, gfs_dev_desc.bDeviceSubClass, byte, 0644); |
| 91 | MODULE_PARM_DESC(bDeviceSubClass, "USB Device subclass"); |
| 92 | module_param_named(bDeviceProtocol, gfs_dev_desc.bDeviceProtocol, byte, 0644); |
| 93 | MODULE_PARM_DESC(bDeviceProtocol, "USB Device protocol"); |
Andrzej Pietrasiewicz | 581791f | 2012-05-14 15:51:52 +0200 | [diff] [blame] | 94 | module_param_array_named(functions, func_names, charp, &func_num, 0); |
| 95 | MODULE_PARM_DESC(functions, "USB Functions list"); |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 96 | |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 97 | static const struct usb_descriptor_header *gfs_otg_desc[] = { |
| 98 | (const struct usb_descriptor_header *) |
| 99 | &(const struct usb_otg_descriptor) { |
| 100 | .bLength = sizeof(struct usb_otg_descriptor), |
| 101 | .bDescriptorType = USB_DT_OTG, |
| 102 | |
Michal Nazarewicz | fc19de6 | 2010-08-12 17:43:48 +0200 | [diff] [blame] | 103 | /* |
| 104 | * REVISIT SRP-only hardware is possible, although |
| 105 | * it would not be called "OTG" ... |
| 106 | */ |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 107 | .bmAttributes = USB_OTG_SRP | USB_OTG_HNP, |
| 108 | }, |
| 109 | |
| 110 | NULL |
| 111 | }; |
| 112 | |
Michal Nazarewicz | 5ab54cf | 2010-11-12 14:29:28 +0100 | [diff] [blame] | 113 | /* String IDs are assigned dynamically */ |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 114 | static struct usb_string gfs_strings[] = { |
Sebastian Andrzej Siewior | 276e2e4 | 2012-09-06 20:11:21 +0200 | [diff] [blame] | 115 | [USB_GADGET_MANUFACTURER_IDX].s = "", |
Sebastian Andrzej Siewior | d33f74f | 2012-09-10 15:01:57 +0200 | [diff] [blame] | 116 | [USB_GADGET_PRODUCT_IDX].s = DRIVER_DESC, |
Sebastian Andrzej Siewior | 276e2e4 | 2012-09-06 20:11:21 +0200 | [diff] [blame] | 117 | [USB_GADGET_SERIAL_IDX].s = "", |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 118 | #ifdef CONFIG_USB_FUNCTIONFS_RNDIS |
Michal Nazarewicz | f8dae53 | 2010-06-25 16:29:27 +0200 | [diff] [blame] | 119 | { .s = "FunctionFS + RNDIS" }, |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 120 | #endif |
| 121 | #ifdef CONFIG_USB_FUNCTIONFS_ETH |
Michal Nazarewicz | f8dae53 | 2010-06-25 16:29:27 +0200 | [diff] [blame] | 122 | { .s = "FunctionFS + ECM" }, |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 123 | #endif |
| 124 | #ifdef CONFIG_USB_FUNCTIONFS_GENERIC |
Michal Nazarewicz | f8dae53 | 2010-06-25 16:29:27 +0200 | [diff] [blame] | 125 | { .s = "FunctionFS" }, |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 126 | #endif |
| 127 | { } /* end of list */ |
| 128 | }; |
| 129 | |
| 130 | static struct usb_gadget_strings *gfs_dev_strings[] = { |
| 131 | &(struct usb_gadget_strings) { |
| 132 | .language = 0x0409, /* en-us */ |
| 133 | .strings = gfs_strings, |
| 134 | }, |
| 135 | NULL, |
| 136 | }; |
| 137 | |
Michal Nazarewicz | f8dae53 | 2010-06-25 16:29:27 +0200 | [diff] [blame] | 138 | struct gfs_configuration { |
| 139 | struct usb_configuration c; |
Andrzej Pietrasiewicz | 6e257b1 | 2013-12-03 15:15:27 +0100 | [diff] [blame] | 140 | int (*eth)(struct usb_configuration *c); |
Michal Nazarewicz | f8dae53 | 2010-06-25 16:29:27 +0200 | [diff] [blame] | 141 | } gfs_configurations[] = { |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 142 | #ifdef CONFIG_USB_FUNCTIONFS_RNDIS |
Michal Nazarewicz | f8dae53 | 2010-06-25 16:29:27 +0200 | [diff] [blame] | 143 | { |
Andrzej Pietrasiewicz | 6e257b1 | 2013-12-03 15:15:27 +0100 | [diff] [blame] | 144 | .eth = bind_rndis_config, |
Michal Nazarewicz | f8dae53 | 2010-06-25 16:29:27 +0200 | [diff] [blame] | 145 | }, |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 146 | #endif |
| 147 | |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 148 | #ifdef CONFIG_USB_FUNCTIONFS_ETH |
Michal Nazarewicz | f8dae53 | 2010-06-25 16:29:27 +0200 | [diff] [blame] | 149 | { |
| 150 | .eth = eth_bind_config, |
| 151 | }, |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 152 | #endif |
| 153 | |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 154 | #ifdef CONFIG_USB_FUNCTIONFS_GENERIC |
Michal Nazarewicz | f8dae53 | 2010-06-25 16:29:27 +0200 | [diff] [blame] | 155 | { |
| 156 | }, |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 157 | #endif |
Michal Nazarewicz | f8dae53 | 2010-06-25 16:29:27 +0200 | [diff] [blame] | 158 | }; |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 159 | |
Andrzej Pietrasiewicz | 4b187fc | 2013-12-03 15:15:32 +0100 | [diff] [blame^] | 160 | static int functionfs_ready_callback(struct ffs_data *ffs); |
| 161 | static void functionfs_closed_callback(struct ffs_data *ffs); |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 162 | static int gfs_bind(struct usb_composite_dev *cdev); |
| 163 | static int gfs_unbind(struct usb_composite_dev *cdev); |
Michal Nazarewicz | f8dae53 | 2010-06-25 16:29:27 +0200 | [diff] [blame] | 164 | static int gfs_do_config(struct usb_configuration *c); |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 165 | |
Sebastian Andrzej Siewior | c2ec75c | 2012-09-06 20:11:03 +0200 | [diff] [blame] | 166 | static __refdata struct usb_composite_driver gfs_driver = { |
Michal Nazarewicz | fc19de6 | 2010-08-12 17:43:48 +0200 | [diff] [blame] | 167 | .name = DRIVER_NAME, |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 168 | .dev = &gfs_dev_desc, |
| 169 | .strings = gfs_dev_strings, |
Tatyana Brokhman | 35a0e0b | 2011-06-29 16:41:49 +0300 | [diff] [blame] | 170 | .max_speed = USB_SPEED_HIGH, |
Sebastian Andrzej Siewior | 03e42bd | 2012-09-06 20:11:04 +0200 | [diff] [blame] | 171 | .bind = gfs_bind, |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 172 | .unbind = gfs_unbind, |
| 173 | }; |
| 174 | |
Andrzej Pietrasiewicz | 581791f | 2012-05-14 15:51:52 +0200 | [diff] [blame] | 175 | static unsigned int missing_funcs; |
Andrzej Pietrasiewicz | 581791f | 2012-05-14 15:51:52 +0200 | [diff] [blame] | 176 | static bool gfs_registered; |
| 177 | static bool gfs_single_func; |
Andrzej Pietrasiewicz | 4b187fc | 2013-12-03 15:15:32 +0100 | [diff] [blame^] | 178 | static struct ffs_dev **ffs_tab; |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 179 | |
Andrzej Pietrasiewicz | 8545e60 | 2012-03-12 12:55:42 +0100 | [diff] [blame] | 180 | static int __init gfs_init(void) |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 181 | { |
Andrzej Pietrasiewicz | 581791f | 2012-05-14 15:51:52 +0200 | [diff] [blame] | 182 | int i; |
Andrzej Pietrasiewicz | 4b187fc | 2013-12-03 15:15:32 +0100 | [diff] [blame^] | 183 | int ret = 0; |
Andrzej Pietrasiewicz | 581791f | 2012-05-14 15:51:52 +0200 | [diff] [blame] | 184 | |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 185 | ENTER(); |
| 186 | |
Andrzej Pietrasiewicz | 4b187fc | 2013-12-03 15:15:32 +0100 | [diff] [blame^] | 187 | if (func_num < 2) { |
Andrzej Pietrasiewicz | 581791f | 2012-05-14 15:51:52 +0200 | [diff] [blame] | 188 | gfs_single_func = true; |
| 189 | func_num = 1; |
| 190 | } |
| 191 | |
Andrzej Pietrasiewicz | 4b187fc | 2013-12-03 15:15:32 +0100 | [diff] [blame^] | 192 | ffs_tab = kcalloc(func_num, sizeof(*ffs_tab), GFP_KERNEL); |
Andrzej Pietrasiewicz | 581791f | 2012-05-14 15:51:52 +0200 | [diff] [blame] | 193 | if (!ffs_tab) |
| 194 | return -ENOMEM; |
| 195 | |
Andrzej Pietrasiewicz | 4b187fc | 2013-12-03 15:15:32 +0100 | [diff] [blame^] | 196 | for (i = 0; i < func_num; i++) { |
| 197 | ffs_dev_lock(); |
| 198 | ffs_tab[i] = ffs_alloc_dev(); |
| 199 | ffs_dev_unlock(); |
| 200 | if (IS_ERR(ffs_tab[i])) { |
| 201 | ret = PTR_ERR(ffs_tab[i]); |
| 202 | --i; |
| 203 | goto no_dev; |
| 204 | } |
| 205 | if (gfs_single_func) |
| 206 | ret = ffs_single_dev(ffs_tab[i]); |
| 207 | else |
| 208 | ret = ffs_name_dev(ffs_tab[i], func_names[i]); |
| 209 | if (ret) |
| 210 | goto no_dev; |
| 211 | ffs_tab[i]->ffs_ready_callback = functionfs_ready_callback; |
| 212 | ffs_tab[i]->ffs_closed_callback = functionfs_closed_callback; |
| 213 | } |
Andrzej Pietrasiewicz | 581791f | 2012-05-14 15:51:52 +0200 | [diff] [blame] | 214 | |
| 215 | missing_funcs = func_num; |
| 216 | |
Andrzej Pietrasiewicz | 4b187fc | 2013-12-03 15:15:32 +0100 | [diff] [blame^] | 217 | return 0; |
| 218 | no_dev: |
| 219 | ffs_dev_lock(); |
| 220 | while (i >= 0) |
| 221 | ffs_free_dev(ffs_tab[i--]); |
| 222 | ffs_dev_unlock(); |
| 223 | kfree(ffs_tab); |
| 224 | return ret; |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 225 | } |
| 226 | module_init(gfs_init); |
| 227 | |
Andrzej Pietrasiewicz | 8545e60 | 2012-03-12 12:55:42 +0100 | [diff] [blame] | 228 | static void __exit gfs_exit(void) |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 229 | { |
Andrzej Pietrasiewicz | 4b187fc | 2013-12-03 15:15:32 +0100 | [diff] [blame^] | 230 | int i; |
| 231 | |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 232 | ENTER(); |
Andrzej Pietrasiewicz | 4b187fc | 2013-12-03 15:15:32 +0100 | [diff] [blame^] | 233 | ffs_dev_lock(); |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 234 | |
Andrzej Pietrasiewicz | 581791f | 2012-05-14 15:51:52 +0200 | [diff] [blame] | 235 | if (gfs_registered) |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 236 | usb_composite_unregister(&gfs_driver); |
Andrzej Pietrasiewicz | 581791f | 2012-05-14 15:51:52 +0200 | [diff] [blame] | 237 | gfs_registered = false; |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 238 | |
Andrzej Pietrasiewicz | 4b187fc | 2013-12-03 15:15:32 +0100 | [diff] [blame^] | 239 | for (i = 0; i < func_num; i++) |
| 240 | ffs_free_dev(ffs_tab[i]); |
| 241 | ffs_dev_unlock(); |
Andrzej Pietrasiewicz | 581791f | 2012-05-14 15:51:52 +0200 | [diff] [blame] | 242 | kfree(ffs_tab); |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 243 | } |
| 244 | module_exit(gfs_exit); |
| 245 | |
Andrzej Pietrasiewicz | 4b187fc | 2013-12-03 15:15:32 +0100 | [diff] [blame^] | 246 | /* |
| 247 | * The caller of this function takes ffs_lock |
| 248 | */ |
Andrzej Pietrasiewicz | 581791f | 2012-05-14 15:51:52 +0200 | [diff] [blame] | 249 | static int functionfs_ready_callback(struct ffs_data *ffs) |
| 250 | { |
Andrzej Pietrasiewicz | 4b187fc | 2013-12-03 15:15:32 +0100 | [diff] [blame^] | 251 | int ret = 0; |
Andrzej Pietrasiewicz | 581791f | 2012-05-14 15:51:52 +0200 | [diff] [blame] | 252 | |
Andrzej Pietrasiewicz | 4b187fc | 2013-12-03 15:15:32 +0100 | [diff] [blame^] | 253 | if (--missing_funcs) |
| 254 | return 0; |
Andrzej Pietrasiewicz | 581791f | 2012-05-14 15:51:52 +0200 | [diff] [blame] | 255 | |
Andrzej Pietrasiewicz | 4b187fc | 2013-12-03 15:15:32 +0100 | [diff] [blame^] | 256 | if (gfs_registered) |
| 257 | return -EBUSY; |
Andrzej Pietrasiewicz | 581791f | 2012-05-14 15:51:52 +0200 | [diff] [blame] | 258 | |
Andrzej Pietrasiewicz | 581791f | 2012-05-14 15:51:52 +0200 | [diff] [blame] | 259 | gfs_registered = true; |
| 260 | |
Sebastian Andrzej Siewior | 03e42bd | 2012-09-06 20:11:04 +0200 | [diff] [blame] | 261 | ret = usb_composite_probe(&gfs_driver); |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 262 | if (unlikely(ret < 0)) |
Andrzej Pietrasiewicz | 581791f | 2012-05-14 15:51:52 +0200 | [diff] [blame] | 263 | gfs_registered = false; |
Andrzej Pietrasiewicz | 4b187fc | 2013-12-03 15:15:32 +0100 | [diff] [blame^] | 264 | |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 265 | return ret; |
| 266 | } |
| 267 | |
Andrzej Pietrasiewicz | 4b187fc | 2013-12-03 15:15:32 +0100 | [diff] [blame^] | 268 | /* |
| 269 | * The caller of this function takes ffs_lock |
| 270 | */ |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 271 | static void functionfs_closed_callback(struct ffs_data *ffs) |
| 272 | { |
Andrzej Pietrasiewicz | 581791f | 2012-05-14 15:51:52 +0200 | [diff] [blame] | 273 | missing_funcs++; |
| 274 | |
| 275 | if (gfs_registered) |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 276 | usb_composite_unregister(&gfs_driver); |
Andrzej Pietrasiewicz | 581791f | 2012-05-14 15:51:52 +0200 | [diff] [blame] | 277 | gfs_registered = false; |
Andrzej Pietrasiewicz | 581791f | 2012-05-14 15:51:52 +0200 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | /* |
Andrzej Pietrasiewicz | 4b187fc | 2013-12-03 15:15:32 +0100 | [diff] [blame^] | 281 | * It is assumed that gfs_bind is called from a context where ffs_lock is held |
Andrzej Pietrasiewicz | 581791f | 2012-05-14 15:51:52 +0200 | [diff] [blame] | 282 | */ |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 283 | static int gfs_bind(struct usb_composite_dev *cdev) |
| 284 | { |
Andrzej Pietrasiewicz | 6e257b1 | 2013-12-03 15:15:27 +0100 | [diff] [blame] | 285 | #if defined CONFIG_USB_FUNCTIONFS_ETH || defined CONFIG_USB_FUNCTIONFS_RNDIS |
Andrzej Pietrasiewicz | 85aec59 | 2013-12-03 15:15:25 +0100 | [diff] [blame] | 286 | struct net_device *net; |
| 287 | #endif |
Michal Nazarewicz | f8dae53 | 2010-06-25 16:29:27 +0200 | [diff] [blame] | 288 | int ret, i; |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 289 | |
| 290 | ENTER(); |
| 291 | |
Andrzej Pietrasiewicz | 581791f | 2012-05-14 15:51:52 +0200 | [diff] [blame] | 292 | if (missing_funcs) |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 293 | return -ENODEV; |
Andrzej Pietrasiewicz | f212ad4 | 2013-12-03 15:15:23 +0100 | [diff] [blame] | 294 | #if defined CONFIG_USB_FUNCTIONFS_ETH |
| 295 | if (can_support_ecm(cdev->gadget)) { |
| 296 | struct f_ecm_opts *ecm_opts; |
| 297 | |
| 298 | fi_ecm = usb_get_function_instance("ecm"); |
| 299 | if (IS_ERR(fi_ecm)) |
| 300 | return PTR_ERR(fi_ecm); |
| 301 | ecm_opts = container_of(fi_ecm, struct f_ecm_opts, func_inst); |
Andrzej Pietrasiewicz | 85aec59 | 2013-12-03 15:15:25 +0100 | [diff] [blame] | 302 | net = ecm_opts->net; |
Andrzej Pietrasiewicz | f212ad4 | 2013-12-03 15:15:23 +0100 | [diff] [blame] | 303 | } else { |
Andrzej Pietrasiewicz | 85aec59 | 2013-12-03 15:15:25 +0100 | [diff] [blame] | 304 | struct f_gether_opts *geth_opts; |
| 305 | |
| 306 | fi_geth = usb_get_function_instance("geth"); |
| 307 | if (IS_ERR(fi_geth)) |
| 308 | return PTR_ERR(fi_geth); |
| 309 | geth_opts = container_of(fi_geth, struct f_gether_opts, |
| 310 | func_inst); |
| 311 | net = geth_opts->net; |
Andrzej Pietrasiewicz | f212ad4 | 2013-12-03 15:15:23 +0100 | [diff] [blame] | 312 | } |
Andrzej Pietrasiewicz | 6e257b1 | 2013-12-03 15:15:27 +0100 | [diff] [blame] | 313 | #endif |
Andrzej Pietrasiewicz | 85aec59 | 2013-12-03 15:15:25 +0100 | [diff] [blame] | 314 | |
Andrzej Pietrasiewicz | 6e257b1 | 2013-12-03 15:15:27 +0100 | [diff] [blame] | 315 | #ifdef CONFIG_USB_FUNCTIONFS_RNDIS |
| 316 | { |
| 317 | struct f_rndis_opts *rndis_opts; |
| 318 | |
| 319 | fi_rndis = usb_get_function_instance("rndis"); |
| 320 | if (IS_ERR(fi_rndis)) { |
| 321 | ret = PTR_ERR(fi_rndis); |
| 322 | goto error; |
| 323 | } |
| 324 | rndis_opts = container_of(fi_rndis, struct f_rndis_opts, |
| 325 | func_inst); |
| 326 | #ifndef CONFIG_USB_FUNCTIONFS_ETH |
| 327 | net = rndis_opts->net; |
| 328 | #endif |
| 329 | } |
| 330 | #endif |
| 331 | |
| 332 | #if defined CONFIG_USB_FUNCTIONFS_ETH || defined CONFIG_USB_FUNCTIONFS_RNDIS |
| 333 | gether_set_qmult(net, qmult); |
Andrzej Pietrasiewicz | 85aec59 | 2013-12-03 15:15:25 +0100 | [diff] [blame] | 334 | if (!gether_set_host_addr(net, host_addr)) |
| 335 | pr_info("using host ethernet address: %s", host_addr); |
| 336 | if (!gether_set_dev_addr(net, dev_addr)) |
| 337 | pr_info("using self ethernet address: %s", dev_addr); |
Sebastian Andrzej Siewior | d6a0143 | 2012-12-23 21:10:12 +0100 | [diff] [blame] | 338 | #endif |
Andrzej Pietrasiewicz | f212ad4 | 2013-12-03 15:15:23 +0100 | [diff] [blame] | 339 | |
| 340 | #if defined CONFIG_USB_FUNCTIONFS_RNDIS && defined CONFIG_USB_FUNCTIONFS_ETH |
Andrzej Pietrasiewicz | 85aec59 | 2013-12-03 15:15:25 +0100 | [diff] [blame] | 341 | gether_set_gadget(net, cdev->gadget); |
| 342 | ret = gether_register_netdev(net); |
| 343 | if (ret) |
Andrzej Pietrasiewicz | 6e257b1 | 2013-12-03 15:15:27 +0100 | [diff] [blame] | 344 | goto error_rndis; |
Andrzej Pietrasiewicz | 85aec59 | 2013-12-03 15:15:25 +0100 | [diff] [blame] | 345 | |
Andrzej Pietrasiewicz | f212ad4 | 2013-12-03 15:15:23 +0100 | [diff] [blame] | 346 | if (can_support_ecm(cdev->gadget)) { |
| 347 | struct f_ecm_opts *ecm_opts; |
| 348 | |
| 349 | ecm_opts = container_of(fi_ecm, struct f_ecm_opts, func_inst); |
Andrzej Pietrasiewicz | f212ad4 | 2013-12-03 15:15:23 +0100 | [diff] [blame] | 350 | ecm_opts->bound = true; |
Andrzej Pietrasiewicz | 85aec59 | 2013-12-03 15:15:25 +0100 | [diff] [blame] | 351 | } else { |
| 352 | struct f_gether_opts *geth_opts; |
| 353 | |
| 354 | geth_opts = container_of(fi_geth, struct f_gether_opts, |
| 355 | func_inst); |
| 356 | geth_opts->bound = true; |
Sebastian Andrzej Siewior | d6a0143 | 2012-12-23 21:10:12 +0100 | [diff] [blame] | 357 | } |
Andrzej Pietrasiewicz | 6e257b1 | 2013-12-03 15:15:27 +0100 | [diff] [blame] | 358 | |
| 359 | rndis_borrow_net(fi_rndis, net); |
Andrzej Pietrasiewicz | f212ad4 | 2013-12-03 15:15:23 +0100 | [diff] [blame] | 360 | #endif |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 361 | |
Michal Nazarewicz | f8dae53 | 2010-06-25 16:29:27 +0200 | [diff] [blame] | 362 | ret = usb_string_ids_tab(cdev, gfs_strings); |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 363 | if (unlikely(ret < 0)) |
Andrzej Pietrasiewicz | 6e257b1 | 2013-12-03 15:15:27 +0100 | [diff] [blame] | 364 | goto error_rndis; |
Sebastian Andrzej Siewior | d33f74f | 2012-09-10 15:01:57 +0200 | [diff] [blame] | 365 | gfs_dev_desc.iProduct = gfs_strings[USB_GADGET_PRODUCT_IDX].id; |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 366 | |
Andrzej Pietrasiewicz | 3416905 | 2013-03-11 16:32:14 +0100 | [diff] [blame] | 367 | for (i = func_num; i--; ) { |
Andrzej Pietrasiewicz | 4b187fc | 2013-12-03 15:15:32 +0100 | [diff] [blame^] | 368 | ret = functionfs_bind(ffs_tab[i]->ffs_data, cdev); |
Andrzej Pietrasiewicz | 581791f | 2012-05-14 15:51:52 +0200 | [diff] [blame] | 369 | if (unlikely(ret < 0)) { |
| 370 | while (++i < func_num) |
Andrzej Pietrasiewicz | 4b187fc | 2013-12-03 15:15:32 +0100 | [diff] [blame^] | 371 | functionfs_unbind(ffs_tab[i]->ffs_data); |
Andrzej Pietrasiewicz | 6e257b1 | 2013-12-03 15:15:27 +0100 | [diff] [blame] | 372 | goto error_rndis; |
Andrzej Pietrasiewicz | 581791f | 2012-05-14 15:51:52 +0200 | [diff] [blame] | 373 | } |
| 374 | } |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 375 | |
Michal Nazarewicz | f8dae53 | 2010-06-25 16:29:27 +0200 | [diff] [blame] | 376 | for (i = 0; i < ARRAY_SIZE(gfs_configurations); ++i) { |
| 377 | struct gfs_configuration *c = gfs_configurations + i; |
Sebastian Andrzej Siewior | 276e2e4 | 2012-09-06 20:11:21 +0200 | [diff] [blame] | 378 | int sid = USB_GADGET_FIRST_AVAIL_IDX + i; |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 379 | |
Sebastian Andrzej Siewior | 276e2e4 | 2012-09-06 20:11:21 +0200 | [diff] [blame] | 380 | c->c.label = gfs_strings[sid].s; |
| 381 | c->c.iConfiguration = gfs_strings[sid].id; |
Michal Nazarewicz | f8dae53 | 2010-06-25 16:29:27 +0200 | [diff] [blame] | 382 | c->c.bConfigurationValue = 1 + i; |
| 383 | c->c.bmAttributes = USB_CONFIG_ATT_SELFPOWER; |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 384 | |
Uwe Kleine-König | c9bfff9 | 2010-08-12 17:43:55 +0200 | [diff] [blame] | 385 | ret = usb_add_config(cdev, &c->c, gfs_do_config); |
Michal Nazarewicz | f8dae53 | 2010-06-25 16:29:27 +0200 | [diff] [blame] | 386 | if (unlikely(ret < 0)) |
| 387 | goto error_unbind; |
| 388 | } |
Sebastian Andrzej Siewior | 7d16e8d | 2012-09-10 15:01:53 +0200 | [diff] [blame] | 389 | usb_composite_overwrite_options(cdev, &coverwrite); |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 390 | return 0; |
| 391 | |
| 392 | error_unbind: |
Andrzej Pietrasiewicz | 581791f | 2012-05-14 15:51:52 +0200 | [diff] [blame] | 393 | for (i = 0; i < func_num; i++) |
Andrzej Pietrasiewicz | 4b187fc | 2013-12-03 15:15:32 +0100 | [diff] [blame^] | 394 | functionfs_unbind(ffs_tab[i]->ffs_data); |
Andrzej Pietrasiewicz | 6e257b1 | 2013-12-03 15:15:27 +0100 | [diff] [blame] | 395 | error_rndis: |
| 396 | #ifdef CONFIG_USB_FUNCTIONFS_RNDIS |
| 397 | usb_put_function_instance(fi_rndis); |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 398 | error: |
Andrzej Pietrasiewicz | 6e257b1 | 2013-12-03 15:15:27 +0100 | [diff] [blame] | 399 | #endif |
Andrzej Pietrasiewicz | f212ad4 | 2013-12-03 15:15:23 +0100 | [diff] [blame] | 400 | #if defined CONFIG_USB_FUNCTIONFS_ETH |
| 401 | if (can_support_ecm(cdev->gadget)) |
| 402 | usb_put_function_instance(fi_ecm); |
| 403 | else |
Andrzej Pietrasiewicz | 85aec59 | 2013-12-03 15:15:25 +0100 | [diff] [blame] | 404 | usb_put_function_instance(fi_geth); |
Andrzej Pietrasiewicz | f212ad4 | 2013-12-03 15:15:23 +0100 | [diff] [blame] | 405 | #endif |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 406 | return ret; |
| 407 | } |
| 408 | |
Andrzej Pietrasiewicz | 581791f | 2012-05-14 15:51:52 +0200 | [diff] [blame] | 409 | /* |
Andrzej Pietrasiewicz | 4b187fc | 2013-12-03 15:15:32 +0100 | [diff] [blame^] | 410 | * It is assumed that gfs_unbind is called from a context where ffs_lock is held |
Andrzej Pietrasiewicz | 581791f | 2012-05-14 15:51:52 +0200 | [diff] [blame] | 411 | */ |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 412 | static int gfs_unbind(struct usb_composite_dev *cdev) |
| 413 | { |
Andrzej Pietrasiewicz | 581791f | 2012-05-14 15:51:52 +0200 | [diff] [blame] | 414 | int i; |
| 415 | |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 416 | ENTER(); |
| 417 | |
Andrzej Pietrasiewicz | f212ad4 | 2013-12-03 15:15:23 +0100 | [diff] [blame] | 418 | |
Andrzej Pietrasiewicz | 6e257b1 | 2013-12-03 15:15:27 +0100 | [diff] [blame] | 419 | #ifdef CONFIG_USB_FUNCTIONFS_RNDIS |
| 420 | usb_put_function(f_rndis); |
| 421 | usb_put_function_instance(fi_rndis); |
| 422 | #endif |
| 423 | |
Andrzej Pietrasiewicz | f212ad4 | 2013-12-03 15:15:23 +0100 | [diff] [blame] | 424 | #if defined CONFIG_USB_FUNCTIONFS_ETH |
| 425 | if (can_support_ecm(cdev->gadget)) { |
| 426 | usb_put_function(f_ecm); |
| 427 | usb_put_function_instance(fi_ecm); |
| 428 | } else { |
Andrzej Pietrasiewicz | 85aec59 | 2013-12-03 15:15:25 +0100 | [diff] [blame] | 429 | usb_put_function(f_geth); |
| 430 | usb_put_function_instance(fi_geth); |
Andrzej Pietrasiewicz | f212ad4 | 2013-12-03 15:15:23 +0100 | [diff] [blame] | 431 | } |
Andrzej Pietrasiewicz | f212ad4 | 2013-12-03 15:15:23 +0100 | [diff] [blame] | 432 | #endif |
Andrzej Pietrasiewicz | 1ec8f00 | 2013-12-03 15:15:22 +0100 | [diff] [blame] | 433 | |
Michal Nazarewicz | fc19de6 | 2010-08-12 17:43:48 +0200 | [diff] [blame] | 434 | /* |
| 435 | * We may have been called in an error recovery from |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 436 | * composite_bind() after gfs_unbind() failure so we need to |
Andrzej Pietrasiewicz | 1ec8f00 | 2013-12-03 15:15:22 +0100 | [diff] [blame] | 437 | * check if instance's ffs_data is not NULL since gfs_bind() handles |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 438 | * all error recovery itself. I'd rather we werent called |
| 439 | * from composite on orror recovery, but what you're gonna |
Michal Nazarewicz | fc19de6 | 2010-08-12 17:43:48 +0200 | [diff] [blame] | 440 | * do...? |
| 441 | */ |
Andrzej Pietrasiewicz | 3416905 | 2013-03-11 16:32:14 +0100 | [diff] [blame] | 442 | for (i = func_num; i--; ) |
Andrzej Pietrasiewicz | 4b187fc | 2013-12-03 15:15:32 +0100 | [diff] [blame^] | 443 | if (ffs_tab[i]->ffs_data) |
| 444 | functionfs_unbind(ffs_tab[i]->ffs_data); |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 445 | |
| 446 | return 0; |
| 447 | } |
| 448 | |
Andrzej Pietrasiewicz | 581791f | 2012-05-14 15:51:52 +0200 | [diff] [blame] | 449 | /* |
| 450 | * It is assumed that gfs_do_config is called from a context where |
Andrzej Pietrasiewicz | 4b187fc | 2013-12-03 15:15:32 +0100 | [diff] [blame^] | 451 | * ffs_lock is held |
Andrzej Pietrasiewicz | 581791f | 2012-05-14 15:51:52 +0200 | [diff] [blame] | 452 | */ |
Michal Nazarewicz | f8dae53 | 2010-06-25 16:29:27 +0200 | [diff] [blame] | 453 | static int gfs_do_config(struct usb_configuration *c) |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 454 | { |
Michal Nazarewicz | f8dae53 | 2010-06-25 16:29:27 +0200 | [diff] [blame] | 455 | struct gfs_configuration *gc = |
| 456 | container_of(c, struct gfs_configuration, c); |
Andrzej Pietrasiewicz | 581791f | 2012-05-14 15:51:52 +0200 | [diff] [blame] | 457 | int i; |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 458 | int ret; |
| 459 | |
Andrzej Pietrasiewicz | 581791f | 2012-05-14 15:51:52 +0200 | [diff] [blame] | 460 | if (missing_funcs) |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 461 | return -ENODEV; |
| 462 | |
| 463 | if (gadget_is_otg(c->cdev->gadget)) { |
| 464 | c->descriptors = gfs_otg_desc; |
| 465 | c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; |
| 466 | } |
| 467 | |
Michal Nazarewicz | f8dae53 | 2010-06-25 16:29:27 +0200 | [diff] [blame] | 468 | if (gc->eth) { |
Andrzej Pietrasiewicz | 6e257b1 | 2013-12-03 15:15:27 +0100 | [diff] [blame] | 469 | ret = gc->eth(c); |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 470 | if (unlikely(ret < 0)) |
| 471 | return ret; |
| 472 | } |
| 473 | |
Andrzej Pietrasiewicz | 581791f | 2012-05-14 15:51:52 +0200 | [diff] [blame] | 474 | for (i = 0; i < func_num; i++) { |
Andrzej Pietrasiewicz | 4b187fc | 2013-12-03 15:15:32 +0100 | [diff] [blame^] | 475 | ret = functionfs_bind_config(c->cdev, c, ffs_tab[i]->ffs_data); |
Andrzej Pietrasiewicz | 581791f | 2012-05-14 15:51:52 +0200 | [diff] [blame] | 476 | if (unlikely(ret < 0)) |
| 477 | return ret; |
| 478 | } |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 479 | |
Michal Nazarewicz | fc19de6 | 2010-08-12 17:43:48 +0200 | [diff] [blame] | 480 | /* |
| 481 | * After previous do_configs there may be some invalid |
Michal Nazarewicz | f588c0d | 2010-06-14 10:43:34 +0200 | [diff] [blame] | 482 | * pointers in c->interface array. This happens every time |
| 483 | * a user space function with fewer interfaces than a user |
| 484 | * space function that was run before the new one is run. The |
| 485 | * compasit's set_config() assumes that if there is no more |
| 486 | * then MAX_CONFIG_INTERFACES interfaces in a configuration |
| 487 | * then there is a NULL pointer after the last interface in |
Michal Nazarewicz | fc19de6 | 2010-08-12 17:43:48 +0200 | [diff] [blame] | 488 | * c->interface array. We need to make sure this is true. |
| 489 | */ |
Michal Nazarewicz | f588c0d | 2010-06-14 10:43:34 +0200 | [diff] [blame] | 490 | if (c->next_interface_id < ARRAY_SIZE(c->interface)) |
| 491 | c->interface[c->next_interface_id] = NULL; |
| 492 | |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 493 | return 0; |
| 494 | } |
| 495 | |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 496 | #ifdef CONFIG_USB_FUNCTIONFS_ETH |
Michal Nazarewicz | fc19de6 | 2010-08-12 17:43:48 +0200 | [diff] [blame] | 497 | |
Andrzej Pietrasiewicz | 6e257b1 | 2013-12-03 15:15:27 +0100 | [diff] [blame] | 498 | static int eth_bind_config(struct usb_configuration *c) |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 499 | { |
Andrzej Pietrasiewicz | f212ad4 | 2013-12-03 15:15:23 +0100 | [diff] [blame] | 500 | int status = 0; |
| 501 | |
| 502 | if (can_support_ecm(c->cdev->gadget)) { |
| 503 | f_ecm = usb_get_function(fi_ecm); |
| 504 | if (IS_ERR(f_ecm)) |
| 505 | return PTR_ERR(f_ecm); |
| 506 | |
| 507 | status = usb_add_function(c, f_ecm); |
| 508 | if (status < 0) |
| 509 | usb_put_function(f_ecm); |
| 510 | |
| 511 | } else { |
Andrzej Pietrasiewicz | 85aec59 | 2013-12-03 15:15:25 +0100 | [diff] [blame] | 512 | f_geth = usb_get_function(fi_geth); |
| 513 | if (IS_ERR(f_geth)) |
| 514 | return PTR_ERR(f_geth); |
| 515 | |
| 516 | status = usb_add_function(c, f_geth); |
| 517 | if (status < 0) |
| 518 | usb_put_function(f_geth); |
Andrzej Pietrasiewicz | f212ad4 | 2013-12-03 15:15:23 +0100 | [diff] [blame] | 519 | } |
| 520 | return status; |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 521 | } |
Michal Nazarewicz | fc19de6 | 2010-08-12 17:43:48 +0200 | [diff] [blame] | 522 | |
Michal Nazarewicz | c6c5600 | 2010-05-05 12:53:15 +0200 | [diff] [blame] | 523 | #endif |
Andrzej Pietrasiewicz | 6e257b1 | 2013-12-03 15:15:27 +0100 | [diff] [blame] | 524 | |
| 525 | #ifdef CONFIG_USB_FUNCTIONFS_RNDIS |
| 526 | |
| 527 | static int bind_rndis_config(struct usb_configuration *c) |
| 528 | { |
| 529 | int status = 0; |
| 530 | |
| 531 | f_rndis = usb_get_function(fi_rndis); |
| 532 | if (IS_ERR(f_rndis)) |
| 533 | return PTR_ERR(f_rndis); |
| 534 | |
| 535 | status = usb_add_function(c, f_rndis); |
| 536 | if (status < 0) |
| 537 | usb_put_function(f_rndis); |
| 538 | |
| 539 | return status; |
| 540 | } |
| 541 | |
| 542 | #endif |