Skip to contentSkip to conversation

driver,usb: Fix a warning in uhci-hcd driver

PATCH In review Li, Zhen-Hua 3 participants 9 messages Apr 23, 2013 – Apr 26, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 driver,usb: Fix a warning in uhci-hcd driver

From: "Li, Zhen-Hua" <[email protected]>

This patch is trying to fix bug QXCR1001261767.
On some HP platform, when usb driver inits the iLo Virtual USB Controller, there may be a warning "Controller not stopped yet!". It is because driver does not wait enough time. This patch adds more time waiting and retries.

---
 drivers/usb/host/uhci-hcd.c |   16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/usb/host/uhci-hcd.c +15 -1
index 4a86b63..514e9d7 100644
@@ -277,6 +277,9 @@ static int global_suspend_mode_is_broken(struct uhci_hcd *uhci)
 		uhci->global_suspend_mode_is_broken(uhci) : 0;
 }
 
+#define UHCI_SUSPENDRH_RETRY_MAX      10
+#define UHCI_SUSPENDRH_RETRY_DELAY    100
+
 static void suspend_rh(struct uhci_hcd *uhci, enum uhci_rh_state new_state)
 __releases(uhci->lock)
 __acquires(uhci->lock)
@@ -284,6 +287,7 @@ __acquires(uhci->lock)
 	int auto_stop;
 	int int_enable, egsm_enable, wakeup_enable;
 	struct usb_device *rhdev = uhci_to_hcd(uhci)->self.root_hub;
+	u16 try, stopped;
 
 	auto_stop = (new_state == UHCI_RH_AUTO_STOPPED);
 	dev_dbg(&rhdev->dev, "%s%s\n", __func__,
@@ -355,7 +359,17 @@ __acquires(uhci->lock)
 		if (uhci->dead)
 			return;
 	}
-	if (!(uhci_readw(uhci, USBSTS) & USBSTS_HCH))
+
+	for (try = 0; try < UHCI_SUSPENDRH_RETRY_MAX; try++) {
+		/*
+		 * Sometimes we may need to wait more time and try again.
+		 */
+		stopped = uhci_readw(uhci, USBSTS) & USBSTS_HCH;
+		if (stopped)
+			break;
+		udelay(UHCI_SUSPENDRH_RETRY_DELAY);
+	}
+	if (!stopped)
 		dev_warn(uhci_dev(uhci), "Controller not stopped yet!\n");
 
 	uhci_get_current_frame_number(uhci);
Signature · 1 line
1.7.10.4
maintainer
#1 lore raw
Quoted 3 lines · Zhen-Hua

From: "Li, Zhen-Hua" <[email protected]>

This patch is trying to fix bug QXCR1001261767.

What is that bug number? Where can it be referenced? If you are going to put it in a public place (like a kernel changelog), it needs to be publicly accessible.

Quoted 1 line

On some HP platform, when usb driver inits the iLo Virtual USB Controller, there may be a warning "Controller not stopped yet!". It is because driver does not wait enough time.

What happened to your line endings?

Quoted 1 line

This patch adds more time waiting and retries.

Why not only do this for your device?

Quoted 29 lines
---
 drivers/usb/host/uhci-hcd.c |   16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/usb/host/uhci-hcd.c +4 -0
index 4a86b63..514e9d7 100644
@@ -277,6 +277,9 @@ static int global_suspend_mode_is_broken(struct uhci_hcd *uhci)
 		uhci->global_suspend_mode_is_broken(uhci) : 0;
 }
 
+#define UHCI_SUSPENDRH_RETRY_MAX      10
+#define UHCI_SUSPENDRH_RETRY_DELAY    100
+
 static void suspend_rh(struct uhci_hcd *uhci, enum uhci_rh_state new_state)
 __releases(uhci->lock)
 __acquires(uhci->lock)
@@ -284,6 +287,7 @@ __acquires(uhci->lock)
 	int auto_stop;
 	int int_enable, egsm_enable, wakeup_enable;
 	struct usb_device *rhdev = uhci_to_hcd(uhci)->self.root_hub;
