Skip to content

Commit

Permalink
linux: Translate Linux NVME ioctls to the lower layers.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Chuck Tuffli authored and bsdimp committed Jun 14, 2024
1 parent 1bce7cd commit ad9cc86
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
35 changes: 35 additions & 0 deletions sys/compat/linux/linux_ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 = { \
Expand All @@ -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

Expand Down Expand Up @@ -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
*/
Expand Down
14 changes: 14 additions & 0 deletions sys/compat/linux/linux_ioctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit ad9cc86

Please sign in to comment.