Skip to contentSkip to conversation

Fix peripheral USB mode detection

PATCH Superseded Svyatoslav Ryhel 4 participants 14 messages Oct 13, 2024 – Nov 21, 2024 USB

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Fix peripheral USB mode detection

In the older USB controllers like for example in ChipIdea controller used by the Tegra 2 the "USBADRA: Device Address Advance" bitflag does not exist, so the new device address set during SET_ADDRESS can't be deferred by hardware, which causes the host to not recognize the device and give an error.

Instead store it until ep completes to apply the change into the hw register as Linux kernel does. This should fix regression on old and and be compatible with newer controllers.

Fixes usb peripheral on Tegra 2 devices.

Ion Agorria (1):
usb: ci_udc: don't use "advance" feature when setting address

 drivers/usb/gadget/ci_udc.c | 24 +++++++++++++++++++++++-
 drivers/usb/gadget/ci_udc.h |  1 +
 2 files changed, 24 insertions(+), 1 deletion(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/1 usb: ci_udc: don't use "advance" feature when setting address

From: Ion Agorria <[email protected]>

In the older USB controllers like for example in ChipIdea controller used by the Tegra 2 the "USBADRA: Device Address Advance" bitflag does not exist, so the new device address set during SET_ADDRESS can't be deferred by hardware, which causes the host to not recognize the device and give an error.

Instead store it until ep completes to apply the change into the hw register as Linux kernel does. This should fix regression on old and and be compatible with newer controllers.

---
 drivers/usb/gadget/ci_udc.c | 24 +++++++++++++++++++++++-
 drivers/usb/gadget/ci_udc.h |  1 +
 2 files changed, 24 insertions(+), 1 deletion(-)
drivers/usb/gadget/ci_udc.c +23 -1
index bbe03cfff1f..4bff75da759 100644
@@ -649,12 +649,30 @@ static void flip_ep0_direction(void)
 	}
 }
 
+/*
+ * This function explicitly sets the address, without the "USBADRA" (advance)
+ * feature, which is not supported by older versions of the controller.
+ */
+static void ci_set_address(struct ci_udc *udc, u8 address)
+{
+	DBG("%s %x\n", __func__, address);
+	writel(address << 25, &udc->devaddr);
+}
+
 static void handle_ep_complete(struct ci_ep *ci_ep)
 {
 	struct ept_queue_item *item, *next_td;
 	int num, in, len, j;
 	struct ci_req *ci_req;
 
+	/* Set the device address that was previously sent by SET_ADDRESS */
+	if (controller.next_device_address != 0) {
+		struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor;
+
+		ci_set_address(udc, controller.next_device_address);
+		controller.next_device_address = 0;
+	}
+
 	num = ci_ep->desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
 	in = (ci_ep->desc->bEndpointAddress & USB_DIR_IN) != 0;
 	item = ci_get_qtd(num, in);
@@ -783,7 +801,7 @@ static void handle_setup(void)
 		 * write address delayed (will take effect
 		 * after the next IN txn)
 		 */
-		writel((r.wValue << 25) | (1 << 24), &udc->devaddr);
+		controller.next_device_address = r.wValue;
 		req->length = 0;
 		usb_ep_queue(controller.gadget.ep0, req, 0);
 		return;
@@ -814,6 +832,9 @@ static void stop_activity(void)
 	int i, num, in;
 	struct ept_queue_head *head;
 	struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor;
+
+	ci_set_address(udc, 0);
+
 	writel(readl(&udc->epcomp), &udc->epcomp);
 #ifdef CONFIG_CI_UDC_HAS_HOSTPC
 	writel(readl(&udc->epsetupstat), &udc->epsetupstat);
@@ -934,6 +955,7 @@ static int ci_pullup(struct usb_gadget *gadget, int is_on)
 	struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor;
 	if (is_on) {
 		/* RESET */
+		controller.next_device_address = 0;
 		writel(USBCMD_ITC(MICRO_8FRAME) | USBCMD_RST, &udc->usbcmd);
 		udelay(200);
 
drivers/usb/gadget/ci_udc.h +1 -0
index bea2f9f3fe3..807f2084c1e 100644
@@ -105,6 +105,7 @@ struct ci_drv {
 	struct ept_queue_head		*epts;
 	uint8_t				*items_mem;
 	struct ci_ep			ep[NUM_ENDPOINTS];
+	u8				next_device_address;
 };
 
 struct ept_queue_head {
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH v1 1/1] usb: ci_udc: don't use "advance" feature when setting address

Hi Svyatoslav,

Thank you for the patch.

Quoted 11 lines · Svyatoslav Ryhel

From: Ion Agorria <[email protected]>

In the older USB controllers like for example in ChipIdea controller used by the Tegra 2 the "USBADRA: Device Address Advance" bitflag does not exist, so the new device address set during SET_ADDRESS can't be deferred by hardware, which causes the host to not recognize the device and give an error.

Instead store it until ep completes to apply the change into the hw register as Linux kernel does. This should fix regression on old and and be compatible with newer controllers.

Since this is based on a linux commit, can we please mention the revision in the commit message?

Per my understanding, this would be:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ef15e5490edc7edf808d3477ab32e0e320792f65

Quoted 75 lines
---
 drivers/usb/gadget/ci_udc.c | 24 +++++++++++++++++++++++-
 drivers/usb/gadget/ci_udc.h |  1 +
 2 files changed, 24 insertions(+), 1 deletion(-)
drivers/usb/gadget/ci_udc.c +23 -1
index bbe03cfff1f..4bff75da759 100644
@@ -649,12 +649,30 @@ static void flip_ep0_direction(void)
 	}
 }
 
