Commit d6a01439 authored by Sebastian Andrzej Siewior's avatar Sebastian Andrzej Siewior Committed by Felipe Balbi

usb: gadget: move the global the_dev variable to their users

the u_ether.c file has a global variable named the_dev which keeps a
pointer to the network device after it has been created via
gether_setup_name(). It is only used internally by u_ether. This patches
moves the variable to its users and passes it via the port.ioport where
it is saved later anyway.
Signed-off-by: default avatarSebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: default avatarFelipe Balbi <balbi@ti.com>
parent 15761826
...@@ -103,7 +103,7 @@ static struct usb_gadget_strings *dev_strings[] = { ...@@ -103,7 +103,7 @@ static struct usb_gadget_strings *dev_strings[] = {
}; };
static u8 hostaddr[ETH_ALEN]; static u8 hostaddr[ETH_ALEN];
static struct eth_dev *the_dev;
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
static struct usb_function *f_acm; static struct usb_function *f_acm;
static struct usb_function_instance *fi_serial; static struct usb_function_instance *fi_serial;
...@@ -122,7 +122,7 @@ static int __init cdc_do_config(struct usb_configuration *c) ...@@ -122,7 +122,7 @@ static int __init cdc_do_config(struct usb_configuration *c)
c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
} }
status = ecm_bind_config(c, hostaddr); status = ecm_bind_config(c, hostaddr, the_dev);
if (status < 0) if (status < 0)
return status; return status;
...@@ -169,9 +169,9 @@ static int __init cdc_bind(struct usb_composite_dev *cdev) ...@@ -169,9 +169,9 @@ static int __init cdc_bind(struct usb_composite_dev *cdev)
} }
/* set up network link layer */ /* set up network link layer */
status = gether_setup(cdev->gadget, hostaddr); the_dev = gether_setup(cdev->gadget, hostaddr);
if (status < 0) if (IS_ERR(the_dev))
return status; return PTR_ERR(the_dev);
/* set up serial link layer */ /* set up serial link layer */
status = gserial_alloc_line(&tty_line); status = gserial_alloc_line(&tty_line);
...@@ -202,7 +202,7 @@ static int __init cdc_bind(struct usb_composite_dev *cdev) ...@@ -202,7 +202,7 @@ static int __init cdc_bind(struct usb_composite_dev *cdev)
fail1: fail1:
gserial_free_line(tty_line); gserial_free_line(tty_line);
fail0: fail0:
gether_cleanup(); gether_cleanup(the_dev);
return status; return status;
} }
...@@ -211,7 +211,7 @@ static int __exit cdc_unbind(struct usb_composite_dev *cdev) ...@@ -211,7 +211,7 @@ static int __exit cdc_unbind(struct usb_composite_dev *cdev)
usb_put_function(f_acm); usb_put_function(f_acm);
usb_put_function_instance(fi_serial); usb_put_function_instance(fi_serial);
gserial_free_line(tty_line); gserial_free_line(tty_line);
gether_cleanup(); gether_cleanup(the_dev);
return 0; return 0;
} }
......
...@@ -207,7 +207,7 @@ static struct usb_gadget_strings *dev_strings[] = { ...@@ -207,7 +207,7 @@ static struct usb_gadget_strings *dev_strings[] = {
}; };
static u8 hostaddr[ETH_ALEN]; static u8 hostaddr[ETH_ALEN];
static struct eth_dev *the_dev;
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
/* /*
...@@ -224,7 +224,7 @@ static int __init rndis_do_config(struct usb_configuration *c) ...@@ -224,7 +224,7 @@ static int __init rndis_do_config(struct usb_configuration *c)
c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
} }
return rndis_bind_config(c, hostaddr); return rndis_bind_config(c, hostaddr, the_dev);
} }
static struct usb_configuration rndis_config_driver = { static struct usb_configuration rndis_config_driver = {
...@@ -257,11 +257,11 @@ static int __init eth_do_config(struct usb_configuration *c) ...@@ -257,11 +257,11 @@ static int __init eth_do_config(struct usb_configuration *c)
} }
if (use_eem) if (use_eem)
return eem_bind_config(c); return eem_bind_config(c, the_dev);
else if (can_support_ecm(c->cdev->gadget)) else if (can_support_ecm(c->cdev->gadget))
return ecm_bind_config(c, hostaddr); return ecm_bind_config(c, hostaddr, the_dev);
else else
return geth_bind_config(c, hostaddr); return geth_bind_config(c, hostaddr, the_dev);
} }
static struct usb_configuration eth_config_driver = { static struct usb_configuration eth_config_driver = {
...@@ -279,9 +279,9 @@ static int __init eth_bind(struct usb_composite_dev *cdev) ...@@ -279,9 +279,9 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
int status; int status;
/* set up network link layer */ /* set up network link layer */
status = gether_setup(cdev->gadget, hostaddr); the_dev = gether_setup(cdev->gadget, hostaddr);
if (status < 0) if (IS_ERR(the_dev))
return status; return PTR_ERR(the_dev);
/* set up main config label and device descriptor */ /* set up main config label and device descriptor */
if (use_eem) { if (use_eem) {
...@@ -338,13 +338,13 @@ static int __init eth_bind(struct usb_composite_dev *cdev) ...@@ -338,13 +338,13 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
return 0; return 0;
fail: fail:
gether_cleanup(); gether_cleanup(the_dev);
return status; return status;
} }
static int __exit eth_unbind(struct usb_composite_dev *cdev) static int __exit eth_unbind(struct usb_composite_dev *cdev)
{ {
gether_cleanup(); gether_cleanup(the_dev);
return 0; return 0;
} }
......
...@@ -824,7 +824,8 @@ ecm_unbind(struct usb_configuration *c, struct usb_function *f) ...@@ -824,7 +824,8 @@ ecm_unbind(struct usb_configuration *c, struct usb_function *f)
* for calling @gether_cleanup() before module unload. * for calling @gether_cleanup() before module unload.
*/ */
int int
ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]) ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
struct eth_dev *dev)
{ {
struct f_ecm *ecm; struct f_ecm *ecm;
int status; int status;
...@@ -852,6 +853,7 @@ ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]) ...@@ -852,6 +853,7 @@ ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN])
snprintf(ecm->ethaddr, sizeof ecm->ethaddr, "%pm", ethaddr); snprintf(ecm->ethaddr, sizeof ecm->ethaddr, "%pm", ethaddr);
ecm_string_defs[1].s = ecm->ethaddr; ecm_string_defs[1].s = ecm->ethaddr;
ecm->port.ioport = dev;
ecm->port.cdc_filter = DEFAULT_FILTER; ecm->port.cdc_filter = DEFAULT_FILTER;
ecm->port.func.name = "cdc_ethernet"; ecm->port.func.name = "cdc_ethernet";
......
...@@ -528,7 +528,7 @@ static int eem_unwrap(struct gether *port, ...@@ -528,7 +528,7 @@ static int eem_unwrap(struct gether *port,
* Caller must have called @gether_setup(). Caller is also responsible * Caller must have called @gether_setup(). Caller is also responsible
* for calling @gether_cleanup() before module unload. * for calling @gether_cleanup() before module unload.
*/ */
int __init eem_bind_config(struct usb_configuration *c) int __init eem_bind_config(struct usb_configuration *c, struct eth_dev *dev)
{ {
struct f_eem *eem; struct f_eem *eem;
int status; int status;
...@@ -549,6 +549,7 @@ int __init eem_bind_config(struct usb_configuration *c) ...@@ -549,6 +549,7 @@ int __init eem_bind_config(struct usb_configuration *c)
if (!eem) if (!eem)
return -ENOMEM; return -ENOMEM;
eem->port.ioport = dev;
eem->port.cdc_filter = DEFAULT_FILTER; eem->port.cdc_filter = DEFAULT_FILTER;
eem->port.func.name = "cdc_eem"; eem->port.func.name = "cdc_eem";
......
...@@ -1287,7 +1287,8 @@ ncm_unbind(struct usb_configuration *c, struct usb_function *f) ...@@ -1287,7 +1287,8 @@ ncm_unbind(struct usb_configuration *c, struct usb_function *f)
* Caller must have called @gether_setup(). Caller is also responsible * Caller must have called @gether_setup(). Caller is also responsible
* for calling @gether_cleanup() before module unload. * for calling @gether_cleanup() before module unload.
*/ */
int __init ncm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]) int __init ncm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
struct eth_dev *dev)
{ {
struct f_ncm *ncm; struct f_ncm *ncm;
int status; int status;
...@@ -1321,6 +1322,7 @@ int __init ncm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]) ...@@ -1321,6 +1322,7 @@ int __init ncm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN])
spin_lock_init(&ncm->lock); spin_lock_init(&ncm->lock);
ncm_reset_values(ncm); ncm_reset_values(ncm);
ncm->port.ioport = dev;
ncm->port.is_fixed = true; ncm->port.is_fixed = true;
ncm->port.func.name = "cdc_network"; ncm->port.func.name = "cdc_network";
......
...@@ -814,7 +814,7 @@ static inline bool can_support_rndis(struct usb_configuration *c) ...@@ -814,7 +814,7 @@ static inline bool can_support_rndis(struct usb_configuration *c)
int int
rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
u32 vendorID, const char *manufacturer) u32 vendorID, const char *manufacturer, struct eth_dev *dev)
{ {
struct f_rndis *rndis; struct f_rndis *rndis;
int status; int status;
...@@ -847,6 +847,7 @@ rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], ...@@ -847,6 +847,7 @@ rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
rndis->vendorID = vendorID; rndis->vendorID = vendorID;
rndis->manufacturer = manufacturer; rndis->manufacturer = manufacturer;
rndis->port.ioport = dev;
/* RNDIS activates when the host changes this filter */ /* RNDIS activates when the host changes this filter */
rndis->port.cdc_filter = 0; rndis->port.cdc_filter = 0;
......
...@@ -380,7 +380,8 @@ geth_unbind(struct usb_configuration *c, struct usb_function *f) ...@@ -380,7 +380,8 @@ geth_unbind(struct usb_configuration *c, struct usb_function *f)
* Caller must have called @gether_setup(). Caller is also responsible * Caller must have called @gether_setup(). Caller is also responsible
* for calling @gether_cleanup() before module unload. * for calling @gether_cleanup() before module unload.
*/ */
int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]) int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
struct eth_dev *dev)
{ {
struct f_gether *geth; struct f_gether *geth;
int status; int status;
...@@ -406,6 +407,7 @@ int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]) ...@@ -406,6 +407,7 @@ int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN])
snprintf(geth->ethaddr, sizeof geth->ethaddr, "%pm", ethaddr); snprintf(geth->ethaddr, sizeof geth->ethaddr, "%pm", ethaddr);
geth_string_defs[1].s = geth->ethaddr; geth_string_defs[1].s = geth->ethaddr;
geth->port.ioport = dev;
geth->port.cdc_filter = DEFAULT_FILTER; geth->port.cdc_filter = DEFAULT_FILTER;
geth->port.func.name = "cdc_subset"; geth->port.func.name = "cdc_subset";
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#define pr_fmt(fmt) "g_ffs: " fmt #define pr_fmt(fmt) "g_ffs: " fmt
#include <linux/module.h> #include <linux/module.h>
/* /*
* kbuild is not very cooperative with respect to linking separately * kbuild is not very cooperative with respect to linking separately
* compiled library objects into one module. So for now we won't use * compiled library objects into one module. So for now we won't use
...@@ -38,13 +37,16 @@ ...@@ -38,13 +37,16 @@
# include "u_ether.c" # include "u_ether.c"
static u8 gfs_hostaddr[ETH_ALEN]; static u8 gfs_hostaddr[ETH_ALEN];
static struct eth_dev *the_dev;
# ifdef CONFIG_USB_FUNCTIONFS_ETH # ifdef CONFIG_USB_FUNCTIONFS_ETH
static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]); static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
struct eth_dev *dev);
# endif # endif
#else #else
# define gether_cleanup() do { } while (0) # define the_dev NULL
# define gether_setup(gadget, hostaddr) ((int)0) # define gether_cleanup(dev) do { } while (0)
# define gfs_hostaddr NULL # define gfs_hostaddr NULL
struct eth_dev;
#endif #endif
#include "f_fs.c" #include "f_fs.c"
...@@ -137,7 +139,8 @@ static struct usb_gadget_strings *gfs_dev_strings[] = { ...@@ -137,7 +139,8 @@ static struct usb_gadget_strings *gfs_dev_strings[] = {
struct gfs_configuration { struct gfs_configuration {
struct usb_configuration c; struct usb_configuration c;
int (*eth)(struct usb_configuration *c, u8 *ethaddr); int (*eth)(struct usb_configuration *c, u8 *ethaddr,
struct eth_dev *dev);
} gfs_configurations[] = { } gfs_configurations[] = {
#ifdef CONFIG_USB_FUNCTIONFS_RNDIS #ifdef CONFIG_USB_FUNCTIONFS_RNDIS
{ {
...@@ -346,10 +349,13 @@ static int gfs_bind(struct usb_composite_dev *cdev) ...@@ -346,10 +349,13 @@ static int gfs_bind(struct usb_composite_dev *cdev)
if (missing_funcs) if (missing_funcs)
return -ENODEV; return -ENODEV;
#if defined CONFIG_USB_FUNCTIONFS_ETH || defined CONFIG_USB_FUNCTIONFS_RNDIS
ret = gether_setup(cdev->gadget, gfs_hostaddr); the_dev = gether_setup(cdev->gadget, gfs_hostaddr);
if (unlikely(ret < 0)) #endif
if (IS_ERR(the_dev)) {
ret = PTR_ERR(the_dev);
goto error_quick; goto error_quick;
}
gfs_ether_setup = true; gfs_ether_setup = true;
ret = usb_string_ids_tab(cdev, gfs_strings); ret = usb_string_ids_tab(cdev, gfs_strings);
...@@ -386,7 +392,7 @@ static int gfs_bind(struct usb_composite_dev *cdev) ...@@ -386,7 +392,7 @@ static int gfs_bind(struct usb_composite_dev *cdev)
for (i = 0; i < func_num; i++) for (i = 0; i < func_num; i++)
functionfs_unbind(ffs_tab[i].ffs_data); functionfs_unbind(ffs_tab[i].ffs_data);
error: error:
gether_cleanup(); gether_cleanup(the_dev);
error_quick: error_quick:
gfs_ether_setup = false; gfs_ether_setup = false;
return ret; return ret;
...@@ -410,7 +416,7 @@ static int gfs_unbind(struct usb_composite_dev *cdev) ...@@ -410,7 +416,7 @@ static int gfs_unbind(struct usb_composite_dev *cdev)
* do...? * do...?
*/ */
if (gfs_ether_setup) if (gfs_ether_setup)
gether_cleanup(); gether_cleanup(the_dev);
gfs_ether_setup = false; gfs_ether_setup = false;
for (i = func_num; --i; ) for (i = func_num; --i; )
...@@ -440,7 +446,7 @@ static int gfs_do_config(struct usb_configuration *c) ...@@ -440,7 +446,7 @@ static int gfs_do_config(struct usb_configuration *c)
} }
if (gc->eth) { if (gc->eth) {
ret = gc->eth(c, gfs_hostaddr); ret = gc->eth(c, gfs_hostaddr, the_dev);
if (unlikely(ret < 0)) if (unlikely(ret < 0))
return ret; return ret;
} }
...@@ -469,11 +475,12 @@ static int gfs_do_config(struct usb_configuration *c) ...@@ -469,11 +475,12 @@ static int gfs_do_config(struct usb_configuration *c)
#ifdef CONFIG_USB_FUNCTIONFS_ETH #ifdef CONFIG_USB_FUNCTIONFS_ETH
static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]) static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
struct eth_dev *dev)
{ {
return can_support_ecm(c->cdev->gadget) return can_support_ecm(c->cdev->gadget)
? ecm_bind_config(c, ethaddr) ? ecm_bind_config(c, ethaddr, dev)
: geth_bind_config(c, ethaddr); : geth_bind_config(c, ethaddr, dev);
} }
#endif #endif
...@@ -137,6 +137,7 @@ static u8 hostaddr[ETH_ALEN]; ...@@ -137,6 +137,7 @@ static u8 hostaddr[ETH_ALEN];
static unsigned char tty_line; static unsigned char tty_line;
static struct usb_function_instance *fi_acm; static struct usb_function_instance *fi_acm;
static struct eth_dev *the_dev;
/********** RNDIS **********/ /********** RNDIS **********/
...@@ -152,7 +153,7 @@ static __init int rndis_do_config(struct usb_configuration *c) ...@@ -152,7 +153,7 @@ static __init int rndis_do_config(struct usb_configuration *c)
c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
} }
ret = rndis_bind_config(c, hostaddr); ret = rndis_bind_config(c, hostaddr, the_dev);
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -214,7 +215,7 @@ static __init int cdc_do_config(struct usb_configuration *c) ...@@ -214,7 +215,7 @@ static __init int cdc_do_config(struct usb_configuration *c)
c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
} }
ret = ecm_bind_config(c, hostaddr); ret = ecm_bind_config(c, hostaddr, the_dev);
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -279,9 +280,9 @@ static int __ref multi_bind(struct usb_composite_dev *cdev) ...@@ -279,9 +280,9 @@ static int __ref multi_bind(struct usb_composite_dev *cdev)
} }
/* set up network link layer */ /* set up network link layer */
status = gether_setup(cdev->gadget, hostaddr); the_dev = gether_setup(cdev->gadget, hostaddr);
if (status < 0) if (IS_ERR(the_dev))
return status; return PTR_ERR(the_dev);
/* set up serial link layer */ /* set up serial link layer */
status = gserial_alloc_line(&tty_line); status = gserial_alloc_line(&tty_line);
...@@ -337,7 +338,7 @@ static int __ref multi_bind(struct usb_composite_dev *cdev) ...@@ -337,7 +338,7 @@ static int __ref multi_bind(struct usb_composite_dev *cdev)
fail0dot5: fail0dot5:
gserial_free_line(tty_line); gserial_free_line(tty_line);
fail0: fail0:
gether_cleanup(); gether_cleanup(the_dev);
return status; return status;
} }
...@@ -351,7 +352,7 @@ static int __exit multi_unbind(struct usb_composite_dev *cdev) ...@@ -351,7 +352,7 @@ static int __exit multi_unbind(struct usb_composite_dev *cdev)
#endif #endif
usb_put_function_instance(fi_acm); usb_put_function_instance(fi_acm);
gserial_free_line(tty_line); gserial_free_line(tty_line);
gether_cleanup(); gether_cleanup(the_dev);
return 0; return 0;
} }
......
...@@ -111,6 +111,7 @@ static struct usb_gadget_strings *dev_strings[] = { ...@@ -111,6 +111,7 @@ static struct usb_gadget_strings *dev_strings[] = {
NULL, NULL,
}; };
struct eth_dev *the_dev;
static u8 hostaddr[ETH_ALEN]; static u8 hostaddr[ETH_ALEN];
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
...@@ -124,7 +125,7 @@ static int __init ncm_do_config(struct usb_configuration *c) ...@@ -124,7 +125,7 @@ static int __init ncm_do_config(struct usb_configuration *c)
c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
} }
return ncm_bind_config(c, hostaddr); return ncm_bind_config(c, hostaddr, the_dev);
} }
static struct usb_configuration ncm_config_driver = { static struct usb_configuration ncm_config_driver = {
...@@ -143,9 +144,9 @@ static int __init gncm_bind(struct usb_composite_dev *cdev) ...@@ -143,9 +144,9 @@ static int __init gncm_bind(struct usb_composite_dev *cdev)
int status; int status;
/* set up network link layer */ /* set up network link layer */
status = gether_setup(cdev->gadget, hostaddr); the_dev = gether_setup(cdev->gadget, hostaddr);
if (status < 0) if (IS_ERR(the_dev))
return status; return PTR_ERR(the_dev);
/* Allocate string descriptor numbers ... note that string /* Allocate string descriptor numbers ... note that string
* contents can be overridden by the composite_dev glue. * contents can be overridden by the composite_dev glue.
...@@ -168,13 +169,13 @@ static int __init gncm_bind(struct usb_composite_dev *cdev) ...@@ -168,13 +169,13 @@ static int __init gncm_bind(struct usb_composite_dev *cdev)
return 0; return 0;
fail: fail:
gether_cleanup(); gether_cleanup(the_dev);
return status; return status;
} }
static int __exit gncm_unbind(struct usb_composite_dev *cdev) static int __exit gncm_unbind(struct usb_composite_dev *cdev)
{ {
gether_cleanup(); gether_cleanup(the_dev);
return 0; return 0;
} }
......
...@@ -99,6 +99,7 @@ MODULE_LICENSE("GPL"); ...@@ -99,6 +99,7 @@ MODULE_LICENSE("GPL");
static struct usb_function *f_acm_cfg1; static struct usb_function *f_acm_cfg1;
static struct usb_function *f_acm_cfg2; static struct usb_function *f_acm_cfg2;
static u8 hostaddr[ETH_ALEN]; static u8 hostaddr[ETH_ALEN];
static struct eth_dev *the_dev;
enum { enum {
TTY_PORT_OBEX0, TTY_PORT_OBEX0,
...@@ -152,7 +153,7 @@ static int __init nokia_bind_config(struct usb_configuration *c) ...@@ -152,7 +153,7 @@ static int __init nokia_bind_config(struct usb_configuration *c)
if (status) if (status)
goto err_conf; goto err_conf;
status = ecm_bind_config(c, hostaddr); status = ecm_bind_config(c, hostaddr, the_dev);
if (status) { if (status) {
pr_debug("could not bind ecm config %d\n", status); pr_debug("could not bind ecm config %d\n", status);
goto err_ecm; goto err_ecm;
...@@ -187,9 +188,11 @@ static int __init nokia_bind(struct usb_composite_dev *cdev) ...@@ -187,9 +188,11 @@ static int __init nokia_bind(struct usb_composite_dev *cdev)
goto err_ether; goto err_ether;
} }
status = gether_setup(cdev->gadget, hostaddr); the_dev = gether_setup(cdev->gadget, hostaddr);
if (status < 0) if (IS_ERR(the_dev)) {
status = PTR_ERR(the_dev);
goto err_ether; goto err_ether;
}
status = usb_string_ids_tab(cdev, strings_dev); status = usb_string_ids_tab(cdev, strings_dev);
if (status < 0) if (status < 0)
...@@ -230,7 +233,7 @@ static int __init nokia_bind(struct usb_composite_dev *cdev) ...@@ -230,7 +233,7 @@ static int __init nokia_bind(struct usb_composite_dev *cdev)
err_acm_inst: err_acm_inst:
usb_put_function_instance(fi_acm); usb_put_function_instance(fi_acm);
err_usb: err_usb:
gether_cleanup(); gether_cleanup(the_dev);
err_ether: err_ether:
cur_line--; cur_line--;
while (cur_line >= 0) while (cur_line >= 0)
...@@ -253,7 +256,7 @@ static int __exit nokia_unbind(struct usb_composite_dev *cdev) ...@@ -253,7 +256,7 @@ static int __exit nokia_unbind(struct usb_composite_dev *cdev)
for (i = 0; i < TTY_PORTS_MAX; i++) for (i = 0; i < TTY_PORTS_MAX; i++)
gserial_free_line(tty_lines[i]); gserial_free_line(tty_lines[i]);
gether_cleanup(); gether_cleanup(the_dev);
return 0; return 0;
} }
......
...@@ -50,7 +50,6 @@ ...@@ -50,7 +50,6 @@
struct eth_dev { struct eth_dev {
/* lock is held while accessing port_usb /* lock is held while accessing port_usb
* or updating its backlink port_usb->ioport
*/ */
spinlock_t lock; spinlock_t lock;
struct gether *port_usb; struct gether *port_usb;
...@@ -729,8 +728,6 @@ static int get_ether_addr(const char *str, u8 *dev_addr) ...@@ -729,8 +728,6 @@ static int get_ether_addr(const char *str, u8 *dev_addr)
return 1; return 1;
} }
static struct eth_dev *the_dev;
static const struct net_device_ops eth_netdev_ops = { static const struct net_device_ops eth_netdev_ops = {
.ndo_open = eth_open, .ndo_open = eth_open,
.ndo_stop = eth_stop, .ndo_stop = eth_stop,
...@@ -758,19 +755,16 @@ static struct device_type gadget_type = { ...@@ -758,19 +755,16 @@ static struct device_type gadget_type = {
* *
* Returns negative errno, or zero on success * Returns negative errno, or zero on success
*/ */
int gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN], struct eth_dev *gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN],
const char *netname) const char *netname)
{ {
struct eth_dev *dev; struct eth_dev *dev;
struct net_device *net; struct net_device *net;
int status; int status;
if (the_dev)
return -EBUSY;
net = alloc_etherdev(sizeof *dev); net = alloc_etherdev(sizeof *dev);
if (!net) if (!net)
return -ENOMEM; return ERR_PTR(-ENOMEM);
dev = netdev_priv(net); dev = netdev_priv(net);
spin_lock_init(&dev->lock); spin_lock_init(&dev->lock);
...@@ -807,12 +801,11 @@ int gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN], ...@@ -807,12 +801,11 @@ int gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN],
if (status < 0) { if (status < 0) {
dev_dbg(&g->dev, "register_netdev failed, %d\n", status); dev_dbg(&g->dev, "register_netdev failed, %d\n", status);
free_netdev(net); free_netdev(net);
dev = ERR_PTR(status);
} else { } else {
INFO(dev, "MAC %pM\n", net->dev_addr); INFO(dev, "MAC %pM\n", net->dev_addr);
INFO(dev, "HOST MAC %pM\n", dev->host_mac); INFO(dev, "HOST MAC %pM\n", dev->host_mac);
the_dev = dev;
/* two kinds of host-initiated state changes: /* two kinds of host-initiated state changes:
* - iff DATA transfer is active, carrier is "on" * - iff DATA transfer is active, carrier is "on"
* - tx queueing enabled if open *and* carrier is "on" * - tx queueing enabled if open *and* carrier is "on"
...@@ -820,7 +813,7 @@ int gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN], ...@@ -820,7 +813,7 @@ int gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN],
netif_carrier_off(net); netif_carrier_off(net);
} }
return status; return dev;
} }
/** /**
...@@ -829,19 +822,16 @@ int gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN], ...@@ -829,19 +822,16 @@ int gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN],
* *
* This is called to free all resources allocated by @gether_setup(). * This is called to free all resources allocated by @gether_setup().
*/ */
void gether_cleanup(void) void gether_cleanup(struct eth_dev *dev)
{ {
if (!the_dev) if (!dev)
return; return;
unregister_netdev(the_dev->net); unregister_netdev(dev->net);
flush_work(&the_dev->work); flush_work(&dev->work);
free_netdev(the_dev->net); free_netdev(dev->net);
the_dev = NULL;
} }
/** /**
* gether_connect - notify network layer that USB link is active * gether_connect - notify network layer that USB link is active
* @link: the USB link, set up with endpoints, descriptors matching * @link: the USB link, set up with endpoints, descriptors matching
...@@ -860,7 +850,7 @@ void gether_cleanup(void) ...@@ -860,7 +850,7 @@ void gether_cleanup(void)
*/ */
struct net_device *gether_connect(struct gether *link) struct net_device *gether_connect(struct gether *link)
{ {
struct eth_dev *dev = the_dev; struct eth_dev *dev = link->ioport;
int result = 0; int result = 0;
if (!dev) if (!dev)
...@@ -895,7 +885,6 @@ struct net_device *gether_connect(struct gether *link) ...@@ -895,7 +885,6 @@ struct net_device *gether_connect(struct gether *link)
spin_lock(&dev->lock); spin_lock(&dev->lock);
dev->port_usb = link; dev->port_usb = link;
link->ioport = dev;
if (netif_running(dev->net)) { if (netif_running(dev->net)) {
if (link->open) if (link->open)
link->open(link); link->open(link);
...@@ -989,6 +978,5 @@ void gether_disconnect(struct gether *link) ...@@ -989,6 +978,5 @@ void gether_disconnect(struct gether *link)
spin_lock(&dev->lock); spin_lock(&dev->lock);
dev->port_usb = NULL; dev->port_usb = NULL;
link->ioport = NULL;
spin_unlock(&dev->lock); spin_unlock(&dev->lock);
} }
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "gadget_chips.h" #include "gadget_chips.h"
struct eth_dev;
/* /*
* This represents the USB side of an "ethernet" link, managed by a USB * This represents the USB side of an "ethernet" link, managed by a USB
...@@ -70,7 +71,7 @@ struct gether { ...@@ -70,7 +71,7 @@ struct gether {
|USB_CDC_PACKET_TYPE_DIRECTED) |USB_CDC_PACKET_TYPE_DIRECTED)
/* variant of gether_setup that allows customizing network device name */ /* variant of gether_setup that allows customizing network device name */
int gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN], struct eth_dev *gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN],
const char *netname); const char *netname);
/* netdev setup/teardown as directed by the gadget driver */ /* netdev setup/teardown as directed by the gadget driver */
...@@ -86,12 +87,13 @@ int gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN], ...@@ -86,12 +87,13 @@ int gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN],
* *
* Returns negative errno, or zero on success * Returns negative errno, or zero on success
*/ */
static inline int gether_setup(struct usb_gadget *g, u8 ethaddr[ETH_ALEN]) static inline struct eth_dev *gether_setup(struct usb_gadget *g,
u8 ethaddr[ETH_ALEN])
{ {
return gether_setup_name(g, ethaddr, "usb"); return gether_setup_name(g, ethaddr, "usb");
} }
void gether_cleanup(void); void gether_cleanup(struct eth_dev *dev);
/* connect/disconnect is handled by individual functions */ /* connect/disconnect is handled by individual functions */
struct net_device *gether_connect(struct gether *); struct net_device *gether_connect(struct gether *);
...@@ -111,21 +113,24 @@ static inline bool can_support_ecm(struct usb_gadget *gadget) ...@@ -111,21 +113,24 @@ static inline bool can_support_ecm(struct usb_gadget *gadget)
} }
/* each configuration may bind one instance of an ethernet link */ /* each configuration may bind one instance of an ethernet link */
int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]); int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
int ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]); struct eth_dev *dev);
int ncm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]); int ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
int eem_bind_config(struct usb_configuration *c); struct eth_dev *dev);
int ncm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
struct eth_dev *dev);
int eem_bind_config(struct usb_configuration *c, struct eth_dev *dev);
#ifdef USB_ETH_RNDIS #ifdef USB_ETH_RNDIS
int rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], int rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
u32 vendorID, const char *manufacturer); u32 vendorID, const char *manufacturer, struct eth_dev *dev);
#else #else
static inline int static inline int
rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
u32 vendorID, const char *manufacturer) u32 vendorID, const char *manufacturer, struct eth_dev *dev)
{ {
return 0; return 0;
} }
...@@ -145,9 +150,9 @@ rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], ...@@ -145,9 +150,9 @@ rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
* for calling @gether_cleanup() before module unload. * for calling @gether_cleanup() before module unload.
*/ */
static inline int rndis_bind_config(struct usb_configuration *c, static inline int rndis_bind_config(struct usb_configuration *c,
u8 ethaddr[ETH_ALEN]) u8 ethaddr[ETH_ALEN], struct eth_dev *dev)
{ {
return rndis_bind_config_vendor(c, ethaddr, 0, NULL); return rndis_bind_config_vendor(c, ethaddr, 0, NULL, dev);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment