usb: gadget: ether: convert to new interface of f_subset
[deliverable/linux.git] / drivers / usb / gadget / ether.c
index 56c8ecae9bc3213781b762e697ad626c23063e59..9e96d5583e4cca900821d573a05be715f1c9d6ef 100644 (file)
@@ -14,6 +14,7 @@
 /* #define VERBOSE_DEBUG */
 
 #include <linux/kernel.h>
+#include <linux/netdevice.h>
 
 #if defined USB_ETH_RNDIS
 #  undef USB_ETH_RNDIS
@@ -91,6 +92,8 @@ static inline bool has_rndis(void)
 #endif
 }
 
+#include <linux/module.h>
+
 /*-------------------------------------------------------------------------*/
 
 /*
@@ -100,18 +103,20 @@ static inline bool has_rndis(void)
  * the runtime footprint, and giving us at least some parts of what
  * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
  */
-#include "f_ecm.c"
-#include "f_subset.c"
+#include "u_ecm.h"
+#include "u_gether.h"
 #ifdef USB_ETH_RNDIS
 #include "f_rndis.c"
-#include "rndis.c"
+#include "rndis.h"
 #endif
-#include "f_eem.c"
-#include "u_ether.c"
+
+#include "u_eem.h"
 
 /*-------------------------------------------------------------------------*/
 USB_GADGET_COMPOSITE_OPTIONS();
 
+USB_ETHERNET_MODULE_PARAMETERS();
+
 /* DO NOT REUSE THESE IDs with a protocol-incompatible driver!!  Ever!!
  * Instead:  allocate your own, using normal USB-IF procedures.
  */
@@ -206,8 +211,18 @@ static struct usb_gadget_strings *dev_strings[] = {
        NULL,
 };
 
-static u8 hostaddr[ETH_ALEN];
+static u8 host_mac[ETH_ALEN];
 static struct eth_dev *the_dev;
