]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - drivers/block/cciss.c
cciss: forbid hard reset of 640x boards
[karo-tx-linux.git] / drivers / block / cciss.c
index 51ceaee98f9feb8c7275a9877cb54866ffe2375a..2abe6df9445e2845f8c0eabd228385c209a138b2 100644 (file)
 #include <linux/kthread.h>
 
 #define CCISS_DRIVER_VERSION(maj,min,submin) ((maj<<16)|(min<<8)|(submin))
-#define DRIVER_NAME "HP CISS Driver (v 3.6.20)"
-#define DRIVER_VERSION CCISS_DRIVER_VERSION(3, 6, 20)
+#define DRIVER_NAME "HP CISS Driver (v 3.6.26)"
+#define DRIVER_VERSION CCISS_DRIVER_VERSION(3, 6, 26)
 
 /* Embedded module documentation macros - see modules.h */
 MODULE_AUTHOR("Hewlett-Packard Company");
 MODULE_DESCRIPTION("Driver for HP Smart Array Controllers");
-MODULE_SUPPORTED_DEVICE("HP SA5i SA5i+ SA532 SA5300 SA5312 SA641 SA642 SA6400"
-                       " SA6i P600 P800 P400 P400i E200 E200i E500 P700m"
-                       " Smart Array G2 Series SAS/SATA Controllers");
-MODULE_VERSION("3.6.20");
+MODULE_SUPPORTED_DEVICE("HP Smart Array Controllers");
+MODULE_VERSION("3.6.26");
 MODULE_LICENSE("GPL");
 
 static int cciss_allow_hpsa;
@@ -107,6 +105,11 @@ static const struct pci_device_id cciss_pci_device_id[] = {
        {PCI_VENDOR_ID_HP,     PCI_DEVICE_ID_HP_CISSE,     0x103C, 0x3249},
        {PCI_VENDOR_ID_HP,     PCI_DEVICE_ID_HP_CISSE,     0x103C, 0x324A},
        {PCI_VENDOR_ID_HP,     PCI_DEVICE_ID_HP_CISSE,     0x103C, 0x324B},
+       {PCI_VENDOR_ID_HP,     PCI_DEVICE_ID_HP_CISSE,     0x103C, 0x3250},
+       {PCI_VENDOR_ID_HP,     PCI_DEVICE_ID_HP_CISSE,     0x103C, 0x3251},
+       {PCI_VENDOR_ID_HP,     PCI_DEVICE_ID_HP_CISSE,     0x103C, 0x3252},
+       {PCI_VENDOR_ID_HP,     PCI_DEVICE_ID_HP_CISSE,     0x103C, 0x3253},
+       {PCI_VENDOR_ID_HP,     PCI_DEVICE_ID_HP_CISSE,     0x103C, 0x3254},
        {0,}
 };
 
@@ -146,6 +149,11 @@ static struct board_type products[] = {
        {0x3249103C, "Smart Array P812", &SA5_access},
        {0x324A103C, "Smart Array P712m", &SA5_access},
        {0x324B103C, "Smart Array P711m", &SA5_access},
+       {0x3250103C, "Smart Array", &SA5_access},
+       {0x3251103C, "Smart Array", &SA5_access},
+       {0x3252103C, "Smart Array", &SA5_access},
+       {0x3253103C, "Smart Array", &SA5_access},
+       {0x3254103C, "Smart Array", &SA5_access},
 };
 
 /* How long to wait (in milliseconds) for board to go into simple mode */
@@ -167,9 +175,13 @@ static DEFINE_MUTEX(scan_mutex);
 static LIST_HEAD(scan_q);
 
 static void do_cciss_request(struct request_queue *q);
-static irqreturn_t do_cciss_intr(int irq, void *dev_id);
+static irqreturn_t do_cciss_intx(int irq, void *dev_id);
+static irqreturn_t do_cciss_msix_intr(int irq, void *dev_id);
 static int cciss_open(struct block_device *bdev, fmode_t mode);
+static int cciss_unlocked_open(struct block_device *bdev, fmode_t mode);
 static int cciss_release(struct gendisk *disk, fmode_t mode);
+static int do_ioctl(struct block_device *bdev, fmode_t mode,
+                   unsigned int cmd, unsigned long arg);
 static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
                       unsigned int cmd, unsigned long arg);
 static int cciss_getgeo(struct block_device *bdev, struct hd_geometry *geo);
@@ -187,8 +199,7 @@ static void cciss_geometry_inquiry(int ctlr, int logvol,
                        sector_t total_size,
                        unsigned int block_size, InquiryData_struct *inq_buff,
                                   drive_info_struct *drv);
-static void __devinit cciss_interrupt_mode(ctlr_info_t *, struct pci_dev *,
-                                          __u32);
+static void __devinit cciss_interrupt_mode(ctlr_info_t *);
 static void start_io(ctlr_info_t *h);
 static int sendcmd_withirq(__u8 cmd, int ctlr, void *buff, size_t size,
                        __u8 page_code, unsigned char scsi3addr[],
@@ -197,7 +208,6 @@ static int sendcmd_withirq_core(ctlr_info_t *h, CommandList_struct *c,
        int attempt_retry);
 static int process_sendcmd_error(ctlr_info_t *h, CommandList_struct *c);
 
-static void fail_all_cmds(unsigned long ctlr);
 static int add_to_scan_list(struct ctlr_info *h);
 static int scan_thread(void *data);
 static int check_for_unit_attention(ctlr_info_t *h, CommandList_struct *c);
@@ -205,6 +215,18 @@ static void cciss_hba_release(struct device *dev);
 static void cciss_device_release(struct device *dev);
 static void cciss_free_gendisk(ctlr_info_t *h, int drv_index);
 static void cciss_free_drive_info(ctlr_info_t *h, int drv_index);
+static inline u32 next_command(ctlr_info_t *h);
+static int __devinit cciss_find_cfg_addrs(struct pci_dev *pdev,
+       void __iomem *vaddr, u32 *cfg_base_addr, u64 *cfg_base_addr_index,
+       u64 *cfg_offset);
+static int __devinit cciss_pci_find_memory_BAR(struct pci_dev *pdev,
+       unsigned long *memory_bar);
+
+
+/* performant mode helper functions */
+static void  calc_bucket_map(int *bucket, int num_buckets, int nsgs,
+                               int *bucket_map);
+static void cciss_put_controller_into_performant_mode(ctlr_info_t *h);
 
 #ifdef CONFIG_PROC_FS
 static void cciss_procinit(int i);
@@ -221,9 +243,9 @@ static int cciss_compat_ioctl(struct block_device *, fmode_t,
 
 static const struct block_device_operations cciss_fops = {
        .owner = THIS_MODULE,
-       .open = cciss_open,
+       .open = cciss_unlocked_open,
        .release = cciss_release,
-       .locked_ioctl = cciss_ioctl,
+       .ioctl = do_ioctl,
        .getgeo = cciss_getgeo,
 #ifdef CONFIG_COMPAT
        .compat_ioctl = cciss_compat_ioctl,
@@ -231,6 +253,16 @@ static const struct block_device_operations cciss_fops = {
        .revalidate_disk = cciss_revalidate,
 };
 
+/* set_performant_mode: Modify the tag for cciss performant
+ * set bit 0 for pull model, bits 3-1 for block fetch
+ * register number
+ */
+static void set_performant_mode(ctlr_info_t *h, CommandList_struct *c)
+{
+       if (likely(h->transMethod == CFGTBL_Trans_Performant))
+               c->busaddr |= 1 | (h->blockFetchTable[c->Header.SGList] << 1);
+}
+
 /*
  * Enqueuing and dequeuing functions for cmdlists.
  */
@@ -257,6 +289,18 @@ static inline void removeQ(CommandList_struct *c)
        hlist_del_init(&c->list);
 }
 
+static void enqueue_cmd_and_start_io(ctlr_info_t *h,
+       CommandList_struct *c)
+{
+       unsigned long flags;
+       set_performant_mode(h, c);
+       spin_lock_irqsave(&h->lock, flags);
+       addQ(&h->reqQ, c);
+       h->Qdepth++;
+       start_io(h);
+       spin_unlock_irqrestore(&h->lock, flags);
+}
+
 static void cciss_free_sg_chain_blocks(SGDescriptor_struct **cmd_sg_list,
        int nr_cmds)
 {
@@ -366,7 +410,7 @@ static void cciss_seq_show_header(struct seq_file *seq)
                h->product_name,
                (unsigned long)h->board_id,
                h->firm_ver[0], h->firm_ver[1], h->firm_ver[2],
-               h->firm_ver[3], (unsigned int)h->intr[SIMPLE_MODE_INT],
+               h->firm_ver[3], (unsigned int)h->intr[PERF_MODE_INT],
                h->num_luns,
                h->Qdepth, h->commands_outstanding,
                h->maxQsinceinit, h->max_outstanding, h->maxSG);
@@ -1004,13 +1048,28 @@ static int cciss_open(struct block_device *bdev, fmode_t mode)
        return 0;
 }
 
+static int cciss_unlocked_open(struct block_device *bdev, fmode_t mode)
+{
+       int ret;
+
+       lock_kernel();
+       ret = cciss_open(bdev, mode);
+       unlock_kernel();
+
+       return ret;
+}
+
 /*
  * Close.  Sync first.
  */
 static int cciss_release(struct gendisk *disk, fmode_t mode)
 {
-       ctlr_info_t *host = get_host(disk);
-       drive_info_struct *drv = get_drv(disk);
+       ctlr_info_t *host;
+       drive_info_struct *drv;
+
+       lock_kernel();
+       host = get_host(disk);
+       drv = get_drv(disk);
 
 #ifdef CCISS_DEBUG
        printk(KERN_DEBUG "cciss_release %s\n", disk->disk_name);
@@ -1018,11 +1077,10 @@ static int cciss_release(struct gendisk *disk, fmode_t mode)
 
        drv->usage_count--;
        host->usage_count--;
+       unlock_kernel();
        return 0;
 }
 
-#ifdef CONFIG_COMPAT
-
 static int do_ioctl(struct block_device *bdev, fmode_t mode,
                    unsigned cmd, unsigned long arg)
 {
@@ -1033,6 +1091,8 @@ static int do_ioctl(struct block_device *bdev, fmode_t mode,
        return ret;
 }
 
+#ifdef CONFIG_COMPAT
+
 static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
                                  unsigned cmd, unsigned long arg);
 static int cciss_ioctl32_big_passthru(struct block_device *bdev, fmode_t mode,
@@ -1377,7 +1437,6 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
                        CommandList_struct *c;
                        char *buff = NULL;
                        u64bit temp64;
-                       unsigned long flags;
                        DECLARE_COMPLETION_ONSTACK(wait);
 
                        if (!arg)
@@ -1449,13 +1508,7 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
                        }
                        c->waiting = &wait;
 
-                       /* Put the request on the tail of the request queue */
-                       spin_lock_irqsave(CCISS_LOCK(ctlr), flags);
-                       addQ(&host->reqQ, c);
-                       host->Qdepth++;
-                       start_io(host);
-                       spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags);
-
+                       enqueue_cmd_and_start_io(host, c);
                        wait_for_completion(&wait);
 
                        /* unlock the buffers from DMA */
