Skip to content

Commit

Permalink
usb: gadget: u_ether: convert into module
Browse files Browse the repository at this point in the history
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 <andrzej.p@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
  • Loading branch information
Andrzej Pietrasiewicz authored and Felipe Balbi committed Jun 10, 2013
1 parent d68c277 commit f1a1823
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 52 deletions.
10 changes: 10 additions & 0 deletions drivers/usb/gadget/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,9 @@ config USB_F_SS_LB
config USB_U_SERIAL
tristate

config USB_U_ETHER
tristate

config USB_F_SERIAL
tristate

Expand Down Expand Up @@ -595,6 +598,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
Expand Down Expand Up @@ -667,6 +671,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
Expand Down Expand Up @@ -710,13 +715,15 @@ 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.

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.

Expand Down Expand Up @@ -817,6 +824,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:
Expand All @@ -834,6 +842,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
Expand Down Expand Up @@ -861,6 +870,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
Expand Down
1 change: 1 addition & 0 deletions drivers/usb/gadget/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions drivers/usb/gadget/cdc2.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
/*-------------------------------------------------------------------------*/
USB_GADGET_COMPOSITE_OPTIONS();

USB_ETHERNET_MODULE_PARAMETERS();

/*
* Kbuild is not very cooperative with respect to linking separately
* compiled library objects into one module. So for now we won't use
Expand All @@ -43,7 +45,6 @@ USB_GADGET_COMPOSITE_OPTIONS();
* a "gcc --combine ... part1.c part2.c part3.c ... " build would.
*/
#include "f_ecm.c"
#include "u_ether.c"

/*-------------------------------------------------------------------------*/

Expand Down Expand Up @@ -102,7 +103,7 @@ 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 *f_acm;
Expand All @@ -120,7 +121,7 @@ static int __init cdc_do_config(struct usb_configuration *c)
c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
}

status = ecm_bind_config(c, hostaddr, the_dev);
status = ecm_bind_config(c, host_mac, the_dev);
if (status < 0)
return status;

Expand Down Expand Up @@ -166,7 +167,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, host_mac,
qmult);
if (IS_ERR(the_dev))
return PTR_ERR(the_dev);

Expand Down
14 changes: 8 additions & 6 deletions drivers/usb/gadget/ether.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,12 @@ static inline bool has_rndis(void)
#include "rndis.c"
#endif
#include "f_eem.c"
#include "u_ether.c"

/*-------------------------------------------------------------------------*/
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.
*/
Expand Down Expand Up @@ -206,7 +207,7 @@ 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;
/*-------------------------------------------------------------------------*/

Expand All @@ -224,7 +225,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 = {
Expand Down Expand Up @@ -259,9 +260,9 @@ static int __init eth_do_config(struct usb_configuration *c)
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);
return ecm_bind_config(c, host_mac, the_dev);
else
return geth_bind_config(c, hostaddr, the_dev);
return geth_bind_config(c, host_mac, the_dev);
}

static struct usb_configuration eth_config_driver = {
Expand All @@ -279,7 +280,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, host_mac,
qmult);
if (IS_ERR(the_dev))
return PTR_ERR(the_dev);

Expand Down
13 changes: 8 additions & 5 deletions drivers/usb/gadget/g_ffs.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
# include "f_rndis.c"
# include "rndis.c"
# endif
# include "u_ether.c"
# include "u_ether.h"

static u8 gfs_hostaddr[ETH_ALEN];
static u8 gfs_host_mac[ETH_ALEN];
static struct eth_dev *the_dev;
# ifdef CONFIG_USB_FUNCTIONFS_ETH
static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
Expand All @@ -45,7 +45,7 @@ static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
#else
# define the_dev NULL
# define gether_cleanup(dev) do { } while (0)
# define gfs_hostaddr NULL
# define gfs_host_mac NULL
struct eth_dev;
#endif

Expand Down Expand Up @@ -73,6 +73,8 @@ struct gfs_ffs_obj {

USB_GADGET_COMPOSITE_OPTIONS();

USB_ETHERNET_MODULE_PARAMETERS();

static struct usb_device_descriptor gfs_dev_desc = {
.bLength = sizeof gfs_dev_desc,
.bDescriptorType = USB_DT_DEVICE,
Expand Down Expand Up @@ -350,7 +352,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_host_mac,
qmult);
#endif
if (IS_ERR(the_dev)) {
ret = PTR_ERR(the_dev);
Expand Down Expand Up @@ -446,7 +449,7 @@ static int gfs_do_config(struct usb_configuration *c)
}

if (gc->eth) {
ret = gc->eth(c, gfs_hostaddr, the_dev);
ret = gc->eth(c, gfs_host_mac, the_dev);
if (unlikely(ret < 0))
return ret;
}
Expand Down
13 changes: 8 additions & 5 deletions drivers/usb/gadget/multi.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ MODULE_LICENSE("GPL");
# include "f_rndis.c"
# include "rndis.c"
#endif
#include "u_ether.c"
#include "u_ether.h"

USB_GADGET_COMPOSITE_OPTIONS();

USB_ETHERNET_MODULE_PARAMETERS();

/***************************** Device Descriptor ****************************/

#define MULTI_VENDOR_NUM 0x1d6b /* Linux Foundation */
Expand Down Expand Up @@ -133,7 +135,7 @@ FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data);

