diff mbox series

[v3,1/8] mpi3mr: add BSG device support

Message ID 20220407192913.345411-2-sumit.saxena@broadcom.com
State Superseded
Headers show
Series mpi3mr: add BSG interface support for controller management | expand

Commit Message

Sumit Saxena April 7, 2022, 7:29 p.m. UTC
Create BSG device per controller for controller management purpose.
BSG Device nodes will be named as /dev/bsg/mpi3mrctl0, /dev/bsg/mpi3mrctl1...

Signed-off-by: Sumit Saxena <sumit.saxena@broadcom.com>
---
 drivers/scsi/mpi3mr/Kconfig      |   1 +
 drivers/scsi/mpi3mr/Makefile     |   1 +
 drivers/scsi/mpi3mr/mpi3mr.h     |  20 ++++++
 drivers/scsi/mpi3mr/mpi3mr_app.c | 105 +++++++++++++++++++++++++++++++
 drivers/scsi/mpi3mr/mpi3mr_os.c  |   2 +
 5 files changed, 129 insertions(+)
 create mode 100644 drivers/scsi/mpi3mr/mpi3mr_app.c

Comments

Hannes Reinecke April 8, 2022, 11:47 a.m. UTC | #1
On 4/7/22 21:29, Sumit Saxena wrote:
> Create BSG device per controller for controller management purpose.
> BSG Device nodes will be named as /dev/bsg/mpi3mrctl0, /dev/bsg/mpi3mrctl1...
> 
> Signed-off-by: Sumit Saxena <sumit.saxena@broadcom.com>
> ---
>   drivers/scsi/mpi3mr/Kconfig      |   1 +
>   drivers/scsi/mpi3mr/Makefile     |   1 +
>   drivers/scsi/mpi3mr/mpi3mr.h     |  20 ++++++
>   drivers/scsi/mpi3mr/mpi3mr_app.c | 105 +++++++++++++++++++++++++++++++
>   drivers/scsi/mpi3mr/mpi3mr_os.c  |   2 +
>   5 files changed, 129 insertions(+)
>   create mode 100644 drivers/scsi/mpi3mr/mpi3mr_app.c
> 
> diff --git a/drivers/scsi/mpi3mr/Kconfig b/drivers/scsi/mpi3mr/Kconfig
> index f7882375e74f..8997531940c2 100644
> --- a/drivers/scsi/mpi3mr/Kconfig
> +++ b/drivers/scsi/mpi3mr/Kconfig
> @@ -3,5 +3,6 @@
>   config SCSI_MPI3MR
>   	tristate "Broadcom MPI3 Storage Controller Device Driver"
>   	depends on PCI && SCSI
> +	select BLK_DEV_BSGLIB
>   	help
>   	MPI3 based Storage & RAID Controllers Driver.
> diff --git a/drivers/scsi/mpi3mr/Makefile b/drivers/scsi/mpi3mr/Makefile
> index 7c2063e04c81..f5cdbe48c150 100644
> --- a/drivers/scsi/mpi3mr/Makefile
> +++ b/drivers/scsi/mpi3mr/Makefile
> @@ -2,3 +2,4 @@
>   obj-m += mpi3mr.o
>   mpi3mr-y +=  mpi3mr_os.o     \
>   		mpi3mr_fw.o \
> +		mpi3mr_app.o \
> diff --git a/drivers/scsi/mpi3mr/mpi3mr.h b/drivers/scsi/mpi3mr/mpi3mr.h
> index 6672d907d75d..f0515f929110 100644
> --- a/drivers/scsi/mpi3mr/mpi3mr.h
> +++ b/drivers/scsi/mpi3mr/mpi3mr.h
> @@ -148,6 +148,7 @@ extern int prot_mask;
>   
>   #define MPI3MR_DEFAULT_MDTS	(128 * 1024)
>   #define MPI3MR_DEFAULT_PGSZEXP         (12)
> +
>   /* Command retry count definitions */
>   #define MPI3MR_DEV_RMHS_RETRY_COUNT 3
>   
> @@ -175,6 +176,18 @@ extern int prot_mask;
>   /* MSI Index from Reply Queue Index */
>   #define REPLY_QUEUE_IDX_TO_MSIX_IDX(qidx, offset)	(qidx + offset)
>   
> +/*
> + * Maximum data transfer size definitions for management
> + * application commands
> + */
> +#define MPI3MR_MAX_APP_XFER_SIZE	(1 * 1024 * 1024)
> +#define MPI3MR_MAX_APP_XFER_SEGMENTS	512
> +/*
> + * 2048 sectors are for data buffers and additional 512 sectors for
> + * other buffers
> + */
> +#define MPI3MR_MAX_APP_XFER_SECTORS	(2048 + 512)
> +
>   /* IOC State definitions */
>   enum mpi3mr_iocstate {
>   	MRIOC_STATE_READY = 1,
> @@ -714,6 +727,8 @@ struct scmd_priv {
>    * @default_qcount: Total Default queues
>    * @active_poll_qcount: Currently active poll queue count
>    * @requested_poll_qcount: User requested poll queue count
> + * @bsg_dev: BSG device structure
> + * @bsg_queue: Request queue for BSG device
>    */
>   struct mpi3mr_ioc {
>   	struct list_head list;
> @@ -854,6 +869,9 @@ struct mpi3mr_ioc {
>   	u16 default_qcount;
>   	u16 active_poll_qcount;
>   	u16 requested_poll_qcount;
> +
> +	struct device *bsg_dev;
> +	struct request_queue *bsg_queue;
>   };
>   
>   /**
> @@ -962,5 +980,7 @@ void mpi3mr_check_rh_fault_ioc(struct mpi3mr_ioc *mrioc, u32 reason_code);
>   int mpi3mr_process_op_reply_q(struct mpi3mr_ioc *mrioc,
>   	struct op_reply_qinfo *op_reply_q);
>   int mpi3mr_blk_mq_poll(struct Scsi_Host *shost, unsigned int queue_num);
> +void mpi3mr_bsg_init(struct mpi3mr_ioc *mrioc);
> +void mpi3mr_bsg_exit(struct mpi3mr_ioc *mrioc);
>   
>   #endif /*MPI3MR_H_INCLUDED*/
> diff --git a/drivers/scsi/mpi3mr/mpi3mr_app.c b/drivers/scsi/mpi3mr/mpi3mr_app.c
> new file mode 100644
> index 000000000000..9b6698525990
> --- /dev/null
> +++ b/drivers/scsi/mpi3mr/mpi3mr_app.c
> @@ -0,0 +1,105 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Driver for Broadcom MPI3 Storage Controllers
> + *
> + * Copyright (C) 2017-2022 Broadcom Inc.
> + *  (mailto: mpi3mr-linuxdrv.pdl@broadcom.com)
> + *
> + */
> +
> +#include "mpi3mr.h"
> +#include <linux/bsg-lib.h>
> +
> +/**
> + * mpi3mr_bsg_request - bsg request entry point
> + * @job: BSG job reference
> + *
> + * This is driver's entry point for bsg requests
> + *
> + * Return: 0 on success and proper error codes on failure
> + */
> +int mpi3mr_bsg_request(struct bsg_job *job)
> +{
> +	return 0;
> +}
> +
> +/**
> + * mpi3mr_bsg_exit - de-registration from bsg layer
> + *
> + * This will be called during driver unload and all
> + * bsg resources allocated during load will be freed.
> + *
> + * Return:Nothing
> + */
> +void mpi3mr_bsg_exit(struct mpi3mr_ioc *mrioc)
> +{
> +	if (!mrioc->bsg_queue)
> +		return;
> +
> +	bsg_remove_queue(mrioc->bsg_queue);
> +	mrioc->bsg_queue = NULL;
> +
> +	device_del(mrioc->bsg_dev);
> +	put_device(mrioc->bsg_dev);
> +	kfree(mrioc->bsg_dev);
> +}
> +
> +/**
> + * mpi3mr_bsg_node_release -release bsg device node
> + * @dev: bsg device node
> + *
> + * decrements bsg dev reference count
> + *
> + * Return:Nothing
> + */
> +void mpi3mr_bsg_node_release(struct device *dev)
> +{
> +	put_device(dev);
> +}
> +
> +/**
> + * mpi3mr_bsg_init -  registration with bsg layer
> + *
> + * This will be called during driver load and it will
> + * register driver with bsg layer
> + *
> + * Return:Nothing
> + */
> +void mpi3mr_bsg_init(struct mpi3mr_ioc *mrioc)
> +{
> +	mrioc->bsg_dev = kzalloc(sizeof(struct device), GFP_KERNEL);
> +	if (!mrioc->bsg_dev) {
> +		ioc_err(mrioc, "bsg device mem allocation failed\n");
> +		return;
> +	}
> +
> +	device_initialize(mrioc->bsg_dev);
> +	dev_set_name(mrioc->bsg_dev, "mpi3mrctl%u", mrioc->id);
> +
> +	if (device_add(mrioc->bsg_dev)) {
> +		ioc_err(mrioc, "%s: bsg device add failed\n",
> +		    dev_name(mrioc->bsg_dev));
> +		goto err_device_add;
> +	}
> +
> +	mrioc->bsg_dev->release = mpi3mr_bsg_node_release;
> +
> +	mrioc->bsg_queue = bsg_setup_queue(mrioc->bsg_dev, dev_name(mrioc->bsg_dev),
> +			mpi3mr_bsg_request, NULL, 0);
> +	if (!mrioc->bsg_queue) {
> +		ioc_err(mrioc, "%s: bsg registration failed\n",
> +		    dev_name(mrioc->bsg_dev));
> +		goto err_setup_queue;
> +	}
> +
> +	blk_queue_max_segments(mrioc->bsg_queue, MPI3MR_MAX_APP_XFER_SEGMENTS);
> +	blk_queue_max_hw_sectors(mrioc->bsg_queue, MPI3MR_MAX_APP_XFER_SECTORS);
> +
> +	return;
> +
> +err_setup_queue:
> +	device_del(mrioc->bsg_dev);
> +	put_device(mrioc->bsg_dev);
> +err_device_add:
> +	kfree(mrioc->bsg_dev);
> +}
> diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c
> index f7cd70a15ea6..faf14a5f9123 100644
> --- a/drivers/scsi/mpi3mr/mpi3mr_os.c
> +++ b/drivers/scsi/mpi3mr/mpi3mr_os.c
> @@ -4345,6 +4345,7 @@ mpi3mr_probe(struct pci_dev *pdev, const struct pci_device_id *id)
>   	}
>   
>   	scsi_scan_host(shost);
> +	mpi3mr_bsg_init(mrioc);
>   	return retval;
>   
>   addhost_failed:
> @@ -4389,6 +4390,7 @@ static void mpi3mr_remove(struct pci_dev *pdev)
>   	while (mrioc->reset_in_progress || mrioc->is_driver_loading)
>   		ssleep(1);
>   
> +	mpi3mr_bsg_exit(mrioc);
>   	mrioc->stop_drv_processing = 1;
>   	mpi3mr_cleanup_fwevt_list(mrioc);
>   	spin_lock_irqsave(&mrioc->fwevt_lock, flags);
Reviewed-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
Himanshu Madhani April 8, 2022, 6:43 p.m. UTC | #2
On 4/7/22 12:29, Sumit Saxena wrote:
> Create BSG device per controller for controller management purpose.
> BSG Device nodes will be named as /dev/bsg/mpi3mrctl0, /dev/bsg/mpi3mrctl1...
> 
> Signed-off-by: Sumit Saxena <sumit.saxena@broadcom.com>
> ---
>   drivers/scsi/mpi3mr/Kconfig      |   1 +
>   drivers/scsi/mpi3mr/Makefile     |   1 +
>   drivers/scsi/mpi3mr/mpi3mr.h     |  20 ++++++
>   drivers/scsi/mpi3mr/mpi3mr_app.c | 105 +++++++++++++++++++++++++++++++
>   drivers/scsi/mpi3mr/mpi3mr_os.c  |   2 +
>   5 files changed, 129 insertions(+)
>   create mode 100644 drivers/scsi/mpi3mr/mpi3mr_app.c
> 
> diff --git a/drivers/scsi/mpi3mr/Kconfig b/drivers/scsi/mpi3mr/Kconfig
> index f7882375e74f..8997531940c2 100644
> --- a/drivers/scsi/mpi3mr/Kconfig
> +++ b/drivers/scsi/mpi3mr/Kconfig
> @@ -3,5 +3,6 @@
>   config SCSI_MPI3MR
>   	tristate "Broadcom MPI3 Storage Controller Device Driver"
>   	depends on PCI && SCSI
> +	select BLK_DEV_BSGLIB
>   	help
>   	MPI3 based Storage & RAID Controllers Driver.
> diff --git a/drivers/scsi/mpi3mr/Makefile b/drivers/scsi/mpi3mr/Makefile
> index 7c2063e04c81..f5cdbe48c150 100644
> --- a/drivers/scsi/mpi3mr/Makefile
> +++ b/drivers/scsi/mpi3mr/Makefile
> @@ -2,3 +2,4 @@
>   obj-m += mpi3mr.o
>   mpi3mr-y +=  mpi3mr_os.o     \
>   		mpi3mr_fw.o \
> +		mpi3mr_app.o \
> diff --git a/drivers/scsi/mpi3mr/mpi3mr.h b/drivers/scsi/mpi3mr/mpi3mr.h
> index 6672d907d75d..f0515f929110 100644
> --- a/drivers/scsi/mpi3mr/mpi3mr.h
> +++ b/drivers/scsi/mpi3mr/mpi3mr.h
> @@ -148,6 +148,7 @@ extern int prot_mask;
>   
>   #define MPI3MR_DEFAULT_MDTS	(128 * 1024)
>   #define MPI3MR_DEFAULT_PGSZEXP         (12)
> +
>   /* Command retry count definitions */
>   #define MPI3MR_DEV_RMHS_RETRY_COUNT 3
>   
> @@ -175,6 +176,18 @@ extern int prot_mask;
>   /* MSI Index from Reply Queue Index */
>   #define REPLY_QUEUE_IDX_TO_MSIX_IDX(qidx, offset)	(qidx + offset)
>   
> +/*
> + * Maximum data transfer size definitions for management
> + * application commands
> + */
> +#define MPI3MR_MAX_APP_XFER_SIZE	(1 * 1024 * 1024)
> +#define MPI3MR_MAX_APP_XFER_SEGMENTS	512
> +/*
> + * 2048 sectors are for data buffers and additional 512 sectors for
> + * other buffers
> + */
> +#define MPI3MR_MAX_APP_XFER_SECTORS	(2048 + 512)
> +
>   /* IOC State definitions */
>   enum mpi3mr_iocstate {
>   	MRIOC_STATE_READY = 1,
> @@ -714,6 +727,8 @@ struct scmd_priv {
>    * @default_qcount: Total Default queues
>    * @active_poll_qcount: Currently active poll queue count
>    * @requested_poll_qcount: User requested poll queue count
> + * @bsg_dev: BSG device structure
> + * @bsg_queue: Request queue for BSG device
>    */
>   struct mpi3mr_ioc {
>   	struct list_head list;
> @@ -854,6 +869,9 @@ struct mpi3mr_ioc {
>   	u16 default_qcount;
>   	u16 active_poll_qcount;
>   	u16 requested_poll_qcount;
> +
> +	struct device *bsg_dev;
> +	struct request_queue *bsg_queue;
>   };
>   
>   /**
> @@ -962,5 +980,7 @@ void mpi3mr_check_rh_fault_ioc(struct mpi3mr_ioc *mrioc, u32 reason_code);
>   int mpi3mr_process_op_reply_q(struct mpi3mr_ioc *mrioc,
>   	struct op_reply_qinfo *op_reply_q);
>   int mpi3mr_blk_mq_poll(struct Scsi_Host *shost, unsigned int queue_num);
> +void mpi3mr_bsg_init(struct mpi3mr_ioc *mrioc);
> +void mpi3mr_bsg_exit(struct mpi3mr_ioc *mrioc);
>   
>   #endif /*MPI3MR_H_INCLUDED*/
> diff --git a/drivers/scsi/mpi3mr/mpi3mr_app.c b/drivers/scsi/mpi3mr/mpi3mr_app.c
> new file mode 100644
> index 000000000000..9b6698525990
> --- /dev/null
> +++ b/drivers/scsi/mpi3mr/mpi3mr_app.c
> @@ -0,0 +1,105 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Driver for Broadcom MPI3 Storage Controllers
> + *
> + * Copyright (C) 2017-2022 Broadcom Inc.
> + *  (mailto: mpi3mr-linuxdrv.pdl@broadcom.com)
> + *
> + */
> +
> +#include "mpi3mr.h"
> +#include <linux/bsg-lib.h>
> +
> +/**
> + * mpi3mr_bsg_request - bsg request entry point
> + * @job: BSG job reference
> + *
> + * This is driver's entry point for bsg requests
> + *
> + * Return: 0 on success and proper error codes on failure
> + */
> +int mpi3mr_bsg_request(struct bsg_job *job)
> +{
> +	return 0;
> +}
> +
> +/**
> + * mpi3mr_bsg_exit - de-registration from bsg layer
> + *
> + * This will be called during driver unload and all
> + * bsg resources allocated during load will be freed.
> + *
> + * Return:Nothing
> + */
> +void mpi3mr_bsg_exit(struct mpi3mr_ioc *mrioc)
> +{
> +	if (!mrioc->bsg_queue)
> +		return;
> +
> +	bsg_remove_queue(mrioc->bsg_queue);
> +	mrioc->bsg_queue = NULL;
> +
> +	device_del(mrioc->bsg_dev);
> +	put_device(mrioc->bsg_dev);
> +	kfree(mrioc->bsg_dev);
> +}
> +
> +/**
> + * mpi3mr_bsg_node_release -release bsg device node
> + * @dev: bsg device node
> + *
> + * decrements bsg dev reference count
> + *
> + * Return:Nothing
> + */
> +void mpi3mr_bsg_node_release(struct device *dev)
> +{
> +	put_device(dev);
> +}
> +
> +/**
> + * mpi3mr_bsg_init -  registration with bsg layer
> + *
> + * This will be called during driver load and it will
> + * register driver with bsg layer
> + *
> + * Return:Nothing
> + */
> +void mpi3mr_bsg_init(struct mpi3mr_ioc *mrioc)
> +{
> +	mrioc->bsg_dev = kzalloc(sizeof(struct device), GFP_KERNEL);
> +	if (!mrioc->bsg_dev) {
> +		ioc_err(mrioc, "bsg device mem allocation failed\n");
> +		return;
> +	}
> +
> +	device_initialize(mrioc->bsg_dev);
> +	dev_set_name(mrioc->bsg_dev, "mpi3mrctl%u", mrioc->id);
> +
> +	if (device_add(mrioc->bsg_dev)) {
> +		ioc_err(mrioc, "%s: bsg device add failed\n",
> +		    dev_name(mrioc->bsg_dev));
> +		goto err_device_add;
> +	}
> +
> +	mrioc->bsg_dev->release = mpi3mr_bsg_node_release;
> +
> +	mrioc->bsg_queue = bsg_setup_queue(mrioc->bsg_dev, dev_name(mrioc->bsg_dev),
> +			mpi3mr_bsg_request, NULL, 0);
> +	if (!mrioc->bsg_queue) {
> +		ioc_err(mrioc, "%s: bsg registration failed\n",
> +		    dev_name(mrioc->bsg_dev));
> +		goto err_setup_queue;
> +	}
> +
> +	blk_queue_max_segments(mrioc->bsg_queue, MPI3MR_MAX_APP_XFER_SEGMENTS);
> +	blk_queue_max_hw_sectors(mrioc->bsg_queue, MPI3MR_MAX_APP_XFER_SECTORS);
> +
> +	return;
> +
> +err_setup_queue:
> +	device_del(mrioc->bsg_dev);
> +	put_device(mrioc->bsg_dev);
> +err_device_add:
> +	kfree(mrioc->bsg_dev);
> +}
> diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c
> index f7cd70a15ea6..faf14a5f9123 100644
> --- a/drivers/scsi/mpi3mr/mpi3mr_os.c
> +++ b/drivers/scsi/mpi3mr/mpi3mr_os.c
> @@ -4345,6 +4345,7 @@ mpi3mr_probe(struct pci_dev *pdev, const struct pci_device_id *id)
>   	}
>   
>   	scsi_scan_host(shost);
> +	mpi3mr_bsg_init(mrioc);
>   	return retval;
>   
>   addhost_failed:
> @@ -4389,6 +4390,7 @@ static void mpi3mr_remove(struct pci_dev *pdev)
>   	while (mrioc->reset_in_progress || mrioc->is_driver_loading)
>   		ssleep(1);
>   
> +	mpi3mr_bsg_exit(mrioc);
>   	mrioc->stop_drv_processing = 1;
>   	mpi3mr_cleanup_fwevt_list(mrioc);
>   	spin_lock_irqsave(&mrioc->fwevt_lock, flags);
> 

Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
diff mbox series

Patch

diff --git a/drivers/scsi/mpi3mr/Kconfig b/drivers/scsi/mpi3mr/Kconfig
index f7882375e74f..8997531940c2 100644
--- a/drivers/scsi/mpi3mr/Kconfig
+++ b/drivers/scsi/mpi3mr/Kconfig
@@ -3,5 +3,6 @@ 
 config SCSI_MPI3MR
 	tristate "Broadcom MPI3 Storage Controller Device Driver"
 	depends on PCI && SCSI
+	select BLK_DEV_BSGLIB
 	help
 	MPI3 based Storage & RAID Controllers Driver.
diff --git a/drivers/scsi/mpi3mr/Makefile b/drivers/scsi/mpi3mr/Makefile
index 7c2063e04c81..f5cdbe48c150 100644
--- a/drivers/scsi/mpi3mr/Makefile
+++ b/drivers/scsi/mpi3mr/Makefile
@@ -2,3 +2,4 @@ 
 obj-m += mpi3mr.o
 mpi3mr-y +=  mpi3mr_os.o     \
 		mpi3mr_fw.o \
+		mpi3mr_app.o \
diff --git a/drivers/scsi/mpi3mr/mpi3mr.h b/drivers/scsi/mpi3mr/mpi3mr.h
index 6672d907d75d..f0515f929110 100644
--- a/drivers/scsi/mpi3mr/mpi3mr.h
+++ b/drivers/scsi/mpi3mr/mpi3mr.h
@@ -148,6 +148,7 @@  extern int prot_mask;
 
 #define MPI3MR_DEFAULT_MDTS	(128 * 1024)
 #define MPI3MR_DEFAULT_PGSZEXP         (12)
+
 /* Command retry count definitions */
 #define MPI3MR_DEV_RMHS_RETRY_COUNT 3
 
@@ -175,6 +176,18 @@  extern int prot_mask;
 /* MSI Index from Reply Queue Index */
 #define REPLY_QUEUE_IDX_TO_MSIX_IDX(qidx, offset)	(qidx + offset)
 
+/*
+ * Maximum data transfer size definitions for management
+ * application commands
+ */
+#define MPI3MR_MAX_APP_XFER_SIZE	(1 * 1024 * 1024)
+#define MPI3MR_MAX_APP_XFER_SEGMENTS	512
+/*
+ * 2048 sectors are for data buffers and additional 512 sectors for
+ * other buffers
+ */
+#define MPI3MR_MAX_APP_XFER_SECTORS	(2048 + 512)
+
 /* IOC State definitions */
 enum mpi3mr_iocstate {
 	MRIOC_STATE_READY = 1,
@@ -714,6 +727,8 @@  struct scmd_priv {
  * @default_qcount: Total Default queues
  * @active_poll_qcount: Currently active poll queue count
  * @requested_poll_qcount: User requested poll queue count
+ * @bsg_dev: BSG device structure
+ * @bsg_queue: Request queue for BSG device
  */
 struct mpi3mr_ioc {
 	struct list_head list;
@@ -854,6 +869,9 @@  struct mpi3mr_ioc {
 	u16 default_qcount;
 	u16 active_poll_qcount;
 	u16 requested_poll_qcount;
+
+	struct device *bsg_dev;
+	struct request_queue *bsg_queue;
 };
 
 /**
@@ -962,5 +980,7 @@  void mpi3mr_check_rh_fault_ioc(struct mpi3mr_ioc *mrioc, u32 reason_code);
 int mpi3mr_process_op_reply_q(struct mpi3mr_ioc *mrioc,
 	struct op_reply_qinfo *op_reply_q);
 int mpi3mr_blk_mq_poll(struct Scsi_Host *shost, unsigned int queue_num);
+void mpi3mr_bsg_init(struct mpi3mr_ioc *mrioc);
+void mpi3mr_bsg_exit(struct mpi3mr_ioc *mrioc);
 
 #endif /*MPI3MR_H_INCLUDED*/
diff --git a/drivers/scsi/mpi3mr/mpi3mr_app.c b/drivers/scsi/mpi3mr/mpi3mr_app.c
new file mode 100644
index 000000000000..9b6698525990
--- /dev/null
+++ b/drivers/scsi/mpi3mr/mpi3mr_app.c
@@ -0,0 +1,105 @@ 
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Driver for Broadcom MPI3 Storage Controllers
+ *
+ * Copyright (C) 2017-2022 Broadcom Inc.
+ *  (mailto: mpi3mr-linuxdrv.pdl@broadcom.com)
+ *
+ */
+
+#include "mpi3mr.h"
+#include <linux/bsg-lib.h>
+
+/**
+ * mpi3mr_bsg_request - bsg request entry point
+ * @job: BSG job reference
+ *
+ * This is driver's entry point for bsg requests
+ *
+ * Return: 0 on success and proper error codes on failure
+ */
+int mpi3mr_bsg_request(struct bsg_job *job)
+{
+	return 0;
+}
+
+/**
+ * mpi3mr_bsg_exit - de-registration from bsg layer
+ *
+ * This will be called during driver unload and all
+ * bsg resources allocated during load will be freed.
+ *
+ * Return:Nothing
+ */
+void mpi3mr_bsg_exit(struct mpi3mr_ioc *mrioc)
+{
+	if (!mrioc->bsg_queue)
+		return;
+
+	bsg_remove_queue(mrioc->bsg_queue);
+	mrioc->bsg_queue = NULL;
+
+	device_del(mrioc->bsg_dev);
+	put_device(mrioc->bsg_dev);
+	kfree(mrioc->bsg_dev);
+}
+
+/**
+ * mpi3mr_bsg_node_release -release bsg device node
+ * @dev: bsg device node
+ *
+ * decrements bsg dev reference count
+ *
+ * Return:Nothing
+ */
+void mpi3mr_bsg_node_release(struct device *dev)
+{
+	put_device(dev);
+}
+
+/**
+ * mpi3mr_bsg_init -  registration with bsg layer
+ *
+ * This will be called during driver load and it will
+ * register driver with bsg layer
+ *
+ * Return:Nothing
+ */
+void mpi3mr_bsg_init(struct mpi3mr_ioc *mrioc)
+{
+	mrioc->bsg_dev = kzalloc(sizeof(struct device), GFP_KERNEL);
+	if (!mrioc->bsg_dev) {
+		ioc_err(mrioc, "bsg device mem allocation failed\n");
+		return;
+	}
+
+	device_initialize(mrioc->bsg_dev);
+	dev_set_name(mrioc->bsg_dev, "mpi3mrctl%u", mrioc->id);
+
+	if (device_add(mrioc->bsg_dev)) {
+		ioc_err(mrioc, "%s: bsg device add failed\n",
+		    dev_name(mrioc->bsg_dev));
+		goto err_device_add;
+	}
+
+	mrioc->bsg_dev->release = mpi3mr_bsg_node_release;
+
+	mrioc->bsg_queue = bsg_setup_queue(mrioc->bsg_dev, dev_name(mrioc->bsg_dev),
+			mpi3mr_bsg_request, NULL, 0);
+	if (!mrioc->bsg_queue) {
+		ioc_err(mrioc, "%s: bsg registration failed\n",
+		    dev_name(mrioc->bsg_dev));
+		goto err_setup_queue;
+	}
+
+	blk_queue_max_segments(mrioc->bsg_queue, MPI3MR_MAX_APP_XFER_SEGMENTS);
+	blk_queue_max_hw_sectors(mrioc->bsg_queue, MPI3MR_MAX_APP_XFER_SECTORS);
+
+	return;
+
+err_setup_queue:
+	device_del(mrioc->bsg_dev);
+	put_device(mrioc->bsg_dev);
+err_device_add:
+	kfree(mrioc->bsg_dev);
+}
diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c
index f7cd70a15ea6..faf14a5f9123 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_os.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_os.c
@@ -4345,6 +4345,7 @@  mpi3mr_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	}
 
 	scsi_scan_host(shost);
+	mpi3mr_bsg_init(mrioc);
 	return retval;
 
 addhost_failed:
@@ -4389,6 +4390,7 @@  static void mpi3mr_remove(struct pci_dev *pdev)
 	while (mrioc->reset_in_progress || mrioc->is_driver_loading)
 		ssleep(1);
 
+	mpi3mr_bsg_exit(mrioc);
 	mrioc->stop_drv_processing = 1;
 	mpi3mr_cleanup_fwevt_list(mrioc);
 	spin_lock_irqsave(&mrioc->fwevt_lock, flags);