+	u16 try, stopped;
 
 	auto_stop = (new_state == UHCI_RH_AUTO_STOPPED);
 	dev_dbg(&rhdev->dev, "%s%s\n", __func__,

drivers/usb/host/uhci-hcd.c __acquires(uhci->lock) · line 366

Quoted 9 lines
drivers/usb/host/uhci-hcd.c +5 -1
@@ -355,7 +359,17 @@ __acquires(uhci->lock)
 		if (uhci->dead)
 			return;
 	}
-	if (!(uhci_readw(uhci, USBSTS) & USBSTS_HCH))
+
+	for (try = 0; try < UHCI_SUSPENDRH_RETRY_MAX; try++) {
+		/*
+		 * Sometimes we may need to wait more time and try again.
+		 */

"Sometimes"? Please be more specific. Also, a multi-line comment isn't needed, make it one line please.

thanks,

greg k-h

maintainer
#2 lore raw
Quoted 9 lines · Greg KH
Quoted 3 lines · Zhen-Hua

From: "Li, Zhen-Hua" <[email protected]>

This patch is trying to fix bug QXCR1001261767.

What is that bug number? Where can it be referenced? If you are going to put it in a public place (like a kernel changelog), it needs to be publicly accessible.

Quoted 7 lines
Quoted 1 line

On some HP platform, when usb driver inits the iLo Virtual USB Controller, there may be a warning "Controller not stopped yet!". It is because driver does not wait enough time.

What happened to your line endings?

Quoted 1 line

This patch adds more time waiting and retries.

Why not only do this for your device?

It won't hurt to do it for all devices, because the wait loop will terminate as soon as the controller goes into suspend. For normal controllers this will be on the first iteration.

Quoted 13 lines
Quoted 13 lines
---
 drivers/usb/host/uhci-hcd.c |   16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/usb/host/uhci-hcd.c +0 -0
index 4a86b63..514e9d7 100644
@@ -277,6 +277,9 @@ static int global_suspend_mode_is_broken(struct uhci_hcd *uhci)
 		uhci->global_suspend_mode_is_broken(uhci) : 0;
 }
 
Quoted 2 lines

drivers/usb/host/uhci-hcd.c static int global_suspend_mode_is_broken(struct uhci_hcd *uhci) · line 281

Quoted 2 lines
drivers/usb/host/uhci-hcd.c +2 -0
+#define UHCI_SUSPENDRH_RETRY_MAX      10
+#define UHCI_SUSPENDRH_RETRY_DELAY    100

Why is the delay set to 100 us? Isn't that excessively large? How long does it take for this controller to go into suspend?

Quoted 8 lines

drivers/usb/host/uhci-hcd.c __acquires(uhci->lock) · line 290

Quoted 8 lines
drivers/usb/host/uhci-hcd.c +1 -0
 static void suspend_rh(struct uhci_hcd *uhci, enum uhci_rh_state new_state)
 __releases(uhci->lock)
 __acquires(uhci->lock)
@@ -284,6 +287,7 @@ __acquires(uhci->lock)
 	int auto_stop;
 	int int_enable, egsm_enable, wakeup_enable;
 	struct usb_device *rhdev = uhci_to_hcd(uhci)->self.root_hub;
+	u16 try, stopped;

Why are these variables u16? Why not int?

Anyway, a better approach would be not to add a delay loop at all. Instead, change this test:

	if (!auto_stop && !(uhci_readw(uhci, USBSTS) & USBSTS_HCH)) {
		uhci->rh_state = UHCI_RH_SUSPENDING;
		spin_unlock_irq(&uhci->lock);
		msleep(1);
		spin_lock_irq(&uhci->lock);
		if (uhci->dead)
			return;
	}

When the iLo controller is present, make the "if" statement always succeed. Then you'll get a whole 1-ms delay.

Alan Stern

author
#3 lore raw
Quoted 10 lines · Alan Stern
Quoted 8 lines · Greg KH
Quoted 3 lines · Zhen-Hua

