Re: [PATCH v3 2/8] mpi3mr: add support for driver commands

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 4/7/22 21:29, Sumit Saxena wrote:
There are certain BSG commands which is to be completed
by driver without involving firmware. These requests are termed
as driver commands. This patch adds support for the same.

Signed-off-by: Sumit Saxena <sumit.saxena@xxxxxxxxxxxx>
---
  drivers/scsi/mpi3mr/mpi3mr.h          |  16 +-
  drivers/scsi/mpi3mr/mpi3mr_app.c      | 397 +++++++++++++++++++++++
  drivers/scsi/mpi3mr/mpi3mr_debug.h    |  12 +-
  drivers/scsi/mpi3mr/mpi3mr_fw.c       |  21 +-
  drivers/scsi/mpi3mr/mpi3mr_os.c       |   3 +
  include/uapi/scsi/mpi3mr/mpi3mr_bsg.h | 434 ++++++++++++++++++++++++++
  6 files changed, 871 insertions(+), 12 deletions(-)
  create mode 100644 include/uapi/scsi/mpi3mr/mpi3mr_bsg.h

diff --git a/drivers/scsi/mpi3mr/mpi3mr.h b/drivers/scsi/mpi3mr/mpi3mr.h
index f0515f929110..877b0925dbc5 100644
--- a/drivers/scsi/mpi3mr/mpi3mr.h
+++ b/drivers/scsi/mpi3mr/mpi3mr.h
@@ -89,7 +89,7 @@ extern int prot_mask;
  /* Reserved Host Tag definitions */
  #define MPI3MR_HOSTTAG_INVALID		0xFFFF
  #define MPI3MR_HOSTTAG_INITCMDS		1
-#define MPI3MR_HOSTTAG_IOCTLCMDS	2
+#define MPI3MR_HOSTTAG_BSG_CMDS		2
  #define MPI3MR_HOSTTAG_BLK_TMS		5
