resubmit: cciss: procfs updates to display info about many
[linux-2.6-block.git] / drivers / block / cciss_scsi.c
index afdff32f67247a4b2adf9ad091998bf56dd859fb..45ac09300eb338c50f372bd51f2532e8bdec8d1b 100644 (file)
@@ -1,20 +1,20 @@
 /*
- *    Disk Array driver for Compaq SA53xx Controllers, SCSI Tape module
- *    Copyright 2001 Compaq Computer Corporation
+ *    Disk Array driver for HP Smart Array controllers, SCSI Tape module.
+ *    (C) Copyright 2001, 2007 Hewlett-Packard Development Company, L.P.
  *
  *    This program is free software; you can redistribute it and/or modify
  *    it under the terms of the GNU General Public License as published by
- *    the Free Software Foundation; either version 2 of the License, or
- *    (at your option) any later version.
+ *    the Free Software Foundation; version 2 of the License.
  *
  *    This program is distributed in the hope that it will be useful,
  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
- *    MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
- *    NON INFRINGEMENT.  See the GNU General Public License for more details.
+ *    MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ *    General Public License for more details.
  *
  *    You should have received a copy of the GNU General Public License
  *    along with this program; if not, write to the Free Software
- *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *    Foundation, Inc., 59 Temple Place, Suite 300, Boston, MA
+ *    02111-1307, USA.
  *
  *    Questions/Comments/Bugfixes to iss_storagedev@hp.com
  *    
@@ -35,7 +35,6 @@
 
 #include <asm/atomic.h>
 
-#include <scsi/scsi.h> 
 #include <scsi/scsi_cmnd.h>
 #include <scsi/scsi_device.h>
 #include <scsi/scsi_host.h> 
@@ -251,10 +250,6 @@ scsi_cmd_stack_free(int ctlr)
        stk->pool = NULL;
 }
 
-/* scsi_device_types comes from scsi.h */
-#define DEVICETYPE(n) (n<0 || n>MAX_SCSI_DEVICE_CODE) ? \
-       "Unknown" : scsi_device_types[n]
-
 #if 0
 static int xmargin=8;
 static int amargin=60;
@@ -389,7 +384,7 @@ cciss_scsi_add_entry(int ctlr, int hostno,
           time anyway (the scsi layer's inquiries will show that info) */
        if (hostno != -1)
                printk("cciss%d: %s device c%db%dt%dl%d added.\n", 
-                       ctlr, DEVICETYPE(sd->devtype), hostno, 
+                       ctlr, scsi_device_type(sd->devtype), hostno,
                        sd->bus, sd->target, sd->lun);
        return 0;
 }
@@ -407,7 +402,7 @@ cciss_scsi_remove_entry(int ctlr, int hostno, int entry)
                ccissscsi[ctlr].dev[i] = ccissscsi[ctlr].dev[i+1];
        ccissscsi[ctlr].ndevices--;
        printk("cciss%d: %s device c%db%dt%dl%d removed.\n",
-               ctlr, DEVICETYPE(sd.devtype), hostno, 
+               ctlr, scsi_device_type(sd.devtype), hostno,
                        sd.bus, sd.target, sd.lun);
 }
 
@@ -458,7 +453,7 @@ adjust_cciss_scsi_table(int ctlr, int hostno,
                if (found == 0) { /* device no longer present. */ 
                        changes++;
                        /* printk("cciss%d: %s device c%db%dt%dl%d removed.\n",
-                               ctlr, DEVICETYPE(csd->devtype), hostno, 
+                               ctlr, scsi_device_type(csd->devtype), hostno,
                                        csd->bus, csd->target, csd->lun); */
                        cciss_scsi_remove_entry(ctlr, hostno, i);
                        /* note, i not incremented */
@@ -468,7 +463,7 @@ adjust_cciss_scsi_table(int ctlr, int hostno,
                        printk("cciss%d: device c%db%dt%dl%d type changed "
                                "(device type now %s).\n",
                                ctlr, hostno, csd->bus, csd->target, csd->lun,
-                                       DEVICETYPE(csd->devtype));
+                                       scsi_device_type(csd->devtype));
                        csd->devtype = sd[j].devtype;
                        i++;    /* so just move along. */
                } else          /* device is same as it ever was, */
@@ -560,7 +555,6 @@ complete_scsi_command( CommandList_struct *cp, int timeout, __u32 tag)
 {
        struct scsi_cmnd *cmd;
        ctlr_info_t *ctlr;
-       u64bit addr64;
        ErrorInfo_struct *ei;
 
        ei = cp->err_info;
@@ -574,20 +568,7 @@ complete_scsi_command( CommandList_struct *cp, int timeout, __u32 tag)
        cmd = (struct scsi_cmnd *) cp->scsi_cmd;        
        ctlr = hba[cp->ctlr];
 
-       /* undo the DMA mappings */
-
-       if (cmd->use_sg) {
-               pci_unmap_sg(ctlr->pdev,
-                       cmd->request_buffer, cmd->use_sg,
-                               cmd->sc_data_direction); 
-       }
-       else if (cmd->request_bufflen) {
-               addr64.val32.lower = cp->SG[0].Addr.lower;
-                addr64.val32.upper = cp->SG[0].Addr.upper;
-                pci_unmap_single(ctlr->pdev, (dma_addr_t) addr64.val,
-                       cmd->request_bufflen, 
-                               cmd->sc_data_direction);
-       }
+       scsi_dma_unmap(cmd);
 
        cmd->result = (DID_OK << 16);           /* host byte */
        cmd->result |= (COMMAND_COMPLETE << 8); /* msg byte */
@@ -602,7 +583,7 @@ complete_scsi_command( CommandList_struct *cp, int timeout, __u32 tag)
                ei->SenseLen > SCSI_SENSE_BUFFERSIZE ?
                        SCSI_SENSE_BUFFERSIZE : 
                        ei->SenseLen);
-       cmd->resid = ei->ResidualCnt;
+       scsi_set_resid(cmd, ei->ResidualCnt);
 
        if(ei->CommandStatus != 0) 
        { /* an error has occurred */ 
@@ -770,7 +751,7 @@ cciss_scsi_do_simple_cmd(ctlr_info_t *c,
                        int direction)
 {
        unsigned long flags;
-       DECLARE_COMPLETION(wait);
+       DECLARE_COMPLETION_ONSTACK(wait);
 
        cp->cmd_type = CMD_IOCTL_PEND;          // treat this like an ioctl 
        cp->scsi_cmd = NULL;
@@ -1098,7 +1079,7 @@ cciss_update_non_disk_devices(int cntl_num, int hostno)
                        if (ncurrent >= CCISS_MAX_SCSI_DEVS_PER_HBA) {
                                printk(KERN_INFO "cciss%d: %s ignored, "
                                        "too many devices.\n", cntl_num,
-                                       DEVICETYPE(devtype));
+                                       scsi_device_type(devtype));
                                break;
                        }
                        memcpy(&currentsd[ncurrent].scsi3addr[0], 
@@ -1209,46 +1190,29 @@ cciss_scatter_gather(struct pci_dev *pdev,
                CommandList_struct *cp, 
                struct scsi_cmnd *cmd)
 {
-       unsigned int use_sg, nsegs=0, len;
-       struct scatterlist *scatter = (struct scatterlist *) cmd->request_buffer;
+       unsigned int len;
+       struct scatterlist *sg;
        __u64 addr64;
-
-       /* is it just one virtual address? */   
-       if (!cmd->use_sg) {
-               if (cmd->request_bufflen) {     /* anything to xfer? */
-
-                       addr64 = (__u64) pci_map_single(pdev, 
-                               cmd->request_buffer, 
-                               cmd->request_bufflen, 
-                               cmd->sc_data_direction); 
-       
-                       cp->SG[0].Addr.lower = 
-                         (__u32) (addr64 & (__u64) 0x00000000FFFFFFFF);
-                       cp->SG[0].Addr.upper =
-                         (__u32) ((addr64 >> 32) & (__u64) 0x00000000FFFFFFFF);
-                       cp->SG[0].Len = cmd->request_bufflen;
-                       nsegs=1;
+       int use_sg, i;
+
+       BUG_ON(scsi_sg_count(cmd) > MAXSGENTRIES);
+
+       use_sg = scsi_dma_map(cmd);
+       if (use_sg) {   /* not too many addrs? */
+               scsi_for_each_sg(cmd, sg, use_sg, i) {
+                       addr64 = (__u64) sg_dma_address(sg);
+                       len  = sg_dma_len(sg);
+                       cp->SG[i].Addr.lower =
+                               (__u32) (addr64 & (__u64) 0x00000000FFFFFFFF);
+                       cp->SG[i].Addr.upper =
+                               (__u32) ((addr64 >> 32) & (__u64) 0x00000000FFFFFFFF);
+                       cp->SG[i].Len = len;
+                       cp->SG[i].Ext = 0;  // we are not chaining
                }
-       } /* else, must be a list of virtual addresses.... */
-       else if (cmd->use_sg <= MAXSGENTRIES) { /* not too many addrs? */
-
-               use_sg = pci_map_sg(pdev, cmd->request_buffer, cmd->use_sg,
-                       cmd->sc_data_direction);
-
-               for (nsegs=0; nsegs < use_sg; nsegs++) {
-                       addr64 = (__u64) sg_dma_address(&scatter[nsegs]);
-                       len  = sg_dma_len(&scatter[nsegs]);
-                       cp->SG[nsegs].Addr.lower =
-                         (__u32) (addr64 & (__u64) 0x00000000FFFFFFFF);
-                       cp->SG[nsegs].Addr.upper =
-                         (__u32) ((addr64 >> 32) & (__u64) 0x00000000FFFFFFFF);
-                       cp->SG[nsegs].Len = len;
-                       cp->SG[nsegs].Ext = 0;  // we are not chaining
-               }
-       } else BUG();
+       }
 
-       cp->Header.SGList = (__u8) nsegs;   /* no. SGs contig in this cmd */
-       cp->Header.SGTotal = (__u16) nsegs; /* total sgs in this cmd list */
+       cp->Header.SGList = (__u8) use_sg;   /* no. SGs contig in this cmd */
+       cp->Header.SGTotal = (__u16) use_sg; /* total sgs in this cmd list */
        return;
 }
 
@@ -1440,21 +1404,18 @@ cciss_engage_scsi(int ctlr)
 }
 
 static void
-cciss_proc_tape_report(int ctlr, unsigned char *buffer, off_t *pos, off_t *len)
+cciss_seq_tape_report(struct seq_file *seq, int ctlr)
 {
        unsigned long flags;
-       int size;
-
-       *pos = *pos -1; *len = *len - 1; // cut off the last trailing newline
 
        CPQ_TAPE_LOCK(ctlr, flags);
-       size = sprintf(buffer + *len, 
+       seq_printf(seq,
                "Sequential access devices: %d\n\n",
                        ccissscsi[ctlr].ndevices);
        CPQ_TAPE_UNLOCK(ctlr, flags);
-       *pos += size; *len += size;
 }
 
+
 /* Need at least one of these error handlers to keep ../scsi/hosts.c from 
  * complaining.  Doing a host- or bus-reset can't do anything good here. 
  * Despite what it might say in scsi_error.c, there may well be commands
@@ -1489,7 +1450,7 @@ static int cciss_eh_device_reset_handler(struct scsi_cmnd *scsicmd)
        rc = sendcmd(CCISS_RESET_MSG, ctlr, NULL, 0, 2, 0, 0, 
                (unsigned char *) &cmd_in_trouble->Header.LUN.LunAddrBytes[0], 
                TYPE_MSG);
-       /* sendcmd turned off interrputs on the board, turn 'em back on. */
+       /* sendcmd turned off interrupts on the board, turn 'em back on. */
        (*c)->access.set_intr_mask(*c, CCISS_INTR_ON);
        if (rc == 0)
                return SUCCESS;
@@ -1519,7 +1480,7 @@ static int  cciss_eh_abort_handler(struct scsi_cmnd *scsicmd)
                0, 2, 0, 0, 
                (unsigned char *) &cmd_to_abort->Header.LUN.LunAddrBytes[0], 
                TYPE_MSG);
-       /* sendcmd turned off interrputs on the board, turn 'em back on. */
+       /* sendcmd turned off interrupts on the board, turn 'em back on. */
        (*c)->access.set_intr_mask(*c, CCISS_INTR_ON);
        if (rc == 0)
                return SUCCESS;
@@ -1534,6 +1495,5 @@ static int  cciss_eh_abort_handler(struct scsi_cmnd *scsicmd)
 #define cciss_scsi_setup(cntl_num)
 #define cciss_unregister_scsi(ctlr)
 #define cciss_register_scsi(ctlr)
-#define cciss_proc_tape_report(ctlr, buffer, pos, len)
 
 #endif /* CONFIG_CISS_SCSI_TAPE */