Skip to contentSkip to conversation

Subject: Protection information and block size cleanup

PATCH Applied Martin K. Petersen 5 participants 39 messages Jun 9, 2021 – Jul 24, 2021

Subsystems (10)
lore
Share & tools
lore
#0 lore raw

cover Subject: Protection information and block size cleanup

This series cleans up how low-level device drivers go about handling protection information. The SCSI midlayer provides a set of flags and helpers but not all drivers currently use them. This series updates the drivers to use the proper calls to query things like the protection interval, reference tag seed value, etc.

In addition scsi_debug is enhanced to validate and store protection information the same way as a regular PI-capable disk drive or SSD. With these changes scsi_debug is now able to pass the same PI qualification tests as physical hardware.

And finally: Bart's recent series [1] attempted to clean up some of the confusion between logical block addresses and block layer sector addresses. Part of Bart's work is included in this series as well as some fixes to the remainder of the scsi_get_lba() call sites. Sometimes it is appropriate use sectors, in other cases logical blocks are a better choice. For instance when printing something with a reference tag given that the latter typically contains the lower 32 bits of the LBA.

The changes done in this series are also meant to facilitate removing the request pointer from struct scsi_cmnd [2]. By removing several references to struct request in the various drivers that transition will now be easier.

[1] https://lore.kernel.org/linux-scsi/[email protected]/
[2] https://lore.kernel.org/linux-scsi/[email protected]/

--
Martin K. Petersen Oracle Linux Engineering

Bart Van Assche (2):
scsi: core: Introduce scsi_get_sector()
scsi: iser: Use scsi_get_sector() instead of scsi_get_lba()

Martin K. Petersen (13):
scsi: core: Add scsi_prot_ref_tag() helper
scsi: lpfc: Use the proper SCSI midlayer interfaces for PI
scsi: qla2xxx: Use the proper SCSI midlayer interfaces for PI
scsi: mpt3sas: Use the proper SCSI midlayer interfaces for PI
scsi: mpi3mr: Use the proper SCSI midlayer interfaces for PI
scsi: zfcp: Use the proper SCSI midlayer interfaces for PI
scsi: isci: Use the proper SCSI midlayer interfaces for PI
scsi: scsi_debug: Remove dump_sector()
scsi: scsi_debug: Improve RDPROTECT/WRPROTECT handling
scsi: core: Make scsi_get_lba() return the LBA
scsi: core: Add helper to return number of logical blocks in a request
scsi: lpfc: Switch to scsi_get_block_count()
scsi: ufs: core: Use scsi_get_lba() to get LBA

 drivers/infiniband/ulp/iser/iser_verbs.c |   2 +-
 drivers/s390/scsi/zfcp_fsf.c             |   4 +-
 drivers/scsi/isci/request.c              |   4 +-
 drivers/scsi/lpfc/lpfc_scsi.c            | 116 +++++++++--------------
 drivers/scsi/mpi3mr/mpi3mr_os.c          |  59 ++++--------
 drivers/scsi/mpt3sas/mpt3sas_scsih.c     |  28 ++----
 drivers/scsi/qla2xxx/qla_iocb.c          |  84 +++-------------
 drivers/scsi/scsi_debug.c                | 112 +++++++++++++---------
 drivers/scsi/ufs/ufshcd.c                |   3 +-
 include/scsi/scsi_cmnd.h                 |  25 ++++-
 10 files changed, 182 insertions(+), 255 deletions(-)
Signature · 1 line
2.31.1
#1 lore raw

PATCH 1/15 scsi: core: Add scsi_prot_ref_tag() helper

We are about to remove the request pointer from struct scsi_cmnd and that will complicate getting to the ref_tag via t10_pi_ref_tag() in the various drivers. Introduce a helper function to retrieve the reference tag so drivers will not have to worry about the details.

---
 include/scsi/scsi_cmnd.h | 7 +++++++
 1 file changed, 7 insertions(+)
include/scsi/scsi_cmnd.h +7 -0
index 779a59fe8676..301b9cd4ddd0 100644
@@ -287,6 +287,13 @@ static inline sector_t scsi_get_lba(struct scsi_cmnd *scmd)
 	return blk_rq_pos(scmd->request);
 }
 
+static inline u32 scsi_prot_ref_tag(struct scsi_cmnd *scmd)
+{
+	struct request *rq = blk_mq_rq_from_pdu(scmd);
+
+	return t10_pi_ref_tag(rq);
+}
+
 static inline unsigned int scsi_prot_interval(struct scsi_cmnd *scmd)
 {
 	return scmd->device->sector_size;
Signature · 1 line
2.31.1
Reviewed-by on v1 1/15
#2 lore raw

Re: [PATCH 01/15] scsi: core: Add scsi_prot_ref_tag() helper

Quoted 18 lines · Martin K. Petersen

We are about to remove the request pointer from struct scsi_cmnd and that will complicate getting to the ref_tag via t10_pi_ref_tag() in the various drivers. Introduce a helper function to retrieve the reference tag so drivers will not have to worry about the details.

---
 include/scsi/scsi_cmnd.h | 7 +++++++
 1 file changed, 7 insertions(+)
include/scsi/scsi_cmnd.h +0 -0
index 779a59fe8676..301b9cd4ddd0 100644
@@ -287,6 +287,13 @@ static inline sector_t scsi_get_lba(struct scsi_cmnd *scmd)
 	return blk_rq_pos(scmd->request);
 }
 

include/scsi/scsi_cmnd.h static inline sector_t scsi_get_lba(struct scsi_cmnd *scmd) · line 299

Quoted 10 lines
include/scsi/scsi_cmnd.h +7 -0
+static inline u32 scsi_prot_ref_tag(struct scsi_cmnd *scmd)
+{
+	struct request *rq = blk_mq_rq_from_pdu(scmd);
+
+	return t10_pi_ref_tag(rq);
+}
+
 static inline unsigned int scsi_prot_interval(struct scsi_cmnd *scmd)
 {
 	return scmd->device->sector_size;
Reviewed-by on v1 1/15
#3 lore raw

Re: [PATCH 01/15] scsi: core: Add scsi_prot_ref_tag() helper

In reply to Martin K. Petersen
Quoted 18 lines · Martin K. Petersen

We are about to remove the request pointer from struct scsi_cmnd and that will complicate getting to the ref_tag via t10_pi_ref_tag() in the various drivers. Introduce a helper function to retrieve the reference tag so drivers will not have to worry about the details.

---
 include/scsi/scsi_cmnd.h | 7 +++++++
 1 file changed, 7 insertions(+)
include/scsi/scsi_cmnd.h +0 -0
index 779a59fe8676..301b9cd4ddd0 100644
@@ -287,6 +287,13 @@ static inline sector_t scsi_get_lba(struct scsi_cmnd *scmd)
 	return blk_rq_pos(scmd->request);
 }
 

include/scsi/scsi_cmnd.h static inline sector_t scsi_get_lba(struct scsi_cmnd *scmd) · line 299

Quoted 10 lines
include/scsi/scsi_cmnd.h +7 -0
+static inline u32 scsi_prot_ref_tag(struct scsi_cmnd *scmd)
+{
+	struct request *rq = blk_mq_rq_from_pdu(scmd);
+
+	return t10_pi_ref_tag(rq);
+}
+
 static inline unsigned int scsi_prot_interval(struct scsi_cmnd *scmd)
 {
 	return scmd->device->sector_size;
Signature · 4 lines
Best Regards, Benjamin Block  / Linux on IBM Z Kernel Development / IBM Systems
IBM Deutschland Research & Development GmbH    /    https://www.ibm.com/privacy
Vorsitz. AufsR.: Gregor Pillen         /        Geschäftsführung: Dirk Wittkopp
Sitz der Gesellschaft: Böblingen / Registergericht: AmtsG Stuttgart, HRB 243294
#4 lore raw

PATCH 2/15 scsi: lpfc: Use the proper SCSI midlayer interfaces for PI

In reply to Martin K. Petersen

Use the SCSI midlayer interfaces to query protection interval, reference tag, and per-command DIX flags.

---
 drivers/scsi/lpfc/lpfc_scsi.c | 92 +++++++++++++----------------------
 1 file changed, 34 insertions(+), 58 deletions(-)
drivers/scsi/lpfc/lpfc_scsi.c +34 -58
index 503919b10a6d..ca2e00e512f4 100644
@@ -87,30 +87,6 @@ lpfc_release_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_io_buf *psb);
 static int
 lpfc_prot_group_type(struct lpfc_hba *phba, struct scsi_cmnd *sc);
 
