u_ether.c has been #include'd by all gadgets which implement
USB Ethernet functions. In order to add configfs support,
the f_ecm.c, f_eem.c, f_ncm.c, f_subset.c, f_rndis.c need to be
converted into modules and must not be #include'd. Consequently,
the u_ether.c needs to be a module too, in a manner similar
to u_serial.c. The resulting module should not take any parameters,
so they are pushed to the current users of it, that is ether.c,
g_ffs.c, multi.c, ncm.c, nokia.c.

Signed-off-by: Andrzej Pietrasiewicz <andrze...@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.p...@samsung.com>
---
 drivers/usb/gadget/Kconfig   |   10 ++++++++++
 drivers/usb/gadget/Makefile  |    2 ++
 drivers/usb/gadget/cdc2.c    |   18 ++++++++++++++++--
 drivers/usb/gadget/ether.c   |   18 ++++++++++++++++--
 drivers/usb/gadget/g_ffs.c   |   19 +++++++++++++++++--
 drivers/usb/gadget/multi.c   |   19 +++++++++++++++++--
 drivers/usb/gadget/ncm.c     |   18 ++++++++++++++++--
 drivers/usb/gadget/nokia.c   |   19 +++++++++++++++++--
 drivers/usb/gadget/u_ether.c |   38 ++++++++++++++++++--------------------
 drivers/usb/gadget/u_ether.h |   12 ++++++++----
 10 files changed, 137 insertions(+), 36 deletions(-)

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index a61d981..1b5b89b 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -506,6 +506,9 @@ config USB_F_SS_LB
 config USB_U_SERIAL
        tristate
 
+config USB_U_ETHER
+       tristate
+
 config USB_F_SERIAL
        tristate
 
@@ -602,6 +605,7 @@ config USB_ETH
        tristate "Ethernet Gadget (with CDC Ethernet support)"
        depends on NET
        select USB_LIBCOMPOSITE
+       select USB_U_ETHER
        select CRC32
        help
          This driver implements Ethernet style communication, in one of
@@ -674,6 +678,7 @@ config USB_G_NCM
        tristate "Network Control Model (NCM) support"
        depends on NET
        select USB_LIBCOMPOSITE
+       select USB_U_ETHER
        select CRC32
        help
          This driver implements USB CDC NCM subclass standard. NCM is
@@ -717,6 +722,7 @@ config USB_FUNCTIONFS
 config USB_FUNCTIONFS_ETH
        bool "Include configuration with CDC ECM (Ethernet)"
        depends on USB_FUNCTIONFS && NET
+       select USB_U_ETHER
        help
          Include a configuration with CDC ECM function (Ethernet) and the
          Function Filesystem.
@@ -724,6 +730,7 @@ config USB_FUNCTIONFS_ETH
 config USB_FUNCTIONFS_RNDIS
        bool "Include configuration with RNDIS (Ethernet)"
        depends on USB_FUNCTIONFS && NET
+       select USB_U_ETHER
        help
          Include a configuration with RNDIS function (Ethernet) and the 
Filesystem.
 
@@ -824,6 +831,7 @@ config USB_CDC_COMPOSITE
        depends on NET
        select USB_LIBCOMPOSITE
        select USB_U_SERIAL
+       select USB_U_ETHER
        select USB_F_ACM
        help
          This driver provides two functions in one configuration:
@@ -841,6 +849,7 @@ config USB_G_NOKIA
        depends on PHONET
        select USB_LIBCOMPOSITE
        select USB_U_SERIAL
+       select USB_U_ETHER
        select USB_F_ACM
        help
          The Nokia composite gadget provides support for acm, obex
@@ -868,6 +877,7 @@ config USB_G_MULTI
        select USB_G_MULTI_CDC if !USB_G_MULTI_RNDIS
        select USB_LIBCOMPOSITE
        select USB_U_SERIAL
