From: Andrzej Pietrasiewicz Date: Tue, 28 May 2013 07:15:46 +0000 (+0200) Subject: usb: gadget: ether: convert to new interface of f_ecm X-Git-Url: http://git.cdn.openwrt.org/?a=commitdiff_plain;h=9c62ce83e4258bacc459faf57bf2ed83cce6be08;p=openwrt%2Fstaging%2Fblogic.git usb: gadget: ether: convert to new interface of f_ecm moving to new interface so we can remove the older one. Signed-off-by: Andrzej Pietrasiewicz Signed-off-by: Kyungmin Park Signed-off-by: Felipe Balbi --- diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig index d6c4e601d711..a34d3da00b28 100644 --- a/drivers/usb/gadget/Kconfig +++ b/drivers/usb/gadget/Kconfig @@ -622,6 +622,7 @@ config USB_ETH select USB_LIBCOMPOSITE select USB_U_ETHER select USB_U_RNDIS + select USB_F_ECM select CRC32 help This driver implements Ethernet style communication, in one of diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c index 862ef656e8a1..f4d46d7cfe37 100644 --- a/drivers/usb/gadget/ether.c +++ b/drivers/usb/gadget/ether.c @@ -102,8 +102,7 @@ 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. */ -#define USBF_ECM_INCLUDED -#include "f_ecm.c" +#include "u_ecm.h" #include "f_subset.c" #ifdef USB_ETH_RNDIS #include "f_rndis.c" @@ -212,6 +211,10 @@ static struct usb_gadget_strings *dev_strings[] = { 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; + /*-------------------------------------------------------------------------*/ /* @@ -253,6 +256,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)) { @@ -262,10 +267,19 @@ 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, host_mac, the_dev); - else + 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 return geth_bind_config(c, host_mac, the_dev); + } static struct usb_configuration eth_config_driver = { @@ -280,13 +294,16 @@ 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_ecm_opts *ecm_opts = NULL; int status; - /* set up network link layer */ - the_dev = gether_setup(cdev->gadget, dev_addr, host_addr, host_mac, - qmult); - if (IS_ERR(the_dev)) - return PTR_ERR(the_dev); + if (use_eem || !can_support_ecm(gadget)) { + /* set up network link layer */ + the_dev = gether_setup(cdev->gadget, dev_addr, host_addr, + host_mac, qmult); + if (IS_ERR(the_dev)) + return PTR_ERR(the_dev); + } /* set up main config label and device descriptor */ if (use_eem) { @@ -294,8 +311,23 @@ static int __init eth_bind(struct usb_composite_dev *cdev) 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); + + gether_set_qmult(ecm_opts->net, qmult); + if (!gether_set_host_addr(ecm_opts->net, host_addr)) + pr_info("using host ethernet address: %s", host_addr); + if (!gether_set_dev_addr(ecm_opts->net, dev_addr)) + pr_info("using self ethernet address: %s", dev_addr); + + the_dev = netdev_priv(ecm_opts->net); + eth_config_driver.label = "CDC Ethernet (ECM)"; } else { /* CDC Subset */ @@ -309,6 +341,15 @@ static int __init eth_bind(struct usb_composite_dev *cdev) if (has_rndis()) { /* RNDIS plus ECM-or-Subset */ + if (!use_eem && can_support_ecm(gadget)) { + gether_set_gadget(ecm_opts->net, cdev->gadget); + status = gether_register_netdev(ecm_opts->net); + if (status) + goto fail; + ecm_opts->bound = true; + gether_get_host_addr_u8(ecm_opts->net, host_mac); + } + device_desc.idVendor = cpu_to_le16(RNDIS_VENDOR_NUM); device_desc.idProduct = cpu_to_le16(RNDIS_PRODUCT_NUM); device_desc.bNumConfigurations = 2; @@ -343,13 +384,19 @@ static int __init eth_bind(struct usb_composite_dev *cdev) return 0; fail: - gether_cleanup(the_dev); + if (use_eem || !can_support_ecm(gadget)) + gether_cleanup(the_dev); + else + usb_put_function_instance(fi_ecm); return status; } static int __exit eth_unbind(struct usb_composite_dev *cdev) { - gether_cleanup(the_dev); + if (use_eem || !can_support_ecm(cdev->gadget)) + gether_cleanup(the_dev); + else + usb_put_function_instance(fi_ecm); return 0; }