All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/24] Introducing mpi3mr driver
@ 2020-12-22 10:11 Kashyap Desai
  2020-12-22 10:11 ` [PATCH 01/24] mpi3mr: add mpi30 Rev-R headers and Kconfig Kashyap Desai
                   ` (24 more replies)
  0 siblings, 25 replies; 75+ messages in thread
From: Kashyap Desai @ 2020-12-22 10:11 UTC (permalink / raw)
  To: linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, Kashyap Desai

[-- Attachment #1: Type: text/plain, Size: 4415 bytes --]

This patch series covers logical patches of the new device driver for the
MPI3MR high performance storage I/O & RAID controllers (Avenger series).
The mpi3mr has true multiple h/w queue interfacing like nvme.

See more info -
https://www.spinics.net/lists/linux-scsi/msg147868.html

The controllers managed by the mpi3mr driver are capable of reaching a
very high performance numbers compared to existing controller due to the
new hardware architectures. This Driver is tested with the internal
versions of the MPI3MR I/O & RAID controllers.

Patches are logical split mainly for better code review. Full patch set is
required for functional stability of this new driver.

You can find the source at - https://github.com/kadesai16/mpi3mr_v1


Kashyap Desai (24):
  mpi3mr: add mpi30 Rev-R headers and Kconfig
  mpi3mr: base driver code
  mpi3mr: create operational request and reply queue pair
  mpi3mr: add support of queue command processing
  mpi3mr: add support of internal watchdog thread
  mpi3mr: add support of event handling part-1
  mpi3mr: add support of event handling pcie devices part-2
  mpi3mr: add support of event handling part-3
  mpi3mr: add support for recovering controller
  mpi3mr: add support of timestamp sync with firmware
  mpi3mr: print ioc info for debugging
  mpi3mr: add bios_param shost template hook
  mpi3mr: implement scsi error handler hooks
  mpi3mr: add change queue depth support
  mpi3mr: allow certain commands during pci-remove hook
  mpi3mr: hardware workaround for UNMAP commands to nvme drives
  mpi3mr: add support of threaded isr
  mpi3mr: add complete support of soft reset
  mpi3mr: print pending host ios for debug
  mpi3mr: wait for pending IO completions upon detection of VD IO
    timeout
  mpi3mr: add support of PM suspend and resume
  mpi3mr: add support of DSN secure fw check
  mpi3mr: add eedp dif dix support
  mpi3mr: add event handling debug prints

 drivers/scsi/Kconfig                      |    1 +
 drivers/scsi/Makefile                     |    1 +
 drivers/scsi/mpi3mr/Kconfig               |    7 +
 drivers/scsi/mpi3mr/Makefile              |    4 +
 drivers/scsi/mpi3mr/mpi/mpi30_api.h       |   23 +
 drivers/scsi/mpi3mr/mpi/mpi30_cnfg.h      | 2721 ++++++++++++++
 drivers/scsi/mpi3mr/mpi/mpi30_image.h     |  285 ++
 drivers/scsi/mpi3mr/mpi/mpi30_init.h      |  216 ++
 drivers/scsi/mpi3mr/mpi/mpi30_ioc.h       | 1423 +++++++
 drivers/scsi/mpi3mr/mpi/mpi30_sas.h       |   46 +
 drivers/scsi/mpi3mr/mpi/mpi30_transport.h |  675 ++++
 drivers/scsi/mpi3mr/mpi/mpi30_type.h      |   89 +
 drivers/scsi/mpi3mr/mpi3mr.h              |  906 +++++
 drivers/scsi/mpi3mr/mpi3mr_debug.h        |   60 +
 drivers/scsi/mpi3mr/mpi3mr_fw.c           | 3944 ++++++++++++++++++++
 drivers/scsi/mpi3mr/mpi3mr_os.c           | 4148 +++++++++++++++++++++
 16 files changed, 14549 insertions(+)
 create mode 100644 drivers/scsi/mpi3mr/Kconfig
 create mode 100644 drivers/scsi/mpi3mr/Makefile
 create mode 100644 drivers/scsi/mpi3mr/mpi/mpi30_api.h
 create mode 100644 drivers/scsi/mpi3mr/mpi/mpi30_cnfg.h
 create mode 100644 drivers/scsi/mpi3mr/mpi/mpi30_image.h
 create mode 100644 drivers/scsi/mpi3mr/mpi/mpi30_init.h
 create mode 100644 drivers/scsi/mpi3mr/mpi/mpi30_ioc.h
 create mode 100644 drivers/scsi/mpi3mr/mpi/mpi30_sas.h
 create mode 100644 drivers/scsi/mpi3mr/mpi/mpi30_transport.h
 create mode 100644 drivers/scsi/mpi3mr/mpi/mpi30_type.h
 create mode 100644 drivers/scsi/mpi3mr/mpi3mr.h
 create mode 100644 drivers/scsi/mpi3mr/mpi3mr_debug.h
 create mode 100644 drivers/scsi/mpi3mr/mpi3mr_fw.c
 create mode 100644 drivers/scsi/mpi3mr/mpi3mr_os.c

-- 
2.18.1


-- 
This electronic communication and the information and any files transmitted 
with it, or attached to it, are confidential and are intended solely for 
the use of the individual or entity to whom it is addressed and may contain 
information that is confidential, legally privileged, protected by privacy 
laws, or otherwise restricted from disclosure to anyone else. If you are 
not the intended recipient or the person responsible for delivering the 
e-mail to the intended recipient, you are hereby notified that any use, 
copying, distributing, dissemination, forwarding, printing, or copying of 
this e-mail is strictly prohibited. If you received this e-mail in error, 
please return the e-mail to the sender, delete it from your computer, and 
destroy any printed copy of it.

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4169 bytes --]

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 01/24] mpi3mr: add mpi30 Rev-R headers and Kconfig
  2020-12-22 10:11 [PATCH 00/24] Introducing mpi3mr driver Kashyap Desai
@ 2020-12-22 10:11 ` Kashyap Desai
  2020-12-22 18:15   ` Bart Van Assche
  2021-02-23 12:30   ` Hannes Reinecke
  2020-12-22 10:11 ` [PATCH 02/24] mpi3mr: base driver code Kashyap Desai
                   ` (23 subsequent siblings)
  24 siblings, 2 replies; 75+ messages in thread
From: Kashyap Desai @ 2020-12-22 10:11 UTC (permalink / raw)
  To: linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, Kashyap Desai, sathya.prakash

[-- Attachment #1: Type: text/plain, Size: 171610 bytes --]

This adds the Kconfig and mpi30 headers.

Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Cc: sathya.prakash@broadcom.com
---
 drivers/scsi/Kconfig                      |    1 +
 drivers/scsi/Makefile                     |    1 +
 drivers/scsi/mpi3mr/Kconfig               |    7 +
 drivers/scsi/mpi3mr/mpi/mpi30_api.h       |   21 +
 drivers/scsi/mpi3mr/mpi/mpi30_image.h     |  285 +++++
 drivers/scsi/mpi3mr/mpi/mpi30_init.h      |  216 ++++
 drivers/scsi/mpi3mr/mpi/mpi30_ioc.h       | 1423 +++++++++++++++++++++
 drivers/scsi/mpi3mr/mpi/mpi30_transport.h |  675 ++++++++++
 drivers/scsi/mpi3mr/mpi/mpi30_type.h      |   89 ++
 9 files changed, 2718 insertions(+)
 create mode 100644 drivers/scsi/mpi3mr/Kconfig
 create mode 100644 drivers/scsi/mpi3mr/mpi/mpi30_api.h
 create mode 100644 drivers/scsi/mpi3mr/mpi/mpi30_image.h
 create mode 100644 drivers/scsi/mpi3mr/mpi/mpi30_init.h
 create mode 100644 drivers/scsi/mpi3mr/mpi/mpi30_ioc.h
 create mode 100644 drivers/scsi/mpi3mr/mpi/mpi30_transport.h
 create mode 100644 drivers/scsi/mpi3mr/mpi/mpi30_type.h

diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index 701b61ec76ee..afccbd062237 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -482,6 +482,7 @@ config SCSI_ARCMSR
 source "drivers/scsi/esas2r/Kconfig"
 source "drivers/scsi/megaraid/Kconfig.megaraid"
 source "drivers/scsi/mpt3sas/Kconfig"
+source "drivers/scsi/mpi3mr/Kconfig"
 source "drivers/scsi/smartpqi/Kconfig"
 source "drivers/scsi/ufs/Kconfig"
 
diff --git a/drivers/scsi/Makefile b/drivers/scsi/Makefile
index c00e3dd57990..7c3f2faae18b 100644
--- a/drivers/scsi/Makefile
+++ b/drivers/scsi/Makefile
@@ -100,6 +100,7 @@ obj-$(CONFIG_MEGARAID_LEGACY)	+= megaraid.o
 obj-$(CONFIG_MEGARAID_NEWGEN)	+= megaraid/
 obj-$(CONFIG_MEGARAID_SAS)	+= megaraid/
 obj-$(CONFIG_SCSI_MPT3SAS)	+= mpt3sas/
+obj-$(CONFIG_SCSI_MPI3MR)	+= mpi3mr/
 obj-$(CONFIG_SCSI_UFSHCD)	+= ufs/
 obj-$(CONFIG_SCSI_ACARD)	+= atp870u.o
 obj-$(CONFIG_SCSI_SUNESP)	+= esp_scsi.o	sun_esp.o
diff --git a/drivers/scsi/mpi3mr/Kconfig b/drivers/scsi/mpi3mr/Kconfig
new file mode 100644
index 000000000000..2d0568dd176a
--- /dev/null
+++ b/drivers/scsi/mpi3mr/Kconfig
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+config SCSI_MPI3MR
+	tristate "Broadcom MPI3 Storage Controller Device Driver"
+	depends on PCI && SCSI
+	help
+	This driver supports Broadcom's Unified MPI3 based Storage & RAID Controllers.
diff --git a/drivers/scsi/mpi3mr/mpi/mpi30_api.h b/drivers/scsi/mpi3mr/mpi/mpi30_api.h
new file mode 100644
index 000000000000..ca07387536d3
--- /dev/null
+++ b/drivers/scsi/mpi3mr/mpi/mpi30_api.h
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ *  Copyright 2019-2020 Broadcom Inc. All rights reserved.
+ *
+ *           Name: mpi30_api.h
+ *    Description: Root header that include all other MPI 3.0 headers
+ *                 Developers need to only include this header to gain
+ *                 access to the full MPI3.0 API definitions.
+ *  Creation Date: 04/15/2019
+ *        Version: 03.00.00
+ */
+#ifndef MPI30_API_H
+#define MPI30_API_H     1
+
+#include "mpi30_type.h"
+#include "mpi30_transport.h"
+#include "mpi30_image.h"
+#include "mpi30_init.h"
+#include "mpi30_ioc.h"
+
+#endif  /* MPI30_API_H */
diff --git a/drivers/scsi/mpi3mr/mpi/mpi30_image.h b/drivers/scsi/mpi3mr/mpi/mpi30_image.h
new file mode 100644
index 000000000000..430662d3a43b
--- /dev/null
+++ b/drivers/scsi/mpi3mr/mpi/mpi30_image.h
@@ -0,0 +1,285 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ *  Copyright 2018-2020 Broadcom Inc. All rights reserved.
+ *
+ *           Name: mpi30_image.h
+ *    Description: Contains definitions for firmware and other component images.
+ *  Creation Date: 04/02/2018
+ *        Version: 03.00.00
+ */
+#ifndef MPI30_IMAGE_H
+#define MPI30_IMAGE_H     1
+
+/* Component Image Version */
+typedef struct _MPI3_COMP_IMAGE_VERSION {
+    U16     BuildNum;            /* 0x00 */
+    U16     CustomerID;          /* 0x02 */
+    U8      PhaseMinor;          /* 0x04 */
+    U8      PhaseMajor;          /* 0x05 */
+    U8      GenMinor;            /* 0x06 */
+    U8      GenMajor;            /* 0x07 */
+} MPI3_COMP_IMAGE_VERSION, MPI3_POINTER PTR_MPI3_COMP_IMAGE_VERSION,
+  Mpi3CompImageVersion, MPI3_POINTER pMpi3CompImageVersion;
+
+/* Hash Exclusion Format */
+typedef struct _MPI3_HASH_EXCLUSION_FORMAT {
+    U32                     Offset;        /* 0x00 */
+    U32                     Size;          /* 0x04 */
+} MPI3_HASH_EXCLUSION_FORMAT, MPI3_POINTER PTR_MPI3_HASH_EXCLUSION_FORMAT,
+Mpi3HashSxclusionFormat_t, MPI3_POINTER pMpi3HashExclusionFormat_t;
+
+#define MPI3_IMAGE_HASH_EXCUSION_NUM                           (4)
+
+/* FW Image Header */
+typedef struct _MPI3_COMPONENT_IMAGE_HEADER {
+    U32                            Signature0;                                      /* 0x00 */
+    U32                            LoadAddress;                                     /* 0x04 */
+    U32                            DataSize;                                        /* 0x08 */
+    U32                            StartOffset;                                     /* 0x0C */
+    U32                            Signature1;                                      /* 0x10 */
+    U32                            FlashOffset;                                     /* 0x14 */
+    U32                            ImageSize;                                       /* 0x18 */
+    U32                            VersionStringOffset;                             /* 0x1C */
+    U32                            BuildDateStringOffset;                           /* 0x20 */
+    U32                            BuildTimeStringOffset;                           /* 0x24 */
+    U32                            EnvironmentVariableOffset;                       /* 0x28 */
+    U32                            ApplicationSpecific;                             /* 0x2C */
+    U32                            Signature2;                                      /* 0x30 */
+    U32                            HeaderSize;                                      /* 0x34 */
+    U32                            Crc;                                             /* 0x38 */
+    U32                            Flags;                                           /* 0x3C */
+    U32                            SecondaryFlashOffset;                            /* 0x40 */
+    U32                            ETPOffset;                                       /* 0x44 */
+    U32                            ETPSize;                                         /* 0x48 */
+    MPI3_VERSION_UNION             RMCInterfaceVersion;                             /* 0x4C */
+    MPI3_VERSION_UNION             ETPInterfaceVersion;                             /* 0x50 */
+    MPI3_COMP_IMAGE_VERSION        ComponentImageVersion;                           /* 0x54 */
+    MPI3_HASH_EXCLUSION_FORMAT     HashExclusion[MPI3_IMAGE_HASH_EXCUSION_NUM];     /* 0x5C */
+    U32                            NextImageHeaderOffset;                           /* 0x7C */
+    MPI3_VERSION_UNION             SecurityVersion;                                 /* 0x80 */
+    U32                            Reserved84[31];                                  /* 0x84 -- 0xFC */
+} MPI3_COMPONENT_IMAGE_HEADER, MPI3_POINTER PTR_MPI3_COMPONENT_IMAGE_HEADER,
+  Mpi3ComponentImageHeader_t, MPI3_POINTER pMpi3ComponentImageHeader_t;
+
+
+/**** Definitions for Signature0 field ****/
+#define MPI3_IMAGE_HEADER_SIGNATURE0_MPI3                     (0xEB00003E)
+
+/**** Definitions for LoadAddress field ****/
+#define MPI3_IMAGE_HEADER_LOAD_ADDRESS_INVALID                (0x00000000)
+
+/**** Definitions for Signature1 field ****/
+#define MPI3_IMAGE_HEADER_SIGNATURE1_APPLICATION              (0x20505041)  /* string "APP "  */
+#define MPI3_IMAGE_HEADER_SIGNATURE1_FIRST_MUTABLE            (0x20434D46)  /* string "FMC "  */
+#define MPI3_IMAGE_HEADER_SIGNATURE1_BSP                      (0x20505342)  /* string "BSP "  */
+#define MPI3_IMAGE_HEADER_SIGNATURE1_ROM_BIOS                 (0x534F4942)  /* string "BIOS"  */
+#define MPI3_IMAGE_HEADER_SIGNATURE1_HII_X64                  (0x4D494948)  /* string "HIIM"  */
+#define MPI3_IMAGE_HEADER_SIGNATURE1_HII_ARM                  (0x41494948)  /* string "HIIA"  */
+#define MPI3_IMAGE_HEADER_SIGNATURE1_CPLD                     (0x444C5043)  /* string "CPLD"  */
+#define MPI3_IMAGE_HEADER_SIGNATURE1_SPD                      (0x20445053)  /* string "SPD "  */
+#define MPI3_IMAGE_HEADER_SIGNATURE1_GAS_GAUGE                (0x20534147)  /* string "GAS "  */
+#define MPI3_IMAGE_HEADER_SIGNATURE1_PBLP                     (0x504C4250)  /* string "PBLP"  */
+
+/**** Definitions for Signature2 field ****/
+#define MPI3_IMAGE_HEADER_SIGNATURE2_VALUE                    (0x50584546)
+
+/**** Definitions for Flags field ****/
+#define MPI3_IMAGE_HEADER_FLAGS_DEVICE_KEY_BASIS_MASK         (0x00000030)
+#define MPI3_IMAGE_HEADER_FLAGS_DEVICE_KEY_BASIS_CDI          (0x00000000)
+#define MPI3_IMAGE_HEADER_FLAGS_DEVICE_KEY_BASIS_DI           (0x00000010)
+#define MPI3_IMAGE_HEADER_FLAGS_SIGNED_NVDATA                 (0x00000008)
+#define MPI3_IMAGE_HEADER_FLAGS_REQUIRES_ACTIVATION           (0x00000004)
+#define MPI3_IMAGE_HEADER_FLAGS_COMPRESSED                    (0x00000002)
+#define MPI3_IMAGE_HEADER_FLAGS_FLASH                         (0x00000001)
+
+
+/**** Offsets for Image Header Fields ****/
+#define MPI3_IMAGE_HEADER_SIGNATURE0_OFFSET                   (0x00)
+#define MPI3_IMAGE_HEADER_LOAD_ADDRESS_OFFSET                 (0x04)
+#define MPI3_IMAGE_HEADER_DATA_SIZE_OFFSET                    (0x08)
+#define MPI3_IMAGE_HEADER_START_OFFSET_OFFSET                 (0x0C)
+#define MPI3_IMAGE_HEADER_SIGNATURE1_OFFSET                   (0x10)
+#define MPI3_IMAGE_HEADER_FLASH_OFFSET_OFFSET                 (0x14)
+#define MPI3_IMAGE_HEADER_FLASH_SIZE_OFFSET                   (0x18)
+#define MPI3_IMAGE_HEADER_VERSION_STRING_OFFSET_OFFSET        (0x1C)
+#define MPI3_IMAGE_HEADER_BUILD_DATE_STRING_OFFSET_OFFSET     (0x20)
+#define MPI3_IMAGE_HEADER_BUILD_TIME_OFFSET_OFFSET            (0x24)
+#define MPI3_IMAGE_HEADER_ENVIROMENT_VAR_OFFSET_OFFSET        (0x28)
+#define MPI3_IMAGE_HEADER_APPLICATION_SPECIFIC_OFFSET         (0x2C)
+#define MPI3_IMAGE_HEADER_SIGNATURE2_OFFSET                   (0x30)
+#define MPI3_IMAGE_HEADER_HEADER_SIZE_OFFSET                  (0x34)
+#define MPI3_IMAGE_HEADER_CRC_OFFSET                          (0x38)
+#define MPI3_IMAGE_HEADER_FLAGS_OFFSET                        (0x3C)
+#define MPI3_IMAGE_HEADER_SECONDARY_FLASH_OFFSET_OFFSET       (0x40)
+#define MPI3_IMAGE_HEADER_ETP_OFFSET_OFFSET                   (0x44)
+#define MPI3_IMAGE_HEADER_ETP_SIZE_OFFSET                     (0x48)
+#define MPI3_IMAGE_HEADER_RMC_INTERFACE_VER_OFFSET            (0x4C)
+#define MPI3_IMAGE_HEADER_ETP_INTERFACE_VER_OFFSET            (0x50)
+#define MPI3_IMAGE_HEADER_COMPONENT_IMAGE_VER_OFFSET          (0x54)
+#define MPI3_IMAGE_HEADER_HASH_EXCLUSION_OFFSET               (0x5C)
+#define MPI3_IMAGE_HEADER_NEXT_IMAGE_HEADER_OFFSET_OFFSET     (0x7C)
+
+
+#define MPI3_IMAGE_HEADER_SIZE                                (0x100)
+
+
+/* Extended Image Header */
+typedef struct _MPI3_EXTENDED_IMAGE_HEADER {
+    U8                             ImageType;                  /* 0x00 */
+    U8                             Reserved01[3];              /* 0x01 */
+    U32                            Checksum;                   /* 0x04 */
+    U32                            ImageSize;                  /* 0x08 */
+    U32                            NextImageHeaderOffset;      /* 0x0C */
+    U32                            Reserved10[4];              /* 0x10 */
+    U32                            IdentifyString[8];          /* 0x20 */
+} MPI3_EXTENDED_IMAGE_HEADER, MPI3_POINTER PTR_MPI3_EXTENDED_IMAGE_HEADER,
+  Mpi3ExtendedImageHeader_t, MPI3_POINTER pMpi3ExtendedImageHeader_t;
+
+/* useful offsets */
+#define MPI3_EXT_IMAGE_IMAGETYPE_OFFSET         (0x00)
+#define MPI3_EXT_IMAGE_IMAGESIZE_OFFSET         (0x08)
+#define MPI3_EXT_IMAGE_NEXTIMAGE_OFFSET         (0x0C)
+
+#define MPI3_EXT_IMAGE_HEADER_SIZE              (0x40)
+
+/* defines for the ImageType field */
+#define MPI3_EXT_IMAGE_TYPE_UNSPECIFIED             (0x00)
+#define MPI3_EXT_IMAGE_TYPE_NVDATA                  (0x03)
+#define MPI3_EXT_IMAGE_TYPE_SUPPORTED_DEVICES       (0x07)
+#define MPI3_EXT_IMAGE_TYPE_ENCRYPTED_HASH          (0x09)
+#define MPI3_EXT_IMAGE_TYPE_RDE                     (0x0A)
+#define MPI3_EXT_IMAGE_TYPE_AUXILIARY_PROCESSOR     (0x0B)
+#define MPI3_EXT_IMAGE_TYPE_MIN_PRODUCT_SPECIFIC    (0x80)
+#define MPI3_EXT_IMAGE_TYPE_MAX_PRODUCT_SPECIFIC    (0xFF)
+
+
+/* Supported Device Data Format */
+typedef struct _MPI3_SUPPORTED_DEVICE {
+    U16                     DeviceID;                   /* 0x00 */
+    U16                     VendorID;                   /* 0x02 */
+    U16                     DeviceIDMask;               /* 0x04 */
+    U16                     Reserved06;                 /* 0x06 */
+    U8                      LowPCIRev;                  /* 0x08 */
+    U8                      HighPCIRev;                 /* 0x09 */
+    U16                     Reserved0A;                 /* 0x0A */
+    U32                     Reserved0C;                 /* 0x0C */
+} MPI3_SUPPORTED_DEVICE, MPI3_POINTER PTR_MPI3_SUPPORTED_DEVICE,
+  Mpi3SupportedDevice_t, MPI3_POINTER pMpi3SupportedDevice_t;
+
+#ifndef MPI3_SUPPORTED_DEVICE_MAX
+#define MPI3_SUPPORTED_DEVICE_MAX                      (1)
+#endif  /* MPI3_SUPPORTED_DEVICE_MAX */
+
+/* Supported Devices Extended Image Data */
+typedef struct _MPI3_SUPPORTED_DEVICES_DATA {
+    U8                      ImageVersion;                                   /* 0x00 */
+    U8                      Reserved01;                                     /* 0x01 */
+    U8                      NumDevices;                                     /* 0x02 */
+    U8                      Reserved03;                                     /* 0x03 */
+    U32                     Reserved04;                                     /* 0x04 */
+    MPI3_SUPPORTED_DEVICE   SupportedDevice[MPI3_SUPPORTED_DEVICE_MAX];     /* 0x08 */    /* variable length */
+} MPI3_SUPPORTED_DEVICES_DATA, MPI3_POINTER PTR_MPI3_SUPPORTED_DEVICES_DATA,
+  Mpi3SupportedDevicesData_t, MPI3_POINTER pMpi3SupportedDevicesData_t;
+
+#ifndef MPI3_ENCRYPTED_HASH_MAX
+#define MPI3_ENCRYPTED_HASH_MAX                      (1)
+#endif  /* MPI3_ENCRYPTED_HASH_MAX */
+
+/* Encrypted Hash Entry Format */
+typedef struct _MPI3_ENCRYPTED_HASH_ENTRY {
+    U8                      HashImageType;                                  /* 0x00 */
+    U8                      HashAlgorithm;                                  /* 0x01 */
+    U8                      EncryptionAlgorithm;                            /* 0x02 */
+    U8                      Reserved03;                                     /* 0x03 */
+    U32                     Reserved04;                                     /* 0x04 */
+    U32                     EncryptedHash[MPI3_ENCRYPTED_HASH_MAX];         /* 0x08 */   /* variable length */
+} MPI3_ENCRYPTED_HASH_ENTRY, MPI3_POINTER PTR_MPI3_ENCRYPTED_HASH_ENTRY,
+  Mpi3EncryptedHashEntry_t, MPI3_POINTER pMpi3EncryptedHashEntry_t;
+
+
+/* defines for the HashImageType field */
+#define MPI3_HASH_IMAGE_TYPE_KEY_WITH_SIGNATURE      (0x03)
+
+/* defines for the HashAlgorithm field */
+#define MPI3_HASH_ALGORITHM_VERSION_MASK             (0xE0)
+#define MPI3_HASH_ALGORITHM_VERSION_NONE             (0x00)
+#define MPI3_HASH_ALGORITHM_VERSION_SHA1             (0x20)   /* Obsolete */
+#define MPI3_HASH_ALGORITHM_VERSION_SHA2             (0x40)
+#define MPI3_HASH_ALGORITHM_VERSION_SHA3             (0x60)
+
+#define MPI3_HASH_ALGORITHM_SIZE_MASK                (0x1F)
+#define MPI3_HASH_ALGORITHM_SIZE_UNUSED              (0x00)
+#define MPI3_HASH_ALGORITHM_SIZE_SHA256              (0x01)
+#define MPI3_HASH_ALGORITHM_SIZE_SHA512              (0x02)
+
+/* defines for the EncryptionAlgorithm field */
+#define MPI3_ENCRYPTION_ALGORITHM_UNUSED             (0x00)
+#define MPI3_ENCRYPTION_ALGORITHM_RSA256             (0x01)   /* Obsolete */
+#define MPI3_ENCRYPTION_ALGORITHM_RSA512             (0x02)   /* Obsolete */
+#define MPI3_ENCRYPTION_ALGORITHM_RSA1024            (0x03)   /* Obsolete */
+#define MPI3_ENCRYPTION_ALGORITHM_RSA2048            (0x04)
+#define MPI3_ENCRYPTION_ALGORITHM_RSA4096            (0x05)
+#define MPI3_ENCRYPTION_ALGORITHM_RSA3072            (0x06)
+
+
+#ifndef MPI3_PUBLIC_KEY_MAX
+#define MPI3_PUBLIC_KEY_MAX                          (1)
+#endif  /* MPI3_PUBLIC_KEY_MAX */
+
+/* Encrypted Key with Hash Entry Format */
+typedef struct _MPI3_ENCRYPTED_KEY_WITH_HASH_ENTRY {
+    U8                      HashImageType;                             /* 0x00 */
+    U8                      HashAlgorithm;                             /* 0x01 */
+    U8                      EncryptionAlgorithm;                       /* 0x02 */
+    U8                      Reserved03;                                /* 0x03 */
+    U32                     Reserved04;                                /* 0x04 */
+    U32                     PublicKey[MPI3_PUBLIC_KEY_MAX];            /* 0x08 */     /* variable length */
+    U32                     EncryptedHash[MPI3_ENCRYPTED_HASH_MAX];    /* 0x0C */     /* variable length */
+} MPI3_ENCRYPTED_KEY_WITH_HASH_ENTRY, MPI3_POINTER PTR_MPI3_ENCRYPTED_KEY_WITH_HASH_ENTRY,
+  Mpi3EncryptedKeyWithHashEntry_t, MPI3_POINTER pMpi3EncryptedKeyWithHashEntry_t;
+
+#ifndef MPI3_ENCRYPTED_HASH_ENTRY_MAX
+#define MPI3_ENCRYPTED_HASH_ENTRY_MAX               (1)
+#endif  /* MPI3_ENCRYPTED_HASH_ENTRY_MAX */
+
+/* Encrypted Hash Image Data */
+typedef struct _MPI3_ENCRYPTED_HASH_DATA {
+    U8                               ImageVersion;                                          /* 0x00 */
+    U8                               NumHash;                                               /* 0x01 */
+    U16                              Reserved02;                                            /* 0x02 */
+    U32                              Reserved04;                                            /* 0x04 */
+    MPI3_ENCRYPTED_HASH_ENTRY        EncryptedHashEntry[MPI3_ENCRYPTED_HASH_ENTRY_MAX];     /* 0x08 */   /* variable length */
+} MPI3_ENCRYPTED_HASH_DATA, MPI3_POINTER PTR_MPI3_ENCRYPTED_HASH_DATA,
+  Mpi3EncryptedHashData_t, MPI3_POINTER pMpi3EncryptedHashData_t;
+
+
+#ifndef MPI3_AUX_PROC_DATA_MAX
+#define MPI3_AUX_PROC_DATA_MAX               (1)
+#endif  /* MPI3_ENCRYPTED_HASH_ENTRY_MAX */
+
+/* Auxiliary Processor Extended Image Data */
+typedef struct _MPI3_AUX_PROCESSOR_DATA {
+    U8                      BootMethod;                               /* 0x00 */
+    U8                      NumLoadAddr;                              /* 0x01 */
+    U8                      Reserved02;                               /* 0x02 */
+    U8                      Type;                                     /* 0x03 */
+    U32                     Version;                                  /* 0x04 */
+    U32                     LoadAddress[8];                           /* 0x08 */
+    U32                     Reserved28[22];                           /* 0x28 */
+    U32                     AuxProcessorData[MPI3_AUX_PROC_DATA_MAX]; /* 0x80 */   /* variable length */
+} MPI3_AUX_PROCESSOR_DATA, MPI3_POINTER PTR_MPI3_AUX_PROCESSOR_DATA,
+  Mpi3AuxProcessorData_t, MPI3_POINTER pMpi3AuxProcessorData_t;
+
+#define MPI3_AUX_PROC_DATA_OFFSET                                     (0x80)
+
+/* defines for the BootMethod field */
+#define MPI3_AUXPROCESSOR_BOOT_METHOD_MO_MSG                          (0x00)
+#define MPI3_AUXPROCESSOR_BOOT_METHOD_MO_DOORBELL                     (0x01)
+#define MPI3_AUXPROCESSOR_BOOT_METHOD_COMPONENT                       (0x02)
+
+/* defines for the Type field */
+#define MPI3_AUXPROCESSOR_TYPE_ARM_A15                                (0x00)
+#define MPI3_AUXPROCESSOR_TYPE_ARM_M0                                 (0x01)
+#define MPI3_AUXPROCESSOR_TYPE_ARM_R4                                 (0x02)
+
+#endif /* MPI30_IMAGE_H */
diff --git a/drivers/scsi/mpi3mr/mpi/mpi30_init.h b/drivers/scsi/mpi3mr/mpi/mpi30_init.h
new file mode 100644
index 000000000000..a0222f0fc9a8
--- /dev/null
+++ b/drivers/scsi/mpi3mr/mpi/mpi30_init.h
@@ -0,0 +1,216 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ *  Copyright 2016-2020 Broadcom Inc. All rights reserved.
+ *
+ *           Name: mpi30_init.h
+ *    Description: Contains definitions for SCSI initiator mode messages and structures.
+ *  Creation Date: 10/27/2016
+ *        Version: 03.00.00
+ */
+#ifndef MPI30_INIT_H
+#define MPI30_INIT_H     1
+
+/*****************************************************************************
+ *              SCSI Initiator Messages                                      *
+ ****************************************************************************/
+
+/*****************************************************************************
+ *              SCSI IO Request Message                                      *
+ ****************************************************************************/
+typedef struct _MPI3_SCSI_IO_CDB_EEDP32 {
+    U8              CDB[20];                            /* 0x00 */
+    __be32          PrimaryReferenceTag;                /* 0x14 */
+    U16             PrimaryApplicationTag;              /* 0x18 */
+    U16             PrimaryApplicationTagMask;          /* 0x1A */
+    U32             TransferLength;                     /* 0x1C */
+} MPI3_SCSI_IO_CDB_EEDP32, MPI3_POINTER PTR_MPI3_SCSI_IO_CDB_EEDP32,
+  Mpi3ScsiIoCdbEedp32_t, MPI3_POINTER pMpi3ScsiIoCdbEedp32_t;
+
+typedef union _MPI3_SCSO_IO_CDB_UNION {
+    U8                      CDB32[32];
+    MPI3_SCSI_IO_CDB_EEDP32 EEDP32;
+    MPI3_SGE_SIMPLE         SGE;
+} MPI3_SCSO_IO_CDB_UNION, MPI3_POINTER PTR_MPI3_SCSO_IO_CDB_UNION,
+  Mpi3ScsiIoCdb_t, MPI3_POINTER pMpi3ScsiIoCdb_t;
+
+typedef struct _MPI3_SCSI_IO_REQUEST {
+    U16                     HostTag;                        /* 0x00 */
+    U8                      IOCUseOnly02;                   /* 0x02 */
+    U8                      Function;                       /* 0x03 */
+    U16                     IOCUseOnly04;                   /* 0x04 */
+    U8                      IOCUseOnly06;                   /* 0x06 */
+    U8                      MsgFlags;                       /* 0x07 */
+    U16                     ChangeCount;                    /* 0x08 */
+    U16                     DevHandle;                      /* 0x0A */
+    U32                     Flags;                          /* 0x0C */
+    U32                     SkipCount;                      /* 0x10 */
+    U32                     DataLength;                     /* 0x14 */
+    U8                      LUN[8];                         /* 0x18 */
+    MPI3_SCSO_IO_CDB_UNION  CDB;                            /* 0x20 */
+    MPI3_SGE_UNION          SGL[4];                         /* 0x40 */
+} MPI3_SCSI_IO_REQUEST, MPI3_POINTER PTR_MPI3_SCSI_IO_REQUEST,
+  Mpi3SCSIIORequest_t, MPI3_POINTER pMpi3SCSIIORequest_t;
+
+/**** Defines for the MsgFlags field ****/
+#define MPI3_SCSIIO_MSGFLAGS_METASGL_VALID                  (0x80)
+
+/**** Defines for the Flags field ****/
+#define MPI3_SCSIIO_FLAGS_LARGE_CDB                         (0x60000000)
+#define MPI3_SCSIIO_FLAGS_CDB_16_OR_LESS                    (0x00000000)
+#define MPI3_SCSIIO_FLAGS_CDB_GREATER_THAN_16               (0x20000000)
+#define MPI3_SCSIIO_FLAGS_CDB_IN_SEPARATE_BUFFER            (0x40000000)
+#define MPI3_SCSIIO_FLAGS_TASKATTRIBUTE_MASK                (0x07000000)
+#define MPI3_SCSIIO_FLAGS_TASKATTRIBUTE_SIMPLEQ             (0x00000000)
+#define MPI3_SCSIIO_FLAGS_TASKATTRIBUTE_HEADOFQ             (0x01000000)
+#define MPI3_SCSIIO_FLAGS_TASKATTRIBUTE_ORDEREDQ            (0x02000000)
+#define MPI3_SCSIIO_FLAGS_TASKATTRIBUTE_ACAQ                (0x04000000)
+#define MPI3_SCSIIO_FLAGS_CMDPRI_MASK                       (0x00F00000)
+#define MPI3_SCSIIO_FLAGS_CMDPRI_SHIFT                      (20)
+#define MPI3_SCSIIO_FLAGS_DATADIRECTION_MASK                (0x000C0000)
+#define MPI3_SCSIIO_FLAGS_DATADIRECTION_NO_DATA_TRANSFER    (0x00000000)
+#define MPI3_SCSIIO_FLAGS_DATADIRECTION_WRITE               (0x00040000)
+#define MPI3_SCSIIO_FLAGS_DATADIRECTION_READ                (0x00080000)
+#define MPI3_SCSIIO_FLAGS_DMAOPERATION_MASK                 (0x00030000)
+#define MPI3_SCSIIO_FLAGS_DMAOPERATION_HOST_PI              (0x00010000)
+
+/**** Defines for the SGL field ****/
+#define MPI3_SCSIIO_METASGL_INDEX                           (3)
+
+/*****************************************************************************
+ *              SCSI IO Error Reply Message                                  *
+ ****************************************************************************/
+typedef struct _MPI3_SCSI_IO_REPLY {
+    U16                     HostTag;                        /* 0x00 */
+    U8                      IOCUseOnly02;                   /* 0x02 */
+    U8                      Function;                       /* 0x03 */
+    U16                     IOCUseOnly04;                   /* 0x04 */
+    U8                      IOCUseOnly06;                   /* 0x06 */
+    U8                      MsgFlags;                       /* 0x07 */
+    U16                     IOCUseOnly08;                   /* 0x08 */
+    U16                     IOCStatus;                      /* 0x0A */
+    U32                     IOCLogInfo;                     /* 0x0C */
+    U8                      SCSIStatus;                     /* 0x10 */
+    U8                      SCSIState;                      /* 0x11 */
+    U16                     DevHandle;                      /* 0x12 */
+    U32                     TransferCount;                  /* 0x14 */
+    U32                     SenseCount;                     /* 0x18 */
+    U32                     ResponseData;                   /* 0x1C */
+    U16                     TaskTag;                        /* 0x20 */
+    U16                     SCSIStatusQualifier;            /* 0x22 */
+    U32                     EEDPErrorOffset;                /* 0x24 */
+    U16                     EEDPObservedAppTag;             /* 0x28 */
+    U16                     EEDPObservedGuard;              /* 0x2A */
+    U32                     EEDPObservedRefTag;             /* 0x2C */
+    U64                     SenseDataBufferAddress;         /* 0x30 */
+} MPI3_SCSI_IO_REPLY, MPI3_POINTER PTR_MPI3_SCSI_IO_REPLY,
+  Mpi3SCSIIOReply_t, MPI3_POINTER pMpi3SCSIIOReply_t;
+
+/**** Defines for the MsgFlags field ****/
+#define MPI3_SCSIIO_REPLY_MSGFLAGS_REFTAG_OBSERVED_VALID        (0x01)
+#define MPI3_SCSIIO_REPLY_MSGFLAGS_APPTAG_OBSERVED_VALID        (0x02)
+#define MPI3_SCSIIO_REPLY_MSGFLAGS_GUARD_OBSERVED_VALID         (0x04)
+
+/**** Defines for the SCSIStatus field ****/
+#define MPI3_SCSI_STATUS_GOOD                   (0x00)
+#define MPI3_SCSI_STATUS_CHECK_CONDITION        (0x02)
+#define MPI3_SCSI_STATUS_CONDITION_MET          (0x04)
+#define MPI3_SCSI_STATUS_BUSY                   (0x08)
+#define MPI3_SCSI_STATUS_INTERMEDIATE           (0x10)
+#define MPI3_SCSI_STATUS_INTERMEDIATE_CONDMET   (0x14)
+#define MPI3_SCSI_STATUS_RESERVATION_CONFLICT   (0x18)
+#define MPI3_SCSI_STATUS_COMMAND_TERMINATED     (0x22)
+#define MPI3_SCSI_STATUS_TASK_SET_FULL          (0x28)
+#define MPI3_SCSI_STATUS_ACA_ACTIVE             (0x30)
+#define MPI3_SCSI_STATUS_TASK_ABORTED           (0x40)
+
+/**** Defines for the SCSIState field ****/
+#define MPI3_SCSI_STATE_SENSE_MASK              (0x03)
+#define MPI3_SCSI_STATE_SENSE_VALID             (0x00)
+#define MPI3_SCSI_STATE_SENSE_FAILED            (0x01)
+#define MPI3_SCSI_STATE_SENSE_BUFF_Q_EMPTY      (0x02)
+#define MPI3_SCSI_STATE_SENSE_NOT_AVAILABLE     (0x03)
+#define MPI3_SCSI_STATE_NO_SCSI_STATUS          (0x04)
+#define MPI3_SCSI_STATE_TERMINATED              (0x08)
+#define MPI3_SCSI_STATE_RESPONSE_DATA_VALID     (0x10)
+
+/**** Defines for the ResponseData field ****/
+#define MPI3_SCSI_RSP_RESPONSECODE_MASK         (0x000000FF)
+#define MPI3_SCSI_RSP_RESPONSECODE_SHIFT        (0)
+#define MPI3_SCSI_RSP_ARI2_MASK                 (0x0000FF00)
+#define MPI3_SCSI_RSP_ARI2_SHIFT                (8)
+#define MPI3_SCSI_RSP_ARI1_MASK                 (0x00FF0000)
+#define MPI3_SCSI_RSP_ARI1_SHIFT                (16)
+#define MPI3_SCSI_RSP_ARI0_MASK                 (0xFF000000)
+#define MPI3_SCSI_RSP_ARI0_SHIFT                (24)
+
+/**** Defines for the TaskTag field ****/
+#define MPI3_SCSI_TASKTAG_UNKNOWN               (0xFFFF)
+
+
+/*****************************************************************************
+ *              SCSI Task Management Request Message                         *
+ ****************************************************************************/
+typedef struct _MPI3_SCSI_TASK_MGMT_REQUEST {
+    U16                     HostTag;                        /* 0x00 */
+    U8                      IOCUseOnly02;                   /* 0x02 */
+    U8                      Function;                       /* 0x03 */
+    U16                     IOCUseOnly04;                   /* 0x04 */
+    U8                      IOCUseOnly06;                   /* 0x06 */
+    U8                      MsgFlags;                       /* 0x07 */
+    U16                     ChangeCount;                    /* 0x08 */
+    U16                     DevHandle;                      /* 0x0A */
+    U16                     TaskHostTag;                    /* 0x0C */
+    U8                      TaskType;                       /* 0x0E */
+    U8                      Reserved0F;                     /* 0x0F */
+    U16                     TaskRequestQueueID;             /* 0x10 */
+    U16                     Reserved12;                     /* 0x12 */
+    U32                     Reserved14;                     /* 0x14 */
+    U8                      LUN[8];                         /* 0x18 */
+} MPI3_SCSI_TASK_MGMT_REQUEST, MPI3_POINTER PTR_MPI3_SCSI_TASK_MGMT_REQUEST,
+  Mpi3SCSITaskMgmtRequest_t, MPI3_POINTER pMpi3SCSITaskMgmtRequest_t;
+
+/**** Defines for the MsgFlags field ****/
+#define MPI3_SCSITASKMGMT_MSGFLAGS_DO_NOT_SEND_TASK_IU      (0x08)
+
+/**** Defines for the TaskType field ****/
+#define MPI3_SCSITASKMGMT_TASKTYPE_ABORT_TASK               (0x01)
+#define MPI3_SCSITASKMGMT_TASKTYPE_ABORT_TASK_SET           (0x02)
+#define MPI3_SCSITASKMGMT_TASKTYPE_TARGET_RESET             (0x03)
+#define MPI3_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET       (0x05)
+#define MPI3_SCSITASKMGMT_TASKTYPE_CLEAR_TASK_SET           (0x06)
+#define MPI3_SCSITASKMGMT_TASKTYPE_QUERY_TASK               (0x07)
+#define MPI3_SCSITASKMGMT_TASKTYPE_CLEAR_ACA                (0x08)
+#define MPI3_SCSITASKMGMT_TASKTYPE_QUERY_TASK_SET           (0x09)
+#define MPI3_SCSITASKMGMT_TASKTYPE_QUERY_ASYNC_EVENT        (0x0A)
+#define MPI3_SCSITASKMGMT_TASKTYPE_I_T_NEXUS_RESET          (0x0B)
+
+
+/*****************************************************************************
+ *              SCSI Task Management Reply Message                           *
+ ****************************************************************************/
+typedef struct _MPI3_SCSI_TASK_MGMT_REPLY {
+    U16                     HostTag;                        /* 0x00 */
+    U8                      IOCUseOnly02;                   /* 0x02 */
+    U8                      Function;                       /* 0x03 */
+    U16                     IOCUseOnly04;                   /* 0x04 */
+    U8                      IOCUseOnly06;                   /* 0x06 */
+    U8                      MsgFlags;                       /* 0x07 */
+    U16                     IOCUseOnly08;                   /* 0x08 */
+    U16                     IOCStatus;                      /* 0x0A */
+    U32                     IOCLogInfo;                     /* 0x0C */
+    U32                     TerminationCount;               /* 0x10 */
+    U32                     ResponseData;                   /* 0x14 */
+    U32                     Reserved18;                     /* 0x18 */
+} MPI3_SCSI_TASK_MGMT_REPLY, MPI3_POINTER PTR_MPI3_SCSI_TASK_MGMT_REPLY,
+  Mpi3SCSITaskMgmtReply_t, MPI3_POINTER pMpi3SCSITaskMgmtReply_t;
+
+/**** Defines for the ResponseData field - use MPI3_SCSI_RSP_ defines ****/
+/*
+ * Values for the ResponseCode (byte 0 of ResponseData) is normally obtained
+ * from the SSP Response frame. A value of 0x80 may be returned by the IOC
+ * for a TaskType of Query Task indicating the specified TaskHostTag I/O is
+ * currently queued on the IOC and has not been sent to the target device yet.
+ */
+#define MPI3_SCSITASKMGMT_RSPCODE_IO_QUEUED_ON_IOC      (0x80)
+
+#endif  /* MPI30_INIT_H */
diff --git a/drivers/scsi/mpi3mr/mpi/mpi30_ioc.h b/drivers/scsi/mpi3mr/mpi/mpi30_ioc.h
new file mode 100644
index 000000000000..880d717000f6
--- /dev/null
+++ b/drivers/scsi/mpi3mr/mpi/mpi30_ioc.h
@@ -0,0 +1,1423 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ *  Copyright 2016-2020 Broadcom Inc. All rights reserved.
+ *
+ *           Name: mpi30_ioc.h
+ *    Description: Contains definitions for IOC messages such as IOC Init, IOC Facts, Port Enable,
+ *                 Events, FW Download, and FW Upload.
+ *  Creation Date: 10/24/2016
+ *        Version: 03.00.00
+ */
+#ifndef MPI30_IOC_H
+#define MPI30_IOC_H     1
+
+/*****************************************************************************
+ *              IOC Messages                                                 *
+ ****************************************************************************/
+
+/*****************************************************************************
+ *              IOCInit Request Message                                      *
+ ****************************************************************************/
+typedef struct _MPI3_IOC_INIT_REQUEST {
+    U16                   HostTag;                            /* 0x00 */
+    U8                    IOCUseOnly02;                       /* 0x02 */
+    U8                    Function;                           /* 0x03 */
+    U16                   IOCUseOnly04;                       /* 0x04 */
+    U8                    IOCUseOnly06;                       /* 0x06 */
+    U8                    MsgFlags;                           /* 0x07 */
+    U16                   ChangeCount;                        /* 0x08 */
+    U16                   Reserved0A;                         /* 0x0A */
+    MPI3_VERSION_UNION    MPIVersion;                         /* 0x0C */
+    U64                   TimeStamp;                          /* 0x10 */
+    U8                    Reserved18;                         /* 0x18 */
+    U8                    WhoInit;                            /* 0x19 */
+    U16                   Reserved1A;                         /* 0x1A */
+    U16                   ReplyFreeQueueDepth;                /* 0x1C */
+    U16                   Reserved1E;                         /* 0x1E */
+    U64                   ReplyFreeQueueAddress;              /* 0x20 */
+    U32                   Reserved28;                         /* 0x28 */
+    U16                   SenseBufferFreeQueueDepth;          /* 0x2C */
+    U16                   SenseBufferLength;                  /* 0x2E */
+    U64                   SenseBufferFreeQueueAddress;        /* 0x30 */
+    U64                   DriverInformationAddress;           /* 0x38 */
+} MPI3_IOC_INIT_REQUEST, MPI3_POINTER PTR_MPI3_IOC_INIT_REQUEST,
+  Mpi3IOCInitRequest_t, MPI3_POINTER pMpi3IOCInitRequest_t;
+
+
+/**** Defines for the WhoInit field ****/
+#define MPI3_WHOINIT_NOT_INITIALIZED            (0x00)
+#define MPI3_WHOINIT_ROM_BIOS                   (0x02)
+#define MPI3_WHOINIT_HOST_DRIVER                (0x03)
+#define MPI3_WHOINIT_MANUFACTURER               (0x04)
+
+/**** Defines for the DriverInformationAddress field */
+typedef struct _MPI3_DRIVER_INFO_LAYOUT {
+    U32             InformationLength;                  /* 0x00 */
+    U8              DriverSignature[12];                /* 0x04 */
+    U8              OsName[16];                         /* 0x10 */
+    U8              OsVersion[12];                      /* 0x20 */
+    U8              DriverName[20];                     /* 0x2C */
+    U8              DriverVersion[32];                  /* 0x40 */
+    U8              DriverReleaseDate[20];              /* 0x60 */
+    U32             DriverCapabilities;                 /* 0x74 */
+} MPI3_DRIVER_INFO_LAYOUT, MPI3_POINTER PTR_MPI3_DRIVER_INFO_LAYOUT,
+  Mpi3DriverInfoLayout_t, MPI3_POINTER pMpi3DriverInfoLayout_t;
+
+/*****************************************************************************
+ *              IOCFacts Request Message                                     *
+ ****************************************************************************/
+typedef struct _MPI3_IOC_FACTS_REQUEST {
+    U16                 HostTag;                            /* 0x00 */
+    U8                  IOCUseOnly02;                       /* 0x02 */
+    U8                  Function;                           /* 0x03 */
+    U16                 IOCUseOnly04;                       /* 0x04 */
+    U8                  IOCUseOnly06;                       /* 0x06 */
+    U8                  MsgFlags;                           /* 0x07 */
+    U16                 ChangeCount;                        /* 0x08 */
+    U16                 Reserved0A;                         /* 0x0A */
+    U32                 Reserved0C;                         /* 0x0C */
+    MPI3_SGE_UNION      SGL;                                /* 0x10 */
+} MPI3_IOC_FACTS_REQUEST, MPI3_POINTER PTR_MPI3_IOC_FACTS_REQUEST,
+  Mpi3IOCFactsRequest_t, MPI3_POINTER pMpi3IOCFactsRequest_t;
+
+/*****************************************************************************
+ *              IOCFacts Data                                                *
+ ****************************************************************************/
+typedef struct _MPI3_IOC_FACTS_DATA {
+    U16                     IOCFactsDataLength;                 /* 0x00 */
+    U16                     Reserved02;                         /* 0x02 */
+    MPI3_VERSION_UNION      MPIVersion;                         /* 0x04 */
+    MPI3_COMP_IMAGE_VERSION FWVersion;                          /* 0x08 */
+    U32                     IOCCapabilities;                    /* 0x10 */
+    U8                      IOCNumber;                          /* 0x14 */
+    U8                      WhoInit;                            /* 0x15 */
+    U16                     MaxMSIxVectors;                     /* 0x16 */
+    U16                     MaxOutstandingRequest;              /* 0x18 */
+    U16                     ProductID;                          /* 0x1A */
+    U16                     IOCRequestFrameSize;                /* 0x1C */
+    U16                     ReplyFrameSize;                     /* 0x1E */
+    U16                     IOCExceptions;                      /* 0x20 */
+    U16                     MaxPersistentID;                    /* 0x22 */
+    U8                      SGEModifierMask;                    /* 0x24 */
+    U8                      SGEModifierValue;                   /* 0x25 */
+    U8                      SGEModifierShift;                   /* 0x26 */
+    U8                      ProtocolFlags;                      /* 0x27 */
+    U16                     MaxSASInitiators;                   /* 0x28 */
+    U16                     MaxSASTargets;                      /* 0x2A */
+    U16                     MaxSASExpanders;                    /* 0x2C */
+    U16                     MaxEnclosures;                      /* 0x2E */
+    U16                     MinDevHandle;                       /* 0x30 */
+    U16                     MaxDevHandle;                       /* 0x32 */
+    U16                     MaxPCIeSwitches;                    /* 0x34 */
+    U16                     MaxNVMe;                            /* 0x36 */
+    U16                     MaxPDs;                             /* 0x38 */
+    U16                     MaxVDs;                             /* 0x3A */
+    U16                     MaxHostPDs;                         /* 0x3C */
+    U16                     MaxAdvancedHostPDs;                 /* 0x3E */
+    U16                     MaxRAIDPDs;                         /* 0x40 */
+    U16                     MaxPostedCmdBuffers;                /* 0x42 */
+    U32                     Flags;                              /* 0x44 */
+    U16                     MaxOperationalRequestQueues;        /* 0x48 */
+    U16                     MaxOperationalReplyQueues;          /* 0x4A */
+    U16                     ShutdownTimeout;                    /* 0x4C */
+    U16                     Reserved4E;                         /* 0x4E */
+    U32                     DiagTraceSize;                      /* 0x50 */
+    U32                     DiagFwSize;                         /* 0x54 */
+} MPI3_IOC_FACTS_DATA, MPI3_POINTER PTR_MPI3_IOC_FACTS_DATA,
+  Mpi3IOCFactsData_t, MPI3_POINTER pMpi3IOCFactsData_t;
+
+/**** Defines for the IOCCapabilities field ****/
+#define MPI3_IOCFACTS_CAPABILITY_ADVANCED_HOST_PD             (0x00000010)
+#define MPI3_IOCFACTS_CAPABILITY_RAID_CAPABLE                 (0x00000008)
+#define MPI3_IOCFACTS_CAPABILITY_COALESCE_CTRL_GRAN_MASK      (0x00000001)
+#define MPI3_IOCFACTS_CAPABILITY_COALESCE_CTRL_IOC_GRAN       (0x00000000)
+#define MPI3_IOCFACTS_CAPABILITY_COALESCE_CTRL_REPLY_Q_GRAN   (0x00000001)
+
+/**** WhoInit values are defined under IOCInit Request Message definition ****/
+
+/**** Defines for the ProductID field ****/
+#define MPI3_IOCFACTS_PID_TYPE_MASK                           (0xF000)
+#define MPI3_IOCFACTS_PID_TYPE_SHIFT                          (12)
+#define MPI3_IOCFACTS_PID_PRODUCT_MASK                        (0x0F00)
+#define MPI3_IOCFACTS_PID_PRODUCT_SHIFT                       (8)
+#define MPI3_IOCFACTS_PID_FAMILY_MASK                         (0x00FF)
+#define MPI3_IOCFACTS_PID_FAMILY_SHIFT                        (0)
+
+/**** Defines for the IOCExceptions field ****/
+#define MPI3_IOCFACTS_EXCEPT_SAFE_MODE                        (0x0800)
+#define MPI3_IOCFACTS_EXCEPT_SECURITY_KEY_MASK                (0x0700)
+#define MPI3_IOCFACTS_EXCEPT_SECURITY_KEY_NONE                (0x0000)
+#define MPI3_IOCFACTS_EXCEPT_SECURITY_KEY_LOCAL_VIA_RAID      (0x0100)
+#define MPI3_IOCFACTS_EXCEPT_SECURITY_KEY_LOCAL_VIA_OOB       (0x0200)
+#define MPI3_IOCFACTS_EXCEPT_SECURITY_KEY_EXT_VIA_RAID        (0x0300)
+#define MPI3_IOCFACTS_EXCEPT_SECURITY_KEY_EXT_VIA_OOB         (0x0400)
+#define MPI3_IOCFACTS_EXCEPT_PCIE_DISABLED                    (0x0080)
+#define MPI3_IOCFACTS_EXCEPT_PARTIAL_MEMORY_FAILURE           (0x0040)
+#define MPI3_IOCFACTS_EXCEPT_MANUFACT_CHECKSUM_FAIL           (0x0020)
+#define MPI3_IOCFACTS_EXCEPT_FW_CHECKSUM_FAIL                 (0x0010)
+#define MPI3_IOCFACTS_EXCEPT_CONFIG_CHECKSUM_FAIL             (0x0008)
+#define MPI3_IOCFACTS_EXCEPT_BOOTSTAT_MASK                    (0x0001)
+#define MPI3_IOCFACTS_EXCEPT_BOOTSTAT_PRIMARY                 (0x0000)
+#define MPI3_IOCFACTS_EXCEPT_BOOTSTAT_SECONDARY               (0x0001)
+
+/**** Defines for the ProtocolFlags field ****/
+#define MPI3_IOCFACTS_PROTOCOL_SAS                            (0x0010)
+#define MPI3_IOCFACTS_PROTOCOL_SATA                           (0x0008)
+#define MPI3_IOCFACTS_PROTOCOL_NVME                           (0x0004)
+#define MPI3_IOCFACTS_PROTOCOL_SCSI_INITIATOR                 (0x0002)
+#define MPI3_IOCFACTS_PROTOCOL_SCSI_TARGET                    (0x0001)
+
+/**** Defines for the Flags field ****/
+#define MPI3_IOCFACTS_FLAGS_SIGNED_NVDATA_REQUIRED            (0x00010000)
+#define MPI3_IOCFACTS_FLAGS_DMA_ADDRESS_WIDTH_MASK            (0x0000FF00)
+#define MPI3_IOCFACTS_FLAGS_DMA_ADDRESS_WIDTH_SHIFT           (8)
+#define MPI3_IOCFACTS_FLAGS_INITIAL_PORT_ENABLE_MASK          (0x00000030)
+#define MPI3_IOCFACTS_FLAGS_INITIAL_PORT_ENABLE_NOT_STARTED   (0x00000000)
+#define MPI3_IOCFACTS_FLAGS_INITIAL_PORT_ENABLE_IN_PROGRESS   (0x00000010)
+#define MPI3_IOCFACTS_FLAGS_INITIAL_PORT_ENABLE_COMPLETE      (0x00000020)
+#define MPI3_IOCFACTS_FLAGS_PERSONALITY_MASK                  (0x0000000F)
+#define MPI3_IOCFACTS_FLAGS_PERSONALITY_EHBA                  (0x00000000)
+#define MPI3_IOCFACTS_FLAGS_PERSONALITY_RAID_DDR              (0x00000002)
+
+
+/*****************************************************************************
+ *              Management Passthrough Request Message                      *
+ ****************************************************************************/
+typedef struct _MPI3_MGMT_PASSTHROUGH_REQUEST {
+    U16                 HostTag;                        /* 0x00 */
+    U8                  IOCUseOnly02;                   /* 0x02 */
+    U8                  Function;                       /* 0x03 */
+    U16                 IOCUseOnly04;                   /* 0x04 */
+    U8                  IOCUseOnly06;                   /* 0x06 */
+    U8                  MsgFlags;                       /* 0x07 */
+    U16                 ChangeCount;                    /* 0x08 */
+    U16                 Reserved0A;                     /* 0x0A */
+    U32                 Reserved0C[5];                  /* 0x0C */
+    MPI3_SGE_UNION      CommandSGL;                     /* 0x20 */
+    MPI3_SGE_UNION      ResponseSGL;                    /* 0x30 */
+} MPI3_MGMT_PASSTHROUGH_REQUEST, MPI3_POINTER PTR_MPI3_MGMT_PASSTHROUGH_REQUEST,
+  Mpi3MgmtPassthroughRequest_t, MPI3_POINTER pMpi3MgmtPassthroughRequest_t;
+
+/*****************************************************************************
+ *              CreateRequestQueue Request Message                        *
+ ****************************************************************************/
+typedef struct _MPI3_CREATE_REQUEST_QUEUE_REQUEST {
+    U16             HostTag;                            /* 0x00 */
+    U8              IOCUseOnly02;                       /* 0x02 */
+    U8              Function;                           /* 0x03 */
+    U16             IOCUseOnly04;                       /* 0x04 */
+    U8              IOCUseOnly06;                       /* 0x06 */
+    U8              MsgFlags;                           /* 0x07 */
+    U16             ChangeCount;                        /* 0x08 */
+    U8              Flags;                              /* 0x0A */
+    U8              Burst;                              /* 0x0B */
+    U16             Size;                               /* 0x0C */
+    U16             QueueID;                            /* 0x0E */
+    U16             ReplyQueueID;                       /* 0x10 */
+    U16             Reserved12;                         /* 0x12 */
+    U32             Reserved14;                         /* 0x14 */
+    U64             BaseAddress;                        /* 0x18 */
+} MPI3_CREATE_REQUEST_QUEUE_REQUEST, MPI3_POINTER PTR_MPI3_CREATE_REQUEST_QUEUE_REQUEST,
+  Mpi3CreateRequestQueueRequest_t, MPI3_POINTER pMpi3CreateRequestQueueRequest_t;
+
+/**** Defines for the Flags field ****/
+#define MPI3_CREATE_REQUEST_QUEUE_FLAGS_SEGMENTED_MASK          (0x80)
+#define MPI3_CREATE_REQUEST_QUEUE_FLAGS_SEGMENTED_SEGMENTED     (0x80)
+#define MPI3_CREATE_REQUEST_QUEUE_FLAGS_SEGMENTED_CONTIGUOUS    (0x00)
+
+
+/*****************************************************************************
+ *              DeleteRequestQueue Request Message                        *
+ ****************************************************************************/
+typedef struct _MPI3_DELETE_REQUEST_QUEUE_REQUEST {
+    U16             HostTag;                            /* 0x00 */
+    U8              IOCUseOnly02;                       /* 0x02 */
+    U8              Function;                           /* 0x03 */
+    U16             IOCUseOnly04;                       /* 0x04 */
+    U8              IOCUseOnly06;                       /* 0x06 */
+    U8              MsgFlags;                           /* 0x07 */
+    U16             ChangeCount;                        /* 0x08 */
+    U16             QueueID;                            /* 0x0A */
+} MPI3_DELETE_REQUEST_QUEUE_REQUEST, MPI3_POINTER PTR_MPI3_DELETE_REQUEST_QUEUE_REQUEST,
+  Mpi3DeleteRequestQueueRequest_t, MPI3_POINTER pMpi3DeleteRequestQueueRequest_t;
+
+
+/*****************************************************************************
+ *              CreateReplyQueue Request Message                          *
+ ****************************************************************************/
+typedef struct _MPI3_CREATE_REPLY_QUEUE_REQUEST {
+    U16             HostTag;                            /* 0x00 */
+    U8              IOCUseOnly02;                       /* 0x02 */
+    U8              Function;                           /* 0x03 */
+    U16             IOCUseOnly04;                       /* 0x04 */
+    U8              IOCUseOnly06;                       /* 0x06 */
+    U8              MsgFlags;                           /* 0x07 */
+    U16             ChangeCount;                        /* 0x08 */
+    U8              Flags;                              /* 0x0A */
+    U8              Reserved0B;                         /* 0x0B */
+    U16             Size;                               /* 0x0C */
+    U16             QueueID;                            /* 0x0E */
+    U16             MSIxIndex;                          /* 0x10 */
+    U16             Reserved12;                         /* 0x12 */
+    U32             Reserved14;                         /* 0x14 */
+    U64             BaseAddress;                        /* 0x18 */
+} MPI3_CREATE_REPLY_QUEUE_REQUEST, MPI3_POINTER PTR_MPI3_CREATE_REPLY_QUEUE_REQUEST,
+  Mpi3CreateReplyQueueRequest_t, MPI3_POINTER pMpi3CreateReplyQueueRequest_t;
+
+/**** Defines for the Flags field ****/
+#define MPI3_CREATE_REPLY_QUEUE_FLAGS_SEGMENTED_MASK            (0x80)
+#define MPI3_CREATE_REPLY_QUEUE_FLAGS_SEGMENTED_SEGMENTED       (0x80)
+#define MPI3_CREATE_REPLY_QUEUE_FLAGS_SEGMENTED_CONTIGUOUS      (0x00)
+#define MPI3_CREATE_REPLY_QUEUE_FLAGS_INT_ENABLE_MASK           (0x01)
+#define MPI3_CREATE_REPLY_QUEUE_FLAGS_INT_ENABLE_DISABLE        (0x00)
+#define MPI3_CREATE_REPLY_QUEUE_FLAGS_INT_ENABLE_ENABLE         (0x01)
+
+
+/*****************************************************************************
+ *              DeleteReplyQueue Request Message                          *
+ ****************************************************************************/
+typedef struct _MPI3_DELETE_REPLY_QUEUE_REQUEST {
+    U16             HostTag;                            /* 0x00 */
+    U8              IOCUseOnly02;                       /* 0x02 */
+    U8              Function;                           /* 0x03 */
+    U16             IOCUseOnly04;                       /* 0x04 */
+    U8              IOCUseOnly06;                       /* 0x06 */
+    U8              MsgFlags;                           /* 0x07 */
+    U16             ChangeCount;                        /* 0x08 */
+    U16             QueueID;                            /* 0x0A */
+} MPI3_DELETE_REPLY_QUEUE_REQUEST, MPI3_POINTER PTR_MPI3_DELETE_REPLY_QUEUE_REQUEST,
+  Mpi3DeleteReplyQueueRequest_t, MPI3_POINTER pMpi3DeleteReplyQueueRequest_t;
+
+
+/*****************************************************************************
+ *              PortEnable Request Message                                   *
+ ****************************************************************************/
+typedef struct _MPI3_PORT_ENABLE_REQUEST {
+    U16             HostTag;                            /* 0x00 */
+    U8              IOCUseOnly02;                       /* 0x02 */
+    U8              Function;                           /* 0x03 */
+    U16             IOCUseOnly04;                       /* 0x04 */
+    U8              IOCUseOnly06;                       /* 0x06 */
+    U8              MsgFlags;                           /* 0x07 */
+    U16             ChangeCount;                        /* 0x08 */
+    U16             Reserved0A;                         /* 0x0A */
+} MPI3_PORT_ENABLE_REQUEST, MPI3_POINTER PTR_MPI3_PORT_ENABLE_REQUEST,
+  Mpi3PortEnableRequest_t, MPI3_POINTER pMpi3PortEnableRequest_t;
+
+
+/*****************************************************************************
+ *              IOC Events and Event Management                              *
+ ****************************************************************************/
+#define MPI3_EVENT_LOG_DATA                         (0x01)
+#define MPI3_EVENT_CHANGE                           (0x02)
+#define MPI3_EVENT_GPIO_INTERRUPT                   (0x04)
+#define MPI3_EVENT_TEMP_THRESHOLD                   (0x05)
+#define MPI3_EVENT_CABLE_MGMT                       (0x06)
+#define MPI3_EVENT_DEVICE_ADDED                     (0x07)
+#define MPI3_EVENT_DEVICE_INFO_CHANGED              (0x08)
+#define MPI3_EVENT_PREPARE_FOR_RESET                (0x09)
+#define MPI3_EVENT_COMP_IMAGE_ACT_START             (0x0A)
+#define MPI3_EVENT_ENCL_DEVICE_ADDED                (0x0B)
+#define MPI3_EVENT_ENCL_DEVICE_STATUS_CHANGE        (0x0C)
+#define MPI3_EVENT_DEVICE_STATUS_CHANGE             (0x0D)
+#define MPI3_EVENT_ENERGY_PACK_CHANGE               (0x0E)
+#define MPI3_EVENT_SAS_DISCOVERY                    (0x11)
+#define MPI3_EVENT_SAS_BROADCAST_PRIMITIVE          (0x12)
+#define MPI3_EVENT_SAS_NOTIFY_PRIMITIVE             (0x13)
+#define MPI3_EVENT_SAS_INIT_DEVICE_STATUS_CHANGE    (0x14)
+#define MPI3_EVENT_SAS_INIT_TABLE_OVERFLOW          (0x15)
+#define MPI3_EVENT_SAS_TOPOLOGY_CHANGE_LIST         (0x16)
+#define MPI3_EVENT_SAS_PHY_COUNTER                  (0x18)
+#define MPI3_EVENT_SAS_DEVICE_DISCOVERY_ERROR       (0x19)
+#define MPI3_EVENT_PCIE_TOPOLOGY_CHANGE_LIST        (0x20)
+#define MPI3_EVENT_PCIE_ENUMERATION                 (0x22)
+#define MPI3_EVENT_HARD_RESET_RECEIVED              (0x40)
+#define MPI3_EVENT_MIN_PRODUCT_SPECIFIC             (0x60)
+#define MPI3_EVENT_MAX_PRODUCT_SPECIFIC             (0x7F)
+
+
+/*****************************************************************************
+ *              Event Notification Request Message                           *
+ ****************************************************************************/
+#define MPI3_EVENT_NOTIFY_EVENTMASK_WORDS           (4)
+
+typedef struct _MPI3_EVENT_NOTIFICATION_REQUEST {
+    U16             HostTag;                                            /* 0x00 */
+    U8              IOCUseOnly02;                                       /* 0x02 */
+    U8              Function;                                           /* 0x03 */
+    U16             IOCUseOnly04;                                       /* 0x04 */
+    U8              IOCUseOnly06;                                       /* 0x06 */
+    U8              MsgFlags;                                           /* 0x07 */
+    U16             ChangeCount;                                        /* 0x08 */
+    U16             Reserved0A;                                         /* 0x0A */
+    U16             SASBroadcastPrimitiveMasks;                         /* 0x0C */
+    U16             SASNotifyPrimitiveMasks;                            /* 0x0E */
+    U32             EventMasks[MPI3_EVENT_NOTIFY_EVENTMASK_WORDS];      /* 0x10 */
+} MPI3_EVENT_NOTIFICATION_REQUEST, MPI3_POINTER PTR_MPI3_EVENT_NOTIFICATION_REQUEST,
+  Mpi3EventNotificationRequest_t, MPI3_POINTER pMpi3EventNotificationRequest_t;
+
+/**** Defines for the SASBroadcastPrimitiveMasks field - use MPI3_EVENT_PRIMITIVE_ values ****/
+
+/**** Defines for the SASNotifyPrimitiveMasks field - use MPI3_EVENT_NOTIFY_ values ****/
+
+/**** Defines for the EventMasks field - use MPI3_EVENT_ values ****/
+
+/*****************************************************************************
+ *              Event Notification Reply Message                             *
+ ****************************************************************************/
+typedef struct _MPI3_EVENT_NOTIFICATION_REPLY {
+    U16             HostTag;                /* 0x00 */
+    U8              IOCUseOnly02;           /* 0x02 */
+    U8              Function;               /* 0x03 */
+    U16             IOCUseOnly04;           /* 0x04 */
+    U8              IOCUseOnly06;           /* 0x06 */
+    U8              MsgFlags;               /* 0x07 */
+    U16             IOCUseOnly08;           /* 0x08 */
+    U16             IOCStatus;              /* 0x0A */
+    U32             IOCLogInfo;             /* 0x0C */
+    U8              EventDataLength;        /* 0x10 */
+    U8              Event;                  /* 0x11 */
+    U16             IOCChangeCount;         /* 0x12 */
+    U32             EventContext;           /* 0x14 */
+    U32             EventData[1];           /* 0x18 */
+} MPI3_EVENT_NOTIFICATION_REPLY, MPI3_POINTER PTR_MPI3_EVENT_NOTIFICATION_REPLY,
+  Mpi3EventNotificationReply_t, MPI3_POINTER pMpi3EventNotificationReply_t;
+
+/**** Defines for the MsgFlags field ****/
+#define MPI3_EVENT_NOTIFY_MSGFLAGS_ACK_MASK                        (0x01)
+#define MPI3_EVENT_NOTIFY_MSGFLAGS_ACK_REQUIRED                    (0x01)
+#define MPI3_EVENT_NOTIFY_MSGFLAGS_ACK_NOT_REQUIRED                (0x00)
+#define MPI3_EVENT_NOTIFY_MSGFLAGS_EVENT_ORIGINALITY_MASK          (0x02)
+#define MPI3_EVENT_NOTIFY_MSGFLAGS_EVENT_ORIGINALITY_ORIGINAL      (0x00)
+#define MPI3_EVENT_NOTIFY_MSGFLAGS_EVENT_ORIGINALITY_REPLAY        (0x02)
+
+/**** Defines for the Event field - use MPI3_EVENT_ values ****/
+
+
+/*****************************************************************************
+ *              GPIO Interrupt Event                                         *
+ ****************************************************************************/
+typedef struct _MPI3_EVENT_DATA_GPIO_INTERRUPT {
+    U8              GPIONum;            /* 0x00 */
+    U8              Reserved01[3];      /* 0x01 */
+} MPI3_EVENT_DATA_GPIO_INTERRUPT, MPI3_POINTER PTR_MPI3_EVENT_DATA_GPIO_INTERRUPT,
+  Mpi3EventDataGpioInterrupt_t, MPI3_POINTER pMpi3EventDataGpioInterrupt_t;
+
+
+/*****************************************************************************
+ *              Temperature Threshold Event                                  *
+ ****************************************************************************/
+typedef struct _MPI3_EVENT_DATA_TEMP_THRESHOLD {
+    U16             Status;                 /* 0x00 */
+    U8              SensorNum;              /* 0x02 */
+    U8              Reserved03;             /* 0x03 */
+    U16             CurrentTemperature;     /* 0x04 */
+    U16             Reserved06;             /* 0x06 */
+    U32             Reserved08;             /* 0x08 */
+    U32             Reserved0C;             /* 0x0C */
+} MPI3_EVENT_DATA_TEMP_THRESHOLD, MPI3_POINTER PTR_MPI3_EVENT_DATA_TEMP_THRESHOLD,
+  Mpi3EventDataTempThreshold_t, MPI3_POINTER pMpi3EventDataTempThreshold_t;
+
+/**** Defines for the Status field ****/
+#define MPI3_EVENT_TEMP_THRESHOLD_STATUS_THRESHOLD3_EXCEEDED         (0x0008)
+#define MPI3_EVENT_TEMP_THRESHOLD_STATUS_THRESHOLD2_EXCEEDED         (0x0004)
+#define MPI3_EVENT_TEMP_THRESHOLD_STATUS_THRESHOLD1_EXCEEDED         (0x0002)
+#define MPI3_EVENT_TEMP_THRESHOLD_STATUS_THRESHOLD0_EXCEEDED         (0x0001)
+
+
+/*****************************************************************************
+ *              Cable Management Event                                       *
+ ****************************************************************************/
+typedef struct _MPI3_EVENT_DATA_CABLE_MANAGEMENT {
+    U32             ActiveCablePowerRequirement;    /* 0x00 */
+    U8              Status;                         /* 0x04 */
+    U8              ReceptacleID;                   /* 0x05 */
+    U16             Reserved06;                     /* 0x06 */
+} MPI3_EVENT_DATA_CABLE_MANAGEMENT, MPI3_POINTER PTR_MPI3_EVENT_DATA_CABLE_MANAGEMENT,
+  Mpi3EventDataCableManagement_t, MPI3_POINTER pMpi3EventDataCableManagement_t;
+
+/**** Defines for the ActiveCablePowerRequirement field ****/
+#define MPI3_EVENT_CABLE_MGMT_ACT_CABLE_PWR_INVALID     (0xFFFFFFFF)
+
+/**** Defines for the Status field ****/
+#define MPI3_EVENT_CABLE_MGMT_STATUS_INSUFFICIENT_POWER        (0x00)
+#define MPI3_EVENT_CABLE_MGMT_STATUS_PRESENT                   (0x01)
+#define MPI3_EVENT_CABLE_MGMT_STATUS_DEGRADED                  (0x02)
+
+
+/*****************************************************************************
+ *              Event Ack Request Message                                    *
+ ****************************************************************************/
+typedef struct _MPI3_EVENT_ACK_REQUEST {
+    U16             HostTag;            /* 0x00 */
+    U8              IOCUseOnly02;       /* 0x02 */
+    U8              Function;           /* 0x03 */
+    U16             IOCUseOnly04;       /* 0x04 */
+    U8              IOCUseOnly06;       /* 0x06 */
+    U8              MsgFlags;           /* 0x07 */
+    U16             ChangeCount;        /* 0x08 */
+    U16             Reserved0A;         /* 0x0A */
+    U8              Event;              /* 0x0C */
+    U8              Reserved0D[3];      /* 0x0D */
+    U32             EventContext;       /* 0x10 */
+} MPI3_EVENT_ACK_REQUEST, MPI3_POINTER PTR_MPI3_EVENT_ACK_REQUEST,
+  Mpi3EventAckRequest_t, MPI3_POINTER pMpi3EventAckRequest_t;
+
+/**** Defines for the Event field - use MPI3_EVENT_ values ****/
+
+
+/*****************************************************************************
+ *              Prepare for Reset Event                                      *
+ ****************************************************************************/
+typedef struct _MPI3_EVENT_DATA_PREPARE_FOR_RESET {
+    U8              ReasonCode;         /* 0x00 */
+    U8              Reserved01;         /* 0x01 */
+    U16             Reserved02;         /* 0x02 */
+} MPI3_EVENT_DATA_PREPARE_FOR_RESET, MPI3_POINTER PTR_MPI3_EVENT_DATA_PREPARE_FOR_RESET,
+  Mpi3EventDataPrepareForReset_t, MPI3_POINTER pMpi3EventDataPrepareForReset_t;
+
+/**** Defines for the ReasonCode field ****/
+#define MPI3_EVENT_PREPARE_RESET_RC_START                (0x01)
+#define MPI3_EVENT_PREPARE_RESET_RC_ABORT                (0x02)
+
+
+/*****************************************************************************
+ *              Component Image Activation Start Event                       *
+ ****************************************************************************/
+typedef struct _MPI3_EVENT_DATA_COMP_IMAGE_ACTIVATION {
+    U32            Reserved00;         /* 0x00 */
+} MPI3_EVENT_DATA_COMP_IMAGE_ACTIVATION, MPI3_POINTER PTR_MPI3_EVENT_DATA_COMP_IMAGE_ACTIVATION,
+  Mpi3EventDataCompImageActivation, MPI3_POINTER pMpi3EventDataCompImageActivation;
+
+/*****************************************************************************
+ *              Device Added Event                                           *
+ ****************************************************************************/
+/*
+ * The Device Added Event Data is exactly the same as Device Page 0 data
+ * (including the Configuration Page header). So, please use/refer to
+ * MPI3_DEVICE_PAGE0  structure for Device Added Event data.
+ */
+
+/****************************************************************************
+ *              Device Info Changed Event                                   *
+ ****************************************************************************/
+/*
+ * The Device Info Changed Event Data is exactly the same as Device Page 0 data
+ * (including the Configuration Page header). So, please use/refer to
+ * MPI3_DEVICE_PAGE0  structure for Device Added Event data.
+ */
+
+/*****************************************************************************
+ *              Device Status Change Event                                  *
+ ****************************************************************************/
+typedef struct _MPI3_EVENT_DATA_DEVICE_STATUS_CHANGE {
+    U16             TaskTag;            /* 0x00 */
+    U8              ReasonCode;         /* 0x02 */
+    U8              IOUnitPort;         /* 0x03 */
+    U16             ParentDevHandle;    /* 0x04 */
+    U16             DevHandle;          /* 0x06 */
+    U64             WWID;               /* 0x08 */
+    U8              LUN[8];             /* 0x10 */
+} MPI3_EVENT_DATA_DEVICE_STATUS_CHANGE, MPI3_POINTER PTR_MPI3_EVENT_DATA_DEVICE_STATUS_CHANGE,
+  Mpi3EventDataDeviceStatusChange_t, MPI3_POINTER pMpi3EventDataDeviceStatusChange_t;
+
+/**** Defines for the ReasonCode field ****/
+#define MPI3_EVENT_DEV_STAT_RC_MOVED                                (0x01)
+#define MPI3_EVENT_DEV_STAT_RC_HIDDEN                               (0x02)
+#define MPI3_EVENT_DEV_STAT_RC_NOT_HIDDEN                           (0x03)
+#define MPI3_EVENT_DEV_STAT_RC_ASYNC_NOTIFICATION                   (0x04)
+#define MPI3_EVENT_DEV_STAT_RC_INT_DEVICE_RESET_STRT                (0x20)
+#define MPI3_EVENT_DEV_STAT_RC_INT_DEVICE_RESET_CMP                 (0x21)
+#define MPI3_EVENT_DEV_STAT_RC_INT_TASK_ABORT_STRT                  (0x22)
+#define MPI3_EVENT_DEV_STAT_RC_INT_TASK_ABORT_CMP                   (0x23)
+#define MPI3_EVENT_DEV_STAT_RC_INT_IT_NEXUS_RESET_STRT              (0x24)
+#define MPI3_EVENT_DEV_STAT_RC_INT_IT_NEXUS_RESET_CMP               (0x25)
+#define MPI3_EVENT_DEV_STAT_RC_PCIE_HOT_RESET_FAILED                (0x30)
+#define MPI3_EVENT_DEV_STAT_RC_EXPANDER_REDUCED_FUNC_STRT           (0x40)
+#define MPI3_EVENT_DEV_STAT_RC_EXPANDER_REDUCED_FUNC_CMP            (0x41)
+#define MPI3_EVENT_DEV_STAT_RC_VD_NOT_RESPONDING                    (0x50)
+
+/*****************************************************************************
+ *              Energy Pack Change Event                                    *
+ ****************************************************************************/
+typedef struct _MPI3_EVENT_DATA_ENERGY_PACK_CHANGE {
+    U32             Reserved00;         /* 0x00 */
+    U16             ShutdownTimeout;    /* 0x04 */
+    U16             Reserved06;         /* 0x06 */
+} MPI3_EVENT_DATA_ENERGY_PACK_CHANGE, MPI3_POINTER PTR_MPI3_EVENT_DATA_ENERGY_PACK_CHANGE,
+  Mpi3EventDataEnergyPackChange_t, MPI3_POINTER pMpi3EventDataEnergyPackChange_t;
+
+/*****************************************************************************
+ *              SAS Discovery Event                                          *
+ ****************************************************************************/
+typedef struct _MPI3_EVENT_DATA_SAS_DISCOVERY {
+    U8              Flags;              /* 0x00 */
+    U8              ReasonCode;         /* 0x01 */
+    U8              IOUnitPort;         /* 0x02 */
+    U8              Reserved03;         /* 0x03 */
+    U32             DiscoveryStatus;    /* 0x04 */
+} MPI3_EVENT_DATA_SAS_DISCOVERY, MPI3_POINTER PTR_MPI3_EVENT_DATA_SAS_DISCOVERY,
+  Mpi3EventDataSasDiscovery_t, MPI3_POINTER pMpi3EventDataSasDiscovery_t;
+
+/**** Defines for the Flags field ****/
+#define MPI3_EVENT_SAS_DISC_FLAGS_DEVICE_CHANGE                 (0x02)
+#define MPI3_EVENT_SAS_DISC_FLAGS_IN_PROGRESS                   (0x01)
+
+/**** Defines for the ReasonCode field ****/
+#define MPI3_EVENT_SAS_DISC_RC_STARTED                          (0x01)
+#define MPI3_EVENT_SAS_DISC_RC_COMPLETED                        (0x02)
+
+/**** Defines for the DiscoveryStatus field ****/
+#define MPI3_SAS_DISC_STATUS_MAX_ENCLOSURES_EXCEED            (0x80000000)
+#define MPI3_SAS_DISC_STATUS_MAX_EXPANDERS_EXCEED             (0x40000000)
+#define MPI3_SAS_DISC_STATUS_MAX_DEVICES_EXCEED               (0x20000000)
+#define MPI3_SAS_DISC_STATUS_MAX_TOPO_PHYS_EXCEED             (0x10000000)
+#define MPI3_SAS_DISC_STATUS_MULTIPLE_DEVICES_IN_SLOT         (0x00004000)
+#define MPI3_SAS_DISC_STATUS_SLOT_COUNT_MISMATCH              (0x00002000)
+#define MPI3_SAS_DISC_STATUS_TOO_MANY_SLOTS                   (0x00001000)
+#define MPI3_SAS_DISC_STATUS_EXP_MULTI_SUBTRACTIVE            (0x00000800)
+#define MPI3_SAS_DISC_STATUS_MULTI_PORT_DOMAIN                (0x00000400)
+#define MPI3_SAS_DISC_STATUS_TABLE_TO_SUBTRACTIVE_LINK        (0x00000200)
+#define MPI3_SAS_DISC_STATUS_UNSUPPORTED_DEVICE               (0x00000100)
+#define MPI3_SAS_DISC_STATUS_TABLE_LINK                       (0x00000080)
+#define MPI3_SAS_DISC_STATUS_SUBTRACTIVE_LINK                 (0x00000040)
+#define MPI3_SAS_DISC_STATUS_SMP_CRC_ERROR                    (0x00000020)
+#define MPI3_SAS_DISC_STATUS_SMP_FUNCTION_FAILED              (0x00000010)
+#define MPI3_SAS_DISC_STATUS_SMP_TIMEOUT                      (0x00000008)
+#define MPI3_SAS_DISC_STATUS_MULTIPLE_PORTS                   (0x00000004)
+#define MPI3_SAS_DISC_STATUS_INVALID_SAS_ADDRESS              (0x00000002)
+#define MPI3_SAS_DISC_STATUS_LOOP_DETECTED                    (0x00000001)
+
+
+/*****************************************************************************
+ *              SAS Broadcast Primitive Event                                *
+ ****************************************************************************/
+typedef struct _MPI3_EVENT_DATA_SAS_BROADCAST_PRIMITIVE {
+    U8              PhyNum;         /* 0x00 */
+    U8              IOUnitPort;     /* 0x01 */
+    U8              PortWidth;      /* 0x02 */
+    U8              Primitive;      /* 0x03 */
+} MPI3_EVENT_DATA_SAS_BROADCAST_PRIMITIVE, MPI3_POINTER PTR_MPI3_EVENT_DATA_SAS_BROADCAST_PRIMITIVE,
+  Mpi3EventDataSasBroadcastPrimitive_t, MPI3_POINTER pMpi3EventDataSasBroadcastPrimitive_t;
+
+/**** Defines for the Primitive field ****/
+#define MPI3_EVENT_BROADCAST_PRIMITIVE_CHANGE                 (0x01)
+#define MPI3_EVENT_BROADCAST_PRIMITIVE_SES                    (0x02)
+#define MPI3_EVENT_BROADCAST_PRIMITIVE_EXPANDER               (0x03)
+#define MPI3_EVENT_BROADCAST_PRIMITIVE_ASYNCHRONOUS_EVENT     (0x04)
+#define MPI3_EVENT_BROADCAST_PRIMITIVE_RESERVED3              (0x05)
+#define MPI3_EVENT_BROADCAST_PRIMITIVE_RESERVED4              (0x06)
+#define MPI3_EVENT_BROADCAST_PRIMITIVE_CHANGE0_RESERVED       (0x07)
+#define MPI3_EVENT_BROADCAST_PRIMITIVE_CHANGE1_RESERVED       (0x08)
+
+
+/*****************************************************************************
+ *              SAS Notify Primitive Event                                   *
+ ****************************************************************************/
+typedef struct _MPI3_EVENT_DATA_SAS_NOTIFY_PRIMITIVE {
+    U8              PhyNum;         /* 0x00 */
+    U8              IOUnitPort;     /* 0x01 */
+    U8              Reserved02;     /* 0x02 */
+    U8              Primitive;      /* 0x03 */
+} MPI3_EVENT_DATA_SAS_NOTIFY_PRIMITIVE, MPI3_POINTER PTR_MPI3_EVENT_DATA_SAS_NOTIFY_PRIMITIVE,
+  Mpi3EventDataSasNotifyPrimitive_t, MPI3_POINTER pMpi3EventDataSasNotifyPrimitive_t;
+
+/**** Defines for the Primitive field ****/
+#define MPI3_EVENT_NOTIFY_PRIMITIVE_ENABLE_SPINUP         (0x01)
+#define MPI3_EVENT_NOTIFY_PRIMITIVE_POWER_LOSS_EXPECTED   (0x02)
+#define MPI3_EVENT_NOTIFY_PRIMITIVE_RESERVED1             (0x03)
+#define MPI3_EVENT_NOTIFY_PRIMITIVE_RESERVED2             (0x04)
+
+
+/*****************************************************************************
+ *              SAS Topology Change List Event                               *
+ ****************************************************************************/
+#ifndef MPI3_EVENT_SAS_TOPO_PHY_COUNT
+#define MPI3_EVENT_SAS_TOPO_PHY_COUNT           (1)
+#endif  /* MPI3_EVENT_SAS_TOPO_PHY_COUNT */
+
+typedef struct _MPI3_EVENT_SAS_TOPO_PHY_ENTRY {
+    U16             AttachedDevHandle;      /* 0x00 */
+    U8              LinkRate;               /* 0x02 */
+    U8              Status;                 /* 0x03 */
+} MPI3_EVENT_SAS_TOPO_PHY_ENTRY, MPI3_POINTER PTR_MPI3_EVENT_SAS_TOPO_PHY_ENTRY,
+  Mpi3EventSasTopoPhyEntry_t, MPI3_POINTER pMpi3EventSasTopoPhyEntry_t;
+
+/**** Defines for the LinkRate field ****/
+#define MPI3_EVENT_SAS_TOPO_LR_CURRENT_MASK                 (0xF0)
+#define MPI3_EVENT_SAS_TOPO_LR_CURRENT_SHIFT                (4)
+#define MPI3_EVENT_SAS_TOPO_LR_PREV_MASK                    (0x0F)
+#define MPI3_EVENT_SAS_TOPO_LR_PREV_SHIFT                   (0)
+#define MPI3_EVENT_SAS_TOPO_LR_UNKNOWN_LINK_RATE            (0x00)
+#define MPI3_EVENT_SAS_TOPO_LR_PHY_DISABLED                 (0x01)
+#define MPI3_EVENT_SAS_TOPO_LR_NEGOTIATION_FAILED           (0x02)
+#define MPI3_EVENT_SAS_TOPO_LR_SATA_OOB_COMPLETE            (0x03)
+#define MPI3_EVENT_SAS_TOPO_LR_PORT_SELECTOR                (0x04)
+#define MPI3_EVENT_SAS_TOPO_LR_SMP_RESET_IN_PROGRESS        (0x05)
+#define MPI3_EVENT_SAS_TOPO_LR_UNSUPPORTED_PHY              (0x06)
+#define MPI3_EVENT_SAS_TOPO_LR_RATE_6_0                     (0x0A)
+#define MPI3_EVENT_SAS_TOPO_LR_RATE_12_0                    (0x0B)
+#define MPI3_EVENT_SAS_TOPO_LR_RATE_22_5                    (0x0C)
+
+/**** Defines for the PhyStatus field ****/
+#define MPI3_EVENT_SAS_TOPO_PHY_STATUS_MASK                 (0xC0)
+#define MPI3_EVENT_SAS_TOPO_PHY_STATUS_SHIFT                (6)
+#define MPI3_EVENT_SAS_TOPO_PHY_STATUS_ACCESSIBLE           (0x00)
+#define MPI3_EVENT_SAS_TOPO_PHY_STATUS_NO_EXIST             (0x40)
+#define MPI3_EVENT_SAS_TOPO_PHY_STATUS_VACANT               (0x80)
+#define MPI3_EVENT_SAS_TOPO_PHY_RC_MASK                     (0x0F)
+#define MPI3_EVENT_SAS_TOPO_PHY_RC_TARG_NOT_RESPONDING      (0x02)
+#define MPI3_EVENT_SAS_TOPO_PHY_RC_PHY_CHANGED              (0x03)
+#define MPI3_EVENT_SAS_TOPO_PHY_RC_NO_CHANGE                (0x04)
+#define MPI3_EVENT_SAS_TOPO_PHY_RC_DELAY_NOT_RESPONDING     (0x05)
+#define MPI3_EVENT_SAS_TOPO_PHY_RC_RESPONDING               (0x06)
+
+
+typedef struct _MPI3_EVENT_DATA_SAS_TOPOLOGY_CHANGE_LIST {
+    U16                             EnclosureHandle;                            /* 0x00 */
+    U16                             ExpanderDevHandle;                          /* 0x02 */
+    U8                              NumPhys;                                    /* 0x04 */
+    U8                              Reserved05[3];                              /* 0x05 */
+    U8                              NumEntries;                                 /* 0x08 */
+    U8                              StartPhyNum;                                /* 0x09 */
+    U8                              ExpStatus;                                  /* 0x0A */
+    U8                              IOUnitPort;                                 /* 0x0B */
+    MPI3_EVENT_SAS_TOPO_PHY_ENTRY   PhyEntry[MPI3_EVENT_SAS_TOPO_PHY_COUNT];    /* 0x0C */
+} MPI3_EVENT_DATA_SAS_TOPOLOGY_CHANGE_LIST, MPI3_POINTER PTR_MPI3_EVENT_DATA_SAS_TOPOLOGY_CHANGE_LIST,
+  Mpi3EventDataSasTopologyChangeList_t, MPI3_POINTER pMpi3EventDataSasTopologyChangeList_t;
+
+/**** Defines for the ExpStatus field ****/
+#define MPI3_EVENT_SAS_TOPO_ES_NO_EXPANDER              (0x00)
+#define MPI3_EVENT_SAS_TOPO_ES_NOT_RESPONDING           (0x02)
+#define MPI3_EVENT_SAS_TOPO_ES_RESPONDING               (0x03)
+#define MPI3_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING     (0x04)
+
+/*****************************************************************************
+ *              SAS PHY Counter Event                                        *
+ ****************************************************************************/
+typedef struct _MPI3_EVENT_DATA_SAS_PHY_COUNTER {
+    U64             TimeStamp;              /* 0x00 */
+    U32             Reserved08;             /* 0x08 */
+    U8              PhyEventCode;           /* 0x0C */
+    U8              PhyNum;                 /* 0x0D */
+    U16             Reserved0E;             /* 0x0E */
+    U32             PhyEventInfo;           /* 0x10 */
+    U8              CounterType;            /* 0x14 */
+    U8              ThresholdWindow;        /* 0x15 */
+    U8              TimeUnits;              /* 0x16 */
+    U8              Reserved17;             /* 0x17 */
+    U32             EventThreshold;         /* 0x18 */
+    U16             ThresholdFlags;         /* 0x1C */
+    U16             Reserved1E;             /* 0x1E */
+} MPI3_EVENT_DATA_SAS_PHY_COUNTER, MPI3_POINTER PTR_MPI3_EVENT_DATA_SAS_PHY_COUNTER,
+  Mpi3EventDataSasPhyCounter_t, MPI3_POINTER pMpi3EventDataSasPhyCounter_t;
+
+/**** Defines for the PhyEventCode field - use MPI3_SASPHY3_EVENT_CODE_ defines ****/
+
+/**** Defines for the CounterType field - use MPI3_SASPHY3_COUNTER_TYPE_ defines ****/
+
+/**** Defines for the TimeUnits field - use MPI3_SASPHY3_TIME_UNITS_ defines ****/
+
+/**** Defines for the ThresholdFlags field - use MPI3_SASPHY3_TFLAGS_ defines ****/
+
+
+/*****************************************************************************
+ *              SAS Device Discovery Error Event                             *
+ ****************************************************************************/
+typedef struct _MPI3_EVENT_DATA_SAS_DEVICE_DISC_ERR {
+    U16             DevHandle;              /* 0x00 */
+    U8              ReasonCode;             /* 0x02 */
+    U8              IOUnitPort;             /* 0x03 */
+    U32             Reserved04;             /* 0x04 */
+    U64             SASAddress;             /* 0x08 */
+} MPI3_EVENT_DATA_SAS_DEVICE_DISC_ERR, MPI3_POINTER PTR_MPI3_EVENT_DATA_SAS_DEVICE_DISC_ERR,
+  Mpi3EventDataSasDeviceDiscErr_t, MPI3_POINTER pMpi3EventDataSasDeviceDiscErr_t;
+
+/**** Defines for the ReasonCode field ****/
+#define MPI3_EVENT_SAS_DISC_ERR_RC_SMP_FAILED          (0x01)
+#define MPI3_EVENT_SAS_DISC_ERR_RC_SMP_TIMEOUT         (0x02)
+
+/*****************************************************************************
+ *              PCIe Enumeration Event                                       *
+ ****************************************************************************/
+typedef struct _MPI3_EVENT_DATA_PCIE_ENUMERATION {
+    U8              Flags;                  /* 0x00 */
+    U8              ReasonCode;             /* 0x01 */
+    U8              IOUnitPort;             /* 0x02 */
+    U8              Reserved03;             /* 0x03 */
+    U32             EnumerationStatus;      /* 0x04 */
+} MPI3_EVENT_DATA_PCIE_ENUMERATION, MPI3_POINTER PTR_MPI3_EVENT_DATA_PCIE_ENUMERATION,
+  Mpi3EventDataPcieEnumeration_t, MPI3_POINTER pMpi3EventDataPcieEnumeration_t;
+
+/**** Defines for the Flags field ****/
+#define MPI3_EVENT_PCIE_ENUM_FLAGS_DEVICE_CHANGE            (0x02)
+#define MPI3_EVENT_PCIE_ENUM_FLAGS_IN_PROGRESS              (0x01)
+
+/**** Defines for the ReasonCode field ****/
+#define MPI3_EVENT_PCIE_ENUM_RC_STARTED                     (0x01)
+#define MPI3_EVENT_PCIE_ENUM_RC_COMPLETED                   (0x02)
+
+/**** Defines for the EnumerationStatus field ****/
+#define MPI3_EVENT_PCIE_ENUM_ES_MAX_SWITCH_DEPTH_EXCEED     (0x80000000)
+#define MPI3_EVENT_PCIE_ENUM_ES_MAX_SWITCHES_EXCEED         (0x40000000)
+#define MPI3_EVENT_PCIE_ENUM_ES_MAX_DEVICES_EXCEED          (0x20000000)
+#define MPI3_EVENT_PCIE_ENUM_ES_RESOURCES_EXHAUSTED         (0x10000000)
+
+
+/*****************************************************************************
+ *              PCIe Topology Change List Event                              *
+ ****************************************************************************/
+#ifndef MPI3_EVENT_PCIE_TOPO_PORT_COUNT
+#define MPI3_EVENT_PCIE_TOPO_PORT_COUNT         (1)
+#endif  /* MPI3_EVENT_PCIE_TOPO_PORT_COUNT */
+
+typedef struct _MPI3_EVENT_PCIE_TOPO_PORT_ENTRY {
+    U16             AttachedDevHandle;      /* 0x00 */
+    U8              PortStatus;             /* 0x02 */
+    U8              Reserved03;             /* 0x03 */
+    U8              CurrentPortInfo;        /* 0x04 */
+    U8              Reserved05;             /* 0x05 */
+    U8              PreviousPortInfo;       /* 0x06 */
+    U8              Reserved07;             /* 0x07 */
+} MPI3_EVENT_PCIE_TOPO_PORT_ENTRY, MPI3_POINTER PTR_MPI3_EVENT_PCIE_TOPO_PORT_ENTRY,
+  Mpi3EventPcieTopoPortEntry_t, MPI3_POINTER pMpi3EventPcieTopoPortEntry_t;
+
+/**** Defines for the PortStatus field ****/
+#define MPI3_EVENT_PCIE_TOPO_PS_NOT_RESPONDING          (0x02)
+#define MPI3_EVENT_PCIE_TOPO_PS_PORT_CHANGED            (0x03)
+#define MPI3_EVENT_PCIE_TOPO_PS_NO_CHANGE               (0x04)
+#define MPI3_EVENT_PCIE_TOPO_PS_DELAY_NOT_RESPONDING    (0x05)
+#define MPI3_EVENT_PCIE_TOPO_PS_RESPONDING              (0x06)
+
+/**** Defines for the CurrentPortInfo and PreviousPortInfo field ****/
+#define MPI3_EVENT_PCIE_TOPO_PI_LANES_MASK              (0xF0)
+#define MPI3_EVENT_PCIE_TOPO_PI_LANES_UNKNOWN           (0x00)
+#define MPI3_EVENT_PCIE_TOPO_PI_LANES_1                 (0x10)
+#define MPI3_EVENT_PCIE_TOPO_PI_LANES_2                 (0x20)
+#define MPI3_EVENT_PCIE_TOPO_PI_LANES_4                 (0x30)
+#define MPI3_EVENT_PCIE_TOPO_PI_LANES_8                 (0x40)
+#define MPI3_EVENT_PCIE_TOPO_PI_LANES_16                (0x50)
+
+#define MPI3_EVENT_PCIE_TOPO_PI_RATE_MASK               (0x0F)
+#define MPI3_EVENT_PCIE_TOPO_PI_RATE_UNKNOWN            (0x00)
+#define MPI3_EVENT_PCIE_TOPO_PI_RATE_DISABLED           (0x01)
+#define MPI3_EVENT_PCIE_TOPO_PI_RATE_2_5                (0x02)
+#define MPI3_EVENT_PCIE_TOPO_PI_RATE_5_0                (0x03)
+#define MPI3_EVENT_PCIE_TOPO_PI_RATE_8_0                (0x04)
+#define MPI3_EVENT_PCIE_TOPO_PI_RATE_16_0               (0x05)
+#define MPI3_EVENT_PCIE_TOPO_PI_RATE_32_0               (0x06)
+
+typedef struct _MPI3_EVENT_DATA_PCIE_TOPOLOGY_CHANGE_LIST {
+    U16                                 EnclosureHandle;                                /* 0x00 */
+    U16                                 SwitchDevHandle;                                /* 0x02 */
+    U8                                  NumPorts;                                       /* 0x04 */
+    U8                                  Reserved05[3];                                  /* 0x05 */
+    U8                                  NumEntries;                                     /* 0x08 */
+    U8                                  StartPortNum;                                   /* 0x09 */
+    U8                                  SwitchStatus;                                   /* 0x0A */
+    U8                                  IOUnitPort;                                     /* 0x0B */
+    U32                                 Reserved0C;                                     /* 0x0C */
+    MPI3_EVENT_PCIE_TOPO_PORT_ENTRY     PortEntry[MPI3_EVENT_PCIE_TOPO_PORT_COUNT];     /* 0x10 */
+} MPI3_EVENT_DATA_PCIE_TOPOLOGY_CHANGE_LIST, MPI3_POINTER PTR_MPI3_EVENT_DATA_PCIE_TOPOLOGY_CHANGE_LIST,
+  Mpi3EventDataPcieTopologyChangeList_t, MPI3_POINTER pMpi3EventDataPcieTopologyChangeList_t;
+
+/**** Defines for the SwitchStatus field ****/
+#define MPI3_EVENT_PCIE_TOPO_SS_NO_PCIE_SWITCH          (0x00)
+#define MPI3_EVENT_PCIE_TOPO_SS_NOT_RESPONDING          (0x02)
+#define MPI3_EVENT_PCIE_TOPO_SS_RESPONDING              (0x03)
+#define MPI3_EVENT_PCIE_TOPO_SS_DELAY_NOT_RESPONDING    (0x04)
+
+/****************************************************************************
+ *              Enclosure Device Added Event                                *
+ ****************************************************************************/
+/*
+ * The Enclosure Device Added Event Data is exactly the same as Enclosure
+ *  Page 0 data (including the Configuration Page header). So, please
+ *  use/refer to MPI3_ENCLOSURE_PAGE0  structure for Enclosure Device Added
+ *  Event data.
+ */
+
+/****************************************************************************
+ *              Enclosure Device Changed Event                              *
+ ****************************************************************************/
+/*
+ * The Enclosure Device Change Event Data is exactly the same as Enclosure
+ *  Page 0 data (including the Configuration Page header). So, please
+ *  use/refer to MPI3_ENCLOSURE_PAGE0  structure for Enclosure Device Change
+ *  Event data.
+ */
+
+/*****************************************************************************
+ *              SAS Initiator Device Status Change Event                     *
+ ****************************************************************************/
+typedef struct _MPI3_EVENT_DATA_SAS_INIT_DEV_STATUS_CHANGE {
+    U8              ReasonCode;             /* 0x00 */
+    U8              IOUnitPort;             /* 0x01 */
+    U16             DevHandle;              /* 0x02 */
+    U32             Reserved04;             /* 0x04 */
+    U64             SASAddress;             /* 0x08 */
+} MPI3_EVENT_DATA_SAS_INIT_DEV_STATUS_CHANGE, MPI3_POINTER PTR_MPI3_EVENT_DATA_SAS_INIT_DEV_STATUS_CHANGE,
+  Mpi3EventDataSasInitDevStatusChange_t, MPI3_POINTER pMpi3EventDataSasInitDevStatusChange_t;
+
+/**** Defines for the ReasonCode field ****/
+#define MPI3_EVENT_SAS_INIT_RC_ADDED                (0x01)
+#define MPI3_EVENT_SAS_INIT_RC_NOT_RESPONDING       (0x02)
+
+
+/*****************************************************************************
+ *              SAS Initiator Device Table Overflow Event                    *
+ ****************************************************************************/
+typedef struct _MPI3_EVENT_DATA_SAS_INIT_TABLE_OVERFLOW {
+    U16             MaxInit;                /* 0x00 */
+    U16             CurrentInit;            /* 0x02 */
+    U32             Reserved04;             /* 0x04 */
+    U64             SASAddress;             /* 0x08 */
+} MPI3_EVENT_DATA_SAS_INIT_TABLE_OVERFLOW, MPI3_POINTER PTR_MPI3_EVENT_DATA_SAS_INIT_TABLE_OVERFLOW,
+  Mpi3EventDataSasInitTableOverflow_t, MPI3_POINTER pMpi3EventDataSasInitTableOverflow_t;
+
+
+/*****************************************************************************
+ *              Hard Reset Received Event                                    *
+ ****************************************************************************/
+typedef struct _MPI3_EVENT_DATA_HARD_RESET_RECEIVED {
+    U8              Reserved00;             /* 0x00 */
+    U8              IOUnitPort;             /* 0x01 */
+    U16             Reserved02;             /* 0x02 */
+} MPI3_EVENT_DATA_HARD_RESET_RECEIVED, MPI3_POINTER PTR_MPI3_EVENT_DATA_HARD_RESET_RECEIVED,
+  Mpi3EventDataHardResetReceived_t, MPI3_POINTER pMpi3EventDataHardResetReceived_t;
+
+
+/*****************************************************************************
+ *              Persistent Event Logs                                       *
+ ****************************************************************************/
+
+/**** Definitions for the Locale field ****/
+#define MPI3_PEL_LOCALE_FLAGS_NON_BLOCKING_BOOT_EVENT   (0x0200)
+#define MPI3_PEL_LOCALE_FLAGS_BLOCKING_BOOT_EVENT       (0x0100)
+#define MPI3_PEL_LOCALE_FLAGS_PCIE                      (0x0080)
+#define MPI3_PEL_LOCALE_FLAGS_CONFIGURATION             (0x0040)
+#define MPI3_PEL_LOCALE_FLAGS_CONTROLER                 (0x0020)
+#define MPI3_PEL_LOCALE_FLAGS_SAS                       (0x0010)
+#define MPI3_PEL_LOCALE_FLAGS_EPACK                     (0x0008)
+#define MPI3_PEL_LOCALE_FLAGS_ENCLOSURE                 (0x0004)
+#define MPI3_PEL_LOCALE_FLAGS_PD                        (0x0002)
+#define MPI3_PEL_LOCALE_FLAGS_VD                        (0x0001)
+
+/**** Definitions for the Class field ****/
+#define MPI3_PEL_CLASS_DEBUG                            (0x00)
+#define MPI3_PEL_CLASS_PROGRESS                         (0x01)
+#define MPI3_PEL_CLASS_INFORMATIONAL                    (0x02)
+#define MPI3_PEL_CLASS_WARNING                          (0x03)
+#define MPI3_PEL_CLASS_CRITICAL                         (0x04)
+#define MPI3_PEL_CLASS_FATAL                            (0x05)
+#define MPI3_PEL_CLASS_FAULT                            (0x06)
+
+/**** Definitions for the ClearType field ****/
+#define MPI3_PEL_CLEARTYPE_CLEAR                        (0x00)
+
+/**** Definitions for the WaitTime field ****/
+#define MPI3_PEL_WAITTIME_INFINITE_WAIT                 (0x00)
+
+/**** Definitions for the Action field ****/
+#define MPI3_PEL_ACTION_GET_SEQNUM                      (0x01)
+#define MPI3_PEL_ACTION_MARK_CLEAR                      (0x02)
+#define MPI3_PEL_ACTION_GET_LOG                         (0x03)
+#define MPI3_PEL_ACTION_GET_COUNT                       (0x04)
+#define MPI3_PEL_ACTION_WAIT                            (0x05)
+#define MPI3_PEL_ACTION_ABORT                           (0x06)
+#define MPI3_PEL_ACTION_GET_PRINT_STRINGS               (0x07)
+#define MPI3_PEL_ACTION_ACKNOWLEDGE                     (0x08)
+
+/**** Definitions for the LogStatus field ****/
+#define MPI3_PEL_STATUS_SUCCESS                         (0x00)
+#define MPI3_PEL_STATUS_NOT_FOUND                       (0x01)
+#define MPI3_PEL_STATUS_ABORTED                         (0x02)
+#define MPI3_PEL_STATUS_NOT_READY                       (0x03)
+
+/****************************************************************************
+ *              PEL Sequence Numbers                                        *
+ ****************************************************************************/
+typedef struct _MPI3_PEL_SEQ {
+    U32                             Newest;                                   /* 0x00 */
+    U32                             Oldest;                                   /* 0x04 */
+    U32                             Clear;                                    /* 0x08 */
+    U32                             Shutdown;                                 /* 0x0C */
+    U32                             Boot;                                     /* 0x10 */
+    U32                             LastAcknowledged;                         /* 0x14 */
+} MPI3_PEL_SEQ, MPI3_POINTER PTR_MPI3_PEL_SEQ,
+  Mpi3PELSeq_t, MPI3_POINTER pMpi3PELSeq_t;
+
+/****************************************************************************
+ *              PEL Entry                                                   *
+ ****************************************************************************/
+
+typedef struct _MPI3_PEL_ENTRY {
+    U32                             SequenceNumber;                                     /* 0x00 */
+    U32                             TimeStamp[2];                                       /* 0x04 */
+    U16                             LogCode;                                            /* 0x0C */
+    U16                             ArgType;                                            /* 0x0E */
+    U16                             Locale;                                             /* 0x10 */
+    U8                              Class;                                              /* 0x12 */
+    U8                              Reserved13;                                         /* 0x13 */
+    U8                              ExtNum;                                             /* 0x14 */
+    U8                              NumExts;                                            /* 0x15 */
+    U8                              ArgDataSize;                                        /* 0x16 */
+    U8                              FixedFormatSize;                                    /* 0x17 */
+    U32                             Reserved18[2];                                      /* 0x18 */
+    U32                             PELInfo[24];                                        /* 0x20 - 0x7F */
+} MPI3_PEL_ENTRY, MPI3_POINTER PTR_MPI3_PEL_ENTRY,
+  Mpi3PELEntry_t, MPI3_POINTER pMpi3PELEntry_t;
+
+/****************************************************************************
+ *              PEL Event List                                              *
+ ****************************************************************************/
+typedef struct _MPI3_PEL_LIST {
+    U32                             LogCount;                                 /* 0x00 */
+    U32                             Reserved04;                               /* 0x04 */
+    MPI3_PEL_ENTRY                  Entry[1];                                 /* 0x08 */  /* variable length */
+} MPI3_PEL_LIST, MPI3_POINTER PTR_MPI3_PEL_LIST,
+  Mpi3PELList_t, MPI3_POINTER pMpi3PELList_t;
+
+/****************************************************************************
+ *              PEL Count Data                                              *
+ ****************************************************************************/
+typedef U32 MPI3_PEL_LOG_COUNT, MPI3_POINTER PTR_MPI3_PEL_LOG_COUNT,
+	    Mpi3PELLogCount_t, MPI3_POINTER pMpi3PELLogCount_t;
+
+/****************************************************************************
+ *              PEL Arg Map                                                 *
+ ****************************************************************************/
+typedef struct _MPI3_PEL_ARG_MAP {
+    U8                              ArgType;                                 /* 0x00 */
+    U8                              Length;                                  /* 0x01 */
+    U16                             StartLocation;                           /* 0x02 */
+} MPI3_PEL_ARG_MAP, MPI3_POINTER PTR_MPI3_PEL_ARG_MAP,
+  Mpi3PELArgMap_t, MPI3_POINTER pMpi3PELArgMap_t;
+
+/**** Definitions for the ArgType field ****/
+#define MPI3_PEL_ARG_MAP_ARG_TYPE_APPEND_STRING                (0x00)
+#define MPI3_PEL_ARG_MAP_ARG_TYPE_INTEGER                      (0x01)
+#define MPI3_PEL_ARG_MAP_ARG_TYPE_STRING                       (0x02)
+#define MPI3_PEL_ARG_MAP_ARG_TYPE_BIT_FIELD                    (0x03)
+
+
+/****************************************************************************
+ *              PEL Print String                                            *
+ ****************************************************************************/
+typedef struct _MPI3_PEL_PRINT_STRING {
+    U16                             LogCode;                                  /* 0x00 */
+    U16                             StringLength;                             /* 0x02 */
+    U8                              NumArgMap;                                /* 0x04 */
+    U8                              Reserved05[3];                            /* 0x05 */
+    MPI3_PEL_ARG_MAP                ArgMap[1];                                /* 0x08 */  /* variable length */
+} MPI3_PEL_PRINT_STRING, MPI3_POINTER PTR_MPI3_PEL_PRINT_STRING,
+  Mpi3PELPrintString_t, MPI3_POINTER pMpi3PELPrintString_t;
+
+/****************************************************************************
+ *              PEL Print String List                                       *
+ ****************************************************************************/
+typedef struct _MPI3_PEL_PRINT_STRING_LIST {
+    U32                             NumPrintStrings;                           /* 0x00 */
+    U32                             ResidualBytesRemain;                       /* 0x04 */
+    U32                             Reserved08[2];                             /* 0x08 */
+    MPI3_PEL_PRINT_STRING           PrintString[1];                            /* 0x10 */  /* variable length */
+} MPI3_PEL_PRINT_STRING_LIST, MPI3_POINTER PTR_MPI3_PEL_PRINT_STRING_LIST,
+  Mpi3PELPrintStringList_t, MPI3_POINTER pMpi3PELPrintStringList_t;
+
+
+/****************************************************************************
+ *              PEL Request Msg - generic to allow header decoding          *
+ ****************************************************************************/
+#ifndef MPI3_PEL_ACTION_SPECIFIC_MAX
+#define MPI3_PEL_ACTION_SPECIFIC_MAX               (1)
+#endif  /* MPI3_PEL_ACTION_SPECIFIC_MAX */
+
+typedef struct _MPI3_PEL_REQUEST {
+    U16                             HostTag;                                         /* 0x00 */
+    U8                              IOCUseOnly02;                                    /* 0x02 */
+    U8                              Function;                                        /* 0x03 */
+    U16                             IOCUseOnly04;                                    /* 0x04 */
+    U8                              IOCUseOnly06;                                    /* 0x06 */
+    U8                              MsgFlags;                                        /* 0x07 */
+    U16                             ChangeCount;                                     /* 0x08 */
+    U8                              Action;                                          /* 0x0A */
+    U8                              Reserved0B;                                      /* 0x0B */
+    U32                             ActionSpecific[MPI3_PEL_ACTION_SPECIFIC_MAX];    /* 0x0C */  /* variable length */
+} MPI3_PEL_REQUEST, MPI3_POINTER PTR_MPI3_PEL_REQUEST,
+  Mpi3PELRequest_t, MPI3_POINTER pMpi3PELRequest_t;
+
+/****************************************************************************
+ *              PEL ACTION Get Sequence Nembers                             *
+ ****************************************************************************/
+typedef struct _MPI3_PEL_REQ_ACTION_GET_SEQUENCE_NUMBERS {
+    U16                             HostTag;                                  /* 0x00 */
+    U8                              IOCUseOnly02;                             /* 0x02 */
+    U8                              Function;                                 /* 0x03 */
+    U16                             IOCUseOnly04;                             /* 0x04 */
+    U8                              IOCUseOnly06;                             /* 0x06 */
+    U8                              MsgFlags;                                 /* 0x07 */
+    U16                             ChangeCount;                              /* 0x08 */
+    U8                              Action;                                   /* 0x0A */
+    U8                              Reserved0B;                               /* 0x0B */
+    U32                             Reserved0C[5];                            /* 0x0C */
+    MPI3_SGE_UNION                  SGL;                                      /* 0x20 */
+} MPI3_PEL_REQ_ACTION_GET_SEQUENCE_NUMBERS, MPI3_POINTER PTR_MPI3_PEL_REQ_ACTION_GET_SEQUENCE_NUMBERS,
+  Mpi3PELReqActionGetSequenceNumbers_t, MPI3_POINTER pMpi3PELReqActionGetSequenceNumbers_t;
+
+/****************************************************************************
+ *              PEL ACTION Clear Log                                        *
+ ****************************************************************************/
+typedef struct _MPI3_PEL_REQ_ACTION_CLEAR_LOG_MARKER {
+    U16                             HostTag;                                  /* 0x00 */
+    U8                              IOCUseOnly02;                             /* 0x02 */
+    U8                              Function;                                 /* 0x03 */
+    U16                             IOCUseOnly04;                             /* 0x04 */
+    U8                              IOCUseOnly06;                             /* 0x06 */
+    U8                              MsgFlags;                                 /* 0x07 */
+    U16                             ChangeCount;                              /* 0x08 */
+    U8                              Action;                                   /* 0x0A */
+    U8                              Reserved0B;                               /* 0x0B */
+    U8                              ClearType;                                /* 0x0C */
+    U8                              Reserved0D[3];                            /* 0x0D */
+} MPI3_PEL_REQ_ACTION_CLEAR_LOG_MARKER, MPI3_POINTER PTR_MPI3_PEL_REQ_ACTION_CLEAR_LOG_MARKER,
+  Mpi3PELReqActionClearLogMMarker_t, MPI3_POINTER pMpi3PELReqActionClearLogMMarker_t;
+
+/****************************************************************************
+ *              PEL ACTION Get Log                                          *
+ ****************************************************************************/
+typedef struct _MPI3_PEL_REQ_ACTION_GET_LOG {
+    U16                             HostTag;                                  /* 0x00 */
+    U8                              IOCUseOnly02;                             /* 0x02 */
+    U8                              Function;                                 /* 0x03 */
+    U16                             IOCUseOnly04;                             /* 0x04 */
+    U8                              IOCUseOnly06;                             /* 0x06 */
+    U8                              MsgFlags;                                 /* 0x07 */
+    U16                             ChangeCount;                              /* 0x08 */
+    U8                              Action;                                   /* 0x0A */
+    U8                              Reserved0B;                               /* 0x0B */
+    U32                             StartingSequenceNumber;                   /* 0x0C */
+    U16                             Locale;                                   /* 0x10 */
+    U8                              Class;                                    /* 0x12 */
+    U8                              Reserved13;                               /* 0x13 */
+    U32                             Reserved14[3];                            /* 0x14 */
+    MPI3_SGE_UNION                  SGL;                                      /* 0x20 */
+} MPI3_PEL_REQ_ACTION_GET_LOG, MPI3_POINTER PTR_MPI3_PEL_REQ_ACTION_GET_LOG,
+  Mpi3PELReqActionGetLog_t, MPI3_POINTER pMpi3PELReqActionGetLog_t;
+
+/****************************************************************************
+ *              PEL ACTION Get Count                                        *
+ ****************************************************************************/
+typedef struct _MPI3_PEL_REQ_ACTION_GET_COUNT {
+    U16                             HostTag;                                  /* 0x00 */
+    U8                              IOCUseOnly02;                             /* 0x02 */
+    U8                              Function;                                 /* 0x03 */
+    U16                             IOCUseOnly04;                             /* 0x04 */
+    U8                              IOCUseOnly06;                             /* 0x06 */
+    U8                              MsgFlags;                                 /* 0x07 */
+    U16                             ChangeCount;                              /* 0x08 */
+    U8                              Action;                                   /* 0x0A */
+    U8                              Reserved0B;                               /* 0x0B */
+    U32                             StartingSequenceNumber;                   /* 0x0C */
+    U16                             Locale;                                   /* 0x10 */
+    U8                              Class;                                    /* 0x12 */
+    U8                              Reserved13;                               /* 0x13 */
+    U32                             Reserved14[3];                            /* 0x14 */
+    MPI3_SGE_UNION                  SGL;                                      /* 0x20 */
+} MPI3_PEL_REQ_ACTION_GET_COUNT, MPI3_POINTER PTR_MPI3_PEL_REQ_ACTION_GET_COUNT,
+  Mpi3PELReqActionGetCount_t, MPI3_POINTER pMpi3PELReqActionGetCount_t;
+
+/****************************************************************************
+ *              PEL ACTION Wait                                             *
+ ****************************************************************************/
+typedef struct _MPI3_PEL_REQ_ACTION_WAIT {
+    U16                             HostTag;                                  /* 0x00 */
+    U8                              IOCUseOnly02;                             /* 0x02 */
+    U8                              Function;                                 /* 0x03 */
+    U16                             IOCUseOnly04;                             /* 0x04 */
+    U8                              IOCUseOnly06;                             /* 0x06 */
+    U8                              MsgFlags;                                 /* 0x07 */
+    U16                             ChangeCount;                              /* 0x08 */
+    U8                              Action;                                   /* 0x0A */
+    U8                              Reserved0B;                               /* 0x0B */
+    U32                             StartingSequenceNumber;                   /* 0x0C */
+    U16                             Locale;                                   /* 0x10 */
+    U8                              Class;                                    /* 0x12 */
+    U8                              Reserved13;                               /* 0x13 */
+    U16                             WaitTime;                                 /* 0x14 */
+    U16                             Reserved16;                               /* 0x16 */
+    U32                             Reserved18[2];                            /* 0x18 */
+} MPI3_PEL_REQ_ACTION_WAIT, MPI3_POINTER PTR_MPI3_PEL_REQ_ACTION_WAIT,
+  Mpi3PELReqActionWait_t, MPI3_POINTER pMpi3PELReqActionWait_t;
+
+/****************************************************************************
+ *              PEL ACTION Abort                                            *
+ ****************************************************************************/
+typedef struct _MPI3_PEL_REQ_ACTION_ABORT {
+    U16                             HostTag;                                  /* 0x00 */
+    U8                              IOCUseOnly02;                             /* 0x02 */
+    U8                              Function;                                 /* 0x03 */
+    U16                             IOCUseOnly04;                             /* 0x04 */
+    U8                              IOCUseOnly06;                             /* 0x06 */
+    U8                              MsgFlags;                                 /* 0x07 */
+    U16                             ChangeCount;                              /* 0x08 */
+    U8                              Action;                                   /* 0x0A */
+    U8                              Reserved0B;                               /* 0x0B */
+    U32                             Reserved0C;                               /* 0x0C */
+    U16                             AbortHostTag;                             /* 0x10 */
+    U16                             Reserved12;                               /* 0x12 */
+    U32                             Reserved14;                               /* 0x14 */
+} MPI3_PEL_REQ_ACTION_ABORT, MPI3_POINTER PTR_MPI3_PEL_REQ_ACTION_ABORT,
+  Mpi3PELReqActionAbort_t, MPI3_POINTER pMpi3PELReqActionAbort_t;
+
+/****************************************************************************
+ *              PEL ACTION Get Print Strings                                *
+ ****************************************************************************/
+typedef struct _MPI3_PEL_REQ_ACTION_GET_PRINT_STRINGS {
+    U16                             HostTag;                                  /* 0x00 */
+    U8                              IOCUseOnly02;                             /* 0x02 */
+    U8                              Function;                                 /* 0x03 */
+    U16                             IOCUseOnly04;                             /* 0x04 */
+    U8                              IOCUseOnly06;                             /* 0x06 */
+    U8                              MsgFlags;                                 /* 0x07 */
+    U16                             ChangeCount;                              /* 0x08 */
+    U8                              Action;                                   /* 0x0A */
+    U8                              Reserved0B;                               /* 0x0B */
+    U32                             Reserved0C;                               /* 0x0C */
+    U16                             StartLogCode;                             /* 0x10 */
+    U16                             Reserved12;                               /* 0x12 */
+    U32                             Reserved14[3];                            /* 0x14 */
+    MPI3_SGE_UNION                  SGL;                                      /* 0x20 */
+} MPI3_PEL_REQ_ACTION_GET_PRINT_STRINGS, MPI3_POINTER PTR_MPI3_PEL_REQ_ACTION_GET_PRINT_STRINGS,
+  Mpi3PELReqActionGetPrintStrings_t, MPI3_POINTER pMpi3PELReqActionGetPrintStrings_t;
+
+/****************************************************************************
+ *              PEL ACTION Acknowledge                                      *
+ ****************************************************************************/
+typedef struct _MPI3_PEL_REQ_ACTION_ACKNOWLEDGE {
+    U16                             HostTag;                                  /* 0x00 */
+    U8                              IOCUseOnly02;                             /* 0x02 */
+    U8                              Function;                                 /* 0x03 */
+    U16                             IOCUseOnly04;                             /* 0x04 */
+    U8                              IOCUseOnly06;                             /* 0x06 */
+    U8                              MsgFlags;                                 /* 0x07 */
+    U16                             ChangeCount;                              /* 0x08 */
+    U8                              Action;                                   /* 0x0A */
+    U8                              Reserved0B;                               /* 0x0B */
+    U32                             SequenceNumber;                           /* 0x0C */
+    U32                             Reserved10;                               /* 0x10 */
+} MPI3_PEL_REQ_ACTION_ACKNOWLEDGE, MPI3_POINTER PTR_MPI3_PEL_REQ_ACTION_ACKNOWLEDGE,
+  Mpi3PELReqActionAcknowledge_t, MPI3_POINTER pMpi3PELReqActionAcknowledge_t;
+
+/**** Definitions for the MsgFlags field ****/
+#define MPI3_PELACKNOWLEDGE_MSGFLAGS_SAFE_MODE_EXIT            (0x01)
+
+/****************************************************************************
+ *              PEL Reply                                                   *
+ ****************************************************************************/
+typedef struct _MPI3_PEL_REPLY {
+    U16                             HostTag;                                  /* 0x00 */
+    U8                              IOCUseOnly02;                             /* 0x02 */
+    U8                              Function;                                 /* 0x03 */
+    U16                             IOCUseOnly04;                             /* 0x04 */
+    U8                              IOCUseOnly06;                             /* 0x06 */
+    U8                              MsgFlags;                                 /* 0x07 */
+    U16                             IOCUseOnly08;                             /* 0x08 */
+    U16                             IOCStatus;                                /* 0x0A */
+    U32                             IOCLogInfo;                               /* 0x0C */
+    U8                              Action;                                   /* 0x10 */
+    U8                              Reserved11;                               /* 0x11 */
+    U16                             Reserved12;                               /* 0x12 */
+    U16                             PELogStatus;                              /* 0x14 */
+    U16                             Reserved16;                               /* 0x16 */
+    U32                             TransferLength;                           /* 0x18 */
+} MPI3_PEL_REPLY, MPI3_POINTER PTR_MPI3_PEL_REPLY,
+  Mpi3PELReply_t, MPI3_POINTER pMpi3PELReply_t;
+
+
+/*****************************************************************************
+ *              Component Image Download                                     *
+ ****************************************************************************/
+typedef struct _MPI3_CI_DOWNLOAD_REQUEST {
+    U16                             HostTag;                                  /* 0x00 */
+    U8                              IOCUseOnly02;                             /* 0x02 */
+    U8                              Function;                                 /* 0x03 */
+    U16                             IOCUseOnly04;                             /* 0x04 */
+    U8                              IOCUseOnly06;                             /* 0x06 */
+    U8                              MsgFlags;                                 /* 0x07 */
+    U16                             ChangeCount;                              /* 0x08 */
+    U8                              Action;                                   /* 0x0A */
+    U8                              Reserved0B;                               /* 0x0B */
+    U32                             Signature1;                               /* 0x0C */
+    U32                             TotalImageSize;                           /* 0x10 */
+    U32                             ImageOffset;                              /* 0x14 */
+    U32                             SegmentSize;                              /* 0x18 */
+    U32                             Reserved1C;                               /* 0x1C */
+    MPI3_SGE_UNION                  SGL;                                      /* 0x20 */
+} MPI3_CI_DOWNLOAD_REQUEST, MPI3_POINTER PTR_MPI3_CI_DOWNLOAD_REQUEST,
+  Mpi3CIDownloadRequest_t,   MPI3_POINTER pMpi3CIDownloadRequest_t;
+
+/**** Definitions for the MsgFlags field ****/
+#define MPI3_CI_DOWNLOAD_MSGFLAGS_LAST_SEGMENT                 (0x80)
+#define MPI3_CI_DOWNLOAD_MSGFLAGS_FORCE_FMC_ENABLE             (0x40)
+#define MPI3_CI_DOWNLOAD_MSGFLAGS_SIGNED_NVDATA                (0x20)
+#define MPI3_CI_DOWNLOAD_MSGFLAGS_WRITE_CACHE_FLUSH_MASK       (0x03)
+#define MPI3_CI_DOWNLOAD_MSGFLAGS_WRITE_CACHE_FLUSH_FAST       (0x00)
+#define MPI3_CI_DOWNLOAD_MSGFLAGS_WRITE_CACHE_FLUSH_MEDIUM     (0x01)
+#define MPI3_CI_DOWNLOAD_MSGFLAGS_WRITE_CACHE_FLUSH_SLOW       (0x02)
+
+/**** Definitions for the Action field ****/
+#define MPI3_CI_DOWNLOAD_ACTION_DOWNLOAD                       (0x01)
+#define MPI3_CI_DOWNLOAD_ACTION_ONLINE_ACTIVATION              (0x02)
+#define MPI3_CI_DOWNLOAD_ACTION_OFFLINE_ACTIVATION             (0x03)
+#define MPI3_CI_DOWNLOAD_ACTION_GET_STATUS                     (0x04)
+
+typedef struct _MPI3_CI_DOWNLOAD_REPLY {
+    U16                             HostTag;                                  /* 0x00 */
+    U8                              IOCUseOnly02;                             /* 0x02 */
+    U8                              Function;                                 /* 0x03 */
+    U16                             IOCUseOnly04;                             /* 0x04 */
+    U8                              IOCUseOnly06;                             /* 0x06 */
+    U8                              MsgFlags;                                 /* 0x07 */
+    U16                             IOCUseOnly08;                             /* 0x08 */
+    U16                             IOCStatus;                                /* 0x0A */
+    U32                             IOCLogInfo;                               /* 0x0C */
+    U8                              Flags;                                    /* 0x10 */
+    U8                              CacheDirty;                               /* 0x11 */
+    U8                              PendingCount;                             /* 0x12 */
+    U8                              Reserved13;                               /* 0x13 */
+} MPI3_CI_DOWNLOAD_REPLY, MPI3_POINTER PTR_MPI3_CI_DOWNLOAD_REPLY,
+  Mpi3CIDownloadReply_t,  MPI3_POINTER pMpi3CIDownloadReply_t;
+
+/**** Definitions for the Flags field ****/
+#define MPI3_CI_DOWNLOAD_FLAGS_DOWNLOAD_IN_PROGRESS                  (0x80)
+#define MPI3_CI_DOWNLOAD_FLAGS_KEY_UPDATE_PENDING                    (0x10)
+#define MPI3_CI_DOWNLOAD_FLAGS_ACTIVATION_STATUS_MASK                (0x0E)
+#define MPI3_CI_DOWNLOAD_FLAGS_ACTIVATION_STATUS_NOT_NEEDED          (0x00)
+#define MPI3_CI_DOWNLOAD_FLAGS_ACTIVATION_STATUS_AWAITING            (0x02)
+#define MPI3_CI_DOWNLOAD_FLAGS_ACTIVATION_STATUS_ONLINE_PENDING      (0x04)
+#define MPI3_CI_DOWNLOAD_FLAGS_ACTIVATION_STATUS_OFFLINE_PENDING     (0x06)
+#define MPI3_CI_DOWNLOAD_FLAGS_COMPATIBLE                            (0x01)
+
+/*****************************************************************************
+ *              Component Image Upload                                       *
+ ****************************************************************************/
+typedef struct _MPI3_CI_UPLOAD_REQUEST {
+    U16                             HostTag;                                  /* 0x00 */
+    U8                              IOCUseOnly02;                             /* 0x02 */
+    U8                              Function;                                 /* 0x03 */
+    U16                             IOCUseOnly04;                             /* 0x04 */
+    U8                              IOCUseOnly06;                             /* 0x06 */
+    U8                              MsgFlags;                                 /* 0x07 */
+    U16                             ChangeCount;                              /* 0x08 */
+    U16                             Reserved0A;                               /* 0x0A */
+    U32                             Signature1;                               /* 0x0C */
+    U32                             Reserved10;                               /* 0x10 */
+    U32                             ImageOffset;                              /* 0x14 */
+    U32                             SegmentSize;                              /* 0x18 */
+    U32                             Reserved1C;                               /* 0x1C */
+    MPI3_SGE_UNION                  SGL;                                      /* 0x20 */
+} MPI3_CI_UPLOAD_REQUEST, MPI3_POINTER PTR_MPI3_CI_UPLOAD_REQUEST,
+  Mpi3CIUploadRequest_t,   MPI3_POINTER pMpi3CIUploadRequest_t;
+
+/**** Defines for the MsgFlags field ****/
+#define MPI3_CI_UPLOAD_MSGFLAGS_LOCATION_MASK                        (0x01)
+#define MPI3_CI_UPLOAD_MSGFLAGS_LOCATION_PRIMARY                     (0x00)
+#define MPI3_CI_UPLOAD_MSGFLAGS_LOCATION_SECONDARY                   (0x01)
+#define MPI3_CI_UPLOAD_MSGFLAGS_FORMAT_MASK                          (0x02)
+#define MPI3_CI_UPLOAD_MSGFLAGS_FORMAT_FLASH                         (0x00)
+#define MPI3_CI_UPLOAD_MSGFLAGS_FORMAT_EXECUTABLE                    (0x02)
+
+/**** Defines for Signature1 field - use MPI3_IMAGE_HEADER_SIGNATURE1_ defines */
+
+/*****************************************************************************
+ *              IO Unit Control                                              *
+ ****************************************************************************/
+
+/**** Definitions for the Operation field ****/
+#define MPI3_CTRL_OP_FORCE_FULL_DISCOVERY                            (0x01)
+#define MPI3_CTRL_OP_LOOKUP_MAPPING                                  (0x02)
+#define MPI3_CTRL_OP_UPDATE_TIMESTAMP                                (0x04)
+#define MPI3_CTRL_OP_GET_TIMESTAMP                                   (0x05)
+#define MPI3_CTRL_OP_REMOVE_DEVICE                                   (0x10)
+#define MPI3_CTRL_OP_CLOSE_PERSISTENT_CONNECTION                     (0x11)
+#define MPI3_CTRL_OP_HIDDEN_ACK                                      (0x12)
+#define MPI3_CTRL_OP_SAS_SEND_PRIMITIVE                              (0x20)
+#define MPI3_CTRL_OP_SAS_CLEAR_ERROR_LOG                             (0x21)
+#define MPI3_CTRL_OP_PCIE_CLEAR_ERROR_LOG                            (0x22)
+
+/**** Depending on the Operation selected, the various ParamX fields         *****/
+/****  contain defined data values. These indexes help identify those values *****/
+#define MPI3_CTRL_OP_LOOKUP_MAPPING_PARAM8_LOOKUP_METHOD_INDEX       (0x00)
+#define MPI3_CTRL_OP_UPDATE_TIMESTAMP_PARAM64_TIMESTAMP_INDEX        (0x00)
+#define MPI3_CTRL_OP_REMOVE_DEVICE_PARAM16_DEVHANDLE_INDEX           (0x00)
+#define MPI3_CTRL_OP_CLOSE_PERSIST_CONN_PARAM16_DEVHANDLE_INDEX      (0x00)
+#define MPI3_CTRL_OP_HIDDEN_ACK_PARAM16_DEVHANDLE_INDEX              (0x00)
+#define MPI3_CTRL_OP_SAS_SEND_PRIM_PARAM8_PHY_INDEX                  (0x00)
+#define MPI3_CTRL_OP_SAS_SEND_PRIM_PARAM8_PRIMSEQ_INDEX              (0x01)
+#define MPI3_CTRL_OP_SAS_SEND_PRIM_PARAM32_PRIMITIVE_INDEX           (0x00)
+#define MPI3_CTRL_OP_SAS_CLEAR_ERR_LOG_PARAM8_PHY_INDEX              (0x00)
+#define MPI3_CTRL_OP_PCIE_CLEAR_ERR_LOG_PARAM8_PHY_INDEX             (0x00)
+
+/**** Definitions for the LookupMethod field ****/
+#define MPI3_CTRL_LOOKUP_METHOD_WWID_ADDRESS                         (0x01)
+#define MPI3_CTRL_LOOKUP_METHOD_ENCLOSURE_SLOT                       (0x02)
+#define MPI3_CTRL_LOOKUP_METHOD_SAS_DEVICE_NAME                      (0x03)
+#define MPI3_CTRL_LOOKUP_METHOD_PERSISTENT_ID                        (0x04)
+
+/**** Definitions for IoUnitControl Lookup Mapping Method Parameters ****/
+#define MPI3_CTRL_LOOKUP_METHOD_WWIDADDR_PARAM16_DEVH_INDEX             (0)
+#define MPI3_CTRL_LOOKUP_METHOD_WWIDADDR_PARAM64_WWID_INDEX             (0)
+#define MPI3_CTRL_LOOKUP_METHOD_ENCLSLOT_PARAM16_SLOTNUM_INDEX          (0)
+#define MPI3_CTRL_LOOKUP_METHOD_ENCLSLOT_PARAM64_ENCLOSURELID_INDEX     (0)
+#define MPI3_CTRL_LOOKUP_METHOD_SASDEVNAME_PARAM16_DEVH_INDEX           (0)
+#define MPI3_CTRL_LOOKUP_METHOD_SASDEVNAME_PARAM64_DEVNAME_INDEX        (0)
+#define MPI3_CTRL_LOOKUP_METHOD_PERSISTID_PARAM16_DEVH_INDEX            (0)
+#define MPI3_CTRL_LOOKUP_METHOD_PERSISTID_PARAM16_PERSISTENT_ID_INDEX   (1)
+
+/*** Definitions for IoUnitControl Reply fields ****/
+#define MPI3_CTRL_LOOKUP_METHOD_VALUE16_DEVH_INDEX                      (0)
+#define MPI3_CTRL_GET_TIMESTAMP_VALUE64_TIMESTAMP_INDEX                 (0)
+
+
+/**** Definitions for the PrimSeq field ****/
+#define MPI3_CTRL_PRIMFLAGS_SINGLE                                   (0x01)
+#define MPI3_CTRL_PRIMFLAGS_TRIPLE                                   (0x03)
+#define MPI3_CTRL_PRIMFLAGS_REDUNDANT                                (0x06)
+
+typedef struct _MPI3_IOUNIT_CONTROL_REQUEST {
+    U16                             HostTag;                                  /* 0x00 */
+    U8                              IOCUseOnly02;                             /* 0x02 */
+    U8                              Function;                                 /* 0x03 */
+    U16                             IOCUseOnly04;                             /* 0x04 */
+    U8                              IOCUseOnly06;                             /* 0x06 */
+    U8                              MsgFlags;                                 /* 0x07 */
+    U16                             ChangeCount;                              /* 0x08 */
+    U8                              Reserved0A;                               /* 0x0A */
+    U8                              Operation;                                /* 0x0B */
+    U32                             Reserved0C;                               /* 0x0C */
+    U64                             Param64[2];                               /* 0x10 */
+    U32                             Param32[4];                               /* 0x20 */
+    U16                             Param16[4];                               /* 0x30 */
+    U8                              Param8[8];                                /* 0x38 */
+} MPI3_IOUNIT_CONTROL_REQUEST, MPI3_POINTER PTR_MPI3_IOUNIT_CONTROL_REQUEST,
+  Mpi3IoUnitControlRequest_t, MPI3_POINTER pMpi3IoUnitControlRequest_t;
+
+
+typedef struct _MPI3_IOUNIT_CONTROL_REPLY {
+    U16                             HostTag;                                  /* 0x00 */
+    U8                              IOCUseOnly02;                             /* 0x02 */
+    U8                              Function;                                 /* 0x03 */
+    U16                             IOCUseOnly04;                             /* 0x04 */
+    U8                              IOCUseOnly06;                             /* 0x06 */
+    U8                              MsgFlags;                                 /* 0x07 */
+    U16                             IOCUseOnly08;                             /* 0x08 */
+    U16                             IOCStatus;                                /* 0x0A */
+    U32                             IOCLogInfo;                               /* 0x0C */
+    U64                             Value64[2];                               /* 0x10 */
+    U32                             Value32[4];                               /* 0x20 */
+    U16                             Value16[4];                               /* 0x30 */
+    U8                              Value8[8];                                /* 0x38 */
+} MPI3_IOUNIT_CONTROL_REPLY, MPI3_POINTER PTR_MPI3_IOUNIT_CONTROL_REPLY,
+  Mpi3IoUnitControlReply_t, MPI3_POINTER pMpi3IoUnitControlReply_t;
+
+#endif  /* MPI30_IOC_H */
diff --git a/drivers/scsi/mpi3mr/mpi/mpi30_transport.h b/drivers/scsi/mpi3mr/mpi/mpi30_transport.h
new file mode 100644
index 000000000000..54f821d25209
--- /dev/null
+++ b/drivers/scsi/mpi3mr/mpi/mpi30_transport.h
@@ -0,0 +1,675 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ *  Copyright 2016-2020 Broadcom Inc. All rights reserved.
+ *
+ *           Name: mpi30_transport.h
+ *    Description: Contains definitions for System Interface Register Set, Scatter Gather Lists etc
+ *  Creation Date: 08/31/2016
+ *        Version: 03.00.00
+ *
+ *  mpi3.h Version:  03.00.00.18
+ *
+ *
+ *  Version History
+ *  ---------------
+ *
+ *  Date      Version       Description
+ *  --------  -----------  ------------------------------------------------------
+ *  11-30-18  03.00.00.08  Corresponds to Fusion-MPT MPI 3.0 Specification Rev H.
+ *  02-08-19  03.00.00.09  Corresponds to Fusion-MPT MPI 3.0 Specification Rev I.
+ *  05-03-19  03.00.00.10  Corresponds to Fusion-MPT MPI 3.0 Specification Rev J.
+ *  08-30-19  03.00.00.12  Corresponds to Fusion-MPT MPI 3.0 Specification Rev L.
+ *  11-01-19  03.00.00.13  Corresponds to Fusion-MPT MPI 3.0 Specification Rev M.
+ *  12-16-19  03.00.00.14  Corresponds to Fusion-MPT MPI 3.0 Specification Rev N.
+ *  02-28-20  03.00.00.15  Corresponds to Fusion-MPT MPI 3.0 Specification Rev O.
+ *  05-01-20  03.00.00.16  Corresponds to Fusion-MPT MPI 3.0 Specification Rev P.
+ *  06-26-20  03.00.00.17  Corresponds to Fusion-MPT MPI 3.0 Specification Rev Q.
+ *  08-28-20  03.00.00.18  Corresponds to Fusion-MPT MPI 3.0 Specification Rev R.
+ */
+#ifndef MPI30_TRANSPORT_H
+#define MPI30_TRANSPORT_H     1
+
+/*****************************************************************************
+ *              Common version structure/union used in                       *
+ *              messages and configuration pages                             *
+ ****************************************************************************/
+
+typedef struct _MPI3_VERSION_STRUCT {
+    U8      Dev;                                                        /* 0x00 */
+    U8      Unit;                                                       /* 0x01 */
+    U8      Minor;                                                      /* 0x02 */
+    U8      Major;                                                      /* 0x03 */
+} MPI3_VERSION_STRUCT, MPI3_POINTER PTR_MPI3_VERSION_STRUCT,
+  Mpi3VersionStruct, MPI3_POINTER pMpi3VersionStruct;
+
+typedef union _MPI3_VERSION_UNION {
+    MPI3_VERSION_STRUCT     Struct;
+    U32                     Word;
+} MPI3_VERSION_UNION, MPI3_POINTER PTR_MPI3_VERSION_UNION,
+  Mpi3VersionUnion, MPI3_POINTER pMpi3VersionUnion;
+
+/****** Version constants for this revision ****/
+#define MPI3_VERSION_MAJOR                                              (3)
+#define MPI3_VERSION_MINOR                                              (0)
+#define MPI3_VERSION_UNIT                                               (0)
+#define MPI3_VERSION_DEV                                                (18)
+
+
+/*****************************************************************************
+ *              System Interface Register Definitions                        *
+ ****************************************************************************/
+typedef struct _MPI3_SYSIF_OPER_QUEUE_INDEXES {
+    U16         ProducerIndex;                                          /* 0x00 */
+    U16         Reserved02;                                             /* 0x02 */
+    U16         ConsumerIndex;                                          /* 0x04 */
+    U16         Reserved06;                                             /* 0x06 */
+} MPI3_SYSIF_OPER_QUEUE_INDEXES, MPI3_POINTER PTR_MPI3_SYSIF_OPER_QUEUE_INDEXES;
+
+typedef volatile struct _MPI3_SYSIF_REGISTERS
+{
+    U64                             IOCInformation;                     /* 0x00   */
+    MPI3_VERSION_UNION              Version;                            /* 0x08   */
+    U32                             Reserved0C[2];                      /* 0x0C   */
+    U32                             IOCConfiguration;                   /* 0x14   */
+    U32                             Reserved18;                         /* 0x18   */
+    U32                             IOCStatus;                          /* 0x1C   */
+    U32                             Reserved20;                         /* 0x20   */
+    U32                             AdminQueueNumEntries;               /* 0x24   */
+    U64                             AdminRequestQueueAddress;           /* 0x28   */
+    U64                             AdminReplyQueueAddress;             /* 0x30   */
+    U32                             Reserved38[2];                      /* 0x38   */
+    U32                             CoalesceControl;                    /* 0x40   */
+    U32                             Reserved44[1007];                   /* 0x44   */
+    U16                             AdminRequestQueuePI;                /* 0x1000 */
+    U16                             Reserved1002;                       /* 0x1002 */
+    U16                             AdminReplyQueueCI;                  /* 0x1004 */
+    U16                             Reserved1006;                       /* 0x1006 */
+    MPI3_SYSIF_OPER_QUEUE_INDEXES   OperQueueIndexes[383];              /* 0x1008 */
+    U32                             Reserved1C00;                       /* 0x1C00 */
+    U32                             WriteSequence;                      /* 0x1C04 */
+    U32                             HostDiagnostic;                     /* 0x1C08 */
+    U32                             Reserved1C0C;                       /* 0x1C0C */
+    U32                             Fault;                              /* 0x1C10 */
+    U32                             FaultInfo[3];                       /* 0x1C14 */
+    U32                             Reserved1C20[4];                    /* 0x1C20 */
+    U64                             HCBAddress;                         /* 0x1C30 */
+    U32                             HCBSize;                            /* 0x1C38 */
+    U32                             Reserved1C3C;                       /* 0x1C3C */
+    U32                             ReplyFreeHostIndex;                 /* 0x1C40 */
+    U32                             SenseBufferFreeHostIndex;           /* 0x1C44 */
+    U32                             Reserved1C48[2];                    /* 0x1C48 */
+    U64                             DiagRWData;                         /* 0x1C50 */
+    U64                             DiagRWAddress;                      /* 0x1C58 */
+    U16                             DiagRWControl;                      /* 0x1C60 */
+    U16                             DiagRWStatus;                       /* 0x1C62 */
+    U32                             Reserved1C64[35];                   /* 0x1C64 */
+    U32                             Scratchpad[4];                      /* 0x1CF0 */
+    U32                             Reserved1D00[192];                  /* 0x1D00 */
+    U32                             DeviceAssignedRegisters[2048];      /* 0x2000 */
+} MPI3_SYSIF_REGS, MPI3_POINTER PTR_MPI3_SYSIF_REGS,
+  Mpi3SysIfRegs_t, MPI3_POINTER pMpi3SysIfRegs_t;
+
+/**** Defines for the IOCInformation register ****/
+#define MPI3_SYSIF_IOC_INFO_LOW_OFFSET                                  (0x00000000)
+#define MPI3_SYSIF_IOC_INFO_HIGH_OFFSET                                 (0x00000004)
+#define MPI3_SYSIF_IOC_INFO_LOW_TIMEOUT_MASK                            (0xFF000000)
+#define MPI3_SYSIF_IOC_INFO_LOW_TIMEOUT_SHIFT                           (24)
+
+/**** Defines for the IOCConfiguration register ****/
+#define MPI3_SYSIF_IOC_CONFIG_OFFSET                                    (0x00000014)
+#define MPI3_SYSIF_IOC_CONFIG_OPER_RPY_ENT_SZ                           (0x00F00000)
+#define MPI3_SYSIF_IOC_CONFIG_OPER_RPY_ENT_SZ_SHIFT                     (20)
+#define MPI3_SYSIF_IOC_CONFIG_OPER_REQ_ENT_SZ                           (0x000F0000)
+#define MPI3_SYSIF_IOC_CONFIG_OPER_REQ_ENT_SZ_SHIFT                     (16)
+#define MPI3_SYSIF_IOC_CONFIG_SHUTDOWN_MASK                             (0x0000C000)
+#define MPI3_SYSIF_IOC_CONFIG_SHUTDOWN_NO                               (0x00000000)
+#define MPI3_SYSIF_IOC_CONFIG_SHUTDOWN_NORMAL                           (0x00004000)
+#define MPI3_SYSIF_IOC_CONFIG_DEVICE_SHUTDOWN                           (0x00002000)
+#define MPI3_SYSIF_IOC_CONFIG_DIAG_SAVE                                 (0x00000010)
+#define MPI3_SYSIF_IOC_CONFIG_ENABLE_IOC                                (0x00000001)
+
+/**** Defines for the IOCStatus register ****/
+#define MPI3_SYSIF_IOC_STATUS_OFFSET                                    (0x0000001C)
+#define MPI3_SYSIF_IOC_STATUS_RESET_HISTORY                             (0x00000010)
+#define MPI3_SYSIF_IOC_STATUS_SHUTDOWN_MASK                             (0x0000000C)
+#define MPI3_SYSIF_IOC_STATUS_SHUTDOWN_NONE                             (0x00000000)
+#define MPI3_SYSIF_IOC_STATUS_SHUTDOWN_IN_PROGRESS                      (0x00000004)
+#define MPI3_SYSIF_IOC_STATUS_SHUTDOWN_COMPLETE                         (0x00000008)
+#define MPI3_SYSIF_IOC_STATUS_FAULT                                     (0x00000002)
+#define MPI3_SYSIF_IOC_STATUS_READY                                     (0x00000001)
+
+/**** Defines for the AdminQueueNumEntries register ****/
+#define MPI3_SYSIF_ADMIN_Q_NUM_ENTRIES_OFFSET                           (0x00000024)
+#define MPI3_SYSIF_ADMIN_Q_NUM_ENTRIES_REQ_MASK                         (0x0FFF)
+#define MPI3_SYSIF_ADMIN_Q_NUM_ENTRIES_REPLY_OFFSET                     (0x00000026)
+#define MPI3_SYSIF_ADMIN_Q_NUM_ENTRIES_REPLY_MASK                       (0x0FFF0000)
+#define MPI3_SYSIF_ADMIN_Q_NUM_ENTRIES_REPLY_SHIFT                      (16)
+
+/**** Defines for the AdminRequestQueueAddress register ****/
+#define MPI3_SYSIF_ADMIN_REQ_Q_ADDR_LOW_OFFSET                          (0x00000028)
+#define MPI3_SYSIF_ADMIN_REQ_Q_ADDR_HIGH_OFFSET                         (0x0000002C)
+
+/**** Defines for the AdminReplyQueueAddress register ****/
+#define MPI3_SYSIF_ADMIN_REPLY_Q_ADDR_LOW_OFFSET                        (0x00000030)
+#define MPI3_SYSIF_ADMIN_REPLY_Q_ADDR_HIGH_OFFSET                       (0x00000034)
+
+/**** Defines for the CoalesceControl register ****/
+#define MPI3_SYSIF_COALESCE_CONTROL_OFFSET                              (0x00000040)
+#define MPI3_SYSIF_COALESCE_CONTROL_ENABLE_MASK                         (0xC0000000)
+#define MPI3_SYSIF_COALESCE_CONTROL_ENABLE_NO_CHANGE                    (0x00000000)
+#define MPI3_SYSIF_COALESCE_CONTROL_ENABLE_DISABLE                      (0x40000000)
+#define MPI3_SYSIF_COALESCE_CONTROL_ENABLE_ENABLE                       (0xC0000000)
+#define MPI3_SYSIF_COALESCE_CONTROL_VALID                               (0x30000000)
+#define MPI3_SYSIF_COALESCE_CONTROL_QUEUE_ID_MASK                       (0x00FF0000)
+#define MPI3_SYSIF_COALESCE_CONTROL_QUEUE_ID_SHIFT                      (16)
+#define MPI3_SYSIF_COALESCE_CONTROL_TIMEOUT_MASK                        (0x0000FF00)
+#define MPI3_SYSIF_COALESCE_CONTROL_TIMEOUT_SHIFT                       (8)
+#define MPI3_SYSIF_COALESCE_CONTROL_DEPTH_MASK                          (0x000000FF)
+#define MPI3_SYSIF_COALESCE_CONTROL_DEPTH_SHIFT                         (0)
+
+/**** Defines for the AdminRequestQueuePI register ****/
+#define MPI3_SYSIF_ADMIN_REQ_Q_PI_OFFSET                                (0x00001000)
+
+/**** Defines for the AdminReplyQueueCI register ****/
+#define MPI3_SYSIF_ADMIN_REPLY_Q_CI_OFFSET                              (0x00001004)
+
+/**** Defines for the OperationalRequestQueuePI register */
+#define MPI3_SYSIF_OPER_REQ_Q_PI_OFFSET                                 (0x00001008)
+#define MPI3_SYSIF_OPER_REQ_Q_N_PI_OFFSET(N)                            (MPI3_SYSIF_OPER_REQ_Q_PI_OFFSET + (((N)-1)*8)) /* N = 1, 2, 3, ..., 255 */
+
+/**** Defines for the OperationalReplyQueueCI register */
+#define MPI3_SYSIF_OPER_REPLY_Q_CI_OFFSET                               (0x0000100C)
+#define MPI3_SYSIF_OPER_REPLY_Q_N_CI_OFFSET(N)                          (MPI3_SYSIF_OPER_REPLY_Q_CI_OFFSET + (((N)-1)*8)) /* N = 1, 2, 3, ..., 255 */
+
+/**** Defines for the WriteSequence register *****/
+#define MPI3_SYSIF_WRITE_SEQUENCE_OFFSET                                (0x00001C04)
+#define MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_MASK                        (0x0000000F)
+#define MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_FLUSH                       (0x0)
+#define MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_1ST                         (0xF)
+#define MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_2ND                         (0x4)
+#define MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_3RD                         (0xB)
+#define MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_4TH                         (0x2)
+#define MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_5TH                         (0x7)
+#define MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_6TH                         (0xD)
+
+/**** Defines for the HostDiagnostic register *****/
+#define MPI3_SYSIF_HOST_DIAG_OFFSET                                     (0x00001C08)
+#define MPI3_SYSIF_HOST_DIAG_RESET_ACTION_MASK                          (0x00000700)
+#define MPI3_SYSIF_HOST_DIAG_RESET_ACTION_NO_RESET                      (0x00000000)
+#define MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET                    (0x00000100)
+#define MPI3_SYSIF_HOST_DIAG_RESET_ACTION_FLASH_RCVRY_RESET             (0x00000200)
+#define MPI3_SYSIF_HOST_DIAG_RESET_ACTION_COMPLETE_RESET                (0x00000300)
+#define MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT                    (0x00000700)
+#define MPI3_SYSIF_HOST_DIAG_SAVE_IN_PROGRESS                           (0x00000080)
+#define MPI3_SYSIF_HOST_DIAG_SECURE_BOOT                                (0x00000040)
+#define MPI3_SYSIF_HOST_DIAG_CLEAR_INVALID_FW_IMAGE                     (0x00000020)
+#define MPI3_SYSIF_HOST_DIAG_INVALID_FW_IMAGE                           (0x00000010)
+#define MPI3_SYSIF_HOST_DIAG_HCBENABLE                                  (0x00000008)
+#define MPI3_SYSIF_HOST_DIAG_HCBMODE                                    (0x00000004)
+#define MPI3_SYSIF_HOST_DIAG_DIAG_RW_ENABLE                             (0x00000002)
+#define MPI3_SYSIF_HOST_DIAG_DIAG_WRITE_ENABLE                          (0x00000001)
+
+/**** Defines for the Fault register ****/
+#define MPI3_SYSIF_FAULT_OFFSET                                         (0x00001C10)
+#define MPI3_SYSIF_FAULT_FUNC_AREA_MASK                                 (0xFF000000)
+#define MPI3_SYSIF_FAULT_FUNC_AREA_SHIFT                                (24)
+#define MPI3_SYSIF_FAULT_FUNC_AREA_MPI_DEFINED                          (0x00000000)
+#define MPI3_SYSIF_FAULT_CODE_MASK                                      (0x0000FFFF)
+#define MPI3_SYSIF_FAULT_CODE_DIAG_FAULT_RESET                          (0x0000F000)
+#define MPI3_SYSIF_FAULT_CODE_CI_ACTIVATION_RESET                       (0x0000F001)
+#define MPI3_SYSIF_FAULT_CODE_SOFT_RESET_IN_PROGRESS                    (0x0000F002)
+#define MPI3_SYSIF_FAULT_CODE_COMPLETE_RESET_NEEDED                     (0x0000F003)
+#define MPI3_SYSIF_FAULT_CODE_SAFE_MODE_EXIT                            (0x0000F004)
+#define MPI3_SYSIF_FAULT_CODE_FACTORY_RESET                             (0x0000F005)
+
+/**** Defines for FaultCodeAdditionalInfo registers ****/
+#define MPI3_SYSIF_FAULT_INFO0_OFFSET                                   (0x00001C14)
+#define MPI3_SYSIF_FAULT_INFO1_OFFSET                                   (0x00001C18)
+#define MPI3_SYSIF_FAULT_INFO2_OFFSET                                   (0x00001C1C)
+
+/**** Defines for HCBAddress register ****/
+#define MPI3_SYSIF_HCB_ADDRESS_LOW_OFFSET                               (0x00001C30)
+#define MPI3_SYSIF_HCB_ADDRESS_HIGH_OFFSET                              (0x00001C34)
+
+/**** Defines for HCBSize register ****/
+#define MPI3_SYSIF_HCB_SIZE_OFFSET                                      (0x00001C38)
+#define MPI3_SYSIF_HCB_SIZE_SIZE_MASK                                   (0xFFFFF000)
+#define MPI3_SYSIF_HCB_SIZE_SIZE_SHIFT                                  (12)
+#define MPI3_SYSIF_HCB_SIZE_HCDW_ENABLE                                 (0x00000001)
+
+/**** Defines for ReplyFreeHostIndex register ****/
+#define MPI3_SYSIF_REPLY_FREE_HOST_INDEX_OFFSET                         (0x00001C40)
+
+/**** Defines for SenseBufferFreeHostIndex register ****/
+#define MPI3_SYSIF_SENSE_BUF_FREE_HOST_INDEX_OFFSET                     (0x00001C44)
+
+/**** Defines for DiagRWData register ****/
+#define MPI3_SYSIF_DIAG_RW_DATA_LOW_OFFSET                              (0x00001C50)
+#define MPI3_SYSIF_DIAG_RW_DATA_HIGH_OFFSET                             (0x00001C54)
+
+/**** Defines for DiagRWAddress ****/
+#define MPI3_SYSIF_DIAG_RW_ADDRESS_LOW_OFFSET                           (0x00001C58)
+#define MPI3_SYSIF_DIAG_RW_ADDRESS_HIGH_OFFSET                          (0x00001C5C)
+
+/**** Defines for DiagRWControl register ****/
+#define MPI3_SYSIF_DIAG_RW_CONTROL_OFFSET                               (0x00001C60)
+#define MPI3_SYSIF_DIAG_RW_CONTROL_LEN_MASK                             (0x00000030)
+#define MPI3_SYSIF_DIAG_RW_CONTROL_LEN_1BYTE                            (0x00000000)
+#define MPI3_SYSIF_DIAG_RW_CONTROL_LEN_2BYTES                           (0x00000010)
+#define MPI3_SYSIF_DIAG_RW_CONTROL_LEN_4BYTES                           (0x00000020)
+#define MPI3_SYSIF_DIAG_RW_CONTROL_LEN_8BYTES                           (0x00000030)
+#define MPI3_SYSIF_DIAG_RW_CONTROL_RESET                                (0x00000004)
+#define MPI3_SYSIF_DIAG_RW_CONTROL_DIR_MASK                             (0x00000002)
+#define MPI3_SYSIF_DIAG_RW_CONTROL_DIR_READ                             (0x00000000)
+#define MPI3_SYSIF_DIAG_RW_CONTROL_DIR_WRITE                            (0x00000002)
+#define MPI3_SYSIF_DIAG_RW_CONTROL_START                                (0x00000001)
+
+/**** Defines for DiagRWStatus register ****/
+#define MPI3_SYSIF_DIAG_RW_STATUS_OFFSET                                (0x00001C62)
+#define MPI3_SYSIF_DIAG_RW_STATUS_STATUS_MASK                           (0x0000000E)
+#define MPI3_SYSIF_DIAG_RW_STATUS_STATUS_SUCCESS                        (0x00000000)
+#define MPI3_SYSIF_DIAG_RW_STATUS_STATUS_INV_ADDR                       (0x00000002)
+#define MPI3_SYSIF_DIAG_RW_STATUS_STATUS_ACC_ERR                        (0x00000004)
+#define MPI3_SYSIF_DIAG_RW_STATUS_STATUS_PAR_ERR                        (0x00000006)
+#define MPI3_SYSIF_DIAG_RW_STATUS_BUSY                                  (0x00000001)
+
+/**** Defines for Scratchpad registers ****/
+#define MPI3_SYSIF_SCRATCHPAD0_OFFSET                                   (0x00001CF0)
+#define MPI3_SYSIF_SCRATCHPAD1_OFFSET                                   (0x00001CF4)
+#define MPI3_SYSIF_SCRATCHPAD2_OFFSET                                   (0x00001CF8)
+#define MPI3_SYSIF_SCRATCHPAD3_OFFSET                                   (0x00001CFC)
+
+/**** Defines for Device Assigned registers ****/
+#define MPI3_SYSIF_DEVICE_ASSIGNED_REGS_OFFSET                          (0x00002000)
+
+/**** Default Defines for Diag Save Timeout ****/
+#define MPI3_SYSIF_DIAG_SAVE_TIMEOUT                                    (60)    /* seconds */
+
+/*****************************************************************************
+ *              Reply Descriptors                                            *
+ ****************************************************************************/
+
+/*****************************************************************************
+ *              Default Reply Descriptor                                     *
+ ****************************************************************************/
+typedef struct _MPI3_DEFAULT_REPLY_DESCRIPTOR {
+    U32             DescriptorTypeDependent1[2];    /* 0x00 */
+    U16             RequestQueueCI;                 /* 0x08 */
+    U16             RequestQueueID;                 /* 0x0A */
+    U16             DescriptorTypeDependent2;       /* 0x0C */
+    U16             ReplyFlags;                     /* 0x0E */
+} MPI3_DEFAULT_REPLY_DESCRIPTOR, MPI3_POINTER PTR_MPI3_DEFAULT_REPLY_DESCRIPTOR,
+  Mpi3DefaultReplyDescriptor_t, MPI3_POINTER pMpi3DefaultReplyDescriptor_t;
+
+/**** Defines for the ReplyFlags field ****/
+#define MPI3_REPLY_DESCRIPT_FLAGS_PHASE_MASK                       (0x0001)
+#define MPI3_REPLY_DESCRIPT_FLAGS_TYPE_MASK                        (0xF000)
+#define MPI3_REPLY_DESCRIPT_FLAGS_TYPE_ADDRESS_REPLY               (0x0000)
+#define MPI3_REPLY_DESCRIPT_FLAGS_TYPE_SUCCESS                     (0x1000)
+#define MPI3_REPLY_DESCRIPT_FLAGS_TYPE_TARGET_COMMAND_BUFFER       (0x2000)
+#define MPI3_REPLY_DESCRIPT_FLAGS_TYPE_STATUS                      (0x3000)
+
+/*****************************************************************************
+ *              Address Reply Descriptor                                     *
+ ****************************************************************************/
+typedef struct _MPI3_ADDRESS_REPLY_DESCRIPTOR {
+    U64             ReplyFrameAddress;              /* 0x00 */
+    U16             RequestQueueCI;                 /* 0x08 */
+    U16             RequestQueueID;                 /* 0x0A */
+    U16             Reserved0C;                     /* 0x0C */
+    U16             ReplyFlags;                     /* 0x0E */
+} MPI3_ADDRESS_REPLY_DESCRIPTOR, MPI3_POINTER PTR_MPI3_ADDRESS_REPLY_DESCRIPTOR,
+  Mpi3AddressReplyDescriptor_t, MPI3_POINTER pMpi3AddressReplyDescriptor_t;
+
+/*****************************************************************************
+ *              Success Reply Descriptor                                     *
+ ****************************************************************************/
+typedef struct _MPI3_SUCCESS_REPLY_DESCRIPTOR {
+    U32             Reserved00[2];                  /* 0x00 */
+    U16             RequestQueueCI;                 /* 0x08 */
+    U16             RequestQueueID;                 /* 0x0A */
+    U16             HostTag;                        /* 0x0C */
+    U16             ReplyFlags;                     /* 0x0E */
+} MPI3_SUCCESS_REPLY_DESCRIPTOR, MPI3_POINTER PTR_MPI3_SUCCESS_REPLY_DESCRIPTOR,
+  Mpi3SuccessReplyDescriptor_t, MPI3_POINTER pMpi3SuccessReplyDescriptor_t;
+
+/*****************************************************************************
+ *              Target Command Buffer Reply Descriptor                       *
+ ****************************************************************************/
+typedef struct _MPI3_TARGET_COMMAND_BUFFER_REPLY_DESCRIPTOR {
+    U32             Reserved00;                     /* 0x00 */
+    U16             InitiatorDevHandle;             /* 0x04 */
+    U8              PhyNum;                         /* 0x06 */
+    U8              Reserved07;                     /* 0x07 */
+    U16             RequestQueueCI;                 /* 0x08 */
+    U16             RequestQueueID;                 /* 0x0A */
+    U16             IOIndex;                        /* 0x0C */
+    U16             ReplyFlags;                     /* 0x0E */
+} MPI3_TARGET_COMMAND_BUFFER_REPLY_DESCRIPTOR, MPI3_POINTER PTR_MPI3_TARGET_COMMAND_BUFFER_REPLY_DESCRIPTOR,
+  Mpi3TargetCommandBufferReplyDescriptor_t, MPI3_POINTER pMpi3TargetCommandBufferReplyDescriptor_t;
+
+/**** See Default Reply Descriptor Defines above for definitions in the ReplyFlags field ****/
+
+/*****************************************************************************
+ *              Status Reply Descriptor                                      *
+ ****************************************************************************/
+typedef struct _MPI3_STATUS_REPLY_DESCRIPTOR {
+    U16             IOCStatus;                      /* 0x00 */
+    U16             Reserved02;                     /* 0x02 */
+    U32             IOCLogInfo;                     /* 0x04 */
+    U16             RequestQueueCI;                 /* 0x08 */
+    U16             RequestQueueID;                 /* 0x0A */
+    U16             HostTag;                        /* 0x0C */
+    U16             ReplyFlags;                     /* 0x0E */
+} MPI3_STATUS_REPLY_DESCRIPTOR, MPI3_POINTER PTR_MPI3_STATUS_REPLY_DESCRIPTOR,
+  Mpi3StatusReplyDescriptor_t, MPI3_POINTER pMpi3StatusReplyDescriptor_t;
+
+/**** Defines for the IOCStatus field ****/
+#define MPI3_REPLY_DESCRIPT_STATUS_IOCSTATUS_LOGINFOAVAIL               (0x8000)
+#define MPI3_REPLY_DESCRIPT_STATUS_IOCSTATUS_STATUS_MASK                (0x7FFF)
+
+/**** Defines for the IOCLogInfo field ****/
+#define MPI3_REPLY_DESCRIPT_STATUS_IOCLOGINFO_TYPE_MASK                 (0xF0000000)
+#define MPI3_REPLY_DESCRIPT_STATUS_IOCLOGINFO_TYPE_NO_INFO              (0x00000000)
+#define MPI3_REPLY_DESCRIPT_STATUS_IOCLOGINFO_TYPE_SAS                  (0x30000000)
+#define MPI3_REPLY_DESCRIPT_STATUS_IOCLOGINFO_DATA_MASK                 (0x0FFFFFFF)
+
+/*****************************************************************************
+ *              Union of Reply Descriptors                                   *
+ ****************************************************************************/
+typedef union _MPI3_REPLY_DESCRIPTORS_UNION {
+    MPI3_DEFAULT_REPLY_DESCRIPTOR               Default;
+    MPI3_ADDRESS_REPLY_DESCRIPTOR               AddressReply;
+    MPI3_SUCCESS_REPLY_DESCRIPTOR               Success;
+    MPI3_TARGET_COMMAND_BUFFER_REPLY_DESCRIPTOR TargetCommandBuffer;
+    MPI3_STATUS_REPLY_DESCRIPTOR                Status;
+    U32                                         Words[4];
+} MPI3_REPLY_DESCRIPTORS_UNION, MPI3_POINTER PTR_MPI3_REPLY_DESCRIPTORS_UNION,
+  Mpi3ReplyDescriptorsUnion_t, MPI3_POINTER pMpi3ReplyDescriptorsUnion_t;
+
+
+/*****************************************************************************
+ *              Scatter Gather Elements                                      *
+ ****************************************************************************/
+
+/*****************************************************************************
+ *              Common structure for Simple, Chain, and Last Chain           *
+ *              scatter gather elements                                      *
+ ****************************************************************************/
+typedef struct _MPI3_SGE_COMMON {
+    U64             Address;                           /* 0x00 */
+    U32             Length;                            /* 0x08 */
+    U8              Reserved0C[3];                     /* 0x0C */
+    U8              Flags;                             /* 0x0F */
+} MPI3_SGE_SIMPLE, MPI3_POINTER PTR_MPI3_SGE_SIMPLE,
+  Mpi3SGESimple_t, MPI3_POINTER pMpi3SGESimple_t,
+  MPI3_SGE_CHAIN, MPI3_POINTER PTR_MPI3_SGE_CHAIN,
+  Mpi3SGEChain_t, MPI3_POINTER pMpi3SGEChain_t,
+  MPI3_SGE_LAST_CHAIN, MPI3_POINTER PTR_MPI3_SGE_LAST_CHAIN,
+  Mpi3SGELastChain_t, MPI3_POINTER pMpi3SGELastChain_t;
+
+/*****************************************************************************
+ *              Bit Bucket scatter gather element                            *
+ ****************************************************************************/
+typedef struct _MPI3_SGE_BIT_BUCKET {
+    U64             Reserved00;                        /* 0x00 */
+    U32             Length;                            /* 0x08 */
+    U8              Reserved0C[3];                     /* 0x0C */
+    U8              Flags;                             /* 0x0F */
+} MPI3_SGE_BIT_BUCKET, MPI3_POINTER PTR_MPI3_SGE_BIT_BUCKET,
+  Mpi3SGEBitBucket, MPI3_POINTER pMpi3SGEBitBucket;
+
+/*****************************************************************************
+ *              Extended EEDP scatter gather element                         *
+ ****************************************************************************/
+typedef struct _MPI3_SGE_EXTENDED_EEDP {
+    U8              UserDataSize;                      /* 0x00 */
+    U8              Reserved01;                        /* 0x01 */
+    U16             EEDPFlags;                         /* 0x02 */
+    U32             SecondaryReferenceTag;             /* 0x04 */
+    U16             SecondaryApplicationTag;           /* 0x08 */
+    U16             ApplicationTagTranslationMask;     /* 0x0A */
+    U16             Reserved0C;                        /* 0x0C */
+    U8              ExtendedOperation;                 /* 0x0E */
+    U8              Flags;                             /* 0x0F */
+} MPI3_SGE_EXTENDED_EEDP, MPI3_POINTER PTR_MPI3_SGE_EXTENDED_EEDP,
+  Mpi3SGEExtendedEEDP_t, MPI3_POINTER pMpi3SGEExtendedEEDP_t;
+
+/*****************************************************************************
+ *              Union of scatter gather elements                             *
+ ****************************************************************************/
+typedef union _MPI3_SGE_UNION {
+    MPI3_SGE_SIMPLE                 Simple;
+    MPI3_SGE_CHAIN                  Chain;
+    MPI3_SGE_LAST_CHAIN             LastChain;
+    MPI3_SGE_BIT_BUCKET             BitBucket;
+    MPI3_SGE_EXTENDED_EEDP          Eedp;
+    U32                             Words[4];
+} MPI3_SGE_UNION, MPI3_POINTER PTR_MPI3_SGE_UNION,
+  Mpi3SGEUnion_t, MPI3_POINTER pMpi3SGEUnion_t;
+
+/**** Definitions for the Flags field ****/
+#define MPI3_SGE_FLAGS_ELEMENT_TYPE_MASK        (0xF0)
+#define MPI3_SGE_FLAGS_ELEMENT_TYPE_SIMPLE      (0x00)
+#define MPI3_SGE_FLAGS_ELEMENT_TYPE_BIT_BUCKET  (0x10)
+#define MPI3_SGE_FLAGS_ELEMENT_TYPE_CHAIN       (0x20)
+#define MPI3_SGE_FLAGS_ELEMENT_TYPE_LAST_CHAIN  (0x30)
+#define MPI3_SGE_FLAGS_ELEMENT_TYPE_EXTENDED    (0xF0)
+#define MPI3_SGE_FLAGS_END_OF_LIST              (0x08)
+#define MPI3_SGE_FLAGS_END_OF_BUFFER            (0x04)
+#define MPI3_SGE_FLAGS_DLAS_MASK                (0x03)
+#define MPI3_SGE_FLAGS_DLAS_SYSTEM              (0x00)
+#define MPI3_SGE_FLAGS_DLAS_IOC_DDR             (0x01)
+#define MPI3_SGE_FLAGS_DLAS_IOC_CTL             (0x02)
+
+/**** Definitions for the ExtendedOperation field of Extended element ****/
+#define MPI3_SGE_EXT_OPER_EEDP                  (0x00)
+
+/**** Definitions for the EEDPFlags field of Extended EEDP element ****/
+#define MPI3_EEDPFLAGS_INCR_PRI_REF_TAG             (0x8000)
+#define MPI3_EEDPFLAGS_INCR_SEC_REF_TAG             (0x4000)
+#define MPI3_EEDPFLAGS_INCR_PRI_APP_TAG             (0x2000)
+#define MPI3_EEDPFLAGS_INCR_SEC_APP_TAG             (0x1000)
+#define MPI3_EEDPFLAGS_ESC_PASSTHROUGH              (0x0800)
+#define MPI3_EEDPFLAGS_CHK_REF_TAG                  (0x0400)
+#define MPI3_EEDPFLAGS_CHK_APP_TAG                  (0x0200)
+#define MPI3_EEDPFLAGS_CHK_GUARD                    (0x0100)
+#define MPI3_EEDPFLAGS_ESC_MODE_MASK                (0x00C0)
+#define MPI3_EEDPFLAGS_ESC_MODE_DO_NOT_DISABLE      (0x0040)
+#define MPI3_EEDPFLAGS_ESC_MODE_APPTAG_DISABLE      (0x0080)
+#define MPI3_EEDPFLAGS_ESC_MODE_APPTAG_REFTAG_DISABLE   (0x00C0)
+#define MPI3_EEDPFLAGS_HOST_GUARD_MASK              (0x0030)
+#define MPI3_EEDPFLAGS_HOST_GUARD_T10_CRC           (0x0000)
+#define MPI3_EEDPFLAGS_HOST_GUARD_IP_CHKSUM         (0x0010)
+#define MPI3_EEDPFLAGS_HOST_GUARD_OEM_SPECIFIC      (0x0020)
+#define MPI3_EEDPFLAGS_PT_REF_TAG                   (0x0008)
+#define MPI3_EEDPFLAGS_EEDP_OP_MASK                 (0x0007)
+#define MPI3_EEDPFLAGS_EEDP_OP_NOOP                 (0x0000)
+#define MPI3_EEDPFLAGS_EEDP_OP_CHECK                (0x0001)
+#define MPI3_EEDPFLAGS_EEDP_OP_STRIP                (0x0002)
+#define MPI3_EEDPFLAGS_EEDP_OP_CHECK_REMOVE         (0x0003)
+#define MPI3_EEDPFLAGS_EEDP_OP_INSERT               (0x0004)
+#define MPI3_EEDPFLAGS_EEDP_OP_REPLACE              (0x0006)
+#define MPI3_EEDPFLAGS_EEDP_OP_CHECK_REGEN          (0x0007)
+
+/**** Definitions for the UserDataSize field of Extended EEDP element ****/
+#define MPI3_EEDP_UDS_512                           (0x01)
+#define MPI3_EEDP_UDS_520                           (0x02)
+#define MPI3_EEDP_UDS_4080                          (0x03)
+#define MPI3_EEDP_UDS_4088                          (0x04)
+#define MPI3_EEDP_UDS_4096                          (0x05)
+#define MPI3_EEDP_UDS_4104                          (0x06)
+#define MPI3_EEDP_UDS_4160                          (0x07)
+
+/*****************************************************************************
+ *              Standard Message Structures                                  *
+ ****************************************************************************/
+
+/*****************************************************************************
+ *              Request Message Header for all request messages              *
+ ****************************************************************************/
+typedef struct _MPI3_REQUEST_HEADER {
+    U16             HostTag;                    /* 0x00 */
+    U8              IOCUseOnly02;               /* 0x02 */
+    U8              Function;                   /* 0x03 */
+    U16             IOCUseOnly04;               /* 0x04 */
+    U8              IOCUseOnly06;               /* 0x06 */
+    U8              MsgFlags;                   /* 0x07 */
+    U16             ChangeCount;                /* 0x08 */
+    U16             FunctionDependent;          /* 0x0A */
+} MPI3_REQUEST_HEADER, MPI3_POINTER PTR_MPI3_REQUEST_HEADER,
+  Mpi3RequestHeader_t, MPI3_POINTER pMpi3RequestHeader_t;
+
+/*****************************************************************************
+ *              Default Reply                                                *
+ ****************************************************************************/
+typedef struct _MPI3_DEFAULT_REPLY {
+    U16             HostTag;                    /* 0x00 */
+    U8              IOCUseOnly02;               /* 0x02 */
+    U8              Function;                   /* 0x03 */
+    U16             IOCUseOnly04;               /* 0x04 */
+    U8              IOCUseOnly06;               /* 0x06 */
+    U8              MsgFlags;                   /* 0x07 */
+    U16             IOCUseOnly08;               /* 0x08 */
+    U16             IOCStatus;                  /* 0x0A */
+    U32             IOCLogInfo;                 /* 0x0C */
+} MPI3_DEFAULT_REPLY, MPI3_POINTER PTR_MPI3_DEFAULT_REPLY,
+  Mpi3DefaultReply_t, MPI3_POINTER pMpi3DefaultReply_t;
+
+/**** Defines for the HostTag field ****/
+#define MPI3_HOST_TAG_INVALID                       (0xFFFF)
+
+/**** Defines for message Function ****/
+/* I/O Controller functions */
+#define MPI3_FUNCTION_IOC_FACTS                     (0x01) /* IOC Facts */
+#define MPI3_FUNCTION_IOC_INIT                      (0x02) /* IOC Init */
+#define MPI3_FUNCTION_PORT_ENABLE                   (0x03) /* Port Enable */
+#define MPI3_FUNCTION_EVENT_NOTIFICATION            (0x04) /* Event Notification */
+#define MPI3_FUNCTION_EVENT_ACK                     (0x05) /* Event Acknowledge */
+#define MPI3_FUNCTION_CI_DOWNLOAD                   (0x06) /* Component Image Download */
+#define MPI3_FUNCTION_CI_UPLOAD                     (0x07) /* Component Image Upload */
+#define MPI3_FUNCTION_IO_UNIT_CONTROL               (0x08) /* IO Unit Control */
+#define MPI3_FUNCTION_PERSISTENT_EVENT_LOG          (0x09) /* Persistent Event Log */
+#define MPI3_FUNCTION_MGMT_PASSTHROUGH              (0x0A) /* Management Passthrough */
+#define MPI3_FUNCTION_CONFIG                        (0x10) /* Configuration */
+
+/* SCSI Initiator I/O functions */
+#define MPI3_FUNCTION_SCSI_IO                       (0x20) /* SCSI IO */
+#define MPI3_FUNCTION_SCSI_TASK_MGMT                (0x21) /* SCSI Task Management */
+#define MPI3_FUNCTION_SMP_PASSTHROUGH               (0x22) /* SMP Passthrough */
+#define MPI3_FUNCTION_NVME_ENCAPSULATED             (0x24) /* NVMe Encapsulated */
+
+/* SCSI Target I/O functions */
+#define MPI3_FUNCTION_TARGET_ASSIST                 (0x30) /* Target Assist */
+#define MPI3_FUNCTION_TARGET_STATUS_SEND            (0x31) /* Target Status Send */
+#define MPI3_FUNCTION_TARGET_MODE_ABORT             (0x32) /* Target Mode Abort */
+#define MPI3_FUNCTION_TARGET_CMD_BUF_POST_BASE      (0x33) /* Target Command Buffer Post Base */
+#define MPI3_FUNCTION_TARGET_CMD_BUF_POST_LIST      (0x34) /* Target Command Buffer Post List */
+
+/* Queue Management functions */
+#define MPI3_FUNCTION_CREATE_REQUEST_QUEUE          (0x70)  /* Create an operational request queue */
+#define MPI3_FUNCTION_DELETE_REQUEST_QUEUE          (0x71)  /* Delete an operational request queue */
+#define MPI3_FUNCTION_CREATE_REPLY_QUEUE            (0x72)  /* Create an operational reply queue */
+#define MPI3_FUNCTION_DELETE_REPLY_QUEUE            (0x73)  /* Delete an operational reply queue */
+
+/* Diagnostic Tools */
+#define MPI3_FUNCTION_TOOLBOX                       (0x80) /* Toolbox */
+#define MPI3_FUNCTION_DIAG_BUFFER_POST              (0x81) /* Post a Diagnostic Buffer to the I/O Unit */
+#define MPI3_FUNCTION_DIAG_BUFFER_MANAGE            (0x82) /* Manage a Diagnostic Buffer */
+#define MPI3_FUNCTION_DIAG_BUFFER_UPLOAD            (0x83) /* Upload a Diagnostic Buffer */
+
+/* Miscellaneous functions */
+#define MPI3_FUNCTION_MIN_IOC_USE_ONLY              (0xC0)  /* Beginning of IOC Use Only range of function codes */
+#define MPI3_FUNCTION_MAX_IOC_USE_ONLY              (0xEF)  /* End of IOC Use Only range of function codes */
+#define MPI3_FUNCTION_MIN_PRODUCT_SPECIFIC          (0xF0)  /* Beginning of the product-specific range of function codes */
+#define MPI3_FUNCTION_MAX_PRODUCT_SPECIFIC          (0xFF)  /* End of the product-specific range of function codes */
+
+/**** Defines for IOCStatus ****/
+#define MPI3_IOCSTATUS_LOG_INFO_AVAIL_MASK          (0x8000)
+#define MPI3_IOCSTATUS_LOG_INFO_AVAILABLE           (0x8000)
+#define MPI3_IOCSTATUS_STATUS_MASK                  (0x7FFF)
+
+/* Common IOCStatus values for all replies */
+#define MPI3_IOCSTATUS_SUCCESS                      (0x0000)
+#define MPI3_IOCSTATUS_INVALID_FUNCTION             (0x0001)
+#define MPI3_IOCSTATUS_BUSY                         (0x0002)
+#define MPI3_IOCSTATUS_INVALID_SGL                  (0x0003)
+#define MPI3_IOCSTATUS_INTERNAL_ERROR               (0x0004)
+#define MPI3_IOCSTATUS_INSUFFICIENT_RESOURCES       (0x0006)
+#define MPI3_IOCSTATUS_INVALID_FIELD                (0x0007)
+#define MPI3_IOCSTATUS_INVALID_STATE                (0x0008)
+#define MPI3_IOCSTATUS_INSUFFICIENT_POWER           (0x000A)
+#define MPI3_IOCSTATUS_INVALID_CHANGE_COUNT         (0x000B)
+#define MPI3_IOCSTATUS_FAILURE                      (0x001F)
+
+/* Config IOCStatus values */
+#define MPI3_IOCSTATUS_CONFIG_INVALID_ACTION        (0x0020)
+#define MPI3_IOCSTATUS_CONFIG_INVALID_TYPE          (0x0021)
+#define MPI3_IOCSTATUS_CONFIG_INVALID_PAGE          (0x0022)
+#define MPI3_IOCSTATUS_CONFIG_INVALID_DATA          (0x0023)
+#define MPI3_IOCSTATUS_CONFIG_NO_DEFAULTS           (0x0024)
+#define MPI3_IOCSTATUS_CONFIG_CANT_COMMIT           (0x0025)
+
+/* SCSI IO IOCStatus values */
+#define MPI3_IOCSTATUS_SCSI_RECOVERED_ERROR         (0x0040)
+#define MPI3_IOCSTATUS_SCSI_TM_NOT_SUPPORTED        (0x0041)
+#define MPI3_IOCSTATUS_SCSI_INVALID_DEVHANDLE       (0x0042)
+#define MPI3_IOCSTATUS_SCSI_DEVICE_NOT_THERE        (0x0043)
+#define MPI3_IOCSTATUS_SCSI_DATA_OVERRUN            (0x0044)
+#define MPI3_IOCSTATUS_SCSI_DATA_UNDERRUN           (0x0045)
+#define MPI3_IOCSTATUS_SCSI_IO_DATA_ERROR           (0x0046)
+#define MPI3_IOCSTATUS_SCSI_PROTOCOL_ERROR          (0x0047)
+#define MPI3_IOCSTATUS_SCSI_TASK_TERMINATED         (0x0048)
+#define MPI3_IOCSTATUS_SCSI_RESIDUAL_MISMATCH       (0x0049)
+#define MPI3_IOCSTATUS_SCSI_TASK_MGMT_FAILED        (0x004A)
+#define MPI3_IOCSTATUS_SCSI_IOC_TERMINATED          (0x004B)
+#define MPI3_IOCSTATUS_SCSI_EXT_TERMINATED          (0x004C)
+
+/* SCSI Initiator and SCSI Target end-to-end data protection values */
+#define MPI3_IOCSTATUS_EEDP_GUARD_ERROR             (0x004D)
+#define MPI3_IOCSTATUS_EEDP_REF_TAG_ERROR           (0x004E)
+#define MPI3_IOCSTATUS_EEDP_APP_TAG_ERROR           (0x004F)
+
+/* SCSI Target IOCStatus values */
+#define MPI3_IOCSTATUS_TARGET_INVALID_IO_INDEX      (0x0062)
+#define MPI3_IOCSTATUS_TARGET_ABORTED               (0x0063)
+#define MPI3_IOCSTATUS_TARGET_NO_CONN_RETRYABLE     (0x0064)
+#define MPI3_IOCSTATUS_TARGET_NO_CONNECTION         (0x0065)
+#define MPI3_IOCSTATUS_TARGET_XFER_COUNT_MISMATCH   (0x006A)
+#define MPI3_IOCSTATUS_TARGET_DATA_OFFSET_ERROR     (0x006D)
+#define MPI3_IOCSTATUS_TARGET_TOO_MUCH_WRITE_DATA   (0x006E)
+#define MPI3_IOCSTATUS_TARGET_IU_TOO_SHORT          (0x006F)
+#define MPI3_IOCSTATUS_TARGET_ACK_NAK_TIMEOUT       (0x0070)
+#define MPI3_IOCSTATUS_TARGET_NAK_RECEIVED          (0x0071)
+
+/* Serial Attached SCSI IOCStatus values */
+#define MPI3_IOCSTATUS_SAS_SMP_REQUEST_FAILED       (0x0090)
+#define MPI3_IOCSTATUS_SAS_SMP_DATA_OVERRUN         (0x0091)
+
+/* Diagnostic Buffer Post/Release IOCStatus values */
+#define MPI3_IOCSTATUS_DIAGNOSTIC_RELEASED          (0x00A0)
+
+/* Component Image Upload/Download */
+#define MPI3_IOCSTATUS_CI_UNSUPPORTED               (0x00B0)
+#define MPI3_IOCSTATUS_CI_UPDATE_SEQUENCE           (0x00B1)
+#define MPI3_IOCSTATUS_CI_VALIDATION_FAILED         (0x00B2)
+#define MPI3_IOCSTATUS_CI_UPDATE_PENDING            (0x00B3)
+
+/* Security values */
+#define MPI3_IOCSTATUS_SECURITY_KEY_REQUIRED        (0x00C0)
+
+/* Request and Reply Queues related IOCStatus values */
+#define MPI3_IOCSTATUS_INVALID_QUEUE_ID             (0x0F00)
+#define MPI3_IOCSTATUS_INVALID_QUEUE_SIZE           (0x0F01)
+#define MPI3_IOCSTATUS_INVALID_MSIX_VECTOR          (0x0F02)
+#define MPI3_IOCSTATUS_INVALID_REPLY_QUEUE_ID       (0x0F03)
+#define MPI3_IOCSTATUS_INVALID_QUEUE_DELETION       (0x0F04)
+
+/**** Defines for IOCLogInfo ****/
+#define MPI3_IOCLOGINFO_TYPE_MASK               (0xF0000000)
+#define MPI3_IOCLOGINFO_TYPE_SHIFT              (28)
+#define MPI3_IOCLOGINFO_TYPE_NONE               (0x0)
+#define MPI3_IOCLOGINFO_TYPE_SAS                (0x3)
+#define MPI3_IOCLOGINFO_LOG_DATA_MASK           (0x0FFFFFFF)
+
+#endif  /* MPI30_TRANSPORT_H */
diff --git a/drivers/scsi/mpi3mr/mpi/mpi30_type.h b/drivers/scsi/mpi3mr/mpi/mpi30_type.h
new file mode 100644
index 000000000000..5de35e7a660f
--- /dev/null
+++ b/drivers/scsi/mpi3mr/mpi/mpi30_type.h
@@ -0,0 +1,89 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ *  Copyright 2016-2020 Broadcom Inc. All rights reserved.
+ *
+ *           Name: mpi30_type.h
+ *    Description: MPI basic type definitions
+ *  Creation Date: 10/07/2016
+ *        Version: 03.00.00
+ */
+#ifndef MPI30_TYPE_H
+#define MPI30_TYPE_H     1
+
+/*****************************************************************************
+ * Define MPI3_POINTER if it has not already been defined. By default        *
+ * MPI3_POINTER is defined to be a near pointer. MPI3_POINTER can be defined *
+ * as a far pointer by defining MPI3_POINTER as "far *" before this header   *
+ * file is included.                                                         *
+ ****************************************************************************/
+#ifndef MPI3_POINTER
+#define MPI3_POINTER    *
+#endif  /* MPI3_POINTER */
+
+/* The basic types may have already been included by mpi_type.h or mpi2_type.h*/
+#if !defined(MPI_TYPE_H) && !defined(MPI2_TYPE_H)
+#if 1
+/*****************************************************************************
+*
+*               Basic Types
+*
+*****************************************************************************/
+
+typedef u8 U8;
+typedef __le16 U16;
+typedef __le32 U32;
+typedef __le64 U64 __aligned(4);
+
+/*****************************************************************************
+*
+*               Pointer Types
+*
+*****************************************************************************/
+
+typedef U8 * PU8;
+typedef U16 * PU16;
+typedef U32 * PU32;
+typedef U64 * PU64;
+#else
+/*****************************************************************************
+ *              Basic Types                                                  *
+ ****************************************************************************/
+typedef int8_t      S8;
+typedef uint8_t     U8;
+typedef int16_t     S16;
+typedef uint16_t    U16;
+typedef int32_t     S32;
+typedef uint32_t    U32;
+typedef int64_t     S64;
+typedef uint64_t    U64;
+
+/*****************************************************************************
+ *              Structure Types                                              *
+ ****************************************************************************/
+typedef struct _S64struct {
+    U32         Low;
+    S32         High;
+} S64struct;
+
+typedef struct _U64struct {
+    U32         Low;
+    U32         High;
+} U64struct;
+
+/*****************************************************************************
+ *              Pointer Types                                                *
+ ****************************************************************************/
+typedef S8 * PS8;
+typedef U8 * PU8;
+typedef S16 * PS16;
+typedef U16 * PU16;
+typedef S32         *PS32;
+typedef U32         *PU32;
+typedef S64 * PS64;
+typedef U64 * PU64;
+typedef S64struct * PS64struct;
+typedef U64struct * PU64struct;
+#endif
+#endif  /* MPI_TYPE_H && MPI2_TYPE_H */
+
+#endif  /* MPI30_TYPE_H */
-- 
2.18.1


-- 
This electronic communication and the information and any files transmitted 
with it, or attached to it, are confidential and are intended solely for 
the use of the individual or entity to whom it is addressed and may contain 
information that is confidential, legally privileged, protected by privacy 
laws, or otherwise restricted from disclosure to anyone else. If you are 
not the intended recipient or the person responsible for delivering the 
e-mail to the intended recipient, you are hereby notified that any use, 
copying, distributing, dissemination, forwarding, printing, or copying of 
this e-mail is strictly prohibited. If you received this e-mail in error, 
please return the e-mail to the sender, delete it from your computer, and 
destroy any printed copy of it.

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4169 bytes --]

^ permalink raw reply related	[flat|nested] 75+ messages in thread

* [PATCH 02/24] mpi3mr: base driver code
  2020-12-22 10:11 [PATCH 00/24] Introducing mpi3mr driver Kashyap Desai
  2020-12-22 10:11 ` [PATCH 01/24] mpi3mr: add mpi30 Rev-R headers and Kconfig Kashyap Desai
@ 2020-12-22 10:11 ` Kashyap Desai
  2020-12-27 14:14     ` kernel test robot
  2021-02-23 12:55   ` Hannes Reinecke
  2020-12-22 10:11 ` [PATCH 03/24] mpi3mr: create operational request and reply queue pair Kashyap Desai
                   ` (22 subsequent siblings)
  24 siblings, 2 replies; 75+ messages in thread
From: Kashyap Desai @ 2020-12-22 10:11 UTC (permalink / raw)
  To: linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, Kashyap Desai, sathya.prakash

[-- Attachment #1: Type: text/plain, Size: 83341 bytes --]

This patch covers basic pci device driver requirements -
device probe, memory allocation, mapping system registers,
allocate irq lines etc.

Source is managed in mainly three different files.

mpi3mr_fw.c -	Keep common code which interact with underlying fw/hw.
mpi3mr_os.c -	Keep common code which interact with scsi midlayer.
mpi3mr_app.c -	Keep common code which interact with application/ioctl.
		This is currently work in progress.

Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Cc: sathya.prakash@broadcom.com
---
 drivers/scsi/mpi3mr/Makefile       |    4 +
 drivers/scsi/mpi3mr/mpi3mr.h       |  526 ++++++++
 drivers/scsi/mpi3mr/mpi3mr_debug.h |   60 +
 drivers/scsi/mpi3mr/mpi3mr_fw.c    | 1819 ++++++++++++++++++++++++++++
 drivers/scsi/mpi3mr/mpi3mr_os.c    |  368 ++++++
 5 files changed, 2777 insertions(+)
 create mode 100644 drivers/scsi/mpi3mr/Makefile
 create mode 100644 drivers/scsi/mpi3mr/mpi3mr.h
 create mode 100644 drivers/scsi/mpi3mr/mpi3mr_debug.h
 create mode 100644 drivers/scsi/mpi3mr/mpi3mr_fw.c
 create mode 100644 drivers/scsi/mpi3mr/mpi3mr_os.c

diff --git a/drivers/scsi/mpi3mr/Makefile b/drivers/scsi/mpi3mr/Makefile
new file mode 100644
index 000000000000..7c2063e04c81
--- /dev/null
+++ b/drivers/scsi/mpi3mr/Makefile
@@ -0,0 +1,4 @@
+# mpi3mr makefile
+obj-m += mpi3mr.o
+mpi3mr-y +=  mpi3mr_os.o     \
+		mpi3mr_fw.o \
diff --git a/drivers/scsi/mpi3mr/mpi3mr.h b/drivers/scsi/mpi3mr/mpi3mr.h
new file mode 100644
index 000000000000..dd79b12218e1
--- /dev/null
+++ b/drivers/scsi/mpi3mr/mpi3mr.h
@@ -0,0 +1,526 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Driver for Broadcom MPI3 Storage Controllers
+ *
+ * Copyright (C) 2017-2020 Broadcom Inc.
+ *  (mailto: mpi3mr-linuxdrv.pdl@broadcom.com)
+ *
+ */
+
+#ifndef MPI3MR_H_INCLUDED
+#define MPI3MR_H_INCLUDED
+
+#include <linux/blkdev.h>
+#include <linux/blk-mq.h>
+#include <linux/blk-mq-pci.h>
+#include <linux/delay.h>
+#include <linux/dmapool.h>
+#include <linux/errno.h>
+#include <linux/init.h>
+#include <linux/io.h>
+#include <linux/interrupt.h>
+#include <linux/kernel.h>
+#include <linux/miscdevice.h>
+#include <linux/module.h>
+#include <linux/pci.h>
+#include <linux/poll.h>
+#include <linux/sched.h>
+#include <linux/slab.h>
+#include <linux/types.h>
+#include <linux/uaccess.h>
+#include <linux/utsname.h>
+#include <linux/version.h>
+#include <linux/workqueue.h>
+#include <asm/unaligned.h>
+#include <scsi/scsi.h>
+#include <scsi/scsi_cmnd.h>
+#include <scsi/scsi_dbg.h>
+#include <scsi/scsi_device.h>
+#include <scsi/scsi_host.h>
+#include <scsi/scsi_tcq.h>
+
+#include "mpi/mpi30_api.h"
+#include "mpi3mr_debug.h"
+
+/* Global list and lock for storing multiple adapters managed by the driver */
+extern spinlock_t mrioc_list_lock;
+extern struct list_head mrioc_list;
+
+#define MPI3MR_DRIVER_VERSION	"00.255.45.01"
+#define MPI3MR_DRIVER_RELDATE	"12-December-2020"
+
+#define MPI3MR_DRIVER_NAME	"mpi3mr"
+#define MPI3MR_DRIVER_LICENSE	"GPL"
+#define MPI3MR_DRIVER_AUTHOR	"Broadcom Inc. <mpi3mr-linuxdrv.pdl@broadcom.com>"
+#define MPI3MR_DRIVER_DESC	"MPI3 Storage Controller Device Driver"
+
+#define MPI3MR_NAME_LENGTH	32
+#define IOCNAME			"%s: "
+
+/* Definitions for internal SGL and Chain SGL buffers */
+#define MPI3MR_PAGE_SIZE_4K		4096
+#define MPI3MR_SG_DEPTH		(PAGE_SIZE/sizeof(Mpi3SGESimple_t))
+
+/* Definitions for MAX values for shost */
+#define MPI3MR_MAX_CMDS_LUN	7
+#define MPI3MR_MAX_CDB_LENGTH	32
+
+/* Admin queue management definitions */
+#define MPI3MR_ADMIN_REQ_Q_SIZE		(2 * MPI3MR_PAGE_SIZE_4K)
+#define MPI3MR_ADMIN_REPLY_Q_SIZE	(4 * MPI3MR_PAGE_SIZE_4K)
+#define MPI3MR_ADMIN_REQ_FRAME_SZ	128
+#define MPI3MR_ADMIN_REPLY_FRAME_SZ	16
+
+
+/* Reserved Host Tag definitions */
+#define MPI3MR_HOSTTAG_INVALID		0xFFFF
+#define MPI3MR_HOSTTAG_INITCMDS		1
+#define MPI3MR_HOSTTAG_IOCTLCMDS	2
+#define MPI3MR_HOSTTAG_BLK_TMS		5
+
+#define MPI3MR_NUM_DEVRMCMD		1
+#define MPI3MR_HOSTTAG_DEVRMCMD_MIN	(MPI3MR_HOSTTAG_BLK_TMS + 1)
+#define MPI3MR_HOSTTAG_DEVRMCMD_MAX	(MPI3MR_HOSTTAG_DEVRMCMD_MIN + \
+						MPI3MR_NUM_DEVRMCMD - 1)
+
+#define MPI3MR_INTERNAL_CMDS_RESVD     MPI3MR_HOSTTAG_DEVRMCMD_MAX
+
+/* Reduced resource count definition for crash kernel */
+#define MPI3MR_HOST_IOS_KDUMP		128
+
+/* command/controller interaction timeout definitions in seconds */
+#define MPI3MR_INTADMCMD_TIMEOUT		10
+#define MPI3MR_RESETTM_TIMEOUT			30
+#define MPI3MR_DEFAULT_SHUTDOWN_TIME		120
+
+#define MPI3MR_WATCHDOG_INTERVAL		1000 /* in milli seconds */
+
+/* Internal admin command state definitions*/
+#define MPI3MR_CMD_NOTUSED	0x8000
+#define MPI3MR_CMD_COMPLETE	0x0001
+#define MPI3MR_CMD_PENDING	0x0002
+#define MPI3MR_CMD_REPLY_VALID	0x0004
+#define MPI3MR_CMD_RESET	0x0008
+
+/* Definitions for Event replies and sense buffer allocated per controller */
+#define MPI3MR_NUM_EVT_REPLIES	64
+#define MPI3MR_SENSEBUF_SZ	256
+#define MPI3MR_SENSEBUF_FACTOR	3
+#define MPI3MR_CHAINBUF_FACTOR	3
+
+/* Invalid target device handle */
+#define MPI3MR_INVALID_DEV_HANDLE	0xFFFF
+
+/* Controller Reset related definitions */
+#define MPI3MR_HOSTDIAG_UNLOCK_RETRY_COUNT	5
+#define MPI3MR_MAX_RESET_RETRY_COUNT		3
+
+/* ResponseCode definitions */
+#define MPI3MR_RI_MASK_RESPCODE		(0x000000FF)
+#define MPI3MR_RSP_TM_COMPLETE		0x00
+#define MPI3MR_RSP_INVALID_FRAME	0x02
+#define MPI3MR_RSP_TM_NOT_SUPPORTED	0x04
+#define MPI3MR_RSP_TM_FAILED		0x05
+#define MPI3MR_RSP_TM_SUCCEEDED		0x08
+#define MPI3MR_RSP_TM_INVALID_LUN	0x09
+#define MPI3MR_RSP_TM_OVERLAPPED_TAG	0x0A
+#define MPI3MR_RSP_IO_QUEUED_ON_IOC \
+			MPI3_SCSITASKMGMT_RSPCODE_IO_QUEUED_ON_IOC
+
+/* SGE Flag definition */
+#define MPI3MR_SGEFLAGS_SYSTEM_SIMPLE_END_OF_LIST \
+	(MPI3_SGE_FLAGS_ELEMENT_TYPE_SIMPLE | MPI3_SGE_FLAGS_DLAS_SYSTEM | \
+	MPI3_SGE_FLAGS_END_OF_LIST)
+
+/* IOC State definitions */
+enum mpi3mr_iocstate {
+	MRIOC_STATE_READY = 1,
+	MRIOC_STATE_RESET,
+	MRIOC_STATE_FAULT,
+	MRIOC_STATE_BECOMING_READY,
+	MRIOC_STATE_RESET_REQUESTED,
+	MRIOC_STATE_UNRECOVERABLE,
+};
+
+/* Reset reason code definitions*/
+enum mpi3mr_reset_reason {
+	MPI3MR_RESET_FROM_BRINGUP = 1,
+	MPI3MR_RESET_FROM_FAULT_WATCH = 2,
+	MPI3MR_RESET_FROM_IOCTL = 3,
+	MPI3MR_RESET_FROM_EH_HOS = 4,
+	MPI3MR_RESET_FROM_TM_TIMEOUT = 5,
+	MPI3MR_RESET_FROM_IOCTL_TIMEOUT = 6,
+	MPI3MR_RESET_FROM_MUR_FAILURE = 7,
+	MPI3MR_RESET_FROM_CTLR_CLEANUP = 8,
+	MPI3MR_RESET_FROM_CIACTIV_FAULT = 9,
+	MPI3MR_RESET_FROM_PE_TIMEOUT = 10,
+	MPI3MR_RESET_FROM_TSU_TIMEOUT = 11,
+	MPI3MR_RESET_FROM_DELREQQ_TIMEOUT = 12,
+	MPI3MR_RESET_FROM_DELREPQ_TIMEOUT = 13,
+	MPI3MR_RESET_FROM_CREATEREPQ_TIMEOUT = 14,
+	MPI3MR_RESET_FROM_CREATEREQQ_TIMEOUT = 15,
+	MPI3MR_RESET_FROM_IOCFACTS_TIMEOUT = 16,
+	MPI3MR_RESET_FROM_IOCINIT_TIMEOUT = 17,
+	MPI3MR_RESET_FROM_EVTNOTIFY_TIMEOUT = 18,
+	MPI3MR_RESET_FROM_EVTACK_TIMEOUT = 19,
+	MPI3MR_RESET_FROM_CIACTVRST_TIMER = 20,
+	MPI3MR_RESET_FROM_GETPKGVER_TIMEOUT = 21,
+};
+
+/**
+ * struct mpi3mr_compimg_ver - replica of component image
+ * version defined in mpi30_image.h in host endianness
+ *
+ */
+struct mpi3mr_compimg_ver {
+	u16 build_num;
+	u16 cust_id;
+	u8 ph_minor;
+	u8 ph_major;
+	u8 gen_minor;
+	u8 gen_major;
+};
+
+/**
+ * struct mpi3mr_ioc_facs - replica of component image version
+ * defined in mpi30_ioc.h in host endianness
+ *
+ */
+struct mpi3mr_ioc_facts {
+	u32 ioc_capabilities;
+	struct mpi3mr_compimg_ver fw_ver;
+	u32 mpi_version;
+	u16 max_reqs;
+	u16 product_id;
+	u16 op_req_sz;
+	u16 reply_sz;
+	u16 exceptions;
+	u16 max_perids;
+	u16 max_pds;
+	u16 max_sasexpanders;
+	u16 max_sasinitiators;
+	u16 max_enclosures;
+	u16 max_pcieswitches;
+	u16 max_nvme;
+	u16 max_vds;
+	u16 max_hpds;
+	u16 max_advhpds;
+	u16 max_raidpds;
+	u16 min_devhandle;
+	u16 max_devhandle;
+	u16 max_op_req_q;
+	u16 max_op_reply_q;
+	u16 shutdown_timeout;
+	u8 ioc_num;
+	u8 who_init;
+	u16 max_msix_vectors;
+	u8 personality;
+	u8 dma_mask;
+	u8 protocol_flags;
+	u8 sge_mod_mask;
+	u8 sge_mod_value;
+	u8 sge_mod_shift;
+};
+
+/**
+ * struct op_req_qinfo -  Operational Request Queue Information
+ *
+ * @ci: consumer index
+ * @pi: producer index
+ */
+struct op_req_qinfo {
+	u16 ci;
+	u16 pi;
+};
+
+/**
+ * struct op_reply_qinfo -  Operational Reply Queue Information
+ *
+ * @ci: consumer index
+ * @qid: Queue Id starting from 1
+ */
+struct op_reply_qinfo {
+	u16 ci;
+	u16 qid;
+};
+
+/**
+ * struct mpi3mr_intr_info -  Interrupt cookie information
+ *
+ * @mrioc: Adapter instance reference
+ * @msix_index: MSIx index
+ * @op_reply_q: Associated operational reply queue
+ * @name: Dev name for the irq claiming device
+ */
+struct mpi3mr_intr_info {
+	struct mpi3mr_ioc *mrioc;
+	u16 msix_index;
+	struct op_reply_qinfo *op_reply_q;
+	char name[MPI3MR_NAME_LENGTH];
+};
+
+
+typedef struct mpi3mr_drv_cmd DRV_CMD;
+typedef void (*DRV_CMD_CALLBACK)(struct mpi3mr_ioc *mrioc,
+	DRV_CMD *drv_cmd);
+
+/**
+ * struct mpi3mr_drv_cmd - Internal command tracker
+ *
+ * @mutex: Command mutex
+ * @done: Completeor for wakeup
+ * @reply: Firmware reply for internal commands
+ * @sensebuf: Sensebuf for SCSI IO commands
+ * @state: Command State
+ * @dev_handle: Firmware handle for device specific commands
+ * @ioc_status: IOC status from the firmware
+ * @ioc_loginfo:IOC log info from the firmware
+ * @is_waiting: Is the command issued in block mode
+ * @retry_count: Retry count for retriable commands
+ * @host_tag: Host tag used by the command
+ * @callback: Callback for non blocking commands
+ */
+struct mpi3mr_drv_cmd {
+	struct mutex mutex;
+	struct completion done;
+	void *reply;
+	u8 *sensebuf;
+	u16 state;
+	u16 dev_handle;
+	u16 ioc_status;
+	u32 ioc_loginfo;
+	u8 is_waiting;
+	u8 retry_count;
+	u16 host_tag;
+	DRV_CMD_CALLBACK callback;
+};
+
+
+/**
+ * struct chain_element - memory descriptor structure to store
+ * virtual and dma addresses for chain elements.
+ *
+ * @addr: virtual address
+ * @dma_addr: dma address
+ */
+struct chain_element {
+	void *addr;
+	dma_addr_t dma_addr;
+};
+
+/**
+ * struct scmd_priv - SCSI command private data
+ *
+ * @host_tag: Host tag specific to operational queue
+ * @in_lld_scope: Command in LLD scope or not
+ * @scmd: SCSI Command pointer
+ * @req_q_idx: Operational request queue index
+ * @chain_idx: Chain frame index
+ * @mpi3mr_scsiio_req: MPI SCSI IO request
+ */
+struct scmd_priv {
+	u16 host_tag;
+	u8 in_lld_scope;
+	struct scsi_cmnd *scmd;
+	u16 req_q_idx;
+	int chain_idx;
+	u8 mpi3mr_scsiio_req[MPI3MR_ADMIN_REQ_FRAME_SZ];
+};
+
+/**
+ * struct mpi3mr_ioc - Adapter anchor structure stored in shost
+ * private data
+ *
+ * @list: List pointer
+ * @pdev: PCI device pointer
+ * @shost: Scsi_Host pointer
+ * @id: Controller ID
+ * @cpu_count: Number of online CPUs
+ * @name: Controller ASCII name
+ * @driver_name: Driver ASCII name
+ * @sysif_regs: System interface registers virtual address
+ * @sysif_regs_phys: System interface registers physical address
+ * @bars: PCI BARS
+ * @dma_mask: DMA mask
+ * @msix_count: Number of MSIX vectors used
+ * @intr_enabled: Is interrupts enabled
+ * @num_admin_req: Number of admin requests
+ * @admin_req_q_sz: Admin request queue size
+ * @admin_req_pi: Admin request queue producer index
+ * @admin_req_ci: Admin request queue consumer index
+ * @admin_req_base: Admin request queue base virtual address
+ * @admin_req_dma: Admin request queue base dma address
+ * @admin_req_lock: Admin queue access lock
+ * @num_admin_replies: Number of admin replies
+ * @admin_reply_q_sz: Admin reply queue size
+ * @admin_reply_ci: Admin reply queue consumer index
+ * @admin_reply_ephase:Admin reply queue expected phase
+ * @admin_reply_base: Admin reply queue base virtual address
+ * @admin_reply_dma: Admin reply queue base dma address
+ * @ready_timeout: Controller ready timeout
+ * @intr_info: Interrupt cookie pointer
+ * @intr_info_count: Number of interrupt cookies
+ * @num_queues: Number of operational queues
+ * @num_op_req_q: Number of operational request queues
+ * @req_qinfo: Operational request queue info pointer
+ * @num_op_reply_q: Number of operational reply queues
+ * @op_reply_qinfo: Operational reply queue info pointer
+ * @init_cmds: Command tracker for initialization commands
+ * @facts: Cached IOC facts data
+ * @op_reply_desc_sz: Operational reply descriptor size
+ * @num_reply_bufs: Number of reply buffers allocated
+ * @reply_buf_pool: Reply buffer pool
+ * @reply_buf: Reply buffer base virtual address
+ * @reply_buf_dma: Reply buffer DMA address
+ * @reply_buf_dma_max_address: Reply DMA address max limit
+ * @reply_free_qsz: Reply free queue size
+ * @reply_free_q_pool: Reply free queue pool
+ * @reply_free_q: Reply free queue base virtual address
+ * @reply_free_q_dma: Reply free queue base DMA address
+ * @reply_free_queue_lock: Reply free queue lock
+ * @reply_free_queue_host_index: Reply free queue host index
+ * @num_sense_bufs: Number of sense buffers
+ * @sense_buf_pool: Sense buffer pool
+ * @sense_buf: Sense buffer base virtual address
+ * @sense_buf_dma: Sense buffer base DMA address
+ * @sense_buf_q_sz: Sense buffer queue size
+ * @sense_buf_q_pool: Sense buffer queue pool
+ * @sense_buf_q: Sense buffer queue virtual address
+ * @sense_buf_q_dma: Sense buffer queue DMA address
+ * @sbq_lock: Sense buffer queue lock
+ * @sbq_host_index: Sense buffer queuehost index
+ * @is_driver_loading: Is driver still loading
+ * @max_host_ios: Maximum host I/O count
+ * @chain_buf_count: Chain buffer count
+ * @chain_buf_pool: Chain buffer pool
+ * @chain_sgl_list: Chain SGL list
+ * @chain_bitmap_sz: Chain buffer allocator bitmap size
+ * @chain_bitmap: Chain buffer allocator bitmap
+ * @reset_in_progress: Reset in progress flag
+ * @unrecoverable: Controller unrecoverable flag
+ * @logging_level: Controller debug logging level
+ * @current_event: Firmware event currently in process
+ * @driver_info: Driver, Kernel, OS information to firmware
+ * @change_count: Topology change count
+ */
+struct mpi3mr_ioc {
+	struct list_head list;
+	struct pci_dev *pdev;
+	struct Scsi_Host *shost;
+	u8 id;
+	int cpu_count;
+
+	char name[MPI3MR_NAME_LENGTH];
+	char driver_name[MPI3MR_NAME_LENGTH];
+
+	Mpi3SysIfRegs_t __iomem *sysif_regs;
+	resource_size_t sysif_regs_phys;
+	int bars;
+	u64 dma_mask;
+
+	u16 msix_count;
+	u8 intr_enabled;
+
+	u16 num_admin_req;
+	u32 admin_req_q_sz;
+	u16 admin_req_pi;
+	u16 admin_req_ci;
+	void *admin_req_base;
+	dma_addr_t admin_req_dma;
+	spinlock_t admin_req_lock;
+
+	u16 num_admin_replies;
+	u32 admin_reply_q_sz;
+	u16 admin_reply_ci;
+	u8 admin_reply_ephase;
+	void *admin_reply_base;
+	dma_addr_t admin_reply_dma;
+
+	u32 ready_timeout;
+
+	struct mpi3mr_intr_info *intr_info;
+	u16 intr_info_count;
+
+	u16 num_queues;
+	u16 num_op_req_q;
+	struct op_req_qinfo *req_qinfo;
+
+	u16 num_op_reply_q;
+	struct op_reply_qinfo *op_reply_qinfo;
+
+	struct mpi3mr_drv_cmd init_cmds;
+	struct mpi3mr_ioc_facts facts;
+	u16 op_reply_desc_sz;
+
+	u32 num_reply_bufs;
+	struct dma_pool *reply_buf_pool;
+	u8 *reply_buf;
+	dma_addr_t reply_buf_dma;
+	dma_addr_t reply_buf_dma_max_address;
+
+	u16 reply_free_qsz;
+	struct dma_pool *reply_free_q_pool;
+	U64 *reply_free_q;
+	dma_addr_t reply_free_q_dma;
+	spinlock_t reply_free_queue_lock;
+	u32 reply_free_queue_host_index;
+
+	u32 num_sense_bufs;
+	struct dma_pool *sense_buf_pool;
+	u8 *sense_buf;
+	dma_addr_t sense_buf_dma;
+
+	u16 sense_buf_q_sz;
+	struct dma_pool *sense_buf_q_pool;
+	U64 *sense_buf_q;
+	dma_addr_t sense_buf_q_dma;
+	spinlock_t sbq_lock;
+	u32 sbq_host_index;
+
+	u8 is_driver_loading;
+
+	u16 max_host_ios;
+
+	u32 chain_buf_count;
+	struct dma_pool *chain_buf_pool;
+	struct chain_element *chain_sgl_list;
+	u16  chain_bitmap_sz;
+	void *chain_bitmap;
+
+	u8 reset_in_progress;
+	u8 unrecoverable;
+
+	int logging_level;
+
+	struct mpi3mr_fwevt *current_event;
+	Mpi3DriverInfoLayout_t driver_info;
+	u16 change_count;
+};
+
+int mpi3mr_setup_resources(struct mpi3mr_ioc *mrioc);
+void mpi3mr_cleanup_resources(struct mpi3mr_ioc *mrioc);
+int mpi3mr_init_ioc(struct mpi3mr_ioc *mrioc);
+void mpi3mr_cleanup_ioc(struct mpi3mr_ioc *mrioc);
+int mpi3mr_admin_request_post(struct mpi3mr_ioc *mrioc, void *admin_req,
+u16 admin_req_sz, u8 ignore_reset);
+void mpi3mr_add_sg_single(void *paddr, u8 flags, u32 length,
+			  dma_addr_t dma_addr);
+void mpi3mr_build_zero_len_sge(void *paddr);
+void *mpi3mr_get_sensebuf_virt_addr(struct mpi3mr_ioc *mrioc,
+				     dma_addr_t phys_addr);
+void *mpi3mr_get_reply_virt_addr(struct mpi3mr_ioc *mrioc,
+				     dma_addr_t phys_addr);
+void mpi3mr_repost_sense_buf(struct mpi3mr_ioc *mrioc,
+				     u64 sense_buf_dma);
+
+void mpi3mr_start_watchdog(struct mpi3mr_ioc *mrioc);
+void mpi3mr_stop_watchdog(struct mpi3mr_ioc *mrioc);
+
+int mpi3mr_soft_reset_handler(struct mpi3mr_ioc *mrioc,
+			      u32 reset_reason, u8 snapdump);
+void mpi3mr_ioc_disable_intr(struct mpi3mr_ioc *mrioc);
+void mpi3mr_ioc_enable_intr(struct mpi3mr_ioc *mrioc);
+
+enum mpi3mr_iocstate mpi3mr_get_iocstate(struct mpi3mr_ioc *mrioc);
+
+#endif /*MPI3MR_H_INCLUDED*/
diff --git a/drivers/scsi/mpi3mr/mpi3mr_debug.h b/drivers/scsi/mpi3mr/mpi3mr_debug.h
new file mode 100644
index 000000000000..d35f296d9325
--- /dev/null
+++ b/drivers/scsi/mpi3mr/mpi3mr_debug.h
@@ -0,0 +1,60 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Driver for Broadcom MPI3 Storage Controllers
+ *
+ * Copyright (C) 2017-2020 Broadcom Inc.
+ *  (mailto: mpi3mr-linuxdrv.pdl@broadcom.com)
+ *
+ */
+
+#ifndef MPI3SAS_DEBUG_H_INCLUDED
+
+#define MPI3SAS_DEBUG_H_INCLUDED
+
+/*
+ * debug levels
+ */
+#define MPI3_DEBUG			0x00000001
+#define MPI3_DEBUG_MSG_FRAME		0x00000002
+#define MPI3_DEBUG_SG			0x00000004
+#define MPI3_DEBUG_EVENTS		0x00000008
+#define MPI3_DEBUG_EVENT_WORK_TASK	0x00000010
+#define MPI3_DEBUG_INIT			0x00000020
+#define MPI3_DEBUG_EXIT			0x00000040
+#define MPI3_DEBUG_FAIL			0x00000080
+#define MPI3_DEBUG_TM			0x00000100
+#define MPI3_DEBUG_REPLY		0x00000200
+#define MPI3_DEBUG_HANDSHAKE		0x00000400
+#define MPI3_DEBUG_CONFIG		0x00000800
+#define MPI3_DEBUG_DL			0x00001000
+#define MPI3_DEBUG_RESET		0x00002000
+#define MPI3_DEBUG_SCSI			0x00004000
+#define MPI3_DEBUG_IOCTL		0x00008000
+#define MPI3_DEBUG_CSMISAS		0x00010000
+#define MPI3_DEBUG_SAS			0x00020000
+#define MPI3_DEBUG_TRANSPORT		0x00040000
+#define MPI3_DEBUG_TASK_SET_FULL	0x00080000
+#define MPI3_DEBUG_TRIGGER_DIAG		0x00200000
+
+
+/*
+ * debug macros
+ */
+
+#define ioc_err(ioc, fmt, ...) \
+	pr_err("%s: " fmt, (ioc)->name, ##__VA_ARGS__)
+#define ioc_notice(ioc, fmt, ...) \
+	pr_notice("%s: " fmt, (ioc)->name, ##__VA_ARGS__)
+#define ioc_warn(ioc, fmt, ...) \
+	pr_warn("%s: " fmt, (ioc)->name, ##__VA_ARGS__)
+#define ioc_info(ioc, fmt, ...) \
+	pr_info("%s: " fmt, (ioc)->name, ##__VA_ARGS__)
+
+
+#define dbgprint(IOC, FMT, ...) \
+	do { \
+		if (IOC->logging_level & MPI3_DEBUG) \
+			pr_info("%s: " FMT, (IOC)->name, ##__VA_ARGS__); \
+	} while (0)
+
+#endif /* MPT3SAS_DEBUG_H_INCLUDED */
diff --git a/drivers/scsi/mpi3mr/mpi3mr_fw.c b/drivers/scsi/mpi3mr/mpi3mr_fw.c
new file mode 100644
index 000000000000..97eb7e6ec5c6
--- /dev/null
+++ b/drivers/scsi/mpi3mr/mpi3mr_fw.c
@@ -0,0 +1,1819 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Driver for Broadcom MPI3 Storage Controllers
+ *
+ * Copyright (C) 2017-2020 Broadcom Inc.
+ *  (mailto: mpi3mr-linuxdrv.pdl@broadcom.com)
+ *
+ */
+
+#include "mpi3mr.h"
+
+#if defined(writeq) && defined(CONFIG_64BIT)
+static inline void mpi3mr_writeq(__u64 b, volatile void __iomem *addr)
+{
+	writeq(b, addr);
+}
+#else
+static inline void mpi3mr_writeq(__u64 b, volatile void __iomem *addr)
+{
+	__u64 data_out = b;
+
+	writel((u32)(data_out), addr);
+	writel((u32)(data_out >> 32), (addr + 4));
+}
+#endif
+
+static void mpi3mr_sync_irqs(struct mpi3mr_ioc *mrioc)
+{
+	u16 i, max_vectors;
+
+	max_vectors = mrioc->intr_info_count;
+
+	for (i = 0; i < max_vectors; i++)
+		synchronize_irq(pci_irq_vector(mrioc->pdev, i));
+}
+
+void mpi3mr_ioc_disable_intr(struct mpi3mr_ioc *mrioc)
+{
+	mrioc->intr_enabled = 0;
+	mpi3mr_sync_irqs(mrioc);
+}
+
+void mpi3mr_ioc_enable_intr(struct mpi3mr_ioc *mrioc)
+{
+	mrioc->intr_enabled = 1;
+}
+
+static void mpi3mr_cleanup_isr(struct mpi3mr_ioc *mrioc)
+{
+	u16 i;
+
+	mpi3mr_ioc_disable_intr(mrioc);
+
+	if (!mrioc->intr_info)
+		return;
+
+	for (i = 0; i < mrioc->intr_info_count; i++)
+		free_irq(pci_irq_vector(mrioc->pdev, i),
+		    (mrioc->intr_info + i));
+
+	kfree(mrioc->intr_info);
+	mrioc->intr_info = NULL;
+	mrioc->intr_info_count = 0;
+	pci_free_irq_vectors(mrioc->pdev);
+}
+
+void mpi3mr_add_sg_single(void *paddr, u8 flags, u32 length,
+	dma_addr_t dma_addr)
+{
+	Mpi3SGESimple_t *sgel = paddr;
+
+	sgel->Flags = flags;
+	sgel->Length = cpu_to_le32(length);
+	sgel->Address = cpu_to_le64(dma_addr);
+}
+
+void mpi3mr_build_zero_len_sge(void *paddr)
+{
+	u8 sgl_flags = MPI3MR_SGEFLAGS_SYSTEM_SIMPLE_END_OF_LIST;
+
+	mpi3mr_add_sg_single(paddr, sgl_flags, 0, -1);
+
+}
+void *mpi3mr_get_reply_virt_addr(struct mpi3mr_ioc *mrioc,
+	dma_addr_t phys_addr)
+{
+	if (!phys_addr)
+		return NULL;
+
+	if ((phys_addr < mrioc->reply_buf_dma) ||
+	    (phys_addr > mrioc->reply_buf_dma_max_address))
+		return NULL;
+
+	return mrioc->reply_buf + (phys_addr - mrioc->reply_buf_dma);
+}
+
+void *mpi3mr_get_sensebuf_virt_addr(struct mpi3mr_ioc *mrioc,
+	dma_addr_t phys_addr)
+{
+	if (!phys_addr)
+		return NULL;
+
+	return mrioc->sense_buf + (phys_addr - mrioc->sense_buf_dma);
+}
+
+static void mpi3mr_repost_reply_buf(struct mpi3mr_ioc *mrioc,
+	u64 reply_dma)
+{
+	u32 old_idx = 0;
+
+	spin_lock(&mrioc->reply_free_queue_lock);
+	old_idx  =  mrioc->reply_free_queue_host_index;
+	mrioc->reply_free_queue_host_index = (
+	    (mrioc->reply_free_queue_host_index ==
+	    (mrioc->reply_free_qsz - 1)) ? 0 :
+	    (mrioc->reply_free_queue_host_index + 1));
+	mrioc->reply_free_q[old_idx] = cpu_to_le64(reply_dma);
+	writel(mrioc->reply_free_queue_host_index,
+	    &mrioc->sysif_regs->ReplyFreeHostIndex);
+	spin_unlock(&mrioc->reply_free_queue_lock);
+}
+
+void mpi3mr_repost_sense_buf(struct mpi3mr_ioc *mrioc,
+	u64 sense_buf_dma)
+{
+	u32 old_idx = 0;
+
+	spin_lock(&mrioc->sbq_lock);
+	old_idx  =  mrioc->sbq_host_index;
+	mrioc->sbq_host_index = ((mrioc->sbq_host_index ==
+	    (mrioc->sense_buf_q_sz - 1)) ? 0 :
+	    (mrioc->sbq_host_index + 1));
+	mrioc->sense_buf_q[old_idx] = cpu_to_le64(sense_buf_dma);
+	writel(mrioc->sbq_host_index,
+	    &mrioc->sysif_regs->SenseBufferFreeHostIndex);
+	spin_unlock(&mrioc->sbq_lock);
+}
+
+static void mpi3mr_handle_events(struct mpi3mr_ioc *mrioc,
+	Mpi3DefaultReply_t *def_reply)
+{
+	Mpi3EventNotificationReply_t *event_reply =
+	    (Mpi3EventNotificationReply_t *)def_reply;
+
+	mrioc->change_count = le16_to_cpu(event_reply->IOCChangeCount);
+}
+
+static struct mpi3mr_drv_cmd *
+mpi3mr_get_drv_cmd(struct mpi3mr_ioc *mrioc, u16 host_tag,
+	Mpi3DefaultReply_t *def_reply)
+{
+	switch (host_tag) {
+	case MPI3MR_HOSTTAG_INITCMDS:
+		return &mrioc->init_cmds;
+	case MPI3MR_HOSTTAG_INVALID:
+		if (def_reply && def_reply->Function ==
+		    MPI3_FUNCTION_EVENT_NOTIFICATION)
+			mpi3mr_handle_events(mrioc, def_reply);
+		return NULL;
+	default:
+		break;
+	}
+
+	return NULL;
+}
+
+static void mpi3mr_process_admin_reply_desc(struct mpi3mr_ioc *mrioc,
+	Mpi3DefaultReplyDescriptor_t *reply_desc, u64 *reply_dma)
+{
+	u16 reply_desc_type, host_tag = 0;
+	u16 ioc_status = MPI3_IOCSTATUS_SUCCESS;
+	u32 ioc_loginfo = 0;
+	Mpi3StatusReplyDescriptor_t *status_desc;
+	Mpi3AddressReplyDescriptor_t *addr_desc;
+	Mpi3SuccessReplyDescriptor_t *success_desc;
+	Mpi3DefaultReply_t *def_reply = NULL;
+	struct mpi3mr_drv_cmd *cmdptr = NULL;
+	Mpi3SCSIIOReply_t *scsi_reply;
+	u8 *sense_buf = NULL;
+
+	*reply_dma = 0;
+	reply_desc_type = le16_to_cpu(reply_desc->ReplyFlags) &
+	    MPI3_REPLY_DESCRIPT_FLAGS_TYPE_MASK;
+	switch (reply_desc_type) {
+	case MPI3_REPLY_DESCRIPT_FLAGS_TYPE_STATUS:
+		status_desc = (Mpi3StatusReplyDescriptor_t *)reply_desc;
+		host_tag = le16_to_cpu(status_desc->HostTag);
+		ioc_status = le16_to_cpu(status_desc->IOCStatus);
+		if (ioc_status &
+		    MPI3_REPLY_DESCRIPT_STATUS_IOCSTATUS_LOGINFOAVAIL)
+			ioc_loginfo = le32_to_cpu(status_desc->IOCLogInfo);
+		ioc_status &= MPI3_REPLY_DESCRIPT_STATUS_IOCSTATUS_STATUS_MASK;
+		break;
+	case MPI3_REPLY_DESCRIPT_FLAGS_TYPE_ADDRESS_REPLY:
+		addr_desc = (Mpi3AddressReplyDescriptor_t *)reply_desc;
+		*reply_dma = le64_to_cpu(addr_desc->ReplyFrameAddress);
+		def_reply = mpi3mr_get_reply_virt_addr(mrioc, *reply_dma);
+		if (!def_reply)
+			goto out;
+		host_tag = le16_to_cpu(def_reply->HostTag);
+		ioc_status = le16_to_cpu(def_reply->IOCStatus);
+		if (ioc_status &
+		    MPI3_REPLY_DESCRIPT_STATUS_IOCSTATUS_LOGINFOAVAIL)
+			ioc_loginfo = le32_to_cpu(def_reply->IOCLogInfo);
+		ioc_status &= MPI3_REPLY_DESCRIPT_STATUS_IOCSTATUS_STATUS_MASK;
+		if (def_reply->Function == MPI3_FUNCTION_SCSI_IO) {
+			scsi_reply = (Mpi3SCSIIOReply_t *)def_reply;
+			sense_buf = mpi3mr_get_sensebuf_virt_addr(mrioc,
+			    le64_to_cpu(scsi_reply->SenseDataBufferAddress));
+		}
+		break;
+	case MPI3_REPLY_DESCRIPT_FLAGS_TYPE_SUCCESS:
+		success_desc = (Mpi3SuccessReplyDescriptor_t *)reply_desc;
+		host_tag = le16_to_cpu(success_desc->HostTag);
+		break;
+	default:
+		break;
+	}
+
+	cmdptr = mpi3mr_get_drv_cmd(mrioc, host_tag, def_reply);
+	if (cmdptr) {
+		if (cmdptr->state & MPI3MR_CMD_PENDING) {
+			cmdptr->state |= MPI3MR_CMD_COMPLETE;
+			cmdptr->ioc_loginfo = ioc_loginfo;
+			cmdptr->ioc_status = ioc_status;
+			cmdptr->state &= ~MPI3MR_CMD_PENDING;
+			if (def_reply) {
+				cmdptr->state |= MPI3MR_CMD_REPLY_VALID;
+				memcpy((u8 *)cmdptr->reply, (u8 *)def_reply,
+				    mrioc->facts.reply_sz);
+			}
+			if (cmdptr->is_waiting) {
+				complete(&cmdptr->done);
+				cmdptr->is_waiting = 0;
+			} else if (cmdptr->callback)
+				cmdptr->callback(mrioc, cmdptr);
+		}
+	}
+out:
+	if (sense_buf)
+		mpi3mr_repost_sense_buf(mrioc,
+		    le64_to_cpu(scsi_reply->SenseDataBufferAddress));
+}
+
+static int mpi3mr_process_admin_reply_q(struct mpi3mr_ioc *mrioc)
+{
+	u32 exp_phase = mrioc->admin_reply_ephase;
+	u32 admin_reply_ci = mrioc->admin_reply_ci;
+	u32 num_admin_replies = 0;
+	u64 reply_dma = 0;
+	Mpi3DefaultReplyDescriptor_t *reply_desc;
+
+	reply_desc = (Mpi3DefaultReplyDescriptor_t *)mrioc->admin_reply_base +
+	    admin_reply_ci;
+
+	if ((le16_to_cpu(reply_desc->ReplyFlags) &
+	    MPI3_REPLY_DESCRIPT_FLAGS_PHASE_MASK) != exp_phase)
+		return 0;
+
+	do {
+		mrioc->admin_req_ci = le16_to_cpu(reply_desc->RequestQueueCI);
+		mpi3mr_process_admin_reply_desc(mrioc, reply_desc, &reply_dma);
+		if (reply_dma)
+			mpi3mr_repost_reply_buf(mrioc, reply_dma);
+		num_admin_replies++;
+		if (++admin_reply_ci == mrioc->num_admin_replies) {
+			admin_reply_ci = 0;
+			exp_phase ^= 1;
+		}
+		reply_desc =
+		    (Mpi3DefaultReplyDescriptor_t *)mrioc->admin_reply_base +
+		    admin_reply_ci;
+		if ((le16_to_cpu(reply_desc->ReplyFlags) &
+		    MPI3_REPLY_DESCRIPT_FLAGS_PHASE_MASK) != exp_phase)
+			break;
+	} while (1);
+
+	writel(admin_reply_ci, &mrioc->sysif_regs->AdminReplyQueueCI);
+	mrioc->admin_reply_ci = admin_reply_ci;
+	mrioc->admin_reply_ephase = exp_phase;
+
+	return num_admin_replies;
+}
+
+static irqreturn_t mpi3mr_isr_primary(int irq, void *privdata)
+{
+	struct mpi3mr_intr_info *intr_info = privdata;
+	struct mpi3mr_ioc *mrioc;
+	u16 midx;
+	u32 num_admin_replies = 0;
+
+	if (!intr_info)
+		return IRQ_NONE;
+
+	mrioc = intr_info->mrioc;
+
+	if (!mrioc->intr_enabled)
+		return IRQ_NONE;
+
+	midx = intr_info->msix_index;
+
+	if (!midx)
+		num_admin_replies = mpi3mr_process_admin_reply_q(mrioc);
+
+	if (num_admin_replies)
+		return IRQ_HANDLED;
+	else
+		return IRQ_NONE;
+}
+
+static irqreturn_t mpi3mr_isr(int irq, void *privdata)
+{
+	struct mpi3mr_intr_info *intr_info = privdata;
+	struct mpi3mr_ioc *mrioc;
+	u16 midx;
+	int ret;
+
+	if (!intr_info)
+		return IRQ_NONE;
+
+	mrioc = intr_info->mrioc;
+	midx = intr_info->msix_index;
+	/* Call primary ISR routine */
+	ret = mpi3mr_isr_primary(irq, privdata);
+
+	return ret;
+}
+
+/**
+ * mpi3mr_isr_poll - Reply queue polling routine
+ * @irq: IRQ
+ * @privdata: Interrupt info
+ *
+ * poll for pending I/O completions in a loop until pending I/Os
+ * present or controller queue depth I/Os are processed.
+ *
+ * Return: IRQ_NONE or IRQ_HANDLED
+ */
+static irqreturn_t mpi3mr_isr_poll(int irq, void *privdata)
+{
+	return IRQ_HANDLED;
+}
+
+/**
+ * mpi3mr_request_irq - Request IRQ and register ISR
+ * @mrioc: Adapter instance reference
+ * @index: IRQ vector index
+ *
+ * Request threaded ISR with primary ISR and secondary
+ *
+ * Return: 0 on success and non zero on failures.
+ */
+static inline int mpi3mr_request_irq(struct mpi3mr_ioc *mrioc, u16 index)
+{
+	struct pci_dev *pdev = mrioc->pdev;
+	struct mpi3mr_intr_info *intr_info = mrioc->intr_info + index;
+	int retval = 0;
+
+	intr_info->mrioc = mrioc;
+	intr_info->msix_index = index;
+	intr_info->op_reply_q = NULL;
+
+	snprintf(intr_info->name, MPI3MR_NAME_LENGTH, "%s%d-msix%d",
+	    mrioc->driver_name, mrioc->id, index);
+
+	retval = request_threaded_irq(pci_irq_vector(pdev, index), mpi3mr_isr,
+	    mpi3mr_isr_poll, IRQF_ONESHOT, intr_info->name, intr_info);
+	if (retval) {
+		ioc_err(mrioc, "%s: Unable to allocate interrupt %d!\n",
+		    intr_info->name, pci_irq_vector(pdev, index));
+		return retval;
+	}
+
+	return retval;
+}
+
+/**
+ * mpi3mr_setup_isr - Setup ISR for the controller
+ * @mrioc: Adapter instance reference
+ * @setup_one: Request one IRQ or more
+ *
+ * Allocate IRQ vectors and call mpi3mr_request_irq to setup ISR
+ *
+ * Return: 0 on success and non zero on failures.
+ */
+static int mpi3mr_setup_isr(struct mpi3mr_ioc *mrioc, u8 setup_one)
+{
+	unsigned int irq_flags = PCI_IRQ_MSIX;
+	u16 max_vectors = 0, i;
+	int retval = 0;
+	struct irq_affinity desc = { .pre_vectors =  1};
+
+
+	mpi3mr_cleanup_isr(mrioc);
+
+	if (setup_one || reset_devices)
+		max_vectors = 1;
+	else {
+		max_vectors =
+		    min_t(int, mrioc->cpu_count + 1, mrioc->msix_count);
+
+		ioc_info(mrioc,
+		    "MSI-X vectors supported: %d, no of cores: %d,",
+		    mrioc->msix_count, mrioc->cpu_count);
+		ioc_info(mrioc,
+		    "MSI-x vectors requested: %d\n", max_vectors);
+	}
+
+	irq_flags |= PCI_IRQ_AFFINITY | PCI_IRQ_ALL_TYPES;
+
+	i = pci_alloc_irq_vectors_affinity(mrioc->pdev,
+	    1, max_vectors, irq_flags, &desc);
+	if (i <= 0) {
+		ioc_err(mrioc, "Cannot alloc irq vectors\n");
+		goto out_failed;
+	}
+	if (i != max_vectors) {
+		ioc_info(mrioc,
+		    "allocated vectors (%d) are less than configured (%d)\n",
+		    i, max_vectors);
+
+		max_vectors = i;
+	}
+	mrioc->intr_info = kzalloc(sizeof(struct mpi3mr_intr_info)*max_vectors,
+	    GFP_KERNEL);
+	if (!mrioc->intr_info) {
+		retval = -1;
+		pci_free_irq_vectors(mrioc->pdev);
+		goto out_failed;
+	}
+	for (i = 0; i < max_vectors; i++) {
+		retval = mpi3mr_request_irq(mrioc, i);
+		if (retval) {
+			mrioc->intr_info_count = i;
+			goto out_failed;
+		}
+	}
+	mrioc->intr_info_count = max_vectors;
+	mpi3mr_ioc_enable_intr(mrioc);
+	return retval;
+out_failed:
+	mpi3mr_cleanup_isr(mrioc);
+
+	return retval;
+}
+
+static const struct {
+	enum mpi3mr_iocstate value;
+	char *name;
+} mrioc_states[] = {
+	{ MRIOC_STATE_READY, "ready" },
+	{ MRIOC_STATE_FAULT, "fault" },
+	{ MRIOC_STATE_RESET, "reset" },
+	{ MRIOC_STATE_BECOMING_READY, "becoming ready" },
+	{ MRIOC_STATE_RESET_REQUESTED, "reset requested" },
+	{ MRIOC_STATE_UNRECOVERABLE, "unrecoverable error" },
+};
+
+static const char *mpi3mr_iocstate_name(enum mpi3mr_iocstate mrioc_state)
+{
+	int i;
+	char *name = NULL;
+
+	for (i = 0; i < ARRAY_SIZE(mrioc_states); i++) {
+		if (mrioc_states[i].value == mrioc_state) {
+			name = mrioc_states[i].name;
+			break;
+		}
+	}
+	return name;
+}
+
+
+/**
+ * mpi3mr_print_fault_info - Display fault information
+ * @mrioc: Adapter instance reference
+ *
+ * Display the controller fault information if there is a
+ * controller fault.
+ *
+ * Return: Nothing.
+ */
+static void mpi3mr_print_fault_info(struct mpi3mr_ioc *mrioc)
+{
+	u32 ioc_status, code, code1, code2, code3;
+
+	ioc_status = readl(&mrioc->sysif_regs->IOCStatus);
+
+	if (ioc_status & MPI3_SYSIF_IOC_STATUS_FAULT) {
+		code = readl(&mrioc->sysif_regs->Fault);
+		code1 = readl(&mrioc->sysif_regs->FaultInfo[0]);
+		code2 = readl(&mrioc->sysif_regs->FaultInfo[1]);
+		code3 = readl(&mrioc->sysif_regs->FaultInfo[2]);
+
+		ioc_info(mrioc,
+		    "fault code(0x%08X): Additional code: (0x%08X:0x%08X:0x%08X)\n",
+		    code, code1, code2, code3);
+	}
+}
+
+/**
+ * mpi3mr_get_iocstate - Get IOC State
+ * @mrioc: Adapter instance reference
+ *
+ * Return a proper IOC state enum based on the IOC status and
+ * IOC configuration and unrcoverable state of the controller.
+ *
+ * Return: Current IOC state.
+ */
+enum mpi3mr_iocstate mpi3mr_get_iocstate(struct mpi3mr_ioc *mrioc)
+{
+	u32 ioc_status, ioc_config;
+	u8 ready, enabled;
+
+	ioc_status = readl(&mrioc->sysif_regs->IOCStatus);
+	ioc_config = readl(&mrioc->sysif_regs->IOCConfiguration);
+
+	if (mrioc->unrecoverable)
+		return MRIOC_STATE_UNRECOVERABLE;
+	if (ioc_status & MPI3_SYSIF_IOC_STATUS_FAULT)
+		return MRIOC_STATE_FAULT;
+
+	ready = (ioc_status & MPI3_SYSIF_IOC_STATUS_READY);
+	enabled = (ioc_config & MPI3_SYSIF_IOC_CONFIG_ENABLE_IOC);
+
+	if (ready && enabled)
+		return MRIOC_STATE_READY;
+	if ((!ready) && (!enabled))
+		return MRIOC_STATE_RESET;
+	if ((!ready) && (enabled))
+		return MRIOC_STATE_BECOMING_READY;
+
+	return MRIOC_STATE_RESET_REQUESTED;
+}
+
+/**
+ * mpi3mr_clear_reset_history - Clear reset history
+ * @mrioc: Adapter instance reference
+ *
+ * Write the reset history bit in IOC Status to clear the bit,
+ * if it is already set.
+ *
+ * Return: Nothing.
+ */
+static inline void mpi3mr_clear_reset_history(struct mpi3mr_ioc *mrioc)
+{
+	u32 ioc_status;
+
+	ioc_status = readl(&mrioc->sysif_regs->IOCStatus);
+	if (ioc_status & MPI3_SYSIF_IOC_STATUS_RESET_HISTORY)
+		writel(ioc_status, &mrioc->sysif_regs->IOCStatus);
+
+}
+
+/**
+ * mpi3mr_issue_and_process_mur - Message Unit Reset handler
+ * @mrioc: Adapter instance reference
+ * @reset_reason: Reset reason code
+ *
+ * Issue Message Unit Reset to the controller and wait for it to
+ * be complete.
+ *
+ * Return: 0 on success, -1 on failure.
+ */
+static int mpi3mr_issue_and_process_mur(struct mpi3mr_ioc *mrioc,
+					u32 reset_reason)
+{
+	u32 ioc_config, timeout, ioc_status;
+	int retval = -1;
+
+	ioc_info(mrioc, "Issuing Message Unit Reset(MUR)\n");
+	if (mrioc->unrecoverable) {
+		ioc_info(mrioc, "IOC is unrecoverable MUR not issued\n");
+		return retval;
+	}
+	mpi3mr_clear_reset_history(mrioc);
+	writel(reset_reason, &mrioc->sysif_regs->Scratchpad[0]);
+	ioc_config = readl(&mrioc->sysif_regs->IOCConfiguration);
+	ioc_config &= ~MPI3_SYSIF_IOC_CONFIG_ENABLE_IOC;
+	writel(ioc_config, &mrioc->sysif_regs->IOCConfiguration);
+
+	timeout = mrioc->ready_timeout * 10;
+	do {
+		ioc_status = readl(&mrioc->sysif_regs->IOCStatus);
+		if ((ioc_status & MPI3_SYSIF_IOC_STATUS_RESET_HISTORY)) {
+			mpi3mr_clear_reset_history(mrioc);
+			ioc_config =
+			    readl(&mrioc->sysif_regs->IOCConfiguration);
+			if (!((ioc_status & MPI3_SYSIF_IOC_STATUS_READY) ||
+			    (ioc_status & MPI3_SYSIF_IOC_STATUS_FAULT) ||
+			    (ioc_config & MPI3_SYSIF_IOC_CONFIG_ENABLE_IOC))) {
+				retval = 0;
+				break;
+			}
+		}
+		msleep(100);
+	} while (--timeout);
+
+	ioc_status = readl(&mrioc->sysif_regs->IOCStatus);
+	ioc_config = readl(&mrioc->sysif_regs->IOCConfiguration);
+
+	ioc_info(mrioc, "Base IOC Sts/Config after %s MUR is (0x%x)/(0x%x)\n",
+	    (!retval) ? "successful" : "failed", ioc_status, ioc_config);
+	return retval;
+}
+
+/**
+ * mpi3mr_bring_ioc_ready - Bring controller to ready state
+ * @mrioc: Adapter instance reference
+ *
+ * Set Enable IOC bit in IOC configuration register and wait for
+ * the controller to become ready.
+ *
+ * Return: 0 on success, -1 on failure.
+ */
+static int mpi3mr_bring_ioc_ready(struct mpi3mr_ioc *mrioc)
+{
+	u32 ioc_config, timeout;
+	enum mpi3mr_iocstate current_state;
+
+	ioc_config = readl(&mrioc->sysif_regs->IOCConfiguration);
+	ioc_config |= MPI3_SYSIF_IOC_CONFIG_ENABLE_IOC;
+	writel(ioc_config, &mrioc->sysif_regs->IOCConfiguration);
+
+	timeout = mrioc->ready_timeout * 10;
+	do {
+		current_state = mpi3mr_get_iocstate(mrioc);
+		if (current_state == MRIOC_STATE_READY)
+			return 0;
+		msleep(100);
+	} while (--timeout);
+
+	return -1;
+}
+
+/**
+ * mpi3mr_set_diagsave - Set diag save bit for snapdump
+ * @mrioc: Adapter reference
+ *
+ * Set diag save bit in IOC configuration register to enable
+ * snapdump.
+ *
+ * Return: Nothing.
+ */
+static inline void mpi3mr_set_diagsave(struct mpi3mr_ioc *mrioc)
+{
+	u32 ioc_config;
+
+	ioc_config = readl(&mrioc->sysif_regs->IOCConfiguration);
+	ioc_config |= MPI3_SYSIF_IOC_CONFIG_DIAG_SAVE;
+	writel(ioc_config, &mrioc->sysif_regs->IOCConfiguration);
+}
+
+/**
+ * mpi3mr_issue_reset - Issue reset to the controller
+ * @mrioc: Adapter reference
+ * @reset_type: Reset type
+ * @reset_reason: Reset reason code
+ *
+ * TBD
+ *
+ * Return: 0 on success, non-zero on failure.
+ */
+static int mpi3mr_issue_reset(struct mpi3mr_ioc *mrioc, u16 reset_type,
+	u32 reset_reason)
+{
+	return 0;
+}
+
+/**
+ * mpi3mr_admin_request_post - Post request to admin queue
+ * @mrioc: Adapter reference
+ * @admin_req: MPI3 request
+ * @admin_req_sz: Request size
+ * @ignore_reset: Ignore reset in process
+ *
+ * Post the MPI3 request into admin request queue and
+ * inform the controller, if the queue is full return
+ * appropriate error.
+ *
+ * Return: 0 on success, non-zero on failure.
+ */
+int mpi3mr_admin_request_post(struct mpi3mr_ioc *mrioc, void *admin_req,
+	u16 admin_req_sz, u8 ignore_reset)
+{
+	u16 areq_pi = 0, areq_ci = 0, max_entries = 0;
+	int retval = 0;
+	unsigned long flags;
+	u8 *areq_entry;
+
+
+	if (mrioc->unrecoverable) {
+		ioc_err(mrioc, "%s : Unrecoverable controller\n", __func__);
+		return -EFAULT;
+	}
+
+	spin_lock_irqsave(&mrioc->admin_req_lock, flags);
+	areq_pi = mrioc->admin_req_pi;
+	areq_ci = mrioc->admin_req_ci;
+	max_entries = mrioc->num_admin_req;
+	if ((areq_ci == (areq_pi + 1)) || ((!areq_ci) &&
+	    (areq_pi == (max_entries - 1)))) {
+		ioc_err(mrioc, "AdminReqQ full condition detected\n");
+		retval = -EAGAIN;
+		goto out;
+	}
+	if (!ignore_reset && mrioc->reset_in_progress) {
+		ioc_err(mrioc, "AdminReqQ submit reset in progress\n");
+		retval = -EAGAIN;
+		goto out;
+	}
+	areq_entry = (u8 *)mrioc->admin_req_base +
+	    (areq_pi * MPI3MR_ADMIN_REQ_FRAME_SZ);
+	memset(areq_entry, 0, MPI3MR_ADMIN_REQ_FRAME_SZ);
+	memcpy(areq_entry, (u8 *)admin_req, admin_req_sz);
+
+	if (++areq_pi == max_entries)
+		areq_pi = 0;
+	mrioc->admin_req_pi = areq_pi;
+
+	writel(mrioc->admin_req_pi, &mrioc->sysif_regs->AdminRequestQueuePI);
+
+out:
+	spin_unlock_irqrestore(&mrioc->admin_req_lock, flags);
+
+	return retval;
+}
+
+
+/**
+ * mpi3mr_setup_admin_qpair - Setup admin queue pair
+ * @mrioc: Adapter instance reference
+ *
+ * Allocate memory for admin queue pair if required and register
+ * the admin queue with the controller.
+ *
+ * Return: 0 on success, non-zero on failures.
+ */
+static int mpi3mr_setup_admin_qpair(struct mpi3mr_ioc *mrioc)
+{
+	int retval = 0;
+	u32 num_admin_entries = 0;
+
+	mrioc->admin_req_q_sz = MPI3MR_ADMIN_REQ_Q_SIZE;
+	mrioc->num_admin_req = mrioc->admin_req_q_sz /
+	    MPI3MR_ADMIN_REQ_FRAME_SZ;
+	mrioc->admin_req_ci = mrioc->admin_req_pi = 0;
+	mrioc->admin_req_base = NULL;
+
+	mrioc->admin_reply_q_sz = MPI3MR_ADMIN_REPLY_Q_SIZE;
+	mrioc->num_admin_replies = mrioc->admin_reply_q_sz /
+	    MPI3MR_ADMIN_REPLY_FRAME_SZ;
+	mrioc->admin_reply_ci = 0;
+	mrioc->admin_reply_ephase = 1;
+	mrioc->admin_reply_base = NULL;
+
+	if (!mrioc->admin_req_base) {
+		mrioc->admin_req_base = dma_alloc_coherent(&mrioc->pdev->dev,
+		    mrioc->admin_req_q_sz, &mrioc->admin_req_dma, GFP_KERNEL);
+
+		if (!mrioc->admin_req_base) {
+			retval = -1;
+			goto out_failed;
+		}
+
+		mrioc->admin_reply_base = dma_alloc_coherent(&mrioc->pdev->dev,
+		    mrioc->admin_reply_q_sz, &mrioc->admin_reply_dma,
+		    GFP_KERNEL);
+
+		if (!mrioc->admin_reply_base) {
+			retval = -1;
+			goto out_failed;
+		}
+
+	}
+
+	num_admin_entries = (mrioc->num_admin_replies << 16) |
+	    (mrioc->num_admin_req);
+	writel(num_admin_entries, &mrioc->sysif_regs->AdminQueueNumEntries);
+	mpi3mr_writeq(mrioc->admin_req_dma,
+	    &mrioc->sysif_regs->AdminRequestQueueAddress);
+	mpi3mr_writeq(mrioc->admin_reply_dma,
+	    &mrioc->sysif_regs->AdminReplyQueueAddress);
+	writel(mrioc->admin_req_pi, &mrioc->sysif_regs->AdminRequestQueuePI);
+	writel(mrioc->admin_reply_ci, &mrioc->sysif_regs->AdminReplyQueueCI);
+	return retval;
+
+out_failed:
+
+	if (mrioc->admin_reply_base) {
+		dma_free_coherent(&mrioc->pdev->dev, mrioc->admin_reply_q_sz,
+		    mrioc->admin_reply_base, mrioc->admin_reply_dma);
+		mrioc->admin_reply_base = NULL;
+	}
+	if (mrioc->admin_req_base) {
+		dma_free_coherent(&mrioc->pdev->dev, mrioc->admin_req_q_sz,
+		    mrioc->admin_req_base, mrioc->admin_req_dma);
+		mrioc->admin_req_base = NULL;
+	}
+	return retval;
+}
+
+/**
+ * mpi3mr_issue_iocfacts - Send IOC Facts
+ * @mrioc: Adapter instance reference
+ *
+ * Issue IOC Facts MPI request through admin queue and wait for
+ * the completion of it or time out.
+ *
+ * Return: 0 on success, non-zero on failures.
+ */
+static int mpi3mr_issue_iocfacts(struct mpi3mr_ioc *mrioc,
+	Mpi3IOCFactsData_t *facts_data)
+{
+	Mpi3IOCFactsRequest_t iocfacts_req;
+	void *data = NULL;
+	dma_addr_t data_dma;
+	u32 data_len = sizeof(*facts_data);
+	int retval = 0;
+	u8 sgl_flags = MPI3MR_SGEFLAGS_SYSTEM_SIMPLE_END_OF_LIST;
+
+	data = dma_alloc_coherent(&mrioc->pdev->dev, data_len, &data_dma,
+	    GFP_KERNEL);
+
+	if (!data) {
+		retval = -1;
+		goto out;
+	}
+
+	memset(&iocfacts_req, 0, sizeof(iocfacts_req));
+	mutex_lock(&mrioc->init_cmds.mutex);
+	if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
+		retval = -1;
+		ioc_err(mrioc, "Issue IOCFacts: Init command is in use\n");
+		mutex_unlock(&mrioc->init_cmds.mutex);
+		goto out;
+	}
+	mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
+	mrioc->init_cmds.is_waiting = 1;
+	mrioc->init_cmds.callback = NULL;
+	iocfacts_req.HostTag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
+	iocfacts_req.Function = MPI3_FUNCTION_IOC_FACTS;
+
+	mpi3mr_add_sg_single(&iocfacts_req.SGL, sgl_flags, data_len,
+	    data_dma);
+
+	init_completion(&mrioc->init_cmds.done);
+	retval = mpi3mr_admin_request_post(mrioc, &iocfacts_req,
+	    sizeof(iocfacts_req), 1);
+	if (retval) {
+		ioc_err(mrioc, "Issue IOCFacts: Admin Post failed\n");
+		goto out_unlock;
+	}
+	wait_for_completion_timeout(&mrioc->init_cmds.done,
+	    (MPI3MR_INTADMCMD_TIMEOUT * HZ));
+	if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
+		ioc_err(mrioc, "Issue IOCFacts: command timed out\n");
+		mpi3mr_set_diagsave(mrioc);
+		mpi3mr_issue_reset(mrioc,
+		    MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT,
+		    MPI3MR_RESET_FROM_IOCFACTS_TIMEOUT);
+		mrioc->unrecoverable = 1;
+		retval = -1;
+		goto out_unlock;
+	}
+	if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
+	    != MPI3_IOCSTATUS_SUCCESS) {
+		ioc_err(mrioc,
+		    "Issue IOCFacts: Failed IOCStatus(0x%04x) Loginfo(0x%08x)\n",
+		    (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
+		    mrioc->init_cmds.ioc_loginfo);
+		retval = -1;
+		goto out_unlock;
+	}
+	memcpy(facts_data, (u8 *)data, data_len);
+out_unlock:
+	mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
+	mutex_unlock(&mrioc->init_cmds.mutex);
+
+out:
+	if (data)
+		dma_free_coherent(&mrioc->pdev->dev, data_len, data, data_dma);
+
+	return retval;
+}
+
+/**
+ * mpi3mr_check_reset_dma_mask - Process IOC facts data
+ * @mrioc: Adapter instance reference
+ *
+ * Check whether the new DMA mask requested through IOCFacts by
+ * firmware needs to be set, if so set it .
+ *
+ * Return: 0 on success, non-zero on failure.
+ */
+static inline int mpi3mr_check_reset_dma_mask(struct mpi3mr_ioc *mrioc)
+{
+	struct pci_dev *pdev = mrioc->pdev;
+	int r;
+	u64 facts_dma_mask = DMA_BIT_MASK(mrioc->facts.dma_mask);
+
+	if (!mrioc->facts.dma_mask || (mrioc->dma_mask <= facts_dma_mask))
+		return 0;
+
+	ioc_info(mrioc, "Changing DMA mask from 0x%016llx to 0x%016llx\n",
+	    mrioc->dma_mask, facts_dma_mask);
+
+	r = dma_set_mask_and_coherent(&pdev->dev, facts_dma_mask);
+	if (r) {
+		ioc_err(mrioc, "Setting DMA mask to 0x%016llx failed: %d\n",
+		    facts_dma_mask, r);
+		return r;
+	}
+	mrioc->dma_mask = facts_dma_mask;
+	return r;
+}
+/**
+ * mpi3mr_process_factsdata - Process IOC facts data
+ * @mrioc: Adapter instance reference
+ *
+ * Convert IOC facts data into cpu endianness and cache it in
+ * the driver .
+ *
+ * Return: Nothing.
+ */
+static void mpi3mr_process_factsdata(struct mpi3mr_ioc *mrioc,
+	Mpi3IOCFactsData_t *facts_data)
+{
+	u32 ioc_config, req_sz, facts_flags;
+
+	if ((le16_to_cpu(facts_data->IOCFactsDataLength)) !=
+	    (sizeof(*facts_data)/4)) {
+		ioc_warn(mrioc,
+		    "IOCFactsdata length mismatch driver_sz(%ld) firmware_sz(%d)\n",
+		    sizeof(*facts_data),
+		    le16_to_cpu(facts_data->IOCFactsDataLength) * 4);
+	}
+
+	ioc_config = readl(&mrioc->sysif_regs->IOCConfiguration);
+	req_sz = 1 << ((ioc_config & MPI3_SYSIF_IOC_CONFIG_OPER_REQ_ENT_SZ) >>
+	    MPI3_SYSIF_IOC_CONFIG_OPER_REQ_ENT_SZ_SHIFT);
+	if (le16_to_cpu(facts_data->IOCRequestFrameSize) != (req_sz/4)) {
+		ioc_err(mrioc,
+		    "IOCFacts data reqFrameSize mismatch hw_size(%d) firmware_sz(%d)\n",
+		    req_sz/4, le16_to_cpu(facts_data->IOCRequestFrameSize));
+	}
+
+	memset(&mrioc->facts, 0, sizeof(mrioc->facts));
+
+	facts_flags = le32_to_cpu(facts_data->Flags);
+	mrioc->facts.op_req_sz = req_sz;
+	mrioc->op_reply_desc_sz = 1 << ((ioc_config &
+	    MPI3_SYSIF_IOC_CONFIG_OPER_RPY_ENT_SZ) >>
+	    MPI3_SYSIF_IOC_CONFIG_OPER_RPY_ENT_SZ_SHIFT);
+
+	mrioc->facts.ioc_num = facts_data->IOCNumber;
+	mrioc->facts.who_init = facts_data->WhoInit;
+	mrioc->facts.max_msix_vectors = le16_to_cpu(facts_data->MaxMSIxVectors);
+	mrioc->facts.personality = (facts_flags &
+	    MPI3_IOCFACTS_FLAGS_PERSONALITY_MASK);
+	mrioc->facts.dma_mask = (facts_flags &
+	    MPI3_IOCFACTS_FLAGS_DMA_ADDRESS_WIDTH_MASK) >>
+	    MPI3_IOCFACTS_FLAGS_DMA_ADDRESS_WIDTH_SHIFT;
+	mrioc->facts.protocol_flags = facts_data->ProtocolFlags;
+	mrioc->facts.mpi_version = le32_to_cpu(facts_data->MPIVersion.Word);
+	mrioc->facts.max_reqs = le16_to_cpu(facts_data->MaxOutstandingRequest);
+	mrioc->facts.product_id = le16_to_cpu(facts_data->ProductID);
+	mrioc->facts.reply_sz = le16_to_cpu(facts_data->ReplyFrameSize) * 4;
+	mrioc->facts.exceptions = le16_to_cpu(facts_data->IOCExceptions);
+	mrioc->facts.max_perids = le16_to_cpu(facts_data->MaxPersistentID);
+	mrioc->facts.max_pds = le16_to_cpu(facts_data->MaxPDs);
+	mrioc->facts.max_vds = le16_to_cpu(facts_data->MaxVDs);
+	mrioc->facts.max_hpds = le16_to_cpu(facts_data->MaxHostPDs);
+	mrioc->facts.max_advhpds = le16_to_cpu(facts_data->MaxAdvancedHostPDs);
+	mrioc->facts.max_raidpds = le16_to_cpu(facts_data->MaxRAIDPDs);
+	mrioc->facts.max_nvme = le16_to_cpu(facts_data->MaxNVMe);
+	mrioc->facts.max_pcieswitches =
+	    le16_to_cpu(facts_data->MaxPCIeSwitches);
+	mrioc->facts.max_sasexpanders =
+	    le16_to_cpu(facts_data->MaxSASExpanders);
+	mrioc->facts.max_sasinitiators =
+	    le16_to_cpu(facts_data->MaxSASInitiators);
+	mrioc->facts.max_enclosures = le16_to_cpu(facts_data->MaxEnclosures);
+	mrioc->facts.min_devhandle = le16_to_cpu(facts_data->MinDevHandle);
+	mrioc->facts.max_devhandle = le16_to_cpu(facts_data->MaxDevHandle);
+	mrioc->facts.max_op_req_q =
+	    le16_to_cpu(facts_data->MaxOperationalRequestQueues);
+	mrioc->facts.max_op_reply_q =
+	    le16_to_cpu(facts_data->MaxOperationalReplyQueues);
+	mrioc->facts.ioc_capabilities =
+	    le32_to_cpu(facts_data->IOCCapabilities);
+	mrioc->facts.fw_ver.build_num =
+	    le16_to_cpu(facts_data->FWVersion.BuildNum);
+	mrioc->facts.fw_ver.cust_id =
+	    le16_to_cpu(facts_data->FWVersion.CustomerID);
+	mrioc->facts.fw_ver.ph_minor = facts_data->FWVersion.PhaseMinor;
+	mrioc->facts.fw_ver.ph_major = facts_data->FWVersion.PhaseMajor;
+	mrioc->facts.fw_ver.gen_minor = facts_data->FWVersion.GenMinor;
+	mrioc->facts.fw_ver.gen_major = facts_data->FWVersion.GenMajor;
+	mrioc->msix_count = min_t(int, mrioc->msix_count,
+	    mrioc->facts.max_msix_vectors);
+	mrioc->facts.sge_mod_mask = facts_data->SGEModifierMask;
+	mrioc->facts.sge_mod_value = facts_data->SGEModifierValue;
+	mrioc->facts.sge_mod_shift = facts_data->SGEModifierShift;
+	mrioc->facts.shutdown_timeout =
+	    le16_to_cpu(facts_data->ShutdownTimeout);
+
+	ioc_info(mrioc, "ioc_num(%d), maxopQ(%d), maxopRepQ(%d), maxdh(%d),",
+	    mrioc->facts.ioc_num, mrioc->facts.max_op_req_q,
+	    mrioc->facts.max_op_reply_q, mrioc->facts.max_devhandle);
+	ioc_info(mrioc,
+	    "maxreqs(%d), mindh(%d) maxPDs(%d) maxvectors(%d) maxperids(%d)\n",
+	    mrioc->facts.max_reqs, mrioc->facts.min_devhandle,
+	    mrioc->facts.max_pds, mrioc->facts.max_msix_vectors,
+	    mrioc->facts.max_perids);
+	ioc_info(mrioc, "SGEModMask 0x%x SGEModVal 0x%x SGEModShift 0x%x ",
+	    mrioc->facts.sge_mod_mask, mrioc->facts.sge_mod_value,
+	    mrioc->facts.sge_mod_shift);
+	ioc_info(mrioc, "DMA Mask %d InitialPE Status 0x%x\n",
+	    mrioc->facts.dma_mask, (facts_flags &
+	    MPI3_IOCFACTS_FLAGS_INITIAL_PORT_ENABLE_MASK));
+
+	mrioc->max_host_ios = mrioc->facts.max_reqs - MPI3MR_INTERNAL_CMDS_RESVD;
+
+	if (reset_devices)
+		mrioc->max_host_ios = min_t(int, mrioc->max_host_ios,
+		    MPI3MR_HOST_IOS_KDUMP);
+
+}
+
+/**
+ * mpi3mr_alloc_reply_sense_bufs - Send IOC Init
+ * @mrioc: Adapter instance reference
+ *
+ * Allocate and initialize the reply free buffers, sense
+ * buffers, reply free queue and sense buffer queue.
+ *
+ * Return: 0 on success, non-zero on failures.
+ */
+static int mpi3mr_alloc_reply_sense_bufs(struct mpi3mr_ioc *mrioc)
+{
+	int retval = 0;
+	u32 sz, i;
+	dma_addr_t phy_addr;
+
+	if (mrioc->init_cmds.reply)
+		goto post_reply_sbuf;
+
+	mrioc->init_cmds.reply = kzalloc(mrioc->facts.reply_sz, GFP_KERNEL);
+	if (!mrioc->init_cmds.reply)
+		goto out_failed;
+
+
+	mrioc->num_reply_bufs = mrioc->facts.max_reqs + MPI3MR_NUM_EVT_REPLIES;
+	mrioc->reply_free_qsz = mrioc->num_reply_bufs + 1;
+	mrioc->num_sense_bufs = mrioc->facts.max_reqs / MPI3MR_SENSEBUF_FACTOR;
+	mrioc->sense_buf_q_sz = mrioc->num_sense_bufs + 1;
+
+	/* reply buffer pool, 16 byte align */
+	sz = mrioc->num_reply_bufs * mrioc->facts.reply_sz;
+	mrioc->reply_buf_pool = dma_pool_create("reply_buf pool",
+	    &mrioc->pdev->dev, sz, 16, 0);
+	if (!mrioc->reply_buf_pool) {
+		ioc_err(mrioc, "reply buf pool: dma_pool_create failed\n");
+		goto out_failed;
+	}
+
+	mrioc->reply_buf = dma_pool_zalloc(mrioc->reply_buf_pool, GFP_KERNEL,
+	    &mrioc->reply_buf_dma);
+	if (!mrioc->reply_buf)
+		goto out_failed;
+
+	mrioc->reply_buf_dma_max_address = mrioc->reply_buf_dma + sz;
+
+	/* reply free queue, 8 byte align */
+	sz = mrioc->reply_free_qsz * 8;
+	mrioc->reply_free_q_pool = dma_pool_create("reply_free_q pool",
+	    &mrioc->pdev->dev, sz, 8, 0);
+	if (!mrioc->reply_free_q_pool) {
+		ioc_err(mrioc, "reply_free_q pool: dma_pool_create failed\n");
+		goto out_failed;
+	}
+	mrioc->reply_free_q = dma_pool_zalloc(mrioc->reply_free_q_pool,
+	    GFP_KERNEL, &mrioc->reply_free_q_dma);
+	if (!mrioc->reply_free_q)
+		goto out_failed;
+
+	/* sense buffer pool,  4 byte align */
+	sz = mrioc->num_sense_bufs * MPI3MR_SENSEBUF_SZ;
+	mrioc->sense_buf_pool = dma_pool_create("sense_buf pool",
+	    &mrioc->pdev->dev, sz, 4, 0);
+	if (!mrioc->sense_buf_pool) {
+		ioc_err(mrioc, "sense_buf pool: dma_pool_create failed\n");
+		goto out_failed;
+	}
+	mrioc->sense_buf = dma_pool_zalloc(mrioc->sense_buf_pool, GFP_KERNEL,
+	    &mrioc->sense_buf_dma);
+	if (!mrioc->sense_buf)
+		goto out_failed;
+
+	/* sense buffer queue, 8 byte align */
+	sz = mrioc->sense_buf_q_sz * 8;
+	mrioc->sense_buf_q_pool = dma_pool_create("sense_buf_q pool",
+	    &mrioc->pdev->dev, sz, 8, 0);
+	if (!mrioc->sense_buf_q_pool) {
+		ioc_err(mrioc, "sense_buf_q pool: dma_pool_create failed\n");
+		goto out_failed;
+	}
+	mrioc->sense_buf_q = dma_pool_zalloc(mrioc->sense_buf_q_pool,
+	    GFP_KERNEL, &mrioc->sense_buf_q_dma);
+	if (!mrioc->sense_buf_q)
+		goto out_failed;
+
+post_reply_sbuf:
+	sz = mrioc->num_reply_bufs * mrioc->facts.reply_sz;
+	ioc_info(mrioc,
+	    "reply buf pool(0x%p): depth(%d), frame_size(%d), pool_size(%d kB), reply_dma(0x%llx)\n",
+	    mrioc->reply_buf, mrioc->num_reply_bufs, mrioc->facts.reply_sz,
+	    (sz / 1024), (unsigned long long)mrioc->reply_buf_dma);
+	sz = mrioc->reply_free_qsz * 8;
+	ioc_info(mrioc,
+	    "reply_free_q pool(0x%p): depth(%d), frame_size(%d), pool_size(%d kB), reply_dma(0x%llx)\n",
+	    mrioc->reply_free_q, mrioc->reply_free_qsz, 8, (sz / 1024),
+	    (unsigned long long)mrioc->reply_free_q_dma);
+	sz = mrioc->num_sense_bufs * MPI3MR_SENSEBUF_SZ;
+	ioc_info(mrioc,
+	    "sense_buf pool(0x%p): depth(%d), frame_size(%d), pool_size(%d kB), sense_dma(0x%llx)\n",
+	    mrioc->sense_buf, mrioc->num_sense_bufs, MPI3MR_SENSEBUF_SZ,
+	    (sz / 1024), (unsigned long long)mrioc->sense_buf_dma);
+	sz = mrioc->sense_buf_q_sz * 8;
+	ioc_info(mrioc,
+	    "sense_buf_q pool(0x%p): depth(%d), frame_size(%d), pool_size(%d kB), sense_dma(0x%llx)\n",
+	    mrioc->sense_buf_q, mrioc->sense_buf_q_sz, 8, (sz / 1024),
+	    (unsigned long long)mrioc->sense_buf_q_dma);
+
+	/* initialize Reply buffer Queue */
+	for (i = 0, phy_addr = mrioc->reply_buf_dma;
+	    i < mrioc->num_reply_bufs; i++, phy_addr += mrioc->facts.reply_sz)
+		mrioc->reply_free_q[i] = cpu_to_le64(phy_addr);
+	mrioc->reply_free_q[i] = cpu_to_le64(0);
+
+	/* initialize Sense Buffer Queue */
+	for (i = 0, phy_addr = mrioc->sense_buf_dma;
+	    i < mrioc->num_sense_bufs; i++, phy_addr += MPI3MR_SENSEBUF_SZ)
+		mrioc->sense_buf_q[i] = cpu_to_le64(phy_addr);
+	mrioc->sense_buf_q[i] = cpu_to_le64(0);
+	return retval;
+
+out_failed:
+	retval = -1;
+	return retval;
+}
+
+/**
+ * mpi3mr_issue_iocinit - Send IOC Init
+ * @mrioc: Adapter instance reference
+ *
+ * Issue IOC Init MPI request through admin queue and wait for
+ * the completion of it or time out.
+ *
+ * Return: 0 on success, non-zero on failures.
+ */
+static int mpi3mr_issue_iocinit(struct mpi3mr_ioc *mrioc)
+{
+	Mpi3IOCInitRequest_t iocinit_req;
+	Mpi3DriverInfoLayout_t *drv_info;
+	dma_addr_t data_dma;
+	u32 data_len = sizeof(*drv_info);
+	int retval = 0;
+	ktime_t current_time;
+
+	drv_info = dma_alloc_coherent(&mrioc->pdev->dev, data_len, &data_dma,
+	    GFP_KERNEL);
+	if (!drv_info) {
+		retval = -1;
+		goto out;
+	}
+	drv_info->InformationLength = cpu_to_le32(data_len);
+	strcpy(drv_info->DriverSignature, "Broadcom");
+	strcpy(drv_info->OsName, utsname()->sysname);
+	drv_info->OsName[sizeof(drv_info->OsName)-1] = 0;
+	strcpy(drv_info->OsVersion, utsname()->release);
+	drv_info->OsVersion[sizeof(drv_info->OsVersion)-1] = 0;
+	strcpy(drv_info->DriverName, MPI3MR_DRIVER_NAME);
+	strcpy(drv_info->DriverVersion, MPI3MR_DRIVER_VERSION);
+	strcpy(drv_info->DriverReleaseDate, MPI3MR_DRIVER_RELDATE);
+	drv_info->DriverCapabilities = 0;
+	memcpy((u8 *)&mrioc->driver_info, (u8 *)drv_info,
+	    sizeof(mrioc->driver_info));
+
+	memset(&iocinit_req, 0, sizeof(iocinit_req));
+	mutex_lock(&mrioc->init_cmds.mutex);
+	if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
+		retval = -1;
+		ioc_err(mrioc, "Issue IOCInit: Init command is in use\n");
+		mutex_unlock(&mrioc->init_cmds.mutex);
+		goto out;
+	}
+	mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
+	mrioc->init_cmds.is_waiting = 1;
+	mrioc->init_cmds.callback = NULL;
+	iocinit_req.HostTag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
+	iocinit_req.Function = MPI3_FUNCTION_IOC_INIT;
+	iocinit_req.MPIVersion.Struct.Dev = MPI3_VERSION_DEV;
+	iocinit_req.MPIVersion.Struct.Unit = MPI3_VERSION_UNIT;
+	iocinit_req.MPIVersion.Struct.Major = MPI3_VERSION_MAJOR;
+	iocinit_req.MPIVersion.Struct.Minor = MPI3_VERSION_MINOR;
+	iocinit_req.WhoInit = MPI3_WHOINIT_HOST_DRIVER;
+	iocinit_req.ReplyFreeQueueDepth = cpu_to_le16(mrioc->reply_free_qsz);
+	iocinit_req.ReplyFreeQueueAddress =
+	    cpu_to_le64(mrioc->reply_free_q_dma);
+	iocinit_req.SenseBufferLength = cpu_to_le16(MPI3MR_SENSEBUF_SZ);
+	iocinit_req.SenseBufferFreeQueueDepth =
+	    cpu_to_le16(mrioc->sense_buf_q_sz);
+	iocinit_req.SenseBufferFreeQueueAddress =
+	    cpu_to_le64(mrioc->sense_buf_q_dma);
+	iocinit_req.DriverInformationAddress = cpu_to_le64(data_dma);
+
+	current_time = ktime_get_real();
+	iocinit_req.TimeStamp = cpu_to_le64(ktime_to_ms(current_time));
+
+	init_completion(&mrioc->init_cmds.done);
+	retval = mpi3mr_admin_request_post(mrioc, &iocinit_req,
+	    sizeof(iocinit_req), 1);
+	if (retval) {
+		ioc_err(mrioc, "Issue IOCInit: Admin Post failed\n");
+		goto out_unlock;
+	}
+	wait_for_completion_timeout(&mrioc->init_cmds.done,
+	    (MPI3MR_INTADMCMD_TIMEOUT * HZ));
+	if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
+		mpi3mr_set_diagsave(mrioc);
+		mpi3mr_issue_reset(mrioc,
+		    MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT,
+		    MPI3MR_RESET_FROM_IOCINIT_TIMEOUT);
+		mrioc->unrecoverable = 1;
+		ioc_err(mrioc, "Issue IOCInit: command timed out\n");
+		retval = -1;
+		goto out_unlock;
+	}
+	if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
+	    != MPI3_IOCSTATUS_SUCCESS) {
+		ioc_err(mrioc,
+		    "Issue IOCInit: Failed IOCStatus(0x%04x) Loginfo(0x%08x)\n",
+		    (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
+		    mrioc->init_cmds.ioc_loginfo);
+		retval = -1;
+		goto out_unlock;
+	}
+
+out_unlock:
+	mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
+	mutex_unlock(&mrioc->init_cmds.mutex);
+
+out:
+	if (drv_info)
+		dma_free_coherent(&mrioc->pdev->dev, data_len, drv_info,
+		    data_dma);
+
+	return retval;
+}
+
+
+/**
+ * mpi3mr_alloc_chain_bufs - Allocate chain buffers
+ * @mrioc: Adapter instance reference
+ *
+ * Allocate chain buffers and set a bitmap to indicate free
+ * chain buffers. Chain buffers are used to pass the SGE
+ * information along with MPI3 SCSI IO requests for host I/O.
+ *
+ * Return: 0 on success, non-zero on failure
+ */
+static int mpi3mr_alloc_chain_bufs(struct mpi3mr_ioc *mrioc)
+{
+	int retval = 0;
+	u32 sz, i;
+	u16 num_chains;
+
+	num_chains = mrioc->max_host_ios/MPI3MR_CHAINBUF_FACTOR;
+
+	mrioc->chain_buf_count = num_chains;
+	sz = sizeof(struct chain_element) * num_chains;
+	mrioc->chain_sgl_list = kzalloc(sz, GFP_KERNEL);
+	if (!mrioc->chain_sgl_list)
+		goto out_failed;
+
+	sz = MPI3MR_PAGE_SIZE_4K;
+	mrioc->chain_buf_pool = dma_pool_create("chain_buf pool",
+	    &mrioc->pdev->dev, sz, 16, 0);
+	if (!mrioc->chain_buf_pool) {
+		ioc_err(mrioc, "chain buf pool: dma_pool_create failed\n");
+		goto out_failed;
+	}
+
+	for (i = 0; i < num_chains; i++) {
+		mrioc->chain_sgl_list[i].addr =
+		    dma_pool_zalloc(mrioc->chain_buf_pool, GFP_KERNEL,
+		    &mrioc->chain_sgl_list[i].dma_addr);
+
+		if (!mrioc->chain_sgl_list[i].addr)
+			goto out_failed;
+	}
+	mrioc->chain_bitmap_sz = num_chains / 8;
+	if (num_chains % 8)
+		mrioc->chain_bitmap_sz++;
+	mrioc->chain_bitmap = kzalloc(mrioc->chain_bitmap_sz, GFP_KERNEL);
+	if (!mrioc->chain_bitmap)
+		goto out_failed;
+	return retval;
+out_failed:
+	retval = -1;
+	return retval;
+}
+
+
+/**
+ * mpi3mr_cleanup_resources - Free PCI resources
+ * @mrioc: Adapter instance reference
+ *
+ * Unmap PCI device memory and disable PCI device.
+ *
+ * Return: 0 on success and non-zero on failure.
+ */
+void mpi3mr_cleanup_resources(struct mpi3mr_ioc *mrioc)
+{
+	struct pci_dev *pdev = mrioc->pdev;
+
+	mpi3mr_cleanup_isr(mrioc);
+
+	if (mrioc->sysif_regs) {
+		iounmap(mrioc->sysif_regs);
+		mrioc->sysif_regs = NULL;
+	}
+
+	if (pci_is_enabled(pdev)) {
+		if (mrioc->bars)
+			pci_release_selected_regions(pdev, mrioc->bars);
+		pci_disable_device(pdev);
+	}
+}
+
+/**
+ * mpi3mr_setup_resources - Enable PCI resources
+ * @mrioc: Adapter instance reference
+ *
+ * Enable PCI device memory, MSI-x registers and set DMA mask.
+ *
+ * Return: 0 on success and non-zero on failure.
+ */
+int mpi3mr_setup_resources(struct mpi3mr_ioc *mrioc)
+{
+	struct pci_dev *pdev = mrioc->pdev;
+	u32 memap_sz = 0;
+	int i, retval = 0, capb = 0;
+	u16 message_control;
+	u64 dma_mask = mrioc->dma_mask ? mrioc->dma_mask :
+	    (((dma_get_required_mask(&pdev->dev) > DMA_BIT_MASK(32)) &&
+	    (sizeof(dma_addr_t) > 4)) ? DMA_BIT_MASK(64):DMA_BIT_MASK(32));
+
+	if (pci_enable_device_mem(pdev)) {
+		ioc_err(mrioc, "pci_enable_device_mem: failed\n");
+		retval = -ENODEV;
+		goto out_failed;
+	}
+
+	capb = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
+	if (!capb) {
+		ioc_err(mrioc, "Unable to find MSI-X Capabilities\n");
+		retval = -ENODEV;
+		goto out_failed;
+	}
+	mrioc->bars = pci_select_bars(pdev, IORESOURCE_MEM);
+
+	if (pci_request_selected_regions(pdev, mrioc->bars,
+	    mrioc->driver_name)) {
+		ioc_err(mrioc, "pci_request_selected_regions: failed\n");
+		retval = -ENODEV;
+		goto out_failed;
+	}
+
+	for (i = 0; (i < DEVICE_COUNT_RESOURCE); i++) {
+		if (pci_resource_flags(pdev, i) & IORESOURCE_MEM) {
+			mrioc->sysif_regs_phys = pci_resource_start(pdev, i);
+			memap_sz = pci_resource_len(pdev, i);
+			mrioc->sysif_regs =
+			    ioremap(mrioc->sysif_regs_phys, memap_sz);
+			break;
+		}
+	}
+
+	pci_set_master(pdev);
+
+	retval = dma_set_mask_and_coherent(&pdev->dev, dma_mask);
+	if (retval) {
+		if (dma_mask != DMA_BIT_MASK(32)) {
+			ioc_warn(mrioc, "Setting 64 bit DMA mask failed\n");
+			dma_mask = DMA_BIT_MASK(32);
+			retval = dma_set_mask_and_coherent(&pdev->dev,
+			    dma_mask);
+		}
+		if (retval) {
+			mrioc->dma_mask = 0;
+			ioc_err(mrioc, "Setting 32 bit DMA mask also failed\n");
+			goto out_failed;
+		}
+	}
+	mrioc->dma_mask = dma_mask;
+
+	if (mrioc->sysif_regs == NULL) {
+		ioc_err(mrioc,
+		    "Unable to map adapter memory or resource not found\n");
+		retval = -EINVAL;
+		goto out_failed;
+	}
+
+	pci_read_config_word(pdev, capb + 2, &message_control);
+	mrioc->msix_count = (message_control & 0x3FF) + 1;
+
+	pci_save_state(pdev);
+
+	pci_set_drvdata(pdev, mrioc->shost);
+
+	mpi3mr_ioc_disable_intr(mrioc);
+
+	ioc_info(mrioc, "iomem(0x%016llx), mapped(0x%p), size(%d)\n",
+	    (unsigned long long)mrioc->sysif_regs_phys,
+	    mrioc->sysif_regs, memap_sz);
+	ioc_info(mrioc, "Number of MSI-X vectors found in capabilities: (%d)\n",
+	    mrioc->msix_count);
+	return retval;
+
+out_failed:
+	mpi3mr_cleanup_resources(mrioc);
+	return retval;
+}
+
+/**
+ * mpi3mr_init_ioc - Initialize the controller
+ * @mrioc: Adapter instance reference
+ *
+ * This the controller initialization routine, executed either
+ * after soft reset or from pci probe callback.
+ * Setup the required resources, memory map the controller
+ * registers, create admin and operational reply queue pairs,
+ * allocate required memory for reply pool, sense buffer pool,
+ * issue IOC init request to the firmware, unmask the events and
+ * issue port enable to discover SAS/SATA/NVMe devies and RAID
+ * volumes.
+ *
+ * Return: 0 on success and non-zero on failure.
+ */
+int mpi3mr_init_ioc(struct mpi3mr_ioc *mrioc)
+{
+	int retval = 0;
+	enum mpi3mr_iocstate ioc_state;
+	u64 base_info;
+	u32 timeout;
+	u32 ioc_status, ioc_config;
+	Mpi3IOCFactsData_t facts_data;
+
+	mrioc->change_count = 0;
+	mrioc->cpu_count = num_online_cpus();
+	retval = mpi3mr_setup_resources(mrioc);
+	if (retval) {
+		ioc_err(mrioc, "Failed to setup resources:error %d\n",
+		    retval);
+		goto out_nocleanup;
+	}
+	ioc_status = readl(&mrioc->sysif_regs->IOCStatus);
+	ioc_config = readl(&mrioc->sysif_regs->IOCConfiguration);
+
+	ioc_info(mrioc, "SOD status %x configuration %x\n",
+	    ioc_status, ioc_config);
+
+	base_info = readq(&mrioc->sysif_regs->IOCInformation);
+	ioc_info(mrioc, "SOD base_info %llx\n",	base_info);
+
+	/*The timeout value is in 2sec unit, changing it to seconds*/
+	mrioc->ready_timeout =
+	    ((base_info & MPI3_SYSIF_IOC_INFO_LOW_TIMEOUT_MASK) >>
+	    MPI3_SYSIF_IOC_INFO_LOW_TIMEOUT_SHIFT) * 2;
+
+	ioc_info(mrioc, "IOC ready timeout %d\n", mrioc->ready_timeout);
+
+	ioc_state = mpi3mr_get_iocstate(mrioc);
+	ioc_info(mrioc, "IOC in %s state during detection\n",
+	    mpi3mr_iocstate_name(ioc_state));
+
+	if (ioc_state == MRIOC_STATE_BECOMING_READY ||
+			ioc_state == MRIOC_STATE_RESET_REQUESTED) {
+		timeout = mrioc->ready_timeout * 10;
+		do {
+			msleep(100);
+		} while (--timeout);
+
+		ioc_state = mpi3mr_get_iocstate(mrioc);
+		ioc_info(mrioc,
+			"IOC in %s state after waiting for reset time\n",
+			mpi3mr_iocstate_name(ioc_state));
+	}
+
+	if (ioc_state == MRIOC_STATE_READY) {
+		retval = mpi3mr_issue_and_process_mur(mrioc,
+		    MPI3MR_RESET_FROM_BRINGUP);
+		if (retval) {
+			ioc_err(mrioc, "Failed to MU reset IOC error %d\n",
+			    retval);
+		}
+		ioc_state = mpi3mr_get_iocstate(mrioc);
+	}
+	if (ioc_state != MRIOC_STATE_RESET) {
+		mpi3mr_print_fault_info(mrioc);
+		retval = mpi3mr_issue_reset(mrioc,
+		    MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET,
+		    MPI3MR_RESET_FROM_BRINGUP);
+		if (retval) {
+			ioc_err(mrioc,
+			    "%s :Failed to soft reset IOC error %d\n",
+			    __func__, retval);
+			goto out_failed;
+		}
+	}
+	ioc_state = mpi3mr_get_iocstate(mrioc);
+	if (ioc_state != MRIOC_STATE_RESET) {
+		ioc_err(mrioc, "Cannot bring IOC to reset state\n");
+		goto out_failed;
+	}
+
+	retval = mpi3mr_setup_admin_qpair(mrioc);
+	if (retval) {
+		ioc_err(mrioc, "Failed to setup admin Qs: error %d\n",
+		    retval);
+		goto out_failed;
+	}
+
+	retval = mpi3mr_bring_ioc_ready(mrioc);
+	if (retval) {
+		ioc_err(mrioc, "Failed to bring ioc ready: error %d\n",
+		    retval);
+		goto out_failed;
+	}
+
+	retval = mpi3mr_setup_isr(mrioc, 1);
+	if (retval) {
+		ioc_err(mrioc, "Failed to setup ISR error %d\n",
+		    retval);
+		goto out_failed;
+	}
+
+	retval = mpi3mr_issue_iocfacts(mrioc, &facts_data);
+	if (retval) {
+		ioc_err(mrioc, "Failed to Issue IOC Facts %d\n",
+		    retval);
+		goto out_failed;
+	}
+
+	mpi3mr_process_factsdata(mrioc, &facts_data);
+	retval = mpi3mr_check_reset_dma_mask(mrioc);
+	if (retval) {
+		ioc_err(mrioc, "Resetting dma mask failed %d\n",
+		    retval);
+		goto out_failed;
+	}
+
+	retval = mpi3mr_alloc_reply_sense_bufs(mrioc);
+	if (retval) {
+		ioc_err(mrioc,
+		    "%s :Failed to allocated reply sense buffers %d\n",
+		    __func__, retval);
+		goto out_failed;
+	}
+
+	retval = mpi3mr_alloc_chain_bufs(mrioc);
+	if (retval) {
+		ioc_err(mrioc, "Failed to allocated chain buffers %d\n",
+		    retval);
+		goto out_failed;
+	}
+
+	retval = mpi3mr_issue_iocinit(mrioc);
+	if (retval) {
+		ioc_err(mrioc, "Failed to Issue IOC Init %d\n",
+		    retval);
+		goto out_failed;
+	}
+	mrioc->reply_free_queue_host_index = mrioc->num_reply_bufs;
+	writel(mrioc->reply_free_queue_host_index,
+	    &mrioc->sysif_regs->ReplyFreeHostIndex);
+
+	mrioc->sbq_host_index = mrioc->num_sense_bufs;
+	writel(mrioc->sbq_host_index,
+	    &mrioc->sysif_regs->SenseBufferFreeHostIndex);
+
+	retval = mpi3mr_setup_isr(mrioc, 0);
+	if (retval) {
+		ioc_err(mrioc, "Failed to re-setup ISR, error %d\n",
+		    retval);
+		goto out_failed;
+	}
+
+	return retval;
+
+out_failed:
+	mpi3mr_cleanup_ioc(mrioc);
+out_nocleanup:
+	return retval;
+}
+
+
+/**
+ * mpi3mr_free_mem - Free memory allocated for a controller
+ * @mrioc: Adapter instance reference
+ *
+ * Free all the memory allocated for a controller.
+ *
+ * Return: Nothing.
+ */
+static void mpi3mr_free_mem(struct mpi3mr_ioc *mrioc)
+{
+	u16 i;
+	struct mpi3mr_intr_info *intr_info;
+
+	if (mrioc->sense_buf_pool) {
+		if (mrioc->sense_buf)
+			dma_pool_free(mrioc->sense_buf_pool, mrioc->sense_buf,
+			    mrioc->sense_buf_dma);
+		dma_pool_destroy(mrioc->sense_buf_pool);
+		mrioc->sense_buf = NULL;
+		mrioc->sense_buf_pool = NULL;
+	}
+	if (mrioc->sense_buf_q_pool) {
+		if (mrioc->sense_buf_q)
+			dma_pool_free(mrioc->sense_buf_q_pool,
+			    mrioc->sense_buf_q, mrioc->sense_buf_q_dma);
+		dma_pool_destroy(mrioc->sense_buf_q_pool);
+		mrioc->sense_buf_q = NULL;
+		mrioc->sense_buf_q_pool = NULL;
+	}
+
+	if (mrioc->reply_buf_pool) {
+		if (mrioc->reply_buf)
+			dma_pool_free(mrioc->reply_buf_pool, mrioc->reply_buf,
+			    mrioc->reply_buf_dma);
+		dma_pool_destroy(mrioc->reply_buf_pool);
+		mrioc->reply_buf = NULL;
+		mrioc->reply_buf_pool = NULL;
+	}
+	if (mrioc->reply_free_q_pool) {
+		if (mrioc->reply_free_q)
+			dma_pool_free(mrioc->reply_free_q_pool,
+			    mrioc->reply_free_q, mrioc->reply_free_q_dma);
+		dma_pool_destroy(mrioc->reply_free_q_pool);
+		mrioc->reply_free_q = NULL;
+		mrioc->reply_free_q_pool = NULL;
+	}
+
+	for (i = 0; i < mrioc->intr_info_count; i++) {
+		intr_info = mrioc->intr_info + i;
+		if (intr_info)
+			intr_info->op_reply_q = NULL;
+	}
+
+	kfree(mrioc->req_qinfo);
+	mrioc->req_qinfo = NULL;
+	mrioc->num_op_req_q = 0;
+
+	kfree(mrioc->op_reply_qinfo);
+	mrioc->op_reply_qinfo = NULL;
+	mrioc->num_op_reply_q = 0;
+
+	kfree(mrioc->init_cmds.reply);
+	mrioc->init_cmds.reply = NULL;
+
+	kfree(mrioc->chain_bitmap);
+	mrioc->chain_bitmap = NULL;
+
+	if (mrioc->chain_buf_pool) {
+		for (i = 0; i < mrioc->chain_buf_count; i++) {
+			if (mrioc->chain_sgl_list[i].addr) {
+				dma_pool_free(mrioc->chain_buf_pool,
+				    mrioc->chain_sgl_list[i].addr,
+				    mrioc->chain_sgl_list[i].dma_addr);
+				mrioc->chain_sgl_list[i].addr = NULL;
+			}
+		}
+		dma_pool_destroy(mrioc->chain_buf_pool);
+		mrioc->chain_buf_pool = NULL;
+	}
+
+	kfree(mrioc->chain_sgl_list);
+	mrioc->chain_sgl_list = NULL;
+
+	if (mrioc->admin_reply_base) {
+		dma_free_coherent(&mrioc->pdev->dev, mrioc->admin_reply_q_sz,
+		    mrioc->admin_reply_base, mrioc->admin_reply_dma);
+		mrioc->admin_reply_base = NULL;
+	}
+	if (mrioc->admin_req_base) {
+		dma_free_coherent(&mrioc->pdev->dev, mrioc->admin_req_q_sz,
+		    mrioc->admin_req_base, mrioc->admin_req_dma);
+		mrioc->admin_req_base = NULL;
+	}
+
+}
+
+/**
+ * mpi3mr_issue_ioc_shutdown - Shutdown controller
+ * @mrioc: Adapter instance reference
+ *
+ * Send shutodwn notification to the controller and wait for the
+ * shutdown_timeout for it to be completed.
+ *
+ * Return: Nothing.
+ */
+static void mpi3mr_issue_ioc_shutdown(struct mpi3mr_ioc *mrioc)
+{
+	u32 ioc_config, ioc_status;
+	u8 retval = 1;
+	u32 timeout = MPI3MR_DEFAULT_SHUTDOWN_TIME * 10;
+
+	ioc_info(mrioc, "Issuing Shutdown Notification\n");
+	if (mrioc->unrecoverable) {
+		ioc_warn(mrioc,
+		    "IOC is unrecoverable Shutdown is not issued\n");
+		return;
+	}
+	ioc_status = readl(&mrioc->sysif_regs->IOCStatus);
+	if ((ioc_status & MPI3_SYSIF_IOC_STATUS_SHUTDOWN_MASK)
+	    == MPI3_SYSIF_IOC_STATUS_SHUTDOWN_IN_PROGRESS) {
+		ioc_info(mrioc, "Shutdown already in progress\n");
+		return;
+	}
+
+	ioc_config = readl(&mrioc->sysif_regs->IOCConfiguration);
+	ioc_config |= MPI3_SYSIF_IOC_CONFIG_SHUTDOWN_NORMAL;
+	ioc_config |= MPI3_SYSIF_IOC_CONFIG_DEVICE_SHUTDOWN;
+
+	writel(ioc_config, &mrioc->sysif_regs->IOCConfiguration);
+
+	if (mrioc->facts.shutdown_timeout)
+		timeout = mrioc->facts.shutdown_timeout * 10;
+
+	do {
+		ioc_status = readl(&mrioc->sysif_regs->IOCStatus);
+		if ((ioc_status & MPI3_SYSIF_IOC_STATUS_SHUTDOWN_MASK)
+		    == MPI3_SYSIF_IOC_STATUS_SHUTDOWN_COMPLETE) {
+			retval = 0;
+			break;
+		}
+		msleep(100);
+	} while (--timeout);
+
+
+	ioc_status = readl(&mrioc->sysif_regs->IOCStatus);
+	ioc_config = readl(&mrioc->sysif_regs->IOCConfiguration);
+
+	if (retval) {
+		if ((ioc_status & MPI3_SYSIF_IOC_STATUS_SHUTDOWN_MASK)
+		    == MPI3_SYSIF_IOC_STATUS_SHUTDOWN_IN_PROGRESS)
+			ioc_warn(mrioc,
+			    "Shutdown still in progress after timeout\n");
+	}
+
+	ioc_info(mrioc,
+	    "Base IOC Sts/Config after %s shutdown is (0x%x)/(0x%x)\n",
+	    (!retval)?"successful":"failed", ioc_status,
+	    ioc_config);
+}
+
+/**
+ * mpi3mr_cleanup_ioc - Cleanup controller
+ * @mrioc: Adapter instance reference
+ *
+ * Controller cleanup handler, Message unit reset or soft reset
+ * and shutdown notification is issued to the controller and the
+ * associated memory resources are freed.
+ *
+ * Return: Nothing.
+ */
+void mpi3mr_cleanup_ioc(struct mpi3mr_ioc *mrioc)
+{
+	enum mpi3mr_iocstate ioc_state;
+
+	mpi3mr_ioc_disable_intr(mrioc);
+
+	ioc_state = mpi3mr_get_iocstate(mrioc);
+
+	if ((!mrioc->unrecoverable) && (!mrioc->reset_in_progress) &&
+	     (ioc_state == MRIOC_STATE_READY)) {
+		if (mpi3mr_issue_and_process_mur(mrioc,
+		    MPI3MR_RESET_FROM_CTLR_CLEANUP))
+			mpi3mr_issue_reset(mrioc,
+			    MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET,
+			    MPI3MR_RESET_FROM_MUR_FAILURE);
+
+		 mpi3mr_issue_ioc_shutdown(mrioc);
+	}
+
+	mpi3mr_free_mem(mrioc);
+	mpi3mr_cleanup_resources(mrioc);
+}
+
+
+/**
+ * mpi3mr_soft_reset_handler - Reset the controller
+ * @mrioc: Adapter instance reference
+ * @reset_reason: Reset reason code
+ * @snapdump: Flag to generate snapdump in firmware or not
+ *
+ * TBD
+ *
+ * Return: 0 on success, non-zero on failure.
+ */
+int mpi3mr_soft_reset_handler(struct mpi3mr_ioc *mrioc,
+	u32 reset_reason, u8 snapdump)
+{
+	return 0;
+}
diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c
new file mode 100644
index 000000000000..c31ec9883152
--- /dev/null
+++ b/drivers/scsi/mpi3mr/mpi3mr_os.c
@@ -0,0 +1,368 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Driver for Broadcom MPI3 Storage Controllers
+ *
+ * Copyright (C) 2017-2020 Broadcom Inc.
+ *  (mailto: mpi3mr-linuxdrv.pdl@broadcom.com)
+ *
+ */
+
+#include "mpi3mr.h"
+
+/* global driver scop variables */
+LIST_HEAD(mrioc_list);
+DEFINE_SPINLOCK(mrioc_list_lock);
+static int mrioc_ids;
+static int warn_non_secure_ctlr;
+
+MODULE_AUTHOR(MPI3MR_DRIVER_AUTHOR);
+MODULE_DESCRIPTION(MPI3MR_DRIVER_DESC);
+MODULE_LICENSE(MPI3MR_DRIVER_LICENSE);
+MODULE_VERSION(MPI3MR_DRIVER_VERSION);
+
+/* Module parameters*/
+int logging_level;
+module_param(logging_level, int, 0);
+MODULE_PARM_DESC(logging_level,
+	" bits for enabling additional logging info (default=0)");
+
+
+/**
+ * mpi3mr_map_queues - Map queues callback handler
+ * @shost: SCSI host reference
+ *
+ * Call the blk_mq_pci_map_queues with from which operational
+ * queue the mapping has to be done
+ *
+ * Return: return of blk_mq_pci_map_queues
+ */
+static int mpi3mr_map_queues(struct Scsi_Host *shost)
+{
+	struct mpi3mr_ioc *mrioc = shost_priv(shost);
+
+	return blk_mq_pci_map_queues(&shost->tag_set.map[HCTX_TYPE_DEFAULT],
+	    mrioc->pdev, 0);
+}
+
+/**
+ * mpi3mr_slave_destroy - Slave destroy callback handler
+ * @sdev: SCSI device reference
+ *
+ * Cleanup and free per device(LUN) private data.
+ *
+ * Return: Nothing.
+ */
+static void mpi3mr_slave_destroy(struct scsi_device *sdev)
+{
+}
+
+/**
+ * mpi3mr_target_destroy - Target destroy callback handler
+ * @starget: SCSI target reference
+ *
+ * Cleanup and free per target private data.
+ *
+ * Return: Nothing.
+ */
+static void mpi3mr_target_destroy(struct scsi_target *starget)
+{
+}
+
+/**
+ * mpi3mr_slave_configure - Slave configure callback handler
+ * @sdev: SCSI device reference
+ *
+ * Configure queue depth, max hardware sectors and virt boundary
+ * as required
+ *
+ * Return: 0 always.
+ */
+static int mpi3mr_slave_configure(struct scsi_device *sdev)
+{
+	int retval = 0;
+	return retval;
+}
+
+/**
+ * mpi3mr_slave_alloc -Slave alloc callback handler
+ * @sdev: SCSI device reference
+ *
+ * Allocate per device(LUN) private data and initialize it.
+ *
+ * Return: 0 on success -ENOMEM on memory allocation failure.
+ */
+static int mpi3mr_slave_alloc(struct scsi_device *sdev)
+{
+	int retval = 0;
+	return retval;
+}
+
+/**
+ * mpi3mr_target_alloc - Target alloc callback handler
+ * @starget: SCSI target reference
+ *
+ * Allocate per target private data and initialize it.
+ *
+ * Return: 0 on success -ENOMEM on memory allocation failure.
+ */
+static int mpi3mr_target_alloc(struct scsi_target *starget)
+{
+	int retval = -ENODEV;
+	return retval;
+}
+
+/**
+ * mpi3mr_qcmd - I/O request despatcher
+ * @shost: SCSI Host reference
+ * @scmd: SCSI Command reference
+ *
+ * Issues the SCSI Command as an MPI3 request.
+ *
+ * Return: 0 on successful queueing of the request or if the
+ *         request is completed with failure.
+ *         SCSI_MLQUEUE_DEVICE_BUSY when the device is busy.
+ *         SCSI_MLQUEUE_HOST_BUSY when the host queue is full.
+ */
+static int mpi3mr_qcmd(struct Scsi_Host *shost,
+	struct scsi_cmnd *scmd)
+{
+	int retval = 0;
+
+	scmd->result = DID_NO_CONNECT << 16;
+	scmd->scsi_done(scmd);
+	return retval;
+}
+
+static struct scsi_host_template mpi3mr_driver_template = {
+	.module				= THIS_MODULE,
+	.name				= "MPI3 Storage Controller",
+	.proc_name			= MPI3MR_DRIVER_NAME,
+	.queuecommand			= mpi3mr_qcmd,
+	.target_alloc			= mpi3mr_target_alloc,
+	.slave_alloc			= mpi3mr_slave_alloc,
+	.slave_configure		= mpi3mr_slave_configure,
+	.target_destroy			= mpi3mr_target_destroy,
+	.slave_destroy			= mpi3mr_slave_destroy,
+	.map_queues			= mpi3mr_map_queues,
+	.no_write_same			= 1,
+	.can_queue			= 1,
+	.this_id			= -1,
+	.sg_tablesize			= MPI3MR_SG_DEPTH,
+	/* max xfer supported is 1M (2K in 512 byte sized sectors)
+	 */
+	.max_sectors			= 2048,
+	.cmd_per_lun			= MPI3MR_MAX_CMDS_LUN,
+	.track_queue_depth		= 1,
+	.cmd_size			= sizeof(struct scmd_priv),
+};
+
+
+/**
+ * mpi3mr_init_drv_cmd - Initialize internal command tracker
+ * @cmdptr: Internal command tracker
+ * @host_tag: Host tag used for the specific command
+ *
+ * Initialize the internal command tracker structure with
+ * specified host tag.
+ *
+ * Return: Nothing.
+ */
+static inline void mpi3mr_init_drv_cmd(struct mpi3mr_drv_cmd *cmdptr,
+	u16 host_tag)
+{
+	mutex_init(&cmdptr->mutex);
+	cmdptr->reply = NULL;
+	cmdptr->state = MPI3MR_CMD_NOTUSED;
+	cmdptr->dev_handle = MPI3MR_INVALID_DEV_HANDLE;
+	cmdptr->host_tag = host_tag;
+}
+
+/**
+ * mpi3mr_probe - PCI probe callback
+ * @pdev: PCI device instance
+ * @id: PCI device ID details
+ *
+ * Controller initialization routine. Checks the security status
+ * of the controller and if it is invalid or tampered return the
+ * probe without initializing the controller. Otherwise,
+ * allocate per adapter instance through shost_priv and
+ * initialize controller specific data structures, initializae
+ * the controller hardware, add shost to the SCSI subsystem.
+ *
+ * Return: 0 on success, non-zero on failure.
+ */
+
+static int
+mpi3mr_probe(struct pci_dev *pdev, const struct pci_device_id *id)
+{
+	struct mpi3mr_ioc *mrioc = NULL;
+	struct Scsi_Host *shost = NULL;
+	int retval = 0;
+
+	shost = scsi_host_alloc(&mpi3mr_driver_template,
+	    sizeof(struct mpi3mr_ioc));
+	if (!shost) {
+		retval = -ENODEV;
+		goto shost_failed;
+	}
+
+	mrioc = shost_priv(shost);
+	mrioc->id = mrioc_ids++;
+	sprintf(mrioc->driver_name, "%s", MPI3MR_DRIVER_NAME);
+	sprintf(mrioc->name, "%s%d", mrioc->driver_name, mrioc->id);
+	INIT_LIST_HEAD(&mrioc->list);
+	spin_lock(&mrioc_list_lock);
+	list_add_tail(&mrioc->list, &mrioc_list);
+	spin_unlock(&mrioc_list_lock);
+
+	spin_lock_init(&mrioc->admin_req_lock);
+	spin_lock_init(&mrioc->reply_free_queue_lock);
+	spin_lock_init(&mrioc->sbq_lock);
+
+	mpi3mr_init_drv_cmd(&mrioc->init_cmds, MPI3MR_HOSTTAG_INITCMDS);
+
+	mrioc->logging_level = logging_level;
+	mrioc->shost = shost;
+	mrioc->pdev = pdev;
+
+	/* init shost parameters */
+	shost->max_cmd_len = MPI3MR_MAX_CDB_LENGTH;
+	shost->max_lun = -1;
+	shost->unique_id = mrioc->id;
+
+	shost->max_channel = 1;
+	shost->max_id = 0xFFFFFFFF;
+
+	mrioc->is_driver_loading = 1;
+	if (mpi3mr_init_ioc(mrioc)) {
+		ioc_err(mrioc, "failure at %s:%d/%s()!\n",
+		    __FILE__, __LINE__, __func__);
+		retval = -ENODEV;
+		goto out_iocinit_failed;
+	}
+
+	shost->nr_hw_queues = mrioc->num_op_reply_q;
+	shost->can_queue = mrioc->max_host_ios;
+	shost->sg_tablesize = MPI3MR_SG_DEPTH;
+	shost->max_id = mrioc->facts.max_perids;
+
+	retval = scsi_add_host(shost, &pdev->dev);
+	if (retval) {
+		ioc_err(mrioc, "failure at %s:%d/%s()!\n",
+		    __FILE__, __LINE__, __func__);
+		goto addhost_failed;
+	}
+
+	scsi_scan_host(shost);
+	return retval;
+
+addhost_failed:
+	mpi3mr_cleanup_ioc(mrioc);
+out_iocinit_failed:
+	spin_lock(&mrioc_list_lock);
+	list_del(&mrioc->list);
+	spin_unlock(&mrioc_list_lock);
+	scsi_host_put(shost);
+shost_failed:
+	return retval;
+}
+
+/**
+ * mpi3mr_remove - PCI remove callback
+ * @pdev: PCI device instance
+ *
+ * Free up all memory and resources associated with the
+ * controllerand target devices, unregister the shost.
+ *
+ * Return: Nothing.
+ */
+static void mpi3mr_remove(struct pci_dev *pdev)
+{
+	struct Scsi_Host *shost = pci_get_drvdata(pdev);
+	struct mpi3mr_ioc *mrioc;
+
+	mrioc = shost_priv(shost);
+	while (mrioc->reset_in_progress || mrioc->is_driver_loading)
+		ssleep(1);
+
+
+	scsi_remove_host(shost);
+
+	mpi3mr_cleanup_ioc(mrioc);
+
+	spin_lock(&mrioc_list_lock);
+	list_del(&mrioc->list);
+	spin_unlock(&mrioc_list_lock);
+
+	scsi_host_put(shost);
+}
+
+/**
+ * mpi3mr_shutdown - PCI shutdown callback
+ * @pdev: PCI device instance
+ *
+ * Free up all memory and resources associated with the
+ * controller
+ *
+ * Return: Nothing.
+ */
+static void mpi3mr_shutdown(struct pci_dev *pdev)
+{
+	struct Scsi_Host *shost = pci_get_drvdata(pdev);
+	struct mpi3mr_ioc *mrioc;
+
+	if (!shost)
+		return;
+
+	mrioc = shost_priv(shost);
+	while (mrioc->reset_in_progress || mrioc->is_driver_loading)
+		ssleep(1);
+
+	mpi3mr_cleanup_ioc(mrioc);
+
+}
+
+static const struct pci_device_id mpi3mr_pci_id_table[] = {
+	{
+		PCI_DEVICE_SUB(PCI_VENDOR_ID_LSI_LOGIC, 0x00A5,
+		    PCI_ANY_ID, PCI_ANY_ID)
+	},
+	{ 0 }
+};
+MODULE_DEVICE_TABLE(pci, mpi3mr_pci_id_table);
+
+static struct pci_driver mpi3mr_pci_driver = {
+	.name = MPI3MR_DRIVER_NAME,
+	.id_table = mpi3mr_pci_id_table,
+	.probe = mpi3mr_probe,
+	.remove = mpi3mr_remove,
+	.shutdown = mpi3mr_shutdown,
+};
+
+static int __init mpi3mr_init(void)
+{
+	int ret_val;
+
+	pr_info("Loading %s version %s\n", MPI3MR_DRIVER_NAME,
+	    MPI3MR_DRIVER_VERSION);
+
+	ret_val = pci_register_driver(&mpi3mr_pci_driver);
+
+	return ret_val;
+}
+
+static void __exit mpi3mr_exit(void)
+{
+	if (warn_non_secure_ctlr)
+		pr_warn(
+		    "Unloading %s version %s while managing a non secure controller\n",
+		    MPI3MR_DRIVER_NAME, MPI3MR_DRIVER_VERSION);
+	else
+		pr_info("Unloading %s version %s\n", MPI3MR_DRIVER_NAME,
+		    MPI3MR_DRIVER_VERSION);
+
+	pci_unregister_driver(&mpi3mr_pci_driver);
+}
+
+module_init(mpi3mr_init);
+module_exit(mpi3mr_exit);
-- 
2.18.1


-- 
This electronic communication and the information and any files transmitted 
with it, or attached to it, are confidential and are intended solely for 
the use of the individual or entity to whom it is addressed and may contain 
information that is confidential, legally privileged, protected by privacy 
laws, or otherwise restricted from disclosure to anyone else. If you are 
not the intended recipient or the person responsible for delivering the 
e-mail to the intended recipient, you are hereby notified that any use, 
copying, distributing, dissemination, forwarding, printing, or copying of 
this e-mail is strictly prohibited. If you received this e-mail in error, 
please return the e-mail to the sender, delete it from your computer, and 
destroy any printed copy of it.

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4169 bytes --]

^ permalink raw reply related	[flat|nested] 75+ messages in thread

* [PATCH 03/24] mpi3mr: create operational request and reply queue pair
  2020-12-22 10:11 [PATCH 00/24] Introducing mpi3mr driver Kashyap Desai
  2020-12-22 10:11 ` [PATCH 01/24] mpi3mr: add mpi30 Rev-R headers and Kconfig Kashyap Desai
  2020-12-22 10:11 ` [PATCH 02/24] mpi3mr: base driver code Kashyap Desai
@ 2020-12-22 10:11 ` Kashyap Desai
  2020-12-22 18:18   ` Bart Van Assche
  2021-02-28 13:04   ` Hannes Reinecke
  2020-12-22 10:11 ` [PATCH 04/24] mpi3mr: add support of queue command processing Kashyap Desai
                   ` (21 subsequent siblings)
  24 siblings, 2 replies; 75+ messages in thread
From: Kashyap Desai @ 2020-12-22 10:11 UTC (permalink / raw)
  To: linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, Kashyap Desai, sathya.prakash

[-- Attachment #1: Type: text/plain, Size: 25421 bytes --]

Create operational request and reply queue pair.

The MPI3 transport interface consists of an Administrative Request Queue,
an Administrative Reply Queue, and Operational Messaging Queues.
The Operational Messaging Queues are the primary communication mechanism
between the host and the I/O Controller (IOC).
Request messages, allocated in host memory, identify I/O operations to be
performed by the IOC. These operations are queued on an Operational
Request Queue by the host driver.
Reply descriptors track I/O operations as they complete.
The IOC queues these completions in an Operational Reply Queue.

To fulfil large contiguous memory requirement, driver creates multiple
segments and provide the list of segments. Each segment size should be 4K
which is h/w requirement. An element array is contiguous or segmented.
A contiguous element array is located in contiguous physical memory.
A contiguous element array must be aligned on an element size boundary.
An element's physical address within the array may be directly calculated
from the base address, the Producer/Consumer index, and the element size.

Expected phased identifier bit is used to find out valid entry on reply queue.
Driver set <ephase> bit and IOC invert the value of this bit on each pass.

Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Cc: sathya.prakash@broadcom.com
---
 drivers/scsi/mpi3mr/mpi3mr.h    |  56 +++
 drivers/scsi/mpi3mr/mpi3mr_fw.c | 601 ++++++++++++++++++++++++++++++++
 drivers/scsi/mpi3mr/mpi3mr_os.c |   4 +-
 3 files changed, 660 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/mpi3mr/mpi3mr.h b/drivers/scsi/mpi3mr/mpi3mr.h
index dd79b12218e1..fe6094bb357a 100644
--- a/drivers/scsi/mpi3mr/mpi3mr.h
+++ b/drivers/scsi/mpi3mr/mpi3mr.h
@@ -71,6 +71,12 @@ extern struct list_head mrioc_list;
 #define MPI3MR_ADMIN_REQ_FRAME_SZ	128
 #define MPI3MR_ADMIN_REPLY_FRAME_SZ	16
 
+/* Operational queue management definitions */
+#define MPI3MR_OP_REQ_Q_QD		512
+#define MPI3MR_OP_REP_Q_QD		4096
+#define MPI3MR_OP_REQ_Q_SEG_SIZE	4096
+#define MPI3MR_OP_REP_Q_SEG_SIZE	4096
+#define MPI3MR_MAX_SEG_LIST_SIZE	4096
 
 /* Reserved Host Tag definitions */
 #define MPI3MR_HOSTTAG_INVALID		0xFFFF
@@ -132,6 +138,9 @@ extern struct list_head mrioc_list;
 	(MPI3_SGE_FLAGS_ELEMENT_TYPE_SIMPLE | MPI3_SGE_FLAGS_DLAS_SYSTEM | \
 	MPI3_SGE_FLAGS_END_OF_LIST)
 
+/* MSI Index from Reply Queue Index */
+#define REPLY_QUEUE_IDX_TO_MSIX_IDX(qidx, offset)	(qidx + offset)
+
 /* IOC State definitions */
 enum mpi3mr_iocstate {
 	MRIOC_STATE_READY = 1,
@@ -222,15 +231,45 @@ struct mpi3mr_ioc_facts {
 	u8 sge_mod_shift;
 };
 
+/**
+ * struct segments - memory descriptor structure to store
+ * virtual and dma addresses for operational queue segments.
+ *
+ * @segment: virtual address
+ * @segment_dma: dma address
+ */
+struct segments {
+	void *segment;
+	dma_addr_t segment_dma;
+};
+
 /**
  * struct op_req_qinfo -  Operational Request Queue Information
  *
  * @ci: consumer index
  * @pi: producer index
+ * @num_request: Maximum number of entries in the queue
+ * @qid: Queue Id starting from 1
+ * @reply_qid: Associated reply queue Id
+ * @num_segments: Number of discontiguous memory segments
+ * @segment_qd: Depth of each segments
+ * @q_lock: Concurrent queue access lock
+ * @q_segments: Segment descriptor pointer
+ * @q_segment_list: Segment list base virtual address
+ * @q_segment_list_dma: Segment list base DMA address
  */
 struct op_req_qinfo {
 	u16 ci;
 	u16 pi;
+	u16 num_requests;
+	u16 qid;
+	u16 reply_qid;
+	u16 num_segments;
+	u16 segment_qd;
+	spinlock_t q_lock;
+	struct segments *q_segments;
+	void *q_segment_list;
+	dma_addr_t q_segment_list_dma;
 };
 
 /**
@@ -238,10 +277,24 @@ struct op_req_qinfo {
  *
  * @ci: consumer index
  * @qid: Queue Id starting from 1
+ * @num_replies: Maximum number of entries in the queue
+ * @num_segments: Number of discontiguous memory segments
+ * @segment_qd: Depth of each segments
+ * @q_segments: Segment descriptor pointer
+ * @q_segment_list: Segment list base virtual address
+ * @q_segment_list_dma: Segment list base DMA address
+ * @ephase: Expected phased identifier for the reply queue
  */
 struct op_reply_qinfo {
 	u16 ci;
 	u16 qid;
+	u16 num_replies;
+	u16 num_segments;
+	u16 segment_qd;
+	struct segments *q_segments;
+	void *q_segment_list;
+	dma_addr_t q_segment_list_dma;
+	u8 ephase;
 };
 
 /**
@@ -402,6 +455,7 @@ struct scmd_priv {
  * @current_event: Firmware event currently in process
  * @driver_info: Driver, Kernel, OS information to firmware
  * @change_count: Topology change count
+ * @op_reply_q_offset: Operational reply queue offset with MSIx
  */
 struct mpi3mr_ioc {
 	struct list_head list;
@@ -409,6 +463,7 @@ struct mpi3mr_ioc {
 	struct Scsi_Host *shost;
 	u8 id;
 	int cpu_count;
+	bool enable_segqueue;
 
 	char name[MPI3MR_NAME_LENGTH];
 	char driver_name[MPI3MR_NAME_LENGTH];
@@ -495,6 +550,7 @@ struct mpi3mr_ioc {
 	struct mpi3mr_fwevt *current_event;
 	Mpi3DriverInfoLayout_t driver_info;
 	u16 change_count;
+	u16 op_reply_q_offset;
 };
 
 int mpi3mr_setup_resources(struct mpi3mr_ioc *mrioc);
diff --git a/drivers/scsi/mpi3mr/mpi3mr_fw.c b/drivers/scsi/mpi3mr/mpi3mr_fw.c
index 97eb7e6ec5c6..6fb28983038e 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_fw.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_fw.c
@@ -408,6 +408,8 @@ static int mpi3mr_setup_isr(struct mpi3mr_ioc *mrioc, u8 setup_one)
 
 	irq_flags |= PCI_IRQ_AFFINITY | PCI_IRQ_ALL_TYPES;
 
+	mrioc->op_reply_q_offset = (max_vectors > 1) ? 1 : 0;
+
 	i = pci_alloc_irq_vectors_affinity(mrioc->pdev,
 	    1, max_vectors, irq_flags, &desc);
 	if (i <= 0) {
@@ -418,6 +420,12 @@ static int mpi3mr_setup_isr(struct mpi3mr_ioc *mrioc, u8 setup_one)
 		ioc_info(mrioc,
 		    "allocated vectors (%d) are less than configured (%d)\n",
 		    i, max_vectors);
+		/*
+		 * If only one MSI-x is allocated, then MSI-x 0 will be shared
+		 * between Admin queue and operational queue
+		 */
+		if (i == 1)
+			mrioc->op_reply_q_offset = 0;
 
 		max_vectors = i;
 	}
@@ -726,6 +734,586 @@ int mpi3mr_admin_request_post(struct mpi3mr_ioc *mrioc, void *admin_req,
 	return retval;
 }
 
+/**
+ * mpi3mr_free_op_req_q_segments - free request memory segments
+ * @mrioc: Adapter instance reference
+ * @q_idx: operational request queue index
+ *
+ * Free memory segments allocated for operational request queue
+ *
+ * Return: Nothing.
+ */
+static void mpi3mr_free_op_req_q_segments(struct mpi3mr_ioc *mrioc, u16 q_idx)
+{
+	u16 j;
+	int size;
+	struct segments *segments;
+
+	segments = mrioc->req_qinfo[q_idx].q_segments;
+	if (!segments)
+		return;
+
+	if (mrioc->enable_segqueue) {
+		size = MPI3MR_OP_REQ_Q_SEG_SIZE;
+		if (mrioc->req_qinfo[q_idx].q_segment_list) {
+			dma_free_coherent(&mrioc->pdev->dev,
+			    MPI3MR_MAX_SEG_LIST_SIZE,
+			    mrioc->req_qinfo[q_idx].q_segment_list,
+			    mrioc->req_qinfo[q_idx].q_segment_list_dma);
+			mrioc->op_reply_qinfo[q_idx].q_segment_list = NULL;
+		}
+	} else
+		size = mrioc->req_qinfo[q_idx].num_requests *
+		    mrioc->facts.op_req_sz;
+
+	for (j = 0; j < mrioc->req_qinfo[q_idx].num_segments; j++) {
+		if (!segments[j].segment)
+			continue;
+		dma_free_coherent(&mrioc->pdev->dev,
+		    size, segments[j].segment, segments[j].segment_dma);
+		segments[j].segment = NULL;
+	}
+	kfree(mrioc->req_qinfo[q_idx].q_segments);
+	mrioc->req_qinfo[q_idx].q_segments = NULL;
+	mrioc->req_qinfo[q_idx].qid = 0;
+}
+
+/**
+ * mpi3mr_free_op_reply_q_segments - free reply memory segments
+ * @mrioc: Adapter instance reference
+ * @q_idx: operational reply queue index
+ *
+ * Free memory segments allocated for operational reply queue
+ *
+ * Return: Nothing.
+ */
+static void mpi3mr_free_op_reply_q_segments(struct mpi3mr_ioc *mrioc, u16 q_idx)
+{
+	u16 j;
+	int size;
+	struct segments *segments;
+
+	segments = mrioc->op_reply_qinfo[q_idx].q_segments;
+	if (!segments)
+		return;
+
+	if (mrioc->enable_segqueue) {
+		size = MPI3MR_OP_REP_Q_SEG_SIZE;
+		if (mrioc->op_reply_qinfo[q_idx].q_segment_list) {
+			dma_free_coherent(&mrioc->pdev->dev,
+			    MPI3MR_MAX_SEG_LIST_SIZE,
+			    mrioc->op_reply_qinfo[q_idx].q_segment_list,
+			    mrioc->op_reply_qinfo[q_idx].q_segment_list_dma);
+			mrioc->op_reply_qinfo[q_idx].q_segment_list = NULL;
+		}
+	} else
+		size = mrioc->op_reply_qinfo[q_idx].segment_qd *
+		    mrioc->op_reply_desc_sz;
+
+	for (j = 0; j < mrioc->op_reply_qinfo[q_idx].num_segments; j++) {
+		if (!segments[j].segment)
+			continue;
+		dma_free_coherent(&mrioc->pdev->dev,
+		    size, segments[j].segment, segments[j].segment_dma);
+		segments[j].segment = NULL;
+	}
+
+	kfree(mrioc->op_reply_qinfo[q_idx].q_segments);
+	mrioc->op_reply_qinfo[q_idx].q_segments = NULL;
+	mrioc->op_reply_qinfo[q_idx].qid = 0;
+}
+
+/**
+ * mpi3mr_delete_op_reply_q - delete operational reply queue
+ * @mrioc: Adapter instance reference
+ * @qidx: operational reply queue index
+ *
+ * Delete operatinal reply queue by issuing MPI request
+ * through admin queue.
+ *
+ * Return:  0 on success, non-zero on failure.
+ */
+static int mpi3mr_delete_op_reply_q(struct mpi3mr_ioc *mrioc, u16 qidx)
+{
+	Mpi3DeleteReplyQueueRequest_t delq_req;
+	int retval = 0;
+	u16 reply_qid = 0, midx;
+
+	reply_qid = mrioc->op_reply_qinfo[qidx].qid;
+
+	midx = REPLY_QUEUE_IDX_TO_MSIX_IDX(qidx, mrioc->op_reply_q_offset);
+
+	if (!reply_qid)	{
+		retval = -1;
+		ioc_err(mrioc, "Issue DelRepQ: called with invalid ReqQID\n");
+		goto out;
+	}
+
+	memset(&delq_req, 0, sizeof(delq_req));
+	mutex_lock(&mrioc->init_cmds.mutex);
+	if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
+		retval = -1;
+		ioc_err(mrioc, "Issue DelRepQ: Init command is in use\n");
+		mutex_unlock(&mrioc->init_cmds.mutex);
+		goto out;
+	}
+	mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
+	mrioc->init_cmds.is_waiting = 1;
+	mrioc->init_cmds.callback = NULL;
+	delq_req.HostTag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
+	delq_req.Function = MPI3_FUNCTION_DELETE_REPLY_QUEUE;
+	delq_req.QueueID = cpu_to_le16(reply_qid);
+
+	init_completion(&mrioc->init_cmds.done);
+	retval = mpi3mr_admin_request_post(mrioc, &delq_req, sizeof(delq_req),
+	    1);
+	if (retval) {
+		ioc_err(mrioc, "Issue DelRepQ: Admin Post failed\n");
+		goto out_unlock;
+	}
+	wait_for_completion_timeout(&mrioc->init_cmds.done,
+	    (MPI3MR_INTADMCMD_TIMEOUT * HZ));
+	if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
+		ioc_err(mrioc, "Issue DelRepQ: command timed out\n");
+		mpi3mr_set_diagsave(mrioc);
+		mpi3mr_issue_reset(mrioc,
+		    MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT,
+		    MPI3MR_RESET_FROM_DELREPQ_TIMEOUT);
+		mrioc->unrecoverable = 1;
+
+		retval = -1;
+		goto out_unlock;
+	}
+	if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
+	    != MPI3_IOCSTATUS_SUCCESS) {
+		ioc_err(mrioc,
+		    "Issue DelRepQ: Failed IOCStatus(0x%04x) Loginfo(0x%08x)\n",
+		    (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
+		    mrioc->init_cmds.ioc_loginfo);
+		retval = -1;
+		goto out_unlock;
+	}
+	mrioc->intr_info[midx].op_reply_q = NULL;
+
+	mpi3mr_free_op_reply_q_segments(mrioc, qidx);
+out_unlock:
+	mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
+	mutex_unlock(&mrioc->init_cmds.mutex);
+out:
+
+	return retval;
+}
+
+/**
+ * mpi3mr_alloc_op_reply_q_segments -Alloc segmented reply pool
+ * @mrioc: Adapter instance reference
+ * @qidx: request queue index
+ *
+ * Allocate segmented memory pools for operational reply
+ * queue.
+ *
+ * Return: 0 on success, non-zero on failure.
+ */
+static int mpi3mr_alloc_op_reply_q_segments(struct mpi3mr_ioc *mrioc, u16 qidx)
+{
+	struct op_reply_qinfo *op_reply_q = mrioc->op_reply_qinfo + qidx;
+	int i, size;
+	u64 *q_segment_list_entry = NULL;
+	struct segments *segments;
+
+	if (mrioc->enable_segqueue) {
+		op_reply_q->segment_qd =
+		    MPI3MR_OP_REP_Q_SEG_SIZE / mrioc->op_reply_desc_sz;
+
+		size = MPI3MR_OP_REP_Q_SEG_SIZE;
+
+		op_reply_q->q_segment_list = dma_alloc_coherent(&mrioc->pdev->dev,
+		    MPI3MR_MAX_SEG_LIST_SIZE, &op_reply_q->q_segment_list_dma,
+		    GFP_KERNEL);
+		if (!op_reply_q->q_segment_list)
+			return -ENOMEM;
+		q_segment_list_entry = (u64 *)op_reply_q->q_segment_list;
+	} else {
+		op_reply_q->segment_qd = op_reply_q->num_replies;
+		size = op_reply_q->num_replies * mrioc->op_reply_desc_sz;
+	}
+
+	op_reply_q->num_segments = DIV_ROUND_UP(op_reply_q->num_replies,
+	    op_reply_q->segment_qd);
+
+	op_reply_q->q_segments = kcalloc(op_reply_q->num_segments,
+	    sizeof(struct segments), GFP_KERNEL);
+	if (!op_reply_q->q_segments)
+		return -ENOMEM;
+
+	segments = op_reply_q->q_segments;
+	for (i = 0; i < op_reply_q->num_segments; i++) {
+		segments[i].segment =
+		    dma_alloc_coherent(&mrioc->pdev->dev,
+		    size, &segments[i].segment_dma, GFP_KERNEL);
+		if (!segments[i].segment)
+			return -ENOMEM;
+		if (mrioc->enable_segqueue)
+			q_segment_list_entry[i] =
+			    (unsigned long)segments[i].segment_dma;
+	}
+
+	return 0;
+}
+
+/**
+ * mpi3mr_alloc_op_req_q_segments - Alloc segmented req pool.
+ * @mrioc: Adapter instance reference
+ * @qidx: request queue index
+ *
+ * Allocate segmented memory pools for operational request
+ * queue.
+ *
+ * Return: 0 on success, non-zero on failure.
+ */
+static int mpi3mr_alloc_op_req_q_segments(struct mpi3mr_ioc *mrioc, u16 qidx)
+{
+	struct op_req_qinfo *op_req_q = mrioc->req_qinfo + qidx;
+	int i, size;
+	u64 *q_segment_list_entry = NULL;
+	struct segments *segments;
+
+	if (mrioc->enable_segqueue) {
+		op_req_q->segment_qd =
+		    MPI3MR_OP_REQ_Q_SEG_SIZE / mrioc->facts.op_req_sz;
+
+		size = MPI3MR_OP_REQ_Q_SEG_SIZE;
+
+		op_req_q->q_segment_list = dma_alloc_coherent(&mrioc->pdev->dev,
+		    MPI3MR_MAX_SEG_LIST_SIZE, &op_req_q->q_segment_list_dma,
+		    GFP_KERNEL);
+		if (!op_req_q->q_segment_list)
+			return -ENOMEM;
+		q_segment_list_entry = (u64 *)op_req_q->q_segment_list;
+
+	} else {
+		op_req_q->segment_qd = op_req_q->num_requests;
+		size = op_req_q->num_requests * mrioc->facts.op_req_sz;
+	}
+
+	op_req_q->num_segments = DIV_ROUND_UP(op_req_q->num_requests,
+	    op_req_q->segment_qd);
+
+	op_req_q->q_segments = kcalloc(op_req_q->num_segments,
+	    sizeof(struct segments), GFP_KERNEL);
+	if (!op_req_q->q_segments)
+		return -ENOMEM;
+
+	segments = op_req_q->q_segments;
+	for (i = 0; i < op_req_q->num_segments; i++) {
+		segments[i].segment =
+		    dma_alloc_coherent(&mrioc->pdev->dev,
+		    size, &segments[i].segment_dma, GFP_KERNEL);
+		if (!segments[i].segment)
+			return -ENOMEM;
+		if (mrioc->enable_segqueue)
+			q_segment_list_entry[i] =
+			    (unsigned long)segments[i].segment_dma;
+	}
+
+	return 0;
+}
+
+/**
+ * mpi3mr_create_op_reply_q - create operational reply queue
+ * @mrioc: Adapter instance reference
+ * @qidx: operational reply queue index
+ *
+ * Create operatinal reply queue by issuing MPI request
+ * through admin queue.
+ *
+ * Return:  0 on success, non-zero on failure.
+ */
+static int mpi3mr_create_op_reply_q(struct mpi3mr_ioc *mrioc, u16 qidx)
+{
+	Mpi3CreateReplyQueueRequest_t create_req;
+	struct op_reply_qinfo *op_reply_q = mrioc->op_reply_qinfo + qidx;
+	int retval = 0;
+	u16 reply_qid = 0, midx;
+
+
+	reply_qid = op_reply_q->qid;
+
+	midx = REPLY_QUEUE_IDX_TO_MSIX_IDX(qidx, mrioc->op_reply_q_offset);
+
+	if (reply_qid) {
+		retval = -1;
+		ioc_err(mrioc, "CreateRepQ: called for duplicate qid %d\n",
+		    reply_qid);
+
+		return retval;
+	}
+
+	reply_qid = qidx + 1;
+	op_reply_q->num_replies = MPI3MR_OP_REP_Q_QD;
+	op_reply_q->ci = 0;
+	op_reply_q->ephase = 1;
+
+	if (!op_reply_q->q_segments) {
+		retval = mpi3mr_alloc_op_reply_q_segments(mrioc, qidx);
+		if (retval) {
+			mpi3mr_free_op_reply_q_segments(mrioc, qidx);
+			goto out;
+		}
+	}
+
+	memset(&create_req, 0, sizeof(create_req));
+	mutex_lock(&mrioc->init_cmds.mutex);
+	if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
+		retval = -1;
+		ioc_err(mrioc, "CreateRepQ: Init command is in use\n");
+		goto out;
+	}
+	mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
+	mrioc->init_cmds.is_waiting = 1;
+	mrioc->init_cmds.callback = NULL;
+	create_req.HostTag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
+	create_req.Function = MPI3_FUNCTION_CREATE_REPLY_QUEUE;
+	create_req.QueueID = cpu_to_le16(reply_qid);
+	create_req.Flags = MPI3_CREATE_REPLY_QUEUE_FLAGS_INT_ENABLE_ENABLE;
+	create_req.MSIxIndex = cpu_to_le16(mrioc->intr_info[midx].msix_index);
+	if (mrioc->enable_segqueue) {
+		create_req.Flags |=
+		    MPI3_CREATE_REQUEST_QUEUE_FLAGS_SEGMENTED_SEGMENTED;
+		create_req.BaseAddress = cpu_to_le64(
+		    op_reply_q->q_segment_list_dma);
+	} else
+		create_req.BaseAddress = cpu_to_le64(
+		    op_reply_q->q_segments[0].segment_dma);
+
+	create_req.Size = cpu_to_le16(op_reply_q->num_replies);
+
+	init_completion(&mrioc->init_cmds.done);
+	retval = mpi3mr_admin_request_post(mrioc, &create_req,
+	    sizeof(create_req), 1);
+	if (retval) {
+		ioc_err(mrioc, "CreateRepQ: Admin Post failed\n");
+		goto out_unlock;
+	}
+	wait_for_completion_timeout(&mrioc->init_cmds.done,
+	    (MPI3MR_INTADMCMD_TIMEOUT * HZ));
+	if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
+		ioc_err(mrioc, "CreateRepQ: command timed out\n");
+		mpi3mr_set_diagsave(mrioc);
+		mpi3mr_issue_reset(mrioc,
+		    MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT,
+		    MPI3MR_RESET_FROM_CREATEREPQ_TIMEOUT);
+		mrioc->unrecoverable = 1;
+		retval = -1;
+		goto out_unlock;
+	}
+	if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
+	    != MPI3_IOCSTATUS_SUCCESS) {
+		ioc_err(mrioc,
+		    "CreateRepQ: Failed IOCStatus(0x%04x) Loginfo(0x%08x)\n",
+		    (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
+		    mrioc->init_cmds.ioc_loginfo);
+		retval = -1;
+		goto out_unlock;
+	}
+	op_reply_q->qid = reply_qid;
+	mrioc->intr_info[midx].op_reply_q = op_reply_q;
+
+out_unlock:
+	mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
+	mutex_unlock(&mrioc->init_cmds.mutex);
+out:
+
+	return retval;
+}
+
+/**
+ * mpi3mr_create_op_req_q - create operational request queue
+ * @mrioc: Adapter instance reference
+ * @idx: operational request queue index
+ * @reply_qid: Reply queue ID
+ *
+ * Create operatinal request queue by issuing MPI request
+ * through admin queue.
+ *
+ * Return:  0 on success, non-zero on failure.
+ */
+static int mpi3mr_create_op_req_q(struct mpi3mr_ioc *mrioc, u16 idx,
+	u16 reply_qid)
+{
+	Mpi3CreateRequestQueueRequest_t create_req;
+	struct op_req_qinfo *op_req_q = mrioc->req_qinfo + idx;
+	int retval = 0;
+	u16 req_qid = 0;
+
+
+	req_qid = op_req_q->qid;
+
+	if (req_qid) {
+		retval = -1;
+		ioc_err(mrioc, "CreateReqQ: called for duplicate qid %d\n",
+		    req_qid);
+
+		return retval;
+	}
+	req_qid = idx + 1;
+
+	op_req_q->num_requests = MPI3MR_OP_REQ_Q_QD;
+	op_req_q->ci = 0;
+	op_req_q->pi = 0;
+	op_req_q->reply_qid = reply_qid;
+	spin_lock_init(&op_req_q->q_lock);
+
+	if (!op_req_q->q_segments) {
+		retval = mpi3mr_alloc_op_req_q_segments(mrioc, idx);
+		if (retval) {
+			mpi3mr_free_op_req_q_segments(mrioc, idx);
+			goto out;
+		}
+	}
+
+	memset(&create_req, 0, sizeof(create_req));
+	mutex_lock(&mrioc->init_cmds.mutex);
+	if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
+		retval = -1;
+		ioc_err(mrioc, "CreateReqQ: Init command is in use\n");
+		goto out;
+	}
+	mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
+	mrioc->init_cmds.is_waiting = 1;
+	mrioc->init_cmds.callback = NULL;
+	create_req.HostTag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
+	create_req.Function = MPI3_FUNCTION_CREATE_REQUEST_QUEUE;
+	create_req.QueueID = cpu_to_le16(req_qid);
+	if (mrioc->enable_segqueue) {
+		create_req.Flags =
+		    MPI3_CREATE_REQUEST_QUEUE_FLAGS_SEGMENTED_SEGMENTED;
+		create_req.BaseAddress = cpu_to_le64(
+		    op_req_q->q_segment_list_dma);
+	} else
+		create_req.BaseAddress = cpu_to_le64(
+		    op_req_q->q_segments[0].segment_dma);
+	create_req.ReplyQueueID = cpu_to_le16(reply_qid);
+	create_req.Size = cpu_to_le16(op_req_q->num_requests);
+
+	init_completion(&mrioc->init_cmds.done);
+	retval = mpi3mr_admin_request_post(mrioc, &create_req,
+	    sizeof(create_req), 1);
+	if (retval) {
+		ioc_err(mrioc, "CreateReqQ: Admin Post failed\n");
+		goto out_unlock;
+	}
+	wait_for_completion_timeout(&mrioc->init_cmds.done,
+	    (MPI3MR_INTADMCMD_TIMEOUT * HZ));
+	if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
+		ioc_err(mrioc, "CreateReqQ: command timed out\n");
+		mpi3mr_set_diagsave(mrioc);
+		if (mpi3mr_issue_reset(mrioc,
+		    MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT,
+		    MPI3MR_RESET_FROM_CREATEREQQ_TIMEOUT))
+			mrioc->unrecoverable = 1;
+		retval = -1;
+		goto out_unlock;
+	}
+	if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
+	    != MPI3_IOCSTATUS_SUCCESS) {
+		ioc_err(mrioc,
+		    "CreateReqQ: Failed IOCStatus(0x%04x) Loginfo(0x%08x)\n",
+		    (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
+		    mrioc->init_cmds.ioc_loginfo);
+		retval = -1;
+		goto out_unlock;
+	}
+	op_req_q->qid = req_qid;
+
+out_unlock:
+	mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
+	mutex_unlock(&mrioc->init_cmds.mutex);
+out:
+
+	return retval;
+}
+
+/**
+ * mpi3mr_create_op_queues - create operational queue pairs
+ * @mrioc: Adapter instance reference
+ *
+ * Allocate memory for operational queue meta data and call
+ * create request and reply queue functions.
+ *
+ * Return: 0 on success, non-zero on failures.
+ */
+static int mpi3mr_create_op_queues(struct mpi3mr_ioc *mrioc)
+{
+	int retval = 0;
+	u16 num_queues = 0, i = 0, msix_count_op_q = 1;
+
+	num_queues = min_t(int, mrioc->facts.max_op_reply_q,
+	    mrioc->facts.max_op_req_q);
+
+	msix_count_op_q =
+	    mrioc->intr_info_count - mrioc->op_reply_q_offset;
+	if (!mrioc->num_queues)
+		mrioc->num_queues = min_t(int, num_queues, msix_count_op_q);
+	num_queues = mrioc->num_queues;
+	ioc_info(mrioc, "Trying to create %d Operational Q pairs\n",
+	    num_queues);
+
+	if (!mrioc->req_qinfo) {
+		mrioc->req_qinfo = kcalloc(num_queues,
+		    sizeof(struct op_req_qinfo), GFP_KERNEL);
+		if (!mrioc->req_qinfo) {
+			retval = -1;
+			goto out_failed;
+		}
+
+		mrioc->op_reply_qinfo = kzalloc(sizeof(struct op_reply_qinfo) *
+		    num_queues, GFP_KERNEL);
+		if (!mrioc->op_reply_qinfo) {
+			retval = -1;
+			goto out_failed;
+		}
+	}
+
+	if (mrioc->enable_segqueue)
+		ioc_info(mrioc,
+		    "allocating operational queues through segmented queues\n");
+
+	for (i = 0; i < num_queues; i++) {
+		if (mpi3mr_create_op_reply_q(mrioc, i)) {
+			ioc_err(mrioc, "Cannot create OP RepQ %d\n", i);
+			break;
+		}
+		if (mpi3mr_create_op_req_q(mrioc, i,
+		    mrioc->op_reply_qinfo[i].qid)) {
+			ioc_err(mrioc, "Cannot create OP ReqQ %d\n", i);
+			mpi3mr_delete_op_reply_q(mrioc, i);
+			break;
+		}
+	}
+
+	if (i == 0) {
+		/* Not even one queue is created successfully*/
+		retval = -1;
+		goto out_failed;
+	}
+	mrioc->num_op_reply_q = mrioc->num_op_req_q = i;
+	ioc_info(mrioc, "Successfully created %d Operational Q pairs\n",
+	    mrioc->num_op_reply_q);
+
+
+	return retval;
+out_failed:
+	kfree(mrioc->req_qinfo);
+	mrioc->req_qinfo = NULL;
+
+	kfree(mrioc->op_reply_qinfo);
+	mrioc->op_reply_qinfo = NULL;
+
+
+	return retval;
+}
+
 
 /**
  * mpi3mr_setup_admin_qpair - Setup admin queue pair
@@ -1599,6 +2187,13 @@ int mpi3mr_init_ioc(struct mpi3mr_ioc *mrioc)
 		goto out_failed;
 	}
 
+	retval = mpi3mr_create_op_queues(mrioc);
+	if (retval) {
+		ioc_err(mrioc, "Failed to create OpQueues error %d\n",
+		    retval);
+		goto out_failed;
+	}
+
 	return retval;
 
 out_failed:
@@ -1655,6 +2250,12 @@ static void mpi3mr_free_mem(struct mpi3mr_ioc *mrioc)
 		mrioc->reply_free_q_pool = NULL;
 	}
 
+	for (i = 0; i < mrioc->num_op_req_q; i++)
+		mpi3mr_free_op_req_q_segments(mrioc, i);
+
+	for (i = 0; i < mrioc->num_op_reply_q; i++)
+		mpi3mr_free_op_reply_q_segments(mrioc, i);
+
 	for (i = 0; i < mrioc->intr_info_count; i++) {
 		intr_info = mrioc->intr_info + i;
 		if (intr_info)
diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c
index c31ec9883152..3cf0be63842f 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_os.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_os.c
@@ -41,7 +41,7 @@ static int mpi3mr_map_queues(struct Scsi_Host *shost)
 	struct mpi3mr_ioc *mrioc = shost_priv(shost);
 
 	return blk_mq_pci_map_queues(&shost->tag_set.map[HCTX_TYPE_DEFAULT],
-	    mrioc->pdev, 0);
+	    mrioc->pdev, mrioc->op_reply_q_offset);
 }
 
 /**
@@ -220,6 +220,8 @@ mpi3mr_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	spin_lock_init(&mrioc->sbq_lock);
 
 	mpi3mr_init_drv_cmd(&mrioc->init_cmds, MPI3MR_HOSTTAG_INITCMDS);
+	if (pdev->revision)
+		mrioc->enable_segqueue = true;
 
 	mrioc->logging_level = logging_level;
 	mrioc->shost = shost;
-- 
2.18.1


-- 
This electronic communication and the information and any files transmitted 
with it, or attached to it, are confidential and are intended solely for 
the use of the individual or entity to whom it is addressed and may contain 
information that is confidential, legally privileged, protected by privacy 
laws, or otherwise restricted from disclosure to anyone else. If you are 
not the intended recipient or the person responsible for delivering the 
e-mail to the intended recipient, you are hereby notified that any use, 
copying, distributing, dissemination, forwarding, printing, or copying of 
this e-mail is strictly prohibited. If you received this e-mail in error, 
please return the e-mail to the sender, delete it from your computer, and 
destroy any printed copy of it.

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4169 bytes --]

^ permalink raw reply related	[flat|nested] 75+ messages in thread

* [PATCH 04/24] mpi3mr: add support of queue command processing
  2020-12-22 10:11 [PATCH 00/24] Introducing mpi3mr driver Kashyap Desai
                   ` (2 preceding siblings ...)
  2020-12-22 10:11 ` [PATCH 03/24] mpi3mr: create operational request and reply queue pair Kashyap Desai
@ 2020-12-22 10:11 ` Kashyap Desai
  2021-02-22 15:23   ` Tomas Henzl
  2021-02-28 13:22   ` Hannes Reinecke
  2020-12-22 10:11 ` [PATCH 05/24] mpi3mr: add support of internal watchdog thread Kashyap Desai
                   ` (20 subsequent siblings)
  24 siblings, 2 replies; 75+ messages in thread
From: Kashyap Desai @ 2020-12-22 10:11 UTC (permalink / raw)
  To: linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, Kashyap Desai, sathya.prakash

[-- Attachment #1: Type: text/plain, Size: 34864 bytes --]

Send Port Enable Request to FW for Device Discovery.
As part of port enable completion driver calls scan_start and
scan_finished hooks.
scsi layer reference like sdev, starget etc is added but actual
device discovery will be supported once driver add complete event
process handling (It is added in subsequent patches)

This patch provides interface which is used to interact with FW
via operational queue pairs.

Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Cc: sathya.prakash@broadcom.com
---
 drivers/scsi/mpi3mr/mpi3mr.h    |  52 +++
 drivers/scsi/mpi3mr/mpi3mr_fw.c | 251 +++++++++++++
 drivers/scsi/mpi3mr/mpi3mr_os.c | 645 +++++++++++++++++++++++++++++++-
 3 files changed, 946 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/mpi3mr/mpi3mr.h b/drivers/scsi/mpi3mr/mpi3mr.h
index fe6094bb357a..f23751e25d0f 100644
--- a/drivers/scsi/mpi3mr/mpi3mr.h
+++ b/drivers/scsi/mpi3mr/mpi3mr.h
@@ -96,6 +96,7 @@ extern struct list_head mrioc_list;
 
 /* command/controller interaction timeout definitions in seconds */
 #define MPI3MR_INTADMCMD_TIMEOUT		10
+#define MPI3MR_PORTENABLE_TIMEOUT		300
 #define MPI3MR_RESETTM_TIMEOUT			30
 #define MPI3MR_DEFAULT_SHUTDOWN_TIME		120
 
@@ -312,6 +313,43 @@ struct mpi3mr_intr_info {
 	char name[MPI3MR_NAME_LENGTH];
 };
 
+/**
+ * struct mpi3mr_stgt_priv_data - SCSI target private structure
+ *
+ * @starget: Scsi_target pointer
+ * @dev_handle: FW device handle
+ * @perst_id: FW assigned Persistent ID
+ * @num_luns: Number of Logical Units
+ * @block_io: I/O blocked to the device or not
+ * @dev_removed: Device removed in the Firmware
+ * @dev_removedelay: Device is waiting to be removed in FW
+ * @dev_type: Device type
+ * @tgt_dev: Internal target device pointer
+ */
+struct mpi3mr_stgt_priv_data {
+	struct scsi_target *starget;
+	u16 dev_handle;
+	u16 perst_id;
+	u32 num_luns;
+	atomic_t block_io;
+	u8 dev_removed;
+	u8 dev_removedelay;
+	u8 dev_type;
+	struct mpi3mr_tgt_dev *tgt_dev;
+};
+
+/**
+ * struct mpi3mr_stgt_priv_data - SCSI device private structure
+ *
+ * @tgt_priv_data: Scsi_target private data pointer
+ * @lun_id: LUN ID of the device
+ * @ncq_prio_enable: NCQ priority enable for SATA device
+ */
+struct mpi3mr_sdev_priv_data {
+	struct mpi3mr_stgt_priv_data *tgt_priv_data;
+	u32 lun_id;
+	u8 ncq_prio_enable;
+};
 
 typedef struct mpi3mr_drv_cmd DRV_CMD;
 typedef void (*DRV_CMD_CALLBACK)(struct mpi3mr_ioc *mrioc,
@@ -443,12 +481,16 @@ struct scmd_priv {
  * @sbq_lock: Sense buffer queue lock
  * @sbq_host_index: Sense buffer queuehost index
  * @is_driver_loading: Is driver still loading
+ * @scan_started: Async scan started
+ * @scan_failed: Asycn scan failed
+ * @stop_drv_processing: Stop all command processing
  * @max_host_ios: Maximum host I/O count
  * @chain_buf_count: Chain buffer count
  * @chain_buf_pool: Chain buffer pool
  * @chain_sgl_list: Chain SGL list
  * @chain_bitmap_sz: Chain buffer allocator bitmap size
  * @chain_bitmap: Chain buffer allocator bitmap
+ * @chain_buf_lock: Chain buffer list lock
  * @reset_in_progress: Reset in progress flag
  * @unrecoverable: Controller unrecoverable flag
  * @logging_level: Controller debug logging level
@@ -533,6 +575,9 @@ struct mpi3mr_ioc {
 	u32 sbq_host_index;
 
 	u8 is_driver_loading;
+	u8 scan_started;
+	u16 scan_failed;
+	u8 stop_drv_processing;
 
 	u16 max_host_ios;
 
@@ -541,6 +586,7 @@ struct mpi3mr_ioc {
 	struct chain_element *chain_sgl_list;
 	u16  chain_bitmap_sz;
 	void *chain_bitmap;
+	spinlock_t chain_buf_lock;
 
 	u8 reset_in_progress;
 	u8 unrecoverable;
@@ -557,8 +603,11 @@ int mpi3mr_setup_resources(struct mpi3mr_ioc *mrioc);
 void mpi3mr_cleanup_resources(struct mpi3mr_ioc *mrioc);
 int mpi3mr_init_ioc(struct mpi3mr_ioc *mrioc);
 void mpi3mr_cleanup_ioc(struct mpi3mr_ioc *mrioc);
+int mpi3mr_issue_port_enable(struct mpi3mr_ioc *mrioc, u8 async);
 int mpi3mr_admin_request_post(struct mpi3mr_ioc *mrioc, void *admin_req,
 u16 admin_req_sz, u8 ignore_reset);
+int mpi3mr_op_request_post(struct mpi3mr_ioc *mrioc,
+			   struct op_req_qinfo *opreqq, u8 *req);
 void mpi3mr_add_sg_single(void *paddr, u8 flags, u32 length,
 			  dma_addr_t dma_addr);
 void mpi3mr_build_zero_len_sge(void *paddr);
@@ -569,6 +618,9 @@ void *mpi3mr_get_reply_virt_addr(struct mpi3mr_ioc *mrioc,
 void mpi3mr_repost_sense_buf(struct mpi3mr_ioc *mrioc,
 				     u64 sense_buf_dma);
 
+void mpi3mr_process_op_reply_desc(struct mpi3mr_ioc *mrioc,
+				  Mpi3DefaultReplyDescriptor_t *reply_desc,
+				  u64 *reply_dma, u16 qidx);
 void mpi3mr_start_watchdog(struct mpi3mr_ioc *mrioc);
 void mpi3mr_stop_watchdog(struct mpi3mr_ioc *mrioc);
 
diff --git a/drivers/scsi/mpi3mr/mpi3mr_fw.c b/drivers/scsi/mpi3mr/mpi3mr_fw.c
index 6fb28983038e..abdf8c653e6b 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_fw.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_fw.c
@@ -24,6 +24,23 @@ static inline void mpi3mr_writeq(__u64 b, volatile void __iomem *addr)
 }
 #endif
 
+static inline bool
+mpi3mr_check_req_qfull(struct op_req_qinfo *op_req_q)
+{
+	u16 pi, ci, max_entries;
+	bool is_qfull = false;
+
+	pi = op_req_q->pi;
+	ci = op_req_q->ci;
+	max_entries = op_req_q->num_requests;
+
+	if ((ci == (pi + 1)) || ((!ci) && (pi == (max_entries - 1))))
+		is_qfull = true;
+
+	return is_qfull;
+}
+
+
 static void mpi3mr_sync_irqs(struct mpi3mr_ioc *mrioc)
 {
 	u16 i, max_vectors;
@@ -282,6 +299,87 @@ static int mpi3mr_process_admin_reply_q(struct mpi3mr_ioc *mrioc)
 	return num_admin_replies;
 }
 
+/**
+ * mpi3mr_get_reply_desc - get reply descriptor frame corresponding to
+ *	queue's consumer index from operational reply descriptor queue.
+ * @op_reply_q: op_reply_qinfo object
+ * @reply_ci: operational reply descriptor's queue consumer index
+ *
+ * Returns reply descriptor frame address
+ */
+static inline Mpi3DefaultReplyDescriptor_t *
+mpi3mr_get_reply_desc(struct op_reply_qinfo *op_reply_q, u32 reply_ci)
+{
+	void *segment_base_addr;
+	struct segments *segments = op_reply_q->q_segments;
+	Mpi3DefaultReplyDescriptor_t *reply_desc = NULL;
+
+	segment_base_addr =
+	    segments[reply_ci / op_reply_q->segment_qd].segment;
+	reply_desc = (Mpi3DefaultReplyDescriptor_t *)segment_base_addr +
+	    (reply_ci % op_reply_q->segment_qd);
+	return reply_desc;
+}
+
+
+static int mpi3mr_process_op_reply_q(struct mpi3mr_ioc *mrioc,
+	struct mpi3mr_intr_info *intr_info)
+{
+	struct op_reply_qinfo *op_reply_q = intr_info->op_reply_q;
+	struct op_req_qinfo *op_req_q;
+	u32 exp_phase;
+	u32 reply_ci;
+	u32 num_op_reply = 0;
+	u64 reply_dma = 0;
+	Mpi3DefaultReplyDescriptor_t *reply_desc;
+	u16 req_q_idx = 0, reply_qidx;
+
+	reply_qidx = op_reply_q->qid - 1;
+
+	exp_phase = op_reply_q->ephase;
+	reply_ci = op_reply_q->ci;
+
+	reply_desc = mpi3mr_get_reply_desc(op_reply_q, reply_ci);
+	if ((le16_to_cpu(reply_desc->ReplyFlags) &
+	    MPI3_REPLY_DESCRIPT_FLAGS_PHASE_MASK) != exp_phase) {
+		return 0;
+	}
+
+	do {
+		req_q_idx = le16_to_cpu(reply_desc->RequestQueueID) - 1;
+		op_req_q = &mrioc->req_qinfo[req_q_idx];
+
+		op_req_q->ci =
+		    le16_to_cpu(reply_desc->RequestQueueCI);
+
+		mpi3mr_process_op_reply_desc(mrioc, reply_desc, &reply_dma,
+		    reply_qidx);
+		if (reply_dma)
+			mpi3mr_repost_reply_buf(mrioc, reply_dma);
+		num_op_reply++;
+
+		if (++reply_ci == op_reply_q->num_replies) {
+			reply_ci = 0;
+			exp_phase ^= 1;
+		}
+
+		reply_desc = mpi3mr_get_reply_desc(op_reply_q, reply_ci);
+
+		if ((le16_to_cpu(reply_desc->ReplyFlags) &
+		    MPI3_REPLY_DESCRIPT_FLAGS_PHASE_MASK) != exp_phase)
+			break;
+
+	} while (1);
+
+
+	writel(reply_ci,
+	    &mrioc->sysif_regs->OperQueueIndexes[reply_qidx].ConsumerIndex);
+	op_reply_q->ci = reply_ci;
+	op_reply_q->ephase = exp_phase;
+
+	return num_op_reply;
+}
+
 static irqreturn_t mpi3mr_isr_primary(int irq, void *privdata)
 {
 	struct mpi3mr_intr_info *intr_info = privdata;
@@ -1314,6 +1412,74 @@ static int mpi3mr_create_op_queues(struct mpi3mr_ioc *mrioc)
 	return retval;
 }
 
+/**
+ * mpi3mr_op_request_post - Post request to operational queue
+ * @mrioc: Adapter reference
+ * @op_req_q: Operational request queue info
+ * @req: MPI3 request
+ *
+ * Post the MPI3 request into operational request queue and
+ * inform the controller, if the queue is full return
+ * appropriate error.
+ *
+ * Return: 0 on success, non-zero on failure.
+ */
+int mpi3mr_op_request_post(struct mpi3mr_ioc *mrioc,
+	struct op_req_qinfo *op_req_q, u8 *req)
+{
+	u16 pi = 0, max_entries, reply_qidx = 0, midx;
+	int retval = 0;
+	unsigned long flags;
+	u8 *req_entry;
+	void *segment_base_addr;
+	u16 req_sz = mrioc->facts.op_req_sz;
+	struct segments *segments = op_req_q->q_segments;
+
+	reply_qidx = op_req_q->reply_qid - 1;
+
+	if (mrioc->unrecoverable)
+		return -EFAULT;
+
+	spin_lock_irqsave(&op_req_q->q_lock, flags);
+	pi = op_req_q->pi;
+	max_entries = op_req_q->num_requests;
+
+	if (mpi3mr_check_req_qfull(op_req_q)) {
+		midx = REPLY_QUEUE_IDX_TO_MSIX_IDX(
+		    reply_qidx, mrioc->op_reply_q_offset);
+		mpi3mr_process_op_reply_q(mrioc, &mrioc->intr_info[midx]);
+
+		if (mpi3mr_check_req_qfull(op_req_q)) {
+			retval = -EAGAIN;
+			goto out;
+		}
+	}
+
+	if (mrioc->reset_in_progress) {
+		ioc_err(mrioc, "OpReqQ submit reset in progress\n");
+		retval = -EAGAIN;
+		goto out;
+	}
+
+	segment_base_addr = segments[pi / op_req_q->segment_qd].segment;
+	req_entry = (u8 *)segment_base_addr +
+	    ((pi % op_req_q->segment_qd) * req_sz);
+
+	memset(req_entry, 0, req_sz);
+	memcpy(req_entry, req, MPI3MR_ADMIN_REQ_FRAME_SZ);
+
+	if (++pi == max_entries)
+		pi = 0;
+	op_req_q->pi = pi;
+
+	writel(op_req_q->pi,
+	    &mrioc->sysif_regs->OperQueueIndexes[reply_qidx].ProducerIndex);
+
+out:
+	spin_unlock_irqrestore(&op_req_q->q_lock, flags);
+	return retval;
+}
+
 
 /**
  * mpi3mr_setup_admin_qpair - Setup admin queue pair
@@ -1901,6 +2067,91 @@ static int mpi3mr_alloc_chain_bufs(struct mpi3mr_ioc *mrioc)
 	return retval;
 }
 
+/**
+ * mpi3mr_port_enable_complete - Mark port enable complete
+ * @mrioc: Adapter instance reference
+ * @drv_cmd: Internal command tracker
+ *
+ * Call back for asynchronous port enable request sets the
+ * driver command to indicate port enable request is complete.
+ *
+ * Return: Nothing
+ */
+static void mpi3mr_port_enable_complete(struct mpi3mr_ioc *mrioc,
+	struct mpi3mr_drv_cmd *drv_cmd)
+{
+
+	drv_cmd->state = MPI3MR_CMD_NOTUSED;
+	drv_cmd->callback = NULL;
+	mrioc->scan_failed = drv_cmd->ioc_status;
+	mrioc->scan_started = 0;
+
+}
+
+/**
+ * mpi3mr_issue_port_enable - Issue Port Enable
+ * @mrioc: Adapter instance reference
+ * @async: Flag to wait for completion or not
+ *
+ * Issue Port Enable MPI request through admin queue and if the
+ * async flag is not set wait for the completion of the port
+ * enable or time out.
+ *
+ * Return: 0 on success, non-zero on failures.
+ */
+int mpi3mr_issue_port_enable(struct mpi3mr_ioc *mrioc, u8 async)
+{
+	Mpi3PortEnableRequest_t pe_req;
+	int retval = 0;
+	u32 pe_timeout = MPI3MR_PORTENABLE_TIMEOUT;
+
+	memset(&pe_req, 0, sizeof(pe_req));
+	mutex_lock(&mrioc->init_cmds.mutex);
+	if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
+		retval = -1;
+		ioc_err(mrioc, "Issue PortEnable: Init command is in use\n");
+		mutex_unlock(&mrioc->init_cmds.mutex);
+		goto out;
+	}
+	mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
+	if (async) {
+		mrioc->init_cmds.is_waiting = 0;
+		mrioc->init_cmds.callback = mpi3mr_port_enable_complete;
+	} else {
+		mrioc->init_cmds.is_waiting = 1;
+		mrioc->init_cmds.callback = NULL;
+		init_completion(&mrioc->init_cmds.done);
+	}
+	pe_req.HostTag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
+	pe_req.Function = MPI3_FUNCTION_PORT_ENABLE;
+
+	retval = mpi3mr_admin_request_post(mrioc, &pe_req, sizeof(pe_req), 1);
+	if (retval) {
+		ioc_err(mrioc, "Issue PortEnable: Admin Post failed\n");
+		goto out_unlock;
+	}
+	if (!async) {
+		wait_for_completion_timeout(&mrioc->init_cmds.done,
+		    (pe_timeout * HZ));
+		if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
+			ioc_err(mrioc, "Issue PortEnable: command timed out\n");
+			retval = -1;
+			mrioc->scan_failed = MPI3_IOCSTATUS_INTERNAL_ERROR;
+			mpi3mr_set_diagsave(mrioc);
+			mpi3mr_issue_reset(mrioc,
+			    MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT,
+			    MPI3MR_RESET_FROM_PE_TIMEOUT);
+			mrioc->unrecoverable = 1;
+			goto out_unlock;
+		}
+		mpi3mr_port_enable_complete(mrioc, &mrioc->init_cmds);
+	}
+out_unlock:
+	mutex_unlock(&mrioc->init_cmds.mutex);
+out:
+	return retval;
+}
+
 
 /**
  * mpi3mr_cleanup_resources - Free PCI resources
diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c
index 3cf0be63842f..01be5f337826 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_os.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_os.c
@@ -26,6 +26,471 @@ module_param(logging_level, int, 0);
 MODULE_PARM_DESC(logging_level,
 	" bits for enabling additional logging info (default=0)");
 
+/* Forward declarations*/
+/**
+ * mpi3mr_host_tag_for_scmd - Get host tag for a scmd
+ * @mrioc: Adapter instance reference
+ * @scmd: SCSI command reference
+ *
+ * Calculate the host tag based on block tag for a given scmd.
+ *
+ * Return: Valid host tag or MPI3MR_HOSTTAG_INVALID.
+ */
+static u16 mpi3mr_host_tag_for_scmd(struct mpi3mr_ioc *mrioc,
+	struct scsi_cmnd *scmd)
+{
+	struct scmd_priv *priv = NULL;
+	u32 unique_tag;
+	u16 host_tag, hw_queue;
+
+	unique_tag = blk_mq_unique_tag(scmd->request);
+
+	hw_queue = blk_mq_unique_tag_to_hwq(unique_tag);
+	if (hw_queue >= mrioc->num_op_reply_q)
+		return MPI3MR_HOSTTAG_INVALID;
+	host_tag = blk_mq_unique_tag_to_tag(unique_tag);
+
+	if (WARN_ON(host_tag >= mrioc->max_host_ios))
+		return MPI3MR_HOSTTAG_INVALID;
+
+	priv = scsi_cmd_priv(scmd);
+	/*host_tag 0 is invalid hence incrementing by 1*/
+	priv->host_tag = host_tag + 1;
+	priv->scmd = scmd;
+	priv->in_lld_scope = 1;
+	priv->req_q_idx = hw_queue;
+	priv->chain_idx = -1;
+	return priv->host_tag;
+}
+
+/**
+ * mpi3mr_scmd_from_host_tag - Get SCSI command from host tag
+ * @mrioc: Adapter instance reference
+ * @host_tag: Host tag
+ * @qidx: Operational queue index
+ *
+ * Identify the block tag from the host tag and queue index and
+ * retrieve associated scsi command using scsi_host_find_tag().
+ *
+ * Return: SCSI command reference or NULL.
+ */
+static struct scsi_cmnd *mpi3mr_scmd_from_host_tag(
+	struct mpi3mr_ioc *mrioc, u16 host_tag, u16 qidx)
+{
+	struct scsi_cmnd *scmd = NULL;
+	struct scmd_priv *priv = NULL;
+	u32 unique_tag = host_tag - 1;
+
+	if (WARN_ON(host_tag > mrioc->max_host_ios))
+		goto out;
+
+	unique_tag |= (qidx << BLK_MQ_UNIQUE_TAG_BITS);
+
+	scmd = scsi_host_find_tag(mrioc->shost, unique_tag);
+	if (scmd) {
+		priv = scsi_cmd_priv(scmd);
+		if (!priv->in_lld_scope)
+			scmd = NULL;
+	}
+out:
+	return scmd;
+}
+
+/**
+ * mpi3mr_clear_scmd_priv - Cleanup SCSI command private date
+ * @mrioc: Adapter instance reference
+ * @scmd: SCSI command reference
+ *
+ * Invalidate the SCSI command private data to mark the command
+ * is not in LLD scope anymore.
+ *
+ * Return: Nothing.
+ */
+static void mpi3mr_clear_scmd_priv(struct mpi3mr_ioc *mrioc,
+	struct scsi_cmnd *scmd)
+{
+	struct scmd_priv *priv = NULL;
+
+	priv = scsi_cmd_priv(scmd);
+
+	if (WARN_ON(priv->in_lld_scope == 0))
+		return;
+	priv->host_tag = MPI3MR_HOSTTAG_INVALID;
+	priv->req_q_idx = 0xFFFF;
+	priv->scmd = NULL;
+	priv->in_lld_scope = 0;
+	if (priv->chain_idx >= 0) {
+		clear_bit(priv->chain_idx, mrioc->chain_bitmap);
+		priv->chain_idx = -1;
+	}
+}
+
+/**
+ * mpi3mr_process_op_reply_desc - reply descriptor handler
+ * @mrioc: Adapter instance reference
+ * @reply_desc: Operational reply descriptor
+ * @reply_dma: place holder for reply DMA address
+ * @qidx: Operational queue index
+ *
+ * Process the operational reply descriptor and identifies the
+ * descriptor type. Based on the descriptor map the MPI3 request
+ * status to a SCSI command status and calls scsi_done call
+ * back.
+ *
+ * Return: Nothing
+ */
+void mpi3mr_process_op_reply_desc(struct mpi3mr_ioc *mrioc,
+	Mpi3DefaultReplyDescriptor_t *reply_desc, u64 *reply_dma, u16 qidx)
+{
+	u16 reply_desc_type, host_tag = 0;
+	u16 ioc_status = MPI3_IOCSTATUS_SUCCESS;
+	u32 ioc_loginfo = 0;
+	Mpi3StatusReplyDescriptor_t *status_desc = NULL;
+	Mpi3AddressReplyDescriptor_t *addr_desc = NULL;
+	Mpi3SuccessReplyDescriptor_t *success_desc = NULL;
+	Mpi3SCSIIOReply_t *scsi_reply = NULL;
+	struct scsi_cmnd *scmd = NULL;
+	struct scmd_priv *priv = NULL;
+	u8 *sense_buf = NULL;
+	u8 scsi_state = 0, scsi_status = 0, sense_state = 0;
+	u32 xfer_count = 0, sense_count = 0, resp_data = 0;
+	u16 dev_handle = 0xFFFF;
+	struct scsi_sense_hdr sshdr;
+
+	*reply_dma = 0;
+	reply_desc_type = le16_to_cpu(reply_desc->ReplyFlags) &
+	    MPI3_REPLY_DESCRIPT_FLAGS_TYPE_MASK;
+	switch (reply_desc_type) {
+	case MPI3_REPLY_DESCRIPT_FLAGS_TYPE_STATUS:
+		status_desc = (Mpi3StatusReplyDescriptor_t *)reply_desc;
+		host_tag = le16_to_cpu(status_desc->HostTag);
+		ioc_status = le16_to_cpu(status_desc->IOCStatus);
+		if (ioc_status &
+		    MPI3_REPLY_DESCRIPT_STATUS_IOCSTATUS_LOGINFOAVAIL)
+			ioc_loginfo = le32_to_cpu(status_desc->IOCLogInfo);
+		ioc_status &= MPI3_REPLY_DESCRIPT_STATUS_IOCSTATUS_STATUS_MASK;
+		break;
+	case MPI3_REPLY_DESCRIPT_FLAGS_TYPE_ADDRESS_REPLY:
+		addr_desc = (Mpi3AddressReplyDescriptor_t *)reply_desc;
+		*reply_dma = le64_to_cpu(addr_desc->ReplyFrameAddress);
+		scsi_reply = mpi3mr_get_reply_virt_addr(mrioc,
+		    *reply_dma);
+		if (!scsi_reply) {
+			panic("%s: scsi_reply is NULL, this shouldn't happen\n",
+			    mrioc->name);
+			goto out;
+		}
+		host_tag = le16_to_cpu(scsi_reply->HostTag);
+		ioc_status = le16_to_cpu(scsi_reply->IOCStatus);
+		scsi_status = scsi_reply->SCSIStatus;
+		scsi_state = scsi_reply->SCSIState;
+		dev_handle = le16_to_cpu(scsi_reply->DevHandle);
+		sense_state = (scsi_state & MPI3_SCSI_STATE_SENSE_MASK);
+		xfer_count = le32_to_cpu(scsi_reply->TransferCount);
+		sense_count = le32_to_cpu(scsi_reply->SenseCount);
+		resp_data = le32_to_cpu(scsi_reply->ResponseData);
+		sense_buf = mpi3mr_get_sensebuf_virt_addr(mrioc,
+		    le64_to_cpu(scsi_reply->SenseDataBufferAddress));
+		if (ioc_status &
+		    MPI3_REPLY_DESCRIPT_STATUS_IOCSTATUS_LOGINFOAVAIL)
+			ioc_loginfo = le32_to_cpu(scsi_reply->IOCLogInfo);
+		ioc_status &= MPI3_REPLY_DESCRIPT_STATUS_IOCSTATUS_STATUS_MASK;
+		if (sense_state == MPI3_SCSI_STATE_SENSE_BUFF_Q_EMPTY)
+			panic("%s: Ran out of sense buffers\n", mrioc->name);
+		break;
+	case MPI3_REPLY_DESCRIPT_FLAGS_TYPE_SUCCESS:
+		success_desc = (Mpi3SuccessReplyDescriptor_t *)reply_desc;
+		host_tag = le16_to_cpu(success_desc->HostTag);
+		break;
+	default:
+		break;
+	}
+	scmd = mpi3mr_scmd_from_host_tag(mrioc, host_tag, qidx);
+	if (!scmd) {
+		panic("%s: Cannot Identify scmd for host_tag 0x%x\n",
+		    mrioc->name, host_tag);
+		goto out;
+	}
+	priv = scsi_cmd_priv(scmd);
+	if (success_desc) {
+		scmd->result = DID_OK << 16;
+		goto out_success;
+	}
+	if (ioc_status == MPI3_IOCSTATUS_SCSI_DATA_UNDERRUN &&
+	    xfer_count == 0 && (scsi_status == MPI3_SCSI_STATUS_BUSY ||
+	    scsi_status == MPI3_SCSI_STATUS_RESERVATION_CONFLICT ||
+	    scsi_status == MPI3_SCSI_STATUS_TASK_SET_FULL))
+		ioc_status = MPI3_IOCSTATUS_SUCCESS;
+
+	if ((sense_state == MPI3_SCSI_STATE_SENSE_VALID) && sense_count
+	    && sense_buf) {
+		u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE, sense_count);
+
+		memcpy(scmd->sense_buffer, sense_buf, sz);
+	}
+
+	switch (ioc_status) {
+	case MPI3_IOCSTATUS_BUSY:
+	case MPI3_IOCSTATUS_INSUFFICIENT_RESOURCES:
+		scmd->result = SAM_STAT_BUSY;
+		break;
+	case MPI3_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
+		scmd->result = DID_NO_CONNECT << 16;
+		break;
+	case MPI3_IOCSTATUS_SCSI_IOC_TERMINATED:
+		scmd->result = DID_SOFT_ERROR << 16;
+		break;
+	case MPI3_IOCSTATUS_SCSI_TASK_TERMINATED:
+	case MPI3_IOCSTATUS_SCSI_EXT_TERMINATED:
+		scmd->result = DID_RESET << 16;
+		break;
+	case MPI3_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
+		if ((xfer_count == 0) || (scmd->underflow > xfer_count))
+			scmd->result = DID_SOFT_ERROR << 16;
+		else
+			scmd->result = (DID_OK << 16) | scsi_status;
+		break;
+	case MPI3_IOCSTATUS_SCSI_DATA_UNDERRUN:
+		scmd->result = (DID_OK << 16) | scsi_status;
+		if (sense_state == MPI3_SCSI_STATE_SENSE_VALID)
+			break;
+		if (xfer_count < scmd->underflow) {
+			if (scsi_status == SAM_STAT_BUSY)
+				scmd->result = SAM_STAT_BUSY;
+			else
+				scmd->result = DID_SOFT_ERROR << 16;
+		} else if ((scsi_state & (MPI3_SCSI_STATE_NO_SCSI_STATUS))
+		    || (sense_state != MPI3_SCSI_STATE_SENSE_NOT_AVAILABLE))
+			scmd->result = DID_SOFT_ERROR << 16;
+		else if (scsi_state & MPI3_SCSI_STATE_TERMINATED)
+			scmd->result = DID_RESET << 16;
+		else if (!xfer_count && scmd->cmnd[0] == REPORT_LUNS) {
+			scsi_status = SAM_STAT_CHECK_CONDITION;
+			scmd->result = (DRIVER_SENSE << 24) |
+			    SAM_STAT_CHECK_CONDITION;
+			scmd->sense_buffer[0] = 0x70;
+			scmd->sense_buffer[2] = ILLEGAL_REQUEST;
+			scmd->sense_buffer[12] = 0x20;
+			scmd->sense_buffer[13] = 0;
+		}
+		break;
+	case MPI3_IOCSTATUS_SCSI_DATA_OVERRUN:
+		scsi_set_resid(scmd, 0);
+		fallthrough;
+	case MPI3_IOCSTATUS_SCSI_RECOVERED_ERROR:
+	case MPI3_IOCSTATUS_SUCCESS:
+		scmd->result = (DID_OK << 16) | scsi_status;
+		if ((scsi_state & (MPI3_SCSI_STATE_NO_SCSI_STATUS))
+			|| (sense_state == MPI3_SCSI_STATE_SENSE_FAILED)
+			|| (sense_state == MPI3_SCSI_STATE_SENSE_BUFF_Q_EMPTY))
+			scmd->result = DID_SOFT_ERROR << 16;
+		else if (scsi_state & MPI3_SCSI_STATE_TERMINATED)
+			scmd->result = DID_RESET << 16;
+		break;
+	case MPI3_IOCSTATUS_SCSI_PROTOCOL_ERROR:
+	case MPI3_IOCSTATUS_INVALID_FUNCTION:
+	case MPI3_IOCSTATUS_INVALID_SGL:
+	case MPI3_IOCSTATUS_INTERNAL_ERROR:
+	case MPI3_IOCSTATUS_INVALID_FIELD:
+	case MPI3_IOCSTATUS_INVALID_STATE:
+	case MPI3_IOCSTATUS_SCSI_IO_DATA_ERROR:
+	case MPI3_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
+	case MPI3_IOCSTATUS_INSUFFICIENT_POWER:
+	default:
+		scmd->result = DID_SOFT_ERROR << 16;
+		break;
+	}
+
+	if (scmd->result != (DID_OK << 16) && (scmd->cmnd[0] != ATA_12) &&
+	    (scmd->cmnd[0] != ATA_16)) {
+		ioc_info(mrioc, "%s :scmd->result 0x%x\n", __func__,
+		    scmd->result);
+		scsi_print_command(scmd);
+		ioc_info(mrioc,
+		    "%s :Command issued to handle 0x%02x returned with error 0x%04x loginfo 0x%08x, qid %d\n",
+		    __func__, dev_handle, ioc_status, ioc_loginfo,
+		    priv->req_q_idx+1);
+		ioc_info(mrioc,
+		    " host_tag %d scsi_state 0x%02x scsi_status 0x%02x, xfer_cnt %d resp_data 0x%x\n",
+		    host_tag, scsi_state, scsi_status, xfer_count, resp_data);
+		if (sense_buf) {
+			scsi_normalize_sense(sense_buf, sense_count, &sshdr);
+			ioc_info(mrioc,
+			    "%s :sense_count 0x%x, sense_key 0x%x ASC 0x%x, ASCQ 0x%x\n",
+			    __func__, sense_count, sshdr.sense_key,
+			    sshdr.asc, sshdr.ascq);
+		}
+	}
+out_success:
+	mpi3mr_clear_scmd_priv(mrioc, scmd);
+	scsi_dma_unmap(scmd);
+	scmd->scsi_done(scmd);
+out:
+	if (sense_buf)
+		mpi3mr_repost_sense_buf(mrioc,
+		    le64_to_cpu(scsi_reply->SenseDataBufferAddress));
+}
+
+/**
+ * mpi3mr_get_chain_idx - get free chain buffer index
+ * @mrioc: Adapter instance reference
+ *
+ * Try to get a free chain buffer index from the free pool.
+ *
+ * Return: -1 on failure or the free chain buffer index
+ */
+static int mpi3mr_get_chain_idx(struct mpi3mr_ioc *mrioc)
+{
+	u8 retry_count = 5;
+	int cmd_idx = -1;
+
+	do {
+		spin_lock(&mrioc->chain_buf_lock);
+		cmd_idx = find_first_zero_bit(mrioc->chain_bitmap,
+		    mrioc->chain_buf_count);
+		if (cmd_idx < mrioc->chain_buf_count) {
+			set_bit(cmd_idx, mrioc->chain_bitmap);
+			spin_unlock(&mrioc->chain_buf_lock);
+			break;
+		}
+		spin_unlock(&mrioc->chain_buf_lock);
+		cmd_idx = -1;
+	} while (retry_count--);
+	return cmd_idx;
+}
+
+/**
+ * mpi3mr_prepare_sg_scmd - build scatter gather list
+ * @mrioc: Adapter instance reference
+ * @scmd: SCSI command reference
+ * @scsiio_req: MPI3 SCSI IO request
+ *
+ * This function maps SCSI command's data and protection SGEs to
+ * MPI request SGEs. If required additional 4K chain buffer is
+ * used to send the SGEs.
+ *
+ * Return: 0 on success, -ENOMEM on dma_map_sg failure
+ */
+static int mpi3mr_prepare_sg_scmd(struct mpi3mr_ioc *mrioc,
+	struct scsi_cmnd *scmd, Mpi3SCSIIORequest_t *scsiio_req)
+{
+	dma_addr_t chain_dma;
+	struct scatterlist *sg_scmd;
+	void *sg_local, *chain;
+	u32 chain_length;
+	int sges_left, chain_idx;
+	u32 sges_in_segment;
+	u8 simple_sgl_flags;
+	u8 simple_sgl_flags_last;
+	u8 last_chain_sgl_flags;
+	struct chain_element *chain_req;
+	struct scmd_priv *priv = NULL;
+
+	priv = scsi_cmd_priv(scmd);
+
+	simple_sgl_flags = MPI3_SGE_FLAGS_ELEMENT_TYPE_SIMPLE |
+	    MPI3_SGE_FLAGS_DLAS_SYSTEM;
+	simple_sgl_flags_last = simple_sgl_flags |
+	    MPI3_SGE_FLAGS_END_OF_LIST;
+	last_chain_sgl_flags = MPI3_SGE_FLAGS_ELEMENT_TYPE_LAST_CHAIN |
+	    MPI3_SGE_FLAGS_DLAS_SYSTEM;
+
+	sg_local = &scsiio_req->SGL;
+
+	if (!scsiio_req->DataLength) {
+		mpi3mr_build_zero_len_sge(sg_local);
+		return 0;
+	}
+
+	sg_scmd = scsi_sglist(scmd);
+	sges_left = scsi_dma_map(scmd);
+
+	if (sges_left < 0) {
+		sdev_printk(KERN_ERR, scmd->device,
+		    "scsi_dma_map failed: request for %d bytes!\n",
+		    scsi_bufflen(scmd));
+		return -ENOMEM;
+	}
+	if (sges_left > MPI3MR_SG_DEPTH) {
+		sdev_printk(KERN_ERR, scmd->device,
+		    "scsi_dma_map returned unsupported sge count %d!\n",
+		    sges_left);
+		return -ENOMEM;
+	}
+
+	sges_in_segment = (mrioc->facts.op_req_sz -
+	    offsetof(Mpi3SCSIIORequest_t, SGL))/sizeof(Mpi3SGESimple_t);
+
+	if (sges_left <= sges_in_segment)
+		goto fill_in_last_segment;
+
+	/* fill in main message segment when there is a chain following */
+	while (sges_in_segment > 1) {
+		mpi3mr_add_sg_single(sg_local, simple_sgl_flags,
+		    sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
+		sg_scmd = sg_next(sg_scmd);
+		sg_local += sizeof(Mpi3SGESimple_t);
+		sges_left--;
+		sges_in_segment--;
+	}
+
+	chain_idx = mpi3mr_get_chain_idx(mrioc);
+	if (chain_idx < 0)
+		return -1;
+	chain_req = &mrioc->chain_sgl_list[chain_idx];
+	priv->chain_idx = chain_idx;
+
+	chain = chain_req->addr;
+	chain_dma = chain_req->dma_addr;
+	sges_in_segment = sges_left;
+	chain_length = sges_in_segment * sizeof(Mpi3SGESimple_t);
+
+	mpi3mr_add_sg_single(sg_local, last_chain_sgl_flags,
+	    chain_length, chain_dma);
+
+	sg_local = chain;
+
+fill_in_last_segment:
+	while (sges_left > 0) {
+		if (sges_left == 1)
+			mpi3mr_add_sg_single(sg_local,
+			    simple_sgl_flags_last, sg_dma_len(sg_scmd),
+			    sg_dma_address(sg_scmd));
+		else
+			mpi3mr_add_sg_single(sg_local, simple_sgl_flags,
+			    sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
+		sg_scmd = sg_next(sg_scmd);
+		sg_local += sizeof(Mpi3SGESimple_t);
+		sges_left--;
+	}
+
+	return 0;
+}
+
+/**
+ * mpi3mr_build_sg_scmd - build scatter gather list for SCSI IO
+ * @mrioc: Adapter instance reference
+ * @scmd: SCSI command reference
+ * @scsiio_req: MPI3 SCSI IO request
+ *
+ * This function calls mpi3mr_prepare_sg_scmd for constructing
+ * both data SGEs and protection information SGEs in the MPI
+ * format from the SCSI Command as appropriate .
+ *
+ * Return: return value of mpi3mr_prepare_sg_scmd.
+ */
+static int mpi3mr_build_sg_scmd(struct mpi3mr_ioc *mrioc,
+	struct scsi_cmnd *scmd, Mpi3SCSIIORequest_t *scsiio_req)
+{
+	int ret;
+
+	ret = mpi3mr_prepare_sg_scmd(mrioc, scmd, scsiio_req);
+	if (ret)
+		return ret;
+
+	return ret;
+}
+
 
 /**
  * mpi3mr_map_queues - Map queues callback handler
@@ -44,6 +509,73 @@ static int mpi3mr_map_queues(struct Scsi_Host *shost)
 	    mrioc->pdev, mrioc->op_reply_q_offset);
 }
 
+/**
+ * mpi3mr_scan_start - Scan start callback handler
+ * @shost: SCSI host reference
+ *
+ * Issue port enable request asynchronously.
+ *
+ * Return: Nothing
+ */
+static void mpi3mr_scan_start(struct Scsi_Host *shost)
+{
+	struct mpi3mr_ioc *mrioc = shost_priv(shost);
+
+	mrioc->scan_started = 1;
+	ioc_info(mrioc, "%s :Issuing Port Enable\n", __func__);
+	if (mpi3mr_issue_port_enable(mrioc, 1)) {
+		ioc_err(mrioc, "%s :Issuing port enable failed\n", __func__);
+		mrioc->scan_started = 0;
+		mrioc->scan_failed = MPI3_IOCSTATUS_INTERNAL_ERROR;
+	}
+
+}
+
+/**
+ * mpi3mr_scan_finished - Scan finished callback handler
+ * @shost: SCSI host reference
+ * @time: Jiffies from the scan start
+ *
+ * Checks whether the port enable is completed or timedout or
+ * failed and set the scan status accordingly after taking any
+ * recovery if required.
+ *
+ * Return: 1 on scan finished or timed out, 0 for in progress
+ */
+static int mpi3mr_scan_finished(struct Scsi_Host *shost,
+	unsigned long time)
+{
+	struct mpi3mr_ioc *mrioc = shost_priv(shost);
+	u32 pe_timeout = MPI3MR_PORTENABLE_TIMEOUT;
+
+	if (time >= (pe_timeout * HZ)) {
+		mrioc->init_cmds.is_waiting = 0;
+		mrioc->init_cmds.callback = NULL;
+		mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
+		ioc_err(mrioc, "%s :port enable request timed out\n", __func__);
+		mrioc->is_driver_loading = 0;
+		mpi3mr_soft_reset_handler(mrioc,
+		    MPI3MR_RESET_FROM_PE_TIMEOUT, 1);
+	}
+
+	if (mrioc->scan_failed) {
+		ioc_err(mrioc,
+		    "%s :port enable failed with (ioc_status=0x%08x)\n",
+		    __func__, mrioc->scan_failed);
+		mrioc->is_driver_loading = 0;
+		mrioc->stop_drv_processing = 1;
+		return 1;
+	}
+
+	if (mrioc->scan_started)
+		return 0;
+	ioc_info(mrioc, "%s :port enable: SUCCESS\n", __func__);
+	mrioc->is_driver_loading = 0;
+
+	return 1;
+}
+
+
 /**
  * mpi3mr_slave_destroy - Slave destroy callback handler
  * @sdev: SCSI device reference
@@ -126,10 +658,114 @@ static int mpi3mr_target_alloc(struct scsi_target *starget)
 static int mpi3mr_qcmd(struct Scsi_Host *shost,
 	struct scsi_cmnd *scmd)
 {
+	struct mpi3mr_ioc *mrioc = shost_priv(shost);
+	struct mpi3mr_stgt_priv_data *stgt_priv_data;
+	struct mpi3mr_sdev_priv_data *sdev_priv_data;
+	struct scmd_priv *scmd_priv_data = NULL;
+	Mpi3SCSIIORequest_t *scsiio_req = NULL;
+	struct op_req_qinfo *op_req_q = NULL;
 	int retval = 0;
+	u16 dev_handle;
+	u16 host_tag;
+	u32 scsiio_flags = 0;
+	struct request *rq = scmd->request;
+	int iprio_class;
+
+	sdev_priv_data = scmd->device->hostdata;
+	if (!sdev_priv_data || !sdev_priv_data->tgt_priv_data) {
+		scmd->result = DID_NO_CONNECT << 16;
+		scmd->scsi_done(scmd);
+		goto out;
+	}
 
-	scmd->result = DID_NO_CONNECT << 16;
-	scmd->scsi_done(scmd);
+	if (mrioc->stop_drv_processing) {
+		scmd->result = DID_NO_CONNECT << 16;
+		scmd->scsi_done(scmd);
+		goto out;
+	}
+
+	if (mrioc->reset_in_progress) {
+		retval = SCSI_MLQUEUE_HOST_BUSY;
+		goto out;
+	}
+
+	stgt_priv_data = sdev_priv_data->tgt_priv_data;
+
+	dev_handle = stgt_priv_data->dev_handle;
+	if (dev_handle == MPI3MR_INVALID_DEV_HANDLE) {
+		scmd->result = DID_NO_CONNECT << 16;
+		scmd->scsi_done(scmd);
+		goto out;
+	}
+	if (stgt_priv_data->dev_removed) {
+		scmd->result = DID_NO_CONNECT << 16;
+		scmd->scsi_done(scmd);
+		goto out;
+	}
+
+	if (atomic_read(&stgt_priv_data->block_io)) {
+		if (mrioc->stop_drv_processing) {
+			scmd->result = DID_NO_CONNECT << 16;
+			scmd->scsi_done(scmd);
+			goto out;
+		}
+		retval = SCSI_MLQUEUE_DEVICE_BUSY;
+		goto out;
+	}
+
+	host_tag = mpi3mr_host_tag_for_scmd(mrioc, scmd);
+	if (host_tag == MPI3MR_HOSTTAG_INVALID) {
+		scmd->result = DID_ERROR << 16;
+		scmd->scsi_done(scmd);
+		goto out;
+	}
+
+	if (scmd->sc_data_direction == DMA_FROM_DEVICE)
+		scsiio_flags = MPI3_SCSIIO_FLAGS_DATADIRECTION_READ;
+	else if (scmd->sc_data_direction == DMA_TO_DEVICE)
+		scsiio_flags = MPI3_SCSIIO_FLAGS_DATADIRECTION_WRITE;
+	else
+		scsiio_flags = MPI3_SCSIIO_FLAGS_DATADIRECTION_NO_DATA_TRANSFER;
+
+	scsiio_flags |= MPI3_SCSIIO_FLAGS_TASKATTRIBUTE_SIMPLEQ;
+
+	if (sdev_priv_data->ncq_prio_enable) {
+		iprio_class = IOPRIO_PRIO_CLASS(req_get_ioprio(rq));
+		if (iprio_class == IOPRIO_CLASS_RT)
+			scsiio_flags |= 1 << MPI3_SCSIIO_FLAGS_CMDPRI_SHIFT;
+	}
+
+	if (scmd->cmd_len > 16)
+		scsiio_flags |= MPI3_SCSIIO_FLAGS_CDB_GREATER_THAN_16;
+
+	scmd_priv_data = scsi_cmd_priv(scmd);
+	memset(scmd_priv_data->mpi3mr_scsiio_req, 0, MPI3MR_ADMIN_REQ_FRAME_SZ);
+	scsiio_req = (Mpi3SCSIIORequest_t *) scmd_priv_data->mpi3mr_scsiio_req;
+	scsiio_req->Function = MPI3_FUNCTION_SCSI_IO;
+	scsiio_req->HostTag = cpu_to_le16(host_tag);
+
+	memcpy(scsiio_req->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
+	scsiio_req->DataLength = cpu_to_le32(scsi_bufflen(scmd));
+	scsiio_req->DevHandle = cpu_to_le16(dev_handle);
+	scsiio_req->Flags = cpu_to_le32(scsiio_flags);
+	int_to_scsilun(sdev_priv_data->lun_id,
+	    (struct scsi_lun *)scsiio_req->LUN);
+
+	if (mpi3mr_build_sg_scmd(mrioc, scmd, scsiio_req)) {
+		mpi3mr_clear_scmd_priv(mrioc, scmd);
+		retval = SCSI_MLQUEUE_HOST_BUSY;
+		goto out;
+	}
+	op_req_q = &mrioc->req_qinfo[scmd_priv_data->req_q_idx];
+
+	if (mpi3mr_op_request_post(mrioc, op_req_q,
+	    scmd_priv_data->mpi3mr_scsiio_req)) {
+		mpi3mr_clear_scmd_priv(mrioc, scmd);
+		retval = SCSI_MLQUEUE_HOST_BUSY;
+		goto out;
+	}
+
+out:
 	return retval;
 }
 
@@ -143,6 +779,8 @@ static struct scsi_host_template mpi3mr_driver_template = {
 	.slave_configure		= mpi3mr_slave_configure,
 	.target_destroy			= mpi3mr_target_destroy,
 	.slave_destroy			= mpi3mr_slave_destroy,
+	.scan_finished			= mpi3mr_scan_finished,
+	.scan_start			= mpi3mr_scan_start,
 	.map_queues			= mpi3mr_map_queues,
 	.no_write_same			= 1,
 	.can_queue			= 1,
@@ -218,6 +856,7 @@ mpi3mr_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	spin_lock_init(&mrioc->admin_req_lock);
 	spin_lock_init(&mrioc->reply_free_queue_lock);
 	spin_lock_init(&mrioc->sbq_lock);
+	spin_lock_init(&mrioc->chain_buf_lock);
 
 	mpi3mr_init_drv_cmd(&mrioc->init_cmds, MPI3MR_HOSTTAG_INITCMDS);
 	if (pdev->revision)
@@ -287,6 +926,7 @@ static void mpi3mr_remove(struct pci_dev *pdev)
 	while (mrioc->reset_in_progress || mrioc->is_driver_loading)
 		ssleep(1);
 
+	mrioc->stop_drv_processing = 1;
 
 	scsi_remove_host(shost);
 
@@ -319,6 +959,7 @@ static void mpi3mr_shutdown(struct pci_dev *pdev)
 	mrioc = shost_priv(shost);
 	while (mrioc->reset_in_progress || mrioc->is_driver_loading)
 		ssleep(1);
+	mrioc->stop_drv_processing = 1;
 
 	mpi3mr_cleanup_ioc(mrioc);
 
-- 
2.18.1


-- 
This electronic communication and the information and any files transmitted 
with it, or attached to it, are confidential and are intended solely for 
the use of the individual or entity to whom it is addressed and may contain 
information that is confidential, legally privileged, protected by privacy 
laws, or otherwise restricted from disclosure to anyone else. If you are 
not the intended recipient or the person responsible for delivering the 
e-mail to the intended recipient, you are hereby notified that any use, 
copying, distributing, dissemination, forwarding, printing, or copying of 
this e-mail is strictly prohibited. If you received this e-mail in error, 
please return the e-mail to the sender, delete it from your computer, and 
destroy any printed copy of it.

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4169 bytes --]

^ permalink raw reply related	[flat|nested] 75+ messages in thread

* [PATCH 05/24] mpi3mr: add support of internal watchdog thread
  2020-12-22 10:11 [PATCH 00/24] Introducing mpi3mr driver Kashyap Desai
                   ` (3 preceding siblings ...)
  2020-12-22 10:11 ` [PATCH 04/24] mpi3mr: add support of queue command processing Kashyap Desai
@ 2020-12-22 10:11 ` Kashyap Desai
  2021-02-28 13:24   ` Hannes Reinecke
  2020-12-22 10:11 ` [PATCH 06/24] mpi3mr: add support of event handling part-1 Kashyap Desai
                   ` (19 subsequent siblings)
  24 siblings, 1 reply; 75+ messages in thread
From: Kashyap Desai @ 2020-12-22 10:11 UTC (permalink / raw)
  To: linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, Kashyap Desai, sathya.prakash

[-- Attachment #1: Type: text/plain, Size: 7799 bytes --]

Watchdog thread is driver's internal thread which does few things like
detecting FW fault and reset the controller, Timestamp sync etc.

Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Cc: sathya.prakash@broadcom.com
---
 drivers/scsi/mpi3mr/mpi3mr.h    |  11 +++
 drivers/scsi/mpi3mr/mpi3mr_fw.c | 125 ++++++++++++++++++++++++++++++++
 drivers/scsi/mpi3mr/mpi3mr_os.c |   3 +
 3 files changed, 139 insertions(+)

diff --git a/drivers/scsi/mpi3mr/mpi3mr.h b/drivers/scsi/mpi3mr/mpi3mr.h
index f23751e25d0f..0fa38036dcf3 100644
--- a/drivers/scsi/mpi3mr/mpi3mr.h
+++ b/drivers/scsi/mpi3mr/mpi3mr.h
@@ -480,6 +480,10 @@ struct scmd_priv {
  * @sense_buf_q_dma: Sense buffer queue DMA address
  * @sbq_lock: Sense buffer queue lock
  * @sbq_host_index: Sense buffer queuehost index
+ * @watchdog_work_q_name: Fault watchdog worker thread name
+ * @watchdog_work_q: Fault watchdog worker thread
+ * @watchdog_work: Fault watchdog work
+ * @watchdog_lock: Fault watchdog lock
  * @is_driver_loading: Is driver still loading
  * @scan_started: Async scan started
  * @scan_failed: Asycn scan failed
@@ -493,6 +497,7 @@ struct scmd_priv {
  * @chain_buf_lock: Chain buffer list lock
  * @reset_in_progress: Reset in progress flag
  * @unrecoverable: Controller unrecoverable flag
+ * @diagsave_timeout: Diagnostic information save timeout
  * @logging_level: Controller debug logging level
  * @current_event: Firmware event currently in process
  * @driver_info: Driver, Kernel, OS information to firmware
@@ -574,6 +579,11 @@ struct mpi3mr_ioc {
 	spinlock_t sbq_lock;
 	u32 sbq_host_index;
 
+	char watchdog_work_q_name[20];
+	struct workqueue_struct *watchdog_work_q;
+	struct delayed_work watchdog_work;
+	spinlock_t watchdog_lock;
+
 	u8 is_driver_loading;
 	u8 scan_started;
 	u16 scan_failed;
@@ -591,6 +601,7 @@ struct mpi3mr_ioc {
 	u8 reset_in_progress;
 	u8 unrecoverable;
 
+	u16 diagsave_timeout;
 	int logging_level;
 
 	struct mpi3mr_fwevt *current_event;
diff --git a/drivers/scsi/mpi3mr/mpi3mr_fw.c b/drivers/scsi/mpi3mr/mpi3mr_fw.c
index abdf8c653e6b..4f1524dcad4d 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_fw.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_fw.c
@@ -1480,6 +1480,129 @@ int mpi3mr_op_request_post(struct mpi3mr_ioc *mrioc,
 	return retval;
 }
 
+/**
+ * mpi3mr_watchdog_work - watchdog thread to monitor faults
+ * @work: work struct
+ *
+ * Watch dog work periodically executed (1 second interval) to
+ * monitor firmware fault and to issue periodic timer sync to
+ * the firmware.
+ *
+ * Return: Nothing.
+ */
+static void mpi3mr_watchdog_work(struct work_struct *work)
+{
+	struct mpi3mr_ioc *mrioc =
+	    container_of(work, struct mpi3mr_ioc, watchdog_work.work);
+	unsigned long flags;
+	enum mpi3mr_iocstate ioc_state;
+	u32 fault, host_diagnostic;
+
+	/*Check for fault state every one second and issue Soft reset*/
+	ioc_state = mpi3mr_get_iocstate(mrioc);
+	if (ioc_state == MRIOC_STATE_FAULT) {
+		fault = readl(&mrioc->sysif_regs->Fault) &
+		    MPI3_SYSIF_FAULT_CODE_MASK;
+		host_diagnostic = readl(&mrioc->sysif_regs->HostDiagnostic);
+		if (host_diagnostic & MPI3_SYSIF_HOST_DIAG_SAVE_IN_PROGRESS) {
+			if (!mrioc->diagsave_timeout) {
+				mpi3mr_print_fault_info(mrioc);
+				ioc_warn(mrioc, "Diag save in progress\n");
+			}
+			if ((mrioc->diagsave_timeout++) <=
+			    MPI3_SYSIF_DIAG_SAVE_TIMEOUT)
+				goto schedule_work;
+		} else
+			mpi3mr_print_fault_info(mrioc);
+		mrioc->diagsave_timeout = 0;
+
+		if (fault == MPI3_SYSIF_FAULT_CODE_FACTORY_RESET) {
+			ioc_info(mrioc,
+			    "Factory Reset Fault occurred marking controller as unrecoverable"
+			    );
+			mrioc->unrecoverable = 1;
+			goto out;
+		}
+
+		if ((fault == MPI3_SYSIF_FAULT_CODE_DIAG_FAULT_RESET)
+		    || (fault == MPI3_SYSIF_FAULT_CODE_SOFT_RESET_IN_PROGRESS)
+		    || (mrioc->reset_in_progress))
+			goto out;
+		if (fault == MPI3_SYSIF_FAULT_CODE_CI_ACTIVATION_RESET)
+			mpi3mr_soft_reset_handler(mrioc,
+			    MPI3MR_RESET_FROM_CIACTIV_FAULT, 0);
+		else
+			mpi3mr_soft_reset_handler(mrioc,
+			    MPI3MR_RESET_FROM_FAULT_WATCH, 0);
+	}
+
+schedule_work:
+	spin_lock_irqsave(&mrioc->watchdog_lock, flags);
+	if (mrioc->watchdog_work_q)
+		queue_delayed_work(mrioc->watchdog_work_q,
+		    &mrioc->watchdog_work,
+		    msecs_to_jiffies(MPI3MR_WATCHDOG_INTERVAL));
+	spin_unlock_irqrestore(&mrioc->watchdog_lock, flags);
+out:
+	return;
+}
+
+/**
+ * mpi3mr_start_watchdog - Start watchdog
+ * @mrioc: Adapter instance reference
+ *
+ * Create and start the watchdog thread to monitor controller
+ * faults.
+ *
+ * Return: Nothing.
+ */
+void mpi3mr_start_watchdog(struct mpi3mr_ioc *mrioc)
+{
+	if (mrioc->watchdog_work_q)
+		return;
+
+	INIT_DELAYED_WORK(&mrioc->watchdog_work, mpi3mr_watchdog_work);
+	snprintf(mrioc->watchdog_work_q_name,
+	    sizeof(mrioc->watchdog_work_q_name), "watchdog_%s%d", mrioc->name,
+	    mrioc->id);
+	mrioc->watchdog_work_q =
+	    create_singlethread_workqueue(mrioc->watchdog_work_q_name);
+	if (!mrioc->watchdog_work_q) {
+		ioc_err(mrioc, "%s: failed (line=%d)\n", __func__, __LINE__);
+		return;
+	}
+
+	if (mrioc->watchdog_work_q)
+		queue_delayed_work(mrioc->watchdog_work_q,
+		    &mrioc->watchdog_work,
+		    msecs_to_jiffies(MPI3MR_WATCHDOG_INTERVAL));
+}
+
+/**
+ * mpi3mr_stop_watchdog - Stop watchdog
+ * @mrioc: Adapter instance reference
+ *
+ * Stop the watchdog thread created to monitor controller
+ * faults.
+ *
+ * Return: Nothing.
+ */
+void mpi3mr_stop_watchdog(struct mpi3mr_ioc *mrioc)
+{
+	unsigned long flags;
+	struct workqueue_struct *wq;
+
+	spin_lock_irqsave(&mrioc->watchdog_lock, flags);
+	wq = mrioc->watchdog_work_q;
+	mrioc->watchdog_work_q = NULL;
+	spin_unlock_irqrestore(&mrioc->watchdog_lock, flags);
+	if (wq) {
+		if (!cancel_delayed_work_sync(&mrioc->watchdog_work))
+			flush_workqueue(wq);
+		destroy_workqueue(wq);
+	}
+}
+
 
 /**
  * mpi3mr_setup_admin_qpair - Setup admin queue pair
@@ -2634,6 +2757,8 @@ void mpi3mr_cleanup_ioc(struct mpi3mr_ioc *mrioc)
 {
 	enum mpi3mr_iocstate ioc_state;
 
+	mpi3mr_stop_watchdog(mrioc);
+
 	mpi3mr_ioc_disable_intr(mrioc);
 
 	ioc_state = mpi3mr_get_iocstate(mrioc);
diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c
index 01be5f337826..7b0d52481929 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_os.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_os.c
@@ -570,6 +570,7 @@ static int mpi3mr_scan_finished(struct Scsi_Host *shost,
 	if (mrioc->scan_started)
 		return 0;
 	ioc_info(mrioc, "%s :port enable: SUCCESS\n", __func__);
+	mpi3mr_start_watchdog(mrioc);
 	mrioc->is_driver_loading = 0;
 
 	return 1;
@@ -856,9 +857,11 @@ mpi3mr_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	spin_lock_init(&mrioc->admin_req_lock);
 	spin_lock_init(&mrioc->reply_free_queue_lock);
 	spin_lock_init(&mrioc->sbq_lock);
+	spin_lock_init(&mrioc->watchdog_lock);
 	spin_lock_init(&mrioc->chain_buf_lock);
 
 	mpi3mr_init_drv_cmd(&mrioc->init_cmds, MPI3MR_HOSTTAG_INITCMDS);
+
 	if (pdev->revision)
 		mrioc->enable_segqueue = true;
 
-- 
2.18.1


-- 
This electronic communication and the information and any files transmitted 
with it, or attached to it, are confidential and are intended solely for 
the use of the individual or entity to whom it is addressed and may contain 
information that is confidential, legally privileged, protected by privacy 
laws, or otherwise restricted from disclosure to anyone else. If you are 
not the intended recipient or the person responsible for delivering the 
e-mail to the intended recipient, you are hereby notified that any use, 
copying, distributing, dissemination, forwarding, printing, or copying of 
this e-mail is strictly prohibited. If you received this e-mail in error, 
please return the e-mail to the sender, delete it from your computer, and 
destroy any printed copy of it.

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4169 bytes --]

^ permalink raw reply related	[flat|nested] 75+ messages in thread

* [PATCH 06/24] mpi3mr: add support of event handling part-1
  2020-12-22 10:11 [PATCH 00/24] Introducing mpi3mr driver Kashyap Desai
                   ` (4 preceding siblings ...)
  2020-12-22 10:11 ` [PATCH 05/24] mpi3mr: add support of internal watchdog thread Kashyap Desai
@ 2020-12-22 10:11 ` Kashyap Desai
  2020-12-27 13:14     ` kernel test robot
                     ` (2 more replies)
  2020-12-22 10:11 ` [PATCH 07/24] mpi3mr: add support of event handling pcie devices part-2 Kashyap Desai
                   ` (18 subsequent siblings)
  24 siblings, 3 replies; 75+ messages in thread
From: Kashyap Desai @ 2020-12-22 10:11 UTC (permalink / raw)
  To: linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, Kashyap Desai, sathya.prakash

[-- Attachment #1: Type: text/plain, Size: 223102 bytes --]

Firmware can report various MPI Events.
Support for certain Events (as listed below) are enabled in the driver
and their processing in driver is covered in this patch.

MPI3_EVENT_DEVICE_ADDED
MPI3_EVENT_DEVICE_INFO_CHANGED
MPI3_EVENT_DEVICE_STATUS_CHANGE
MPI3_EVENT_ENCL_DEVICE_STATUS_CHANGE
MPI3_EVENT_SAS_TOPOLOGY_CHANGE_LIST
MPI3_EVENT_SAS_DISCOVERY
MPI3_EVENT_SAS_DEVICE_DISCOVERY_ERROR

Key support in this patch is device add/removal.

Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Cc: sathya.prakash@broadcom.com
---
 drivers/scsi/mpi3mr/mpi/mpi30_api.h  |    2 +
 drivers/scsi/mpi3mr/mpi/mpi30_cnfg.h | 2721 ++++++++++++++++++++++++++
 drivers/scsi/mpi3mr/mpi/mpi30_sas.h  |   46 +
 drivers/scsi/mpi3mr/mpi3mr.h         |  195 ++
 drivers/scsi/mpi3mr/mpi3mr_fw.c      |  177 +-
 drivers/scsi/mpi3mr/mpi3mr_os.c      | 1452 ++++++++++++++
 6 files changed, 4592 insertions(+), 1 deletion(-)
 create mode 100644 drivers/scsi/mpi3mr/mpi/mpi30_cnfg.h
 create mode 100644 drivers/scsi/mpi3mr/mpi/mpi30_sas.h

diff --git a/drivers/scsi/mpi3mr/mpi/mpi30_api.h b/drivers/scsi/mpi3mr/mpi/mpi30_api.h
index ca07387536d3..7bdd5aeb23be 100644
--- a/drivers/scsi/mpi3mr/mpi/mpi30_api.h
+++ b/drivers/scsi/mpi3mr/mpi/mpi30_api.h
@@ -14,8 +14,10 @@
 
 #include "mpi30_type.h"
 #include "mpi30_transport.h"
+#include "mpi30_cnfg.h"
 #include "mpi30_image.h"
 #include "mpi30_init.h"
 #include "mpi30_ioc.h"
+#include "mpi30_sas.h"
 
 #endif  /* MPI30_API_H */
diff --git a/drivers/scsi/mpi3mr/mpi/mpi30_cnfg.h b/drivers/scsi/mpi3mr/mpi/mpi30_cnfg.h
new file mode 100644
index 000000000000..3badb1bb85b1
--- /dev/null
+++ b/drivers/scsi/mpi3mr/mpi/mpi30_cnfg.h
@@ -0,0 +1,2721 @@
+/*
+ *  Copyright 2017-2020 Broadcom Inc. All rights reserved.
+ *
+ *           Name: mpi30_cnfg.h
+ *    Description: Contains definitions for Configuration messages and pages
+ *  Creation Date: 03/15/2017
+ *        Version: 03.00.00
+ */
+#ifndef MPI30_CNFG_H
+#define MPI30_CNFG_H     1
+
+/*****************************************************************************
+ *              Configuration Page Types                                     *
+ ****************************************************************************/
+#define MPI3_CONFIG_PAGETYPE_IO_UNIT                    (0x00)
+#define MPI3_CONFIG_PAGETYPE_MANUFACTURING              (0x01)
+#define MPI3_CONFIG_PAGETYPE_IOC                        (0x02)
+#define MPI3_CONFIG_PAGETYPE_UEFI_BSD                   (0x03)
+#define MPI3_CONFIG_PAGETYPE_SECURITY                   (0x04)
+#define MPI3_CONFIG_PAGETYPE_ENCLOSURE                  (0x11)
+#define MPI3_CONFIG_PAGETYPE_DEVICE                     (0x12)
+#define MPI3_CONFIG_PAGETYPE_SAS_IO_UNIT                (0x20)
+#define MPI3_CONFIG_PAGETYPE_SAS_EXPANDER               (0x21)
+#define MPI3_CONFIG_PAGETYPE_SAS_PHY                    (0x23)
+#define MPI3_CONFIG_PAGETYPE_SAS_PORT                   (0x24)
+#define MPI3_CONFIG_PAGETYPE_PCIE_IO_UNIT               (0x30)
+#define MPI3_CONFIG_PAGETYPE_PCIE_SWITCH                (0x31)
+#define MPI3_CONFIG_PAGETYPE_PCIE_LINK                  (0x33)
+
+/*****************************************************************************
+ *              Configuration Page Attributes                                *
+ ****************************************************************************/
+#define MPI3_CONFIG_PAGEATTR_MASK                       (0xF0)
+#define MPI3_CONFIG_PAGEATTR_READ_ONLY                  (0x00)
+#define MPI3_CONFIG_PAGEATTR_CHANGEABLE                 (0x10)
+#define MPI3_CONFIG_PAGEATTR_PERSISTENT                 (0x20)
+
+/*****************************************************************************
+ *              Configuration Page Actions                                   *
+ ****************************************************************************/
+#define MPI3_CONFIG_ACTION_PAGE_HEADER                  (0x00)
+#define MPI3_CONFIG_ACTION_READ_DEFAULT                 (0x01)
+#define MPI3_CONFIG_ACTION_READ_CURRENT                 (0x02)
+#define MPI3_CONFIG_ACTION_WRITE_CURRENT                (0x03)
+#define MPI3_CONFIG_ACTION_READ_PERSISTENT              (0x04)
+#define MPI3_CONFIG_ACTION_WRITE_PERSISTENT             (0x05)
+
+/*****************************************************************************
+ *              Configuration Page Addressing                                *
+ ****************************************************************************/
+
+/**** Device PageAddress Format ****/
+#define MPI3_DEVICE_PGAD_FORM_MASK                      (0xF0000000)
+#define MPI3_DEVICE_PGAD_FORM_GET_NEXT_HANDLE           (0x00000000)
+#define MPI3_DEVICE_PGAD_FORM_HANDLE                    (0x20000000)
+#define MPI3_DEVICE_PGAD_HANDLE_MASK                    (0x0000FFFF)
+
+/**** SAS Expander PageAddress Format ****/
+#define MPI3_SAS_EXPAND_PGAD_FORM_MASK                  (0xF0000000)
+#define MPI3_SAS_EXPAND_PGAD_FORM_GET_NEXT_HANDLE       (0x00000000)
+#define MPI3_SAS_EXPAND_PGAD_FORM_HANDLE_PHY_NUM        (0x10000000)
+#define MPI3_SAS_EXPAND_PGAD_FORM_HANDLE                (0x20000000)
+#define MPI3_SAS_EXPAND_PGAD_PHYNUM_MASK                (0x00FF0000)
+#define MPI3_SAS_EXPAND_PGAD_PHYNUM_SHIFT               (16)
+#define MPI3_SAS_EXPAND_PGAD_HANDLE_MASK                (0x0000FFFF)
+
+/**** SAS Phy PageAddress Format ****/
+#define MPI3_SAS_PHY_PGAD_FORM_MASK                     (0xF0000000)
+#define MPI3_SAS_PHY_PGAD_FORM_PHY_NUMBER               (0x00000000)
+#define MPI3_SAS_PHY_PGAD_PHY_NUMBER_MASK               (0x000000FF)
+
+/**** SAS Port PageAddress Format ****/
+#define MPI3_SASPORT_PGAD_FORM_MASK                     (0xF0000000)
+#define MPI3_SASPORT_PGAD_FORM_GET_NEXT_PORT            (0x00000000)
+#define MPI3_SASPORT_PGAD_FORM_PORT_NUM                 (0x10000000)
+#define MPI3_SASPORT_PGAD_PORT_NUMBER_MASK              (0x000000FF)
+
+/**** Enclosure PageAddress Format ****/
+#define MPI3_ENCLOS_PGAD_FORM_MASK                      (0xF0000000)
+#define MPI3_ENCLOS_PGAD_FORM_GET_NEXT_HANDLE           (0x00000000)
+#define MPI3_ENCLOS_PGAD_FORM_HANDLE                    (0x10000000)
+#define MPI3_ENCLOS_PGAD_HANDLE_MASK                    (0x0000FFFF)
+
+/**** PCIe Switch PageAddress Format ****/
+#define MPI3_PCIE_SWITCH_PGAD_FORM_MASK                 (0xF0000000)
+#define MPI3_PCIE_SWITCH_PGAD_FORM_GET_NEXT_HANDLE      (0x00000000)
+#define MPI3_PCIE_SWITCH_PGAD_FORM_HANDLE_PORT_NUM      (0x10000000)
+#define MPI3_PCIE_SWITCH_PGAD_FORM_HANDLE               (0x20000000)
+#define MPI3_PCIE_SWITCH_PGAD_PORTNUM_MASK              (0x00FF0000)
+#define MPI3_PCIE_SWITCH_PGAD_PORTNUM_SHIFT             (16)
+#define MPI3_PCIE_SWITCH_PGAD_HANDLE_MASK               (0x0000FFFF)
+
+/**** PCIe Link PageAddress Format ****/
+#define MPI3_PCIE_LINK_PGAD_FORM_MASK                   (0xF0000000)
+#define MPI3_PCIE_LINK_PGAD_FORM_GET_NEXT_LINK          (0x00000000)
+#define MPI3_PCIE_LINK_PGAD_FORM_LINK_NUM               (0x10000000)
+#define MPI3_PCIE_LINK_PGAD_LINKNUM_MASK                (0x000000FF)
+
+/**** Security PageAddress Format ****/
+#define MPI3_SECURITY_PGAD_FORM_MASK                    (0xF0000000)
+#define MPI3_SECURITY_PGAD_FORM_GET_NEXT_SLOT           (0x00000000)
+#define MPI3_SECURITY_PGAD_FORM_SOT_NUM                 (0x10000000)
+#define MPI3_SECURITY_PGAD_SLOT_GROUP_MASK              (0x0000FF00)
+#define MPI3_SECURITY_PGAD_SLOT_MASK                    (0x000000FF)
+
+/*****************************************************************************
+ *              Configuration Request Message                                *
+ ****************************************************************************/
+typedef struct _MPI3_CONFIG_REQUEST {
+    U16             HostTag;                            /* 0x00 */
+    U8              IOCUseOnly02;                       /* 0x02 */
+    U8              Function;                           /* 0x03 */
+    U16             IOCUseOnly04;                       /* 0x04 */
+    U8              IOCUseOnly06;                       /* 0x06 */
+    U8              MsgFlags;                           /* 0x07 */
+    U16             ChangeCount;                        /* 0x08 */
+    U16             Reserved0A;                         /* 0x0A */
+    U8              PageVersion;                        /* 0x0C */
+    U8              PageNumber;                         /* 0x0D */
+    U8              PageType;                           /* 0x0E */
+    U8              Action;                             /* 0x0F */
+    U32             PageAddress;                        /* 0x10 */
+    U16             PageLength;                         /* 0x14 */
+    U16             Reserved16;                         /* 0x16 */
+    U32             Reserved18[2];                      /* 0x18 */
+    MPI3_SGE_UNION  SGL;                                /* 0x20 */
+} MPI3_CONFIG_REQUEST, MPI3_POINTER PTR_MPI3_CONFIG_REQUEST,
+  Mpi3ConfigRequest_t, MPI3_POINTER pMpi3ConfigRequest_t;
+
+/*****************************************************************************
+ *              Configuration Pages                                          *
+ ****************************************************************************/
+
+/*****************************************************************************
+ *              Configuration Page Header                                    *
+ ****************************************************************************/
+typedef struct _MPI3_CONFIG_PAGE_HEADER {
+    U8              PageVersion;                        /* 0x00 */
+    U8              Reserved01;                         /* 0x01 */
+    U8              PageNumber;                         /* 0x02 */
+    U8              PageAttribute;                      /* 0x03 */
+    U16             PageLength;                         /* 0x04 */
+    U8              PageType;                           /* 0x06 */
+    U8              Reserved07;                         /* 0x07 */
+} MPI3_CONFIG_PAGE_HEADER, MPI3_POINTER PTR_MPI3_CONFIG_PAGE_HEADER,
+  Mpi3ConfigPageHeader_t, MPI3_POINTER pMpi3ConfigPageHeader_t;
+
+/*****************************************************************************
+ *              Common definitions used by Configuration Pages           *
+ ****************************************************************************/
+
+/**** Defines for Negotiated Link Rates ****/
+#define MPI3_SAS_NEG_LINK_RATE_LOGICAL_MASK             (0xF0)
+#define MPI3_SAS_NEG_LINK_RATE_LOGICAL_SHIFT            (4)
+#define MPI3_SAS_NEG_LINK_RATE_PHYSICAL_MASK            (0x0F)
+#define MPI3_SAS_NEG_LINK_RATE_UNKNOWN_LINK_RATE        (0x00)
+#define MPI3_SAS_NEG_LINK_RATE_PHY_DISABLED             (0x01)
+#define MPI3_SAS_NEG_LINK_RATE_NEGOTIATION_FAILED       (0x02)
+#define MPI3_SAS_NEG_LINK_RATE_SATA_OOB_COMPLETE        (0x03)
+#define MPI3_SAS_NEG_LINK_RATE_PORT_SELECTOR            (0x04)
+#define MPI3_SAS_NEG_LINK_RATE_SMP_RESET_IN_PROGRESS    (0x05)
+#define MPI3_SAS_NEG_LINK_RATE_UNSUPPORTED_PHY          (0x06)
+#define MPI3_SAS_NEG_LINK_RATE_1_5                      (0x08)
+#define MPI3_SAS_NEG_LINK_RATE_3_0                      (0x09)
+#define MPI3_SAS_NEG_LINK_RATE_6_0                      (0x0A)
+#define MPI3_SAS_NEG_LINK_RATE_12_0                     (0x0B)
+#define MPI3_SAS_NEG_LINK_RATE_22_5                     (0x0C)
+
+/**** Defines for the AttachedPhyInfo field ****/
+#define MPI3_SAS_APHYINFO_INSIDE_ZPSDS_PERSISTENT       (0x00000040)
+#define MPI3_SAS_APHYINFO_REQUESTED_INSIDE_ZPSDS        (0x00000020)
+#define MPI3_SAS_APHYINFO_BREAK_REPLY_CAPABLE           (0x00000010)
+
+#define MPI3_SAS_APHYINFO_REASON_MASK                   (0x0000000F)
+#define MPI3_SAS_APHYINFO_REASON_UNKNOWN                (0x00000000)
+#define MPI3_SAS_APHYINFO_REASON_POWER_ON               (0x00000001)
+#define MPI3_SAS_APHYINFO_REASON_HARD_RESET             (0x00000002)
+#define MPI3_SAS_APHYINFO_REASON_SMP_PHY_CONTROL        (0x00000003)
+#define MPI3_SAS_APHYINFO_REASON_LOSS_OF_SYNC           (0x00000004)
+#define MPI3_SAS_APHYINFO_REASON_MULTIPLEXING_SEQ       (0x00000005)
+#define MPI3_SAS_APHYINFO_REASON_IT_NEXUS_LOSS_TIMER    (0x00000006)
+#define MPI3_SAS_APHYINFO_REASON_BREAK_TIMEOUT          (0x00000007)
+#define MPI3_SAS_APHYINFO_REASON_PHY_TEST_STOPPED       (0x00000008)
+#define MPI3_SAS_APHYINFO_REASON_EXP_REDUCED_FUNC       (0x00000009)
+
+/**** Defines for the PhyInfo field ****/
+#define MPI3_SAS_PHYINFO_STATUS_MASK                    (0xC0000000)
+#define MPI3_SAS_PHYINFO_STATUS_SHIFT                   (30)
+#define MPI3_SAS_PHYINFO_STATUS_ACCESSIBLE              (0x00000000)
+#define MPI3_SAS_PHYINFO_STATUS_NOT_EXIST               (0x40000000)
+#define MPI3_SAS_PHYINFO_STATUS_VACANT                  (0x80000000)
+
+#define MPI3_SAS_PHYINFO_PHY_POWER_CONDITION_MASK       (0x18000000)
+#define MPI3_SAS_PHYINFO_PHY_POWER_CONDITION_ACTIVE     (0x00000000)
+#define MPI3_SAS_PHYINFO_PHY_POWER_CONDITION_PARTIAL    (0x08000000)
+#define MPI3_SAS_PHYINFO_PHY_POWER_CONDITION_SLUMBER    (0x10000000)
+
+#define MPI3_SAS_PHYINFO_REASON_MASK                    (0x000F0000)
+#define MPI3_SAS_PHYINFO_REASON_UNKNOWN                 (0x00000000)
+#define MPI3_SAS_PHYINFO_REASON_POWER_ON                (0x00010000)
+#define MPI3_SAS_PHYINFO_REASON_HARD_RESET              (0x00020000)
+#define MPI3_SAS_PHYINFO_REASON_SMP_PHY_CONTROL         (0x00030000)
+#define MPI3_SAS_PHYINFO_REASON_LOSS_OF_SYNC            (0x00040000)
+#define MPI3_SAS_PHYINFO_REASON_MULTIPLEXING_SEQ        (0x00050000)
+#define MPI3_SAS_PHYINFO_REASON_IT_NEXUS_LOSS_TIMER     (0x00060000)
+#define MPI3_SAS_PHYINFO_REASON_BREAK_TIMEOUT           (0x00070000)
+#define MPI3_SAS_PHYINFO_REASON_PHY_TEST_STOPPED        (0x00080000)
+#define MPI3_SAS_PHYINFO_REASON_EXP_REDUCED_FUNC        (0x00090000)
+
+#define MPI3_SAS_PHYINFO_SATA_PORT_ACTIVE               (0x00004000)
+#define MPI3_SAS_PHYINFO_SATA_PORT_SELECTOR_PRESENT     (0x00002000)
+#define MPI3_SAS_PHYINFO_VIRTUAL_PHY                    (0x00001000)
+
+#define MPI3_SAS_PHYINFO_PARTIAL_PATHWAY_TIME_MASK      (0x00000F00)
+#define MPI3_SAS_PHYINFO_PARTIAL_PATHWAY_TIME_SHIFT     (8)
+
+#define MPI3_SAS_PHYINFO_ROUTING_ATTRIBUTE_MASK         (0x000000F0)
+#define MPI3_SAS_PHYINFO_ROUTING_ATTRIBUTE_DIRECT       (0x00000000)
+#define MPI3_SAS_PHYINFO_ROUTING_ATTRIBUTE_SUBTRACTIVE  (0x00000010)
+#define MPI3_SAS_PHYINFO_ROUTING_ATTRIBUTE_TABLE        (0x00000020)
+
+/**** Defines for the ProgrammedLinkRate field ****/
+#define MPI3_SAS_PRATE_MAX_RATE_MASK                    (0xF0)
+#define MPI3_SAS_PRATE_MAX_RATE_NOT_PROGRAMMABLE        (0x00)
+#define MPI3_SAS_PRATE_MAX_RATE_1_5                     (0x80)
+#define MPI3_SAS_PRATE_MAX_RATE_3_0                     (0x90)
+#define MPI3_SAS_PRATE_MAX_RATE_6_0                     (0xA0)
+#define MPI3_SAS_PRATE_MAX_RATE_12_0                    (0xB0)
+#define MPI3_SAS_PRATE_MAX_RATE_22_5                    (0xC0)
+#define MPI3_SAS_PRATE_MIN_RATE_MASK                    (0x0F)
+#define MPI3_SAS_PRATE_MIN_RATE_NOT_PROGRAMMABLE        (0x00)
+#define MPI3_SAS_PRATE_MIN_RATE_1_5                     (0x08)
+#define MPI3_SAS_PRATE_MIN_RATE_3_0                     (0x09)
+#define MPI3_SAS_PRATE_MIN_RATE_6_0                     (0x0A)
+#define MPI3_SAS_PRATE_MIN_RATE_12_0                    (0x0B)
+#define MPI3_SAS_PRATE_MIN_RATE_22_5                    (0x0C)
+
+/**** Defines for the HwLinkRate field ****/
+#define MPI3_SAS_HWRATE_MAX_RATE_MASK                   (0xF0)
+#define MPI3_SAS_HWRATE_MAX_RATE_1_5                    (0x80)
+#define MPI3_SAS_HWRATE_MAX_RATE_3_0                    (0x90)
+#define MPI3_SAS_HWRATE_MAX_RATE_6_0                    (0xA0)
+#define MPI3_SAS_HWRATE_MAX_RATE_12_0                   (0xB0)
+#define MPI3_SAS_HWRATE_MAX_RATE_22_5                   (0xC0)
+#define MPI3_SAS_HWRATE_MIN_RATE_MASK                   (0x0F)
+#define MPI3_SAS_HWRATE_MIN_RATE_1_5                    (0x08)
+#define MPI3_SAS_HWRATE_MIN_RATE_3_0                    (0x09)
+#define MPI3_SAS_HWRATE_MIN_RATE_6_0                    (0x0A)
+#define MPI3_SAS_HWRATE_MIN_RATE_12_0                   (0x0B)
+#define MPI3_SAS_HWRATE_MIN_RATE_22_5                   (0x0C)
+
+/**** Defines for the Slot field ****/
+#define MPI3_SLOT_INVALID                           (0xFFFF)
+
+/**** Defines for the SlotIndex field ****/
+#define MPI3_SLOT_INDEX_INVALID                     (0xFFFF)
+
+/*****************************************************************************
+ *              Manufacturing Configuration Pages                            *
+ ****************************************************************************/
+
+/*****************************************************************************
+ *              Manufacturing Page 0                                         *
+ ****************************************************************************/
+typedef struct _MPI3_MAN_PAGE0 {
+    MPI3_CONFIG_PAGE_HEADER         Header;                 /* 0x00 */
+    U8                              ChipRevision[8];        /* 0x08 */
+    U8                              ChipName[32];           /* 0x10 */
+    U8                              BoardName[32];          /* 0x30 */
+    U8                              BoardAssembly[32];      /* 0x50 */
+    U8                              BoardTracerNumber[32];  /* 0x70 */
+    U32                             BoardPower;             /* 0x90 */
+    U32                             Reserved94;             /* 0x94 */
+    U32                             Reserved98;             /* 0x98 */
+    U8                              OEM;                    /* 0x9C */
+    U8                              SubOEM;                 /* 0x9D */
+    U16                             Reserved9E;             /* 0x9E */
+    U8                              BoardMfgDay;            /* 0xA0 */
+    U8                              BoardMfgMonth;          /* 0xA1 */
+    U16                             BoardMfgYear;           /* 0xA2 */
+    U8                              BoardReworkDay;         /* 0xA4 */
+    U8                              BoardReworkMonth;       /* 0xA5 */
+    U16                             BoardReworkYear;        /* 0xA6 */
+    U64                             BoardRevision;          /* 0xA8 */
+    U8                              EPackFRU[16];           /* 0xB0 */
+    U8                              ProductName[256];       /* 0xC0 */
+} MPI3_MAN_PAGE0, MPI3_POINTER PTR_MPI3_MAN_PAGE0,
+  Mpi3ManPage0_t, MPI3_POINTER pMpi3ManPage0_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_MAN0_PAGEVERSION       (0x00)
+
+/*****************************************************************************
+ *              Manufacturing Page 1                                         *
+ ****************************************************************************/
+
+#define MPI3_MAN1_VPD_SIZE                                   (512)
+
+typedef struct _MPI3_MAN_PAGE1 {
+    MPI3_CONFIG_PAGE_HEADER         Header;                  /* 0x00 */
+    U32                             Reserved08[2];           /* 0x08 */
+    U8                              VPD[MPI3_MAN1_VPD_SIZE]; /* 0x10 */
+} MPI3_MAN_PAGE1, MPI3_POINTER PTR_MPI3_MAN_PAGE1,
+  Mpi3ManPage1_t, MPI3_POINTER pMpi3ManPage1_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_MAN1_PAGEVERSION                                 (0x00)
+
+/*****************************************************************************
+ *              Manufacturing Page 5                                         *
+ ****************************************************************************/
+typedef struct _MPI3_MAN5_PHY_ENTRY {
+    U64     IOC_WWID;                                       /* 0x00 */
+    U64     DeviceName;                                     /* 0x08 */
+    U64     SATA_WWID;                                      /* 0x10 */
+} MPI3_MAN5_PHY_ENTRY, MPI3_POINTER PTR_MPI3_MAN5_PHY_ENTRY,
+  Mpi3Man5PhyEntry_t, MPI3_POINTER pMpi3Man5PhyEntry_t;
+
+#ifndef MPI3_MAN5_PHY_MAX
+#define MPI3_MAN5_PHY_MAX                                   (1)
+#endif  /* MPI3_MAN5_PHY_MAX */
+
+typedef struct _MPI3_MAN_PAGE5 {
+    MPI3_CONFIG_PAGE_HEADER         Header;                 /* 0x00 */
+    U8                              NumPhys;                /* 0x08 */
+    U8                              Reserved09[3];          /* 0x09 */
+    U32                             Reserved0C;             /* 0x0C */
+    MPI3_MAN5_PHY_ENTRY             Phy[MPI3_MAN5_PHY_MAX]; /* 0x10 */
+} MPI3_MAN_PAGE5, MPI3_POINTER PTR_MPI3_MAN_PAGE5,
+  Mpi3ManPage5_t, MPI3_POINTER pMpi3ManPage5_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_MAN5_PAGEVERSION                                (0x00)
+
+/*****************************************************************************
+ *              Manufacturing Page 6                                         *
+ ****************************************************************************/
+typedef struct _MPI3_MAN6_GPIO_ENTRY {
+    U8      FunctionCode;                                                     /* 0x00 */
+    U8      Reserved01;                                                       /* 0x01 */
+    U16     Flags;                                                            /* 0x02 */
+    U8      Param1;                                                           /* 0x04 */
+    U8      Param2;                                                           /* 0x05 */
+    U16     Reserved06;                                                       /* 0x06 */
+    U32     Param3;                                                           /* 0x08 */
+} MPI3_MAN6_GPIO_ENTRY, MPI3_POINTER PTR_MPI3_MAN6_GPIO_ENTRY,
+  Mpi3Man6GpioEntry_t, MPI3_POINTER pMpi3Man6GpioEntry_t;
+
+/**** Defines for the FunctionCode field ****/
+#define MPI3_MAN6_GPIO_FUNCTION_GENERIC                                       (0x00)
+#define MPI3_MAN6_GPIO_FUNCTION_ALTERNATE                                     (0x01)
+#define MPI3_MAN6_GPIO_FUNCTION_EXT_INTERRUPT                                 (0x02)
+#define MPI3_MAN6_GPIO_FUNCTION_GLOBAL_ACTIVITY                               (0x03)
+#define MPI3_MAN6_GPIO_FUNCTION_OVER_TEMPERATURE                              (0x04)
+#define MPI3_MAN6_GPIO_FUNCTION_PORT_STATUS_GREEN                             (0x05)
+#define MPI3_MAN6_GPIO_FUNCTION_PORT_STATUS_YELLOW                            (0x06)
+#define MPI3_MAN6_GPIO_FUNCTION_CABLE_MANAGEMENT                              (0x07)
+#define MPI3_MAN6_GPIO_FUNCTION_BKPLANE_MGMT_TYPE                             (0x08)
+#define MPI3_MAN6_GPIO_FUNCTION_ISTWI_MUX_RESET                               (0x09)
+#define MPI3_MAN6_GPIO_FUNCTION_ISTWI_RESET                                   (0x0A)
+#define MPI3_MAN6_GPIO_FUNCTION_BACKEND_PCIE_RESET                            (0x0B)
+#define MPI3_MAN6_GPIO_FUNCTION_GLOBAL_FAULT                                  (0x0C)
+#define MPI3_MAN6_GPIO_FUNCTION_EPACK_ATTN                                    (0x0D)
+#define MPI3_MAN6_GPIO_FUNCTION_EPACK_ONLINE                                  (0x0E)
+#define MPI3_MAN6_GPIO_FUNCTION_EPACK_FAULT                                   (0x0F)
+#define MPI3_MAN6_GPIO_FUNCTION_CTRL_TYPE                                     (0x10)
+#define MPI3_MAN6_GPIO_FUNCTION_LICENSE                                       (0x11)
+#define MPI3_MAN6_GPIO_FUNCTION_REFCLK_CONTROL                                (0x12)
+
+/**** Defines for Param1 (Flags) when FunctionCode is EXT_INTERRUPT ****/
+#define MPI3_MAN6_GPIO_EXTINT_PARAM1_FLAGS_SOURCE_MASK                        (0xF0)
+#define MPI3_MAN6_GPIO_EXTINT_PARAM1_FLAGS_SOURCE_GENERIC                     (0x00)
+#define MPI3_MAN6_GPIO_EXTINT_PARAM1_FLAGS_SOURCE_CABLE_MGMT                  (0x10)
+#define MPI3_MAN6_GPIO_EXTINT_PARAM1_FLAGS_SOURCE_ACTIVE_CABLE_OVERCURRENT    (0x20)
+
+#define MPI3_MAN6_GPIO_EXTINT_PARAM1_FLAGS_TRIGGER_MASK                       (0x01)
+#define MPI3_MAN6_GPIO_EXTINT_PARAM1_FLAGS_TRIGGER_EDGE                       (0x00)
+#define MPI3_MAN6_GPIO_EXTINT_PARAM1_FLAGS_TRIGGER_LEVEL                      (0x01)
+
+/**** Defines for Param1 (PHY STATE) when FunctionCode is PORT_STATUS_GREEN ****/
+#define MPI3_MAN6_GPIO_PORT_GREEN_PARAM1_PHY_STATUS_ALL_UP                    (0x00)
+#define MPI3_MAN6_GPIO_PORT_GREEN_PARAM1_PHY_STATUS_ONE_OR_MORE_UP            (0x01)
+
+/**** Defines for Param1 (INTERFACE_SIGNAL) when FunctionCode is CABLE_MANAGEMENT ****/
+#define MPI3_MAN6_GPIO_CABLE_MGMT_PARAM1_INTERFACE_MODULE_PRESENT             (0x00)
+#define MPI3_MAN6_GPIO_CABLE_MGMT_PARAM1_INTERFACE_ACTIVE_CABLE_ENABLE        (0x01)
+#define MPI3_MAN6_GPIO_CABLE_MGMT_PARAM1_INTERFACE_CABLE_MGMT_ENABLE          (0x02)
+
+/**** Defines for Param2 (ISTWI RESET) when FunctionCode is ISTWI_MUX_RESET ****/
+#define MPI3_MAN6_GPIO_ISTWI_MUX_RESET_PARAM2_SPEC_MUX                        (0x00)
+#define MPI3_MAN6_GPIO_ISTWI_MUX_RESET_PARAM2_ALL_MUXES                       (0x01)
+
+/**** Defines for Param1 (LECENSE_TYPE) when FunctionCode is LICENSE ****/
+#define MPI3_MAN6_GPIO_LICENSE_PARAM1_TYPE_IBUTTON                            (0x00)
+
+
+/**** Defines for the Flags field ****/
+#define MPI3_MAN6_GPIO_FLAGS_SLEW_RATE_MASK                                   (0x0100)
+#define MPI3_MAN6_GPIO_FLAGS_SLEW_RATE_FAST_EDGE                              (0x0100)
+#define MPI3_MAN6_GPIO_FLAGS_SLEW_RATE_SLOW_EDGE                              (0x0000)
+#define MPI3_MAN6_GPIO_FLAGS_DRIVE_STRENGTH_MASK                              (0x00C0)
+#define MPI3_MAN6_GPIO_FLAGS_DRIVE_STRENGTH_100OHM                            (0x0000)
+#define MPI3_MAN6_GPIO_FLAGS_DRIVE_STRENGTH_66OHM                             (0x0040)
+#define MPI3_MAN6_GPIO_FLAGS_DRIVE_STRENGTH_50OHM                             (0x0080)
+#define MPI3_MAN6_GPIO_FLAGS_DRIVE_STRENGTH_33OHM                             (0x00C0)
+#define MPI3_MAN6_GPIO_FLAGS_ALT_DATA_SEL_MASK                                (0x0030)
+#define MPI3_MAN6_GPIO_FLAGS_ALT_DATA_SEL_SHIFT                               (4)
+#define MPI3_MAN6_GPIO_FLAGS_ACTIVE_HIGH                                      (0x0008)
+#define MPI3_MAN6_GPIO_FLAGS_BI_DIR_ENABLED                                   (0x0004)
+#define MPI3_MAN6_GPIO_FLAGS_DIRECTION_MASK                                   (0x0003)
+#define MPI3_MAN6_GPIO_FLAGS_DIRECTION_INPUT                                  (0x0000)
+#define MPI3_MAN6_GPIO_FLAGS_DIRECTION_OPEN_DRAIN_OUTPUT                      (0x0001)
+#define MPI3_MAN6_GPIO_FLAGS_DIRECTION_OPEN_SOURCE_OUTPUT                     (0x0002)
+#define MPI3_MAN6_GPIO_FLAGS_DIRECTION_PUSH_PULL_OUTPUT                       (0x0003)
+
+#ifndef MPI3_MAN6_GPIO_MAX
+#define MPI3_MAN6_GPIO_MAX                                                    (1)
+#endif  /* MPI3_MAN6_GPIO_MAX */
+
+typedef struct _MPI3_MAN_PAGE6 {
+    MPI3_CONFIG_PAGE_HEADER         Header;                                   /* 0x00 */
+    U16                             Flags;                                    /* 0x08 */
+    U16                             Reserved0A;                               /* 0x0A */
+    U8                              NumGPIO;                                  /* 0x0C */
+    U8                              Reserved0D[3];                            /* 0x0D */
+    MPI3_MAN6_GPIO_ENTRY            GPIO[MPI3_MAN6_GPIO_MAX];                 /* 0x10 */
+} MPI3_MAN_PAGE6, MPI3_POINTER PTR_MPI3_MAN_PAGE6,
+  Mpi3ManPage6_t, MPI3_POINTER pMpi3ManPage6_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_MAN6_PAGEVERSION                                                 (0x00)
+
+/**** Defines for the Flags field ****/
+#define MPI3_MAN6_FLAGS_HEARTBEAT_LED_DISABLED                                (0x0001)
+
+/*****************************************************************************
+ *              Manufacturing Page 7                                         *
+ ****************************************************************************/
+typedef struct _MPI3_MAN7_RECEPTACLE_INFO {
+    U32                             Name[4];                    /* 0x00 */
+    U8                              Location;                   /* 0x10 */
+    U8                              ConnectorType;              /* 0x11 */
+    U8                              PEDClk;                     /* 0x12 */
+    U8                              ConnectorID;                /* 0x13 */
+    U32                             Reserved14;                 /* 0x14 */
+} MPI3_MAN7_RECEPTACLE_INFO, MPI3_POINTER PTR_MPI3_MAN7_RECEPTACLE_INFO,
+ Mpi3Man7ReceptacleInfo_t, MPI3_POINTER pMpi3Man7ReceptacleInfo_t;
+
+/**** Defines for Location field ****/
+#define MPI3_MAN7_LOCATION_UNKNOWN                         (0x00)
+#define MPI3_MAN7_LOCATION_INTERNAL                        (0x01)
+#define MPI3_MAN7_LOCATION_EXTERNAL                        (0x02)
+#define MPI3_MAN7_LOCATION_VIRTUAL                         (0x03)
+
+/**** Defines for ConnectorType - Use definitions from SES-4 ****/
+
+/**** Defines for PEDClk field ****/
+#define MPI3_MAN7_PEDCLK_ROUTING_MASK                      (0x10)
+#define MPI3_MAN7_PEDCLK_ROUTING_DIRECT                    (0x00)
+#define MPI3_MAN7_PEDCLK_ROUTING_CLOCK_BUFFER              (0x10)
+#define MPI3_MAN7_PEDCLK_ID_MASK                           (0x0F)
+
+#ifndef MPI3_MAN7_RECEPTACLE_INFO_MAX
+#define MPI3_MAN7_RECEPTACLE_INFO_MAX                      (1)
+#endif  /* MPI3_MAN7_RECEPTACLE_INFO_MAX */
+
+typedef struct _MPI3_MAN_PAGE7 {
+    MPI3_CONFIG_PAGE_HEADER         Header;                                           /* 0x00 */
+    U32                             Flags;                                            /* 0x08 */
+    U8                              NumReceptacles;                                   /* 0x0C */
+    U8                              Reserved0D[3];                                    /* 0x0D */
+    U32                             EnclosureName[4];                                 /* 0x10 */
+    MPI3_MAN7_RECEPTACLE_INFO       ReceptacleInfo[MPI3_MAN7_RECEPTACLE_INFO_MAX];    /* 0x20 */   /* variable length array */
+} MPI3_MAN_PAGE7, MPI3_POINTER PTR_MPI3_MAN_PAGE7,
+  Mpi3ManPage7_t, MPI3_POINTER pMpi3ManPage7_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_MAN7_PAGEVERSION                              (0x00)
+
+/**** Defines for Flags field ****/
+#define MPI3_MAN7_FLAGS_BASE_ENCLOSURE_LEVEL_MASK          (0x01)
+#define MPI3_MAN7_FLAGS_BASE_ENCLOSURE_LEVEL_0             (0x00)
+#define MPI3_MAN7_FLAGS_BASE_ENCLOSURE_LEVEL_1             (0x01)
+
+
+/*****************************************************************************
+ *              Manufacturing Page 8                                         *
+ ****************************************************************************/
+
+typedef struct _MPI3_MAN8_PHY_INFO {
+    U8                              ReceptacleID;               /* 0x00 */
+    U8                              ConnectorLane;              /* 0x01 */
+    U16                             Reserved02;                 /* 0x02 */
+    U16                             Slotx1;                     /* 0x04 */
+    U16                             Slotx2;                     /* 0x06 */
+    U16                             Slotx4;                     /* 0x08 */
+    U16                             Reserved0A;                 /* 0x0A */
+    U32                             Reserved0C;                 /* 0x0C */
+} MPI3_MAN8_PHY_INFO, MPI3_POINTER PTR_MPI3_MAN8_PHY_INFO,
+  Mpi3Man8PhyInfo_t, MPI3_POINTER pMpi3Man8PhyInfo_t;
+
+#ifndef MPI3_MAN8_PHY_INFO_MAX
+#define MPI3_MAN8_PHY_INFO_MAX                      (1)
+#endif  /* MPI3_MAN8_PHY_INFO_MAX */
+
+typedef struct _MPI3_MAN_PAGE8 {
+    MPI3_CONFIG_PAGE_HEADER         Header;                            /* 0x00 */
+    U32                             Reserved08;                        /* 0x08 */
+    U8                              NumPhys;                           /* 0x0C */
+    U8                              Reserved0D[3];                     /* 0x0D */
+    MPI3_MAN8_PHY_INFO              PhyInfo[MPI3_MAN8_PHY_INFO_MAX];   /* 0x10 */  /* variable length array */
+} MPI3_MAN_PAGE8, MPI3_POINTER PTR_MPI3_MAN_PAGE8,
+  Mpi3ManPage8_t, MPI3_POINTER pMpi3ManPage8_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_MAN8_PAGEVERSION                   (0x00)
+
+/*****************************************************************************
+ *              Manufacturing Page 9                                         *
+ ****************************************************************************/
+typedef struct _MPI3_MAN9_RSRC_ENTRY {
+    U32     Maximum;        /* 0x00 */
+    U32     Decrement;      /* 0x04 */
+    U32     Minimum;        /* 0x08 */
+    U32     Actual;         /* 0x0C */
+} MPI3_MAN9_RSRC_ENTRY, MPI3_POINTER PTR_MPI3_MAN9_RSRC_ENTRY,
+  Mpi3Man9RsrcEntry_t, MPI3_POINTER pMpi3Man9RsrcEntry_t;
+
+typedef enum _MPI3_MAN9_RESOURCES {
+    MPI3_MAN9_RSRC_OUTSTANDING_REQS = 0,
+    MPI3_MAN9_RSRC_TARGET_CMDS      = 1,
+    MPI3_MAN9_RSRC_SAS_TARGETS      = 2,
+    MPI3_MAN9_RSRC_PCIE_TARGETS     = 3,
+    MPI3_MAN9_RSRC_INITIATORS       = 4,
+    MPI3_MAN9_RSRC_VDS              = 5,
+    MPI3_MAN9_RSRC_ENCLOSURES       = 6,
+    MPI3_MAN9_RSRC_ENCLOSURE_PHYS   = 7,
+    MPI3_MAN9_RSRC_EXPANDERS        = 8,
+    MPI3_MAN9_RSRC_PCIE_SWITCHES    = 9,
+    MPI3_MAN9_RSRC_PDS              = 10,
+    MPI3_MAN9_RSRC_HOST_PDS         = 11,
+    MPI3_MAN9_RSRC_ADV_HOST_PDS     = 12,
+    MPI3_MAN9_RSRC_RAID_PDS         = 13,
+    MPI3_MAN9_RSRC_NUM_RESOURCES
+} MPI3_MAN9_RESOURCES;
+
+#define MPI3_MAN9_MIN_OUTSTANDING_REQS      (1)
+#define MPI3_MAN9_MAX_OUTSTANDING_REQS      (65000)
+
+#define MPI3_MAN9_MIN_TARGET_CMDS           (0)
+#define MPI3_MAN9_MAX_TARGET_CMDS           (65535)
+
+#define MPI3_MAN9_MIN_SAS_TARGETS           (0)
+#define MPI3_MAN9_MAX_SAS_TARGETS           (65535)
+
+#define MPI3_MAN9_MIN_PCIE_TARGETS          (0)
+/* Max PCIe Targets is product specific */
+
+#define MPI3_MAN9_MIN_INITIATORS            (0)
+#define MPI3_MAN9_MAX_INITIATORS            (65535)
+
+#define MPI3_MAN9_MIN_ENCLOSURES            (0)
+#define MPI3_MAN9_MAX_ENCLOSURES            (65535)
+
+#define MPI3_MAN9_MIN_ENCLOSURE_PHYS        (0)
+/*
+ * Max Enclosure Phys depends on the largest enclosure
+ * i.e. the enclosure with the largest number of phys.
+ */
+
+#define MPI3_MAN9_MIN_EXPANDERS             (0)
+#define MPI3_MAN9_MAX_EXPANDERS             (65535)
+
+#define MPI3_MAN9_MIN_PCIE_SWITCHES         (0)
+/* Max PCIe Switches is product specific */
+
+typedef struct _MPI3_MAN_PAGE9 {
+    MPI3_CONFIG_PAGE_HEADER         Header;                                 /* 0x00 */
+    U8                              NumResources;                           /* 0x08 */
+    U8                              Reserved09;                             /* 0x09 */
+    U16                             Reserved0A;                             /* 0x0A */
+    U32                             Reserved0C;                             /* 0x0C */
+    U32                             Reserved10;                             /* 0x10 */
+    U32                             Reserved14;                             /* 0x14 */
+    U32                             Reserved18;                             /* 0x18 */
+    U32                             Reserved1C;                             /* 0x1C */
+    MPI3_MAN9_RSRC_ENTRY            Resource[MPI3_MAN9_RSRC_NUM_RESOURCES]; /* 0x20 */
+} MPI3_MAN_PAGE9, MPI3_POINTER PTR_MPI3_MAN_PAGE9,
+  Mpi3ManPage9_t, MPI3_POINTER pMpi3ManPage9_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_MAN9_PAGEVERSION                   (0x00)
+
+/*****************************************************************************
+ *              Manufacturing Page 10                                        *
+ ****************************************************************************/
+typedef struct _MPI3_MAN10_ISTWI_CTRLR_ENTRY {
+    U16     SlaveAddress;       /* 0x00 */
+    U16     Flags;              /* 0x02 */
+    U32     Reserved04;         /* 0x04 */
+} MPI3_MAN10_ISTWI_CTRLR_ENTRY, MPI3_POINTER PTR_MPI3_MAN10_ISTWI_CTRLR_ENTRY,
+  Mpi3Man10IstwiCtrlrEntry_t, MPI3_POINTER pMpi3Man10IstwiCtrlrEntry_t;
+
+/**** Defines for the Flags field ****/
+#define MPI3_MAN10_ISTWI_CTRLR_FLAGS_SLAVE_ENABLED          (0x0002)
+#define MPI3_MAN10_ISTWI_CTRLR_FLAGS_MASTER_ENABLED         (0x0001)
+
+#ifndef MPI3_MAN10_ISTWI_CTRLR_MAX
+#define MPI3_MAN10_ISTWI_CTRLR_MAX          (1)
+#endif  /* MPI3_MAN10_ISTWI_CTRLR_MAX */
+
+typedef struct _MPI3_MAN_PAGE10 {
+    MPI3_CONFIG_PAGE_HEADER         Header;                                         /* 0x00 */
+    U32                             Reserved08;                                     /* 0x08 */
+    U8                              NumISTWICtrl;                                   /* 0x0C */
+    U8                              Reserved0D[3];                                  /* 0x0D */
+    MPI3_MAN10_ISTWI_CTRLR_ENTRY    ISTWIController[MPI3_MAN10_ISTWI_CTRLR_MAX];    /* 0x10 */
+} MPI3_MAN_PAGE10, MPI3_POINTER PTR_MPI3_MAN_PAGE10,
+  Mpi3ManPage10_t, MPI3_POINTER pMpi3ManPage10_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_MAN10_PAGEVERSION                  (0x00)
+
+/*****************************************************************************
+ *              Manufacturing Page 11                                        *
+ ****************************************************************************/
+typedef struct _MPI3_MAN11_MUX_DEVICE_FORMAT {
+    U8      MaxChannel;         /* 0x00 */
+    U8      Reserved01[3];      /* 0x01 */
+    U32     Reserved04;         /* 0x04 */
+} MPI3_MAN11_MUX_DEVICE_FORMAT, MPI3_POINTER PTR_MPI3_MAN11_MUX_DEVICE_FORMAT,
+  Mpi3Man11MuxDeviceFormat_t, MPI3_POINTER pMpi3Man11MuxDeviceFormat_t;
+
+typedef struct _MPI3_MAN11_TEMP_SENSOR_DEVICE_FORMAT {
+    U8      Type;               /* 0x00 */
+    U8      Reserved01[3];      /* 0x01 */
+    U8      TempChannel[4];     /* 0x04 */
+} MPI3_MAN11_TEMP_SENSOR_DEVICE_FORMAT, MPI3_POINTER PTR_MPI3_MAN11_TEMP_SENSOR_DEVICE_FORMAT,
+  Mpi3Man11TempSensorDeviceFormat_t, MPI3_POINTER pMpi3Man11TempSensorDeviceFormat_t;
+
+/**** Defines for the Type field ****/
+#define MPI3_MAN11_TEMP_SENSOR_TYPE_MAX6654         (0x00)
+#define MPI3_MAN11_TEMP_SENSOR_TYPE_EMC1442         (0x01)
+#define MPI3_MAN11_TEMP_SENSOR_TYPE_ADT7476         (0x02)
+
+/**** Define for the TempChannel field ****/
+#define MPI3_MAN11_TEMP_SENSOR_CHANNEL_ENABLED      (0x01)
+
+typedef struct _MPI3_MAN11_SEEPROM_DEVICE_FORMAT {
+    U8      Size;               /* 0x00 */
+    U8      PageWriteSize;      /* 0x01 */
+    U16     Reserved02;         /* 0x02 */
+    U32     Reserved04;         /* 0x04 */
+} MPI3_MAN11_SEEPROM_DEVICE_FORMAT, MPI3_POINTER PTR_MPI3_MAN11_SEEPROM_DEVICE_FORMAT,
+  Mpi3Man11SeepromDeviceFormat_t, MPI3_POINTER pMpi3Man11SeepromDeviceFormat_t;
+
+/**** Defines for the Size field ****/
+#define MPI3_MAN11_SEEPROM_SIZE_1KBITS              (0x01)
+#define MPI3_MAN11_SEEPROM_SIZE_2KBITS              (0x02)
+#define MPI3_MAN11_SEEPROM_SIZE_4KBITS              (0x03)
+#define MPI3_MAN11_SEEPROM_SIZE_8KBITS              (0x04)
+#define MPI3_MAN11_SEEPROM_SIZE_16KBITS             (0x05)
+#define MPI3_MAN11_SEEPROM_SIZE_32KBITS             (0x06)
+#define MPI3_MAN11_SEEPROM_SIZE_64KBITS             (0x07)
+#define MPI3_MAN11_SEEPROM_SIZE_128KBITS            (0x08)
+
+typedef struct _MPI3_MAN11_DDR_SPD_DEVICE_FORMAT {
+    U8      Channel;            /* 0x00 */
+    U8      Reserved01[3];      /* 0x01 */
+    U32     Reserved04;         /* 0x04 */
+} MPI3_MAN11_DDR_SPD_DEVICE_FORMAT, MPI3_POINTER PTR_MPI3_MAN11_DDR_SPD_DEVICE_FORMAT,
+  Mpi3Man11DdrSpdDeviceFormat_t, MPI3_POINTER pMpi3Man11DdrSpdDeviceFormat_t;
+
+typedef struct _MPI3_MAN11_CABLE_MGMT_DEVICE_FORMAT {
+    U8      Type;               /* 0x00 */
+    U8      ReceptacleID;       /* 0x01 */
+    U16     Reserved02;         /* 0x02 */
+    U32     Reserved04;         /* 0x04 */
+} MPI3_MAN11_CABLE_MGMT_DEVICE_FORMAT, MPI3_POINTER PTR_MPI3_MAN11_CABLE_MGMT_DEVICE_FORMAT,
+  Mpi3Man11CableMgmtDeviceFormat_t, MPI3_POINTER pMpi3Man11CableMgmtDeviceFormat_t;
+
+/**** Defines for the Type field ****/
+#define MPI3_MAN11_CABLE_MGMT_TYPE_SFF_8636           (0x00)
+
+typedef struct _MPI3_MAN11_BKPLANE_SPEC_UBM_FORMAT {
+    U16     Flags;              /* 0x00 */
+    U16     Reserved02;         /* 0x02 */
+} MPI3_MAN11_BKPLANE_SPEC_UBM_FORMAT, MPI3_POINTER PTR_MPI3_MAN11_BKPLANE_SPEC_UBM_FORMAT,
+  Mpi3Man11BkplaneSpecUBMFormat, MPI3_POINTER pMpi3Man11BkplaneSpecUBMFormat;
+
+#define MPI3_MAN11_BKPLANE_UBM_FLAGS_REFCLK_POLICY_ALWAYS_ENABLED  (0x0200)
+#define MPI3_MAN11_BKPLANE_UBM_FLAGS_FORCE_POLLING                 (0x0100)
+#define MPI3_MAN11_BKPLANE_UBM_FLAGS_MAX_FRU_MASK                  (0x00F0)
+#define MPI3_MAN11_BKPLANE_UBM_FLAGS_MAX_FRU_SHIFT                 (4)
+#define MPI3_MAN11_BKPLANE_UBM_FLAGS_POLL_INTERVAL_MASK            (0x000F)
+#define MPI3_MAN11_BKPLANE_UBM_FLAGS_POLL_INTERVAL_SHIFT           (0)
+
+typedef struct _MPI3_MAN11_BKPLANE_SPEC_VPP_FORMAT {
+    U16     Flags;              /* 0x00 */
+    U16     Reserved02;         /* 0x02 */
+} MPI3_MAN11_BKPLANE_SPEC_VPP_FORMAT, MPI3_POINTER PTR_MPI3_MAN11_BKPLANE_SPEC_VPP_FORMAT,
+  Mpi3Man11BkplaneSpecVPPFormat, MPI3_POINTER pMpi3Man11BkplaneSpecVPPFormat;
+
+#define MPI3_MAN11_BKPLANE_VPP_FLAGS_REFCLK_POLICY_ALWAYS_ENABLED  (0x0040)
+#define MPI3_MAN11_BKPLANE_VPP_FLAGS_PRESENCE_DETECT_MASK          (0x0030)
+#define MPI3_MAN11_BKPLANE_VPP_FLAGS_PRESENCE_DETECT_GPIO          (0x0000)
+#define MPI3_MAN11_BKPLANE_VPP_FLAGS_PRESENCE_DETECT_REG           (0x0010)
+#define MPI3_MAN11_BKPLANE_VPP_FLAGS_POLL_INTERVAL_MASK            (0x000F)
+#define MPI3_MAN11_BKPLANE_VPP_FLAGS_POLL_INTERVAL_SHIFT           (0)
+
+
+typedef union _MPI3_MAN11_BKPLANE_SPEC_FORMAT {
+    MPI3_MAN11_BKPLANE_SPEC_UBM_FORMAT     Ubm;
+    MPI3_MAN11_BKPLANE_SPEC_VPP_FORMAT     Vpp;
+} MPI3_MAN11_BKPLANE_SPEC_FORMAT, MPI3_POINTER PTR_MPI3_MAN11_BKPLANE_SPEC_FORMAT,
+  Mpi3Man11BkplaneSpecFormat, MPI3_POINTER pMpi3Man11BkplaneSpecFormat;
+
+typedef struct _MPI3_MAN11_BKPLANE_MGMT_DEVICE_FORMAT {
+    U8                                     Type;                   /* 0x00 */
+    U8                                     ReceptacleID;           /* 0x01 */
+    U16                                    Reserved02;             /* 0x02 */
+    MPI3_MAN11_BKPLANE_SPEC_FORMAT         BackplaneMgmtSpecific;  /* 0x04 */
+} MPI3_MAN11_BKPLANE_MGMT_DEVICE_FORMAT, MPI3_POINTER PTR_MPI3_MAN11_BKPLANE_MGMT_DEVICE_FORMAT,
+  Mpi3Man11BkplaneMgmtDeviceFormat_t, MPI3_POINTER pMpi3Man11BkplaneMgmtDeviceFormat_t;
+
+/**** Defines for the Type field ****/
+#define MPI3_MAN11_BKPLANE_MGMT_TYPE_UBM            (0x00)
+#define MPI3_MAN11_BKPLANE_MGMT_TYPE_VPP            (0x01)
+
+typedef struct _MPI3_MAN11_GAS_GAUGE_DEVICE_FORMAT {
+    U8      Type;               /* 0x00 */
+    U8      Reserved01[3];      /* 0x01 */
+    U32     Reserved04;         /* 0x04 */
+} MPI3_MAN11_GAS_GAUGE_DEVICE_FORMAT, MPI3_POINTER PTR_MPI3_MAN11_GAS_GAUGE_DEVICE_FORMAT,
+  Mpi3Man11GasGaugeDeviceFormat_t, MPI3_POINTER pMpi3Man11GasGaugeDeviceFormat_t;
+
+/**** Defines for the Type field ****/
+#define MPI3_MAN11_GAS_GAUGE_TYPE_STANDARD          (0x00)
+
+typedef union _MPI3_MAN11_DEVICE_SPECIFIC_FORMAT {
+    MPI3_MAN11_MUX_DEVICE_FORMAT            Mux;
+    MPI3_MAN11_TEMP_SENSOR_DEVICE_FORMAT    TempSensor;
+    MPI3_MAN11_SEEPROM_DEVICE_FORMAT        Seeprom;
+    MPI3_MAN11_DDR_SPD_DEVICE_FORMAT        DdrSpd;
+    MPI3_MAN11_CABLE_MGMT_DEVICE_FORMAT     CableMgmt;
+    MPI3_MAN11_BKPLANE_MGMT_DEVICE_FORMAT   BkplaneMgmt;
+    MPI3_MAN11_GAS_GAUGE_DEVICE_FORMAT      GasGauge;
+    U32                                     Words[2];
+} MPI3_MAN11_DEVICE_SPECIFIC_FORMAT, MPI3_POINTER PTR_MPI3_MAN11_DEVICE_SPECIFIC_FORMAT,
+  Mpi3Man11DeviceSpecificFormat_t, MPI3_POINTER pMpi3Man11DeviceSpecificFormat_t;
+
+typedef struct _MPI3_MAN11_ISTWI_DEVICE_FORMAT {
+    U8                                  DeviceType;         /* 0x00 */
+    U8                                  Controller;         /* 0x01 */
+    U8                                  Reserved02;         /* 0x02 */
+    U8                                  Flags;              /* 0x03 */
+    U16                                 DeviceAddress;      /* 0x04 */
+    U8                                  MuxChannel;         /* 0x06 */
+    U8                                  MuxIndex;           /* 0x07 */
+    MPI3_MAN11_DEVICE_SPECIFIC_FORMAT   DeviceSpecific;     /* 0x08 */
+} MPI3_MAN11_ISTWI_DEVICE_FORMAT, MPI3_POINTER PTR_MPI3_MAN11_ISTWI_DEVICE_FORMAT,
+  Mpi3Man11IstwiDeviceFormat_t, MPI3_POINTER pMpi3Man11IstwiDeviceFormat_t;
+
+/**** Defines for the DeviceType field ****/
+#define MPI3_MAN11_ISTWI_DEVTYPE_MUX                  (0x00)
+#define MPI3_MAN11_ISTWI_DEVTYPE_TEMP_SENSOR          (0x01)
+#define MPI3_MAN11_ISTWI_DEVTYPE_SEEPROM              (0x02)
+#define MPI3_MAN11_ISTWI_DEVTYPE_DDR_SPD              (0x03)
+#define MPI3_MAN11_ISTWI_DEVTYPE_CABLE_MGMT           (0x04)
+#define MPI3_MAN11_ISTWI_DEVTYPE_BACKPLANE_MGMT       (0x05)
+#define MPI3_MAN11_ISTWI_DEVTYPE_GAS_GAUGE            (0x06)
+
+/**** Defines for the Flags field ****/
+#define MPI3_MAN11_ISTWI_FLAGS_MUX_PRESENT            (0x01)
+#define MPI3_MAN11_ISTWI_FLAGS_BUS_SPEED_MASK         (0x06)
+#define MPI3_MAN11_ISTWI_FLAGS_BUS_SPEED_100KHZ       (0x00)
+#define MPI3_MAN11_ISTWI_FLAGS_BUS_SPEED_400KHZ       (0x02)
+
+#ifndef MPI3_MAN11_ISTWI_DEVICE_MAX
+#define MPI3_MAN11_ISTWI_DEVICE_MAX             (1)
+#endif  /* MPI3_MAN11_ISTWI_DEVICE_MAX */
+
+typedef struct _MPI3_MAN_PAGE11 {
+    MPI3_CONFIG_PAGE_HEADER         Header;                                     /* 0x00 */
+    U32                             Reserved08;                                 /* 0x08 */
+    U8                              NumISTWIDev;                                /* 0x0C */
+    U8                              Reserved0D[3];                              /* 0x0D */
+    MPI3_MAN11_ISTWI_DEVICE_FORMAT  ISTWIDevice[MPI3_MAN11_ISTWI_DEVICE_MAX];   /* 0x10 */
+} MPI3_MAN_PAGE11, MPI3_POINTER PTR_MPI3_MAN_PAGE11,
+  Mpi3ManPage11_t, MPI3_POINTER pMpi3ManPage11_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_MAN11_PAGEVERSION                  (0x00)
+
+
+/*****************************************************************************
+ *              Manufacturing Page 12                                        *
+ ****************************************************************************/
+#ifndef MPI3_MAN12_NUM_SGPIO_MAX
+#define MPI3_MAN12_NUM_SGPIO_MAX                                     (1)
+#endif  /* MPI3_MAN12_NUM_SGPIO_MAX */
+
+typedef struct _MPI3_MAN12_SGPIO_INFO {
+    U8                              SlotCount;                                  /* 0x00 */
+    U8                              Reserved01[3];                              /* 0x01 */
+    U32                             Reserved04;                                 /* 0x04 */
+    U8                              PhyOrder[32];                               /* 0x08 */
+} MPI3_MAN12_SGPIO_INFO, MPI3_POINTER PTR_MPI3_MAN12_SGPIO_INFO,
+  Mpi3Man12SGPIOInfo, MPI3_POINTER pMpi3Man12SGPIOInfo;
+
+typedef struct _MPI3_MAN_PAGE12 {
+    MPI3_CONFIG_PAGE_HEADER         Header;                                     /* 0x00 */
+    U32                             Flags;                                      /* 0x08 */
+    U32                             SClockFreq;                                 /* 0x0C */
+    U32                             ActivityModulation;                         /* 0x10 */
+    U8                              NumSGPIO;                                   /* 0x14 */
+    U8                              Reserved15[3];                              /* 0x15 */
+    U32                             Reserved18;                                 /* 0x18 */
+    U32                             Reserved1C;                                 /* 0x1C */
+    U32                             Pattern[8];                                 /* 0x20 */
+    MPI3_MAN12_SGPIO_INFO           SGPIOInfo[MPI3_MAN12_NUM_SGPIO_MAX];        /* 0x40 */   /* variable length */
+} MPI3_MAN_PAGE12, MPI3_POINTER PTR_MPI3_MAN_PAGE12,
+  Mpi3ManPage12_t, MPI3_POINTER pMpi3ManPage12_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_MAN12_PAGEVERSION                                       (0x00)
+
+/**** Defines for the Flags field ****/
+#define MPI3_MAN12_FLAGS_ERROR_PRESENCE_ENABLED                      (0x0400)
+#define MPI3_MAN12_FLAGS_ACTIVITY_INVERT_ENABLED                     (0x0200)
+#define MPI3_MAN12_FLAGS_GROUP_ID_DISABLED                           (0x0100)
+#define MPI3_MAN12_FLAGS_SIO_CLK_FILTER_ENABLED                      (0x0004)
+#define MPI3_MAN12_FLAGS_SCLOCK_SLOAD_TYPE_MASK                      (0x0002)
+#define MPI3_MAN12_FLAGS_SCLOCK_SLOAD_TYPE_PUSH_PULL                 (0x0000)
+#define MPI3_MAN12_FLAGS_SCLOCK_SLOAD_TYPE_OPEN_DRAIN                (0x0002)
+#define MPI3_MAN12_FLAGS_SDATAOUT_TYPE_MASK                          (0x0001)
+#define MPI3_MAN12_FLAGS_SDATAOUT_TYPE_PUSH_PULL                     (0x0000)
+#define MPI3_MAN12_FLAGS_SDATAOUT_TYPE_OPEN_DRAIN                    (0x0001)
+
+/**** Defines for the SioClkFreq field ****/
+#define MPI3_MAN12_SIO_CLK_FREQ_MIN                                  (32)        /* 32 Hz min SIO Clk Freq */
+#define MPI3_MAN12_SIO_CLK_FREQ_MAX                                  (100000)    /* 100 KHz max SIO Clk Freq */
+
+/**** Defines for the ActivityModulation field ****/
+#define MPI3_MAN12_ACTIVITY_MODULATION_FORCE_OFF_MASK                (0x0000F000)
+#define MPI3_MAN12_ACTIVITY_MODULATION_FORCE_OFF_SHIFT               (12)
+#define MPI3_MAN12_ACTIVITY_MODULATION_MAX_ON_MASK                   (0x00000F00)
+#define MPI3_MAN12_ACTIVITY_MODULATION_MAX_ON_SHIFT                  (8)
+#define MPI3_MAN12_ACTIVITY_MODULATION_STRETCH_OFF_MASK              (0x000000F0)
+#define MPI3_MAN12_ACTIVITY_MODULATION_STRETCH_OFF_SHIFT             (4)
+#define MPI3_MAN12_ACTIVITY_MODULATION_STRETCH_ON_MASK               (0x0000000F)
+#define MPI3_MAN12_ACTIVITY_MODULATION_STRETCH_ON_SHIFT              (0)
+
+/*** Defines for the Pattern field ****/
+#define MPI3_MAN12_PATTERN_RATE_MASK                                 (0xE0000000)
+#define MPI3_MAN12_PATTERN_RATE_2_HZ                                 (0x00000000)
+#define MPI3_MAN12_PATTERN_RATE_4_HZ                                 (0x20000000)
+#define MPI3_MAN12_PATTERN_RATE_8_HZ                                 (0x40000000)
+#define MPI3_MAN12_PATTERN_RATE_16_HZ                                (0x60000000)
+#define MPI3_MAN12_PATTERN_RATE_10_HZ                                (0x80000000)
+#define MPI3_MAN12_PATTERN_RATE_20_HZ                                (0xA0000000)
+#define MPI3_MAN12_PATTERN_RATE_40_HZ                                (0xC0000000)
+#define MPI3_MAN12_PATTERN_LENGTH_MASK                               (0x1F000000)
+#define MPI3_MAN12_PATTERN_LENGTH_SHIFT                              (24)
+#define MPI3_MAN12_PATTERN_BIT_PATTERN_MASK                          (0x00FFFFFF)
+#define MPI3_MAN12_PATTERN_BIT_PATTERN_SHIFT                         (0)
+
+
+/*****************************************************************************
+ *              Manufacturing Page 13                                        *
+ ****************************************************************************/
+
+#ifndef MPI3_MAN13_NUM_TRANSLATION_MAX
+#define MPI3_MAN13_NUM_TRANSLATION_MAX                               (1)
+#endif  /* MPI3_MAN13_NUM_TRANSLATION_MAX */
+
+typedef struct _MPI3_MAN13_TRANSLATION_INFO {
+    U32                             SlotStatus;                                        /* 0x00 */
+    U32                             Mask;                                              /* 0x04 */
+    U8                              Activity;                                          /* 0x08 */
+    U8                              Locate;                                            /* 0x09 */
+    U8                              Error;                                             /* 0x0A */
+    U8                              Reserved0B;                                        /* 0x0B */
+} MPI3_MAN13_TRANSLATION_INFO, MPI3_POINTER PTR_MPI3_MAN13_TRANSLATION_INFO,
+  Mpi3Man13TranslationInfo, MPI3_POINTER pMpi3Man13TranslationInfo;
+
+/**** Defines for the SlotStatus field ****/
+#define MPI3_MAN13_TRANSLATION_SLOTSTATUS_FAULT                     (0x20000000)
+#define MPI3_MAN13_TRANSLATION_SLOTSTATUS_DEVICE_OFF                (0x10000000)
+#define MPI3_MAN13_TRANSLATION_SLOTSTATUS_DEVICE_ACTIVITY           (0x00800000)
+#define MPI3_MAN13_TRANSLATION_SLOTSTATUS_DO_NOT_REMOVE             (0x00400000)
+#define MPI3_MAN13_TRANSLATION_SLOTSTATUS_DEVICE_MISSING            (0x00100000)
+#define MPI3_MAN13_TRANSLATION_SLOTSTATUS_INSERT                    (0x00080000)
+#define MPI3_MAN13_TRANSLATION_SLOTSTATUS_REMOVAL                   (0x00040000)
+#define MPI3_MAN13_TRANSLATION_SLOTSTATUS_IDENTIFY                  (0x00020000)
+#define MPI3_MAN13_TRANSLATION_SLOTSTATUS_OK                        (0x00008000)
+#define MPI3_MAN13_TRANSLATION_SLOTSTATUS_RESERVED_DEVICE           (0x00004000)
+#define MPI3_MAN13_TRANSLATION_SLOTSTATUS_HOT_SPARE                 (0x00002000)
+#define MPI3_MAN13_TRANSLATION_SLOTSTATUS_CONSISTENCY_CHECK         (0x00001000)
+#define MPI3_MAN13_TRANSLATION_SLOTSTATUS_IN_CRITICAL_ARRAY         (0x00000800)
+#define MPI3_MAN13_TRANSLATION_SLOTSTATUS_IN_FAILED_ARRAY           (0x00000400)
+#define MPI3_MAN13_TRANSLATION_SLOTSTATUS_REBUILD_REMAP             (0x00000200)
+#define MPI3_MAN13_TRANSLATION_SLOTSTATUS_REBUILD_REMAP_ABORT       (0x00000100)
+#define MPI3_MAN13_TRANSLATION_SLOTSTATUS_PREDICTED_FAILURE         (0x00000040)
+
+/**** Defines for the Mask field - use MPI3_MAN13_TRANSLATION_SLOTSTATUS_ defines ****/
+
+/**** Defines for the Activity, Locate, and Error fields ****/
+#define MPI3_MAN13_BLINK_PATTERN_FORCE_OFF                          (0x00)
+#define MPI3_MAN13_BLINK_PATTERN_FORCE_ON                           (0x01)
+#define MPI3_MAN13_BLINK_PATTERN_PATTERN_0                          (0x02)
+#define MPI3_MAN13_BLINK_PATTERN_PATTERN_1                          (0x03)
+#define MPI3_MAN13_BLINK_PATTERN_PATTERN_2                          (0x04)
+#define MPI3_MAN13_BLINK_PATTERN_PATTERN_3                          (0x05)
+#define MPI3_MAN13_BLINK_PATTERN_PATTERN_4                          (0x06)
+#define MPI3_MAN13_BLINK_PATTERN_PATTERN_5                          (0x07)
+#define MPI3_MAN13_BLINK_PATTERN_PATTERN_6                          (0x08)
+#define MPI3_MAN13_BLINK_PATTERN_PATTERN_7                          (0x09)
+#define MPI3_MAN13_BLINK_PATTERN_ACTIVITY                           (0x0A)
+#define MPI3_MAN13_BLINK_PATTERN_ACTIVITY_TRAIL                     (0x0B)
+
+typedef struct _MPI3_MAN_PAGE13 {
+    MPI3_CONFIG_PAGE_HEADER         Header;                                            /* 0x00 */
+    U8                              NumTrans;                                          /* 0x08 */
+    U8                              Reserved09[3];                                     /* 0x09 */
+    U32                             Reserved0C;                                        /* 0x0C */
+    MPI3_MAN13_TRANSLATION_INFO     Translation[MPI3_MAN13_NUM_TRANSLATION_MAX];       /* 0x10 */  /* variable length */
+} MPI3_MAN_PAGE13, MPI3_POINTER PTR_MPI3_MAN_PAGE13,
+  Mpi3ManPage13_t, MPI3_POINTER pMpi3ManPage13_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_MAN13_PAGEVERSION                                       (0x00)
+
+/*****************************************************************************
+ *              Manufacturing Page 14                                        *
+ ****************************************************************************/
+
+typedef struct _MPI3_MAN_PAGE14 {
+    MPI3_CONFIG_PAGE_HEADER         Header;                                            /* 0x00 */
+    U16                             Flags;                                             /* 0x08 */
+    U16                             Reserved0A;                                        /* 0x0A */
+    U8                              NumSlotGroups;                                     /* 0x0C */
+    U8                              NumSlots;                                          /* 0x0D */
+    U16                             MaxCertChainLength;                                /* 0x0E */
+    U32                             SealedSlots;                                       /* 0x10 */
+} MPI3_MAN_PAGE14, MPI3_POINTER PTR_MPI3_MAN_PAGE14,
+  Mpi3ManPage14_t, MPI3_POINTER pMpi3ManPage14_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_MAN14_PAGEVERSION                                       (0x00)
+
+/**** Defines for the Flags field ****/
+#define MPI3_MAN14_FLAGS_AUTH_SESSION_REQ                            (0x01)
+#define MPI3_MAN14_FLAGS_AUTH_API_MASK                               (0x0E)
+#define MPI3_MAN14_FLAGS_AUTH_API_NONE                               (0x00)
+#define MPI3_MAN14_FLAGS_AUTH_API_CEREBUS                            (0x02)
+#define MPI3_MAN14_FLAGS_AUTH_API_DMTF_PMCI                          (0x04)
+
+/*****************************************************************************
+ *              Manufacturing Page 15                                        *
+ ****************************************************************************/
+
+#ifndef MPI3_MAN15_VERSION_RECORD_MAX
+#define MPI3_MAN15_VERSION_RECORD_MAX      1
+#endif  /* MPI3_MAN15_VERSION_RECORD_MAX */
+
+typedef struct _MPI3_MAN15_VERSION_RECORD {
+    U16                             SPDMVersion;                                       /* 0x00 */
+    U16                             Reserved02;                                        /* 0x02 */
+} MPI3_MAN15_VERSION_RECORD, MPI3_POINTER PTR_MPI3_MAN15_VERSION_RECORD,
+  Mpi3Man15VersionRecord_t, MPI3_POINTER pMpi3Man15VersionRecord_t;
+
+typedef struct _MPI3_MAN_PAGE15 {
+    MPI3_CONFIG_PAGE_HEADER         Header;                                            /* 0x00 */
+    U8                              NumVersionRecords;                                 /* 0x08 */
+    U8                              Reserved09[3];                                     /* 0x09 */
+    U32                             Reserved0C;                                        /* 0x0C */
+    MPI3_MAN15_VERSION_RECORD       VersionRecord[MPI3_MAN15_VERSION_RECORD_MAX];      /* 0x10 */
+} MPI3_MAN_PAGE15, MPI3_POINTER PTR_MPI3_MAN_PAGE15,
+  Mpi3ManPage15_t, MPI3_POINTER pMpi3ManPage15_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_MAN15_PAGEVERSION                                       (0x00)
+
+/*****************************************************************************
+ *              Manufacturing Page 16                                        *
+ ****************************************************************************/
+
+#ifndef MPI3_MAN16_CERT_ALGO_MAX
+#define MPI3_MAN16_CERT_ALGO_MAX      1
+#endif  /* MPI3_MAN16_CERT_ALGO_MAX */
+
+typedef struct _MPI3_MAN16_CERTIFICATE_ALGORITHM {
+    U8                                   SlotGroup;                                    /* 0x00 */
+    U8                                   Reserved01[3];                                /* 0x01 */
+    U32                                  BaseAsymAlgo;                                 /* 0x04 */
+    U32                                  BaseHashAlgo;                                 /* 0x08 */
+    U32                                  Reserved0C[3];                                /* 0x0C */
+} MPI3_MAN16_CERTIFICATE_ALGORITHM, MPI3_POINTER PTR_MPI3_MAN16_CERTIFICATE_ALGORITHM,
+  Mpi3Man16CertificateAlgorithm_t, MPI3_POINTER pMpi3Man16CertificateAlgorithm_t;
+
+typedef struct _MPI3_MAN_PAGE16 {
+    MPI3_CONFIG_PAGE_HEADER              Header;                                         /* 0x00 */
+    U32                                  Reserved08;                                     /* 0x08 */
+    U8                                   NumCertAlgos;                                   /* 0x0C */
+    U8                                   Reserved0D[3];                                  /* 0x0D */
+    MPI3_MAN16_CERTIFICATE_ALGORITHM     CertificateAlgorithm[MPI3_MAN16_CERT_ALGO_MAX]; /* 0x10 */
+} MPI3_MAN_PAGE16, MPI3_POINTER PTR_MPI3_MAN_PAGE16,
+  Mpi3ManPage16_t, MPI3_POINTER pMpi3ManPage16_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_MAN16_PAGEVERSION                                       (0x00)
+
+/*****************************************************************************
+ *              Manufacturing Page 17                                        *
+ ****************************************************************************/
+
+#ifndef MPI3_MAN17_HASH_ALGORITHM_MAX
+#define MPI3_MAN17_HASH_ALGORITHM_MAX      1
+#endif  /* MPI3_MAN17_HASH_ALGORITHM_MAX */
+
+typedef struct _MPI3_MAN17_HASH_ALGORITHM {
+    U8                              MeasSpecification;                                 /* 0x00 */
+    U8                              Reserved01[3];                                     /* 0x01 */
+    U32                             MeasurementHashAlgo;                               /* 0x04 */
+    U32                             Reserved08[2];                                     /* 0x08 */
+} MPI3_MAN17_HASH_ALGORITHM, MPI3_POINTER PTR_MPI3_MAN17_HASH_ALGORITHM,
+  Mpi3Man17HashAlgorithm_t, MPI3_POINTER pMpi3Man17HashAlgorithm_t;
+
+typedef struct _MPI3_MAN_PAGE17 {
+    MPI3_CONFIG_PAGE_HEADER         Header;                                            /* 0x00 */
+    U32                             Reserved08;                                        /* 0x08 */
+    U8                              NumHashAlgos;                                      /* 0x0C */
+    U8                              Reserved0D[3];                                     /* 0x0D */
+    MPI3_MAN17_HASH_ALGORITHM       HashAlgorithm[MPI3_MAN17_HASH_ALGORITHM_MAX];      /* 0x10 */
+} MPI3_MAN_PAGE17, MPI3_POINTER PTR_MPI3_MAN_PAGE17,
+  Mpi3ManPage17_t, MPI3_POINTER pMpi3ManPage17_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_MAN17_PAGEVERSION                                       (0x00)
+
+/*****************************************************************************
+ *              Manufacturing Page 20                                        *
+ ****************************************************************************/
+
+typedef struct _MPI3_MAN_PAGE20 {
+    MPI3_CONFIG_PAGE_HEADER         Header;                                            /* 0x00 */
+    U32                             Reserved08;                                        /* 0x08 */
+    U32                             NonpremiumFeatures;                                /* 0x0C */
+    U8                              AllowedPersonalities;                              /* 0x10 */
+    U8                              Reserved11[3];                                     /* 0x11 */
+} MPI3_MAN_PAGE20, MPI3_POINTER PTR_MPI3_MAN_PAGE20,
+  Mpi3ManPage20_t, MPI3_POINTER pMpi3ManPage20_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_MAN20_PAGEVERSION                                       (0x00)
+
+/**** Defines for the AllowedPersonalities field ****/
+#define MPI3_MAN20_ALLOWEDPERSON_RAID_MASK                           (0x02)
+#define MPI3_MAN20_ALLOWEDPERSON_RAID_ALLOWED                        (0x02)
+#define MPI3_MAN20_ALLOWEDPERSON_RAID_NOT_ALLOWED                    (0x00)
+#define MPI3_MAN20_ALLOWEDPERSON_EHBA_MASK                           (0x01)
+#define MPI3_MAN20_ALLOWEDPERSON_EHBA_ALLOWED                        (0x01)
+#define MPI3_MAN20_ALLOWEDPERSON_EHBA_NOT_ALLOWED                    (0x00)
+
+/**** Defines for the NonpremuimFeatures field ****/
+#define MPI3_MAN20_NONPREMUIM_DISABLE_PD_DEGRADED_MASK               (0x01)
+#define MPI3_MAN20_NONPREMUIM_DISABLE_PD_DEGRADED_ENABLED            (0x00)
+#define MPI3_MAN20_NONPREMUIM_DISABLE_PD_DEGRADED_DISABLED           (0x01)
+
+/*****************************************************************************
+ *              Manufacturing Page 21                                        *
+ ****************************************************************************/
+
+typedef struct _MPI3_MAN_PAGE21 {
+    MPI3_CONFIG_PAGE_HEADER         Header;                                            /* 0x00 */
+    U32                             Reserved08;                                        /* 0x08 */
+    U32                             Flags;                                             /* 0x0C */
+} MPI3_MAN_PAGE21, MPI3_POINTER PTR_MPI3_MAN_PAGE21,
+  Mpi3ManPage21_t, MPI3_POINTER pMpi3ManPage21_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_MAN21_PAGEVERSION                                       (0x00)
+
+/**** Defines for the Flags field ****/
+#define MPI3_MAN21_FLAGS_HOST_METADATA_CAPABILITY_MASK               (0x80)
+#define MPI3_MAN21_FLAGS_HOST_METADATA_CAPABILITY_ENABLED            (0x80)
+#define MPI3_MAN21_FLAGS_HOST_METADATA_CAPABILITY_DISABLED           (0x00)
+#define MPI3_MAN21_FLAGS_UNCERTIFIED_DRIVES_MASK                     (0x60)
+#define MPI3_MAN21_FLAGS_UNCERTIFIED_DRIVES_BLOCK                    (0x00)
+#define MPI3_MAN21_FLAGS_UNCERTIFIED_DRIVES_ALLOW                    (0x20)
+#define MPI3_MAN21_FLAGS_UNCERTIFIED_DRIVES_WARN                     (0x40)
+#define MPI3_MAN21_FLAGS_BLOCK_SSD_WR_CACHE_CHANGE_MASK              (0x08)
+#define MPI3_MAN21_FLAGS_BLOCK_SSD_WR_CACHE_CHANGE_ALLOW             (0x00)
+#define MPI3_MAN21_FLAGS_BLOCK_SSD_WR_CACHE_CHANGE_PREVENT           (0x08)
+#define MPI3_MAN21_FLAGS_SES_VPD_ASSOC_MASK                          (0x01)
+#define MPI3_MAN21_FLAGS_SES_VPD_ASSOC_DEFAULT                       (0x00)
+#define MPI3_MAN21_FLAGS_SES_VPD_ASSOC_OEM_SPECIFIC                  (0x01)
+
+/*****************************************************************************
+ *              Manufacturing Pages 32-63 (ProductSpecific)                  *
+ ****************************************************************************/
+#ifndef MPI3_MAN_PROD_SPECIFIC_MAX
+#define MPI3_MAN_PROD_SPECIFIC_MAX                      (1)
+#endif  /* MPI3_MAN_PROD_SPECIFIC_MAX */
+
+typedef struct _MPI3_MAN_PAGE_PRODUCT_SPECIFIC {
+    MPI3_CONFIG_PAGE_HEADER         Header;                                            /* 0x00 */
+    U32                             ProductSpecificInfo[MPI3_MAN_PROD_SPECIFIC_MAX];   /* 0x08 */  /* variable length array */
+} MPI3_MAN_PAGE_PRODUCT_SPECIFIC, MPI3_POINTER PTR_MPI3_MAN_PAGE_PRODUCT_SPECIFIC,
+  Mpi3ManPageProductSpecific_t, MPI3_POINTER pMpi3ManPageProductSpecific_t;
+
+/*****************************************************************************
+ *              IO Unit Configuration Pages                                  *
+ ****************************************************************************/
+
+/*****************************************************************************
+ *              IO Unit Page 0                                               *
+ ****************************************************************************/
+typedef struct _MPI3_IO_UNIT_PAGE0 {
+    MPI3_CONFIG_PAGE_HEADER         Header;                     /* 0x00 */
+    U64                             UniqueValue;                /* 0x08 */
+    U32                             NvdataVersionDefault;       /* 0x10 */
+    U32                             NvdataVersionPersistent;    /* 0x14 */
+} MPI3_IO_UNIT_PAGE0, MPI3_POINTER PTR_MPI3_IO_UNIT_PAGE0,
+  Mpi3IOUnitPage0_t, MPI3_POINTER pMpi3IOUnitPage0_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_IOUNIT0_PAGEVERSION                (0x00)
+
+/*****************************************************************************
+ *              IO Unit Page 1                                               *
+ ****************************************************************************/
+typedef struct _MPI3_IO_UNIT_PAGE1 {
+    MPI3_CONFIG_PAGE_HEADER         Header;                     /* 0x00 */
+    U32                             Flags;                      /* 0x08 */
+    U8                              DMDIoDelay;                 /* 0x0C */
+    U8                              DMDReportPCIe;              /* 0x0D */
+    U8                              DMDReportSATA;              /* 0x0E */
+    U8                              DMDReportSAS;               /* 0x0F */
+} MPI3_IO_UNIT_PAGE1, MPI3_POINTER PTR_MPI3_IO_UNIT_PAGE1,
+  Mpi3IOUnitPage1_t, MPI3_POINTER pMpi3IOUnitPage1_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_IOUNIT1_PAGEVERSION                (0x00)
+
+/**** Defines for the Flags field ****/
+#define MPI3_IOUNIT1_FLAGS_NVME_WRITE_CACHE_MASK                   (0x00000030)
+#define MPI3_IOUNIT1_FLAGS_NVME_WRITE_CACHE_ENABLE                 (0x00000000)
+#define MPI3_IOUNIT1_FLAGS_NVME_WRITE_CACHE_DISABLE                (0x00000010)
+#define MPI3_IOUNIT1_FLAGS_NVME_WRITE_CACHE_NO_MODIFY              (0x00000020)
+#define MPI3_IOUNIT1_FLAGS_ATA_SECURITY_FREEZE_LOCK                (0x00000008)
+#define MPI3_IOUNIT1_FLAGS_WRITE_SAME_BUFFER                       (0x00000004)
+#define MPI3_IOUNIT1_FLAGS_SATA_WRITE_CACHE_MASK                   (0x00000003)
+#define MPI3_IOUNIT1_FLAGS_SATA_WRITE_CACHE_ENABLE                 (0x00000000)
+#define MPI3_IOUNIT1_FLAGS_SATA_WRITE_CACHE_DISABLE                (0x00000001)
+#define MPI3_IOUNIT1_FLAGS_SATA_WRITE_CACHE_UNCHANGED              (0x00000002)
+
+/**** Defines for the DMDReport PCIe/SATA/SAS fields ****/
+#define MPI3_IOUNIT1_DMD_REPORT_DELAY_TIME_MASK                    (0x7F)
+#define MPI3_IOUNIT1_DMD_REPORT_UNIT_16_SEC                        (0x80)
+
+/*****************************************************************************
+ *              IO Unit Page 2                                               *
+ ****************************************************************************/
+#ifndef MPI3_IO_UNIT2_GPIO_VAL_MAX
+#define MPI3_IO_UNIT2_GPIO_VAL_MAX      (1)
+#endif  /* MPI3_IO_UNIT2_GPIO_VAL_MAX */
+
+typedef struct _MPI3_IO_UNIT_PAGE2 {
+    MPI3_CONFIG_PAGE_HEADER         Header;                                 /* 0x00 */
+    U8                              GPIOCount;                              /* 0x08 */
+    U8                              Reserved09[3];                          /* 0x09 */
+    U16                             GPIOVal[MPI3_IO_UNIT2_GPIO_VAL_MAX];    /* 0x0C */
+} MPI3_IO_UNIT_PAGE2, MPI3_POINTER PTR_MPI3_IO_UNIT_PAGE2,
+  Mpi3IOUnitPage2_t, MPI3_POINTER pMpi3IOUnitPage2_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_IOUNIT2_PAGEVERSION                (0x00)
+
+/**** Define for the GPIOVal field ****/
+#define MPI3_IOUNIT2_GPIO_FUNCTION_MASK         (0xFFFC)
+#define MPI3_IOUNIT2_GPIO_FUNCTION_SHIFT        (2)
+#define MPI3_IOUNIT2_GPIO_SETTING_MASK          (0x0001)
+#define MPI3_IOUNIT2_GPIO_SETTING_OFF           (0x0000)
+#define MPI3_IOUNIT2_GPIO_SETTING_ON            (0x0001)
+
+/*****************************************************************************
+ *              IO Unit Page 3                                               *
+ ****************************************************************************/
+
+typedef struct _MPI3_IO_UNIT3_SENSOR {
+    U16             Flags;                                      /* 0x00 */
+    U16             Reserved02;                                 /* 0x02 */
+    U16             Threshold[4];                               /* 0x04 */
+    U32             Reserved0C;                                 /* 0x0C */
+    U32             Reserved10;                                 /* 0x10 */
+    U32             Reserved14;                                 /* 0x14 */
+} MPI3_IO_UNIT3_SENSOR, MPI3_POINTER PTR_MPI3_IO_UNIT3_SENSOR,
+  Mpi3IOUnit3Sensor_t, MPI3_POINTER pMpi3IOUnit3Sensor_t;
+
+/**** Defines for the Flags field ****/
+#define MPI3_IOUNIT3_SENSOR_FLAGS_T3_ENABLE         (0x0008)
+#define MPI3_IOUNIT3_SENSOR_FLAGS_T2_ENABLE         (0x0004)
+#define MPI3_IOUNIT3_SENSOR_FLAGS_T1_ENABLE         (0x0002)
+#define MPI3_IOUNIT3_SENSOR_FLAGS_T0_ENABLE         (0x0001)
+
+#ifndef MPI3_IO_UNIT3_SENSOR_MAX
+#define MPI3_IO_UNIT3_SENSOR_MAX        (1)
+#endif  /* MPI3_IO_UNIT3_SENSOR_MAX */
+
+typedef struct _MPI3_IO_UNIT_PAGE3 {
+    MPI3_CONFIG_PAGE_HEADER         Header;                             /* 0x00 */
+    U32                             Reserved08;                         /* 0x08 */
+    U8                              NumSensors;                         /* 0x0C */
+    U8                              PollingInterval;                    /* 0x0D */
+    U16                             Reserved0E;                         /* 0x0E */
+    MPI3_IO_UNIT3_SENSOR            Sensor[MPI3_IO_UNIT3_SENSOR_MAX];   /* 0x10 */
+} MPI3_IO_UNIT_PAGE3, MPI3_POINTER PTR_MPI3_IO_UNIT_PAGE3,
+  Mpi3IOUnitPage3_t, MPI3_POINTER pMpi3IOUnitPage3_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_IOUNIT3_PAGEVERSION                (0x00)
+
+/*****************************************************************************
+ *              IO Unit Page 4                                               *
+ ****************************************************************************/
+typedef struct _MPI3_IO_UNIT4_SENSOR {
+    U16             CurrentTemperature;     /* 0x00 */
+    U16             Reserved02;             /* 0x02 */
+    U8              Flags;                  /* 0x04 */
+    U8              Reserved05[3];          /* 0x05 */
+    U32             Reserved08;             /* 0x08 */
+    U32             Reserved0C;             /* 0x0C */
+} MPI3_IO_UNIT4_SENSOR, MPI3_POINTER PTR_MPI3_IO_UNIT4_SENSOR,
+  Mpi3IOUnit4Sensor_t, MPI3_POINTER pMpi3IOUnit4Sensor_t;
+
+/**** Defines for the Flags field ****/
+#define MPI3_IOUNIT4_SENSOR_FLAGS_TEMP_VALID        (0x01)
+
+#ifndef MPI3_IO_UNIT4_SENSOR_MAX
+#define MPI3_IO_UNIT4_SENSOR_MAX        (1)
+#endif  /* MPI3_IO_UNIT4_SENSOR_MAX */
+
+typedef struct _MPI3_IO_UNIT_PAGE4 {
+    MPI3_CONFIG_PAGE_HEADER         Header;                             /* 0x00 */
+    U32                             Reserved08;                         /* 0x08 */
+    U8                              NumSensors;                         /* 0x0C */
+    U8                              Reserved0D[3];                      /* 0x0D */
+    MPI3_IO_UNIT4_SENSOR            Sensor[MPI3_IO_UNIT4_SENSOR_MAX];   /* 0x10 */
+} MPI3_IO_UNIT_PAGE4, MPI3_POINTER PTR_MPI3_IO_UNIT_PAGE4,
+  Mpi3IOUnitPage4_t, MPI3_POINTER pMpi3IOUnitPage4_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_IOUNIT4_PAGEVERSION                (0x00)
+
+/*****************************************************************************
+ *              IO Unit Page 5                                               *
+ ****************************************************************************/
+typedef struct _MPI3_IO_UNIT5_SPINUP_GROUP {
+    U8              MaxTargetSpinup;    /* 0x00 */
+    U8              SpinupDelay;        /* 0x01 */
+    U8              SpinupFlags;        /* 0x02 */
+    U8              Reserved03;         /* 0x03 */
+} MPI3_IO_UNIT5_SPINUP_GROUP, MPI3_POINTER PTR_MPI3_IO_UNIT5_SPINUP_GROUP,
+  Mpi3IOUnit5SpinupGroup_t, MPI3_POINTER pMpi3IOUnit5SpinupGroup_t;
+
+/**** Defines for the SpinupFlags field ****/
+#define MPI3_IOUNIT5_SPINUP_FLAGS_DISABLE       (0x01)
+
+#ifndef MPI3_IO_UNIT5_PHY_MAX
+#define MPI3_IO_UNIT5_PHY_MAX       (4)
+#endif  /* MPI3_IO_UNIT5_PHY_MAX */
+
+typedef struct _MPI3_IO_UNIT_PAGE5 {
+    MPI3_CONFIG_PAGE_HEADER         Header;                     /* 0x00 */
+    MPI3_IO_UNIT5_SPINUP_GROUP      SpinupGroupParameters[4];   /* 0x08 */
+    U32                             Reserved18;                 /* 0x18 */
+    U32                             Reserved1C;                 /* 0x1C */
+    U32                             Reserved20;                 /* 0x20 */
+    U8                              Reserved24;                 /* 0x24 */
+    U8                              SATADeviceWaitTime;         /* 0x25 */
+    U8                              SpinupEnclDriveCount;       /* 0x26 */
+    U8                              SpinupEnclDelay;            /* 0x27 */
+    U8                              NumPhys;                    /* 0x28 */
+    U8                              PEInitialSpinupDelay;       /* 0x29 */
+    U8                              TopologyStableTime;         /* 0x2A */
+    U8                              Flags;                      /* 0x2B */
+    U8                              Phy[MPI3_IO_UNIT5_PHY_MAX]; /* 0x2C */
+} MPI3_IO_UNIT_PAGE5, MPI3_POINTER PTR_MPI3_IO_UNIT_PAGE5,
+  Mpi3IOUnitPage5_t, MPI3_POINTER pMpi3IOUnitPage5_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_IOUNIT5_PAGEVERSION                           (0x00)
+
+/**** Defines for the Flags field ****/
+#define MPI3_IOUNIT5_FLAGS_POWER_CAPABLE_SPINUP            (0x02)
+#define MPI3_IOUNIT5_FLAGS_AUTO_PORT_ENABLE                (0x01)
+
+/**** Defines for the PHY field ****/
+#define MPI3_IOUNIT5_PHY_SPINUP_GROUP_MASK                 (0x03)
+
+/*****************************************************************************
+ *              IO Unit Page 6                                               *
+ ****************************************************************************/
+typedef struct _MPI3_IO_UNIT_PAGE6 {
+    MPI3_CONFIG_PAGE_HEADER         Header;                     /* 0x00 */
+    U32                             BoardPowerRequirement;      /* 0x08 */
+    U32                             PCISlotPowerAllocation;     /* 0x0C */
+    U8                              Flags;                      /* 0x10 */
+    U8                              Reserved11[3];              /* 0x11 */
+} MPI3_IO_UNIT_PAGE6, MPI3_POINTER PTR_MPI3_IO_UNIT_PAGE6,
+  Mpi3IOUnitPage6_t, MPI3_POINTER pMpi3IOUnitPage6_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_IOUNIT6_PAGEVERSION                (0x00)
+
+/**** Defines for the Flags field ****/
+#define MPI3_IOUNIT6_FLAGS_ACT_CABLE_PWR_EXC    (0x01)
+
+/*****************************************************************************
+ *              IO Unit Page 7                                               *
+ ****************************************************************************/
+typedef struct _MPI3_IO_UNIT_PAGE7 {
+    MPI3_CONFIG_PAGE_HEADER         Header;                     /* 0x00 */
+    U32                             Reserved08;                 /* 0x08 */
+} MPI3_IO_UNIT_PAGE7, MPI3_POINTER PTR_MPI3_IO_UNIT_PAGE7,
+  Mpi3IOUnitPage7_t, MPI3_POINTER pMpi3IOUnitPage7_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_IOUNIT7_PAGEVERSION                (0x00)
+
+/*****************************************************************************
+ *              IO Unit Page 8                                               *
+ ****************************************************************************/
+
+#ifndef MPI3_IOUNIT8_DIGEST_MAX
+#define MPI3_IOUNIT8_DIGEST_MAX                   (1)
+#endif  /* MPI3_IOUNIT8_DIGEST_MAX */
+
+typedef union _MPI3_IOUNIT8_DIGEST {
+    U32                             Dword[16];
+    U16                             Word[32];
+    U8                              Byte[64];
+} MPI3_IOUNIT8_DIGEST, MPI3_POINTER PTR_MPI3_IOUNIT8_DIGEST,
+  Mpi3IOUnit8Digest, MPI3_POINTER pMpi3IOUnit8Digest;
+
+typedef struct _MPI3_IO_UNIT_PAGE8 {
+    MPI3_CONFIG_PAGE_HEADER         Header;                             /* 0x00 */
+    U8                              SBMode;                             /* 0x08 */
+    U8                              SbState;                            /* 0x09 */
+    U16                             Reserved0A;                         /* 0x0A */
+    U8                              NumSlots;                           /* 0x0C */
+    U8                              SlotsAvailable;                     /* 0x0D */
+    U8                              CurrentKeyEncryptionAlgo;           /* 0x0E */
+    U8                              KeyDigestHashAlgo;                  /* 0x0F */
+    U32                             Reserved10[2];                      /* 0x10 */
+    U32                             CurrentKey[128];                    /* 0x18 */
+    MPI3_IOUNIT8_DIGEST             Digest[MPI3_IOUNIT8_DIGEST_MAX];   /* 0x218 */  /* variable length */
+} MPI3_IO_UNIT_PAGE8, MPI3_POINTER PTR_MPI3_IO_UNIT_PAGE8,
+  Mpi3IOUnitPage8_t, MPI3_POINTER pMpi3IOUnitPage8_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_IOUNIT8_PAGEVERSION                  (0x00)
+
+/**** Defines for the SBMode field ****/
+#define MPI3_IOUNIT8_SBMODE_SECURE_DEBUG          (0x04)
+#define MPI3_IOUNIT8_SBMODE_HARD_SECURE           (0x02)
+#define MPI3_IOUNIT8_SBMODE_CONFIG_SECURE         (0x01)
+
+/**** Defines for the SBState field ****/
+#define MPI3_IOUNIT8_SBSTATE_KEY_UPDATE_PENDING   (0x02)
+#define MPI3_IOUNIT8_SBSTATE_SECURE_BOOT_ENABLED  (0x01)
+
+/*****************************************************************************
+ *              IO Unit Page 9                                               *
+ ****************************************************************************/
+
+typedef struct _MPI3_IO_UNIT_PAGE9 {
+    MPI3_CONFIG_PAGE_HEADER         Header;                             /* 0x00 */
+    U32                             Flags;                              /* 0x08 */
+    U16                             FirstDevice;                        /* 0x0C */
+    U16                             Reserved0E;                         /* 0x0E */
+} MPI3_IO_UNIT_PAGE9, MPI3_POINTER PTR_MPI3_IO_UNIT_PAGE9,
+  Mpi3IOUnitPage9_t, MPI3_POINTER pMpi3IOUnitPage9_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_IOUNIT9_PAGEVERSION                  (0x00)
+
+/**** Defines for the Flags field ****/
+#define MPI3_IOUNIT9_FLAGS_VDFIRST_ENABLED         (0x01)
+
+/**** Defines for the FirstDevice field ****/
+#define MPI3_IOUNIT9_FIRSTDEVICE_UNKNOWN          (0xFFFF)
+
+/*****************************************************************************
+ *              IOC Configuration Pages                                      *
+ ****************************************************************************/
+
+/*****************************************************************************
+ *              IOC Page 0                                                   *
+ ****************************************************************************/
+typedef struct _MPI3_IOC_PAGE0 {
+    MPI3_CONFIG_PAGE_HEADER         Header;                 /* 0x00 */
+    U32                             Reserved08;             /* 0x08 */
+    U16                             VendorID;               /* 0x0C */
+    U16                             DeviceID;               /* 0x0E */
+    U8                              RevisionID;             /* 0x10 */
+    U8                              Reserved11[3];          /* 0x11 */
+    U32                             ClassCode;              /* 0x14 */
+    U16                             SubsystemVendorID;      /* 0x18 */
+    U16                             SubsystemID;            /* 0x1A */
+} MPI3_IOC_PAGE0, MPI3_POINTER PTR_MPI3_IOC_PAGE0,
+  Mpi3IOCPage0_t, MPI3_POINTER pMpi3IOCPage0_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_IOC0_PAGEVERSION               (0x00)
+
+/*****************************************************************************
+ *              IOC Page 1                                                   *
+ ****************************************************************************/
+typedef struct _MPI3_IOC_PAGE1 {
+    MPI3_CONFIG_PAGE_HEADER         Header;                 /* 0x00 */
+    U32                             CoalescingTimeout;      /* 0x08 */
+    U8                              CoalescingDepth;        /* 0x0C */
+    U8                              PCISlotNum;             /* 0x0D */
+    U16                             Reserved0E;             /* 0x0E */
+} MPI3_IOC_PAGE1, MPI3_POINTER PTR_MPI3_IOC_PAGE1,
+  Mpi3IOCPage1_t, MPI3_POINTER pMpi3IOCPage1_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_IOC1_PAGEVERSION               (0x00)
+
+/**** Defines for the PCISlotNum field ****/
+#define MPI3_IOC1_PCISLOTNUM_UNKNOWN        (0xFF)
+
+/*****************************************************************************
+ *              IOC Page 2                                                   *
+ ****************************************************************************/
+#ifndef MPI3_IOC2_EVENTMASK_WORDS
+#define MPI3_IOC2_EVENTMASK_WORDS           (4)
+#endif  /* MPI3_IOC2_EVENTMASK_WORDS */
+
+typedef struct _MPI3_IOC_PAGE2 {
+    MPI3_CONFIG_PAGE_HEADER         Header;                                 /* 0x00 */
+    U32                             Reserved08;                             /* 0x08 */
+    U16                             SASBroadcastPrimitiveMasks;             /* 0x0C */
+    U16                             SASNotifyPrimitiveMasks;                /* 0x0E */
+    U32                             EventMasks[MPI3_IOC2_EVENTMASK_WORDS];  /* 0x10 */
+} MPI3_IOC_PAGE2, MPI3_POINTER PTR_MPI3_IOC_PAGE2,
+  Mpi3IOCPage2_t, MPI3_POINTER pMpi3IOCPage2_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_IOC2_PAGEVERSION               (0x00)
+
+
+/*****************************************************************************
+ *              UEFI BSD and HII Configuration Pages                         *
+ ****************************************************************************/
+typedef struct _MPI3_UEFIBSD_PAGE0 {
+    MPI3_CONFIG_PAGE_HEADER         Header;             /* 0x00 */
+    U32                             BSDOptions;         /* 0x08 */
+    U8                              SSUTimeout;         /* 0x0C */
+    U8                              IOTimeout;          /* 0x0D */
+    U8                              TURRetries;         /* 0x0E */
+    U8                              TURInterval;        /* 0x0F */
+    U8                              Reserved10;         /* 0x10 */
+    U8                              SecurityKeyTimeout; /* 0x11 */
+    U16                             Reserved12;         /* 0x12 */
+    U32                             Reserved14;         /* 0x14 */
+    U32                             Reserved18;         /* 0x18 */
+} MPI3_UEFIBSD_PAGE0, MPI3_POINTER PTR_MPI3_UEFIBSD_PAGE0,
+  Mpi3UefiBsdPage0_t, MPI3_POINTER pMpi3UefiBsdPage0_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_UEFIBSD_PAGEVERSION               (0x00)
+
+/**** Defines for the BSDOptions field ****/
+#define MPI3_UEFIBSD_BSDOPTS_REGISTRATION_MASK              (0x00000003)
+#define MPI3_UEFIBSD_BSDOPTS_REGISTRATION_IOC_AND_DEVS      (0x00000000)
+#define MPI3_UEFIBSD_BSDOPTS_REGISTRATION_IOC_ONLY          (0x00000001)
+#define MPI3_UEFIBSD_BSDOPTS_REGISTRATION_NONE              (0x00000002)
+#define MPI3_UEFIBSD_BSDOPTS_DIS_HII_CONFIG_UTIL            (0x00000004)
+#define MPI3_UEFIBSD_BSDOPTS_EN_ADV_ADAPTER_CONFIG          (0x00000008)
+
+
+/*****************************************************************************
+ *              Security Configuration Pages                                *
+ ****************************************************************************/
+
+typedef union _MPI3_SECURITY_MAC {
+    U32                             Dword[16];
+    U16                             Word[32];
+    U8                              Byte[64];
+} MPI3_SECURITY_MAC, MPI3_POINTER PTR_MPI3_SECURITY_MAC,
+  Mpi3SecurityMAC_t, MPI3_POINTER pMpi3SecurityMAC_t;
+
+typedef union _MPI3_SECURITY_NONCE {
+    U32                             Dword[16];
+    U16                             Word[32];
+    U8                              Byte[64];
+} MPI3_SECURITY_NONCE, MPI3_POINTER PTR_MPI3_SECURITY_NONCE,
+  Mpi3SecurityNonce_t, MPI3_POINTER pMpi3SecurityNonce_t;
+
+/*****************************************************************************
+ *              Security Page 0                                             *
+ ****************************************************************************/
+
+typedef union _MPI3_SECURITY0_CERT_CHAIN {
+    U32                             Dword[1024];
+    U16                             Word[2048];
+    U8                              Byte[4096];
+} MPI3_SECURITY0_CERT_CHAIN, MPI3_POINTER PTR_MPI3_SECURITY0_CERT_CHAIN,
+  Mpi3Security0CertChain_t, MPI3_POINTER pMpi3Security0CertChain_t;
+
+typedef struct _MPI3_SECURITY_PAGE0 {
+    MPI3_CONFIG_PAGE_HEADER         Header;                                 /* 0x00 */
+    U8                              SlotNumGroup;                           /* 0x08 */
+    U8                              SlotNum;                                /* 0x09 */
+    U16                             CertChainLength;                        /* 0x0A */
+    U8                              CertChainFlags;                         /* 0x0C */
+    U8                              Reserved0D[3];                          /* 0x0D */
+    U32                             BaseAsymAlgo;                           /* 0x10 */
+    U32                             BaseHashAlgo;                           /* 0x14 */
+    U32                             Reserved18[4];                          /* 0x18 */
+    MPI3_SECURITY_MAC               MAC;                                    /* 0x28 */
+    MPI3_SECURITY_NONCE             Nonce;                                  /* 0x68 */
+    MPI3_SECURITY0_CERT_CHAIN       CertificateChain;                       /* 0xA8 */
+} MPI3_SECURITY_PAGE0, MPI3_POINTER PTR_MPI3_SECURITY_PAGE0,
+  Mpi3SecurityPage0_t, MPI3_POINTER pMpi3SecurityPage0_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_SECURITY0_PAGEVERSION               (0x00)
+
+/**** Defines for the CertChainFlags field ****/
+#define MPI3_SECURITY0_CERTCHAIN_FLAGS_AUTH_API_MASK       (0x0E)
+#define MPI3_SECURITY0_CERTCHAIN_FLAGS_AUTH_API_UNUSED     (0x00)
+#define MPI3_SECURITY0_CERTCHAIN_FLAGS_AUTH_API_CERBERUS   (0x02)
+#define MPI3_SECURITY0_CERTCHAIN_FLAGS_AUTH_API_SPDM       (0x04)
+#define MPI3_SECURITY0_CERTCHAIN_FLAGS_SEALED              (0x01)
+
+/*****************************************************************************
+ *              Security Page 1                                             *
+ ****************************************************************************/
+
+#ifndef MPI3_SECURITY1_KEY_RECORD_MAX
+#define MPI3_SECURITY1_KEY_RECORD_MAX      1
+#endif  /* MPI3_SECURITY1_KEY_RECORD_MAX */
+
+#ifndef MPI3_SECURITY1_PAD_MAX
+#define MPI3_SECURITY1_PAD_MAX      1
+#endif  /* MPI3_SECURITY1_PAD_MAX */
+
+typedef union _MPI3_SECURITY1_KEY_DATA {
+    U32                             Dword[128];
+    U16                             Word[256];
+    U8                              Byte[512];
+} MPI3_SECURITY1_KEY_DATA, MPI3_POINTER PTR_MPI3_SECURITY1_KEY_DATA,
+  Mpi3Security1KeyData_t, MPI3_POINTER pMpi3Security1KeyData_t;
+
+typedef struct _MPI3_SECURITY1_KEY_RECORD {
+    U8                              Flags;                                  /* 0x00 */
+    U8                              Consumer;                               /* 0x01 */
+    U16                             KeyDataSize;                            /* 0x02 */
+    U32                             AdditionalKeyData;                      /* 0x04 */
+    U32                             Reserved08[2];                          /* 0x08 */
+    MPI3_SECURITY1_KEY_DATA         KeyData;                                /* 0x10 */
+} MPI3_SECURITY1_KEY_RECORD, MPI3_POINTER PTR_MPI3_SECURITY1_KEY_RECORD,
+  Mpi3Security1KeyRecord_t, MPI3_POINTER pMpi3Security1KeyRecord_t;
+
+/**** Defines for the Flags field ****/
+#define MPI3_SECURITY1_KEY_RECORD_FLAGS_TYPE_MASK            (0x1F)
+#define MPI3_SECURITY1_KEY_RECORD_FLAGS_TYPE_NOT_VALID       (0x00)
+#define MPI3_SECURITY1_KEY_RECORD_FLAGS_TYPE_HMAC            (0x01)
+#define MPI3_SECURITY1_KEY_RECORD_FLAGS_TYPE_AES             (0x02)
+#define MPI3_SECURITY1_KEY_RECORD_FLAGS_TYPE_ECDSA_PRIVATE   (0x03)
+#define MPI3_SECURITY1_KEY_RECORD_FLAGS_TYPE_ECDSA_PUBLIC    (0x04)
+
+/**** Defines for the Consumer field ****/
+#define MPI3_SECURITY1_KEY_RECORD_CONSUMER_NOT_VALID         (0x00)
+#define MPI3_SECURITY1_KEY_RECORD_CONSUMER_SAFESTORE         (0x01)
+#define MPI3_SECURITY1_KEY_RECORD_CONSUMER_CERT_CHAIN        (0x02)
+#define MPI3_SECURITY1_KEY_RECORD_CONSUMER_AUTH_DEV_KEY      (0x03)
+#define MPI3_SECURITY1_KEY_RECORD_CONSUMER_CACHE_OFFLOAD     (0x04)
+
+typedef struct _MPI3_SECURITY_PAGE1 {
+    MPI3_CONFIG_PAGE_HEADER         Header;                                     /* 0x00 */
+    U32                             Reserved08[2];                              /* 0x08 */
+    MPI3_SECURITY_MAC               MAC;                                        /* 0x10 */
+    MPI3_SECURITY_NONCE             Nonce;                                      /* 0x50 */
+    U8                              NumKeys;                                    /* 0x90 */
+    U8                              Reserved91[3];                              /* 0x91 */
+    U32                             Reserved94[3];                              /* 0x94 */
+    MPI3_SECURITY1_KEY_RECORD       KeyRecord[MPI3_SECURITY1_KEY_RECORD_MAX];   /* 0xA0 */
+    U8                              Pad[MPI3_SECURITY1_PAD_MAX];                /* ??  */
+} MPI3_SECURITY_PAGE1, MPI3_POINTER PTR_MPI3_SECURITY_PAGE1,
+  Mpi3SecurityPage1_t, MPI3_POINTER pMpi3SecurityPage1_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_SECURITY1_PAGEVERSION               (0x00)
+
+/*****************************************************************************
+ *              SAS IO Unit Configuration Pages                              *
+ ****************************************************************************/
+
+/*****************************************************************************
+ *              SAS IO Unit Page 0                                           *
+ ****************************************************************************/
+typedef struct _MPI3_SAS_IO_UNIT0_PHY_DATA {
+    U8              IOUnitPort;                         /* 0x00 */
+    U8              PortFlags;                          /* 0x01 */
+    U8              PhyFlags;                           /* 0x02 */
+    U8              NegotiatedLinkRate;                 /* 0x03 */
+    U16             ControllerPhyDeviceInfo;            /* 0x04 */
+    U16             Reserved06;                         /* 0x06 */
+    U16             AttachedDevHandle;                  /* 0x08 */
+    U16             ControllerDevHandle;                /* 0x0A */
+    U32             DiscoveryStatus;                    /* 0x0C */
+    U32             Reserved10;                         /* 0x10 */
+} MPI3_SAS_IO_UNIT0_PHY_DATA, MPI3_POINTER PTR_MPI3_SAS_IO_UNIT0_PHY_DATA,
+  Mpi3SasIOUnit0PhyData_t, MPI3_POINTER pMpi3SasIOUnit0PhyData_t;
+
+#ifndef MPI3_SAS_IO_UNIT0_PHY_MAX
+#define MPI3_SAS_IO_UNIT0_PHY_MAX           (1)
+#endif  /* MPI3_SAS_IO_UNIT0_PHY_MAX */
+
+typedef struct _MPI3_SAS_IO_UNIT_PAGE0 {
+    MPI3_CONFIG_PAGE_HEADER         Header;                                 /* 0x00 */
+    U32                             Reserved08;                             /* 0x08 */
+    U8                              NumPhys;                                /* 0x0C */
+    U8                              Reserved0D[3];                          /* 0x0D */
+    MPI3_SAS_IO_UNIT0_PHY_DATA      PhyData[MPI3_SAS_IO_UNIT0_PHY_MAX];     /* 0x10 */
+} MPI3_SAS_IO_UNIT_PAGE0, MPI3_POINTER PTR_MPI3_SAS_IO_UNIT_PAGE0,
+  Mpi3SasIOUnitPage0_t, MPI3_POINTER pMpi3SasIOUnitPage0_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_SASIOUNIT0_PAGEVERSION                         (0x00)
+
+/**** Defines for the PortFlags field ****/
+#define MPI3_SASIOUNIT0_PORTFLAGS_DISC_IN_PROGRESS          (0x08)
+#define MPI3_SASIOUNIT0_PORTFLAGS_AUTO_PORT_CONFIG          (0x01)
+
+/**** Defines for the PhyFlags field ****/
+#define MPI3_SASIOUNIT0_PHYFLAGS_INIT_PERSIST_CONNECT       (0x40)
+#define MPI3_SASIOUNIT0_PHYFLAGS_TARG_PERSIST_CONNECT       (0x20)
+#define MPI3_SASIOUNIT0_PHYFLAGS_PHY_DISABLED               (0x08)
+
+/**** Use MPI3_SAS_NEG_LINK_RATE_ defines for the NegotiatedLinkRate field ****/
+
+/**** Use MPI3_SAS_DEVICE_INFO_ defines (see mpi30_sas.h) for the ControllerPhyDeviceInfo field ****/
+
+/**** Use MPI3_SAS_DISC_STATUS_ defines (see mpi30_ioc.h) for the DiscoveryStatus field ****/
+
+/*****************************************************************************
+ *              SAS IO Unit Page 1                                           *
+ ****************************************************************************/
+typedef struct _MPI3_SAS_IO_UNIT1_PHY_DATA {
+    U8              IOUnitPort;                         /* 0x00 */
+    U8              PortFlags;                          /* 0x01 */
+    U8              PhyFlags;                           /* 0x02 */
+    U8              MaxMinLinkRate;                     /* 0x03 */
+    U16             ControllerPhyDeviceInfo;            /* 0x04 */
+    U16             MaxTargetPortConnectTime;           /* 0x06 */
+    U32             Reserved08;                         /* 0x08 */
+} MPI3_SAS_IO_UNIT1_PHY_DATA, MPI3_POINTER PTR_MPI3_SAS_IO_UNIT1_PHY_DATA,
+  Mpi3SasIOUnit1PhyData_t, MPI3_POINTER pMpi3SasIOUnit1PhyData_t;
+
+#ifndef MPI3_SAS_IO_UNIT1_PHY_MAX
+#define MPI3_SAS_IO_UNIT1_PHY_MAX           (1)
+#endif  /* MPI3_SAS_IO_UNIT1_PHY_MAX */
+
+typedef struct _MPI3_SAS_IO_UNIT_PAGE1 {
+    MPI3_CONFIG_PAGE_HEADER         Header;                                 /* 0x00 */
+    U16                             ControlFlags;                           /* 0x08 */
+    U16                             SASNarrowMaxQueueDepth;                 /* 0x0A */
+    U16                             AdditionalControlFlags;                 /* 0x0C */
+    U16                             SASWideMaxQueueDepth;                   /* 0x0E */
+    U8                              NumPhys;                                /* 0x10 */
+    U8                              SATAMaxQDepth;                          /* 0x11 */
+    U16                             Reserved12;                             /* 0x12 */
+    MPI3_SAS_IO_UNIT1_PHY_DATA      PhyData[MPI3_SAS_IO_UNIT1_PHY_MAX];     /* 0x14 */
+} MPI3_SAS_IO_UNIT_PAGE1, MPI3_POINTER PTR_MPI3_SAS_IO_UNIT_PAGE1,
+  Mpi3SasIOUnitPage1_t, MPI3_POINTER pMpi3SasIOUnitPage1_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_SASIOUNIT1_PAGEVERSION                                 (0x00)
+
+/**** Defines for the ControlFlags field ****/
+#define MPI3_SASIOUNIT1_CONTROL_CONTROLLER_DEVICE_SELF_TEST         (0x8000)
+#define MPI3_SASIOUNIT1_CONTROL_SATA_SW_PRESERVE                    (0x1000)
+#define MPI3_SASIOUNIT1_CONTROL_SATA_48BIT_LBA_REQUIRED             (0x0080)
+#define MPI3_SASIOUNIT1_CONTROL_SATA_SMART_REQUIRED                 (0x0040)
+#define MPI3_SASIOUNIT1_CONTROL_SATA_NCQ_REQUIRED                   (0x0020)
+#define MPI3_SASIOUNIT1_CONTROL_SATA_FUA_REQUIRED                   (0x0010)
+#define MPI3_SASIOUNIT1_CONTROL_TABLE_SUBTRACTIVE_ILLEGAL           (0x0008)
+#define MPI3_SASIOUNIT1_CONTROL_SUBTRACTIVE_ILLEGAL                 (0x0004)
+#define MPI3_SASIOUNIT1_CONTROL_FIRST_LVL_DISC_ONLY                 (0x0002)
+#define MPI3_SASIOUNIT1_CONTROL_HARD_RESET_MASK                     (0x0001)
+#define MPI3_SASIOUNIT1_CONTROL_HARD_RESET_DEVICE_NAME              (0x0000)
+#define MPI3_SASIOUNIT1_CONTROL_HARD_RESET_SAS_ADDRESS              (0x0001)
+
+/**** Defines for the AdditionalControlFlags field ****/
+#define MPI3_SASIOUNIT1_ACONTROL_DA_PERSIST_CONNECT                 (0x0100)
+#define MPI3_SASIOUNIT1_ACONTROL_MULTI_PORT_DOMAIN_ILLEGAL          (0x0080)
+#define MPI3_SASIOUNIT1_ACONTROL_SATA_ASYNCHROUNOUS_NOTIFICATION    (0x0040)
+#define MPI3_SASIOUNIT1_ACONTROL_INVALID_TOPOLOGY_CORRECTION        (0x0020)
+#define MPI3_SASIOUNIT1_ACONTROL_PORT_ENABLE_ONLY_SATA_LINK_RESET   (0x0010)
+#define MPI3_SASIOUNIT1_ACONTROL_OTHER_AFFILIATION_SATA_LINK_RESET  (0x0008)
+#define MPI3_SASIOUNIT1_ACONTROL_SELF_AFFILIATION_SATA_LINK_RESET   (0x0004)
+#define MPI3_SASIOUNIT1_ACONTROL_NO_AFFILIATION_SATA_LINK_RESET     (0x0002)
+#define MPI3_SASIOUNIT1_ACONTROL_ALLOW_TABLE_TO_TABLE               (0x0001)
+
+/**** Defines for the PortFlags field ****/
+#define MPI3_SASIOUNIT1_PORT_FLAGS_AUTO_PORT_CONFIG                 (0x01)
+
+/**** Defines for the PhyFlags field ****/
+#define MPI3_SASIOUNIT1_PHYFLAGS_INIT_PERSIST_CONNECT               (0x40)
+#define MPI3_SASIOUNIT1_PHYFLAGS_TARG_PERSIST_CONNECT               (0x20)
+#define MPI3_SASIOUNIT1_PHYFLAGS_PHY_DISABLE                        (0x08)
+
+/**** Defines for the MaxMinLinkRate field ****/
+#define MPI3_SASIOUNIT1_MMLR_MAX_RATE_MASK                          (0xF0)
+#define MPI3_SASIOUNIT1_MMLR_MAX_RATE_SHIFT                         (4)
+#define MPI3_SASIOUNIT1_MMLR_MAX_RATE_6_0                           (0xA0)
+#define MPI3_SASIOUNIT1_MMLR_MAX_RATE_12_0                          (0xB0)
+#define MPI3_SASIOUNIT1_MMLR_MAX_RATE_22_5                          (0xC0)
+#define MPI3_SASIOUNIT1_MMLR_MIN_RATE_MASK                          (0x0F)
+#define MPI3_SASIOUNIT1_MMLR_MIN_RATE_6_0                           (0x0A)
+#define MPI3_SASIOUNIT1_MMLR_MIN_RATE_12_0                          (0x0B)
+#define MPI3_SASIOUNIT1_MMLR_MIN_RATE_22_5                          (0x0C)
+
+/**** Use MPI3_SAS_DEVICE_INFO_ defines (see mpi30_sas.h) for the ControllerPhyDeviceInfo field ****/
+
+/*****************************************************************************
+ *              SAS IO Unit Page 2                                           *
+ ****************************************************************************/
+typedef struct _MPI3_SAS_IO_UNIT2_PHY_PM_SETTINGS {
+    U8              ControlFlags;                       /* 0x00 */
+    U8              Reserved01;                         /* 0x01 */
+    U16             InactivityTimerExponent;            /* 0x02 */
+    U8              SATAPartialTimeout;                 /* 0x04 */
+    U8              Reserved05;                         /* 0x05 */
+    U8              SATASlumberTimeout;                 /* 0x06 */
+    U8              Reserved07;                         /* 0x07 */
+    U8              SASPartialTimeout;                  /* 0x08 */
+    U8              Reserved09;                         /* 0x09 */
+    U8              SASSlumberTimeout;                  /* 0x0A */
+    U8              Reserved0B;                         /* 0x0B */
+} MPI3_SAS_IO_UNIT2_PHY_PM_SETTINGS, MPI3_POINTER PTR_MPI3_SAS_IO_UNIT2_PHY_PM_SETTINGS,
+  Mpi3SasIOUnit2PhyPmSettings_t, MPI3_POINTER pMpi3SasIOUnit2PhyPmSettings_t;
+
+#ifndef MPI3_SAS_IO_UNIT2_PHY_MAX
+#define MPI3_SAS_IO_UNIT2_PHY_MAX           (1)
+#endif  /* MPI3_SAS_IO_UNIT2_PHY_MAX */
+
+typedef struct _MPI3_SAS_IO_UNIT_PAGE2 {
+    MPI3_CONFIG_PAGE_HEADER             Header;                                                     /* 0x00 */
+    U8                                  NumPhys;                                                    /* 0x08 */
+    U8                                  Reserved09[3];                                              /* 0x09 */
+    U32                                 Reserved0C;                                                 /* 0x0C */
+    MPI3_SAS_IO_UNIT2_PHY_PM_SETTINGS   SASPhyPowerManagementSettings[MPI3_SAS_IO_UNIT2_PHY_MAX];   /* 0x10 */
+} MPI3_SAS_IO_UNIT_PAGE2, MPI3_POINTER PTR_MPI3_SAS_IO_UNIT_PAGE2,
+  Mpi3SasIOUnitPage2_t, MPI3_POINTER pMpi3SasIOUnitPage2_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_SASIOUNIT2_PAGEVERSION                     (0x00)
+
+/**** Defines for the ControlFlags field ****/
+#define MPI3_SASIOUNIT2_CONTROL_SAS_SLUMBER_ENABLE      (0x08)
+#define MPI3_SASIOUNIT2_CONTROL_SAS_PARTIAL_ENABLE      (0x04)
+#define MPI3_SASIOUNIT2_CONTROL_SATA_SLUMBER_ENABLE     (0x02)
+#define MPI3_SASIOUNIT2_CONTROL_SATA_PARTIAL_ENABLE     (0x01)
+
+/**** Defines for the InactivityTimerExponent field ****/
+#define MPI3_SASIOUNIT2_ITE_SAS_SLUMBER_MASK            (0x7000)
+#define MPI3_SASIOUNIT2_ITE_SAS_SLUMBER_SHIFT           (12)
+#define MPI3_SASIOUNIT2_ITE_SAS_PARTIAL_MASK            (0x0700)
+#define MPI3_SASIOUNIT2_ITE_SAS_PARTIAL_SHIFT           (8)
+#define MPI3_SASIOUNIT2_ITE_SATA_SLUMBER_MASK           (0x0070)
+#define MPI3_SASIOUNIT2_ITE_SATA_SLUMBER_SHIFT          (4)
+#define MPI3_SASIOUNIT2_ITE_SATA_PARTIAL_MASK           (0x0007)
+#define MPI3_SASIOUNIT2_ITE_SATA_PARTIAL_SHIFT          (0)
+
+#define MPI3_SASIOUNIT2_ITE_EXP_TEN_SECONDS             (7)
+#define MPI3_SASIOUNIT2_ITE_EXP_ONE_SECOND              (6)
+#define MPI3_SASIOUNIT2_ITE_EXP_HUNDRED_MILLISECONDS    (5)
+#define MPI3_SASIOUNIT2_ITE_EXP_TEN_MILLISECONDS        (4)
+#define MPI3_SASIOUNIT2_ITE_EXP_ONE_MILLISECOND         (3)
+#define MPI3_SASIOUNIT2_ITE_EXP_HUNDRED_MICROSECONDS    (2)
+#define MPI3_SASIOUNIT2_ITE_EXP_TEN_MICROSECONDS        (1)
+#define MPI3_SASIOUNIT2_ITE_EXP_ONE_MICROSECOND         (0)
+
+/*****************************************************************************
+ *              SAS IO Unit Page 3                                           *
+ ****************************************************************************/
+typedef struct _MPI3_SAS_IO_UNIT_PAGE3 {
+    MPI3_CONFIG_PAGE_HEADER         Header;                         /* 0x00 */
+    U32                             Reserved08;                     /* 0x08 */
+    U32                             PowerManagementCapabilities;    /* 0x0C */
+} MPI3_SAS_IO_UNIT_PAGE3, MPI3_POINTER PTR_MPI3_SAS_IO_UNIT_PAGE3,
+  Mpi3SasIOUnitPage3_t, MPI3_POINTER pMpi3SasIOUnitPage3_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_SASIOUNIT3_PAGEVERSION                     (0x00)
+
+/**** Defines for the PowerManagementCapabilities field ****/
+#define MPI3_SASIOUNIT3_PM_HOST_SAS_SLUMBER_MODE        (0x00000800)
+#define MPI3_SASIOUNIT3_PM_HOST_SAS_PARTIAL_MODE        (0x00000400)
+#define MPI3_SASIOUNIT3_PM_HOST_SATA_SLUMBER_MODE       (0x00000200)
+#define MPI3_SASIOUNIT3_PM_HOST_SATA_PARTIAL_MODE       (0x00000100)
+#define MPI3_SASIOUNIT3_PM_IOUNIT_SAS_SLUMBER_MODE      (0x00000008)
+#define MPI3_SASIOUNIT3_PM_IOUNIT_SAS_PARTIAL_MODE      (0x00000004)
+#define MPI3_SASIOUNIT3_PM_IOUNIT_SATA_SLUMBER_MODE     (0x00000002)
+#define MPI3_SASIOUNIT3_PM_IOUNIT_SATA_PARTIAL_MODE     (0x00000001)
+
+
+/*****************************************************************************
+ *              SAS Expander Configuration Pages                             *
+ ****************************************************************************/
+
+/*****************************************************************************
+ *              SAS Expander Page 0                                          *
+ ****************************************************************************/
+typedef struct _MPI3_SAS_EXPANDER_PAGE0 {
+    MPI3_CONFIG_PAGE_HEADER         Header;                         /* 0x00 */
+    U8                              IOUnitPort;                     /* 0x08 */
+    U8                              ReportGenLength;                /* 0x09 */
+    U16                             EnclosureHandle;                /* 0x0A */
+    U32                             Reserved0C;                     /* 0x0C */
+    U64                             SASAddress;                     /* 0x10 */
+    U32                             DiscoveryStatus;                /* 0x18 */
+    U16                             DevHandle;                      /* 0x1C */
+    U16                             ParentDevHandle;                /* 0x1E */
+    U16                             ExpanderChangeCount;            /* 0x20 */
+    U16                             ExpanderRouteIndexes;           /* 0x22 */
+    U8                              NumPhys;                        /* 0x24 */
+    U8                              SASLevel;                       /* 0x25 */
+    U16                             Flags;                          /* 0x26 */
+    U16                             STPBusInactivityTimeLimit;      /* 0x28 */
+    U16                             STPMaxConnectTimeLimit;         /* 0x2A */
+    U16                             STP_SMP_NexusLossTime;          /* 0x2C */
+    U16                             MaxNumRoutedSASAddresses;       /* 0x2E */
+    U64                             ActiveZoneManagerSASAddress;    /* 0x30 */
+    U16                             ZoneLockInactivityLimit;        /* 0x38 */
+    U16                             Reserved3A;                     /* 0x3A */
+    U8                              TimeToReducedFunc;              /* 0x3C */
+    U8                              InitialTimeToReducedFunc;       /* 0x3D */
+    U8                              MaxReducedFuncTime;             /* 0x3E */
+    U8                              ExpStatus;                      /* 0x3F */
+} MPI3_SAS_EXPANDER_PAGE0, MPI3_POINTER PTR_MPI3_SAS_EXPANDER_PAGE0,
+  Mpi3SasExpanderPage0_t, MPI3_POINTER pMpi3SasExpanderPage0_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_SASEXPANDER0_PAGEVERSION                       (0x00)
+
+/**** Use MPI3_SAS_DISC_STATUS_ defines (see mpi30_ioc.h) for the DiscoveryStatus field ****/
+
+/**** Defines for the Flags field ****/
+#define MPI3_SASEXPANDER0_FLAGS_REDUCED_FUNCTIONALITY       (0x2000)
+#define MPI3_SASEXPANDER0_FLAGS_ZONE_LOCKED                 (0x1000)
+#define MPI3_SASEXPANDER0_FLAGS_SUPPORTED_PHYSICAL_PRES     (0x0800)
+#define MPI3_SASEXPANDER0_FLAGS_ASSERTED_PHYSICAL_PRES      (0x0400)
+#define MPI3_SASEXPANDER0_FLAGS_ZONING_SUPPORT              (0x0200)
+#define MPI3_SASEXPANDER0_FLAGS_ENABLED_ZONING              (0x0100)
+#define MPI3_SASEXPANDER0_FLAGS_TABLE_TO_TABLE_SUPPORT      (0x0080)
+#define MPI3_SASEXPANDER0_FLAGS_CONNECTOR_END_DEVICE        (0x0010)
+#define MPI3_SASEXPANDER0_FLAGS_OTHERS_CONFIG               (0x0004)
+#define MPI3_SASEXPANDER0_FLAGS_CONFIG_IN_PROGRESS          (0x0002)
+#define MPI3_SASEXPANDER0_FLAGS_ROUTE_TABLE_CONFIG          (0x0001)
+
+/**** Defines for the ExpStatus field ****/
+#define MPI3_SASEXPANDER0_ES_NOT_RESPONDING                 (0x02)
+#define MPI3_SASEXPANDER0_ES_RESPONDING                     (0x03)
+#define MPI3_SASEXPANDER0_ES_DELAY_NOT_RESPONDING           (0x04)
+
+/*****************************************************************************
+ *              SAS Expander Page 1                                          *
+ ****************************************************************************/
+typedef struct _MPI3_SAS_EXPANDER_PAGE1 {
+    MPI3_CONFIG_PAGE_HEADER         Header;                     /* 0x00 */
+    U8                              IOUnitPort;                 /* 0x08 */
+    U8                              Reserved09[3];              /* 0x09 */
+    U8                              NumPhys;                    /* 0x0C */
+    U8                              Phy;                        /* 0x0D */
+    U16                             NumTableEntriesProgrammed;  /* 0x0E */
+    U8                              ProgrammedLinkRate;         /* 0x10 */
+    U8                              HwLinkRate;                 /* 0x11 */
+    U16                             AttachedDevHandle;          /* 0x12 */
+    U32                             PhyInfo;                    /* 0x14 */
+    U16                             AttachedDeviceInfo;         /* 0x18 */
+    U16                             Reserved1A;                 /* 0x1A */
+    U16                             ExpanderDevHandle;          /* 0x1C */
+    U8                              ChangeCount;                /* 0x1E */
+    U8                              NegotiatedLinkRate;         /* 0x1F */
+    U8                              PhyIdentifier;              /* 0x20 */
+    U8                              AttachedPhyIdentifier;      /* 0x21 */
+    U8                              Reserved22;                 /* 0x22 */
+    U8                              DiscoveryInfo;              /* 0x23 */
+    U32                             AttachedPhyInfo;            /* 0x24 */
+    U8                              ZoneGroup;                  /* 0x28 */
+    U8                              SelfConfigStatus;           /* 0x29 */
+    U16                             Reserved2A;                 /* 0x2A */
+    U16                             Slot;                       /* 0x2C */
+    U16                             SlotIndex;                  /* 0x2E */
+} MPI3_SAS_EXPANDER_PAGE1, MPI3_POINTER PTR_MPI3_SAS_EXPANDER_PAGE1,
+  Mpi3SasExpanderPage1_t, MPI3_POINTER pMpi3SasExpanderPage1_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_SASEXPANDER1_PAGEVERSION                   (0x00)
+
+/**** Defines for the ProgrammedLinkRate field - use MPI3_SAS_PRATE_ defines ****/
+
+/**** Defines for the HwLinkRate field - use MPI3_SAS_HWRATE_ defines ****/
+
+/**** Defines for the PhyInfo field - use MPI3_SAS_PHYINFO_ defines ****/
+
+/**** Defines for the AttachedDeviceInfo field - use MPI3_SAS_DEVICE_INFO_ defines ****/
+
+/**** Defines for the NegotiatedLinkRate field - use MPI3_SAS_NEG_LINK_RATE_ defines ****/
+
+/**** Defines for the DiscoveryInfo field ****/
+#define MPI3_SASEXPANDER1_DISCINFO_BAD_PHY_DISABLED     (0x04)
+#define MPI3_SASEXPANDER1_DISCINFO_LINK_STATUS_CHANGE   (0x02)
+#define MPI3_SASEXPANDER1_DISCINFO_NO_ROUTING_ENTRIES   (0x01)
+
+/**** Defines for the AttachedPhyInfo field - use MPI3_SAS_APHYINFO_ defines ****/
+
+/**** Defines for the Slot field - use MPI3_SLOT_ defines ****/
+
+/**** Defines for the SlotIndex field - use MPI3_SLOT_INDEX_ ****/
+
+
+/*****************************************************************************
+ *              SAS Port Configuration Pages                                 *
+ ****************************************************************************/
+
+/*****************************************************************************
+ *              SAS Port Page 0                                              *
+ ****************************************************************************/
+typedef struct _MPI3_SAS_PORT_PAGE0 {
+    MPI3_CONFIG_PAGE_HEADER         Header;                 /* 0x00 */
+    U8                              PortNumber;             /* 0x08 */
+    U8                              Reserved09;             /* 0x09 */
+    U8                              PortWidth;              /* 0x0A */
+    U8                              Reserved0B;             /* 0x0B */
+    U8                              ZoneGroup;              /* 0x0C */
+    U8                              Reserved0D[3];          /* 0x0D */
+    U64                             SASAddress;             /* 0x10 */
+    U16                             DeviceInfo;             /* 0x18 */
+    U16                             Reserved1A;             /* 0x1A */
+    U32                             Reserved1C;             /* 0x1C */
+} MPI3_SAS_PORT_PAGE0, MPI3_POINTER PTR_MPI3_SAS_PORT_PAGE0,
+  Mpi3SasPortPage0, MPI3_POINTER pMpi3SasPortPage0;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_SASPORT0_PAGEVERSION                       (0x00)
+
+/**** Defines for the DeviceInfo field - use MPI3_SAS_DEVICE_INFO_ defines ****/
+
+/*****************************************************************************
+ *              SAS PHY Configuration Pages                                  *
+ ****************************************************************************/
+
+/*****************************************************************************
+ *              SAS PHY Page 0                                               *
+ ****************************************************************************/
+typedef struct _MPI3_SAS_PHY_PAGE0 {
+    MPI3_CONFIG_PAGE_HEADER         Header;                 /* 0x00 */
+    U16                             OwnerDevHandle;         /* 0x08 */
+    U16                             Reserved0A;             /* 0x0A */
+    U16                             AttachedDevHandle;      /* 0x0C */
+    U8                              AttachedPhyIdentifier;  /* 0x0E */
+    U8                              Reserved0F;             /* 0x0F */
+    U32                             AttachedPhyInfo;        /* 0x10 */
+    U8                              ProgrammedLinkRate;     /* 0x14 */
+    U8                              HwLinkRate;             /* 0x15 */
+    U8                              ChangeCount;            /* 0x16 */
+    U8                              Flags;                  /* 0x17 */
+    U32                             PhyInfo;                /* 0x18 */
+    U8                              NegotiatedLinkRate;     /* 0x1C */
+    U8                              Reserved1D[3];          /* 0x1D */
+    U16                             Slot;                   /* 0x20 */
+    U16                             SlotIndex;              /* 0x22 */
+} MPI3_SAS_PHY_PAGE0, MPI3_POINTER PTR_MPI3_SAS_PHY_PAGE0,
+  Mpi3SasPhyPage0_t, MPI3_POINTER pMpi3SasPhyPage0_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_SASPHY0_PAGEVERSION                        (0x00)
+
+/**** Defines for the AttachedPhyInfo field - use MPI3_SAS_APHYINFO_ defines ****/
+
+/**** Defines for the ProgrammedLinkRate field - use MPI3_SAS_PRATE_ defines ****/
+
+/**** Defines for the HwLinkRate field - use MPI3_SAS_HWRATE_ defines ****/
+
+/**** Defines for the Flags field ****/
+#define MPI3_SASPHY0_FLAGS_SGPIO_DIRECT_ATTACH_ENC      (0x01)
+
+/**** Defines for the PhyInfo field - use MPI3_SAS_PHYINFO_ defines ****/
+
+/**** Defines for the NegotiatedLinkRate field - use MPI3_SAS_NEG_LINK_RATE_ defines ****/
+
+/**** Defines for the Slot field - use MPI3_SLOT_ defines ****/
+
+/**** Defines for the SlotIndex field - use MPI3_SLOT_INDEX_ ****/
+
+/*****************************************************************************
+ *              SAS PHY Page 1                                               *
+ ****************************************************************************/
+typedef struct _MPI3_SAS_PHY_PAGE1 {
+    MPI3_CONFIG_PAGE_HEADER         Header;                         /* 0x00 */
+    U32                             Reserved08;                     /* 0x08 */
+    U32                             InvalidDwordCount;              /* 0x0C */
+    U32                             RunningDisparityErrorCount;     /* 0x10 */
+    U32                             LossDwordSynchCount;            /* 0x14 */
+    U32                             PhyResetProblemCount;           /* 0x18 */
+} MPI3_SAS_PHY_PAGE1, MPI3_POINTER PTR_MPI3_SAS_PHY_PAGE1,
+  Mpi3SasPhyPage1_t, MPI3_POINTER pMpi3SasPhyPage1_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_SASPHY1_PAGEVERSION                        (0x00)
+
+/*****************************************************************************
+ *              SAS PHY Page 2                                               *
+ ****************************************************************************/
+typedef struct _MPI3_SAS_PHY2_PHY_EVENT {
+    U8      PhyEventCode;       /* 0x00 */
+    U8      Reserved01[3];      /* 0x01 */
+    U32     PhyEventInfo;       /* 0x04 */
+} MPI3_SAS_PHY2_PHY_EVENT, MPI3_POINTER PTR_MPI3_SAS_PHY2_PHY_EVENT,
+  Mpi3SasPhy2PhyEvent_t, MPI3_POINTER pMpi3SasPhy2PhyEvent_t;
+
+/**** Defines for the PhyEventCode field - use MPI3_SASPHY3_EVENT_CODE_ defines */
+
+#ifndef MPI3_SAS_PHY2_PHY_EVENT_MAX
+#define MPI3_SAS_PHY2_PHY_EVENT_MAX         (1)
+#endif  /* MPI3_SAS_PHY2_PHY_EVENT_MAX */
+
+typedef struct _MPI3_SAS_PHY_PAGE2 {
+    MPI3_CONFIG_PAGE_HEADER         Header;                                     /* 0x00 */
+    U32                             Reserved08;                                 /* 0x08 */
+    U8                              NumPhyEvents;                               /* 0x0C */
+    U8                              Reserved0D[3];                              /* 0x0D */
+    MPI3_SAS_PHY2_PHY_EVENT         PhyEvent[MPI3_SAS_PHY2_PHY_EVENT_MAX];      /* 0x10 */
+} MPI3_SAS_PHY_PAGE2, MPI3_POINTER PTR_MPI3_SAS_PHY_PAGE2,
+  Mpi3SasPhyPage2_t, MPI3_POINTER pMpi3SasPhyPage2_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_SASPHY2_PAGEVERSION                        (0x00)
+
+/*****************************************************************************
+ *              SAS PHY Page 3                                               *
+ ****************************************************************************/
+typedef struct _MPI3_SAS_PHY3_PHY_EVENT_CONFIG {
+    U8      PhyEventCode;           /* 0x00 */
+    U8      Reserved01[3];          /* 0x01 */
+    U8      CounterType;            /* 0x04 */
+    U8      ThresholdWindow;        /* 0x05 */
+    U8      TimeUnits;              /* 0x06 */
+    U8      Reserved07;             /* 0x07 */
+    U32     EventThreshold;         /* 0x08 */
+    U16     ThresholdFlags;         /* 0x0C */
+    U16     Reserved0E;             /* 0x0E */
+} MPI3_SAS_PHY3_PHY_EVENT_CONFIG, MPI3_POINTER PTR_MPI3_SAS_PHY3_PHY_EVENT_CONFIG,
+  Mpi3SasPhy3PhyEventConfig_t, MPI3_POINTER pMpi3SasPhy3PhyEventConfig_t;
+
+/**** Defines for the PhyEventCode field ****/
+#define MPI3_SASPHY3_EVENT_CODE_NO_EVENT                    (0x00)
+#define MPI3_SASPHY3_EVENT_CODE_INVALID_DWORD               (0x01)
+#define MPI3_SASPHY3_EVENT_CODE_RUNNING_DISPARITY_ERROR     (0x02)
+#define MPI3_SASPHY3_EVENT_CODE_LOSS_DWORD_SYNC             (0x03)
+#define MPI3_SASPHY3_EVENT_CODE_PHY_RESET_PROBLEM           (0x04)
+#define MPI3_SASPHY3_EVENT_CODE_ELASTICITY_BUF_OVERFLOW     (0x05)
+#define MPI3_SASPHY3_EVENT_CODE_RX_ERROR                    (0x06)
+#define MPI3_SASPHY3_EVENT_CODE_INV_SPL_PACKETS             (0x07)
+#define MPI3_SASPHY3_EVENT_CODE_LOSS_SPL_PACKET_SYNC        (0x08)
+#define MPI3_SASPHY3_EVENT_CODE_RX_ADDR_FRAME_ERROR         (0x20)
+#define MPI3_SASPHY3_EVENT_CODE_TX_AC_OPEN_REJECT           (0x21)
+#define MPI3_SASPHY3_EVENT_CODE_RX_AC_OPEN_REJECT           (0x22)
+#define MPI3_SASPHY3_EVENT_CODE_TX_RC_OPEN_REJECT           (0x23)
+#define MPI3_SASPHY3_EVENT_CODE_RX_RC_OPEN_REJECT           (0x24)
+#define MPI3_SASPHY3_EVENT_CODE_RX_AIP_PARTIAL_WAITING_ON   (0x25)
+#define MPI3_SASPHY3_EVENT_CODE_RX_AIP_CONNECT_WAITING_ON   (0x26)
+#define MPI3_SASPHY3_EVENT_CODE_TX_BREAK                    (0x27)
+#define MPI3_SASPHY3_EVENT_CODE_RX_BREAK                    (0x28)
+#define MPI3_SASPHY3_EVENT_CODE_BREAK_TIMEOUT               (0x29)
+#define MPI3_SASPHY3_EVENT_CODE_CONNECTION                  (0x2A)
+#define MPI3_SASPHY3_EVENT_CODE_PEAKTX_PATHWAY_BLOCKED      (0x2B)
+#define MPI3_SASPHY3_EVENT_CODE_PEAKTX_ARB_WAIT_TIME        (0x2C)
+#define MPI3_SASPHY3_EVENT_CODE_PEAK_ARB_WAIT_TIME          (0x2D)
+#define MPI3_SASPHY3_EVENT_CODE_PEAK_CONNECT_TIME           (0x2E)
+#define MPI3_SASPHY3_EVENT_CODE_PERSIST_CONN                (0x2F)
+#define MPI3_SASPHY3_EVENT_CODE_TX_SSP_FRAMES               (0x40)
+#define MPI3_SASPHY3_EVENT_CODE_RX_SSP_FRAMES               (0x41)
+#define MPI3_SASPHY3_EVENT_CODE_TX_SSP_ERROR_FRAMES         (0x42)
+#define MPI3_SASPHY3_EVENT_CODE_RX_SSP_ERROR_FRAMES         (0x43)
+#define MPI3_SASPHY3_EVENT_CODE_TX_CREDIT_BLOCKED           (0x44)
+#define MPI3_SASPHY3_EVENT_CODE_RX_CREDIT_BLOCKED           (0x45)
+#define MPI3_SASPHY3_EVENT_CODE_TX_SATA_FRAMES              (0x50)
+#define MPI3_SASPHY3_EVENT_CODE_RX_SATA_FRAMES              (0x51)
+#define MPI3_SASPHY3_EVENT_CODE_SATA_OVERFLOW               (0x52)
+#define MPI3_SASPHY3_EVENT_CODE_TX_SMP_FRAMES               (0x60)
+#define MPI3_SASPHY3_EVENT_CODE_RX_SMP_FRAMES               (0x61)
+#define MPI3_SASPHY3_EVENT_CODE_RX_SMP_ERROR_FRAMES         (0x63)
+#define MPI3_SASPHY3_EVENT_CODE_HOTPLUG_TIMEOUT             (0xD0)
+#define MPI3_SASPHY3_EVENT_CODE_MISALIGNED_MUX_PRIMITIVE    (0xD1)
+#define MPI3_SASPHY3_EVENT_CODE_RX_AIP                      (0xD2)
+#define MPI3_SASPHY3_EVENT_CODE_LCARB_WAIT_TIME             (0xD3)
+#define MPI3_SASPHY3_EVENT_CODE_RCVD_CONN_RESP_WAIT_TIME    (0xD4)
+#define MPI3_SASPHY3_EVENT_CODE_LCCONN_TIME                 (0xD5)
+#define MPI3_SASPHY3_EVENT_CODE_SSP_TX_START_TRANSMIT       (0xD6)
+#define MPI3_SASPHY3_EVENT_CODE_SATA_TX_START               (0xD7)
+#define MPI3_SASPHY3_EVENT_CODE_SMP_TX_START_TRANSMT        (0xD8)
+#define MPI3_SASPHY3_EVENT_CODE_TX_SMP_BREAK_CONN           (0xD9)
+#define MPI3_SASPHY3_EVENT_CODE_SSP_RX_START_RECEIVE        (0xDA)
+#define MPI3_SASPHY3_EVENT_CODE_SATA_RX_START_RECEIVE       (0xDB)
+#define MPI3_SASPHY3_EVENT_CODE_SMP_RX_START_RECEIVE        (0xDC)
+
+/**** Defines for the CounterType field ****/
+#define MPI3_SASPHY3_COUNTER_TYPE_WRAPPING                  (0x00)
+#define MPI3_SASPHY3_COUNTER_TYPE_SATURATING                (0x01)
+#define MPI3_SASPHY3_COUNTER_TYPE_PEAK_VALUE                (0x02)
+
+/**** Defines for the TimeUnits field ****/
+#define MPI3_SASPHY3_TIME_UNITS_10_MICROSECONDS             (0x00)
+#define MPI3_SASPHY3_TIME_UNITS_100_MICROSECONDS            (0x01)
+#define MPI3_SASPHY3_TIME_UNITS_1_MILLISECOND               (0x02)
+#define MPI3_SASPHY3_TIME_UNITS_10_MILLISECONDS             (0x03)
+
+/**** Defines for the ThresholdFlags field ****/
+#define MPI3_SASPHY3_TFLAGS_PHY_RESET                       (0x0002)
+#define MPI3_SASPHY3_TFLAGS_EVENT_NOTIFY                    (0x0001)
+
+#ifndef MPI3_SAS_PHY3_PHY_EVENT_MAX
+#define MPI3_SAS_PHY3_PHY_EVENT_MAX         (1)
+#endif  /* MPI3_SAS_PHY3_PHY_EVENT_MAX */
+
+typedef struct _MPI3_SAS_PHY_PAGE3 {
+    MPI3_CONFIG_PAGE_HEADER         Header;                                         /* 0x00 */
+    U32                             Reserved08;                                     /* 0x08 */
+    U8                              NumPhyEvents;                                   /* 0x0C */
+    U8                              Reserved0D[3];                                  /* 0x0D */
+    MPI3_SAS_PHY3_PHY_EVENT_CONFIG  PhyEventConfig[MPI3_SAS_PHY3_PHY_EVENT_MAX];    /* 0x10 */
+} MPI3_SAS_PHY_PAGE3, MPI3_POINTER PTR_MPI3_SAS_PHY_PAGE3,
+  Mpi3SasPhyPage3_t, MPI3_POINTER pMpi3SasPhyPage3_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_SASPHY3_PAGEVERSION                        (0x00)
+
+/*****************************************************************************
+ *              SAS PHY Page 4                                               *
+ ****************************************************************************/
+typedef struct _MPI3_SAS_PHY_PAGE4 {
+    MPI3_CONFIG_PAGE_HEADER         Header;             /* 0x00 */
+    U8                              Reserved08[3];      /* 0x08 */
+    U8                              Flags;              /* 0x0B */
+    U8                              InitialFrame[28];   /* 0x0C */
+} MPI3_SAS_PHY_PAGE4, MPI3_POINTER PTR_MPI3_SAS_PHY_PAGE4,
+  Mpi3SasPhyPage4_t, MPI3_POINTER pMpi3SasPhyPage4_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_SASPHY4_PAGEVERSION                        (0x00)
+
+/**** Defines for the Flags field ****/
+#define MPI3_SASPHY4_FLAGS_FRAME_VALID                  (0x02)
+#define MPI3_SASPHY4_FLAGS_SATA_FRAME                   (0x01)
+
+
+/*****************************************************************************
+ *              Common definitions used by PCIe Configuration Pages          *
+ ****************************************************************************/
+
+/**** Defines for Negotiated Link Rates ****/
+#define MPI3_PCIE_LINK_RETIMERS_MASK                    (0x30)
+#define MPI3_PCIE_LINK_RETIMERS_SHIFT                   (4)
+#define MPI3_PCIE_NEG_LINK_RATE_MASK                    (0x0F)
+#define MPI3_PCIE_NEG_LINK_RATE_UNKNOWN                 (0x00)
+#define MPI3_PCIE_NEG_LINK_RATE_PHY_DISABLED            (0x01)
+#define MPI3_PCIE_NEG_LINK_RATE_2_5                     (0x02)
+#define MPI3_PCIE_NEG_LINK_RATE_5_0                     (0x03)
+#define MPI3_PCIE_NEG_LINK_RATE_8_0                     (0x04)
+#define MPI3_PCIE_NEG_LINK_RATE_16_0                    (0x05)
+#define MPI3_PCIE_NEG_LINK_RATE_32_0                    (0x06)
+
+/*****************************************************************************
+ *              PCIe IO Unit Configuration Pages                             *
+ ****************************************************************************/
+
+/*****************************************************************************
+ *              PCIe IO Unit Page 0                                          *
+ ****************************************************************************/
+typedef struct _MPI3_PCIE_IO_UNIT0_PHY_DATA {
+    U8      Link;                       /* 0x00 */
+    U8      LinkFlags;                  /* 0x01 */
+    U8      PhyFlags;                   /* 0x02 */
+    U8      NegotiatedLinkRate;         /* 0x03 */
+    U16     AttachedDevHandle;          /* 0x04 */
+    U16     ControllerDevHandle;        /* 0x06 */
+    U32     EnumerationStatus;          /* 0x08 */
+    U8      IOUnitPort;                 /* 0x0C */
+    U8      Reserved0D[3];              /* 0x0D */
+} MPI3_PCIE_IO_UNIT0_PHY_DATA, MPI3_POINTER PTR_MPI3_PCIE_IO_UNIT0_PHY_DATA,
+  Mpi3PcieIOUnit0PhyData_t, MPI3_POINTER pMpi3PcieIOUnit0PhyData_t;
+
+/**** Defines for the LinkFlags field ****/
+#define MPI3_PCIEIOUNIT0_LINKFLAGS_CONFIG_SOURCE_MASK      (0x10)
+#define MPI3_PCIEIOUNIT0_LINKFLAGS_CONFIG_SOURCE_IOUNIT1   (0x00)
+#define MPI3_PCIEIOUNIT0_LINKFLAGS_CONFIG_SOURCE_BKPLANE   (0x10)
+#define MPI3_PCIEIOUNIT0_LINKFLAGS_ENUM_IN_PROGRESS        (0x08)
+
+/**** Defines for the PhyFlags field ****/
+#define MPI3_PCIEIOUNIT0_PHYFLAGS_PHY_DISABLED          (0x08)
+#define MPI3_PCIEIOUNIT0_PHYFLAGS_HOST_PHY              (0x01)
+
+/**** Defines for the NegotiatedLinkRate field - use MPI3_PCIE_NEG_LINK_RATE_ defines ****/
+
+/**** Defines for the EnumerationStatus field ****/
+#define MPI3_PCIEIOUNIT0_ES_MAX_SWITCH_DEPTH_EXCEEDED   (0x80000000)
+#define MPI3_PCIEIOUNIT0_ES_MAX_SWITCHES_EXCEEDED       (0x40000000)
+#define MPI3_PCIEIOUNIT0_ES_MAX_ENDPOINTS_EXCEEDED      (0x20000000)
+#define MPI3_PCIEIOUNIT0_ES_INSUFFICIENT_RESOURCES      (0x10000000)
+
+#ifndef MPI3_PCIE_IO_UNIT0_PHY_MAX
+#define MPI3_PCIE_IO_UNIT0_PHY_MAX      (1)
+#endif  /* MPI3_PCIE_IO_UNIT0_PHY_MAX */
+
+typedef struct _MPI3_PCIE_IO_UNIT_PAGE0 {
+    MPI3_CONFIG_PAGE_HEADER         Header;                                 /* 0x00 */
+    U32                             Reserved08;                             /* 0x08 */
+    U8                              NumPhys;                                /* 0x0C */
+    U8                              InitStatus;                             /* 0x0D */
+    U16                             Reserved0E;                             /* 0x0E */
+    MPI3_PCIE_IO_UNIT0_PHY_DATA     PhyData[MPI3_PCIE_IO_UNIT0_PHY_MAX];    /* 0x10 */
+} MPI3_PCIE_IO_UNIT_PAGE0, MPI3_POINTER PTR_MPI3_PCIE_IO_UNIT_PAGE0,
+  Mpi3PcieIOUnitPage0_t, MPI3_POINTER pMpi3PcieIOUnitPage0_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_PCIEIOUNIT0_PAGEVERSION                        (0x00)
+
+/**** Defines for the InitStatus field ****/
+#define MPI3_PCIEIOUNIT0_INITSTATUS_NO_ERRORS               (0x00)
+#define MPI3_PCIEIOUNIT0_INITSTATUS_NEEDS_INITIALIZATION    (0x01)
+#define MPI3_PCIEIOUNIT0_INITSTATUS_NO_TARGETS_ALLOCATED    (0x02)
+#define MPI3_PCIEIOUNIT0_INITSTATUS_RESOURCE_ALLOC_FAILED   (0x03)
+#define MPI3_PCIEIOUNIT0_INITSTATUS_BAD_NUM_PHYS            (0x04)
+#define MPI3_PCIEIOUNIT0_INITSTATUS_UNSUPPORTED_CONFIG      (0x05)
+#define MPI3_PCIEIOUNIT0_INITSTATUS_HOST_PORT_MISMATCH      (0x06)
+#define MPI3_PCIEIOUNIT0_INITSTATUS_PHYS_NOT_CONSECUTIVE    (0x07)
+#define MPI3_PCIEIOUNIT0_INITSTATUS_BAD_CLOCKING_MODE       (0x08)
+#define MPI3_PCIEIOUNIT0_INITSTATUS_PROD_SPEC_START         (0xF0)
+#define MPI3_PCIEIOUNIT0_INITSTATUS_PROD_SPEC_END           (0xFF)
+
+/*****************************************************************************
+ *              PCIe IO Unit Page 1                                          *
+ ****************************************************************************/
+typedef struct _MPI3_PCIE_IO_UNIT1_PHY_DATA {
+    U8      Link;                       /* 0x00 */
+    U8      LinkFlags;                  /* 0x01 */
+    U8      PhyFlags;                   /* 0x02 */
+    U8      MaxMinLinkRate;             /* 0x03 */
+    U32     Reserved04;                 /* 0x04 */
+    U32     Reserved08;                 /* 0x08 */
+} MPI3_PCIE_IO_UNIT1_PHY_DATA, MPI3_POINTER PTR_MPI3_PCIE_IO_UNIT1_PHY_DATA,
+  Mpi3PcieIOUnit1PhyData_t, MPI3_POINTER pMpi3PcieIOUnit1PhyData_t;
+
+/**** Defines for the LinkFlags field ****/
+#define MPI3_PCIEIOUNIT1_LINKFLAGS_PCIE_CLK_MODE_MASK                     (0x03)
+#define MPI3_PCIEIOUNIT1_LINKFLAGS_PCIE_CLK_MODE_DIS_SEPARATE_REFCLK      (0x00)
+#define MPI3_PCIEIOUNIT1_LINKFLAGS_PCIE_CLK_MODE_EN_SRIS                  (0x01)
+#define MPI3_PCIEIOUNIT1_LINKFLAGS_PCIE_CLK_MODE_EN_SRNS                  (0x02)
+
+/**** Defines for the PhyFlags field ****/
+#define MPI3_PCIEIOUNIT1_PHYFLAGS_PHY_DISABLE               (0x08)
+
+/**** Defines for the MaxMinLinkRate ****/
+#define MPI3_PCIEIOUNIT1_MMLR_MAX_RATE_MASK                      (0xF0)
+#define MPI3_PCIEIOUNIT1_MMLR_MAX_RATE_SHIFT                     (4)
+#define MPI3_PCIEIOUNIT1_MMLR_MAX_RATE_2_5                       (0x20)
+#define MPI3_PCIEIOUNIT1_MMLR_MAX_RATE_5_0                       (0x30)
+#define MPI3_PCIEIOUNIT1_MMLR_MAX_RATE_8_0                       (0x40)
+#define MPI3_PCIEIOUNIT1_MMLR_MAX_RATE_16_0                      (0x50)
+#define MPI3_PCIEIOUNIT1_MMLR_MAX_RATE_32_0                      (0x60)
+
+#ifndef MPI3_PCIE_IO_UNIT1_PHY_MAX
+#define MPI3_PCIE_IO_UNIT1_PHY_MAX          (1)
+#endif  /* MPI3_PCIE_IO_UNIT1_PHY_MAX */
+
+typedef struct _MPI3_PCIE_IO_UNIT_PAGE1 {
+    MPI3_CONFIG_PAGE_HEADER         Header;                                 /* 0x00 */
+    U32                             ControlFlags;                           /* 0x08 */
+    U32                             Reserved0C;                             /* 0x0C */
+    U8                              NumPhys;                                /* 0x10 */
+    U8                              Reserved11;                             /* 0x11 */
+    U16                             Reserved12;                             /* 0x12 */
+    MPI3_PCIE_IO_UNIT1_PHY_DATA     PhyData[MPI3_PCIE_IO_UNIT1_PHY_MAX];    /* 0x14 */
+} MPI3_PCIE_IO_UNIT_PAGE1, MPI3_POINTER PTR_MPI3_PCIE_IO_UNIT_PAGE1,
+  Mpi3PcieIOUnitPage1_t, MPI3_POINTER pMpi3PcieIOUnitPage1_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_PCIEIOUNIT1_PAGEVERSION                        (0x00)
+
+/*****************************************************************************
+ *              PCIe IO Unit Page 2                                          *
+ ****************************************************************************/
+typedef struct _MPI3_PCIE_IO_UNIT_PAGE2 {
+    MPI3_CONFIG_PAGE_HEADER         Header;                                 /* 0x00 */
+    U16                             NVMeMaxQueueDepth;                      /* 0x08 */
+    U16                             Reserved0A;                             /* 0x0A */
+    U8                              NVMeAbortTO;                            /* 0x0C */
+    U8                              Reserved0D;                             /* 0x0D */
+    U16                             Reserved0E;                             /* 0x0E */
+} MPI3_PCIE_IO_UNIT_PAGE2, MPI3_POINTER PTR_MPI3_PCIE_IO_UNIT_PAGE2,
+  Mpi3PcieIOUnitPage2_t, MPI3_POINTER pMpi3PcieIOUnitPage2_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_PCIEIOUNIT2_PAGEVERSION                        (0x00)
+
+/*****************************************************************************
+ *              PCIe Switch Configuration Pages                              *
+ ****************************************************************************/
+
+/*****************************************************************************
+ *              PCIe Switch Page 0                                           *
+ ****************************************************************************/
+typedef struct _MPI3_PCIE_SWITCH_PAGE0 {
+    MPI3_CONFIG_PAGE_HEADER     Header;             /* 0x00 */
+    U8                          IOUnitPort;         /* 0x08 */
+    U8                          SwitchStatus;       /* 0x09 */
+    U8                          Reserved0A[2];      /* 0x0A */
+    U16                         DevHandle;          /* 0x0C */
+    U16                         ParentDevHandle;    /* 0x0E */
+    U8                          NumPorts;           /* 0x10 */
+    U8                          PCIeLevel;          /* 0x11 */
+    U16                         Reserved12;         /* 0x12 */
+    U32                         Reserved14;         /* 0x14 */
+    U32                         Reserved18;         /* 0x18 */
+    U32                         Reserved1C;         /* 0x1C */
+} MPI3_PCIE_SWITCH_PAGE0, MPI3_POINTER PTR_MPI3_PCIE_SWITCH_PAGE0,
+  Mpi3PcieSwitchPage0_t, MPI3_POINTER pMpi3PcieSwitchPage0_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_PCIESWITCH0_PAGEVERSION                  (0x00)
+
+/**** Defines for the SwitchStatus field ****/
+#define MPI3_PCIESWITCH0_SS_NOT_RESPONDING            (0x02)
+#define MPI3_PCIESWITCH0_SS_RESPONDING                (0x03)
+#define MPI3_PCIESWITCH0_SS_DELAY_NOT_RESPONDING      (0x04)
+
+/*****************************************************************************
+ *              PCIe Switch Page 1                                           *
+ ****************************************************************************/
+typedef struct _MPI3_PCIE_SWITCH_PAGE1 {
+    MPI3_CONFIG_PAGE_HEADER     Header;                 /* 0x00 */
+    U8                          IOUnitPort;             /* 0x08 */
+    U8                          Reserved09[3];          /* 0x09 */
+    U8                          NumPorts;               /* 0x0C */
+    U8                          PortNum;                /* 0x0D */
+    U16                         AttachedDevHandle;      /* 0x0E */
+    U16                         SwitchDevHandle;        /* 0x10 */
+    U8                          NegotiatedPortWidth;    /* 0x12 */
+    U8                          NegotiatedLinkRate;     /* 0x13 */
+    U16                         Slot;                   /* 0x14 */
+    U16                         SlotIndex;              /* 0x16 */
+    U32                         Reserved18;             /* 0x18 */
+} MPI3_PCIE_SWITCH_PAGE1, MPI3_POINTER PTR_MPI3_PCIE_SWITCH_PAGE1,
+  Mpi3PcieSwitchPage1_t, MPI3_POINTER pMpi3PcieSwitchPage1_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_PCIESWITCH1_PAGEVERSION        (0x00)
+
+/**** Defines for the NegotiatedLinkRate field - use MPI3_PCIE_NEG_LINK_RATE_ defines ****/
+
+/**** Defines for the Slot field - use MPI3_SLOT_ defines ****/
+
+/**** Defines for the SlotIndex field - use MPI3_SLOT_INDEX_ ****/
+
+/*****************************************************************************
+ *              PCIe Link Configuration Pages                                *
+ ****************************************************************************/
+typedef struct _MPI3_PCIE_LINK_PAGE0 {
+    MPI3_CONFIG_PAGE_HEADER     Header;                 /* 0x00 */
+    U8                          Link;                   /* 0x08 */
+    U8                          Reserved09[3];          /* 0x09 */
+    U32                         CorrectableErrorCount;  /* 0x0C */
+    U16                         NFatalErrorCount;       /* 0x10 */
+    U16                         Reserved12;             /* 0x12 */
+    U16                         FatalErrorCount;        /* 0x14 */
+    U16                         Reserved16;             /* 0x16 */
+} MPI3_PCIE_LINK_PAGE0, MPI3_POINTER PTR_MPI3_PCIE_LINK_PAGE0,
+  Mpi3PcieLinkPage0_t, MPI3_POINTER pMpi3PcieLinkPage0_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_PCIELINK0_PAGEVERSION          (0x00)
+
+
+/*****************************************************************************
+ *              Enclosure Configuration Pages                                *
+ ****************************************************************************/
+
+/*****************************************************************************
+ *              Enclosure Page 0                                             *
+ ****************************************************************************/
+typedef struct _MPI3_ENCLOSURE_PAGE0 {
+    MPI3_CONFIG_PAGE_HEADER         Header;                 /* 0x00 */
+    U64                             EnclosureLogicalID;     /* 0x08 */
+    U16                             Flags;                  /* 0x10 */
+    U16                             EnclosureHandle;        /* 0x12 */
+    U16                             NumSlots;               /* 0x14 */
+    U16                             StartSlot;              /* 0x16 */
+    U8                              IOUnitPort;             /* 0x18 */
+    U8                              EnclosureLevel;         /* 0x19 */
+    U16                             SEPDevHandle;           /* 0x1A */
+    U32                             Reserved1C;             /* 0x1C */
+} MPI3_ENCLOSURE_PAGE0, MPI3_POINTER PTR_MPI3_ENCLOSURE_PAGE0,
+  Mpi3EnclosurePage0_t, MPI3_POINTER pMpi3EnclosurePage0_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_ENCLOSURE0_PAGEVERSION                     (0x00)
+
+/**** Defines for the Flags field ****/
+#define MPI3_ENCLS0_FLAGS_ENCL_TYPE_MASK                (0xC000)
+#define MPI3_ENCLS0_FLAGS_ENCL_TYPE_VIRTUAL             (0x0000)
+#define MPI3_ENCLS0_FLAGS_ENCL_TYPE_SAS                 (0x4000)
+#define MPI3_ENCLS0_FLAGS_ENCL_TYPE_PCIE                (0x8000)
+#define MPI3_ENCLS0_FLAGS_ENCL_DEV_PRESENT_MASK         (0x0010)
+#define MPI3_ENCLS0_FLAGS_ENCL_DEV_NOT_FOUND            (0x0000)
+#define MPI3_ENCLS0_FLAGS_ENCL_DEV_PRESENT              (0x0010)
+#define MPI3_ENCLS0_FLAGS_MNG_MASK                      (0x000F)
+#define MPI3_ENCLS0_FLAGS_MNG_UNKNOWN                   (0x0000)
+#define MPI3_ENCLS0_FLAGS_MNG_IOC_SES                   (0x0001)
+#define MPI3_ENCLS0_FLAGS_MNG_SES_ENCLOSURE             (0x0002)
+
+/**** Defines for the PhysicalPort field - use MPI3_DEVICE0_PHYPORT_ defines ****/
+
+/*****************************************************************************
+ *              Device Configuration Pages                                   *
+ ****************************************************************************/
+
+/*****************************************************************************
+ *              Common definitions used by Device Configuration Pages           *
+ ****************************************************************************/
+
+/**** Defines for the DeviceForm field ****/
+#define MPI3_DEVICE_DEVFORM_SAS_SATA                    (0x00)
+#define MPI3_DEVICE_DEVFORM_PCIE                        (0x01)
+#define MPI3_DEVICE_DEVFORM_VD                          (0x02)
+
+/*****************************************************************************
+ *              Device Page 0                                                *
+ ****************************************************************************/
+typedef struct _MPI3_DEVICE0_SAS_SATA_FORMAT {
+    U64     SASAddress;                 /* 0x00 */
+    U16     Flags;                      /* 0x08 */
+    U16     DeviceInfo;                 /* 0x0A */
+    U8      PhyNum;                     /* 0x0C */
+    U8      AttachedPhyIdentifier;      /* 0x0D */
+    U8      MaxPortConnections;         /* 0x0E */
+    U8      ZoneGroup;                  /* 0x0F */
+} MPI3_DEVICE0_SAS_SATA_FORMAT, MPI3_POINTER PTR_MPI3_DEVICE0_SAS_SATA_FORMAT,
+  Mpi3Device0SasSataFormat_t, MPI3_POINTER pMpi3Device0SasSataFormat_t;
+
+/**** Defines for the Flags field ****/
+#define MPI3_DEVICE0_SASSATA_FLAGS_SLUMBER_CAP          (0x0200)
+#define MPI3_DEVICE0_SASSATA_FLAGS_PARTIAL_CAP          (0x0100)
+#define MPI3_DEVICE0_SASSATA_FLAGS_ASYNC_NOTIFY         (0x0080)
+#define MPI3_DEVICE0_SASSATA_FLAGS_SW_PRESERVE          (0x0040)
+#define MPI3_DEVICE0_SASSATA_FLAGS_UNSUPP_DEV           (0x0020)
+#define MPI3_DEVICE0_SASSATA_FLAGS_48BIT_LBA            (0x0010)
+#define MPI3_DEVICE0_SASSATA_FLAGS_SMART_SUPP           (0x0008)
+#define MPI3_DEVICE0_SASSATA_FLAGS_NCQ_SUPP             (0x0004)
+#define MPI3_DEVICE0_SASSATA_FLAGS_FUA_SUPP             (0x0002)
+#define MPI3_DEVICE0_SASSATA_FLAGS_PERSIST_CAP          (0x0001)
+
+/**** Defines for the DeviceInfo field - use MPI3_SAS_DEVICE_INFO_ defines (see mpi30_sas.h) ****/
+
+typedef struct _MPI3_DEVICE0_PCIE_FORMAT {
+    U8      SupportedLinkRates;         /* 0x00 */
+    U8      MaxPortWidth;               /* 0x01 */
+    U8      NegotiatedPortWidth;        /* 0x02 */
+    U8      NegotiatedLinkRate;         /* 0x03 */
+    U8      PortNum;                    /* 0x04 */
+    U8      ControllerResetTO;          /* 0x05 */
+    U16     DeviceInfo;                 /* 0x06 */
+    U32     MaximumDataTransferSize;    /* 0x08 */
+    U32     Capabilities;               /* 0x0C */
+    U16     NOIOB;                      /* 0x10 */
+    U8      NVMeAbortTO;                /* 0x12 */
+    U8      PageSize;                   /* 0x13 */
+    U16     ShutdownLatency;            /* 0x14 */
+    U16     Reserved16;                 /* 0x16 */
+} MPI3_DEVICE0_PCIE_FORMAT, MPI3_POINTER PTR_MPI3_DEVICE0_PCIE_FORMAT,
+  Mpi3Device0PcieFormat_t, MPI3_POINTER pMpi3Device0PcieFormat_t;
+
+/**** Defines for the SupportedLinkRates field ****/
+#define MPI3_DEVICE0_PCIE_LINK_RATE_32_0_SUPP           (0x10)
+#define MPI3_DEVICE0_PCIE_LINK_RATE_16_0_SUPP           (0x08)
+#define MPI3_DEVICE0_PCIE_LINK_RATE_8_0_SUPP            (0x04)
+#define MPI3_DEVICE0_PCIE_LINK_RATE_5_0_SUPP            (0x02)
+#define MPI3_DEVICE0_PCIE_LINK_RATE_2_5_SUPP            (0x01)
+
+/**** Defines for the NegotiatedLinkRate field - use MPI3_PCIE_NEG_LINK_RATE_ defines ****/
+
+/**** Defines for DeviceInfo bitfield ****/
+#define MPI3_DEVICE0_PCIE_DEVICE_INFO_TYPE_MASK             (0x0003)
+#define MPI3_DEVICE0_PCIE_DEVICE_INFO_TYPE_NO_DEVICE        (0x0000)
+#define MPI3_DEVICE0_PCIE_DEVICE_INFO_TYPE_NVME_DEVICE      (0x0001)
+#define MPI3_DEVICE0_PCIE_DEVICE_INFO_TYPE_SWITCH_DEVICE    (0x0002)
+#define MPI3_DEVICE0_PCIE_DEVICE_INFO_TYPE_SCSI_DEVICE      (0x0003)
+
+/**** Defines for the Capabilities field ****/
+#define MPI3_DEVICE0_PCIE_CAP_METADATA_SEPARATED            (0x00000010)
+#define MPI3_DEVICE0_PCIE_CAP_SGL_DWORD_ALIGN_REQUIRED      (0x00000008)
+#define MPI3_DEVICE0_PCIE_CAP_NVME_SGL_ENABLED              (0x00000004)
+#define MPI3_DEVICE0_PCIE_CAP_BIT_BUCKET_SGL_SUPP           (0x00000002)
+#define MPI3_DEVICE0_PCIE_CAP_SGL_SUPP                      (0x00000001)
+
+typedef struct _MPI3_DEVICE0_VD_FORMAT {
+    U8      VdState;              /* 0x00 */
+    U8      RAIDLevel;            /* 0x01 */
+    U16     DeviceInfo;           /* 0x02 */
+    U16     Flags;                /* 0x04 */
+    U16     Reserved06;           /* 0x06 */
+    U32     Reserved08[2];        /* 0x08 */
+} MPI3_DEVICE0_VD_FORMAT, MPI3_POINTER PTR_MPI3_DEVICE0_VD_FORMAT,
+  Mpi3Device0VdFormat_t, MPI3_POINTER pMpi3Device0VdFormat_t;
+
+/**** Defines for the VdState field ****/
+#define MPI3_DEVICE0_VD_STATE_OFFLINE                       (0x00)
+#define MPI3_DEVICE0_VD_STATE_PARTIALLY_DEGRADED            (0x01)
+#define MPI3_DEVICE0_VD_STATE_DEGRADED                      (0x02)
+#define MPI3_DEVICE0_VD_STATE_OPTIMAL                       (0x03)
+
+/**** Defines for RAIDLevel field ****/
+#define MPI3_DEVICE0_VD_RAIDLEVEL_RAID_0                    (0)
+#define MPI3_DEVICE0_VD_RAIDLEVEL_RAID_1                    (1)
+#define MPI3_DEVICE0_VD_RAIDLEVEL_RAID_5                    (5)
+#define MPI3_DEVICE0_VD_RAIDLEVEL_RAID_6                    (6)
+#define MPI3_DEVICE0_VD_RAIDLEVEL_RAID_10                   (10)
+#define MPI3_DEVICE0_VD_RAIDLEVEL_RAID_50                   (50)
+#define MPI3_DEVICE0_VD_RAIDLEVEL_RAID_60                   (60)
+
+/**** Defines for DeviceInfo field ****/
+#define MPI3_DEVICE0_VD_DEVICE_INFO_HDD                     (0x0010)
+#define MPI3_DEVICE0_VD_DEVICE_INFO_SSD                     (0x0008)
+#define MPI3_DEVICE0_VD_DEVICE_INFO_NVME                    (0x0004)
+#define MPI3_DEVICE0_VD_DEVICE_INFO_SATA                    (0x0002)
+#define MPI3_DEVICE0_VD_DEVICE_INFO_SAS                     (0x0001)
+
+/**** Defines for the Flags field ****/
+#define MPI3_DEVICE0_VD_FLAGS_METADATA_MODE_MASK            (0x0003)
+#define MPI3_DEVICE0_VD_FLAGS_METADATA_MODE_NONE            (0x0000)
+#define MPI3_DEVICE0_VD_FLAGS_METADATA_MODE_HOST            (0x0001)
+#define MPI3_DEVICE0_VD_FLAGS_METADATA_MODE_IOC             (0x0002)
+
+typedef union _MPI3_DEVICE0_DEV_SPEC_FORMAT {
+    MPI3_DEVICE0_SAS_SATA_FORMAT        SasSataFormat;
+    MPI3_DEVICE0_PCIE_FORMAT            PcieFormat;
+    MPI3_DEVICE0_VD_FORMAT              VdFormat;
+} MPI3_DEVICE0_DEV_SPEC_FORMAT, MPI3_POINTER PTR_MPI3_DEVICE0_DEV_SPEC_FORMAT,
+  Mpi3Device0DevSpecFormat_t, MPI3_POINTER pMpi3Device0DevSpecFormat_t;
+
+typedef struct _MPI3_DEVICE_PAGE0 {
+    MPI3_CONFIG_PAGE_HEADER         Header;                 /* 0x00 */
+    U16                             DevHandle;              /* 0x08 */
+    U16                             ParentDevHandle;        /* 0x0A */
+    U16                             Slot;                   /* 0x0C */
+    U16                             EnclosureHandle;        /* 0x0E */
+    U64                             WWID;                   /* 0x10 */
+    U16                             PersistentID;           /* 0x18 */
+    U8                              IOUnitPort;             /* 0x1A */
+    U8                              AccessStatus;           /* 0x1B */
+    U16                             Flags;                  /* 0x1C */
+    U16                             Reserved1E;             /* 0x1E */
+    U16                             SlotIndex;              /* 0x20 */
+    U16                             QueueDepth;             /* 0x22 */
+    U8                              Reserved24[3];          /* 0x24 */
+    U8                              DeviceForm;             /* 0x27 */
+    MPI3_DEVICE0_DEV_SPEC_FORMAT    DeviceSpecific;         /* 0x28 */
+} MPI3_DEVICE_PAGE0, MPI3_POINTER PTR_MPI3_DEVICE_PAGE0,
+  Mpi3DevicePage0_t, MPI3_POINTER pMpi3DevicePage0_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_DEVICE0_PAGEVERSION                        (0x00)
+
+/**** Defines for the Slot field - use MPI3_SLOT_ defines ****/
+
+/**** Defines for the WWID field ****/
+#define MPI3_DEVICE0_WWID_INVALID                       (0xFFFFFFFFFFFFFFFF)
+
+/**** Defines for the PersistentID field ****/
+#define MPI3_DEVICE0_PERSISTENTID_INVALID               (0xFFFF)
+
+/**** Defines for the IOUnitPort field ****/
+#define MPI3_DEVICE0_IOUNITPORT_INVALID                 (0xFF)
+
+/**** Defines for the AccessStatus field ****/
+/* Generic Access Status Codes  */
+#define MPI3_DEVICE0_ASTATUS_NO_ERRORS                              (0x00)
+#define MPI3_DEVICE0_ASTATUS_NEEDS_INITIALIZATION                   (0x01)
+#define MPI3_DEVICE0_ASTATUS_CAP_UNSUPPORTED                        (0x02)
+#define MPI3_DEVICE0_ASTATUS_DEVICE_BLOCKED                         (0x03)
+#define MPI3_DEVICE0_ASTATUS_UNAUTHORIZED                           (0x04)
+#define MPI3_DEVICE0_ASTATUS_DEVICE_MISSING_DELAY                   (0x05)
+/* SAS Access Status Codes  */
+#define MPI3_DEVICE0_ASTATUS_SAS_UNKNOWN                            (0x10)
+#define MPI3_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE                  (0x11)
+#define MPI3_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE              (0x12)
+/* SATA Access Status Codes  */
+#define MPI3_DEVICE0_ASTATUS_SIF_UNKNOWN                            (0x20)
+#define MPI3_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT               (0x21)
+#define MPI3_DEVICE0_ASTATUS_SIF_DIAG                               (0x22)
+#define MPI3_DEVICE0_ASTATUS_SIF_IDENTIFICATION                     (0x23)
+#define MPI3_DEVICE0_ASTATUS_SIF_CHECK_POWER                        (0x24)
+#define MPI3_DEVICE0_ASTATUS_SIF_PIO_SN                             (0x25)
+#define MPI3_DEVICE0_ASTATUS_SIF_MDMA_SN                            (0x26)
+#define MPI3_DEVICE0_ASTATUS_SIF_UDMA_SN                            (0x27)
+#define MPI3_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION                   (0x28)
+#define MPI3_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE                    (0x29)
+#define MPI3_DEVICE0_ASTATUS_SIF_MAX                                (0x2F)
+/* PCIe Access Status Codes  */
+#define MPI3_DEVICE0_ASTATUS_PCIE_UNKNOWN                           (0x30)
+#define MPI3_DEVICE0_ASTATUS_PCIE_MEM_SPACE_ACCESS                  (0x31)
+#define MPI3_DEVICE0_ASTATUS_PCIE_UNSUPPORTED                       (0x32)
+#define MPI3_DEVICE0_ASTATUS_PCIE_MSIX_REQUIRED                     (0x33)
+/* NVMe Access Status Codes  */
+#define MPI3_DEVICE0_ASTATUS_NVME_UNKNOWN                           (0x40)
+#define MPI3_DEVICE0_ASTATUS_NVME_READY_TIMEOUT                     (0x41)
+#define MPI3_DEVICE0_ASTATUS_NVME_DEVCFG_UNSUPPORTED                (0x42)
+#define MPI3_DEVICE0_ASTATUS_NVME_IDENTIFY_FAILED                   (0x43)
+#define MPI3_DEVICE0_ASTATUS_NVME_QCONFIG_FAILED                    (0x44)
+#define MPI3_DEVICE0_ASTATUS_NVME_QCREATION_FAILED                  (0x45)
+#define MPI3_DEVICE0_ASTATUS_NVME_EVENTCFG_FAILED                   (0x46)
+#define MPI3_DEVICE0_ASTATUS_NVME_GET_FEATURE_STAT_FAILED           (0x47)
+#define MPI3_DEVICE0_ASTATUS_NVME_IDLE_TIMEOUT                      (0x48)
+#define MPI3_DEVICE0_ASTATUS_NVME_CTRL_FAILURE_STATUS               (0x49)
+/* Virtual Device Access Status Codes  */
+#define MPI3_DEVICE0_ASTATUS_VD_UNKNOWN                             (0x50)
+
+/**** Defines for the Flags field ****/
+#define MPI3_DEVICE0_FLAGS_CONTROLLER_DEV_HANDLE        (0x0080)
+#define MPI3_DEVICE0_FLAGS_HIDDEN                       (0x0008)
+#define MPI3_DEVICE0_FLAGS_ATT_METHOD_MASK              (0x0006)
+#define MPI3_DEVICE0_FLAGS_ATT_METHOD_NOT_DIR_ATTACHED  (0x0000)
+#define MPI3_DEVICE0_FLAGS_ATT_METHOD_DIR_ATTACHED      (0x0002)
+#define MPI3_DEVICE0_FLAGS_ATT_METHOD_VIRTUAL           (0x0004)
+#define MPI3_DEVICE0_FLAGS_DEVICE_PRESENT               (0x0001)
+
+/**** Defines for the SlotIndex field - use MPI3_SLOT_INDEX_ defines ****/
+
+/**** Defines for the DeviceForm field - use MPI3_DEVICE_DEVFORM_ defines ****/
+
+/**** Defines for the QueueDepth field ****/
+#define MPI3_DEVICE0_QUEUE_DEPTH_NOT_APPLICABLE         (0x0000)
+
+
+/*****************************************************************************
+ *              Device Page 1                                                *
+ ****************************************************************************/
+typedef struct _MPI3_DEVICE1_SAS_SATA_FORMAT {
+    U32                             Reserved00;             /* 0x00 */
+} MPI3_DEVICE1_SAS_SATA_FORMAT, MPI3_POINTER PTR_MPI3_DEVICE1_SAS_SATA_FORMAT,
+  Mpi3Device1SasSataFormat_t, MPI3_POINTER pMpi3Device1SasSataFormat_t;
+
+typedef struct _MPI3_DEVICE1_PCIE_FORMAT {
+    U16                             VendorID;               /* 0x00 */
+    U16                             DeviceID;               /* 0x02 */
+    U16                             SubsystemVendorID;      /* 0x04 */
+    U16                             SubsystemID;            /* 0x06 */
+    U32                             Reserved08;             /* 0x08 */
+    U8                              RevisionID;             /* 0x0C */
+    U8                              Reserved0D;             /* 0x0D */
+    U16                             PCIParameters;          /* 0x0E */
+} MPI3_DEVICE1_PCIE_FORMAT, MPI3_POINTER PTR_MPI3_DEVICE1_PCIE_FORMAT,
+  Mpi3Device1PcieFormat_t, MPI3_POINTER pMpi3Device1PcieFormat_t;
+
+/**** Defines for the PCIParameters field ****/
+#define MPI3_DEVICE1_PCIE_PARAMS_DATA_SIZE_128B              (0x0)
+#define MPI3_DEVICE1_PCIE_PARAMS_DATA_SIZE_256B              (0x1)
+#define MPI3_DEVICE1_PCIE_PARAMS_DATA_SIZE_512B              (0x2)
+#define MPI3_DEVICE1_PCIE_PARAMS_DATA_SIZE_1024B             (0x3)
+#define MPI3_DEVICE1_PCIE_PARAMS_DATA_SIZE_2048B             (0x4)
+#define MPI3_DEVICE1_PCIE_PARAMS_DATA_SIZE_4096B             (0x5)
+
+/*** MaxReadRequestSize, CurrentMaxPayloadSize, and MaxPayloadSizeSupported  ***/
+/***  all use the size definitions above - shifted to the proper position    ***/
+#define MPI3_DEVICE1_PCIE_PARAMS_MAX_READ_REQ_MASK           (0x01C0)
+#define MPI3_DEVICE1_PCIE_PARAMS_MAX_READ_REQ_SHIFT          (6)
+#define MPI3_DEVICE1_PCIE_PARAMS_CURR_MAX_PAYLOAD_MASK       (0x0038)
+#define MPI3_DEVICE1_PCIE_PARAMS_CURR_MAX_PAYLOAD_SHIFT      (3)
+#define MPI3_DEVICE1_PCIE_PARAMS_SUPP_MAX_PAYLOAD_MASK       (0x0007)
+#define MPI3_DEVICE1_PCIE_PARAMS_SUPP_MAX_PAYLOAD_SHIFT      (0)
+
+typedef struct _MPI3_DEVICE1_VD_FORMAT {
+    U32                             Reserved00;             /* 0x00 */
+} MPI3_DEVICE1_VD_FORMAT, MPI3_POINTER PTR_MPI3_DEVICE1_VD_FORMAT,
+  Mpi3Device1VdFormat_t, MPI3_POINTER pMpi3Device1VdFormat_t;
+
+typedef union _MPI3_DEVICE1_DEV_SPEC_FORMAT {
+    MPI3_DEVICE1_SAS_SATA_FORMAT    SasSataFormat;
+    MPI3_DEVICE1_PCIE_FORMAT        PcieFormat;
+    MPI3_DEVICE1_VD_FORMAT          VdFormat;
+} MPI3_DEVICE1_DEV_SPEC_FORMAT, MPI3_POINTER PTR_MPI3_DEVICE1_DEV_SPEC_FORMAT,
+  Mpi3Device1DevSpecFormat_t, MPI3_POINTER pMpi3Device1DevSpecFormat_t;
+
+typedef struct _MPI3_DEVICE_PAGE1 {
+    MPI3_CONFIG_PAGE_HEADER         Header;                 /* 0x00 */
+    U16                             DevHandle;              /* 0x08 */
+    U16                             Reserved0A;             /* 0x0A */
+    U32                             Reserved0C[12];         /* 0x0C */
+    U8                              Reserved3C[3];          /* 0x3C */
+    U8                              DeviceForm;             /* 0x3F */
+    MPI3_DEVICE1_DEV_SPEC_FORMAT    DeviceSpecific;         /* 0x40 */
+} MPI3_DEVICE_PAGE1, MPI3_POINTER PTR_MPI3_DEVICE_PAGE1,
+  Mpi3DevicePage1_t, MPI3_POINTER pMpi3DevicePage1_t;
+
+/**** Defines for the PageVersion field ****/
+#define MPI3_DEVICE1_PAGEVERSION                            (0x00)
+
+/**** Defines for the DeviceForm field - use MPI3_DEVICE_DEVFORM_ defines ****/
+
+#endif  /* MPI30_CNFG_H */
diff --git a/drivers/scsi/mpi3mr/mpi/mpi30_sas.h b/drivers/scsi/mpi3mr/mpi/mpi30_sas.h
new file mode 100644
index 000000000000..b60a5899437e
--- /dev/null
+++ b/drivers/scsi/mpi3mr/mpi/mpi30_sas.h
@@ -0,0 +1,46 @@
+/*
+ *  Copyright 2016-2020 Broadcom Inc. All rights reserved.
+ *
+ *           Name: mpi30_sas.h
+ *    Description: Contains MPI Serial Attached SCSI structures and definitions
+ *  Creation Date: 12/08/2016
+ *        Version: 03.00.00
+ */
+#ifndef MPI30_SAS_H
+#define MPI30_SAS_H     1
+
+/*****************************************************************************
+ *              SAS Device Info Definitions                                  *
+ ****************************************************************************/
+#define MPI3_SAS_DEVICE_INFO_SSP_TARGET             (0x00000100)
+#define MPI3_SAS_DEVICE_INFO_STP_SATA_TARGET        (0x00000080)
+#define MPI3_SAS_DEVICE_INFO_SMP_TARGET             (0x00000040)
+#define MPI3_SAS_DEVICE_INFO_SSP_INITIATOR          (0x00000020)
+#define MPI3_SAS_DEVICE_INFO_STP_INITIATOR          (0x00000010)
+#define MPI3_SAS_DEVICE_INFO_SMP_INITIATOR          (0x00000008)
+#define MPI3_SAS_DEVICE_INFO_DEVICE_TYPE_MASK       (0x00000007)
+#define MPI3_SAS_DEVICE_INFO_DEVICE_TYPE_NO_DEVICE  (0x00000000)
+#define MPI3_SAS_DEVICE_INFO_DEVICE_TYPE_END_DEVICE (0x00000001)
+#define MPI3_SAS_DEVICE_INFO_DEVICE_TYPE_EXPANDER   (0x00000002)
+
+/*****************************************************************************
+ *              SMP Passthrough Request Message                              *
+ ****************************************************************************/
+typedef struct _MPI3_SMP_PASSTHROUGH_REQUEST {
+    U16                     HostTag;                        /* 0x00 */
+    U8                      IOCUseOnly02;                   /* 0x02 */
+    U8                      Function;                       /* 0x03 */
+    U16                     IOCUseOnly04;                   /* 0x04 */
+    U8                      IOCUseOnly06;                   /* 0x06 */
+    U8                      MsgFlags;                       /* 0x07 */
+    U16                     ChangeCount;                    /* 0x08 */
+    U8                      Reserved0A;                     /* 0x0A */
+    U8                      IOUnitPort;                     /* 0x0B */
+    U32                     Reserved0C[3];                  /* 0x0C */
+    U64                     SASAddress;                     /* 0x18 */
+    MPI3_SGE_SIMPLE         RequestSGE;                     /* 0x20 */
+    MPI3_SGE_SIMPLE         ResponseSGE;                    /* 0x30 */
+} MPI3_SMP_PASSTHROUGH_REQUEST, MPI3_POINTER PTR_MPI3_SMP_PASSTHROUGH_REQUEST,
+  Mpi3SmpPassthroughRequest_t, MPI3_POINTER pMpi3SmpPassthroughRequest_t;
+
+#endif  /* MPI30_SAS_H */
diff --git a/drivers/scsi/mpi3mr/mpi3mr.h b/drivers/scsi/mpi3mr/mpi3mr.h
index 0fa38036dcf3..1f70a67d7868 100644
--- a/drivers/scsi/mpi3mr/mpi3mr.h
+++ b/drivers/scsi/mpi3mr/mpi3mr.h
@@ -134,6 +134,10 @@ extern struct list_head mrioc_list;
 #define MPI3MR_RSP_IO_QUEUED_ON_IOC \
 			MPI3_SCSITASKMGMT_RSPCODE_IO_QUEUED_ON_IOC
 
+#define MPI3MR_DEFAULT_MDTS	(128 * 1024)
+/* Command retry count definitions */
+#define MPI3MR_DEV_RMHS_RETRY_COUNT 3
+
 /* SGE Flag definition */
 #define MPI3MR_SGEFLAGS_SYSTEM_SIMPLE_END_OF_LIST \
 	(MPI3_SGE_FLAGS_ELEMENT_TYPE_SIMPLE | MPI3_SGE_FLAGS_DLAS_SYSTEM | \
@@ -313,6 +317,126 @@ struct mpi3mr_intr_info {
 	char name[MPI3MR_NAME_LENGTH];
 };
 
+/**
+ * struct tgt_dev_sas_sata - SAS/SATA device specific
+ * information cached from firmware given data
+ *
+ * @sas_address: World wide unique SAS address
+ * @dev_info: Device information bits
+ */
+struct tgt_dev_sas_sata {
+	u64 sas_address;
+	u16 dev_info;
+};
+
+/**
+ * struct tgt_dev_pcie - PCIe device specific information cached
+ * from firmware given data
+ *
+ * @mdts: Maximum data transfer size
+ * @capb: Device capabilities
+ * @pgsz: Device page size
+ * @abort_to: Timeout for abort TM
+ * @reset_to: Timeout for Target/LUN reset TM
+ */
+struct tgt_dev_pcie {
+	u32 mdts;
+	u16 capb;
+	u8 pgsz;
+	u8 abort_to;
+	u8 reset_to;
+};
+
+/**
+ * struct tgt_dev_volume - virtual device specific information
+ * cached from firmware given data
+ *
+ * @state: State of the VD
+ */
+struct tgt_dev_volume {
+	u8 state;
+};
+
+/**
+ * union _form_spec_inf - union of device specific information
+ */
+union _form_spec_inf {
+	struct tgt_dev_sas_sata sas_sata_inf;
+	struct tgt_dev_pcie pcie_inf;
+	struct tgt_dev_volume vol_inf;
+};
+
+
+
+/**
+ * struct mpi3mr_tgt_dev - target device data structure
+ *
+ * @list: List pointer
+ * @starget: Scsi_target pointer
+ * @dev_handle: FW device handle
+ * @parent_handle: FW parent device handle
+ * @slot: Slot number
+ * @encl_handle: FW enclosure handle
+ * @perst_id: FW assigned Persistent ID
+ * @dev_type: SAS/SATA/PCIE device type
+ * @is_hidden: Should be exposed to upper layers or not
+ * @host_exposed: Already exposed to host or not
+ * @q_depth: Device specific Queue Depth
+ * @wwid: World wide ID
+ * @dev_spec: Device type specific information
+ * @ref_count: Reference count
+ */
+struct mpi3mr_tgt_dev {
+	struct list_head list;
+	struct scsi_target *starget;
+	u16 dev_handle;
+	u16 parent_handle;
+	u16 slot;
+	u16 encl_handle;
+	u16 perst_id;
+	u8 dev_type;
+	u8 is_hidden;
+	u8 host_exposed;
+	u16 q_depth;
+	u64 wwid;
+	union _form_spec_inf dev_spec;
+	struct kref ref_count;
+};
+
+/**
+ * mpi3mr_tgtdev_get - k reference incrementor
+ * @s: Target device reference
+ *
+ * Increment target device reference count.
+ */
+static inline void mpi3mr_tgtdev_get(struct mpi3mr_tgt_dev *s)
+{
+	kref_get(&s->ref_count);
+}
+
+/**
+ * mpi3mr_free_tgtdev - target device memory dealloctor
+ * @r: k reference pointer of the target device
+ *
+ * Free target device memory when no reference.
+ */
+static inline void mpi3mr_free_tgtdev(struct kref *r)
+{
+	kfree(container_of(r, struct mpi3mr_tgt_dev, ref_count));
+}
+
+/**
+ * mpi3mr_tgtdev_put - k reference decrementor
+ * @s: Target device reference
+ *
+ * Decrement target device reference count.
+ */
+static inline void mpi3mr_tgtdev_put(struct mpi3mr_tgt_dev *s)
+{
+	kref_put(&s->ref_count, mpi3mr_free_tgtdev);
+}
+
+
 /**
  * struct mpi3mr_stgt_priv_data - SCSI target private structure
  *
@@ -362,6 +486,7 @@ typedef void (*DRV_CMD_CALLBACK)(struct mpi3mr_ioc *mrioc,
  * @done: Completeor for wakeup
  * @reply: Firmware reply for internal commands
  * @sensebuf: Sensebuf for SCSI IO commands
+ * @iou_rc: IO Unit control reason code
  * @state: Command State
  * @dev_handle: Firmware handle for device specific commands
  * @ioc_status: IOC status from the firmware
@@ -376,6 +501,7 @@ struct mpi3mr_drv_cmd {
 	struct completion done;
 	void *reply;
 	u8 *sensebuf;
+	u8 iou_rc;
 	u16 state;
 	u16 dev_handle;
 	u16 ioc_status;
@@ -480,6 +606,11 @@ struct scmd_priv {
  * @sense_buf_q_dma: Sense buffer queue DMA address
  * @sbq_lock: Sense buffer queue lock
  * @sbq_host_index: Sense buffer queuehost index
+ * @event_masks: Event mask bitmap
+ * @fwevt_worker_name: Firmware event worker thread name
+ * @fwevt_worker_thread: Firmware event worker thread
+ * @fwevt_lock: Firmware event lock
+ * @fwevt_list: Firmware event list
  * @watchdog_work_q_name: Fault watchdog worker thread name
  * @watchdog_work_q: Fault watchdog worker thread
  * @watchdog_work: Fault watchdog work
@@ -495,6 +626,12 @@ struct scmd_priv {
  * @chain_bitmap_sz: Chain buffer allocator bitmap size
  * @chain_bitmap: Chain buffer allocator bitmap
  * @chain_buf_lock: Chain buffer list lock
+ * @dev_rmhs_cmds: Command tracker for device removal commands
+ * @devrem_bitmap_sz: Device removal bitmap size
+ * @devrem_bitmap: Device removal bitmap
+ * @dev_handle_bitmap_sz: Device handle bitmap size
+ * @removepend_bitmap: Remove pending bitmap
+ * @delayed_rmhs_list: Delayed device removal list
  * @reset_in_progress: Reset in progress flag
  * @unrecoverable: Controller unrecoverable flag
  * @diagsave_timeout: Diagnostic information save timeout
@@ -578,6 +715,12 @@ struct mpi3mr_ioc {
 	dma_addr_t sense_buf_q_dma;
 	spinlock_t sbq_lock;
 	u32 sbq_host_index;
+	u32 event_masks[MPI3_EVENT_NOTIFY_EVENTMASK_WORDS];
+
+	char fwevt_worker_name[MPI3MR_NAME_LENGTH];
+	struct workqueue_struct	*fwevt_worker_thread;
+	spinlock_t fwevt_lock;
+	struct list_head fwevt_list;
 
 	char watchdog_work_q_name[20];
 	struct workqueue_struct *watchdog_work_q;
@@ -590,6 +733,8 @@ struct mpi3mr_ioc {
 	u8 stop_drv_processing;
 
 	u16 max_host_ios;
+	spinlock_t tgtdev_lock;
+	struct list_head tgtdev_list;
 
 	u32 chain_buf_count;
 	struct dma_pool *chain_buf_pool;
@@ -598,6 +743,13 @@ struct mpi3mr_ioc {
 	void *chain_bitmap;
 	spinlock_t chain_buf_lock;
 
+	struct mpi3mr_drv_cmd dev_rmhs_cmds[MPI3MR_NUM_DEVRMCMD];
+	u16 devrem_bitmap_sz;
+	void *devrem_bitmap;
+	u16 dev_handle_bitmap_sz;
+	void *removepend_bitmap;
+	struct list_head delayed_rmhs_list;
+
 	u8 reset_in_progress;
 	u8 unrecoverable;
 
@@ -610,6 +762,45 @@ struct mpi3mr_ioc {
 	u16 op_reply_q_offset;
 };
 
+/**
+ * struct mpi3mr_fwevt - Firmware event structure.
+ *
+ * @list: list head
+ * @work: Work structure
+ * @mrioc: Adapter instance reference
+ * @event_id: MPI3 firmware event ID
+ * @send_ack: Event acknowledgment required or not
+ * @process_evt: Bottomhalf processing required or not
+ * @evt_ctx: Event context to send in Ack
+ * @ref_count: kref count
+ * @event_data: Actual MPI3 event data
+ */
+struct mpi3mr_fwevt {
+	struct list_head list;
+	struct work_struct work;
+	struct mpi3mr_ioc *mrioc;
+	u16 event_id;
+	bool send_ack;
+	bool process_evt;
+	u32 evt_ctx;
+	struct kref ref_count;
+	char event_data[0] __aligned(4);
+};
+
+
+/**
+ * struct delayed_dev_rmhs_node - Delayed device removal node
+ *
+ * @list: list head
+ * @handle: Device handle
+ * @iou_rc: IO Unit Control Reason Code
+ */
+struct delayed_dev_rmhs_node {
+	struct list_head list;
+	u16 handle;
+	u8 iou_rc;
+};
+
 int mpi3mr_setup_resources(struct mpi3mr_ioc *mrioc);
 void mpi3mr_cleanup_resources(struct mpi3mr_ioc *mrioc);
 int mpi3mr_init_ioc(struct mpi3mr_ioc *mrioc);
@@ -629,6 +820,8 @@ void *mpi3mr_get_reply_virt_addr(struct mpi3mr_ioc *mrioc,
 void mpi3mr_repost_sense_buf(struct mpi3mr_ioc *mrioc,
 				     u64 sense_buf_dma);
 
+void mpi3mr_os_handle_events(struct mpi3mr_ioc *mrioc,
+			     Mpi3EventNotificationReply_t *event_reply);
 void mpi3mr_process_op_reply_desc(struct mpi3mr_ioc *mrioc,
 				  Mpi3DefaultReplyDescriptor_t *reply_desc,
 				  u64 *reply_dma, u16 qidx);
@@ -641,5 +834,7 @@ void mpi3mr_ioc_disable_intr(struct mpi3mr_ioc *mrioc);
 void mpi3mr_ioc_enable_intr(struct mpi3mr_ioc *mrioc);
 
 enum mpi3mr_iocstate mpi3mr_get_iocstate(struct mpi3mr_ioc *mrioc);
+int mpi3mr_send_event_ack(struct mpi3mr_ioc *mrioc, u8 event,
+			  u32 event_ctx);
 
 #endif /*MPI3MR_H_INCLUDED*/
diff --git a/drivers/scsi/mpi3mr/mpi3mr_fw.c b/drivers/scsi/mpi3mr/mpi3mr_fw.c
index 4f1524dcad4d..c3933c9b73fc 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_fw.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_fw.c
@@ -160,6 +160,7 @@ static void mpi3mr_handle_events(struct mpi3mr_ioc *mrioc,
 	    (Mpi3EventNotificationReply_t *)def_reply;
 
 	mrioc->change_count = le16_to_cpu(event_reply->IOCChangeCount);
+	mpi3mr_os_handle_events(mrioc, event_reply);
 }
 
 static struct mpi3mr_drv_cmd *
@@ -2137,6 +2138,162 @@ static int mpi3mr_issue_iocinit(struct mpi3mr_ioc *mrioc)
 	return retval;
 }
 
+/**
+ * mpi3mr_unmask_events - Unmask events in event mask bitmap
+ * @mrioc: Adapter instance reference
+ * @event: MPI event ID
+ *
+ * Un mask the specific event by resetting the event_mask
+ * bitmap.
+ *
+ * Return: 0 on success, non-zero on failures.
+ */
+static void mpi3mr_unmask_events(struct mpi3mr_ioc *mrioc, u16 event)
+{
+	u32 desired_event;
+	u8 word;
+
+	if (event >= 128)
+		return;
+
+	desired_event = (1 << (event % 32));
+	word = event / 32;
+
+	mrioc->event_masks[word] &= ~desired_event;
+}
+
+/**
+ * mpi3mr_issue_event_notification - Send event notification
+ * @mrioc: Adapter instance reference
+ *
+ * Issue event notification MPI request through admin queue and
+ * wait for the completion of it or time out.
+ *
+ * Return: 0 on success, non-zero on failures.
+ */
+static int mpi3mr_issue_event_notification(struct mpi3mr_ioc *mrioc)
+{
+	Mpi3EventNotificationRequest_t evtnotify_req;
+	int retval = 0;
+	u8 i;
+
+	memset(&evtnotify_req, 0, sizeof(evtnotify_req));
+	mutex_lock(&mrioc->init_cmds.mutex);
+	if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
+		retval = -1;
+		ioc_err(mrioc, "Issue EvtNotify: Init command is in use\n");
+		mutex_unlock(&mrioc->init_cmds.mutex);
+		goto out;
+	}
+	mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
+	mrioc->init_cmds.is_waiting = 1;
+	mrioc->init_cmds.callback = NULL;
+	evtnotify_req.HostTag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
+	evtnotify_req.Function = MPI3_FUNCTION_EVENT_NOTIFICATION;
+	for (i = 0; i < MPI3_EVENT_NOTIFY_EVENTMASK_WORDS; i++)
+		evtnotify_req.EventMasks[i] =
+		    cpu_to_le32(mrioc->event_masks[i]);
+	init_completion(&mrioc->init_cmds.done);
+	retval = mpi3mr_admin_request_post(mrioc, &evtnotify_req,
+	    sizeof(evtnotify_req), 1);
+	if (retval) {
+		ioc_err(mrioc, "Issue EvtNotify: Admin Post failed\n");
+		goto out_unlock;
+	}
+	wait_for_completion_timeout(&mrioc->init_cmds.done,
+	    (MPI3MR_INTADMCMD_TIMEOUT * HZ));
+	if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
+		ioc_err(mrioc, "Issue EvtNotify: command timed out\n");
+		mpi3mr_set_diagsave(mrioc);
+		mpi3mr_issue_reset(mrioc,
+		    MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT,
+		    MPI3MR_RESET_FROM_EVTNOTIFY_TIMEOUT);
+		mrioc->unrecoverable = 1;
+		retval = -1;
+		goto out_unlock;
+	}
+	if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
+	    != MPI3_IOCSTATUS_SUCCESS) {
+		ioc_err(mrioc,
+		    "Issue EvtNotify: Failed IOCStatus(0x%04x) Loginfo(0x%08x)\n",
+		    (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
+		    mrioc->init_cmds.ioc_loginfo);
+		retval = -1;
+		goto out_unlock;
+	}
+
+out_unlock:
+	mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
+	mutex_unlock(&mrioc->init_cmds.mutex);
+out:
+	return retval;
+}
+
+/**
+ * mpi3mr_send_event_ack - Send event acknowledgment
+ * @event: MPI3 event ID
+ * @event_ctx: Event context
+ *
+ * Send event acknowledgment through admin queue and wait for
+ * it to complete.
+ *
+ * Return: 0 on success, non-zero on failures.
+ */
+int mpi3mr_send_event_ack(struct mpi3mr_ioc *mrioc, u8 event,
+	u32 event_ctx)
+{
+	Mpi3EventAckRequest_t evtack_req;
+	int retval = 0;
+
+	memset(&evtack_req, 0, sizeof(evtack_req));
+	mutex_lock(&mrioc->init_cmds.mutex);
+	if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
+		retval = -1;
+		ioc_err(mrioc, "Send EvtAck: Init command is in use\n");
+		mutex_unlock(&mrioc->init_cmds.mutex);
+		goto out;
+	}
+	mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
+	mrioc->init_cmds.is_waiting = 1;
+	mrioc->init_cmds.callback = NULL;
+	evtack_req.HostTag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
+	evtack_req.Function = MPI3_FUNCTION_EVENT_ACK;
+	evtack_req.Event = event;
+	evtack_req.EventContext = cpu_to_le32(event_ctx);
+
+	init_completion(&mrioc->init_cmds.done);
+	retval = mpi3mr_admin_request_post(mrioc, &evtack_req,
+	    sizeof(evtack_req), 1);
+	if (retval) {
+		ioc_err(mrioc, "Send EvtAck: Admin Post failed\n");
+		goto out_unlock;
+	}
+	wait_for_completion_timeout(&mrioc->init_cmds.done,
+	    (MPI3MR_INTADMCMD_TIMEOUT * HZ));
+	if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
+		ioc_err(mrioc, "Issue EvtNotify: command timed out\n");
+		mpi3mr_soft_reset_handler(mrioc,
+		    MPI3MR_RESET_FROM_EVTACK_TIMEOUT, 1);
+		retval = -1;
+		goto out_unlock;
+	}
+	if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
+	    != MPI3_IOCSTATUS_SUCCESS) {
+		ioc_err(mrioc,
+		    "Send EvtAck: Failed IOCStatus(0x%04x) Loginfo(0x%08x)\n",
+		    (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
+		    mrioc->init_cmds.ioc_loginfo);
+		retval = -1;
+		goto out_unlock;
+	}
+
+out_unlock:
+	mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
+	mutex_unlock(&mrioc->init_cmds.mutex);
+out:
+	return retval;
+}
+
 
 /**
  * mpi3mr_alloc_chain_bufs - Allocate chain buffers
@@ -2418,7 +2575,7 @@ int mpi3mr_init_ioc(struct mpi3mr_ioc *mrioc)
 	enum mpi3mr_iocstate ioc_state;
 	u64 base_info;
 	u32 timeout;
-	u32 ioc_status, ioc_config;
+	u32 ioc_status, ioc_config, i;
 	Mpi3IOCFactsData_t facts_data;
 
 	mrioc->change_count = 0;
@@ -2568,6 +2725,24 @@ int mpi3mr_init_ioc(struct mpi3mr_ioc *mrioc)
 		goto out_failed;
 	}
 
+	for (i = 0; i < MPI3_EVENT_NOTIFY_EVENTMASK_WORDS; i++)
+		mrioc->event_masks[i] = -1;
+
+	mpi3mr_unmask_events(mrioc, MPI3_EVENT_DEVICE_ADDED);
+	mpi3mr_unmask_events(mrioc, MPI3_EVENT_DEVICE_INFO_CHANGED);
+	mpi3mr_unmask_events(mrioc, MPI3_EVENT_DEVICE_STATUS_CHANGE);
+	mpi3mr_unmask_events(mrioc, MPI3_EVENT_ENCL_DEVICE_STATUS_CHANGE);
+	mpi3mr_unmask_events(mrioc, MPI3_EVENT_SAS_TOPOLOGY_CHANGE_LIST);
+	mpi3mr_unmask_events(mrioc, MPI3_EVENT_SAS_DISCOVERY);
+	mpi3mr_unmask_events(mrioc, MPI3_EVENT_SAS_DEVICE_DISCOVERY_ERROR);
+
+	retval = mpi3mr_issue_event_notification(mrioc);
+	if (retval) {
+		ioc_err(mrioc, "Failed to issue event notification %d\n",
+		    retval);
+		goto out_failed;
+	}
+
 	return retval;
 
 out_failed:
diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c
index 7b0d52481929..e0ca657bfff5 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_os.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_os.c
@@ -125,6 +125,1284 @@ static void mpi3mr_clear_scmd_priv(struct mpi3mr_ioc *mrioc,
 	}
 }
 
+static void mpi3mr_dev_rmhs_send_tm(struct mpi3mr_ioc *mrioc, u16 handle,
+	struct mpi3mr_drv_cmd *cmdparam, u8 iou_rc);
+static void mpi3mr_fwevt_worker(struct work_struct *work);
+
+
+/**
+ * mpi3mr_fwevt_free - firmware event memory dealloctor
+ * @r: k reference pointer of the firmware event
+ *
+ * Free firmware event memory when no reference.
+ */
+static void mpi3mr_fwevt_free(struct kref *r)
+{
+	kfree(container_of(r, struct mpi3mr_fwevt, ref_count));
+}
+
+/**
+ * mpi3mr_fwevt_get - k reference incrementor
+ * @fwevt: Firmware event reference
+ *
+ * Increment firmware event reference count.
+ */
+static void mpi3mr_fwevt_get(struct mpi3mr_fwevt *fwevt)
+{
+	kref_get(&fwevt->ref_count);
+}
+
+/**
+ * mpi3mr_fwevt_put - k reference decrementor
+ * @fwevt: Firmware event reference
+ *
+ * Decrement firmware event reference count.
+ */
+static void mpi3mr_fwevt_put(struct mpi3mr_fwevt *fwevt)
+{
+	kref_put(&fwevt->ref_count, mpi3mr_fwevt_free);
+}
+
+/**
+ * mpi3mr_alloc_fwevt - Allocate firmware event
+ * @len: Length of firmware event data to allocate
+ *
+ * Allocate firmware event with required length and initialize
+ * the reference counter.
+ *
+ * Return: firmware event reference.
+ */
+static struct mpi3mr_fwevt *mpi3mr_alloc_fwevt(int len)
+{
+	struct mpi3mr_fwevt *fwevt;
+
+	fwevt = kzalloc(sizeof(*fwevt) + len, GFP_ATOMIC);
+	if (!fwevt)
+		return NULL;
+
+	kref_init(&fwevt->ref_count);
+	return fwevt;
+}
+
+/**
+ * mpi3mr_fwevt_add_to_list - Add firmware event to the list
+ * @mrioc: Adapter instance reference
+ * @fwevt: Firmware event reference
+ *
+ * Add the given firmware event to the firmware event list.
+ *
+ * Return: Nothing.
+ */
+static void mpi3mr_fwevt_add_to_list(struct mpi3mr_ioc *mrioc,
+	struct mpi3mr_fwevt *fwevt)
+{
+	unsigned long flags;
+
+	if (mrioc->fwevt_worker_thread == NULL)
+		return;
+
+	spin_lock_irqsave(&mrioc->fwevt_lock, flags);
+	/* get fwevt reference count while adding it to fwevt_list */
+	mpi3mr_fwevt_get(fwevt);
+	INIT_LIST_HEAD(&fwevt->list);
+	list_add_tail(&fwevt->list, &mrioc->fwevt_list);
+	INIT_WORK(&fwevt->work, mpi3mr_fwevt_worker);
+	/* get fwevt reference count while enqueueing it to worker queue */
+	mpi3mr_fwevt_get(fwevt);
+	queue_work(mrioc->fwevt_worker_thread, &fwevt->work);
+	spin_unlock_irqrestore(&mrioc->fwevt_lock, flags);
+}
+
+/**
+ * mpi3mr_fwevt_del_from_list - Delete firmware event from list
+ * @mrioc: Adapter instance reference
+ * @fwevt: Firmware event reference
+ *
+ * Delete the given firmware event from the firmware event list.
+ *
+ * Return: Nothing.
+ */
+static void mpi3mr_fwevt_del_from_list(struct mpi3mr_ioc *mrioc,
+	struct mpi3mr_fwevt *fwevt)
+{
+	unsigned long flags;
+
+	spin_lock_irqsave(&mrioc->fwevt_lock, flags);
+	if (!list_empty(&fwevt->list)) {
+		list_del_init(&fwevt->list);
+		/*
+		 * Put fwevt reference count after
+		 * removing it from fwevt_list
+		 */
+		mpi3mr_fwevt_put(fwevt);
+	}
+	spin_unlock_irqrestore(&mrioc->fwevt_lock, flags);
+}
+
+/**
+ * mpi3mr_dequeue_fwevt - Dequeue firmware event from the list
+ * @mrioc: Adapter instance reference
+ *
+ * Dequeue a firmware event from the firmware event list.
+ *
+ * Return: firmware event.
+ */
+static struct mpi3mr_fwevt *mpi3mr_dequeue_fwevt(
+	struct mpi3mr_ioc *mrioc)
+{
+	unsigned long flags;
+	struct mpi3mr_fwevt *fwevt = NULL;
+
+	spin_lock_irqsave(&mrioc->fwevt_lock, flags);
+	if (!list_empty(&mrioc->fwevt_list)) {
+		fwevt = list_first_entry(&mrioc->fwevt_list,
+		    struct mpi3mr_fwevt, list);
+		list_del_init(&fwevt->list);
+		/*
+		 * Put fwevt reference count after
+		 * removing it from fwevt_list
+		 */
+		mpi3mr_fwevt_put(fwevt);
+	}
+	spin_unlock_irqrestore(&mrioc->fwevt_lock, flags);
+
+	return fwevt;
+}
+
+/**
+ * mpi3mr_cleanup_fwevt_list - Cleanup firmware event list
+ * @mrioc: Adapter instance reference
+ *
+ * Flush all pending firmware events from the firmware event
+ * list.
+ *
+ * Return: Nothing.
+ */
+void mpi3mr_cleanup_fwevt_list(struct mpi3mr_ioc *mrioc)
+{
+	struct mpi3mr_fwevt *fwevt = NULL;
+
+	if ((list_empty(&mrioc->fwevt_list) && !mrioc->current_event) ||
+	    !mrioc->fwevt_worker_thread || in_interrupt())
+		return;
+
+	while ((fwevt = mpi3mr_dequeue_fwevt(mrioc)) ||
+	    (fwevt = mrioc->current_event)) {
+		/*
+		 * Wait on the fwevt to complete. If this returns 1, then
+		 * the event was never executed, and we need a put for the
+		 * reference the work had on the fwevt.
+		 *
+		 * If it did execute, we wait for it to finish, and the put will
+		 * happen from mpi3mr_process_fwevt()
+		 */
+		if (cancel_work_sync(&fwevt->work)) {
+			/*
+			 * Put fwevt reference count after
+			 * dequeuing it from worker queue
+			 */
+			mpi3mr_fwevt_put(fwevt);
+			/*
+			 * Put fwevt reference count to neutralize
+			 * kref_init increment
+			 */
+			mpi3mr_fwevt_put(fwevt);
+		}
+	}
+}
+
+/**
+ * mpi3mr_alloc_tgtdev - target device allocator
+ *
+ * Allocate target device instance and initialize the reference
+ * count
+ *
+ * Return: target device instance.
+ */
+static struct mpi3mr_tgt_dev *mpi3mr_alloc_tgtdev(void)
+{
+	struct mpi3mr_tgt_dev *tgtdev;
+
+	tgtdev = kzalloc(sizeof(*tgtdev), GFP_ATOMIC);
+	if (!tgtdev)
+		return NULL;
+	kref_init(&tgtdev->ref_count);
+	return tgtdev;
+}
+
+/**
+ * mpi3mr_tgtdev_add_to_list -Add tgtdevice to the list
+ * @mrioc: Adapter instance reference
+ * @tgtdev: Target device
+ *
+ * Add the target device to the target device list
+ *
+ * Return: Nothing.
+ */
+static void mpi3mr_tgtdev_add_to_list(struct mpi3mr_ioc *mrioc,
+	struct mpi3mr_tgt_dev *tgtdev)
+{
+	unsigned long flags;
+
+	spin_lock_irqsave(&mrioc->tgtdev_lock, flags);
+	mpi3mr_tgtdev_get(tgtdev);
+	INIT_LIST_HEAD(&tgtdev->list);
+	list_add_tail(&tgtdev->list, &mrioc->tgtdev_list);
+	spin_unlock_irqrestore(&mrioc->tgtdev_lock, flags);
+}
+
+/**
+ * mpi3mr_tgtdev_del_from_list -Delete tgtdevice from the list
+ * @mrioc: Adapter instance reference
+ * @tgtdev: Target device
+ *
+ * Remove the target device from the target device list
+ *
+ * Return: Nothing.
+ */
+static void mpi3mr_tgtdev_del_from_list(struct mpi3mr_ioc *mrioc,
+	struct mpi3mr_tgt_dev *tgtdev)
+{
+	unsigned long flags;
+
+	spin_lock_irqsave(&mrioc->tgtdev_lock, flags);
+	if (!list_empty(&tgtdev->list)) {
+		list_del_init(&tgtdev->list);
+		mpi3mr_tgtdev_put(tgtdev);
+	}
+	spin_unlock_irqrestore(&mrioc->tgtdev_lock, flags);
+}
+
+/**
+ * __mpi3mr_get_tgtdev_by_handle -Get tgtdev from device handle
+ * @mrioc: Adapter instance reference
+ * @handle: Device handle
+ *
+ * Accessor to retrieve target device from the device handle.
+ * Non Lock version
+ *
+ * Return: Target device reference.
+ */
+static struct mpi3mr_tgt_dev  *__mpi3mr_get_tgtdev_by_handle(
+	struct mpi3mr_ioc *mrioc, u16 handle)
+{
+	struct mpi3mr_tgt_dev *tgtdev;
+
+	assert_spin_locked(&mrioc->tgtdev_lock);
+	list_for_each_entry(tgtdev, &mrioc->tgtdev_list, list)
+		if (tgtdev->dev_handle == handle)
+			goto found_tgtdev;
+	return NULL;
+
+found_tgtdev:
+	mpi3mr_tgtdev_get(tgtdev);
+	return tgtdev;
+}
+
+/**
+ * mpi3mr_get_tgtdev_by_handle -Get tgtdev from device handle
+ * @mrioc: Adapter instance reference
+ * @handle: Device handle
+ *
+ * Accessor to retrieve target device from the device handle.
+ * Lock version
+ *
+ * Return: Target device reference.
+ */
+struct mpi3mr_tgt_dev *mpi3mr_get_tgtdev_by_handle(
+	struct mpi3mr_ioc *mrioc, u16 handle)
+{
+	struct mpi3mr_tgt_dev *tgtdev;
+	unsigned long flags;
+
+	spin_lock_irqsave(&mrioc->tgtdev_lock, flags);
+	tgtdev = __mpi3mr_get_tgtdev_by_handle(mrioc, handle);
+	spin_unlock_irqrestore(&mrioc->tgtdev_lock, flags);
+	return tgtdev;
+}
+
+/**
+ * __mpi3mr_get_tgtdev_by_perst_id -Get tgtdev from persist ID
+ * @mrioc: Adapter instance reference
+ * @persist_id: Persistent ID
+ *
+ * Accessor to retrieve target device from the Persistent ID.
+ * Non Lock version
+ *
+ * Return: Target device reference.
+ */
+static struct mpi3mr_tgt_dev  *__mpi3mr_get_tgtdev_by_perst_id(
+	struct mpi3mr_ioc *mrioc, u16 persist_id)
+{
+	struct mpi3mr_tgt_dev *tgtdev;
+
+	assert_spin_locked(&mrioc->tgtdev_lock);
+	list_for_each_entry(tgtdev, &mrioc->tgtdev_list, list)
+		if (tgtdev->perst_id == persist_id)
+			goto found_tgtdev;
+	return NULL;
+
+found_tgtdev:
+	mpi3mr_tgtdev_get(tgtdev);
+	return tgtdev;
+}
+
+/**
+ * mpi3mr_get_tgtdev_by_perst_id -Get tgtdev from persistent ID
+ * @mrioc: Adapter instance reference
+ * @persist_id: Persistent ID
+ *
+ * Accessor to retrieve target device from the Persistent ID.
+ * Lock version
+ *
+ * Return: Target device reference.
+ */
+struct mpi3mr_tgt_dev *mpi3mr_get_tgtdev_by_perst_id(
+	struct mpi3mr_ioc *mrioc, u16 persist_id)
+{
+	struct mpi3mr_tgt_dev *tgtdev;
+	unsigned long flags;
+
+	spin_lock_irqsave(&mrioc->tgtdev_lock, flags);
+	tgtdev = __mpi3mr_get_tgtdev_by_perst_id(mrioc, persist_id);
+	spin_unlock_irqrestore(&mrioc->tgtdev_lock, flags);
+	return tgtdev;
+}
+
+
+/**
+ * __mpi3mr_get_tgtdev_from_tgtpriv -Get tgtdev from tgt private
+ * @mrioc: Adapter instance reference
+ * @tgt_priv: Target private data
+ *
+ * Accessor to return target device from the target private
+ * data. Non Lock version
+ *
+ * Return: Target device reference.
+ */
+static struct mpi3mr_tgt_dev  *__mpi3mr_get_tgtdev_from_tgtpriv(
+	struct mpi3mr_ioc *mrioc, struct mpi3mr_stgt_priv_data *tgt_priv)
+{
+	struct mpi3mr_tgt_dev *tgtdev;
+
+	assert_spin_locked(&mrioc->tgtdev_lock);
+	tgtdev = tgt_priv->tgt_dev;
+	if (tgtdev)
+		mpi3mr_tgtdev_get(tgtdev);
+	return tgtdev;
+}
+
+/**
+ * mpi3mr_remove_tgtdev_from_host - Remove dev from upper layers
+ * @mrioc: Adapter instance reference
+ * @tgtdev: Target device structure
+ *
+ * Checks whether the device is exposed to upper layers and if it
+ * is then remove the device from upper layers by calling
+ * scsi_remove_target().
+ *
+ * Return: 0 on success, non zero on failure.
+ */
+static void mpi3mr_remove_tgtdev_from_host(struct mpi3mr_ioc *mrioc,
+	struct mpi3mr_tgt_dev *tgtdev)
+{
+	struct mpi3mr_stgt_priv_data *tgt_priv;
+
+
+	ioc_info(mrioc, "%s :Removing handle(0x%04x), wwid(0x%016llx)\n",
+	    __func__, tgtdev->dev_handle, (unsigned long long) tgtdev->wwid);
+	if (tgtdev->starget && tgtdev->starget->hostdata) {
+		tgt_priv = tgtdev->starget->hostdata;
+		tgt_priv->dev_handle = MPI3MR_INVALID_DEV_HANDLE;
+	}
+
+	if (tgtdev->starget) {
+		scsi_remove_target(&tgtdev->starget->dev);
+		tgtdev->host_exposed = 0;
+	}
+	ioc_info(mrioc, "%s :Removed handle(0x%04x), wwid(0x%016llx)\n",
+	    __func__, tgtdev->dev_handle, (unsigned long long) tgtdev->wwid);
+}
+
+
+/**
+ * mpi3mr_report_tgtdev_to_host - Expose device to upper layers
+ * @mrioc: Adapter instance reference
+ * @perst_id: Persistent ID of the device
+ *
+ * Checks whether the device can be exposed to upper layers and
+ * if it is not then expose the device to upper layers by
+ * calling scsi_scan_target().
+ *
+ * Return: 0 on success, non zero on failure.
+ */
+static int mpi3mr_report_tgtdev_to_host(struct mpi3mr_ioc *mrioc,
+	u16 perst_id)
+{
+	int retval = 0;
+	struct mpi3mr_tgt_dev *tgtdev;
+
+	tgtdev = mpi3mr_get_tgtdev_by_perst_id(mrioc, perst_id);
+	if (!tgtdev) {
+		retval = -1;
+		goto out;
+	}
+	if (tgtdev->is_hidden) {
+		retval = -1;
+		goto out;
+	}
+	if (!tgtdev->host_exposed && !mrioc->reset_in_progress) {
+		tgtdev->host_exposed = 1;
+		scsi_scan_target(&mrioc->shost->shost_gendev, 0,
+		    tgtdev->perst_id,
+		    SCAN_WILD_CARD, SCSI_SCAN_INITIAL);
+		if (!tgtdev->starget)
+			tgtdev->host_exposed = 0;
+	}
+out:
+	if (tgtdev)
+		mpi3mr_tgtdev_put(tgtdev);
+
+	return retval;
+}
+
+/**
+ * mpi3mr_rfresh_tgtdevs - Refresh target device exposure
+ * @mrioc: Adapter instance reference
+ *
+ * This is executed post controller reset to identify any
+ * missing devices during reset and remove from the upper layers
+ * or expose any newly detected device to the upper layers.
+ *
+ * Return: Nothing.
+ */
+
+void mpi3mr_rfresh_tgtdevs(struct mpi3mr_ioc *mrioc)
+{
+	struct mpi3mr_tgt_dev *tgtdev, *tgtdev_next;
+
+	list_for_each_entry_safe(tgtdev, tgtdev_next, &mrioc->tgtdev_list,
+	    list) {
+		if ((tgtdev->dev_handle == MPI3MR_INVALID_DEV_HANDLE) &&
+		    tgtdev->host_exposed) {
+			mpi3mr_remove_tgtdev_from_host(mrioc, tgtdev);
+			mpi3mr_tgtdev_del_from_list(mrioc, tgtdev);
+			mpi3mr_tgtdev_put(tgtdev);
+		}
+	}
+
+	tgtdev = NULL;
+	list_for_each_entry(tgtdev, &mrioc->tgtdev_list, list) {
+		if ((tgtdev->dev_handle != MPI3MR_INVALID_DEV_HANDLE) &&
+		    !tgtdev->is_hidden && !tgtdev->host_exposed)
+			mpi3mr_report_tgtdev_to_host(mrioc, tgtdev->perst_id);
+	}
+}
+
+/**
+ * mpi3mr_update_tgtdev - DevStatusChange evt bottomhalf
+ * @mrioc: Adapter instance reference
+ * @tgtdev: Target device internal structure
+ * @dev_pg0: New device page0
+ *
+ * Update the information from the device page0 into the driver
+ * cached target device structure.
+ *
+ * Return: Nothing.
+ */
+static void mpi3mr_update_tgtdev(struct mpi3mr_ioc *mrioc,
+	struct mpi3mr_tgt_dev *tgtdev, Mpi3DevicePage0_t *dev_pg0)
+{
+	u16 flags = 0;
+	struct mpi3mr_stgt_priv_data *scsi_tgt_priv_data;
+
+	tgtdev->perst_id = le16_to_cpu(dev_pg0->PersistentID);
+	tgtdev->dev_handle = le16_to_cpu(dev_pg0->DevHandle);
+	tgtdev->dev_type = dev_pg0->DeviceForm;
+	tgtdev->encl_handle = le16_to_cpu(dev_pg0->EnclosureHandle);
+	tgtdev->parent_handle = le16_to_cpu(dev_pg0->ParentDevHandle);
+	tgtdev->slot = le16_to_cpu(dev_pg0->Slot);
+	tgtdev->q_depth = le16_to_cpu(dev_pg0->QueueDepth);
+	tgtdev->wwid = le64_to_cpu(dev_pg0->WWID);
+
+	flags = le16_to_cpu(dev_pg0->Flags);
+	tgtdev->is_hidden = (flags & MPI3_DEVICE0_FLAGS_HIDDEN);
+
+	if (tgtdev->starget && tgtdev->starget->hostdata) {
+		scsi_tgt_priv_data = (struct mpi3mr_stgt_priv_data *)
+		    tgtdev->starget->hostdata;
+		scsi_tgt_priv_data->perst_id = tgtdev->perst_id;
+		scsi_tgt_priv_data->dev_handle = tgtdev->dev_handle;
+		scsi_tgt_priv_data->dev_type = tgtdev->dev_type;
+	}
+
+	switch (tgtdev->dev_type) {
+	case MPI3_DEVICE_DEVFORM_SAS_SATA:
+	{
+		Mpi3Device0SasSataFormat_t *sasinf =
+		    &dev_pg0->DeviceSpecific.SasSataFormat;
+		u16 dev_info = le16_to_cpu(sasinf->DeviceInfo);
+
+		tgtdev->dev_spec.sas_sata_inf.dev_info = dev_info;
+		tgtdev->dev_spec.sas_sata_inf.sas_address =
+		    le64_to_cpu(sasinf->SASAddress);
+		if ((dev_info & MPI3_SAS_DEVICE_INFO_DEVICE_TYPE_MASK) !=
+		    MPI3_SAS_DEVICE_INFO_DEVICE_TYPE_END_DEVICE)
+			tgtdev->is_hidden = 1;
+		else if (!(dev_info & (MPI3_SAS_DEVICE_INFO_STP_SATA_TARGET |
+		    MPI3_SAS_DEVICE_INFO_SSP_TARGET)))
+			tgtdev->is_hidden = 1;
+		break;
+	}
+	case MPI3_DEVICE_DEVFORM_VD:
+	{
+		Mpi3Device0VdFormat_t *vdinf =
+		    &dev_pg0->DeviceSpecific.VdFormat;
+
+		tgtdev->dev_spec.vol_inf.state = vdinf->VdState;
+		if (vdinf->VdState == MPI3_DEVICE0_VD_STATE_OFFLINE)
+			tgtdev->is_hidden = 1;
+		break;
+	}
+	default:
+		break;
+	}
+}
+
+/**
+ * mpi3mr_devstatuschg_evt_bh - DevStatusChange evt bottomhalf
+ * @mrioc: Adapter instance reference
+ * @dev_pg0: New device page0
+ *
+ * Process Device Status Change event and based on device's new
+ * information, either expose the device to the upper layers, or
+ * remove the device from upper layers.
+ *
+ * Return: Nothing.
+ */
+static void mpi3mr_devstatuschg_evt_bh(struct mpi3mr_ioc *mrioc,
+	struct mpi3mr_fwevt *fwevt)
+{
+	u16 dev_handle = 0;
+	u8 uhide = 0, delete = 0, cleanup = 0;
+	struct mpi3mr_tgt_dev *tgtdev = NULL;
+	struct mpi3mr_stgt_priv_data *scsi_tgt_priv_data = NULL;
+	Mpi3EventDataDeviceStatusChange_t *evtdata =
+	    (Mpi3EventDataDeviceStatusChange_t *)fwevt->event_data;
+
+
+	dev_handle = le16_to_cpu(evtdata->DevHandle);
+	ioc_info(mrioc,
+	    "%s :device status change: handle(0x%04x): reason code(0x%x)\n",
+	    __func__, dev_handle, evtdata->ReasonCode);
+	switch (evtdata->ReasonCode) {
+	case MPI3_EVENT_DEV_STAT_RC_HIDDEN:
+		delete = 1;
+		break;
+	case MPI3_EVENT_DEV_STAT_RC_NOT_HIDDEN:
+		uhide = 1;
+		break;
+	case MPI3_EVENT_DEV_STAT_RC_VD_NOT_RESPONDING:
+		delete = 1;
+		cleanup = 1;
+		break;
+	default:
+		ioc_info(mrioc, "%s :Unhandled reason code(0x%x)\n", __func__,
+		    evtdata->ReasonCode);
+		break;
+	}
+
+	tgtdev = mpi3mr_get_tgtdev_by_handle(mrioc, dev_handle);
+	if (!tgtdev)
+		goto out;
+	if (uhide) {
+		tgtdev->is_hidden = 0;
+		if (!tgtdev->host_exposed)
+			mpi3mr_report_tgtdev_to_host(mrioc, tgtdev->perst_id);
+	}
+	if (tgtdev->starget && tgtdev->starget->hostdata) {
+		scsi_tgt_priv_data = (struct mpi3mr_stgt_priv_data *)
+		    tgtdev->starget->hostdata;
+		if (delete)
+			mpi3mr_remove_tgtdev_from_host(mrioc, tgtdev);
+	}
+	if (cleanup) {
+		mpi3mr_tgtdev_del_from_list(mrioc, tgtdev);
+		mpi3mr_tgtdev_put(tgtdev);
+	}
+
+out:
+	if (tgtdev)
+		mpi3mr_tgtdev_put(tgtdev);
+
+}
+
+/**
+ * mpi3mr_devinfochg_evt_bh - DeviceInfoChange evt bottomhalf
+ * @mrioc: Adapter instance reference
+ * @dev_pg0: New device page0
+ *
+ * Process Device Info Change event and based on device's new
+ * information, either expose the device to the upper layers, or
+ * remove the device from upper layers or update the details of
+ * the device.
+ *
+ * Return: Nothing.
+ */
+static void mpi3mr_devinfochg_evt_bh(struct mpi3mr_ioc *mrioc,
+	Mpi3DevicePage0_t *dev_pg0)
+{
+	struct mpi3mr_tgt_dev *tgtdev = NULL;
+	u16 dev_handle = 0, perst_id = 0;
+
+	perst_id = le16_to_cpu(dev_pg0->PersistentID);
+	dev_handle = le16_to_cpu(dev_pg0->DevHandle);
+	ioc_info(mrioc,
+	    "%s :Device info change: handle(0x%04x): persist_id(0x%x)\n",
+	    __func__, dev_handle, perst_id);
+	tgtdev = mpi3mr_get_tgtdev_by_handle(mrioc, dev_handle);
+	if (!tgtdev)
+		goto out;
+	mpi3mr_update_tgtdev(mrioc, tgtdev, dev_pg0);
+	if (!tgtdev->is_hidden && !tgtdev->host_exposed)
+		mpi3mr_report_tgtdev_to_host(mrioc, perst_id);
+	if (tgtdev->is_hidden && tgtdev->host_exposed)
+		mpi3mr_remove_tgtdev_from_host(mrioc, tgtdev);
+out:
+	if (tgtdev)
+		mpi3mr_tgtdev_put(tgtdev);
+
+}
+
+/**
+ * mpi3mr_sastopochg_evt_bh - SASTopologyChange evt bottomhalf
+ * @mrioc: Adapter instance reference
+ * @fwevt: Firmware event reference
+ *
+ * Prints information about the SAS topology change event and
+ * for "not responding" event code, removes the device from the
+ * upper layers.
+ *
+ * Return: Nothing.
+ */
+static void mpi3mr_sastopochg_evt_bh(struct mpi3mr_ioc *mrioc,
+	struct mpi3mr_fwevt *fwevt)
+{
+	Mpi3EventDataSasTopologyChangeList_t *event_data =
+	    (Mpi3EventDataSasTopologyChangeList_t *)fwevt->event_data;
+	int i;
+	u16 handle;
+	u8 reason_code;
+	struct mpi3mr_tgt_dev *tgtdev = NULL;
+
+	for (i = 0; i < event_data->NumEntries; i++) {
+		handle = le16_to_cpu(event_data->PhyEntry[i].AttachedDevHandle);
+		if (!handle)
+			continue;
+		tgtdev = mpi3mr_get_tgtdev_by_handle(mrioc, handle);
+		if (!tgtdev)
+			continue;
+
+		reason_code = event_data->PhyEntry[i].Status &
+		    MPI3_EVENT_SAS_TOPO_PHY_RC_MASK;
+
+		switch (reason_code) {
+		case MPI3_EVENT_SAS_TOPO_PHY_RC_TARG_NOT_RESPONDING:
+			if (tgtdev->host_exposed)
+				mpi3mr_remove_tgtdev_from_host(mrioc, tgtdev);
+			mpi3mr_tgtdev_del_from_list(mrioc, tgtdev);
+			mpi3mr_tgtdev_put(tgtdev);
+			break;
+		default:
+			break;
+		}
+		if (tgtdev)
+			mpi3mr_tgtdev_put(tgtdev);
+	}
+}
+
+/**
+ * mpi3mr_fwevt_bh - Firmware event bottomhalf handler
+ * @mrioc: Adapter instance reference
+ * @fwevt: Firmware event reference
+ *
+ * Identifies the firmware event and calls corresponding bottomg
+ * half handler and sends event acknowledgment if required.
+ *
+ * Return: Nothing.
+ */
+static void mpi3mr_fwevt_bh(struct mpi3mr_ioc *mrioc,
+	struct mpi3mr_fwevt *fwevt)
+{
+	mrioc->current_event = fwevt;
+	mpi3mr_fwevt_del_from_list(mrioc, fwevt);
+
+	if (mrioc->stop_drv_processing)
+		goto out;
+
+	if (!fwevt->process_evt)
+		goto evt_ack;
+
+	switch (fwevt->event_id) {
+	case MPI3_EVENT_DEVICE_ADDED:
+	{
+		Mpi3DevicePage0_t *dev_pg0 =
+		    (Mpi3DevicePage0_t *) fwevt->event_data;
+		mpi3mr_report_tgtdev_to_host(mrioc,
+		    le16_to_cpu(dev_pg0->PersistentID));
+		break;
+	}
+	case MPI3_EVENT_DEVICE_INFO_CHANGED:
+	{
+		mpi3mr_devinfochg_evt_bh(mrioc,
+		    (Mpi3DevicePage0_t *) fwevt->event_data);
+		break;
+	}
+	case MPI3_EVENT_DEVICE_STATUS_CHANGE:
+	{
+		mpi3mr_devstatuschg_evt_bh(mrioc, fwevt);
+		break;
+	}
+	case MPI3_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
+	{
+		mpi3mr_sastopochg_evt_bh(mrioc, fwevt);
+		break;
+	}
+	default:
+		break;
+	}
+
+evt_ack:
+	if (fwevt->send_ack)
+		mpi3mr_send_event_ack(mrioc, fwevt->event_id,
+		    fwevt->evt_ctx);
+out:
+	/* Put fwevt reference count to neutralize kref_init increment */
+	mpi3mr_fwevt_put(fwevt);
+	mrioc->current_event = NULL;
+
+}
+
+/**
+ * mpi3mr_fwevt_worker - Firmware event worker
+ * @work: Work struct containing firmware event
+ *
+ * Extracts the firmware event and calls mpi3mr_fwevt_bh.
+ *
+ * Return: Nothing.
+ */
+static void mpi3mr_fwevt_worker(struct work_struct *work)
+{
+	struct mpi3mr_fwevt *fwevt = container_of(work, struct mpi3mr_fwevt,
+	    work);
+	mpi3mr_fwevt_bh(fwevt->mrioc, fwevt);
+	/*
+	 * Put fwevt reference count after
+	 * dequeuing it from worker queue
+	 */
+	mpi3mr_fwevt_put(fwevt);
+}
+
+
+/**
+ * mpi3mr_create_tgtdev - Create and add a target device
+ * @mrioc: Adapter instance reference
+ * @dev_pg0: Device Page 0 data
+ *
+ * If the device specified by the device page 0 data is not
+ * present in the driver's internal list, allocate the memory
+ * for the device, populate the data and add to the list, else
+ * update the device data.  The key is persistent ID.
+ *
+ * Return: 0 on success, -ENOMEM on memory allocation failure
+ */
+static int mpi3mr_create_tgtdev(struct mpi3mr_ioc *mrioc,
+	Mpi3DevicePage0_t *dev_pg0)
+{
+	int retval = 0;
+	struct mpi3mr_tgt_dev *tgtdev = NULL;
+	u16 perst_id = 0;
+
+	perst_id = le16_to_cpu(dev_pg0->PersistentID);
+	tgtdev = mpi3mr_get_tgtdev_by_perst_id(mrioc, perst_id);
+	if (tgtdev) {
+		mpi3mr_update_tgtdev(mrioc, tgtdev, dev_pg0);
+		mpi3mr_tgtdev_put(tgtdev);
+	} else {
+		tgtdev = mpi3mr_alloc_tgtdev();
+		if (!tgtdev)
+			return -ENOMEM;
+		mpi3mr_update_tgtdev(mrioc, tgtdev, dev_pg0);
+		mpi3mr_tgtdev_add_to_list(mrioc, tgtdev);
+	}
+
+	return retval;
+}
+
+/**
+ * mpi3mr_flush_delayed_rmhs_list - Flush pending commands
+ * @mrioc: Adapter instance reference
+ * @cmdparam: Internal command tracker
+ *
+ * Flush pending commands in the delayed removal handshake list
+ * due to a controller reset or driver removal as a cleanup.
+ *
+ * Return: Nothing
+ */
+void mpi3mr_flush_delayed_rmhs_list(struct mpi3mr_ioc *mrioc)
+{
+	struct delayed_dev_rmhs_node *_rmhs_node;
+
+	while (!list_empty(&mrioc->delayed_rmhs_list)) {
+		_rmhs_node = list_entry(mrioc->delayed_rmhs_list.next,
+		    struct delayed_dev_rmhs_node, list);
+		list_del(&_rmhs_node->list);
+		kfree(_rmhs_node);
+	}
+}
+
+/**
+ * mpi3mr_dev_rmhs_complete_iou - Device removal IOUC completion
+ * @mrioc: Adapter instance reference
+ * @cmdparam: Internal command tracker
+ *
+ * Issues a target reset TM to the firmware from the device
+ * removal TM pend list or retry the removal handshake sequence
+ * based on the IOU control request IOC status.
+ *
+ * Return: Nothing
+ */
+static void mpi3mr_dev_rmhs_complete_iou(struct mpi3mr_ioc *mrioc,
+	struct mpi3mr_drv_cmd *drv_cmd)
+{
+	u16 cmd_idx = drv_cmd->host_tag - MPI3MR_HOSTTAG_DEVRMCMD_MIN;
+	struct delayed_dev_rmhs_node *delayed_dev_rmhs = NULL;
+
+	ioc_info(mrioc,
+	    "%s :dev_rmhs_iouctrl_complete:handle(0x%04x), ioc_status(0x%04x), loginfo(0x%08x)\n",
+	    __func__, drv_cmd->dev_handle, drv_cmd->ioc_status,
+	    drv_cmd->ioc_loginfo);
+	if (drv_cmd->ioc_status != MPI3_IOCSTATUS_SUCCESS) {
+		if (drv_cmd->retry_count < MPI3MR_DEV_RMHS_RETRY_COUNT) {
+			drv_cmd->retry_count++;
+			ioc_info(mrioc,
+			    "%s :dev_rmhs_iouctrl_complete: handle(0x%04x)retrying handshake retry=%d\n",
+			    __func__, drv_cmd->dev_handle,
+			    drv_cmd->retry_count);
+			mpi3mr_dev_rmhs_send_tm(mrioc, drv_cmd->dev_handle,
+			    drv_cmd, drv_cmd->iou_rc);
+			return;
+		}
+		ioc_err(mrioc,
+		    "%s :dev removal handshake failed after all retries: handle(0x%04x)\n",
+		    __func__, drv_cmd->dev_handle);
+	} else {
+		ioc_info(mrioc,
+		    "%s :dev removal handshake completed successfully: handle(0x%04x)\n",
+		    __func__, drv_cmd->dev_handle);
+		clear_bit(drv_cmd->dev_handle, mrioc->removepend_bitmap);
+	}
+
+	if (!list_empty(&mrioc->delayed_rmhs_list)) {
+		delayed_dev_rmhs = list_entry(mrioc->delayed_rmhs_list.next,
+		    struct delayed_dev_rmhs_node, list);
+		drv_cmd->dev_handle = delayed_dev_rmhs->handle;
+		drv_cmd->retry_count = 0;
+		drv_cmd->iou_rc = delayed_dev_rmhs->iou_rc;
+		ioc_info(mrioc,
+		    "%s :dev_rmhs_iouctrl_complete: processing delayed TM: handle(0x%04x)\n",
+		    __func__, drv_cmd->dev_handle);
+		mpi3mr_dev_rmhs_send_tm(mrioc, drv_cmd->dev_handle, drv_cmd,
+		    drv_cmd->iou_rc);
+		list_del(&delayed_dev_rmhs->list);
+		kfree(delayed_dev_rmhs);
+		return;
+	}
+	drv_cmd->state = MPI3MR_CMD_NOTUSED;
+	drv_cmd->callback = NULL;
+	drv_cmd->retry_count = 0;
+	drv_cmd->dev_handle = MPI3MR_INVALID_DEV_HANDLE;
+	clear_bit(cmd_idx, mrioc->devrem_bitmap);
+}
+
+/**
+ * mpi3mr_dev_rmhs_complete_tm - Device removal TM completion
+ * @mrioc: Adapter instance reference
+ * @cmdparam: Internal command tracker
+ *
+ * Issues a target reset TM to the firmware from the device
+ * removal TM pend list or issue IO Unit control request as
+ * part of device removal or hidden acknowledgment handshake.
+ *
+ * Return: Nothing
+ */
+static void mpi3mr_dev_rmhs_complete_tm(struct mpi3mr_ioc *mrioc,
+	struct mpi3mr_drv_cmd *drv_cmd)
+{
+	Mpi3IoUnitControlRequest_t iou_ctrl;
+	u16 cmd_idx = drv_cmd->host_tag - MPI3MR_HOSTTAG_DEVRMCMD_MIN;
+	Mpi3SCSITaskMgmtReply_t *tm_reply = NULL;
+	int retval;
+
+	if (drv_cmd->state & MPI3MR_CMD_REPLY_VALID)
+		tm_reply = (Mpi3SCSITaskMgmtReply_t *)drv_cmd->reply;
+
+	if (tm_reply)
+		pr_info(IOCNAME
+		    "dev_rmhs_tr_complete:handle(0x%04x), ioc_status(0x%04x), loginfo(0x%08x), term_count(%d)\n",
+		    mrioc->name, drv_cmd->dev_handle, drv_cmd->ioc_status,
+		    drv_cmd->ioc_loginfo,
+		    le32_to_cpu(tm_reply->TerminationCount));
+
+	pr_info(IOCNAME "Issuing IOU CTL: handle(0x%04x) dev_rmhs idx(%d)\n",
+	    mrioc->name, drv_cmd->dev_handle, cmd_idx);
+
+	memset(&iou_ctrl, 0, sizeof(iou_ctrl));
+
+	drv_cmd->state = MPI3MR_CMD_PENDING;
+	drv_cmd->is_waiting = 0;
+	drv_cmd->callback = mpi3mr_dev_rmhs_complete_iou;
+	iou_ctrl.Operation = drv_cmd->iou_rc;
+	iou_ctrl.Param16[0] = cpu_to_le16(drv_cmd->dev_handle);
+	iou_ctrl.HostTag = cpu_to_le16(drv_cmd->host_tag);
+	iou_ctrl.Function = MPI3_FUNCTION_IO_UNIT_CONTROL;
+
+	retval = mpi3mr_admin_request_post(mrioc, &iou_ctrl, sizeof(iou_ctrl),
+	    1);
+	if (retval) {
+		pr_err(IOCNAME "Issue DevRmHsTMIOUCTL: Admin post failed\n",
+		    mrioc->name);
+		goto out_failed;
+	}
+
+	return;
+out_failed:
+	drv_cmd->state = MPI3MR_CMD_NOTUSED;
+	drv_cmd->callback = NULL;
+	drv_cmd->dev_handle = MPI3MR_INVALID_DEV_HANDLE;
+	drv_cmd->retry_count = 0;
+	clear_bit(cmd_idx, mrioc->devrem_bitmap);
+}
+
+/**
+ * mpi3mr_dev_rmhs_send_tm - Issue TM for device removal
+ * @mrioc: Adapter instance reference
+ * @handle: Device handle
+ * @cmdparam: Internal command tracker
+ * @iou_rc: IO Unit reason code
+ *
+ * Issues a target reset TM to the firmware or add it to a pend
+ * list as part of device removal or hidden acknowledgment
+ * handshake.
+ *
+ * Return: Nothing
+ */
+static void mpi3mr_dev_rmhs_send_tm(struct mpi3mr_ioc *mrioc, u16 handle,
+	struct mpi3mr_drv_cmd *cmdparam, u8 iou_rc)
+{
+	Mpi3SCSITaskMgmtRequest_t tm_req;
+	int retval = 0;
+	u16 cmd_idx = MPI3MR_NUM_DEVRMCMD;
+	u8 retrycount = 5;
+	struct mpi3mr_drv_cmd *drv_cmd = cmdparam;
+	struct delayed_dev_rmhs_node *delayed_dev_rmhs = NULL;
+
+	if (drv_cmd)
+		goto issue_cmd;
+	do {
+		cmd_idx = find_first_zero_bit(mrioc->devrem_bitmap,
+		    MPI3MR_NUM_DEVRMCMD);
+		if (cmd_idx < MPI3MR_NUM_DEVRMCMD) {
+			if (!test_and_set_bit(cmd_idx, mrioc->devrem_bitmap))
+				break;
+			cmd_idx = MPI3MR_NUM_DEVRMCMD;
+		}
+	} while (retrycount--);
+
+	if (cmd_idx >= MPI3MR_NUM_DEVRMCMD) {
+		delayed_dev_rmhs = kzalloc(sizeof(*delayed_dev_rmhs),
+		    GFP_ATOMIC);
+		if (!delayed_dev_rmhs)
+			return;
+		INIT_LIST_HEAD(&delayed_dev_rmhs->list);
+		delayed_dev_rmhs->handle = handle;
+		delayed_dev_rmhs->iou_rc = iou_rc;
+		list_add_tail(&delayed_dev_rmhs->list,
+		    &mrioc->delayed_rmhs_list);
+		ioc_info(mrioc, "%s :DevRmHs: tr:handle(0x%04x) is postponed\n",
+		    __func__, handle);
+		return;
+	}
+	drv_cmd = &mrioc->dev_rmhs_cmds[cmd_idx];
+
+issue_cmd:
+	cmd_idx = drv_cmd->host_tag - MPI3MR_HOSTTAG_DEVRMCMD_MIN;
+	ioc_info(mrioc,
+	    "%s :Issuing TR TM: for devhandle 0x%04x with dev_rmhs %d\n",
+	    __func__, handle, cmd_idx);
+
+	memset(&tm_req, 0, sizeof(tm_req));
+	if (drv_cmd->state & MPI3MR_CMD_PENDING) {
+		ioc_err(mrioc, "%s :Issue TM: Command is in use\n", __func__);
+		goto out;
+	}
+	drv_cmd->state = MPI3MR_CMD_PENDING;
+	drv_cmd->is_waiting = 0;
+	drv_cmd->callback = mpi3mr_dev_rmhs_complete_tm;
+	drv_cmd->dev_handle = handle;
+	drv_cmd->iou_rc = iou_rc;
+	tm_req.DevHandle = cpu_to_le16(handle);
+	tm_req.TaskType = MPI3_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
+	tm_req.HostTag = cpu_to_le16(drv_cmd->host_tag);
+	tm_req.TaskHostTag = cpu_to_le16(MPI3MR_HOSTTAG_INVALID);
+	tm_req.Function = MPI3_FUNCTION_SCSI_TASK_MGMT;
+
+	set_bit(handle, mrioc->removepend_bitmap);
+	retval = mpi3mr_admin_request_post(mrioc, &tm_req, sizeof(tm_req), 1);
+	if (retval) {
+		ioc_err(mrioc, "%s :Issue DevRmHsTM: Admin Post failed\n",
+		    __func__);
+		goto out_failed;
+	}
+out:
+	return;
+out_failed:
+	drv_cmd->state = MPI3MR_CMD_NOTUSED;
+	drv_cmd->callback = NULL;
+	drv_cmd->dev_handle = MPI3MR_INVALID_DEV_HANDLE;
+	drv_cmd->retry_count = 0;
+	clear_bit(cmd_idx, mrioc->devrem_bitmap);
+}
+
+/**
+ * mpi3mr_sastopochg_evt_th - SASTopologyChange evt tophalf
+ * @mrioc: Adapter instance reference
+ * @event_reply: Event data
+ *
+ * Checks for the reason code and based on that either block I/O
+ * to device, or unblock I/O to the device, or start the device
+ * removal handshake with reason as remove with the firmware for
+ * SAS/SATA devices.
+ *
+ * Return: Nothing
+ */
+static void mpi3mr_sastopochg_evt_th(struct mpi3mr_ioc *mrioc,
+	Mpi3EventNotificationReply_t *event_reply)
+{
+	Mpi3EventDataSasTopologyChangeList_t *topo_evt =
+	    (Mpi3EventDataSasTopologyChangeList_t *)event_reply->EventData;
+	int i;
+	u16 handle;
+	u8 reason_code;
+	struct mpi3mr_tgt_dev *tgtdev = NULL;
+	struct mpi3mr_stgt_priv_data *scsi_tgt_priv_data = NULL;
+
+	for (i = 0; i < topo_evt->NumEntries; i++) {
+		handle = le16_to_cpu(topo_evt->PhyEntry[i].AttachedDevHandle);
+		if (!handle)
+			continue;
+		reason_code = topo_evt->PhyEntry[i].Status &
+		    MPI3_EVENT_SAS_TOPO_PHY_RC_MASK;
+		scsi_tgt_priv_data =  NULL;
+		tgtdev = mpi3mr_get_tgtdev_by_handle(mrioc, handle);
+		if (tgtdev && tgtdev->starget && tgtdev->starget->hostdata)
+			scsi_tgt_priv_data = (struct mpi3mr_stgt_priv_data *)
+			    tgtdev->starget->hostdata;
+		switch (reason_code) {
+		case MPI3_EVENT_SAS_TOPO_PHY_RC_TARG_NOT_RESPONDING:
+			if (scsi_tgt_priv_data) {
+				scsi_tgt_priv_data->dev_removed = 1;
+				scsi_tgt_priv_data->dev_removedelay = 0;
+				atomic_set(&scsi_tgt_priv_data->block_io, 0);
+			}
+			mpi3mr_dev_rmhs_send_tm(mrioc, handle, NULL,
+			    MPI3_CTRL_OP_REMOVE_DEVICE);
+			break;
+		case MPI3_EVENT_SAS_TOPO_PHY_RC_DELAY_NOT_RESPONDING:
+			if (scsi_tgt_priv_data) {
+				scsi_tgt_priv_data->dev_removedelay = 1;
+				atomic_inc(&scsi_tgt_priv_data->block_io);
+			}
+			break;
+		case MPI3_EVENT_SAS_TOPO_PHY_RC_RESPONDING:
+			if (scsi_tgt_priv_data &&
+			    scsi_tgt_priv_data->dev_removedelay) {
+				scsi_tgt_priv_data->dev_removedelay = 0;
+				atomic_dec_if_positive
+				    (&scsi_tgt_priv_data->block_io);
+			}
+		case MPI3_EVENT_SAS_TOPO_PHY_RC_PHY_CHANGED:
+		default:
+			break;
+		}
+		if (tgtdev)
+			mpi3mr_tgtdev_put(tgtdev);
+	}
+
+}
+
+/**
+ * mpi3mr_devstatuschg_evt_th - DeviceStatusChange evt tophalf
+ * @mrioc: Adapter instance reference
+ * @event_reply: Event data
+ *
+ * Checks for the reason code and based on that either block I/O
+ * to device, or unblock I/O to the device, or start the device
+ * removal handshake with reason as remove/hide acknowledgment
+ * with the firmware.
+ *
+ * Return: Nothing
+ */
+static void mpi3mr_devstatuschg_evt_th(struct mpi3mr_ioc *mrioc,
+	Mpi3EventNotificationReply_t *event_reply)
+{
+	u16 dev_handle = 0;
+	u8 ublock = 0, block = 0, hide = 0, delete = 0, remove = 0;
+	struct mpi3mr_tgt_dev *tgtdev = NULL;
+	struct mpi3mr_stgt_priv_data *scsi_tgt_priv_data = NULL;
+	Mpi3EventDataDeviceStatusChange_t *evtdata =
+	    (Mpi3EventDataDeviceStatusChange_t *) event_reply->EventData;
+
+	if (mrioc->stop_drv_processing)
+		goto out;
+
+	dev_handle = le16_to_cpu(evtdata->DevHandle);
+
+	switch (evtdata->ReasonCode) {
+	case MPI3_EVENT_DEV_STAT_RC_INT_DEVICE_RESET_STRT:
+	case MPI3_EVENT_DEV_STAT_RC_INT_IT_NEXUS_RESET_STRT:
+		block = 1;
+		break;
+	case MPI3_EVENT_DEV_STAT_RC_HIDDEN:
+		delete = 1;
+		hide = 1;
+		break;
+	case MPI3_EVENT_DEV_STAT_RC_VD_NOT_RESPONDING:
+		delete = 1;
+		remove = 1;
+		break;
+	case MPI3_EVENT_DEV_STAT_RC_INT_DEVICE_RESET_CMP:
+	case MPI3_EVENT_DEV_STAT_RC_INT_IT_NEXUS_RESET_CMP:
+		ublock = 1;
+		break;
+	default:
+		break;
+	}
+
+	tgtdev = mpi3mr_get_tgtdev_by_handle(mrioc, dev_handle);
+	if (!tgtdev)
+		goto out;
+	if (hide)
+		tgtdev->is_hidden = hide;
+	if (tgtdev->starget && tgtdev->starget->hostdata) {
+		scsi_tgt_priv_data = (struct mpi3mr_stgt_priv_data *)
+		    tgtdev->starget->hostdata;
+		if (block)
+			atomic_inc(&scsi_tgt_priv_data->block_io);
+		if (delete)
+			scsi_tgt_priv_data->dev_removed = 1;
+		if (ublock)
+			atomic_dec_if_positive(&scsi_tgt_priv_data->block_io);
+	}
+	if (remove)
+		mpi3mr_dev_rmhs_send_tm(mrioc, dev_handle, NULL,
+		    MPI3_CTRL_OP_REMOVE_DEVICE);
+	if (hide)
+		mpi3mr_dev_rmhs_send_tm(mrioc, dev_handle, NULL,
+		    MPI3_CTRL_OP_HIDDEN_ACK);
+
+out:
+	if (tgtdev)
+		mpi3mr_tgtdev_put(tgtdev);
+
+}
+
+/**
+ * mpi3mr_os_handle_events - Firmware event handler
+ * @mrioc: Adapter instance reference
+ * @event_reply: Event data
+ *
+ * Identify whteher the event has to handled and acknowledged
+ * and either process the event in the tophalf and/or schedule a
+ * bottom half through mpi3mr_fwevt_worker.
+ *
+ * Return: Nothing
+ */
+void mpi3mr_os_handle_events(struct mpi3mr_ioc *mrioc,
+	Mpi3EventNotificationReply_t *event_reply)
+{
+	u16 evt_type, sz;
+	struct mpi3mr_fwevt *fwevt = NULL;
+	bool ack_req = 0, process_evt_bh = 0;
+
+	if (mrioc->stop_drv_processing)
+		return;
+
+	if ((event_reply->MsgFlags & MPI3_EVENT_NOTIFY_MSGFLAGS_ACK_MASK)
+	    == MPI3_EVENT_NOTIFY_MSGFLAGS_ACK_REQUIRED)
+		ack_req = 1;
+
+	evt_type = event_reply->Event;
+
+	switch (evt_type) {
+	case MPI3_EVENT_DEVICE_ADDED:
+	{
+		Mpi3DevicePage0_t *dev_pg0 =
+		    (Mpi3DevicePage0_t *) event_reply->EventData;
+		if (mpi3mr_create_tgtdev(mrioc, dev_pg0))
+			ioc_err(mrioc,
+			    "%s :Failed to add device in the device add event\n",
+			    __func__);
+		else
+			process_evt_bh = 1;
+		break;
+	}
+	case MPI3_EVENT_DEVICE_STATUS_CHANGE:
+	{
+		process_evt_bh = 1;
+		mpi3mr_devstatuschg_evt_th(mrioc, event_reply);
+		break;
+	}
+	case MPI3_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
+	{
+		process_evt_bh = 1;
+		mpi3mr_sastopochg_evt_th(mrioc, event_reply);
+		break;
+	}
+	case MPI3_EVENT_DEVICE_INFO_CHANGED:
+	{
+		process_evt_bh = 1;
+		break;
+	}
+	case MPI3_EVENT_ENCL_DEVICE_STATUS_CHANGE:
+	case MPI3_EVENT_SAS_DISCOVERY:
+	case MPI3_EVENT_SAS_DEVICE_DISCOVERY_ERROR:
+		break;
+	default:
+		ioc_info(mrioc, "%s :Event 0x%02x is not handled\n",
+		    __func__, evt_type);
+		break;
+	}
+	if (process_evt_bh || ack_req) {
+		sz = event_reply->EventDataLength * 4;
+		fwevt = mpi3mr_alloc_fwevt(sz);
+		if (!fwevt) {
+			ioc_info(mrioc, "%s :failure at %s:%d/%s()!\n",
+			    __func__, __FILE__, __LINE__, __func__);
+			return;
+		}
+
+		memcpy(fwevt->event_data, event_reply->EventData, sz);
+		fwevt->mrioc = mrioc;
+		fwevt->event_id = evt_type;
+		fwevt->send_ack = ack_req;
+		fwevt->process_evt = process_evt_bh;
+		fwevt->evt_ctx = le32_to_cpu(event_reply->EventContext);
+		mpi3mr_fwevt_add_to_list(mrioc, fwevt);
+	}
+
+}
+
 /**
  * mpi3mr_process_op_reply_desc - reply descriptor handler
  * @mrioc: Adapter instance reference
@@ -587,6 +1865,33 @@ static int mpi3mr_scan_finished(struct Scsi_Host *shost,
  */
 static void mpi3mr_slave_destroy(struct scsi_device *sdev)
 {
+	struct Scsi_Host *shost;
+	struct mpi3mr_ioc *mrioc;
+	struct mpi3mr_stgt_priv_data *scsi_tgt_priv_data;
+	struct mpi3mr_tgt_dev *tgt_dev;
+	unsigned long flags;
+	struct scsi_target *starget;
+
+	if (!sdev->hostdata)
+		return;
+
+	starget = scsi_target(sdev);
+	shost = dev_to_shost(&starget->dev);
+	mrioc = shost_priv(shost);
+	scsi_tgt_priv_data = starget->hostdata;
+
+	scsi_tgt_priv_data->num_luns--;
+
+	spin_lock_irqsave(&mrioc->tgtdev_lock, flags);
+	tgt_dev = __mpi3mr_get_tgtdev_by_perst_id(mrioc, starget->id);
+	if (tgt_dev && (!scsi_tgt_priv_data->num_luns))
+		tgt_dev->starget = NULL;
+	if (tgt_dev)
+		mpi3mr_tgtdev_put(tgt_dev);
+	spin_unlock_irqrestore(&mrioc->tgtdev_lock, flags);
+
+	kfree(sdev->hostdata);
+	sdev->hostdata = NULL;
 }
 
 /**
@@ -599,6 +1904,35 @@ static void mpi3mr_slave_destroy(struct scsi_device *sdev)
  */
 static void mpi3mr_target_destroy(struct scsi_target *starget)
 {
+	struct Scsi_Host *shost;
+	struct mpi3mr_ioc *mrioc;
+	struct mpi3mr_stgt_priv_data *scsi_tgt_priv_data;
+	struct mpi3mr_tgt_dev *tgt_dev;
+	unsigned long flags;
+
+	if (!starget->hostdata)
+		return;
+
+	shost = dev_to_shost(&starget->dev);
+	mrioc = shost_priv(shost);
+	scsi_tgt_priv_data = starget->hostdata;
+
+	spin_lock_irqsave(&mrioc->tgtdev_lock, flags);
+	tgt_dev = __mpi3mr_get_tgtdev_from_tgtpriv(mrioc, scsi_tgt_priv_data);
+	if (tgt_dev && (tgt_dev->starget == starget) &&
+	    (tgt_dev->perst_id == starget->id))
+		tgt_dev->starget = NULL;
+	if (tgt_dev) {
+		scsi_tgt_priv_data->tgt_dev = NULL;
+		scsi_tgt_priv_data->perst_id = 0;
+		mpi3mr_tgtdev_put(tgt_dev);
+		mpi3mr_tgtdev_put(tgt_dev);
+	}
+	spin_unlock_irqrestore(&mrioc->tgtdev_lock, flags);
+
+	kfree(starget->hostdata);
+	starget->hostdata = NULL;
+
 }
 
 /**
@@ -612,7 +1946,25 @@ static void mpi3mr_target_destroy(struct scsi_target *starget)
  */
 static int mpi3mr_slave_configure(struct scsi_device *sdev)
 {
+	struct scsi_target *starget;
+	struct Scsi_Host *shost;
+	struct mpi3mr_ioc *mrioc;
+	struct mpi3mr_tgt_dev *tgt_dev;
+	unsigned long flags;
 	int retval = 0;
+
+	starget = scsi_target(sdev);
+	shost = dev_to_shost(&starget->dev);
+	mrioc = shost_priv(shost);
+
+	spin_lock_irqsave(&mrioc->tgtdev_lock, flags);
+	tgt_dev = __mpi3mr_get_tgtdev_by_perst_id(mrioc, starget->id);
+	spin_unlock_irqrestore(&mrioc->tgtdev_lock, flags);
+	if (!tgt_dev)
+		return retval;
+
+	mpi3mr_tgtdev_put(tgt_dev);
+
 	return retval;
 }
 
@@ -626,7 +1978,37 @@ static int mpi3mr_slave_configure(struct scsi_device *sdev)
  */
 static int mpi3mr_slave_alloc(struct scsi_device *sdev)
 {
+	struct Scsi_Host *shost;
+	struct mpi3mr_ioc *mrioc;
+	struct mpi3mr_stgt_priv_data *scsi_tgt_priv_data;
+	struct mpi3mr_tgt_dev *tgt_dev;
+	struct mpi3mr_sdev_priv_data *scsi_dev_priv_data;
+	unsigned long flags;
+	struct scsi_target *starget;
 	int retval = 0;
+
+	starget = scsi_target(sdev);
+	shost = dev_to_shost(&starget->dev);
+	mrioc = shost_priv(shost);
+	scsi_tgt_priv_data = starget->hostdata;
+
+	scsi_dev_priv_data = kzalloc(sizeof(*scsi_dev_priv_data), GFP_KERNEL);
+	if (!scsi_dev_priv_data)
+		return -ENOMEM;
+
+	scsi_dev_priv_data->lun_id = sdev->lun;
+	scsi_dev_priv_data->tgt_priv_data = scsi_tgt_priv_data;
+	sdev->hostdata = scsi_dev_priv_data;
+
+	scsi_tgt_priv_data->num_luns++;
+
+	spin_lock_irqsave(&mrioc->tgtdev_lock, flags);
+	tgt_dev = __mpi3mr_get_tgtdev_by_perst_id(mrioc, starget->id);
+	if (tgt_dev && (tgt_dev->starget == NULL))
+		tgt_dev->starget = starget;
+	if (tgt_dev)
+		mpi3mr_tgtdev_put(tgt_dev);
+	spin_unlock_irqrestore(&mrioc->tgtdev_lock, flags);
 	return retval;
 }
 
@@ -640,7 +2022,33 @@ static int mpi3mr_slave_alloc(struct scsi_device *sdev)
  */
 static int mpi3mr_target_alloc(struct scsi_target *starget)
 {
+	struct Scsi_Host *shost = dev_to_shost(&starget->dev);
+	struct mpi3mr_ioc *mrioc = shost_priv(shost);
+	struct mpi3mr_stgt_priv_data *scsi_tgt_priv_data;
+	struct mpi3mr_tgt_dev *tgt_dev;
+	unsigned long flags;
 	int retval = -ENODEV;
+
+	scsi_tgt_priv_data = kzalloc(sizeof(*scsi_tgt_priv_data), GFP_KERNEL);
+	if (!scsi_tgt_priv_data)
+		return -ENOMEM;
+
+	starget->hostdata = scsi_tgt_priv_data;
+	scsi_tgt_priv_data->starget = starget;
+	scsi_tgt_priv_data->dev_handle = MPI3MR_INVALID_DEV_HANDLE;
+
+	spin_lock_irqsave(&mrioc->tgtdev_lock, flags);
+	tgt_dev = __mpi3mr_get_tgtdev_by_perst_id(mrioc, starget->id);
+	if (tgt_dev && !tgt_dev->is_hidden) {
+		scsi_tgt_priv_data->dev_handle = tgt_dev->dev_handle;
+		scsi_tgt_priv_data->perst_id = tgt_dev->perst_id;
+		scsi_tgt_priv_data->dev_type = tgt_dev->dev_type;
+		scsi_tgt_priv_data->tgt_dev = tgt_dev;
+		tgt_dev->starget = starget;
+		atomic_set(&scsi_tgt_priv_data->block_io, 0);
+		retval = 0;
+	}
+	spin_unlock_irqrestore(&mrioc->tgtdev_lock, flags);
 	return retval;
 }
 
@@ -857,9 +2265,15 @@ mpi3mr_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	spin_lock_init(&mrioc->admin_req_lock);
 	spin_lock_init(&mrioc->reply_free_queue_lock);
 	spin_lock_init(&mrioc->sbq_lock);
+	spin_lock_init(&mrioc->fwevt_lock);
+	spin_lock_init(&mrioc->tgtdev_lock);
 	spin_lock_init(&mrioc->watchdog_lock);
 	spin_lock_init(&mrioc->chain_buf_lock);
 
+	INIT_LIST_HEAD(&mrioc->fwevt_list);
+	INIT_LIST_HEAD(&mrioc->tgtdev_list);
+	INIT_LIST_HEAD(&mrioc->delayed_rmhs_list);
+
 	mpi3mr_init_drv_cmd(&mrioc->init_cmds, MPI3MR_HOSTTAG_INITCMDS);
 
 	if (pdev->revision)
@@ -877,6 +2291,17 @@ mpi3mr_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	shost->max_channel = 1;
 	shost->max_id = 0xFFFFFFFF;
 
+	snprintf(mrioc->fwevt_worker_name, sizeof(mrioc->fwevt_worker_name),
+	    "%s%d_fwevt_wrkr", mrioc->driver_name, mrioc->id);
+	mrioc->fwevt_worker_thread = alloc_ordered_workqueue(
+	    mrioc->fwevt_worker_name, WQ_MEM_RECLAIM);
+	if (!mrioc->fwevt_worker_thread) {
+		ioc_err(mrioc, "failure at %s:%d/%s()!\n",
+		    __FILE__, __LINE__, __func__);
+		retval = -ENODEV;
+		goto out_fwevtthread_failed;
+	}
+
 	mrioc->is_driver_loading = 1;
 	if (mpi3mr_init_ioc(mrioc)) {
 		ioc_err(mrioc, "failure at %s:%d/%s()!\n",
@@ -903,6 +2328,8 @@ mpi3mr_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 addhost_failed:
 	mpi3mr_cleanup_ioc(mrioc);
 out_iocinit_failed:
+	destroy_workqueue(mrioc->fwevt_worker_thread);
+out_fwevtthread_failed:
 	spin_lock(&mrioc_list_lock);
 	list_del(&mrioc->list);
 	spin_unlock(&mrioc_list_lock);
@@ -924,14 +2351,30 @@ static void mpi3mr_remove(struct pci_dev *pdev)
 {
 	struct Scsi_Host *shost = pci_get_drvdata(pdev);
 	struct mpi3mr_ioc *mrioc;
+	struct workqueue_struct	*wq;
+	unsigned long flags;
+	struct mpi3mr_tgt_dev *tgtdev, *tgtdev_next;
 
 	mrioc = shost_priv(shost);
 	while (mrioc->reset_in_progress || mrioc->is_driver_loading)
 		ssleep(1);
 
 	mrioc->stop_drv_processing = 1;
+	mpi3mr_cleanup_fwevt_list(mrioc);
+	spin_lock_irqsave(&mrioc->fwevt_lock, flags);
+	wq = mrioc->fwevt_worker_thread;
+	mrioc->fwevt_worker_thread = NULL;
+	spin_unlock_irqrestore(&mrioc->fwevt_lock, flags);
+	if (wq)
+		destroy_workqueue(wq);
 
 	scsi_remove_host(shost);
+	list_for_each_entry_safe(tgtdev, tgtdev_next, &mrioc->tgtdev_list,
+	    list) {
+		mpi3mr_remove_tgtdev_from_host(mrioc, tgtdev);
+		mpi3mr_tgtdev_del_from_list(mrioc, tgtdev);
+		mpi3mr_tgtdev_put(tgtdev);
+	}
 
 	mpi3mr_cleanup_ioc(mrioc);
 
@@ -955,6 +2398,8 @@ static void mpi3mr_shutdown(struct pci_dev *pdev)
 {
 	struct Scsi_Host *shost = pci_get_drvdata(pdev);
 	struct mpi3mr_ioc *mrioc;
+	struct workqueue_struct	*wq;
+	unsigned long flags;
 
 	if (!shost)
 		return;
@@ -963,6 +2408,13 @@ static void mpi3mr_shutdown(struct pci_dev *pdev)
 	while (mrioc->reset_in_progress || mrioc->is_driver_loading)
 		ssleep(1);
 	mrioc->stop_drv_processing = 1;
+	mpi3mr_cleanup_fwevt_list(mrioc);
+	spin_lock_irqsave(&mrioc->fwevt_lock, flags);
+	wq = mrioc->fwevt_worker_thread;
+	mrioc->fwevt_worker_thread = NULL;
+	spin_unlock_irqrestore(&mrioc->fwevt_lock, flags);
+	if (wq)
+		destroy_workqueue(wq);
 
 	mpi3mr_cleanup_ioc(mrioc);
 
-- 
2.18.1


-- 
This electronic communication and the information and any files transmitted 
with it, or attached to it, are confidential and are intended solely for 
the use of the individual or entity to whom it is addressed and may contain 
information that is confidential, legally privileged, protected by privacy 
laws, or otherwise restricted from disclosure to anyone else. If you are 
not the intended recipient or the person responsible for delivering the 
e-mail to the intended recipient, you are hereby notified that any use, 
copying, distributing, dissemination, forwarding, printing, or copying of 
this e-mail is strictly prohibited. If you received this e-mail in error, 
please return the e-mail to the sender, delete it from your computer, and 
destroy any printed copy of it.

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4169 bytes --]

^ permalink raw reply related	[flat|nested] 75+ messages in thread

* [PATCH 07/24] mpi3mr: add support of event handling pcie devices part-2
  2020-12-22 10:11 [PATCH 00/24] Introducing mpi3mr driver Kashyap Desai
                   ` (5 preceding siblings ...)
  2020-12-22 10:11 ` [PATCH 06/24] mpi3mr: add support of event handling part-1 Kashyap Desai
@ 2020-12-22 10:11 ` Kashyap Desai
  2021-03-01  6:52   ` Hannes Reinecke
  2020-12-22 10:11 ` [PATCH 08/24] mpi3mr: add support of event handling part-3 Kashyap Desai
                   ` (17 subsequent siblings)
  24 siblings, 1 reply; 75+ messages in thread
From: Kashyap Desai @ 2020-12-22 10:11 UTC (permalink / raw)
  To: linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, Kashyap Desai, sathya.prakash

[-- Attachment #1: Type: text/plain, Size: 10068 bytes --]

Firmware can report various MPI Events.
Support for certain Events (as listed below) are enabled in the driver
and their processing in driver is covered in this patch.

MPI3_EVENT_PCIE_TOPOLOGY_CHANGE_LIST
MPI3_EVENT_PCIE_ENUMERATION

Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Cc: sathya.prakash@broadcom.com
---
 drivers/scsi/mpi3mr/mpi3mr_fw.c |   2 +
 drivers/scsi/mpi3mr/mpi3mr_os.c | 202 ++++++++++++++++++++++++++++++++
 2 files changed, 204 insertions(+)

diff --git a/drivers/scsi/mpi3mr/mpi3mr_fw.c b/drivers/scsi/mpi3mr/mpi3mr_fw.c
index c3933c9b73fc..c70c75fdac5c 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_fw.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_fw.c
@@ -2735,6 +2735,8 @@ int mpi3mr_init_ioc(struct mpi3mr_ioc *mrioc)
 	mpi3mr_unmask_events(mrioc, MPI3_EVENT_SAS_TOPOLOGY_CHANGE_LIST);
 	mpi3mr_unmask_events(mrioc, MPI3_EVENT_SAS_DISCOVERY);
 	mpi3mr_unmask_events(mrioc, MPI3_EVENT_SAS_DEVICE_DISCOVERY_ERROR);
+	mpi3mr_unmask_events(mrioc, MPI3_EVENT_PCIE_TOPOLOGY_CHANGE_LIST);
+	mpi3mr_unmask_events(mrioc, MPI3_EVENT_PCIE_ENUMERATION);
 
 	retval = mpi3mr_issue_event_notification(mrioc);
 	if (retval) {
diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c
index e0ca657bfff5..5be25fbe0e5b 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_os.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_os.c
@@ -566,6 +566,40 @@ static int mpi3mr_report_tgtdev_to_host(struct mpi3mr_ioc *mrioc,
 	return retval;
 }
 
+/**
+ * mpi3mr_update_sdev - Update SCSI device information
+ * @sdev: SCSI device reference
+ * @data: target device reference
+ *
+ * This is an iterator function called for each SCSI device in a
+ * target to update the target specific information into each
+ * SCSI device.
+ *
+ * Return: Nothing.
+ */
+static void
+mpi3mr_update_sdev(struct scsi_device *sdev, void *data)
+{
+	struct mpi3mr_tgt_dev *tgtdev;
+
+	tgtdev = (struct mpi3mr_tgt_dev *) data;
+	if (!tgtdev)
+		return;
+
+	switch (tgtdev->dev_type) {
+	case MPI3_DEVICE_DEVFORM_PCIE:
+		/*The block layer hw sector size = 512*/
+		blk_queue_max_hw_sectors(sdev->request_queue,
+		    tgtdev->dev_spec.pcie_inf.mdts / 512);
+		blk_queue_virt_boundary(sdev->request_queue,
+		    ((1 << tgtdev->dev_spec.pcie_inf.pgsz) - 1));
+
+		break;
+	default:
+		break;
+	}
+}
+
 /**
  * mpi3mr_rfresh_tgtdevs - Refresh target device exposure
  * @mrioc: Adapter instance reference
@@ -654,6 +688,33 @@ static void mpi3mr_update_tgtdev(struct mpi3mr_ioc *mrioc,
 			tgtdev->is_hidden = 1;
 		break;
 	}
+	case MPI3_DEVICE_DEVFORM_PCIE:
+	{
+		Mpi3Device0PcieFormat_t *pcieinf =
+		    &dev_pg0->DeviceSpecific.PcieFormat;
+		u16 dev_info = le16_to_cpu(pcieinf->DeviceInfo);
+
+		tgtdev->dev_spec.pcie_inf.capb =
+		    le32_to_cpu(pcieinf->Capabilities);
+		tgtdev->dev_spec.pcie_inf.mdts = MPI3MR_DEFAULT_MDTS;
+		/* 2^12 = 4096 */
+		tgtdev->dev_spec.pcie_inf.pgsz = 12;
+		if (dev_pg0->AccessStatus == MPI3_DEVICE0_ASTATUS_NO_ERRORS) {
+			tgtdev->dev_spec.pcie_inf.mdts =
+			    le32_to_cpu(pcieinf->MaximumDataTransferSize);
+			tgtdev->dev_spec.pcie_inf.pgsz = pcieinf->PageSize;
+			tgtdev->dev_spec.pcie_inf.reset_to =
+			    pcieinf->ControllerResetTO;
+			tgtdev->dev_spec.pcie_inf.abort_to =
+			    pcieinf->NVMeAbortTO;
+		}
+		if (tgtdev->dev_spec.pcie_inf.mdts > (1024 * 1024))
+			tgtdev->dev_spec.pcie_inf.mdts = (1024 * 1024);
+		if ((dev_info & MPI3_DEVICE0_PCIE_DEVICE_INFO_TYPE_MASK) !=
+		    MPI3_DEVICE0_PCIE_DEVICE_INFO_TYPE_NVME_DEVICE)
+			tgtdev->is_hidden = 1;
+		break;
+	}
 	case MPI3_DEVICE_DEVFORM_VD:
 	{
 		Mpi3Device0VdFormat_t *vdinf =
@@ -768,6 +829,9 @@ static void mpi3mr_devinfochg_evt_bh(struct mpi3mr_ioc *mrioc,
 		mpi3mr_report_tgtdev_to_host(mrioc, perst_id);
 	if (tgtdev->is_hidden && tgtdev->host_exposed)
 		mpi3mr_remove_tgtdev_from_host(mrioc, tgtdev);
+	if (!tgtdev->is_hidden && tgtdev->host_exposed && tgtdev->starget)
+		starget_for_each_device(tgtdev->starget, (void *) tgtdev,
+		    mpi3mr_update_sdev);
 out:
 	if (tgtdev)
 		mpi3mr_tgtdev_put(tgtdev);
@@ -821,6 +885,54 @@ static void mpi3mr_sastopochg_evt_bh(struct mpi3mr_ioc *mrioc,
 	}
 }
 
+/**
+ * mpi3mr_pcietopochg_evt_bh - PCIeTopologyChange evt bottomhalf
+ * @mrioc: Adapter instance reference
+ * @fwevt: Firmware event reference
+ *
+ * Prints information about the PCIe topology change event and
+ * for "not responding" event code, removes the device from the
+ * upper layers.
+ *
+ * Return: Nothing.
+ */
+static void mpi3mr_pcietopochg_evt_bh(struct mpi3mr_ioc *mrioc,
+	struct mpi3mr_fwevt *fwevt)
+{
+	Mpi3EventDataPcieTopologyChangeList_t *event_data =
+	    (Mpi3EventDataPcieTopologyChangeList_t *)fwevt->event_data;
+	int i;
+	u16 handle;
+	u8 reason_code;
+	struct mpi3mr_tgt_dev *tgtdev = NULL;
+
+	for (i = 0; i < event_data->NumEntries; i++) {
+		handle =
+		    le16_to_cpu(event_data->PortEntry[i].AttachedDevHandle);
+		if (!handle)
+			continue;
+		tgtdev = mpi3mr_get_tgtdev_by_handle(mrioc, handle);
+		if (!tgtdev)
+			continue;
+
+		reason_code = event_data->PortEntry[i].PortStatus;
+
+		switch (reason_code) {
+		case MPI3_EVENT_PCIE_TOPO_PS_NOT_RESPONDING:
+			if (tgtdev->host_exposed)
+				mpi3mr_remove_tgtdev_from_host(mrioc, tgtdev);
+			mpi3mr_tgtdev_del_from_list(mrioc, tgtdev);
+			mpi3mr_tgtdev_put(tgtdev);
+			break;
+		default:
+			break;
+		}
+		if (tgtdev)
+			mpi3mr_tgtdev_put(tgtdev);
+	}
+}
+
+
 /**
  * mpi3mr_fwevt_bh - Firmware event bottomhalf handler
  * @mrioc: Adapter instance reference
@@ -868,6 +980,11 @@ static void mpi3mr_fwevt_bh(struct mpi3mr_ioc *mrioc,
 		mpi3mr_sastopochg_evt_bh(mrioc, fwevt);
 		break;
 	}
+	case MPI3_EVENT_PCIE_TOPOLOGY_CHANGE_LIST:
+	{
+		mpi3mr_pcietopochg_evt_bh(mrioc, fwevt);
+		break;
+	}
 	default:
 		break;
 	}
@@ -1174,6 +1291,72 @@ static void mpi3mr_dev_rmhs_send_tm(struct mpi3mr_ioc *mrioc, u16 handle,
 	clear_bit(cmd_idx, mrioc->devrem_bitmap);
 }
 
+/**
+ * mpi3mr_pcietopochg_evt_th - PCIETopologyChange evt tophalf
+ * @mrioc: Adapter instance reference
+ * @event_reply: Event data
+ *
+ * Checks for the reason code and based on that either block I/O
+ * to device, or unblock I/O to the device, or start the device
+ * removal handshake with reason as remove with the firmware for
+ * PCIe devices.
+ *
+ * Return: Nothing
+ */
+static void mpi3mr_pcietopochg_evt_th(struct mpi3mr_ioc *mrioc,
+	Mpi3EventNotificationReply_t *event_reply)
+{
+	Mpi3EventDataPcieTopologyChangeList_t *topo_evt =
+	    (Mpi3EventDataPcieTopologyChangeList_t *) event_reply->EventData;
+	int i;
+	u16 handle;
+	u8 reason_code;
+	struct mpi3mr_tgt_dev *tgtdev = NULL;
+	struct mpi3mr_stgt_priv_data *scsi_tgt_priv_data = NULL;
+
+	for (i = 0; i < topo_evt->NumEntries; i++) {
+		handle = le16_to_cpu(topo_evt->PortEntry[i].AttachedDevHandle);
+		if (!handle)
+			continue;
+		reason_code = topo_evt->PortEntry[i].PortStatus;
+		scsi_tgt_priv_data =  NULL;
+		tgtdev = mpi3mr_get_tgtdev_by_handle(mrioc, handle);
+		if (tgtdev && tgtdev->starget && tgtdev->starget->hostdata)
+			scsi_tgt_priv_data = (struct mpi3mr_stgt_priv_data *)
+			    tgtdev->starget->hostdata;
+		switch (reason_code) {
+		case MPI3_EVENT_PCIE_TOPO_PS_NOT_RESPONDING:
+			if (scsi_tgt_priv_data) {
+				scsi_tgt_priv_data->dev_removed = 1;
+				scsi_tgt_priv_data->dev_removedelay = 0;
+				atomic_set(&scsi_tgt_priv_data->block_io, 0);
+			}
+			mpi3mr_dev_rmhs_send_tm(mrioc, handle, NULL,
+			    MPI3_CTRL_OP_REMOVE_DEVICE);
+			break;
+		case MPI3_EVENT_PCIE_TOPO_PS_DELAY_NOT_RESPONDING:
+			if (scsi_tgt_priv_data) {
+				scsi_tgt_priv_data->dev_removedelay = 1;
+				atomic_inc(&scsi_tgt_priv_data->block_io);
+			}
+			break;
+		case MPI3_EVENT_PCIE_TOPO_PS_RESPONDING:
+			if (scsi_tgt_priv_data &&
+			    scsi_tgt_priv_data->dev_removedelay) {
+				scsi_tgt_priv_data->dev_removedelay = 0;
+				atomic_dec_if_positive
+				    (&scsi_tgt_priv_data->block_io);
+			}
+			break;
+		case MPI3_EVENT_PCIE_TOPO_PS_PORT_CHANGED:
+		default:
+			break;
+		}
+		if (tgtdev)
+			mpi3mr_tgtdev_put(tgtdev);
+	}
+}
+
 /**
  * mpi3mr_sastopochg_evt_th - SASTopologyChange evt tophalf
  * @mrioc: Adapter instance reference
@@ -1369,6 +1552,12 @@ void mpi3mr_os_handle_events(struct mpi3mr_ioc *mrioc,
 		mpi3mr_sastopochg_evt_th(mrioc, event_reply);
 		break;
 	}
+	case MPI3_EVENT_PCIE_TOPOLOGY_CHANGE_LIST:
+	{
+		process_evt_bh = 1;
+		mpi3mr_pcietopochg_evt_th(mrioc, event_reply);
+		break;
+	}
 	case MPI3_EVENT_DEVICE_INFO_CHANGED:
 	{
 		process_evt_bh = 1;
@@ -1377,6 +1566,7 @@ void mpi3mr_os_handle_events(struct mpi3mr_ioc *mrioc,
 	case MPI3_EVENT_ENCL_DEVICE_STATUS_CHANGE:
 	case MPI3_EVENT_SAS_DISCOVERY:
 	case MPI3_EVENT_SAS_DEVICE_DISCOVERY_ERROR:
+	case MPI3_EVENT_PCIE_ENUMERATION:
 		break;
 	default:
 		ioc_info(mrioc, "%s :Event 0x%02x is not handled\n",
@@ -1963,6 +2153,18 @@ static int mpi3mr_slave_configure(struct scsi_device *sdev)
 	if (!tgt_dev)
 		return retval;
 
+	switch (tgt_dev->dev_type) {
+	case MPI3_DEVICE_DEVFORM_PCIE:
+		/*The block layer hw sector size = 512*/
+		blk_queue_max_hw_sectors(sdev->request_queue,
+		    tgt_dev->dev_spec.pcie_inf.mdts / 512);
+		blk_queue_virt_boundary(sdev->request_queue,
+		    ((1 << tgt_dev->dev_spec.pcie_inf.pgsz) - 1));
+		break;
+	default:
+		break;
+	}
+
 	mpi3mr_tgtdev_put(tgt_dev);
 
 	return retval;
-- 
2.18.1


-- 
This electronic communication and the information and any files transmitted 
with it, or attached to it, are confidential and are intended solely for 
the use of the individual or entity to whom it is addressed and may contain 
information that is confidential, legally privileged, protected by privacy 
laws, or otherwise restricted from disclosure to anyone else. If you are 
not the intended recipient or the person responsible for delivering the 
e-mail to the intended recipient, you are hereby notified that any use, 
copying, distributing, dissemination, forwarding, printing, or copying of 
this e-mail is strictly prohibited. If you received this e-mail in error, 
please return the e-mail to the sender, delete it from your computer, and 
destroy any printed copy of it.

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4169 bytes --]

^ permalink raw reply related	[flat|nested] 75+ messages in thread

* [PATCH 08/24] mpi3mr: add support of event handling part-3
  2020-12-22 10:11 [PATCH 00/24] Introducing mpi3mr driver Kashyap Desai
                   ` (6 preceding siblings ...)
  2020-12-22 10:11 ` [PATCH 07/24] mpi3mr: add support of event handling pcie devices part-2 Kashyap Desai
@ 2020-12-22 10:11 ` Kashyap Desai
  2021-03-01  6:53   ` Hannes Reinecke
  2020-12-22 10:11 ` [PATCH 09/24] mpi3mr: add support for recovering controller Kashyap Desai
                   ` (16 subsequent siblings)
  24 siblings, 1 reply; 75+ messages in thread
From: Kashyap Desai @ 2020-12-22 10:11 UTC (permalink / raw)
  To: linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, Kashyap Desai, sathya.prakash

[-- Attachment #1: Type: text/plain, Size: 3908 bytes --]

Firmware can report various MPI Events.
Support for certain Events (as listed below) are enabled in the driver
and their processing in driver is covered in this patch.

MPI3_EVENT_SAS_BROADCAST_PRIMITIVE
MPI3_EVENT_CABLE_MGMT
MPI3_EVENT_ENERGY_PACK_CHANGE

Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Cc: sathya.prakash@broadcom.com
---
 drivers/scsi/mpi3mr/mpi3mr_fw.c |  3 +++
 drivers/scsi/mpi3mr/mpi3mr_os.c | 37 +++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)

diff --git a/drivers/scsi/mpi3mr/mpi3mr_fw.c b/drivers/scsi/mpi3mr/mpi3mr_fw.c
index c70c75fdac5c..de2de39c719e 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_fw.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_fw.c
@@ -2735,8 +2735,11 @@ int mpi3mr_init_ioc(struct mpi3mr_ioc *mrioc)
 	mpi3mr_unmask_events(mrioc, MPI3_EVENT_SAS_TOPOLOGY_CHANGE_LIST);
 	mpi3mr_unmask_events(mrioc, MPI3_EVENT_SAS_DISCOVERY);
 	mpi3mr_unmask_events(mrioc, MPI3_EVENT_SAS_DEVICE_DISCOVERY_ERROR);
+	mpi3mr_unmask_events(mrioc, MPI3_EVENT_SAS_BROADCAST_PRIMITIVE);
 	mpi3mr_unmask_events(mrioc, MPI3_EVENT_PCIE_TOPOLOGY_CHANGE_LIST);
 	mpi3mr_unmask_events(mrioc, MPI3_EVENT_PCIE_ENUMERATION);
+	mpi3mr_unmask_events(mrioc, MPI3_EVENT_CABLE_MGMT);
+	mpi3mr_unmask_events(mrioc, MPI3_EVENT_ENERGY_PACK_CHANGE);
 
 	retval = mpi3mr_issue_event_notification(mrioc);
 	if (retval) {
diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c
index 5be25fbe0e5b..9999d4c9be05 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_os.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_os.c
@@ -1500,6 +1500,36 @@ static void mpi3mr_devstatuschg_evt_th(struct mpi3mr_ioc *mrioc,
 
 }
 
+/**
+ * mpi3mr_energypackchg_evt_th - Energy pack change evt tophalf
+ * @mrioc: Adapter instance reference
+ * @event_reply: Event data
+ *
+ * Identifies the new shutdown timeout value and update.
+ *
+ * Return: Nothing
+ */
+static void mpi3mr_energypackchg_evt_th(struct mpi3mr_ioc *mrioc,
+	Mpi3EventNotificationReply_t *event_reply)
+{
+	Mpi3EventDataEnergyPackChange_t *evtdata =
+	    (Mpi3EventDataEnergyPackChange_t *)event_reply->EventData;
+	u16 shutdown_timeout = le16_to_cpu(evtdata->ShutdownTimeout);
+
+	if (shutdown_timeout <= 0) {
+		ioc_warn(mrioc,
+		    "%s :Invalid Shutdown Timeout received = %d\n",
+		    __func__, shutdown_timeout);
+		return;
+	}
+
+	ioc_info(mrioc,
+	    "%s :Previous Shutdown Timeout Value = %d New Shutdown Timeout Value = %d\n",
+	    __func__, mrioc->facts.shutdown_timeout, shutdown_timeout);
+	mrioc->facts.shutdown_timeout = shutdown_timeout;
+}
+
+
 /**
  * mpi3mr_os_handle_events - Firmware event handler
  * @mrioc: Adapter instance reference
@@ -1563,9 +1593,16 @@ void mpi3mr_os_handle_events(struct mpi3mr_ioc *mrioc,
 		process_evt_bh = 1;
 		break;
 	}
+	case MPI3_EVENT_ENERGY_PACK_CHANGE:
+	{
+		mpi3mr_energypackchg_evt_th(mrioc, event_reply);
+		break;
+	}
 	case MPI3_EVENT_ENCL_DEVICE_STATUS_CHANGE:
 	case MPI3_EVENT_SAS_DISCOVERY:
+	case MPI3_EVENT_CABLE_MGMT:
 	case MPI3_EVENT_SAS_DEVICE_DISCOVERY_ERROR:
+	case MPI3_EVENT_SAS_BROADCAST_PRIMITIVE:
 	case MPI3_EVENT_PCIE_ENUMERATION:
 		break;
 	default:
-- 
2.18.1


-- 
This electronic communication and the information and any files transmitted 
with it, or attached to it, are confidential and are intended solely for 
the use of the individual or entity to whom it is addressed and may contain 
information that is confidential, legally privileged, protected by privacy 
laws, or otherwise restricted from disclosure to anyone else. If you are 
not the intended recipient or the person responsible for delivering the 
e-mail to the intended recipient, you are hereby notified that any use, 
copying, distributing, dissemination, forwarding, printing, or copying of 
this e-mail is strictly prohibited. If you received this e-mail in error, 
please return the e-mail to the sender, delete it from your computer, and 
destroy any printed copy of it.

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4169 bytes --]

^ permalink raw reply related	[flat|nested] 75+ messages in thread

* [PATCH 09/24] mpi3mr: add support for recovering controller
  2020-12-22 10:11 [PATCH 00/24] Introducing mpi3mr driver Kashyap Desai
                   ` (7 preceding siblings ...)
  2020-12-22 10:11 ` [PATCH 08/24] mpi3mr: add support of event handling part-3 Kashyap Desai
@ 2020-12-22 10:11 ` Kashyap Desai
  2021-03-01  6:56   ` Hannes Reinecke
  2020-12-22 10:11 ` [PATCH 10/24] mpi3mr: add support of timestamp sync with firmware Kashyap Desai
                   ` (15 subsequent siblings)
  24 siblings, 1 reply; 75+ messages in thread
From: Kashyap Desai @ 2020-12-22 10:11 UTC (permalink / raw)
  To: linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, Kashyap Desai, sathya.prakash

[-- Attachment #1: Type: text/plain, Size: 24245 bytes --]

Added h/w defined process of doing controller reset.
The driver on detection of firmware fault or any kind of unresponsiveness in
the controller (Any admin command time outs) results in resetting the controller.
The primary reset mechanisms used are either soft reset or diag fault reset.
Reset is performed if the host sets the ResetAction field in the HostDiagnostic
register to a 001b (Soft Reset) or 007b(diag fault reset).
The driver after successfully resetting the controller reinitialize the
controller by going through start of the day controller initialization procedures.
The pending I/Os during the reset are returned back to SML for retry.

Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Cc: sathya.prakash@broadcom.com
---
 drivers/scsi/mpi3mr/mpi3mr.h    |  22 +-
 drivers/scsi/mpi3mr/mpi3mr_fw.c | 416 +++++++++++++++++++++++++++++---
 drivers/scsi/mpi3mr/mpi3mr_os.c |  93 ++++++-
 3 files changed, 488 insertions(+), 43 deletions(-)

diff --git a/drivers/scsi/mpi3mr/mpi3mr.h b/drivers/scsi/mpi3mr/mpi3mr.h
index 1f70a67d7868..f60749c94c9a 100644
--- a/drivers/scsi/mpi3mr/mpi3mr.h
+++ b/drivers/scsi/mpi3mr/mpi3mr.h
@@ -98,6 +98,7 @@ extern struct list_head mrioc_list;
 #define MPI3MR_INTADMCMD_TIMEOUT		10
 #define MPI3MR_PORTENABLE_TIMEOUT		300
 #define MPI3MR_RESETTM_TIMEOUT			30
+#define MPI3MR_RESET_HOST_IOWAIT_TIMEOUT	5
 #define MPI3MR_DEFAULT_SHUTDOWN_TIME		120
 
 #define MPI3MR_WATCHDOG_INTERVAL		1000 /* in milli seconds */
@@ -632,10 +633,14 @@ struct scmd_priv {
  * @dev_handle_bitmap_sz: Device handle bitmap size
  * @removepend_bitmap: Remove pending bitmap
  * @delayed_rmhs_list: Delayed device removal list
+ * @fault_dbg: Fault debug flag
  * @reset_in_progress: Reset in progress flag
  * @unrecoverable: Controller unrecoverable flag
+ * @reset_mutex: Controller reset mutex
+ * @reset_waitq: Controller reset  wait queue
  * @diagsave_timeout: Diagnostic information save timeout
  * @logging_level: Controller debug logging level
+ * @flush_io_count: I/O count to flush after reset
  * @current_event: Firmware event currently in process
  * @driver_info: Driver, Kernel, OS information to firmware
  * @change_count: Topology change count
@@ -750,11 +755,15 @@ struct mpi3mr_ioc {
 	void *removepend_bitmap;
 	struct list_head delayed_rmhs_list;
 
+	u8 fault_dbg;
 	u8 reset_in_progress;
 	u8 unrecoverable;
+	struct mutex reset_mutex;
+	wait_queue_head_t reset_waitq;
 
 	u16 diagsave_timeout;
 	int logging_level;
+	u16 flush_io_count;
 
 	struct mpi3mr_fwevt *current_event;
 	Mpi3DriverInfoLayout_t driver_info;
@@ -803,8 +812,8 @@ struct delayed_dev_rmhs_node {
 
 int mpi3mr_setup_resources(struct mpi3mr_ioc *mrioc);
 void mpi3mr_cleanup_resources(struct mpi3mr_ioc *mrioc);
-int mpi3mr_init_ioc(struct mpi3mr_ioc *mrioc);
-void mpi3mr_cleanup_ioc(struct mpi3mr_ioc *mrioc);
+int mpi3mr_init_ioc(struct mpi3mr_ioc *mrioc, u8 re_init);
+void mpi3mr_cleanup_ioc(struct mpi3mr_ioc *mrioc, u8 re_init);
 int mpi3mr_issue_port_enable(struct mpi3mr_ioc *mrioc, u8 async);
 int mpi3mr_admin_request_post(struct mpi3mr_ioc *mrioc, void *admin_req,
 u16 admin_req_sz, u8 ignore_reset);
@@ -830,6 +839,8 @@ void mpi3mr_stop_watchdog(struct mpi3mr_ioc *mrioc);
 
 int mpi3mr_soft_reset_handler(struct mpi3mr_ioc *mrioc,
 			      u32 reset_reason, u8 snapdump);
+int mpi3mr_diagfault_reset_handler(struct mpi3mr_ioc *mrioc,
+				   u32 reset_reason);
 void mpi3mr_ioc_disable_intr(struct mpi3mr_ioc *mrioc);
 void mpi3mr_ioc_enable_intr(struct mpi3mr_ioc *mrioc);
 
@@ -837,4 +848,11 @@ enum mpi3mr_iocstate mpi3mr_get_iocstate(struct mpi3mr_ioc *mrioc);
 int mpi3mr_send_event_ack(struct mpi3mr_ioc *mrioc, u8 event,
 			  u32 event_ctx);
 
+void mpi3mr_wait_for_host_io(struct mpi3mr_ioc *mrioc, u32 timeout);
+void mpi3mr_cleanup_fwevt_list(struct mpi3mr_ioc *mrioc);
+void mpi3mr_flush_host_io(struct mpi3mr_ioc *mrioc);
+void mpi3mr_invalidate_devhandles(struct mpi3mr_ioc *mrioc);
+void mpi3mr_rfresh_tgtdevs(struct mpi3mr_ioc *mrioc);
+void mpi3mr_flush_delayed_rmhs_list(struct mpi3mr_ioc *mrioc);
+
 #endif /*MPI3MR_H_INCLUDED*/
diff --git a/drivers/scsi/mpi3mr/mpi3mr_fw.c b/drivers/scsi/mpi3mr/mpi3mr_fw.c
index de2de39c719e..6129065c34b7 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_fw.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_fw.c
@@ -1604,6 +1604,40 @@ void mpi3mr_stop_watchdog(struct mpi3mr_ioc *mrioc)
 	}
 }
 
+/**
+ * mpi3mr_kill_ioc - Kill the controller
+ * @mrioc: Adapter instance reference
+ * @reason: reason for the failure.
+ *
+ * If fault debug is enabled, display the fault info else issue
+ * diag fault and freeze the system for controller debug
+ * purpose.
+ *
+ * Return: Nothing.
+ */
+static void mpi3mr_kill_ioc(struct mpi3mr_ioc *mrioc, u32 reason)
+{
+	enum mpi3mr_iocstate ioc_state;
+
+	if (!mrioc->fault_dbg)
+		return;
+
+	dump_stack();
+
+	ioc_state = mpi3mr_get_iocstate(mrioc);
+	if (ioc_state == MRIOC_STATE_FAULT)
+		mpi3mr_print_fault_info(mrioc);
+	else {
+		ioc_err(mrioc, "Firmware is halted due to the reason %d\n",
+		    reason);
+		mpi3mr_diagfault_reset_handler(mrioc, reason);
+	}
+	if (mrioc->fault_dbg == 2)
+		for (;;)
+			;
+	else
+		panic("panic in %s\n", __func__);
+}
 
 /**
  * mpi3mr_setup_admin_qpair - Setup admin queue pair
@@ -2347,6 +2381,7 @@ static int mpi3mr_alloc_chain_bufs(struct mpi3mr_ioc *mrioc)
 	return retval;
 }
 
+
 /**
  * mpi3mr_port_enable_complete - Mark port enable complete
  * @mrioc: Adapter instance reference
@@ -2557,6 +2592,7 @@ int mpi3mr_setup_resources(struct mpi3mr_ioc *mrioc)
 /**
  * mpi3mr_init_ioc - Initialize the controller
  * @mrioc: Adapter instance reference
+ * @re_init: Flag to indicate is this fresh init or re-init
  *
  * This the controller initialization routine, executed either
  * after soft reset or from pci probe callback.
@@ -2569,7 +2605,7 @@ int mpi3mr_setup_resources(struct mpi3mr_ioc *mrioc)
  *
  * Return: 0 on success and non-zero on failure.
  */
-int mpi3mr_init_ioc(struct mpi3mr_ioc *mrioc)
+int mpi3mr_init_ioc(struct mpi3mr_ioc *mrioc, u8 re_init)
 {
 	int retval = 0;
 	enum mpi3mr_iocstate ioc_state;
@@ -2579,12 +2615,14 @@ int mpi3mr_init_ioc(struct mpi3mr_ioc *mrioc)
 	Mpi3IOCFactsData_t facts_data;
 
 	mrioc->change_count = 0;
-	mrioc->cpu_count = num_online_cpus();
-	retval = mpi3mr_setup_resources(mrioc);
-	if (retval) {
-		ioc_err(mrioc, "Failed to setup resources:error %d\n",
-		    retval);
-		goto out_nocleanup;
+	if (!re_init) {
+		mrioc->cpu_count = num_online_cpus();
+		retval = mpi3mr_setup_resources(mrioc);
+		if (retval) {
+			ioc_err(mrioc, "Failed to setup resources:error %d\n",
+			    retval);
+			goto out_nocleanup;
+		}
 	}
 	ioc_status = readl(&mrioc->sysif_regs->IOCStatus);
 	ioc_config = readl(&mrioc->sysif_regs->IOCConfiguration);
@@ -2660,12 +2698,15 @@ int mpi3mr_init_ioc(struct mpi3mr_ioc *mrioc)
 		goto out_failed;
 	}
 
-	retval = mpi3mr_setup_isr(mrioc, 1);
-	if (retval) {
-		ioc_err(mrioc, "Failed to setup ISR error %d\n",
-		    retval);
-		goto out_failed;
-	}
+	if (!re_init) {
+		retval = mpi3mr_setup_isr(mrioc, 1);
+		if (retval) {
+			ioc_err(mrioc, "Failed to setup ISR error %d\n",
+			    retval);
+			goto out_failed;
+		}
+	} else
+		mpi3mr_ioc_enable_intr(mrioc);
 
 	retval = mpi3mr_issue_iocfacts(mrioc, &facts_data);
 	if (retval) {
@@ -2675,11 +2716,14 @@ int mpi3mr_init_ioc(struct mpi3mr_ioc *mrioc)
 	}
 
 	mpi3mr_process_factsdata(mrioc, &facts_data);
-	retval = mpi3mr_check_reset_dma_mask(mrioc);
-	if (retval) {
-		ioc_err(mrioc, "Resetting dma mask failed %d\n",
-		    retval);
-		goto out_failed;
+	if (!re_init) {
+		retval = mpi3mr_check_reset_dma_mask(mrioc);
+		if (retval) {
+			ioc_err(mrioc, "Resetting dma mask failed %d\n",
+			    retval);
+			goto out_failed;
+		}
+
 	}
 
 	retval = mpi3mr_alloc_reply_sense_bufs(mrioc);
@@ -2690,13 +2734,15 @@ int mpi3mr_init_ioc(struct mpi3mr_ioc *mrioc)
 		goto out_failed;
 	}
 
-	retval = mpi3mr_alloc_chain_bufs(mrioc);
-	if (retval) {
-		ioc_err(mrioc, "Failed to allocated chain buffers %d\n",
-		    retval);
-		goto out_failed;
-	}
+	if (!re_init) {
+		retval = mpi3mr_alloc_chain_bufs(mrioc);
+		if (retval) {
+			ioc_err(mrioc, "Failed to allocated chain buffers %d\n",
+			    retval);
+			goto out_failed;
+		}
 
+	}
 	retval = mpi3mr_issue_iocinit(mrioc);
 	if (retval) {
 		ioc_err(mrioc, "Failed to Issue IOC Init %d\n",
@@ -2711,11 +2757,13 @@ int mpi3mr_init_ioc(struct mpi3mr_ioc *mrioc)
 	writel(mrioc->sbq_host_index,
 	    &mrioc->sysif_regs->SenseBufferFreeHostIndex);
 
-	retval = mpi3mr_setup_isr(mrioc, 0);
-	if (retval) {
-		ioc_err(mrioc, "Failed to re-setup ISR, error %d\n",
-		    retval);
-		goto out_failed;
+	if (!re_init)  {
+		retval = mpi3mr_setup_isr(mrioc, 0);
+		if (retval) {
+			ioc_err(mrioc, "Failed to re-setup ISR, error %d\n",
+			    retval);
+			goto out_failed;
+		}
 	}
 
 	retval = mpi3mr_create_op_queues(mrioc);
@@ -2725,6 +2773,14 @@ int mpi3mr_init_ioc(struct mpi3mr_ioc *mrioc)
 		goto out_failed;
 	}
 
+	if (re_init &&
+	    (mrioc->shost->nr_hw_queues > mrioc->num_op_reply_q)) {
+		ioc_err(mrioc,
+		    "Cannot create minimum number of OpQueues expected:%d created:%d\n",
+		    mrioc->shost->nr_hw_queues, mrioc->num_op_reply_q);
+		goto out_failed;
+	}
+
 	for (i = 0; i < MPI3_EVENT_NOTIFY_EVENTMASK_WORDS; i++)
 		mrioc->event_masks[i] = -1;
 
@@ -2748,14 +2804,109 @@ int mpi3mr_init_ioc(struct mpi3mr_ioc *mrioc)
 		goto out_failed;
 	}
 
+	if (re_init) {
+		ioc_info(mrioc, "Issuing Port Enable\n");
+		retval = mpi3mr_issue_port_enable(mrioc, 0);
+		if (retval) {
+			ioc_err(mrioc, "Failed to issue port enable %d\n",
+			    retval);
+			goto out_failed;
+		}
+	}
 	return retval;
 
 out_failed:
-	mpi3mr_cleanup_ioc(mrioc);
+	mpi3mr_cleanup_ioc(mrioc, re_init);
 out_nocleanup:
 	return retval;
 }
 
+/**
+ * mpi3mr_memset_op_reply_q_buffers - memset the operational reply queue's
+ *					segments
+ * @mrioc: Adapter instance reference
+ * @qidx: Operational reply queue index
+ *
+ * Return: Nothing.
+ */
+static void mpi3mr_memset_op_reply_q_buffers(struct mpi3mr_ioc *mrioc, u16 qidx)
+{
+	struct op_reply_qinfo *op_reply_q = mrioc->op_reply_qinfo + qidx;
+	struct segments *segments;
+	int i, size;
+
+	if (!op_reply_q->q_segments)
+		return;
+
+	size = op_reply_q->segment_qd * mrioc->op_reply_desc_sz;
+	segments = op_reply_q->q_segments;
+	for (i = 0; i < op_reply_q->num_segments; i++)
+		memset(segments[i].segment, 0, size);
+}
+
+/**
+ * mpi3mr_memset_op_req_q_buffers - memset the operational request queue's
+ *					segments
+ * @mrioc: Adapter instance reference
+ * @qidx: Operational request queue index
+ *
+ * Return: Nothing.
+ */
+static void mpi3mr_memset_op_req_q_buffers(struct mpi3mr_ioc *mrioc, u16 qidx)
+{
+	struct op_req_qinfo *op_req_q = mrioc->req_qinfo + qidx;
+	struct segments *segments;
+	int i, size;
+
+	if (!op_req_q->q_segments)
+		return;
+
+	size = op_req_q->segment_qd * mrioc->facts.op_req_sz;
+	segments = op_req_q->q_segments;
+	for (i = 0; i < op_req_q->num_segments; i++)
+		memset(segments[i].segment, 0, size);
+}
+
+/**
+ * mpi3mr_memset_buffers - memset memory for a controller
+ * @mrioc: Adapter instance reference
+ *
+ * clear all the memory allocated for a controller, typically
+ * called post reset to reuse the memory allocated during the
+ * controller init.
+ *
+ * Return: Nothing.
+ */
+static void mpi3mr_memset_buffers(struct mpi3mr_ioc *mrioc)
+{
+	u16 i;
+
+	memset(mrioc->admin_req_base, 0, mrioc->admin_req_q_sz);
+	memset(mrioc->admin_reply_base, 0, mrioc->admin_reply_q_sz);
+
+	memset(mrioc->init_cmds.reply, 0, sizeof(*mrioc->init_cmds.reply));
+	for (i = 0; i < MPI3MR_NUM_DEVRMCMD; i++)
+		memset(mrioc->dev_rmhs_cmds[i].reply, 0,
+		    sizeof(*mrioc->dev_rmhs_cmds[i].reply));
+	memset(mrioc->removepend_bitmap, 0, mrioc->dev_handle_bitmap_sz);
+	memset(mrioc->devrem_bitmap, 0, mrioc->devrem_bitmap_sz);
+
+	for (i = 0; i < mrioc->num_queues; i++) {
+		mrioc->op_reply_qinfo[i].qid = 0;
+		mrioc->op_reply_qinfo[i].ci = 0;
+		mrioc->op_reply_qinfo[i].num_replies = 0;
+		mrioc->op_reply_qinfo[i].ephase = 0;
+		mpi3mr_memset_op_reply_q_buffers(mrioc, i);
+
+		mrioc->req_qinfo[i].ci = 0;
+		mrioc->req_qinfo[i].pi = 0;
+		mrioc->req_qinfo[i].num_requests = 0;
+		mrioc->req_qinfo[i].qid = 0;
+		mrioc->req_qinfo[i].reply_qid = 0;
+		spin_lock_init(&mrioc->req_qinfo[i].q_lock);
+		mpi3mr_memset_op_req_q_buffers(mrioc, i);
+	}
+}
 
 /**
  * mpi3mr_free_mem - Free memory allocated for a controller
@@ -2926,6 +3077,7 @@ static void mpi3mr_issue_ioc_shutdown(struct mpi3mr_ioc *mrioc)
 /**
  * mpi3mr_cleanup_ioc - Cleanup controller
  * @mrioc: Adapter instance reference
+ * @re_init: Cleanup due to a reinit or not
  *
  * Controller cleanup handler, Message unit reset or soft reset
  * and shutdown notification is issued to the controller and the
@@ -2933,11 +3085,12 @@ static void mpi3mr_issue_ioc_shutdown(struct mpi3mr_ioc *mrioc)
  *
  * Return: Nothing.
  */
-void mpi3mr_cleanup_ioc(struct mpi3mr_ioc *mrioc)
+void mpi3mr_cleanup_ioc(struct mpi3mr_ioc *mrioc, u8 re_init)
 {
 	enum mpi3mr_iocstate ioc_state;
 
-	mpi3mr_stop_watchdog(mrioc);
+	if (!re_init)
+		mpi3mr_stop_watchdog(mrioc);
 
 	mpi3mr_ioc_disable_intr(mrioc);
 
@@ -2951,13 +3104,94 @@ void mpi3mr_cleanup_ioc(struct mpi3mr_ioc *mrioc)
 			    MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET,
 			    MPI3MR_RESET_FROM_MUR_FAILURE);
 
-		 mpi3mr_issue_ioc_shutdown(mrioc);
+		if (!re_init)
+			mpi3mr_issue_ioc_shutdown(mrioc);
 	}
 
-	mpi3mr_free_mem(mrioc);
-	mpi3mr_cleanup_resources(mrioc);
+	if (!re_init) {
+		mpi3mr_free_mem(mrioc);
+		mpi3mr_cleanup_resources(mrioc);
+	}
+}
+
+/**
+ * mpi3mr_drv_cmd_comp_reset - Flush a internal driver command
+ * @mrioc: Adapter instance reference
+ * @cmdptr: Internal command tracker
+ *
+ * Complete an internal driver commands with state indicating it
+ * is completed due to reset.
+ *
+ * Return: Nothing.
+ */
+static inline void mpi3mr_drv_cmd_comp_reset(struct mpi3mr_ioc *mrioc,
+	struct mpi3mr_drv_cmd *cmdptr)
+{
+	if (cmdptr->state & MPI3MR_CMD_PENDING) {
+		cmdptr->state |= MPI3MR_CMD_RESET;
+		cmdptr->state &= ~MPI3MR_CMD_PENDING;
+		if (cmdptr->is_waiting) {
+			complete(&cmdptr->done);
+			cmdptr->is_waiting = 0;
+		} else if (cmdptr->callback)
+			cmdptr->callback(mrioc, cmdptr);
+	}
 }
 
+/**
+ * mpi3mr_flush_drv_cmds - Flush internaldriver commands
+ * @mrioc: Adapter instance reference
+ *
+ * Flush all internal driver commands post reset
+ *
+ * Return: Nothing.
+ */
+static void mpi3mr_flush_drv_cmds(struct mpi3mr_ioc *mrioc)
+{
+	struct mpi3mr_drv_cmd *cmdptr;
+	u8 i;
+
+	cmdptr = &mrioc->init_cmds;
+	mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
+
+	for (i = 0; i < MPI3MR_NUM_DEVRMCMD; i++) {
+		cmdptr = &mrioc->dev_rmhs_cmds[i];
+		mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
+	}
+}
+
+/**
+ * mpi3mr_diagfault_reset_handler - Diag fault reset handler
+ * @mrioc: Adapter instance reference
+ * @reset_reason: Reset reason code
+ *
+ * This is an handler for issuing diag fault reset from the
+ * applications through IOCTL path to stop the execution of the
+ * controller
+ *
+ * Return: 0 on success, non-zero on failure.
+ */
+int mpi3mr_diagfault_reset_handler(struct mpi3mr_ioc *mrioc,
+	u32 reset_reason)
+{
+	int retval = 0;
+
+	mrioc->reset_in_progress = 1;
+
+	mpi3mr_ioc_disable_intr(mrioc);
+
+	retval = mpi3mr_issue_reset(mrioc,
+	    MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT, reset_reason);
+
+	if (retval) {
+		ioc_err(mrioc, "The diag fault reset failed: reason %d\n",
+		    reset_reason);
+		mpi3mr_ioc_enable_intr(mrioc);
+	}
+	ioc_info(mrioc, "%s\n", ((retval == 0) ? "SUCCESS" : "FAILED"));
+	mrioc->reset_in_progress = 0;
+	return retval;
+}
 
 /**
  * mpi3mr_soft_reset_handler - Reset the controller
@@ -2965,12 +3199,120 @@ void mpi3mr_cleanup_ioc(struct mpi3mr_ioc *mrioc)
  * @reset_reason: Reset reason code
  * @snapdump: Flag to generate snapdump in firmware or not
  *
- * TBD
+ * This is an handler for recovering controller by issuing soft
+ * reset are diag fault reset.  This is a blocking function and
+ * when one reset is executed if any other resets they will be
+ * blocked. All IOCTLs/IO will be blocked during the reset. If
+ * controller reset is successful then the controller will be
+ * reinitalized, otherwise the controller will be marked as not
+ * recoverable
+ *
+ * In snapdump bit is set, the controller is issued with diag
+ * fault reset so that the firmware can create a snap dump and
+ * post that the firmware will result in F000 fault and the
+ * driver will issue soft reset to recover from that.
  *
  * Return: 0 on success, non-zero on failure.
  */
 int mpi3mr_soft_reset_handler(struct mpi3mr_ioc *mrioc,
 	u32 reset_reason, u8 snapdump)
 {
-	return 0;
+	int retval = 0, i;
+	unsigned long flags;
+	u32 host_diagnostic, timeout = MPI3_SYSIF_DIAG_SAVE_TIMEOUT * 10;
+
+	if (mrioc->fault_dbg) {
+		if (snapdump)
+			mpi3mr_set_diagsave(mrioc);
+		mpi3mr_kill_ioc(mrioc, reset_reason);
+	}
+
+	/*
+	 * Block new resets until the currently executing one is finished and
+	 * return the status of the existing reset for all blocked resets
+	 */
+	if (!mutex_trylock(&mrioc->reset_mutex)) {
+		ioc_info(mrioc, "Another reset in progress\n");
+		return -1;
+	}
+	mrioc->reset_in_progress = 1;
+
+	if ((!snapdump) && (reset_reason != MPI3MR_RESET_FROM_FAULT_WATCH) &&
+	    (reset_reason != MPI3MR_RESET_FROM_CIACTIV_FAULT)) {
+
+		for (i = 0; i < MPI3_EVENT_NOTIFY_EVENTMASK_WORDS; i++)
+			mrioc->event_masks[i] = -1;
+
+		retval = mpi3mr_issue_event_notification(mrioc);
+
+		if (retval) {
+			ioc_err(mrioc,
+			    "Failed to turn off events prior to reset %d\n",
+			    retval);
+		}
+	}
+
+	mpi3mr_ioc_disable_intr(mrioc);
+
+	if (snapdump) {
+		mpi3mr_set_diagsave(mrioc);
+		retval = mpi3mr_issue_reset(mrioc,
+		    MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT, reset_reason);
+		if (!retval) {
+			do {
+				host_diagnostic =
+				    readl(&mrioc->sysif_regs->HostDiagnostic);
+				if (!(host_diagnostic &
+				    MPI3_SYSIF_HOST_DIAG_SAVE_IN_PROGRESS))
+					break;
+				msleep(100);
+			} while (--timeout);
+		}
+	}
+
+	retval = mpi3mr_issue_reset(mrioc,
+	    MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET, reset_reason);
+	if (retval) {
+		ioc_err(mrioc, "Failed to issue soft reset to the ioc\n");
+		goto out;
+	}
+
+	mpi3mr_flush_delayed_rmhs_list(mrioc);
+	mpi3mr_flush_drv_cmds(mrioc);
+	memset(mrioc->devrem_bitmap, 0, mrioc->devrem_bitmap_sz);
+	memset(mrioc->removepend_bitmap, 0, mrioc->dev_handle_bitmap_sz);
+	mpi3mr_cleanup_fwevt_list(mrioc);
+	mpi3mr_flush_host_io(mrioc);
+	mpi3mr_invalidate_devhandles(mrioc);
+	mpi3mr_memset_buffers(mrioc);
+	retval = mpi3mr_init_ioc(mrioc, 1);
+	if (retval) {
+		pr_err(IOCNAME "reinit after soft reset failed: reason %d\n",
+		    mrioc->name, reset_reason);
+		goto out;
+	}
+	ssleep(10);
+
+out:
+	if (!retval) {
+		mrioc->reset_in_progress = 0;
+		scsi_unblock_requests(mrioc->shost);
+		mpi3mr_rfresh_tgtdevs(mrioc);
+		spin_lock_irqsave(&mrioc->watchdog_lock, flags);
+		if (mrioc->watchdog_work_q)
+			queue_delayed_work(mrioc->watchdog_work_q,
+			    &mrioc->watchdog_work,
+			    msecs_to_jiffies(MPI3MR_WATCHDOG_INTERVAL));
+		spin_unlock_irqrestore(&mrioc->watchdog_lock, flags);
+	} else {
+		mpi3mr_issue_reset(mrioc,
+		    MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT, reset_reason);
+		mrioc->unrecoverable = 1;
+		mrioc->reset_in_progress = 0;
+		retval = -1;
+	}
+
+	mutex_unlock(&mrioc->reset_mutex);
+	ioc_info(mrioc, "%s\n", ((retval == 0) ? "SUCCESS" : "FAILED"));
+	return retval;
 }
diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c
index 9999d4c9be05..4d94352a4d48 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_os.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_os.c
@@ -311,6 +311,88 @@ void mpi3mr_cleanup_fwevt_list(struct mpi3mr_ioc *mrioc)
 	}
 }
 
+/**
+ * mpi3mr_invalidate_devhandles -Invalidate device handles
+ * @mrioc: Adapter instance reference
+ *
+ * Invalidate the device handles in the target device structures
+ * . Called post reset prior to reinitializing the controller.
+ *
+ * Return: Nothing.
+ */
+void mpi3mr_invalidate_devhandles(struct mpi3mr_ioc *mrioc)
+{
+	struct mpi3mr_tgt_dev *tgtdev;
+	struct mpi3mr_stgt_priv_data *tgt_priv;
+
+	list_for_each_entry(tgtdev, &mrioc->tgtdev_list, list) {
+		tgtdev->dev_handle = MPI3MR_INVALID_DEV_HANDLE;
+		if (tgtdev->starget && tgtdev->starget->hostdata) {
+			tgt_priv = tgtdev->starget->hostdata;
+			tgt_priv->dev_handle = MPI3MR_INVALID_DEV_HANDLE;
+		}
+	}
+}
+
+
+/**
+ * mpi3mr_flush_scmd - Flush individual SCSI command
+ * @rq: Block request
+ * @data: Adapter instance reference
+ *
+ * Return the SCSI command to the upper layers if it is in LLD
+ * scope.
+ *
+ * Return: true always.
+ */
+
+static bool mpi3mr_flush_scmd(struct request *rq,
+	void *data, bool reserved)
+{
+	struct mpi3mr_ioc *mrioc = (struct mpi3mr_ioc *)data;
+	struct scsi_cmnd *scmd = blk_mq_rq_to_pdu(rq);
+	struct scmd_priv *priv = NULL;
+
+	if (scmd) {
+		priv = scsi_cmd_priv(scmd);
+		if (!priv->in_lld_scope)
+			goto out;
+
+		mpi3mr_clear_scmd_priv(mrioc, scmd);
+		scsi_dma_unmap(scmd);
+		scmd->result = DID_RESET << 16;
+		scsi_print_command(scmd);
+		scmd->scsi_done(scmd);
+		mrioc->flush_io_count++;
+	}
+
+out:
+	return(true);
+}
+
+
+/**
+ * mpi3mr_flush_host_io -  Flush host I/Os
+ * @mrioc: Adapter instance reference
+ *
+ * Flush all of the pending I/Os by calling
+ * blk_mq_tagset_busy_iter() for each possible tag. This is
+ * executed post controller reset
+ *
+ * Return: Nothing.
+ */
+void mpi3mr_flush_host_io(struct mpi3mr_ioc *mrioc)
+{
+	struct Scsi_Host *shost = mrioc->shost;
+
+	mrioc->flush_io_count = 0;
+	ioc_info(mrioc, "%s :Flushing Host I/O cmds post reset\n", __func__);
+	blk_mq_tagset_busy_iter(&shost->tag_set,
+	    mpi3mr_flush_scmd, (void *)mrioc);
+	ioc_info(mrioc, "%s :Flushed %d Host I/O cmds\n", __func__,
+	    mrioc->flush_io_count);
+}
+
 /**
  * mpi3mr_alloc_tgtdev - target device allocator
  *
@@ -2513,11 +2595,14 @@ mpi3mr_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	INIT_LIST_HEAD(&mrioc->tgtdev_list);
 	INIT_LIST_HEAD(&mrioc->delayed_rmhs_list);
 
+	mutex_init(&mrioc->reset_mutex);
 	mpi3mr_init_drv_cmd(&mrioc->init_cmds, MPI3MR_HOSTTAG_INITCMDS);
 
 	if (pdev->revision)
 		mrioc->enable_segqueue = true;
 
+	init_waitqueue_head(&mrioc->reset_waitq);
+
 	mrioc->logging_level = logging_level;
 	mrioc->shost = shost;
 	mrioc->pdev = pdev;
@@ -2542,7 +2627,7 @@ mpi3mr_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	}
 
 	mrioc->is_driver_loading = 1;
-	if (mpi3mr_init_ioc(mrioc)) {
+	if (mpi3mr_init_ioc(mrioc, 0)) {
 		ioc_err(mrioc, "failure at %s:%d/%s()!\n",
 		    __FILE__, __LINE__, __func__);
 		retval = -ENODEV;
@@ -2565,7 +2650,7 @@ mpi3mr_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	return retval;
 
 addhost_failed:
-	mpi3mr_cleanup_ioc(mrioc);
+	mpi3mr_cleanup_ioc(mrioc, 0);
 out_iocinit_failed:
 	destroy_workqueue(mrioc->fwevt_worker_thread);
 out_fwevtthread_failed:
@@ -2615,7 +2700,7 @@ static void mpi3mr_remove(struct pci_dev *pdev)
 		mpi3mr_tgtdev_put(tgtdev);
 	}
 
-	mpi3mr_cleanup_ioc(mrioc);
+	mpi3mr_cleanup_ioc(mrioc, 0);
 
 	spin_lock(&mrioc_list_lock);
 	list_del(&mrioc->list);
@@ -2655,7 +2740,7 @@ static void mpi3mr_shutdown(struct pci_dev *pdev)
 	if (wq)
 		destroy_workqueue(wq);
 
-	mpi3mr_cleanup_ioc(mrioc);
+	mpi3mr_cleanup_ioc(mrioc, 0);
 
 }
 
-- 
2.18.1


-- 
This electronic communication and the information and any files transmitted 
with it, or attached to it, are confidential and are intended solely for 
the use of the individual or entity to whom it is addressed and may contain 
information that is confidential, legally privileged, protected by privacy 
laws, or otherwise restricted from disclosure to anyone else. If you are 
not the intended recipient or the person responsible for delivering the 
e-mail to the intended recipient, you are hereby notified that any use, 
copying, distributing, dissemination, forwarding, printing, or copying of 
this e-mail is strictly prohibited. If you received this e-mail in error, 
please return the e-mail to the sender, delete it from your computer, and 
destroy any printed copy of it.

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4169 bytes --]

^ permalink raw reply related	[flat|nested] 75+ messages in thread

* [PATCH 10/24] mpi3mr: add support of timestamp sync with firmware
  2020-12-22 10:11 [PATCH 00/24] Introducing mpi3mr driver Kashyap Desai
                   ` (8 preceding siblings ...)
  2020-12-22 10:11 ` [PATCH 09/24] mpi3mr: add support for recovering controller Kashyap Desai
@ 2020-12-22 10:11 ` Kashyap Desai
  2021-03-01  6:57   ` Hannes Reinecke
  2020-12-22 10:11 ` [PATCH 11/24] mpi3mr: print ioc info for debugging Kashyap Desai
                   ` (14 subsequent siblings)
  24 siblings, 1 reply; 75+ messages in thread
From: Kashyap Desai @ 2020-12-22 10:11 UTC (permalink / raw)
  To: linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, Kashyap Desai, sathya.prakash

[-- Attachment #1: Type: text/plain, Size: 5750 bytes --]

This operation requests that the IOC update the TimeStamp.

When the I/O Unit is powered on, it sets the TimeStamp field value to
0x0000_0000_0000_0000 and increments the current value every millisecond.
A host driver sets the TimeStamp field to the current time by using an
IOCInit request. The TimeStamp field is periodically updated by host driver.

Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Cc: sathya.prakash@broadcom.com
---
 drivers/scsi/mpi3mr/mpi3mr.h    |  3 ++
 drivers/scsi/mpi3mr/mpi3mr_fw.c | 74 +++++++++++++++++++++++++++++++++
 2 files changed, 77 insertions(+)

diff --git a/drivers/scsi/mpi3mr/mpi3mr.h b/drivers/scsi/mpi3mr/mpi3mr.h
index f60749c94c9a..24e2337466dc 100644
--- a/drivers/scsi/mpi3mr/mpi3mr.h
+++ b/drivers/scsi/mpi3mr/mpi3mr.h
@@ -99,6 +99,7 @@ extern struct list_head mrioc_list;
 #define MPI3MR_PORTENABLE_TIMEOUT		300
 #define MPI3MR_RESETTM_TIMEOUT			30
 #define MPI3MR_RESET_HOST_IOWAIT_TIMEOUT	5
+#define MPI3MR_TSUPDATE_INTERVAL		900
 #define MPI3MR_DEFAULT_SHUTDOWN_TIME		120
 
 #define MPI3MR_WATCHDOG_INTERVAL		1000 /* in milli seconds */
@@ -633,6 +634,7 @@ struct scmd_priv {
  * @dev_handle_bitmap_sz: Device handle bitmap size
  * @removepend_bitmap: Remove pending bitmap
  * @delayed_rmhs_list: Delayed device removal list
+ * @ts_update_counter: Timestamp update counter
  * @fault_dbg: Fault debug flag
  * @reset_in_progress: Reset in progress flag
  * @unrecoverable: Controller unrecoverable flag
@@ -755,6 +757,7 @@ struct mpi3mr_ioc {
 	void *removepend_bitmap;
 	struct list_head delayed_rmhs_list;
 
+	u32 ts_update_counter;
 	u8 fault_dbg;
 	u8 reset_in_progress;
 	u8 unrecoverable;
diff --git a/drivers/scsi/mpi3mr/mpi3mr_fw.c b/drivers/scsi/mpi3mr/mpi3mr_fw.c
index 6129065c34b7..10ff287e78db 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_fw.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_fw.c
@@ -1481,6 +1481,74 @@ int mpi3mr_op_request_post(struct mpi3mr_ioc *mrioc,
 	return retval;
 }
 
+/**
+ * mpi3mr_sync_timestamp - Issue time stamp sync request
+ * @mrioc: Adapter reference
+ *
+ * Issue IO unit control MPI request to synchornize firmware
+ * timestamp with host time.
+ *
+ * Return: 0 on success, non-zero on failure.
+ */
+static int mpi3mr_sync_timestamp(struct mpi3mr_ioc *mrioc)
+{
+	ktime_t current_time;
+	Mpi3IoUnitControlRequest_t iou_ctrl;
+	int retval = 0;
+
+	memset(&iou_ctrl, 0, sizeof(iou_ctrl));
+	mutex_lock(&mrioc->init_cmds.mutex);
+	if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
+		retval = -1;
+		ioc_err(mrioc, "Issue IOUCTL TimeStamp: command is in use\n");
+		mutex_unlock(&mrioc->init_cmds.mutex);
+		goto out;
+	}
+	mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
+	mrioc->init_cmds.is_waiting = 1;
+	mrioc->init_cmds.callback = NULL;
+	iou_ctrl.HostTag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
+	iou_ctrl.Function = MPI3_FUNCTION_IO_UNIT_CONTROL;
+	iou_ctrl.Operation = MPI3_CTRL_OP_UPDATE_TIMESTAMP;
+	current_time = ktime_get_real();
+	iou_ctrl.Param64[0] = cpu_to_le64(ktime_to_ms(current_time));
+
+	init_completion(&mrioc->init_cmds.done);
+	retval = mpi3mr_admin_request_post(mrioc, &iou_ctrl,
+	    sizeof(iou_ctrl), 0);
+	if (retval) {
+		ioc_err(mrioc, "Issue IOUCTL TimeStamp: Admin Post failed\n");
+		goto out_unlock;
+	}
+
+	wait_for_completion_timeout(&mrioc->init_cmds.done,
+	    (MPI3MR_INTADMCMD_TIMEOUT * HZ));
+	if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
+		ioc_err(mrioc, "Issue IOUCTL TimeStamp: command timed out\n");
+		mrioc->init_cmds.is_waiting = 0;
+		mpi3mr_soft_reset_handler(mrioc,
+		    MPI3MR_RESET_FROM_TSU_TIMEOUT, 1);
+		retval = -1;
+		goto out_unlock;
+	}
+	if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
+	    != MPI3_IOCSTATUS_SUCCESS) {
+		ioc_err(mrioc,
+		    "Issue IOUCTL TimeStamp: Failed IOCStatus(0x%04x) Loginfo(0x%08x)\n",
+		    (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
+		    mrioc->init_cmds.ioc_loginfo);
+		retval = -1;
+		goto out_unlock;
+	}
+
+out_unlock:
+	mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
+	mutex_unlock(&mrioc->init_cmds.mutex);
+
+out:
+	return retval;
+}
+
 /**
  * mpi3mr_watchdog_work - watchdog thread to monitor faults
  * @work: work struct
@@ -1499,6 +1567,11 @@ static void mpi3mr_watchdog_work(struct work_struct *work)
 	enum mpi3mr_iocstate ioc_state;
 	u32 fault, host_diagnostic;
 
+	if (mrioc->ts_update_counter++ >= MPI3MR_TSUPDATE_INTERVAL) {
+		mrioc->ts_update_counter = 0;
+		mpi3mr_sync_timestamp(mrioc);
+	}
+
 	/*Check for fault state every one second and issue Soft reset*/
 	ioc_state = mpi3mr_get_iocstate(mrioc);
 	if (ioc_state == MRIOC_STATE_FAULT) {
@@ -3298,6 +3371,7 @@ int mpi3mr_soft_reset_handler(struct mpi3mr_ioc *mrioc,
 		mrioc->reset_in_progress = 0;
 		scsi_unblock_requests(mrioc->shost);
 		mpi3mr_rfresh_tgtdevs(mrioc);
+		mrioc->ts_update_counter = 0;
 		spin_lock_irqsave(&mrioc->watchdog_lock, flags);
 		if (mrioc->watchdog_work_q)
 			queue_delayed_work(mrioc->watchdog_work_q,
-- 
2.18.1


-- 
This electronic communication and the information and any files transmitted 
with it, or attached to it, are confidential and are intended solely for 
the use of the individual or entity to whom it is addressed and may contain 
information that is confidential, legally privileged, protected by privacy 
laws, or otherwise restricted from disclosure to anyone else. If you are 
not the intended recipient or the person responsible for delivering the 
e-mail to the intended recipient, you are hereby notified that any use, 
copying, distributing, dissemination, forwarding, printing, or copying of 
this e-mail is strictly prohibited. If you received this e-mail in error, 
please return the e-mail to the sender, delete it from your computer, and 
destroy any printed copy of it.

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4169 bytes --]

^ permalink raw reply related	[flat|nested] 75+ messages in thread

* [PATCH 11/24] mpi3mr: print ioc info for debugging
  2020-12-22 10:11 [PATCH 00/24] Introducing mpi3mr driver Kashyap Desai
                   ` (9 preceding siblings ...)
  2020-12-22 10:11 ` [PATCH 10/24] mpi3mr: add support of timestamp sync with firmware Kashyap Desai
@ 2020-12-22 10:11 ` Kashyap Desai
  2021-03-01  6:59   ` Hannes Reinecke
  2020-12-22 10:11 ` [PATCH 12/24] mpi3mr: add bios_param shost template hook Kashyap Desai
                   ` (13 subsequent siblings)
  24 siblings, 1 reply; 75+ messages in thread
From: Kashyap Desai @ 2020-12-22 10:11 UTC (permalink / raw)
  To: linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, Kashyap Desai, sathya.prakash

[-- Attachment #1: Type: text/plain, Size: 3039 bytes --]

Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Cc: sathya.prakash@broadcom.com
---
 drivers/scsi/mpi3mr/mpi3mr_fw.c | 63 +++++++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)

diff --git a/drivers/scsi/mpi3mr/mpi3mr_fw.c b/drivers/scsi/mpi3mr/mpi3mr_fw.c
index 10ff287e78db..aad0a2bd06b9 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_fw.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_fw.c
@@ -2540,6 +2540,68 @@ int mpi3mr_issue_port_enable(struct mpi3mr_ioc *mrioc, u8 async)
 	return retval;
 }
 
+/**
+ * mpi3mr_print_ioc_info - Display controller information
+ * @mrioc: Adapter instance reference
+ *
+ * Display controller personalit, capability, supported
+ * protocols etc.
+ *
+ * Return: Nothing
+ */
+static void
+mpi3mr_print_ioc_info(struct mpi3mr_ioc *mrioc)
+{
+	int i = 0;
+	char personality[16];
+	struct mpi3mr_compimg_ver *fwver = &mrioc->facts.fw_ver;
+
+	switch (mrioc->facts.personality) {
+	case MPI3_IOCFACTS_FLAGS_PERSONALITY_EHBA:
+		strcpy(personality, "Enhanced HBA");
+		break;
+	case MPI3_IOCFACTS_FLAGS_PERSONALITY_RAID_DDR:
+		strcpy(personality, "RAID");
+		break;
+	default:
+		strcpy(personality, "Unknown");
+		break;
+	}
+
+	ioc_info(mrioc, "Running in %s Personality", personality);
+
+	ioc_info(mrioc, "FW Version(%d.%d.%d.%d.%d.%d)\n",
+	fwver->gen_major, fwver->gen_minor, fwver->ph_major,
+	    fwver->ph_minor, fwver->cust_id, fwver->build_num);
+
+	ioc_info(mrioc, "Protocol=(");
+
+	if (mrioc->facts.protocol_flags &
+	    MPI3_IOCFACTS_PROTOCOL_SCSI_INITIATOR) {
+		pr_cont("Initiator");
+		i++;
+	}
+
+	if (mrioc->facts.protocol_flags &
+	    MPI3_IOCFACTS_PROTOCOL_SCSI_TARGET) {
+		pr_cont("%sTarget", i ? "," : "");
+		i++;
+	}
+
+	if (mrioc->facts.protocol_flags &
+	    MPI3_IOCFACTS_PROTOCOL_NVME) {
+		pr_cont("%sNVMe attachment", i ? "," : "");
+		i++;
+	}
+	pr_cont("), ");
+	pr_cont("Capabilities=(");
+
+	if (mrioc->facts.ioc_capabilities &
+	    MPI3_IOCFACTS_CAPABILITY_RAID_CAPABLE)
+		pr_cont("RAID");
+
+	pr_cont(")\n");
+}
 
 /**
  * mpi3mr_cleanup_resources - Free PCI resources
@@ -2798,6 +2860,7 @@ int mpi3mr_init_ioc(struct mpi3mr_ioc *mrioc, u8 re_init)
 		}
 
 	}
+	mpi3mr_print_ioc_info(mrioc);
 
 	retval = mpi3mr_alloc_reply_sense_bufs(mrioc);
 	if (retval) {
-- 
2.18.1


-- 
This electronic communication and the information and any files transmitted 
with it, or attached to it, are confidential and are intended solely for 
the use of the individual or entity to whom it is addressed and may contain 
information that is confidential, legally privileged, protected by privacy 
laws, or otherwise restricted from disclosure to anyone else. If you are 
not the intended recipient or the person responsible for delivering the 
e-mail to the intended recipient, you are hereby notified that any use, 
copying, distributing, dissemination, forwarding, printing, or copying of 
this e-mail is strictly prohibited. If you received this e-mail in error, 
please return the e-mail to the sender, delete it from your computer, and 
destroy any printed copy of it.

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4169 bytes --]

^ permalink raw reply related	[flat|nested] 75+ messages in thread

* [PATCH 12/24] mpi3mr: add bios_param shost template hook
  2020-12-22 10:11 [PATCH 00/24] Introducing mpi3mr driver Kashyap Desai
                   ` (10 preceding siblings ...)
  2020-12-22 10:11 ` [PATCH 11/24] mpi3mr: print ioc info for debugging Kashyap Desai
@ 2020-12-22 10:11 ` Kashyap Desai
  2021-03-01  7:00   ` Hannes Reinecke
  2020-12-22 10:11 ` [PATCH 13/24] mpi3mr: implement scsi error handler hooks Kashyap Desai
                   ` (12 subsequent siblings)
  24 siblings, 1 reply; 75+ messages in thread
From: Kashyap Desai @ 2020-12-22 10:11 UTC (permalink / raw)
  To: linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, Kashyap Desai, sathya.prakash

[-- Attachment #1: Type: text/plain, Size: 2502 bytes --]

Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Cc: sathya.prakash@broadcom.com
---
 drivers/scsi/mpi3mr/mpi3mr_os.c | 40 +++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c
index 4d94352a4d48..7e0eacf45d84 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_os.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_os.c
@@ -2078,6 +2078,45 @@ static int mpi3mr_build_sg_scmd(struct mpi3mr_ioc *mrioc,
 	return ret;
 }
 
+/**
+ * mpi3mr_bios_param - BIOS param callback
+ * @sdev: SCSI device reference
+ * @bdev: Block device reference
+ * @capacity: Capacity in logical sectors
+ * @params: Parameter array
+ *
+ * Just the parameters with heads/secots/cylinders.
+ *
+ * Return: 0 always
+ */
+static int mpi3mr_bios_param(struct scsi_device *sdev,
+	struct block_device *bdev, sector_t capacity, int params[])
+{
+	int heads;
+	int sectors;
+	sector_t cylinders;
+	ulong dummy;
+
+	heads = 64;
+	sectors = 32;
+
+	dummy = heads * sectors;
+	cylinders = capacity;
+	sector_div(cylinders, dummy);
+
+	if ((ulong)capacity >= 0x200000) {
+		heads = 255;
+		sectors = 63;
+		dummy = heads * sectors;
+		cylinders = capacity;
+		sector_div(cylinders, dummy);
+	}
+
+	params[0] = heads;
+	params[1] = sectors;
+	params[2] = cylinders;
+	return 0;
+}
 
 /**
  * mpi3mr_map_queues - Map queues callback handler
@@ -2511,6 +2550,7 @@ static struct scsi_host_template mpi3mr_driver_template = {
 	.slave_destroy			= mpi3mr_slave_destroy,
 	.scan_finished			= mpi3mr_scan_finished,
 	.scan_start			= mpi3mr_scan_start,
+	.bios_param			= mpi3mr_bios_param,
 	.map_queues			= mpi3mr_map_queues,
 	.no_write_same			= 1,
 	.can_queue			= 1,
-- 
2.18.1


-- 
This electronic communication and the information and any files transmitted 
with it, or attached to it, are confidential and are intended solely for 
the use of the individual or entity to whom it is addressed and may contain 
information that is confidential, legally privileged, protected by privacy 
laws, or otherwise restricted from disclosure to anyone else. If you are 
not the intended recipient or the person responsible for delivering the 
e-mail to the intended recipient, you are hereby notified that any use, 
copying, distributing, dissemination, forwarding, printing, or copying of 
this e-mail is strictly prohibited. If you received this e-mail in error, 
please return the e-mail to the sender, delete it from your computer, and 
destroy any printed copy of it.

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4169 bytes --]

^ permalink raw reply related	[flat|nested] 75+ messages in thread

* [PATCH 13/24] mpi3mr: implement scsi error handler hooks
  2020-12-22 10:11 [PATCH 00/24] Introducing mpi3mr driver Kashyap Desai
                   ` (11 preceding siblings ...)
  2020-12-22 10:11 ` [PATCH 12/24] mpi3mr: add bios_param shost template hook Kashyap Desai
@ 2020-12-22 10:11 ` Kashyap Desai
  2021-03-01  7:09   ` Hannes Reinecke
  2020-12-22 10:11 ` [PATCH 14/24] mpi3mr: add change queue depth support Kashyap Desai
                   ` (11 subsequent siblings)
  24 siblings, 1 reply; 75+ messages in thread
From: Kashyap Desai @ 2020-12-22 10:11 UTC (permalink / raw)
  To: linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, Kashyap Desai, sathya.prakash

[-- Attachment #1: Type: text/plain, Size: 20005 bytes --]

SCSI EH hook is added.

Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Cc: sathya.prakash@broadcom.com
---
 drivers/scsi/mpi3mr/mpi3mr.h    |   3 +
 drivers/scsi/mpi3mr/mpi3mr_fw.c |  51 ++++
 drivers/scsi/mpi3mr/mpi3mr_os.c | 431 +++++++++++++++++++++++++++++++-
 3 files changed, 484 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/mpi3mr/mpi3mr.h b/drivers/scsi/mpi3mr/mpi3mr.h
index 24e2337466dc..a677a4b57a2c 100644
--- a/drivers/scsi/mpi3mr/mpi3mr.h
+++ b/drivers/scsi/mpi3mr/mpi3mr.h
@@ -97,6 +97,7 @@ extern struct list_head mrioc_list;
 /* command/controller interaction timeout definitions in seconds */
 #define MPI3MR_INTADMCMD_TIMEOUT		10
 #define MPI3MR_PORTENABLE_TIMEOUT		300
+#define MPI3MR_ABORTTM_TIMEOUT			30
 #define MPI3MR_RESETTM_TIMEOUT			30
 #define MPI3MR_RESET_HOST_IOWAIT_TIMEOUT	5
 #define MPI3MR_TSUPDATE_INTERVAL		900
@@ -628,6 +629,7 @@ struct scmd_priv {
  * @chain_bitmap_sz: Chain buffer allocator bitmap size
  * @chain_bitmap: Chain buffer allocator bitmap
  * @chain_buf_lock: Chain buffer list lock
+ * @host_tm_cmds: Command tracker for task management commands
  * @dev_rmhs_cmds: Command tracker for device removal commands
  * @devrem_bitmap_sz: Device removal bitmap size
  * @devrem_bitmap: Device removal bitmap
@@ -750,6 +752,7 @@ struct mpi3mr_ioc {
 	void *chain_bitmap;
 	spinlock_t chain_buf_lock;
 
+	struct mpi3mr_drv_cmd host_tm_cmds;
 	struct mpi3mr_drv_cmd dev_rmhs_cmds[MPI3MR_NUM_DEVRMCMD];
 	u16 devrem_bitmap_sz;
 	void *devrem_bitmap;
diff --git a/drivers/scsi/mpi3mr/mpi3mr_fw.c b/drivers/scsi/mpi3mr/mpi3mr_fw.c
index aad0a2bd06b9..ba4bfcc17809 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_fw.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_fw.c
@@ -167,9 +167,13 @@ static struct mpi3mr_drv_cmd *
 mpi3mr_get_drv_cmd(struct mpi3mr_ioc *mrioc, u16 host_tag,
 	Mpi3DefaultReply_t *def_reply)
 {
+	u16 idx;
+
 	switch (host_tag) {
 	case MPI3MR_HOSTTAG_INITCMDS:
 		return &mrioc->init_cmds;
+	case MPI3MR_HOSTTAG_BLK_TMS:
+		return &mrioc->host_tm_cmds;
 	case MPI3MR_HOSTTAG_INVALID:
 		if (def_reply && def_reply->Function ==
 		    MPI3_FUNCTION_EVENT_NOTIFICATION)
@@ -178,6 +182,11 @@ mpi3mr_get_drv_cmd(struct mpi3mr_ioc *mrioc, u16 host_tag,
 	default:
 		break;
 	}
+	if (host_tag >= MPI3MR_HOSTTAG_DEVRMCMD_MIN &&
+	    host_tag <= MPI3MR_HOSTTAG_DEVRMCMD_MAX) {
+		idx = host_tag - MPI3MR_HOSTTAG_DEVRMCMD_MIN;
+		return &mrioc->dev_rmhs_cmds[idx];
+	}
 
 	return NULL;
 }
@@ -2035,6 +2044,31 @@ static int mpi3mr_alloc_reply_sense_bufs(struct mpi3mr_ioc *mrioc)
 	if (!mrioc->init_cmds.reply)
 		goto out_failed;
 
+	mrioc->host_tm_cmds.reply = kzalloc(mrioc->facts.reply_sz, GFP_KERNEL);
+	if (!mrioc->host_tm_cmds.reply)
+		goto out_failed;
+
+	for (i = 0; i < MPI3MR_NUM_DEVRMCMD; i++) {
+		mrioc->dev_rmhs_cmds[i].reply = kzalloc(mrioc->facts.reply_sz,
+		    GFP_KERNEL);
+		if (!mrioc->dev_rmhs_cmds[i].reply)
+			goto out_failed;
+	}
+	mrioc->dev_handle_bitmap_sz = mrioc->facts.max_devhandle / 8;
+	if (mrioc->facts.max_devhandle % 8)
+		mrioc->dev_handle_bitmap_sz++;
+	mrioc->removepend_bitmap = kzalloc(mrioc->dev_handle_bitmap_sz,
+	    GFP_KERNEL);
+	if (!mrioc->removepend_bitmap)
+		goto out_failed;
+
+	mrioc->devrem_bitmap_sz = MPI3MR_NUM_DEVRMCMD / 8;
+	if (MPI3MR_NUM_DEVRMCMD % 8)
+		mrioc->devrem_bitmap_sz++;
+	mrioc->devrem_bitmap = kzalloc(mrioc->devrem_bitmap_sz,
+	    GFP_KERNEL);
+	if (!mrioc->devrem_bitmap)
+		goto out_failed;
 
 	mrioc->num_reply_bufs = mrioc->facts.max_reqs + MPI3MR_NUM_EVT_REPLIES;
 	mrioc->reply_free_qsz = mrioc->num_reply_bufs + 1;
@@ -3021,6 +3055,8 @@ static void mpi3mr_memset_buffers(struct mpi3mr_ioc *mrioc)
 	memset(mrioc->admin_reply_base, 0, mrioc->admin_reply_q_sz);
 
 	memset(mrioc->init_cmds.reply, 0, sizeof(*mrioc->init_cmds.reply));
+	memset(mrioc->host_tm_cmds.reply, 0,
+		    sizeof(*mrioc->host_tm_cmds.reply));
 	for (i = 0; i < MPI3MR_NUM_DEVRMCMD; i++)
 		memset(mrioc->dev_rmhs_cmds[i].reply, 0,
 		    sizeof(*mrioc->dev_rmhs_cmds[i].reply));
@@ -3114,6 +3150,19 @@ static void mpi3mr_free_mem(struct mpi3mr_ioc *mrioc)
 	kfree(mrioc->init_cmds.reply);
 	mrioc->init_cmds.reply = NULL;
 
+	kfree(mrioc->host_tm_cmds.reply);
+	mrioc->host_tm_cmds.reply = NULL;
+
+	for (i = 0; i < MPI3MR_NUM_DEVRMCMD; i++) {
+		kfree(mrioc->dev_rmhs_cmds[i].reply);
+		mrioc->dev_rmhs_cmds[i].reply = NULL;
+	}
+	kfree(mrioc->removepend_bitmap);
+	mrioc->removepend_bitmap = NULL;
+
+	kfree(mrioc->devrem_bitmap);
+	mrioc->devrem_bitmap = NULL;
+
 	kfree(mrioc->chain_bitmap);
 	mrioc->chain_bitmap = NULL;
 
@@ -3289,6 +3338,8 @@ static void mpi3mr_flush_drv_cmds(struct mpi3mr_ioc *mrioc)
 
 	cmdptr = &mrioc->init_cmds;
 	mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
+	cmdptr = &mrioc->host_tm_cmds;
+	mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
 
 	for (i = 0; i < MPI3MR_NUM_DEVRMCMD; i++) {
 		cmdptr = &mrioc->dev_rmhs_cmds[i];
diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c
index 7e0eacf45d84..80de597f8ccf 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_os.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_os.c
@@ -2078,6 +2078,212 @@ static int mpi3mr_build_sg_scmd(struct mpi3mr_ioc *mrioc,
 	return ret;
 }
 
+/**
+ * mpi3mr_print_response_code - print TM response as a string
+ * @mrioc: Adapter instance reference
+ * @resp_code: TM response code
+ *
+ * Print TM response code as a readable string.
+ *
+ * Return: Nothing.
+ */
+static void mpi3mr_print_response_code(struct mpi3mr_ioc *mrioc, u8 resp_code)
+{
+	char *desc;
+
+	switch (resp_code) {
+	case MPI3MR_RSP_TM_COMPLETE:
+		desc = "task management request completed";
+		break;
+	case MPI3MR_RSP_INVALID_FRAME:
+		desc = "invalid frame";
+		break;
+	case MPI3MR_RSP_TM_NOT_SUPPORTED:
+		desc = "task management request not supported";
+		break;
+	case MPI3MR_RSP_TM_FAILED:
+		desc = "task management request failed";
+		break;
+	case MPI3MR_RSP_TM_SUCCEEDED:
+		desc = "task management request succeeded";
+		break;
+	case MPI3MR_RSP_TM_INVALID_LUN:
+		desc = "invalid lun";
+		break;
+	case MPI3MR_RSP_TM_OVERLAPPED_TAG:
+		desc = "overlapped tag attempted";
+		break;
+	case MPI3MR_RSP_IO_QUEUED_ON_IOC:
+		desc = "task queued, however not sent to target";
+		break;
+	default:
+		desc = "unknown";
+		break;
+	}
+	ioc_info(mrioc, "%s :response_code(0x%01x): %s\n", __func__,
+	    resp_code, desc);
+}
+
+/**
+ * mpi3mr_issue_tm - Issue Task Management request
+ * @mrioc: Adapter instance reference
+ * @tm_type: Task Management type
+ * @handle: Device handle
+ * @lun: LUN ID
+ * @htag: Host tag of the TM request
+ * @drv_cmd: Internal command tracker
+ * @resp_code: Response code place holder
+ * @cmd_priv: SCSI command private data
+ *
+ * Issues a Task Management Request to the controller for a
+ * specified target, LUN and command and wait for its completion
+ * and check TM response. Recover the TM if it timed out by
+ * issuing controller reset.
+ *
+ * Return: 0 on success, non-zero on errors
+ */
+static int mpi3mr_issue_tm(struct mpi3mr_ioc *mrioc, u8 tm_type,
+	u16 handle, uint lun, u16 htag, ulong timeout,
+	struct mpi3mr_drv_cmd *drv_cmd,
+	u8 *resp_code, struct scmd_priv *cmd_priv)
+{
+	Mpi3SCSITaskMgmtRequest_t tm_req;
+	Mpi3SCSITaskMgmtReply_t *tm_reply = NULL;
+	int retval = 0;
+	struct mpi3mr_tgt_dev *tgtdev = NULL;
+	struct mpi3mr_stgt_priv_data *scsi_tgt_priv_data = NULL;
+	struct op_req_qinfo *op_req_q = NULL;
+
+	ioc_info(mrioc, "%s :Issue TM: TM Type (0x%x) for devhandle 0x%04x\n",
+	    __func__, tm_type, handle);
+	if (mrioc->unrecoverable) {
+		retval = -1;
+		ioc_err(mrioc, "%s :Issue TM: Unrecoverable controller\n",
+		    __func__);
+		goto out;
+	}
+
+	memset(&tm_req, 0, sizeof(tm_req));
+	mutex_lock(&drv_cmd->mutex);
+	if (drv_cmd->state & MPI3MR_CMD_PENDING) {
+		retval = -1;
+		ioc_err(mrioc, "%s :Issue TM: Command is in use\n", __func__);
+		mutex_unlock(&drv_cmd->mutex);
+		goto out;
+	}
+	if (mrioc->reset_in_progress) {
+		retval = -1;
+		ioc_err(mrioc, "%s :Issue TM: Reset in progress\n", __func__);
+		mutex_unlock(&drv_cmd->mutex);
+		goto out;
+	}
+
+	drv_cmd->state = MPI3MR_CMD_PENDING;
+	drv_cmd->is_waiting = 1;
+	drv_cmd->callback = NULL;
+	tm_req.DevHandle = cpu_to_le16(handle);
+	tm_req.TaskType = tm_type;
+	tm_req.HostTag = cpu_to_le16(htag);
+
+	int_to_scsilun(lun, (struct scsi_lun *)tm_req.LUN);
+	tm_req.Function = MPI3_FUNCTION_SCSI_TASK_MGMT;
+
+	tgtdev = mpi3mr_get_tgtdev_by_handle(mrioc, handle);
+	if (tgtdev && tgtdev->starget && tgtdev->starget->hostdata) {
+		scsi_tgt_priv_data = (struct mpi3mr_stgt_priv_data *)
+		    tgtdev->starget->hostdata;
+		atomic_inc(&scsi_tgt_priv_data->block_io);
+	}
+	if (cmd_priv) {
+		op_req_q = &mrioc->req_qinfo[cmd_priv->req_q_idx];
+		tm_req.TaskHostTag = cpu_to_le16(cmd_priv->host_tag);
+		tm_req.TaskRequestQueueID = cpu_to_le16(op_req_q->qid);
+	}
+	if (tgtdev && (tgtdev->dev_type == MPI3_DEVICE_DEVFORM_PCIE)) {
+		if (cmd_priv && tgtdev->dev_spec.pcie_inf.abort_to)
+			timeout = tgtdev->dev_spec.pcie_inf.abort_to;
+		else if (!cmd_priv && tgtdev->dev_spec.pcie_inf.reset_to)
+			timeout = tgtdev->dev_spec.pcie_inf.reset_to;
+	}
+
+	init_completion(&drv_cmd->done);
+	retval = mpi3mr_admin_request_post(mrioc, &tm_req, sizeof(tm_req), 1);
+	if (retval) {
+		ioc_err(mrioc, "%s :Issue TM: Admin Post failed\n", __func__);
+		goto out_unlock;
+	}
+	wait_for_completion_timeout(&drv_cmd->done, (timeout * HZ));
+
+	if (!(drv_cmd->state & MPI3MR_CMD_COMPLETE)) {
+		ioc_err(mrioc, "%s :Issue TM: command timed out\n", __func__);
+		drv_cmd->is_waiting = 0;
+		retval = -1;
+		mpi3mr_soft_reset_handler(mrioc,
+		    MPI3MR_RESET_FROM_TM_TIMEOUT, 1);
+		goto out_unlock;
+	}
+
+	if (drv_cmd->state & MPI3MR_CMD_REPLY_VALID)
+		tm_reply = (Mpi3SCSITaskMgmtReply_t *)drv_cmd->reply;
+
+	if (drv_cmd->ioc_status != MPI3_IOCSTATUS_SUCCESS) {
+		ioc_err(mrioc,
+		    "%s :Issue TM: handle(0x%04x) Failed IOCStatus(0x%04x) Loginfo(0x%08x)\n",
+		    __func__, handle, drv_cmd->ioc_status,
+		    drv_cmd->ioc_loginfo);
+		retval = -1;
+		goto out_unlock;
+	}
+
+	if (!tm_reply) {
+		ioc_err(mrioc, "%s :Issue TM: No TM Reply message\n", __func__);
+		retval = -1;
+		goto out_unlock;
+	}
+
+	*resp_code = le32_to_cpu(tm_reply->ResponseData) &
+	    MPI3MR_RI_MASK_RESPCODE;
+	switch (*resp_code) {
+	case MPI3MR_RSP_TM_SUCCEEDED:
+	case MPI3MR_RSP_TM_COMPLETE:
+		break;
+	case MPI3MR_RSP_IO_QUEUED_ON_IOC:
+		if (tm_type != MPI3_SCSITASKMGMT_TASKTYPE_QUERY_TASK)
+			retval = -1;
+		break;
+	default:
+		retval = -1;
+		break;
+	}
+
+	ioc_info(mrioc,
+	    "%s :Issue TM: Completed TM Type (0x%x) handle(0x%04x) ",
+	    __func__, tm_type, handle);
+	ioc_info(mrioc,
+	    "with ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
+	    drv_cmd->ioc_status, drv_cmd->ioc_loginfo,
+	    le32_to_cpu(tm_reply->TerminationCount));
+	mpi3mr_print_response_code(mrioc, *resp_code);
+
+out_unlock:
+	drv_cmd->state = MPI3MR_CMD_NOTUSED;
+	mutex_unlock(&drv_cmd->mutex);
+	if (scsi_tgt_priv_data)
+		atomic_dec_if_positive(&scsi_tgt_priv_data->block_io);
+	if (tgtdev)
+		mpi3mr_tgtdev_put(tgtdev);
+	if (!retval) {
+		/*
+		 * Flush all IRQ handlers by calling synchronize_irq().
+		 * mpi3mr_ioc_disable_intr() takes care of it.
+		 */
+		mpi3mr_ioc_disable_intr(mrioc);
+		mpi3mr_ioc_enable_intr(mrioc);
+	}
+out:
+	return retval;
+}
+
 /**
  * mpi3mr_bios_param - BIOS param callback
  * @sdev: SCSI device reference
@@ -2135,6 +2341,221 @@ static int mpi3mr_map_queues(struct Scsi_Host *shost)
 	    mrioc->pdev, mrioc->op_reply_q_offset);
 }
 
+/**
+ * mpi3mr_eh_host_reset - Host reset error handling callback
+ * @scmd: SCSI command reference
+ *
+ * Issue controller reset if the scmd is for a Physical Device,
+ * if the scmd is for RAID volume, then wait for
+ * MPI3MR_RAID_ERRREC_RESET_TIMEOUT and checke whether any
+ * pending I/Os prior to issuing reset to the controller.
+ *
+ * Return: SUCCESS of successful reset else FAILED
+ */
+static int mpi3mr_eh_host_reset(struct scsi_cmnd *scmd)
+{
+	struct mpi3mr_ioc *mrioc = shost_priv(scmd->device->host);
+	struct mpi3mr_stgt_priv_data *stgt_priv_data;
+	struct mpi3mr_sdev_priv_data *sdev_priv_data;
+	u8 dev_type = MPI3_DEVICE_DEVFORM_VD;
+	int retval = FAILED, ret;
+
+	sdev_priv_data = scmd->device->hostdata;
+	if (sdev_priv_data && sdev_priv_data->tgt_priv_data) {
+		stgt_priv_data = sdev_priv_data->tgt_priv_data;
+		dev_type = stgt_priv_data->dev_type;
+	}
+
+	ret = mpi3mr_soft_reset_handler(mrioc,
+	    MPI3MR_RESET_FROM_EH_HOS, 1);
+	if (ret)
+		goto out;
+
+	retval = SUCCESS;
+out:
+	sdev_printk(KERN_INFO, scmd->device,
+	    "Host reset is %s for scmd(%p)\n",
+	    ((retval == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
+
+	return retval;
+}
+
+/**
+ * mpi3mr_eh_target_reset - Target reset error handling callback
+ * @scmd: SCSI command reference
+ *
+ * Issue Target reset Task Management and verify the scmd is
+ * terminated successfully and return status accordingly.
+ *
+ * Return: SUCCESS of successful termination of the scmd else
+ *         FAILED
+ */
+static int mpi3mr_eh_target_reset(struct scsi_cmnd *scmd)
+{
+	struct mpi3mr_ioc *mrioc = shost_priv(scmd->device->host);
+	struct mpi3mr_stgt_priv_data *stgt_priv_data;
+	struct mpi3mr_sdev_priv_data *sdev_priv_data;
+	u16 dev_handle;
+	u8 resp_code = 0;
+	int retval = FAILED, ret = 0;
+
+
+	sdev_printk(KERN_INFO, scmd->device,
+	    "Attempting Target Reset! scmd(%p)\n", scmd);
+	scsi_print_command(scmd);
+
+	sdev_priv_data = scmd->device->hostdata;
+	if (!sdev_priv_data || !sdev_priv_data->tgt_priv_data) {
+		sdev_printk(KERN_INFO, scmd->device,
+		    "SCSI device is not available\n");
+		retval = SUCCESS;
+		goto out;
+	}
+
+	stgt_priv_data = sdev_priv_data->tgt_priv_data;
+	dev_handle = stgt_priv_data->dev_handle;
+	sdev_printk(KERN_INFO, scmd->device,
+	    "Target Reset is issued to handle(0x%04x)\n",
+	    dev_handle);
+
+	ret = mpi3mr_issue_tm(mrioc,
+	    MPI3_SCSITASKMGMT_TASKTYPE_TARGET_RESET, dev_handle,
+	    sdev_priv_data->lun_id, MPI3MR_HOSTTAG_BLK_TMS,
+	    MPI3MR_RESETTM_TIMEOUT, &mrioc->host_tm_cmds, &resp_code, NULL);
+
+	if (ret)
+		goto out;
+
+	retval = SUCCESS;
+out:
+	sdev_printk(KERN_INFO, scmd->device,
+	    "Target reset is %s for scmd(%p)\n",
+	    ((retval == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
+
+	return retval;
+}
+
+/**
+ * mpi3mr_eh_dev_reset- Device reset error handling callback
+ * @scmd: SCSI command reference
+ *
+ * Issue LUN reset Task Management and verify the scmd is
+ * terminated successfully and return status accordingly.
+ *
+ * Return: SUCCESS of successful termination of the scmd else
+ *         FAILED
+ */
+static int mpi3mr_eh_dev_reset(struct scsi_cmnd *scmd)
+{
+	struct mpi3mr_ioc *mrioc = shost_priv(scmd->device->host);
+	struct mpi3mr_stgt_priv_data *stgt_priv_data;
+	struct mpi3mr_sdev_priv_data *sdev_priv_data;
+	u16 dev_handle;
+	u8 resp_code = 0;
+	int retval = FAILED, ret = 0;
+
+	sdev_printk(KERN_INFO, scmd->device,
+	    "Attempting Device(LUN) Reset! scmd(%p)\n", scmd);
+	scsi_print_command(scmd);
+
+	sdev_priv_data = scmd->device->hostdata;
+	if (!sdev_priv_data || !sdev_priv_data->tgt_priv_data) {
+		sdev_printk(KERN_INFO, scmd->device,
+		    "SCSI device is not available\n");
+		retval = SUCCESS;
+		goto out;
+	}
+
+	stgt_priv_data = sdev_priv_data->tgt_priv_data;
+	dev_handle = stgt_priv_data->dev_handle;
+	sdev_printk(KERN_INFO, scmd->device,
+	    "Device(LUN) Reset is issued to handle(0x%04x)\n", dev_handle);
+
+	ret = mpi3mr_issue_tm(mrioc,
+	    MPI3_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, dev_handle,
+	    sdev_priv_data->lun_id, MPI3MR_HOSTTAG_BLK_TMS,
+	    MPI3MR_RESETTM_TIMEOUT, &mrioc->host_tm_cmds, &resp_code, NULL);
+
+	if (ret)
+		goto out;
+
+	retval = SUCCESS;
+out:
+	sdev_printk(KERN_INFO, scmd->device,
+	    "Device(LUN) reset is %s for scmd(%p)\n",
+	    ((retval == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
+
+	return retval;
+}
+
+/**
+ * mpi3mr_eh_abort- Abort error handling callback
+ * @scmd: SCSI command reference
+ *
+ * Issue Abort Task Management if the command is in LLD scope
+ * and verify if it is aborted successfully and return status
+ * accordingly.
+ *
+ * Return: SUCCESS of successful abort the scmd else FAILED
+ */
+static int mpi3mr_eh_abort(struct scsi_cmnd *scmd)
+{
+	struct mpi3mr_ioc *mrioc = shost_priv(scmd->device->host);
+	struct mpi3mr_stgt_priv_data *stgt_priv_data;
+	struct mpi3mr_sdev_priv_data *sdev_priv_data;
+	struct scmd_priv *cmd_priv;
+	u16 dev_handle;
+	u8 resp_code = 0;
+	int retval = FAILED, ret = 0;
+
+	sdev_printk(KERN_INFO, scmd->device,
+	    "Attempting Task Abort! scmd(%p)\n", scmd);
+	scsi_print_command(scmd);
+
+	sdev_priv_data = scmd->device->hostdata;
+	if (!sdev_priv_data || !sdev_priv_data->tgt_priv_data) {
+		sdev_printk(KERN_INFO, scmd->device,
+		    "SCSI device is not available\n");
+		retval = SUCCESS;
+		goto out;
+	}
+
+	stgt_priv_data = sdev_priv_data->tgt_priv_data;
+	dev_handle = stgt_priv_data->dev_handle;
+	sdev_printk(KERN_INFO, scmd->device,
+	    "Timedout scmd (%p) is issued to handle(0x%04x)\n", scmd,
+	    dev_handle);
+
+	cmd_priv = scsi_cmd_priv(scmd);
+	if (!cmd_priv->in_lld_scope ||
+	    cmd_priv->host_tag == MPI3MR_HOSTTAG_INVALID) {
+		sdev_printk(KERN_INFO, scmd->device,
+		    "SCSI command not in LLD scope\n");
+		retval = SUCCESS;
+		goto out;
+	}
+
+	ret = mpi3mr_issue_tm(mrioc, MPI3_SCSITASKMGMT_TASKTYPE_ABORT_TASK,
+	    dev_handle, sdev_priv_data->lun_id, MPI3MR_HOSTTAG_BLK_TMS,
+	    MPI3MR_ABORTTM_TIMEOUT, &mrioc->host_tm_cmds, &resp_code,
+	    cmd_priv);
+
+	if (ret)
+		goto out;
+
+	if (cmd_priv->in_lld_scope) {
+		sdev_printk(KERN_INFO, scmd->device,
+		    "SCSI command(%p) is still not aborted\n", scmd);
+		goto out;
+	}
+	retval = SUCCESS;
+out:
+	sdev_printk(KERN_INFO, scmd->device, "Task Abort is %s for scmd(%p)\n",
+	    ((retval == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
+
+	return retval;
+}
+
 /**
  * mpi3mr_scan_start - Scan start callback handler
  * @shost: SCSI host reference
@@ -2550,6 +2971,10 @@ static struct scsi_host_template mpi3mr_driver_template = {
 	.slave_destroy			= mpi3mr_slave_destroy,
 	.scan_finished			= mpi3mr_scan_finished,
 	.scan_start			= mpi3mr_scan_start,
+	.eh_abort_handler		= mpi3mr_eh_abort,
+	.eh_device_reset_handler	= mpi3mr_eh_dev_reset,
+	.eh_target_reset_handler	= mpi3mr_eh_target_reset,
+	.eh_host_reset_handler		= mpi3mr_eh_host_reset,
 	.bios_param			= mpi3mr_bios_param,
 	.map_queues			= mpi3mr_map_queues,
 	.no_write_same			= 1,
@@ -2605,7 +3030,7 @@ mpi3mr_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 {
 	struct mpi3mr_ioc *mrioc = NULL;
 	struct Scsi_Host *shost = NULL;
-	int retval = 0;
+	int retval = 0, i;
 
 	shost = scsi_host_alloc(&mpi3mr_driver_template,
 	    sizeof(struct mpi3mr_ioc));
@@ -2637,7 +3062,11 @@ mpi3mr_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 
 	mutex_init(&mrioc->reset_mutex);
 	mpi3mr_init_drv_cmd(&mrioc->init_cmds, MPI3MR_HOSTTAG_INITCMDS);
+	mpi3mr_init_drv_cmd(&mrioc->host_tm_cmds, MPI3MR_HOSTTAG_BLK_TMS);
 
+	for (i = 0; i < MPI3MR_NUM_DEVRMCMD; i++)
+		mpi3mr_init_drv_cmd(&mrioc->dev_rmhs_cmds[i],
+		    MPI3MR_HOSTTAG_DEVRMCMD_MIN + i);
 	if (pdev->revision)
 		mrioc->enable_segqueue = true;
 
-- 
2.18.1


-- 
This electronic communication and the information and any files transmitted 
with it, or attached to it, are confidential and are intended solely for 
the use of the individual or entity to whom it is addressed and may contain 
information that is confidential, legally privileged, protected by privacy 
laws, or otherwise restricted from disclosure to anyone else. If you are 
not the intended recipient or the person responsible for delivering the 
e-mail to the intended recipient, you are hereby notified that any use, 
copying, distributing, dissemination, forwarding, printing, or copying of 
this e-mail is strictly prohibited. If you received this e-mail in error, 
please return the e-mail to the sender, delete it from your computer, and 
destroy any printed copy of it.

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4169 bytes --]

^ permalink raw reply related	[flat|nested] 75+ messages in thread

* [PATCH 14/24] mpi3mr: add change queue depth support
  2020-12-22 10:11 [PATCH 00/24] Introducing mpi3mr driver Kashyap Desai
                   ` (12 preceding siblings ...)
  2020-12-22 10:11 ` [PATCH 13/24] mpi3mr: implement scsi error handler hooks Kashyap Desai
@ 2020-12-22 10:11 ` Kashyap Desai
  2021-03-01  7:10   ` Hannes Reinecke
  2020-12-22 10:11 ` [PATCH 15/24] mpi3mr: allow certain commands during pci-remove hook Kashyap Desai
                   ` (10 subsequent siblings)
  24 siblings, 1 reply; 75+ messages in thread
From: Kashyap Desai @ 2020-12-22 10:11 UTC (permalink / raw)
  To: linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, Kashyap Desai, sathya.prakash

[-- Attachment #1: Type: text/plain, Size: 3901 bytes --]

Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Cc: sathya.prakash@broadcom.com
---
 drivers/scsi/mpi3mr/mpi3mr.h    |  3 +++
 drivers/scsi/mpi3mr/mpi3mr_os.c | 35 ++++++++++++++++++++++++++++++++-
 2 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/mpi3mr/mpi3mr.h b/drivers/scsi/mpi3mr/mpi3mr.h
index a677a4b57a2c..74b6b4b6e322 100644
--- a/drivers/scsi/mpi3mr/mpi3mr.h
+++ b/drivers/scsi/mpi3mr/mpi3mr.h
@@ -141,6 +141,9 @@ extern struct list_head mrioc_list;
 /* Command retry count definitions */
 #define MPI3MR_DEV_RMHS_RETRY_COUNT 3
 
+/* Default target device queue depth */
+#define MPI3MR_DEFAULT_SDEV_QD	32
+
 /* SGE Flag definition */
 #define MPI3MR_SGEFLAGS_SYSTEM_SIMPLE_END_OF_LIST \
 	(MPI3_SGE_FLAGS_ELEMENT_TYPE_SIMPLE | MPI3_SGE_FLAGS_DLAS_SYSTEM | \
diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c
index 80de597f8ccf..6f19e5392433 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_os.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_os.c
@@ -648,6 +648,34 @@ static int mpi3mr_report_tgtdev_to_host(struct mpi3mr_ioc *mrioc,
 	return retval;
 }
 
+/**
+ * mpi3mr_change_queue_depth- Change QD callback handler
+ * @sdev: SCSI device reference
+ * @q_depth: Queue depth
+ *
+ * Validate and limit QD and call scsi_change_queue_depth.
+ *
+ * Return: return value of scsi_change_queue_depth
+ */
+static int mpi3mr_change_queue_depth(struct scsi_device *sdev,
+	int q_depth)
+{
+	struct scsi_target *starget = scsi_target(sdev);
+	struct Scsi_Host *shost = dev_to_shost(&starget->dev);
+	int retval = 0;
+
+	if (!sdev->tagged_supported)
+		q_depth = 1;
+	if (q_depth > shost->can_queue)
+		q_depth = shost->can_queue;
+	else if (!q_depth)
+		q_depth = MPI3MR_DEFAULT_SDEV_QD;
+	retval = scsi_change_queue_depth(sdev, q_depth);
+
+	return retval;
+}
+
+
 /**
  * mpi3mr_update_sdev - Update SCSI device information
  * @sdev: SCSI device reference
@@ -668,6 +696,7 @@ mpi3mr_update_sdev(struct scsi_device *sdev, void *data)
 	if (!tgtdev)
 		return;
 
+	mpi3mr_change_queue_depth(sdev, tgtdev->q_depth);
 	switch (tgtdev->dev_type) {
 	case MPI3_DEVICE_DEVFORM_PCIE:
 		/*The block layer hw sector size = 512*/
@@ -2729,9 +2758,12 @@ static int mpi3mr_slave_configure(struct scsi_device *sdev)
 	spin_lock_irqsave(&mrioc->tgtdev_lock, flags);
 	tgt_dev = __mpi3mr_get_tgtdev_by_perst_id(mrioc, starget->id);
 	spin_unlock_irqrestore(&mrioc->tgtdev_lock, flags);
-	if (!tgt_dev)
+	if (!tgt_dev) {
+		mpi3mr_change_queue_depth(sdev, MPI3MR_DEFAULT_SDEV_QD);
 		return retval;
+	}
 
+	mpi3mr_change_queue_depth(sdev, tgt_dev->q_depth);
 	switch (tgt_dev->dev_type) {
 	case MPI3_DEVICE_DEVFORM_PCIE:
 		/*The block layer hw sector size = 512*/
@@ -2971,6 +3003,7 @@ static struct scsi_host_template mpi3mr_driver_template = {
 	.slave_destroy			= mpi3mr_slave_destroy,
 	.scan_finished			= mpi3mr_scan_finished,
 	.scan_start			= mpi3mr_scan_start,
+	.change_queue_depth		= mpi3mr_change_queue_depth,
 	.eh_abort_handler		= mpi3mr_eh_abort,
 	.eh_device_reset_handler	= mpi3mr_eh_dev_reset,
 	.eh_target_reset_handler	= mpi3mr_eh_target_reset,
-- 
2.18.1


-- 
This electronic communication and the information and any files transmitted 
with it, or attached to it, are confidential and are intended solely for 
the use of the individual or entity to whom it is addressed and may contain 
information that is confidential, legally privileged, protected by privacy 
laws, or otherwise restricted from disclosure to anyone else. If you are 
not the intended recipient or the person responsible for delivering the 
e-mail to the intended recipient, you are hereby notified that any use, 
copying, distributing, dissemination, forwarding, printing, or copying of 
this e-mail is strictly prohibited. If you received this e-mail in error, 
please return the e-mail to the sender, delete it from your computer, and 
destroy any printed copy of it.

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4169 bytes --]

^ permalink raw reply related	[flat|nested] 75+ messages in thread

* [PATCH 15/24] mpi3mr: allow certain commands during pci-remove hook
  2020-12-22 10:11 [PATCH 00/24] Introducing mpi3mr driver Kashyap Desai
                   ` (13 preceding siblings ...)
  2020-12-22 10:11 ` [PATCH 14/24] mpi3mr: add change queue depth support Kashyap Desai
@ 2020-12-22 10:11 ` Kashyap Desai
  2021-03-01  7:11   ` Hannes Reinecke
  2020-12-22 10:11 ` [PATCH 16/24] mpi3mr: hardware workaround for UNMAP commands to nvme drives Kashyap Desai
                   ` (9 subsequent siblings)
  24 siblings, 1 reply; 75+ messages in thread
From: Kashyap Desai @ 2020-12-22 10:11 UTC (permalink / raw)
  To: linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, Kashyap Desai, sathya.prakash

[-- Attachment #1: Type: text/plain, Size: 2272 bytes --]

This patch allows SSU and Sync Cache commands to be sent to the controller
instead of driver returning DID_NO_CONNECT during driver unload to flush
any cached data from the drive.

Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Cc: sathya.prakash@broadcom.com
---
 drivers/scsi/mpi3mr/mpi3mr_os.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c
index 6f19e5392433..07a7b1efbc4f 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_os.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_os.c
@@ -2865,6 +2865,27 @@ static int mpi3mr_target_alloc(struct scsi_target *starget)
 	return retval;
 }
 
+
+/**
+ * mpi3mr_allow_scmd_to_fw - Command is allowed during shutdown
+ * @scmd: SCSI Command reference
+ *
+ * Checks whether a CDB is allowed during shutdown or not.
+ *
+ * Return: TRUE for allowed commands, FALSE otherwise.
+ */
+
+inline bool mpi3mr_allow_scmd_to_fw(struct scsi_cmnd *scmd)
+{
+	switch (scmd->cmnd[0]) {
+	case SYNCHRONIZE_CACHE:
+	case START_STOP:
+		return true;
+	default:
+		return false;
+	}
+}
+
 /**
  * mpi3mr_qcmd - I/O request despatcher
  * @shost: SCSI Host reference
@@ -2900,7 +2921,8 @@ static int mpi3mr_qcmd(struct Scsi_Host *shost,
 		goto out;
 	}
 
-	if (mrioc->stop_drv_processing) {
+	if (mrioc->stop_drv_processing &&
+	    !(mpi3mr_allow_scmd_to_fw(scmd))) {
 		scmd->result = DID_NO_CONNECT << 16;
 		scmd->scsi_done(scmd);
 		goto out;
-- 
2.18.1


-- 
This electronic communication and the information and any files transmitted 
with it, or attached to it, are confidential and are intended solely for 
the use of the individual or entity to whom it is addressed and may contain 
information that is confidential, legally privileged, protected by privacy 
laws, or otherwise restricted from disclosure to anyone else. If you are 
not the intended recipient or the person responsible for delivering the 
e-mail to the intended recipient, you are hereby notified that any use, 
copying, distributing, dissemination, forwarding, printing, or copying of 
this e-mail is strictly prohibited. If you received this e-mail in error, 
please return the e-mail to the sender, delete it from your computer, and 
destroy any printed copy of it.

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4169 bytes --]

^ permalink raw reply related	[flat|nested] 75+ messages in thread

* [PATCH 16/24] mpi3mr: hardware workaround for UNMAP commands to nvme drives
  2020-12-22 10:11 [PATCH 00/24] Introducing mpi3mr driver Kashyap Desai
                   ` (14 preceding siblings ...)
  2020-12-22 10:11 ` [PATCH 15/24] mpi3mr: allow certain commands during pci-remove hook Kashyap Desai
@ 2020-12-22 10:11 ` Kashyap Desai
  2021-03-01  7:13   ` Hannes Reinecke
  2020-12-22 10:11 ` [PATCH 17/24] mpi3mr: add support of threaded isr Kashyap Desai
                   ` (8 subsequent siblings)
  24 siblings, 1 reply; 75+ messages in thread
From: Kashyap Desai @ 2020-12-22 10:11 UTC (permalink / raw)
  To: linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, Kashyap Desai, sathya.prakash

[-- Attachment #1: Type: text/plain, Size: 4627 bytes --]

The controller hardware can not handle certain unmap commands for NVMe
drives, this patch adds support in the driver to check those commands and
handle as appropriate.

Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Cc: sathya.prakash@broadcom.com
---
 drivers/scsi/mpi3mr/mpi3mr_os.c | 99 +++++++++++++++++++++++++++++++++
 1 file changed, 99 insertions(+)

diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c
index 07a7b1efbc4f..742cf45d4878 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_os.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_os.c
@@ -2865,6 +2865,100 @@ static int mpi3mr_target_alloc(struct scsi_target *starget)
 	return retval;
 }
 
+/**
+ * mpi3mr_check_return_unmap - Whether an unmap is allowed
+ * @mrioc: Adapter instance reference
+ * @scmd: SCSI Command reference
+ *
+ * The controller hardware cannot handle certain unmap commands
+ * for NVMe drives, this routine checks those and return true
+ * and completes the SCSI command with proper status and sense
+ * data.
+ *
+ * Return: TRUE for not  allowed unmap, FALSE otherwise.
+ */
+static bool mpi3mr_check_return_unmap(struct mpi3mr_ioc *mrioc,
+	struct scsi_cmnd *scmd)
+{
+	unsigned char *buf;
+	u16 param_len, desc_len;
+
+	param_len = get_unaligned_be16(scmd->cmnd + 7);
+
+	if (!param_len) {
+		ioc_warn(mrioc,
+		    "%s: CDB received with zero parameter length\n",
+		    __func__);
+		scsi_print_command(scmd);
+		scmd->result = DID_OK << 16;
+		scmd->scsi_done(scmd);
+		return true;
+	}
+
+	if (param_len < 24) {
+		ioc_warn(mrioc,
+		    "%s: CDB received with invalid param_len: %d\n",
+		    __func__, param_len);
+		scsi_print_command(scmd);
+		scmd->result = (DRIVER_SENSE << 24) |
+		    SAM_STAT_CHECK_CONDITION;
+		scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST,
+		    0x1A, 0);
+		scmd->scsi_done(scmd);
+		return true;
+	}
+	if (param_len != scsi_bufflen(scmd)) {
+		ioc_warn(mrioc,
+		    "%s: CDB received with param_len: %d bufflen: %d\n",
+		    __func__, param_len, scsi_bufflen(scmd));
+		scsi_print_command(scmd);
+		scmd->result = (DRIVER_SENSE << 24) |
+		    SAM_STAT_CHECK_CONDITION;
+		scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST,
+		    0x1A, 0);
+		scmd->scsi_done(scmd);
+		return true;
+	}
+	buf = kzalloc(scsi_bufflen(scmd), GFP_ATOMIC);
+	if (!buf) {
+		scsi_print_command(scmd);
+		scmd->result = (DRIVER_SENSE << 24) |
+		    SAM_STAT_CHECK_CONDITION;
+		scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST,
+		    0x55, 0x03);
+		scmd->scsi_done(scmd);
+		return true;
+	}
+	scsi_sg_copy_to_buffer(scmd, buf, scsi_bufflen(scmd));
+	desc_len = get_unaligned_be16(&buf[2]);
+
+	if (desc_len < 16) {
+		ioc_warn(mrioc,
+		    "%s: Invalid descriptor length in param list: %d\n",
+		    __func__, desc_len);
+		scsi_print_command(scmd);
+		scmd->result = (DRIVER_SENSE << 24) |
+		    SAM_STAT_CHECK_CONDITION;
+		scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST,
+		    0x26, 0);
+		scmd->scsi_done(scmd);
+		kfree(buf);
+		return true;
+	}
+
+	if (param_len > (desc_len + 8)) {
+		scsi_print_command(scmd);
+		ioc_warn(mrioc,
+		    "%s: Truncating param_len(%d) to desc_len+8(%d)\n",
+		    __func__, param_len, (desc_len + 8));
+		param_len = desc_len + 8;
+		put_unaligned_be16(param_len, scmd->cmnd+7);
+		scsi_print_command(scmd);
+	}
+
+	kfree(buf);
+	return false;
+}
 
 /**
  * mpi3mr_allow_scmd_to_fw - Command is allowed during shutdown
@@ -2957,6 +3051,11 @@ static int mpi3mr_qcmd(struct Scsi_Host *shost,
 		goto out;
 	}
 
+	if ((scmd->cmnd[0] == UNMAP) &&
+	    (stgt_priv_data->dev_type == MPI3_DEVICE_DEVFORM_PCIE) &&
+	    mpi3mr_check_return_unmap(mrioc, scmd))
+		goto out;
+
 	host_tag = mpi3mr_host_tag_for_scmd(mrioc, scmd);
 	if (host_tag == MPI3MR_HOSTTAG_INVALID) {
 		scmd->result = DID_ERROR << 16;
-- 
2.18.1


-- 
This electronic communication and the information and any files transmitted 
with it, or attached to it, are confidential and are intended solely for 
the use of the individual or entity to whom it is addressed and may contain 
information that is confidential, legally privileged, protected by privacy 
laws, or otherwise restricted from disclosure to anyone else. If you are 
not the intended recipient or the person responsible for delivering the 
e-mail to the intended recipient, you are hereby notified that any use, 
copying, distributing, dissemination, forwarding, printing, or copying of 
this e-mail is strictly prohibited. If you received this e-mail in error, 
please return the e-mail to the sender, delete it from your computer, and 
destroy any printed copy of it.

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4169 bytes --]

^ permalink raw reply related	[flat|nested] 75+ messages in thread

* [PATCH 17/24] mpi3mr: add support of threaded isr
  2020-12-22 10:11 [PATCH 00/24] Introducing mpi3mr driver Kashyap Desai
                   ` (15 preceding siblings ...)
  2020-12-22 10:11 ` [PATCH 16/24] mpi3mr: hardware workaround for UNMAP commands to nvme drives Kashyap Desai
@ 2020-12-22 10:11 ` Kashyap Desai
  2020-12-27 13:51     ` kernel test robot
  2021-03-01  7:14   ` Hannes Reinecke
  2020-12-22 10:11 ` [PATCH 18/24] mpi3mr: add complete support of soft reset Kashyap Desai
                   ` (7 subsequent siblings)
  24 siblings, 2 replies; 75+ messages in thread
From: Kashyap Desai @ 2020-12-22 10:11 UTC (permalink / raw)
  To: linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, Kashyap Desai, sathya.prakash

[-- Attachment #1: Type: text/plain, Size: 8598 bytes --]

Register driver for threaded interrupt.

By default, driver will attempt io completion from interrupt context
(primary handler). Since driver tracks per reply queue outstanding ios,
it will schedule threaded ISR if there are any outstanding IOs expected
on that particular reply queue. Threaded ISR (secondary handler) will loop
for IO completion as long as there are outstanding IOs
(speculative method using same per reply queue outstanding counter)
or it has completed some X amount of commands (something like budget).

Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Cc: sathya.prakash@broadcom.com
---
 drivers/scsi/mpi3mr/mpi3mr.h    | 12 ++++++
 drivers/scsi/mpi3mr/mpi3mr_fw.c | 75 +++++++++++++++++++++++++++++++--
 2 files changed, 84 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/mpi3mr/mpi3mr.h b/drivers/scsi/mpi3mr/mpi3mr.h
index 74b6b4b6e322..41a8689b46c9 100644
--- a/drivers/scsi/mpi3mr/mpi3mr.h
+++ b/drivers/scsi/mpi3mr/mpi3mr.h
@@ -144,6 +144,10 @@ extern struct list_head mrioc_list;
 /* Default target device queue depth */
 #define MPI3MR_DEFAULT_SDEV_QD	32
 
+/* Definitions for Threaded IRQ poll*/
+#define MPI3MR_IRQ_POLL_SLEEP			2
+#define MPI3MR_IRQ_POLL_TRIGGER_IOCOUNT		8
+
 /* SGE Flag definition */
 #define MPI3MR_SGEFLAGS_SYSTEM_SIMPLE_END_OF_LIST \
 	(MPI3_SGE_FLAGS_ELEMENT_TYPE_SIMPLE | MPI3_SGE_FLAGS_DLAS_SYSTEM | \
@@ -295,6 +299,9 @@ struct op_req_qinfo {
  * @q_segment_list: Segment list base virtual address
  * @q_segment_list_dma: Segment list base DMA address
  * @ephase: Expected phased identifier for the reply queue
+ * @pend_ios: Number of IOs pending in HW for this queue
+ * @enable_irq_poll: Flag to indicate polling is enabled
+ * @in_use: Queue is handled by poll/ISR
  */
 struct op_reply_qinfo {
 	u16 ci;
@@ -306,6 +313,9 @@ struct op_reply_qinfo {
 	void *q_segment_list;
 	dma_addr_t q_segment_list_dma;
 	u8 ephase;
+	atomic_t pend_ios;
+	bool enable_irq_poll;
+	atomic_t in_use;
 };
 
 /**
@@ -559,6 +569,7 @@ struct scmd_priv {
  * @shost: Scsi_Host pointer
  * @id: Controller ID
  * @cpu_count: Number of online CPUs
+ * @irqpoll_sleep: usleep unit used in threaded isr irqpoll
  * @name: Controller ASCII name
  * @driver_name: Driver ASCII name
  * @sysif_regs: System interface registers virtual address
@@ -660,6 +671,7 @@ struct mpi3mr_ioc {
 	u8 id;
 	int cpu_count;
 	bool enable_segqueue;
+	u32 irqpoll_sleep;
 
 	char name[MPI3MR_NAME_LENGTH];
 	char driver_name[MPI3MR_NAME_LENGTH];
diff --git a/drivers/scsi/mpi3mr/mpi3mr_fw.c b/drivers/scsi/mpi3mr/mpi3mr_fw.c
index ba4bfcc17809..4c4e21fb4ef3 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_fw.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_fw.c
@@ -346,12 +346,16 @@ static int mpi3mr_process_op_reply_q(struct mpi3mr_ioc *mrioc,
 
 	reply_qidx = op_reply_q->qid - 1;
 
+	if (!atomic_add_unless(&op_reply_q->in_use, 1, 1))
+		return 0;
+
 	exp_phase = op_reply_q->ephase;
 	reply_ci = op_reply_q->ci;
 
 	reply_desc = mpi3mr_get_reply_desc(op_reply_q, reply_ci);
 	if ((le16_to_cpu(reply_desc->ReplyFlags) &
 	    MPI3_REPLY_DESCRIPT_FLAGS_PHASE_MASK) != exp_phase) {
+		atomic_dec(&op_reply_q->in_use);
 		return 0;
 	}
 
@@ -364,6 +368,7 @@ static int mpi3mr_process_op_reply_q(struct mpi3mr_ioc *mrioc,
 
 		mpi3mr_process_op_reply_desc(mrioc, reply_desc, &reply_dma,
 		    reply_qidx);
+		atomic_dec(&op_reply_q->pend_ios);
 		if (reply_dma)
 			mpi3mr_repost_reply_buf(mrioc, reply_dma);
 		num_op_reply++;
@@ -378,6 +383,14 @@ static int mpi3mr_process_op_reply_q(struct mpi3mr_ioc *mrioc,
 		if ((le16_to_cpu(reply_desc->ReplyFlags) &
 		    MPI3_REPLY_DESCRIPT_FLAGS_PHASE_MASK) != exp_phase)
 			break;
+		/*
+		 * Exit completion loop to avoid CPU lockup
+		 * Ensure remaining completion happens from threaded ISR.
+		 */
+		if (num_op_reply > mrioc->max_host_ios) {
+			intr_info->op_reply_q->enable_irq_poll = true;
+			break;
+		}
 
 	} while (1);
 
@@ -386,6 +399,7 @@ static int mpi3mr_process_op_reply_q(struct mpi3mr_ioc *mrioc,
 	    &mrioc->sysif_regs->OperQueueIndexes[reply_qidx].ConsumerIndex);
 	op_reply_q->ci = reply_ci;
 	op_reply_q->ephase = exp_phase;
+	atomic_dec(&op_reply_q->in_use);
 
 	return num_op_reply;
 }
@@ -395,7 +409,7 @@ static irqreturn_t mpi3mr_isr_primary(int irq, void *privdata)
 	struct mpi3mr_intr_info *intr_info = privdata;
 	struct mpi3mr_ioc *mrioc;
 	u16 midx;
-	u32 num_admin_replies = 0;
+	u32 num_admin_replies = 0, num_op_reply = 0;
 
 	if (!intr_info)
 		return IRQ_NONE;
@@ -409,8 +423,10 @@ static irqreturn_t mpi3mr_isr_primary(int irq, void *privdata)
 
 	if (!midx)
 		num_admin_replies = mpi3mr_process_admin_reply_q(mrioc);
+	if (intr_info->op_reply_q)
+		num_op_reply = mpi3mr_process_op_reply_q(mrioc, intr_info);
 
-	if (num_admin_replies)
+	if (num_admin_replies || num_op_reply)
 		return IRQ_HANDLED;
 	else
 		return IRQ_NONE;
@@ -431,7 +447,20 @@ static irqreturn_t mpi3mr_isr(int irq, void *privdata)
 	/* Call primary ISR routine */
 	ret = mpi3mr_isr_primary(irq, privdata);
 
-	return ret;
+	/*
+	 * If more IOs are expected, schedule IRQ polling thread.
+	 * Otherwise exit from ISR.
+	 */
+	if (!intr_info->op_reply_q)
+		return ret;
+
+	if (!intr_info->op_reply_q->enable_irq_poll ||
+	    !atomic_read(&intr_info->op_reply_q->pend_ios))
+		return ret;
+
+	disable_irq_nosync(pci_irq_vector(mrioc->pdev, midx));
+
+	return IRQ_WAKE_THREAD;
 }
 
 /**
@@ -446,6 +475,36 @@ static irqreturn_t mpi3mr_isr(int irq, void *privdata)
  */
 static irqreturn_t mpi3mr_isr_poll(int irq, void *privdata)
 {
+	struct mpi3mr_intr_info *intr_info = privdata;
+	struct mpi3mr_ioc *mrioc;
+	u16 midx;
+	u32 num_admin_replies = 0, num_op_reply = 0;
+
+	if (!intr_info || !intr_info->op_reply_q)
+		return IRQ_NONE;
+
+	mrioc = intr_info->mrioc;
+	midx = intr_info->msix_index;
+
+	/* Poll for pending IOs completions */
+	do {
+		if (!mrioc->intr_enabled)
+			break;
+
+		if (!midx)
+			num_admin_replies = mpi3mr_process_admin_reply_q(mrioc);
+		if (intr_info->op_reply_q)
+			num_op_reply +=
+			    mpi3mr_process_op_reply_q(mrioc, intr_info);
+
+		usleep_range(mrioc->irqpoll_sleep, 10 * mrioc->irqpoll_sleep);
+
+	} while (atomic_read(&intr_info->op_reply_q->pend_ios) &&
+	    (num_op_reply < mrioc->max_host_ios));
+
+	intr_info->op_reply_q->enable_irq_poll = false;
+	enable_irq(pci_irq_vector(mrioc->pdev, midx));
+
 	return IRQ_HANDLED;
 }
 
@@ -1161,6 +1220,9 @@ static int mpi3mr_create_op_reply_q(struct mpi3mr_ioc *mrioc, u16 qidx)
 	op_reply_q->num_replies = MPI3MR_OP_REP_Q_QD;
 	op_reply_q->ci = 0;
 	op_reply_q->ephase = 1;
+	atomic_set(&op_reply_q->pend_ios, 0);
+	atomic_set(&op_reply_q->in_use, 0);
+	op_reply_q->enable_irq_poll = false;
 
 	if (!op_reply_q->q_segments) {
 		retval = mpi3mr_alloc_op_reply_q_segments(mrioc, qidx);
@@ -1482,6 +1544,10 @@ int mpi3mr_op_request_post(struct mpi3mr_ioc *mrioc,
 		pi = 0;
 	op_req_q->pi = pi;
 
+	if (atomic_inc_return(&mrioc->op_reply_qinfo[reply_qidx].pend_ios)
+	    > MPI3MR_IRQ_POLL_TRIGGER_IOCOUNT)
+		mrioc->op_reply_qinfo[reply_qidx].enable_irq_poll = true;
+
 	writel(op_req_q->pi,
 	    &mrioc->sysif_regs->OperQueueIndexes[reply_qidx].ProducerIndex);
 
@@ -2783,6 +2849,7 @@ int mpi3mr_init_ioc(struct mpi3mr_ioc *mrioc, u8 re_init)
 	u32 ioc_status, ioc_config, i;
 	Mpi3IOCFactsData_t facts_data;
 
+	mrioc->irqpoll_sleep = MPI3MR_IRQ_POLL_SLEEP;
 	mrioc->change_count = 0;
 	if (!re_init) {
 		mrioc->cpu_count = num_online_cpus();
@@ -3068,6 +3135,8 @@ static void mpi3mr_memset_buffers(struct mpi3mr_ioc *mrioc)
 		mrioc->op_reply_qinfo[i].ci = 0;
 		mrioc->op_reply_qinfo[i].num_replies = 0;
 		mrioc->op_reply_qinfo[i].ephase = 0;
+		atomic_set(&mrioc->op_reply_qinfo[i].pend_ios, 0);
+		atomic_set(&mrioc->op_reply_qinfo[i].in_use, 0);
 		mpi3mr_memset_op_reply_q_buffers(mrioc, i);
 
 		mrioc->req_qinfo[i].ci = 0;
-- 
2.18.1


-- 
This electronic communication and the information and any files transmitted 
with it, or attached to it, are confidential and are intended solely for 
the use of the individual or entity to whom it is addressed and may contain 
information that is confidential, legally privileged, protected by privacy 
laws, or otherwise restricted from disclosure to anyone else. If you are 
not the intended recipient or the person responsible for delivering the 
e-mail to the intended recipient, you are hereby notified that any use, 
copying, distributing, dissemination, forwarding, printing, or copying of 
this e-mail is strictly prohibited. If you received this e-mail in error, 
please return the e-mail to the sender, delete it from your computer, and 
destroy any printed copy of it.

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4169 bytes --]

^ permalink raw reply related	[flat|nested] 75+ messages in thread

* [PATCH 18/24] mpi3mr: add complete support of soft reset
  2020-12-22 10:11 [PATCH 00/24] Introducing mpi3mr driver Kashyap Desai
                   ` (16 preceding siblings ...)
  2020-12-22 10:11 ` [PATCH 17/24] mpi3mr: add support of threaded isr Kashyap Desai
@ 2020-12-22 10:11 ` Kashyap Desai
  2021-03-01  7:16   ` Hannes Reinecke
  2020-12-22 10:11 ` [PATCH 19/24] mpi3mr: print pending host ios for debug Kashyap Desai
                   ` (6 subsequent siblings)
  24 siblings, 1 reply; 75+ messages in thread
From: Kashyap Desai @ 2020-12-22 10:11 UTC (permalink / raw)
  To: linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, Kashyap Desai, sathya.prakash

[-- Attachment #1: Type: text/plain, Size: 11011 bytes --]

Unlock the host diagnostic registers and write the specific
reset type to that, wait for reset acknowledgment from the
controller, if the reset is not successful retry for the
predefined number of times

Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Cc: sathya.prakash@broadcom.com
---
 drivers/scsi/mpi3mr/mpi3mr.h    |   3 +
 drivers/scsi/mpi3mr/mpi3mr_fw.c | 245 +++++++++++++++++++++++++++++++-
 2 files changed, 246 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/mpi3mr/mpi3mr.h b/drivers/scsi/mpi3mr/mpi3mr.h
index 41a8689b46c9..1d51e42778f6 100644
--- a/drivers/scsi/mpi3mr/mpi3mr.h
+++ b/drivers/scsi/mpi3mr/mpi3mr.h
@@ -189,6 +189,9 @@ enum mpi3mr_reset_reason {
 	MPI3MR_RESET_FROM_EVTACK_TIMEOUT = 19,
 	MPI3MR_RESET_FROM_CIACTVRST_TIMER = 20,
 	MPI3MR_RESET_FROM_GETPKGVER_TIMEOUT = 21,
+	MPI3MR_RESET_FROM_PELABORT_TIMEOUT = 22,
+	MPI3MR_RESET_FROM_SYSFS = 23,
+	MPI3MR_RESET_FROM_SYSFS_TIMEOUT = 24
 };
 
 /**
diff --git a/drivers/scsi/mpi3mr/mpi3mr_fw.c b/drivers/scsi/mpi3mr/mpi3mr_fw.c
index 4c4e21fb4ef3..36a68c488019 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_fw.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_fw.c
@@ -645,6 +645,100 @@ static const char *mpi3mr_iocstate_name(enum mpi3mr_iocstate mrioc_state)
 	return name;
 }
 
+/* Reset reason to name mapper structure*/
+static const struct {
+	enum mpi3mr_reset_reason value;
+	char *name;
+} mpi3mr_reset_reason_codes[] = {
+	{ MPI3MR_RESET_FROM_BRINGUP, "timeout in bringup" },
+	{ MPI3MR_RESET_FROM_FAULT_WATCH, "fault" },
+	{ MPI3MR_RESET_FROM_IOCTL, "application invocation" },
+	{ MPI3MR_RESET_FROM_EH_HOS, "error handling" },
+	{ MPI3MR_RESET_FROM_TM_TIMEOUT, "TM timeout" },
+	{ MPI3MR_RESET_FROM_IOCTL_TIMEOUT, "IOCTL timeout" },
+	{ MPI3MR_RESET_FROM_MUR_FAILURE, "MUR failure" },
+	{ MPI3MR_RESET_FROM_CTLR_CLEANUP, "timeout in controller cleanup" },
+	{ MPI3MR_RESET_FROM_CIACTIV_FAULT, "component image activation fault" },
+	{ MPI3MR_RESET_FROM_PE_TIMEOUT, "port enable timeout" },
+	{ MPI3MR_RESET_FROM_TSU_TIMEOUT, "time stamp update timeout" },
+	{ MPI3MR_RESET_FROM_DELREQQ_TIMEOUT, "delete request queue timeout" },
+	{ MPI3MR_RESET_FROM_DELREPQ_TIMEOUT, "delete reply queue timeout" },
+	{
+		MPI3MR_RESET_FROM_CREATEREPQ_TIMEOUT,
+		"create request queue timeout"
+	},
+	{
+		MPI3MR_RESET_FROM_CREATEREQQ_TIMEOUT,
+		"create reply queue timeout"
+	},
+	{ MPI3MR_RESET_FROM_IOCFACTS_TIMEOUT, "IOC facts timeout" },
+	{ MPI3MR_RESET_FROM_IOCINIT_TIMEOUT, "IOC init timeout" },
+	{ MPI3MR_RESET_FROM_EVTNOTIFY_TIMEOUT, "event notify timeout" },
+	{ MPI3MR_RESET_FROM_EVTACK_TIMEOUT, "event acknowledgment timeout" },
+	{
+		MPI3MR_RESET_FROM_CIACTVRST_TIMER,
+		"component image activation timeout"
+	},
+	{
+		MPI3MR_RESET_FROM_GETPKGVER_TIMEOUT,
+		"get package version timeout"
+	},
+	{ MPI3MR_RESET_FROM_SYSFS, "sysfs invocation" },
+	{ MPI3MR_RESET_FROM_SYSFS_TIMEOUT, "sysfs TM timeout" },
+};
+
+/**
+ * mpi3mr_reset_rc_name - get reset reason code name
+ * @reason_code: reset reason code value
+ *
+ * Map reset reason to an NULL terminated ASCII string
+ *
+ * Return: Name corresponding to reset reason value or NULL.
+ */
+static const char *mpi3mr_reset_rc_name(enum mpi3mr_reset_reason reason_code)
+{
+	int i;
+	char *name = NULL;
+
+	for (i = 0; i < ARRAY_SIZE(mpi3mr_reset_reason_codes); i++) {
+		if (mpi3mr_reset_reason_codes[i].value == reason_code) {
+			name = mpi3mr_reset_reason_codes[i].name;
+			break;
+		}
+	}
+	return name;
+}
+
+/* Reset type to name mapper structure*/
+static const struct {
+	u16 reset_type;
+	char *name;
+} mpi3mr_reset_types[] = {
+	{ MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET, "soft" },
+	{ MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT, "diag fault" },
+};
+
+/**
+ * mpi3mr_reset_type_name - get reset type name
+ * reset_type: reset type value
+ *
+ * Map reset type to an NULL terminated ASCII string
+ *
+ * Return: Name corresponding to reset type value or NULL.
+ */
+static const char *mpi3mr_reset_type_name(u16 reset_type)
+{
+	int i;
+	char *name = NULL;
+
+	for (i = 0; i < ARRAY_SIZE(mpi3mr_reset_types); i++) {
+		if (mpi3mr_reset_types[i].reset_type == reset_type) {
+			name = mpi3mr_reset_types[i].name;
+			break;
+		}
+	}
+	return name;
+}
 
 /**
  * mpi3mr_print_fault_info - Display fault information
@@ -808,6 +902,48 @@ static int mpi3mr_bring_ioc_ready(struct mpi3mr_ioc *mrioc)
 	return -1;
 }
 
+/**
+ * mpi3mr_soft_reset_success - Check softreset is success or not
+ * @ioc_status: IOC status register value
+ * @ioc_config: IOC config register value
+ *
+ * Check whether the soft reset is successful or not based on
+ * IOC status and IOC config register values.
+ *
+ * Return: True when the soft reset is success, false otherwise.
+ */
+static inline bool
+mpi3mr_soft_reset_success(u32 ioc_status, u32 ioc_config)
+{
+	if (!((ioc_status & MPI3_SYSIF_IOC_STATUS_READY) ||
+	    (ioc_status & MPI3_SYSIF_IOC_STATUS_FAULT) ||
+	    (ioc_config & MPI3_SYSIF_IOC_CONFIG_ENABLE_IOC)))
+		return true;
+	return false;
+}
+
+/**
+ * mpi3mr_diagfault_success - Check diag fault is success or not
+ * @mrioc: Adapter reference
+ * @ioc_status: IOC status register value
+ *
+ * Check whether the controller hit diag reset fault code.
+ *
+ * Return: True when there is diag fault, false otherwise.
+ */
+static inline bool mpi3mr_diagfault_success(struct mpi3mr_ioc *mrioc,
+	u32 ioc_status)
+{
+	u32 fault;
+
+	if (!(ioc_status & MPI3_SYSIF_IOC_STATUS_FAULT))
+		return false;
+	fault = readl(&mrioc->sysif_regs->Fault) & MPI3_SYSIF_FAULT_CODE_MASK;
+	if (fault == MPI3_SYSIF_FAULT_CODE_DIAG_FAULT_RESET)
+		return true;
+	return false;
+}
+
 /**
  * mpi3mr_set_diagsave - Set diag save bit for snapdump
  * @mrioc: Adapter reference
@@ -832,14 +968,117 @@ static inline void mpi3mr_set_diagsave(struct mpi3mr_ioc *mrioc)
  * @reset_type: Reset type
  * @reset_reason: Reset reason code
  *
- * TBD
+ * Unlock the host diagnostic registers and write the specific
+ * reset type to that, wait for reset acknowledgment from the
+ * controller, if the reset is not successful retry for the
+ * predefined number of times.
  *
  * Return: 0 on success, non-zero on failure.
  */
 static int mpi3mr_issue_reset(struct mpi3mr_ioc *mrioc, u16 reset_type,
 	u32 reset_reason)
 {
-	return 0;
+	int retval = -1;
+	u8 unlock_retry_count, reset_retry_count = 0;
+	u32 host_diagnostic, timeout, ioc_status, ioc_config;
+
+	pci_cfg_access_lock(mrioc->pdev);
+	if ((reset_type != MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET) &&
+	    (reset_type != MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT))
+		goto out;
+	if (mrioc->unrecoverable)
+		goto out;
+retry_reset:
+	unlock_retry_count = 0;
+	mpi3mr_clear_reset_history(mrioc);
+	do {
+		ioc_info(mrioc,
+		    "Write magic sequence to unlock host diag register (retry=%d)\n",
+		    ++unlock_retry_count);
+		if (unlock_retry_count >= MPI3MR_HOSTDIAG_UNLOCK_RETRY_COUNT) {
+			writel(reset_reason, &mrioc->sysif_regs->Scratchpad[0]);
+			mrioc->unrecoverable = 1;
+			goto out;
+		}
+
+		writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_FLUSH,
+		    &mrioc->sysif_regs->WriteSequence);
+		writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_1ST,
+		    &mrioc->sysif_regs->WriteSequence);
+		writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_2ND,
+		    &mrioc->sysif_regs->WriteSequence);
+		writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_3RD,
+		    &mrioc->sysif_regs->WriteSequence);
+		writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_4TH,
+		    &mrioc->sysif_regs->WriteSequence);
+		writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_5TH,
+		    &mrioc->sysif_regs->WriteSequence);
+		writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_6TH,
+		    &mrioc->sysif_regs->WriteSequence);
+		usleep_range(1000, 1100);
+		host_diagnostic = readl(&mrioc->sysif_regs->HostDiagnostic);
+		ioc_info(mrioc,
+		    "wrote magic sequence: retry_count(%d), host_diagnostic(0x%08x)\n",
+		    unlock_retry_count, host_diagnostic);
+	} while (!(host_diagnostic & MPI3_SYSIF_HOST_DIAG_DIAG_WRITE_ENABLE));
+
+	writel(reset_reason, &mrioc->sysif_regs->Scratchpad[0]);
+	ioc_info(mrioc, "%s reset due to %s(0x%x)\n",
+	    mpi3mr_reset_type_name(reset_type),
+	    mpi3mr_reset_rc_name(reset_reason), reset_reason);
+	writel(host_diagnostic | reset_type,
+	    &mrioc->sysif_regs->HostDiagnostic);
+	timeout = mrioc->ready_timeout * 10;
+	if (reset_type == MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET) {
+		do {
+			ioc_status = readl(&mrioc->sysif_regs->IOCStatus);
+			if (ioc_status &
+			    MPI3_SYSIF_IOC_STATUS_RESET_HISTORY) {
+				mpi3mr_clear_reset_history(mrioc);
+				ioc_config =
+				    readl(&mrioc->sysif_regs->IOCConfiguration);
+				if (mpi3mr_soft_reset_success(ioc_status,
+				    ioc_config)) {
+					retval = 0;
+					break;
+				}
+			}
+			msleep(100);
+		} while (--timeout);
+		writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_2ND,
+		    &mrioc->sysif_regs->WriteSequence);
+	} else if (reset_type == MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT) {
+		do {
+			ioc_status = readl(&mrioc->sysif_regs->IOCStatus);
+			if (mpi3mr_diagfault_success(mrioc, ioc_status)) {
+				retval = 0;
+				break;
+			}
+			msleep(100);
+		} while (--timeout);
+		mpi3mr_clear_reset_history(mrioc);
+		writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_2ND,
+		    &mrioc->sysif_regs->WriteSequence);
+	}
+	if (retval && ((++reset_retry_count) < MPI3MR_MAX_RESET_RETRY_COUNT)) {
+		ioc_status = readl(&mrioc->sysif_regs->IOCStatus);
+		ioc_config = readl(&mrioc->sysif_regs->IOCConfiguration);
+		ioc_info(mrioc,
+		    "Base IOC Sts/Config after reset try %d is (0x%x)/(0x%x)\n",
+		    reset_retry_count, ioc_status, ioc_config);
+		goto retry_reset;
+	}
+
+out:
+	pci_cfg_access_unlock(mrioc->pdev);
+	ioc_status = readl(&mrioc->sysif_regs->IOCStatus);
+	ioc_config = readl(&mrioc->sysif_regs->IOCConfiguration);
+
+	ioc_info(mrioc,
+	    "Base IOC Sts/Config after %s reset is (0x%x)/(0x%x)\n",
+	    (!retval)?"successful":"failed", ioc_status,
+	    ioc_config);
+	return retval;
 }
 
 /**
@@ -3432,6 +3671,8 @@ int mpi3mr_diagfault_reset_handler(struct mpi3mr_ioc *mrioc,
 {
 	int retval = 0;
 
+	ioc_info(mrioc, "Entry: reason code: %s\n",
+	    mpi3mr_reset_rc_name(reset_reason));
 	mrioc->reset_in_progress = 1;
 
 	mpi3mr_ioc_disable_intr(mrioc);
-- 
2.18.1


-- 
This electronic communication and the information and any files transmitted 
with it, or attached to it, are confidential and are intended solely for 
the use of the individual or entity to whom it is addressed and may contain 
information that is confidential, legally privileged, protected by privacy 
laws, or otherwise restricted from disclosure to anyone else. If you are 
not the intended recipient or the person responsible for delivering the 
e-mail to the intended recipient, you are hereby notified that any use, 
copying, distributing, dissemination, forwarding, printing, or copying of 
this e-mail is strictly prohibited. If you received this e-mail in error, 
please return the e-mail to the sender, delete it from your computer, and 
destroy any printed copy of it.

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4169 bytes --]

^ permalink raw reply related	[flat|nested] 75+ messages in thread

* [PATCH 19/24] mpi3mr: print pending host ios for debug
  2020-12-22 10:11 [PATCH 00/24] Introducing mpi3mr driver Kashyap Desai
                   ` (17 preceding siblings ...)
  2020-12-22 10:11 ` [PATCH 18/24] mpi3mr: add complete support of soft reset Kashyap Desai
@ 2020-12-22 10:11 ` Kashyap Desai
  2021-03-01  7:16   ` Hannes Reinecke
  2020-12-22 10:11 ` [PATCH 20/24] mpi3mr: wait for pending IO completions upon detection of VD IO timeout Kashyap Desai
                   ` (5 subsequent siblings)
  24 siblings, 1 reply; 75+ messages in thread
From: Kashyap Desai @ 2020-12-22 10:11 UTC (permalink / raw)
  To: linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, Kashyap Desai, sathya.prakash

[-- Attachment #1: Type: text/plain, Size: 3517 bytes --]

Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Cc: sathya.prakash@broadcom.com
---
 drivers/scsi/mpi3mr/mpi3mr_os.c | 68 +++++++++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)

diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c
index 742cf45d4878..8e665c70604d 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_os.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_os.c
@@ -334,6 +334,36 @@ void mpi3mr_invalidate_devhandles(struct mpi3mr_ioc *mrioc)
 	}
 }
 
+/**
+ * mpi3mr_print_scmd - print individual SCSI command
+ * @rq: Block request
+ * @data: Adapter instance reference
+ *
+ * Print the SCSI command details if it is in LLD scope.
+ *
+ * Return: true always.
+ */
+static bool mpi3mr_print_scmd(struct request *rq,
+	void *data, bool reserved)
+{
+	struct mpi3mr_ioc *mrioc = (struct mpi3mr_ioc *)data;
+	struct scsi_cmnd *scmd = blk_mq_rq_to_pdu(rq);
+	struct scmd_priv *priv = NULL;
+
+	if (scmd) {
+		priv = scsi_cmd_priv(scmd);
+		if (!priv->in_lld_scope)
+			goto out;
+
+		ioc_info(mrioc, "%s :Host Tag = %d, qid = %d\n",
+		    __func__, priv->host_tag, priv->req_q_idx + 1);
+		scsi_print_command(scmd);
+	}
+
+out:
+	return(true);
+}
+
 
 /**
  * mpi3mr_flush_scmd - Flush individual SCSI command
@@ -2370,6 +2400,43 @@ static int mpi3mr_map_queues(struct Scsi_Host *shost)
 	    mrioc->pdev, mrioc->op_reply_q_offset);
 }
 
+/**
+ * mpi3mr_get_fw_pending_ios - Calculate pending I/O count
+ * @mrioc: Adapter instance reference
+ *
+ * Calculate the pending I/Os for the controller and return.
+ *
+ * Return: Number of pending I/Os
+ */
+static inline int mpi3mr_get_fw_pending_ios(struct mpi3mr_ioc *mrioc)
+{
+	u16 i;
+	uint pend_ios = 0;
+
+	for (i = 0; i < mrioc->num_op_reply_q; i++)
+		pend_ios += atomic_read(&mrioc->op_reply_qinfo[i].pend_ios);
+	return pend_ios;
+}
+
+/**
+ * mpi3mr_print_pending_host_io - print pending I/Os
+ * @mrioc: Adapter instance reference
+ *
+ * Print number of pending I/Os and each I/O details prior to
+ * reset for debug purpose.
+ *
+ * Return: Nothing
+ */
+static void mpi3mr_print_pending_host_io(struct mpi3mr_ioc *mrioc)
+{
+	struct Scsi_Host *shost = mrioc->shost;
+
+	ioc_info(mrioc, "%s :Pending commands prior to reset: %d\n",
+	    __func__, mpi3mr_get_fw_pending_ios(mrioc));
+	blk_mq_tagset_busy_iter(&shost->tag_set,
+	    mpi3mr_print_scmd, (void *)mrioc);
+}
+
 /**
  * mpi3mr_eh_host_reset - Host reset error handling callback
  * @scmd: SCSI command reference
@@ -2395,6 +2462,7 @@ static int mpi3mr_eh_host_reset(struct scsi_cmnd *scmd)
 		dev_type = stgt_priv_data->dev_type;
 	}
 
+	mpi3mr_print_pending_host_io(mrioc);
 	ret = mpi3mr_soft_reset_handler(mrioc,
 	    MPI3MR_RESET_FROM_EH_HOS, 1);
 	if (ret)
-- 
2.18.1


-- 
This electronic communication and the information and any files transmitted 
with it, or attached to it, are confidential and are intended solely for 
the use of the individual or entity to whom it is addressed and may contain 
information that is confidential, legally privileged, protected by privacy 
laws, or otherwise restricted from disclosure to anyone else. If you are 
not the intended recipient or the person responsible for delivering the 
e-mail to the intended recipient, you are hereby notified that any use, 
copying, distributing, dissemination, forwarding, printing, or copying of 
this e-mail is strictly prohibited. If you received this e-mail in error, 
please return the e-mail to the sender, delete it from your computer, and 
destroy any printed copy of it.

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4169 bytes --]

^ permalink raw reply related	[flat|nested] 75+ messages in thread

* [PATCH 20/24] mpi3mr: wait for pending IO completions upon detection of VD IO timeout
  2020-12-22 10:11 [PATCH 00/24] Introducing mpi3mr driver Kashyap Desai
                   ` (18 preceding siblings ...)
  2020-12-22 10:11 ` [PATCH 19/24] mpi3mr: print pending host ios for debug Kashyap Desai
@ 2020-12-22 10:11 ` Kashyap Desai
  2021-03-01  7:17   ` Hannes Reinecke
  2020-12-22 10:11 ` [PATCH 21/24] mpi3mr: add support of PM suspend and resume Kashyap Desai
                   ` (4 subsequent siblings)
  24 siblings, 1 reply; 75+ messages in thread
From: Kashyap Desai @ 2020-12-22 10:11 UTC (permalink / raw)
  To: linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, Kashyap Desai, sathya.prakash

[-- Attachment #1: Type: text/plain, Size: 3907 bytes --]

Wait for (default 180 seconds) host IO completion if IO timeout is detected
on VDs

Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Cc: sathya.prakash@broadcom.com
---
 drivers/scsi/mpi3mr/mpi3mr.h    |  1 +
 drivers/scsi/mpi3mr/mpi3mr_fw.c |  2 ++
 drivers/scsi/mpi3mr/mpi3mr_os.c | 45 +++++++++++++++++++++++++++++++++
 3 files changed, 48 insertions(+)

diff --git a/drivers/scsi/mpi3mr/mpi3mr.h b/drivers/scsi/mpi3mr/mpi3mr.h
index 1d51e42778f6..5554b0e49a58 100644
--- a/drivers/scsi/mpi3mr/mpi3mr.h
+++ b/drivers/scsi/mpi3mr/mpi3mr.h
@@ -102,6 +102,7 @@ extern struct list_head mrioc_list;
 #define MPI3MR_RESET_HOST_IOWAIT_TIMEOUT	5
 #define MPI3MR_TSUPDATE_INTERVAL		900
 #define MPI3MR_DEFAULT_SHUTDOWN_TIME		120
+#define	MPI3MR_RAID_ERRREC_RESET_TIMEOUT	180
 
 #define MPI3MR_WATCHDOG_INTERVAL		1000 /* in milli seconds */
 
diff --git a/drivers/scsi/mpi3mr/mpi3mr_fw.c b/drivers/scsi/mpi3mr/mpi3mr_fw.c
index 36a68c488019..b27e44f78544 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_fw.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_fw.c
@@ -3749,6 +3749,8 @@ int mpi3mr_soft_reset_handler(struct mpi3mr_ioc *mrioc,
 		}
 	}
 
+	mpi3mr_wait_for_host_io(mrioc, MPI3MR_RESET_HOST_IOWAIT_TIMEOUT);
+
 	mpi3mr_ioc_disable_intr(mrioc);
 
 	if (snapdump) {
diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c
index 8e665c70604d..1708aca1a5cd 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_os.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_os.c
@@ -2437,6 +2437,43 @@ static void mpi3mr_print_pending_host_io(struct mpi3mr_ioc *mrioc)
 	    mpi3mr_print_scmd, (void *)mrioc);
 }
 
+/**
+ * mpi3mr_wait_for_host_io - block for I/Os to complete
+ * @mrioc: Adapter instance reference
+ * @timeout: time out in seconds
+ * Waits for pending I/Os for the given adapter to complete or
+ * to hit the timeout.
+ *
+ * Return: Nothing
+ */
+void mpi3mr_wait_for_host_io(struct mpi3mr_ioc *mrioc, u32 timeout)
+{
+	enum mpi3mr_iocstate iocstate;
+	int i = 0;
+
+	iocstate = mpi3mr_get_iocstate(mrioc);
+	if (iocstate != MRIOC_STATE_READY)
+		return;
+
+	if (!mpi3mr_get_fw_pending_ios(mrioc))
+		return;
+	ioc_info(mrioc,
+	    "%s :Waiting for %d seconds prior to reset for %d I/O\n",
+	    __func__, timeout, mpi3mr_get_fw_pending_ios(mrioc));
+
+	for (i = 0; i < timeout; i++) {
+		if (!mpi3mr_get_fw_pending_ios(mrioc))
+			break;
+		iocstate = mpi3mr_get_iocstate(mrioc);
+		if (iocstate != MRIOC_STATE_READY)
+			break;
+		msleep(1000);
+	}
+
+	ioc_info(mrioc, "%s :Pending I/Os after wait is: %d\n", __func__,
+	    mpi3mr_get_fw_pending_ios(mrioc));
+}
+
 /**
  * mpi3mr_eh_host_reset - Host reset error handling callback
  * @scmd: SCSI command reference
@@ -2462,6 +2499,14 @@ static int mpi3mr_eh_host_reset(struct scsi_cmnd *scmd)
 		dev_type = stgt_priv_data->dev_type;
 	}
 
+	if (dev_type == MPI3_DEVICE_DEVFORM_VD) {
+		mpi3mr_wait_for_host_io(mrioc,
+		    MPI3MR_RAID_ERRREC_RESET_TIMEOUT);
+		if (!mpi3mr_get_fw_pending_ios(mrioc)) {
+			retval = SUCCESS;
+			goto out;
+		}
+	}
 	mpi3mr_print_pending_host_io(mrioc);
 	ret = mpi3mr_soft_reset_handler(mrioc,
 	    MPI3MR_RESET_FROM_EH_HOS, 1);
-- 
2.18.1


-- 
This electronic communication and the information and any files transmitted 
with it, or attached to it, are confidential and are intended solely for 
the use of the individual or entity to whom it is addressed and may contain 
information that is confidential, legally privileged, protected by privacy 
laws, or otherwise restricted from disclosure to anyone else. If you are 
not the intended recipient or the person responsible for delivering the 
e-mail to the intended recipient, you are hereby notified that any use, 
copying, distributing, dissemination, forwarding, printing, or copying of 
this e-mail is strictly prohibited. If you received this e-mail in error, 
please return the e-mail to the sender, delete it from your computer, and 
destroy any printed copy of it.

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4169 bytes --]

^ permalink raw reply related	[flat|nested] 75+ messages in thread

* [PATCH 21/24] mpi3mr: add support of PM suspend and resume
  2020-12-22 10:11 [PATCH 00/24] Introducing mpi3mr driver Kashyap Desai
                   ` (19 preceding siblings ...)
  2020-12-22 10:11 ` [PATCH 20/24] mpi3mr: wait for pending IO completions upon detection of VD IO timeout Kashyap Desai
@ 2020-12-22 10:11 ` Kashyap Desai
  2021-02-22 15:32   ` Tomas Henzl
  2021-03-01  7:18   ` Hannes Reinecke
  2020-12-22 10:11 ` [PATCH 22/24] mpi3mr: add support of DSN secure fw check Kashyap Desai
                   ` (3 subsequent siblings)
  24 siblings, 2 replies; 75+ messages in thread
From: Kashyap Desai @ 2020-12-22 10:11 UTC (permalink / raw)
  To: linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, Kashyap Desai, sathya.prakash

[-- Attachment #1: Type: text/plain, Size: 3792 bytes --]

Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Cc: sathya.prakash@broadcom.com
---
 drivers/scsi/mpi3mr/mpi3mr_os.c | 85 +++++++++++++++++++++++++++++++++
 1 file changed, 85 insertions(+)

diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c
index 1708aca1a5cd..ac47eed74705 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_os.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_os.c
@@ -3480,6 +3480,87 @@ static void mpi3mr_shutdown(struct pci_dev *pdev)
 
 }
 
+#ifdef CONFIG_PM
+/**
+ * mpi3mr_suspend - PCI power management suspend callback
+ * @pdev: PCI device instance
+ * @state: New power state
+ *
+ * Change the power state to the given value and cleanup the IOC
+ * by issuing MUR and shutdown notification
+ *
+ * Return: 0 always.
+ */
+static int mpi3mr_suspend(struct pci_dev *pdev, pm_message_t state)
+{
+	struct Scsi_Host *shost = pci_get_drvdata(pdev);
+	struct mpi3mr_ioc *mrioc;
+	pci_power_t device_state;
+
+	if (!shost)
+		return 0;
+
+	mrioc = shost_priv(shost);
+	while (mrioc->reset_in_progress || mrioc->is_driver_loading)
+		ssleep(1);
+	mrioc->stop_drv_processing = 1;
+	mpi3mr_cleanup_fwevt_list(mrioc);
+	scsi_block_requests(shost);
+	mpi3mr_stop_watchdog(mrioc);
+	mpi3mr_cleanup_ioc(mrioc, 1);
+
+	device_state = pci_choose_state(pdev, state);
+	ioc_info(mrioc, "pdev=0x%p, slot=%s, entering operating state [D%d]\n",
+	    pdev, pci_name(pdev), device_state);
+	pci_save_state(pdev);
+	pci_set_power_state(pdev, device_state);
+	mpi3mr_cleanup_resources(mrioc);
+
+	return 0;
+}
+
+/**
+ * mpi3mr_resume - PCI power management resume callback
+ * @pdev: PCI device instance
+ *
+ * Restore the power state to D0 and reinitialize the controller
+ * and resume I/O operations to the target devices
+ *
+ * Return: 0 on success, non-zero on failure
+ */
+static int mpi3mr_resume(struct pci_dev *pdev)
+{
+	struct Scsi_Host *shost = pci_get_drvdata(pdev);
+	struct mpi3mr_ioc *mrioc;
+	pci_power_t device_state = pdev->current_state;
+	int r;
+
+	mrioc = shost_priv(shost);
+
+	ioc_info(mrioc, "pdev=0x%p, slot=%s, previous operating state [D%d]\n",
+	    pdev, pci_name(pdev), device_state);
+	pci_set_power_state(pdev, PCI_D0);
+	pci_enable_wake(pdev, PCI_D0, 0);
+	pci_restore_state(pdev);
+	mrioc->pdev = pdev;
+	mrioc->cpu_count = num_online_cpus();
+	r = mpi3mr_setup_resources(mrioc);
+	if (r) {
+		ioc_info(mrioc, "%s: Setup resoruces failed[%d]\n",
+		    __func__, r);
+		return r;
+	}
+
+	mrioc->stop_drv_processing = 0;
+	mpi3mr_init_ioc(mrioc, 1);
+	scsi_unblock_requests(shost);
+	mpi3mr_start_watchdog(mrioc);
+
+	return 0;
+}
+#endif
+
+
 static const struct pci_device_id mpi3mr_pci_id_table[] = {
 	{
 		PCI_DEVICE_SUB(PCI_VENDOR_ID_LSI_LOGIC, 0x00A5,
@@ -3495,6 +3576,10 @@ static struct pci_driver mpi3mr_pci_driver = {
 	.probe = mpi3mr_probe,
 	.remove = mpi3mr_remove,
 	.shutdown = mpi3mr_shutdown,
+#ifdef CONFIG_PM
+	.suspend = mpi3mr_suspend,
+	.resume = mpi3mr_resume,
+#endif
 };
 
 static int __init mpi3mr_init(void)
-- 
2.18.1


-- 
This electronic communication and the information and any files transmitted 
with it, or attached to it, are confidential and are intended solely for 
the use of the individual or entity to whom it is addressed and may contain 
information that is confidential, legally privileged, protected by privacy 
laws, or otherwise restricted from disclosure to anyone else. If you are 
not the intended recipient or the person responsible for delivering the 
e-mail to the intended recipient, you are hereby notified that any use, 
copying, distributing, dissemination, forwarding, printing, or copying of 
this e-mail is strictly prohibited. If you received this e-mail in error, 
please return the e-mail to the sender, delete it from your computer, and 
destroy any printed copy of it.

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4169 bytes --]

^ permalink raw reply related	[flat|nested] 75+ messages in thread

* [PATCH 22/24] mpi3mr: add support of DSN secure fw check
  2020-12-22 10:11 [PATCH 00/24] Introducing mpi3mr driver Kashyap Desai
                   ` (20 preceding siblings ...)
  2020-12-22 10:11 ` [PATCH 21/24] mpi3mr: add support of PM suspend and resume Kashyap Desai
@ 2020-12-22 10:11 ` Kashyap Desai
  2021-03-01  7:19   ` Hannes Reinecke
  2020-12-22 10:11 ` [PATCH 23/24] mpi3mr: add eedp dif dix support Kashyap Desai
                   ` (2 subsequent siblings)
  24 siblings, 1 reply; 75+ messages in thread
From: Kashyap Desai @ 2020-12-22 10:11 UTC (permalink / raw)
  To: linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, Kashyap Desai, sathya.prakash

[-- Attachment #1: Type: text/plain, Size: 5416 bytes --]

Read PCI_EXT_CAP_ID_DSN to know security status.

Driver will throw an warning message when a non-secure type controller
is detected. Purpose of this interface is to avoid interacting with
any firmware which is not secured/signed by Broadcom.
Any tampering on Firmware component will be detected by hardware
and it will be communicated to the driver to avoid any further
interaction with that component.

Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Cc: sathya.prakash@broadcom.com
---
 drivers/scsi/mpi3mr/mpi3mr.h    |  9 ++++
 drivers/scsi/mpi3mr/mpi3mr_os.c | 80 +++++++++++++++++++++++++++++++++
 2 files changed, 89 insertions(+)

diff --git a/drivers/scsi/mpi3mr/mpi3mr.h b/drivers/scsi/mpi3mr/mpi3mr.h
index 5554b0e49a58..f0ead83dc16c 100644
--- a/drivers/scsi/mpi3mr/mpi3mr.h
+++ b/drivers/scsi/mpi3mr/mpi3mr.h
@@ -149,6 +149,15 @@ extern struct list_head mrioc_list;
 #define MPI3MR_IRQ_POLL_SLEEP			2
 #define MPI3MR_IRQ_POLL_TRIGGER_IOCOUNT		8
 
+/* Definitions for the controller security status*/
+#define MPI3MR_CTLR_SECURITY_STATUS_MASK	0x0C
+#define MPI3MR_CTLR_SECURE_DBG_STATUS_MASK	0x02
+
+#define MPI3MR_INVALID_DEVICE			0x00
+#define MPI3MR_CONFIG_SECURE_DEVICE		0x04
+#define MPI3MR_HARD_SECURE_DEVICE		0x08
+#define MPI3MR_TAMPERED_DEVICE			0x0C
+
 /* SGE Flag definition */
 #define MPI3MR_SGEFLAGS_SYSTEM_SIMPLE_END_OF_LIST \
 	(MPI3_SGE_FLAGS_ELEMENT_TYPE_SIMPLE | MPI3_SGE_FLAGS_DLAS_SYSTEM | \
diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c
index ac47eed74705..57d9df6662f9 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_os.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_os.c
@@ -3277,6 +3277,75 @@ static inline void mpi3mr_init_drv_cmd(struct mpi3mr_drv_cmd *cmdptr,
 	cmdptr->host_tag = host_tag;
 }
 
+/**
+ * osintfc_mrioc_security_status -Check controller secure status
+ * @pdev: PCI device instance
+ *
+ * Read the Device Serial Number capability from PCI config
+ * space and decide whether the controller is secure or not.
+ *
+ * Return: 0 on success, non-zero on failure.
+ */
+static int
+osintfc_mrioc_security_status(struct pci_dev *pdev)
+{
+	u32 cap_data;
+	int base;
+	u32 ctlr_status;
+	u32 debug_status;
+	int retval = 0;
+
+	base = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_DSN);
+	if (!base) {
+		dev_err(&pdev->dev,
+		    "%s: PCI_EXT_CAP_ID_DSN is not supported\n", __func__);
+		return -1;
+	}
+
+	pci_read_config_dword(pdev, base + 4, &cap_data);
+
+	debug_status = cap_data & MPI3MR_CTLR_SECURE_DBG_STATUS_MASK;
+	ctlr_status = cap_data & MPI3MR_CTLR_SECURITY_STATUS_MASK;
+
+	switch (ctlr_status) {
+	case MPI3MR_INVALID_DEVICE:
+		dev_err(&pdev->dev,
+		    "%s: Non secure ctlr (Invalid) is detected: DID: 0x%x: SVID: 0x%x: SDID: 0x%x\n",
+		    __func__, pdev->device, pdev->subsystem_vendor,
+		    pdev->subsystem_device);
+		retval = -1;
+		break;
+	case MPI3MR_CONFIG_SECURE_DEVICE:
+		if (!debug_status)
+			dev_info(&pdev->dev,
+			    "%s: Config secure ctlr is detected\n",
+			    __func__);
+		break;
+	case MPI3MR_HARD_SECURE_DEVICE:
+		break;
+	case MPI3MR_TAMPERED_DEVICE:
+		dev_err(&pdev->dev,
+		    "%s: Non secure ctlr (Tampered) is detected: DID: 0x%x: SVID: 0x%x: SDID: 0x%x\n",
+		    __func__, pdev->device, pdev->subsystem_vendor,
+		    pdev->subsystem_device);
+		retval = -1;
+		break;
+	default:
+		retval = -1;
+			break;
+	}
+
+	if (!retval && debug_status) {
+		dev_err(&pdev->dev,
+		    "%s: Non secure ctlr (Secure Dbg) is detected: DID: 0x%x: SVID: 0x%x: SDID: 0x%x\n",
+		    __func__, pdev->device, pdev->subsystem_vendor,
+		    pdev->subsystem_device);
+		retval = -1;
+	}
+
+	return retval;
+}
+
 /**
  * mpi3mr_probe - PCI probe callback
  * @pdev: PCI device instance
@@ -3299,6 +3368,11 @@ mpi3mr_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	struct Scsi_Host *shost = NULL;
 	int retval = 0, i;
 
+	if (osintfc_mrioc_security_status(pdev)) {
+		warn_non_secure_ctlr = 1;
+		return 1; /* For Invalid and Tampered device */
+	}
+
 	shost = scsi_host_alloc(&mpi3mr_driver_template,
 	    sizeof(struct mpi3mr_ioc));
 	if (!shost) {
@@ -3415,6 +3489,9 @@ static void mpi3mr_remove(struct pci_dev *pdev)
 	unsigned long flags;
 	struct mpi3mr_tgt_dev *tgtdev, *tgtdev_next;
 
+	if (!shost)
+		return;
+
 	mrioc = shost_priv(shost);
 	while (mrioc->reset_in_progress || mrioc->is_driver_loading)
 		ssleep(1);
@@ -3535,6 +3612,9 @@ static int mpi3mr_resume(struct pci_dev *pdev)
 	pci_power_t device_state = pdev->current_state;
 	int r;
 
+	if (!shost)
+		return 0;
+
 	mrioc = shost_priv(shost);
 
 	ioc_info(mrioc, "pdev=0x%p, slot=%s, previous operating state [D%d]\n",
-- 
2.18.1


-- 
This electronic communication and the information and any files transmitted 
with it, or attached to it, are confidential and are intended solely for 
the use of the individual or entity to whom it is addressed and may contain 
information that is confidential, legally privileged, protected by privacy 
laws, or otherwise restricted from disclosure to anyone else. If you are 
not the intended recipient or the person responsible for delivering the 
e-mail to the intended recipient, you are hereby notified that any use, 
copying, distributing, dissemination, forwarding, printing, or copying of 
this e-mail is strictly prohibited. If you received this e-mail in error, 
please return the e-mail to the sender, delete it from your computer, and 
destroy any printed copy of it.

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4169 bytes --]

^ permalink raw reply related	[flat|nested] 75+ messages in thread

* [PATCH 23/24] mpi3mr: add eedp dif dix support
  2020-12-22 10:11 [PATCH 00/24] Introducing mpi3mr driver Kashyap Desai
                   ` (21 preceding siblings ...)
  2020-12-22 10:11 ` [PATCH 22/24] mpi3mr: add support of DSN secure fw check Kashyap Desai
@ 2020-12-22 10:11 ` Kashyap Desai
  2021-02-22 15:37   ` Tomas Henzl
  2021-03-01  7:20   ` Hannes Reinecke
  2020-12-22 10:11 ` [PATCH 24/24] mpi3mr: add event handling debug prints Kashyap Desai
  2021-02-22 15:39 ` [PATCH 00/24] Introducing mpi3mr driver Tomas Henzl
  24 siblings, 2 replies; 75+ messages in thread
From: Kashyap Desai @ 2020-12-22 10:11 UTC (permalink / raw)
  To: linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, Kashyap Desai, sathya.prakash

[-- Attachment #1: Type: text/plain, Size: 17093 bytes --]

Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Cc: sathya.prakash@broadcom.com
---
 drivers/scsi/mpi3mr/mpi3mr.h    |  18 +-
 drivers/scsi/mpi3mr/mpi3mr_fw.c |   7 +
 drivers/scsi/mpi3mr/mpi3mr_os.c | 303 +++++++++++++++++++++++++++++++-
 3 files changed, 321 insertions(+), 7 deletions(-)

diff --git a/drivers/scsi/mpi3mr/mpi3mr.h b/drivers/scsi/mpi3mr/mpi3mr.h
index f0ead83dc16c..acc5649bed5f 100644
--- a/drivers/scsi/mpi3mr/mpi3mr.h
+++ b/drivers/scsi/mpi3mr/mpi3mr.h
@@ -118,6 +118,7 @@ extern struct list_head mrioc_list;
 #define MPI3MR_SENSEBUF_SZ	256
 #define MPI3MR_SENSEBUF_FACTOR	3
 #define MPI3MR_CHAINBUF_FACTOR	3
+#define MPI3MR_CHAINBUFDIX_FACTOR	2
 
 /* Invalid target device handle */
 #define MPI3MR_INVALID_DEV_HANDLE	0xFFFF
@@ -145,6 +146,15 @@ extern struct list_head mrioc_list;
 /* Default target device queue depth */
 #define MPI3MR_DEFAULT_SDEV_QD	32
 
+/* Definitions for the sector size for EEDP */
+#define MPI3_SECTOR_SIZE_512_BYTE	(512)
+#define MPI3_SECTOR_SIZE_520_BYTE	(520)
+#define MPI3_SECTOR_SIZE_4080_BYTE	(4080)
+#define MPI3_SECTOR_SIZE_4088_BYTE	(4088)
+#define MPI3_SECTOR_SIZE_4096_BYTE	(4096)
+#define MPI3_SECTOR_SIZE_4104_BYTE	(4104)
+#define MPI3_SECTOR_SIZE_4160_BYTE	(4160)
+
 /* Definitions for Threaded IRQ poll*/
 #define MPI3MR_IRQ_POLL_SLEEP			2
 #define MPI3MR_IRQ_POLL_TRIGGER_IOCOUNT		8
@@ -559,17 +569,21 @@ struct chain_element {
  *
  * @host_tag: Host tag specific to operational queue
  * @in_lld_scope: Command in LLD scope or not
+ * @meta_sg_valid: DIX command with meta data SGL or not
  * @scmd: SCSI Command pointer
- * @req_q_idx: Operational request queue index
+ * @req_q_idx: Operational request queue undex
  * @chain_idx: Chain frame index
+ * @meta_chain_idx: Chain frame index of meta data SGL
  * @mpi3mr_scsiio_req: MPI SCSI IO request
  */
-struct scmd_priv {
+struct scmd_priv{
 	u16 host_tag;
 	u8 in_lld_scope;
+	u8 meta_sg_valid;
 	struct scsi_cmnd *scmd;
 	u16 req_q_idx;
 	int chain_idx;
+	int meta_chain_idx;
 	u8 mpi3mr_scsiio_req[MPI3MR_ADMIN_REQ_FRAME_SZ];
 };
 
diff --git a/drivers/scsi/mpi3mr/mpi3mr_fw.c b/drivers/scsi/mpi3mr/mpi3mr_fw.c
index b27e44f78544..8ce715b139f2 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_fw.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_fw.c
@@ -8,6 +8,7 @@
  */
 
 #include "mpi3mr.h"
+extern int prot_mask;
 
 #if defined(writeq) && defined(CONFIG_64BIT)
 static inline void mpi3mr_writeq(__u64 b, volatile void __iomem *addr)
@@ -2759,6 +2760,12 @@ static int mpi3mr_alloc_chain_bufs(struct mpi3mr_ioc *mrioc)
 
 	num_chains = mrioc->max_host_ios/MPI3MR_CHAINBUF_FACTOR;
 
+	if (prot_mask & (SHOST_DIX_TYPE0_PROTECTION
+	    | SHOST_DIX_TYPE1_PROTECTION
+	    | SHOST_DIX_TYPE2_PROTECTION
+	    | SHOST_DIX_TYPE3_PROTECTION))
+		num_chains += (num_chains / MPI3MR_CHAINBUFDIX_FACTOR);
+
 	mrioc->chain_buf_count = num_chains;
 	sz = sizeof(struct chain_element) * num_chains;
 	mrioc->chain_sgl_list = kzalloc(sz, GFP_KERNEL);
diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c
index 57d9df6662f9..425659e8f7b4 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_os.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_os.c
@@ -21,6 +21,13 @@ MODULE_LICENSE(MPI3MR_DRIVER_LICENSE);
 MODULE_VERSION(MPI3MR_DRIVER_VERSION);
 
 /* Module parameters*/
+int prot_mask = -1;
+module_param(prot_mask, int, 0);
+MODULE_PARM_DESC(prot_mask, "Host protection capabilities mask, def=0x07");
+
+int prot_guard_mask = 3;
+module_param(prot_guard_mask, int, 0);
+MODULE_PARM_DESC(prot_guard_mask, " Host protection guard mask, def=3");
 int logging_level;
 module_param(logging_level, int, 0);
 MODULE_PARM_DESC(logging_level,
@@ -59,7 +66,9 @@ static u16 mpi3mr_host_tag_for_scmd(struct mpi3mr_ioc *mrioc,
 	priv->scmd = scmd;
 	priv->in_lld_scope = 1;
 	priv->req_q_idx = hw_queue;
+	priv->meta_chain_idx = -1;
 	priv->chain_idx = -1;
+	priv->meta_sg_valid = 0;
 	return priv->host_tag;
 }
 
@@ -119,10 +128,15 @@ static void mpi3mr_clear_scmd_priv(struct mpi3mr_ioc *mrioc,
 	priv->req_q_idx = 0xFFFF;
 	priv->scmd = NULL;
 	priv->in_lld_scope = 0;
+	priv->meta_sg_valid = 0;
 	if (priv->chain_idx >= 0) {
 		clear_bit(priv->chain_idx, mrioc->chain_bitmap);
 		priv->chain_idx = -1;
 	}
+	if (priv->meta_chain_idx >= 0) {
+		clear_bit(priv->meta_chain_idx, mrioc->chain_bitmap);
+		priv->meta_chain_idx = -1;
+	}
 }
 
 static void mpi3mr_dev_rmhs_send_tm(struct mpi3mr_ioc *mrioc, u16 handle,
@@ -388,6 +402,9 @@ static bool mpi3mr_flush_scmd(struct request *rq,
 		if (!priv->in_lld_scope)
 			goto out;
 
+		if (priv->meta_sg_valid)
+			dma_unmap_sg(&mrioc->pdev->dev, scsi_prot_sglist(scmd),
+			    scsi_prot_sg_count(scmd), scmd->sc_data_direction);
 		mpi3mr_clear_scmd_priv(mrioc, scmd);
 		scsi_dma_unmap(scmd);
 		scmd->result = DID_RESET << 16;
@@ -790,6 +807,7 @@ static void mpi3mr_update_tgtdev(struct mpi3mr_ioc *mrioc,
 {
 	u16 flags = 0;
 	struct mpi3mr_stgt_priv_data *scsi_tgt_priv_data;
+	u8 prot_mask = 0;
 
 	tgtdev->perst_id = le16_to_cpu(dev_pg0->PersistentID);
 	tgtdev->dev_handle = le16_to_cpu(dev_pg0->DevHandle);
@@ -854,6 +872,15 @@ static void mpi3mr_update_tgtdev(struct mpi3mr_ioc *mrioc,
 		if ((dev_info & MPI3_DEVICE0_PCIE_DEVICE_INFO_TYPE_MASK) !=
 		    MPI3_DEVICE0_PCIE_DEVICE_INFO_TYPE_NVME_DEVICE)
 			tgtdev->is_hidden = 1;
+		if (mrioc->shost)
+			prot_mask = scsi_host_get_prot(mrioc->shost);
+		if (prot_mask & SHOST_DIX_TYPE0_PROTECTION) {
+			scsi_host_set_prot(mrioc->shost, prot_mask & 0x77);
+			ioc_info(mrioc,
+			    "%s : Disabling DIX0 prot capability\n", __func__);
+			ioc_info(mrioc,
+			    "because HBA does not support DIX0 operation on NVME drives\n");
+		}
 		break;
 	}
 	case MPI3_DEVICE_DEVFORM_VD:
@@ -1771,6 +1798,195 @@ void mpi3mr_os_handle_events(struct mpi3mr_ioc *mrioc,
 
 }
 
+/**
+ * mpi3mr_setup_eedp - Setup EEDP information in MPI3 SCSI IO
+ * @mrioc: Adapter instance reference
+ * @scmd: SCSI command reference
+ * @scsiio_req: MPI3 SCSI IO request
+ *
+ * Identifies the protection information flags from the SCSI
+ * command and set appropriate flags in the MPI3 SCSI IO
+ * request.
+ *
+ * Return: Nothing
+ */
+static void mpi3mr_setup_eedp(struct mpi3mr_ioc *mrioc,
+	struct scsi_cmnd *scmd, Mpi3SCSIIORequest_t *scsiio_req)
+{
+	u16 eedp_flags = 0;
+	unsigned char prot_op = scsi_get_prot_op(scmd);
+	unsigned char prot_type = scsi_get_prot_type(scmd);
+
+	switch (prot_op) {
+	case SCSI_PROT_NORMAL:
+		return;
+	case SCSI_PROT_READ_STRIP:
+		eedp_flags = MPI3_EEDPFLAGS_EEDP_OP_CHECK_REMOVE;
+		break;
+	case SCSI_PROT_WRITE_INSERT:
+		eedp_flags = MPI3_EEDPFLAGS_EEDP_OP_INSERT;
+		break;
+	case SCSI_PROT_READ_INSERT:
+		eedp_flags = MPI3_EEDPFLAGS_EEDP_OP_INSERT;
+		scsiio_req->MsgFlags |= MPI3_SCSIIO_MSGFLAGS_METASGL_VALID;
+		break;
+	case SCSI_PROT_WRITE_STRIP:
+		eedp_flags = MPI3_EEDPFLAGS_EEDP_OP_CHECK_REMOVE;
+		scsiio_req->MsgFlags |= MPI3_SCSIIO_MSGFLAGS_METASGL_VALID;
+		break;
+	case SCSI_PROT_READ_PASS:
+		eedp_flags = MPI3_EEDPFLAGS_EEDP_OP_CHECK |
+		    MPI3_EEDPFLAGS_CHK_REF_TAG | MPI3_EEDPFLAGS_CHK_APP_TAG |
+		    MPI3_EEDPFLAGS_CHK_GUARD;
+		scsiio_req->MsgFlags |= MPI3_SCSIIO_MSGFLAGS_METASGL_VALID;
+		break;
+	case SCSI_PROT_WRITE_PASS:
+		if (scsi_host_get_guard(scmd->device->host)
+		    & SHOST_DIX_GUARD_IP) {
+			eedp_flags = MPI3_EEDPFLAGS_EEDP_OP_CHECK_REGEN |
+			    MPI3_EEDPFLAGS_CHK_APP_TAG |
+			    MPI3_EEDPFLAGS_CHK_GUARD |
+			    MPI3_EEDPFLAGS_INCR_PRI_REF_TAG;
+			scsiio_req->SGL[0].Eedp.ApplicationTagTranslationMask
+			    = 0xffff;
+		} else {
+			eedp_flags = MPI3_EEDPFLAGS_EEDP_OP_CHECK |
+			    MPI3_EEDPFLAGS_CHK_REF_TAG |
+			    MPI3_EEDPFLAGS_CHK_APP_TAG |
+			    MPI3_EEDPFLAGS_CHK_GUARD;
+		}
+		scsiio_req->MsgFlags |= MPI3_SCSIIO_MSGFLAGS_METASGL_VALID;
+		break;
+	default:
+		return;
+	}
+
+	if (scsi_host_get_guard(scmd->device->host) & SHOST_DIX_GUARD_IP)
+		eedp_flags |= MPI3_EEDPFLAGS_HOST_GUARD_IP_CHKSUM;
+
+	switch (prot_type) {
+	case SCSI_PROT_DIF_TYPE0:
+		eedp_flags |= MPI3_EEDPFLAGS_INCR_PRI_REF_TAG;
+		scsiio_req->CDB.EEDP32.PrimaryReferenceTag =
+		    cpu_to_be32(t10_pi_ref_tag(scmd->request));
+		break;
+	case SCSI_PROT_DIF_TYPE1:
+	case SCSI_PROT_DIF_TYPE2:
+		eedp_flags |= MPI3_EEDPFLAGS_INCR_PRI_REF_TAG |
+		    MPI3_EEDPFLAGS_ESC_MODE_APPTAG_DISABLE |
+		    MPI3_EEDPFLAGS_CHK_GUARD;
+		scsiio_req->CDB.EEDP32.PrimaryReferenceTag =
+		    cpu_to_be32(t10_pi_ref_tag(scmd->request));
+		break;
+	case SCSI_PROT_DIF_TYPE3:
+		eedp_flags |= MPI3_EEDPFLAGS_CHK_GUARD |
+		    MPI3_EEDPFLAGS_ESC_MODE_APPTAG_DISABLE;
+		break;
+
+	default:
+		scsiio_req->MsgFlags &= ~(MPI3_SCSIIO_MSGFLAGS_METASGL_VALID);
+		return;
+	}
+
+	switch (scmd->device->sector_size) {
+	case MPI3_SECTOR_SIZE_512_BYTE:
+		scsiio_req->SGL[0].Eedp.UserDataSize = MPI3_EEDP_UDS_512;
+		break;
+	case MPI3_SECTOR_SIZE_520_BYTE:
+		scsiio_req->SGL[0].Eedp.UserDataSize = MPI3_EEDP_UDS_520;
+		break;
+	case MPI3_SECTOR_SIZE_4080_BYTE:
+		scsiio_req->SGL[0].Eedp.UserDataSize = MPI3_EEDP_UDS_4080;
+		break;
+	case MPI3_SECTOR_SIZE_4088_BYTE:
+		scsiio_req->SGL[0].Eedp.UserDataSize = MPI3_EEDP_UDS_4088;
+		break;
+	case MPI3_SECTOR_SIZE_4096_BYTE:
+		scsiio_req->SGL[0].Eedp.UserDataSize = MPI3_EEDP_UDS_4096;
+		break;
+	case MPI3_SECTOR_SIZE_4104_BYTE:
+		scsiio_req->SGL[0].Eedp.UserDataSize = MPI3_EEDP_UDS_4104;
+		break;
+	case MPI3_SECTOR_SIZE_4160_BYTE:
+		scsiio_req->SGL[0].Eedp.UserDataSize = MPI3_EEDP_UDS_4160;
+		break;
+	default:
+		break;
+	}
+
+	scsiio_req->SGL[0].Eedp.EEDPFlags = cpu_to_le16(eedp_flags);
+	scsiio_req->SGL[0].Eedp.Flags = MPI3_SGE_FLAGS_ELEMENT_TYPE_EXTENDED;
+}
+
+
+
+/**
+ * mpi3mr_build_sense_buffer - Map sense information
+ * @desc: Sense type
+ * @buf: Sense buffer to populate
+ * @key: Sense key
+ * @asc: Additional sense code
+ * @ascq: Additional sense code qualifier
+ *
+ * Maps the given sense information into either descriptor or
+ * fixed format sense data.
+ *
+ * Return: Nothing
+ */
+static inline void mpi3mr_build_sense_buffer(int desc, u8 *buf, u8 key,
+	u8 asc, u8 ascq)
+{
+	if (desc) {
+		buf[0] = 0x72;	/* descriptor, current */
+		buf[1] = key;
+		buf[2] = asc;
+		buf[3] = ascq;
+		buf[7] = 0;
+	} else {
+		buf[0] = 0x70;	/* fixed, current */
+		buf[2] = key;
+		buf[7] = 0xa;
+		buf[12] = asc;
+		buf[13] = ascq;
+	}
+}
+
+/**
+ * mpi3mr_map_eedp_error - Map EEDP errors from IOC status
+ * @scmd: SCSI command reference
+ * @ioc_status: Status of MPI3 request
+ *
+ * Maps the EEDP error status of the SCSI IO request to sense
+ * data.
+ *
+ * Return: Nothing
+ */
+static void mpi3mr_map_eedp_error(struct scsi_cmnd *scmd,
+	u16 ioc_status)
+{
+	u8 ascq = 0;
+
+	switch (ioc_status) {
+	case MPI3_IOCSTATUS_EEDP_GUARD_ERROR:
+		ascq = 0x01;
+		break;
+	case MPI3_IOCSTATUS_EEDP_APP_TAG_ERROR:
+		ascq = 0x02;
+		break;
+	case MPI3_IOCSTATUS_EEDP_REF_TAG_ERROR:
+		ascq = 0x03;
+		break;
+	default:
+		ascq = 0x00;
+		break;
+	}
+
+	mpi3mr_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST,
+	    0x10, ascq);
+	scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) |
+	    SAM_STAT_CHECK_CONDITION;
+}
+
 /**
  * mpi3mr_process_op_reply_desc - reply descriptor handler
  * @mrioc: Adapter instance reference
@@ -1933,6 +2149,11 @@ void mpi3mr_process_op_reply_desc(struct mpi3mr_ioc *mrioc,
 		else if (scsi_state & MPI3_SCSI_STATE_TERMINATED)
 			scmd->result = DID_RESET << 16;
 		break;
+	case MPI3_IOCSTATUS_EEDP_GUARD_ERROR:
+	case MPI3_IOCSTATUS_EEDP_REF_TAG_ERROR:
+	case MPI3_IOCSTATUS_EEDP_APP_TAG_ERROR:
+		mpi3mr_map_eedp_error(scmd, ioc_status);
+		break;
 	case MPI3_IOCSTATUS_SCSI_PROTOCOL_ERROR:
 	case MPI3_IOCSTATUS_INVALID_FUNCTION:
 	case MPI3_IOCSTATUS_INVALID_SGL:
@@ -1968,6 +2189,10 @@ void mpi3mr_process_op_reply_desc(struct mpi3mr_ioc *mrioc,
 		}
 	}
 out_success:
+	if (priv->meta_sg_valid) {
+		dma_unmap_sg(&mrioc->pdev->dev, scsi_prot_sglist(scmd),
+		    scsi_prot_sg_count(scmd), scmd->sc_data_direction);
+	}
 	mpi3mr_clear_scmd_priv(mrioc, scmd);
 	scsi_dma_unmap(scmd);
 	scmd->scsi_done(scmd);
@@ -2031,6 +2256,8 @@ static int mpi3mr_prepare_sg_scmd(struct mpi3mr_ioc *mrioc,
 	u8 last_chain_sgl_flags;
 	struct chain_element *chain_req;
 	struct scmd_priv *priv = NULL;
+	u32 meta_sg = le32_to_cpu(scsiio_req->Flags) &
+	    MPI3_SCSIIO_FLAGS_DMAOPERATION_HOST_PI;
 
 	priv = scsi_cmd_priv(scmd);
 
@@ -2041,15 +2268,27 @@ static int mpi3mr_prepare_sg_scmd(struct mpi3mr_ioc *mrioc,
 	last_chain_sgl_flags = MPI3_SGE_FLAGS_ELEMENT_TYPE_LAST_CHAIN |
 	    MPI3_SGE_FLAGS_DLAS_SYSTEM;
 
-	sg_local = &scsiio_req->SGL;
+	if (meta_sg)
+		sg_local = &scsiio_req->SGL[MPI3_SCSIIO_METASGL_INDEX];
+	else
+		sg_local = &scsiio_req->SGL;
 
-	if (!scsiio_req->DataLength) {
+	if (!scsiio_req->DataLength && !meta_sg) {
 		mpi3mr_build_zero_len_sge(sg_local);
 		return 0;
 	}
 
-	sg_scmd = scsi_sglist(scmd);
-	sges_left = scsi_dma_map(scmd);
+	if (meta_sg) {
+		sg_scmd = scsi_prot_sglist(scmd);
+		sges_left = dma_map_sg(&mrioc->pdev->dev,
+		    scsi_prot_sglist(scmd),
+		    scsi_prot_sg_count(scmd),
+		    scmd->sc_data_direction);
+		priv->meta_sg_valid = 1; /* To unmap meta sg DMA */
+	} else {
+		sg_scmd = scsi_sglist(scmd);
+		sges_left = scsi_dma_map(scmd);
+	}
 
 	if (sges_left < 0) {
 		sdev_printk(KERN_ERR, scmd->device,
@@ -2067,6 +2306,22 @@ static int mpi3mr_prepare_sg_scmd(struct mpi3mr_ioc *mrioc,
 	sges_in_segment = (mrioc->facts.op_req_sz -
 	    offsetof(Mpi3SCSIIORequest_t, SGL))/sizeof(Mpi3SGESimple_t);
 
+	if (scsiio_req->SGL[0].Eedp.Flags ==
+	    MPI3_SGE_FLAGS_ELEMENT_TYPE_EXTENDED && !meta_sg) {
+		sg_local += sizeof(Mpi3SGEUnion_t);
+		sges_in_segment--;
+		/* Reserve 1st segment (scsiio_req->SGL[0]) for eedp */
+	}
+
+	if (scsiio_req->MsgFlags ==
+	    MPI3_SCSIIO_MSGFLAGS_METASGL_VALID && !meta_sg) {
+		sges_in_segment--;
+		/* Reserve last segment (scsiio_req->SGL[3]) for meta sg */
+	}
+
+	if (meta_sg)
+		sges_in_segment = 1;
+
 	if (sges_left <= sges_in_segment)
 		goto fill_in_last_segment;
 
@@ -2084,7 +2339,10 @@ static int mpi3mr_prepare_sg_scmd(struct mpi3mr_ioc *mrioc,
 	if (chain_idx < 0)
 		return -1;
 	chain_req = &mrioc->chain_sgl_list[chain_idx];
-	priv->chain_idx = chain_idx;
+	if (meta_sg)
+		priv->meta_chain_idx = chain_idx;
+	else
+		priv->chain_idx = chain_idx;
 
 	chain = chain_req->addr;
 	chain_dma = chain_req->dma_addr;
@@ -2134,6 +2392,13 @@ static int mpi3mr_build_sg_scmd(struct mpi3mr_ioc *mrioc,
 	if (ret)
 		return ret;
 
+	if (scsiio_req->MsgFlags == MPI3_SCSIIO_MSGFLAGS_METASGL_VALID) {
+		/* There is a valid meta sg */
+		scsiio_req->Flags |=
+		    cpu_to_le32(MPI3_SCSIIO_FLAGS_DMAOPERATION_HOST_PI);
+		ret = mpi3mr_prepare_sg_scmd(mrioc, scmd, scsiio_req);
+	}
+
 	return ret;
 }
 
@@ -3200,6 +3465,8 @@ static int mpi3mr_qcmd(struct Scsi_Host *shost,
 	scsiio_req->Function = MPI3_FUNCTION_SCSI_IO;
 	scsiio_req->HostTag = cpu_to_le16(host_tag);
 
+	mpi3mr_setup_eedp(mrioc, scmd, scsiio_req);
+
 	memcpy(scsiio_req->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
 	scsiio_req->DataLength = cpu_to_le32(scsi_bufflen(scmd));
 	scsiio_req->DevHandle = cpu_to_le16(dev_handle);
@@ -3425,6 +3692,32 @@ mpi3mr_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	shost->max_channel = 1;
 	shost->max_id = 0xFFFFFFFF;
 
+	if (prot_mask >= 0)
+		scsi_host_set_prot(shost, prot_mask);
+	else {
+		prot_mask = SHOST_DIF_TYPE1_PROTECTION
+		    | SHOST_DIF_TYPE2_PROTECTION
+		    | SHOST_DIF_TYPE3_PROTECTION;
+		scsi_host_set_prot(shost, prot_mask);
+
+	}
+
+	ioc_info(mrioc,
+	    "%s :host protection capabilities enabled %s%s%s%s%s%s%s\n",
+	    __func__,
+	    (prot_mask & SHOST_DIF_TYPE1_PROTECTION) ? " DIF1" : "",
+	    (prot_mask & SHOST_DIF_TYPE2_PROTECTION) ? " DIF2" : "",
+	    (prot_mask & SHOST_DIF_TYPE3_PROTECTION) ? " DIF3" : "",
+	    (prot_mask & SHOST_DIX_TYPE0_PROTECTION) ? " DIX0" : "",
+	    (prot_mask & SHOST_DIX_TYPE1_PROTECTION) ? " DIX1" : "",
+	    (prot_mask & SHOST_DIX_TYPE2_PROTECTION) ? " DIX2" : "",
+	    (prot_mask & SHOST_DIX_TYPE3_PROTECTION) ? " DIX3" : "");
+
+	if (prot_guard_mask)
+		scsi_host_set_guard(shost, (prot_guard_mask & 3));
+	else
+		scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
+
 	snprintf(mrioc->fwevt_worker_name, sizeof(mrioc->fwevt_worker_name),
 	    "%s%d_fwevt_wrkr", mrioc->driver_name, mrioc->id);
 	mrioc->fwevt_worker_thread = alloc_ordered_workqueue(
-- 
2.18.1


-- 
This electronic communication and the information and any files transmitted 
with it, or attached to it, are confidential and are intended solely for 
the use of the individual or entity to whom it is addressed and may contain 
information that is confidential, legally privileged, protected by privacy 
laws, or otherwise restricted from disclosure to anyone else. If you are 
not the intended recipient or the person responsible for delivering the 
e-mail to the intended recipient, you are hereby notified that any use, 
copying, distributing, dissemination, forwarding, printing, or copying of 
this e-mail is strictly prohibited. If you received this e-mail in error, 
please return the e-mail to the sender, delete it from your computer, and 
destroy any printed copy of it.

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4169 bytes --]

^ permalink raw reply related	[flat|nested] 75+ messages in thread

* [PATCH 24/24] mpi3mr: add event handling debug prints
  2020-12-22 10:11 [PATCH 00/24] Introducing mpi3mr driver Kashyap Desai
                   ` (22 preceding siblings ...)
  2020-12-22 10:11 ` [PATCH 23/24] mpi3mr: add eedp dif dix support Kashyap Desai
@ 2020-12-22 10:11 ` Kashyap Desai
  2021-03-01  7:20   ` Hannes Reinecke
  2021-02-22 15:39 ` [PATCH 00/24] Introducing mpi3mr driver Tomas Henzl
  24 siblings, 1 reply; 75+ messages in thread
From: Kashyap Desai @ 2020-12-22 10:11 UTC (permalink / raw)
  To: linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, Kashyap Desai, sathya.prakash

[-- Attachment #1: Type: text/plain, Size: 11420 bytes --]

Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Cc: sathya.prakash@broadcom.com
---
 drivers/scsi/mpi3mr/mpi3mr_fw.c | 119 +++++++++++++++++++++++
 drivers/scsi/mpi3mr/mpi3mr_os.c | 164 ++++++++++++++++++++++++++++++++
 2 files changed, 283 insertions(+)

diff --git a/drivers/scsi/mpi3mr/mpi3mr_fw.c b/drivers/scsi/mpi3mr/mpi3mr_fw.c
index 8ce715b139f2..283444901034 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_fw.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_fw.c
@@ -154,6 +154,124 @@ void mpi3mr_repost_sense_buf(struct mpi3mr_ioc *mrioc,
 	spin_unlock(&mrioc->sbq_lock);
 }
 
+
+static void mpi3mr_print_event_data(struct mpi3mr_ioc *mrioc,
+	Mpi3EventNotificationReply_t *event_reply)
+{
+	char *desc = NULL;
+	u16 event;
+
+	event = event_reply->Event;
+
+	switch (event) {
+	case MPI3_EVENT_LOG_DATA:
+		desc = "Log Data";
+		break;
+	case MPI3_EVENT_CHANGE:
+		desc = "Event Change";
+		break;
+	case MPI3_EVENT_GPIO_INTERRUPT:
+		desc = "GPIO Interrupt";
+		break;
+	case MPI3_EVENT_TEMP_THRESHOLD:
+		desc = "Temperature Threshold";
+		break;
+	case MPI3_EVENT_CABLE_MGMT:
+		desc = "Cable Management";
+		break;
+	case MPI3_EVENT_ENERGY_PACK_CHANGE:
+		desc = "Energy Pack Change";
+		break;
+	case MPI3_EVENT_DEVICE_ADDED:
+	{
+		Mpi3DevicePage0_t *event_data =
+		    (Mpi3DevicePage0_t *)event_reply->EventData;
+		ioc_info(mrioc, "Device Added: Dev=0x%04x Form=0x%x\n",
+		    event_data->DevHandle, event_data->DeviceForm);
+		return;
+	}
+	case MPI3_EVENT_DEVICE_INFO_CHANGED:
+	{
+		Mpi3DevicePage0_t *event_data =
+		    (Mpi3DevicePage0_t *)event_reply->EventData;
+		ioc_info(mrioc, "Device Info Changed: Dev=0x%04x Form=0x%x\n",
+		    event_data->DevHandle, event_data->DeviceForm);
+		return;
+	}
+	case MPI3_EVENT_DEVICE_STATUS_CHANGE:
+	{
+		Mpi3EventDataDeviceStatusChange_t *event_data =
+		    (Mpi3EventDataDeviceStatusChange_t *)event_reply->EventData;
+		ioc_info(mrioc, "Device Status Change: Dev=0x%04x RC=0x%x\n",
+		    event_data->DevHandle, event_data->ReasonCode);
+		return;
+	}
+	case MPI3_EVENT_SAS_DISCOVERY:
+	{
+		Mpi3EventDataSasDiscovery_t *event_data =
+		    (Mpi3EventDataSasDiscovery_t *)event_reply->EventData;
+		ioc_info(mrioc, "SAS Discovery: (%s)",
+		    (event_data->ReasonCode == MPI3_EVENT_SAS_DISC_RC_STARTED) ?
+		    "start" : "stop");
+		if (event_data->DiscoveryStatus)
+			pr_cont("discovery_status(0x%08x)",
+			    le32_to_cpu(event_data->DiscoveryStatus));
+		pr_cont("\n");
+		return;
+	}
+	case MPI3_EVENT_SAS_BROADCAST_PRIMITIVE:
+		desc = "SAS Broadcast Primitive";
+		break;
+	case MPI3_EVENT_SAS_NOTIFY_PRIMITIVE:
+		desc = "SAS Notify Primitive";
+		break;
+	case MPI3_EVENT_SAS_INIT_DEVICE_STATUS_CHANGE:
+		desc = "SAS Init Device Status Change";
+		break;
+	case MPI3_EVENT_SAS_INIT_TABLE_OVERFLOW:
+		desc = "SAS Init Table Overflow";
+		break;
+	case MPI3_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
+		desc = "SAS Topology Change List";
+		break;
+	case MPI3_EVENT_ENCL_DEVICE_STATUS_CHANGE:
+		desc = "Enclosure Device Status Change";
+		break;
+	case MPI3_EVENT_HARD_RESET_RECEIVED:
+		desc = "Hard Reset Received";
+		break;
+	case MPI3_EVENT_SAS_PHY_COUNTER:
+		desc = "SAS PHY Counter";
+		break;
+	case MPI3_EVENT_SAS_DEVICE_DISCOVERY_ERROR:
+		desc = "SAS Device Discovery Error";
+		break;
+	case MPI3_EVENT_PCIE_TOPOLOGY_CHANGE_LIST:
+		desc = "PCIE Topology Change List";
+		break;
+	case MPI3_EVENT_PCIE_ENUMERATION:
+	{
+		Mpi3EventDataPcieEnumeration_t *event_data =
+		    (Mpi3EventDataPcieEnumeration_t *)event_reply->EventData;
+		ioc_info(mrioc, "PCIE Enumeration: (%s)",
+		    (event_data->ReasonCode ==
+		    MPI3_EVENT_PCIE_ENUM_RC_STARTED) ? "start" : "stop");
+		if (event_data->EnumerationStatus)
+			ioc_info(mrioc, "enumeration_status(0x%08x)\n",
+			    le32_to_cpu(event_data->EnumerationStatus));
+		return;
+	}
+	case MPI3_EVENT_PREPARE_FOR_RESET:
+		desc = "Prepare For Reset";
+		break;
+	}
+
+	if (!desc)
+		return;
+
+	ioc_info(mrioc, "%s\n", desc);
+}
+
 static void mpi3mr_handle_events(struct mpi3mr_ioc *mrioc,
 	Mpi3DefaultReply_t *def_reply)
 {
@@ -161,6 +279,7 @@ static void mpi3mr_handle_events(struct mpi3mr_ioc *mrioc,
 	    (Mpi3EventNotificationReply_t *)def_reply;
 
 	mrioc->change_count = le16_to_cpu(event_reply->IOCChangeCount);
+	mpi3mr_print_event_data(mrioc, event_reply);
 	mpi3mr_os_handle_events(mrioc, event_reply);
 }
 
diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c
index 425659e8f7b4..f744c4980b6e 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_os.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_os.c
@@ -1006,6 +1006,85 @@ static void mpi3mr_devinfochg_evt_bh(struct mpi3mr_ioc *mrioc,
 
 }
 
+/**
+ * mpi3mr_sastopochg_evt_debug - SASTopoChange details
+ * @mrioc: Adapter instance reference
+ * @event_data: SAS topology change list event data
+ *
+ * Prints information about the SAS topology change event.
+ *
+ * Return: Nothing.
+ */
+static void
+mpi3mr_sastopochg_evt_debug(struct mpi3mr_ioc *mrioc,
+	Mpi3EventDataSasTopologyChangeList_t *event_data)
+{
+	int i;
+	u16 handle;
+	u8 reason_code, phy_number;
+	char *status_str = NULL;
+	u8 link_rate, prev_link_rate;
+
+	switch (event_data->ExpStatus) {
+	case MPI3_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
+		status_str = "remove";
+		break;
+	case MPI3_EVENT_SAS_TOPO_ES_RESPONDING:
+		status_str =  "responding";
+		break;
+	case MPI3_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
+		status_str = "remove delay";
+		break;
+	case MPI3_EVENT_SAS_TOPO_ES_NO_EXPANDER:
+		status_str = "direct attached";
+		break;
+	default:
+		status_str = "unknown status";
+		break;
+	}
+	ioc_info(mrioc, "%s :sas topology change: (%s)\n",
+	    __func__, status_str);
+	ioc_info(mrioc,
+	    "%s :\texpander_handle(0x%04x), enclosure_handle(0x%04x) start_phy(%02d), num_entries(%d)\n",
+	    __func__, le16_to_cpu(event_data->ExpanderDevHandle),
+	    le16_to_cpu(event_data->EnclosureHandle),
+	    event_data->StartPhyNum, event_data->NumEntries);
+	for (i = 0; i < event_data->NumEntries; i++) {
+		handle = le16_to_cpu(event_data->PhyEntry[i].AttachedDevHandle);
+		if (!handle)
+			continue;
+		phy_number = event_data->StartPhyNum + i;
+		reason_code = event_data->PhyEntry[i].Status &
+		    MPI3_EVENT_SAS_TOPO_PHY_RC_MASK;
+		switch (reason_code) {
+		case MPI3_EVENT_SAS_TOPO_PHY_RC_TARG_NOT_RESPONDING:
+			status_str = "target remove";
+			break;
+		case MPI3_EVENT_SAS_TOPO_PHY_RC_DELAY_NOT_RESPONDING:
+			status_str = "delay target remove";
+			break;
+		case MPI3_EVENT_SAS_TOPO_PHY_RC_PHY_CHANGED:
+			status_str = "link status change";
+			break;
+		case MPI3_EVENT_SAS_TOPO_PHY_RC_NO_CHANGE:
+			status_str = "link status no change";
+			break;
+		case MPI3_EVENT_SAS_TOPO_PHY_RC_RESPONDING:
+			status_str = "target responding";
+			break;
+		default:
+			status_str = "unknown";
+			break;
+		}
+		link_rate = event_data->PhyEntry[i].LinkRate >> 4;
+		prev_link_rate = event_data->PhyEntry[i].LinkRate & 0xF;
+		ioc_info(mrioc,
+		    "%s :\tphy(%02d), attached_handle(0x%04x): %s: link rate: new(0x%02x), old(0x%02x)\n",
+		    __func__, phy_number, handle, status_str, link_rate,
+		    prev_link_rate);
+	}
+}
+
 /**
  * mpi3mr_sastopochg_evt_bh - SASTopologyChange evt bottomhalf
  * @mrioc: Adapter instance reference
@@ -1027,6 +1106,8 @@ static void mpi3mr_sastopochg_evt_bh(struct mpi3mr_ioc *mrioc,
 	u8 reason_code;
 	struct mpi3mr_tgt_dev *tgtdev = NULL;
 
+	mpi3mr_sastopochg_evt_debug(mrioc, event_data);
+
 	for (i = 0; i < event_data->NumEntries; i++) {
 		handle = le16_to_cpu(event_data->PhyEntry[i].AttachedDevHandle);
 		if (!handle)
@@ -1053,6 +1134,87 @@ static void mpi3mr_sastopochg_evt_bh(struct mpi3mr_ioc *mrioc,
 	}
 }
 
+/**
+ * mpi3mr_pcietopochg_evt_debug - PCIeTopoChange details
+ * @mrioc: Adapter instance reference
+ * @event_data: PCIe topology change list event data
+ *
+ * Prints information about the PCIe topology change event.
+ *
+ * Return: Nothing.
+ */
+static void
+mpi3mr_pcietopochg_evt_debug(struct mpi3mr_ioc *mrioc,
+	Mpi3EventDataPcieTopologyChangeList_t *event_data)
+{
+	int i;
+	u16 handle;
+	u16 reason_code;
+	u8 port_number;
+	char *status_str = NULL;
+	u8 link_rate, prev_link_rate;
+
+	switch (event_data->SwitchStatus) {
+	case MPI3_EVENT_PCIE_TOPO_SS_NOT_RESPONDING:
+		status_str = "remove";
+		break;
+	case MPI3_EVENT_PCIE_TOPO_SS_RESPONDING:
+		status_str =  "responding";
+		break;
+	case MPI3_EVENT_PCIE_TOPO_SS_DELAY_NOT_RESPONDING:
+		status_str = "remove delay";
+		break;
+	case MPI3_EVENT_PCIE_TOPO_SS_NO_PCIE_SWITCH:
+		status_str = "direct attached";
+		break;
+	default:
+		status_str = "unknown status";
+		break;
+	}
+	ioc_info(mrioc, "%s :pcie topology change: (%s)\n",
+	    __func__, status_str);
+	ioc_info(mrioc,
+	    "%s :\tswitch_handle(0x%04x), enclosure_handle(0x%04x) start_port(%02d), num_entries(%d)\n",
+	    __func__, le16_to_cpu(event_data->SwitchDevHandle),
+	    le16_to_cpu(event_data->EnclosureHandle),
+	    event_data->StartPortNum, event_data->NumEntries);
+	for (i = 0; i < event_data->NumEntries; i++) {
+		handle =
+		    le16_to_cpu(event_data->PortEntry[i].AttachedDevHandle);
+		if (!handle)
+			continue;
+		port_number = event_data->StartPortNum + i;
+		reason_code = event_data->PortEntry[i].PortStatus;
+		switch (reason_code) {
+		case MPI3_EVENT_PCIE_TOPO_PS_NOT_RESPONDING:
+			status_str = "target remove";
+			break;
+		case MPI3_EVENT_PCIE_TOPO_PS_DELAY_NOT_RESPONDING:
+			status_str = "delay target remove";
+			break;
+		case MPI3_EVENT_PCIE_TOPO_PS_PORT_CHANGED:
+			status_str = "link status change";
+			break;
+		case MPI3_EVENT_PCIE_TOPO_PS_NO_CHANGE:
+			status_str = "link status no change";
+			break;
+		case MPI3_EVENT_PCIE_TOPO_PS_RESPONDING:
+			status_str = "target responding";
+			break;
+		default:
+			status_str = "unknown";
+			break;
+		}
+		link_rate = event_data->PortEntry[i].CurrentPortInfo &
+		    MPI3_EVENT_PCIE_TOPO_PI_RATE_MASK;
+		prev_link_rate = event_data->PortEntry[i].PreviousPortInfo &
+		    MPI3_EVENT_PCIE_TOPO_PI_RATE_MASK;
+		ioc_info(mrioc,
+		    "%s :\tport(%02d), attached_handle(0x%04x): %s: link rate: new(0x%02x), old(0x%02x)\n",
+		    __func__, port_number, handle, status_str, link_rate,
+		    prev_link_rate);
+	}
+}
 /**
  * mpi3mr_pcietopochg_evt_bh - PCIeTopologyChange evt bottomhalf
  * @mrioc: Adapter instance reference
@@ -1074,6 +1236,8 @@ static void mpi3mr_pcietopochg_evt_bh(struct mpi3mr_ioc *mrioc,
 	u8 reason_code;
 	struct mpi3mr_tgt_dev *tgtdev = NULL;
 
+	mpi3mr_pcietopochg_evt_debug(mrioc, event_data);
+
 	for (i = 0; i < event_data->NumEntries; i++) {
 		handle =
 		    le16_to_cpu(event_data->PortEntry[i].AttachedDevHandle);
-- 
2.18.1


-- 
This electronic communication and the information and any files transmitted 
with it, or attached to it, are confidential and are intended solely for 
the use of the individual or entity to whom it is addressed and may contain 
information that is confidential, legally privileged, protected by privacy 
laws, or otherwise restricted from disclosure to anyone else. If you are 
not the intended recipient or the person responsible for delivering the 
e-mail to the intended recipient, you are hereby notified that any use, 
copying, distributing, dissemination, forwarding, printing, or copying of 
this e-mail is strictly prohibited. If you received this e-mail in error, 
please return the e-mail to the sender, delete it from your computer, and 
destroy any printed copy of it.

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4169 bytes --]

^ permalink raw reply related	[flat|nested] 75+ messages in thread

* Re: [PATCH 01/24] mpi3mr: add mpi30 Rev-R headers and Kconfig
  2020-12-22 10:11 ` [PATCH 01/24] mpi3mr: add mpi30 Rev-R headers and Kconfig Kashyap Desai
@ 2020-12-22 18:15   ` Bart Van Assche
  2020-12-23 13:33     ` Kashyap Desai
  2021-02-23 12:30   ` Hannes Reinecke
  1 sibling, 1 reply; 75+ messages in thread
From: Bart Van Assche @ 2020-12-22 18:15 UTC (permalink / raw)
  To: Kashyap Desai, linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, sathya.prakash

On 12/22/20 2:11 AM, Kashyap Desai wrote:
> diff --git a/drivers/scsi/mpi3mr/mpi/mpi30_type.h b/drivers/scsi/mpi3mr/mpi/mpi30_type.h
> new file mode 100644
> index 000000000000..5de35e7a660f
> --- /dev/null
> +++ b/drivers/scsi/mpi3mr/mpi/mpi30_type.h
> @@ -0,0 +1,89 @@
> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> +/*
> + *  Copyright 2016-2020 Broadcom Inc. All rights reserved.
> + *
> + *           Name: mpi30_type.h
> + *    Description: MPI basic type definitions
> + *  Creation Date: 10/07/2016
> + *        Version: 03.00.00
> + */
> +#ifndef MPI30_TYPE_H
> +#define MPI30_TYPE_H     1
> +
> +/*****************************************************************************
> + * Define MPI3_POINTER if it has not already been defined. By default        *
> + * MPI3_POINTER is defined to be a near pointer. MPI3_POINTER can be defined *
> + * as a far pointer by defining MPI3_POINTER as "far *" before this header   *
> + * file is included.                                                         *
> + ****************************************************************************/
> +#ifndef MPI3_POINTER
> +#define MPI3_POINTER    *
> +#endif  /* MPI3_POINTER */

Near and far pointers are concepts that come from 16-bit Intel
architectures. I think that these concepts are not relevant in the Linux
kernel. Hence please remove the MPI3_POINTER macro and use '*' directly.

> +typedef u8 U8;
> +typedef __le16 U16;
> +typedef __le32 U32;
> +typedef __le64 U64 __aligned(4);

Typedefs like the above reduce source code readability significantly.
Please remove these typedefs and use __le16 etc. directly.

> +typedef U8 * PU8;
> +typedef U16 * PU16;
> +typedef U32 * PU32;
> +typedef U64 * PU64;

Same comment for the above typedefs.

> +typedef struct _S64struct {
> +    U32         Low;
> +    S32         High;
> +} S64struct;
> +
> +typedef struct _U64struct {
> +    U32         Low;
> +    U32         High;
> +} U64struct;

Please use upper_32_bits() and lower_32_bits() and remove the above
structure definitions.

> +typedef S8 * PS8;
> +typedef U8 * PU8;
> +typedef S16 * PS16;
> +typedef U16 * PU16;
> +typedef S32         *PS32;
> +typedef U32         *PU32;
> +typedef S64 * PS64;
> +typedef U64 * PU64;
> +typedef S64struct * PS64struct;
> +typedef U64struct * PU64struct;

Please remove these typedefs too. Additionally, please follow the Linux
kernel coding style (only a space at the left of '*' but not at the right).

Thanks,

Bart.

^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 03/24] mpi3mr: create operational request and reply queue pair
  2020-12-22 10:11 ` [PATCH 03/24] mpi3mr: create operational request and reply queue pair Kashyap Desai
@ 2020-12-22 18:18   ` Bart Van Assche
  2020-12-23 13:16     ` Kashyap Desai
  2021-02-28 13:04   ` Hannes Reinecke
  1 sibling, 1 reply; 75+ messages in thread
From: Bart Van Assche @ 2020-12-22 18:18 UTC (permalink / raw)
  To: Kashyap Desai, linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, sathya.prakash

On 12/22/20 2:11 AM, Kashyap Desai wrote:
> This electronic communication and the information and any files
> transmitted with it, or attached to it, are confidential and are
> intended solely for the use of the individual or entity to whom it is
> addressed and may contain information that is confidential, legally
> privileged, protected by privacy laws, or otherwise restricted from
> disclosure to anyone else. If you are not the intended recipient or
> the person responsible for delivering the e-mail to the intended
> recipient, you are hereby notified that any use, copying,
> distributing, dissemination, forwarding, printing, or copying of
> this e-mail is strictly prohibited. If you received this e-mail in
> error, please return the e-mail to the sender, delete it from your
> computer, and destroy any printed copy of it.

Please make sure that no confidentiality footers are added when posting
to a public mailing list.

Thanks,

Bart.

^ permalink raw reply	[flat|nested] 75+ messages in thread

* RE: [PATCH 03/24] mpi3mr: create operational request and reply queue pair
  2020-12-22 18:18   ` Bart Van Assche
@ 2020-12-23 13:16     ` Kashyap Desai
  0 siblings, 0 replies; 75+ messages in thread
From: Kashyap Desai @ 2020-12-23 13:16 UTC (permalink / raw)
  To: Bart Van Assche, linux-scsi
  Cc: jejb, martin.petersen, Steve Hagan, Peter Rivera,
	mpi3mr-drvr-developers, Sathya Prakash Veerichetty

[-- Attachment #1: Type: text/plain, Size: 2288 bytes --]

> -----Original Message-----
> From: Bart Van Assche [mailto:bvanassche@acm.org]
> Sent: Tuesday, December 22, 2020 11:49 PM
> To: Kashyap Desai <kashyap.desai@broadcom.com>; linux-
> scsi@vger.kernel.org
> Cc: jejb@linux.ibm.com; martin.petersen@oracle.com;
> steve.hagan@broadcom.com; peter.rivera@broadcom.com; mpi3mr-
> linuxdrv.pdl@broadcom.com; sathya.prakash@broadcom.com
> Subject: Re: [PATCH 03/24] mpi3mr: create operational request and reply
> queue pair
>
> On 12/22/20 2:11 AM, Kashyap Desai wrote:
> > This electronic communication and the information and any files
> > transmitted with it, or attached to it, are confidential and are
> > intended solely for the use of the individual or entity to whom it is
> > addressed and may contain information that is confidential, legally
> > privileged, protected by privacy laws, or otherwise restricted from
> > disclosure to anyone else. If you are not the intended recipient or
> > the person responsible for delivering the e-mail to the intended
> > recipient, you are hereby notified that any use, copying,
> > distributing, dissemination, forwarding, printing, or copying of this
> > e-mail is strictly prohibited. If you received this e-mail in error,
> > please return the e-mail to the sender, delete it from your computer,
> > and destroy any printed copy of it.
>
> Please make sure that no confidentiality footers are added when posting
to a
> public mailing list.

Sorry for this. I will take care next time.
>
> Thanks,
>
> Bart.

-- 
This electronic communication and the information and any files transmitted 
with it, or attached to it, are confidential and are intended solely for 
the use of the individual or entity to whom it is addressed and may contain 
information that is confidential, legally privileged, protected by privacy 
laws, or otherwise restricted from disclosure to anyone else. If you are 
not the intended recipient or the person responsible for delivering the 
e-mail to the intended recipient, you are hereby notified that any use, 
copying, distributing, dissemination, forwarding, printing, or copying of 
this e-mail is strictly prohibited. If you received this e-mail in error, 
please return the e-mail to the sender, delete it from your computer, and 
destroy any printed copy of it.

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4169 bytes --]

^ permalink raw reply	[flat|nested] 75+ messages in thread

* RE: [PATCH 01/24] mpi3mr: add mpi30 Rev-R headers and Kconfig
  2020-12-22 18:15   ` Bart Van Assche
@ 2020-12-23 13:33     ` Kashyap Desai
  0 siblings, 0 replies; 75+ messages in thread
From: Kashyap Desai @ 2020-12-23 13:33 UTC (permalink / raw)
  To: Bart Van Assche, linux-scsi
  Cc: jejb, martin.petersen, Steve Hagan, Peter Rivera,
	mpi3mr-drvr-developers, Sathya Prakash Veerichetty

[-- Attachment #1: Type: text/plain, Size: 2685 bytes --]

> > +#ifndef MPI3_POINTER
> > +#define MPI3_POINTER    *
> > +#endif  /* MPI3_POINTER */
>
> Near and far pointers are concepts that come from 16-bit Intel
architectures. I
> think that these concepts are not relevant in the Linux kernel. Hence
please
> remove the MPI3_POINTER macro and use '*' directly.

Hi Bart,

All your comments are noted. This is a common header file used by Firmware
and all OS drivers.  That is a reason we need typedef and other coding
standard exception (mainly for mpi header files).
We will cover coding standards as you pointed in all other .c files.

>
> > +typedef u8 U8;
> > +typedef __le16 U16;
> > +typedef __le32 U32;
> > +typedef __le64 U64 __aligned(4);
>
> Typedefs like the above reduce source code readability significantly.
> Please remove these typedefs and use __le16 etc. directly.
>
> > +typedef U8 * PU8;
> > +typedef U16 * PU16;
> > +typedef U32 * PU32;
> > +typedef U64 * PU64;
>
> Same comment for the above typedefs.
>
> > +typedef struct _S64struct {
> > +    U32         Low;
> > +    S32         High;
> > +} S64struct;
> > +
> > +typedef struct _U64struct {
> > +    U32         Low;
> > +    U32         High;
> > +} U64struct;
>
> Please use upper_32_bits() and lower_32_bits() and remove the above
> structure definitions.
>
> > +typedef S8 * PS8;
> > +typedef U8 * PU8;
> > +typedef S16 * PS16;
> > +typedef U16 * PU16;
> > +typedef S32         *PS32;
> > +typedef U32         *PU32;
> > +typedef S64 * PS64;
> > +typedef U64 * PU64;
> > +typedef S64struct * PS64struct;
> > +typedef U64struct * PU64struct;
>
> Please remove these typedefs too. Additionally, please follow the Linux
kernel
> coding style (only a space at the left of '*' but not at the right).

One specific part of this file is undefined, so we can remove it
completely. I have to syncup internally since this file is shared header
file.

Kashyap

>
> Thanks,
>
> Bart.

-- 
This electronic communication and the information and any files transmitted 
with it, or attached to it, are confidential and are intended solely for 
the use of the individual or entity to whom it is addressed and may contain 
information that is confidential, legally privileged, protected by privacy 
laws, or otherwise restricted from disclosure to anyone else. If you are 
not the intended recipient or the person responsible for delivering the 
e-mail to the intended recipient, you are hereby notified that any use, 
copying, distributing, dissemination, forwarding, printing, or copying of 
this e-mail is strictly prohibited. If you received this e-mail in error, 
please return the e-mail to the sender, delete it from your computer, and 
destroy any printed copy of it.

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4169 bytes --]

^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 06/24] mpi3mr: add support of event handling part-1
  2020-12-22 10:11 ` [PATCH 06/24] mpi3mr: add support of event handling part-1 Kashyap Desai
@ 2020-12-27 13:14     ` kernel test robot
  2021-02-22 15:31   ` Tomas Henzl
  2021-03-01  6:47   ` Hannes Reinecke
  2 siblings, 0 replies; 75+ messages in thread
From: kernel test robot @ 2020-12-27 13:14 UTC (permalink / raw)
  To: Kashyap Desai, linux-scsi
  Cc: kbuild-all, jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, Kashyap Desai, sathya.prakash

[-- Attachment #1: Type: text/plain, Size: 9632 bytes --]

Hi Kashyap,

I love your patch! Perhaps something to improve:

[auto build test WARNING on mkp-scsi/for-next]
[also build test WARNING on scsi/for-next v5.10 next-20201223]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Kashyap-Desai/Introducing-mpi3mr-driver/20201222-181732
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git for-next
config: powerpc-allyesconfig (attached as .config)
compiler: powerpc64-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/f353c97f9e813b38c4546df7698017174df5a559
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Kashyap-Desai/Introducing-mpi3mr-driver/20201222-181732
        git checkout f353c97f9e813b38c4546df7698017174df5a559
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=powerpc 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   drivers/scsi/mpi3mr/mpi3mr_os.c:281:6: warning: no previous prototype for 'mpi3mr_cleanup_fwevt_list' [-Wmissing-prototypes]
     281 | void mpi3mr_cleanup_fwevt_list(struct mpi3mr_ioc *mrioc)
         |      ^~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/scsi/mpi3mr/mpi3mr_os.c:412:24: warning: no previous prototype for 'mpi3mr_get_tgtdev_by_handle' [-Wmissing-prototypes]
     412 | struct mpi3mr_tgt_dev *mpi3mr_get_tgtdev_by_handle(
         |                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/scsi/mpi3mr/mpi3mr_os.c:460:24: warning: no previous prototype for 'mpi3mr_get_tgtdev_by_perst_id' [-Wmissing-prototypes]
     460 | struct mpi3mr_tgt_dev *mpi3mr_get_tgtdev_by_perst_id(
         |                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/scsi/mpi3mr/mpi3mr_os.c:580:6: warning: no previous prototype for 'mpi3mr_rfresh_tgtdevs' [-Wmissing-prototypes]
     580 | void mpi3mr_rfresh_tgtdevs(struct mpi3mr_ioc *mrioc)
         |      ^~~~~~~~~~~~~~~~~~~~~
   drivers/scsi/mpi3mr/mpi3mr_os.c: In function 'mpi3mr_devstatuschg_evt_bh':
>> drivers/scsi/mpi3mr/mpi3mr_os.c:689:32: warning: variable 'scsi_tgt_priv_data' set but not used [-Wunused-but-set-variable]
     689 |  struct mpi3mr_stgt_priv_data *scsi_tgt_priv_data = NULL;
         |                                ^~~~~~~~~~~~~~~~~~
   drivers/scsi/mpi3mr/mpi3mr_os.c: At top level:
   drivers/scsi/mpi3mr/mpi3mr_os.c:952:6: warning: no previous prototype for 'mpi3mr_flush_delayed_rmhs_list' [-Wmissing-prototypes]
     952 | void mpi3mr_flush_delayed_rmhs_list(struct mpi3mr_ioc *mrioc)
         |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


vim +/mpi3mr_get_tgtdev_by_handle +412 drivers/scsi/mpi3mr/mpi3mr_os.c

   271	
   272	/**
   273	 * mpi3mr_cleanup_fwevt_list - Cleanup firmware event list
   274	 * @mrioc: Adapter instance reference
   275	 *
   276	 * Flush all pending firmware events from the firmware event
   277	 * list.
   278	 *
   279	 * Return: Nothing.
   280	 */
 > 281	void mpi3mr_cleanup_fwevt_list(struct mpi3mr_ioc *mrioc)
   282	{
   283		struct mpi3mr_fwevt *fwevt = NULL;
   284	
   285		if ((list_empty(&mrioc->fwevt_list) && !mrioc->current_event) ||
   286		    !mrioc->fwevt_worker_thread || in_interrupt())
   287			return;
   288	
   289		while ((fwevt = mpi3mr_dequeue_fwevt(mrioc)) ||
   290		    (fwevt = mrioc->current_event)) {
   291			/*
   292			 * Wait on the fwevt to complete. If this returns 1, then
   293			 * the event was never executed, and we need a put for the
   294			 * reference the work had on the fwevt.
   295			 *
   296			 * If it did execute, we wait for it to finish, and the put will
   297			 * happen from mpi3mr_process_fwevt()
   298			 */
   299			if (cancel_work_sync(&fwevt->work)) {
   300				/*
   301				 * Put fwevt reference count after
   302				 * dequeuing it from worker queue
   303				 */
   304				mpi3mr_fwevt_put(fwevt);
   305				/*
   306				 * Put fwevt reference count to neutralize
   307				 * kref_init increment
   308				 */
   309				mpi3mr_fwevt_put(fwevt);
   310			}
   311		}
   312	}
   313	
   314	/**
   315	 * mpi3mr_alloc_tgtdev - target device allocator
   316	 *
   317	 * Allocate target device instance and initialize the reference
   318	 * count
   319	 *
   320	 * Return: target device instance.
   321	 */
   322	static struct mpi3mr_tgt_dev *mpi3mr_alloc_tgtdev(void)
   323	{
   324		struct mpi3mr_tgt_dev *tgtdev;
   325	
   326		tgtdev = kzalloc(sizeof(*tgtdev), GFP_ATOMIC);
   327		if (!tgtdev)
   328			return NULL;
   329		kref_init(&tgtdev->ref_count);
   330		return tgtdev;
   331	}
   332	
   333	/**
   334	 * mpi3mr_tgtdev_add_to_list -Add tgtdevice to the list
   335	 * @mrioc: Adapter instance reference
   336	 * @tgtdev: Target device
   337	 *
   338	 * Add the target device to the target device list
   339	 *
   340	 * Return: Nothing.
   341	 */
   342	static void mpi3mr_tgtdev_add_to_list(struct mpi3mr_ioc *mrioc,
   343		struct mpi3mr_tgt_dev *tgtdev)
   344	{
   345		unsigned long flags;
   346	
   347		spin_lock_irqsave(&mrioc->tgtdev_lock, flags);
   348		mpi3mr_tgtdev_get(tgtdev);
   349		INIT_LIST_HEAD(&tgtdev->list);
   350		list_add_tail(&tgtdev->list, &mrioc->tgtdev_list);
   351		spin_unlock_irqrestore(&mrioc->tgtdev_lock, flags);
   352	}
   353	
   354	/**
   355	 * mpi3mr_tgtdev_del_from_list -Delete tgtdevice from the list
   356	 * @mrioc: Adapter instance reference
   357	 * @tgtdev: Target device
   358	 *
   359	 * Remove the target device from the target device list
   360	 *
   361	 * Return: Nothing.
   362	 */
   363	static void mpi3mr_tgtdev_del_from_list(struct mpi3mr_ioc *mrioc,
   364		struct mpi3mr_tgt_dev *tgtdev)
   365	{
   366		unsigned long flags;
   367	
   368		spin_lock_irqsave(&mrioc->tgtdev_lock, flags);
   369		if (!list_empty(&tgtdev->list)) {
   370			list_del_init(&tgtdev->list);
   371			mpi3mr_tgtdev_put(tgtdev);
   372		}
   373		spin_unlock_irqrestore(&mrioc->tgtdev_lock, flags);
   374	}
   375	
   376	/**
   377	 * __mpi3mr_get_tgtdev_by_handle -Get tgtdev from device handle
   378	 * @mrioc: Adapter instance reference
   379	 * @handle: Device handle
   380	 *
   381	 * Accessor to retrieve target device from the device handle.
   382	 * Non Lock version
   383	 *
   384	 * Return: Target device reference.
   385	 */
   386	static struct mpi3mr_tgt_dev  *__mpi3mr_get_tgtdev_by_handle(
   387		struct mpi3mr_ioc *mrioc, u16 handle)
   388	{
   389		struct mpi3mr_tgt_dev *tgtdev;
   390	
   391		assert_spin_locked(&mrioc->tgtdev_lock);
   392		list_for_each_entry(tgtdev, &mrioc->tgtdev_list, list)
   393			if (tgtdev->dev_handle == handle)
   394				goto found_tgtdev;
   395		return NULL;
   396	
   397	found_tgtdev:
   398		mpi3mr_tgtdev_get(tgtdev);
   399		return tgtdev;
   400	}
   401	
   402	/**
   403	 * mpi3mr_get_tgtdev_by_handle -Get tgtdev from device handle
   404	 * @mrioc: Adapter instance reference
   405	 * @handle: Device handle
   406	 *
   407	 * Accessor to retrieve target device from the device handle.
   408	 * Lock version
   409	 *
   410	 * Return: Target device reference.
   411	 */
 > 412	struct mpi3mr_tgt_dev *mpi3mr_get_tgtdev_by_handle(
   413		struct mpi3mr_ioc *mrioc, u16 handle)
   414	{
   415		struct mpi3mr_tgt_dev *tgtdev;
   416		unsigned long flags;
   417	
   418		spin_lock_irqsave(&mrioc->tgtdev_lock, flags);
   419		tgtdev = __mpi3mr_get_tgtdev_by_handle(mrioc, handle);
   420		spin_unlock_irqrestore(&mrioc->tgtdev_lock, flags);
   421		return tgtdev;
   422	}
   423	
   424	/**
   425	 * __mpi3mr_get_tgtdev_by_perst_id -Get tgtdev from persist ID
   426	 * @mrioc: Adapter instance reference
   427	 * @persist_id: Persistent ID
   428	 *
   429	 * Accessor to retrieve target device from the Persistent ID.
   430	 * Non Lock version
   431	 *
   432	 * Return: Target device reference.
   433	 */
   434	static struct mpi3mr_tgt_dev  *__mpi3mr_get_tgtdev_by_perst_id(
   435		struct mpi3mr_ioc *mrioc, u16 persist_id)
   436	{
   437		struct mpi3mr_tgt_dev *tgtdev;
   438	
   439		assert_spin_locked(&mrioc->tgtdev_lock);
   440		list_for_each_entry(tgtdev, &mrioc->tgtdev_list, list)
   441			if (tgtdev->perst_id == persist_id)
   442				goto found_tgtdev;
   443		return NULL;
   444	
   445	found_tgtdev:
   446		mpi3mr_tgtdev_get(tgtdev);
   447		return tgtdev;
   448	}
   449	
   450	/**
   451	 * mpi3mr_get_tgtdev_by_perst_id -Get tgtdev from persistent ID
   452	 * @mrioc: Adapter instance reference
   453	 * @persist_id: Persistent ID
   454	 *
   455	 * Accessor to retrieve target device from the Persistent ID.
   456	 * Lock version
   457	 *
   458	 * Return: Target device reference.
   459	 */
 > 460	struct mpi3mr_tgt_dev *mpi3mr_get_tgtdev_by_perst_id(
   461		struct mpi3mr_ioc *mrioc, u16 persist_id)
   462	{
   463		struct mpi3mr_tgt_dev *tgtdev;
   464		unsigned long flags;
   465	
   466		spin_lock_irqsave(&mrioc->tgtdev_lock, flags);
   467		tgtdev = __mpi3mr_get_tgtdev_by_perst_id(mrioc, persist_id);
   468		spin_unlock_irqrestore(&mrioc->tgtdev_lock, flags);
   469		return tgtdev;
   470	}
   471	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 71613 bytes --]

^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 06/24] mpi3mr: add support of event handling part-1
@ 2020-12-27 13:14     ` kernel test robot
  0 siblings, 0 replies; 75+ messages in thread
From: kernel test robot @ 2020-12-27 13:14 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 9892 bytes --]

Hi Kashyap,

I love your patch! Perhaps something to improve:

[auto build test WARNING on mkp-scsi/for-next]
[also build test WARNING on scsi/for-next v5.10 next-20201223]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Kashyap-Desai/Introducing-mpi3mr-driver/20201222-181732
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git for-next
config: powerpc-allyesconfig (attached as .config)
compiler: powerpc64-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/f353c97f9e813b38c4546df7698017174df5a559
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Kashyap-Desai/Introducing-mpi3mr-driver/20201222-181732
        git checkout f353c97f9e813b38c4546df7698017174df5a559
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=powerpc 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   drivers/scsi/mpi3mr/mpi3mr_os.c:281:6: warning: no previous prototype for 'mpi3mr_cleanup_fwevt_list' [-Wmissing-prototypes]
     281 | void mpi3mr_cleanup_fwevt_list(struct mpi3mr_ioc *mrioc)
         |      ^~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/scsi/mpi3mr/mpi3mr_os.c:412:24: warning: no previous prototype for 'mpi3mr_get_tgtdev_by_handle' [-Wmissing-prototypes]
     412 | struct mpi3mr_tgt_dev *mpi3mr_get_tgtdev_by_handle(
         |                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/scsi/mpi3mr/mpi3mr_os.c:460:24: warning: no previous prototype for 'mpi3mr_get_tgtdev_by_perst_id' [-Wmissing-prototypes]
     460 | struct mpi3mr_tgt_dev *mpi3mr_get_tgtdev_by_perst_id(
         |                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/scsi/mpi3mr/mpi3mr_os.c:580:6: warning: no previous prototype for 'mpi3mr_rfresh_tgtdevs' [-Wmissing-prototypes]
     580 | void mpi3mr_rfresh_tgtdevs(struct mpi3mr_ioc *mrioc)
         |      ^~~~~~~~~~~~~~~~~~~~~
   drivers/scsi/mpi3mr/mpi3mr_os.c: In function 'mpi3mr_devstatuschg_evt_bh':
>> drivers/scsi/mpi3mr/mpi3mr_os.c:689:32: warning: variable 'scsi_tgt_priv_data' set but not used [-Wunused-but-set-variable]
     689 |  struct mpi3mr_stgt_priv_data *scsi_tgt_priv_data = NULL;
         |                                ^~~~~~~~~~~~~~~~~~
   drivers/scsi/mpi3mr/mpi3mr_os.c: At top level:
   drivers/scsi/mpi3mr/mpi3mr_os.c:952:6: warning: no previous prototype for 'mpi3mr_flush_delayed_rmhs_list' [-Wmissing-prototypes]
     952 | void mpi3mr_flush_delayed_rmhs_list(struct mpi3mr_ioc *mrioc)
         |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


vim +/mpi3mr_get_tgtdev_by_handle +412 drivers/scsi/mpi3mr/mpi3mr_os.c

   271	
   272	/**
   273	 * mpi3mr_cleanup_fwevt_list - Cleanup firmware event list
   274	 * @mrioc: Adapter instance reference
   275	 *
   276	 * Flush all pending firmware events from the firmware event
   277	 * list.
   278	 *
   279	 * Return: Nothing.
   280	 */
 > 281	void mpi3mr_cleanup_fwevt_list(struct mpi3mr_ioc *mrioc)
   282	{
   283		struct mpi3mr_fwevt *fwevt = NULL;
   284	
   285		if ((list_empty(&mrioc->fwevt_list) && !mrioc->current_event) ||
   286		    !mrioc->fwevt_worker_thread || in_interrupt())
   287			return;
   288	
   289		while ((fwevt = mpi3mr_dequeue_fwevt(mrioc)) ||
   290		    (fwevt = mrioc->current_event)) {
   291			/*
   292			 * Wait on the fwevt to complete. If this returns 1, then
   293			 * the event was never executed, and we need a put for the
   294			 * reference the work had on the fwevt.
   295			 *
   296			 * If it did execute, we wait for it to finish, and the put will
   297			 * happen from mpi3mr_process_fwevt()
   298			 */
   299			if (cancel_work_sync(&fwevt->work)) {
   300				/*
   301				 * Put fwevt reference count after
   302				 * dequeuing it from worker queue
   303				 */
   304				mpi3mr_fwevt_put(fwevt);
   305				/*
   306				 * Put fwevt reference count to neutralize
   307				 * kref_init increment
   308				 */
   309				mpi3mr_fwevt_put(fwevt);
   310			}
   311		}
   312	}
   313	
   314	/**
   315	 * mpi3mr_alloc_tgtdev - target device allocator
   316	 *
   317	 * Allocate target device instance and initialize the reference
   318	 * count
   319	 *
   320	 * Return: target device instance.
   321	 */
   322	static struct mpi3mr_tgt_dev *mpi3mr_alloc_tgtdev(void)
   323	{
   324		struct mpi3mr_tgt_dev *tgtdev;
   325	
   326		tgtdev = kzalloc(sizeof(*tgtdev), GFP_ATOMIC);
   327		if (!tgtdev)
   328			return NULL;
   329		kref_init(&tgtdev->ref_count);
   330		return tgtdev;
   331	}
   332	
   333	/**
   334	 * mpi3mr_tgtdev_add_to_list -Add tgtdevice to the list
   335	 * @mrioc: Adapter instance reference
   336	 * @tgtdev: Target device
   337	 *
   338	 * Add the target device to the target device list
   339	 *
   340	 * Return: Nothing.
   341	 */
   342	static void mpi3mr_tgtdev_add_to_list(struct mpi3mr_ioc *mrioc,
   343		struct mpi3mr_tgt_dev *tgtdev)
   344	{
   345		unsigned long flags;
   346	
   347		spin_lock_irqsave(&mrioc->tgtdev_lock, flags);
   348		mpi3mr_tgtdev_get(tgtdev);
   349		INIT_LIST_HEAD(&tgtdev->list);
   350		list_add_tail(&tgtdev->list, &mrioc->tgtdev_list);
   351		spin_unlock_irqrestore(&mrioc->tgtdev_lock, flags);
   352	}
   353	
   354	/**
   355	 * mpi3mr_tgtdev_del_from_list -Delete tgtdevice from the list
   356	 * @mrioc: Adapter instance reference
   357	 * @tgtdev: Target device
   358	 *
   359	 * Remove the target device from the target device list
   360	 *
   361	 * Return: Nothing.
   362	 */
   363	static void mpi3mr_tgtdev_del_from_list(struct mpi3mr_ioc *mrioc,
   364		struct mpi3mr_tgt_dev *tgtdev)
   365	{
   366		unsigned long flags;
   367	
   368		spin_lock_irqsave(&mrioc->tgtdev_lock, flags);
   369		if (!list_empty(&tgtdev->list)) {
   370			list_del_init(&tgtdev->list);
   371			mpi3mr_tgtdev_put(tgtdev);
   372		}
   373		spin_unlock_irqrestore(&mrioc->tgtdev_lock, flags);
   374	}
   375	
   376	/**
   377	 * __mpi3mr_get_tgtdev_by_handle -Get tgtdev from device handle
   378	 * @mrioc: Adapter instance reference
   379	 * @handle: Device handle
   380	 *
   381	 * Accessor to retrieve target device from the device handle.
   382	 * Non Lock version
   383	 *
   384	 * Return: Target device reference.
   385	 */
   386	static struct mpi3mr_tgt_dev  *__mpi3mr_get_tgtdev_by_handle(
   387		struct mpi3mr_ioc *mrioc, u16 handle)
   388	{
   389		struct mpi3mr_tgt_dev *tgtdev;
   390	
   391		assert_spin_locked(&mrioc->tgtdev_lock);
   392		list_for_each_entry(tgtdev, &mrioc->tgtdev_list, list)
   393			if (tgtdev->dev_handle == handle)
   394				goto found_tgtdev;
   395		return NULL;
   396	
   397	found_tgtdev:
   398		mpi3mr_tgtdev_get(tgtdev);
   399		return tgtdev;
   400	}
   401	
   402	/**
   403	 * mpi3mr_get_tgtdev_by_handle -Get tgtdev from device handle
   404	 * @mrioc: Adapter instance reference
   405	 * @handle: Device handle
   406	 *
   407	 * Accessor to retrieve target device from the device handle.
   408	 * Lock version
   409	 *
   410	 * Return: Target device reference.
   411	 */
 > 412	struct mpi3mr_tgt_dev *mpi3mr_get_tgtdev_by_handle(
   413		struct mpi3mr_ioc *mrioc, u16 handle)
   414	{
   415		struct mpi3mr_tgt_dev *tgtdev;
   416		unsigned long flags;
   417	
   418		spin_lock_irqsave(&mrioc->tgtdev_lock, flags);
   419		tgtdev = __mpi3mr_get_tgtdev_by_handle(mrioc, handle);
   420		spin_unlock_irqrestore(&mrioc->tgtdev_lock, flags);
   421		return tgtdev;
   422	}
   423	
   424	/**
   425	 * __mpi3mr_get_tgtdev_by_perst_id -Get tgtdev from persist ID
   426	 * @mrioc: Adapter instance reference
   427	 * @persist_id: Persistent ID
   428	 *
   429	 * Accessor to retrieve target device from the Persistent ID.
   430	 * Non Lock version
   431	 *
   432	 * Return: Target device reference.
   433	 */
   434	static struct mpi3mr_tgt_dev  *__mpi3mr_get_tgtdev_by_perst_id(
   435		struct mpi3mr_ioc *mrioc, u16 persist_id)
   436	{
   437		struct mpi3mr_tgt_dev *tgtdev;
   438	
   439		assert_spin_locked(&mrioc->tgtdev_lock);
   440		list_for_each_entry(tgtdev, &mrioc->tgtdev_list, list)
   441			if (tgtdev->perst_id == persist_id)
   442				goto found_tgtdev;
   443		return NULL;
   444	
   445	found_tgtdev:
   446		mpi3mr_tgtdev_get(tgtdev);
   447		return tgtdev;
   448	}
   449	
   450	/**
   451	 * mpi3mr_get_tgtdev_by_perst_id -Get tgtdev from persistent ID
   452	 * @mrioc: Adapter instance reference
   453	 * @persist_id: Persistent ID
   454	 *
   455	 * Accessor to retrieve target device from the Persistent ID.
   456	 * Lock version
   457	 *
   458	 * Return: Target device reference.
   459	 */
 > 460	struct mpi3mr_tgt_dev *mpi3mr_get_tgtdev_by_perst_id(
   461		struct mpi3mr_ioc *mrioc, u16 persist_id)
   462	{
   463		struct mpi3mr_tgt_dev *tgtdev;
   464		unsigned long flags;
   465	
   466		spin_lock_irqsave(&mrioc->tgtdev_lock, flags);
   467		tgtdev = __mpi3mr_get_tgtdev_by_perst_id(mrioc, persist_id);
   468		spin_unlock_irqrestore(&mrioc->tgtdev_lock, flags);
   469		return tgtdev;
   470	}
   471	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 71613 bytes --]

^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 17/24] mpi3mr: add support of threaded isr
  2020-12-22 10:11 ` [PATCH 17/24] mpi3mr: add support of threaded isr Kashyap Desai
@ 2020-12-27 13:51     ` kernel test robot
  2021-03-01  7:14   ` Hannes Reinecke
  1 sibling, 0 replies; 75+ messages in thread
From: kernel test robot @ 2020-12-27 13:51 UTC (permalink / raw)
  To: Kashyap Desai, linux-scsi
  Cc: kbuild-all, jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, Kashyap Desai, sathya.prakash

[-- Attachment #1: Type: text/plain, Size: 3335 bytes --]

Hi Kashyap,

I love your patch! Perhaps something to improve:

[auto build test WARNING on mkp-scsi/for-next]
[also build test WARNING on scsi/for-next v5.10 next-20201223]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Kashyap-Desai/Introducing-mpi3mr-driver/20201222-181732
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git for-next
config: powerpc-allyesconfig (attached as .config)
compiler: powerpc64-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/877f4e22deefcac84c14ed953f360f8131e02d14
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Kashyap-Desai/Introducing-mpi3mr-driver/20201222-181732
        git checkout 877f4e22deefcac84c14ed953f360f8131e02d14
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=powerpc 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   drivers/scsi/mpi3mr/mpi3mr_fw.c: In function 'mpi3mr_isr_poll':
>> drivers/scsi/mpi3mr/mpi3mr_fw.c:481:6: warning: variable 'num_admin_replies' set but not used [-Wunused-but-set-variable]
     481 |  u32 num_admin_replies = 0, num_op_reply = 0;
         |      ^~~~~~~~~~~~~~~~~


vim +/num_admin_replies +481 drivers/scsi/mpi3mr/mpi3mr_fw.c

   465	
   466	/**
   467	 * mpi3mr_isr_poll - Reply queue polling routine
   468	 * @irq: IRQ
   469	 * @privdata: Interrupt info
   470	 *
   471	 * poll for pending I/O completions in a loop until pending I/Os
   472	 * present or controller queue depth I/Os are processed.
   473	 *
   474	 * Return: IRQ_NONE or IRQ_HANDLED
   475	 */
   476	static irqreturn_t mpi3mr_isr_poll(int irq, void *privdata)
   477	{
   478		struct mpi3mr_intr_info *intr_info = privdata;
   479		struct mpi3mr_ioc *mrioc;
   480		u16 midx;
 > 481		u32 num_admin_replies = 0, num_op_reply = 0;
   482	
   483		if (!intr_info || !intr_info->op_reply_q)
   484			return IRQ_NONE;
   485	
   486		mrioc = intr_info->mrioc;
   487		midx = intr_info->msix_index;
   488	
   489		/* Poll for pending IOs completions */
   490		do {
   491			if (!mrioc->intr_enabled)
   492				break;
   493	
   494			if (!midx)
   495				num_admin_replies = mpi3mr_process_admin_reply_q(mrioc);
   496			if (intr_info->op_reply_q)
   497				num_op_reply +=
   498				    mpi3mr_process_op_reply_q(mrioc, intr_info);
   499	
   500			usleep_range(mrioc->irqpoll_sleep, 10 * mrioc->irqpoll_sleep);
   501	
   502		} while (atomic_read(&intr_info->op_reply_q->pend_ios) &&
   503		    (num_op_reply < mrioc->max_host_ios));
   504	
   505		intr_info->op_reply_q->enable_irq_poll = false;
   506		enable_irq(pci_irq_vector(mrioc->pdev, midx));
   507	
   508		return IRQ_HANDLED;
   509	}
   510	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 71613 bytes --]

^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 17/24] mpi3mr: add support of threaded isr
@ 2020-12-27 13:51     ` kernel test robot
  0 siblings, 0 replies; 75+ messages in thread
From: kernel test robot @ 2020-12-27 13:51 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 3424 bytes --]

Hi Kashyap,

I love your patch! Perhaps something to improve:

[auto build test WARNING on mkp-scsi/for-next]
[also build test WARNING on scsi/for-next v5.10 next-20201223]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Kashyap-Desai/Introducing-mpi3mr-driver/20201222-181732
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git for-next
config: powerpc-allyesconfig (attached as .config)
compiler: powerpc64-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/877f4e22deefcac84c14ed953f360f8131e02d14
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Kashyap-Desai/Introducing-mpi3mr-driver/20201222-181732
        git checkout 877f4e22deefcac84c14ed953f360f8131e02d14
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=powerpc 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   drivers/scsi/mpi3mr/mpi3mr_fw.c: In function 'mpi3mr_isr_poll':
>> drivers/scsi/mpi3mr/mpi3mr_fw.c:481:6: warning: variable 'num_admin_replies' set but not used [-Wunused-but-set-variable]
     481 |  u32 num_admin_replies = 0, num_op_reply = 0;
         |      ^~~~~~~~~~~~~~~~~


vim +/num_admin_replies +481 drivers/scsi/mpi3mr/mpi3mr_fw.c

   465	
   466	/**
   467	 * mpi3mr_isr_poll - Reply queue polling routine
   468	 * @irq: IRQ
   469	 * @privdata: Interrupt info
   470	 *
   471	 * poll for pending I/O completions in a loop until pending I/Os
   472	 * present or controller queue depth I/Os are processed.
   473	 *
   474	 * Return: IRQ_NONE or IRQ_HANDLED
   475	 */
   476	static irqreturn_t mpi3mr_isr_poll(int irq, void *privdata)
   477	{
   478		struct mpi3mr_intr_info *intr_info = privdata;
   479		struct mpi3mr_ioc *mrioc;
   480		u16 midx;
 > 481		u32 num_admin_replies = 0, num_op_reply = 0;
   482	
   483		if (!intr_info || !intr_info->op_reply_q)
   484			return IRQ_NONE;
   485	
   486		mrioc = intr_info->mrioc;
   487		midx = intr_info->msix_index;
   488	
   489		/* Poll for pending IOs completions */
   490		do {
   491			if (!mrioc->intr_enabled)
   492				break;
   493	
   494			if (!midx)
   495				num_admin_replies = mpi3mr_process_admin_reply_q(mrioc);
   496			if (intr_info->op_reply_q)
   497				num_op_reply +=
   498				    mpi3mr_process_op_reply_q(mrioc, intr_info);
   499	
   500			usleep_range(mrioc->irqpoll_sleep, 10 * mrioc->irqpoll_sleep);
   501	
   502		} while (atomic_read(&intr_info->op_reply_q->pend_ios) &&
   503		    (num_op_reply < mrioc->max_host_ios));
   504	
   505		intr_info->op_reply_q->enable_irq_poll = false;
   506		enable_irq(pci_irq_vector(mrioc->pdev, midx));
   507	
   508		return IRQ_HANDLED;
   509	}
   510	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 71613 bytes --]

^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 02/24] mpi3mr: base driver code
  2020-12-22 10:11 ` [PATCH 02/24] mpi3mr: base driver code Kashyap Desai
@ 2020-12-27 14:14     ` kernel test robot
  2021-02-23 12:55   ` Hannes Reinecke
  1 sibling, 0 replies; 75+ messages in thread
From: kernel test robot @ 2020-12-27 14:14 UTC (permalink / raw)
  To: Kashyap Desai, linux-scsi
  Cc: kbuild-all, jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, Kashyap Desai, sathya.prakash

[-- Attachment #1: Type: text/plain, Size: 15114 bytes --]

Hi Kashyap,

I love your patch! Yet something to improve:

[auto build test ERROR on mkp-scsi/for-next]
[also build test ERROR on scsi/for-next v5.10 next-20201223]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Kashyap-Desai/Introducing-mpi3mr-driver/20201222-181732
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git for-next
config: arc-allyesconfig (attached as .config)
compiler: arceb-elf-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/f1507bd10ed4f38cbe02ec83c46bcac080b681cb
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Kashyap-Desai/Introducing-mpi3mr-driver/20201222-181732
        git checkout f1507bd10ed4f38cbe02ec83c46bcac080b681cb
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arc 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All error/warnings (new ones prefixed by >>):

   drivers/scsi/mpi3mr/mpi3mr_fw.c: In function 'mpi3mr_isr':
   drivers/scsi/mpi3mr/mpi3mr_fw.c:315:6: warning: variable 'midx' set but not used [-Wunused-but-set-variable]
     315 |  u16 midx;
         |      ^~~~
   drivers/scsi/mpi3mr/mpi3mr_fw.c:314:21: warning: variable 'mrioc' set but not used [-Wunused-but-set-variable]
     314 |  struct mpi3mr_ioc *mrioc;
         |                     ^~~~~
   In file included from include/linux/printk.h:7,
                    from include/linux/kernel.h:16,
                    from include/linux/list.h:9,
                    from include/linux/rculist.h:10,
                    from include/linux/pid.h:5,
                    from include/linux/sched.h:14,
                    from include/linux/blkdev.h:5,
                    from drivers/scsi/mpi3mr/mpi3mr.h:13,
                    from drivers/scsi/mpi3mr/mpi3mr_fw.c:10:
   drivers/scsi/mpi3mr/mpi3mr_fw.c: In function 'mpi3mr_process_factsdata':
   include/linux/kern_levels.h:5:18: warning: format '%ld' expects argument of type 'long int', but argument 3 has type 'unsigned int' [-Wformat=]
       5 | #define KERN_SOH "\001"  /* ASCII Start Of Header */
         |                  ^~~~~~
   include/linux/kern_levels.h:12:22: note: in expansion of macro 'KERN_SOH'
      12 | #define KERN_WARNING KERN_SOH "4" /* warning conditions */
         |                      ^~~~~~~~
   include/linux/printk.h:353:9: note: in expansion of macro 'KERN_WARNING'
     353 |  printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
         |         ^~~~~~~~~~~~
   drivers/scsi/mpi3mr/mpi3mr_debug.h:49:2: note: in expansion of macro 'pr_warn'
      49 |  pr_warn("%s: " fmt, (ioc)->name, ##__VA_ARGS__)
         |  ^~~~~~~
   drivers/scsi/mpi3mr/mpi3mr_fw.c:933:3: note: in expansion of macro 'ioc_warn'
     933 |   ioc_warn(mrioc,
         |   ^~~~~~~~
   drivers/scsi/mpi3mr/mpi3mr_fw.c:934:49: note: format string is defined here
     934 |       "IOCFactsdata length mismatch driver_sz(%ld) firmware_sz(%d)\n",
         |                                               ~~^
         |                                                 |
         |                                                 long int
         |                                               %d
   drivers/scsi/mpi3mr/mpi3mr_fw.c: In function 'mpi3mr_cleanup_resources':
>> drivers/scsi/mpi3mr/mpi3mr_fw.c:1332:16: warning: passing argument 1 of 'iounmap' discards 'volatile' qualifier from pointer target type [-Wdiscarded-qualifiers]
    1332 |   iounmap(mrioc->sysif_regs);
         |           ~~~~~^~~~~~~~~~~~
   In file included from include/linux/io.h:13,
                    from include/linux/irq.h:20,
                    from include/asm-generic/hardirq.h:13,
                    from ./arch/arc/include/generated/asm/hardirq.h:1,
                    from include/linux/hardirq.h:10,
                    from include/linux/highmem.h:10,
                    from include/linux/pagemap.h:11,
                    from include/linux/blkdev.h:14,
                    from drivers/scsi/mpi3mr/mpi3mr.h:13,
                    from drivers/scsi/mpi3mr/mpi3mr_fw.c:10:
   arch/arc/include/asm/io.h:35:41: note: expected 'const void *' but argument is of type 'volatile Mpi3SysIfRegs_t *' {aka 'volatile struct _MPI3_SYSIF_REGISTERS *'}
      35 | extern void iounmap(const void __iomem *addr);
         |                     ~~~~~~~~~~~~~~~~~~~~^~~~
   drivers/scsi/mpi3mr/mpi3mr_fw.c: In function 'mpi3mr_init_ioc':
>> drivers/scsi/mpi3mr/mpi3mr_fw.c:1476:14: error: implicit declaration of function 'readq'; did you mean 'readl'? [-Werror=implicit-function-declaration]
    1476 |  base_info = readq(&mrioc->sysif_regs->IOCInformation);
         |              ^~~~~
         |              readl
   cc1: some warnings being treated as errors


vim +1476 drivers/scsi/mpi3mr/mpi3mr_fw.c

  1315	
  1316	
  1317	/**
  1318	 * mpi3mr_cleanup_resources - Free PCI resources
  1319	 * @mrioc: Adapter instance reference
  1320	 *
  1321	 * Unmap PCI device memory and disable PCI device.
  1322	 *
  1323	 * Return: 0 on success and non-zero on failure.
  1324	 */
  1325	void mpi3mr_cleanup_resources(struct mpi3mr_ioc *mrioc)
  1326	{
  1327		struct pci_dev *pdev = mrioc->pdev;
  1328	
  1329		mpi3mr_cleanup_isr(mrioc);
  1330	
  1331		if (mrioc->sysif_regs) {
> 1332			iounmap(mrioc->sysif_regs);
  1333			mrioc->sysif_regs = NULL;
  1334		}
  1335	
  1336		if (pci_is_enabled(pdev)) {
  1337			if (mrioc->bars)
  1338				pci_release_selected_regions(pdev, mrioc->bars);
  1339			pci_disable_device(pdev);
  1340		}
  1341	}
  1342	
  1343	/**
  1344	 * mpi3mr_setup_resources - Enable PCI resources
  1345	 * @mrioc: Adapter instance reference
  1346	 *
  1347	 * Enable PCI device memory, MSI-x registers and set DMA mask.
  1348	 *
  1349	 * Return: 0 on success and non-zero on failure.
  1350	 */
  1351	int mpi3mr_setup_resources(struct mpi3mr_ioc *mrioc)
  1352	{
  1353		struct pci_dev *pdev = mrioc->pdev;
  1354		u32 memap_sz = 0;
  1355		int i, retval = 0, capb = 0;
  1356		u16 message_control;
  1357		u64 dma_mask = mrioc->dma_mask ? mrioc->dma_mask :
  1358		    (((dma_get_required_mask(&pdev->dev) > DMA_BIT_MASK(32)) &&
  1359		    (sizeof(dma_addr_t) > 4)) ? DMA_BIT_MASK(64):DMA_BIT_MASK(32));
  1360	
  1361		if (pci_enable_device_mem(pdev)) {
  1362			ioc_err(mrioc, "pci_enable_device_mem: failed\n");
  1363			retval = -ENODEV;
  1364			goto out_failed;
  1365		}
  1366	
  1367		capb = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
  1368		if (!capb) {
  1369			ioc_err(mrioc, "Unable to find MSI-X Capabilities\n");
  1370			retval = -ENODEV;
  1371			goto out_failed;
  1372		}
  1373		mrioc->bars = pci_select_bars(pdev, IORESOURCE_MEM);
  1374	
  1375		if (pci_request_selected_regions(pdev, mrioc->bars,
  1376		    mrioc->driver_name)) {
  1377			ioc_err(mrioc, "pci_request_selected_regions: failed\n");
  1378			retval = -ENODEV;
  1379			goto out_failed;
  1380		}
  1381	
  1382		for (i = 0; (i < DEVICE_COUNT_RESOURCE); i++) {
  1383			if (pci_resource_flags(pdev, i) & IORESOURCE_MEM) {
  1384				mrioc->sysif_regs_phys = pci_resource_start(pdev, i);
  1385				memap_sz = pci_resource_len(pdev, i);
  1386				mrioc->sysif_regs =
  1387				    ioremap(mrioc->sysif_regs_phys, memap_sz);
  1388				break;
  1389			}
  1390		}
  1391	
  1392		pci_set_master(pdev);
  1393	
  1394		retval = dma_set_mask_and_coherent(&pdev->dev, dma_mask);
  1395		if (retval) {
  1396			if (dma_mask != DMA_BIT_MASK(32)) {
  1397				ioc_warn(mrioc, "Setting 64 bit DMA mask failed\n");
  1398				dma_mask = DMA_BIT_MASK(32);
  1399				retval = dma_set_mask_and_coherent(&pdev->dev,
  1400				    dma_mask);
  1401			}
  1402			if (retval) {
  1403				mrioc->dma_mask = 0;
  1404				ioc_err(mrioc, "Setting 32 bit DMA mask also failed\n");
  1405				goto out_failed;
  1406			}
  1407		}
  1408		mrioc->dma_mask = dma_mask;
  1409	
  1410		if (mrioc->sysif_regs == NULL) {
  1411			ioc_err(mrioc,
  1412			    "Unable to map adapter memory or resource not found\n");
  1413			retval = -EINVAL;
  1414			goto out_failed;
  1415		}
  1416	
  1417		pci_read_config_word(pdev, capb + 2, &message_control);
  1418		mrioc->msix_count = (message_control & 0x3FF) + 1;
  1419	
  1420		pci_save_state(pdev);
  1421	
  1422		pci_set_drvdata(pdev, mrioc->shost);
  1423	
  1424		mpi3mr_ioc_disable_intr(mrioc);
  1425	
  1426		ioc_info(mrioc, "iomem(0x%016llx), mapped(0x%p), size(%d)\n",
  1427		    (unsigned long long)mrioc->sysif_regs_phys,
  1428		    mrioc->sysif_regs, memap_sz);
  1429		ioc_info(mrioc, "Number of MSI-X vectors found in capabilities: (%d)\n",
  1430		    mrioc->msix_count);
  1431		return retval;
  1432	
  1433	out_failed:
  1434		mpi3mr_cleanup_resources(mrioc);
  1435		return retval;
  1436	}
  1437	
  1438	/**
  1439	 * mpi3mr_init_ioc - Initialize the controller
  1440	 * @mrioc: Adapter instance reference
  1441	 *
  1442	 * This the controller initialization routine, executed either
  1443	 * after soft reset or from pci probe callback.
  1444	 * Setup the required resources, memory map the controller
  1445	 * registers, create admin and operational reply queue pairs,
  1446	 * allocate required memory for reply pool, sense buffer pool,
  1447	 * issue IOC init request to the firmware, unmask the events and
  1448	 * issue port enable to discover SAS/SATA/NVMe devies and RAID
  1449	 * volumes.
  1450	 *
  1451	 * Return: 0 on success and non-zero on failure.
  1452	 */
  1453	int mpi3mr_init_ioc(struct mpi3mr_ioc *mrioc)
  1454	{
  1455		int retval = 0;
  1456		enum mpi3mr_iocstate ioc_state;
  1457		u64 base_info;
  1458		u32 timeout;
  1459		u32 ioc_status, ioc_config;
  1460		Mpi3IOCFactsData_t facts_data;
  1461	
  1462		mrioc->change_count = 0;
  1463		mrioc->cpu_count = num_online_cpus();
  1464		retval = mpi3mr_setup_resources(mrioc);
  1465		if (retval) {
  1466			ioc_err(mrioc, "Failed to setup resources:error %d\n",
  1467			    retval);
  1468			goto out_nocleanup;
  1469		}
  1470		ioc_status = readl(&mrioc->sysif_regs->IOCStatus);
  1471		ioc_config = readl(&mrioc->sysif_regs->IOCConfiguration);
  1472	
  1473		ioc_info(mrioc, "SOD status %x configuration %x\n",
  1474		    ioc_status, ioc_config);
  1475	
> 1476		base_info = readq(&mrioc->sysif_regs->IOCInformation);
  1477		ioc_info(mrioc, "SOD base_info %llx\n",	base_info);
  1478	
  1479		/*The timeout value is in 2sec unit, changing it to seconds*/
  1480		mrioc->ready_timeout =
  1481		    ((base_info & MPI3_SYSIF_IOC_INFO_LOW_TIMEOUT_MASK) >>
  1482		    MPI3_SYSIF_IOC_INFO_LOW_TIMEOUT_SHIFT) * 2;
  1483	
  1484		ioc_info(mrioc, "IOC ready timeout %d\n", mrioc->ready_timeout);
  1485	
  1486		ioc_state = mpi3mr_get_iocstate(mrioc);
  1487		ioc_info(mrioc, "IOC in %s state during detection\n",
  1488		    mpi3mr_iocstate_name(ioc_state));
  1489	
  1490		if (ioc_state == MRIOC_STATE_BECOMING_READY ||
  1491				ioc_state == MRIOC_STATE_RESET_REQUESTED) {
  1492			timeout = mrioc->ready_timeout * 10;
  1493			do {
  1494				msleep(100);
  1495			} while (--timeout);
  1496	
  1497			ioc_state = mpi3mr_get_iocstate(mrioc);
  1498			ioc_info(mrioc,
  1499				"IOC in %s state after waiting for reset time\n",
  1500				mpi3mr_iocstate_name(ioc_state));
  1501		}
  1502	
  1503		if (ioc_state == MRIOC_STATE_READY) {
  1504			retval = mpi3mr_issue_and_process_mur(mrioc,
  1505			    MPI3MR_RESET_FROM_BRINGUP);
  1506			if (retval) {
  1507				ioc_err(mrioc, "Failed to MU reset IOC error %d\n",
  1508				    retval);
  1509			}
  1510			ioc_state = mpi3mr_get_iocstate(mrioc);
  1511		}
  1512		if (ioc_state != MRIOC_STATE_RESET) {
  1513			mpi3mr_print_fault_info(mrioc);
  1514			retval = mpi3mr_issue_reset(mrioc,
  1515			    MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET,
  1516			    MPI3MR_RESET_FROM_BRINGUP);
  1517			if (retval) {
  1518				ioc_err(mrioc,
  1519				    "%s :Failed to soft reset IOC error %d\n",
  1520				    __func__, retval);
  1521				goto out_failed;
  1522			}
  1523		}
  1524		ioc_state = mpi3mr_get_iocstate(mrioc);
  1525		if (ioc_state != MRIOC_STATE_RESET) {
  1526			ioc_err(mrioc, "Cannot bring IOC to reset state\n");
  1527			goto out_failed;
  1528		}
  1529	
  1530		retval = mpi3mr_setup_admin_qpair(mrioc);
  1531		if (retval) {
  1532			ioc_err(mrioc, "Failed to setup admin Qs: error %d\n",
  1533			    retval);
  1534			goto out_failed;
  1535		}
  1536	
  1537		retval = mpi3mr_bring_ioc_ready(mrioc);
  1538		if (retval) {
  1539			ioc_err(mrioc, "Failed to bring ioc ready: error %d\n",
  1540			    retval);
  1541			goto out_failed;
  1542		}
  1543	
  1544		retval = mpi3mr_setup_isr(mrioc, 1);
  1545		if (retval) {
  1546			ioc_err(mrioc, "Failed to setup ISR error %d\n",
  1547			    retval);
  1548			goto out_failed;
  1549		}
  1550	
  1551		retval = mpi3mr_issue_iocfacts(mrioc, &facts_data);
  1552		if (retval) {
  1553			ioc_err(mrioc, "Failed to Issue IOC Facts %d\n",
  1554			    retval);
  1555			goto out_failed;
  1556		}
  1557	
  1558		mpi3mr_process_factsdata(mrioc, &facts_data);
  1559		retval = mpi3mr_check_reset_dma_mask(mrioc);
  1560		if (retval) {
  1561			ioc_err(mrioc, "Resetting dma mask failed %d\n",
  1562			    retval);
  1563			goto out_failed;
  1564		}
  1565	
  1566		retval = mpi3mr_alloc_reply_sense_bufs(mrioc);
  1567		if (retval) {
  1568			ioc_err(mrioc,
  1569			    "%s :Failed to allocated reply sense buffers %d\n",
  1570			    __func__, retval);
  1571			goto out_failed;
  1572		}
  1573	
  1574		retval = mpi3mr_alloc_chain_bufs(mrioc);
  1575		if (retval) {
  1576			ioc_err(mrioc, "Failed to allocated chain buffers %d\n",
  1577			    retval);
  1578			goto out_failed;
  1579		}
  1580	
  1581		retval = mpi3mr_issue_iocinit(mrioc);
  1582		if (retval) {
  1583			ioc_err(mrioc, "Failed to Issue IOC Init %d\n",
  1584			    retval);
  1585			goto out_failed;
  1586		}
  1587		mrioc->reply_free_queue_host_index = mrioc->num_reply_bufs;
  1588		writel(mrioc->reply_free_queue_host_index,
  1589		    &mrioc->sysif_regs->ReplyFreeHostIndex);
  1590	
  1591		mrioc->sbq_host_index = mrioc->num_sense_bufs;
  1592		writel(mrioc->sbq_host_index,
  1593		    &mrioc->sysif_regs->SenseBufferFreeHostIndex);
  1594	
  1595		retval = mpi3mr_setup_isr(mrioc, 0);
  1596		if (retval) {
  1597			ioc_err(mrioc, "Failed to re-setup ISR, error %d\n",
  1598			    retval);
  1599			goto out_failed;
  1600		}
  1601	
  1602		return retval;
  1603	
  1604	out_failed:
  1605		mpi3mr_cleanup_ioc(mrioc);
  1606	out_nocleanup:
  1607		return retval;
  1608	}
  1609	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 66536 bytes --]

^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 02/24] mpi3mr: base driver code
@ 2020-12-27 14:14     ` kernel test robot
  0 siblings, 0 replies; 75+ messages in thread
From: kernel test robot @ 2020-12-27 14:14 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 15509 bytes --]

Hi Kashyap,

I love your patch! Yet something to improve:

[auto build test ERROR on mkp-scsi/for-next]
[also build test ERROR on scsi/for-next v5.10 next-20201223]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Kashyap-Desai/Introducing-mpi3mr-driver/20201222-181732
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git for-next
config: arc-allyesconfig (attached as .config)
compiler: arceb-elf-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/f1507bd10ed4f38cbe02ec83c46bcac080b681cb
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Kashyap-Desai/Introducing-mpi3mr-driver/20201222-181732
        git checkout f1507bd10ed4f38cbe02ec83c46bcac080b681cb
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arc 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All error/warnings (new ones prefixed by >>):

   drivers/scsi/mpi3mr/mpi3mr_fw.c: In function 'mpi3mr_isr':
   drivers/scsi/mpi3mr/mpi3mr_fw.c:315:6: warning: variable 'midx' set but not used [-Wunused-but-set-variable]
     315 |  u16 midx;
         |      ^~~~
   drivers/scsi/mpi3mr/mpi3mr_fw.c:314:21: warning: variable 'mrioc' set but not used [-Wunused-but-set-variable]
     314 |  struct mpi3mr_ioc *mrioc;
         |                     ^~~~~
   In file included from include/linux/printk.h:7,
                    from include/linux/kernel.h:16,
                    from include/linux/list.h:9,
                    from include/linux/rculist.h:10,
                    from include/linux/pid.h:5,
                    from include/linux/sched.h:14,
                    from include/linux/blkdev.h:5,
                    from drivers/scsi/mpi3mr/mpi3mr.h:13,
                    from drivers/scsi/mpi3mr/mpi3mr_fw.c:10:
   drivers/scsi/mpi3mr/mpi3mr_fw.c: In function 'mpi3mr_process_factsdata':
   include/linux/kern_levels.h:5:18: warning: format '%ld' expects argument of type 'long int', but argument 3 has type 'unsigned int' [-Wformat=]
       5 | #define KERN_SOH "\001"  /* ASCII Start Of Header */
         |                  ^~~~~~
   include/linux/kern_levels.h:12:22: note: in expansion of macro 'KERN_SOH'
      12 | #define KERN_WARNING KERN_SOH "4" /* warning conditions */
         |                      ^~~~~~~~
   include/linux/printk.h:353:9: note: in expansion of macro 'KERN_WARNING'
     353 |  printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
         |         ^~~~~~~~~~~~
   drivers/scsi/mpi3mr/mpi3mr_debug.h:49:2: note: in expansion of macro 'pr_warn'
      49 |  pr_warn("%s: " fmt, (ioc)->name, ##__VA_ARGS__)
         |  ^~~~~~~
   drivers/scsi/mpi3mr/mpi3mr_fw.c:933:3: note: in expansion of macro 'ioc_warn'
     933 |   ioc_warn(mrioc,
         |   ^~~~~~~~
   drivers/scsi/mpi3mr/mpi3mr_fw.c:934:49: note: format string is defined here
     934 |       "IOCFactsdata length mismatch driver_sz(%ld) firmware_sz(%d)\n",
         |                                               ~~^
         |                                                 |
         |                                                 long int
         |                                               %d
   drivers/scsi/mpi3mr/mpi3mr_fw.c: In function 'mpi3mr_cleanup_resources':
>> drivers/scsi/mpi3mr/mpi3mr_fw.c:1332:16: warning: passing argument 1 of 'iounmap' discards 'volatile' qualifier from pointer target type [-Wdiscarded-qualifiers]
    1332 |   iounmap(mrioc->sysif_regs);
         |           ~~~~~^~~~~~~~~~~~
   In file included from include/linux/io.h:13,
                    from include/linux/irq.h:20,
                    from include/asm-generic/hardirq.h:13,
                    from ./arch/arc/include/generated/asm/hardirq.h:1,
                    from include/linux/hardirq.h:10,
                    from include/linux/highmem.h:10,
                    from include/linux/pagemap.h:11,
                    from include/linux/blkdev.h:14,
                    from drivers/scsi/mpi3mr/mpi3mr.h:13,
                    from drivers/scsi/mpi3mr/mpi3mr_fw.c:10:
   arch/arc/include/asm/io.h:35:41: note: expected 'const void *' but argument is of type 'volatile Mpi3SysIfRegs_t *' {aka 'volatile struct _MPI3_SYSIF_REGISTERS *'}
      35 | extern void iounmap(const void __iomem *addr);
         |                     ~~~~~~~~~~~~~~~~~~~~^~~~
   drivers/scsi/mpi3mr/mpi3mr_fw.c: In function 'mpi3mr_init_ioc':
>> drivers/scsi/mpi3mr/mpi3mr_fw.c:1476:14: error: implicit declaration of function 'readq'; did you mean 'readl'? [-Werror=implicit-function-declaration]
    1476 |  base_info = readq(&mrioc->sysif_regs->IOCInformation);
         |              ^~~~~
         |              readl
   cc1: some warnings being treated as errors


vim +1476 drivers/scsi/mpi3mr/mpi3mr_fw.c

  1315	
  1316	
  1317	/**
  1318	 * mpi3mr_cleanup_resources - Free PCI resources
  1319	 * @mrioc: Adapter instance reference
  1320	 *
  1321	 * Unmap PCI device memory and disable PCI device.
  1322	 *
  1323	 * Return: 0 on success and non-zero on failure.
  1324	 */
  1325	void mpi3mr_cleanup_resources(struct mpi3mr_ioc *mrioc)
  1326	{
  1327		struct pci_dev *pdev = mrioc->pdev;
  1328	
  1329		mpi3mr_cleanup_isr(mrioc);
  1330	
  1331		if (mrioc->sysif_regs) {
> 1332			iounmap(mrioc->sysif_regs);
  1333			mrioc->sysif_regs = NULL;
  1334		}
  1335	
  1336		if (pci_is_enabled(pdev)) {
  1337			if (mrioc->bars)
  1338				pci_release_selected_regions(pdev, mrioc->bars);
  1339			pci_disable_device(pdev);
  1340		}
  1341	}
  1342	
  1343	/**
  1344	 * mpi3mr_setup_resources - Enable PCI resources
  1345	 * @mrioc: Adapter instance reference
  1346	 *
  1347	 * Enable PCI device memory, MSI-x registers and set DMA mask.
  1348	 *
  1349	 * Return: 0 on success and non-zero on failure.
  1350	 */
  1351	int mpi3mr_setup_resources(struct mpi3mr_ioc *mrioc)
  1352	{
  1353		struct pci_dev *pdev = mrioc->pdev;
  1354		u32 memap_sz = 0;
  1355		int i, retval = 0, capb = 0;
  1356		u16 message_control;
  1357		u64 dma_mask = mrioc->dma_mask ? mrioc->dma_mask :
  1358		    (((dma_get_required_mask(&pdev->dev) > DMA_BIT_MASK(32)) &&
  1359		    (sizeof(dma_addr_t) > 4)) ? DMA_BIT_MASK(64):DMA_BIT_MASK(32));
  1360	
  1361		if (pci_enable_device_mem(pdev)) {
  1362			ioc_err(mrioc, "pci_enable_device_mem: failed\n");
  1363			retval = -ENODEV;
  1364			goto out_failed;
  1365		}
  1366	
  1367		capb = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
  1368		if (!capb) {
  1369			ioc_err(mrioc, "Unable to find MSI-X Capabilities\n");
  1370			retval = -ENODEV;
  1371			goto out_failed;
  1372		}
  1373		mrioc->bars = pci_select_bars(pdev, IORESOURCE_MEM);
  1374	
  1375		if (pci_request_selected_regions(pdev, mrioc->bars,
  1376		    mrioc->driver_name)) {
  1377			ioc_err(mrioc, "pci_request_selected_regions: failed\n");
  1378			retval = -ENODEV;
  1379			goto out_failed;
  1380		}
  1381	
  1382		for (i = 0; (i < DEVICE_COUNT_RESOURCE); i++) {
  1383			if (pci_resource_flags(pdev, i) & IORESOURCE_MEM) {
  1384				mrioc->sysif_regs_phys = pci_resource_start(pdev, i);
  1385				memap_sz = pci_resource_len(pdev, i);
  1386				mrioc->sysif_regs =
  1387				    ioremap(mrioc->sysif_regs_phys, memap_sz);
  1388				break;
  1389			}
  1390		}
  1391	
  1392		pci_set_master(pdev);
  1393	
  1394		retval = dma_set_mask_and_coherent(&pdev->dev, dma_mask);
  1395		if (retval) {
  1396			if (dma_mask != DMA_BIT_MASK(32)) {
  1397				ioc_warn(mrioc, "Setting 64 bit DMA mask failed\n");
  1398				dma_mask = DMA_BIT_MASK(32);
  1399				retval = dma_set_mask_and_coherent(&pdev->dev,
  1400				    dma_mask);
  1401			}
  1402			if (retval) {
  1403				mrioc->dma_mask = 0;
  1404				ioc_err(mrioc, "Setting 32 bit DMA mask also failed\n");
  1405				goto out_failed;
  1406			}
  1407		}
  1408		mrioc->dma_mask = dma_mask;
  1409	
  1410		if (mrioc->sysif_regs == NULL) {
  1411			ioc_err(mrioc,
  1412			    "Unable to map adapter memory or resource not found\n");
  1413			retval = -EINVAL;
  1414			goto out_failed;
  1415		}
  1416	
  1417		pci_read_config_word(pdev, capb + 2, &message_control);
  1418		mrioc->msix_count = (message_control & 0x3FF) + 1;
  1419	
  1420		pci_save_state(pdev);
  1421	
  1422		pci_set_drvdata(pdev, mrioc->shost);
  1423	
  1424		mpi3mr_ioc_disable_intr(mrioc);
  1425	
  1426		ioc_info(mrioc, "iomem(0x%016llx), mapped(0x%p), size(%d)\n",
  1427		    (unsigned long long)mrioc->sysif_regs_phys,
  1428		    mrioc->sysif_regs, memap_sz);
  1429		ioc_info(mrioc, "Number of MSI-X vectors found in capabilities: (%d)\n",
  1430		    mrioc->msix_count);
  1431		return retval;
  1432	
  1433	out_failed:
  1434		mpi3mr_cleanup_resources(mrioc);
  1435		return retval;
  1436	}
  1437	
  1438	/**
  1439	 * mpi3mr_init_ioc - Initialize the controller
  1440	 * @mrioc: Adapter instance reference
  1441	 *
  1442	 * This the controller initialization routine, executed either
  1443	 * after soft reset or from pci probe callback.
  1444	 * Setup the required resources, memory map the controller
  1445	 * registers, create admin and operational reply queue pairs,
  1446	 * allocate required memory for reply pool, sense buffer pool,
  1447	 * issue IOC init request to the firmware, unmask the events and
  1448	 * issue port enable to discover SAS/SATA/NVMe devies and RAID
  1449	 * volumes.
  1450	 *
  1451	 * Return: 0 on success and non-zero on failure.
  1452	 */
  1453	int mpi3mr_init_ioc(struct mpi3mr_ioc *mrioc)
  1454	{
  1455		int retval = 0;
  1456		enum mpi3mr_iocstate ioc_state;
  1457		u64 base_info;
  1458		u32 timeout;
  1459		u32 ioc_status, ioc_config;
  1460		Mpi3IOCFactsData_t facts_data;
  1461	
  1462		mrioc->change_count = 0;
  1463		mrioc->cpu_count = num_online_cpus();
  1464		retval = mpi3mr_setup_resources(mrioc);
  1465		if (retval) {
  1466			ioc_err(mrioc, "Failed to setup resources:error %d\n",
  1467			    retval);
  1468			goto out_nocleanup;
  1469		}
  1470		ioc_status = readl(&mrioc->sysif_regs->IOCStatus);
  1471		ioc_config = readl(&mrioc->sysif_regs->IOCConfiguration);
  1472	
  1473		ioc_info(mrioc, "SOD status %x configuration %x\n",
  1474		    ioc_status, ioc_config);
  1475	
> 1476		base_info = readq(&mrioc->sysif_regs->IOCInformation);
  1477		ioc_info(mrioc, "SOD base_info %llx\n",	base_info);
  1478	
  1479		/*The timeout value is in 2sec unit, changing it to seconds*/
  1480		mrioc->ready_timeout =
  1481		    ((base_info & MPI3_SYSIF_IOC_INFO_LOW_TIMEOUT_MASK) >>
  1482		    MPI3_SYSIF_IOC_INFO_LOW_TIMEOUT_SHIFT) * 2;
  1483	
  1484		ioc_info(mrioc, "IOC ready timeout %d\n", mrioc->ready_timeout);
  1485	
  1486		ioc_state = mpi3mr_get_iocstate(mrioc);
  1487		ioc_info(mrioc, "IOC in %s state during detection\n",
  1488		    mpi3mr_iocstate_name(ioc_state));
  1489	
  1490		if (ioc_state == MRIOC_STATE_BECOMING_READY ||
  1491				ioc_state == MRIOC_STATE_RESET_REQUESTED) {
  1492			timeout = mrioc->ready_timeout * 10;
  1493			do {
  1494				msleep(100);
  1495			} while (--timeout);
  1496	
  1497			ioc_state = mpi3mr_get_iocstate(mrioc);
  1498			ioc_info(mrioc,
  1499				"IOC in %s state after waiting for reset time\n",
  1500				mpi3mr_iocstate_name(ioc_state));
  1501		}
  1502	
  1503		if (ioc_state == MRIOC_STATE_READY) {
  1504			retval = mpi3mr_issue_and_process_mur(mrioc,
  1505			    MPI3MR_RESET_FROM_BRINGUP);
  1506			if (retval) {
  1507				ioc_err(mrioc, "Failed to MU reset IOC error %d\n",
  1508				    retval);
  1509			}
  1510			ioc_state = mpi3mr_get_iocstate(mrioc);
  1511		}
  1512		if (ioc_state != MRIOC_STATE_RESET) {
  1513			mpi3mr_print_fault_info(mrioc);
  1514			retval = mpi3mr_issue_reset(mrioc,
  1515			    MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET,
  1516			    MPI3MR_RESET_FROM_BRINGUP);
  1517			if (retval) {
  1518				ioc_err(mrioc,
  1519				    "%s :Failed to soft reset IOC error %d\n",
  1520				    __func__, retval);
  1521				goto out_failed;
  1522			}
  1523		}
  1524		ioc_state = mpi3mr_get_iocstate(mrioc);
  1525		if (ioc_state != MRIOC_STATE_RESET) {
  1526			ioc_err(mrioc, "Cannot bring IOC to reset state\n");
  1527			goto out_failed;
  1528		}
  1529	
  1530		retval = mpi3mr_setup_admin_qpair(mrioc);
  1531		if (retval) {
  1532			ioc_err(mrioc, "Failed to setup admin Qs: error %d\n",
  1533			    retval);
  1534			goto out_failed;
  1535		}
  1536	
  1537		retval = mpi3mr_bring_ioc_ready(mrioc);
  1538		if (retval) {
  1539			ioc_err(mrioc, "Failed to bring ioc ready: error %d\n",
  1540			    retval);
  1541			goto out_failed;
  1542		}
  1543	
  1544		retval = mpi3mr_setup_isr(mrioc, 1);
  1545		if (retval) {
  1546			ioc_err(mrioc, "Failed to setup ISR error %d\n",
  1547			    retval);
  1548			goto out_failed;
  1549		}
  1550	
  1551		retval = mpi3mr_issue_iocfacts(mrioc, &facts_data);
  1552		if (retval) {
  1553			ioc_err(mrioc, "Failed to Issue IOC Facts %d\n",
  1554			    retval);
  1555			goto out_failed;
  1556		}
  1557	
  1558		mpi3mr_process_factsdata(mrioc, &facts_data);
  1559		retval = mpi3mr_check_reset_dma_mask(mrioc);
  1560		if (retval) {
  1561			ioc_err(mrioc, "Resetting dma mask failed %d\n",
  1562			    retval);
  1563			goto out_failed;
  1564		}
  1565	
  1566		retval = mpi3mr_alloc_reply_sense_bufs(mrioc);
  1567		if (retval) {
  1568			ioc_err(mrioc,
  1569			    "%s :Failed to allocated reply sense buffers %d\n",
  1570			    __func__, retval);
  1571			goto out_failed;
  1572		}
  1573	
  1574		retval = mpi3mr_alloc_chain_bufs(mrioc);
  1575		if (retval) {
  1576			ioc_err(mrioc, "Failed to allocated chain buffers %d\n",
  1577			    retval);
  1578			goto out_failed;
  1579		}
  1580	
  1581		retval = mpi3mr_issue_iocinit(mrioc);
  1582		if (retval) {
  1583			ioc_err(mrioc, "Failed to Issue IOC Init %d\n",
  1584			    retval);
  1585			goto out_failed;
  1586		}
  1587		mrioc->reply_free_queue_host_index = mrioc->num_reply_bufs;
  1588		writel(mrioc->reply_free_queue_host_index,
  1589		    &mrioc->sysif_regs->ReplyFreeHostIndex);
  1590	
  1591		mrioc->sbq_host_index = mrioc->num_sense_bufs;
  1592		writel(mrioc->sbq_host_index,
  1593		    &mrioc->sysif_regs->SenseBufferFreeHostIndex);
  1594	
  1595		retval = mpi3mr_setup_isr(mrioc, 0);
  1596		if (retval) {
  1597			ioc_err(mrioc, "Failed to re-setup ISR, error %d\n",
  1598			    retval);
  1599			goto out_failed;
  1600		}
  1601	
  1602		return retval;
  1603	
  1604	out_failed:
  1605		mpi3mr_cleanup_ioc(mrioc);
  1606	out_nocleanup:
  1607		return retval;
  1608	}
  1609	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 66536 bytes --]

^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 04/24] mpi3mr: add support of queue command processing
  2020-12-22 10:11 ` [PATCH 04/24] mpi3mr: add support of queue command processing Kashyap Desai
@ 2021-02-22 15:23   ` Tomas Henzl
  2021-02-25 13:24     ` Kashyap Desai
  2021-02-28 13:22   ` Hannes Reinecke
  1 sibling, 1 reply; 75+ messages in thread
From: Tomas Henzl @ 2021-02-22 15:23 UTC (permalink / raw)
  To: Kashyap Desai, linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, sathya.prakash

On 12/22/20 11:11 AM, Kashyap Desai wrote:
> Send Port Enable Request to FW for Device Discovery.
> As part of port enable completion driver calls scan_start and
> scan_finished hooks.
> scsi layer reference like sdev, starget etc is added but actual
> device discovery will be supported once driver add complete event
> process handling (It is added in subsequent patches)
> 
> This patch provides interface which is used to interact with FW
> via operational queue pairs.
> 
> Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
> Cc: sathya.prakash@broadcom.com
> ---
>  drivers/scsi/mpi3mr/mpi3mr.h    |  52 +++
>  drivers/scsi/mpi3mr/mpi3mr_fw.c | 251 +++++++++++++
>  drivers/scsi/mpi3mr/mpi3mr_os.c | 645 +++++++++++++++++++++++++++++++-
>  3 files changed, 946 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/scsi/mpi3mr/mpi3mr.h b/drivers/scsi/mpi3mr/mpi3mr.h
> index fe6094bb357a..f23751e25d0f 100644
> --- a/drivers/scsi/mpi3mr/mpi3mr.h
> +++ b/drivers/scsi/mpi3mr/mpi3mr.h
> @@ -96,6 +96,7 @@ extern struct list_head mrioc_list;
>  
>  /* command/controller interaction timeout definitions in seconds */
>  #define MPI3MR_INTADMCMD_TIMEOUT		10
> +#define MPI3MR_PORTENABLE_TIMEOUT		300
>  #define MPI3MR_RESETTM_TIMEOUT			30
>  #define MPI3MR_DEFAULT_SHUTDOWN_TIME		120
>  
> @@ -312,6 +313,43 @@ struct mpi3mr_intr_info {
>  	char name[MPI3MR_NAME_LENGTH];
>  };
>  
> +/**
> + * struct mpi3mr_stgt_priv_data - SCSI target private structure
> + *
> + * @starget: Scsi_target pointer
> + * @dev_handle: FW device handle
> + * @perst_id: FW assigned Persistent ID
> + * @num_luns: Number of Logical Units
> + * @block_io: I/O blocked to the device or not
> + * @dev_removed: Device removed in the Firmware
> + * @dev_removedelay: Device is waiting to be removed in FW
> + * @dev_type: Device type
> + * @tgt_dev: Internal target device pointer
> + */
> +struct mpi3mr_stgt_priv_data {
> +	struct scsi_target *starget;
> +	u16 dev_handle;
> +	u16 perst_id;
> +	u32 num_luns;
> +	atomic_t block_io;
> +	u8 dev_removed;
> +	u8 dev_removedelay;
> +	u8 dev_type;
> +	struct mpi3mr_tgt_dev *tgt_dev;
> +};
> +
> +/**
> + * struct mpi3mr_stgt_priv_data - SCSI device private structure
> + *
> + * @tgt_priv_data: Scsi_target private data pointer
> + * @lun_id: LUN ID of the device
> + * @ncq_prio_enable: NCQ priority enable for SATA device
> + */
> +struct mpi3mr_sdev_priv_data {
> +	struct mpi3mr_stgt_priv_data *tgt_priv_data;
> +	u32 lun_id;
> +	u8 ncq_prio_enable;
> +};
>  
>  typedef struct mpi3mr_drv_cmd DRV_CMD;
>  typedef void (*DRV_CMD_CALLBACK)(struct mpi3mr_ioc *mrioc,
> @@ -443,12 +481,16 @@ struct scmd_priv {
>   * @sbq_lock: Sense buffer queue lock
>   * @sbq_host_index: Sense buffer queuehost index
>   * @is_driver_loading: Is driver still loading
> + * @scan_started: Async scan started
> + * @scan_failed: Asycn scan failed
> + * @stop_drv_processing: Stop all command processing
>   * @max_host_ios: Maximum host I/O count
>   * @chain_buf_count: Chain buffer count
>   * @chain_buf_pool: Chain buffer pool
>   * @chain_sgl_list: Chain SGL list
>   * @chain_bitmap_sz: Chain buffer allocator bitmap size
>   * @chain_bitmap: Chain buffer allocator bitmap
> + * @chain_buf_lock: Chain buffer list lock
>   * @reset_in_progress: Reset in progress flag
>   * @unrecoverable: Controller unrecoverable flag
>   * @logging_level: Controller debug logging level
> @@ -533,6 +575,9 @@ struct mpi3mr_ioc {
>  	u32 sbq_host_index;
>  
>  	u8 is_driver_loading;
> +	u8 scan_started;
> +	u16 scan_failed;
> +	u8 stop_drv_processing;
>  
>  	u16 max_host_ios;
>  
> @@ -541,6 +586,7 @@ struct mpi3mr_ioc {
>  	struct chain_element *chain_sgl_list;
>  	u16  chain_bitmap_sz;
>  	void *chain_bitmap;
> +	spinlock_t chain_buf_lock;
>  
>  	u8 reset_in_progress;
>  	u8 unrecoverable;
> @@ -557,8 +603,11 @@ int mpi3mr_setup_resources(struct mpi3mr_ioc *mrioc);
>  void mpi3mr_cleanup_resources(struct mpi3mr_ioc *mrioc);
>  int mpi3mr_init_ioc(struct mpi3mr_ioc *mrioc);
>  void mpi3mr_cleanup_ioc(struct mpi3mr_ioc *mrioc);
> +int mpi3mr_issue_port_enable(struct mpi3mr_ioc *mrioc, u8 async);
>  int mpi3mr_admin_request_post(struct mpi3mr_ioc *mrioc, void *admin_req,
>  u16 admin_req_sz, u8 ignore_reset);
> +int mpi3mr_op_request_post(struct mpi3mr_ioc *mrioc,
> +			   struct op_req_qinfo *opreqq, u8 *req);
>  void mpi3mr_add_sg_single(void *paddr, u8 flags, u32 length,
>  			  dma_addr_t dma_addr);
>  void mpi3mr_build_zero_len_sge(void *paddr);
> @@ -569,6 +618,9 @@ void *mpi3mr_get_reply_virt_addr(struct mpi3mr_ioc *mrioc,
>  void mpi3mr_repost_sense_buf(struct mpi3mr_ioc *mrioc,
>  				     u64 sense_buf_dma);
>  
> +void mpi3mr_process_op_reply_desc(struct mpi3mr_ioc *mrioc,
> +				  Mpi3DefaultReplyDescriptor_t *reply_desc,
> +				  u64 *reply_dma, u16 qidx);
>  void mpi3mr_start_watchdog(struct mpi3mr_ioc *mrioc);
>  void mpi3mr_stop_watchdog(struct mpi3mr_ioc *mrioc);
>  
> diff --git a/drivers/scsi/mpi3mr/mpi3mr_fw.c b/drivers/scsi/mpi3mr/mpi3mr_fw.c
> index 6fb28983038e..abdf8c653e6b 100644
> --- a/drivers/scsi/mpi3mr/mpi3mr_fw.c
> +++ b/drivers/scsi/mpi3mr/mpi3mr_fw.c
> @@ -24,6 +24,23 @@ static inline void mpi3mr_writeq(__u64 b, volatile void __iomem *addr)
>  }
>  #endif
>  
> +static inline bool
> +mpi3mr_check_req_qfull(struct op_req_qinfo *op_req_q)
> +{
> +	u16 pi, ci, max_entries;
> +	bool is_qfull = false;
> +
> +	pi = op_req_q->pi;
> +	ci = op_req_q->ci;
> +	max_entries = op_req_q->num_requests;
> +
> +	if ((ci == (pi + 1)) || ((!ci) && (pi == (max_entries - 1))))
> +		is_qfull = true;
> +
> +	return is_qfull;
> +}
> +
> +
>  static void mpi3mr_sync_irqs(struct mpi3mr_ioc *mrioc)
>  {
>  	u16 i, max_vectors;
> @@ -282,6 +299,87 @@ static int mpi3mr_process_admin_reply_q(struct mpi3mr_ioc *mrioc)
>  	return num_admin_replies;
>  }
>  
> +/**
> + * mpi3mr_get_reply_desc - get reply descriptor frame corresponding to
> + *	queue's consumer index from operational reply descriptor queue.
> + * @op_reply_q: op_reply_qinfo object
> + * @reply_ci: operational reply descriptor's queue consumer index
> + *
> + * Returns reply descriptor frame address
> + */
> +static inline Mpi3DefaultReplyDescriptor_t *
> +mpi3mr_get_reply_desc(struct op_reply_qinfo *op_reply_q, u32 reply_ci)
> +{
> +	void *segment_base_addr;
> +	struct segments *segments = op_reply_q->q_segments;
> +	Mpi3DefaultReplyDescriptor_t *reply_desc = NULL;
> +
> +	segment_base_addr =
> +	    segments[reply_ci / op_reply_q->segment_qd].segment;
> +	reply_desc = (Mpi3DefaultReplyDescriptor_t *)segment_base_addr +
> +	    (reply_ci % op_reply_q->segment_qd);
> +	return reply_desc;
> +}
> +
> +
> +static int mpi3mr_process_op_reply_q(struct mpi3mr_ioc *mrioc,
> +	struct mpi3mr_intr_info *intr_info)
> +{
> +	struct op_reply_qinfo *op_reply_q = intr_info->op_reply_q;
> +	struct op_req_qinfo *op_req_q;
> +	u32 exp_phase;
> +	u32 reply_ci;
> +	u32 num_op_reply = 0;
> +	u64 reply_dma = 0;
> +	Mpi3DefaultReplyDescriptor_t *reply_desc;
> +	u16 req_q_idx = 0, reply_qidx;
> +
> +	reply_qidx = op_reply_q->qid - 1;
> +
> +	exp_phase = op_reply_q->ephase;
> +	reply_ci = op_reply_q->ci;
> +
> +	reply_desc = mpi3mr_get_reply_desc(op_reply_q, reply_ci);
> +	if ((le16_to_cpu(reply_desc->ReplyFlags) &
> +	    MPI3_REPLY_DESCRIPT_FLAGS_PHASE_MASK) != exp_phase) {
> +		return 0;
> +	}
> +
> +	do {
> +		req_q_idx = le16_to_cpu(reply_desc->RequestQueueID) - 1;
> +		op_req_q = &mrioc->req_qinfo[req_q_idx];
> +
> +		op_req_q->ci =
> +		    le16_to_cpu(reply_desc->RequestQueueCI);
> +
> +		mpi3mr_process_op_reply_desc(mrioc, reply_desc, &reply_dma,
> +		    reply_qidx);
> +		if (reply_dma)
> +			mpi3mr_repost_reply_buf(mrioc, reply_dma);
> +		num_op_reply++;
> +
> +		if (++reply_ci == op_reply_q->num_replies) {
> +			reply_ci = 0;
> +			exp_phase ^= 1;
> +		}
> +
> +		reply_desc = mpi3mr_get_reply_desc(op_reply_q, reply_ci);
> +
> +		if ((le16_to_cpu(reply_desc->ReplyFlags) &
> +		    MPI3_REPLY_DESCRIPT_FLAGS_PHASE_MASK) != exp_phase)
> +			break;
> +
> +	} while (1);
> +
> +
> +	writel(reply_ci,
> +	    &mrioc->sysif_regs->OperQueueIndexes[reply_qidx].ConsumerIndex);
> +	op_reply_q->ci = reply_ci;
> +	op_reply_q->ephase = exp_phase;
> +
> +	return num_op_reply;
> +}
> +
>  static irqreturn_t mpi3mr_isr_primary(int irq, void *privdata)
>  {
>  	struct mpi3mr_intr_info *intr_info = privdata;
> @@ -1314,6 +1412,74 @@ static int mpi3mr_create_op_queues(struct mpi3mr_ioc *mrioc)
>  	return retval;
>  }
>  
> +/**
> + * mpi3mr_op_request_post - Post request to operational queue
> + * @mrioc: Adapter reference
> + * @op_req_q: Operational request queue info
> + * @req: MPI3 request
> + *
> + * Post the MPI3 request into operational request queue and
> + * inform the controller, if the queue is full return
> + * appropriate error.
> + *
> + * Return: 0 on success, non-zero on failure.
> + */
> +int mpi3mr_op_request_post(struct mpi3mr_ioc *mrioc,
> +	struct op_req_qinfo *op_req_q, u8 *req)
> +{
> +	u16 pi = 0, max_entries, reply_qidx = 0, midx;
> +	int retval = 0;
> +	unsigned long flags;
> +	u8 *req_entry;
> +	void *segment_base_addr;
> +	u16 req_sz = mrioc->facts.op_req_sz;
> +	struct segments *segments = op_req_q->q_segments;
> +
> +	reply_qidx = op_req_q->reply_qid - 1;
> +
> +	if (mrioc->unrecoverable)
> +		return -EFAULT;
> +
> +	spin_lock_irqsave(&op_req_q->q_lock, flags);
> +	pi = op_req_q->pi;
> +	max_entries = op_req_q->num_requests;
> +
> +	if (mpi3mr_check_req_qfull(op_req_q)) {
> +		midx = REPLY_QUEUE_IDX_TO_MSIX_IDX(
> +		    reply_qidx, mrioc->op_reply_q_offset);
> +		mpi3mr_process_op_reply_q(mrioc, &mrioc->intr_info[midx]);
> +
> +		if (mpi3mr_check_req_qfull(op_req_q)) {
> +			retval = -EAGAIN;
> +			goto out;
> +		}
> +	}
> +
> +	if (mrioc->reset_in_progress) {
> +		ioc_err(mrioc, "OpReqQ submit reset in progress\n");
> +		retval = -EAGAIN;
> +		goto out;
> +	}
> +
> +	segment_base_addr = segments[pi / op_req_q->segment_qd].segment;
> +	req_entry = (u8 *)segment_base_addr +
> +	    ((pi % op_req_q->segment_qd) * req_sz);
> +
> +	memset(req_entry, 0, req_sz);
> +	memcpy(req_entry, req, MPI3MR_ADMIN_REQ_FRAME_SZ);
> +
> +	if (++pi == max_entries)
> +		pi = 0;
> +	op_req_q->pi = pi;
> +
> +	writel(op_req_q->pi,
> +	    &mrioc->sysif_regs->OperQueueIndexes[reply_qidx].ProducerIndex);
> +
> +out:
> +	spin_unlock_irqrestore(&op_req_q->q_lock, flags);
> +	return retval;
> +}
> +
>  
>  /**
>   * mpi3mr_setup_admin_qpair - Setup admin queue pair
> @@ -1901,6 +2067,91 @@ static int mpi3mr_alloc_chain_bufs(struct mpi3mr_ioc *mrioc)
>  	return retval;
>  }
>  
> +/**
> + * mpi3mr_port_enable_complete - Mark port enable complete
> + * @mrioc: Adapter instance reference
> + * @drv_cmd: Internal command tracker
> + *
> + * Call back for asynchronous port enable request sets the
> + * driver command to indicate port enable request is complete.
> + *
> + * Return: Nothing
> + */
> +static void mpi3mr_port_enable_complete(struct mpi3mr_ioc *mrioc,
> +	struct mpi3mr_drv_cmd *drv_cmd)
> +{
> +
> +	drv_cmd->state = MPI3MR_CMD_NOTUSED;
> +	drv_cmd->callback = NULL;
> +	mrioc->scan_failed = drv_cmd->ioc_status;
> +	mrioc->scan_started = 0;
> +
> +}
> +
> +/**
> + * mpi3mr_issue_port_enable - Issue Port Enable
> + * @mrioc: Adapter instance reference
> + * @async: Flag to wait for completion or not
> + *
> + * Issue Port Enable MPI request through admin queue and if the
> + * async flag is not set wait for the completion of the port
> + * enable or time out.
> + *
> + * Return: 0 on success, non-zero on failures.
> + */
> +int mpi3mr_issue_port_enable(struct mpi3mr_ioc *mrioc, u8 async)
> +{
> +	Mpi3PortEnableRequest_t pe_req;
> +	int retval = 0;
> +	u32 pe_timeout = MPI3MR_PORTENABLE_TIMEOUT;
> +
> +	memset(&pe_req, 0, sizeof(pe_req));
> +	mutex_lock(&mrioc->init_cmds.mutex);
> +	if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
> +		retval = -1;
> +		ioc_err(mrioc, "Issue PortEnable: Init command is in use\n");
> +		mutex_unlock(&mrioc->init_cmds.mutex);
> +		goto out;
> +	}
> +	mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
> +	if (async) {
> +		mrioc->init_cmds.is_waiting = 0;
> +		mrioc->init_cmds.callback = mpi3mr_port_enable_complete;
> +	} else {
> +		mrioc->init_cmds.is_waiting = 1;
> +		mrioc->init_cmds.callback = NULL;
> +		init_completion(&mrioc->init_cmds.done);
> +	}
> +	pe_req.HostTag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
> +	pe_req.Function = MPI3_FUNCTION_PORT_ENABLE;
> +
> +	retval = mpi3mr_admin_request_post(mrioc, &pe_req, sizeof(pe_req), 1);
> +	if (retval) {
> +		ioc_err(mrioc, "Issue PortEnable: Admin Post failed\n");
> +		goto out_unlock;
> +	}
> +	if (!async) {
> +		wait_for_completion_timeout(&mrioc->init_cmds.done,
> +		    (pe_timeout * HZ));
> +		if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
> +			ioc_err(mrioc, "Issue PortEnable: command timed out\n");
> +			retval = -1;
> +			mrioc->scan_failed = MPI3_IOCSTATUS_INTERNAL_ERROR;
> +			mpi3mr_set_diagsave(mrioc);
> +			mpi3mr_issue_reset(mrioc,
> +			    MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT,
> +			    MPI3MR_RESET_FROM_PE_TIMEOUT);
> +			mrioc->unrecoverable = 1;
> +			goto out_unlock;
> +		}
> +		mpi3mr_port_enable_complete(mrioc, &mrioc->init_cmds);
> +	}
> +out_unlock:
> +	mutex_unlock(&mrioc->init_cmds.mutex);
> +out:
> +	return retval;
> +}
> +
>  
>  /**
>   * mpi3mr_cleanup_resources - Free PCI resources
> diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c
> index 3cf0be63842f..01be5f337826 100644
> --- a/drivers/scsi/mpi3mr/mpi3mr_os.c
> +++ b/drivers/scsi/mpi3mr/mpi3mr_os.c
> @@ -26,6 +26,471 @@ module_param(logging_level, int, 0);
>  MODULE_PARM_DESC(logging_level,
>  	" bits for enabling additional logging info (default=0)");
>  
> +/* Forward declarations*/
> +/**
> + * mpi3mr_host_tag_for_scmd - Get host tag for a scmd
> + * @mrioc: Adapter instance reference
> + * @scmd: SCSI command reference
> + *
> + * Calculate the host tag based on block tag for a given scmd.
> + *
> + * Return: Valid host tag or MPI3MR_HOSTTAG_INVALID.
> + */
> +static u16 mpi3mr_host_tag_for_scmd(struct mpi3mr_ioc *mrioc,
> +	struct scsi_cmnd *scmd)
> +{
> +	struct scmd_priv *priv = NULL;
> +	u32 unique_tag;
> +	u16 host_tag, hw_queue;
> +
> +	unique_tag = blk_mq_unique_tag(scmd->request);
> +
> +	hw_queue = blk_mq_unique_tag_to_hwq(unique_tag);
> +	if (hw_queue >= mrioc->num_op_reply_q)
> +		return MPI3MR_HOSTTAG_INVALID;
> +	host_tag = blk_mq_unique_tag_to_tag(unique_tag);
> +
> +	if (WARN_ON(host_tag >= mrioc->max_host_ios))
> +		return MPI3MR_HOSTTAG_INVALID;
> +
> +	priv = scsi_cmd_priv(scmd);
> +	/*host_tag 0 is invalid hence incrementing by 1*/
> +	priv->host_tag = host_tag + 1;
> +	priv->scmd = scmd;
> +	priv->in_lld_scope = 1;
> +	priv->req_q_idx = hw_queue;
> +	priv->chain_idx = -1;
> +	return priv->host_tag;
> +}
> +
> +/**
> + * mpi3mr_scmd_from_host_tag - Get SCSI command from host tag
> + * @mrioc: Adapter instance reference
> + * @host_tag: Host tag
> + * @qidx: Operational queue index
> + *
> + * Identify the block tag from the host tag and queue index and
> + * retrieve associated scsi command using scsi_host_find_tag().
> + *
> + * Return: SCSI command reference or NULL.
> + */
> +static struct scsi_cmnd *mpi3mr_scmd_from_host_tag(
> +	struct mpi3mr_ioc *mrioc, u16 host_tag, u16 qidx)
> +{
> +	struct scsi_cmnd *scmd = NULL;
> +	struct scmd_priv *priv = NULL;
> +	u32 unique_tag = host_tag - 1;
> +
> +	if (WARN_ON(host_tag > mrioc->max_host_ios))
> +		goto out;
> +
> +	unique_tag |= (qidx << BLK_MQ_UNIQUE_TAG_BITS);
> +
> +	scmd = scsi_host_find_tag(mrioc->shost, unique_tag);
> +	if (scmd) {
> +		priv = scsi_cmd_priv(scmd);
> +		if (!priv->in_lld_scope)
> +			scmd = NULL;
> +	}
> +out:
> +	return scmd;
> +}
> +
> +/**
> + * mpi3mr_clear_scmd_priv - Cleanup SCSI command private date
> + * @mrioc: Adapter instance reference
> + * @scmd: SCSI command reference
> + *
> + * Invalidate the SCSI command private data to mark the command
> + * is not in LLD scope anymore.
> + *
> + * Return: Nothing.
> + */
> +static void mpi3mr_clear_scmd_priv(struct mpi3mr_ioc *mrioc,
> +	struct scsi_cmnd *scmd)
> +{
> +	struct scmd_priv *priv = NULL;
> +
> +	priv = scsi_cmd_priv(scmd);
> +
> +	if (WARN_ON(priv->in_lld_scope == 0))
> +		return;
> +	priv->host_tag = MPI3MR_HOSTTAG_INVALID;
> +	priv->req_q_idx = 0xFFFF;
> +	priv->scmd = NULL;
> +	priv->in_lld_scope = 0;
> +	if (priv->chain_idx >= 0) {
> +		clear_bit(priv->chain_idx, mrioc->chain_bitmap);
> +		priv->chain_idx = -1;
> +	}
> +}
> +
> +/**
> + * mpi3mr_process_op_reply_desc - reply descriptor handler
> + * @mrioc: Adapter instance reference
> + * @reply_desc: Operational reply descriptor
> + * @reply_dma: place holder for reply DMA address
> + * @qidx: Operational queue index
> + *
> + * Process the operational reply descriptor and identifies the
> + * descriptor type. Based on the descriptor map the MPI3 request
> + * status to a SCSI command status and calls scsi_done call
> + * back.
> + *
> + * Return: Nothing
> + */
> +void mpi3mr_process_op_reply_desc(struct mpi3mr_ioc *mrioc,
> +	Mpi3DefaultReplyDescriptor_t *reply_desc, u64 *reply_dma, u16 qidx)
> +{
> +	u16 reply_desc_type, host_tag = 0;
> +	u16 ioc_status = MPI3_IOCSTATUS_SUCCESS;
> +	u32 ioc_loginfo = 0;
> +	Mpi3StatusReplyDescriptor_t *status_desc = NULL;
> +	Mpi3AddressReplyDescriptor_t *addr_desc = NULL;
> +	Mpi3SuccessReplyDescriptor_t *success_desc = NULL;
> +	Mpi3SCSIIOReply_t *scsi_reply = NULL;
> +	struct scsi_cmnd *scmd = NULL;
> +	struct scmd_priv *priv = NULL;
> +	u8 *sense_buf = NULL;
> +	u8 scsi_state = 0, scsi_status = 0, sense_state = 0;
> +	u32 xfer_count = 0, sense_count = 0, resp_data = 0;
> +	u16 dev_handle = 0xFFFF;
> +	struct scsi_sense_hdr sshdr;
> +
> +	*reply_dma = 0;
> +	reply_desc_type = le16_to_cpu(reply_desc->ReplyFlags) &
> +	    MPI3_REPLY_DESCRIPT_FLAGS_TYPE_MASK;
> +	switch (reply_desc_type) {
> +	case MPI3_REPLY_DESCRIPT_FLAGS_TYPE_STATUS:
> +		status_desc = (Mpi3StatusReplyDescriptor_t *)reply_desc;
> +		host_tag = le16_to_cpu(status_desc->HostTag);
> +		ioc_status = le16_to_cpu(status_desc->IOCStatus);
> +		if (ioc_status &
> +		    MPI3_REPLY_DESCRIPT_STATUS_IOCSTATUS_LOGINFOAVAIL)
> +			ioc_loginfo = le32_to_cpu(status_desc->IOCLogInfo);
> +		ioc_status &= MPI3_REPLY_DESCRIPT_STATUS_IOCSTATUS_STATUS_MASK;
> +		break;
> +	case MPI3_REPLY_DESCRIPT_FLAGS_TYPE_ADDRESS_REPLY:
> +		addr_desc = (Mpi3AddressReplyDescriptor_t *)reply_desc;
> +		*reply_dma = le64_to_cpu(addr_desc->ReplyFrameAddress);
> +		scsi_reply = mpi3mr_get_reply_virt_addr(mrioc,
> +		    *reply_dma);
> +		if (!scsi_reply) {
> +			panic("%s: scsi_reply is NULL, this shouldn't happen\n",
> +			    mrioc->name);
> +			goto out;
> +		}
> +		host_tag = le16_to_cpu(scsi_reply->HostTag);
> +		ioc_status = le16_to_cpu(scsi_reply->IOCStatus);
> +		scsi_status = scsi_reply->SCSIStatus;
> +		scsi_state = scsi_reply->SCSIState;
> +		dev_handle = le16_to_cpu(scsi_reply->DevHandle);
> +		sense_state = (scsi_state & MPI3_SCSI_STATE_SENSE_MASK);
> +		xfer_count = le32_to_cpu(scsi_reply->TransferCount);
> +		sense_count = le32_to_cpu(scsi_reply->SenseCount);
> +		resp_data = le32_to_cpu(scsi_reply->ResponseData);
> +		sense_buf = mpi3mr_get_sensebuf_virt_addr(mrioc,
> +		    le64_to_cpu(scsi_reply->SenseDataBufferAddress));
> +		if (ioc_status &
> +		    MPI3_REPLY_DESCRIPT_STATUS_IOCSTATUS_LOGINFOAVAIL)
> +			ioc_loginfo = le32_to_cpu(scsi_reply->IOCLogInfo);
> +		ioc_status &= MPI3_REPLY_DESCRIPT_STATUS_IOCSTATUS_STATUS_MASK;
> +		if (sense_state == MPI3_SCSI_STATE_SENSE_BUFF_Q_EMPTY)
> +			panic("%s: Ran out of sense buffers\n", mrioc->name);
> +		break;
> +	case MPI3_REPLY_DESCRIPT_FLAGS_TYPE_SUCCESS:
> +		success_desc = (Mpi3SuccessReplyDescriptor_t *)reply_desc;
> +		host_tag = le16_to_cpu(success_desc->HostTag);
> +		break;
> +	default:
> +		break;
> +	}
> +	scmd = mpi3mr_scmd_from_host_tag(mrioc, host_tag, qidx);
> +	if (!scmd) {
> +		panic("%s: Cannot Identify scmd for host_tag 0x%x\n",
> +		    mrioc->name, host_tag);
> +		goto out;
> +	}
> +	priv = scsi_cmd_priv(scmd);
> +	if (success_desc) {
> +		scmd->result = DID_OK << 16;
> +		goto out_success;
> +	}
> +	if (ioc_status == MPI3_IOCSTATUS_SCSI_DATA_UNDERRUN &&
> +	    xfer_count == 0 && (scsi_status == MPI3_SCSI_STATUS_BUSY ||
> +	    scsi_status == MPI3_SCSI_STATUS_RESERVATION_CONFLICT ||
> +	    scsi_status == MPI3_SCSI_STATUS_TASK_SET_FULL))
> +		ioc_status = MPI3_IOCSTATUS_SUCCESS;
> +
> +	if ((sense_state == MPI3_SCSI_STATE_SENSE_VALID) && sense_count
> +	    && sense_buf) {
> +		u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE, sense_count);
> +
> +		memcpy(scmd->sense_buffer, sense_buf, sz);
> +	}
> +
> +	switch (ioc_status) {
> +	case MPI3_IOCSTATUS_BUSY:
> +	case MPI3_IOCSTATUS_INSUFFICIENT_RESOURCES:
> +		scmd->result = SAM_STAT_BUSY;
> +		break;
> +	case MPI3_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
> +		scmd->result = DID_NO_CONNECT << 16;
> +		break;
> +	case MPI3_IOCSTATUS_SCSI_IOC_TERMINATED:
> +		scmd->result = DID_SOFT_ERROR << 16;
> +		break;
> +	case MPI3_IOCSTATUS_SCSI_TASK_TERMINATED:
> +	case MPI3_IOCSTATUS_SCSI_EXT_TERMINATED:
> +		scmd->result = DID_RESET << 16;
> +		break;
> +	case MPI3_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
> +		if ((xfer_count == 0) || (scmd->underflow > xfer_count))
> +			scmd->result = DID_SOFT_ERROR << 16;
> +		else
> +			scmd->result = (DID_OK << 16) | scsi_status;
> +		break;
> +	case MPI3_IOCSTATUS_SCSI_DATA_UNDERRUN:
> +		scmd->result = (DID_OK << 16) | scsi_status;
> +		if (sense_state == MPI3_SCSI_STATE_SENSE_VALID)
> +			break;
> +		if (xfer_count < scmd->underflow) {
> +			if (scsi_status == SAM_STAT_BUSY)
> +				scmd->result = SAM_STAT_BUSY;
> +			else
> +				scmd->result = DID_SOFT_ERROR << 16;
> +		} else if ((scsi_state & (MPI3_SCSI_STATE_NO_SCSI_STATUS))
> +		    || (sense_state != MPI3_SCSI_STATE_SENSE_NOT_AVAILABLE))
> +			scmd->result = DID_SOFT_ERROR << 16;
> +		else if (scsi_state & MPI3_SCSI_STATE_TERMINATED)
> +			scmd->result = DID_RESET << 16;
> +		else if (!xfer_count && scmd->cmnd[0] == REPORT_LUNS) {
> +			scsi_status = SAM_STAT_CHECK_CONDITION;
> +			scmd->result = (DRIVER_SENSE << 24) |
> +			    SAM_STAT_CHECK_CONDITION;
> +			scmd->sense_buffer[0] = 0x70;
> +			scmd->sense_buffer[2] = ILLEGAL_REQUEST;
> +			scmd->sense_buffer[12] = 0x20;
> +			scmd->sense_buffer[13] = 0;
> +		}
> +		break;
> +	case MPI3_IOCSTATUS_SCSI_DATA_OVERRUN:
> +		scsi_set_resid(scmd, 0);
> +		fallthrough;
> +	case MPI3_IOCSTATUS_SCSI_RECOVERED_ERROR:
> +	case MPI3_IOCSTATUS_SUCCESS:
> +		scmd->result = (DID_OK << 16) | scsi_status;
> +		if ((scsi_state & (MPI3_SCSI_STATE_NO_SCSI_STATUS))
> +			|| (sense_state == MPI3_SCSI_STATE_SENSE_FAILED)
> +			|| (sense_state == MPI3_SCSI_STATE_SENSE_BUFF_Q_EMPTY))
> +			scmd->result = DID_SOFT_ERROR << 16;
> +		else if (scsi_state & MPI3_SCSI_STATE_TERMINATED)
> +			scmd->result = DID_RESET << 16;
> +		break;
> +	case MPI3_IOCSTATUS_SCSI_PROTOCOL_ERROR:
> +	case MPI3_IOCSTATUS_INVALID_FUNCTION:
> +	case MPI3_IOCSTATUS_INVALID_SGL:
> +	case MPI3_IOCSTATUS_INTERNAL_ERROR:
> +	case MPI3_IOCSTATUS_INVALID_FIELD:
> +	case MPI3_IOCSTATUS_INVALID_STATE:
> +	case MPI3_IOCSTATUS_SCSI_IO_DATA_ERROR:
> +	case MPI3_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
> +	case MPI3_IOCSTATUS_INSUFFICIENT_POWER:
> +	default:
> +		scmd->result = DID_SOFT_ERROR << 16;
> +		break;
> +	}
> +
> +	if (scmd->result != (DID_OK << 16) && (scmd->cmnd[0] != ATA_12) &&
> +	    (scmd->cmnd[0] != ATA_16)) {
> +		ioc_info(mrioc, "%s :scmd->result 0x%x\n", __func__,
> +		    scmd->result);
> +		scsi_print_command(scmd);
> +		ioc_info(mrioc,
> +		    "%s :Command issued to handle 0x%02x returned with error 0x%04x loginfo 0x%08x, qid %d\n",
> +		    __func__, dev_handle, ioc_status, ioc_loginfo,
> +		    priv->req_q_idx+1);
> +		ioc_info(mrioc,
> +		    " host_tag %d scsi_state 0x%02x scsi_status 0x%02x, xfer_cnt %d resp_data 0x%x\n",
> +		    host_tag, scsi_state, scsi_status, xfer_count, resp_data);
> +		if (sense_buf) {
> +			scsi_normalize_sense(sense_buf, sense_count, &sshdr);
> +			ioc_info(mrioc,
> +			    "%s :sense_count 0x%x, sense_key 0x%x ASC 0x%x, ASCQ 0x%x\n",
> +			    __func__, sense_count, sshdr.sense_key,
> +			    sshdr.asc, sshdr.ascq);
> +		}
> +	}
> +out_success:
> +	mpi3mr_clear_scmd_priv(mrioc, scmd);
> +	scsi_dma_unmap(scmd);
> +	scmd->scsi_done(scmd);
> +out:
> +	if (sense_buf)
> +		mpi3mr_repost_sense_buf(mrioc,
> +		    le64_to_cpu(scsi_reply->SenseDataBufferAddress));
> +}
> +
> +/**
> + * mpi3mr_get_chain_idx - get free chain buffer index
> + * @mrioc: Adapter instance reference
> + *
> + * Try to get a free chain buffer index from the free pool.
> + *
> + * Return: -1 on failure or the free chain buffer index
> + */
> +static int mpi3mr_get_chain_idx(struct mpi3mr_ioc *mrioc)
> +{
> +	u8 retry_count = 5;
> +	int cmd_idx = -1;
> +
> +	do {
> +		spin_lock(&mrioc->chain_buf_lock);
> +		cmd_idx = find_first_zero_bit(mrioc->chain_bitmap,
> +		    mrioc->chain_buf_count);
> +		if (cmd_idx < mrioc->chain_buf_count) {
> +			set_bit(cmd_idx, mrioc->chain_bitmap);
> +			spin_unlock(&mrioc->chain_buf_lock);
> +			break;
> +		}
> +		spin_unlock(&mrioc->chain_buf_lock);
> +		cmd_idx = -1;
> +	} while (retry_count--);
> +	return cmd_idx;
> +}
> +
> +/**
> + * mpi3mr_prepare_sg_scmd - build scatter gather list
> + * @mrioc: Adapter instance reference
> + * @scmd: SCSI command reference
> + * @scsiio_req: MPI3 SCSI IO request
> + *
> + * This function maps SCSI command's data and protection SGEs to
> + * MPI request SGEs. If required additional 4K chain buffer is
> + * used to send the SGEs.
> + *
> + * Return: 0 on success, -ENOMEM on dma_map_sg failure
> + */
> +static int mpi3mr_prepare_sg_scmd(struct mpi3mr_ioc *mrioc,
> +	struct scsi_cmnd *scmd, Mpi3SCSIIORequest_t *scsiio_req)
> +{
> +	dma_addr_t chain_dma;
> +	struct scatterlist *sg_scmd;
> +	void *sg_local, *chain;
> +	u32 chain_length;
> +	int sges_left, chain_idx;
> +	u32 sges_in_segment;
> +	u8 simple_sgl_flags;
> +	u8 simple_sgl_flags_last;
> +	u8 last_chain_sgl_flags;
> +	struct chain_element *chain_req;
> +	struct scmd_priv *priv = NULL;
> +
> +	priv = scsi_cmd_priv(scmd);
> +
> +	simple_sgl_flags = MPI3_SGE_FLAGS_ELEMENT_TYPE_SIMPLE |
> +	    MPI3_SGE_FLAGS_DLAS_SYSTEM;
> +	simple_sgl_flags_last = simple_sgl_flags |
> +	    MPI3_SGE_FLAGS_END_OF_LIST;
> +	last_chain_sgl_flags = MPI3_SGE_FLAGS_ELEMENT_TYPE_LAST_CHAIN |
> +	    MPI3_SGE_FLAGS_DLAS_SYSTEM;
> +
> +	sg_local = &scsiio_req->SGL;
> +
> +	if (!scsiio_req->DataLength) {
> +		mpi3mr_build_zero_len_sge(sg_local);
> +		return 0;
> +	}
> +
> +	sg_scmd = scsi_sglist(scmd);
> +	sges_left = scsi_dma_map(scmd);
> +
> +	if (sges_left < 0) {
> +		sdev_printk(KERN_ERR, scmd->device,
> +		    "scsi_dma_map failed: request for %d bytes!\n",
> +		    scsi_bufflen(scmd));
> +		return -ENOMEM;
> +	}
> +	if (sges_left > MPI3MR_SG_DEPTH) {
> +		sdev_printk(KERN_ERR, scmd->device,
> +		    "scsi_dma_map returned unsupported sge count %d!\n",
> +		    sges_left);
> +		return -ENOMEM;
> +	}
> +
> +	sges_in_segment = (mrioc->facts.op_req_sz -
> +	    offsetof(Mpi3SCSIIORequest_t, SGL))/sizeof(Mpi3SGESimple_t);
> +
> +	if (sges_left <= sges_in_segment)
> +		goto fill_in_last_segment;
> +
> +	/* fill in main message segment when there is a chain following */
> +	while (sges_in_segment > 1) {
> +		mpi3mr_add_sg_single(sg_local, simple_sgl_flags,
> +		    sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
> +		sg_scmd = sg_next(sg_scmd);
> +		sg_local += sizeof(Mpi3SGESimple_t);
> +		sges_left--;
> +		sges_in_segment--;
> +	}
> +
> +	chain_idx = mpi3mr_get_chain_idx(mrioc);
> +	if (chain_idx < 0)
> +		return -1;
> +	chain_req = &mrioc->chain_sgl_list[chain_idx];
> +	priv->chain_idx = chain_idx;
> +
> +	chain = chain_req->addr;
> +	chain_dma = chain_req->dma_addr;
> +	sges_in_segment = sges_left;
> +	chain_length = sges_in_segment * sizeof(Mpi3SGESimple_t);
> +
> +	mpi3mr_add_sg_single(sg_local, last_chain_sgl_flags,
> +	    chain_length, chain_dma);
> +
> +	sg_local = chain;
> +
> +fill_in_last_segment:
> +	while (sges_left > 0) {
> +		if (sges_left == 1)
> +			mpi3mr_add_sg_single(sg_local,
> +			    simple_sgl_flags_last, sg_dma_len(sg_scmd),
> +			    sg_dma_address(sg_scmd));
> +		else
> +			mpi3mr_add_sg_single(sg_local, simple_sgl_flags,
> +			    sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
> +		sg_scmd = sg_next(sg_scmd);
> +		sg_local += sizeof(Mpi3SGESimple_t);
> +		sges_left--;
> +	}
> +
> +	return 0;
> +}
> +
> +/**
> + * mpi3mr_build_sg_scmd - build scatter gather list for SCSI IO
> + * @mrioc: Adapter instance reference
> + * @scmd: SCSI command reference
> + * @scsiio_req: MPI3 SCSI IO request
> + *
> + * This function calls mpi3mr_prepare_sg_scmd for constructing
> + * both data SGEs and protection information SGEs in the MPI
> + * format from the SCSI Command as appropriate .
> + *
> + * Return: return value of mpi3mr_prepare_sg_scmd.
> + */
> +static int mpi3mr_build_sg_scmd(struct mpi3mr_ioc *mrioc,
> +	struct scsi_cmnd *scmd, Mpi3SCSIIORequest_t *scsiio_req)
> +{
> +	int ret;
> +
> +	ret = mpi3mr_prepare_sg_scmd(mrioc, scmd, scsiio_req);
> +	if (ret)
> +		return ret;
> +
> +	return ret;
> +}
> +
>  
>  /**
>   * mpi3mr_map_queues - Map queues callback handler
> @@ -44,6 +509,73 @@ static int mpi3mr_map_queues(struct Scsi_Host *shost)
>  	    mrioc->pdev, mrioc->op_reply_q_offset);
>  }
>  
> +/**
> + * mpi3mr_scan_start - Scan start callback handler
> + * @shost: SCSI host reference
> + *
> + * Issue port enable request asynchronously.
> + *
> + * Return: Nothing
> + */
> +static void mpi3mr_scan_start(struct Scsi_Host *shost)
> +{
> +	struct mpi3mr_ioc *mrioc = shost_priv(shost);
> +
> +	mrioc->scan_started = 1;
> +	ioc_info(mrioc, "%s :Issuing Port Enable\n", __func__);
> +	if (mpi3mr_issue_port_enable(mrioc, 1)) {
> +		ioc_err(mrioc, "%s :Issuing port enable failed\n", __func__);
> +		mrioc->scan_started = 0;
> +		mrioc->scan_failed = MPI3_IOCSTATUS_INTERNAL_ERROR;
> +	}
> +
> +}
> +
> +/**
> + * mpi3mr_scan_finished - Scan finished callback handler
> + * @shost: SCSI host reference
> + * @time: Jiffies from the scan start
> + *
> + * Checks whether the port enable is completed or timedout or
> + * failed and set the scan status accordingly after taking any
> + * recovery if required.
> + *
> + * Return: 1 on scan finished or timed out, 0 for in progress
> + */
> +static int mpi3mr_scan_finished(struct Scsi_Host *shost,
> +	unsigned long time)
> +{
> +	struct mpi3mr_ioc *mrioc = shost_priv(shost);
> +	u32 pe_timeout = MPI3MR_PORTENABLE_TIMEOUT;
> +
> +	if (time >= (pe_timeout * HZ)) {
> +		mrioc->init_cmds.is_waiting = 0;
> +		mrioc->init_cmds.callback = NULL;
> +		mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
> +		ioc_err(mrioc, "%s :port enable request timed out\n", __func__);
> +		mrioc->is_driver_loading = 0;
> +		mpi3mr_soft_reset_handler(mrioc,
> +		    MPI3MR_RESET_FROM_PE_TIMEOUT, 1);
> +	}
> +
> +	if (mrioc->scan_failed) {
> +		ioc_err(mrioc,
> +		    "%s :port enable failed with (ioc_status=0x%08x)\n",
> +		    __func__, mrioc->scan_failed);
> +		mrioc->is_driver_loading = 0;
> +		mrioc->stop_drv_processing = 1;
> +		return 1;
> +	}
> +
> +	if (mrioc->scan_started)
> +		return 0;
> +	ioc_info(mrioc, "%s :port enable: SUCCESS\n", __func__);
> +	mrioc->is_driver_loading = 0;
> +
> +	return 1;
> +}
> +
> +
>  /**
>   * mpi3mr_slave_destroy - Slave destroy callback handler
>   * @sdev: SCSI device reference
> @@ -126,10 +658,114 @@ static int mpi3mr_target_alloc(struct scsi_target *starget)
>  static int mpi3mr_qcmd(struct Scsi_Host *shost,
>  	struct scsi_cmnd *scmd)
>  {
> +	struct mpi3mr_ioc *mrioc = shost_priv(shost);
> +	struct mpi3mr_stgt_priv_data *stgt_priv_data;
> +	struct mpi3mr_sdev_priv_data *sdev_priv_data;
> +	struct scmd_priv *scmd_priv_data = NULL;
> +	Mpi3SCSIIORequest_t *scsiio_req = NULL;
> +	struct op_req_qinfo *op_req_q = NULL;
>  	int retval = 0;
> +	u16 dev_handle;
> +	u16 host_tag;
> +	u32 scsiio_flags = 0;
> +	struct request *rq = scmd->request;
> +	int iprio_class;
> +
> +	sdev_priv_data = scmd->device->hostdata;
> +	if (!sdev_priv_data || !sdev_priv_data->tgt_priv_data) {
> +		scmd->result = DID_NO_CONNECT << 16;
> +		scmd->scsi_done(scmd);
> +		goto out;
> +	}
>  
> -	scmd->result = DID_NO_CONNECT << 16;
> -	scmd->scsi_done(scmd);
> +	if (mrioc->stop_drv_processing) {
> +		scmd->result = DID_NO_CONNECT << 16;
> +		scmd->scsi_done(scmd);
> +		goto out;
> +	}
Hi Kashyap,
for what is the above test needed (stop_drv_processing) it looks like
other drivers don't need to protect exit function in this was (for
example mpt3sas).
Regards,
Tomash

> +
> +	if (mrioc->reset_in_progress) {
> +		retval = SCSI_MLQUEUE_HOST_BUSY;
> +		goto out;
> +	}
> +
> +	stgt_priv_data = sdev_priv_data->tgt_priv_data;
> +
> +	dev_handle = stgt_priv_data->dev_handle;
> +	if (dev_handle == MPI3MR_INVALID_DEV_HANDLE) {
> +		scmd->result = DID_NO_CONNECT << 16;
> +		scmd->scsi_done(scmd);
> +		goto out;
> +	}
> +	if (stgt_priv_data->dev_removed) {
> +		scmd->result = DID_NO_CONNECT << 16;
> +		scmd->scsi_done(scmd);
> +		goto out;
> +	}
> +
> +	if (atomic_read(&stgt_priv_data->block_io)) {
> +		if (mrioc->stop_drv_processing) {
> +			scmd->result = DID_NO_CONNECT << 16;
> +			scmd->scsi_done(scmd);
> +			goto out;
> +		}
> +		retval = SCSI_MLQUEUE_DEVICE_BUSY;
> +		goto out;
> +	}
> +
> +	host_tag = mpi3mr_host_tag_for_scmd(mrioc, scmd);
> +	if (host_tag == MPI3MR_HOSTTAG_INVALID) {
> +		scmd->result = DID_ERROR << 16;
> +		scmd->scsi_done(scmd);
> +		goto out;
> +	}
> +
> +	if (scmd->sc_data_direction == DMA_FROM_DEVICE)
> +		scsiio_flags = MPI3_SCSIIO_FLAGS_DATADIRECTION_READ;
> +	else if (scmd->sc_data_direction == DMA_TO_DEVICE)
> +		scsiio_flags = MPI3_SCSIIO_FLAGS_DATADIRECTION_WRITE;
> +	else
> +		scsiio_flags = MPI3_SCSIIO_FLAGS_DATADIRECTION_NO_DATA_TRANSFER;
> +
> +	scsiio_flags |= MPI3_SCSIIO_FLAGS_TASKATTRIBUTE_SIMPLEQ;
> +
> +	if (sdev_priv_data->ncq_prio_enable) {
> +		iprio_class = IOPRIO_PRIO_CLASS(req_get_ioprio(rq));
> +		if (iprio_class == IOPRIO_CLASS_RT)
> +			scsiio_flags |= 1 << MPI3_SCSIIO_FLAGS_CMDPRI_SHIFT;
> +	}
> +
> +	if (scmd->cmd_len > 16)
> +		scsiio_flags |= MPI3_SCSIIO_FLAGS_CDB_GREATER_THAN_16;
> +
> +	scmd_priv_data = scsi_cmd_priv(scmd);
> +	memset(scmd_priv_data->mpi3mr_scsiio_req, 0, MPI3MR_ADMIN_REQ_FRAME_SZ);
> +	scsiio_req = (Mpi3SCSIIORequest_t *) scmd_priv_data->mpi3mr_scsiio_req;
> +	scsiio_req->Function = MPI3_FUNCTION_SCSI_IO;
> +	scsiio_req->HostTag = cpu_to_le16(host_tag);
> +
> +	memcpy(scsiio_req->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
> +	scsiio_req->DataLength = cpu_to_le32(scsi_bufflen(scmd));
> +	scsiio_req->DevHandle = cpu_to_le16(dev_handle);
> +	scsiio_req->Flags = cpu_to_le32(scsiio_flags);
> +	int_to_scsilun(sdev_priv_data->lun_id,
> +	    (struct scsi_lun *)scsiio_req->LUN);
> +
> +	if (mpi3mr_build_sg_scmd(mrioc, scmd, scsiio_req)) {
> +		mpi3mr_clear_scmd_priv(mrioc, scmd);
> +		retval = SCSI_MLQUEUE_HOST_BUSY;
> +		goto out;
> +	}
> +	op_req_q = &mrioc->req_qinfo[scmd_priv_data->req_q_idx];
> +
> +	if (mpi3mr_op_request_post(mrioc, op_req_q,
> +	    scmd_priv_data->mpi3mr_scsiio_req)) {
> +		mpi3mr_clear_scmd_priv(mrioc, scmd);
> +		retval = SCSI_MLQUEUE_HOST_BUSY;
> +		goto out;
> +	}
> +
> +out:
>  	return retval;
>  }
>  
> @@ -143,6 +779,8 @@ static struct scsi_host_template mpi3mr_driver_template = {
>  	.slave_configure		= mpi3mr_slave_configure,
>  	.target_destroy			= mpi3mr_target_destroy,
>  	.slave_destroy			= mpi3mr_slave_destroy,
> +	.scan_finished			= mpi3mr_scan_finished,
> +	.scan_start			= mpi3mr_scan_start,
>  	.map_queues			= mpi3mr_map_queues,
>  	.no_write_same			= 1,
>  	.can_queue			= 1,
> @@ -218,6 +856,7 @@ mpi3mr_probe(struct pci_dev *pdev, const struct pci_device_id *id)
>  	spin_lock_init(&mrioc->admin_req_lock);
>  	spin_lock_init(&mrioc->reply_free_queue_lock);
>  	spin_lock_init(&mrioc->sbq_lock);
> +	spin_lock_init(&mrioc->chain_buf_lock);
>  
>  	mpi3mr_init_drv_cmd(&mrioc->init_cmds, MPI3MR_HOSTTAG_INITCMDS);
>  	if (pdev->revision)
> @@ -287,6 +926,7 @@ static void mpi3mr_remove(struct pci_dev *pdev)
>  	while (mrioc->reset_in_progress || mrioc->is_driver_loading)
>  		ssleep(1);
>  
> +	mrioc->stop_drv_processing = 1;
>  
>  	scsi_remove_host(shost);
>  
> @@ -319,6 +959,7 @@ static void mpi3mr_shutdown(struct pci_dev *pdev)
>  	mrioc = shost_priv(shost);
>  	while (mrioc->reset_in_progress || mrioc->is_driver_loading)
>  		ssleep(1);
> +	mrioc->stop_drv_processing = 1;
>  
>  	mpi3mr_cleanup_ioc(mrioc);
>  
> 


^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 06/24] mpi3mr: add support of event handling part-1
  2020-12-22 10:11 ` [PATCH 06/24] mpi3mr: add support of event handling part-1 Kashyap Desai
  2020-12-27 13:14     ` kernel test robot
@ 2021-02-22 15:31   ` Tomas Henzl
  2021-02-25 13:36     ` Kashyap Desai
  2021-03-01  6:47   ` Hannes Reinecke
  2 siblings, 1 reply; 75+ messages in thread
From: Tomas Henzl @ 2021-02-22 15:31 UTC (permalink / raw)
  To: Kashyap Desai, linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, sathya.prakash

On 12/22/20 11:11 AM, Kashyap Desai wrote:
> Firmware can report various MPI Events.
> Support for certain Events (as listed below) are enabled in the driver
> and their processing in driver is covered in this patch.
> 
> MPI3_EVENT_DEVICE_ADDED
> MPI3_EVENT_DEVICE_INFO_CHANGED
> MPI3_EVENT_DEVICE_STATUS_CHANGE
> MPI3_EVENT_ENCL_DEVICE_STATUS_CHANGE
> MPI3_EVENT_SAS_TOPOLOGY_CHANGE_LIST
> MPI3_EVENT_SAS_DISCOVERY
> MPI3_EVENT_SAS_DEVICE_DISCOVERY_ERROR
> 
> Key support in this patch is device add/removal.
> 
> Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
> Cc: sathya.prakash@broadcom.com
> ---
...
> + */
> +void mpi3mr_cleanup_fwevt_list(struct mpi3mr_ioc *mrioc)
> +{
> +	struct mpi3mr_fwevt *fwevt = NULL;
> +
> +	if ((list_empty(&mrioc->fwevt_list) && !mrioc->current_event) ||
> +	    !mrioc->fwevt_worker_thread || in_interrupt())
The in_interrup macro is deprecated and should not be used in new code.
Is it at all possible to call the mpi3mr_cleanup_fwevt_list from
interrupt context?

> +		return;
> +
> +	while ((fwevt = mpi3mr_dequeue_fwevt(mrioc)) ||
> +	    (fwevt = mrioc->current_event)) {
> +		/*
> +		 * Wait on the fwevt to complete. If this returns 1, then
> +		 * the event was never executed, and we need a put for the
> +		 * reference the work had on the fwevt.
> +		 *
> +		 * If it did execute, we wait for it to finish, and the put will
> +		 * happen from mpi3mr_process_fwevt()
> +		 */
> +		if (cancel_work_sync(&fwevt->work)) {
> +			/*
> +			 * Put fwevt reference count after
> +			 * dequeuing it from worker queue
> +			 */
> +			mpi3mr_fwevt_put(fwevt);
> +			/*
> +			 * Put fwevt reference count to neutralize
> +			 * kref_init increment
> +			 */
> +			mpi3mr_fwevt_put(fwevt);
> +		}
> +	}
> +}


^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 21/24] mpi3mr: add support of PM suspend and resume
  2020-12-22 10:11 ` [PATCH 21/24] mpi3mr: add support of PM suspend and resume Kashyap Desai
@ 2021-02-22 15:32   ` Tomas Henzl
  2021-02-25 13:37     ` Kashyap Desai
  2021-03-01  7:18   ` Hannes Reinecke
  1 sibling, 1 reply; 75+ messages in thread
From: Tomas Henzl @ 2021-02-22 15:32 UTC (permalink / raw)
  To: Kashyap Desai, linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, sathya.prakash

On 12/22/20 11:11 AM, Kashyap Desai wrote:
> Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
> Cc: sathya.prakash@broadcom.com
> ---
>  drivers/scsi/mpi3mr/mpi3mr_os.c | 85 +++++++++++++++++++++++++++++++++
>  1 file changed, 85 insertions(+)
> 
> diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c
> index 1708aca1a5cd..ac47eed74705 100644
> --- a/drivers/scsi/mpi3mr/mpi3mr_os.c
> +++ b/drivers/scsi/mpi3mr/mpi3mr_os.c
...
> +/**
> + * mpi3mr_resume - PCI power management resume callback
> + * @pdev: PCI device instance
> + *
> + * Restore the power state to D0 and reinitialize the controller
> + * and resume I/O operations to the target devices
> + *
> + * Return: 0 on success, non-zero on failure
> + */
> +static int mpi3mr_resume(struct pci_dev *pdev)
> +{
> +	struct Scsi_Host *shost = pci_get_drvdata(pdev);
> +	struct mpi3mr_ioc *mrioc;
> +	pci_power_t device_state = pdev->current_state;
> +	int r;
> +
> +	mrioc = shost_priv(shost);
> +
> +	ioc_info(mrioc, "pdev=0x%p, slot=%s, previous operating state [D%d]\n",
> +	    pdev, pci_name(pdev), device_state);
> +	pci_set_power_state(pdev, PCI_D0);
> +	pci_enable_wake(pdev, PCI_D0, 0);
> +	pci_restore_state(pdev);
> +	mrioc->pdev = pdev;
> +	mrioc->cpu_count = num_online_cpus();
> +	r = mpi3mr_setup_resources(mrioc);
> +	if (r) {
> +		ioc_info(mrioc, "%s: Setup resoruces failed[%d]\n",

A typo 					here ^
> +		    __func__, r);
> +		return r;
> +	}


^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 23/24] mpi3mr: add eedp dif dix support
  2020-12-22 10:11 ` [PATCH 23/24] mpi3mr: add eedp dif dix support Kashyap Desai
@ 2021-02-22 15:37   ` Tomas Henzl
  2021-02-25 13:39     ` Kashyap Desai
  2021-03-01  7:20   ` Hannes Reinecke
  1 sibling, 1 reply; 75+ messages in thread
From: Tomas Henzl @ 2021-02-22 15:37 UTC (permalink / raw)
  To: Kashyap Desai, linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, sathya.prakash

On 12/22/20 11:11 AM, Kashyap Desai wrote:
> Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
> Cc: sathya.prakash@broadcom.com
> ---
>  drivers/scsi/mpi3mr/mpi3mr.h    |  18 +-
>  drivers/scsi/mpi3mr/mpi3mr_fw.c |   7 +
>  drivers/scsi/mpi3mr/mpi3mr_os.c | 303 +++++++++++++++++++++++++++++++-
>  3 files changed, 321 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/scsi/mpi3mr/mpi3mr.h b/drivers/scsi/mpi3mr/mpi3mr.h
> index f0ead83dc16c..acc5649bed5f 100644
> --- a/drivers/scsi/mpi3mr/mpi3mr.h
> +++ b/drivers/scsi/mpi3mr/mpi3mr.h
> @@ -118,6 +118,7 @@ extern struct list_head mrioc_list;
>  #define MPI3MR_SENSEBUF_SZ	256
>  #define MPI3MR_SENSEBUF_FACTOR	3
>  #define MPI3MR_CHAINBUF_FACTOR	3
> +#define MPI3MR_CHAINBUFDIX_FACTOR	2
>  
>  /* Invalid target device handle */
>  #define MPI3MR_INVALID_DEV_HANDLE	0xFFFF
> @@ -145,6 +146,15 @@ extern struct list_head mrioc_list;
>  /* Default target device queue depth */
>  #define MPI3MR_DEFAULT_SDEV_QD	32
>  
> +/* Definitions for the sector size for EEDP */
> +#define MPI3_SECTOR_SIZE_512_BYTE	(512)
> +#define MPI3_SECTOR_SIZE_520_BYTE	(520)
> +#define MPI3_SECTOR_SIZE_4080_BYTE	(4080)
> +#define MPI3_SECTOR_SIZE_4088_BYTE	(4088)
> +#define MPI3_SECTOR_SIZE_4096_BYTE	(4096)
> +#define MPI3_SECTOR_SIZE_4104_BYTE	(4104)
> +#define MPI3_SECTOR_SIZE_4160_BYTE	(4160)
> +

This looks weird, please use the values directly instead of creating
macros.

tomash


^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 00/24] Introducing mpi3mr driver
  2020-12-22 10:11 [PATCH 00/24] Introducing mpi3mr driver Kashyap Desai
                   ` (23 preceding siblings ...)
  2020-12-22 10:11 ` [PATCH 24/24] mpi3mr: add event handling debug prints Kashyap Desai
@ 2021-02-22 15:39 ` Tomas Henzl
  24 siblings, 0 replies; 75+ messages in thread
From: Tomas Henzl @ 2021-02-22 15:39 UTC (permalink / raw)
  To: Kashyap Desai, linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera, mpi3mr-linuxdrv.pdl

On 12/22/20 11:11 AM, Kashyap Desai wrote:
> This patch series covers logical patches of the new device driver for the
> MPI3MR high performance storage I/O & RAID controllers (Avenger series).
> The mpi3mr has true multiple h/w queue interfacing like nvme.
> 
> See more info -
> https://www.spinics.net/lists/linux-scsi/msg147868.html
> 
> The controllers managed by the mpi3mr driver are capable of reaching a
> very high performance numbers compared to existing controller due to the
> new hardware architectures. This Driver is tested with the internal
> versions of the MPI3MR I/O & RAID controllers.
> 
> Patches are logical split mainly for better code review. Full patch set is
> required for functional stability of this new driver.
> 
> You can find the source at - https://github.com/kadesai16/mpi3mr_v1

This was posted months ago, If I may suggest sort out the comments and
post a V2 of  the set.
Cheers,
tomash
> 
> 
> Kashyap Desai (24):
>   mpi3mr: add mpi30 Rev-R headers and Kconfig
>   mpi3mr: base driver code
>   mpi3mr: create operational request and reply queue pair
>   mpi3mr: add support of queue command processing
>   mpi3mr: add support of internal watchdog thread
>   mpi3mr: add support of event handling part-1
>   mpi3mr: add support of event handling pcie devices part-2
>   mpi3mr: add support of event handling part-3
>   mpi3mr: add support for recovering controller
>   mpi3mr: add support of timestamp sync with firmware
>   mpi3mr: print ioc info for debugging
>   mpi3mr: add bios_param shost template hook
>   mpi3mr: implement scsi error handler hooks
>   mpi3mr: add change queue depth support
>   mpi3mr: allow certain commands during pci-remove hook
>   mpi3mr: hardware workaround for UNMAP commands to nvme drives
>   mpi3mr: add support of threaded isr
>   mpi3mr: add complete support of soft reset
>   mpi3mr: print pending host ios for debug
>   mpi3mr: wait for pending IO completions upon detection of VD IO
>     timeout
>   mpi3mr: add support of PM suspend and resume
>   mpi3mr: add support of DSN secure fw check
>   mpi3mr: add eedp dif dix support
>   mpi3mr: add event handling debug prints
> 
>  drivers/scsi/Kconfig                      |    1 +
>  drivers/scsi/Makefile                     |    1 +
>  drivers/scsi/mpi3mr/Kconfig               |    7 +
>  drivers/scsi/mpi3mr/Makefile              |    4 +
>  drivers/scsi/mpi3mr/mpi/mpi30_api.h       |   23 +
>  drivers/scsi/mpi3mr/mpi/mpi30_cnfg.h      | 2721 ++++++++++++++
>  drivers/scsi/mpi3mr/mpi/mpi30_image.h     |  285 ++
>  drivers/scsi/mpi3mr/mpi/mpi30_init.h      |  216 ++
>  drivers/scsi/mpi3mr/mpi/mpi30_ioc.h       | 1423 +++++++
>  drivers/scsi/mpi3mr/mpi/mpi30_sas.h       |   46 +
>  drivers/scsi/mpi3mr/mpi/mpi30_transport.h |  675 ++++
>  drivers/scsi/mpi3mr/mpi/mpi30_type.h      |   89 +
>  drivers/scsi/mpi3mr/mpi3mr.h              |  906 +++++
>  drivers/scsi/mpi3mr/mpi3mr_debug.h        |   60 +
>  drivers/scsi/mpi3mr/mpi3mr_fw.c           | 3944 ++++++++++++++++++++
>  drivers/scsi/mpi3mr/mpi3mr_os.c           | 4148 +++++++++++++++++++++
>  16 files changed, 14549 insertions(+)
>  create mode 100644 drivers/scsi/mpi3mr/Kconfig
>  create mode 100644 drivers/scsi/mpi3mr/Makefile
>  create mode 100644 drivers/scsi/mpi3mr/mpi/mpi30_api.h
>  create mode 100644 drivers/scsi/mpi3mr/mpi/mpi30_cnfg.h
>  create mode 100644 drivers/scsi/mpi3mr/mpi/mpi30_image.h
>  create mode 100644 drivers/scsi/mpi3mr/mpi/mpi30_init.h
>  create mode 100644 drivers/scsi/mpi3mr/mpi/mpi30_ioc.h
>  create mode 100644 drivers/scsi/mpi3mr/mpi/mpi30_sas.h
>  create mode 100644 drivers/scsi/mpi3mr/mpi/mpi30_transport.h
>  create mode 100644 drivers/scsi/mpi3mr/mpi/mpi30_type.h
>  create mode 100644 drivers/scsi/mpi3mr/mpi3mr.h
>  create mode 100644 drivers/scsi/mpi3mr/mpi3mr_debug.h
>  create mode 100644 drivers/scsi/mpi3mr/mpi3mr_fw.c
>  create mode 100644 drivers/scsi/mpi3mr/mpi3mr_os.c
> 


^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 01/24] mpi3mr: add mpi30 Rev-R headers and Kconfig
  2020-12-22 10:11 ` [PATCH 01/24] mpi3mr: add mpi30 Rev-R headers and Kconfig Kashyap Desai
  2020-12-22 18:15   ` Bart Van Assche
@ 2021-02-23 12:30   ` Hannes Reinecke
  2021-03-02 18:11     ` Kashyap Desai
  1 sibling, 1 reply; 75+ messages in thread
From: Hannes Reinecke @ 2021-02-23 12:30 UTC (permalink / raw)
  To: Kashyap Desai, linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, sathya.prakash

On 12/22/20 11:11 AM, Kashyap Desai wrote:
> This adds the Kconfig and mpi30 headers.
> 
> Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
> Cc: sathya.prakash@broadcom.com
> ---
>  drivers/scsi/Kconfig                      |    1 +
>  drivers/scsi/Makefile                     |    1 +
>  drivers/scsi/mpi3mr/Kconfig               |    7 +
>  drivers/scsi/mpi3mr/mpi/mpi30_api.h       |   21 +
>  drivers/scsi/mpi3mr/mpi/mpi30_image.h     |  285 +++++
>  drivers/scsi/mpi3mr/mpi/mpi30_init.h      |  216 ++++
>  drivers/scsi/mpi3mr/mpi/mpi30_ioc.h       | 1423 +++++++++++++++++++++
>  drivers/scsi/mpi3mr/mpi/mpi30_transport.h |  675 ++++++++++
>  drivers/scsi/mpi3mr/mpi/mpi30_type.h      |   89 ++
>  9 files changed, 2718 insertions(+)
>  create mode 100644 drivers/scsi/mpi3mr/Kconfig
>  create mode 100644 drivers/scsi/mpi3mr/mpi/mpi30_api.h
>  create mode 100644 drivers/scsi/mpi3mr/mpi/mpi30_image.h
>  create mode 100644 drivers/scsi/mpi3mr/mpi/mpi30_init.h
>  create mode 100644 drivers/scsi/mpi3mr/mpi/mpi30_ioc.h
>  create mode 100644 drivers/scsi/mpi3mr/mpi/mpi30_transport.h
>  create mode 100644 drivers/scsi/mpi3mr/mpi/mpi30_type.h
> 
> diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
> index 701b61ec76ee..afccbd062237 100644
> --- a/drivers/scsi/Kconfig
> +++ b/drivers/scsi/Kconfig
> @@ -482,6 +482,7 @@ config SCSI_ARCMSR
>  source "drivers/scsi/esas2r/Kconfig"
>  source "drivers/scsi/megaraid/Kconfig.megaraid"
>  source "drivers/scsi/mpt3sas/Kconfig"
> +source "drivers/scsi/mpi3mr/Kconfig"
>  source "drivers/scsi/smartpqi/Kconfig"
>  source "drivers/scsi/ufs/Kconfig"
>  
> diff --git a/drivers/scsi/Makefile b/drivers/scsi/Makefile
> index c00e3dd57990..7c3f2faae18b 100644
> --- a/drivers/scsi/Makefile
> +++ b/drivers/scsi/Makefile
> @@ -100,6 +100,7 @@ obj-$(CONFIG_MEGARAID_LEGACY)	+= megaraid.o
>  obj-$(CONFIG_MEGARAID_NEWGEN)	+= megaraid/
>  obj-$(CONFIG_MEGARAID_SAS)	+= megaraid/
>  obj-$(CONFIG_SCSI_MPT3SAS)	+= mpt3sas/
> +obj-$(CONFIG_SCSI_MPI3MR)	+= mpi3mr/
>  obj-$(CONFIG_SCSI_UFSHCD)	+= ufs/
>  obj-$(CONFIG_SCSI_ACARD)	+= atp870u.o
>  obj-$(CONFIG_SCSI_SUNESP)	+= esp_scsi.o	sun_esp.o
> diff --git a/drivers/scsi/mpi3mr/Kconfig b/drivers/scsi/mpi3mr/Kconfig
> new file mode 100644
> index 000000000000..2d0568dd176a
> --- /dev/null
> +++ b/drivers/scsi/mpi3mr/Kconfig
> @@ -0,0 +1,7 @@
> +# SPDX-License-Identifier: GPL-2.0-or-later
> +
> +config SCSI_MPI3MR
> +	tristate "Broadcom MPI3 Storage Controller Device Driver"
> +	depends on PCI && SCSI
> +	help
> +	This driver supports Broadcom's Unified MPI3 based Storage & RAID Controllers.
> diff --git a/drivers/scsi/mpi3mr/mpi/mpi30_api.h b/drivers/scsi/mpi3mr/mpi/mpi30_api.h
> new file mode 100644
> index 000000000000..ca07387536d3
> --- /dev/null
> +++ b/drivers/scsi/mpi3mr/mpi/mpi30_api.h
> @@ -0,0 +1,21 @@
> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> +/*
> + *  Copyright 2019-2020 Broadcom Inc. All rights reserved.
> + *

2020? Sure you don't want to update it to 2021?

> + *           Name: mpi30_api.h
> + *    Description: Root header that include all other MPI 3.0 headers
> + *                 Developers need to only include this header to gain
> + *                 access to the full MPI3.0 API definitions.
> + *  Creation Date: 04/15/2019
> + *        Version: 03.00.00
> + */
> +#ifndef MPI30_API_H
> +#define MPI30_API_H     1
> +
> +#include "mpi30_type.h"
> +#include "mpi30_transport.h"
> +#include "mpi30_image.h"
> +#include "mpi30_init.h"
> +#include "mpi30_ioc.h"
> +
> +#endif  /* MPI30_API_H */
> diff --git a/drivers/scsi/mpi3mr/mpi/mpi30_image.h b/drivers/scsi/mpi3mr/mpi/mpi30_image.h
> new file mode 100644
> index 000000000000..430662d3a43b
> --- /dev/null
> +++ b/drivers/scsi/mpi3mr/mpi/mpi30_image.h
> @@ -0,0 +1,285 @@
> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> +/*
> + *  Copyright 2018-2020 Broadcom Inc. All rights reserved.
> + *
> + *           Name: mpi30_image.h
> + *    Description: Contains definitions for firmware and other component images.
> + *  Creation Date: 04/02/2018
> + *        Version: 03.00.00
> + */
> +#ifndef MPI30_IMAGE_H
> +#define MPI30_IMAGE_H     1
> +
> +/* Component Image Version */
> +typedef struct _MPI3_COMP_IMAGE_VERSION {
> +    U16     BuildNum;            /* 0x00 */
> +    U16     CustomerID;          /* 0x02 */
> +    U8      PhaseMinor;          /* 0x04 */
> +    U8      PhaseMajor;          /* 0x05 */
> +    U8      GenMinor;            /* 0x06 */
> +    U8      GenMajor;            /* 0x07 */
> +} MPI3_COMP_IMAGE_VERSION, MPI3_POINTER PTR_MPI3_COMP_IMAGE_VERSION,
> +  Mpi3CompImageVersion, MPI3_POINTER pMpi3CompImageVersion;
> +
> +/* Hash Exclusion Format */
> +typedef struct _MPI3_HASH_EXCLUSION_FORMAT {
> +    U32                     Offset;        /* 0x00 */
> +    U32                     Size;          /* 0x04 */
> +} MPI3_HASH_EXCLUSION_FORMAT, MPI3_POINTER PTR_MPI3_HASH_EXCLUSION_FORMAT,
> +Mpi3HashSxclusionFormat_t, MPI3_POINTER pMpi3HashExclusionFormat_t;
> +
> +#define MPI3_IMAGE_HASH_EXCUSION_NUM                           (4)
> +
> +/* FW Image Header */
> +typedef struct _MPI3_COMPONENT_IMAGE_HEADER {
> +    U32                            Signature0;                                      /* 0x00 */
> +    U32                            LoadAddress;                                     /* 0x04 */
> +    U32                            DataSize;                                        /* 0x08 */
> +    U32                            StartOffset;                                     /* 0x0C */
> +    U32                            Signature1;                                      /* 0x10 */
> +    U32                            FlashOffset;                                     /* 0x14 */
> +    U32                            ImageSize;                                       /* 0x18 */
> +    U32                            VersionStringOffset;                             /* 0x1C */
> +    U32                            BuildDateStringOffset;                           /* 0x20 */
> +    U32                            BuildTimeStringOffset;                           /* 0x24 */
> +    U32                            EnvironmentVariableOffset;                       /* 0x28 */
> +    U32                            ApplicationSpecific;                             /* 0x2C */
> +    U32                            Signature2;                                      /* 0x30 */
> +    U32                            HeaderSize;                                      /* 0x34 */
> +    U32                            Crc;                                             /* 0x38 */
> +    U32                            Flags;                                           /* 0x3C */
> +    U32                            SecondaryFlashOffset;                            /* 0x40 */
> +    U32                            ETPOffset;                                       /* 0x44 */
> +    U32                            ETPSize;                                         /* 0x48 */
> +    MPI3_VERSION_UNION             RMCInterfaceVersion;                             /* 0x4C */
> +    MPI3_VERSION_UNION             ETPInterfaceVersion;                             /* 0x50 */
> +    MPI3_COMP_IMAGE_VERSION        ComponentImageVersion;                           /* 0x54 */
> +    MPI3_HASH_EXCLUSION_FORMAT     HashExclusion[MPI3_IMAGE_HASH_EXCUSION_NUM];     /* 0x5C */
> +    U32                            NextImageHeaderOffset;                           /* 0x7C */
> +    MPI3_VERSION_UNION             SecurityVersion;                                 /* 0x80 */
> +    U32                            Reserved84[31];                                  /* 0x84 -- 0xFC */
> +} MPI3_COMPONENT_IMAGE_HEADER, MPI3_POINTER PTR_MPI3_COMPONENT_IMAGE_HEADER,
> +  Mpi3ComponentImageHeader_t, MPI3_POINTER pMpi3ComponentImageHeader_t;
> +
> +
> +/**** Definitions for Signature0 field ****/
> +#define MPI3_IMAGE_HEADER_SIGNATURE0_MPI3                     (0xEB00003E)
> +
> +/**** Definitions for LoadAddress field ****/
> +#define MPI3_IMAGE_HEADER_LOAD_ADDRESS_INVALID                (0x00000000)
> +
> +/**** Definitions for Signature1 field ****/
> +#define MPI3_IMAGE_HEADER_SIGNATURE1_APPLICATION              (0x20505041)  /* string "APP "  */
> +#define MPI3_IMAGE_HEADER_SIGNATURE1_FIRST_MUTABLE            (0x20434D46)  /* string "FMC "  */
> +#define MPI3_IMAGE_HEADER_SIGNATURE1_BSP                      (0x20505342)  /* string "BSP "  */
> +#define MPI3_IMAGE_HEADER_SIGNATURE1_ROM_BIOS                 (0x534F4942)  /* string "BIOS"  */
> +#define MPI3_IMAGE_HEADER_SIGNATURE1_HII_X64                  (0x4D494948)  /* string "HIIM"  */
> +#define MPI3_IMAGE_HEADER_SIGNATURE1_HII_ARM                  (0x41494948)  /* string "HIIA"  */
> +#define MPI3_IMAGE_HEADER_SIGNATURE1_CPLD                     (0x444C5043)  /* string "CPLD"  */
> +#define MPI3_IMAGE_HEADER_SIGNATURE1_SPD                      (0x20445053)  /* string "SPD "  */
> +#define MPI3_IMAGE_HEADER_SIGNATURE1_GAS_GAUGE                (0x20534147)  /* string "GAS "  */
> +#define MPI3_IMAGE_HEADER_SIGNATURE1_PBLP                     (0x504C4250)  /* string "PBLP"  */
> +
> +/**** Definitions for Signature2 field ****/
> +#define MPI3_IMAGE_HEADER_SIGNATURE2_VALUE                    (0x50584546)
> +
> +/**** Definitions for Flags field ****/
> +#define MPI3_IMAGE_HEADER_FLAGS_DEVICE_KEY_BASIS_MASK         (0x00000030)
> +#define MPI3_IMAGE_HEADER_FLAGS_DEVICE_KEY_BASIS_CDI          (0x00000000)
> +#define MPI3_IMAGE_HEADER_FLAGS_DEVICE_KEY_BASIS_DI           (0x00000010)
> +#define MPI3_IMAGE_HEADER_FLAGS_SIGNED_NVDATA                 (0x00000008)
> +#define MPI3_IMAGE_HEADER_FLAGS_REQUIRES_ACTIVATION           (0x00000004)
> +#define MPI3_IMAGE_HEADER_FLAGS_COMPRESSED                    (0x00000002)
> +#define MPI3_IMAGE_HEADER_FLAGS_FLASH                         (0x00000001)
> +
> +
> +/**** Offsets for Image Header Fields ****/
> +#define MPI3_IMAGE_HEADER_SIGNATURE0_OFFSET                   (0x00)
> +#define MPI3_IMAGE_HEADER_LOAD_ADDRESS_OFFSET                 (0x04)
> +#define MPI3_IMAGE_HEADER_DATA_SIZE_OFFSET                    (0x08)
> +#define MPI3_IMAGE_HEADER_START_OFFSET_OFFSET                 (0x0C)
> +#define MPI3_IMAGE_HEADER_SIGNATURE1_OFFSET                   (0x10)
> +#define MPI3_IMAGE_HEADER_FLASH_OFFSET_OFFSET                 (0x14)
> +#define MPI3_IMAGE_HEADER_FLASH_SIZE_OFFSET                   (0x18)
> +#define MPI3_IMAGE_HEADER_VERSION_STRING_OFFSET_OFFSET        (0x1C)
> +#define MPI3_IMAGE_HEADER_BUILD_DATE_STRING_OFFSET_OFFSET     (0x20)
> +#define MPI3_IMAGE_HEADER_BUILD_TIME_OFFSET_OFFSET            (0x24)
> +#define MPI3_IMAGE_HEADER_ENVIROMENT_VAR_OFFSET_OFFSET        (0x28)
> +#define MPI3_IMAGE_HEADER_APPLICATION_SPECIFIC_OFFSET         (0x2C)
> +#define MPI3_IMAGE_HEADER_SIGNATURE2_OFFSET                   (0x30)
> +#define MPI3_IMAGE_HEADER_HEADER_SIZE_OFFSET                  (0x34)
> +#define MPI3_IMAGE_HEADER_CRC_OFFSET                          (0x38)
> +#define MPI3_IMAGE_HEADER_FLAGS_OFFSET                        (0x3C)
> +#define MPI3_IMAGE_HEADER_SECONDARY_FLASH_OFFSET_OFFSET       (0x40)
> +#define MPI3_IMAGE_HEADER_ETP_OFFSET_OFFSET                   (0x44)
> +#define MPI3_IMAGE_HEADER_ETP_SIZE_OFFSET                     (0x48)
> +#define MPI3_IMAGE_HEADER_RMC_INTERFACE_VER_OFFSET            (0x4C)
> +#define MPI3_IMAGE_HEADER_ETP_INTERFACE_VER_OFFSET            (0x50)
> +#define MPI3_IMAGE_HEADER_COMPONENT_IMAGE_VER_OFFSET          (0x54)
> +#define MPI3_IMAGE_HEADER_HASH_EXCLUSION_OFFSET               (0x5C)
> +#define MPI3_IMAGE_HEADER_NEXT_IMAGE_HEADER_OFFSET_OFFSET     (0x7C)
> +
> +
> +#define MPI3_IMAGE_HEADER_SIZE                                (0x100)
> +
> +
> +/* Extended Image Header */
> +typedef struct _MPI3_EXTENDED_IMAGE_HEADER {
> +    U8                             ImageType;                  /* 0x00 */
> +    U8                             Reserved01[3];              /* 0x01 */
> +    U32                            Checksum;                   /* 0x04 */
> +    U32                            ImageSize;                  /* 0x08 */
> +    U32                            NextImageHeaderOffset;      /* 0x0C */
> +    U32                            Reserved10[4];              /* 0x10 */
> +    U32                            IdentifyString[8];          /* 0x20 */
> +} MPI3_EXTENDED_IMAGE_HEADER, MPI3_POINTER PTR_MPI3_EXTENDED_IMAGE_HEADER,
> +  Mpi3ExtendedImageHeader_t, MPI3_POINTER pMpi3ExtendedImageHeader_t;
> +
> +/* useful offsets */
> +#define MPI3_EXT_IMAGE_IMAGETYPE_OFFSET         (0x00)
> +#define MPI3_EXT_IMAGE_IMAGESIZE_OFFSET         (0x08)
> +#define MPI3_EXT_IMAGE_NEXTIMAGE_OFFSET         (0x0C)
> +
> +#define MPI3_EXT_IMAGE_HEADER_SIZE              (0x40)
> +
> +/* defines for the ImageType field */
> +#define MPI3_EXT_IMAGE_TYPE_UNSPECIFIED             (0x00)
> +#define MPI3_EXT_IMAGE_TYPE_NVDATA                  (0x03)
> +#define MPI3_EXT_IMAGE_TYPE_SUPPORTED_DEVICES       (0x07)
> +#define MPI3_EXT_IMAGE_TYPE_ENCRYPTED_HASH          (0x09)
> +#define MPI3_EXT_IMAGE_TYPE_RDE                     (0x0A)
> +#define MPI3_EXT_IMAGE_TYPE_AUXILIARY_PROCESSOR     (0x0B)
> +#define MPI3_EXT_IMAGE_TYPE_MIN_PRODUCT_SPECIFIC    (0x80)
> +#define MPI3_EXT_IMAGE_TYPE_MAX_PRODUCT_SPECIFIC    (0xFF)
> +
> +
> +/* Supported Device Data Format */
> +typedef struct _MPI3_SUPPORTED_DEVICE {
> +    U16                     DeviceID;                   /* 0x00 */
> +    U16                     VendorID;                   /* 0x02 */
> +    U16                     DeviceIDMask;               /* 0x04 */
> +    U16                     Reserved06;                 /* 0x06 */
> +    U8                      LowPCIRev;                  /* 0x08 */
> +    U8                      HighPCIRev;                 /* 0x09 */
> +    U16                     Reserved0A;                 /* 0x0A */
> +    U32                     Reserved0C;                 /* 0x0C */
> +} MPI3_SUPPORTED_DEVICE, MPI3_POINTER PTR_MPI3_SUPPORTED_DEVICE,
> +  Mpi3SupportedDevice_t, MPI3_POINTER pMpi3SupportedDevice_t;
> +
> +#ifndef MPI3_SUPPORTED_DEVICE_MAX
> +#define MPI3_SUPPORTED_DEVICE_MAX                      (1)
> +#endif  /* MPI3_SUPPORTED_DEVICE_MAX */
> +
> +/* Supported Devices Extended Image Data */
> +typedef struct _MPI3_SUPPORTED_DEVICES_DATA {
> +    U8                      ImageVersion;                                   /* 0x00 */
> +    U8                      Reserved01;                                     /* 0x01 */
> +    U8                      NumDevices;                                     /* 0x02 */
> +    U8                      Reserved03;                                     /* 0x03 */
> +    U32                     Reserved04;                                     /* 0x04 */
> +    MPI3_SUPPORTED_DEVICE   SupportedDevice[MPI3_SUPPORTED_DEVICE_MAX];     /* 0x08 */    /* variable length */
> +} MPI3_SUPPORTED_DEVICES_DATA, MPI3_POINTER PTR_MPI3_SUPPORTED_DEVICES_DATA,
> +  Mpi3SupportedDevicesData_t, MPI3_POINTER pMpi3SupportedDevicesData_t;
> +
> +#ifndef MPI3_ENCRYPTED_HASH_MAX
> +#define MPI3_ENCRYPTED_HASH_MAX                      (1)
> +#endif  /* MPI3_ENCRYPTED_HASH_MAX */
> +
> +/* Encrypted Hash Entry Format */
> +typedef struct _MPI3_ENCRYPTED_HASH_ENTRY {
> +    U8                      HashImageType;                                  /* 0x00 */
> +    U8                      HashAlgorithm;                                  /* 0x01 */
> +    U8                      EncryptionAlgorithm;                            /* 0x02 */
> +    U8                      Reserved03;                                     /* 0x03 */
> +    U32                     Reserved04;                                     /* 0x04 */
> +    U32                     EncryptedHash[MPI3_ENCRYPTED_HASH_MAX];         /* 0x08 */   /* variable length */
> +} MPI3_ENCRYPTED_HASH_ENTRY, MPI3_POINTER PTR_MPI3_ENCRYPTED_HASH_ENTRY,
> +  Mpi3EncryptedHashEntry_t, MPI3_POINTER pMpi3EncryptedHashEntry_t;
> +
> +
> +/* defines for the HashImageType field */
> +#define MPI3_HASH_IMAGE_TYPE_KEY_WITH_SIGNATURE      (0x03)
> +
> +/* defines for the HashAlgorithm field */
> +#define MPI3_HASH_ALGORITHM_VERSION_MASK             (0xE0)
> +#define MPI3_HASH_ALGORITHM_VERSION_NONE             (0x00)
> +#define MPI3_HASH_ALGORITHM_VERSION_SHA1             (0x20)   /* Obsolete */
> +#define MPI3_HASH_ALGORITHM_VERSION_SHA2             (0x40)
> +#define MPI3_HASH_ALGORITHM_VERSION_SHA3             (0x60)
> +
> +#define MPI3_HASH_ALGORITHM_SIZE_MASK                (0x1F)
> +#define MPI3_HASH_ALGORITHM_SIZE_UNUSED              (0x00)
> +#define MPI3_HASH_ALGORITHM_SIZE_SHA256              (0x01)
> +#define MPI3_HASH_ALGORITHM_SIZE_SHA512              (0x02)
> +
> +/* defines for the EncryptionAlgorithm field */
> +#define MPI3_ENCRYPTION_ALGORITHM_UNUSED             (0x00)
> +#define MPI3_ENCRYPTION_ALGORITHM_RSA256             (0x01)   /* Obsolete */
> +#define MPI3_ENCRYPTION_ALGORITHM_RSA512             (0x02)   /* Obsolete */
> +#define MPI3_ENCRYPTION_ALGORITHM_RSA1024            (0x03)   /* Obsolete */
> +#define MPI3_ENCRYPTION_ALGORITHM_RSA2048            (0x04)
> +#define MPI3_ENCRYPTION_ALGORITHM_RSA4096            (0x05)
> +#define MPI3_ENCRYPTION_ALGORITHM_RSA3072            (0x06)
> +
> +
> +#ifndef MPI3_PUBLIC_KEY_MAX
> +#define MPI3_PUBLIC_KEY_MAX                          (1)
> +#endif  /* MPI3_PUBLIC_KEY_MAX */
> +
> +/* Encrypted Key with Hash Entry Format */
> +typedef struct _MPI3_ENCRYPTED_KEY_WITH_HASH_ENTRY {
> +    U8                      HashImageType;                             /* 0x00 */
> +    U8                      HashAlgorithm;                             /* 0x01 */
> +    U8                      EncryptionAlgorithm;                       /* 0x02 */
> +    U8                      Reserved03;                                /* 0x03 */
> +    U32                     Reserved04;                                /* 0x04 */
> +    U32                     PublicKey[MPI3_PUBLIC_KEY_MAX];            /* 0x08 */     /* variable length */
> +    U32                     EncryptedHash[MPI3_ENCRYPTED_HASH_MAX];    /* 0x0C */     /* variable length */
> +} MPI3_ENCRYPTED_KEY_WITH_HASH_ENTRY, MPI3_POINTER PTR_MPI3_ENCRYPTED_KEY_WITH_HASH_ENTRY,
> +  Mpi3EncryptedKeyWithHashEntry_t, MPI3_POINTER pMpi3EncryptedKeyWithHashEntry_t;
> +
> +#ifndef MPI3_ENCRYPTED_HASH_ENTRY_MAX
> +#define MPI3_ENCRYPTED_HASH_ENTRY_MAX               (1)
> +#endif  /* MPI3_ENCRYPTED_HASH_ENTRY_MAX */
> +
> +/* Encrypted Hash Image Data */
> +typedef struct _MPI3_ENCRYPTED_HASH_DATA {
> +    U8                               ImageVersion;                                          /* 0x00 */
> +    U8                               NumHash;                                               /* 0x01 */
> +    U16                              Reserved02;                                            /* 0x02 */
> +    U32                              Reserved04;                                            /* 0x04 */
> +    MPI3_ENCRYPTED_HASH_ENTRY        EncryptedHashEntry[MPI3_ENCRYPTED_HASH_ENTRY_MAX];     /* 0x08 */   /* variable length */
> +} MPI3_ENCRYPTED_HASH_DATA, MPI3_POINTER PTR_MPI3_ENCRYPTED_HASH_DATA,
> +  Mpi3EncryptedHashData_t, MPI3_POINTER pMpi3EncryptedHashData_t;
> +
> +
> +#ifndef MPI3_AUX_PROC_DATA_MAX
> +#define MPI3_AUX_PROC_DATA_MAX               (1)
> +#endif  /* MPI3_ENCRYPTED_HASH_ENTRY_MAX */
> +
> +/* Auxiliary Processor Extended Image Data */
> +typedef struct _MPI3_AUX_PROCESSOR_DATA {
> +    U8                      BootMethod;                               /* 0x00 */
> +    U8                      NumLoadAddr;                              /* 0x01 */
> +    U8                      Reserved02;                               /* 0x02 */
> +    U8                      Type;                                     /* 0x03 */
> +    U32                     Version;                                  /* 0x04 */
> +    U32                     LoadAddress[8];                           /* 0x08 */
> +    U32                     Reserved28[22];                           /* 0x28 */
> +    U32                     AuxProcessorData[MPI3_AUX_PROC_DATA_MAX]; /* 0x80 */   /* variable length */
> +} MPI3_AUX_PROCESSOR_DATA, MPI3_POINTER PTR_MPI3_AUX_PROCESSOR_DATA,
> +  Mpi3AuxProcessorData_t, MPI3_POINTER pMpi3AuxProcessorData_t;
> +
> +#define MPI3_AUX_PROC_DATA_OFFSET                                     (0x80)
> +
> +/* defines for the BootMethod field */
> +#define MPI3_AUXPROCESSOR_BOOT_METHOD_MO_MSG                          (0x00)
> +#define MPI3_AUXPROCESSOR_BOOT_METHOD_MO_DOORBELL                     (0x01)
> +#define MPI3_AUXPROCESSOR_BOOT_METHOD_COMPONENT                       (0x02)
> +
> +/* defines for the Type field */
> +#define MPI3_AUXPROCESSOR_TYPE_ARM_A15                                (0x00)
> +#define MPI3_AUXPROCESSOR_TYPE_ARM_M0                                 (0x01)
> +#define MPI3_AUXPROCESSOR_TYPE_ARM_R4                                 (0x02)
> +
> +#endif /* MPI30_IMAGE_H */
> diff --git a/drivers/scsi/mpi3mr/mpi/mpi30_init.h b/drivers/scsi/mpi3mr/mpi/mpi30_init.h
> new file mode 100644
> index 000000000000..a0222f0fc9a8
> --- /dev/null
> +++ b/drivers/scsi/mpi3mr/mpi/mpi30_init.h
> @@ -0,0 +1,216 @@
> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> +/*
> + *  Copyright 2016-2020 Broadcom Inc. All rights reserved.
> + *
> + *           Name: mpi30_init.h
> + *    Description: Contains definitions for SCSI initiator mode messages and structures.
> + *  Creation Date: 10/27/2016
> + *        Version: 03.00.00
> + */
> +#ifndef MPI30_INIT_H
> +#define MPI30_INIT_H     1
> +
> +/*****************************************************************************
> + *              SCSI Initiator Messages                                      *
> + ****************************************************************************/
> +
> +/*****************************************************************************
> + *              SCSI IO Request Message                                      *
> + ****************************************************************************/
> +typedef struct _MPI3_SCSI_IO_CDB_EEDP32 {
> +    U8              CDB[20];                            /* 0x00 */
> +    __be32          PrimaryReferenceTag;                /* 0x14 */
> +    U16             PrimaryApplicationTag;              /* 0x18 */
> +    U16             PrimaryApplicationTagMask;          /* 0x1A */
> +    U32             TransferLength;                     /* 0x1C */
> +} MPI3_SCSI_IO_CDB_EEDP32, MPI3_POINTER PTR_MPI3_SCSI_IO_CDB_EEDP32,
> +  Mpi3ScsiIoCdbEedp32_t, MPI3_POINTER pMpi3ScsiIoCdbEedp32_t;
> +

As noted by Bart, this is a bit naff.
I can live with having driver-specific typedefs, but having
driver-specific typedefs _just_ for little endian is pushing it.
(And incidentally also cancels your argument that you need the
driver-specific types for cross-development.)
So please, be consistent, and either use driver-specific typedefs
throughout or revert to use basic linux types.

> +typedef union _MPI3_SCSO_IO_CDB_UNION {
> +    U8                      CDB32[32];
> +    MPI3_SCSI_IO_CDB_EEDP32 EEDP32;
> +    MPI3_SGE_SIMPLE         SGE;
> +} MPI3_SCSO_IO_CDB_UNION, MPI3_POINTER PTR_MPI3_SCSO_IO_CDB_UNION,
> +  Mpi3ScsiIoCdb_t, MPI3_POINTER pMpi3ScsiIoCdb_t;
> +
> +typedef struct _MPI3_SCSI_IO_REQUEST {
> +    U16                     HostTag;                        /* 0x00 */
> +    U8                      IOCUseOnly02;                   /* 0x02 */
> +    U8                      Function;                       /* 0x03 */
> +    U16                     IOCUseOnly04;                   /* 0x04 */
> +    U8                      IOCUseOnly06;                   /* 0x06 */
> +    U8                      MsgFlags;                       /* 0x07 */
> +    U16                     ChangeCount;                    /* 0x08 */
> +    U16                     DevHandle;                      /* 0x0A */
> +    U32                     Flags;                          /* 0x0C */
> +    U32                     SkipCount;                      /* 0x10 */
> +    U32                     DataLength;                     /* 0x14 */
> +    U8                      LUN[8];                         /* 0x18 */
> +    MPI3_SCSO_IO_CDB_UNION  CDB;                            /* 0x20 */
> +    MPI3_SGE_UNION          SGL[4];                         /* 0x40 */
> +} MPI3_SCSI_IO_REQUEST, MPI3_POINTER PTR_MPI3_SCSI_IO_REQUEST,
> +  Mpi3SCSIIORequest_t, MPI3_POINTER pMpi3SCSIIORequest_t;
> +

Ho-hum.
What happens if you have SGLs with more than 4 entries?

> +/**** Defines for the MsgFlags field ****/
> +#define MPI3_SCSIIO_MSGFLAGS_METASGL_VALID                  (0x80)
> +
> +/**** Defines for the Flags field ****/
> +#define MPI3_SCSIIO_FLAGS_LARGE_CDB                         (0x60000000)
> +#define MPI3_SCSIIO_FLAGS_CDB_16_OR_LESS                    (0x00000000)
> +#define MPI3_SCSIIO_FLAGS_CDB_GREATER_THAN_16               (0x20000000)
> +#define MPI3_SCSIIO_FLAGS_CDB_IN_SEPARATE_BUFFER            (0x40000000)
> +#define MPI3_SCSIIO_FLAGS_TASKATTRIBUTE_MASK                (0x07000000)
> +#define MPI3_SCSIIO_FLAGS_TASKATTRIBUTE_SIMPLEQ             (0x00000000)
> +#define MPI3_SCSIIO_FLAGS_TASKATTRIBUTE_HEADOFQ             (0x01000000)
> +#define MPI3_SCSIIO_FLAGS_TASKATTRIBUTE_ORDEREDQ            (0x02000000)
> +#define MPI3_SCSIIO_FLAGS_TASKATTRIBUTE_ACAQ                (0x04000000)
> +#define MPI3_SCSIIO_FLAGS_CMDPRI_MASK                       (0x00F00000)
> +#define MPI3_SCSIIO_FLAGS_CMDPRI_SHIFT                      (20)
> +#define MPI3_SCSIIO_FLAGS_DATADIRECTION_MASK                (0x000C0000)
> +#define MPI3_SCSIIO_FLAGS_DATADIRECTION_NO_DATA_TRANSFER    (0x00000000)
> +#define MPI3_SCSIIO_FLAGS_DATADIRECTION_WRITE               (0x00040000)
> +#define MPI3_SCSIIO_FLAGS_DATADIRECTION_READ                (0x00080000)
> +#define MPI3_SCSIIO_FLAGS_DMAOPERATION_MASK                 (0x00030000)
> +#define MPI3_SCSIIO_FLAGS_DMAOPERATION_HOST_PI              (0x00010000)
> +
> +/**** Defines for the SGL field ****/
> +#define MPI3_SCSIIO_METASGL_INDEX                           (3)
> +
> +/*****************************************************************************
> + *              SCSI IO Error Reply Message                                  *
> + ****************************************************************************/
> +typedef struct _MPI3_SCSI_IO_REPLY {
> +    U16                     HostTag;                        /* 0x00 */
> +    U8                      IOCUseOnly02;                   /* 0x02 */
> +    U8                      Function;                       /* 0x03 */
> +    U16                     IOCUseOnly04;                   /* 0x04 */
> +    U8                      IOCUseOnly06;                   /* 0x06 */
> +    U8                      MsgFlags;                       /* 0x07 */
> +    U16                     IOCUseOnly08;                   /* 0x08 */
> +    U16                     IOCStatus;                      /* 0x0A */
> +    U32                     IOCLogInfo;                     /* 0x0C */
> +    U8                      SCSIStatus;                     /* 0x10 */
> +    U8                      SCSIState;                      /* 0x11 */
> +    U16                     DevHandle;                      /* 0x12 */
> +    U32                     TransferCount;                  /* 0x14 */
> +    U32                     SenseCount;                     /* 0x18 */
> +    U32                     ResponseData;                   /* 0x1C */
> +    U16                     TaskTag;                        /* 0x20 */
> +    U16                     SCSIStatusQualifier;            /* 0x22 */
> +    U32                     EEDPErrorOffset;                /* 0x24 */
> +    U16                     EEDPObservedAppTag;             /* 0x28 */
> +    U16                     EEDPObservedGuard;              /* 0x2A */
> +    U32                     EEDPObservedRefTag;             /* 0x2C */
> +    U64                     SenseDataBufferAddress;         /* 0x30 */
> +} MPI3_SCSI_IO_REPLY, MPI3_POINTER PTR_MPI3_SCSI_IO_REPLY,
> +  Mpi3SCSIIOReply_t, MPI3_POINTER pMpi3SCSIIOReply_t;
> +
> +/**** Defines for the MsgFlags field ****/
> +#define MPI3_SCSIIO_REPLY_MSGFLAGS_REFTAG_OBSERVED_VALID        (0x01)
> +#define MPI3_SCSIIO_REPLY_MSGFLAGS_APPTAG_OBSERVED_VALID        (0x02)
> +#define MPI3_SCSIIO_REPLY_MSGFLAGS_GUARD_OBSERVED_VALID         (0x04)
> +
> +/**** Defines for the SCSIStatus field ****/
> +#define MPI3_SCSI_STATUS_GOOD                   (0x00)
> +#define MPI3_SCSI_STATUS_CHECK_CONDITION        (0x02)
> +#define MPI3_SCSI_STATUS_CONDITION_MET          (0x04)
> +#define MPI3_SCSI_STATUS_BUSY                   (0x08)
> +#define MPI3_SCSI_STATUS_INTERMEDIATE           (0x10)
> +#define MPI3_SCSI_STATUS_INTERMEDIATE_CONDMET   (0x14)
> +#define MPI3_SCSI_STATUS_RESERVATION_CONFLICT   (0x18)
> +#define MPI3_SCSI_STATUS_COMMAND_TERMINATED     (0x22)
> +#define MPI3_SCSI_STATUS_TASK_SET_FULL          (0x28)
> +#define MPI3_SCSI_STATUS_ACA_ACTIVE             (0x30)
> +#define MPI3_SCSI_STATUS_TASK_ABORTED           (0x40)
> +
> +/**** Defines for the SCSIState field ****/
> +#define MPI3_SCSI_STATE_SENSE_MASK              (0x03)
> +#define MPI3_SCSI_STATE_SENSE_VALID             (0x00)
> +#define MPI3_SCSI_STATE_SENSE_FAILED            (0x01)
> +#define MPI3_SCSI_STATE_SENSE_BUFF_Q_EMPTY      (0x02)
> +#define MPI3_SCSI_STATE_SENSE_NOT_AVAILABLE     (0x03)
> +#define MPI3_SCSI_STATE_NO_SCSI_STATUS          (0x04)
> +#define MPI3_SCSI_STATE_TERMINATED              (0x08)
> +#define MPI3_SCSI_STATE_RESPONSE_DATA_VALID     (0x10)
> +
> +/**** Defines for the ResponseData field ****/
> +#define MPI3_SCSI_RSP_RESPONSECODE_MASK         (0x000000FF)
> +#define MPI3_SCSI_RSP_RESPONSECODE_SHIFT        (0)
> +#define MPI3_SCSI_RSP_ARI2_MASK                 (0x0000FF00)
> +#define MPI3_SCSI_RSP_ARI2_SHIFT                (8)
> +#define MPI3_SCSI_RSP_ARI1_MASK                 (0x00FF0000)
> +#define MPI3_SCSI_RSP_ARI1_SHIFT                (16)
> +#define MPI3_SCSI_RSP_ARI0_MASK                 (0xFF000000)
> +#define MPI3_SCSI_RSP_ARI0_SHIFT                (24)
> +
> +/**** Defines for the TaskTag field ****/
> +#define MPI3_SCSI_TASKTAG_UNKNOWN               (0xFFFF)
> +
> +
> +/*****************************************************************************
> + *              SCSI Task Management Request Message                         *
> + ****************************************************************************/
> +typedef struct _MPI3_SCSI_TASK_MGMT_REQUEST {
> +    U16                     HostTag;                        /* 0x00 */
> +    U8                      IOCUseOnly02;                   /* 0x02 */
> +    U8                      Function;                       /* 0x03 */
> +    U16                     IOCUseOnly04;                   /* 0x04 */
> +    U8                      IOCUseOnly06;                   /* 0x06 */
> +    U8                      MsgFlags;                       /* 0x07 */
> +    U16                     ChangeCount;                    /* 0x08 */
> +    U16                     DevHandle;                      /* 0x0A */
> +    U16                     TaskHostTag;                    /* 0x0C */
> +    U8                      TaskType;                       /* 0x0E */
> +    U8                      Reserved0F;                     /* 0x0F */
> +    U16                     TaskRequestQueueID;             /* 0x10 */
> +    U16                     Reserved12;                     /* 0x12 */
> +    U32                     Reserved14;                     /* 0x14 */
> +    U8                      LUN[8];                         /* 0x18 */
> +} MPI3_SCSI_TASK_MGMT_REQUEST, MPI3_POINTER PTR_MPI3_SCSI_TASK_MGMT_REQUEST,
> +  Mpi3SCSITaskMgmtRequest_t, MPI3_POINTER pMpi3SCSITaskMgmtRequest_t;
> +
> +/**** Defines for the MsgFlags field ****/
> +#define MPI3_SCSITASKMGMT_MSGFLAGS_DO_NOT_SEND_TASK_IU      (0x08)
> +
> +/**** Defines for the TaskType field ****/
> +#define MPI3_SCSITASKMGMT_TASKTYPE_ABORT_TASK               (0x01)
> +#define MPI3_SCSITASKMGMT_TASKTYPE_ABORT_TASK_SET           (0x02)
> +#define MPI3_SCSITASKMGMT_TASKTYPE_TARGET_RESET             (0x03)
> +#define MPI3_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET       (0x05)
> +#define MPI3_SCSITASKMGMT_TASKTYPE_CLEAR_TASK_SET           (0x06)
> +#define MPI3_SCSITASKMGMT_TASKTYPE_QUERY_TASK               (0x07)
> +#define MPI3_SCSITASKMGMT_TASKTYPE_CLEAR_ACA                (0x08)
> +#define MPI3_SCSITASKMGMT_TASKTYPE_QUERY_TASK_SET           (0x09)
> +#define MPI3_SCSITASKMGMT_TASKTYPE_QUERY_ASYNC_EVENT        (0x0A)
> +#define MPI3_SCSITASKMGMT_TASKTYPE_I_T_NEXUS_RESET          (0x0B)
> +
> +
> +/*****************************************************************************
> + *              SCSI Task Management Reply Message                           *
> + ****************************************************************************/
> +typedef struct _MPI3_SCSI_TASK_MGMT_REPLY {
> +    U16                     HostTag;                        /* 0x00 */
> +    U8                      IOCUseOnly02;                   /* 0x02 */
> +    U8                      Function;                       /* 0x03 */
> +    U16                     IOCUseOnly04;                   /* 0x04 */
> +    U8                      IOCUseOnly06;                   /* 0x06 */
> +    U8                      MsgFlags;                       /* 0x07 */
> +    U16                     IOCUseOnly08;                   /* 0x08 */
> +    U16                     IOCStatus;                      /* 0x0A */
> +    U32                     IOCLogInfo;                     /* 0x0C */
> +    U32                     TerminationCount;               /* 0x10 */
> +    U32                     ResponseData;                   /* 0x14 */
> +    U32                     Reserved18;                     /* 0x18 */
> +} MPI3_SCSI_TASK_MGMT_REPLY, MPI3_POINTER PTR_MPI3_SCSI_TASK_MGMT_REPLY,
> +  Mpi3SCSITaskMgmtReply_t, MPI3_POINTER pMpi3SCSITaskMgmtReply_t;
> +
> +/**** Defines for the ResponseData field - use MPI3_SCSI_RSP_ defines ****/
> +/*
> + * Values for the ResponseCode (byte 0 of ResponseData) is normally obtained
> + * from the SSP Response frame. A value of 0x80 may be returned by the IOC
> + * for a TaskType of Query Task indicating the specified TaskHostTag I/O is
> + * currently queued on the IOC and has not been sent to the target device yet.
> + */
> +#define MPI3_SCSITASKMGMT_RSPCODE_IO_QUEUED_ON_IOC      (0x80)
> +
> +#endif  /* MPI30_INIT_H */
> diff --git a/drivers/scsi/mpi3mr/mpi/mpi30_ioc.h b/drivers/scsi/mpi3mr/mpi/mpi30_ioc.h
> new file mode 100644
> index 000000000000..880d717000f6
> --- /dev/null
> +++ b/drivers/scsi/mpi3mr/mpi/mpi30_ioc.h
> @@ -0,0 +1,1423 @@
> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> +/*
> + *  Copyright 2016-2020 Broadcom Inc. All rights reserved.
> + *
> + *           Name: mpi30_ioc.h
> + *    Description: Contains definitions for IOC messages such as IOC Init, IOC Facts, Port Enable,
> + *                 Events, FW Download, and FW Upload.
> + *  Creation Date: 10/24/2016
> + *        Version: 03.00.00
> + */
> +#ifndef MPI30_IOC_H
> +#define MPI30_IOC_H     1
> +
> +/*****************************************************************************
> + *              IOC Messages                                                 *
> + ****************************************************************************/
> +
> +/*****************************************************************************
> + *              IOCInit Request Message                                      *
> + ****************************************************************************/
> +typedef struct _MPI3_IOC_INIT_REQUEST {
> +    U16                   HostTag;                            /* 0x00 */
> +    U8                    IOCUseOnly02;                       /* 0x02 */
> +    U8                    Function;                           /* 0x03 */
> +    U16                   IOCUseOnly04;                       /* 0x04 */
> +    U8                    IOCUseOnly06;                       /* 0x06 */
> +    U8                    MsgFlags;                           /* 0x07 */
> +    U16                   ChangeCount;                        /* 0x08 */
> +    U16                   Reserved0A;                         /* 0x0A */
> +    MPI3_VERSION_UNION    MPIVersion;                         /* 0x0C */
> +    U64                   TimeStamp;                          /* 0x10 */
> +    U8                    Reserved18;                         /* 0x18 */
> +    U8                    WhoInit;                            /* 0x19 */
> +    U16                   Reserved1A;                         /* 0x1A */
> +    U16                   ReplyFreeQueueDepth;                /* 0x1C */
> +    U16                   Reserved1E;                         /* 0x1E */
> +    U64                   ReplyFreeQueueAddress;              /* 0x20 */
> +    U32                   Reserved28;                         /* 0x28 */
> +    U16                   SenseBufferFreeQueueDepth;          /* 0x2C */
> +    U16                   SenseBufferLength;                  /* 0x2E */
> +    U64                   SenseBufferFreeQueueAddress;        /* 0x30 */
> +    U64                   DriverInformationAddress;           /* 0x38 */
> +} MPI3_IOC_INIT_REQUEST, MPI3_POINTER PTR_MPI3_IOC_INIT_REQUEST,
> +  Mpi3IOCInitRequest_t, MPI3_POINTER pMpi3IOCInitRequest_t;
> +
> +
> +/**** Defines for the WhoInit field ****/
> +#define MPI3_WHOINIT_NOT_INITIALIZED            (0x00)
> +#define MPI3_WHOINIT_ROM_BIOS                   (0x02)
> +#define MPI3_WHOINIT_HOST_DRIVER                (0x03)
> +#define MPI3_WHOINIT_MANUFACTURER               (0x04)
> +
> +/**** Defines for the DriverInformationAddress field */
> +typedef struct _MPI3_DRIVER_INFO_LAYOUT {
> +    U32             InformationLength;                  /* 0x00 */
> +    U8              DriverSignature[12];                /* 0x04 */
> +    U8              OsName[16];                         /* 0x10 */
> +    U8              OsVersion[12];                      /* 0x20 */
> +    U8              DriverName[20];                     /* 0x2C */
> +    U8              DriverVersion[32];                  /* 0x40 */
> +    U8              DriverReleaseDate[20];              /* 0x60 */
> +    U32             DriverCapabilities;                 /* 0x74 */
> +} MPI3_DRIVER_INFO_LAYOUT, MPI3_POINTER PTR_MPI3_DRIVER_INFO_LAYOUT,
> +  Mpi3DriverInfoLayout_t, MPI3_POINTER pMpi3DriverInfoLayout_t;
> +
> +/*****************************************************************************
> + *              IOCFacts Request Message                                     *
> + ****************************************************************************/
> +typedef struct _MPI3_IOC_FACTS_REQUEST {
> +    U16                 HostTag;                            /* 0x00 */
> +    U8                  IOCUseOnly02;                       /* 0x02 */
> +    U8                  Function;                           /* 0x03 */
> +    U16                 IOCUseOnly04;                       /* 0x04 */
> +    U8                  IOCUseOnly06;                       /* 0x06 */
> +    U8                  MsgFlags;                           /* 0x07 */
> +    U16                 ChangeCount;                        /* 0x08 */
> +    U16                 Reserved0A;                         /* 0x0A */
> +    U32                 Reserved0C;                         /* 0x0C */
> +    MPI3_SGE_UNION      SGL;                                /* 0x10 */
> +} MPI3_IOC_FACTS_REQUEST, MPI3_POINTER PTR_MPI3_IOC_FACTS_REQUEST,
> +  Mpi3IOCFactsRequest_t, MPI3_POINTER pMpi3IOCFactsRequest_t;
> +
> +/*****************************************************************************
> + *              IOCFacts Data                                                *
> + ****************************************************************************/
> +typedef struct _MPI3_IOC_FACTS_DATA {
> +    U16                     IOCFactsDataLength;                 /* 0x00 */
> +    U16                     Reserved02;                         /* 0x02 */
> +    MPI3_VERSION_UNION      MPIVersion;                         /* 0x04 */
> +    MPI3_COMP_IMAGE_VERSION FWVersion;                          /* 0x08 */
> +    U32                     IOCCapabilities;                    /* 0x10 */
> +    U8                      IOCNumber;                          /* 0x14 */
> +    U8                      WhoInit;                            /* 0x15 */
> +    U16                     MaxMSIxVectors;                     /* 0x16 */
> +    U16                     MaxOutstandingRequest;              /* 0x18 */
> +    U16                     ProductID;                          /* 0x1A */
> +    U16                     IOCRequestFrameSize;                /* 0x1C */
> +    U16                     ReplyFrameSize;                     /* 0x1E */
> +    U16                     IOCExceptions;                      /* 0x20 */
> +    U16                     MaxPersistentID;                    /* 0x22 */
> +    U8                      SGEModifierMask;                    /* 0x24 */
> +    U8                      SGEModifierValue;                   /* 0x25 */
> +    U8                      SGEModifierShift;                   /* 0x26 */
> +    U8                      ProtocolFlags;                      /* 0x27 */
> +    U16                     MaxSASInitiators;                   /* 0x28 */
> +    U16                     MaxSASTargets;                      /* 0x2A */
> +    U16                     MaxSASExpanders;                    /* 0x2C */
> +    U16                     MaxEnclosures;                      /* 0x2E */
> +    U16                     MinDevHandle;                       /* 0x30 */
> +    U16                     MaxDevHandle;                       /* 0x32 */
> +    U16                     MaxPCIeSwitches;                    /* 0x34 */
> +    U16                     MaxNVMe;                            /* 0x36 */
> +    U16                     MaxPDs;                             /* 0x38 */
> +    U16                     MaxVDs;                             /* 0x3A */
> +    U16                     MaxHostPDs;                         /* 0x3C */
> +    U16                     MaxAdvancedHostPDs;                 /* 0x3E */
> +    U16                     MaxRAIDPDs;                         /* 0x40 */
> +    U16                     MaxPostedCmdBuffers;                /* 0x42 */
> +    U32                     Flags;                              /* 0x44 */
> +    U16                     MaxOperationalRequestQueues;        /* 0x48 */
> +    U16                     MaxOperationalReplyQueues;          /* 0x4A */
> +    U16                     ShutdownTimeout;                    /* 0x4C */
> +    U16                     Reserved4E;                         /* 0x4E */
> +    U32                     DiagTraceSize;                      /* 0x50 */
> +    U32                     DiagFwSize;                         /* 0x54 */
> +} MPI3_IOC_FACTS_DATA, MPI3_POINTER PTR_MPI3_IOC_FACTS_DATA,
> +  Mpi3IOCFactsData_t, MPI3_POINTER pMpi3IOCFactsData_t;
> +
> +/**** Defines for the IOCCapabilities field ****/
> +#define MPI3_IOCFACTS_CAPABILITY_ADVANCED_HOST_PD             (0x00000010)
> +#define MPI3_IOCFACTS_CAPABILITY_RAID_CAPABLE                 (0x00000008)
> +#define MPI3_IOCFACTS_CAPABILITY_COALESCE_CTRL_GRAN_MASK      (0x00000001)
> +#define MPI3_IOCFACTS_CAPABILITY_COALESCE_CTRL_IOC_GRAN       (0x00000000)
> +#define MPI3_IOCFACTS_CAPABILITY_COALESCE_CTRL_REPLY_Q_GRAN   (0x00000001)
> +
> +/**** WhoInit values are defined under IOCInit Request Message definition ****/
> +
> +/**** Defines for the ProductID field ****/
> +#define MPI3_IOCFACTS_PID_TYPE_MASK                           (0xF000)
> +#define MPI3_IOCFACTS_PID_TYPE_SHIFT                          (12)
> +#define MPI3_IOCFACTS_PID_PRODUCT_MASK                        (0x0F00)
> +#define MPI3_IOCFACTS_PID_PRODUCT_SHIFT                       (8)
> +#define MPI3_IOCFACTS_PID_FAMILY_MASK                         (0x00FF)
> +#define MPI3_IOCFACTS_PID_FAMILY_SHIFT                        (0)
> +
> +/**** Defines for the IOCExceptions field ****/
> +#define MPI3_IOCFACTS_EXCEPT_SAFE_MODE                        (0x0800)
> +#define MPI3_IOCFACTS_EXCEPT_SECURITY_KEY_MASK                (0x0700)
> +#define MPI3_IOCFACTS_EXCEPT_SECURITY_KEY_NONE                (0x0000)
> +#define MPI3_IOCFACTS_EXCEPT_SECURITY_KEY_LOCAL_VIA_RAID      (0x0100)
> +#define MPI3_IOCFACTS_EXCEPT_SECURITY_KEY_LOCAL_VIA_OOB       (0x0200)
> +#define MPI3_IOCFACTS_EXCEPT_SECURITY_KEY_EXT_VIA_RAID        (0x0300)
> +#define MPI3_IOCFACTS_EXCEPT_SECURITY_KEY_EXT_VIA_OOB         (0x0400)
> +#define MPI3_IOCFACTS_EXCEPT_PCIE_DISABLED                    (0x0080)
> +#define MPI3_IOCFACTS_EXCEPT_PARTIAL_MEMORY_FAILURE           (0x0040)
> +#define MPI3_IOCFACTS_EXCEPT_MANUFACT_CHECKSUM_FAIL           (0x0020)
> +#define MPI3_IOCFACTS_EXCEPT_FW_CHECKSUM_FAIL                 (0x0010)
> +#define MPI3_IOCFACTS_EXCEPT_CONFIG_CHECKSUM_FAIL             (0x0008)
> +#define MPI3_IOCFACTS_EXCEPT_BOOTSTAT_MASK                    (0x0001)
> +#define MPI3_IOCFACTS_EXCEPT_BOOTSTAT_PRIMARY                 (0x0000)
> +#define MPI3_IOCFACTS_EXCEPT_BOOTSTAT_SECONDARY               (0x0001)
> +
> +/**** Defines for the ProtocolFlags field ****/
> +#define MPI3_IOCFACTS_PROTOCOL_SAS                            (0x0010)
> +#define MPI3_IOCFACTS_PROTOCOL_SATA                           (0x0008)
> +#define MPI3_IOCFACTS_PROTOCOL_NVME                           (0x0004)
> +#define MPI3_IOCFACTS_PROTOCOL_SCSI_INITIATOR                 (0x0002)
> +#define MPI3_IOCFACTS_PROTOCOL_SCSI_TARGET                    (0x0001)
> +
> +/**** Defines for the Flags field ****/
> +#define MPI3_IOCFACTS_FLAGS_SIGNED_NVDATA_REQUIRED            (0x00010000)
> +#define MPI3_IOCFACTS_FLAGS_DMA_ADDRESS_WIDTH_MASK            (0x0000FF00)
> +#define MPI3_IOCFACTS_FLAGS_DMA_ADDRESS_WIDTH_SHIFT           (8)
> +#define MPI3_IOCFACTS_FLAGS_INITIAL_PORT_ENABLE_MASK          (0x00000030)
> +#define MPI3_IOCFACTS_FLAGS_INITIAL_PORT_ENABLE_NOT_STARTED   (0x00000000)
> +#define MPI3_IOCFACTS_FLAGS_INITIAL_PORT_ENABLE_IN_PROGRESS   (0x00000010)
> +#define MPI3_IOCFACTS_FLAGS_INITIAL_PORT_ENABLE_COMPLETE      (0x00000020)
> +#define MPI3_IOCFACTS_FLAGS_PERSONALITY_MASK                  (0x0000000F)
> +#define MPI3_IOCFACTS_FLAGS_PERSONALITY_EHBA                  (0x00000000)
> +#define MPI3_IOCFACTS_FLAGS_PERSONALITY_RAID_DDR              (0x00000002)
> +
> +
> +/*****************************************************************************
> + *              Management Passthrough Request Message                      *
> + ****************************************************************************/
> +typedef struct _MPI3_MGMT_PASSTHROUGH_REQUEST {
> +    U16                 HostTag;                        /* 0x00 */
> +    U8                  IOCUseOnly02;                   /* 0x02 */
> +    U8                  Function;                       /* 0x03 */
> +    U16                 IOCUseOnly04;                   /* 0x04 */
> +    U8                  IOCUseOnly06;                   /* 0x06 */
> +    U8                  MsgFlags;                       /* 0x07 */
> +    U16                 ChangeCount;                    /* 0x08 */
> +    U16                 Reserved0A;                     /* 0x0A */
> +    U32                 Reserved0C[5];                  /* 0x0C */
> +    MPI3_SGE_UNION      CommandSGL;                     /* 0x20 */
> +    MPI3_SGE_UNION      ResponseSGL;                    /* 0x30 */
> +} MPI3_MGMT_PASSTHROUGH_REQUEST, MPI3_POINTER PTR_MPI3_MGMT_PASSTHROUGH_REQUEST,
> +  Mpi3MgmtPassthroughRequest_t, MPI3_POINTER pMpi3MgmtPassthroughRequest_t;
> +
> +/*****************************************************************************
> + *              CreateRequestQueue Request Message                        *
> + ****************************************************************************/
> +typedef struct _MPI3_CREATE_REQUEST_QUEUE_REQUEST {
> +    U16             HostTag;                            /* 0x00 */
> +    U8              IOCUseOnly02;                       /* 0x02 */
> +    U8              Function;                           /* 0x03 */
> +    U16             IOCUseOnly04;                       /* 0x04 */
> +    U8              IOCUseOnly06;                       /* 0x06 */
> +    U8              MsgFlags;                           /* 0x07 */
> +    U16             ChangeCount;                        /* 0x08 */
> +    U8              Flags;                              /* 0x0A */
> +    U8              Burst;                              /* 0x0B */
> +    U16             Size;                               /* 0x0C */
> +    U16             QueueID;                            /* 0x0E */
> +    U16             ReplyQueueID;                       /* 0x10 */
> +    U16             Reserved12;                         /* 0x12 */
> +    U32             Reserved14;                         /* 0x14 */
> +    U64             BaseAddress;                        /* 0x18 */
> +} MPI3_CREATE_REQUEST_QUEUE_REQUEST, MPI3_POINTER PTR_MPI3_CREATE_REQUEST_QUEUE_REQUEST,
> +  Mpi3CreateRequestQueueRequest_t, MPI3_POINTER pMpi3CreateRequestQueueRequest_t;
> +
> +/**** Defines for the Flags field ****/
> +#define MPI3_CREATE_REQUEST_QUEUE_FLAGS_SEGMENTED_MASK          (0x80)
> +#define MPI3_CREATE_REQUEST_QUEUE_FLAGS_SEGMENTED_SEGMENTED     (0x80)
> +#define MPI3_CREATE_REQUEST_QUEUE_FLAGS_SEGMENTED_CONTIGUOUS    (0x00)
> +
> +
> +/*****************************************************************************
> + *              DeleteRequestQueue Request Message                        *
> + ****************************************************************************/
> +typedef struct _MPI3_DELETE_REQUEST_QUEUE_REQUEST {
> +    U16             HostTag;                            /* 0x00 */
> +    U8              IOCUseOnly02;                       /* 0x02 */
> +    U8              Function;                           /* 0x03 */
> +    U16             IOCUseOnly04;                       /* 0x04 */
> +    U8              IOCUseOnly06;                       /* 0x06 */
> +    U8              MsgFlags;                           /* 0x07 */
> +    U16             ChangeCount;                        /* 0x08 */
> +    U16             QueueID;                            /* 0x0A */
> +} MPI3_DELETE_REQUEST_QUEUE_REQUEST, MPI3_POINTER PTR_MPI3_DELETE_REQUEST_QUEUE_REQUEST,
> +  Mpi3DeleteRequestQueueRequest_t, MPI3_POINTER pMpi3DeleteRequestQueueRequest_t;
> +
> +
> +/*****************************************************************************
> + *              CreateReplyQueue Request Message                          *
> + ****************************************************************************/
> +typedef struct _MPI3_CREATE_REPLY_QUEUE_REQUEST {
> +    U16             HostTag;                            /* 0x00 */
> +    U8              IOCUseOnly02;                       /* 0x02 */
> +    U8              Function;                           /* 0x03 */
> +    U16             IOCUseOnly04;                       /* 0x04 */
> +    U8              IOCUseOnly06;                       /* 0x06 */
> +    U8              MsgFlags;                           /* 0x07 */
> +    U16             ChangeCount;                        /* 0x08 */
> +    U8              Flags;                              /* 0x0A */
> +    U8              Reserved0B;                         /* 0x0B */
> +    U16             Size;                               /* 0x0C */
> +    U16             QueueID;                            /* 0x0E */
> +    U16             MSIxIndex;                          /* 0x10 */
> +    U16             Reserved12;                         /* 0x12 */
> +    U32             Reserved14;                         /* 0x14 */
> +    U64             BaseAddress;                        /* 0x18 */
> +} MPI3_CREATE_REPLY_QUEUE_REQUEST, MPI3_POINTER PTR_MPI3_CREATE_REPLY_QUEUE_REQUEST,
> +  Mpi3CreateReplyQueueRequest_t, MPI3_POINTER pMpi3CreateReplyQueueRequest_t;
> +
> +/**** Defines for the Flags field ****/
> +#define MPI3_CREATE_REPLY_QUEUE_FLAGS_SEGMENTED_MASK            (0x80)
> +#define MPI3_CREATE_REPLY_QUEUE_FLAGS_SEGMENTED_SEGMENTED       (0x80)
> +#define MPI3_CREATE_REPLY_QUEUE_FLAGS_SEGMENTED_CONTIGUOUS      (0x00)
> +#define MPI3_CREATE_REPLY_QUEUE_FLAGS_INT_ENABLE_MASK           (0x01)
> +#define MPI3_CREATE_REPLY_QUEUE_FLAGS_INT_ENABLE_DISABLE        (0x00)
> +#define MPI3_CREATE_REPLY_QUEUE_FLAGS_INT_ENABLE_ENABLE         (0x01)
> +
> +
> +/*****************************************************************************
> + *              DeleteReplyQueue Request Message                          *
> + ****************************************************************************/
> +typedef struct _MPI3_DELETE_REPLY_QUEUE_REQUEST {
> +    U16             HostTag;                            /* 0x00 */
> +    U8              IOCUseOnly02;                       /* 0x02 */
> +    U8              Function;                           /* 0x03 */
> +    U16             IOCUseOnly04;                       /* 0x04 */
> +    U8              IOCUseOnly06;                       /* 0x06 */
> +    U8              MsgFlags;                           /* 0x07 */
> +    U16             ChangeCount;                        /* 0x08 */
> +    U16             QueueID;                            /* 0x0A */
> +} MPI3_DELETE_REPLY_QUEUE_REQUEST, MPI3_POINTER PTR_MPI3_DELETE_REPLY_QUEUE_REQUEST,
> +  Mpi3DeleteReplyQueueRequest_t, MPI3_POINTER pMpi3DeleteReplyQueueRequest_t;
> +
> +
> +/*****************************************************************************
> + *              PortEnable Request Message                                   *
> + ****************************************************************************/
> +typedef struct _MPI3_PORT_ENABLE_REQUEST {
> +    U16             HostTag;                            /* 0x00 */
> +    U8              IOCUseOnly02;                       /* 0x02 */
> +    U8              Function;                           /* 0x03 */
> +    U16             IOCUseOnly04;                       /* 0x04 */
> +    U8              IOCUseOnly06;                       /* 0x06 */
> +    U8              MsgFlags;                           /* 0x07 */
> +    U16             ChangeCount;                        /* 0x08 */
> +    U16             Reserved0A;                         /* 0x0A */
> +} MPI3_PORT_ENABLE_REQUEST, MPI3_POINTER PTR_MPI3_PORT_ENABLE_REQUEST,
> +  Mpi3PortEnableRequest_t, MPI3_POINTER pMpi3PortEnableRequest_t;
> +
> +
> +/*****************************************************************************
> + *              IOC Events and Event Management                              *
> + ****************************************************************************/
> +#define MPI3_EVENT_LOG_DATA                         (0x01)
> +#define MPI3_EVENT_CHANGE                           (0x02)
> +#define MPI3_EVENT_GPIO_INTERRUPT                   (0x04)
> +#define MPI3_EVENT_TEMP_THRESHOLD                   (0x05)
> +#define MPI3_EVENT_CABLE_MGMT                       (0x06)
> +#define MPI3_EVENT_DEVICE_ADDED                     (0x07)
> +#define MPI3_EVENT_DEVICE_INFO_CHANGED              (0x08)
> +#define MPI3_EVENT_PREPARE_FOR_RESET                (0x09)
> +#define MPI3_EVENT_COMP_IMAGE_ACT_START             (0x0A)
> +#define MPI3_EVENT_ENCL_DEVICE_ADDED                (0x0B)
> +#define MPI3_EVENT_ENCL_DEVICE_STATUS_CHANGE        (0x0C)
> +#define MPI3_EVENT_DEVICE_STATUS_CHANGE             (0x0D)
> +#define MPI3_EVENT_ENERGY_PACK_CHANGE               (0x0E)
> +#define MPI3_EVENT_SAS_DISCOVERY                    (0x11)
> +#define MPI3_EVENT_SAS_BROADCAST_PRIMITIVE          (0x12)
> +#define MPI3_EVENT_SAS_NOTIFY_PRIMITIVE             (0x13)
> +#define MPI3_EVENT_SAS_INIT_DEVICE_STATUS_CHANGE    (0x14)
> +#define MPI3_EVENT_SAS_INIT_TABLE_OVERFLOW          (0x15)
> +#define MPI3_EVENT_SAS_TOPOLOGY_CHANGE_LIST         (0x16)
> +#define MPI3_EVENT_SAS_PHY_COUNTER                  (0x18)
> +#define MPI3_EVENT_SAS_DEVICE_DISCOVERY_ERROR       (0x19)
> +#define MPI3_EVENT_PCIE_TOPOLOGY_CHANGE_LIST        (0x20)
> +#define MPI3_EVENT_PCIE_ENUMERATION                 (0x22)
> +#define MPI3_EVENT_HARD_RESET_RECEIVED              (0x40)
> +#define MPI3_EVENT_MIN_PRODUCT_SPECIFIC             (0x60)
> +#define MPI3_EVENT_MAX_PRODUCT_SPECIFIC             (0x7F)
> +
> +
> +/*****************************************************************************
> + *              Event Notification Request Message                           *
> + ****************************************************************************/
> +#define MPI3_EVENT_NOTIFY_EVENTMASK_WORDS           (4)
> +
> +typedef struct _MPI3_EVENT_NOTIFICATION_REQUEST {
> +    U16             HostTag;                                            /* 0x00 */
> +    U8              IOCUseOnly02;                                       /* 0x02 */
> +    U8              Function;                                           /* 0x03 */
> +    U16             IOCUseOnly04;                                       /* 0x04 */
> +    U8              IOCUseOnly06;                                       /* 0x06 */
> +    U8              MsgFlags;                                           /* 0x07 */
> +    U16             ChangeCount;                                        /* 0x08 */
> +    U16             Reserved0A;                                         /* 0x0A */
> +    U16             SASBroadcastPrimitiveMasks;                         /* 0x0C */
> +    U16             SASNotifyPrimitiveMasks;                            /* 0x0E */
> +    U32             EventMasks[MPI3_EVENT_NOTIFY_EVENTMASK_WORDS];      /* 0x10 */
> +} MPI3_EVENT_NOTIFICATION_REQUEST, MPI3_POINTER PTR_MPI3_EVENT_NOTIFICATION_REQUEST,
> +  Mpi3EventNotificationRequest_t, MPI3_POINTER pMpi3EventNotificationRequest_t;
> +
> +/**** Defines for the SASBroadcastPrimitiveMasks field - use MPI3_EVENT_PRIMITIVE_ values ****/
> +
> +/**** Defines for the SASNotifyPrimitiveMasks field - use MPI3_EVENT_NOTIFY_ values ****/
> +
> +/**** Defines for the EventMasks field - use MPI3_EVENT_ values ****/
> +
> +/*****************************************************************************
> + *              Event Notification Reply Message                             *
> + ****************************************************************************/
> +typedef struct _MPI3_EVENT_NOTIFICATION_REPLY {
> +    U16             HostTag;                /* 0x00 */
> +    U8              IOCUseOnly02;           /* 0x02 */
> +    U8              Function;               /* 0x03 */
> +    U16             IOCUseOnly04;           /* 0x04 */
> +    U8              IOCUseOnly06;           /* 0x06 */
> +    U8              MsgFlags;               /* 0x07 */
> +    U16             IOCUseOnly08;           /* 0x08 */
> +    U16             IOCStatus;              /* 0x0A */
> +    U32             IOCLogInfo;             /* 0x0C */
> +    U8              EventDataLength;        /* 0x10 */
> +    U8              Event;                  /* 0x11 */
> +    U16             IOCChangeCount;         /* 0x12 */
> +    U32             EventContext;           /* 0x14 */
> +    U32             EventData[1];           /* 0x18 */
> +} MPI3_EVENT_NOTIFICATION_REPLY, MPI3_POINTER PTR_MPI3_EVENT_NOTIFICATION_REPLY,
> +  Mpi3EventNotificationReply_t, MPI3_POINTER pMpi3EventNotificationReply_t;
> +
> +/**** Defines for the MsgFlags field ****/
> +#define MPI3_EVENT_NOTIFY_MSGFLAGS_ACK_MASK                        (0x01)
> +#define MPI3_EVENT_NOTIFY_MSGFLAGS_ACK_REQUIRED                    (0x01)
> +#define MPI3_EVENT_NOTIFY_MSGFLAGS_ACK_NOT_REQUIRED                (0x00)
> +#define MPI3_EVENT_NOTIFY_MSGFLAGS_EVENT_ORIGINALITY_MASK          (0x02)
> +#define MPI3_EVENT_NOTIFY_MSGFLAGS_EVENT_ORIGINALITY_ORIGINAL      (0x00)
> +#define MPI3_EVENT_NOTIFY_MSGFLAGS_EVENT_ORIGINALITY_REPLAY        (0x02)
> +
> +/**** Defines for the Event field - use MPI3_EVENT_ values ****/
> +
> +
> +/*****************************************************************************
> + *              GPIO Interrupt Event                                         *
> + ****************************************************************************/
> +typedef struct _MPI3_EVENT_DATA_GPIO_INTERRUPT {
> +    U8              GPIONum;            /* 0x00 */
> +    U8              Reserved01[3];      /* 0x01 */
> +} MPI3_EVENT_DATA_GPIO_INTERRUPT, MPI3_POINTER PTR_MPI3_EVENT_DATA_GPIO_INTERRUPT,
> +  Mpi3EventDataGpioInterrupt_t, MPI3_POINTER pMpi3EventDataGpioInterrupt_t;
> +
> +
> +/*****************************************************************************
> + *              Temperature Threshold Event                                  *
> + ****************************************************************************/
> +typedef struct _MPI3_EVENT_DATA_TEMP_THRESHOLD {
> +    U16             Status;                 /* 0x00 */
> +    U8              SensorNum;              /* 0x02 */
> +    U8              Reserved03;             /* 0x03 */
> +    U16             CurrentTemperature;     /* 0x04 */
> +    U16             Reserved06;             /* 0x06 */
> +    U32             Reserved08;             /* 0x08 */
> +    U32             Reserved0C;             /* 0x0C */
> +} MPI3_EVENT_DATA_TEMP_THRESHOLD, MPI3_POINTER PTR_MPI3_EVENT_DATA_TEMP_THRESHOLD,
> +  Mpi3EventDataTempThreshold_t, MPI3_POINTER pMpi3EventDataTempThreshold_t;
> +
> +/**** Defines for the Status field ****/
> +#define MPI3_EVENT_TEMP_THRESHOLD_STATUS_THRESHOLD3_EXCEEDED         (0x0008)
> +#define MPI3_EVENT_TEMP_THRESHOLD_STATUS_THRESHOLD2_EXCEEDED         (0x0004)
> +#define MPI3_EVENT_TEMP_THRESHOLD_STATUS_THRESHOLD1_EXCEEDED         (0x0002)
> +#define MPI3_EVENT_TEMP_THRESHOLD_STATUS_THRESHOLD0_EXCEEDED         (0x0001)
> +
> +
> +/*****************************************************************************
> + *              Cable Management Event                                       *
> + ****************************************************************************/
> +typedef struct _MPI3_EVENT_DATA_CABLE_MANAGEMENT {
> +    U32             ActiveCablePowerRequirement;    /* 0x00 */
> +    U8              Status;                         /* 0x04 */
> +    U8              ReceptacleID;                   /* 0x05 */
> +    U16             Reserved06;                     /* 0x06 */
> +} MPI3_EVENT_DATA_CABLE_MANAGEMENT, MPI3_POINTER PTR_MPI3_EVENT_DATA_CABLE_MANAGEMENT,
> +  Mpi3EventDataCableManagement_t, MPI3_POINTER pMpi3EventDataCableManagement_t;
> +
> +/**** Defines for the ActiveCablePowerRequirement field ****/
> +#define MPI3_EVENT_CABLE_MGMT_ACT_CABLE_PWR_INVALID     (0xFFFFFFFF)
> +
> +/**** Defines for the Status field ****/
> +#define MPI3_EVENT_CABLE_MGMT_STATUS_INSUFFICIENT_POWER        (0x00)
> +#define MPI3_EVENT_CABLE_MGMT_STATUS_PRESENT                   (0x01)
> +#define MPI3_EVENT_CABLE_MGMT_STATUS_DEGRADED                  (0x02)
> +
> +
> +/*****************************************************************************
> + *              Event Ack Request Message                                    *
> + ****************************************************************************/
> +typedef struct _MPI3_EVENT_ACK_REQUEST {
> +    U16             HostTag;            /* 0x00 */
> +    U8              IOCUseOnly02;       /* 0x02 */
> +    U8              Function;           /* 0x03 */
> +    U16             IOCUseOnly04;       /* 0x04 */
> +    U8              IOCUseOnly06;       /* 0x06 */
> +    U8              MsgFlags;           /* 0x07 */
> +    U16             ChangeCount;        /* 0x08 */
> +    U16             Reserved0A;         /* 0x0A */
> +    U8              Event;              /* 0x0C */
> +    U8              Reserved0D[3];      /* 0x0D */
> +    U32             EventContext;       /* 0x10 */
> +} MPI3_EVENT_ACK_REQUEST, MPI3_POINTER PTR_MPI3_EVENT_ACK_REQUEST,
> +  Mpi3EventAckRequest_t, MPI3_POINTER pMpi3EventAckRequest_t;
> +
> +/**** Defines for the Event field - use MPI3_EVENT_ values ****/
> +
> +
> +/*****************************************************************************
> + *              Prepare for Reset Event                                      *
> + ****************************************************************************/
> +typedef struct _MPI3_EVENT_DATA_PREPARE_FOR_RESET {
> +    U8              ReasonCode;         /* 0x00 */
> +    U8              Reserved01;         /* 0x01 */
> +    U16             Reserved02;         /* 0x02 */
> +} MPI3_EVENT_DATA_PREPARE_FOR_RESET, MPI3_POINTER PTR_MPI3_EVENT_DATA_PREPARE_FOR_RESET,
> +  Mpi3EventDataPrepareForReset_t, MPI3_POINTER pMpi3EventDataPrepareForReset_t;
> +
> +/**** Defines for the ReasonCode field ****/
> +#define MPI3_EVENT_PREPARE_RESET_RC_START                (0x01)
> +#define MPI3_EVENT_PREPARE_RESET_RC_ABORT                (0x02)
> +
> +
> +/*****************************************************************************
> + *              Component Image Activation Start Event                       *
> + ****************************************************************************/
> +typedef struct _MPI3_EVENT_DATA_COMP_IMAGE_ACTIVATION {
> +    U32            Reserved00;         /* 0x00 */
> +} MPI3_EVENT_DATA_COMP_IMAGE_ACTIVATION, MPI3_POINTER PTR_MPI3_EVENT_DATA_COMP_IMAGE_ACTIVATION,
> +  Mpi3EventDataCompImageActivation, MPI3_POINTER pMpi3EventDataCompImageActivation;
> +
> +/*****************************************************************************
> + *              Device Added Event                                           *
> + ****************************************************************************/
> +/*
> + * The Device Added Event Data is exactly the same as Device Page 0 data
> + * (including the Configuration Page header). So, please use/refer to
> + * MPI3_DEVICE_PAGE0  structure for Device Added Event data.
> + */
> +
> +/****************************************************************************
> + *              Device Info Changed Event                                   *
> + ****************************************************************************/
> +/*
> + * The Device Info Changed Event Data is exactly the same as Device Page 0 data
> + * (including the Configuration Page header). So, please use/refer to
> + * MPI3_DEVICE_PAGE0  structure for Device Added Event data.
> + */
> +
> +/*****************************************************************************
> + *              Device Status Change Event                                  *
> + ****************************************************************************/
> +typedef struct _MPI3_EVENT_DATA_DEVICE_STATUS_CHANGE {
> +    U16             TaskTag;            /* 0x00 */
> +    U8              ReasonCode;         /* 0x02 */
> +    U8              IOUnitPort;         /* 0x03 */
> +    U16             ParentDevHandle;    /* 0x04 */
> +    U16             DevHandle;          /* 0x06 */
> +    U64             WWID;               /* 0x08 */
> +    U8              LUN[8];             /* 0x10 */
> +} MPI3_EVENT_DATA_DEVICE_STATUS_CHANGE, MPI3_POINTER PTR_MPI3_EVENT_DATA_DEVICE_STATUS_CHANGE,
> +  Mpi3EventDataDeviceStatusChange_t, MPI3_POINTER pMpi3EventDataDeviceStatusChange_t;
> +
> +/**** Defines for the ReasonCode field ****/
> +#define MPI3_EVENT_DEV_STAT_RC_MOVED                                (0x01)
> +#define MPI3_EVENT_DEV_STAT_RC_HIDDEN                               (0x02)
> +#define MPI3_EVENT_DEV_STAT_RC_NOT_HIDDEN                           (0x03)
> +#define MPI3_EVENT_DEV_STAT_RC_ASYNC_NOTIFICATION                   (0x04)
> +#define MPI3_EVENT_DEV_STAT_RC_INT_DEVICE_RESET_STRT                (0x20)
> +#define MPI3_EVENT_DEV_STAT_RC_INT_DEVICE_RESET_CMP                 (0x21)
> +#define MPI3_EVENT_DEV_STAT_RC_INT_TASK_ABORT_STRT                  (0x22)
> +#define MPI3_EVENT_DEV_STAT_RC_INT_TASK_ABORT_CMP                   (0x23)
> +#define MPI3_EVENT_DEV_STAT_RC_INT_IT_NEXUS_RESET_STRT              (0x24)
> +#define MPI3_EVENT_DEV_STAT_RC_INT_IT_NEXUS_RESET_CMP               (0x25)
> +#define MPI3_EVENT_DEV_STAT_RC_PCIE_HOT_RESET_FAILED                (0x30)
> +#define MPI3_EVENT_DEV_STAT_RC_EXPANDER_REDUCED_FUNC_STRT           (0x40)
> +#define MPI3_EVENT_DEV_STAT_RC_EXPANDER_REDUCED_FUNC_CMP            (0x41)
> +#define MPI3_EVENT_DEV_STAT_RC_VD_NOT_RESPONDING                    (0x50)
> +
> +/*****************************************************************************
> + *              Energy Pack Change Event                                    *
> + ****************************************************************************/
> +typedef struct _MPI3_EVENT_DATA_ENERGY_PACK_CHANGE {
> +    U32             Reserved00;         /* 0x00 */
> +    U16             ShutdownTimeout;    /* 0x04 */
> +    U16             Reserved06;         /* 0x06 */
> +} MPI3_EVENT_DATA_ENERGY_PACK_CHANGE, MPI3_POINTER PTR_MPI3_EVENT_DATA_ENERGY_PACK_CHANGE,
> +  Mpi3EventDataEnergyPackChange_t, MPI3_POINTER pMpi3EventDataEnergyPackChange_t;
> +
> +/*****************************************************************************
> + *              SAS Discovery Event                                          *
> + ****************************************************************************/
> +typedef struct _MPI3_EVENT_DATA_SAS_DISCOVERY {
> +    U8              Flags;              /* 0x00 */
> +    U8              ReasonCode;         /* 0x01 */
> +    U8              IOUnitPort;         /* 0x02 */
> +    U8              Reserved03;         /* 0x03 */
> +    U32             DiscoveryStatus;    /* 0x04 */
> +} MPI3_EVENT_DATA_SAS_DISCOVERY, MPI3_POINTER PTR_MPI3_EVENT_DATA_SAS_DISCOVERY,
> +  Mpi3EventDataSasDiscovery_t, MPI3_POINTER pMpi3EventDataSasDiscovery_t;
> +
> +/**** Defines for the Flags field ****/
> +#define MPI3_EVENT_SAS_DISC_FLAGS_DEVICE_CHANGE                 (0x02)
> +#define MPI3_EVENT_SAS_DISC_FLAGS_IN_PROGRESS                   (0x01)
> +
> +/**** Defines for the ReasonCode field ****/
> +#define MPI3_EVENT_SAS_DISC_RC_STARTED                          (0x01)
> +#define MPI3_EVENT_SAS_DISC_RC_COMPLETED                        (0x02)
> +
> +/**** Defines for the DiscoveryStatus field ****/
> +#define MPI3_SAS_DISC_STATUS_MAX_ENCLOSURES_EXCEED            (0x80000000)
> +#define MPI3_SAS_DISC_STATUS_MAX_EXPANDERS_EXCEED             (0x40000000)
> +#define MPI3_SAS_DISC_STATUS_MAX_DEVICES_EXCEED               (0x20000000)
> +#define MPI3_SAS_DISC_STATUS_MAX_TOPO_PHYS_EXCEED             (0x10000000)
> +#define MPI3_SAS_DISC_STATUS_MULTIPLE_DEVICES_IN_SLOT         (0x00004000)
> +#define MPI3_SAS_DISC_STATUS_SLOT_COUNT_MISMATCH              (0x00002000)
> +#define MPI3_SAS_DISC_STATUS_TOO_MANY_SLOTS                   (0x00001000)
> +#define MPI3_SAS_DISC_STATUS_EXP_MULTI_SUBTRACTIVE            (0x00000800)
> +#define MPI3_SAS_DISC_STATUS_MULTI_PORT_DOMAIN                (0x00000400)
> +#define MPI3_SAS_DISC_STATUS_TABLE_TO_SUBTRACTIVE_LINK        (0x00000200)
> +#define MPI3_SAS_DISC_STATUS_UNSUPPORTED_DEVICE               (0x00000100)
> +#define MPI3_SAS_DISC_STATUS_TABLE_LINK                       (0x00000080)
> +#define MPI3_SAS_DISC_STATUS_SUBTRACTIVE_LINK                 (0x00000040)
> +#define MPI3_SAS_DISC_STATUS_SMP_CRC_ERROR                    (0x00000020)
> +#define MPI3_SAS_DISC_STATUS_SMP_FUNCTION_FAILED              (0x00000010)
> +#define MPI3_SAS_DISC_STATUS_SMP_TIMEOUT                      (0x00000008)
> +#define MPI3_SAS_DISC_STATUS_MULTIPLE_PORTS                   (0x00000004)
> +#define MPI3_SAS_DISC_STATUS_INVALID_SAS_ADDRESS              (0x00000002)
> +#define MPI3_SAS_DISC_STATUS_LOOP_DETECTED                    (0x00000001)
> +
> +
> +/*****************************************************************************
> + *              SAS Broadcast Primitive Event                                *
> + ****************************************************************************/
> +typedef struct _MPI3_EVENT_DATA_SAS_BROADCAST_PRIMITIVE {
> +    U8              PhyNum;         /* 0x00 */
> +    U8              IOUnitPort;     /* 0x01 */
> +    U8              PortWidth;      /* 0x02 */
> +    U8              Primitive;      /* 0x03 */
> +} MPI3_EVENT_DATA_SAS_BROADCAST_PRIMITIVE, MPI3_POINTER PTR_MPI3_EVENT_DATA_SAS_BROADCAST_PRIMITIVE,
> +  Mpi3EventDataSasBroadcastPrimitive_t, MPI3_POINTER pMpi3EventDataSasBroadcastPrimitive_t;
> +
> +/**** Defines for the Primitive field ****/
> +#define MPI3_EVENT_BROADCAST_PRIMITIVE_CHANGE                 (0x01)
> +#define MPI3_EVENT_BROADCAST_PRIMITIVE_SES                    (0x02)
> +#define MPI3_EVENT_BROADCAST_PRIMITIVE_EXPANDER               (0x03)
> +#define MPI3_EVENT_BROADCAST_PRIMITIVE_ASYNCHRONOUS_EVENT     (0x04)
> +#define MPI3_EVENT_BROADCAST_PRIMITIVE_RESERVED3              (0x05)
> +#define MPI3_EVENT_BROADCAST_PRIMITIVE_RESERVED4              (0x06)
> +#define MPI3_EVENT_BROADCAST_PRIMITIVE_CHANGE0_RESERVED       (0x07)
> +#define MPI3_EVENT_BROADCAST_PRIMITIVE_CHANGE1_RESERVED       (0x08)
> +
> +
> +/*****************************************************************************
> + *              SAS Notify Primitive Event                                   *
> + ****************************************************************************/
> +typedef struct _MPI3_EVENT_DATA_SAS_NOTIFY_PRIMITIVE {
> +    U8              PhyNum;         /* 0x00 */
> +    U8              IOUnitPort;     /* 0x01 */
> +    U8              Reserved02;     /* 0x02 */
> +    U8              Primitive;      /* 0x03 */
> +} MPI3_EVENT_DATA_SAS_NOTIFY_PRIMITIVE, MPI3_POINTER PTR_MPI3_EVENT_DATA_SAS_NOTIFY_PRIMITIVE,
> +  Mpi3EventDataSasNotifyPrimitive_t, MPI3_POINTER pMpi3EventDataSasNotifyPrimitive_t;
> +
> +/**** Defines for the Primitive field ****/
> +#define MPI3_EVENT_NOTIFY_PRIMITIVE_ENABLE_SPINUP         (0x01)
> +#define MPI3_EVENT_NOTIFY_PRIMITIVE_POWER_LOSS_EXPECTED   (0x02)
> +#define MPI3_EVENT_NOTIFY_PRIMITIVE_RESERVED1             (0x03)
> +#define MPI3_EVENT_NOTIFY_PRIMITIVE_RESERVED2             (0x04)
> +
> +
> +/*****************************************************************************
> + *              SAS Topology Change List Event                               *
> + ****************************************************************************/
> +#ifndef MPI3_EVENT_SAS_TOPO_PHY_COUNT
> +#define MPI3_EVENT_SAS_TOPO_PHY_COUNT           (1)
> +#endif  /* MPI3_EVENT_SAS_TOPO_PHY_COUNT */
> +
> +typedef struct _MPI3_EVENT_SAS_TOPO_PHY_ENTRY {
> +    U16             AttachedDevHandle;      /* 0x00 */
> +    U8              LinkRate;               /* 0x02 */
> +    U8              Status;                 /* 0x03 */
> +} MPI3_EVENT_SAS_TOPO_PHY_ENTRY, MPI3_POINTER PTR_MPI3_EVENT_SAS_TOPO_PHY_ENTRY,
> +  Mpi3EventSasTopoPhyEntry_t, MPI3_POINTER pMpi3EventSasTopoPhyEntry_t;
> +
> +/**** Defines for the LinkRate field ****/
> +#define MPI3_EVENT_SAS_TOPO_LR_CURRENT_MASK                 (0xF0)
> +#define MPI3_EVENT_SAS_TOPO_LR_CURRENT_SHIFT                (4)
> +#define MPI3_EVENT_SAS_TOPO_LR_PREV_MASK                    (0x0F)
> +#define MPI3_EVENT_SAS_TOPO_LR_PREV_SHIFT                   (0)
> +#define MPI3_EVENT_SAS_TOPO_LR_UNKNOWN_LINK_RATE            (0x00)
> +#define MPI3_EVENT_SAS_TOPO_LR_PHY_DISABLED                 (0x01)
> +#define MPI3_EVENT_SAS_TOPO_LR_NEGOTIATION_FAILED           (0x02)
> +#define MPI3_EVENT_SAS_TOPO_LR_SATA_OOB_COMPLETE            (0x03)
> +#define MPI3_EVENT_SAS_TOPO_LR_PORT_SELECTOR                (0x04)
> +#define MPI3_EVENT_SAS_TOPO_LR_SMP_RESET_IN_PROGRESS        (0x05)
> +#define MPI3_EVENT_SAS_TOPO_LR_UNSUPPORTED_PHY              (0x06)
> +#define MPI3_EVENT_SAS_TOPO_LR_RATE_6_0                     (0x0A)
> +#define MPI3_EVENT_SAS_TOPO_LR_RATE_12_0                    (0x0B)
> +#define MPI3_EVENT_SAS_TOPO_LR_RATE_22_5                    (0x0C)
> +
> +/**** Defines for the PhyStatus field ****/
> +#define MPI3_EVENT_SAS_TOPO_PHY_STATUS_MASK                 (0xC0)
> +#define MPI3_EVENT_SAS_TOPO_PHY_STATUS_SHIFT                (6)
> +#define MPI3_EVENT_SAS_TOPO_PHY_STATUS_ACCESSIBLE           (0x00)
> +#define MPI3_EVENT_SAS_TOPO_PHY_STATUS_NO_EXIST             (0x40)
> +#define MPI3_EVENT_SAS_TOPO_PHY_STATUS_VACANT               (0x80)
> +#define MPI3_EVENT_SAS_TOPO_PHY_RC_MASK                     (0x0F)
> +#define MPI3_EVENT_SAS_TOPO_PHY_RC_TARG_NOT_RESPONDING      (0x02)
> +#define MPI3_EVENT_SAS_TOPO_PHY_RC_PHY_CHANGED              (0x03)
> +#define MPI3_EVENT_SAS_TOPO_PHY_RC_NO_CHANGE                (0x04)
> +#define MPI3_EVENT_SAS_TOPO_PHY_RC_DELAY_NOT_RESPONDING     (0x05)
> +#define MPI3_EVENT_SAS_TOPO_PHY_RC_RESPONDING               (0x06)
> +
> +
> +typedef struct _MPI3_EVENT_DATA_SAS_TOPOLOGY_CHANGE_LIST {
> +    U16                             EnclosureHandle;                            /* 0x00 */
> +    U16                             ExpanderDevHandle;                          /* 0x02 */
> +    U8                              NumPhys;                                    /* 0x04 */
> +    U8                              Reserved05[3];                              /* 0x05 */
> +    U8                              NumEntries;                                 /* 0x08 */
> +    U8                              StartPhyNum;                                /* 0x09 */
> +    U8                              ExpStatus;                                  /* 0x0A */
> +    U8                              IOUnitPort;                                 /* 0x0B */
> +    MPI3_EVENT_SAS_TOPO_PHY_ENTRY   PhyEntry[MPI3_EVENT_SAS_TOPO_PHY_COUNT];    /* 0x0C */
> +} MPI3_EVENT_DATA_SAS_TOPOLOGY_CHANGE_LIST, MPI3_POINTER PTR_MPI3_EVENT_DATA_SAS_TOPOLOGY_CHANGE_LIST,
> +  Mpi3EventDataSasTopologyChangeList_t, MPI3_POINTER pMpi3EventDataSasTopologyChangeList_t;
> +
> +/**** Defines for the ExpStatus field ****/
> +#define MPI3_EVENT_SAS_TOPO_ES_NO_EXPANDER              (0x00)
> +#define MPI3_EVENT_SAS_TOPO_ES_NOT_RESPONDING           (0x02)
> +#define MPI3_EVENT_SAS_TOPO_ES_RESPONDING               (0x03)
> +#define MPI3_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING     (0x04)
> +
> +/*****************************************************************************
> + *              SAS PHY Counter Event                                        *
> + ****************************************************************************/
> +typedef struct _MPI3_EVENT_DATA_SAS_PHY_COUNTER {
> +    U64             TimeStamp;              /* 0x00 */
> +    U32             Reserved08;             /* 0x08 */
> +    U8              PhyEventCode;           /* 0x0C */
> +    U8              PhyNum;                 /* 0x0D */
> +    U16             Reserved0E;             /* 0x0E */
> +    U32             PhyEventInfo;           /* 0x10 */
> +    U8              CounterType;            /* 0x14 */
> +    U8              ThresholdWindow;        /* 0x15 */
> +    U8              TimeUnits;              /* 0x16 */
> +    U8              Reserved17;             /* 0x17 */
> +    U32             EventThreshold;         /* 0x18 */
> +    U16             ThresholdFlags;         /* 0x1C */
> +    U16             Reserved1E;             /* 0x1E */
> +} MPI3_EVENT_DATA_SAS_PHY_COUNTER, MPI3_POINTER PTR_MPI3_EVENT_DATA_SAS_PHY_COUNTER,
> +  Mpi3EventDataSasPhyCounter_t, MPI3_POINTER pMpi3EventDataSasPhyCounter_t;
> +
> +/**** Defines for the PhyEventCode field - use MPI3_SASPHY3_EVENT_CODE_ defines ****/
> +
> +/**** Defines for the CounterType field - use MPI3_SASPHY3_COUNTER_TYPE_ defines ****/
> +
> +/**** Defines for the TimeUnits field - use MPI3_SASPHY3_TIME_UNITS_ defines ****/
> +
> +/**** Defines for the ThresholdFlags field - use MPI3_SASPHY3_TFLAGS_ defines ****/
> +
> +
> +/*****************************************************************************
> + *              SAS Device Discovery Error Event                             *
> + ****************************************************************************/
> +typedef struct _MPI3_EVENT_DATA_SAS_DEVICE_DISC_ERR {
> +    U16             DevHandle;              /* 0x00 */
> +    U8              ReasonCode;             /* 0x02 */
> +    U8              IOUnitPort;             /* 0x03 */
> +    U32             Reserved04;             /* 0x04 */
> +    U64             SASAddress;             /* 0x08 */
> +} MPI3_EVENT_DATA_SAS_DEVICE_DISC_ERR, MPI3_POINTER PTR_MPI3_EVENT_DATA_SAS_DEVICE_DISC_ERR,
> +  Mpi3EventDataSasDeviceDiscErr_t, MPI3_POINTER pMpi3EventDataSasDeviceDiscErr_t;
> +
> +/**** Defines for the ReasonCode field ****/
> +#define MPI3_EVENT_SAS_DISC_ERR_RC_SMP_FAILED          (0x01)
> +#define MPI3_EVENT_SAS_DISC_ERR_RC_SMP_TIMEOUT         (0x02)
> +
> +/*****************************************************************************
> + *              PCIe Enumeration Event                                       *
> + ****************************************************************************/
> +typedef struct _MPI3_EVENT_DATA_PCIE_ENUMERATION {
> +    U8              Flags;                  /* 0x00 */
> +    U8              ReasonCode;             /* 0x01 */
> +    U8              IOUnitPort;             /* 0x02 */
> +    U8              Reserved03;             /* 0x03 */
> +    U32             EnumerationStatus;      /* 0x04 */
> +} MPI3_EVENT_DATA_PCIE_ENUMERATION, MPI3_POINTER PTR_MPI3_EVENT_DATA_PCIE_ENUMERATION,
> +  Mpi3EventDataPcieEnumeration_t, MPI3_POINTER pMpi3EventDataPcieEnumeration_t;
> +
> +/**** Defines for the Flags field ****/
> +#define MPI3_EVENT_PCIE_ENUM_FLAGS_DEVICE_CHANGE            (0x02)
> +#define MPI3_EVENT_PCIE_ENUM_FLAGS_IN_PROGRESS              (0x01)
> +
> +/**** Defines for the ReasonCode field ****/
> +#define MPI3_EVENT_PCIE_ENUM_RC_STARTED                     (0x01)
> +#define MPI3_EVENT_PCIE_ENUM_RC_COMPLETED                   (0x02)
> +
> +/**** Defines for the EnumerationStatus field ****/
> +#define MPI3_EVENT_PCIE_ENUM_ES_MAX_SWITCH_DEPTH_EXCEED     (0x80000000)
> +#define MPI3_EVENT_PCIE_ENUM_ES_MAX_SWITCHES_EXCEED         (0x40000000)
> +#define MPI3_EVENT_PCIE_ENUM_ES_MAX_DEVICES_EXCEED          (0x20000000)
> +#define MPI3_EVENT_PCIE_ENUM_ES_RESOURCES_EXHAUSTED         (0x10000000)
> +
> +
> +/*****************************************************************************
> + *              PCIe Topology Change List Event                              *
> + ****************************************************************************/
> +#ifndef MPI3_EVENT_PCIE_TOPO_PORT_COUNT
> +#define MPI3_EVENT_PCIE_TOPO_PORT_COUNT         (1)
> +#endif  /* MPI3_EVENT_PCIE_TOPO_PORT_COUNT */
> +
> +typedef struct _MPI3_EVENT_PCIE_TOPO_PORT_ENTRY {
> +    U16             AttachedDevHandle;      /* 0x00 */
> +    U8              PortStatus;             /* 0x02 */
> +    U8              Reserved03;             /* 0x03 */
> +    U8              CurrentPortInfo;        /* 0x04 */
> +    U8              Reserved05;             /* 0x05 */
> +    U8              PreviousPortInfo;       /* 0x06 */
> +    U8              Reserved07;             /* 0x07 */
> +} MPI3_EVENT_PCIE_TOPO_PORT_ENTRY, MPI3_POINTER PTR_MPI3_EVENT_PCIE_TOPO_PORT_ENTRY,
> +  Mpi3EventPcieTopoPortEntry_t, MPI3_POINTER pMpi3EventPcieTopoPortEntry_t;
> +
> +/**** Defines for the PortStatus field ****/
> +#define MPI3_EVENT_PCIE_TOPO_PS_NOT_RESPONDING          (0x02)
> +#define MPI3_EVENT_PCIE_TOPO_PS_PORT_CHANGED            (0x03)
> +#define MPI3_EVENT_PCIE_TOPO_PS_NO_CHANGE               (0x04)
> +#define MPI3_EVENT_PCIE_TOPO_PS_DELAY_NOT_RESPONDING    (0x05)
> +#define MPI3_EVENT_PCIE_TOPO_PS_RESPONDING              (0x06)
> +
> +/**** Defines for the CurrentPortInfo and PreviousPortInfo field ****/
> +#define MPI3_EVENT_PCIE_TOPO_PI_LANES_MASK              (0xF0)
> +#define MPI3_EVENT_PCIE_TOPO_PI_LANES_UNKNOWN           (0x00)
> +#define MPI3_EVENT_PCIE_TOPO_PI_LANES_1                 (0x10)
> +#define MPI3_EVENT_PCIE_TOPO_PI_LANES_2                 (0x20)
> +#define MPI3_EVENT_PCIE_TOPO_PI_LANES_4                 (0x30)
> +#define MPI3_EVENT_PCIE_TOPO_PI_LANES_8                 (0x40)
> +#define MPI3_EVENT_PCIE_TOPO_PI_LANES_16                (0x50)
> +
> +#define MPI3_EVENT_PCIE_TOPO_PI_RATE_MASK               (0x0F)
> +#define MPI3_EVENT_PCIE_TOPO_PI_RATE_UNKNOWN            (0x00)
> +#define MPI3_EVENT_PCIE_TOPO_PI_RATE_DISABLED           (0x01)
> +#define MPI3_EVENT_PCIE_TOPO_PI_RATE_2_5                (0x02)
> +#define MPI3_EVENT_PCIE_TOPO_PI_RATE_5_0                (0x03)
> +#define MPI3_EVENT_PCIE_TOPO_PI_RATE_8_0                (0x04)
> +#define MPI3_EVENT_PCIE_TOPO_PI_RATE_16_0               (0x05)
> +#define MPI3_EVENT_PCIE_TOPO_PI_RATE_32_0               (0x06)
> +
> +typedef struct _MPI3_EVENT_DATA_PCIE_TOPOLOGY_CHANGE_LIST {
> +    U16                                 EnclosureHandle;                                /* 0x00 */
> +    U16                                 SwitchDevHandle;                                /* 0x02 */
> +    U8                                  NumPorts;                                       /* 0x04 */
> +    U8                                  Reserved05[3];                                  /* 0x05 */
> +    U8                                  NumEntries;                                     /* 0x08 */
> +    U8                                  StartPortNum;                                   /* 0x09 */
> +    U8                                  SwitchStatus;                                   /* 0x0A */
> +    U8                                  IOUnitPort;                                     /* 0x0B */
> +    U32                                 Reserved0C;                                     /* 0x0C */
> +    MPI3_EVENT_PCIE_TOPO_PORT_ENTRY     PortEntry[MPI3_EVENT_PCIE_TOPO_PORT_COUNT];     /* 0x10 */
> +} MPI3_EVENT_DATA_PCIE_TOPOLOGY_CHANGE_LIST, MPI3_POINTER PTR_MPI3_EVENT_DATA_PCIE_TOPOLOGY_CHANGE_LIST,
> +  Mpi3EventDataPcieTopologyChangeList_t, MPI3_POINTER pMpi3EventDataPcieTopologyChangeList_t;
> +
> +/**** Defines for the SwitchStatus field ****/
> +#define MPI3_EVENT_PCIE_TOPO_SS_NO_PCIE_SWITCH          (0x00)
> +#define MPI3_EVENT_PCIE_TOPO_SS_NOT_RESPONDING          (0x02)
> +#define MPI3_EVENT_PCIE_TOPO_SS_RESPONDING              (0x03)
> +#define MPI3_EVENT_PCIE_TOPO_SS_DELAY_NOT_RESPONDING    (0x04)
> +
> +/****************************************************************************
> + *              Enclosure Device Added Event                                *
> + ****************************************************************************/
> +/*
> + * The Enclosure Device Added Event Data is exactly the same as Enclosure
> + *  Page 0 data (including the Configuration Page header). So, please
> + *  use/refer to MPI3_ENCLOSURE_PAGE0  structure for Enclosure Device Added
> + *  Event data.
> + */
> +
> +/****************************************************************************
> + *              Enclosure Device Changed Event                              *
> + ****************************************************************************/
> +/*
> + * The Enclosure Device Change Event Data is exactly the same as Enclosure
> + *  Page 0 data (including the Configuration Page header). So, please
> + *  use/refer to MPI3_ENCLOSURE_PAGE0  structure for Enclosure Device Change
> + *  Event data.
> + */
> +
> +/*****************************************************************************
> + *              SAS Initiator Device Status Change Event                     *
> + ****************************************************************************/
> +typedef struct _MPI3_EVENT_DATA_SAS_INIT_DEV_STATUS_CHANGE {
> +    U8              ReasonCode;             /* 0x00 */
> +    U8              IOUnitPort;             /* 0x01 */
> +    U16             DevHandle;              /* 0x02 */
> +    U32             Reserved04;             /* 0x04 */
> +    U64             SASAddress;             /* 0x08 */
> +} MPI3_EVENT_DATA_SAS_INIT_DEV_STATUS_CHANGE, MPI3_POINTER PTR_MPI3_EVENT_DATA_SAS_INIT_DEV_STATUS_CHANGE,
> +  Mpi3EventDataSasInitDevStatusChange_t, MPI3_POINTER pMpi3EventDataSasInitDevStatusChange_t;
> +
> +/**** Defines for the ReasonCode field ****/
> +#define MPI3_EVENT_SAS_INIT_RC_ADDED                (0x01)
> +#define MPI3_EVENT_SAS_INIT_RC_NOT_RESPONDING       (0x02)
> +
> +
> +/*****************************************************************************
> + *              SAS Initiator Device Table Overflow Event                    *
> + ****************************************************************************/
> +typedef struct _MPI3_EVENT_DATA_SAS_INIT_TABLE_OVERFLOW {
> +    U16             MaxInit;                /* 0x00 */
> +    U16             CurrentInit;            /* 0x02 */
> +    U32             Reserved04;             /* 0x04 */
> +    U64             SASAddress;             /* 0x08 */
> +} MPI3_EVENT_DATA_SAS_INIT_TABLE_OVERFLOW, MPI3_POINTER PTR_MPI3_EVENT_DATA_SAS_INIT_TABLE_OVERFLOW,
> +  Mpi3EventDataSasInitTableOverflow_t, MPI3_POINTER pMpi3EventDataSasInitTableOverflow_t;
> +
> +
> +/*****************************************************************************
> + *              Hard Reset Received Event                                    *
> + ****************************************************************************/
> +typedef struct _MPI3_EVENT_DATA_HARD_RESET_RECEIVED {
> +    U8              Reserved00;             /* 0x00 */
> +    U8              IOUnitPort;             /* 0x01 */
> +    U16             Reserved02;             /* 0x02 */
> +} MPI3_EVENT_DATA_HARD_RESET_RECEIVED, MPI3_POINTER PTR_MPI3_EVENT_DATA_HARD_RESET_RECEIVED,
> +  Mpi3EventDataHardResetReceived_t, MPI3_POINTER pMpi3EventDataHardResetReceived_t;
> +
> +
> +/*****************************************************************************
> + *              Persistent Event Logs                                       *
> + ****************************************************************************/
> +
> +/**** Definitions for the Locale field ****/
> +#define MPI3_PEL_LOCALE_FLAGS_NON_BLOCKING_BOOT_EVENT   (0x0200)
> +#define MPI3_PEL_LOCALE_FLAGS_BLOCKING_BOOT_EVENT       (0x0100)
> +#define MPI3_PEL_LOCALE_FLAGS_PCIE                      (0x0080)
> +#define MPI3_PEL_LOCALE_FLAGS_CONFIGURATION             (0x0040)
> +#define MPI3_PEL_LOCALE_FLAGS_CONTROLER                 (0x0020)
> +#define MPI3_PEL_LOCALE_FLAGS_SAS                       (0x0010)
> +#define MPI3_PEL_LOCALE_FLAGS_EPACK                     (0x0008)
> +#define MPI3_PEL_LOCALE_FLAGS_ENCLOSURE                 (0x0004)
> +#define MPI3_PEL_LOCALE_FLAGS_PD                        (0x0002)
> +#define MPI3_PEL_LOCALE_FLAGS_VD                        (0x0001)
> +
> +/**** Definitions for the Class field ****/
> +#define MPI3_PEL_CLASS_DEBUG                            (0x00)
> +#define MPI3_PEL_CLASS_PROGRESS                         (0x01)
> +#define MPI3_PEL_CLASS_INFORMATIONAL                    (0x02)
> +#define MPI3_PEL_CLASS_WARNING                          (0x03)
> +#define MPI3_PEL_CLASS_CRITICAL                         (0x04)
> +#define MPI3_PEL_CLASS_FATAL                            (0x05)
> +#define MPI3_PEL_CLASS_FAULT                            (0x06)
> +
> +/**** Definitions for the ClearType field ****/
> +#define MPI3_PEL_CLEARTYPE_CLEAR                        (0x00)
> +
> +/**** Definitions for the WaitTime field ****/
> +#define MPI3_PEL_WAITTIME_INFINITE_WAIT                 (0x00)
> +
> +/**** Definitions for the Action field ****/
> +#define MPI3_PEL_ACTION_GET_SEQNUM                      (0x01)
> +#define MPI3_PEL_ACTION_MARK_CLEAR                      (0x02)
> +#define MPI3_PEL_ACTION_GET_LOG                         (0x03)
> +#define MPI3_PEL_ACTION_GET_COUNT                       (0x04)
> +#define MPI3_PEL_ACTION_WAIT                            (0x05)
> +#define MPI3_PEL_ACTION_ABORT                           (0x06)
> +#define MPI3_PEL_ACTION_GET_PRINT_STRINGS               (0x07)
> +#define MPI3_PEL_ACTION_ACKNOWLEDGE                     (0x08)
> +
> +/**** Definitions for the LogStatus field ****/
> +#define MPI3_PEL_STATUS_SUCCESS                         (0x00)
> +#define MPI3_PEL_STATUS_NOT_FOUND                       (0x01)
> +#define MPI3_PEL_STATUS_ABORTED                         (0x02)
> +#define MPI3_PEL_STATUS_NOT_READY                       (0x03)
> +
> +/****************************************************************************
> + *              PEL Sequence Numbers                                        *
> + ****************************************************************************/
> +typedef struct _MPI3_PEL_SEQ {
> +    U32                             Newest;                                   /* 0x00 */
> +    U32                             Oldest;                                   /* 0x04 */
> +    U32                             Clear;                                    /* 0x08 */
> +    U32                             Shutdown;                                 /* 0x0C */
> +    U32                             Boot;                                     /* 0x10 */
> +    U32                             LastAcknowledged;                         /* 0x14 */
> +} MPI3_PEL_SEQ, MPI3_POINTER PTR_MPI3_PEL_SEQ,
> +  Mpi3PELSeq_t, MPI3_POINTER pMpi3PELSeq_t;
> +
> +/****************************************************************************
> + *              PEL Entry                                                   *
> + ****************************************************************************/
> +
> +typedef struct _MPI3_PEL_ENTRY {
> +    U32                             SequenceNumber;                                     /* 0x00 */
> +    U32                             TimeStamp[2];                                       /* 0x04 */
> +    U16                             LogCode;                                            /* 0x0C */
> +    U16                             ArgType;                                            /* 0x0E */
> +    U16                             Locale;                                             /* 0x10 */
> +    U8                              Class;                                              /* 0x12 */
> +    U8                              Reserved13;                                         /* 0x13 */
> +    U8                              ExtNum;                                             /* 0x14 */
> +    U8                              NumExts;                                            /* 0x15 */
> +    U8                              ArgDataSize;                                        /* 0x16 */
> +    U8                              FixedFormatSize;                                    /* 0x17 */
> +    U32                             Reserved18[2];                                      /* 0x18 */
> +    U32                             PELInfo[24];                                        /* 0x20 - 0x7F */
> +} MPI3_PEL_ENTRY, MPI3_POINTER PTR_MPI3_PEL_ENTRY,
> +  Mpi3PELEntry_t, MPI3_POINTER pMpi3PELEntry_t;
> +
> +/****************************************************************************
> + *              PEL Event List                                              *
> + ****************************************************************************/
> +typedef struct _MPI3_PEL_LIST {
> +    U32                             LogCount;                                 /* 0x00 */
> +    U32                             Reserved04;                               /* 0x04 */
> +    MPI3_PEL_ENTRY                  Entry[1];                                 /* 0x08 */  /* variable length */
> +} MPI3_PEL_LIST, MPI3_POINTER PTR_MPI3_PEL_LIST,
> +  Mpi3PELList_t, MPI3_POINTER pMpi3PELList_t;
> +
> +/****************************************************************************
> + *              PEL Count Data                                              *
> + ****************************************************************************/
> +typedef U32 MPI3_PEL_LOG_COUNT, MPI3_POINTER PTR_MPI3_PEL_LOG_COUNT,
> +	    Mpi3PELLogCount_t, MPI3_POINTER pMpi3PELLogCount_t;
> +
> +/****************************************************************************
> + *              PEL Arg Map                                                 *
> + ****************************************************************************/
> +typedef struct _MPI3_PEL_ARG_MAP {
> +    U8                              ArgType;                                 /* 0x00 */
> +    U8                              Length;                                  /* 0x01 */
> +    U16                             StartLocation;                           /* 0x02 */
> +} MPI3_PEL_ARG_MAP, MPI3_POINTER PTR_MPI3_PEL_ARG_MAP,
> +  Mpi3PELArgMap_t, MPI3_POINTER pMpi3PELArgMap_t;
> +
> +/**** Definitions for the ArgType field ****/
> +#define MPI3_PEL_ARG_MAP_ARG_TYPE_APPEND_STRING                (0x00)
> +#define MPI3_PEL_ARG_MAP_ARG_TYPE_INTEGER                      (0x01)
> +#define MPI3_PEL_ARG_MAP_ARG_TYPE_STRING                       (0x02)
> +#define MPI3_PEL_ARG_MAP_ARG_TYPE_BIT_FIELD                    (0x03)
> +
> +
> +/****************************************************************************
> + *              PEL Print String                                            *
> + ****************************************************************************/
> +typedef struct _MPI3_PEL_PRINT_STRING {
> +    U16                             LogCode;                                  /* 0x00 */
> +    U16                             StringLength;                             /* 0x02 */
> +    U8                              NumArgMap;                                /* 0x04 */
> +    U8                              Reserved05[3];                            /* 0x05 */
> +    MPI3_PEL_ARG_MAP                ArgMap[1];                                /* 0x08 */  /* variable length */
> +} MPI3_PEL_PRINT_STRING, MPI3_POINTER PTR_MPI3_PEL_PRINT_STRING,
> +  Mpi3PELPrintString_t, MPI3_POINTER pMpi3PELPrintString_t;
> +
> +/****************************************************************************
> + *              PEL Print String List                                       *
> + ****************************************************************************/
> +typedef struct _MPI3_PEL_PRINT_STRING_LIST {
> +    U32                             NumPrintStrings;                           /* 0x00 */
> +    U32                             ResidualBytesRemain;                       /* 0x04 */
> +    U32                             Reserved08[2];                             /* 0x08 */
> +    MPI3_PEL_PRINT_STRING           PrintString[1];                            /* 0x10 */  /* variable length */
> +} MPI3_PEL_PRINT_STRING_LIST, MPI3_POINTER PTR_MPI3_PEL_PRINT_STRING_LIST,
> +  Mpi3PELPrintStringList_t, MPI3_POINTER pMpi3PELPrintStringList_t;
> +
> +
> +/****************************************************************************
> + *              PEL Request Msg - generic to allow header decoding          *
> + ****************************************************************************/
> +#ifndef MPI3_PEL_ACTION_SPECIFIC_MAX
> +#define MPI3_PEL_ACTION_SPECIFIC_MAX               (1)
> +#endif  /* MPI3_PEL_ACTION_SPECIFIC_MAX */
> +
> +typedef struct _MPI3_PEL_REQUEST {
> +    U16                             HostTag;                                         /* 0x00 */
> +    U8                              IOCUseOnly02;                                    /* 0x02 */
> +    U8                              Function;                                        /* 0x03 */
> +    U16                             IOCUseOnly04;                                    /* 0x04 */
> +    U8                              IOCUseOnly06;                                    /* 0x06 */
> +    U8                              MsgFlags;                                        /* 0x07 */
> +    U16                             ChangeCount;                                     /* 0x08 */
> +    U8                              Action;                                          /* 0x0A */
> +    U8                              Reserved0B;                                      /* 0x0B */
> +    U32                             ActionSpecific[MPI3_PEL_ACTION_SPECIFIC_MAX];    /* 0x0C */  /* variable length */
> +} MPI3_PEL_REQUEST, MPI3_POINTER PTR_MPI3_PEL_REQUEST,
> +  Mpi3PELRequest_t, MPI3_POINTER pMpi3PELRequest_t;
> +
> +/****************************************************************************
> + *              PEL ACTION Get Sequence Nembers                             *
> + ****************************************************************************/
> +typedef struct _MPI3_PEL_REQ_ACTION_GET_SEQUENCE_NUMBERS {
> +    U16                             HostTag;                                  /* 0x00 */
> +    U8                              IOCUseOnly02;                             /* 0x02 */
> +    U8                              Function;                                 /* 0x03 */
> +    U16                             IOCUseOnly04;                             /* 0x04 */
> +    U8                              IOCUseOnly06;                             /* 0x06 */
> +    U8                              MsgFlags;                                 /* 0x07 */
> +    U16                             ChangeCount;                              /* 0x08 */
> +    U8                              Action;                                   /* 0x0A */
> +    U8                              Reserved0B;                               /* 0x0B */
> +    U32                             Reserved0C[5];                            /* 0x0C */
> +    MPI3_SGE_UNION                  SGL;                                      /* 0x20 */
> +} MPI3_PEL_REQ_ACTION_GET_SEQUENCE_NUMBERS, MPI3_POINTER PTR_MPI3_PEL_REQ_ACTION_GET_SEQUENCE_NUMBERS,
> +  Mpi3PELReqActionGetSequenceNumbers_t, MPI3_POINTER pMpi3PELReqActionGetSequenceNumbers_t;
> +
> +/****************************************************************************
> + *              PEL ACTION Clear Log                                        *
> + ****************************************************************************/
> +typedef struct _MPI3_PEL_REQ_ACTION_CLEAR_LOG_MARKER {
> +    U16                             HostTag;                                  /* 0x00 */
> +    U8                              IOCUseOnly02;                             /* 0x02 */
> +    U8                              Function;                                 /* 0x03 */
> +    U16                             IOCUseOnly04;                             /* 0x04 */
> +    U8                              IOCUseOnly06;                             /* 0x06 */
> +    U8                              MsgFlags;                                 /* 0x07 */
> +    U16                             ChangeCount;                              /* 0x08 */
> +    U8                              Action;                                   /* 0x0A */
> +    U8                              Reserved0B;                               /* 0x0B */
> +    U8                              ClearType;                                /* 0x0C */
> +    U8                              Reserved0D[3];                            /* 0x0D */
> +} MPI3_PEL_REQ_ACTION_CLEAR_LOG_MARKER, MPI3_POINTER PTR_MPI3_PEL_REQ_ACTION_CLEAR_LOG_MARKER,
> +  Mpi3PELReqActionClearLogMMarker_t, MPI3_POINTER pMpi3PELReqActionClearLogMMarker_t;
> +
> +/****************************************************************************
> + *              PEL ACTION Get Log                                          *
> + ****************************************************************************/
> +typedef struct _MPI3_PEL_REQ_ACTION_GET_LOG {
> +    U16                             HostTag;                                  /* 0x00 */
> +    U8                              IOCUseOnly02;                             /* 0x02 */
> +    U8                              Function;                                 /* 0x03 */
> +    U16                             IOCUseOnly04;                             /* 0x04 */
> +    U8                              IOCUseOnly06;                             /* 0x06 */
> +    U8                              MsgFlags;                                 /* 0x07 */
> +    U16                             ChangeCount;                              /* 0x08 */
> +    U8                              Action;                                   /* 0x0A */
> +    U8                              Reserved0B;                               /* 0x0B */
> +    U32                             StartingSequenceNumber;                   /* 0x0C */
> +    U16                             Locale;                                   /* 0x10 */
> +    U8                              Class;                                    /* 0x12 */
> +    U8                              Reserved13;                               /* 0x13 */
> +    U32                             Reserved14[3];                            /* 0x14 */
> +    MPI3_SGE_UNION                  SGL;                                      /* 0x20 */
> +} MPI3_PEL_REQ_ACTION_GET_LOG, MPI3_POINTER PTR_MPI3_PEL_REQ_ACTION_GET_LOG,
> +  Mpi3PELReqActionGetLog_t, MPI3_POINTER pMpi3PELReqActionGetLog_t;
> +
> +/****************************************************************************
> + *              PEL ACTION Get Count                                        *
> + ****************************************************************************/
> +typedef struct _MPI3_PEL_REQ_ACTION_GET_COUNT {
> +    U16                             HostTag;                                  /* 0x00 */
> +    U8                              IOCUseOnly02;                             /* 0x02 */
> +    U8                              Function;                                 /* 0x03 */
> +    U16                             IOCUseOnly04;                             /* 0x04 */
> +    U8                              IOCUseOnly06;                             /* 0x06 */
> +    U8                              MsgFlags;                                 /* 0x07 */
> +    U16                             ChangeCount;                              /* 0x08 */
> +    U8                              Action;                                   /* 0x0A */
> +    U8                              Reserved0B;                               /* 0x0B */
> +    U32                             StartingSequenceNumber;                   /* 0x0C */
> +    U16                             Locale;                                   /* 0x10 */
> +    U8                              Class;                                    /* 0x12 */
> +    U8                              Reserved13;                               /* 0x13 */
> +    U32                             Reserved14[3];                            /* 0x14 */
> +    MPI3_SGE_UNION                  SGL;                                      /* 0x20 */
> +} MPI3_PEL_REQ_ACTION_GET_COUNT, MPI3_POINTER PTR_MPI3_PEL_REQ_ACTION_GET_COUNT,
> +  Mpi3PELReqActionGetCount_t, MPI3_POINTER pMpi3PELReqActionGetCount_t;
> +
> +/****************************************************************************
> + *              PEL ACTION Wait                                             *
> + ****************************************************************************/
> +typedef struct _MPI3_PEL_REQ_ACTION_WAIT {
> +    U16                             HostTag;                                  /* 0x00 */
> +    U8                              IOCUseOnly02;                             /* 0x02 */
> +    U8                              Function;                                 /* 0x03 */
> +    U16                             IOCUseOnly04;                             /* 0x04 */
> +    U8                              IOCUseOnly06;                             /* 0x06 */
> +    U8                              MsgFlags;                                 /* 0x07 */
> +    U16                             ChangeCount;                              /* 0x08 */
> +    U8                              Action;                                   /* 0x0A */
> +    U8                              Reserved0B;                               /* 0x0B */
> +    U32                             StartingSequenceNumber;                   /* 0x0C */
> +    U16                             Locale;                                   /* 0x10 */
> +    U8                              Class;                                    /* 0x12 */
> +    U8                              Reserved13;                               /* 0x13 */
> +    U16                             WaitTime;                                 /* 0x14 */
> +    U16                             Reserved16;                               /* 0x16 */
> +    U32                             Reserved18[2];                            /* 0x18 */
> +} MPI3_PEL_REQ_ACTION_WAIT, MPI3_POINTER PTR_MPI3_PEL_REQ_ACTION_WAIT,
> +  Mpi3PELReqActionWait_t, MPI3_POINTER pMpi3PELReqActionWait_t;
> +
> +/****************************************************************************
> + *              PEL ACTION Abort                                            *
> + ****************************************************************************/
> +typedef struct _MPI3_PEL_REQ_ACTION_ABORT {
> +    U16                             HostTag;                                  /* 0x00 */
> +    U8                              IOCUseOnly02;                             /* 0x02 */
> +    U8                              Function;                                 /* 0x03 */
> +    U16                             IOCUseOnly04;                             /* 0x04 */
> +    U8                              IOCUseOnly06;                             /* 0x06 */
> +    U8                              MsgFlags;                                 /* 0x07 */
> +    U16                             ChangeCount;                              /* 0x08 */
> +    U8                              Action;                                   /* 0x0A */
> +    U8                              Reserved0B;                               /* 0x0B */
> +    U32                             Reserved0C;                               /* 0x0C */
> +    U16                             AbortHostTag;                             /* 0x10 */
> +    U16                             Reserved12;                               /* 0x12 */
> +    U32                             Reserved14;                               /* 0x14 */
> +} MPI3_PEL_REQ_ACTION_ABORT, MPI3_POINTER PTR_MPI3_PEL_REQ_ACTION_ABORT,
> +  Mpi3PELReqActionAbort_t, MPI3_POINTER pMpi3PELReqActionAbort_t;
> +
> +/****************************************************************************
> + *              PEL ACTION Get Print Strings                                *
> + ****************************************************************************/
> +typedef struct _MPI3_PEL_REQ_ACTION_GET_PRINT_STRINGS {
> +    U16                             HostTag;                                  /* 0x00 */
> +    U8                              IOCUseOnly02;                             /* 0x02 */
> +    U8                              Function;                                 /* 0x03 */
> +    U16                             IOCUseOnly04;                             /* 0x04 */
> +    U8                              IOCUseOnly06;                             /* 0x06 */
> +    U8                              MsgFlags;                                 /* 0x07 */
> +    U16                             ChangeCount;                              /* 0x08 */
> +    U8                              Action;                                   /* 0x0A */
> +    U8                              Reserved0B;                               /* 0x0B */
> +    U32                             Reserved0C;                               /* 0x0C */
> +    U16                             StartLogCode;                             /* 0x10 */
> +    U16                             Reserved12;                               /* 0x12 */
> +    U32                             Reserved14[3];                            /* 0x14 */
> +    MPI3_SGE_UNION                  SGL;                                      /* 0x20 */
> +} MPI3_PEL_REQ_ACTION_GET_PRINT_STRINGS, MPI3_POINTER PTR_MPI3_PEL_REQ_ACTION_GET_PRINT_STRINGS,
> +  Mpi3PELReqActionGetPrintStrings_t, MPI3_POINTER pMpi3PELReqActionGetPrintStrings_t;
> +
> +/****************************************************************************
> + *              PEL ACTION Acknowledge                                      *
> + ****************************************************************************/
> +typedef struct _MPI3_PEL_REQ_ACTION_ACKNOWLEDGE {
> +    U16                             HostTag;                                  /* 0x00 */
> +    U8                              IOCUseOnly02;                             /* 0x02 */
> +    U8                              Function;                                 /* 0x03 */
> +    U16                             IOCUseOnly04;                             /* 0x04 */
> +    U8                              IOCUseOnly06;                             /* 0x06 */
> +    U8                              MsgFlags;                                 /* 0x07 */
> +    U16                             ChangeCount;                              /* 0x08 */
> +    U8                              Action;                                   /* 0x0A */
> +    U8                              Reserved0B;                               /* 0x0B */
> +    U32                             SequenceNumber;                           /* 0x0C */
> +    U32                             Reserved10;                               /* 0x10 */
> +} MPI3_PEL_REQ_ACTION_ACKNOWLEDGE, MPI3_POINTER PTR_MPI3_PEL_REQ_ACTION_ACKNOWLEDGE,
> +  Mpi3PELReqActionAcknowledge_t, MPI3_POINTER pMpi3PELReqActionAcknowledge_t;
> +
> +/**** Definitions for the MsgFlags field ****/
> +#define MPI3_PELACKNOWLEDGE_MSGFLAGS_SAFE_MODE_EXIT            (0x01)
> +
> +/****************************************************************************
> + *              PEL Reply                                                   *
> + ****************************************************************************/
> +typedef struct _MPI3_PEL_REPLY {
> +    U16                             HostTag;                                  /* 0x00 */
> +    U8                              IOCUseOnly02;                             /* 0x02 */
> +    U8                              Function;                                 /* 0x03 */
> +    U16                             IOCUseOnly04;                             /* 0x04 */
> +    U8                              IOCUseOnly06;                             /* 0x06 */
> +    U8                              MsgFlags;                                 /* 0x07 */
> +    U16                             IOCUseOnly08;                             /* 0x08 */
> +    U16                             IOCStatus;                                /* 0x0A */
> +    U32                             IOCLogInfo;                               /* 0x0C */
> +    U8                              Action;                                   /* 0x10 */
> +    U8                              Reserved11;                               /* 0x11 */
> +    U16                             Reserved12;                               /* 0x12 */
> +    U16                             PELogStatus;                              /* 0x14 */
> +    U16                             Reserved16;                               /* 0x16 */
> +    U32                             TransferLength;                           /* 0x18 */
> +} MPI3_PEL_REPLY, MPI3_POINTER PTR_MPI3_PEL_REPLY,
> +  Mpi3PELReply_t, MPI3_POINTER pMpi3PELReply_t;
> +
> +
> +/*****************************************************************************
> + *              Component Image Download                                     *
> + ****************************************************************************/
> +typedef struct _MPI3_CI_DOWNLOAD_REQUEST {
> +    U16                             HostTag;                                  /* 0x00 */
> +    U8                              IOCUseOnly02;                             /* 0x02 */
> +    U8                              Function;                                 /* 0x03 */
> +    U16                             IOCUseOnly04;                             /* 0x04 */
> +    U8                              IOCUseOnly06;                             /* 0x06 */
> +    U8                              MsgFlags;                                 /* 0x07 */
> +    U16                             ChangeCount;                              /* 0x08 */
> +    U8                              Action;                                   /* 0x0A */
> +    U8                              Reserved0B;                               /* 0x0B */
> +    U32                             Signature1;                               /* 0x0C */
> +    U32                             TotalImageSize;                           /* 0x10 */
> +    U32                             ImageOffset;                              /* 0x14 */
> +    U32                             SegmentSize;                              /* 0x18 */
> +    U32                             Reserved1C;                               /* 0x1C */
> +    MPI3_SGE_UNION                  SGL;                                      /* 0x20 */
> +} MPI3_CI_DOWNLOAD_REQUEST, MPI3_POINTER PTR_MPI3_CI_DOWNLOAD_REQUEST,
> +  Mpi3CIDownloadRequest_t,   MPI3_POINTER pMpi3CIDownloadRequest_t;
> +
> +/**** Definitions for the MsgFlags field ****/
> +#define MPI3_CI_DOWNLOAD_MSGFLAGS_LAST_SEGMENT                 (0x80)
> +#define MPI3_CI_DOWNLOAD_MSGFLAGS_FORCE_FMC_ENABLE             (0x40)
> +#define MPI3_CI_DOWNLOAD_MSGFLAGS_SIGNED_NVDATA                (0x20)
> +#define MPI3_CI_DOWNLOAD_MSGFLAGS_WRITE_CACHE_FLUSH_MASK       (0x03)
> +#define MPI3_CI_DOWNLOAD_MSGFLAGS_WRITE_CACHE_FLUSH_FAST       (0x00)
> +#define MPI3_CI_DOWNLOAD_MSGFLAGS_WRITE_CACHE_FLUSH_MEDIUM     (0x01)
> +#define MPI3_CI_DOWNLOAD_MSGFLAGS_WRITE_CACHE_FLUSH_SLOW       (0x02)
> +
> +/**** Definitions for the Action field ****/
> +#define MPI3_CI_DOWNLOAD_ACTION_DOWNLOAD                       (0x01)
> +#define MPI3_CI_DOWNLOAD_ACTION_ONLINE_ACTIVATION              (0x02)
> +#define MPI3_CI_DOWNLOAD_ACTION_OFFLINE_ACTIVATION             (0x03)
> +#define MPI3_CI_DOWNLOAD_ACTION_GET_STATUS                     (0x04)
> +
> +typedef struct _MPI3_CI_DOWNLOAD_REPLY {
> +    U16                             HostTag;                                  /* 0x00 */
> +    U8                              IOCUseOnly02;                             /* 0x02 */
> +    U8                              Function;                                 /* 0x03 */
> +    U16                             IOCUseOnly04;                             /* 0x04 */
> +    U8                              IOCUseOnly06;                             /* 0x06 */
> +    U8                              MsgFlags;                                 /* 0x07 */
> +    U16                             IOCUseOnly08;                             /* 0x08 */
> +    U16                             IOCStatus;                                /* 0x0A */
> +    U32                             IOCLogInfo;                               /* 0x0C */
> +    U8                              Flags;                                    /* 0x10 */
> +    U8                              CacheDirty;                               /* 0x11 */
> +    U8                              PendingCount;                             /* 0x12 */
> +    U8                              Reserved13;                               /* 0x13 */
> +} MPI3_CI_DOWNLOAD_REPLY, MPI3_POINTER PTR_MPI3_CI_DOWNLOAD_REPLY,
> +  Mpi3CIDownloadReply_t,  MPI3_POINTER pMpi3CIDownloadReply_t;
> +
> +/**** Definitions for the Flags field ****/
> +#define MPI3_CI_DOWNLOAD_FLAGS_DOWNLOAD_IN_PROGRESS                  (0x80)
> +#define MPI3_CI_DOWNLOAD_FLAGS_KEY_UPDATE_PENDING                    (0x10)
> +#define MPI3_CI_DOWNLOAD_FLAGS_ACTIVATION_STATUS_MASK                (0x0E)
> +#define MPI3_CI_DOWNLOAD_FLAGS_ACTIVATION_STATUS_NOT_NEEDED          (0x00)
> +#define MPI3_CI_DOWNLOAD_FLAGS_ACTIVATION_STATUS_AWAITING            (0x02)
> +#define MPI3_CI_DOWNLOAD_FLAGS_ACTIVATION_STATUS_ONLINE_PENDING      (0x04)
> +#define MPI3_CI_DOWNLOAD_FLAGS_ACTIVATION_STATUS_OFFLINE_PENDING     (0x06)
> +#define MPI3_CI_DOWNLOAD_FLAGS_COMPATIBLE                            (0x01)
> +
> +/*****************************************************************************
> + *              Component Image Upload                                       *
> + ****************************************************************************/
> +typedef struct _MPI3_CI_UPLOAD_REQUEST {
> +    U16                             HostTag;                                  /* 0x00 */
> +    U8                              IOCUseOnly02;                             /* 0x02 */
> +    U8                              Function;                                 /* 0x03 */
> +    U16                             IOCUseOnly04;                             /* 0x04 */
> +    U8                              IOCUseOnly06;                             /* 0x06 */
> +    U8                              MsgFlags;                                 /* 0x07 */
> +    U16                             ChangeCount;                              /* 0x08 */
> +    U16                             Reserved0A;                               /* 0x0A */
> +    U32                             Signature1;                               /* 0x0C */
> +    U32                             Reserved10;                               /* 0x10 */
> +    U32                             ImageOffset;                              /* 0x14 */
> +    U32                             SegmentSize;                              /* 0x18 */
> +    U32                             Reserved1C;                               /* 0x1C */
> +    MPI3_SGE_UNION                  SGL;                                      /* 0x20 */
> +} MPI3_CI_UPLOAD_REQUEST, MPI3_POINTER PTR_MPI3_CI_UPLOAD_REQUEST,
> +  Mpi3CIUploadRequest_t,   MPI3_POINTER pMpi3CIUploadRequest_t;
> +
> +/**** Defines for the MsgFlags field ****/
> +#define MPI3_CI_UPLOAD_MSGFLAGS_LOCATION_MASK                        (0x01)
> +#define MPI3_CI_UPLOAD_MSGFLAGS_LOCATION_PRIMARY                     (0x00)
> +#define MPI3_CI_UPLOAD_MSGFLAGS_LOCATION_SECONDARY                   (0x01)
> +#define MPI3_CI_UPLOAD_MSGFLAGS_FORMAT_MASK                          (0x02)
> +#define MPI3_CI_UPLOAD_MSGFLAGS_FORMAT_FLASH                         (0x00)
> +#define MPI3_CI_UPLOAD_MSGFLAGS_FORMAT_EXECUTABLE                    (0x02)
> +
> +/**** Defines for Signature1 field - use MPI3_IMAGE_HEADER_SIGNATURE1_ defines */
> +
> +/*****************************************************************************
> + *              IO Unit Control                                              *
> + ****************************************************************************/
> +
> +/**** Definitions for the Operation field ****/
> +#define MPI3_CTRL_OP_FORCE_FULL_DISCOVERY                            (0x01)
> +#define MPI3_CTRL_OP_LOOKUP_MAPPING                                  (0x02)
> +#define MPI3_CTRL_OP_UPDATE_TIMESTAMP                                (0x04)
> +#define MPI3_CTRL_OP_GET_TIMESTAMP                                   (0x05)
> +#define MPI3_CTRL_OP_REMOVE_DEVICE                                   (0x10)
> +#define MPI3_CTRL_OP_CLOSE_PERSISTENT_CONNECTION                     (0x11)
> +#define MPI3_CTRL_OP_HIDDEN_ACK                                      (0x12)
> +#define MPI3_CTRL_OP_SAS_SEND_PRIMITIVE                              (0x20)
> +#define MPI3_CTRL_OP_SAS_CLEAR_ERROR_LOG                             (0x21)
> +#define MPI3_CTRL_OP_PCIE_CLEAR_ERROR_LOG                            (0x22)
> +
> +/**** Depending on the Operation selected, the various ParamX fields         *****/
> +/****  contain defined data values. These indexes help identify those values *****/
> +#define MPI3_CTRL_OP_LOOKUP_MAPPING_PARAM8_LOOKUP_METHOD_INDEX       (0x00)
> +#define MPI3_CTRL_OP_UPDATE_TIMESTAMP_PARAM64_TIMESTAMP_INDEX        (0x00)
> +#define MPI3_CTRL_OP_REMOVE_DEVICE_PARAM16_DEVHANDLE_INDEX           (0x00)
> +#define MPI3_CTRL_OP_CLOSE_PERSIST_CONN_PARAM16_DEVHANDLE_INDEX      (0x00)
> +#define MPI3_CTRL_OP_HIDDEN_ACK_PARAM16_DEVHANDLE_INDEX              (0x00)
> +#define MPI3_CTRL_OP_SAS_SEND_PRIM_PARAM8_PHY_INDEX                  (0x00)
> +#define MPI3_CTRL_OP_SAS_SEND_PRIM_PARAM8_PRIMSEQ_INDEX              (0x01)
> +#define MPI3_CTRL_OP_SAS_SEND_PRIM_PARAM32_PRIMITIVE_INDEX           (0x00)
> +#define MPI3_CTRL_OP_SAS_CLEAR_ERR_LOG_PARAM8_PHY_INDEX              (0x00)
> +#define MPI3_CTRL_OP_PCIE_CLEAR_ERR_LOG_PARAM8_PHY_INDEX             (0x00)
> +
> +/**** Definitions for the LookupMethod field ****/
> +#define MPI3_CTRL_LOOKUP_METHOD_WWID_ADDRESS                         (0x01)
> +#define MPI3_CTRL_LOOKUP_METHOD_ENCLOSURE_SLOT                       (0x02)
> +#define MPI3_CTRL_LOOKUP_METHOD_SAS_DEVICE_NAME                      (0x03)
> +#define MPI3_CTRL_LOOKUP_METHOD_PERSISTENT_ID                        (0x04)
> +
> +/**** Definitions for IoUnitControl Lookup Mapping Method Parameters ****/
> +#define MPI3_CTRL_LOOKUP_METHOD_WWIDADDR_PARAM16_DEVH_INDEX             (0)
> +#define MPI3_CTRL_LOOKUP_METHOD_WWIDADDR_PARAM64_WWID_INDEX             (0)
> +#define MPI3_CTRL_LOOKUP_METHOD_ENCLSLOT_PARAM16_SLOTNUM_INDEX          (0)
> +#define MPI3_CTRL_LOOKUP_METHOD_ENCLSLOT_PARAM64_ENCLOSURELID_INDEX     (0)
> +#define MPI3_CTRL_LOOKUP_METHOD_SASDEVNAME_PARAM16_DEVH_INDEX           (0)
> +#define MPI3_CTRL_LOOKUP_METHOD_SASDEVNAME_PARAM64_DEVNAME_INDEX        (0)
> +#define MPI3_CTRL_LOOKUP_METHOD_PERSISTID_PARAM16_DEVH_INDEX            (0)
> +#define MPI3_CTRL_LOOKUP_METHOD_PERSISTID_PARAM16_PERSISTENT_ID_INDEX   (1)
> +
> +/*** Definitions for IoUnitControl Reply fields ****/
> +#define MPI3_CTRL_LOOKUP_METHOD_VALUE16_DEVH_INDEX                      (0)
> +#define MPI3_CTRL_GET_TIMESTAMP_VALUE64_TIMESTAMP_INDEX                 (0)
> +
> +
> +/**** Definitions for the PrimSeq field ****/
> +#define MPI3_CTRL_PRIMFLAGS_SINGLE                                   (0x01)
> +#define MPI3_CTRL_PRIMFLAGS_TRIPLE                                   (0x03)
> +#define MPI3_CTRL_PRIMFLAGS_REDUNDANT                                (0x06)
> +
> +typedef struct _MPI3_IOUNIT_CONTROL_REQUEST {
> +    U16                             HostTag;                                  /* 0x00 */
> +    U8                              IOCUseOnly02;                             /* 0x02 */
> +    U8                              Function;                                 /* 0x03 */
> +    U16                             IOCUseOnly04;                             /* 0x04 */
> +    U8                              IOCUseOnly06;                             /* 0x06 */
> +    U8                              MsgFlags;                                 /* 0x07 */
> +    U16                             ChangeCount;                              /* 0x08 */
> +    U8                              Reserved0A;                               /* 0x0A */
> +    U8                              Operation;                                /* 0x0B */
> +    U32                             Reserved0C;                               /* 0x0C */
> +    U64                             Param64[2];                               /* 0x10 */
> +    U32                             Param32[4];                               /* 0x20 */
> +    U16                             Param16[4];                               /* 0x30 */
> +    U8                              Param8[8];                                /* 0x38 */
> +} MPI3_IOUNIT_CONTROL_REQUEST, MPI3_POINTER PTR_MPI3_IOUNIT_CONTROL_REQUEST,
> +  Mpi3IoUnitControlRequest_t, MPI3_POINTER pMpi3IoUnitControlRequest_t;
> +
> +
> +typedef struct _MPI3_IOUNIT_CONTROL_REPLY {
> +    U16                             HostTag;                                  /* 0x00 */
> +    U8                              IOCUseOnly02;                             /* 0x02 */
> +    U8                              Function;                                 /* 0x03 */
> +    U16                             IOCUseOnly04;                             /* 0x04 */
> +    U8                              IOCUseOnly06;                             /* 0x06 */
> +    U8                              MsgFlags;                                 /* 0x07 */
> +    U16                             IOCUseOnly08;                             /* 0x08 */
> +    U16                             IOCStatus;                                /* 0x0A */
> +    U32                             IOCLogInfo;                               /* 0x0C */
> +    U64                             Value64[2];                               /* 0x10 */
> +    U32                             Value32[4];                               /* 0x20 */
> +    U16                             Value16[4];                               /* 0x30 */
> +    U8                              Value8[8];                                /* 0x38 */
> +} MPI3_IOUNIT_CONTROL_REPLY, MPI3_POINTER PTR_MPI3_IOUNIT_CONTROL_REPLY,
> +  Mpi3IoUnitControlReply_t, MPI3_POINTER pMpi3IoUnitControlReply_t;
> +
> +#endif  /* MPI30_IOC_H */
> diff --git a/drivers/scsi/mpi3mr/mpi/mpi30_transport.h b/drivers/scsi/mpi3mr/mpi/mpi30_transport.h
> new file mode 100644
> index 000000000000..54f821d25209
> --- /dev/null
> +++ b/drivers/scsi/mpi3mr/mpi/mpi30_transport.h
> @@ -0,0 +1,675 @@
> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> +/*
> + *  Copyright 2016-2020 Broadcom Inc. All rights reserved.
> + *
> + *           Name: mpi30_transport.h
> + *    Description: Contains definitions for System Interface Register Set, Scatter Gather Lists etc
> + *  Creation Date: 08/31/2016
> + *        Version: 03.00.00
> + *
> + *  mpi3.h Version:  03.00.00.18
> + *
> + *
> + *  Version History
> + *  ---------------
> + *
> + *  Date      Version       Description
> + *  --------  -----------  ------------------------------------------------------
> + *  11-30-18  03.00.00.08  Corresponds to Fusion-MPT MPI 3.0 Specification Rev H.
> + *  02-08-19  03.00.00.09  Corresponds to Fusion-MPT MPI 3.0 Specification Rev I.
> + *  05-03-19  03.00.00.10  Corresponds to Fusion-MPT MPI 3.0 Specification Rev J.
> + *  08-30-19  03.00.00.12  Corresponds to Fusion-MPT MPI 3.0 Specification Rev L.
> + *  11-01-19  03.00.00.13  Corresponds to Fusion-MPT MPI 3.0 Specification Rev M.
> + *  12-16-19  03.00.00.14  Corresponds to Fusion-MPT MPI 3.0 Specification Rev N.
> + *  02-28-20  03.00.00.15  Corresponds to Fusion-MPT MPI 3.0 Specification Rev O.
> + *  05-01-20  03.00.00.16  Corresponds to Fusion-MPT MPI 3.0 Specification Rev P.
> + *  06-26-20  03.00.00.17  Corresponds to Fusion-MPT MPI 3.0 Specification Rev Q.
> + *  08-28-20  03.00.00.18  Corresponds to Fusion-MPT MPI 3.0 Specification Rev R.
> + */
> +#ifndef MPI30_TRANSPORT_H
> +#define MPI30_TRANSPORT_H     1
> +
> +/*****************************************************************************
> + *              Common version structure/union used in                       *
> + *              messages and configuration pages                             *
> + ****************************************************************************/
> +
> +typedef struct _MPI3_VERSION_STRUCT {
> +    U8      Dev;                                                        /* 0x00 */
> +    U8      Unit;                                                       /* 0x01 */
> +    U8      Minor;                                                      /* 0x02 */
> +    U8      Major;                                                      /* 0x03 */
> +} MPI3_VERSION_STRUCT, MPI3_POINTER PTR_MPI3_VERSION_STRUCT,
> +  Mpi3VersionStruct, MPI3_POINTER pMpi3VersionStruct;
> +
> +typedef union _MPI3_VERSION_UNION {
> +    MPI3_VERSION_STRUCT     Struct;
> +    U32                     Word;
> +} MPI3_VERSION_UNION, MPI3_POINTER PTR_MPI3_VERSION_UNION,
> +  Mpi3VersionUnion, MPI3_POINTER pMpi3VersionUnion;
> +
> +/****** Version constants for this revision ****/
> +#define MPI3_VERSION_MAJOR                                              (3)
> +#define MPI3_VERSION_MINOR                                              (0)
> +#define MPI3_VERSION_UNIT                                               (0)
> +#define MPI3_VERSION_DEV                                                (18)
> +
> +
> +/*****************************************************************************
> + *              System Interface Register Definitions                        *
> + ****************************************************************************/
> +typedef struct _MPI3_SYSIF_OPER_QUEUE_INDEXES {
> +    U16         ProducerIndex;                                          /* 0x00 */
> +    U16         Reserved02;                                             /* 0x02 */
> +    U16         ConsumerIndex;                                          /* 0x04 */
> +    U16         Reserved06;                                             /* 0x06 */
> +} MPI3_SYSIF_OPER_QUEUE_INDEXES, MPI3_POINTER PTR_MPI3_SYSIF_OPER_QUEUE_INDEXES;
> +
> +typedef volatile struct _MPI3_SYSIF_REGISTERS
> +{
> +    U64                             IOCInformation;                     /* 0x00   */
> +    MPI3_VERSION_UNION              Version;                            /* 0x08   */
> +    U32                             Reserved0C[2];                      /* 0x0C   */
> +    U32                             IOCConfiguration;                   /* 0x14   */
> +    U32                             Reserved18;                         /* 0x18   */
> +    U32                             IOCStatus;                          /* 0x1C   */
> +    U32                             Reserved20;                         /* 0x20   */
> +    U32                             AdminQueueNumEntries;               /* 0x24   */
> +    U64                             AdminRequestQueueAddress;           /* 0x28   */
> +    U64                             AdminReplyQueueAddress;             /* 0x30   */
> +    U32                             Reserved38[2];                      /* 0x38   */
> +    U32                             CoalesceControl;                    /* 0x40   */
> +    U32                             Reserved44[1007];                   /* 0x44   */
> +    U16                             AdminRequestQueuePI;                /* 0x1000 */
> +    U16                             Reserved1002;                       /* 0x1002 */
> +    U16                             AdminReplyQueueCI;                  /* 0x1004 */
> +    U16                             Reserved1006;                       /* 0x1006 */
> +    MPI3_SYSIF_OPER_QUEUE_INDEXES   OperQueueIndexes[383];              /* 0x1008 */
> +    U32                             Reserved1C00;                       /* 0x1C00 */
> +    U32                             WriteSequence;                      /* 0x1C04 */
> +    U32                             HostDiagnostic;                     /* 0x1C08 */
> +    U32                             Reserved1C0C;                       /* 0x1C0C */
> +    U32                             Fault;                              /* 0x1C10 */
> +    U32                             FaultInfo[3];                       /* 0x1C14 */
> +    U32                             Reserved1C20[4];                    /* 0x1C20 */
> +    U64                             HCBAddress;                         /* 0x1C30 */
> +    U32                             HCBSize;                            /* 0x1C38 */
> +    U32                             Reserved1C3C;                       /* 0x1C3C */
> +    U32                             ReplyFreeHostIndex;                 /* 0x1C40 */
> +    U32                             SenseBufferFreeHostIndex;           /* 0x1C44 */
> +    U32                             Reserved1C48[2];                    /* 0x1C48 */
> +    U64                             DiagRWData;                         /* 0x1C50 */
> +    U64                             DiagRWAddress;                      /* 0x1C58 */
> +    U16                             DiagRWControl;                      /* 0x1C60 */
> +    U16                             DiagRWStatus;                       /* 0x1C62 */
> +    U32                             Reserved1C64[35];                   /* 0x1C64 */
> +    U32                             Scratchpad[4];                      /* 0x1CF0 */
> +    U32                             Reserved1D00[192];                  /* 0x1D00 */
> +    U32                             DeviceAssignedRegisters[2048];      /* 0x2000 */
> +} MPI3_SYSIF_REGS, MPI3_POINTER PTR_MPI3_SYSIF_REGS,
> +  Mpi3SysIfRegs_t, MPI3_POINTER pMpi3SysIfRegs_t;
> +
> +/**** Defines for the IOCInformation register ****/
> +#define MPI3_SYSIF_IOC_INFO_LOW_OFFSET                                  (0x00000000)
> +#define MPI3_SYSIF_IOC_INFO_HIGH_OFFSET                                 (0x00000004)
> +#define MPI3_SYSIF_IOC_INFO_LOW_TIMEOUT_MASK                            (0xFF000000)
> +#define MPI3_SYSIF_IOC_INFO_LOW_TIMEOUT_SHIFT                           (24)
> +
> +/**** Defines for the IOCConfiguration register ****/
> +#define MPI3_SYSIF_IOC_CONFIG_OFFSET                                    (0x00000014)
> +#define MPI3_SYSIF_IOC_CONFIG_OPER_RPY_ENT_SZ                           (0x00F00000)
> +#define MPI3_SYSIF_IOC_CONFIG_OPER_RPY_ENT_SZ_SHIFT                     (20)
> +#define MPI3_SYSIF_IOC_CONFIG_OPER_REQ_ENT_SZ                           (0x000F0000)
> +#define MPI3_SYSIF_IOC_CONFIG_OPER_REQ_ENT_SZ_SHIFT                     (16)
> +#define MPI3_SYSIF_IOC_CONFIG_SHUTDOWN_MASK                             (0x0000C000)
> +#define MPI3_SYSIF_IOC_CONFIG_SHUTDOWN_NO                               (0x00000000)
> +#define MPI3_SYSIF_IOC_CONFIG_SHUTDOWN_NORMAL                           (0x00004000)
> +#define MPI3_SYSIF_IOC_CONFIG_DEVICE_SHUTDOWN                           (0x00002000)
> +#define MPI3_SYSIF_IOC_CONFIG_DIAG_SAVE                                 (0x00000010)
> +#define MPI3_SYSIF_IOC_CONFIG_ENABLE_IOC                                (0x00000001)
> +
> +/**** Defines for the IOCStatus register ****/
> +#define MPI3_SYSIF_IOC_STATUS_OFFSET                                    (0x0000001C)
> +#define MPI3_SYSIF_IOC_STATUS_RESET_HISTORY                             (0x00000010)
> +#define MPI3_SYSIF_IOC_STATUS_SHUTDOWN_MASK                             (0x0000000C)
> +#define MPI3_SYSIF_IOC_STATUS_SHUTDOWN_NONE                             (0x00000000)
> +#define MPI3_SYSIF_IOC_STATUS_SHUTDOWN_IN_PROGRESS                      (0x00000004)
> +#define MPI3_SYSIF_IOC_STATUS_SHUTDOWN_COMPLETE                         (0x00000008)
> +#define MPI3_SYSIF_IOC_STATUS_FAULT                                     (0x00000002)
> +#define MPI3_SYSIF_IOC_STATUS_READY                                     (0x00000001)
> +
> +/**** Defines for the AdminQueueNumEntries register ****/
> +#define MPI3_SYSIF_ADMIN_Q_NUM_ENTRIES_OFFSET                           (0x00000024)
> +#define MPI3_SYSIF_ADMIN_Q_NUM_ENTRIES_REQ_MASK                         (0x0FFF)
> +#define MPI3_SYSIF_ADMIN_Q_NUM_ENTRIES_REPLY_OFFSET                     (0x00000026)
> +#define MPI3_SYSIF_ADMIN_Q_NUM_ENTRIES_REPLY_MASK                       (0x0FFF0000)
> +#define MPI3_SYSIF_ADMIN_Q_NUM_ENTRIES_REPLY_SHIFT                      (16)
> +
> +/**** Defines for the AdminRequestQueueAddress register ****/
> +#define MPI3_SYSIF_ADMIN_REQ_Q_ADDR_LOW_OFFSET                          (0x00000028)
> +#define MPI3_SYSIF_ADMIN_REQ_Q_ADDR_HIGH_OFFSET                         (0x0000002C)
> +
> +/**** Defines for the AdminReplyQueueAddress register ****/
> +#define MPI3_SYSIF_ADMIN_REPLY_Q_ADDR_LOW_OFFSET                        (0x00000030)
> +#define MPI3_SYSIF_ADMIN_REPLY_Q_ADDR_HIGH_OFFSET                       (0x00000034)
> +
> +/**** Defines for the CoalesceControl register ****/
> +#define MPI3_SYSIF_COALESCE_CONTROL_OFFSET                              (0x00000040)
> +#define MPI3_SYSIF_COALESCE_CONTROL_ENABLE_MASK                         (0xC0000000)
> +#define MPI3_SYSIF_COALESCE_CONTROL_ENABLE_NO_CHANGE                    (0x00000000)
> +#define MPI3_SYSIF_COALESCE_CONTROL_ENABLE_DISABLE                      (0x40000000)
> +#define MPI3_SYSIF_COALESCE_CONTROL_ENABLE_ENABLE                       (0xC0000000)
> +#define MPI3_SYSIF_COALESCE_CONTROL_VALID                               (0x30000000)
> +#define MPI3_SYSIF_COALESCE_CONTROL_QUEUE_ID_MASK                       (0x00FF0000)
> +#define MPI3_SYSIF_COALESCE_CONTROL_QUEUE_ID_SHIFT                      (16)
> +#define MPI3_SYSIF_COALESCE_CONTROL_TIMEOUT_MASK                        (0x0000FF00)
> +#define MPI3_SYSIF_COALESCE_CONTROL_TIMEOUT_SHIFT                       (8)
> +#define MPI3_SYSIF_COALESCE_CONTROL_DEPTH_MASK                          (0x000000FF)
> +#define MPI3_SYSIF_COALESCE_CONTROL_DEPTH_SHIFT                         (0)
> +
> +/**** Defines for the AdminRequestQueuePI register ****/
> +#define MPI3_SYSIF_ADMIN_REQ_Q_PI_OFFSET                                (0x00001000)
> +
> +/**** Defines for the AdminReplyQueueCI register ****/
> +#define MPI3_SYSIF_ADMIN_REPLY_Q_CI_OFFSET                              (0x00001004)
> +
> +/**** Defines for the OperationalRequestQueuePI register */
> +#define MPI3_SYSIF_OPER_REQ_Q_PI_OFFSET                                 (0x00001008)
> +#define MPI3_SYSIF_OPER_REQ_Q_N_PI_OFFSET(N)                            (MPI3_SYSIF_OPER_REQ_Q_PI_OFFSET + (((N)-1)*8)) /* N = 1, 2, 3, ..., 255 */
> +
> +/**** Defines for the OperationalReplyQueueCI register */
> +#define MPI3_SYSIF_OPER_REPLY_Q_CI_OFFSET                               (0x0000100C)
> +#define MPI3_SYSIF_OPER_REPLY_Q_N_CI_OFFSET(N)                          (MPI3_SYSIF_OPER_REPLY_Q_CI_OFFSET + (((N)-1)*8)) /* N = 1, 2, 3, ..., 255 */
> +
> +/**** Defines for the WriteSequence register *****/
> +#define MPI3_SYSIF_WRITE_SEQUENCE_OFFSET                                (0x00001C04)
> +#define MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_MASK                        (0x0000000F)
> +#define MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_FLUSH                       (0x0)
> +#define MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_1ST                         (0xF)
> +#define MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_2ND                         (0x4)
> +#define MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_3RD                         (0xB)
> +#define MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_4TH                         (0x2)
> +#define MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_5TH                         (0x7)
> +#define MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_6TH                         (0xD)
> +
> +/**** Defines for the HostDiagnostic register *****/
> +#define MPI3_SYSIF_HOST_DIAG_OFFSET                                     (0x00001C08)
> +#define MPI3_SYSIF_HOST_DIAG_RESET_ACTION_MASK                          (0x00000700)
> +#define MPI3_SYSIF_HOST_DIAG_RESET_ACTION_NO_RESET                      (0x00000000)
> +#define MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET                    (0x00000100)
> +#define MPI3_SYSIF_HOST_DIAG_RESET_ACTION_FLASH_RCVRY_RESET             (0x00000200)
> +#define MPI3_SYSIF_HOST_DIAG_RESET_ACTION_COMPLETE_RESET                (0x00000300)
> +#define MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT                    (0x00000700)
> +#define MPI3_SYSIF_HOST_DIAG_SAVE_IN_PROGRESS                           (0x00000080)
> +#define MPI3_SYSIF_HOST_DIAG_SECURE_BOOT                                (0x00000040)
> +#define MPI3_SYSIF_HOST_DIAG_CLEAR_INVALID_FW_IMAGE                     (0x00000020)
> +#define MPI3_SYSIF_HOST_DIAG_INVALID_FW_IMAGE                           (0x00000010)
> +#define MPI3_SYSIF_HOST_DIAG_HCBENABLE                                  (0x00000008)
> +#define MPI3_SYSIF_HOST_DIAG_HCBMODE                                    (0x00000004)
> +#define MPI3_SYSIF_HOST_DIAG_DIAG_RW_ENABLE                             (0x00000002)
> +#define MPI3_SYSIF_HOST_DIAG_DIAG_WRITE_ENABLE                          (0x00000001)
> +
> +/**** Defines for the Fault register ****/
> +#define MPI3_SYSIF_FAULT_OFFSET                                         (0x00001C10)
> +#define MPI3_SYSIF_FAULT_FUNC_AREA_MASK                                 (0xFF000000)
> +#define MPI3_SYSIF_FAULT_FUNC_AREA_SHIFT                                (24)
> +#define MPI3_SYSIF_FAULT_FUNC_AREA_MPI_DEFINED                          (0x00000000)
> +#define MPI3_SYSIF_FAULT_CODE_MASK                                      (0x0000FFFF)
> +#define MPI3_SYSIF_FAULT_CODE_DIAG_FAULT_RESET                          (0x0000F000)
> +#define MPI3_SYSIF_FAULT_CODE_CI_ACTIVATION_RESET                       (0x0000F001)
> +#define MPI3_SYSIF_FAULT_CODE_SOFT_RESET_IN_PROGRESS                    (0x0000F002)
> +#define MPI3_SYSIF_FAULT_CODE_COMPLETE_RESET_NEEDED                     (0x0000F003)
> +#define MPI3_SYSIF_FAULT_CODE_SAFE_MODE_EXIT                            (0x0000F004)
> +#define MPI3_SYSIF_FAULT_CODE_FACTORY_RESET                             (0x0000F005)
> +
> +/**** Defines for FaultCodeAdditionalInfo registers ****/
> +#define MPI3_SYSIF_FAULT_INFO0_OFFSET                                   (0x00001C14)
> +#define MPI3_SYSIF_FAULT_INFO1_OFFSET                                   (0x00001C18)
> +#define MPI3_SYSIF_FAULT_INFO2_OFFSET                                   (0x00001C1C)
> +
> +/**** Defines for HCBAddress register ****/
> +#define MPI3_SYSIF_HCB_ADDRESS_LOW_OFFSET                               (0x00001C30)
> +#define MPI3_SYSIF_HCB_ADDRESS_HIGH_OFFSET                              (0x00001C34)
> +
> +/**** Defines for HCBSize register ****/
> +#define MPI3_SYSIF_HCB_SIZE_OFFSET                                      (0x00001C38)
> +#define MPI3_SYSIF_HCB_SIZE_SIZE_MASK                                   (0xFFFFF000)
> +#define MPI3_SYSIF_HCB_SIZE_SIZE_SHIFT                                  (12)
> +#define MPI3_SYSIF_HCB_SIZE_HCDW_ENABLE                                 (0x00000001)
> +
> +/**** Defines for ReplyFreeHostIndex register ****/
> +#define MPI3_SYSIF_REPLY_FREE_HOST_INDEX_OFFSET                         (0x00001C40)
> +
> +/**** Defines for SenseBufferFreeHostIndex register ****/
> +#define MPI3_SYSIF_SENSE_BUF_FREE_HOST_INDEX_OFFSET                     (0x00001C44)
> +
> +/**** Defines for DiagRWData register ****/
> +#define MPI3_SYSIF_DIAG_RW_DATA_LOW_OFFSET                              (0x00001C50)
> +#define MPI3_SYSIF_DIAG_RW_DATA_HIGH_OFFSET                             (0x00001C54)
> +
> +/**** Defines for DiagRWAddress ****/
> +#define MPI3_SYSIF_DIAG_RW_ADDRESS_LOW_OFFSET                           (0x00001C58)
> +#define MPI3_SYSIF_DIAG_RW_ADDRESS_HIGH_OFFSET                          (0x00001C5C)
> +
> +/**** Defines for DiagRWControl register ****/
> +#define MPI3_SYSIF_DIAG_RW_CONTROL_OFFSET                               (0x00001C60)
> +#define MPI3_SYSIF_DIAG_RW_CONTROL_LEN_MASK                             (0x00000030)
> +#define MPI3_SYSIF_DIAG_RW_CONTROL_LEN_1BYTE                            (0x00000000)
> +#define MPI3_SYSIF_DIAG_RW_CONTROL_LEN_2BYTES                           (0x00000010)
> +#define MPI3_SYSIF_DIAG_RW_CONTROL_LEN_4BYTES                           (0x00000020)
> +#define MPI3_SYSIF_DIAG_RW_CONTROL_LEN_8BYTES                           (0x00000030)
> +#define MPI3_SYSIF_DIAG_RW_CONTROL_RESET                                (0x00000004)
> +#define MPI3_SYSIF_DIAG_RW_CONTROL_DIR_MASK                             (0x00000002)
> +#define MPI3_SYSIF_DIAG_RW_CONTROL_DIR_READ                             (0x00000000)
> +#define MPI3_SYSIF_DIAG_RW_CONTROL_DIR_WRITE                            (0x00000002)
> +#define MPI3_SYSIF_DIAG_RW_CONTROL_START                                (0x00000001)
> +
> +/**** Defines for DiagRWStatus register ****/
> +#define MPI3_SYSIF_DIAG_RW_STATUS_OFFSET                                (0x00001C62)
> +#define MPI3_SYSIF_DIAG_RW_STATUS_STATUS_MASK                           (0x0000000E)
> +#define MPI3_SYSIF_DIAG_RW_STATUS_STATUS_SUCCESS                        (0x00000000)
> +#define MPI3_SYSIF_DIAG_RW_STATUS_STATUS_INV_ADDR                       (0x00000002)
> +#define MPI3_SYSIF_DIAG_RW_STATUS_STATUS_ACC_ERR                        (0x00000004)
> +#define MPI3_SYSIF_DIAG_RW_STATUS_STATUS_PAR_ERR                        (0x00000006)
> +#define MPI3_SYSIF_DIAG_RW_STATUS_BUSY                                  (0x00000001)
> +
> +/**** Defines for Scratchpad registers ****/
> +#define MPI3_SYSIF_SCRATCHPAD0_OFFSET                                   (0x00001CF0)
> +#define MPI3_SYSIF_SCRATCHPAD1_OFFSET                                   (0x00001CF4)
> +#define MPI3_SYSIF_SCRATCHPAD2_OFFSET                                   (0x00001CF8)
> +#define MPI3_SYSIF_SCRATCHPAD3_OFFSET                                   (0x00001CFC)
> +
> +/**** Defines for Device Assigned registers ****/
> +#define MPI3_SYSIF_DEVICE_ASSIGNED_REGS_OFFSET                          (0x00002000)
> +
> +/**** Default Defines for Diag Save Timeout ****/
> +#define MPI3_SYSIF_DIAG_SAVE_TIMEOUT                                    (60)    /* seconds */
> +
> +/*****************************************************************************
> + *              Reply Descriptors                                            *
> + ****************************************************************************/
> +
> +/*****************************************************************************
> + *              Default Reply Descriptor                                     *
> + ****************************************************************************/
> +typedef struct _MPI3_DEFAULT_REPLY_DESCRIPTOR {
> +    U32             DescriptorTypeDependent1[2];    /* 0x00 */
> +    U16             RequestQueueCI;                 /* 0x08 */
> +    U16             RequestQueueID;                 /* 0x0A */
> +    U16             DescriptorTypeDependent2;       /* 0x0C */
> +    U16             ReplyFlags;                     /* 0x0E */
> +} MPI3_DEFAULT_REPLY_DESCRIPTOR, MPI3_POINTER PTR_MPI3_DEFAULT_REPLY_DESCRIPTOR,
> +  Mpi3DefaultReplyDescriptor_t, MPI3_POINTER pMpi3DefaultReplyDescriptor_t;
> +
> +/**** Defines for the ReplyFlags field ****/
> +#define MPI3_REPLY_DESCRIPT_FLAGS_PHASE_MASK                       (0x0001)
> +#define MPI3_REPLY_DESCRIPT_FLAGS_TYPE_MASK                        (0xF000)
> +#define MPI3_REPLY_DESCRIPT_FLAGS_TYPE_ADDRESS_REPLY               (0x0000)
> +#define MPI3_REPLY_DESCRIPT_FLAGS_TYPE_SUCCESS                     (0x1000)
> +#define MPI3_REPLY_DESCRIPT_FLAGS_TYPE_TARGET_COMMAND_BUFFER       (0x2000)
> +#define MPI3_REPLY_DESCRIPT_FLAGS_TYPE_STATUS                      (0x3000)
> +
> +/*****************************************************************************
> + *              Address Reply Descriptor                                     *
> + ****************************************************************************/
> +typedef struct _MPI3_ADDRESS_REPLY_DESCRIPTOR {
> +    U64             ReplyFrameAddress;              /* 0x00 */
> +    U16             RequestQueueCI;                 /* 0x08 */
> +    U16             RequestQueueID;                 /* 0x0A */
> +    U16             Reserved0C;                     /* 0x0C */
> +    U16             ReplyFlags;                     /* 0x0E */
> +} MPI3_ADDRESS_REPLY_DESCRIPTOR, MPI3_POINTER PTR_MPI3_ADDRESS_REPLY_DESCRIPTOR,
> +  Mpi3AddressReplyDescriptor_t, MPI3_POINTER pMpi3AddressReplyDescriptor_t;
> +
> +/*****************************************************************************
> + *              Success Reply Descriptor                                     *
> + ****************************************************************************/
> +typedef struct _MPI3_SUCCESS_REPLY_DESCRIPTOR {
> +    U32             Reserved00[2];                  /* 0x00 */
> +    U16             RequestQueueCI;                 /* 0x08 */
> +    U16             RequestQueueID;                 /* 0x0A */
> +    U16             HostTag;                        /* 0x0C */
> +    U16             ReplyFlags;                     /* 0x0E */
> +} MPI3_SUCCESS_REPLY_DESCRIPTOR, MPI3_POINTER PTR_MPI3_SUCCESS_REPLY_DESCRIPTOR,
> +  Mpi3SuccessReplyDescriptor_t, MPI3_POINTER pMpi3SuccessReplyDescriptor_t;
> +
> +/*****************************************************************************
> + *              Target Command Buffer Reply Descriptor                       *
> + ****************************************************************************/
> +typedef struct _MPI3_TARGET_COMMAND_BUFFER_REPLY_DESCRIPTOR {
> +    U32             Reserved00;                     /* 0x00 */
> +    U16             InitiatorDevHandle;             /* 0x04 */
> +    U8              PhyNum;                         /* 0x06 */
> +    U8              Reserved07;                     /* 0x07 */
> +    U16             RequestQueueCI;                 /* 0x08 */
> +    U16             RequestQueueID;                 /* 0x0A */
> +    U16             IOIndex;                        /* 0x0C */
> +    U16             ReplyFlags;                     /* 0x0E */
> +} MPI3_TARGET_COMMAND_BUFFER_REPLY_DESCRIPTOR, MPI3_POINTER PTR_MPI3_TARGET_COMMAND_BUFFER_REPLY_DESCRIPTOR,
> +  Mpi3TargetCommandBufferReplyDescriptor_t, MPI3_POINTER pMpi3TargetCommandBufferReplyDescriptor_t;
> +
> +/**** See Default Reply Descriptor Defines above for definitions in the ReplyFlags field ****/
> +
> +/*****************************************************************************
> + *              Status Reply Descriptor                                      *
> + ****************************************************************************/
> +typedef struct _MPI3_STATUS_REPLY_DESCRIPTOR {
> +    U16             IOCStatus;                      /* 0x00 */
> +    U16             Reserved02;                     /* 0x02 */
> +    U32             IOCLogInfo;                     /* 0x04 */
> +    U16             RequestQueueCI;                 /* 0x08 */
> +    U16             RequestQueueID;                 /* 0x0A */
> +    U16             HostTag;                        /* 0x0C */
> +    U16             ReplyFlags;                     /* 0x0E */
> +} MPI3_STATUS_REPLY_DESCRIPTOR, MPI3_POINTER PTR_MPI3_STATUS_REPLY_DESCRIPTOR,
> +  Mpi3StatusReplyDescriptor_t, MPI3_POINTER pMpi3StatusReplyDescriptor_t;
> +
> +/**** Defines for the IOCStatus field ****/
> +#define MPI3_REPLY_DESCRIPT_STATUS_IOCSTATUS_LOGINFOAVAIL               (0x8000)
> +#define MPI3_REPLY_DESCRIPT_STATUS_IOCSTATUS_STATUS_MASK                (0x7FFF)
> +
> +/**** Defines for the IOCLogInfo field ****/
> +#define MPI3_REPLY_DESCRIPT_STATUS_IOCLOGINFO_TYPE_MASK                 (0xF0000000)
> +#define MPI3_REPLY_DESCRIPT_STATUS_IOCLOGINFO_TYPE_NO_INFO              (0x00000000)
> +#define MPI3_REPLY_DESCRIPT_STATUS_IOCLOGINFO_TYPE_SAS                  (0x30000000)
> +#define MPI3_REPLY_DESCRIPT_STATUS_IOCLOGINFO_DATA_MASK                 (0x0FFFFFFF)
> +
> +/*****************************************************************************
> + *              Union of Reply Descriptors                                   *
> + ****************************************************************************/
> +typedef union _MPI3_REPLY_DESCRIPTORS_UNION {
> +    MPI3_DEFAULT_REPLY_DESCRIPTOR               Default;
> +    MPI3_ADDRESS_REPLY_DESCRIPTOR               AddressReply;
> +    MPI3_SUCCESS_REPLY_DESCRIPTOR               Success;
> +    MPI3_TARGET_COMMAND_BUFFER_REPLY_DESCRIPTOR TargetCommandBuffer;
> +    MPI3_STATUS_REPLY_DESCRIPTOR                Status;
> +    U32                                         Words[4];
> +} MPI3_REPLY_DESCRIPTORS_UNION, MPI3_POINTER PTR_MPI3_REPLY_DESCRIPTORS_UNION,
> +  Mpi3ReplyDescriptorsUnion_t, MPI3_POINTER pMpi3ReplyDescriptorsUnion_t;
> +
> +
> +/*****************************************************************************
> + *              Scatter Gather Elements                                      *
> + ****************************************************************************/
> +
> +/*****************************************************************************
> + *              Common structure for Simple, Chain, and Last Chain           *
> + *              scatter gather elements                                      *
> + ****************************************************************************/
> +typedef struct _MPI3_SGE_COMMON {
> +    U64             Address;                           /* 0x00 */
> +    U32             Length;                            /* 0x08 */
> +    U8              Reserved0C[3];                     /* 0x0C */
> +    U8              Flags;                             /* 0x0F */
> +} MPI3_SGE_SIMPLE, MPI3_POINTER PTR_MPI3_SGE_SIMPLE,
> +  Mpi3SGESimple_t, MPI3_POINTER pMpi3SGESimple_t,
> +  MPI3_SGE_CHAIN, MPI3_POINTER PTR_MPI3_SGE_CHAIN,
> +  Mpi3SGEChain_t, MPI3_POINTER pMpi3SGEChain_t,
> +  MPI3_SGE_LAST_CHAIN, MPI3_POINTER PTR_MPI3_SGE_LAST_CHAIN,
> +  Mpi3SGELastChain_t, MPI3_POINTER pMpi3SGELastChain_t;
> +
> +/*****************************************************************************
> + *              Bit Bucket scatter gather element                            *
> + ****************************************************************************/
> +typedef struct _MPI3_SGE_BIT_BUCKET {
> +    U64             Reserved00;                        /* 0x00 */
> +    U32             Length;                            /* 0x08 */
> +    U8              Reserved0C[3];                     /* 0x0C */
> +    U8              Flags;                             /* 0x0F */
> +} MPI3_SGE_BIT_BUCKET, MPI3_POINTER PTR_MPI3_SGE_BIT_BUCKET,
> +  Mpi3SGEBitBucket, MPI3_POINTER pMpi3SGEBitBucket;
> +
> +/*****************************************************************************
> + *              Extended EEDP scatter gather element                         *
> + ****************************************************************************/
> +typedef struct _MPI3_SGE_EXTENDED_EEDP {
> +    U8              UserDataSize;                      /* 0x00 */
> +    U8              Reserved01;                        /* 0x01 */
> +    U16             EEDPFlags;                         /* 0x02 */
> +    U32             SecondaryReferenceTag;             /* 0x04 */
> +    U16             SecondaryApplicationTag;           /* 0x08 */
> +    U16             ApplicationTagTranslationMask;     /* 0x0A */
> +    U16             Reserved0C;                        /* 0x0C */
> +    U8              ExtendedOperation;                 /* 0x0E */
> +    U8              Flags;                             /* 0x0F */
> +} MPI3_SGE_EXTENDED_EEDP, MPI3_POINTER PTR_MPI3_SGE_EXTENDED_EEDP,
> +  Mpi3SGEExtendedEEDP_t, MPI3_POINTER pMpi3SGEExtendedEEDP_t;
> +
> +/*****************************************************************************
> + *              Union of scatter gather elements                             *
> + ****************************************************************************/
> +typedef union _MPI3_SGE_UNION {
> +    MPI3_SGE_SIMPLE                 Simple;
> +    MPI3_SGE_CHAIN                  Chain;
> +    MPI3_SGE_LAST_CHAIN             LastChain;
> +    MPI3_SGE_BIT_BUCKET             BitBucket;
> +    MPI3_SGE_EXTENDED_EEDP          Eedp;
> +    U32                             Words[4];
> +} MPI3_SGE_UNION, MPI3_POINTER PTR_MPI3_SGE_UNION,
> +  Mpi3SGEUnion_t, MPI3_POINTER pMpi3SGEUnion_t;
> +
> +/**** Definitions for the Flags field ****/
> +#define MPI3_SGE_FLAGS_ELEMENT_TYPE_MASK        (0xF0)
> +#define MPI3_SGE_FLAGS_ELEMENT_TYPE_SIMPLE      (0x00)
> +#define MPI3_SGE_FLAGS_ELEMENT_TYPE_BIT_BUCKET  (0x10)
> +#define MPI3_SGE_FLAGS_ELEMENT_TYPE_CHAIN       (0x20)
> +#define MPI3_SGE_FLAGS_ELEMENT_TYPE_LAST_CHAIN  (0x30)
> +#define MPI3_SGE_FLAGS_ELEMENT_TYPE_EXTENDED    (0xF0)
> +#define MPI3_SGE_FLAGS_END_OF_LIST              (0x08)
> +#define MPI3_SGE_FLAGS_END_OF_BUFFER            (0x04)
> +#define MPI3_SGE_FLAGS_DLAS_MASK                (0x03)
> +#define MPI3_SGE_FLAGS_DLAS_SYSTEM              (0x00)
> +#define MPI3_SGE_FLAGS_DLAS_IOC_DDR             (0x01)
> +#define MPI3_SGE_FLAGS_DLAS_IOC_CTL             (0x02)
> +
> +/**** Definitions for the ExtendedOperation field of Extended element ****/
> +#define MPI3_SGE_EXT_OPER_EEDP                  (0x00)
> +
> +/**** Definitions for the EEDPFlags field of Extended EEDP element ****/
> +#define MPI3_EEDPFLAGS_INCR_PRI_REF_TAG             (0x8000)
> +#define MPI3_EEDPFLAGS_INCR_SEC_REF_TAG             (0x4000)
> +#define MPI3_EEDPFLAGS_INCR_PRI_APP_TAG             (0x2000)
> +#define MPI3_EEDPFLAGS_INCR_SEC_APP_TAG             (0x1000)
> +#define MPI3_EEDPFLAGS_ESC_PASSTHROUGH              (0x0800)
> +#define MPI3_EEDPFLAGS_CHK_REF_TAG                  (0x0400)
> +#define MPI3_EEDPFLAGS_CHK_APP_TAG                  (0x0200)
> +#define MPI3_EEDPFLAGS_CHK_GUARD                    (0x0100)
> +#define MPI3_EEDPFLAGS_ESC_MODE_MASK                (0x00C0)
> +#define MPI3_EEDPFLAGS_ESC_MODE_DO_NOT_DISABLE      (0x0040)
> +#define MPI3_EEDPFLAGS_ESC_MODE_APPTAG_DISABLE      (0x0080)
> +#define MPI3_EEDPFLAGS_ESC_MODE_APPTAG_REFTAG_DISABLE   (0x00C0)
> +#define MPI3_EEDPFLAGS_HOST_GUARD_MASK              (0x0030)
> +#define MPI3_EEDPFLAGS_HOST_GUARD_T10_CRC           (0x0000)
> +#define MPI3_EEDPFLAGS_HOST_GUARD_IP_CHKSUM         (0x0010)
> +#define MPI3_EEDPFLAGS_HOST_GUARD_OEM_SPECIFIC      (0x0020)
> +#define MPI3_EEDPFLAGS_PT_REF_TAG                   (0x0008)
> +#define MPI3_EEDPFLAGS_EEDP_OP_MASK                 (0x0007)
> +#define MPI3_EEDPFLAGS_EEDP_OP_NOOP                 (0x0000)
> +#define MPI3_EEDPFLAGS_EEDP_OP_CHECK                (0x0001)
> +#define MPI3_EEDPFLAGS_EEDP_OP_STRIP                (0x0002)
> +#define MPI3_EEDPFLAGS_EEDP_OP_CHECK_REMOVE         (0x0003)
> +#define MPI3_EEDPFLAGS_EEDP_OP_INSERT               (0x0004)
> +#define MPI3_EEDPFLAGS_EEDP_OP_REPLACE              (0x0006)
> +#define MPI3_EEDPFLAGS_EEDP_OP_CHECK_REGEN          (0x0007)
> +
> +/**** Definitions for the UserDataSize field of Extended EEDP element ****/
> +#define MPI3_EEDP_UDS_512                           (0x01)
> +#define MPI3_EEDP_UDS_520                           (0x02)
> +#define MPI3_EEDP_UDS_4080                          (0x03)
> +#define MPI3_EEDP_UDS_4088                          (0x04)
> +#define MPI3_EEDP_UDS_4096                          (0x05)
> +#define MPI3_EEDP_UDS_4104                          (0x06)
> +#define MPI3_EEDP_UDS_4160                          (0x07)
> +
> +/*****************************************************************************
> + *              Standard Message Structures                                  *
> + ****************************************************************************/
> +
> +/*****************************************************************************
> + *              Request Message Header for all request messages              *
> + ****************************************************************************/
> +typedef struct _MPI3_REQUEST_HEADER {
> +    U16             HostTag;                    /* 0x00 */
> +    U8              IOCUseOnly02;               /* 0x02 */
> +    U8              Function;                   /* 0x03 */
> +    U16             IOCUseOnly04;               /* 0x04 */
> +    U8              IOCUseOnly06;               /* 0x06 */
> +    U8              MsgFlags;                   /* 0x07 */
> +    U16             ChangeCount;                /* 0x08 */
> +    U16             FunctionDependent;          /* 0x0A */
> +} MPI3_REQUEST_HEADER, MPI3_POINTER PTR_MPI3_REQUEST_HEADER,
> +  Mpi3RequestHeader_t, MPI3_POINTER pMpi3RequestHeader_t;
> +
> +/*****************************************************************************
> + *              Default Reply                                                *
> + ****************************************************************************/
> +typedef struct _MPI3_DEFAULT_REPLY {
> +    U16             HostTag;                    /* 0x00 */
> +    U8              IOCUseOnly02;               /* 0x02 */
> +    U8              Function;                   /* 0x03 */
> +    U16             IOCUseOnly04;               /* 0x04 */
> +    U8              IOCUseOnly06;               /* 0x06 */
> +    U8              MsgFlags;                   /* 0x07 */
> +    U16             IOCUseOnly08;               /* 0x08 */
> +    U16             IOCStatus;                  /* 0x0A */
> +    U32             IOCLogInfo;                 /* 0x0C */
> +} MPI3_DEFAULT_REPLY, MPI3_POINTER PTR_MPI3_DEFAULT_REPLY,
> +  Mpi3DefaultReply_t, MPI3_POINTER pMpi3DefaultReply_t;
> +
> +/**** Defines for the HostTag field ****/
> +#define MPI3_HOST_TAG_INVALID                       (0xFFFF)
> +
> +/**** Defines for message Function ****/
> +/* I/O Controller functions */
> +#define MPI3_FUNCTION_IOC_FACTS                     (0x01) /* IOC Facts */
> +#define MPI3_FUNCTION_IOC_INIT                      (0x02) /* IOC Init */
> +#define MPI3_FUNCTION_PORT_ENABLE                   (0x03) /* Port Enable */
> +#define MPI3_FUNCTION_EVENT_NOTIFICATION            (0x04) /* Event Notification */
> +#define MPI3_FUNCTION_EVENT_ACK                     (0x05) /* Event Acknowledge */
> +#define MPI3_FUNCTION_CI_DOWNLOAD                   (0x06) /* Component Image Download */
> +#define MPI3_FUNCTION_CI_UPLOAD                     (0x07) /* Component Image Upload */
> +#define MPI3_FUNCTION_IO_UNIT_CONTROL               (0x08) /* IO Unit Control */
> +#define MPI3_FUNCTION_PERSISTENT_EVENT_LOG          (0x09) /* Persistent Event Log */
> +#define MPI3_FUNCTION_MGMT_PASSTHROUGH              (0x0A) /* Management Passthrough */
> +#define MPI3_FUNCTION_CONFIG                        (0x10) /* Configuration */
> +
> +/* SCSI Initiator I/O functions */
> +#define MPI3_FUNCTION_SCSI_IO                       (0x20) /* SCSI IO */
> +#define MPI3_FUNCTION_SCSI_TASK_MGMT                (0x21) /* SCSI Task Management */
> +#define MPI3_FUNCTION_SMP_PASSTHROUGH               (0x22) /* SMP Passthrough */
> +#define MPI3_FUNCTION_NVME_ENCAPSULATED             (0x24) /* NVMe Encapsulated */
> +
> +/* SCSI Target I/O functions */
> +#define MPI3_FUNCTION_TARGET_ASSIST                 (0x30) /* Target Assist */
> +#define MPI3_FUNCTION_TARGET_STATUS_SEND            (0x31) /* Target Status Send */
> +#define MPI3_FUNCTION_TARGET_MODE_ABORT             (0x32) /* Target Mode Abort */
> +#define MPI3_FUNCTION_TARGET_CMD_BUF_POST_BASE      (0x33) /* Target Command Buffer Post Base */
> +#define MPI3_FUNCTION_TARGET_CMD_BUF_POST_LIST      (0x34) /* Target Command Buffer Post List */
> +
> +/* Queue Management functions */
> +#define MPI3_FUNCTION_CREATE_REQUEST_QUEUE          (0x70)  /* Create an operational request queue */
> +#define MPI3_FUNCTION_DELETE_REQUEST_QUEUE          (0x71)  /* Delete an operational request queue */
> +#define MPI3_FUNCTION_CREATE_REPLY_QUEUE            (0x72)  /* Create an operational reply queue */
> +#define MPI3_FUNCTION_DELETE_REPLY_QUEUE            (0x73)  /* Delete an operational reply queue */
> +
> +/* Diagnostic Tools */
> +#define MPI3_FUNCTION_TOOLBOX                       (0x80) /* Toolbox */
> +#define MPI3_FUNCTION_DIAG_BUFFER_POST              (0x81) /* Post a Diagnostic Buffer to the I/O Unit */
> +#define MPI3_FUNCTION_DIAG_BUFFER_MANAGE            (0x82) /* Manage a Diagnostic Buffer */
> +#define MPI3_FUNCTION_DIAG_BUFFER_UPLOAD            (0x83) /* Upload a Diagnostic Buffer */
> +
> +/* Miscellaneous functions */
> +#define MPI3_FUNCTION_MIN_IOC_USE_ONLY              (0xC0)  /* Beginning of IOC Use Only range of function codes */
> +#define MPI3_FUNCTION_MAX_IOC_USE_ONLY              (0xEF)  /* End of IOC Use Only range of function codes */
> +#define MPI3_FUNCTION_MIN_PRODUCT_SPECIFIC          (0xF0)  /* Beginning of the product-specific range of function codes */
> +#define MPI3_FUNCTION_MAX_PRODUCT_SPECIFIC          (0xFF)  /* End of the product-specific range of function codes */
> +
> +/**** Defines for IOCStatus ****/
> +#define MPI3_IOCSTATUS_LOG_INFO_AVAIL_MASK          (0x8000)
> +#define MPI3_IOCSTATUS_LOG_INFO_AVAILABLE           (0x8000)
> +#define MPI3_IOCSTATUS_STATUS_MASK                  (0x7FFF)
> +
> +/* Common IOCStatus values for all replies */
> +#define MPI3_IOCSTATUS_SUCCESS                      (0x0000)
> +#define MPI3_IOCSTATUS_INVALID_FUNCTION             (0x0001)
> +#define MPI3_IOCSTATUS_BUSY                         (0x0002)
> +#define MPI3_IOCSTATUS_INVALID_SGL                  (0x0003)
> +#define MPI3_IOCSTATUS_INTERNAL_ERROR               (0x0004)
> +#define MPI3_IOCSTATUS_INSUFFICIENT_RESOURCES       (0x0006)
> +#define MPI3_IOCSTATUS_INVALID_FIELD                (0x0007)
> +#define MPI3_IOCSTATUS_INVALID_STATE                (0x0008)
> +#define MPI3_IOCSTATUS_INSUFFICIENT_POWER           (0x000A)
> +#define MPI3_IOCSTATUS_INVALID_CHANGE_COUNT         (0x000B)
> +#define MPI3_IOCSTATUS_FAILURE                      (0x001F)
> +
> +/* Config IOCStatus values */
> +#define MPI3_IOCSTATUS_CONFIG_INVALID_ACTION        (0x0020)
> +#define MPI3_IOCSTATUS_CONFIG_INVALID_TYPE          (0x0021)
> +#define MPI3_IOCSTATUS_CONFIG_INVALID_PAGE          (0x0022)
> +#define MPI3_IOCSTATUS_CONFIG_INVALID_DATA          (0x0023)
> +#define MPI3_IOCSTATUS_CONFIG_NO_DEFAULTS           (0x0024)
> +#define MPI3_IOCSTATUS_CONFIG_CANT_COMMIT           (0x0025)
> +
> +/* SCSI IO IOCStatus values */
> +#define MPI3_IOCSTATUS_SCSI_RECOVERED_ERROR         (0x0040)
> +#define MPI3_IOCSTATUS_SCSI_TM_NOT_SUPPORTED        (0x0041)
> +#define MPI3_IOCSTATUS_SCSI_INVALID_DEVHANDLE       (0x0042)
> +#define MPI3_IOCSTATUS_SCSI_DEVICE_NOT_THERE        (0x0043)
> +#define MPI3_IOCSTATUS_SCSI_DATA_OVERRUN            (0x0044)
> +#define MPI3_IOCSTATUS_SCSI_DATA_UNDERRUN           (0x0045)
> +#define MPI3_IOCSTATUS_SCSI_IO_DATA_ERROR           (0x0046)
> +#define MPI3_IOCSTATUS_SCSI_PROTOCOL_ERROR          (0x0047)
> +#define MPI3_IOCSTATUS_SCSI_TASK_TERMINATED         (0x0048)
> +#define MPI3_IOCSTATUS_SCSI_RESIDUAL_MISMATCH       (0x0049)
> +#define MPI3_IOCSTATUS_SCSI_TASK_MGMT_FAILED        (0x004A)
> +#define MPI3_IOCSTATUS_SCSI_IOC_TERMINATED          (0x004B)
> +#define MPI3_IOCSTATUS_SCSI_EXT_TERMINATED          (0x004C)
> +
> +/* SCSI Initiator and SCSI Target end-to-end data protection values */
> +#define MPI3_IOCSTATUS_EEDP_GUARD_ERROR             (0x004D)
> +#define MPI3_IOCSTATUS_EEDP_REF_TAG_ERROR           (0x004E)
> +#define MPI3_IOCSTATUS_EEDP_APP_TAG_ERROR           (0x004F)
> +
> +/* SCSI Target IOCStatus values */
> +#define MPI3_IOCSTATUS_TARGET_INVALID_IO_INDEX      (0x0062)
> +#define MPI3_IOCSTATUS_TARGET_ABORTED               (0x0063)
> +#define MPI3_IOCSTATUS_TARGET_NO_CONN_RETRYABLE     (0x0064)
> +#define MPI3_IOCSTATUS_TARGET_NO_CONNECTION         (0x0065)
> +#define MPI3_IOCSTATUS_TARGET_XFER_COUNT_MISMATCH   (0x006A)
> +#define MPI3_IOCSTATUS_TARGET_DATA_OFFSET_ERROR     (0x006D)
> +#define MPI3_IOCSTATUS_TARGET_TOO_MUCH_WRITE_DATA   (0x006E)
> +#define MPI3_IOCSTATUS_TARGET_IU_TOO_SHORT          (0x006F)
> +#define MPI3_IOCSTATUS_TARGET_ACK_NAK_TIMEOUT       (0x0070)
> +#define MPI3_IOCSTATUS_TARGET_NAK_RECEIVED          (0x0071)
> +
> +/* Serial Attached SCSI IOCStatus values */
> +#define MPI3_IOCSTATUS_SAS_SMP_REQUEST_FAILED       (0x0090)
> +#define MPI3_IOCSTATUS_SAS_SMP_DATA_OVERRUN         (0x0091)
> +
> +/* Diagnostic Buffer Post/Release IOCStatus values */
> +#define MPI3_IOCSTATUS_DIAGNOSTIC_RELEASED          (0x00A0)
> +
> +/* Component Image Upload/Download */
> +#define MPI3_IOCSTATUS_CI_UNSUPPORTED               (0x00B0)
> +#define MPI3_IOCSTATUS_CI_UPDATE_SEQUENCE           (0x00B1)
> +#define MPI3_IOCSTATUS_CI_VALIDATION_FAILED         (0x00B2)
> +#define MPI3_IOCSTATUS_CI_UPDATE_PENDING            (0x00B3)
> +
> +/* Security values */
> +#define MPI3_IOCSTATUS_SECURITY_KEY_REQUIRED        (0x00C0)
> +
> +/* Request and Reply Queues related IOCStatus values */
> +#define MPI3_IOCSTATUS_INVALID_QUEUE_ID             (0x0F00)
> +#define MPI3_IOCSTATUS_INVALID_QUEUE_SIZE           (0x0F01)
> +#define MPI3_IOCSTATUS_INVALID_MSIX_VECTOR          (0x0F02)
> +#define MPI3_IOCSTATUS_INVALID_REPLY_QUEUE_ID       (0x0F03)
> +#define MPI3_IOCSTATUS_INVALID_QUEUE_DELETION       (0x0F04)
> +
> +/**** Defines for IOCLogInfo ****/
> +#define MPI3_IOCLOGINFO_TYPE_MASK               (0xF0000000)
> +#define MPI3_IOCLOGINFO_TYPE_SHIFT              (28)
> +#define MPI3_IOCLOGINFO_TYPE_NONE               (0x0)
> +#define MPI3_IOCLOGINFO_TYPE_SAS                (0x3)
> +#define MPI3_IOCLOGINFO_LOG_DATA_MASK           (0x0FFFFFFF)
> +
> +#endif  /* MPI30_TRANSPORT_H */
> diff --git a/drivers/scsi/mpi3mr/mpi/mpi30_type.h b/drivers/scsi/mpi3mr/mpi/mpi30_type.h
> new file mode 100644
> index 000000000000..5de35e7a660f
> --- /dev/null
> +++ b/drivers/scsi/mpi3mr/mpi/mpi30_type.h
> @@ -0,0 +1,89 @@
> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> +/*
> + *  Copyright 2016-2020 Broadcom Inc. All rights reserved.
> + *
> + *           Name: mpi30_type.h
> + *    Description: MPI basic type definitions
> + *  Creation Date: 10/07/2016
> + *        Version: 03.00.00
> + */
> +#ifndef MPI30_TYPE_H
> +#define MPI30_TYPE_H     1
> +
> +/*****************************************************************************
> + * Define MPI3_POINTER if it has not already been defined. By default        *
> + * MPI3_POINTER is defined to be a near pointer. MPI3_POINTER can be defined *
> + * as a far pointer by defining MPI3_POINTER as "far *" before this header   *
> + * file is included.                                                         *
> + ****************************************************************************/
> +#ifndef MPI3_POINTER
> +#define MPI3_POINTER    *
> +#endif  /* MPI3_POINTER */
> +
> +/* The basic types may have already been included by mpi_type.h or mpi2_type.h*/
> +#if !defined(MPI_TYPE_H) && !defined(MPI2_TYPE_H)
> +#if 1
> +/*****************************************************************************
> +*
> +*               Basic Types
> +*
> +*****************************************************************************/
> +
> +typedef u8 U8;
> +typedef __le16 U16;
> +typedef __le32 U32;
> +typedef __le64 U64 __aligned(4);
> +
> +/*****************************************************************************
> +*
> +*               Pointer Types
> +*
> +*****************************************************************************/
> +
> +typedef U8 * PU8;
> +typedef U16 * PU16;
> +typedef U32 * PU32;
> +typedef U64 * PU64;
> +#else
> +/*****************************************************************************
> + *              Basic Types                                                  *
> + ****************************************************************************/
> +typedef int8_t      S8;
> +typedef uint8_t     U8;
> +typedef int16_t     S16;
> +typedef uint16_t    U16;
> +typedef int32_t     S32;
> +typedef uint32_t    U32;
> +typedef int64_t     S64;
> +typedef uint64_t    U64;
> +
> +/*****************************************************************************
> + *              Structure Types                                              *
> + ****************************************************************************/
> +typedef struct _S64struct {
> +    U32         Low;
> +    S32         High;
> +} S64struct;
> +
> +typedef struct _U64struct {
> +    U32         Low;
> +    U32         High;
> +} U64struct;
> +

I wonder why you need these structures on a 64-bit system ...

> +/*****************************************************************************
> + *              Pointer Types                                                *
> + ****************************************************************************/
> +typedef S8 * PS8;
> +typedef U8 * PU8;
> +typedef S16 * PS16;
> +typedef U16 * PU16;
> +typedef S32         *PS32;
> +typedef U32         *PU32;
> +typedef S64 * PS64;
> +typedef U64 * PU64;
> +typedef S64struct * PS64struct;
> +typedef U64struct * PU64struct;
> +#endif
> +#endif  /* MPI_TYPE_H && MPI2_TYPE_H */
> +
> +#endif  /* MPI30_TYPE_H */
> 
And I do agree with Bart, please kill the pointer types.
It's not serving any purpose whatsoever.

Cheers,

Hannes
-- 
Dr. Hannes Reinecke		           Kernel Storage Architect
hare@suse.de			                  +49 911 74053 688
SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), GF: Felix Imendörffer

^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 02/24] mpi3mr: base driver code
  2020-12-22 10:11 ` [PATCH 02/24] mpi3mr: base driver code Kashyap Desai
  2020-12-27 14:14     ` kernel test robot
@ 2021-02-23 12:55   ` Hannes Reinecke
  2021-03-02 18:36     ` Kashyap Desai
  1 sibling, 1 reply; 75+ messages in thread
From: Hannes Reinecke @ 2021-02-23 12:55 UTC (permalink / raw)
  To: Kashyap Desai, linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, sathya.prakash

On 12/22/20 11:11 AM, Kashyap Desai wrote:
> This patch covers basic pci device driver requirements -
> device probe, memory allocation, mapping system registers,
> allocate irq lines etc.
> 
> Source is managed in mainly three different files.
> 
> mpi3mr_fw.c -	Keep common code which interact with underlying fw/hw.
> mpi3mr_os.c -	Keep common code which interact with scsi midlayer.
> mpi3mr_app.c -	Keep common code which interact with application/ioctl.
> 		This is currently work in progress.
> 
> Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
> Cc: sathya.prakash@broadcom.com
> ---
>  drivers/scsi/mpi3mr/Makefile       |    4 +
>  drivers/scsi/mpi3mr/mpi3mr.h       |  526 ++++++++
>  drivers/scsi/mpi3mr/mpi3mr_debug.h |   60 +
>  drivers/scsi/mpi3mr/mpi3mr_fw.c    | 1819 ++++++++++++++++++++++++++++
>  drivers/scsi/mpi3mr/mpi3mr_os.c    |  368 ++++++
>  5 files changed, 2777 insertions(+)
>  create mode 100644 drivers/scsi/mpi3mr/Makefile
>  create mode 100644 drivers/scsi/mpi3mr/mpi3mr.h
>  create mode 100644 drivers/scsi/mpi3mr/mpi3mr_debug.h
>  create mode 100644 drivers/scsi/mpi3mr/mpi3mr_fw.c
>  create mode 100644 drivers/scsi/mpi3mr/mpi3mr_os.c
> 
> diff --git a/drivers/scsi/mpi3mr/Makefile b/drivers/scsi/mpi3mr/Makefile
> new file mode 100644
> index 000000000000..7c2063e04c81
> --- /dev/null
> +++ b/drivers/scsi/mpi3mr/Makefile
> @@ -0,0 +1,4 @@
> +# mpi3mr makefile
> +obj-m += mpi3mr.o
> +mpi3mr-y +=  mpi3mr_os.o     \
> +		mpi3mr_fw.o \
> diff --git a/drivers/scsi/mpi3mr/mpi3mr.h b/drivers/scsi/mpi3mr/mpi3mr.h
> new file mode 100644
> index 000000000000..dd79b12218e1
> --- /dev/null
> +++ b/drivers/scsi/mpi3mr/mpi3mr.h
> @@ -0,0 +1,526 @@
> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> +/*
> + * Driver for Broadcom MPI3 Storage Controllers
> + *
> + * Copyright (C) 2017-2020 Broadcom Inc.
> + *  (mailto: mpi3mr-linuxdrv.pdl@broadcom.com)
> + *
> + */
> +
> +#ifndef MPI3MR_H_INCLUDED
> +#define MPI3MR_H_INCLUDED
> +
> +#include <linux/blkdev.h>
> +#include <linux/blk-mq.h>
> +#include <linux/blk-mq-pci.h>
> +#include <linux/delay.h>
> +#include <linux/dmapool.h>
> +#include <linux/errno.h>
> +#include <linux/init.h>
> +#include <linux/io.h>
> +#include <linux/interrupt.h>
> +#include <linux/kernel.h>
> +#include <linux/miscdevice.h>
> +#include <linux/module.h>
> +#include <linux/pci.h>
> +#include <linux/poll.h>
> +#include <linux/sched.h>
> +#include <linux/slab.h>
> +#include <linux/types.h>
> +#include <linux/uaccess.h>
> +#include <linux/utsname.h>
> +#include <linux/version.h>
> +#include <linux/workqueue.h>
> +#include <asm/unaligned.h>
> +#include <scsi/scsi.h>
> +#include <scsi/scsi_cmnd.h>
> +#include <scsi/scsi_dbg.h>
> +#include <scsi/scsi_device.h>
> +#include <scsi/scsi_host.h>
> +#include <scsi/scsi_tcq.h>
> +
> +#include "mpi/mpi30_api.h"
> +#include "mpi3mr_debug.h"
> +
> +/* Global list and lock for storing multiple adapters managed by the driver */
> +extern spinlock_t mrioc_list_lock;
> +extern struct list_head mrioc_list;
> +
> +#define MPI3MR_DRIVER_VERSION	"00.255.45.01"
> +#define MPI3MR_DRIVER_RELDATE	"12-December-2020"
> +
> +#define MPI3MR_DRIVER_NAME	"mpi3mr"
> +#define MPI3MR_DRIVER_LICENSE	"GPL"
> +#define MPI3MR_DRIVER_AUTHOR	"Broadcom Inc. <mpi3mr-linuxdrv.pdl@broadcom.com>"
> +#define MPI3MR_DRIVER_DESC	"MPI3 Storage Controller Device Driver"
> +
> +#define MPI3MR_NAME_LENGTH	32
> +#define IOCNAME			"%s: "
> +
> +/* Definitions for internal SGL and Chain SGL buffers */
> +#define MPI3MR_PAGE_SIZE_4K		4096
> +#define MPI3MR_SG_DEPTH		(PAGE_SIZE/sizeof(Mpi3SGESimple_t))
> +
> +/* Definitions for MAX values for shost */
> +#define MPI3MR_MAX_CMDS_LUN	7
> +#define MPI3MR_MAX_CDB_LENGTH	32
> +
> +/* Admin queue management definitions */
> +#define MPI3MR_ADMIN_REQ_Q_SIZE		(2 * MPI3MR_PAGE_SIZE_4K)
> +#define MPI3MR_ADMIN_REPLY_Q_SIZE	(4 * MPI3MR_PAGE_SIZE_4K)
> +#define MPI3MR_ADMIN_REQ_FRAME_SZ	128
> +#define MPI3MR_ADMIN_REPLY_FRAME_SZ	16
> +
> +
> +/* Reserved Host Tag definitions */
> +#define MPI3MR_HOSTTAG_INVALID		0xFFFF
> +#define MPI3MR_HOSTTAG_INITCMDS		1
> +#define MPI3MR_HOSTTAG_IOCTLCMDS	2
> +#define MPI3MR_HOSTTAG_BLK_TMS		5
> +
> +#define MPI3MR_NUM_DEVRMCMD		1
> +#define MPI3MR_HOSTTAG_DEVRMCMD_MIN	(MPI3MR_HOSTTAG_BLK_TMS + 1)
> +#define MPI3MR_HOSTTAG_DEVRMCMD_MAX	(MPI3MR_HOSTTAG_DEVRMCMD_MIN + \
> +						MPI3MR_NUM_DEVRMCMD - 1)
> +
> +#define MPI3MR_INTERNAL_CMDS_RESVD     MPI3MR_HOSTTAG_DEVRMCMD_MAX
> +
> +/* Reduced resource count definition for crash kernel */
> +#define MPI3MR_HOST_IOS_KDUMP		128
> +
> +/* command/controller interaction timeout definitions in seconds */
> +#define MPI3MR_INTADMCMD_TIMEOUT		10
> +#define MPI3MR_RESETTM_TIMEOUT			30
> +#define MPI3MR_DEFAULT_SHUTDOWN_TIME		120
> +
> +#define MPI3MR_WATCHDOG_INTERVAL		1000 /* in milli seconds */
> +
> +/* Internal admin command state definitions*/
> +#define MPI3MR_CMD_NOTUSED	0x8000
> +#define MPI3MR_CMD_COMPLETE	0x0001
> +#define MPI3MR_CMD_PENDING	0x0002
> +#define MPI3MR_CMD_REPLY_VALID	0x0004
> +#define MPI3MR_CMD_RESET	0x0008
> +
> +/* Definitions for Event replies and sense buffer allocated per controller */
> +#define MPI3MR_NUM_EVT_REPLIES	64
> +#define MPI3MR_SENSEBUF_SZ	256
> +#define MPI3MR_SENSEBUF_FACTOR	3
> +#define MPI3MR_CHAINBUF_FACTOR	3
> +
> +/* Invalid target device handle */
> +#define MPI3MR_INVALID_DEV_HANDLE	0xFFFF
> +
> +/* Controller Reset related definitions */
> +#define MPI3MR_HOSTDIAG_UNLOCK_RETRY_COUNT	5
> +#define MPI3MR_MAX_RESET_RETRY_COUNT		3
> +
> +/* ResponseCode definitions */
> +#define MPI3MR_RI_MASK_RESPCODE		(0x000000FF)
> +#define MPI3MR_RSP_TM_COMPLETE		0x00
> +#define MPI3MR_RSP_INVALID_FRAME	0x02
> +#define MPI3MR_RSP_TM_NOT_SUPPORTED	0x04
> +#define MPI3MR_RSP_TM_FAILED		0x05
> +#define MPI3MR_RSP_TM_SUCCEEDED		0x08
> +#define MPI3MR_RSP_TM_INVALID_LUN	0x09
> +#define MPI3MR_RSP_TM_OVERLAPPED_TAG	0x0A
> +#define MPI3MR_RSP_IO_QUEUED_ON_IOC \
> +			MPI3_SCSITASKMGMT_RSPCODE_IO_QUEUED_ON_IOC
> +
> +/* SGE Flag definition */
> +#define MPI3MR_SGEFLAGS_SYSTEM_SIMPLE_END_OF_LIST \
> +	(MPI3_SGE_FLAGS_ELEMENT_TYPE_SIMPLE | MPI3_SGE_FLAGS_DLAS_SYSTEM | \
> +	MPI3_SGE_FLAGS_END_OF_LIST)
> +
> +/* IOC State definitions */
> +enum mpi3mr_iocstate {
> +	MRIOC_STATE_READY = 1,
> +	MRIOC_STATE_RESET,
> +	MRIOC_STATE_FAULT,
> +	MRIOC_STATE_BECOMING_READY,
> +	MRIOC_STATE_RESET_REQUESTED,
> +	MRIOC_STATE_UNRECOVERABLE,
> +};
> +
> +/* Reset reason code definitions*/
> +enum mpi3mr_reset_reason {
> +	MPI3MR_RESET_FROM_BRINGUP = 1,
> +	MPI3MR_RESET_FROM_FAULT_WATCH = 2,
> +	MPI3MR_RESET_FROM_IOCTL = 3,
> +	MPI3MR_RESET_FROM_EH_HOS = 4,
> +	MPI3MR_RESET_FROM_TM_TIMEOUT = 5,
> +	MPI3MR_RESET_FROM_IOCTL_TIMEOUT = 6,
> +	MPI3MR_RESET_FROM_MUR_FAILURE = 7,
> +	MPI3MR_RESET_FROM_CTLR_CLEANUP = 8,
> +	MPI3MR_RESET_FROM_CIACTIV_FAULT = 9,
> +	MPI3MR_RESET_FROM_PE_TIMEOUT = 10,
> +	MPI3MR_RESET_FROM_TSU_TIMEOUT = 11,
> +	MPI3MR_RESET_FROM_DELREQQ_TIMEOUT = 12,
> +	MPI3MR_RESET_FROM_DELREPQ_TIMEOUT = 13,
> +	MPI3MR_RESET_FROM_CREATEREPQ_TIMEOUT = 14,
> +	MPI3MR_RESET_FROM_CREATEREQQ_TIMEOUT = 15,
> +	MPI3MR_RESET_FROM_IOCFACTS_TIMEOUT = 16,
> +	MPI3MR_RESET_FROM_IOCINIT_TIMEOUT = 17,
> +	MPI3MR_RESET_FROM_EVTNOTIFY_TIMEOUT = 18,
> +	MPI3MR_RESET_FROM_EVTACK_TIMEOUT = 19,
> +	MPI3MR_RESET_FROM_CIACTVRST_TIMER = 20,
> +	MPI3MR_RESET_FROM_GETPKGVER_TIMEOUT = 21,
> +};
> +
> +/**
> + * struct mpi3mr_compimg_ver - replica of component image
> + * version defined in mpi30_image.h in host endianness
> + *
> + */
> +struct mpi3mr_compimg_ver {
> +	u16 build_num;
> +	u16 cust_id;
> +	u8 ph_minor;
> +	u8 ph_major;
> +	u8 gen_minor;
> +	u8 gen_major;
> +};
> +
> +/**
> + * struct mpi3mr_ioc_facs - replica of component image version
> + * defined in mpi30_ioc.h in host endianness
> + *
> + */
> +struct mpi3mr_ioc_facts {
> +	u32 ioc_capabilities;
> +	struct mpi3mr_compimg_ver fw_ver;
> +	u32 mpi_version;
> +	u16 max_reqs;
> +	u16 product_id;
> +	u16 op_req_sz;
> +	u16 reply_sz;
> +	u16 exceptions;
> +	u16 max_perids;
> +	u16 max_pds;
> +	u16 max_sasexpanders;
> +	u16 max_sasinitiators;
> +	u16 max_enclosures;
> +	u16 max_pcieswitches;
> +	u16 max_nvme;
> +	u16 max_vds;
> +	u16 max_hpds;
> +	u16 max_advhpds;
> +	u16 max_raidpds;
> +	u16 min_devhandle;
> +	u16 max_devhandle;
> +	u16 max_op_req_q;
> +	u16 max_op_reply_q;
> +	u16 shutdown_timeout;
> +	u8 ioc_num;
> +	u8 who_init;
> +	u16 max_msix_vectors;
> +	u8 personality;
> +	u8 dma_mask;
> +	u8 protocol_flags;
> +	u8 sge_mod_mask;
> +	u8 sge_mod_value;
> +	u8 sge_mod_shift;
> +};
> +
> +/**
> + * struct op_req_qinfo -  Operational Request Queue Information
> + *
> + * @ci: consumer index
> + * @pi: producer index
> + */
> +struct op_req_qinfo {
> +	u16 ci;
> +	u16 pi;
> +};
> +
> +/**
> + * struct op_reply_qinfo -  Operational Reply Queue Information
> + *
> + * @ci: consumer index
> + * @qid: Queue Id starting from 1
> + */
> +struct op_reply_qinfo {
> +	u16 ci;
> +	u16 qid;
> +};
> +
> +/**
> + * struct mpi3mr_intr_info -  Interrupt cookie information
> + *
> + * @mrioc: Adapter instance reference
> + * @msix_index: MSIx index
> + * @op_reply_q: Associated operational reply queue
> + * @name: Dev name for the irq claiming device
> + */
> +struct mpi3mr_intr_info {
> +	struct mpi3mr_ioc *mrioc;
> +	u16 msix_index;
> +	struct op_reply_qinfo *op_reply_q;
> +	char name[MPI3MR_NAME_LENGTH];
> +};
> +
> +
> +typedef struct mpi3mr_drv_cmd DRV_CMD;
> +typedef void (*DRV_CMD_CALLBACK)(struct mpi3mr_ioc *mrioc,
> +	DRV_CMD *drv_cmd);
> +
> +/**
> + * struct mpi3mr_drv_cmd - Internal command tracker
> + *
> + * @mutex: Command mutex
> + * @done: Completeor for wakeup
> + * @reply: Firmware reply for internal commands
> + * @sensebuf: Sensebuf for SCSI IO commands
> + * @state: Command State
> + * @dev_handle: Firmware handle for device specific commands
> + * @ioc_status: IOC status from the firmware
> + * @ioc_loginfo:IOC log info from the firmware
> + * @is_waiting: Is the command issued in block mode
> + * @retry_count: Retry count for retriable commands
> + * @host_tag: Host tag used by the command
> + * @callback: Callback for non blocking commands
> + */
> +struct mpi3mr_drv_cmd {
> +	struct mutex mutex;
> +	struct completion done;
> +	void *reply;
> +	u8 *sensebuf;
> +	u16 state;
> +	u16 dev_handle;
> +	u16 ioc_status;
> +	u32 ioc_loginfo;
> +	u8 is_waiting;
> +	u8 retry_count;
> +	u16 host_tag;
> +	DRV_CMD_CALLBACK callback;
> +};
> +
> +
> +/**
> + * struct chain_element - memory descriptor structure to store
> + * virtual and dma addresses for chain elements.
> + *
> + * @addr: virtual address
> + * @dma_addr: dma address
> + */
> +struct chain_element {
> +	void *addr;
> +	dma_addr_t dma_addr;
> +};
> +
> +/**
> + * struct scmd_priv - SCSI command private data
> + *
> + * @host_tag: Host tag specific to operational queue
> + * @in_lld_scope: Command in LLD scope or not
> + * @scmd: SCSI Command pointer
> + * @req_q_idx: Operational request queue index
> + * @chain_idx: Chain frame index
> + * @mpi3mr_scsiio_req: MPI SCSI IO request
> + */
> +struct scmd_priv {
> +	u16 host_tag;
> +	u8 in_lld_scope;
> +	struct scsi_cmnd *scmd;
> +	u16 req_q_idx;
> +	int chain_idx;
> +	u8 mpi3mr_scsiio_req[MPI3MR_ADMIN_REQ_FRAME_SZ];
> +};
> +
> +/**
> + * struct mpi3mr_ioc - Adapter anchor structure stored in shost
> + * private data
> + *
> + * @list: List pointer
> + * @pdev: PCI device pointer
> + * @shost: Scsi_Host pointer
> + * @id: Controller ID
> + * @cpu_count: Number of online CPUs
> + * @name: Controller ASCII name
> + * @driver_name: Driver ASCII name
> + * @sysif_regs: System interface registers virtual address
> + * @sysif_regs_phys: System interface registers physical address
> + * @bars: PCI BARS
> + * @dma_mask: DMA mask
> + * @msix_count: Number of MSIX vectors used
> + * @intr_enabled: Is interrupts enabled
> + * @num_admin_req: Number of admin requests
> + * @admin_req_q_sz: Admin request queue size
> + * @admin_req_pi: Admin request queue producer index
> + * @admin_req_ci: Admin request queue consumer index
> + * @admin_req_base: Admin request queue base virtual address
> + * @admin_req_dma: Admin request queue base dma address
> + * @admin_req_lock: Admin queue access lock
> + * @num_admin_replies: Number of admin replies
> + * @admin_reply_q_sz: Admin reply queue size
> + * @admin_reply_ci: Admin reply queue consumer index
> + * @admin_reply_ephase:Admin reply queue expected phase
> + * @admin_reply_base: Admin reply queue base virtual address
> + * @admin_reply_dma: Admin reply queue base dma address
> + * @ready_timeout: Controller ready timeout
> + * @intr_info: Interrupt cookie pointer
> + * @intr_info_count: Number of interrupt cookies
> + * @num_queues: Number of operational queues
> + * @num_op_req_q: Number of operational request queues
> + * @req_qinfo: Operational request queue info pointer
> + * @num_op_reply_q: Number of operational reply queues
> + * @op_reply_qinfo: Operational reply queue info pointer
> + * @init_cmds: Command tracker for initialization commands
> + * @facts: Cached IOC facts data
> + * @op_reply_desc_sz: Operational reply descriptor size
> + * @num_reply_bufs: Number of reply buffers allocated
> + * @reply_buf_pool: Reply buffer pool
> + * @reply_buf: Reply buffer base virtual address
> + * @reply_buf_dma: Reply buffer DMA address
> + * @reply_buf_dma_max_address: Reply DMA address max limit
> + * @reply_free_qsz: Reply free queue size
> + * @reply_free_q_pool: Reply free queue pool
> + * @reply_free_q: Reply free queue base virtual address
> + * @reply_free_q_dma: Reply free queue base DMA address
> + * @reply_free_queue_lock: Reply free queue lock
> + * @reply_free_queue_host_index: Reply free queue host index
> + * @num_sense_bufs: Number of sense buffers
> + * @sense_buf_pool: Sense buffer pool
> + * @sense_buf: Sense buffer base virtual address
> + * @sense_buf_dma: Sense buffer base DMA address
> + * @sense_buf_q_sz: Sense buffer queue size
> + * @sense_buf_q_pool: Sense buffer queue pool
> + * @sense_buf_q: Sense buffer queue virtual address
> + * @sense_buf_q_dma: Sense buffer queue DMA address
> + * @sbq_lock: Sense buffer queue lock
> + * @sbq_host_index: Sense buffer queuehost index
> + * @is_driver_loading: Is driver still loading
> + * @max_host_ios: Maximum host I/O count
> + * @chain_buf_count: Chain buffer count
> + * @chain_buf_pool: Chain buffer pool
> + * @chain_sgl_list: Chain SGL list
> + * @chain_bitmap_sz: Chain buffer allocator bitmap size
> + * @chain_bitmap: Chain buffer allocator bitmap
> + * @reset_in_progress: Reset in progress flag
> + * @unrecoverable: Controller unrecoverable flag
> + * @logging_level: Controller debug logging level
> + * @current_event: Firmware event currently in process
> + * @driver_info: Driver, Kernel, OS information to firmware
> + * @change_count: Topology change count
> + */
> +struct mpi3mr_ioc {
> +	struct list_head list;
> +	struct pci_dev *pdev;
> +	struct Scsi_Host *shost;
> +	u8 id;
> +	int cpu_count;
> +
> +	char name[MPI3MR_NAME_LENGTH];
> +	char driver_name[MPI3MR_NAME_LENGTH];
> +
> +	Mpi3SysIfRegs_t __iomem *sysif_regs;
> +	resource_size_t sysif_regs_phys;
> +	int bars;
> +	u64 dma_mask;
> +
> +	u16 msix_count;
> +	u8 intr_enabled;
> +
> +	u16 num_admin_req;
> +	u32 admin_req_q_sz;
> +	u16 admin_req_pi;
> +	u16 admin_req_ci;
> +	void *admin_req_base;
> +	dma_addr_t admin_req_dma;
> +	spinlock_t admin_req_lock;
> +
> +	u16 num_admin_replies;
> +	u32 admin_reply_q_sz;
> +	u16 admin_reply_ci;
> +	u8 admin_reply_ephase;
> +	void *admin_reply_base;
> +	dma_addr_t admin_reply_dma;
> +
> +	u32 ready_timeout;
> +
> +	struct mpi3mr_intr_info *intr_info;

Please, be consistent.
If you must introduce typedefs for your internal structures, okay.
But then introduce typedefs for _all_ internal structures.
Or leave the typedefs and just use 'struct XXX'; which actually is the
recommended way for linux.

> +	u16 intr_info_count;
> +
> +	u16 num_queues;
> +	u16 num_op_req_q;
> +	struct op_req_qinfo *req_qinfo;
> +
> +	u16 num_op_reply_q;
> +	struct op_reply_qinfo *op_reply_qinfo;
> +
> +	struct mpi3mr_drv_cmd init_cmds;
> +	struct mpi3mr_ioc_facts facts;
> +	u16 op_reply_desc_sz;
> +
> +	u32 num_reply_bufs;
> +	struct dma_pool *reply_buf_pool;
> +	u8 *reply_buf;
> +	dma_addr_t reply_buf_dma;
> +	dma_addr_t reply_buf_dma_max_address;
> +
> +	u16 reply_free_qsz;
> +	struct dma_pool *reply_free_q_pool;
> +	U64 *reply_free_q;
> +	dma_addr_t reply_free_q_dma;
> +	spinlock_t reply_free_queue_lock;
> +	u32 reply_free_queue_host_index;
> +
> +	u32 num_sense_bufs;
> +	struct dma_pool *sense_buf_pool;
> +	u8 *sense_buf;
> +	dma_addr_t sense_buf_dma;
> +
> +	u16 sense_buf_q_sz;
> +	struct dma_pool *sense_buf_q_pool;
> +	U64 *sense_buf_q;
> +	dma_addr_t sense_buf_q_dma;
> +	spinlock_t sbq_lock;
> +	u32 sbq_host_index;
> +
> +	u8 is_driver_loading;
> +
> +	u16 max_host_ios;
> +
> +	u32 chain_buf_count;
> +	struct dma_pool *chain_buf_pool;
> +	struct chain_element *chain_sgl_list;
> +	u16  chain_bitmap_sz;
> +	void *chain_bitmap;
> +
> +	u8 reset_in_progress;
> +	u8 unrecoverable;
> +
> +	int logging_level;
> +
> +	struct mpi3mr_fwevt *current_event;
> +	Mpi3DriverInfoLayout_t driver_info;

See my comment about struct typedefs above.

> +	u16 change_count;
> +};
> +
> +int mpi3mr_setup_resources(struct mpi3mr_ioc *mrioc);
> +void mpi3mr_cleanup_resources(struct mpi3mr_ioc *mrioc);
> +int mpi3mr_init_ioc(struct mpi3mr_ioc *mrioc);
> +void mpi3mr_cleanup_ioc(struct mpi3mr_ioc *mrioc);
> +int mpi3mr_admin_request_post(struct mpi3mr_ioc *mrioc, void *admin_req,
> +u16 admin_req_sz, u8 ignore_reset);
> +void mpi3mr_add_sg_single(void *paddr, u8 flags, u32 length,
> +			  dma_addr_t dma_addr);
> +void mpi3mr_build_zero_len_sge(void *paddr);
> +void *mpi3mr_get_sensebuf_virt_addr(struct mpi3mr_ioc *mrioc,
> +				     dma_addr_t phys_addr);
> +void *mpi3mr_get_reply_virt_addr(struct mpi3mr_ioc *mrioc,
> +				     dma_addr_t phys_addr);
> +void mpi3mr_repost_sense_buf(struct mpi3mr_ioc *mrioc,
> +				     u64 sense_buf_dma);
> +
> +void mpi3mr_start_watchdog(struct mpi3mr_ioc *mrioc);
> +void mpi3mr_stop_watchdog(struct mpi3mr_ioc *mrioc);
> +
> +int mpi3mr_soft_reset_handler(struct mpi3mr_ioc *mrioc,
> +			      u32 reset_reason, u8 snapdump);
> +void mpi3mr_ioc_disable_intr(struct mpi3mr_ioc *mrioc);
> +void mpi3mr_ioc_enable_intr(struct mpi3mr_ioc *mrioc);
> +
> +enum mpi3mr_iocstate mpi3mr_get_iocstate(struct mpi3mr_ioc *mrioc);
> +
> +#endif /*MPI3MR_H_INCLUDED*/
> diff --git a/drivers/scsi/mpi3mr/mpi3mr_debug.h b/drivers/scsi/mpi3mr/mpi3mr_debug.h
> new file mode 100644
> index 000000000000..d35f296d9325
> --- /dev/null
> +++ b/drivers/scsi/mpi3mr/mpi3mr_debug.h
> @@ -0,0 +1,60 @@
> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> +/*
> + * Driver for Broadcom MPI3 Storage Controllers
> + *
> + * Copyright (C) 2017-2020 Broadcom Inc.
> + *  (mailto: mpi3mr-linuxdrv.pdl@broadcom.com)
> + *
> + */
> +
> +#ifndef MPI3SAS_DEBUG_H_INCLUDED
> +
> +#define MPI3SAS_DEBUG_H_INCLUDED
> +
> +/*
> + * debug levels
> + */
> +#define MPI3_DEBUG			0x00000001
> +#define MPI3_DEBUG_MSG_FRAME		0x00000002
> +#define MPI3_DEBUG_SG			0x00000004
> +#define MPI3_DEBUG_EVENTS		0x00000008
> +#define MPI3_DEBUG_EVENT_WORK_TASK	0x00000010
> +#define MPI3_DEBUG_INIT			0x00000020
> +#define MPI3_DEBUG_EXIT			0x00000040
> +#define MPI3_DEBUG_FAIL			0x00000080
> +#define MPI3_DEBUG_TM			0x00000100
> +#define MPI3_DEBUG_REPLY		0x00000200
> +#define MPI3_DEBUG_HANDSHAKE		0x00000400
> +#define MPI3_DEBUG_CONFIG		0x00000800
> +#define MPI3_DEBUG_DL			0x00001000
> +#define MPI3_DEBUG_RESET		0x00002000
> +#define MPI3_DEBUG_SCSI			0x00004000
> +#define MPI3_DEBUG_IOCTL		0x00008000
> +#define MPI3_DEBUG_CSMISAS		0x00010000
> +#define MPI3_DEBUG_SAS			0x00020000
> +#define MPI3_DEBUG_TRANSPORT		0x00040000
> +#define MPI3_DEBUG_TASK_SET_FULL	0x00080000
> +#define MPI3_DEBUG_TRIGGER_DIAG		0x00200000
> +
> +
> +/*
> + * debug macros
> + */
> +
> +#define ioc_err(ioc, fmt, ...) \
> +	pr_err("%s: " fmt, (ioc)->name, ##__VA_ARGS__)
> +#define ioc_notice(ioc, fmt, ...) \
> +	pr_notice("%s: " fmt, (ioc)->name, ##__VA_ARGS__)
> +#define ioc_warn(ioc, fmt, ...) \
> +	pr_warn("%s: " fmt, (ioc)->name, ##__VA_ARGS__)
> +#define ioc_info(ioc, fmt, ...) \
> +	pr_info("%s: " fmt, (ioc)->name, ##__VA_ARGS__)
> +
> +
> +#define dbgprint(IOC, FMT, ...) \
> +	do { \
> +		if (IOC->logging_level & MPI3_DEBUG) \
> +			pr_info("%s: " FMT, (IOC)->name, ##__VA_ARGS__); \
> +	} while (0)
> +
> +#endif /* MPT3SAS_DEBUG_H_INCLUDED */
> diff --git a/drivers/scsi/mpi3mr/mpi3mr_fw.c b/drivers/scsi/mpi3mr/mpi3mr_fw.c
> new file mode 100644
> index 000000000000..97eb7e6ec5c6
> --- /dev/null
> +++ b/drivers/scsi/mpi3mr/mpi3mr_fw.c
> @@ -0,0 +1,1819 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Driver for Broadcom MPI3 Storage Controllers
> + *
> + * Copyright (C) 2017-2020 Broadcom Inc.
> + *  (mailto: mpi3mr-linuxdrv.pdl@broadcom.com)
> + *
> + */
> +
> +#include "mpi3mr.h"
> +
> +#if defined(writeq) && defined(CONFIG_64BIT)
> +static inline void mpi3mr_writeq(__u64 b, volatile void __iomem *addr)
> +{
> +	writeq(b, addr);
> +}
> +#else
> +static inline void mpi3mr_writeq(__u64 b, volatile void __iomem *addr)
> +{
> +	__u64 data_out = b;
> +
> +	writel((u32)(data_out), addr);
> +	writel((u32)(data_out >> 32), (addr + 4));
> +}
> +#endif
> +
> +static void mpi3mr_sync_irqs(struct mpi3mr_ioc *mrioc)
> +{
> +	u16 i, max_vectors;
> +
> +	max_vectors = mrioc->intr_info_count;
> +
> +	for (i = 0; i < max_vectors; i++)
> +		synchronize_irq(pci_irq_vector(mrioc->pdev, i));
> +}
> +
> +void mpi3mr_ioc_disable_intr(struct mpi3mr_ioc *mrioc)
> +{
> +	mrioc->intr_enabled = 0;
> +	mpi3mr_sync_irqs(mrioc);
> +}
> +
> +void mpi3mr_ioc_enable_intr(struct mpi3mr_ioc *mrioc)
> +{
> +	mrioc->intr_enabled = 1;
> +}
> +
> +static void mpi3mr_cleanup_isr(struct mpi3mr_ioc *mrioc)
> +{
> +	u16 i;
> +
> +	mpi3mr_ioc_disable_intr(mrioc);
> +
> +	if (!mrioc->intr_info)
> +		return;
> +
> +	for (i = 0; i < mrioc->intr_info_count; i++)
> +		free_irq(pci_irq_vector(mrioc->pdev, i),
> +		    (mrioc->intr_info + i));
> +
> +	kfree(mrioc->intr_info);
> +	mrioc->intr_info = NULL;
> +	mrioc->intr_info_count = 0;
> +	pci_free_irq_vectors(mrioc->pdev);
> +}
> +
> +void mpi3mr_add_sg_single(void *paddr, u8 flags, u32 length,
> +	dma_addr_t dma_addr)
> +{
> +	Mpi3SGESimple_t *sgel = paddr;
> +
> +	sgel->Flags = flags;
> +	sgel->Length = cpu_to_le32(length);
> +	sgel->Address = cpu_to_le64(dma_addr);
> +}
> +
> +void mpi3mr_build_zero_len_sge(void *paddr)
> +{
> +	u8 sgl_flags = MPI3MR_SGEFLAGS_SYSTEM_SIMPLE_END_OF_LIST;
> +
> +	mpi3mr_add_sg_single(paddr, sgl_flags, 0, -1);
> +
> +}
> +void *mpi3mr_get_reply_virt_addr(struct mpi3mr_ioc *mrioc,
> +	dma_addr_t phys_addr)
> +{
> +	if (!phys_addr)
> +		return NULL;
> +
> +	if ((phys_addr < mrioc->reply_buf_dma) ||
> +	    (phys_addr > mrioc->reply_buf_dma_max_address))
> +		return NULL;
> +
> +	return mrioc->reply_buf + (phys_addr - mrioc->reply_buf_dma);
> +}
> +
> +void *mpi3mr_get_sensebuf_virt_addr(struct mpi3mr_ioc *mrioc,
> +	dma_addr_t phys_addr)
> +{
> +	if (!phys_addr)
> +		return NULL;
> +
> +	return mrioc->sense_buf + (phys_addr - mrioc->sense_buf_dma);
> +}
> +
> +static void mpi3mr_repost_reply_buf(struct mpi3mr_ioc *mrioc,
> +	u64 reply_dma)
> +{
> +	u32 old_idx = 0;
> +
> +	spin_lock(&mrioc->reply_free_queue_lock);
> +	old_idx  =  mrioc->reply_free_queue_host_index;
> +	mrioc->reply_free_queue_host_index = (
> +	    (mrioc->reply_free_queue_host_index ==
> +	    (mrioc->reply_free_qsz - 1)) ? 0 :
> +	    (mrioc->reply_free_queue_host_index + 1));
> +	mrioc->reply_free_q[old_idx] = cpu_to_le64(reply_dma);
> +	writel(mrioc->reply_free_queue_host_index,
> +	    &mrioc->sysif_regs->ReplyFreeHostIndex);
> +	spin_unlock(&mrioc->reply_free_queue_lock);
> +}
> +
> +void mpi3mr_repost_sense_buf(struct mpi3mr_ioc *mrioc,
> +	u64 sense_buf_dma)
> +{
> +	u32 old_idx = 0;
> +
> +	spin_lock(&mrioc->sbq_lock);
> +	old_idx  =  mrioc->sbq_host_index;
> +	mrioc->sbq_host_index = ((mrioc->sbq_host_index ==
> +	    (mrioc->sense_buf_q_sz - 1)) ? 0 :
> +	    (mrioc->sbq_host_index + 1));
> +	mrioc->sense_buf_q[old_idx] = cpu_to_le64(sense_buf_dma);
> +	writel(mrioc->sbq_host_index,
> +	    &mrioc->sysif_regs->SenseBufferFreeHostIndex);
> +	spin_unlock(&mrioc->sbq_lock);
> +}
> +
> +static void mpi3mr_handle_events(struct mpi3mr_ioc *mrioc,
> +	Mpi3DefaultReply_t *def_reply)
> +{
> +	Mpi3EventNotificationReply_t *event_reply =
> +	    (Mpi3EventNotificationReply_t *)def_reply;
> +
> +	mrioc->change_count = le16_to_cpu(event_reply->IOCChangeCount);
> +}
> +
> +static struct mpi3mr_drv_cmd *
> +mpi3mr_get_drv_cmd(struct mpi3mr_ioc *mrioc, u16 host_tag,
> +	Mpi3DefaultReply_t *def_reply)
> +{
> +	switch (host_tag) {
> +	case MPI3MR_HOSTTAG_INITCMDS:
> +		return &mrioc->init_cmds;
> +	case MPI3MR_HOSTTAG_INVALID:
> +		if (def_reply && def_reply->Function ==
> +		    MPI3_FUNCTION_EVENT_NOTIFICATION)
> +			mpi3mr_handle_events(mrioc, def_reply);
> +		return NULL;
> +	default:
> +		break;
> +	}
> +
> +	return NULL;
> +}
> +
> +static void mpi3mr_process_admin_reply_desc(struct mpi3mr_ioc *mrioc,
> +	Mpi3DefaultReplyDescriptor_t *reply_desc, u64 *reply_dma)
> +{
> +	u16 reply_desc_type, host_tag = 0;
> +	u16 ioc_status = MPI3_IOCSTATUS_SUCCESS;
> +	u32 ioc_loginfo = 0;
> +	Mpi3StatusReplyDescriptor_t *status_desc;
> +	Mpi3AddressReplyDescriptor_t *addr_desc;
> +	Mpi3SuccessReplyDescriptor_t *success_desc;
> +	Mpi3DefaultReply_t *def_reply = NULL;
> +	struct mpi3mr_drv_cmd *cmdptr = NULL;
> +	Mpi3SCSIIOReply_t *scsi_reply;
> +	u8 *sense_buf = NULL;
> +
> +	*reply_dma = 0;
> +	reply_desc_type = le16_to_cpu(reply_desc->ReplyFlags) &
> +	    MPI3_REPLY_DESCRIPT_FLAGS_TYPE_MASK;
> +	switch (reply_desc_type) {
> +	case MPI3_REPLY_DESCRIPT_FLAGS_TYPE_STATUS:
> +		status_desc = (Mpi3StatusReplyDescriptor_t *)reply_desc;
> +		host_tag = le16_to_cpu(status_desc->HostTag);
> +		ioc_status = le16_to_cpu(status_desc->IOCStatus);
> +		if (ioc_status &
> +		    MPI3_REPLY_DESCRIPT_STATUS_IOCSTATUS_LOGINFOAVAIL)
> +			ioc_loginfo = le32_to_cpu(status_desc->IOCLogInfo);
> +		ioc_status &= MPI3_REPLY_DESCRIPT_STATUS_IOCSTATUS_STATUS_MASK;
> +		break;
> +	case MPI3_REPLY_DESCRIPT_FLAGS_TYPE_ADDRESS_REPLY:
> +		addr_desc = (Mpi3AddressReplyDescriptor_t *)reply_desc;
> +		*reply_dma = le64_to_cpu(addr_desc->ReplyFrameAddress);
> +		def_reply = mpi3mr_get_reply_virt_addr(mrioc, *reply_dma);
> +		if (!def_reply)
> +			goto out;
> +		host_tag = le16_to_cpu(def_reply->HostTag);
> +		ioc_status = le16_to_cpu(def_reply->IOCStatus);
> +		if (ioc_status &
> +		    MPI3_REPLY_DESCRIPT_STATUS_IOCSTATUS_LOGINFOAVAIL)
> +			ioc_loginfo = le32_to_cpu(def_reply->IOCLogInfo);
> +		ioc_status &= MPI3_REPLY_DESCRIPT_STATUS_IOCSTATUS_STATUS_MASK;
> +		if (def_reply->Function == MPI3_FUNCTION_SCSI_IO) {
> +			scsi_reply = (Mpi3SCSIIOReply_t *)def_reply;
> +			sense_buf = mpi3mr_get_sensebuf_virt_addr(mrioc,
> +			    le64_to_cpu(scsi_reply->SenseDataBufferAddress));
> +		}
> +		break;
> +	case MPI3_REPLY_DESCRIPT_FLAGS_TYPE_SUCCESS:
> +		success_desc = (Mpi3SuccessReplyDescriptor_t *)reply_desc;
> +		host_tag = le16_to_cpu(success_desc->HostTag);
> +		break;
> +	default:
> +		break;
> +	}
> +
> +	cmdptr = mpi3mr_get_drv_cmd(mrioc, host_tag, def_reply);
> +	if (cmdptr) {
> +		if (cmdptr->state & MPI3MR_CMD_PENDING) {
> +			cmdptr->state |= MPI3MR_CMD_COMPLETE;
> +			cmdptr->ioc_loginfo = ioc_loginfo;
> +			cmdptr->ioc_status = ioc_status;
> +			cmdptr->state &= ~MPI3MR_CMD_PENDING;
> +			if (def_reply) {
> +				cmdptr->state |= MPI3MR_CMD_REPLY_VALID;
> +				memcpy((u8 *)cmdptr->reply, (u8 *)def_reply,
> +				    mrioc->facts.reply_sz);
> +			}
> +			if (cmdptr->is_waiting) {
> +				complete(&cmdptr->done);
> +				cmdptr->is_waiting = 0;
> +			} else if (cmdptr->callback)
> +				cmdptr->callback(mrioc, cmdptr);
> +		}
> +	}
> +out:
> +	if (sense_buf)
> +		mpi3mr_repost_sense_buf(mrioc,
> +		    le64_to_cpu(scsi_reply->SenseDataBufferAddress));
> +}
> +
> +static int mpi3mr_process_admin_reply_q(struct mpi3mr_ioc *mrioc)
> +{
> +	u32 exp_phase = mrioc->admin_reply_ephase;
> +	u32 admin_reply_ci = mrioc->admin_reply_ci;
> +	u32 num_admin_replies = 0;
> +	u64 reply_dma = 0;
> +	Mpi3DefaultReplyDescriptor_t *reply_desc;
> +
> +	reply_desc = (Mpi3DefaultReplyDescriptor_t *)mrioc->admin_reply_base +
> +	    admin_reply_ci;
> +
> +	if ((le16_to_cpu(reply_desc->ReplyFlags) &
> +	    MPI3_REPLY_DESCRIPT_FLAGS_PHASE_MASK) != exp_phase)
> +		return 0;
> +
> +	do {
> +		mrioc->admin_req_ci = le16_to_cpu(reply_desc->RequestQueueCI);
> +		mpi3mr_process_admin_reply_desc(mrioc, reply_desc, &reply_dma);
> +		if (reply_dma)
> +			mpi3mr_repost_reply_buf(mrioc, reply_dma);
> +		num_admin_replies++;
> +		if (++admin_reply_ci == mrioc->num_admin_replies) {
> +			admin_reply_ci = 0;
> +			exp_phase ^= 1;
> +		}
> +		reply_desc =
> +		    (Mpi3DefaultReplyDescriptor_t *)mrioc->admin_reply_base +
> +		    admin_reply_ci;
> +		if ((le16_to_cpu(reply_desc->ReplyFlags) &
> +		    MPI3_REPLY_DESCRIPT_FLAGS_PHASE_MASK) != exp_phase)
> +			break;
> +	} while (1);
> +
> +	writel(admin_reply_ci, &mrioc->sysif_regs->AdminReplyQueueCI);
> +	mrioc->admin_reply_ci = admin_reply_ci;
> +	mrioc->admin_reply_ephase = exp_phase;
> +
> +	return num_admin_replies;
> +}
> +
> +static irqreturn_t mpi3mr_isr_primary(int irq, void *privdata)
> +{
> +	struct mpi3mr_intr_info *intr_info = privdata;
> +	struct mpi3mr_ioc *mrioc;
> +	u16 midx;
> +	u32 num_admin_replies = 0;
> +
> +	if (!intr_info)
> +		return IRQ_NONE;
> +
> +	mrioc = intr_info->mrioc;
> +
> +	if (!mrioc->intr_enabled)
> +		return IRQ_NONE;
> +
> +	midx = intr_info->msix_index;
> +
> +	if (!midx)
> +		num_admin_replies = mpi3mr_process_admin_reply_q(mrioc);
> +
> +	if (num_admin_replies)
> +		return IRQ_HANDLED;
> +	else
> +		return IRQ_NONE;
> +}
> +
> +static irqreturn_t mpi3mr_isr(int irq, void *privdata)
> +{
> +	struct mpi3mr_intr_info *intr_info = privdata;
> +	struct mpi3mr_ioc *mrioc;
> +	u16 midx;
> +	int ret;
> +
> +	if (!intr_info)
> +		return IRQ_NONE;
> +
> +	mrioc = intr_info->mrioc;
> +	midx = intr_info->msix_index;
> +	/* Call primary ISR routine */
> +	ret = mpi3mr_isr_primary(irq, privdata);
> +
> +	return ret;
> +}
> +
> +/**
> + * mpi3mr_isr_poll - Reply queue polling routine
> + * @irq: IRQ
> + * @privdata: Interrupt info
> + *
> + * poll for pending I/O completions in a loop until pending I/Os
> + * present or controller queue depth I/Os are processed.
> + *
> + * Return: IRQ_NONE or IRQ_HANDLED
> + */
> +static irqreturn_t mpi3mr_isr_poll(int irq, void *privdata)
> +{
> +	return IRQ_HANDLED;
> +}
> +
> +/**
> + * mpi3mr_request_irq - Request IRQ and register ISR
> + * @mrioc: Adapter instance reference
> + * @index: IRQ vector index
> + *
> + * Request threaded ISR with primary ISR and secondary
> + *
> + * Return: 0 on success and non zero on failures.
> + */
> +static inline int mpi3mr_request_irq(struct mpi3mr_ioc *mrioc, u16 index)
> +{
> +	struct pci_dev *pdev = mrioc->pdev;
> +	struct mpi3mr_intr_info *intr_info = mrioc->intr_info + index;
> +	int retval = 0;
> +
> +	intr_info->mrioc = mrioc;
> +	intr_info->msix_index = index;
> +	intr_info->op_reply_q = NULL;
> +
> +	snprintf(intr_info->name, MPI3MR_NAME_LENGTH, "%s%d-msix%d",
> +	    mrioc->driver_name, mrioc->id, index);
> +
> +	retval = request_threaded_irq(pci_irq_vector(pdev, index), mpi3mr_isr,
> +	    mpi3mr_isr_poll, IRQF_ONESHOT, intr_info->name, intr_info);
> +	if (retval) {
> +		ioc_err(mrioc, "%s: Unable to allocate interrupt %d!\n",
> +		    intr_info->name, pci_irq_vector(pdev, index));
> +		return retval;
> +	}
> +

The point of having 'mpi3mr_isr_poll()' here is what exactly?

> +	return retval;
> +}
> +
> +/**
> + * mpi3mr_setup_isr - Setup ISR for the controller
> + * @mrioc: Adapter instance reference
> + * @setup_one: Request one IRQ or more
> + *
> + * Allocate IRQ vectors and call mpi3mr_request_irq to setup ISR
> + *
> + * Return: 0 on success and non zero on failures.
> + */
> +static int mpi3mr_setup_isr(struct mpi3mr_ioc *mrioc, u8 setup_one)
> +{
> +	unsigned int irq_flags = PCI_IRQ_MSIX;
> +	u16 max_vectors = 0, i;
> +	int retval = 0;
> +	struct irq_affinity desc = { .pre_vectors =  1};
> +
> +
> +	mpi3mr_cleanup_isr(mrioc);
> +
> +	if (setup_one || reset_devices)
> +		max_vectors = 1;
> +	else {
> +		max_vectors =
> +		    min_t(int, mrioc->cpu_count + 1, mrioc->msix_count);
> +
> +		ioc_info(mrioc,
> +		    "MSI-X vectors supported: %d, no of cores: %d,",
> +		    mrioc->msix_count, mrioc->cpu_count);
> +		ioc_info(mrioc,
> +		    "MSI-x vectors requested: %d\n", max_vectors);
> +	}
> +
> +	irq_flags |= PCI_IRQ_AFFINITY | PCI_IRQ_ALL_TYPES;
> +
> +	i = pci_alloc_irq_vectors_affinity(mrioc->pdev,
> +	    1, max_vectors, irq_flags, &desc);
> +	if (i <= 0) {
> +		ioc_err(mrioc, "Cannot alloc irq vectors\n");
> +		goto out_failed;
> +	}
> +	if (i != max_vectors) {
> +		ioc_info(mrioc,
> +		    "allocated vectors (%d) are less than configured (%d)\n",
> +		    i, max_vectors);
> +
> +		max_vectors = i;
> +	}
> +	mrioc->intr_info = kzalloc(sizeof(struct mpi3mr_intr_info)*max_vectors,
> +	    GFP_KERNEL);
> +	if (!mrioc->intr_info) {
> +		retval = -1;
> +		pci_free_irq_vectors(mrioc->pdev);
> +		goto out_failed;
> +	}
> +	for (i = 0; i < max_vectors; i++) {
> +		retval = mpi3mr_request_irq(mrioc, i);
> +		if (retval) {
> +			mrioc->intr_info_count = i;
> +			goto out_failed;
> +		}
> +	}
> +	mrioc->intr_info_count = max_vectors;
> +	mpi3mr_ioc_enable_intr(mrioc);
> +	return retval;
> +out_failed:
> +	mpi3mr_cleanup_isr(mrioc);
> +
> +	return retval;
> +}
> +
> +static const struct {
> +	enum mpi3mr_iocstate value;
> +	char *name;
> +} mrioc_states[] = {
> +	{ MRIOC_STATE_READY, "ready" },
> +	{ MRIOC_STATE_FAULT, "fault" },
> +	{ MRIOC_STATE_RESET, "reset" },
> +	{ MRIOC_STATE_BECOMING_READY, "becoming ready" },
> +	{ MRIOC_STATE_RESET_REQUESTED, "reset requested" },
> +	{ MRIOC_STATE_UNRECOVERABLE, "unrecoverable error" },
> +};
> +
> +static const char *mpi3mr_iocstate_name(enum mpi3mr_iocstate mrioc_state)
> +{
> +	int i;
> +	char *name = NULL;
> +
> +	for (i = 0; i < ARRAY_SIZE(mrioc_states); i++) {
> +		if (mrioc_states[i].value == mrioc_state) {
> +			name = mrioc_states[i].name;
> +			break;
> +		}
> +	}
> +	return name;
> +}
> +
> +
> +/**
> + * mpi3mr_print_fault_info - Display fault information
> + * @mrioc: Adapter instance reference
> + *
> + * Display the controller fault information if there is a
> + * controller fault.
> + *
> + * Return: Nothing.
> + */
> +static void mpi3mr_print_fault_info(struct mpi3mr_ioc *mrioc)
> +{
> +	u32 ioc_status, code, code1, code2, code3;
> +
> +	ioc_status = readl(&mrioc->sysif_regs->IOCStatus);
> +
> +	if (ioc_status & MPI3_SYSIF_IOC_STATUS_FAULT) {
> +		code = readl(&mrioc->sysif_regs->Fault);
> +		code1 = readl(&mrioc->sysif_regs->FaultInfo[0]);
> +		code2 = readl(&mrioc->sysif_regs->FaultInfo[1]);
> +		code3 = readl(&mrioc->sysif_regs->FaultInfo[2]);
> +
> +		ioc_info(mrioc,
> +		    "fault code(0x%08X): Additional code: (0x%08X:0x%08X:0x%08X)\n",
> +		    code, code1, code2, code3);
> +	}
> +}
> +
> +/**
> + * mpi3mr_get_iocstate - Get IOC State
> + * @mrioc: Adapter instance reference
> + *
> + * Return a proper IOC state enum based on the IOC status and
> + * IOC configuration and unrcoverable state of the controller.
> + *
> + * Return: Current IOC state.
> + */
> +enum mpi3mr_iocstate mpi3mr_get_iocstate(struct mpi3mr_ioc *mrioc)
> +{
> +	u32 ioc_status, ioc_config;
> +	u8 ready, enabled;
> +
> +	ioc_status = readl(&mrioc->sysif_regs->IOCStatus);
> +	ioc_config = readl(&mrioc->sysif_regs->IOCConfiguration);
> +
> +	if (mrioc->unrecoverable)
> +		return MRIOC_STATE_UNRECOVERABLE;
> +	if (ioc_status & MPI3_SYSIF_IOC_STATUS_FAULT)
> +		return MRIOC_STATE_FAULT;
> +
> +	ready = (ioc_status & MPI3_SYSIF_IOC_STATUS_READY);
> +	enabled = (ioc_config & MPI3_SYSIF_IOC_CONFIG_ENABLE_IOC);
> +
> +	if (ready && enabled)
> +		return MRIOC_STATE_READY;
> +	if ((!ready) && (!enabled))
> +		return MRIOC_STATE_RESET;
> +	if ((!ready) && (enabled))
> +		return MRIOC_STATE_BECOMING_READY;
> +
> +	return MRIOC_STATE_RESET_REQUESTED;
> +}
> +
> +/**
> + * mpi3mr_clear_reset_history - Clear reset history
> + * @mrioc: Adapter instance reference
> + *
> + * Write the reset history bit in IOC Status to clear the bit,
> + * if it is already set.
> + *
> + * Return: Nothing.
> + */
> +static inline void mpi3mr_clear_reset_history(struct mpi3mr_ioc *mrioc)
> +{
> +	u32 ioc_status;
> +
> +	ioc_status = readl(&mrioc->sysif_regs->IOCStatus);
> +	if (ioc_status & MPI3_SYSIF_IOC_STATUS_RESET_HISTORY)
> +		writel(ioc_status, &mrioc->sysif_regs->IOCStatus);
> +
> +}
> +
> +/**
> + * mpi3mr_issue_and_process_mur - Message Unit Reset handler
> + * @mrioc: Adapter instance reference
> + * @reset_reason: Reset reason code
> + *
> + * Issue Message Unit Reset to the controller and wait for it to
> + * be complete.
> + *
> + * Return: 0 on success, -1 on failure.
> + */
> +static int mpi3mr_issue_and_process_mur(struct mpi3mr_ioc *mrioc,
> +					u32 reset_reason)
> +{
> +	u32 ioc_config, timeout, ioc_status;
> +	int retval = -1;
> +
> +	ioc_info(mrioc, "Issuing Message Unit Reset(MUR)\n");
> +	if (mrioc->unrecoverable) {
> +		ioc_info(mrioc, "IOC is unrecoverable MUR not issued\n");
> +		return retval;
> +	}
> +	mpi3mr_clear_reset_history(mrioc);
> +	writel(reset_reason, &mrioc->sysif_regs->Scratchpad[0]);
> +	ioc_config = readl(&mrioc->sysif_regs->IOCConfiguration);
> +	ioc_config &= ~MPI3_SYSIF_IOC_CONFIG_ENABLE_IOC;
> +	writel(ioc_config, &mrioc->sysif_regs->IOCConfiguration);
> +
> +	timeout = mrioc->ready_timeout * 10;
> +	do {
> +		ioc_status = readl(&mrioc->sysif_regs->IOCStatus);
> +		if ((ioc_status & MPI3_SYSIF_IOC_STATUS_RESET_HISTORY)) {
> +			mpi3mr_clear_reset_history(mrioc);
> +			ioc_config =
> +			    readl(&mrioc->sysif_regs->IOCConfiguration);
> +			if (!((ioc_status & MPI3_SYSIF_IOC_STATUS_READY) ||
> +			    (ioc_status & MPI3_SYSIF_IOC_STATUS_FAULT) ||
> +			    (ioc_config & MPI3_SYSIF_IOC_CONFIG_ENABLE_IOC))) {
> +				retval = 0;
> +				break;
> +			}
> +		}
> +		msleep(100);
> +	} while (--timeout);
> +
> +	ioc_status = readl(&mrioc->sysif_regs->IOCStatus);
> +	ioc_config = readl(&mrioc->sysif_regs->IOCConfiguration);
> +
> +	ioc_info(mrioc, "Base IOC Sts/Config after %s MUR is (0x%x)/(0x%x)\n",
> +	    (!retval) ? "successful" : "failed", ioc_status, ioc_config);
> +	return retval;
> +}
> +
> +/**
> + * mpi3mr_bring_ioc_ready - Bring controller to ready state
> + * @mrioc: Adapter instance reference
> + *
> + * Set Enable IOC bit in IOC configuration register and wait for
> + * the controller to become ready.
> + *
> + * Return: 0 on success, -1 on failure.
> + */
> +static int mpi3mr_bring_ioc_ready(struct mpi3mr_ioc *mrioc)
> +{
> +	u32 ioc_config, timeout;
> +	enum mpi3mr_iocstate current_state;
> +
> +	ioc_config = readl(&mrioc->sysif_regs->IOCConfiguration);
> +	ioc_config |= MPI3_SYSIF_IOC_CONFIG_ENABLE_IOC;
> +	writel(ioc_config, &mrioc->sysif_regs->IOCConfiguration);
> +
> +	timeout = mrioc->ready_timeout * 10;
> +	do {
> +		current_state = mpi3mr_get_iocstate(mrioc);
> +		if (current_state == MRIOC_STATE_READY)
> +			return 0;
> +		msleep(100);
> +	} while (--timeout);
> +
> +	return -1;
> +}
> +
> +/**
> + * mpi3mr_set_diagsave - Set diag save bit for snapdump
> + * @mrioc: Adapter reference
> + *
> + * Set diag save bit in IOC configuration register to enable
> + * snapdump.
> + *
> + * Return: Nothing.
> + */
> +static inline void mpi3mr_set_diagsave(struct mpi3mr_ioc *mrioc)
> +{
> +	u32 ioc_config;
> +
> +	ioc_config = readl(&mrioc->sysif_regs->IOCConfiguration);
> +	ioc_config |= MPI3_SYSIF_IOC_CONFIG_DIAG_SAVE;
> +	writel(ioc_config, &mrioc->sysif_regs->IOCConfiguration);
> +}
> +
> +/**
> + * mpi3mr_issue_reset - Issue reset to the controller
> + * @mrioc: Adapter reference
> + * @reset_type: Reset type
> + * @reset_reason: Reset reason code
> + *
> + * TBD
> + *
> + * Return: 0 on success, non-zero on failure.
> + */
> +static int mpi3mr_issue_reset(struct mpi3mr_ioc *mrioc, u16 reset_type,
> +	u32 reset_reason)
> +{
> +	return 0;
> +}
> +
> +/**
> + * mpi3mr_admin_request_post - Post request to admin queue
> + * @mrioc: Adapter reference
> + * @admin_req: MPI3 request
> + * @admin_req_sz: Request size
> + * @ignore_reset: Ignore reset in process
> + *
> + * Post the MPI3 request into admin request queue and
> + * inform the controller, if the queue is full return
> + * appropriate error.
> + *
> + * Return: 0 on success, non-zero on failure.
> + */
> +int mpi3mr_admin_request_post(struct mpi3mr_ioc *mrioc, void *admin_req,
> +	u16 admin_req_sz, u8 ignore_reset)
> +{
> +	u16 areq_pi = 0, areq_ci = 0, max_entries = 0;
> +	int retval = 0;
> +	unsigned long flags;
> +	u8 *areq_entry;
> +
> +
> +	if (mrioc->unrecoverable) {
> +		ioc_err(mrioc, "%s : Unrecoverable controller\n", __func__);
> +		return -EFAULT;
> +	}
> +
> +	spin_lock_irqsave(&mrioc->admin_req_lock, flags);
> +	areq_pi = mrioc->admin_req_pi;
> +	areq_ci = mrioc->admin_req_ci;
> +	max_entries = mrioc->num_admin_req;
> +	if ((areq_ci == (areq_pi + 1)) || ((!areq_ci) &&
> +	    (areq_pi == (max_entries - 1)))) {
> +		ioc_err(mrioc, "AdminReqQ full condition detected\n");
> +		retval = -EAGAIN;
> +		goto out;
> +	}
> +	if (!ignore_reset && mrioc->reset_in_progress) {
> +		ioc_err(mrioc, "AdminReqQ submit reset in progress\n");
> +		retval = -EAGAIN;
> +		goto out;
> +	}
> +	areq_entry = (u8 *)mrioc->admin_req_base +
> +	    (areq_pi * MPI3MR_ADMIN_REQ_FRAME_SZ);
> +	memset(areq_entry, 0, MPI3MR_ADMIN_REQ_FRAME_SZ);
> +	memcpy(areq_entry, (u8 *)admin_req, admin_req_sz);
> +
> +	if (++areq_pi == max_entries)
> +		areq_pi = 0;
> +	mrioc->admin_req_pi = areq_pi;
> +
> +	writel(mrioc->admin_req_pi, &mrioc->sysif_regs->AdminRequestQueuePI);
> +
> +out:
> +	spin_unlock_irqrestore(&mrioc->admin_req_lock, flags);
> +
> +	return retval;
> +}
> +

It might be an idea to have an 'admin' queue structure; keeping the
values all within the main IOC structure might cause cache misses and a
degraded performance.

> +
> +/**
> + * mpi3mr_setup_admin_qpair - Setup admin queue pair
> + * @mrioc: Adapter instance reference
> + *
> + * Allocate memory for admin queue pair if required and register
> + * the admin queue with the controller.
> + *
> + * Return: 0 on success, non-zero on failures.
> + */
> +static int mpi3mr_setup_admin_qpair(struct mpi3mr_ioc *mrioc)
> +{
> +	int retval = 0;
> +	u32 num_admin_entries = 0;
> +
> +	mrioc->admin_req_q_sz = MPI3MR_ADMIN_REQ_Q_SIZE;
> +	mrioc->num_admin_req = mrioc->admin_req_q_sz /
> +	    MPI3MR_ADMIN_REQ_FRAME_SZ;
> +	mrioc->admin_req_ci = mrioc->admin_req_pi = 0;
> +	mrioc->admin_req_base = NULL;
> +
> +	mrioc->admin_reply_q_sz = MPI3MR_ADMIN_REPLY_Q_SIZE;
> +	mrioc->num_admin_replies = mrioc->admin_reply_q_sz /
> +	    MPI3MR_ADMIN_REPLY_FRAME_SZ;
> +	mrioc->admin_reply_ci = 0;
> +	mrioc->admin_reply_ephase = 1;
> +	mrioc->admin_reply_base = NULL;
> +
> +	if (!mrioc->admin_req_base) {
> +		mrioc->admin_req_base = dma_alloc_coherent(&mrioc->pdev->dev,
> +		    mrioc->admin_req_q_sz, &mrioc->admin_req_dma, GFP_KERNEL);
> +
> +		if (!mrioc->admin_req_base) {
> +			retval = -1;
> +			goto out_failed;
> +		}
> +
> +		mrioc->admin_reply_base = dma_alloc_coherent(&mrioc->pdev->dev,
> +		    mrioc->admin_reply_q_sz, &mrioc->admin_reply_dma,
> +		    GFP_KERNEL);
> +
> +		if (!mrioc->admin_reply_base) {
> +			retval = -1;
> +			goto out_failed;
> +		}
> +
> +	}
> +
> +	num_admin_entries = (mrioc->num_admin_replies << 16) |
> +	    (mrioc->num_admin_req);
> +	writel(num_admin_entries, &mrioc->sysif_regs->AdminQueueNumEntries);
> +	mpi3mr_writeq(mrioc->admin_req_dma,
> +	    &mrioc->sysif_regs->AdminRequestQueueAddress);
> +	mpi3mr_writeq(mrioc->admin_reply_dma,
> +	    &mrioc->sysif_regs->AdminReplyQueueAddress);
> +	writel(mrioc->admin_req_pi, &mrioc->sysif_regs->AdminRequestQueuePI);
> +	writel(mrioc->admin_reply_ci, &mrioc->sysif_regs->AdminReplyQueueCI);
> +	return retval;
> +
> +out_failed:
> +
> +	if (mrioc->admin_reply_base) {
> +		dma_free_coherent(&mrioc->pdev->dev, mrioc->admin_reply_q_sz,
> +		    mrioc->admin_reply_base, mrioc->admin_reply_dma);
> +		mrioc->admin_reply_base = NULL;
> +	}
> +	if (mrioc->admin_req_base) {
> +		dma_free_coherent(&mrioc->pdev->dev, mrioc->admin_req_q_sz,
> +		    mrioc->admin_req_base, mrioc->admin_req_dma);
> +		mrioc->admin_req_base = NULL;
> +	}
> +	return retval;
> +}
> +
> +/**
> + * mpi3mr_issue_iocfacts - Send IOC Facts
> + * @mrioc: Adapter instance reference
> + *
> + * Issue IOC Facts MPI request through admin queue and wait for
> + * the completion of it or time out.
> + *
> + * Return: 0 on success, non-zero on failures.
> + */
> +static int mpi3mr_issue_iocfacts(struct mpi3mr_ioc *mrioc,
> +	Mpi3IOCFactsData_t *facts_data)
> +{
> +	Mpi3IOCFactsRequest_t iocfacts_req;
> +	void *data = NULL;
> +	dma_addr_t data_dma;
> +	u32 data_len = sizeof(*facts_data);
> +	int retval = 0;
> +	u8 sgl_flags = MPI3MR_SGEFLAGS_SYSTEM_SIMPLE_END_OF_LIST;
> +
> +	data = dma_alloc_coherent(&mrioc->pdev->dev, data_len, &data_dma,
> +	    GFP_KERNEL);
> +
> +	if (!data) {
> +		retval = -1;
> +		goto out;
> +	}
> +
> +	memset(&iocfacts_req, 0, sizeof(iocfacts_req));
> +	mutex_lock(&mrioc->init_cmds.mutex);
> +	if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
> +		retval = -1;
> +		ioc_err(mrioc, "Issue IOCFacts: Init command is in use\n");
> +		mutex_unlock(&mrioc->init_cmds.mutex);
> +		goto out;
> +	}
> +	mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
> +	mrioc->init_cmds.is_waiting = 1;
> +	mrioc->init_cmds.callback = NULL;
> +	iocfacts_req.HostTag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
> +	iocfacts_req.Function = MPI3_FUNCTION_IOC_FACTS;
> +
> +	mpi3mr_add_sg_single(&iocfacts_req.SGL, sgl_flags, data_len,
> +	    data_dma);
> +
> +	init_completion(&mrioc->init_cmds.done);
> +	retval = mpi3mr_admin_request_post(mrioc, &iocfacts_req,
> +	    sizeof(iocfacts_req), 1);
> +	if (retval) {
> +		ioc_err(mrioc, "Issue IOCFacts: Admin Post failed\n");
> +		goto out_unlock;
> +	}
> +	wait_for_completion_timeout(&mrioc->init_cmds.done,
> +	    (MPI3MR_INTADMCMD_TIMEOUT * HZ));
> +	if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
> +		ioc_err(mrioc, "Issue IOCFacts: command timed out\n");
> +		mpi3mr_set_diagsave(mrioc);
> +		mpi3mr_issue_reset(mrioc,
> +		    MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT,
> +		    MPI3MR_RESET_FROM_IOCFACTS_TIMEOUT);
> +		mrioc->unrecoverable = 1;
> +		retval = -1;
> +		goto out_unlock;
> +	}
> +	if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
> +	    != MPI3_IOCSTATUS_SUCCESS) {
> +		ioc_err(mrioc,
> +		    "Issue IOCFacts: Failed IOCStatus(0x%04x) Loginfo(0x%08x)\n",
> +		    (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
> +		    mrioc->init_cmds.ioc_loginfo);
> +		retval = -1;
> +		goto out_unlock;
> +	}
> +	memcpy(facts_data, (u8 *)data, data_len);
> +out_unlock:
> +	mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
> +	mutex_unlock(&mrioc->init_cmds.mutex);
> +
> +out:
> +	if (data)
> +		dma_free_coherent(&mrioc->pdev->dev, data_len, data, data_dma);
> +
> +	return retval;
> +}
> +
> +/**
> + * mpi3mr_check_reset_dma_mask - Process IOC facts data
> + * @mrioc: Adapter instance reference
> + *
> + * Check whether the new DMA mask requested through IOCFacts by
> + * firmware needs to be set, if so set it .
> + *
> + * Return: 0 on success, non-zero on failure.
> + */
> +static inline int mpi3mr_check_reset_dma_mask(struct mpi3mr_ioc *mrioc)
> +{
> +	struct pci_dev *pdev = mrioc->pdev;
> +	int r;
> +	u64 facts_dma_mask = DMA_BIT_MASK(mrioc->facts.dma_mask);
> +
> +	if (!mrioc->facts.dma_mask || (mrioc->dma_mask <= facts_dma_mask))
> +		return 0;
> +
> +	ioc_info(mrioc, "Changing DMA mask from 0x%016llx to 0x%016llx\n",
> +	    mrioc->dma_mask, facts_dma_mask);
> +
> +	r = dma_set_mask_and_coherent(&pdev->dev, facts_dma_mask);
> +	if (r) {
> +		ioc_err(mrioc, "Setting DMA mask to 0x%016llx failed: %d\n",
> +		    facts_dma_mask, r);
> +		return r;
> +	}
> +	mrioc->dma_mask = facts_dma_mask;
> +	return r;
> +}
> +/**
> + * mpi3mr_process_factsdata - Process IOC facts data
> + * @mrioc: Adapter instance reference
> + *
> + * Convert IOC facts data into cpu endianness and cache it in
> + * the driver .
> + *
> + * Return: Nothing.
> + */
> +static void mpi3mr_process_factsdata(struct mpi3mr_ioc *mrioc,
> +	Mpi3IOCFactsData_t *facts_data)
> +{
> +	u32 ioc_config, req_sz, facts_flags;
> +
> +	if ((le16_to_cpu(facts_data->IOCFactsDataLength)) !=
> +	    (sizeof(*facts_data)/4)) {
> +		ioc_warn(mrioc,
> +		    "IOCFactsdata length mismatch driver_sz(%ld) firmware_sz(%d)\n",
> +		    sizeof(*facts_data),
> +		    le16_to_cpu(facts_data->IOCFactsDataLength) * 4);
> +	}
> +
> +	ioc_config = readl(&mrioc->sysif_regs->IOCConfiguration);
> +	req_sz = 1 << ((ioc_config & MPI3_SYSIF_IOC_CONFIG_OPER_REQ_ENT_SZ) >>
> +	    MPI3_SYSIF_IOC_CONFIG_OPER_REQ_ENT_SZ_SHIFT);
> +	if (le16_to_cpu(facts_data->IOCRequestFrameSize) != (req_sz/4)) {
> +		ioc_err(mrioc,
> +		    "IOCFacts data reqFrameSize mismatch hw_size(%d) firmware_sz(%d)\n",
> +		    req_sz/4, le16_to_cpu(facts_data->IOCRequestFrameSize));
> +	}
> +
> +	memset(&mrioc->facts, 0, sizeof(mrioc->facts));
> +
> +	facts_flags = le32_to_cpu(facts_data->Flags);
> +	mrioc->facts.op_req_sz = req_sz;
> +	mrioc->op_reply_desc_sz = 1 << ((ioc_config &
> +	    MPI3_SYSIF_IOC_CONFIG_OPER_RPY_ENT_SZ) >>
> +	    MPI3_SYSIF_IOC_CONFIG_OPER_RPY_ENT_SZ_SHIFT);
> +
> +	mrioc->facts.ioc_num = facts_data->IOCNumber;
> +	mrioc->facts.who_init = facts_data->WhoInit;
> +	mrioc->facts.max_msix_vectors = le16_to_cpu(facts_data->MaxMSIxVectors);
> +	mrioc->facts.personality = (facts_flags &
> +	    MPI3_IOCFACTS_FLAGS_PERSONALITY_MASK);
> +	mrioc->facts.dma_mask = (facts_flags &
> +	    MPI3_IOCFACTS_FLAGS_DMA_ADDRESS_WIDTH_MASK) >>
> +	    MPI3_IOCFACTS_FLAGS_DMA_ADDRESS_WIDTH_SHIFT;
> +	mrioc->facts.protocol_flags = facts_data->ProtocolFlags;
> +	mrioc->facts.mpi_version = le32_to_cpu(facts_data->MPIVersion.Word);
> +	mrioc->facts.max_reqs = le16_to_cpu(facts_data->MaxOutstandingRequest);
> +	mrioc->facts.product_id = le16_to_cpu(facts_data->ProductID);
> +	mrioc->facts.reply_sz = le16_to_cpu(facts_data->ReplyFrameSize) * 4;
> +	mrioc->facts.exceptions = le16_to_cpu(facts_data->IOCExceptions);
> +	mrioc->facts.max_perids = le16_to_cpu(facts_data->MaxPersistentID);
> +	mrioc->facts.max_pds = le16_to_cpu(facts_data->MaxPDs);
> +	mrioc->facts.max_vds = le16_to_cpu(facts_data->MaxVDs);
> +	mrioc->facts.max_hpds = le16_to_cpu(facts_data->MaxHostPDs);
> +	mrioc->facts.max_advhpds = le16_to_cpu(facts_data->MaxAdvancedHostPDs);
> +	mrioc->facts.max_raidpds = le16_to_cpu(facts_data->MaxRAIDPDs);
> +	mrioc->facts.max_nvme = le16_to_cpu(facts_data->MaxNVMe);
> +	mrioc->facts.max_pcieswitches =
> +	    le16_to_cpu(facts_data->MaxPCIeSwitches);
> +	mrioc->facts.max_sasexpanders =
> +	    le16_to_cpu(facts_data->MaxSASExpanders);
> +	mrioc->facts.max_sasinitiators =
> +	    le16_to_cpu(facts_data->MaxSASInitiators);
> +	mrioc->facts.max_enclosures = le16_to_cpu(facts_data->MaxEnclosures);
> +	mrioc->facts.min_devhandle = le16_to_cpu(facts_data->MinDevHandle);
> +	mrioc->facts.max_devhandle = le16_to_cpu(facts_data->MaxDevHandle);
> +	mrioc->facts.max_op_req_q =
> +	    le16_to_cpu(facts_data->MaxOperationalRequestQueues);
> +	mrioc->facts.max_op_reply_q =
> +	    le16_to_cpu(facts_data->MaxOperationalReplyQueues);
> +	mrioc->facts.ioc_capabilities =
> +	    le32_to_cpu(facts_data->IOCCapabilities);
> +	mrioc->facts.fw_ver.build_num =
> +	    le16_to_cpu(facts_data->FWVersion.BuildNum);
> +	mrioc->facts.fw_ver.cust_id =
> +	    le16_to_cpu(facts_data->FWVersion.CustomerID);
> +	mrioc->facts.fw_ver.ph_minor = facts_data->FWVersion.PhaseMinor;
> +	mrioc->facts.fw_ver.ph_major = facts_data->FWVersion.PhaseMajor;
> +	mrioc->facts.fw_ver.gen_minor = facts_data->FWVersion.GenMinor;
> +	mrioc->facts.fw_ver.gen_major = facts_data->FWVersion.GenMajor;
> +	mrioc->msix_count = min_t(int, mrioc->msix_count,
> +	    mrioc->facts.max_msix_vectors);
> +	mrioc->facts.sge_mod_mask = facts_data->SGEModifierMask;
> +	mrioc->facts.sge_mod_value = facts_data->SGEModifierValue;
> +	mrioc->facts.sge_mod_shift = facts_data->SGEModifierShift;
> +	mrioc->facts.shutdown_timeout =
> +	    le16_to_cpu(facts_data->ShutdownTimeout);
> +
> +	ioc_info(mrioc, "ioc_num(%d), maxopQ(%d), maxopRepQ(%d), maxdh(%d),",
> +	    mrioc->facts.ioc_num, mrioc->facts.max_op_req_q,
> +	    mrioc->facts.max_op_reply_q, mrioc->facts.max_devhandle);
> +	ioc_info(mrioc,
> +	    "maxreqs(%d), mindh(%d) maxPDs(%d) maxvectors(%d) maxperids(%d)\n",
> +	    mrioc->facts.max_reqs, mrioc->facts.min_devhandle,
> +	    mrioc->facts.max_pds, mrioc->facts.max_msix_vectors,
> +	    mrioc->facts.max_perids);
> +	ioc_info(mrioc, "SGEModMask 0x%x SGEModVal 0x%x SGEModShift 0x%x ",
> +	    mrioc->facts.sge_mod_mask, mrioc->facts.sge_mod_value,
> +	    mrioc->facts.sge_mod_shift);
> +	ioc_info(mrioc, "DMA Mask %d InitialPE Status 0x%x\n",
> +	    mrioc->facts.dma_mask, (facts_flags &
> +	    MPI3_IOCFACTS_FLAGS_INITIAL_PORT_ENABLE_MASK));
> +
> +	mrioc->max_host_ios = mrioc->facts.max_reqs - MPI3MR_INTERNAL_CMDS_RESVD;
> +
> +	if (reset_devices)
> +		mrioc->max_host_ios = min_t(int, mrioc->max_host_ios,
> +		    MPI3MR_HOST_IOS_KDUMP);
> +
> +}
> +
> +/**
> + * mpi3mr_alloc_reply_sense_bufs - Send IOC Init
> + * @mrioc: Adapter instance reference
> + *
> + * Allocate and initialize the reply free buffers, sense
> + * buffers, reply free queue and sense buffer queue.
> + *
> + * Return: 0 on success, non-zero on failures.
> + */
> +static int mpi3mr_alloc_reply_sense_bufs(struct mpi3mr_ioc *mrioc)
> +{
> +	int retval = 0;
> +	u32 sz, i;
> +	dma_addr_t phy_addr;
> +
> +	if (mrioc->init_cmds.reply)
> +		goto post_reply_sbuf;
> +
> +	mrioc->init_cmds.reply = kzalloc(mrioc->facts.reply_sz, GFP_KERNEL);
> +	if (!mrioc->init_cmds.reply)
> +		goto out_failed;
> +
> +
> +	mrioc->num_reply_bufs = mrioc->facts.max_reqs + MPI3MR_NUM_EVT_REPLIES;
> +	mrioc->reply_free_qsz = mrioc->num_reply_bufs + 1;
> +	mrioc->num_sense_bufs = mrioc->facts.max_reqs / MPI3MR_SENSEBUF_FACTOR;
> +	mrioc->sense_buf_q_sz = mrioc->num_sense_bufs + 1;
> +
> +	/* reply buffer pool, 16 byte align */
> +	sz = mrioc->num_reply_bufs * mrioc->facts.reply_sz;
> +	mrioc->reply_buf_pool = dma_pool_create("reply_buf pool",
> +	    &mrioc->pdev->dev, sz, 16, 0);
> +	if (!mrioc->reply_buf_pool) {
> +		ioc_err(mrioc, "reply buf pool: dma_pool_create failed\n");
> +		goto out_failed;
> +	}
> +
> +	mrioc->reply_buf = dma_pool_zalloc(mrioc->reply_buf_pool, GFP_KERNEL,
> +	    &mrioc->reply_buf_dma);
> +	if (!mrioc->reply_buf)
> +		goto out_failed;
> +
> +	mrioc->reply_buf_dma_max_address = mrioc->reply_buf_dma + sz;
> +
> +	/* reply free queue, 8 byte align */
> +	sz = mrioc->reply_free_qsz * 8;
> +	mrioc->reply_free_q_pool = dma_pool_create("reply_free_q pool",
> +	    &mrioc->pdev->dev, sz, 8, 0);
> +	if (!mrioc->reply_free_q_pool) {
> +		ioc_err(mrioc, "reply_free_q pool: dma_pool_create failed\n");
> +		goto out_failed;
> +	}
> +	mrioc->reply_free_q = dma_pool_zalloc(mrioc->reply_free_q_pool,
> +	    GFP_KERNEL, &mrioc->reply_free_q_dma);
> +	if (!mrioc->reply_free_q)
> +		goto out_failed;
> +
> +	/* sense buffer pool,  4 byte align */
> +	sz = mrioc->num_sense_bufs * MPI3MR_SENSEBUF_SZ;
> +	mrioc->sense_buf_pool = dma_pool_create("sense_buf pool",
> +	    &mrioc->pdev->dev, sz, 4, 0);
> +	if (!mrioc->sense_buf_pool) {
> +		ioc_err(mrioc, "sense_buf pool: dma_pool_create failed\n");
> +		goto out_failed;
> +	}
> +	mrioc->sense_buf = dma_pool_zalloc(mrioc->sense_buf_pool, GFP_KERNEL,
> +	    &mrioc->sense_buf_dma);
> +	if (!mrioc->sense_buf)
> +		goto out_failed;
> +
> +	/* sense buffer queue, 8 byte align */
> +	sz = mrioc->sense_buf_q_sz * 8;
> +	mrioc->sense_buf_q_pool = dma_pool_create("sense_buf_q pool",
> +	    &mrioc->pdev->dev, sz, 8, 0);
> +	if (!mrioc->sense_buf_q_pool) {
> +		ioc_err(mrioc, "sense_buf_q pool: dma_pool_create failed\n");
> +		goto out_failed;
> +	}
> +	mrioc->sense_buf_q = dma_pool_zalloc(mrioc->sense_buf_q_pool,
> +	    GFP_KERNEL, &mrioc->sense_buf_q_dma);
> +	if (!mrioc->sense_buf_q)
> +		goto out_failed;
> +
> +post_reply_sbuf:
> +	sz = mrioc->num_reply_bufs * mrioc->facts.reply_sz;
> +	ioc_info(mrioc,
> +	    "reply buf pool(0x%p): depth(%d), frame_size(%d), pool_size(%d kB), reply_dma(0x%llx)\n",
> +	    mrioc->reply_buf, mrioc->num_reply_bufs, mrioc->facts.reply_sz,
> +	    (sz / 1024), (unsigned long long)mrioc->reply_buf_dma);
> +	sz = mrioc->reply_free_qsz * 8;
> +	ioc_info(mrioc,
> +	    "reply_free_q pool(0x%p): depth(%d), frame_size(%d), pool_size(%d kB), reply_dma(0x%llx)\n",
> +	    mrioc->reply_free_q, mrioc->reply_free_qsz, 8, (sz / 1024),
> +	    (unsigned long long)mrioc->reply_free_q_dma);
> +	sz = mrioc->num_sense_bufs * MPI3MR_SENSEBUF_SZ;
> +	ioc_info(mrioc,
> +	    "sense_buf pool(0x%p): depth(%d), frame_size(%d), pool_size(%d kB), sense_dma(0x%llx)\n",
> +	    mrioc->sense_buf, mrioc->num_sense_bufs, MPI3MR_SENSEBUF_SZ,
> +	    (sz / 1024), (unsigned long long)mrioc->sense_buf_dma);
> +	sz = mrioc->sense_buf_q_sz * 8;
> +	ioc_info(mrioc,
> +	    "sense_buf_q pool(0x%p): depth(%d), frame_size(%d), pool_size(%d kB), sense_dma(0x%llx)\n",
> +	    mrioc->sense_buf_q, mrioc->sense_buf_q_sz, 8, (sz / 1024),
> +	    (unsigned long long)mrioc->sense_buf_q_dma);
> +
> +	/* initialize Reply buffer Queue */
> +	for (i = 0, phy_addr = mrioc->reply_buf_dma;
> +	    i < mrioc->num_reply_bufs; i++, phy_addr += mrioc->facts.reply_sz)
> +		mrioc->reply_free_q[i] = cpu_to_le64(phy_addr);
> +	mrioc->reply_free_q[i] = cpu_to_le64(0);
> +
> +	/* initialize Sense Buffer Queue */
> +	for (i = 0, phy_addr = mrioc->sense_buf_dma;
> +	    i < mrioc->num_sense_bufs; i++, phy_addr += MPI3MR_SENSEBUF_SZ)
> +		mrioc->sense_buf_q[i] = cpu_to_le64(phy_addr);
> +	mrioc->sense_buf_q[i] = cpu_to_le64(0);
> +	return retval;
> +
> +out_failed:
> +	retval = -1;
> +	return retval;
> +}
> +
> +/**
> + * mpi3mr_issue_iocinit - Send IOC Init
> + * @mrioc: Adapter instance reference
> + *
> + * Issue IOC Init MPI request through admin queue and wait for
> + * the completion of it or time out.
> + *
> + * Return: 0 on success, non-zero on failures.
> + */
> +static int mpi3mr_issue_iocinit(struct mpi3mr_ioc *mrioc)
> +{
> +	Mpi3IOCInitRequest_t iocinit_req;
> +	Mpi3DriverInfoLayout_t *drv_info;
> +	dma_addr_t data_dma;
> +	u32 data_len = sizeof(*drv_info);
> +	int retval = 0;
> +	ktime_t current_time;
> +
> +	drv_info = dma_alloc_coherent(&mrioc->pdev->dev, data_len, &data_dma,
> +	    GFP_KERNEL);
> +	if (!drv_info) {
> +		retval = -1;
> +		goto out;
> +	}
> +	drv_info->InformationLength = cpu_to_le32(data_len);
> +	strcpy(drv_info->DriverSignature, "Broadcom");
> +	strcpy(drv_info->OsName, utsname()->sysname);
> +	drv_info->OsName[sizeof(drv_info->OsName)-1] = 0;
> +	strcpy(drv_info->OsVersion, utsname()->release);
> +	drv_info->OsVersion[sizeof(drv_info->OsVersion)-1] = 0;
> +	strcpy(drv_info->DriverName, MPI3MR_DRIVER_NAME);
> +	strcpy(drv_info->DriverVersion, MPI3MR_DRIVER_VERSION);
> +	strcpy(drv_info->DriverReleaseDate, MPI3MR_DRIVER_RELDATE);
> +	drv_info->DriverCapabilities = 0;
> +	memcpy((u8 *)&mrioc->driver_info, (u8 *)drv_info,
> +	    sizeof(mrioc->driver_info));
> +
> +	memset(&iocinit_req, 0, sizeof(iocinit_req));
> +	mutex_lock(&mrioc->init_cmds.mutex);
> +	if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
> +		retval = -1;
> +		ioc_err(mrioc, "Issue IOCInit: Init command is in use\n");
> +		mutex_unlock(&mrioc->init_cmds.mutex);
> +		goto out;
> +	}
> +	mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
> +	mrioc->init_cmds.is_waiting = 1;
> +	mrioc->init_cmds.callback = NULL;
> +	iocinit_req.HostTag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
> +	iocinit_req.Function = MPI3_FUNCTION_IOC_INIT;
> +	iocinit_req.MPIVersion.Struct.Dev = MPI3_VERSION_DEV;
> +	iocinit_req.MPIVersion.Struct.Unit = MPI3_VERSION_UNIT;
> +	iocinit_req.MPIVersion.Struct.Major = MPI3_VERSION_MAJOR;
> +	iocinit_req.MPIVersion.Struct.Minor = MPI3_VERSION_MINOR;
> +	iocinit_req.WhoInit = MPI3_WHOINIT_HOST_DRIVER;
> +	iocinit_req.ReplyFreeQueueDepth = cpu_to_le16(mrioc->reply_free_qsz);
> +	iocinit_req.ReplyFreeQueueAddress =
> +	    cpu_to_le64(mrioc->reply_free_q_dma);
> +	iocinit_req.SenseBufferLength = cpu_to_le16(MPI3MR_SENSEBUF_SZ);
> +	iocinit_req.SenseBufferFreeQueueDepth =
> +	    cpu_to_le16(mrioc->sense_buf_q_sz);
> +	iocinit_req.SenseBufferFreeQueueAddress =
> +	    cpu_to_le64(mrioc->sense_buf_q_dma);
> +	iocinit_req.DriverInformationAddress = cpu_to_le64(data_dma);
> +
> +	current_time = ktime_get_real();
> +	iocinit_req.TimeStamp = cpu_to_le64(ktime_to_ms(current_time));
> +
> +	init_completion(&mrioc->init_cmds.done);
> +	retval = mpi3mr_admin_request_post(mrioc, &iocinit_req,
> +	    sizeof(iocinit_req), 1);
> +	if (retval) {
> +		ioc_err(mrioc, "Issue IOCInit: Admin Post failed\n");
> +		goto out_unlock;
> +	}
> +	wait_for_completion_timeout(&mrioc->init_cmds.done,
> +	    (MPI3MR_INTADMCMD_TIMEOUT * HZ));
> +	if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
> +		mpi3mr_set_diagsave(mrioc);
> +		mpi3mr_issue_reset(mrioc,
> +		    MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT,
> +		    MPI3MR_RESET_FROM_IOCINIT_TIMEOUT);
> +		mrioc->unrecoverable = 1;
> +		ioc_err(mrioc, "Issue IOCInit: command timed out\n");
> +		retval = -1;
> +		goto out_unlock;
> +	}
> +	if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
> +	    != MPI3_IOCSTATUS_SUCCESS) {
> +		ioc_err(mrioc,
> +		    "Issue IOCInit: Failed IOCStatus(0x%04x) Loginfo(0x%08x)\n",
> +		    (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
> +		    mrioc->init_cmds.ioc_loginfo);
> +		retval = -1;
> +		goto out_unlock;
> +	}
> +
> +out_unlock:
> +	mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
> +	mutex_unlock(&mrioc->init_cmds.mutex);
> +
> +out:
> +	if (drv_info)
> +		dma_free_coherent(&mrioc->pdev->dev, data_len, drv_info,
> +		    data_dma);
> +
> +	return retval;
> +}
> +
> +
> +/**
> + * mpi3mr_alloc_chain_bufs - Allocate chain buffers
> + * @mrioc: Adapter instance reference
> + *
> + * Allocate chain buffers and set a bitmap to indicate free
> + * chain buffers. Chain buffers are used to pass the SGE
> + * information along with MPI3 SCSI IO requests for host I/O.
> + *
> + * Return: 0 on success, non-zero on failure
> + */
> +static int mpi3mr_alloc_chain_bufs(struct mpi3mr_ioc *mrioc)
> +{
> +	int retval = 0;
> +	u32 sz, i;
> +	u16 num_chains;
> +
> +	num_chains = mrioc->max_host_ios/MPI3MR_CHAINBUF_FACTOR;
> +
> +	mrioc->chain_buf_count = num_chains;
> +	sz = sizeof(struct chain_element) * num_chains;
> +	mrioc->chain_sgl_list = kzalloc(sz, GFP_KERNEL);
> +	if (!mrioc->chain_sgl_list)
> +		goto out_failed;
> +
> +	sz = MPI3MR_PAGE_SIZE_4K;
> +	mrioc->chain_buf_pool = dma_pool_create("chain_buf pool",
> +	    &mrioc->pdev->dev, sz, 16, 0);
> +	if (!mrioc->chain_buf_pool) {
> +		ioc_err(mrioc, "chain buf pool: dma_pool_create failed\n");
> +		goto out_failed;
> +	}
> +
> +	for (i = 0; i < num_chains; i++) {
> +		mrioc->chain_sgl_list[i].addr =
> +		    dma_pool_zalloc(mrioc->chain_buf_pool, GFP_KERNEL,
> +		    &mrioc->chain_sgl_list[i].dma_addr);
> +
> +		if (!mrioc->chain_sgl_list[i].addr)
> +			goto out_failed;
> +	}
> +	mrioc->chain_bitmap_sz = num_chains / 8;
> +	if (num_chains % 8)
> +		mrioc->chain_bitmap_sz++;
> +	mrioc->chain_bitmap = kzalloc(mrioc->chain_bitmap_sz, GFP_KERNEL);
> +	if (!mrioc->chain_bitmap)
> +		goto out_failed;
> +	return retval;
> +out_failed:
> +	retval = -1;
> +	return retval;
> +}
> +
> +
> +/**
> + * mpi3mr_cleanup_resources - Free PCI resources
> + * @mrioc: Adapter instance reference
> + *
> + * Unmap PCI device memory and disable PCI device.
> + *
> + * Return: 0 on success and non-zero on failure.
> + */
> +void mpi3mr_cleanup_resources(struct mpi3mr_ioc *mrioc)
> +{
> +	struct pci_dev *pdev = mrioc->pdev;
> +
> +	mpi3mr_cleanup_isr(mrioc);
> +
> +	if (mrioc->sysif_regs) {
> +		iounmap(mrioc->sysif_regs);
> +		mrioc->sysif_regs = NULL;
> +	}
> +
> +	if (pci_is_enabled(pdev)) {
> +		if (mrioc->bars)
> +			pci_release_selected_regions(pdev, mrioc->bars);
> +		pci_disable_device(pdev);
> +	}
> +}
> +
> +/**
> + * mpi3mr_setup_resources - Enable PCI resources
> + * @mrioc: Adapter instance reference
> + *
> + * Enable PCI device memory, MSI-x registers and set DMA mask.
> + *
> + * Return: 0 on success and non-zero on failure.
> + */
> +int mpi3mr_setup_resources(struct mpi3mr_ioc *mrioc)
> +{
> +	struct pci_dev *pdev = mrioc->pdev;
> +	u32 memap_sz = 0;
> +	int i, retval = 0, capb = 0;
> +	u16 message_control;
> +	u64 dma_mask = mrioc->dma_mask ? mrioc->dma_mask :
> +	    (((dma_get_required_mask(&pdev->dev) > DMA_BIT_MASK(32)) &&
> +	    (sizeof(dma_addr_t) > 4)) ? DMA_BIT_MASK(64):DMA_BIT_MASK(32));
> +
> +	if (pci_enable_device_mem(pdev)) {
> +		ioc_err(mrioc, "pci_enable_device_mem: failed\n");
> +		retval = -ENODEV;
> +		goto out_failed;
> +	}
> +
> +	capb = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
> +	if (!capb) {
> +		ioc_err(mrioc, "Unable to find MSI-X Capabilities\n");
> +		retval = -ENODEV;
> +		goto out_failed;
> +	}
> +	mrioc->bars = pci_select_bars(pdev, IORESOURCE_MEM);
> +
> +	if (pci_request_selected_regions(pdev, mrioc->bars,
> +	    mrioc->driver_name)) {
> +		ioc_err(mrioc, "pci_request_selected_regions: failed\n");
> +		retval = -ENODEV;
> +		goto out_failed;
> +	}
> +
> +	for (i = 0; (i < DEVICE_COUNT_RESOURCE); i++) {
> +		if (pci_resource_flags(pdev, i) & IORESOURCE_MEM) {
> +			mrioc->sysif_regs_phys = pci_resource_start(pdev, i);
> +			memap_sz = pci_resource_len(pdev, i);
> +			mrioc->sysif_regs =
> +			    ioremap(mrioc->sysif_regs_phys, memap_sz);
> +			break;
> +		}
> +	}
> +
> +	pci_set_master(pdev);
> +
> +	retval = dma_set_mask_and_coherent(&pdev->dev, dma_mask);
> +	if (retval) {
> +		if (dma_mask != DMA_BIT_MASK(32)) {
> +			ioc_warn(mrioc, "Setting 64 bit DMA mask failed\n");
> +			dma_mask = DMA_BIT_MASK(32);
> +			retval = dma_set_mask_and_coherent(&pdev->dev,
> +			    dma_mask);
> +		}
> +		if (retval) {
> +			mrioc->dma_mask = 0;
> +			ioc_err(mrioc, "Setting 32 bit DMA mask also failed\n");
> +			goto out_failed;
> +		}
> +	}
> +	mrioc->dma_mask = dma_mask;
> +
> +	if (mrioc->sysif_regs == NULL) {
> +		ioc_err(mrioc,
> +		    "Unable to map adapter memory or resource not found\n");
> +		retval = -EINVAL;
> +		goto out_failed;
> +	}
> +
> +	pci_read_config_word(pdev, capb + 2, &message_control);
> +	mrioc->msix_count = (message_control & 0x3FF) + 1;
> +
> +	pci_save_state(pdev);
> +
> +	pci_set_drvdata(pdev, mrioc->shost);
> +
> +	mpi3mr_ioc_disable_intr(mrioc);
> +
> +	ioc_info(mrioc, "iomem(0x%016llx), mapped(0x%p), size(%d)\n",
> +	    (unsigned long long)mrioc->sysif_regs_phys,
> +	    mrioc->sysif_regs, memap_sz);
> +	ioc_info(mrioc, "Number of MSI-X vectors found in capabilities: (%d)\n",
> +	    mrioc->msix_count);
> +	return retval;
> +
> +out_failed:
> +	mpi3mr_cleanup_resources(mrioc);
> +	return retval;
> +}
> +
> +/**
> + * mpi3mr_init_ioc - Initialize the controller
> + * @mrioc: Adapter instance reference
> + *
> + * This the controller initialization routine, executed either
> + * after soft reset or from pci probe callback.
> + * Setup the required resources, memory map the controller
> + * registers, create admin and operational reply queue pairs,
> + * allocate required memory for reply pool, sense buffer pool,
> + * issue IOC init request to the firmware, unmask the events and
> + * issue port enable to discover SAS/SATA/NVMe devies and RAID
> + * volumes.
> + *
> + * Return: 0 on success and non-zero on failure.
> + */
> +int mpi3mr_init_ioc(struct mpi3mr_ioc *mrioc)
> +{
> +	int retval = 0;
> +	enum mpi3mr_iocstate ioc_state;
> +	u64 base_info;
> +	u32 timeout;
> +	u32 ioc_status, ioc_config;
> +	Mpi3IOCFactsData_t facts_data;
> +
> +	mrioc->change_count = 0;
> +	mrioc->cpu_count = num_online_cpus();

What about CPU hotplug?

> +	retval = mpi3mr_setup_resources(mrioc);
> +	if (retval) {
> +		ioc_err(mrioc, "Failed to setup resources:error %d\n",
> +		    retval);
> +		goto out_nocleanup;
> +	}
> +	ioc_status = readl(&mrioc->sysif_regs->IOCStatus);
> +	ioc_config = readl(&mrioc->sysif_regs->IOCConfiguration);
> +
> +	ioc_info(mrioc, "SOD status %x configuration %x\n",
> +	    ioc_status, ioc_config);
> +
> +	base_info = readq(&mrioc->sysif_regs->IOCInformation);
> +	ioc_info(mrioc, "SOD base_info %llx\n",	base_info);
> +
> +	/*The timeout value is in 2sec unit, changing it to seconds*/
> +	mrioc->ready_timeout =
> +	    ((base_info & MPI3_SYSIF_IOC_INFO_LOW_TIMEOUT_MASK) >>
> +	    MPI3_SYSIF_IOC_INFO_LOW_TIMEOUT_SHIFT) * 2;
> +
> +	ioc_info(mrioc, "IOC ready timeout %d\n", mrioc->ready_timeout);
> +
> +	ioc_state = mpi3mr_get_iocstate(mrioc);
> +	ioc_info(mrioc, "IOC in %s state during detection\n",
> +	    mpi3mr_iocstate_name(ioc_state));
> +
> +	if (ioc_state == MRIOC_STATE_BECOMING_READY ||
> +			ioc_state == MRIOC_STATE_RESET_REQUESTED) {
> +		timeout = mrioc->ready_timeout * 10;
> +		do {
> +			msleep(100);
> +		} while (--timeout);
> +
> +		ioc_state = mpi3mr_get_iocstate(mrioc);
> +		ioc_info(mrioc,
> +			"IOC in %s state after waiting for reset time\n",
> +			mpi3mr_iocstate_name(ioc_state));
> +	}
> +
> +	if (ioc_state == MRIOC_STATE_READY) {
> +		retval = mpi3mr_issue_and_process_mur(mrioc,
> +		    MPI3MR_RESET_FROM_BRINGUP);
> +		if (retval) {
> +			ioc_err(mrioc, "Failed to MU reset IOC error %d\n",
> +			    retval);
> +		}
> +		ioc_state = mpi3mr_get_iocstate(mrioc);
> +	}
> +	if (ioc_state != MRIOC_STATE_RESET) {
> +		mpi3mr_print_fault_info(mrioc);
> +		retval = mpi3mr_issue_reset(mrioc,
> +		    MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET,
> +		    MPI3MR_RESET_FROM_BRINGUP);
> +		if (retval) {
> +			ioc_err(mrioc,
> +			    "%s :Failed to soft reset IOC error %d\n",
> +			    __func__, retval);
> +			goto out_failed;
> +		}
> +	}
> +	ioc_state = mpi3mr_get_iocstate(mrioc);
> +	if (ioc_state != MRIOC_STATE_RESET) {
> +		ioc_err(mrioc, "Cannot bring IOC to reset state\n");
> +		goto out_failed;
> +	}
> +
> +	retval = mpi3mr_setup_admin_qpair(mrioc);
> +	if (retval) {
> +		ioc_err(mrioc, "Failed to setup admin Qs: error %d\n",
> +		    retval);
> +		goto out_failed;
> +	}
> +
> +	retval = mpi3mr_bring_ioc_ready(mrioc);
> +	if (retval) {
> +		ioc_err(mrioc, "Failed to bring ioc ready: error %d\n",
> +		    retval);
> +		goto out_failed;
> +	}
> +
> +	retval = mpi3mr_setup_isr(mrioc, 1);
> +	if (retval) {
> +		ioc_err(mrioc, "Failed to setup ISR error %d\n",
> +		    retval);
> +		goto out_failed;
> +	}
> +
> +	retval = mpi3mr_issue_iocfacts(mrioc, &facts_data);
> +	if (retval) {
> +		ioc_err(mrioc, "Failed to Issue IOC Facts %d\n",
> +		    retval);
> +		goto out_failed;
> +	}
> +
> +	mpi3mr_process_factsdata(mrioc, &facts_data);
> +	retval = mpi3mr_check_reset_dma_mask(mrioc);
> +	if (retval) {
> +		ioc_err(mrioc, "Resetting dma mask failed %d\n",
> +		    retval);
> +		goto out_failed;
> +	}
> +
> +	retval = mpi3mr_alloc_reply_sense_bufs(mrioc);
> +	if (retval) {
> +		ioc_err(mrioc,
> +		    "%s :Failed to allocated reply sense buffers %d\n",
> +		    __func__, retval);
> +		goto out_failed;
> +	}
> +
> +	retval = mpi3mr_alloc_chain_bufs(mrioc);
> +	if (retval) {
> +		ioc_err(mrioc, "Failed to allocated chain buffers %d\n",
> +		    retval);
> +		goto out_failed;
> +	}
> +
> +	retval = mpi3mr_issue_iocinit(mrioc);
> +	if (retval) {
> +		ioc_err(mrioc, "Failed to Issue IOC Init %d\n",
> +		    retval);
> +		goto out_failed;
> +	}
> +	mrioc->reply_free_queue_host_index = mrioc->num_reply_bufs;
> +	writel(mrioc->reply_free_queue_host_index,
> +	    &mrioc->sysif_regs->ReplyFreeHostIndex);
> +
> +	mrioc->sbq_host_index = mrioc->num_sense_bufs;
> +	writel(mrioc->sbq_host_index,
> +	    &mrioc->sysif_regs->SenseBufferFreeHostIndex);
> +
> +	retval = mpi3mr_setup_isr(mrioc, 0);
> +	if (retval) {
> +		ioc_err(mrioc, "Failed to re-setup ISR, error %d\n",
> +		    retval);
> +		goto out_failed;
> +	}
> +
> +	return retval;
> +
> +out_failed:
> +	mpi3mr_cleanup_ioc(mrioc);
> +out_nocleanup:
> +	return retval;
> +}
> +
> +
> +/**
> + * mpi3mr_free_mem - Free memory allocated for a controller
> + * @mrioc: Adapter instance reference
> + *
> + * Free all the memory allocated for a controller.
> + *
> + * Return: Nothing.
> + */
> +static void mpi3mr_free_mem(struct mpi3mr_ioc *mrioc)
> +{
> +	u16 i;
> +	struct mpi3mr_intr_info *intr_info;
> +
> +	if (mrioc->sense_buf_pool) {
> +		if (mrioc->sense_buf)
> +			dma_pool_free(mrioc->sense_buf_pool, mrioc->sense_buf,
> +			    mrioc->sense_buf_dma);
> +		dma_pool_destroy(mrioc->sense_buf_pool);
> +		mrioc->sense_buf = NULL;
> +		mrioc->sense_buf_pool = NULL;
> +	}
> +	if (mrioc->sense_buf_q_pool) {
> +		if (mrioc->sense_buf_q)
> +			dma_pool_free(mrioc->sense_buf_q_pool,
> +			    mrioc->sense_buf_q, mrioc->sense_buf_q_dma);
> +		dma_pool_destroy(mrioc->sense_buf_q_pool);
> +		mrioc->sense_buf_q = NULL;
> +		mrioc->sense_buf_q_pool = NULL;
> +	}
> +
> +	if (mrioc->reply_buf_pool) {
> +		if (mrioc->reply_buf)
> +			dma_pool_free(mrioc->reply_buf_pool, mrioc->reply_buf,
> +			    mrioc->reply_buf_dma);
> +		dma_pool_destroy(mrioc->reply_buf_pool);
> +		mrioc->reply_buf = NULL;
> +		mrioc->reply_buf_pool = NULL;
> +	}
> +	if (mrioc->reply_free_q_pool) {
> +		if (mrioc->reply_free_q)
> +			dma_pool_free(mrioc->reply_free_q_pool,
> +			    mrioc->reply_free_q, mrioc->reply_free_q_dma);
> +		dma_pool_destroy(mrioc->reply_free_q_pool);
> +		mrioc->reply_free_q = NULL;
> +		mrioc->reply_free_q_pool = NULL;
> +	}
> +
> +	for (i = 0; i < mrioc->intr_info_count; i++) {
> +		intr_info = mrioc->intr_info + i;
> +		if (intr_info)
> +			intr_info->op_reply_q = NULL;
> +	}
> +
> +	kfree(mrioc->req_qinfo);
> +	mrioc->req_qinfo = NULL;
> +	mrioc->num_op_req_q = 0;
> +
> +	kfree(mrioc->op_reply_qinfo);
> +	mrioc->op_reply_qinfo = NULL;
> +	mrioc->num_op_reply_q = 0;
> +
> +	kfree(mrioc->init_cmds.reply);
> +	mrioc->init_cmds.reply = NULL;
> +
> +	kfree(mrioc->chain_bitmap);
> +	mrioc->chain_bitmap = NULL;
> +
> +	if (mrioc->chain_buf_pool) {
> +		for (i = 0; i < mrioc->chain_buf_count; i++) {
> +			if (mrioc->chain_sgl_list[i].addr) {
> +				dma_pool_free(mrioc->chain_buf_pool,
> +				    mrioc->chain_sgl_list[i].addr,
> +				    mrioc->chain_sgl_list[i].dma_addr);
> +				mrioc->chain_sgl_list[i].addr = NULL;
> +			}
> +		}
> +		dma_pool_destroy(mrioc->chain_buf_pool);
> +		mrioc->chain_buf_pool = NULL;
> +	}
> +
> +	kfree(mrioc->chain_sgl_list);
> +	mrioc->chain_sgl_list = NULL;
> +
> +	if (mrioc->admin_reply_base) {
> +		dma_free_coherent(&mrioc->pdev->dev, mrioc->admin_reply_q_sz,
> +		    mrioc->admin_reply_base, mrioc->admin_reply_dma);
> +		mrioc->admin_reply_base = NULL;
> +	}
> +	if (mrioc->admin_req_base) {
> +		dma_free_coherent(&mrioc->pdev->dev, mrioc->admin_req_q_sz,
> +		    mrioc->admin_req_base, mrioc->admin_req_dma);
> +		mrioc->admin_req_base = NULL;
> +	}
> +
> +}
> +
> +/**
> + * mpi3mr_issue_ioc_shutdown - Shutdown controller
> + * @mrioc: Adapter instance reference
> + *
> + * Send shutodwn notification to the controller and wait for the
> + * shutdown_timeout for it to be completed.
> + *
> + * Return: Nothing.
> + */
> +static void mpi3mr_issue_ioc_shutdown(struct mpi3mr_ioc *mrioc)
> +{
> +	u32 ioc_config, ioc_status;
> +	u8 retval = 1;
> +	u32 timeout = MPI3MR_DEFAULT_SHUTDOWN_TIME * 10;
> +
> +	ioc_info(mrioc, "Issuing Shutdown Notification\n");
> +	if (mrioc->unrecoverable) {
> +		ioc_warn(mrioc,
> +		    "IOC is unrecoverable Shutdown is not issued\n");
> +		return;
> +	}
> +	ioc_status = readl(&mrioc->sysif_regs->IOCStatus);
> +	if ((ioc_status & MPI3_SYSIF_IOC_STATUS_SHUTDOWN_MASK)
> +	    == MPI3_SYSIF_IOC_STATUS_SHUTDOWN_IN_PROGRESS) {
> +		ioc_info(mrioc, "Shutdown already in progress\n");
> +		return;
> +	}
> +
> +	ioc_config = readl(&mrioc->sysif_regs->IOCConfiguration);
> +	ioc_config |= MPI3_SYSIF_IOC_CONFIG_SHUTDOWN_NORMAL;
> +	ioc_config |= MPI3_SYSIF_IOC_CONFIG_DEVICE_SHUTDOWN;
> +
> +	writel(ioc_config, &mrioc->sysif_regs->IOCConfiguration);
> +
> +	if (mrioc->facts.shutdown_timeout)
> +		timeout = mrioc->facts.shutdown_timeout * 10;
> +
> +	do {
> +		ioc_status = readl(&mrioc->sysif_regs->IOCStatus);
> +		if ((ioc_status & MPI3_SYSIF_IOC_STATUS_SHUTDOWN_MASK)
> +		    == MPI3_SYSIF_IOC_STATUS_SHUTDOWN_COMPLETE) {
> +			retval = 0;
> +			break;
> +		}
> +		msleep(100);
> +	} while (--timeout);
> +
> +
> +	ioc_status = readl(&mrioc->sysif_regs->IOCStatus);
> +	ioc_config = readl(&mrioc->sysif_regs->IOCConfiguration);
> +
> +	if (retval) {
> +		if ((ioc_status & MPI3_SYSIF_IOC_STATUS_SHUTDOWN_MASK)
> +		    == MPI3_SYSIF_IOC_STATUS_SHUTDOWN_IN_PROGRESS)
> +			ioc_warn(mrioc,
> +			    "Shutdown still in progress after timeout\n");
> +	}
> +
> +	ioc_info(mrioc,
> +	    "Base IOC Sts/Config after %s shutdown is (0x%x)/(0x%x)\n",
> +	    (!retval)?"successful":"failed", ioc_status,
> +	    ioc_config);
> +}
> +
> +/**
> + * mpi3mr_cleanup_ioc - Cleanup controller
> + * @mrioc: Adapter instance reference
> + *
> + * Controller cleanup handler, Message unit reset or soft reset
> + * and shutdown notification is issued to the controller and the
> + * associated memory resources are freed.
> + *
> + * Return: Nothing.
> + */
> +void mpi3mr_cleanup_ioc(struct mpi3mr_ioc *mrioc)
> +{
> +	enum mpi3mr_iocstate ioc_state;
> +
> +	mpi3mr_ioc_disable_intr(mrioc);
> +
> +	ioc_state = mpi3mr_get_iocstate(mrioc);
> +
> +	if ((!mrioc->unrecoverable) && (!mrioc->reset_in_progress) &&
> +	     (ioc_state == MRIOC_STATE_READY)) {
> +		if (mpi3mr_issue_and_process_mur(mrioc,
> +		    MPI3MR_RESET_FROM_CTLR_CLEANUP))
> +			mpi3mr_issue_reset(mrioc,
> +			    MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET,
> +			    MPI3MR_RESET_FROM_MUR_FAILURE);
> +
> +		 mpi3mr_issue_ioc_shutdown(mrioc);
> +	}
> +
> +	mpi3mr_free_mem(mrioc);
> +	mpi3mr_cleanup_resources(mrioc);
> +}
> +
> +
> +/**
> + * mpi3mr_soft_reset_handler - Reset the controller
> + * @mrioc: Adapter instance reference
> + * @reset_reason: Reset reason code
> + * @snapdump: Flag to generate snapdump in firmware or not
> + *
> + * TBD
> + *
> + * Return: 0 on success, non-zero on failure.
> + */
> +int mpi3mr_soft_reset_handler(struct mpi3mr_ioc *mrioc,
> +	u32 reset_reason, u8 snapdump)
> +{
> +	return 0;
> +}
> diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c
> new file mode 100644
> index 000000000000..c31ec9883152
> --- /dev/null
> +++ b/drivers/scsi/mpi3mr/mpi3mr_os.c
> @@ -0,0 +1,368 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Driver for Broadcom MPI3 Storage Controllers
> + *
> + * Copyright (C) 2017-2020 Broadcom Inc.
> + *  (mailto: mpi3mr-linuxdrv.pdl@broadcom.com)
> + *
> + */
> +
> +#include "mpi3mr.h"
> +
> +/* global driver scop variables */
> +LIST_HEAD(mrioc_list);
> +DEFINE_SPINLOCK(mrioc_list_lock);
> +static int mrioc_ids;
> +static int warn_non_secure_ctlr;
> +
> +MODULE_AUTHOR(MPI3MR_DRIVER_AUTHOR);
> +MODULE_DESCRIPTION(MPI3MR_DRIVER_DESC);
> +MODULE_LICENSE(MPI3MR_DRIVER_LICENSE);
> +MODULE_VERSION(MPI3MR_DRIVER_VERSION);
> +
> +/* Module parameters*/
> +int logging_level;
> +module_param(logging_level, int, 0);
> +MODULE_PARM_DESC(logging_level,
> +	" bits for enabling additional logging info (default=0)");
> +
> +
> +/**
> + * mpi3mr_map_queues - Map queues callback handler
> + * @shost: SCSI host reference
> + *
> + * Call the blk_mq_pci_map_queues with from which operational
> + * queue the mapping has to be done
> + *
> + * Return: return of blk_mq_pci_map_queues
> + */
> +static int mpi3mr_map_queues(struct Scsi_Host *shost)
> +{
> +	struct mpi3mr_ioc *mrioc = shost_priv(shost);
> +
> +	return blk_mq_pci_map_queues(&shost->tag_set.map[HCTX_TYPE_DEFAULT],
> +	    mrioc->pdev, 0);
> +}
> +

What happened to polling?
You did some patches for megaraid_sas, so I would have expected them to
be here, too ...

> +/**
> + * mpi3mr_slave_destroy - Slave destroy callback handler
> + * @sdev: SCSI device reference
> + *
> + * Cleanup and free per device(LUN) private data.
> + *
> + * Return: Nothing.
> + */
> +static void mpi3mr_slave_destroy(struct scsi_device *sdev)
> +{
> +}
> +
> +/**
> + * mpi3mr_target_destroy - Target destroy callback handler
> + * @starget: SCSI target reference
> + *
> + * Cleanup and free per target private data.
> + *
> + * Return: Nothing.
> + */
> +static void mpi3mr_target_destroy(struct scsi_target *starget)
> +{
> +}
> +
> +/**
> + * mpi3mr_slave_configure - Slave configure callback handler
> + * @sdev: SCSI device reference
> + *
> + * Configure queue depth, max hardware sectors and virt boundary
> + * as required
> + *
> + * Return: 0 always.
> + */
> +static int mpi3mr_slave_configure(struct scsi_device *sdev)
> +{
> +	int retval = 0;
> +	return retval;
> +}
> +
> +/**
> + * mpi3mr_slave_alloc -Slave alloc callback handler
> + * @sdev: SCSI device reference
> + *
> + * Allocate per device(LUN) private data and initialize it.
> + *
> + * Return: 0 on success -ENOMEM on memory allocation failure.
> + */
> +static int mpi3mr_slave_alloc(struct scsi_device *sdev)
> +{
> +	int retval = 0;
> +	return retval;
> +}
> +
> +/**
> + * mpi3mr_target_alloc - Target alloc callback handler
> + * @starget: SCSI target reference
> + *
> + * Allocate per target private data and initialize it.
> + *
> + * Return: 0 on success -ENOMEM on memory allocation failure.
> + */
> +static int mpi3mr_target_alloc(struct scsi_target *starget)
> +{
> +	int retval = -ENODEV;
> +	return retval;
> +}
> +
> +/**
> + * mpi3mr_qcmd - I/O request despatcher
> + * @shost: SCSI Host reference
> + * @scmd: SCSI Command reference
> + *
> + * Issues the SCSI Command as an MPI3 request.
> + *
> + * Return: 0 on successful queueing of the request or if the
> + *         request is completed with failure.
> + *         SCSI_MLQUEUE_DEVICE_BUSY when the device is busy.
> + *         SCSI_MLQUEUE_HOST_BUSY when the host queue is full.
> + */
> +static int mpi3mr_qcmd(struct Scsi_Host *shost,
> +	struct scsi_cmnd *scmd)
> +{
> +	int retval = 0;
> +
> +	scmd->result = DID_NO_CONNECT << 16;
> +	scmd->scsi_done(scmd);
> +	return retval;
> +}
> +
> +static struct scsi_host_template mpi3mr_driver_template = {
> +	.module				= THIS_MODULE,
> +	.name				= "MPI3 Storage Controller",
> +	.proc_name			= MPI3MR_DRIVER_NAME,
> +	.queuecommand			= mpi3mr_qcmd,
> +	.target_alloc			= mpi3mr_target_alloc,
> +	.slave_alloc			= mpi3mr_slave_alloc,
> +	.slave_configure		= mpi3mr_slave_configure,
> +	.target_destroy			= mpi3mr_target_destroy,
> +	.slave_destroy			= mpi3mr_slave_destroy,
> +	.map_queues			= mpi3mr_map_queues,
> +	.no_write_same			= 1,
> +	.can_queue			= 1,
> +	.this_id			= -1,
> +	.sg_tablesize			= MPI3MR_SG_DEPTH,
> +	/* max xfer supported is 1M (2K in 512 byte sized sectors)
> +	 */
> +	.max_sectors			= 2048,
> +	.cmd_per_lun			= MPI3MR_MAX_CMDS_LUN,
> +	.track_queue_depth		= 1,
> +	.cmd_size			= sizeof(struct scmd_priv),
> +};
> +
> +
> +/**
> + * mpi3mr_init_drv_cmd - Initialize internal command tracker
> + * @cmdptr: Internal command tracker
> + * @host_tag: Host tag used for the specific command
> + *
> + * Initialize the internal command tracker structure with
> + * specified host tag.
> + *
> + * Return: Nothing.
> + */
> +static inline void mpi3mr_init_drv_cmd(struct mpi3mr_drv_cmd *cmdptr,
> +	u16 host_tag)
> +{
> +	mutex_init(&cmdptr->mutex);
> +	cmdptr->reply = NULL;
> +	cmdptr->state = MPI3MR_CMD_NOTUSED;
> +	cmdptr->dev_handle = MPI3MR_INVALID_DEV_HANDLE;
> +	cmdptr->host_tag = host_tag;
> +}
> +
> +/**
> + * mpi3mr_probe - PCI probe callback
> + * @pdev: PCI device instance
> + * @id: PCI device ID details
> + *
> + * Controller initialization routine. Checks the security status
> + * of the controller and if it is invalid or tampered return the
> + * probe without initializing the controller. Otherwise,
> + * allocate per adapter instance through shost_priv and
> + * initialize controller specific data structures, initializae
> + * the controller hardware, add shost to the SCSI subsystem.
> + *
> + * Return: 0 on success, non-zero on failure.
> + */
> +
> +static int
> +mpi3mr_probe(struct pci_dev *pdev, const struct pci_device_id *id)
> +{
> +	struct mpi3mr_ioc *mrioc = NULL;
> +	struct Scsi_Host *shost = NULL;
> +	int retval = 0;
> +
> +	shost = scsi_host_alloc(&mpi3mr_driver_template,
> +	    sizeof(struct mpi3mr_ioc));
> +	if (!shost) {
> +		retval = -ENODEV;
> +		goto shost_failed;
> +	}
> +
> +	mrioc = shost_priv(shost);
> +	mrioc->id = mrioc_ids++;
> +	sprintf(mrioc->driver_name, "%s", MPI3MR_DRIVER_NAME);
> +	sprintf(mrioc->name, "%s%d", mrioc->driver_name, mrioc->id);
> +	INIT_LIST_HEAD(&mrioc->list);
> +	spin_lock(&mrioc_list_lock);
> +	list_add_tail(&mrioc->list, &mrioc_list);
> +	spin_unlock(&mrioc_list_lock);
> +
> +	spin_lock_init(&mrioc->admin_req_lock);
> +	spin_lock_init(&mrioc->reply_free_queue_lock);
> +	spin_lock_init(&mrioc->sbq_lock);
> +
> +	mpi3mr_init_drv_cmd(&mrioc->init_cmds, MPI3MR_HOSTTAG_INITCMDS);
> +
> +	mrioc->logging_level = logging_level;
> +	mrioc->shost = shost;
> +	mrioc->pdev = pdev;
> +
> +	/* init shost parameters */
> +	shost->max_cmd_len = MPI3MR_MAX_CDB_LENGTH;
> +	shost->max_lun = -1;
> +	shost->unique_id = mrioc->id;
> +
> +	shost->max_channel = 1;
> +	shost->max_id = 0xFFFFFFFF;
> +
> +	mrioc->is_driver_loading = 1;
> +	if (mpi3mr_init_ioc(mrioc)) {
> +		ioc_err(mrioc, "failure at %s:%d/%s()!\n",
> +		    __FILE__, __LINE__, __func__);
> +		retval = -ENODEV;
> +		goto out_iocinit_failed;
> +	}
> +
> +	shost->nr_hw_queues = mrioc->num_op_reply_q;
> +	shost->can_queue = mrioc->max_host_ios;
> +	shost->sg_tablesize = MPI3MR_SG_DEPTH;
> +	shost->max_id = mrioc->facts.max_perids;
> +
> +	retval = scsi_add_host(shost, &pdev->dev);
> +	if (retval) {
> +		ioc_err(mrioc, "failure at %s:%d/%s()!\n",
> +		    __FILE__, __LINE__, __func__);
> +		goto addhost_failed;
> +	}
> +
> +	scsi_scan_host(shost);
> +	return retval;
> +
> +addhost_failed:
> +	mpi3mr_cleanup_ioc(mrioc);
> +out_iocinit_failed:
> +	spin_lock(&mrioc_list_lock);
> +	list_del(&mrioc->list);
> +	spin_unlock(&mrioc_list_lock);
> +	scsi_host_put(shost);
> +shost_failed:
> +	return retval;
> +}
> +
> +/**
> + * mpi3mr_remove - PCI remove callback
> + * @pdev: PCI device instance
> + *
> + * Free up all memory and resources associated with the
> + * controllerand target devices, unregister the shost.
> + *
> + * Return: Nothing.
> + */
> +static void mpi3mr_remove(struct pci_dev *pdev)
> +{
> +	struct Scsi_Host *shost = pci_get_drvdata(pdev);
> +	struct mpi3mr_ioc *mrioc;
> +
> +	mrioc = shost_priv(shost);
> +	while (mrioc->reset_in_progress || mrioc->is_driver_loading)
> +		ssleep(1);
> +
> +
> +	scsi_remove_host(shost);
> +
> +	mpi3mr_cleanup_ioc(mrioc);
> +
> +	spin_lock(&mrioc_list_lock);
> +	list_del(&mrioc->list);
> +	spin_unlock(&mrioc_list_lock);
> +
> +	scsi_host_put(shost);
> +}
> +
> +/**
> + * mpi3mr_shutdown - PCI shutdown callback
> + * @pdev: PCI device instance
> + *
> + * Free up all memory and resources associated with the
> + * controller
> + *
> + * Return: Nothing.
> + */
> +static void mpi3mr_shutdown(struct pci_dev *pdev)
> +{
> +	struct Scsi_Host *shost = pci_get_drvdata(pdev);
> +	struct mpi3mr_ioc *mrioc;
> +
> +	if (!shost)
> +		return;
> +
> +	mrioc = shost_priv(shost);
> +	while (mrioc->reset_in_progress || mrioc->is_driver_loading)
> +		ssleep(1);
> +
> +	mpi3mr_cleanup_ioc(mrioc);
> +
> +}
> +
> +static const struct pci_device_id mpi3mr_pci_id_table[] = {
> +	{
> +		PCI_DEVICE_SUB(PCI_VENDOR_ID_LSI_LOGIC, 0x00A5,
> +		    PCI_ANY_ID, PCI_ANY_ID)
> +	},
> +	{ 0 }
> +};
> +MODULE_DEVICE_TABLE(pci, mpi3mr_pci_id_table);
> +
> +static struct pci_driver mpi3mr_pci_driver = {
> +	.name = MPI3MR_DRIVER_NAME,
> +	.id_table = mpi3mr_pci_id_table,
> +	.probe = mpi3mr_probe,
> +	.remove = mpi3mr_remove,
> +	.shutdown = mpi3mr_shutdown,
> +};
> +
> +static int __init mpi3mr_init(void)
> +{
> +	int ret_val;
> +
> +	pr_info("Loading %s version %s\n", MPI3MR_DRIVER_NAME,
> +	    MPI3MR_DRIVER_VERSION);
> +
> +	ret_val = pci_register_driver(&mpi3mr_pci_driver);
> +
> +	return ret_val;
> +}
> +
> +static void __exit mpi3mr_exit(void)
> +{
> +	if (warn_non_secure_ctlr)
> +		pr_warn(
> +		    "Unloading %s version %s while managing a non secure controller\n",
> +		    MPI3MR_DRIVER_NAME, MPI3MR_DRIVER_VERSION);
> +	else
> +		pr_info("Unloading %s version %s\n", MPI3MR_DRIVER_NAME,
> +		    MPI3MR_DRIVER_VERSION);
> +
> +	pci_unregister_driver(&mpi3mr_pci_driver);
> +}
> +
> +module_init(mpi3mr_init);
> +module_exit(mpi3mr_exit);
> 
Cheers,

Hannes
-- 
Dr. Hannes Reinecke		           Kernel Storage Architect
hare@suse.de			                  +49 911 74053 688
SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), GF: Felix Imendörffer

^ permalink raw reply	[flat|nested] 75+ messages in thread

* RE: [PATCH 04/24] mpi3mr: add support of queue command processing
  2021-02-22 15:23   ` Tomas Henzl
@ 2021-02-25 13:24     ` Kashyap Desai
  2021-02-25 14:11       ` Tomas Henzl
  0 siblings, 1 reply; 75+ messages in thread
From: Kashyap Desai @ 2021-02-25 13:24 UTC (permalink / raw)
  To: Tomas Henzl, linux-scsi
  Cc: jejb, martin.petersen, Steve Hagan, Peter Rivera,
	mpi3mr-drvr-developers, Sathya Prakash Veerichetty

[-- Attachment #1: Type: text/plain, Size: 1999 bytes --]

> >   * mpi3mr_slave_destroy - Slave destroy callback handler
> >   * @sdev: SCSI device reference
> > @@ -126,10 +658,114 @@ static int mpi3mr_target_alloc(struct
> > scsi_target *starget)  static int mpi3mr_qcmd(struct Scsi_Host *shost,
> >  	struct scsi_cmnd *scmd)
> >  {
> > +	struct mpi3mr_ioc *mrioc = shost_priv(shost);
> > +	struct mpi3mr_stgt_priv_data *stgt_priv_data;
> > +	struct mpi3mr_sdev_priv_data *sdev_priv_data;
> > +	struct scmd_priv *scmd_priv_data = NULL;
> > +	Mpi3SCSIIORequest_t *scsiio_req = NULL;
> > +	struct op_req_qinfo *op_req_q = NULL;
> >  	int retval = 0;
> > +	u16 dev_handle;
> > +	u16 host_tag;
> > +	u32 scsiio_flags = 0;
> > +	struct request *rq = scmd->request;
> > +	int iprio_class;
> > +
> > +	sdev_priv_data = scmd->device->hostdata;
> > +	if (!sdev_priv_data || !sdev_priv_data->tgt_priv_data) {
> > +		scmd->result = DID_NO_CONNECT << 16;
> > +		scmd->scsi_done(scmd);
> > +		goto out;
> > +	}
> >
> > -	scmd->result = DID_NO_CONNECT << 16;
> > -	scmd->scsi_done(scmd);
> > +	if (mrioc->stop_drv_processing) {
> > +		scmd->result = DID_NO_CONNECT << 16;
> > +		scmd->scsi_done(scmd);
> > +		goto out;
> > +	}
> Hi Kashyap,
> for what is the above test needed (stop_drv_processing) it looks like
other
> drivers don't need to protect exit function in this was (for example
mpt3sas).
Tomas, This driver code Is still under active development and I will
review this (marking as TBD).
Not only this area, but there are many more optimization possible in
mpi3mr driver.
We want to start with stable version of driver and gradually improve.
<mpi3mr> as multiple h/w queue support and mpt3sas is single queue h/w.
Due to some h/w differences we have noticed some issue are very frequent
for mp3mr vs mpt3sas.

We can opt other way around as well. We can remove this check now and when
we find the bug we can add the fix with root cause details.
Let me know if you are OK to keep this check now or add it whenever it is
required.

Kashyap

> Regards,
> Tomash

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4212 bytes --]

^ permalink raw reply	[flat|nested] 75+ messages in thread

* RE: [PATCH 06/24] mpi3mr: add support of event handling part-1
  2021-02-22 15:31   ` Tomas Henzl
@ 2021-02-25 13:36     ` Kashyap Desai
  0 siblings, 0 replies; 75+ messages in thread
From: Kashyap Desai @ 2021-02-25 13:36 UTC (permalink / raw)
  To: Tomas Henzl, linux-scsi
  Cc: jejb, martin.petersen, Steve Hagan, Peter Rivera,
	mpi3mr-drvr-developers, Sathya Prakash Veerichetty

[-- Attachment #1: Type: text/plain, Size: 1314 bytes --]

> ...
> > + */
> > +void mpi3mr_cleanup_fwevt_list(struct mpi3mr_ioc *mrioc) {
> > +	struct mpi3mr_fwevt *fwevt = NULL;
> > +
> > +	if ((list_empty(&mrioc->fwevt_list) && !mrioc->current_event) ||
> > +	    !mrioc->fwevt_worker_thread || in_interrupt())
> The in_interrup macro is deprecated and should not be used in new code.
> Is it at all possible to call the mpi3mr_cleanup_fwevt_list from
interrupt
> context?

I agree with you. In_interrupt() check is safe to remove. I will take care
while sending V2.

Kashyap
>
> > +		return;
> > +
> > +	while ((fwevt = mpi3mr_dequeue_fwevt(mrioc)) ||
> > +	    (fwevt = mrioc->current_event)) {
> > +		/*
> > +		 * Wait on the fwevt to complete. If this returns 1, then
> > +		 * the event was never executed, and we need a put for the
> > +		 * reference the work had on the fwevt.
> > +		 *
> > +		 * If it did execute, we wait for it to finish, and the
put will
> > +		 * happen from mpi3mr_process_fwevt()
> > +		 */
> > +		if (cancel_work_sync(&fwevt->work)) {
> > +			/*
> > +			 * Put fwevt reference count after
> > +			 * dequeuing it from worker queue
> > +			 */
> > +			mpi3mr_fwevt_put(fwevt);
> > +			/*
> > +			 * Put fwevt reference count to neutralize
> > +			 * kref_init increment
> > +			 */
> > +			mpi3mr_fwevt_put(fwevt);
> > +		}
> > +	}
> > +}

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4212 bytes --]

^ permalink raw reply	[flat|nested] 75+ messages in thread

* RE: [PATCH 21/24] mpi3mr: add support of PM suspend and resume
  2021-02-22 15:32   ` Tomas Henzl
@ 2021-02-25 13:37     ` Kashyap Desai
  0 siblings, 0 replies; 75+ messages in thread
From: Kashyap Desai @ 2021-02-25 13:37 UTC (permalink / raw)
  To: Tomas Henzl, linux-scsi
  Cc: jejb, martin.petersen, Steve Hagan, Peter Rivera,
	mpi3mr-drvr-developers, Sathya Prakash Veerichetty

[-- Attachment #1: Type: text/plain, Size: 2089 bytes --]

> -----Original Message-----
> From: Tomas Henzl [mailto:thenzl@redhat.com]
> Sent: Monday, February 22, 2021 9:03 PM
> To: Kashyap Desai <kashyap.desai@broadcom.com>; linux-
> scsi@vger.kernel.org
> Cc: jejb@linux.ibm.com; martin.petersen@oracle.com;
> steve.hagan@broadcom.com; peter.rivera@broadcom.com; mpi3mr-
> linuxdrv.pdl@broadcom.com; sathya.prakash@broadcom.com
> Subject: Re: [PATCH 21/24] mpi3mr: add support of PM suspend and resume
>
> On 12/22/20 11:11 AM, Kashyap Desai wrote:
> > Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
> > Cc: sathya.prakash@broadcom.com
> > ---
> >  drivers/scsi/mpi3mr/mpi3mr_os.c | 85
> > +++++++++++++++++++++++++++++++++
> >  1 file changed, 85 insertions(+)
> >
> > diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c
> > b/drivers/scsi/mpi3mr/mpi3mr_os.c index 1708aca1a5cd..ac47eed74705
> > 100644
> > --- a/drivers/scsi/mpi3mr/mpi3mr_os.c
> > +++ b/drivers/scsi/mpi3mr/mpi3mr_os.c
> ...
> > +/**
> > + * mpi3mr_resume - PCI power management resume callback
> > + * @pdev: PCI device instance
> > + *
> > + * Restore the power state to D0 and reinitialize the controller
> > + * and resume I/O operations to the target devices
> > + *
> > + * Return: 0 on success, non-zero on failure  */ static int
> > +mpi3mr_resume(struct pci_dev *pdev) {
> > +	struct Scsi_Host *shost = pci_get_drvdata(pdev);
> > +	struct mpi3mr_ioc *mrioc;
> > +	pci_power_t device_state = pdev->current_state;
> > +	int r;
> > +
> > +	mrioc = shost_priv(shost);
> > +
> > +	ioc_info(mrioc, "pdev=0x%p, slot=%s, previous operating state
> [D%d]\n",
> > +	    pdev, pci_name(pdev), device_state);
> > +	pci_set_power_state(pdev, PCI_D0);
> > +	pci_enable_wake(pdev, PCI_D0, 0);
> > +	pci_restore_state(pdev);
> > +	mrioc->pdev = pdev;
> > +	mrioc->cpu_count = num_online_cpus();
> > +	r = mpi3mr_setup_resources(mrioc);
> > +	if (r) {
> > +		ioc_info(mrioc, "%s: Setup resoruces failed[%d]\n",
>
> A typo 					here ^

Noted. I will fix it in V2. I will scan all the patch for such things one
more time.

Kashyap

> > +		    __func__, r);
> > +		return r;
> > +	}

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4212 bytes --]

^ permalink raw reply	[flat|nested] 75+ messages in thread

* RE: [PATCH 23/24] mpi3mr: add eedp dif dix support
  2021-02-22 15:37   ` Tomas Henzl
@ 2021-02-25 13:39     ` Kashyap Desai
  0 siblings, 0 replies; 75+ messages in thread
From: Kashyap Desai @ 2021-02-25 13:39 UTC (permalink / raw)
  To: Tomas Henzl, linux-scsi
  Cc: jejb, martin.petersen, Steve Hagan, Peter Rivera,
	mpi3mr-drvr-developers, Sathya Prakash Veerichetty

[-- Attachment #1: Type: text/plain, Size: 1968 bytes --]

> -----Original Message-----
> From: Tomas Henzl [mailto:thenzl@redhat.com]
> Sent: Monday, February 22, 2021 9:07 PM
> To: Kashyap Desai <kashyap.desai@broadcom.com>; linux-
> scsi@vger.kernel.org
> Cc: jejb@linux.ibm.com; martin.petersen@oracle.com;
> steve.hagan@broadcom.com; peter.rivera@broadcom.com; mpi3mr-
> linuxdrv.pdl@broadcom.com; sathya.prakash@broadcom.com
> Subject: Re: [PATCH 23/24] mpi3mr: add eedp dif dix support
>
> On 12/22/20 11:11 AM, Kashyap Desai wrote:
> > Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
> > Cc: sathya.prakash@broadcom.com
> > ---
> >  drivers/scsi/mpi3mr/mpi3mr.h    |  18 +-
> >  drivers/scsi/mpi3mr/mpi3mr_fw.c |   7 +
> >  drivers/scsi/mpi3mr/mpi3mr_os.c | 303
> > +++++++++++++++++++++++++++++++-
> >  3 files changed, 321 insertions(+), 7 deletions(-)
> >
> > diff --git a/drivers/scsi/mpi3mr/mpi3mr.h
> > b/drivers/scsi/mpi3mr/mpi3mr.h index f0ead83dc16c..acc5649bed5f
> 100644
> > --- a/drivers/scsi/mpi3mr/mpi3mr.h
> > +++ b/drivers/scsi/mpi3mr/mpi3mr.h
> > @@ -118,6 +118,7 @@ extern struct list_head mrioc_list;
> >  #define MPI3MR_SENSEBUF_SZ	256
> >  #define MPI3MR_SENSEBUF_FACTOR	3
> >  #define MPI3MR_CHAINBUF_FACTOR	3
> > +#define MPI3MR_CHAINBUFDIX_FACTOR	2
> >
> >  /* Invalid target device handle */
> >  #define MPI3MR_INVALID_DEV_HANDLE	0xFFFF
> > @@ -145,6 +146,15 @@ extern struct list_head mrioc_list;
> >  /* Default target device queue depth */
> >  #define MPI3MR_DEFAULT_SDEV_QD	32
> >
> > +/* Definitions for the sector size for EEDP */
> > +#define MPI3_SECTOR_SIZE_512_BYTE	(512)
> > +#define MPI3_SECTOR_SIZE_520_BYTE	(520)
> > +#define MPI3_SECTOR_SIZE_4080_BYTE	(4080)
> > +#define MPI3_SECTOR_SIZE_4088_BYTE	(4088)
> > +#define MPI3_SECTOR_SIZE_4096_BYTE	(4096)
> > +#define MPI3_SECTOR_SIZE_4104_BYTE	(4104)
> > +#define MPI3_SECTOR_SIZE_4160_BYTE	(4160)
> > +
>
> This looks weird, please use the values directly instead of creating
macros.

I will change in V2.
>
> tomash

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4212 bytes --]

^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 04/24] mpi3mr: add support of queue command processing
  2021-02-25 13:24     ` Kashyap Desai
@ 2021-02-25 14:11       ` Tomas Henzl
  0 siblings, 0 replies; 75+ messages in thread
From: Tomas Henzl @ 2021-02-25 14:11 UTC (permalink / raw)
  To: Kashyap Desai, linux-scsi
  Cc: jejb, martin.petersen, Steve Hagan, Peter Rivera,
	mpi3mr-drvr-developers, Sathya Prakash Veerichetty

On 2/25/21 2:24 PM, Kashyap Desai wrote:
>>>   * mpi3mr_slave_destroy - Slave destroy callback handler
>>>   * @sdev: SCSI device reference
>>> @@ -126,10 +658,114 @@ static int mpi3mr_target_alloc(struct
>>> scsi_target *starget)  static int mpi3mr_qcmd(struct Scsi_Host *shost,
>>>  	struct scsi_cmnd *scmd)
>>>  {
>>> +	struct mpi3mr_ioc *mrioc = shost_priv(shost);
>>> +	struct mpi3mr_stgt_priv_data *stgt_priv_data;
>>> +	struct mpi3mr_sdev_priv_data *sdev_priv_data;
>>> +	struct scmd_priv *scmd_priv_data = NULL;
>>> +	Mpi3SCSIIORequest_t *scsiio_req = NULL;
>>> +	struct op_req_qinfo *op_req_q = NULL;
>>>  	int retval = 0;
>>> +	u16 dev_handle;
>>> +	u16 host_tag;
>>> +	u32 scsiio_flags = 0;
>>> +	struct request *rq = scmd->request;
>>> +	int iprio_class;
>>> +
>>> +	sdev_priv_data = scmd->device->hostdata;
>>> +	if (!sdev_priv_data || !sdev_priv_data->tgt_priv_data) {
>>> +		scmd->result = DID_NO_CONNECT << 16;
>>> +		scmd->scsi_done(scmd);
>>> +		goto out;
>>> +	}
>>>
>>> -	scmd->result = DID_NO_CONNECT << 16;
>>> -	scmd->scsi_done(scmd);
>>> +	if (mrioc->stop_drv_processing) {
>>> +		scmd->result = DID_NO_CONNECT << 16;
>>> +		scmd->scsi_done(scmd);
>>> +		goto out;
>>> +	}
>> Hi Kashyap,
>> for what is the above test needed (stop_drv_processing) it looks like
> other
>> drivers don't need to protect exit function in this was (for example
> mpt3sas).
> Tomas, This driver code Is still under active development and I will
> review this (marking as TBD).
> Not only this area, but there are many more optimization possible in
> mpi3mr driver.
> We want to start with stable version of driver and gradually improve.
> <mpi3mr> as multiple h/w queue support and mpt3sas is single queue h/w.
> Due to some h/w differences we have noticed some issue are very frequent
> for mp3mr vs mpt3sas.
> 
> We can opt other way around as well. We can remove this check now and when
> we find the bug we can add the fix with root cause details.
> Let me know if you are OK to keep this check now or add it whenever it is
> required.

You may keep it as it is and remove later if you think that it is safer.
I was only curious how this could be triggered.


> 
> Kashyap
> 
>> Regards,
>> Tomash


^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 03/24] mpi3mr: create operational request and reply queue pair
  2020-12-22 10:11 ` [PATCH 03/24] mpi3mr: create operational request and reply queue pair Kashyap Desai
  2020-12-22 18:18   ` Bart Van Assche
@ 2021-02-28 13:04   ` Hannes Reinecke
  2021-03-02 19:05     ` Kashyap Desai
  1 sibling, 1 reply; 75+ messages in thread
From: Hannes Reinecke @ 2021-02-28 13:04 UTC (permalink / raw)
  To: Kashyap Desai, linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, sathya.prakash

On 12/22/20 11:11 AM, Kashyap Desai wrote:
> Create operational request and reply queue pair.
> 
> The MPI3 transport interface consists of an Administrative Request Queue,
> an Administrative Reply Queue, and Operational Messaging Queues.
> The Operational Messaging Queues are the primary communication mechanism
> between the host and the I/O Controller (IOC).
> Request messages, allocated in host memory, identify I/O operations to be
> performed by the IOC. These operations are queued on an Operational
> Request Queue by the host driver.
> Reply descriptors track I/O operations as they complete.
> The IOC queues these completions in an Operational Reply Queue.
> 
> To fulfil large contiguous memory requirement, driver creates multiple
> segments and provide the list of segments. Each segment size should be 4K
> which is h/w requirement. An element array is contiguous or segmented.
> A contiguous element array is located in contiguous physical memory.
> A contiguous element array must be aligned on an element size boundary.
> An element's physical address within the array may be directly calculated
> from the base address, the Producer/Consumer index, and the element size.
> 
> Expected phased identifier bit is used to find out valid entry on reply queue.
> Driver set <ephase> bit and IOC invert the value of this bit on each pass.
> 
> Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
> Cc: sathya.prakash@broadcom.com
> ---
>   drivers/scsi/mpi3mr/mpi3mr.h    |  56 +++
>   drivers/scsi/mpi3mr/mpi3mr_fw.c | 601 ++++++++++++++++++++++++++++++++
>   drivers/scsi/mpi3mr/mpi3mr_os.c |   4 +-
>   3 files changed, 660 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/scsi/mpi3mr/mpi3mr.h b/drivers/scsi/mpi3mr/mpi3mr.h
> index dd79b12218e1..fe6094bb357a 100644
> --- a/drivers/scsi/mpi3mr/mpi3mr.h
> +++ b/drivers/scsi/mpi3mr/mpi3mr.h
> @@ -71,6 +71,12 @@ extern struct list_head mrioc_list;
>   #define MPI3MR_ADMIN_REQ_FRAME_SZ	128
>   #define MPI3MR_ADMIN_REPLY_FRAME_SZ	16
>   
> +/* Operational queue management definitions */
> +#define MPI3MR_OP_REQ_Q_QD		512
> +#define MPI3MR_OP_REP_Q_QD		4096
> +#define MPI3MR_OP_REQ_Q_SEG_SIZE	4096
> +#define MPI3MR_OP_REP_Q_SEG_SIZE	4096
> +#define MPI3MR_MAX_SEG_LIST_SIZE	4096
>   
Do I read this correctly?
The reply queue depth is larger than the request queue depth?
Why is that?

>   /* Reserved Host Tag definitions */
>   #define MPI3MR_HOSTTAG_INVALID		0xFFFF
> @@ -132,6 +138,9 @@ extern struct list_head mrioc_list;
>   	(MPI3_SGE_FLAGS_ELEMENT_TYPE_SIMPLE | MPI3_SGE_FLAGS_DLAS_SYSTEM | \
>   	MPI3_SGE_FLAGS_END_OF_LIST)
>   
> +/* MSI Index from Reply Queue Index */
> +#define REPLY_QUEUE_IDX_TO_MSIX_IDX(qidx, offset)	(qidx + offset)
> +
>   /* IOC State definitions */
>   enum mpi3mr_iocstate {
>   	MRIOC_STATE_READY = 1,
> @@ -222,15 +231,45 @@ struct mpi3mr_ioc_facts {
>   	u8 sge_mod_shift;
>   };
>   
> +/**
> + * struct segments - memory descriptor structure to store
> + * virtual and dma addresses for operational queue segments.
> + *
> + * @segment: virtual address
> + * @segment_dma: dma address
> + */
> +struct segments {
> +	void *segment;
> +	dma_addr_t segment_dma;
> +};
> +
>   /**
>    * struct op_req_qinfo -  Operational Request Queue Information
>    *
>    * @ci: consumer index
>    * @pi: producer index
> + * @num_request: Maximum number of entries in the queue
> + * @qid: Queue Id starting from 1
> + * @reply_qid: Associated reply queue Id
> + * @num_segments: Number of discontiguous memory segments
> + * @segment_qd: Depth of each segments
> + * @q_lock: Concurrent queue access lock
> + * @q_segments: Segment descriptor pointer
> + * @q_segment_list: Segment list base virtual address
> + * @q_segment_list_dma: Segment list base DMA address
>    */
>   struct op_req_qinfo {
>   	u16 ci;
>   	u16 pi;
> +	u16 num_requests;
> +	u16 qid;
> +	u16 reply_qid;
> +	u16 num_segments;
> +	u16 segment_qd;
> +	spinlock_t q_lock;
> +	struct segments *q_segments;
> +	void *q_segment_list;
> +	dma_addr_t q_segment_list_dma;
>   };
>   
>   /**
> @@ -238,10 +277,24 @@ struct op_req_qinfo {
>    *
>    * @ci: consumer index
>    * @qid: Queue Id starting from 1
> + * @num_replies: Maximum number of entries in the queue
> + * @num_segments: Number of discontiguous memory segments
> + * @segment_qd: Depth of each segments
> + * @q_segments: Segment descriptor pointer
> + * @q_segment_list: Segment list base virtual address
> + * @q_segment_list_dma: Segment list base DMA address
> + * @ephase: Expected phased identifier for the reply queue
>    */
>   struct op_reply_qinfo {
>   	u16 ci;
>   	u16 qid;
> +	u16 num_replies;
> +	u16 num_segments;
> +	u16 segment_qd;
> +	struct segments *q_segments;
> +	void *q_segment_list;
> +	dma_addr_t q_segment_list_dma;
> +	u8 ephase;
>   };
>   
>   /**
> @@ -402,6 +455,7 @@ struct scmd_priv {
>    * @current_event: Firmware event currently in process
>    * @driver_info: Driver, Kernel, OS information to firmware
>    * @change_count: Topology change count
> + * @op_reply_q_offset: Operational reply queue offset with MSIx
>    */
>   struct mpi3mr_ioc {
>   	struct list_head list;
> @@ -409,6 +463,7 @@ struct mpi3mr_ioc {
>   	struct Scsi_Host *shost;
>   	u8 id;
>   	int cpu_count;
> +	bool enable_segqueue;
>   
>   	char name[MPI3MR_NAME_LENGTH];
>   	char driver_name[MPI3MR_NAME_LENGTH];
> @@ -495,6 +550,7 @@ struct mpi3mr_ioc {
>   	struct mpi3mr_fwevt *current_event;
>   	Mpi3DriverInfoLayout_t driver_info;
>   	u16 change_count;
> +	u16 op_reply_q_offset;
>   };
>   
>   int mpi3mr_setup_resources(struct mpi3mr_ioc *mrioc);
> diff --git a/drivers/scsi/mpi3mr/mpi3mr_fw.c b/drivers/scsi/mpi3mr/mpi3mr_fw.c
> index 97eb7e6ec5c6..6fb28983038e 100644
> --- a/drivers/scsi/mpi3mr/mpi3mr_fw.c
> +++ b/drivers/scsi/mpi3mr/mpi3mr_fw.c
> @@ -408,6 +408,8 @@ static int mpi3mr_setup_isr(struct mpi3mr_ioc *mrioc, u8 setup_one)
>   
>   	irq_flags |= PCI_IRQ_AFFINITY | PCI_IRQ_ALL_TYPES;
>   
> +	mrioc->op_reply_q_offset = (max_vectors > 1) ? 1 : 0;
> +
>   	i = pci_alloc_irq_vectors_affinity(mrioc->pdev,
>   	    1, max_vectors, irq_flags, &desc);
>   	if (i <= 0) {
> @@ -418,6 +420,12 @@ static int mpi3mr_setup_isr(struct mpi3mr_ioc *mrioc, u8 setup_one)
>   		ioc_info(mrioc,
>   		    "allocated vectors (%d) are less than configured (%d)\n",
>   		    i, max_vectors);
> +		/*
> +		 * If only one MSI-x is allocated, then MSI-x 0 will be shared
> +		 * between Admin queue and operational queue
> +		 */
> +		if (i == 1)
> +			mrioc->op_reply_q_offset = 0;
>   
>   		max_vectors = i;
>   	}
> @@ -726,6 +734,586 @@ int mpi3mr_admin_request_post(struct mpi3mr_ioc *mrioc, void *admin_req,
>   	return retval;
>   }
>   
> +/**
> + * mpi3mr_free_op_req_q_segments - free request memory segments
> + * @mrioc: Adapter instance reference
> + * @q_idx: operational request queue index
> + *
> + * Free memory segments allocated for operational request queue
> + *
> + * Return: Nothing.
> + */
> +static void mpi3mr_free_op_req_q_segments(struct mpi3mr_ioc *mrioc, u16 q_idx)
> +{
> +	u16 j;
> +	int size;
> +	struct segments *segments;
> +
> +	segments = mrioc->req_qinfo[q_idx].q_segments;
> +	if (!segments)
> +		return;
> +
> +	if (mrioc->enable_segqueue) {
> +		size = MPI3MR_OP_REQ_Q_SEG_SIZE;
> +		if (mrioc->req_qinfo[q_idx].q_segment_list) {
> +			dma_free_coherent(&mrioc->pdev->dev,
> +			    MPI3MR_MAX_SEG_LIST_SIZE,
> +			    mrioc->req_qinfo[q_idx].q_segment_list,
> +			    mrioc->req_qinfo[q_idx].q_segment_list_dma);
> +			mrioc->op_reply_qinfo[q_idx].q_segment_list = NULL;
> +		}
> +	} else
> +		size = mrioc->req_qinfo[q_idx].num_requests *
> +		    mrioc->facts.op_req_sz;
> +
> +	for (j = 0; j < mrioc->req_qinfo[q_idx].num_segments; j++) {
> +		if (!segments[j].segment)
> +			continue;
> +		dma_free_coherent(&mrioc->pdev->dev,
> +		    size, segments[j].segment, segments[j].segment_dma);
> +		segments[j].segment = NULL;
> +	}
> +	kfree(mrioc->req_qinfo[q_idx].q_segments);
> +	mrioc->req_qinfo[q_idx].q_segments = NULL;
> +	mrioc->req_qinfo[q_idx].qid = 0;
> +}
> +
> +/**
> + * mpi3mr_free_op_reply_q_segments - free reply memory segments
> + * @mrioc: Adapter instance reference
> + * @q_idx: operational reply queue index
> + *
> + * Free memory segments allocated for operational reply queue
> + *
> + * Return: Nothing.
> + */
> +static void mpi3mr_free_op_reply_q_segments(struct mpi3mr_ioc *mrioc, u16 q_idx)
> +{
> +	u16 j;
> +	int size;
> +	struct segments *segments;
> +
> +	segments = mrioc->op_reply_qinfo[q_idx].q_segments;
> +	if (!segments)
> +		return;
> +
> +	if (mrioc->enable_segqueue) {
> +		size = MPI3MR_OP_REP_Q_SEG_SIZE;
> +		if (mrioc->op_reply_qinfo[q_idx].q_segment_list) {
> +			dma_free_coherent(&mrioc->pdev->dev,
> +			    MPI3MR_MAX_SEG_LIST_SIZE,
> +			    mrioc->op_reply_qinfo[q_idx].q_segment_list,
> +			    mrioc->op_reply_qinfo[q_idx].q_segment_list_dma);
> +			mrioc->op_reply_qinfo[q_idx].q_segment_list = NULL;
> +		}
> +	} else
> +		size = mrioc->op_reply_qinfo[q_idx].segment_qd *
> +		    mrioc->op_reply_desc_sz;
> +
> +	for (j = 0; j < mrioc->op_reply_qinfo[q_idx].num_segments; j++) {
> +		if (!segments[j].segment)
> +			continue;
> +		dma_free_coherent(&mrioc->pdev->dev,
> +		    size, segments[j].segment, segments[j].segment_dma);
> +		segments[j].segment = NULL;
> +	}
> +
> +	kfree(mrioc->op_reply_qinfo[q_idx].q_segments);
> +	mrioc->op_reply_qinfo[q_idx].q_segments = NULL;
> +	mrioc->op_reply_qinfo[q_idx].qid = 0;
> +}
> +
> +/**
> + * mpi3mr_delete_op_reply_q - delete operational reply queue
> + * @mrioc: Adapter instance reference
> + * @qidx: operational reply queue index
> + *
> + * Delete operatinal reply queue by issuing MPI request
> + * through admin queue.
> + *
> + * Return:  0 on success, non-zero on failure.
> + */
> +static int mpi3mr_delete_op_reply_q(struct mpi3mr_ioc *mrioc, u16 qidx)
> +{
> +	Mpi3DeleteReplyQueueRequest_t delq_req;
> +	int retval = 0;
> +	u16 reply_qid = 0, midx;
> +
> +	reply_qid = mrioc->op_reply_qinfo[qidx].qid;
> +
> +	midx = REPLY_QUEUE_IDX_TO_MSIX_IDX(qidx, mrioc->op_reply_q_offset);
> +
> +	if (!reply_qid)	{
> +		retval = -1;
> +		ioc_err(mrioc, "Issue DelRepQ: called with invalid ReqQID\n");
> +		goto out;
> +	}
> +
> +	memset(&delq_req, 0, sizeof(delq_req));
> +	mutex_lock(&mrioc->init_cmds.mutex);
> +	if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
> +		retval = -1;
> +		ioc_err(mrioc, "Issue DelRepQ: Init command is in use\n");
> +		mutex_unlock(&mrioc->init_cmds.mutex);
> +		goto out;
> +	}
> +	mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
> +	mrioc->init_cmds.is_waiting = 1;
> +	mrioc->init_cmds.callback = NULL;
> +	delq_req.HostTag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
> +	delq_req.Function = MPI3_FUNCTION_DELETE_REPLY_QUEUE;
> +	delq_req.QueueID = cpu_to_le16(reply_qid);
> +
> +	init_completion(&mrioc->init_cmds.done);
> +	retval = mpi3mr_admin_request_post(mrioc, &delq_req, sizeof(delq_req),
> +	    1);
> +	if (retval) {
> +		ioc_err(mrioc, "Issue DelRepQ: Admin Post failed\n");
> +		goto out_unlock;
> +	}
> +	wait_for_completion_timeout(&mrioc->init_cmds.done,
> +	    (MPI3MR_INTADMCMD_TIMEOUT * HZ));
> +	if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
> +		ioc_err(mrioc, "Issue DelRepQ: command timed out\n");
> +		mpi3mr_set_diagsave(mrioc);
> +		mpi3mr_issue_reset(mrioc,
> +		    MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT,
> +		    MPI3MR_RESET_FROM_DELREPQ_TIMEOUT);
> +		mrioc->unrecoverable = 1;
> +
> +		retval = -1;
> +		goto out_unlock;
> +	}
> +	if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
> +	    != MPI3_IOCSTATUS_SUCCESS) {
> +		ioc_err(mrioc,
> +		    "Issue DelRepQ: Failed IOCStatus(0x%04x) Loginfo(0x%08x)\n",
> +		    (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
> +		    mrioc->init_cmds.ioc_loginfo);
> +		retval = -1;
> +		goto out_unlock;
> +	}
> +	mrioc->intr_info[midx].op_reply_q = NULL;
> +
> +	mpi3mr_free_op_reply_q_segments(mrioc, qidx);
> +out_unlock:
> +	mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
> +	mutex_unlock(&mrioc->init_cmds.mutex);
> +out:
> +
> +	return retval;
> +}
> +
> +/**
> + * mpi3mr_alloc_op_reply_q_segments -Alloc segmented reply pool
> + * @mrioc: Adapter instance reference
> + * @qidx: request queue index
> + *
> + * Allocate segmented memory pools for operational reply
> + * queue.
> + *
> + * Return: 0 on success, non-zero on failure.
> + */
> +static int mpi3mr_alloc_op_reply_q_segments(struct mpi3mr_ioc *mrioc, u16 qidx)
> +{
> +	struct op_reply_qinfo *op_reply_q = mrioc->op_reply_qinfo + qidx;
> +	int i, size;
> +	u64 *q_segment_list_entry = NULL;
> +	struct segments *segments;
> +
> +	if (mrioc->enable_segqueue) {
> +		op_reply_q->segment_qd =
> +		    MPI3MR_OP_REP_Q_SEG_SIZE / mrioc->op_reply_desc_sz;
> +
> +		size = MPI3MR_OP_REP_Q_SEG_SIZE;
> +
> +		op_reply_q->q_segment_list = dma_alloc_coherent(&mrioc->pdev->dev,
> +		    MPI3MR_MAX_SEG_LIST_SIZE, &op_reply_q->q_segment_list_dma,
> +		    GFP_KERNEL);
> +		if (!op_reply_q->q_segment_list)
> +			return -ENOMEM;
> +		q_segment_list_entry = (u64 *)op_reply_q->q_segment_list;
> +	} else {
> +		op_reply_q->segment_qd = op_reply_q->num_replies;
> +		size = op_reply_q->num_replies * mrioc->op_reply_desc_sz;
> +	}
> +
> +	op_reply_q->num_segments = DIV_ROUND_UP(op_reply_q->num_replies,
> +	    op_reply_q->segment_qd);
> +
> +	op_reply_q->q_segments = kcalloc(op_reply_q->num_segments,
> +	    sizeof(struct segments), GFP_KERNEL);
> +	if (!op_reply_q->q_segments)
> +		return -ENOMEM;
> +
> +	segments = op_reply_q->q_segments;
> +	for (i = 0; i < op_reply_q->num_segments; i++) {
> +		segments[i].segment =
> +		    dma_alloc_coherent(&mrioc->pdev->dev,
> +		    size, &segments[i].segment_dma, GFP_KERNEL);
> +		if (!segments[i].segment)
> +			return -ENOMEM;
> +		if (mrioc->enable_segqueue)
> +			q_segment_list_entry[i] =
> +			    (unsigned long)segments[i].segment_dma;
> +	}
> +
> +	return 0;
> +}
> +
> +/**
> + * mpi3mr_alloc_op_req_q_segments - Alloc segmented req pool.
> + * @mrioc: Adapter instance reference
> + * @qidx: request queue index
> + *
> + * Allocate segmented memory pools for operational request
> + * queue.
> + *
> + * Return: 0 on success, non-zero on failure.
> + */
> +static int mpi3mr_alloc_op_req_q_segments(struct mpi3mr_ioc *mrioc, u16 qidx)
> +{
> +	struct op_req_qinfo *op_req_q = mrioc->req_qinfo + qidx;
> +	int i, size;
> +	u64 *q_segment_list_entry = NULL;
> +	struct segments *segments;
> +
> +	if (mrioc->enable_segqueue) {
> +		op_req_q->segment_qd =
> +		    MPI3MR_OP_REQ_Q_SEG_SIZE / mrioc->facts.op_req_sz;
> +
> +		size = MPI3MR_OP_REQ_Q_SEG_SIZE;
> +
> +		op_req_q->q_segment_list = dma_alloc_coherent(&mrioc->pdev->dev,
> +		    MPI3MR_MAX_SEG_LIST_SIZE, &op_req_q->q_segment_list_dma,
> +		    GFP_KERNEL);
> +		if (!op_req_q->q_segment_list)
> +			return -ENOMEM;
> +		q_segment_list_entry = (u64 *)op_req_q->q_segment_list;
> +
> +	} else {
> +		op_req_q->segment_qd = op_req_q->num_requests;
> +		size = op_req_q->num_requests * mrioc->facts.op_req_sz;
> +	}
> +
> +	op_req_q->num_segments = DIV_ROUND_UP(op_req_q->num_requests,
> +	    op_req_q->segment_qd);
> +
> +	op_req_q->q_segments = kcalloc(op_req_q->num_segments,
> +	    sizeof(struct segments), GFP_KERNEL);
> +	if (!op_req_q->q_segments)
> +		return -ENOMEM;
> +
> +	segments = op_req_q->q_segments;
> +	for (i = 0; i < op_req_q->num_segments; i++) {
> +		segments[i].segment =
> +		    dma_alloc_coherent(&mrioc->pdev->dev,
> +		    size, &segments[i].segment_dma, GFP_KERNEL);
> +		if (!segments[i].segment)
> +			return -ENOMEM;
> +		if (mrioc->enable_segqueue)
> +			q_segment_list_entry[i] =
> +			    (unsigned long)segments[i].segment_dma;
> +	}
> +
> +	return 0;
> +}
> +
> +/**
> + * mpi3mr_create_op_reply_q - create operational reply queue
> + * @mrioc: Adapter instance reference
> + * @qidx: operational reply queue index
> + *
> + * Create operatinal reply queue by issuing MPI request
> + * through admin queue.
> + *
> + * Return:  0 on success, non-zero on failure.
> + */
> +static int mpi3mr_create_op_reply_q(struct mpi3mr_ioc *mrioc, u16 qidx)
> +{
> +	Mpi3CreateReplyQueueRequest_t create_req;
> +	struct op_reply_qinfo *op_reply_q = mrioc->op_reply_qinfo + qidx;
> +	int retval = 0;
> +	u16 reply_qid = 0, midx;
> +
> +
> +	reply_qid = op_reply_q->qid;
> +
> +	midx = REPLY_QUEUE_IDX_TO_MSIX_IDX(qidx, mrioc->op_reply_q_offset);
> +
> +	if (reply_qid) {
> +		retval = -1;
> +		ioc_err(mrioc, "CreateRepQ: called for duplicate qid %d\n",
> +		    reply_qid);
> +
> +		return retval;
> +	}
> +
> +	reply_qid = qidx + 1;
> +	op_reply_q->num_replies = MPI3MR_OP_REP_Q_QD;
> +	op_reply_q->ci = 0;
> +	op_reply_q->ephase = 1;
> +
> +	if (!op_reply_q->q_segments) {
> +		retval = mpi3mr_alloc_op_reply_q_segments(mrioc, qidx);
> +		if (retval) {
> +			mpi3mr_free_op_reply_q_segments(mrioc, qidx);
> +			goto out;
> +		}
> +	}
> +
> +	memset(&create_req, 0, sizeof(create_req));
> +	mutex_lock(&mrioc->init_cmds.mutex);
> +	if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
> +		retval = -1;
> +		ioc_err(mrioc, "CreateRepQ: Init command is in use\n");
> +		goto out;
> +	}
> +	mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
> +	mrioc->init_cmds.is_waiting = 1;
> +	mrioc->init_cmds.callback = NULL;
> +	create_req.HostTag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
> +	create_req.Function = MPI3_FUNCTION_CREATE_REPLY_QUEUE;
> +	create_req.QueueID = cpu_to_le16(reply_qid);
> +	create_req.Flags = MPI3_CREATE_REPLY_QUEUE_FLAGS_INT_ENABLE_ENABLE;
> +	create_req.MSIxIndex = cpu_to_le16(mrioc->intr_info[midx].msix_index);
> +	if (mrioc->enable_segqueue) {
> +		create_req.Flags |=
> +		    MPI3_CREATE_REQUEST_QUEUE_FLAGS_SEGMENTED_SEGMENTED;
> +		create_req.BaseAddress = cpu_to_le64(
> +		    op_reply_q->q_segment_list_dma);
> +	} else
> +		create_req.BaseAddress = cpu_to_le64(
> +		    op_reply_q->q_segments[0].segment_dma);
> +
> +	create_req.Size = cpu_to_le16(op_reply_q->num_replies);
> +
> +	init_completion(&mrioc->init_cmds.done);
> +	retval = mpi3mr_admin_request_post(mrioc, &create_req,
> +	    sizeof(create_req), 1);
> +	if (retval) {
> +		ioc_err(mrioc, "CreateRepQ: Admin Post failed\n");
> +		goto out_unlock;
> +	}
> +	wait_for_completion_timeout(&mrioc->init_cmds.done,
> +	    (MPI3MR_INTADMCMD_TIMEOUT * HZ));
> +	if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
> +		ioc_err(mrioc, "CreateRepQ: command timed out\n");
> +		mpi3mr_set_diagsave(mrioc);
> +		mpi3mr_issue_reset(mrioc,
> +		    MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT,
> +		    MPI3MR_RESET_FROM_CREATEREPQ_TIMEOUT);
> +		mrioc->unrecoverable = 1;
> +		retval = -1;
> +		goto out_unlock;
> +	}
> +	if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
> +	    != MPI3_IOCSTATUS_SUCCESS) {
> +		ioc_err(mrioc,
> +		    "CreateRepQ: Failed IOCStatus(0x%04x) Loginfo(0x%08x)\n",
> +		    (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
> +		    mrioc->init_cmds.ioc_loginfo);
> +		retval = -1;
> +		goto out_unlock;
> +	}
> +	op_reply_q->qid = reply_qid;
> +	mrioc->intr_info[midx].op_reply_q = op_reply_q;
> +
> +out_unlock:
> +	mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
> +	mutex_unlock(&mrioc->init_cmds.mutex);
> +out:
> +
> +	return retval;
> +}
> +
> +/**
> + * mpi3mr_create_op_req_q - create operational request queue
> + * @mrioc: Adapter instance reference
> + * @idx: operational request queue index
> + * @reply_qid: Reply queue ID
> + *
> + * Create operatinal request queue by issuing MPI request
> + * through admin queue.
> + *
> + * Return:  0 on success, non-zero on failure.
> + */
> +static int mpi3mr_create_op_req_q(struct mpi3mr_ioc *mrioc, u16 idx,
> +	u16 reply_qid)
> +{
> +	Mpi3CreateRequestQueueRequest_t create_req;
> +	struct op_req_qinfo *op_req_q = mrioc->req_qinfo + idx;
> +	int retval = 0;
> +	u16 req_qid = 0;
> +
> +
> +	req_qid = op_req_q->qid;
> +
> +	if (req_qid) {
> +		retval = -1;
> +		ioc_err(mrioc, "CreateReqQ: called for duplicate qid %d\n",
> +		    req_qid);
> +
> +		return retval;
> +	}
> +	req_qid = idx + 1;
> +
> +	op_req_q->num_requests = MPI3MR_OP_REQ_Q_QD;
> +	op_req_q->ci = 0;
> +	op_req_q->pi = 0;
> +	op_req_q->reply_qid = reply_qid;
> +	spin_lock_init(&op_req_q->q_lock);
> +
> +	if (!op_req_q->q_segments) {
> +		retval = mpi3mr_alloc_op_req_q_segments(mrioc, idx);
> +		if (retval) {
> +			mpi3mr_free_op_req_q_segments(mrioc, idx);
> +			goto out;
> +		}
> +	}
> +
> +	memset(&create_req, 0, sizeof(create_req));
> +	mutex_lock(&mrioc->init_cmds.mutex);
> +	if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
> +		retval = -1;
> +		ioc_err(mrioc, "CreateReqQ: Init command is in use\n");
> +		goto out;
> +	}
> +	mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
> +	mrioc->init_cmds.is_waiting = 1;
> +	mrioc->init_cmds.callback = NULL;
> +	create_req.HostTag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
> +	create_req.Function = MPI3_FUNCTION_CREATE_REQUEST_QUEUE;
> +	create_req.QueueID = cpu_to_le16(req_qid);
> +	if (mrioc->enable_segqueue) {
> +		create_req.Flags =
> +		    MPI3_CREATE_REQUEST_QUEUE_FLAGS_SEGMENTED_SEGMENTED;
> +		create_req.BaseAddress = cpu_to_le64(
> +		    op_req_q->q_segment_list_dma);
> +	} else
> +		create_req.BaseAddress = cpu_to_le64(
> +		    op_req_q->q_segments[0].segment_dma);
> +	create_req.ReplyQueueID = cpu_to_le16(reply_qid);
> +	create_req.Size = cpu_to_le16(op_req_q->num_requests);
> +
> +	init_completion(&mrioc->init_cmds.done);
> +	retval = mpi3mr_admin_request_post(mrioc, &create_req,
> +	    sizeof(create_req), 1);
> +	if (retval) {
> +		ioc_err(mrioc, "CreateReqQ: Admin Post failed\n");
> +		goto out_unlock;
> +	}
> +	wait_for_completion_timeout(&mrioc->init_cmds.done,
> +	    (MPI3MR_INTADMCMD_TIMEOUT * HZ));
> +	if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
> +		ioc_err(mrioc, "CreateReqQ: command timed out\n");
> +		mpi3mr_set_diagsave(mrioc);
> +		if (mpi3mr_issue_reset(mrioc,
> +		    MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT,
> +		    MPI3MR_RESET_FROM_CREATEREQQ_TIMEOUT))
> +			mrioc->unrecoverable = 1;
> +		retval = -1;
> +		goto out_unlock;
> +	}
> +	if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
> +	    != MPI3_IOCSTATUS_SUCCESS) {
> +		ioc_err(mrioc,
> +		    "CreateReqQ: Failed IOCStatus(0x%04x) Loginfo(0x%08x)\n",
> +		    (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
> +		    mrioc->init_cmds.ioc_loginfo);
> +		retval = -1;
> +		goto out_unlock;
> +	}
> +	op_req_q->qid = req_qid;
> +
> +out_unlock:
> +	mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
> +	mutex_unlock(&mrioc->init_cmds.mutex);
> +out:
> +
> +	return retval;
> +}
> +
> +/**
> + * mpi3mr_create_op_queues - create operational queue pairs
> + * @mrioc: Adapter instance reference
> + *
> + * Allocate memory for operational queue meta data and call
> + * create request and reply queue functions.
> + *
> + * Return: 0 on success, non-zero on failures.
> + */
> +static int mpi3mr_create_op_queues(struct mpi3mr_ioc *mrioc)
> +{
> +	int retval = 0;
> +	u16 num_queues = 0, i = 0, msix_count_op_q = 1;
> +
> +	num_queues = min_t(int, mrioc->facts.max_op_reply_q,
> +	    mrioc->facts.max_op_req_q);
> +
> +	msix_count_op_q =
> +	    mrioc->intr_info_count - mrioc->op_reply_q_offset;
> +	if (!mrioc->num_queues)
> +		mrioc->num_queues = min_t(int, num_queues, msix_count_op_q);
> +	num_queues = mrioc->num_queues;
> +	ioc_info(mrioc, "Trying to create %d Operational Q pairs\n",
> +	    num_queues);
> +
> +	if (!mrioc->req_qinfo) {
> +		mrioc->req_qinfo = kcalloc(num_queues,
> +		    sizeof(struct op_req_qinfo), GFP_KERNEL);
> +		if (!mrioc->req_qinfo) {
> +			retval = -1;
> +			goto out_failed;
> +		}
> +
> +		mrioc->op_reply_qinfo = kzalloc(sizeof(struct op_reply_qinfo) *
> +		    num_queues, GFP_KERNEL);
> +		if (!mrioc->op_reply_qinfo) {
> +			retval = -1;
> +			goto out_failed;
> +		}
> +	}
> +
> +	if (mrioc->enable_segqueue)
> +		ioc_info(mrioc,
> +		    "allocating operational queues through segmented queues\n");
> +
> +	for (i = 0; i < num_queues; i++) {
> +		if (mpi3mr_create_op_reply_q(mrioc, i)) {
> +			ioc_err(mrioc, "Cannot create OP RepQ %d\n", i);
> +			break;
> +		}
> +		if (mpi3mr_create_op_req_q(mrioc, i,
> +		    mrioc->op_reply_qinfo[i].qid)) {
> +			ioc_err(mrioc, "Cannot create OP ReqQ %d\n", i);
> +			mpi3mr_delete_op_reply_q(mrioc, i);
> +			break;
> +		}
> +	}
> +
> +	if (i == 0) {
> +		/* Not even one queue is created successfully*/
> +		retval = -1;
> +		goto out_failed;
> +	}
> +	mrioc->num_op_reply_q = mrioc->num_op_req_q = i;
> +	ioc_info(mrioc, "Successfully created %d Operational Q pairs\n",
> +	    mrioc->num_op_reply_q);
> +
> +
> +	return retval;
> +out_failed:
> +	kfree(mrioc->req_qinfo);
> +	mrioc->req_qinfo = NULL;
> +
> +	kfree(mrioc->op_reply_qinfo);
> +	mrioc->op_reply_qinfo = NULL;
> +
> +
> +	return retval;
> +}
> +
>   
>   /**
>    * mpi3mr_setup_admin_qpair - Setup admin queue pair
> @@ -1599,6 +2187,13 @@ int mpi3mr_init_ioc(struct mpi3mr_ioc *mrioc)
>   		goto out_failed;
>   	}
>   
> +	retval = mpi3mr_create_op_queues(mrioc);
> +	if (retval) {
> +		ioc_err(mrioc, "Failed to create OpQueues error %d\n",
> +		    retval);
> +		goto out_failed;
> +	}
> +
>   	return retval;
>   
>   out_failed:
> @@ -1655,6 +2250,12 @@ static void mpi3mr_free_mem(struct mpi3mr_ioc *mrioc)
>   		mrioc->reply_free_q_pool = NULL;
>   	}
>   
> +	for (i = 0; i < mrioc->num_op_req_q; i++)
> +		mpi3mr_free_op_req_q_segments(mrioc, i);
> +
> +	for (i = 0; i < mrioc->num_op_reply_q; i++)
> +		mpi3mr_free_op_reply_q_segments(mrioc, i);
> +
>   	for (i = 0; i < mrioc->intr_info_count; i++) {
>   		intr_info = mrioc->intr_info + i;
>   		if (intr_info)
> diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c
> index c31ec9883152..3cf0be63842f 100644
> --- a/drivers/scsi/mpi3mr/mpi3mr_os.c
> +++ b/drivers/scsi/mpi3mr/mpi3mr_os.c
> @@ -41,7 +41,7 @@ static int mpi3mr_map_queues(struct Scsi_Host *shost)
>   	struct mpi3mr_ioc *mrioc = shost_priv(shost);
>   
>   	return blk_mq_pci_map_queues(&shost->tag_set.map[HCTX_TYPE_DEFAULT],
> -	    mrioc->pdev, 0);
> +	    mrioc->pdev, mrioc->op_reply_q_offset);
>   }
>   
>   /**
> @@ -220,6 +220,8 @@ mpi3mr_probe(struct pci_dev *pdev, const struct pci_device_id *id)
>   	spin_lock_init(&mrioc->sbq_lock);
>   
>   	mpi3mr_init_drv_cmd(&mrioc->init_cmds, MPI3MR_HOSTTAG_INITCMDS);
> +	if (pdev->revision)
> +		mrioc->enable_segqueue = true;
>   
>   	mrioc->logging_level = logging_level;
>   	mrioc->shost = shost;
> 
Other than that:

Reviewed-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                Kernel Storage Architect
hare@suse.de                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer

^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 04/24] mpi3mr: add support of queue command processing
  2020-12-22 10:11 ` [PATCH 04/24] mpi3mr: add support of queue command processing Kashyap Desai
  2021-02-22 15:23   ` Tomas Henzl
@ 2021-02-28 13:22   ` Hannes Reinecke
  2021-03-08 18:25     ` Kashyap Desai
  1 sibling, 1 reply; 75+ messages in thread
From: Hannes Reinecke @ 2021-02-28 13:22 UTC (permalink / raw)
  To: Kashyap Desai, linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, sathya.prakash

On 12/22/20 11:11 AM, Kashyap Desai wrote:
> Send Port Enable Request to FW for Device Discovery.
> As part of port enable completion driver calls scan_start and
> scan_finished hooks.
> scsi layer reference like sdev, starget etc is added but actual
> device discovery will be supported once driver add complete event
> process handling (It is added in subsequent patches)
> 
> This patch provides interface which is used to interact with FW
> via operational queue pairs.
> 
> Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
> Cc: sathya.prakash@broadcom.com
> ---
>   drivers/scsi/mpi3mr/mpi3mr.h    |  52 +++
>   drivers/scsi/mpi3mr/mpi3mr_fw.c | 251 +++++++++++++
>   drivers/scsi/mpi3mr/mpi3mr_os.c | 645 +++++++++++++++++++++++++++++++-
>   3 files changed, 946 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/scsi/mpi3mr/mpi3mr.h b/drivers/scsi/mpi3mr/mpi3mr.h
> index fe6094bb357a..f23751e25d0f 100644
> --- a/drivers/scsi/mpi3mr/mpi3mr.h
> +++ b/drivers/scsi/mpi3mr/mpi3mr.h
> @@ -96,6 +96,7 @@ extern struct list_head mrioc_list;
>   
>   /* command/controller interaction timeout definitions in seconds */
>   #define MPI3MR_INTADMCMD_TIMEOUT		10
> +#define MPI3MR_PORTENABLE_TIMEOUT		300
>   #define MPI3MR_RESETTM_TIMEOUT			30
>   #define MPI3MR_DEFAULT_SHUTDOWN_TIME		120
>   
> @@ -312,6 +313,43 @@ struct mpi3mr_intr_info {
>   	char name[MPI3MR_NAME_LENGTH];
>   };
>   
> +/**
> + * struct mpi3mr_stgt_priv_data - SCSI target private structure
> + *
> + * @starget: Scsi_target pointer
> + * @dev_handle: FW device handle
> + * @perst_id: FW assigned Persistent ID
> + * @num_luns: Number of Logical Units
> + * @block_io: I/O blocked to the device or not
> + * @dev_removed: Device removed in the Firmware
> + * @dev_removedelay: Device is waiting to be removed in FW
> + * @dev_type: Device type
> + * @tgt_dev: Internal target device pointer
> + */
> +struct mpi3mr_stgt_priv_data {
> +	struct scsi_target *starget;
> +	u16 dev_handle;
> +	u16 perst_id;
> +	u32 num_luns;
> +	atomic_t block_io;
> +	u8 dev_removed;
> +	u8 dev_removedelay;
> +	u8 dev_type;
> +	struct mpi3mr_tgt_dev *tgt_dev;
> +};
> +
> +/**
> + * struct mpi3mr_stgt_priv_data - SCSI device private structure
> + *
> + * @tgt_priv_data: Scsi_target private data pointer
> + * @lun_id: LUN ID of the device
> + * @ncq_prio_enable: NCQ priority enable for SATA device
> + */
> +struct mpi3mr_sdev_priv_data {
> +	struct mpi3mr_stgt_priv_data *tgt_priv_data;
> +	u32 lun_id;
> +	u8 ncq_prio_enable;
> +};
>   
Why is there a separate 'lun_id' field?

>   typedef struct mpi3mr_drv_cmd DRV_CMD;
>   typedef void (*DRV_CMD_CALLBACK)(struct mpi3mr_ioc *mrioc,
> @@ -443,12 +481,16 @@ struct scmd_priv {
>    * @sbq_lock: Sense buffer queue lock
>    * @sbq_host_index: Sense buffer queuehost index
>    * @is_driver_loading: Is driver still loading
> + * @scan_started: Async scan started
> + * @scan_failed: Asycn scan failed
> + * @stop_drv_processing: Stop all command processing
>    * @max_host_ios: Maximum host I/O count
>    * @chain_buf_count: Chain buffer count
>    * @chain_buf_pool: Chain buffer pool
>    * @chain_sgl_list: Chain SGL list
>    * @chain_bitmap_sz: Chain buffer allocator bitmap size
>    * @chain_bitmap: Chain buffer allocator bitmap
> + * @chain_buf_lock: Chain buffer list lock
>    * @reset_in_progress: Reset in progress flag
>    * @unrecoverable: Controller unrecoverable flag
>    * @logging_level: Controller debug logging level
> @@ -533,6 +575,9 @@ struct mpi3mr_ioc {
>   	u32 sbq_host_index;
>   
>   	u8 is_driver_loading;
> +	u8 scan_started;
> +	u16 scan_failed;
> +	u8 stop_drv_processing;
>   
>   	u16 max_host_ios;
>   
> @@ -541,6 +586,7 @@ struct mpi3mr_ioc {
>   	struct chain_element *chain_sgl_list;
>   	u16  chain_bitmap_sz;
>   	void *chain_bitmap;
> +	spinlock_t chain_buf_lock;
>   
>   	u8 reset_in_progress;
>   	u8 unrecoverable;
> @@ -557,8 +603,11 @@ int mpi3mr_setup_resources(struct mpi3mr_ioc *mrioc);
>   void mpi3mr_cleanup_resources(struct mpi3mr_ioc *mrioc);
>   int mpi3mr_init_ioc(struct mpi3mr_ioc *mrioc);
>   void mpi3mr_cleanup_ioc(struct mpi3mr_ioc *mrioc);
> +int mpi3mr_issue_port_enable(struct mpi3mr_ioc *mrioc, u8 async);
>   int mpi3mr_admin_request_post(struct mpi3mr_ioc *mrioc, void *admin_req,
>   u16 admin_req_sz, u8 ignore_reset);
> +int mpi3mr_op_request_post(struct mpi3mr_ioc *mrioc,
> +			   struct op_req_qinfo *opreqq, u8 *req);
>   void mpi3mr_add_sg_single(void *paddr, u8 flags, u32 length,
>   			  dma_addr_t dma_addr);
>   void mpi3mr_build_zero_len_sge(void *paddr);
> @@ -569,6 +618,9 @@ void *mpi3mr_get_reply_virt_addr(struct mpi3mr_ioc *mrioc,
>   void mpi3mr_repost_sense_buf(struct mpi3mr_ioc *mrioc,
>   				     u64 sense_buf_dma);
>   
> +void mpi3mr_process_op_reply_desc(struct mpi3mr_ioc *mrioc,
> +				  Mpi3DefaultReplyDescriptor_t *reply_desc,
> +				  u64 *reply_dma, u16 qidx);
>   void mpi3mr_start_watchdog(struct mpi3mr_ioc *mrioc);
>   void mpi3mr_stop_watchdog(struct mpi3mr_ioc *mrioc);
>   
> diff --git a/drivers/scsi/mpi3mr/mpi3mr_fw.c b/drivers/scsi/mpi3mr/mpi3mr_fw.c
> index 6fb28983038e..abdf8c653e6b 100644
> --- a/drivers/scsi/mpi3mr/mpi3mr_fw.c
> +++ b/drivers/scsi/mpi3mr/mpi3mr_fw.c
> @@ -24,6 +24,23 @@ static inline void mpi3mr_writeq(__u64 b, volatile void __iomem *addr)
>   }
>   #endif
>   
> +static inline bool
> +mpi3mr_check_req_qfull(struct op_req_qinfo *op_req_q)
> +{
> +	u16 pi, ci, max_entries;
> +	bool is_qfull = false;
> +
> +	pi = op_req_q->pi;
> +	ci = op_req_q->ci;
> +	max_entries = op_req_q->num_requests;
> +
> +	if ((ci == (pi + 1)) || ((!ci) && (pi == (max_entries - 1))))
> +		is_qfull = true;
> +
> +	return is_qfull;
> +}
> + > +

This needs to be protected by a lock to ensure the 'ci' and 'pi' values 
won't change during processing; alternatively you'd need to use 
READ_ONCE() here.
Please modify or add respective lockdep annotations.

>   static void mpi3mr_sync_irqs(struct mpi3mr_ioc *mrioc)
>   {
>   	u16 i, max_vectors;
> @@ -282,6 +299,87 @@ static int mpi3mr_process_admin_reply_q(struct mpi3mr_ioc *mrioc)
>   	return num_admin_replies;
>   }
>   
> +/**
> + * mpi3mr_get_reply_desc - get reply descriptor frame corresponding to
> + *	queue's consumer index from operational reply descriptor queue.
> + * @op_reply_q: op_reply_qinfo object
> + * @reply_ci: operational reply descriptor's queue consumer index
> + *
> + * Returns reply descriptor frame address
> + */
> +static inline Mpi3DefaultReplyDescriptor_t *
> +mpi3mr_get_reply_desc(struct op_reply_qinfo *op_reply_q, u32 reply_ci)
> +{
> +	void *segment_base_addr;
> +	struct segments *segments = op_reply_q->q_segments;
> +	Mpi3DefaultReplyDescriptor_t *reply_desc = NULL;
> +
> +	segment_base_addr =
> +	    segments[reply_ci / op_reply_q->segment_qd].segment;
> +	reply_desc = (Mpi3DefaultReplyDescriptor_t *)segment_base_addr +
> +	    (reply_ci % op_reply_q->segment_qd);
> +	return reply_desc;
> +}
> +
> +
> +static int mpi3mr_process_op_reply_q(struct mpi3mr_ioc *mrioc,
> +	struct mpi3mr_intr_info *intr_info)
> +{
> +	struct op_reply_qinfo *op_reply_q = intr_info->op_reply_q;
> +	struct op_req_qinfo *op_req_q;
> +	u32 exp_phase;
> +	u32 reply_ci;
> +	u32 num_op_reply = 0;
> +	u64 reply_dma = 0;
> +	Mpi3DefaultReplyDescriptor_t *reply_desc;
> +	u16 req_q_idx = 0, reply_qidx;
> +
> +	reply_qidx = op_reply_q->qid - 1;
> +
> +	exp_phase = op_reply_q->ephase;
> +	reply_ci = op_reply_q->ci;
> +
> +	reply_desc = mpi3mr_get_reply_desc(op_reply_q, reply_ci);
> +	if ((le16_to_cpu(reply_desc->ReplyFlags) &
> +	    MPI3_REPLY_DESCRIPT_FLAGS_PHASE_MASK) != exp_phase) {
> +		return 0;
> +	}
> +
> +	do {
> +		req_q_idx = le16_to_cpu(reply_desc->RequestQueueID) - 1;
> +		op_req_q = &mrioc->req_qinfo[req_q_idx];
> +
> +		op_req_q->ci =
> +		    le16_to_cpu(reply_desc->RequestQueueCI);
> +

This introduces an interlock with request processing; from what I can 
see request processing is guarded by a spinlock, yet I don't see any 
protection here.
How do you ensure a timely update of the 'ci' value if there is parallel 
execution of requests and responses (note: you cannot always assume that 
you will have a 1:1 relationship between queuepairs, CPUs, and interrupts).
I would have expected at least a WRITE_ONCE() here.

Question is why you need to modify this at all; in most implementations 
I know of the 'ci' index is modified by firmware, as really it's the 
firmware consuming the request.
Why not here?

> +		mpi3mr_process_op_reply_desc(mrioc, reply_desc, &reply_dma,
> +		    reply_qidx);
> +		if (reply_dma)
> +			mpi3mr_repost_reply_buf(mrioc, reply_dma);
> +		num_op_reply++;
> +
> +		if (++reply_ci == op_reply_q->num_replies) {
> +			reply_ci = 0;
> +			exp_phase ^= 1;
> +		}
> +
> +		reply_desc = mpi3mr_get_reply_desc(op_reply_q, reply_ci);
> +
> +		if ((le16_to_cpu(reply_desc->ReplyFlags) &
> +		    MPI3_REPLY_DESCRIPT_FLAGS_PHASE_MASK) != exp_phase)
> +			break;
> +
> +	} while (1);
> +
> +
> +	writel(reply_ci,
> +	    &mrioc->sysif_regs->OperQueueIndexes[reply_qidx].ConsumerIndex);
> +	op_reply_q->ci = reply_ci;
> +	op_reply_q->ephase = exp_phase;
> +
> +	return num_op_reply;
> +}
> +
>   static irqreturn_t mpi3mr_isr_primary(int irq, void *privdata)
>   {
>   	struct mpi3mr_intr_info *intr_info = privdata;
> @@ -1314,6 +1412,74 @@ static int mpi3mr_create_op_queues(struct mpi3mr_ioc *mrioc)
>   	return retval;
>   }
>   
> +/**
> + * mpi3mr_op_request_post - Post request to operational queue
> + * @mrioc: Adapter reference
> + * @op_req_q: Operational request queue info
> + * @req: MPI3 request
> + *
> + * Post the MPI3 request into operational request queue and
> + * inform the controller, if the queue is full return
> + * appropriate error.
> + *
> + * Return: 0 on success, non-zero on failure.
> + */
> +int mpi3mr_op_request_post(struct mpi3mr_ioc *mrioc,
> +	struct op_req_qinfo *op_req_q, u8 *req)
> +{
> +	u16 pi = 0, max_entries, reply_qidx = 0, midx;
> +	int retval = 0;
> +	unsigned long flags;
> +	u8 *req_entry;
> +	void *segment_base_addr;
> +	u16 req_sz = mrioc->facts.op_req_sz;
> +	struct segments *segments = op_req_q->q_segments;
> +
> +	reply_qidx = op_req_q->reply_qid - 1;
> +
> +	if (mrioc->unrecoverable)
> +		return -EFAULT;
> +
> +	spin_lock_irqsave(&op_req_q->q_lock, flags);
> +	pi = op_req_q->pi;
> +	max_entries = op_req_q->num_requests;
> +
> +	if (mpi3mr_check_req_qfull(op_req_q)) {
> +		midx = REPLY_QUEUE_IDX_TO_MSIX_IDX(
> +		    reply_qidx, mrioc->op_reply_q_offset);
> +		mpi3mr_process_op_reply_q(mrioc, &mrioc->intr_info[midx]);
> +
> +		if (mpi3mr_check_req_qfull(op_req_q)) {

Ah, so here it's being used.
So do add the lockdep annotation to mpi3mr_check_req_qfull().

> +			retval = -EAGAIN;
> +			goto out;
> +		}
> +	}
> +
> +	if (mrioc->reset_in_progress) {
> +		ioc_err(mrioc, "OpReqQ submit reset in progress\n");
> +		retval = -EAGAIN;
> +		goto out;
> +	}
> +
> +	segment_base_addr = segments[pi / op_req_q->segment_qd].segment;
> +	req_entry = (u8 *)segment_base_addr +
> +	    ((pi % op_req_q->segment_qd) * req_sz);
> +
> +	memset(req_entry, 0, req_sz);
> +	memcpy(req_entry, req, MPI3MR_ADMIN_REQ_FRAME_SZ);
> +
> +	if (++pi == max_entries)
> +		pi = 0;
> +	op_req_q->pi = pi;
> +
> +	writel(op_req_q->pi,
> +	    &mrioc->sysif_regs->OperQueueIndexes[reply_qidx].ProducerIndex);
> +
> +out:
> +	spin_unlock_irqrestore(&op_req_q->q_lock, flags);
> +	return retval;
> +}
> +
>   
>   /**
>    * mpi3mr_setup_admin_qpair - Setup admin queue pair
> @@ -1901,6 +2067,91 @@ static int mpi3mr_alloc_chain_bufs(struct mpi3mr_ioc *mrioc)
>   	return retval;
>   }
>   
> +/**
> + * mpi3mr_port_enable_complete - Mark port enable complete
> + * @mrioc: Adapter instance reference
> + * @drv_cmd: Internal command tracker
> + *
> + * Call back for asynchronous port enable request sets the
> + * driver command to indicate port enable request is complete.
> + *
> + * Return: Nothing
> + */
> +static void mpi3mr_port_enable_complete(struct mpi3mr_ioc *mrioc,
> +	struct mpi3mr_drv_cmd *drv_cmd)
> +{
> +
> +	drv_cmd->state = MPI3MR_CMD_NOTUSED;
> +	drv_cmd->callback = NULL;
> +	mrioc->scan_failed = drv_cmd->ioc_status;
> +	mrioc->scan_started = 0;
> +
> +}
> +
> +/**
> + * mpi3mr_issue_port_enable - Issue Port Enable
> + * @mrioc: Adapter instance reference
> + * @async: Flag to wait for completion or not
> + *
> + * Issue Port Enable MPI request through admin queue and if the
> + * async flag is not set wait for the completion of the port
> + * enable or time out.
> + *
> + * Return: 0 on success, non-zero on failures.
> + */
> +int mpi3mr_issue_port_enable(struct mpi3mr_ioc *mrioc, u8 async)
> +{
> +	Mpi3PortEnableRequest_t pe_req;
> +	int retval = 0;
> +	u32 pe_timeout = MPI3MR_PORTENABLE_TIMEOUT;
> +
> +	memset(&pe_req, 0, sizeof(pe_req));
> +	mutex_lock(&mrioc->init_cmds.mutex);
> +	if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
> +		retval = -1;
> +		ioc_err(mrioc, "Issue PortEnable: Init command is in use\n");
> +		mutex_unlock(&mrioc->init_cmds.mutex);
> +		goto out;
> +	}
> +	mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
> +	if (async) {
> +		mrioc->init_cmds.is_waiting = 0;
> +		mrioc->init_cmds.callback = mpi3mr_port_enable_complete;
> +	} else {
> +		mrioc->init_cmds.is_waiting = 1;
> +		mrioc->init_cmds.callback = NULL;
> +		init_completion(&mrioc->init_cmds.done);
> +	}
> +	pe_req.HostTag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
> +	pe_req.Function = MPI3_FUNCTION_PORT_ENABLE;
> +
> +	retval = mpi3mr_admin_request_post(mrioc, &pe_req, sizeof(pe_req), 1);
> +	if (retval) {
> +		ioc_err(mrioc, "Issue PortEnable: Admin Post failed\n");
> +		goto out_unlock;
> +	}
> +	if (!async) {
> +		wait_for_completion_timeout(&mrioc->init_cmds.done,
> +		    (pe_timeout * HZ));
> +		if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
> +			ioc_err(mrioc, "Issue PortEnable: command timed out\n");
> +			retval = -1;
> +			mrioc->scan_failed = MPI3_IOCSTATUS_INTERNAL_ERROR;
> +			mpi3mr_set_diagsave(mrioc);
> +			mpi3mr_issue_reset(mrioc,
> +			    MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT,
> +			    MPI3MR_RESET_FROM_PE_TIMEOUT);
> +			mrioc->unrecoverable = 1;
> +			goto out_unlock;
> +		}
> +		mpi3mr_port_enable_complete(mrioc, &mrioc->init_cmds);
> +	}
> +out_unlock:
> +	mutex_unlock(&mrioc->init_cmds.mutex);
> +out:
> +	return retval;
> +}
> +
>   
>   /**
>    * mpi3mr_cleanup_resources - Free PCI resources
> diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c
> index 3cf0be63842f..01be5f337826 100644
> --- a/drivers/scsi/mpi3mr/mpi3mr_os.c
> +++ b/drivers/scsi/mpi3mr/mpi3mr_os.c
> @@ -26,6 +26,471 @@ module_param(logging_level, int, 0);
>   MODULE_PARM_DESC(logging_level,
>   	" bits for enabling additional logging info (default=0)");
>   
> +/* Forward declarations*/
> +/**
> + * mpi3mr_host_tag_for_scmd - Get host tag for a scmd
> + * @mrioc: Adapter instance reference
> + * @scmd: SCSI command reference
> + *
> + * Calculate the host tag based on block tag for a given scmd.
> + *
> + * Return: Valid host tag or MPI3MR_HOSTTAG_INVALID.
> + */
> +static u16 mpi3mr_host_tag_for_scmd(struct mpi3mr_ioc *mrioc,
> +	struct scsi_cmnd *scmd)
> +{
> +	struct scmd_priv *priv = NULL;
> +	u32 unique_tag;
> +	u16 host_tag, hw_queue;
> +
> +	unique_tag = blk_mq_unique_tag(scmd->request);
> +
> +	hw_queue = blk_mq_unique_tag_to_hwq(unique_tag);
> +	if (hw_queue >= mrioc->num_op_reply_q)
> +		return MPI3MR_HOSTTAG_INVALID;
> +	host_tag = blk_mq_unique_tag_to_tag(unique_tag);
> +
> +	if (WARN_ON(host_tag >= mrioc->max_host_ios))
> +		return MPI3MR_HOSTTAG_INVALID;
> +
> +	priv = scsi_cmd_priv(scmd);
> +	/*host_tag 0 is invalid hence incrementing by 1*/
> +	priv->host_tag = host_tag + 1;
> +	priv->scmd = scmd;
> +	priv->in_lld_scope = 1;
> +	priv->req_q_idx = hw_queue;
> +	priv->chain_idx = -1;
> +	return priv->host_tag;
> +}
> +
> +/**
> + * mpi3mr_scmd_from_host_tag - Get SCSI command from host tag
> + * @mrioc: Adapter instance reference
> + * @host_tag: Host tag
> + * @qidx: Operational queue index
> + *
> + * Identify the block tag from the host tag and queue index and
> + * retrieve associated scsi command using scsi_host_find_tag().
> + *
> + * Return: SCSI command reference or NULL.
> + */
> +static struct scsi_cmnd *mpi3mr_scmd_from_host_tag(
> +	struct mpi3mr_ioc *mrioc, u16 host_tag, u16 qidx)
> +{
> +	struct scsi_cmnd *scmd = NULL;
> +	struct scmd_priv *priv = NULL;
> +	u32 unique_tag = host_tag - 1;
> +
> +	if (WARN_ON(host_tag > mrioc->max_host_ios))
> +		goto out;
> +
> +	unique_tag |= (qidx << BLK_MQ_UNIQUE_TAG_BITS);
> +
> +	scmd = scsi_host_find_tag(mrioc->shost, unique_tag);
> +	if (scmd) {
> +		priv = scsi_cmd_priv(scmd);
> +		if (!priv->in_lld_scope)
> +			scmd = NULL;
> +	}
> +out:
> +	return scmd;
> +}
> +
> +/**
> + * mpi3mr_clear_scmd_priv - Cleanup SCSI command private date
> + * @mrioc: Adapter instance reference
> + * @scmd: SCSI command reference
> + *
> + * Invalidate the SCSI command private data to mark the command
> + * is not in LLD scope anymore.
> + *
> + * Return: Nothing.
> + */
> +static void mpi3mr_clear_scmd_priv(struct mpi3mr_ioc *mrioc,
> +	struct scsi_cmnd *scmd)
> +{
> +	struct scmd_priv *priv = NULL;
> +
> +	priv = scsi_cmd_priv(scmd);
> +
> +	if (WARN_ON(priv->in_lld_scope == 0))
> +		return;
> +	priv->host_tag = MPI3MR_HOSTTAG_INVALID;
> +	priv->req_q_idx = 0xFFFF;
> +	priv->scmd = NULL;
> +	priv->in_lld_scope = 0;
> +	if (priv->chain_idx >= 0) {
> +		clear_bit(priv->chain_idx, mrioc->chain_bitmap);
> +		priv->chain_idx = -1;
> +	}
> +}
> +
> +/**
> + * mpi3mr_process_op_reply_desc - reply descriptor handler
> + * @mrioc: Adapter instance reference
> + * @reply_desc: Operational reply descriptor
> + * @reply_dma: place holder for reply DMA address
> + * @qidx: Operational queue index
> + *
> + * Process the operational reply descriptor and identifies the
> + * descriptor type. Based on the descriptor map the MPI3 request
> + * status to a SCSI command status and calls scsi_done call
> + * back.
> + *
> + * Return: Nothing
> + */
> +void mpi3mr_process_op_reply_desc(struct mpi3mr_ioc *mrioc,
> +	Mpi3DefaultReplyDescriptor_t *reply_desc, u64 *reply_dma, u16 qidx)
> +{
> +	u16 reply_desc_type, host_tag = 0;
> +	u16 ioc_status = MPI3_IOCSTATUS_SUCCESS;
> +	u32 ioc_loginfo = 0;
> +	Mpi3StatusReplyDescriptor_t *status_desc = NULL;
> +	Mpi3AddressReplyDescriptor_t *addr_desc = NULL;
> +	Mpi3SuccessReplyDescriptor_t *success_desc = NULL;
> +	Mpi3SCSIIOReply_t *scsi_reply = NULL;
> +	struct scsi_cmnd *scmd = NULL;
> +	struct scmd_priv *priv = NULL;
> +	u8 *sense_buf = NULL;
> +	u8 scsi_state = 0, scsi_status = 0, sense_state = 0;
> +	u32 xfer_count = 0, sense_count = 0, resp_data = 0;
> +	u16 dev_handle = 0xFFFF;
> +	struct scsi_sense_hdr sshdr;
> +
> +	*reply_dma = 0;
> +	reply_desc_type = le16_to_cpu(reply_desc->ReplyFlags) &
> +	    MPI3_REPLY_DESCRIPT_FLAGS_TYPE_MASK;
> +	switch (reply_desc_type) {
> +	case MPI3_REPLY_DESCRIPT_FLAGS_TYPE_STATUS:
> +		status_desc = (Mpi3StatusReplyDescriptor_t *)reply_desc;
> +		host_tag = le16_to_cpu(status_desc->HostTag);
> +		ioc_status = le16_to_cpu(status_desc->IOCStatus);
> +		if (ioc_status &
> +		    MPI3_REPLY_DESCRIPT_STATUS_IOCSTATUS_LOGINFOAVAIL)
> +			ioc_loginfo = le32_to_cpu(status_desc->IOCLogInfo);
> +		ioc_status &= MPI3_REPLY_DESCRIPT_STATUS_IOCSTATUS_STATUS_MASK;
> +		break;
> +	case MPI3_REPLY_DESCRIPT_FLAGS_TYPE_ADDRESS_REPLY:
> +		addr_desc = (Mpi3AddressReplyDescriptor_t *)reply_desc;
> +		*reply_dma = le64_to_cpu(addr_desc->ReplyFrameAddress);
> +		scsi_reply = mpi3mr_get_reply_virt_addr(mrioc,
> +		    *reply_dma);
> +		if (!scsi_reply) {
> +			panic("%s: scsi_reply is NULL, this shouldn't happen\n",
> +			    mrioc->name);
> +			goto out;
> +		}
> +		host_tag = le16_to_cpu(scsi_reply->HostTag);
> +		ioc_status = le16_to_cpu(scsi_reply->IOCStatus);
> +		scsi_status = scsi_reply->SCSIStatus;
> +		scsi_state = scsi_reply->SCSIState;
> +		dev_handle = le16_to_cpu(scsi_reply->DevHandle);
> +		sense_state = (scsi_state & MPI3_SCSI_STATE_SENSE_MASK);
> +		xfer_count = le32_to_cpu(scsi_reply->TransferCount);
> +		sense_count = le32_to_cpu(scsi_reply->SenseCount);
> +		resp_data = le32_to_cpu(scsi_reply->ResponseData);
> +		sense_buf = mpi3mr_get_sensebuf_virt_addr(mrioc,
> +		    le64_to_cpu(scsi_reply->SenseDataBufferAddress));
> +		if (ioc_status &
> +		    MPI3_REPLY_DESCRIPT_STATUS_IOCSTATUS_LOGINFOAVAIL)
> +			ioc_loginfo = le32_to_cpu(scsi_reply->IOCLogInfo);
> +		ioc_status &= MPI3_REPLY_DESCRIPT_STATUS_IOCSTATUS_STATUS_MASK;
> +		if (sense_state == MPI3_SCSI_STATE_SENSE_BUFF_Q_EMPTY)
> +			panic("%s: Ran out of sense buffers\n", mrioc->name);
> +		break;
> +	case MPI3_REPLY_DESCRIPT_FLAGS_TYPE_SUCCESS:
> +		success_desc = (Mpi3SuccessReplyDescriptor_t *)reply_desc;
> +		host_tag = le16_to_cpu(success_desc->HostTag);
> +		break;
> +	default:
> +		break;
> +	}
> +	scmd = mpi3mr_scmd_from_host_tag(mrioc, host_tag, qidx);
> +	if (!scmd) {
> +		panic("%s: Cannot Identify scmd for host_tag 0x%x\n",
> +		    mrioc->name, host_tag);
> +		goto out;
> +	}
> +	priv = scsi_cmd_priv(scmd);
> +	if (success_desc) {
> +		scmd->result = DID_OK << 16;
> +		goto out_success;
> +	}
> +	if (ioc_status == MPI3_IOCSTATUS_SCSI_DATA_UNDERRUN &&
> +	    xfer_count == 0 && (scsi_status == MPI3_SCSI_STATUS_BUSY ||
> +	    scsi_status == MPI3_SCSI_STATUS_RESERVATION_CONFLICT ||
> +	    scsi_status == MPI3_SCSI_STATUS_TASK_SET_FULL))
> +		ioc_status = MPI3_IOCSTATUS_SUCCESS;
> +
> +	if ((sense_state == MPI3_SCSI_STATE_SENSE_VALID) && sense_count
> +	    && sense_buf) {
> +		u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE, sense_count);
> +
> +		memcpy(scmd->sense_buffer, sense_buf, sz);
> +	}
> +
> +	switch (ioc_status) {
> +	case MPI3_IOCSTATUS_BUSY:
> +	case MPI3_IOCSTATUS_INSUFFICIENT_RESOURCES:
> +		scmd->result = SAM_STAT_BUSY;
> +		break;
> +	case MPI3_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
> +		scmd->result = DID_NO_CONNECT << 16;
> +		break;
> +	case MPI3_IOCSTATUS_SCSI_IOC_TERMINATED:
> +		scmd->result = DID_SOFT_ERROR << 16;
> +		break;
> +	case MPI3_IOCSTATUS_SCSI_TASK_TERMINATED:
> +	case MPI3_IOCSTATUS_SCSI_EXT_TERMINATED:
> +		scmd->result = DID_RESET << 16;
> +		break;
> +	case MPI3_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
> +		if ((xfer_count == 0) || (scmd->underflow > xfer_count))
> +			scmd->result = DID_SOFT_ERROR << 16;
> +		else
> +			scmd->result = (DID_OK << 16) | scsi_status;
> +		break;
> +	case MPI3_IOCSTATUS_SCSI_DATA_UNDERRUN:
> +		scmd->result = (DID_OK << 16) | scsi_status;
> +		if (sense_state == MPI3_SCSI_STATE_SENSE_VALID)
> +			break;
> +		if (xfer_count < scmd->underflow) {
> +			if (scsi_status == SAM_STAT_BUSY)
> +				scmd->result = SAM_STAT_BUSY;
> +			else
> +				scmd->result = DID_SOFT_ERROR << 16;
> +		} else if ((scsi_state & (MPI3_SCSI_STATE_NO_SCSI_STATUS))
> +		    || (sense_state != MPI3_SCSI_STATE_SENSE_NOT_AVAILABLE))
> +			scmd->result = DID_SOFT_ERROR << 16;
> +		else if (scsi_state & MPI3_SCSI_STATE_TERMINATED)
> +			scmd->result = DID_RESET << 16;
> +		else if (!xfer_count && scmd->cmnd[0] == REPORT_LUNS) {
> +			scsi_status = SAM_STAT_CHECK_CONDITION;
> +			scmd->result = (DRIVER_SENSE << 24) |
> +			    SAM_STAT_CHECK_CONDITION;
> +			scmd->sense_buffer[0] = 0x70;
> +			scmd->sense_buffer[2] = ILLEGAL_REQUEST;
> +			scmd->sense_buffer[12] = 0x20;
> +			scmd->sense_buffer[13] = 0;
> +		}
> +		break;
> +	case MPI3_IOCSTATUS_SCSI_DATA_OVERRUN:
> +		scsi_set_resid(scmd, 0);
> +		fallthrough;
> +	case MPI3_IOCSTATUS_SCSI_RECOVERED_ERROR:
> +	case MPI3_IOCSTATUS_SUCCESS:
> +		scmd->result = (DID_OK << 16) | scsi_status;
> +		if ((scsi_state & (MPI3_SCSI_STATE_NO_SCSI_STATUS))
> +			|| (sense_state == MPI3_SCSI_STATE_SENSE_FAILED)
> +			|| (sense_state == MPI3_SCSI_STATE_SENSE_BUFF_Q_EMPTY))
> +			scmd->result = DID_SOFT_ERROR << 16;
> +		else if (scsi_state & MPI3_SCSI_STATE_TERMINATED)
> +			scmd->result = DID_RESET << 16;
> +		break;
> +	case MPI3_IOCSTATUS_SCSI_PROTOCOL_ERROR:
> +	case MPI3_IOCSTATUS_INVALID_FUNCTION:
> +	case MPI3_IOCSTATUS_INVALID_SGL:
> +	case MPI3_IOCSTATUS_INTERNAL_ERROR:
> +	case MPI3_IOCSTATUS_INVALID_FIELD:
> +	case MPI3_IOCSTATUS_INVALID_STATE:
> +	case MPI3_IOCSTATUS_SCSI_IO_DATA_ERROR:
> +	case MPI3_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
> +	case MPI3_IOCSTATUS_INSUFFICIENT_POWER:
> +	default:
> +		scmd->result = DID_SOFT_ERROR << 16;
> +		break;
> +	}
> +
> +	if (scmd->result != (DID_OK << 16) && (scmd->cmnd[0] != ATA_12) &&
> +	    (scmd->cmnd[0] != ATA_16)) {
> +		ioc_info(mrioc, "%s :scmd->result 0x%x\n", __func__,
> +		    scmd->result);
> +		scsi_print_command(scmd);
> +		ioc_info(mrioc,
> +		    "%s :Command issued to handle 0x%02x returned with error 0x%04x loginfo 0x%08x, qid %d\n",
> +		    __func__, dev_handle, ioc_status, ioc_loginfo,
> +		    priv->req_q_idx+1);
> +		ioc_info(mrioc,
> +		    " host_tag %d scsi_state 0x%02x scsi_status 0x%02x, xfer_cnt %d resp_data 0x%x\n",
> +		    host_tag, scsi_state, scsi_status, xfer_count, resp_data);
> +		if (sense_buf) {
> +			scsi_normalize_sense(sense_buf, sense_count, &sshdr);
> +			ioc_info(mrioc,
> +			    "%s :sense_count 0x%x, sense_key 0x%x ASC 0x%x, ASCQ 0x%x\n",
> +			    __func__, sense_count, sshdr.sense_key,
> +			    sshdr.asc, sshdr.ascq);
> +		}
> +	}
> +out_success:
> +	mpi3mr_clear_scmd_priv(mrioc, scmd);
> +	scsi_dma_unmap(scmd);
> +	scmd->scsi_done(scmd);
> +out:
> +	if (sense_buf)
> +		mpi3mr_repost_sense_buf(mrioc,
> +		    le64_to_cpu(scsi_reply->SenseDataBufferAddress));
> +}
> +
> +/**
> + * mpi3mr_get_chain_idx - get free chain buffer index
> + * @mrioc: Adapter instance reference
> + *
> + * Try to get a free chain buffer index from the free pool.
> + *
> + * Return: -1 on failure or the free chain buffer index
> + */
> +static int mpi3mr_get_chain_idx(struct mpi3mr_ioc *mrioc)
> +{
> +	u8 retry_count = 5;
> +	int cmd_idx = -1;
> +
> +	do {
> +		spin_lock(&mrioc->chain_buf_lock);
> +		cmd_idx = find_first_zero_bit(mrioc->chain_bitmap,
> +		    mrioc->chain_buf_count);
> +		if (cmd_idx < mrioc->chain_buf_count) {
> +			set_bit(cmd_idx, mrioc->chain_bitmap);
> +			spin_unlock(&mrioc->chain_buf_lock);
> +			break;
> +		}
> +		spin_unlock(&mrioc->chain_buf_lock);
> +		cmd_idx = -1;
> +	} while (retry_count--);
> +	return cmd_idx;
> +}
> +
> +/**
> + * mpi3mr_prepare_sg_scmd - build scatter gather list
> + * @mrioc: Adapter instance reference
> + * @scmd: SCSI command reference
> + * @scsiio_req: MPI3 SCSI IO request
> + *
> + * This function maps SCSI command's data and protection SGEs to
> + * MPI request SGEs. If required additional 4K chain buffer is
> + * used to send the SGEs.
> + *
> + * Return: 0 on success, -ENOMEM on dma_map_sg failure
> + */
> +static int mpi3mr_prepare_sg_scmd(struct mpi3mr_ioc *mrioc,
> +	struct scsi_cmnd *scmd, Mpi3SCSIIORequest_t *scsiio_req)
> +{
> +	dma_addr_t chain_dma;
> +	struct scatterlist *sg_scmd;
> +	void *sg_local, *chain;
> +	u32 chain_length;
> +	int sges_left, chain_idx;
> +	u32 sges_in_segment;
> +	u8 simple_sgl_flags;
> +	u8 simple_sgl_flags_last;
> +	u8 last_chain_sgl_flags;
> +	struct chain_element *chain_req;
> +	struct scmd_priv *priv = NULL;
> +
> +	priv = scsi_cmd_priv(scmd);
> +
> +	simple_sgl_flags = MPI3_SGE_FLAGS_ELEMENT_TYPE_SIMPLE |
> +	    MPI3_SGE_FLAGS_DLAS_SYSTEM;
> +	simple_sgl_flags_last = simple_sgl_flags |
> +	    MPI3_SGE_FLAGS_END_OF_LIST;
> +	last_chain_sgl_flags = MPI3_SGE_FLAGS_ELEMENT_TYPE_LAST_CHAIN |
> +	    MPI3_SGE_FLAGS_DLAS_SYSTEM;
> +
> +	sg_local = &scsiio_req->SGL;
> +
> +	if (!scsiio_req->DataLength) {
> +		mpi3mr_build_zero_len_sge(sg_local);
> +		return 0;
> +	}
> +
> +	sg_scmd = scsi_sglist(scmd);
> +	sges_left = scsi_dma_map(scmd);
> +
> +	if (sges_left < 0) {
> +		sdev_printk(KERN_ERR, scmd->device,
> +		    "scsi_dma_map failed: request for %d bytes!\n",
> +		    scsi_bufflen(scmd));
> +		return -ENOMEM;
> +	}
> +	if (sges_left > MPI3MR_SG_DEPTH) {
> +		sdev_printk(KERN_ERR, scmd->device,
> +		    "scsi_dma_map returned unsupported sge count %d!\n",
> +		    sges_left);
> +		return -ENOMEM;
> +	}
> +
> +	sges_in_segment = (mrioc->facts.op_req_sz -
> +	    offsetof(Mpi3SCSIIORequest_t, SGL))/sizeof(Mpi3SGESimple_t);
> +
> +	if (sges_left <= sges_in_segment)
> +		goto fill_in_last_segment;
> +
> +	/* fill in main message segment when there is a chain following */
> +	while (sges_in_segment > 1) {
> +		mpi3mr_add_sg_single(sg_local, simple_sgl_flags,
> +		    sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
> +		sg_scmd = sg_next(sg_scmd);
> +		sg_local += sizeof(Mpi3SGESimple_t);
> +		sges_left--;
> +		sges_in_segment--;
> +	}
> +
> +	chain_idx = mpi3mr_get_chain_idx(mrioc);
> +	if (chain_idx < 0)
> +		return -1;
> +	chain_req = &mrioc->chain_sgl_list[chain_idx];
> +	priv->chain_idx = chain_idx;
> +
> +	chain = chain_req->addr;
> +	chain_dma = chain_req->dma_addr;
> +	sges_in_segment = sges_left;
> +	chain_length = sges_in_segment * sizeof(Mpi3SGESimple_t);
> +
> +	mpi3mr_add_sg_single(sg_local, last_chain_sgl_flags,
> +	    chain_length, chain_dma);
> +
> +	sg_local = chain;
> +
> +fill_in_last_segment:
> +	while (sges_left > 0) {
> +		if (sges_left == 1)
> +			mpi3mr_add_sg_single(sg_local,
> +			    simple_sgl_flags_last, sg_dma_len(sg_scmd),
> +			    sg_dma_address(sg_scmd));
> +		else
> +			mpi3mr_add_sg_single(sg_local, simple_sgl_flags,
> +			    sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
> +		sg_scmd = sg_next(sg_scmd);
> +		sg_local += sizeof(Mpi3SGESimple_t);
> +		sges_left--;
> +	}
> +
> +	return 0;
> +}
> +
> +/**
> + * mpi3mr_build_sg_scmd - build scatter gather list for SCSI IO
> + * @mrioc: Adapter instance reference
> + * @scmd: SCSI command reference
> + * @scsiio_req: MPI3 SCSI IO request
> + *
> + * This function calls mpi3mr_prepare_sg_scmd for constructing
> + * both data SGEs and protection information SGEs in the MPI
> + * format from the SCSI Command as appropriate .
> + *
> + * Return: return value of mpi3mr_prepare_sg_scmd.
> + */
> +static int mpi3mr_build_sg_scmd(struct mpi3mr_ioc *mrioc,
> +	struct scsi_cmnd *scmd, Mpi3SCSIIORequest_t *scsiio_req)
> +{
> +	int ret;
> +
> +	ret = mpi3mr_prepare_sg_scmd(mrioc, scmd, scsiio_req);
> +	if (ret)
> +		return ret;
> +
> +	return ret;
> +}
> +
>   
>   /**
>    * mpi3mr_map_queues - Map queues callback handler
> @@ -44,6 +509,73 @@ static int mpi3mr_map_queues(struct Scsi_Host *shost)
>   	    mrioc->pdev, mrioc->op_reply_q_offset);
>   }
>   
> +/**
> + * mpi3mr_scan_start - Scan start callback handler
> + * @shost: SCSI host reference
> + *
> + * Issue port enable request asynchronously.
> + *
> + * Return: Nothing
> + */
> +static void mpi3mr_scan_start(struct Scsi_Host *shost)
> +{
> +	struct mpi3mr_ioc *mrioc = shost_priv(shost);
> +
> +	mrioc->scan_started = 1;
> +	ioc_info(mrioc, "%s :Issuing Port Enable\n", __func__);
> +	if (mpi3mr_issue_port_enable(mrioc, 1)) {
> +		ioc_err(mrioc, "%s :Issuing port enable failed\n", __func__);
> +		mrioc->scan_started = 0;
> +		mrioc->scan_failed = MPI3_IOCSTATUS_INTERNAL_ERROR;
> +	}
> +
> +}
> +
> +/**
> + * mpi3mr_scan_finished - Scan finished callback handler
> + * @shost: SCSI host reference
> + * @time: Jiffies from the scan start
> + *
> + * Checks whether the port enable is completed or timedout or
> + * failed and set the scan status accordingly after taking any
> + * recovery if required.
> + *
> + * Return: 1 on scan finished or timed out, 0 for in progress
> + */
> +static int mpi3mr_scan_finished(struct Scsi_Host *shost,
> +	unsigned long time)
> +{
> +	struct mpi3mr_ioc *mrioc = shost_priv(shost);
> +	u32 pe_timeout = MPI3MR_PORTENABLE_TIMEOUT;
> +
> +	if (time >= (pe_timeout * HZ)) {
> +		mrioc->init_cmds.is_waiting = 0;
> +		mrioc->init_cmds.callback = NULL;
> +		mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
> +		ioc_err(mrioc, "%s :port enable request timed out\n", __func__);
> +		mrioc->is_driver_loading = 0;
> +		mpi3mr_soft_reset_handler(mrioc,
> +		    MPI3MR_RESET_FROM_PE_TIMEOUT, 1);
> +	}
> +
> +	if (mrioc->scan_failed) {
> +		ioc_err(mrioc,
> +		    "%s :port enable failed with (ioc_status=0x%08x)\n",
> +		    __func__, mrioc->scan_failed);
> +		mrioc->is_driver_loading = 0;
> +		mrioc->stop_drv_processing = 1;
> +		return 1;
> +	}
> +
> +	if (mrioc->scan_started)
> +		return 0;
> +	ioc_info(mrioc, "%s :port enable: SUCCESS\n", __func__);
> +	mrioc->is_driver_loading = 0;
> +
> +	return 1;
> +}
> +
> +
>   /**
>    * mpi3mr_slave_destroy - Slave destroy callback handler
>    * @sdev: SCSI device reference
> @@ -126,10 +658,114 @@ static int mpi3mr_target_alloc(struct scsi_target *starget)
>   static int mpi3mr_qcmd(struct Scsi_Host *shost,
>   	struct scsi_cmnd *scmd)
>   {
> +	struct mpi3mr_ioc *mrioc = shost_priv(shost);
> +	struct mpi3mr_stgt_priv_data *stgt_priv_data;
> +	struct mpi3mr_sdev_priv_data *sdev_priv_data;
> +	struct scmd_priv *scmd_priv_data = NULL;
> +	Mpi3SCSIIORequest_t *scsiio_req = NULL;
> +	struct op_req_qinfo *op_req_q = NULL;
>   	int retval = 0;
> +	u16 dev_handle;
> +	u16 host_tag;
> +	u32 scsiio_flags = 0;
> +	struct request *rq = scmd->request;
> +	int iprio_class;
> +
> +	sdev_priv_data = scmd->device->hostdata;
> +	if (!sdev_priv_data || !sdev_priv_data->tgt_priv_data) {
> +		scmd->result = DID_NO_CONNECT << 16;
> +		scmd->scsi_done(scmd);
> +		goto out;
> +	}
>   
> -	scmd->result = DID_NO_CONNECT << 16;
> -	scmd->scsi_done(scmd);
> +	if (mrioc->stop_drv_processing) {
> +		scmd->result = DID_NO_CONNECT << 16;
> +		scmd->scsi_done(scmd);
> +		goto out;
> +	}
> +
> +	if (mrioc->reset_in_progress) {
> +		retval = SCSI_MLQUEUE_HOST_BUSY;
> +		goto out;
> +	}
> +
> +	stgt_priv_data = sdev_priv_data->tgt_priv_data;
> +
> +	dev_handle = stgt_priv_data->dev_handle;
> +	if (dev_handle == MPI3MR_INVALID_DEV_HANDLE) {
> +		scmd->result = DID_NO_CONNECT << 16;
> +		scmd->scsi_done(scmd);
> +		goto out;
> +	}
> +	if (stgt_priv_data->dev_removed) {
> +		scmd->result = DID_NO_CONNECT << 16;
> +		scmd->scsi_done(scmd);
> +		goto out;
> +	}
> +
> +	if (atomic_read(&stgt_priv_data->block_io)) {
> +		if (mrioc->stop_drv_processing) {
> +			scmd->result = DID_NO_CONNECT << 16;
> +			scmd->scsi_done(scmd);
> +			goto out;
> +		}
> +		retval = SCSI_MLQUEUE_DEVICE_BUSY;
> +		goto out;
> +	}
> +
> +	host_tag = mpi3mr_host_tag_for_scmd(mrioc, scmd);
> +	if (host_tag == MPI3MR_HOSTTAG_INVALID) {
> +		scmd->result = DID_ERROR << 16;
> +		scmd->scsi_done(scmd);
> +		goto out;
> +	}
> +
> +	if (scmd->sc_data_direction == DMA_FROM_DEVICE)
> +		scsiio_flags = MPI3_SCSIIO_FLAGS_DATADIRECTION_READ;
> +	else if (scmd->sc_data_direction == DMA_TO_DEVICE)
> +		scsiio_flags = MPI3_SCSIIO_FLAGS_DATADIRECTION_WRITE;
> +	else
> +		scsiio_flags = MPI3_SCSIIO_FLAGS_DATADIRECTION_NO_DATA_TRANSFER;
> +
> +	scsiio_flags |= MPI3_SCSIIO_FLAGS_TASKATTRIBUTE_SIMPLEQ;
> +
> +	if (sdev_priv_data->ncq_prio_enable) {
> +		iprio_class = IOPRIO_PRIO_CLASS(req_get_ioprio(rq));
> +		if (iprio_class == IOPRIO_CLASS_RT)
> +			scsiio_flags |= 1 << MPI3_SCSIIO_FLAGS_CMDPRI_SHIFT;
> +	}
> +
> +	if (scmd->cmd_len > 16)
> +		scsiio_flags |= MPI3_SCSIIO_FLAGS_CDB_GREATER_THAN_16;
> +
> +	scmd_priv_data = scsi_cmd_priv(scmd);
> +	memset(scmd_priv_data->mpi3mr_scsiio_req, 0, MPI3MR_ADMIN_REQ_FRAME_SZ);
> +	scsiio_req = (Mpi3SCSIIORequest_t *) scmd_priv_data->mpi3mr_scsiio_req;
> +	scsiio_req->Function = MPI3_FUNCTION_SCSI_IO;
> +	scsiio_req->HostTag = cpu_to_le16(host_tag);
> +
> +	memcpy(scsiio_req->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
> +	scsiio_req->DataLength = cpu_to_le32(scsi_bufflen(scmd));
> +	scsiio_req->DevHandle = cpu_to_le16(dev_handle);
> +	scsiio_req->Flags = cpu_to_le32(scsiio_flags);
> +	int_to_scsilun(sdev_priv_data->lun_id,
> +	    (struct scsi_lun *)scsiio_req->LUN);
> +
> +	if (mpi3mr_build_sg_scmd(mrioc, scmd, scsiio_req)) {
> +		mpi3mr_clear_scmd_priv(mrioc, scmd);
> +		retval = SCSI_MLQUEUE_HOST_BUSY;
> +		goto out;
> +	}
> +	op_req_q = &mrioc->req_qinfo[scmd_priv_data->req_q_idx];
> +
> +	if (mpi3mr_op_request_post(mrioc, op_req_q,
> +	    scmd_priv_data->mpi3mr_scsiio_req)) {
> +		mpi3mr_clear_scmd_priv(mrioc, scmd);
> +		retval = SCSI_MLQUEUE_HOST_BUSY;
> +		goto out;
> +	}
> +
> +out:
>   	return retval;
>   }
>   
> @@ -143,6 +779,8 @@ static struct scsi_host_template mpi3mr_driver_template = {
>   	.slave_configure		= mpi3mr_slave_configure,
>   	.target_destroy			= mpi3mr_target_destroy,
>   	.slave_destroy			= mpi3mr_slave_destroy,
> +	.scan_finished			= mpi3mr_scan_finished,
> +	.scan_start			= mpi3mr_scan_start,
>   	.map_queues			= mpi3mr_map_queues,
>   	.no_write_same			= 1,
>   	.can_queue			= 1,
> @@ -218,6 +856,7 @@ mpi3mr_probe(struct pci_dev *pdev, const struct pci_device_id *id)
>   	spin_lock_init(&mrioc->admin_req_lock);
>   	spin_lock_init(&mrioc->reply_free_queue_lock);
>   	spin_lock_init(&mrioc->sbq_lock);
> +	spin_lock_init(&mrioc->chain_buf_lock);
>   
>   	mpi3mr_init_drv_cmd(&mrioc->init_cmds, MPI3MR_HOSTTAG_INITCMDS);
>   	if (pdev->revision)
> @@ -287,6 +926,7 @@ static void mpi3mr_remove(struct pci_dev *pdev)
>   	while (mrioc->reset_in_progress || mrioc->is_driver_loading)
>   		ssleep(1);
>   
> +	mrioc->stop_drv_processing = 1;
>   
>   	scsi_remove_host(shost);
>   
> @@ -319,6 +959,7 @@ static void mpi3mr_shutdown(struct pci_dev *pdev)
>   	mrioc = shost_priv(shost);
>   	while (mrioc->reset_in_progress || mrioc->is_driver_loading)
>   		ssleep(1);
> +	mrioc->stop_drv_processing = 1;
>   
>   	mpi3mr_cleanup_ioc(mrioc);
>   
> 

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                Kernel Storage Architect
hare@suse.de                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer

^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 05/24] mpi3mr: add support of internal watchdog thread
  2020-12-22 10:11 ` [PATCH 05/24] mpi3mr: add support of internal watchdog thread Kashyap Desai
@ 2021-02-28 13:24   ` Hannes Reinecke
  0 siblings, 0 replies; 75+ messages in thread
From: Hannes Reinecke @ 2021-02-28 13:24 UTC (permalink / raw)
  To: Kashyap Desai, linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, sathya.prakash

On 12/22/20 11:11 AM, Kashyap Desai wrote:
> Watchdog thread is driver's internal thread which does few things like
> detecting FW fault and reset the controller, Timestamp sync etc.
> 
> Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
> Cc: sathya.prakash@broadcom.com
> ---
>   drivers/scsi/mpi3mr/mpi3mr.h    |  11 +++
>   drivers/scsi/mpi3mr/mpi3mr_fw.c | 125 ++++++++++++++++++++++++++++++++
>   drivers/scsi/mpi3mr/mpi3mr_os.c |   3 +
>   3 files changed, 139 insertions(+)
> 
Reviewed-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                Kernel Storage Architect
hare@suse.de                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer

^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 06/24] mpi3mr: add support of event handling part-1
  2020-12-22 10:11 ` [PATCH 06/24] mpi3mr: add support of event handling part-1 Kashyap Desai
  2020-12-27 13:14     ` kernel test robot
  2021-02-22 15:31   ` Tomas Henzl
@ 2021-03-01  6:47   ` Hannes Reinecke
  2 siblings, 0 replies; 75+ messages in thread
From: Hannes Reinecke @ 2021-03-01  6:47 UTC (permalink / raw)
  To: Kashyap Desai, linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, sathya.prakash

On 12/22/20 11:11 AM, Kashyap Desai wrote:
> Firmware can report various MPI Events.
> Support for certain Events (as listed below) are enabled in the driver
> and their processing in driver is covered in this patch.
> 
> MPI3_EVENT_DEVICE_ADDED
> MPI3_EVENT_DEVICE_INFO_CHANGED
> MPI3_EVENT_DEVICE_STATUS_CHANGE
> MPI3_EVENT_ENCL_DEVICE_STATUS_CHANGE
> MPI3_EVENT_SAS_TOPOLOGY_CHANGE_LIST
> MPI3_EVENT_SAS_DISCOVERY
> MPI3_EVENT_SAS_DEVICE_DISCOVERY_ERROR
> 
> Key support in this patch is device add/removal.
> 
> Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
> Cc: sathya.prakash@broadcom.com
> ---
>   drivers/scsi/mpi3mr/mpi/mpi30_api.h  |    2 +
>   drivers/scsi/mpi3mr/mpi/mpi30_cnfg.h | 2721 ++++++++++++++++++++++++++
>   drivers/scsi/mpi3mr/mpi/mpi30_sas.h  |   46 +
>   drivers/scsi/mpi3mr/mpi3mr.h         |  195 ++
>   drivers/scsi/mpi3mr/mpi3mr_fw.c      |  177 +-
>   drivers/scsi/mpi3mr/mpi3mr_os.c      | 1452 ++++++++++++++
>   6 files changed, 4592 insertions(+), 1 deletion(-)
>   create mode 100644 drivers/scsi/mpi3mr/mpi/mpi30_cnfg.h
>   create mode 100644 drivers/scsi/mpi3mr/mpi/mpi30_sas.h
> 
> diff --git a/drivers/scsi/mpi3mr/mpi/mpi30_api.h b/drivers/scsi/mpi3mr/mpi/mpi30_api.h
> index ca07387536d3..7bdd5aeb23be 100644
> --- a/drivers/scsi/mpi3mr/mpi/mpi30_api.h
> +++ b/drivers/scsi/mpi3mr/mpi/mpi30_api.h
> @@ -14,8 +14,10 @@
>   
>   #include "mpi30_type.h"
>   #include "mpi30_transport.h"
> +#include "mpi30_cnfg.h"
>   #include "mpi30_image.h"
>   #include "mpi30_init.h"
>   #include "mpi30_ioc.h"
> +#include "mpi30_sas.h"
>   
>   #endif  /* MPI30_API_H */
> diff --git a/drivers/scsi/mpi3mr/mpi/mpi30_cnfg.h b/drivers/scsi/mpi3mr/mpi/mpi30_cnfg.h
> new file mode 100644
> index 000000000000..3badb1bb85b1
> --- /dev/null
> +++ b/drivers/scsi/mpi3mr/mpi/mpi30_cnfg.h
> @@ -0,0 +1,2721 @@
> +/*
> + *  Copyright 2017-2020 Broadcom Inc. All rights reserved.
> + *
> + *           Name: mpi30_cnfg.h
> + *    Description: Contains definitions for Configuration messages and pages
> + *  Creation Date: 03/15/2017
> + *        Version: 03.00.00
> + */
> +#ifndef MPI30_CNFG_H
> +#define MPI30_CNFG_H     1
> +
> +/*****************************************************************************
> + *              Configuration Page Types                                     *
> + ****************************************************************************/
> +#define MPI3_CONFIG_PAGETYPE_IO_UNIT                    (0x00)
> +#define MPI3_CONFIG_PAGETYPE_MANUFACTURING              (0x01)
> +#define MPI3_CONFIG_PAGETYPE_IOC                        (0x02)
> +#define MPI3_CONFIG_PAGETYPE_UEFI_BSD                   (0x03)
> +#define MPI3_CONFIG_PAGETYPE_SECURITY                   (0x04)
> +#define MPI3_CONFIG_PAGETYPE_ENCLOSURE                  (0x11)
> +#define MPI3_CONFIG_PAGETYPE_DEVICE                     (0x12)
> +#define MPI3_CONFIG_PAGETYPE_SAS_IO_UNIT                (0x20)
> +#define MPI3_CONFIG_PAGETYPE_SAS_EXPANDER               (0x21)
> +#define MPI3_CONFIG_PAGETYPE_SAS_PHY                    (0x23)
> +#define MPI3_CONFIG_PAGETYPE_SAS_PORT                   (0x24)
> +#define MPI3_CONFIG_PAGETYPE_PCIE_IO_UNIT               (0x30)
> +#define MPI3_CONFIG_PAGETYPE_PCIE_SWITCH                (0x31)
> +#define MPI3_CONFIG_PAGETYPE_PCIE_LINK                  (0x33)
> +
> +/*****************************************************************************
> + *              Configuration Page Attributes                                *
> + ****************************************************************************/
> +#define MPI3_CONFIG_PAGEATTR_MASK                       (0xF0)
> +#define MPI3_CONFIG_PAGEATTR_READ_ONLY                  (0x00)
> +#define MPI3_CONFIG_PAGEATTR_CHANGEABLE                 (0x10)
> +#define MPI3_CONFIG_PAGEATTR_PERSISTENT                 (0x20)
> +
> +/*****************************************************************************
> + *              Configuration Page Actions                                   *
> + ****************************************************************************/
> +#define MPI3_CONFIG_ACTION_PAGE_HEADER                  (0x00)
> +#define MPI3_CONFIG_ACTION_READ_DEFAULT                 (0x01)
> +#define MPI3_CONFIG_ACTION_READ_CURRENT                 (0x02)
> +#define MPI3_CONFIG_ACTION_WRITE_CURRENT                (0x03)
> +#define MPI3_CONFIG_ACTION_READ_PERSISTENT              (0x04)
> +#define MPI3_CONFIG_ACTION_WRITE_PERSISTENT             (0x05)
> +
> +/*****************************************************************************
> + *              Configuration Page Addressing                                *
> + ****************************************************************************/
> +
> +/**** Device PageAddress Format ****/
> +#define MPI3_DEVICE_PGAD_FORM_MASK                      (0xF0000000)
> +#define MPI3_DEVICE_PGAD_FORM_GET_NEXT_HANDLE           (0x00000000)
> +#define MPI3_DEVICE_PGAD_FORM_HANDLE                    (0x20000000)
> +#define MPI3_DEVICE_PGAD_HANDLE_MASK                    (0x0000FFFF)
> +
> +/**** SAS Expander PageAddress Format ****/
> +#define MPI3_SAS_EXPAND_PGAD_FORM_MASK                  (0xF0000000)
> +#define MPI3_SAS_EXPAND_PGAD_FORM_GET_NEXT_HANDLE       (0x00000000)
> +#define MPI3_SAS_EXPAND_PGAD_FORM_HANDLE_PHY_NUM        (0x10000000)
> +#define MPI3_SAS_EXPAND_PGAD_FORM_HANDLE                (0x20000000)
> +#define MPI3_SAS_EXPAND_PGAD_PHYNUM_MASK                (0x00FF0000)
> +#define MPI3_SAS_EXPAND_PGAD_PHYNUM_SHIFT               (16)
> +#define MPI3_SAS_EXPAND_PGAD_HANDLE_MASK                (0x0000FFFF)
> +
> +/**** SAS Phy PageAddress Format ****/
> +#define MPI3_SAS_PHY_PGAD_FORM_MASK                     (0xF0000000)
> +#define MPI3_SAS_PHY_PGAD_FORM_PHY_NUMBER               (0x00000000)
> +#define MPI3_SAS_PHY_PGAD_PHY_NUMBER_MASK               (0x000000FF)
> +
> +/**** SAS Port PageAddress Format ****/
> +#define MPI3_SASPORT_PGAD_FORM_MASK                     (0xF0000000)
> +#define MPI3_SASPORT_PGAD_FORM_GET_NEXT_PORT            (0x00000000)
> +#define MPI3_SASPORT_PGAD_FORM_PORT_NUM                 (0x10000000)
> +#define MPI3_SASPORT_PGAD_PORT_NUMBER_MASK              (0x000000FF)
> +
> +/**** Enclosure PageAddress Format ****/
> +#define MPI3_ENCLOS_PGAD_FORM_MASK                      (0xF0000000)
> +#define MPI3_ENCLOS_PGAD_FORM_GET_NEXT_HANDLE           (0x00000000)
> +#define MPI3_ENCLOS_PGAD_FORM_HANDLE                    (0x10000000)
> +#define MPI3_ENCLOS_PGAD_HANDLE_MASK                    (0x0000FFFF)
> +
> +/**** PCIe Switch PageAddress Format ****/
> +#define MPI3_PCIE_SWITCH_PGAD_FORM_MASK                 (0xF0000000)
> +#define MPI3_PCIE_SWITCH_PGAD_FORM_GET_NEXT_HANDLE      (0x00000000)
> +#define MPI3_PCIE_SWITCH_PGAD_FORM_HANDLE_PORT_NUM      (0x10000000)
> +#define MPI3_PCIE_SWITCH_PGAD_FORM_HANDLE               (0x20000000)
> +#define MPI3_PCIE_SWITCH_PGAD_PORTNUM_MASK              (0x00FF0000)
> +#define MPI3_PCIE_SWITCH_PGAD_PORTNUM_SHIFT             (16)
> +#define MPI3_PCIE_SWITCH_PGAD_HANDLE_MASK               (0x0000FFFF)
> +
> +/**** PCIe Link PageAddress Format ****/
> +#define MPI3_PCIE_LINK_PGAD_FORM_MASK                   (0xF0000000)
> +#define MPI3_PCIE_LINK_PGAD_FORM_GET_NEXT_LINK          (0x00000000)
> +#define MPI3_PCIE_LINK_PGAD_FORM_LINK_NUM               (0x10000000)
> +#define MPI3_PCIE_LINK_PGAD_LINKNUM_MASK                (0x000000FF)
> +
> +/**** Security PageAddress Format ****/
> +#define MPI3_SECURITY_PGAD_FORM_MASK                    (0xF0000000)
> +#define MPI3_SECURITY_PGAD_FORM_GET_NEXT_SLOT           (0x00000000)
> +#define MPI3_SECURITY_PGAD_FORM_SOT_NUM                 (0x10000000)
> +#define MPI3_SECURITY_PGAD_SLOT_GROUP_MASK              (0x0000FF00)
> +#define MPI3_SECURITY_PGAD_SLOT_MASK                    (0x000000FF)
> +
> +/*****************************************************************************
> + *              Configuration Request Message                                *
> + ****************************************************************************/
> +typedef struct _MPI3_CONFIG_REQUEST {
> +    U16             HostTag;                            /* 0x00 */
> +    U8              IOCUseOnly02;                       /* 0x02 */
> +    U8              Function;                           /* 0x03 */
> +    U16             IOCUseOnly04;                       /* 0x04 */
> +    U8              IOCUseOnly06;                       /* 0x06 */
> +    U8              MsgFlags;                           /* 0x07 */
> +    U16             ChangeCount;                        /* 0x08 */
> +    U16             Reserved0A;                         /* 0x0A */
> +    U8              PageVersion;                        /* 0x0C */
> +    U8              PageNumber;                         /* 0x0D */
> +    U8              PageType;                           /* 0x0E */
> +    U8              Action;                             /* 0x0F */
> +    U32             PageAddress;                        /* 0x10 */
> +    U16             PageLength;                         /* 0x14 */
> +    U16             Reserved16;                         /* 0x16 */
> +    U32             Reserved18[2];                      /* 0x18 */
> +    MPI3_SGE_UNION  SGL;                                /* 0x20 */
> +} MPI3_CONFIG_REQUEST, MPI3_POINTER PTR_MPI3_CONFIG_REQUEST,
> +  Mpi3ConfigRequest_t, MPI3_POINTER pMpi3ConfigRequest_t;
> +
Can you please restrict yourself to _one_ set of codingstyle?
IE please keep your typedefs to all caps, or mixed caps.
But having both is just silly.

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                Kernel Storage Architect
hare@suse.de                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer

^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 07/24] mpi3mr: add support of event handling pcie devices part-2
  2020-12-22 10:11 ` [PATCH 07/24] mpi3mr: add support of event handling pcie devices part-2 Kashyap Desai
@ 2021-03-01  6:52   ` Hannes Reinecke
  0 siblings, 0 replies; 75+ messages in thread
From: Hannes Reinecke @ 2021-03-01  6:52 UTC (permalink / raw)
  To: Kashyap Desai, linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, sathya.prakash

On 12/22/20 11:11 AM, Kashyap Desai wrote:
> Firmware can report various MPI Events.
> Support for certain Events (as listed below) are enabled in the driver
> and their processing in driver is covered in this patch.
> 
> MPI3_EVENT_PCIE_TOPOLOGY_CHANGE_LIST
> MPI3_EVENT_PCIE_ENUMERATION
> 
> Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
> Cc: sathya.prakash@broadcom.com
> ---
>   drivers/scsi/mpi3mr/mpi3mr_fw.c |   2 +
>   drivers/scsi/mpi3mr/mpi3mr_os.c | 202 ++++++++++++++++++++++++++++++++
>   2 files changed, 204 insertions(+)
> 
Reviewed-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                Kernel Storage Architect
hare@suse.de                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer

^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 08/24] mpi3mr: add support of event handling part-3
  2020-12-22 10:11 ` [PATCH 08/24] mpi3mr: add support of event handling part-3 Kashyap Desai
@ 2021-03-01  6:53   ` Hannes Reinecke
  0 siblings, 0 replies; 75+ messages in thread
From: Hannes Reinecke @ 2021-03-01  6:53 UTC (permalink / raw)
  To: Kashyap Desai, linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, sathya.prakash

On 12/22/20 11:11 AM, Kashyap Desai wrote:
> Firmware can report various MPI Events.
> Support for certain Events (as listed below) are enabled in the driver
> and their processing in driver is covered in this patch.
> 
> MPI3_EVENT_SAS_BROADCAST_PRIMITIVE
> MPI3_EVENT_CABLE_MGMT
> MPI3_EVENT_ENERGY_PACK_CHANGE
> 
> Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
> Cc: sathya.prakash@broadcom.com
> ---
>   drivers/scsi/mpi3mr/mpi3mr_fw.c |  3 +++
>   drivers/scsi/mpi3mr/mpi3mr_os.c | 37 +++++++++++++++++++++++++++++++++
>   2 files changed, 40 insertions(+)
> 
Reviewed-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                Kernel Storage Architect
hare@suse.de                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer

^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 09/24] mpi3mr: add support for recovering controller
  2020-12-22 10:11 ` [PATCH 09/24] mpi3mr: add support for recovering controller Kashyap Desai
@ 2021-03-01  6:56   ` Hannes Reinecke
  0 siblings, 0 replies; 75+ messages in thread
From: Hannes Reinecke @ 2021-03-01  6:56 UTC (permalink / raw)
  To: Kashyap Desai, linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, sathya.prakash

On 12/22/20 11:11 AM, Kashyap Desai wrote:
> Added h/w defined process of doing controller reset.
> The driver on detection of firmware fault or any kind of unresponsiveness in
> the controller (Any admin command time outs) results in resetting the controller.
> The primary reset mechanisms used are either soft reset or diag fault reset.
> Reset is performed if the host sets the ResetAction field in the HostDiagnostic
> register to a 001b (Soft Reset) or 007b(diag fault reset).
> The driver after successfully resetting the controller reinitialize the
> controller by going through start of the day controller initialization procedures.
> The pending I/Os during the reset are returned back to SML for retry.
> 
> Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
> Cc: sathya.prakash@broadcom.com
> ---
>   drivers/scsi/mpi3mr/mpi3mr.h    |  22 +-
>   drivers/scsi/mpi3mr/mpi3mr_fw.c | 416 +++++++++++++++++++++++++++++---
>   drivers/scsi/mpi3mr/mpi3mr_os.c |  93 ++++++-
>   3 files changed, 488 insertions(+), 43 deletions(-)
> 
Reviewed-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                Kernel Storage Architect
hare@suse.de                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer

^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 10/24] mpi3mr: add support of timestamp sync with firmware
  2020-12-22 10:11 ` [PATCH 10/24] mpi3mr: add support of timestamp sync with firmware Kashyap Desai
@ 2021-03-01  6:57   ` Hannes Reinecke
  0 siblings, 0 replies; 75+ messages in thread
From: Hannes Reinecke @ 2021-03-01  6:57 UTC (permalink / raw)
  To: Kashyap Desai, linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, sathya.prakash

On 12/22/20 11:11 AM, Kashyap Desai wrote:
> This operation requests that the IOC update the TimeStamp.
> 
> When the I/O Unit is powered on, it sets the TimeStamp field value to
> 0x0000_0000_0000_0000 and increments the current value every millisecond.
> A host driver sets the TimeStamp field to the current time by using an
> IOCInit request. The TimeStamp field is periodically updated by host driver.
> 
> Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
> Cc: sathya.prakash@broadcom.com
> ---
>   drivers/scsi/mpi3mr/mpi3mr.h    |  3 ++
>   drivers/scsi/mpi3mr/mpi3mr_fw.c | 74 +++++++++++++++++++++++++++++++++
>   2 files changed, 77 insertions(+)
> 
Reviewed-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                Kernel Storage Architect
hare@suse.de                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer

^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 11/24] mpi3mr: print ioc info for debugging
  2020-12-22 10:11 ` [PATCH 11/24] mpi3mr: print ioc info for debugging Kashyap Desai
@ 2021-03-01  6:59   ` Hannes Reinecke
  0 siblings, 0 replies; 75+ messages in thread
From: Hannes Reinecke @ 2021-03-01  6:59 UTC (permalink / raw)
  To: Kashyap Desai, linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, sathya.prakash

On 12/22/20 11:11 AM, Kashyap Desai wrote:
> Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
> Cc: sathya.prakash@broadcom.com
> ---
>   drivers/scsi/mpi3mr/mpi3mr_fw.c | 63 +++++++++++++++++++++++++++++++++
>   1 file changed, 63 insertions(+)
> 
> diff --git a/drivers/scsi/mpi3mr/mpi3mr_fw.c b/drivers/scsi/mpi3mr/mpi3mr_fw.c
> index 10ff287e78db..aad0a2bd06b9 100644
> --- a/drivers/scsi/mpi3mr/mpi3mr_fw.c
> +++ b/drivers/scsi/mpi3mr/mpi3mr_fw.c
> @@ -2540,6 +2540,68 @@ int mpi3mr_issue_port_enable(struct mpi3mr_ioc *mrioc, u8 async)
>   	return retval;
>   }
>   
> +/**
> + * mpi3mr_print_ioc_info - Display controller information
> + * @mrioc: Adapter instance reference
> + *
> + * Display controller personalit, capability, supported
> + * protocols etc.
> + *
> + * Return: Nothing
> + */
> +static void
> +mpi3mr_print_ioc_info(struct mpi3mr_ioc *mrioc)
> +{
> +	int i = 0;
> +	char personality[16];
> +	struct mpi3mr_compimg_ver *fwver = &mrioc->facts.fw_ver;
> +
> +	switch (mrioc->facts.personality) {
> +	case MPI3_IOCFACTS_FLAGS_PERSONALITY_EHBA:
> +		strcpy(personality, "Enhanced HBA");
> +		break;
> +	case MPI3_IOCFACTS_FLAGS_PERSONALITY_RAID_DDR:
> +		strcpy(personality, "RAID");
> +		break;
> +	default:
> +		strcpy(personality, "Unknown");
> +		break;
> +	}
> +
> +	ioc_info(mrioc, "Running in %s Personality", personality);
> +
> +	ioc_info(mrioc, "FW Version(%d.%d.%d.%d.%d.%d)\n",
> +	fwver->gen_major, fwver->gen_minor, fwver->ph_major,
> +	    fwver->ph_minor, fwver->cust_id, fwver->build_num);
> +
> +	ioc_info(mrioc, "Protocol=(");
> +
> +	if (mrioc->facts.protocol_flags &
> +	    MPI3_IOCFACTS_PROTOCOL_SCSI_INITIATOR) {
> +		pr_cont("Initiator");
> +		i++;
> +	}
> +
> +	if (mrioc->facts.protocol_flags &
> +	    MPI3_IOCFACTS_PROTOCOL_SCSI_TARGET) {
> +		pr_cont("%sTarget", i ? "," : "");
> +		i++;
> +	}
> +
> +	if (mrioc->facts.protocol_flags &
> +	    MPI3_IOCFACTS_PROTOCOL_NVME) {
> +		pr_cont("%sNVMe attachment", i ? "," : "");
> +		i++;
> +	}
> +	pr_cont("), ");
> +	pr_cont("Capabilities=(");
> +
> +	if (mrioc->facts.ioc_capabilities &
> +	    MPI3_IOCFACTS_CAPABILITY_RAID_CAPABLE)
> +		pr_cont("RAID");
> +
> +	pr_cont(")\n");
> +}
>  
Yikes. Don't.

pr_cont() has the habit to be broken up into individual lines per call 
if the system has to print out lots of messages.
I would seriously advocate having just one pr_XX() call per line, and 
use conditional statements to construct the arguments.

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                Kernel Storage Architect
hare@suse.de                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer

^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 12/24] mpi3mr: add bios_param shost template hook
  2020-12-22 10:11 ` [PATCH 12/24] mpi3mr: add bios_param shost template hook Kashyap Desai
@ 2021-03-01  7:00   ` Hannes Reinecke
  0 siblings, 0 replies; 75+ messages in thread
From: Hannes Reinecke @ 2021-03-01  7:00 UTC (permalink / raw)
  To: Kashyap Desai, linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, sathya.prakash

On 12/22/20 11:11 AM, Kashyap Desai wrote:
> Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
> Cc: sathya.prakash@broadcom.com
> ---
>   drivers/scsi/mpi3mr/mpi3mr_os.c | 40 +++++++++++++++++++++++++++++++++
>   1 file changed, 40 insertions(+)
> 
> diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c
> index 4d94352a4d48..7e0eacf45d84 100644
> --- a/drivers/scsi/mpi3mr/mpi3mr_os.c
> +++ b/drivers/scsi/mpi3mr/mpi3mr_os.c
> @@ -2078,6 +2078,45 @@ static int mpi3mr_build_sg_scmd(struct mpi3mr_ioc *mrioc,
>   	return ret;
>   }
>   
> +/**
> + * mpi3mr_bios_param - BIOS param callback
> + * @sdev: SCSI device reference
> + * @bdev: Block device reference
> + * @capacity: Capacity in logical sectors
> + * @params: Parameter array
> + *
> + * Just the parameters with heads/secots/cylinders.
> + *
> + * Return: 0 always
> + */
> +static int mpi3mr_bios_param(struct scsi_device *sdev,
> +	struct block_device *bdev, sector_t capacity, int params[])
> +{
> +	int heads;
> +	int sectors;
> +	sector_t cylinders;
> +	ulong dummy;
> +
> +	heads = 64;
> +	sectors = 32;
> +
> +	dummy = heads * sectors;
> +	cylinders = capacity;
> +	sector_div(cylinders, dummy);
> +
> +	if ((ulong)capacity >= 0x200000) {
> +		heads = 255;
> +		sectors = 63;
> +		dummy = heads * sectors;
> +		cylinders = capacity;
> +		sector_div(cylinders, dummy);
> +	}
> +
> +	params[0] = heads;
> +	params[1] = sectors;
> +	params[2] = cylinders;
> +	return 0;
> +}
>   
>   /**
>    * mpi3mr_map_queues - Map queues callback handler
> @@ -2511,6 +2550,7 @@ static struct scsi_host_template mpi3mr_driver_template = {
>   	.slave_destroy			= mpi3mr_slave_destroy,
>   	.scan_finished			= mpi3mr_scan_finished,
>   	.scan_start			= mpi3mr_scan_start,
> +	.bios_param			= mpi3mr_bios_param,
>   	.map_queues			= mpi3mr_map_queues,
>   	.no_write_same			= 1,
>   	.can_queue			= 1,
> 
OMG. I had hoped we could kill this eventually.
Oh well.

Reviewed-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                Kernel Storage Architect
hare@suse.de                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer

^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 13/24] mpi3mr: implement scsi error handler hooks
  2020-12-22 10:11 ` [PATCH 13/24] mpi3mr: implement scsi error handler hooks Kashyap Desai
@ 2021-03-01  7:09   ` Hannes Reinecke
  2021-04-16 14:12     ` Kashyap Desai
  0 siblings, 1 reply; 75+ messages in thread
From: Hannes Reinecke @ 2021-03-01  7:09 UTC (permalink / raw)
  To: Kashyap Desai, linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, sathya.prakash

On 12/22/20 11:11 AM, Kashyap Desai wrote:
> SCSI EH hook is added.
> 
> Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
> Cc: sathya.prakash@broadcom.com
> ---
>   drivers/scsi/mpi3mr/mpi3mr.h    |   3 +
>   drivers/scsi/mpi3mr/mpi3mr_fw.c |  51 ++++
>   drivers/scsi/mpi3mr/mpi3mr_os.c | 431 +++++++++++++++++++++++++++++++-
>   3 files changed, 484 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/scsi/mpi3mr/mpi3mr.h b/drivers/scsi/mpi3mr/mpi3mr.h
> index 24e2337466dc..a677a4b57a2c 100644
> --- a/drivers/scsi/mpi3mr/mpi3mr.h
> +++ b/drivers/scsi/mpi3mr/mpi3mr.h
> @@ -97,6 +97,7 @@ extern struct list_head mrioc_list;
>   /* command/controller interaction timeout definitions in seconds */
>   #define MPI3MR_INTADMCMD_TIMEOUT		10
>   #define MPI3MR_PORTENABLE_TIMEOUT		300
> +#define MPI3MR_ABORTTM_TIMEOUT			30
>   #define MPI3MR_RESETTM_TIMEOUT			30
>   #define MPI3MR_RESET_HOST_IOWAIT_TIMEOUT	5
>   #define MPI3MR_TSUPDATE_INTERVAL		900
> @@ -628,6 +629,7 @@ struct scmd_priv {
>    * @chain_bitmap_sz: Chain buffer allocator bitmap size
>    * @chain_bitmap: Chain buffer allocator bitmap
>    * @chain_buf_lock: Chain buffer list lock
> + * @host_tm_cmds: Command tracker for task management commands
>    * @dev_rmhs_cmds: Command tracker for device removal commands
>    * @devrem_bitmap_sz: Device removal bitmap size
>    * @devrem_bitmap: Device removal bitmap
> @@ -750,6 +752,7 @@ struct mpi3mr_ioc {
>   	void *chain_bitmap;
>   	spinlock_t chain_buf_lock;
>   
> +	struct mpi3mr_drv_cmd host_tm_cmds;
>   	struct mpi3mr_drv_cmd dev_rmhs_cmds[MPI3MR_NUM_DEVRMCMD];
>   	u16 devrem_bitmap_sz;
>   	void *devrem_bitmap;
> diff --git a/drivers/scsi/mpi3mr/mpi3mr_fw.c b/drivers/scsi/mpi3mr/mpi3mr_fw.c
> index aad0a2bd06b9..ba4bfcc17809 100644
> --- a/drivers/scsi/mpi3mr/mpi3mr_fw.c
> +++ b/drivers/scsi/mpi3mr/mpi3mr_fw.c
> @@ -167,9 +167,13 @@ static struct mpi3mr_drv_cmd *
>   mpi3mr_get_drv_cmd(struct mpi3mr_ioc *mrioc, u16 host_tag,
>   	Mpi3DefaultReply_t *def_reply)
>   {
> +	u16 idx;
> +
>   	switch (host_tag) {
>   	case MPI3MR_HOSTTAG_INITCMDS:
>   		return &mrioc->init_cmds;
> +	case MPI3MR_HOSTTAG_BLK_TMS:
> +		return &mrioc->host_tm_cmds;
>   	case MPI3MR_HOSTTAG_INVALID:
>   		if (def_reply && def_reply->Function ==
>   		    MPI3_FUNCTION_EVENT_NOTIFICATION)
> @@ -178,6 +182,11 @@ mpi3mr_get_drv_cmd(struct mpi3mr_ioc *mrioc, u16 host_tag,
>   	default:
>   		break;
>   	}
> +	if (host_tag >= MPI3MR_HOSTTAG_DEVRMCMD_MIN &&
> +	    host_tag <= MPI3MR_HOSTTAG_DEVRMCMD_MAX) {
> +		idx = host_tag - MPI3MR_HOSTTAG_DEVRMCMD_MIN;
> +		return &mrioc->dev_rmhs_cmds[idx];
> +	}
>   
>   	return NULL;
>   }

Looks like this hunk is misdirected, and should be moved to the device 
handling patch ...

> @@ -2035,6 +2044,31 @@ static int mpi3mr_alloc_reply_sense_bufs(struct mpi3mr_ioc *mrioc)
>   	if (!mrioc->init_cmds.reply)
>   		goto out_failed;
>   
> +	mrioc->host_tm_cmds.reply = kzalloc(mrioc->facts.reply_sz, GFP_KERNEL);
> +	if (!mrioc->host_tm_cmds.reply)
> +		goto out_failed;
> +
> +	for (i = 0; i < MPI3MR_NUM_DEVRMCMD; i++) {
> +		mrioc->dev_rmhs_cmds[i].reply = kzalloc(mrioc->facts.reply_sz,
> +		    GFP_KERNEL);
> +		if (!mrioc->dev_rmhs_cmds[i].reply)
> +			goto out_failed;
> +	}

Same here

> +	mrioc->dev_handle_bitmap_sz = mrioc->facts.max_devhandle / 8;
> +	if (mrioc->facts.max_devhandle % 8)
> +		mrioc->dev_handle_bitmap_sz++;
> +	mrioc->removepend_bitmap = kzalloc(mrioc->dev_handle_bitmap_sz,
> +	    GFP_KERNEL);
> +	if (!mrioc->removepend_bitmap)
> +		goto out_failed;
> +
> +	mrioc->devrem_bitmap_sz = MPI3MR_NUM_DEVRMCMD / 8;
> +	if (MPI3MR_NUM_DEVRMCMD % 8)
> +		mrioc->devrem_bitmap_sz++;
> +	mrioc->devrem_bitmap = kzalloc(mrioc->devrem_bitmap_sz,
> +	    GFP_KERNEL);
> +	if (!mrioc->devrem_bitmap)
> +		goto out_failed;
>   >   	mrioc->num_reply_bufs = mrioc->facts.max_reqs + 
MPI3MR_NUM_EVT_REPLIES;
>   	mrioc->reply_free_qsz = mrioc->num_reply_bufs + 1;
> @@ -3021,6 +3055,8 @@ static void mpi3mr_memset_buffers(struct mpi3mr_ioc *mrioc)
>   	memset(mrioc->admin_reply_base, 0, mrioc->admin_reply_q_sz);
>   
>   	memset(mrioc->init_cmds.reply, 0, sizeof(*mrioc->init_cmds.reply));
> +	memset(mrioc->host_tm_cmds.reply, 0,
> +		    sizeof(*mrioc->host_tm_cmds.reply));
>   	for (i = 0; i < MPI3MR_NUM_DEVRMCMD; i++)
>   		memset(mrioc->dev_rmhs_cmds[i].reply, 0,
>   		    sizeof(*mrioc->dev_rmhs_cmds[i].reply));
> @@ -3114,6 +3150,19 @@ static void mpi3mr_free_mem(struct mpi3mr_ioc *mrioc)
>   	kfree(mrioc->init_cmds.reply);
>   	mrioc->init_cmds.reply = NULL;
>   
> +	kfree(mrioc->host_tm_cmds.reply);
> +	mrioc->host_tm_cmds.reply = NULL;
> +
> +	for (i = 0; i < MPI3MR_NUM_DEVRMCMD; i++) {
> +		kfree(mrioc->dev_rmhs_cmds[i].reply);
> +		mrioc->dev_rmhs_cmds[i].reply = NULL;
> +	}

And here.

> +	kfree(mrioc->removepend_bitmap);
> +	mrioc->removepend_bitmap = NULL;
> +
> +	kfree(mrioc->devrem_bitmap);
> +	mrioc->devrem_bitmap = NULL;
> +
>   	kfree(mrioc->chain_bitmap);
>   	mrioc->chain_bitmap = NULL;
>   
> @@ -3289,6 +3338,8 @@ static void mpi3mr_flush_drv_cmds(struct mpi3mr_ioc *mrioc)
>   
>   	cmdptr = &mrioc->init_cmds;
>   	mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
> +	cmdptr = &mrioc->host_tm_cmds;
> +	mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
>   
>   	for (i = 0; i < MPI3MR_NUM_DEVRMCMD; i++) {
>   		cmdptr = &mrioc->dev_rmhs_cmds[i];
> diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c
> index 7e0eacf45d84..80de597f8ccf 100644
> --- a/drivers/scsi/mpi3mr/mpi3mr_os.c
> +++ b/drivers/scsi/mpi3mr/mpi3mr_os.c
> @@ -2078,6 +2078,212 @@ static int mpi3mr_build_sg_scmd(struct mpi3mr_ioc *mrioc,
>   	return ret;
>   }
>   
> +/**
> + * mpi3mr_print_response_code - print TM response as a string
> + * @mrioc: Adapter instance reference
> + * @resp_code: TM response code
> + *
> + * Print TM response code as a readable string.
> + *
> + * Return: Nothing.
> + */
> +static void mpi3mr_print_response_code(struct mpi3mr_ioc *mrioc, u8 resp_code)
> +{
> +	char *desc;
> +
> +	switch (resp_code) {
> +	case MPI3MR_RSP_TM_COMPLETE:
> +		desc = "task management request completed";
> +		break;
> +	case MPI3MR_RSP_INVALID_FRAME:
> +		desc = "invalid frame";
> +		break;
> +	case MPI3MR_RSP_TM_NOT_SUPPORTED:
> +		desc = "task management request not supported";
> +		break;
> +	case MPI3MR_RSP_TM_FAILED:
> +		desc = "task management request failed";
> +		break;
> +	case MPI3MR_RSP_TM_SUCCEEDED:
> +		desc = "task management request succeeded";
> +		break;
> +	case MPI3MR_RSP_TM_INVALID_LUN:
> +		desc = "invalid lun";
> +		break;
> +	case MPI3MR_RSP_TM_OVERLAPPED_TAG:
> +		desc = "overlapped tag attempted";
> +		break;
> +	case MPI3MR_RSP_IO_QUEUED_ON_IOC:
> +		desc = "task queued, however not sent to target";
> +		break;
> +	default:
> +		desc = "unknown";
> +		break;
> +	}
> +	ioc_info(mrioc, "%s :response_code(0x%01x): %s\n", __func__,
> +	    resp_code, desc);
> +}
> +
> +/**
> + * mpi3mr_issue_tm - Issue Task Management request
> + * @mrioc: Adapter instance reference
> + * @tm_type: Task Management type
> + * @handle: Device handle
> + * @lun: LUN ID
> + * @htag: Host tag of the TM request
> + * @drv_cmd: Internal command tracker
> + * @resp_code: Response code place holder
> + * @cmd_priv: SCSI command private data
> + *
> + * Issues a Task Management Request to the controller for a
> + * specified target, LUN and command and wait for its completion
> + * and check TM response. Recover the TM if it timed out by
> + * issuing controller reset.
> + *
> + * Return: 0 on success, non-zero on errors
> + */
> +static int mpi3mr_issue_tm(struct mpi3mr_ioc *mrioc, u8 tm_type,
> +	u16 handle, uint lun, u16 htag, ulong timeout,
> +	struct mpi3mr_drv_cmd *drv_cmd,
> +	u8 *resp_code, struct scmd_priv *cmd_priv)
> +{
> +	Mpi3SCSITaskMgmtRequest_t tm_req;
> +	Mpi3SCSITaskMgmtReply_t *tm_reply = NULL;
> +	int retval = 0;
> +	struct mpi3mr_tgt_dev *tgtdev = NULL;
> +	struct mpi3mr_stgt_priv_data *scsi_tgt_priv_data = NULL;
> +	struct op_req_qinfo *op_req_q = NULL;
> +
> +	ioc_info(mrioc, "%s :Issue TM: TM Type (0x%x) for devhandle 0x%04x\n",
> +	    __func__, tm_type, handle);
> +	if (mrioc->unrecoverable) {
> +		retval = -1;
> +		ioc_err(mrioc, "%s :Issue TM: Unrecoverable controller\n",
> +		    __func__);
> +		goto out;
> +	}
> +
> +	memset(&tm_req, 0, sizeof(tm_req));
> +	mutex_lock(&drv_cmd->mutex);
> +	if (drv_cmd->state & MPI3MR_CMD_PENDING) {
> +		retval = -1;
> +		ioc_err(mrioc, "%s :Issue TM: Command is in use\n", __func__);
> +		mutex_unlock(&drv_cmd->mutex);
> +		goto out;
> +	}
> +	if (mrioc->reset_in_progress) {
> +		retval = -1;
> +		ioc_err(mrioc, "%s :Issue TM: Reset in progress\n", __func__);
> +		mutex_unlock(&drv_cmd->mutex);
> +		goto out;
> +	}
> +
> +	drv_cmd->state = MPI3MR_CMD_PENDING;
> +	drv_cmd->is_waiting = 1;
> +	drv_cmd->callback = NULL;
> +	tm_req.DevHandle = cpu_to_le16(handle);
> +	tm_req.TaskType = tm_type;
> +	tm_req.HostTag = cpu_to_le16(htag);
> +
> +	int_to_scsilun(lun, (struct scsi_lun *)tm_req.LUN);
> +	tm_req.Function = MPI3_FUNCTION_SCSI_TASK_MGMT;
> +
> +	tgtdev = mpi3mr_get_tgtdev_by_handle(mrioc, handle);
> +	if (tgtdev && tgtdev->starget && tgtdev->starget->hostdata) {
> +		scsi_tgt_priv_data = (struct mpi3mr_stgt_priv_data *)
> +		    tgtdev->starget->hostdata;
> +		atomic_inc(&scsi_tgt_priv_data->block_io);
> +	}
> +	if (cmd_priv) {
> +		op_req_q = &mrioc->req_qinfo[cmd_priv->req_q_idx];
> +		tm_req.TaskHostTag = cpu_to_le16(cmd_priv->host_tag);
> +		tm_req.TaskRequestQueueID = cpu_to_le16(op_req_q->qid);
> +	}
> +	if (tgtdev && (tgtdev->dev_type == MPI3_DEVICE_DEVFORM_PCIE)) {
> +		if (cmd_priv && tgtdev->dev_spec.pcie_inf.abort_to)
> +			timeout = tgtdev->dev_spec.pcie_inf.abort_to;
> +		else if (!cmd_priv && tgtdev->dev_spec.pcie_inf.reset_to)
> +			timeout = tgtdev->dev_spec.pcie_inf.reset_to;
> +	}
> +
> +	init_completion(&drv_cmd->done);
> +	retval = mpi3mr_admin_request_post(mrioc, &tm_req, sizeof(tm_req), 1);
> +	if (retval) {
> +		ioc_err(mrioc, "%s :Issue TM: Admin Post failed\n", __func__);
> +		goto out_unlock;
> +	}
> +	wait_for_completion_timeout(&drv_cmd->done, (timeout * HZ));
> +
> +	if (!(drv_cmd->state & MPI3MR_CMD_COMPLETE)) {
> +		ioc_err(mrioc, "%s :Issue TM: command timed out\n", __func__);
> +		drv_cmd->is_waiting = 0;
> +		retval = -1;
> +		mpi3mr_soft_reset_handler(mrioc,
> +		    MPI3MR_RESET_FROM_TM_TIMEOUT, 1);
> +		goto out_unlock;
> +	}
> +
> +	if (drv_cmd->state & MPI3MR_CMD_REPLY_VALID)
> +		tm_reply = (Mpi3SCSITaskMgmtReply_t *)drv_cmd->reply;
> +
> +	if (drv_cmd->ioc_status != MPI3_IOCSTATUS_SUCCESS) {
> +		ioc_err(mrioc,
> +		    "%s :Issue TM: handle(0x%04x) Failed IOCStatus(0x%04x) Loginfo(0x%08x)\n",
> +		    __func__, handle, drv_cmd->ioc_status,
> +		    drv_cmd->ioc_loginfo);
> +		retval = -1;
> +		goto out_unlock;
> +	}
> +
> +	if (!tm_reply) {
> +		ioc_err(mrioc, "%s :Issue TM: No TM Reply message\n", __func__);
> +		retval = -1;
> +		goto out_unlock;
> +	}
> +
> +	*resp_code = le32_to_cpu(tm_reply->ResponseData) &
> +	    MPI3MR_RI_MASK_RESPCODE;
> +	switch (*resp_code) {
> +	case MPI3MR_RSP_TM_SUCCEEDED:
> +	case MPI3MR_RSP_TM_COMPLETE:
> +		break;
> +	case MPI3MR_RSP_IO_QUEUED_ON_IOC:
> +		if (tm_type != MPI3_SCSITASKMGMT_TASKTYPE_QUERY_TASK)
> +			retval = -1;
> +		break;
> +	default:
> +		retval = -1;
> +		break;
> +	}
> +
> +	ioc_info(mrioc,
> +	    "%s :Issue TM: Completed TM Type (0x%x) handle(0x%04x) ",
> +	    __func__, tm_type, handle);
> +	ioc_info(mrioc,
> +	    "with ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
> +	    drv_cmd->ioc_status, drv_cmd->ioc_loginfo,
> +	    le32_to_cpu(tm_reply->TerminationCount));
> +	mpi3mr_print_response_code(mrioc, *resp_code);
> +
> +out_unlock:
> +	drv_cmd->state = MPI3MR_CMD_NOTUSED;
> +	mutex_unlock(&drv_cmd->mutex);
> +	if (scsi_tgt_priv_data)
> +		atomic_dec_if_positive(&scsi_tgt_priv_data->block_io);
> +	if (tgtdev)
> +		mpi3mr_tgtdev_put(tgtdev);
> +	if (!retval) {
> +		/*
> +		 * Flush all IRQ handlers by calling synchronize_irq().
> +		 * mpi3mr_ioc_disable_intr() takes care of it.
> +		 */
> +		mpi3mr_ioc_disable_intr(mrioc);
> +		mpi3mr_ioc_enable_intr(mrioc);
> +	}
> +out:
> +	return retval;
> +}
> +
>   /**
>    * mpi3mr_bios_param - BIOS param callback
>    * @sdev: SCSI device reference
> @@ -2135,6 +2341,221 @@ static int mpi3mr_map_queues(struct Scsi_Host *shost)
>   	    mrioc->pdev, mrioc->op_reply_q_offset);
>   }
>   
> +/**
> + * mpi3mr_eh_host_reset - Host reset error handling callback
> + * @scmd: SCSI command reference
> + *
> + * Issue controller reset if the scmd is for a Physical Device,
> + * if the scmd is for RAID volume, then wait for
> + * MPI3MR_RAID_ERRREC_RESET_TIMEOUT and checke whether any
> + * pending I/Os prior to issuing reset to the controller.
> + *
> + * Return: SUCCESS of successful reset else FAILED
> + */
> +static int mpi3mr_eh_host_reset(struct scsi_cmnd *scmd)
> +{
> +	struct mpi3mr_ioc *mrioc = shost_priv(scmd->device->host);
> +	struct mpi3mr_stgt_priv_data *stgt_priv_data;
> +	struct mpi3mr_sdev_priv_data *sdev_priv_data;
> +	u8 dev_type = MPI3_DEVICE_DEVFORM_VD;
> +	int retval = FAILED, ret;
> +
> +	sdev_priv_data = scmd->device->hostdata;
> +	if (sdev_priv_data && sdev_priv_data->tgt_priv_data) {
> +		stgt_priv_data = sdev_priv_data->tgt_priv_data;
> +		dev_type = stgt_priv_data->dev_type;
> +	}
> +
> +	ret = mpi3mr_soft_reset_handler(mrioc,
> +	    MPI3MR_RESET_FROM_EH_HOS, 1);
> +	if (ret)
> +		goto out;
> +
> +	retval = SUCCESS;
> +out:
> +	sdev_printk(KERN_INFO, scmd->device,
> +	    "Host reset is %s for scmd(%p)\n",
> +	    ((retval == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
> +
> +	return retval;
> +}
> +
> +/**
> + * mpi3mr_eh_target_reset - Target reset error handling callback
> + * @scmd: SCSI command reference
> + *
> + * Issue Target reset Task Management and verify the scmd is
> + * terminated successfully and return status accordingly.
> + *
> + * Return: SUCCESS of successful termination of the scmd else
> + *         FAILED
> + */
> +static int mpi3mr_eh_target_reset(struct scsi_cmnd *scmd)
> +{
> +	struct mpi3mr_ioc *mrioc = shost_priv(scmd->device->host);
> +	struct mpi3mr_stgt_priv_data *stgt_priv_data;
> +	struct mpi3mr_sdev_priv_data *sdev_priv_data;
> +	u16 dev_handle;
> +	u8 resp_code = 0;
> +	int retval = FAILED, ret = 0;
> +
> +
> +	sdev_printk(KERN_INFO, scmd->device,
> +	    "Attempting Target Reset! scmd(%p)\n", scmd);
> +	scsi_print_command(scmd);
> +
> +	sdev_priv_data = scmd->device->hostdata;
> +	if (!sdev_priv_data || !sdev_priv_data->tgt_priv_data) {
> +		sdev_printk(KERN_INFO, scmd->device,
> +		    "SCSI device is not available\n");
> +		retval = SUCCESS;
> +		goto out;
> +	}
> +
> +	stgt_priv_data = sdev_priv_data->tgt_priv_data;
> +	dev_handle = stgt_priv_data->dev_handle;
> +	sdev_printk(KERN_INFO, scmd->device,
> +	    "Target Reset is issued to handle(0x%04x)\n",
> +	    dev_handle);
> +
> +	ret = mpi3mr_issue_tm(mrioc,
> +	    MPI3_SCSITASKMGMT_TASKTYPE_TARGET_RESET, dev_handle,
> +	    sdev_priv_data->lun_id, MPI3MR_HOSTTAG_BLK_TMS,
> +	    MPI3MR_RESETTM_TIMEOUT, &mrioc->host_tm_cmds, &resp_code, NULL);
> +
> +	if (ret)
> +		goto out;
> +
> +	retval = SUCCESS;
> +out:
> +	sdev_printk(KERN_INFO, scmd->device,
> +	    "Target reset is %s for scmd(%p)\n",
> +	    ((retval == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
> +
> +	return retval;
> +}
> +
> +/**
> + * mpi3mr_eh_dev_reset- Device reset error handling callback
> + * @scmd: SCSI command reference
> + *
> + * Issue LUN reset Task Management and verify the scmd is
> + * terminated successfully and return status accordingly.
> + *
> + * Return: SUCCESS of successful termination of the scmd else
> + *         FAILED
> + */
> +static int mpi3mr_eh_dev_reset(struct scsi_cmnd *scmd)
> +{
> +	struct mpi3mr_ioc *mrioc = shost_priv(scmd->device->host);
> +	struct mpi3mr_stgt_priv_data *stgt_priv_data;
> +	struct mpi3mr_sdev_priv_data *sdev_priv_data;
> +	u16 dev_handle;
> +	u8 resp_code = 0;
> +	int retval = FAILED, ret = 0;
> +
> +	sdev_printk(KERN_INFO, scmd->device,
> +	    "Attempting Device(LUN) Reset! scmd(%p)\n", scmd);
> +	scsi_print_command(scmd);
> +
> +	sdev_priv_data = scmd->device->hostdata;
> +	if (!sdev_priv_data || !sdev_priv_data->tgt_priv_data) {
> +		sdev_printk(KERN_INFO, scmd->device,
> +		    "SCSI device is not available\n");
> +		retval = SUCCESS;
> +		goto out;
> +	}
> +
> +	stgt_priv_data = sdev_priv_data->tgt_priv_data;
> +	dev_handle = stgt_priv_data->dev_handle;
> +	sdev_printk(KERN_INFO, scmd->device,
> +	    "Device(LUN) Reset is issued to handle(0x%04x)\n", dev_handle);
> +
> +	ret = mpi3mr_issue_tm(mrioc,
> +	    MPI3_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, dev_handle,
> +	    sdev_priv_data->lun_id, MPI3MR_HOSTTAG_BLK_TMS,
> +	    MPI3MR_RESETTM_TIMEOUT, &mrioc->host_tm_cmds, &resp_code, NULL);
> +
> +	if (ret)
> +		goto out;
> +
> +	retval = SUCCESS;
> +out:
> +	sdev_printk(KERN_INFO, scmd->device,
> +	    "Device(LUN) reset is %s for scmd(%p)\n",
> +	    ((retval == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
> +
> +	return retval;
> +}
> +
> +/**
> + * mpi3mr_eh_abort- Abort error handling callback
> + * @scmd: SCSI command reference
> + *
> + * Issue Abort Task Management if the command is in LLD scope
> + * and verify if it is aborted successfully and return status
> + * accordingly.
> + *
> + * Return: SUCCESS of successful abort the scmd else FAILED
> + */
> +static int mpi3mr_eh_abort(struct scsi_cmnd *scmd)
> +{
> +	struct mpi3mr_ioc *mrioc = shost_priv(scmd->device->host);
> +	struct mpi3mr_stgt_priv_data *stgt_priv_data;
> +	struct mpi3mr_sdev_priv_data *sdev_priv_data;
> +	struct scmd_priv *cmd_priv;
> +	u16 dev_handle;
> +	u8 resp_code = 0;
> +	int retval = FAILED, ret = 0;
> +
> +	sdev_printk(KERN_INFO, scmd->device,
> +	    "Attempting Task Abort! scmd(%p)\n", scmd);
> +	scsi_print_command(scmd);
> +
> +	sdev_priv_data = scmd->device->hostdata;
> +	if (!sdev_priv_data || !sdev_priv_data->tgt_priv_data) {
> +		sdev_printk(KERN_INFO, scmd->device,
> +		    "SCSI device is not available\n");
> +		retval = SUCCESS;
> +		goto out;
> +	}
> +
> +	stgt_priv_data = sdev_priv_data->tgt_priv_data;
> +	dev_handle = stgt_priv_data->dev_handle;
> +	sdev_printk(KERN_INFO, scmd->device,
> +	    "Timedout scmd (%p) is issued to handle(0x%04x)\n", scmd,
> +	    dev_handle);
> +
> +	cmd_priv = scsi_cmd_priv(scmd);
> +	if (!cmd_priv->in_lld_scope ||
> +	    cmd_priv->host_tag == MPI3MR_HOSTTAG_INVALID) {
> +		sdev_printk(KERN_INFO, scmd->device,
> +		    "SCSI command not in LLD scope\n");
> +		retval = SUCCESS;
> +		goto out;
> +	}
> +
> +	ret = mpi3mr_issue_tm(mrioc, MPI3_SCSITASKMGMT_TASKTYPE_ABORT_TASK,
> +	    dev_handle, sdev_priv_data->lun_id, MPI3MR_HOSTTAG_BLK_TMS,
> +	    MPI3MR_ABORTTM_TIMEOUT, &mrioc->host_tm_cmds, &resp_code,
> +	    cmd_priv);
> +
> +	if (ret)
> +		goto out;
> +
> +	if (cmd_priv->in_lld_scope) {
> +		sdev_printk(KERN_INFO, scmd->device,
> +		    "SCSI command(%p) is still not aborted\n", scmd);
> +		goto out;
> +	}
> +	retval = SUCCESS;
> +out:
> +	sdev_printk(KERN_INFO, scmd->device, "Task Abort is %s for scmd(%p)\n",
> +	    ((retval == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
> +
> +	return retval;
> +}
> +
>   /**
>    * mpi3mr_scan_start - Scan start callback handler
>    * @shost: SCSI host reference

Hmm. This looks a bit unfortunate.
You are reserving just one tag for task management commands, which is 
okay for device and target reset (as there we're running in single-step 
mode and will only ever need one tag), but it's certainly not okay for 
task abort, which is issued in-line and as such can occur for _every_ 
command.

So I guess you'll need to rethink you tag allocation strategy here.

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                Kernel Storage Architect
hare@suse.de                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer

^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 14/24] mpi3mr: add change queue depth support
  2020-12-22 10:11 ` [PATCH 14/24] mpi3mr: add change queue depth support Kashyap Desai
@ 2021-03-01  7:10   ` Hannes Reinecke
  0 siblings, 0 replies; 75+ messages in thread
From: Hannes Reinecke @ 2021-03-01  7:10 UTC (permalink / raw)
  To: Kashyap Desai, linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, sathya.prakash

On 12/22/20 11:11 AM, Kashyap Desai wrote:
> Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
> Cc: sathya.prakash@broadcom.com
> ---
>   drivers/scsi/mpi3mr/mpi3mr.h    |  3 +++
>   drivers/scsi/mpi3mr/mpi3mr_os.c | 35 ++++++++++++++++++++++++++++++++-
>   2 files changed, 37 insertions(+), 1 deletion(-)
> 
Reviewed-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                Kernel Storage Architect
hare@suse.de                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer

^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 15/24] mpi3mr: allow certain commands during pci-remove hook
  2020-12-22 10:11 ` [PATCH 15/24] mpi3mr: allow certain commands during pci-remove hook Kashyap Desai
@ 2021-03-01  7:11   ` Hannes Reinecke
  0 siblings, 0 replies; 75+ messages in thread
From: Hannes Reinecke @ 2021-03-01  7:11 UTC (permalink / raw)
  To: Kashyap Desai, linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, sathya.prakash

On 12/22/20 11:11 AM, Kashyap Desai wrote:
> This patch allows SSU and Sync Cache commands to be sent to the controller
> instead of driver returning DID_NO_CONNECT during driver unload to flush
> any cached data from the drive.
> 
> Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
> Cc: sathya.prakash@broadcom.com
> ---
>   drivers/scsi/mpi3mr/mpi3mr_os.c | 24 +++++++++++++++++++++++-
>   1 file changed, 23 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c
> index 6f19e5392433..07a7b1efbc4f 100644
> --- a/drivers/scsi/mpi3mr/mpi3mr_os.c
> +++ b/drivers/scsi/mpi3mr/mpi3mr_os.c
> @@ -2865,6 +2865,27 @@ static int mpi3mr_target_alloc(struct scsi_target *starget)
>   	return retval;
>   }
>   
> +
> +/**
> + * mpi3mr_allow_scmd_to_fw - Command is allowed during shutdown
> + * @scmd: SCSI Command reference
> + *
> + * Checks whether a CDB is allowed during shutdown or not.
> + *
> + * Return: TRUE for allowed commands, FALSE otherwise.
> + */
> +
> +inline bool mpi3mr_allow_scmd_to_fw(struct scsi_cmnd *scmd)
> +{
> +	switch (scmd->cmnd[0]) {
> +	case SYNCHRONIZE_CACHE:
> +	case START_STOP:
> +		return true;
> +	default:
> +		return false;
> +	}
> +}
> +
>   /**
>    * mpi3mr_qcmd - I/O request despatcher
>    * @shost: SCSI Host reference
> @@ -2900,7 +2921,8 @@ static int mpi3mr_qcmd(struct Scsi_Host *shost,
>   		goto out;
>   	}
>   
> -	if (mrioc->stop_drv_processing) {
> +	if (mrioc->stop_drv_processing &&
> +	    !(mpi3mr_allow_scmd_to_fw(scmd))) {
>   		scmd->result = DID_NO_CONNECT << 16;
>   		scmd->scsi_done(scmd);
>   		goto out;
> 
Reviewed-by: Hannes Reinecke <hare@suse.com>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                Kernel Storage Architect
hare@suse.de                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer

^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 16/24] mpi3mr: hardware workaround for UNMAP commands to nvme drives
  2020-12-22 10:11 ` [PATCH 16/24] mpi3mr: hardware workaround for UNMAP commands to nvme drives Kashyap Desai
@ 2021-03-01  7:13   ` Hannes Reinecke
  0 siblings, 0 replies; 75+ messages in thread
From: Hannes Reinecke @ 2021-03-01  7:13 UTC (permalink / raw)
  To: Kashyap Desai, linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, sathya.prakash

On 12/22/20 11:11 AM, Kashyap Desai wrote:
> The controller hardware can not handle certain unmap commands for NVMe
> drives, this patch adds support in the driver to check those commands and
> handle as appropriate.
> 
> Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
> Cc: sathya.prakash@broadcom.com
> ---
>   drivers/scsi/mpi3mr/mpi3mr_os.c | 99 +++++++++++++++++++++++++++++++++
>   1 file changed, 99 insertions(+)
> 
> diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c
> index 07a7b1efbc4f..742cf45d4878 100644
> --- a/drivers/scsi/mpi3mr/mpi3mr_os.c
> +++ b/drivers/scsi/mpi3mr/mpi3mr_os.c
> @@ -2865,6 +2865,100 @@ static int mpi3mr_target_alloc(struct scsi_target *starget)
>   	return retval;
>   }
>   
> +/**
> + * mpi3mr_check_return_unmap - Whether an unmap is allowed
> + * @mrioc: Adapter instance reference
> + * @scmd: SCSI Command reference
> + *
> + * The controller hardware cannot handle certain unmap commands
> + * for NVMe drives, this routine checks those and return true
> + * and completes the SCSI command with proper status and sense
> + * data.
> + *
> + * Return: TRUE for not  allowed unmap, FALSE otherwise.
> + */
> +static bool mpi3mr_check_return_unmap(struct mpi3mr_ioc *mrioc,
> +	struct scsi_cmnd *scmd)
> +{
> +	unsigned char *buf;
> +	u16 param_len, desc_len;
> +
> +	param_len = get_unaligned_be16(scmd->cmnd + 7);
> +
> +	if (!param_len) {
> +		ioc_warn(mrioc,
> +		    "%s: CDB received with zero parameter length\n",
> +		    __func__);
> +		scsi_print_command(scmd);
> +		scmd->result = DID_OK << 16;
> +		scmd->scsi_done(scmd);
> +		return true;
> +	}
> +
> +	if (param_len < 24) {
> +		ioc_warn(mrioc,
> +		    "%s: CDB received with invalid param_len: %d\n",
> +		    __func__, param_len);
> +		scsi_print_command(scmd);
> +		scmd->result = (DRIVER_SENSE << 24) |
> +		    SAM_STAT_CHECK_CONDITION;
> +		scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST,
> +		    0x1A, 0);
> +		scmd->scsi_done(scmd);
> +		return true;
> +	}
> +	if (param_len != scsi_bufflen(scmd)) {
> +		ioc_warn(mrioc,
> +		    "%s: CDB received with param_len: %d bufflen: %d\n",
> +		    __func__, param_len, scsi_bufflen(scmd));
> +		scsi_print_command(scmd);
> +		scmd->result = (DRIVER_SENSE << 24) |
> +		    SAM_STAT_CHECK_CONDITION;
> +		scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST,
> +		    0x1A, 0);
> +		scmd->scsi_done(scmd);
> +		return true;
> +	}
> +	buf = kzalloc(scsi_bufflen(scmd), GFP_ATOMIC);
> +	if (!buf) {
> +		scsi_print_command(scmd);
> +		scmd->result = (DRIVER_SENSE << 24) |
> +		    SAM_STAT_CHECK_CONDITION;
> +		scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST,
> +		    0x55, 0x03);
> +		scmd->scsi_done(scmd);
> +		return true;
> +	}
> +	scsi_sg_copy_to_buffer(scmd, buf, scsi_bufflen(scmd));
> +	desc_len = get_unaligned_be16(&buf[2]);
> +
> +	if (desc_len < 16) {
> +		ioc_warn(mrioc,
> +		    "%s: Invalid descriptor length in param list: %d\n",
> +		    __func__, desc_len);
> +		scsi_print_command(scmd);
> +		scmd->result = (DRIVER_SENSE << 24) |
> +		    SAM_STAT_CHECK_CONDITION;
> +		scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST,
> +		    0x26, 0);
> +		scmd->scsi_done(scmd);
> +		kfree(buf);
> +		return true;
> +	}
> +
> +	if (param_len > (desc_len + 8)) {
> +		scsi_print_command(scmd);
> +		ioc_warn(mrioc,
> +		    "%s: Truncating param_len(%d) to desc_len+8(%d)\n",
> +		    __func__, param_len, (desc_len + 8));
> +		param_len = desc_len + 8;
> +		put_unaligned_be16(param_len, scmd->cmnd+7);
> +		scsi_print_command(scmd);
> +	}
> +
> +	kfree(buf);
> +	return false;
> +}
>   
>   /**
>    * mpi3mr_allow_scmd_to_fw - Command is allowed during shutdown
> @@ -2957,6 +3051,11 @@ static int mpi3mr_qcmd(struct Scsi_Host *shost,
>   		goto out;
>   	}
>   
> +	if ((scmd->cmnd[0] == UNMAP) &&
> +	    (stgt_priv_data->dev_type == MPI3_DEVICE_DEVFORM_PCIE) &&
> +	    mpi3mr_check_return_unmap(mrioc, scmd))
> +		goto out;
> +
>   	host_tag = mpi3mr_host_tag_for_scmd(mrioc, scmd);
>   	if (host_tag == MPI3MR_HOSTTAG_INVALID) {
>   		scmd->result = DID_ERROR << 16;
> 
One _could_ have modified the firmware instead ... oh well.

Reviewed-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                Kernel Storage Architect
hare@suse.de                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer

^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 17/24] mpi3mr: add support of threaded isr
  2020-12-22 10:11 ` [PATCH 17/24] mpi3mr: add support of threaded isr Kashyap Desai
  2020-12-27 13:51     ` kernel test robot
@ 2021-03-01  7:14   ` Hannes Reinecke
  1 sibling, 0 replies; 75+ messages in thread
From: Hannes Reinecke @ 2021-03-01  7:14 UTC (permalink / raw)
  To: Kashyap Desai, linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, sathya.prakash

On 12/22/20 11:11 AM, Kashyap Desai wrote:
> Register driver for threaded interrupt.
> 
> By default, driver will attempt io completion from interrupt context
> (primary handler). Since driver tracks per reply queue outstanding ios,
> it will schedule threaded ISR if there are any outstanding IOs expected
> on that particular reply queue. Threaded ISR (secondary handler) will loop
> for IO completion as long as there are outstanding IOs
> (speculative method using same per reply queue outstanding counter)
> or it has completed some X amount of commands (something like budget).
> 
> Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
> Cc: sathya.prakash@broadcom.com
> ---
>   drivers/scsi/mpi3mr/mpi3mr.h    | 12 ++++++
>   drivers/scsi/mpi3mr/mpi3mr_fw.c | 75 +++++++++++++++++++++++++++++++--
>   2 files changed, 84 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/scsi/mpi3mr/mpi3mr.h b/drivers/scsi/mpi3mr/mpi3mr.h
> index 74b6b4b6e322..41a8689b46c9 100644
> --- a/drivers/scsi/mpi3mr/mpi3mr.h
> +++ b/drivers/scsi/mpi3mr/mpi3mr.h
> @@ -144,6 +144,10 @@ extern struct list_head mrioc_list;
>   /* Default target device queue depth */
>   #define MPI3MR_DEFAULT_SDEV_QD	32
>   
> +/* Definitions for Threaded IRQ poll*/
> +#define MPI3MR_IRQ_POLL_SLEEP			2
> +#define MPI3MR_IRQ_POLL_TRIGGER_IOCOUNT		8
> +
>   /* SGE Flag definition */
>   #define MPI3MR_SGEFLAGS_SYSTEM_SIMPLE_END_OF_LIST \
>   	(MPI3_SGE_FLAGS_ELEMENT_TYPE_SIMPLE | MPI3_SGE_FLAGS_DLAS_SYSTEM | \
> @@ -295,6 +299,9 @@ struct op_req_qinfo {
>    * @q_segment_list: Segment list base virtual address
>    * @q_segment_list_dma: Segment list base DMA address
>    * @ephase: Expected phased identifier for the reply queue
> + * @pend_ios: Number of IOs pending in HW for this queue
> + * @enable_irq_poll: Flag to indicate polling is enabled
> + * @in_use: Queue is handled by poll/ISR
>    */
>   struct op_reply_qinfo {
>   	u16 ci;
> @@ -306,6 +313,9 @@ struct op_reply_qinfo {
>   	void *q_segment_list;
>   	dma_addr_t q_segment_list_dma;
>   	u8 ephase;
> +	atomic_t pend_ios;
> +	bool enable_irq_poll;
> +	atomic_t in_use;
>   };
>   
>   /**
> @@ -559,6 +569,7 @@ struct scmd_priv {
>    * @shost: Scsi_Host pointer
>    * @id: Controller ID
>    * @cpu_count: Number of online CPUs
> + * @irqpoll_sleep: usleep unit used in threaded isr irqpoll
>    * @name: Controller ASCII name
>    * @driver_name: Driver ASCII name
>    * @sysif_regs: System interface registers virtual address
> @@ -660,6 +671,7 @@ struct mpi3mr_ioc {
>   	u8 id;
>   	int cpu_count;
>   	bool enable_segqueue;
> +	u32 irqpoll_sleep;
>   
>   	char name[MPI3MR_NAME_LENGTH];
>   	char driver_name[MPI3MR_NAME_LENGTH];
> diff --git a/drivers/scsi/mpi3mr/mpi3mr_fw.c b/drivers/scsi/mpi3mr/mpi3mr_fw.c
> index ba4bfcc17809..4c4e21fb4ef3 100644
> --- a/drivers/scsi/mpi3mr/mpi3mr_fw.c
> +++ b/drivers/scsi/mpi3mr/mpi3mr_fw.c
> @@ -346,12 +346,16 @@ static int mpi3mr_process_op_reply_q(struct mpi3mr_ioc *mrioc,
>   
>   	reply_qidx = op_reply_q->qid - 1;
>   
> +	if (!atomic_add_unless(&op_reply_q->in_use, 1, 1))
> +		return 0;
> +
>   	exp_phase = op_reply_q->ephase;
>   	reply_ci = op_reply_q->ci;
>   
>   	reply_desc = mpi3mr_get_reply_desc(op_reply_q, reply_ci);
>   	if ((le16_to_cpu(reply_desc->ReplyFlags) &
>   	    MPI3_REPLY_DESCRIPT_FLAGS_PHASE_MASK) != exp_phase) {
> +		atomic_dec(&op_reply_q->in_use);
>   		return 0;
>   	}
>   
> @@ -364,6 +368,7 @@ static int mpi3mr_process_op_reply_q(struct mpi3mr_ioc *mrioc,
>   
>   		mpi3mr_process_op_reply_desc(mrioc, reply_desc, &reply_dma,
>   		    reply_qidx);
> +		atomic_dec(&op_reply_q->pend_ios);
>   		if (reply_dma)
>   			mpi3mr_repost_reply_buf(mrioc, reply_dma);
>   		num_op_reply++;
> @@ -378,6 +383,14 @@ static int mpi3mr_process_op_reply_q(struct mpi3mr_ioc *mrioc,
>   		if ((le16_to_cpu(reply_desc->ReplyFlags) &
>   		    MPI3_REPLY_DESCRIPT_FLAGS_PHASE_MASK) != exp_phase)
>   			break;
> +		/*
> +		 * Exit completion loop to avoid CPU lockup
> +		 * Ensure remaining completion happens from threaded ISR.
> +		 */
> +		if (num_op_reply > mrioc->max_host_ios) {
> +			intr_info->op_reply_q->enable_irq_poll = true;
> +			break;
> +		}
>   
>   	} while (1);
>   
> @@ -386,6 +399,7 @@ static int mpi3mr_process_op_reply_q(struct mpi3mr_ioc *mrioc,
>   	    &mrioc->sysif_regs->OperQueueIndexes[reply_qidx].ConsumerIndex);
>   	op_reply_q->ci = reply_ci;
>   	op_reply_q->ephase = exp_phase;
> +	atomic_dec(&op_reply_q->in_use);
>   
>   	return num_op_reply;
>   }
> @@ -395,7 +409,7 @@ static irqreturn_t mpi3mr_isr_primary(int irq, void *privdata)
>   	struct mpi3mr_intr_info *intr_info = privdata;
>   	struct mpi3mr_ioc *mrioc;
>   	u16 midx;
> -	u32 num_admin_replies = 0;
> +	u32 num_admin_replies = 0, num_op_reply = 0;
>   
>   	if (!intr_info)
>   		return IRQ_NONE;
> @@ -409,8 +423,10 @@ static irqreturn_t mpi3mr_isr_primary(int irq, void *privdata)
>   
>   	if (!midx)
>   		num_admin_replies = mpi3mr_process_admin_reply_q(mrioc);
> +	if (intr_info->op_reply_q)
> +		num_op_reply = mpi3mr_process_op_reply_q(mrioc, intr_info);
>   
> -	if (num_admin_replies)
> +	if (num_admin_replies || num_op_reply)
>   		return IRQ_HANDLED;
>   	else
>   		return IRQ_NONE;
> @@ -431,7 +447,20 @@ static irqreturn_t mpi3mr_isr(int irq, void *privdata)
>   	/* Call primary ISR routine */
>   	ret = mpi3mr_isr_primary(irq, privdata);
>   
> -	return ret;
> +	/*
> +	 * If more IOs are expected, schedule IRQ polling thread.
> +	 * Otherwise exit from ISR.
> +	 */
> +	if (!intr_info->op_reply_q)
> +		return ret;
> +
> +	if (!intr_info->op_reply_q->enable_irq_poll ||
> +	    !atomic_read(&intr_info->op_reply_q->pend_ios))
> +		return ret;
> +
> +	disable_irq_nosync(pci_irq_vector(mrioc->pdev, midx));
> +
> +	return IRQ_WAKE_THREAD;
>   }
>   
>   /**
> @@ -446,6 +475,36 @@ static irqreturn_t mpi3mr_isr(int irq, void *privdata)
>    */
>   static irqreturn_t mpi3mr_isr_poll(int irq, void *privdata)
>   {
> +	struct mpi3mr_intr_info *intr_info = privdata;
> +	struct mpi3mr_ioc *mrioc;
> +	u16 midx;
> +	u32 num_admin_replies = 0, num_op_reply = 0;
> +
> +	if (!intr_info || !intr_info->op_reply_q)
> +		return IRQ_NONE;
> +
> +	mrioc = intr_info->mrioc;
> +	midx = intr_info->msix_index;
> +
> +	/* Poll for pending IOs completions */
> +	do {
> +		if (!mrioc->intr_enabled)
> +			break;
> +
> +		if (!midx)
> +			num_admin_replies = mpi3mr_process_admin_reply_q(mrioc);
> +		if (intr_info->op_reply_q)
> +			num_op_reply +=
> +			    mpi3mr_process_op_reply_q(mrioc, intr_info);
> +
> +		usleep_range(mrioc->irqpoll_sleep, 10 * mrioc->irqpoll_sleep);
> +
> +	} while (atomic_read(&intr_info->op_reply_q->pend_ios) &&
> +	    (num_op_reply < mrioc->max_host_ios));
> +
> +	intr_info->op_reply_q->enable_irq_poll = false;
> +	enable_irq(pci_irq_vector(mrioc->pdev, midx));
> +
>   	return IRQ_HANDLED;
>   }
>   
> @@ -1161,6 +1220,9 @@ static int mpi3mr_create_op_reply_q(struct mpi3mr_ioc *mrioc, u16 qidx)
>   	op_reply_q->num_replies = MPI3MR_OP_REP_Q_QD;
>   	op_reply_q->ci = 0;
>   	op_reply_q->ephase = 1;
> +	atomic_set(&op_reply_q->pend_ios, 0);
> +	atomic_set(&op_reply_q->in_use, 0);
> +	op_reply_q->enable_irq_poll = false;
>   
>   	if (!op_reply_q->q_segments) {
>   		retval = mpi3mr_alloc_op_reply_q_segments(mrioc, qidx);
> @@ -1482,6 +1544,10 @@ int mpi3mr_op_request_post(struct mpi3mr_ioc *mrioc,
>   		pi = 0;
>   	op_req_q->pi = pi;
>   
> +	if (atomic_inc_return(&mrioc->op_reply_qinfo[reply_qidx].pend_ios)
> +	    > MPI3MR_IRQ_POLL_TRIGGER_IOCOUNT)
> +		mrioc->op_reply_qinfo[reply_qidx].enable_irq_poll = true;
> +
>   	writel(op_req_q->pi,
>   	    &mrioc->sysif_regs->OperQueueIndexes[reply_qidx].ProducerIndex);
>   
> @@ -2783,6 +2849,7 @@ int mpi3mr_init_ioc(struct mpi3mr_ioc *mrioc, u8 re_init)
>   	u32 ioc_status, ioc_config, i;
>   	Mpi3IOCFactsData_t facts_data;
>   
> +	mrioc->irqpoll_sleep = MPI3MR_IRQ_POLL_SLEEP;
>   	mrioc->change_count = 0;
>   	if (!re_init) {
>   		mrioc->cpu_count = num_online_cpus();
> @@ -3068,6 +3135,8 @@ static void mpi3mr_memset_buffers(struct mpi3mr_ioc *mrioc)
>   		mrioc->op_reply_qinfo[i].ci = 0;
>   		mrioc->op_reply_qinfo[i].num_replies = 0;
>   		mrioc->op_reply_qinfo[i].ephase = 0;
> +		atomic_set(&mrioc->op_reply_qinfo[i].pend_ios, 0);
> +		atomic_set(&mrioc->op_reply_qinfo[i].in_use, 0);
>   		mpi3mr_memset_op_reply_q_buffers(mrioc, i);
>   
>   		mrioc->req_qinfo[i].ci = 0;
> 
Reviewed-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                Kernel Storage Architect
hare@suse.de                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer

^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 18/24] mpi3mr: add complete support of soft reset
  2020-12-22 10:11 ` [PATCH 18/24] mpi3mr: add complete support of soft reset Kashyap Desai
@ 2021-03-01  7:16   ` Hannes Reinecke
  0 siblings, 0 replies; 75+ messages in thread
From: Hannes Reinecke @ 2021-03-01  7:16 UTC (permalink / raw)
  To: Kashyap Desai, linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, sathya.prakash

On 12/22/20 11:11 AM, Kashyap Desai wrote:
> Unlock the host diagnostic registers and write the specific
> reset type to that, wait for reset acknowledgment from the
> controller, if the reset is not successful retry for the
> predefined number of times
> 
> Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
> Cc: sathya.prakash@broadcom.com
> ---
>   drivers/scsi/mpi3mr/mpi3mr.h    |   3 +
>   drivers/scsi/mpi3mr/mpi3mr_fw.c | 245 +++++++++++++++++++++++++++++++-
>   2 files changed, 246 insertions(+), 2 deletions(-)
> 
Reviewed-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                Kernel Storage Architect
hare@suse.de                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer

^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 19/24] mpi3mr: print pending host ios for debug
  2020-12-22 10:11 ` [PATCH 19/24] mpi3mr: print pending host ios for debug Kashyap Desai
@ 2021-03-01  7:16   ` Hannes Reinecke
  0 siblings, 0 replies; 75+ messages in thread
From: Hannes Reinecke @ 2021-03-01  7:16 UTC (permalink / raw)
  To: Kashyap Desai, linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, sathya.prakash

On 12/22/20 11:11 AM, Kashyap Desai wrote:
> Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
> Cc: sathya.prakash@broadcom.com
> ---
>   drivers/scsi/mpi3mr/mpi3mr_os.c | 68 +++++++++++++++++++++++++++++++++
>   1 file changed, 68 insertions(+)
> 
> diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c
> index 742cf45d4878..8e665c70604d 100644
> --- a/drivers/scsi/mpi3mr/mpi3mr_os.c
> +++ b/drivers/scsi/mpi3mr/mpi3mr_os.c
> @@ -334,6 +334,36 @@ void mpi3mr_invalidate_devhandles(struct mpi3mr_ioc *mrioc)
>   	}
>   }
>   
> +/**
> + * mpi3mr_print_scmd - print individual SCSI command
> + * @rq: Block request
> + * @data: Adapter instance reference
> + *
> + * Print the SCSI command details if it is in LLD scope.
> + *
> + * Return: true always.
> + */
> +static bool mpi3mr_print_scmd(struct request *rq,
> +	void *data, bool reserved)
> +{
> +	struct mpi3mr_ioc *mrioc = (struct mpi3mr_ioc *)data;
> +	struct scsi_cmnd *scmd = blk_mq_rq_to_pdu(rq);
> +	struct scmd_priv *priv = NULL;
> +
> +	if (scmd) {
> +		priv = scsi_cmd_priv(scmd);
> +		if (!priv->in_lld_scope)
> +			goto out;
> +
> +		ioc_info(mrioc, "%s :Host Tag = %d, qid = %d\n",
> +		    __func__, priv->host_tag, priv->req_q_idx + 1);
> +		scsi_print_command(scmd);
> +	}
> +
> +out:
> +	return(true);
> +}
> +
>   
>   /**
>    * mpi3mr_flush_scmd - Flush individual SCSI command
> @@ -2370,6 +2400,43 @@ static int mpi3mr_map_queues(struct Scsi_Host *shost)
>   	    mrioc->pdev, mrioc->op_reply_q_offset);
>   }
>   
> +/**
> + * mpi3mr_get_fw_pending_ios - Calculate pending I/O count
> + * @mrioc: Adapter instance reference
> + *
> + * Calculate the pending I/Os for the controller and return.
> + *
> + * Return: Number of pending I/Os
> + */
> +static inline int mpi3mr_get_fw_pending_ios(struct mpi3mr_ioc *mrioc)
> +{
> +	u16 i;
> +	uint pend_ios = 0;
> +
> +	for (i = 0; i < mrioc->num_op_reply_q; i++)
> +		pend_ios += atomic_read(&mrioc->op_reply_qinfo[i].pend_ios);
> +	return pend_ios;
> +}
> +
> +/**
> + * mpi3mr_print_pending_host_io - print pending I/Os
> + * @mrioc: Adapter instance reference
> + *
> + * Print number of pending I/Os and each I/O details prior to
> + * reset for debug purpose.
> + *
> + * Return: Nothing
> + */
> +static void mpi3mr_print_pending_host_io(struct mpi3mr_ioc *mrioc)
> +{
> +	struct Scsi_Host *shost = mrioc->shost;
> +
> +	ioc_info(mrioc, "%s :Pending commands prior to reset: %d\n",
> +	    __func__, mpi3mr_get_fw_pending_ios(mrioc));
> +	blk_mq_tagset_busy_iter(&shost->tag_set,
> +	    mpi3mr_print_scmd, (void *)mrioc);
> +}
> +
>   /**
>    * mpi3mr_eh_host_reset - Host reset error handling callback
>    * @scmd: SCSI command reference
> @@ -2395,6 +2462,7 @@ static int mpi3mr_eh_host_reset(struct scsi_cmnd *scmd)
>   		dev_type = stgt_priv_data->dev_type;
>   	}
>   
> +	mpi3mr_print_pending_host_io(mrioc);
>   	ret = mpi3mr_soft_reset_handler(mrioc,
>   	    MPI3MR_RESET_FROM_EH_HOS, 1);
>   	if (ret)
> 
Reviewed-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                Kernel Storage Architect
hare@suse.de                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer

^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 20/24] mpi3mr: wait for pending IO completions upon detection of VD IO timeout
  2020-12-22 10:11 ` [PATCH 20/24] mpi3mr: wait for pending IO completions upon detection of VD IO timeout Kashyap Desai
@ 2021-03-01  7:17   ` Hannes Reinecke
  0 siblings, 0 replies; 75+ messages in thread
From: Hannes Reinecke @ 2021-03-01  7:17 UTC (permalink / raw)
  To: Kashyap Desai, linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, sathya.prakash

On 12/22/20 11:11 AM, Kashyap Desai wrote:
> Wait for (default 180 seconds) host IO completion if IO timeout is detected
> on VDs
> 
> Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
> Cc: sathya.prakash@broadcom.com
> ---
>   drivers/scsi/mpi3mr/mpi3mr.h    |  1 +
>   drivers/scsi/mpi3mr/mpi3mr_fw.c |  2 ++
>   drivers/scsi/mpi3mr/mpi3mr_os.c | 45 +++++++++++++++++++++++++++++++++
>   3 files changed, 48 insertions(+)
> 
> diff --git a/drivers/scsi/mpi3mr/mpi3mr.h b/drivers/scsi/mpi3mr/mpi3mr.h
> index 1d51e42778f6..5554b0e49a58 100644
> --- a/drivers/scsi/mpi3mr/mpi3mr.h
> +++ b/drivers/scsi/mpi3mr/mpi3mr.h
> @@ -102,6 +102,7 @@ extern struct list_head mrioc_list;
>   #define MPI3MR_RESET_HOST_IOWAIT_TIMEOUT	5
>   #define MPI3MR_TSUPDATE_INTERVAL		900
>   #define MPI3MR_DEFAULT_SHUTDOWN_TIME		120
> +#define	MPI3MR_RAID_ERRREC_RESET_TIMEOUT	180
>   
>   #define MPI3MR_WATCHDOG_INTERVAL		1000 /* in milli seconds */
>   
> diff --git a/drivers/scsi/mpi3mr/mpi3mr_fw.c b/drivers/scsi/mpi3mr/mpi3mr_fw.c
> index 36a68c488019..b27e44f78544 100644
> --- a/drivers/scsi/mpi3mr/mpi3mr_fw.c
> +++ b/drivers/scsi/mpi3mr/mpi3mr_fw.c
> @@ -3749,6 +3749,8 @@ int mpi3mr_soft_reset_handler(struct mpi3mr_ioc *mrioc,
>   		}
>   	}
>   
> +	mpi3mr_wait_for_host_io(mrioc, MPI3MR_RESET_HOST_IOWAIT_TIMEOUT);
> +
>   	mpi3mr_ioc_disable_intr(mrioc);
>   
>   	if (snapdump) {
> diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c
> index 8e665c70604d..1708aca1a5cd 100644
> --- a/drivers/scsi/mpi3mr/mpi3mr_os.c
> +++ b/drivers/scsi/mpi3mr/mpi3mr_os.c
> @@ -2437,6 +2437,43 @@ static void mpi3mr_print_pending_host_io(struct mpi3mr_ioc *mrioc)
>   	    mpi3mr_print_scmd, (void *)mrioc);
>   }
>   
> +/**
> + * mpi3mr_wait_for_host_io - block for I/Os to complete
> + * @mrioc: Adapter instance reference
> + * @timeout: time out in seconds
> + * Waits for pending I/Os for the given adapter to complete or
> + * to hit the timeout.
> + *
> + * Return: Nothing
> + */
> +void mpi3mr_wait_for_host_io(struct mpi3mr_ioc *mrioc, u32 timeout)
> +{
> +	enum mpi3mr_iocstate iocstate;
> +	int i = 0;
> +
> +	iocstate = mpi3mr_get_iocstate(mrioc);
> +	if (iocstate != MRIOC_STATE_READY)
> +		return;
> +
> +	if (!mpi3mr_get_fw_pending_ios(mrioc))
> +		return;
> +	ioc_info(mrioc,
> +	    "%s :Waiting for %d seconds prior to reset for %d I/O\n",
> +	    __func__, timeout, mpi3mr_get_fw_pending_ios(mrioc));
> +
> +	for (i = 0; i < timeout; i++) {
> +		if (!mpi3mr_get_fw_pending_ios(mrioc))
> +			break;
> +		iocstate = mpi3mr_get_iocstate(mrioc);
> +		if (iocstate != MRIOC_STATE_READY)
> +			break;
> +		msleep(1000);
> +	}
> +
> +	ioc_info(mrioc, "%s :Pending I/Os after wait is: %d\n", __func__,
> +	    mpi3mr_get_fw_pending_ios(mrioc));
> +}
> +
>   /**
>    * mpi3mr_eh_host_reset - Host reset error handling callback
>    * @scmd: SCSI command reference
> @@ -2462,6 +2499,14 @@ static int mpi3mr_eh_host_reset(struct scsi_cmnd *scmd)
>   		dev_type = stgt_priv_data->dev_type;
>   	}
>   
> +	if (dev_type == MPI3_DEVICE_DEVFORM_VD) {
> +		mpi3mr_wait_for_host_io(mrioc,
> +		    MPI3MR_RAID_ERRREC_RESET_TIMEOUT);
> +		if (!mpi3mr_get_fw_pending_ios(mrioc)) {
> +			retval = SUCCESS;
> +			goto out;
> +		}
> +	}
>   	mpi3mr_print_pending_host_io(mrioc);
>   	ret = mpi3mr_soft_reset_handler(mrioc,
>   	    MPI3MR_RESET_FROM_EH_HOS, 1);
> 
Reviewed-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                Kernel Storage Architect
hare@suse.de                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer

^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 21/24] mpi3mr: add support of PM suspend and resume
  2020-12-22 10:11 ` [PATCH 21/24] mpi3mr: add support of PM suspend and resume Kashyap Desai
  2021-02-22 15:32   ` Tomas Henzl
@ 2021-03-01  7:18   ` Hannes Reinecke
  1 sibling, 0 replies; 75+ messages in thread
From: Hannes Reinecke @ 2021-03-01  7:18 UTC (permalink / raw)
  To: Kashyap Desai, linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, sathya.prakash

On 12/22/20 11:11 AM, Kashyap Desai wrote:
> Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
> Cc: sathya.prakash@broadcom.com
> ---
>   drivers/scsi/mpi3mr/mpi3mr_os.c | 85 +++++++++++++++++++++++++++++++++
>   1 file changed, 85 insertions(+)
> 
> diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c
> index 1708aca1a5cd..ac47eed74705 100644
> --- a/drivers/scsi/mpi3mr/mpi3mr_os.c
> +++ b/drivers/scsi/mpi3mr/mpi3mr_os.c
> @@ -3480,6 +3480,87 @@ static void mpi3mr_shutdown(struct pci_dev *pdev)
>   
>   }
>   
> +#ifdef CONFIG_PM
> +/**
> + * mpi3mr_suspend - PCI power management suspend callback
> + * @pdev: PCI device instance
> + * @state: New power state
> + *
> + * Change the power state to the given value and cleanup the IOC
> + * by issuing MUR and shutdown notification
> + *
> + * Return: 0 always.
> + */
> +static int mpi3mr_suspend(struct pci_dev *pdev, pm_message_t state)
> +{
> +	struct Scsi_Host *shost = pci_get_drvdata(pdev);
> +	struct mpi3mr_ioc *mrioc;
> +	pci_power_t device_state;
> +
> +	if (!shost)
> +		return 0;
> +
> +	mrioc = shost_priv(shost);
> +	while (mrioc->reset_in_progress || mrioc->is_driver_loading)
> +		ssleep(1);
> +	mrioc->stop_drv_processing = 1;
> +	mpi3mr_cleanup_fwevt_list(mrioc);
> +	scsi_block_requests(shost);
> +	mpi3mr_stop_watchdog(mrioc);
> +	mpi3mr_cleanup_ioc(mrioc, 1);
> +
> +	device_state = pci_choose_state(pdev, state);
> +	ioc_info(mrioc, "pdev=0x%p, slot=%s, entering operating state [D%d]\n",
> +	    pdev, pci_name(pdev), device_state);
> +	pci_save_state(pdev);
> +	pci_set_power_state(pdev, device_state);
> +	mpi3mr_cleanup_resources(mrioc);
> +
> +	return 0;
> +}
> +
> +/**
> + * mpi3mr_resume - PCI power management resume callback
> + * @pdev: PCI device instance
> + *
> + * Restore the power state to D0 and reinitialize the controller
> + * and resume I/O operations to the target devices
> + *
> + * Return: 0 on success, non-zero on failure
> + */
> +static int mpi3mr_resume(struct pci_dev *pdev)
> +{
> +	struct Scsi_Host *shost = pci_get_drvdata(pdev);
> +	struct mpi3mr_ioc *mrioc;
> +	pci_power_t device_state = pdev->current_state;
> +	int r;
> +
> +	mrioc = shost_priv(shost);
> +
> +	ioc_info(mrioc, "pdev=0x%p, slot=%s, previous operating state [D%d]\n",
> +	    pdev, pci_name(pdev), device_state);
> +	pci_set_power_state(pdev, PCI_D0);
> +	pci_enable_wake(pdev, PCI_D0, 0);
> +	pci_restore_state(pdev);
> +	mrioc->pdev = pdev;
> +	mrioc->cpu_count = num_online_cpus();
> +	r = mpi3mr_setup_resources(mrioc);
> +	if (r) {
> +		ioc_info(mrioc, "%s: Setup resoruces failed[%d]\n",
> +		    __func__, r);
> +		return r;
> +	}
> +
> +	mrioc->stop_drv_processing = 0;
> +	mpi3mr_init_ioc(mrioc, 1);
> +	scsi_unblock_requests(shost);
> +	mpi3mr_start_watchdog(mrioc);
> +
> +	return 0;
> +}
> +#endif
> +
> +
>   static const struct pci_device_id mpi3mr_pci_id_table[] = {
>   	{
>   		PCI_DEVICE_SUB(PCI_VENDOR_ID_LSI_LOGIC, 0x00A5,
> @@ -3495,6 +3576,10 @@ static struct pci_driver mpi3mr_pci_driver = {
>   	.probe = mpi3mr_probe,
>   	.remove = mpi3mr_remove,
>   	.shutdown = mpi3mr_shutdown,
> +#ifdef CONFIG_PM
> +	.suspend = mpi3mr_suspend,
> +	.resume = mpi3mr_resume,
> +#endif
>   };
>   
>   static int __init mpi3mr_init(void)
> 
Reviewed-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                Kernel Storage Architect
hare@suse.de                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer

^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 22/24] mpi3mr: add support of DSN secure fw check
  2020-12-22 10:11 ` [PATCH 22/24] mpi3mr: add support of DSN secure fw check Kashyap Desai
@ 2021-03-01  7:19   ` Hannes Reinecke
  0 siblings, 0 replies; 75+ messages in thread
From: Hannes Reinecke @ 2021-03-01  7:19 UTC (permalink / raw)
  To: Kashyap Desai, linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, sathya.prakash

On 12/22/20 11:11 AM, Kashyap Desai wrote:
> Read PCI_EXT_CAP_ID_DSN to know security status.
> 
> Driver will throw an warning message when a non-secure type controller
> is detected. Purpose of this interface is to avoid interacting with
> any firmware which is not secured/signed by Broadcom.
> Any tampering on Firmware component will be detected by hardware
> and it will be communicated to the driver to avoid any further
> interaction with that component.
> 
> Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
> Cc: sathya.prakash@broadcom.com
> ---
>   drivers/scsi/mpi3mr/mpi3mr.h    |  9 ++++
>   drivers/scsi/mpi3mr/mpi3mr_os.c | 80 +++++++++++++++++++++++++++++++++
>   2 files changed, 89 insertions(+)
> 
Reviewed-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                Kernel Storage Architect
hare@suse.de                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer

^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 23/24] mpi3mr: add eedp dif dix support
  2020-12-22 10:11 ` [PATCH 23/24] mpi3mr: add eedp dif dix support Kashyap Desai
  2021-02-22 15:37   ` Tomas Henzl
@ 2021-03-01  7:20   ` Hannes Reinecke
  1 sibling, 0 replies; 75+ messages in thread
From: Hannes Reinecke @ 2021-03-01  7:20 UTC (permalink / raw)
  To: Kashyap Desai, linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, sathya.prakash

On 12/22/20 11:11 AM, Kashyap Desai wrote:
> Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
> Cc: sathya.prakash@broadcom.com
> ---
>   drivers/scsi/mpi3mr/mpi3mr.h    |  18 +-
>   drivers/scsi/mpi3mr/mpi3mr_fw.c |   7 +
>   drivers/scsi/mpi3mr/mpi3mr_os.c | 303 +++++++++++++++++++++++++++++++-
>   3 files changed, 321 insertions(+), 7 deletions(-)
> 
Reviewed-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                Kernel Storage Architect
hare@suse.de                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer

^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 24/24] mpi3mr: add event handling debug prints
  2020-12-22 10:11 ` [PATCH 24/24] mpi3mr: add event handling debug prints Kashyap Desai
@ 2021-03-01  7:20   ` Hannes Reinecke
  0 siblings, 0 replies; 75+ messages in thread
From: Hannes Reinecke @ 2021-03-01  7:20 UTC (permalink / raw)
  To: Kashyap Desai, linux-scsi
  Cc: jejb, martin.petersen, steve.hagan, peter.rivera,
	mpi3mr-linuxdrv.pdl, sathya.prakash

On 12/22/20 11:11 AM, Kashyap Desai wrote:
> Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
> Cc: sathya.prakash@broadcom.com
> ---
>   drivers/scsi/mpi3mr/mpi3mr_fw.c | 119 +++++++++++++++++++++++
>   drivers/scsi/mpi3mr/mpi3mr_os.c | 164 ++++++++++++++++++++++++++++++++
>   2 files changed, 283 insertions(+)
> Reviewed-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                Kernel Storage Architect
hare@suse.de                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer

^ permalink raw reply	[flat|nested] 75+ messages in thread

* RE: [PATCH 01/24] mpi3mr: add mpi30 Rev-R headers and Kconfig
  2021-02-23 12:30   ` Hannes Reinecke
@ 2021-03-02 18:11     ` Kashyap Desai
  0 siblings, 0 replies; 75+ messages in thread
From: Kashyap Desai @ 2021-03-02 18:11 UTC (permalink / raw)
  To: Hannes Reinecke, linux-scsi
  Cc: jejb, martin.petersen, Steve Hagan, Peter Rivera,
	mpi3mr-drvr-developers, Sathya Prakash Veerichetty

[-- Attachment #1: Type: text/plain, Size: 8238 bytes --]

> > +++ b/drivers/scsi/mpi3mr/mpi/mpi30_api.h
> > @@ -0,0 +1,21 @@
> > +/* SPDX-License-Identifier: GPL-2.0-or-later */
> > +/*
> > + *  Copyright 2019-2020 Broadcom Inc. All rights reserved.
> > + *
>
> 2020? Sure you don't want to update it to 2021?
This file is common for application, firmware, driver and UEFI driver and
we are consumer of this file. Further update on this driver will have
updated revision whenever maintainer of this header file post the new
update.

> > +typedef struct _MPI3_SCSI_IO_CDB_EEDP32 {
> > +    U8              CDB[20];                            /* 0x00 */
> > +    __be32          PrimaryReferenceTag;                /* 0x14 */
> > +    U16             PrimaryApplicationTag;              /* 0x18 */
> > +    U16             PrimaryApplicationTagMask;          /* 0x1A */
> > +    U32             TransferLength;                     /* 0x1C */
> > +} MPI3_SCSI_IO_CDB_EEDP32, MPI3_POINTER
> PTR_MPI3_SCSI_IO_CDB_EEDP32,
> > +  Mpi3ScsiIoCdbEedp32_t, MPI3_POINTER pMpi3ScsiIoCdbEedp32_t;
> > +
>
> As noted by Bart, this is a bit naff.
> I can live with having driver-specific typedefs, but having
> driver-specific typedefs _just_ for little endian is pushing it.
> (And incidentally also cancels your argument that you need the
> driver-specific types for cross-development.)
> So please, be consistent, and either use driver-specific typedefs
> throughout or revert to use basic linux types.

As explained earlier - This file is common for application, firmware,
driver and UEFI driver and we are consumer of this file.
Please consider header file as an exception.

>
> > +typedef union _MPI3_SCSO_IO_CDB_UNION {
> > +    U8                      CDB32[32];
> > +    MPI3_SCSI_IO_CDB_EEDP32 EEDP32;
> > +    MPI3_SGE_SIMPLE         SGE;
> > +} MPI3_SCSO_IO_CDB_UNION, MPI3_POINTER
> PTR_MPI3_SCSO_IO_CDB_UNION,
> > +  Mpi3ScsiIoCdb_t, MPI3_POINTER pMpi3ScsiIoCdb_t;
> > +
> > +typedef struct _MPI3_SCSI_IO_REQUEST {
> > +    U16                     HostTag;                        /* 0x00
*/
> > +    U8                      IOCUseOnly02;                   /* 0x02
*/
> > +    U8                      Function;                       /* 0x03
*/
> > +    U16                     IOCUseOnly04;                   /* 0x04
*/
> > +    U8                      IOCUseOnly06;                   /* 0x06
*/
> > +    U8                      MsgFlags;                       /* 0x07
*/
> > +    U16                     ChangeCount;                    /* 0x08
*/
> > +    U16                     DevHandle;                      /* 0x0A
*/
> > +    U32                     Flags;                          /* 0x0C
*/
> > +    U32                     SkipCount;                      /* 0x10
*/
> > +    U32                     DataLength;                     /* 0x14
*/
> > +    U8                      LUN[8];                         /* 0x18
*/
> > +    MPI3_SCSO_IO_CDB_UNION  CDB;                            /* 0x20
*/
> > +    MPI3_SGE_UNION          SGL[4];                         /* 0x40
*/
> > +} MPI3_SCSI_IO_REQUEST, MPI3_POINTER PTR_MPI3_SCSI_IO_REQUEST,
> > +  Mpi3SCSIIORequest_t, MPI3_POINTER pMpi3SCSIIORequest_t;
> > +
>
> Ho-hum.
> What happens if you have SGLs with more than 4 entries?

It is dynamic array. SGL[3] is primarily used in driver and you can notice
that it is for DIF/DIX metadata. Driver will fill simple SGLs in main
frame if there is a room.
Usually MPT Frame size is 128 byte, but another size can be defined by FW
as well. If there are more than 4 SGLs and driver cannot accommodate in
main frame, it will use chain frame which will have remaining SGLs.
Chain frame logic is same as generic mpt3sas interface (with slight
modification in fields based on hardware interface.)

> > diff --git a/drivers/scsi/mpi3mr/mpi/mpi30_type.h
> b/drivers/scsi/mpi3mr/mpi/mpi30_type.h
> > new file mode 100644
> > index 000000000000..5de35e7a660f
> > --- /dev/null
> > +++ b/drivers/scsi/mpi3mr/mpi/mpi30_type.h
> > @@ -0,0 +1,89 @@
> > +/* SPDX-License-Identifier: GPL-2.0-or-later */
> > +/*
> > + *  Copyright 2016-2020 Broadcom Inc. All rights reserved.
> > + *
> > + *           Name: mpi30_type.h
> > + *    Description: MPI basic type definitions
> > + *  Creation Date: 10/07/2016
> > + *        Version: 03.00.00
> > + */
> > +#ifndef MPI30_TYPE_H
> > +#define MPI30_TYPE_H     1
> > +
> >
> +/***************************************************************
> **************
> > + * Define MPI3_POINTER if it has not already been defined. By default
*
> > + * MPI3_POINTER is defined to be a near pointer. MPI3_POINTER can be
> defined *
> > + * as a far pointer by defining MPI3_POINTER as "far *" before this
header
> *
> > + * file is included.
*
> > +
> *****************************************************************
> ***********/
> > +#ifndef MPI3_POINTER
> > +#define MPI3_POINTER    *
> > +#endif  /* MPI3_POINTER */
> > +
> > +/* The basic types may have already been included by mpi_type.h or
> mpi2_type.h*/
> > +#if !defined(MPI_TYPE_H) && !defined(MPI2_TYPE_H)
> > +#if 1
> >
> +/***************************************************************
> **************
> > +*
> > +*               Basic Types
> > +*
> >
> +****************************************************************
> *************/
> > +
> > +typedef u8 U8;
> > +typedef __le16 U16;
> > +typedef __le32 U32;
> > +typedef __le64 U64 __aligned(4);
> > +
> >
> +/***************************************************************
> **************
> > +*
> > +*               Pointer Types
> > +*
> >
> +****************************************************************
> *************/
> > +
> > +typedef U8 * PU8;
> > +typedef U16 * PU16;
> > +typedef U32 * PU32;
> > +typedef U64 * PU64;
> > +#else
> >
> +/***************************************************************
> **************
> > + *              Basic Types
*
> > +
> *****************************************************************
> ***********/
> > +typedef int8_t      S8;
> > +typedef uint8_t     U8;
> > +typedef int16_t     S16;
> > +typedef uint16_t    U16;
> > +typedef int32_t     S32;
> > +typedef uint32_t    U32;
> > +typedef int64_t     S64;
> > +typedef uint64_t    U64;
> > +
> >
> +/***************************************************************
> **************
> > + *              Structure Types
*
> > +
> *****************************************************************
> ***********/
> > +typedef struct _S64struct {
> > +    U32         Low;
> > +    S32         High;
> > +} S64struct;
> > +
> > +typedef struct _U64struct {
> > +    U32         Low;
> > +    U32         High;
> > +} U64struct;
> > +
>
> I wonder why you need these structures on a 64-bit system ...

Please consider all such things in header file as an exception since
header files are common and created to all platforms and users must use
without modified version to avoid API compatibility issues.
Mpi3mr linux driver is not using this but some other users like UEFI
driver, windows drivers etc might be a consumer of it.

>
> >
> +/***************************************************************
> **************
> > + *              Pointer Types
*
> > +
> *****************************************************************
> ***********/
> > +typedef S8 * PS8;
> > +typedef U8 * PU8;
> > +typedef S16 * PS16;
> > +typedef U16 * PU16;
> > +typedef S32         *PS32;
> > +typedef U32         *PU32;
> > +typedef S64 * PS64;
> > +typedef U64 * PU64;
> > +typedef S64struct * PS64struct;
> > +typedef U64struct * PU64struct;
> > +#endif
> > +#endif  /* MPI_TYPE_H && MPI2_TYPE_H */
> > +
> > +#endif  /* MPI30_TYPE_H */
> >
> And I do agree with Bart, please kill the pointer types.
> It's not serving any purpose whatsoever.

Same as above.
>
> Cheers,
>
> Hannes
> --
> Dr. Hannes Reinecke		           Kernel Storage Architect
> hare@suse.de			                  +49 911 74053 688
> SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg
> HRB 36809 (AG Nürnberg), GF: Felix Imendörffer

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4212 bytes --]

^ permalink raw reply	[flat|nested] 75+ messages in thread

* RE: [PATCH 02/24] mpi3mr: base driver code
  2021-02-23 12:55   ` Hannes Reinecke
@ 2021-03-02 18:36     ` Kashyap Desai
  0 siblings, 0 replies; 75+ messages in thread
From: Kashyap Desai @ 2021-03-02 18:36 UTC (permalink / raw)
  To: Hannes Reinecke, linux-scsi
  Cc: jejb, martin.petersen, Steve Hagan, Peter Rivera,
	mpi3mr-drvr-developers, Sathya Prakash Veerichetty

[-- Attachment #1: Type: text/plain, Size: 7260 bytes --]

> > +struct mpi3mr_ioc {
> > +	struct list_head list;
> > +	struct pci_dev *pdev;
> > +	struct Scsi_Host *shost;
> > +	u8 id;
> > +	int cpu_count;
> > +
> > +	char name[MPI3MR_NAME_LENGTH];
> > +	char driver_name[MPI3MR_NAME_LENGTH];
> > +
> > +	Mpi3SysIfRegs_t __iomem *sysif_regs;
> > +	resource_size_t sysif_regs_phys;
> > +	int bars;
> > +	u64 dma_mask;
> > +
> > +	u16 msix_count;
> > +	u8 intr_enabled;
> > +
> > +	u16 num_admin_req;
> > +	u32 admin_req_q_sz;
> > +	u16 admin_req_pi;
> > +	u16 admin_req_ci;
> > +	void *admin_req_base;
> > +	dma_addr_t admin_req_dma;
> > +	spinlock_t admin_req_lock;
> > +
> > +	u16 num_admin_replies;
> > +	u32 admin_reply_q_sz;
> > +	u16 admin_reply_ci;
> > +	u8 admin_reply_ephase;
> > +	void *admin_reply_base;
> > +	dma_addr_t admin_reply_dma;
> > +
> > +	u32 ready_timeout;
> > +
> > +	struct mpi3mr_intr_info *intr_info;
>
> Please, be consistent.
> If you must introduce typedefs for your internal structures, okay.
> But then introduce typedefs for _all_ internal structures.
> Or leave the typedefs and just use 'struct XXX'; which actually is the
> recommended way for linux.

Are you referring " typedef struct mpi3mr_drv_" ?. This is because of some
inter-operability issue of different kernel version. I will remove this
typedef in my V2.
Usually, our goal is not to have typedef in drivers except mpi3.0 header
files. I will scan such instances in and will update all the places.

>
> > +	u16 intr_info_count;
> > +
> > +	u16 num_queues;
> > +	u16 num_op_req_q;
> > +	struct op_req_qinfo *req_qinfo;
> > +
> > +	u16 num_op_reply_q;
> > +	struct op_reply_qinfo *op_reply_qinfo;
> > +
> > +	struct mpi3mr_drv_cmd init_cmds;
> > +	struct mpi3mr_ioc_facts facts;
> > +	u16 op_reply_desc_sz;
> > +
> > +	u32 num_reply_bufs;
> > +	struct dma_pool *reply_buf_pool;
> > +	u8 *reply_buf;
> > +	dma_addr_t reply_buf_dma;
> > +	dma_addr_t reply_buf_dma_max_address;
> > +
> > +	u16 reply_free_qsz;
> > +	struct dma_pool *reply_free_q_pool;
> > +	U64 *reply_free_q;
> > +	dma_addr_t reply_free_q_dma;
> > +	spinlock_t reply_free_queue_lock;
> > +	u32 reply_free_queue_host_index;
> > +
> > +	u32 num_sense_bufs;
> > +	struct dma_pool *sense_buf_pool;
> > +	u8 *sense_buf;
> > +	dma_addr_t sense_buf_dma;
> > +
> > +	u16 sense_buf_q_sz;
> > +	struct dma_pool *sense_buf_q_pool;
> > +	U64 *sense_buf_q;
> > +	dma_addr_t sense_buf_q_dma;
> > +	spinlock_t sbq_lock;
> > +	u32 sbq_host_index;
> > +
> > +	u8 is_driver_loading;
> > +
> > +	u16 max_host_ios;
> > +
> > +	u32 chain_buf_count;
> > +	struct dma_pool *chain_buf_pool;
> > +	struct chain_element *chain_sgl_list;
> > +	u16  chain_bitmap_sz;
> > +	void *chain_bitmap;
> > +
> > +	u8 reset_in_progress;
> > +	u8 unrecoverable;
> > +
> > +	int logging_level;
> > +
> > +	struct mpi3mr_fwevt *current_event;
> > +	Mpi3DriverInfoLayout_t driver_info;
>
> See my comment about struct typedefs above.

I will remove this typedef and similar instances.

> > +static inline int mpi3mr_request_irq(struct mpi3mr_ioc *mrioc, u16
index)
> > +{
> > +	struct pci_dev *pdev = mrioc->pdev;
> > +	struct mpi3mr_intr_info *intr_info = mrioc->intr_info + index;
> > +	int retval = 0;
> > +
> > +	intr_info->mrioc = mrioc;
> > +	intr_info->msix_index = index;
> > +	intr_info->op_reply_q = NULL;
> > +
> > +	snprintf(intr_info->name, MPI3MR_NAME_LENGTH, "%s%d-msix%d",
> > +	    mrioc->driver_name, mrioc->id, index);
> > +
> > +	retval = request_threaded_irq(pci_irq_vector(pdev, index),
> mpi3mr_isr,
> > +	    mpi3mr_isr_poll, IRQF_ONESHOT, intr_info->name, intr_info);
> > +	if (retval) {
> > +		ioc_err(mrioc, "%s: Unable to allocate interrupt %d!\n",
> > +		    intr_info->name, pci_irq_vector(pdev, index));
> > +		return retval;
> > +	}
> > +
>
> The point of having 'mpi3mr_isr_poll()' here is what exactly?

This is a place holder and actual use case is handled in " [17/24] mpi3mr:
add support of threaded isr"
For easy review, I have created separate patch " [17/24] mpi3mr: add
support of threaded isr"
> > +	areq_entry = (u8 *)mrioc->admin_req_base +
> > +	    (areq_pi * MPI3MR_ADMIN_REQ_FRAME_SZ);
> > +	memset(areq_entry, 0, MPI3MR_ADMIN_REQ_FRAME_SZ);
> > +	memcpy(areq_entry, (u8 *)admin_req, admin_req_sz);
> > +
> > +	if (++areq_pi == max_entries)
> > +		areq_pi = 0;
> > +	mrioc->admin_req_pi = areq_pi;
> > +
> > +	writel(mrioc->admin_req_pi, &mrioc->sysif_regs-
> >AdminRequestQueuePI);
> > +
> > +out:
> > +	spin_unlock_irqrestore(&mrioc->admin_req_lock, flags);
> > +
> > +	return retval;
> > +}
> > +
>
> It might be an idea to have an 'admin' queue structure; keeping the
> values all within the main IOC structure might cause cache misses and a
> degraded performance.

Noted your point. We can do it in future update. I think it make sense for
code readability as well.

> > +int mpi3mr_init_ioc(struct mpi3mr_ioc *mrioc)
> > +{
> > +	int retval = 0;
> > +	enum mpi3mr_iocstate ioc_state;
> > +	u64 base_info;
> > +	u32 timeout;
> > +	u32 ioc_status, ioc_config;
> > +	Mpi3IOCFactsData_t facts_data;
> > +
> > +	mrioc->change_count = 0;
> > +	mrioc->cpu_count = num_online_cpus();
>
> What about CPU hotplug?


We have to use num_available_cpus() to get benefit of cpu hotplug. In next
update it will be available.

> > +
> > +/* global driver scop variables */
> > +LIST_HEAD(mrioc_list);
> > +DEFINE_SPINLOCK(mrioc_list_lock);
> > +static int mrioc_ids;
> > +static int warn_non_secure_ctlr;
> > +
> > +MODULE_AUTHOR(MPI3MR_DRIVER_AUTHOR);
> > +MODULE_DESCRIPTION(MPI3MR_DRIVER_DESC);
> > +MODULE_LICENSE(MPI3MR_DRIVER_LICENSE);
> > +MODULE_VERSION(MPI3MR_DRIVER_VERSION);
> > +
> > +/* Module parameters*/
> > +int logging_level;
> > +module_param(logging_level, int, 0);
> > +MODULE_PARM_DESC(logging_level,
> > +	" bits for enabling additional logging info (default=0)");
> > +
> > +
> > +/**
> > + * mpi3mr_map_queues - Map queues callback handler
> > + * @shost: SCSI host reference
> > + *
> > + * Call the blk_mq_pci_map_queues with from which operational
> > + * queue the mapping has to be done
> > + *
> > + * Return: return of blk_mq_pci_map_queues
> > + */
> > +static int mpi3mr_map_queues(struct Scsi_Host *shost)
> > +{
> > +	struct mpi3mr_ioc *mrioc = shost_priv(shost);
> > +
> > +	return blk_mq_pci_map_queues(&shost-
> >tag_set.map[HCTX_TYPE_DEFAULT],
> > +	    mrioc->pdev, 0);
> > +}
> > +
>
> What happened to polling?
> You did some patches for megaraid_sas, so I would have expected them to
> be here, too ...

Internally, Io_uring iopoll is also completed for this driver as well, but
it is under testing and may be available in next update.

> > +module_init(mpi3mr_init);
> > +module_exit(mpi3mr_exit);
> >
> Cheers,

Hannes -

Thanks for the feedback. I am working on all the comments and soon I will
be posting V2.

Kashyap
>
> Hannes
> --
> Dr. Hannes Reinecke		           Kernel Storage Architect
> hare@suse.de			                  +49 911 74053 688
> SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg
> HRB 36809 (AG Nürnberg), GF: Felix Imendörffer

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4212 bytes --]

^ permalink raw reply	[flat|nested] 75+ messages in thread

* RE: [PATCH 03/24] mpi3mr: create operational request and reply queue pair
  2021-02-28 13:04   ` Hannes Reinecke
@ 2021-03-02 19:05     ` Kashyap Desai
  0 siblings, 0 replies; 75+ messages in thread
From: Kashyap Desai @ 2021-03-02 19:05 UTC (permalink / raw)
  To: Hannes Reinecke, linux-scsi
  Cc: jejb, martin.petersen, Steve Hagan, Peter Rivera,
	mpi3mr-drvr-developers, Sathya Prakash Veerichetty

[-- Attachment #1: Type: text/plain, Size: 2096 bytes --]

> > diff --git a/drivers/scsi/mpi3mr/mpi3mr.h
> > b/drivers/scsi/mpi3mr/mpi3mr.h index dd79b12218e1..fe6094bb357a
> 100644
> > --- a/drivers/scsi/mpi3mr/mpi3mr.h
> > +++ b/drivers/scsi/mpi3mr/mpi3mr.h
> > @@ -71,6 +71,12 @@ extern struct list_head mrioc_list;
> >   #define MPI3MR_ADMIN_REQ_FRAME_SZ	128
> >   #define MPI3MR_ADMIN_REPLY_FRAME_SZ	16
> >
> > +/* Operational queue management definitions */
> > +#define MPI3MR_OP_REQ_Q_QD		512
> > +#define MPI3MR_OP_REP_Q_QD		4096
> > +#define MPI3MR_OP_REQ_Q_SEG_SIZE	4096
> > +#define MPI3MR_OP_REP_Q_SEG_SIZE	4096
> > +#define MPI3MR_MAX_SEG_LIST_SIZE	4096
> >
> Do I read this correctly?
> The reply queue depth is larger than the request queue depth?
> Why is that?

Hannes, You are correct. Request queue desc unit size is 128 byte and
reply queue desc unit size is 16 byte.
Having current values of queue depth, we are creating 64K size request
pool and reply pool.
To avoid memory allocation failure, we have come up with some realistic
queue depth which can meet memory allocation requirement on most of the
cases and also we do not harm performance.

BTW, we have also improvement in this area. You can notice segemented
queue depth “enable_segqueue” field in the same patch.
We have plan to improve this area based on test results of
“enable_segqueue”.

> >   /**
> > @@ -220,6 +220,8 @@ mpi3mr_probe(struct pci_dev *pdev, const struct
> pci_device_id *id)
> >   	spin_lock_init(&mrioc->sbq_lock);
> >
> >   	mpi3mr_init_drv_cmd(&mrioc->init_cmds,
> MPI3MR_HOSTTAG_INITCMDS);
> > +	if (pdev->revision)
> > +		mrioc->enable_segqueue = true;
> >
> >   	mrioc->logging_level = logging_level;
> >   	mrioc->shost = shost;
> >
> Other than that:
>
> Reviewed-by: Hannes Reinecke <hare@suse.de>
>
> Cheers,
>
> Hannes
> --
> Dr. Hannes Reinecke                Kernel Storage Architect
> hare@suse.de                              +49 911 74053 688
> SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809
> (AG Nürnberg), Geschäftsführer: Felix Imendörffer

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4212 bytes --]

^ permalink raw reply	[flat|nested] 75+ messages in thread

* RE: [PATCH 04/24] mpi3mr: add support of queue command processing
  2021-02-28 13:22   ` Hannes Reinecke
@ 2021-03-08 18:25     ` Kashyap Desai
  0 siblings, 0 replies; 75+ messages in thread
From: Kashyap Desai @ 2021-03-08 18:25 UTC (permalink / raw)
  To: Hannes Reinecke, linux-scsi
  Cc: jejb, martin.petersen, Steve Hagan, Peter Rivera,
	mpi3mr-drvr-developers, Sathya Prakash Veerichetty

[-- Attachment #1: Type: text/plain, Size: 7632 bytes --]

> > +
> > +/**
> > + * struct mpi3mr_stgt_priv_data - SCSI device private structure
> > + *
> > + * @tgt_priv_data: Scsi_target private data pointer
> > + * @lun_id: LUN ID of the device
> > + * @ncq_prio_enable: NCQ priority enable for SATA device  */ struct
> > +mpi3mr_sdev_priv_data {
> > +	struct mpi3mr_stgt_priv_data *tgt_priv_data;
> > +	u32 lun_id;
> > +	u8 ncq_prio_enable;
> > +};
> >
> Why is there a separate 'lun_id' field?
H/W is multi lun capable and driver store lun_id so that it can pass the
same to the FW in qcmd() and other path like task management etc.

>
> >   typedef struct mpi3mr_drv_cmd DRV_CMD;
> >   typedef void (*DRV_CMD_CALLBACK)(struct mpi3mr_ioc *mrioc, @@
> > -443,12 +481,16 @@ struct scmd_priv {
> >    * @sbq_lock: Sense buffer queue lock
> >    * @sbq_host_index: Sense buffer queuehost index
> >    * @is_driver_loading: Is driver still loading
> > + * @scan_started: Async scan started
> > + * @scan_failed: Asycn scan failed
> > + * @stop_drv_processing: Stop all command processing
> >    * @max_host_ios: Maximum host I/O count
> >    * @chain_buf_count: Chain buffer count
> >    * @chain_buf_pool: Chain buffer pool
> >    * @chain_sgl_list: Chain SGL list
> >    * @chain_bitmap_sz: Chain buffer allocator bitmap size
> >    * @chain_bitmap: Chain buffer allocator bitmap
> > + * @chain_buf_lock: Chain buffer list lock
> >    * @reset_in_progress: Reset in progress flag
> >    * @unrecoverable: Controller unrecoverable flag
> >    * @logging_level: Controller debug logging level @@ -533,6 +575,9
> > @@ struct mpi3mr_ioc {
> >   	u32 sbq_host_index;
> >
> >   	u8 is_driver_loading;
> > +	u8 scan_started;
> > +	u16 scan_failed;
> > +	u8 stop_drv_processing;
> >
> >   	u16 max_host_ios;
> >
> > @@ -541,6 +586,7 @@ struct mpi3mr_ioc {
> >   	struct chain_element *chain_sgl_list;
> >   	u16  chain_bitmap_sz;
> >   	void *chain_bitmap;
> > +	spinlock_t chain_buf_lock;
> >
> >   	u8 reset_in_progress;
> >   	u8 unrecoverable;
> > @@ -557,8 +603,11 @@ int mpi3mr_setup_resources(struct mpi3mr_ioc
> *mrioc);
> >   void mpi3mr_cleanup_resources(struct mpi3mr_ioc *mrioc);
> >   int mpi3mr_init_ioc(struct mpi3mr_ioc *mrioc);
> >   void mpi3mr_cleanup_ioc(struct mpi3mr_ioc *mrioc);
> > +int mpi3mr_issue_port_enable(struct mpi3mr_ioc *mrioc, u8 async);
> >   int mpi3mr_admin_request_post(struct mpi3mr_ioc *mrioc, void
> *admin_req,
> >   u16 admin_req_sz, u8 ignore_reset);
> > +int mpi3mr_op_request_post(struct mpi3mr_ioc *mrioc,
> > +			   struct op_req_qinfo *opreqq, u8 *req);
> >   void mpi3mr_add_sg_single(void *paddr, u8 flags, u32 length,
> >   			  dma_addr_t dma_addr);
> >   void mpi3mr_build_zero_len_sge(void *paddr); @@ -569,6 +618,9 @@
> > void *mpi3mr_get_reply_virt_addr(struct mpi3mr_ioc *mrioc,
> >   void mpi3mr_repost_sense_buf(struct mpi3mr_ioc *mrioc,
> >   				     u64 sense_buf_dma);
> >
> > +void mpi3mr_process_op_reply_desc(struct mpi3mr_ioc *mrioc,
> > +				  Mpi3DefaultReplyDescriptor_t
*reply_desc,
> > +				  u64 *reply_dma, u16 qidx);
> >   void mpi3mr_start_watchdog(struct mpi3mr_ioc *mrioc);
> >   void mpi3mr_stop_watchdog(struct mpi3mr_ioc *mrioc);
> >
> > diff --git a/drivers/scsi/mpi3mr/mpi3mr_fw.c
> > b/drivers/scsi/mpi3mr/mpi3mr_fw.c index 6fb28983038e..abdf8c653e6b
> > 100644
> > --- a/drivers/scsi/mpi3mr/mpi3mr_fw.c
> > +++ b/drivers/scsi/mpi3mr/mpi3mr_fw.c
> > @@ -24,6 +24,23 @@ static inline void mpi3mr_writeq(__u64 b, volatile
> void __iomem *addr)
> >   }
> >   #endif
> >
> > +static inline bool
> > +mpi3mr_check_req_qfull(struct op_req_qinfo *op_req_q) {
> > +	u16 pi, ci, max_entries;
> > +	bool is_qfull = false;
> > +
> > +	pi = op_req_q->pi;
> > +	ci = op_req_q->ci;
> > +	max_entries = op_req_q->num_requests;
> > +
> > +	if ((ci == (pi + 1)) || ((!ci) && (pi == (max_entries - 1))))
> > +		is_qfull = true;
> > +
> > +	return is_qfull;
> > +}
> > + > +
>
> This needs to be protected by a lock to ensure the 'ci' and 'pi' values
won't
> change during processing; alternatively you'd need to use
> READ_ONCE() here.

I will add READ_ONCE() for op_req_q->ci.

> Please modify or add respective lockdep annotations.
I will discuss with you.

>
> >   static void mpi3mr_sync_irqs(struct mpi3mr_ioc *mrioc)
> >   {
> >   	u16 i, max_vectors;
> > @@ -282,6 +299,87 @@ static int mpi3mr_process_admin_reply_q(struct
> mpi3mr_ioc *mrioc)
> >   	return num_admin_replies;
> >   }
> >
> > +/**
> > + * mpi3mr_get_reply_desc - get reply descriptor frame corresponding
to
> > + *	queue's consumer index from operational reply descriptor queue.
> > + * @op_reply_q: op_reply_qinfo object
> > + * @reply_ci: operational reply descriptor's queue consumer index
> > + *
> > + * Returns reply descriptor frame address  */ static inline
> > +Mpi3DefaultReplyDescriptor_t * mpi3mr_get_reply_desc(struct
> > +op_reply_qinfo *op_reply_q, u32 reply_ci) {
> > +	void *segment_base_addr;
> > +	struct segments *segments = op_reply_q->q_segments;
> > +	Mpi3DefaultReplyDescriptor_t *reply_desc = NULL;
> > +
> > +	segment_base_addr =
> > +	    segments[reply_ci / op_reply_q->segment_qd].segment;
> > +	reply_desc = (Mpi3DefaultReplyDescriptor_t *)segment_base_addr +
> > +	    (reply_ci % op_reply_q->segment_qd);
> > +	return reply_desc;
> > +}
> > +
> > +
> > +static int mpi3mr_process_op_reply_q(struct mpi3mr_ioc *mrioc,
> > +	struct mpi3mr_intr_info *intr_info)
> > +{
> > +	struct op_reply_qinfo *op_reply_q = intr_info->op_reply_q;
> > +	struct op_req_qinfo *op_req_q;
> > +	u32 exp_phase;
> > +	u32 reply_ci;
> > +	u32 num_op_reply = 0;
> > +	u64 reply_dma = 0;
> > +	Mpi3DefaultReplyDescriptor_t *reply_desc;
> > +	u16 req_q_idx = 0, reply_qidx;
> > +
> > +	reply_qidx = op_reply_q->qid - 1;
> > +
> > +	exp_phase = op_reply_q->ephase;
> > +	reply_ci = op_reply_q->ci;
> > +
> > +	reply_desc = mpi3mr_get_reply_desc(op_reply_q, reply_ci);
> > +	if ((le16_to_cpu(reply_desc->ReplyFlags) &
> > +	    MPI3_REPLY_DESCRIPT_FLAGS_PHASE_MASK) != exp_phase) {
> > +		return 0;
> > +	}
> > +
> > +	do {
> > +		req_q_idx = le16_to_cpu(reply_desc->RequestQueueID) - 1;
> > +		op_req_q = &mrioc->req_qinfo[req_q_idx];
> > +
> > +		op_req_q->ci =
> > +		    le16_to_cpu(reply_desc->RequestQueueCI);
> > +
>
> This introduces an interlock with request processing; from what I can
see
> request processing is guarded by a spinlock, yet I don't see any
protection
> here.
As of now there is only one path to process reply queue (from interrupt).
Going forward, blk_mq_poll interface in this driver require interlock in
this area.

> How do you ensure a timely update of the 'ci' value if there is parallel
> execution of requests and responses (note: you cannot always assume that
> you will have a 1:1 relationship between queuepairs, CPUs, and
interrupts).
> I would have expected at least a WRITE_ONCE() here.

I will add WRITE_ONCE.
>
> Question is why you need to modify this at all; in most implementations
I
> know of the 'ci' index is modified by firmware, as really it's the
firmware
> consuming the request.
> Why not here?
Each request queue need separate memory space of queue_depth for that
particular request queue. Currently we are restricting 256 queue depth for
each request queue to get better memory utilization. If we allocate each
request queue same as can_queue, we may not have require this queue_full
check (there may be some corner case, but we can work on those.).  "ci" on
request queue is updated by FW only, but driver is reading those value to
know if there are enough space to post more request. If we see frequent
queue_full with 256 queue depth, we will increase the queue_depth value in
future.

~ Kashyap

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4212 bytes --]

^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 13/24] mpi3mr: implement scsi error handler hooks
  2021-03-01  7:09   ` Hannes Reinecke
@ 2021-04-16 14:12     ` Kashyap Desai
  2021-04-16 14:31       ` Hannes Reinecke
  0 siblings, 1 reply; 75+ messages in thread
From: Kashyap Desai @ 2021-04-16 14:12 UTC (permalink / raw)
  To: Hannes Reinecke
  Cc: linux-scsi, James E . J . Bottomley, Martin K. Petersen,
	Steve Hagan, Peter Rivera, mpi3mr-drvr-developers,
	Sathya Prakash Veerichetty

[-- Attachment #1: Type: text/plain, Size: 1326 bytes --]

> > +     if (host_tag >= MPI3MR_HOSTTAG_DEVRMCMD_MIN &&
> > +         host_tag <= MPI3MR_HOSTTAG_DEVRMCMD_MAX) {
> > +             idx = host_tag - MPI3MR_HOSTTAG_DEVRMCMD_MIN;
> > +             return &mrioc->dev_rmhs_cmds[idx];
> > +     }
> >
> >       return NULL;
> >   }
>
> Looks like this hunk is misdirected, and should be moved to the device
> handling patch ...

Hannes -
I missed to reply to this thread. I have handled this in V2. I am
planning to post V3 soon.

>
> Hmm. This looks a bit unfortunate.
> You are reserving just one tag for task management commands, which is
> okay for device and target reset (as there we're running in single-step
> mode and will only ever need one tag), but it's certainly not okay for
> task abort, which is issued in-line and as such can occur for _every_
> command.
>
> So I guess you'll need to rethink you tag allocation strategy here.

Agree with you Hannes. Currently we are looking for a stable interface and
improvement in upcoming driver updates.

>
> Cheers,
>
> Hannes
> --
> Dr. Hannes Reinecke                Kernel Storage Architect
> hare@suse.de                              +49 911 74053 688
> SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
> HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4212 bytes --]

^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 13/24] mpi3mr: implement scsi error handler hooks
  2021-04-16 14:12     ` Kashyap Desai
@ 2021-04-16 14:31       ` Hannes Reinecke
  0 siblings, 0 replies; 75+ messages in thread
From: Hannes Reinecke @ 2021-04-16 14:31 UTC (permalink / raw)
  To: Kashyap Desai
  Cc: linux-scsi, James E . J . Bottomley, Martin K. Petersen,
	Steve Hagan, Peter Rivera, mpi3mr-drvr-developers,
	Sathya Prakash Veerichetty

On 4/16/21 4:12 PM, Kashyap Desai wrote:
>>> +     if (host_tag >= MPI3MR_HOSTTAG_DEVRMCMD_MIN &&
>>> +         host_tag <= MPI3MR_HOSTTAG_DEVRMCMD_MAX) {
>>> +             idx = host_tag - MPI3MR_HOSTTAG_DEVRMCMD_MIN;
>>> +             return &mrioc->dev_rmhs_cmds[idx];
>>> +     }
>>>
>>>       return NULL;
>>>   }
>>
>> Looks like this hunk is misdirected, and should be moved to the device
>> handling patch ...
> 
> Hannes -
> I missed to reply to this thread. I have handled this in V2. I am
> planning to post V3 soon.
> 
>>
>> Hmm. This looks a bit unfortunate.
>> You are reserving just one tag for task management commands, which is
>> okay for device and target reset (as there we're running in single-step
>> mode and will only ever need one tag), but it's certainly not okay for
>> task abort, which is issued in-line and as such can occur for _every_
>> command.
>>
>> So I guess you'll need to rethink you tag allocation strategy here.
> 
> Agree with you Hannes. Currently we are looking for a stable interface and
> improvement in upcoming driver updates.
> 
Alternatively you could drop task abort (in favour of doing a task set
abort/lun reset); that way your current tag allocation strategy would
work and we can think of command abort later.

Which will be even more of an issue once my patchset for private
commands in SCSI goes in (note to self: resend); there are other drivers
which will suffer from precisely this issue, too.

I'll be reviewing the other patches shortly.

Cheers,

Hannes
-- 
Dr. Hannes Reinecke		        Kernel Storage Architect
hare@suse.de			               +49 911 74053 688
SUSE Software Solutions Germany GmbH, 90409 Nürnberg
GF: F. Imendörffer, HRB 36809 (AG Nürnberg)

^ permalink raw reply	[flat|nested] 75+ messages in thread

end of thread, other threads:[~2021-04-16 14:31 UTC | newest]

Thread overview: 75+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-22 10:11 [PATCH 00/24] Introducing mpi3mr driver Kashyap Desai
2020-12-22 10:11 ` [PATCH 01/24] mpi3mr: add mpi30 Rev-R headers and Kconfig Kashyap Desai
2020-12-22 18:15   ` Bart Van Assche
2020-12-23 13:33     ` Kashyap Desai
2021-02-23 12:30   ` Hannes Reinecke
2021-03-02 18:11     ` Kashyap Desai
2020-12-22 10:11 ` [PATCH 02/24] mpi3mr: base driver code Kashyap Desai
2020-12-27 14:14   ` kernel test robot
2020-12-27 14:14     ` kernel test robot
2021-02-23 12:55   ` Hannes Reinecke
2021-03-02 18:36     ` Kashyap Desai
2020-12-22 10:11 ` [PATCH 03/24] mpi3mr: create operational request and reply queue pair Kashyap Desai
2020-12-22 18:18   ` Bart Van Assche
2020-12-23 13:16     ` Kashyap Desai
2021-02-28 13:04   ` Hannes Reinecke
2021-03-02 19:05     ` Kashyap Desai
2020-12-22 10:11 ` [PATCH 04/24] mpi3mr: add support of queue command processing Kashyap Desai
2021-02-22 15:23   ` Tomas Henzl
2021-02-25 13:24     ` Kashyap Desai
2021-02-25 14:11       ` Tomas Henzl
2021-02-28 13:22   ` Hannes Reinecke
2021-03-08 18:25     ` Kashyap Desai
2020-12-22 10:11 ` [PATCH 05/24] mpi3mr: add support of internal watchdog thread Kashyap Desai
2021-02-28 13:24   ` Hannes Reinecke
2020-12-22 10:11 ` [PATCH 06/24] mpi3mr: add support of event handling part-1 Kashyap Desai
2020-12-27 13:14   ` kernel test robot
2020-12-27 13:14     ` kernel test robot
2021-02-22 15:31   ` Tomas Henzl
2021-02-25 13:36     ` Kashyap Desai
2021-03-01  6:47   ` Hannes Reinecke
2020-12-22 10:11 ` [PATCH 07/24] mpi3mr: add support of event handling pcie devices part-2 Kashyap Desai
2021-03-01  6:52   ` Hannes Reinecke
2020-12-22 10:11 ` [PATCH 08/24] mpi3mr: add support of event handling part-3 Kashyap Desai
2021-03-01  6:53   ` Hannes Reinecke
2020-12-22 10:11 ` [PATCH 09/24] mpi3mr: add support for recovering controller Kashyap Desai
2021-03-01  6:56   ` Hannes Reinecke
2020-12-22 10:11 ` [PATCH 10/24] mpi3mr: add support of timestamp sync with firmware Kashyap Desai
2021-03-01  6:57   ` Hannes Reinecke
2020-12-22 10:11 ` [PATCH 11/24] mpi3mr: print ioc info for debugging Kashyap Desai
2021-03-01  6:59   ` Hannes Reinecke
2020-12-22 10:11 ` [PATCH 12/24] mpi3mr: add bios_param shost template hook Kashyap Desai
2021-03-01  7:00   ` Hannes Reinecke
2020-12-22 10:11 ` [PATCH 13/24] mpi3mr: implement scsi error handler hooks Kashyap Desai
2021-03-01  7:09   ` Hannes Reinecke
2021-04-16 14:12     ` Kashyap Desai
2021-04-16 14:31       ` Hannes Reinecke
2020-12-22 10:11 ` [PATCH 14/24] mpi3mr: add change queue depth support Kashyap Desai
2021-03-01  7:10   ` Hannes Reinecke
2020-12-22 10:11 ` [PATCH 15/24] mpi3mr: allow certain commands during pci-remove hook Kashyap Desai
2021-03-01  7:11   ` Hannes Reinecke
2020-12-22 10:11 ` [PATCH 16/24] mpi3mr: hardware workaround for UNMAP commands to nvme drives Kashyap Desai
2021-03-01  7:13   ` Hannes Reinecke
2020-12-22 10:11 ` [PATCH 17/24] mpi3mr: add support of threaded isr Kashyap Desai
2020-12-27 13:51   ` kernel test robot
2020-12-27 13:51     ` kernel test robot
2021-03-01  7:14   ` Hannes Reinecke
2020-12-22 10:11 ` [PATCH 18/24] mpi3mr: add complete support of soft reset Kashyap Desai
2021-03-01  7:16   ` Hannes Reinecke
2020-12-22 10:11 ` [PATCH 19/24] mpi3mr: print pending host ios for debug Kashyap Desai
2021-03-01  7:16   ` Hannes Reinecke
2020-12-22 10:11 ` [PATCH 20/24] mpi3mr: wait for pending IO completions upon detection of VD IO timeout Kashyap Desai
2021-03-01  7:17   ` Hannes Reinecke
2020-12-22 10:11 ` [PATCH 21/24] mpi3mr: add support of PM suspend and resume Kashyap Desai
2021-02-22 15:32   ` Tomas Henzl
2021-02-25 13:37     ` Kashyap Desai
2021-03-01  7:18   ` Hannes Reinecke
2020-12-22 10:11 ` [PATCH 22/24] mpi3mr: add support of DSN secure fw check Kashyap Desai
2021-03-01  7:19   ` Hannes Reinecke
2020-12-22 10:11 ` [PATCH 23/24] mpi3mr: add eedp dif dix support Kashyap Desai
2021-02-22 15:37   ` Tomas Henzl
2021-02-25 13:39     ` Kashyap Desai
2021-03-01  7:20   ` Hannes Reinecke
2020-12-22 10:11 ` [PATCH 24/24] mpi3mr: add event handling debug prints Kashyap Desai
2021-03-01  7:20   ` Hannes Reinecke
2021-02-22 15:39 ` [PATCH 00/24] Introducing mpi3mr driver Tomas Henzl

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.