Skip to content

Commit 4d1a8f6

Browse files
Andrzej PietrasiewiczFelipe Balbi
authored andcommitted
usb: gadget: multi: convert to new interface of f_rndis
Convert the legacy multi gadget to the new interface of f_rndis, so that later the compatibility layer in f_rndis 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>
1 parent 7388901 commit 4d1a8f6

2 files changed

Lines changed: 52 additions & 24 deletions

File tree

‎drivers/usb/gadget/Kconfig‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,6 @@ config USB_G_MULTI
10361036
select USB_LIBCOMPOSITE
10371037
select USB_U_SERIAL
10381038
select USB_U_ETHER
1039-
select USB_U_RNDIS
10401039
select USB_F_ACM
10411040
select USB_U_MS
10421041
help
@@ -1057,6 +1056,8 @@ config USB_G_MULTI
10571056
config USB_G_MULTI_RNDIS
10581057
bool "RNDIS + CDC Serial + Storage configuration"
10591058
depends on USB_G_MULTI
1059+
select USB_U_RNDIS
1060+
select USB_F_RNDIS
10601061
default y
10611062
help
10621063
This option enables a configuration with RNDIS, CDC Serial and

‎drivers/usb/gadget/multi.c‎

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ MODULE_LICENSE("GPL");
4747

4848
#include "u_ecm.h"
4949
#ifdef USB_ETH_RNDIS
50-
# define USB_FRNDIS_INCLUDED
51-
# include "f_rndis.c"
50+
# include "u_rndis.h"
5251
# include "rndis.h"
5352
#endif
5453
#include "u_ether.h"
@@ -152,14 +151,13 @@ FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data);
152151
static struct fsg_common fsg_common;
153152

154153
static struct usb_function_instance *fi_acm;
155-
static struct eth_dev *the_dev;
156154

157155
/********** RNDIS **********/
158156

159157
#ifdef USB_ETH_RNDIS
160-
static u8 host_mac[ETH_ALEN];
161-
158+
static struct usb_function_instance *fi_rndis;
162159
static struct usb_function *f_acm_rndis;
160+
static struct usb_function *f_rndis;
163161

164162
static __init int rndis_do_config(struct usb_configuration *c)
165163
{
@@ -170,13 +168,19 @@ static __init int rndis_do_config(struct usb_configuration *c)
170168
c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
171169
}
172170

173-
ret = rndis_bind_config(c, host_mac, the_dev);
171+
f_rndis = usb_get_function(fi_rndis);
172+
if (IS_ERR(f_rndis))
173+
return PTR_ERR(f_rndis);
174+
175+
ret = usb_add_function(c, f_rndis);
174176
if (ret < 0)
175-
return ret;
177+
goto err_func_rndis;
176178

177179
f_acm_rndis = usb_get_function(fi_acm);
178-
if (IS_ERR(f_acm_rndis))
179-
return PTR_ERR(f_acm_rndis);
180+
if (IS_ERR(f_acm_rndis)) {
181+
ret = PTR_ERR(f_acm_rndis);
182+
goto err_func_acm;
183+
}
180184

181185
ret = usb_add_function(c, f_acm_rndis);
182186
if (ret)
@@ -191,6 +195,10 @@ static __init int rndis_do_config(struct usb_configuration *c)
191195
usb_remove_function(c, f_acm_rndis);
192196
err_conf:
193197
usb_put_function(f_acm_rndis);
198+
err_func_acm:
199+
usb_remove_function(c, f_rndis);
200+
err_func_rndis:
201+
usb_put_function(f_rndis);
194202
return ret;
195203
}
196204

@@ -299,12 +307,15 @@ static int __ref multi_bind(struct usb_composite_dev *cdev)
299307
struct usb_gadget *gadget = cdev->gadget;
300308
#ifdef CONFIG_USB_G_MULTI_CDC
301309
struct f_ecm_opts *ecm_opts;
310+
#endif
311+
#ifdef USB_ETH_RNDIS
312+
struct f_rndis_opts *rndis_opts;
302313
#endif
303314
int status;
304315

