]>
Commit | Line | Data |
---|---|---|
a86ec89e GI |
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 | struct nvme_command | |
35 | { | |
36 | /* dword 0 */ | |
37 | uint16_t opc : 8; /* opcode */ | |
38 | uint16_t fuse : 2; /* fused operation */ | |
39 | uint16_t rsvd1 : 6; | |
40 | uint16_t cid; /* command identifier */ | |
41 | ||
42 | /* dword 1 */ | |
43 | uint32_t nsid; /* namespace identifier */ | |
44 | ||
45 | /* dword 2-3 */ | |
46 | uint32_t rsvd2; | |
47 | uint32_t rsvd3; | |
48 | ||
49 | /* dword 4-5 */ | |
50 | uint64_t mptr; /* metadata pointer */ | |
51 | ||
52 | /* dword 6-7 */ | |
53 | uint64_t prp1; /* prp entry 1 */ | |
54 | ||
55 | /* dword 8-9 */ | |
56 | uint64_t prp2; /* prp entry 2 */ | |
57 | ||
58 | /* dword 10-15 */ | |
59 | uint32_t cdw10; /* command-specific */ | |
60 | uint32_t cdw11; /* command-specific */ | |
61 | uint32_t cdw12; /* command-specific */ | |
62 | uint32_t cdw13; /* command-specific */ | |
63 | uint32_t cdw14; /* command-specific */ | |
64 | uint32_t cdw15; /* command-specific */ | |
65 | } __packed; | |
66 | ||
67 | struct nvme_status { | |
68 | ||
69 | uint16_t p : 1; /* phase tag */ | |
70 | uint16_t sc : 8; /* status code */ | |
71 | uint16_t sct : 3; /* status code type */ | |
72 | uint16_t rsvd2 : 2; | |
73 | uint16_t m : 1; /* more */ | |
74 | uint16_t dnr : 1; /* do not retry */ | |
75 | } __packed; | |
76 | ||
77 | struct nvme_completion { | |
78 | ||
79 | /* dword 0 */ | |
80 | uint32_t cdw0; /* command-specific */ | |
81 | ||
82 | /* dword 1 */ | |
83 | uint32_t rsvd1; | |
84 | ||
85 | /* dword 2 */ | |
86 | uint16_t sqhd; /* submission queue head pointer */ | |
87 | uint16_t sqid; /* submission queue identifier */ | |
88 | ||
89 | /* dword 3 */ | |
90 | uint16_t cid; /* command identifier */ | |
91 | struct nvme_status status; | |
92 | } __packed; | |
93 | ||
94 | struct nvme_pt_command { | |
95 | ||
96 | /* | |
97 | * cmd is used to specify a passthrough command to a controller or | |
98 | * namespace. | |
99 | * | |
100 | * The following fields from cmd may be specified by the caller: | |
101 | * * opc (opcode) | |
102 | * * nsid (namespace id) - for admin commands only | |
103 | * * cdw10-cdw15 | |
104 | * | |
105 | * Remaining fields must be set to 0 by the caller. | |
106 | */ | |
107 | struct nvme_command cmd; | |
108 | ||
109 | /* | |
110 | * cpl returns completion status for the passthrough command | |
111 | * specified by cmd. | |
112 | * | |
113 | * The following fields will be filled out by the driver, for | |
114 | * consumption by the caller: | |
115 | * * cdw0 | |
116 | * * status (except for phase) | |
117 | * | |
118 | * Remaining fields will be set to 0 by the driver. | |
119 | */ | |
120 | struct nvme_completion cpl; | |
121 | ||
122 | /* buf is the data buffer associated with this passthrough command. */ | |
123 | void * buf; | |
124 | ||
125 | /* | |
126 | * len is the length of the data buffer associated with this | |
127 | * passthrough command. | |
128 | */ | |
129 | uint32_t len; | |
130 | ||
131 | /* | |
132 | * is_read = 1 if the passthrough command will read data into the | |
133 | * supplied buffer from the controller. | |
134 | * | |
135 | * is_read = 0 if the passthrough command will write data from the | |
136 | * supplied buffer to the controller. | |
137 | */ | |
138 | uint32_t is_read; | |
139 | ||
140 | /* | |
141 | * driver_lock is used by the driver only. It must be set to 0 | |
142 | * by the caller. | |
143 | */ | |
144 | struct mtx * driver_lock; | |
145 | }; | |
146 | ||
147 | #define nvme_completion_is_error(cpl) \ | |
148 | ((cpl)->status.sc != 0 || (cpl)->status.sct != 0) | |
149 | ||
150 | #define NVME_CTRLR_PREFIX "/dev/nvme" | |
151 | #define NVME_NS_PREFIX "ns" |