From: "Li, Zhen-Hua" <[email protected]>

This patch is trying to fix bug QXCR1001261767.

What is that bug number? Where can it be referenced? If you are going to put it in a public place (like a kernel changelog), it needs to be publicly accessible.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

On some HP platform, when usb driver inits the iLo Virtual USB Controller, there may be a warning "Controller not stopped yet!". It is because driver does not wait enough time.

What happened to your line endings?

Quoted 1 line

This patch adds more time waiting and retries.

Why not only do this for your device?

It won't hurt to do it for all devices, because the wait loop will terminate as soon as the controller goes into suspend. For normal controllers this will be on the first iteration.

Yes, most devices only need one time check.

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
---
  drivers/usb/host/uhci-hcd.c |   16 +++++++++++++++-
  1 file changed, 15 insertions(+), 1 deletion(-)
drivers/usb/host/uhci-hcd.c +0 -0
index 4a86b63..514e9d7 100644
@@ -277,6 +277,9 @@ static int global_suspend_mode_is_broken(struct uhci_hcd *uhci)
  		uhci->global_suspend_mode_is_broken(uhci) : 0;
  }
 
Quoted 4 lines
Quoted 2 lines

drivers/usb/host/uhci-hcd.c static int global_suspend_mode_is_broken(struct uhci_hcd *uhci) · line 281

Quoted 2 lines
drivers/usb/host/uhci-hcd.c +2 -0
+#define UHCI_SUSPENDRH_RETRY_MAX      10
+#define UHCI_SUSPENDRH_RETRY_DELAY    100

Why is the delay set to 100 us? Isn't that excessively large? How long does it take for this controller to go into suspend?

This controller will take about 200~400 us, but I am not sure how long other devices will take. I set interval to 100 us, so it will save more time.

Quoted 10 lines
Quoted 9 lines

drivers/usb/host/uhci-hcd.c __acquires(uhci->lock) · line 290

Quoted 9 lines
drivers/usb/host/uhci-hcd.c +1 -0
  static void suspend_rh(struct uhci_hcd *uhci, enum uhci_rh_state new_state)
  __releases(uhci->lock)
  __acquires(uhci->lock)
@@ -284,6 +287,7 @@ __acquires(uhci->lock)
  	int auto_stop;
  	int int_enable, egsm_enable, wakeup_enable;
  	struct usb_device *rhdev = uhci_to_hcd(uhci)->self.root_hub;
+	u16 try, stopped;

Why are these variables u16? Why not int?

uhci_readw will return u16.

Quoted 12 lines

Anyway, a better approach would be not to add a delay loop at all. Instead, change this test:

	if (!auto_stop && !(uhci_readw(uhci, USBSTS) & USBSTS_HCH)) {
		uhci->rh_state = UHCI_RH_SUSPENDING;
		spin_unlock_irq(&uhci->lock);
		msleep(1);
		spin_lock_irq(&uhci->lock);
		if (uhci->dead)
			return;
	}
Quoted 2 lines

When the iLo controller is present, make the "if" statement always succeed. Then you'll get a whole 1-ms delay.

This will cause more operation and more time for other devices.

Quoted 2 lines

Alan Stern

maintainer
#4 lore raw
Quoted 7 lines · ZhenHua
Quoted 4 lines
Quoted 2 lines

drivers/usb/host/uhci-hcd.c static int global_suspend_mode_is_broken(struct uhci_hcd *uhci) · line 281

Quoted 2 lines
drivers/usb/host/uhci-hcd.c +2 -0
+#define UHCI_SUSPENDRH_RETRY_MAX      10
+#define UHCI_SUSPENDRH_RETRY_DELAY    100

Why is the delay set to 100 us? Isn't that excessively large? How long does it take for this controller to go into suspend?

This controller will take about 200~400 us, but I am not sure how long other devices will take.
I set interval to 100 us, so it will save more time.

A 400-us delay is fairly long. It would be better to avoid it entirely.

Quoted 2 lines
Quoted 1 line

Why are these variables u16? Why not int?

uhci_readw will return u16.

