All of lore.kernel.org
 help / color / mirror / Atom feed
From: Felipe Balbi <felipe.balbi@linux.intel.com>
To: "Westermann, Oliver" <Oliver.Westermann@cognex.com>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>
Subject: Configuring host_addr and device_addr for u_ether
Date: Wed, 06 Mar 2019 10:48:15 +0200	[thread overview]
Message-ID: <875zsw1j8w.fsf@linux.intel.com> (raw)

Hi,

(please break your lines at 80-columns)

"Westermann, Oliver" <Oliver.Westermann@cognex.com> writes:
> 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_addr and dev_addr
> change on every start.
>
> 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.

> * 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?

diff --git a/drivers/usb/gadget/function/f_ecm.c b/drivers/usb/gadget/function/f_ecm.c
index 6ce044008cf6..31279aaf3f3b 100644
--- a/drivers/usb/gadget/function/f_ecm.c
+++ b/drivers/usb/gadget/function/f_ecm.c
@@ -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,
diff --git a/drivers/usb/gadget/function/u_ecm.h b/drivers/usb/gadget/function/u_ecm.h
index 050aa672ee7f..752258dd1c3e 100644
--- a/drivers/usb/gadget/function/u_ecm.h
+++ b/drivers/usb/gadget/function/u_ecm.h
@@ -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.
diff --git a/drivers/usb/gadget/function/u_ether_configfs.h b/drivers/usb/gadget/function/u_ether_configfs.h
index cd33cee4d78b..7fe0a7fa4e7a 100644
--- a/drivers/usb/gadget/function/u_ether_configfs.h
+++ b/drivers/usb/gadget/function/u_ether_configfs.h
@@ -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;					\
 		}							\

                 reply	other threads:[~2019-03-06  8:48 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=875zsw1j8w.fsf@linux.intel.com \
    --to=felipe.balbi@linux.intel.com \
    --cc=Oliver.Westermann@cognex.com \
    --cc=linux-usb@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.