nvme: add support for DIOCGIDENT
Add support for the DIOCGIDENT ioctl to both nvme controller device nodes and namespace device nodes. This information was already available via the nda(4) device node. However, mapping /dev/nvmeX to /dev/ndaY device nodes is not straightforward, so it's better to get it directly from the /dev/nvme device node. PR: 290259 MFC after: 2 weeks Sponsored by: ConnectWise Submitted by: imp (mostly) Pull Request: https://github.com/freebsd/freebsd-src/pull/1875
This commit is contained in:
@@ -33,6 +33,7 @@
|
||||
#include <sys/buf.h>
|
||||
#include <sys/bus.h>
|
||||
#include <sys/conf.h>
|
||||
#include <sys/disk.h>
|
||||
#include <sys/ioccom.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/smp.h>
|
||||
@@ -1253,6 +1254,24 @@ nvme_ctrlr_poll(struct nvme_controller *ctrlr)
|
||||
nvme_qpair_process_completions(&ctrlr->ioq[i]);
|
||||
}
|
||||
|
||||
/*
|
||||
* Copy the NVME device's serial number to the provided buffer, which must be
|
||||
* at least DISK_IDENT_SIZE bytes large.
|
||||
*/
|
||||
void
|
||||
nvme_ctrlr_get_ident(const struct nvme_controller *ctrlr, uint8_t *sn)
|
||||
{
|
||||
_Static_assert(NVME_SERIAL_NUMBER_LENGTH < DISK_IDENT_SIZE,
|
||||
"NVME serial number too big for disk ident");
|
||||
|
||||
memmove(sn, ctrlr->cdata.sn, NVME_SERIAL_NUMBER_LENGTH);
|
||||
sn[NVME_SERIAL_NUMBER_LENGTH] = '\0';
|
||||
for (int i = 0; sn[i] != '\0'; i++) {
|
||||
if (sn[i] < 0x20 || sn[i] >= 0x80)
|
||||
sn[i] = ' ';
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Poll the single-vector interrupt case: num_io_queues will be 1 and
|
||||
* there's only a single vector. While we're polling, we mask further
|
||||
@@ -1495,6 +1514,11 @@ nvme_ctrlr_ioctl(struct cdev *cdev, u_long cmd, caddr_t arg, int flag,
|
||||
case NVME_GET_CONTROLLER_DATA:
|
||||
memcpy(arg, &ctrlr->cdata, sizeof(ctrlr->cdata));
|
||||
break;
|
||||
case DIOCGIDENT: {
|
||||
uint8_t *sn = arg;
|
||||
nvme_ctrlr_get_ident(ctrlr, sn);
|
||||
break;
|
||||
}
|
||||
/* Linux Compatible (see nvme_linux.h) */
|
||||
case NVME_IOCTL_ID:
|
||||
td->td_retval[0] = 0xfffffffful;
|
||||
|
||||
@@ -88,6 +88,11 @@ nvme_ns_ioctl(struct cdev *cdev, u_long cmd, caddr_t arg, int flag,
|
||||
gnsid->nsid = ns->id;
|
||||
break;
|
||||
}
|
||||
case DIOCGIDENT: {
|
||||
uint8_t *sn = arg;
|
||||
nvme_ctrlr_get_ident(ctrlr, sn);
|
||||
break;
|
||||
}
|
||||
case DIOCGMEDIASIZE:
|
||||
*(off_t *)arg = (off_t)nvme_ns_get_size(ns);
|
||||
break;
|
||||
|
||||
@@ -563,6 +563,7 @@ void nvme_notify_new_controller(struct nvme_controller *ctrlr);
|
||||
void nvme_notify_ns(struct nvme_controller *ctrlr, int nsid);
|
||||
|
||||
void nvme_ctrlr_shared_handler(void *arg);
|
||||
void nvme_ctrlr_get_ident(const struct nvme_controller *ctrlr, uint8_t *sn);
|
||||
void nvme_ctrlr_poll(struct nvme_controller *ctrlr);
|
||||
|
||||
int nvme_ctrlr_suspend(struct nvme_controller *ctrlr);
|
||||
|
||||
Reference in New Issue
Block a user