[PATCH v3 2/2] HACK: remove all v6.11-rc1 changes in drivers/scsi/

Luca Coelho luciano.coelho at intel.com
Tue Jul 30 13:52:13 UTC 2024


Signed-off-by: Luca Coelho <luciano.coelho at intel.com>
---
 drivers/scsi/BusLogic.c                   |    1 -
 drivers/scsi/Kconfig                      |    1 +
 drivers/scsi/advansys.c                   |    1 -
 drivers/scsi/aha152x.c                    |    2 +-
 drivers/scsi/aha1542.c                    |    2 -
 drivers/scsi/aha1740.c                    |    1 -
 drivers/scsi/arm/acornscsi.c              |    9 +-
 drivers/scsi/arm/cumana_2.c               |    2 +-
 drivers/scsi/arm/eesox.c                  |    2 +-
 drivers/scsi/arm/powertec.c               |    2 +-
 drivers/scsi/atari_scsi.c                 |    1 -
 drivers/scsi/atp870u.c                    |    2 -
 drivers/scsi/elx/efct/efct_driver.c       |    1 -
 drivers/scsi/fcoe/fcoe_sysfs.c            |    2 +-
 drivers/scsi/g_NCR5380.c                  |    1 -
 drivers/scsi/imm.c                        |    2 +-
 drivers/scsi/isci/init.c                  |    1 -
 drivers/scsi/iscsi_tcp.c                  |    8 +-
 drivers/scsi/libsas/sas_ata.c             |   22 +-
 drivers/scsi/libsas/sas_discover.c        |    2 +-
 drivers/scsi/lpfc/lpfc_attr.c             |   10 +-
 drivers/scsi/lpfc/lpfc_ct.c               |   16 +-
 drivers/scsi/lpfc/lpfc_els.c              |   19 +-
 drivers/scsi/lpfc/lpfc_hbadisc.c          |   10 +-
 drivers/scsi/lpfc/lpfc_nvmet.c            |   11 -
 drivers/scsi/lpfc/lpfc_sli.c              |   43 +-
 drivers/scsi/lpfc/lpfc_version.h          |    2 +-
 drivers/scsi/mac_scsi.c                   |    1 -
 drivers/scsi/megaraid/megaraid_sas_base.c |    2 +
 drivers/scsi/mpi3mr/mpi/mpi30_tool.h      |   44 -
 drivers/scsi/mpi3mr/mpi3mr.h              |  140 +--
 drivers/scsi/mpi3mr/mpi3mr_app.c          | 1090 +--------------------
 drivers/scsi/mpi3mr/mpi3mr_fw.c           |  294 +-----
 drivers/scsi/mpi3mr/mpi3mr_os.c           |  361 +------
 drivers/scsi/mpi3mr/mpi3mr_transport.c    |   43 +-
 drivers/scsi/mpt3sas/mpt3sas_scsih.c      |    6 +
 drivers/scsi/pcmcia/aha152x_stub.c        |    1 -
 drivers/scsi/pm8001/pm8001_sas.c          |    4 +-
 drivers/scsi/pm8001/pm80xx_hwi.c          |    6 +-
 drivers/scsi/ppa.c                        |    2 +-
 drivers/scsi/qedf/qedf_main.c             |    2 +-
 drivers/scsi/qla2xxx/qla_bsg.c            |   98 +-
 drivers/scsi/qla2xxx/qla_def.h            |   17 +-
 drivers/scsi/qla2xxx/qla_gbl.h            |    6 +-
 drivers/scsi/qla2xxx/qla_gs.c             |  467 +++++----
 drivers/scsi/qla2xxx/qla_init.c           |   94 +-
 drivers/scsi/qla2xxx/qla_inline.h         |    8 -
 drivers/scsi/qla2xxx/qla_isr.c            |    6 +
 drivers/scsi/qla2xxx/qla_mid.c            |    2 +-
 drivers/scsi/qla2xxx/qla_nvme.c           |    5 +-
 drivers/scsi/qla2xxx/qla_os.c             |   19 +-
 drivers/scsi/qla2xxx/qla_sup.c            |  108 +-
 drivers/scsi/qla2xxx/qla_version.h        |    4 +-
 drivers/scsi/scsi_common.c                |    1 -
 drivers/scsi/scsi_debug.c                 |  588 +++--------
 drivers/scsi/scsi_devinfo.c               |   11 +-
 drivers/scsi/scsi_lib.c                   |    9 +-
 drivers/scsi/scsi_scan.c                  |    3 +-
 drivers/scsi/scsi_sysfs.c                 |    6 +-
 drivers/scsi/scsi_trace.c                 |   22 -
 drivers/scsi/scsi_transport_iscsi.c       |    2 +-
 drivers/scsi/sd.c                         |  376 +++----
 drivers/scsi/sd.h                         |   31 +-
 drivers/scsi/sd_dif.c                     |   45 +-
 drivers/scsi/sd_zbc.c                     |   52 +-
 drivers/scsi/sr.c                         |   42 +-
 drivers/scsi/sun3_scsi.c                  |    1 -
 drivers/scsi/virtio_scsi.c                |   32 +-
 68 files changed, 901 insertions(+), 3326 deletions(-)
 delete mode 100644 drivers/scsi/mpi3mr/mpi/mpi30_tool.h

diff --git a/drivers/scsi/BusLogic.c b/drivers/scsi/BusLogic.c
index 2135a2b3e2d0..72ceaf650b0d 100644
--- a/drivers/scsi/BusLogic.c
+++ b/drivers/scsi/BusLogic.c
@@ -78,7 +78,6 @@ static struct blogic_drvr_options blogic_drvr_options[BLOGIC_MAX_ADAPTERS];
   BusLogic can be assigned a string by insmod.
 */
 
-MODULE_DESCRIPTION("BusLogic MultiMaster and FlashPoint SCSI Host Adapter driver");
 MODULE_LICENSE("GPL");
 #ifdef MODULE
 static char *BusLogic;
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index 37c24ffea65c..065db86d6021 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -82,6 +82,7 @@ comment "SCSI support type (disk, tape, CD-ROM)"
 config BLK_DEV_SD
 	tristate "SCSI disk support"
 	depends on SCSI
+	select BLK_DEV_INTEGRITY_T10 if BLK_DEV_INTEGRITY
 	help
 	  If you want to use SCSI hard disks, Fibre Channel disks,
 	  Serial ATA (SATA) or Parallel ATA (PATA) hard disks,
diff --git a/drivers/scsi/advansys.c b/drivers/scsi/advansys.c
index fd4fcb37863d..ab066bb27a57 100644
--- a/drivers/scsi/advansys.c
+++ b/drivers/scsi/advansys.c
@@ -11545,7 +11545,6 @@ static void __exit advansys_exit(void)
 module_init(advansys_init);
 module_exit(advansys_exit);
 
-MODULE_DESCRIPTION("AdvanSys SCSI Adapter driver");
 MODULE_LICENSE("GPL");
 MODULE_FIRMWARE("advansys/mcode.bin");
 MODULE_FIRMWARE("advansys/3550.bin");
diff --git a/drivers/scsi/aha152x.c b/drivers/scsi/aha152x.c
index a0fb330b8df5..83f16fc14d96 100644
--- a/drivers/scsi/aha152x.c
+++ b/drivers/scsi/aha152x.c
@@ -1072,7 +1072,7 @@ static int aha152x_abort(struct scsi_cmnd *SCpnt)
 static int aha152x_device_reset(struct scsi_cmnd * SCpnt)
 {
 	struct Scsi_Host *shpnt = SCpnt->device->host;
-	DECLARE_COMPLETION_ONSTACK(done);
+	DECLARE_COMPLETION(done);
 	int ret, issued, disconnected;
 	unsigned char old_cmd_len = SCpnt->cmd_len;
 	unsigned long flags;
diff --git a/drivers/scsi/aha1542.c b/drivers/scsi/aha1542.c
index 389499d3e00a..9503996c6325 100644
--- a/drivers/scsi/aha1542.c
+++ b/drivers/scsi/aha1542.c
@@ -1009,8 +1009,6 @@ static int aha1542_biosparam(struct scsi_device *sdev,
 
 	return 0;
 }
-
-MODULE_DESCRIPTION("Adaptec AHA-1542 SCSI host adapter driver");
 MODULE_LICENSE("GPL");
 
 static int aha1542_init_cmd_priv(struct Scsi_Host *shost, struct scsi_cmnd *cmd)
diff --git a/drivers/scsi/aha1740.c b/drivers/scsi/aha1740.c
index be7ebbbb9ba8..3d18945abaf7 100644
--- a/drivers/scsi/aha1740.c
+++ b/drivers/scsi/aha1740.c
@@ -681,5 +681,4 @@ static __exit void aha1740_exit (void)
 module_init (aha1740_init);
 module_exit (aha1740_exit);
 
-MODULE_DESCRIPTION("Adaptec AHA1740 SCSI host adapter driver");
 MODULE_LICENSE("GPL");
diff --git a/drivers/scsi/arm/acornscsi.c b/drivers/scsi/arm/acornscsi.c
index e50a3dbf9de3..0b046e4b395c 100644
--- a/drivers/scsi/arm/acornscsi.c
+++ b/drivers/scsi/arm/acornscsi.c
@@ -2450,7 +2450,7 @@ static int acornscsi_queuecmd_lck(struct scsi_cmnd *SCpnt)
     return 0;
 }
 
-static DEF_SCSI_QCMD(acornscsi_queuecmd)
+DEF_SCSI_QCMD(acornscsi_queuecmd)
 
 enum res_abort { res_not_running, res_success, res_success_clear, res_snooze };
 
@@ -2552,7 +2552,7 @@ static enum res_abort acornscsi_do_abort(AS_Host *host, struct scsi_cmnd *SCpnt)
  * Params   : SCpnt - command to abort
  * Returns  : one of SCSI_ABORT_ macros
  */
-static int acornscsi_abort(struct scsi_cmnd *SCpnt)
+int acornscsi_abort(struct scsi_cmnd *SCpnt)
 {
 	AS_Host *host = (AS_Host *) SCpnt->device->host->hostdata;
 	int result;
@@ -2634,7 +2634,7 @@ static int acornscsi_abort(struct scsi_cmnd *SCpnt)
  * Params   : SCpnt  - command causing reset
  * Returns  : one of SCSI_RESET_ macros
  */
-static int acornscsi_host_reset(struct scsi_cmnd *SCpnt)
+int acornscsi_host_reset(struct scsi_cmnd *SCpnt)
 {
 	AS_Host *host = (AS_Host *)SCpnt->device->host->hostdata;
 	struct scsi_cmnd *SCptr;
@@ -2679,7 +2679,8 @@ static int acornscsi_host_reset(struct scsi_cmnd *SCpnt)
  * Params  : host - host to give information on
  * Returns : a constant string
  */
-static const char *acornscsi_info(struct Scsi_Host *host)
+const
+char *acornscsi_info(struct Scsi_Host *host)
 {
     static char string[100], *p;
 
diff --git a/drivers/scsi/arm/cumana_2.c b/drivers/scsi/arm/cumana_2.c
index e460068f6834..c5d8f4313b31 100644
--- a/drivers/scsi/arm/cumana_2.c
+++ b/drivers/scsi/arm/cumana_2.c
@@ -296,7 +296,7 @@ cumanascsi_2_dma_stop(struct Scsi_Host *host, struct scsi_pointer *SCp)
  * Params   : host - driver host structure to return info for.
  * Returns  : pointer to a static buffer containing null terminated string.
  */
-static const char *cumanascsi_2_info(struct Scsi_Host *host)
+const char *cumanascsi_2_info(struct Scsi_Host *host)
 {
 	struct cumanascsi2_info *info = (struct cumanascsi2_info *)host->hostdata;
 	static char string[150];
diff --git a/drivers/scsi/arm/eesox.c b/drivers/scsi/arm/eesox.c
index 99be9da8757f..b3ec7635bc72 100644
--- a/drivers/scsi/arm/eesox.c
+++ b/drivers/scsi/arm/eesox.c
@@ -381,7 +381,7 @@ eesoxscsi_dma_stop(struct Scsi_Host *host, struct scsi_pointer *SCp)
  * Params   : host - driver host structure to return info for.
  * Returns  : pointer to a static buffer containing null terminated string.
  */
-static const char *eesoxscsi_info(struct Scsi_Host *host)
+const char *eesoxscsi_info(struct Scsi_Host *host)
 {
 	struct eesoxscsi_info *info = (struct eesoxscsi_info *)host->hostdata;
 	static char string[150];
diff --git a/drivers/scsi/arm/powertec.c b/drivers/scsi/arm/powertec.c
index 823c65ff6c12..3b5991427886 100644
--- a/drivers/scsi/arm/powertec.c
+++ b/drivers/scsi/arm/powertec.c
@@ -184,7 +184,7 @@ powertecscsi_dma_stop(struct Scsi_Host *host, struct scsi_pointer *SCp)
  * Params   : host - driver host structure to return info for.
  * Returns  : pointer to a static buffer containing null terminated string.
  */
-static const char *powertecscsi_info(struct Scsi_Host *host)
+const char *powertecscsi_info(struct Scsi_Host *host)
 {
 	struct powertec_info *info = (struct powertec_info *)host->hostdata;
 	static char string[150];
diff --git a/drivers/scsi/atari_scsi.c b/drivers/scsi/atari_scsi.c
index 98a1b966a0b0..742625ac7d99 100644
--- a/drivers/scsi/atari_scsi.c
+++ b/drivers/scsi/atari_scsi.c
@@ -894,5 +894,4 @@ static struct platform_driver atari_scsi_driver __refdata = {
 module_platform_driver_probe(atari_scsi_driver, atari_scsi_probe);
 
 MODULE_ALIAS("platform:" DRV_MODULE_NAME);
-MODULE_DESCRIPTION("Atari TT/Falcon NCR5380 SCSI driver");
 MODULE_LICENSE("GPL");
diff --git a/drivers/scsi/atp870u.c b/drivers/scsi/atp870u.c
index 928151ec927a..2a748af269c2 100644
--- a/drivers/scsi/atp870u.c
+++ b/drivers/scsi/atp870u.c
@@ -1724,8 +1724,6 @@ static void atp870u_remove (struct pci_dev *pdev)
 	atp870u_free_tables(pshost);
 	scsi_host_put(pshost);
 }
-
-MODULE_DESCRIPTION("ACARD SCSI host adapter driver");
 MODULE_LICENSE("GPL");
 
 static const struct scsi_host_template atp870u_template = {
diff --git a/drivers/scsi/elx/efct/efct_driver.c b/drivers/scsi/elx/efct/efct_driver.c
index 55d2301bfd7d..49fd2cfed70c 100644
--- a/drivers/scsi/elx/efct/efct_driver.c
+++ b/drivers/scsi/elx/efct/efct_driver.c
@@ -778,6 +778,5 @@ static void __exit efct_exit(void)
 module_init(efct_init);
 module_exit(efct_exit);
 MODULE_VERSION(EFCT_DRIVER_VERSION);
-MODULE_DESCRIPTION("Emulex Fibre Channel Target driver");
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Broadcom");
diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
index 7d3b904af9e8..453665ac6020 100644
--- a/drivers/scsi/fcoe/fcoe_sysfs.c
+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
@@ -600,7 +600,7 @@ static const struct attribute_group *fcoe_fcf_attr_groups[] = {
 static const struct bus_type fcoe_bus_type;
 
 static int fcoe_bus_match(struct device *dev,
-			  const struct device_driver *drv)
+			  struct device_driver *drv)
 {
 	if (dev->bus == &fcoe_bus_type)
 		return 1;
diff --git a/drivers/scsi/g_NCR5380.c b/drivers/scsi/g_NCR5380.c
index 270eae7ac427..f6305e3e60f4 100644
--- a/drivers/scsi/g_NCR5380.c
+++ b/drivers/scsi/g_NCR5380.c
@@ -110,7 +110,6 @@ module_param_array(card, int, NULL, 0);
 MODULE_PARM_DESC(card, "card type (0=NCR5380, 1=NCR53C400, 2=NCR53C400A, 3=DTC3181E, 4=HP C2502)");
 
 MODULE_ALIAS("g_NCR5380_mmio");
-MODULE_DESCRIPTION("Generic NCR5380/NCR53C400 SCSI driver");
 MODULE_LICENSE("GPL");
 
 static void g_NCR5380_trigger_irq(struct Scsi_Host *instance)
diff --git a/drivers/scsi/imm.c b/drivers/scsi/imm.c
index 1d4c7310f1a6..21339da505f1 100644
--- a/drivers/scsi/imm.c
+++ b/drivers/scsi/imm.c
@@ -1275,8 +1275,8 @@ static struct parport_driver imm_driver = {
 	.name		= "imm",
 	.match_port	= imm_attach,
 	.detach		= imm_detach,
+	.devmodel	= true,
 };
 module_parport_driver(imm_driver);
 
-MODULE_DESCRIPTION("IOMEGA MatchMaker parallel port SCSI host adapter driver");
 MODULE_LICENSE("GPL");
diff --git a/drivers/scsi/isci/init.c b/drivers/scsi/isci/init.c
index d31884f82f2a..de2aefcf2089 100644
--- a/drivers/scsi/isci/init.c
+++ b/drivers/scsi/isci/init.c
@@ -758,7 +758,6 @@ static __exit void isci_exit(void)
 	sas_release_transport(isci_transport_template);
 }
 
-MODULE_DESCRIPTION("Intel(R) C600 Series Chipset SAS Controller driver");
 MODULE_LICENSE("Dual BSD/GPL");
 MODULE_FIRMWARE(ISCI_FW_NAME);
 module_init(isci_init);
diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c
index c708e1059638..60688f18fac6 100644
--- a/drivers/scsi/iscsi_tcp.c
+++ b/drivers/scsi/iscsi_tcp.c
@@ -1057,15 +1057,15 @@ static umode_t iscsi_sw_tcp_attr_is_visible(int param_type, int param)
 	return 0;
 }
 
-static int iscsi_sw_tcp_device_configure(struct scsi_device *sdev,
-		struct queue_limits *lim)
+static int iscsi_sw_tcp_slave_configure(struct scsi_device *sdev)
 {
 	struct iscsi_sw_tcp_host *tcp_sw_host = iscsi_host_priv(sdev->host);
 	struct iscsi_session *session = tcp_sw_host->session;
 	struct iscsi_conn *conn = session->leadconn;
 
 	if (conn->datadgst_en)
-		lim->features |= BLK_FEAT_STABLE_WRITES;
+		blk_queue_flag_set(QUEUE_FLAG_STABLE_WRITES,
+				   sdev->request_queue);
 	return 0;
 }
 
@@ -1083,7 +1083,7 @@ static const struct scsi_host_template iscsi_sw_tcp_sht = {
 	.eh_device_reset_handler= iscsi_eh_device_reset,
 	.eh_target_reset_handler = iscsi_eh_recover_target,
 	.dma_boundary		= PAGE_SIZE - 1,
-	.device_configure	= iscsi_sw_tcp_device_configure,
+	.slave_configure        = iscsi_sw_tcp_slave_configure,
 	.proc_name		= "iscsi_tcp",
 	.this_id		= -1,
 	.track_queue_depth	= 1,
diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
index 88714b7b0dba..cbbe43d8ef87 100644
--- a/drivers/scsi/libsas/sas_ata.c
+++ b/drivers/scsi/libsas/sas_ata.c
@@ -572,6 +572,15 @@ static struct ata_port_operations sas_sata_ops = {
 	.end_eh			= sas_ata_end_eh,
 };
 
+static struct ata_port_info sata_port_info = {
+	.flags = ATA_FLAG_SATA | ATA_FLAG_PIO_DMA | ATA_FLAG_NCQ |
+		 ATA_FLAG_SAS_HOST | ATA_FLAG_FPDMA_AUX,
+	.pio_mask = ATA_PIO4,
+	.mwdma_mask = ATA_MWDMA2,
+	.udma_mask = ATA_UDMA6,
+	.port_ops = &sas_sata_ops
+};
+
 int sas_ata_init(struct domain_device *found_dev)
 {
 	struct sas_ha_struct *ha = found_dev->port->ha;
@@ -588,25 +597,18 @@ int sas_ata_init(struct domain_device *found_dev)
 
 	ata_host_init(ata_host, ha->dev, &sas_sata_ops);
 
-	ap = ata_port_alloc(ata_host);
+	ap = ata_sas_port_alloc(ata_host, &sata_port_info, shost);
 	if (!ap) {
-		pr_err("ata_port_alloc failed.\n");
+		pr_err("ata_sas_port_alloc failed.\n");
 		rc = -ENODEV;
 		goto free_host;
 	}
 
-	ap->port_no = 0;
-	ap->pio_mask = ATA_PIO4;
-	ap->mwdma_mask = ATA_MWDMA2;
-	ap->udma_mask = ATA_UDMA6;
-	ap->flags |= ATA_FLAG_SATA | ATA_FLAG_PIO_DMA | ATA_FLAG_NCQ |
-		     ATA_FLAG_SAS_HOST | ATA_FLAG_FPDMA_AUX;
-	ap->ops = &sas_sata_ops;
 	ap->private_data = found_dev;
 	ap->cbl = ATA_CBL_SATA;
 	ap->scsi_host = shost;
 
-	rc = ata_tport_add(ata_host->dev, ap);
+	rc = ata_sas_tport_add(ata_host->dev, ap);
 	if (rc)
 		goto free_port;
 
diff --git a/drivers/scsi/libsas/sas_discover.c b/drivers/scsi/libsas/sas_discover.c
index 951bdc554a10..48d975c6dbf2 100644
--- a/drivers/scsi/libsas/sas_discover.c
+++ b/drivers/scsi/libsas/sas_discover.c
@@ -300,7 +300,7 @@ void sas_free_device(struct kref *kref)
 		kfree(dev->ex_dev.ex_phy);
 
 	if (dev_is_sata(dev) && dev->sata_dev.ap) {
-		ata_tport_delete(dev->sata_dev.ap);
+		ata_sas_tport_delete(dev->sata_dev.ap);
 		ata_port_free(dev->sata_dev.ap);
 		ata_host_put(dev->sata_dev.ata_host);
 		dev->sata_dev.ata_host = NULL;
diff --git a/drivers/scsi/lpfc/lpfc_attr.c b/drivers/scsi/lpfc/lpfc_attr.c
index 39b504164ecc..a46c73e8d7c4 100644
--- a/drivers/scsi/lpfc/lpfc_attr.c
+++ b/drivers/scsi/lpfc/lpfc_attr.c
@@ -1831,7 +1831,6 @@ static int
 lpfc_set_trunking(struct lpfc_hba *phba, char *buff_out)
 {
 	LPFC_MBOXQ_t *mbox = NULL;
-	u32 payload_len;
 	unsigned long val = 0;
 	char *pval = NULL;
 	int rc = 0;
@@ -1870,11 +1869,9 @@ lpfc_set_trunking(struct lpfc_hba *phba, char *buff_out)
 	if (!mbox)
 		return -ENOMEM;
 
-	payload_len = sizeof(struct lpfc_mbx_set_trunk_mode) -
-		      sizeof(struct lpfc_sli4_cfg_mhdr);
 	lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
 			 LPFC_MBOX_OPCODE_FCOE_FC_SET_TRUNK_MODE,
-			 payload_len, LPFC_SLI4_MBX_EMBED);
+			 12, LPFC_SLI4_MBX_EMBED);
 
 	bf_set(lpfc_mbx_set_trunk_mode,
 	       &mbox->u.mqe.un.set_trunk_mode,
@@ -1910,11 +1907,6 @@ lpfc_xcvr_data_show(struct device *dev, struct device_attribute *attr,
 
 	/* Get transceiver information */
 	rdp_context = kmalloc(sizeof(*rdp_context), GFP_KERNEL);
-	if (!rdp_context) {
-		len = scnprintf(buf, PAGE_SIZE - len,
-				"SPF info NA: alloc failure\n");
-		return len;
-	}
 
 	rc = lpfc_get_sfp_info_wait(phba, rdp_context);
 	if (rc) {
diff --git a/drivers/scsi/lpfc/lpfc_ct.c b/drivers/scsi/lpfc/lpfc_ct.c
index 2dedd1493e5b..376d0f958b72 100644
--- a/drivers/scsi/lpfc/lpfc_ct.c
+++ b/drivers/scsi/lpfc/lpfc_ct.c
@@ -1553,14 +1553,22 @@ lpfc_cmpl_ct_cmd_gft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
 			if (ndlp->nlp_state == NLP_STE_REG_LOGIN_ISSUE &&
 			    ndlp->nlp_fc4_type) {
 				ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
-				lpfc_nlp_set_state(vport, ndlp,
-						   NLP_STE_PRLI_ISSUE);
-				lpfc_issue_els_prli(vport, ndlp, 0);
+				/* This is a fabric topology so if discovery
+				 * started with an unsolicited PLOGI, don't
+				 * send a PRLI.  Targets don't issue PLOGI or
+				 * PRLI when acting as a target. Likely this is
+				 * an initiator function.
+				 */
+				if (!(ndlp->nlp_flag & NLP_RCV_PLOGI)) {
+					lpfc_nlp_set_state(vport, ndlp,
+							   NLP_STE_PRLI_ISSUE);
+					lpfc_issue_els_prli(vport, ndlp, 0);
+				}
 			} else if (!ndlp->nlp_fc4_type) {
 				/* If fc4 type is still unknown, then LOGO */
 				lpfc_printf_vlog(vport, KERN_INFO,
 						 LOG_DISCOVERY | LOG_NODE,
-						 "6443 Sending LOGO ndlp x%px, "
+						 "6443 Sending LOGO ndlp x%px,"
 						 "DID x%06x with fc4_type: "
 						 "x%08x, state: %d\n",
 						 ndlp, did, ndlp->nlp_fc4_type,
diff --git a/drivers/scsi/lpfc/lpfc_els.c b/drivers/scsi/lpfc/lpfc_els.c
index 929cbfc95163..c32bc773ab29 100644
--- a/drivers/scsi/lpfc/lpfc_els.c
+++ b/drivers/scsi/lpfc/lpfc_els.c
@@ -7302,13 +7302,13 @@ int lpfc_get_sfp_info_wait(struct lpfc_hba *phba,
 		mbox->u.mqe.un.mem_dump_type3.addr_hi = putPaddrHigh(mp->phys);
 	}
 	mbox->vport = phba->pport;
-	rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_SLI4_CONFIG_TMO);
+
+	rc = lpfc_sli_issue_mbox_wait(phba, mbox, 30);
 	if (rc == MBX_NOT_FINISHED) {
 		rc = 1;
 		goto error;
 	}
-	if (rc == MBX_TIMEOUT)
-		goto error;
+
 	if (phba->sli_rev == LPFC_SLI_REV4)
 		mp = mbox->ctx_buf;
 	else
@@ -7361,10 +7361,7 @@ int lpfc_get_sfp_info_wait(struct lpfc_hba *phba,
 		mbox->u.mqe.un.mem_dump_type3.addr_hi = putPaddrHigh(mp->phys);
 	}
 
-	rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_SLI4_CONFIG_TMO);
-
-	if (rc == MBX_TIMEOUT)
-		goto error;
+	rc = lpfc_sli_issue_mbox_wait(phba, mbox, 30);
 	if (bf_get(lpfc_mqe_status, &mbox->u.mqe)) {
 		rc = 1;
 		goto error;
@@ -7375,10 +7372,8 @@ int lpfc_get_sfp_info_wait(struct lpfc_hba *phba,
 			     DMP_SFF_PAGE_A2_SIZE);
 
 error:
-	if (mbox->mbox_flag & LPFC_MBX_WAKE) {
-		mbox->ctx_buf = mpsave;
-		lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED);
-	}
+	mbox->ctx_buf = mpsave;
+	lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED);
 
 	return rc;
 
@@ -9670,7 +9665,7 @@ lpfc_els_flush_cmd(struct lpfc_vport *vport)
 	list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
 		spin_lock_irqsave(&phba->hbalock, iflags);
 		list_del_init(&piocb->dlist);
-		if (mbx_tmo_err || !(phba->sli.sli_flag & LPFC_SLI_ACTIVE))
+		if (mbx_tmo_err)
 			list_move_tail(&piocb->list, &cancel_list);
 		else
 			lpfc_sli_issue_abort_iotag(phba, pring, piocb, NULL);
diff --git a/drivers/scsi/lpfc/lpfc_hbadisc.c b/drivers/scsi/lpfc/lpfc_hbadisc.c
index 6943f6c6395c..153770bdc56a 100644
--- a/drivers/scsi/lpfc/lpfc_hbadisc.c
+++ b/drivers/scsi/lpfc/lpfc_hbadisc.c
@@ -214,11 +214,6 @@ lpfc_dev_loss_tmo_callbk(struct fc_rport *rport)
 	if (ndlp->nlp_state == NLP_STE_MAPPED_NODE)
 		return;
 
-	/* check for recovered fabric node */
-	if (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE &&
-	    ndlp->nlp_DID == Fabric_DID)
-		return;
-
 	if (rport->port_name != wwn_to_u64(ndlp->nlp_portname.u.wwn))
 		lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
 				 "6789 rport name %llx != node port name %llx",
@@ -551,9 +546,6 @@ lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp)
 					 ndlp->nlp_DID, kref_read(&ndlp->kref),
 					 ndlp, ndlp->nlp_flag,
 					 vport->port_state);
-			spin_lock_irqsave(&ndlp->lock, iflags);
-			ndlp->nlp_flag &= ~NLP_IN_DEV_LOSS;
-			spin_unlock_irqrestore(&ndlp->lock, iflags);
 			return fcf_inuse;
 		}
 
@@ -5733,7 +5725,7 @@ lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did)
 				return ndlp;
 
 			if (ndlp->nlp_state > NLP_STE_UNUSED_NODE &&
-			    ndlp->nlp_state <= NLP_STE_PRLI_ISSUE) {
+			    ndlp->nlp_state < NLP_STE_PRLI_ISSUE) {
 				lpfc_disc_state_machine(vport, ndlp, NULL,
 							NLP_EVT_DEVICE_RECOVERY);
 			}
diff --git a/drivers/scsi/lpfc/lpfc_nvmet.c b/drivers/scsi/lpfc/lpfc_nvmet.c
index 0cef5d089f34..5297cacc8beb 100644
--- a/drivers/scsi/lpfc/lpfc_nvmet.c
+++ b/drivers/scsi/lpfc/lpfc_nvmet.c
@@ -1363,16 +1363,6 @@ lpfc_nvmet_ls_abort(struct nvmet_fc_target_port *targetport,
 		atomic_inc(&lpfc_nvmet->xmt_ls_abort);
 }
 
-static int
-lpfc_nvmet_host_traddr(void *hosthandle, u64 *wwnn, u64 *wwpn)
-{
-	struct lpfc_nodelist *ndlp = hosthandle;
-
-	*wwnn = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
-	*wwpn = wwn_to_u64(ndlp->nlp_portname.u.wwn);
-	return 0;
-}
-
 static void
 lpfc_nvmet_host_release(void *hosthandle)
 {
@@ -1423,7 +1413,6 @@ static struct nvmet_fc_target_template lpfc_tgttemplate = {
 	.ls_req         = lpfc_nvmet_ls_req,
 	.ls_abort       = lpfc_nvmet_ls_abort,
 	.host_release   = lpfc_nvmet_host_release,
-	.host_traddr    = lpfc_nvmet_host_traddr,
 
 	.max_hw_queues  = 1,
 	.max_sgl_segments = LPFC_NVMET_DEFAULT_SEGS,
diff --git a/drivers/scsi/lpfc/lpfc_sli.c b/drivers/scsi/lpfc/lpfc_sli.c
index 88debef2fb6d..f475e7ece41a 100644
--- a/drivers/scsi/lpfc/lpfc_sli.c
+++ b/drivers/scsi/lpfc/lpfc_sli.c
@@ -10579,11 +10579,10 @@ lpfc_prep_embed_io(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd)
 {
 	struct lpfc_iocbq *piocb = &lpfc_cmd->cur_iocbq;
 	union lpfc_wqe128 *wqe = &lpfc_cmd->cur_iocbq.wqe;
-	struct sli4_sge_le *sgl;
-	u32 type_size;
+	struct sli4_sge *sgl;
 
 	/* 128 byte wqe support here */
-	sgl = (struct sli4_sge_le *)lpfc_cmd->dma_sgl;
+	sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl;
 
 	if (phba->fcp_embed_io) {
 		struct fcp_cmnd *fcp_cmnd;
@@ -10592,9 +10591,9 @@ lpfc_prep_embed_io(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd)
 		fcp_cmnd = lpfc_cmd->fcp_cmnd;
 
 		/* Word 0-2 - FCP_CMND */
-		type_size = le32_to_cpu(sgl->sge_len);
-		type_size |= ULP_BDE64_TYPE_BDE_IMMED;
-		wqe->generic.bde.tus.w = type_size;
+		wqe->generic.bde.tus.f.bdeFlags =
+			BUFF_TYPE_BDE_IMMED;
+		wqe->generic.bde.tus.f.bdeSize = sgl->sge_len;
 		wqe->generic.bde.addrHigh = 0;
 		wqe->generic.bde.addrLow =  72;  /* Word 18 */
 
@@ -10603,13 +10602,13 @@ lpfc_prep_embed_io(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd)
 
 		/* Word 18-29  FCP CMND Payload */
 		ptr = &wqe->words[18];
-		lpfc_sli_pcimem_bcopy(fcp_cmnd, ptr, le32_to_cpu(sgl->sge_len));
+		memcpy(ptr, fcp_cmnd, sgl->sge_len);
 	} else {
 		/* Word 0-2 - Inline BDE */
 		wqe->generic.bde.tus.f.bdeFlags =  BUFF_TYPE_BDE_64;
-		wqe->generic.bde.tus.f.bdeSize = le32_to_cpu(sgl->sge_len);
-		wqe->generic.bde.addrHigh = le32_to_cpu(sgl->addr_hi);
-		wqe->generic.bde.addrLow = le32_to_cpu(sgl->addr_lo);
+		wqe->generic.bde.tus.f.bdeSize = sgl->sge_len;
+		wqe->generic.bde.addrHigh = sgl->addr_hi;
+		wqe->generic.bde.addrLow =  sgl->addr_lo;
 
 		/* Word 10 */
 		bf_set(wqe_dbde, &wqe->generic.wqe_com, 1);
@@ -12302,16 +12301,18 @@ lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
 				goto release_iocb;
 			}
 		}
-	}
 
-	lpfc_printf_log(phba, KERN_INFO, LOG_ELS | LOG_SLI,
-			"0327 Abort els iocb complete x%px with io cmd xri %x "
-			"abort tag x%x abort status %x abort code %x\n",
-			cmdiocb, get_job_abtsiotag(phba, cmdiocb),
-			(phba->sli_rev == LPFC_SLI_REV4) ?
-			get_wqe_reqtag(cmdiocb) :
-			cmdiocb->iocb.ulpIoTag,
-			ulp_status, ulp_word4);
+		lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI,
+				"0327 Cannot abort els iocb x%px "
+				"with io cmd xri %x abort tag : x%x, "
+				"abort status %x abort code %x\n",
+				cmdiocb, get_job_abtsiotag(phba, cmdiocb),
+				(phba->sli_rev == LPFC_SLI_REV4) ?
+				get_wqe_reqtag(cmdiocb) :
+				cmdiocb->iocb.un.acxri.abortContextTag,
+				ulp_status, ulp_word4);
+
+	}
 release_iocb:
 	lpfc_sli_release_iocbq(phba, cmdiocb);
 	return;
@@ -12508,10 +12509,10 @@ lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
 	lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
 			 "0339 Abort IO XRI x%x, Original iotag x%x, "
 			 "abort tag x%x Cmdjob : x%px Abortjob : x%px "
-			 "retval x%x : IA %d cmd_cmpl %ps\n",
+			 "retval x%x : IA %d\n",
 			 ulp_context, (phba->sli_rev == LPFC_SLI_REV4) ?
 			 cmdiocb->iotag : iotag, iotag, cmdiocb, abtsiocbp,
-			 retval, ia, abtsiocbp->cmd_cmpl);
+			 retval, ia);
 	if (retval) {
 		cmdiocb->cmd_flag &= ~LPFC_DRIVER_ABORTED;
 		__lpfc_sli_release_iocbq(phba, abtsiocbp);
diff --git a/drivers/scsi/lpfc/lpfc_version.h b/drivers/scsi/lpfc/lpfc_version.h
index 7ac9ef281881..f06087e47859 100644
--- a/drivers/scsi/lpfc/lpfc_version.h
+++ b/drivers/scsi/lpfc/lpfc_version.h
@@ -20,7 +20,7 @@
  * included with this package.                                     *
  *******************************************************************/
 
-#define LPFC_DRIVER_VERSION "14.4.0.3"
+#define LPFC_DRIVER_VERSION "14.4.0.2"
 #define LPFC_DRIVER_NAME		"lpfc"
 
 /* Used for SLI 2/3 */
diff --git a/drivers/scsi/mac_scsi.c b/drivers/scsi/mac_scsi.c
index 53ee8f84d094..a402c4dc4645 100644
--- a/drivers/scsi/mac_scsi.c
+++ b/drivers/scsi/mac_scsi.c
@@ -550,5 +550,4 @@ static struct platform_driver mac_scsi_driver __refdata = {
 module_platform_driver_probe(mac_scsi_driver, mac_scsi_probe);
 
 MODULE_ALIAS("platform:" DRV_MODULE_NAME);
-MODULE_DESCRIPTION("Macintosh NCR5380 SCSI driver");
 MODULE_LICENSE("GPL");
diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
index 6c79c350a4d5..88acefbf9aea 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -1981,6 +1981,8 @@ megasas_set_nvme_device_properties(struct scsi_device *sdev,
 
 	lim->max_hw_sectors = max_io_size / 512;
 	lim->virt_boundary_mask = mr_nvme_pg_size - 1;
+
+	blk_queue_flag_set(QUEUE_FLAG_NOMERGES, sdev->request_queue);
 }
 
 /*
diff --git a/drivers/scsi/mpi3mr/mpi/mpi30_tool.h b/drivers/scsi/mpi3mr/mpi/mpi30_tool.h
deleted file mode 100644
index 3b960893870f..000000000000
--- a/drivers/scsi/mpi3mr/mpi/mpi30_tool.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-/*
- *  Copyright 2016-2024 Broadcom Inc. All rights reserved.
- */
-#ifndef MPI30_TOOL_H
-#define MPI30_TOOL_H     1
-
-#define MPI3_DIAG_BUFFER_TYPE_TRACE	(0x01)
-#define MPI3_DIAG_BUFFER_TYPE_FW	(0x02)
-#define MPI3_DIAG_BUFFER_ACTION_RELEASE	(0x01)
-
-struct mpi3_diag_buffer_post_request {
-	__le16                     host_tag;
-	u8                         ioc_use_only02;
-	u8                         function;
-	__le16                     ioc_use_only04;
-	u8                         ioc_use_only06;
-	u8                         msg_flags;
-	__le16                     change_count;
-	__le16                     reserved0a;
-	u8                         type;
-	u8                         reserved0d;
-	__le16                     reserved0e;
-	__le64                     address;
-	__le32                     length;
-	__le32                     reserved1c;
-};
-
-struct mpi3_diag_buffer_manage_request {
-	__le16                     host_tag;
-	u8                         ioc_use_only02;
-	u8                         function;
-	__le16                     ioc_use_only04;
-	u8                         ioc_use_only06;
-	u8                         msg_flags;
-	__le16                     change_count;
-	__le16                     reserved0a;
-	u8                         type;
-	u8                         action;
-	__le16                     reserved0e;
-};
-
-
-#endif
diff --git a/drivers/scsi/mpi3mr/mpi3mr.h b/drivers/scsi/mpi3mr/mpi3mr.h
index dc2cdd5f0311..f5a1529fa537 100644
--- a/drivers/scsi/mpi3mr/mpi3mr.h
+++ b/drivers/scsi/mpi3mr/mpi3mr.h
@@ -23,7 +23,6 @@
 #include <linux/miscdevice.h>
 #include <linux/module.h>
 #include <linux/pci.h>
-#include <linux/aer.h>
 #include <linux/poll.h>
 #include <linux/sched.h>
 #include <linux/slab.h>
@@ -48,7 +47,6 @@
 #include "mpi/mpi30_ioc.h"
 #include "mpi/mpi30_sas.h"
 #include "mpi/mpi30_pci.h"
-#include "mpi/mpi30_tool.h"
 #include "mpi3mr_debug.h"
 
 /* Global list and lock for storing multiple adapters managed by the driver */
@@ -57,8 +55,8 @@ extern struct list_head mrioc_list;
 extern int prot_mask;
 extern atomic64_t event_counter;
 
-#define MPI3MR_DRIVER_VERSION	"8.9.1.0.51"
-#define MPI3MR_DRIVER_RELDATE	"29-May-2024"
+#define MPI3MR_DRIVER_VERSION	"8.8.1.0.50"
+#define MPI3MR_DRIVER_RELDATE	"5-March-2024"
 
 #define MPI3MR_DRIVER_NAME	"mpi3mr"
 #define MPI3MR_DRIVER_LICENSE	"GPL"
@@ -130,7 +128,6 @@ extern atomic64_t event_counter;
 #define MPI3MR_PREPARE_FOR_RESET_TIMEOUT	180
 #define MPI3MR_RESET_ACK_TIMEOUT		30
 #define MPI3MR_MUR_TIMEOUT			120
-#define MPI3MR_RESET_TIMEOUT			510
 
 #define MPI3MR_WATCHDOG_INTERVAL		1000 /* in milli seconds */
 
@@ -190,30 +187,6 @@ extern atomic64_t event_counter;
 #define MPI3MR_HARD_SECURE_DEVICE		0x08
 #define MPI3MR_TAMPERED_DEVICE			0x0C
 
-#define MPI3MR_DEFAULT_HDB_MAX_SZ       (4 * 1024 * 1024)
-#define MPI3MR_DEFAULT_HDB_DEC_SZ       (1 * 1024 * 1024)
-#define MPI3MR_DEFAULT_HDB_MIN_SZ       (2 * 1024 * 1024)
-#define MPI3MR_MAX_NUM_HDB      2
-
-#define MPI3MR_HDB_TRIGGER_TYPE_UNKNOWN		0
-#define MPI3MR_HDB_TRIGGER_TYPE_FAULT		1
-#define MPI3MR_HDB_TRIGGER_TYPE_ELEMENT		2
-#define MPI3MR_HDB_TRIGGER_TYPE_GLOBAL          3
-#define MPI3MR_HDB_TRIGGER_TYPE_SOFT_RESET	4
-#define MPI3MR_HDB_TRIGGER_TYPE_FW_RELEASED	5
-
-#define MPI3MR_HDB_REFRESH_TYPE_RESERVED       0
-#define MPI3MR_HDB_REFRESH_TYPE_CURRENT                1
-#define MPI3MR_HDB_REFRESH_TYPE_DEFAULT                2
-#define MPI3MR_HDB_HDB_REFRESH_TYPE_PERSISTENT 3
-
-#define MPI3MR_DEFAULT_HDB_SZ  (4 * 1024 * 1024)
-#define MPI3MR_MAX_NUM_HDB     2
-
-#define MPI3MR_HDB_QUERY_ELEMENT_TRIGGER_FORMAT_INDEX   0
-#define MPI3MR_HDB_QUERY_ELEMENT_TRIGGER_FORMAT_DATA    1
-
-
 /* SGE Flag definition */
 #define MPI3MR_SGEFLAGS_SYSTEM_SIMPLE_END_OF_LIST \
 	(MPI3_SGE_FLAGS_ELEMENT_TYPE_SIMPLE | MPI3_SGE_FLAGS_DLAS_SYSTEM | \
@@ -237,8 +210,6 @@ extern atomic64_t event_counter;
 #define MPI3MR_WRITE_SAME_MAX_LEN_256_BLKS 256
 #define MPI3MR_WRITE_SAME_MAX_LEN_2048_BLKS 2048
 
-#define MPI3MR_DRIVER_EVENT_PROCESS_TRIGGER    (0xFFFD)
-
 /**
  * struct mpi3mr_nvme_pt_sge -  Structure to store SGEs for NVMe
  * Encapsulated commands.
@@ -318,12 +289,9 @@ enum mpi3mr_reset_reason {
 	MPI3MR_RESET_FROM_PELABORT_TIMEOUT = 22,
 	MPI3MR_RESET_FROM_SYSFS = 23,
 	MPI3MR_RESET_FROM_SYSFS_TIMEOUT = 24,
-	MPI3MR_RESET_FROM_DIAG_BUFFER_POST_TIMEOUT = 25,
-	MPI3MR_RESET_FROM_DIAG_BUFFER_RELEASE_TIMEOUT = 26,
 	MPI3MR_RESET_FROM_FIRMWARE = 27,
 	MPI3MR_RESET_FROM_CFG_REQ_TIMEOUT = 29,
 	MPI3MR_RESET_FROM_SAS_TRANSPORT_TIMEOUT = 30,
-	MPI3MR_RESET_FROM_TRIGGER = 31,
 };
 
 #define MPI3MR_RESET_REASON_OSTYPE_LINUX	1
@@ -359,9 +327,6 @@ struct mpi3mr_ioc_facts {
 	u32 ioc_capabilities;
 	struct mpi3mr_compimg_ver fw_ver;
 	u32 mpi_version;
-	u32 diag_trace_sz;
-	u32 diag_fw_sz;
-	u32 diag_drvr_sz;
 	u16 max_reqs;
 	u16 product_id;
 	u16 op_req_sz;
@@ -519,7 +484,6 @@ struct mpi3mr_throttle_group_info {
 
 /* HBA port flags */
 #define MPI3MR_HBA_PORT_FLAG_DIRTY	0x01
-#define MPI3MR_HBA_PORT_FLAG_NEW       0x02
 
 /* IOCTL data transfer sge*/
 #define MPI3MR_NUM_IOCTL_SGE		256
@@ -888,59 +852,6 @@ struct mpi3mr_drv_cmd {
 	    struct mpi3mr_drv_cmd *drv_cmd);
 };
 
-/**
- * union mpi3mr_trigger_data - Trigger data information
- * @fault: Fault code
- * @global: Global trigger data
- * @element: element trigger data
- */
-union mpi3mr_trigger_data {
-	u16 fault;
-	u64 global;
-	union mpi3_driver2_trigger_element element;
-};
-
-/**
- * struct trigger_event_data - store trigger related
- * information.
- *
- * @trace_hdb: Trace diag buffer descriptor reference
- * @fw_hdb: FW diag buffer descriptor reference
- * @trigger_type: Trigger type
- * @trigger_specific_data: Trigger specific data
- * @snapdump: Snapdump enable or disable flag
- */
-struct trigger_event_data {
-	struct diag_buffer_desc *trace_hdb;
-	struct diag_buffer_desc *fw_hdb;
-	u8 trigger_type;
-	union mpi3mr_trigger_data trigger_specific_data;
-	bool snapdump;
-};
-
-/**
- * struct diag_buffer_desc - memory descriptor structure to
- * store virtual, dma addresses, size, buffer status for host
- * diagnostic buffers.
- *
- * @type: Buffer type
- * @trigger_data: Trigger data
- * @trigger_type: Trigger type
- * @status: Buffer status
- * @size: Buffer size
- * @addr: Virtual address
- * @dma_addr: Buffer DMA address
- */
-struct diag_buffer_desc {
-	u8 type;
-	union mpi3mr_trigger_data trigger_data;
-	u8 trigger_type;
-	u8 status;
-	u32 size;
-	void *addr;
-	dma_addr_t dma_addr;
-};
-
 /**
  * struct dma_memory_desc - memory descriptor structure to store
  * virtual address, dma address and size for any generic dma
@@ -1143,21 +1054,11 @@ struct scmd_priv {
  * @sas_node_lock: Lock to protect SAS node list
  * @hba_port_table_list: List of HBA Ports
  * @enclosure_list: List of Enclosure objects
- * @diag_buffers: Host diagnostic buffers
- * @driver_pg2:  Driver page 2 pointer
- * @reply_trigger_present: Reply trigger present flag
- * @event_trigger_present: Event trigger present flag
- * @scsisense_trigger_present: Scsi sense trigger present flag
  * @ioctl_dma_pool: DMA pool for IOCTL data buffers
  * @ioctl_sge: DMA buffer descriptors for IOCTL data
  * @ioctl_chain_sge: DMA buffer descriptor for IOCTL chain
  * @ioctl_resp_sge: DMA buffer descriptor for Mgmt cmd response
  * @ioctl_sges_allocated: Flag for IOCTL SGEs allocated or not
- * @trace_release_trigger_active: Trace trigger active flag
- * @fw_release_trigger_active: Fw release trigger active flag
- * @snapdump_trigger_active: Snapdump trigger active flag
- * @pci_err_recovery: PCI error recovery in progress
- * @block_on_pci_err: Block IO during PCI error recovery
  */
 struct mpi3mr_ioc {
 	struct list_head list;
@@ -1349,17 +1250,6 @@ struct mpi3mr_ioc {
 	struct dma_memory_desc ioctl_chain_sge;
 	struct dma_memory_desc ioctl_resp_sge;
 	bool ioctl_sges_allocated;
-	bool reply_trigger_present;
-	bool event_trigger_present;
-	bool scsisense_trigger_present;
-	struct diag_buffer_desc diag_buffers[MPI3MR_MAX_NUM_HDB];
-	struct mpi3_driver_page2 *driver_pg2;
-	spinlock_t trigger_lock;
-	bool snapdump_trigger_active;
-	bool trace_release_trigger_active;
-	bool fw_release_trigger_active;
-	bool pci_err_recovery;
-	bool block_on_pci_err;
 };
 
 /**
@@ -1516,8 +1406,6 @@ int mpi3mr_cfg_set_sas_io_unit_pg1(struct mpi3mr_ioc *mrioc,
 	struct mpi3_sas_io_unit_page1 *sas_io_unit_pg1, u16 pg_sz);
 int mpi3mr_cfg_get_driver_pg1(struct mpi3mr_ioc *mrioc,
 	struct mpi3_driver_page1 *driver_pg1, u16 pg_sz);
-int mpi3mr_cfg_get_driver_pg2(struct mpi3mr_ioc *mrioc,
-	struct mpi3_driver_page2 *driver_pg2, u16 pg_sz, u8 page_type);
 
 u8 mpi3mr_is_expander_device(u16 device_info);
 int mpi3mr_expander_add(struct mpi3mr_ioc *mrioc, u16 handle);
@@ -1551,28 +1439,4 @@ void mpi3mr_free_enclosure_list(struct mpi3mr_ioc *mrioc);
 int mpi3mr_process_admin_reply_q(struct mpi3mr_ioc *mrioc);
 void mpi3mr_expander_node_remove(struct mpi3mr_ioc *mrioc,
 	struct mpi3mr_sas_node *sas_expander);
-void mpi3mr_alloc_diag_bufs(struct mpi3mr_ioc *mrioc);
-int mpi3mr_post_diag_bufs(struct mpi3mr_ioc *mrioc);
-int mpi3mr_issue_diag_buf_release(struct mpi3mr_ioc *mrioc,
-	struct diag_buffer_desc *diag_buffer);
-void mpi3mr_release_diag_bufs(struct mpi3mr_ioc *mrioc, u8 skip_rel_action);
-void mpi3mr_set_trigger_data_in_hdb(struct diag_buffer_desc *hdb,
-	u8 type, union mpi3mr_trigger_data *trigger_data, bool force);
-int mpi3mr_refresh_trigger(struct mpi3mr_ioc *mrioc, u8 page_type);
-struct diag_buffer_desc *mpi3mr_diag_buffer_for_type(struct mpi3mr_ioc *mrioc,
-	u8 buf_type);
-int mpi3mr_issue_diag_buf_post(struct mpi3mr_ioc *mrioc,
-	struct diag_buffer_desc *diag_buffer);
-void mpi3mr_set_trigger_data_in_all_hdb(struct mpi3mr_ioc *mrioc,
-	u8 type, union mpi3mr_trigger_data *trigger_data, bool force);
-void mpi3mr_reply_trigger(struct mpi3mr_ioc *mrioc, u16 iocstatus,
-	u32 iocloginfo);
-void mpi3mr_hdb_trigger_data_event(struct mpi3mr_ioc *mrioc,
-	struct trigger_event_data *event_data);
-void mpi3mr_scsisense_trigger(struct mpi3mr_ioc *mrioc, u8 senseky, u8 asc,
-	u8 ascq);
-void mpi3mr_event_trigger(struct mpi3mr_ioc *mrioc, u8 event);
-void mpi3mr_global_trigger(struct mpi3mr_ioc *mrioc, u64 trigger_data);
-void mpi3mr_hdbstatuschg_evt_th(struct mpi3mr_ioc *mrioc,
-	struct mpi3_event_notification_reply *event_reply);
 #endif /*MPI3MR_H_INCLUDED*/
diff --git a/drivers/scsi/mpi3mr/mpi3mr_app.c b/drivers/scsi/mpi3mr/mpi3mr_app.c
index 8b0eded6ef36..cd261b48eb46 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_app.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_app.c
@@ -11,821 +11,6 @@
 #include <linux/bsg-lib.h>
 #include <uapi/scsi/scsi_bsg_mpi3mr.h>
 
-/**
- * mpi3mr_alloc_trace_buffer:	Allocate trace buffer
- * @mrioc: Adapter instance reference
- * @trace_size: Trace buffer size
- *
- * Allocate trace buffer
- * Return: 0 on success, non-zero on failure.
- */
-static int mpi3mr_alloc_trace_buffer(struct mpi3mr_ioc *mrioc, u32 trace_size)
-{
-	struct diag_buffer_desc *diag_buffer = &mrioc->diag_buffers[0];
-
-	diag_buffer->addr = dma_alloc_coherent(&mrioc->pdev->dev,
-	    trace_size, &diag_buffer->dma_addr, GFP_KERNEL);
-	if (diag_buffer->addr) {
-		dprint_init(mrioc, "trace diag buffer is allocated successfully\n");
-		return 0;
-	}
-	return -1;
-}
-
-/**
- * mpi3mr_alloc_diag_bufs - Allocate memory for diag buffers
- * @mrioc: Adapter instance reference
- *
- * This functions checks whether the driver defined buffer sizes
- * are greater than IOCFacts provided controller local buffer
- * sizes and if the driver defined sizes are more then the
- * driver allocates the specific buffer by reading driver page1
- *
- * Return: Nothing.
- */
-void mpi3mr_alloc_diag_bufs(struct mpi3mr_ioc *mrioc)
-{
-	struct diag_buffer_desc *diag_buffer;
-	struct mpi3_driver_page1 driver_pg1;
-	u32 trace_dec_size, trace_min_size, fw_dec_size, fw_min_size,
-		trace_size, fw_size;
-	u16 pg_sz = sizeof(driver_pg1);
-	int retval = 0;
-	bool retry = false;
-
-	if (mrioc->diag_buffers[0].addr || mrioc->diag_buffers[1].addr)
-		return;
-
-	retval = mpi3mr_cfg_get_driver_pg1(mrioc, &driver_pg1, pg_sz);
-	if (retval) {
-		ioc_warn(mrioc,
-		    "%s: driver page 1 read failed, allocating trace\n"
-		    "and firmware diag buffers of default size\n", __func__);
-		trace_size = fw_size = MPI3MR_DEFAULT_HDB_MAX_SZ;
-		trace_dec_size = fw_dec_size = MPI3MR_DEFAULT_HDB_DEC_SZ;
-		trace_min_size = fw_min_size = MPI3MR_DEFAULT_HDB_MIN_SZ;
-
-	} else {
-		trace_size = driver_pg1.host_diag_trace_max_size * 1024;
-		trace_dec_size = driver_pg1.host_diag_trace_decrement_size
-			 * 1024;
-		trace_min_size = driver_pg1.host_diag_trace_min_size * 1024;
-		fw_size = driver_pg1.host_diag_fw_max_size * 1024;
-		fw_dec_size = driver_pg1.host_diag_fw_decrement_size * 1024;
-		fw_min_size = driver_pg1.host_diag_fw_min_size * 1024;
-		dprint_init(mrioc,
-		    "%s:trace diag buffer sizes read from driver\n"
-		    "page1: maximum size = %dKB, decrement size = %dKB\n"
-		    ", minimum size = %dKB\n", __func__, driver_pg1.host_diag_trace_max_size,
-		    driver_pg1.host_diag_trace_decrement_size,
-		    driver_pg1.host_diag_trace_min_size);
-		dprint_init(mrioc,
-		    "%s:firmware diag buffer sizes read from driver\n"
-		    "page1: maximum size = %dKB, decrement size = %dKB\n"
-		    ", minimum size = %dKB\n", __func__, driver_pg1.host_diag_fw_max_size,
-		    driver_pg1.host_diag_fw_decrement_size,
-		    driver_pg1.host_diag_fw_min_size);
-		if ((trace_size == 0) && (fw_size == 0))
-			return;
-	}
-
-
-retry_trace:
-	diag_buffer = &mrioc->diag_buffers[0];
-	diag_buffer->type = MPI3_DIAG_BUFFER_TYPE_TRACE;
-	diag_buffer->status = MPI3MR_HDB_BUFSTATUS_NOT_ALLOCATED;
-	if ((mrioc->facts.diag_trace_sz < trace_size) && (trace_size >=
-		trace_min_size)) {
-		if (!retry)
-			dprint_init(mrioc,
-			    "trying to allocate trace diag buffer of size = %dKB\n",
-			    trace_size / 1024);
-		if (mpi3mr_alloc_trace_buffer(mrioc, trace_size)) {
-			retry = true;
-			trace_size -= trace_dec_size;
-			dprint_init(mrioc, "trace diag buffer allocation failed\n"
-			"retrying smaller size %dKB\n", trace_size / 1024);
-			goto retry_trace;
-		} else
-			diag_buffer->size = trace_size;
-	}
-
-	retry = false;
-retry_fw:
-
-	diag_buffer = &mrioc->diag_buffers[1];
-
-	diag_buffer->type = MPI3_DIAG_BUFFER_TYPE_FW;
-	diag_buffer->status = MPI3MR_HDB_BUFSTATUS_NOT_ALLOCATED;
-	if ((mrioc->facts.diag_fw_sz < fw_size) && (fw_size >= fw_min_size)) {
-		diag_buffer->addr = dma_alloc_coherent(&mrioc->pdev->dev,
-		    fw_size, &diag_buffer->dma_addr, GFP_KERNEL);
-		if (!retry)
-			dprint_init(mrioc,
-			    "%s:trying to allocate firmware diag buffer of size = %dKB\n",
-			    __func__, fw_size / 1024);
-		if (diag_buffer->addr) {
-			dprint_init(mrioc, "%s:firmware diag buffer allocated successfully\n",
-			    __func__);
-			diag_buffer->size = fw_size;
-		} else {
-			retry = true;
-			fw_size -= fw_dec_size;
-			dprint_init(mrioc, "%s:trace diag buffer allocation failed,\n"
-					"retrying smaller size %dKB\n",
-					__func__, fw_size / 1024);
-			goto retry_fw;
-		}
-	}
-}
-
-/**
- * mpi3mr_issue_diag_buf_post - Send diag buffer post req
- * @mrioc: Adapter instance reference
- * @diag_buffer: Diagnostic buffer descriptor
- *
- * Issue diagnostic buffer post MPI request through admin queue
- * and wait for the completion of it or time out.
- *
- * Return: 0 on success, non-zero on failures.
- */
-int mpi3mr_issue_diag_buf_post(struct mpi3mr_ioc *mrioc,
-	struct diag_buffer_desc *diag_buffer)
-{
-	struct mpi3_diag_buffer_post_request diag_buf_post_req;
-	u8 prev_status;
-	int retval = 0;
-
-	memset(&diag_buf_post_req, 0, sizeof(diag_buf_post_req));
-	mutex_lock(&mrioc->init_cmds.mutex);
-	if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
-		dprint_bsg_err(mrioc, "%s: command is in use\n", __func__);
-		mutex_unlock(&mrioc->init_cmds.mutex);
-		return -1;
-	}
-	mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
-	mrioc->init_cmds.is_waiting = 1;
-	mrioc->init_cmds.callback = NULL;
-	diag_buf_post_req.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
-	diag_buf_post_req.function = MPI3_FUNCTION_DIAG_BUFFER_POST;
-	diag_buf_post_req.type = diag_buffer->type;
-	diag_buf_post_req.address = le64_to_cpu(diag_buffer->dma_addr);
-	diag_buf_post_req.length = le32_to_cpu(diag_buffer->size);
-
-	dprint_bsg_info(mrioc, "%s: posting diag buffer type %d\n", __func__,
-	    diag_buffer->type);
-	prev_status = diag_buffer->status;
-	diag_buffer->status = MPI3MR_HDB_BUFSTATUS_POSTED_UNPAUSED;
-	init_completion(&mrioc->init_cmds.done);
-	retval = mpi3mr_admin_request_post(mrioc, &diag_buf_post_req,
-	    sizeof(diag_buf_post_req), 1);
-	if (retval) {
-		dprint_bsg_err(mrioc, "%s: admin request post failed\n",
-		    __func__);
-		goto out_unlock;
-	}
-	wait_for_completion_timeout(&mrioc->init_cmds.done,
-	    (MPI3MR_INTADMCMD_TIMEOUT * HZ));
-	if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
-		mrioc->init_cmds.is_waiting = 0;
-		dprint_bsg_err(mrioc, "%s: command timedout\n", __func__);
-		mpi3mr_check_rh_fault_ioc(mrioc,
-		    MPI3MR_RESET_FROM_DIAG_BUFFER_POST_TIMEOUT);
-		retval = -1;
-		goto out_unlock;
-	}
-	if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
-	    != MPI3_IOCSTATUS_SUCCESS) {
-		dprint_bsg_err(mrioc,
-		    "%s: command failed, buffer_type (%d) ioc_status(0x%04x) log_info(0x%08x)\n",
-		    __func__, diag_buffer->type,
-		    (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
-		    mrioc->init_cmds.ioc_loginfo);
-		retval = -1;
-		goto out_unlock;
-	}
-	dprint_bsg_info(mrioc, "%s: diag buffer type %d posted successfully\n",
-	    __func__, diag_buffer->type);
-
-out_unlock:
-	if (retval)
-		diag_buffer->status = prev_status;
-	mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
-	mutex_unlock(&mrioc->init_cmds.mutex);
-	return retval;
-}
-
-/**
- * mpi3mr_post_diag_bufs - Post diag buffers to the controller
- * @mrioc: Adapter instance reference
- *
- * This function calls helper function to post both trace and
- * firmware buffers to the controller.
- *
- * Return: None
- */
-int mpi3mr_post_diag_bufs(struct mpi3mr_ioc *mrioc)
-{
-	u8 i;
-	struct diag_buffer_desc *diag_buffer;
-
-	for (i = 0; i < MPI3MR_MAX_NUM_HDB; i++) {
-		diag_buffer = &mrioc->diag_buffers[i];
-		if (!(diag_buffer->addr))
-			continue;
-		if (mpi3mr_issue_diag_buf_post(mrioc, diag_buffer))
-			return -1;
-	}
-	return 0;
-}
-
-/**
- * mpi3mr_issue_diag_buf_release - Send diag buffer release req
- * @mrioc: Adapter instance reference
- * @diag_buffer: Diagnostic buffer descriptor
- *
- * Issue diagnostic buffer manage MPI request with release
- * action request through admin queue and wait for the
- * completion of it or time out.
- *
- * Return: 0 on success, non-zero on failures.
- */
-int mpi3mr_issue_diag_buf_release(struct mpi3mr_ioc *mrioc,
-	struct diag_buffer_desc *diag_buffer)
-{
-	struct mpi3_diag_buffer_manage_request diag_buf_manage_req;
-	int retval = 0;
-
-	if ((diag_buffer->status != MPI3MR_HDB_BUFSTATUS_POSTED_UNPAUSED) &&
-	    (diag_buffer->status != MPI3MR_HDB_BUFSTATUS_POSTED_PAUSED))
-		return retval;
-
-	memset(&diag_buf_manage_req, 0, sizeof(diag_buf_manage_req));
-	mutex_lock(&mrioc->init_cmds.mutex);
-	if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
-		dprint_reset(mrioc, "%s: command is in use\n", __func__);
-		mutex_unlock(&mrioc->init_cmds.mutex);
-		return -1;
-	}
-	mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
-	mrioc->init_cmds.is_waiting = 1;
-	mrioc->init_cmds.callback = NULL;
-	diag_buf_manage_req.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
-	diag_buf_manage_req.function = MPI3_FUNCTION_DIAG_BUFFER_MANAGE;
-	diag_buf_manage_req.type = diag_buffer->type;
-	diag_buf_manage_req.action = MPI3_DIAG_BUFFER_ACTION_RELEASE;
-
-
-	dprint_reset(mrioc, "%s: releasing diag buffer type %d\n", __func__,
-	    diag_buffer->type);
-	init_completion(&mrioc->init_cmds.done);
-	retval = mpi3mr_admin_request_post(mrioc, &diag_buf_manage_req,
-	    sizeof(diag_buf_manage_req), 1);
-	if (retval) {
-		dprint_reset(mrioc, "%s: admin request post failed\n", __func__);
-		mpi3mr_set_trigger_data_in_hdb(diag_buffer,
-		    MPI3MR_HDB_TRIGGER_TYPE_UNKNOWN, NULL, 1);
-		goto out_unlock;
-	}
-	wait_for_completion_timeout(&mrioc->init_cmds.done,
-	    (MPI3MR_INTADMCMD_TIMEOUT * HZ));
-	if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
-		mrioc->init_cmds.is_waiting = 0;
-		dprint_reset(mrioc, "%s: command timedout\n", __func__);
-		mpi3mr_check_rh_fault_ioc(mrioc,
-		    MPI3MR_RESET_FROM_DIAG_BUFFER_RELEASE_TIMEOUT);
-		retval = -1;
-		goto out_unlock;
-	}
-	if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
-	    != MPI3_IOCSTATUS_SUCCESS) {
-		dprint_reset(mrioc,
-		    "%s: command failed, buffer_type (%d) ioc_status(0x%04x) log_info(0x%08x)\n",
-		    __func__, diag_buffer->type,
-		    (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
-		    mrioc->init_cmds.ioc_loginfo);
-		retval = -1;
-		goto out_unlock;
-	}
-	dprint_reset(mrioc, "%s: diag buffer type %d released successfully\n",
-	    __func__, diag_buffer->type);
-
-out_unlock:
-	mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
-	mutex_unlock(&mrioc->init_cmds.mutex);
-	return retval;
-}
-
-/**
- * mpi3mr_process_trigger - Generic HDB Trigger handler
- * @mrioc: Adapter instance reference
- * @trigger_type: Trigger type
- * @trigger_data: Trigger data
- * @trigger_flags: Trigger flags
- *
- * This function checks validity of HDB, triggers and based on
- * trigger information, creates an event to be processed in the
- * firmware event worker thread .
- *
- * This function should be called with trigger spinlock held
- *
- * Return: Nothing
- */
-static void mpi3mr_process_trigger(struct mpi3mr_ioc *mrioc, u8 trigger_type,
-	union mpi3mr_trigger_data *trigger_data, u8 trigger_flags)
-{
-	struct trigger_event_data event_data;
-	struct diag_buffer_desc *trace_hdb = NULL;
-	struct diag_buffer_desc *fw_hdb = NULL;
-	u64 global_trigger;
-
-	trace_hdb = mpi3mr_diag_buffer_for_type(mrioc,
-	    MPI3_DIAG_BUFFER_TYPE_TRACE);
-	if (trace_hdb &&
-	    (trace_hdb->status != MPI3MR_HDB_BUFSTATUS_POSTED_UNPAUSED) &&
-	    (trace_hdb->status != MPI3MR_HDB_BUFSTATUS_POSTED_PAUSED))
-		trace_hdb =  NULL;
-
-	fw_hdb = mpi3mr_diag_buffer_for_type(mrioc, MPI3_DIAG_BUFFER_TYPE_FW);
-
-	if (fw_hdb &&
-	    (fw_hdb->status != MPI3MR_HDB_BUFSTATUS_POSTED_UNPAUSED) &&
-	    (fw_hdb->status != MPI3MR_HDB_BUFSTATUS_POSTED_PAUSED))
-		fw_hdb = NULL;
-
-	if (mrioc->snapdump_trigger_active || (mrioc->fw_release_trigger_active
-	    && mrioc->trace_release_trigger_active) ||
-	    (!trace_hdb && !fw_hdb) || (!mrioc->driver_pg2) ||
-	    ((trigger_type == MPI3MR_HDB_TRIGGER_TYPE_ELEMENT)
-	     && (!mrioc->driver_pg2->num_triggers)))
-		return;
-
-	memset(&event_data, 0, sizeof(event_data));
-	event_data.trigger_type = trigger_type;
-	memcpy(&event_data.trigger_specific_data, trigger_data,
-	    sizeof(*trigger_data));
-	global_trigger = le64_to_cpu(mrioc->driver_pg2->global_trigger);
-
-	if (global_trigger & MPI3_DRIVER2_GLOBALTRIGGER_SNAPDUMP_ENABLED) {
-		event_data.snapdump = true;
-		event_data.trace_hdb = trace_hdb;
-		event_data.fw_hdb = fw_hdb;
-		mrioc->snapdump_trigger_active = true;
-	} else if (trigger_type == MPI3MR_HDB_TRIGGER_TYPE_GLOBAL) {
-		if ((trace_hdb) && (global_trigger &
-		    MPI3_DRIVER2_GLOBALTRIGGER_DIAG_TRACE_RELEASE) &&
-		    (!mrioc->trace_release_trigger_active)) {
-			event_data.trace_hdb = trace_hdb;
-			mrioc->trace_release_trigger_active = true;
-		}
-		if ((fw_hdb) && (global_trigger &
-		    MPI3_DRIVER2_GLOBALTRIGGER_DIAG_FW_RELEASE) &&
-		    (!mrioc->fw_release_trigger_active)) {
-			event_data.fw_hdb = fw_hdb;
-			mrioc->fw_release_trigger_active = true;
-		}
-	} else if (trigger_type == MPI3MR_HDB_TRIGGER_TYPE_ELEMENT) {
-		if ((trace_hdb) && (trigger_flags &
-		    MPI3_DRIVER2_TRIGGER_FLAGS_DIAG_TRACE_RELEASE) &&
-		    (!mrioc->trace_release_trigger_active)) {
-			event_data.trace_hdb = trace_hdb;
-			mrioc->trace_release_trigger_active = true;
-		}
-		if ((fw_hdb) && (trigger_flags &
-		    MPI3_DRIVER2_TRIGGER_FLAGS_DIAG_FW_RELEASE) &&
-		    (!mrioc->fw_release_trigger_active)) {
-			event_data.fw_hdb = fw_hdb;
-			mrioc->fw_release_trigger_active = true;
-		}
-	}
-
-	if (event_data.trace_hdb || event_data.fw_hdb)
-		mpi3mr_hdb_trigger_data_event(mrioc, &event_data);
-}
-
-/**
- * mpi3mr_global_trigger - Global HDB trigger handler
- * @mrioc: Adapter instance reference
- * @trigger_data: Trigger data
- *
- * This function checks whether the given global trigger is
- * enabled in the driver page 2 and if so calls generic trigger
- * handler to queue event for HDB release.
- *
- * Return: Nothing
- */
-void mpi3mr_global_trigger(struct mpi3mr_ioc *mrioc, u64 trigger_data)
-{
-	unsigned long flags;
-	union mpi3mr_trigger_data trigger_specific_data;
-
-	spin_lock_irqsave(&mrioc->trigger_lock, flags);
-	if (le64_to_cpu(mrioc->driver_pg2->global_trigger) & trigger_data) {
-		memset(&trigger_specific_data, 0,
-		    sizeof(trigger_specific_data));
-		trigger_specific_data.global = trigger_data;
-		mpi3mr_process_trigger(mrioc, MPI3MR_HDB_TRIGGER_TYPE_GLOBAL,
-		    &trigger_specific_data, 0);
-	}
-	spin_unlock_irqrestore(&mrioc->trigger_lock, flags);
-}
-
-/**
- * mpi3mr_scsisense_trigger - SCSI sense HDB trigger handler
- * @mrioc: Adapter instance reference
- * @sensekey: Sense Key
- * @asc: Additional Sense Code
- * @ascq: Additional Sense Code Qualifier
- *
- * This function compares SCSI sense trigger values with driver
- * page 2 values and calls generic trigger handler to release
- * HDBs if match found
- *
- * Return: Nothing
- */
-void mpi3mr_scsisense_trigger(struct mpi3mr_ioc *mrioc, u8 sensekey, u8 asc,
-	u8 ascq)
-{
-	struct mpi3_driver2_trigger_scsi_sense *scsi_sense_trigger = NULL;
-	u64 i = 0;
-	unsigned long flags;
-	u8 num_triggers, trigger_flags;
-
-	if (mrioc->scsisense_trigger_present) {
-		spin_lock_irqsave(&mrioc->trigger_lock, flags);
-		scsi_sense_trigger = (struct mpi3_driver2_trigger_scsi_sense *)
-			mrioc->driver_pg2->trigger;
-		num_triggers = mrioc->driver_pg2->num_triggers;
-		for (i = 0; i < num_triggers; i++, scsi_sense_trigger++) {
-			if (scsi_sense_trigger->type !=
-			    MPI3_DRIVER2_TRIGGER_TYPE_SCSI_SENSE)
-				continue;
-			if (!(scsi_sense_trigger->sense_key ==
-			    MPI3_DRIVER2_TRIGGER_SCSI_SENSE_SENSE_KEY_MATCH_ALL
-			      || scsi_sense_trigger->sense_key == sensekey))
-				continue;
-			if (!(scsi_sense_trigger->asc ==
-			    MPI3_DRIVER2_TRIGGER_SCSI_SENSE_ASC_MATCH_ALL ||
-			    scsi_sense_trigger->asc == asc))
-				continue;
-			if (!(scsi_sense_trigger->ascq ==
-			    MPI3_DRIVER2_TRIGGER_SCSI_SENSE_ASCQ_MATCH_ALL ||
-			    scsi_sense_trigger->ascq == ascq))
-				continue;
-			trigger_flags = scsi_sense_trigger->flags;
-			mpi3mr_process_trigger(mrioc,
-			    MPI3MR_HDB_TRIGGER_TYPE_ELEMENT,
-			    (union mpi3mr_trigger_data *)scsi_sense_trigger,
-			    trigger_flags);
-			break;
-		}
-		spin_unlock_irqrestore(&mrioc->trigger_lock, flags);
-	}
-}
-
-/**
- * mpi3mr_event_trigger - MPI event HDB trigger handler
- * @mrioc: Adapter instance reference
- * @event: MPI Event
- *
- * This function compares event trigger values with driver page
- * 2 values and calls generic trigger handler to release
- * HDBs if match found.
- *
- * Return: Nothing
- */
-void mpi3mr_event_trigger(struct mpi3mr_ioc *mrioc, u8 event)
-{
-	struct mpi3_driver2_trigger_event *event_trigger = NULL;
-	u64 i = 0;
-	unsigned long flags;
-	u8 num_triggers, trigger_flags;
-
-	if (mrioc->event_trigger_present) {
-		spin_lock_irqsave(&mrioc->trigger_lock, flags);
-		event_trigger = (struct mpi3_driver2_trigger_event *)
-			mrioc->driver_pg2->trigger;
-		num_triggers = mrioc->driver_pg2->num_triggers;
-
-		for (i = 0; i < num_triggers; i++, event_trigger++) {
-			if (event_trigger->type !=
-			    MPI3_DRIVER2_TRIGGER_TYPE_EVENT)
-				continue;
-			if (event_trigger->event != event)
-				continue;
-			trigger_flags = event_trigger->flags;
-			mpi3mr_process_trigger(mrioc,
-			    MPI3MR_HDB_TRIGGER_TYPE_ELEMENT,
-			    (union mpi3mr_trigger_data *)event_trigger,
-			    trigger_flags);
-			break;
-		}
-		spin_unlock_irqrestore(&mrioc->trigger_lock, flags);
-	}
-}
-
-/**
- * mpi3mr_reply_trigger - MPI Reply HDB trigger handler
- * @mrioc: Adapter instance reference
- * @ioc_status: Masked value of IOC Status from MPI Reply
- * @ioc_loginfo: IOC Log Info from MPI Reply
- *
- * This function compares IOC status and IOC log info trigger
- * values with driver page 2 values and calls generic trigger
- * handler to release HDBs if match found.
- *
- * Return: Nothing
- */
-void mpi3mr_reply_trigger(struct mpi3mr_ioc *mrioc, u16 ioc_status,
-	u32 ioc_loginfo)
-{
-	struct mpi3_driver2_trigger_reply *reply_trigger = NULL;
-	u64 i = 0;
-	unsigned long flags;
-	u8 num_triggers, trigger_flags;
-
-	if (mrioc->reply_trigger_present) {
-		spin_lock_irqsave(&mrioc->trigger_lock, flags);
-		reply_trigger = (struct mpi3_driver2_trigger_reply *)
-			mrioc->driver_pg2->trigger;
-		num_triggers = mrioc->driver_pg2->num_triggers;
-		for (i = 0; i < num_triggers; i++, reply_trigger++) {
-			if (reply_trigger->type !=
-			    MPI3_DRIVER2_TRIGGER_TYPE_REPLY)
-				continue;
-			if ((le16_to_cpu(reply_trigger->ioc_status) !=
-			     ioc_status)
-			    && (le16_to_cpu(reply_trigger->ioc_status) !=
-			    MPI3_DRIVER2_TRIGGER_REPLY_IOCSTATUS_MATCH_ALL))
-				continue;
-			if ((le32_to_cpu(reply_trigger->ioc_log_info) !=
-			    (le32_to_cpu(reply_trigger->ioc_log_info_mask) &
-			     ioc_loginfo)))
-				continue;
-			trigger_flags = reply_trigger->flags;
-			mpi3mr_process_trigger(mrioc,
-			    MPI3MR_HDB_TRIGGER_TYPE_ELEMENT,
-			    (union mpi3mr_trigger_data *)reply_trigger,
-			    trigger_flags);
-			break;
-		}
-		spin_unlock_irqrestore(&mrioc->trigger_lock, flags);
-	}
-}
-
-/**
- * mpi3mr_get_num_trigger - Gets number of HDB triggers
- * @mrioc: Adapter instance reference
- * @num_triggers: Number of triggers
- * @page_action: Page action
- *
- * This function reads number of triggers by reading driver page
- * 2
- *
- * Return: 0 on success and proper error codes on failure
- */
-static int mpi3mr_get_num_trigger(struct mpi3mr_ioc *mrioc, u8 *num_triggers,
-	u8 page_action)
-{
-	struct mpi3_driver_page2 drvr_page2;
-	int retval = 0;
-
-	*num_triggers = 0;
-
-	retval = mpi3mr_cfg_get_driver_pg2(mrioc, &drvr_page2,
-	    sizeof(struct mpi3_driver_page2), page_action);
-
-	if (retval) {
-		dprint_init(mrioc, "%s: driver page 2 read failed\n", __func__);
-		return retval;
-	}
-	*num_triggers = drvr_page2.num_triggers;
-	return retval;
-}
-
-/**
- * mpi3mr_refresh_trigger - Handler for Refresh trigger BSG
- * @mrioc: Adapter instance reference
- * @page_action: Page action
- *
- * This function caches the driver page 2 in the driver's memory
- * by reading driver page 2 from the controller for a given page
- * type and updates the HDB trigger values
- *
- * Return: 0 on success and proper error codes on failure
- */
-int mpi3mr_refresh_trigger(struct mpi3mr_ioc *mrioc, u8 page_action)
-{
-	u16 pg_sz = sizeof(struct mpi3_driver_page2);
-	struct mpi3_driver_page2 *drvr_page2 = NULL;
-	u8 trigger_type, num_triggers;
-	int retval;
-	int i = 0;
-	unsigned long flags;
-
-	retval = mpi3mr_get_num_trigger(mrioc, &num_triggers, page_action);
-
-	if (retval)
-		goto out;
-
-	pg_sz = offsetof(struct mpi3_driver_page2, trigger) +
-		(num_triggers * sizeof(union mpi3_driver2_trigger_element));
-	drvr_page2 = kzalloc(pg_sz, GFP_KERNEL);
-	if (!drvr_page2) {
-		retval = -ENOMEM;
-		goto out;
-	}
-
-	retval = mpi3mr_cfg_get_driver_pg2(mrioc, drvr_page2, pg_sz, page_action);
-	if (retval) {
-		dprint_init(mrioc, "%s: driver page 2 read failed\n", __func__);
-		kfree(drvr_page2);
-		goto out;
-	}
-	spin_lock_irqsave(&mrioc->trigger_lock, flags);
-	kfree(mrioc->driver_pg2);
-	mrioc->driver_pg2 = drvr_page2;
-	mrioc->reply_trigger_present = false;
-	mrioc->event_trigger_present = false;
-	mrioc->scsisense_trigger_present = false;
-
-	for (i = 0; (i < mrioc->driver_pg2->num_triggers); i++) {
-		trigger_type = mrioc->driver_pg2->trigger[i].event.type;
-		switch (trigger_type) {
-		case MPI3_DRIVER2_TRIGGER_TYPE_REPLY:
-			mrioc->reply_trigger_present = true;
-			break;
-		case MPI3_DRIVER2_TRIGGER_TYPE_EVENT:
-			mrioc->event_trigger_present = true;
-			break;
-		case MPI3_DRIVER2_TRIGGER_TYPE_SCSI_SENSE:
-			mrioc->scsisense_trigger_present = true;
-			break;
-		default:
-			break;
-		}
-	}
-	spin_unlock_irqrestore(&mrioc->trigger_lock, flags);
-out:
-	return retval;
-}
-
-/**
- * mpi3mr_release_diag_bufs - Release diag buffers
- * @mrioc: Adapter instance reference
- * @skip_rel_action: Skip release action and set buffer state
- *
- * This function calls helper function to release both trace and
- * firmware buffers from the controller.
- *
- * Return: None
- */
-void mpi3mr_release_diag_bufs(struct mpi3mr_ioc *mrioc, u8 skip_rel_action)
-{
-	u8 i;
-	struct diag_buffer_desc *diag_buffer;
-
-	for (i = 0; i < MPI3MR_MAX_NUM_HDB; i++) {
-		diag_buffer = &mrioc->diag_buffers[i];
-		if (!(diag_buffer->addr))
-			continue;
-		if (diag_buffer->status == MPI3MR_HDB_BUFSTATUS_RELEASED)
-			continue;
-		if (!skip_rel_action)
-			mpi3mr_issue_diag_buf_release(mrioc, diag_buffer);
-		diag_buffer->status = MPI3MR_HDB_BUFSTATUS_RELEASED;
-		atomic64_inc(&event_counter);
-	}
-}
-
-/**
- * mpi3mr_set_trigger_data_in_hdb - Updates HDB trigger type and
- * trigger data
- *
- * @hdb: HDB pointer
- * @type: Trigger type
- * @data: Trigger data
- * @force: Trigger overwrite flag
- * @trigger_data: Pointer to trigger data information
- *
- * Updates trigger type and trigger data based on parameter
- * passed to this function
- *
- * Return: Nothing
- */
-void mpi3mr_set_trigger_data_in_hdb(struct diag_buffer_desc *hdb,
-	u8 type, union mpi3mr_trigger_data *trigger_data, bool force)
-{
-	if ((!force) && (hdb->trigger_type != MPI3MR_HDB_TRIGGER_TYPE_UNKNOWN))
-		return;
-	hdb->trigger_type = type;
-	if (!trigger_data)
-		memset(&hdb->trigger_data, 0, sizeof(*trigger_data));
-	else
-		memcpy(&hdb->trigger_data, trigger_data, sizeof(*trigger_data));
-}
-
-/**
- * mpi3mr_set_trigger_data_in_all_hdb - Updates HDB trigger type
- * and trigger data for all HDB
- *
- * @mrioc: Adapter instance reference
- * @type: Trigger type
- * @data: Trigger data
- * @force: Trigger overwrite flag
- * @trigger_data: Pointer to trigger data information
- *
- * Updates trigger type and trigger data based on parameter
- * passed to this function
- *
- * Return: Nothing
- */
-void mpi3mr_set_trigger_data_in_all_hdb(struct mpi3mr_ioc *mrioc,
-	u8 type, union mpi3mr_trigger_data *trigger_data, bool force)
-{
-	struct diag_buffer_desc *hdb = NULL;
-
-	hdb = mpi3mr_diag_buffer_for_type(mrioc, MPI3_DIAG_BUFFER_TYPE_TRACE);
-	if (hdb)
-		mpi3mr_set_trigger_data_in_hdb(hdb, type, trigger_data, force);
-	hdb = mpi3mr_diag_buffer_for_type(mrioc, MPI3_DIAG_BUFFER_TYPE_FW);
-	if (hdb)
-		mpi3mr_set_trigger_data_in_hdb(hdb, type, trigger_data, force);
-}
-
-/**
- * mpi3mr_hdbstatuschg_evt_th - HDB status change evt tophalf
- * @mrioc: Adapter instance reference
- * @event_reply: event data
- *
- * Modifies the status of the applicable diag buffer descriptors
- *
- * Return: Nothing
- */
-void mpi3mr_hdbstatuschg_evt_th(struct mpi3mr_ioc *mrioc,
-	struct mpi3_event_notification_reply *event_reply)
-{
-	struct mpi3_event_data_diag_buffer_status_change *evtdata;
-	struct diag_buffer_desc *diag_buffer;
-
-	evtdata = (struct mpi3_event_data_diag_buffer_status_change *)
-	    event_reply->event_data;
-
-	diag_buffer = mpi3mr_diag_buffer_for_type(mrioc, evtdata->type);
-	if (!diag_buffer)
-		return;
-	if ((diag_buffer->status != MPI3MR_HDB_BUFSTATUS_POSTED_UNPAUSED) &&
-	    (diag_buffer->status != MPI3MR_HDB_BUFSTATUS_POSTED_PAUSED))
-		return;
-	switch (evtdata->reason_code) {
-	case MPI3_EVENT_DIAG_BUFFER_STATUS_CHANGE_RC_RELEASED:
-	{
-		diag_buffer->status = MPI3MR_HDB_BUFSTATUS_RELEASED;
-		mpi3mr_set_trigger_data_in_hdb(diag_buffer,
-		    MPI3MR_HDB_TRIGGER_TYPE_FW_RELEASED, NULL, 0);
-		atomic64_inc(&event_counter);
-		break;
-	}
-	case MPI3_EVENT_DIAG_BUFFER_STATUS_CHANGE_RC_RESUMED:
-	{
-		diag_buffer->status = MPI3MR_HDB_BUFSTATUS_POSTED_UNPAUSED;
-		break;
-	}
-	case MPI3_EVENT_DIAG_BUFFER_STATUS_CHANGE_RC_PAUSED:
-	{
-		diag_buffer->status = MPI3MR_HDB_BUFSTATUS_POSTED_PAUSED;
-		break;
-	}
-	default:
-		dprint_event_th(mrioc, "%s: unknown reason_code(%d)\n",
-		    __func__, evtdata->reason_code);
-		break;
-	}
-}
-
-/**
- * mpi3mr_diag_buffer_for_type - returns buffer desc for type
- * @mrioc: Adapter instance reference
- * @buf_type: Diagnostic buffer type
- *
- * Identifies matching diag descriptor from mrioc for given diag
- * buffer type.
- *
- * Return: diag buffer descriptor on success, NULL on failures.
- */
-
-struct diag_buffer_desc *
-mpi3mr_diag_buffer_for_type(struct mpi3mr_ioc *mrioc, u8 buf_type)
-{
-	u8 i;
-
-	for (i = 0; i < MPI3MR_MAX_NUM_HDB; i++) {
-		if (mrioc->diag_buffers[i].type == buf_type)
-			return &mrioc->diag_buffers[i];
-	}
-	return NULL;
-}
-
 /**
  * mpi3mr_bsg_pel_abort - sends PEL abort request
  * @mrioc: Adapter instance reference
@@ -846,7 +31,7 @@ static int mpi3mr_bsg_pel_abort(struct mpi3mr_ioc *mrioc)
 		dprint_bsg_err(mrioc, "%s: reset in progress\n", __func__);
 		return -1;
 	}
-	if (mrioc->stop_bsgs || mrioc->block_on_pci_err) {
+	if (mrioc->stop_bsgs) {
 		dprint_bsg_err(mrioc, "%s: bsgs are blocked\n", __func__);
 		return -1;
 	}
@@ -940,259 +125,6 @@ static struct mpi3mr_ioc *mpi3mr_bsg_verify_adapter(int ioc_number)
 	return NULL;
 }
 
-/**
- * mpi3mr_bsg_refresh_hdb_triggers - Refresh HDB trigger data
- * @mrioc: Adapter instance reference
- * @job: BSG Job pointer
- *
- * This function reads the controller trigger config page as
- * defined by the input page type and refreshes the driver's
- * local trigger information structures with the controller's
- * config page data.
- *
- * Return: 0 on success and proper error codes on failure
- */
-static long
-mpi3mr_bsg_refresh_hdb_triggers(struct mpi3mr_ioc *mrioc,
-				struct bsg_job *job)
-{
-	struct mpi3mr_bsg_out_refresh_hdb_triggers refresh_triggers;
-	uint32_t data_out_sz;
-	u8 page_action;
-	long rval = -EINVAL;
-
-	data_out_sz = job->request_payload.payload_len;
-
-	if (data_out_sz != sizeof(refresh_triggers)) {
-		dprint_bsg_err(mrioc, "%s: invalid size argument\n",
-		    __func__);
-		return rval;
-	}
-
-	if (mrioc->unrecoverable) {
-		dprint_bsg_err(mrioc, "%s: unrecoverable controller\n",
-		    __func__);
-		return -EFAULT;
-	}
-	if (mrioc->reset_in_progress) {
-		dprint_bsg_err(mrioc, "%s: reset in progress\n", __func__);
-		return -EAGAIN;
-	}
-
-	sg_copy_to_buffer(job->request_payload.sg_list,
-	    job->request_payload.sg_cnt,
-	    &refresh_triggers, sizeof(refresh_triggers));
-
-	switch (refresh_triggers.page_type) {
-	case MPI3MR_HDB_REFRESH_TYPE_CURRENT:
-		page_action = MPI3_CONFIG_ACTION_READ_CURRENT;
-		break;
-	case MPI3MR_HDB_REFRESH_TYPE_DEFAULT:
-		page_action = MPI3_CONFIG_ACTION_READ_DEFAULT;
-		break;
-	case MPI3MR_HDB_HDB_REFRESH_TYPE_PERSISTENT:
-		page_action = MPI3_CONFIG_ACTION_READ_PERSISTENT;
-		break;
-	default:
-		dprint_bsg_err(mrioc,
-		    "%s: unsupported refresh trigger, page_type %d\n",
-		    __func__, refresh_triggers.page_type);
-		return rval;
-	}
-	rval = mpi3mr_refresh_trigger(mrioc, page_action);
-
-	return rval;
-}
-
-/**
- * mpi3mr_bsg_upload_hdb - Upload a specific HDB to user space
- * @mrioc: Adapter instance reference
- * @job: BSG Job pointer
- *
- * Return: 0 on success and proper error codes on failure
- */
-static long mpi3mr_bsg_upload_hdb(struct mpi3mr_ioc *mrioc,
-				  struct bsg_job *job)
-{
-	struct mpi3mr_bsg_out_upload_hdb upload_hdb;
-	struct diag_buffer_desc *diag_buffer;
-	uint32_t data_out_size;
-	uint32_t data_in_size;
-
-	data_out_size = job->request_payload.payload_len;
-	data_in_size = job->reply_payload.payload_len;
-
-	if (data_out_size != sizeof(upload_hdb)) {
-		dprint_bsg_err(mrioc, "%s: invalid size argument\n",
-		    __func__);
-		return -EINVAL;
-	}
-
-	sg_copy_to_buffer(job->request_payload.sg_list,
-			  job->request_payload.sg_cnt,
-			  &upload_hdb, sizeof(upload_hdb));
-
-	if ((!upload_hdb.length) || (data_in_size != upload_hdb.length)) {
-		dprint_bsg_err(mrioc, "%s: invalid length argument\n",
-		    __func__);
-		return -EINVAL;
-	}
-	diag_buffer = mpi3mr_diag_buffer_for_type(mrioc, upload_hdb.buf_type);
-	if ((!diag_buffer) || (!diag_buffer->addr)) {
-		dprint_bsg_err(mrioc, "%s: invalid buffer type %d\n",
-		    __func__, upload_hdb.buf_type);
-		return -EINVAL;
-	}
-
-	if ((diag_buffer->status != MPI3MR_HDB_BUFSTATUS_RELEASED) &&
-	    (diag_buffer->status != MPI3MR_HDB_BUFSTATUS_POSTED_PAUSED)) {
-		dprint_bsg_err(mrioc,
-		    "%s: invalid buffer status %d for type %d\n",
-		    __func__, diag_buffer->status, upload_hdb.buf_type);
-		return -EINVAL;
-	}
-
-	if ((upload_hdb.start_offset + upload_hdb.length) > diag_buffer->size) {
-		dprint_bsg_err(mrioc,
-		    "%s: invalid start offset %d, length %d for type %d\n",
-		    __func__, upload_hdb.start_offset, upload_hdb.length,
-		    upload_hdb.buf_type);
-		return -EINVAL;
-	}
-	sg_copy_from_buffer(job->reply_payload.sg_list,
-			    job->reply_payload.sg_cnt,
-	    (diag_buffer->addr + upload_hdb.start_offset),
-	    data_in_size);
-	return 0;
-}
-
-/**
- * mpi3mr_bsg_repost_hdb - Re-post HDB
- * @mrioc: Adapter instance reference
- * @job: BSG job pointer
- *
- * This function retrieves the HDB descriptor corresponding to a
- * given buffer type and if the HDB is in released status then
- * posts the HDB with the firmware.
- *
- * Return: 0 on success and proper error codes on failure
- */
-static long mpi3mr_bsg_repost_hdb(struct mpi3mr_ioc *mrioc,
-				  struct bsg_job *job)
-{
-	struct mpi3mr_bsg_out_repost_hdb repost_hdb;
-	struct diag_buffer_desc *diag_buffer;
-	uint32_t data_out_sz;
-
-	data_out_sz = job->request_payload.payload_len;
-
-	if (data_out_sz != sizeof(repost_hdb)) {
-		dprint_bsg_err(mrioc, "%s: invalid size argument\n",
-		    __func__);
-		return -EINVAL;
-	}
-	if (mrioc->unrecoverable) {
-		dprint_bsg_err(mrioc, "%s: unrecoverable controller\n",
-		    __func__);
-		return -EFAULT;
-	}
-	if (mrioc->reset_in_progress) {
-		dprint_bsg_err(mrioc, "%s: reset in progress\n", __func__);
-		return -EAGAIN;
-	}
-
-	sg_copy_to_buffer(job->request_payload.sg_list,
-			  job->request_payload.sg_cnt,
-			  &repost_hdb, sizeof(repost_hdb));
-
-	diag_buffer = mpi3mr_diag_buffer_for_type(mrioc, repost_hdb.buf_type);
-	if ((!diag_buffer) || (!diag_buffer->addr)) {
-		dprint_bsg_err(mrioc, "%s: invalid buffer type %d\n",
-		    __func__, repost_hdb.buf_type);
-		return -EINVAL;
-	}
-
-	if (diag_buffer->status != MPI3MR_HDB_BUFSTATUS_RELEASED) {
-		dprint_bsg_err(mrioc,
-		    "%s: invalid buffer status %d for type %d\n",
-		    __func__, diag_buffer->status, repost_hdb.buf_type);
-		return -EINVAL;
-	}
-
-	if (mpi3mr_issue_diag_buf_post(mrioc, diag_buffer)) {
-		dprint_bsg_err(mrioc, "%s: post failed for type %d\n",
-		    __func__, repost_hdb.buf_type);
-		return -EFAULT;
-	}
-	mpi3mr_set_trigger_data_in_hdb(diag_buffer,
-	    MPI3MR_HDB_TRIGGER_TYPE_UNKNOWN, NULL, 1);
-
-	return 0;
-}
-
-/**
- * mpi3mr_bsg_query_hdb - Handler for query HDB command
- * @mrioc: Adapter instance reference
- * @job: BSG job pointer
- *
- * This function prepares and copies the host diagnostic buffer
- * entries to the user buffer.
- *
- * Return: 0 on success and proper error codes on failure
- */
-static long mpi3mr_bsg_query_hdb(struct mpi3mr_ioc *mrioc,
-				 struct bsg_job *job)
-{
-	long rval = 0;
-	struct mpi3mr_bsg_in_hdb_status *hbd_status;
-	struct mpi3mr_hdb_entry *hbd_status_entry;
-	u32 length, min_length;
-	u8 i;
-	struct diag_buffer_desc *diag_buffer;
-	uint32_t data_in_sz = 0;
-
-	data_in_sz = job->request_payload.payload_len;
-
-	length = (sizeof(*hbd_status) + ((MPI3MR_MAX_NUM_HDB - 1) *
-		    sizeof(*hbd_status_entry)));
-	hbd_status = kmalloc(length, GFP_KERNEL);
-	if (!hbd_status)
-		return -ENOMEM;
-	hbd_status_entry = &hbd_status->entry[0];
-
-	hbd_status->num_hdb_types = MPI3MR_MAX_NUM_HDB;
-	for (i = 0; i < MPI3MR_MAX_NUM_HDB; i++) {
-		diag_buffer = &mrioc->diag_buffers[i];
-		hbd_status_entry->buf_type = diag_buffer->type;
-		hbd_status_entry->status = diag_buffer->status;
-		hbd_status_entry->trigger_type = diag_buffer->trigger_type;
-		memcpy(&hbd_status_entry->trigger_data,
-		    &diag_buffer->trigger_data,
-		    sizeof(hbd_status_entry->trigger_data));
-		hbd_status_entry->size = (diag_buffer->size / 1024);
-		hbd_status_entry++;
-	}
-	hbd_status->element_trigger_format =
-		MPI3MR_HDB_QUERY_ELEMENT_TRIGGER_FORMAT_DATA;
-
-	if (data_in_sz < 4) {
-		dprint_bsg_err(mrioc, "%s: invalid size passed\n", __func__);
-		rval = -EINVAL;
-		goto out;
-	}
-	min_length = min(data_in_sz, length);
-	if (job->request_payload.payload_len >= min_length) {
-		sg_copy_from_buffer(job->request_payload.sg_list,
-				    job->request_payload.sg_cnt,
-				    hbd_status, min_length);
-		rval = 0;
-	}
-out:
-	kfree(hbd_status);
-	return rval;
-}
-
-
 /**
  * mpi3mr_enable_logdata - Handler for log data enable
  * @mrioc: Adapter instance reference
@@ -1492,9 +424,6 @@ static long mpi3mr_bsg_adp_reset(struct mpi3mr_ioc *mrioc,
 		goto out;
 	}
 
-	if (mrioc->unrecoverable || mrioc->block_on_pci_err)
-		return -EINVAL;
-
 	sg_copy_to_buffer(job->request_payload.sg_list,
 			  job->request_payload.sg_cnt,
 			  &adpreset, sizeof(adpreset));
@@ -1624,18 +553,6 @@ static long mpi3mr_bsg_process_drv_cmds(struct bsg_job *job)
 	case MPI3MR_DRVBSG_OPCODE_PELENABLE:
 		rval = mpi3mr_bsg_pel_enable(mrioc, job);
 		break;
-	case MPI3MR_DRVBSG_OPCODE_QUERY_HDB:
-		rval = mpi3mr_bsg_query_hdb(mrioc, job);
-		break;
-	case MPI3MR_DRVBSG_OPCODE_REPOST_HDB:
-		rval = mpi3mr_bsg_repost_hdb(mrioc, job);
-		break;
-	case MPI3MR_DRVBSG_OPCODE_UPLOAD_HDB:
-		rval = mpi3mr_bsg_upload_hdb(mrioc, job);
-		break;
-	case MPI3MR_DRVBSG_OPCODE_REFRESH_HDB_TRIGGERS:
-		rval = mpi3mr_bsg_refresh_hdb_triggers(mrioc, job);
-		break;
 	case MPI3MR_DRVBSG_OPCODE_UNKNOWN:
 	default:
 		pr_err("%s: unsupported driver command opcode %d\n",
@@ -2578,7 +1495,7 @@ static long mpi3mr_bsg_process_mpt_cmds(struct bsg_job *job)
 		mutex_unlock(&mrioc->bsg_cmds.mutex);
 		goto out;
 	}
-	if (mrioc->stop_bsgs || mrioc->block_on_pci_err) {
+	if (mrioc->stop_bsgs) {
 		dprint_bsg_err(mrioc, "%s: bsgs are blocked\n", __func__);
 		rval = -EAGAIN;
 		mutex_unlock(&mrioc->bsg_cmds.mutex);
@@ -3111,8 +2028,7 @@ adp_state_show(struct device *dev, struct device_attribute *attr,
 	ioc_state = mpi3mr_get_iocstate(mrioc);
 	if (ioc_state == MRIOC_STATE_UNRECOVERABLE)
 		adp_state = MPI3MR_BSG_ADPSTATE_UNRECOVERABLE;
-	else if (mrioc->reset_in_progress || mrioc->stop_bsgs ||
-		 mrioc->block_on_pci_err)
+	else if ((mrioc->reset_in_progress) || (mrioc->stop_bsgs))
 		adp_state = MPI3MR_BSG_ADPSTATE_IN_RESET;
 	else if (ioc_state == MRIOC_STATE_FAULT)
 		adp_state = MPI3MR_BSG_ADPSTATE_FAULT;
diff --git a/drivers/scsi/mpi3mr/mpi3mr_fw.c b/drivers/scsi/mpi3mr/mpi3mr_fw.c
index c196dc14ad20..c2a22e96f7b7 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_fw.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_fw.c
@@ -274,9 +274,6 @@ static void mpi3mr_print_event_data(struct mpi3mr_ioc *mrioc,
 	case MPI3_EVENT_PREPARE_FOR_RESET:
 		desc = "Prepare For Reset";
 		break;
-	case MPI3_EVENT_DIAGNOSTIC_BUFFER_STATUS_CHANGE:
-		desc = "Diagnostic Buffer Status Change";
-		break;
 	}
 
 	if (!desc)
@@ -345,14 +342,13 @@ static void mpi3mr_process_admin_reply_desc(struct mpi3mr_ioc *mrioc,
 {
 	u16 reply_desc_type, host_tag = 0;
 	u16 ioc_status = MPI3_IOCSTATUS_SUCCESS;
-	u32 ioc_loginfo = 0, sense_count = 0;
+	u32 ioc_loginfo = 0;
 	struct mpi3_status_reply_descriptor *status_desc;
 	struct mpi3_address_reply_descriptor *addr_desc;
 	struct mpi3_success_reply_descriptor *success_desc;
 	struct mpi3_default_reply *def_reply = NULL;
 	struct mpi3mr_drv_cmd *cmdptr = NULL;
 	struct mpi3_scsi_io_reply *scsi_reply;
-	struct scsi_sense_hdr sshdr;
 	u8 *sense_buf = NULL;
 
 	*reply_dma = 0;
@@ -367,7 +363,6 @@ static void mpi3mr_process_admin_reply_desc(struct mpi3mr_ioc *mrioc,
 		    MPI3_REPLY_DESCRIPT_STATUS_IOCSTATUS_LOGINFOAVAIL)
 			ioc_loginfo = le32_to_cpu(status_desc->ioc_log_info);
 		ioc_status &= MPI3_REPLY_DESCRIPT_STATUS_IOCSTATUS_STATUS_MASK;
-		mpi3mr_reply_trigger(mrioc, ioc_status, ioc_loginfo);
 		break;
 	case MPI3_REPLY_DESCRIPT_FLAGS_TYPE_ADDRESS_REPLY:
 		addr_desc = (struct mpi3_address_reply_descriptor *)reply_desc;
@@ -385,15 +380,7 @@ static void mpi3mr_process_admin_reply_desc(struct mpi3mr_ioc *mrioc,
 			scsi_reply = (struct mpi3_scsi_io_reply *)def_reply;
 			sense_buf = mpi3mr_get_sensebuf_virt_addr(mrioc,
 			    le64_to_cpu(scsi_reply->sense_data_buffer_address));
-			sense_count = le32_to_cpu(scsi_reply->sense_count);
-			if (sense_buf) {
-				scsi_normalize_sense(sense_buf, sense_count,
-				    &sshdr);
-				mpi3mr_scsisense_trigger(mrioc, sshdr.sense_key,
-				    sshdr.asc, sshdr.ascq);
-			}
 		}
-		mpi3mr_reply_trigger(mrioc, ioc_status, ioc_loginfo);
 		break;
 	case MPI3_REPLY_DESCRIPT_FLAGS_TYPE_SUCCESS:
 		success_desc = (struct mpi3_success_reply_descriptor *)reply_desc;
@@ -608,7 +595,7 @@ int mpi3mr_blk_mq_poll(struct Scsi_Host *shost, unsigned int queue_num)
 	mrioc = (struct mpi3mr_ioc *)shost->hostdata;
 
 	if ((mrioc->reset_in_progress || mrioc->prepare_for_reset ||
-	    mrioc->unrecoverable || mrioc->pci_err_recovery))
+	    mrioc->unrecoverable))
 		return 0;
 
 	num_entries = mpi3mr_process_op_reply_q(mrioc,
@@ -951,14 +938,6 @@ static const struct {
 	},
 	{ MPI3MR_RESET_FROM_SYSFS, "sysfs invocation" },
 	{ MPI3MR_RESET_FROM_SYSFS_TIMEOUT, "sysfs TM timeout" },
-	{
-		MPI3MR_RESET_FROM_DIAG_BUFFER_POST_TIMEOUT,
-		"diagnostic buffer post timeout"
-	},
-	{
-		MPI3MR_RESET_FROM_DIAG_BUFFER_RELEASE_TIMEOUT,
-		"diagnostic buffer release timeout"
-	},
 	{ MPI3MR_RESET_FROM_FIRMWARE, "firmware asynchronous reset" },
 	{ MPI3MR_RESET_FROM_CFG_REQ_TIMEOUT, "configuration request timeout"},
 	{ MPI3MR_RESET_FROM_SAS_TRANSPORT_TIMEOUT, "timeout of a SAS transport layer request" },
@@ -1693,12 +1672,6 @@ int mpi3mr_admin_request_post(struct mpi3mr_ioc *mrioc, void *admin_req,
 		retval = -EAGAIN;
 		goto out;
 	}
-	if (mrioc->pci_err_recovery) {
-		ioc_err(mrioc, "admin request queue submission failed due to pci error recovery 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);
@@ -2369,11 +2342,6 @@ int mpi3mr_op_request_post(struct mpi3mr_ioc *mrioc,
 		retval = -EAGAIN;
 		goto out;
 	}
-	if (mrioc->pci_err_recovery) {
-		ioc_err(mrioc, "operational request queue submission failed due to pci error recovery in progress\n");
-		retval = -EAGAIN;
-		goto out;
-	}
 
 	segment_base_addr = segments[pi / op_req_q->segment_qd].segment;
 	req_entry = (u8 *)segment_base_addr +
@@ -2419,7 +2387,6 @@ int mpi3mr_op_request_post(struct mpi3mr_ioc *mrioc,
 void mpi3mr_check_rh_fault_ioc(struct mpi3mr_ioc *mrioc, u32 reason_code)
 {
 	u32 ioc_status, host_diagnostic, timeout;
-	union mpi3mr_trigger_data trigger_data;
 
 	if (mrioc->unrecoverable) {
 		ioc_err(mrioc, "controller is unrecoverable\n");
@@ -2431,30 +2398,16 @@ void mpi3mr_check_rh_fault_ioc(struct mpi3mr_ioc *mrioc, u32 reason_code)
 		ioc_err(mrioc, "controller is not present\n");
 		return;
 	}
-	memset(&trigger_data, 0, sizeof(trigger_data));
-	ioc_status = readl(&mrioc->sysif_regs->ioc_status);
 
-	if (ioc_status & MPI3_SYSIF_IOC_STATUS_RESET_HISTORY) {
-		mpi3mr_set_trigger_data_in_all_hdb(mrioc,
-		    MPI3MR_HDB_TRIGGER_TYPE_FW_RELEASED, NULL, 0);
-		return;
-	} else if (ioc_status & MPI3_SYSIF_IOC_STATUS_FAULT) {
-		trigger_data.fault = (readl(&mrioc->sysif_regs->fault) &
-		      MPI3_SYSIF_FAULT_CODE_MASK);
-
-		mpi3mr_set_trigger_data_in_all_hdb(mrioc,
-		    MPI3MR_HDB_TRIGGER_TYPE_FAULT, &trigger_data, 0);
+	ioc_status = readl(&mrioc->sysif_regs->ioc_status);
+	if ((ioc_status & MPI3_SYSIF_IOC_STATUS_RESET_HISTORY) ||
+	    (ioc_status & MPI3_SYSIF_IOC_STATUS_FAULT)) {
 		mpi3mr_print_fault_info(mrioc);
 		return;
 	}
-
 	mpi3mr_set_diagsave(mrioc);
 	mpi3mr_issue_reset(mrioc, MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT,
 	    reason_code);
-	trigger_data.fault = (readl(&mrioc->sysif_regs->fault) &
-		      MPI3_SYSIF_FAULT_CODE_MASK);
-	mpi3mr_set_trigger_data_in_all_hdb(mrioc, MPI3MR_HDB_TRIGGER_TYPE_FAULT,
-	    &trigger_data, 0);
 	timeout = MPI3_SYSIF_DIAG_SAVE_TIMEOUT * 10;
 	do {
 		host_diagnostic = readl(&mrioc->sysif_regs->host_diagnostic);
@@ -2634,11 +2587,10 @@ static void mpi3mr_watchdog_work(struct work_struct *work)
 	    container_of(work, struct mpi3mr_ioc, watchdog_work.work);
 	unsigned long flags;
 	enum mpi3mr_iocstate ioc_state;
-	u32 host_diagnostic, ioc_status;
-	union mpi3mr_trigger_data trigger_data;
+	u32 fault, host_diagnostic, ioc_status;
 	u16 reset_reason = MPI3MR_RESET_FROM_FAULT_WATCH;
 
-	if (mrioc->reset_in_progress || mrioc->pci_err_recovery)
+	if (mrioc->reset_in_progress)
 		return;
 
 	if (!mrioc->unrecoverable && !pci_device_is_present(mrioc->pdev)) {
@@ -2666,11 +2618,8 @@ static void mpi3mr_watchdog_work(struct work_struct *work)
 		return;
 	}
 
-	memset(&trigger_data, 0, sizeof(trigger_data));
 	ioc_status = readl(&mrioc->sysif_regs->ioc_status);
 	if (ioc_status & MPI3_SYSIF_IOC_STATUS_RESET_HISTORY) {
-		mpi3mr_set_trigger_data_in_all_hdb(mrioc,
-		    MPI3MR_HDB_TRIGGER_TYPE_FW_RELEASED, NULL, 0);
 		mpi3mr_soft_reset_handler(mrioc, MPI3MR_RESET_FROM_FIRMWARE, 0);
 		return;
 	}
@@ -2680,9 +2629,7 @@ static void mpi3mr_watchdog_work(struct work_struct *work)
 	if (ioc_state != MRIOC_STATE_FAULT)
 		goto schedule_work;
 
-	trigger_data.fault = readl(&mrioc->sysif_regs->fault) & MPI3_SYSIF_FAULT_CODE_MASK;
-	mpi3mr_set_trigger_data_in_all_hdb(mrioc,
-	    MPI3MR_HDB_TRIGGER_TYPE_FAULT, &trigger_data, 0);
+	fault = readl(&mrioc->sysif_regs->fault) & MPI3_SYSIF_FAULT_CODE_MASK;
 	host_diagnostic = readl(&mrioc->sysif_regs->host_diagnostic);
 	if (host_diagnostic & MPI3_SYSIF_HOST_DIAG_SAVE_IN_PROGRESS) {
 		if (!mrioc->diagsave_timeout) {
@@ -2696,7 +2643,7 @@ static void mpi3mr_watchdog_work(struct work_struct *work)
 	mpi3mr_print_fault_info(mrioc);
 	mrioc->diagsave_timeout = 0;
 
-	switch (trigger_data.fault) {
+	switch (fault) {
 	case MPI3_SYSIF_FAULT_CODE_COMPLETE_RESET_NEEDED:
 	case MPI3_SYSIF_FAULT_CODE_POWER_CYCLE_REQUIRED:
 		ioc_warn(mrioc,
@@ -3056,11 +3003,7 @@ static void mpi3mr_process_factsdata(struct mpi3mr_ioc *mrioc,
 	mrioc->facts.sge_mod_shift = facts_data->sge_modifier_shift;
 	mrioc->facts.shutdown_timeout =
 	    le16_to_cpu(facts_data->shutdown_timeout);
-	mrioc->facts.diag_trace_sz =
-	    le32_to_cpu(facts_data->diag_trace_size);
-	mrioc->facts.diag_fw_sz =
-	    le32_to_cpu(facts_data->diag_fw_size);
-	mrioc->facts.diag_drvr_sz = le32_to_cpu(facts_data->diag_driver_size);
+
 	mrioc->facts.max_dev_per_tg =
 	    facts_data->max_devices_per_throttle_group;
 	mrioc->facts.io_throttle_data_length =
@@ -3738,94 +3681,6 @@ static const struct {
 	{ MPI3_IOCFACTS_CAPABILITY_MULTIPATH_SUPPORTED, "MultiPath" },
 };
 
-/**
- * mpi3mr_repost_diag_bufs - repost host diag buffers
- * @mrioc: Adapter instance reference
- *
- * repost firmware and trace diag buffers based on global
- * trigger flag from driver page 2
- *
- * Return: 0 on success, non-zero on failures.
- */
-static int mpi3mr_repost_diag_bufs(struct mpi3mr_ioc *mrioc)
-{
-	u64 global_trigger;
-	union mpi3mr_trigger_data prev_trigger_data;
-	struct diag_buffer_desc *trace_hdb = NULL;
-	struct diag_buffer_desc *fw_hdb = NULL;
-	int retval = 0;
-	bool trace_repost_needed = false;
-	bool fw_repost_needed = false;
-	u8 prev_trigger_type;
-
-	retval = mpi3mr_refresh_trigger(mrioc, MPI3_CONFIG_ACTION_READ_CURRENT);
-	if (retval)
-		return -1;
-
-	trace_hdb = mpi3mr_diag_buffer_for_type(mrioc,
-	    MPI3_DIAG_BUFFER_TYPE_TRACE);
-
-	if (trace_hdb &&
-	    trace_hdb->status != MPI3MR_HDB_BUFSTATUS_NOT_ALLOCATED &&
-	    trace_hdb->trigger_type != MPI3MR_HDB_TRIGGER_TYPE_GLOBAL &&
-	    trace_hdb->trigger_type != MPI3MR_HDB_TRIGGER_TYPE_ELEMENT)
-		trace_repost_needed = true;
-
-	fw_hdb = mpi3mr_diag_buffer_for_type(mrioc, MPI3_DIAG_BUFFER_TYPE_FW);
-
-	if (fw_hdb && fw_hdb->status != MPI3MR_HDB_BUFSTATUS_NOT_ALLOCATED &&
-	    fw_hdb->trigger_type != MPI3MR_HDB_TRIGGER_TYPE_GLOBAL &&
-	    fw_hdb->trigger_type != MPI3MR_HDB_TRIGGER_TYPE_ELEMENT)
-		fw_repost_needed = true;
-
-	if (trace_repost_needed || fw_repost_needed) {
-		global_trigger = le64_to_cpu(mrioc->driver_pg2->global_trigger);
-		if (global_trigger &
-		      MPI3_DRIVER2_GLOBALTRIGGER_POST_DIAG_TRACE_DISABLED)
-			trace_repost_needed = false;
-		if (global_trigger &
-		     MPI3_DRIVER2_GLOBALTRIGGER_POST_DIAG_FW_DISABLED)
-			fw_repost_needed = false;
-	}
-
-	if (trace_repost_needed) {
-		prev_trigger_type = trace_hdb->trigger_type;
-		memcpy(&prev_trigger_data, &trace_hdb->trigger_data,
-		    sizeof(trace_hdb->trigger_data));
-		retval = mpi3mr_issue_diag_buf_post(mrioc, trace_hdb);
-		if (!retval) {
-			dprint_init(mrioc, "trace diag buffer reposted");
-			mpi3mr_set_trigger_data_in_hdb(trace_hdb,
-				    MPI3MR_HDB_TRIGGER_TYPE_UNKNOWN, NULL, 1);
-		} else {
-			trace_hdb->trigger_type = prev_trigger_type;
-			memcpy(&trace_hdb->trigger_data, &prev_trigger_data,
-			    sizeof(prev_trigger_data));
-			ioc_err(mrioc, "trace diag buffer repost failed");
-			return -1;
-		}
-	}
-
-	if (fw_repost_needed) {
-		prev_trigger_type = fw_hdb->trigger_type;
-		memcpy(&prev_trigger_data, &fw_hdb->trigger_data,
-		    sizeof(fw_hdb->trigger_data));
-		retval = mpi3mr_issue_diag_buf_post(mrioc, fw_hdb);
-		if (!retval) {
-			dprint_init(mrioc, "firmware diag buffer reposted");
-			mpi3mr_set_trigger_data_in_hdb(fw_hdb,
-				    MPI3MR_HDB_TRIGGER_TYPE_UNKNOWN, NULL, 1);
-		} else {
-			fw_hdb->trigger_type = prev_trigger_type;
-			memcpy(&fw_hdb->trigger_data, &prev_trigger_data,
-			    sizeof(prev_trigger_data));
-			ioc_err(mrioc, "firmware diag buffer repost failed");
-			return -1;
-		}
-	}
-	return retval;
-}
-
 /**
  * mpi3mr_print_ioc_info - Display controller information
  * @mrioc: Adapter instance reference
@@ -4043,7 +3898,6 @@ static int mpi3mr_enable_events(struct mpi3mr_ioc *mrioc)
 	mpi3mr_unmask_events(mrioc, MPI3_EVENT_PREPARE_FOR_RESET);
 	mpi3mr_unmask_events(mrioc, MPI3_EVENT_CABLE_MGMT);
 	mpi3mr_unmask_events(mrioc, MPI3_EVENT_ENERGY_PACK_CHANGE);
-	mpi3mr_unmask_events(mrioc, MPI3_EVENT_DIAGNOSTIC_BUFFER_STATUS_CHANGE);
 
 	retval = mpi3mr_issue_event_notification(mrioc);
 	if (retval)
@@ -4135,18 +3989,9 @@ int mpi3mr_init_ioc(struct mpi3mr_ioc *mrioc)
 		}
 	}
 
-	dprint_init(mrioc, "allocating host diag buffers\n");
-	mpi3mr_alloc_diag_bufs(mrioc);
-
 	dprint_init(mrioc, "allocating ioctl dma buffers\n");
 	mpi3mr_alloc_ioctl_dma_memory(mrioc);
 
-	dprint_init(mrioc, "posting host diag buffers\n");
-	retval = mpi3mr_post_diag_bufs(mrioc);
-
-	if (retval)
-		ioc_warn(mrioc, "failed to post host diag buffers\n");
-
 	if (!mrioc->init_cmds.reply) {
 		retval = mpi3mr_alloc_reply_sense_bufs(mrioc);
 		if (retval) {
@@ -4222,12 +4067,6 @@ int mpi3mr_init_ioc(struct mpi3mr_ioc *mrioc)
 		goto out_failed;
 	}
 
-	retval = mpi3mr_refresh_trigger(mrioc, MPI3_CONFIG_ACTION_READ_CURRENT);
-	if (retval) {
-		ioc_err(mrioc, "failed to refresh triggers\n");
-		goto out_failed;
-	}
-
 	ioc_info(mrioc, "controller initialization completed successfully\n");
 	return retval;
 out_failed:
@@ -4279,7 +4118,7 @@ int mpi3mr_reinit_ioc(struct mpi3mr_ioc *mrioc, u8 is_resume)
 		goto out_failed_noretry;
 	}
 
-	if (is_resume || mrioc->block_on_pci_err) {
+	if (is_resume) {
 		dprint_reset(mrioc, "setting up single ISR\n");
 		retval = mpi3mr_setup_isr(mrioc, 1);
 		if (retval) {
@@ -4305,17 +4144,6 @@ int mpi3mr_reinit_ioc(struct mpi3mr_ioc *mrioc, u8 is_resume)
 
 	mpi3mr_print_ioc_info(mrioc);
 
-	if (is_resume) {
-		dprint_reset(mrioc, "posting host diag buffers\n");
-		retval = mpi3mr_post_diag_bufs(mrioc);
-		if (retval)
-			ioc_warn(mrioc, "failed to post host diag buffers\n");
-	} else {
-		retval = mpi3mr_repost_diag_bufs(mrioc);
-		if (retval)
-			ioc_warn(mrioc, "failed to re post host diag buffers\n");
-	}
-
 	dprint_reset(mrioc, "sending ioc_init\n");
 	retval = mpi3mr_issue_iocinit(mrioc);
 	if (retval) {
@@ -4330,7 +4158,7 @@ int mpi3mr_reinit_ioc(struct mpi3mr_ioc *mrioc, u8 is_resume)
 		goto out_failed;
 	}
 
-	if (is_resume || mrioc->block_on_pci_err) {
+	if (is_resume) {
 		dprint_reset(mrioc, "setting up multiple ISR\n");
 		retval = mpi3mr_setup_isr(mrioc, 0);
 		if (retval) {
@@ -4581,7 +4409,6 @@ void mpi3mr_free_mem(struct mpi3mr_ioc *mrioc)
 {
 	u16 i;
 	struct mpi3mr_intr_info *intr_info;
-	struct diag_buffer_desc *diag_buffer;
 
 	mpi3mr_free_enclosure_list(mrioc);
 	mpi3mr_free_ioctl_dma_memory(mrioc);
@@ -4716,19 +4543,6 @@ void mpi3mr_free_mem(struct mpi3mr_ioc *mrioc)
 		mrioc->pel_seqnum_virt = NULL;
 	}
 
-	for (i = 0; i < MPI3MR_MAX_NUM_HDB; i++) {
-		diag_buffer = &mrioc->diag_buffers[i];
-		if (diag_buffer->addr) {
-			dma_free_coherent(&mrioc->pdev->dev,
-			    diag_buffer->size, diag_buffer->addr,
-			    diag_buffer->dma_addr);
-			diag_buffer->addr = NULL;
-			diag_buffer->size = 0;
-			diag_buffer->type = 0;
-			diag_buffer->status = 0;
-		}
-	}
-
 	kfree(mrioc->throttle_groups);
 	mrioc->throttle_groups = NULL;
 
@@ -4818,8 +4632,7 @@ void mpi3mr_cleanup_ioc(struct mpi3mr_ioc *mrioc)
 
 	ioc_state = mpi3mr_get_iocstate(mrioc);
 
-	if (!mrioc->unrecoverable && !mrioc->reset_in_progress &&
-	    !mrioc->pci_err_recovery &&
+	if ((!mrioc->unrecoverable) && (!mrioc->reset_in_progress) &&
 	    (ioc_state == MRIOC_STATE_READY)) {
 		if (mpi3mr_issue_and_process_mur(mrioc,
 		    MPI3MR_RESET_FROM_CTLR_CLEANUP))
@@ -5167,7 +4980,6 @@ int mpi3mr_soft_reset_handler(struct mpi3mr_ioc *mrioc,
 	int retval = 0, i;
 	unsigned long flags;
 	u32 host_diagnostic, timeout = MPI3_SYSIF_DIAG_SAVE_TIMEOUT * 10;
-	union mpi3mr_trigger_data trigger_data;
 
 	/* Block the reset handler until diag save in progress*/
 	dprint_reset(mrioc,
@@ -5200,16 +5012,10 @@ int mpi3mr_soft_reset_handler(struct mpi3mr_ioc *mrioc,
 	mrioc->reset_in_progress = 1;
 	mrioc->stop_bsgs = 1;
 	mrioc->prev_reset_result = -1;
-	memset(&trigger_data, 0, sizeof(trigger_data));
 
 	if ((!snapdump) && (reset_reason != MPI3MR_RESET_FROM_FAULT_WATCH) &&
 	    (reset_reason != MPI3MR_RESET_FROM_FIRMWARE) &&
 	    (reset_reason != MPI3MR_RESET_FROM_CIACTIV_FAULT)) {
-		mpi3mr_set_trigger_data_in_all_hdb(mrioc,
-		    MPI3MR_HDB_TRIGGER_TYPE_SOFT_RESET, NULL, 0);
-		dprint_reset(mrioc,
-		    "soft_reset_handler: releasing host diagnostic buffers\n");
-		mpi3mr_release_diag_bufs(mrioc, 0);
 		for (i = 0; i < MPI3_EVENT_NOTIFY_EVENTMASK_WORDS; i++)
 			mrioc->event_masks[i] = -1;
 
@@ -5226,8 +5032,6 @@ int mpi3mr_soft_reset_handler(struct mpi3mr_ioc *mrioc,
 		retval = mpi3mr_issue_reset(mrioc,
 		    MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT, reset_reason);
 		if (!retval) {
-			trigger_data.fault = (readl(&mrioc->sysif_regs->fault) &
-				      MPI3_SYSIF_FAULT_CODE_MASK);
 			do {
 				host_diagnostic =
 				    readl(&mrioc->sysif_regs->host_diagnostic);
@@ -5236,8 +5040,6 @@ int mpi3mr_soft_reset_handler(struct mpi3mr_ioc *mrioc,
 					break;
 				msleep(100);
 			} while (--timeout);
-			mpi3mr_set_trigger_data_in_all_hdb(mrioc,
-			    MPI3MR_HDB_TRIGGER_TYPE_FAULT, &trigger_data, 0);
 		}
 	}
 
@@ -5273,15 +5075,6 @@ int mpi3mr_soft_reset_handler(struct mpi3mr_ioc *mrioc,
 		mrioc->prepare_for_reset_timeout_counter = 0;
 	}
 	mpi3mr_memset_buffers(mrioc);
-	mpi3mr_release_diag_bufs(mrioc, 1);
-	mrioc->fw_release_trigger_active = false;
-	mrioc->trace_release_trigger_active = false;
-	mrioc->snapdump_trigger_active = false;
-	mpi3mr_set_trigger_data_in_all_hdb(mrioc,
-	    MPI3MR_HDB_TRIGGER_TYPE_SOFT_RESET, NULL, 0);
-
-	dprint_reset(mrioc,
-	    "soft_reset_handler: reinitializing the controller\n");
 	retval = mpi3mr_reinit_ioc(mrioc, 0);
 	if (retval) {
 		pr_err(IOCNAME "reinit after soft reset failed: reason %d\n",
@@ -6161,64 +5954,3 @@ int mpi3mr_cfg_get_driver_pg1(struct mpi3mr_ioc *mrioc,
 out_failed:
 	return -1;
 }
-
-/**
- * mpi3mr_cfg_get_driver_pg2 - Read current driver page2
- * @mrioc: Adapter instance reference
- * @driver_pg2: Pointer to return driver page 2
- * @pg_sz: Size of the memory allocated to the page pointer
- * @page_action: Page action
- *
- * This is handler for config page read for the driver page2.
- * This routine checks ioc_status to decide whether the page
- * read is success or not.
- *
- * Return: 0 on success, non-zero on failure.
- */
-int mpi3mr_cfg_get_driver_pg2(struct mpi3mr_ioc *mrioc,
-	struct mpi3_driver_page2 *driver_pg2, u16 pg_sz, u8 page_action)
-{
-	struct mpi3_config_page_header cfg_hdr;
-	struct mpi3_config_request cfg_req;
-	u16 ioc_status = 0;
-
-	memset(driver_pg2, 0, pg_sz);
-	memset(&cfg_hdr, 0, sizeof(cfg_hdr));
-	memset(&cfg_req, 0, sizeof(cfg_req));
-
-	cfg_req.function = MPI3_FUNCTION_CONFIG;
-	cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
-	cfg_req.page_type = MPI3_CONFIG_PAGETYPE_DRIVER;
-	cfg_req.page_number = 2;
-	cfg_req.page_address = 0;
-	cfg_req.page_version = MPI3_DRIVER2_PAGEVERSION;
-
-	if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
-	    MPI3MR_INTADMCMD_TIMEOUT, &ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
-		ioc_err(mrioc, "driver page2 header read failed\n");
-		goto out_failed;
-	}
-	if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
-		ioc_err(mrioc, "driver page2 header read failed with\n"
-			       "ioc_status(0x%04x)\n",
-		    ioc_status);
-		goto out_failed;
-	}
-	cfg_req.action = page_action;
-
-	if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
-	    MPI3MR_INTADMCMD_TIMEOUT, &ioc_status, driver_pg2, pg_sz)) {
-		ioc_err(mrioc, "driver page2 read failed\n");
-		goto out_failed;
-	}
-	if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
-		ioc_err(mrioc, "driver page2 read failed with\n"
-			       "ioc_status(0x%04x)\n",
-		    ioc_status);
-		goto out_failed;
-	}
-	return 0;
-out_failed:
-	return -1;
-}
-
diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c
index 69b14918de59..bce639a6cca1 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_os.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_os.c
@@ -241,40 +241,6 @@ static void mpi3mr_fwevt_add_to_list(struct mpi3mr_ioc *mrioc,
 	spin_unlock_irqrestore(&mrioc->fwevt_lock, flags);
 }
 
-/**
- * mpi3mr_hdb_trigger_data_event - Add hdb trigger data event to
- * the list
- * @mrioc: Adapter instance reference
- * @event_data: Event data
- *
- * Add the given hdb trigger data event to the firmware event
- * list.
- *
- * Return: Nothing.
- */
-void mpi3mr_hdb_trigger_data_event(struct mpi3mr_ioc *mrioc,
-	struct trigger_event_data *event_data)
-{
-	struct mpi3mr_fwevt *fwevt;
-	u16 sz = sizeof(*event_data);
-
-	fwevt = mpi3mr_alloc_fwevt(sz);
-	if (!fwevt) {
-		ioc_warn(mrioc, "failed to queue hdb trigger data event\n");
-		return;
-	}
-
-	fwevt->mrioc = mrioc;
-	fwevt->event_id = MPI3MR_DRIVER_EVENT_PROCESS_TRIGGER;
-	fwevt->send_ack = 0;
-	fwevt->process_evt = 1;
-	fwevt->evt_ctx = 0;
-	fwevt->event_data_size = sz;
-	memcpy(fwevt->event_data, event_data, sz);
-
-	mpi3mr_fwevt_add_to_list(mrioc, fwevt);
-}
-
 /**
  * mpi3mr_fwevt_del_from_list - Delete firmware event from list
  * @mrioc: Adapter instance reference
@@ -932,8 +898,6 @@ void mpi3mr_remove_tgtdev_from_host(struct mpi3mr_ioc *mrioc,
 		}
 	} else
 		mpi3mr_remove_tgtdev_from_sas_transport(mrioc, tgtdev);
-	mpi3mr_global_trigger(mrioc,
-	    MPI3_DRIVER2_GLOBALTRIGGER_DEVICE_REMOVAL_ENABLED);
 
 	ioc_info(mrioc, "%s :Removed handle(0x%04x), wwid(0x%016llx)\n",
 	    __func__, tgtdev->dev_handle, (unsigned long long)tgtdev->wwid);
@@ -956,7 +920,7 @@ static int mpi3mr_report_tgtdev_to_host(struct mpi3mr_ioc *mrioc,
 	int retval = 0;
 	struct mpi3mr_tgt_dev *tgtdev;
 
-	if (mrioc->reset_in_progress || mrioc->pci_err_recovery)
+	if (mrioc->reset_in_progress)
 		return -1;
 
 	tgtdev = mpi3mr_get_tgtdev_by_perst_id(mrioc, perst_id);
@@ -1469,62 +1433,6 @@ struct mpi3mr_enclosure_node *mpi3mr_enclosure_find_by_handle(
 	return r;
 }
 
-/**
- * mpi3mr_process_trigger_data_event_bh - Process trigger event
- * data
- * @mrioc: Adapter instance reference
- * @event_data: Event data
- *
- * This function releases diage buffers or issues diag fault
- * based on trigger conditions
- *
- * Return: Nothing
- */
-static void mpi3mr_process_trigger_data_event_bh(struct mpi3mr_ioc *mrioc,
-	struct trigger_event_data *event_data)
-{
-	struct diag_buffer_desc *trace_hdb = event_data->trace_hdb;
-	struct diag_buffer_desc *fw_hdb = event_data->fw_hdb;
-	unsigned long flags;
-	int retval = 0;
-	u8 trigger_type = event_data->trigger_type;
-	union mpi3mr_trigger_data *trigger_data =
-		&event_data->trigger_specific_data;
-
-	if (event_data->snapdump)  {
-		if (trace_hdb)
-			mpi3mr_set_trigger_data_in_hdb(trace_hdb, trigger_type,
-			    trigger_data, 1);
-		if (fw_hdb)
-			mpi3mr_set_trigger_data_in_hdb(fw_hdb, trigger_type,
-			    trigger_data, 1);
-		mpi3mr_soft_reset_handler(mrioc,
-			    MPI3MR_RESET_FROM_TRIGGER, 1);
-		return;
-	}
-
-	if (trace_hdb) {
-		retval = mpi3mr_issue_diag_buf_release(mrioc, trace_hdb);
-		if (!retval) {
-			mpi3mr_set_trigger_data_in_hdb(trace_hdb, trigger_type,
-			    trigger_data, 1);
-		}
-		spin_lock_irqsave(&mrioc->trigger_lock, flags);
-		mrioc->trace_release_trigger_active = false;
-		spin_unlock_irqrestore(&mrioc->trigger_lock, flags);
-	}
-	if (fw_hdb) {
-		retval = mpi3mr_issue_diag_buf_release(mrioc, fw_hdb);
-		if (!retval) {
-			mpi3mr_set_trigger_data_in_hdb(fw_hdb, trigger_type,
-		    trigger_data, 1);
-		}
-		spin_lock_irqsave(&mrioc->trigger_lock, flags);
-		mrioc->fw_release_trigger_active = false;
-		spin_unlock_irqrestore(&mrioc->trigger_lock, flags);
-	}
-}
-
 /**
  * mpi3mr_encldev_add_chg_evt_debug - debug for enclosure event
  * @mrioc: Adapter instance reference
@@ -2007,7 +1915,6 @@ static void mpi3mr_fwevt_bh(struct mpi3mr_ioc *mrioc,
 	struct mpi3_device_page0 *dev_pg0 = NULL;
 	u16 perst_id, handle, dev_info;
 	struct mpi3_device0_sas_sata_format *sasinf = NULL;
-	unsigned int timeout;
 
 	mpi3mr_fwevt_del_from_list(mrioc, fwevt);
 	mrioc->current_event = fwevt;
@@ -2098,18 +2005,8 @@ static void mpi3mr_fwevt_bh(struct mpi3mr_ioc *mrioc,
 	}
 	case MPI3_EVENT_WAIT_FOR_DEVICES_TO_REFRESH:
 	{
-		timeout = MPI3MR_RESET_TIMEOUT * 2;
-		while ((mrioc->device_refresh_on || mrioc->block_on_pci_err) &&
-		    !mrioc->unrecoverable && !mrioc->pci_err_recovery) {
+		while (mrioc->device_refresh_on)
 			msleep(500);
-			if (!timeout--) {
-				mrioc->unrecoverable = 1;
-				break;
-			}
-		}
-
-		if (mrioc->unrecoverable || mrioc->pci_err_recovery)
-			break;
 
 		dprint_event_bh(mrioc,
 		    "scan for non responding and newly added devices after soft reset started\n");
@@ -2122,12 +2019,6 @@ static void mpi3mr_fwevt_bh(struct mpi3mr_ioc *mrioc,
 		    "scan for non responding and newly added devices after soft reset completed\n");
 		break;
 	}
-	case MPI3MR_DRIVER_EVENT_PROCESS_TRIGGER:
-	{
-		mpi3mr_process_trigger_data_event_bh(mrioc,
-		    (struct trigger_event_data *)fwevt->event_data);
-		break;
-	}
 	default:
 		break;
 	}
@@ -2966,7 +2857,6 @@ void mpi3mr_os_handle_events(struct mpi3mr_ioc *mrioc,
 		ack_req = 1;
 
 	evt_type = event_reply->event;
-	mpi3mr_event_trigger(mrioc, event_reply->event);
 
 	switch (evt_type) {
 	case MPI3_EVENT_DEVICE_ADDED:
@@ -3005,11 +2895,6 @@ void mpi3mr_os_handle_events(struct mpi3mr_ioc *mrioc,
 		ack_req = 0;
 		break;
 	}
-	case MPI3_EVENT_DIAGNOSTIC_BUFFER_STATUS_CHANGE:
-	{
-		mpi3mr_hdbstatuschg_evt_th(mrioc, event_reply);
-		break;
-	}
 	case MPI3_EVENT_DEVICE_INFO_CHANGED:
 	case MPI3_EVENT_LOG_DATA:
 	case MPI3_EVENT_ENCL_DEVICE_STATUS_CHANGE:
@@ -3273,7 +3158,6 @@ void mpi3mr_process_op_reply_desc(struct mpi3mr_ioc *mrioc,
 		    MPI3_REPLY_DESCRIPT_STATUS_IOCSTATUS_LOGINFOAVAIL)
 			ioc_loginfo = le32_to_cpu(status_desc->ioc_log_info);
 		ioc_status &= MPI3_REPLY_DESCRIPT_STATUS_IOCSTATUS_STATUS_MASK;
-		mpi3mr_reply_trigger(mrioc, ioc_status, ioc_loginfo);
 		break;
 	case MPI3_REPLY_DESCRIPT_FLAGS_TYPE_ADDRESS_REPLY:
 		addr_desc = (struct mpi3_address_reply_descriptor *)reply_desc;
@@ -3302,12 +3186,6 @@ void mpi3mr_process_op_reply_desc(struct mpi3mr_ioc *mrioc,
 		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);
-		if (sense_buf) {
-			scsi_normalize_sense(sense_buf, sense_count, &sshdr);
-			mpi3mr_scsisense_trigger(mrioc, sshdr.sense_key,
-			    sshdr.asc, sshdr.ascq);
-		}
-		mpi3mr_reply_trigger(mrioc, ioc_status, ioc_loginfo);
 		break;
 	case MPI3_REPLY_DESCRIPT_FLAGS_TYPE_SUCCESS:
 		success_desc = (struct mpi3_success_reply_descriptor *)reply_desc;
@@ -3807,13 +3685,6 @@ int mpi3mr_issue_tm(struct mpi3mr_ioc *mrioc, u8 tm_type,
 		mutex_unlock(&drv_cmd->mutex);
 		goto out;
 	}
-	if (mrioc->block_on_pci_err) {
-		retval = -1;
-		dprint_tm(mrioc, "sending task management failed due to\n"
-				"pci error recovery in progress\n");
-		mutex_unlock(&drv_cmd->mutex);
-		goto out;
-	}
 
 	drv_cmd->state = MPI3MR_CMD_PENDING;
 	drv_cmd->is_waiting = 1;
@@ -3940,8 +3811,6 @@ int mpi3mr_issue_tm(struct mpi3mr_ioc *mrioc, u8 tm_type,
 	default:
 		break;
 	}
-	mpi3mr_global_trigger(mrioc,
-	    MPI3_DRIVER2_GLOBALTRIGGER_TASK_MANAGEMENT_ENABLED);
 
 out_unlock:
 	drv_cmd->state = MPI3MR_CMD_NOTUSED;
@@ -4199,7 +4068,6 @@ static int mpi3mr_eh_bus_reset(struct scsi_cmnd *scmd)
 	struct mpi3mr_sdev_priv_data *sdev_priv_data;
 	u8 dev_type = MPI3_DEVICE_DEVFORM_VD;
 	int retval = FAILED;
-	unsigned int timeout = MPI3MR_RESET_TIMEOUT;
 
 	sdev_priv_data = scmd->device->hostdata;
 	if (sdev_priv_data && sdev_priv_data->tgt_priv_data) {
@@ -4210,24 +4078,12 @@ static int mpi3mr_eh_bus_reset(struct scsi_cmnd *scmd)
 	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)) {
-			while (mrioc->reset_in_progress ||
-			       mrioc->prepare_for_reset ||
-			       mrioc->block_on_pci_err) {
-				ssleep(1);
-				if (!timeout--) {
-					retval = FAILED;
-					goto out;
-				}
-			}
+		if (!mpi3mr_get_fw_pending_ios(mrioc))
 			retval = SUCCESS;
-			goto out;
-		}
 	}
 	if (retval == FAILED)
 		mpi3mr_print_pending_host_io(mrioc);
 
-out:
 	sdev_printk(KERN_INFO, scmd->device,
 		"Bus reset is %s for scmd(%p)\n",
 		((retval == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
@@ -4910,8 +4766,7 @@ static int mpi3mr_qcmd(struct Scsi_Host *shost,
 		goto out;
 	}
 
-	if (mrioc->reset_in_progress || mrioc->prepare_for_reset
-	    || mrioc->block_on_pci_err) {
+	if (mrioc->reset_in_progress) {
 		retval = SCSI_MLQUEUE_HOST_BUSY;
 		goto out;
 	}
@@ -5394,14 +5249,7 @@ static void mpi3mr_remove(struct pci_dev *pdev)
 	while (mrioc->reset_in_progress || mrioc->is_driver_loading)
 		ssleep(1);
 
-	if (mrioc->block_on_pci_err) {
-		mrioc->block_on_pci_err = false;
-		scsi_unblock_requests(shost);
-		mrioc->unrecoverable = 1;
-	}
-
-	if (!pci_device_is_present(mrioc->pdev) ||
-	    mrioc->pci_err_recovery) {
+	if (!pci_device_is_present(mrioc->pdev)) {
 		mrioc->unrecoverable = 1;
 		mpi3mr_flush_cmds_for_unrecovered_controller(mrioc);
 	}
@@ -5585,197 +5433,6 @@ mpi3mr_resume(struct device *dev)
 	return 0;
 }
 
-/**
- * mpi3mr_pcierr_error_detected - PCI error detected callback
- * @pdev: PCI device instance
- * @state: channel state
- *
- * This function is called by the PCI error recovery driver and
- * based on the state passed the driver decides what actions to
- * be recommended back to PCI driver.
- *
- * For all of the states if there is no valid mrioc or scsi host
- * references in the PCI device then this function will return
- * the result as disconnect.
- *
- * For normal state, this function will return the result as can
- * recover.
- *
- * For frozen state, this function will block for any pending
- * controller initialization or re-initialization to complete,
- * stop any new interactions with the controller and return
- * status as reset required.
- *
- * For permanent failure state, this function will mark the
- * controller as unrecoverable and return status as disconnect.
- *
- * Returns: PCI_ERS_RESULT_NEED_RESET or CAN_RECOVER or
- * DISCONNECT based on the controller state.
- */
-static pci_ers_result_t
-mpi3mr_pcierr_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
-{
-	struct Scsi_Host *shost;
-	struct mpi3mr_ioc *mrioc;
-	unsigned int timeout = MPI3MR_RESET_TIMEOUT;
-
-	dev_info(&pdev->dev, "%s: callback invoked state(%d)\n", __func__,
-	    state);
-
-	shost = pci_get_drvdata(pdev);
-	mrioc = shost_priv(shost);
-
-	switch (state) {
-	case pci_channel_io_normal:
-		return PCI_ERS_RESULT_CAN_RECOVER;
-	case pci_channel_io_frozen:
-		mrioc->pci_err_recovery = true;
-		mrioc->block_on_pci_err = true;
-		do {
-			if (mrioc->reset_in_progress || mrioc->is_driver_loading)
-				ssleep(1);
-			else
-				break;
-		} while (--timeout);
-
-		if (!timeout) {
-			mrioc->pci_err_recovery = true;
-			mrioc->block_on_pci_err = true;
-			mrioc->unrecoverable = 1;
-			mpi3mr_stop_watchdog(mrioc);
-			mpi3mr_flush_cmds_for_unrecovered_controller(mrioc);
-			return PCI_ERS_RESULT_DISCONNECT;
-		}
-
-		scsi_block_requests(mrioc->shost);
-		mpi3mr_stop_watchdog(mrioc);
-		mpi3mr_cleanup_resources(mrioc);
-		return PCI_ERS_RESULT_NEED_RESET;
-	case pci_channel_io_perm_failure:
-		mrioc->pci_err_recovery = true;
-		mrioc->block_on_pci_err = true;
-		mrioc->unrecoverable = 1;
-		mpi3mr_stop_watchdog(mrioc);
-		mpi3mr_flush_cmds_for_unrecovered_controller(mrioc);
-		return PCI_ERS_RESULT_DISCONNECT;
-	default:
-		return PCI_ERS_RESULT_DISCONNECT;
-	}
-}
-
-/**
- * mpi3mr_pcierr_slot_reset - Post slot reset callback
- * @pdev: PCI device instance
- *
- * This function is called by the PCI error recovery driver
- * after a slot or link reset issued by it for the recovery, the
- * driver is expected to bring back the controller and
- * initialize it.
- *
- * This function restores PCI state and reinitializes controller
- * resources and the controller, this blocks for any pending
- * reset to complete.
- *
- * Returns: PCI_ERS_RESULT_DISCONNECT on failure or
- * PCI_ERS_RESULT_RECOVERED
- */
-static pci_ers_result_t mpi3mr_pcierr_slot_reset(struct pci_dev *pdev)
-{
-	struct Scsi_Host *shost;
-	struct mpi3mr_ioc *mrioc;
-	unsigned int timeout = MPI3MR_RESET_TIMEOUT;
-
-	dev_info(&pdev->dev, "%s: callback invoked\n", __func__);
-
-	shost = pci_get_drvdata(pdev);
-	mrioc = shost_priv(shost);
-
-	do {
-		if (mrioc->reset_in_progress)
-			ssleep(1);
-		else
-			break;
-	} while (--timeout);
-
-	if (!timeout)
-		goto out_failed;
-
-	pci_restore_state(pdev);
-
-	if (mpi3mr_setup_resources(mrioc)) {
-		ioc_err(mrioc, "setup resources failed\n");
-		goto out_failed;
-	}
-	mrioc->unrecoverable = 0;
-	mrioc->pci_err_recovery = false;
-
-	if (mpi3mr_soft_reset_handler(mrioc, MPI3MR_RESET_FROM_FIRMWARE, 0))
-		goto out_failed;
-
-	return PCI_ERS_RESULT_RECOVERED;
-
-out_failed:
-	mrioc->unrecoverable = 1;
-	mrioc->block_on_pci_err = false;
-	scsi_unblock_requests(shost);
-	mpi3mr_start_watchdog(mrioc);
-	return PCI_ERS_RESULT_DISCONNECT;
-}
-
-/**
- * mpi3mr_pcierr_resume - PCI error recovery resume
- * callback
- * @pdev: PCI device instance
- *
- * This function enables all I/O and IOCTLs post reset issued as
- * part of the PCI error recovery
- *
- * Return: Nothing.
- */
-static void mpi3mr_pcierr_resume(struct pci_dev *pdev)
-{
-	struct Scsi_Host *shost;
-	struct mpi3mr_ioc *mrioc;
-
-	dev_info(&pdev->dev, "%s: callback invoked\n", __func__);
-
-	shost = pci_get_drvdata(pdev);
-	mrioc = shost_priv(shost);
-
-	if (mrioc->block_on_pci_err) {
-		mrioc->block_on_pci_err = false;
-		scsi_unblock_requests(shost);
-		mpi3mr_start_watchdog(mrioc);
-	}
-}
-
-/**
- * mpi3mr_pcierr_mmio_enabled - PCI error recovery callback
- * @pdev: PCI device instance
- *
- * This is called only if mpi3mr_pcierr_error_detected returns
- * PCI_ERS_RESULT_CAN_RECOVER.
- *
- * Return: PCI_ERS_RESULT_DISCONNECT when the controller is
- * unrecoverable or when the shost/mrioc reference cannot be
- * found, else return PCI_ERS_RESULT_RECOVERED
- */
-static pci_ers_result_t mpi3mr_pcierr_mmio_enabled(struct pci_dev *pdev)
-{
-	struct Scsi_Host *shost;
-	struct mpi3mr_ioc *mrioc;
-
-	dev_info(&pdev->dev, "%s: callback invoked\n", __func__);
-
-	shost = pci_get_drvdata(pdev);
-	mrioc = shost_priv(shost);
-
-	if (mrioc->unrecoverable)
-		return PCI_ERS_RESULT_DISCONNECT;
-
-	return PCI_ERS_RESULT_RECOVERED;
-}
-
 static const struct pci_device_id mpi3mr_pci_id_table[] = {
 	{
 		PCI_DEVICE_SUB(MPI3_MFGPAGE_VENDORID_BROADCOM,
@@ -5793,13 +5450,6 @@ static const struct pci_device_id mpi3mr_pci_id_table[] = {
 };
 MODULE_DEVICE_TABLE(pci, mpi3mr_pci_id_table);
 
-static struct pci_error_handlers mpi3mr_err_handler = {
-	.error_detected = mpi3mr_pcierr_error_detected,
-	.mmio_enabled = mpi3mr_pcierr_mmio_enabled,
-	.slot_reset = mpi3mr_pcierr_slot_reset,
-	.resume = mpi3mr_pcierr_resume,
-};
-
 static SIMPLE_DEV_PM_OPS(mpi3mr_pm_ops, mpi3mr_suspend, mpi3mr_resume);
 
 static struct pci_driver mpi3mr_pci_driver = {
@@ -5808,7 +5458,6 @@ static struct pci_driver mpi3mr_pci_driver = {
 	.probe = mpi3mr_probe,
 	.remove = mpi3mr_remove,
 	.shutdown = mpi3mr_shutdown,
-	.err_handler = &mpi3mr_err_handler,
 	.driver.pm = &mpi3mr_pm_ops,
 };
 
diff --git a/drivers/scsi/mpi3mr/mpi3mr_transport.c b/drivers/scsi/mpi3mr/mpi3mr_transport.c
index ccd23def2e0c..82aa4e418c5a 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_transport.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_transport.c
@@ -151,11 +151,6 @@ static int mpi3mr_report_manufacture(struct mpi3mr_ioc *mrioc,
 		return -EFAULT;
 	}
 
-	if (mrioc->pci_err_recovery) {
-		ioc_err(mrioc, "%s: pci error recovery in progress!\n", __func__);
-		return -EFAULT;
-	}
-
 	data_out_sz = sizeof(struct rep_manu_request);
 	data_in_sz = sizeof(struct rep_manu_reply);
 	data_out = dma_alloc_coherent(&mrioc->pdev->dev,
@@ -795,12 +790,6 @@ static int mpi3mr_set_identify(struct mpi3mr_ioc *mrioc, u16 handle,
 		return -EFAULT;
 	}
 
-	if (mrioc->pci_err_recovery) {
-		ioc_err(mrioc, "%s: pci error recovery in progress!\n",
-		    __func__);
-		return -EFAULT;
-	}
-
 	if ((mpi3mr_cfg_get_dev_pg0(mrioc, &ioc_status, &device_pg0,
 	    sizeof(device_pg0), MPI3_DEVICE_PGAD_FORM_HANDLE, handle))) {
 		ioc_err(mrioc, "%s: device page0 read failed\n", __func__);
@@ -1018,9 +1007,6 @@ mpi3mr_alloc_hba_port(struct mpi3mr_ioc *mrioc, u16 port_id)
 	hba_port->port_id = port_id;
 	ioc_info(mrioc, "hba_port entry: %p, port: %d is added to hba_port list\n",
 	    hba_port, hba_port->port_id);
-	if (mrioc->reset_in_progress ||
-		mrioc->pci_err_recovery)
-		hba_port->flags = MPI3MR_HBA_PORT_FLAG_NEW;
 	list_add_tail(&hba_port->list, &mrioc->hba_port_table_list);
 	return hba_port;
 }
@@ -1069,7 +1055,7 @@ void mpi3mr_update_links(struct mpi3mr_ioc *mrioc,
 	struct mpi3mr_sas_node *mr_sas_node;
 	struct mpi3mr_sas_phy *mr_sas_phy;
 
-	if (mrioc->reset_in_progress || mrioc->pci_err_recovery)
+	if (mrioc->reset_in_progress)
 		return;
 
 	spin_lock_irqsave(&mrioc->sas_node_lock, flags);
@@ -1367,7 +1353,7 @@ static struct mpi3mr_sas_port *mpi3mr_sas_port_add(struct mpi3mr_ioc *mrioc,
 	mpi3mr_sas_port_sanity_check(mrioc, mr_sas_node,
 	    mr_sas_port->remote_identify.sas_address, hba_port);
 
-	if (mr_sas_node->num_phys >= sizeof(mr_sas_port->phy_mask) * 8)
+	if (mr_sas_node->num_phys > sizeof(mr_sas_port->phy_mask) * 8)
 		ioc_info(mrioc, "max port count %u could be too high\n",
 		    mr_sas_node->num_phys);
 
@@ -1377,7 +1363,7 @@ static struct mpi3mr_sas_port *mpi3mr_sas_port_add(struct mpi3mr_ioc *mrioc,
 		    (mr_sas_node->phy[i].hba_port != hba_port))
 			continue;
 
-		if (i >= sizeof(mr_sas_port->phy_mask) * 8) {
+		if (i > sizeof(mr_sas_port->phy_mask) * 8) {
 			ioc_warn(mrioc, "skipping port %u, max allowed value is %zu\n",
 			    i, sizeof(mr_sas_port->phy_mask) * 8);
 			goto out_fail;
@@ -1992,7 +1978,7 @@ int mpi3mr_expander_add(struct mpi3mr_ioc *mrioc, u16 handle)
 	if (!handle)
 		return -1;
 
-	if (mrioc->reset_in_progress || mrioc->pci_err_recovery)
+	if (mrioc->reset_in_progress)
 		return -1;
 
 	if ((mpi3mr_cfg_get_sas_exp_pg0(mrioc, &ioc_status, &expander_pg0,
@@ -2198,7 +2184,7 @@ void mpi3mr_expander_node_remove(struct mpi3mr_ioc *mrioc,
 	/* remove sibling ports attached to this expander */
 	list_for_each_entry_safe(mr_sas_port, next,
 	   &sas_expander->sas_port_list, port_list) {
-		if (mrioc->reset_in_progress || mrioc->pci_err_recovery)
+		if (mrioc->reset_in_progress)
 			return;
 		if (mr_sas_port->remote_identify.device_type ==
 		    SAS_END_DEVICE)
@@ -2248,7 +2234,7 @@ void mpi3mr_expander_remove(struct mpi3mr_ioc *mrioc, u64 sas_address,
 	struct mpi3mr_sas_node *sas_expander;
 	unsigned long flags;
 
-	if (mrioc->reset_in_progress || mrioc->pci_err_recovery)
+	if (mrioc->reset_in_progress)
 		return;
 
 	if (!hba_port)
@@ -2559,11 +2545,6 @@ static int mpi3mr_get_expander_phy_error_log(struct mpi3mr_ioc *mrioc,
 		return -EFAULT;
 	}
 
-	if (mrioc->pci_err_recovery) {
-		ioc_err(mrioc, "%s: pci error recovery in progress!\n", __func__);
-		return -EFAULT;
-	}
-
 	data_out_sz = sizeof(struct phy_error_log_request);
 	data_in_sz = sizeof(struct phy_error_log_reply);
 	sz = data_out_sz + data_in_sz;
@@ -2823,12 +2804,6 @@ mpi3mr_expander_phy_control(struct mpi3mr_ioc *mrioc,
 		return -EFAULT;
 	}
 
-	if (mrioc->pci_err_recovery) {
-		ioc_err(mrioc, "%s: pci error recovery in progress!\n",
-		    __func__);
-		return -EFAULT;
-	}
-
 	data_out_sz = sizeof(struct phy_control_request);
 	data_in_sz = sizeof(struct phy_control_reply);
 	sz = data_out_sz + data_in_sz;
@@ -3252,12 +3227,6 @@ mpi3mr_transport_smp_handler(struct bsg_job *job, struct Scsi_Host *shost,
 		goto out;
 	}
 
-	if (mrioc->pci_err_recovery) {
-		ioc_err(mrioc, "%s: pci error recovery in progress!\n", __func__);
-		rc = -EFAULT;
-		goto out;
-	}
-
 	rc = mpi3mr_map_smp_buffer(&mrioc->pdev->dev, &job->request_payload,
 	    &dma_addr_out, &dma_len_out, &addr_out);
 	if (rc)
diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
index 97c2472cd434..870ec2cb4af4 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -2680,6 +2680,12 @@ scsih_device_configure(struct scsi_device *sdev, struct queue_limits *lim)
 		pcie_device_put(pcie_device);
 		spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
 		mpt3sas_scsih_change_queue_depth(sdev, qdepth);
+		/* Enable QUEUE_FLAG_NOMERGES flag, so that IOs won't be
+		 ** merged and can eliminate holes created during merging
+		 ** operation.
+		 **/
+		blk_queue_flag_set(QUEUE_FLAG_NOMERGES,
+				sdev->request_queue);
 		lim->virt_boundary_mask = ioc->page_size - 1;
 		return 0;
 	}
diff --git a/drivers/scsi/pcmcia/aha152x_stub.c b/drivers/scsi/pcmcia/aha152x_stub.c
index 1b54ba51a485..6a6621728c69 100644
--- a/drivers/scsi/pcmcia/aha152x_stub.c
+++ b/drivers/scsi/pcmcia/aha152x_stub.c
@@ -75,7 +75,6 @@ module_param(synchronous, int, 0);
 module_param(reset_delay, int, 0);
 module_param(ext_trans, int, 0);
 
-MODULE_DESCRIPTION("Adaptec AHA152X-compatible PCMCIA SCSI card driver");
 MODULE_LICENSE("Dual MPL/GPL");
 
 /*====================================================================*/
diff --git a/drivers/scsi/pm8001/pm8001_sas.c b/drivers/scsi/pm8001/pm8001_sas.c
index ee2da8e49d4c..a5a31dfa4512 100644
--- a/drivers/scsi/pm8001/pm8001_sas.c
+++ b/drivers/scsi/pm8001/pm8001_sas.c
@@ -166,6 +166,7 @@ int pm8001_phy_control(struct asd_sas_phy *sas_phy, enum phy_func func,
 	unsigned long flags;
 	pm8001_ha = sas_phy->ha->lldd_ha;
 	phy = &pm8001_ha->phy[phy_id];
+	pm8001_ha->phy[phy_id].enable_completion = &completion;
 
 	if (PM8001_CHIP_DISP->fatal_errors(pm8001_ha)) {
 		/*
@@ -189,7 +190,6 @@ int pm8001_phy_control(struct asd_sas_phy *sas_phy, enum phy_func func,
 				rates->maximum_linkrate;
 		}
 		if (pm8001_ha->phy[phy_id].phy_state ==  PHY_LINK_DISABLE) {
-			pm8001_ha->phy[phy_id].enable_completion = &completion;
 			PM8001_CHIP_DISP->phy_start_req(pm8001_ha, phy_id);
 			wait_for_completion(&completion);
 		}
@@ -198,7 +198,6 @@ int pm8001_phy_control(struct asd_sas_phy *sas_phy, enum phy_func func,
 		break;
 	case PHY_FUNC_HARD_RESET:
 		if (pm8001_ha->phy[phy_id].phy_state == PHY_LINK_DISABLE) {
-			pm8001_ha->phy[phy_id].enable_completion = &completion;
 			PM8001_CHIP_DISP->phy_start_req(pm8001_ha, phy_id);
 			wait_for_completion(&completion);
 		}
@@ -207,7 +206,6 @@ int pm8001_phy_control(struct asd_sas_phy *sas_phy, enum phy_func func,
 		break;
 	case PHY_FUNC_LINK_RESET:
 		if (pm8001_ha->phy[phy_id].phy_state == PHY_LINK_DISABLE) {
-			pm8001_ha->phy[phy_id].enable_completion = &completion;
 			PM8001_CHIP_DISP->phy_start_req(pm8001_ha, phy_id);
 			wait_for_completion(&completion);
 		}
diff --git a/drivers/scsi/pm8001/pm80xx_hwi.c b/drivers/scsi/pm8001/pm80xx_hwi.c
index 8fe886dc5e47..a52ae6841939 100644
--- a/drivers/scsi/pm8001/pm80xx_hwi.c
+++ b/drivers/scsi/pm8001/pm80xx_hwi.c
@@ -568,13 +568,13 @@ static void read_main_config_table(struct pm8001_hba_info *pm8001_ha)
 	pm8001_ha->main_cfg_tbl.pm80xx_tbl.inc_fw_version =
 		pm8001_mr32(address, MAIN_MPI_INACTIVE_FW_VERSION);
 
-	pm8001_dbg(pm8001_ha, INIT,
+	pm8001_dbg(pm8001_ha, DEV,
 		   "Main cfg table: sign:%x interface rev:%x fw_rev:%x\n",
 		   pm8001_ha->main_cfg_tbl.pm80xx_tbl.signature,
 		   pm8001_ha->main_cfg_tbl.pm80xx_tbl.interface_rev,
 		   pm8001_ha->main_cfg_tbl.pm80xx_tbl.firmware_rev);
 
-	pm8001_dbg(pm8001_ha, INIT,
+	pm8001_dbg(pm8001_ha, DEV,
 		   "table offset: gst:%x iq:%x oq:%x int vec:%x phy attr:%x\n",
 		   pm8001_ha->main_cfg_tbl.pm80xx_tbl.gst_offset,
 		   pm8001_ha->main_cfg_tbl.pm80xx_tbl.inbound_queue_offset,
@@ -582,7 +582,7 @@ static void read_main_config_table(struct pm8001_hba_info *pm8001_ha)
 		   pm8001_ha->main_cfg_tbl.pm80xx_tbl.int_vec_table_offset,
 		   pm8001_ha->main_cfg_tbl.pm80xx_tbl.phy_attr_table_offset);
 
-	pm8001_dbg(pm8001_ha, INIT,
+	pm8001_dbg(pm8001_ha, DEV,
 		   "Main cfg table; ila rev:%x Inactive fw rev:%x\n",
 		   pm8001_ha->main_cfg_tbl.pm80xx_tbl.ila_version,
 		   pm8001_ha->main_cfg_tbl.pm80xx_tbl.inc_fw_version);
diff --git a/drivers/scsi/ppa.c b/drivers/scsi/ppa.c
index a06329b47851..8300f0bdddb3 100644
--- a/drivers/scsi/ppa.c
+++ b/drivers/scsi/ppa.c
@@ -1151,8 +1151,8 @@ static struct parport_driver ppa_driver = {
 	.name		= "ppa",
 	.match_port	= ppa_attach,
 	.detach		= ppa_detach,
+	.devmodel	= true,
 };
 module_parport_driver(ppa_driver);
 
-MODULE_DESCRIPTION("IOMEGA PPA3 parallel port SCSI host adapter driver");
 MODULE_LICENSE("GPL");
diff --git a/drivers/scsi/qedf/qedf_main.c b/drivers/scsi/qedf/qedf_main.c
index 4813087e58a1..49adddf978cc 100644
--- a/drivers/scsi/qedf/qedf_main.c
+++ b/drivers/scsi/qedf/qedf_main.c
@@ -2286,7 +2286,7 @@ static bool qedf_process_completions(struct qedf_fastpath *fp)
 		 * on.
 		 */
 		if (!io_req)
-			/* If there is not io_req associated with this CQE
+			/* If there is not io_req assocated with this CQE
 			 * just queue it on CPU 0
 			 */
 			cpu = 0;
diff --git a/drivers/scsi/qla2xxx/qla_bsg.c b/drivers/scsi/qla2xxx/qla_bsg.c
index 52dc9604f567..19bb64bdd88b 100644
--- a/drivers/scsi/qla2xxx/qla_bsg.c
+++ b/drivers/scsi/qla2xxx/qla_bsg.c
@@ -324,7 +324,7 @@ qla2x00_process_els(struct bsg_job *bsg_job)
 		    "request_sg_cnt=%x reply_sg_cnt=%x.\n",
 		    bsg_job->request_payload.sg_cnt,
 		    bsg_job->reply_payload.sg_cnt);
-		rval = -ENOBUFS;
+		rval = -EPERM;
 		goto done;
 	}
 
@@ -3059,60 +3059,16 @@ qla24xx_bsg_request(struct bsg_job *bsg_job)
 	return ret;
 }
 
-static bool qla_bsg_found(struct qla_qpair *qpair, struct bsg_job *bsg_job)
-{
-	bool found = false;
-	struct fc_bsg_reply *bsg_reply = bsg_job->reply;
-	scsi_qla_host_t *vha = shost_priv(fc_bsg_to_shost(bsg_job));
-	struct qla_hw_data *ha = vha->hw;
-	srb_t *sp = NULL;
-	int cnt;
-	unsigned long flags;
-	struct req_que *req;
-
-	spin_lock_irqsave(qpair->qp_lock_ptr, flags);
-	req = qpair->req;
-
-	for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
-		sp = req->outstanding_cmds[cnt];
-		if (sp &&
-		    (sp->type == SRB_CT_CMD ||
-		     sp->type == SRB_ELS_CMD_HST ||
-		     sp->type == SRB_ELS_CMD_HST_NOLOGIN) &&
-		    sp->u.bsg_job == bsg_job) {
-			req->outstanding_cmds[cnt] = NULL;
-			spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
-
-			if (!ha->flags.eeh_busy && ha->isp_ops->abort_command(sp)) {
-				ql_log(ql_log_warn, vha, 0x7089,
-						"mbx abort_command failed.\n");
-				bsg_reply->result = -EIO;
-			} else {
-				ql_dbg(ql_dbg_user, vha, 0x708a,
-						"mbx abort_command success.\n");
-				bsg_reply->result = 0;
-			}
-			/* ref: INIT */
-			kref_put(&sp->cmd_kref, qla2x00_sp_release);
-
-			found = true;
-			goto done;
-		}
-	}
-	spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
-
-done:
-	return found;
-}
-
 int
 qla24xx_bsg_timeout(struct bsg_job *bsg_job)
 {
 	struct fc_bsg_reply *bsg_reply = bsg_job->reply;
 	scsi_qla_host_t *vha = shost_priv(fc_bsg_to_shost(bsg_job));
 	struct qla_hw_data *ha = vha->hw;
-	int i;
-	struct qla_qpair *qpair;
+	srb_t *sp;
+	int cnt, que;
+	unsigned long flags;
+	struct req_que *req;
 
 	ql_log(ql_log_info, vha, 0x708b, "%s CMD timeout. bsg ptr %p.\n",
 	    __func__, bsg_job);
@@ -3123,22 +3079,48 @@ qla24xx_bsg_timeout(struct bsg_job *bsg_job)
 		qla_pci_set_eeh_busy(vha);
 	}
 
-	if (qla_bsg_found(ha->base_qpair, bsg_job))
-		goto done;
-
 	/* find the bsg job from the active list of commands */
-	for (i = 0; i < ha->max_qpairs; i++) {
-		qpair = vha->hw->queue_pair_map[i];
-		if (!qpair)
+	spin_lock_irqsave(&ha->hardware_lock, flags);
+	for (que = 0; que < ha->max_req_queues; que++) {
+		req = ha->req_q_map[que];
+		if (!req)
 			continue;
-		if (qla_bsg_found(qpair, bsg_job))
-			goto done;
-	}
 
+		for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
+			sp = req->outstanding_cmds[cnt];
+			if (sp &&
+			    (sp->type == SRB_CT_CMD ||
+			     sp->type == SRB_ELS_CMD_HST ||
+			     sp->type == SRB_ELS_CMD_HST_NOLOGIN ||
+			     sp->type == SRB_FXIOCB_BCMD) &&
+			    sp->u.bsg_job == bsg_job) {
+				req->outstanding_cmds[cnt] = NULL;
+				spin_unlock_irqrestore(&ha->hardware_lock, flags);
+
+				if (!ha->flags.eeh_busy && ha->isp_ops->abort_command(sp)) {
+					ql_log(ql_log_warn, vha, 0x7089,
+					    "mbx abort_command failed.\n");
+					bsg_reply->result = -EIO;
+				} else {
+					ql_dbg(ql_dbg_user, vha, 0x708a,
+					    "mbx abort_command success.\n");
+					bsg_reply->result = 0;
+				}
+				spin_lock_irqsave(&ha->hardware_lock, flags);
+				goto done;
+
+			}
+		}
+	}
+	spin_unlock_irqrestore(&ha->hardware_lock, flags);
 	ql_log(ql_log_info, vha, 0x708b, "SRB not found to abort.\n");
 	bsg_reply->result = -ENXIO;
+	return 0;
 
 done:
+	spin_unlock_irqrestore(&ha->hardware_lock, flags);
+	/* ref: INIT */
+	kref_put(&sp->cmd_kref, qla2x00_sp_release);
 	return 0;
 }
 
diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
index 7cf998e3cc68..2f49baf131e2 100644
--- a/drivers/scsi/qla2xxx/qla_def.h
+++ b/drivers/scsi/qla2xxx/qla_def.h
@@ -3309,20 +3309,9 @@ struct fab_scan_rp {
 	u8 node_name[8];
 };
 
-enum scan_step {
-	FAB_SCAN_START,
-	FAB_SCAN_GPNFT_FCP,
-	FAB_SCAN_GNNFT_FCP,
-	FAB_SCAN_GPNFT_NVME,
-	FAB_SCAN_GNNFT_NVME,
-};
-
 struct fab_scan {
 	struct fab_scan_rp *l;
 	u32 size;
-	u32 rscn_gen_start;
-	u32 rscn_gen_end;
-	enum scan_step step;
 	u16 scan_retry;
 #define MAX_SCAN_RETRIES 5
 	enum scan_flags_t scan_flags;
@@ -3548,8 +3537,9 @@ enum qla_work_type {
 	QLA_EVT_RELOGIN,
 	QLA_EVT_ASYNC_PRLO,
 	QLA_EVT_ASYNC_PRLO_DONE,
-	QLA_EVT_SCAN_CMD,
-	QLA_EVT_SCAN_FINISH,
+	QLA_EVT_GPNFT,
+	QLA_EVT_GPNFT_DONE,
+	QLA_EVT_GNNFT_DONE,
 	QLA_EVT_GFPNID,
 	QLA_EVT_SP_RETRY,
 	QLA_EVT_IIDMA,
@@ -5040,7 +5030,6 @@ typedef struct scsi_qla_host {
 
 	/* Counter to detect races between ELS and RSCN events */
 	atomic_t		generation_tick;
-	atomic_t		rscn_gen;
 	/* Time when global fcport update has been scheduled */
 	int			total_fcport_update_gen;
 	/* List of pending LOGOs, protected by tgt_mutex */
diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
index cededfda9d0e..7309310d2ab9 100644
--- a/drivers/scsi/qla2xxx/qla_gbl.h
+++ b/drivers/scsi/qla2xxx/qla_gbl.h
@@ -728,9 +728,9 @@ int qla24xx_async_gpsc(scsi_qla_host_t *, fc_port_t *);
 void qla24xx_handle_gpsc_event(scsi_qla_host_t *, struct event_arg *);
 int qla2x00_mgmt_svr_login(scsi_qla_host_t *);
 int qla24xx_async_gffid(scsi_qla_host_t *vha, fc_port_t *fcport, bool);
-int qla_fab_async_scan(scsi_qla_host_t *, srb_t *);
-void qla_fab_scan_start(struct scsi_qla_host *);
-void qla_fab_scan_finish(scsi_qla_host_t *, srb_t *);
+int qla24xx_async_gpnft(scsi_qla_host_t *, u8, srb_t *);
+void qla24xx_async_gpnft_done(scsi_qla_host_t *, srb_t *);
+void qla24xx_async_gnnft_done(scsi_qla_host_t *, srb_t *);
 int qla24xx_post_gfpnid_work(struct scsi_qla_host *, fc_port_t *);
 int qla24xx_async_gfpnid(scsi_qla_host_t *, fc_port_t *);
 void qla24xx_handle_gfpnid_event(scsi_qla_host_t *, struct event_arg *);
diff --git a/drivers/scsi/qla2xxx/qla_gs.c b/drivers/scsi/qla2xxx/qla_gs.c
index d2bddca7045a..1cf9d200d563 100644
--- a/drivers/scsi/qla2xxx/qla_gs.c
+++ b/drivers/scsi/qla2xxx/qla_gs.c
@@ -1710,7 +1710,7 @@ qla2x00_hba_attributes(scsi_qla_host_t *vha, void *entries,
 	eiter->type = cpu_to_be16(FDMI_HBA_OPTION_ROM_VERSION);
 	alen = scnprintf(
 		eiter->a.orom_version, sizeof(eiter->a.orom_version),
-		"%d.%02d", ha->efi_revision[1], ha->efi_revision[0]);
+		"%d.%02d", ha->bios_revision[1], ha->bios_revision[0]);
 	alen += FDMI_ATTR_ALIGNMENT(alen);
 	alen += FDMI_ATTR_TYPELEN(eiter);
 	eiter->len = cpu_to_be16(alen);
@@ -3168,30 +3168,7 @@ static int qla2x00_is_a_vp(scsi_qla_host_t *vha, u64 wwn)
 	return rc;
 }
 
-static bool qla_ok_to_clear_rscn(scsi_qla_host_t *vha, fc_port_t *fcport)
-{
-	u32 rscn_gen;
-
-	rscn_gen = atomic_read(&vha->rscn_gen);
-	ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x2017,
-	    "%s %d %8phC rscn_gen %x start %x end %x current %x\n",
-	    __func__, __LINE__, fcport->port_name, fcport->rscn_gen,
-	    vha->scan.rscn_gen_start, vha->scan.rscn_gen_end, rscn_gen);
-
-	if (val_is_in_range(fcport->rscn_gen, vha->scan.rscn_gen_start,
-	    vha->scan.rscn_gen_end))
-		/* rscn came in before fabric scan */
-		return true;
-
-	if (val_is_in_range(fcport->rscn_gen, vha->scan.rscn_gen_end, rscn_gen))
-		/* rscn came in after fabric scan */
-		return false;
-
-	/* rare: fcport's scan_needed + rscn_gen must be stale */
-	return true;
-}
-
-void qla_fab_scan_finish(scsi_qla_host_t *vha, srb_t *sp)
+void qla24xx_async_gnnft_done(scsi_qla_host_t *vha, srb_t *sp)
 {
 	fc_port_t *fcport;
 	u32 i, rc;
@@ -3304,10 +3281,10 @@ void qla_fab_scan_finish(scsi_qla_host_t *vha, srb_t *sp)
 				   (fcport->scan_needed &&
 				    fcport->port_type != FCT_INITIATOR &&
 				    fcport->port_type != FCT_NVME_INITIATOR)) {
-				fcport->scan_needed = 0;
 				qlt_schedule_sess_for_deletion(fcport);
 			}
 			fcport->d_id.b24 = rp->id.b24;
+			fcport->scan_needed = 0;
 			break;
 		}
 
@@ -3348,9 +3325,7 @@ void qla_fab_scan_finish(scsi_qla_host_t *vha, srb_t *sp)
 				do_delete = true;
 			}
 
-			if (qla_ok_to_clear_rscn(vha, fcport))
-				fcport->scan_needed = 0;
-
+			fcport->scan_needed = 0;
 			if (((qla_dual_mode_enabled(vha) ||
 			      qla_ini_mode_enabled(vha)) &&
 			    atomic_read(&fcport->state) == FCS_ONLINE) ||
@@ -3380,9 +3355,7 @@ void qla_fab_scan_finish(scsi_qla_host_t *vha, srb_t *sp)
 					    fcport->port_name, fcport->loop_id,
 					    fcport->login_retry);
 				}
-
-				if (qla_ok_to_clear_rscn(vha, fcport))
-					fcport->scan_needed = 0;
+				fcport->scan_needed = 0;
 				qla24xx_fcport_handle_login(vha, fcport);
 			}
 		}
@@ -3406,11 +3379,14 @@ void qla_fab_scan_finish(scsi_qla_host_t *vha, srb_t *sp)
 	}
 }
 
-static int qla2x00_post_next_scan_work(struct scsi_qla_host *vha,
+static int qla2x00_post_gnnft_gpnft_done_work(struct scsi_qla_host *vha,
     srb_t *sp, int cmd)
 {
 	struct qla_work_evt *e;
 
+	if (cmd != QLA_EVT_GPNFT_DONE && cmd != QLA_EVT_GNNFT_DONE)
+		return QLA_PARAMETER_ERROR;
+
 	e = qla2x00_alloc_work(vha, cmd);
 	if (!e)
 		return QLA_FUNCTION_FAILED;
@@ -3420,15 +3396,37 @@ static int qla2x00_post_next_scan_work(struct scsi_qla_host *vha,
 	return qla2x00_post_work(vha, e);
 }
 
+static int qla2x00_post_nvme_gpnft_work(struct scsi_qla_host *vha,
+    srb_t *sp, int cmd)
+{
+	struct qla_work_evt *e;
+
+	if (cmd != QLA_EVT_GPNFT)
+		return QLA_PARAMETER_ERROR;
+
+	e = qla2x00_alloc_work(vha, cmd);
+	if (!e)
+		return QLA_FUNCTION_FAILED;
+
+	e->u.gpnft.fc4_type = FC4_TYPE_NVME;
+	e->u.gpnft.sp = sp;
+
+	return qla2x00_post_work(vha, e);
+}
+
 static void qla2x00_find_free_fcp_nvme_slot(struct scsi_qla_host *vha,
 	struct srb *sp)
 {
 	struct qla_hw_data *ha = vha->hw;
 	int num_fibre_dev = ha->max_fibre_devices;
+	struct ct_sns_req *ct_req =
+		(struct ct_sns_req *)sp->u.iocb_cmd.u.ctarg.req;
 	struct ct_sns_gpnft_rsp *ct_rsp =
 		(struct ct_sns_gpnft_rsp *)sp->u.iocb_cmd.u.ctarg.rsp;
 	struct ct_sns_gpn_ft_data *d;
 	struct fab_scan_rp *rp;
+	u16 cmd = be16_to_cpu(ct_req->command);
+	u8 fc4_type = sp->gen2;
 	int i, j, k;
 	port_id_t id;
 	u8 found;
@@ -3447,83 +3445,85 @@ static void qla2x00_find_free_fcp_nvme_slot(struct scsi_qla_host *vha,
 		if (id.b24 == 0 || wwn == 0)
 			continue;
 
-		ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x2025,
-		       "%s %06x %8ph \n",
-		       __func__, id.b24, d->port_name);
-
-		switch (vha->scan.step) {
-		case FAB_SCAN_GPNFT_FCP:
-			rp = &vha->scan.l[j];
-			rp->id = id;
-			memcpy(rp->port_name, d->port_name, 8);
-			j++;
-			rp->fc4type = FS_FC4TYPE_FCP;
-			break;
-		case FAB_SCAN_GNNFT_FCP:
-			for (k = 0; k < num_fibre_dev; k++) {
-				rp = &vha->scan.l[k];
-				if (id.b24 == rp->id.b24) {
-					memcpy(rp->node_name,
-					    d->port_name, 8);
-					break;
-				}
-			}
-			break;
-		case FAB_SCAN_GPNFT_NVME:
-			found = 0;
-
-			for (k = 0; k < num_fibre_dev; k++) {
-				rp = &vha->scan.l[k];
-				if (!memcmp(rp->port_name, d->port_name, 8)) {
-					/*
-					 * Supports FC-NVMe & FCP
-					 */
-					rp->fc4type |= FS_FC4TYPE_NVME;
-					found = 1;
-					break;
+		if (fc4_type == FC4_TYPE_FCP_SCSI) {
+			if (cmd == GPN_FT_CMD) {
+				rp = &vha->scan.l[j];
+				rp->id = id;
+				memcpy(rp->port_name, d->port_name, 8);
+				j++;
+				rp->fc4type = FS_FC4TYPE_FCP;
+			} else {
+				for (k = 0; k < num_fibre_dev; k++) {
+					rp = &vha->scan.l[k];
+					if (id.b24 == rp->id.b24) {
+						memcpy(rp->node_name,
+						    d->port_name, 8);
+						break;
+					}
 				}
 			}
+		} else {
+			/* Search if the fibre device supports FC4_TYPE_NVME */
+			if (cmd == GPN_FT_CMD) {
+				found = 0;
 
-			/* We found new FC-NVMe only port */
-			if (!found) {
 				for (k = 0; k < num_fibre_dev; k++) {
 					rp = &vha->scan.l[k];
-					if (wwn_to_u64(rp->port_name)) {
-						continue;
-					} else {
-						rp->id = id;
-						memcpy(rp->port_name, d->port_name, 8);
-						rp->fc4type = FS_FC4TYPE_NVME;
+					if (!memcmp(rp->port_name,
+					    d->port_name, 8)) {
+						/*
+						 * Supports FC-NVMe & FCP
+						 */
+						rp->fc4type |= FS_FC4TYPE_NVME;
+						found = 1;
 						break;
 					}
 				}
-			}
-			break;
-		case FAB_SCAN_GNNFT_NVME:
-			for (k = 0; k < num_fibre_dev; k++) {
-				rp = &vha->scan.l[k];
-				if (id.b24 == rp->id.b24) {
-					memcpy(rp->node_name, d->port_name, 8);
-					break;
+
+				/* We found new FC-NVMe only port */
+				if (!found) {
+					for (k = 0; k < num_fibre_dev; k++) {
+						rp = &vha->scan.l[k];
+						if (wwn_to_u64(rp->port_name)) {
+							continue;
+						} else {
+							rp->id = id;
+							memcpy(rp->port_name,
+							    d->port_name, 8);
+							rp->fc4type =
+							    FS_FC4TYPE_NVME;
+							break;
+						}
+					}
+				}
+			} else {
+				for (k = 0; k < num_fibre_dev; k++) {
+					rp = &vha->scan.l[k];
+					if (id.b24 == rp->id.b24) {
+						memcpy(rp->node_name,
+						    d->port_name, 8);
+						break;
+					}
 				}
 			}
-			break;
-		default:
-			break;
 		}
 	}
 }
 
-static void qla_async_scan_sp_done(srb_t *sp, int res)
+static void qla2x00_async_gpnft_gnnft_sp_done(srb_t *sp, int res)
 {
 	struct scsi_qla_host *vha = sp->vha;
+	struct ct_sns_req *ct_req =
+		(struct ct_sns_req *)sp->u.iocb_cmd.u.ctarg.req;
+	u16 cmd = be16_to_cpu(ct_req->command);
+	u8 fc4_type = sp->gen2;
 	unsigned long flags;
 	int rc;
 
 	/* gen2 field is holding the fc4type */
-	ql_dbg(ql_dbg_disc, vha, 0x2026,
-	    "Async done-%s res %x step %x\n",
-	    sp->name, res, vha->scan.step);
+	ql_dbg(ql_dbg_disc, vha, 0xffff,
+	    "Async done-%s res %x FC4Type %x\n",
+	    sp->name, res, sp->gen2);
 
 	sp->rc = res;
 	if (res) {
@@ -3547,7 +3547,8 @@ static void qla_async_scan_sp_done(srb_t *sp, int res)
 		 * sp for GNNFT_DONE work. This will allow all
 		 * the resource to get freed up.
 		 */
-		rc = qla2x00_post_next_scan_work(vha, sp, QLA_EVT_SCAN_FINISH);
+		rc = qla2x00_post_gnnft_gpnft_done_work(vha, sp,
+		    QLA_EVT_GNNFT_DONE);
 		if (rc) {
 			/* Cleanup here to prevent memory leak */
 			qla24xx_sp_unmap(vha, sp);
@@ -3572,30 +3573,28 @@ static void qla_async_scan_sp_done(srb_t *sp, int res)
 
 	qla2x00_find_free_fcp_nvme_slot(vha, sp);
 
-	spin_lock_irqsave(&vha->work_lock, flags);
-	vha->scan.scan_flags &= ~SF_SCANNING;
-	spin_unlock_irqrestore(&vha->work_lock, flags);
+	if ((fc4_type == FC4_TYPE_FCP_SCSI) && vha->flags.nvme_enabled &&
+	    cmd == GNN_FT_CMD) {
+		spin_lock_irqsave(&vha->work_lock, flags);
+		vha->scan.scan_flags &= ~SF_SCANNING;
+		spin_unlock_irqrestore(&vha->work_lock, flags);
 
-	switch (vha->scan.step) {
-	case FAB_SCAN_GPNFT_FCP:
-	case FAB_SCAN_GPNFT_NVME:
-		rc = qla2x00_post_next_scan_work(vha, sp, QLA_EVT_SCAN_CMD);
-		break;
-	case  FAB_SCAN_GNNFT_FCP:
-		if (vha->flags.nvme_enabled)
-			rc = qla2x00_post_next_scan_work(vha, sp, QLA_EVT_SCAN_CMD);
-		else
-			rc = qla2x00_post_next_scan_work(vha, sp, QLA_EVT_SCAN_FINISH);
+		sp->rc = res;
+		rc = qla2x00_post_nvme_gpnft_work(vha, sp, QLA_EVT_GPNFT);
+		if (rc) {
+			qla24xx_sp_unmap(vha, sp);
+			set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
+			set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
+		}
+		return;
+	}
 
-		break;
-	case  FAB_SCAN_GNNFT_NVME:
-		rc = qla2x00_post_next_scan_work(vha, sp, QLA_EVT_SCAN_FINISH);
-		break;
-	default:
-		/* should not be here */
-		WARN_ON(1);
-		rc = QLA_FUNCTION_FAILED;
-		break;
+	if (cmd == GPN_FT_CMD) {
+		rc = qla2x00_post_gnnft_gpnft_done_work(vha, sp,
+		    QLA_EVT_GPNFT_DONE);
+	} else {
+		rc = qla2x00_post_gnnft_gpnft_done_work(vha, sp,
+		    QLA_EVT_GNNFT_DONE);
 	}
 
 	if (rc) {
@@ -3606,16 +3605,127 @@ static void qla_async_scan_sp_done(srb_t *sp, int res)
 	}
 }
 
+/*
+ * Get WWNN list for fc4_type
+ *
+ * It is assumed the same SRB is re-used from GPNFT to avoid
+ * mem free & re-alloc
+ */
+static int qla24xx_async_gnnft(scsi_qla_host_t *vha, struct srb *sp,
+    u8 fc4_type)
+{
+	int rval = QLA_FUNCTION_FAILED;
+	struct ct_sns_req *ct_req;
+	struct ct_sns_pkt *ct_sns;
+	unsigned long flags;
+
+	if (!vha->flags.online) {
+		spin_lock_irqsave(&vha->work_lock, flags);
+		vha->scan.scan_flags &= ~SF_SCANNING;
+		spin_unlock_irqrestore(&vha->work_lock, flags);
+		goto done_free_sp;
+	}
+
+	if (!sp->u.iocb_cmd.u.ctarg.req || !sp->u.iocb_cmd.u.ctarg.rsp) {
+		ql_log(ql_log_warn, vha, 0xffff,
+		    "%s: req %p rsp %p are not setup\n",
+		    __func__, sp->u.iocb_cmd.u.ctarg.req,
+		    sp->u.iocb_cmd.u.ctarg.rsp);
+		spin_lock_irqsave(&vha->work_lock, flags);
+		vha->scan.scan_flags &= ~SF_SCANNING;
+		spin_unlock_irqrestore(&vha->work_lock, flags);
+		WARN_ON(1);
+		set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
+		set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
+		goto done_free_sp;
+	}
+
+	ql_dbg(ql_dbg_disc, vha, 0xfffff,
+	    "%s: FC4Type %x, CT-PASSTHRU %s command ctarg rsp size %d, ctarg req size %d\n",
+	    __func__, fc4_type, sp->name, sp->u.iocb_cmd.u.ctarg.rsp_size,
+	     sp->u.iocb_cmd.u.ctarg.req_size);
+
+	sp->type = SRB_CT_PTHRU_CMD;
+	sp->name = "gnnft";
+	sp->gen1 = vha->hw->base_qpair->chip_reset;
+	sp->gen2 = fc4_type;
+	qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha) + 2,
+			      qla2x00_async_gpnft_gnnft_sp_done);
+
+	memset(sp->u.iocb_cmd.u.ctarg.rsp, 0, sp->u.iocb_cmd.u.ctarg.rsp_size);
+	memset(sp->u.iocb_cmd.u.ctarg.req, 0, sp->u.iocb_cmd.u.ctarg.req_size);
+
+	ct_sns = (struct ct_sns_pkt *)sp->u.iocb_cmd.u.ctarg.req;
+	/* CT_IU preamble  */
+	ct_req = qla2x00_prep_ct_req(ct_sns, GNN_FT_CMD,
+	    sp->u.iocb_cmd.u.ctarg.rsp_size);
+
+	/* GPN_FT req */
+	ct_req->req.gpn_ft.port_type = fc4_type;
+
+	sp->u.iocb_cmd.u.ctarg.req_size = GNN_FT_REQ_SIZE;
+	sp->u.iocb_cmd.u.ctarg.nport_handle = NPH_SNS;
+
+	ql_dbg(ql_dbg_disc, vha, 0xffff,
+	    "Async-%s hdl=%x FC4Type %x.\n", sp->name,
+	    sp->handle, ct_req->req.gpn_ft.port_type);
+
+	rval = qla2x00_start_sp(sp);
+	if (rval != QLA_SUCCESS) {
+		goto done_free_sp;
+	}
+
+	return rval;
+
+done_free_sp:
+	if (sp->u.iocb_cmd.u.ctarg.req) {
+		dma_free_coherent(&vha->hw->pdev->dev,
+		    sp->u.iocb_cmd.u.ctarg.req_allocated_size,
+		    sp->u.iocb_cmd.u.ctarg.req,
+		    sp->u.iocb_cmd.u.ctarg.req_dma);
+		sp->u.iocb_cmd.u.ctarg.req = NULL;
+	}
+	if (sp->u.iocb_cmd.u.ctarg.rsp) {
+		dma_free_coherent(&vha->hw->pdev->dev,
+		    sp->u.iocb_cmd.u.ctarg.rsp_allocated_size,
+		    sp->u.iocb_cmd.u.ctarg.rsp,
+		    sp->u.iocb_cmd.u.ctarg.rsp_dma);
+		sp->u.iocb_cmd.u.ctarg.rsp = NULL;
+	}
+	/* ref: INIT */
+	kref_put(&sp->cmd_kref, qla2x00_sp_release);
+
+	spin_lock_irqsave(&vha->work_lock, flags);
+	vha->scan.scan_flags &= ~SF_SCANNING;
+	if (vha->scan.scan_flags == 0) {
+		ql_dbg(ql_dbg_disc, vha, 0xffff,
+		    "%s: schedule\n", __func__);
+		vha->scan.scan_flags |= SF_QUEUED;
+		schedule_delayed_work(&vha->scan.scan_work, 5);
+	}
+	spin_unlock_irqrestore(&vha->work_lock, flags);
+
+
+	return rval;
+} /* GNNFT */
+
+void qla24xx_async_gpnft_done(scsi_qla_host_t *vha, srb_t *sp)
+{
+	ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0xffff,
+	    "%s enter\n", __func__);
+	qla24xx_async_gnnft(vha, sp, sp->gen2);
+}
+
 /* Get WWPN list for certain fc4_type */
-int qla_fab_async_scan(scsi_qla_host_t *vha, srb_t *sp)
+int qla24xx_async_gpnft(scsi_qla_host_t *vha, u8 fc4_type, srb_t *sp)
 {
 	int rval = QLA_FUNCTION_FAILED;
 	struct ct_sns_req       *ct_req;
 	struct ct_sns_pkt *ct_sns;
-	u32 rspsz = 0;
+	u32 rspsz;
 	unsigned long flags;
 
-	ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x200c,
+	ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0xffff,
 	    "%s enter\n", __func__);
 
 	if (!vha->flags.online)
@@ -3624,21 +3734,22 @@ int qla_fab_async_scan(scsi_qla_host_t *vha, srb_t *sp)
 	spin_lock_irqsave(&vha->work_lock, flags);
 	if (vha->scan.scan_flags & SF_SCANNING) {
 		spin_unlock_irqrestore(&vha->work_lock, flags);
-		ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x2012,
+		ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0xffff,
 		    "%s: scan active\n", __func__);
 		return rval;
 	}
 	vha->scan.scan_flags |= SF_SCANNING;
-	if (!sp)
-		vha->scan.step = FAB_SCAN_START;
-
 	spin_unlock_irqrestore(&vha->work_lock, flags);
 
-	switch (vha->scan.step) {
-	case FAB_SCAN_START:
-		ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x2018,
+	if (fc4_type == FC4_TYPE_FCP_SCSI) {
+		ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0xffff,
 		    "%s: Performing FCP Scan\n", __func__);
 
+		if (sp) {
+			/* ref: INIT */
+			kref_put(&sp->cmd_kref, qla2x00_sp_release);
+		}
+
 		/* ref: INIT */
 		sp = qla2x00_get_sp(vha, NULL, GFP_KERNEL);
 		if (!sp) {
@@ -3654,7 +3765,7 @@ int qla_fab_async_scan(scsi_qla_host_t *vha, srb_t *sp)
 								GFP_KERNEL);
 		sp->u.iocb_cmd.u.ctarg.req_allocated_size = sizeof(struct ct_sns_pkt);
 		if (!sp->u.iocb_cmd.u.ctarg.req) {
-			ql_log(ql_log_warn, vha, 0x201a,
+			ql_log(ql_log_warn, vha, 0xffff,
 			    "Failed to allocate ct_sns request.\n");
 			spin_lock_irqsave(&vha->work_lock, flags);
 			vha->scan.scan_flags &= ~SF_SCANNING;
@@ -3662,6 +3773,7 @@ int qla_fab_async_scan(scsi_qla_host_t *vha, srb_t *sp)
 			qla2x00_rel_sp(sp);
 			return rval;
 		}
+		sp->u.iocb_cmd.u.ctarg.req_size = GPN_FT_REQ_SIZE;
 
 		rspsz = sizeof(struct ct_sns_gpnft_rsp) +
 			vha->hw->max_fibre_devices *
@@ -3673,7 +3785,7 @@ int qla_fab_async_scan(scsi_qla_host_t *vha, srb_t *sp)
 								GFP_KERNEL);
 		sp->u.iocb_cmd.u.ctarg.rsp_allocated_size = rspsz;
 		if (!sp->u.iocb_cmd.u.ctarg.rsp) {
-			ql_log(ql_log_warn, vha, 0x201b,
+			ql_log(ql_log_warn, vha, 0xffff,
 			    "Failed to allocate ct_sns request.\n");
 			spin_lock_irqsave(&vha->work_lock, flags);
 			vha->scan.scan_flags &= ~SF_SCANNING;
@@ -3693,95 +3805,35 @@ int qla_fab_async_scan(scsi_qla_host_t *vha, srb_t *sp)
 		    "%s scan list size %d\n", __func__, vha->scan.size);
 
 		memset(vha->scan.l, 0, vha->scan.size);
-
-		vha->scan.step = FAB_SCAN_GPNFT_FCP;
-		break;
-	case FAB_SCAN_GPNFT_FCP:
-		vha->scan.step = FAB_SCAN_GNNFT_FCP;
-		break;
-	case FAB_SCAN_GNNFT_FCP:
-		vha->scan.step = FAB_SCAN_GPNFT_NVME;
-		break;
-	case FAB_SCAN_GPNFT_NVME:
-		vha->scan.step = FAB_SCAN_GNNFT_NVME;
-		break;
-	case FAB_SCAN_GNNFT_NVME:
-	default:
-		/* should not be here */
-		WARN_ON(1);
-		goto done_free_sp;
-	}
-
-	if (!sp) {
-		ql_dbg(ql_dbg_disc, vha, 0x201c,
-		    "scan did not provide SP\n");
+	} else if (!sp) {
+		ql_dbg(ql_dbg_disc, vha, 0xffff,
+		    "NVME scan did not provide SP\n");
 		return rval;
 	}
-	if (!sp->u.iocb_cmd.u.ctarg.req || !sp->u.iocb_cmd.u.ctarg.rsp) {
-		ql_log(ql_log_warn, vha, 0x201d,
-		    "%s: req %p rsp %p are not setup\n",
-		    __func__, sp->u.iocb_cmd.u.ctarg.req,
-		    sp->u.iocb_cmd.u.ctarg.rsp);
-		spin_lock_irqsave(&vha->work_lock, flags);
-		vha->scan.scan_flags &= ~SF_SCANNING;
-		spin_unlock_irqrestore(&vha->work_lock, flags);
-		WARN_ON(1);
-		set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
-		set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
-		goto done_free_sp;
-	}
-
-	rspsz = sp->u.iocb_cmd.u.ctarg.rsp_size;
-	memset(sp->u.iocb_cmd.u.ctarg.req, 0, sp->u.iocb_cmd.u.ctarg.req_size);
-	memset(sp->u.iocb_cmd.u.ctarg.rsp, 0, sp->u.iocb_cmd.u.ctarg.rsp_size);
-
 
 	sp->type = SRB_CT_PTHRU_CMD;
+	sp->name = "gpnft";
 	sp->gen1 = vha->hw->base_qpair->chip_reset;
+	sp->gen2 = fc4_type;
 	qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha) + 2,
-			      qla_async_scan_sp_done);
+			      qla2x00_async_gpnft_gnnft_sp_done);
 
-	ct_sns = (struct ct_sns_pkt *)sp->u.iocb_cmd.u.ctarg.req;
+	rspsz = sp->u.iocb_cmd.u.ctarg.rsp_size;
+	memset(sp->u.iocb_cmd.u.ctarg.rsp, 0, sp->u.iocb_cmd.u.ctarg.rsp_size);
+	memset(sp->u.iocb_cmd.u.ctarg.req, 0, sp->u.iocb_cmd.u.ctarg.req_size);
 
+	ct_sns = (struct ct_sns_pkt *)sp->u.iocb_cmd.u.ctarg.req;
 	/* CT_IU preamble  */
-	switch (vha->scan.step) {
-	case FAB_SCAN_GPNFT_FCP:
-		sp->name = "gpnft";
-		ct_req = qla2x00_prep_ct_req(ct_sns, GPN_FT_CMD, rspsz);
-		ct_req->req.gpn_ft.port_type = FC4_TYPE_FCP_SCSI;
-		sp->u.iocb_cmd.u.ctarg.req_size = GPN_FT_REQ_SIZE;
-		break;
-	case FAB_SCAN_GNNFT_FCP:
-		sp->name = "gnnft";
-		ct_req = qla2x00_prep_ct_req(ct_sns, GNN_FT_CMD, rspsz);
-		ct_req->req.gpn_ft.port_type = FC4_TYPE_FCP_SCSI;
-		sp->u.iocb_cmd.u.ctarg.req_size = GNN_FT_REQ_SIZE;
-		break;
-	case FAB_SCAN_GPNFT_NVME:
-		sp->name = "gpnft";
-		ct_req = qla2x00_prep_ct_req(ct_sns, GPN_FT_CMD, rspsz);
-		ct_req->req.gpn_ft.port_type = FC4_TYPE_NVME;
-		sp->u.iocb_cmd.u.ctarg.req_size = GPN_FT_REQ_SIZE;
-		break;
-	case FAB_SCAN_GNNFT_NVME:
-		sp->name = "gnnft";
-		ct_req = qla2x00_prep_ct_req(ct_sns, GNN_FT_CMD, rspsz);
-		ct_req->req.gpn_ft.port_type = FC4_TYPE_NVME;
-		sp->u.iocb_cmd.u.ctarg.req_size = GNN_FT_REQ_SIZE;
-		break;
-	default:
-		/* should not be here */
-		WARN_ON(1);
-		goto done_free_sp;
-	}
+	ct_req = qla2x00_prep_ct_req(ct_sns, GPN_FT_CMD, rspsz);
+
+	/* GPN_FT req */
+	ct_req->req.gpn_ft.port_type = fc4_type;
 
 	sp->u.iocb_cmd.u.ctarg.nport_handle = NPH_SNS;
 
-	ql_dbg(ql_dbg_disc, vha, 0x2003,
-	       "%s: step %d, rsp size %d, req size %d hdl %x %s FC4TYPE %x \n",
-	       __func__, vha->scan.step, sp->u.iocb_cmd.u.ctarg.rsp_size,
-	       sp->u.iocb_cmd.u.ctarg.req_size, sp->handle, sp->name,
-	       ct_req->req.gpn_ft.port_type);
+	ql_dbg(ql_dbg_disc, vha, 0xffff,
+	    "Async-%s hdl=%x FC4Type %x.\n", sp->name,
+	    sp->handle, ct_req->req.gpn_ft.port_type);
 
 	rval = qla2x00_start_sp(sp);
 	if (rval != QLA_SUCCESS) {
@@ -3812,7 +3864,7 @@ int qla_fab_async_scan(scsi_qla_host_t *vha, srb_t *sp)
 	spin_lock_irqsave(&vha->work_lock, flags);
 	vha->scan.scan_flags &= ~SF_SCANNING;
 	if (vha->scan.scan_flags == 0) {
-		ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x2007,
+		ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0xffff,
 		    "%s: Scan scheduled.\n", __func__);
 		vha->scan.scan_flags |= SF_QUEUED;
 		schedule_delayed_work(&vha->scan.scan_work, 5);
@@ -3823,15 +3875,6 @@ int qla_fab_async_scan(scsi_qla_host_t *vha, srb_t *sp)
 	return rval;
 }
 
-void qla_fab_scan_start(struct scsi_qla_host *vha)
-{
-	int rval;
-
-	rval = qla_fab_async_scan(vha, NULL);
-	if (rval)
-		set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
-}
-
 void qla_scan_work_fn(struct work_struct *work)
 {
 	struct fab_scan *s = container_of(to_delayed_work(work),
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index 31fc6a0eca3e..8377624d76c9 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -423,7 +423,7 @@ qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
 	sp->type = SRB_LOGOUT_CMD;
 	sp->name = "logout";
 	qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha) + 2,
-			      qla2x00_async_logout_sp_done);
+			      qla2x00_async_logout_sp_done),
 
 	ql_dbg(ql_dbg_disc, vha, 0x2070,
 	    "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x %8phC explicit %d.\n",
@@ -1842,18 +1842,10 @@ int qla24xx_post_newsess_work(struct scsi_qla_host *vha, port_id_t *id,
 	return qla2x00_post_work(vha, e);
 }
 
-static void qla_rscn_gen_tick(scsi_qla_host_t *vha, u32 *ret_rscn_gen)
-{
-	*ret_rscn_gen = atomic_inc_return(&vha->rscn_gen);
-	/* memory barrier */
-	wmb();
-}
-
 void qla2x00_handle_rscn(scsi_qla_host_t *vha, struct event_arg *ea)
 {
 	fc_port_t *fcport;
 	unsigned long flags;
-	u32 rscn_gen;
 
 	switch (ea->id.b.rsvd_1) {
 	case RSCN_PORT_ADDR:
@@ -1883,16 +1875,15 @@ void qla2x00_handle_rscn(scsi_qla_host_t *vha, struct event_arg *ea)
 					 * Otherwise we're already in the middle of a relogin
 					 */
 					fcport->scan_needed = 1;
-					qla_rscn_gen_tick(vha, &fcport->rscn_gen);
+					fcport->rscn_gen++;
 				}
 			} else {
 				fcport->scan_needed = 1;
-				qla_rscn_gen_tick(vha, &fcport->rscn_gen);
+				fcport->rscn_gen++;
 			}
 		}
 		break;
 	case RSCN_AREA_ADDR:
-		qla_rscn_gen_tick(vha, &rscn_gen);
 		list_for_each_entry(fcport, &vha->vp_fcports, list) {
 			if (fcport->flags & FCF_FCP2_DEVICE &&
 			    atomic_read(&fcport->state) == FCS_ONLINE)
@@ -1900,12 +1891,11 @@ void qla2x00_handle_rscn(scsi_qla_host_t *vha, struct event_arg *ea)
 
 			if ((ea->id.b24 & 0xffff00) == (fcport->d_id.b24 & 0xffff00)) {
 				fcport->scan_needed = 1;
-				fcport->rscn_gen = rscn_gen;
+				fcport->rscn_gen++;
 			}
 		}
 		break;
 	case RSCN_DOM_ADDR:
-		qla_rscn_gen_tick(vha, &rscn_gen);
 		list_for_each_entry(fcport, &vha->vp_fcports, list) {
 			if (fcport->flags & FCF_FCP2_DEVICE &&
 			    atomic_read(&fcport->state) == FCS_ONLINE)
@@ -1913,20 +1903,19 @@ void qla2x00_handle_rscn(scsi_qla_host_t *vha, struct event_arg *ea)
 
 			if ((ea->id.b24 & 0xff0000) == (fcport->d_id.b24 & 0xff0000)) {
 				fcport->scan_needed = 1;
-				fcport->rscn_gen = rscn_gen;
+				fcport->rscn_gen++;
 			}
 		}
 		break;
 	case RSCN_FAB_ADDR:
 	default:
-		qla_rscn_gen_tick(vha, &rscn_gen);
 		list_for_each_entry(fcport, &vha->vp_fcports, list) {
 			if (fcport->flags & FCF_FCP2_DEVICE &&
 			    atomic_read(&fcport->state) == FCS_ONLINE)
 				continue;
 
 			fcport->scan_needed = 1;
-			fcport->rscn_gen = rscn_gen;
+			fcport->rscn_gen++;
 		}
 		break;
 	}
@@ -1935,7 +1924,6 @@ void qla2x00_handle_rscn(scsi_qla_host_t *vha, struct event_arg *ea)
 	if (vha->scan.scan_flags == 0) {
 		ql_dbg(ql_dbg_disc, vha, 0xffff, "%s: schedule\n", __func__);
 		vha->scan.scan_flags |= SF_QUEUED;
-		vha->scan.rscn_gen_start = atomic_read(&vha->rscn_gen);
 		schedule_delayed_work(&vha->scan.scan_work, 5);
 	}
 	spin_unlock_irqrestore(&vha->work_lock, flags);
@@ -6405,9 +6393,10 @@ qla2x00_configure_fabric(scsi_qla_host_t *vha)
 		qlt_do_generation_tick(vha, &discovery_gen);
 
 		if (USE_ASYNC_SCAN(ha)) {
-			/* start of scan begins here */
-			vha->scan.rscn_gen_end = atomic_read(&vha->rscn_gen);
-			qla_fab_scan_start(vha);
+			rval = qla24xx_async_gpnft(vha, FC4_TYPE_FCP_SCSI,
+			    NULL);
+			if (rval)
+				set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
 		} else  {
 			list_for_each_entry(fcport, &vha->vp_fcports, list)
 				fcport->scan_state = QLA_FCPORT_SCAN;
@@ -8218,21 +8207,15 @@ qla28xx_get_aux_images(
 	struct qla27xx_image_status pri_aux_image_status, sec_aux_image_status;
 	bool valid_pri_image = false, valid_sec_image = false;
 	bool active_pri_image = false, active_sec_image = false;
-	int rc;
 
 	if (!ha->flt_region_aux_img_status_pri) {
 		ql_dbg(ql_dbg_init, vha, 0x018a, "Primary aux image not addressed\n");
 		goto check_sec_image;
 	}
 
-	rc = qla24xx_read_flash_data(vha, (uint32_t *)&pri_aux_image_status,
+	qla24xx_read_flash_data(vha, (uint32_t *)&pri_aux_image_status,
 	    ha->flt_region_aux_img_status_pri,
 	    sizeof(pri_aux_image_status) >> 2);
-	if (rc) {
-		ql_log(ql_log_info, vha, 0x01a1,
-		    "Unable to read Primary aux image(%x).\n", rc);
-		goto check_sec_image;
-	}
 	qla27xx_print_image(vha, "Primary aux image", &pri_aux_image_status);
 
 	if (qla28xx_check_aux_image_status_signature(&pri_aux_image_status)) {
@@ -8263,15 +8246,9 @@ qla28xx_get_aux_images(
 		goto check_valid_image;
 	}
 
-	rc = qla24xx_read_flash_data(vha, (uint32_t *)&sec_aux_image_status,
+	qla24xx_read_flash_data(vha, (uint32_t *)&sec_aux_image_status,
 	    ha->flt_region_aux_img_status_sec,
 	    sizeof(sec_aux_image_status) >> 2);
-	if (rc) {
-		ql_log(ql_log_info, vha, 0x01a2,
-		    "Unable to read Secondary aux image(%x).\n", rc);
-		goto check_valid_image;
-	}
-
 	qla27xx_print_image(vha, "Secondary aux image", &sec_aux_image_status);
 
 	if (qla28xx_check_aux_image_status_signature(&sec_aux_image_status)) {
@@ -8329,7 +8306,6 @@ qla27xx_get_active_image(struct scsi_qla_host *vha,
 	struct qla27xx_image_status pri_image_status, sec_image_status;
 	bool valid_pri_image = false, valid_sec_image = false;
 	bool active_pri_image = false, active_sec_image = false;
-	int rc;
 
 	if (!ha->flt_region_img_status_pri) {
 		ql_dbg(ql_dbg_init, vha, 0x018a, "Primary image not addressed\n");
@@ -8371,14 +8347,8 @@ qla27xx_get_active_image(struct scsi_qla_host *vha,
 		goto check_valid_image;
 	}
 
-	rc = qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status),
+	qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status),
 	    ha->flt_region_img_status_sec, sizeof(sec_image_status) >> 2);
-	if (rc) {
-		ql_log(ql_log_info, vha, 0x01a3,
-		    "Unable to read Secondary image status(%x).\n", rc);
-		goto check_valid_image;
-	}
-
 	qla27xx_print_image(vha, "Secondary image", &sec_image_status);
 
 	if (qla27xx_check_image_status_signature(&sec_image_status)) {
@@ -8450,10 +8420,11 @@ qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
 	    "FW: Loading firmware from flash (%x).\n", faddr);
 
 	dcode = (uint32_t *)req->ring;
-	rval = qla24xx_read_flash_data(vha, dcode, faddr, 8);
-	if (rval || qla24xx_risc_firmware_invalid(dcode)) {
+	qla24xx_read_flash_data(vha, dcode, faddr, 8);
+	if (qla24xx_risc_firmware_invalid(dcode)) {
 		ql_log(ql_log_fatal, vha, 0x008c,
-		    "Unable to verify the integrity of flash firmware image (rval %x).\n", rval);
+		    "Unable to verify the integrity of flash firmware "
+		    "image.\n");
 		ql_log(ql_log_fatal, vha, 0x008d,
 		    "Firmware data: %08x %08x %08x %08x.\n",
 		    dcode[0], dcode[1], dcode[2], dcode[3]);
@@ -8467,12 +8438,7 @@ qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
 	for (j = 0; j < segments; j++) {
 		ql_dbg(ql_dbg_init, vha, 0x008d,
 		    "-> Loading segment %u...\n", j);
-		rval = qla24xx_read_flash_data(vha, dcode, faddr, 10);
-		if (rval) {
-			ql_log(ql_log_fatal, vha, 0x016a,
-			    "-> Unable to read segment addr + size .\n");
-			return QLA_FUNCTION_FAILED;
-		}
+		qla24xx_read_flash_data(vha, dcode, faddr, 10);
 		risc_addr = be32_to_cpu((__force __be32)dcode[2]);
 		risc_size = be32_to_cpu((__force __be32)dcode[3]);
 		if (!*srisc_addr) {
@@ -8488,13 +8454,7 @@ qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
 			ql_dbg(ql_dbg_init, vha, 0x008e,
 			    "-> Loading fragment %u: %#x <- %#x (%#lx dwords)...\n",
 			    fragment, risc_addr, faddr, dlen);
-			rval = qla24xx_read_flash_data(vha, dcode, faddr, dlen);
-			if (rval) {
-				ql_log(ql_log_fatal, vha, 0x016b,
-				    "-> Unable to read fragment(faddr %#x dlen %#lx).\n",
-				    faddr, dlen);
-				return QLA_FUNCTION_FAILED;
-			}
+			qla24xx_read_flash_data(vha, dcode, faddr, dlen);
 			for (i = 0; i < dlen; i++)
 				dcode[i] = swab32(dcode[i]);
 
@@ -8523,14 +8483,7 @@ qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
 		fwdt->length = 0;
 
 		dcode = (uint32_t *)req->ring;
-
-		rval = qla24xx_read_flash_data(vha, dcode, faddr, 7);
-		if (rval) {
-			ql_log(ql_log_fatal, vha, 0x016c,
-			    "-> Unable to read template size.\n");
-			goto failed;
-		}
-
+		qla24xx_read_flash_data(vha, dcode, faddr, 7);
 		risc_size = be32_to_cpu((__force __be32)dcode[2]);
 		ql_dbg(ql_dbg_init, vha, 0x0161,
 		    "-> fwdt%u template array at %#x (%#x dwords)\n",
@@ -8556,12 +8509,11 @@ qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
 		}
 
 		dcode = fwdt->template;
-		rval = qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
+		qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
 
-		if (rval || !qla27xx_fwdt_template_valid(dcode)) {
+		if (!qla27xx_fwdt_template_valid(dcode)) {
 			ql_log(ql_log_warn, vha, 0x0165,
-			    "-> fwdt%u failed template validate (rval %x)\n",
-			    j, rval);
+			    "-> fwdt%u failed template validate\n", j);
 			goto failed;
 		}
 
diff --git a/drivers/scsi/qla2xxx/qla_inline.h b/drivers/scsi/qla2xxx/qla_inline.h
index ef4b3cc1cd77..a4a56ab0ba74 100644
--- a/drivers/scsi/qla2xxx/qla_inline.h
+++ b/drivers/scsi/qla2xxx/qla_inline.h
@@ -631,11 +631,3 @@ static inline int qla_mapq_alloc_qp_cpu_map(struct qla_hw_data *ha)
 	}
 	return 0;
 }
-
-static inline bool val_is_in_range(u32 val, u32 start, u32 end)
-{
-	if (val >= start && val <= end)
-		return true;
-	else
-		return false;
-}
diff --git a/drivers/scsi/qla2xxx/qla_isr.c b/drivers/scsi/qla2xxx/qla_isr.c
index fe98c76e9be3..d48007e18288 100644
--- a/drivers/scsi/qla2xxx/qla_isr.c
+++ b/drivers/scsi/qla2xxx/qla_isr.c
@@ -3014,6 +3014,12 @@ qla2x00_handle_sense(srb_t *sp, uint8_t *sense_data, uint32_t par_sense_len,
 	}
 }
 
+struct scsi_dif_tuple {
+	__be16 guard;       /* Checksum */
+	__be16 app_tag;         /* APPL identifier */
+	__be32 ref_tag;         /* Target LBA or indirect LBA */
+};
+
 /*
  * Checks the guard or meta-data for the type of error
  * detected by the HBA. In case of errors, we set the
diff --git a/drivers/scsi/qla2xxx/qla_mid.c b/drivers/scsi/qla2xxx/qla_mid.c
index 76703f2706b8..b67416951a5f 100644
--- a/drivers/scsi/qla2xxx/qla_mid.c
+++ b/drivers/scsi/qla2xxx/qla_mid.c
@@ -180,7 +180,7 @@ qla24xx_disable_vp(scsi_qla_host_t *vha)
 	atomic_set(&vha->loop_state, LOOP_DOWN);
 	atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
 	list_for_each_entry(fcport, &vha->vp_fcports, list)
-		fcport->logout_on_delete = 1;
+		fcport->logout_on_delete = 0;
 
 	if (!vha->hw->flags.edif_enabled)
 		qla2x00_wait_for_sess_deletion(vha);
diff --git a/drivers/scsi/qla2xxx/qla_nvme.c b/drivers/scsi/qla2xxx/qla_nvme.c
index 8f4cc136a9c9..a8ddf356e662 100644
--- a/drivers/scsi/qla2xxx/qla_nvme.c
+++ b/drivers/scsi/qla2xxx/qla_nvme.c
@@ -49,10 +49,7 @@ int qla_nvme_register_remote(struct scsi_qla_host *vha, struct fc_port *fcport)
 		return 0;
 	}
 
-	if (qla_nvme_register_hba(vha))
-		return 0;
-
-	if (!vha->nvme_local_port)
+	if (!vha->nvme_local_port && qla_nvme_register_hba(vha))
 		return 0;
 
 	if (!(fcport->nvme_prli_service_param &
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index bc3b2aea3f8b..fcb06df2ce4e 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -1875,9 +1875,14 @@ __qla2x00_abort_all_cmds(struct qla_qpair *qp, int res)
 	for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
 		sp = req->outstanding_cmds[cnt];
 		if (sp) {
+			/*
+			 * perform lockless completion during driver unload
+			 */
 			if (qla2x00_chip_is_down(vha)) {
 				req->outstanding_cmds[cnt] = NULL;
+				spin_unlock_irqrestore(qp->qp_lock_ptr, flags);
 				sp->done(sp, res);
+				spin_lock_irqsave(qp->qp_lock_ptr, flags);
 				continue;
 			}
 
@@ -4684,7 +4689,7 @@ static void
 qla2x00_number_of_exch(scsi_qla_host_t *vha, u32 *ret_cnt, u16 max_cnt)
 {
 	u32 temp;
-	struct init_cb_81xx *icb = (struct init_cb_81xx *)vha->hw->init_cb;
+	struct init_cb_81xx *icb = (struct init_cb_81xx *)&vha->hw->init_cb;
 	*ret_cnt = FW_DEF_EXCHANGES_CNT;
 
 	if (max_cnt > vha->hw->max_exchg)
@@ -5558,11 +5563,15 @@ qla2x00_do_work(struct scsi_qla_host *vha)
 			qla2x00_async_prlo_done(vha, e->u.logio.fcport,
 			    e->u.logio.data);
 			break;
-		case QLA_EVT_SCAN_CMD:
-			qla_fab_async_scan(vha, e->u.iosb.sp);
+		case QLA_EVT_GPNFT:
+			qla24xx_async_gpnft(vha, e->u.gpnft.fc4_type,
+			    e->u.gpnft.sp);
+			break;
+		case QLA_EVT_GPNFT_DONE:
+			qla24xx_async_gpnft_done(vha, e->u.iosb.sp);
 			break;
-		case QLA_EVT_SCAN_FINISH:
-			qla_fab_scan_finish(vha, e->u.iosb.sp);
+		case QLA_EVT_GNNFT_DONE:
+			qla24xx_async_gnnft_done(vha, e->u.iosb.sp);
 			break;
 		case QLA_EVT_GFPNID:
 			qla24xx_async_gfpnid(vha, e->u.fcport.fcport);
diff --git a/drivers/scsi/qla2xxx/qla_sup.c b/drivers/scsi/qla2xxx/qla_sup.c
index 6d16546e1729..c092a6b1ced4 100644
--- a/drivers/scsi/qla2xxx/qla_sup.c
+++ b/drivers/scsi/qla2xxx/qla_sup.c
@@ -555,7 +555,6 @@ qla2xxx_find_flt_start(scsi_qla_host_t *vha, uint32_t *start)
 	struct qla_flt_location *fltl = (void *)req->ring;
 	uint32_t *dcode = (uint32_t *)req->ring;
 	uint8_t *buf = (void *)req->ring, *bcode,  last_image;
-	int rc;
 
 	/*
 	 * FLT-location structure resides after the last PCI region.
@@ -585,24 +584,14 @@ qla2xxx_find_flt_start(scsi_qla_host_t *vha, uint32_t *start)
 	pcihdr = 0;
 	do {
 		/* Verify PCI expansion ROM header. */
-		rc = qla24xx_read_flash_data(vha, dcode, pcihdr >> 2, 0x20);
-		if (rc) {
-			ql_log(ql_log_info, vha, 0x016d,
-			    "Unable to read PCI Expansion Rom Header (%x).\n", rc);
-			return QLA_FUNCTION_FAILED;
-		}
+		qla24xx_read_flash_data(vha, dcode, pcihdr >> 2, 0x20);
 		bcode = buf + (pcihdr % 4);
 		if (bcode[0x0] != 0x55 || bcode[0x1] != 0xaa)
 			goto end;
 
 		/* Locate PCI data structure. */
 		pcids = pcihdr + ((bcode[0x19] << 8) | bcode[0x18]);
-		rc = qla24xx_read_flash_data(vha, dcode, pcids >> 2, 0x20);
-		if (rc) {
-			ql_log(ql_log_info, vha, 0x0179,
-			    "Unable to read PCI Data Structure (%x).\n", rc);
-			return QLA_FUNCTION_FAILED;
-		}
+		qla24xx_read_flash_data(vha, dcode, pcids >> 2, 0x20);
 		bcode = buf + (pcihdr % 4);
 
 		/* Validate signature of PCI data structure. */
@@ -617,12 +606,7 @@ qla2xxx_find_flt_start(scsi_qla_host_t *vha, uint32_t *start)
 	} while (!last_image);
 
 	/* Now verify FLT-location structure. */
-	rc = qla24xx_read_flash_data(vha, dcode, pcihdr >> 2, sizeof(*fltl) >> 2);
-	if (rc) {
-		ql_log(ql_log_info, vha, 0x017a,
-		    "Unable to read FLT (%x).\n", rc);
-		return QLA_FUNCTION_FAILED;
-	}
+	qla24xx_read_flash_data(vha, dcode, pcihdr >> 2, sizeof(*fltl) >> 2);
 	if (memcmp(fltl->sig, "QFLT", 4))
 		goto end;
 
@@ -2621,18 +2605,13 @@ qla24xx_read_optrom_data(struct scsi_qla_host *vha, void *buf,
     uint32_t offset, uint32_t length)
 {
 	struct qla_hw_data *ha = vha->hw;
-	int rc;
 
 	/* Suspend HBA. */
 	scsi_block_requests(vha->host);
 	set_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
 
 	/* Go with read. */
-	rc = qla24xx_read_flash_data(vha, buf, offset >> 2, length >> 2);
-	if (rc) {
-		ql_log(ql_log_info, vha, 0x01a0,
-		    "Unable to perform optrom read(%x).\n", rc);
-	}
+	qla24xx_read_flash_data(vha, buf, offset >> 2, length >> 2);
 
 	/* Resume HBA. */
 	clear_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
@@ -3433,7 +3412,7 @@ qla24xx_get_flash_version(scsi_qla_host_t *vha, void *mbuf)
 	struct active_regions active_regions = { };
 
 	if (IS_P3P_TYPE(ha))
-		return QLA_SUCCESS;
+		return ret;
 
 	if (!mbuf)
 		return QLA_FUNCTION_FAILED;
@@ -3453,31 +3432,20 @@ qla24xx_get_flash_version(scsi_qla_host_t *vha, void *mbuf)
 
 	do {
 		/* Verify PCI expansion ROM header. */
-		ret = qla24xx_read_flash_data(vha, dcode, pcihdr >> 2, 0x20);
-		if (ret) {
-			ql_log(ql_log_info, vha, 0x017d,
-			    "Unable to read PCI EXP Rom Header(%x).\n", ret);
-			return QLA_FUNCTION_FAILED;
-		}
-
+		qla24xx_read_flash_data(vha, dcode, pcihdr >> 2, 0x20);
 		bcode = mbuf + (pcihdr % 4);
 		if (memcmp(bcode, "\x55\xaa", 2)) {
 			/* No signature */
 			ql_log(ql_log_fatal, vha, 0x0059,
 			    "No matching ROM signature.\n");
-			return QLA_FUNCTION_FAILED;
+			ret = QLA_FUNCTION_FAILED;
+			break;
 		}
 
 		/* Locate PCI data structure. */
 		pcids = pcihdr + ((bcode[0x19] << 8) | bcode[0x18]);
 
-		ret = qla24xx_read_flash_data(vha, dcode, pcids >> 2, 0x20);
-		if (ret) {
-			ql_log(ql_log_info, vha, 0x018e,
-			    "Unable to read PCI Data Structure (%x).\n", ret);
-			return QLA_FUNCTION_FAILED;
-		}
-
+		qla24xx_read_flash_data(vha, dcode, pcids >> 2, 0x20);
 		bcode = mbuf + (pcihdr % 4);
 
 		/* Validate signature of PCI data structure. */
@@ -3486,7 +3454,8 @@ qla24xx_get_flash_version(scsi_qla_host_t *vha, void *mbuf)
 			ql_log(ql_log_fatal, vha, 0x005a,
 			    "PCI data struct not found pcir_adr=%x.\n", pcids);
 			ql_dump_buffer(ql_dbg_init, vha, 0x0059, dcode, 32);
-			return QLA_FUNCTION_FAILED;
+			ret = QLA_FUNCTION_FAILED;
+			break;
 		}
 
 		/* Read version */
@@ -3538,26 +3507,20 @@ qla24xx_get_flash_version(scsi_qla_host_t *vha, void *mbuf)
 			faddr = ha->flt_region_fw_sec;
 	}
 
-	ret = qla24xx_read_flash_data(vha, dcode, faddr, 8);
-	if (ret) {
-		ql_log(ql_log_info, vha, 0x019e,
-		    "Unable to read FW version (%x).\n", ret);
-		return ret;
+	qla24xx_read_flash_data(vha, dcode, faddr, 8);
+	if (qla24xx_risc_firmware_invalid(dcode)) {
+		ql_log(ql_log_warn, vha, 0x005f,
+		    "Unrecognized fw revision at %x.\n",
+		    ha->flt_region_fw * 4);
+		ql_dump_buffer(ql_dbg_init, vha, 0x005f, dcode, 32);
 	} else {
-		if (qla24xx_risc_firmware_invalid(dcode)) {
-			ql_log(ql_log_warn, vha, 0x005f,
-			    "Unrecognized fw revision at %x.\n",
-			    ha->flt_region_fw * 4);
-			ql_dump_buffer(ql_dbg_init, vha, 0x005f, dcode, 32);
-		} else {
-			for (i = 0; i < 4; i++)
-				ha->fw_revision[i] =
+		for (i = 0; i < 4; i++)
+			ha->fw_revision[i] =
 				be32_to_cpu((__force __be32)dcode[4+i]);
-			ql_dbg(ql_dbg_init, vha, 0x0060,
-			    "Firmware revision (flash) %u.%u.%u (%x).\n",
-			    ha->fw_revision[0], ha->fw_revision[1],
-			    ha->fw_revision[2], ha->fw_revision[3]);
-		}
+		ql_dbg(ql_dbg_init, vha, 0x0060,
+		    "Firmware revision (flash) %u.%u.%u (%x).\n",
+		    ha->fw_revision[0], ha->fw_revision[1],
+		    ha->fw_revision[2], ha->fw_revision[3]);
 	}
 
 	/* Check for golden firmware and get version if available */
@@ -3568,23 +3531,18 @@ qla24xx_get_flash_version(scsi_qla_host_t *vha, void *mbuf)
 
 	memset(ha->gold_fw_version, 0, sizeof(ha->gold_fw_version));
 	faddr = ha->flt_region_gold_fw;
-	ret = qla24xx_read_flash_data(vha, dcode, ha->flt_region_gold_fw, 8);
-	if (ret) {
-		ql_log(ql_log_info, vha, 0x019f,
-		    "Unable to read Gold FW version (%x).\n", ret);
+	qla24xx_read_flash_data(vha, dcode, ha->flt_region_gold_fw, 8);
+	if (qla24xx_risc_firmware_invalid(dcode)) {
+		ql_log(ql_log_warn, vha, 0x0056,
+		    "Unrecognized golden fw at %#x.\n", faddr);
+		ql_dump_buffer(ql_dbg_init, vha, 0x0056, dcode, 32);
 		return ret;
-	} else {
-		if (qla24xx_risc_firmware_invalid(dcode)) {
-			ql_log(ql_log_warn, vha, 0x0056,
-			    "Unrecognized golden fw at %#x.\n", faddr);
-			ql_dump_buffer(ql_dbg_init, vha, 0x0056, dcode, 32);
-			return QLA_FUNCTION_FAILED;
-		}
-
-		for (i = 0; i < 4; i++)
-			ha->gold_fw_version[i] =
-			   be32_to_cpu((__force __be32)dcode[4+i]);
 	}
+
+	for (i = 0; i < 4; i++)
+		ha->gold_fw_version[i] =
+			be32_to_cpu((__force __be32)dcode[4+i]);
+
 	return ret;
 }
 
diff --git a/drivers/scsi/qla2xxx/qla_version.h b/drivers/scsi/qla2xxx/qla_version.h
index cf0f9d9db645..7627fd807bc3 100644
--- a/drivers/scsi/qla2xxx/qla_version.h
+++ b/drivers/scsi/qla2xxx/qla_version.h
@@ -6,9 +6,9 @@
 /*
  * Driver version
  */
-#define QLA2XXX_VERSION      "10.02.09.300-k"
+#define QLA2XXX_VERSION      "10.02.09.200-k"
 
 #define QLA_DRIVER_MAJOR_VER	10
 #define QLA_DRIVER_MINOR_VER	2
 #define QLA_DRIVER_PATCH_VER	9
-#define QLA_DRIVER_BETA_VER	300
+#define QLA_DRIVER_BETA_VER	200
diff --git a/drivers/scsi/scsi_common.c b/drivers/scsi/scsi_common.c
index 04749fde1636..9c14fdf61037 100644
--- a/drivers/scsi/scsi_common.c
+++ b/drivers/scsi/scsi_common.c
@@ -12,7 +12,6 @@
 #include <asm/unaligned.h>
 #include <scsi/scsi_common.h>
 
-MODULE_DESCRIPTION("SCSI functions used by both the initiator and the target code");
 MODULE_LICENSE("GPL v2");
 
 /* Command group 3 is reserved and should never be used.  */
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index a9d8a9c62663..91f022fb8d0c 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -69,8 +69,6 @@ static const char *sdebug_version_date = "20210520";
 
 /* Additional Sense Code (ASC) */
 #define NO_ADDITIONAL_SENSE 0x0
-#define OVERLAP_ATOMIC_COMMAND_ASC 0x0
-#define OVERLAP_ATOMIC_COMMAND_ASCQ 0x23
 #define LOGICAL_UNIT_NOT_READY 0x4
 #define LOGICAL_UNIT_COMMUNICATION_FAILURE 0x8
 #define UNRECOVERED_READ_ERR 0x11
@@ -105,7 +103,6 @@ static const char *sdebug_version_date = "20210520";
 #define READ_BOUNDARY_ASCQ 0x7
 #define ATTEMPT_ACCESS_GAP 0x9
 #define INSUFF_ZONE_ASCQ 0xe
-/* see drivers/scsi/sense_codes.h */
 
 /* Additional Sense Code Qualifier (ASCQ) */
 #define ACK_NAK_TO 0x3
@@ -155,12 +152,6 @@ static const char *sdebug_version_date = "20210520";
 #define DEF_VIRTUAL_GB   0
 #define DEF_VPD_USE_HOSTNO 1
 #define DEF_WRITESAME_LENGTH 0xFFFF
-#define DEF_ATOMIC_WR 0
-#define DEF_ATOMIC_WR_MAX_LENGTH 8192
-#define DEF_ATOMIC_WR_ALIGN 2
-#define DEF_ATOMIC_WR_GRAN 2
-#define DEF_ATOMIC_WR_MAX_LENGTH_BNDRY (DEF_ATOMIC_WR_MAX_LENGTH)
-#define DEF_ATOMIC_WR_MAX_BNDRY 128
 #define DEF_STRICT 0
 #define DEF_STATISTICS false
 #define DEF_SUBMIT_QUEUES 1
@@ -383,9 +374,7 @@ struct sdebug_host_info {
 
 /* There is an xarray of pointers to this struct's objects, one per host */
 struct sdeb_store_info {
-	rwlock_t macc_data_lck;	/* for media data access on this store */
-	rwlock_t macc_meta_lck;	/* for atomic media meta access on this store */
-	rwlock_t macc_sector_lck;	/* per-sector media data access on this store */
+	rwlock_t macc_lck;	/* for atomic media access on this store */
 	u8 *storep;		/* user data storage (ram) */
 	struct t10_pi_tuple *dif_storep; /* protection info */
 	void *map_storep;	/* provisioning map */
@@ -409,20 +398,12 @@ struct sdebug_defer {
 	enum sdeb_defer_type defer_t;
 };
 
-struct sdebug_device_access_info {
-	bool atomic_write;
-	u64 lba;
-	u32 num;
-	struct scsi_cmnd *self;
-};
-
 struct sdebug_queued_cmd {
 	/* corresponding bit set in in_use_bm[] in owning struct sdebug_queue
 	 * instance indicates this slot is in use.
 	 */
 	struct sdebug_defer sd_dp;
 	struct scsi_cmnd *scmd;
-	struct sdebug_device_access_info *i;
 };
 
 struct sdebug_scsi_cmd {
@@ -482,8 +463,7 @@ enum sdeb_opcode_index {
 	SDEB_I_PRE_FETCH = 29,		/* 10, 16 */
 	SDEB_I_ZONE_OUT = 30,		/* 0x94+SA; includes no data xfer */
 	SDEB_I_ZONE_IN = 31,		/* 0x95+SA; all have data-in */
-	SDEB_I_ATOMIC_WRITE_16 = 32,
-	SDEB_I_LAST_ELEM_P1 = 33,	/* keep this last (previous + 1) */
+	SDEB_I_LAST_ELEM_P1 = 32,	/* keep this last (previous + 1) */
 };
 
 
@@ -517,8 +497,7 @@ static const unsigned char opcode_ind_arr[256] = {
 	0, 0, 0, SDEB_I_VERIFY,
 	SDEB_I_PRE_FETCH, SDEB_I_SYNC_CACHE, 0, SDEB_I_WRITE_SAME,
 	SDEB_I_ZONE_OUT, SDEB_I_ZONE_IN, 0, 0,
-	0, 0, 0, 0,
-	SDEB_I_ATOMIC_WRITE_16, 0, SDEB_I_SERV_ACT_IN_16, SDEB_I_SERV_ACT_OUT_16,
+	0, 0, 0, 0, 0, 0, SDEB_I_SERV_ACT_IN_16, SDEB_I_SERV_ACT_OUT_16,
 /* 0xa0; 0xa0->0xbf: 12 byte cdbs */
 	SDEB_I_REPORT_LUNS, SDEB_I_ATA_PT, 0, SDEB_I_MAINT_IN,
 	     SDEB_I_MAINT_OUT, 0, 0, 0,
@@ -568,7 +547,6 @@ static int resp_write_buffer(struct scsi_cmnd *, struct sdebug_dev_info *);
 static int resp_sync_cache(struct scsi_cmnd *, struct sdebug_dev_info *);
 static int resp_pre_fetch(struct scsi_cmnd *, struct sdebug_dev_info *);
 static int resp_report_zones(struct scsi_cmnd *, struct sdebug_dev_info *);
-static int resp_atomic_write(struct scsi_cmnd *, struct sdebug_dev_info *);
 static int resp_open_zone(struct scsi_cmnd *, struct sdebug_dev_info *);
 static int resp_close_zone(struct scsi_cmnd *, struct sdebug_dev_info *);
 static int resp_finish_zone(struct scsi_cmnd *, struct sdebug_dev_info *);
@@ -810,11 +788,6 @@ static const struct opcode_info_t opcode_info_arr[SDEB_I_LAST_ELEM_P1 + 1] = {
 	    resp_report_zones, zone_in_iarr, /* ZONE_IN(16), REPORT ZONES) */
 		{16,  0x0 /* SA */, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
 		 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xbf, 0xc7} },
-/* 31 */
-	{0, 0x0, 0x0, F_D_OUT | FF_MEDIA_IO,
-	    resp_atomic_write, NULL, /* ATOMIC WRITE 16 */
-		{16,  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
-		 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff} },
 /* sentinel */
 	{0xff, 0, 0, 0, NULL, NULL,		/* terminating element */
 	    {0,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
@@ -862,13 +835,6 @@ static unsigned int sdebug_unmap_granularity = DEF_UNMAP_GRANULARITY;
 static unsigned int sdebug_unmap_max_blocks = DEF_UNMAP_MAX_BLOCKS;
 static unsigned int sdebug_unmap_max_desc = DEF_UNMAP_MAX_DESC;
 static unsigned int sdebug_write_same_length = DEF_WRITESAME_LENGTH;
-static unsigned int sdebug_atomic_wr = DEF_ATOMIC_WR;
-static unsigned int sdebug_atomic_wr_max_length = DEF_ATOMIC_WR_MAX_LENGTH;
-static unsigned int sdebug_atomic_wr_align = DEF_ATOMIC_WR_ALIGN;
-static unsigned int sdebug_atomic_wr_gran = DEF_ATOMIC_WR_GRAN;
-static unsigned int sdebug_atomic_wr_max_length_bndry =
-			DEF_ATOMIC_WR_MAX_LENGTH_BNDRY;
-static unsigned int sdebug_atomic_wr_max_bndry = DEF_ATOMIC_WR_MAX_BNDRY;
 static int sdebug_uuid_ctl = DEF_UUID_CTL;
 static bool sdebug_random = DEF_RANDOM;
 static bool sdebug_per_host_store = DEF_PER_HOST_STORE;
@@ -1226,11 +1192,6 @@ static inline bool scsi_debug_lbp(void)
 		(sdebug_lbpu || sdebug_lbpws || sdebug_lbpws10);
 }
 
-static inline bool scsi_debug_atomic_write(void)
-{
-	return sdebug_fake_rw == 0 && sdebug_atomic_wr;
-}
-
 static void *lba2fake_store(struct sdeb_store_info *sip,
 			    unsigned long long lba)
 {
@@ -1858,14 +1819,6 @@ static int inquiry_vpd_b0(unsigned char *arr)
 	/* Maximum WRITE SAME Length */
 	put_unaligned_be64(sdebug_write_same_length, &arr[32]);
 
-	if (sdebug_atomic_wr) {
-		put_unaligned_be32(sdebug_atomic_wr_max_length, &arr[40]);
-		put_unaligned_be32(sdebug_atomic_wr_align, &arr[44]);
-		put_unaligned_be32(sdebug_atomic_wr_gran, &arr[48]);
-		put_unaligned_be32(sdebug_atomic_wr_max_length_bndry, &arr[52]);
-		put_unaligned_be32(sdebug_atomic_wr_max_bndry, &arr[56]);
-	}
-
 	return 0x3c; /* Mandatory page length for Logical Block Provisioning */
 }
 
@@ -3428,238 +3381,16 @@ static inline struct sdeb_store_info *devip2sip(struct sdebug_dev_info *devip,
 	return xa_load(per_store_ap, devip->sdbg_host->si_idx);
 }
 
-static inline void
-sdeb_read_lock(rwlock_t *lock)
-{
-	if (sdebug_no_rwlock)
-		__acquire(lock);
-	else
-		read_lock(lock);
-}
-
-static inline void
-sdeb_read_unlock(rwlock_t *lock)
-{
-	if (sdebug_no_rwlock)
-		__release(lock);
-	else
-		read_unlock(lock);
-}
-
-static inline void
-sdeb_write_lock(rwlock_t *lock)
-{
-	if (sdebug_no_rwlock)
-		__acquire(lock);
-	else
-		write_lock(lock);
-}
-
-static inline void
-sdeb_write_unlock(rwlock_t *lock)
-{
-	if (sdebug_no_rwlock)
-		__release(lock);
-	else
-		write_unlock(lock);
-}
-
-static inline void
-sdeb_data_read_lock(struct sdeb_store_info *sip)
-{
-	BUG_ON(!sip);
-
-	sdeb_read_lock(&sip->macc_data_lck);
-}
-
-static inline void
-sdeb_data_read_unlock(struct sdeb_store_info *sip)
-{
-	BUG_ON(!sip);
-
-	sdeb_read_unlock(&sip->macc_data_lck);
-}
-
-static inline void
-sdeb_data_write_lock(struct sdeb_store_info *sip)
-{
-	BUG_ON(!sip);
-
-	sdeb_write_lock(&sip->macc_data_lck);
-}
-
-static inline void
-sdeb_data_write_unlock(struct sdeb_store_info *sip)
-{
-	BUG_ON(!sip);
-
-	sdeb_write_unlock(&sip->macc_data_lck);
-}
-
-static inline void
-sdeb_data_sector_read_lock(struct sdeb_store_info *sip)
-{
-	BUG_ON(!sip);
-
-	sdeb_read_lock(&sip->macc_sector_lck);
-}
-
-static inline void
-sdeb_data_sector_read_unlock(struct sdeb_store_info *sip)
-{
-	BUG_ON(!sip);
-
-	sdeb_read_unlock(&sip->macc_sector_lck);
-}
-
-static inline void
-sdeb_data_sector_write_lock(struct sdeb_store_info *sip)
-{
-	BUG_ON(!sip);
-
-	sdeb_write_lock(&sip->macc_sector_lck);
-}
-
-static inline void
-sdeb_data_sector_write_unlock(struct sdeb_store_info *sip)
-{
-	BUG_ON(!sip);
-
-	sdeb_write_unlock(&sip->macc_sector_lck);
-}
-
-/*
- * Atomic locking:
- * We simplify the atomic model to allow only 1x atomic write and many non-
- * atomic reads or writes for all LBAs.
-
- * A RW lock has a similar bahaviour:
- * Only 1x writer and many readers.
-
- * So use a RW lock for per-device read and write locking:
- * An atomic access grabs the lock as a writer and non-atomic grabs the lock
- * as a reader.
- */
-
-static inline void
-sdeb_data_lock(struct sdeb_store_info *sip, bool atomic)
-{
-	if (atomic)
-		sdeb_data_write_lock(sip);
-	else
-		sdeb_data_read_lock(sip);
-}
-
-static inline void
-sdeb_data_unlock(struct sdeb_store_info *sip, bool atomic)
-{
-	if (atomic)
-		sdeb_data_write_unlock(sip);
-	else
-		sdeb_data_read_unlock(sip);
-}
-
-/* Allow many reads but only 1x write per sector */
-static inline void
-sdeb_data_sector_lock(struct sdeb_store_info *sip, bool do_write)
-{
-	if (do_write)
-		sdeb_data_sector_write_lock(sip);
-	else
-		sdeb_data_sector_read_lock(sip);
-}
-
-static inline void
-sdeb_data_sector_unlock(struct sdeb_store_info *sip, bool do_write)
-{
-	if (do_write)
-		sdeb_data_sector_write_unlock(sip);
-	else
-		sdeb_data_sector_read_unlock(sip);
-}
-
-static inline void
-sdeb_meta_read_lock(struct sdeb_store_info *sip)
-{
-	if (sdebug_no_rwlock) {
-		if (sip)
-			__acquire(&sip->macc_meta_lck);
-		else
-			__acquire(&sdeb_fake_rw_lck);
-	} else {
-		if (sip)
-			read_lock(&sip->macc_meta_lck);
-		else
-			read_lock(&sdeb_fake_rw_lck);
-	}
-}
-
-static inline void
-sdeb_meta_read_unlock(struct sdeb_store_info *sip)
-{
-	if (sdebug_no_rwlock) {
-		if (sip)
-			__release(&sip->macc_meta_lck);
-		else
-			__release(&sdeb_fake_rw_lck);
-	} else {
-		if (sip)
-			read_unlock(&sip->macc_meta_lck);
-		else
-			read_unlock(&sdeb_fake_rw_lck);
-	}
-}
-
-static inline void
-sdeb_meta_write_lock(struct sdeb_store_info *sip)
-{
-	if (sdebug_no_rwlock) {
-		if (sip)
-			__acquire(&sip->macc_meta_lck);
-		else
-			__acquire(&sdeb_fake_rw_lck);
-	} else {
-		if (sip)
-			write_lock(&sip->macc_meta_lck);
-		else
-			write_lock(&sdeb_fake_rw_lck);
-	}
-}
-
-static inline void
-sdeb_meta_write_unlock(struct sdeb_store_info *sip)
-{
-	if (sdebug_no_rwlock) {
-		if (sip)
-			__release(&sip->macc_meta_lck);
-		else
-			__release(&sdeb_fake_rw_lck);
-	} else {
-		if (sip)
-			write_unlock(&sip->macc_meta_lck);
-		else
-			write_unlock(&sdeb_fake_rw_lck);
-	}
-}
-
 /* Returns number of bytes copied or -1 if error. */
 static int do_device_access(struct sdeb_store_info *sip, struct scsi_cmnd *scp,
-			    u32 sg_skip, u64 lba, u32 num, u8 group_number,
-			    bool do_write, bool atomic)
+			    u32 sg_skip, u64 lba, u32 num, bool do_write,
+			    u8 group_number)
 {
 	int ret;
-	u64 block;
+	u64 block, rest = 0;
 	enum dma_data_direction dir;
 	struct scsi_data_buffer *sdb = &scp->sdb;
 	u8 *fsp;
-	int i;
-
-	/*
-	 * Even though reads are inherently atomic (in this driver), we expect
-	 * the atomic flag only for writes.
-	 */
-	if (!do_write && atomic)
-		return -1;
 
 	if (do_write) {
 		dir = DMA_TO_DEVICE;
@@ -3679,26 +3410,21 @@ static int do_device_access(struct sdeb_store_info *sip, struct scsi_cmnd *scp,
 	fsp = sip->storep;
 
 	block = do_div(lba, sdebug_store_sectors);
+	if (block + num > sdebug_store_sectors)
+		rest = block + num - sdebug_store_sectors;
 
-	/* Only allow 1x atomic write or multiple non-atomic writes at any given time */
-	sdeb_data_lock(sip, atomic);
-	for (i = 0; i < num; i++) {
-		/* We shouldn't need to lock for atomic writes, but do it anyway */
-		sdeb_data_sector_lock(sip, do_write);
-		ret = sg_copy_buffer(sdb->table.sgl, sdb->table.nents,
+	ret = sg_copy_buffer(sdb->table.sgl, sdb->table.nents,
 		   fsp + (block * sdebug_sector_size),
-		   sdebug_sector_size, sg_skip, do_write);
-		sdeb_data_sector_unlock(sip, do_write);
-		if (ret != sdebug_sector_size) {
-			ret += (i * sdebug_sector_size);
-			break;
-		}
-		sg_skip += sdebug_sector_size;
-		if (++block >= sdebug_store_sectors)
-			block = 0;
+		   (num - rest) * sdebug_sector_size, sg_skip, do_write);
+	if (ret != (num - rest) * sdebug_sector_size)
+		return ret;
+
+	if (rest) {
+		ret += sg_copy_buffer(sdb->table.sgl, sdb->table.nents,
+			    fsp, rest * sdebug_sector_size,
+			    sg_skip + ((num - rest) * sdebug_sector_size),
+			    do_write);
 	}
-	ret = num * sdebug_sector_size;
-	sdeb_data_unlock(sip, atomic);
 
 	return ret;
 }
@@ -3874,6 +3600,70 @@ static int prot_verify_read(struct scsi_cmnd *scp, sector_t start_sec,
 	return ret;
 }
 
+static inline void
+sdeb_read_lock(struct sdeb_store_info *sip)
+{
+	if (sdebug_no_rwlock) {
+		if (sip)
+			__acquire(&sip->macc_lck);
+		else
+			__acquire(&sdeb_fake_rw_lck);
+	} else {
+		if (sip)
+			read_lock(&sip->macc_lck);
+		else
+			read_lock(&sdeb_fake_rw_lck);
+	}
+}
+
+static inline void
+sdeb_read_unlock(struct sdeb_store_info *sip)
+{
+	if (sdebug_no_rwlock) {
+		if (sip)
+			__release(&sip->macc_lck);
+		else
+			__release(&sdeb_fake_rw_lck);
+	} else {
+		if (sip)
+			read_unlock(&sip->macc_lck);
+		else
+			read_unlock(&sdeb_fake_rw_lck);
+	}
+}
+
+static inline void
+sdeb_write_lock(struct sdeb_store_info *sip)
+{
+	if (sdebug_no_rwlock) {
+		if (sip)
+			__acquire(&sip->macc_lck);
+		else
+			__acquire(&sdeb_fake_rw_lck);
+	} else {
+		if (sip)
+			write_lock(&sip->macc_lck);
+		else
+			write_lock(&sdeb_fake_rw_lck);
+	}
+}
+
+static inline void
+sdeb_write_unlock(struct sdeb_store_info *sip)
+{
+	if (sdebug_no_rwlock) {
+		if (sip)
+			__release(&sip->macc_lck);
+		else
+			__release(&sdeb_fake_rw_lck);
+	} else {
+		if (sip)
+			write_unlock(&sip->macc_lck);
+		else
+			write_unlock(&sdeb_fake_rw_lck);
+	}
+}
+
 static int resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
 {
 	bool check_prot;
@@ -3883,7 +3673,6 @@ static int resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
 	u64 lba;
 	struct sdeb_store_info *sip = devip2sip(devip, true);
 	u8 *cmd = scp->cmnd;
-	bool meta_data_locked = false;
 
 	switch (cmd[0]) {
 	case READ_16:
@@ -3942,10 +3731,6 @@ static int resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
 		atomic_set(&sdeb_inject_pending, 0);
 	}
 
-	/*
-	 * When checking device access params, for reads we only check data
-	 * versus what is set at init time, so no need to lock.
-	 */
 	ret = check_device_access_params(scp, lba, num, false);
 	if (ret)
 		return ret;
@@ -3965,33 +3750,29 @@ static int resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
 		return check_condition_result;
 	}
 
-	if (sdebug_dev_is_zoned(devip) ||
-	    (sdebug_dix && scsi_prot_sg_count(scp)))  {
-		sdeb_meta_read_lock(sip);
-		meta_data_locked = true;
-	}
+	sdeb_read_lock(sip);
 
 	/* DIX + T10 DIF */
 	if (unlikely(sdebug_dix && scsi_prot_sg_count(scp))) {
 		switch (prot_verify_read(scp, lba, num, ei_lba)) {
 		case 1: /* Guard tag error */
 			if (cmd[1] >> 5 != 3) { /* RDPROTECT != 3 */
-				sdeb_meta_read_unlock(sip);
+				sdeb_read_unlock(sip);
 				mk_sense_buffer(scp, ABORTED_COMMAND, 0x10, 1);
 				return check_condition_result;
 			} else if (scp->prot_flags & SCSI_PROT_GUARD_CHECK) {
-				sdeb_meta_read_unlock(sip);
+				sdeb_read_unlock(sip);
 				mk_sense_buffer(scp, ILLEGAL_REQUEST, 0x10, 1);
 				return illegal_condition_result;
 			}
 			break;
 		case 3: /* Reference tag error */
 			if (cmd[1] >> 5 != 3) { /* RDPROTECT != 3 */
-				sdeb_meta_read_unlock(sip);
+				sdeb_read_unlock(sip);
 				mk_sense_buffer(scp, ABORTED_COMMAND, 0x10, 3);
 				return check_condition_result;
 			} else if (scp->prot_flags & SCSI_PROT_REF_CHECK) {
-				sdeb_meta_read_unlock(sip);
+				sdeb_read_unlock(sip);
 				mk_sense_buffer(scp, ILLEGAL_REQUEST, 0x10, 3);
 				return illegal_condition_result;
 			}
@@ -3999,9 +3780,8 @@ static int resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
 		}
 	}
 
-	ret = do_device_access(sip, scp, 0, lba, num, 0, false, false);
-	if (meta_data_locked)
-		sdeb_meta_read_unlock(sip);
+	ret = do_device_access(sip, scp, 0, lba, num, false, 0);
+	sdeb_read_unlock(sip);
 	if (unlikely(ret == -1))
 		return DID_ERROR << 16;
 
@@ -4191,7 +3971,6 @@ static int resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
 	u64 lba;
 	struct sdeb_store_info *sip = devip2sip(devip, true);
 	u8 *cmd = scp->cmnd;
-	bool meta_data_locked = false;
 
 	switch (cmd[0]) {
 	case WRITE_16:
@@ -4250,17 +4029,10 @@ static int resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
 				    "to DIF device\n");
 	}
 
-	if (sdebug_dev_is_zoned(devip) ||
-	    (sdebug_dix && scsi_prot_sg_count(scp)) ||
-	    scsi_debug_lbp())  {
-		sdeb_meta_write_lock(sip);
-		meta_data_locked = true;
-	}
-
+	sdeb_write_lock(sip);
 	ret = check_device_access_params(scp, lba, num, true);
 	if (ret) {
-		if (meta_data_locked)
-			sdeb_meta_write_unlock(sip);
+		sdeb_write_unlock(sip);
 		return ret;
 	}
 
@@ -4269,22 +4041,22 @@ static int resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
 		switch (prot_verify_write(scp, lba, num, ei_lba)) {
 		case 1: /* Guard tag error */
 			if (scp->prot_flags & SCSI_PROT_GUARD_CHECK) {
-				sdeb_meta_write_unlock(sip);
+				sdeb_write_unlock(sip);
 				mk_sense_buffer(scp, ILLEGAL_REQUEST, 0x10, 1);
 				return illegal_condition_result;
 			} else if (scp->cmnd[1] >> 5 != 3) { /* WRPROTECT != 3 */
-				sdeb_meta_write_unlock(sip);
+				sdeb_write_unlock(sip);
 				mk_sense_buffer(scp, ABORTED_COMMAND, 0x10, 1);
 				return check_condition_result;
 			}
 			break;
 		case 3: /* Reference tag error */
 			if (scp->prot_flags & SCSI_PROT_REF_CHECK) {
-				sdeb_meta_write_unlock(sip);
+				sdeb_write_unlock(sip);
 				mk_sense_buffer(scp, ILLEGAL_REQUEST, 0x10, 3);
 				return illegal_condition_result;
 			} else if (scp->cmnd[1] >> 5 != 3) { /* WRPROTECT != 3 */
-				sdeb_meta_write_unlock(sip);
+				sdeb_write_unlock(sip);
 				mk_sense_buffer(scp, ABORTED_COMMAND, 0x10, 3);
 				return check_condition_result;
 			}
@@ -4292,16 +4064,13 @@ static int resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
 		}
 	}
 
-	ret = do_device_access(sip, scp, 0, lba, num, group, true, false);
+	ret = do_device_access(sip, scp, 0, lba, num, true, group);
 	if (unlikely(scsi_debug_lbp()))
 		map_region(sip, lba, num);
-
 	/* If ZBC zone then bump its write pointer */
 	if (sdebug_dev_is_zoned(devip))
 		zbc_inc_wp(devip, lba, num);
-	if (meta_data_locked)
-		sdeb_meta_write_unlock(sip);
-
+	sdeb_write_unlock(sip);
 	if (unlikely(-1 == ret))
 		return DID_ERROR << 16;
 	else if (unlikely(sdebug_verbose &&
@@ -4411,8 +4180,7 @@ static int resp_write_scat(struct scsi_cmnd *scp,
 		goto err_out;
 	}
 
-	/* Just keep it simple and always lock for now */
-	sdeb_meta_write_lock(sip);
+	sdeb_write_lock(sip);
 	sg_off = lbdof_blen;
 	/* Spec says Buffer xfer Length field in number of LBs in dout */
 	cum_lb = 0;
@@ -4455,11 +4223,7 @@ static int resp_write_scat(struct scsi_cmnd *scp,
 			}
 		}
 
-		/*
-		 * Write ranges atomically to keep as close to pre-atomic
-		 * writes behaviour as possible.
-		 */
-		ret = do_device_access(sip, scp, sg_off, lba, num, group, true, true);
+		ret = do_device_access(sip, scp, sg_off, lba, num, true, group);
 		/* If ZBC zone then bump its write pointer */
 		if (sdebug_dev_is_zoned(devip))
 			zbc_inc_wp(devip, lba, num);
@@ -4498,7 +4262,7 @@ static int resp_write_scat(struct scsi_cmnd *scp,
 	}
 	ret = 0;
 err_out_unlock:
-	sdeb_meta_write_unlock(sip);
+	sdeb_write_unlock(sip);
 err_out:
 	kfree(lrdp);
 	return ret;
@@ -4517,16 +4281,14 @@ static int resp_write_same(struct scsi_cmnd *scp, u64 lba, u32 num,
 						scp->device->hostdata, true);
 	u8 *fs1p;
 	u8 *fsp;
-	bool meta_data_locked = false;
 
-	if (sdebug_dev_is_zoned(devip) || scsi_debug_lbp()) {
-		sdeb_meta_write_lock(sip);
-		meta_data_locked = true;
-	}
+	sdeb_write_lock(sip);
 
 	ret = check_device_access_params(scp, lba, num, true);
-	if (ret)
-		goto out;
+	if (ret) {
+		sdeb_write_unlock(sip);
+		return ret;
+	}
 
 	if (unmap && scsi_debug_lbp()) {
 		unmap_region(sip, lba, num);
@@ -4537,7 +4299,6 @@ static int resp_write_same(struct scsi_cmnd *scp, u64 lba, u32 num,
 	/* if ndob then zero 1 logical block, else fetch 1 logical block */
 	fsp = sip->storep;
 	fs1p = fsp + (block * lb_size);
-	sdeb_data_write_lock(sip);
 	if (ndob) {
 		memset(fs1p, 0, lb_size);
 		ret = 0;
@@ -4545,8 +4306,8 @@ static int resp_write_same(struct scsi_cmnd *scp, u64 lba, u32 num,
 		ret = fetch_to_dev_buffer(scp, fs1p, lb_size);
 
 	if (-1 == ret) {
-		ret = DID_ERROR << 16;
-		goto out;
+		sdeb_write_unlock(sip);
+		return DID_ERROR << 16;
 	} else if (sdebug_verbose && !ndob && (ret < lb_size))
 		sdev_printk(KERN_INFO, scp->device,
 			    "%s: %s: lb size=%u, IO sent=%d bytes\n",
@@ -4563,12 +4324,10 @@ static int resp_write_same(struct scsi_cmnd *scp, u64 lba, u32 num,
 	/* If ZBC zone then bump its write pointer */
 	if (sdebug_dev_is_zoned(devip))
 		zbc_inc_wp(devip, lba, num);
-	sdeb_data_write_unlock(sip);
-	ret = 0;
 out:
-	if (meta_data_locked)
-		sdeb_meta_write_unlock(sip);
-	return ret;
+	sdeb_write_unlock(sip);
+
+	return 0;
 }
 
 static int resp_write_same_10(struct scsi_cmnd *scp,
@@ -4711,30 +4470,25 @@ static int resp_comp_write(struct scsi_cmnd *scp,
 		return check_condition_result;
 	}
 
+	sdeb_write_lock(sip);
+
 	ret = do_dout_fetch(scp, dnum, arr);
 	if (ret == -1) {
 		retval = DID_ERROR << 16;
-		goto cleanup_free;
+		goto cleanup;
 	} else if (sdebug_verbose && (ret < (dnum * lb_size)))
 		sdev_printk(KERN_INFO, scp->device, "%s: compare_write: cdb "
 			    "indicated=%u, IO sent=%d bytes\n", my_name,
 			    dnum * lb_size, ret);
-
-	sdeb_data_write_lock(sip);
-	sdeb_meta_write_lock(sip);
 	if (!comp_write_worker(sip, lba, num, arr, false)) {
 		mk_sense_buffer(scp, MISCOMPARE, MISCOMPARE_VERIFY_ASC, 0);
 		retval = check_condition_result;
-		goto cleanup_unlock;
+		goto cleanup;
 	}
-
-	/* Cover sip->map_storep (which map_region()) sets with data lock */
 	if (scsi_debug_lbp())
 		map_region(sip, lba, num);
-cleanup_unlock:
-	sdeb_meta_write_unlock(sip);
-	sdeb_data_write_unlock(sip);
-cleanup_free:
+cleanup:
+	sdeb_write_unlock(sip);
 	kfree(arr);
 	return retval;
 }
@@ -4778,7 +4532,7 @@ static int resp_unmap(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
 
 	desc = (void *)&buf[8];
 
-	sdeb_meta_write_lock(sip);
+	sdeb_write_lock(sip);
 
 	for (i = 0 ; i < descriptors ; i++) {
 		unsigned long long lba = get_unaligned_be64(&desc[i].lba);
@@ -4794,7 +4548,7 @@ static int resp_unmap(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
 	ret = 0;
 
 out:
-	sdeb_meta_write_unlock(sip);
+	sdeb_write_unlock(sip);
 	kfree(buf);
 
 	return ret;
@@ -4952,13 +4706,12 @@ static int resp_pre_fetch(struct scsi_cmnd *scp,
 		rest = block + nblks - sdebug_store_sectors;
 
 	/* Try to bring the PRE-FETCH range into CPU's cache */
-	sdeb_data_read_lock(sip);
+	sdeb_read_lock(sip);
 	prefetch_range(fsp + (sdebug_sector_size * block),
 		       (nblks - rest) * sdebug_sector_size);
 	if (rest)
 		prefetch_range(fsp, rest * sdebug_sector_size);
-
-	sdeb_data_read_unlock(sip);
+	sdeb_read_unlock(sip);
 fini:
 	if (cmd[1] & 0x2)
 		res = SDEG_RES_IMMED_MASK;
@@ -5117,7 +4870,7 @@ static int resp_verify(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
 		return check_condition_result;
 	}
 	/* Not changing store, so only need read access */
-	sdeb_data_read_lock(sip);
+	sdeb_read_lock(sip);
 
 	ret = do_dout_fetch(scp, a_num, arr);
 	if (ret == -1) {
@@ -5139,7 +4892,7 @@ static int resp_verify(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
 		goto cleanup;
 	}
 cleanup:
-	sdeb_data_read_unlock(sip);
+	sdeb_read_unlock(sip);
 	kfree(arr);
 	return ret;
 }
@@ -5185,7 +4938,7 @@ static int resp_report_zones(struct scsi_cmnd *scp,
 		return check_condition_result;
 	}
 
-	sdeb_meta_read_lock(sip);
+	sdeb_read_lock(sip);
 
 	desc = arr + 64;
 	for (lba = zs_lba; lba < sdebug_capacity;
@@ -5283,70 +5036,11 @@ static int resp_report_zones(struct scsi_cmnd *scp,
 	ret = fill_from_dev_buffer(scp, arr, min_t(u32, alloc_len, rep_len));
 
 fini:
-	sdeb_meta_read_unlock(sip);
+	sdeb_read_unlock(sip);
 	kfree(arr);
 	return ret;
 }
 
-static int resp_atomic_write(struct scsi_cmnd *scp,
-			     struct sdebug_dev_info *devip)
-{
-	struct sdeb_store_info *sip;
-	u8 *cmd = scp->cmnd;
-	u16 boundary, len;
-	u64 lba, lba_tmp;
-	int ret;
-
-	if (!scsi_debug_atomic_write()) {
-		mk_sense_invalid_opcode(scp);
-		return check_condition_result;
-	}
-
-	sip = devip2sip(devip, true);
-
-	lba = get_unaligned_be64(cmd + 2);
-	boundary = get_unaligned_be16(cmd + 10);
-	len = get_unaligned_be16(cmd + 12);
-
-	lba_tmp = lba;
-	if (sdebug_atomic_wr_align &&
-	    do_div(lba_tmp, sdebug_atomic_wr_align)) {
-		/* Does not meet alignment requirement */
-		mk_sense_buffer(scp, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, 0);
-		return check_condition_result;
-	}
-
-	if (sdebug_atomic_wr_gran && len % sdebug_atomic_wr_gran) {
-		/* Does not meet alignment requirement */
-		mk_sense_buffer(scp, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, 0);
-		return check_condition_result;
-	}
-
-	if (boundary > 0) {
-		if (boundary > sdebug_atomic_wr_max_bndry) {
-			mk_sense_invalid_fld(scp, SDEB_IN_CDB, 12, -1);
-			return check_condition_result;
-		}
-
-		if (len > sdebug_atomic_wr_max_length_bndry) {
-			mk_sense_invalid_fld(scp, SDEB_IN_CDB, 12, -1);
-			return check_condition_result;
-		}
-	} else {
-		if (len > sdebug_atomic_wr_max_length) {
-			mk_sense_invalid_fld(scp, SDEB_IN_CDB, 12, -1);
-			return check_condition_result;
-		}
-	}
-
-	ret = do_device_access(sip, scp, 0, lba, len, 0, true, true);
-	if (unlikely(ret == -1))
-		return DID_ERROR << 16;
-	if (unlikely(ret != len * sdebug_sector_size))
-		return DID_ERROR << 16;
-	return 0;
-}
-
 /* Logic transplanted from tcmu-runner, file_zbc.c */
 static void zbc_open_all(struct sdebug_dev_info *devip)
 {
@@ -5373,7 +5067,8 @@ static int resp_open_zone(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
 		mk_sense_invalid_opcode(scp);
 		return check_condition_result;
 	}
-	sdeb_meta_write_lock(sip);
+
+	sdeb_write_lock(sip);
 
 	if (all) {
 		/* Check if all closed zones can be open */
@@ -5422,7 +5117,7 @@ static int resp_open_zone(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
 
 	zbc_open_zone(devip, zsp, true);
 fini:
-	sdeb_meta_write_unlock(sip);
+	sdeb_write_unlock(sip);
 	return res;
 }
 
@@ -5449,7 +5144,7 @@ static int resp_close_zone(struct scsi_cmnd *scp,
 		return check_condition_result;
 	}
 
-	sdeb_meta_write_lock(sip);
+	sdeb_write_lock(sip);
 
 	if (all) {
 		zbc_close_all(devip);
@@ -5478,7 +5173,7 @@ static int resp_close_zone(struct scsi_cmnd *scp,
 
 	zbc_close_zone(devip, zsp);
 fini:
-	sdeb_meta_write_unlock(sip);
+	sdeb_write_unlock(sip);
 	return res;
 }
 
@@ -5521,7 +5216,7 @@ static int resp_finish_zone(struct scsi_cmnd *scp,
 		return check_condition_result;
 	}
 
-	sdeb_meta_write_lock(sip);
+	sdeb_write_lock(sip);
 
 	if (all) {
 		zbc_finish_all(devip);
@@ -5550,7 +5245,7 @@ static int resp_finish_zone(struct scsi_cmnd *scp,
 
 	zbc_finish_zone(devip, zsp, true);
 fini:
-	sdeb_meta_write_unlock(sip);
+	sdeb_write_unlock(sip);
 	return res;
 }
 
@@ -5601,7 +5296,7 @@ static int resp_rwp_zone(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
 		return check_condition_result;
 	}
 
-	sdeb_meta_write_lock(sip);
+	sdeb_write_lock(sip);
 
 	if (all) {
 		zbc_rwp_all(devip);
@@ -5629,7 +5324,7 @@ static int resp_rwp_zone(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
 
 	zbc_rwp_zone(devip, zsp);
 fini:
-	sdeb_meta_write_unlock(sip);
+	sdeb_write_unlock(sip);
 	return res;
 }
 
@@ -6593,7 +6288,6 @@ module_param_named(lbprz, sdebug_lbprz, int, S_IRUGO);
 module_param_named(lbpu, sdebug_lbpu, int, S_IRUGO);
 module_param_named(lbpws, sdebug_lbpws, int, S_IRUGO);
 module_param_named(lbpws10, sdebug_lbpws10, int, S_IRUGO);
-module_param_named(atomic_wr, sdebug_atomic_wr, int, S_IRUGO);
 module_param_named(lowest_aligned, sdebug_lowest_aligned, int, S_IRUGO);
 module_param_named(lun_format, sdebug_lun_am_i, int, S_IRUGO | S_IWUSR);
 module_param_named(max_luns, sdebug_max_luns, int, S_IRUGO | S_IWUSR);
@@ -6628,11 +6322,6 @@ module_param_named(unmap_alignment, sdebug_unmap_alignment, int, S_IRUGO);
 module_param_named(unmap_granularity, sdebug_unmap_granularity, int, S_IRUGO);
 module_param_named(unmap_max_blocks, sdebug_unmap_max_blocks, int, S_IRUGO);
 module_param_named(unmap_max_desc, sdebug_unmap_max_desc, int, S_IRUGO);
-module_param_named(atomic_wr_max_length, sdebug_atomic_wr_max_length, int, S_IRUGO);
-module_param_named(atomic_wr_align, sdebug_atomic_wr_align, int, S_IRUGO);
-module_param_named(atomic_wr_gran, sdebug_atomic_wr_gran, int, S_IRUGO);
-module_param_named(atomic_wr_max_length_bndry, sdebug_atomic_wr_max_length_bndry, int, S_IRUGO);
-module_param_named(atomic_wr_max_bndry, sdebug_atomic_wr_max_bndry, int, S_IRUGO);
 module_param_named(uuid_ctl, sdebug_uuid_ctl, int, S_IRUGO);
 module_param_named(virtual_gb, sdebug_virtual_gb, int, S_IRUGO | S_IWUSR);
 module_param_named(vpd_use_hostno, sdebug_vpd_use_hostno, int,
@@ -6676,7 +6365,6 @@ MODULE_PARM_DESC(lbprz,
 MODULE_PARM_DESC(lbpu, "enable LBP, support UNMAP command (def=0)");
 MODULE_PARM_DESC(lbpws, "enable LBP, support WRITE SAME(16) with UNMAP bit (def=0)");
 MODULE_PARM_DESC(lbpws10, "enable LBP, support WRITE SAME(10) with UNMAP bit (def=0)");
-MODULE_PARM_DESC(atomic_write, "enable ATOMIC WRITE support, support WRITE ATOMIC(16) (def=0)");
 MODULE_PARM_DESC(lowest_aligned, "lowest aligned lba (def=0)");
 MODULE_PARM_DESC(lun_format, "LUN format: 0->peripheral (def); 1 --> flat address method");
 MODULE_PARM_DESC(max_luns, "number of LUNs per target to simulate(def=1)");
@@ -6708,11 +6396,6 @@ MODULE_PARM_DESC(unmap_alignment, "lowest aligned thin provisioning lba (def=0)"
 MODULE_PARM_DESC(unmap_granularity, "thin provisioning granularity in blocks (def=1)");
 MODULE_PARM_DESC(unmap_max_blocks, "max # of blocks can be unmapped in one cmd (def=0xffffffff)");
 MODULE_PARM_DESC(unmap_max_desc, "max # of ranges that can be unmapped in one cmd (def=256)");
-MODULE_PARM_DESC(atomic_wr_max_length, "max # of blocks can be atomically written in one cmd (def=8192)");
-MODULE_PARM_DESC(atomic_wr_align, "minimum alignment of atomic write in blocks (def=2)");
-MODULE_PARM_DESC(atomic_wr_gran, "minimum granularity of atomic write in blocks (def=2)");
-MODULE_PARM_DESC(atomic_wr_max_length_bndry, "max # of blocks can be atomically written in one cmd with boundary set (def=8192)");
-MODULE_PARM_DESC(atomic_wr_max_bndry, "max # boundaries per atomic write (def=128)");
 MODULE_PARM_DESC(uuid_ctl,
 		 "1->use uuid for lu name, 0->don't, 2->all use same (def=0)");
 MODULE_PARM_DESC(virtual_gb, "virtual gigabyte (GiB) size (def=0 -> use dev_size_mb)");
@@ -7884,7 +7567,6 @@ static int __init scsi_debug_init(void)
 			return -EINVAL;
 		}
 	}
-
 	xa_init_flags(per_store_ap, XA_FLAGS_ALLOC | XA_FLAGS_LOCK_IRQ);
 	if (want_store) {
 		idx = sdebug_add_store();
@@ -8092,9 +7774,7 @@ static int sdebug_add_store(void)
 			map_region(sip, 0, 2);
 	}
 
-	rwlock_init(&sip->macc_data_lck);
-	rwlock_init(&sip->macc_meta_lck);
-	rwlock_init(&sip->macc_sector_lck);
+	rwlock_init(&sip->macc_lck);
 	return (int)n_idx;
 err:
 	sdebug_erase_store((int)n_idx, sip);
diff --git a/drivers/scsi/scsi_devinfo.c b/drivers/scsi/scsi_devinfo.c
index 90f1393a23f8..a7071e71389e 100644
--- a/drivers/scsi/scsi_devinfo.c
+++ b/drivers/scsi/scsi_devinfo.c
@@ -39,12 +39,13 @@ static LIST_HEAD(scsi_dev_info_list);
 static char scsi_dev_flags[256];
 
 /*
- * scsi_static_device_list: list of devices that require settings that differ
- * from the default, includes black-listed (broken) devices. The entries here
- * are added to the tail of scsi_dev_info_list via scsi_dev_info_list_init.
+ * scsi_static_device_list: deprecated list of devices that require
+ * settings that differ from the default, includes black-listed (broken)
+ * devices. The entries here are added to the tail of scsi_dev_info_list
+ * via scsi_dev_info_list_init.
  *
- * If possible, set the BLIST_* flags from inside a SCSI LLD rather than
- * adding an entry to this list.
+ * Do not add to this list, use the command line or proc interface to add
+ * to the scsi_dev_info_list. This table will eventually go away.
  */
 static struct {
 	char *vendor;
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 3958a6d14bf4..ec39acc986d6 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -631,7 +631,8 @@ static bool scsi_end_request(struct request *req, blk_status_t error,
 	if (blk_update_request(req, error, bytes))
 		return true;
 
-	if (q->limits.features & BLK_FEAT_ADD_RANDOM)
+	// XXX:
+	if (blk_queue_add_random(q))
 		add_disk_randomness(req->q->disk);
 
 	WARN_ON_ONCE(!blk_rq_is_passthrough(req) &&
@@ -1139,9 +1140,9 @@ blk_status_t scsi_alloc_sgtables(struct scsi_cmnd *cmd)
 	 */
 	count = __blk_rq_map_sg(rq->q, rq, cmd->sdb.table.sgl, &last_sg);
 
-	if (blk_rq_bytes(rq) & rq->q->limits.dma_pad_mask) {
+	if (blk_rq_bytes(rq) & rq->q->dma_pad_mask) {
 		unsigned int pad_len =
-			(rq->q->limits.dma_pad_mask & ~blk_rq_bytes(rq)) + 1;
+			(rq->q->dma_pad_mask & ~blk_rq_bytes(rq)) + 1;
 
 		last_sg->length += pad_len;
 		cmd->extra_len += pad_len;
@@ -1986,7 +1987,7 @@ void scsi_init_limits(struct Scsi_Host *shost, struct queue_limits *lim)
 		shost->dma_alignment, dma_get_cache_alignment() - 1);
 
 	if (shost->no_highmem)
-		lim->features |= BLK_FEAT_BOUNCE_HIGH;
+		lim->bounce = BLK_BOUNCE_HIGH;
 
 	dma_set_seg_boundary(dev, shost->dma_boundary);
 	dma_set_max_seg_size(dev, shost->max_segment_size);
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index c0b72199b4fa..8300fc28cb10 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -334,7 +334,7 @@ static struct scsi_device *scsi_alloc_sdev(struct scsi_target *starget,
 	sdev->sg_reserved_size = INT_MAX;
 
 	scsi_init_limits(shost, &lim);
-	q = blk_mq_alloc_queue(&sdev->host->tag_set, &lim, sdev);
+	q = blk_mq_alloc_queue(&sdev->host->tag_set, &lim, NULL);
 	if (IS_ERR(q)) {
 		/* release fn is set up in scsi_sysfs_device_initialise, so
 		 * have to free and put manually here */
@@ -344,6 +344,7 @@ static struct scsi_device *scsi_alloc_sdev(struct scsi_target *starget,
 	}
 	kref_get(&sdev->host->tagset_refcnt);
 	sdev->request_queue = q;
+	q->queuedata = sdev;
 
 	depth = sdev->host->cmd_per_lun ?: 1;
 
diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
index 32f94db6d6bf..b5aae4e8ae33 100644
--- a/drivers/scsi/scsi_sysfs.c
+++ b/drivers/scsi/scsi_sysfs.c
@@ -528,7 +528,7 @@ static struct class sdev_class = {
 };
 
 /* all probing is done in the individual ->probe routines */
-static int scsi_bus_match(struct device *dev, const struct device_driver *gendrv)
+static int scsi_bus_match(struct device *dev, struct device_driver *gendrv)
 {
 	struct scsi_device *sdp;
 
@@ -661,7 +661,7 @@ static int scsi_sdev_check_buf_bit(const char *buf)
 			return 1;
 		else if (buf[0] == '0')
 			return 0;
-		else
+		else 
 			return -EINVAL;
 	} else
 		return -EINVAL;
@@ -886,7 +886,7 @@ store_queue_type_field(struct device *dev, struct device_attribute *attr,
 
 	if (!sdev->tagged_supported)
 		return -EINVAL;
-
+		
 	sdev_printk(KERN_INFO, sdev,
 		    "ignoring write to deprecated queue_type attribute");
 	return count;
diff --git a/drivers/scsi/scsi_trace.c b/drivers/scsi/scsi_trace.c
index 3e47c4472a80..41a950075913 100644
--- a/drivers/scsi/scsi_trace.c
+++ b/drivers/scsi/scsi_trace.c
@@ -325,26 +325,6 @@ scsi_trace_zbc_out(struct trace_seq *p, unsigned char *cdb, int len)
 	return ret;
 }
 
-static const char *
-scsi_trace_atomic_write16_out(struct trace_seq *p, unsigned char *cdb, int len)
-{
-	const char *ret = trace_seq_buffer_ptr(p);
-	unsigned int boundary_size;
-	unsigned int nr_blocks;
-	sector_t lba;
-
-	lba = get_unaligned_be64(&cdb[2]);
-	boundary_size = get_unaligned_be16(&cdb[10]);
-	nr_blocks = get_unaligned_be16(&cdb[12]);
-
-	trace_seq_printf(p, "lba=%llu txlen=%u boundary_size=%u",
-			  lba, nr_blocks, boundary_size);
-
-	trace_seq_putc(p, 0);
-
-	return ret;
-}
-
 static const char *
 scsi_trace_varlen(struct trace_seq *p, unsigned char *cdb, int len)
 {
@@ -405,8 +385,6 @@ scsi_trace_parse_cdb(struct trace_seq *p, unsigned char *cdb, int len)
 		return scsi_trace_zbc_in(p, cdb, len);
 	case ZBC_OUT:
 		return scsi_trace_zbc_out(p, cdb, len);
-	case WRITE_ATOMIC_16:
-		return scsi_trace_atomic_write16_out(p, cdb, len);
 	default:
 		return scsi_trace_misc(p, cdb, len);
 	}
diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
index fde7de3b1e55..93e1978ad564 100644
--- a/drivers/scsi/scsi_transport_iscsi.c
+++ b/drivers/scsi/scsi_transport_iscsi.c
@@ -1204,7 +1204,7 @@ static const struct device_type iscsi_flashnode_conn_dev_type = {
 static const struct bus_type iscsi_flashnode_bus;
 
 int iscsi_flashnode_bus_match(struct device *dev,
-			      const struct device_driver *drv)
+				     struct device_driver *drv)
 {
 	if (dev->bus == &iscsi_flashnode_bus)
 		return 1;
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index adeaa8ab9951..1b7561abe05d 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -33,12 +33,11 @@
  *	than the level indicated above to trigger output.	
  */
 
-#include <linux/bio-integrity.h>
 #include <linux/module.h>
 #include <linux/fs.h>
 #include <linux/kernel.h>
 #include <linux/mm.h>
-#include <linux/bio-integrity.h>
+#include <linux/bio.h>
 #include <linux/hdreg.h>
 #include <linux/errno.h>
 #include <linux/idr.h>
@@ -103,13 +102,12 @@ MODULE_ALIAS_SCSI_DEVICE(TYPE_ZBC);
 
 #define SD_MINORS	16
 
-static void sd_config_discard(struct scsi_disk *sdkp, struct queue_limits *lim,
-		unsigned int mode);
-static void sd_config_write_same(struct scsi_disk *sdkp,
-		struct queue_limits *lim);
+static void sd_config_discard(struct scsi_disk *, unsigned int);
+static void sd_config_write_same(struct scsi_disk *);
 static int  sd_revalidate_disk(struct gendisk *);
 static void sd_unlock_native_capacity(struct gendisk *disk);
 static void sd_shutdown(struct device *);
+static void sd_read_capacity(struct scsi_disk *sdkp, unsigned char *buffer);
 static void scsi_disk_release(struct device *cdev);
 
 static DEFINE_IDA(sd_index_ida);
@@ -122,18 +120,17 @@ static const char *sd_cache_types[] = {
 	"write back, no read (daft)"
 };
 
-static void sd_set_flush_flag(struct scsi_disk *sdkp,
-		struct queue_limits *lim)
+static void sd_set_flush_flag(struct scsi_disk *sdkp)
 {
+	bool wc = false, fua = false;
+
 	if (sdkp->WCE) {
-		lim->features |= BLK_FEAT_WRITE_CACHE;
+		wc = true;
 		if (sdkp->DPOFUA)
-			lim->features |= BLK_FEAT_FUA;
-		else
-			lim->features &= ~BLK_FEAT_FUA;
-	} else {
-		lim->features &= ~(BLK_FEAT_WRITE_CACHE | BLK_FEAT_FUA);
+			fua = true;
 	}
+
+	blk_queue_write_cache(sdkp->disk->queue, wc, fua);
 }
 
 static ssize_t
@@ -171,18 +168,9 @@ cache_type_store(struct device *dev, struct device_attribute *attr,
 	wce = (ct & 0x02) && !sdkp->write_prot ? 1 : 0;
 
 	if (sdkp->cache_override) {
-		struct queue_limits lim;
-
 		sdkp->WCE = wce;
 		sdkp->RCD = rcd;
-
-		lim = queue_limits_start_update(sdkp->disk->queue);
-		sd_set_flush_flag(sdkp, &lim);
-		blk_mq_freeze_queue(sdkp->disk->queue);
-		ret = queue_limits_commit_update(sdkp->disk->queue, &lim);
-		blk_mq_unfreeze_queue(sdkp->disk->queue);
-		if (ret)
-			return ret;
+		sd_set_flush_flag(sdkp);
 		return count;
 	}
 
@@ -469,12 +457,16 @@ provisioning_mode_store(struct device *dev, struct device_attribute *attr,
 {
 	struct scsi_disk *sdkp = to_scsi_disk(dev);
 	struct scsi_device *sdp = sdkp->device;
-	struct queue_limits lim;
-	int mode, err;
+	int mode;
 
 	if (!capable(CAP_SYS_ADMIN))
 		return -EACCES;
 
+	if (sd_is_zoned(sdkp)) {
+		sd_config_discard(sdkp, SD_LBP_DISABLE);
+		return count;
+	}
+
 	if (sdp->type != TYPE_DISK)
 		return -EINVAL;
 
@@ -482,13 +474,8 @@ provisioning_mode_store(struct device *dev, struct device_attribute *attr,
 	if (mode < 0)
 		return -EINVAL;
 
-	lim = queue_limits_start_update(sdkp->disk->queue);
-	sd_config_discard(sdkp, &lim, mode);
-	blk_mq_freeze_queue(sdkp->disk->queue);
-	err = queue_limits_commit_update(sdkp->disk->queue, &lim);
-	blk_mq_unfreeze_queue(sdkp->disk->queue);
-	if (err)
-		return err;
+	sd_config_discard(sdkp, mode);
+
 	return count;
 }
 static DEVICE_ATTR_RW(provisioning_mode);
@@ -571,7 +558,6 @@ max_write_same_blocks_store(struct device *dev, struct device_attribute *attr,
 {
 	struct scsi_disk *sdkp = to_scsi_disk(dev);
 	struct scsi_device *sdp = sdkp->device;
-	struct queue_limits lim;
 	unsigned long max;
 	int err;
 
@@ -593,13 +579,8 @@ max_write_same_blocks_store(struct device *dev, struct device_attribute *attr,
 		sdkp->max_ws_blocks = max;
 	}
 
-	lim = queue_limits_start_update(sdkp->disk->queue);
-	sd_config_write_same(sdkp, &lim);
-	blk_mq_freeze_queue(sdkp->disk->queue);
-	err = queue_limits_commit_update(sdkp->disk->queue, &lim);
-	blk_mq_unfreeze_queue(sdkp->disk->queue);
-	if (err)
-		return err;
+	sd_config_write_same(sdkp);
+
 	return count;
 }
 static DEVICE_ATTR_RW(max_write_same_blocks);
@@ -842,28 +823,25 @@ static unsigned char sd_setup_protect_cmnd(struct scsi_cmnd *scmd,
 	return protect;
 }
 
-static void sd_disable_discard(struct scsi_disk *sdkp)
-{
-	sdkp->provisioning_mode = SD_LBP_DISABLE;
-	blk_queue_disable_discard(sdkp->disk->queue);
-}
-
-static void sd_config_discard(struct scsi_disk *sdkp, struct queue_limits *lim,
-		unsigned int mode)
+static void sd_config_discard(struct scsi_disk *sdkp, unsigned int mode)
 {
+	struct request_queue *q = sdkp->disk->queue;
 	unsigned int logical_block_size = sdkp->device->sector_size;
 	unsigned int max_blocks = 0;
 
-	lim->discard_alignment = sdkp->unmap_alignment * logical_block_size;
-	lim->discard_granularity = max(sdkp->physical_block_size,
-			sdkp->unmap_granularity * logical_block_size);
+	q->limits.discard_alignment =
+		sdkp->unmap_alignment * logical_block_size;
+	q->limits.discard_granularity =
+		max(sdkp->physical_block_size,
+		    sdkp->unmap_granularity * logical_block_size);
 	sdkp->provisioning_mode = mode;
 
 	switch (mode) {
 
 	case SD_LBP_FULL:
 	case SD_LBP_DISABLE:
-		break;
+		blk_queue_max_discard_sectors(q, 0);
+		return;
 
 	case SD_LBP_UNMAP:
 		max_blocks = min_not_zero(sdkp->max_unmap_blocks,
@@ -894,8 +872,7 @@ static void sd_config_discard(struct scsi_disk *sdkp, struct queue_limits *lim,
 		break;
 	}
 
-	lim->max_hw_discard_sectors = max_blocks *
-		(logical_block_size >> SECTOR_SHIFT);
+	blk_queue_max_discard_sectors(q, max_blocks * (logical_block_size >> 9));
 }
 
 static void *sd_set_special_bvec(struct request *rq, unsigned int data_len)
@@ -941,64 +918,6 @@ static blk_status_t sd_setup_unmap_cmnd(struct scsi_cmnd *cmd)
 	return scsi_alloc_sgtables(cmd);
 }
 
-static void sd_config_atomic(struct scsi_disk *sdkp, struct queue_limits *lim)
-{
-	unsigned int logical_block_size = sdkp->device->sector_size,
-		physical_block_size_sectors, max_atomic, unit_min, unit_max;
-
-	if ((!sdkp->max_atomic && !sdkp->max_atomic_with_boundary) ||
-	    sdkp->protection_type == T10_PI_TYPE2_PROTECTION)
-		return;
-
-	physical_block_size_sectors = sdkp->physical_block_size /
-					sdkp->device->sector_size;
-
-	unit_min = rounddown_pow_of_two(sdkp->atomic_granularity ?
-					sdkp->atomic_granularity :
-					physical_block_size_sectors);
-
-	/*
-	 * Only use atomic boundary when we have the odd scenario of
-	 * sdkp->max_atomic == 0, which the spec does permit.
-	 */
-	if (sdkp->max_atomic) {
-		max_atomic = sdkp->max_atomic;
-		unit_max = rounddown_pow_of_two(sdkp->max_atomic);
-		sdkp->use_atomic_write_boundary = 0;
-	} else {
-		max_atomic = sdkp->max_atomic_with_boundary;
-		unit_max = rounddown_pow_of_two(sdkp->max_atomic_boundary);
-		sdkp->use_atomic_write_boundary = 1;
-	}
-
-	/*
-	 * Ensure compliance with granularity and alignment. For now, keep it
-	 * simple and just don't support atomic writes for values mismatched
-	 * with max_{boundary}atomic, physical block size, and
-	 * atomic_granularity itself.
-	 *
-	 * We're really being distrustful by checking unit_max also...
-	 */
-	if (sdkp->atomic_granularity > 1) {
-		if (unit_min > 1 && unit_min % sdkp->atomic_granularity)
-			return;
-		if (unit_max > 1 && unit_max % sdkp->atomic_granularity)
-			return;
-	}
-
-	if (sdkp->atomic_alignment > 1) {
-		if (unit_min > 1 && unit_min % sdkp->atomic_alignment)
-			return;
-		if (unit_max > 1 && unit_max % sdkp->atomic_alignment)
-			return;
-	}
-
-	lim->atomic_write_hw_max = max_atomic * logical_block_size;
-	lim->atomic_write_hw_boundary = 0;
-	lim->atomic_write_hw_unit_min = unit_min * logical_block_size;
-	lim->atomic_write_hw_unit_max = unit_max * logical_block_size;
-}
-
 static blk_status_t sd_setup_write_same16_cmnd(struct scsi_cmnd *cmd,
 		bool unmap)
 {
@@ -1081,16 +1000,9 @@ static blk_status_t sd_setup_write_zeroes_cmnd(struct scsi_cmnd *cmd)
 	return sd_setup_write_same10_cmnd(cmd, false);
 }
 
-static void sd_disable_write_same(struct scsi_disk *sdkp)
-{
-	sdkp->device->no_write_same = 1;
-	sdkp->max_ws_blocks = 0;
-	blk_queue_disable_write_zeroes(sdkp->disk->queue);
-}
-
-static void sd_config_write_same(struct scsi_disk *sdkp,
-		struct queue_limits *lim)
+static void sd_config_write_same(struct scsi_disk *sdkp)
 {
+	struct request_queue *q = sdkp->disk->queue;
 	unsigned int logical_block_size = sdkp->device->sector_size;
 
 	if (sdkp->device->no_write_same) {
@@ -1144,8 +1056,8 @@ static void sd_config_write_same(struct scsi_disk *sdkp,
 	}
 
 out:
-	lim->max_write_zeroes_sectors =
-		sdkp->max_ws_blocks * (logical_block_size >> SECTOR_SHIFT);
+	blk_queue_max_write_zeroes_sectors(q, sdkp->max_ws_blocks *
+					 (logical_block_size >> 9));
 }
 
 static blk_status_t sd_setup_flush_cmnd(struct scsi_cmnd *cmd)
@@ -1297,26 +1209,6 @@ static int sd_cdl_dld(struct scsi_disk *sdkp, struct scsi_cmnd *scmd)
 	return (hint - IOPRIO_HINT_DEV_DURATION_LIMIT_1) + 1;
 }
 
-static blk_status_t sd_setup_atomic_cmnd(struct scsi_cmnd *cmd,
-					sector_t lba, unsigned int nr_blocks,
-					bool boundary, unsigned char flags)
-{
-	cmd->cmd_len  = 16;
-	cmd->cmnd[0]  = WRITE_ATOMIC_16;
-	cmd->cmnd[1]  = flags;
-	put_unaligned_be64(lba, &cmd->cmnd[2]);
-	put_unaligned_be16(nr_blocks, &cmd->cmnd[12]);
-	if (boundary)
-		put_unaligned_be16(nr_blocks, &cmd->cmnd[10]);
-	else
-		put_unaligned_be16(0, &cmd->cmnd[10]);
-	put_unaligned_be16(nr_blocks, &cmd->cmnd[12]);
-	cmd->cmnd[14] = 0;
-	cmd->cmnd[15] = 0;
-
-	return BLK_STS_OK;
-}
-
 static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *cmd)
 {
 	struct request *rq = scsi_cmd_to_rq(cmd);
@@ -1382,10 +1274,6 @@ static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *cmd)
 	if (protect && sdkp->protection_type == T10_PI_TYPE2_PROTECTION) {
 		ret = sd_setup_rw32_cmnd(cmd, write, lba, nr_blocks,
 					 protect | fua, dld);
-	} else if (rq->cmd_flags & REQ_ATOMIC && write) {
-		ret = sd_setup_atomic_cmnd(cmd, lba, nr_blocks,
-				sdkp->use_atomic_write_boundary,
-				protect | fua);
 	} else if (sdp->use_16_for_rw || (nr_blocks > 0xffff)) {
 		ret = sd_setup_rw16_cmnd(cmd, write, lba, nr_blocks,
 					 protect | fua, dld);
@@ -2359,14 +2247,15 @@ static int sd_done(struct scsi_cmnd *SCpnt)
 		case 0x24:	/* INVALID FIELD IN CDB */
 			switch (SCpnt->cmnd[0]) {
 			case UNMAP:
-				sd_disable_discard(sdkp);
+				sd_config_discard(sdkp, SD_LBP_DISABLE);
 				break;
 			case WRITE_SAME_16:
 			case WRITE_SAME:
 				if (SCpnt->cmnd[1] & 8) { /* UNMAP */
-					sd_disable_discard(sdkp);
+					sd_config_discard(sdkp, SD_LBP_DISABLE);
 				} else {
-					sd_disable_write_same(sdkp);
+					sdkp->device->no_write_same = 1;
+					sd_config_write_same(sdkp);
 					req->rq_flags |= RQF_QUIET;
 				}
 				break;
@@ -2378,7 +2267,7 @@ static int sd_done(struct scsi_cmnd *SCpnt)
 	}
 
  out:
-	if (sdkp->device->type == TYPE_ZBC)
+	if (sd_is_zoned(sdkp))
 		good_bytes = sd_zbc_complete(SCpnt, good_bytes, &sshdr);
 
 	SCSI_LOG_HLCOMPLETE(1, scmd_printk(KERN_INFO, SCpnt,
@@ -2572,13 +2461,11 @@ static int sd_read_protection_type(struct scsi_disk *sdkp, unsigned char *buffer
 	return 0;
 }
 
-static void sd_config_protection(struct scsi_disk *sdkp,
-		struct queue_limits *lim)
+static void sd_config_protection(struct scsi_disk *sdkp)
 {
 	struct scsi_device *sdp = sdkp->device;
 
-	if (IS_ENABLED(CONFIG_BLK_DEV_INTEGRITY))
-		sd_dif_config_host(sdkp, lim);
+	sd_dif_config_host(sdkp);
 
 	if (!sdkp->protection_type)
 		return;
@@ -2627,7 +2514,7 @@ static void read_capacity_error(struct scsi_disk *sdkp, struct scsi_device *sdp,
 #define READ_CAPACITY_RETRIES_ON_RESET	10
 
 static int read_capacity_16(struct scsi_disk *sdkp, struct scsi_device *sdp,
-		struct queue_limits *lim, unsigned char *buffer)
+						unsigned char *buffer)
 {
 	unsigned char cmd[16];
 	struct scsi_sense_hdr sshdr;
@@ -2701,7 +2588,7 @@ static int read_capacity_16(struct scsi_disk *sdkp, struct scsi_device *sdp,
 
 	/* Lowest aligned logical block */
 	alignment = ((buffer[14] & 0x3f) << 8 | buffer[15]) * sector_size;
-	lim->alignment_offset = alignment;
+	blk_queue_alignment_offset(sdp->request_queue, alignment);
 	if (alignment && sdkp->first_scan)
 		sd_printk(KERN_NOTICE, sdkp,
 			  "physical block alignment offset: %u\n", alignment);
@@ -2712,7 +2599,7 @@ static int read_capacity_16(struct scsi_disk *sdkp, struct scsi_device *sdp,
 		if (buffer[14] & 0x40) /* LBPRZ */
 			sdkp->lbprz = 1;
 
-		sd_config_discard(sdkp, lim, SD_LBP_WS16);
+		sd_config_discard(sdkp, SD_LBP_WS16);
 	}
 
 	sdkp->capacity = lba + 1;
@@ -2815,14 +2702,13 @@ static int sd_try_rc16_first(struct scsi_device *sdp)
  * read disk capacity
  */
 static void
-sd_read_capacity(struct scsi_disk *sdkp, struct queue_limits *lim,
-		unsigned char *buffer)
+sd_read_capacity(struct scsi_disk *sdkp, unsigned char *buffer)
 {
 	int sector_size;
 	struct scsi_device *sdp = sdkp->device;
 
 	if (sd_try_rc16_first(sdp)) {
-		sector_size = read_capacity_16(sdkp, sdp, lim, buffer);
+		sector_size = read_capacity_16(sdkp, sdp, buffer);
 		if (sector_size == -EOVERFLOW)
 			goto got_data;
 		if (sector_size == -ENODEV)
@@ -2842,7 +2728,7 @@ sd_read_capacity(struct scsi_disk *sdkp, struct queue_limits *lim,
 			int old_sector_size = sector_size;
 			sd_printk(KERN_NOTICE, sdkp, "Very big device. "
 					"Trying to use READ CAPACITY(16).\n");
-			sector_size = read_capacity_16(sdkp, sdp, lim, buffer);
+			sector_size = read_capacity_16(sdkp, sdp, buffer);
 			if (sector_size < 0) {
 				sd_printk(KERN_NOTICE, sdkp,
 					"Using 0xffffffff as device size\n");
@@ -2901,8 +2787,9 @@ sd_read_capacity(struct scsi_disk *sdkp, struct queue_limits *lim,
 		 */
 		sector_size = 512;
 	}
-	lim->logical_block_size = sector_size;
-	lim->physical_block_size = sdkp->physical_block_size;
+	blk_queue_logical_block_size(sdp->request_queue, sector_size);
+	blk_queue_physical_block_size(sdp->request_queue,
+				      sdkp->physical_block_size);
 	sdkp->device->sector_size = sector_size;
 
 	if (sdkp->capacity > 0xffffffff)
@@ -3308,30 +3195,11 @@ static void sd_read_app_tag_own(struct scsi_disk *sdkp, unsigned char *buffer)
 	return;
 }
 
-static unsigned int sd_discard_mode(struct scsi_disk *sdkp)
-{
-	if (!sdkp->lbpvpd) {
-		/* LBP VPD page not provided */
-		if (sdkp->max_unmap_blocks)
-			return SD_LBP_UNMAP;
-		return SD_LBP_WS16;
-	}
-
-	/* LBP VPD page tells us what to use */
-	if (sdkp->lbpu && sdkp->max_unmap_blocks)
-		return SD_LBP_UNMAP;
-	if (sdkp->lbpws)
-		return SD_LBP_WS16;
-	if (sdkp->lbpws10)
-		return SD_LBP_WS10;
-	return SD_LBP_DISABLE;
-}
-
-/*
- * Query disk device for preferred I/O sizes.
+/**
+ * sd_read_block_limits - Query disk device for preferred I/O sizes.
+ * @sdkp: disk to query
  */
-static void sd_read_block_limits(struct scsi_disk *sdkp,
-		struct queue_limits *lim)
+static void sd_read_block_limits(struct scsi_disk *sdkp)
 {
 	struct scsi_vpd *vpd;
 
@@ -3351,7 +3219,7 @@ static void sd_read_block_limits(struct scsi_disk *sdkp,
 		sdkp->max_ws_blocks = (u32)get_unaligned_be64(&vpd->data[36]);
 
 		if (!sdkp->lbpme)
-			goto config_atomic;
+			goto out;
 
 		lba_count = get_unaligned_be32(&vpd->data[20]);
 		desc_count = get_unaligned_be32(&vpd->data[24]);
@@ -3365,16 +3233,23 @@ static void sd_read_block_limits(struct scsi_disk *sdkp,
 			sdkp->unmap_alignment =
 				get_unaligned_be32(&vpd->data[32]) & ~(1 << 31);
 
-		sd_config_discard(sdkp, lim, sd_discard_mode(sdkp));
-
-config_atomic:
-		sdkp->max_atomic = get_unaligned_be32(&vpd->data[44]);
-		sdkp->atomic_alignment = get_unaligned_be32(&vpd->data[48]);
-		sdkp->atomic_granularity = get_unaligned_be32(&vpd->data[52]);
-		sdkp->max_atomic_with_boundary = get_unaligned_be32(&vpd->data[56]);
-		sdkp->max_atomic_boundary = get_unaligned_be32(&vpd->data[60]);
-
-		sd_config_atomic(sdkp, lim);
+		if (!sdkp->lbpvpd) { /* LBP VPD page not provided */
+
+			if (sdkp->max_unmap_blocks)
+				sd_config_discard(sdkp, SD_LBP_UNMAP);
+			else
+				sd_config_discard(sdkp, SD_LBP_WS16);
+
+		} else {	/* LBP VPD page tells us what to use */
+			if (sdkp->lbpu && sdkp->max_unmap_blocks)
+				sd_config_discard(sdkp, SD_LBP_UNMAP);
+			else if (sdkp->lbpws)
+				sd_config_discard(sdkp, SD_LBP_WS16);
+			else if (sdkp->lbpws10)
+				sd_config_discard(sdkp, SD_LBP_WS10);
+			else
+				sd_config_discard(sdkp, SD_LBP_DISABLE);
+		}
 	}
 
  out:
@@ -3393,10 +3268,13 @@ static void sd_read_block_limits_ext(struct scsi_disk *sdkp)
 	rcu_read_unlock();
 }
 
-/* Query block device characteristics */
-static void sd_read_block_characteristics(struct scsi_disk *sdkp,
-		struct queue_limits *lim)
+/**
+ * sd_read_block_characteristics - Query block dev. characteristics
+ * @sdkp: disk to query
+ */
+static void sd_read_block_characteristics(struct scsi_disk *sdkp)
 {
+	struct request_queue *q = sdkp->disk->queue;
 	struct scsi_vpd *vpd;
 	u16 rot;
 
@@ -3412,13 +3290,37 @@ static void sd_read_block_characteristics(struct scsi_disk *sdkp,
 	sdkp->zoned = (vpd->data[8] >> 4) & 3;
 	rcu_read_unlock();
 
-	if (rot == 1)
-		lim->features &= ~(BLK_FEAT_ROTATIONAL | BLK_FEAT_ADD_RANDOM);
+	if (rot == 1) {
+		blk_queue_flag_set(QUEUE_FLAG_NONROT, q);
+		blk_queue_flag_clear(QUEUE_FLAG_ADD_RANDOM, q);
+	}
+
+
+#ifdef CONFIG_BLK_DEV_ZONED /* sd_probe rejects ZBD devices early otherwise */
+	if (sdkp->device->type == TYPE_ZBC) {
+		/*
+		 * Host-managed.
+		 */
+		disk_set_zoned(sdkp->disk);
+
+		/*
+		 * Per ZBC and ZAC specifications, writes in sequential write
+		 * required zones of host-managed devices must be aligned to
+		 * the device physical block size.
+		 */
+		blk_queue_zone_write_granularity(q, sdkp->physical_block_size);
+	} else {
+		/*
+		 * Host-aware devices are treated as conventional.
+		 */
+		WARN_ON_ONCE(blk_queue_is_zoned(q));
+	}
+#endif /* CONFIG_BLK_DEV_ZONED */
 
 	if (!sdkp->first_scan)
 		return;
 
-	if (sdkp->device->type == TYPE_ZBC)
+	if (blk_queue_is_zoned(q))
 		sd_printk(KERN_NOTICE, sdkp, "Host-managed zoned block device\n");
 	else if (sdkp->zoned == 1)
 		sd_printk(KERN_NOTICE, sdkp, "Host-aware SMR disk used as regular disk\n");
@@ -3699,11 +3601,10 @@ static int sd_revalidate_disk(struct gendisk *disk)
 {
 	struct scsi_disk *sdkp = scsi_disk(disk);
 	struct scsi_device *sdp = sdkp->device;
+	struct request_queue *q = sdkp->disk->queue;
 	sector_t old_capacity = sdkp->capacity;
-	struct queue_limits lim;
 	unsigned char *buffer;
-	unsigned int dev_max;
-	int err;
+	unsigned int dev_max, rw_max;
 
 	SCSI_LOG_HLQUEUE(3, sd_printk(KERN_INFO, sdkp,
 				      "sd_revalidate_disk\n"));
@@ -3724,14 +3625,12 @@ static int sd_revalidate_disk(struct gendisk *disk)
 
 	sd_spinup_disk(sdkp);
 
-	lim = queue_limits_start_update(sdkp->disk->queue);
-
 	/*
 	 * Without media there is no reason to ask; moreover, some devices
 	 * react badly if we do.
 	 */
 	if (sdkp->media_present) {
-		sd_read_capacity(sdkp, &lim, buffer);
+		sd_read_capacity(sdkp, buffer);
 		/*
 		 * Some USB/UAS devices return generic values for mode pages
 		 * until the media has been accessed. Trigger a READ operation
@@ -3745,14 +3644,15 @@ static int sd_revalidate_disk(struct gendisk *disk)
 		 * cause this to be updated correctly and any device which
 		 * doesn't support it should be treated as rotational.
 		 */
-		lim.features |= (BLK_FEAT_ROTATIONAL | BLK_FEAT_ADD_RANDOM);
+		blk_queue_flag_clear(QUEUE_FLAG_NONROT, q);
+		blk_queue_flag_set(QUEUE_FLAG_ADD_RANDOM, q);
 
 		if (scsi_device_supports_vpd(sdp)) {
 			sd_read_block_provisioning(sdkp);
-			sd_read_block_limits(sdkp, &lim);
+			sd_read_block_limits(sdkp);
 			sd_read_block_limits_ext(sdkp);
-			sd_read_block_characteristics(sdkp, &lim);
-			sd_zbc_read_zones(sdkp, &lim, buffer);
+			sd_read_block_characteristics(sdkp);
+			sd_zbc_read_zones(sdkp, buffer);
 			sd_read_cpr(sdkp);
 		}
 
@@ -3764,50 +3664,64 @@ static int sd_revalidate_disk(struct gendisk *disk)
 		sd_read_app_tag_own(sdkp, buffer);
 		sd_read_write_same(sdkp, buffer);
 		sd_read_security(sdkp, buffer);
-		sd_config_protection(sdkp, &lim);
+		sd_config_protection(sdkp);
 	}
 
 	/*
 	 * We now have all cache related info, determine how we deal
 	 * with flush requests.
 	 */
-	sd_set_flush_flag(sdkp, &lim);
+	sd_set_flush_flag(sdkp);
 
 	/* Initial block count limit based on CDB TRANSFER LENGTH field size. */
 	dev_max = sdp->use_16_for_rw ? SD_MAX_XFER_BLOCKS : SD_DEF_XFER_BLOCKS;
 
 	/* Some devices report a maximum block count for READ/WRITE requests. */
 	dev_max = min_not_zero(dev_max, sdkp->max_xfer_blocks);
-	lim.max_dev_sectors = logical_to_sectors(sdp, dev_max);
+	q->limits.max_dev_sectors = logical_to_sectors(sdp, dev_max);
 
 	if (sd_validate_min_xfer_size(sdkp))
-		lim.io_min = logical_to_bytes(sdp, sdkp->min_xfer_blocks);
+		blk_queue_io_min(sdkp->disk->queue,
+				 logical_to_bytes(sdp, sdkp->min_xfer_blocks));
 	else
-		lim.io_min = 0;
+		blk_queue_io_min(sdkp->disk->queue, 0);
+
+	if (sd_validate_opt_xfer_size(sdkp, dev_max)) {
+		q->limits.io_opt = logical_to_bytes(sdp, sdkp->opt_xfer_blocks);
+		rw_max = logical_to_sectors(sdp, sdkp->opt_xfer_blocks);
+	} else {
+		q->limits.io_opt = 0;
+		rw_max = min_not_zero(logical_to_sectors(sdp, dev_max),
+				      (sector_t)BLK_DEF_MAX_SECTORS_CAP);
+	}
 
 	/*
 	 * Limit default to SCSI host optimal sector limit if set. There may be
 	 * an impact on performance for when the size of a request exceeds this
 	 * host limit.
 	 */
-	lim.io_opt = sdp->host->opt_sectors << SECTOR_SHIFT;
-	if (sd_validate_opt_xfer_size(sdkp, dev_max)) {
-		lim.io_opt = min_not_zero(lim.io_opt,
-				logical_to_bytes(sdp, sdkp->opt_xfer_blocks));
+	rw_max = min_not_zero(rw_max, sdp->host->opt_sectors);
+
+	/* Do not exceed controller limit */
+	rw_max = min(rw_max, queue_max_hw_sectors(q));
+
+	/*
+	 * Only update max_sectors if previously unset or if the current value
+	 * exceeds the capabilities of the hardware.
+	 */
+	if (sdkp->first_scan ||
+	    q->limits.max_sectors > q->limits.max_dev_sectors ||
+	    q->limits.max_sectors > q->limits.max_hw_sectors) {
+		q->limits.max_sectors = rw_max;
+		q->limits.max_user_sectors = rw_max;
 	}
 
 	sdkp->first_scan = 0;
 
 	set_capacity_and_notify(disk, logical_to_sectors(sdp, sdkp->capacity));
-	sd_config_write_same(sdkp, &lim);
+	sd_config_write_same(sdkp);
 	kfree(buffer);
 
-	blk_mq_freeze_queue(sdkp->disk->queue);
-	err = queue_limits_commit_update(sdkp->disk->queue, &lim);
-	blk_mq_unfreeze_queue(sdkp->disk->queue);
-	if (err)
-		return err;
-
 	/*
 	 * For a zoned drive, revalidating the zones can be done only once
 	 * the gendisk capacity is set. So if this fails, set back the gendisk
diff --git a/drivers/scsi/sd.h b/drivers/scsi/sd.h
index 36382eca941c..49dd600bfa48 100644
--- a/drivers/scsi/sd.h
+++ b/drivers/scsi/sd.h
@@ -115,13 +115,6 @@ struct scsi_disk {
 	u32		max_unmap_blocks;
 	u32		unmap_granularity;
 	u32		unmap_alignment;
-
-	u32		max_atomic;
-	u32		atomic_alignment;
-	u32		atomic_granularity;
-	u32		max_atomic_with_boundary;
-	u32		max_atomic_boundary;
-
 	u32		index;
 	unsigned int	physical_block_size;
 	unsigned int	max_medium_access_timeouts;
@@ -155,7 +148,6 @@ struct scsi_disk {
 	unsigned	security : 1;
 	unsigned	ignore_medium_access_errors : 1;
 	unsigned	rscs : 1; /* reduced stream control support */
-	unsigned	use_atomic_write_boundary : 1;
 };
 #define to_scsi_disk(obj) container_of(obj, struct scsi_disk, disk_dev)
 
@@ -228,12 +220,26 @@ static inline sector_t sectors_to_logical(struct scsi_device *sdev, sector_t sec
 	return sector >> (ilog2(sdev->sector_size) - 9);
 }
 
-void sd_dif_config_host(struct scsi_disk *sdkp, struct queue_limits *lim);
+#ifdef CONFIG_BLK_DEV_INTEGRITY
+
+extern void sd_dif_config_host(struct scsi_disk *);
+
+#else /* CONFIG_BLK_DEV_INTEGRITY */
+
+static inline void sd_dif_config_host(struct scsi_disk *disk)
+{
+}
+
+#endif /* CONFIG_BLK_DEV_INTEGRITY */
+
+static inline int sd_is_zoned(struct scsi_disk *sdkp)
+{
+	return sdkp->zoned == 1 || sdkp->device->type == TYPE_ZBC;
+}
 
 #ifdef CONFIG_BLK_DEV_ZONED
 
-int sd_zbc_read_zones(struct scsi_disk *sdkp, struct queue_limits *lim,
-		u8 buf[SD_BUF_SIZE]);
+int sd_zbc_read_zones(struct scsi_disk *sdkp, u8 buf[SD_BUF_SIZE]);
 int sd_zbc_revalidate_zones(struct scsi_disk *sdkp);
 blk_status_t sd_zbc_setup_zone_mgmt_cmnd(struct scsi_cmnd *cmd,
 					 unsigned char op, bool all);
@@ -244,8 +250,7 @@ int sd_zbc_report_zones(struct gendisk *disk, sector_t sector,
 
 #else /* CONFIG_BLK_DEV_ZONED */
 
-static inline int sd_zbc_read_zones(struct scsi_disk *sdkp,
-		struct queue_limits *lim, u8 buf[SD_BUF_SIZE])
+static inline int sd_zbc_read_zones(struct scsi_disk *sdkp, u8 buf[SD_BUF_SIZE])
 {
 	return 0;
 }
diff --git a/drivers/scsi/sd_dif.c b/drivers/scsi/sd_dif.c
index ae6ce6f5d622..1df847b5f747 100644
--- a/drivers/scsi/sd_dif.c
+++ b/drivers/scsi/sd_dif.c
@@ -24,15 +24,14 @@
 /*
  * Configure exchange of protection information between OS and HBA.
  */
-void sd_dif_config_host(struct scsi_disk *sdkp, struct queue_limits *lim)
+void sd_dif_config_host(struct scsi_disk *sdkp)
 {
 	struct scsi_device *sdp = sdkp->device;
+	struct gendisk *disk = sdkp->disk;
 	u8 type = sdkp->protection_type;
-	struct blk_integrity *bi = &lim->integrity;
+	struct blk_integrity bi;
 	int dif, dix;
 
-	memset(bi, 0, sizeof(*bi));
-
 	dif = scsi_host_dif_capable(sdp->host, type);
 	dix = scsi_host_dix_capable(sdp->host, type);
 
@@ -40,33 +39,45 @@ void sd_dif_config_host(struct scsi_disk *sdkp, struct queue_limits *lim)
 		dif = 0; dix = 1;
 	}
 
-	if (!dix)
+	if (!dix) {
+		blk_integrity_unregister(disk);
 		return;
+	}
+
+	memset(&bi, 0, sizeof(bi));
 
 	/* Enable DMA of protection information */
-	if (scsi_host_get_guard(sdkp->device->host) & SHOST_DIX_GUARD_IP)
-		bi->csum_type = BLK_INTEGRITY_CSUM_IP;
-	else
-		bi->csum_type = BLK_INTEGRITY_CSUM_CRC;
+	if (scsi_host_get_guard(sdkp->device->host) & SHOST_DIX_GUARD_IP) {
+		if (type == T10_PI_TYPE3_PROTECTION)
+			bi.profile = &t10_pi_type3_ip;
+		else
+			bi.profile = &t10_pi_type1_ip;
 
-	if (type != T10_PI_TYPE3_PROTECTION)
-		bi->flags |= BLK_INTEGRITY_REF_TAG;
+		bi.flags |= BLK_INTEGRITY_IP_CHECKSUM;
+	} else
+		if (type == T10_PI_TYPE3_PROTECTION)
+			bi.profile = &t10_pi_type3_crc;
+		else
+			bi.profile = &t10_pi_type1_crc;
 
-	bi->tuple_size = sizeof(struct t10_pi_tuple);
+	bi.tuple_size = sizeof(struct t10_pi_tuple);
 
 	if (dif && type) {
-		bi->flags |= BLK_INTEGRITY_DEVICE_CAPABLE;
+		bi.flags |= BLK_INTEGRITY_DEVICE_CAPABLE;
 
 		if (!sdkp->ATO)
-			return;
+			goto out;
 
 		if (type == T10_PI_TYPE3_PROTECTION)
-			bi->tag_size = sizeof(u16) + sizeof(u32);
+			bi.tag_size = sizeof(u16) + sizeof(u32);
 		else
-			bi->tag_size = sizeof(u16);
+			bi.tag_size = sizeof(u16);
 	}
 
 	sd_first_printk(KERN_NOTICE, sdkp,
 			"Enabling DIX %s, application tag size %u bytes\n",
-			blk_integrity_profile_name(bi), bi->tag_size);
+			bi.profile->name, bi.tag_size);
+out:
+	blk_integrity_register(disk, &bi);
 }
+
diff --git a/drivers/scsi/sd_zbc.c b/drivers/scsi/sd_zbc.c
index c8b9654d30f0..806036e48abe 100644
--- a/drivers/scsi/sd_zbc.c
+++ b/drivers/scsi/sd_zbc.c
@@ -232,7 +232,7 @@ int sd_zbc_report_zones(struct gendisk *disk, sector_t sector,
 	int zone_idx = 0;
 	int ret;
 
-	if (sdkp->device->type != TYPE_ZBC)
+	if (!sd_is_zoned(sdkp))
 		/* Not a zoned device */
 		return -EOPNOTSUPP;
 
@@ -300,7 +300,7 @@ static blk_status_t sd_zbc_cmnd_checks(struct scsi_cmnd *cmd)
 	struct scsi_disk *sdkp = scsi_disk(rq->q->disk);
 	sector_t sector = blk_rq_pos(rq);
 
-	if (sdkp->device->type != TYPE_ZBC)
+	if (!sd_is_zoned(sdkp))
 		/* Not a zoned device */
 		return BLK_STS_IOERR;
 
@@ -521,7 +521,7 @@ static int sd_zbc_check_capacity(struct scsi_disk *sdkp, unsigned char *buf,
 
 static void sd_zbc_print_zones(struct scsi_disk *sdkp)
 {
-	if (sdkp->device->type != TYPE_ZBC || !sdkp->capacity)
+	if (!sd_is_zoned(sdkp) || !sdkp->capacity)
 		return;
 
 	if (sdkp->capacity & (sdkp->zone_info.zone_blocks - 1))
@@ -565,6 +565,12 @@ int sd_zbc_revalidate_zones(struct scsi_disk *sdkp)
 	sdkp->zone_info.zone_blocks = zone_blocks;
 	sdkp->zone_info.nr_zones = nr_zones;
 
+	blk_queue_chunk_sectors(q,
+			logical_to_sectors(sdkp->device, zone_blocks));
+
+	/* Enable block layer zone append emulation */
+	blk_queue_max_zone_append_sectors(q, 0);
+
 	flags = memalloc_noio_save();
 	ret = blk_revalidate_disk_zones(disk);
 	memalloc_noio_restore(flags);
@@ -582,31 +588,27 @@ int sd_zbc_revalidate_zones(struct scsi_disk *sdkp)
 /**
  * sd_zbc_read_zones - Read zone information and update the request queue
  * @sdkp: SCSI disk pointer.
- * @lim: queue limits to read into
  * @buf: 512 byte buffer used for storing SCSI command output.
  *
  * Read zone information and update the request queue zone characteristics and
  * also the zoned device information in *sdkp. Called by sd_revalidate_disk()
  * before the gendisk capacity has been set.
  */
-int sd_zbc_read_zones(struct scsi_disk *sdkp, struct queue_limits *lim,
-		u8 buf[SD_BUF_SIZE])
+int sd_zbc_read_zones(struct scsi_disk *sdkp, u8 buf[SD_BUF_SIZE])
 {
+	struct gendisk *disk = sdkp->disk;
+	struct request_queue *q = disk->queue;
 	unsigned int nr_zones;
 	u32 zone_blocks = 0;
 	int ret;
 
-	if (sdkp->device->type != TYPE_ZBC)
+	if (!sd_is_zoned(sdkp)) {
+		/*
+		 * Device managed or normal SCSI disk, no special handling
+		 * required.
+		 */
 		return 0;
-
-	lim->features |= BLK_FEAT_ZONED;
-
-	/*
-	 * Per ZBC and ZAC specifications, writes in sequential write required
-	 * zones of host-managed devices must be aligned to the device physical
-	 * block size.
-	 */
-	lim->zone_write_granularity = sdkp->physical_block_size;
+	}
 
 	/* READ16/WRITE16/SYNC16 is mandatory for ZBC devices */
 	sdkp->device->use_16_for_rw = 1;
@@ -623,19 +625,17 @@ int sd_zbc_read_zones(struct scsi_disk *sdkp, struct queue_limits *lim,
 	if (ret != 0)
 		goto err;
 
-	nr_zones = round_up(sdkp->capacity, zone_blocks) >> ilog2(zone_blocks);
-	sdkp->early_zone_info.nr_zones = nr_zones;
-	sdkp->early_zone_info.zone_blocks = zone_blocks;
-
 	/* The drive satisfies the kernel restrictions: set it up */
+	blk_queue_flag_set(QUEUE_FLAG_ZONE_RESETALL, q);
 	if (sdkp->zones_max_open == U32_MAX)
-		lim->max_open_zones = 0;
+		disk_set_max_open_zones(disk, 0);
 	else
-		lim->max_open_zones = sdkp->zones_max_open;
-	lim->max_active_zones = 0;
-	lim->chunk_sectors = logical_to_sectors(sdkp->device, zone_blocks);
-	/* Enable block layer zone append emulation */
-	lim->max_zone_append_sectors = 0;
+		disk_set_max_open_zones(disk, sdkp->zones_max_open);
+	disk_set_max_active_zones(disk, 0);
+	nr_zones = round_up(sdkp->capacity, zone_blocks) >> ilog2(zone_blocks);
+
+	sdkp->early_zone_info.nr_zones = nr_zones;
+	sdkp->early_zone_info.zone_blocks = zone_blocks;
 
 	return 0;
 
diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c
index 3f491019103e..7ab000942b97 100644
--- a/drivers/scsi/sr.c
+++ b/drivers/scsi/sr.c
@@ -111,7 +111,7 @@ static struct lock_class_key sr_bio_compl_lkclass;
 static int sr_open(struct cdrom_device_info *, int);
 static void sr_release(struct cdrom_device_info *);
 
-static int get_sectorsize(struct scsi_cd *);
+static void get_sectorsize(struct scsi_cd *);
 static int get_capabilities(struct scsi_cd *);
 
 static unsigned int sr_check_events(struct cdrom_device_info *cdi,
@@ -473,15 +473,15 @@ static blk_status_t sr_init_command(struct scsi_cmnd *SCpnt)
 	return BLK_STS_IOERR;
 }
 
-static int sr_revalidate_disk(struct scsi_cd *cd)
+static void sr_revalidate_disk(struct scsi_cd *cd)
 {
 	struct scsi_sense_hdr sshdr;
 
 	/* if the unit is not ready, nothing more to do */
 	if (scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES, &sshdr))
-		return 0;
+		return;
 	sr_cd_check(&cd->cdi);
-	return get_sectorsize(cd);
+	get_sectorsize(cd);
 }
 
 static int sr_block_open(struct gendisk *disk, blk_mode_t mode)
@@ -494,16 +494,13 @@ static int sr_block_open(struct gendisk *disk, blk_mode_t mode)
 		return -ENXIO;
 
 	scsi_autopm_get_device(sdev);
-	if (disk_check_media_change(disk)) {
-		ret = sr_revalidate_disk(cd);
-		if (ret)
-			goto out;
-	}
+	if (disk_check_media_change(disk))
+		sr_revalidate_disk(cd);
 
 	mutex_lock(&cd->lock);
 	ret = cdrom_open(&cd->cdi, mode);
 	mutex_unlock(&cd->lock);
-out:
+
 	scsi_autopm_put_device(sdev);
 	if (ret)
 		scsi_device_put(cd->device);
@@ -688,9 +685,7 @@ static int sr_probe(struct device *dev)
 	blk_pm_runtime_init(sdev->request_queue, dev);
 
 	dev_set_drvdata(dev, cd);
-	error = sr_revalidate_disk(cd);
-	if (error)
-		goto unregister_cdrom;
+	sr_revalidate_disk(cd);
 
 	error = device_add_disk(&sdev->sdev_gendev, disk, NULL);
 	if (error)
@@ -719,14 +714,13 @@ static int sr_probe(struct device *dev)
 }
 
 
-static int get_sectorsize(struct scsi_cd *cd)
+static void get_sectorsize(struct scsi_cd *cd)
 {
-	struct request_queue *q = cd->device->request_queue;
 	static const u8 cmd[10] = { READ_CAPACITY };
 	unsigned char buffer[8] = { };
-	struct queue_limits lim;
-	int err;
+	int the_result;
 	int sector_size;
+	struct request_queue *queue;
 	struct scsi_failure failure_defs[] = {
 		{
 			.result = SCMD_FAILURE_RESULT_ANY,
@@ -742,10 +736,10 @@ static int get_sectorsize(struct scsi_cd *cd)
 	};
 
 	/* Do the command and wait.. */
-	err = scsi_execute_cmd(cd->device, cmd, REQ_OP_DRV_IN, buffer,
+	the_result = scsi_execute_cmd(cd->device, cmd, REQ_OP_DRV_IN, buffer,
 				      sizeof(buffer), SR_TIMEOUT, MAX_RETRIES,
 				      &exec_args);
-	if (err) {
+	if (the_result) {
 		cd->capacity = 0x1fffff;
 		sector_size = 2048;	/* A guess, just in case */
 	} else {
@@ -795,12 +789,10 @@ static int get_sectorsize(struct scsi_cd *cd)
 		set_capacity(cd->disk, cd->capacity);
 	}
 
-	lim = queue_limits_start_update(q);
-	lim.logical_block_size = sector_size;
-	blk_mq_freeze_queue(q);
-	err = queue_limits_commit_update(q, &lim);
-	blk_mq_unfreeze_queue(q);
-	return err;
+	queue = cd->device->request_queue;
+	blk_queue_logical_block_size(queue, sector_size);
+
+	return;
 }
 
 static int get_capabilities(struct scsi_cd *cd)
diff --git a/drivers/scsi/sun3_scsi.c b/drivers/scsi/sun3_scsi.c
index f51702893306..4a8cc2e8238e 100644
--- a/drivers/scsi/sun3_scsi.c
+++ b/drivers/scsi/sun3_scsi.c
@@ -666,5 +666,4 @@ static struct platform_driver sun3_scsi_driver = {
 module_platform_driver_probe(sun3_scsi_driver, sun3_scsi_probe);
 
 MODULE_ALIAS("platform:" DRV_MODULE_NAME);
-MODULE_DESCRIPTION("Sun3 NCR5380 SCSI controller driver");
 MODULE_LICENSE("GPL");
diff --git a/drivers/scsi/virtio_scsi.c b/drivers/scsi/virtio_scsi.c
index 8471f38b730e..89ca26945721 100644
--- a/drivers/scsi/virtio_scsi.c
+++ b/drivers/scsi/virtio_scsi.c
@@ -841,16 +841,19 @@ static int virtscsi_init(struct virtio_device *vdev,
 	int err;
 	u32 i;
 	u32 num_vqs, num_poll_vqs, num_req_vqs;
-	struct virtqueue_info *vqs_info;
+	vq_callback_t **callbacks;
+	const char **names;
 	struct virtqueue **vqs;
 	struct irq_affinity desc = { .pre_vectors = 2 };
 
 	num_req_vqs = vscsi->num_queues;
 	num_vqs = num_req_vqs + VIRTIO_SCSI_VQ_BASE;
 	vqs = kmalloc_array(num_vqs, sizeof(struct virtqueue *), GFP_KERNEL);
-	vqs_info = kcalloc(num_vqs, sizeof(*vqs_info), GFP_KERNEL);
+	callbacks = kmalloc_array(num_vqs, sizeof(vq_callback_t *),
+				  GFP_KERNEL);
+	names = kmalloc_array(num_vqs, sizeof(char *), GFP_KERNEL);
 
-	if (!vqs || !vqs_info) {
+	if (!callbacks || !vqs || !names) {
 		err = -ENOMEM;
 		goto out;
 	}
@@ -866,20 +869,22 @@ static int virtscsi_init(struct virtio_device *vdev,
 		 vscsi->io_queues[HCTX_TYPE_READ],
 		 vscsi->io_queues[HCTX_TYPE_POLL]);
 
-	vqs_info[0].callback = virtscsi_ctrl_done;
-	vqs_info[0].name = "control";
-	vqs_info[1].callback = virtscsi_event_done;
-	vqs_info[1].name = "event";
+	callbacks[0] = virtscsi_ctrl_done;
+	callbacks[1] = virtscsi_event_done;
+	names[0] = "control";
+	names[1] = "event";
 	for (i = VIRTIO_SCSI_VQ_BASE; i < num_vqs - num_poll_vqs; i++) {
-		vqs_info[i].callback = virtscsi_req_done;
-		vqs_info[i].name = "request";
+		callbacks[i] = virtscsi_req_done;
+		names[i] = "request";
 	}
 
-	for (; i < num_vqs; i++)
-		vqs_info[i].name = "request_poll";
+	for (; i < num_vqs; i++) {
+		callbacks[i] = NULL;
+		names[i] = "request_poll";
+	}
 
 	/* Discover virtqueues and write information to configuration.  */
-	err = virtio_find_vqs(vdev, num_vqs, vqs, vqs_info, &desc);
+	err = virtio_find_vqs(vdev, num_vqs, vqs, callbacks, names, &desc);
 	if (err)
 		goto out;
 
@@ -895,7 +900,8 @@ static int virtscsi_init(struct virtio_device *vdev,
 	err = 0;
 
 out:
-	kfree(vqs_info);
+	kfree(names);
+	kfree(callbacks);
 	kfree(vqs);
 	if (err)
 		virtscsi_remove_vqs(vdev);
-- 
2.39.2



More information about the Intel-gfx-trybot mailing list