+
+static struct usb_function_instance *fi_ecm;
+static struct usb_function *f_ecm;
+
+static struct usb_function_instance *fi_eem;
+static struct usb_function *f_eem;
+
+static struct usb_function_instance *fi_geth;
+static struct usb_function *f_geth;
+
 /*-------------------------------------------------------------------------*/
 
 /*
@@ -224,7 +239,7 @@ static int __init rndis_do_config(struct usb_configuration *c)
                c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
        }
 
-       return rndis_bind_config(c, hostaddr, the_dev);
+       return rndis_bind_config(c, host_mac, the_dev);
 }
 
 static struct usb_configuration rndis_config_driver = {
@@ -249,6 +264,8 @@ MODULE_PARM_DESC(use_eem, "use CDC EEM mode");
  */
 static int __init eth_do_config(struct usb_configuration *c)
 {
+       int status = 0;
+
        /* FIXME alloc iConfiguration string, set it in c->strings */
 
        if (gadget_is_otg(c->cdev->gadget)) {
@@ -256,12 +273,38 @@ static int __init eth_do_config(struct usb_configuration *c)
                c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
        }
 
-       if (use_eem)
-               return eem_bind_config(c, the_dev);
-       else if (can_support_ecm(c->cdev->gadget))
-               return ecm_bind_config(c, hostaddr, the_dev);
-       else
-               return geth_bind_config(c, hostaddr, the_dev);
+       if (use_eem) {
+               f_eem = usb_get_function(fi_eem);
+               if (IS_ERR(f_eem))
+                       return PTR_ERR(f_eem);
+
+               status = usb_add_function(c, f_eem);
+               if (status < 0)
+                       usb_put_function(f_eem);
+
+               return status;
+       } else if (can_support_ecm(c->cdev->gadget)) {
+               f_ecm = usb_get_function(fi_ecm);
+               if (IS_ERR(f_ecm))
+                       return PTR_ERR(f_ecm);
+
+               status = usb_add_function(c, f_ecm);
+               if (status < 0)
+                       usb_put_function(f_ecm);
+
+               return status;
+       } else {
+               f_geth = usb_get_function(fi_geth);
+               if (IS_ERR(f_geth))
+                       return PTR_ERR(f_geth);
+
+               status = usb_add_function(c, f_geth);
+               if (status < 0)
+                       usb_put_function(f_geth);
+
+               return status;
+       }
+
 }
 
 static struct usb_configuration eth_config_driver = {
@@ -276,24 +319,53 @@ static struct usb_configuration eth_config_driver = {
 static int __init eth_bind(struct usb_composite_dev *cdev)
 {
        struct usb_gadget       *gadget = cdev->gadget;
+       struct f_eem_opts       *eem_opts = NULL;
+       struct f_ecm_opts       *ecm_opts = NULL;
+       struct f_gether_opts    *geth_opts = NULL;
+       struct net_device       *net;
        int                     status;
 
-       /* set up network link layer */
-       the_dev = gether_setup(cdev->gadget, hostaddr);
-       if (IS_ERR(the_dev))
-               return PTR_ERR(the_dev);
-
        /* set up main config label and device descriptor */
        if (use_eem) {
                /* EEM */
+               fi_eem = usb_get_function_instance("eem");
+               if (IS_ERR(fi_eem))
+                       return PTR_ERR(fi_eem);
+
+               eem_opts = container_of(fi_eem, struct f_eem_opts, func_inst);
+
+               net = eem_opts->net;
+               the_dev = netdev_priv(net);
+
                eth_config_driver.label = "CDC Ethernet (EEM)";
                device_desc.idVendor = cpu_to_le16(EEM_VENDOR_NUM);
                device_desc.idProduct = cpu_to_le16(EEM_PRODUCT_NUM);
-       } else if (can_support_ecm(cdev->gadget)) {
+       } else if (can_support_ecm(gadget)) {
                /* ECM */
+
+               fi_ecm = usb_get_function_instance("ecm");
+               if (IS_ERR(fi_ecm))
+                       return PTR_ERR(fi_ecm);
+
+               ecm_opts = container_of(fi_ecm, struct f_ecm_opts, func_inst);
+
+               net = ecm_opts->net;
+               the_dev = netdev_priv(net);
+
                eth_config_driver.label = "CDC Ethernet (ECM)";
        } else {
                /* CDC Subset */
+
+               fi_geth = usb_get_function_instance("geth");
+               if (IS_ERR(fi_geth))
+                       return PTR_ERR(fi_geth);
+
+               geth_opts = container_of(fi_geth, struct f_gether_opts,
+                                        func_inst);
+
+               net = geth_opts->net;
+               the_dev = netdev_priv(net);
+
                eth_config_driver.label = "CDC Subset/SAFE";
 
                device_desc.idVendor = cpu_to_le16(SIMPLE_VENDOR_NUM);
@@ -302,8 +374,27 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
                        device_desc.bDeviceClass = USB_CLASS_VENDOR_SPEC;
        }
 
+       gether_set_qmult(net, qmult);
+       if (!gether_set_host_addr(net, host_addr))
+               pr_info("using host ethernet address: %s", host_addr);
+       if (!gether_set_dev_addr(net, dev_addr))
+               pr_info("using self ethernet address: %s", dev_addr);
+
        if (has_rndis()) {
                /* RNDIS plus ECM-or-Subset */
+               gether_set_gadget(net, cdev->gadget);
+               status = gether_register_netdev(net);
+               if (status)
+                       goto fail;
+               gether_get_host_addr_u8(net, host_mac);
+
+               if (use_eem)
+                       eem_opts->bound = true;
+               else if (can_support_ecm(gadget))
+                       ecm_opts->bound = true;
+               else
+                       geth_opts->bound = true;
+
                device_desc.idVendor = cpu_to_le16(RNDIS_VENDOR_NUM);
                device_desc.idProduct = cpu_to_le16(RNDIS_PRODUCT_NUM);
                device_desc.bNumConfigurations = 2;
@@ -338,13 +429,23 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
        return 0;
 
 fail:
-       gether_cleanup(the_dev);
+       if (use_eem)
+               usb_put_function_instance(fi_eem);
+       else if (can_support_ecm(gadget))
+               usb_put_function_instance(fi_ecm);
+       else
+               usb_put_function_instance(fi_geth);
        return status;
 }
 
 static int __exit eth_unbind(struct usb_composite_dev *cdev)
 {
-       gether_cleanup(the_dev);
+       if (use_eem)
+               usb_put_function_instance(fi_eem);
+       else if (can_support_ecm(cdev->gadget))
+               usb_put_function_instance(fi_ecm);
+       else
+               usb_put_function_instance(fi_geth);
        return 0;
 }
 
This page took 0.036586 seconds and 5 git commands to generate.