+/*
+ * This function explicitly sets the address, without the "USBADRA" (advance)
+ * feature, which is not supported by older versions of the controller.
+ */
+static void ci_set_address(struct ci_udc *udc, u8 address)
+{
+	DBG("%s %x\n", __func__, address);
+	writel(address << 25, &udc->devaddr);
+}
+
 static void handle_ep_complete(struct ci_ep *ci_ep)
 {
 	struct ept_queue_item *item, *next_td;
 	int num, in, len, j;
 	struct ci_req *ci_req;
 
+	/* Set the device address that was previously sent by SET_ADDRESS */
+	if (controller.next_device_address != 0) {
+		struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor;
+
+		ci_set_address(udc, controller.next_device_address);
+		controller.next_device_address = 0;
+	}
+
 	num = ci_ep->desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
 	in = (ci_ep->desc->bEndpointAddress & USB_DIR_IN) != 0;
 	item = ci_get_qtd(num, in);
@@ -783,7 +801,7 @@ static void handle_setup(void)
 		 * write address delayed (will take effect
 		 * after the next IN txn)
 		 */
-		writel((r.wValue << 25) | (1 << 24), &udc->devaddr);
+		controller.next_device_address = r.wValue;
 		req->length = 0;
 		usb_ep_queue(controller.gadget.ep0, req, 0);
 		return;
@@ -814,6 +832,9 @@ static void stop_activity(void)
 	int i, num, in;
 	struct ept_queue_head *head;
 	struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor;
+
+	ci_set_address(udc, 0);
+
 	writel(readl(&udc->epcomp), &udc->epcomp);
 #ifdef CONFIG_CI_UDC_HAS_HOSTPC
 	writel(readl(&udc->epsetupstat), &udc->epsetupstat);
@@ -934,6 +955,7 @@ static int ci_pullup(struct usb_gadget *gadget, int is_on)
 	struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor;
 	if (is_on) {
 		/* RESET */
+		controller.next_device_address = 0;
 		writel(USBCMD_ITC(MICRO_8FRAME) | USBCMD_RST, &udc->usbcmd);
 		udelay(200);
 
drivers/usb/gadget/ci_udc.h +0 -0
index bea2f9f3fe3..807f2084c1e 100644

drivers/usb/gadget/ci_udc.h struct ci_drv { · line 108

Quoted 4 lines
drivers/usb/gadget/ci_udc.h +1 -0
@@ -105,6 +105,7 @@ struct ci_drv {
 	struct ept_queue_head		*epts;
 	uint8_t				*items_mem;
 	struct ci_ep			ep[NUM_ENDPOINTS];
+	u8				next_device_address;

Comparing to
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ef15e5490edc7edf808d3477ab32e0e320792f65,

Can we please keep similar logic ?
Having both:
- bool setaddr
- u8 address

This way, we keep the diff with the linux driver a bit lower.

Quoted 5 lines
drivers/usb/gadget/ci_udc.h +0 -0
 };
 
 struct ept_queue_head {
Signature · 1 line
2.43.0
#3 lore raw

Re: [PATCH v1 1/1] usb: ci_udc: don't use "advance" feature when setting address

Hello,

Yes that's the correct commit I found when researching why the issue didn't happen in Linux, I already found that Tegra 2 reference docs had a different information about the register compared to Tegra 3.

I consider that a single variable is enough since the value is only non-zero when we want to set a new address. But if is necessary i can copy like Linux does.

Regards,
Ion Agorria

Quoted 120 lines · Mattijs Korpershoek

Hi Svyatoslav,

Thank you for the patch.

Quoted 11 lines · Svyatoslav Ryhel

From: Ion Agorria <[email protected]>

In the older USB controllers like for example in ChipIdea controller used by the Tegra 2 the "USBADRA: Device Address Advance" bitflag does not exist, so the new device address set during SET_ADDRESS can't be deferred by hardware, which causes the host to not recognize the device and give an error.

Instead store it until ep completes to apply the change into the hw register as Linux kernel does. This should fix regression on old and and be compatible with newer controllers.

Since this is based on a linux commit, can we please mention the revision in the commit message?

Per my understanding, this would be:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ef15e5490edc7edf808d3477ab32e0e320792f65

Quoted 75 lines
---
 drivers/usb/gadget/ci_udc.c | 24 +++++++++++++++++++++++-
 drivers/usb/gadget/ci_udc.h |  1 +
 2 files changed, 24 insertions(+), 1 deletion(-)
drivers/usb/gadget/ci_udc.c +23 -1
index bbe03cfff1f..4bff75da759 100644
@@ -649,12 +649,30 @@ static void flip_ep0_direction(void)
      }
 }
 
+/*
+ * This function explicitly sets the address, without the "USBADRA" (advance)
+ * feature, which is not supported by older versions of the controller.
+ */
+static void ci_set_address(struct ci_udc *udc, u8 address)
+{
+     DBG("%s %x\n", __func__, address);
+     writel(address << 25, &udc->devaddr);
+}
+
 static void handle_ep_complete(struct ci_ep *ci_ep)
 {
      struct ept_queue_item *item, *next_td;
      int num, in, len, j;
      struct ci_req *ci_req;
 
+     /* Set the device address that was previously sent by SET_ADDRESS */
+     if (controller.next_device_address != 0) {
+             struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor;
+
+             ci_set_address(udc, controller.next_device_address);
+             controller.next_device_address = 0;
+     }
+
      num = ci_ep->desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
      in = (ci_ep->desc->bEndpointAddress & USB_DIR_IN) != 0;
      item = ci_get_qtd(num, in);
@@ -783,7 +801,7 @@ static void handle_setup(void)
               * write address delayed (will take effect
               * after the next IN txn)
               */
-             writel((r.wValue << 25) | (1 << 24), &udc->devaddr);
+             controller.next_device_address = r.wValue;
              req->length = 0;
              usb_ep_queue(controller.gadget.ep0, req, 0);
              return;
@@ -814,6 +832,9 @@ static void stop_activity(void)
      int i, num, in;
      struct ept_queue_head *head;
      struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor;
+
+     ci_set_address(udc, 0);
+
      writel(readl(&udc->epcomp), &udc->epcomp);
 #ifdef CONFIG_CI_UDC_HAS_HOSTPC
      writel(readl(&udc->epsetupstat), &udc->epsetupstat);
@@ -934,6 +955,7 @@ static int ci_pullup(struct usb_gadget *gadget, int is_on)
      struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor;
      if (is_on) {
              /* RESET */
+             controller.next_device_address = 0;
              writel(USBCMD_ITC(MICRO_8FRAME) | USBCMD_RST, &udc->usbcmd);
              udelay(200);
 
drivers/usb/gadget/ci_udc.h +0 -0
index bea2f9f3fe3..807f2084c1e 100644

drivers/usb/gadget/ci_udc.h struct ci_drv { · line 108

Quoted 4 lines
drivers/usb/gadget/ci_udc.h +1 -0
@@ -105,6 +105,7 @@ struct ci_drv {
      struct ept_queue_head           *epts;
      uint8_t                         *items_mem;
      struct ci_ep                    ep[NUM_ENDPOINTS];
+     u8                              next_device_address;

Comparing to
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ef15e5490edc7edf808d3477ab32e0e320792f65,

Can we please keep similar logic ?
Having both:
- bool setaddr
- u8 address

This way, we keep the diff with the linux driver a bit lower.

Quoted 5 lines
drivers/usb/gadget/ci_udc.h +0 -1
 };
 
 struct ept_queue_head {
--

2.43.0

#4 lore raw

Re: [PATCH v1 1/1] usb: ci_udc: don't use "advance" feature when setting address

Hi,

Quoted 9 lines · Ion Agorria

Hello,

Yes that's the correct commit I found when researching why the issue didn't happen in Linux, I already found that Tegra 2 reference docs had a different information about the register compared to Tegra 3.

I consider that a single variable is enough since the value is only non-zero when we want to set a new address. But if is necessary i can copy like Linux does.

You are right, a single variable is enough. I'd still prefer to have what Linux does because it will make it easier to compare with the Linux driver in the future,

Thanks
Mattijs

Quoted 126 lines

Regards,
Ion Agorria

Quoted 120 lines · Mattijs Korpershoek

Hi Svyatoslav,

Thank you for the patch.

Quoted 11 lines · Svyatoslav Ryhel

From: Ion Agorria <[email protected]>

In the older USB controllers like for example in ChipIdea controller used by the Tegra 2 the "USBADRA: Device Address Advance" bitflag does not exist, so the new device address set during SET_ADDRESS can't be deferred by hardware, which causes the host to not recognize the device and give an error.

Instead store it until ep completes to apply the change into the hw register as Linux kernel does. This should fix regression on old and and be compatible with newer controllers.

Since this is based on a linux commit, can we please mention the revision in the commit message?

Per my understanding, this would be:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ef15e5490edc7edf808d3477ab32e0e320792f65

Quoted 75 lines
---
 drivers/usb/gadget/ci_udc.c | 24 +++++++++++++++++++++++-
 drivers/usb/gadget/ci_udc.h |  1 +
 2 files changed, 24 insertions(+), 1 deletion(-)
drivers/usb/gadget/ci_udc.c +23 -1
index bbe03cfff1f..4bff75da759 100644
@@ -649,12 +649,30 @@ static void flip_ep0_direction(void)
      }
 }
 
+/*
+ * This function explicitly sets the address, without the "USBADRA" (advance)
+ * feature, which is not supported by older versions of the controller.
+ */
+static void ci_set_address(struct ci_udc *udc, u8 address)
+{
+     DBG("%s %x\n", __func__, address);
+     writel(address << 25, &udc->devaddr);
+}
+
 static void handle_ep_complete(struct ci_ep *ci_ep)
 {
      struct ept_queue_item *item, *next_td;
      int num, in, len, j;
      struct ci_req *ci_req;
 
+     /* Set the device address that was previously sent by SET_ADDRESS */
+     if (controller.next_device_address != 0) {
+             struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor;
+
+             ci_set_address(udc, controller.next_device_address);
+             controller.next_device_address = 0;
+     }
+
      num = ci_ep->desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
      in = (ci_ep->desc->bEndpointAddress & USB_DIR_IN) != 0;
      item = ci_get_qtd(num, in);
@@ -783,7 +801,7 @@ static void handle_setup(void)
               * write address delayed (will take effect
               * after the next IN txn)
               */
-             writel((r.wValue << 25) | (1 << 24), &udc->devaddr);
+             controller.next_device_address = r.wValue;
              req->length = 0;
              usb_ep_queue(controller.gadget.ep0, req, 0);
              return;
@@ -814,6 +832,9 @@ static void stop_activity(void)
      int i, num, in;
      struct ept_queue_head *head;
      struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor;
+
+     ci_set_address(udc, 0);
+
      writel(readl(&udc->epcomp), &udc->epcomp);
 #ifdef CONFIG_CI_UDC_HAS_HOSTPC
      writel(readl(&udc->epsetupstat), &udc->epsetupstat);
@@ -934,6 +955,7 @@ static int ci_pullup(struct usb_gadget *gadget, int is_on)
      struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor;
      if (is_on) {
              /* RESET */
+             controller.next_device_address = 0;
              writel(USBCMD_ITC(MICRO_8FRAME) | USBCMD_RST, &udc->usbcmd);
              udelay(200);
 
drivers/usb/gadget/ci_udc.h +0 -0
index bea2f9f3fe3..807f2084c1e 100644

drivers/usb/gadget/ci_udc.h struct ci_drv { · line 108

Quoted 4 lines
drivers/usb/gadget/ci_udc.h +1 -0
@@ -105,6 +105,7 @@ struct ci_drv {
      struct ept_queue_head           *epts;
      uint8_t                         *items_mem;
      struct ci_ep                    ep[NUM_ENDPOINTS];
+     u8                              next_device_address;

Comparing to
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ef15e5490edc7edf808d3477ab32e0e320792f65,

Can we please keep similar logic ?
Having both:
- bool setaddr
- u8 address

This way, we keep the diff with the linux driver a bit lower.

Quoted 5 lines
drivers/usb/gadget/ci_udc.h +0 -1
 };
 
 struct ept_queue_head {
--

2.43.0

#5 lore raw

Re: [PATCH v1 1/1] usb: ci_udc: don't use "advance" feature when setting address

чт, 17 жовт. 2024 р. о 15:21 Mattijs Korpershoek
<[email protected]> пише:

Quoted 11 lines

Hi,

Quoted 6 lines · Ion Agorria

Hello,

Yes that's the correct commit I found when researching why the issue didn't happen in Linux, I already found that Tegra 2 reference docs had a different information about the register compared to Tegra 3.

Quoted 8 lines
Quoted 3 lines

I consider that a single variable is enough since the value is only non-zero when we want to set a new address. But if is necessary i can copy like Linux does.

You are right, a single variable is enough. I'd still prefer to have what Linux does because it will make it easier to compare with the Linux driver in the future,

Hello!

Proposed patch already does what Linux changes do. Your request to make it "same" as Linux is impossible to achieve since the u-boot driver itself does not descend from Linux, nor it is similar to Linux one. There is nothing to compare with Linux in the future.

Best regards,
Svyatoslav R.

Quoted 129 lines

Thanks
Mattijs

Quoted 126 lines

Regards,
Ion Agorria

Quoted 120 lines · Mattijs Korpershoek

Hi Svyatoslav,

Thank you for the patch.

Quoted 11 lines · Svyatoslav Ryhel

From: Ion Agorria <[email protected]>

In the older USB controllers like for example in ChipIdea controller used by the Tegra 2 the "USBADRA: Device Address Advance" bitflag does not exist, so the new device address set during SET_ADDRESS can't be deferred by hardware, which causes the host to not recognize the device and give an error.

Instead store it until ep completes to apply the change into the hw register as Linux kernel does. This should fix regression on old and and be compatible with newer controllers.

Since this is based on a linux commit, can we please mention the revision in the commit message?

Per my understanding, this would be:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ef15e5490edc7edf808d3477ab32e0e320792f65

Quoted 75 lines
---
 drivers/usb/gadget/ci_udc.c | 24 +++++++++++++++++++++++-
 drivers/usb/gadget/ci_udc.h |  1 +
 2 files changed, 24 insertions(+), 1 deletion(-)
drivers/usb/gadget/ci_udc.c +23 -1
index bbe03cfff1f..4bff75da759 100644
@@ -649,12 +649,30 @@ static void flip_ep0_direction(void)
      }
 }
 
+/*
+ * This function explicitly sets the address, without the "USBADRA" (advance)
+ * feature, which is not supported by older versions of the controller.
+ */
+static void ci_set_address(struct ci_udc *udc, u8 address)
+{
+     DBG("%s %x\n", __func__, address);
+     writel(address << 25, &udc->devaddr);
+}
+
 static void handle_ep_complete(struct ci_ep *ci_ep)
 {
      struct ept_queue_item *item, *next_td;
      int num, in, len, j;
      struct ci_req *ci_req;
 
+     /* Set the device address that was previously sent by SET_ADDRESS */
+     if (controller.next_device_address != 0) {
+             struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor;
+
+             ci_set_address(udc, controller.next_device_address);
+             controller.next_device_address = 0;
+     }
+
      num = ci_ep->desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
      in = (ci_ep->desc->bEndpointAddress & USB_DIR_IN) != 0;
      item = ci_get_qtd(num, in);
@@ -783,7 +801,7 @@ static void handle_setup(void)
               * write address delayed (will take effect
               * after the next IN txn)
               */
-             writel((r.wValue << 25) | (1 << 24), &udc->devaddr);
+             controller.next_device_address = r.wValue;
              req->length = 0;
              usb_ep_queue(controller.gadget.ep0, req, 0);
              return;
@@ -814,6 +832,9 @@ static void stop_activity(void)
      int i, num, in;
      struct ept_queue_head *head;
      struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor;
+
+     ci_set_address(udc, 0);
+
      writel(readl(&udc->epcomp), &udc->epcomp);
 #ifdef CONFIG_CI_UDC_HAS_HOSTPC
      writel(readl(&udc->epsetupstat), &udc->epsetupstat);
@@ -934,6 +955,7 @@ static int ci_pullup(struct usb_gadget *gadget, int is_on)
      struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor;
      if (is_on) {
              /* RESET */
+             controller.next_device_address = 0;
              writel(USBCMD_ITC(MICRO_8FRAME) | USBCMD_RST, &udc->usbcmd);
              udelay(200);
 
drivers/usb/gadget/ci_udc.h +0 -0
index bea2f9f3fe3..807f2084c1e 100644

drivers/usb/gadget/ci_udc.h struct ci_drv { · line 108

Quoted 4 lines
drivers/usb/gadget/ci_udc.h +1 -0
@@ -105,6 +105,7 @@ struct ci_drv {
      struct ept_queue_head           *epts;
      uint8_t                         *items_mem;
      struct ci_ep                    ep[NUM_ENDPOINTS];
+     u8                              next_device_address;

Comparing to
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ef15e5490edc7edf808d3477ab32e0e320792f65,

Can we please keep similar logic ?
Having both:
- bool setaddr
- u8 address

This way, we keep the diff with the linux driver a bit lower.

Quoted 5 lines
drivers/usb/gadget/ci_udc.h +0 -1
 };
 
 struct ept_queue_head {
--

2.43.0

#6 lore raw

Re: [PATCH v1 1/1] usb: ci_udc: don't use "advance" feature when setting address

Quoted 22 lines · Svyatoslav Ryhel

чт, 17 жовт. 2024 р. о 15:21 Mattijs Korpershoek
<[email protected]> пише:

Quoted 11 lines

Hi,

Quoted 6 lines · Ion Agorria

Hello,

Yes that's the correct commit I found when researching why the issue didn't happen in Linux, I already found that Tegra 2 reference docs had a different information about the register compared to Tegra 3.

Quoted 8 lines
Quoted 3 lines

I consider that a single variable is enough since the value is only non-zero when we want to set a new address. But if is necessary i can copy like Linux does.

You are right, a single variable is enough. I'd still prefer to have what Linux does because it will make it easier to compare with the Linux driver in the future,

Quoted 6 lines

Hello!

Proposed patch already does what Linux changes do. Your request to make it "same" as Linux is impossible to achieve since the u-boot driver itself does not descend from Linux, nor it is similar to Linux one. There is nothing to compare with Linux in the future.

I'm not saying it should be a verbatim copy of the Linux driver. I'm saying that keeping similar variable names can help people comparing both.

Ion just send previously:

"""
Yes that's the correct commit I found when researching why the issue didn't happen in Linux
"""

So clearly, comparison with the linux driver is valuable given that it was done for **this very patch**.

Quoted 133 lines

Best regards,
Svyatoslav R.

Quoted 129 lines

Thanks
Mattijs

Quoted 126 lines

Regards,
Ion Agorria

Quoted 120 lines · Mattijs Korpershoek

Hi Svyatoslav,

Thank you for the patch.

Quoted 11 lines · Svyatoslav Ryhel

From: Ion Agorria <[email protected]>

In the older USB controllers like for example in ChipIdea controller used by the Tegra 2 the "USBADRA: Device Address Advance" bitflag does not exist, so the new device address set during SET_ADDRESS can't be deferred by hardware, which causes the host to not recognize the device and give an error.

Instead store it until ep completes to apply the change into the hw register as Linux kernel does. This should fix regression on old and and be compatible with newer controllers.

Since this is based on a linux commit, can we please mention the revision in the commit message?

Per my understanding, this would be:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ef15e5490edc7edf808d3477ab32e0e320792f65

Quoted 75 lines
---
 drivers/usb/gadget/ci_udc.c | 24 +++++++++++++++++++++++-
 drivers/usb/gadget/ci_udc.h |  1 +
 2 files changed, 24 insertions(+), 1 deletion(-)
drivers/usb/gadget/ci_udc.c +23 -1
index bbe03cfff1f..4bff75da759 100644
@@ -649,12 +649,30 @@ static void flip_ep0_direction(void)
      }
 }
 
+/*
+ * This function explicitly sets the address, without the "USBADRA" (advance)
+ * feature, which is not supported by older versions of the controller.
+ */
+static void ci_set_address(struct ci_udc *udc, u8 address)
+{
+     DBG("%s %x\n", __func__, address);
+     writel(address << 25, &udc->devaddr);
+}
+
 static void handle_ep_complete(struct ci_ep *ci_ep)
 {
      struct ept_queue_item *item, *next_td;
      int num, in, len, j;
      struct ci_req *ci_req;
 
+     /* Set the device address that was previously sent by SET_ADDRESS */
+     if (controller.next_device_address != 0) {
+             struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor;
+
+             ci_set_address(udc, controller.next_device_address);
+             controller.next_device_address = 0;
+     }
+
      num = ci_ep->desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
      in = (ci_ep->desc->bEndpointAddress & USB_DIR_IN) != 0;
      item = ci_get_qtd(num, in);
@@ -783,7 +801,7 @@ static void handle_setup(void)
               * write address delayed (will take effect
               * after the next IN txn)
               */
-             writel((r.wValue << 25) | (1 << 24), &udc->devaddr);
+             controller.next_device_address = r.wValue;
              req->length = 0;
              usb_ep_queue(controller.gadget.ep0, req, 0);
              return;
@@ -814,6 +832,9 @@ static void stop_activity(void)
      int i, num, in;
      struct ept_queue_head *head;
      struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor;
+
+     ci_set_address(udc, 0);
+
      writel(readl(&udc->epcomp), &udc->epcomp);
 #ifdef CONFIG_CI_UDC_HAS_HOSTPC
      writel(readl(&udc->epsetupstat), &udc->epsetupstat);
@@ -934,6 +955,7 @@ static int ci_pullup(struct usb_gadget *gadget, int is_on)
      struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor;
      if (is_on) {
              /* RESET */
+             controller.next_device_address = 0;
              writel(USBCMD_ITC(MICRO_8FRAME) | USBCMD_RST, &udc->usbcmd);
              udelay(200);
 
drivers/usb/gadget/ci_udc.h +0 -0
index bea2f9f3fe3..807f2084c1e 100644

drivers/usb/gadget/ci_udc.h struct ci_drv { · line 108

Quoted 4 lines
drivers/usb/gadget/ci_udc.h +1 -0
@@ -105,6 +105,7 @@ struct ci_drv {
      struct ept_queue_head           *epts;
      uint8_t                         *items_mem;
      struct ci_ep                    ep[NUM_ENDPOINTS];
+     u8                              next_device_address;

Comparing to
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ef15e5490edc7edf808d3477ab32e0e320792f65,

Can we please keep similar logic ?
Having both:
- bool setaddr
- u8 address

This way, we keep the diff with the linux driver a bit lower.

Quoted 5 lines
drivers/usb/gadget/ci_udc.h +0 -1
 };
 
 struct ept_queue_head {
--

2.43.0

#7 lore raw

Re: [PATCH v1 1/1] usb: ci_udc: don't use "advance" feature when setting address

Hello,

I already finished the fix before looking up and only moved the set address function outside as a func after seeing the linux version.

I think drivers are different enough so there isnt much to compare.

Regards,
Ion

Quoted 196 lines · On Thu, 17 Oct 2024, 15:13 Mattijs Korpershoek, <[email protected]>…
Quoted 22 lines · Svyatoslav Ryhel

чт, 17 жовт. 2024 р. о 15:21 Mattijs Korpershoek
<[email protected]> пише:

Quoted 11 lines

Hi,

Quoted 6 lines · Ion Agorria

Hello,

Yes that's the correct commit I found when researching why the issue didn't happen in Linux, I already found that Tegra 2 reference docs had a different information about the register compared to Tegra 3.

Quoted 8 lines
Quoted 3 lines

I consider that a single variable is enough since the value is only non-zero when we want to set a new address. But if is necessary i can copy like Linux does.

You are right, a single variable is enough. I'd still prefer to have what Linux does because it will make it easier to compare with the Linux driver in the future,

Quoted 6 lines

Hello!

Proposed patch already does what Linux changes do. Your request to make it "same" as Linux is impossible to achieve since the u-boot driver itself does not descend from Linux, nor it is similar to Linux one. There is nothing to compare with Linux in the future.

I'm not saying it should be a verbatim copy of the Linux driver. I'm saying that keeping similar variable names can help people comparing both.

Ion just send previously:

"""
Yes that's the correct commit I found when researching why the issue didn't happen in Linux
"""

So clearly, comparison with the linux driver is valuable given that it was done for **this very patch**.

Quoted 19 lines

Best regards,
Svyatoslav R.

Quoted 15 lines

Thanks
Mattijs

Quoted 12 lines

Regards,
Ion Agorria

Quoted 6 lines · Mattijs Korpershoek

Hi Svyatoslav,

Thank you for the patch.

On dim., oct. 13, 2024 at 17:58, Svyatoslav Ryhel <

Quoted 4 lines · [email protected]> wrote:
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

From: Ion Agorria <[email protected]>

In the older USB controllers like for example in ChipIdea

controller

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

used by the Tegra 2 the "USBADRA: Device Address Advance" bitflag does not exist, so the new device address set during SET_ADDRESS can't be deferred by hardware, which causes the host to not

recognize

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

the device and give an error.

Instead store it until ep completes to apply the change into the hw register as Linux kernel does. This should fix regression on old

and

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 1 line

and be compatible with newer controllers.

Since this is based on a linux commit, can we please mention the revision in the commit message?

Per my understanding, this would be:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ef15e5490edc7edf808d3477ab32e0e320792f65

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

Review

Quoted 10 lines
---
 drivers/usb/gadget/ci_udc.c | 24 +++++++++++++++++++++++-
 drivers/usb/gadget/ci_udc.h |  1 +
 2 files changed, 24 insertions(+), 1 deletion(-)
(quoted diff) +0 -0

b/drivers/usb/gadget/ci_udc.c

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

drivers/usb/gadget/ci_udc.c static void flip_ep0_direction(void) · line 653

Quoted 9 lines

index bbe03cfff1f..4bff75da759 100644

drivers/usb/gadget/ci_udc.c +2 -0
@@ -649,12 +649,30 @@ static void flip_ep0_direction(void)
      }
 }
 
+/*
+ * This function explicitly sets the address, without the

"USBADRA" (advance)

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

drivers/usb/gadget/ci_udc.c static void flip_ep0_direction(void) · line 654

Quoted 1 line
drivers/usb/gadget/ci_udc.c +1 -0
+ * feature, which is not supported by older versions of the

controller.

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
drivers/usb/gadget/ci_udc.c +7 -0
+ */
+static void ci_set_address(struct ci_udc *udc, u8 address)
+{
+     DBG("%s %x\n", __func__, address);
+     writel(address << 25, &udc->devaddr);
+}
+
 static void handle_ep_complete(struct ci_ep *ci_ep)
 {
      struct ept_queue_item *item, *next_td;
      int num, in, len, j;
      struct ci_req *ci_req;
 
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

drivers/usb/gadget/ci_udc.c static void flip_ep0_direction(void) · line 668

Quoted 1 line
drivers/usb/gadget/ci_udc.c +1 -0
+     /* Set the device address that was previously sent by

SET_ADDRESS */

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

drivers/usb/gadget/ci_udc.c static void flip_ep0_direction(void) · line 670

Quoted 2 lines
drivers/usb/gadget/ci_udc.c +2 -0
+     if (controller.next_device_address != 0) {
+             struct ci_udc *udc = (struct ci_udc

*)controller.ctrl->hcor;

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

drivers/usb/gadget/ci_udc.c static void flip_ep0_direction(void)

Quoted 6 lines
drivers/usb/gadget/ci_udc.c +5 -0
+
+             ci_set_address(udc, controller.next_device_address);
+             controller.next_device_address = 0;
+     }
+
      num = ci_ep->desc->bEndpointAddress &

USB_ENDPOINT_NUMBER_MASK;

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
drivers/usb/gadget/ci_udc.c +1 -1
      in = (ci_ep->desc->bEndpointAddress & USB_DIR_IN) != 0;
      item = ci_get_qtd(num, in);
@@ -783,7 +801,7 @@ static void handle_setup(void)
               * write address delayed (will take effect
               * after the next IN txn)
               */
-             writel((r.wValue << 25) | (1 << 24), &udc->devaddr);
+             controller.next_device_address = r.wValue;
              req->length = 0;
              usb_ep_queue(controller.gadget.ep0, req, 0);
              return;
@@ -814,6 +832,9 @@ static void stop_activity(void)
      int i, num, in;
      struct ept_queue_head *head;
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/usb/gadget/ci_udc.c static int ci_pullup(struct usb_gadget

Quoted 8 lines
drivers/usb/gadget/ci_udc.c +3 -0
      struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor;
+
+     ci_set_address(udc, 0);
+
      writel(readl(&udc->epcomp), &udc->epcomp);
 #ifdef CONFIG_CI_UDC_HAS_HOSTPC
      writel(readl(&udc->epsetupstat), &udc->epsetupstat);
@@ -934,6 +955,7 @@ static int ci_pullup(struct usb_gadget

*gadget, int is_on)

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

drivers/usb/gadget/ci_udc.c static int ci_pullup(struct usb_gadget *gadget, int is_on)

Quoted 5 lines
drivers/usb/gadget/ci_udc.c +1 -0
      struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor;
      if (is_on) {
              /* RESET */
+             controller.next_device_address = 0;
              writel(USBCMD_ITC(MICRO_8FRAME) | USBCMD_RST,

&udc->usbcmd);

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Review

Quoted 3 lines
drivers/usb/gadget/ci_udc.c +0 -0
              udelay(200);
 
(quoted diff) +0 -0

b/drivers/usb/gadget/ci_udc.h

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

drivers/usb/gadget/ci_udc.h struct ci_drv { · line 108

Quoted 8 lines

index bea2f9f3fe3..807f2084c1e 100644

drivers/usb/gadget/ci_udc.h +1 -0
@@ -105,6 +105,7 @@ struct ci_drv {
      struct ept_queue_head           *epts;
      uint8_t                         *items_mem;
      struct ci_ep                    ep[NUM_ENDPOINTS];
+     u8                              next_device_address;

Comparing to

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ef15e5490edc7edf808d3477ab32e0e320792f65
,

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines

Can we please keep similar logic ?
Having both:
- bool setaddr
- u8 address

This way, we keep the diff with the linux driver a bit lower.

Quoted 5 lines
drivers/usb/gadget/ci_udc.h +0 -1
 };
 
 struct ept_queue_head {
--

2.43.0

#8 lore raw

Re: [PATCH v1 1/1] usb: ci_udc: don't use "advance" feature when setting address

In reply to Svyatoslav Ryhel

On 10/13/24 4:58 PM, Svyatoslav Ryhel wrote:

Sorry for the late reply.

drivers/usb/gadget/ci_udc.c static void flip_ep0_direction(void) · line 658

Quoted 12 lines

+++ b/drivers/usb/gadget/ci_udc.c

drivers/usb/gadget/ci_udc.c +7 -0
@@ -649,12 +649,30 @@ static void flip_ep0_direction(void)
  	}
  }
 
+/*
+ * This function explicitly sets the address, without the "USBADRA" (advance)
+ * feature, which is not supported by older versions of the controller.
+ */
+static void ci_set_address(struct ci_udc *udc, u8 address)
+{
+	DBG("%s %x\n", __func__, address);

log_debug() or dev_dbg() please.

Quoted 21 lines
drivers/usb/gadget/ci_udc.c +11 -0
+	writel(address << 25, &udc->devaddr);
+}
+
  static void handle_ep_complete(struct ci_ep *ci_ep)
  {
  	struct ept_queue_item *item, *next_td;
  	int num, in, len, j;
  	struct ci_req *ci_req;
 
+	/* Set the device address that was previously sent by SET_ADDRESS */
+	if (controller.next_device_address != 0) {
+		struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor;
+
+		ci_set_address(udc, controller.next_device_address);
+		controller.next_device_address = 0;
+	}
+
  	num = ci_ep->desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
  	in = (ci_ep->desc->bEndpointAddress & USB_DIR_IN) != 0;
  	item = ci_get_qtd(num, in);

drivers/usb/gadget/ci_udc.c static void handle_setup(void) · line 804

Quoted 5 lines
drivers/usb/gadget/ci_udc.c +1 -1
@@ -783,7 +801,7 @@ static void handle_setup(void)
  		 * write address delayed (will take effect
  		 * after the next IN txn)
  		 */
-		writel((r.wValue << 25) | (1 << 24), &udc->devaddr);
+		controller.next_device_address = r.wValue;

wValue is word , u16 , but next_device_address is u8 below , why ?

Quoted 26 lines
drivers/usb/gadget/ci_udc.c +4 -0
  		req->length = 0;
  		usb_ep_queue(controller.gadget.ep0, req, 0);
  		return;
@@ -814,6 +832,9 @@ static void stop_activity(void)
  	int i, num, in;
  	struct ept_queue_head *head;
  	struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor;
+
+	ci_set_address(udc, 0);
+
  	writel(readl(&udc->epcomp), &udc->epcomp);
  #ifdef CONFIG_CI_UDC_HAS_HOSTPC
  	writel(readl(&udc->epsetupstat), &udc->epsetupstat);
@@ -934,6 +955,7 @@ static int ci_pullup(struct usb_gadget *gadget, int is_on)
  	struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor;
  	if (is_on) {
  		/* RESET */
+		controller.next_device_address = 0;
  		writel(USBCMD_ITC(MICRO_8FRAME) | USBCMD_RST, &udc->usbcmd);
  		udelay(200);
 
drivers/usb/gadget/ci_udc.h +0 -0
index bea2f9f3fe3..807f2084c1e 100644

drivers/usb/gadget/ci_udc.h struct ci_drv { · line 108

Quoted 4 lines
drivers/usb/gadget/ci_udc.h +1 -0
@@ -105,6 +105,7 @@ struct ci_drv {
  	struct ept_queue_head		*epts;
  	uint8_t				*items_mem;
  	struct ci_ep			ep[NUM_ENDPOINTS];
+	u8				next_device_address;

Should this be u16 ?

#9 lore raw

Re: [PATCH v1 1/1] usb: ci_udc: don't use "advance" feature when setting address

нд, 27 жовт. 2024 р. о 18:09 Marek Vasut <[email protected]> пише:

Quoted 10 lines · Svyatoslav Ryhel

Sorry for the late reply.

Quoted 5 lines

+++ b/drivers/usb/gadget/ci_udc.c

(quoted diff) +0 -0
@@ -649,12 +649,30 @@ static void flip_ep0_direction(void)
      }
  }
 
Quoted 10 lines

drivers/usb/gadget/ci_udc.c static void flip_ep0_direction(void) · line 658

Quoted 7 lines
drivers/usb/gadget/ci_udc.c +7 -0
+/*
+ * This function explicitly sets the address, without the "USBADRA" (advance)
+ * feature, which is not supported by older versions of the controller.
+ */
+static void ci_set_address(struct ci_udc *udc, u8 address)
+{
+     DBG("%s %x\n", __func__, address);

log_debug() or dev_dbg() please.

DBG macro is used across entire driver, if you wish to replace it, then pls, send a followup with patch for entire driver. This is out of scope of this patch.

Quoted 20 lines
Quoted 20 lines
drivers/usb/gadget/ci_udc.c +11 -0
+     writel(address << 25, &udc->devaddr);
+}
+
  static void handle_ep_complete(struct ci_ep *ci_ep)
  {
      struct ept_queue_item *item, *next_td;
      int num, in, len, j;
      struct ci_req *ci_req;
 
+     /* Set the device address that was previously sent by SET_ADDRESS */
+     if (controller.next_device_address != 0) {
+             struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor;
+
+             ci_set_address(udc, controller.next_device_address);
+             controller.next_device_address = 0;
+     }
+
      num = ci_ep->desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
      in = (ci_ep->desc->bEndpointAddress & USB_DIR_IN) != 0;
      item = ci_get_qtd(num, in);
Quoted 9 lines

drivers/usb/gadget/ci_udc.c static void handle_setup(void) · line 804

Quoted 6 lines
drivers/usb/gadget/ci_udc.c +1 -1
@@ -783,7 +801,7 @@ static void handle_setup(void)
               * write address delayed (will take effect
               * after the next IN txn)
               */
-             writel((r.wValue << 25) | (1 << 24), &udc->devaddr);
+             controller.next_device_address = r.wValue;

wValue is word , u16 , but next_device_address is u8 below , why ?

wValue is u16 but only 8 bits are relevant since USB address is 8 bit, hence u8. Changing wValue to u8 is out of scope of this patch as well.

Quoted 21 lines
Quoted 21 lines
drivers/usb/gadget/ci_udc.c +4 -0
              req->length = 0;
              usb_ep_queue(controller.gadget.ep0, req, 0);
              return;
@@ -814,6 +832,9 @@ static void stop_activity(void)
      int i, num, in;
      struct ept_queue_head *head;
      struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor;
+
+     ci_set_address(udc, 0);
+
      writel(readl(&udc->epcomp), &udc->epcomp);
  #ifdef CONFIG_CI_UDC_HAS_HOSTPC
      writel(readl(&udc->epsetupstat), &udc->epsetupstat);
@@ -934,6 +955,7 @@ static int ci_pullup(struct usb_gadget *gadget, int is_on)
      struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor;
      if (is_on) {
              /* RESET */
+             controller.next_device_address = 0;
              writel(USBCMD_ITC(MICRO_8FRAME) | USBCMD_RST, &udc->usbcmd);
              udelay(200);
 
Quoted 11 lines

drivers/usb/gadget/ci_udc.h struct ci_drv { · line 108

Quoted 9 lines
drivers/usb/gadget/ci_udc.h +1 -0
index bea2f9f3fe3..807f2084c1e 100644
@@ -105,6 +105,7 @@ struct ci_drv {
      struct ept_queue_head           *epts;
      uint8_t                         *items_mem;
      struct ci_ep                    ep[NUM_ENDPOINTS];
+     u8                              next_device_address;

Should this be u16 ?

No, USB address is only 8bits (u8)

#10 lore raw

Re: [PATCH v1 1/1] usb: ci_udc: don't use "advance" feature when setting address

нд, 27 жовт. 2024 р. о 18:42 Svyatoslav Ryhel <[email protected]> пише:

Quoted 93 lines

нд, 27 жовт. 2024 р. о 18:09 Marek Vasut <[email protected]> пише:

Quoted 10 lines · Svyatoslav Ryhel

Sorry for the late reply.

Quoted 5 lines

+++ b/drivers/usb/gadget/ci_udc.c

(quoted diff) +0 -0
@@ -649,12 +649,30 @@ static void flip_ep0_direction(void)
      }
  }
 
Quoted 10 lines

drivers/usb/gadget/ci_udc.c static void flip_ep0_direction(void) · line 658

Quoted 7 lines
drivers/usb/gadget/ci_udc.c +7 -0
+/*
+ * This function explicitly sets the address, without the "USBADRA" (advance)
+ * feature, which is not supported by older versions of the controller.
+ */
+static void ci_set_address(struct ci_udc *udc, u8 address)
+{
+     DBG("%s %x\n", __func__, address);

log_debug() or dev_dbg() please.

DBG macro is used across entire driver, if you wish to replace it, then pls, send a followup with patch for entire driver. This is out of scope of this patch.

Quoted 20 lines
Quoted 20 lines
drivers/usb/gadget/ci_udc.c +11 -0
+     writel(address << 25, &udc->devaddr);
+}
+
  static void handle_ep_complete(struct ci_ep *ci_ep)
  {
      struct ept_queue_item *item, *next_td;
      int num, in, len, j;
      struct ci_req *ci_req;
 
+     /* Set the device address that was previously sent by SET_ADDRESS */
+     if (controller.next_device_address != 0) {
+             struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor;
+
+             ci_set_address(udc, controller.next_device_address);
+             controller.next_device_address = 0;
+     }
+
      num = ci_ep->desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
      in = (ci_ep->desc->bEndpointAddress & USB_DIR_IN) != 0;
      item = ci_get_qtd(num, in);
Quoted 9 lines

drivers/usb/gadget/ci_udc.c static void handle_setup(void) · line 804

Quoted 6 lines
drivers/usb/gadget/ci_udc.c +1 -1
@@ -783,7 +801,7 @@ static void handle_setup(void)
               * write address delayed (will take effect
               * after the next IN txn)
               */
-             writel((r.wValue << 25) | (1 << 24), &udc->devaddr);
+             controller.next_device_address = r.wValue;

wValue is word , u16 , but next_device_address is u8 below , why ?

wValue is u16 but only 8 bits are relevant since USB address is 8 bit, hence u8. Changing wValue to u8 is out of scope of this patch as well.

Quoted 21 lines
Quoted 21 lines
drivers/usb/gadget/ci_udc.c +4 -0
              req->length = 0;
              usb_ep_queue(controller.gadget.ep0, req, 0);
              return;
@@ -814,6 +832,9 @@ static void stop_activity(void)
      int i, num, in;
      struct ept_queue_head *head;
      struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor;
+
+     ci_set_address(udc, 0);
+
      writel(readl(&udc->epcomp), &udc->epcomp);
  #ifdef CONFIG_CI_UDC_HAS_HOSTPC
      writel(readl(&udc->epsetupstat), &udc->epsetupstat);
@@ -934,6 +955,7 @@ static int ci_pullup(struct usb_gadget *gadget, int is_on)
      struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor;
      if (is_on) {
              /* RESET */
+             controller.next_device_address = 0;
              writel(USBCMD_ITC(MICRO_8FRAME) | USBCMD_RST, &udc->usbcmd);
              udelay(200);
 
Quoted 11 lines

drivers/usb/gadget/ci_udc.h struct ci_drv { · line 108

Quoted 9 lines
drivers/usb/gadget/ci_udc.h +1 -0
index bea2f9f3fe3..807f2084c1e 100644
@@ -105,6 +105,7 @@ struct ci_drv {
      struct ept_queue_head           *epts;
      uint8_t                         *items_mem;
      struct ci_ep                    ep[NUM_ENDPOINTS];
+     u8                              next_device_address;

Should this be u16 ?

Quoted 1 line

No, USB address is only 8bits (u8)

If no other comments were proposed, may this patch be applied?

#11 lore raw

Re: [PATCH v1 1/1] usb: ci_udc: don't use "advance" feature when setting address

Hello,

Quoted 94 lines · Svyatoslav Ryhel

нд, 27 жовт. 2024 р. о 18:42 Svyatoslav Ryhel <[email protected]> пише:

Quoted 93 lines

нд, 27 жовт. 2024 р. о 18:09 Marek Vasut <[email protected]> пише:

Quoted 10 lines · Svyatoslav Ryhel

Sorry for the late reply.

Quoted 5 lines

+++ b/drivers/usb/gadget/ci_udc.c

(quoted diff) +0 -0
@@ -649,12 +649,30 @@ static void flip_ep0_direction(void)
      }
  }
 
Quoted 10 lines

drivers/usb/gadget/ci_udc.c static void flip_ep0_direction(void) · line 658

Quoted 7 lines
drivers/usb/gadget/ci_udc.c +7 -0
+/*
+ * This function explicitly sets the address, without the "USBADRA" (advance)
+ * feature, which is not supported by older versions of the controller.
+ */
+static void ci_set_address(struct ci_udc *udc, u8 address)
+{
+     DBG("%s %x\n", __func__, address);

log_debug() or dev_dbg() please.

DBG macro is used across entire driver, if you wish to replace it, then pls, send a followup with patch for entire driver. This is out of scope of this patch.

Quoted 20 lines
Quoted 20 lines
drivers/usb/gadget/ci_udc.c +11 -0
+     writel(address << 25, &udc->devaddr);
+}
+
  static void handle_ep_complete(struct ci_ep *ci_ep)
  {
      struct ept_queue_item *item, *next_td;
      int num, in, len, j;
      struct ci_req *ci_req;
 
+     /* Set the device address that was previously sent by SET_ADDRESS */
+     if (controller.next_device_address != 0) {
+             struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor;
+
+             ci_set_address(udc, controller.next_device_address);
+             controller.next_device_address = 0;
+     }
+
      num = ci_ep->desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
      in = (ci_ep->desc->bEndpointAddress & USB_DIR_IN) != 0;
      item = ci_get_qtd(num, in);
Quoted 9 lines

drivers/usb/gadget/ci_udc.c static void handle_setup(void) · line 804

Quoted 6 lines
drivers/usb/gadget/ci_udc.c +1 -1
@@ -783,7 +801,7 @@ static void handle_setup(void)
               * write address delayed (will take effect
               * after the next IN txn)
               */
-             writel((r.wValue << 25) | (1 << 24), &udc->devaddr);
+             controller.next_device_address = r.wValue;

wValue is word , u16 , but next_device_address is u8 below , why ?

wValue is u16 but only 8 bits are relevant since USB address is 8 bit, hence u8. Changing wValue to u8 is out of scope of this patch as well.

Quoted 32 lines
Quoted 26 lines
drivers/usb/gadget/ci_udc.c +4 -0
              req->length = 0;
              usb_ep_queue(controller.gadget.ep0, req, 0);
              return;
@@ -814,6 +832,9 @@ static void stop_activity(void)
      int i, num, in;
      struct ept_queue_head *head;
      struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor;
+
+     ci_set_address(udc, 0);
+
      writel(readl(&udc->epcomp), &udc->epcomp);
  #ifdef CONFIG_CI_UDC_HAS_HOSTPC
      writel(readl(&udc->epsetupstat), &udc->epsetupstat);
@@ -934,6 +955,7 @@ static int ci_pullup(struct usb_gadget *gadget, int is_on)
      struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor;
      if (is_on) {
              /* RESET */
+             controller.next_device_address = 0;
              writel(USBCMD_ITC(MICRO_8FRAME) | USBCMD_RST, &udc->usbcmd);
              udelay(200);
 
drivers/usb/gadget/ci_udc.h +0 -0
index bea2f9f3fe3..807f2084c1e 100644

drivers/usb/gadget/ci_udc.h struct ci_drv { · line 108

Quoted 4 lines
drivers/usb/gadget/ci_udc.h +1 -0
@@ -105,6 +105,7 @@ struct ci_drv {
      struct ept_queue_head           *epts;
      uint8_t                         *items_mem;
      struct ci_ep                    ep[NUM_ENDPOINTS];
+     u8                              next_device_address;

Should this be u16 ?

Quoted 3 lines
Quoted 1 line

No, USB address is only 8bits (u8)

If no other comments were proposed, may this patch be applied?

Ah, sorry, i've been waiting for a v2 patch that includes a link to the related kernel commit as asked in [1].

Do you want me to fixup the commit message locally or will a v2 be send?

Thanks!
Mattijs

[1] https://lore.kernel.org/all/[email protected]/

#12 lore raw

Re: [PATCH v1 1/1] usb: ci_udc: don't use "advance" feature when setting address

чт, 21 лист. 2024 р. о 13:14 Mattijs Korpershoek
<[email protected]> пише:

Quoted 106 lines

Hello,

Quoted 94 lines · Svyatoslav Ryhel

нд, 27 жовт. 2024 р. о 18:42 Svyatoslav Ryhel <[email protected]> пише:

Quoted 93 lines

нд, 27 жовт. 2024 р. о 18:09 Marek Vasut <[email protected]> пише:

Quoted 10 lines · Svyatoslav Ryhel

Sorry for the late reply.

Quoted 5 lines

+++ b/drivers/usb/gadget/ci_udc.c

(quoted diff) +0 -0
@@ -649,12 +649,30 @@ static void flip_ep0_direction(void)
      }
  }
 
Quoted 10 lines

drivers/usb/gadget/ci_udc.c static void flip_ep0_direction(void) · line 658

Quoted 7 lines
drivers/usb/gadget/ci_udc.c +7 -0
+/*
+ * This function explicitly sets the address, without the "USBADRA" (advance)
+ * feature, which is not supported by older versions of the controller.
+ */
+static void ci_set_address(struct ci_udc *udc, u8 address)
+{
+     DBG("%s %x\n", __func__, address);

log_debug() or dev_dbg() please.

DBG macro is used across entire driver, if you wish to replace it, then pls, send a followup with patch for entire driver. This is out of scope of this patch.

Quoted 20 lines
Quoted 20 lines
drivers/usb/gadget/ci_udc.c +11 -0
+     writel(address << 25, &udc->devaddr);
+}
+
  static void handle_ep_complete(struct ci_ep *ci_ep)
  {
      struct ept_queue_item *item, *next_td;
      int num, in, len, j;
      struct ci_req *ci_req;
 
+     /* Set the device address that was previously sent by SET_ADDRESS */
+     if (controller.next_device_address != 0) {
+             struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor;
+
+             ci_set_address(udc, controller.next_device_address);
+             controller.next_device_address = 0;
+     }
+
      num = ci_ep->desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
      in = (ci_ep->desc->bEndpointAddress & USB_DIR_IN) != 0;
      item = ci_get_qtd(num, in);
Quoted 9 lines

drivers/usb/gadget/ci_udc.c static void handle_setup(void) · line 804

Quoted 6 lines
drivers/usb/gadget/ci_udc.c +1 -1
@@ -783,7 +801,7 @@ static void handle_setup(void)
               * write address delayed (will take effect
               * after the next IN txn)
               */
-             writel((r.wValue << 25) | (1 << 24), &udc->devaddr);
+             controller.next_device_address = r.wValue;

wValue is word , u16 , but next_device_address is u8 below , why ?

wValue is u16 but only 8 bits are relevant since USB address is 8 bit, hence u8. Changing wValue to u8 is out of scope of this patch as well.

Quoted 32 lines
Quoted 26 lines
drivers/usb/gadget/ci_udc.c +4 -0
              req->length = 0;
              usb_ep_queue(controller.gadget.ep0, req, 0);
              return;
@@ -814,6 +832,9 @@ static void stop_activity(void)
      int i, num, in;
      struct ept_queue_head *head;
      struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor;
+
+     ci_set_address(udc, 0);
+
      writel(readl(&udc->epcomp), &udc->epcomp);
  #ifdef CONFIG_CI_UDC_HAS_HOSTPC
      writel(readl(&udc->epsetupstat), &udc->epsetupstat);
@@ -934,6 +955,7 @@ static int ci_pullup(struct usb_gadget *gadget, int is_on)
      struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor;
      if (is_on) {
              /* RESET */
+             controller.next_device_address = 0;
              writel(USBCMD_ITC(MICRO_8FRAME) | USBCMD_RST, &udc->usbcmd);
              udelay(200);
 
drivers/usb/gadget/ci_udc.h +0 -0
index bea2f9f3fe3..807f2084c1e 100644

drivers/usb/gadget/ci_udc.h struct ci_drv { · line 108

Quoted 4 lines
drivers/usb/gadget/ci_udc.h +1 -0
@@ -105,6 +105,7 @@ struct ci_drv {
      struct ept_queue_head           *epts;
      uint8_t                         *items_mem;
      struct ci_ep                    ep[NUM_ENDPOINTS];
+     u8                              next_device_address;

Should this be u16 ?

Quoted 3 lines
Quoted 1 line

No, USB address is only 8bits (u8)

If no other comments were proposed, may this patch be applied?

Ah, sorry, i've been waiting for a v2 patch that includes a link to the related kernel commit as asked in [1].

Quoted 6 lines

Do you want me to fixup the commit message locally or will a v2 be send?

Thanks!
Mattijs

[1] https://lore.kernel.org/all/[email protected]/

Both options are acceptable, it is up to you, what to choose.

#13 lore raw

Re: [PATCH v1 1/1] usb: ci_udc: don't use "advance" feature when setting address

Hi,

On jeu., nov. 21, 2024 at 13:15, Svyatoslav Ryhel <[email protected]> wrote:

[...]

Quoted 5 lines
Quoted 5 lines
Quoted 1 line

If no other comments were proposed, may this patch be applied?

Ah, sorry, i've been waiting for a v2 patch that includes a link to the related kernel commit as asked in [1].

Quoted 8 lines
Quoted 6 lines

Do you want me to fixup the commit message locally or will a v2 be send?

Thanks!
Mattijs

[1] https://lore.kernel.org/all/[email protected]/

Both options are acceptable, it is up to you, what to choose.

Please send a v2 then. Thanks