diff options
author | Chuck Tuffli <chuck@FreeBSD.org> | 2018-08-22 04:29:24 +0000 |
---|---|---|
committer | Chuck Tuffli <chuck@FreeBSD.org> | 2018-08-22 04:29:24 +0000 |
commit | 9544e6dcf1f338af481614dc5daf232e1ed5860b (patch) | |
tree | 6fdb66a56676d2112c97b1dc6282b2632a86dbd6 /sbin/nvmecontrol | |
parent | d3878608d735ec8610b04e3f2195a436c7f56e15 (diff) | |
download | src-9544e6dcf1f338af481614dc5daf232e1ed5860b.tar.gz src-9544e6dcf1f338af481614dc5daf232e1ed5860b.zip |
Make NVMe compatible with the original API
The original NVMe API used bit-fields to represent fields in data
structures defined by the specification (e.g. the op-code in the command
data structure). The implementation targeted x86_64 processors and
defined the bit fields for little endian dwords (i.e. 32 bits).
This approach does not work as-is for big endian architectures and was
changed to use a combination of bit shifts and masks to support PowerPC.
Unfortunately, this changed the NVMe API and forces #ifdef's based on
the OS revision level in user space code.
This change reverts to something that looks like the original API, but
it uses bytes instead of bit-fields inside the packed command structure.
As a bonus, this works as-is for both big and little endian CPU
architectures.
Bump __FreeBSD_version to 1200081 due to API change
Reviewed by: imp, kbowling, smh, mav
Approved by: imp (mentor)
Differential Revision: https://reviews.freebsd.org/D16404
Notes
Notes:
svn path=/head/; revision=338182
Diffstat (limited to 'sbin/nvmecontrol')
-rw-r--r-- | sbin/nvmecontrol/firmware.c | 4 | ||||
-rw-r--r-- | sbin/nvmecontrol/format.c | 2 | ||||
-rw-r--r-- | sbin/nvmecontrol/logpage.c | 2 | ||||
-rw-r--r-- | sbin/nvmecontrol/ns.c | 12 | ||||
-rw-r--r-- | sbin/nvmecontrol/nvmecontrol.c | 4 | ||||
-rw-r--r-- | sbin/nvmecontrol/power.c | 4 | ||||
-rw-r--r-- | sbin/nvmecontrol/wdc.c | 2 |
7 files changed, 15 insertions, 15 deletions
diff --git a/sbin/nvmecontrol/firmware.c b/sbin/nvmecontrol/firmware.c index 8857cc08cc5a..473da9b872d2 100644 --- a/sbin/nvmecontrol/firmware.c +++ b/sbin/nvmecontrol/firmware.c @@ -125,7 +125,7 @@ update_firmware(int fd, uint8_t *payload, int32_t payload_size) memcpy(chunk, payload + off, size); memset(&pt, 0, sizeof(pt)); - pt.cmd.opc_fuse = NVME_CMD_SET_OPC(NVME_OPC_FIRMWARE_IMAGE_DOWNLOAD); + pt.cmd.opc = NVME_OPC_FIRMWARE_IMAGE_DOWNLOAD; pt.cmd.cdw10 = htole32((size / sizeof(uint32_t)) - 1); pt.cmd.cdw11 = htole32(off / sizeof(uint32_t)); pt.buf = chunk; @@ -150,7 +150,7 @@ activate_firmware(int fd, int slot, int activate_action) uint16_t sct, sc; memset(&pt, 0, sizeof(pt)); - pt.cmd.opc_fuse = NVME_CMD_SET_OPC(NVME_OPC_FIRMWARE_ACTIVATE); + pt.cmd.opc = NVME_OPC_FIRMWARE_ACTIVATE; pt.cmd.cdw10 = htole32((activate_action << 3) | slot); pt.is_read = 0; diff --git a/sbin/nvmecontrol/format.c b/sbin/nvmecontrol/format.c index 26850f1dbc7f..1463af1e45ae 100644 --- a/sbin/nvmecontrol/format.c +++ b/sbin/nvmecontrol/format.c @@ -172,7 +172,7 @@ format(int argc, char *argv[]) } memset(&pt, 0, sizeof(pt)); - pt.cmd.opc_fuse = NVME_CMD_SET_OPC(NVME_OPC_FORMAT_NVM); + pt.cmd.opc = NVME_OPC_FORMAT_NVM; pt.cmd.nsid = htole32(nsid); pt.cmd.cdw10 = htole32((ses << 9) + (pil << 8) + (pi << 5) + (mset << 4) + lbaf); diff --git a/sbin/nvmecontrol/logpage.c b/sbin/nvmecontrol/logpage.c index e617bcd921ce..82c08ddd00b0 100644 --- a/sbin/nvmecontrol/logpage.c +++ b/sbin/nvmecontrol/logpage.c @@ -107,7 +107,7 @@ read_logpage(int fd, uint8_t log_page, uint32_t nsid, void *payload, int i, err_pages; memset(&pt, 0, sizeof(pt)); - pt.cmd.opc_fuse = NVME_CMD_SET_OPC(NVME_OPC_GET_LOG_PAGE); + pt.cmd.opc = NVME_OPC_GET_LOG_PAGE; pt.cmd.nsid = htole32(nsid); pt.cmd.cdw10 = ((payload_size/sizeof(uint32_t)) - 1) << 16; pt.cmd.cdw10 |= log_page; diff --git a/sbin/nvmecontrol/ns.c b/sbin/nvmecontrol/ns.c index 58dad083242a..bcc0da54dfe4 100644 --- a/sbin/nvmecontrol/ns.c +++ b/sbin/nvmecontrol/ns.c @@ -216,7 +216,7 @@ nscreate(int argc, char *argv[]) nvme_namespace_data_swapbytes(&nsdata); memset(&pt, 0, sizeof(pt)); - pt.cmd.opc_fuse = NVME_CMD_SET_OPC(NVME_OPC_NAMESPACE_MANAGEMENT); + pt.cmd.opc = NVME_OPC_NAMESPACE_MANAGEMENT; pt.cmd.cdw10 = 0; /* create */ pt.buf = &nsdata; @@ -267,7 +267,7 @@ nsdelete(int argc, char *argv[]) errx(1, "controller does not support namespace management"); memset(&pt, 0, sizeof(pt)); - pt.cmd.opc_fuse = NVME_CMD_SET_OPC(NVME_OPC_NAMESPACE_MANAGEMENT); + pt.cmd.opc = NVME_OPC_NAMESPACE_MANAGEMENT; pt.cmd.cdw10 = 1; /* delete */ pt.buf = buf; pt.len = sizeof(buf); @@ -343,7 +343,7 @@ nsattach(int argc, char *argv[]) if (ctrlrid == -1) { /* Get full list of controllers to attach to. */ memset(&pt, 0, sizeof(pt)); - pt.cmd.opc_fuse = NVME_CMD_SET_OPC(NVME_OPC_IDENTIFY); + pt.cmd.opc = NVME_OPC_IDENTIFY; pt.cmd.cdw10 = htole32(0x13); pt.buf = clist; pt.len = sizeof(clist); @@ -362,7 +362,7 @@ nsattach(int argc, char *argv[]) } memset(&pt, 0, sizeof(pt)); - pt.cmd.opc_fuse = NVME_CMD_SET_OPC(NVME_OPC_NAMESPACE_ATTACHMENT); + pt.cmd.opc = NVME_OPC_NAMESPACE_ATTACHMENT; pt.cmd.cdw10 = 0; /* attach */ pt.cmd.nsid = (uint32_t)nsid; pt.buf = &clist; @@ -422,7 +422,7 @@ nsdetach(int argc, char *argv[]) if (ctrlrid == -1) { /* Get list of controllers this namespace attached to. */ memset(&pt, 0, sizeof(pt)); - pt.cmd.opc_fuse = NVME_CMD_SET_OPC(NVME_OPC_IDENTIFY); + pt.cmd.opc = NVME_OPC_IDENTIFY; pt.cmd.nsid = htole32(nsid); pt.cmd.cdw10 = htole32(0x12); pt.buf = clist; @@ -448,7 +448,7 @@ nsdetach(int argc, char *argv[]) } memset(&pt, 0, sizeof(pt)); - pt.cmd.opc_fuse = NVME_CMD_SET_OPC(NVME_OPC_NAMESPACE_ATTACHMENT); + pt.cmd.opc = NVME_OPC_NAMESPACE_ATTACHMENT; pt.cmd.cdw10 = 1; /* detach */ pt.cmd.nsid = (uint32_t)nsid; pt.buf = &clist; diff --git a/sbin/nvmecontrol/nvmecontrol.c b/sbin/nvmecontrol/nvmecontrol.c index 0074816b3061..80f9af710674 100644 --- a/sbin/nvmecontrol/nvmecontrol.c +++ b/sbin/nvmecontrol/nvmecontrol.c @@ -148,7 +148,7 @@ read_controller_data(int fd, struct nvme_controller_data *cdata) struct nvme_pt_command pt; memset(&pt, 0, sizeof(pt)); - pt.cmd.opc_fuse = NVME_CMD_SET_OPC(NVME_OPC_IDENTIFY); + pt.cmd.opc = NVME_OPC_IDENTIFY; pt.cmd.cdw10 = htole32(1); pt.buf = cdata; pt.len = sizeof(*cdata); @@ -170,7 +170,7 @@ read_namespace_data(int fd, uint32_t nsid, struct nvme_namespace_data *nsdata) struct nvme_pt_command pt; memset(&pt, 0, sizeof(pt)); - pt.cmd.opc_fuse = NVME_CMD_SET_OPC(NVME_OPC_IDENTIFY); + pt.cmd.opc = NVME_OPC_IDENTIFY; pt.cmd.nsid = htole32(nsid); pt.buf = nsdata; pt.len = sizeof(*nsdata); diff --git a/sbin/nvmecontrol/power.c b/sbin/nvmecontrol/power.c index 9e60796af62b..07bdcd521adf 100644 --- a/sbin/nvmecontrol/power.c +++ b/sbin/nvmecontrol/power.c @@ -104,7 +104,7 @@ power_set(int fd, int power_val, int workload, int perm) p = perm ? (1u << 31) : 0; memset(&pt, 0, sizeof(pt)); - pt.cmd.opc_fuse = NVME_CMD_SET_OPC(NVME_OPC_SET_FEATURES); + pt.cmd.opc = NVME_OPC_SET_FEATURES; pt.cmd.cdw10 = htole32(NVME_FEAT_POWER_MANAGEMENT | p); pt.cmd.cdw11 = htole32(power_val | (workload << 5)); @@ -121,7 +121,7 @@ power_show(int fd) struct nvme_pt_command pt; memset(&pt, 0, sizeof(pt)); - pt.cmd.opc_fuse = NVME_CMD_SET_OPC(NVME_OPC_GET_FEATURES); + pt.cmd.opc = NVME_OPC_GET_FEATURES; pt.cmd.cdw10 = htole32(NVME_FEAT_POWER_MANAGEMENT); if (ioctl(fd, NVME_PASSTHROUGH_CMD, &pt) < 0) diff --git a/sbin/nvmecontrol/wdc.c b/sbin/nvmecontrol/wdc.c index f0291e5e2443..58ebe880a765 100644 --- a/sbin/nvmecontrol/wdc.c +++ b/sbin/nvmecontrol/wdc.c @@ -81,7 +81,7 @@ wdc_get_data(int fd, uint32_t opcode, uint32_t len, uint32_t off, uint32_t cmd, struct nvme_pt_command pt; memset(&pt, 0, sizeof(pt)); - pt.cmd.opc_fuse = NVME_CMD_SET_OPC(opcode); + pt.cmd.opc = opcode; pt.cmd.cdw10 = htole32(len / sizeof(uint32_t)); /* - 1 like all the others ??? */ pt.cmd.cdw11 = htole32(off / sizeof(uint32_t)); pt.cmd.cdw12 = htole32(cmd); |