Skip to contentSkip to conversation

mpi3mr: Few Enhancements and minor fixes

PATCH Applied Ranjan Kumar 2 participants 7 messages Jan 29, 2025 – Feb 10, 2025

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

cover mpi3mr: Few Enhancements and minor fixes

Few Enhancements and minor fixes of mpi3mr driver.

Ranjan Kumar (4):
mpi3mr: Avoid reply queue full condition
mpi3mr: Support for Segmented Hardware Trace buffer
mpi3mr: synchronous access b/w reset and tm thread for reply queue
mpi3mr: Update driver version to 8.12.1.0.50

 drivers/scsi/mpi3mr/mpi/mpi30_tool.h |   1 +
 drivers/scsi/mpi3mr/mpi3mr.h         |  31 +++++-
 drivers/scsi/mpi3mr/mpi3mr_app.c     | 128 ++++++++++++++++++++++--
 drivers/scsi/mpi3mr/mpi3mr_fw.c      | 144 +++++++++++++++++++++++++--
 4 files changed, 281 insertions(+), 23 deletions(-)
Signature · 1 line
2.31.1
#1 lore raw

PATCH 1/4 mpi3mr: Avoid reply queue full condition

- Driver will check the IOCFacts capabilities for qfull.
- It will update Operational reply queue’s Consumer Index after processing 100 replies.
- If pending IOs on a reply queue exceeds threshold (reply_queue_depth - 200) then return IO back to OS to retry.
- Driver would increase admin reply queue size to 2K.

---
 drivers/scsi/mpi3mr/mpi3mr.h     | 12 +++++++++++-
 drivers/scsi/mpi3mr/mpi3mr_app.c | 24 ++++++++++++++++++++++++
 drivers/scsi/mpi3mr/mpi3mr_fw.c  | 32 ++++++++++++++++++++++++++++----
 3 files changed, 63 insertions(+), 5 deletions(-)
drivers/scsi/mpi3mr/mpi3mr.h +11 -1
index 0c3e1ac076b5..20a29474369a 100644
@@ -81,13 +81,14 @@ extern atomic64_t event_counter;
 
 /* Admin queue management definitions */
 #define MPI3MR_ADMIN_REQ_Q_SIZE		(2 * MPI3MR_PAGE_SIZE_4K)
-#define MPI3MR_ADMIN_REPLY_Q_SIZE	(4 * MPI3MR_PAGE_SIZE_4K)
+#define MPI3MR_ADMIN_REPLY_Q_SIZE	(8 * MPI3MR_PAGE_SIZE_4K)
 #define MPI3MR_ADMIN_REQ_FRAME_SZ	128
 #define MPI3MR_ADMIN_REPLY_FRAME_SZ	16
 
 /* Operational queue management definitions */
 #define MPI3MR_OP_REQ_Q_QD		512
 #define MPI3MR_OP_REP_Q_QD		1024
+#define MPI3MR_OP_REP_Q_QD2K            2048
 #define MPI3MR_OP_REP_Q_QD4K		4096
 #define MPI3MR_OP_REQ_Q_SEG_SIZE	4096
 #define MPI3MR_OP_REP_Q_SEG_SIZE	4096
