megaraid_sas: JBOD sequence number support

Implemented JBOD map which will provide quick access for JBOD path and
also provide sequence number.  This will help hardware to fail command
to the FW in case of any sequence mismatch.

Fast Path I/O for JBOD will refer JBOD map (which has sequence number
per JBOD device) instead of RAID map.  Previously, the driver used RAID
map to get device handle for fast path I/O and this not have sequence
number information. Now, driver will use JBOD map instead.  As part of
error handling, if JBOD map is failed/not supported by firmware, driver
will continue using legacy behavior.

Now there will be three IO paths for JBOD (syspd):

 - JBOD map with sequence number (Fast Path)
 - RAID map without sequence number (Fast Path)
 - FW path via h/w exception queue deliberately setup devhandle
   0xFFFF (FW path).

Relevant data structures:

 - Driver send new DCMD MR_DCMD_SYSTEM_PD_MAP_GET_INFO for this purpose.
 - struct MR_PD_CFG_SEQ- This structure represent map of single physical
   device.
 - struct MR_PD_CFG_SEQ_NUM_SYNC- This structure represent whole JBOD
   map in general(size, count of sysPDs configured, struct MR_PD_CFG_SEQ
   of syspD with 0 index).
 - JBOD sequence map size is: sizeof(struct MR_PD_CFG_SEQ_NUM_SYNC)
   + (sizeof(struct MR_PD_CFG_SEQ) * (MAX_PHYSICAL_DEVICES - 1)) which
   is allocated while setting up JBOD map at driver load time.

Signed-off-by: Sumit Saxena <sumit.saxena@avagotech.com>
Signed-off-by: Kashyap Desai <kashyap.desai@avagotech.com>
Reviewed-by: Martin Petersen <martin.petersen@oracle.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
diff --git a/drivers/scsi/megaraid/megaraid_sas.h b/drivers/scsi/megaraid/megaraid_sas.h
index b0d373d..811fc4a 100644
--- a/drivers/scsi/megaraid/megaraid_sas.h
+++ b/drivers/scsi/megaraid/megaraid_sas.h
@@ -973,7 +973,8 @@
 
 	struct {
 #if defined(__BIG_ENDIAN_BITFIELD)
-		u32     reserved:8;
+		u32     reserved:7;
+		u32     useSeqNumJbodFP:1;
 		u32     supportExtendedSSCSize:1;
 		u32     supportDiskCacheSettingForSysPDs:1;
 		u32     supportCPLDUpdate:1;
@@ -1021,7 +1022,8 @@
 		u32     supportCPLDUpdate:1;
 		u32     supportDiskCacheSettingForSysPDs:1;
 		u32     supportExtendedSSCSize:1;
-		u32     reserved:8;
+		u32     useSeqNumJbodFP:1;
+		u32     reserved:7;
 #endif
 	} adapterOperations3;
 
@@ -1700,6 +1702,7 @@
 	u32 crash_dump_drv_support;
 	u32 crash_dump_app_support;
 	u32 secure_jbod_support;
+	bool use_seqnum_jbod_fp;   /* Added for PD sequence */
 	spinlock_t crashdump_lock;
 
 	struct megasas_register_set __iomem *reg_set;
@@ -1779,7 +1782,9 @@
 	struct msix_entry msixentry[MEGASAS_MAX_MSIX_QUEUES];
 	struct megasas_irq_context irq_context[MEGASAS_MAX_MSIX_QUEUES];
 	u64 map_id;
+	u64 pd_seq_map_id;
 	struct megasas_cmd *map_update_cmd;
+	struct megasas_cmd *jbod_seq_cmd;
 	unsigned long bar;
 	long reset_flags;
 	struct mutex reset_mutex;
@@ -1995,6 +2000,9 @@
 void mr_update_load_balance_params(struct MR_DRV_RAID_MAP_ALL *map,
 	struct LD_LOAD_BALANCE_INFO *lbInfo);
 int megasas_get_ctrl_info(struct megasas_instance *instance);
+/* PD sequence */
+int
+megasas_sync_pd_seq_num(struct megasas_instance *instance, bool pend);
 int megasas_set_crash_dump_params(struct megasas_instance *instance,
 	u8 crash_buf_state);
 void megasas_free_host_crash_buffer(struct megasas_instance *instance);
@@ -2010,5 +2018,6 @@
 void megasas_return_mfi_mpt_pthr(struct megasas_instance *instance,
 	struct megasas_cmd *cmd_mfi, struct megasas_cmd_fusion *cmd_fusion);
 int megasas_cmd_type(struct scsi_cmnd *cmd);
+void megasas_setup_jbod_map(struct megasas_instance *instance);
 
 #endif				/*LSI_MEGARAID_SAS_H */