@@ -1495,7 +1548,6 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
                        unsigned char **buff = NULL;
                        int *buff_size = NULL;
                        u64bit temp64;
-                       unsigned long flags;
                        BYTE sg_used = 0;
                        int status = 0;
                        int i;
@@ -1602,12 +1654,7 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
                                }
                        }
                        c->waiting = &wait;
-                       /* Put the request on the tail of the request queue */
-                       spin_lock_irqsave(CCISS_LOCK(ctlr), flags);
-                       addQ(&host->reqQ, c);
-                       host->Qdepth++;
-                       start_io(host);
-                       spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags);
+                       enqueue_cmd_and_start_io(host, c);
                        wait_for_completion(&wait);
                        /* unlock the buffers from DMA */
                        for (i = 0; i < sg_used; i++) {
@@ -1729,8 +1776,8 @@ static void cciss_softirq_done(struct request *rq)
        CommandList_struct *cmd = rq->completion_data;
        ctlr_info_t *h = hba[cmd->ctlr];
        SGDescriptor_struct *curr_sg = cmd->SG;
-       unsigned long flags;
        u64bit temp64;
+       unsigned long flags;
        int i, ddir;
        int sg_index = 0;
 
@@ -1760,7 +1807,7 @@ static void cciss_softirq_done(struct request *rq)
 #endif                         /* CCISS_DEBUG */
 
        /* set the residual count for pc requests */
-       if (blk_pc_request(rq))
+       if (rq->cmd_type == REQ_TYPE_BLOCK_PC)
                rq->resid_len = cmd->err_info->ResidualCnt;
 
        blk_end_request_all(rq, (rq->errors == 0) ? 0 : -EIO);
@@ -2679,17 +2726,11 @@ static int sendcmd_withirq_core(ctlr_info_t *h, CommandList_struct *c,
 {
        DECLARE_COMPLETION_ONSTACK(wait);
        u64bit buff_dma_handle;
-       unsigned long flags;
        int return_status = IO_OK;
 
 resend_cmd2:
        c->waiting = &wait;
-       /* Put the request on the tail of the queue and send it */
-       spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags);
-       addQ(&h->reqQ, c);
-       h->Qdepth++;
-       start_io(h);
-       spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
+       enqueue_cmd_and_start_io(h, c);
 
        wait_for_completion(&wait);
 
@@ -2966,7 +3007,7 @@ static inline int evaluate_target_status(ctlr_info_t *h,
        driver_byte = DRIVER_OK;
        msg_byte = cmd->err_info->CommandStatus; /* correct?  seems too device specific */
 
-       if (blk_pc_request(cmd->rq))
+       if (cmd->rq->cmd_type == REQ_TYPE_BLOCK_PC)
                host_byte = DID_PASSTHROUGH;
        else
                host_byte = DID_OK;
@@ -2975,7 +3016,7 @@ static inline int evaluate_target_status(ctlr_info_t *h,
                host_byte, driver_byte);
 
        if (cmd->err_info->ScsiStatus != SAM_STAT_CHECK_CONDITION) {
-               if (!blk_pc_request(cmd->rq))
+               if (cmd->rq->cmd_type != REQ_TYPE_BLOCK_PC)
                        printk(KERN_WARNING "cciss: cmd %p "
                               "has SCSI Status 0x%x\n",
                               cmd, cmd->err_info->ScsiStatus);
@@ -2985,15 +3026,17 @@ static inline int evaluate_target_status(ctlr_info_t *h,
        /* check the sense key */
        sense_key = 0xf & cmd->err_info->SenseInfo[2];
        /* no status or recovered error */
-       if (((sense_key == 0x0) || (sense_key == 0x1)) && !blk_pc_request(cmd->rq))
+       if (((sense_key == 0x0) || (sense_key == 0x1)) &&
+           (cmd->rq->cmd_type != REQ_TYPE_BLOCK_PC))
                error_value = 0;
 
        if (check_for_unit_attention(h, cmd)) {
-               *retry_cmd = !blk_pc_request(cmd->rq);
+               *retry_cmd = !(cmd->rq->cmd_type == REQ_TYPE_BLOCK_PC);
                return 0;
        }
 
-       if (!blk_pc_request(cmd->rq)) { /* Not SG_IO or similar? */
+       /* Not SG_IO or similar? */
+       if (cmd->rq->cmd_type != REQ_TYPE_BLOCK_PC) {
                if (error_value != 0)
                        printk(KERN_WARNING "cciss: cmd %p has CHECK CONDITION"
                               " sense key = 0x%x\n", cmd, sense_key);
@@ -3035,7 +3078,7 @@ static inline void complete_command(ctlr_info_t *h, CommandList_struct *cmd,
                rq->errors = evaluate_target_status(h, cmd, &retry_cmd);
                break;
        case CMD_DATA_UNDERRUN:
-               if (blk_fs_request(cmd->rq)) {
+               if (cmd->rq->cmd_type == REQ_TYPE_FS) {
                        printk(KERN_WARNING "cciss: cmd %p has"
                               " completed with data underrun "
                               "reported\n", cmd);
@@ -3043,7 +3086,7 @@ static inline void complete_command(ctlr_info_t *h, CommandList_struct *cmd,
                }
                break;
        case CMD_DATA_OVERRUN:
-               if (blk_fs_request(cmd->rq))
+               if (cmd->rq->cmd_type == REQ_TYPE_FS)
                        printk(KERN_WARNING "cciss: cmd %p has"
                               " completed with data overrun "
                               "reported\n", cmd);
@@ -3053,42 +3096,48 @@ static inline void complete_command(ctlr_info_t *h, CommandList_struct *cmd,
                       "reported invalid\n", cmd);
                rq->errors = make_status_bytes(SAM_STAT_GOOD,
                        cmd->err_info->CommandStatus, DRIVER_OK,
-                       blk_pc_request(cmd->rq) ? DID_PASSTHROUGH : DID_ERROR);
+                       (cmd->rq->cmd_type == REQ_TYPE_BLOCK_PC) ?
+                               DID_PASSTHROUGH : DID_ERROR);
                break;
        case CMD_PROTOCOL_ERR:
                printk(KERN_WARNING "cciss: cmd %p has "
                       "protocol error \n", cmd);
                rq->errors = make_status_bytes(SAM_STAT_GOOD,
                        cmd->err_info->CommandStatus, DRIVER_OK,
-                       blk_pc_request(cmd->rq) ? DID_PASSTHROUGH : DID_ERROR);
+                       (cmd->rq->cmd_type == REQ_TYPE_BLOCK_PC) ?
+                               DID_PASSTHROUGH : DID_ERROR);
                break;
        case CMD_HARDWARE_ERR:
                printk(KERN_WARNING "cciss: cmd %p had "
                       " hardware error\n", cmd);
                rq->errors = make_status_bytes(SAM_STAT_GOOD,
                        cmd->err_info->CommandStatus, DRIVER_OK,
-                       blk_pc_request(cmd->rq) ? DID_PASSTHROUGH : DID_ERROR);
+                       (cmd->rq->cmd_type == REQ_TYPE_BLOCK_PC) ?
+                               DID_PASSTHROUGH : DID_ERROR);
                break;
        case CMD_CONNECTION_LOST:
                printk(KERN_WARNING "cciss: cmd %p had "
                       "connection lost\n", cmd);
                rq->errors = make_status_bytes(SAM_STAT_GOOD,
                        cmd->err_info->CommandStatus, DRIVER_OK,
-                       blk_pc_request(cmd->rq) ? DID_PASSTHROUGH : DID_ERROR);
+                       (cmd->rq->cmd_type == REQ_TYPE_BLOCK_PC) ?
+                               DID_PASSTHROUGH : DID_ERROR);
                break;
        case CMD_ABORTED:
                printk(KERN_WARNING "cciss: cmd %p was "
                       "aborted\n", cmd);
                rq->errors = make_status_bytes(SAM_STAT_GOOD,
                        cmd->err_info->CommandStatus, DRIVER_OK,
-                       blk_pc_request(cmd->rq) ? DID_PASSTHROUGH : DID_ABORT);
+                       (cmd->rq->cmd_type == REQ_TYPE_BLOCK_PC) ?
+                               DID_PASSTHROUGH : DID_ABORT);
                break;
        case CMD_ABORT_FAILED:
                printk(KERN_WARNING "cciss: cmd %p reports "
                       "abort failed\n", cmd);
                rq->errors = make_status_bytes(SAM_STAT_GOOD,
                        cmd->err_info->CommandStatus, DRIVER_OK,
-                       blk_pc_request(cmd->rq) ? DID_PASSTHROUGH : DID_ERROR);
+                       (cmd->rq->cmd_type == REQ_TYPE_BLOCK_PC) ?
+                               DID_PASSTHROUGH : DID_ERROR);
                break;
        case CMD_UNSOLICITED_ABORT:
                printk(KERN_WARNING "cciss%d: unsolicited "
@@ -3104,13 +3153,15 @@ static inline void complete_command(ctlr_info_t *h, CommandList_struct *cmd,
                               "many times\n", h->ctlr, cmd);
                rq->errors = make_status_bytes(SAM_STAT_GOOD,
                        cmd->err_info->CommandStatus, DRIVER_OK,
-                       blk_pc_request(cmd->rq) ? DID_PASSTHROUGH : DID_ABORT);
+                       (cmd->rq->cmd_type == REQ_TYPE_BLOCK_PC) ?
+                               DID_PASSTHROUGH : DID_ABORT);
                break;
        case CMD_TIMEOUT:
                printk(KERN_WARNING "cciss: cmd %p timedout\n", cmd);
                rq->errors = make_status_bytes(SAM_STAT_GOOD,
                        cmd->err_info->CommandStatus, DRIVER_OK,
-                       blk_pc_request(cmd->rq) ? DID_PASSTHROUGH : DID_ERROR);
+                       (cmd->rq->cmd_type == REQ_TYPE_BLOCK_PC) ?
+                               DID_PASSTHROUGH : DID_ERROR);
                break;
        default:
                printk(KERN_WARNING "cciss: cmd %p returned "
@@ -3118,7 +3169,8 @@ static inline void complete_command(ctlr_info_t *h, CommandList_struct *cmd,
                       cmd->err_info->CommandStatus);
                rq->errors = make_status_bytes(SAM_STAT_GOOD,
                        cmd->err_info->CommandStatus, DRIVER_OK,
-                       blk_pc_request(cmd->rq) ? DID_PASSTHROUGH : DID_ERROR);
+                       (cmd->rq->cmd_type == REQ_TYPE_BLOCK_PC) ?
+                               DID_PASSTHROUGH : DID_ERROR);
        }
 
 after_error_processing:
@@ -3132,6 +3184,34 @@ after_error_processing:
        blk_complete_request(cmd->rq);
 }
 
+static inline u32 cciss_tag_contains_index(u32 tag)
+{
+#define DIRECT_LOOKUP_BIT 0x10
+       return tag & DIRECT_LOOKUP_BIT;
+}
+
+static inline u32 cciss_tag_to_index(u32 tag)
+{
+#define DIRECT_LOOKUP_SHIFT 5
+       return tag >> DIRECT_LOOKUP_SHIFT;
+}
+
+static inline u32 cciss_tag_discard_error_bits(u32 tag)
+{
+#define CCISS_ERROR_BITS 0x03
+       return tag & ~CCISS_ERROR_BITS;
+}
+
+static inline void cciss_mark_tag_indexed(u32 *tag)
+{
+       *tag |= DIRECT_LOOKUP_BIT;
+}
+
+static inline void cciss_set_tag_index(u32 *tag, u32 index)
+{
+       *tag |= (index << DIRECT_LOOKUP_SHIFT);
+}
+
 /*
  * Get a request and submit it to the controller.
  */
@@ -3180,8 +3260,8 @@ static void do_cciss_request(struct request_queue *q)
        /* got command from pool, so use the command block index instead */
        /* for direct lookups. */
        /* The first 2 bits are reserved for controller error reporting. */
-       c->Header.Tag.lower = (c->cmdindex << 3);
-       c->Header.Tag.lower |= 0x04;    /* flag for direct lookup. */
+       cciss_set_tag_index(&c->Header.Tag.lower, c->cmdindex);
+       cciss_mark_tag_indexed(&c->Header.Tag.lower);
        memcpy(&c->Header.LUN, drv->LunID, sizeof(drv->LunID));
        c->Request.CDBLen = 10; /* 12 byte commands not in FW yet; */
        c->Request.Type.Type = TYPE_CMD;        /* It is a command. */
@@ -3242,11 +3322,14 @@ static void do_cciss_request(struct request_queue *q)
                        blk_rq_sectors(creq), seg, chained);
 #endif                         /* CCISS_DEBUG */
 
