Skip to content

Commit 7388901

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

2 files changed

Lines changed: 61 additions & 8 deletions

File tree

‎drivers/usb/gadget/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,7 @@ config USB_G_MULTI_CDC
10701070
bool "CDC Ethernet + CDC Serial + Storage configuration"
10711071
depends on USB_G_MULTI
10721072
default n
1073+
select USB_F_ECM
10731074
help
10741075
This option enables a configuration with CDC Ethernet (ECM), CDC
10751076
Serial and Mass Storage functions available in the Multifunction

‎drivers/usb/gadget/multi.c‎

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include <linux/kernel.h>
1717
#include <linux/module.h>
18+
#include <linux/netdevice.h>
1819

1920
#include "u_serial.h"
2021
#if defined USB_ETH_RNDIS
@@ -44,8 +45,7 @@ MODULE_LICENSE("GPL");
4445
#define USB_FMS_INCLUDED
4546
#include "f_mass_storage.c"
4647

47-
#define USBF_ECM_INCLUDED
48-
#include "f_ecm.c"
48+
#include "u_ecm.h"
4949
#ifdef USB_ETH_RNDIS
5050
# define USB_FRNDIS_INCLUDED
5151
# include "f_rndis.c"
@@ -151,14 +151,14 @@ FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data);
151151

152152
static struct fsg_common fsg_common;
153153

154-
static u8 host_mac[ETH_ALEN];
155-
156154
static struct usb_function_instance *fi_acm;
157155
static struct eth_dev *the_dev;
158156

159157
/********** RNDIS **********/
160158

161159
#ifdef USB_ETH_RNDIS
160+
static u8 host_mac[ETH_ALEN];
161+
162162
static struct usb_function *f_acm_rndis;
163163

164164
static __init int rndis_do_config(struct usb_configuration *c)
@@ -220,7 +220,9 @@ static __ref int rndis_config_register(struct usb_composite_dev *cdev)
220220
/********** CDC ECM **********/
221221

222222
#ifdef CONFIG_USB_G_MULTI_CDC
223+
static struct usb_function_instance *fi_ecm;
223224
static struct usb_function *f_acm_multi;
225+
static struct usb_function *f_ecm;
224226

225227
static __init int cdc_do_config(struct usb_configuration *c)
226228
{
@@ -231,14 +233,20 @@ static __init int cdc_do_config(struct usb_configuration *c)
231233
c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
232234
}
233235

234-
ret = ecm_bind_config(c, host_mac, the_dev);
236+
f_ecm = usb_get_function(fi_ecm);
237+
if (IS_ERR(f_ecm))
238+
return PTR_ERR(f_ecm);
239+
240+
ret = usb_add_function(c, f_ecm);
235241
if (ret < 0)
236-
return ret;
242+
goto err_func_ecm;
237243

238244
/* implicit port_num is zero */
239245
f_acm_multi = usb_get_function(fi_acm);
240-
if (IS_ERR(f_acm_multi))
241-
return PTR_ERR(f_acm_multi);
246+
if (IS_ERR(f_acm_multi)) {
247+
ret = PTR_ERR(f_acm_multi);
248+
goto err_func_acm;
249+
}
242250

243251
ret = usb_add_function(c, f_acm_multi);
244252
if (ret)
@@ -253,6 +261,10 @@ static __init int cdc_do_config(struct usb_configuration *c)
253261
usb_remove_function(c, f_acm_multi);
254262
err_conf:
255263
usb_put_function(f_acm_multi);
264+
err_func_acm:
265+
usb_remove_function(c, f_ecm);
266+
err_func_ecm:
267+
usb_put_function(f_ecm);
256268
return ret;
257269
}
258270

@@ -285,6 +297,9 @@ static __ref int cdc_config_register(struct usb_composite_dev *cdev)
285297
static int __ref multi_bind(struct usb_composite_dev *cdev)
286298
{
287299
struct usb_gadget *gadget = cdev->gadget;
300+
#ifdef CONFIG_USB_G_MULTI_CDC
301+
struct f_ecm_opts *ecm_opts;
302+
#endif
288303
int status;
289304

290305
if (!can_support_ecm(cdev->gadget)) {
@@ -293,11 +308,39 @@ static int __ref multi_bind(struct usb_composite_dev *cdev)
293308
return -EINVAL;
294309
}
295310

311+
#ifdef CONFIG_USB_G_MULTI_CDC
312+
fi_ecm = usb_get_function_instance("ecm");
313+
if (IS_ERR(fi_ecm))
314+
return PTR_ERR(fi_ecm);
315+
316+
ecm_opts = container_of(fi_ecm, struct f_ecm_opts, func_inst);
317+
318+
gether_set_qmult(ecm_opts->net, qmult);
319+
if (!gether_set_host_addr(ecm_opts->net, host_addr))
320+
pr_info("using host ethernet address: %s", host_addr);
321+
if (!gether_set_dev_addr(ecm_opts->net, dev_addr))
322+
pr_info("using self ethernet address: %s", dev_addr);
323+
324+
the_dev = netdev_priv(ecm_opts->net);
325+
326+
#elif defined USB_ETH_RNDIS
327+
296328
/* set up network link layer */
297329
the_dev = gether_setup(cdev->gadget, dev_addr, host_addr, host_mac,
298330
qmult);
299331
if (IS_ERR(the_dev))
300332
return PTR_ERR(the_dev);
333+
#endif
334+
335+
#if (defined CONFIG_USB_G_MULTI_CDC && defined USB_ETH_RNDIS)
336+
gether_set_gadget(ecm_opts->net, cdev->gadget);
337+
status = gether_register_netdev(ecm_opts->net);
338+
if (status)
339+
goto fail0;
340+
ecm_opts->bound = true;
341+
342+
gether_get_host_addr_u8(ecm_opts->net, host_mac);
343+
#endif
301344

302345
/* set up serial link layer */
303346
fi_acm = usb_get_function_instance("acm");
@@ -345,7 +388,11 @@ static int __ref multi_bind(struct usb_composite_dev *cdev)
345388
fail1:
346389
usb_put_function_instance(fi_acm);
347390
fail0:
391+
#ifdef CONFIG_USB_G_MULTI_CDC
392+
usb_put_function_instance(fi_ecm);
393+
#else
348394
gether_cleanup(the_dev);
395+
#endif
349396
return status;
350397
}
351398

@@ -358,7 +405,12 @@ static int __exit multi_unbind(struct usb_composite_dev *cdev)
358405
usb_put_function(f_acm_rndis);
359406
#endif
360407
usb_put_function_instance(fi_acm);
408+
#ifdef CONFIG_USB_G_MULTI_CDC
409+
usb_put_function(f_ecm);
410+
usb_put_function_instance(fi_ecm);
411+
#else
361412
gether_cleanup(the_dev);
413+
#endif
362414
return 0;
363415
}
364416

0 commit comments

Comments
 (0)