--- /dev/null
+From 49a7a4adb0167b656b8dfb6ccb83220d553a1860 Mon Sep 17 00:00:00 2001
+From: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
+Date: Thu, 19 Oct 2017 02:48:54 -0700
+Subject: scsi: megaraid_sas: Create separate functions to allocate ctrl memory
+
+From: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
+
+commit 49a7a4adb0167b656b8dfb6ccb83220d553a1860 upstream.
+
+No functional change. Code refactoring to improve readability. Move the
+code to allocate and free controller memory into separate functions.
+
+Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
+Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
+Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ drivers/scsi/megaraid/megaraid_sas_base.c | 122 ++++++++++++++++++------------
+ 1 file changed, 76 insertions(+), 46 deletions(-)
+
+--- a/drivers/scsi/megaraid/megaraid_sas_base.c
++++ b/drivers/scsi/megaraid/megaraid_sas_base.c
+@@ -6016,6 +6016,75 @@ static inline void megasas_set_adapter_t
+ }
+ }
+
++static inline int megasas_alloc_mfi_ctrl_mem(struct megasas_instance *instance)
++{
++ instance->producer = pci_alloc_consistent(instance->pdev, sizeof(u32),
++ &instance->producer_h);
++ instance->consumer = pci_alloc_consistent(instance->pdev, sizeof(u32),
++ &instance->consumer_h);
++
++ if (!instance->producer || !instance->consumer) {
++ dev_err(&instance->pdev->dev,
++ "Failed to allocate memory for producer, consumer\n");
++ return -1;
++ }
++
++ *instance->producer = 0;
++ *instance->consumer = 0;
++ return 0;
++}
++
++/**
++ * megasas_alloc_ctrl_mem - Allocate per controller memory for core data
++ * structures which are not common across MFI
++ * adapters and fusion adapters.
++ * For MFI based adapters, allocate producer and
++ * consumer buffers. For fusion adapters, allocate
++ * memory for fusion context.
++ * @instance: Adapter soft state
++ * return: 0 for SUCCESS
++ */
++static int megasas_alloc_ctrl_mem(struct megasas_instance *instance)
++{
++ switch (instance->adapter_type) {
++ case MFI_SERIES:
++ if (megasas_alloc_mfi_ctrl_mem(instance))
++ return -ENOMEM;
++ break;
++ case VENTURA_SERIES:
++ case THUNDERBOLT_SERIES:
++ case INVADER_SERIES:
++ if (megasas_alloc_fusion_context(instance))
++ return -ENOMEM;
++ break;
++ }
++
++ return 0;
++}
++
++/*
++ * megasas_free_ctrl_mem - Free fusion context for fusion adapters and
++ * producer, consumer buffers for MFI adapters
++ *
++ * @instance - Adapter soft instance
++ *
++ */
++static inline void megasas_free_ctrl_mem(struct megasas_instance *instance)
++{
++ if (instance->adapter_type == MFI_SERIES) {
++ if (instance->producer)
++ pci_free_consistent(instance->pdev, sizeof(u32),
++ instance->producer,
++ instance->producer_h);
++ if (instance->consumer)
++ pci_free_consistent(instance->pdev, sizeof(u32),
++ instance->consumer,
++ instance->consumer_h);
++ } else {
++ megasas_free_fusion_context(instance);
++ }
++}
++
+ /**
+ * megasas_probe_one - PCI hotplug entry point
+ * @pdev: PCI device structure
+@@ -6074,33 +6143,8 @@ static int megasas_probe_one(struct pci_
+
+ megasas_set_adapter_type(instance);
+
+- switch (instance->adapter_type) {
+- case MFI_SERIES:
+- instance->producer =
+- pci_alloc_consistent(pdev, sizeof(u32),
+- &instance->producer_h);
+- instance->consumer =
+- pci_alloc_consistent(pdev, sizeof(u32),
+- &instance->consumer_h);
+-
+- if (!instance->producer || !instance->consumer) {
+- dev_printk(KERN_DEBUG, &pdev->dev, "Failed to allocate "
+- "memory for producer, consumer\n");
+- goto fail_alloc_dma_buf;
+- }
+-
+- *instance->producer = 0;
+- *instance->consumer = 0;
+-
+- break;
+- case VENTURA_SERIES:
+- case THUNDERBOLT_SERIES:
+- case INVADER_SERIES:
+- if (megasas_alloc_fusion_context(instance)) {
+- megasas_free_fusion_context(instance);
+- goto fail_alloc_dma_buf;
+- }
+- }
++ if (megasas_alloc_ctrl_mem(instance))
++ goto fail_alloc_dma_buf;
+
+ /* Crash dump feature related initialisation*/
+ instance->drv_buf_index = 0;
+@@ -6296,12 +6340,7 @@ fail_alloc_dma_buf:
+ pci_free_consistent(pdev, sizeof(struct MR_TARGET_PROPERTIES),
+ instance->tgt_prop,
+ instance->tgt_prop_h);
+- if (instance->producer)
+- pci_free_consistent(pdev, sizeof(u32), instance->producer,
+- instance->producer_h);
+- if (instance->consumer)
+- pci_free_consistent(pdev, sizeof(u32), instance->consumer,
+- instance->consumer_h);
++ megasas_free_ctrl_mem(instance);
+ scsi_host_put(host);
+
+ fail_alloc_instance:
+@@ -6572,12 +6611,8 @@ fail_init_mfi:
+ pci_free_consistent(pdev, sizeof(struct MR_TARGET_PROPERTIES),
+ instance->tgt_prop,
+ instance->tgt_prop_h);
+- if (instance->producer)
+- pci_free_consistent(pdev, sizeof(u32), instance->producer,
+- instance->producer_h);
+- if (instance->consumer)
+- pci_free_consistent(pdev, sizeof(u32), instance->consumer,
+- instance->consumer_h);
++
++ megasas_free_ctrl_mem(instance);
+ scsi_host_put(host);
+
+ fail_set_dma_mask:
+@@ -6718,15 +6753,8 @@ skip_firing_dcmds:
+ fusion->pd_seq_sync[i],
+ fusion->pd_seq_phys[i]);
+ }
+- megasas_free_fusion_context(instance);
+ } else {
+ megasas_release_mfi(instance);
+- pci_free_consistent(pdev, sizeof(u32),
+- instance->producer,
+- instance->producer_h);
+- pci_free_consistent(pdev, sizeof(u32),
+- instance->consumer,
+- instance->consumer_h);
+ }
+
+ kfree(instance->ctrl_info);
+@@ -6767,6 +6795,8 @@ skip_firing_dcmds:
+ pci_free_consistent(pdev, sizeof(struct MR_DRV_SYSTEM_INFO),
+ instance->system_info_buf, instance->system_info_h);
+
++ megasas_free_ctrl_mem(instance);
++
+ scsi_host_put(host);
+
+ pci_disable_device(pdev);
--- /dev/null
+From adbe552349f2d1e48357a00e564d26135e586634 Mon Sep 17 00:00:00 2001
+From: Ming Lei <ming.lei@redhat.com>
+Date: Tue, 13 Mar 2018 17:42:40 +0800
+Subject: scsi: megaraid_sas: fix selection of reply queue
+
+From: Ming Lei <ming.lei@redhat.com>
+
+commit adbe552349f2d1e48357a00e564d26135e586634 upstream.
+
+Since commit 84676c1f21e8 ("genirq/affinity: assign vectors to all
+possible CPUs") we could end up with an MSI-X vector that did not have
+any online CPUs mapped. This would lead to I/O hangs since there was no
+CPU to receive the completion.
+
+Retrieve IRQ affinity information using pci_irq_get_affinity() and use
+this mapping to choose a reply queue.
+
+[mkp: tweaked commit desc]
+
+Cc: Hannes Reinecke <hare@suse.de>
+Cc: "Martin K. Petersen" <martin.petersen@oracle.com>,
+Cc: James Bottomley <james.bottomley@hansenpartnership.com>,
+Cc: Christoph Hellwig <hch@lst.de>,
+Cc: Don Brace <don.brace@microsemi.com>
+Cc: Kashyap Desai <kashyap.desai@broadcom.com>
+Cc: Laurence Oberman <loberman@redhat.com>
+Cc: Mike Snitzer <snitzer@redhat.com>
+Cc: Meelis Roos <mroos@linux.ee>
+Cc: Artem Bityutskiy <artem.bityutskiy@intel.com>
+Fixes: 84676c1f21e8 ("genirq/affinity: assign vectors to all possible CPUs")
+Signed-off-by: Ming Lei <ming.lei@redhat.com>
+Acked-by: Kashyap Desai <kashyap.desai@broadcom.com>
+Tested-by: Kashyap Desai <kashyap.desai@broadcom.com>
+Reviewed-by: Christoph Hellwig <hch@lst.de>
+Tested-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
+Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ drivers/scsi/megaraid/megaraid_sas.h | 1
+ drivers/scsi/megaraid/megaraid_sas_base.c | 39 +++++++++++++++++++++++++---
+ drivers/scsi/megaraid/megaraid_sas_fusion.c | 12 ++------
+ 3 files changed, 41 insertions(+), 11 deletions(-)
+
+--- a/drivers/scsi/megaraid/megaraid_sas.h
++++ b/drivers/scsi/megaraid/megaraid_sas.h
+@@ -2099,6 +2099,7 @@ enum MR_PD_TYPE {
+
+ struct megasas_instance {
+
++ unsigned int *reply_map;
+ __le32 *producer;
+ dma_addr_t producer_h;
+ __le32 *consumer;
+--- a/drivers/scsi/megaraid/megaraid_sas_base.c
++++ b/drivers/scsi/megaraid/megaraid_sas_base.c
+@@ -5138,6 +5138,26 @@ skip_alloc:
+ instance->use_seqnum_jbod_fp = false;
+ }
+
++static void megasas_setup_reply_map(struct megasas_instance *instance)
++{
++ const struct cpumask *mask;
++ unsigned int queue, cpu;
++
++ for (queue = 0; queue < instance->msix_vectors; queue++) {
++ mask = pci_irq_get_affinity(instance->pdev, queue);
++ if (!mask)
++ goto fallback;
++
++ for_each_cpu(cpu, mask)
++ instance->reply_map[cpu] = queue;
++ }
++ return;
++
++fallback:
++ for_each_possible_cpu(cpu)
++ instance->reply_map[cpu] = cpu % instance->msix_vectors;
++}
++
+ /**
+ * megasas_init_fw - Initializes the FW
+ * @instance: Adapter soft state
+@@ -5303,6 +5323,8 @@ static int megasas_init_fw(struct megasa
+ goto fail_setup_irqs;
+ }
+
++ megasas_setup_reply_map(instance);
++
+ dev_info(&instance->pdev->dev,
+ "firmware supports msix\t: (%d)", fw_msix_count);
+ dev_info(&instance->pdev->dev,
+@@ -6046,20 +6068,29 @@ static inline int megasas_alloc_mfi_ctrl
+ */
+ static int megasas_alloc_ctrl_mem(struct megasas_instance *instance)
+ {
++ instance->reply_map = kzalloc(sizeof(unsigned int) * nr_cpu_ids,
++ GFP_KERNEL);
++ if (!instance->reply_map)
++ return -ENOMEM;
++
+ switch (instance->adapter_type) {
+ case MFI_SERIES:
+ if (megasas_alloc_mfi_ctrl_mem(instance))
+- return -ENOMEM;
++ goto fail;
+ break;
+ case VENTURA_SERIES:
+ case THUNDERBOLT_SERIES:
+ case INVADER_SERIES:
+ if (megasas_alloc_fusion_context(instance))
+- return -ENOMEM;
++ goto fail;
+ break;
+ }
+
+ return 0;
++ fail:
++ kfree(instance->reply_map);
++ instance->reply_map = NULL;
++ return -ENOMEM;
+ }
+
+ /*
+@@ -6071,6 +6102,7 @@ static int megasas_alloc_ctrl_mem(struct
+ */
+ static inline void megasas_free_ctrl_mem(struct megasas_instance *instance)
+ {
++ kfree(instance->reply_map);
+ if (instance->adapter_type == MFI_SERIES) {
+ if (instance->producer)
+ pci_free_consistent(instance->pdev, sizeof(u32),
+@@ -6342,7 +6374,6 @@ fail_alloc_dma_buf:
+ instance->tgt_prop_h);
+ megasas_free_ctrl_mem(instance);
+ scsi_host_put(host);
+-
+ fail_alloc_instance:
+ fail_set_dma_mask:
+ pci_disable_device(pdev);
+@@ -6548,6 +6579,8 @@ megasas_resume(struct pci_dev *pdev)
+ if (rval < 0)
+ goto fail_reenable_msix;
+
++ megasas_setup_reply_map(instance);
++
+ if (instance->adapter_type != MFI_SERIES) {
+ megasas_reset_reply_desc(instance);
+ if (megasas_ioc_init_fusion(instance)) {
+--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
++++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
+@@ -2341,11 +2341,8 @@ megasas_build_ldio_fusion(struct megasas
+ fp_possible = (io_info.fpOkForIo > 0) ? true : false;
+ }
+
+- /* Use raw_smp_processor_id() for now until cmd->request->cpu is CPU
+- id by default, not CPU group id, otherwise all MSI-X queues won't
+- be utilized */
+- cmd->request_desc->SCSIIO.MSIxIndex = instance->msix_vectors ?
+- raw_smp_processor_id() % instance->msix_vectors : 0;
++ cmd->request_desc->SCSIIO.MSIxIndex =
++ instance->reply_map[raw_smp_processor_id()];
+
+ praid_context = &io_request->RaidContext;
+
+@@ -2667,10 +2664,9 @@ megasas_build_syspd_fusion(struct megasa
+ }
+
+ cmd->request_desc->SCSIIO.DevHandle = io_request->DevHandle;
+- cmd->request_desc->SCSIIO.MSIxIndex =
+- instance->msix_vectors ?
+- (raw_smp_processor_id() % instance->msix_vectors) : 0;
+
++ cmd->request_desc->SCSIIO.MSIxIndex =
++ instance->reply_map[raw_smp_processor_id()];
+
+ if (!fp_possible) {
+ /* system pd firmware path */
--- /dev/null
+From e7d36b88435077847e1ea992919c600f3fa9321c Mon Sep 17 00:00:00 2001
+From: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
+Date: Thu, 19 Oct 2017 02:48:50 -0700
+Subject: scsi: megaraid_sas: replace instance->ctrl_context checks with instance->adapter_type
+
+From: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
+
+commit e7d36b88435077847e1ea992919c600f3fa9321c upstream.
+
+Increase code readability. No functional change.
+
+Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
+Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
+Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ drivers/scsi/megaraid/megaraid_sas_base.c | 64 +++++++++++++++++-------------
+ 1 file changed, 37 insertions(+), 27 deletions(-)
+
+--- a/drivers/scsi/megaraid/megaraid_sas_base.c
++++ b/drivers/scsi/megaraid/megaraid_sas_base.c
+@@ -2023,7 +2023,7 @@ void megaraid_sas_kill_hba(struct megasa
+ msleep(1000);
+ if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0073SKINNY) ||
+ (instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0071SKINNY) ||
+- (instance->ctrl_context)) {
++ (instance->adapter_type != MFI_SERIES)) {
+ writel(MFI_STOP_ADP, &instance->reg_set->doorbell);
+ /* Flush */
+ readl(&instance->reg_set->doorbell);
+@@ -2494,7 +2494,8 @@ int megasas_sriov_start_heartbeat(struct
+ dev_warn(&instance->pdev->dev, "SR-IOV: Starting heartbeat for scsi%d\n",
+ instance->host->host_no);
+
+- if (instance->ctrl_context && !instance->mask_interrupts)
++ if ((instance->adapter_type != MFI_SERIES) &&
++ !instance->mask_interrupts)
+ retval = megasas_issue_blocked_cmd(instance, cmd,
+ MEGASAS_ROUTINE_WAIT_TIME_VF);
+ else
+@@ -2790,7 +2791,9 @@ static int megasas_reset_bus_host(struct
+ /*
+ * First wait for all commands to complete
+ */
+- if (instance->ctrl_context) {
++ if (instance->adapter_type == MFI_SERIES) {
++ ret = megasas_generic_reset(scmd);
++ } else {
+ struct megasas_cmd_fusion *cmd;
+ cmd = (struct megasas_cmd_fusion *)scmd->SCp.ptr;
+ if (cmd)
+@@ -2798,8 +2801,7 @@ static int megasas_reset_bus_host(struct
+ MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE);
+ ret = megasas_reset_fusion(scmd->device->host,
+ SCSIIO_TIMEOUT_OCR);
+- } else
+- ret = megasas_generic_reset(scmd);
++ }
+
+ return ret;
+ }
+@@ -2816,7 +2818,7 @@ static int megasas_task_abort(struct scs
+
+ instance = (struct megasas_instance *)scmd->device->host->hostdata;
+
+- if (instance->ctrl_context)
++ if (instance->adapter_type != MFI_SERIES)
+ ret = megasas_task_abort_fusion(scmd);
+ else {
+ sdev_printk(KERN_NOTICE, scmd->device, "TASK ABORT not supported\n");
+@@ -2838,7 +2840,7 @@ static int megasas_reset_target(struct s
+
+ instance = (struct megasas_instance *)scmd->device->host->hostdata;
+
+- if (instance->ctrl_context)
++ if (instance->adapter_type != MFI_SERIES)
+ ret = megasas_reset_target_fusion(scmd);
+ else {
+ sdev_printk(KERN_NOTICE, scmd->device, "TARGET RESET not supported\n");
+@@ -3715,7 +3717,7 @@ megasas_transition_to_ready(struct megas
+ PCI_DEVICE_ID_LSI_SAS0073SKINNY) ||
+ (instance->pdev->device ==
+ PCI_DEVICE_ID_LSI_SAS0071SKINNY) ||
+- (instance->ctrl_context))
++ (instance->adapter_type != MFI_SERIES))
+ writel(
+ MFI_INIT_CLEAR_HANDSHAKE|MFI_INIT_HOTPLUG,
+ &instance->reg_set->doorbell);
+@@ -3733,7 +3735,7 @@ megasas_transition_to_ready(struct megas
+ PCI_DEVICE_ID_LSI_SAS0073SKINNY) ||
+ (instance->pdev->device ==
+ PCI_DEVICE_ID_LSI_SAS0071SKINNY) ||
+- (instance->ctrl_context))
++ (instance->adapter_type != MFI_SERIES))
+ writel(MFI_INIT_HOTPLUG,
+ &instance->reg_set->doorbell);
+ else
+@@ -3753,11 +3755,11 @@ megasas_transition_to_ready(struct megas
+ PCI_DEVICE_ID_LSI_SAS0073SKINNY) ||
+ (instance->pdev->device ==
+ PCI_DEVICE_ID_LSI_SAS0071SKINNY) ||
+- (instance->ctrl_context)) {
++ (instance->adapter_type != MFI_SERIES)) {
+ writel(MFI_RESET_FLAGS,
+ &instance->reg_set->doorbell);
+
+- if (instance->ctrl_context) {
++ if (instance->adapter_type != MFI_SERIES) {
+ for (i = 0; i < (10 * 1000); i += 20) {
+ if (readl(
+ &instance->
+@@ -3924,7 +3926,8 @@ static int megasas_create_frame_pool(str
+ * max_sge_sz = 12 byte (sizeof megasas_sge64)
+ * Total 192 byte (3 MFI frame of 64 byte)
+ */
+- frame_count = instance->ctrl_context ? (3 + 1) : (15 + 1);
++ frame_count = (instance->adapter_type == MFI_SERIES) ?
++ (15 + 1) : (3 + 1);
+ instance->mfi_frame_size = MEGAMFI_FRAME_SIZE * frame_count;
+ /*
+ * Use DMA pool facility provided by PCI layer
+@@ -3979,7 +3982,7 @@ static int megasas_create_frame_pool(str
+ memset(cmd->frame, 0, instance->mfi_frame_size);
+ cmd->frame->io.context = cpu_to_le32(cmd->index);
+ cmd->frame->io.pad_0 = 0;
+- if (!instance->ctrl_context && reset_devices)
++ if ((instance->adapter_type == MFI_SERIES) && reset_devices)
+ cmd->frame->hdr.cmd = MFI_CMD_INVALID;
+ }
+
+@@ -4099,7 +4102,7 @@ int megasas_alloc_cmds(struct megasas_in
+ inline int
+ dcmd_timeout_ocr_possible(struct megasas_instance *instance) {
+
+- if (!instance->ctrl_context)
++ if (instance->adapter_type == MFI_SERIES)
+ return KILL_ADAPTER;
+ else if (instance->unload ||
+ test_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags))
+@@ -4143,7 +4146,8 @@ megasas_get_pd_info(struct megasas_insta
+ dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(instance->pd_info_h);
+ dcmd->sgl.sge32[0].length = cpu_to_le32(sizeof(struct MR_PD_INFO));
+
+- if (instance->ctrl_context && !instance->mask_interrupts)
++ if ((instance->adapter_type != MFI_SERIES) &&
++ !instance->mask_interrupts)
+ ret = megasas_issue_blocked_cmd(instance, cmd, MFI_IO_TIMEOUT_SECS);
+ else
+ ret = megasas_issue_polled(instance, cmd);
+@@ -4240,7 +4244,8 @@ megasas_get_pd_list(struct megasas_insta
+ dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(ci_h);
+ dcmd->sgl.sge32[0].length = cpu_to_le32(MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST));
+
+- if (instance->ctrl_context && !instance->mask_interrupts)
++ if ((instance->adapter_type != MFI_SERIES) &&
++ !instance->mask_interrupts)
+ ret = megasas_issue_blocked_cmd(instance, cmd,
+ MFI_IO_TIMEOUT_SECS);
+ else
+@@ -4251,7 +4256,7 @@ megasas_get_pd_list(struct megasas_insta
+ dev_info(&instance->pdev->dev, "MR_DCMD_PD_LIST_QUERY "
+ "failed/not supported by firmware\n");
+
+- if (instance->ctrl_context)
++ if (instance->adapter_type != MFI_SERIES)
+ megaraid_sas_kill_hba(instance);
+ else
+ instance->pd_list_not_supported = 1;
+@@ -4372,7 +4377,8 @@ megasas_get_ld_list(struct megasas_insta
+ dcmd->sgl.sge32[0].length = cpu_to_le32(sizeof(struct MR_LD_LIST));
+ dcmd->pad_0 = 0;
+
+- if (instance->ctrl_context && !instance->mask_interrupts)
++ if ((instance->adapter_type != MFI_SERIES) &&
++ !instance->mask_interrupts)
+ ret = megasas_issue_blocked_cmd(instance, cmd,
+ MFI_IO_TIMEOUT_SECS);
+ else
+@@ -4491,7 +4497,8 @@ megasas_ld_list_query(struct megasas_ins
+ dcmd->sgl.sge32[0].length = cpu_to_le32(sizeof(struct MR_LD_TARGETID_LIST));
+ dcmd->pad_0 = 0;
+
+- if (instance->ctrl_context && !instance->mask_interrupts)
++ if ((instance->adapter_type != MFI_SERIES) &&
++ !instance->mask_interrupts)
+ ret = megasas_issue_blocked_cmd(instance, cmd, MFI_IO_TIMEOUT_SECS);
+ else
+ ret = megasas_issue_polled(instance, cmd);
+@@ -4664,7 +4671,8 @@ megasas_get_ctrl_info(struct megasas_ins
+ dcmd->sgl.sge32[0].length = cpu_to_le32(sizeof(struct megasas_ctrl_info));
+ dcmd->mbox.b[0] = 1;
+
+- if (instance->ctrl_context && !instance->mask_interrupts)
++ if ((instance->adapter_type != MFI_SERIES) &&
++ !instance->mask_interrupts)
+ ret = megasas_issue_blocked_cmd(instance, cmd, MFI_IO_TIMEOUT_SECS);
+ else
+ ret = megasas_issue_polled(instance, cmd);
+@@ -4783,7 +4791,8 @@ int megasas_set_crash_dump_params(struct
+ dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(instance->crash_dump_h);
+ dcmd->sgl.sge32[0].length = cpu_to_le32(CRASH_DMA_BUF_SIZE);
+
+- if (instance->ctrl_context && !instance->mask_interrupts)
++ if ((instance->adapter_type != MFI_SERIES) &&
++ !instance->mask_interrupts)
+ ret = megasas_issue_blocked_cmd(instance, cmd, MFI_IO_TIMEOUT_SECS);
+ else
+ ret = megasas_issue_polled(instance, cmd);
+@@ -5170,7 +5179,7 @@ static int megasas_init_fw(struct megasa
+
+ reg_set = instance->reg_set;
+
+- if (fusion)
++ if (instance->adapter_type != MFI_SERIES)
+ instance->instancet = &megasas_instance_template_fusion;
+ else {
+ switch (instance->pdev->device) {
+@@ -5805,7 +5814,8 @@ megasas_get_target_prop(struct megasas_i
+ dcmd->sgl.sge32[0].length =
+ cpu_to_le32(sizeof(struct MR_TARGET_PROPERTIES));
+
+- if (instance->ctrl_context && !instance->mask_interrupts)
++ if ((instance->adapter_type != MFI_SERIES) &&
++ !instance->mask_interrupts)
+ ret = megasas_issue_blocked_cmd(instance,
+ cmd, MFI_IO_TIMEOUT_SECS);
+ else
+@@ -6186,7 +6196,7 @@ static int megasas_probe_one(struct pci_
+ instance->disableOnlineCtrlReset = 1;
+ instance->UnevenSpanSupport = 0;
+
+- if (instance->ctrl_context) {
++ if (instance->adapter_type != MFI_SERIES) {
+ INIT_WORK(&instance->work_init, megasas_fusion_ocr_wq);
+ INIT_WORK(&instance->crash_init, megasas_fusion_crash_dump_wq);
+ } else
+@@ -6266,7 +6276,7 @@ fail_io_attach:
+ instance->instancet->disable_intr(instance);
+ megasas_destroy_irqs(instance);
+
+- if (instance->ctrl_context)
++ if (instance->adapter_type != MFI_SERIES)
+ megasas_release_fusion(instance);
+ else
+ megasas_release_mfi(instance);
+@@ -6500,7 +6510,7 @@ megasas_resume(struct pci_dev *pdev)
+ if (rval < 0)
+ goto fail_reenable_msix;
+
+- if (instance->ctrl_context) {
++ if (instance->adapter_type != MFI_SERIES) {
+ megasas_reset_reply_desc(instance);
+ if (megasas_ioc_init_fusion(instance)) {
+ megasas_free_cmds(instance);
+@@ -6684,7 +6694,7 @@ skip_firing_dcmds:
+ }
+
+
+- if (instance->ctrl_context) {
++ if (instance->adapter_type != MFI_SERIES) {
+ megasas_release_fusion(instance);
+ pd_seq_map_sz = sizeof(struct MR_PD_CFG_SEQ_NUM_SYNC) +
+ (sizeof(struct MR_PD_CFG_SEQ) *
--- /dev/null
+From f369a31578c461a360f58c7695e5aef931bada13 Mon Sep 17 00:00:00 2001
+From: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
+Date: Thu, 19 Oct 2017 02:48:52 -0700
+Subject: scsi: megaraid_sas: replace is_ventura with adapter_type checks
+
+From: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
+
+commit f369a31578c461a360f58c7695e5aef931bada13 upstream.
+
+No functional change.
+
+Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
+Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
+Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ drivers/scsi/megaraid/megaraid_sas.h | 1 -
+ drivers/scsi/megaraid/megaraid_sas_base.c | 9 ++++-----
+ drivers/scsi/megaraid/megaraid_sas_fp.c | 10 +++++-----
+ drivers/scsi/megaraid/megaraid_sas_fusion.c | 24 ++++++++++++------------
+ 4 files changed, 21 insertions(+), 23 deletions(-)
+
+--- a/drivers/scsi/megaraid/megaraid_sas.h
++++ b/drivers/scsi/megaraid/megaraid_sas.h
+@@ -2243,7 +2243,6 @@ struct megasas_instance {
+ bool dev_handle;
+ bool fw_sync_cache_support;
+ u32 mfi_frame_size;
+- bool is_ventura;
+ bool msix_combined;
+ u16 max_raid_mapsize;
+ /* preffered count to send as LDIO irrspective of FP capable.*/
+--- a/drivers/scsi/megaraid/megaraid_sas_base.c
++++ b/drivers/scsi/megaraid/megaraid_sas_base.c
+@@ -5220,7 +5220,7 @@ static int megasas_init_fw(struct megasa
+ goto fail_ready_state;
+ }
+
+- if (instance->is_ventura) {
++ if (instance->adapter_type == VENTURA_SERIES) {
+ scratch_pad_3 =
+ readl(&instance->reg_set->outbound_scratch_pad_3);
+ instance->max_raid_mapsize = ((scratch_pad_3 >>
+@@ -5329,7 +5329,7 @@ static int megasas_init_fw(struct megasa
+ if (instance->instancet->init_adapter(instance))
+ goto fail_init_adapter;
+
+- if (instance->is_ventura) {
++ if (instance->adapter_type == VENTURA_SERIES) {
+ scratch_pad_4 =
+ readl(&instance->reg_set->outbound_scratch_pad_4);
+ if ((scratch_pad_4 & MR_NVME_PAGE_SIZE_MASK) >=
+@@ -5365,7 +5365,7 @@ static int megasas_init_fw(struct megasa
+ memset(instance->ld_ids, 0xff, MEGASAS_MAX_LD_IDS);
+
+ /* stream detection initialization */
+- if (instance->is_ventura && fusion) {
++ if (instance->adapter_type == VENTURA_SERIES) {
+ fusion->stream_detect_by_ld =
+ kzalloc(sizeof(struct LD_STREAM_DETECT *)
+ * MAX_LOGICAL_DRIVES_EXT,
+@@ -6094,7 +6094,6 @@ static int megasas_probe_one(struct pci_
+
+ break;
+ case VENTURA_SERIES:
+- instance->is_ventura = 1;
+ case THUNDERBOLT_SERIES:
+ case INVADER_SERIES:
+ if (megasas_alloc_fusion_context(instance)) {
+@@ -6686,7 +6685,7 @@ skip_firing_dcmds:
+ if (instance->msix_vectors)
+ pci_free_irq_vectors(instance->pdev);
+
+- if (instance->is_ventura) {
++ if (instance->adapter_type == VENTURA_SERIES) {
+ for (i = 0; i < MAX_LOGICAL_DRIVES_EXT; ++i)
+ kfree(fusion->stream_detect_by_ld[i]);
+ kfree(fusion->stream_detect_by_ld);
+--- a/drivers/scsi/megaraid/megaraid_sas_fp.c
++++ b/drivers/scsi/megaraid/megaraid_sas_fp.c
+@@ -745,7 +745,7 @@ static u8 mr_spanset_get_phy_params(stru
+ *pDevHandle = MR_PdDevHandleGet(pd, map);
+ *pPdInterface = MR_PdInterfaceTypeGet(pd, map);
+ /* get second pd also for raid 1/10 fast path writes*/
+- if (instance->is_ventura &&
++ if ((instance->adapter_type == VENTURA_SERIES) &&
+ (raid->level == 1) &&
+ !io_info->isRead) {
+ r1_alt_pd = MR_ArPdGet(arRef, physArm + 1, map);
+@@ -770,7 +770,7 @@ static u8 mr_spanset_get_phy_params(stru
+ }
+
+ *pdBlock += stripRef + le64_to_cpu(MR_LdSpanPtrGet(ld, span, map)->startBlk);
+- if (instance->is_ventura) {
++ if (instance->adapter_type == VENTURA_SERIES) {
+ ((struct RAID_CONTEXT_G35 *)pRAID_Context)->span_arm =
+ (span << RAID_CTX_SPANARM_SPAN_SHIFT) | physArm;
+ io_info->span_arm =
+@@ -861,7 +861,7 @@ u8 MR_GetPhyParams(struct megasas_instan
+ *pDevHandle = MR_PdDevHandleGet(pd, map);
+ *pPdInterface = MR_PdInterfaceTypeGet(pd, map);
+ /* get second pd also for raid 1/10 fast path writes*/
+- if (instance->is_ventura &&
++ if ((instance->adapter_type == VENTURA_SERIES) &&
+ (raid->level == 1) &&
+ !io_info->isRead) {
+ r1_alt_pd = MR_ArPdGet(arRef, physArm + 1, map);
+@@ -888,7 +888,7 @@ u8 MR_GetPhyParams(struct megasas_instan
+ }
+
+ *pdBlock += stripRef + le64_to_cpu(MR_LdSpanPtrGet(ld, span, map)->startBlk);
+- if (instance->is_ventura) {
++ if (instance->adapter_type == VENTURA_SERIES) {
+ ((struct RAID_CONTEXT_G35 *)pRAID_Context)->span_arm =
+ (span << RAID_CTX_SPANARM_SPAN_SHIFT) | physArm;
+ io_info->span_arm =
+@@ -1099,7 +1099,7 @@ MR_BuildRaidContext(struct megasas_insta
+ if (instance->adapter_type == INVADER_SERIES)
+ pRAID_Context->reg_lock_flags = (isRead) ?
+ raid->regTypeReqOnRead : raid->regTypeReqOnWrite;
+- else if (!instance->is_ventura)
++ else if (instance->adapter_type == THUNDERBOLT_SERIES)
+ pRAID_Context->reg_lock_flags = (isRead) ?
+ REGION_TYPE_SHARED_READ : raid->regTypeReqOnWrite;
+ pRAID_Context->virtual_disk_tgt_id = raid->targetId;
+--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
++++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
+@@ -237,7 +237,7 @@ megasas_fusion_update_can_queue(struct m
+ reg_set = instance->reg_set;
+
+ /* ventura FW does not fill outbound_scratch_pad_3 with queue depth */
+- if (!instance->is_ventura)
++ if (instance->adapter_type < VENTURA_SERIES)
+ cur_max_fw_cmds =
+ readl(&instance->reg_set->outbound_scratch_pad_3) & 0x00FFFF;
+
+@@ -285,7 +285,7 @@ megasas_fusion_update_can_queue(struct m
+ instance->host->can_queue = instance->cur_can_queue;
+ }
+
+- if (instance->is_ventura)
++ if (instance->adapter_type == VENTURA_SERIES)
+ instance->max_mpt_cmds =
+ instance->max_fw_cmds * RAID_1_PEER_CMDS;
+ else
+@@ -2349,7 +2349,7 @@ megasas_build_ldio_fusion(struct megasas
+
+ praid_context = &io_request->RaidContext;
+
+- if (instance->is_ventura) {
++ if (instance->adapter_type == VENTURA_SERIES) {
+ spin_lock_irqsave(&instance->stream_lock, spinlock_flags);
+ megasas_stream_detect(instance, cmd, &io_info);
+ spin_unlock_irqrestore(&instance->stream_lock, spinlock_flags);
+@@ -2415,7 +2415,7 @@ megasas_build_ldio_fusion(struct megasas
+ io_request->RaidContext.raid_context.reg_lock_flags |=
+ (MR_RL_FLAGS_GRANT_DESTINATION_CUDA |
+ MR_RL_FLAGS_SEQ_NUM_ENABLE);
+- } else if (instance->is_ventura) {
++ } else if (instance->adapter_type == VENTURA_SERIES) {
+ io_request->RaidContext.raid_context_g35.nseg_type |=
+ (1 << RAID_CONTEXT_NSEG_SHIFT);
+ io_request->RaidContext.raid_context_g35.nseg_type |=
+@@ -2434,7 +2434,7 @@ megasas_build_ldio_fusion(struct megasas
+ &io_info, local_map_ptr);
+ scp->SCp.Status |= MEGASAS_LOAD_BALANCE_FLAG;
+ cmd->pd_r1_lb = io_info.pd_after_lb;
+- if (instance->is_ventura)
++ if (instance->adapter_type == VENTURA_SERIES)
+ io_request->RaidContext.raid_context_g35.span_arm
+ = io_info.span_arm;
+ else
+@@ -2444,7 +2444,7 @@ megasas_build_ldio_fusion(struct megasas
+ } else
+ scp->SCp.Status &= ~MEGASAS_LOAD_BALANCE_FLAG;
+
+- if (instance->is_ventura)
++ if (instance->adapter_type == VENTURA_SERIES)
+ cmd->r1_alt_dev_handle = io_info.r1_alt_dev_handle;
+ else
+ cmd->r1_alt_dev_handle = MR_DEVHANDLE_INVALID;
+@@ -2480,7 +2480,7 @@ megasas_build_ldio_fusion(struct megasas
+ (MR_RL_FLAGS_GRANT_DESTINATION_CPU0 |
+ MR_RL_FLAGS_SEQ_NUM_ENABLE);
+ io_request->RaidContext.raid_context.nseg = 0x1;
+- } else if (instance->is_ventura) {
++ } else if (instance->adapter_type == VENTURA_SERIES) {
+ io_request->RaidContext.raid_context_g35.routing_flags |=
+ (1 << MR_RAID_CTX_ROUTINGFLAGS_SQN_SHIFT);
+ io_request->RaidContext.raid_context_g35.nseg_type |=
+@@ -2555,7 +2555,7 @@ static void megasas_build_ld_nonrw_fusio
+
+ /* set RAID context values */
+ pRAID_Context->config_seq_num = raid->seqNum;
+- if (!instance->is_ventura)
++ if (instance->adapter_type != VENTURA_SERIES)
+ pRAID_Context->reg_lock_flags = REGION_TYPE_SHARED_READ;
+ pRAID_Context->timeout_value =
+ cpu_to_le16(raid->fpIoTimeoutForLd);
+@@ -2640,7 +2640,7 @@ megasas_build_syspd_fusion(struct megasa
+ cpu_to_le16(device_id + (MAX_PHYSICAL_DEVICES - 1));
+ pRAID_Context->config_seq_num = pd_sync->seq[pd_index].seqNum;
+ io_request->DevHandle = pd_sync->seq[pd_index].devHandle;
+- if (instance->is_ventura) {
++ if (instance->adapter_type == VENTURA_SERIES) {
+ io_request->RaidContext.raid_context_g35.routing_flags |=
+ (1 << MR_RAID_CTX_ROUTINGFLAGS_SQN_SHIFT);
+ io_request->RaidContext.raid_context_g35.nseg_type |=
+@@ -2771,7 +2771,7 @@ megasas_build_io_fusion(struct megasas_i
+ return 1;
+ }
+
+- if (instance->is_ventura) {
++ if (instance->adapter_type == VENTURA_SERIES) {
+ set_num_sge(&io_request->RaidContext.raid_context_g35, sge_count);
+ cpu_to_le16s(&io_request->RaidContext.raid_context_g35.routing_flags);
+ cpu_to_le16s(&io_request->RaidContext.raid_context_g35.nseg_type);
+@@ -4233,7 +4233,7 @@ int megasas_reset_fusion(struct Scsi_Hos
+ for (i = 0 ; i < instance->max_scsi_cmds; i++) {
+ cmd_fusion = fusion->cmd_list[i];
+ /*check for extra commands issued by driver*/
+- if (instance->is_ventura) {
++ if (instance->adapter_type == VENTURA_SERIES) {
+ r1_cmd = fusion->cmd_list[i + instance->max_fw_cmds];
+ megasas_return_cmd_fusion(instance, r1_cmd);
+ }
+@@ -4334,7 +4334,7 @@ transition_to_ready:
+ megasas_set_dynamic_target_properties(sdev);
+
+ /* reset stream detection array */
+- if (instance->is_ventura) {
++ if (instance->adapter_type == VENTURA_SERIES) {
+ for (j = 0; j < MAX_LOGICAL_DRIVES_EXT; ++j) {
+ memset(fusion->stream_detect_by_ld[j],
+ 0, sizeof(struct LD_STREAM_DETECT));
--- /dev/null
+From c365178f3147f38d26c15bdf43a363bacb5406ec Mon Sep 17 00:00:00 2001
+From: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
+Date: Thu, 19 Oct 2017 02:48:48 -0700
+Subject: scsi: megaraid_sas: use adapter_type for all gen controllers
+
+From: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
+
+commit c365178f3147f38d26c15bdf43a363bacb5406ec upstream.
+
+No functional change.
+Refactor adapter_type to set for all generation controllers, not
+just for fusion controllers.
+
+Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
+Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
+Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ drivers/scsi/megaraid/megaraid_sas.h | 8 ++
+ drivers/scsi/megaraid/megaraid_sas_base.c | 88 +++++++++++++++++-----------
+ drivers/scsi/megaraid/megaraid_sas_fp.c | 10 +--
+ drivers/scsi/megaraid/megaraid_sas_fusion.c | 18 ++---
+ drivers/scsi/megaraid/megaraid_sas_fusion.h | 7 --
+ 5 files changed, 76 insertions(+), 55 deletions(-)
+
+--- a/drivers/scsi/megaraid/megaraid_sas.h
++++ b/drivers/scsi/megaraid/megaraid_sas.h
+@@ -1504,6 +1504,13 @@ enum FW_BOOT_CONTEXT {
+
+ #define MR_CAN_HANDLE_SYNC_CACHE_OFFSET 0X01000000
+
++enum MR_ADAPTER_TYPE {
++ MFI_SERIES = 1,
++ THUNDERBOLT_SERIES = 2,
++ INVADER_SERIES = 3,
++ VENTURA_SERIES = 4,
++};
++
+ /*
+ * register set for both 1068 and 1078 controllers
+ * structure extended for 1078 registers
+@@ -2242,6 +2249,7 @@ struct megasas_instance {
+ /* preffered count to send as LDIO irrspective of FP capable.*/
+ u8 r1_ldio_hint_default;
+ u32 nvme_page_size;
++ u8 adapter_type;
+ };
+ struct MR_LD_VF_MAP {
+ u32 size;
+--- a/drivers/scsi/megaraid/megaraid_sas_base.c
++++ b/drivers/scsi/megaraid/megaraid_sas_base.c
+@@ -5229,7 +5229,8 @@ static int megasas_init_fw(struct megasa
+ (&instance->reg_set->outbound_scratch_pad_2);
+ /* Check max MSI-X vectors */
+ if (fusion) {
+- if (fusion->adapter_type == THUNDERBOLT_SERIES) { /* Thunderbolt Series*/
++ if (instance->adapter_type == THUNDERBOLT_SERIES) {
++ /* Thunderbolt Series*/
+ instance->msix_vectors = (scratch_pad_2
+ & MR_MAX_REPLY_QUEUES_OFFSET) + 1;
+ fw_msix_count = instance->msix_vectors;
+@@ -5965,6 +5966,46 @@ fail_set_dma_mask:
+ return 1;
+ }
+
++/*
++ * megasas_set_adapter_type - Set adapter type.
++ * Supported controllers can be divided in
++ * 4 categories- enum MR_ADAPTER_TYPE {
++ * MFI_SERIES = 1,
++ * THUNDERBOLT_SERIES = 2,
++ * INVADER_SERIES = 3,
++ * VENTURA_SERIES = 4,
++ * };
++ * @instance: Adapter soft state
++ * return: void
++ */
++static inline void megasas_set_adapter_type(struct megasas_instance *instance)
++{
++ switch (instance->pdev->device) {
++ case PCI_DEVICE_ID_LSI_VENTURA:
++ case PCI_DEVICE_ID_LSI_HARPOON:
++ case PCI_DEVICE_ID_LSI_TOMCAT:
++ case PCI_DEVICE_ID_LSI_VENTURA_4PORT:
++ case PCI_DEVICE_ID_LSI_CRUSADER_4PORT:
++ instance->adapter_type = VENTURA_SERIES;
++ break;
++ case PCI_DEVICE_ID_LSI_FUSION:
++ case PCI_DEVICE_ID_LSI_PLASMA:
++ instance->adapter_type = THUNDERBOLT_SERIES;
++ break;
++ case PCI_DEVICE_ID_LSI_INVADER:
++ case PCI_DEVICE_ID_LSI_INTRUDER:
++ case PCI_DEVICE_ID_LSI_INTRUDER_24:
++ case PCI_DEVICE_ID_LSI_CUTLASS_52:
++ case PCI_DEVICE_ID_LSI_CUTLASS_53:
++ case PCI_DEVICE_ID_LSI_FURY:
++ instance->adapter_type = INVADER_SERIES;
++ break;
++ default: /* For all other supported controllers */
++ instance->adapter_type = MFI_SERIES;
++ break;
++ }
++}
++
+ /**
+ * megasas_probe_one - PCI hotplug entry point
+ * @pdev: PCI device structure
+@@ -5977,7 +6018,6 @@ static int megasas_probe_one(struct pci_
+ struct Scsi_Host *host;
+ struct megasas_instance *instance;
+ u16 control = 0;
+- struct fusion_context *fusion = NULL;
+
+ /* Reset MSI-X in the kdump kernel */
+ if (reset_devices) {
+@@ -6022,39 +6062,10 @@ static int megasas_probe_one(struct pci_
+ atomic_set(&instance->fw_reset_no_pci_access, 0);
+ instance->pdev = pdev;
+
+- switch (instance->pdev->device) {
+- case PCI_DEVICE_ID_LSI_VENTURA:
+- case PCI_DEVICE_ID_LSI_HARPOON:
+- case PCI_DEVICE_ID_LSI_TOMCAT:
+- case PCI_DEVICE_ID_LSI_VENTURA_4PORT:
+- case PCI_DEVICE_ID_LSI_CRUSADER_4PORT:
+- instance->is_ventura = true;
+- case PCI_DEVICE_ID_LSI_FUSION:
+- case PCI_DEVICE_ID_LSI_PLASMA:
+- case PCI_DEVICE_ID_LSI_INVADER:
+- case PCI_DEVICE_ID_LSI_FURY:
+- case PCI_DEVICE_ID_LSI_INTRUDER:
+- case PCI_DEVICE_ID_LSI_INTRUDER_24:
+- case PCI_DEVICE_ID_LSI_CUTLASS_52:
+- case PCI_DEVICE_ID_LSI_CUTLASS_53:
+- {
+- if (megasas_alloc_fusion_context(instance)) {
+- megasas_free_fusion_context(instance);
+- goto fail_alloc_dma_buf;
+- }
+- fusion = instance->ctrl_context;
+-
+- if ((instance->pdev->device == PCI_DEVICE_ID_LSI_FUSION) ||
+- (instance->pdev->device == PCI_DEVICE_ID_LSI_PLASMA))
+- fusion->adapter_type = THUNDERBOLT_SERIES;
+- else if (instance->is_ventura)
+- fusion->adapter_type = VENTURA_SERIES;
+- else
+- fusion->adapter_type = INVADER_SERIES;
+- }
+- break;
+- default: /* For all other supported controllers */
++ megasas_set_adapter_type(instance);
+
++ switch (instance->adapter_type) {
++ case MFI_SERIES:
+ instance->producer =
+ pci_alloc_consistent(pdev, sizeof(u32),
+ &instance->producer_h);
+@@ -6070,7 +6081,16 @@ static int megasas_probe_one(struct pci_
+
+ *instance->producer = 0;
+ *instance->consumer = 0;
++
+ break;
++ case VENTURA_SERIES:
++ instance->is_ventura = 1;
++ case THUNDERBOLT_SERIES:
++ case INVADER_SERIES:
++ if (megasas_alloc_fusion_context(instance)) {
++ megasas_free_fusion_context(instance);
++ goto fail_alloc_dma_buf;
++ }
+ }
+
+ /* Crash dump feature related initialisation*/
+--- a/drivers/scsi/megaraid/megaraid_sas_fp.c
++++ b/drivers/scsi/megaraid/megaraid_sas_fp.c
+@@ -755,8 +755,8 @@ static u8 mr_spanset_get_phy_params(stru
+ }
+ } else {
+ if ((raid->level >= 5) &&
+- ((fusion->adapter_type == THUNDERBOLT_SERIES) ||
+- ((fusion->adapter_type == INVADER_SERIES) &&
++ ((instance->adapter_type == THUNDERBOLT_SERIES) ||
++ ((instance->adapter_type == INVADER_SERIES) &&
+ (raid->regTypeReqOnRead != REGION_TYPE_UNUSED))))
+ pRAID_Context->reg_lock_flags = REGION_TYPE_EXCLUSIVE;
+ else if (raid->level == 1) {
+@@ -871,8 +871,8 @@ u8 MR_GetPhyParams(struct megasas_instan
+ }
+ } else {
+ if ((raid->level >= 5) &&
+- ((fusion->adapter_type == THUNDERBOLT_SERIES) ||
+- ((fusion->adapter_type == INVADER_SERIES) &&
++ ((instance->adapter_type == THUNDERBOLT_SERIES) ||
++ ((instance->adapter_type == INVADER_SERIES) &&
+ (raid->regTypeReqOnRead != REGION_TYPE_UNUSED))))
+ pRAID_Context->reg_lock_flags = REGION_TYPE_EXCLUSIVE;
+ else if (raid->level == 1) {
+@@ -1096,7 +1096,7 @@ MR_BuildRaidContext(struct megasas_insta
+ cpu_to_le16(raid->fpIoTimeoutForLd ?
+ raid->fpIoTimeoutForLd :
+ map->raidMap.fpPdIoTimeoutSec);
+- if (fusion->adapter_type == INVADER_SERIES)
++ if (instance->adapter_type == INVADER_SERIES)
+ pRAID_Context->reg_lock_flags = (isRead) ?
+ raid->regTypeReqOnRead : raid->regTypeReqOnWrite;
+ else if (!instance->is_ventura)
+--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
++++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
+@@ -838,7 +838,7 @@ megasas_ioc_init_fusion(struct megasas_i
+ drv_ops = (MFI_CAPABILITIES *) &(init_frame->driver_operations);
+
+ /* driver support Extended MSIX */
+- if (fusion->adapter_type >= INVADER_SERIES)
++ if (instance->adapter_type >= INVADER_SERIES)
+ drv_ops->mfi_capabilities.support_additional_msix = 1;
+ /* driver supports HA / Remote LUN over Fast Path interface */
+ drv_ops->mfi_capabilities.support_fp_remote_lun = 1;
+@@ -1789,7 +1789,7 @@ megasas_make_sgl_fusion(struct megasas_i
+
+ fusion = instance->ctrl_context;
+
+- if (fusion->adapter_type >= INVADER_SERIES) {
++ if (instance->adapter_type >= INVADER_SERIES) {
+ struct MPI25_IEEE_SGE_CHAIN64 *sgl_ptr_end = sgl_ptr;
+ sgl_ptr_end += fusion->max_sge_in_main_msg - 1;
+ sgl_ptr_end->Flags = 0;
+@@ -1799,7 +1799,7 @@ megasas_make_sgl_fusion(struct megasas_i
+ sgl_ptr->Length = cpu_to_le32(sg_dma_len(os_sgl));
+ sgl_ptr->Address = cpu_to_le64(sg_dma_address(os_sgl));
+ sgl_ptr->Flags = 0;
+- if (fusion->adapter_type >= INVADER_SERIES)
++ if (instance->adapter_type >= INVADER_SERIES)
+ if (i == sge_count - 1)
+ sgl_ptr->Flags = IEEE_SGE_FLAGS_END_OF_LIST;
+ sgl_ptr++;
+@@ -1809,7 +1809,7 @@ megasas_make_sgl_fusion(struct megasas_i
+ (sge_count > fusion->max_sge_in_main_msg)) {
+
+ struct MPI25_IEEE_SGE_CHAIN64 *sg_chain;
+- if (fusion->adapter_type >= INVADER_SERIES) {
++ if (instance->adapter_type >= INVADER_SERIES) {
+ if ((le16_to_cpu(cmd->io_request->IoFlags) &
+ MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH) !=
+ MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH)
+@@ -1825,7 +1825,7 @@ megasas_make_sgl_fusion(struct megasas_i
+ sg_chain = sgl_ptr;
+ /* Prepare chain element */
+ sg_chain->NextChainOffset = 0;
+- if (fusion->adapter_type >= INVADER_SERIES)
++ if (instance->adapter_type >= INVADER_SERIES)
+ sg_chain->Flags = IEEE_SGE_FLAGS_CHAIN_ELEMENT;
+ else
+ sg_chain->Flags =
+@@ -2402,7 +2402,7 @@ megasas_build_ldio_fusion(struct megasas
+ cmd->request_desc->SCSIIO.RequestFlags =
+ (MPI2_REQ_DESCRIPT_FLAGS_FP_IO
+ << MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
+- if (fusion->adapter_type == INVADER_SERIES) {
++ if (instance->adapter_type == INVADER_SERIES) {
+ if (io_request->RaidContext.raid_context.reg_lock_flags ==
+ REGION_TYPE_UNUSED)
+ cmd->request_desc->SCSIIO.RequestFlags =
+@@ -2467,7 +2467,7 @@ megasas_build_ldio_fusion(struct megasas
+ cmd->request_desc->SCSIIO.RequestFlags =
+ (MEGASAS_REQ_DESCRIPT_FLAGS_LD_IO
+ << MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
+- if (fusion->adapter_type == INVADER_SERIES) {
++ if (instance->adapter_type == INVADER_SERIES) {
+ if (io_info.do_fp_rlbypass ||
+ (io_request->RaidContext.raid_context.reg_lock_flags
+ == REGION_TYPE_UNUSED))
+@@ -2688,7 +2688,7 @@ megasas_build_syspd_fusion(struct megasa
+ pRAID_Context->timeout_value =
+ cpu_to_le16((os_timeout_value > timeout_limit) ?
+ timeout_limit : os_timeout_value);
+- if (fusion->adapter_type >= INVADER_SERIES)
++ if (instance->adapter_type >= INVADER_SERIES)
+ io_request->IoFlags |=
+ cpu_to_le16(MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH);
+
+@@ -3301,7 +3301,7 @@ build_mpt_mfi_pass_thru(struct megasas_i
+
+ io_req = cmd->io_request;
+
+- if (fusion->adapter_type >= INVADER_SERIES) {
++ if (instance->adapter_type >= INVADER_SERIES) {
+ struct MPI25_IEEE_SGE_CHAIN64 *sgl_ptr_end =
+ (struct MPI25_IEEE_SGE_CHAIN64 *)&io_req->SGL;
+ sgl_ptr_end += fusion->max_sge_in_main_msg - 1;
+--- a/drivers/scsi/megaraid/megaraid_sas_fusion.h
++++ b/drivers/scsi/megaraid/megaraid_sas_fusion.h
+@@ -104,12 +104,6 @@ enum MR_RAID_FLAGS_IO_SUB_TYPE {
+ #define RAID_1_PEER_CMDS 2
+ #define JBOD_MAPS_COUNT 2
+
+-enum MR_FUSION_ADAPTER_TYPE {
+- THUNDERBOLT_SERIES = 0,
+- INVADER_SERIES = 1,
+- VENTURA_SERIES = 2,
+-};
+-
+ /*
+ * Raid Context structure which describes MegaRAID specific IO Parameters
+ * This resides at offset 0x60 where the SGL normally starts in MPT IO Frames
+@@ -1319,7 +1313,6 @@ struct fusion_context {
+ struct LD_LOAD_BALANCE_INFO *load_balance_info;
+ u32 load_balance_info_pages;
+ LD_SPAN_INFO log_to_span[MAX_LOGICAL_DRIVES_EXT];
+- u8 adapter_type;
+ struct LD_STREAM_DETECT **stream_detect_by_ld;
+ };
+
devpts-resolve-devpts-bind-mounts.patch
fix-up-non-directory-creation-in-sgid-directories.patch
genirq-affinity-assign-vectors-to-all-possible-cpus.patch
+scsi-megaraid_sas-use-adapter_type-for-all-gen-controllers.patch
+scsi-megaraid_sas-replace-instance-ctrl_context-checks-with-instance-adapter_type.patch
+scsi-megaraid_sas-replace-is_ventura-with-adapter_type-checks.patch
+scsi-megaraid_sas-create-separate-functions-to-allocate-ctrl-memory.patch
+scsi-megaraid_sas-fix-selection-of-reply-queue.patch