-       c->Header.SGList = c->Header.SGTotal = seg + chained;
-       if (seg > h->max_cmd_sgentries)
+       c->Header.SGTotal = seg + chained;
+       if (seg <= h->max_cmd_sgentries)
+               c->Header.SGList = c->Header.SGTotal;
+       else
                c->Header.SGList = h->max_cmd_sgentries;
+       set_performant_mode(h, c);
 
-       if (likely(blk_fs_request(creq))) {
+       if (likely(creq->cmd_type == REQ_TYPE_FS)) {
                if(h->cciss_read == CCISS_READ_10) {
                        c->Request.CDB[1] = 0;
                        c->Request.CDB[2] = (start_blk >> 24) & 0xff; /* MSB */
@@ -3276,7 +3359,7 @@ static void do_cciss_request(struct request_queue *q)
                        c->Request.CDB[13]= blk_rq_sectors(creq) & 0xff;
                        c->Request.CDB[14] = c->Request.CDB[15] = 0;
                }
-       } else if (blk_pc_request(creq)) {
+       } else if (creq->cmd_type == REQ_TYPE_BLOCK_PC) {
                c->Request.CDBLen = creq->cmd_len;
                memcpy(c->Request.CDB, creq->cmd, BLK_MAX_CDB);
        } else {
@@ -3313,16 +3396,97 @@ static inline int interrupt_pending(ctlr_info_t *h)
 
 static inline long interrupt_not_for_us(ctlr_info_t *h)
 {
-       return (((h->access.intr_pending(h) == 0) ||
-                (h->interrupts_enabled == 0)));
+       return !(h->msi_vector || h->msix_vector) &&
+               ((h->access.intr_pending(h) == 0) ||
+               (h->interrupts_enabled == 0));
 }
 
-static irqreturn_t do_cciss_intr(int irq, void *dev_id)
+static inline int bad_tag(ctlr_info_t *h, u32 tag_index,
+                       u32 raw_tag)
 {
-       ctlr_info_t *h = dev_id;
+       if (unlikely(tag_index >= h->nr_cmds)) {
+               dev_warn(&h->pdev->dev, "bad tag 0x%08x ignored.\n", raw_tag);
+               return 1;
+       }
+       return 0;
+}
+
+static inline void finish_cmd(ctlr_info_t *h, CommandList_struct *c,
+                               u32 raw_tag)
+{
+       removeQ(c);
+       if (likely(c->cmd_type == CMD_RWREQ))
+               complete_command(h, c, 0);
+       else if (c->cmd_type == CMD_IOCTL_PEND)
+               complete(c->waiting);
+#ifdef CONFIG_CISS_SCSI_TAPE
+       else if (c->cmd_type == CMD_SCSI)
+               complete_scsi_command(c, 0, raw_tag);
+#endif
+}
+
+static inline u32 next_command(ctlr_info_t *h)
+{
+       u32 a;
+
+       if (unlikely(h->transMethod != CFGTBL_Trans_Performant))
+               return h->access.command_completed(h);
+
+       if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
+               a = *(h->reply_pool_head); /* Next cmd in ring buffer */
+               (h->reply_pool_head)++;
+               h->commands_outstanding--;
+       } else {
+               a = FIFO_EMPTY;
+       }
+       /* Check for wraparound */
+       if (h->reply_pool_head == (h->reply_pool + h->max_commands)) {
+               h->reply_pool_head = h->reply_pool;
+               h->reply_pool_wraparound ^= 1;
+       }
+       return a;
+}
+
+/* process completion of an indexed ("direct lookup") command */
+static inline u32 process_indexed_cmd(ctlr_info_t *h, u32 raw_tag)
+{
+       u32 tag_index;
        CommandList_struct *c;
+
+       tag_index = cciss_tag_to_index(raw_tag);
+       if (bad_tag(h, tag_index, raw_tag))
+               return next_command(h);
+       c = h->cmd_pool + tag_index;
+       finish_cmd(h, c, raw_tag);
+       return next_command(h);
+}
+
+/* process completion of a non-indexed command */
+static inline u32 process_nonindexed_cmd(ctlr_info_t *h, u32 raw_tag)
+{
+       u32 tag;
+       CommandList_struct *c = NULL;
+       struct hlist_node *tmp;
+       __u32 busaddr_masked, tag_masked;
+
+       tag = cciss_tag_discard_error_bits(raw_tag);
+       hlist_for_each_entry(c, tmp, &h->cmpQ, list) {
+               busaddr_masked = cciss_tag_discard_error_bits(c->busaddr);
+               tag_masked = cciss_tag_discard_error_bits(tag);
+               if (busaddr_masked == tag_masked) {
+                       finish_cmd(h, c, raw_tag);
+                       return next_command(h);
+               }
+       }
+       bad_tag(h, h->nr_cmds + 1, raw_tag);
+       return next_command(h);
+}
+
+static irqreturn_t do_cciss_intx(int irq, void *dev_id)
+{
+       ctlr_info_t *h = dev_id;
        unsigned long flags;
-       __u32 a, a1, a2;
+       u32 raw_tag;
 
        if (interrupt_not_for_us(h))
                return IRQ_NONE;
@@ -3332,50 +3496,41 @@ static irqreturn_t do_cciss_intr(int irq, void *dev_id)
         */
        spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags);
        while (interrupt_pending(h)) {
-               while ((a = get_next_completion(h)) != FIFO_EMPTY) {
-                       a1 = a;
-                       if ((a & 0x04)) {
-                               a2 = (a >> 3);
-                               if (a2 >= h->nr_cmds) {
-                                       printk(KERN_WARNING
-                                              "cciss: controller cciss%d failed, stopping.\n",
-                                              h->ctlr);
-                                       spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
-                                       fail_all_cmds(h->ctlr);
-                                       return IRQ_HANDLED;
-                               }
+               raw_tag = get_next_completion(h);
+               while (raw_tag != FIFO_EMPTY) {
+                       if (cciss_tag_contains_index(raw_tag))
+                               raw_tag = process_indexed_cmd(h, raw_tag);
+                       else
+                               raw_tag = process_nonindexed_cmd(h, raw_tag);
+               }
+       }
 
-                               c = h->cmd_pool + a2;
-                               a = c->busaddr;
+       spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
+       return IRQ_HANDLED;
+}
 
-                       } else {
-                               struct hlist_node *tmp;
+/* Add a second interrupt handler for MSI/MSI-X mode. In this mode we never
+ * check the interrupt pending register because it is not set.
+ */
+static irqreturn_t do_cciss_msix_intr(int irq, void *dev_id)
+{
+       ctlr_info_t *h = dev_id;
+       unsigned long flags;
+       u32 raw_tag;
 
-                               a &= ~3;
-                               c = NULL;
-                               hlist_for_each_entry(c, tmp, &h->cmpQ, list) {
-                                       if (c->busaddr == a)
-                                               break;
-                               }
-                       }
-                       /*
-                        * If we've found the command, take it off the
-                        * completion Q and free it
-                        */
-                       if (c && c->busaddr == a) {
-                               removeQ(c);
-                               if (c->cmd_type == CMD_RWREQ) {
-                                       complete_command(h, c, 0);
-                               } else if (c->cmd_type == CMD_IOCTL_PEND) {
-                                       complete(c->waiting);
-                               }
-#                              ifdef CONFIG_CISS_SCSI_TAPE
-                               else if (c->cmd_type == CMD_SCSI)
-                                       complete_scsi_command(c, 0, a1);
-#                              endif
-                               continue;
-                       }
-               }
+       if (interrupt_not_for_us(h))
+               return IRQ_NONE;
+       /*
+        * If there are completed commands in the completion queue,
+        * we had better do something about it.
+        */
+       spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags);
+       raw_tag = get_next_completion(h);
+       while (raw_tag != FIFO_EMPTY) {
+               if (cciss_tag_contains_index(raw_tag))
+                       raw_tag = process_indexed_cmd(h, raw_tag);
+               else
+                       raw_tag = process_nonindexed_cmd(h, raw_tag);
        }
 
        spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
