scsi: ufs: core: Micro-optimize ufshcd_map_sg()
authorBart Van Assche <bvanassche@acm.org>
Wed, 20 Oct 2021 21:40:24 +0000 (14:40 -0700)
committerMartin K. Petersen <martin.petersen@oracle.com>
Wed, 27 Oct 2021 03:24:50 +0000 (23:24 -0400)
Replace two cpu_to_le32() calls by a single cpu_to_le64() call.

Additionally, issue a warning if the length of an scatter gather list
element exceeds what is allowed by the UFSHCI specification.

Link: https://lore.kernel.org/r/20211020214024.2007615-11-bvanassche@acm.org
Acked-by: Avri Altman <Avri.Altman@wdc.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/ufs/ufshcd.c
drivers/scsi/ufs/ufshci.h

index dde4d3f607f23f67d8ecb73a1cf3ec89b2bf2922..04cb67995750a270337caf4e5b1c3775101891e5 100644 (file)
@@ -2379,12 +2379,19 @@ static int ufshcd_map_sg(struct ufs_hba *hba, struct ufshcd_lrb *lrbp)
                prd_table = lrbp->ucd_prdt_ptr;
 
                scsi_for_each_sg(cmd, sg, sg_segments, i) {
-                       prd_table[i].size  =
-                               cpu_to_le32(((u32) sg_dma_len(sg))-1);
-                       prd_table[i].base_addr =
-                               cpu_to_le32(lower_32_bits(sg->dma_address));
-                       prd_table[i].upper_addr =
-                               cpu_to_le32(upper_32_bits(sg->dma_address));
+                       const unsigned int len = sg_dma_len(sg);
+
+                       /*
+                        * From the UFSHCI spec: "Data Byte Count (DBC): A '0'
+                        * based value that indicates the length, in bytes, of
+                        * the data block. A maximum of length of 256KB may
+                        * exist for any entry. Bits 1:0 of this field shall be
+                        * 11b to indicate Dword granularity. A value of '3'
+                        * indicates 4 bytes, '7' indicates 8 bytes, etc."
+                        */
+                       WARN_ONCE(len > 256 * 1024, "len = %#x\n", len);
+                       prd_table[i].size = cpu_to_le32(len - 1);
+                       prd_table[i].addr = cpu_to_le64(sg->dma_address);
                        prd_table[i].reserved = 0;
                }
        } else {
index f66cf9e477cb864a80e312b2500e6d5f39cb68d7..6a295c88d850f840eeaa36daf16f388f55a77ea2 100644 (file)
@@ -415,14 +415,12 @@ enum {
 
 /**
  * struct ufshcd_sg_entry - UFSHCI PRD Entry
- * @base_addr: Lower 32bit physical address DW-0
- * @upper_addr: Upper 32bit physical address DW-1
+ * @addr: Physical address; DW-0 and DW-1.
  * @reserved: Reserved for future use DW-2
  * @size: size of physical segment DW-3
  */
 struct ufshcd_sg_entry {
-       __le32    base_addr;
-       __le32    upper_addr;
+       __le64    addr;
        __le32    reserved;
        __le32    size;
 };