]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/scsi/ips.c
Merge branches 'release' and 'throttling-domains' into release
[linux-2.6-omap-h63xx.git] / drivers / scsi / ips.c
index 595a91afca0e9d802f20c7725219276624201ddb..bb152fb9fec7dc4b3260c2b4add978ba4af0e314 100644 (file)
@@ -389,17 +389,17 @@ static struct  pci_device_id  ips_pci_table[] = {
 MODULE_DEVICE_TABLE( pci, ips_pci_table );
 
 static char ips_hot_plug_name[] = "ips";
-   
+
 static int __devinit  ips_insert_device(struct pci_dev *pci_dev, const struct pci_device_id *ent);
 static void __devexit ips_remove_device(struct pci_dev *pci_dev);
-   
+
 static struct pci_driver ips_pci_driver = {
        .name           = ips_hot_plug_name,
        .id_table       = ips_pci_table,
        .probe          = ips_insert_device,
        .remove         = __devexit_p(ips_remove_device),
 };
-           
+
 
 /*
  * Necessary forward function protoypes
@@ -587,7 +587,7 @@ static void
 ips_setup_funclist(ips_ha_t * ha)
 {
 
-       /*                                
+       /*
         * Setup Functions
         */
        if (IPS_IS_MORPHEUS(ha) || IPS_IS_MARCO(ha)) {
@@ -702,10 +702,6 @@ ips_release(struct Scsi_Host *sh)
        /* free extra memory */
        ips_free(ha);
 
-       /* Free I/O Region */
-       if (ha->io_addr)
-               release_region(ha->io_addr, ha->io_len);
-
        /* free IRQ */
        free_irq(ha->pcidev->irq, ha);
 
@@ -1313,7 +1309,7 @@ ips_intr_copperhead(ips_ha_t * ha)
                        cstatus.value = (*ha->func.statupd) (ha);
 
                if (cstatus.fields.command_id > (IPS_MAX_CMDS - 1)) {
-                       /* Spurious Interupt ? */
+                       /* Spurious Interrupt ? */
                        continue;
                }
 
@@ -2081,7 +2077,7 @@ ips_host_info(ips_ha_t * ha, char *ptr, off_t offset, int len)
     /* That keeps everything happy for "text" operations on the proc file.                    */
 
        if (le32_to_cpu(ha->nvram->signature) == IPS_NVRAM_P5_SIG) {
-        if (ha->nvram->bios_low[3] == 0) { 
+       if (ha->nvram->bios_low[3] == 0) {
             copy_info(&info,
                                  "\tBIOS Version                      : %c%c%c%c%c%c%c\n",
                                  ha->nvram->bios_high[0], ha->nvram->bios_high[1],
@@ -2740,8 +2736,6 @@ ips_next(ips_ha_t * ha, int intr)
                SC->result = DID_OK;
                SC->host_scribble = NULL;
 
-               memset(SC->sense_buffer, 0, sizeof (SC->sense_buffer));
-
                scb->target_id = SC->device->id;
                scb->lun = SC->device->lun;
                scb->bus = SC->device->channel;
@@ -2780,10 +2774,11 @@ ips_next(ips_ha_t * ha, int intr)
                scb->dcdb.cmd_attribute =
                    ips_command_direction[scb->scsi_cmd->cmnd[0]];
 
-        /* Allow a WRITE BUFFER Command to Have no Data */
-        /* This is Used by Tape Flash Utilites          */
-        if ((scb->scsi_cmd->cmnd[0] == WRITE_BUFFER) && (scb->data_len == 0)) 
-            scb->dcdb.cmd_attribute = 0;                  
+               /* Allow a WRITE BUFFER Command to Have no Data */
+               /* This is Used by Tape Flash Utilites          */
+               if ((scb->scsi_cmd->cmnd[0] == WRITE_BUFFER) &&
+                               (scb->data_len == 0))
+                       scb->dcdb.cmd_attribute = 0;
 
                if (!(scb->dcdb.cmd_attribute & 0x3))
                        scb->dcdb.transfer_length = 0;
@@ -3404,7 +3399,7 @@ ips_map_status(ips_ha_t * ha, ips_scb_t * scb, ips_stat_t * sp)
 
                                /* Restrict access to physical DASD */
                                if (scb->scsi_cmd->cmnd[0] == INQUIRY) {
-                                   ips_scmd_buf_read(scb->scsi_cmd, 
+                                   ips_scmd_buf_read(scb->scsi_cmd,
                                       &inquiryData, sizeof (inquiryData));
                                    if ((inquiryData.DeviceType & 0x1f) == TYPE_DISK) {
                                        errcode = DID_TIME_OUT;
@@ -3438,13 +3433,11 @@ ips_map_status(ips_ha_t * ha, ips_scb_t * scb, ips_stat_t * sp)
                                            (IPS_DCDB_TABLE_TAPE *) & scb->dcdb;
                                        memcpy(scb->scsi_cmd->sense_buffer,
                                               tapeDCDB->sense_info,
-                                              sizeof (scb->scsi_cmd->
-                                                      sense_buffer));
+                                              SCSI_SENSE_BUFFERSIZE);
                                } else {
                                        memcpy(scb->scsi_cmd->sense_buffer,
                                               scb->dcdb.sense_info,
-                                              sizeof (scb->scsi_cmd->
-                                                      sense_buffer));
+                                              SCSI_SENSE_BUFFERSIZE);
                                }
                                device_error = 2;       /* check condition */
                        }
@@ -3824,7 +3817,6 @@ ips_send_cmd(ips_ha_t * ha, ips_scb_t * scb)
                        /* attempted, a Check Condition occurred, and Sense   */
                        /* Data indicating an Invalid CDB OpCode is returned. */
                        sp = (char *) scb->scsi_cmd->sense_buffer;
-                       memset(sp, 0, sizeof (scb->scsi_cmd->sense_buffer));
 
                        sp[0] = 0x70;   /* Error Code               */
                        sp[2] = ILLEGAL_REQUEST;        /* Sense Key 5 Illegal Req. */
@@ -4090,10 +4082,10 @@ ips_chkstatus(ips_ha_t * ha, IPS_STATUS * pstatus)
                        scb->scsi_cmd->result = errcode << 16;
                } else {        /* bus == 0 */
                        /* restrict access to physical drives */
-                       if (scb->scsi_cmd->cmnd[0] == INQUIRY) { 
-                           ips_scmd_buf_read(scb->scsi_cmd, 
+                       if (scb->scsi_cmd->cmnd[0] == INQUIRY) {
+                           ips_scmd_buf_read(scb->scsi_cmd,
                                   &inquiryData, sizeof (inquiryData));
-                           if ((inquiryData.DeviceType & 0x1f) == TYPE_DISK) 
+                           if ((inquiryData.DeviceType & 0x1f) == TYPE_DISK)
                                scb->scsi_cmd->result = DID_TIME_OUT << 16;
                        }
                }               /* else */
@@ -4393,8 +4385,6 @@ ips_free(ips_ha_t * ha)
                        ha->mem_ptr = NULL;
                }
 
-               if (ha->mem_addr)
-                       release_mem_region(ha->mem_addr, ha->mem_len);
                ha->mem_addr = 0;
 
        }
@@ -4661,8 +4651,8 @@ ips_isinit_morpheus(ips_ha_t * ha)
        uint32_t bits;
 
        METHOD_TRACE("ips_is_init_morpheus", 1);
-   
-       if (ips_isintr_morpheus(ha)) 
+
+       if (ips_isintr_morpheus(ha))
            ips_flush_and_reset(ha);
 
        post = readl(ha->mem_ptr + IPS_REG_I960_MSG0);
@@ -4686,7 +4676,7 @@ ips_isinit_morpheus(ips_ha_t * ha)
 /*   state ( was trying to INIT and an interrupt was already pending ) ...  */
 /*                                                                          */
 /****************************************************************************/
-static void 
+static void
 ips_flush_and_reset(ips_ha_t *ha)
 {
        ips_scb_t *scb;
@@ -4718,9 +4708,9 @@ ips_flush_and_reset(ips_ha_t *ha)
            if (ret == IPS_SUCCESS) {
                time = 60 * IPS_ONE_SEC;                      /* Max Wait time is 60 seconds */
                done = 0;
-                   
+
                while ((time > 0) && (!done)) {
-                  done = ips_poll_for_flush_complete(ha);         
+                  done = ips_poll_for_flush_complete(ha);
                   /* This may look evil, but it's only done during extremely rare start-up conditions ! */
                   udelay(1000);
                   time--;
@@ -4749,17 +4739,17 @@ static int
 ips_poll_for_flush_complete(ips_ha_t * ha)
 {
        IPS_STATUS cstatus;
-    
+
        while (TRUE) {
            cstatus.value = (*ha->func.statupd) (ha);
 
            if (cstatus.value == 0xffffffff)      /* If No Interrupt to process */
                        break;
-            
+
            /* Success is when we see the Flush Command ID */
-           if (cstatus.fields.command_id == IPS_MAX_CMDS ) 
+           if (cstatus.fields.command_id == IPS_MAX_CMDS)
                return 1;
-        }      
+        }
 
        return 0;
 }
@@ -5920,7 +5910,7 @@ ips_read_config(ips_ha_t * ha, int intr)
 
                return (0);
        }
-       
+
        memcpy(ha->conf, ha->ioctl_data, sizeof(*ha->conf));
        return (1);
 }
@@ -5959,7 +5949,7 @@ ips_readwrite_page5(ips_ha_t * ha, int write, int intr)
        scb->cmd.nvram.buffer_addr = ha->ioctl_busaddr;
        if (write)
                memcpy(ha->ioctl_data, ha->nvram, sizeof(*ha->nvram));
-       
+
        /* issue the command */
        if (((ret =
              ips_send_wait(ha, scb, ips_cmd_timeout, intr)) == IPS_FAILURE)
@@ -6842,13 +6832,10 @@ ips_register_scsi(int index)
        if (request_irq(ha->pcidev->irq, do_ipsintr, IRQF_SHARED, ips_name, ha)) {
                IPS_PRINTK(KERN_WARNING, ha->pcidev,
                           "Unable to install interrupt handler\n");
-               scsi_host_put(sh);
-               return -1;
+               goto err_out_sh;
        }
 
        kfree(oldha);
-       ips_sh[index] = sh;
-       ips_ha[index] = ha;
 
        /* Store away needed values for later use */
        sh->unique_id = (ha->io_addr) ? ha->io_addr : ha->mem_addr;
@@ -6864,10 +6851,21 @@ ips_register_scsi(int index)
        sh->max_channel = ha->nbus - 1;
        sh->can_queue = ha->max_cmds - 1;
 
-       scsi_add_host(sh, NULL);
+       if (scsi_add_host(sh, &ha->pcidev->dev))
+               goto err_out;
+
+       ips_sh[index] = sh;
+       ips_ha[index] = ha;
+
        scsi_scan_host(sh);
 
        return 0;
+
+err_out:
+       free_irq(ha->pcidev->irq, ha);
+err_out_sh:
+       scsi_host_put(sh);
+       return -1;
 }
 
 /*---------------------------------------------------------------------------*/
@@ -6879,20 +6877,14 @@ ips_register_scsi(int index)
 static void __devexit
 ips_remove_device(struct pci_dev *pci_dev)
 {
-       int i;
-       struct Scsi_Host *sh;
-       ips_ha_t *ha;
+       struct Scsi_Host *sh = pci_get_drvdata(pci_dev);
 
-       for (i = 0; i < IPS_MAX_ADAPTERS; i++) {
-               ha = ips_ha[i];
-               if (ha) {
-                       if ((pci_dev->bus->number == ha->pcidev->bus->number) &&
-                           (pci_dev->devfn == ha->pcidev->devfn)) {
-                               sh = ips_sh[i];
-                               ips_release(sh);
-                       }
-               }
-       }
+       pci_set_drvdata(pci_dev, NULL);
+
+       ips_release(sh);
+
+       pci_release_regions(pci_dev);
+       pci_disable_device(pci_dev);
 }
 
 /****************************************************************************/
@@ -6946,12 +6938,17 @@ module_exit(ips_module_exit);
 static int __devinit
 ips_insert_device(struct pci_dev *pci_dev, const struct pci_device_id *ent)
 {
-       int uninitialized_var(index);
+       int index = -1;
        int rc;
 
        METHOD_TRACE("ips_insert_device", 1);
-       if (pci_enable_device(pci_dev))
-               return -1;
+       rc = pci_enable_device(pci_dev);
+       if (rc)
+               return rc;
+
+       rc = pci_request_regions(pci_dev, "ips");
+       if (rc)
+               goto err_out;
 
        rc = ips_init_phase1(pci_dev, &index);
        if (rc == SUCCESS)
@@ -6967,6 +6964,19 @@ ips_insert_device(struct pci_dev *pci_dev, const struct pci_device_id *ent)
                ips_num_controllers++;
 
        ips_next_controller = ips_num_controllers;
+
+       if (rc < 0) {
+               rc = -ENODEV;
+               goto err_out_regions;
+       }
+
+       pci_set_drvdata(pci_dev, ips_sh[index]);
+       return 0;
+
+err_out_regions:
+       pci_release_regions(pci_dev);
+err_out:
+       pci_disable_device(pci_dev);
        return rc;
 }
 
@@ -6999,7 +7009,7 @@ ips_init_phase1(struct pci_dev *pci_dev, int *indexPtr)
        METHOD_TRACE("ips_init_phase1", 1);
        index = IPS_MAX_ADAPTERS;
        for (j = 0; j < IPS_MAX_ADAPTERS; j++) {
-               if (ips_ha[j] == 0) {
+               if (ips_ha[j] == NULL) {
                        index = j;
                        break;
                }
@@ -7036,32 +7046,17 @@ ips_init_phase1(struct pci_dev *pci_dev, int *indexPtr)
                uint32_t base;
                uint32_t offs;
 
-               if (!request_mem_region(mem_addr, mem_len, "ips")) {
-                       IPS_PRINTK(KERN_WARNING, pci_dev,
-                                  "Couldn't allocate IO Memory space %x len %d.\n",
-                                  mem_addr, mem_len);
-                       return -1;
-               }
-
                base = mem_addr & PAGE_MASK;
                offs = mem_addr - base;
                ioremap_ptr = ioremap(base, PAGE_SIZE);
+               if (!ioremap_ptr)
+                       return -1;
                mem_ptr = ioremap_ptr + offs;
        } else {
                ioremap_ptr = NULL;
                mem_ptr = NULL;
        }
 
-       /* setup I/O mapped area (if applicable) */
-       if (io_addr) {
-               if (!request_region(io_addr, io_len, "ips")) {
-                       IPS_PRINTK(KERN_WARNING, pci_dev,
-                                  "Couldn't allocate IO space %x len %d.\n",
-                                  io_addr, io_len);
-                       return -1;
-               }
-       }
-
        /* found a controller */
        ha = kzalloc(sizeof (ips_ha_t), GFP_KERNEL);
        if (ha == NULL) {
@@ -7070,7 +7065,6 @@ ips_init_phase1(struct pci_dev *pci_dev, int *indexPtr)
                return -1;
        }
 
-
        ips_sh[index] = NULL;
        ips_ha[index] = ha;
        ha->active = 1;