@@ -3562,9 +3717,9 @@ static int check_for_unit_attention(ctlr_info_t *h, CommandList_struct *c)
  *   the io functions.
  *   This is for debug only.
  */
-#ifdef CCISS_DEBUG
 static void print_cfg_table(CfgTable_struct *tb)
 {
+#ifdef CCISS_DEBUG
        int i;
        char temp_name[17];
 
@@ -3593,8 +3748,8 @@ static void print_cfg_table(CfgTable_struct *tb)
        temp_name[16] = '\0';
        printk("   Server Name = %s\n", temp_name);
        printk("   Heartbeat Counter = 0x%x\n\n\n", readl(&(tb->HeartBeat)));
-}
 #endif                         /* CCISS_DEBUG */
+}
 
 static int find_PCI_BAR_index(struct pci_dev *pdev, unsigned long pci_bar_addr)
 {
@@ -3630,12 +3785,183 @@ static int find_PCI_BAR_index(struct pci_dev *pdev, unsigned long pci_bar_addr)
        return -1;
 }
 
+/* Fill in bucket_map[], given nsgs (the max number of
+ * scatter gather elements supported) and bucket[],
+ * which is an array of 8 integers.  The bucket[] array
+ * contains 8 different DMA transfer sizes (in 16
+ * byte increments) which the controller uses to fetch
+ * commands.  This function fills in bucket_map[], which
+ * maps a given number of scatter gather elements to one of
+ * the 8 DMA transfer sizes.  The point of it is to allow the
+ * controller to only do as much DMA as needed to fetch the
+ * command, with the DMA transfer size encoded in the lower
+ * bits of the command address.
+ */
+static void  calc_bucket_map(int bucket[], int num_buckets,
+       int nsgs, int *bucket_map)
+{
+       int i, j, b, size;
+
+       /* even a command with 0 SGs requires 4 blocks */
+#define MINIMUM_TRANSFER_BLOCKS 4
+#define NUM_BUCKETS 8
+       /* Note, bucket_map must have nsgs+1 entries. */
+       for (i = 0; i <= nsgs; i++) {
+               /* Compute size of a command with i SG entries */
+               size = i + MINIMUM_TRANSFER_BLOCKS;
+               b = num_buckets; /* Assume the biggest bucket */
+               /* Find the bucket that is just big enough */
+               for (j = 0; j < 8; j++) {
+                       if (bucket[j] >= size) {
+                               b = j;
+                               break;
+                       }
+               }
+               /* for a command with i SG entries, use bucket b. */
+               bucket_map[i] = b;
+       }
+}
+
+static void __devinit cciss_wait_for_mode_change_ack(ctlr_info_t *h)
+{
+       int i;
+
+       /* under certain very rare conditions, this can take awhile.
+        * (e.g.: hot replace a failed 144GB drive in a RAID 5 set right
+        * as we enter this code.) */
+       for (i = 0; i < MAX_CONFIG_WAIT; i++) {
+               if (!(readl(h->vaddr + SA5_DOORBELL) & CFGTBL_ChangeReq))
+                       break;
+               msleep(10);
+       }
+}
+
+static __devinit void cciss_enter_performant_mode(ctlr_info_t *h)
+{
+       /* This is a bit complicated.  There are 8 registers on
+        * the controller which we write to to tell it 8 different
+        * sizes of commands which there may be.  It's a way of
+        * reducing the DMA done to fetch each command.  Encoded into
+        * each command's tag are 3 bits which communicate to the controller
+        * which of the eight sizes that command fits within.  The size of
+        * each command depends on how many scatter gather entries there are.
+        * Each SG entry requires 16 bytes.  The eight registers are programmed
+        * with the number of 16-byte blocks a command of that size requires.
+        * The smallest command possible requires 5 such 16 byte blocks.
+        * the largest command possible requires MAXSGENTRIES + 4 16-byte
+        * blocks.  Note, this only extends to the SG entries contained
+        * within the command block, and does not extend to chained blocks
+        * of SG elements.   bft[] contains the eight values we write to
+        * the registers.  They are not evenly distributed, but have more
+        * sizes for small commands, and fewer sizes for larger commands.
+        */
+       __u32 trans_offset;
+       int bft[8] = { 5, 6, 8, 10, 12, 20, 28, MAXSGENTRIES + 4};
+                       /*
+                        *  5 = 1 s/g entry or 4k
+                        *  6 = 2 s/g entry or 8k
+                        *  8 = 4 s/g entry or 16k
+                        * 10 = 6 s/g entry or 24k
+                        */
+       unsigned long register_value;
+       BUILD_BUG_ON(28 > MAXSGENTRIES + 4);
+
+       h->reply_pool_wraparound = 1; /* spec: init to 1 */
+
+       /* Controller spec: zero out this buffer. */
+       memset(h->reply_pool, 0, h->max_commands * sizeof(__u64));
+       h->reply_pool_head = h->reply_pool;
+
+       trans_offset = readl(&(h->cfgtable->TransMethodOffset));
+       calc_bucket_map(bft, ARRAY_SIZE(bft), h->maxsgentries,
+                               h->blockFetchTable);
+       writel(bft[0], &h->transtable->BlockFetch0);
+       writel(bft[1], &h->transtable->BlockFetch1);
+       writel(bft[2], &h->transtable->BlockFetch2);
+       writel(bft[3], &h->transtable->BlockFetch3);
+       writel(bft[4], &h->transtable->BlockFetch4);
+       writel(bft[5], &h->transtable->BlockFetch5);
+       writel(bft[6], &h->transtable->BlockFetch6);
+       writel(bft[7], &h->transtable->BlockFetch7);
+
+       /* size of controller ring buffer */
+       writel(h->max_commands, &h->transtable->RepQSize);
+       writel(1, &h->transtable->RepQCount);
+       writel(0, &h->transtable->RepQCtrAddrLow32);
+       writel(0, &h->transtable->RepQCtrAddrHigh32);
+       writel(h->reply_pool_dhandle, &h->transtable->RepQAddr0Low32);
+       writel(0, &h->transtable->RepQAddr0High32);
+       writel(CFGTBL_Trans_Performant,
+                       &(h->cfgtable->HostWrite.TransportRequest));
+
+       writel(CFGTBL_ChangeReq, h->vaddr + SA5_DOORBELL);
+       cciss_wait_for_mode_change_ack(h);
+       register_value = readl(&(h->cfgtable->TransportActive));
+       if (!(register_value & CFGTBL_Trans_Performant))
+               printk(KERN_WARNING "cciss: unable to get board into"
+                                       " performant mode\n");
+}
+
+static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
+{
+       __u32 trans_support;
+
+       dev_dbg(&h->pdev->dev, "Trying to put board into Performant mode\n");
+       /* Attempt to put controller into performant mode if supported */
+       /* Does board support performant mode? */
+       trans_support = readl(&(h->cfgtable->TransportSupport));
+       if (!(trans_support & PERFORMANT_MODE))
+               return;
+
+       printk(KERN_WARNING "cciss%d: Placing controller into "
+                               "performant mode\n", h->ctlr);
+       /* Performant mode demands commands on a 32 byte boundary
+        * pci_alloc_consistent aligns on page boundarys already.
+        * Just need to check if divisible by 32
+        */
+       if ((sizeof(CommandList_struct) % 32) != 0) {
+               printk(KERN_WARNING "%s %d %s\n",
+                       "cciss info: command size[",
+                       (int)sizeof(CommandList_struct),
+                       "] not divisible by 32, no performant mode..\n");
+               return;
+       }
+
+       /* Performant mode ring buffer and supporting data structures */
+       h->reply_pool = (__u64 *)pci_alloc_consistent(
+               h->pdev, h->max_commands * sizeof(__u64),
+               &(h->reply_pool_dhandle));
+
+       /* Need a block fetch table for performant mode */
+       h->blockFetchTable = kmalloc(((h->maxsgentries+1) *
+               sizeof(__u32)), GFP_KERNEL);
+
+       if ((h->reply_pool == NULL) || (h->blockFetchTable == NULL))
+               goto clean_up;
+
+       cciss_enter_performant_mode(h);
+
+       /* Change the access methods to the performant access methods */
+       h->access = SA5_performant_access;
+       h->transMethod = CFGTBL_Trans_Performant;
+
+       return;
+clean_up:
+       kfree(h->blockFetchTable);
+       if (h->reply_pool)
+               pci_free_consistent(h->pdev,
+                               h->max_commands * sizeof(__u64),
+                               h->reply_pool,
+                               h->reply_pool_dhandle);
+       return;
+
+} /* cciss_put_controller_into_performant_mode */
+
 /* If MSI/MSI-X is supported by the kernel we will try to enable it on
  * controllers that are capable. If not, we use IO-APIC mode.
  */
 
