diff mbox series

[3/3] scsi: ufs: core: Add exception event handler to implicitly handle WB buffer resize event

Message ID 20230907094517.1961-1-luhongfei@vivo.com
State Superseded
Headers show
Series None | expand

Commit Message

Lu Hongfei Sept. 7, 2023, 9:44 a.m. UTC
The WRITEBOOSTER_RESIZE_HINT event mechanism is enabled by
setting the WRITEBOOSTER_RESIZE_HINT_EN bit of the
wExceptionEventControl attribute.

The pre-conditions for enabling it include:
    1. WB enable
    2. Wb is in preserving user space mode
    3. UFS version not less than 4.1
    4. Host driver allows it to be opened

After enabled, when there is a recommendation about resize
for the WB Buffer, the device inform the host by the
WRITEBOOSTER_RESIZE_HINT exception mechanism.

Host driver will call ufshcd_wb_resize_exception_event_handler
to handle the exception event.

Signed-off-by: Lu Hongfei <luhongfei@vivo.com>
---
 drivers/ufs/core/ufshcd.c | 41 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
 mode change 100644 => 100755 drivers/ufs/core/ufshcd.c

Comments

kernel test robot Sept. 7, 2023, 10:57 p.m. UTC | #1
Hi Lu,

kernel test robot noticed the following build errors:

[auto build test ERROR on mkp-scsi/for-next]
[also build test ERROR on jejb-scsi/for-next linus/master v6.5 next-20230907]
[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/Lu-Hongfei/scsi-ufs-core-allow-host-driver-to-enable-wb-buffer-resize-function/20230907-234105
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git for-next
patch link:    https://lore.kernel.org/r/20230907094517.1961-1-luhongfei%40vivo.com
patch subject: [PATCH 3/3] scsi: ufs: core: Add exception event handler to implicitly handle WB buffer resize event
config: hexagon-randconfig-002-20230908 (https://download.01.org/0day-ci/archive/20230908/202309080646.NhYcVypx-lkp@intel.com/config)
compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project.git 4a5ac14ee968ff0ad5d2cc1ffa0299048db4c88a)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20230908/202309080646.NhYcVypx-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/202309080646.NhYcVypx-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from drivers/ufs/core/ufshcd.c:18:
   In file included from include/linux/blkdev.h:9:
   In file included from include/linux/blk_types.h:10:
   In file included from include/linux/bvec.h:10:
   In file included from include/linux/highmem.h:12:
   In file included from include/linux/hardirq.h:11:
   In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
   In file included from include/asm-generic/hardirq.h:17:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/hexagon/include/asm/io.h:334:
   include/asm-generic/io.h:547:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     547 |         val = __raw_readb(PCI_IOBASE + addr);
         |                           ~~~~~~~~~~ ^
   include/asm-generic/io.h:560:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     560 |         val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr));
         |                                                         ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/little_endian.h:37:51: note: expanded from macro '__le16_to_cpu'
      37 | #define __le16_to_cpu(x) ((__force __u16)(__le16)(x))
         |                                                   ^
   In file included from drivers/ufs/core/ufshcd.c:18:
   In file included from include/linux/blkdev.h:9:
   In file included from include/linux/blk_types.h:10:
   In file included from include/linux/bvec.h:10:
   In file included from include/linux/highmem.h:12:
   In file included from include/linux/hardirq.h:11:
   In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
   In file included from include/asm-generic/hardirq.h:17:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/hexagon/include/asm/io.h:334:
   include/asm-generic/io.h:573:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     573 |         val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
         |                                                         ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/little_endian.h:35:51: note: expanded from macro '__le32_to_cpu'
      35 | #define __le32_to_cpu(x) ((__force __u32)(__le32)(x))
         |                                                   ^
   In file included from drivers/ufs/core/ufshcd.c:18:
   In file included from include/linux/blkdev.h:9:
   In file included from include/linux/blk_types.h:10:
   In file included from include/linux/bvec.h:10:
   In file included from include/linux/highmem.h:12:
   In file included from include/linux/hardirq.h:11:
   In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
   In file included from include/asm-generic/hardirq.h:17:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/hexagon/include/asm/io.h:334:
   include/asm-generic/io.h:584:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     584 |         __raw_writeb(value, PCI_IOBASE + addr);
         |                             ~~~~~~~~~~ ^
   include/asm-generic/io.h:594:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     594 |         __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
         |                                                       ~~~~~~~~~~ ^
   include/asm-generic/io.h:604:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     604 |         __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
         |                                                       ~~~~~~~~~~ ^
