summaryrefslogtreecommitdiffstats
path: root/drivers/scsi/megaraid
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2011-10-28 19:44:18 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2011-10-28 19:44:18 -0400
commitec7ae517537ae5c7b0b2cd7f562dfa3e7a05b954 (patch)
treee6b0c64a51a7c0aa0efd09d4f7a80872e3b1657a /drivers/scsi/megaraid
parent97d2eb13a019ec09cc1a7ea2d3705c0b117b3c0d (diff)
parent590134fa78fbdbe5fea78c7ae0b2c3364bc9572f (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi-misc-2.6
* git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi-misc-2.6: (204 commits) [SCSI] qla4xxx: export address/port of connection (fix udev disk names) [SCSI] ipr: Fix BUG on adapter dump timeout [SCSI] megaraid_sas: Fix instance access in megasas_reset_timer [SCSI] hpsa: change confusing message to be more clear [SCSI] iscsi class: fix vlan configuration [SCSI] qla4xxx: fix data alignment and use nl helpers [SCSI] iscsi class: fix link local mispelling [SCSI] iscsi class: Replace iscsi_get_next_target_id with IDA [SCSI] aacraid: use lower snprintf() limit [SCSI] lpfc 8.3.27: Change driver version to 8.3.27 [SCSI] lpfc 8.3.27: T10 additions for SLI4 [SCSI] lpfc 8.3.27: Fix queue allocation failure recovery [SCSI] lpfc 8.3.27: Change algorithm for getting physical port name [SCSI] lpfc 8.3.27: Changed worst case mailbox timeout [SCSI] lpfc 8.3.27: Miscellanous logic and interface fixes [SCSI] megaraid_sas: Changelog and version update [SCSI] megaraid_sas: Add driver workaround for PERC5/1068 kdump kernel panic [SCSI] megaraid_sas: Add multiple MSI-X vector/multiple reply queue support [SCSI] megaraid_sas: Add support for MegaRAID 9360/9380 12GB/s controllers [SCSI] megaraid_sas: Clear FUSION_IN_RESET before enabling interrupts ...
Diffstat (limited to 'drivers/scsi/megaraid')
-rw-r--r--drivers/scsi/megaraid/megaraid_sas.h22
-rw-r--r--drivers/scsi/megaraid/megaraid_sas_base.c239
-rw-r--r--drivers/scsi/megaraid/megaraid_sas_fp.c26
-rw-r--r--drivers/scsi/megaraid/megaraid_sas_fusion.c193
-rw-r--r--drivers/scsi/megaraid/megaraid_sas_fusion.h19
5 files changed, 365 insertions, 134 deletions
diff --git a/drivers/scsi/megaraid/megaraid_sas.h b/drivers/scsi/megaraid/megaraid_sas.h
index 3948a00d81f4..dd94c7d574fb 100644
--- a/drivers/scsi/megaraid/megaraid_sas.h
+++ b/drivers/scsi/megaraid/megaraid_sas.h
@@ -33,9 +33,9 @@
33/* 33/*
34 * MegaRAID SAS Driver meta data 34 * MegaRAID SAS Driver meta data
35 */ 35 */
36#define MEGASAS_VERSION "00.00.05.40-rc1" 36#define MEGASAS_VERSION "00.00.06.12-rc1"
37#define MEGASAS_RELDATE "Jul. 26, 2011" 37#define MEGASAS_RELDATE "Oct. 5, 2011"
38#define MEGASAS_EXT_VERSION "Tue. Jul. 26 17:00:00 PDT 2011" 38#define MEGASAS_EXT_VERSION "Wed. Oct. 5 17:00:00 PDT 2011"
39 39
40/* 40/*
41 * Device IDs 41 * Device IDs
@@ -48,6 +48,7 @@
48#define PCI_DEVICE_ID_LSI_SAS0073SKINNY 0x0073 48#define PCI_DEVICE_ID_LSI_SAS0073SKINNY 0x0073
49#define PCI_DEVICE_ID_LSI_SAS0071SKINNY 0x0071 49#define PCI_DEVICE_ID_LSI_SAS0071SKINNY 0x0071
50#define PCI_DEVICE_ID_LSI_FUSION 0x005b 50#define PCI_DEVICE_ID_LSI_FUSION 0x005b
51#define PCI_DEVICE_ID_LSI_INVADER 0x005d
51 52
52/* 53/*
53 * ===================================== 54 * =====================================
@@ -138,6 +139,7 @@
138#define MFI_CMD_ABORT 0x06 139#define MFI_CMD_ABORT 0x06
139#define MFI_CMD_SMP 0x07 140#define MFI_CMD_SMP 0x07
140#define MFI_CMD_STP 0x08 141#define MFI_CMD_STP 0x08
142#define MFI_CMD_INVALID 0xff
141 143
142#define MR_DCMD_CTRL_GET_INFO 0x01010000 144#define MR_DCMD_CTRL_GET_INFO 0x01010000
143#define MR_DCMD_LD_GET_LIST 0x03010000 145#define MR_DCMD_LD_GET_LIST 0x03010000
@@ -221,6 +223,7 @@ enum MFI_STAT {
221 MFI_STAT_RESERVATION_IN_PROGRESS = 0x36, 223 MFI_STAT_RESERVATION_IN_PROGRESS = 0x36,
222 MFI_STAT_I2C_ERRORS_DETECTED = 0x37, 224 MFI_STAT_I2C_ERRORS_DETECTED = 0x37,
223 MFI_STAT_PCI_ERRORS_DETECTED = 0x38, 225 MFI_STAT_PCI_ERRORS_DETECTED = 0x38,
226 MFI_STAT_CONFIG_SEQ_MISMATCH = 0x67,
224 227
225 MFI_STAT_INVALID_STATUS = 0xFF 228 MFI_STAT_INVALID_STATUS = 0xFF
226}; 229};
@@ -716,7 +719,7 @@ struct megasas_ctrl_info {
716#define MEGASAS_DEFAULT_INIT_ID -1 719#define MEGASAS_DEFAULT_INIT_ID -1
717#define MEGASAS_MAX_LUN 8 720#define MEGASAS_MAX_LUN 8
718#define MEGASAS_MAX_LD 64 721#define MEGASAS_MAX_LD 64
719#define MEGASAS_DEFAULT_CMD_PER_LUN 128 722#define MEGASAS_DEFAULT_CMD_PER_LUN 256
720#define MEGASAS_MAX_PD (MEGASAS_MAX_PD_CHANNELS * \ 723#define MEGASAS_MAX_PD (MEGASAS_MAX_PD_CHANNELS * \
721 MEGASAS_MAX_DEV_PER_CHANNEL) 724 MEGASAS_MAX_DEV_PER_CHANNEL)
722#define MEGASAS_MAX_LD_IDS (MEGASAS_MAX_LD_CHANNELS * \ 725#define MEGASAS_MAX_LD_IDS (MEGASAS_MAX_LD_CHANNELS * \
@@ -755,6 +758,7 @@ struct megasas_ctrl_info {
755#define MEGASAS_INT_CMDS 32 758#define MEGASAS_INT_CMDS 32
756#define MEGASAS_SKINNY_INT_CMDS 5 759#define MEGASAS_SKINNY_INT_CMDS 5
757 760
761#define MEGASAS_MAX_MSIX_QUEUES 16
758/* 762/*
759 * FW can accept both 32 and 64 bit SGLs. We want to allocate 32/64 bit 763 * FW can accept both 32 and 64 bit SGLs. We want to allocate 32/64 bit
760 * SGLs based on the size of dma_addr_t 764 * SGLs based on the size of dma_addr_t
@@ -1276,6 +1280,11 @@ struct megasas_aen_event {
1276 struct megasas_instance *instance; 1280 struct megasas_instance *instance;
1277}; 1281};
1278 1282
1283struct megasas_irq_context {
1284 struct megasas_instance *instance;
1285 u32 MSIxIndex;
1286};
1287
1279struct megasas_instance { 1288struct megasas_instance {
1280 1289
1281 u32 *producer; 1290 u32 *producer;
@@ -1349,8 +1358,9 @@ struct megasas_instance {
1349 1358
1350 /* Ptr to hba specific information */ 1359 /* Ptr to hba specific information */
1351 void *ctrl_context; 1360 void *ctrl_context;
1352 u8 msi_flag; 1361 unsigned int msix_vectors;
1353 struct msix_entry msixentry; 1362 struct msix_entry msixentry[MEGASAS_MAX_MSIX_QUEUES];
1363 struct megasas_irq_context irq_context[MEGASAS_MAX_MSIX_QUEUES];
1354 u64 map_id; 1364 u64 map_id;
1355 struct megasas_cmd *map_update_cmd; 1365 struct megasas_cmd *map_update_cmd;
1356 unsigned long bar; 1366 unsigned long bar;
diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
index 776d01988660..29a994f9c4f1 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -18,7 +18,7 @@
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * 19 *
20 * FILE: megaraid_sas_base.c 20 * FILE: megaraid_sas_base.c
21 * Version : v00.00.05.40-rc1 21 * Version : v00.00.06.12-rc1
22 * 22 *
23 * Authors: LSI Corporation 23 * Authors: LSI Corporation
24 * Sreenivas Bagalkote 24 * Sreenivas Bagalkote
@@ -84,7 +84,7 @@ MODULE_VERSION(MEGASAS_VERSION);
84MODULE_AUTHOR("megaraidlinux@lsi.com"); 84MODULE_AUTHOR("megaraidlinux@lsi.com");
85MODULE_DESCRIPTION("LSI MegaRAID SAS Driver"); 85MODULE_DESCRIPTION("LSI MegaRAID SAS Driver");
86 86
87int megasas_transition_to_ready(struct megasas_instance *instance); 87int megasas_transition_to_ready(struct megasas_instance *instance, int ocr);
88static int megasas_get_pd_list(struct megasas_instance *instance); 88static int megasas_get_pd_list(struct megasas_instance *instance);
89static int megasas_issue_init_mfi(struct megasas_instance *instance); 89static int megasas_issue_init_mfi(struct megasas_instance *instance);
90static int megasas_register_aen(struct megasas_instance *instance, 90static int megasas_register_aen(struct megasas_instance *instance,
@@ -114,6 +114,8 @@ static struct pci_device_id megasas_pci_table[] = {
114 /* xscale IOP */ 114 /* xscale IOP */
115 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FUSION)}, 115 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FUSION)},
116 /* Fusion */ 116 /* Fusion */
117 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_INVADER)},
118 /* Invader */
117 {} 119 {}
118}; 120};
119 121
@@ -213,6 +215,10 @@ megasas_return_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd)
213 215
214 cmd->scmd = NULL; 216 cmd->scmd = NULL;
215 cmd->frame_count = 0; 217 cmd->frame_count = 0;
218 if ((instance->pdev->device != PCI_DEVICE_ID_LSI_FUSION) &&
219 (instance->pdev->device != PCI_DEVICE_ID_LSI_INVADER) &&
220 (reset_devices))
221 cmd->frame->hdr.cmd = MFI_CMD_INVALID;
216 list_add_tail(&cmd->list, &instance->cmd_pool); 222 list_add_tail(&cmd->list, &instance->cmd_pool);
217 223
218 spin_unlock_irqrestore(&instance->cmd_pool_lock, flags); 224 spin_unlock_irqrestore(&instance->cmd_pool_lock, flags);
@@ -1583,7 +1589,8 @@ void megaraid_sas_kill_hba(struct megasas_instance *instance)
1583{ 1589{
1584 if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0073SKINNY) || 1590 if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0073SKINNY) ||
1585 (instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0071SKINNY) || 1591 (instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0071SKINNY) ||
1586 (instance->pdev->device == PCI_DEVICE_ID_LSI_FUSION)) { 1592 (instance->pdev->device == PCI_DEVICE_ID_LSI_FUSION) ||
1593 (instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER)) {
1587 writel(MFI_STOP_ADP, &instance->reg_set->doorbell); 1594 writel(MFI_STOP_ADP, &instance->reg_set->doorbell);
1588 } else { 1595 } else {
1589 writel(MFI_STOP_ADP, &instance->reg_set->inbound_doorbell); 1596 writel(MFI_STOP_ADP, &instance->reg_set->inbound_doorbell);
@@ -1907,7 +1914,6 @@ static int megasas_generic_reset(struct scsi_cmnd *scmd)
1907static enum 1914static enum
1908blk_eh_timer_return megasas_reset_timer(struct scsi_cmnd *scmd) 1915blk_eh_timer_return megasas_reset_timer(struct scsi_cmnd *scmd)
1909{ 1916{
1910 struct megasas_cmd *cmd = (struct megasas_cmd *)scmd->SCp.ptr;
1911 struct megasas_instance *instance; 1917 struct megasas_instance *instance;
1912 unsigned long flags; 1918 unsigned long flags;
1913 1919
@@ -1916,7 +1922,7 @@ blk_eh_timer_return megasas_reset_timer(struct scsi_cmnd *scmd)
1916 return BLK_EH_NOT_HANDLED; 1922 return BLK_EH_NOT_HANDLED;
1917 } 1923 }
1918 1924
1919 instance = cmd->instance; 1925 instance = (struct megasas_instance *)scmd->device->host->hostdata;
1920 if (!(instance->flag & MEGASAS_FW_BUSY)) { 1926 if (!(instance->flag & MEGASAS_FW_BUSY)) {
1921 /* FW is busy, throttle IO */ 1927 /* FW is busy, throttle IO */
1922 spin_lock_irqsave(instance->host->host_lock, flags); 1928 spin_lock_irqsave(instance->host->host_lock, flags);
@@ -1957,7 +1963,8 @@ static int megasas_reset_bus_host(struct scsi_cmnd *scmd)
1957 /* 1963 /*
1958 * First wait for all commands to complete 1964 * First wait for all commands to complete
1959 */ 1965 */
1960 if (instance->pdev->device == PCI_DEVICE_ID_LSI_FUSION) 1966 if ((instance->pdev->device == PCI_DEVICE_ID_LSI_FUSION) ||
1967 (instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER))
1961 ret = megasas_reset_fusion(scmd->device->host); 1968 ret = megasas_reset_fusion(scmd->device->host);
1962 else 1969 else
1963 ret = megasas_generic_reset(scmd); 1970 ret = megasas_generic_reset(scmd);
@@ -2161,7 +2168,16 @@ megasas_complete_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd,
2161 cmd->scmd->SCp.ptr = NULL; 2168 cmd->scmd->SCp.ptr = NULL;
2162 2169
2163 switch (hdr->cmd) { 2170 switch (hdr->cmd) {
2164 2171 case MFI_CMD_INVALID:
2172 /* Some older 1068 controller FW may keep a pended
2173 MR_DCMD_CTRL_EVENT_GET_INFO left over from the main kernel
2174 when booting the kdump kernel. Ignore this command to
2175 prevent a kernel panic on shutdown of the kdump kernel. */
2176 printk(KERN_WARNING "megaraid_sas: MFI_CMD_INVALID command "
2177 "completed.\n");
2178 printk(KERN_WARNING "megaraid_sas: If you have a controller "
2179 "other than PERC5, please upgrade your firmware.\n");
2180 break;
2165 case MFI_CMD_PD_SCSI_IO: 2181 case MFI_CMD_PD_SCSI_IO:
2166 case MFI_CMD_LD_SCSI_IO: 2182 case MFI_CMD_LD_SCSI_IO:
2167 2183
@@ -2477,7 +2493,7 @@ process_fw_state_change_wq(struct work_struct *work)
2477 msleep(1000); 2493 msleep(1000);
2478 } 2494 }
2479 2495
2480 if (megasas_transition_to_ready(instance)) { 2496 if (megasas_transition_to_ready(instance, 1)) {
2481 printk(KERN_NOTICE "megaraid_sas:adapter not ready\n"); 2497 printk(KERN_NOTICE "megaraid_sas:adapter not ready\n");
2482 2498
2483 megaraid_sas_kill_hba(instance); 2499 megaraid_sas_kill_hba(instance);
@@ -2532,7 +2548,7 @@ megasas_deplete_reply_queue(struct megasas_instance *instance,
2532 instance->reg_set) 2548 instance->reg_set)
2533 ) == 0) { 2549 ) == 0) {
2534 /* Hardware may not set outbound_intr_status in MSI-X mode */ 2550 /* Hardware may not set outbound_intr_status in MSI-X mode */
2535 if (!instance->msi_flag) 2551 if (!instance->msix_vectors)
2536 return IRQ_NONE; 2552 return IRQ_NONE;
2537 } 2553 }
2538 2554
@@ -2590,16 +2606,14 @@ megasas_deplete_reply_queue(struct megasas_instance *instance,
2590 */ 2606 */
2591static irqreturn_t megasas_isr(int irq, void *devp) 2607static irqreturn_t megasas_isr(int irq, void *devp)
2592{ 2608{
2593 struct megasas_instance *instance; 2609 struct megasas_irq_context *irq_context = devp;
2610 struct megasas_instance *instance = irq_context->instance;
2594 unsigned long flags; 2611 unsigned long flags;
2595 irqreturn_t rc; 2612 irqreturn_t rc;
2596 2613
2597 if (atomic_read( 2614 if (atomic_read(&instance->fw_reset_no_pci_access))
2598 &(((struct megasas_instance *)devp)->fw_reset_no_pci_access)))
2599 return IRQ_HANDLED; 2615 return IRQ_HANDLED;
2600 2616
2601 instance = (struct megasas_instance *)devp;
2602
2603 spin_lock_irqsave(&instance->hba_lock, flags); 2617 spin_lock_irqsave(&instance->hba_lock, flags);
2604 rc = megasas_deplete_reply_queue(instance, DID_OK); 2618 rc = megasas_deplete_reply_queue(instance, DID_OK);
2605 spin_unlock_irqrestore(&instance->hba_lock, flags); 2619 spin_unlock_irqrestore(&instance->hba_lock, flags);
@@ -2617,7 +2631,7 @@ static irqreturn_t megasas_isr(int irq, void *devp)
2617 * has to wait for the ready state. 2631 * has to wait for the ready state.
2618 */ 2632 */
2619int 2633int
2620megasas_transition_to_ready(struct megasas_instance* instance) 2634megasas_transition_to_ready(struct megasas_instance *instance, int ocr)
2621{ 2635{
2622 int i; 2636 int i;
2623 u8 max_wait; 2637 u8 max_wait;
@@ -2639,11 +2653,13 @@ megasas_transition_to_ready(struct megasas_instance* instance)
2639 switch (fw_state) { 2653 switch (fw_state) {
2640 2654
2641 case MFI_STATE_FAULT: 2655 case MFI_STATE_FAULT:
2642
2643 printk(KERN_DEBUG "megasas: FW in FAULT state!!\n"); 2656 printk(KERN_DEBUG "megasas: FW in FAULT state!!\n");
2644 max_wait = MEGASAS_RESET_WAIT_TIME; 2657 if (ocr) {
2645 cur_state = MFI_STATE_FAULT; 2658 max_wait = MEGASAS_RESET_WAIT_TIME;
2646 break; 2659 cur_state = MFI_STATE_FAULT;
2660 break;
2661 } else
2662 return -ENODEV;
2647 2663
2648 case MFI_STATE_WAIT_HANDSHAKE: 2664 case MFI_STATE_WAIT_HANDSHAKE:
2649 /* 2665 /*
@@ -2654,7 +2670,9 @@ megasas_transition_to_ready(struct megasas_instance* instance)
2654 (instance->pdev->device == 2670 (instance->pdev->device ==
2655 PCI_DEVICE_ID_LSI_SAS0071SKINNY) || 2671 PCI_DEVICE_ID_LSI_SAS0071SKINNY) ||
2656 (instance->pdev->device == 2672 (instance->pdev->device ==
2657 PCI_DEVICE_ID_LSI_FUSION)) { 2673 PCI_DEVICE_ID_LSI_FUSION) ||
2674 (instance->pdev->device ==
2675 PCI_DEVICE_ID_LSI_INVADER)) {
2658 writel( 2676 writel(
2659 MFI_INIT_CLEAR_HANDSHAKE|MFI_INIT_HOTPLUG, 2677 MFI_INIT_CLEAR_HANDSHAKE|MFI_INIT_HOTPLUG,
2660 &instance->reg_set->doorbell); 2678 &instance->reg_set->doorbell);
@@ -2674,7 +2692,9 @@ megasas_transition_to_ready(struct megasas_instance* instance)
2674 (instance->pdev->device == 2692 (instance->pdev->device ==
2675 PCI_DEVICE_ID_LSI_SAS0071SKINNY) || 2693 PCI_DEVICE_ID_LSI_SAS0071SKINNY) ||
2676 (instance->pdev->device == 2694 (instance->pdev->device ==
2677 PCI_DEVICE_ID_LSI_FUSION)) { 2695 PCI_DEVICE_ID_LSI_FUSION) ||
2696 (instance->pdev->device ==
2697 PCI_DEVICE_ID_LSI_INVADER)) {
2678 writel(MFI_INIT_HOTPLUG, 2698 writel(MFI_INIT_HOTPLUG,
2679 &instance->reg_set->doorbell); 2699 &instance->reg_set->doorbell);
2680 } else 2700 } else
@@ -2695,11 +2715,15 @@ megasas_transition_to_ready(struct megasas_instance* instance)
2695 (instance->pdev->device == 2715 (instance->pdev->device ==
2696 PCI_DEVICE_ID_LSI_SAS0071SKINNY) || 2716 PCI_DEVICE_ID_LSI_SAS0071SKINNY) ||
2697 (instance->pdev->device 2717 (instance->pdev->device
2698 == PCI_DEVICE_ID_LSI_FUSION)) { 2718 == PCI_DEVICE_ID_LSI_FUSION) ||
2719 (instance->pdev->device
2720 == PCI_DEVICE_ID_LSI_INVADER)) {
2699 writel(MFI_RESET_FLAGS, 2721 writel(MFI_RESET_FLAGS,
2700 &instance->reg_set->doorbell); 2722 &instance->reg_set->doorbell);
2701 if (instance->pdev->device == 2723 if ((instance->pdev->device ==
2702 PCI_DEVICE_ID_LSI_FUSION) { 2724 PCI_DEVICE_ID_LSI_FUSION) ||
2725 (instance->pdev->device ==
2726 PCI_DEVICE_ID_LSI_INVADER)) {
2703 for (i = 0; i < (10 * 1000); i += 20) { 2727 for (i = 0; i < (10 * 1000); i += 20) {
2704 if (readl( 2728 if (readl(
2705 &instance-> 2729 &instance->
@@ -2922,6 +2946,10 @@ static int megasas_create_frame_pool(struct megasas_instance *instance)
2922 memset(cmd->frame, 0, total_sz); 2946 memset(cmd->frame, 0, total_sz);
2923 cmd->frame->io.context = cmd->index; 2947 cmd->frame->io.context = cmd->index;
2924 cmd->frame->io.pad_0 = 0; 2948 cmd->frame->io.pad_0 = 0;
2949 if ((instance->pdev->device != PCI_DEVICE_ID_LSI_FUSION) &&
2950 (instance->pdev->device != PCI_DEVICE_ID_LSI_INVADER) &&
2951 (reset_devices))
2952 cmd->frame->hdr.cmd = MFI_CMD_INVALID;
2925 } 2953 }
2926 2954
2927 return 0; 2955 return 0;
@@ -3474,6 +3502,7 @@ static int megasas_init_fw(struct megasas_instance *instance)
3474 struct megasas_register_set __iomem *reg_set; 3502 struct megasas_register_set __iomem *reg_set;
3475 struct megasas_ctrl_info *ctrl_info; 3503 struct megasas_ctrl_info *ctrl_info;
3476 unsigned long bar_list; 3504 unsigned long bar_list;
3505 int i;
3477 3506
3478 /* Find first memory bar */ 3507 /* Find first memory bar */
3479 bar_list = pci_select_bars(instance->pdev, IORESOURCE_MEM); 3508 bar_list = pci_select_bars(instance->pdev, IORESOURCE_MEM);
@@ -3496,6 +3525,7 @@ static int megasas_init_fw(struct megasas_instance *instance)
3496 3525
3497 switch (instance->pdev->device) { 3526 switch (instance->pdev->device) {
3498 case PCI_DEVICE_ID_LSI_FUSION: 3527 case PCI_DEVICE_ID_LSI_FUSION:
3528 case PCI_DEVICE_ID_LSI_INVADER:
3499 instance->instancet = &megasas_instance_template_fusion; 3529 instance->instancet = &megasas_instance_template_fusion;
3500 break; 3530 break;
3501 case PCI_DEVICE_ID_LSI_SAS1078R: 3531 case PCI_DEVICE_ID_LSI_SAS1078R:
@@ -3520,15 +3550,39 @@ static int megasas_init_fw(struct megasas_instance *instance)
3520 /* 3550 /*
3521 * We expect the FW state to be READY 3551 * We expect the FW state to be READY
3522 */ 3552 */
3523 if (megasas_transition_to_ready(instance)) 3553 if (megasas_transition_to_ready(instance, 0))
3524 goto fail_ready_state; 3554 goto fail_ready_state;
3525 3555
3526 /* Check if MSI-X is supported while in ready state */ 3556 /* Check if MSI-X is supported while in ready state */
3527 msix_enable = (instance->instancet->read_fw_status_reg(reg_set) & 3557 msix_enable = (instance->instancet->read_fw_status_reg(reg_set) &
3528 0x4000000) >> 0x1a; 3558 0x4000000) >> 0x1a;
3529 if (msix_enable && !msix_disable && 3559 if (msix_enable && !msix_disable) {
3530 !pci_enable_msix(instance->pdev, &instance->msixentry, 1)) 3560 /* Check max MSI-X vectors */
3531 instance->msi_flag = 1; 3561 if ((instance->pdev->device == PCI_DEVICE_ID_LSI_FUSION) ||
3562 (instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER)) {
3563 instance->msix_vectors = (readl(&instance->reg_set->
3564 outbound_scratch_pad_2
3565 ) & 0x1F) + 1;
3566 } else
3567 instance->msix_vectors = 1;
3568 /* Don't bother allocating more MSI-X vectors than cpus */
3569 instance->msix_vectors = min(instance->msix_vectors,
3570 (unsigned int)num_online_cpus());
3571 for (i = 0; i < instance->msix_vectors; i++)
3572 instance->msixentry[i].entry = i;
3573 i = pci_enable_msix(instance->pdev, instance->msixentry,
3574 instance->msix_vectors);
3575 if (i >= 0) {
3576 if (i) {
3577 if (!pci_enable_msix(instance->pdev,
3578 instance->msixentry, i))
3579 instance->msix_vectors = i;
3580 else
3581 instance->msix_vectors = 0;
3582 }
3583 } else
3584 instance->msix_vectors = 0;
3585 }
3532 3586
3533 /* Get operational params, sge flags, send init cmd to controller */ 3587 /* Get operational params, sge flags, send init cmd to controller */
3534 if (instance->instancet->init_adapter(instance)) 3588 if (instance->instancet->init_adapter(instance))
@@ -3892,7 +3946,8 @@ static int megasas_io_attach(struct megasas_instance *instance)
3892 host->max_cmd_len = 16; 3946 host->max_cmd_len = 16;
3893 3947
3894 /* Fusion only supports host reset */ 3948 /* Fusion only supports host reset */
3895 if (instance->pdev->device == PCI_DEVICE_ID_LSI_FUSION) { 3949 if ((instance->pdev->device == PCI_DEVICE_ID_LSI_FUSION) ||
3950 (instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER)) {
3896 host->hostt->eh_device_reset_handler = NULL; 3951 host->hostt->eh_device_reset_handler = NULL;
3897 host->hostt->eh_bus_reset_handler = NULL; 3952 host->hostt->eh_bus_reset_handler = NULL;
3898 } 3953 }
@@ -3942,7 +3997,7 @@ fail_set_dma_mask:
3942static int __devinit 3997static int __devinit
3943megasas_probe_one(struct pci_dev *pdev, const struct pci_device_id *id) 3998megasas_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
3944{ 3999{
3945 int rval, pos; 4000 int rval, pos, i, j;
3946 struct Scsi_Host *host; 4001 struct Scsi_Host *host;
3947 struct megasas_instance *instance; 4002 struct megasas_instance *instance;
3948 u16 control = 0; 4003 u16 control = 0;
@@ -4002,6 +4057,7 @@ megasas_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
4002 4057
4003 switch (instance->pdev->device) { 4058 switch (instance->pdev->device) {
4004 case PCI_DEVICE_ID_LSI_FUSION: 4059 case PCI_DEVICE_ID_LSI_FUSION:
4060 case PCI_DEVICE_ID_LSI_INVADER:
4005 { 4061 {
4006 struct fusion_context *fusion; 4062 struct fusion_context *fusion;
4007 4063
@@ -4094,7 +4150,8 @@ megasas_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
4094 instance->last_time = 0; 4150 instance->last_time = 0;
4095 instance->disableOnlineCtrlReset = 1; 4151 instance->disableOnlineCtrlReset = 1;
4096 4152
4097 if (instance->pdev->device == PCI_DEVICE_ID_LSI_FUSION) 4153 if ((instance->pdev->device == PCI_DEVICE_ID_LSI_FUSION) ||
4154 (instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER))
4098 INIT_WORK(&instance->work_init, megasas_fusion_ocr_wq); 4155 INIT_WORK(&instance->work_init, megasas_fusion_ocr_wq);
4099 else 4156 else
4100 INIT_WORK(&instance->work_init, process_fw_state_change_wq); 4157 INIT_WORK(&instance->work_init, process_fw_state_change_wq);
@@ -4108,11 +4165,32 @@ megasas_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
4108 /* 4165 /*
4109 * Register IRQ 4166 * Register IRQ
4110 */ 4167 */
4111 if (request_irq(instance->msi_flag ? instance->msixentry.vector : 4168 if (instance->msix_vectors) {
4112 pdev->irq, instance->instancet->service_isr, 4169 for (i = 0 ; i < instance->msix_vectors; i++) {
4113 IRQF_SHARED, "megasas", instance)) { 4170 instance->irq_context[i].instance = instance;
4114 printk(KERN_DEBUG "megasas: Failed to register IRQ\n"); 4171 instance->irq_context[i].MSIxIndex = i;
4115 goto fail_irq; 4172 if (request_irq(instance->msixentry[i].vector,
4173 instance->instancet->service_isr, 0,
4174 "megasas",
4175 &instance->irq_context[i])) {
4176 printk(KERN_DEBUG "megasas: Failed to "
4177 "register IRQ for vector %d.\n", i);
4178 for (j = 0 ; j < i ; j++)
4179 free_irq(
4180 instance->msixentry[j].vector,
4181 &instance->irq_context[j]);
4182 goto fail_irq;
4183 }
4184 }
4185 } else {
4186 instance->irq_context[0].instance = instance;
4187 instance->irq_context[0].MSIxIndex = 0;
4188 if (request_irq(pdev->irq, instance->instancet->service_isr,
4189 IRQF_SHARED, "megasas",
4190 &instance->irq_context[0])) {
4191 printk(KERN_DEBUG "megasas: Failed to register IRQ\n");
4192 goto fail_irq;
4193 }
4116 } 4194 }
4117 4195
4118 instance->instancet->enable_intr(instance->reg_set); 4196 instance->instancet->enable_intr(instance->reg_set);
@@ -4156,15 +4234,20 @@ megasas_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
4156 4234
4157 pci_set_drvdata(pdev, NULL); 4235 pci_set_drvdata(pdev, NULL);
4158 instance->instancet->disable_intr(instance->reg_set); 4236 instance->instancet->disable_intr(instance->reg_set);
4159 free_irq(instance->msi_flag ? instance->msixentry.vector : 4237 if (instance->msix_vectors)
4160 instance->pdev->irq, instance); 4238 for (i = 0 ; i < instance->msix_vectors; i++)
4239 free_irq(instance->msixentry[i].vector,
4240 &instance->irq_context[i]);
4241 else
4242 free_irq(instance->pdev->irq, &instance->irq_context[0]);
4161fail_irq: 4243fail_irq:
4162 if (instance->pdev->device == PCI_DEVICE_ID_LSI_FUSION) 4244 if ((instance->pdev->device == PCI_DEVICE_ID_LSI_FUSION) ||
4245 (instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER))
4163 megasas_release_fusion(instance); 4246 megasas_release_fusion(instance);
4164 else 4247 else
4165 megasas_release_mfi(instance); 4248 megasas_release_mfi(instance);
4166 fail_init_mfi: 4249 fail_init_mfi:
4167 if (instance->msi_flag) 4250 if (instance->msix_vectors)
4168 pci_disable_msix(instance->pdev); 4251 pci_disable_msix(instance->pdev);
4169 fail_alloc_dma_buf: 4252 fail_alloc_dma_buf:
4170 if (instance->evt_detail) 4253 if (instance->evt_detail)
@@ -4280,6 +4363,7 @@ megasas_suspend(struct pci_dev *pdev, pm_message_t state)
4280{ 4363{
4281 struct Scsi_Host *host; 4364 struct Scsi_Host *host;
4282 struct megasas_instance *instance; 4365 struct megasas_instance *instance;
4366 int i;
4283 4367
4284 instance = pci_get_drvdata(pdev); 4368 instance = pci_get_drvdata(pdev);
4285 host = instance->host; 4369 host = instance->host;
@@ -4303,9 +4387,14 @@ megasas_suspend(struct pci_dev *pdev, pm_message_t state)
4303 4387
4304 pci_set_drvdata(instance->pdev, instance); 4388 pci_set_drvdata(instance->pdev, instance);
4305 instance->instancet->disable_intr(instance->reg_set); 4389 instance->instancet->disable_intr(instance->reg_set);
4306 free_irq(instance->msi_flag ? instance->msixentry.vector : 4390
4307 instance->pdev->irq, instance); 4391 if (instance->msix_vectors)
4308 if (instance->msi_flag) 4392 for (i = 0 ; i < instance->msix_vectors; i++)
4393 free_irq(instance->msixentry[i].vector,
4394 &instance->irq_context[i]);
4395 else
4396 free_irq(instance->pdev->irq, &instance->irq_context[0]);
4397 if (instance->msix_vectors)
4309 pci_disable_msix(instance->pdev); 4398 pci_disable_msix(instance->pdev);
4310 4399
4311 pci_save_state(pdev); 4400 pci_save_state(pdev);
@@ -4323,7 +4412,7 @@ megasas_suspend(struct pci_dev *pdev, pm_message_t state)
4323static int 4412static int
4324megasas_resume(struct pci_dev *pdev) 4413megasas_resume(struct pci_dev *pdev)
4325{ 4414{
4326 int rval; 4415 int rval, i, j;
4327 struct Scsi_Host *host; 4416 struct Scsi_Host *host;
4328 struct megasas_instance *instance; 4417 struct megasas_instance *instance;
4329 4418
@@ -4357,15 +4446,17 @@ megasas_resume(struct pci_dev *pdev)
4357 /* 4446 /*
4358 * We expect the FW state to be READY 4447 * We expect the FW state to be READY
4359 */ 4448 */
4360 if (megasas_transition_to_ready(instance)) 4449 if (megasas_transition_to_ready(instance, 0))
4361 goto fail_ready_state; 4450 goto fail_ready_state;
4362 4451
4363 /* Now re-enable MSI-X */ 4452 /* Now re-enable MSI-X */
4364 if (instance->msi_flag) 4453 if (instance->msix_vectors)
4365 pci_enable_msix(instance->pdev, &instance->msixentry, 1); 4454 pci_enable_msix(instance->pdev, instance->msixentry,
4455 instance->msix_vectors);
4366 4456
4367 switch (instance->pdev->device) { 4457 switch (instance->pdev->device) {
4368 case PCI_DEVICE_ID_LSI_FUSION: 4458 case PCI_DEVICE_ID_LSI_FUSION:
4459 case PCI_DEVICE_ID_LSI_INVADER:
4369 { 4460 {
4370 megasas_reset_reply_desc(instance); 4461 megasas_reset_reply_desc(instance);
4371 if (megasas_ioc_init_fusion(instance)) { 4462 if (megasas_ioc_init_fusion(instance)) {
@@ -4391,11 +4482,32 @@ megasas_resume(struct pci_dev *pdev)
4391 /* 4482 /*
4392 * Register IRQ 4483 * Register IRQ
4393 */ 4484 */
4394 if (request_irq(instance->msi_flag ? instance->msixentry.vector : 4485 if (instance->msix_vectors) {
4395 pdev->irq, instance->instancet->service_isr, 4486 for (i = 0 ; i < instance->msix_vectors; i++) {
4396 IRQF_SHARED, "megasas", instance)) { 4487 instance->irq_context[i].instance = instance;
4397 printk(KERN_ERR "megasas: Failed to register IRQ\n"); 4488 instance->irq_context[i].MSIxIndex = i;
4398 goto fail_irq; 4489 if (request_irq(instance->msixentry[i].vector,
4490 instance->instancet->service_isr, 0,
4491 "megasas",
4492 &instance->irq_context[i])) {
4493 printk(KERN_DEBUG "megasas: Failed to "
4494 "register IRQ for vector %d.\n", i);
4495 for (j = 0 ; j < i ; j++)
4496 free_irq(
4497 instance->msixentry[j].vector,
4498 &instance->irq_context[j]);
4499 goto fail_irq;
4500 }
4501 }
4502 } else {
4503 instance->irq_context[0].instance = instance;
4504 instance->irq_context[0].MSIxIndex = 0;
4505 if (request_irq(pdev->irq, instance->instancet->service_isr,
4506 IRQF_SHARED, "megasas",
4507 &instance->irq_context[0])) {
4508 printk(KERN_DEBUG "megasas: Failed to register IRQ\n");
4509 goto fail_irq;
4510 }
4399 } 4511 }
4400 4512
4401 instance->instancet->enable_intr(instance->reg_set); 4513 instance->instancet->enable_intr(instance->reg_set);
@@ -4492,13 +4604,18 @@ static void __devexit megasas_detach_one(struct pci_dev *pdev)
4492 4604
4493 instance->instancet->disable_intr(instance->reg_set); 4605 instance->instancet->disable_intr(instance->reg_set);
4494 4606
4495 free_irq(instance->msi_flag ? instance->msixentry.vector : 4607 if (instance->msix_vectors)
4496 instance->pdev->irq, instance); 4608 for (i = 0 ; i < instance->msix_vectors; i++)
4497 if (instance->msi_flag) 4609 free_irq(instance->msixentry[i].vector,
4610 &instance->irq_context[i]);
4611 else
4612 free_irq(instance->pdev->irq, &instance->irq_context[0]);
4613 if (instance->msix_vectors)
4498 pci_disable_msix(instance->pdev); 4614 pci_disable_msix(instance->pdev);
4499 4615
4500 switch (instance->pdev->device) { 4616 switch (instance->pdev->device) {
4501 case PCI_DEVICE_ID_LSI_FUSION: 4617 case PCI_DEVICE_ID_LSI_FUSION:
4618 case PCI_DEVICE_ID_LSI_INVADER:
4502 megasas_release_fusion(instance); 4619 megasas_release_fusion(instance);
4503 for (i = 0; i < 2 ; i++) 4620 for (i = 0; i < 2 ; i++)
4504 if (fusion->ld_map[i]) 4621 if (fusion->ld_map[i])
@@ -4539,14 +4656,20 @@ static void __devexit megasas_detach_one(struct pci_dev *pdev)
4539 */ 4656 */
4540static void megasas_shutdown(struct pci_dev *pdev) 4657static void megasas_shutdown(struct pci_dev *pdev)
4541{ 4658{
4659 int i;
4542 struct megasas_instance *instance = pci_get_drvdata(pdev); 4660 struct megasas_instance *instance = pci_get_drvdata(pdev);
4661
4543 instance->unload = 1; 4662 instance->unload = 1;
4544 megasas_flush_cache(instance); 4663 megasas_flush_cache(instance);
4545 megasas_shutdown_controller(instance, MR_DCMD_CTRL_SHUTDOWN); 4664 megasas_shutdown_controller(instance, MR_DCMD_CTRL_SHUTDOWN);
4546 instance->instancet->disable_intr(instance->reg_set); 4665 instance->instancet->disable_intr(instance->reg_set);
4547 free_irq(instance->msi_flag ? instance->msixentry.vector : 4666 if (instance->msix_vectors)
4548 instance->pdev->irq, instance); 4667 for (i = 0 ; i < instance->msix_vectors; i++)
4549 if (instance->msi_flag) 4668 free_irq(instance->msixentry[i].vector,
4669 &instance->irq_context[i]);
4670 else
4671 free_irq(instance->pdev->irq, &instance->irq_context[0]);
4672 if (instance->msix_vectors)
4550 pci_disable_msix(instance->pdev); 4673 pci_disable_msix(instance->pdev);
4551} 4674}
4552 4675
diff --git a/drivers/scsi/megaraid/megaraid_sas_fp.c b/drivers/scsi/megaraid/megaraid_sas_fp.c
index 5a5af1fe7581..5255dd688aca 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fp.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fp.c
@@ -52,6 +52,7 @@
52#include <scsi/scsi_host.h> 52#include <scsi/scsi_host.h>
53 53
54#include "megaraid_sas_fusion.h" 54#include "megaraid_sas_fusion.h"
55#include "megaraid_sas.h"
55#include <asm/div64.h> 56#include <asm/div64.h>
56 57
57#define ABS_DIFF(a, b) (((a) > (b)) ? ((a) - (b)) : ((b) - (a))) 58#define ABS_DIFF(a, b) (((a) > (b)) ? ((a) - (b)) : ((b) - (a)))
@@ -226,8 +227,9 @@ u32 MR_GetSpanBlock(u32 ld, u64 row, u64 *span_blk,
226* span - Span number 227* span - Span number
227* block - Absolute Block number in the physical disk 228* block - Absolute Block number in the physical disk
228*/ 229*/
229u8 MR_GetPhyParams(u32 ld, u64 stripRow, u16 stripRef, u64 *pdBlock, 230u8 MR_GetPhyParams(struct megasas_instance *instance, u32 ld, u64 stripRow,
230 u16 *pDevHandle, struct RAID_CONTEXT *pRAID_Context, 231 u16 stripRef, u64 *pdBlock, u16 *pDevHandle,
232 struct RAID_CONTEXT *pRAID_Context,
231 struct MR_FW_RAID_MAP_ALL *map) 233 struct MR_FW_RAID_MAP_ALL *map)
232{ 234{
233 struct MR_LD_RAID *raid = MR_LdRaidGet(ld, map); 235 struct MR_LD_RAID *raid = MR_LdRaidGet(ld, map);
@@ -279,7 +281,8 @@ u8 MR_GetPhyParams(u32 ld, u64 stripRow, u16 stripRef, u64 *pdBlock,
279 *pDevHandle = MR_PdDevHandleGet(pd, map); 281 *pDevHandle = MR_PdDevHandleGet(pd, map);
280 else { 282 else {
281 *pDevHandle = MR_PD_INVALID; /* set dev handle as invalid. */ 283 *pDevHandle = MR_PD_INVALID; /* set dev handle as invalid. */
282 if (raid->level >= 5) 284 if ((raid->level >= 5) &&
285 (instance->pdev->device != PCI_DEVICE_ID_LSI_INVADER))
283 pRAID_Context->regLockFlags = REGION_TYPE_EXCLUSIVE; 286 pRAID_Context->regLockFlags = REGION_TYPE_EXCLUSIVE;
284 else if (raid->level == 1) { 287 else if (raid->level == 1) {
285 /* Get alternate Pd. */ 288 /* Get alternate Pd. */
@@ -306,7 +309,8 @@ u8 MR_GetPhyParams(u32 ld, u64 stripRow, u16 stripRef, u64 *pdBlock,
306* This function will return 0 if region lock was acquired OR return num strips 309* This function will return 0 if region lock was acquired OR return num strips
307*/ 310*/
308u8 311u8
309MR_BuildRaidContext(struct IO_REQUEST_INFO *io_info, 312MR_BuildRaidContext(struct megasas_instance *instance,
313 struct IO_REQUEST_INFO *io_info,
310 struct RAID_CONTEXT *pRAID_Context, 314 struct RAID_CONTEXT *pRAID_Context,
311 struct MR_FW_RAID_MAP_ALL *map) 315 struct MR_FW_RAID_MAP_ALL *map)
312{ 316{
@@ -394,8 +398,12 @@ MR_BuildRaidContext(struct IO_REQUEST_INFO *io_info,
394 } 398 }
395 399
396 pRAID_Context->timeoutValue = map->raidMap.fpPdIoTimeoutSec; 400 pRAID_Context->timeoutValue = map->raidMap.fpPdIoTimeoutSec;
397 pRAID_Context->regLockFlags = (isRead) ? REGION_TYPE_SHARED_READ : 401 if (instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER)
398 raid->regTypeReqOnWrite; 402 pRAID_Context->regLockFlags = (isRead) ?
403 raid->regTypeReqOnRead : raid->regTypeReqOnWrite;
404 else
405 pRAID_Context->regLockFlags = (isRead) ?
406 REGION_TYPE_SHARED_READ : raid->regTypeReqOnWrite;
399 pRAID_Context->VirtualDiskTgtId = raid->targetId; 407 pRAID_Context->VirtualDiskTgtId = raid->targetId;
400 pRAID_Context->regLockRowLBA = regStart; 408 pRAID_Context->regLockRowLBA = regStart;
401 pRAID_Context->regLockLength = regSize; 409 pRAID_Context->regLockLength = regSize;
@@ -404,7 +412,8 @@ MR_BuildRaidContext(struct IO_REQUEST_INFO *io_info,
404 /*Get Phy Params only if FP capable, or else leave it to MR firmware 412 /*Get Phy Params only if FP capable, or else leave it to MR firmware
405 to do the calculation.*/ 413 to do the calculation.*/
406 if (io_info->fpOkForIo) { 414 if (io_info->fpOkForIo) {
407 retval = MR_GetPhyParams(ld, start_strip, ref_in_start_stripe, 415 retval = MR_GetPhyParams(instance, ld, start_strip,
416 ref_in_start_stripe,
408 &io_info->pdBlock, 417 &io_info->pdBlock,
409 &io_info->devHandle, pRAID_Context, 418 &io_info->devHandle, pRAID_Context,
410 map); 419 map);
@@ -415,7 +424,8 @@ MR_BuildRaidContext(struct IO_REQUEST_INFO *io_info,
415 } else if (isRead) { 424 } else if (isRead) {
416 uint stripIdx; 425 uint stripIdx;
417 for (stripIdx = 0; stripIdx < num_strips; stripIdx++) { 426 for (stripIdx = 0; stripIdx < num_strips; stripIdx++) {
418 if (!MR_GetPhyParams(ld, start_strip + stripIdx, 427 if (!MR_GetPhyParams(instance, ld,
428 start_strip + stripIdx,
419 ref_in_start_stripe, 429 ref_in_start_stripe,
420 &io_info->pdBlock, 430 &io_info->pdBlock,
421 &io_info->devHandle, 431 &io_info->devHandle,
diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index f13e7abd345a..bfd87fab39aa 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -74,7 +74,8 @@ megasas_issue_polled(struct megasas_instance *instance,
74 struct megasas_cmd *cmd); 74 struct megasas_cmd *cmd);
75 75
76u8 76u8
77MR_BuildRaidContext(struct IO_REQUEST_INFO *io_info, 77MR_BuildRaidContext(struct megasas_instance *instance,
78 struct IO_REQUEST_INFO *io_info,
78 struct RAID_CONTEXT *pRAID_Context, 79 struct RAID_CONTEXT *pRAID_Context,
79 struct MR_FW_RAID_MAP_ALL *map); 80 struct MR_FW_RAID_MAP_ALL *map);
80u16 MR_TargetIdToLdGet(u32 ldTgtId, struct MR_FW_RAID_MAP_ALL *map); 81u16 MR_TargetIdToLdGet(u32 ldTgtId, struct MR_FW_RAID_MAP_ALL *map);
@@ -89,7 +90,7 @@ u8 MR_ValidateMapInfo(struct MR_FW_RAID_MAP_ALL *map,
89 struct LD_LOAD_BALANCE_INFO *lbInfo); 90 struct LD_LOAD_BALANCE_INFO *lbInfo);
90u16 get_updated_dev_handle(struct LD_LOAD_BALANCE_INFO *lbInfo, 91u16 get_updated_dev_handle(struct LD_LOAD_BALANCE_INFO *lbInfo,
91 struct IO_REQUEST_INFO *in_info); 92 struct IO_REQUEST_INFO *in_info);
92int megasas_transition_to_ready(struct megasas_instance *instance); 93int megasas_transition_to_ready(struct megasas_instance *instance, int ocr);
93void megaraid_sas_kill_hba(struct megasas_instance *instance); 94void megaraid_sas_kill_hba(struct megasas_instance *instance);
94 95
95extern u32 megasas_dbg_lvl; 96extern u32 megasas_dbg_lvl;
@@ -101,6 +102,10 @@ extern u32 megasas_dbg_lvl;
101void 102void
102megasas_enable_intr_fusion(struct megasas_register_set __iomem *regs) 103megasas_enable_intr_fusion(struct megasas_register_set __iomem *regs)
103{ 104{
105 /* For Thunderbolt/Invader also clear intr on enable */
106 writel(~0, &regs->outbound_intr_status);
107 readl(&regs->outbound_intr_status);
108
104 writel(~MFI_FUSION_ENABLE_INTERRUPT_MASK, &(regs)->outbound_intr_mask); 109 writel(~MFI_FUSION_ENABLE_INTERRUPT_MASK, &(regs)->outbound_intr_mask);
105 110
106 /* Dummy readl to force pci flush */ 111 /* Dummy readl to force pci flush */
@@ -139,11 +144,6 @@ megasas_clear_intr_fusion(struct megasas_register_set __iomem *regs)
139 if (!(status & MFI_FUSION_ENABLE_INTERRUPT_MASK)) 144 if (!(status & MFI_FUSION_ENABLE_INTERRUPT_MASK))
140 return 0; 145 return 0;
141 146
142 /*
143 * dummy read to flush PCI
144 */
145 readl(&regs->outbound_intr_status);
146
147 return 1; 147 return 1;
148} 148}
149 149
@@ -385,7 +385,7 @@ static int megasas_create_frame_pool_fusion(struct megasas_instance *instance)
385int 385int
386megasas_alloc_cmds_fusion(struct megasas_instance *instance) 386megasas_alloc_cmds_fusion(struct megasas_instance *instance)
387{ 387{
388 int i, j; 388 int i, j, count;
389 u32 max_cmd, io_frames_sz; 389 u32 max_cmd, io_frames_sz;
390 struct fusion_context *fusion; 390 struct fusion_context *fusion;
391 struct megasas_cmd_fusion *cmd; 391 struct megasas_cmd_fusion *cmd;
@@ -409,9 +409,10 @@ megasas_alloc_cmds_fusion(struct megasas_instance *instance)
409 goto fail_req_desc; 409 goto fail_req_desc;
410 } 410 }
411 411
412 count = instance->msix_vectors > 0 ? instance->msix_vectors : 1;
412 fusion->reply_frames_desc_pool = 413 fusion->reply_frames_desc_pool =
413 pci_pool_create("reply_frames pool", instance->pdev, 414 pci_pool_create("reply_frames pool", instance->pdev,
414 fusion->reply_alloc_sz, 16, 0); 415 fusion->reply_alloc_sz * count, 16, 0);
415 416
416 if (!fusion->reply_frames_desc_pool) { 417 if (!fusion->reply_frames_desc_pool) {
417 printk(KERN_ERR "megasas; Could not allocate memory for " 418 printk(KERN_ERR "megasas; Could not allocate memory for "
@@ -430,7 +431,7 @@ megasas_alloc_cmds_fusion(struct megasas_instance *instance)
430 } 431 }
431 432
432 reply_desc = fusion->reply_frames_desc; 433 reply_desc = fusion->reply_frames_desc;
433 for (i = 0; i < fusion->reply_q_depth; i++, reply_desc++) 434 for (i = 0; i < fusion->reply_q_depth * count; i++, reply_desc++)
434 reply_desc->Words = ULLONG_MAX; 435 reply_desc->Words = ULLONG_MAX;
435 436
436 io_frames_sz = fusion->io_frames_alloc_sz; 437 io_frames_sz = fusion->io_frames_alloc_sz;
@@ -590,7 +591,6 @@ megasas_ioc_init_fusion(struct megasas_instance *instance)
590 struct megasas_init_frame *init_frame; 591 struct megasas_init_frame *init_frame;
591 struct MPI2_IOC_INIT_REQUEST *IOCInitMessage; 592 struct MPI2_IOC_INIT_REQUEST *IOCInitMessage;
592 dma_addr_t ioc_init_handle; 593 dma_addr_t ioc_init_handle;
593 u32 context;
594 struct megasas_cmd *cmd; 594 struct megasas_cmd *cmd;
595 u8 ret; 595 u8 ret;
596 struct fusion_context *fusion; 596 struct fusion_context *fusion;
@@ -634,14 +634,13 @@ megasas_ioc_init_fusion(struct megasas_instance *instance)
634 fusion->reply_frames_desc_phys; 634 fusion->reply_frames_desc_phys;
635 IOCInitMessage->SystemRequestFrameBaseAddress = 635 IOCInitMessage->SystemRequestFrameBaseAddress =
636 fusion->io_request_frames_phys; 636 fusion->io_request_frames_phys;
637 637 /* Set to 0 for none or 1 MSI-X vectors */
638 IOCInitMessage->HostMSIxVectors = (instance->msix_vectors > 0 ?
639 instance->msix_vectors : 0);
638 init_frame = (struct megasas_init_frame *)cmd->frame; 640 init_frame = (struct megasas_init_frame *)cmd->frame;
639 memset(init_frame, 0, MEGAMFI_FRAME_SIZE); 641 memset(init_frame, 0, MEGAMFI_FRAME_SIZE);
640 642
641 frame_hdr = &cmd->frame->hdr; 643 frame_hdr = &cmd->frame->hdr;
642 context = init_frame->context;
643 init_frame->context = context;
644
645 frame_hdr->cmd_status = 0xFF; 644 frame_hdr->cmd_status = 0xFF;
646 frame_hdr->flags |= MFI_FRAME_DONT_POST_IN_REPLY_QUEUE; 645 frame_hdr->flags |= MFI_FRAME_DONT_POST_IN_REPLY_QUEUE;
647 646
@@ -881,7 +880,7 @@ megasas_init_adapter_fusion(struct megasas_instance *instance)
881 struct megasas_register_set __iomem *reg_set; 880 struct megasas_register_set __iomem *reg_set;
882 struct fusion_context *fusion; 881 struct fusion_context *fusion;
883 u32 max_cmd; 882 u32 max_cmd;
884 int i = 0; 883 int i = 0, count;
885 884
886 fusion = instance->ctrl_context; 885 fusion = instance->ctrl_context;
887 886
@@ -933,7 +932,9 @@ megasas_init_adapter_fusion(struct megasas_instance *instance)
933 (MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE - 932 (MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE -
934 sizeof(union MPI2_SGE_IO_UNION))/16; 933 sizeof(union MPI2_SGE_IO_UNION))/16;
935 934
936 fusion->last_reply_idx = 0; 935 count = instance->msix_vectors > 0 ? instance->msix_vectors : 1;
936 for (i = 0 ; i < count; i++)
937 fusion->last_reply_idx[i] = 0;
937 938
938 /* 939 /*
939 * Allocate memory for descriptors 940 * Allocate memory for descriptors
@@ -1043,7 +1044,9 @@ map_cmd_status(struct megasas_cmd_fusion *cmd, u8 status, u8 ext_status)
1043 case MFI_STAT_DEVICE_NOT_FOUND: 1044 case MFI_STAT_DEVICE_NOT_FOUND:
1044 cmd->scmd->result = DID_BAD_TARGET << 16; 1045 cmd->scmd->result = DID_BAD_TARGET << 16;
1045 break; 1046 break;
1046 1047 case MFI_STAT_CONFIG_SEQ_MISMATCH:
1048 cmd->scmd->result = DID_IMM_RETRY << 16;
1049 break;
1047 default: 1050 default:
1048 printk(KERN_DEBUG "megasas: FW status %#x\n", status); 1051 printk(KERN_DEBUG "megasas: FW status %#x\n", status);
1049 cmd->scmd->result = DID_ERROR << 16; 1052 cmd->scmd->result = DID_ERROR << 16;
@@ -1066,14 +1069,17 @@ megasas_make_sgl_fusion(struct megasas_instance *instance,
1066 struct MPI25_IEEE_SGE_CHAIN64 *sgl_ptr, 1069 struct MPI25_IEEE_SGE_CHAIN64 *sgl_ptr,
1067 struct megasas_cmd_fusion *cmd) 1070 struct megasas_cmd_fusion *cmd)
1068{ 1071{
1069 int i, sg_processed; 1072 int i, sg_processed, sge_count;
1070 int sge_count, sge_idx;
1071 struct scatterlist *os_sgl; 1073 struct scatterlist *os_sgl;
1072 struct fusion_context *fusion; 1074 struct fusion_context *fusion;
1073 1075
1074 fusion = instance->ctrl_context; 1076 fusion = instance->ctrl_context;
1075 1077
1076 cmd->io_request->ChainOffset = 0; 1078 if (instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) {
1079 struct MPI25_IEEE_SGE_CHAIN64 *sgl_ptr_end = sgl_ptr;
1080 sgl_ptr_end += fusion->max_sge_in_main_msg - 1;
1081 sgl_ptr_end->Flags = 0;
1082 }
1077 1083
1078 sge_count = scsi_dma_map(scp); 1084 sge_count = scsi_dma_map(scp);
1079 1085
@@ -1082,16 +1088,14 @@ megasas_make_sgl_fusion(struct megasas_instance *instance,
1082 if (sge_count > instance->max_num_sge || !sge_count) 1088 if (sge_count > instance->max_num_sge || !sge_count)
1083 return sge_count; 1089 return sge_count;
1084 1090
1085 if (sge_count > fusion->max_sge_in_main_msg) {
1086 /* One element to store the chain info */
1087 sge_idx = fusion->max_sge_in_main_msg - 1;
1088 } else
1089 sge_idx = sge_count;
1090
1091 scsi_for_each_sg(scp, os_sgl, sge_count, i) { 1091 scsi_for_each_sg(scp, os_sgl, sge_count, i) {
1092 sgl_ptr->Length = sg_dma_len(os_sgl); 1092 sgl_ptr->Length = sg_dma_len(os_sgl);
1093 sgl_ptr->Address = sg_dma_address(os_sgl); 1093 sgl_ptr->Address = sg_dma_address(os_sgl);
1094 sgl_ptr->Flags = 0; 1094 sgl_ptr->Flags = 0;
1095 if (instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) {
1096 if (i == sge_count - 1)
1097 sgl_ptr->Flags = IEEE_SGE_FLAGS_END_OF_LIST;
1098 }
1095 sgl_ptr++; 1099 sgl_ptr++;
1096 1100
1097 sg_processed = i + 1; 1101 sg_processed = i + 1;
@@ -1100,13 +1104,30 @@ megasas_make_sgl_fusion(struct megasas_instance *instance,
1100 (sge_count > fusion->max_sge_in_main_msg)) { 1104 (sge_count > fusion->max_sge_in_main_msg)) {
1101 1105
1102 struct MPI25_IEEE_SGE_CHAIN64 *sg_chain; 1106 struct MPI25_IEEE_SGE_CHAIN64 *sg_chain;
1103 cmd->io_request->ChainOffset = 1107 if (instance->pdev->device ==
1104 fusion->chain_offset_io_request; 1108 PCI_DEVICE_ID_LSI_INVADER) {
1109 if ((cmd->io_request->IoFlags &
1110 MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH) !=
1111 MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH)
1112 cmd->io_request->ChainOffset =
1113 fusion->
1114 chain_offset_io_request;
1115 else
1116 cmd->io_request->ChainOffset = 0;
1117 } else
1118 cmd->io_request->ChainOffset =
1119 fusion->chain_offset_io_request;
1120
1105 sg_chain = sgl_ptr; 1121 sg_chain = sgl_ptr;
1106 /* Prepare chain element */ 1122 /* Prepare chain element */
1107 sg_chain->NextChainOffset = 0; 1123 sg_chain->NextChainOffset = 0;
1108 sg_chain->Flags = (IEEE_SGE_FLAGS_CHAIN_ELEMENT | 1124 if (instance->pdev->device ==
1109 MPI2_IEEE_SGE_FLAGS_IOCPLBNTA_ADDR); 1125 PCI_DEVICE_ID_LSI_INVADER)
1126 sg_chain->Flags = IEEE_SGE_FLAGS_CHAIN_ELEMENT;
1127 else
1128 sg_chain->Flags =
1129 (IEEE_SGE_FLAGS_CHAIN_ELEMENT |
1130 MPI2_IEEE_SGE_FLAGS_IOCPLBNTA_ADDR);
1110 sg_chain->Length = (sizeof(union MPI2_SGE_IO_UNION) 1131 sg_chain->Length = (sizeof(union MPI2_SGE_IO_UNION)
1111 *(sge_count - sg_processed)); 1132 *(sge_count - sg_processed));
1112 sg_chain->Address = cmd->sg_frame_phys_addr; 1133 sg_chain->Address = cmd->sg_frame_phys_addr;
@@ -1399,11 +1420,18 @@ megasas_build_ldio_fusion(struct megasas_instance *instance,
1399 io_request->RaidContext.regLockFlags = 0; 1420 io_request->RaidContext.regLockFlags = 0;
1400 fp_possible = 0; 1421 fp_possible = 0;
1401 } else { 1422 } else {
1402 if (MR_BuildRaidContext(&io_info, &io_request->RaidContext, 1423 if (MR_BuildRaidContext(instance, &io_info,
1424 &io_request->RaidContext,
1403 local_map_ptr)) 1425 local_map_ptr))
1404 fp_possible = io_info.fpOkForIo; 1426 fp_possible = io_info.fpOkForIo;
1405 } 1427 }
1406 1428
1429 /* Use smp_processor_id() for now until cmd->request->cpu is CPU
1430 id by default, not CPU group id, otherwise all MSI-X queues won't
1431 be utilized */
1432 cmd->request_desc->SCSIIO.MSIxIndex = instance->msix_vectors ?
1433 smp_processor_id() % instance->msix_vectors : 0;
1434
1407 if (fp_possible) { 1435 if (fp_possible) {
1408 megasas_set_pd_lba(io_request, scp->cmd_len, &io_info, scp, 1436 megasas_set_pd_lba(io_request, scp->cmd_len, &io_info, scp,
1409 local_map_ptr, start_lba_lo); 1437 local_map_ptr, start_lba_lo);
@@ -1412,6 +1440,20 @@ megasas_build_ldio_fusion(struct megasas_instance *instance,
1412 cmd->request_desc->SCSIIO.RequestFlags = 1440 cmd->request_desc->SCSIIO.RequestFlags =
1413 (MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY 1441 (MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY
1414 << MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); 1442 << MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
1443 if (instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) {
1444 if (io_request->RaidContext.regLockFlags ==
1445 REGION_TYPE_UNUSED)
1446 cmd->request_desc->SCSIIO.RequestFlags =
1447 (MEGASAS_REQ_DESCRIPT_FLAGS_NO_LOCK <<
1448 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
1449 io_request->RaidContext.Type = MPI2_TYPE_CUDA;
1450 io_request->RaidContext.nseg = 0x1;
1451 io_request->IoFlags |=
1452 MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH;
1453 io_request->RaidContext.regLockFlags |=
1454 (MR_RL_FLAGS_GRANT_DESTINATION_CUDA |
1455 MR_RL_FLAGS_SEQ_NUM_ENABLE);
1456 }
1415 if ((fusion->load_balance_info[device_id].loadBalanceFlag) && 1457 if ((fusion->load_balance_info[device_id].loadBalanceFlag) &&
1416 (io_info.isRead)) { 1458 (io_info.isRead)) {
1417 io_info.devHandle = 1459 io_info.devHandle =
@@ -1426,11 +1468,23 @@ megasas_build_ldio_fusion(struct megasas_instance *instance,
1426 } else { 1468 } else {
1427 io_request->RaidContext.timeoutValue = 1469 io_request->RaidContext.timeoutValue =
1428 local_map_ptr->raidMap.fpPdIoTimeoutSec; 1470 local_map_ptr->raidMap.fpPdIoTimeoutSec;
1429 io_request->Function = MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST;
1430 io_request->DevHandle = device_id;
1431 cmd->request_desc->SCSIIO.RequestFlags = 1471 cmd->request_desc->SCSIIO.RequestFlags =
1432 (MEGASAS_REQ_DESCRIPT_FLAGS_LD_IO 1472 (MEGASAS_REQ_DESCRIPT_FLAGS_LD_IO
1433 << MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); 1473 << MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
1474 if (instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) {
1475 if (io_request->RaidContext.regLockFlags ==
1476 REGION_TYPE_UNUSED)
1477 cmd->request_desc->SCSIIO.RequestFlags =
1478 (MEGASAS_REQ_DESCRIPT_FLAGS_NO_LOCK <<
1479 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
1480 io_request->RaidContext.Type = MPI2_TYPE_CUDA;
1481 io_request->RaidContext.regLockFlags |=
1482 (MR_RL_FLAGS_GRANT_DESTINATION_CPU0 |
1483 MR_RL_FLAGS_SEQ_NUM_ENABLE);
1484 io_request->RaidContext.nseg = 0x1;
1485 }
1486 io_request->Function = MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST;
1487 io_request->DevHandle = device_id;
1434 } /* Not FP */ 1488 } /* Not FP */
1435} 1489}
1436 1490
@@ -1513,8 +1567,10 @@ megasas_build_io_fusion(struct megasas_instance *instance,
1513 io_request->EEDPFlags = 0; 1567 io_request->EEDPFlags = 0;
1514 io_request->Control = 0; 1568 io_request->Control = 0;
1515 io_request->EEDPBlockSize = 0; 1569 io_request->EEDPBlockSize = 0;
1516 io_request->IoFlags = 0; 1570 io_request->ChainOffset = 0;
1517 io_request->RaidContext.RAIDFlags = 0; 1571 io_request->RaidContext.RAIDFlags = 0;
1572 io_request->RaidContext.Type = 0;
1573 io_request->RaidContext.nseg = 0;
1518 1574
1519 memcpy(io_request->CDB.CDB32, scp->cmnd, scp->cmd_len); 1575 memcpy(io_request->CDB.CDB32, scp->cmnd, scp->cmd_len);
1520 /* 1576 /*
@@ -1612,7 +1668,6 @@ megasas_build_and_issue_cmd_fusion(struct megasas_instance *instance,
1612 1668
1613 req_desc->Words = 0; 1669 req_desc->Words = 0;
1614 cmd->request_desc = req_desc; 1670 cmd->request_desc = req_desc;
1615 cmd->request_desc->Words = 0;
1616 1671
1617 if (megasas_build_io_fusion(instance, scmd, cmd)) { 1672 if (megasas_build_io_fusion(instance, scmd, cmd)) {
1618 megasas_return_cmd_fusion(instance, cmd); 1673 megasas_return_cmd_fusion(instance, cmd);
@@ -1647,7 +1702,7 @@ megasas_build_and_issue_cmd_fusion(struct megasas_instance *instance,
1647 * Completes all commands that is in reply descriptor queue 1702 * Completes all commands that is in reply descriptor queue
1648 */ 1703 */
1649int 1704int
1650complete_cmd_fusion(struct megasas_instance *instance) 1705complete_cmd_fusion(struct megasas_instance *instance, u32 MSIxIndex)
1651{ 1706{
1652 union MPI2_REPLY_DESCRIPTORS_UNION *desc; 1707 union MPI2_REPLY_DESCRIPTORS_UNION *desc;
1653 struct MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR *reply_desc; 1708 struct MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR *reply_desc;
@@ -1667,7 +1722,9 @@ complete_cmd_fusion(struct megasas_instance *instance)
1667 return IRQ_HANDLED; 1722 return IRQ_HANDLED;
1668 1723
1669 desc = fusion->reply_frames_desc; 1724 desc = fusion->reply_frames_desc;
1670 desc += fusion->last_reply_idx; 1725 desc += ((MSIxIndex * fusion->reply_alloc_sz)/
1726 sizeof(union MPI2_REPLY_DESCRIPTORS_UNION)) +
1727 fusion->last_reply_idx[MSIxIndex];
1671 1728
1672 reply_desc = (struct MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR *)desc; 1729 reply_desc = (struct MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR *)desc;
1673 1730
@@ -1740,16 +1797,19 @@ complete_cmd_fusion(struct megasas_instance *instance)
1740 break; 1797 break;
1741 } 1798 }
1742 1799
1743 fusion->last_reply_idx++; 1800 fusion->last_reply_idx[MSIxIndex]++;
1744 if (fusion->last_reply_idx >= fusion->reply_q_depth) 1801 if (fusion->last_reply_idx[MSIxIndex] >=
1745 fusion->last_reply_idx = 0; 1802 fusion->reply_q_depth)
1803 fusion->last_reply_idx[MSIxIndex] = 0;
1746 1804
1747 desc->Words = ULLONG_MAX; 1805 desc->Words = ULLONG_MAX;
1748 num_completed++; 1806 num_completed++;
1749 1807
1750 /* Get the next reply descriptor */ 1808 /* Get the next reply descriptor */
1751 if (!fusion->last_reply_idx) 1809 if (!fusion->last_reply_idx[MSIxIndex])
1752 desc = fusion->reply_frames_desc; 1810 desc = fusion->reply_frames_desc +
1811 ((MSIxIndex * fusion->reply_alloc_sz)/
1812 sizeof(union MPI2_REPLY_DESCRIPTORS_UNION));
1753 else 1813 else
1754 desc++; 1814 desc++;
1755 1815
@@ -1769,7 +1829,7 @@ complete_cmd_fusion(struct megasas_instance *instance)
1769 return IRQ_NONE; 1829 return IRQ_NONE;
1770 1830
1771 wmb(); 1831 wmb();
1772 writel(fusion->last_reply_idx, 1832 writel((MSIxIndex << 24) | fusion->last_reply_idx[MSIxIndex],
1773 &instance->reg_set->reply_post_host_index); 1833 &instance->reg_set->reply_post_host_index);
1774 megasas_check_and_restore_queue_depth(instance); 1834 megasas_check_and_restore_queue_depth(instance);
1775 return IRQ_HANDLED; 1835 return IRQ_HANDLED;
@@ -1787,6 +1847,9 @@ megasas_complete_cmd_dpc_fusion(unsigned long instance_addr)
1787 struct megasas_instance *instance = 1847 struct megasas_instance *instance =
1788 (struct megasas_instance *)instance_addr; 1848 (struct megasas_instance *)instance_addr;
1789 unsigned long flags; 1849 unsigned long flags;
1850 u32 count, MSIxIndex;
1851
1852 count = instance->msix_vectors > 0 ? instance->msix_vectors : 1;
1790 1853
1791 /* If we have already declared adapter dead, donot complete cmds */ 1854 /* If we have already declared adapter dead, donot complete cmds */
1792 spin_lock_irqsave(&instance->hba_lock, flags); 1855 spin_lock_irqsave(&instance->hba_lock, flags);
@@ -1797,7 +1860,8 @@ megasas_complete_cmd_dpc_fusion(unsigned long instance_addr)
1797 spin_unlock_irqrestore(&instance->hba_lock, flags); 1860 spin_unlock_irqrestore(&instance->hba_lock, flags);
1798 1861
1799 spin_lock_irqsave(&instance->completion_lock, flags); 1862 spin_lock_irqsave(&instance->completion_lock, flags);
1800 complete_cmd_fusion(instance); 1863 for (MSIxIndex = 0 ; MSIxIndex < count; MSIxIndex++)
1864 complete_cmd_fusion(instance, MSIxIndex);
1801 spin_unlock_irqrestore(&instance->completion_lock, flags); 1865 spin_unlock_irqrestore(&instance->completion_lock, flags);
1802} 1866}
1803 1867
@@ -1806,20 +1870,24 @@ megasas_complete_cmd_dpc_fusion(unsigned long instance_addr)
1806 */ 1870 */
1807irqreturn_t megasas_isr_fusion(int irq, void *devp) 1871irqreturn_t megasas_isr_fusion(int irq, void *devp)
1808{ 1872{
1809 struct megasas_instance *instance = (struct megasas_instance *)devp; 1873 struct megasas_irq_context *irq_context = devp;
1874 struct megasas_instance *instance = irq_context->instance;
1810 u32 mfiStatus, fw_state; 1875 u32 mfiStatus, fw_state;
1811 1876
1812 if (!instance->msi_flag) { 1877 if (!instance->msix_vectors) {
1813 mfiStatus = instance->instancet->clear_intr(instance->reg_set); 1878 mfiStatus = instance->instancet->clear_intr(instance->reg_set);
1814 if (!mfiStatus) 1879 if (!mfiStatus)
1815 return IRQ_NONE; 1880 return IRQ_NONE;
1816 } 1881 }
1817 1882
1818 /* If we are resetting, bail */ 1883 /* If we are resetting, bail */
1819 if (test_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags)) 1884 if (test_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags)) {
1885 instance->instancet->clear_intr(instance->reg_set);
1820 return IRQ_HANDLED; 1886 return IRQ_HANDLED;
1887 }
1821 1888
1822 if (!complete_cmd_fusion(instance)) { 1889 if (!complete_cmd_fusion(instance, irq_context->MSIxIndex)) {
1890 instance->instancet->clear_intr(instance->reg_set);
1823 /* If we didn't complete any commands, check for FW fault */ 1891 /* If we didn't complete any commands, check for FW fault */
1824 fw_state = instance->instancet->read_fw_status_reg( 1892 fw_state = instance->instancet->read_fw_status_reg(
1825 instance->reg_set) & MFI_STATE_MASK; 1893 instance->reg_set) & MFI_STATE_MASK;
@@ -1866,6 +1934,14 @@ build_mpt_mfi_pass_thru(struct megasas_instance *instance,
1866 1934
1867 fusion = instance->ctrl_context; 1935 fusion = instance->ctrl_context;
1868 io_req = cmd->io_request; 1936 io_req = cmd->io_request;
1937
1938 if (instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) {
1939 struct MPI25_IEEE_SGE_CHAIN64 *sgl_ptr_end =
1940 (struct MPI25_IEEE_SGE_CHAIN64 *)&io_req->SGL;
1941 sgl_ptr_end += fusion->max_sge_in_main_msg - 1;
1942 sgl_ptr_end->Flags = 0;
1943 }
1944
1869 mpi25_ieee_chain = 1945 mpi25_ieee_chain =
1870 (struct MPI25_IEEE_SGE_CHAIN64 *)&io_req->SGL.IeeeChain; 1946 (struct MPI25_IEEE_SGE_CHAIN64 *)&io_req->SGL.IeeeChain;
1871 1947
@@ -1928,15 +2004,12 @@ megasas_issue_dcmd_fusion(struct megasas_instance *instance,
1928 struct megasas_cmd *cmd) 2004 struct megasas_cmd *cmd)
1929{ 2005{
1930 union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc; 2006 union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc;
1931 union desc_value d_val;
1932 2007
1933 req_desc = build_mpt_cmd(instance, cmd); 2008 req_desc = build_mpt_cmd(instance, cmd);
1934 if (!req_desc) { 2009 if (!req_desc) {
1935 printk(KERN_ERR "Couldn't issue MFI pass thru cmd\n"); 2010 printk(KERN_ERR "Couldn't issue MFI pass thru cmd\n");
1936 return; 2011 return;
1937 } 2012 }
1938 d_val.word = req_desc->Words;
1939
1940 instance->instancet->fire_cmd(instance, req_desc->u.low, 2013 instance->instancet->fire_cmd(instance, req_desc->u.low,
1941 req_desc->u.high, instance->reg_set); 2014 req_desc->u.high, instance->reg_set);
1942} 2015}
@@ -2029,14 +2102,16 @@ out:
2029 2102
2030void megasas_reset_reply_desc(struct megasas_instance *instance) 2103void megasas_reset_reply_desc(struct megasas_instance *instance)
2031{ 2104{
2032 int i; 2105 int i, count;
2033 struct fusion_context *fusion; 2106 struct fusion_context *fusion;
2034 union MPI2_REPLY_DESCRIPTORS_UNION *reply_desc; 2107 union MPI2_REPLY_DESCRIPTORS_UNION *reply_desc;
2035 2108
2036 fusion = instance->ctrl_context; 2109 fusion = instance->ctrl_context;
2037 fusion->last_reply_idx = 0; 2110 count = instance->msix_vectors > 0 ? instance->msix_vectors : 1;
2111 for (i = 0 ; i < count ; i++)
2112 fusion->last_reply_idx[i] = 0;
2038 reply_desc = fusion->reply_frames_desc; 2113 reply_desc = fusion->reply_frames_desc;
2039 for (i = 0 ; i < fusion->reply_q_depth; i++, reply_desc++) 2114 for (i = 0 ; i < fusion->reply_q_depth * count; i++, reply_desc++)
2040 reply_desc->Words = ULLONG_MAX; 2115 reply_desc->Words = ULLONG_MAX;
2041} 2116}
2042 2117
@@ -2057,8 +2132,7 @@ int megasas_reset_fusion(struct Scsi_Host *shost)
2057 if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR) { 2132 if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR) {
2058 printk(KERN_WARNING "megaraid_sas: Hardware critical error, " 2133 printk(KERN_WARNING "megaraid_sas: Hardware critical error, "
2059 "returning FAILED.\n"); 2134 "returning FAILED.\n");
2060 retval = FAILED; 2135 return FAILED;
2061 goto out;
2062 } 2136 }
2063 2137
2064 mutex_lock(&instance->reset_mutex); 2138 mutex_lock(&instance->reset_mutex);
@@ -2173,7 +2247,7 @@ int megasas_reset_fusion(struct Scsi_Host *shost)
2173 } 2247 }
2174 2248
2175 /* Wait for FW to become ready */ 2249 /* Wait for FW to become ready */
2176 if (megasas_transition_to_ready(instance)) { 2250 if (megasas_transition_to_ready(instance, 1)) {
2177 printk(KERN_WARNING "megaraid_sas: Failed to " 2251 printk(KERN_WARNING "megaraid_sas: Failed to "
2178 "transition controller to ready.\n"); 2252 "transition controller to ready.\n");
2179 continue; 2253 continue;
@@ -2186,6 +2260,8 @@ int megasas_reset_fusion(struct Scsi_Host *shost)
2186 continue; 2260 continue;
2187 } 2261 }
2188 2262
2263 clear_bit(MEGASAS_FUSION_IN_RESET,
2264 &instance->reset_flags);
2189 instance->instancet->enable_intr(instance->reg_set); 2265 instance->instancet->enable_intr(instance->reg_set);
2190 instance->adprecovery = MEGASAS_HBA_OPERATIONAL; 2266 instance->adprecovery = MEGASAS_HBA_OPERATIONAL;
2191 2267
@@ -2247,6 +2323,7 @@ int megasas_reset_fusion(struct Scsi_Host *shost)
2247 megaraid_sas_kill_hba(instance); 2323 megaraid_sas_kill_hba(instance);
2248 retval = FAILED; 2324 retval = FAILED;
2249 } else { 2325 } else {
2326 clear_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags);
2250 instance->instancet->enable_intr(instance->reg_set); 2327 instance->instancet->enable_intr(instance->reg_set);
2251 instance->adprecovery = MEGASAS_HBA_OPERATIONAL; 2328 instance->adprecovery = MEGASAS_HBA_OPERATIONAL;
2252 } 2329 }
diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.h b/drivers/scsi/megaraid/megaraid_sas_fusion.h
index 82b577a72c8b..088c9f91da95 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.h
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.h
@@ -43,6 +43,15 @@
43#define HOST_DIAG_WRITE_ENABLE 0x80 43#define HOST_DIAG_WRITE_ENABLE 0x80
44#define HOST_DIAG_RESET_ADAPTER 0x4 44#define HOST_DIAG_RESET_ADAPTER 0x4
45#define MEGASAS_FUSION_MAX_RESET_TRIES 3 45#define MEGASAS_FUSION_MAX_RESET_TRIES 3
46#define MAX_MSIX_QUEUES_FUSION 16
47
48/* Invader defines */
49#define MPI2_TYPE_CUDA 0x2
50#define MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH 0x4000
51#define MR_RL_FLAGS_GRANT_DESTINATION_CPU0 0x00
52#define MR_RL_FLAGS_GRANT_DESTINATION_CPU1 0x10
53#define MR_RL_FLAGS_GRANT_DESTINATION_CUDA 0x80
54#define MR_RL_FLAGS_SEQ_NUM_ENABLE 0x8
46 55
47/* T10 PI defines */ 56/* T10 PI defines */
48#define MR_PROT_INFO_TYPE_CONTROLLER 0x8 57#define MR_PROT_INFO_TYPE_CONTROLLER 0x8
@@ -70,7 +79,7 @@ enum MR_RAID_FLAGS_IO_SUB_TYPE {
70 */ 79 */
71#define MEGASAS_REQ_DESCRIPT_FLAGS_LD_IO 0x7 80#define MEGASAS_REQ_DESCRIPT_FLAGS_LD_IO 0x7
72#define MEGASAS_REQ_DESCRIPT_FLAGS_MFA 0x1 81#define MEGASAS_REQ_DESCRIPT_FLAGS_MFA 0x1
73 82#define MEGASAS_REQ_DESCRIPT_FLAGS_NO_LOCK 0x2
74#define MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT 1 83#define MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT 1
75 84
76#define MEGASAS_FP_CMD_LEN 16 85#define MEGASAS_FP_CMD_LEN 16
@@ -82,7 +91,9 @@ enum MR_RAID_FLAGS_IO_SUB_TYPE {
82 */ 91 */
83 92
84struct RAID_CONTEXT { 93struct RAID_CONTEXT {
85 u16 resvd0; 94 u8 Type:4;
95 u8 nseg:4;
96 u8 resvd0;
86 u16 timeoutValue; 97 u16 timeoutValue;
87 u8 regLockFlags; 98 u8 regLockFlags;
88 u8 resvd1; 99 u8 resvd1;
@@ -527,7 +538,7 @@ struct MR_LD_RAID {
527 u8 ldState; 538 u8 ldState;
528 u8 regTypeReqOnWrite; 539 u8 regTypeReqOnWrite;
529 u8 modFactor; 540 u8 modFactor;
530 u8 reserved2[1]; 541 u8 regTypeReqOnRead;
531 u16 seqNum; 542 u16 seqNum;
532 543
533 struct { 544 struct {
@@ -663,7 +674,7 @@ struct fusion_context {
663 union MPI2_REPLY_DESCRIPTORS_UNION *reply_frames_desc; 674 union MPI2_REPLY_DESCRIPTORS_UNION *reply_frames_desc;
664 struct dma_pool *reply_frames_desc_pool; 675 struct dma_pool *reply_frames_desc_pool;
665 676
666 u16 last_reply_idx; 677 u16 last_reply_idx[MAX_MSIX_QUEUES_FUSION];
667 678
668 u32 reply_q_depth; 679 u32 reply_q_depth;
669 u32 request_alloc_sz; 680 u32 request_alloc_sz;