2 * NVM Express device driver
3 * Copyright (c) 2011-2014, Intel Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * Refer to the SCSI-NVMe Translation spec for details on how
17 * each command is translated.
20 #include <linux/bio.h>
21 #include <linux/bitops.h>
22 #include <linux/blkdev.h>
23 #include <linux/compat.h>
24 #include <linux/delay.h>
25 #include <linux/errno.h>
27 #include <linux/genhd.h>
28 #include <linux/idr.h>
29 #include <linux/init.h>
30 #include <linux/interrupt.h>
32 #include <linux/kdev_t.h>
33 #include <linux/kthread.h>
34 #include <linux/kernel.h>
36 #include <linux/module.h>
37 #include <linux/moduleparam.h>
38 #include <linux/pci.h>
39 #include <linux/poison.h>
40 #include <linux/sched.h>
41 #include <linux/slab.h>
42 #include <linux/types.h>
43 #include <asm/unaligned.h>
45 #include <scsi/scsi.h>
49 static int sg_version_num
= 30534; /* 2 digits for each component */
52 #define VPD_SUPPORTED_PAGES 0x00
53 #define VPD_SERIAL_NUMBER 0x80
54 #define VPD_DEVICE_IDENTIFIERS 0x83
55 #define VPD_EXTENDED_INQUIRY 0x86
56 #define VPD_BLOCK_LIMITS 0xB0
57 #define VPD_BLOCK_DEV_CHARACTERISTICS 0xB1
59 /* format unit paramter list offsets */
60 #define FORMAT_UNIT_SHORT_PARM_LIST_LEN 4
61 #define FORMAT_UNIT_LONG_PARM_LIST_LEN 8
62 #define FORMAT_UNIT_PROT_INT_OFFSET 3
63 #define FORMAT_UNIT_PROT_FIELD_USAGE_OFFSET 0
64 #define FORMAT_UNIT_PROT_FIELD_USAGE_MASK 0x07
67 #define FIXED_SENSE_DATA 0x70
68 #define DESC_FORMAT_SENSE_DATA 0x72
69 #define FIXED_SENSE_DATA_ADD_LENGTH 10
70 #define LUN_ENTRY_SIZE 8
71 #define LUN_DATA_HEADER_SIZE 8
72 #define ALL_LUNS_RETURNED 0x02
73 #define ALL_WELL_KNOWN_LUNS_RETURNED 0x01
74 #define RESTRICTED_LUNS_RETURNED 0x00
75 #define NVME_POWER_STATE_START_VALID 0x00
76 #define NVME_POWER_STATE_ACTIVE 0x01
77 #define NVME_POWER_STATE_IDLE 0x02
78 #define NVME_POWER_STATE_STANDBY 0x03
79 #define NVME_POWER_STATE_LU_CONTROL 0x07
80 #define POWER_STATE_0 0
81 #define POWER_STATE_1 1
82 #define POWER_STATE_2 2
83 #define POWER_STATE_3 3
84 #define DOWNLOAD_SAVE_ACTIVATE 0x05
85 #define DOWNLOAD_SAVE_DEFER_ACTIVATE 0x0E
86 #define ACTIVATE_DEFERRED_MICROCODE 0x0F
87 #define FORMAT_UNIT_IMMED_MASK 0x2
88 #define FORMAT_UNIT_IMMED_OFFSET 1
89 #define KELVIN_TEMP_FACTOR 273
90 #define FIXED_FMT_SENSE_DATA_SIZE 18
91 #define DESC_FMT_SENSE_DATA_SIZE 8
93 /* SCSI/NVMe defines and bit masks */
94 #define INQ_STANDARD_INQUIRY_PAGE 0x00
95 #define INQ_SUPPORTED_VPD_PAGES_PAGE 0x00
96 #define INQ_UNIT_SERIAL_NUMBER_PAGE 0x80
97 #define INQ_DEVICE_IDENTIFICATION_PAGE 0x83
98 #define INQ_EXTENDED_INQUIRY_DATA_PAGE 0x86
99 #define INQ_BDEV_LIMITS_PAGE 0xB0
100 #define INQ_BDEV_CHARACTERISTICS_PAGE 0xB1
101 #define INQ_SERIAL_NUMBER_LENGTH 0x14
102 #define INQ_NUM_SUPPORTED_VPD_PAGES 6
103 #define VERSION_SPC_4 0x06
104 #define ACA_UNSUPPORTED 0
105 #define STANDARD_INQUIRY_LENGTH 36
106 #define ADDITIONAL_STD_INQ_LENGTH 31
107 #define EXTENDED_INQUIRY_DATA_PAGE_LENGTH 0x3C
108 #define RESERVED_FIELD 0
110 /* Mode Sense/Select defines */
111 #define MODE_PAGE_INFO_EXCEP 0x1C
112 #define MODE_PAGE_CACHING 0x08
113 #define MODE_PAGE_CONTROL 0x0A
114 #define MODE_PAGE_POWER_CONDITION 0x1A
115 #define MODE_PAGE_RETURN_ALL 0x3F
116 #define MODE_PAGE_BLK_DES_LEN 0x08
117 #define MODE_PAGE_LLBAA_BLK_DES_LEN 0x10
118 #define MODE_PAGE_CACHING_LEN 0x14
119 #define MODE_PAGE_CONTROL_LEN 0x0C
120 #define MODE_PAGE_POW_CND_LEN 0x28
121 #define MODE_PAGE_INF_EXC_LEN 0x0C
122 #define MODE_PAGE_ALL_LEN 0x54
123 #define MODE_SENSE6_MPH_SIZE 4
124 #define MODE_SENSE_PAGE_CONTROL_MASK 0xC0
125 #define MODE_SENSE_PAGE_CODE_OFFSET 2
126 #define MODE_SENSE_PAGE_CODE_MASK 0x3F
127 #define MODE_SENSE_LLBAA_MASK 0x10
128 #define MODE_SENSE_LLBAA_SHIFT 4
129 #define MODE_SENSE_DBD_MASK 8
130 #define MODE_SENSE_DBD_SHIFT 3
131 #define MODE_SENSE10_MPH_SIZE 8
132 #define MODE_SELECT_CDB_PAGE_FORMAT_MASK 0x10
133 #define MODE_SELECT_CDB_SAVE_PAGES_MASK 0x1
134 #define MODE_SELECT_6_BD_OFFSET 3
135 #define MODE_SELECT_10_BD_OFFSET 6
136 #define MODE_SELECT_10_LLBAA_OFFSET 4
137 #define MODE_SELECT_10_LLBAA_MASK 1
138 #define MODE_SELECT_6_MPH_SIZE 4
139 #define MODE_SELECT_10_MPH_SIZE 8
140 #define CACHING_MODE_PAGE_WCE_MASK 0x04
141 #define MODE_SENSE_BLK_DESC_ENABLED 0
142 #define MODE_SENSE_BLK_DESC_COUNT 1
143 #define MODE_SELECT_PAGE_CODE_MASK 0x3F
144 #define SHORT_DESC_BLOCK 8
145 #define LONG_DESC_BLOCK 16
146 #define MODE_PAGE_POW_CND_LEN_FIELD 0x26
147 #define MODE_PAGE_INF_EXC_LEN_FIELD 0x0A
148 #define MODE_PAGE_CACHING_LEN_FIELD 0x12
149 #define MODE_PAGE_CONTROL_LEN_FIELD 0x0A
150 #define MODE_SENSE_PC_CURRENT_VALUES 0
152 /* Log Sense defines */
153 #define LOG_PAGE_SUPPORTED_LOG_PAGES_PAGE 0x00
154 #define LOG_PAGE_SUPPORTED_LOG_PAGES_LENGTH 0x07
155 #define LOG_PAGE_INFORMATIONAL_EXCEPTIONS_PAGE 0x2F
156 #define LOG_PAGE_TEMPERATURE_PAGE 0x0D
157 #define LOG_SENSE_CDB_SP_NOT_ENABLED 0
158 #define LOG_SENSE_CDB_PC_MASK 0xC0
159 #define LOG_SENSE_CDB_PC_SHIFT 6
160 #define LOG_SENSE_CDB_PC_CUMULATIVE_VALUES 1
161 #define LOG_SENSE_CDB_PAGE_CODE_MASK 0x3F
162 #define REMAINING_INFO_EXCP_PAGE_LENGTH 0x8
163 #define LOG_INFO_EXCP_PAGE_LENGTH 0xC
164 #define REMAINING_TEMP_PAGE_LENGTH 0xC
165 #define LOG_TEMP_PAGE_LENGTH 0x10
166 #define LOG_TEMP_UNKNOWN 0xFF
167 #define SUPPORTED_LOG_PAGES_PAGE_LENGTH 0x3
169 /* Read Capacity defines */
170 #define READ_CAP_10_RESP_SIZE 8
171 #define READ_CAP_16_RESP_SIZE 32
173 /* NVMe Namespace and Command Defines */
174 #define BYTES_TO_DWORDS 4
175 #define NVME_MAX_FIRMWARE_SLOT 7
177 /* Report LUNs defines */
178 #define REPORT_LUNS_FIRST_LUN_OFFSET 8
180 /* SCSI ADDITIONAL SENSE Codes */
182 #define SCSI_ASC_NO_SENSE 0x00
183 #define SCSI_ASC_PERIPHERAL_DEV_WRITE_FAULT 0x03
184 #define SCSI_ASC_LUN_NOT_READY 0x04
185 #define SCSI_ASC_WARNING 0x0B
186 #define SCSI_ASC_LOG_BLOCK_GUARD_CHECK_FAILED 0x10
187 #define SCSI_ASC_LOG_BLOCK_APPTAG_CHECK_FAILED 0x10
188 #define SCSI_ASC_LOG_BLOCK_REFTAG_CHECK_FAILED 0x10
189 #define SCSI_ASC_UNRECOVERED_READ_ERROR 0x11
190 #define SCSI_ASC_MISCOMPARE_DURING_VERIFY 0x1D
191 #define SCSI_ASC_ACCESS_DENIED_INVALID_LUN_ID 0x20
192 #define SCSI_ASC_ILLEGAL_COMMAND 0x20
193 #define SCSI_ASC_ILLEGAL_BLOCK 0x21
194 #define SCSI_ASC_INVALID_CDB 0x24
195 #define SCSI_ASC_INVALID_LUN 0x25
196 #define SCSI_ASC_INVALID_PARAMETER 0x26
197 #define SCSI_ASC_FORMAT_COMMAND_FAILED 0x31
198 #define SCSI_ASC_INTERNAL_TARGET_FAILURE 0x44
200 /* SCSI ADDITIONAL SENSE Code Qualifiers */
202 #define SCSI_ASCQ_CAUSE_NOT_REPORTABLE 0x00
203 #define SCSI_ASCQ_FORMAT_COMMAND_FAILED 0x01
204 #define SCSI_ASCQ_LOG_BLOCK_GUARD_CHECK_FAILED 0x01
205 #define SCSI_ASCQ_LOG_BLOCK_APPTAG_CHECK_FAILED 0x02
206 #define SCSI_ASCQ_LOG_BLOCK_REFTAG_CHECK_FAILED 0x03
207 #define SCSI_ASCQ_FORMAT_IN_PROGRESS 0x04
208 #define SCSI_ASCQ_POWER_LOSS_EXPECTED 0x08
209 #define SCSI_ASCQ_INVALID_LUN_ID 0x09
211 /* copied from drivers/usb/gadget/function/storage_common.h */
212 static inline u32
get_unaligned_be24(u8
*buf
)
214 return 0xffffff & (u32
) get_unaligned_be32(buf
- 1);
217 /* Struct to gather data that needs to be extracted from a SCSI CDB.
218 Not conforming to any particular CDB variant, but compatible with all. */
220 struct nvme_trans_io_cdb
{
228 /* Internal Helper Functions */
231 /* Copy data to userspace memory */
233 static int nvme_trans_copy_to_user(struct sg_io_hdr
*hdr
, void *from
,
238 size_t remaining
= n
;
241 if (hdr
->iovec_count
> 0) {
244 for (i
= 0; i
< hdr
->iovec_count
; i
++) {
245 if (copy_from_user(&sgl
, hdr
->dxferp
+
246 i
* sizeof(struct sg_iovec
),
247 sizeof(struct sg_iovec
)))
249 xfer_len
= min(remaining
, sgl
.iov_len
);
250 if (copy_to_user(sgl
.iov_base
, index
, xfer_len
))
254 remaining
-= xfer_len
;
261 if (copy_to_user(hdr
->dxferp
, from
, n
))
266 /* Copy data from userspace memory */
268 static int nvme_trans_copy_from_user(struct sg_io_hdr
*hdr
, void *to
,
273 size_t remaining
= n
;
276 if (hdr
->iovec_count
> 0) {
279 for (i
= 0; i
< hdr
->iovec_count
; i
++) {
280 if (copy_from_user(&sgl
, hdr
->dxferp
+
281 i
* sizeof(struct sg_iovec
),
282 sizeof(struct sg_iovec
)))
284 xfer_len
= min(remaining
, sgl
.iov_len
);
285 if (copy_from_user(index
, sgl
.iov_base
, xfer_len
))
288 remaining
-= xfer_len
;
295 if (copy_from_user(to
, hdr
->dxferp
, n
))
300 /* Status/Sense Buffer Writeback */
302 static int nvme_trans_completion(struct sg_io_hdr
*hdr
, u8 status
, u8 sense_key
,
306 u8 resp
[DESC_FMT_SENSE_DATA_SIZE
];
308 if (scsi_status_is_good(status
)) {
309 hdr
->status
= SAM_STAT_GOOD
;
310 hdr
->masked_status
= GOOD
;
311 hdr
->host_status
= DID_OK
;
312 hdr
->driver_status
= DRIVER_OK
;
315 hdr
->status
= status
;
316 hdr
->masked_status
= status
>> 1;
317 hdr
->host_status
= DID_OK
;
318 hdr
->driver_status
= DRIVER_OK
;
320 memset(resp
, 0, DESC_FMT_SENSE_DATA_SIZE
);
321 resp
[0] = DESC_FORMAT_SENSE_DATA
;
326 xfer_len
= min_t(u8
, hdr
->mx_sb_len
, DESC_FMT_SENSE_DATA_SIZE
);
327 hdr
->sb_len_wr
= xfer_len
;
328 if (copy_to_user(hdr
->sbp
, resp
, xfer_len
) > 0)
336 * Take a status code from a lowlevel routine, and if it was a positive NVMe
337 * error code update the sense data based on it. In either case the passed
338 * in value is returned again, unless an -EFAULT from copy_to_user overrides
341 static int nvme_trans_status_code(struct sg_io_hdr
*hdr
, int nvme_sc
)
343 u8 status
, sense_key
, asc
, ascq
;
346 /* For non-nvme (Linux) errors, simply return the error code */
350 /* Mask DNR, More, and reserved fields */
351 switch (nvme_sc
& 0x7FF) {
352 /* Generic Command Status */
353 case NVME_SC_SUCCESS
:
354 status
= SAM_STAT_GOOD
;
355 sense_key
= NO_SENSE
;
356 asc
= SCSI_ASC_NO_SENSE
;
357 ascq
= SCSI_ASCQ_CAUSE_NOT_REPORTABLE
;
359 case NVME_SC_INVALID_OPCODE
:
360 status
= SAM_STAT_CHECK_CONDITION
;
361 sense_key
= ILLEGAL_REQUEST
;
362 asc
= SCSI_ASC_ILLEGAL_COMMAND
;
363 ascq
= SCSI_ASCQ_CAUSE_NOT_REPORTABLE
;
365 case NVME_SC_INVALID_FIELD
:
366 status
= SAM_STAT_CHECK_CONDITION
;
367 sense_key
= ILLEGAL_REQUEST
;
368 asc
= SCSI_ASC_INVALID_CDB
;
369 ascq
= SCSI_ASCQ_CAUSE_NOT_REPORTABLE
;
371 case NVME_SC_DATA_XFER_ERROR
:
372 status
= SAM_STAT_CHECK_CONDITION
;
373 sense_key
= MEDIUM_ERROR
;
374 asc
= SCSI_ASC_NO_SENSE
;
375 ascq
= SCSI_ASCQ_CAUSE_NOT_REPORTABLE
;
377 case NVME_SC_POWER_LOSS
:
378 status
= SAM_STAT_TASK_ABORTED
;
379 sense_key
= ABORTED_COMMAND
;
380 asc
= SCSI_ASC_WARNING
;
381 ascq
= SCSI_ASCQ_POWER_LOSS_EXPECTED
;
383 case NVME_SC_INTERNAL
:
384 status
= SAM_STAT_CHECK_CONDITION
;
385 sense_key
= HARDWARE_ERROR
;
386 asc
= SCSI_ASC_INTERNAL_TARGET_FAILURE
;
387 ascq
= SCSI_ASCQ_CAUSE_NOT_REPORTABLE
;
389 case NVME_SC_ABORT_REQ
:
390 status
= SAM_STAT_TASK_ABORTED
;
391 sense_key
= ABORTED_COMMAND
;
392 asc
= SCSI_ASC_NO_SENSE
;
393 ascq
= SCSI_ASCQ_CAUSE_NOT_REPORTABLE
;
395 case NVME_SC_ABORT_QUEUE
:
396 status
= SAM_STAT_TASK_ABORTED
;
397 sense_key
= ABORTED_COMMAND
;
398 asc
= SCSI_ASC_NO_SENSE
;
399 ascq
= SCSI_ASCQ_CAUSE_NOT_REPORTABLE
;
401 case NVME_SC_FUSED_FAIL
:
402 status
= SAM_STAT_TASK_ABORTED
;
403 sense_key
= ABORTED_COMMAND
;
404 asc
= SCSI_ASC_NO_SENSE
;
405 ascq
= SCSI_ASCQ_CAUSE_NOT_REPORTABLE
;
407 case NVME_SC_FUSED_MISSING
:
408 status
= SAM_STAT_TASK_ABORTED
;
409 sense_key
= ABORTED_COMMAND
;
410 asc
= SCSI_ASC_NO_SENSE
;
411 ascq
= SCSI_ASCQ_CAUSE_NOT_REPORTABLE
;
413 case NVME_SC_INVALID_NS
:
414 status
= SAM_STAT_CHECK_CONDITION
;
415 sense_key
= ILLEGAL_REQUEST
;
416 asc
= SCSI_ASC_ACCESS_DENIED_INVALID_LUN_ID
;
417 ascq
= SCSI_ASCQ_INVALID_LUN_ID
;
419 case NVME_SC_LBA_RANGE
:
420 status
= SAM_STAT_CHECK_CONDITION
;
421 sense_key
= ILLEGAL_REQUEST
;
422 asc
= SCSI_ASC_ILLEGAL_BLOCK
;
423 ascq
= SCSI_ASCQ_CAUSE_NOT_REPORTABLE
;
425 case NVME_SC_CAP_EXCEEDED
:
426 status
= SAM_STAT_CHECK_CONDITION
;
427 sense_key
= MEDIUM_ERROR
;
428 asc
= SCSI_ASC_NO_SENSE
;
429 ascq
= SCSI_ASCQ_CAUSE_NOT_REPORTABLE
;
431 case NVME_SC_NS_NOT_READY
:
432 status
= SAM_STAT_CHECK_CONDITION
;
433 sense_key
= NOT_READY
;
434 asc
= SCSI_ASC_LUN_NOT_READY
;
435 ascq
= SCSI_ASCQ_CAUSE_NOT_REPORTABLE
;
438 /* Command Specific Status */
439 case NVME_SC_INVALID_FORMAT
:
440 status
= SAM_STAT_CHECK_CONDITION
;
441 sense_key
= ILLEGAL_REQUEST
;
442 asc
= SCSI_ASC_FORMAT_COMMAND_FAILED
;
443 ascq
= SCSI_ASCQ_FORMAT_COMMAND_FAILED
;
445 case NVME_SC_BAD_ATTRIBUTES
:
446 status
= SAM_STAT_CHECK_CONDITION
;
447 sense_key
= ILLEGAL_REQUEST
;
448 asc
= SCSI_ASC_INVALID_CDB
;
449 ascq
= SCSI_ASCQ_CAUSE_NOT_REPORTABLE
;
453 case NVME_SC_WRITE_FAULT
:
454 status
= SAM_STAT_CHECK_CONDITION
;
455 sense_key
= MEDIUM_ERROR
;
456 asc
= SCSI_ASC_PERIPHERAL_DEV_WRITE_FAULT
;
457 ascq
= SCSI_ASCQ_CAUSE_NOT_REPORTABLE
;
459 case NVME_SC_READ_ERROR
:
460 status
= SAM_STAT_CHECK_CONDITION
;
461 sense_key
= MEDIUM_ERROR
;
462 asc
= SCSI_ASC_UNRECOVERED_READ_ERROR
;
463 ascq
= SCSI_ASCQ_CAUSE_NOT_REPORTABLE
;
465 case NVME_SC_GUARD_CHECK
:
466 status
= SAM_STAT_CHECK_CONDITION
;
467 sense_key
= MEDIUM_ERROR
;
468 asc
= SCSI_ASC_LOG_BLOCK_GUARD_CHECK_FAILED
;
469 ascq
= SCSI_ASCQ_LOG_BLOCK_GUARD_CHECK_FAILED
;
471 case NVME_SC_APPTAG_CHECK
:
472 status
= SAM_STAT_CHECK_CONDITION
;
473 sense_key
= MEDIUM_ERROR
;
474 asc
= SCSI_ASC_LOG_BLOCK_APPTAG_CHECK_FAILED
;
475 ascq
= SCSI_ASCQ_LOG_BLOCK_APPTAG_CHECK_FAILED
;
477 case NVME_SC_REFTAG_CHECK
:
478 status
= SAM_STAT_CHECK_CONDITION
;
479 sense_key
= MEDIUM_ERROR
;
480 asc
= SCSI_ASC_LOG_BLOCK_REFTAG_CHECK_FAILED
;
481 ascq
= SCSI_ASCQ_LOG_BLOCK_REFTAG_CHECK_FAILED
;
483 case NVME_SC_COMPARE_FAILED
:
484 status
= SAM_STAT_CHECK_CONDITION
;
485 sense_key
= MISCOMPARE
;
486 asc
= SCSI_ASC_MISCOMPARE_DURING_VERIFY
;
487 ascq
= SCSI_ASCQ_CAUSE_NOT_REPORTABLE
;
489 case NVME_SC_ACCESS_DENIED
:
490 status
= SAM_STAT_CHECK_CONDITION
;
491 sense_key
= ILLEGAL_REQUEST
;
492 asc
= SCSI_ASC_ACCESS_DENIED_INVALID_LUN_ID
;
493 ascq
= SCSI_ASCQ_INVALID_LUN_ID
;
496 /* Unspecified/Default */
497 case NVME_SC_CMDID_CONFLICT
:
498 case NVME_SC_CMD_SEQ_ERROR
:
499 case NVME_SC_CQ_INVALID
:
500 case NVME_SC_QID_INVALID
:
501 case NVME_SC_QUEUE_SIZE
:
502 case NVME_SC_ABORT_LIMIT
:
503 case NVME_SC_ABORT_MISSING
:
504 case NVME_SC_ASYNC_LIMIT
:
505 case NVME_SC_FIRMWARE_SLOT
:
506 case NVME_SC_FIRMWARE_IMAGE
:
507 case NVME_SC_INVALID_VECTOR
:
508 case NVME_SC_INVALID_LOG_PAGE
:
510 status
= SAM_STAT_CHECK_CONDITION
;
511 sense_key
= ILLEGAL_REQUEST
;
512 asc
= SCSI_ASC_NO_SENSE
;
513 ascq
= SCSI_ASCQ_CAUSE_NOT_REPORTABLE
;
517 res
= nvme_trans_completion(hdr
, status
, sense_key
, asc
, ascq
);
518 return res
? res
: nvme_sc
;
521 /* INQUIRY Helper Functions */
523 static int nvme_trans_standard_inquiry_page(struct nvme_ns
*ns
,
524 struct sg_io_hdr
*hdr
, u8
*inq_response
,
527 struct nvme_ctrl
*ctrl
= ns
->ctrl
;
528 struct nvme_id_ns
*id_ns
;
532 u8 resp_data_format
= 0x02;
534 u8 cmdque
= 0x01 << 1;
535 u8 fw_offset
= sizeof(ctrl
->firmware_rev
);
537 /* nvme ns identify - use DPS value for PROTECT field */
538 nvme_sc
= nvme_identify_ns(ctrl
, ns
->ns_id
, &id_ns
);
539 res
= nvme_trans_status_code(hdr
, nvme_sc
);
549 memset(inq_response
, 0, STANDARD_INQUIRY_LENGTH
);
550 inq_response
[2] = VERSION_SPC_4
;
551 inq_response
[3] = resp_data_format
; /*normaca=0 | hisup=0 */
552 inq_response
[4] = ADDITIONAL_STD_INQ_LENGTH
;
553 inq_response
[5] = protect
; /* sccs=0 | acc=0 | tpgs=0 | pc3=0 */
554 inq_response
[7] = cmdque
; /* wbus16=0 | sync=0 | vs=0 */
555 strncpy(&inq_response
[8], "NVMe ", 8);
556 strncpy(&inq_response
[16], ctrl
->model
, 16);
558 while (ctrl
->firmware_rev
[fw_offset
- 1] == ' ' && fw_offset
> 4)
561 strncpy(&inq_response
[32], ctrl
->firmware_rev
+ fw_offset
, 4);
563 xfer_len
= min(alloc_len
, STANDARD_INQUIRY_LENGTH
);
564 return nvme_trans_copy_to_user(hdr
, inq_response
, xfer_len
);
567 static int nvme_trans_supported_vpd_pages(struct nvme_ns
*ns
,
568 struct sg_io_hdr
*hdr
, u8
*inq_response
,
573 memset(inq_response
, 0, STANDARD_INQUIRY_LENGTH
);
574 inq_response
[1] = INQ_SUPPORTED_VPD_PAGES_PAGE
; /* Page Code */
575 inq_response
[3] = INQ_NUM_SUPPORTED_VPD_PAGES
; /* Page Length */
576 inq_response
[4] = INQ_SUPPORTED_VPD_PAGES_PAGE
;
577 inq_response
[5] = INQ_UNIT_SERIAL_NUMBER_PAGE
;
578 inq_response
[6] = INQ_DEVICE_IDENTIFICATION_PAGE
;
579 inq_response
[7] = INQ_EXTENDED_INQUIRY_DATA_PAGE
;
580 inq_response
[8] = INQ_BDEV_CHARACTERISTICS_PAGE
;
581 inq_response
[9] = INQ_BDEV_LIMITS_PAGE
;
583 xfer_len
= min(alloc_len
, STANDARD_INQUIRY_LENGTH
);
584 return nvme_trans_copy_to_user(hdr
, inq_response
, xfer_len
);
587 static int nvme_trans_unit_serial_page(struct nvme_ns
*ns
,
588 struct sg_io_hdr
*hdr
, u8
*inq_response
,
593 memset(inq_response
, 0, STANDARD_INQUIRY_LENGTH
);
594 inq_response
[1] = INQ_UNIT_SERIAL_NUMBER_PAGE
; /* Page Code */
595 inq_response
[3] = INQ_SERIAL_NUMBER_LENGTH
; /* Page Length */
596 strncpy(&inq_response
[4], ns
->ctrl
->serial
, INQ_SERIAL_NUMBER_LENGTH
);
598 xfer_len
= min(alloc_len
, STANDARD_INQUIRY_LENGTH
);
599 return nvme_trans_copy_to_user(hdr
, inq_response
, xfer_len
);
602 static int nvme_fill_device_id_eui64(struct nvme_ns
*ns
, struct sg_io_hdr
*hdr
,
603 u8
*inq_response
, int alloc_len
)
605 struct nvme_id_ns
*id_ns
;
610 nvme_sc
= nvme_identify_ns(ns
->ctrl
, ns
->ns_id
, &id_ns
);
611 res
= nvme_trans_status_code(hdr
, nvme_sc
);
616 len
= sizeof(id_ns
->eui64
);
618 if (ns
->ctrl
->vs
>= NVME_VS(1, 2)) {
619 if (bitmap_empty(eui
, len
* 8)) {
621 len
= sizeof(id_ns
->nguid
);
625 if (bitmap_empty(eui
, len
* 8)) {
630 memset(inq_response
, 0, alloc_len
);
631 inq_response
[1] = INQ_DEVICE_IDENTIFICATION_PAGE
;
632 inq_response
[3] = 4 + len
; /* Page Length */
634 /* Designation Descriptor start */
635 inq_response
[4] = 0x01; /* Proto ID=0h | Code set=1h */
636 inq_response
[5] = 0x02; /* PIV=0b | Asso=00b | Designator Type=2h */
637 inq_response
[6] = 0x00; /* Rsvd */
638 inq_response
[7] = len
; /* Designator Length */
639 memcpy(&inq_response
[8], eui
, len
);
641 res
= nvme_trans_copy_to_user(hdr
, inq_response
, alloc_len
);
647 static int nvme_fill_device_id_scsi_string(struct nvme_ns
*ns
,
648 struct sg_io_hdr
*hdr
, u8
*inq_response
, int alloc_len
)
650 struct nvme_ctrl
*ctrl
= ns
->ctrl
;
651 struct nvme_id_ctrl
*id_ctrl
;
654 if (alloc_len
< 72) {
655 return nvme_trans_completion(hdr
,
656 SAM_STAT_CHECK_CONDITION
,
657 ILLEGAL_REQUEST
, SCSI_ASC_INVALID_CDB
,
658 SCSI_ASCQ_CAUSE_NOT_REPORTABLE
);
661 nvme_sc
= nvme_identify_ctrl(ctrl
, &id_ctrl
);
662 res
= nvme_trans_status_code(hdr
, nvme_sc
);
666 memset(inq_response
, 0, alloc_len
);
667 inq_response
[1] = INQ_DEVICE_IDENTIFICATION_PAGE
;
668 inq_response
[3] = 0x48; /* Page Length */
670 /* Designation Descriptor start */
671 inq_response
[4] = 0x03; /* Proto ID=0h | Code set=3h */
672 inq_response
[5] = 0x08; /* PIV=0b | Asso=00b | Designator Type=8h */
673 inq_response
[6] = 0x00; /* Rsvd */
674 inq_response
[7] = 0x44; /* Designator Length */
676 sprintf(&inq_response
[8], "%04x", le16_to_cpu(id_ctrl
->vid
));
677 memcpy(&inq_response
[12], ctrl
->model
, sizeof(ctrl
->model
));
678 sprintf(&inq_response
[52], "%04x", cpu_to_be32(ns
->ns_id
));
679 memcpy(&inq_response
[56], ctrl
->serial
, sizeof(ctrl
->serial
));
681 res
= nvme_trans_copy_to_user(hdr
, inq_response
, alloc_len
);
686 static int nvme_trans_device_id_page(struct nvme_ns
*ns
, struct sg_io_hdr
*hdr
,
687 u8
*resp
, int alloc_len
)
691 if (ns
->ctrl
->vs
>= NVME_VS(1, 1)) {
692 res
= nvme_fill_device_id_eui64(ns
, hdr
, resp
, alloc_len
);
693 if (res
!= -EOPNOTSUPP
)
697 return nvme_fill_device_id_scsi_string(ns
, hdr
, resp
, alloc_len
);
700 static int nvme_trans_ext_inq_page(struct nvme_ns
*ns
, struct sg_io_hdr
*hdr
,
706 struct nvme_ctrl
*ctrl
= ns
->ctrl
;
707 struct nvme_id_ctrl
*id_ctrl
;
708 struct nvme_id_ns
*id_ns
;
712 u8 spt_lut
[8] = {0, 0, 2, 1, 4, 6, 5, 7};
713 u8 grd_chk
, app_chk
, ref_chk
, protect
;
718 inq_response
= kmalloc(EXTENDED_INQUIRY_DATA_PAGE_LENGTH
, GFP_KERNEL
);
719 if (inq_response
== NULL
)
722 nvme_sc
= nvme_identify_ns(ctrl
, ns
->ns_id
, &id_ns
);
723 res
= nvme_trans_status_code(hdr
, nvme_sc
);
727 spt
= spt_lut
[id_ns
->dpc
& 0x07] << 3;
734 grd_chk
= protect
<< 2;
735 app_chk
= protect
<< 1;
738 nvme_sc
= nvme_identify_ctrl(ctrl
, &id_ctrl
);
739 res
= nvme_trans_status_code(hdr
, nvme_sc
);
743 v_sup
= id_ctrl
->vwc
;
746 memset(inq_response
, 0, EXTENDED_INQUIRY_DATA_PAGE_LENGTH
);
747 inq_response
[1] = INQ_EXTENDED_INQUIRY_DATA_PAGE
; /* Page Code */
748 inq_response
[2] = 0x00; /* Page Length MSB */
749 inq_response
[3] = 0x3C; /* Page Length LSB */
750 inq_response
[4] = microcode
| spt
| grd_chk
| app_chk
| ref_chk
;
751 inq_response
[5] = uask_sup
;
752 inq_response
[6] = v_sup
;
753 inq_response
[7] = luiclr
;
757 xfer_len
= min(alloc_len
, EXTENDED_INQUIRY_DATA_PAGE_LENGTH
);
758 res
= nvme_trans_copy_to_user(hdr
, inq_response
, xfer_len
);
765 static int nvme_trans_bdev_limits_page(struct nvme_ns
*ns
, struct sg_io_hdr
*hdr
,
766 u8
*inq_response
, int alloc_len
)
768 __be32 max_sectors
= cpu_to_be32(
769 nvme_block_nr(ns
, queue_max_hw_sectors(ns
->queue
)));
770 __be32 max_discard
= cpu_to_be32(ns
->queue
->limits
.max_discard_sectors
);
771 __be32 discard_desc_count
= cpu_to_be32(0x100);
773 memset(inq_response
, 0, STANDARD_INQUIRY_LENGTH
);
774 inq_response
[1] = VPD_BLOCK_LIMITS
;
775 inq_response
[3] = 0x3c; /* Page Length */
776 memcpy(&inq_response
[8], &max_sectors
, sizeof(u32
));
777 memcpy(&inq_response
[20], &max_discard
, sizeof(u32
));
780 memcpy(&inq_response
[24], &discard_desc_count
, sizeof(u32
));
782 return nvme_trans_copy_to_user(hdr
, inq_response
, 0x3c);
785 static int nvme_trans_bdev_char_page(struct nvme_ns
*ns
, struct sg_io_hdr
*hdr
,
792 inq_response
= kzalloc(EXTENDED_INQUIRY_DATA_PAGE_LENGTH
, GFP_KERNEL
);
793 if (inq_response
== NULL
) {
798 inq_response
[1] = INQ_BDEV_CHARACTERISTICS_PAGE
; /* Page Code */
799 inq_response
[2] = 0x00; /* Page Length MSB */
800 inq_response
[3] = 0x3C; /* Page Length LSB */
801 inq_response
[4] = 0x00; /* Medium Rotation Rate MSB */
802 inq_response
[5] = 0x01; /* Medium Rotation Rate LSB */
803 inq_response
[6] = 0x00; /* Form Factor */
805 xfer_len
= min(alloc_len
, EXTENDED_INQUIRY_DATA_PAGE_LENGTH
);
806 res
= nvme_trans_copy_to_user(hdr
, inq_response
, xfer_len
);
813 /* LOG SENSE Helper Functions */
815 static int nvme_trans_log_supp_pages(struct nvme_ns
*ns
, struct sg_io_hdr
*hdr
,
822 log_response
= kzalloc(LOG_PAGE_SUPPORTED_LOG_PAGES_LENGTH
, GFP_KERNEL
);
823 if (log_response
== NULL
) {
828 log_response
[0] = LOG_PAGE_SUPPORTED_LOG_PAGES_PAGE
;
829 /* Subpage=0x00, Page Length MSB=0 */
830 log_response
[3] = SUPPORTED_LOG_PAGES_PAGE_LENGTH
;
831 log_response
[4] = LOG_PAGE_SUPPORTED_LOG_PAGES_PAGE
;
832 log_response
[5] = LOG_PAGE_INFORMATIONAL_EXCEPTIONS_PAGE
;
833 log_response
[6] = LOG_PAGE_TEMPERATURE_PAGE
;
835 xfer_len
= min(alloc_len
, LOG_PAGE_SUPPORTED_LOG_PAGES_LENGTH
);
836 res
= nvme_trans_copy_to_user(hdr
, log_response
, xfer_len
);
843 static int nvme_trans_log_info_exceptions(struct nvme_ns
*ns
,
844 struct sg_io_hdr
*hdr
, int alloc_len
)
849 struct nvme_smart_log
*smart_log
;
853 log_response
= kzalloc(LOG_INFO_EXCP_PAGE_LENGTH
, GFP_KERNEL
);
854 if (log_response
== NULL
)
857 res
= nvme_get_log_page(ns
->ctrl
, &smart_log
);
859 goto out_free_response
;
861 if (res
!= NVME_SC_SUCCESS
) {
862 temp_c
= LOG_TEMP_UNKNOWN
;
864 temp_k
= (smart_log
->temperature
[1] << 8) +
865 (smart_log
->temperature
[0]);
866 temp_c
= temp_k
- KELVIN_TEMP_FACTOR
;
870 log_response
[0] = LOG_PAGE_INFORMATIONAL_EXCEPTIONS_PAGE
;
871 /* Subpage=0x00, Page Length MSB=0 */
872 log_response
[3] = REMAINING_INFO_EXCP_PAGE_LENGTH
;
873 /* Informational Exceptions Log Parameter 1 Start */
874 /* Parameter Code=0x0000 bytes 4,5 */
875 log_response
[6] = 0x23; /* DU=0, TSD=1, ETC=0, TMC=0, FMT_AND_LNK=11b */
876 log_response
[7] = 0x04; /* PARAMETER LENGTH */
877 /* Add sense Code and qualifier = 0x00 each */
878 /* Use Temperature from NVMe Get Log Page, convert to C from K */
879 log_response
[10] = temp_c
;
881 xfer_len
= min(alloc_len
, LOG_INFO_EXCP_PAGE_LENGTH
);
882 res
= nvme_trans_copy_to_user(hdr
, log_response
, xfer_len
);
889 static int nvme_trans_log_temperature(struct nvme_ns
*ns
, struct sg_io_hdr
*hdr
,
895 struct nvme_smart_log
*smart_log
;
897 u8 temp_c_cur
, temp_c_thresh
;
900 log_response
= kzalloc(LOG_TEMP_PAGE_LENGTH
, GFP_KERNEL
);
901 if (log_response
== NULL
)
904 res
= nvme_get_log_page(ns
->ctrl
, &smart_log
);
906 goto out_free_response
;
908 if (res
!= NVME_SC_SUCCESS
) {
909 temp_c_cur
= LOG_TEMP_UNKNOWN
;
911 temp_k
= (smart_log
->temperature
[1] << 8) +
912 (smart_log
->temperature
[0]);
913 temp_c_cur
= temp_k
- KELVIN_TEMP_FACTOR
;
917 /* Get Features for Temp Threshold */
918 res
= nvme_get_features(ns
->ctrl
, NVME_FEAT_TEMP_THRESH
, 0, 0,
920 if (res
!= NVME_SC_SUCCESS
)
921 temp_c_thresh
= LOG_TEMP_UNKNOWN
;
923 temp_c_thresh
= (feature_resp
& 0xFFFF) - KELVIN_TEMP_FACTOR
;
925 log_response
[0] = LOG_PAGE_TEMPERATURE_PAGE
;
926 /* Subpage=0x00, Page Length MSB=0 */
927 log_response
[3] = REMAINING_TEMP_PAGE_LENGTH
;
928 /* Temperature Log Parameter 1 (Temperature) Start */
929 /* Parameter Code = 0x0000 */
930 log_response
[6] = 0x01; /* Format and Linking = 01b */
931 log_response
[7] = 0x02; /* Parameter Length */
932 /* Use Temperature from NVMe Get Log Page, convert to C from K */
933 log_response
[9] = temp_c_cur
;
934 /* Temperature Log Parameter 2 (Reference Temperature) Start */
935 log_response
[11] = 0x01; /* Parameter Code = 0x0001 */
936 log_response
[12] = 0x01; /* Format and Linking = 01b */
937 log_response
[13] = 0x02; /* Parameter Length */
938 /* Use Temperature Thresh from NVMe Get Log Page, convert to C from K */
939 log_response
[15] = temp_c_thresh
;
941 xfer_len
= min(alloc_len
, LOG_TEMP_PAGE_LENGTH
);
942 res
= nvme_trans_copy_to_user(hdr
, log_response
, xfer_len
);
949 /* MODE SENSE Helper Functions */
951 static int nvme_trans_fill_mode_parm_hdr(u8
*resp
, int len
, u8 cdb10
, u8 llbaa
,
952 u16 mode_data_length
, u16 blk_desc_len
)
954 /* Quick check to make sure I don't stomp on my own memory... */
955 if ((cdb10
&& len
< 8) || (!cdb10
&& len
< 4))
959 resp
[0] = (mode_data_length
& 0xFF00) >> 8;
960 resp
[1] = (mode_data_length
& 0x00FF);
961 resp
[3] = 0x10 /* DPOFUA */;
963 resp
[5] = RESERVED_FIELD
;
964 resp
[6] = (blk_desc_len
& 0xFF00) >> 8;
965 resp
[7] = (blk_desc_len
& 0x00FF);
967 resp
[0] = (mode_data_length
& 0x00FF);
968 resp
[2] = 0x10 /* DPOFUA */;
969 resp
[3] = (blk_desc_len
& 0x00FF);
975 static int nvme_trans_fill_blk_desc(struct nvme_ns
*ns
, struct sg_io_hdr
*hdr
,
976 u8
*resp
, int len
, u8 llbaa
)
980 struct nvme_id_ns
*id_ns
;
984 if (llbaa
== 0 && len
< MODE_PAGE_BLK_DES_LEN
)
986 else if (llbaa
> 0 && len
< MODE_PAGE_LLBAA_BLK_DES_LEN
)
989 nvme_sc
= nvme_identify_ns(ns
->ctrl
, ns
->ns_id
, &id_ns
);
990 res
= nvme_trans_status_code(hdr
, nvme_sc
);
994 flbas
= (id_ns
->flbas
) & 0x0F;
995 lba_length
= (1 << (id_ns
->lbaf
[flbas
].ds
));
998 __be32 tmp_cap
= cpu_to_be32(le64_to_cpu(id_ns
->ncap
));
999 /* Byte 4 is reserved */
1000 __be32 tmp_len
= cpu_to_be32(lba_length
& 0x00FFFFFF);
1002 memcpy(resp
, &tmp_cap
, sizeof(u32
));
1003 memcpy(&resp
[4], &tmp_len
, sizeof(u32
));
1005 __be64 tmp_cap
= cpu_to_be64(le64_to_cpu(id_ns
->ncap
));
1006 __be32 tmp_len
= cpu_to_be32(lba_length
);
1008 memcpy(resp
, &tmp_cap
, sizeof(u64
));
1009 /* Bytes 8, 9, 10, 11 are reserved */
1010 memcpy(&resp
[12], &tmp_len
, sizeof(u32
));
1017 static int nvme_trans_fill_control_page(struct nvme_ns
*ns
,
1018 struct sg_io_hdr
*hdr
, u8
*resp
,
1021 if (len
< MODE_PAGE_CONTROL_LEN
)
1024 resp
[0] = MODE_PAGE_CONTROL
;
1025 resp
[1] = MODE_PAGE_CONTROL_LEN_FIELD
;
1026 resp
[2] = 0x0E; /* TST=000b, TMF_ONLY=0, DPICZ=1,
1027 * D_SENSE=1, GLTSD=1, RLEC=0 */
1028 resp
[3] = 0x12; /* Q_ALGO_MODIFIER=1h, NUAR=0, QERR=01b */
1029 /* Byte 4: VS=0, RAC=0, UA_INT=0, SWP=0 */
1030 resp
[5] = 0x40; /* ATO=0, TAS=1, ATMPE=0, RWWP=0, AUTOLOAD=0 */
1031 /* resp[6] and [7] are obsolete, thus zero */
1032 resp
[8] = 0xFF; /* Busy timeout period = 0xffff */
1034 /* Bytes 10,11: Extended selftest completion time = 0x0000 */
1039 static int nvme_trans_fill_caching_page(struct nvme_ns
*ns
,
1040 struct sg_io_hdr
*hdr
,
1048 if (len
< MODE_PAGE_CACHING_LEN
)
1051 nvme_sc
= nvme_get_features(ns
->ctrl
, NVME_FEAT_VOLATILE_WC
, 0, 0,
1053 res
= nvme_trans_status_code(hdr
, nvme_sc
);
1057 vwc
= feature_resp
& 0x00000001;
1059 resp
[0] = MODE_PAGE_CACHING
;
1060 resp
[1] = MODE_PAGE_CACHING_LEN_FIELD
;
1065 static int nvme_trans_fill_pow_cnd_page(struct nvme_ns
*ns
,
1066 struct sg_io_hdr
*hdr
, u8
*resp
,
1069 if (len
< MODE_PAGE_POW_CND_LEN
)
1072 resp
[0] = MODE_PAGE_POWER_CONDITION
;
1073 resp
[1] = MODE_PAGE_POW_CND_LEN_FIELD
;
1074 /* All other bytes are zero */
1079 static int nvme_trans_fill_inf_exc_page(struct nvme_ns
*ns
,
1080 struct sg_io_hdr
*hdr
, u8
*resp
,
1083 if (len
< MODE_PAGE_INF_EXC_LEN
)
1086 resp
[0] = MODE_PAGE_INFO_EXCEP
;
1087 resp
[1] = MODE_PAGE_INF_EXC_LEN_FIELD
;
1089 /* All other bytes are zero */
1094 static int nvme_trans_fill_all_pages(struct nvme_ns
*ns
, struct sg_io_hdr
*hdr
,
1098 u16 mode_pages_offset_1
= 0;
1099 u16 mode_pages_offset_2
, mode_pages_offset_3
, mode_pages_offset_4
;
1101 mode_pages_offset_2
= mode_pages_offset_1
+ MODE_PAGE_CACHING_LEN
;
1102 mode_pages_offset_3
= mode_pages_offset_2
+ MODE_PAGE_CONTROL_LEN
;
1103 mode_pages_offset_4
= mode_pages_offset_3
+ MODE_PAGE_POW_CND_LEN
;
1105 res
= nvme_trans_fill_caching_page(ns
, hdr
, &resp
[mode_pages_offset_1
],
1106 MODE_PAGE_CACHING_LEN
);
1109 res
= nvme_trans_fill_control_page(ns
, hdr
, &resp
[mode_pages_offset_2
],
1110 MODE_PAGE_CONTROL_LEN
);
1113 res
= nvme_trans_fill_pow_cnd_page(ns
, hdr
, &resp
[mode_pages_offset_3
],
1114 MODE_PAGE_POW_CND_LEN
);
1117 return nvme_trans_fill_inf_exc_page(ns
, hdr
, &resp
[mode_pages_offset_4
],
1118 MODE_PAGE_INF_EXC_LEN
);
1121 static inline int nvme_trans_get_blk_desc_len(u8 dbd
, u8 llbaa
)
1123 if (dbd
== MODE_SENSE_BLK_DESC_ENABLED
) {
1124 /* SPC-4: len = 8 x Num_of_descriptors if llbaa = 0, 16x if 1 */
1125 return 8 * (llbaa
+ 1) * MODE_SENSE_BLK_DESC_COUNT
;
1131 static int nvme_trans_mode_page_create(struct nvme_ns
*ns
,
1132 struct sg_io_hdr
*hdr
, u8
*cmd
,
1133 u16 alloc_len
, u8 cdb10
,
1134 int (*mode_page_fill_func
)
1136 struct sg_io_hdr
*hdr
, u8
*, int),
1137 u16 mode_pages_tot_len
)
1145 u16 mode_pages_offset_1
;
1146 u16 blk_desc_len
, blk_desc_offset
, mode_data_length
;
1148 dbd
= (cmd
[1] & MODE_SENSE_DBD_MASK
) >> MODE_SENSE_DBD_SHIFT
;
1149 llbaa
= (cmd
[1] & MODE_SENSE_LLBAA_MASK
) >> MODE_SENSE_LLBAA_SHIFT
;
1150 mph_size
= cdb10
? MODE_SENSE10_MPH_SIZE
: MODE_SENSE6_MPH_SIZE
;
1152 blk_desc_len
= nvme_trans_get_blk_desc_len(dbd
, llbaa
);
1154 resp_size
= mph_size
+ blk_desc_len
+ mode_pages_tot_len
;
1155 /* Refer spc4r34 Table 440 for calculation of Mode data Length field */
1156 mode_data_length
= 3 + (3 * cdb10
) + blk_desc_len
+ mode_pages_tot_len
;
1158 blk_desc_offset
= mph_size
;
1159 mode_pages_offset_1
= blk_desc_offset
+ blk_desc_len
;
1161 response
= kzalloc(resp_size
, GFP_KERNEL
);
1162 if (response
== NULL
) {
1167 res
= nvme_trans_fill_mode_parm_hdr(&response
[0], mph_size
, cdb10
,
1168 llbaa
, mode_data_length
, blk_desc_len
);
1171 if (blk_desc_len
> 0) {
1172 res
= nvme_trans_fill_blk_desc(ns
, hdr
,
1173 &response
[blk_desc_offset
],
1174 blk_desc_len
, llbaa
);
1178 res
= mode_page_fill_func(ns
, hdr
, &response
[mode_pages_offset_1
],
1179 mode_pages_tot_len
);
1183 xfer_len
= min(alloc_len
, resp_size
);
1184 res
= nvme_trans_copy_to_user(hdr
, response
, xfer_len
);
1192 /* Read Capacity Helper Functions */
1194 static void nvme_trans_fill_read_cap(u8
*response
, struct nvme_id_ns
*id_ns
,
1201 u8 p_type_lut
[4] = {0, 0, 1, 2};
1206 flbas
= (id_ns
->flbas
) & 0x0F;
1207 lba_length
= (1 << (id_ns
->lbaf
[flbas
].ds
));
1208 rlba
= le64_to_cpup(&id_ns
->nsze
) - 1;
1209 (id_ns
->dps
) ? (prot_en
= 0x01) : (prot_en
= 0);
1212 if (rlba
> 0xFFFFFFFF)
1214 tmp_rlba_32
= cpu_to_be32(rlba
);
1215 tmp_len
= cpu_to_be32(lba_length
);
1216 memcpy(response
, &tmp_rlba_32
, sizeof(u32
));
1217 memcpy(&response
[4], &tmp_len
, sizeof(u32
));
1219 tmp_rlba
= cpu_to_be64(rlba
);
1220 tmp_len
= cpu_to_be32(lba_length
);
1221 memcpy(response
, &tmp_rlba
, sizeof(u64
));
1222 memcpy(&response
[8], &tmp_len
, sizeof(u32
));
1223 response
[12] = (p_type_lut
[id_ns
->dps
& 0x3] << 1) | prot_en
;
1224 /* P_I_Exponent = 0x0 | LBPPBE = 0x0 */
1225 /* LBPME = 0 | LBPRZ = 0 | LALBA = 0x00 */
1226 /* Bytes 16-31 - Reserved */
1230 /* Start Stop Unit Helper Functions */
1232 static int nvme_trans_power_state(struct nvme_ns
*ns
, struct sg_io_hdr
*hdr
,
1233 u8 pc
, u8 pcmod
, u8 start
)
1237 struct nvme_id_ctrl
*id_ctrl
;
1238 int lowest_pow_st
; /* max npss = lowest power consumption */
1239 unsigned ps_desired
= 0;
1241 nvme_sc
= nvme_identify_ctrl(ns
->ctrl
, &id_ctrl
);
1242 res
= nvme_trans_status_code(hdr
, nvme_sc
);
1246 lowest_pow_st
= max(POWER_STATE_0
, (int)(id_ctrl
->npss
- 1));
1250 case NVME_POWER_STATE_START_VALID
:
1251 /* Action unspecified if POWER CONDITION MODIFIER != 0 */
1252 if (pcmod
== 0 && start
== 0x1)
1253 ps_desired
= POWER_STATE_0
;
1254 if (pcmod
== 0 && start
== 0x0)
1255 ps_desired
= lowest_pow_st
;
1257 case NVME_POWER_STATE_ACTIVE
:
1258 /* Action unspecified if POWER CONDITION MODIFIER != 0 */
1260 ps_desired
= POWER_STATE_0
;
1262 case NVME_POWER_STATE_IDLE
:
1263 /* Action unspecified if POWER CONDITION MODIFIER != [0,1,2] */
1265 ps_desired
= POWER_STATE_1
;
1266 else if (pcmod
== 0x1)
1267 ps_desired
= POWER_STATE_2
;
1268 else if (pcmod
== 0x2)
1269 ps_desired
= POWER_STATE_3
;
1271 case NVME_POWER_STATE_STANDBY
:
1272 /* Action unspecified if POWER CONDITION MODIFIER != [0,1] */
1274 ps_desired
= max(POWER_STATE_0
, (lowest_pow_st
- 2));
1275 else if (pcmod
== 0x1)
1276 ps_desired
= max(POWER_STATE_0
, (lowest_pow_st
- 1));
1278 case NVME_POWER_STATE_LU_CONTROL
:
1280 res
= nvme_trans_completion(hdr
, SAM_STAT_CHECK_CONDITION
,
1281 ILLEGAL_REQUEST
, SCSI_ASC_INVALID_CDB
,
1282 SCSI_ASCQ_CAUSE_NOT_REPORTABLE
);
1285 nvme_sc
= nvme_set_features(ns
->ctrl
, NVME_FEAT_POWER_MGMT
, ps_desired
, 0,
1287 return nvme_trans_status_code(hdr
, nvme_sc
);
1290 static int nvme_trans_send_activate_fw_cmd(struct nvme_ns
*ns
, struct sg_io_hdr
*hdr
,
1293 struct nvme_command c
;
1296 memset(&c
, 0, sizeof(c
));
1297 c
.common
.opcode
= nvme_admin_activate_fw
;
1298 c
.common
.cdw10
[0] = cpu_to_le32(buffer_id
| NVME_FWACT_REPL_ACTV
);
1300 nvme_sc
= nvme_submit_sync_cmd(ns
->queue
, &c
, NULL
, 0);
1301 return nvme_trans_status_code(hdr
, nvme_sc
);
1304 static int nvme_trans_send_download_fw_cmd(struct nvme_ns
*ns
, struct sg_io_hdr
*hdr
,
1305 u8 opcode
, u32 tot_len
, u32 offset
,
1309 struct nvme_command c
;
1311 if (hdr
->iovec_count
> 0) {
1312 /* Assuming SGL is not allowed for this command */
1313 return nvme_trans_completion(hdr
,
1314 SAM_STAT_CHECK_CONDITION
,
1316 SCSI_ASC_INVALID_CDB
,
1317 SCSI_ASCQ_CAUSE_NOT_REPORTABLE
);
1320 memset(&c
, 0, sizeof(c
));
1321 c
.common
.opcode
= nvme_admin_download_fw
;
1322 c
.dlfw
.numd
= cpu_to_le32((tot_len
/BYTES_TO_DWORDS
) - 1);
1323 c
.dlfw
.offset
= cpu_to_le32(offset
/BYTES_TO_DWORDS
);
1325 nvme_sc
= nvme_submit_user_cmd(ns
->ctrl
->admin_q
, &c
,
1326 hdr
->dxferp
, tot_len
, NULL
, 0);
1327 return nvme_trans_status_code(hdr
, nvme_sc
);
1330 /* Mode Select Helper Functions */
1332 static inline void nvme_trans_modesel_get_bd_len(u8
*parm_list
, u8 cdb10
,
1333 u16
*bd_len
, u8
*llbaa
)
1337 *bd_len
= (parm_list
[MODE_SELECT_10_BD_OFFSET
] << 8) +
1338 parm_list
[MODE_SELECT_10_BD_OFFSET
+ 1];
1339 *llbaa
= parm_list
[MODE_SELECT_10_LLBAA_OFFSET
] &
1340 MODE_SELECT_10_LLBAA_MASK
;
1343 *bd_len
= parm_list
[MODE_SELECT_6_BD_OFFSET
];
1347 static void nvme_trans_modesel_save_bd(struct nvme_ns
*ns
, u8
*parm_list
,
1348 u16 idx
, u16 bd_len
, u8 llbaa
)
1352 bd_num
= bd_len
/ ((llbaa
== 0) ?
1353 SHORT_DESC_BLOCK
: LONG_DESC_BLOCK
);
1354 /* Store block descriptor info if a FORMAT UNIT comes later */
1355 /* TODO Saving 1st BD info; what to do if multiple BD received? */
1357 /* Standard Block Descriptor - spc4r34 7.5.5.1 */
1358 ns
->mode_select_num_blocks
=
1359 (parm_list
[idx
+ 1] << 16) +
1360 (parm_list
[idx
+ 2] << 8) +
1361 (parm_list
[idx
+ 3]);
1363 ns
->mode_select_block_len
=
1364 (parm_list
[idx
+ 5] << 16) +
1365 (parm_list
[idx
+ 6] << 8) +
1366 (parm_list
[idx
+ 7]);
1368 /* Long LBA Block Descriptor - sbc3r27 6.4.2.3 */
1369 ns
->mode_select_num_blocks
=
1370 (((u64
)parm_list
[idx
+ 0]) << 56) +
1371 (((u64
)parm_list
[idx
+ 1]) << 48) +
1372 (((u64
)parm_list
[idx
+ 2]) << 40) +
1373 (((u64
)parm_list
[idx
+ 3]) << 32) +
1374 (((u64
)parm_list
[idx
+ 4]) << 24) +
1375 (((u64
)parm_list
[idx
+ 5]) << 16) +
1376 (((u64
)parm_list
[idx
+ 6]) << 8) +
1377 ((u64
)parm_list
[idx
+ 7]);
1379 ns
->mode_select_block_len
=
1380 (parm_list
[idx
+ 12] << 24) +
1381 (parm_list
[idx
+ 13] << 16) +
1382 (parm_list
[idx
+ 14] << 8) +
1383 (parm_list
[idx
+ 15]);
1387 static int nvme_trans_modesel_get_mp(struct nvme_ns
*ns
, struct sg_io_hdr
*hdr
,
1388 u8
*mode_page
, u8 page_code
)
1394 switch (page_code
) {
1395 case MODE_PAGE_CACHING
:
1396 dword11
= ((mode_page
[2] & CACHING_MODE_PAGE_WCE_MASK
) ? 1 : 0);
1397 nvme_sc
= nvme_set_features(ns
->ctrl
, NVME_FEAT_VOLATILE_WC
,
1399 res
= nvme_trans_status_code(hdr
, nvme_sc
);
1401 case MODE_PAGE_CONTROL
:
1403 case MODE_PAGE_POWER_CONDITION
:
1404 /* Verify the OS is not trying to set timers */
1405 if ((mode_page
[2] & 0x01) != 0 || (mode_page
[3] & 0x0F) != 0) {
1406 res
= nvme_trans_completion(hdr
,
1407 SAM_STAT_CHECK_CONDITION
,
1409 SCSI_ASC_INVALID_PARAMETER
,
1410 SCSI_ASCQ_CAUSE_NOT_REPORTABLE
);
1415 res
= nvme_trans_completion(hdr
, SAM_STAT_CHECK_CONDITION
,
1416 ILLEGAL_REQUEST
, SCSI_ASC_INVALID_CDB
,
1417 SCSI_ASCQ_CAUSE_NOT_REPORTABLE
);
1424 static int nvme_trans_modesel_data(struct nvme_ns
*ns
, struct sg_io_hdr
*hdr
,
1425 u8
*cmd
, u16 parm_list_len
, u8 pf
,
1432 u16 index
, saved_index
;
1436 /* Get parm list from data-in/out buffer */
1437 parm_list
= kmalloc(parm_list_len
, GFP_KERNEL
);
1438 if (parm_list
== NULL
) {
1443 res
= nvme_trans_copy_from_user(hdr
, parm_list
, parm_list_len
);
1447 nvme_trans_modesel_get_bd_len(parm_list
, cdb10
, &bd_len
, &llbaa
);
1448 index
= (cdb10
) ? (MODE_SELECT_10_MPH_SIZE
) : (MODE_SELECT_6_MPH_SIZE
);
1451 /* Block Descriptors present, parse */
1452 nvme_trans_modesel_save_bd(ns
, parm_list
, index
, bd_len
, llbaa
);
1455 saved_index
= index
;
1457 /* Multiple mode pages may be present; iterate through all */
1458 /* In 1st Iteration, don't do NVME Command, only check for CDB errors */
1460 page_code
= parm_list
[index
] & MODE_SELECT_PAGE_CODE_MASK
;
1461 mp_size
= parm_list
[index
+ 1] + 2;
1462 if ((page_code
!= MODE_PAGE_CACHING
) &&
1463 (page_code
!= MODE_PAGE_CONTROL
) &&
1464 (page_code
!= MODE_PAGE_POWER_CONDITION
)) {
1465 res
= nvme_trans_completion(hdr
,
1466 SAM_STAT_CHECK_CONDITION
,
1468 SCSI_ASC_INVALID_CDB
,
1469 SCSI_ASCQ_CAUSE_NOT_REPORTABLE
);
1473 } while (index
< parm_list_len
);
1475 /* In 2nd Iteration, do the NVME Commands */
1476 index
= saved_index
;
1478 page_code
= parm_list
[index
] & MODE_SELECT_PAGE_CODE_MASK
;
1479 mp_size
= parm_list
[index
+ 1] + 2;
1480 res
= nvme_trans_modesel_get_mp(ns
, hdr
, &parm_list
[index
],
1485 } while (index
< parm_list_len
);
1493 /* Format Unit Helper Functions */
1495 static int nvme_trans_fmt_set_blk_size_count(struct nvme_ns
*ns
,
1496 struct sg_io_hdr
*hdr
)
1503 * SCSI Expects a MODE SELECT would have been issued prior to
1504 * a FORMAT UNIT, and the block size and number would be used
1505 * from the block descriptor in it. If a MODE SELECT had not
1506 * been issued, FORMAT shall use the current values for both.
1509 if (ns
->mode_select_num_blocks
== 0 || ns
->mode_select_block_len
== 0) {
1510 struct nvme_id_ns
*id_ns
;
1512 nvme_sc
= nvme_identify_ns(ns
->ctrl
, ns
->ns_id
, &id_ns
);
1513 res
= nvme_trans_status_code(hdr
, nvme_sc
);
1517 if (ns
->mode_select_num_blocks
== 0)
1518 ns
->mode_select_num_blocks
= le64_to_cpu(id_ns
->ncap
);
1519 if (ns
->mode_select_block_len
== 0) {
1520 flbas
= (id_ns
->flbas
) & 0x0F;
1521 ns
->mode_select_block_len
=
1522 (1 << (id_ns
->lbaf
[flbas
].ds
));
1531 static int nvme_trans_fmt_get_parm_header(struct sg_io_hdr
*hdr
, u8 len
,
1532 u8 format_prot_info
, u8
*nvme_pf_code
)
1536 u8 pf_usage
, pf_code
;
1538 parm_list
= kmalloc(len
, GFP_KERNEL
);
1539 if (parm_list
== NULL
) {
1543 res
= nvme_trans_copy_from_user(hdr
, parm_list
, len
);
1547 if ((parm_list
[FORMAT_UNIT_IMMED_OFFSET
] &
1548 FORMAT_UNIT_IMMED_MASK
) != 0) {
1549 res
= nvme_trans_completion(hdr
, SAM_STAT_CHECK_CONDITION
,
1550 ILLEGAL_REQUEST
, SCSI_ASC_INVALID_CDB
,
1551 SCSI_ASCQ_CAUSE_NOT_REPORTABLE
);
1555 if (len
== FORMAT_UNIT_LONG_PARM_LIST_LEN
&&
1556 (parm_list
[FORMAT_UNIT_PROT_INT_OFFSET
] & 0x0F) != 0) {
1557 res
= nvme_trans_completion(hdr
, SAM_STAT_CHECK_CONDITION
,
1558 ILLEGAL_REQUEST
, SCSI_ASC_INVALID_CDB
,
1559 SCSI_ASCQ_CAUSE_NOT_REPORTABLE
);
1562 pf_usage
= parm_list
[FORMAT_UNIT_PROT_FIELD_USAGE_OFFSET
] &
1563 FORMAT_UNIT_PROT_FIELD_USAGE_MASK
;
1564 pf_code
= (pf_usage
<< 2) | format_prot_info
;
1579 res
= nvme_trans_completion(hdr
, SAM_STAT_CHECK_CONDITION
,
1580 ILLEGAL_REQUEST
, SCSI_ASC_INVALID_CDB
,
1581 SCSI_ASCQ_CAUSE_NOT_REPORTABLE
);
1591 static int nvme_trans_fmt_send_cmd(struct nvme_ns
*ns
, struct sg_io_hdr
*hdr
,
1596 struct nvme_id_ns
*id_ns
;
1599 u8 selected_lbaf
= 0xFF;
1601 struct nvme_command c
;
1603 /* Loop thru LBAF's in id_ns to match reqd lbaf, put in cdw10 */
1604 nvme_sc
= nvme_identify_ns(ns
->ctrl
, ns
->ns_id
, &id_ns
);
1605 res
= nvme_trans_status_code(hdr
, nvme_sc
);
1609 flbas
= (id_ns
->flbas
) & 0x0F;
1610 nlbaf
= id_ns
->nlbaf
;
1612 for (i
= 0; i
< nlbaf
; i
++) {
1613 if (ns
->mode_select_block_len
== (1 << (id_ns
->lbaf
[i
].ds
))) {
1618 if (selected_lbaf
> 0x0F) {
1619 res
= nvme_trans_completion(hdr
, SAM_STAT_CHECK_CONDITION
,
1620 ILLEGAL_REQUEST
, SCSI_ASC_INVALID_PARAMETER
,
1621 SCSI_ASCQ_CAUSE_NOT_REPORTABLE
);
1623 if (ns
->mode_select_num_blocks
!= le64_to_cpu(id_ns
->ncap
)) {
1624 res
= nvme_trans_completion(hdr
, SAM_STAT_CHECK_CONDITION
,
1625 ILLEGAL_REQUEST
, SCSI_ASC_INVALID_PARAMETER
,
1626 SCSI_ASCQ_CAUSE_NOT_REPORTABLE
);
1629 cdw10
|= prot_info
<< 5;
1630 cdw10
|= selected_lbaf
& 0x0F;
1631 memset(&c
, 0, sizeof(c
));
1632 c
.format
.opcode
= nvme_admin_format_nvm
;
1633 c
.format
.nsid
= cpu_to_le32(ns
->ns_id
);
1634 c
.format
.cdw10
= cpu_to_le32(cdw10
);
1636 nvme_sc
= nvme_submit_sync_cmd(ns
->ctrl
->admin_q
, &c
, NULL
, 0);
1637 res
= nvme_trans_status_code(hdr
, nvme_sc
);
1643 static inline u32
nvme_trans_io_get_num_cmds(struct sg_io_hdr
*hdr
,
1644 struct nvme_trans_io_cdb
*cdb_info
,
1647 /* If using iovecs, send one nvme command per vector */
1648 if (hdr
->iovec_count
> 0)
1649 return hdr
->iovec_count
;
1650 else if (cdb_info
->xfer_len
> max_blocks
)
1651 return ((cdb_info
->xfer_len
- 1) / max_blocks
) + 1;
1656 static u16
nvme_trans_io_get_control(struct nvme_ns
*ns
,
1657 struct nvme_trans_io_cdb
*cdb_info
)
1661 /* When Protection information support is added, implement here */
1663 if (cdb_info
->fua
> 0)
1664 control
|= NVME_RW_FUA
;
1669 static int nvme_trans_do_nvme_io(struct nvme_ns
*ns
, struct sg_io_hdr
*hdr
,
1670 struct nvme_trans_io_cdb
*cdb_info
, u8 is_write
)
1672 int nvme_sc
= NVME_SC_SUCCESS
;
1675 u64 unit_num_blocks
; /* Number of blocks to xfer in each nvme cmd */
1678 u64 nvme_offset
= 0;
1679 void __user
*next_mapping_addr
;
1680 struct nvme_command c
;
1681 u8 opcode
= (is_write
? nvme_cmd_write
: nvme_cmd_read
);
1683 u32 max_blocks
= queue_max_hw_sectors(ns
->queue
);
1685 num_cmds
= nvme_trans_io_get_num_cmds(hdr
, cdb_info
, max_blocks
);
1688 * This loop handles two cases.
1689 * First, when an SGL is used in the form of an iovec list:
1690 * - Use iov_base as the next mapping address for the nvme command_id
1691 * - Use iov_len as the data transfer length for the command.
1692 * Second, when we have a single buffer
1693 * - If larger than max_blocks, split into chunks, offset
1694 * each nvme command accordingly.
1696 for (i
= 0; i
< num_cmds
; i
++) {
1697 memset(&c
, 0, sizeof(c
));
1698 if (hdr
->iovec_count
> 0) {
1699 struct sg_iovec sgl
;
1701 retcode
= copy_from_user(&sgl
, hdr
->dxferp
+
1702 i
* sizeof(struct sg_iovec
),
1703 sizeof(struct sg_iovec
));
1706 unit_len
= sgl
.iov_len
;
1707 unit_num_blocks
= unit_len
>> ns
->lba_shift
;
1708 next_mapping_addr
= sgl
.iov_base
;
1710 unit_num_blocks
= min((u64
)max_blocks
,
1711 (cdb_info
->xfer_len
- nvme_offset
));
1712 unit_len
= unit_num_blocks
<< ns
->lba_shift
;
1713 next_mapping_addr
= hdr
->dxferp
+
1714 ((1 << ns
->lba_shift
) * nvme_offset
);
1717 c
.rw
.opcode
= opcode
;
1718 c
.rw
.nsid
= cpu_to_le32(ns
->ns_id
);
1719 c
.rw
.slba
= cpu_to_le64(cdb_info
->lba
+ nvme_offset
);
1720 c
.rw
.length
= cpu_to_le16(unit_num_blocks
- 1);
1721 control
= nvme_trans_io_get_control(ns
, cdb_info
);
1722 c
.rw
.control
= cpu_to_le16(control
);
1724 if (get_capacity(ns
->disk
) - unit_num_blocks
<
1725 cdb_info
->lba
+ nvme_offset
) {
1726 nvme_sc
= NVME_SC_LBA_RANGE
;
1729 nvme_sc
= nvme_submit_user_cmd(ns
->queue
, &c
,
1730 next_mapping_addr
, unit_len
, NULL
, 0);
1734 nvme_offset
+= unit_num_blocks
;
1737 return nvme_trans_status_code(hdr
, nvme_sc
);
1741 /* SCSI Command Translation Functions */
1743 static int nvme_trans_io(struct nvme_ns
*ns
, struct sg_io_hdr
*hdr
, u8 is_write
,
1747 struct nvme_trans_io_cdb cdb_info
= { 0, };
1750 u64 sum_iov_len
= 0;
1751 struct sg_iovec sgl
;
1756 * The FUA and WPROTECT fields are not supported in 6-byte CDBs,
1757 * but always in the same place for all others.
1764 cdb_info
.fua
= cmd
[1] & 0x8;
1765 cdb_info
.prot_info
= (cmd
[1] & 0xe0) >> 5;
1766 if (cdb_info
.prot_info
&& !ns
->pi_type
) {
1767 return nvme_trans_completion(hdr
,
1768 SAM_STAT_CHECK_CONDITION
,
1770 SCSI_ASC_INVALID_CDB
,
1771 SCSI_ASCQ_CAUSE_NOT_REPORTABLE
);
1778 cdb_info
.lba
= get_unaligned_be24(&cmd
[1]);
1779 cdb_info
.xfer_len
= cmd
[4];
1780 if (cdb_info
.xfer_len
== 0)
1781 cdb_info
.xfer_len
= 256;
1785 cdb_info
.lba
= get_unaligned_be32(&cmd
[2]);
1786 cdb_info
.xfer_len
= get_unaligned_be16(&cmd
[7]);
1790 cdb_info
.lba
= get_unaligned_be32(&cmd
[2]);
1791 cdb_info
.xfer_len
= get_unaligned_be32(&cmd
[6]);
1795 cdb_info
.lba
= get_unaligned_be64(&cmd
[2]);
1796 cdb_info
.xfer_len
= get_unaligned_be32(&cmd
[10]);
1799 /* Will never really reach here */
1804 /* Calculate total length of transfer (in bytes) */
1805 if (hdr
->iovec_count
> 0) {
1806 for (i
= 0; i
< hdr
->iovec_count
; i
++) {
1807 not_copied
= copy_from_user(&sgl
, hdr
->dxferp
+
1808 i
* sizeof(struct sg_iovec
),
1809 sizeof(struct sg_iovec
));
1812 sum_iov_len
+= sgl
.iov_len
;
1813 /* IO vector sizes should be multiples of block size */
1814 if (sgl
.iov_len
% (1 << ns
->lba_shift
) != 0) {
1815 res
= nvme_trans_completion(hdr
,
1816 SAM_STAT_CHECK_CONDITION
,
1818 SCSI_ASC_INVALID_PARAMETER
,
1819 SCSI_ASCQ_CAUSE_NOT_REPORTABLE
);
1824 sum_iov_len
= hdr
->dxfer_len
;
1827 /* As Per sg ioctl howto, if the lengths differ, use the lower one */
1828 xfer_bytes
= min(((u64
)hdr
->dxfer_len
), sum_iov_len
);
1830 /* If block count and actual data buffer size dont match, error out */
1831 if (xfer_bytes
!= (cdb_info
.xfer_len
<< ns
->lba_shift
)) {
1836 /* Check for 0 length transfer - it is not illegal */
1837 if (cdb_info
.xfer_len
== 0)
1840 /* Send NVMe IO Command(s) */
1841 res
= nvme_trans_do_nvme_io(ns
, hdr
, &cdb_info
, is_write
);
1849 static int nvme_trans_inquiry(struct nvme_ns
*ns
, struct sg_io_hdr
*hdr
,
1858 evpd
= cmd
[1] & 0x01;
1860 alloc_len
= get_unaligned_be16(&cmd
[3]);
1862 inq_response
= kmalloc(max(alloc_len
, STANDARD_INQUIRY_LENGTH
),
1864 if (inq_response
== NULL
) {
1870 if (page_code
== INQ_STANDARD_INQUIRY_PAGE
) {
1871 res
= nvme_trans_standard_inquiry_page(ns
, hdr
,
1872 inq_response
, alloc_len
);
1874 res
= nvme_trans_completion(hdr
,
1875 SAM_STAT_CHECK_CONDITION
,
1877 SCSI_ASC_INVALID_CDB
,
1878 SCSI_ASCQ_CAUSE_NOT_REPORTABLE
);
1881 switch (page_code
) {
1882 case VPD_SUPPORTED_PAGES
:
1883 res
= nvme_trans_supported_vpd_pages(ns
, hdr
,
1884 inq_response
, alloc_len
);
1886 case VPD_SERIAL_NUMBER
:
1887 res
= nvme_trans_unit_serial_page(ns
, hdr
, inq_response
,
1890 case VPD_DEVICE_IDENTIFIERS
:
1891 res
= nvme_trans_device_id_page(ns
, hdr
, inq_response
,
1894 case VPD_EXTENDED_INQUIRY
:
1895 res
= nvme_trans_ext_inq_page(ns
, hdr
, alloc_len
);
1897 case VPD_BLOCK_LIMITS
:
1898 res
= nvme_trans_bdev_limits_page(ns
, hdr
, inq_response
,
1901 case VPD_BLOCK_DEV_CHARACTERISTICS
:
1902 res
= nvme_trans_bdev_char_page(ns
, hdr
, alloc_len
);
1905 res
= nvme_trans_completion(hdr
,
1906 SAM_STAT_CHECK_CONDITION
,
1908 SCSI_ASC_INVALID_CDB
,
1909 SCSI_ASCQ_CAUSE_NOT_REPORTABLE
);
1913 kfree(inq_response
);
1918 static int nvme_trans_log_sense(struct nvme_ns
*ns
, struct sg_io_hdr
*hdr
,
1926 if (cmd
[1] != LOG_SENSE_CDB_SP_NOT_ENABLED
) {
1927 res
= nvme_trans_completion(hdr
, SAM_STAT_CHECK_CONDITION
,
1928 ILLEGAL_REQUEST
, SCSI_ASC_INVALID_CDB
,
1929 SCSI_ASCQ_CAUSE_NOT_REPORTABLE
);
1933 page_code
= cmd
[2] & LOG_SENSE_CDB_PAGE_CODE_MASK
;
1934 pc
= (cmd
[2] & LOG_SENSE_CDB_PC_MASK
) >> LOG_SENSE_CDB_PC_SHIFT
;
1935 if (pc
!= LOG_SENSE_CDB_PC_CUMULATIVE_VALUES
) {
1936 res
= nvme_trans_completion(hdr
, SAM_STAT_CHECK_CONDITION
,
1937 ILLEGAL_REQUEST
, SCSI_ASC_INVALID_CDB
,
1938 SCSI_ASCQ_CAUSE_NOT_REPORTABLE
);
1941 alloc_len
= get_unaligned_be16(&cmd
[7]);
1942 switch (page_code
) {
1943 case LOG_PAGE_SUPPORTED_LOG_PAGES_PAGE
:
1944 res
= nvme_trans_log_supp_pages(ns
, hdr
, alloc_len
);
1946 case LOG_PAGE_INFORMATIONAL_EXCEPTIONS_PAGE
:
1947 res
= nvme_trans_log_info_exceptions(ns
, hdr
, alloc_len
);
1949 case LOG_PAGE_TEMPERATURE_PAGE
:
1950 res
= nvme_trans_log_temperature(ns
, hdr
, alloc_len
);
1953 res
= nvme_trans_completion(hdr
, SAM_STAT_CHECK_CONDITION
,
1954 ILLEGAL_REQUEST
, SCSI_ASC_INVALID_CDB
,
1955 SCSI_ASCQ_CAUSE_NOT_REPORTABLE
);
1963 static int nvme_trans_mode_select(struct nvme_ns
*ns
, struct sg_io_hdr
*hdr
,
1971 page_format
= cmd
[1] & MODE_SELECT_CDB_PAGE_FORMAT_MASK
;
1972 save_pages
= cmd
[1] & MODE_SELECT_CDB_SAVE_PAGES_MASK
;
1974 if (cmd
[0] == MODE_SELECT
) {
1975 parm_list_len
= cmd
[4];
1977 parm_list_len
= cmd
[7];
1981 if (parm_list_len
!= 0) {
1983 * According to SPC-4 r24, a paramter list length field of 0
1984 * shall not be considered an error
1986 return nvme_trans_modesel_data(ns
, hdr
, cmd
, parm_list_len
,
1987 page_format
, save_pages
, cdb10
);
1993 static int nvme_trans_mode_sense(struct nvme_ns
*ns
, struct sg_io_hdr
*hdr
,
2000 if (cmd
[0] == MODE_SENSE
) {
2003 alloc_len
= get_unaligned_be16(&cmd
[7]);
2007 if ((cmd
[2] & MODE_SENSE_PAGE_CONTROL_MASK
) !=
2008 MODE_SENSE_PC_CURRENT_VALUES
) {
2009 res
= nvme_trans_completion(hdr
, SAM_STAT_CHECK_CONDITION
,
2010 ILLEGAL_REQUEST
, SCSI_ASC_INVALID_CDB
,
2011 SCSI_ASCQ_CAUSE_NOT_REPORTABLE
);
2015 switch (cmd
[2] & MODE_SENSE_PAGE_CODE_MASK
) {
2016 case MODE_PAGE_CACHING
:
2017 res
= nvme_trans_mode_page_create(ns
, hdr
, cmd
, alloc_len
,
2019 &nvme_trans_fill_caching_page
,
2020 MODE_PAGE_CACHING_LEN
);
2022 case MODE_PAGE_CONTROL
:
2023 res
= nvme_trans_mode_page_create(ns
, hdr
, cmd
, alloc_len
,
2025 &nvme_trans_fill_control_page
,
2026 MODE_PAGE_CONTROL_LEN
);
2028 case MODE_PAGE_POWER_CONDITION
:
2029 res
= nvme_trans_mode_page_create(ns
, hdr
, cmd
, alloc_len
,
2031 &nvme_trans_fill_pow_cnd_page
,
2032 MODE_PAGE_POW_CND_LEN
);
2034 case MODE_PAGE_INFO_EXCEP
:
2035 res
= nvme_trans_mode_page_create(ns
, hdr
, cmd
, alloc_len
,
2037 &nvme_trans_fill_inf_exc_page
,
2038 MODE_PAGE_INF_EXC_LEN
);
2040 case MODE_PAGE_RETURN_ALL
:
2041 res
= nvme_trans_mode_page_create(ns
, hdr
, cmd
, alloc_len
,
2043 &nvme_trans_fill_all_pages
,
2047 res
= nvme_trans_completion(hdr
, SAM_STAT_CHECK_CONDITION
,
2048 ILLEGAL_REQUEST
, SCSI_ASC_INVALID_CDB
,
2049 SCSI_ASCQ_CAUSE_NOT_REPORTABLE
);
2057 static int nvme_trans_read_capacity(struct nvme_ns
*ns
, struct sg_io_hdr
*hdr
,
2065 struct nvme_id_ns
*id_ns
;
2069 alloc_len
= get_unaligned_be32(&cmd
[10]);
2070 resp_size
= READ_CAP_16_RESP_SIZE
;
2072 alloc_len
= READ_CAP_10_RESP_SIZE
;
2073 resp_size
= READ_CAP_10_RESP_SIZE
;
2076 nvme_sc
= nvme_identify_ns(ns
->ctrl
, ns
->ns_id
, &id_ns
);
2077 res
= nvme_trans_status_code(hdr
, nvme_sc
);
2081 response
= kzalloc(resp_size
, GFP_KERNEL
);
2082 if (response
== NULL
) {
2086 nvme_trans_fill_read_cap(response
, id_ns
, cdb16
);
2088 xfer_len
= min(alloc_len
, resp_size
);
2089 res
= nvme_trans_copy_to_user(hdr
, response
, xfer_len
);
2097 static int nvme_trans_report_luns(struct nvme_ns
*ns
, struct sg_io_hdr
*hdr
,
2102 u32 alloc_len
, xfer_len
, resp_size
;
2104 struct nvme_id_ctrl
*id_ctrl
;
2105 u32 ll_length
, lun_id
;
2106 u8 lun_id_offset
= REPORT_LUNS_FIRST_LUN_OFFSET
;
2111 return nvme_trans_completion(hdr
, SAM_STAT_CHECK_CONDITION
,
2112 ILLEGAL_REQUEST
, SCSI_ASC_INVALID_CDB
,
2113 SCSI_ASCQ_CAUSE_NOT_REPORTABLE
);
2114 case ALL_LUNS_RETURNED
:
2115 case ALL_WELL_KNOWN_LUNS_RETURNED
:
2116 case RESTRICTED_LUNS_RETURNED
:
2117 nvme_sc
= nvme_identify_ctrl(ns
->ctrl
, &id_ctrl
);
2118 res
= nvme_trans_status_code(hdr
, nvme_sc
);
2122 ll_length
= le32_to_cpu(id_ctrl
->nn
) * LUN_ENTRY_SIZE
;
2123 resp_size
= ll_length
+ LUN_DATA_HEADER_SIZE
;
2125 alloc_len
= get_unaligned_be32(&cmd
[6]);
2126 if (alloc_len
< resp_size
) {
2127 res
= nvme_trans_completion(hdr
,
2128 SAM_STAT_CHECK_CONDITION
,
2129 ILLEGAL_REQUEST
, SCSI_ASC_INVALID_CDB
,
2130 SCSI_ASCQ_CAUSE_NOT_REPORTABLE
);
2134 response
= kzalloc(resp_size
, GFP_KERNEL
);
2135 if (response
== NULL
) {
2140 /* The first LUN ID will always be 0 per the SAM spec */
2141 for (lun_id
= 0; lun_id
< le32_to_cpu(id_ctrl
->nn
); lun_id
++) {
2143 * Set the LUN Id and then increment to the next LUN
2144 * location in the parameter data.
2146 __be64 tmp_id
= cpu_to_be64(lun_id
);
2147 memcpy(&response
[lun_id_offset
], &tmp_id
, sizeof(u64
));
2148 lun_id_offset
+= LUN_ENTRY_SIZE
;
2150 tmp_len
= cpu_to_be32(ll_length
);
2151 memcpy(response
, &tmp_len
, sizeof(u32
));
2154 xfer_len
= min(alloc_len
, resp_size
);
2155 res
= nvme_trans_copy_to_user(hdr
, response
, xfer_len
);
2163 static int nvme_trans_request_sense(struct nvme_ns
*ns
, struct sg_io_hdr
*hdr
,
2167 u8 alloc_len
, xfer_len
, resp_size
;
2171 desc_format
= cmd
[1] & 0x01;
2174 resp_size
= ((desc_format
) ? (DESC_FMT_SENSE_DATA_SIZE
) :
2175 (FIXED_FMT_SENSE_DATA_SIZE
));
2176 response
= kzalloc(resp_size
, GFP_KERNEL
);
2177 if (response
== NULL
) {
2183 /* Descriptor Format Sense Data */
2184 response
[0] = DESC_FORMAT_SENSE_DATA
;
2185 response
[1] = NO_SENSE
;
2186 /* TODO How is LOW POWER CONDITION ON handled? (byte 2) */
2187 response
[2] = SCSI_ASC_NO_SENSE
;
2188 response
[3] = SCSI_ASCQ_CAUSE_NOT_REPORTABLE
;
2189 /* SDAT_OVFL = 0 | Additional Sense Length = 0 */
2191 /* Fixed Format Sense Data */
2192 response
[0] = FIXED_SENSE_DATA
;
2193 /* Byte 1 = Obsolete */
2194 response
[2] = NO_SENSE
; /* FM, EOM, ILI, SDAT_OVFL = 0 */
2195 /* Bytes 3-6 - Information - set to zero */
2196 response
[7] = FIXED_SENSE_DATA_ADD_LENGTH
;
2197 /* Bytes 8-11 - Cmd Specific Information - set to zero */
2198 response
[12] = SCSI_ASC_NO_SENSE
;
2199 response
[13] = SCSI_ASCQ_CAUSE_NOT_REPORTABLE
;
2200 /* Byte 14 = Field Replaceable Unit Code = 0 */
2201 /* Bytes 15-17 - SKSV=0; Sense Key Specific = 0 */
2204 xfer_len
= min(alloc_len
, resp_size
);
2205 res
= nvme_trans_copy_to_user(hdr
, response
, xfer_len
);
2212 static int nvme_trans_security_protocol(struct nvme_ns
*ns
,
2213 struct sg_io_hdr
*hdr
,
2216 return nvme_trans_completion(hdr
, SAM_STAT_CHECK_CONDITION
,
2217 ILLEGAL_REQUEST
, SCSI_ASC_ILLEGAL_COMMAND
,
2218 SCSI_ASCQ_CAUSE_NOT_REPORTABLE
);
2221 static int nvme_trans_synchronize_cache(struct nvme_ns
*ns
,
2222 struct sg_io_hdr
*hdr
)
2225 struct nvme_command c
;
2227 memset(&c
, 0, sizeof(c
));
2228 c
.common
.opcode
= nvme_cmd_flush
;
2229 c
.common
.nsid
= cpu_to_le32(ns
->ns_id
);
2231 nvme_sc
= nvme_submit_sync_cmd(ns
->queue
, &c
, NULL
, 0);
2232 return nvme_trans_status_code(hdr
, nvme_sc
);
2235 static int nvme_trans_start_stop(struct nvme_ns
*ns
, struct sg_io_hdr
*hdr
,
2238 u8 immed
, pcmod
, pc
, no_flush
, start
;
2240 immed
= cmd
[1] & 0x01;
2241 pcmod
= cmd
[3] & 0x0f;
2242 pc
= (cmd
[4] & 0xf0) >> 4;
2243 no_flush
= cmd
[4] & 0x04;
2244 start
= cmd
[4] & 0x01;
2247 return nvme_trans_completion(hdr
, SAM_STAT_CHECK_CONDITION
,
2248 ILLEGAL_REQUEST
, SCSI_ASC_INVALID_CDB
,
2249 SCSI_ASCQ_CAUSE_NOT_REPORTABLE
);
2251 if (no_flush
== 0) {
2252 /* Issue NVME FLUSH command prior to START STOP UNIT */
2253 int res
= nvme_trans_synchronize_cache(ns
, hdr
);
2257 /* Setup the expected power state transition */
2258 return nvme_trans_power_state(ns
, hdr
, pc
, pcmod
, start
);
2262 static int nvme_trans_format_unit(struct nvme_ns
*ns
, struct sg_io_hdr
*hdr
,
2266 u8 parm_hdr_len
= 0;
2267 u8 nvme_pf_code
= 0;
2268 u8 format_prot_info
, long_list
, format_data
;
2270 format_prot_info
= (cmd
[1] & 0xc0) >> 6;
2271 long_list
= cmd
[1] & 0x20;
2272 format_data
= cmd
[1] & 0x10;
2274 if (format_data
!= 0) {
2275 if (format_prot_info
!= 0) {
2277 parm_hdr_len
= FORMAT_UNIT_SHORT_PARM_LIST_LEN
;
2279 parm_hdr_len
= FORMAT_UNIT_LONG_PARM_LIST_LEN
;
2281 } else if (format_data
== 0 && format_prot_info
!= 0) {
2282 res
= nvme_trans_completion(hdr
, SAM_STAT_CHECK_CONDITION
,
2283 ILLEGAL_REQUEST
, SCSI_ASC_INVALID_CDB
,
2284 SCSI_ASCQ_CAUSE_NOT_REPORTABLE
);
2288 /* Get parm header from data-in/out buffer */
2290 * According to the translation spec, the only fields in the parameter
2291 * list we are concerned with are in the header. So allocate only that.
2293 if (parm_hdr_len
> 0) {
2294 res
= nvme_trans_fmt_get_parm_header(hdr
, parm_hdr_len
,
2295 format_prot_info
, &nvme_pf_code
);
2300 /* Attempt to activate any previously downloaded firmware image */
2301 res
= nvme_trans_send_activate_fw_cmd(ns
, hdr
, 0);
2303 /* Determine Block size and count and send format command */
2304 res
= nvme_trans_fmt_set_blk_size_count(ns
, hdr
);
2308 res
= nvme_trans_fmt_send_cmd(ns
, hdr
, nvme_pf_code
);
2314 static int nvme_trans_test_unit_ready(struct nvme_ns
*ns
,
2315 struct sg_io_hdr
*hdr
,
2318 if (nvme_ctrl_ready(ns
->ctrl
))
2319 return nvme_trans_completion(hdr
, SAM_STAT_CHECK_CONDITION
,
2320 NOT_READY
, SCSI_ASC_LUN_NOT_READY
,
2321 SCSI_ASCQ_CAUSE_NOT_REPORTABLE
);
2323 return nvme_trans_completion(hdr
, SAM_STAT_GOOD
, NO_SENSE
, 0, 0);
2326 static int nvme_trans_write_buffer(struct nvme_ns
*ns
, struct sg_io_hdr
*hdr
,
2330 u32 buffer_offset
, parm_list_length
;
2333 parm_list_length
= get_unaligned_be24(&cmd
[6]);
2334 if (parm_list_length
% BYTES_TO_DWORDS
!= 0) {
2335 /* NVMe expects Firmware file to be a whole number of DWORDS */
2336 res
= nvme_trans_completion(hdr
, SAM_STAT_CHECK_CONDITION
,
2337 ILLEGAL_REQUEST
, SCSI_ASC_INVALID_CDB
,
2338 SCSI_ASCQ_CAUSE_NOT_REPORTABLE
);
2342 if (buffer_id
> NVME_MAX_FIRMWARE_SLOT
) {
2343 res
= nvme_trans_completion(hdr
, SAM_STAT_CHECK_CONDITION
,
2344 ILLEGAL_REQUEST
, SCSI_ASC_INVALID_CDB
,
2345 SCSI_ASCQ_CAUSE_NOT_REPORTABLE
);
2348 mode
= cmd
[1] & 0x1f;
2349 buffer_offset
= get_unaligned_be24(&cmd
[3]);
2352 case DOWNLOAD_SAVE_ACTIVATE
:
2353 res
= nvme_trans_send_download_fw_cmd(ns
, hdr
, nvme_admin_download_fw
,
2354 parm_list_length
, buffer_offset
,
2358 res
= nvme_trans_send_activate_fw_cmd(ns
, hdr
, buffer_id
);
2360 case DOWNLOAD_SAVE_DEFER_ACTIVATE
:
2361 res
= nvme_trans_send_download_fw_cmd(ns
, hdr
, nvme_admin_download_fw
,
2362 parm_list_length
, buffer_offset
,
2365 case ACTIVATE_DEFERRED_MICROCODE
:
2366 res
= nvme_trans_send_activate_fw_cmd(ns
, hdr
, buffer_id
);
2369 res
= nvme_trans_completion(hdr
, SAM_STAT_CHECK_CONDITION
,
2370 ILLEGAL_REQUEST
, SCSI_ASC_INVALID_CDB
,
2371 SCSI_ASCQ_CAUSE_NOT_REPORTABLE
);
2379 struct scsi_unmap_blk_desc
{
2385 struct scsi_unmap_parm_list
{
2386 __be16 unmap_data_len
;
2387 __be16 unmap_blk_desc_data_len
;
2389 struct scsi_unmap_blk_desc desc
[0];
2392 static int nvme_trans_unmap(struct nvme_ns
*ns
, struct sg_io_hdr
*hdr
,
2395 struct scsi_unmap_parm_list
*plist
;
2396 struct nvme_dsm_range
*range
;
2397 struct nvme_command c
;
2398 int i
, nvme_sc
, res
;
2399 u16 ndesc
, list_len
;
2401 list_len
= get_unaligned_be16(&cmd
[7]);
2405 plist
= kmalloc(list_len
, GFP_KERNEL
);
2409 res
= nvme_trans_copy_from_user(hdr
, plist
, list_len
);
2413 ndesc
= be16_to_cpu(plist
->unmap_blk_desc_data_len
) >> 4;
2414 if (!ndesc
|| ndesc
> 256) {
2419 range
= kcalloc(ndesc
, sizeof(*range
), GFP_KERNEL
);
2425 for (i
= 0; i
< ndesc
; i
++) {
2426 range
[i
].nlb
= cpu_to_le32(be32_to_cpu(plist
->desc
[i
].nlb
));
2427 range
[i
].slba
= cpu_to_le64(be64_to_cpu(plist
->desc
[i
].slba
));
2431 memset(&c
, 0, sizeof(c
));
2432 c
.dsm
.opcode
= nvme_cmd_dsm
;
2433 c
.dsm
.nsid
= cpu_to_le32(ns
->ns_id
);
2434 c
.dsm
.nr
= cpu_to_le32(ndesc
- 1);
2435 c
.dsm
.attributes
= cpu_to_le32(NVME_DSMGMT_AD
);
2437 nvme_sc
= nvme_submit_sync_cmd(ns
->queue
, &c
, range
,
2438 ndesc
* sizeof(*range
));
2439 res
= nvme_trans_status_code(hdr
, nvme_sc
);
2447 static int nvme_scsi_translate(struct nvme_ns
*ns
, struct sg_io_hdr
*hdr
)
2449 u8 cmd
[BLK_MAX_CDB
];
2451 unsigned int opcode
;
2453 if (hdr
->cmdp
== NULL
)
2455 if (copy_from_user(cmd
, hdr
->cmdp
, hdr
->cmd_len
))
2459 * Prime the hdr with good status for scsi commands that don't require
2460 * an nvme command for translation.
2462 retcode
= nvme_trans_status_code(hdr
, NVME_SC_SUCCESS
);
2473 retcode
= nvme_trans_io(ns
, hdr
, 0, cmd
);
2479 retcode
= nvme_trans_io(ns
, hdr
, 1, cmd
);
2482 retcode
= nvme_trans_inquiry(ns
, hdr
, cmd
);
2485 retcode
= nvme_trans_log_sense(ns
, hdr
, cmd
);
2488 case MODE_SELECT_10
:
2489 retcode
= nvme_trans_mode_select(ns
, hdr
, cmd
);
2493 retcode
= nvme_trans_mode_sense(ns
, hdr
, cmd
);
2496 retcode
= nvme_trans_read_capacity(ns
, hdr
, cmd
, 0);
2498 case SERVICE_ACTION_IN_16
:
2500 case SAI_READ_CAPACITY_16
:
2501 retcode
= nvme_trans_read_capacity(ns
, hdr
, cmd
, 1);
2508 retcode
= nvme_trans_report_luns(ns
, hdr
, cmd
);
2511 retcode
= nvme_trans_request_sense(ns
, hdr
, cmd
);
2513 case SECURITY_PROTOCOL_IN
:
2514 case SECURITY_PROTOCOL_OUT
:
2515 retcode
= nvme_trans_security_protocol(ns
, hdr
, cmd
);
2518 retcode
= nvme_trans_start_stop(ns
, hdr
, cmd
);
2520 case SYNCHRONIZE_CACHE
:
2521 retcode
= nvme_trans_synchronize_cache(ns
, hdr
);
2524 retcode
= nvme_trans_format_unit(ns
, hdr
, cmd
);
2526 case TEST_UNIT_READY
:
2527 retcode
= nvme_trans_test_unit_ready(ns
, hdr
, cmd
);
2530 retcode
= nvme_trans_write_buffer(ns
, hdr
, cmd
);
2533 retcode
= nvme_trans_unmap(ns
, hdr
, cmd
);
2537 retcode
= nvme_trans_completion(hdr
, SAM_STAT_CHECK_CONDITION
,
2538 ILLEGAL_REQUEST
, SCSI_ASC_ILLEGAL_COMMAND
,
2539 SCSI_ASCQ_CAUSE_NOT_REPORTABLE
);
2545 int nvme_sg_io(struct nvme_ns
*ns
, struct sg_io_hdr __user
*u_hdr
)
2547 struct sg_io_hdr hdr
;
2550 if (!capable(CAP_SYS_ADMIN
))
2552 if (copy_from_user(&hdr
, u_hdr
, sizeof(hdr
)))
2554 if (hdr
.interface_id
!= 'S')
2556 if (hdr
.cmd_len
> BLK_MAX_CDB
)
2560 * A positive return code means a NVMe status, which has been
2561 * translated to sense data.
2563 retcode
= nvme_scsi_translate(ns
, &hdr
);
2566 if (copy_to_user(u_hdr
, &hdr
, sizeof(sg_io_hdr_t
)) > 0)
2571 int nvme_sg_get_version_num(int __user
*ip
)
2573 return put_user(sg_version_num
, ip
);