b37f23
From 88b3ac2949cb535c5213324f33e9745d769f7dad Mon Sep 17 00:00:00 2001
b37f23
From: Sasikumar Chandrasekaran <sasikumar.pc@broadcom.com>
b37f23
Date: Tue, 10 Jan 2017 18:20:48 -0500
b37f23
Subject: [PATCH 06/11] scsi: megaraid_sas: Dynamic Raid Map Changes for SAS3.5
b37f23
 Generic Megaraid Controllers
b37f23
b37f23
SAS3.5 Generic Megaraid Controllers FW will support new dynamic RaidMap to have different
b37f23
sizes for different number of supported VDs.
b37f23
b37f23
Signed-off-by: Sasikumar Chandrasekaran <sasikumar.pc@broadcom.com>
b37f23
Reviewed-by: Tomas Henzl <thenzl@redhat.com>
b37f23
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
b37f23
---
b37f23
 drivers/scsi/megaraid/megaraid_sas.h        |   7 +
b37f23
 drivers/scsi/megaraid/megaraid_sas_base.c   |  60 ++++--
b37f23
 drivers/scsi/megaraid/megaraid_sas_fp.c     | 301 ++++++++++++++++++++++++----
b37f23
 drivers/scsi/megaraid/megaraid_sas_fusion.c | 225 ++++++++++++++++-----
b37f23
 drivers/scsi/megaraid/megaraid_sas_fusion.h | 240 ++++++++++++++++++----
b37f23
 5 files changed, 695 insertions(+), 138 deletions(-)
b37f23
b37f23
diff --git a/drivers/scsi/megaraid/megaraid_sas.h b/drivers/scsi/megaraid/megaraid_sas.h
b37f23
index 0b4d37b..d5205c4 100644
b37f23
--- a/drivers/scsi/megaraid/megaraid_sas.h
b37f23
+++ b/drivers/scsi/megaraid/megaraid_sas.h
b37f23
@@ -1434,6 +1434,12 @@ enum FW_BOOT_CONTEXT {
b37f23
 #define MR_MAX_REPLY_QUEUES_EXT_OFFSET_SHIFT    14
b37f23
 #define MR_MAX_MSIX_REG_ARRAY                   16
b37f23
 #define MR_RDPQ_MODE_OFFSET			0X00800000
b37f23
+
b37f23
+#define MR_MAX_RAID_MAP_SIZE_OFFSET_SHIFT	16
b37f23
+#define MR_MAX_RAID_MAP_SIZE_MASK		0x1FF
b37f23
+#define MR_MIN_MAP_SIZE				0x10000
b37f23
+/* 64k */
b37f23
+
b37f23
 #define MR_CAN_HANDLE_SYNC_CACHE_OFFSET		0X01000000
b37f23
 
b37f23
 /*
b37f23
@@ -2152,6 +2158,7 @@ struct megasas_instance {
b37f23
 	bool fw_sync_cache_support;
b37f23
 	bool is_ventura;
b37f23
 	bool msix_combined;
b37f23
+	u16 max_raid_mapsize;
b37f23
 };
b37f23
 struct MR_LD_VF_MAP {
b37f23
 	u32 size;
b37f23
diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
b37f23
index 0722286..1d8cf03 100644
b37f23
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
b37f23
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
b37f23
@@ -4457,8 +4457,7 @@ megasas_ld_list_query(struct megasas_instance *instance, u8 query_type)
b37f23
 static void megasas_update_ext_vd_details(struct megasas_instance *instance)
b37f23
 {
b37f23
 	struct fusion_context *fusion;
b37f23
-	u32 old_map_sz;
b37f23
-	u32 new_map_sz;
b37f23
+	u32 ventura_map_sz = 0;
b37f23
 
b37f23
 	fusion = instance->ctrl_context;
b37f23
 	/* For MFI based controllers return dummy success */
b37f23
@@ -4488,21 +4487,38 @@ static void megasas_update_ext_vd_details(struct megasas_instance *instance)
b37f23
 		instance->supportmax256vd ? "Extended VD(240 VD)firmware" :
b37f23
 		"Legacy(64 VD) firmware");
b37f23
 
b37f23
-	old_map_sz = sizeof(struct MR_FW_RAID_MAP) +
b37f23
-				(sizeof(struct MR_LD_SPAN_MAP) *
b37f23
-				(instance->fw_supported_vd_count - 1));
b37f23
-	new_map_sz = sizeof(struct MR_FW_RAID_MAP_EXT);
b37f23
-	fusion->drv_map_sz = sizeof(struct MR_DRV_RAID_MAP) +
b37f23
-				(sizeof(struct MR_LD_SPAN_MAP) *
b37f23
-				(instance->drv_supported_vd_count - 1));
b37f23
-
b37f23
-	fusion->max_map_sz = max(old_map_sz, new_map_sz);
b37f23
+	if (instance->max_raid_mapsize) {
b37f23
+		ventura_map_sz = instance->max_raid_mapsize *
b37f23
+						MR_MIN_MAP_SIZE; /* 64k */
b37f23
+		fusion->current_map_sz = ventura_map_sz;
b37f23
+		fusion->max_map_sz = ventura_map_sz;
b37f23
+	} else {
b37f23
+		fusion->old_map_sz =  sizeof(struct MR_FW_RAID_MAP) +
b37f23
+					(sizeof(struct MR_LD_SPAN_MAP) *
b37f23
+					(instance->fw_supported_vd_count - 1));
b37f23
+		fusion->new_map_sz =  sizeof(struct MR_FW_RAID_MAP_EXT);
b37f23
 
b37f23
+		fusion->max_map_sz =
b37f23
+			max(fusion->old_map_sz, fusion->new_map_sz);
b37f23
 
b37f23
-	if (instance->supportmax256vd)
b37f23
-		fusion->current_map_sz = new_map_sz;
b37f23
-	else
b37f23
-		fusion->current_map_sz = old_map_sz;
b37f23
+		if (instance->supportmax256vd)
b37f23
+			fusion->current_map_sz = fusion->new_map_sz;
b37f23
+		else
b37f23
+			fusion->current_map_sz = fusion->old_map_sz;
b37f23
+	}
b37f23
+	/* irrespective of FW raid maps, driver raid map is constant */
b37f23
+	fusion->drv_map_sz = sizeof(struct MR_DRV_RAID_MAP_ALL);
b37f23
+
b37f23
+#if VD_EXT_DEBUG
b37f23
+	dev_info(&instance->pdev->dev, "instance->max_raid_mapsize 0x%x\n ",
b37f23
+		instance->max_raid_mapsize);
b37f23
+	dev_info(&instance->pdev->dev, "new_map_sz = 0x%x, old_map_sz = 0x%x\n",
b37f23
+		fusion->new_map_sz, fusion->old_map_sz);
b37f23
+	dev_info(&instance->pdev->dev, "ventura_map_sz = 0x%x, current_map_sz = 0x%x\n",
b37f23
+		ventura_map_sz, fusion->current_map_sz);
b37f23
+	dev_info(&instance->pdev->dev, "fusion->drv_map_sz =0x%x, size of driver raid map 0x%lx\n",
b37f23
+		fusion->drv_map_sz, sizeof(struct MR_DRV_RAID_MAP_ALL));
b37f23
+#endif
b37f23
 }
b37f23
 
b37f23
 /**
b37f23
@@ -5043,7 +5059,7 @@ static int megasas_init_fw(struct megasas_instance *instance)
b37f23
 {
b37f23
 	u32 max_sectors_1;
b37f23
 	u32 max_sectors_2;
b37f23
-	u32 tmp_sectors, msix_enable, scratch_pad_2;
b37f23
+	u32 tmp_sectors, msix_enable, scratch_pad_2, scratch_pad_3;
b37f23
 	resource_size_t base_addr;
b37f23
 	struct megasas_register_set __iomem *reg_set;
b37f23
 	struct megasas_ctrl_info *ctrl_info = NULL;
b37f23
@@ -5119,7 +5135,17 @@ static int megasas_init_fw(struct megasas_instance *instance)
b37f23
 			goto fail_ready_state;
b37f23
 	}
b37f23
 
b37f23
-
b37f23
+	if (instance->is_ventura) {
b37f23
+		scratch_pad_3 =
b37f23
+			readl(&instance->reg_set->outbound_scratch_pad_3);
b37f23
+#if VD_EXT_DEBUG
b37f23
+		dev_info(&instance->pdev->dev, "scratch_pad3 0x%x\n",
b37f23
+			scratch_pad_3);
b37f23
+#endif
b37f23
+		instance->max_raid_mapsize = ((scratch_pad_3 >>
b37f23
+			MR_MAX_RAID_MAP_SIZE_OFFSET_SHIFT) &
b37f23
+			MR_MAX_RAID_MAP_SIZE_MASK);
b37f23
+	}
b37f23
 
b37f23
 	/* Check if MSI-X is supported while in ready state */
