Fix NVMe's use of XPT_GDEV_TYPE

This patch changes the way XPT_GDEV_TYPE works for NVMe. The current
ccb_getdev structure includes pointers to the NVMe Identify Controller
and Namespace structures, but these are kernel virtual addresses which
are not accessible from user space.

As an alternative, the patch changes the pointers into padding in
ccb_getdev and adds two new types to ccb_dev_advinfo to retrieve the
Identify Controller (CDAI_TYPE_NVME_CNTRL) and Namespace
(CDAI_TYPE_NVME_NS) data structures.

Reviewed By: rpokala, imp
Differential Revision: https://reviews.freebsd.org/D10466
Submitted by: Chuck Tuffli
This commit is contained in:
Warner Losh 2017-08-29 17:03:30 +00:00
parent c2005bba77
commit 9f8ed7e40b
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=322999
6 changed files with 54 additions and 26 deletions

View file

@ -366,8 +366,7 @@ struct ccb_getdev {
u_int8_t serial_num[252];
u_int8_t inq_flags;
u_int8_t serial_num_len;
const struct nvme_controller_data *nvme_cdata;
const struct nvme_namespace_data *nvme_data;
void *padding[2];
};
/* Device Statistics CCB */
@ -1267,6 +1266,8 @@ struct ccb_dev_advinfo {
#define CDAI_TYPE_PHYS_PATH 3
#define CDAI_TYPE_RCAPLONG 4
#define CDAI_TYPE_EXT_INQ 5
#define CDAI_TYPE_NVME_CNTRL 6 /* NVMe Identify Controller data */
#define CDAI_TYPE_NVME_NS 7 /* NVMe Identify Namespace data */
off_t bufsiz; /* IN: Size of external buffer */
#define CAM_SCSI_DEVID_MAXLEN 65536 /* length in buffer is an uint16_t */
off_t provsiz; /* OUT: Size required/used */

View file

@ -2834,8 +2834,6 @@ xpt_action_default(union ccb *start_ccb)
cgd->inq_data = dev->inq_data;
cgd->ident_data = dev->ident_data;
cgd->inq_flags = dev->inq_flags;
cgd->nvme_data = dev->nvme_data;
cgd->nvme_cdata = dev->nvme_cdata;
cgd->ccb_h.status = CAM_REQ_CMP;
cgd->serial_num_len = dev->serial_num_len;
if ((dev->serial_num_len > 0)

View file

@ -35,6 +35,7 @@ __FBSDID("$FreeBSD$");
#include <sys/systm.h>
#include <sys/libkern.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/sysctl.h>
#else
#include <errno.h>
@ -54,6 +55,13 @@ __FBSDID("$FreeBSD$");
#include <sys/sbuf.h>
#include <sys/endian.h>
#ifdef _KERNEL
#include <cam/cam_periph.h>
#include <cam/cam_xpt_sim.h>
#include <cam/cam_xpt_periph.h>
#include <cam/cam_xpt_internal.h>
#endif
void
nvme_ns_cmd(struct ccb_nvmeio *nvmeio, uint8_t cmd, uint32_t nsid,
uint32_t cdw10, uint32_t cdw11, uint32_t cdw12, uint32_t cdw13,
@ -122,3 +130,23 @@ nvme_cmd_string(const struct nvme_command *cmd, char *cmd_string, size_t len)
return cmd_string;
}
const void *
nvme_get_identify_cntrl(struct cam_periph *periph)
{
struct cam_ed *device;
device = periph->path->device;
return device->nvme_cdata;
}
const void *
nvme_get_identify_ns(struct cam_periph *periph)
{
struct cam_ed *device;
device = periph->path->device;
return device->nvme_data;
}

View file

@ -44,5 +44,7 @@ int nvme_identify_match(caddr_t identbuffer, caddr_t table_entry);
void nvme_print_ident(const struct nvme_controller_data *, const struct nvme_namespace_data *);
const char *nvme_op_string(const struct nvme_command *);
const char *nvme_cmd_string(const struct nvme_command *, char *, size_t);
const void *nvme_get_identify_cntrl(struct cam_periph *);
const void *nvme_get_identify_ns(struct cam_periph *);
#endif /* CAM_NVME_NVME_ALL_H */

View file

@ -684,21 +684,14 @@ ndaregister(struct cam_periph *periph, void *arg)
struct nda_softc *softc;
struct disk *disk;
struct ccb_pathinq cpi;
struct ccb_getdev *cgd;
const struct nvme_namespace_data *nsd;
const struct nvme_controller_data *cd;
char announce_buf[80];
// caddr_t match;
u_int maxio;
int quirks;
cgd = (struct ccb_getdev *)arg;
if (cgd == NULL) {
printf("ndaregister: no getdev CCB, can't register device\n");
return(CAM_REQ_CMP_ERR);
}
nsd = cgd->nvme_data;
cd = cgd->nvme_cdata;
nsd = nvme_get_identify_ns(periph);
cd = nvme_get_identify_cntrl(periph);
softc = (struct nda_softc *)malloc(sizeof(*softc), M_DEVBUF,
M_NOWAIT | M_ZERO);
@ -719,19 +712,7 @@ ndaregister(struct cam_periph *periph, void *arg)
periph->softc = softc;
#if 0
/*
* See if this device has any quirks.
*/
match = cam_quirkmatch((caddr_t)&cgd->ident_data,
(caddr_t)nda_quirk_table,
sizeof(nda_quirk_table)/sizeof(*nda_quirk_table),
sizeof(*nda_quirk_table), ata_identify_match);
if (match != NULL)
softc->quirks = ((struct nda_quirk_entry *)match)->quirks;
else
#endif
softc->quirks = NDA_Q_NONE;
softc->quirks = NDA_Q_NONE;
bzero(&cpi, sizeof(cpi));
xpt_setup_ccb(&cpi.ccb_h, periph->path, CAM_PRIORITY_NONE);

View file

@ -538,6 +538,24 @@ nvme_dev_advinfo(union ccb *start_ccb)
memcpy(cdai->buf, device->physpath, amt);
}
break;
case CDAI_TYPE_NVME_CNTRL:
if (cdai->flags & CDAI_FLAG_STORE)
return;
amt = sizeof(struct nvme_controller_data);
cdai->provsiz = amt;
if (amt > cdai->bufsiz)
amt = cdai->bufsiz;
memcpy(cdai->buf, device->nvme_cdata, amt);
break;
case CDAI_TYPE_NVME_NS:
if (cdai->flags & CDAI_FLAG_STORE)
return;
amt = sizeof(struct nvme_namespace_data);
cdai->provsiz = amt;
if (amt > cdai->bufsiz)
amt = cdai->bufsiz;
memcpy(cdai->buf, device->nvme_data, amt);
break;
default:
return;
}