Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / drivers / scsi / aic7xxx / aic79xx_osm_pci.c
index 91daf0c..ebbf7e4 100644 (file)
@@ -92,27 +92,34 @@ struct pci_driver aic79xx_pci_driver = {
 static void
 ahd_linux_pci_dev_remove(struct pci_dev *pdev)
 {
-       struct ahd_softc *ahd;
-       u_long l;
+       struct ahd_softc *ahd = pci_get_drvdata(pdev);
+       u_long s;
 
-       /*
-        * We should be able to just perform
-        * the free directly, but check our
-        * list for extra sanity.
-        */
-       ahd_list_lock(&l);
-       ahd = ahd_find_softc((struct ahd_softc *)pci_get_drvdata(pdev));
-       if (ahd != NULL) {
-               u_long s;
-
-               TAILQ_REMOVE(&ahd_tailq, ahd, links);
-               ahd_list_unlock(&l);
-               ahd_lock(ahd, &s);
-               ahd_intr_enable(ahd, FALSE);
-               ahd_unlock(ahd, &s);
-               ahd_free(ahd);
-       } else
-               ahd_list_unlock(&l);
+       if (ahd->platform_data && ahd->platform_data->host)
+                       scsi_remove_host(ahd->platform_data->host);
+
+       ahd_lock(ahd, &s);
+       ahd_intr_enable(ahd, FALSE);
+       ahd_unlock(ahd, &s);
+       ahd_free(ahd);
+}
+
+static void
+ahd_linux_pci_inherit_flags(struct ahd_softc *ahd)
+{
+       struct pci_dev *pdev = ahd->dev_softc, *master_pdev;
+       unsigned int master_devfn = PCI_DEVFN(PCI_SLOT(pdev->devfn), 0);
+
+       master_pdev = pci_get_slot(pdev->bus, master_devfn);
+       if (master_pdev) {
+               struct ahd_softc *master = pci_get_drvdata(master_pdev);
+               if (master) {
+                       ahd->flags &= ~AHD_BIOS_ENABLED;
+                       ahd->flags |= master->flags & AHD_BIOS_ENABLED;
+               } else
+                       printk(KERN_ERR "aic79xx: no multichannel peer found!\n");
+               pci_dev_put(master_pdev);
+       }
 }
 
 static int
@@ -125,22 +132,6 @@ ahd_linux_pci_dev_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
        char            *name;
        int              error;
 
-       /*
-        * Some BIOSen report the same device multiple times.
-        */
-       TAILQ_FOREACH(ahd, &ahd_tailq, links) {
-               struct pci_dev *probed_pdev;
-
-               probed_pdev = ahd->dev_softc;
-               if (probed_pdev->bus->number == pdev->bus->number
-                && probed_pdev->devfn == pdev->devfn)
-                       break;
-       }
-       if (ahd != NULL) {
-               /* Skip duplicate. */
-               return (-ENODEV);
-       }
-
        pci = pdev;
        entry = ahd_find_pci_device(pci);
        if (entry == NULL)
@@ -177,15 +168,12 @@ ahd_linux_pci_dev_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
                if (memsize >= 0x8000000000ULL
                 && pci_set_dma_mask(pdev, DMA_64BIT_MASK) == 0) {
                        ahd->flags |= AHD_64BIT_ADDRESSING;
-                       ahd->platform_data->hw_dma_mask = DMA_64BIT_MASK;
                } else if (memsize > 0x80000000
                        && pci_set_dma_mask(pdev, mask_39bit) == 0) {
                        ahd->flags |= AHD_39BIT_ADDRESSING;
-                       ahd->platform_data->hw_dma_mask = mask_39bit;
                }
        } else {
                pci_set_dma_mask(pdev, DMA_32BIT_MASK);
-               ahd->platform_data->hw_dma_mask = DMA_32BIT_MASK;
        }
        ahd->dev_softc = pci;
        error = ahd_pci_config(ahd, entry);
@@ -193,16 +181,17 @@ ahd_linux_pci_dev_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
                ahd_free(ahd);
                return (-error);
        }
+
+       /*
+        * Second Function PCI devices need to inherit some
+        * * settings from function 0.
+        */
+       if ((ahd->features & AHD_MULTI_FUNC) && PCI_FUNC(pdev->devfn) != 0)
+               ahd_linux_pci_inherit_flags(ahd);
+
        pci_set_drvdata(pdev, ahd);
-       if (aic79xx_detect_complete) {
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
-               ahd_linux_register_host(ahd, &aic79xx_driver_template);
-#else
-               printf("aic79xx: ignoring PCI device found after "
-                      "initialization\n");
-               return (-ENODEV);
-#endif
-       }
+
+       ahd_linux_register_host(ahd, &aic79xx_driver_template);
        return (0);
 }
 
@@ -231,10 +220,10 @@ ahd_linux_pci_reserve_io_regions(struct ahd_softc *ahd, u_long *base,
        *base2 = pci_resource_start(ahd->dev_softc, 3);
        if (*base == 0 || *base2 == 0)
                return (ENOMEM);
-       if (request_region(*base, 256, "aic79xx") == 0)
+       if (!request_region(*base, 256, "aic79xx"))
                return (ENOMEM);
-       if (request_region(*base2, 256, "aic79xx") == 0) {
-               release_region(*base2, 256);
+       if (!request_region(*base2, 256, "aic79xx")) {
+               release_region(*base, 256);
                return (ENOMEM);
        }
        return (0);
@@ -248,7 +237,7 @@ ahd_linux_pci_reserve_mem_region(struct ahd_softc *ahd,
        u_long  start;
        u_long  base_page;
        u_long  base_offset;
-       int     error;
+       int     error = 0;
 
        if (aic79xx_allow_memio == 0)
                return (ENOMEM);
@@ -256,16 +245,15 @@ ahd_linux_pci_reserve_mem_region(struct ahd_softc *ahd,
        if ((ahd->bugs & AHD_PCIX_MMAPIO_BUG) != 0)
                return (ENOMEM);
 
-       error = 0;
        start = pci_resource_start(ahd->dev_softc, 1);
        base_page = start & PAGE_MASK;
        base_offset = start - base_page;
        if (start != 0) {
                *bus_addr = start;
-               if (request_mem_region(start, 0x1000, "aic79xx") == 0)
+               if (!request_mem_region(start, 0x1000, "aic79xx"))
                        error = ENOMEM;
-               if (error == 0) {
-                       *maddr = ioremap_nocache(base_page, base_offset + 256);
+               if (!error) {
+                       *maddr = ioremap_nocache(base_page, base_offset + 512);
                        if (*maddr == NULL) {
                                error = ENOMEM;
                                release_mem_region(start, 0x1000);
@@ -355,7 +343,7 @@ ahd_pci_map_int(struct ahd_softc *ahd)
 
        error = request_irq(ahd->dev_softc->irq, ahd_linux_isr,
                            SA_SHIRQ, "aic79xx", ahd);
-       if (error == 0)
+       if (!error)
                ahd->platform_data->irq = ahd->dev_softc->irq;
        
        return (-error);