305316
if (!can_support_ecm(cdev->gadget)) {
306317
dev_err(&gadget->dev, "controller '%s' not usable\n",
307-
gadget->name);
318+
gadget->name);
308319
return -EINVAL;
309320
}
310321

@@ -320,26 +331,38 @@ static int __ref multi_bind(struct usb_composite_dev *cdev)
320331
pr_info("using host ethernet address: %s", host_addr);
321332
if (!gether_set_dev_addr(ecm_opts->net, dev_addr))
322333
pr_info("using self ethernet address: %s", dev_addr);
334+
#endif
323335

324-
the_dev = netdev_priv(ecm_opts->net);
336+
#ifdef USB_ETH_RNDIS
337+
fi_rndis = usb_get_function_instance("rndis");
338+
if (IS_ERR(fi_rndis)) {
339+
status = PTR_ERR(fi_rndis);
340+
goto fail;
341+
}
325342

326-
#elif defined USB_ETH_RNDIS
343+
rndis_opts = container_of(fi_rndis, struct f_rndis_opts, func_inst);
327344

328-
/* set up network link layer */
329-
the_dev = gether_setup(cdev->gadget, dev_addr, host_addr, host_mac,
330-
qmult);
331-
if (IS_ERR(the_dev))
332-
return PTR_ERR(the_dev);
345+
gether_set_qmult(rndis_opts->net, qmult);
346+
if (!gether_set_host_addr(rndis_opts->net, host_addr))
347+
pr_info("using host ethernet address: %s", host_addr);
348+
if (!gether_set_dev_addr(rndis_opts->net, dev_addr))
349+
pr_info("using self ethernet address: %s", dev_addr);
333350
#endif
334351

335352
#if (defined CONFIG_USB_G_MULTI_CDC && defined USB_ETH_RNDIS)
353+
/*
354+
* If both ecm and rndis are selected then:
355+
* 1) rndis borrows the net interface from ecm
356+
* 2) since the interface is shared it must not be bound
357+
* twice - in ecm's _and_ rndis' binds, so do it here.
358+
*/
336359
gether_set_gadget(ecm_opts->net, cdev->gadget);
337360
status = gether_register_netdev(ecm_opts->net);
338361
if (status)
339362
goto fail0;
340-
ecm_opts->bound = true;
341363

342-
gether_get_host_addr_u8(ecm_opts->net, host_mac);
364+
rndis_borrow_net(fi_rndis, ecm_opts->net);
365+
ecm_opts->bound = true;
343366
#endif
344367

345368
/* set up serial link layer */
@@ -388,10 +411,12 @@ static int __ref multi_bind(struct usb_composite_dev *cdev)
388411
fail1:
389412
usb_put_function_instance(fi_acm);
390413
fail0:
414+
#ifdef USB_ETH_RNDIS
415+
usb_put_function_instance(fi_rndis);
416+
fail:
417+
#endif
391418
#ifdef CONFIG_USB_G_MULTI_CDC
392419
usb_put_function_instance(fi_ecm);
393-
#else
394-
gether_cleanup(the_dev);
395420
#endif
396421
return status;
397422
}
@@ -405,11 +430,13 @@ static int __exit multi_unbind(struct usb_composite_dev *cdev)
405430
usb_put_function(f_acm_rndis);
406431
#endif
407432
usb_put_function_instance(fi_acm);
433+
#ifdef USB_ETH_RNDIS
434+
usb_put_function(f_rndis);
435+
usb_put_function_instance(fi_rndis);
436+
#endif
408437
#ifdef CONFIG_USB_G_MULTI_CDC
409438
usb_put_function(f_ecm);
410439
usb_put_function_instance(fi_ecm);
411-
#else
412-
gether_cleanup(the_dev);
413440
#endif
414441
return 0;
415442
}

0 commit comments

Comments
 (0)