smartmontools SVN Rev 5645
Utility to control and monitor storage systems with "S.M.A.R.T."
freebsd_nvme_ioctl.h
Go to the documentation of this file.
1/*-
2 * Copyright (C) 2012-2013 Intel Corporation
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD$
27 */
28
29
30#include <sys/param.h>
31
32#define NVME_PASSTHROUGH_CMD _IOWR('n', 0, struct nvme_pt_command)
33
34#if __FreeBSD_version < 1100110
36{
37 /* dword 0 */
38 uint16_t opc : 8; /* opcode */
39 uint16_t fuse : 2; /* fused operation */
40 uint16_t rsvd1 : 6;
41 uint16_t cid; /* command identifier */
42
43 /* dword 1 */
44 uint32_t nsid; /* namespace identifier */
45
46 /* dword 2-3 */
47 uint32_t rsvd2;
48 uint32_t rsvd3;
49
50 /* dword 4-5 */
51 uint64_t mptr; /* metadata pointer */
52
53 /* dword 6-7 */
54 uint64_t prp1; /* prp entry 1 */
55
56 /* dword 8-9 */
57 uint64_t prp2; /* prp entry 2 */
58
59 /* dword 10-15 */
60 uint32_t cdw10; /* command-specific */
61 uint32_t cdw11; /* command-specific */
62 uint32_t cdw12; /* command-specific */
63 uint32_t cdw13; /* command-specific */
64 uint32_t cdw14; /* command-specific */
65 uint32_t cdw15; /* command-specific */
67
69
70 uint16_t p : 1; /* phase tag */
71 uint16_t sc : 8; /* status code */
72 uint16_t sct : 3; /* status code type */
73 uint16_t rsvd2 : 2;
74 uint16_t m : 1; /* more */
75 uint16_t dnr : 1; /* do not retry */
76} __packed;
77
79
80 /* dword 0 */
81 uint32_t cdw0; /* command-specific */
82
83 /* dword 1 */
84 uint32_t rsvd1;
85
86 /* dword 2 */
87 uint16_t sqhd; /* submission queue head pointer */
88 uint16_t sqid; /* submission queue identifier */
89
90 /* dword 3 */
91 uint16_t cid; /* command identifier */
93} __packed;
94
96
97 /*
98 * cmd is used to specify a passthrough command to a controller or
99 * namespace.
100 *
101 * The following fields from cmd may be specified by the caller:
102 * * opc (opcode)
103 * * nsid (namespace id) - for admin commands only
104 * * cdw10-cdw15
105 *
106 * Remaining fields must be set to 0 by the caller.
107 */
109
110 /*
111 * cpl returns completion status for the passthrough command
112 * specified by cmd.
113 *
114 * The following fields will be filled out by the driver, for
115 * consumption by the caller:
116 * * cdw0
117 * * status (except for phase)
118 *
119 * Remaining fields will be set to 0 by the driver.
120 */
122
123 /* buf is the data buffer associated with this passthrough command. */
124 void * buf;
125
126 /*
127 * len is the length of the data buffer associated with this
128 * passthrough command.
129 */
130 uint32_t len;
131
132 /*
133 * is_read = 1 if the passthrough command will read data into the
134 * supplied buffer from the controller.
135 *
136 * is_read = 0 if the passthrough command will write data from the
137 * supplied buffer to the controller.
138 */
139 uint32_t is_read;
140
141 /*
142 * driver_lock is used by the driver only. It must be set to 0
143 * by the caller.
144 */
145 struct mtx * driver_lock;
146};
147#else
148#include <dev/nvme/nvme.h>
149#endif
150
151#if __FreeBSD_version < 1200058
152#define nvme_completion_is_error(cpl) \
153 ((cpl)->status.sc != 0 || (cpl)->status.sct != 0)
154#endif
155
156#define NVME_CTRLR_PREFIX "/dev/nvme"
157#define NVME_NS_PREFIX "ns"
struct nvme_command __packed
struct nvme_status status
struct nvme_command cmd
struct mtx * driver_lock
struct nvme_completion cpl