-static inline unsigned
-lpfc_cmd_blksize(struct scsi_cmnd *sc)
-{
-	return sc->device->sector_size;
-}
-
-#define LPFC_CHECK_PROTECT_GUARD	1
-#define LPFC_CHECK_PROTECT_REF		2
-static inline unsigned
-lpfc_cmd_protect(struct scsi_cmnd *sc, int flag)
-{
-	return 1;
-}
-
-static inline unsigned
-lpfc_cmd_guard_csum(struct scsi_cmnd *sc)
-{
-	if (lpfc_prot_group_type(NULL, sc) == LPFC_PG_TYPE_NO_DIF)
-		return 0;
-	if (scsi_host_get_guard(sc->device->host) == SHOST_DIX_GUARD_IP)
-		return 1;
-	return 0;
-}
-
 /**
  * lpfc_sli4_set_rsp_sgl_last - Set the last bit in the response sge.
  * @phba: Pointer to HBA object.
@@ -1037,13 +1013,13 @@ lpfc_bg_err_inject(struct lpfc_hba *phba, struct scsi_cmnd *sc,
 		return 0;
 
 	sgpe = scsi_prot_sglist(sc);
-	lba = t10_pi_ref_tag(sc->request);
+	lba = scsi_prot_ref_tag(sc);
 	if (lba == LPFC_INVALID_REFTAG)
 		return 0;
 
 	/* First check if we need to match the LBA */
 	if (phba->lpfc_injerr_lba != LPFC_INJERR_LBA_OFF) {
-		blksize = lpfc_cmd_blksize(sc);
+		blksize = scsi_prot_interval(sc);
 		numblks = (scsi_bufflen(sc) + blksize - 1) / blksize;
 
 		/* Make sure we have the right LBA if one is specified */
@@ -1432,7 +1408,7 @@ lpfc_sc_to_bg_opcodes(struct lpfc_hba *phba, struct scsi_cmnd *sc,
 {
 	uint8_t ret = 0;
 
-	if (lpfc_cmd_guard_csum(sc)) {
+	if (sc->prot_flags & SCSI_PROT_IP_CHECKSUM) {
 		switch (scsi_get_prot_op(sc)) {
 		case SCSI_PROT_READ_INSERT:
 		case SCSI_PROT_WRITE_STRIP:
@@ -1512,7 +1488,7 @@ lpfc_bg_err_opcodes(struct lpfc_hba *phba, struct scsi_cmnd *sc,
 {
 	uint8_t ret = 0;
 
-	if (lpfc_cmd_guard_csum(sc)) {
+	if (sc->prot_flags & SCSI_PROT_IP_CHECKSUM) {
 		switch (scsi_get_prot_op(sc)) {
 		case SCSI_PROT_READ_INSERT:
 		case SCSI_PROT_WRITE_STRIP:
@@ -1620,7 +1596,7 @@ lpfc_bg_setup_bpl(struct lpfc_hba *phba, struct scsi_cmnd *sc,
 		goto out;
 
 	/* extract some info from the scsi command for pde*/
-	reftag = t10_pi_ref_tag(sc->request);
+	reftag = scsi_prot_ref_tag(sc);
 	if (reftag == LPFC_INVALID_REFTAG)
 		goto out;
 
@@ -1659,12 +1635,12 @@ lpfc_bg_setup_bpl(struct lpfc_hba *phba, struct scsi_cmnd *sc,
 	 * protection data is automatically generated, not checked.
 	 */
 	if (datadir == DMA_FROM_DEVICE) {
-		if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD))
+		if (sc->prot_flags & SCSI_PROT_GUARD_CHECK)
 			bf_set(pde6_ce, pde6, checking);
 		else
 			bf_set(pde6_ce, pde6, 0);
 
-		if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF))
+		if (sc->prot_flags & SCSI_PROT_REF_CHECK)
 			bf_set(pde6_re, pde6, checking);
 		else
 			bf_set(pde6_re, pde6, 0);
@@ -1782,8 +1758,8 @@ lpfc_bg_setup_bpl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc,
 		goto out;
 
 	/* extract some info from the scsi command */
-	blksize = lpfc_cmd_blksize(sc);
-	reftag = t10_pi_ref_tag(sc->request);
+	blksize = scsi_prot_interval(sc);
+	reftag = scsi_prot_ref_tag(sc);
 	if (reftag == LPFC_INVALID_REFTAG)
 		goto out;
 
@@ -1823,12 +1799,12 @@ lpfc_bg_setup_bpl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc,
 		bf_set(pde6_optx, pde6, txop);
 		bf_set(pde6_oprx, pde6, rxop);
 
-		if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD))
+		if (sc->prot_flags & SCSI_PROT_GUARD_CHECK)
 			bf_set(pde6_ce, pde6, checking);
 		else
 			bf_set(pde6_ce, pde6, 0);
 
-		if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF))
+		if (sc->prot_flags & SCSI_PROT_REF_CHECK)
 			bf_set(pde6_re, pde6, checking);
 		else
 			bf_set(pde6_re, pde6, 0);
@@ -2014,7 +1990,7 @@ lpfc_bg_setup_sgl(struct lpfc_hba *phba, struct scsi_cmnd *sc,
 		goto out;
 
 	/* extract some info from the scsi command for pde*/
-	reftag = t10_pi_ref_tag(sc->request);
+	reftag = scsi_prot_ref_tag(sc);
 	if (reftag == LPFC_INVALID_REFTAG)
 		goto out;
 
@@ -2042,12 +2018,12 @@ lpfc_bg_setup_sgl(struct lpfc_hba *phba, struct scsi_cmnd *sc,
 	 * protection data is automatically generated, not checked.
 	 */
 	if (sc->sc_data_direction == DMA_FROM_DEVICE) {
-		if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD))
+		if (sc->prot_flags & SCSI_PROT_GUARD_CHECK)
 			bf_set(lpfc_sli4_sge_dif_ce, diseed, checking);
 		else
 			bf_set(lpfc_sli4_sge_dif_ce, diseed, 0);
 
-		if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF))
+		if (sc->prot_flags & SCSI_PROT_REF_CHECK)
 			bf_set(lpfc_sli4_sge_dif_re, diseed, checking);
 		else
 			bf_set(lpfc_sli4_sge_dif_re, diseed, 0);
@@ -2214,8 +2190,8 @@ lpfc_bg_setup_sgl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc,
 		goto out;
 
 	/* extract some info from the scsi command */
-	blksize = lpfc_cmd_blksize(sc);
-	reftag = t10_pi_ref_tag(sc->request);
+	blksize = scsi_prot_interval(sc);
+	reftag = scsi_prot_ref_tag(sc);
 	if (reftag == LPFC_INVALID_REFTAG)
 		goto out;
 
@@ -2272,9 +2248,8 @@ lpfc_bg_setup_sgl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc,
 		diseed->ref_tag = cpu_to_le32(reftag);
 		diseed->ref_tag_tran = diseed->ref_tag;
 
-		if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD)) {
+		if (sc->prot_flags & SCSI_PROT_GUARD_CHECK) {
 			bf_set(lpfc_sli4_sge_dif_ce, diseed, checking);
-
 		} else {
 			bf_set(lpfc_sli4_sge_dif_ce, diseed, 0);
 			/*
@@ -2291,7 +2266,7 @@ lpfc_bg_setup_sgl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc,
 		}
 
 
-		if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF))
+		if (sc->prot_flags & SCSI_PROT_REF_CHECK)
 			bf_set(lpfc_sli4_sge_dif_re, diseed, checking);
 		else
 			bf_set(lpfc_sli4_sge_dif_re, diseed, 0);
@@ -2548,7 +2523,7 @@ lpfc_bg_scsi_adjust_dl(struct lpfc_hba *phba,
 	 * DIF (trailer) attached to it. Must ajust FCP data length
 	 * to account for the protection data.
 	 */
-	fcpdl += (fcpdl / lpfc_cmd_blksize(sc)) * 8;
+	fcpdl += (fcpdl / scsi_prot_interval(sc)) * 8;
 
 	return fcpdl;
 }
@@ -2802,14 +2777,14 @@ lpfc_calc_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd)
 		 * data length is a multiple of the blksize.
 		 */
 		sgde = scsi_sglist(cmd);
-		blksize = lpfc_cmd_blksize(cmd);
+		blksize = scsi_prot_interval(cmd);
 		data_src = (uint8_t *)sg_virt(sgde);
 		data_len = sgde->length;
 		if ((data_len & (blksize - 1)) == 0)
 			chk_guard = 1;
 
 		src = (struct scsi_dif_tuple *)sg_virt(sgpe);
-		start_ref_tag = t10_pi_ref_tag(cmd->request);
+		start_ref_tag = scsi_prot_ref_tag(cmd);
 		if (start_ref_tag == LPFC_INVALID_REFTAG)
 			goto out;
 		start_app_tag = src->app_tag;
@@ -2830,7 +2805,8 @@ lpfc_calc_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd)
 				/* First Guard Tag checking */
 				if (chk_guard) {
 					guard_tag = src->guard_tag;
-					if (lpfc_cmd_guard_csum(cmd))
+					if (cmd->prot_flags
+					    & SCSI_PROT_IP_CHECKSUM)
 						sum = lpfc_bg_csum(data_src,
 								   blksize);
 					else
@@ -2901,7 +2877,7 @@ lpfc_calc_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd)
 		phba->bg_guard_err_cnt++;
 		lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
 				"9069 BLKGRD: reftag %x grd_tag err %x != %x\n",
-				t10_pi_ref_tag(cmd->request),
+				scsi_prot_ref_tag(cmd),
 				sum, guard_tag);
 
 	} else if (err_type == BGS_REFTAG_ERR_MASK) {
@@ -2911,7 +2887,7 @@ lpfc_calc_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd)
 		phba->bg_reftag_err_cnt++;
 		lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
 				"9066 BLKGRD: reftag %x ref_tag err %x != %x\n",
-				t10_pi_ref_tag(cmd->request),
+				scsi_prot_ref_tag(cmd),
 				ref_tag, start_ref_tag);
 
 	} else if (err_type == BGS_APPTAG_ERR_MASK) {
@@ -2921,7 +2897,7 @@ lpfc_calc_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd)
 		phba->bg_apptag_err_cnt++;
 		lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
 				"9041 BLKGRD: reftag %x app_tag err %x != %x\n",
-				t10_pi_ref_tag(cmd->request),
+				scsi_prot_ref_tag(cmd),
 				app_tag, start_app_tag);
 	}
 }
@@ -3094,7 +3070,7 @@ lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd,
 				"9072 BLKGRD: Invalid BG Profile in cmd "
 				"0x%x reftag 0x%x blk cnt 0x%x "
 				"bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
-				t10_pi_ref_tag(cmd->request),
+				scsi_prot_ref_tag(cmd),
 				blk_rq_sectors(cmd->request), bgstat, bghm);
 		ret = (-1);
 		goto out;
@@ -3106,7 +3082,7 @@ lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd,
 				"9073 BLKGRD: Invalid BG PDIF Block in cmd "
 				"0x%x reftag 0x%x blk cnt 0x%x "
 				"bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
-				t10_pi_ref_tag(cmd->request),
+				scsi_prot_ref_tag(cmd),
 				blk_rq_sectors(cmd->request), bgstat, bghm);
 		ret = (-1);
 		goto out;
@@ -3122,7 +3098,7 @@ lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd,
 				"9055 BLKGRD: Guard Tag error in cmd "
 				"0x%x reftag 0x%x blk cnt 0x%x "
 				"bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
-				t10_pi_ref_tag(cmd->request),
+				scsi_prot_ref_tag(cmd),
 				blk_rq_sectors(cmd->request), bgstat, bghm);
 	}
 
@@ -3137,7 +3113,7 @@ lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd,
 				"9056 BLKGRD: Ref Tag error in cmd "
 				"0x%x reftag 0x%x blk cnt 0x%x "
 				"bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
-				t10_pi_ref_tag(cmd->request),
+				scsi_prot_ref_tag(cmd),
 				blk_rq_sectors(cmd->request), bgstat, bghm);
 	}
 
@@ -3152,7 +3128,7 @@ lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd,
 				"9061 BLKGRD: App Tag error in cmd "
 				"0x%x reftag 0x%x blk cnt 0x%x "
 				"bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
-				t10_pi_ref_tag(cmd->request),
+				scsi_prot_ref_tag(cmd),
 				blk_rq_sectors(cmd->request), bgstat, bghm);
 	}
 