+       select USB_U_ETHER
        select USB_F_ACM
        help
          The Multifunction Composite Gadget provides Ethernet (RNDIS
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index 6afd166..8ca4fc7 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -45,6 +45,7 @@ usb_f_serial-y                        := f_serial.o
 obj-$(CONFIG_USB_F_SERIAL)     += usb_f_serial.o
 usb_f_obex-y                   := f_obex.o
 obj-$(CONFIG_USB_F_OBEX)       += usb_f_obex.o
+obj-$(CONFIG_USB_U_ETHER)      += u_ether.o
 
 #
 # USB gadget drivers
@@ -85,3 +86,4 @@ obj-$(CONFIG_USB_G_WEBCAM)    += g_webcam.o
 obj-$(CONFIG_USB_G_NCM)                += g_ncm.o
 obj-$(CONFIG_USB_G_ACM_MS)     += g_acm_ms.o
 obj-$(CONFIG_USB_GADGET_TARGET)        += tcm_usb_gadget.o
+
diff --git a/drivers/usb/gadget/cdc2.c b/drivers/usb/gadget/cdc2.c
index c6ee6f1..8cf8c6d 100644
--- a/drivers/usb/gadget/cdc2.c
+++ b/drivers/usb/gadget/cdc2.c
@@ -35,6 +35,20 @@
 /*-------------------------------------------------------------------------*/
 USB_GADGET_COMPOSITE_OPTIONS();
 
+static unsigned qmult = QMULT_DEFAULT;
+module_param(qmult, uint, S_IRUGO|S_IWUSR);
+MODULE_PARM_DESC(qmult, "queue length multiplier at high/super speed");
+
+/* initial value, changed by "ifconfig usb0 hw ether xx:xx:xx:xx:xx:xx" */
+static char *dev_addr;
+module_param(dev_addr, charp, S_IRUGO);
+MODULE_PARM_DESC(dev_addr, "Device Ethernet Address");
+
+/* this address is invisible to ifconfig */
+static char *host_addr;
+module_param(host_addr, charp, S_IRUGO);
+MODULE_PARM_DESC(host_addr, "Host Ethernet Address");
+
 /*
  * Kbuild is not very cooperative with respect to linking separately
  * compiled library objects into one module.  So for now we won't use
@@ -43,7 +57,6 @@ USB_GADGET_COMPOSITE_OPTIONS();
  * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
  */
 #include "f_ecm.c"
-#include "u_ether.c"
 
 /*-------------------------------------------------------------------------*/
 
@@ -164,7 +177,8 @@ static int __init cdc_bind(struct usb_composite_dev *cdev)
        }
 
        /* set up network link layer */
-       the_dev = gether_setup(cdev->gadget, hostaddr);
+       the_dev = gether_setup(cdev->gadget, dev_addr, host_addr, hostaddr,
+                              qmult);
        if (IS_ERR(the_dev))
                return PTR_ERR(the_dev);
 
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index 56c8eca..5fd58c1 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -107,11 +107,24 @@ static inline bool has_rndis(void)
 #include "rndis.c"
 #endif
 #include "f_eem.c"
-#include "u_ether.c"
 
 /*-------------------------------------------------------------------------*/
 USB_GADGET_COMPOSITE_OPTIONS();
 
+static unsigned qmult = QMULT_DEFAULT;
+module_param(qmult, uint, S_IRUGO|S_IWUSR);
+MODULE_PARM_DESC(qmult, "queue length multiplier at high/super speed");
+
+/* initial value, changed by "ifconfig usb0 hw ether xx:xx:xx:xx:xx:xx" */
+static char *dev_addr;
+module_param(dev_addr, charp, S_IRUGO);
+MODULE_PARM_DESC(dev_addr, "Device Ethernet Address");
+
+/* this address is invisible to ifconfig */
+static char *host_addr;
+module_param(host_addr, charp, S_IRUGO);
+MODULE_PARM_DESC(host_addr, "Host Ethernet Address");
+
 /* DO NOT REUSE THESE IDs with a protocol-incompatible driver!!  Ever!!
  * Instead:  allocate your own, using normal USB-IF procedures.
  */
@@ -279,7 +292,8 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
        int                     status;
 
        /* set up network link layer */
-       the_dev = gether_setup(cdev->gadget, hostaddr);
+       the_dev = gether_setup(cdev->gadget, dev_addr, host_addr, hostaddr,
+                              qmult);
        if (IS_ERR(the_dev))
                return PTR_ERR(the_dev);
 
diff --git a/drivers/usb/gadget/g_ffs.c b/drivers/usb/gadget/g_ffs.c
index 787a78e..6e9c63b 100644
--- a/drivers/usb/gadget/g_ffs.c
+++ b/drivers/usb/gadget/g_ffs.c
@@ -34,7 +34,7 @@
 #    include "f_rndis.c"
 #    include "rndis.c"
 #  endif
-#  include "u_ether.c"
+#  include "u_ether.h"
 
 static u8 gfs_hostaddr[ETH_ALEN];
 static struct eth_dev *the_dev;
