USB: ehci-dbgp,ehci: Allow early or late use of the dbgp device
Jason Wessel [Thu, 20 Aug 2009 20:39:54 +0000 (15:39 -0500)]
If the EHCI debug port is initialized and in use, the EHCI host
controller driver must follow two rules.

1) If the EHCI host driver issues a controller reset, the debug
   controller driver re-initialization must get called after the reset
   is completed.

2) The EHCI host driver should ignore any requests to the physical
   EHCI debug port when the EHCI debug port is in use.

The code to check for the debug port was moved from ehci_pci_reinit()
to ehci_pci_setup because it must get called prior to ehci_reset()
which will clear the debug port registers.

Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: dbrownell@users.sourceforge.net
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

drivers/usb/early/ehci-dbgp.c
drivers/usb/host/ehci-hcd.c
drivers/usb/host/ehci-hub.c
drivers/usb/host/ehci-pci.c
include/linux/usb/ehci_def.h

index 06e05ea..b88cb65 100644 (file)
@@ -933,3 +933,26 @@ struct console early_dbgp_console = {
        .flags =        CON_PRINTBUFFER,
        .index =        -1,
 };
+
+int dbgp_reset_prep(void)
+{
+       u32 ctrl;
+
+       dbgp_not_safe = 1;
+       if (!ehci_debug)
+               return 0;
+
+       if (early_dbgp_console.index != -1 &&
+               !(early_dbgp_console.flags & CON_BOOT))
+               return 1;
+       /* This means the console is not initialized, or should get
+        * shutdown so as to allow for reuse of the usb device, which
+        * means it is time to shutdown the usb debug port. */
+       ctrl = readl(&ehci_debug->control);
+       if (ctrl & DBGP_ENABLED) {
+               ctrl &= ~(DBGP_CLAIM);
+               writel(ctrl, &ehci_debug->control);
+       }
+       return 0;
+}
+EXPORT_SYMBOL_GPL(dbgp_reset_prep);
index 4f89d7f..9835e07 100644 (file)
@@ -240,6 +240,11 @@ static int ehci_reset (struct ehci_hcd *ehci)
        int     retval;
        u32     command = ehci_readl(ehci, &ehci->regs->command);
 
+       /* If the EHCI debug controller is active, special care must be
+        * taken before and after a host controller reset */
+       if (ehci->debug && !dbgp_reset_prep())
+               ehci->debug = NULL;
+
        command |= CMD_RESET;
        dbg_cmd (ehci, "reset", command);
        ehci_writel(ehci, command, &ehci->regs->command);
@@ -260,6 +265,9 @@ static int ehci_reset (struct ehci_hcd *ehci)
        if (ehci_is_TDI(ehci))
                tdi_reset (ehci);
 
+       if (ehci->debug)
+               dbgp_external_startup();
+
        return retval;
 }
 
index 818647c..6b5e4d1 100644 (file)
@@ -855,6 +855,15 @@ static int ehci_hub_control (
        case SetPortFeature:
                selector = wIndex >> 8;
                wIndex &= 0xff;
+               if (unlikely(ehci->debug)) {
+                       /* If the debug port is active any port
+                        * feature requests should get denied */
+                       if (wIndex == HCS_DEBUG_PORT(ehci->hcs_params) &&
+                           (readl(&ehci->debug->control) & DBGP_ENABLED)) {
+                               retval = -ENODEV;
+                               goto error_exit;
+                       }
+               }
                if (!wIndex || wIndex > ports)
                        goto error;
                wIndex--;
@@ -951,6 +960,7 @@ error:
                /* "stall" on error */
                retval = -EPIPE;
        }
+error_exit:
        spin_unlock_irqrestore (&ehci->lock, flags);
        return retval;
 }
index a88ad51..378861b 100644 (file)
 /* called after powerup, by probe or system-pm "wakeup" */
 static int ehci_pci_reinit(struct ehci_hcd *ehci, struct pci_dev *pdev)
 {
-       u32                     temp;
        int                     retval;
 
-       /* optional debug port, normally in the first BAR */
-       temp = pci_find_capability(pdev, 0x0a);
-       if (temp) {
-               pci_read_config_dword(pdev, temp, &temp);
-               temp >>= 16;
-               if ((temp & (3 << 13)) == (1 << 13)) {
-                       temp &= 0x1fff;
-                       ehci->debug = ehci_to_hcd(ehci)->regs + temp;
-                       temp = ehci_readl(ehci, &ehci->debug->control);
-                       ehci_info(ehci, "debug port %d%s\n",
-                               HCS_DEBUG_PORT(ehci->hcs_params),
-                               (temp & DBGP_ENABLED)
-                                       ? " IN USE"
-                                       : "");
-                       if (!(temp & DBGP_ENABLED))
-                               ehci->debug = NULL;
-               }
-       }
-
        /* we expect static quirk code to handle the "extended capabilities"
         * (currently just BIOS handoff) allowed starting with EHCI 0.96
         */
@@ -195,6 +175,25 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
                break;
        }
 
+       /* optional debug port, normally in the first BAR */
+       temp = pci_find_capability(pdev, 0x0a);
+       if (temp) {
+               pci_read_config_dword(pdev, temp, &temp);
+               temp >>= 16;
+               if ((temp & (3 << 13)) == (1 << 13)) {
+                       temp &= 0x1fff;
+                       ehci->debug = ehci_to_hcd(ehci)->regs + temp;
+                       temp = ehci_readl(ehci, &ehci->debug->control);
+                       ehci_info(ehci, "debug port %d%s\n",
+                               HCS_DEBUG_PORT(ehci->hcs_params),
+                               (temp & DBGP_ENABLED)
+                                       ? " IN USE"
+                                       : "");
+                       if (!(temp & DBGP_ENABLED))
+                               ehci->debug = NULL;
+               }
+       }
+
        ehci_reset(ehci);
 
        /* at least the Genesys GL880S needs fixup here */
index 07851e0..1909d92 100644 (file)
@@ -179,6 +179,16 @@ extern struct console early_dbgp_console;
 #ifdef CONFIG_EARLY_PRINTK_DBGP
 /* Call backs from ehci host driver to ehci debug driver */
 extern int dbgp_external_startup(void);
+extern int dbgp_reset_prep(void);
+#else
+static inline int dbgp_reset_prep(void)
+{
+       return 1;
+}
+static inline int dbgp_external_startup(void)
+{
+       return -1;
+}
 #endif
 
 #endif /* __LINUX_USB_EHCI_DEF_H */