@@ -3196,7 +3172,7 @@ lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd,
 				"9057 BLKGRD: Unknown error in cmd "
 				"0x%x reftag 0x%x blk cnt 0x%x "
 				"bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
-				t10_pi_ref_tag(cmd->request),
+				scsi_prot_ref_tag(cmd),
 				blk_rq_sectors(cmd->request), bgstat, bghm);
 
 		/* Calcuate what type of error it was */
@@ -5284,7 +5260,7 @@ lpfc_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *cmnd)
 					 "reftag x%x cnt %u pt %x\n",
 					 dif_op_str[scsi_get_prot_op(cmnd)],
 					 cmnd->cmnd[0],
-					 t10_pi_ref_tag(cmnd->request),
+					 scsi_prot_ref_tag(cmnd),
 					 blk_rq_sectors(cmnd->request),
 					 (cmnd->cmnd[1]>>5));
 		}
@@ -5296,7 +5272,7 @@ lpfc_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *cmnd)
 					 "9038 BLKGRD: rcvd PROT_NORMAL cmd: "
 					 "x%x reftag x%x cnt %u pt %x\n",
 					 cmnd->cmnd[0],
-					 t10_pi_ref_tag(cmnd->request),
+					 scsi_prot_ref_tag(cmnd),
 					 blk_rq_sectors(cmnd->request),
 					 (cmnd->cmnd[1]>>5));
 		}
Signature · 1 line
2.31.1
#5 lore raw

PATCH 3/15 scsi: qla2xxx: Use the proper SCSI midlayer interfaces for PI

In reply to Martin K. Petersen

Use the SCSI midlayer interfaces to query protection interval, reference tag, and per-command DIX flags.

---
 drivers/scsi/qla2xxx/qla_iocb.c | 84 ++++++---------------------------
 1 file changed, 15 insertions(+), 69 deletions(-)
drivers/scsi/qla2xxx/qla_iocb.c +15 -69
index 38b5bdde2405..42a6fbba7529 100644
@@ -145,7 +145,6 @@ inline int
 qla24xx_configure_prot_mode(srb_t *sp, uint16_t *fw_prot_opts)
 {
 	struct scsi_cmnd *cmd = GET_CMD_SP(sp);
-	uint8_t	guard = scsi_host_get_guard(cmd->device->host);
 
 	/* We always use DIFF Bundling for best performance */
 	*fw_prot_opts = 0;
@@ -166,7 +165,7 @@ qla24xx_configure_prot_mode(srb_t *sp, uint16_t *fw_prot_opts)
 		break;
 	case SCSI_PROT_READ_PASS:
 	case SCSI_PROT_WRITE_PASS:
-		if (guard & SHOST_DIX_GUARD_IP)
+		if (cmd->prot_flags & SCSI_PROT_IP_CHECKSUM)
 			*fw_prot_opts |= PO_MODE_DIF_TCP_CKSUM;
 		else
 			*fw_prot_opts |= PO_MODE_DIF_PASS;
@@ -176,6 +175,9 @@ qla24xx_configure_prot_mode(srb_t *sp, uint16_t *fw_prot_opts)
 		break;
 	}
 
+	if (!(cmd->prot_flags & SCSI_PROT_GUARD_CHECK))
+		*fw_prot_opts |= PO_DISABLE_GUARD_CHECK;
+
 	return scsi_prot_sg_count(cmd);
 }
 
