@@ -94,109 +94,137 @@ static int nvme_status_to_pr_err(int status)
94
94
}
95
95
}
96
96
97
- static int nvme_send_pr_command (struct block_device * bdev ,
98
- struct nvme_command * c , void * data , unsigned int data_len )
97
+ static int __nvme_send_pr_command (struct block_device * bdev , u32 cdw10 ,
98
+ u32 cdw11 , u8 op , void * data , unsigned int data_len )
99
99
{
100
- if (nvme_disk_is_ns_head (bdev -> bd_disk ))
101
- return nvme_send_ns_head_pr_command (bdev , c , data , data_len );
100
+ struct nvme_command c = { 0 };
102
101
103
- return nvme_send_ns_pr_command (bdev -> bd_disk -> private_data , c , data ,
104
- data_len );
102
+ c .common .opcode = op ;
103
+ c .common .cdw10 = cpu_to_le32 (cdw10 );
104
+ c .common .cdw11 = cpu_to_le32 (cdw11 );
105
+
106
+ if (nvme_disk_is_ns_head (bdev -> bd_disk ))
107
+ return nvme_send_ns_head_pr_command (bdev , & c , data , data_len );
108
+ return nvme_send_ns_pr_command (bdev -> bd_disk -> private_data , & c ,
109
+ data , data_len );
105
110
}
106
111
107
- static int nvme_pr_command (struct block_device * bdev , u32 cdw10 ,
108
- u64 key , u64 sa_key , u8 op )
112
+ static int nvme_send_pr_command (struct block_device * bdev , u32 cdw10 , u32 cdw11 ,
113
+ u8 op , void * data , unsigned int data_len )
109
114
{
110
- struct nvme_command c = { };
111
- u8 data [16 ] = { 0 , };
112
115
int ret ;
113
116
114
- put_unaligned_le64 (key , & data [0 ]);
115
- put_unaligned_le64 (sa_key , & data [8 ]);
116
-
117
- c .common .opcode = op ;
118
- c .common .cdw10 = cpu_to_le32 (cdw10 );
119
-
120
- ret = nvme_send_pr_command (bdev , & c , data , sizeof (data ));
121
- if (ret < 0 )
122
- return ret ;
123
-
124
- return nvme_status_to_pr_err (ret );
117
+ ret = __nvme_send_pr_command (bdev , cdw10 , cdw11 , op , data , data_len );
118
+ return ret < 0 ? ret : nvme_status_to_pr_err (ret );
125
119
}
126
120
127
- static int nvme_pr_register (struct block_device * bdev , u64 old ,
128
- u64 new , unsigned flags )
121
+ static int nvme_pr_register (struct block_device * bdev , u64 old_key , u64 new_key ,
122
+ unsigned int flags )
129
123
{
124
+ struct nvmet_pr_register_data data = { 0 };
130
125
u32 cdw10 ;
131
126
132
127
if (flags & ~PR_FL_IGNORE_KEY )
133
128
return - EOPNOTSUPP ;
134
129
135
- cdw10 = old ? 2 : 0 ;
136
- cdw10 |= (flags & PR_FL_IGNORE_KEY ) ? 1 << 3 : 0 ;
137
- cdw10 |= (1 << 30 ) | (1 << 31 ); /* PTPL=1 */
138
- return nvme_pr_command (bdev , cdw10 , old , new , nvme_cmd_resv_register );
130
+ data .crkey = cpu_to_le64 (old_key );
131
+ data .nrkey = cpu_to_le64 (new_key );
132
+
133
+ cdw10 = old_key ? NVME_PR_REGISTER_ACT_REPLACE :
134
+ NVME_PR_REGISTER_ACT_REG ;
135
+ cdw10 |= (flags & PR_FL_IGNORE_KEY ) ? NVME_PR_IGNORE_KEY : 0 ;
136
+ cdw10 |= NVME_PR_CPTPL_PERSIST ;
137
+
138
+ return nvme_send_pr_command (bdev , cdw10 , 0 , nvme_cmd_resv_register ,
139
+ & data , sizeof (data ));
139
140
}
140
141
141
142
static int nvme_pr_reserve (struct block_device * bdev , u64 key ,
142
143
enum pr_type type , unsigned flags )
143
144
{
145
+ struct nvmet_pr_acquire_data data = { 0 };
144
146
u32 cdw10 ;
145
147
146
148
if (flags & ~PR_FL_IGNORE_KEY )
147
149
return - EOPNOTSUPP ;
148
150
149
- cdw10 = nvme_pr_type_from_blk (type ) << 8 ;
150
- cdw10 |= ((flags & PR_FL_IGNORE_KEY ) ? 1 << 3 : 0 );
151
- return nvme_pr_command (bdev , cdw10 , key , 0 , nvme_cmd_resv_acquire );
151
+ data .crkey = cpu_to_le64 (key );
152
+
153
+ cdw10 = NVME_PR_ACQUIRE_ACT_ACQUIRE ;
154
+ cdw10 |= nvme_pr_type_from_blk (type ) << 8 ;
155
+ cdw10 |= (flags & PR_FL_IGNORE_KEY ) ? NVME_PR_IGNORE_KEY : 0 ;
156
+
157
+ return nvme_send_pr_command (bdev , cdw10 , 0 , nvme_cmd_resv_acquire ,
158
+ & data , sizeof (data ));
152
159
}
153
160
154
161
static int nvme_pr_preempt (struct block_device * bdev , u64 old , u64 new ,
155
162
enum pr_type type , bool abort )
156
163
{
157
- u32 cdw10 = nvme_pr_type_from_blk (type ) << 8 | (abort ? 2 : 1 );
164
+ struct nvmet_pr_acquire_data data = { 0 };
165
+ u32 cdw10 ;
166
+
167
+ data .crkey = cpu_to_le64 (old );
168
+ data .prkey = cpu_to_le64 (new );
158
169
159
- return nvme_pr_command (bdev , cdw10 , old , new , nvme_cmd_resv_acquire );
170
+ cdw10 = abort ? NVME_PR_ACQUIRE_ACT_PREEMPT_AND_ABORT :
171
+ NVME_PR_ACQUIRE_ACT_PREEMPT ;
172
+ cdw10 |= nvme_pr_type_from_blk (type ) << 8 ;
173
+
174
+ return nvme_send_pr_command (bdev , cdw10 , 0 , nvme_cmd_resv_acquire ,
175
+ & data , sizeof (data ));
160
176
}
161
177
162
178
static int nvme_pr_clear (struct block_device * bdev , u64 key )
163
179
{
164
- u32 cdw10 = 1 | (key ? 0 : 1 << 3 );
180
+ struct nvmet_pr_release_data data = { 0 };
181
+ u32 cdw10 ;
182
+
183
+ data .crkey = cpu_to_le64 (key );
165
184
166
- return nvme_pr_command (bdev , cdw10 , key , 0 , nvme_cmd_resv_release );
185
+ cdw10 = NVME_PR_RELEASE_ACT_CLEAR ;
186
+ cdw10 |= key ? 0 : NVME_PR_IGNORE_KEY ;
187
+
188
+ return nvme_send_pr_command (bdev , cdw10 , 0 , nvme_cmd_resv_release ,
189
+ & data , sizeof (data ));
167
190
}
168
191
169
192
static int nvme_pr_release (struct block_device * bdev , u64 key , enum pr_type type )
170
193
{
171
- u32 cdw10 = nvme_pr_type_from_blk (type ) << 8 | (key ? 0 : 1 << 3 );
194
+ struct nvmet_pr_release_data data = { 0 };
195
+ u32 cdw10 ;
196
+
197
+ data .crkey = cpu_to_le64 (key );
172
198
173
- return nvme_pr_command (bdev , cdw10 , key , 0 , nvme_cmd_resv_release );
199
+ cdw10 = NVME_PR_RELEASE_ACT_RELEASE ;
200
+ cdw10 |= nvme_pr_type_from_blk (type ) << 8 ;
201
+ cdw10 |= key ? 0 : NVME_PR_IGNORE_KEY ;
202
+
203
+ return nvme_send_pr_command (bdev , cdw10 , 0 , nvme_cmd_resv_release ,
204
+ & data , sizeof (data ));
174
205
}
175
206
176
207
static int nvme_pr_resv_report (struct block_device * bdev , void * data ,
177
208
u32 data_len , bool * eds )
178
209
{
179
- struct nvme_command c = { } ;
210
+ u32 cdw10 , cdw11 ;
180
211
int ret ;
181
212
182
- c .common .opcode = nvme_cmd_resv_report ;
183
- c .common .cdw10 = cpu_to_le32 (nvme_bytes_to_numd (data_len ));
184
- c .common .cdw11 = cpu_to_le32 (NVME_EXTENDED_DATA_STRUCT );
213
+ cdw10 = nvme_bytes_to_numd (data_len );
214
+ cdw11 = NVME_EXTENDED_DATA_STRUCT ;
185
215
* eds = true;
186
216
187
217
retry :
188
- ret = nvme_send_pr_command (bdev , & c , data , data_len );
218
+ ret = __nvme_send_pr_command (bdev , cdw10 , cdw11 , nvme_cmd_resv_report ,
219
+ data , data_len );
189
220
if (ret == NVME_SC_HOST_ID_INCONSIST &&
190
- c . common . cdw11 == cpu_to_le32 ( NVME_EXTENDED_DATA_STRUCT ) ) {
191
- c . common . cdw11 = 0 ;
221
+ cdw11 == NVME_EXTENDED_DATA_STRUCT ) {
222
+ cdw11 = 0 ;
192
223
* eds = false;
193
224
goto retry ;
194
225
}
195
226
196
- if (ret < 0 )
197
- return ret ;
198
-
199
- return nvme_status_to_pr_err (ret );
227
+ return ret < 0 ? ret : nvme_status_to_pr_err (ret );
200
228
}
201
229
202
230
static int nvme_pr_read_keys (struct block_device * bdev ,
0 commit comments