>> drivers/ufs/core/ufshcd.c:322:19: error: member reference type 'struct ufs_dev_info' is not a pointer; did you mean to use '.'?
     322 |         if (hba->dev_info->wspecversion >= 0x410
         |             ~~~~~~~~~~~~~^~
         |                          .
   drivers/ufs/core/ufshcd.c:323:22: error: member reference type 'struct ufs_dev_info' is not a pointer; did you mean to use '.'?
     323 |             && hba->dev_info->b_presrv_uspc_en
         |                ~~~~~~~~~~~~~^~
         |                             .
>> drivers/ufs/core/ufshcd.c:326:3: error: call to undeclared function 'ufshcd_enable_ee'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     326 |                 ufshcd_enable_ee(hba, mask);
         |                 ^
   drivers/ufs/core/ufshcd.c:326:3: note: did you mean 'ufshcd_enable_irq'?
   drivers/ufs/core/ufshcd.c:291:20: note: 'ufshcd_enable_irq' declared here
     291 | static inline void ufshcd_enable_irq(struct ufs_hba *hba)
         |                    ^
>> drivers/ufs/core/ufshcd.c:5642:19: error: static declaration of 'ufshcd_enable_ee' follows non-static declaration
    5642 | static inline int ufshcd_enable_ee(struct ufs_hba *hba, u16 mask)
         |                   ^
   drivers/ufs/core/ufshcd.c:326:3: note: previous implicit declaration is here
     326 |                 ufshcd_enable_ee(hba, mask);
         |                 ^
   drivers/ufs/core/ufshcd.c:10216:44: warning: shift count >= width of type [-Wshift-count-overflow]
    10216 |                 if (!dma_set_mask_and_coherent(hba->dev, DMA_BIT_MASK(64)))
          |                                                          ^~~~~~~~~~~~~~~~
   include/linux/dma-mapping.h:77:54: note: expanded from macro 'DMA_BIT_MASK'
      77 | #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
         |                                                      ^ ~~~
   7 warnings and 4 errors generated.


vim +322 drivers/ufs/core/ufshcd.c

   306	
   307	static void ufshcd_configure_wb(struct ufs_hba *hba)
   308	{
   309		u16 mask = 0;
   310	
   311		if (!ufshcd_is_wb_allowed(hba))
   312			return;
   313	
   314		ufshcd_wb_toggle(hba, true);
   315	
   316		ufshcd_wb_toggle_buf_flush_during_h8(hba, true);
   317	
   318		if (ufshcd_is_wb_buf_flush_allowed(hba))
   319			ufshcd_wb_toggle_buf_flush(hba, true);
   320	
   321		/* Enable the WRITEBOOSTER_RESIZE_HINT exception mechanism. */
 > 322		if (hba->dev_info->wspecversion >= 0x410
   323		    && hba->dev_info->b_presrv_uspc_en
   324		    && ufshcd_is_wb_buf_resize_allowed(hba)) {
   325			mask |= MASK_EE_WRITEBOOSTER_RESIZE_HINT;
 > 326			ufshcd_enable_ee(hba, mask);
   327		}
   328	}
   329
kernel test robot Sept. 7, 2023, 11:20 p.m. UTC | #2
Hi Lu,

kernel test robot noticed the following build errors:

[auto build test ERROR on mkp-scsi/for-next]
[also build test ERROR on jejb-scsi/for-next linus/master v6.5 next-20230907]
[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/Lu-Hongfei/scsi-ufs-core-allow-host-driver-to-enable-wb-buffer-resize-function/20230907-234105
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git for-next
patch link:    https://lore.kernel.org/r/20230907094517.1961-1-luhongfei%40vivo.com
patch subject: [PATCH 3/3] scsi: ufs: core: Add exception event handler to implicitly handle WB buffer resize event
config: x86_64-randconfig-r036-20230908 (https://download.01.org/0day-ci/archive/20230908/202309080739.i8Muq8IT-lkp@intel.com/config)
compiler: gcc-7 (Ubuntu 7.5.0-6ubuntu2) 7.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20230908/202309080739.i8Muq8IT-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/202309080739.i8Muq8IT-lkp@intel.com/

All errors (new ones prefixed by >>):

   drivers/ufs/core/ufshcd.c: In function 'ufshcd_configure_wb':
   drivers/ufs/core/ufshcd.c:322:19: error: invalid type argument of '->' (have 'struct ufs_dev_info')
     if (hba->dev_info->wspecversion >= 0x410
                      ^~
   drivers/ufs/core/ufshcd.c:323:22: error: invalid type argument of '->' (have 'struct ufs_dev_info')
         && hba->dev_info->b_presrv_uspc_en
                         ^~
   drivers/ufs/core/ufshcd.c:326:3: error: implicit declaration of function 'ufshcd_enable_ee'; did you mean 'ufshcd_enable_irq'? [-Werror=implicit-function-declaration]
      ufshcd_enable_ee(hba, mask);
      ^~~~~~~~~~~~~~~~
      ufshcd_enable_irq
   drivers/ufs/core/ufshcd.c: At top level:
>> drivers/ufs/core/ufshcd.c:5642:19: error: conflicting types for 'ufshcd_enable_ee'
    static inline int ufshcd_enable_ee(struct ufs_hba *hba, u16 mask)
                      ^~~~~~~~~~~~~~~~
   drivers/ufs/core/ufshcd.c:5643:1: note: an argument type that has a default promotion can't match an empty parameter name list declaration
    {
    ^
   drivers/ufs/core/ufshcd.c:326:3: note: previous implicit declaration of 'ufshcd_enable_ee' was here
      ufshcd_enable_ee(hba, mask);
      ^~~~~~~~~~~~~~~~
   cc1: some warnings being treated as errors


vim +/ufshcd_enable_ee +5642 drivers/ufs/core/ufshcd.c

66ec6d59407baf drivers/scsi/ufs/ufshcd.c Sujit Reddy Thumma 2013-07-30  5631  
66ec6d59407baf drivers/scsi/ufs/ufshcd.c Sujit Reddy Thumma 2013-07-30  5632  /**
66ec6d59407baf drivers/scsi/ufs/ufshcd.c Sujit Reddy Thumma 2013-07-30  5633   * ufshcd_enable_ee - enable exception event
66ec6d59407baf drivers/scsi/ufs/ufshcd.c Sujit Reddy Thumma 2013-07-30  5634   * @hba: per-adapter instance
66ec6d59407baf drivers/scsi/ufs/ufshcd.c Sujit Reddy Thumma 2013-07-30  5635   * @mask: exception event to enable
66ec6d59407baf drivers/scsi/ufs/ufshcd.c Sujit Reddy Thumma 2013-07-30  5636   *
66ec6d59407baf drivers/scsi/ufs/ufshcd.c Sujit Reddy Thumma 2013-07-30  5637   * Enable corresponding exception event in the device to allow
66ec6d59407baf drivers/scsi/ufs/ufshcd.c Sujit Reddy Thumma 2013-07-30  5638   * device to alert host in critical scenarios.
66ec6d59407baf drivers/scsi/ufs/ufshcd.c Sujit Reddy Thumma 2013-07-30  5639   *
3a17fefe0f1960 drivers/ufs/core/ufshcd.c Bart Van Assche    2023-07-27  5640   * Return: zero on success, non-zero error value on failure.
66ec6d59407baf drivers/scsi/ufs/ufshcd.c Sujit Reddy Thumma 2013-07-30  5641   */
cd4694756188dc drivers/scsi/ufs/ufshcd.c Adrian Hunter      2021-02-09 @5642  static inline int ufshcd_enable_ee(struct ufs_hba *hba, u16 mask)
66ec6d59407baf drivers/scsi/ufs/ufshcd.c Sujit Reddy Thumma 2013-07-30  5643  {
cd4694756188dc drivers/scsi/ufs/ufshcd.c Adrian Hunter      2021-02-09  5644  	return ufshcd_update_ee_drv_mask(hba, mask, 0);
66ec6d59407baf drivers/scsi/ufs/ufshcd.c Sujit Reddy Thumma 2013-07-30  5645  }
66ec6d59407baf drivers/scsi/ufs/ufshcd.c Sujit Reddy Thumma 2013-07-30  5646
diff mbox series

Patch

diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index c2df07545f96..f15d14c46789
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -306,6 +306,8 @@  static inline void ufshcd_disable_irq(struct ufs_hba *hba)
 
 static void ufshcd_configure_wb(struct ufs_hba *hba)
 {
+	u16 mask = 0;
+
 	if (!ufshcd_is_wb_allowed(hba))
 		return;
 
@@ -315,6 +317,14 @@  static void ufshcd_configure_wb(struct ufs_hba *hba)
 
 	if (ufshcd_is_wb_buf_flush_allowed(hba))
 		ufshcd_wb_toggle_buf_flush(hba, true);
+
+	/* Enable the WRITEBOOSTER_RESIZE_HINT exception mechanism. */
+	if (hba->dev_info->wspecversion >= 0x410
+	    && hba->dev_info->b_presrv_uspc_en
+	    && ufshcd_is_wb_buf_resize_allowed(hba)) {
+		mask |= MASK_EE_WRITEBOOSTER_RESIZE_HINT;
+		ufshcd_enable_ee(hba, mask);
+	}
 }
 
 static void ufshcd_scsi_unblock_requests(struct ufs_hba *hba)
@@ -5868,6 +5878,34 @@  static void ufshcd_temp_exception_event_handler(struct ufs_hba *hba, u16 status)
 	 */
 }
 
+static void ufshcd_wb_resize_exception_event_handler(struct ufs_hba *hba, u16 status)
+{
+	u32 value;
+	int err;
+
+	if (!(status | MASK_EE_WRITEBOOSTER_RESIZE_HINT))
+		return;
+
+	if (ufshcd_query_attr_retry(hba, UPIU_QUERY_OPCODE_READ_ATTR,
+				QUERY_ATTR_IDN_WB_BUF_RESIZE_HINT, 0, 0, &value))
+		return;
+
+	dev_info(hba->dev, "WB Buffer Resize Hint info %u\n", value);
+	if (value != 0x01 && value != 0x02)
+		return;
+
+	if (ufshcd_wait_for_doorbell_clr(hba, 1 * USEC_PER_SEC))
+		return;
+
+	err = ufshcd_query_attr_retry(hba, UPIU_QUERY_OPCODE_WRITE_ATTR,
+		QUERY_ATTR_IDN_WB_BUF_RESIZE_EN, 0, 0, &value);
+
+	if (err) {
+		dev_err(hba->dev, "Issue %s WB buffer size cmd failed\n",
+				value == 0x01 ? "Decrease" : "Increase");
+	}
+}
+
 static int __ufshcd_wb_toggle(struct ufs_hba *hba, bool set, enum flag_idn idn)
 {
 	u8 index;
@@ -6091,6 +6129,9 @@  static void ufshcd_exception_event_handler(struct work_struct *work)
 	if (status & hba->ee_drv_mask & MASK_EE_URGENT_TEMP)
 		ufshcd_temp_exception_event_handler(hba, status);
 
+	if (status & hba->ee_drv_mask & MASK_EE_WRITEBOOSTER_RESIZE_HINT)
+		ufshcd_wb_resize_exception_event_handler(hba, status);
+
 	ufs_debugfs_exception_event(hba, status);
 out:
 	ufshcd_scsi_unblock_requests(hba);