diff mbox series

[v2,5/7] mpi3mr: Debug ability improvements

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

Commit Message

Ranjan Kumar March 7, 2024, 3:08 p.m. UTC
Driver updated to include OS type in fault/reset reason code.
MPI request sent through IOCTL now automatically dumped on timeout.

Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
Signed-off-by: Sathya Prakash <sathya.prakash@broadcom.com>
---
 drivers/scsi/mpi3mr/mpi3mr.h     |  6 +++++-
 drivers/scsi/mpi3mr/mpi3mr_app.c | 21 ++++++++++++++-------
 drivers/scsi/mpi3mr/mpi3mr_fw.c  | 21 ++++++++++++++-------
 3 files changed, 33 insertions(+), 15 deletions(-)

Comments

kernel test robot March 8, 2024, 11:40 a.m. UTC | #1
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.8-rc7 next-20240308]
[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-Block-devices-are-not-removed-from-OS-even-vd-s-are-offlined/20240307-231302
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git for-next
patch link:    https://lore.kernel.org/r/20240307150825.7613-6-ranjan.kumar%40broadcom.com
patch subject: [PATCH v2 5/7] mpi3mr: Debug ability improvements
config: microblaze-allmodconfig (https://download.01.org/0day-ci/archive/20240308/202403081903.q3Dq54zZ-lkp@intel.com/config)
compiler: microblaze-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240308/202403081903.q3Dq54zZ-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/202403081903.q3Dq54zZ-lkp@intel.com/

All warnings (new ones prefixed by >>):

   drivers/scsi/mpi3mr/mpi3mr_fw.c: In function 'mpi3mr_issue_reset':
>> drivers/scsi/mpi3mr/mpi3mr_fw.c:1531:54: warning: variable 'scratch_pad0' set but not used [-Wunused-but-set-variable]
    1531 |         u32 host_diagnostic, ioc_status, ioc_config, scratch_pad0;
         |                                                      ^~~~~~~~~~~~
   drivers/scsi/mpi3mr/mpi3mr_fw.c: In function 'mpi3mr_setup_isr':
   drivers/scsi/mpi3mr/mpi3mr_fw.c:732:58: warning: '%d' directive output may be truncated writing between 1 and 3 bytes into a region of size between 1 and 32 [-Wformat-truncation=]
     732 |         snprintf(intr_info->name, MPI3MR_NAME_LENGTH, "%s%d-msix%d",
         |                                                          ^~
   In function 'mpi3mr_request_irq',
       inlined from 'mpi3mr_setup_isr' at drivers/scsi/mpi3mr/mpi3mr_fw.c:857:12:
   drivers/scsi/mpi3mr/mpi3mr_fw.c:732:55: note: directive argument in the range [0, 255]
     732 |         snprintf(intr_info->name, MPI3MR_NAME_LENGTH, "%s%d-msix%d",
         |                                                       ^~~~~~~~~~~~~
   drivers/scsi/mpi3mr/mpi3mr_fw.c:732:55: note: directive argument in the range [0, 65535]
   drivers/scsi/mpi3mr/mpi3mr_fw.c:732:9: note: 'snprintf' output between 8 and 45 bytes into a destination of size 32
     732 |         snprintf(intr_info->name, MPI3MR_NAME_LENGTH, "%s%d-msix%d",
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     733 |             mrioc->driver_name, mrioc->id, index);
         |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/scsi/mpi3mr/mpi3mr_fw.c: In function 'mpi3mr_start_watchdog':
   drivers/scsi/mpi3mr/mpi3mr_fw.c:2690:60: warning: '%s' directive output may be truncated writing up to 31 bytes into a region of size 11 [-Wformat-truncation=]
    2690 |             sizeof(mrioc->watchdog_work_q_name), "watchdog_%s%d", mrioc->name,
         |                                                            ^~
   drivers/scsi/mpi3mr/mpi3mr_fw.c:2690:50: note: directive argument in the range [0, 255]
    2690 |             sizeof(mrioc->watchdog_work_q_name), "watchdog_%s%d", mrioc->name,
         |                                                  ^~~~~~~~~~~~~~~
   drivers/scsi/mpi3mr/mpi3mr_fw.c:2689:9: note: 'snprintf' output between 11 and 44 bytes into a destination of size 20
    2689 |         snprintf(mrioc->watchdog_work_q_name,
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    2690 |             sizeof(mrioc->watchdog_work_q_name), "watchdog_%s%d", mrioc->name,
         |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    2691 |             mrioc->id);
         |             ~~~~~~~~~~


vim +/scratch_pad0 +1531 drivers/scsi/mpi3mr/mpi3mr_fw.c

  1512	
  1513	/**
  1514	 * mpi3mr_issue_reset - Issue reset to the controller
  1515	 * @mrioc: Adapter reference
  1516	 * @reset_type: Reset type
  1517	 * @reset_reason: Reset reason code
  1518	 *
  1519	 * Unlock the host diagnostic registers and write the specific
  1520	 * reset type to that, wait for reset acknowledgment from the
  1521	 * controller, if the reset is not successful retry for the
  1522	 * predefined number of times.
  1523	 *
  1524	 * Return: 0 on success, non-zero on failure.
  1525	 */
  1526	static int mpi3mr_issue_reset(struct mpi3mr_ioc *mrioc, u16 reset_type,
  1527		u16 reset_reason)
  1528	{
  1529		int retval = -1;
  1530		u8 unlock_retry_count = 0;
> 1531		u32 host_diagnostic, ioc_status, ioc_config, scratch_pad0;
  1532		u32 timeout = MPI3MR_RESET_ACK_TIMEOUT * 10;
  1533	
  1534		if ((reset_type != MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET) &&
  1535		    (reset_type != MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT))
  1536			return retval;
  1537		if (mrioc->unrecoverable)
  1538			return retval;
  1539		if (reset_reason == MPI3MR_RESET_FROM_FIRMWARE) {
  1540			retval = 0;
  1541			return retval;
  1542		}
  1543	
  1544		ioc_info(mrioc, "%s reset due to %s(0x%x)\n",
  1545		    mpi3mr_reset_type_name(reset_type),
  1546		    mpi3mr_reset_rc_name(reset_reason), reset_reason);
  1547	
  1548		mpi3mr_clear_reset_history(mrioc);
  1549		do {
  1550			ioc_info(mrioc,
  1551			    "Write magic sequence to unlock host diag register (retry=%d)\n",
  1552			    ++unlock_retry_count);
  1553			if (unlock_retry_count >= MPI3MR_HOSTDIAG_UNLOCK_RETRY_COUNT) {
  1554				ioc_err(mrioc,
  1555				    "%s reset failed due to unlock failure, host_diagnostic(0x%08x)\n",
  1556				    mpi3mr_reset_type_name(reset_type),
  1557				    host_diagnostic);
  1558				mrioc->unrecoverable = 1;
  1559				return retval;
  1560			}
  1561	
  1562			writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_FLUSH,
  1563			    &mrioc->sysif_regs->write_sequence);
  1564			writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_1ST,
  1565			    &mrioc->sysif_regs->write_sequence);
  1566			writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_2ND,
  1567			    &mrioc->sysif_regs->write_sequence);
  1568			writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_3RD,
  1569			    &mrioc->sysif_regs->write_sequence);
  1570			writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_4TH,
  1571			    &mrioc->sysif_regs->write_sequence);
  1572			writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_5TH,
  1573			    &mrioc->sysif_regs->write_sequence);
  1574			writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_6TH,
  1575			    &mrioc->sysif_regs->write_sequence);
  1576			usleep_range(1000, 1100);
  1577			host_diagnostic = readl(&mrioc->sysif_regs->host_diagnostic);
  1578			ioc_info(mrioc,
  1579			    "wrote magic sequence: retry_count(%d), host_diagnostic(0x%08x)\n",
  1580			    unlock_retry_count, host_diagnostic);
  1581		} while (!(host_diagnostic & MPI3_SYSIF_HOST_DIAG_DIAG_WRITE_ENABLE));
  1582	
  1583		scratch_pad0 = ((MPI3MR_RESET_REASON_OSTYPE_LINUX <<
  1584		    MPI3MR_RESET_REASON_OSTYPE_SHIFT) | (mrioc->facts.ioc_num <<
  1585		    MPI3MR_RESET_REASON_IOCNUM_SHIFT) | reset_reason);
  1586		writel(reset_reason, &mrioc->sysif_regs->scratchpad[0]);
  1587		writel(host_diagnostic | reset_type,
  1588		    &mrioc->sysif_regs->host_diagnostic);
  1589		switch (reset_type) {
  1590		case MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET:
  1591			do {
  1592				ioc_status = readl(&mrioc->sysif_regs->ioc_status);
  1593				ioc_config =
  1594				    readl(&mrioc->sysif_regs->ioc_configuration);
  1595				if ((ioc_status & MPI3_SYSIF_IOC_STATUS_RESET_HISTORY)
  1596				    && mpi3mr_soft_reset_success(ioc_status, ioc_config)
  1597				    ) {
  1598					mpi3mr_clear_reset_history(mrioc);
  1599					retval = 0;
  1600					break;
  1601				}
  1602				msleep(100);
  1603			} while (--timeout);
  1604			mpi3mr_print_fault_info(mrioc);
  1605			break;
  1606		case MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT:
  1607			do {
  1608				ioc_status = readl(&mrioc->sysif_regs->ioc_status);
  1609				if (mpi3mr_diagfault_success(mrioc, ioc_status)) {
  1610					retval = 0;
  1611					break;
  1612				}
  1613				msleep(100);
  1614			} while (--timeout);
  1615			break;
  1616		default:
  1617			break;
  1618		}
  1619	
  1620		writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_2ND,
  1621		    &mrioc->sysif_regs->write_sequence);
  1622	
  1623		ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
  1624		ioc_status = readl(&mrioc->sysif_regs->ioc_status);
  1625		ioc_info(mrioc,
  1626		    "ioc_status/ioc_onfig after %s reset is (0x%x)/(0x%x)\n",
  1627		    (!retval)?"successful":"failed", ioc_status,
  1628		    ioc_config);
  1629		if (retval)
  1630			mrioc->unrecoverable = 1;
  1631		return retval;
  1632	}
  1633
