Configuring host_addr and device_addr for u_ether
Hi,
(please break your lines at 80-columns)
Quoted 7 lines · Oliver
Hey,
I'm trying to use a composite gadget on a embedded linux platform using configfs. The kernel-doc was fine and I can now create my gadgets as needed. One big drawback is that the
host_addranddev_addrchange on every start.
Quoted 7 lines
So I tried to change them, without success:
* Most web documentation applies only to
g_ether(eg setting module/kernel parameters)* ${CONFIGFS}/usb_gadget/g1/functions/rndis.0/host_addr reports EBUSY if I try to write it
because the gadget is already configured.
Quoted 3 lines
* I checked the sources of my kernel (4.19) and the current ones to check if I can somehow add a MAC to the dtb of my system: It seems that there is no such binding.
you can write host_addr and dev_addr via configufs, but according to code, you have to do it before adding the functions to the gadget. This, to me, seems a bit odd. Does this patch help the situation in any way?
drivers/usb/gadget/function/f_ecm.c +8 -0
@@ -530,14 +530,19 @@ static int ecm_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl)static int ecm_set_alt (struct usb_function *f,unsigned intf,unsigned alt) {struct f_ecm *ecm =func_to_ecm (f); +struct f_ecm_opts *ecm_opts;struct usb_composite_dev *cdev = f->config->cdev; + ecm_opts = container_of(f->fi, struct f_ecm_opts, func_inst); +/* Control interface has only altsetting 0 */ if (intf == ecm->ctrl_id) {if (alt !=0 ) goto fail;VDBG (cdev,"reset ecm control %d\n" , intf); + + ecm_opts->running = false;usb_ep_disable (ecm->notify);if (!(ecm->notify->desc)) {VDBG (cdev,"init ecm ctrl %d\n" , intf);
@@ -545,6 +550,7 @@ static int ecm_set_alt(struct usb_function *f, unsigned intf, unsigned alt) goto fail; }usb_ep_enable (ecm->notify); + ecm_opts->running = true;/* Data interface has two altsettings, 0 and 1 */ }else if (intf == ecm->data_id) {
@@ -553,6 +559,7 @@ static int ecm_set_alt(struct usb_function *f, unsigned intf, unsigned alt)if (ecm->port.in_ep->enabled) {DBG (cdev,"reset ecm\n" ); + ecm_opts->running = false;gether_disconnect (&ecm->port); }
@@ -585,6 +592,7 @@ static int ecm_set_alt(struct usb_function *f, unsigned intf, unsigned alt) net =gether_connect (&ecm->port);if (IS_ERR (net))return PTR_ERR (net); + ecm_opts->running = true; }/* NOTE this can be a minor disagreement with the ECM spec,
drivers/usb/gadget/function/u_ecm.h +1 -0
@@ -19,6 +19,7 @@ struct f_ecm_opts {struct usb_function_instance func_inst;struct net_device *net;bool bound; +bool running;/* * Read/write access to configfs attributes is handled by configfs.
drivers/usb/gadget/function/u_ether_configfs.h +2 -2
@@ -46,7 +46,7 @@int ret; \ \mutex_lock (&opts->lock); \ -if (opts->refcnt) { \ +if (opts->running) { \mutex_unlock (&opts->lock); \return -EBUSY ; \ } \
@@ -81,7 +81,7 @@int ret; \ \mutex_lock (&opts->lock); \ -if (opts->refcnt) { \ +if (opts->running) { \mutex_unlock (&opts->lock); \return -EBUSY ; \ } \