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