That's not a good reason, since u16 fits perfectly well inside an int. But never mind...

Quoted 12 lines
Quoted 12 lines

Anyway, a better approach would be not to add a delay loop at all. Instead, change this test:

	if (!auto_stop && !(uhci_readw(uhci, USBSTS) & USBSTS_HCH)) {
		uhci->rh_state = UHCI_RH_SUSPENDING;
		spin_unlock_irq(&uhci->lock);
		msleep(1);
		spin_lock_irq(&uhci->lock);
		if (uhci->dead)
			return;
	}
Quoted 3 lines
Quoted 2 lines

When the iLo controller is present, make the "if" statement always succeed. Then you'll get a whole 1-ms delay.

This will cause more operation and more time for other devices.

Actually what I wrote was wrong anyway. I forgot that when auto_stop is set, the routine is not allowed to sleep.

A better way to solve your problem is to change uhci_hub_status_data(). In the UHCI_RH_RUNNING_NODEVS case, change the line that says

		else if (time_after_eq(jiffies, uhci->auto_stop_time))

to

		else if (time_after_eq(jiffies, uhci->auto_stop_time) &&
				!uhci->no_auto_stops)

where uhci->no_auto_stops is a new bitflag that you set inside uhci_pci_init() if you detect that the controller is an iLo virtual UHCI controller.

This way there will always be a 1-ms delay, so the slow controller will suspend successfully. And other types of host controllers won't be affected, because the no_auto_stops flag won't get set for them.

Alan Stern

author
#5 lore raw
Quoted 10 lines · Alan Stern
Quoted 7 lines · ZhenHua
Quoted 4 lines
Quoted 2 lines

drivers/usb/host/uhci-hcd.c static int global_suspend_mode_is_broken(struct uhci_hcd *uhci) · line 281

Quoted 2 lines
drivers/usb/host/uhci-hcd.c +2 -0
+#define UHCI_SUSPENDRH_RETRY_MAX      10
+#define UHCI_SUSPENDRH_RETRY_DELAY    100

Why is the delay set to 100 us? Isn't that excessively large? How long does it take for this controller to go into suspend?

This controller will take about 200~400 us, but I am not sure how long other devices will take.
I set interval to 100 us, so it will save more time.

A 400-us delay is fairly long. It would be better to avoid it

The device needs about 200~400 us to get stopped, not OS. For other devices, it will not wait.

Quoted 39 lines

entirely.

Quoted 2 lines
Quoted 1 line

Why are these variables u16? Why not int?

uhci_readw will return u16.

That's not a good reason, since u16 fits perfectly well inside an int. But never mind...

Quoted 12 lines
Quoted 12 lines

Anyway, a better approach would be not to add a delay loop at all. Instead, change this test:

	if (!auto_stop && !(uhci_readw(uhci, USBSTS) & USBSTS_HCH)) {
		uhci->rh_state = UHCI_RH_SUSPENDING;
		spin_unlock_irq(&uhci->lock);
		msleep(1);
		spin_lock_irq(&uhci->lock);
		if (uhci->dead)
			return;
	}
Quoted 3 lines
Quoted 2 lines

When the iLo controller is present, make the "if" statement always succeed. Then you'll get a whole 1-ms delay.

This will cause more operation and more time for other devices.

Actually what I wrote was wrong anyway. I forgot that when auto_stop is set, the routine is not allowed to sleep.

A better way to solve your problem is to change uhci_hub_status_data(). In the UHCI_RH_RUNNING_NODEVS case, change the line that says

		else if (time_after_eq(jiffies, uhci->auto_stop_time))

to

		else if (time_after_eq(jiffies, uhci->auto_stop_time) &&
				!uhci->no_auto_stops)

where uhci->no_auto_stops is a new bitflag that you set inside uhci_pci_init() if you detect that the controller is an iLo virtual UHCI controller.

Quoted 6 lines

This way there will always be a 1-ms delay, so the slow controller will suspend successfully. And other types of host controllers won't be affected, because the no_auto_stops flag won't get set for them.

Alan Stern

I think it is a good idea, and the logic of the code may be more clear. I will do some test on my system.

Thanks
Zhen-Hua

author
#6 lore raw
In reply to Greg KH
Quoted 4 lines · Greg KH
Quoted 3 lines · Zhen-Hua

From: "Li, Zhen-Hua" <[email protected]>

This patch is trying to fix bug QXCR1001261767.

Sorry for the bug number. Please ignore this line.

Quoted 53 lines

What is that bug number? Where can it be referenced? If you are going to put it in a public place (like a kernel changelog), it needs to be publicly accessible.

Quoted 1 line

On some HP platform, when usb driver inits the iLo Virtual USB Controller, there may be a warning "Controller not stopped yet!". It is because driver does not wait enough time.

What happened to your line endings?

Quoted 1 line

This patch adds more time waiting and retries.

Why not only do this for your device?

Quoted 28 lines
---
  drivers/usb/host/uhci-hcd.c |   16 +++++++++++++++-
  1 file changed, 15 insertions(+), 1 deletion(-)
drivers/usb/host/uhci-hcd.c +4 -0
index 4a86b63..514e9d7 100644
@@ -277,6 +277,9 @@ static int global_suspend_mode_is_broken(struct uhci_hcd *uhci)
  		uhci->global_suspend_mode_is_broken(uhci) : 0;
  }
 
+#define UHCI_SUSPENDRH_RETRY_MAX      10
+#define UHCI_SUSPENDRH_RETRY_DELAY    100
+
  static void suspend_rh(struct uhci_hcd *uhci, enum uhci_rh_state new_state)
  __releases(uhci->lock)
  __acquires(uhci->lock)
@@ -284,6 +287,7 @@ __acquires(uhci->lock)
  	int auto_stop;
  	int int_enable, egsm_enable, wakeup_enable;
  	struct usb_device *rhdev = uhci_to_hcd(uhci)->self.root_hub;
+	u16 try, stopped;
 
  	auto_stop = (new_state == UHCI_RH_AUTO_STOPPED);
  	dev_dbg(&rhdev->dev, "%s%s\n", __func__,

drivers/usb/host/uhci-hcd.c __acquires(uhci->lock) · line 366

Quoted 9 lines
drivers/usb/host/uhci-hcd.c +5 -1
@@ -355,7 +359,17 @@ __acquires(uhci->lock)
  		if (uhci->dead)
  			return;
  	}
-	if (!(uhci_readw(uhci, USBSTS) & USBSTS_HCH))
+
+	for (try = 0; try < UHCI_SUSPENDRH_RETRY_MAX; try++) {
+		/*
+		 * Sometimes we may need to wait more time and try again.
+		 */

"Sometimes"? Please be more specific. Also, a multi-line comment isn't needed, make it one line please.

thanks,

greg k-h

maintainer
#7 lore raw
Quoted 6 lines · ZhenHua
Quoted 4 lines · Greg KH
Quoted 3 lines · Zhen-Hua

From: "Li, Zhen-Hua" <[email protected]>

This patch is trying to fix bug QXCR1001261767.

Sorry for the bug number. Please ignore this line.

I don't want to ignore it, I want it to point to something that I, and others, can reference in the future. Is there a url you can use for it?

thanks,

greg k-h

author
#8 lore raw

I did not found any url you can visit. And we will file a bug on SLES bugzilla site if possible.

I paste the bug discription here:
When booting SLES 11 SP2 on our server , messages like the following are logged during boot:

[  254.087187] uhci_hcd 0000:07:00.4: Controller not stopped yet!

Thanks
Zhen-Hua

Quoted 13 lines · Greg KH
Quoted 6 lines · ZhenHua
Quoted 4 lines · Greg KH
Quoted 3 lines · Zhen-Hua

From: "Li, Zhen-Hua" <[email protected]>

This patch is trying to fix bug QXCR1001261767.

Sorry for the bug number. Please ignore this line.

I don't want to ignore it, I want it to point to something that I, and others, can reference in the future. Is there a url you can use for it?

thanks,

greg k-h