-static void __devinit cciss_interrupt_mode(ctlr_info_t *c,
-                                          struct pci_dev *pdev, __u32 board_id)
+static void __devinit cciss_interrupt_mode(ctlr_info_t *c)
 {
 #ifdef CONFIG_PCI_MSI
        int err;
@@ -3644,13 +3970,12 @@ static void __devinit cciss_interrupt_mode(ctlr_info_t *c,
        };
 
        /* Some boards advertise MSI but don't really support it */
-       if ((board_id == 0x40700E11) ||
-           (board_id == 0x40800E11) ||
-           (board_id == 0x40820E11) || (board_id == 0x40830E11))
+       if ((c->board_id == 0x40700E11) || (c->board_id == 0x40800E11) ||
+           (c->board_id == 0x40820E11) || (c->board_id == 0x40830E11))
                goto default_int_mode;
 
-       if (pci_find_capability(pdev, PCI_CAP_ID_MSIX)) {
-               err = pci_enable_msix(pdev, cciss_msix_entries, 4);
+       if (pci_find_capability(c->pdev, PCI_CAP_ID_MSIX)) {
+               err = pci_enable_msix(c->pdev, cciss_msix_entries, 4);
                if (!err) {
                        c->intr[0] = cciss_msix_entries[0].vector;
                        c->intr[1] = cciss_msix_entries[1].vector;
@@ -3669,8 +3994,8 @@ static void __devinit cciss_interrupt_mode(ctlr_info_t *c,
                        goto default_int_mode;
                }
        }
-       if (pci_find_capability(pdev, PCI_CAP_ID_MSI)) {
-               if (!pci_enable_msi(pdev)) {
+       if (pci_find_capability(c->pdev, PCI_CAP_ID_MSI)) {
+               if (!pci_enable_msi(c->pdev)) {
                        c->msi_vector = 1;
                } else {
                        printk(KERN_WARNING "cciss: MSI init failed\n");
@@ -3679,233 +4004,254 @@ static void __devinit cciss_interrupt_mode(ctlr_info_t *c,
 default_int_mode:
 #endif                         /* CONFIG_PCI_MSI */
        /* if we get here we're going to use the default interrupt mode */
-       c->intr[SIMPLE_MODE_INT] = pdev->irq;
+       c->intr[PERF_MODE_INT] = c->pdev->irq;
        return;
 }
 
-static int __devinit cciss_pci_init(ctlr_info_t *c, struct pci_dev *pdev)
+static int __devinit cciss_lookup_board_id(struct pci_dev *pdev, u32 *board_id)
 {
-       ushort subsystem_vendor_id, subsystem_device_id, command;
-       __u32 board_id, scratchpad = 0;
-       __u64 cfg_offset;
-       __u32 cfg_base_addr;
-       __u64 cfg_base_addr_index;
-       int i, prod_index, err;
+       int i;
+       u32 subsystem_vendor_id, subsystem_device_id;
 
        subsystem_vendor_id = pdev->subsystem_vendor;
        subsystem_device_id = pdev->subsystem_device;
-       board_id = (((__u32) (subsystem_device_id << 16) & 0xffff0000) |
-                   subsystem_vendor_id);
+       *board_id = ((subsystem_device_id << 16) & 0xffff0000) |
+                       subsystem_vendor_id;
 
        for (i = 0; i < ARRAY_SIZE(products); i++) {
                /* Stand aside for hpsa driver on request */
                if (cciss_allow_hpsa && products[i].board_id == HPSA_BOUNDARY)
                        return -ENODEV;
-               if (board_id == products[i].board_id)
-                       break;
-       }
-       prod_index = i;
-       if (prod_index == ARRAY_SIZE(products)) {
-               dev_warn(&pdev->dev,
-                       "unrecognized board ID: 0x%08lx, ignoring.\n",
-                       (unsigned long) board_id);
-               return -ENODEV;
+               if (*board_id == products[i].board_id)
+                       return i;
        }
+       dev_warn(&pdev->dev, "unrecognized board ID: 0x%08x, ignoring.\n",
+               *board_id);
+       return -ENODEV;
+}
 
-       /* check to see if controller has been disabled */
-       /* BEFORE trying to enable it */
-       (void)pci_read_config_word(pdev, PCI_COMMAND, &command);
-       if (!(command & 0x02)) {
-               printk(KERN_WARNING
-                      "cciss: controller appears to be disabled\n");
-               return -ENODEV;
-       }
+static inline bool cciss_board_disabled(ctlr_info_t *h)
+{
+       u16 command;
 
-       err = pci_enable_device(pdev);
-       if (err) {
-               printk(KERN_ERR "cciss: Unable to Enable PCI device\n");
-               return err;
-       }
+       (void) pci_read_config_word(h->pdev, PCI_COMMAND, &command);
+       return ((command & PCI_COMMAND_MEMORY) == 0);
+}
 
-       err = pci_request_regions(pdev, "cciss");
-       if (err) {
-               printk(KERN_ERR "cciss: Cannot obtain PCI resources, "
-                      "aborting\n");
-               return err;
-       }
+static int __devinit cciss_pci_find_memory_BAR(struct pci_dev *pdev,
+       unsigned long *memory_bar)
+{
+       int i;
 
-#ifdef CCISS_DEBUG
-       printk("command = %x\n", command);
-       printk("irq = %x\n", pdev->irq);
-       printk("board_id = %x\n", board_id);
-#endif                         /* CCISS_DEBUG */
+       for (i = 0; i < DEVICE_COUNT_RESOURCE; i++)
+               if (pci_resource_flags(pdev, i) & IORESOURCE_MEM) {
+                       /* addressing mode bits already removed */
+                       *memory_bar = pci_resource_start(pdev, i);
+                       dev_dbg(&pdev->dev, "memory BAR = %lx\n",
+                               *memory_bar);
+                       return 0;
+               }
+       dev_warn(&pdev->dev, "no memory BAR found\n");
+       return -ENODEV;
+}
 
-/* If the kernel supports MSI/MSI-X we will try to enable that functionality,
- * else we use the IO-APIC interrupt assigned to us by system ROM.
- */
-       cciss_interrupt_mode(c, pdev, board_id);
+static int __devinit cciss_wait_for_board_ready(ctlr_info_t *h)
+{
+       int i;
+       u32 scratchpad;
 
-       /* find the memory BAR */
-       for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
-               if (pci_resource_flags(pdev, i) & IORESOURCE_MEM)
-                       break;
+       for (i = 0; i < CCISS_BOARD_READY_ITERATIONS; i++) {
+               scratchpad = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
+               if (scratchpad == CCISS_FIRMWARE_READY)
+                       return 0;
+               msleep(CCISS_BOARD_READY_POLL_INTERVAL_MSECS);
        }
-       if (i == DEVICE_COUNT_RESOURCE) {
-               printk(KERN_WARNING "cciss: No memory BAR found\n");
-               err = -ENODEV;
-               goto err_out_free_res;
+       dev_warn(&h->pdev->dev, "board not ready, timed out.\n");
+       return -ENODEV;
+}
+
+static int __devinit cciss_find_cfg_addrs(struct pci_dev *pdev,
+       void __iomem *vaddr, u32 *cfg_base_addr, u64 *cfg_base_addr_index,
+       u64 *cfg_offset)
+{
+       *cfg_base_addr = readl(vaddr + SA5_CTCFG_OFFSET);
+       *cfg_offset = readl(vaddr + SA5_CTMEM_OFFSET);
+       *cfg_base_addr &= (u32) 0x0000ffff;
+       *cfg_base_addr_index = find_PCI_BAR_index(pdev, *cfg_base_addr);
+       if (*cfg_base_addr_index == -1) {
+               dev_warn(&pdev->dev, "cannot find cfg_base_addr_index, "
+                       "*cfg_base_addr = 0x%08x\n", *cfg_base_addr);
+               return -ENODEV;
        }
+       return 0;
+}
 
-       c->paddr = pci_resource_start(pdev, i); /* addressing mode bits
-                                                * already removed
-                                                */
+static int __devinit cciss_find_cfgtables(ctlr_info_t *h)
+{
+       u64 cfg_offset;
+       u32 cfg_base_addr;
+       u64 cfg_base_addr_index;
+       u32 trans_offset;
+       int rc;
 
-#ifdef CCISS_DEBUG
-       printk("address 0 = %lx\n", c->paddr);
-#endif                         /* CCISS_DEBUG */
-       c->vaddr = remap_pci_mem(c->paddr, 0x250);
+       rc = cciss_find_cfg_addrs(h->pdev, h->vaddr, &cfg_base_addr,
+               &cfg_base_addr_index, &cfg_offset);
+       if (rc)
+               return rc;
+       h->cfgtable = remap_pci_mem(pci_resource_start(h->pdev,
+               cfg_base_addr_index) + cfg_offset, sizeof(h->cfgtable));
+       if (!h->cfgtable)
+               return -ENOMEM;
+       /* Find performant mode table. */
+       trans_offset = readl(&h->cfgtable->TransMethodOffset);
+       h->transtable = remap_pci_mem(pci_resource_start(h->pdev,
+                               cfg_base_addr_index)+cfg_offset+trans_offset,
+                               sizeof(*h->transtable));
+       if (!h->transtable)
+               return -ENOMEM;
+       return 0;
+}
 
-       /* Wait for the board to become ready.  (PCI hotplug needs this.)
-        * We poll for up to 120 secs, once per 100ms. */
-       for (i = 0; i < 1200; i++) {
-               scratchpad = readl(c->vaddr + SA5_SCRATCHPAD_OFFSET);
-               if (scratchpad == CCISS_FIRMWARE_READY)
-                       break;
-               set_current_state(TASK_INTERRUPTIBLE);
-               schedule_timeout(msecs_to_jiffies(100));        /* wait 100ms */
+static void __devinit cciss_get_max_perf_mode_cmds(struct ctlr_info *h)
+{
+       h->max_commands = readl(&(h->cfgtable->MaxPerformantModeCommands));
+       if (h->max_commands < 16) {
+               dev_warn(&h->pdev->dev, "Controller reports "
+                       "max supported commands of %d, an obvious lie. "
+                       "Using 16.  Ensure that firmware is up to date.\n",
+                       h->max_commands);
+               h->max_commands = 16;
        }
-       if (scratchpad != CCISS_FIRMWARE_READY) {
-               printk(KERN_WARNING "cciss: Board not ready.  Timed out.\n");
-               err = -ENODEV;
-               goto err_out_free_res;
+}
+
+/* Interrogate the hardware for some limits:
+ * max commands, max SG elements without chaining, and with chaining,
+ * SG chain block size, etc.
+ */
+static void __devinit cciss_find_board_params(ctlr_info_t *h)
+{
+       cciss_get_max_perf_mode_cmds(h);
+       h->nr_cmds = h->max_commands - 4; /* Allow room for some ioctls */
+       h->maxsgentries = readl(&(h->cfgtable->MaxSGElements));
+       /*
+        * Limit in-command s/g elements to 32 save dma'able memory.
+        * Howvever spec says if 0, use 31
+        */
+       h->max_cmd_sgentries = 31;
+       if (h->maxsgentries > 512) {
+               h->max_cmd_sgentries = 32;
+               h->chainsize = h->maxsgentries - h->max_cmd_sgentries + 1;
+               h->maxsgentries--; /* save one for chain pointer */
+       } else {
+               h->maxsgentries = 31; /* default to traditional values */
+               h->chainsize = 0;
        }
+}
 
-       /* get the address index number */
-       cfg_base_addr = readl(c->vaddr + SA5_CTCFG_OFFSET);
-       cfg_base_addr &= (__u32) 0x0000ffff;
-#ifdef CCISS_DEBUG
-       printk("cfg base address = %x\n", cfg_base_addr);
-#endif                         /* CCISS_DEBUG */
-       cfg_base_addr_index = find_PCI_BAR_index(pdev, cfg_base_addr);
-#ifdef CCISS_DEBUG
-       printk("cfg base address index = %llx\n",
-               (unsigned long long)cfg_base_addr_index);
-#endif                         /* CCISS_DEBUG */
-       if (cfg_base_addr_index == -1) {
-               printk(KERN_WARNING "cciss: Cannot find cfg_base_addr_index\n");
-               err = -ENODEV;
-               goto err_out_free_res;
+static inline bool CISS_signature_present(ctlr_info_t *h)
+{
+       if ((readb(&h->cfgtable->Signature[0]) != 'C') ||
+           (readb(&h->cfgtable->Signature[1]) != 'I') ||
+           (readb(&h->cfgtable->Signature[2]) != 'S') ||
+           (readb(&h->cfgtable->Signature[3]) != 'S')) {
+               dev_warn(&h->pdev->dev, "not a valid CISS config table\n");
+               return false;
        }
+       return true;
+}
 
-       cfg_offset = readl(c->vaddr + SA5_CTMEM_OFFSET);
-#ifdef CCISS_DEBUG
-       printk("cfg offset = %llx\n", (unsigned long long)cfg_offset);
-#endif                         /* CCISS_DEBUG */
-       c->cfgtable = remap_pci_mem(pci_resource_start(pdev,
-                                                      cfg_base_addr_index) +
-                                   cfg_offset, sizeof(CfgTable_struct));
-       c->board_id = board_id;
+/* Need to enable prefetch in the SCSI core for 6400 in x86 */
+static inline void cciss_enable_scsi_prefetch(ctlr_info_t *h)
+{
+#ifdef CONFIG_X86
+       u32 prefetch;
 
-#ifdef CCISS_DEBUG
-       print_cfg_table(c->cfgtable);
-#endif                         /* CCISS_DEBUG */
+       prefetch = readl(&(h->cfgtable->SCSI_Prefetch));
+       prefetch |= 0x100;
+       writel(prefetch, &(h->cfgtable->SCSI_Prefetch));
+#endif
+}
 
-       /* Some controllers support Zero Memory Raid (ZMR).
-        * When configured in ZMR mode the number of supported
-        * commands drops to 64. So instead of just setting an
-        * arbitrary value we make the driver a little smarter.
-        * We read the config table to tell us how many commands
-        * are supported on the controller then subtract 4 to
-        * leave a little room for ioctl calls.
-        */
-       c->max_commands = readl(&(c->cfgtable->CmdsOutMax));
-       c->maxsgentries = readl(&(c->cfgtable->MaxSGElements));
+/* Disable DMA prefetch for the P600.  Otherwise an ASIC bug may result
+ * in a prefetch beyond physical memory.
+ */
+static inline void cciss_p600_dma_prefetch_quirk(ctlr_info_t *h)
+{
+       u32 dma_prefetch;
+       __u32 dma_refetch;
 
-       /*
-        * Limit native command to 32 s/g elements to save dma'able memory.
-        * Howvever spec says if 0, use 31
-        */
+       if (h->board_id != 0x3225103C)
+               return;
+       dma_prefetch = readl(h->vaddr + I2O_DMA1_CFG);
+       dma_prefetch |= 0x8000;
+       writel(dma_prefetch, h->vaddr + I2O_DMA1_CFG);
+       pci_read_config_dword(h->pdev, PCI_COMMAND_PARITY, &dma_refetch);
+       dma_refetch |= 0x1;
+       pci_write_config_dword(h->pdev, PCI_COMMAND_PARITY, dma_refetch);
+}
 
-       c->max_cmd_sgentries = 31;
-       if (c->maxsgentries > 512) {
-               c->max_cmd_sgentries = 32;
-               c->chainsize = c->maxsgentries - c->max_cmd_sgentries + 1;
-               c->maxsgentries -= 1;   /* account for chain pointer */
-       } else {
-               c->maxsgentries = 31;   /* Default to traditional value */
-               c->chainsize = 0;       /* traditional */
-       }
+static int __devinit cciss_pci_init(ctlr_info_t *c)
+{
+       int prod_index, err;
 
+       prod_index = cciss_lookup_board_id(c->pdev, &c->board_id);
+       if (prod_index < 0)
+               return -ENODEV;
        c->product_name = products[prod_index].product_name;
        c->access = *(products[prod_index].access);
-       c->nr_cmds = c->max_commands - 4;
-       if ((readb(&c->cfgtable->Signature[0]) != 'C') ||
-           (readb(&c->cfgtable->Signature[1]) != 'I') ||
-           (readb(&c->cfgtable->Signature[2]) != 'S') ||
-           (readb(&c->cfgtable->Signature[3]) != 'S')) {
-               printk("Does not appear to be a valid CISS config table\n");
-               err = -ENODEV;
-               goto err_out_free_res;
+
+       if (cciss_board_disabled(c)) {
+               printk(KERN_WARNING
+                      "cciss: controller appears to be disabled\n");
+               return -ENODEV;
        }
-#ifdef CONFIG_X86
-       {
-               /* Need to enable prefetch in the SCSI core for 6400 in x86 */
-               __u32 prefetch;
-               prefetch = readl(&(c->cfgtable->SCSI_Prefetch));
-               prefetch |= 0x100;
-               writel(prefetch, &(c->cfgtable->SCSI_Prefetch));
+       err = pci_enable_device(c->pdev);
+       if (err) {
+               printk(KERN_ERR "cciss: Unable to Enable PCI device\n");
+               return err;
        }
-#endif
 
-       /* Disabling DMA prefetch and refetch for the P600.
-        * An ASIC bug may result in accesses to invalid memory addresses.
-        * We've disabled prefetch for some time now. Testing with XEN
-        * kernels revealed a bug in the refetch if dom0 resides on a P600.
-        */
-       if(board_id == 0x3225103C) {
-               __u32 dma_prefetch;
-               __u32 dma_refetch;
-               dma_prefetch = readl(c->vaddr + I2O_DMA1_CFG);
-               dma_prefetch |= 0x8000;
-               writel(dma_prefetch, c->vaddr + I2O_DMA1_CFG);
-               pci_read_config_dword(pdev, PCI_COMMAND_PARITY, &dma_refetch);
-               dma_refetch |= 0x1;
-               pci_write_config_dword(pdev, PCI_COMMAND_PARITY, dma_refetch);
+       err = pci_request_regions(c->pdev, "cciss");
+       if (err) {
+               printk(KERN_ERR "cciss: Cannot obtain PCI resources, "
+                      "aborting\n");
+               return err;
        }
 
 #ifdef CCISS_DEBUG
-       printk("Trying to put board into Simple mode\n");
+       printk(KERN_INFO "command = %x\n", command);
+       printk(KERN_INFO "irq = %x\n", c->pdev->irq);
+       printk(KERN_INFO "board_id = %x\n", c->board_id);
 #endif                         /* CCISS_DEBUG */
-       c->max_commands = readl(&(c->cfgtable->CmdsOutMax));
-       /* Update the field, and then ring the doorbell */
-       writel(CFGTBL_Trans_Simple, &(c->cfgtable->HostWrite.TransportRequest));
-       writel(CFGTBL_ChangeReq, c->vaddr + SA5_DOORBELL);
 
-       /* under certain very rare conditions, this can take awhile.
-        * (e.g.: hot replace a failed 144GB drive in a RAID 5 set right
-        * as we enter this code.) */
-       for (i = 0; i < MAX_CONFIG_WAIT; i++) {
-               if (!(readl(c->vaddr + SA5_DOORBELL) & CFGTBL_ChangeReq))
-                       break;
-               /* delay and try again */
-               set_current_state(TASK_INTERRUPTIBLE);
-               schedule_timeout(msecs_to_jiffies(1));
+/* If the kernel supports MSI/MSI-X we will try to enable that functionality,
+ * else we use the IO-APIC interrupt assigned to us by system ROM.
+ */
+       cciss_interrupt_mode(c);
+       err = cciss_pci_find_memory_BAR(c->pdev, &c->paddr);
+       if (err)
+               goto err_out_free_res;
+       c->vaddr = remap_pci_mem(c->paddr, 0x250);
+       if (!c->vaddr) {
+               err = -ENOMEM;
+               goto err_out_free_res;
        }
-
-#ifdef CCISS_DEBUG
-       printk(KERN_DEBUG "I counter got to %d %x\n", i,
-              readl(c->vaddr + SA5_DOORBELL));
-#endif                         /* CCISS_DEBUG */
-#ifdef CCISS_DEBUG
+       err = cciss_wait_for_board_ready(c);
+       if (err)
+               goto err_out_free_res;
+       err = cciss_find_cfgtables(c);
+       if (err)
+               goto err_out_free_res;
        print_cfg_table(c->cfgtable);
-#endif                         /* CCISS_DEBUG */
+       cciss_find_board_params(c);
 
-       if (!(readl(&(c->cfgtable->TransportActive)) & CFGTBL_Trans_Simple)) {
-               printk(KERN_WARNING "cciss: unable to get board into"
-                      " simple mode\n");
+       if (!CISS_signature_present(c)) {
                err = -ENODEV;
                goto err_out_free_res;
        }
+       cciss_enable_scsi_prefetch(c);
+       cciss_p600_dma_prefetch_quirk(c);
+       cciss_put_controller_into_performant_mode(c);
        return 0;
 
 err_out_free_res:
@@ -3913,7 +4259,13 @@ err_out_free_res:
         * Deliberately omit pci_disable_device(): it does something nasty to
         * Smart Array controllers that pci_enable_device does not undo
         */
-       pci_release_regions(pdev);
+       if (c->transtable)
+               iounmap(c->transtable);
+       if (c->cfgtable)
+               iounmap(c->cfgtable);
+       if (c->vaddr)
+               iounmap(c->vaddr);
+       pci_release_regions(c->pdev);
        return err;
 }
 
@@ -4079,68 +4431,144 @@ static __devinit int cciss_reset_msi(struct pci_dev *pdev)
        return 0;
 }
 
-/* This does a hard reset of the controller using PCI power management
- * states. */
-static __devinit int cciss_hard_reset_controller(struct pci_dev *pdev)
+static int cciss_controller_hard_reset(struct pci_dev *pdev,
+       void * __iomem vaddr, bool use_doorbell)
 {
-       u16 pmcsr, saved_config_space[32];
-       int i, pos;
+       u16 pmcsr;
+       int pos;
 
-       printk(KERN_INFO "cciss: using PCI PM to reset controller\n");
+       if (use_doorbell) {
+               /* For everything after the P600, the PCI power state method
+                * of resetting the controller doesn't work, so we have this
+                * other way using the doorbell register.
+                */
+               dev_info(&pdev->dev, "using doorbell to reset controller\n");
+               writel(DOORBELL_CTLR_RESET, vaddr + SA5_DOORBELL);
+               msleep(1000);
+       } else { /* Try to do it the PCI power state way */
+
+               /* Quoting from the Open CISS Specification: "The Power
+                * Management Control/Status Register (CSR) controls the power
+                * state of the device.  The normal operating state is D0,
+                * CSR=00h.  The software off state is D3, CSR=03h.  To reset
+                * the controller, place the interface device in D3 then to D0,
+                * this causes a secondary PCI reset which will reset the
+                * controller." */
+
+               pos = pci_find_capability(pdev, PCI_CAP_ID_PM);
+               if (pos == 0) {
+                       dev_err(&pdev->dev,
+                               "cciss_controller_hard_reset: "
+                               "PCI PM not supported\n");
+                       return -ENODEV;
+               }
+               dev_info(&pdev->dev, "using PCI PM to reset controller\n");
+               /* enter the D3hot power management state */
+               pci_read_config_word(pdev, pos + PCI_PM_CTRL, &pmcsr);
+               pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
+               pmcsr |= PCI_D3hot;
+               pci_write_config_word(pdev, pos + PCI_PM_CTRL, pmcsr);
 
-       /* This is very nearly the same thing as
+               msleep(500);
 
-          pci_save_state(pci_dev);
-          pci_set_power_state(pci_dev, PCI_D3hot);
-          pci_set_power_state(pci_dev, PCI_D0);
-          pci_restore_state(pci_dev);
+               /* enter the D0 power management state */
+               pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
+               pmcsr |= PCI_D0;
+               pci_write_config_word(pdev, pos + PCI_PM_CTRL, pmcsr);
 
-          but we can't use these nice canned kernel routines on
-          kexec, because they also check the MSI/MSI-X state in PCI
-          configuration space and do the wrong thing when it is
-          set/cleared.  Also, the pci_save/restore_state functions
-          violate the ordering requirements for restoring the
-          configuration space from the CCISS document (see the
-          comment below).  So we roll our own .... */
+               msleep(500);
+       }
+       return 0;
+}
 
-       for (i = 0; i < 32; i++)
-               pci_read_config_word(pdev, 2*i, &saved_config_space[i]);
+/* This does a hard reset of the controller using PCI power management
+ * states or using the doorbell register. */
+static __devinit int cciss_kdump_hard_reset_controller(struct pci_dev *pdev)
+{
+       u16 saved_config_space[32];
+       u64 cfg_offset;
+       u32 cfg_base_addr;
+       u64 cfg_base_addr_index;
+       void __iomem *vaddr;
+       unsigned long paddr;
+       u32 misc_fw_support, active_transport;
+       int rc, i;
+       CfgTable_struct __iomem *cfgtable;
+       bool use_doorbell;
+       u32 board_id;
+
+       /* For controllers as old a the p600, this is very nearly
+        * the same thing as
+        *
+        * pci_save_state(pci_dev);
+        * pci_set_power_state(pci_dev, PCI_D3hot);
+        * pci_set_power_state(pci_dev, PCI_D0);
+        * pci_restore_state(pci_dev);
+        *
+        * but we can't use these nice canned kernel routines on
+        * kexec, because they also check the MSI/MSI-X state in PCI
+        * configuration space and do the wrong thing when it is
+        * set/cleared.  Also, the pci_save/restore_state functions
+        * violate the ordering requirements for restoring the
+        * configuration space from the CCISS document (see the
+        * comment below).  So we roll our own ....
+        *
+        * For controllers newer than the P600, the pci power state
+        * method of resetting doesn't work so we have another way
+        * using the doorbell register.
+        */
 
-       pos = pci_find_capability(pdev, PCI_CAP_ID_PM);
-       if (pos == 0) {
-               printk(KERN_ERR "cciss_reset_controller: PCI PM not supported\n");
+       /* Exclude 640x boards.  These are two pci devices in one slot
+        * which share a battery backed cache module.  One controls the
+        * cache, the other accesses the cache through the one that controls
+        * it.  If we reset the one controlling the cache, the other will
+        * likely not be happy.  Just forbid resetting this conjoined mess.
+        */
+       cciss_lookup_board_id(pdev, &board_id);
+       if (board_id == 0x409C0E11 || board_id == 0x409D0E11) {
+               dev_warn(&pdev->dev, "Cannot reset Smart Array 640x "
+                               "due to shared cache module.");
                return -ENODEV;
        }
 
-       /* Quoting from the Open CISS Specification: "The Power
-        * Management Control/Status Register (CSR) controls the power
-        * state of the device.  The normal operating state is D0,
-        * CSR=00h.  The software off state is D3, CSR=03h.  To reset
-        * the controller, place the interface device in D3 then to
-        * D0, this causes a secondary PCI reset which will reset the
-        * controller." */
+       for (i = 0; i < 32; i++)
+               pci_read_config_word(pdev, 2*i, &saved_config_space[i]);
 
-       /* enter the D3hot power management state */
-       pci_read_config_word(pdev, pos + PCI_PM_CTRL, &pmcsr);
-       pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
-       pmcsr |= PCI_D3hot;
-       pci_write_config_word(pdev, pos + PCI_PM_CTRL, pmcsr);
+       /* find the first memory BAR, so we can find the cfg table */
+       rc = cciss_pci_find_memory_BAR(pdev, &paddr);
+       if (rc)
+               return rc;
+       vaddr = remap_pci_mem(paddr, 0x250);
+       if (!vaddr)
+               return -ENOMEM;
 
-       schedule_timeout_uninterruptible(HZ >> 1);
+       /* find cfgtable in order to check if reset via doorbell is supported */
+       rc = cciss_find_cfg_addrs(pdev, vaddr, &cfg_base_addr,
+                                       &cfg_base_addr_index, &cfg_offset);
+       if (rc)
+               goto unmap_vaddr;
+       cfgtable = remap_pci_mem(pci_resource_start(pdev,
+                      cfg_base_addr_index) + cfg_offset, sizeof(*cfgtable));
+       if (!cfgtable) {
+               rc = -ENOMEM;
+               goto unmap_vaddr;
+       }
 
-       /* enter the D0 power management state */
-       pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
-       pmcsr |= PCI_D0;
-       pci_write_config_word(pdev, pos + PCI_PM_CTRL, pmcsr);
+       /* If reset via doorbell register is supported, use that. */
+       misc_fw_support = readl(&cfgtable->misc_fw_support);
+       use_doorbell = misc_fw_support & MISC_FW_DOORBELL_RESET;
 
-       schedule_timeout_uninterruptible(HZ >> 1);
+       rc = cciss_controller_hard_reset(pdev, vaddr, use_doorbell);
+       if (rc)
+               goto unmap_cfgtable;
 
        /* Restore the PCI configuration space.  The Open CISS
         * Specification says, "Restore the PCI Configuration
         * Registers, offsets 00h through 60h. It is important to
         * restore the command register, 16-bits at offset 04h,
         * last. Do not restore the configuration status register,
-        * 16-bits at offset 06h."  Note that the offset is 2*i. */
+        * 16-bits at offset 06h."  Note that the offset is 2*i.
+        */
        for (i = 0; i < 32; i++) {
                if (i == 2 || i == 3)
                        continue;
@@ -4149,6 +4577,63 @@ static __devinit int cciss_hard_reset_controller(struct pci_dev *pdev)
        wmb();
        pci_write_config_word(pdev, 4, saved_config_space[2]);
 
+       /* Some devices (notably the HP Smart Array 5i Controller)
+          need a little pause here */
+       msleep(CCISS_POST_RESET_PAUSE_MSECS);
+
+       /* Controller should be in simple mode at this point.  If it's not,
+        * It means we're on one of those controllers which doesn't support
+        * the doorbell reset method and on which the PCI power management reset
+        * method doesn't work (P800, for example.)
+        * In those cases, don't try to proceed, as it generally doesn't work.
+        */
+       active_transport = readl(&cfgtable->TransportActive);
+       if (active_transport & PERFORMANT_MODE) {
+               dev_warn(&pdev->dev, "Unable to successfully reset controller,"
+                       " Ignoring controller.\n");
+               rc = -ENODEV;
+       }
+
+unmap_cfgtable:
+       iounmap(cfgtable);
+
+unmap_vaddr:
+       iounmap(vaddr);
+       return rc;
+}
+
+static __devinit int cciss_init_reset_devices(struct pci_dev *pdev)
+{
+       int rc, i;
+
+       if (!reset_devices)
+               return 0;
+
+       /* Reset the controller with a PCI power-cycle or via doorbell */
+       rc = cciss_kdump_hard_reset_controller(pdev);
+
+       /* -ENOTSUPP here means we cannot reset the controller
+        * but it's already (and still) up and running in
+        * "performant mode".  Or, it might be 640x, which can't reset
+        * due to concerns about shared bbwc between 6402/6404 pair.
+        */
+       if (rc == -ENOTSUPP)
+               return 0; /* just try to do the kdump anyhow. */
+       if (rc)
+               return -ENODEV;
+       if (cciss_reset_msi(pdev))
+               return -ENODEV;
+
+       /* Now try to get the controller to respond to a no-op */
+       for (i = 0; i < CCISS_POST_RESET_NOOP_RETRIES; i++) {
+               if (cciss_noop(pdev) == 0)
+                       break;
+               else
+                       dev_warn(&pdev->dev, "no-op failed%s\n",
+                               (i < CCISS_POST_RESET_NOOP_RETRIES - 1 ?
+                                       "; re-trying" : ""));
+               msleep(CCISS_POST_RESET_NOOP_INTERVAL_MSECS);
+       }
        return 0;
 }
 
@@ -4167,41 +4652,24 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
        int dac, return_code;
        InquiryData_struct *inq_buff;
 
-       if (reset_devices) {
-               /* Reset the controller with a PCI power-cycle */
-               if (cciss_hard_reset_controller(pdev) || cciss_reset_msi(pdev))
-                       return -ENODEV;
-
-               /* Now try to get the controller to respond to a no-op. Some
-                  devices (notably the HP Smart Array 5i Controller) need
-                  up to 30 seconds to respond. */
-               for (i=0; i<30; i++) {
-                       if (cciss_noop(pdev) == 0)
-                               break;
-
-                       schedule_timeout_uninterruptible(HZ);
-               }
-               if (i == 30) {
-                       printk(KERN_ERR "cciss: controller seems dead\n");
-                       return -EBUSY;
-               }
-       }
-
+       rc = cciss_init_reset_devices(pdev);
+       if (rc)
+               return rc;
        i = alloc_cciss_hba();
        if (i < 0)
                return -1;
 
+       hba[i]->pdev = pdev;
        hba[i]->busy_initializing = 1;
        INIT_HLIST_HEAD(&hba[i]->cmpQ);
        INIT_HLIST_HEAD(&hba[i]->reqQ);
        mutex_init(&hba[i]->busy_shutting_down);
 
-       if (cciss_pci_init(hba[i], pdev) != 0)
+       if (cciss_pci_init(hba[i]) != 0)
                goto clean_no_release_regions;
 
        sprintf(hba[i]->devname, "cciss%d", i);
        hba[i]->ctlr = i;
-       hba[i]->pdev = pdev;
 
        init_completion(&hba[i]->scan_wait);
 
@@ -4238,16 +4706,26 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
 
        /* make sure the board interrupts are off */
        hba[i]->access.set_intr_mask(hba[i], CCISS_INTR_OFF);
-       if (request_irq(hba[i]->intr[SIMPLE_MODE_INT], do_cciss_intr,
-                       IRQF_DISABLED | IRQF_SHARED, hba[i]->devname, hba[i])) {
-               printk(KERN_ERR "cciss: Unable to get irq %d for %s\n",
-                      hba[i]->intr[SIMPLE_MODE_INT], hba[i]->devname);
-               goto clean2;
+       if (hba[i]->msi_vector || hba[i]->msix_vector) {
+               if (request_irq(hba[i]->intr[PERF_MODE_INT],
+                               do_cciss_msix_intr,
+                               IRQF_DISABLED, hba[i]->devname, hba[i])) {
+                       printk(KERN_ERR "cciss: Unable to get irq %d for %s\n",
+                              hba[i]->intr[PERF_MODE_INT], hba[i]->devname);
+                       goto clean2;
+               }
+       } else {
+               if (request_irq(hba[i]->intr[PERF_MODE_INT], do_cciss_intx,
+                               IRQF_DISABLED, hba[i]->devname, hba[i])) {
+                       printk(KERN_ERR "cciss: Unable to get irq %d for %s\n",
+                              hba[i]->intr[PERF_MODE_INT], hba[i]->devname);
+                       goto clean2;
+               }
        }
 
        printk(KERN_INFO "%s: <0x%x> at PCI %s IRQ %d%s using DAC\n",
               hba[i]->devname, pdev->device, pci_name(pdev),
-              hba[i]->intr[SIMPLE_MODE_INT], dac ? "" : " not");
+              hba[i]->intr[PERF_MODE_INT], dac ? "" : " not");
 
        hba[i]->cmd_pool_bits =
            kmalloc(DIV_ROUND_UP(hba[i]->nr_cmds, BITS_PER_LONG)
@@ -4353,7 +4831,7 @@ clean4:
                                    hba[i]->nr_cmds * sizeof(ErrorInfo_struct),
                                    hba[i]->errinfo_pool,
                                    hba[i]->errinfo_pool_dhandle);
-       free_irq(hba[i]->intr[SIMPLE_MODE_INT], hba[i]);
+       free_irq(hba[i]->intr[PERF_MODE_INT], hba[i]);
 clean2:
        unregister_blkdev(hba[i]->major, hba[i]->devname);
 clean1:
@@ -4395,7 +4873,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
                printk(KERN_WARNING "cciss%d: Error flushing cache\n",
                        h->ctlr);
        h->access.set_intr_mask(h, CCISS_INTR_OFF);
-       free_irq(h->intr[2], h);
+       free_irq(h->intr[PERF_MODE_INT], h);
 }
 
 static void __devexit cciss_remove_one(struct pci_dev *pdev)
@@ -4450,6 +4928,8 @@ static void __devexit cciss_remove_one(struct pci_dev *pdev)
                pci_disable_msi(hba[i]->pdev);
 #endif                         /* CONFIG_PCI_MSI */
 
+       iounmap(hba[i]->transtable);
+       iounmap(hba[i]->cfgtable);
        iounmap(hba[i]->vaddr);
 
        pci_free_consistent(hba[i]->pdev, hba[i]->nr_cmds * sizeof(CommandList_struct),
@@ -4495,7 +4975,6 @@ static int __init cciss_init(void)
         * array of them, the size must be a multiple of 8 bytes.
         */
        BUILD_BUG_ON(sizeof(CommandList_struct) % COMMANDLIST_ALIGNMENT);
-
        printk(KERN_INFO DRIVER_NAME "\n");
 
        err = bus_register(&cciss_bus_type);
@@ -4542,46 +5021,5 @@ static void __exit cciss_cleanup(void)
        bus_unregister(&cciss_bus_type);
 }
 
-static void fail_all_cmds(unsigned long ctlr)
-{
-       /* If we get here, the board is apparently dead. */
-       ctlr_info_t *h = hba[ctlr];
-       CommandList_struct *c;
-       unsigned long flags;
-
-       printk(KERN_WARNING "cciss%d: controller not responding.\n", h->ctlr);
-       h->alive = 0;           /* the controller apparently died... */
-
-       spin_lock_irqsave(CCISS_LOCK(ctlr), flags);
-
-       pci_disable_device(h->pdev);    /* Make sure it is really dead. */
-
-       /* move everything off the request queue onto the completed queue */
-       while (!hlist_empty(&h->reqQ)) {
-               c = hlist_entry(h->reqQ.first, CommandList_struct, list);
-               removeQ(c);
-               h->Qdepth--;
-               addQ(&h->cmpQ, c);
-       }
-
-       /* Now, fail everything on the completed queue with a HW error */
-       while (!hlist_empty(&h->cmpQ)) {
-               c = hlist_entry(h->cmpQ.first, CommandList_struct, list);
-               removeQ(c);
-               if (c->cmd_type != CMD_MSG_STALE)
-                       c->err_info->CommandStatus = CMD_HARDWARE_ERR;
-               if (c->cmd_type == CMD_RWREQ) {
-                       complete_command(h, c, 0);
-               } else if (c->cmd_type == CMD_IOCTL_PEND)
-                       complete(c->waiting);
-#ifdef CONFIG_CISS_SCSI_TAPE
-               else if (c->cmd_type == CMD_SCSI)
-                       complete_scsi_command(c, 0, 0);
-#endif
-       }
-       spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags);
-       return;
-}
-
 module_init(cciss_init);
 module_exit(cciss_cleanup);