usb: gadget: f_eem: remove compatibility layer
[deliverable/linux.git] / drivers / usb / gadget / f_eem.c
index f4e0bbef602a3ed05c2df67b06d55884dfaf2161..9d54d68628e5b8b0c9aaeaf42fbe15b0bcf417b5 100644 (file)
  */
 
 #include <linux/kernel.h>
+#include <linux/module.h>
 #include <linux/device.h>
 #include <linux/etherdevice.h>
 #include <linux/crc32.h>
 #include <linux/slab.h>
 
 #include "u_ether.h"
+#include "u_eem.h"
 
 #define EEM_HLEN 2
 
@@ -40,7 +42,7 @@ static inline struct f_eem *func_to_eem(struct usb_function *f)
 
 /* interface descriptor: */
 
-static struct usb_interface_descriptor eem_intf __initdata = {
+static struct usb_interface_descriptor eem_intf = {
        .bLength =              sizeof eem_intf,
        .bDescriptorType =      USB_DT_INTERFACE,
 
@@ -54,7 +56,7 @@ static struct usb_interface_descriptor eem_intf __initdata = {
 
 /* full speed support: */
 
-static struct usb_endpoint_descriptor eem_fs_in_desc __initdata = {
+static struct usb_endpoint_descriptor eem_fs_in_desc = {
        .bLength =              USB_DT_ENDPOINT_SIZE,
        .bDescriptorType =      USB_DT_ENDPOINT,
 
@@ -62,7 +64,7 @@ static struct usb_endpoint_descriptor eem_fs_in_desc __initdata = {
        .bmAttributes =         USB_ENDPOINT_XFER_BULK,
 };
 
-static struct usb_endpoint_descriptor eem_fs_out_desc __initdata = {
+static struct usb_endpoint_descriptor eem_fs_out_desc = {
        .bLength =              USB_DT_ENDPOINT_SIZE,
        .bDescriptorType =      USB_DT_ENDPOINT,
 
@@ -70,7 +72,7 @@ static struct usb_endpoint_descriptor eem_fs_out_desc __initdata = {
        .bmAttributes =         USB_ENDPOINT_XFER_BULK,
 };
 
-static struct usb_descriptor_header *eem_fs_function[] __initdata = {
+static struct usb_descriptor_header *eem_fs_function[] = {
        /* CDC EEM control descriptors */
        (struct usb_descriptor_header *) &eem_intf,
        (struct usb_descriptor_header *) &eem_fs_in_desc,
@@ -80,7 +82,7 @@ static struct usb_descriptor_header *eem_fs_function[] __initdata = {
 
 /* high speed support: */
 
-static struct usb_endpoint_descriptor eem_hs_in_desc __initdata = {
+static struct usb_endpoint_descriptor eem_hs_in_desc = {
        .bLength =              USB_DT_ENDPOINT_SIZE,
        .bDescriptorType =      USB_DT_ENDPOINT,
 
@@ -89,7 +91,7 @@ static struct usb_endpoint_descriptor eem_hs_in_desc __initdata = {
        .wMaxPacketSize =       cpu_to_le16(512),
 };
 
-static struct usb_endpoint_descriptor eem_hs_out_desc __initdata = {
+static struct usb_endpoint_descriptor eem_hs_out_desc = {
        .bLength =              USB_DT_ENDPOINT_SIZE,
        .bDescriptorType =      USB_DT_ENDPOINT,
 
@@ -98,7 +100,7 @@ static struct usb_endpoint_descriptor eem_hs_out_desc __initdata = {
        .wMaxPacketSize =       cpu_to_le16(512),
 };
 
-static struct usb_descriptor_header *eem_hs_function[] __initdata = {
+static struct usb_descriptor_header *eem_hs_function[] = {
        /* CDC EEM control descriptors */
        (struct usb_descriptor_header *) &eem_intf,
        (struct usb_descriptor_header *) &eem_hs_in_desc,
@@ -108,7 +110,7 @@ static struct usb_descriptor_header *eem_hs_function[] __initdata = {
 
 /* super speed support: */
 
-static struct usb_endpoint_descriptor eem_ss_in_desc __initdata = {
+static struct usb_endpoint_descriptor eem_ss_in_desc = {
        .bLength =              USB_DT_ENDPOINT_SIZE,
        .bDescriptorType =      USB_DT_ENDPOINT,
 
@@ -117,7 +119,7 @@ static struct usb_endpoint_descriptor eem_ss_in_desc __initdata = {
        .wMaxPacketSize =       cpu_to_le16(1024),
 };
 
-static struct usb_endpoint_descriptor eem_ss_out_desc __initdata = {
+static struct usb_endpoint_descriptor eem_ss_out_desc = {
        .bLength =              USB_DT_ENDPOINT_SIZE,
        .bDescriptorType =      USB_DT_ENDPOINT,
 
@@ -126,7 +128,7 @@ static struct usb_endpoint_descriptor eem_ss_out_desc __initdata = {
        .wMaxPacketSize =       cpu_to_le16(1024),
 };
 
-static struct usb_ss_ep_comp_descriptor eem_ss_bulk_comp_desc __initdata = {
+static struct usb_ss_ep_comp_descriptor eem_ss_bulk_comp_desc = {
        .bLength =              sizeof eem_ss_bulk_comp_desc,
        .bDescriptorType =      USB_DT_SS_ENDPOINT_COMP,
 
@@ -135,7 +137,7 @@ static struct usb_ss_ep_comp_descriptor eem_ss_bulk_comp_desc __initdata = {
        /* .bmAttributes =      0, */
 };
 
-static struct usb_descriptor_header *eem_ss_function[] __initdata = {
+static struct usb_descriptor_header *eem_ss_function[] = {
        /* CDC EEM control descriptors */
        (struct usb_descriptor_header *) &eem_intf,
        (struct usb_descriptor_header *) &eem_ss_in_desc,
@@ -242,14 +244,42 @@ static void eem_disable(struct usb_function *f)
 
 /* EEM function driver setup/binding */
 
-static int __init
-eem_bind(struct usb_configuration *c, struct usb_function *f)
+static int eem_bind(struct usb_configuration *c, struct usb_function *f)
 {
        struct usb_composite_dev *cdev = c->cdev;
        struct f_eem            *eem = func_to_eem(f);
        int                     status;
        struct usb_ep           *ep;
 
+       struct f_eem_opts       *eem_opts;
+
+       eem_opts = container_of(f->fi, struct f_eem_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 eem_opts->bound access
+        */
+       if (!eem_opts->bound) {
+               gether_set_gadget(eem_opts->net, cdev->gadget);
+               status = gether_register_netdev(eem_opts->net);
+               if (status)
+                       return status;
+               eem_opts->bound = true;
+       }
+
+       /* maybe allocate device-global string IDs */
+       if (eem_string_defs[0].id == 0) {
+
+               /* control interface label */
+               status = usb_string_id(c->cdev);
+               if (status < 0)
+                       return status;
+               eem_string_defs[0].id = status;
+               eem_intf.iInterface = status;
+       }
+
        /* allocate instance-specific interface IDs */
        status = usb_interface_id(c, f);
        if (status < 0)
@@ -307,17 +337,6 @@ fail:
        return status;
 }
 
-static void
-eem_unbind(struct usb_configuration *c, struct usb_function *f)
-{
-       struct f_eem    *eem = func_to_eem(f);
-
-       DBG(c->cdev, "eem unbind\n");
-
-       usb_free_all_descriptors(f);
-       kfree(eem);
-}
-
 static void eem_cmd_complete(struct usb_ep *ep, struct usb_request *req)
 {
        struct sk_buff *skb = (struct sk_buff *)req->context;
@@ -518,38 +537,61 @@ error:
        return status;
 }
 
-/**
- * eem_bind_config - add CDC Ethernet (EEM) network link to a configuration
- * @c: the configuration to support the network link
- * Context: single threaded during gadget setup
- *
- * Returns zero on success, else negative errno.
- *
- * Caller must have called @gether_setup().  Caller is also responsible
- * for calling @gether_cleanup() before module unload.
- */
-int __init eem_bind_config(struct usb_configuration *c, struct eth_dev *dev)
+static void eem_free_inst(struct usb_function_instance *f)
 {
-       struct f_eem    *eem;
-       int             status;
+       struct f_eem_opts *opts;
+
+       opts = container_of(f, struct f_eem_opts, func_inst);
+       if (opts->bound)
+               gether_cleanup(netdev_priv(opts->net));
+       else
+               free_netdev(opts->net);
+       kfree(opts);
+}
 
-       /* maybe allocate device-global string IDs */
-       if (eem_string_defs[0].id == 0) {
+static struct usb_function_instance *eem_alloc_inst(void)
+{
+       struct f_eem_opts *opts;
 
-               /* control interface label */
-               status = usb_string_id(c->cdev);
-               if (status < 0)
-                       return status;
-               eem_string_defs[0].id = status;
-               eem_intf.iInterface = status;
-       }
+       opts = kzalloc(sizeof(*opts), GFP_KERNEL);
+       if (!opts)
+               return ERR_PTR(-ENOMEM);
+       opts->func_inst.free_func_inst = eem_free_inst;
+       opts->net = gether_setup_default();
+       if (IS_ERR(opts->net))
+               return ERR_CAST(opts->net);
+
+       return &opts->func_inst;
+}
+
+static void eem_free(struct usb_function *f)
+{
+       struct f_eem *eem;
+
+       eem = func_to_eem(f);
+       kfree(eem);
+}
+
+static void eem_unbind(struct usb_configuration *c, struct usb_function *f)
+{
+       DBG(c->cdev, "eem unbind\n");
+
+       usb_free_all_descriptors(f);
+}
+
+struct usb_function *eem_alloc(struct usb_function_instance *fi)
+{
+       struct f_eem    *eem;
+       struct f_eem_opts *opts;
 
        /* allocate and initialize one new instance */
-       eem = kzalloc(sizeof *eem, GFP_KERNEL);
+       eem = kzalloc(sizeof(*eem), GFP_KERNEL);
        if (!eem)
-               return -ENOMEM;
+               return ERR_PTR(-ENOMEM);
 
-       eem->port.ioport = dev;
+       opts = container_of(fi, struct f_eem_opts, func_inst);
+
+       eem->port.ioport = netdev_priv(opts->net);
        eem->port.cdc_filter = DEFAULT_FILTER;
 
        eem->port.func.name = "cdc_eem";
@@ -560,13 +602,14 @@ int __init eem_bind_config(struct usb_configuration *c, struct eth_dev *dev)
        eem->port.func.set_alt = eem_set_alt;
        eem->port.func.setup = eem_setup;
        eem->port.func.disable = eem_disable;
+       eem->port.func.free_func = eem_free;
        eem->port.wrap = eem_wrap;
        eem->port.unwrap = eem_unwrap;
        eem->port.header_len = EEM_HLEN;
 
-       status = usb_add_function(c, &eem->port.func);
-       if (status)
-               kfree(eem);
-       return status;
+       return &eem->port.func;
 }
 
+DECLARE_USB_FUNCTION_INIT(eem, eem_alloc_inst, eem_alloc);
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("David Brownell");
This page took 0.029896 seconds and 5 git commands to generate.