@@ -73,6 +73,20 @@ struct gfs_ffs_obj {
 
 USB_GADGET_COMPOSITE_OPTIONS();
 
+static unsigned qmult = QMULT_DEFAULT;
+module_param(qmult, uint, S_IRUGO|S_IWUSR);
+MODULE_PARM_DESC(qmult, "queue length multiplier at high/super speed");
+
+/* initial value, changed by "ifconfig usb0 hw ether xx:xx:xx:xx:xx:xx" */
+static char *dev_addr;
+module_param(dev_addr, charp, S_IRUGO);
+MODULE_PARM_DESC(dev_addr, "Device Ethernet Address");
+
+/* this address is invisible to ifconfig */
+static char *host_addr;
+module_param(host_addr, charp, S_IRUGO);
+MODULE_PARM_DESC(host_addr, "Host Ethernet Address");
+
 static struct usb_device_descriptor gfs_dev_desc = {
        .bLength                = sizeof gfs_dev_desc,
        .bDescriptorType        = USB_DT_DEVICE,
@@ -350,7 +364,8 @@ static int gfs_bind(struct usb_composite_dev *cdev)
        if (missing_funcs)
                return -ENODEV;
 #if defined CONFIG_USB_FUNCTIONFS_ETH || defined CONFIG_USB_FUNCTIONFS_RNDIS
-       the_dev = gether_setup(cdev->gadget, gfs_hostaddr);
+       the_dev = gether_setup(cdev->gadget, dev_addr, host_addr, gfs_hostaddr,
+                              qmult);
 #endif
        if (IS_ERR(the_dev)) {
                ret = PTR_ERR(the_dev);
diff --git a/drivers/usb/gadget/multi.c b/drivers/usb/gadget/multi.c
index a74ebef..5d9e3ab 100644
--- a/drivers/usb/gadget/multi.c
+++ b/drivers/usb/gadget/multi.c
@@ -49,10 +49,24 @@ MODULE_LICENSE("GPL");
 #  include "f_rndis.c"
 #  include "rndis.c"
 #endif
-#include "u_ether.c"
+#include "u_ether.h"
 
 USB_GADGET_COMPOSITE_OPTIONS();
 
+static unsigned qmult = QMULT_DEFAULT;
+module_param(qmult, uint, S_IRUGO|S_IWUSR);
+MODULE_PARM_DESC(qmult, "queue length multiplier at high/super speed");
+
+/* initial value, changed by "ifconfig usb0 hw ether xx:xx:xx:xx:xx:xx" */
+static char *dev_addr;
+module_param(dev_addr, charp, S_IRUGO);
+MODULE_PARM_DESC(dev_addr, "Device Ethernet Address");
+
+/* this address is invisible to ifconfig */
+static char *host_addr;
+module_param(host_addr, charp, S_IRUGO);
+MODULE_PARM_DESC(host_addr, "Host Ethernet Address");
+
 /***************************** Device Descriptor ****************************/
 
 #define MULTI_VENDOR_NUM       0x1d6b  /* Linux Foundation */
@@ -278,7 +292,8 @@ static int __ref multi_bind(struct usb_composite_dev *cdev)
        }
 
        /* set up network link layer */
-       the_dev = gether_setup(cdev->gadget, hostaddr);
+       the_dev = gether_setup(cdev->gadget, dev_addr, host_addr, hostaddr,
+                              qmult);
        if (IS_ERR(the_dev))
                return PTR_ERR(the_dev);
 
diff --git a/drivers/usb/gadget/ncm.c b/drivers/usb/gadget/ncm.c
index 3b02fd4..0fb8ed7 100644
--- a/drivers/usb/gadget/ncm.c
+++ b/drivers/usb/gadget/ncm.c
@@ -37,7 +37,6 @@
  * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
  */
 #include "f_ncm.c"
-#include "u_ether.c"
 
 /*-------------------------------------------------------------------------*/
 
@@ -54,6 +53,20 @@
 /*-------------------------------------------------------------------------*/
 USB_GADGET_COMPOSITE_OPTIONS();
 
+static unsigned qmult = QMULT_DEFAULT;
+module_param(qmult, uint, S_IRUGO|S_IWUSR);
+MODULE_PARM_DESC(qmult, "queue length multiplier at high/super speed");
+
+/* initial value, changed by "ifconfig usb0 hw ether xx:xx:xx:xx:xx:xx" */
+static char *dev_addr;
+module_param(dev_addr, charp, S_IRUGO);
+MODULE_PARM_DESC(dev_addr, "Device Ethernet Address");
+
+/* this address is invisible to ifconfig */
+static char *host_addr;
+module_param(host_addr, charp, S_IRUGO);
+MODULE_PARM_DESC(host_addr, "Host Ethernet Address");
+
 static struct usb_device_descriptor device_desc = {
        .bLength =              sizeof device_desc,
        .bDescriptorType =      USB_DT_DEVICE,
@@ -144,7 +157,8 @@ static int __init gncm_bind(struct usb_composite_dev *cdev)
        int                     status;
 
        /* set up network link layer */
-       the_dev = gether_setup(cdev->gadget, hostaddr);
+       the_dev = gether_setup(cdev->gadget, dev_addr, host_addr, hostaddr,
+                              qmult);
        if (IS_ERR(the_dev))
                return PTR_ERR(the_dev);
 
diff --git a/drivers/usb/gadget/nokia.c b/drivers/usb/gadget/nokia.c
index 3b344b4..f6501a8 100644
--- a/drivers/usb/gadget/nokia.c
+++ b/drivers/usb/gadget/nokia.c
@@ -41,11 +41,25 @@
 #include "f_ecm.c"
 #include "f_obex.c"
 #include "f_phonet.c"
-#include "u_ether.c"
+#include "u_ether.h"
 
 /*-------------------------------------------------------------------------*/
 USB_GADGET_COMPOSITE_OPTIONS();
 
+static unsigned qmult = QMULT_DEFAULT;
+module_param(qmult, uint, S_IRUGO|S_IWUSR);
+MODULE_PARM_DESC(qmult, "queue length multiplier at high/super speed");
+
+/* initial value, changed by "ifconfig usb0 hw ether xx:xx:xx:xx:xx:xx" */
+static char *dev_addr;
+module_param(dev_addr, charp, S_IRUGO);
+MODULE_PARM_DESC(dev_addr, "Device Ethernet Address");
+
+/* this address is invisible to ifconfig */
+static char *host_addr;
+module_param(host_addr, charp, S_IRUGO);
+MODULE_PARM_DESC(host_addr, "Host Ethernet Address");
+
 #define NOKIA_VENDOR_ID                        0x0421  /* Nokia */
 #define NOKIA_PRODUCT_ID               0x01c8  /* Nokia Gadget */
 
@@ -186,7 +200,8 @@ static int __init nokia_bind(struct usb_composite_dev *cdev)
                        goto err_ether;
        }
 
-       the_dev = gether_setup(cdev->gadget, hostaddr);
+       the_dev = gether_setup(cdev->gadget, dev_addr, host_addr, hostaddr,
+                              qmult);
        if (IS_ERR(the_dev)) {
                status = PTR_ERR(the_dev);
                goto err_ether;
diff --git a/drivers/usb/gadget/u_ether.c b/drivers/usb/gadget/u_ether.c
index 4b76124..5f9dacf 100644
--- a/drivers/usb/gadget/u_ether.c
+++ b/drivers/usb/gadget/u_ether.c
@@ -63,6 +63,8 @@ struct eth_dev {
 
        struct sk_buff_head     rx_frames;
 
+       unsigned                qmult;
+
        unsigned                header_len;
        struct sk_buff          *(*wrap)(struct gether *, struct sk_buff *skb);
        int                     (*unwrap)(struct gether *,
@@ -84,12 +86,8 @@ struct eth_dev {
 
 #define DEFAULT_QLEN   2       /* double buffering by default */
 
-static unsigned qmult = 5;
-module_param(qmult, uint, S_IRUGO|S_IWUSR);
-MODULE_PARM_DESC(qmult, "queue length multiplier at high/super speed");
-
 /* for dual-speed hardware, use deeper queues at high/super speed */
-static inline int qlen(struct usb_gadget *gadget)
+static inline int qlen(struct usb_gadget *gadget, unsigned qmult)
 {
        if (gadget_is_dualspeed(gadget) && (gadget->speed == USB_SPEED_HIGH ||
                                            gadget->speed == USB_SPEED_SUPER))
@@ -588,7 +586,7 @@ static netdev_tx_t eth_start_xmit(struct sk_buff *skb,
        if (gadget_is_dualspeed(dev->gadget))
                req->no_interrupt = (dev->gadget->speed == USB_SPEED_HIGH ||
                                     dev->gadget->speed == USB_SPEED_SUPER)
-                       ? ((atomic_read(&dev->tx_qlen) % qmult) != 0)
+                       ? ((atomic_read(&dev->tx_qlen) % dev->qmult) != 0)
                        : 0;
 
        retval = usb_ep_queue(in, req, GFP_ATOMIC);
@@ -697,16 +695,6 @@ static int eth_stop(struct net_device *net)
 
 /*-------------------------------------------------------------------------*/
 
-/* initial value, changed by "ifconfig usb0 hw ether xx:xx:xx:xx:xx:xx" */
-static char *dev_addr;
-module_param(dev_addr, charp, S_IRUGO);
-MODULE_PARM_DESC(dev_addr, "Device Ethernet Address");
-
-/* this address is invisible to ifconfig */
-static char *host_addr;
-module_param(host_addr, charp, S_IRUGO);
-MODULE_PARM_DESC(host_addr, "Host Ethernet Address");
-
 static int get_ether_addr(const char *str, u8 *dev_addr)
 {
        if (str) {
@@ -755,8 +743,9 @@ static struct device_type gadget_type = {
  *
  * Returns negative errno, or zero on success
  */
-struct eth_dev *gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN],
-               const char *netname)
+struct eth_dev *gether_setup_name(struct usb_gadget *g,
+               const char *dev_addr, const char *host_addr,
+               u8 ethaddr[ETH_ALEN], unsigned qmult, const char *netname)
 {
        struct eth_dev          *dev;
        struct net_device       *net;
@@ -777,6 +766,7 @@ struct eth_dev *gether_setup_name(struct usb_gadget *g, u8 
ethaddr[ETH_ALEN],
 
        /* network device setup */
        dev->net = net;
+       dev->qmult = qmult;
        snprintf(net->name, sizeof(net->name), "%s%%d", netname);
 
        if (get_ether_addr(dev_addr, net->dev_addr))
@@ -815,6 +805,7 @@ struct eth_dev *gether_setup_name(struct usb_gadget *g, u8 
ethaddr[ETH_ALEN],
 
        return dev;
 }
+EXPORT_SYMBOL(gether_setup_name);
 
 /**
  * gether_cleanup - remove Ethernet-over-USB device
@@ -831,6 +822,7 @@ void gether_cleanup(struct eth_dev *dev)
        flush_work(&dev->work);
        free_netdev(dev->net);
 }
+EXPORT_SYMBOL(gether_cleanup);
 
 /**
  * gether_connect - notify network layer that USB link is active
@@ -873,11 +865,12 @@ struct net_device *gether_connect(struct gether *link)
        }
 
        if (result == 0)
-               result = alloc_requests(dev, link, qlen(dev->gadget));
+               result = alloc_requests(dev, link, qlen(dev->gadget,
+                                       dev->qmult));
 
        if (result == 0) {
                dev->zlp = link->is_zlp_ok;
-               DBG(dev, "qlen %d\n", qlen(dev->gadget));
+               DBG(dev, "qlen %d\n", qlen(dev->gadget, dev->qmult));
 
                dev->header_len = link->header_len;
                dev->unwrap = link->unwrap;
@@ -910,6 +903,7 @@ fail0:
                return ERR_PTR(result);
        return dev->net;
 }
+EXPORT_SYMBOL(gether_connect);
 
 /**
  * gether_disconnect - notify network layer that USB link is inactive
@@ -980,3 +974,7 @@ void gether_disconnect(struct gether *link)
        dev->port_usb = NULL;
        spin_unlock(&dev->lock);
 }
+EXPORT_SYMBOL(gether_disconnect);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("David Brownell");
diff --git a/drivers/usb/gadget/u_ether.h b/drivers/usb/gadget/u_ether.h
index 0252233..465b859 100644
--- a/drivers/usb/gadget/u_ether.h
+++ b/drivers/usb/gadget/u_ether.h
@@ -21,6 +21,8 @@
 
 #include "gadget_chips.h"
 
+#define QMULT_DEFAULT 5
+
 struct eth_dev;
 
 /*
@@ -71,8 +73,9 @@ struct gether {
                        |USB_CDC_PACKET_TYPE_DIRECTED)
 
 /* variant of gether_setup that allows customizing network device name */
-struct eth_dev *gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN],
-               const char *netname);
+struct eth_dev *gether_setup_name(struct usb_gadget *g,
+               const char *dev_addr, const char *host_addr,
+               u8 ethaddr[ETH_ALEN], unsigned qmult, const char *netname);
 
 /* netdev setup/teardown as directed by the gadget driver */
 /* gether_setup - initialize one ethernet-over-usb link
@@ -88,9 +91,10 @@ struct eth_dev *gether_setup_name(struct usb_gadget *g, u8 
ethaddr[ETH_ALEN],
  * Returns negative errno, or zero on success
  */
 static inline struct eth_dev *gether_setup(struct usb_gadget *g,
-               u8 ethaddr[ETH_ALEN])
+               const char *dev_addr, const char *host_addr,
+               u8 ethaddr[ETH_ALEN], unsigned qmult)
 {
-       return gether_setup_name(g, ethaddr, "usb");
+       return gether_setup_name(g, dev_addr, host_addr, ethaddr, qmult, "usb");
 }
 
 void gether_cleanup(struct eth_dev *dev);
-- 
1.7.0.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to