@@ -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);
152151static struct fsg_common fsg_common ;
153152
154153static 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 ;
162159static struct usb_function * f_acm_rndis ;
160+ static struct usb_function * f_rndis ;
163161
164162static __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 );
192196err_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)
388411fail1 :
389412 usb_put_function_instance (fi_acm );
390413fail0 :
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