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