diff mbox series

Patch

diff --git a/drivers/scsi/mpi3mr/mpi3mr.h b/drivers/scsi/mpi3mr/mpi3mr.h
index 06359915a48d..d7ee94aff67a 100644
--- a/drivers/scsi/mpi3mr/mpi3mr.h
+++ b/drivers/scsi/mpi3mr/mpi3mr.h
@@ -294,6 +294,10 @@  enum mpi3mr_reset_reason {
 	MPI3MR_RESET_FROM_SAS_TRANSPORT_TIMEOUT = 30,
 };
 
+#define MPI3MR_RESET_REASON_OSTYPE_LINUX	1
+#define MPI3MR_RESET_REASON_OSTYPE_SHIFT	28
+#define MPI3MR_RESET_REASON_IOCNUM_SHIFT	20
+
 /* Queue type definitions */
 enum queue_type {
 	MPI3MR_DEFAULT_QUEUE = 0,
@@ -1336,7 +1340,7 @@  void mpi3mr_start_watchdog(struct mpi3mr_ioc *mrioc);
 void mpi3mr_stop_watchdog(struct mpi3mr_ioc *mrioc);
 
 int mpi3mr_soft_reset_handler(struct mpi3mr_ioc *mrioc,
-			      u32 reset_reason, u8 snapdump);
+			      u16 reset_reason, u8 snapdump);
 void mpi3mr_ioc_disable_intr(struct mpi3mr_ioc *mrioc);
 void mpi3mr_ioc_enable_intr(struct mpi3mr_ioc *mrioc);
 
