summaryrefslogtreecommitdiffstats
path: root/drivers/usb/gadget/f_subset.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-07-02 11:31:09 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2013-07-02 11:31:09 -0700
commita84270189e2afc7028b1123415a66d444f460977 (patch)
tree0f239afe73655167c02b411d1cf84bf3211818af /drivers/usb/gadget/f_subset.c
parentbcd7351e83728859833e3c5b8aae9a2816914e4b (diff)
parent3a0ddc714a1b8fcbff24c135a1332a28b4668d78 (diff)
Merge tag 'usb-3.11-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb
Pull USB updates from Greg KH: "Here's the big USB 3.11-rc1 merge request. Lots of gadget and finally, chipidea driver updates (they were much needed), along with a new host controller driver, lots of little serial driver fixes, the removal of the 255 usb-serial device limitation, and a variety of other minor things. All of these have been in the linux-next releases for a while" * tag 'usb-3.11-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb: (254 commits) usb: musb: omap2430: make it compile again usb: chipidea: ci_hdrc_imx: access phy via private data xhci: Add missing unlocks on error paths USB: option,qcserial: move Novatel Gobi1K IDs to qcserial ehci-atmel.c: prepare clk before calling enable USB: ohci-at91: prepare clk before calling enable USB: HWA: fix device probe failure wusbcore: add entries in Documentation/ABI for new wusbhc sysfs attributes wusbcore: add sysfs attribute for retry count wusbcore: add sysfs attribute for DNTS count and interval usb: chipidea: drop "13xxx" infix usb: phy: tegra: remove duplicated include from phy-tegra-usb.c usb: host: xhci-plat: release mem region while removing module usbmisc_imx: allow autoloading on according to dt ids usb: fix build error without CONFIG_USB_PHY usb: check usb_hub_to_struct_hub() return value xhci: check for failed dma pool allocation usb: gadget: f_subset: fix missing unlock on error in geth_alloc() usb: gadget: f_ncm: fix missing unlock on error in ncm_alloc() usb: gadget: f_ecm: fix missing unlock on error in ecm_alloc() ...
Diffstat (limited to 'drivers/usb/gadget/f_subset.c')
-rw-r--r--drivers/usb/gadget/f_subset.c181
1 files changed, 165 insertions, 16 deletions
diff --git a/drivers/usb/gadget/f_subset.c b/drivers/usb/gadget/f_subset.c
index 7be04b34249..5601e1d96c4 100644
--- a/drivers/usb/gadget/f_subset.c
+++ b/drivers/usb/gadget/f_subset.c
@@ -12,11 +12,13 @@
#include <linux/slab.h>
#include <linux/kernel.h>
+#include <linux/module.h>
#include <linux/device.h>
#include <linux/etherdevice.h>
#include "u_ether.h"
-
+#include "u_ether_configfs.h"
+#include "u_gether.h"
/*
* This function packages a simple "CDC Subset" Ethernet port with no real
@@ -295,9 +297,40 @@ geth_bind(struct usb_configuration *c, struct usb_function *f)
{
struct usb_composite_dev *cdev = c->cdev;
struct f_gether *geth = func_to_geth(f);
+ struct usb_string *us;
int status;
struct usb_ep *ep;
+#ifndef USB_FSUBSET_INCLUDED
+ struct f_gether_opts *gether_opts;
+
+ gether_opts = container_of(f->fi, struct f_gether_opts, func_inst);
+
+ /*
+ * in drivers/usb/gadget/configfs.c:configfs_composite_bind()
+ * configurations are bound in sequence with list_for_each_entry,
+ * in each configuration its functions are bound in sequence
+ * with list_for_each_entry, so we assume no race condition
+ * with regard to gether_opts->bound access
+ */
+ if (!gether_opts->bound) {
+ mutex_lock(&gether_opts->lock);
+ gether_set_gadget(gether_opts->net, cdev->gadget);
+ status = gether_register_netdev(gether_opts->net);
+ mutex_unlock(&gether_opts->lock);
+ if (status)
+ return status;
+ gether_opts->bound = true;
+ }
+#endif
+ us = usb_gstrings_attach(cdev, geth_strings,
+ ARRAY_SIZE(geth_string_defs));
+ if (IS_ERR(us))
+ return PTR_ERR(us);
+
+ subset_data_intf.iInterface = us[0].id;
+ ether_desc.iMACAddress = us[1].id;
+
/* allocate instance-specific interface IDs */
status = usb_interface_id(c, f);
if (status < 0)
@@ -360,8 +393,10 @@ fail:
return status;
}
+#ifdef USB_FSUBSET_INCLUDED
+
static void
-geth_unbind(struct usb_configuration *c, struct usb_function *f)
+geth_old_unbind(struct usb_configuration *c, struct usb_function *f)
{
geth_string_defs[0].id = 0;
usb_free_all_descriptors(f);
@@ -387,18 +422,6 @@ int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
struct f_gether *geth;
int status;
- if (!ethaddr)
- return -EINVAL;
-
- /* maybe allocate device-global string IDs */
- if (geth_string_defs[0].id == 0) {
- status = usb_string_ids_tab(c->cdev, geth_string_defs);
- if (status < 0)
- return status;
- subset_data_intf.iInterface = geth_string_defs[0].id;
- ether_desc.iMACAddress = geth_string_defs[1].id;
- }
-
/* allocate and initialize one new instance */
geth = kzalloc(sizeof *geth, GFP_KERNEL);
if (!geth)
@@ -412,9 +435,8 @@ int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
geth->port.cdc_filter = DEFAULT_FILTER;
geth->port.func.name = "cdc_subset";
- geth->port.func.strings = geth_strings;
geth->port.func.bind = geth_bind;
- geth->port.func.unbind = geth_unbind;
+ geth->port.func.unbind = geth_old_unbind;
geth->port.func.set_alt = geth_set_alt;
geth->port.func.disable = geth_disable;
@@ -423,3 +445,130 @@ int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
kfree(geth);
return status;
}
+
+#else
+
+static inline struct f_gether_opts *to_f_gether_opts(struct config_item *item)
+{
+ return container_of(to_config_group(item), struct f_gether_opts,
+ func_inst.group);
+}
+
+/* f_gether_item_ops */
+USB_ETHERNET_CONFIGFS_ITEM(gether);
+
+/* f_gether_opts_dev_addr */
+USB_ETHERNET_CONFIGFS_ITEM_ATTR_DEV_ADDR(gether);
+
+/* f_gether_opts_host_addr */
+USB_ETHERNET_CONFIGFS_ITEM_ATTR_HOST_ADDR(gether);
+
+/* f_gether_opts_qmult */
+USB_ETHERNET_CONFIGFS_ITEM_ATTR_QMULT(gether);
+
+/* f_gether_opts_ifname */
+USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(gether);
+
+static struct configfs_attribute *gether_attrs[] = {
+ &f_gether_opts_dev_addr.attr,
+ &f_gether_opts_host_addr.attr,
+ &f_gether_opts_qmult.attr,
+ &f_gether_opts_ifname.attr,
+ NULL,
+};
+
+static struct config_item_type gether_func_type = {
+ .ct_item_ops = &gether_item_ops,
+ .ct_attrs = gether_attrs,
+ .ct_owner = THIS_MODULE,
+};
+
+static void geth_free_inst(struct usb_function_instance *f)
+{
+ struct f_gether_opts *opts;
+
+ opts = container_of(f, struct f_gether_opts, func_inst);
+ if (opts->bound)
+ gether_cleanup(netdev_priv(opts->net));
+ else
+ free_netdev(opts->net);
+ kfree(opts);
+}
+
+static struct usb_function_instance *geth_alloc_inst(void)
+{
+ struct f_gether_opts *opts;
+
+ opts = kzalloc(sizeof(*opts), GFP_KERNEL);
+ if (!opts)
+ return ERR_PTR(-ENOMEM);
+ mutex_init(&opts->lock);
+ opts->func_inst.free_func_inst = geth_free_inst;
+ opts->net = gether_setup_default();
+ if (IS_ERR(opts->net))
+ return ERR_CAST(opts->net);
+
+ config_group_init_type_name(&opts->func_inst.group, "",
+ &gether_func_type);
+
+ return &opts->func_inst;
+}
+
+static void geth_free(struct usb_function *f)
+{
+ struct f_gether *eth;
+
+ eth = func_to_geth(f);
+ kfree(eth);
+}
+
+static void geth_unbind(struct usb_configuration *c, struct usb_function *f)
+{
+ geth_string_defs[0].id = 0;
+ usb_free_all_descriptors(f);
+}
+
+static struct usb_function *geth_alloc(struct usb_function_instance *fi)
+{
+ struct f_gether *geth;
+ struct f_gether_opts *opts;
+ int status;
+
+ /* allocate and initialize one new instance */
+ geth = kzalloc(sizeof(*geth), GFP_KERNEL);
+ if (!geth)
+ return ERR_PTR(-ENOMEM);
+
+ opts = container_of(fi, struct f_gether_opts, func_inst);
+
+ mutex_lock(&opts->lock);
+ opts->refcnt++;
+ /* export host's Ethernet address in CDC format */
+ status = gether_get_host_addr_cdc(opts->net, geth->ethaddr,
+ sizeof(geth->ethaddr));
+ if (status < 12) {
+ kfree(geth);
+ mutex_unlock(&opts->lock);
+ return ERR_PTR(-EINVAL);
+ }
+ geth_string_defs[1].s = geth->ethaddr;
+
+ geth->port.ioport = netdev_priv(opts->net);
+ mutex_unlock(&opts->lock);
+ geth->port.cdc_filter = DEFAULT_FILTER;
+
+ geth->port.func.name = "cdc_subset";
+ geth->port.func.bind = geth_bind;
+ geth->port.func.unbind = geth_unbind;
+ geth->port.func.set_alt = geth_set_alt;
+ geth->port.func.disable = geth_disable;
+ geth->port.func.free_func = geth_free;
+
+ return &geth->port.func;
+}
+
+DECLARE_USB_FUNCTION_INIT(geth, geth_alloc_inst, geth_alloc);
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("David Brownell");
+
+#endif