b37f23
 	msix_enable = (instance->instancet->read_fw_status_reg(reg_set) &
b37f23
diff --git a/drivers/scsi/megaraid/megaraid_sas_fp.c b/drivers/scsi/megaraid/megaraid_sas_fp.c
b37f23
index 3644dbc..e45affe 100644
b37f23
--- a/drivers/scsi/megaraid/megaraid_sas_fp.c
b37f23
+++ b/drivers/scsi/megaraid/megaraid_sas_fp.c
b37f23
@@ -179,18 +179,204 @@ void MR_PopulateDrvRaidMap(struct megasas_instance *instance)
b37f23
 	struct fusion_context *fusion = instance->ctrl_context;
b37f23
 	struct MR_FW_RAID_MAP_ALL     *fw_map_old    = NULL;
b37f23
 	struct MR_FW_RAID_MAP         *pFwRaidMap    = NULL;
b37f23
-	int i;
b37f23
+	int i, j;
b37f23
 	u16 ld_count;
b37f23
+	struct MR_FW_RAID_MAP_DYNAMIC *fw_map_dyn;
b37f23
+	struct MR_FW_RAID_MAP_EXT *fw_map_ext;
b37f23
+	struct MR_RAID_MAP_DESC_TABLE *desc_table;
b37f23
 
b37f23
 
b37f23
 	struct MR_DRV_RAID_MAP_ALL *drv_map =
b37f23
 			fusion->ld_drv_map[(instance->map_id & 1)];
b37f23
 	struct MR_DRV_RAID_MAP *pDrvRaidMap = &drv_map->raidMap;
b37f23
+	void *raid_map_data = NULL;
b37f23
+
b37f23
+	memset(drv_map, 0, fusion->drv_map_sz);
b37f23
+	memset(pDrvRaidMap->ldTgtIdToLd,
b37f23
+		0xff, (sizeof(u16) * MAX_LOGICAL_DRIVES_DYN));
b37f23
+
b37f23
+	if (instance->max_raid_mapsize) {
b37f23
+		fw_map_dyn = fusion->ld_map[(instance->map_id & 1)];
b37f23
+#if VD_EXT_DEBUG
b37f23
+		dev_dbg(&instance->pdev->dev, "raidMapSize 0x%x fw_map_dyn->descTableOffset 0x%x\n",
b37f23
+			le32_to_cpu(fw_map_dyn->raid_map_size),
b37f23
+			le32_to_cpu(fw_map_dyn->desc_table_offset));
b37f23
+		dev_dbg(&instance->pdev->dev, "descTableSize 0x%x descTableNumElements 0x%x\n",
b37f23
+			le32_to_cpu(fw_map_dyn->desc_table_size),
b37f23
+			le32_to_cpu(fw_map_dyn->desc_table_num_elements));
b37f23
+		dev_dbg(&instance->pdev->dev, "drv map %p ldCount %d\n",
b37f23
+			drv_map, fw_map_dyn->ld_count);
b37f23
+#endif
b37f23
+		desc_table =
b37f23
+		(struct MR_RAID_MAP_DESC_TABLE *)((void *)fw_map_dyn + le32_to_cpu(fw_map_dyn->desc_table_offset));
b37f23
+		if (desc_table != fw_map_dyn->raid_map_desc_table)
b37f23
+			dev_dbg(&instance->pdev->dev, "offsets of desc table are not matching desc %p original %p\n",
b37f23
+				desc_table, fw_map_dyn->raid_map_desc_table);
b37f23
+
b37f23
+		ld_count = (u16)le16_to_cpu(fw_map_dyn->ld_count);
b37f23
+		pDrvRaidMap->ldCount = (__le16)cpu_to_le16(ld_count);
b37f23
+		pDrvRaidMap->fpPdIoTimeoutSec =
b37f23
+			fw_map_dyn->fp_pd_io_timeout_sec;
b37f23
+		pDrvRaidMap->totalSize = sizeof(struct MR_DRV_RAID_MAP_ALL);
b37f23
+		/* point to actual data starting point*/
b37f23
+		raid_map_data = (void *)fw_map_dyn +
b37f23
+			le32_to_cpu(fw_map_dyn->desc_table_offset) +
b37f23
+			le32_to_cpu(fw_map_dyn->desc_table_size);
b37f23
+
b37f23
+		for (i = 0; i < le32_to_cpu(fw_map_dyn->desc_table_num_elements); ++i) {
b37f23
+
b37f23
+#if VD_EXT_DEBUG
b37f23
+			dev_dbg(&instance->pdev->dev, "desc table %p\n",
b37f23
+				desc_table);
b37f23
+			dev_dbg(&instance->pdev->dev, "raidmap type %d, raidmapOffset 0x%x\n",
b37f23
+				desc_table->raid_map_desc_type,
b37f23
+				desc_table->raid_map_desc_offset);
b37f23
+			dev_dbg(&instance->pdev->dev, "raid map number of elements 0%x, raidmapsize 0x%x\n",
b37f23
+				desc_table->raid_map_desc_elements,
b37f23
+				desc_table->raid_map_desc_buffer_size);
b37f23
+#endif
b37f23
+			switch (le32_to_cpu(desc_table->raid_map_desc_type)) {
b37f23
+			case RAID_MAP_DESC_TYPE_DEVHDL_INFO:
b37f23
+				fw_map_dyn->dev_hndl_info =
b37f23
+				(struct MR_DEV_HANDLE_INFO *)(raid_map_data + le32_to_cpu(desc_table->raid_map_desc_offset));
b37f23
+#if VD_EXT_DEBUG
b37f23
+				dev_dbg(&instance->pdev->dev, "devHndlInfo  address %p\n",
b37f23
+					fw_map_dyn->dev_hndl_info);
b37f23
+#endif
b37f23
+				memcpy(pDrvRaidMap->devHndlInfo,
b37f23
+				fw_map_dyn->dev_hndl_info,
b37f23
+				sizeof(struct MR_DEV_HANDLE_INFO) *
b37f23
+				le32_to_cpu(desc_table->raid_map_desc_elements));
b37f23
+			break;
b37f23
+			case RAID_MAP_DESC_TYPE_TGTID_INFO:
b37f23
+				fw_map_dyn->ld_tgt_id_to_ld =
b37f23
+				(u16 *) (raid_map_data +
b37f23
+				le32_to_cpu(desc_table->raid_map_desc_offset));
b37f23
+#if VD_EXT_DEBUG
b37f23
+			dev_dbg(&instance->pdev->dev, "ldTgtIdToLd  address %p\n",
b37f23
+				fw_map_dyn->ld_tgt_id_to_ld);
b37f23
+#endif
b37f23
+			for (j = 0; j < le32_to_cpu(desc_table->raid_map_desc_elements); j++) {
b37f23
+				pDrvRaidMap->ldTgtIdToLd[j] =
b37f23
+				fw_map_dyn->ld_tgt_id_to_ld[j];
b37f23
+#if VD_EXT_DEBUG
b37f23
+				dev_dbg(&instance->pdev->dev, " %d drv ldTgtIdToLd %d\n",
b37f23
+					j, pDrvRaidMap->ldTgtIdToLd[j]);
b37f23
+#endif
b37f23
+			}
b37f23
+			break;
b37f23
+			case RAID_MAP_DESC_TYPE_ARRAY_INFO:
b37f23
+				fw_map_dyn->ar_map_info =
b37f23
+				(struct MR_ARRAY_INFO *)
b37f23
+				(raid_map_data + le32_to_cpu(desc_table->raid_map_desc_offset));
b37f23
+#if VD_EXT_DEBUG
b37f23
+				dev_dbg(&instance->pdev->dev, "arMapInfo  address %p\n",
b37f23
+					fw_map_dyn->ar_map_info);
b37f23
+#endif
b37f23
+
b37f23
+				memcpy(pDrvRaidMap->arMapInfo,
b37f23
+				fw_map_dyn->ar_map_info,
b37f23
+				sizeof(struct MR_ARRAY_INFO) * le32_to_cpu(desc_table->raid_map_desc_elements));
b37f23
+			break;
b37f23
+			case RAID_MAP_DESC_TYPE_SPAN_INFO:
b37f23
+				fw_map_dyn->ld_span_map =
b37f23
+				(struct MR_LD_SPAN_MAP *)
b37f23
+				(raid_map_data + le32_to_cpu(desc_table->raid_map_desc_offset));
b37f23
+				memcpy(pDrvRaidMap->ldSpanMap,
b37f23
+				fw_map_dyn->ld_span_map,
b37f23
+				sizeof(struct MR_LD_SPAN_MAP) * le32_to_cpu(desc_table->raid_map_desc_elements));
b37f23
+#if VD_EXT_DEBUG
b37f23
+				dev_dbg(&instance->pdev->dev, "ldSpanMap  address %p\n",
b37f23
+					fw_map_dyn->ld_span_map);
b37f23
+				dev_dbg(&instance->pdev->dev, "MR_LD_SPAN_MAP size 0x%lx\n",
b37f23
+					sizeof(struct MR_LD_SPAN_MAP));
b37f23
+				for (j = 0; j < ld_count; j++) {
b37f23
+					dev_dbg(&instance->pdev->dev, "megaraid_sas(%d) : fw_map_dyn->ldSpanMap[%d].ldRaid.targetId 0x%x\n",
b37f23
+					j, j, fw_map_dyn->ld_span_map[j].ldRaid.targetId);
b37f23
+					dev_dbg(&instance->pdev->dev, "fw_map_dyn->ldSpanMap[%d].ldRaid.seqNum 0x%x\n",
b37f23
+					j, fw_map_dyn->ld_span_map[j].ldRaid.seqNum);
b37f23
+					dev_dbg(&instance->pdev->dev, "fw_map_dyn->ld_span_map[%d].ldRaid.rowSize 0x%x\n",
b37f23
+					j, (u32)fw_map_dyn->ld_span_map[j].ldRaid.rowSize);
b37f23
+
b37f23
+					dev_dbg(&instance->pdev->dev, "megaraid_sas(%d) :pDrvRaidMap->ldSpanMap[%d].ldRaid.targetId 0x%x\n",
b37f23
+					j, j, pDrvRaidMap->ldSpanMap[j].ldRaid.targetId);
b37f23
+					dev_dbg(&instance->pdev->dev, "DrvRaidMap->ldSpanMap[%d].ldRaid.seqNum 0x%x\n",
b37f23
+					j, pDrvRaidMap->ldSpanMap[j].ldRaid.seqNum);
b37f23
+					dev_dbg(&instance->pdev->dev, "pDrvRaidMap->ldSpanMap[%d].ldRaid.rowSize 0x%x\n",
b37f23
+					j, (u32)pDrvRaidMap->ldSpanMap[j].ldRaid.rowSize);
b37f23
+
b37f23
+					dev_dbg(&instance->pdev->dev, "megaraid_sas(%d) : drv raid map all %p\n",
b37f23
+					instance->unique_id, drv_map);
b37f23
+					dev_dbg(&instance->pdev->dev, "raid map %p LD RAID MAP %p/%p\n",
b37f23
+					pDrvRaidMap,
b37f23
+					&fw_map_dyn->ld_span_map[j].ldRaid,
b37f23
+					&pDrvRaidMap->ldSpanMap[j].ldRaid);
b37f23
+				}
b37f23
+#endif
b37f23
+			break;
b37f23
+			default:
b37f23
+				dev_dbg(&instance->pdev->dev, "wrong number of desctableElements %d\n",
b37f23
+					fw_map_dyn->desc_table_num_elements);
b37f23
+			}
b37f23
+			++desc_table;
b37f23
+		}
b37f23
+
b37f23
+	} else if (instance->supportmax256vd) {
b37f23
+		fw_map_ext =
b37f23
+		(struct MR_FW_RAID_MAP_EXT *) fusion->ld_map[(instance->map_id & 1)];
b37f23
+		ld_count = (u16)le16_to_cpu(fw_map_ext->ldCount);
b37f23
+		if (ld_count > MAX_LOGICAL_DRIVES_EXT) {
b37f23
+			dev_dbg(&instance->pdev->dev, "megaraid_sas: LD count exposed in RAID map in not valid\n");
b37f23
+			return;
b37f23
+		}
b37f23
+#if VD_EXT_DEBUG
b37f23
+		for (i = 0; i < ld_count; i++) {
b37f23
+			dev_dbg(&instance->pdev->dev, "megaraid_sas(%d) :Index 0x%x\n",
b37f23
+				instance->unique_id, i);
b37f23
+			dev_dbg(&instance->pdev->dev, "Target Id 0x%x\n",
b37f23
+				fw_map_ext->ldSpanMap[i].ldRaid.targetId);
b37f23
+			dev_dbg(&instance->pdev->dev, "Seq Num 0x%x Size 0/%llx\n",
b37f23
+				fw_map_ext->ldSpanMap[i].ldRaid.seqNum,
b37f23
+				fw_map_ext->ldSpanMap[i].ldRaid.size);
b37f23
+		}
b37f23
+#endif
b37f23
+
b37f23
+		pDrvRaidMap->ldCount = (__le16)cpu_to_le16(ld_count);
b37f23
+		pDrvRaidMap->fpPdIoTimeoutSec = fw_map_ext->fpPdIoTimeoutSec;
b37f23
+		for (i = 0; i < (MAX_LOGICAL_DRIVES_EXT); i++)
b37f23
+			pDrvRaidMap->ldTgtIdToLd[i] =
b37f23
+				(u16)fw_map_ext->ldTgtIdToLd[i];
b37f23
+		memcpy(pDrvRaidMap->ldSpanMap, fw_map_ext->ldSpanMap,
b37f23
+				sizeof(struct MR_LD_SPAN_MAP) * ld_count);
b37f23
+#if VD_EXT_DEBUG
b37f23
+		for (i = 0; i < ld_count; i++) {
b37f23
+			dev_dbg(&instance->pdev->dev, "megaraid_sas(%d) : fw_map_ext->ldSpanMap[%d].ldRaid.targetId 0x%x\n",
b37f23
+			i, i, fw_map_ext->ldSpanMap[i].ldRaid.targetId);
b37f23
+			dev_dbg(&instance->pdev->dev, "fw_map_ext->ldSpanMap[%d].ldRaid.seqNum 0x%x\n",
b37f23
+			i, fw_map_ext->ldSpanMap[i].ldRaid.seqNum);
b37f23
+			dev_dbg(&instance->pdev->dev, "fw_map_ext->ldSpanMap[%d].ldRaid.rowSize 0x%x\n",
b37f23
+			i, (u32)fw_map_ext->ldSpanMap[i].ldRaid.rowSize);
b37f23
+
b37f23
+			dev_dbg(&instance->pdev->dev, "megaraid_sas(%d) : pDrvRaidMap->ldSpanMap[%d].ldRaid.targetId 0x%x\n",
b37f23
+			i, i, pDrvRaidMap->ldSpanMap[i].ldRaid.targetId);
b37f23
+			dev_dbg(&instance->pdev->dev, "pDrvRaidMap->ldSpanMap[%d].ldRaid.seqNum 0x%x\n",
b37f23
+			i, pDrvRaidMap->ldSpanMap[i].ldRaid.seqNum);
b37f23
+			dev_dbg(&instance->pdev->dev, "pDrvRaidMap->ldSpanMap[%d].ldRaid.rowSize 0x%x\n",
b37f23
+			i, (u32)pDrvRaidMap->ldSpanMap[i].ldRaid.rowSize);
b37f23
+
b37f23
+			dev_dbg(&instance->pdev->dev, "megaraid_sas(%d) : drv raid map all %p\n",
b37f23
+			instance->unique_id, drv_map);
b37f23
+			dev_dbg(&instance->pdev->dev, "raid map %p LD RAID MAP %p %p\n",
b37f23
+			pDrvRaidMap, &fw_map_ext->ldSpanMap[i].ldRaid,
b37f23
+			&pDrvRaidMap->ldSpanMap[i].ldRaid);
b37f23
+		}
b37f23
+#endif
b37f23
+		memcpy(pDrvRaidMap->arMapInfo, fw_map_ext->arMapInfo,
b37f23
+			sizeof(struct MR_ARRAY_INFO) * MAX_API_ARRAYS_EXT);
b37f23
+		memcpy(pDrvRaidMap->devHndlInfo, fw_map_ext->devHndlInfo,
b37f23
+			sizeof(struct MR_DEV_HANDLE_INFO) *
b37f23
+					MAX_RAIDMAP_PHYSICAL_DEVICES);
b37f23
 
b37f23
-	if (instance->supportmax256vd) {
b37f23
-		memcpy(fusion->ld_drv_map[instance->map_id & 1],
b37f23
-			fusion->ld_map[instance->map_id & 1],
b37f23
-			fusion->current_map_sz);
b37f23
 		/* New Raid map will not set totalSize, so keep expected value
b37f23
 		 * for legacy code in ValidateMapInfo
b37f23
 		 */
b37f23
@@ -213,16 +399,12 @@ void MR_PopulateDrvRaidMap(struct megasas_instance *instance)
b37f23
 		}
b37f23
 #endif
b37f23
 
b37f23
-		memset(drv_map, 0, fusion->drv_map_sz);
b37f23
 		pDrvRaidMap->totalSize = pFwRaidMap->totalSize;
b37f23
 		pDrvRaidMap->ldCount = (__le16)cpu_to_le16(ld_count);
b37f23
 		pDrvRaidMap->fpPdIoTimeoutSec = pFwRaidMap->fpPdIoTimeoutSec;
b37f23
 		for (i = 0; i < MAX_RAIDMAP_LOGICAL_DRIVES + MAX_RAIDMAP_VIEWS; i++)
b37f23
 			pDrvRaidMap->ldTgtIdToLd[i] =
b37f23
 				(u8)pFwRaidMap->ldTgtIdToLd[i];
b37f23
-		for (i = (MAX_RAIDMAP_LOGICAL_DRIVES + MAX_RAIDMAP_VIEWS);
b37f23
-			i < MAX_LOGICAL_DRIVES_EXT; i++)
b37f23
-			pDrvRaidMap->ldTgtIdToLd[i] = 0xff;
b37f23
 		for (i = 0; i < ld_count; i++) {
b37f23
 			pDrvRaidMap->ldSpanMap[i] = pFwRaidMap->ldSpanMap[i];
b37f23
 #if VD_EXT_DEBUG
b37f23
@@ -279,7 +461,9 @@ u8 MR_ValidateMapInfo(struct megasas_instance *instance)
b37f23
 	lbInfo = fusion->load_balance_info;
b37f23
 	ldSpanInfo = fusion->log_to_span;
b37f23
 
b37f23
-	if (instance->supportmax256vd)
b37f23
+	if (instance->max_raid_mapsize)
b37f23
+		expected_size = sizeof(struct MR_DRV_RAID_MAP_ALL);
b37f23
+	else if (instance->supportmax256vd)
b37f23
 		expected_size = sizeof(struct MR_FW_RAID_MAP_EXT);
b37f23
 	else
b37f23
 		expected_size =
b37f23
@@ -287,8 +471,10 @@ u8 MR_ValidateMapInfo(struct megasas_instance *instance)
b37f23
 			(sizeof(struct MR_LD_SPAN_MAP) * le16_to_cpu(pDrvRaidMap->ldCount)));
b37f23
 
b37f23
 	if (le32_to_cpu(pDrvRaidMap->totalSize) != expected_size) {
b37f23
-		dev_err(&instance->pdev->dev, "map info structure size 0x%x is not matching with ld count\n",
b37f23
-		       (unsigned int) expected_size);
b37f23
+		dev_dbg(&instance->pdev->dev, "megasas: map info structure size 0x%x",
b37f23
+			le32_to_cpu(pDrvRaidMap->totalSize));
b37f23
+		dev_dbg(&instance->pdev->dev, "is not matching expected size 0x%x\n",
b37f23
+			(unsigned int) expected_size);
b37f23
 		dev_err(&instance->pdev->dev, "megasas: span map %x, pDrvRaidMap->totalSize : %x\n",
b37f23
 			(unsigned int)sizeof(struct MR_LD_SPAN_MAP),
b37f23
 			le32_to_cpu(pDrvRaidMap->totalSize));
b37f23
@@ -787,7 +973,7 @@ static u8 mr_spanset_get_phy_params(struct megasas_instance *instance, u32 ld,
b37f23
 			((fusion->adapter_type == THUNDERBOLT_SERIES)  ||
b37f23
 			((fusion->adapter_type == INVADER_SERIES) &&
b37f23
 			(raid->regTypeReqOnRead != REGION_TYPE_UNUSED))))
b37f23
-			pRAID_Context->regLockFlags = REGION_TYPE_EXCLUSIVE;
b37f23
+			pRAID_Context->reg_lock_flags = REGION_TYPE_EXCLUSIVE;
b37f23
 		else if (raid->level == 1) {
b37f23
 			pd = MR_ArPdGet(arRef, physArm + 1, map);
b37f23
 			if (pd != MR_PD_INVALID)
b37f23
@@ -796,9 +982,16 @@ static u8 mr_spanset_get_phy_params(struct megasas_instance *instance, u32 ld,
b37f23
 	}
b37f23
 
b37f23
 	*pdBlock += stripRef + le64_to_cpu(MR_LdSpanPtrGet(ld, span, map)->startBlk);
b37f23
-	pRAID_Context->spanArm = (span << RAID_CTX_SPANARM_SPAN_SHIFT) |
b37f23
-					physArm;
b37f23
-	io_info->span_arm = pRAID_Context->spanArm;
b37f23
+	if (instance->is_ventura) {
b37f23
+		((struct RAID_CONTEXT_G35 *) pRAID_Context)->span_arm =
b37f23
+			(span << RAID_CTX_SPANARM_SPAN_SHIFT) | physArm;
b37f23
+		io_info->span_arm =
b37f23
+			(span << RAID_CTX_SPANARM_SPAN_SHIFT) | physArm;
b37f23
+	} else {
b37f23
+		pRAID_Context->span_arm =
b37f23
+			(span << RAID_CTX_SPANARM_SPAN_SHIFT) | physArm;
b37f23
+		io_info->span_arm = pRAID_Context->span_arm;
b37f23
+	}
b37f23
 	return retval;
b37f23
 }
b37f23
 
b37f23
@@ -890,7 +1083,7 @@ u8 MR_GetPhyParams(struct megasas_instance *instance, u32 ld, u64 stripRow,
b37f23
 			((fusion->adapter_type == THUNDERBOLT_SERIES)  ||
b37f23
 			((fusion->adapter_type == INVADER_SERIES) &&
b37f23
 			(raid->regTypeReqOnRead != REGION_TYPE_UNUSED))))
b37f23
-			pRAID_Context->regLockFlags = REGION_TYPE_EXCLUSIVE;
b37f23
+			pRAID_Context->reg_lock_flags = REGION_TYPE_EXCLUSIVE;
b37f23
 		else if (raid->level == 1) {
b37f23
 			/* Get alternate Pd. */
b37f23
 			pd = MR_ArPdGet(arRef, physArm + 1, map);
b37f23
@@ -901,9 +1094,16 @@ u8 MR_GetPhyParams(struct megasas_instance *instance, u32 ld, u64 stripRow,
b37f23
 	}
b37f23
 
b37f23
 	*pdBlock += stripRef + le64_to_cpu(MR_LdSpanPtrGet(ld, span, map)->startBlk);
b37f23
-	pRAID_Context->spanArm = (span << RAID_CTX_SPANARM_SPAN_SHIFT) |
b37f23
-		physArm;
b37f23
-	io_info->span_arm = pRAID_Context->spanArm;
b37f23
+	if (instance->is_ventura) {
b37f23
+		((struct RAID_CONTEXT_G35 *) pRAID_Context)->span_arm =
b37f23
+				(span << RAID_CTX_SPANARM_SPAN_SHIFT) | physArm;
b37f23
+		io_info->span_arm =
b37f23
+				(span << RAID_CTX_SPANARM_SPAN_SHIFT) | physArm;
b37f23
+	} else {
b37f23
+		pRAID_Context->span_arm =
b37f23
+			(span << RAID_CTX_SPANARM_SPAN_SHIFT) | physArm;
b37f23
+		io_info->span_arm = pRAID_Context->span_arm;
b37f23
+	}
b37f23
 	return retval;
b37f23
 }
b37f23
 
b37f23
@@ -1107,20 +1307,20 @@ MR_BuildRaidContext(struct megasas_instance *instance,
b37f23
 			regSize += stripSize;
b37f23
 	}
b37f23
 
b37f23
-	pRAID_Context->timeoutValue =
b37f23
+	pRAID_Context->timeout_value =
b37f23
 		cpu_to_le16(raid->fpIoTimeoutForLd ?
b37f23
 			    raid->fpIoTimeoutForLd :
b37f23
 			    map->raidMap.fpPdIoTimeoutSec);
b37f23
 	if (fusion->adapter_type == INVADER_SERIES)
b37f23
-		pRAID_Context->regLockFlags = (isRead) ?
b37f23
+		pRAID_Context->reg_lock_flags = (isRead) ?
b37f23
 			raid->regTypeReqOnRead : raid->regTypeReqOnWrite;
b37f23
-	else
b37f23
-		pRAID_Context->regLockFlags = (isRead) ?
b37f23
+	else if (!instance->is_ventura)
b37f23
+		pRAID_Context->reg_lock_flags = (isRead) ?
b37f23
 			REGION_TYPE_SHARED_READ : raid->regTypeReqOnWrite;
b37f23
-	pRAID_Context->VirtualDiskTgtId = raid->targetId;
b37f23
-	pRAID_Context->regLockRowLBA    = cpu_to_le64(regStart);
b37f23
-	pRAID_Context->regLockLength    = cpu_to_le32(regSize);
b37f23
-	pRAID_Context->configSeqNum	= raid->seqNum;
b37f23
+	pRAID_Context->virtual_disk_tgt_id = raid->targetId;
b37f23
+	pRAID_Context->reg_lock_row_lba    = cpu_to_le64(regStart);
b37f23
+	pRAID_Context->reg_lock_length    = cpu_to_le32(regSize);
b37f23
+	pRAID_Context->config_seq_num	= raid->seqNum;
b37f23
 	/* save pointer to raid->LUN array */
b37f23
 	*raidLUN = raid->LUN;
b37f23
 
b37f23
@@ -1138,6 +1338,13 @@ MR_BuildRaidContext(struct megasas_instance *instance,
b37f23
 		/* If IO on an invalid Pd, then FP is not possible.*/
b37f23
 		if (io_info->devHandle == cpu_to_le16(MR_PD_INVALID))
b37f23
 			io_info->fpOkForIo = FALSE;
b37f23
+		/* if FP possible, set the SLUD bit in
b37f23
+		 *  regLockFlags for ventura
b37f23
+		 */
b37f23
+		else if ((instance->is_ventura) && (!isRead) &&
b37f23
+			(raid->writeMode == MR_RL_WRITE_BACK_MODE) &&
b37f23
+			(raid->capability.fp_cache_bypass_capable))
b37f23
+			((struct RAID_CONTEXT_G35 *) pRAID_Context)->routing_flags.bits.sld = 1;
b37f23
 		/* set raid 1/10 fast path write capable bit in io_info */
b37f23
 		if (io_info->fpOkForIo &&
b37f23
 		    (io_info->r1_alt_dev_handle != MR_PD_INVALID) &&
b37f23
@@ -1317,6 +1524,7 @@ u8 megasas_get_best_arm_pd(struct megasas_instance *instance,
b37f23
 	struct fusion_context *fusion;
b37f23
 	struct MR_LD_RAID  *raid;
b37f23
 	struct MR_DRV_RAID_MAP_ALL *drv_map;
b37f23
+	u16	pd1_dev_handle;
b37f23
 	u16     pend0, pend1, ld;
b37f23
 	u64     diff0, diff1;
b37f23
 	u8      bestArm, pd0, pd1, span, arm;
b37f23
@@ -1342,23 +1550,36 @@ u8 megasas_get_best_arm_pd(struct megasas_instance *instance,
b37f23
 	pd1 = MR_ArPdGet(arRef, (arm + 1) >= span_row_size ?
b37f23
 		(arm + 1 - span_row_size) : arm + 1, drv_map);
b37f23
 
b37f23
-	/* get the pending cmds for the data and mirror arms */
b37f23
-	pend0 = atomic_read(&lbInfo->scsi_pending_cmds[pd0]);
b37f23
-	pend1 = atomic_read(&lbInfo->scsi_pending_cmds[pd1]);
b37f23
+	/* Get PD1 Dev Handle */
b37f23
+
b37f23
+	pd1_dev_handle = MR_PdDevHandleGet(pd1, drv_map);
b37f23
+
b37f23
+	if (pd1_dev_handle == MR_PD_INVALID) {
b37f23
+		bestArm = arm;
b37f23
+	} else {
b37f23
+		/* get the pending cmds for the data and mirror arms */
b37f23
+		pend0 = atomic_read(&lbInfo->scsi_pending_cmds[pd0]);
b37f23
+		pend1 = atomic_read(&lbInfo->scsi_pending_cmds[pd1]);
b37f23
 
b37f23
-	/* Determine the disk whose head is nearer to the req. block */
b37f23
-	diff0 = ABS_DIFF(block, lbInfo->last_accessed_block[pd0]);
b37f23
-	diff1 = ABS_DIFF(block, lbInfo->last_accessed_block[pd1]);
b37f23
-	bestArm = (diff0 <= diff1 ? arm : arm ^ 1);
b37f23
+		/* Determine the disk whose head is nearer to the req. block */
b37f23
+		diff0 = ABS_DIFF(block, lbInfo->last_accessed_block[pd0]);
b37f23
+		diff1 = ABS_DIFF(block, lbInfo->last_accessed_block[pd1]);
b37f23
+		bestArm = (diff0 <= diff1 ? arm : arm ^ 1);
b37f23
 
b37f23
-	if ((bestArm == arm && pend0 > pend1 + lb_pending_cmds)  ||
b37f23
+		/* Make balance count from 16 to 4 to
b37f23
+		 *  keep driver in sync with Firmware
b37f23
+		 */
b37f23
+		if ((bestArm == arm && pend0 > pend1 + lb_pending_cmds)  ||
b37f23
 			(bestArm != arm && pend1 > pend0 + lb_pending_cmds))
b37f23
-		bestArm ^= 1;
b37f23
+			bestArm ^= 1;
b37f23
+
b37f23
+		/* Update the last accessed block on the correct pd */
b37f23
+		io_info->span_arm =
b37f23
+			(span << RAID_CTX_SPANARM_SPAN_SHIFT) | bestArm;
b37f23
+		io_info->pd_after_lb = (bestArm == arm) ? pd0 : pd1;
b37f23
+	}
b37f23
 
b37f23
-	/* Update the last accessed block on the correct pd */
b37f23
-	io_info->pd_after_lb = (bestArm == arm) ? pd0 : pd1;
b37f23
 	lbInfo->last_accessed_block[io_info->pd_after_lb] = block + count - 1;
b37f23
-	io_info->span_arm = (span << RAID_CTX_SPANARM_SPAN_SHIFT) | bestArm;
b37f23
 #if SPAN_DEBUG
b37f23
 	if (arm != bestArm)
b37f23
 		dev_dbg(&instance->pdev->dev, "LSI Debug R1 Load balance "
b37f23
diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c
b37f23
index b146cd1..178f166 100644
b37f23
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
b37f23
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
b37f23
@@ -1829,7 +1829,7 @@ megasas_build_ldio_fusion(struct megasas_instance *instance,
b37f23
 			  struct megasas_cmd_fusion *cmd)
b37f23
 {
b37f23
 	u8 fp_possible;
b37f23
-	u32 start_lba_lo, start_lba_hi, device_id, datalength = 0;
b37f23
+	u32 start_lba_lo, start_lba_hi, device_id, datalength = 0, ld;
b37f23
 	struct MPI2_RAID_SCSI_IO_REQUEST *io_request;
b37f23
 	union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc;
b37f23
 	struct IO_REQUEST_INFO io_info;
b37f23
@@ -1837,16 +1837,18 @@ megasas_build_ldio_fusion(struct megasas_instance *instance,
b37f23
 	struct MR_DRV_RAID_MAP_ALL *local_map_ptr;
b37f23
 	u8 *raidLUN;
b37f23
 	unsigned long spinlock_flags;
b37f23
+	union RAID_CONTEXT_UNION *praid_context;
b37f23
+	struct MR_LD_RAID *raid;
b37f23
 
b37f23
 	device_id = MEGASAS_DEV_INDEX(scp);
b37f23
 
b37f23
 	fusion = instance->ctrl_context;
b37f23
 
b37f23
 	io_request = cmd->io_request;
b37f23
-	io_request->RaidContext.raid_context.VirtualDiskTgtId =
b37f23
+	io_request->RaidContext.raid_context.virtual_disk_tgt_id =
b37f23
 		cpu_to_le16(device_id);
b37f23
 	io_request->RaidContext.raid_context.status = 0;
b37f23
-	io_request->RaidContext.raid_context.exStatus = 0;
b37f23
+	io_request->RaidContext.raid_context.ex_status = 0;
b37f23
 
b37f23
 	req_desc = (union MEGASAS_REQUEST_DESCRIPTOR_UNION *)cmd->request_desc;
b37f23
 
b37f23
@@ -1915,10 +1917,12 @@ megasas_build_ldio_fusion(struct megasas_instance *instance,
b37f23
 		io_info.isRead = 1;
b37f23
 
b37f23
 	local_map_ptr = fusion->ld_drv_map[(instance->map_id & 1)];
b37f23
+	ld = MR_TargetIdToLdGet(device_id, local_map_ptr);
b37f23
+	raid = MR_LdRaidGet(ld, local_map_ptr);
b37f23
 
b37f23
 	if ((MR_TargetIdToLdGet(device_id, local_map_ptr) >=
b37f23
 		instance->fw_supported_vd_count) || (!fusion->fast_path_io)) {
b37f23
-		io_request->RaidContext.raid_context.regLockFlags  = 0;
b37f23
+		io_request->RaidContext.raid_context.reg_lock_flags  = 0;
b37f23
 		fp_possible = 0;
b37f23
 	} else {
b37f23
 		if (MR_BuildRaidContext(instance, &io_info,
b37f23
@@ -1945,6 +1949,8 @@ megasas_build_ldio_fusion(struct megasas_instance *instance,
b37f23
 			fp_possible = false;
b37f23
 	}
b37f23
 
b37f23
+	praid_context = &io_request->RaidContext;
b37f23
+
b37f23
 	if (fp_possible) {
b37f23
 		megasas_set_pd_lba(io_request, scp->cmd_len, &io_info, scp,
b37f23
 				   local_map_ptr, start_lba_lo);
b37f23
@@ -1953,18 +1959,25 @@ megasas_build_ldio_fusion(struct megasas_instance *instance,
b37f23
 			(MPI2_REQ_DESCRIPT_FLAGS_FP_IO
b37f23
 			 << MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
b37f23
 		if (fusion->adapter_type == INVADER_SERIES) {
b37f23
-			if (io_request->RaidContext.raid_context.regLockFlags ==
b37f23
+			if (io_request->RaidContext.raid_context.reg_lock_flags ==
b37f23
 			    REGION_TYPE_UNUSED)
b37f23
 				cmd->request_desc->SCSIIO.RequestFlags =
b37f23
 					(MEGASAS_REQ_DESCRIPT_FLAGS_NO_LOCK <<
b37f23
 					MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
b37f23
-			io_request->RaidContext.raid_context.Type
b37f23
+			io_request->RaidContext.raid_context.type
b37f23
 				= MPI2_TYPE_CUDA;
b37f23
 			io_request->RaidContext.raid_context.nseg = 0x1;
b37f23
 			io_request->IoFlags |= cpu_to_le16(MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH);
b37f23
-			io_request->RaidContext.raid_context.regLockFlags |=
b37f23
+			io_request->RaidContext.raid_context.reg_lock_flags |=
b37f23
 			  (MR_RL_FLAGS_GRANT_DESTINATION_CUDA |
b37f23
 			   MR_RL_FLAGS_SEQ_NUM_ENABLE);
b37f23
+		} else if (instance->is_ventura) {
b37f23
+			io_request->RaidContext.raid_context_g35.type
b37f23
+				= MPI2_TYPE_CUDA;
b37f23
+			io_request->RaidContext.raid_context_g35.nseg = 0x1;
b37f23
+			io_request->RaidContext.raid_context_g35.routing_flags.bits.sqn = 1;
b37f23
+			io_request->IoFlags |=
b37f23
+			cpu_to_le16(MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH);
b37f23
 		}
b37f23
 		if ((fusion->load_balance_info[device_id].loadBalanceFlag) &&
b37f23
 		    (io_info.isRead)) {
b37f23
@@ -1974,6 +1987,13 @@ megasas_build_ldio_fusion(struct megasas_instance *instance,
b37f23
 					&io_info);
b37f23
 			scp->SCp.Status |= MEGASAS_LOAD_BALANCE_FLAG;
b37f23
 			cmd->pd_r1_lb = io_info.pd_after_lb;
b37f23
+			if (instance->is_ventura)
b37f23
+				io_request->RaidContext.raid_context_g35.span_arm
b37f23
+					= io_info.span_arm;
b37f23
+			else
b37f23
+				io_request->RaidContext.raid_context.span_arm
b37f23
+					= io_info.span_arm;
b37f23
+
b37f23
 		} else
b37f23
 			scp->SCp.Status &= ~MEGASAS_LOAD_BALANCE_FLAG;
b37f23
 
b37f23
@@ -1992,28 +2012,98 @@ megasas_build_ldio_fusion(struct megasas_instance *instance,
b37f23
 		io_request->DevHandle = io_info.devHandle;
b37f23
 		/* populate the LUN field */
b37f23
 		memcpy(io_request->LUN, raidLUN, 8);
b37f23
+		if (instance->is_ventura) {
b37f23
+			if (io_info.isRead) {
b37f23
+				if ((raid->cpuAffinity.pdRead.cpu0) &&
b37f23
+					(raid->cpuAffinity.pdRead.cpu1))
b37f23
+					praid_context->raid_context_g35.routing_flags.bits.cpu_sel
b37f23
+					= MR_RAID_CTX_CPUSEL_FCFS;
b37f23
+				else if (raid->cpuAffinity.pdRead.cpu1)
b37f23
+					praid_context->raid_context_g35.routing_flags.bits.cpu_sel
b37f23
+					= MR_RAID_CTX_CPUSEL_1;
b37f23
+				else
b37f23
+					praid_context->raid_context_g35.routing_flags.bits.cpu_sel
b37f23
+					= MR_RAID_CTX_CPUSEL_0;
b37f23
+			} else {
b37f23
+			if ((raid->cpuAffinity.pdWrite.cpu0)
b37f23
+			&& (raid->cpuAffinity.pdWrite.cpu1))
b37f23
+				praid_context->raid_context_g35.routing_flags.bits.cpu_sel
b37f23
+					= MR_RAID_CTX_CPUSEL_FCFS;
b37f23
+				else if (raid->cpuAffinity.pdWrite.cpu1)
b37f23
+					praid_context->raid_context_g35.routing_flags.bits.cpu_sel
b37f23
+					= MR_RAID_CTX_CPUSEL_1;
b37f23
+				else
b37f23
+					praid_context->raid_context_g35.routing_flags.bits.cpu_sel
b37f23
+					= MR_RAID_CTX_CPUSEL_0;
b37f23
+				if (praid_context->raid_context_g35.routing_flags.bits.sld) {
b37f23
+					praid_context->raid_context_g35.raid_flags
b37f23
+					= (MR_RAID_FLAGS_IO_SUB_TYPE_CACHE_BYPASS
b37f23
+					<< MR_RAID_CTX_RAID_FLAGS_IO_SUB_TYPE_SHIFT);
b37f23
+				}
b37f23
+			}
b37f23
+		}
b37f23
 	} else {
b37f23
-		io_request->RaidContext.raid_context.timeoutValue =
b37f23
+		io_request->RaidContext.raid_context.timeout_value =
b37f23
 			cpu_to_le16(local_map_ptr->raidMap.fpPdIoTimeoutSec);
b37f23
 		cmd->request_desc->SCSIIO.RequestFlags =
b37f23
 			(MEGASAS_REQ_DESCRIPT_FLAGS_LD_IO
b37f23
 			 << MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
b37f23
 		if (fusion->adapter_type == INVADER_SERIES) {
b37f23
 			if (io_info.do_fp_rlbypass ||
b37f23
-			(io_request->RaidContext.raid_context.regLockFlags
b37f23
+			(io_request->RaidContext.raid_context.reg_lock_flags
b37f23
 					== REGION_TYPE_UNUSED))
b37f23
 				cmd->request_desc->SCSIIO.RequestFlags =
b37f23
 					(MEGASAS_REQ_DESCRIPT_FLAGS_NO_LOCK <<
b37f23
 					MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
b37f23
-			io_request->RaidContext.raid_context.Type
b37f23
+			io_request->RaidContext.raid_context.type
b37f23
 				= MPI2_TYPE_CUDA;
b37f23
-			io_request->RaidContext.raid_context.regLockFlags |=
b37f23
+			io_request->RaidContext.raid_context.reg_lock_flags |=
b37f23
 				(MR_RL_FLAGS_GRANT_DESTINATION_CPU0 |
b37f23
 				 MR_RL_FLAGS_SEQ_NUM_ENABLE);
b37f23
 			io_request->RaidContext.raid_context.nseg = 0x1;
b37f23
+		} else if (instance->is_ventura) {
b37f23
+			io_request->RaidContext.raid_context_g35.type
b37f23
+				= MPI2_TYPE_CUDA;
b37f23
+			io_request->RaidContext.raid_context_g35.routing_flags.bits.sqn = 1;
b37f23
+			io_request->RaidContext.raid_context_g35.nseg = 0x1;
b37f23
 		}
b37f23
 		io_request->Function = MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST;
b37f23
 		io_request->DevHandle = cpu_to_le16(device_id);
b37f23
+
b37f23
+		if (instance->is_ventura) {
b37f23
+			if (io_info.isRead) {
b37f23
+				if ((raid->cpuAffinity.ldRead.cpu0)
b37f23
+				&& (raid->cpuAffinity.ldRead.cpu1))
b37f23
+					praid_context->raid_context_g35.routing_flags.bits.cpu_sel
b37f23
+					= MR_RAID_CTX_CPUSEL_FCFS;
b37f23
+				else if (raid->cpuAffinity.ldRead.cpu1)
b37f23
+					praid_context->raid_context_g35.routing_flags.bits.cpu_sel
b37f23
+						= MR_RAID_CTX_CPUSEL_1;
b37f23
+				else
b37f23
+					praid_context->raid_context_g35.routing_flags.bits.cpu_sel
b37f23
+						= MR_RAID_CTX_CPUSEL_0;
b37f23
+			} else {
b37f23
+				if ((raid->cpuAffinity.ldWrite.cpu0) &&
b37f23
+					(raid->cpuAffinity.ldWrite.cpu1))
b37f23
+					praid_context->raid_context_g35.routing_flags.bits.cpu_sel
b37f23
+						= MR_RAID_CTX_CPUSEL_FCFS;
b37f23
+				else if (raid->cpuAffinity.ldWrite.cpu1)
b37f23
+					praid_context->raid_context_g35.routing_flags.bits.cpu_sel
b37f23
+						= MR_RAID_CTX_CPUSEL_1;
b37f23
+				else
b37f23
+					praid_context->raid_context_g35.routing_flags.bits.cpu_sel
b37f23
+					= MR_RAID_CTX_CPUSEL_0;
b37f23
+
b37f23
+				if (io_request->RaidContext.raid_context_g35.stream_detected
b37f23
+					&& (raid->level == 5) &&
b37f23
+					(raid->writeMode == MR_RL_WRITE_THROUGH_MODE)) {
b37f23
+					if (praid_context->raid_context_g35.routing_flags.bits.cpu_sel
b37f23
+						== MR_RAID_CTX_CPUSEL_FCFS)
b37f23
+						praid_context->raid_context_g35.routing_flags.bits.cpu_sel
b37f23
+							= MR_RAID_CTX_CPUSEL_0;
b37f23
+				}
b37f23
+			}
b37f23
+		}
b37f23
 	} /* Not FP */
b37f23
 }
b37f23
 
b37f23
@@ -2048,9 +2138,9 @@ static void megasas_build_ld_nonrw_fusion(struct megasas_instance *instance,
b37f23
 	/* get RAID_Context pointer */
b37f23
 	pRAID_Context = &io_request->RaidContext.raid_context;
b37f23
 	/* Check with FW team */
b37f23
-	pRAID_Context->VirtualDiskTgtId = cpu_to_le16(device_id);
b37f23
-	pRAID_Context->regLockRowLBA    = 0;
b37f23
-	pRAID_Context->regLockLength    = 0;
b37f23
+	pRAID_Context->virtual_disk_tgt_id = cpu_to_le16(device_id);
b37f23
+	pRAID_Context->reg_lock_row_lba    = 0;
b37f23
+	pRAID_Context->reg_lock_length    = 0;
b37f23
 
b37f23
 	if (fusion->fast_path_io && (
b37f23
 		device_id < instance->fw_supported_vd_count)) {
b37f23
@@ -2069,7 +2159,7 @@ static void megasas_build_ld_nonrw_fusion(struct megasas_instance *instance,
b37f23
 		io_request->Function  = MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST;
b37f23
 		io_request->DevHandle = cpu_to_le16(device_id);
b37f23
 		io_request->LUN[1] = scmd->device->lun;
b37f23
-		pRAID_Context->timeoutValue =
b37f23
+		pRAID_Context->timeout_value =
b37f23
 			cpu_to_le16 (scmd->request->timeout / HZ);
b37f23
 		cmd->request_desc->SCSIIO.RequestFlags =
b37f23
 			(MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO <<
b37f23
@@ -2077,9 +2167,11 @@ static void megasas_build_ld_nonrw_fusion(struct megasas_instance *instance,
b37f23
 	} else {
b37f23
 
b37f23
 		/* set RAID context values */
b37f23
-		pRAID_Context->configSeqNum = raid->seqNum;
b37f23
-		pRAID_Context->regLockFlags = REGION_TYPE_SHARED_READ;
b37f23
-		pRAID_Context->timeoutValue = cpu_to_le16(raid->fpIoTimeoutForLd);
b37f23
+		pRAID_Context->config_seq_num = raid->seqNum;
b37f23
+		if (!instance->is_ventura)
b37f23
+			pRAID_Context->reg_lock_flags = REGION_TYPE_SHARED_READ;
b37f23
+		pRAID_Context->timeout_value =
b37f23
+			cpu_to_le16(raid->fpIoTimeoutForLd);
b37f23
 
b37f23
 		/* get the DevHandle for the PD (since this is
b37f23
 		   fpNonRWCapable, this is a single disk RAID0) */
b37f23
@@ -2134,12 +2226,12 @@ megasas_build_syspd_fusion(struct megasas_instance *instance,
b37f23
 	io_request = cmd->io_request;
b37f23
 	/* get RAID_Context pointer */
b37f23
 	pRAID_Context = &io_request->RaidContext.raid_context;
b37f23
-	pRAID_Context->regLockFlags = 0;
b37f23
-	pRAID_Context->regLockRowLBA = 0;
b37f23
-	pRAID_Context->regLockLength = 0;
b37f23
+	pRAID_Context->reg_lock_flags = 0;
b37f23
+	pRAID_Context->reg_lock_row_lba = 0;
b37f23
+	pRAID_Context->reg_lock_length = 0;
b37f23
 	io_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
b37f23
 	io_request->LUN[1] = scmd->device->lun;
b37f23
-	pRAID_Context->RAIDFlags = MR_RAID_FLAGS_IO_SUB_TYPE_SYSTEM_PD
b37f23
+	pRAID_Context->raid_flags = MR_RAID_FLAGS_IO_SUB_TYPE_SYSTEM_PD
b37f23
 		<< MR_RAID_CTX_RAID_FLAGS_IO_SUB_TYPE_SHIFT;
b37f23
 
b37f23
 	/* If FW supports PD sequence number */
b37f23
@@ -2148,24 +2240,27 @@ megasas_build_syspd_fusion(struct megasas_instance *instance,
b37f23
 		/* TgtId must be incremented by 255 as jbod seq number is index
b37f23
 		 * below raid map
b37f23
 		 */
b37f23
-		pRAID_Context->VirtualDiskTgtId =
b37f23
+		pRAID_Context->virtual_disk_tgt_id =
b37f23
 			cpu_to_le16(device_id + (MAX_PHYSICAL_DEVICES - 1));
b37f23
-		pRAID_Context->configSeqNum = pd_sync->seq[pd_index].seqNum;
b37f23
+		pRAID_Context->config_seq_num = pd_sync->seq[pd_index].seqNum;
b37f23
 		io_request->DevHandle = pd_sync->seq[pd_index].devHandle;
b37f23
-		pRAID_Context->regLockFlags |=
b37f23
+		if (instance->is_ventura)
b37f23
+			io_request->RaidContext.raid_context_g35.routing_flags.bits.sqn = 1;
b37f23
+		else
b37f23
+		pRAID_Context->reg_lock_flags |=
b37f23
 			(MR_RL_FLAGS_SEQ_NUM_ENABLE|MR_RL_FLAGS_GRANT_DESTINATION_CUDA);
b37f23
-		pRAID_Context->Type = MPI2_TYPE_CUDA;
b37f23
+		pRAID_Context->type = MPI2_TYPE_CUDA;
b37f23
 		pRAID_Context->nseg = 0x1;
b37f23
 	} else if (fusion->fast_path_io) {
b37f23
-		pRAID_Context->VirtualDiskTgtId = cpu_to_le16(device_id);
b37f23
-		pRAID_Context->configSeqNum = 0;
b37f23
+		pRAID_Context->virtual_disk_tgt_id = cpu_to_le16(device_id);
b37f23
+		pRAID_Context->config_seq_num = 0;
b37f23
 		local_map_ptr = fusion->ld_drv_map[(instance->map_id & 1)];
b37f23
 		io_request->DevHandle =
b37f23
 			local_map_ptr->raidMap.devHndlInfo[device_id].curDevHdl;
b37f23
 	} else {
b37f23
 		/* Want to send all IO via FW path */
b37f23
-		pRAID_Context->VirtualDiskTgtId = cpu_to_le16(device_id);
b37f23
-		pRAID_Context->configSeqNum = 0;
b37f23
+		pRAID_Context->virtual_disk_tgt_id = cpu_to_le16(device_id);
b37f23
+		pRAID_Context->config_seq_num = 0;
b37f23
 		io_request->DevHandle = cpu_to_le16(0xFFFF);
b37f23
 	}
b37f23
 
b37f23
@@ -2181,14 +2276,14 @@ megasas_build_syspd_fusion(struct megasas_instance *instance,
b37f23
 		cmd->request_desc->SCSIIO.RequestFlags =
b37f23
 			(MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO <<
b37f23
 				MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
b37f23
-		pRAID_Context->timeoutValue = cpu_to_le16(os_timeout_value);
b37f23
-		pRAID_Context->VirtualDiskTgtId = cpu_to_le16(device_id);
b37f23
+		pRAID_Context->timeout_value = cpu_to_le16(os_timeout_value);
b37f23
+		pRAID_Context->virtual_disk_tgt_id = cpu_to_le16(device_id);
b37f23
 	} else {
b37f23
 		/* system pd Fast Path */
b37f23
 		io_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
b37f23
 		timeout_limit = (scmd->device->type == TYPE_DISK) ?
b37f23
 				255 : 0xFFFF;
b37f23
-		pRAID_Context->timeoutValue =
b37f23
+		pRAID_Context->timeout_value =
b37f23
 			cpu_to_le16((os_timeout_value > timeout_limit) ?
b37f23
 			timeout_limit : os_timeout_value);
b37f23
 		if (fusion->adapter_type == INVADER_SERIES)
b37f23
@@ -2227,8 +2322,8 @@ megasas_build_io_fusion(struct megasas_instance *instance,
b37f23
 	io_request->Control = 0;
b37f23
 	io_request->EEDPBlockSize = 0;
b37f23
 	io_request->ChainOffset = 0;
b37f23
-	io_request->RaidContext.raid_context.RAIDFlags = 0;
b37f23
-	io_request->RaidContext.raid_context.Type = 0;
b37f23
+	io_request->RaidContext.raid_context.raid_flags = 0;
b37f23
+	io_request->RaidContext.raid_context.type = 0;
b37f23
 	io_request->RaidContext.raid_context.nseg = 0;
b37f23
 
b37f23
 	memcpy(io_request->CDB.CDB32, scp->cmnd, scp->cmd_len);
b37f23
@@ -2273,11 +2368,16 @@ megasas_build_io_fusion(struct megasas_instance *instance,
b37f23
 		return 1;
b37f23
 	}
b37f23
 
b37f23
-	/* numSGE store lower 8 bit of sge_count.
b37f23
-	 * numSGEExt store higher 8 bit of sge_count
b37f23
-	 */
b37f23
-	io_request->RaidContext.raid_context.numSGE = sge_count;
b37f23
-	io_request->RaidContext.raid_context.numSGEExt = (u8)(sge_count >> 8);
b37f23
+	if (instance->is_ventura)
b37f23
+		io_request->RaidContext.raid_context_g35.num_sge = sge_count;
b37f23
+	else {
b37f23
+		/* numSGE store lower 8 bit of sge_count.
b37f23
+		 * numSGEExt store higher 8 bit of sge_count
b37f23
+		 */
b37f23
+		io_request->RaidContext.raid_context.num_sge = sge_count;
b37f23
+		io_request->RaidContext.raid_context.num_sge_ext =
b37f23
+			(u8)(sge_count >> 8);
b37f23
+	}
b37f23
 
b37f23
 	io_request->SGLFlags = cpu_to_le16(MPI2_SGE_FLAGS_64_BIT_ADDRESSING);
b37f23
 
b37f23
@@ -2326,6 +2426,10 @@ void megasas_fpio_to_ldio(struct megasas_instance *instance,
b37f23
 	struct megasas_cmd_fusion *cmd, struct scsi_cmnd *scmd)
b37f23
 {
b37f23
 	struct fusion_context *fusion;
b37f23
+	union RAID_CONTEXT_UNION *praid_context;
b37f23
+	struct MR_LD_RAID *raid;
b37f23
+	struct MR_DRV_RAID_MAP_ALL *local_map_ptr;
b37f23
+	u32 device_id, ld;
b37f23
 
b37f23
 	fusion = instance->ctrl_context;
b37f23
 	cmd->request_desc->SCSIIO.RequestFlags =
b37f23
@@ -2349,6 +2453,35 @@ void megasas_fpio_to_ldio(struct megasas_instance *instance,
b37f23
 	cmd->io_request->Control = 0;
b37f23
 	cmd->io_request->EEDPBlockSize = 0;
b37f23
 	cmd->is_raid_1_fp_write = 0;
b37f23
+
b37f23
+	device_id = MEGASAS_DEV_INDEX(cmd->scmd);
b37f23
+	local_map_ptr = fusion->ld_drv_map[(instance->map_id & 1)];
b37f23
+	ld = MR_TargetIdToLdGet(device_id, local_map_ptr);
b37f23
+	raid = MR_LdRaidGet(ld, local_map_ptr);
b37f23
+	praid_context = &cmd->io_request->RaidContext;
b37f23
+	if (cmd->scmd->sc_data_direction == PCI_DMA_FROMDEVICE) {
b37f23
+		if ((raid->cpuAffinity.ldRead.cpu0)
b37f23
+		&& (raid->cpuAffinity.ldRead.cpu1))
b37f23
+			praid_context->raid_context_g35.routing_flags.bits.cpu_sel
b37f23
+			= MR_RAID_CTX_CPUSEL_FCFS;
b37f23
+		else if (raid->cpuAffinity.ldRead.cpu1)
b37f23
+			praid_context->raid_context_g35.routing_flags.bits.cpu_sel
b37f23
+			= MR_RAID_CTX_CPUSEL_1;
b37f23
+		else
b37f23
+			praid_context->raid_context_g35.routing_flags.bits.cpu_sel
b37f23
+			= MR_RAID_CTX_CPUSEL_0;
b37f23
+	} else {
b37f23
+	if ((raid->cpuAffinity.ldWrite.cpu0)
b37f23
+		&& (raid->cpuAffinity.ldWrite.cpu1))
b37f23
+		praid_context->raid_context_g35.routing_flags.bits.cpu_sel
b37f23
+			= MR_RAID_CTX_CPUSEL_FCFS;
b37f23
+	else if (raid->cpuAffinity.ldWrite.cpu1)
b37f23
+		praid_context->raid_context_g35.routing_flags.bits.cpu_sel
b37f23
+			= MR_RAID_CTX_CPUSEL_1;
b37f23
+	else
b37f23
+		praid_context->raid_context_g35.routing_flags.bits.cpu_sel
b37f23
+		= MR_RAID_CTX_CPUSEL_0;
b37f23
+	}
b37f23
 }
b37f23
 
b37f23
 /* megasas_prepate_secondRaid1_IO
b37f23
@@ -2585,7 +2718,7 @@ complete_cmd_fusion(struct megasas_instance *instance, u32 MSIxIndex)
b37f23
 
b37f23
 		scmd_local = cmd_fusion->scmd;
b37f23
 		status = scsi_io_req->RaidContext.raid_context.status;
b37f23
-		extStatus = scsi_io_req->RaidContext.raid_context.exStatus;
b37f23
+		extStatus = scsi_io_req->RaidContext.raid_context.ex_status;
b37f23
 		sense = cmd_fusion->sense;
b37f23
 		data_length = scsi_io_req->DataLength;
b37f23
 
b37f23
@@ -2653,13 +2786,13 @@ complete_cmd_fusion(struct megasas_instance *instance, u32 MSIxIndex)
b37f23
 					status =
b37f23
 					r1_cmd->io_request->RaidContext.raid_context.status;
b37f23
 					extStatus =
b37f23
-					r1_cmd->io_request->RaidContext.raid_context.exStatus;
b37f23
+					r1_cmd->io_request->RaidContext.raid_context.ex_status;
b37f23
 					data_length =
b37f23
 						r1_cmd->io_request->DataLength;
b37f23
 					sense = r1_cmd->sense;
b37f23
 				}
b37f23
 				r1_cmd->io_request->RaidContext.raid_context.status = 0;
b37f23
-				r1_cmd->io_request->RaidContext.raid_context.exStatus = 0;
b37f23
+				r1_cmd->io_request->RaidContext.raid_context.ex_status = 0;
b37f23
 				cmd_fusion->is_raid_1_fp_write = 0;
b37f23
 				r1_cmd->is_raid_1_fp_write = 0;
b37f23
 				r1_cmd->cmd_completed = false;
b37f23
@@ -2669,10 +2802,8 @@ complete_cmd_fusion(struct megasas_instance *instance, u32 MSIxIndex)
b37f23
 			if (!cmd_fusion->is_raid_1_fp_write) {
b37f23
 				map_cmd_status(fusion, scmd_local, status,
b37f23
 					extStatus, data_length, sense);
b37f23
-				scsi_io_req->RaidContext.raid_context.status
b37f23
-				= 0;
b37f23
-				scsi_io_req->RaidContext.raid_context.exStatus
b37f23
-				= 0;
b37f23
+				scsi_io_req->RaidContext.raid_context.status = 0;
b37f23
+				scsi_io_req->RaidContext.raid_context.ex_status = 0;
b37f23
 				megasas_return_cmd_fusion(instance, cmd_fusion);
b37f23
 				scsi_dma_unmap(scmd_local);
b37f23
 				scmd_local->scsi_done(scmd_local);
b37f23
diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.h b/drivers/scsi/megaraid/megaraid_sas_fusion.h
b37f23
index 7a3c3d1..2de12b4 100644
b37f23
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.h
b37f23
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.h
b37f23
@@ -59,6 +59,8 @@
b37f23
 #define	MR_RL_FLAGS_GRANT_DESTINATION_CPU1	    0x10
b37f23
 #define	MR_RL_FLAGS_GRANT_DESTINATION_CUDA	    0x80
b37f23
 #define MR_RL_FLAGS_SEQ_NUM_ENABLE		    0x8
b37f23
+#define MR_RL_WRITE_THROUGH_MODE		    0x00
b37f23
+#define MR_RL_WRITE_BACK_MODE			    0x01
b37f23
 
b37f23
 /* T10 PI defines */
b37f23
 #define MR_PROT_INFO_TYPE_CONTROLLER                0x8
b37f23
@@ -81,6 +83,11 @@
b37f23
 enum MR_RAID_FLAGS_IO_SUB_TYPE {
b37f23
 	MR_RAID_FLAGS_IO_SUB_TYPE_NONE = 0,
b37f23
 	MR_RAID_FLAGS_IO_SUB_TYPE_SYSTEM_PD = 1,
b37f23
+	MR_RAID_FLAGS_IO_SUB_TYPE_RMW_DATA     = 2,
b37f23
+	MR_RAID_FLAGS_IO_SUB_TYPE_RMW_P        = 3,
b37f23
+	MR_RAID_FLAGS_IO_SUB_TYPE_RMW_Q        = 4,
b37f23
+	MR_RAID_FLAGS_IO_SUB_TYPE_CACHE_BYPASS = 6,
b37f23
+	MR_RAID_FLAGS_IO_SUB_TYPE_LDIO_BW_LIMIT = 7
b37f23
 };
b37f23
 
b37f23
 /*
b37f23
@@ -109,29 +116,29 @@ enum MR_FUSION_ADAPTER_TYPE {
b37f23
 
b37f23
 struct RAID_CONTEXT {
b37f23
 #if   defined(__BIG_ENDIAN_BITFIELD)
b37f23
-	u8	nseg:4;
b37f23
-	u8	Type:4;
b37f23
+	u8 nseg:4;
b37f23
+	u8 type:4;
b37f23
 #else
b37f23
-	u8	Type:4;
b37f23
-	u8	nseg:4;
b37f23
+	u8 type:4;
b37f23
+	u8 nseg:4;
b37f23
 #endif
b37f23
-	u8	resvd0;
b37f23
-	__le16	timeoutValue;
b37f23
-	u8      regLockFlags;
b37f23
-	u8      resvd1;
b37f23
-	__le16	VirtualDiskTgtId;
b37f23
-	__le64	regLockRowLBA;
b37f23
-	__le32	regLockLength;
b37f23
-	__le16	nextLMId;
b37f23
-	u8      exStatus;
b37f23
-	u8      status;
b37f23
-	u8      RAIDFlags;
b37f23
-	u8      numSGE;
b37f23
-	__le16	configSeqNum;
b37f23
-	u8      spanArm;
b37f23
-	u8      priority;
b37f23
-	u8	numSGEExt;
b37f23
-	u8      resvd2;
b37f23
+	u8 resvd0;
b37f23
+	__le16 timeout_value;
b37f23
+	u8 reg_lock_flags;
b37f23
+	u8 resvd1;
b37f23
+	__le16 virtual_disk_tgt_id;
b37f23
+	__le64 reg_lock_row_lba;
b37f23
+	__le32 reg_lock_length;
b37f23
+	__le16 next_lmid;
b37f23
+	u8 ex_status;
b37f23
+	u8 status;
b37f23
+	u8 raid_flags;
b37f23
+	u8 num_sge;
b37f23
+	__le16 config_seq_num;
b37f23
+	u8 span_arm;
b37f23
+	u8 priority;
b37f23
+	u8 num_sge_ext;
b37f23
+	u8 resvd2;
b37f23
 };
b37f23
 
b37f23
 /*
b37f23
@@ -187,7 +194,7 @@ struct RAID_CONTEXT_G35 {
b37f23
 	} smid;
b37f23
 	u8 ex_status;       /* 0x16 : OUT */
b37f23
 	u8 status;          /* 0x17 status */
b37f23
-	u8 RAIDFlags;		/* 0x18 resvd[7:6], ioSubType[5:4],
b37f23
+	u8 raid_flags;		/* 0x18 resvd[7:6], ioSubType[5:4],
b37f23
 				 * resvd[3:1], preferredCpu[0]
b37f23
 				 */
b37f23
 	u8 span_arm;            /* 0x1C span[7:5], arm[4:0] */
b37f23
@@ -672,14 +679,17 @@ struct MPI2_IOC_INIT_REQUEST {
b37f23
 #define MAX_RAIDMAP_ROW_SIZE (MAX_ROW_SIZE)
b37f23
 #define MAX_LOGICAL_DRIVES 64
b37f23
 #define MAX_LOGICAL_DRIVES_EXT 256
b37f23
+#define MAX_LOGICAL_DRIVES_DYN 512
b37f23
 #define MAX_RAIDMAP_LOGICAL_DRIVES (MAX_LOGICAL_DRIVES)
b37f23
 #define MAX_RAIDMAP_VIEWS (MAX_LOGICAL_DRIVES)
b37f23
 #define MAX_ARRAYS 128
b37f23
 #define MAX_RAIDMAP_ARRAYS (MAX_ARRAYS)
b37f23
 #define MAX_ARRAYS_EXT	256
b37f23
 #define MAX_API_ARRAYS_EXT (MAX_ARRAYS_EXT)
b37f23
+#define MAX_API_ARRAYS_DYN 512
b37f23
 #define MAX_PHYSICAL_DEVICES 256
b37f23
 #define MAX_RAIDMAP_PHYSICAL_DEVICES (MAX_PHYSICAL_DEVICES)
b37f23
+#define MAX_RAIDMAP_PHYSICAL_DEVICES_DYN 512
b37f23
 #define MR_DCMD_LD_MAP_GET_INFO             0x0300e101
b37f23
 #define MR_DCMD_SYSTEM_PD_MAP_GET_INFO      0x0200e102
b37f23
 #define MR_DCMD_CTRL_SHARED_HOST_MEM_ALLOC  0x010e8485   /* SR-IOV HB alloc*/
b37f23
@@ -726,12 +736,56 @@ struct MR_SPAN_BLOCK_INFO {
b37f23
 	struct MR_SPAN_INFO block_span_info;
b37f23
 };
b37f23
 
b37f23
+#define MR_RAID_CTX_CPUSEL_0		0
b37f23
+#define MR_RAID_CTX_CPUSEL_1		1
b37f23
+#define MR_RAID_CTX_CPUSEL_2		2
b37f23
+#define MR_RAID_CTX_CPUSEL_3		3
b37f23
+#define MR_RAID_CTX_CPUSEL_FCFS		0xF
b37f23
+
b37f23
+struct MR_CPU_AFFINITY_MASK {
b37f23
+	union {
b37f23
+		struct {
b37f23
+#ifndef MFI_BIG_ENDIAN
b37f23
+		u8 hw_path:1;
b37f23
+		u8 cpu0:1;
b37f23
+		u8 cpu1:1;
b37f23
+		u8 cpu2:1;
b37f23
+		u8 cpu3:1;
b37f23
+		u8 reserved:3;
b37f23
+#else
b37f23
+		u8 reserved:3;
b37f23
+		u8 cpu3:1;
b37f23
+		u8 cpu2:1;
b37f23
+		u8 cpu1:1;
b37f23
+		u8 cpu0:1;
b37f23
+		u8 hw_path:1;
b37f23
+#endif
b37f23
+		};
b37f23
+		u8 core_mask;
b37f23
+	};
b37f23
+};
b37f23
+
b37f23
+struct MR_IO_AFFINITY {
b37f23
+	union {
b37f23
+		struct {
b37f23
+			struct MR_CPU_AFFINITY_MASK pdRead;
b37f23
+			struct MR_CPU_AFFINITY_MASK pdWrite;
b37f23
+			struct MR_CPU_AFFINITY_MASK ldRead;
b37f23
+			struct MR_CPU_AFFINITY_MASK ldWrite;
b37f23
+			};
b37f23
+		u32 word;
b37f23
+		};
b37f23
+	u8 maxCores;    /* Total cores + HW Path in ROC */
b37f23
+	u8 reserved[3];
b37f23
+};
b37f23
+
b37f23
 struct MR_LD_RAID {
b37f23
 	struct {
b37f23
 #if   defined(__BIG_ENDIAN_BITFIELD)
b37f23
-		u32     reserved4:3;
b37f23
-		u32     fp_cache_bypass_capable:1;
b37f23
-		u32     fp_rmw_capable:1;
b37f23
+		u32 reserved4:2;
b37f23
+		u32 fp_cache_bypass_capable:1;
b37f23
+		u32 fp_rmw_capable:1;
b37f23
+		u32 disable_coalescing:1;
b37f23
 		u32     fpBypassRegionLock:1;
b37f23
 		u32     tmCapable:1;
b37f23
 		u32	fpNonRWCapable:1;
b37f23
@@ -759,9 +813,10 @@ struct MR_LD_RAID {
b37f23
 		u32	fpNonRWCapable:1;
b37f23
 		u32     tmCapable:1;
b37f23
 		u32     fpBypassRegionLock:1;
b37f23
-		u32     fp_rmw_capable:1;
b37f23
-		u32     fp_cache_bypass_capable:1;
b37f23
-		u32     reserved4:3;
b37f23
+		u32 disable_coalescing:1;
b37f23
+		u32 fp_rmw_capable:1;
b37f23
+		u32 fp_cache_bypass_capable:1;
b37f23
+		u32 reserved4:2;
b37f23
 #endif
b37f23
 	} capability;
b37f23
 	__le32     reserved6;
b37f23
@@ -788,7 +843,36 @@ struct MR_LD_RAID {
b37f23
 
b37f23
 	u8	LUN[8]; /* 0x24 8 byte LUN field used for SCSI IO's */
b37f23
 	u8	fpIoTimeoutForLd;/*0x2C timeout value used by driver in FP IO*/
b37f23
-	u8      reserved3[0x80-0x2D]; /* 0x2D */
b37f23
+	/* Ox2D This LD accept priority boost of this type */
b37f23
+	u8 ld_accept_priority_type;
b37f23
+	u8 reserved2[2];	        /* 0x2E - 0x2F */
b37f23
+	/* 0x30 - 0x33, Logical block size for the LD */
b37f23
+	u32 logical_block_length;
b37f23
+	struct {
b37f23
+#ifndef MFI_BIG_ENDIAN
b37f23
+	/* 0x34, P_I_EXPONENT from READ CAPACITY 16 */
b37f23
+	u32 ld_pi_exp:4;
b37f23
+	/* 0x34, LOGICAL BLOCKS PER PHYSICAL
b37f23
+	 *  BLOCK EXPONENT from READ CAPACITY 16
b37f23
+	 */
b37f23
+	u32 ld_logical_block_exp:4;
b37f23
+	u32 reserved1:24;           /* 0x34 */
b37f23
+#else
b37f23
+	u32 reserved1:24;           /* 0x34 */
b37f23
+	/* 0x34, LOGICAL BLOCKS PER PHYSICAL
b37f23
+	 *  BLOCK EXPONENT from READ CAPACITY 16
b37f23
+	 */
b37f23
+	u32 ld_logical_block_exp:4;
b37f23
+	/* 0x34, P_I_EXPONENT from READ CAPACITY 16 */
b37f23
+	u32 ld_pi_exp:4;
b37f23
+#endif
b37f23
+	};                               /* 0x34 - 0x37 */
b37f23
+	 /* 0x38 - 0x3f, This will determine which
b37f23
+	  *  core will process LD IO and PD IO.
b37f23
+	  */
b37f23
+	struct MR_IO_AFFINITY cpuAffinity;
b37f23
+     /* Bit definiations are specified by MR_IO_AFFINITY */
b37f23
+	u8 reserved3[0x80-0x40];    /* 0x40 - 0x7f */
b37f23
 };
b37f23
 
b37f23
 struct MR_LD_SPAN_MAP {
b37f23
@@ -846,6 +930,91 @@ struct MR_LD_TARGET_SYNC {
b37f23
 	__le16 seqNum;
b37f23
 };
b37f23
 
b37f23
+/*
b37f23
+ * RAID Map descriptor Types.
b37f23
+ * Each element should uniquely idetify one data structure in the RAID map
b37f23
+ */
b37f23
+enum MR_RAID_MAP_DESC_TYPE {
b37f23
+	/* MR_DEV_HANDLE_INFO data */
b37f23
+	RAID_MAP_DESC_TYPE_DEVHDL_INFO    = 0x0,
b37f23
+	/* target to Ld num Index map */
b37f23
+	RAID_MAP_DESC_TYPE_TGTID_INFO     = 0x1,
b37f23
+	/* MR_ARRAY_INFO data */
b37f23
+	RAID_MAP_DESC_TYPE_ARRAY_INFO     = 0x2,
b37f23
+	/* MR_LD_SPAN_MAP data */
b37f23
+	RAID_MAP_DESC_TYPE_SPAN_INFO      = 0x3,
b37f23
+	RAID_MAP_DESC_TYPE_COUNT,
b37f23
+};
b37f23
+
b37f23
+/*
b37f23
+ * This table defines the offset, size and num elements  of each descriptor
b37f23
+ * type in the RAID Map buffer
b37f23
+ */
b37f23
+struct MR_RAID_MAP_DESC_TABLE {
b37f23
+	/* Raid map descriptor type */
b37f23
+	u32 raid_map_desc_type;
b37f23
+	/* Offset into the RAID map buffer where
b37f23
+	 *  descriptor data is saved
b37f23
+	 */
b37f23
+	u32 raid_map_desc_offset;
b37f23
+	/* total size of the
b37f23
+	 * descriptor buffer
b37f23
+	 */
b37f23
+	u32 raid_map_desc_buffer_size;
b37f23
+	/* Number of elements contained in the
b37f23
+	 *  descriptor buffer
b37f23
+	 */
b37f23
+	u32 raid_map_desc_elements;
b37f23
+};
b37f23
+
b37f23
+/*
b37f23
+ * Dynamic Raid Map Structure.
b37f23
+ */
b37f23
+struct MR_FW_RAID_MAP_DYNAMIC {
b37f23
+	u32 raid_map_size;   /* total size of RAID Map structure */
b37f23
+	u32 desc_table_offset;/* Offset of desc table into RAID map*/
b37f23
+	u32 desc_table_size;  /* Total Size of desc table */
b37f23
+	/* Total Number of elements in the desc table */
b37f23
+	u32 desc_table_num_elements;
b37f23
+	u64	reserved1;
b37f23
+	u32	reserved2[3];	/*future use */
b37f23
+	/* timeout value used by driver in FP IOs */
b37f23
+	u8 fp_pd_io_timeout_sec;
b37f23
+	u8 reserved3[3];
b37f23
+	/* when this seqNum increments, driver needs to
b37f23
+	 *  release RMW buffers asap
b37f23
+	 */
b37f23
+	u32 rmw_fp_seq_num;
b37f23
+	u16 ld_count;	/* count of lds. */
b37f23
+	u16 ar_count;   /* count of arrays */
b37f23
+	u16 span_count; /* count of spans */
b37f23
+	u16 reserved4[3];
b37f23
+/*
b37f23
+ * The below structure of pointers is only to be used by the driver.
b37f23
+ * This is added in the ,API to reduce the amount of code changes
b37f23
+ * needed in the driver to support dynamic RAID map Firmware should
b37f23
+ * not update these pointers while preparing the raid map
b37f23
+ */
b37f23
+	union {
b37f23
+		struct {
b37f23
+			struct MR_DEV_HANDLE_INFO  *dev_hndl_info;
b37f23
+			u16 *ld_tgt_id_to_ld;
b37f23
+			struct MR_ARRAY_INFO *ar_map_info;
b37f23
+			struct MR_LD_SPAN_MAP *ld_span_map;
b37f23
+			};
b37f23
+		u64 ptr_structure_size[RAID_MAP_DESC_TYPE_COUNT];
b37f23
+		};
b37f23
+/*
b37f23
+ * RAID Map descriptor table defines the layout of data in the RAID Map.
b37f23
+ * The size of the descriptor table itself could change.
b37f23
+ */
b37f23
+	/* Variable Size descriptor Table. */
b37f23
+	struct MR_RAID_MAP_DESC_TABLE
b37f23
+			raid_map_desc_table[RAID_MAP_DESC_TYPE_COUNT];
b37f23
+	/* Variable Size buffer containing all data */
b37f23
+	u32 raid_map_desc_data[1];
b37f23
+}; /* Dynamicaly sized RAID MAp structure */
b37f23
+
b37f23
 #define IEEE_SGE_FLAGS_ADDR_MASK            (0x03)
b37f23
 #define IEEE_SGE_FLAGS_SYSTEM_ADDR          (0x00)
b37f23
 #define IEEE_SGE_FLAGS_IOCDDR_ADDR          (0x01)
b37f23
@@ -955,9 +1124,10 @@ struct MR_DRV_RAID_MAP {
b37f23
 	__le16                 spanCount;
b37f23
 	__le16                 reserve3;
b37f23
 
b37f23
-	struct MR_DEV_HANDLE_INFO  devHndlInfo[MAX_RAIDMAP_PHYSICAL_DEVICES];
b37f23
-	u8                  ldTgtIdToLd[MAX_LOGICAL_DRIVES_EXT];
b37f23
-	struct MR_ARRAY_INFO       arMapInfo[MAX_API_ARRAYS_EXT];
b37f23
+	struct MR_DEV_HANDLE_INFO
b37f23
+		devHndlInfo[MAX_RAIDMAP_PHYSICAL_DEVICES_DYN];
b37f23
+	u16 ldTgtIdToLd[MAX_LOGICAL_DRIVES_DYN];
b37f23
+	struct MR_ARRAY_INFO arMapInfo[MAX_API_ARRAYS_DYN];
b37f23
 	struct MR_LD_SPAN_MAP      ldSpanMap[1];
b37f23
 
b37f23
 };
b37f23
@@ -969,7 +1139,7 @@ struct MR_DRV_RAID_MAP {
b37f23
 struct MR_DRV_RAID_MAP_ALL {
b37f23
 
b37f23
 	struct MR_DRV_RAID_MAP raidMap;
b37f23
-	struct MR_LD_SPAN_MAP      ldSpanMap[MAX_LOGICAL_DRIVES_EXT - 1];
b37f23
+	struct MR_LD_SPAN_MAP ldSpanMap[MAX_LOGICAL_DRIVES_DYN - 1];
b37f23
 } __packed;
b37f23
 
b37f23
 
b37f23
@@ -1088,7 +1258,7 @@ struct fusion_context {
b37f23
 	u8	chain_offset_io_request;
b37f23
 	u8	chain_offset_mfi_pthru;
b37f23
 
b37f23
-	struct MR_FW_RAID_MAP_ALL *ld_map[2];
b37f23
+	struct MR_FW_RAID_MAP_DYNAMIC *ld_map[2];
b37f23
 	dma_addr_t ld_map_phys[2];
b37f23
 
b37f23
 	/*Non dma-able memory. Driver local copy.*/
b37f23
@@ -1096,6 +1266,8 @@ struct fusion_context {
b37f23
 
b37f23
 	u32 max_map_sz;
b37f23
 	u32 current_map_sz;
b37f23
+	u32 old_map_sz;
b37f23
+	u32 new_map_sz;
b37f23
 	u32 drv_map_sz;
b37f23
 	u32 drv_map_pages;
b37f23
 	struct MR_PD_CFG_SEQ_NUM_SYNC	*pd_seq_sync[JBOD_MAPS_COUNT];
b37f23
-- 
b37f23
1.8.3.1
b37f23