summaryrefslogtreecommitdiff
path: root/patches.tizen/0640-usb-gadget-ether-convert-to-new-interface-of-f_rndis.patch
blob: df0e2a725d5e0d15ac5a8e23390c317f545520ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
From dbc5c92ab2a38ed442f55e0644c91fbe1ceee26f Mon Sep 17 00:00:00 2001
From: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
Date: Tue, 28 May 2013 09:15:58 +0200
Subject: [PATCH 0640/1302] usb: gadget: ether: convert to new interface of
 f_rndis

use new interface so old one can be removed.

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>
Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
---
 drivers/usb/gadget/Kconfig |  1 +
 drivers/usb/gadget/ether.c | 56 +++++++++++++++++++++++++++-------------------
 2 files changed, 34 insertions(+), 23 deletions(-)

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index d9535f4..b5941bf 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -702,6 +702,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..f48712f 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -94,23 +94,14 @@ 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"
+#else
+#define rndis_borrow_net(...) do {} while (0)
 #endif
-
 #include "u_eem.h"
 
 /*-------------------------------------------------------------------------*/
@@ -212,9 +203,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 +212,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 +224,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 +233,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 +337,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 +351,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 +364,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 +385,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 +393,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 +412,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 +421,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 +434,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 +449,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.8.3.2