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