@@ -772,74 +774,18 @@ qla24xx_set_t10dif_tags(srb_t *sp, struct fw_dif_context *pkt,
 {
 	struct scsi_cmnd *cmd = GET_CMD_SP(sp);
 
-	switch (scsi_get_prot_type(cmd)) {
-	case SCSI_PROT_DIF_TYPE0:
-		/*
-		 * No check for ql2xenablehba_err_chk, as it would be an
-		 * I/O error if hba tag generation is not done.
-		 */
-		pkt->ref_tag = cpu_to_le32((uint32_t)
-		    (0xffffffff & scsi_get_lba(cmd)));
-
-		if (!qla2x00_hba_err_chk_enabled(sp))
-			break;
-
-		pkt->ref_tag_mask[0] = 0xff;
-		pkt->ref_tag_mask[1] = 0xff;
-		pkt->ref_tag_mask[2] = 0xff;
-		pkt->ref_tag_mask[3] = 0xff;
-		break;
-
-	/*
-	 * For TYPE 2 protection: 16 bit GUARD + 32 bit REF tag has to
-	 * match LBA in CDB + N
-	 */
-	case SCSI_PROT_DIF_TYPE2:
-		pkt->app_tag = cpu_to_le16(0);
-		pkt->app_tag_mask[0] = 0x0;
-		pkt->app_tag_mask[1] = 0x0;
-
-		pkt->ref_tag = cpu_to_le32((uint32_t)
-		    (0xffffffff & scsi_get_lba(cmd)));
+	pkt->ref_tag = cpu_to_le32(scsi_prot_ref_tag(cmd));
 
-		if (!qla2x00_hba_err_chk_enabled(sp))
-			break;
-
-		/* enable ALL bytes of the ref tag */
-		pkt->ref_tag_mask[0] = 0xff;
-		pkt->ref_tag_mask[1] = 0xff;
-		pkt->ref_tag_mask[2] = 0xff;
-		pkt->ref_tag_mask[3] = 0xff;
-		break;
-
-	/* For Type 3 protection: 16 bit GUARD only */
-	case SCSI_PROT_DIF_TYPE3:
-		pkt->ref_tag_mask[0] = pkt->ref_tag_mask[1] =
-			pkt->ref_tag_mask[2] = pkt->ref_tag_mask[3] =
-								0x00;
-		break;
-
-	/*
-	 * For TYpe 1 protection: 16 bit GUARD tag, 32 bit REF tag, and
-	 * 16 bit app tag.
-	 */
-	case SCSI_PROT_DIF_TYPE1:
-		pkt->ref_tag = cpu_to_le32((uint32_t)
-		    (0xffffffff & scsi_get_lba(cmd)));
-		pkt->app_tag = cpu_to_le16(0);
-		pkt->app_tag_mask[0] = 0x0;
-		pkt->app_tag_mask[1] = 0x0;
-
-		if (!qla2x00_hba_err_chk_enabled(sp))
-			break;
-
-		/* enable ALL bytes of the ref tag */
-		pkt->ref_tag_mask[0] = 0xff;
-		pkt->ref_tag_mask[1] = 0xff;
-		pkt->ref_tag_mask[2] = 0xff;
-		pkt->ref_tag_mask[3] = 0xff;
-		break;
+	if (cmd->prot_flags & SCSI_PROT_REF_CHECK) {
+                pkt->ref_tag_mask[0] = 0xff;
+                pkt->ref_tag_mask[1] = 0xff;
+                pkt->ref_tag_mask[2] = 0xff;
+                pkt->ref_tag_mask[3] = 0xff;
 	}
+
+	pkt->app_tag = __constant_cpu_to_le16(0);
+	pkt->app_tag_mask[0] = 0x0;
+	pkt->app_tag_mask[1] = 0x0;
 }
 
 int
@@ -905,7 +851,7 @@ qla24xx_walk_and_build_sglist_no_difb(struct qla_hw_data *ha, srb_t *sp,
 	memset(&sgx, 0, sizeof(struct qla2_sgx));
 	if (sp) {
 		cmd = GET_CMD_SP(sp);
-		prot_int = cmd->device->sector_size;
+		prot_int = scsi_prot_interval(cmd);
 
 		sgx.tot_bytes = scsi_bufflen(cmd);
 		sgx.cur_sg = scsi_sglist(cmd);
Signature · 1 line
2.31.1
Reviewed-by on v1 3/15
#6 lore raw

Re: [PATCH 03/15] scsi: qla2xxx: Use the proper SCSI midlayer interfaces for PI

Quoted 102 lines · Martin K. Petersen

Use the SCSI midlayer interfaces to query protection interval, reference tag, and per-command DIX flags.

---
 drivers/scsi/qla2xxx/qla_iocb.c | 84 ++++++---------------------------
 1 file changed, 15 insertions(+), 69 deletions(-)
drivers/scsi/qla2xxx/qla_iocb.c +5 -59
index 38b5bdde2405..42a6fbba7529 100644
@@ -145,7 +145,6 @@ inline int
 qla24xx_configure_prot_mode(srb_t *sp, uint16_t *fw_prot_opts)
 {
 	struct scsi_cmnd *cmd = GET_CMD_SP(sp);
-	uint8_t	guard = scsi_host_get_guard(cmd->device->host);
 
 	/* We always use DIFF Bundling for best performance */
 	*fw_prot_opts = 0;
@@ -166,7 +165,7 @@ qla24xx_configure_prot_mode(srb_t *sp, uint16_t *fw_prot_opts)
 		break;
 	case SCSI_PROT_READ_PASS:
 	case SCSI_PROT_WRITE_PASS:
-		if (guard & SHOST_DIX_GUARD_IP)
+		if (cmd->prot_flags & SCSI_PROT_IP_CHECKSUM)
 			*fw_prot_opts |= PO_MODE_DIF_TCP_CKSUM;
 		else
 			*fw_prot_opts |= PO_MODE_DIF_PASS;
@@ -176,6 +175,9 @@ qla24xx_configure_prot_mode(srb_t *sp, uint16_t *fw_prot_opts)
 		break;
 	}
 
+	if (!(cmd->prot_flags & SCSI_PROT_GUARD_CHECK))
+		*fw_prot_opts |= PO_DISABLE_GUARD_CHECK;
+
 	return scsi_prot_sg_count(cmd);
 }
 
@@ -772,74 +774,18 @@ qla24xx_set_t10dif_tags(srb_t *sp, struct fw_dif_context *pkt,
 {
 	struct scsi_cmnd *cmd = GET_CMD_SP(sp);
 
-	switch (scsi_get_prot_type(cmd)) {
-	case SCSI_PROT_DIF_TYPE0:
-		/*
-		 * No check for ql2xenablehba_err_chk, as it would be an
-		 * I/O error if hba tag generation is not done.
-		 */
-		pkt->ref_tag = cpu_to_le32((uint32_t)
-		    (0xffffffff & scsi_get_lba(cmd)));
-
-		if (!qla2x00_hba_err_chk_enabled(sp))
-			break;
-
-		pkt->ref_tag_mask[0] = 0xff;
-		pkt->ref_tag_mask[1] = 0xff;
-		pkt->ref_tag_mask[2] = 0xff;
-		pkt->ref_tag_mask[3] = 0xff;
-		break;
-
-	/*
-	 * For TYPE 2 protection: 16 bit GUARD + 32 bit REF tag has to
-	 * match LBA in CDB + N
-	 */
-	case SCSI_PROT_DIF_TYPE2:
-		pkt->app_tag = cpu_to_le16(0);
-		pkt->app_tag_mask[0] = 0x0;
-		pkt->app_tag_mask[1] = 0x0;
-
-		pkt->ref_tag = cpu_to_le32((uint32_t)
-		    (0xffffffff & scsi_get_lba(cmd)));
+	pkt->ref_tag = cpu_to_le32(scsi_prot_ref_tag(cmd));
 
-		if (!qla2x00_hba_err_chk_enabled(sp))
-			break;
-
-		/* enable ALL bytes of the ref tag */
-		pkt->ref_tag_mask[0] = 0xff;
-		pkt->ref_tag_mask[1] = 0xff;
-		pkt->ref_tag_mask[2] = 0xff;
-		pkt->ref_tag_mask[3] = 0xff;
-		break;
-
-	/* For Type 3 protection: 16 bit GUARD only */
-	case SCSI_PROT_DIF_TYPE3:
-		pkt->ref_tag_mask[0] = pkt->ref_tag_mask[1] =
-			pkt->ref_tag_mask[2] = pkt->ref_tag_mask[3] =
-								0x00;
-		break;
-
-	/*
-	 * For TYpe 1 protection: 16 bit GUARD tag, 32 bit REF tag, and
-	 * 16 bit app tag.
-	 */
-	case SCSI_PROT_DIF_TYPE1:
-		pkt->ref_tag = cpu_to_le32((uint32_t)
-		    (0xffffffff & scsi_get_lba(cmd)));
-		pkt->app_tag = cpu_to_le16(0);
-		pkt->app_tag_mask[0] = 0x0;
-		pkt->app_tag_mask[1] = 0x0;
-

drivers/scsi/qla2xxx/qla_iocb.c qla24xx_set_t10dif_tags(srb_t *sp, struct fw_dif_context *pkt, · line 779

Quoted 10 lines
drivers/scsi/qla2xxx/qla_iocb.c +1 -9
-		if (!qla2x00_hba_err_chk_enabled(sp))
-			break;
-
-		/* enable ALL bytes of the ref tag */
-		pkt->ref_tag_mask[0] = 0xff;
-		pkt->ref_tag_mask[1] = 0xff;
-		pkt->ref_tag_mask[2] = 0xff;
-		pkt->ref_tag_mask[3] = 0xff;
-		break;
+	if (cmd->prot_flags & SCSI_PROT_REF_CHECK) {

I would also add a "&& qla2x00_hba_err_chk_enabled(sp)" to the above check to preserve the old semantics (which was helpful during testing).

With that:

Regards,
-Arun

Quoted 22 lines
drivers/scsi/qla2xxx/qla_iocb.c +9 -1
+                pkt->ref_tag_mask[0] = 0xff;
+                pkt->ref_tag_mask[1] = 0xff;
+                pkt->ref_tag_mask[2] = 0xff;
+                pkt->ref_tag_mask[3] = 0xff;
 	}
+
+	pkt->app_tag = __constant_cpu_to_le16(0);
+	pkt->app_tag_mask[0] = 0x0;
+	pkt->app_tag_mask[1] = 0x0;
 }
 
 int
@@ -905,7 +851,7 @@ qla24xx_walk_and_build_sglist_no_difb(struct qla_hw_data *ha, srb_t *sp,
 	memset(&sgx, 0, sizeof(struct qla2_sgx));
 	if (sp) {
 		cmd = GET_CMD_SP(sp);
-		prot_int = cmd->device->sector_size;
+		prot_int = scsi_prot_interval(cmd);
 
 		sgx.tot_bytes = scsi_bufflen(cmd);
 		sgx.cur_sg = scsi_sglist(cmd);
#7 lore raw

PATCH 4/15 scsi: mpt3sas: Use the proper SCSI midlayer interfaces for PI

In reply to Martin K. Petersen

Use the SCSI midlayer interfaces to query protection interval, reference tag, and per-command DIX flags.

---
 drivers/scsi/mpt3sas/mpt3sas_scsih.c | 28 ++++++----------------------
 1 file changed, 6 insertions(+), 22 deletions(-)
drivers/scsi/mpt3sas/mpt3sas_scsih.c +6 -22
index dc2aaaf645d3..322450800056 100644
@@ -5062,33 +5062,17 @@ _scsih_setup_eedp(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
 	else
 		return;
 
-	switch (prot_type) {
-	case SCSI_PROT_DIF_TYPE1:
-	case SCSI_PROT_DIF_TYPE2:
+	if (scmd->prot_op & SCSI_PROT_GUARD_CHECK)
+		eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
 
-		/*
-		* enable ref/guard checking
-		* auto increment ref tag
-		*/
+	if (scmd->prot_op & SCSI_PROT_REF_CHECK) {
 		eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
-		    MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
-		    MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
+			MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG;
 		mpi_request->CDB.EEDP32.PrimaryReferenceTag =
-		    cpu_to_be32(t10_pi_ref_tag(scmd->request));
-		break;
-
-	case SCSI_PROT_DIF_TYPE3:
-
-		/*
-		* enable guard checking
-		*/
-		eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
-
-		break;
+			cpu_to_be32(scsi_prot_ref_tag(scmd));
 	}
 
-	mpi_request_3v->EEDPBlockSize =
-	    cpu_to_le16(scmd->device->sector_size);
+	mpi_request_3v->EEDPBlockSize = scsi_prot_interval(scmd);
 
 	if (ioc->is_gen35_ioc)
 		eedp_flags |= MPI25_SCSIIO_EEDPFLAGS_APPTAG_DISABLE_MODE;
Signature · 1 line
2.31.1
#8 lore raw

PATCH 5/15 scsi: mpi3mr: Use the proper SCSI midlayer interfaces for PI

In reply to Martin K. Petersen

Use the SCSI midlayer interfaces to query protection interval, reference tag, and per-command DIX flags

---
 drivers/scsi/mpi3mr/mpi3mr_os.c | 59 +++++++++++----------------------
 1 file changed, 20 insertions(+), 39 deletions(-)
drivers/scsi/mpi3mr/mpi3mr_os.c +20 -39
index 4ab0609a1b94..11dcd6930215 100644
@@ -1962,7 +1962,6 @@ static void mpi3mr_setup_eedp(struct mpi3mr_ioc *mrioc,
 {
 	u16 eedp_flags = 0;
 	unsigned char prot_op = scsi_get_prot_op(scmd);
-	unsigned char prot_type = scsi_get_prot_type(scmd);
 
 	switch (prot_op) {
 	case SCSI_PROT_NORMAL:
@@ -1982,60 +1981,42 @@ static void mpi3mr_setup_eedp(struct mpi3mr_ioc *mrioc,
 		scsiio_req->msg_flags |= MPI3_SCSIIO_MSGFLAGS_METASGL_VALID;
 		break;
 	case SCSI_PROT_READ_PASS:
-		eedp_flags = MPI3_EEDPFLAGS_EEDP_OP_CHECK |
-		    MPI3_EEDPFLAGS_CHK_REF_TAG | MPI3_EEDPFLAGS_CHK_APP_TAG |
-		    MPI3_EEDPFLAGS_CHK_GUARD;
+		eedp_flags = MPI3_EEDPFLAGS_EEDP_OP_CHECK;
 		scsiio_req->msg_flags |= MPI3_SCSIIO_MSGFLAGS_METASGL_VALID;
 		break;
 	case SCSI_PROT_WRITE_PASS:
-		if (scsi_host_get_guard(scmd->device->host)
-		    & SHOST_DIX_GUARD_IP) {
-			eedp_flags = MPI3_EEDPFLAGS_EEDP_OP_CHECK_REGEN |
-			    MPI3_EEDPFLAGS_CHK_APP_TAG |
-			    MPI3_EEDPFLAGS_CHK_GUARD |
-			    MPI3_EEDPFLAGS_INCR_PRI_REF_TAG;
+		if (scmd->prot_flags & SCSI_PROT_IP_CHECKSUM) {
+			eedp_flags = MPI3_EEDPFLAGS_EEDP_OP_CHECK_REGEN;
 			scsiio_req->sgl[0].eedp.application_tag_translation_mask =
 			    0xffff;
-		} else {
-			eedp_flags = MPI3_EEDPFLAGS_EEDP_OP_CHECK |
-			    MPI3_EEDPFLAGS_CHK_REF_TAG |
-			    MPI3_EEDPFLAGS_CHK_APP_TAG |
-			    MPI3_EEDPFLAGS_CHK_GUARD;
-		}
+		} else
+			eedp_flags = MPI3_EEDPFLAGS_EEDP_OP_CHECK;
+
 		scsiio_req->msg_flags |= MPI3_SCSIIO_MSGFLAGS_METASGL_VALID;
 		break;
 	default:
 		return;
 	}
 
-	if (scsi_host_get_guard(scmd->device->host) & SHOST_DIX_GUARD_IP)
+	if (scmd->prot_flags & SCSI_PROT_GUARD_CHECK)
+		eedp_flags |= MPI3_EEDPFLAGS_CHK_GUARD;
+
+	if (scmd->prot_flags & SCSI_PROT_IP_CHECKSUM)
 		eedp_flags |= MPI3_EEDPFLAGS_HOST_GUARD_IP_CHKSUM;
 
-	switch (prot_type) {
-	case SCSI_PROT_DIF_TYPE0:
-		eedp_flags |= MPI3_EEDPFLAGS_INCR_PRI_REF_TAG;
+	if (scmd->prot_flags & SCSI_PROT_REF_CHECK) {
+		eedp_flags |= MPI3_EEDPFLAGS_CHK_REF_TAG |
+			MPI3_EEDPFLAGS_INCR_PRI_REF_TAG;
 		scsiio_req->cdb.eedp32.primary_reference_tag =
-		    cpu_to_be32(t10_pi_ref_tag(scmd->request));
-		break;
-	case SCSI_PROT_DIF_TYPE1:
-	case SCSI_PROT_DIF_TYPE2:
-		eedp_flags |= MPI3_EEDPFLAGS_INCR_PRI_REF_TAG |
-		    MPI3_EEDPFLAGS_ESC_MODE_APPTAG_DISABLE |
-		    MPI3_EEDPFLAGS_CHK_GUARD;
-		scsiio_req->cdb.eedp32.primary_reference_tag =
-		    cpu_to_be32(t10_pi_ref_tag(scmd->request));
-		break;
-	case SCSI_PROT_DIF_TYPE3:
-		eedp_flags |= MPI3_EEDPFLAGS_CHK_GUARD |
-		    MPI3_EEDPFLAGS_ESC_MODE_APPTAG_DISABLE;
-		break;
-
-	default:
-		scsiio_req->msg_flags &= ~(MPI3_SCSIIO_MSGFLAGS_METASGL_VALID);
-		return;
+			cpu_to_be32(scsi_prot_ref_tag(scmd));
 	}
 
-	switch (scmd->device->sector_size) {
+	if (scmd->prot_flags & SCSI_PROT_REF_INCREMENT)
+		eedp_flags |= MPI3_EEDPFLAGS_INCR_PRI_REF_TAG;
+
+	eedp_flags |= MPI3_EEDPFLAGS_ESC_MODE_APPTAG_DISABLE;
+
+	switch (scsi_prot_interval(scmd)) {
 	case 512:
 		scsiio_req->sgl[0].eedp.user_data_size = MPI3_EEDP_UDS_512;
 		break;
Signature · 1 line
2.31.1
#9 lore raw

PATCH 6/15 scsi: zfcp: Use the proper SCSI midlayer interfaces for PI

In reply to Martin K. Petersen

Use scsi_prot_ref_tag() and scsi_prot_interval() instead scsi_get_lba() and sector_size.

---
 drivers/s390/scsi/zfcp_fsf.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/s390/scsi/zfcp_fsf.c +2 -2
index 2e4804ef2fb9..1990216cf289 100644
@@ -2599,8 +2599,8 @@ int zfcp_fsf_fcp_cmnd(struct scsi_cmnd *scsi_cmnd)
 	io->fcp_cmnd_length = FCP_CMND_LEN;
 
 	if (scsi_get_prot_op(scsi_cmnd) != SCSI_PROT_NORMAL) {
-		io->data_block_length = scsi_cmnd->device->sector_size;
-		io->ref_tag_value = scsi_get_lba(scsi_cmnd) & 0xFFFFFFFF;
+		io->data_block_length = scsi_prot_interval(scsi_cmnd);
+		io->ref_tag_value = scsi_prot_ref_tag(scsi_cmnd);
 	}
 
 	if (zfcp_fsf_set_data_dir(scsi_cmnd, &io->data_direction))
Signature · 1 line
2.31.1
Reviewed-by on v1 6/15
#10 lore raw

Re: [PATCH 06/15] scsi: zfcp: Use the proper SCSI midlayer interfaces for PI

Hey Martin,

please set me and Steffen on CC next time for zfcp.

Quoted 13 lines · Martin K. Petersen

Use scsi_prot_ref_tag() and scsi_prot_interval() instead scsi_get_lba() and sector_size.

---
 drivers/s390/scsi/zfcp_fsf.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/s390/scsi/zfcp_fsf.c +0 -0
index 2e4804ef2fb9..1990216cf289 100644

drivers/s390/scsi/zfcp_fsf.c int zfcp_fsf_fcp_cmnd(struct scsi_cmnd *scsi_cmnd) · line 2603

Quoted 7 lines
drivers/s390/scsi/zfcp_fsf.c +2 -2
@@ -2599,8 +2599,8 @@ int zfcp_fsf_fcp_cmnd(struct scsi_cmnd *scsi_cmnd)
 	io->fcp_cmnd_length = FCP_CMND_LEN;
 
 	if (scsi_get_prot_op(scsi_cmnd) != SCSI_PROT_NORMAL) {
-		io->data_block_length = scsi_cmnd->device->sector_size;
-		io->ref_tag_value = scsi_get_lba(scsi_cmnd) & 0xFFFFFFFF;
+		io->data_block_length = scsi_prot_interval(scsi_cmnd);
+		io->ref_tag_value = scsi_prot_ref_tag(scsi_cmnd);

Out of curiosity, do you have any idea whether there is any storage that offers DIF with a different Logical Block Size than 512 (I haven't see any, although, that doesn't say much)? Just re-read some parts of our HBA specs and we probably would be in trouble, if it does, with how we do things here.

Signature · 4 lines
Best Regards, Benjamin Block  / Linux on IBM Z Kernel Development / IBM Systems
IBM Deutschland Research & Development GmbH    /    https://www.ibm.com/privacy
Vorsitz. AufsR.: Gregor Pillen         /        Geschäftsführung: Dirk Wittkopp
Sitz der Gesellschaft: Böblingen / Registergericht: AmtsG Stuttgart, HRB 243294
#11 lore raw

Re: [PATCH 06/15] scsi: zfcp: Use the proper SCSI midlayer interfaces for PI

Benjamin,

Quoted 1 line

please set me and Steffen on CC next time for zfcp.

Sure.

Quoted 5 lines

Out of curiosity, do you have any idea whether there is any storage that offers DIF with a different Logical Block Size than 512 (I haven't see any, although, that doesn't say much)? Just re-read some parts of our HBA specs and we probably would be in trouble, if it does, with how we do things here.

I have a few that are 4Kn+8. It wouldn't say these are very common, the 16-bit CRC isn't that great with 4K blocks.

To address the block size issue we defined a couple of new protection formats in NVMe. These allow for 32 and 64-bit CRCs, larger reference tags, etc. However, these enhancements have yet to percolate down into SCSI/SBC.

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
#12 lore raw

Re: [PATCH 06/15] scsi: zfcp: Use the proper SCSI midlayer interfaces for PI

Quoted 6 lines · Martin K. Petersen
Quoted 5 lines

Out of curiosity, do you have any idea whether there is any storage that offers DIF with a different Logical Block Size than 512 (I haven't see any, although, that doesn't say much)? Just re-read some parts of our HBA specs and we probably would be in trouble, if it does, with how we do things here.

Quoted 7 lines

I have a few that are 4Kn+8. It wouldn't say these are very common, the 16-bit CRC isn't that great with 4K blocks.

To address the block size issue we defined a couple of new protection formats in NVMe. These allow for 32 and 64-bit CRCs, larger reference tags, etc. However, these enhancements have yet to percolate down into SCSI/SBC.

Oh, interesting. Thanks for sharing.

Signature · 4 lines
Best Regards, Benjamin Block  / Linux on IBM Z Kernel Development / IBM Systems
IBM Deutschland Research & Development GmbH    /    https://www.ibm.com/privacy
Vorsitz. AufsR.: Gregor Pillen         /        Geschäftsführung: Dirk Wittkopp
Sitz der Gesellschaft: Böblingen / Registergericht: AmtsG Stuttgart, HRB 243294
#13 lore raw

PATCH 7/15 scsi: isci: Use the proper SCSI midlayer interfaces for PI

In reply to Martin K. Petersen

Use scsi_prot_ref_tag() instead of scsi_get_lba() to get the reference tag for a given I/O.

---
 drivers/scsi/isci/request.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/isci/request.c +2 -2
index e1ff79464131..fcaa84a3c210 100644
@@ -341,7 +341,7 @@ static void scu_ssp_ireq_dif_insert(struct isci_request *ireq, u8 type, u8 op)
 	tc->reserved_E8_0 = 0;
 
 	if ((type & SCSI_PROT_DIF_TYPE1) || (type & SCSI_PROT_DIF_TYPE2))
-		tc->ref_tag_seed_gen = scsi_get_lba(scmd) & 0xffffffff;
+		tc->ref_tag_seed_gen = scsi_prot_ref_tag(scmd);
 	else if (type & SCSI_PROT_DIF_TYPE3)
 		tc->ref_tag_seed_gen = 0;
 }
@@ -369,7 +369,7 @@ static void scu_ssp_ireq_dif_strip(struct isci_request *ireq, u8 type, u8 op)
 	tc->app_tag_gen = 0;
 
 	if ((type & SCSI_PROT_DIF_TYPE1) || (type & SCSI_PROT_DIF_TYPE2))
-		tc->ref_tag_seed_verify = scsi_get_lba(scmd) & 0xffffffff;
+		tc->ref_tag_seed_verify = scsi_prot_ref_tag(scmd);
 	else if (type & SCSI_PROT_DIF_TYPE3)
 		tc->ref_tag_seed_verify = 0;
 
Signature · 1 line
2.31.1
#14 lore raw

PATCH 8/15 scsi: scsi_debug: Remove dump_sector()

In reply to Martin K. Petersen

The function used to dump sectors containing protection information errors was useful during initial development over a decade ago. However, dump_sector() substantially slows down the system during testing due to writing an entire sector's worth of data to syslog on every error.

We now log plenty of information about the nature of detected protection information errors throughout the stack. Dumping the entire contents of an offending sector is no longer needed.

---
 drivers/scsi/scsi_debug.c | 26 +-------------------------
 1 file changed, 1 insertion(+), 25 deletions(-)
drivers/scsi/scsi_debug.c +1 -25
index 5b3a20a140f9..9033ab4911ba 100644
@@ -3232,28 +3232,6 @@ static int resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
 	return 0;
 }
 
-static void dump_sector(unsigned char *buf, int len)
-{
-	int i, j, n;
-
-	pr_err(">>> Sector Dump <<<\n");
-	for (i = 0 ; i < len ; i += 16) {
-		char b[128];
-
-		for (j = 0, n = 0; j < 16; j++) {
-			unsigned char c = buf[i+j];
-
-			if (c >= 0x20 && c < 0x7e)
-				n += scnprintf(b + n, sizeof(b) - n,
-					       " %c ", buf[i+j]);
-			else
-				n += scnprintf(b + n, sizeof(b) - n,
-					       "%02x ", buf[i+j]);
-		}
-		pr_err("%04d: %s\n", i, b);
-	}
-}
-
 static int prot_verify_write(struct scsi_cmnd *SCpnt, sector_t start_sec,
 			     unsigned int sectors, u32 ei_lba)
 {
@@ -3300,10 +3278,8 @@ static int prot_verify_write(struct scsi_cmnd *SCpnt, sector_t start_sec,
 			daddr = diter.addr + dpage_offset;
 
 			ret = dif_verify(sdt, daddr, sector, ei_lba);
-			if (ret) {
-				dump_sector(daddr, sdebug_sector_size);
+			if (ret)
 				goto out;
-			}
 
 			sector++;
 			ei_lba++;
Signature · 1 line
2.31.1
Reviewed-by on v1 8/15
#15 lore raw

Re: [PATCH 08/15] scsi: scsi_debug: Remove dump_sector()

Quoted 9 lines · Martin K. Petersen

The function used to dump sectors containing protection information errors was useful during initial development over a decade ago. However, dump_sector() substantially slows down the system during testing due to writing an entire sector's worth of data to syslog on every error.

We now log plenty of information about the nature of detected protection information errors throughout the stack. Dumping the entire contents of an offending sector is no longer needed.

Reviewed-by on v1 8/15
#16 lore raw

Re: [PATCH 08/15] scsi: scsi_debug: Remove dump_sector()

In reply to Martin K. Petersen
Quoted 11 lines · Martin K. Petersen

The function used to dump sectors containing protection information errors was useful during initial development over a decade ago. However, dump_sector() substantially slows down the system during testing due to writing an entire sector's worth of data to syslog on every error.

We now log plenty of information about the nature of detected protection information errors throughout the stack. Dumping the entire contents of an offending sector is no longer needed.

#17 lore raw

PATCH 9/15 scsi: scsi_debug: Improve RDPROTECT/WRPROTECT handling

In reply to Martin K. Petersen

It is useful for testing purposes to be able to inject errors by writing bad protection information to media with checking disabled and then attempting to read it back. Extend scsi_debug's PI verification logic to give the driver feature parity with commercially available drives. Almost all devices with PI capability support RDPROTECT and WRPROTECT values of 0, 1, and 3.

---
 drivers/scsi/scsi_debug.c | 90 +++++++++++++++++++++++++++++----------
 1 file changed, 67 insertions(+), 23 deletions(-)
drivers/scsi/scsi_debug.c +67 -23
index 9033ab4911ba..25112b15ab14 100644
@@ -3076,6 +3076,7 @@ static void dif_copy_prot(struct scsi_cmnd *scp, sector_t sector,
 static int prot_verify_read(struct scsi_cmnd *scp, sector_t start_sec,
 			    unsigned int sectors, u32 ei_lba)
 {
+	int ret = 0;
 	unsigned int i;
 	sector_t sector;
 	struct sdeb_store_info *sip = devip2sip((struct sdebug_dev_info *)
@@ -3083,26 +3084,33 @@ static int prot_verify_read(struct scsi_cmnd *scp, sector_t start_sec,
 	struct t10_pi_tuple *sdt;
 
 	for (i = 0; i < sectors; i++, ei_lba++) {
-		int ret;
-
 		sector = start_sec + i;
 		sdt = dif_store(sip, sector);
 
 		if (sdt->app_tag == cpu_to_be16(0xffff))
 			continue;
 
-		ret = dif_verify(sdt, lba2fake_store(sip, sector), sector,
-				 ei_lba);
-		if (ret) {
-			dif_errors++;
-			return ret;
+		/*
+		 * Because scsi_debug acts as both initiator and
+		 * target we proceed to verify the PI even if
+		 * RDPROTECT=3. This is done so the "initiator" knows
+		 * which type of error to return. Otherwise we would
+		 * have to iterate over the PI twice.
+		 */
+		if (scp->cmnd[1] >> 5) { /* RDPROTECT */
+			ret = dif_verify(sdt, lba2fake_store(sip, sector),
+					 sector, ei_lba);
+			if (ret) {
+				dif_errors++;
+				break;
+			}
 		}
 	}
 
 	dif_copy_prot(scp, start_sec, sectors, true);
 	dix_reads++;
 
-	return 0;
+	return ret;
 }
 
 static int resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
@@ -3196,12 +3204,29 @@ static int resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
 
 	/* DIX + T10 DIF */
 	if (unlikely(sdebug_dix && scsi_prot_sg_count(scp))) {
-		int prot_ret = prot_verify_read(scp, lba, num, ei_lba);
-
-		if (prot_ret) {
-			read_unlock(macc_lckp);
-			mk_sense_buffer(scp, ABORTED_COMMAND, 0x10, prot_ret);
-			return illegal_condition_result;
+		switch (prot_verify_read(scp, lba, num, ei_lba)) {
+		case 1: /* Guard tag error */
+			if (cmd[1] >> 5 != 3) { /* RDPROTECT != 3 */
+				read_unlock(macc_lckp);
+				mk_sense_buffer(scp, ABORTED_COMMAND, 0x10, 1);
+				return check_condition_result;
+			} else if (scp->prot_flags & SCSI_PROT_GUARD_CHECK) {
+				read_unlock(macc_lckp);
+				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 */
+				read_unlock(macc_lckp);
+				mk_sense_buffer(scp, ABORTED_COMMAND, 0x10, 3);
+				return check_condition_result;
+			} else if (scp->prot_flags & SCSI_PROT_REF_CHECK) {
+				read_unlock(macc_lckp);
+				mk_sense_buffer(scp, ILLEGAL_REQUEST, 0x10, 3);
+				return illegal_condition_result;
+			}
+			break;
 		}
 	}
 
@@ -3277,9 +3302,11 @@ static int prot_verify_write(struct scsi_cmnd *SCpnt, sector_t start_sec,
 			sdt = piter.addr + ppage_offset;
 			daddr = diter.addr + dpage_offset;
 
-			ret = dif_verify(sdt, daddr, sector, ei_lba);
-			if (ret)
-				goto out;
+			if (SCpnt->cmnd[1] >> 5 != 3) { /* WRPROTECT */
+				ret = dif_verify(sdt, daddr, sector, ei_lba);
+				if (ret)
+					goto out;
+			}
 
 			sector++;
 			ei_lba++;
@@ -3456,12 +3483,29 @@ static int resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
 
 	/* DIX + T10 DIF */
 	if (unlikely(sdebug_dix && scsi_prot_sg_count(scp))) {
-		int prot_ret = prot_verify_write(scp, lba, num, ei_lba);
-
-		if (prot_ret) {
-			write_unlock(macc_lckp);
-			mk_sense_buffer(scp, ILLEGAL_REQUEST, 0x10, prot_ret);
-			return illegal_condition_result;
+		switch (prot_verify_write(scp, lba, num, ei_lba)) {
+		case 1: /* Guard tag error */
+			if (scp->prot_flags & SCSI_PROT_GUARD_CHECK) {
+				write_unlock(macc_lckp);
+				mk_sense_buffer(scp, ILLEGAL_REQUEST, 0x10, 1);
+				return illegal_condition_result;
+			} else if (scp->cmnd[1] >> 5 != 3) { /* WRPROTECT != 3 */
+				write_unlock(macc_lckp);
+				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) {
+				write_unlock(macc_lckp);
+				mk_sense_buffer(scp, ILLEGAL_REQUEST, 0x10, 3);
+				return illegal_condition_result;
+			} else if (scp->cmnd[1] >> 5 != 3) { /* WRPROTECT != 3 */
+				write_unlock(macc_lckp);
+				mk_sense_buffer(scp, ABORTED_COMMAND, 0x10, 3);
+				return check_condition_result;
+			}
+			break;
 		}
 	}
 
Signature · 1 line
2.31.1
Reviewed-by on v1 9/15
#18 lore raw

Re: [PATCH 09/15] scsi: scsi_debug: Improve RDPROTECT/WRPROTECT handling

Quoted 8 lines · Martin K. Petersen

It is useful for testing purposes to be able to inject errors by writing bad protection information to media with checking disabled and then attempting to read it back. Extend scsi_debug's PI verification logic to give the driver feature parity with commercially available drives. Almost all devices with PI capability support RDPROTECT and WRPROTECT values of 0, 1, and 3.

#19 lore raw

PATCH 10/15 scsi: core: Introduce scsi_get_sector()

In reply to Martin K. Petersen

From: Bart Van Assche <[email protected]>

Since scsi_get_lba() returns a sector_t value instead of the LBA, the name of that function is confusing. Introduce an identical function scsi_get_sector().

---
 include/scsi/scsi_cmnd.h | 5 +++++
 1 file changed, 5 insertions(+)
include/scsi/scsi_cmnd.h +5 -0
index 301b9cd4ddd0..cba63377d46a 100644
@@ -220,6 +220,11 @@ static inline int scsi_sg_copy_to_buffer(struct scsi_cmnd *cmd,
 				 buf, buflen);
 }
 
+static inline sector_t scsi_get_sector(struct scsi_cmnd *scmd)
+{
+	return blk_rq_pos(scmd->request);
+}
+
 /*
  * The operations below are hints that tell the controller driver how
  * to handle I/Os with DIF or similar types of protection information.
Signature · 1 line
2.31.1
#20 lore raw

Re: [PATCH 10/15] scsi: core: Introduce scsi_get_sector()

Quoted 22 lines · Martin K. Petersen

From: Bart Van Assche <[email protected]>

Since scsi_get_lba() returns a sector_t value instead of the LBA, the name of that function is confusing. Introduce an identical function scsi_get_sector().

---
 include/scsi/scsi_cmnd.h | 5 +++++
 1 file changed, 5 insertions(+)
include/scsi/scsi_cmnd.h +0 -0
index 301b9cd4ddd0..cba63377d46a 100644

include/scsi/scsi_cmnd.h static inline int scsi_sg_copy_to_buffer(struct scsi_cmnd *cmd, · line 225

Quoted 6 lines
include/scsi/scsi_cmnd.h +3 -0
@@ -220,6 +220,11 @@ static inline int scsi_sg_copy_to_buffer(struct scsi_cmnd *cmd,
 				 buf, buflen);
 }
 
+static inline sector_t scsi_get_sector(struct scsi_cmnd *scmd)
+{
+	return blk_rq_pos(scmd->request);

Wondering a bit why this still uses the request pointer, after you say in patch 01 that it goes away. So it should probably use blk_mq_rq_from_pdu()?

Signature · 4 lines
Best Regards, Benjamin Block  / Linux on IBM Z Kernel Development / IBM Systems
IBM Deutschland Research & Development GmbH    /    https://www.ibm.com/privacy
Vorsitz. AufsR.: Gregor Pillen         /        Geschäftsführung: Dirk Wittkopp
Sitz der Gesellschaft: Böblingen / Registergericht: AmtsG Stuttgart, HRB 243294
#21 lore raw

Re: [PATCH 10/15] scsi: core: Introduce scsi_get_sector()

Benjamin,

Quoted 3 lines

Wondering a bit why this still uses the request pointer, after you say in patch 01 that it goes away. So it should probably use blk_mq_rq_from_pdu()?

I was just getting everything ready for Bart's series that makes this change throughout the tree.

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
Reviewed-by
#22 lore raw

Re: [PATCH 10/15] scsi: core: Introduce scsi_get_sector()

Quoted 7 lines · Martin K. Petersen
Quoted 3 lines

Wondering a bit why this still uses the request pointer, after you say in patch 01 that it goes away. So it should probably use blk_mq_rq_from_pdu()?

I was just getting everything ready for Bart's series that makes this change throughout the tree.

Ah ok, didn't realize that.

Signature · 4 lines
Best Regards, Benjamin Block  / Linux on IBM Z Kernel Development / IBM Systems
IBM Deutschland Research & Development GmbH    /    https://www.ibm.com/privacy
Vorsitz. AufsR.: Gregor Pillen         /        Geschäftsführung: Dirk Wittkopp
Sitz der Gesellschaft: Böblingen / Registergericht: AmtsG Stuttgart, HRB 243294
#23 lore raw

PATCH 11/15 scsi: iser: Use scsi_get_sector() instead of scsi_get_lba()

In reply to Martin K. Petersen

From: Bart Van Assche <[email protected]>

Use scsi_get_sector() instead of scsi_get_lba() since the name of the latter is confusing. This patch does not change any functionality.

---
 drivers/infiniband/ulp/iser/iser_verbs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/ulp/iser/iser_verbs.c +1 -1
index 136f6c4492e0..d6bbf1bf428c 100644
@@ -949,7 +949,7 @@ u8 iser_check_task_pi_status(struct iscsi_iser_task *iser_task,
 			sector_t sector_off = mr_status.sig_err.sig_err_offset;
 
 			sector_div(sector_off, sector_size + 8);
-			*sector = scsi_get_lba(iser_task->sc) + sector_off;
+			*sector = scsi_get_sector(iser_task->sc) + sector_off;
 
 			iser_err("PI error found type %d at sector %llx "
 			       "expected %x vs actual %x\n",
Signature · 1 line
2.31.1
#24 lore raw

PATCH 12/15 scsi: core: Make scsi_get_lba() return the LBA

In reply to Martin K. Petersen

scsi_get_lba() confusingly returned the block layer sector number expressed in units of 512 bytes. Now that we have a more aptly named scsi_get_sector() function, make scsi_get_lba() return the actual LBA.

---
 include/scsi/scsi_cmnd.h | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
include/scsi/scsi_cmnd.h +7 -5
index cba63377d46a..90da9617d28a 100644
@@ -225,6 +225,13 @@ static inline sector_t scsi_get_sector(struct scsi_cmnd *scmd)
 	return blk_rq_pos(scmd->request);
 }
 
+static inline sector_t scsi_get_lba(struct scsi_cmnd *scmd)
+{
+	unsigned int shift = ilog2(scmd->device->sector_size) - SECTOR_SHIFT;
+
+	return blk_rq_pos(scmd->request) >> shift;
+}
+
 /*
  * The operations below are hints that tell the controller driver how
  * to handle I/Os with DIF or similar types of protection information.
@@ -287,11 +294,6 @@ static inline unsigned char scsi_get_prot_type(struct scsi_cmnd *scmd)
 	return scmd->prot_type;
 }
 
-static inline sector_t scsi_get_lba(struct scsi_cmnd *scmd)
-{
-	return blk_rq_pos(scmd->request);
-}
-
 static inline u32 scsi_prot_ref_tag(struct scsi_cmnd *scmd)
 {
 	struct request *rq = blk_mq_rq_from_pdu(scmd);
Signature · 1 line
2.31.1
Reviewed-by on v1 12/15
#25 lore raw

Re: [PATCH 12/15] scsi: core: Make scsi_get_lba() return the LBA

Quoted 3 lines · Martin K. Petersen

scsi_get_lba() confusingly returned the block layer sector number expressed in units of 512 bytes. Now that we have a more aptly named scsi_get_sector() function, make scsi_get_lba() return the actual LBA.

#26 lore raw

Re: [PATCH 12/15] scsi: core: Make scsi_get_lba() return the LBA

In reply to Martin K. Petersen
Quoted 14 lines · Martin K. Petersen

scsi_get_lba() confusingly returned the block layer sector number expressed in units of 512 bytes. Now that we have a more aptly named scsi_get_sector() function, make scsi_get_lba() return the actual LBA.

---
 include/scsi/scsi_cmnd.h | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
include/scsi/scsi_cmnd.h +0 -0
index cba63377d46a..90da9617d28a 100644

include/scsi/scsi_cmnd.h static inline sector_t scsi_get_sector(struct scsi_cmnd *scmd) · line 232

Quoted 8 lines
include/scsi/scsi_cmnd.h +5 -0
@@ -225,6 +225,13 @@ static inline sector_t scsi_get_sector(struct scsi_cmnd *scmd)
 	return blk_rq_pos(scmd->request);
 }
 
+static inline sector_t scsi_get_lba(struct scsi_cmnd *scmd)
+{
+	unsigned int shift = ilog2(scmd->device->sector_size) - SECTOR_SHIFT;
+
+	return blk_rq_pos(scmd->request) >> shift;

Hmm again, should it use blk_mq_rq_from_pdu()?

Signature · 4 lines
Best Regards, Benjamin Block  / Linux on IBM Z Kernel Development / IBM Systems
IBM Deutschland Research & Development GmbH    /    https://www.ibm.com/privacy
Vorsitz. AufsR.: Gregor Pillen         /        Geschäftsführung: Dirk Wittkopp
Sitz der Gesellschaft: Böblingen / Registergericht: AmtsG Stuttgart, HRB 243294
Reviewed-by
#27 lore raw

Re: [PATCH 12/15] scsi: core: Make scsi_get_lba() return the LBA

Quoted 18 lines · Benjamin Block
Quoted 17 lines · Martin K. Petersen

scsi_get_lba() confusingly returned the block layer sector number expressed in units of 512 bytes. Now that we have a more aptly named scsi_get_sector() function, make scsi_get_lba() return the actual LBA.

---
 include/scsi/scsi_cmnd.h | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
include/scsi/scsi_cmnd.h +0 -0
index cba63377d46a..90da9617d28a 100644
@@ -225,6 +225,13 @@ static inline sector_t scsi_get_sector(struct scsi_cmnd *scmd)
 	return blk_rq_pos(scmd->request);
 }
 
Quoted 8 lines

include/scsi/scsi_cmnd.h static inline sector_t scsi_get_sector(struct scsi_cmnd *scmd) · line 232

Quoted 5 lines
include/scsi/scsi_cmnd.h +5 -0
+static inline sector_t scsi_get_lba(struct scsi_cmnd *scmd)
+{
+	unsigned int shift = ilog2(scmd->device->sector_size) - SECTOR_SHIFT;
+
+	return blk_rq_pos(scmd->request) >> shift;

Hmm again, should it use blk_mq_rq_from_pdu()?

I'm taking this is the same as with the other patch, Bart's series will replace that as well.

Signature · 4 lines
Best Regards, Benjamin Block  / Linux on IBM Z Kernel Development / IBM Systems
IBM Deutschland Research & Development GmbH    /    https://www.ibm.com/privacy
Vorsitz. AufsR.: Gregor Pillen         /        Geschäftsführung: Dirk Wittkopp
Sitz der Gesellschaft: Böblingen / Registergericht: AmtsG Stuttgart, HRB 243294
#28 lore raw

PATCH 13/15 scsi: core: Add helper to return number of logical blocks in a request

In reply to Martin K. Petersen
---
 include/scsi/scsi_cmnd.h | 7 +++++++
 1 file changed, 7 insertions(+)
include/scsi/scsi_cmnd.h +7 -0
index 90da9617d28a..570719237f23 100644
@@ -232,6 +232,13 @@ static inline sector_t scsi_get_lba(struct scsi_cmnd *scmd)
 	return blk_rq_pos(scmd->request) >> shift;
 }
 
+static inline unsigned int scsi_get_block_count(struct scsi_cmnd *scmd)
+{
+	unsigned int shift = ilog2(scmd->device->sector_size) - SECTOR_SHIFT;
+
+	return blk_rq_bytes(scmd->request) >> shift;
+}
+
 /*
  * The operations below are hints that tell the controller driver how
  * to handle I/Os with DIF or similar types of protection information.
Signature · 1 line
2.31.1
#29 lore raw

Re: [PATCH 13/15] scsi: core: Add helper to return number of logical blocks in a request

include/scsi/scsi_cmnd.h static inline sector_t scsi_get_lba(struct scsi_cmnd *scmd) · line 240

Quoted 6 lines · Martin K. Petersen
include/scsi/scsi_cmnd.h +6 -0
+static inline unsigned int scsi_get_block_count(struct scsi_cmnd *scmd)
+{
+	unsigned int shift = ilog2(scmd->device->sector_size) - SECTOR_SHIFT;
+
+	return blk_rq_bytes(scmd->request) >> shift;
+}

I think we either need a comment above this function that explains that the return value is a number of logical blocks or to change the function name to make the meaning of the return value clear.

Thanks,

Bart.

#30 lore raw

Re: [PATCH 13/15] scsi: core: Add helper to return number of logical blocks in a request

Hi Bart!

Quoted 11 lines · Martin K. Petersen

include/scsi/scsi_cmnd.h static inline sector_t scsi_get_lba(struct scsi_cmnd *scmd) · line 240

Quoted 6 lines
include/scsi/scsi_cmnd.h +6 -0
+static inline unsigned int scsi_get_block_count(struct scsi_cmnd *scmd)
+{
+	unsigned int shift = ilog2(scmd->device->sector_size) - SECTOR_SHIFT;
+
+	return blk_rq_bytes(scmd->request) >> shift;
+}

I think we either need a comment above this function that explains that the return value is a number of logical blocks or to change the function name to make the meaning of the return value clear.

I went with the scsi_get_ prefix to match the scsi_get_sectors() and scsi_get_lba() calls. Felt that "block" would suffice but I could make it scsi_logical_block_count() if you prefer?

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
#31 lore raw

Re: [PATCH 13/15] scsi: core: Add helper to return number of logical blocks in a request

Quoted 12 lines · Martin K. Petersen
Quoted 11 lines · Martin K. Petersen

include/scsi/scsi_cmnd.h static inline sector_t scsi_get_lba(struct scsi_cmnd *scmd) · line 240

Quoted 6 lines
include/scsi/scsi_cmnd.h +6 -0
+static inline unsigned int scsi_get_block_count(struct scsi_cmnd *scmd)
+{
+	unsigned int shift = ilog2(scmd->device->sector_size) - SECTOR_SHIFT;
+
+	return blk_rq_bytes(scmd->request) >> shift;
+}

I think we either need a comment above this function that explains that the return value is a number of logical blocks or to change the function name to make the meaning of the return value clear.

Quoted 3 lines

I went with the scsi_get_ prefix to match the scsi_get_sectors() and scsi_get_lba() calls. Felt that "block" would suffice but I could make it scsi_logical_block_count() if you prefer?

The name scsi_logical_block_count() sounds fine to me :-)

Thanks,

Bart.

#32 lore raw

PATCH 14/15 scsi: lpfc: Switch to scsi_get_block_count()

In reply to Martin K. Petersen

Use scsi_get_block_count() for places where the I/O size needs to be expressed in units of the logical block size.

---
 drivers/scsi/lpfc/lpfc_scsi.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
drivers/scsi/lpfc/lpfc_scsi.c +12 -12
index ca2e00e512f4..5f19eccaad24 100644
@@ -2959,7 +2959,7 @@ lpfc_sli4_parse_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd,
 				" 0x%x lba 0x%llx blk cnt 0x%x "
 				"bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
 				(unsigned long long)scsi_get_lba(cmd),
-				blk_rq_sectors(cmd->request), bgstat, bghm);
+				scsi_get_block_count(cmd), bgstat, bghm);
 	}
 
 	if (lpfc_bgs_get_reftag_err(bgstat)) {
@@ -2974,7 +2974,7 @@ lpfc_sli4_parse_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd,
 				" 0x%x lba 0x%llx blk cnt 0x%x "
 				"bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
 				(unsigned long long)scsi_get_lba(cmd),
-				blk_rq_sectors(cmd->request), bgstat, bghm);
+				scsi_get_block_count(cmd), bgstat, bghm);
 	}
 
 	if (lpfc_bgs_get_apptag_err(bgstat)) {
@@ -2989,7 +2989,7 @@ lpfc_sli4_parse_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd,
 				" 0x%x lba 0x%llx blk cnt 0x%x "
 				"bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
 				(unsigned long long)scsi_get_lba(cmd),
-				blk_rq_sectors(cmd->request), bgstat, bghm);
+				scsi_get_block_count(cmd), bgstat, bghm);
 	}
 
 	if (lpfc_bgs_get_hi_water_mark_present(bgstat)) {
@@ -3033,7 +3033,7 @@ lpfc_sli4_parse_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd,
 				" 0x%x lba 0x%llx blk cnt 0x%x "
 				"bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
 				(unsigned long long)scsi_get_lba(cmd),
-				blk_rq_sectors(cmd->request), bgstat, bghm);
+				scsi_get_block_count(cmd), bgstat, bghm);
 
 		/* Calcuate what type of error it was */
 		lpfc_calc_bg_err(phba, lpfc_cmd);
@@ -3071,7 +3071,7 @@ lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd,
 				"0x%x reftag 0x%x blk cnt 0x%x "
 				"bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
 				scsi_prot_ref_tag(cmd),
-				blk_rq_sectors(cmd->request), bgstat, bghm);
+				scsi_get_block_count(cmd), bgstat, bghm);
 		ret = (-1);
 		goto out;
 	}
@@ -3083,7 +3083,7 @@ lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd,
 				"0x%x reftag 0x%x blk cnt 0x%x "
 				"bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
 				scsi_prot_ref_tag(cmd),
-				blk_rq_sectors(cmd->request), bgstat, bghm);
+				scsi_get_block_count(cmd), bgstat, bghm);
 		ret = (-1);
 		goto out;
 	}
@@ -3099,7 +3099,7 @@ lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd,
 				"0x%x reftag 0x%x blk cnt 0x%x "
 				"bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
 				scsi_prot_ref_tag(cmd),
-				blk_rq_sectors(cmd->request), bgstat, bghm);
+				scsi_get_block_count(cmd), bgstat, bghm);
 	}
 
 	if (lpfc_bgs_get_reftag_err(bgstat)) {
@@ -3114,7 +3114,7 @@ lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd,
 				"0x%x reftag 0x%x blk cnt 0x%x "
 				"bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
 				scsi_prot_ref_tag(cmd),
-				blk_rq_sectors(cmd->request), bgstat, bghm);
+				scsi_get_block_count(cmd), bgstat, bghm);
 	}
 
 	if (lpfc_bgs_get_apptag_err(bgstat)) {
@@ -3129,7 +3129,7 @@ lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd,
 				"0x%x reftag 0x%x blk cnt 0x%x "
 				"bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
 				scsi_prot_ref_tag(cmd),
-				blk_rq_sectors(cmd->request), bgstat, bghm);
+				scsi_get_block_count(cmd), bgstat, bghm);
 	}
 
 	if (lpfc_bgs_get_hi_water_mark_present(bgstat)) {
@@ -3173,7 +3173,7 @@ lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd,
 				"0x%x reftag 0x%x blk cnt 0x%x "
 				"bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
 				scsi_prot_ref_tag(cmd),
-				blk_rq_sectors(cmd->request), bgstat, bghm);
+				scsi_get_block_count(cmd), bgstat, bghm);
 
 		/* Calcuate what type of error it was */
 		lpfc_calc_bg_err(phba, lpfc_cmd);
@@ -5261,7 +5261,7 @@ lpfc_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *cmnd)
 					 dif_op_str[scsi_get_prot_op(cmnd)],
 					 cmnd->cmnd[0],
 					 scsi_prot_ref_tag(cmnd),
-					 blk_rq_sectors(cmnd->request),
+					 scsi_get_block_count(cmnd),
 					 (cmnd->cmnd[1]>>5));
 		}
 		err = lpfc_bg_scsi_prep_dma_buf(phba, lpfc_cmd);
@@ -5273,7 +5273,7 @@ lpfc_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *cmnd)
 					 "x%x reftag x%x cnt %u pt %x\n",
 					 cmnd->cmnd[0],
 					 scsi_prot_ref_tag(cmnd),
-					 blk_rq_sectors(cmnd->request),
+					 scsi_get_block_count(cmnd),
 					 (cmnd->cmnd[1]>>5));
 		}
 		err = lpfc_scsi_prep_dma_buf(phba, lpfc_cmd);
Signature · 1 line
2.31.1
#33 lore raw

PATCH 15/15 scsi: ufs: core: Use scsi_get_lba() to get LBA

In reply to Martin K. Petersen

Use the scsi_get_lba() helper instead of a function internal to the SCSI disk driver. Remove #include "sd.h".

---
 drivers/scsi/ufs/ufshcd.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/scsi/ufs/ufshcd.c +1 -2
index fe1b5f4b586a..beb52245554f 100644
@@ -25,7 +25,6 @@
 #include "ufs_bsg.h"
 #include "ufshcd-crypto.h"
 #include <asm/unaligned.h>
-#include "../sd.h"
 
 #define CREATE_TRACE_POINTS
 #include <trace/events/ufs.h>
@@ -390,7 +389,7 @@ static void ufshcd_add_command_trace(struct ufs_hba *hba, unsigned int tag,
 	/* trace UPIU also */
 	ufshcd_add_cmd_upiu_trace(hba, tag, str_t);
 	opcode = cmd->cmnd[0];
-	lba = sectors_to_logical(cmd->device, blk_rq_pos(cmd->request));
+	lba = scsi_get_lba(cmd);
 
 	if (opcode == READ_10 || opcode == WRITE_10) {
 		/*
Signature · 1 line
2.31.1
Reviewed-by on v1 15/15
#34 lore raw

Re: [PATCH 15/15] scsi: ufs: core: Use scsi_get_lba() to get LBA

Quoted 2 lines · Martin K. Petersen

Use the scsi_get_lba() helper instead of a function internal to the SCSI disk driver. Remove #include "sd.h".

#35 lore raw
In reply to Martin K. Petersen
Quoted 5 lines · Martin K. Petersen

This series cleans up how low-level device drivers go about handling protection information. The SCSI midlayer provides a set of flags and helpers but not all drivers currently use them. This series updates the drivers to use the proper calls to query things like the protection interval, reference tag seed value, etc.

Hi Martin,

Do you plan to queue or repost this patch series?

Thanks,

Bart.

#36 lore raw

Bart,

Quoted 1 line

Do you plan to queue or repost this patch series?

Yes. Still haven't pushed my 5.15 tree because I had several issues with -rc1, including the configfs bug which broke most of my test setup. I am rebasing to -rc2.

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
#37 lore raw
Quoted 2 lines · Martin K. Petersen

Yes. Still haven't pushed my 5.15 tree because I had several issues with -rc1, including the configfs bug which broke most of my test setup.

Hi Martin,

To test my configfs patch I used LIO scripts that I wrote many years ago. It was only after I received a bug report that I realized that these scripts only write configfs attributes but do not read any configfs attribute. The configfs breakage shouldn't have happened but this explains how read testing got overlooked.

Bart.

author Applied
#38 lore raw
In reply to Martin K. Petersen
Quoted 6 lines · Martin K. Petersen

This series cleans up how low-level device drivers go about handling protection information. The SCSI midlayer provides a set of flags and helpers but not all drivers currently use them. This series updates the drivers to use the proper calls to query things like the protection interval, reference tag seed value, etc.

Quoted 6 lines

In addition scsi_debug is enhanced to validate and store protection information the same way as a regular PI-capable disk drive or SSD. With these changes scsi_debug is now able to pass the same PI qualification tests as physical hardware.

[...]

Applied to 5.15/scsi-queue, thanks!

[01/15] scsi: core: Add scsi_prot_ref_tag() helper

        https://git.kernel.org/mkp/scsi/c/7ba46799d346
[03/15] scsi: qla2xxx: Use the proper SCSI midlayer interfaces for PI
        https://git.kernel.org/mkp/scsi/c/e2e9cd68fb3c
[06/15] scsi: zfcp: Use the proper SCSI midlayer interfaces for PI
        https://git.kernel.org/mkp/scsi/c/73e61d5c22bf
[08/15] scsi: scsi_debug: Remove dump_sector()
        https://git.kernel.org/mkp/scsi/c/c78be80d20cd
[09/15] scsi: scsi_debug: Improve RDPROTECT/WRPROTECT handling
        https://git.kernel.org/mkp/scsi/c/f7be677227a5
[10/15] scsi: core: Introduce scsi_get_sector()
        https://git.kernel.org/mkp/scsi/c/f0f214fe8cd3
[11/15] scsi: iser: Use scsi_get_sector() instead of scsi_get_lba()
        https://git.kernel.org/mkp/scsi/c/87662a472a9d
[12/15] scsi: core: Make scsi_get_lba() return the LBA
        https://git.kernel.org/mkp/scsi/c/d2c945f01d23
[15/15] scsi: ufs: core: Use scsi_get_lba() to get LBA
        https://git.kernel.org/mkp/scsi/c/54815088859f
Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering