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