Merge master.kernel.org:/pub/scm/linux/kernel/git/acme/net-2.6
[pandora-kernel.git] / drivers / scsi / dpt_i2o.c
index 6252b9d..7b3bd34 100644 (file)
@@ -46,7 +46,6 @@ MODULE_DESCRIPTION("Adaptec I2O RAID Driver");
 
 #include <linux/stat.h>
 #include <linux/slab.h>                /* for kmalloc() */
-#include <linux/config.h>      /* for CONFIG_PCI */
 #include <linux/pci.h>         /* for PCI support */
 #include <linux/proc_fs.h>
 #include <linux/blkdev.h>
@@ -57,10 +56,12 @@ MODULE_DESCRIPTION("Adaptec I2O RAID Driver");
 #include <linux/reboot.h>
 #include <linux/spinlock.h>
 #include <linux/smp_lock.h>
+#include <linux/dma-mapping.h>
 
 #include <linux/timer.h>
 #include <linux/string.h>
 #include <linux/ioport.h>
+#include <linux/mutex.h>
 
 #include <asm/processor.h>     /* for boot_cpu_data */
 #include <asm/pgtable.h>
@@ -106,7 +107,7 @@ static dpt_sig_S DPTI_sig = {
  *============================================================================
  */
 
-static DECLARE_MUTEX(adpt_configuration_lock);
+static DEFINE_MUTEX(adpt_configuration_lock);
 
 static struct i2o_sys_tbl *sys_tbl = NULL;
 static int sys_tbl_ind = 0;
@@ -183,7 +184,7 @@ static int adpt_detect(struct scsi_host_template* sht)
        PINFO("Detecting Adaptec I2O RAID controllers...\n");
 
         /* search for all Adatpec I2O RAID cards */
-       while ((pDev = pci_find_device( PCI_DPT_VENDOR_ID, PCI_ANY_ID, pDev))) {
+       while ((pDev = pci_get_device( PCI_DPT_VENDOR_ID, PCI_ANY_ID, pDev))) {
                if(pDev->device == PCI_DPT_DEVICE_ID ||
                   pDev->device == PCI_DPT_RAPTOR_DEVICE_ID){
                        if(adpt_install_hba(sht, pDev) ){
@@ -191,8 +192,11 @@ static int adpt_detect(struct scsi_host_template* sht)
                                PERROR("Will not try to detect others.\n");
                                return hba_count-1;
                        }
+                       pci_dev_get(pDev);
                }
        }
+       if (pDev)
+               pci_dev_put(pDev);
 
        /* In INIT state, Activate IOPs */
        for (pHba = hba_chain; pHba; pHba = pHba->next) {
@@ -537,13 +541,13 @@ static int adpt_proc_info(struct Scsi_Host *host, char *buffer, char **start, of
         */
 
        // Find HBA (host bus adapter) we are looking for
-       down(&adpt_configuration_lock);
+       mutex_lock(&adpt_configuration_lock);
        for (pHba = hba_chain; pHba; pHba = pHba->next) {
                if (pHba->host == host) {
                        break;  /* found adapter */
                }
        }
-       up(&adpt_configuration_lock);
+       mutex_unlock(&adpt_configuration_lock);
        if (pHba == NULL) {
                return 0;
        }
@@ -898,9 +902,15 @@ static int adpt_install_hba(struct scsi_host_template* sht, struct pci_dev* pDev
        if(pci_enable_device(pDev)) {
                return -EINVAL;
        }
+
+       if (pci_request_regions(pDev, "dpt_i2o")) {
+               PERROR("dpti: adpt_config_hba: pci request region failed\n");
+               return -EINVAL;
+       }
+
        pci_set_master(pDev);
-       if (pci_set_dma_mask(pDev, 0xffffffffffffffffULL) &&
-           pci_set_dma_mask(pDev, 0xffffffffULL))
+       if (pci_set_dma_mask(pDev, DMA_64BIT_MASK) &&
+           pci_set_dma_mask(pDev, DMA_32BIT_MASK))
                return -EINVAL;
 
        base_addr0_phys = pci_resource_start(pDev,0);
@@ -923,10 +933,6 @@ static int adpt_install_hba(struct scsi_host_template* sht, struct pci_dev* pDev
                raptorFlag = TRUE;
        }
 
-       if (pci_request_regions(pDev, "dpt_i2o")) {
-               PERROR("dpti: adpt_config_hba: pci request region failed\n");
-               return -EINVAL;
-       }
        base_addr_virt = ioremap(base_addr0_phys,hba_map0_area_size);
        if (!base_addr_virt) {
                pci_release_regions(pDev);
@@ -958,7 +964,7 @@ static int adpt_install_hba(struct scsi_host_template* sht, struct pci_dev* pDev
        }
        memset(pHba, 0, sizeof(adpt_hba));
 
-       down(&adpt_configuration_lock);
+       mutex_lock(&adpt_configuration_lock);
 
        if(hba_chain != NULL){
                for(p = hba_chain; p->next; p = p->next);
@@ -971,7 +977,7 @@ static int adpt_install_hba(struct scsi_host_template* sht, struct pci_dev* pDev
        sprintf(pHba->name, "dpti%d", hba_count);
        hba_count++;
        
-       up(&adpt_configuration_lock);
+       mutex_unlock(&adpt_configuration_lock);
 
        pHba->pDev = pDev;
        pHba->base_addr_phys = base_addr0_phys;
@@ -1005,7 +1011,7 @@ static int adpt_install_hba(struct scsi_host_template* sht, struct pci_dev* pDev
                printk(KERN_INFO"     BAR1 %p - size= %x\n",msg_addr_virt,hba_map1_area_size);
        }
 
-       if (request_irq (pDev->irq, adpt_isr, SA_SHIRQ, pHba->name, pHba)) {
+       if (request_irq (pDev->irq, adpt_isr, IRQF_SHARED, pHba->name, pHba)) {
                printk(KERN_ERR"%s: Couldn't register IRQ %d\n", pHba->name, pDev->irq);
                adpt_i2o_delete_hba(pHba);
                return -EINVAL;
@@ -1027,7 +1033,7 @@ static void adpt_i2o_delete_hba(adpt_hba* pHba)
        struct adpt_device* pNext;
 
 
-       down(&adpt_configuration_lock);
+       mutex_lock(&adpt_configuration_lock);
        // scsi_unregister calls our adpt_release which
        // does a quiese
        if(pHba->host){
@@ -1046,7 +1052,7 @@ static void adpt_i2o_delete_hba(adpt_hba* pHba)
        }
 
        hba_count--;
-       up(&adpt_configuration_lock);
+       mutex_unlock(&adpt_configuration_lock);
 
        iounmap(pHba->base_addr_virt);
        pci_release_regions(pHba->pDev);
@@ -1072,6 +1078,7 @@ static void adpt_i2o_delete_hba(adpt_hba* pHba)
                        }
                }
        }
+       pci_dev_put(pHba->pDev);
        kfree(pHba);
 
        if(hba_count <= 0){
@@ -1549,7 +1556,7 @@ static int adpt_i2o_parse_lct(adpt_hba* pHba)
  
 static int adpt_i2o_install_device(adpt_hba* pHba, struct i2o_device *d)
 {
-       down(&adpt_configuration_lock);
+       mutex_lock(&adpt_configuration_lock);
        d->controller=pHba;
        d->owner=NULL;
        d->next=pHba->devices;
@@ -1560,7 +1567,7 @@ static int adpt_i2o_install_device(adpt_hba* pHba, struct i2o_device *d)
        pHba->devices=d;
        *d->dev_name = 0;
 
-       up(&adpt_configuration_lock);
+       mutex_unlock(&adpt_configuration_lock);
        return 0;
 }
 
@@ -1575,24 +1582,24 @@ static int adpt_open(struct inode *inode, struct file *file)
        if (minor >= hba_count) {
                return -ENXIO;
        }
-       down(&adpt_configuration_lock);
+       mutex_lock(&adpt_configuration_lock);
        for (pHba = hba_chain; pHba; pHba = pHba->next) {
                if (pHba->unit == minor) {
                        break;  /* found adapter */
                }
        }
        if (pHba == NULL) {
-               up(&adpt_configuration_lock);
+               mutex_unlock(&adpt_configuration_lock);
                return -ENXIO;
        }
 
 //     if(pHba->in_use){
-       //      up(&adpt_configuration_lock);
+       //      mutex_unlock(&adpt_configuration_lock);
 //             return -EBUSY;
 //     }
 
        pHba->in_use = 1;
-       up(&adpt_configuration_lock);
+       mutex_unlock(&adpt_configuration_lock);
 
        return 0;
 }
@@ -1606,13 +1613,13 @@ static int adpt_close(struct inode *inode, struct file *file)
        if (minor >= hba_count) {
                return -ENXIO;
        }
-       down(&adpt_configuration_lock);
+       mutex_lock(&adpt_configuration_lock);
        for (pHba = hba_chain; pHba; pHba = pHba->next) {
                if (pHba->unit == minor) {
                        break;  /* found adapter */
                }
        }
-       up(&adpt_configuration_lock);
+       mutex_unlock(&adpt_configuration_lock);
        if (pHba == NULL) {
                return -ENXIO;
        }
@@ -1910,13 +1917,13 @@ static int adpt_ioctl(struct inode *inode, struct file *file, uint cmd,
        if (minor >= DPTI_MAX_HBA){
                return -ENXIO;
        }
-       down(&adpt_configuration_lock);
+       mutex_lock(&adpt_configuration_lock);
        for (pHba = hba_chain; pHba; pHba = pHba->next) {
                if (pHba->unit == minor) {
                        break;  /* found adapter */
                }
        }
-       up(&adpt_configuration_lock);
+       mutex_unlock(&adpt_configuration_lock);
        if(pHba == NULL){
                return -ENXIO;
        }