#define MPI3MR_NUM_DEVRMCMD 16
@@ -202,10 +202,10 @@ enum mpi3mr_iocstate {
  enum mpi3mr_reset_reason {
  	MPI3MR_RESET_FROM_BRINGUP = 1,
  	MPI3MR_RESET_FROM_FAULT_WATCH = 2,
-	MPI3MR_RESET_FROM_IOCTL = 3,
+	MPI3MR_RESET_FROM_APP = 3,
  	MPI3MR_RESET_FROM_EH_HOS = 4,
  	MPI3MR_RESET_FROM_TM_TIMEOUT = 5,
-	MPI3MR_RESET_FROM_IOCTL_TIMEOUT = 6,
+	MPI3MR_RESET_FROM_APP_TIMEOUT = 6,
  	MPI3MR_RESET_FROM_MUR_FAILURE = 7,
  	MPI3MR_RESET_FROM_CTLR_CLEANUP = 8,
  	MPI3MR_RESET_FROM_CIACTIV_FAULT = 9,
@@ -698,6 +698,7 @@ struct scmd_priv {
   * @chain_bitmap_sz: Chain buffer allocator bitmap size
   * @chain_bitmap: Chain buffer allocator bitmap
   * @chain_buf_lock: Chain buffer list lock
+ * @bsg_cmds: Command tracker for BSG command
   * @host_tm_cmds: Command tracker for task management commands
   * @dev_rmhs_cmds: Command tracker for device removal commands
   * @evtack_cmds: Command tracker for event ack commands
@@ -729,6 +730,10 @@ struct scmd_priv {
   * @requested_poll_qcount: User requested poll queue count
   * @bsg_dev: BSG device structure
   * @bsg_queue: Request queue for BSG device
+ * @stop_bsgs: Stop BSG request flag
+ * @logdata_buf: Circular buffer to store log data entries
+ * @logdata_buf_idx: Index of entry in buffer to store
+ * @logdata_entry_sz: log data entry size
   */
  struct mpi3mr_ioc {
  	struct list_head list;
@@ -835,6 +840,7 @@ struct mpi3mr_ioc {
  	void *chain_bitmap;
  	spinlock_t chain_buf_lock;
+ struct mpi3mr_drv_cmd bsg_cmds;
  	struct mpi3mr_drv_cmd host_tm_cmds;
  	struct mpi3mr_drv_cmd dev_rmhs_cmds[MPI3MR_NUM_DEVRMCMD];
  	struct mpi3mr_drv_cmd evtack_cmds[MPI3MR_NUM_EVTACKCMD];
@@ -872,6 +878,10 @@ struct mpi3mr_ioc {
struct device *bsg_dev;
  	struct request_queue *bsg_queue;
+	u8 stop_bsgs;
+	u8 *logdata_buf;
+	u16 logdata_buf_idx;
+	u16 logdata_entry_sz;
  };
/**
diff --git a/drivers/scsi/mpi3mr/mpi3mr_app.c b/drivers/scsi/mpi3mr/mpi3mr_app.c
index 9b6698525990..3136f5c5d164 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_app.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_app.c
@@ -9,6 +9,386 @@
#include "mpi3mr.h"
  #include <linux/bsg-lib.h>
+#include <uapi/scsi/mpi3mr/mpi3mr_bsg.h>
+
+/**
+ * mpi3mr_bsg_verify_adapter - verify adapter number is valid
+ * @ioc_number: Adapter number
+ * @mriocpp: Pointer to hold per adapter instance
+ *
+ * This function checks whether given adapter number matches
+ * with an adapter id in the driver's list and if so fills
+ * pointer to the per adapter instance in mriocpp else set that
+ * to NULL.
+ *
+ * Return: Nothing.
+ */
+static void mpi3mr_bsg_verify_adapter(int ioc_number,
+	struct mpi3mr_ioc **mriocpp)
+{
+	struct mpi3mr_ioc *mrioc;
+
+	spin_lock(&mrioc_list_lock);
+	list_for_each_entry(mrioc, &mrioc_list, list) {
+		if (mrioc->id != ioc_number)
+			continue;
+		spin_unlock(&mrioc_list_lock);
+		*mriocpp = mrioc;
+		return;
+	}
+	spin_unlock(&mrioc_list_lock);
+	*mriocpp = NULL;
+}
+
Please return 'struct mpi3mr_io *' here and avoid having to pass a return pointer.

+/**
+ * mpi3mr_enable_logdata - Handler for log data enable
+ * @mrioc: Adapter instance reference
+ * @job: BSG job reference
+ *
+ * This function enables log data caching in the driver if not
+ * already enabled and return the maximum number of log data
+ * entries that can be cached in the driver.
+ *
+ * Return: 0 on success and proper error codes on failure
+ */
+static long mpi3mr_enable_logdata(struct mpi3mr_ioc *mrioc,
+	struct bsg_job *job)
+{
+	long rval = -EINVAL;
+	struct mpi3mr_logdata_enable logdata_enable;
+
+	if (mrioc->logdata_buf)
+		goto copy_user_data;
+
+	mrioc->logdata_entry_sz =
+	    (mrioc->reply_sz - (sizeof(struct mpi3_event_notification_reply) - 4))
+	    + MPI3MR_BSG_LOGDATA_ENTRY_HEADER_SZ;
+	mrioc->logdata_buf_idx = 0;
+
+	mrioc->logdata_buf = kcalloc(MPI3MR_BSG_LOGDATA_MAX_ENTRIES,
+	    mrioc->logdata_entry_sz, GFP_KERNEL);
+	if (!mrioc->logdata_buf)
+		return -ENOMEM;
+
+copy_user_data:
+	memset(&logdata_enable, 0, sizeof(logdata_enable));
+	logdata_enable.max_entries =
+	    MPI3MR_BSG_LOGDATA_MAX_ENTRIES;
+	if (job->request_payload.payload_len >= sizeof(logdata_enable)) {
+		sg_copy_from_buffer(job->request_payload.sg_list,
+				    job->request_payload.sg_cnt,
+				    &logdata_enable, sizeof(logdata_enable));
+		rval = 0;
+	}
+	return rval;
+}

This is a very unusual programming pattern.
You allocate the buffer only _after_ the command has been submitted, risking a failure in buffer allocation even though the command succeeded.

Please convert this to allocate the buffer _first_, then issue the command, and then evaluate the response.

Same for the other bsg handler functions.

Cheers,

Hannes
--
Dr. Hannes Reinecke		           Kernel Storage Architect
hare@xxxxxxx			                  +49 911 74053 688
SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), GF: Felix Imendörffer



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [SCSI Target Devel]     [Linux SCSI Target Infrastructure]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Samba]     [Device Mapper]

  Powered by Linux