[PATCH v4 21/46] usb/gadget: ether: convert to new interface of f_ecm

[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 |   43 +++++++++++++++++++++++++++++++++++++------
 2 files changed, 38 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 4d97a72..f4a7438 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -668,6 +668,7 @@ config USB_ETH
 	select USB_U_ETHER
 	select USB_U_RNDIS
 	select USB_F_EEM
+	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 550b1f3..52106e5 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -24,6 +24,7 @@
 
 #include "u_ether.h"
 #include "u_eem.h"
+#include "u_ecm.h"
 
 
 /*
@@ -103,8 +104,6 @@ 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 USB_FECM_INCLUDED
-#include "f_ecm.c"
 #include "f_subset.c"
 #ifdef	USB_ETH_RNDIS
 #include "f_rndis.c"
@@ -214,6 +213,9 @@ static struct eth_dev *the_dev;
 static struct usb_function_instance *f_eem_inst;
 static struct usb_function *f_eem;
 
+static struct usb_function_instance *f_ecm_inst;
+static struct usb_function *f_ecm;
+
 /*-------------------------------------------------------------------------*/
 
 /*
@@ -255,6 +257,7 @@ MODULE_PARM_DESC(use_eem, "use CDC EEM mode");
  */
 static int __init eth_do_config(struct usb_configuration *c)
 {
+	int status;
 	/* FIXME alloc iConfiguration string, set it in c->strings */
 
 	if (gadget_is_otg(c->cdev->gadget)) {
@@ -264,7 +267,6 @@ static int __init eth_do_config(struct usb_configuration *c)
 
 	if (use_eem) {
 		struct f_eem_opts *eem_opts;
-		int status;
 
 		f_eem_inst = usb_get_function_instance("eem");
 		if (IS_ERR(f_eem_inst))
@@ -290,9 +292,34 @@ static int __init eth_do_config(struct usb_configuration *c)
 
 		return 0;
 
-	} else if (can_support_ecm(c->cdev->gadget))
-		return ecm_bind_config(c, hostaddr, the_dev);
-	else
+	} else if (can_support_ecm(c->cdev->gadget)) {
+		struct f_ecm_opts *ecm_opts;
+
+		f_ecm_inst = usb_get_function_instance("ecm");
+		if (IS_ERR(f_ecm_inst))
+			return PTR_ERR(f_ecm_inst);
+
+		ecm_opts = container_of(f_ecm_inst, struct f_ecm_opts,
+					func_inst);
+		ecm_opts->ethaddr = hostaddr;
+		ecm_opts->dev = the_dev;
+
+		f_ecm = usb_get_function(f_ecm_inst);
+		if (IS_ERR(f_ecm)) {
+			status = PTR_ERR(f_ecm);
+			usb_put_function_instance(f_ecm_inst);
+			return status;
+		}
+
+		status = usb_add_function(c, f_ecm);
+		if (status < 0) {
+			usb_put_function(f_ecm);
+			usb_put_function_instance(f_ecm_inst);
+			return status;
+		}
+
+		return 0;
+	} else
 		return geth_bind_config(c, hostaddr, the_dev);
 }
 
@@ -381,6 +408,10 @@ static int __exit eth_unbind(struct usb_composite_dev *cdev)
 		usb_put_function(f_eem);
 	if (!IS_ERR_OR_NULL(f_eem_inst))
 		usb_put_function_instance(f_eem_inst);
+	if (!IS_ERR_OR_NULL(f_ecm))
+		usb_put_function(f_ecm);
+	if (!IS_ERR_OR_NULL(f_ecm_inst))
+		usb_put_function_instance(f_ecm_inst);
 	return 0;
 }
 
-- 
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