Fyi.

-----Original Message-----
From: Christopher Hoover [mailto:[EMAIL PROTECTED]] 
Sent: Wednesday, June 05, 2002 2:48 PM
To: [EMAIL PROTECTED]
Subject: [PATCH] ush-ohci fixes




Move iounmap from core to bus glue support (pci needs to iounamp,
sa-1111 does not).

Pickup up fix for urb->next lossage.

Fix hc_reset not to oops on bogus pci_dev.

Christopher Hoover
mailto:[EMAIL PROTECTED]
mailto:[EMAIL PROTECTED]

PATCH FOLLOWS
KernelVersion: 2.5.18-rmk1
diff -X ../dontdiff.txt -Naur
linux-2.5.18-rmk1/drivers/usb/host/usb-ohci.c
linux-2.5.18-rmk1-ch1/drivers/usb/host/usb-ohci.c
--- linux-2.5.18-rmk1/drivers/usb/host/usb-ohci.c       Wed May 29
10:47:48 2002
+++ linux-2.5.18-rmk1-ch1/drivers/usb/host/usb-ohci.c   Tue Jun  4
18:16:50 2002
@@ -66,7 +66,12 @@
 #include <linux/timer.h>
 #include <linux/list.h>
 #include <linux/interrupt.h>  /* for in_interrupt() */
-#undef DEBUG
+
+#ifdef CONFIG_USB_DEBUG
+#      define DEBUG
+#else
+#      undef DEBUG
+#endif
 #include <linux/usb.h>
 
 #include <asm/io.h>
@@ -96,7 +101,7 @@
 #define OHCI_UNLINK_TIMEOUT    (HZ / 10)
 
 static LIST_HEAD (ohci_hcd_list);
-static spinlock_t usb_ed_lock = SPIN_LOCK_UNLOCKED;
+spinlock_t usb_ed_lock = SPIN_LOCK_UNLOCKED;
 
 
 
/*----------------------------------------------------------------------
---*/
@@ -455,7 +460,7 @@
 static int sohci_return_urb (struct ohci *hc, struct urb * urb)  {
        urb_priv_t * urb_priv = urb->hcpriv;
-       struct urb * urbt;
+       struct urb * urbt = NULL;
        unsigned long flags;
        int i;
        
@@ -489,7 +494,7 @@
                        break;
                        
                case PIPE_ISOCHRONOUS:
-                       for (urbt = urb->next; urbt && (urbt != urb);
urbt = urbt->next);
+                       // for (urbt = urb->next; urbt && (urbt != urb);
urbt = urbt->next);
                        if (urbt) { /* send the reply and requeue URB */

                                pci_unmap_single (hc->ohci_dev,
                                        urb_priv->td [0]->data_dma,
@@ -1519,7 +1524,7 @@
 /* replies to the request have to be on a FIFO basis so
  * we reverse the reversed done-list */
  
-static td_t * dl_reverse_done_list (ohci_t * ohci)
+td_t * dl_reverse_done_list (ohci_t * ohci)
 {
        __u32 td_list_hc;
        td_t * td_rev = NULL;
@@ -1667,7 +1672,7 @@
 
 /* td done list */
 
-static void dl_done_list (ohci_t * ohci, td_t * td_list)
+void dl_done_list (ohci_t * ohci, td_t * td_list)
 {
        td_t * td_list_next = NULL;
        ed_t * ed;
@@ -2138,7 +2143,7 @@
 
 /* reset the HC and BUS */
 
-static int hc_reset (ohci_t * ohci)
+int hc_reset (ohci_t * ohci)
 {
        int timeout = 30;
        int smm_timeout = 50; /* 0,5 sec */
@@ -2395,7 +2400,11 @@
                return NULL;
        }
        ohci->bus->hcpriv = (void *) ohci;
+#ifdef CONFIG_PCI
        ohci->bus->bus_name = dev->slot_name;
+#else
+       ohci->bus->bus_name = "ohci-hc";
+#endif
 
        return ohci;
 } 
@@ -2434,9 +2443,6 @@
 
        ohci_mem_cleanup (ohci);
     
-       /* unmap the IO address space */
-       iounmap (ohci->regs);
-
        pci_free_consistent (ohci->ohci_dev, sizeof *ohci->hcca,
                ohci->hcca, ohci->hcca_dma);
        kfree (ohci);
@@ -2529,3 +2535,7 @@
 EXPORT_SYMBOL(hc_add_ohci);
 EXPORT_SYMBOL(hc_remove_ohci);
 EXPORT_SYMBOL(hc_start);
+EXPORT_SYMBOL(hc_reset);
+EXPORT_SYMBOL(dl_done_list); EXPORT_SYMBOL(dl_reverse_done_list);
+EXPORT_SYMBOL(usb_ed_lock);
diff -X ../dontdiff.txt -Naur
linux-2.5.18-rmk1/drivers/usb/host/usb-ohci-pci.c
linux-2.5.18-rmk1-ch1/drivers/usb/host/usb-ohci-pci.c
--- linux-2.5.18-rmk1/drivers/usb/host/usb-ohci-pci.c   Wed May 29
10:47:48 2002
+++ linux-2.5.18-rmk1-ch1/drivers/usb/host/usb-ohci-pci.c       Tue Jun
4 12:01:21 2002
@@ -9,6 +9,7 @@
 #undef DEBUG
 #include <linux/usb.h>
 
+#include "../core/hcd.h"
 #include "usb-ohci.h"
 
 #ifdef CONFIG_PMAC_PBOOK
@@ -120,12 +121,14 @@
 {
        unsigned long mem_resource, mem_len;
        void *mem_base;
+       int status;
 
        if (pci_enable_device(dev) < 0)
                return -ENODEV;
 
         if (!dev->irq) {
                err("found OHCI device with no IRQ assigned. check BIOS
settings!");
+               pci_disable_device (dev);
                return -ENODEV;
         }
        
@@ -134,20 +137,28 @@
        mem_len = pci_resource_len(dev, 0);
        if (!request_mem_region (mem_resource, mem_len,
ohci_pci_driver.name)) {
                dbg ("controller already in use");
+               pci_disable_device (dev);
                return -EBUSY;
        }
 
        mem_base = ioremap_nocache (mem_resource, mem_len);
        if (!mem_base) {
                err("Error mapping OHCI memory");
-               free_mem_region(mem_resource, mem_len);
+               release_mem_region(mem_resource, mem_len);
+               pci_disable_device (dev);
                return -EFAULT;
        }
 
        /* controller writes into our memory */
        pci_set_master (dev);
 
-       return hc_found_ohci (dev, dev->irq, mem_base, id);
+       status = hc_found_ohci (dev, dev->irq, mem_base, id);
+       if (status < 0) {
+               iounmap (mem_base);
+               release_mem_region(mem_resource, mem_len);
+               pci_disable_device (dev);
+       }
+       return status;
 } 
 
 
/*----------------------------------------------------------------------
---*/
@@ -170,6 +181,9 @@
 
        hc_remove_ohci(ohci);
 
+       /* unmap the IO address space */
+       iounmap (ohci->regs);
+
        release_mem_region (pci_resource_start (dev, 0),
pci_resource_len (dev, 0));  }
 
@@ -431,3 +445,4 @@
 module_init (ohci_hcd_init);
 module_exit (ohci_hcd_cleanup);
 
+MODULE_LICENSE("GPL");
diff -X ../dontdiff.txt -Naur
linux-2.5.18-rmk1/drivers/usb/host/usb-ohci-sa1111.c
linux-2.5.18-rmk1-ch1/drivers/usb/host/usb-ohci-sa1111.c
--- linux-2.5.18-rmk1/drivers/usb/host/usb-ohci-sa1111.c        Wed May
29 10:47:48 2002
+++ linux-2.5.18-rmk1-ch1/drivers/usb/host/usb-ohci-sa1111.c    Tue Jun
4 18:20:14 2002
@@ -12,6 +12,7 @@
 #include <linux/interrupt.h>
 #include <linux/slab.h>
 #include <linux/usb.h>
+#include <linux/pci.h>
 #include <linux/errno.h>
 
 #include <asm/hardware.h>
@@ -27,6 +28,8 @@
 hc_add_ohci(struct pci_dev *dev, int irq, void *membase, unsigned long
flags,
            ohci_t **ohci, const char *name, const char *slot_name);
extern void hc_remove_ohci(ohci_t *ohci);
+extern int hc_start (ohci_t * ohci, struct device *parent_dev);
+
 
 static ohci_t *sa1111_ohci;
 
@@ -34,6 +37,15 @@
 {
        unsigned int usb_rst = 0;
 
+       printk(KERN_DEBUG __FILE__ 
+              ": starting SA-1111 OHCI USB Controller\n");
+
+#ifdef CONFIG_SA1100_BADGE4
+       if (machine_is_badge4())
+               /* power the bus */
+               badge4_set_5V(BADGE4_5V_USB, 1);
+#endif
+
        if (machine_is_xp860() ||
            machine_has_neponset() ||
            machine_is_pfs168() ||
@@ -55,6 +67,28 @@
        USB_RESET = usb_rst;
 }
 
+static void __exit sa1111_ohci_unconfigure(void)
+{
+       printk(KERN_DEBUG __FILE__ 
+              ": stopping SA-1111 OHCI USB Controller\n");
+
+       /*
+        * Put the USB host controller into reset.
+        */
+       USB_RESET |= USB_RESET_FORCEIFRESET | USB_RESET_FORCEHCRESET;
+
+       /*
+        * Stop the USB clock.
+        */
+       SKPCR &= ~SKPCR_UCLKEN;
+
+#ifdef CONFIG_SA1100_BADGE4
+       if (machine_is_badge4())
+               badge4_set_5V(BADGE4_5V_USB, 0);
+#endif
+}
+
+
 static int __init sa1111_ohci_init(void)
 {
        int ret;
@@ -65,66 +99,56 @@
        /*
         * Request memory resources.
         */
-//     if (!request_mem_region(_USB_OHCI_OP_BASE, _USB_EXTENT,
"usb-ohci"))
-//             return -EBUSY;
+       if (!request_mem_region(_USB_OHCI_OP_BASE, _USB_EXTENT,
"usb-ohci"))
+               return -EBUSY;
 
        sa1111_ohci_configure();
 
        /*
         * Initialise the generic OHCI driver.
         */
-       ret = hc_add_ohci((struct pci_dev *)1, NIRQHCIM,
+       sa1111_ohci = 0;
+       ret = hc_add_ohci(SA1111_FAKE_PCIDEV, NIRQHCIM,
                          (void *)&USB_OHCI_OP_BASE, 0, &sa1111_ohci,
                          "usb-ohci", "sa1111");
 
-       if (ret == 0) {
-               if (hc_start (sa1111_ohci, &sa1111->dev) < 0) {
-                       err ("can't start usb-%s",
sa1111_ohci->slot_name);
-                       hc_remove_ohci (sa1111_ohci);
-                       return -EBUSY;
-               }
+       if (ret || !sa1111_ohci) {
+               sa1111_ohci_unconfigure();
+               release_mem_region(_USB_OHCI_OP_BASE, _USB_EXTENT);
+               return -EBUSY;
+       }
+
+       if (hc_start (sa1111_ohci, &sa1111->dev) < 0) {
+               err ("can't start usb-%s", sa1111_ohci->slot_name);
+               hc_remove_ohci (sa1111_ohci);
+               sa1111_ohci_unconfigure();
+               release_mem_region(_USB_OHCI_OP_BASE, _USB_EXTENT);
+               return -EBUSY;
+       }
 
 #ifdef DEBUG
-               ohci_dump (ohci, 1);
+       ohci_dump (sa1111_ohci, 1);
 #endif
-#ifdef CONFIG_SA1100_BADGE4
-               if (machine_is_badge4()) {
-                       /* found the controller, so now power the bus */
-                       badge4_set_5V(BADGE4_5V_USB, 1);
-               }
-#endif
-       }
-//     else
-//             release_mem_region(_USB_OHCI_OP_BASE, _USB_EXTENT);
 
-       return ret;
+       return 0;
 }
 
 static void __exit sa1111_ohci_exit(void)
 {
-       hc_remove_ohci(sa1111_ohci);
+       printk(KERN_DEBUG __FUNCTION__ ": cleaning up\n");
 
-       /*
-        * Put the USB host controller into reset.
-        */
-       USB_RESET |= USB_RESET_FORCEIFRESET | USB_RESET_FORCEHCRESET;
-
-       /*
-        * Stop the USB clock.
-        */
-       SKPCR &= ~SKPCR_UCLKEN;
+       if (sa1111_ohci) {
+               hc_remove_ohci(sa1111_ohci);
+               sa1111_ohci = 0;
+       }
 
-       /*
-        * Release memory resources.
-        */
-//     release_mem_region(_USB_OHCI_OP_BASE, _USB_EXTENT);
+       sa1111_ohci_unconfigure();
+       release_mem_region(_USB_OHCI_OP_BASE, _USB_EXTENT);
 
-#ifdef CONFIG_SA1100_BADGE4
-       if (machine_is_badge4()) {
-               badge4_set_5V(BADGE4_5V_USB, 0);
-       }
-#endif
+       printk(KERN_DEBUG __FUNCTION__ ": exiting\n");
 }
 
 module_init(sa1111_ohci_init);
 module_exit(sa1111_ohci_exit);
+
+MODULE_LICENSE("GPL");


_______________________________________________________________

Don't miss the 2002 Sprint PCS Application Developer's Conference
August 25-28 in Las Vegas -- http://devcon.sprintpcs.com/adp/index.cfm

_______________________________________________
[EMAIL PROTECTED]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to