@@ -329,6 +330,7 @@ enum mpi3mr_reset_reason {
 #define MPI3MR_RESET_REASON_OSTYPE_SHIFT	28
 #define MPI3MR_RESET_REASON_IOCNUM_SHIFT	20
 
+
 /* Queue type definitions */
 enum queue_type {
 	MPI3MR_DEFAULT_QUEUE = 0,
@@ -388,6 +390,7 @@ struct mpi3mr_ioc_facts {
 	u16 max_msix_vectors;
 	u8 personality;
 	u8 dma_mask;
+	bool max_req_limit;
 	u8 protocol_flags;
 	u8 sge_mod_mask;
 	u8 sge_mod_value;
@@ -457,6 +460,8 @@ struct op_req_qinfo {
  * @enable_irq_poll: Flag to indicate polling is enabled
  * @in_use: Queue is handled by poll/ISR
  * @qtype: Type of queue (types defined in enum queue_type)
+ * @qfull_watermark: Watermark defined in reply queue to avoid
+ *                    reply queue full
  */
 struct op_reply_qinfo {
 	u16 ci;
@@ -472,6 +477,7 @@ struct op_reply_qinfo {
 	bool enable_irq_poll;
 	atomic_t in_use;
 	enum queue_type qtype;
+	u16 qfull_watermark;
 };
 
 /**
@@ -1154,6 +1160,8 @@ struct scmd_priv {
  * @snapdump_trigger_active: Snapdump trigger active flag
  * @pci_err_recovery: PCI error recovery in progress
  * @block_on_pci_err: Block IO during PCI error recovery
+ * @reply_qfull_count: Occurences of reply queue full avoidance kicking-in
+ * @prevent_reply_qfull: Enable reply queue prevention
  */
 struct mpi3mr_ioc {
 	struct list_head list;
@@ -1352,6 +1360,8 @@ struct mpi3mr_ioc {
 	bool fw_release_trigger_active;
 	bool pci_err_recovery;
 	bool block_on_pci_err;
+	atomic_t reply_qfull_count;
+	bool prevent_reply_qfull;
 };
 
 /**
drivers/scsi/mpi3mr/mpi3mr_app.c +24 -0
index 7589f48aebc8..1532436f0f3a 100644
@@ -3060,6 +3060,29 @@ reply_queue_count_show(struct device *dev, struct device_attribute *attr,
 
 static DEVICE_ATTR_RO(reply_queue_count);
 
+/**
+ * reply_qfull_count_show - Show reply qfull count
+ * @dev: class device
+ * @attr: Device attributes
+ * @buf: Buffer to copy
+ *
+ * Retrieves the current value of the reply_qfull_count from the mrioc structure and
+ * formats it as a string for display.
+ *
+ * Return: sysfs_emit() return
+ */
+static ssize_t
+reply_qfull_count_show(struct device *dev, struct device_attribute *attr,
+			char *buf)
+{
+	struct Scsi_Host *shost = class_to_shost(dev);
+	struct mpi3mr_ioc *mrioc = shost_priv(shost);
+
+	return sysfs_emit(buf, "%u\n", atomic_read(&mrioc->reply_qfull_count));
+}
+
+static DEVICE_ATTR_RO(reply_qfull_count);
+
 /**
  * logging_level_show - Show controller debug level
  * @dev: class device
@@ -3152,6 +3175,7 @@ static struct attribute *mpi3mr_host_attrs[] = {
 	&dev_attr_fw_queue_depth.attr,
 	&dev_attr_op_req_q_count.attr,
 	&dev_attr_reply_queue_count.attr,
+	&dev_attr_reply_qfull_count.attr,
 	&dev_attr_logging_level.attr,
 	&dev_attr_adp_state.attr,
 	NULL,
drivers/scsi/mpi3mr/mpi3mr_fw.c +28 -4
index 5ed31fe57474..84e57218a614 100644
@@ -2104,15 +2104,22 @@ static int mpi3mr_create_op_reply_q(struct mpi3mr_ioc *mrioc, u16 qidx)
 	}
 
 	reply_qid = qidx + 1;
-	op_reply_q->num_replies = MPI3MR_OP_REP_Q_QD;
-	if ((mrioc->pdev->device == MPI3_MFGPAGE_DEVID_SAS4116) &&
-		!mrioc->pdev->revision)
-		op_reply_q->num_replies = MPI3MR_OP_REP_Q_QD4K;
+
+	if (mrioc->pdev->device == MPI3_MFGPAGE_DEVID_SAS4116) {
+		if (mrioc->pdev->revision)
+			op_reply_q->num_replies = MPI3MR_OP_REP_Q_QD;
+		else
+			op_reply_q->num_replies = MPI3MR_OP_REP_Q_QD4K;
+	} else
+		op_reply_q->num_replies = MPI3MR_OP_REP_Q_QD2K;
+
 	op_reply_q->ci = 0;
 	op_reply_q->ephase = 1;
 	atomic_set(&op_reply_q->pend_ios, 0);
 	atomic_set(&op_reply_q->in_use, 0);
 	op_reply_q->enable_irq_poll = false;
+	op_reply_q->qfull_watermark =
+		op_reply_q->num_replies - (MPI3MR_THRESHOLD_REPLY_COUNT * 2);
 
 	if (!op_reply_q->q_segments) {
 		retval = mpi3mr_alloc_op_reply_q_segments(mrioc, qidx);
@@ -2416,8 +2423,10 @@ int mpi3mr_op_request_post(struct mpi3mr_ioc *mrioc,
 	void *segment_base_addr;
 	u16 req_sz = mrioc->facts.op_req_sz;
 	struct segments *segments = op_req_q->q_segments;
+	struct op_reply_qinfo *op_reply_q = NULL;
 
 	reply_qidx = op_req_q->reply_qid - 1;
+	op_reply_q = mrioc->op_reply_qinfo + reply_qidx;
 
 	if (mrioc->unrecoverable)
 		return -EFAULT;
@@ -2448,6 +2457,15 @@ int mpi3mr_op_request_post(struct mpi3mr_ioc *mrioc,
 		goto out;
 	}
 
+	/* Reply queue is nearing to get full, pushback IOs to SML*/
+	if ((mrioc->prevent_reply_qfull == true) &&
+		(atomic_read(&op_reply_q->pend_ios) >
+	     (op_reply_q->qfull_watermark))) {
+		atomic_inc(&mrioc->reply_qfull_count);
+		retval = -EAGAIN;
+		goto out;
+	}
+
 	segment_base_addr = segments[pi / op_req_q->segment_qd].segment;
 	req_entry = (u8 *)segment_base_addr +
 	    ((pi % op_req_q->segment_qd) * req_sz);
@@ -3091,6 +3109,9 @@ static void mpi3mr_process_factsdata(struct mpi3mr_ioc *mrioc,
 	mrioc->facts.dma_mask = (facts_flags &
 	    MPI3_IOCFACTS_FLAGS_DMA_ADDRESS_WIDTH_MASK) >>
 	    MPI3_IOCFACTS_FLAGS_DMA_ADDRESS_WIDTH_SHIFT;
+	mrioc->facts.dma_mask = (facts_flags &
+	    MPI3_IOCFACTS_FLAGS_DMA_ADDRESS_WIDTH_MASK) >>
+	    MPI3_IOCFACTS_FLAGS_DMA_ADDRESS_WIDTH_SHIFT;
 	mrioc->facts.protocol_flags = facts_data->protocol_flags;
 	mrioc->facts.mpi_version = le32_to_cpu(facts_data->mpi_version.word);
 	mrioc->facts.max_reqs = le16_to_cpu(facts_data->max_outstanding_requests);
@@ -4214,6 +4235,9 @@ int mpi3mr_init_ioc(struct mpi3mr_ioc *mrioc)
 		mrioc->shost->transportt = mpi3mr_transport_template;
 	}
 
+	if (mrioc->facts.max_req_limit)
+		mrioc->prevent_reply_qfull = true;
+
 	mrioc->reply_sz = mrioc->facts.reply_sz;
 
 	retval = mpi3mr_check_reset_dma_mask(mrioc);
Signature · 1 line
2.31.1
#2 lore raw

PATCH 2/4 mpi3mr: Support for Segmented Hardware Trace buffer

In reply to Ranjan Kumar

- Driver will allocate Segmented trace buffer, if firmware advertises the capability in IOC facts.
- Upon driver load, driver will read the trace buffer size from driver page 1, calculate the required segments for trace buffer and allocate Segmented buffers.
Each segmented is of 4096 bytes size.
- While posting driver diagnostic buffer to firmware, driver advertises that trace buffer is Segmented.
- Driver will de-allocate Segmented buffers during driver unload.

---
 drivers/scsi/mpi3mr/mpi/mpi30_tool.h |   1 +
 drivers/scsi/mpi3mr/mpi3mr.h         |  13 ++++
 drivers/scsi/mpi3mr/mpi3mr_app.c     | 104 ++++++++++++++++++++++++---
 drivers/scsi/mpi3mr/mpi3mr_fw.c      |  45 ++++++++++--
 4 files changed, 150 insertions(+), 13 deletions(-)
drivers/scsi/mpi3mr/mpi/mpi30_tool.h +1 -0
index 3b960893870f..50a65b16a818 100644
@@ -9,6 +9,7 @@
 #define MPI3_DIAG_BUFFER_TYPE_FW	(0x02)
 #define MPI3_DIAG_BUFFER_ACTION_RELEASE	(0x01)
 
+#define MPI3_DIAG_BUFFER_POST_MSGFLAGS_SEGMENTED	(0x01)
 struct mpi3_diag_buffer_post_request {
 	__le16                     host_tag;
 	u8                         ioc_use_only02;
drivers/scsi/mpi3mr/mpi3mr.h +13 -0
index 20a29474369a..98db83e1cd12 100644
@@ -935,6 +935,8 @@ struct trigger_event_data {
  * @size: Buffer size
  * @addr: Virtual address
  * @dma_addr: Buffer DMA address
+ * @is_segmented: The buffer is segmented or not
+ * @disabled_after_reset: The buffer is disabled after reset
  */
 struct diag_buffer_desc {
 	u8 type;
@@ -944,6 +946,8 @@ struct diag_buffer_desc {
 	u32 size;
 	void *addr;
 	dma_addr_t dma_addr;
+	bool is_segmented;
+	bool disabled_after_reset;
 };
 
 /**
@@ -1162,6 +1166,10 @@ struct scmd_priv {
  * @block_on_pci_err: Block IO during PCI error recovery
  * @reply_qfull_count: Occurences of reply queue full avoidance kicking-in
  * @prevent_reply_qfull: Enable reply queue prevention
+ * @seg_tb_support: Segmented trace buffer support
+ * @num_tb_segs: Number of Segments in Trace buffer
+ * @trace_buf_pool: DMA pool for Segmented trace buffer segments
+ * @trace_buf: Trace buffer segments memory descriptor
  */
 struct mpi3mr_ioc {
 	struct list_head list;
@@ -1362,6 +1370,11 @@ struct mpi3mr_ioc {
 	bool block_on_pci_err;
 	atomic_t reply_qfull_count;
 	bool prevent_reply_qfull;
+	bool seg_tb_support;
+	u32 num_tb_segs;
+	struct dma_pool *trace_buf_pool;
+	struct segments *trace_buf;
+
 };
 
 /**
drivers/scsi/mpi3mr/mpi3mr_app.c +95 -9

140 lines not on this page · raw message

drivers/scsi/mpi3mr/mpi3mr_fw.c +41 -4

87 lines not on this page · raw message

Signature · 1 line
2.31.1
#3 lore raw

PATCH 3/4 mpi3mr: synchronous access b/w reset and tm thread for reply queue

In reply to Ranjan Kumar

when the task management thread processes reply queues
while the reset thread resets them. The task management thread accesses an invalid queue ID (0xFFFF), set by the reset thread, which points to unallocated memory, causing a crash.

Flag "io_admin_reset_sync" is added to synchronize access between the reset, IO, and admin threads. Before a reset, the reset handler sets this flag to block IO and admin processing threads. If any thread bypasses the initial check, the reset thread waits up to 10 seconds for processing to finish. If the wait exceeds 10 seconds, the controller is marked as unrecoverable.

---
 drivers/scsi/mpi3mr/mpi3mr.h    |  2 +
 drivers/scsi/mpi3mr/mpi3mr_fw.c | 67 +++++++++++++++++++++++++++++++--
 2 files changed, 66 insertions(+), 3 deletions(-)
drivers/scsi/mpi3mr/mpi3mr.h +2 -0
index 98db83e1cd12..8978c201c6f0 100644
@@ -1101,6 +1101,7 @@ struct scmd_priv {
  * @ts_update_interval: Timestamp update interval
  * @reset_in_progress: Reset in progress flag
  * @unrecoverable: Controller unrecoverable flag
+ * @io_admin_reset_sync: Manage state of I/O ops during an admin reset process
  * @prev_reset_result: Result of previous reset
  * @reset_mutex: Controller reset mutex
  * @reset_waitq: Controller reset  wait queue
@@ -1293,6 +1294,7 @@ struct mpi3mr_ioc {
 	u16 ts_update_interval;
 	u8 reset_in_progress;
 	u8 unrecoverable;
+	u8 io_admin_reset_sync;
 	int prev_reset_result;
 	struct mutex reset_mutex;
 	wait_queue_head_t reset_waitq;
drivers/scsi/mpi3mr/mpi3mr_fw.c +64 -3

109 lines not on this page · raw message

Signature · 1 line
2.31.1
#4 lore raw

PATCH 4/4 mpi3mr: Update driver version to 8.12.1.0.50

In reply to Ranjan Kumar

Update driver version to 8.12.1.0.50

---
 drivers/scsi/mpi3mr/mpi3mr.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/mpi3mr/mpi3mr.h +2 -2
index 8978c201c6f0..b6e15b531596 100644
@@ -57,8 +57,8 @@ extern struct list_head mrioc_list;
 extern int prot_mask;
 extern atomic64_t event_counter;
 
-#define MPI3MR_DRIVER_VERSION	"8.12.0.3.50"
-#define MPI3MR_DRIVER_RELDATE	"11-November-2024"
+#define MPI3MR_DRIVER_VERSION	"8.12.1.0.50"
+#define MPI3MR_DRIVER_RELDATE	"28-January-2025"
 
 #define MPI3MR_DRIVER_NAME	"mpi3mr"
 #define MPI3MR_DRIVER_LICENSE	"GPL"
Signature · 1 line
2.31.1
#5 lore raw
In reply to Ranjan Kumar

Ranjan,

Quoted 1 line

Few Enhancements and minor fixes of mpi3mr driver.

Applied to 6.15/scsi-staging, thanks!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
#6 lore raw
In reply to Ranjan Kumar
Quoted 9 lines · Ranjan Kumar

Few Enhancements and minor fixes of mpi3mr driver.

Ranjan Kumar (4):
mpi3mr: Avoid reply queue full condition
mpi3mr: Support for Segmented Hardware Trace buffer
mpi3mr: synchronous access b/w reset and tm thread for reply queue
mpi3mr: Update driver version to 8.12.1.0.50

[...]

Applied to 6.15/scsi-queue, thanks!

[1/4] mpi3mr: Avoid reply queue full condition

      https://git.kernel.org/mkp/scsi/c/f08b24d82749
[2/4] mpi3mr: Support for Segmented Hardware Trace buffer
      https://git.kernel.org/mkp/scsi/c/339a7b32a371
[3/4] mpi3mr: synchronous access b/w reset and tm thread for reply queue
      https://git.kernel.org/mkp/scsi/c/f195fc060c73
[4/4] mpi3mr: Update driver version to 8.12.1.0.50
      https://git.kernel.org/mkp/scsi/c/35a0437d9f33
Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering