diff mbox series

[v1,4/6] mpi3mr: WriteSame implementation

Message ID 20230724132303.19470-5-ranjan.kumar@broadcom.com (mailing list archive)
State Superseded
Headers show
Series mpi3mr: Few Enhancements and minor fixes | expand

Commit Message

Ranjan Kumar July 24, 2023, 1:23 p.m. UTC
The driver is enhanced to divert the writesame commands that
are issued with unmap=1 and NDOB=1 and with the transfer length
greater than the max writesame length specified by the firmware
for the particular drive to the firmware.

Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
---
 drivers/scsi/mpi3mr/mpi3mr.h    |  11 +++
 drivers/scsi/mpi3mr/mpi3mr_os.c | 118 +++++++++++++++++++++++++-------
 2 files changed, 105 insertions(+), 24 deletions(-)

Comments

Martin K. Petersen July 26, 2023, 1:24 a.m. UTC | #1
Hi Ranjan!

I am still unable to parse the indentation:

> @@ -4445,39 +4500,50 @@ static int mpi3mr_target_alloc(struct scsi_target *starget)
>  	starget->hostdata = scsi_tgt_priv_data;
>  
>  	spin_lock_irqsave(&mrioc->tgtdev_lock, flags);
> -
>  	if (starget->channel == mrioc->scsi_device_channel) {
>  		tgt_dev = __mpi3mr_get_tgtdev_by_perst_id(mrioc, starget->id);
> -		if (tgt_dev && !tgt_dev->is_hidden)
> -			update_stgt_priv_data = true;
> -		else
> +		if (tgt_dev && !tgt_dev->is_hidden) {

The block starts here                               ^

> +			scsi_tgt_priv_data->starget = starget;
> +			scsi_tgt_priv_data->dev_handle = tgt_dev->dev_handle;
> +			scsi_tgt_priv_data->perst_id = tgt_dev->perst_id;
> +			scsi_tgt_priv_data->dev_type = tgt_dev->dev_type;
> +			scsi_tgt_priv_data->tgt_dev = tgt_dev;
> +			tgt_dev->starget = starget;
> +			atomic_set(&scsi_tgt_priv_data->block_io, 0);
> +			retval = 0;
> +		if ((tgt_dev->dev_type == MPI3_DEVICE_DEVFORM_PCIE) &&
> +		    ((tgt_dev->dev_spec.pcie_inf.dev_info &
> +		    MPI3_DEVICE0_PCIE_DEVICE_INFO_TYPE_MASK) ==
> +		    MPI3_DEVICE0_PCIE_DEVICE_INFO_TYPE_NVME_DEVICE) &&
> +		    ((tgt_dev->dev_spec.pcie_inf.dev_info &
> +		    MPI3_DEVICE0_PCIE_DEVICE_INFO_PITYPE_MASK) !=
> +		    MPI3_DEVICE0_PCIE_DEVICE_INFO_PITYPE_0))
> +			scsi_tgt_priv_data->dev_nvme_dif = 1;
> +		scsi_tgt_priv_data->io_throttle_enabled = tgt_dev->io_throttle_enabled;
> +		scsi_tgt_priv_data->wslen = tgt_dev->wslen;
> +		if (tgt_dev->dev_type == MPI3_DEVICE_DEVFORM_VD)
> +			scsi_tgt_priv_data->throttle_group = tgt_dev->dev_spec.vd_inf.tg;
> +		} else

and ends here.  ^

So either everything after "retval = 0" is incorrectly indented or it
belongs in a different scope.
kernel test robot July 27, 2023, 5:06 p.m. UTC | #2
Hi Ranjan,

kernel test robot noticed the following build warnings:

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

url:    https://github.com/intel-lab-lkp/linux/commits/Ranjan-Kumar/mpi3mr-Invokes-soft-reset-upon-TSU-or-event-ack-time-out/20230724-212757
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git for-next
patch link:    https://lore.kernel.org/r/20230724132303.19470-5-ranjan.kumar%40broadcom.com
patch subject: [PATCH v1 4/6] mpi3mr: WriteSame implementation
config: x86_64-randconfig-m001-20230726 (https://download.01.org/0day-ci/archive/20230728/202307280034.DXU5pTVV-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce: (https://download.01.org/0day-ci/archive/20230728/202307280034.DXU5pTVV-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202307280034.DXU5pTVV-lkp@intel.com/

smatch warnings:
drivers/scsi/mpi3mr/mpi3mr_os.c:4514 mpi3mr_target_alloc() warn: inconsistent indenting

vim +4514 drivers/scsi/mpi3mr/mpi3mr_os.c

  4477	
  4478	/**
  4479	 * mpi3mr_target_alloc - Target alloc callback handler
  4480	 * @starget: SCSI target reference
  4481	 *
  4482	 * Allocate per target private data and initialize it.
  4483	 *
  4484	 * Return: 0 on success -ENOMEM on memory allocation failure.
  4485	 */
  4486	static int mpi3mr_target_alloc(struct scsi_target *starget)
  4487	{
  4488		struct Scsi_Host *shost = dev_to_shost(&starget->dev);
  4489		struct mpi3mr_ioc *mrioc = shost_priv(shost);
  4490		struct mpi3mr_stgt_priv_data *scsi_tgt_priv_data;
  4491		struct mpi3mr_tgt_dev *tgt_dev;
  4492		unsigned long flags;
  4493		int retval = 0;
  4494		struct sas_rphy *rphy = NULL;
  4495	
  4496		scsi_tgt_priv_data = kzalloc(sizeof(*scsi_tgt_priv_data), GFP_KERNEL);
  4497		if (!scsi_tgt_priv_data)
  4498			return -ENOMEM;
  4499	
  4500		starget->hostdata = scsi_tgt_priv_data;
  4501	
  4502		spin_lock_irqsave(&mrioc->tgtdev_lock, flags);
  4503		if (starget->channel == mrioc->scsi_device_channel) {
  4504			tgt_dev = __mpi3mr_get_tgtdev_by_perst_id(mrioc, starget->id);
  4505			if (tgt_dev && !tgt_dev->is_hidden) {
  4506				scsi_tgt_priv_data->starget = starget;
  4507				scsi_tgt_priv_data->dev_handle = tgt_dev->dev_handle;
  4508				scsi_tgt_priv_data->perst_id = tgt_dev->perst_id;
  4509				scsi_tgt_priv_data->dev_type = tgt_dev->dev_type;
  4510				scsi_tgt_priv_data->tgt_dev = tgt_dev;
  4511				tgt_dev->starget = starget;
  4512				atomic_set(&scsi_tgt_priv_data->block_io, 0);
  4513				retval = 0;
> 4514			if ((tgt_dev->dev_type == MPI3_DEVICE_DEVFORM_PCIE) &&
  4515			    ((tgt_dev->dev_spec.pcie_inf.dev_info &
  4516			    MPI3_DEVICE0_PCIE_DEVICE_INFO_TYPE_MASK) ==
  4517			    MPI3_DEVICE0_PCIE_DEVICE_INFO_TYPE_NVME_DEVICE) &&
  4518			    ((tgt_dev->dev_spec.pcie_inf.dev_info &
  4519			    MPI3_DEVICE0_PCIE_DEVICE_INFO_PITYPE_MASK) !=
  4520			    MPI3_DEVICE0_PCIE_DEVICE_INFO_PITYPE_0))
  4521				scsi_tgt_priv_data->dev_nvme_dif = 1;
  4522			scsi_tgt_priv_data->io_throttle_enabled = tgt_dev->io_throttle_enabled;
  4523			scsi_tgt_priv_data->wslen = tgt_dev->wslen;
  4524			if (tgt_dev->dev_type == MPI3_DEVICE_DEVFORM_VD)
  4525				scsi_tgt_priv_data->throttle_group = tgt_dev->dev_spec.vd_inf.tg;
  4526			} else
  4527				retval = -ENXIO;
  4528		} else if (mrioc->sas_transport_enabled && !starget->channel) {
  4529			rphy = dev_to_rphy(starget->dev.parent);
  4530			tgt_dev = __mpi3mr_get_tgtdev_by_addr_and_rphy(mrioc,
  4531			    rphy->identify.sas_address, rphy);
  4532			if (tgt_dev && !tgt_dev->is_hidden && !tgt_dev->non_stl &&
  4533			    (tgt_dev->dev_type == MPI3_DEVICE_DEVFORM_SAS_SATA)) {
  4534				scsi_tgt_priv_data->starget = starget;
  4535				scsi_tgt_priv_data->dev_handle = tgt_dev->dev_handle;
  4536				scsi_tgt_priv_data->perst_id = tgt_dev->perst_id;
  4537				scsi_tgt_priv_data->dev_type = tgt_dev->dev_type;
  4538				scsi_tgt_priv_data->tgt_dev = tgt_dev;
  4539				scsi_tgt_priv_data->io_throttle_enabled = tgt_dev->io_throttle_enabled;
  4540				scsi_tgt_priv_data->wslen = tgt_dev->wslen;
  4541				tgt_dev->starget = starget;
  4542				atomic_set(&scsi_tgt_priv_data->block_io, 0);
  4543				retval = 0;
  4544			} else
  4545				retval = -ENXIO;
  4546		}
  4547		spin_unlock_irqrestore(&mrioc->tgtdev_lock, flags);
  4548	
  4549		return retval;
  4550	}
  4551
diff mbox series

Patch

diff --git a/drivers/scsi/mpi3mr/mpi3mr.h b/drivers/scsi/mpi3mr/mpi3mr.h
index fd3619775739..8b009ba26d88 100644
--- a/drivers/scsi/mpi3mr/mpi3mr.h
+++ b/drivers/scsi/mpi3mr/mpi3mr.h
@@ -207,6 +207,9 @@  extern atomic64_t event_counter;
  */
 #define MPI3MR_MAX_APP_XFER_SECTORS	(2048 + 512)
 
+#define MPI3MR_WRITE_SAME_MAX_LEN_256_BLKS 256
+#define MPI3MR_WRITE_SAME_MAX_LEN_2048_BLKS 2048
+
 /**
  * struct mpi3mr_nvme_pt_sge -  Structure to store SGEs for NVMe
  * Encapsulated commands.
@@ -678,6 +681,7 @@  enum mpi3mr_dev_state {
  * @io_unit_port: IO Unit port ID
  * @non_stl: Is this device not to be attached with SAS TL
  * @io_throttle_enabled: I/O throttling needed or not
+ * @wslen: Write same max length
  * @q_depth: Device specific Queue Depth
  * @wwid: World wide ID
  * @enclosure_logical_id: Enclosure logical identifier
@@ -700,6 +704,7 @@  struct mpi3mr_tgt_dev {
 	u8 io_unit_port;
 	u8 non_stl;
 	u8 io_throttle_enabled;
+	u16 wslen;
 	u16 q_depth;
 	u64 wwid;
 	u64 enclosure_logical_id;
@@ -753,6 +758,8 @@  static inline void mpi3mr_tgtdev_put(struct mpi3mr_tgt_dev *s)
  * @dev_removed: Device removed in the Firmware
  * @dev_removedelay: Device is waiting to be removed in FW
  * @dev_type: Device type
+ * @dev_nvme_dif: Device is NVMe DIF enabled
+ * @wslen: Write same max length
  * @io_throttle_enabled: I/O throttling needed or not
  * @io_divert: Flag indicates io divert is on or off for the dev
  * @throttle_group: Pointer to throttle group info
@@ -769,6 +776,8 @@  struct mpi3mr_stgt_priv_data {
 	u8 dev_removed;
 	u8 dev_removedelay;
 	u8 dev_type;
+	u8 dev_nvme_dif;
+	u16 wslen;
 	u8 io_throttle_enabled;
 	u8 io_divert;
 	struct mpi3mr_throttle_group_info *throttle_group;
@@ -784,12 +793,14 @@  struct mpi3mr_stgt_priv_data {
  * @ncq_prio_enable: NCQ priority enable for SATA device
  * @pend_count: Counter to track pending I/Os during error
  *		handling
+ * @wslen: Write same max length
  */
 struct mpi3mr_sdev_priv_data {
 	struct mpi3mr_stgt_priv_data *tgt_priv_data;
 	u32 lun_id;
 	u8 ncq_prio_enable;
 	u32 pend_count;
+	u16 wslen;
 };
 
 /**
diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c
index b19b624d0e97..080c1a958905 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_os.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_os.c
@@ -430,6 +430,7 @@  void mpi3mr_invalidate_devhandles(struct mpi3mr_ioc *mrioc)
 			tgt_priv->io_throttle_enabled = 0;
 			tgt_priv->io_divert = 0;
 			tgt_priv->throttle_group = NULL;
+			tgt_priv->wslen = 0;
 			if (tgtdev->host_exposed)
 				atomic_set(&tgt_priv->block_io, 1);
 		}
@@ -1108,6 +1109,18 @@  static void mpi3mr_update_tgtdev(struct mpi3mr_ioc *mrioc,
 		tgtdev->io_throttle_enabled =
 		    (flags & MPI3_DEVICE0_FLAGS_IO_THROTTLING_REQUIRED) ? 1 : 0;
 
+	switch (flags & MPI3_DEVICE0_FLAGS_MAX_WRITE_SAME_MASK) {
+	case MPI3_DEVICE0_FLAGS_MAX_WRITE_SAME_256_LB:
+		tgtdev->wslen = MPI3MR_WRITE_SAME_MAX_LEN_256_BLKS;
+		break;
+	case MPI3_DEVICE0_FLAGS_MAX_WRITE_SAME_2048_LB:
+		tgtdev->wslen = MPI3MR_WRITE_SAME_MAX_LEN_2048_BLKS;
+		break;
+	case MPI3_DEVICE0_FLAGS_MAX_WRITE_SAME_NO_LIMIT:
+	default:
+		tgtdev->wslen = 0;
+		break;
+	}
 
 	if (tgtdev->starget && tgtdev->starget->hostdata) {
 		scsi_tgt_priv_data = (struct mpi3mr_stgt_priv_data *)
@@ -1119,6 +1132,7 @@  static void mpi3mr_update_tgtdev(struct mpi3mr_ioc *mrioc,
 		    tgtdev->io_throttle_enabled;
 		if (is_added == true)
 			atomic_set(&scsi_tgt_priv_data->block_io, 0);
+		scsi_tgt_priv_data->wslen = tgtdev->wslen;
 	}
 
 	switch (dev_pg0->access_status) {
@@ -3939,6 +3953,48 @@  void mpi3mr_wait_for_host_io(struct mpi3mr_ioc *mrioc, u32 timeout)
 	    mpi3mr_get_fw_pending_ios(mrioc));
 }
 
+/**
+ * mpi3mr_setup_divert_ws - Setup Divert IO flag for write same
+ * @mrioc: Adapter instance reference
+ * @scmd: SCSI command reference
+ * @scsiio_req: MPI3 SCSI IO request
+ * @scsiio_flags: Pointer to MPI3 SCSI IO Flags
+ * @wslen: write same max length
+ *
+ * Gets values of unmap, ndob and number of blocks from write
+ * same scsi io and based on these values it sets divert IO flag
+ * and reason for diverting IO to firmware.
+ *
+ * Return: Nothing
+ */
+static inline void mpi3mr_setup_divert_ws(struct mpi3mr_ioc *mrioc,
+	struct scsi_cmnd *scmd, struct mpi3_scsi_io_request *scsiio_req,
+	u32 *scsiio_flags, u16 wslen)
+{
+	u8 unmap = 0, ndob = 0;
+	u8 opcode = scmd->cmnd[0];
+	u32 num_blocks = 0;
+	u16 sa = (scmd->cmnd[8] << 8) | (scmd->cmnd[9]);
+
+	if (opcode == WRITE_SAME_16) {
+		unmap = scmd->cmnd[1] & 0x08;
+		ndob = scmd->cmnd[1] & 0x01;
+		num_blocks = get_unaligned_be32(scmd->cmnd + 10);
+	} else if ((opcode == VARIABLE_LENGTH_CMD) && (sa == WRITE_SAME_32)) {
+		unmap = scmd->cmnd[10] & 0x08;
+		ndob = scmd->cmnd[10] & 0x01;
+		num_blocks = get_unaligned_be32(scmd->cmnd + 28);
+	} else
+		return;
+
+	if ((unmap) && (ndob) && (num_blocks > wslen)) {
+		scsiio_req->msg_flags |=
+		    MPI3_SCSIIO_MSGFLAGS_DIVERT_TO_FIRMWARE;
+		*scsiio_flags |=
+			MPI3_SCSIIO_FLAGS_DIVERT_REASON_WRITE_SAME_TOO_LARGE;
+	}
+}
+
 /**
  * mpi3mr_eh_host_reset - Host reset error handling callback
  * @scmd: SCSI command reference
@@ -4436,7 +4492,6 @@  static int mpi3mr_target_alloc(struct scsi_target *starget)
 	unsigned long flags;
 	int retval = 0;
 	struct sas_rphy *rphy = NULL;
-	bool update_stgt_priv_data = false;
 
 	scsi_tgt_priv_data = kzalloc(sizeof(*scsi_tgt_priv_data), GFP_KERNEL);
 	if (!scsi_tgt_priv_data)
@@ -4445,39 +4500,50 @@  static int mpi3mr_target_alloc(struct scsi_target *starget)
 	starget->hostdata = scsi_tgt_priv_data;
 
 	spin_lock_irqsave(&mrioc->tgtdev_lock, flags);
-
 	if (starget->channel == mrioc->scsi_device_channel) {
 		tgt_dev = __mpi3mr_get_tgtdev_by_perst_id(mrioc, starget->id);
-		if (tgt_dev && !tgt_dev->is_hidden)
-			update_stgt_priv_data = true;
-		else
+		if (tgt_dev && !tgt_dev->is_hidden) {
+			scsi_tgt_priv_data->starget = starget;
+			scsi_tgt_priv_data->dev_handle = tgt_dev->dev_handle;
+			scsi_tgt_priv_data->perst_id = tgt_dev->perst_id;
+			scsi_tgt_priv_data->dev_type = tgt_dev->dev_type;
+			scsi_tgt_priv_data->tgt_dev = tgt_dev;
+			tgt_dev->starget = starget;
+			atomic_set(&scsi_tgt_priv_data->block_io, 0);
+			retval = 0;
+		if ((tgt_dev->dev_type == MPI3_DEVICE_DEVFORM_PCIE) &&
+		    ((tgt_dev->dev_spec.pcie_inf.dev_info &
+		    MPI3_DEVICE0_PCIE_DEVICE_INFO_TYPE_MASK) ==
+		    MPI3_DEVICE0_PCIE_DEVICE_INFO_TYPE_NVME_DEVICE) &&
+		    ((tgt_dev->dev_spec.pcie_inf.dev_info &
+		    MPI3_DEVICE0_PCIE_DEVICE_INFO_PITYPE_MASK) !=
+		    MPI3_DEVICE0_PCIE_DEVICE_INFO_PITYPE_0))
+			scsi_tgt_priv_data->dev_nvme_dif = 1;
+		scsi_tgt_priv_data->io_throttle_enabled = tgt_dev->io_throttle_enabled;
+		scsi_tgt_priv_data->wslen = tgt_dev->wslen;
+		if (tgt_dev->dev_type == MPI3_DEVICE_DEVFORM_VD)
+			scsi_tgt_priv_data->throttle_group = tgt_dev->dev_spec.vd_inf.tg;
+		} else
 			retval = -ENXIO;
 	} else if (mrioc->sas_transport_enabled && !starget->channel) {
 		rphy = dev_to_rphy(starget->dev.parent);
 		tgt_dev = __mpi3mr_get_tgtdev_by_addr_and_rphy(mrioc,
 		    rphy->identify.sas_address, rphy);
 		if (tgt_dev && !tgt_dev->is_hidden && !tgt_dev->non_stl &&
-		    (tgt_dev->dev_type == MPI3_DEVICE_DEVFORM_SAS_SATA))
-			update_stgt_priv_data = true;
-		else
+		    (tgt_dev->dev_type == MPI3_DEVICE_DEVFORM_SAS_SATA)) {
+			scsi_tgt_priv_data->starget = starget;
+			scsi_tgt_priv_data->dev_handle = tgt_dev->dev_handle;
+			scsi_tgt_priv_data->perst_id = tgt_dev->perst_id;
+			scsi_tgt_priv_data->dev_type = tgt_dev->dev_type;
+			scsi_tgt_priv_data->tgt_dev = tgt_dev;
+			scsi_tgt_priv_data->io_throttle_enabled = tgt_dev->io_throttle_enabled;
+			scsi_tgt_priv_data->wslen = tgt_dev->wslen;
+			tgt_dev->starget = starget;
+			atomic_set(&scsi_tgt_priv_data->block_io, 0);
+			retval = 0;
+		} else
 			retval = -ENXIO;
 	}
-
-	if (update_stgt_priv_data) {
-		scsi_tgt_priv_data->starget = starget;
-		scsi_tgt_priv_data->dev_handle = tgt_dev->dev_handle;
-		scsi_tgt_priv_data->perst_id = tgt_dev->perst_id;
-		scsi_tgt_priv_data->dev_type = tgt_dev->dev_type;
-		scsi_tgt_priv_data->tgt_dev = tgt_dev;
-		tgt_dev->starget = starget;
-		atomic_set(&scsi_tgt_priv_data->block_io, 0);
-		retval = 0;
-		scsi_tgt_priv_data->io_throttle_enabled =
-		    tgt_dev->io_throttle_enabled;
-		if (tgt_dev->dev_type == MPI3_DEVICE_DEVFORM_VD)
-			scsi_tgt_priv_data->throttle_group =
-			    tgt_dev->dev_spec.vd_inf.tg;
-	}
 	spin_unlock_irqrestore(&mrioc->tgtdev_lock, flags);
 
 	return retval;
@@ -4738,6 +4804,10 @@  static int mpi3mr_qcmd(struct Scsi_Host *shost,
 
 	mpi3mr_setup_eedp(mrioc, scmd, scsiio_req);
 
+	if (stgt_priv_data->wslen)
+		mpi3mr_setup_divert_ws(mrioc, scmd, scsiio_req, &scsiio_flags,
+		    stgt_priv_data->wslen);
+
 	memcpy(scsiio_req->cdb.cdb32, scmd->cmnd, scmd->cmd_len);
 	scsiio_req->data_length = cpu_to_le32(scsi_bufflen(scmd));
 	scsiio_req->dev_handle = cpu_to_le16(dev_handle);