Skip to content

Commit

Permalink
scsi: mpi3mr: NVMe encapsulation support for tri-mode HBA
Browse files Browse the repository at this point in the history
  • Loading branch information
ixhamza committed Nov 18, 2024
1 parent b3b26df commit 6c12015
Show file tree
Hide file tree
Showing 4 changed files with 464 additions and 9 deletions.
12 changes: 12 additions & 0 deletions drivers/scsi/mpi3mr/mpi3mr.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
#include "mpi/mpi30_pci.h"
#include "mpi/mpi30_tool.h"
#include "mpi3mr_debug.h"
#include <linux/nvme.h>
#include <linux/nvme_ioctl.h>

/* Global list and lock for storing multiple adapters managed by the driver */
extern spinlock_t mrioc_list_lock;
Expand Down Expand Up @@ -1492,6 +1494,16 @@ extern const struct attribute_group *mpi3mr_dev_groups[];
extern struct sas_function_template mpi3mr_transport_functions;
extern struct scsi_transport_template *mpi3mr_transport_template;

int mpi3mr_build_nvme_sgl(struct mpi3mr_ioc *mrioc,
struct mpi3_nvme_encapsulated_request *nvme_encap_request,
struct mpi3mr_buf_map *drv_bufs, u8 bufcnt);
int mpi3mr_build_nvme_prp(struct mpi3mr_ioc *mrioc,
struct mpi3_nvme_encapsulated_request *nvme_encap_request,
struct mpi3mr_buf_map *drv_bufs, u8 bufcnt);
unsigned int mpi3mr_get_nvme_data_fmt(
struct mpi3_nvme_encapsulated_request *nvme_encap_request);
int mpi3mr_map_data_buffer_dma(struct mpi3mr_ioc *mrioc,
struct mpi3mr_buf_map *drv_buf, u16 desc_count, void *ubuf);
int mpi3mr_cfg_get_dev_pg0(struct mpi3mr_ioc *mrioc, u16 *ioc_status,
struct mpi3_device_page0 *dev_pg0, u16 pg_sz, u32 form, u32 form_spec);
int mpi3mr_cfg_get_sas_phy_pg0(struct mpi3mr_ioc *mrioc, u16 *ioc_status,
Expand Down
25 changes: 16 additions & 9 deletions drivers/scsi/mpi3mr/mpi3mr_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -1843,7 +1843,7 @@ static int mpi3mr_bsg_build_sgl(struct mpi3mr_ioc *mrioc, u8 *mpi_req,
*
* Return: Data format of the NVMe command (PRP/SGL etc)
*/
static unsigned int mpi3mr_get_nvme_data_fmt(
unsigned int mpi3mr_get_nvme_data_fmt(
struct mpi3_nvme_encapsulated_request *nvme_encap_request)
{
u8 format = 0;
Expand All @@ -1866,7 +1866,7 @@ static unsigned int mpi3mr_get_nvme_data_fmt(
*
* Return: 0 on success, -1 on failure
*/
static int mpi3mr_build_nvme_sgl(struct mpi3mr_ioc *mrioc,
int mpi3mr_build_nvme_sgl(struct mpi3mr_ioc *mrioc,
struct mpi3_nvme_encapsulated_request *nvme_encap_request,
struct mpi3mr_buf_map *drv_bufs, u8 bufcnt)
{
Expand Down Expand Up @@ -1963,7 +1963,7 @@ static int mpi3mr_build_nvme_sgl(struct mpi3mr_ioc *mrioc,
*
* Return: 0 on success, -1 on failure
*/
static int mpi3mr_build_nvme_prp(struct mpi3mr_ioc *mrioc,
int mpi3mr_build_nvme_prp(struct mpi3mr_ioc *mrioc,
struct mpi3_nvme_encapsulated_request *nvme_encap_request,
struct mpi3mr_buf_map *drv_bufs, u8 bufcnt)
{
Expand Down Expand Up @@ -2237,9 +2237,9 @@ static int mpi3mr_build_nvme_prp(struct mpi3mr_ioc *mrioc,
*
* Return: 0 on success, -1 on failure
*/
static int mpi3mr_map_data_buffer_dma(struct mpi3mr_ioc *mrioc,
int mpi3mr_map_data_buffer_dma(struct mpi3mr_ioc *mrioc,
struct mpi3mr_buf_map *drv_buf,
u16 desc_count)
u16 desc_count, void *ubuf)
{
u16 i, needed_desc = drv_buf->kern_buf_len / MPI3MR_IOCTL_SGE_SIZE;
u32 buf_len = drv_buf->kern_buf_len, copied_len = 0;
Expand Down Expand Up @@ -2268,9 +2268,15 @@ static int mpi3mr_map_data_buffer_dma(struct mpi3mr_ioc *mrioc,
memset(drv_buf->dma_desc[i].addr, 0,
mrioc->ioctl_sge[desc_count].size);
if (drv_buf->data_dir == DMA_TO_DEVICE) {
memcpy(drv_buf->dma_desc[i].addr,
drv_buf->bsg_buf + copied_len,
drv_buf->dma_desc[i].size);
if (ubuf) {
if (copy_from_user(drv_buf->dma_desc[i].addr,
ubuf + copied_len, drv_buf->dma_desc[i].size))
return (-EFAULT);
} else {
memcpy(drv_buf->dma_desc[i].addr,
drv_buf->bsg_buf + copied_len,
drv_buf->dma_desc[i].size);
}
copied_len += drv_buf->dma_desc[i].size;
}
}
Expand Down Expand Up @@ -2542,7 +2548,8 @@ static long mpi3mr_bsg_process_mpt_cmds(struct bsg_job *job)
} else {
if (!drv_buf_iter->kern_buf_len)
continue;
if (mpi3mr_map_data_buffer_dma(mrioc, drv_buf_iter, desc_count)) {
if (mpi3mr_map_data_buffer_dma(mrioc, drv_buf_iter,
desc_count, NULL)) {
rval = -ENOMEM;
dprint_bsg_err(mrioc, "%s:%d: mapping data buffers failed\n",
__func__, __LINE__);
Expand Down
Loading

0 comments on commit 6c12015

Please sign in to comment.