diff --git a/drivers/scsi/mpi3mr/mpi3mr_app.c b/drivers/scsi/mpi3mr/mpi3mr_app.c
index 0380996b5ad2..38f63bc7ef3b 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_app.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_app.c
@@ -1598,26 +1598,33 @@  static long mpi3mr_bsg_process_mpt_cmds(struct bsg_job *job)
 		rval = -EAGAIN;
 		if (mrioc->bsg_cmds.state & MPI3MR_CMD_RESET)
 			goto out_unlock;
-		dprint_bsg_err(mrioc,
-		    "%s: bsg request timedout after %d seconds\n", __func__,
-		    karg->timeout);
-		if (mrioc->logging_level & MPI3_DEBUG_BSG_ERROR) {
-			dprint_dump(mpi_req, MPI3MR_ADMIN_REQ_FRAME_SZ,
+		if (((mpi_header->function != MPI3_FUNCTION_SCSI_IO) &&
+		    (mpi_header->function != MPI3_FUNCTION_NVME_ENCAPSULATED))
+		    || (mrioc->logging_level & MPI3_DEBUG_BSG_ERROR)) {
+			ioc_info(mrioc, "%s: bsg request timedout after %d seconds\n",
+			    __func__, karg->timeout);
+			if (!(mrioc->logging_level & MPI3_DEBUG_BSG_INFO)) {
+				dprint_dump(mpi_req, MPI3MR_ADMIN_REQ_FRAME_SZ,
 			    "bsg_mpi3_req");
 			if (mpi_header->function ==
-			    MPI3_BSG_FUNCTION_MGMT_PASSTHROUGH) {
+			    MPI3_FUNCTION_MGMT_PASSTHROUGH) {
 				drv_buf_iter = &drv_bufs[0];
 				dprint_dump(drv_buf_iter->kern_buf,
 				    rmc_size, "mpi3_mgmt_req");
+				}
 			}
 		}
 		if ((mpi_header->function == MPI3_BSG_FUNCTION_NVME_ENCAPSULATED) ||
-		    (mpi_header->function == MPI3_BSG_FUNCTION_SCSI_IO))
+			(mpi_header->function == MPI3_BSG_FUNCTION_SCSI_IO)) {
+			dprint_bsg_err(mrioc, "%s: bsg request timedout after %d seconds,\n"
+				"issuing target reset to (0x%04x)\n", __func__,
+				karg->timeout, mpi_header->function_dependent);
 			mpi3mr_issue_tm(mrioc,
 			    MPI3_SCSITASKMGMT_TASKTYPE_TARGET_RESET,
 			    mpi_header->function_dependent, 0,
 			    MPI3MR_HOSTTAG_BLK_TMS, MPI3MR_RESETTM_TIMEOUT,
 			    &mrioc->host_tm_cmds, &resp_code, NULL);
+		}
 		if (!(mrioc->bsg_cmds.state & MPI3MR_CMD_COMPLETE) &&
 		    !(mrioc->bsg_cmds.state & MPI3MR_CMD_RESET))
 			mpi3mr_soft_reset_handler(mrioc,
diff --git a/drivers/scsi/mpi3mr/mpi3mr_fw.c b/drivers/scsi/mpi3mr/mpi3mr_fw.c
index 6ce75366dd8a..07accf01be0f 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_fw.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_fw.c
@@ -11,7 +11,7 @@ 
 #include <linux/io-64-nonatomic-lo-hi.h>
 
 static int
-mpi3mr_issue_reset(struct mpi3mr_ioc *mrioc, u16 reset_type, u32 reset_reason);
+mpi3mr_issue_reset(struct mpi3mr_ioc *mrioc, u16 reset_type, u16 reset_reason);
 static int mpi3mr_setup_admin_qpair(struct mpi3mr_ioc *mrioc);
 static void mpi3mr_process_factsdata(struct mpi3mr_ioc *mrioc,
 	struct mpi3_ioc_facts_data *facts_data);
@@ -1195,7 +1195,7 @@  static inline void mpi3mr_clear_reset_history(struct mpi3mr_ioc *mrioc)
 static int mpi3mr_issue_and_process_mur(struct mpi3mr_ioc *mrioc,
 	u32 reset_reason)
 {
-	u32 ioc_config, timeout, ioc_status;
+	u32 ioc_config, timeout, ioc_status, scratch_pad0;
 	int retval = -1;
 
 	ioc_info(mrioc, "Issuing Message unit Reset(MUR)\n");
@@ -1204,7 +1204,11 @@  static int mpi3mr_issue_and_process_mur(struct mpi3mr_ioc *mrioc,
 		return retval;
 	}
 	mpi3mr_clear_reset_history(mrioc);
-	writel(reset_reason, &mrioc->sysif_regs->scratchpad[0]);
+	scratch_pad0 = ((MPI3MR_RESET_REASON_OSTYPE_LINUX <<
+			 MPI3MR_RESET_REASON_OSTYPE_SHIFT) |
+			(mrioc->facts.ioc_num <<
+			 MPI3MR_RESET_REASON_IOCNUM_SHIFT) | reset_reason);
+	writel(scratch_pad0, &mrioc->sysif_regs->scratchpad[0]);
 	ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
 	ioc_config &= ~MPI3_SYSIF_IOC_CONFIG_ENABLE_IOC;
 	writel(ioc_config, &mrioc->sysif_regs->ioc_configuration);
@@ -1520,11 +1524,11 @@  static inline void mpi3mr_set_diagsave(struct mpi3mr_ioc *mrioc)
  * Return: 0 on success, non-zero on failure.
  */
 static int mpi3mr_issue_reset(struct mpi3mr_ioc *mrioc, u16 reset_type,
-	u32 reset_reason)
+	u16 reset_reason)
 {
 	int retval = -1;
 	u8 unlock_retry_count = 0;
-	u32 host_diagnostic, ioc_status, ioc_config;
+	u32 host_diagnostic, ioc_status, ioc_config, scratch_pad0;
 	u32 timeout = MPI3MR_RESET_ACK_TIMEOUT * 10;
 
 	if ((reset_type != MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET) &&
@@ -1576,6 +1580,9 @@  static int mpi3mr_issue_reset(struct mpi3mr_ioc *mrioc, u16 reset_type,
 		    unlock_retry_count, host_diagnostic);
 	} while (!(host_diagnostic & MPI3_SYSIF_HOST_DIAG_DIAG_WRITE_ENABLE));
 
+	scratch_pad0 = ((MPI3MR_RESET_REASON_OSTYPE_LINUX <<
+	    MPI3MR_RESET_REASON_OSTYPE_SHIFT) | (mrioc->facts.ioc_num <<
+	    MPI3MR_RESET_REASON_IOCNUM_SHIFT) | reset_reason);
 	writel(reset_reason, &mrioc->sysif_regs->scratchpad[0]);
 	writel(host_diagnostic | reset_type,
 	    &mrioc->sysif_regs->host_diagnostic);
@@ -2581,7 +2588,7 @@  static void mpi3mr_watchdog_work(struct work_struct *work)
 	unsigned long flags;
 	enum mpi3mr_iocstate ioc_state;
 	u32 fault, host_diagnostic, ioc_status;
-	u32 reset_reason = MPI3MR_RESET_FROM_FAULT_WATCH;
+	u16 reset_reason = MPI3MR_RESET_FROM_FAULT_WATCH;
 
 	if (mrioc->reset_in_progress)
 		return;
@@ -4968,7 +4975,7 @@  void mpi3mr_pel_get_seqnum_complete(struct mpi3mr_ioc *mrioc,
  * Return: 0 on success, non-zero on failure.
  */
 int mpi3mr_soft_reset_handler(struct mpi3mr_ioc *mrioc,
-	u32 reset_reason, u8 snapdump)
+	u16 reset_reason, u8 snapdump)
 {
 	int retval = 0, i;
 	unsigned long flags;