From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from omzsmtpe03.verizonbusiness.com ([199.249.25.208]:9345 "EHLO omzsmtpe03.verizonbusiness.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753054AbdDDTcl (ORCPT ); Tue, 4 Apr 2017 15:32:41 -0400 From: alexander.levin@verizon.com To: "gregkh@linuxfoundation.org" CC: "stable@vger.kernel.org" Subject: [PATCH for 4.9 09/98] scsi: ufs: introduce UFSHCD_QUIRK_PRDT_BYTE_GRAN quirk Date: Tue, 4 Apr 2017 19:32:05 +0000 Message-ID: <20170404193158.19041-10-alexander.levin@verizon.com> References: <20170404193158.19041-1-alexander.levin@verizon.com> In-Reply-To: <20170404193158.19041-1-alexander.levin@verizon.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Kiwoong Kim [ Upstream commit 75b1cc4ad63afa28c1a045b5157c008f405f06a9 ] Some UFS host controllers may think granularities of PRDT length and offset as bytes, not double words. Signed-off-by: Kiwoong Kim Reviewed-by: Subhash Jadavani Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/ufs/ufshcd.c | 28 +++++++++++++++++++++------- drivers/scsi/ufs/ufshcd.h | 6 ++++++ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 05c7456..b89618f 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -1088,7 +1088,7 @@ ufshcd_send_uic_cmd(struct ufs_hba *hba, struct uic_c= ommand *uic_cmd) * * Returns 0 in case of success, non-zero value in case of failure */ -static int ufshcd_map_sg(struct ufshcd_lrb *lrbp) +static int ufshcd_map_sg(struct ufs_hba *hba, struct ufshcd_lrb *lrbp) { struct ufshcd_sg_entry *prd_table; struct scatterlist *sg; @@ -1102,8 +1102,13 @@ static int ufshcd_map_sg(struct ufshcd_lrb *lrbp) return sg_segments; =20 if (sg_segments) { - lrbp->utr_descriptor_ptr->prd_table_length =3D - cpu_to_le16((u16) (sg_segments)); + if (hba->quirks & UFSHCD_QUIRK_PRDT_BYTE_GRAN) + lrbp->utr_descriptor_ptr->prd_table_length =3D + cpu_to_le16((u16)(sg_segments * + sizeof(struct ufshcd_sg_entry))); + else + lrbp->utr_descriptor_ptr->prd_table_length =3D + cpu_to_le16((u16) (sg_segments)); =20 prd_table =3D (struct ufshcd_sg_entry *)lrbp->ucd_prdt_ptr; =20 @@ -1465,7 +1470,7 @@ static int ufshcd_queuecommand(struct Scsi_Host *host= , struct scsi_cmnd *cmd) =20 ufshcd_comp_scsi_upiu(hba, lrbp); =20 - err =3D ufshcd_map_sg(lrbp); + err =3D ufshcd_map_sg(hba, lrbp); if (err) { lrbp->cmd =3D NULL; clear_bit_unlock(tag, &hba->lrb_in_use); @@ -2320,12 +2325,21 @@ static void ufshcd_host_memory_configure(struct ufs= _hba *hba) cpu_to_le32(upper_32_bits(cmd_desc_element_addr)); =20 /* Response upiu and prdt offset should be in double words */ - utrdlp[i].response_upiu_offset =3D + if (hba->quirks & UFSHCD_QUIRK_PRDT_BYTE_GRAN) { + utrdlp[i].response_upiu_offset =3D + cpu_to_le16(response_offset); + utrdlp[i].prd_table_offset =3D + cpu_to_le16(prdt_offset); + utrdlp[i].response_upiu_length =3D + cpu_to_le16(ALIGNED_UPIU_SIZE); + } else { + utrdlp[i].response_upiu_offset =3D cpu_to_le16((response_offset >> 2)); - utrdlp[i].prd_table_offset =3D + utrdlp[i].prd_table_offset =3D cpu_to_le16((prdt_offset >> 2)); - utrdlp[i].response_upiu_length =3D + utrdlp[i].response_upiu_length =3D cpu_to_le16(ALIGNED_UPIU_SIZE >> 2); + } =20 hba->lrb[i].utr_descriptor_ptr =3D (utrdlp + i); hba->lrb[i].ucd_req_ptr =3D diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h index 430bef1..5b65441 100644 --- a/drivers/scsi/ufs/ufshcd.h +++ b/drivers/scsi/ufs/ufshcd.h @@ -474,6 +474,12 @@ struct ufs_hba { */ #define UFSHCD_QUIRK_BROKEN_UFS_HCI_VERSION UFS_BIT(5) =20 + /* + * This quirk needs to be enabled if the host contoller regards + * resolution of the values of PRDTO and PRDTL in UTRD as byte. + */ + #define UFSHCD_QUIRK_PRDT_BYTE_GRAN UFS_BIT(7) + unsigned int quirks; /* Deviations from standard UFSHCI spec. */ =20 /* Device deviations from standard UFS device spec. */ --=20 2.9.3