This patch includes:

 - updates from Benjamin Herrenschmidt to make usbcore
   behave a bit better during PM suspend (setting and
   checking hcd state).

 - related updates from me, making more paths into hcds
   fail when the driver is suspended.

 - updates based on some feedback from Alan Stern,
   notably including getting rid of a state we don't
   really need (most of the patch, by volume).

 - an experiment that tries to give a warning in the
   sadly common case of ACPI or APIC (etc) settings
   that need to change before USB works.

Net effect is that some of the PM issues start to get
resolved, maybe IRQ problems will be diagnosed quicker,
and some overdue cleanup gets started.

Please have a look-see.

- Dave

--- 1.20/drivers/usb/core/hcd-pci.c     Tue Aug 12 09:19:01 2003
+++ edited/drivers/usb/core/hcd-pci.c   Fri Aug 29 18:14:52 2003
@@ -139,6 +139,7 @@
                        return retval;
                }
        }
+       // hcd zeroed everything
        hcd->regs = base;
        hcd->region = region;
 
@@ -165,6 +166,7 @@
                dev_err (hcd->controller, "can't reset\n");
                goto clean_3;
        }
+       hcd->state = USB_STATE_HALT;
 
        pci_set_master (dev);
 #ifndef __sparc__
@@ -230,7 +232,8 @@
                BUG ();
 
        hub = hcd->self.root_hub;
-       hcd->state = USB_STATE_QUIESCING;
+       if (HCD_IS_RUNNING (hcd->state))
+               hcd->state = USB_STATE_QUIESCING;
 
        dev_dbg (hcd->controller, "roothub graceful disconnect\n");
        usb_disconnect (&hub);
@@ -287,8 +290,8 @@
                pci_save_state (dev, hcd->pci_state);
 
                /* driver may want to disable DMA etc */
+               hcd->state = USB_STATE_QUIESCING;
                retval = hcd->driver->suspend (hcd, state);
-               hcd->state = USB_STATE_SUSPENDED;
        }
 
        pci_set_power_state (dev, state);
--- 1.72/drivers/usb/core/hcd.c Tue Aug 12 09:07:44 2003
+++ edited/drivers/usb/core/hcd.c       Fri Aug 29 18:16:13 2003
@@ -1097,6 +1097,8 @@
 static int hcd_get_frame_number (struct usb_device *udev)
 {
        struct usb_hcd  *hcd = (struct usb_hcd *)udev->bus->hcpriv;
+       if (!HCD_IS_RUNNING (hcd->state))
+               return -ESHUTDOWN;
        return hcd->driver->get_frame_number (hcd);
 }
 
@@ -1193,6 +1195,12 @@
                goto done;
        }
 
+       /* running ~= hc unlink handshake works (irq, timer, etc)
+        * halted ~= no unlink handshake is needed
+        * suspended, resuming == should never happen
+        */
+       WARN_ON (!HCD_IS_RUNNING (hcd->state) && hcd->state != USB_STATE_HALT);
+
        if (!urb->hcpriv) {
                retval = -EINVAL;
                goto done;
@@ -1208,6 +1216,17 @@
                goto done;
        }
 
+       /* PCI IRQ setup can easily be broken so that USB controllers
+        * never get completion IRQs ... maybe even the ones we need to
+        * finish unlinking the initial failed usb_set_address().
+        */
+       if (!hcd->saw_irq) {
+               dev_warn (hcd->controller, "Unlink after no-IRQ?  "
+                       "Different ACPI or APIC settings may help."
+                       "\n");
+               hcd->saw_irq = 1;
+       }
+
        /* maybe set up to block until the urb's completion fires.  the
         * lower level hcd code is always async, locking on urb->status
         * updates; an intercepted completion unblocks us.
@@ -1287,6 +1306,8 @@
        dev = udev->hcpriv;
        hcd = udev->bus->hcpriv;
 
+       WARN_ON (!HCD_IS_RUNNING (hcd->state) && hcd->state != USB_STATE_HALT);
+
        local_irq_disable ();
 
 rescan:
@@ -1483,6 +1504,7 @@
        if (unlikely (hcd->state == USB_STATE_HALT))    /* irq sharing? */
                return IRQ_NONE;
 
+       hcd->saw_irq = 1;
        hcd->driver->irq (hcd, r);
        if (hcd->state != start && hcd->state == USB_STATE_HALT)
                usb_hc_died (hcd);
--- 1.33/drivers/usb/core/hcd.h Tue Aug 12 09:13:35 2003
+++ edited/drivers/usb/core/hcd.h       Fri Aug 29 18:06:37 2003
@@ -73,6 +73,7 @@
         * hardware info/state
         */
        struct hc_driver        *driver;        /* hw-specific hooks */
+       unsigned                saw_irq : 1;
        int                     irq;            /* irq allocated */
        void                    *regs;          /* device memory/io */
        struct device           *controller;    /* handle to hardware */
@@ -89,13 +90,11 @@
 
        int                     state;
 #      define  __ACTIVE                0x01
-#      define  __SLEEPY                0x02
 #      define  __SUSPEND               0x04
 #      define  __TRANSIENT             0x80
 
 #      define  USB_STATE_HALT          0
 #      define  USB_STATE_RUNNING       (__ACTIVE)
-#      define  USB_STATE_READY         (__ACTIVE|__SLEEPY)
 #      define  USB_STATE_QUIESCING     (__SUSPEND|__TRANSIENT|__ACTIVE)
 #      define  USB_STATE_RESUMING      (__SUSPEND|__TRANSIENT)
 #      define  USB_STATE_SUSPENDED     (__SUSPEND)
--- 1.57/drivers/usb/host/ehci-hcd.c    Thu Jul 31 07:25:14 2003
+++ edited/drivers/usb/host/ehci-hcd.c  Fri Aug 29 18:21:44 2003
@@ -232,7 +232,6 @@
                ehci->hcd.state = USB_STATE_HALT;
                return;
        }
-       ehci->hcd.state = USB_STATE_READY;
 }
 
 /*-------------------------------------------------------------------------*/
@@ -482,7 +481,7 @@
        ehci->reboot_notifier.notifier_call = ehci_reboot;
        register_reboot_notifier (&ehci->reboot_notifier);
 
-       ehci->hcd.state = USB_STATE_READY;
+       ehci->hcd.state = USB_STATE_RUNNING;
        writel (FLAG_CF, &ehci->regs->configured_flag);
        readl (&ehci->regs->command);   /* unblock posted write */
 
@@ -626,7 +625,7 @@
        /* resume HC and each port */
 // restore pci FLADJ value
        // khubd and drivers will set HC running, if needed;
-       hcd->state = USB_STATE_READY;
+       hcd->state = USB_STATE_RUNNING;
        // FIXME Philips/Intel/... etc don't really have a "READY"
        // state ... turn on CMD_RUN too
        for (i = 0; i < ports; i++) {
--- 1.46/drivers/usb/host/ohci-hcd.c    Thu Jul 31 13:51:23 2003
+++ edited/drivers/usb/host/ohci-hcd.c  Fri Aug 29 18:23:08 2003
@@ -529,7 +529,7 @@
        /* connect the virtual root hub */
        bus = hcd_to_bus (&ohci->hcd);
        bus->root_hub = udev = usb_alloc_dev (NULL, bus);
-       ohci->hcd.state = USB_STATE_READY;
+       ohci->hcd.state = USB_STATE_RUNNING;
        if (!udev) {
                disable (ohci);
                ohci->hc_control &= ~OHCI_CTRL_HCFS;
--- 1.14/drivers/usb/host/ohci-pci.c    Thu Jul 31 14:36:49 2003
+++ edited/drivers/usb/host/ohci-pci.c  Fri Aug 29 18:24:51 2003
@@ -264,7 +264,7 @@
                        if (ohci->ed_bulktail)
                                ohci->hc_control |= OHCI_CTRL_BLE;
                }
-               hcd->state = USB_STATE_READY;
+               hcd->state = USB_STATE_RUNNING;
                writel (ohci->hc_control, &ohci->regs->control);
 
                /* trigger a start-frame interrupt (why?) */
--- 1.40/drivers/usb/host/uhci-hcd.c    Wed Aug  6 04:52:20 2003
+++ edited/drivers/usb/host/uhci-hcd.c  Fri Aug 29 18:29:09 2003
@@ -2099,7 +2099,7 @@
        uhci->state_end = jiffies + HZ;
        outw(USBCMD_RS | USBCMD_CF | USBCMD_MAXP, io_addr + USBCMD);
 
-        uhci->hcd.state = USB_STATE_READY;
+        uhci->hcd.state = USB_STATE_RUNNING;
 }
 
 /*
@@ -2446,7 +2446,7 @@
                reset_hc(uhci);
                start_hc(uhci);
        }
-       uhci->hcd.state = USB_STATE_READY;
+       uhci->hcd.state = USB_STATE_RUNNING;
        return 0;
 }
 #endif

Reply via email to