[PATCH 14/17] usb/gadget: ether: convert to new interface of f_rndis

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@xxxxxxxxxxx>
Signed-off-by: Kyungmin Park <kyungmin.park@xxxxxxxxxxx>
---
 drivers/usb/gadget/Kconfig |    1 +
 drivers/usb/gadget/ether.c |   54 +++++++++++++++++++++++++------------------
 2 files changed, 32 insertions(+), 23 deletions(-)

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index a4a6416..a33a307 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -812,6 +812,7 @@ config USB_ETH_RNDIS
 	bool "RNDIS support"
 	depends on USB_ETH
 	select USB_LIBCOMPOSITE
+	select USB_F_RNDIS
 	default y
 	help
 	   Microsoft Windows XP bundles the "Remote NDIS" (RNDIS) protocol,
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index 4d7290a..71fc52f 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -94,23 +94,12 @@ static inline bool has_rndis(void)
 
 #include <linux/module.h>
 
-/*-------------------------------------------------------------------------*/
-
-/*
- * Kbuild is not very cooperative with respect to linking separately
- * compiled library objects into one module.  So for now we won't use
- * separate compilation ... ensuring init/exit sections work to shrink
- * the runtime footprint, and giving us at least some parts of what
- * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
- */
 #include "u_ecm.h"
 #include "u_gether.h"
 #ifdef	USB_ETH_RNDIS
-#define USB_FRNDIS_INCLUDED
-#include "f_rndis.c"
+#include "u_rndis.h"
 #include "rndis.h"
 #endif
-
 #include "u_eem.h"
 
 /*-------------------------------------------------------------------------*/
@@ -212,9 +201,6 @@ static struct usb_gadget_strings *dev_strings[] = {
 	NULL,
 };
 
-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;
 
@@ -224,6 +210,9 @@ static struct usb_function *f_eem;
 static struct usb_function_instance *fi_geth;
 static struct usb_function *f_geth;
 
+static struct usb_function_instance *fi_rndis;
+static struct usb_function *f_rndis;
+
 /*-------------------------------------------------------------------------*/
 
 /*
@@ -233,6 +222,8 @@ static struct usb_function *f_geth;
  */
 static int __init rndis_do_config(struct usb_configuration *c)
 {
+	int status;
+
 	/* FIXME alloc iConfiguration string, set it in c->strings */
 
 	if (gadget_is_otg(c->cdev->gadget)) {
@@ -240,7 +231,15 @@ static int __init rndis_do_config(struct usb_configuration *c)
 		c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
 	}
 
-	return rndis_bind_config(c, host_mac, the_dev);
+	f_rndis = usb_get_function(fi_rndis);
+	if (IS_ERR(f_rndis))
+		return PTR_ERR(f_rndis);
+
+	status = usb_add_function(c, f_rndis);
+	if (status < 0)
+		usb_put_function(f_rndis);
+
+	return status;
 }
 
 static struct usb_configuration rndis_config_driver = {
@@ -336,7 +335,6 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
 		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);
@@ -351,7 +349,6 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
 		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 {
@@ -365,7 +362,6 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
 					 func_inst);
 
 		net = geth_opts->net;
-		the_dev = netdev_priv(net);
 
 		eth_config_driver.label = "CDC Subset/SAFE";
 
@@ -387,7 +383,6 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
 		status = gether_register_netdev(net);
 		if (status)
 			goto fail;
-		gether_get_host_addr_u8(net, host_mac);
 
 		if (use_eem)
 			eem_opts->bound = true;
@@ -396,6 +391,14 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
 		else
 			geth_opts->bound = true;
 
+		fi_rndis = usb_get_function_instance("rndis");
+		if (IS_ERR(fi_rndis)) {
+			status = PTR_ERR(fi_rndis);
+			goto fail;
+		}
+
+		rndis_borrow_net(fi_rndis, net);
+
 		device_desc.idVendor = cpu_to_le16(RNDIS_VENDOR_NUM);
 		device_desc.idProduct = cpu_to_le16(RNDIS_PRODUCT_NUM);
 		device_desc.bNumConfigurations = 2;
@@ -407,7 +410,7 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
 
 	status = usb_string_ids_tab(cdev, strings_dev);
 	if (status < 0)
-		goto fail;
+		goto fail1;
 	device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id;
 	device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
 
@@ -416,12 +419,12 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
 		status = usb_add_config(cdev, &rndis_config_driver,
 				rndis_do_config);
 		if (status < 0)
-			goto fail;
+			goto fail1;
 	}
 
 	status = usb_add_config(cdev, &eth_config_driver, eth_do_config);
 	if (status < 0)
-		goto fail;
+		goto fail1;
 
 	usb_composite_overwrite_options(cdev, &coverwrite);
 	dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n",
@@ -429,6 +432,9 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
 
 	return 0;
 
+fail1:
+	if (has_rndis())
+		usb_put_function_instance(fi_rndis);
 fail:
 	if (use_eem)
 		usb_put_function_instance(fi_eem);
@@ -441,6 +447,8 @@ fail:
 
 static int __exit eth_unbind(struct usb_composite_dev *cdev)
 {
+	if (has_rndis())
+		usb_put_function_instance(fi_rndis);
 	if (use_eem)
 		usb_put_function_instance(fi_eem);
 	else if (can_support_ecm(cdev->gadget))
-- 
1.7.0.4

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




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux