Console keyboard events and accessibility
[safe/jmp/linux-2.6] / drivers / scsi / qla1280.c
index 680f606..76089cf 100644 (file)
         - Don't walk the entire list in qla1280_putq_t() just to directly
          grab the pointer to the last element afterwards
     Rev  3.23.5 Beta August 9, 2001, Jes Sorensen
-       - Don't use SA_INTERRUPT, it's use is deprecated for this kinda driver
+       - Don't use IRQF_DISABLED, it's use is deprecated for this kinda driver
     Rev  3.23.4 Beta August 8, 2001, Jes Sorensen
        - Set dev->max_sectors to 1024
     Rev  3.23.3 Beta August 6, 2001, Jes Sorensen
 *****************************************************************************/
 
 
-#include <linux/config.h>
 #include <linux/module.h>
 
 #include <linux/version.h>
 #include <linux/ioport.h>
 #include <linux/delay.h>
 #include <linux/timer.h>
-#include <linux/sched.h>
 #include <linux/pci.h>
 #include <linux/proc_fs.h>
 #include <linux/stat.h>
@@ -814,7 +812,7 @@ qla1280_error_action(struct scsi_cmnd *cmd, enum action action)
        uint16_t data;
        unsigned char *handle;
        int result, i;
-       DECLARE_COMPLETION(wait);
+       DECLARE_COMPLETION_ONSTACK(wait);
        struct timer_list timer;
 
        ha = (struct scsi_qla_host *)(CMD_HOST(cmd)->hostdata);
@@ -932,11 +930,10 @@ qla1280_error_action(struct scsi_cmnd *cmd, enum action action)
 
        case BUS_RESET:
                if (qla1280_verbose)
-                       printk(KERN_INFO "qla1280(%ld:%d): Issuing BUS "
-                              "DEVICE RESET\n", ha->host_no, bus);
-               if (qla1280_bus_reset(ha, bus == 0))
+                       printk(KERN_INFO "qla1280(%ld:%d): Issued bus "
+                              "reset.\n", ha->host_no, bus);
+               if (qla1280_bus_reset(ha, bus) == 0)
                        result = SUCCESS;
-
                break;
 
        case ADAPTER_RESET:
@@ -1114,7 +1111,7 @@ qla1280_enable_intrs(struct scsi_qla_host *ha)
  *   Handles the H/W interrupt
  **************************************************************************/
 static irqreturn_t
-qla1280_intr_handler(int irq, void *dev_id, struct pt_regs *regs)
+qla1280_intr_handler(int irq, void *dev_id)
 {
        struct scsi_qla_host *ha;
        struct device_reg __iomem *reg;
@@ -1343,7 +1340,7 @@ qla1280_return_status(struct response * sts, struct scsi_cmnd *cp)
        int host_status = DID_ERROR;
        uint16_t comp_status = le16_to_cpu(sts->comp_status);
        uint16_t state_flags = le16_to_cpu(sts->state_flags);
-       uint16_t residual_length = le32_to_cpu(sts->residual_length);
+       uint32_t residual_length = le32_to_cpu(sts->residual_length);
        uint16_t scsi_status = le16_to_cpu(sts->scsi_status);
 #if DEBUG_QLA1280_INTR
        static char *reason[] = {
@@ -1415,8 +1412,10 @@ qla1280_return_status(struct response * sts, struct scsi_cmnd *cp)
                               "scsi: Underflow detected - retrying "
                               "command.\n");
                        host_status = DID_ERROR;
-               } else
+               } else {
+                       cp->resid = residual_length;
                        host_status = DID_OK;
+               }
                break;
 
        default:
@@ -2407,7 +2406,7 @@ qla1280_mailbox_command(struct scsi_qla_host *ha, uint8_t mr, uint16_t *mb)
        uint16_t *optr, *iptr;
        uint16_t __iomem *mptr;
        uint16_t data;
-       DECLARE_COMPLETION(wait);
+       DECLARE_COMPLETION_ONSTACK(wait);
        struct timer_list timer;
 
        ENTER("qla1280_mailbox_command");
@@ -2776,7 +2775,7 @@ qla1280_64bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
        struct device_reg __iomem *reg = ha->iobase;
        struct scsi_cmnd *cmd = sp->cmd;
        cmd_a64_entry_t *pkt;
-       struct scatterlist *sg = NULL;
+       struct scatterlist *sg = NULL, *s;
        __le32 *dword_ptr;
        dma_addr_t dma_handle;
        int status = 0;
@@ -2863,7 +2862,7 @@ qla1280_64bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
        memset(((char *)pkt + 8), 0, (REQUEST_ENTRY_SIZE - 8));
 
        /* Set ISP command timeout. */
-       pkt->timeout = cpu_to_le16(30);
+       pkt->timeout = cpu_to_le16(cmd->timeout_per_command/HZ);
 
        /* Set device target ID and LUN */
        pkt->lun = SCSI_LUN_32(cmd);
@@ -2890,13 +2889,16 @@ qla1280_64bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
         * Load data segments.
         */
        if (seg_cnt) {  /* If data transfer. */
+               int remseg = seg_cnt;
                /* Setup packet address segment pointer. */
                dword_ptr = (u32 *)&pkt->dseg_0_address;
 
                if (cmd->use_sg) {      /* If scatter gather */
                        /* Load command entry data segments. */
-                       for (cnt = 0; cnt < 2 && seg_cnt; cnt++, seg_cnt--) {
-                               dma_handle = sg_dma_address(sg);
+                       for_each_sg(sg, s, seg_cnt, cnt) {
+                               if (cnt == 2)
+                                       break;
+                               dma_handle = sg_dma_address(s);
 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
                                if (ha->flags.use_pci_vchannel)
                                        sn_pci_set_vchan(ha->pdev,
@@ -2907,12 +2909,12 @@ qla1280_64bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
                                        cpu_to_le32(pci_dma_lo32(dma_handle));
                                *dword_ptr++ =
                                        cpu_to_le32(pci_dma_hi32(dma_handle));
-                               *dword_ptr++ = cpu_to_le32(sg_dma_len(sg));
-                               sg++;
+                               *dword_ptr++ = cpu_to_le32(sg_dma_len(s));
                                dprintk(3, "S/G Segment phys_addr=%x %x, len=0x%x\n",
                                        cpu_to_le32(pci_dma_hi32(dma_handle)),
                                        cpu_to_le32(pci_dma_lo32(dma_handle)),
-                                       cpu_to_le32(sg_dma_len(sg)));
+                                       cpu_to_le32(sg_dma_len(sg_next(s))));
+                               remseg--;
                        }
                        dprintk(5, "qla1280_64bit_start_scsi: Scatter/gather "
                                "command packet data - b %i, t %i, l %i \n",
@@ -2927,7 +2929,9 @@ qla1280_64bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
                        dprintk(3, "S/G Building Continuation...seg_cnt=0x%x "
                                "remains\n", seg_cnt);
 
-                       while (seg_cnt > 0) {
+                       while (remseg > 0) {
+                               /* Update sg start */
+                               sg = s;
                                /* Adjust ring index. */
                                ha->req_ring_index++;
                                if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
@@ -2953,9 +2957,10 @@ qla1280_64bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
                                        (u32 *)&((struct cont_a64_entry *) pkt)->dseg_0_address;
 
                                /* Load continuation entry data segments. */
-                               for (cnt = 0; cnt < 5 && seg_cnt;
-                                    cnt++, seg_cnt--) {
-                                       dma_handle = sg_dma_address(sg);
+                               for_each_sg(sg, s, remseg, cnt) {
+                                       if (cnt == 5)
+                                               break;
+                                       dma_handle = sg_dma_address(s);
 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
                                if (ha->flags.use_pci_vchannel)
                                        sn_pci_set_vchan(ha->pdev, 
@@ -2967,13 +2972,13 @@ qla1280_64bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
                                        *dword_ptr++ =
                                                cpu_to_le32(pci_dma_hi32(dma_handle));
                                        *dword_ptr++ =
-                                               cpu_to_le32(sg_dma_len(sg));
+                                               cpu_to_le32(sg_dma_len(s));
                                        dprintk(3, "S/G Segment Cont. phys_addr=%x %x, len=0x%x\n",
                                                cpu_to_le32(pci_dma_hi32(dma_handle)),
                                                cpu_to_le32(pci_dma_lo32(dma_handle)),
-                                               cpu_to_le32(sg_dma_len(sg)));
-                                       sg++;
+                                               cpu_to_le32(sg_dma_len(s)));
                                }
+                               remseg -= cnt;
                                dprintk(5, "qla1280_64bit_start_scsi: "
                                        "continuation packet data - b %i, t "
                                        "%i, l %i \n", SCSI_BUS_32(cmd),
@@ -3063,7 +3068,7 @@ qla1280_32bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
        struct device_reg __iomem *reg = ha->iobase;
        struct scsi_cmnd *cmd = sp->cmd;
        struct cmd_entry *pkt;
-       struct scatterlist *sg = NULL;
+       struct scatterlist *sg = NULL, *s;
        __le32 *dword_ptr;
        int status = 0;
        int cnt;
@@ -3162,7 +3167,7 @@ qla1280_32bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
        memset(((char *)pkt + 8), 0, (REQUEST_ENTRY_SIZE - 8));
 
        /* Set ISP command timeout. */
-       pkt->timeout = cpu_to_le16(30);
+       pkt->timeout = cpu_to_le16(cmd->timeout_per_command/HZ);
 
        /* Set device target ID and LUN */
        pkt->lun = SCSI_LUN_32(cmd);
@@ -3189,6 +3194,7 @@ qla1280_32bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
         * Load data segments.
         */
        if (seg_cnt) {
+               int remseg = seg_cnt;
                /* Setup packet address segment pointer. */
                dword_ptr = &pkt->dseg_0_address;
 
@@ -3197,22 +3203,25 @@ qla1280_32bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
                        qla1280_dump_buffer(1, (char *)sg, 4 * 16);
 
                        /* Load command entry data segments. */
-                       for (cnt = 0; cnt < 4 && seg_cnt; cnt++, seg_cnt--) {
+                       for_each_sg(sg, s, seg_cnt, cnt) {
+                               if (cnt == 4)
+                                       break;
                                *dword_ptr++ =
-                                       cpu_to_le32(pci_dma_lo32(sg_dma_address(sg)));
-                               *dword_ptr++ =
-                                       cpu_to_le32(sg_dma_len(sg));
+                                       cpu_to_le32(pci_dma_lo32(sg_dma_address(s)));
+                               *dword_ptr++ = cpu_to_le32(sg_dma_len(s));
                                dprintk(3, "S/G Segment phys_addr=0x%lx, len=0x%x\n",
-                                       (pci_dma_lo32(sg_dma_address(sg))),
-                                       (sg_dma_len(sg)));
-                               sg++;
+                                       (pci_dma_lo32(sg_dma_address(s))),
+                                       (sg_dma_len(s)));
+                               remseg--;
                        }
                        /*
                         * Build continuation packets.
                         */
                        dprintk(3, "S/G Building Continuation"
                                "...seg_cnt=0x%x remains\n", seg_cnt);
-                       while (seg_cnt > 0) {
+                       while (remseg > 0) {
+                               /* Continue from end point */
+                               sg = s;
                                /* Adjust ring index. */
                                ha->req_ring_index++;
                                if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
@@ -3240,19 +3249,20 @@ qla1280_32bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
                                        &((struct cont_entry *) pkt)->dseg_0_address;
 
                                /* Load continuation entry data segments. */
-                               for (cnt = 0; cnt < 7 && seg_cnt;
-                                    cnt++, seg_cnt--) {
+                               for_each_sg(sg, s, remseg, cnt) {
+                                       if (cnt == 7)
+                                               break;
                                        *dword_ptr++ =
-                                               cpu_to_le32(pci_dma_lo32(sg_dma_address(sg)));
+                                               cpu_to_le32(pci_dma_lo32(sg_dma_address(s)));
                                        *dword_ptr++ =
-                                               cpu_to_le32(sg_dma_len(sg));
+                                               cpu_to_le32(sg_dma_len(s));
                                        dprintk(1,
                                                "S/G Segment Cont. phys_addr=0x%x, "
                                                "len=0x%x\n",
-                                               cpu_to_le32(pci_dma_lo32(sg_dma_address(sg))),
-                                               cpu_to_le32(sg_dma_len(sg)));
-                                       sg++;
+                                               cpu_to_le32(pci_dma_lo32(sg_dma_address(s))),
+                                               cpu_to_le32(sg_dma_len(s)));
                                }
+                               remseg -= cnt;
                                dprintk(5, "qla1280_32bit_start_scsi: "
                                        "continuation packet data - "
                                        "scsi(%i:%i:%i)\n", SCSI_BUS_32(cmd),
@@ -4087,7 +4097,7 @@ __qla1280_print_scsi_cmd(struct scsi_cmnd *cmd)
           } */
        printk("  tag=%d, transfersize=0x%x \n",
               cmd->tag, cmd->transfersize);
-       printk("  Pid=%li, SP=0x%p\n", cmd->pid, CMD_SP(cmd));
+       printk("  Pid=%li, SP=0x%p\n", cmd->serial_number, CMD_SP(cmd));
        printk(" underflow size = 0x%x, direction=0x%x\n",
               cmd->underflow, cmd->sc_data_direction);
 }
@@ -4210,7 +4220,7 @@ qla1280_setup(char *s)
 }
 
 
-static int
+static int __init
 qla1280_get_token(char *str)
 {
        char *sep;
@@ -4249,6 +4259,7 @@ static struct scsi_host_template qla1280_driver_template = {
        .sg_tablesize           = SG_ALL,
        .cmd_per_lun            = 1,
        .use_clustering         = ENABLE_CLUSTERING,
+       .use_sg_chaining        = ENABLE_SG_CHAINING,
 };
 
 
@@ -4294,7 +4305,7 @@ qla1280_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
        ha->devnum = devnum;    /* specifies microcode load address */
 
 #ifdef QLA_64BIT_PTR
-       if (pci_set_dma_mask(ha->pdev, (dma_addr_t) ~ 0ULL)) {
+       if (pci_set_dma_mask(ha->pdev, DMA_64BIT_MASK)) {
                if (pci_set_dma_mask(ha->pdev, DMA_32BIT_MASK)) {
                        printk(KERN_WARNING "scsi(%li): Unable to set a "
                               "suitable DMA mask - aborting\n", ha->host_no);
@@ -4370,7 +4381,7 @@ qla1280_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
        /* Disable ISP interrupts. */
        qla1280_disable_intrs(ha);
 
-       if (request_irq(pdev->irq, qla1280_intr_handler, SA_SHIRQ,
+       if (request_irq(pdev->irq, qla1280_intr_handler, IRQF_SHARED,
                                "qla1280", ha)) {
                printk("qla1280 : Failed to reserve interrupt %d already "
                       "in use\n", pdev->irq);
@@ -4485,7 +4496,7 @@ qla1280_init(void)
                qla1280_setup(qla1280);
 #endif
 
-       return pci_module_init(&qla1280_pci_driver);
+       return pci_register_driver(&qla1280_pci_driver);
 }
 
 static void __exit