linux: Translate Linux NVME ioctls to the lower layers.

The lower layers implement a ABI compatible Linux ioctl for a few of the
Linux IOCTLs. Translate them and pass them down. Since they are ABI
compatible, just use the nvme ioctl name.

Co-Authored-by: Warner Losh <imp@bsdimp.com>
Reviewed by:	chuck
Differential Revision:	https://reviews.freebsd.org/D45416
This commit is contained in:
Chuck Tuffli 2024-06-14 16:40:20 -06:00 committed by Warner Losh
parent 1bce7cd885
commit ad9cc86bf6
2 changed files with 49 additions and 0 deletions

View file

@ -83,6 +83,8 @@
#include <cam/scsi/scsi_sg.h>
#include <dev/nvme/nvme_linux.h>
#define DEFINE_LINUX_IOCTL_SET(shortname, SHORTNAME) \
static linux_ioctl_function_t linux_ioctl_ ## shortname; \
static struct linux_ioctl_handler shortname ## _handler = { \
@ -108,6 +110,9 @@ DEFINE_LINUX_IOCTL_SET(v4l2, VIDEO2);
DEFINE_LINUX_IOCTL_SET(fbsd_usb, FBSD_LUSB);
DEFINE_LINUX_IOCTL_SET(evdev, EVDEV);
DEFINE_LINUX_IOCTL_SET(kcov, KCOV);
#ifndef COMPAT_LINUX32
DEFINE_LINUX_IOCTL_SET(nvme, NVME);
#endif
#undef DEFINE_LINUX_IOCTL_SET
@ -3531,6 +3536,36 @@ linux_ioctl_kcov(struct thread *td, struct linux_ioctl_args *args)
return (error);
}
#ifndef COMPAT_LINUX32
static int
linux_ioctl_nvme(struct thread *td, struct linux_ioctl_args *args)
{
/*
* The NVMe drivers for namespace and controller implement these
* commands using their native format. All the others are not
* implemented yet.
*/
switch (args->cmd & 0xffff) {
case LINUX_NVME_IOCTL_ID:
args->cmd = NVME_IOCTL_ID;
break;
case LINUX_NVME_IOCTL_RESET:
args->cmd = NVME_IOCTL_RESET;
break;
case LINUX_NVME_IOCTL_ADMIN_CMD:
args->cmd = NVME_IOCTL_ADMIN_CMD;
break;
case LINUX_NVME_IOCTL_IO_CMD:
args->cmd = NVME_IOCTL_IO_CMD;
break;
default:
return (ENODEV);
}
return (sys_ioctl(td, (struct ioctl_args *)args));
}
#endif
/*
* main ioctl syscall function
*/

View file

@ -781,6 +781,20 @@
#define LINUX_KCOV_DISABLE 0x6365
#define LINUX_KCOV_REMOTE_ENABLE 0x6366
/*
* NVMe IOCTLs defined by Linux
*/
#define LINUX_NVME_IOCTL_ID 0x4e40
#define LINUX_NVME_IOCTL_ADMIN_CMD 0x4e41
#define LINUX_NVME_IOCTL_SUBMIT_IO 0x4e42
#define LINUX_NVME_IOCTL_IO_CMD 0x4e43
#define LINUX_NVME_IOCTL_RESET 0x4e44
#define LINUX_NVME_IOCTL_SUBSYS_RESET 0x4e45
#define LINUX_NVME_IOCTL_RESCAN 0x4e46
#define LINUX_IOCTL_NVME_MIN LINUX_NVME_IOCTL_ID
#define LINUX_IOCTL_NVME_MAX LINUX_NVME_IOCTL_RESCAN
/*
* Pluggable ioctl handlers
*/