static struct fsg_common fsg_common;

static u8 hostaddr[ETH_ALEN];
static u8 host_mac[ETH_ALEN];

static struct usb_function_instance *fi_acm;
static struct eth_dev *the_dev;
Expand All @@ -152,7 +154,7 @@ static __init int rndis_do_config(struct usb_configuration *c)
c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
}

ret = rndis_bind_config(c, hostaddr, the_dev);
ret = rndis_bind_config(c, host_mac, the_dev);
if (ret < 0)
return ret;

Expand Down Expand Up @@ -216,7 +218,7 @@ static __init int cdc_do_config(struct usb_configuration *c)
c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
}

ret = ecm_bind_config(c, hostaddr, the_dev);
ret = ecm_bind_config(c, host_mac, the_dev);
if (ret < 0)
return ret;

Expand Down Expand Up @@ -280,7 +282,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, host_mac,
qmult);
if (IS_ERR(the_dev))
return PTR_ERR(the_dev);

Expand Down
10 changes: 6 additions & 4 deletions drivers/usb/gadget/ncm.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
* a "gcc --combine ... part1.c part2.c part3.c ... " build would.
*/
#include "f_ncm.c"
#include "u_ether.c"

/*-------------------------------------------------------------------------*/

Expand All @@ -54,6 +53,8 @@
/*-------------------------------------------------------------------------*/
USB_GADGET_COMPOSITE_OPTIONS();

USB_ETHERNET_MODULE_PARAMETERS();

static struct usb_device_descriptor device_desc = {
.bLength = sizeof device_desc,
.bDescriptorType = USB_DT_DEVICE,
Expand Down Expand Up @@ -112,7 +113,7 @@ static struct usb_gadget_strings *dev_strings[] = {
};

struct eth_dev *the_dev;
static u8 hostaddr[ETH_ALEN];
static u8 host_mac[ETH_ALEN];

/*-------------------------------------------------------------------------*/

Expand All @@ -125,7 +126,7 @@ static int __init ncm_do_config(struct usb_configuration *c)
c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
}

return ncm_bind_config(c, hostaddr, the_dev);
return ncm_bind_config(c, host_mac, the_dev);
}

static struct usb_configuration ncm_config_driver = {
Expand All @@ -144,7 +145,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, host_mac,
qmult);
if (IS_ERR(the_dev))
return PTR_ERR(the_dev);

Expand Down
11 changes: 7 additions & 4 deletions drivers/usb/gadget/nokia.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@
#include "f_ecm.c"
#include "f_obex.c"
#include "f_phonet.c"
#include "u_ether.c"
#include "u_ether.h"

/*-------------------------------------------------------------------------*/
USB_GADGET_COMPOSITE_OPTIONS();

USB_ETHERNET_MODULE_PARAMETERS();

#define NOKIA_VENDOR_ID 0x0421 /* Nokia */
#define NOKIA_PRODUCT_ID 0x01c8 /* Nokia Gadget */

Expand Down Expand Up @@ -98,7 +100,7 @@ MODULE_LICENSE("GPL");
/*-------------------------------------------------------------------------*/
static struct usb_function *f_acm_cfg1;
static struct usb_function *f_acm_cfg2;
static u8 hostaddr[ETH_ALEN];
static u8 host_mac[ETH_ALEN];
static struct eth_dev *the_dev;

enum {
Expand Down Expand Up @@ -152,7 +154,7 @@ static int __init nokia_bind_config(struct usb_configuration *c)
if (status)
goto err_conf;

status = ecm_bind_config(c, hostaddr, the_dev);
status = ecm_bind_config(c, host_mac, the_dev);
if (status) {
pr_debug("could not bind ecm config %d\n", status);
goto err_ecm;
Expand Down Expand Up @@ -186,7 +188,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, host_mac,
qmult);
if (IS_ERR(the_dev)) {
status = PTR_ERR(the_dev);
goto err_ether;
Expand Down
Loading

0 comments on commit f1a1823

Please sign in to comment.