aboutsummaryrefslogtreecommitdiff
path: root/inhex/nvme_write_ctl.hex
blob: 9e6c1123940b3b4e98ab4fdf2058d1aff5b5a1d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# 64 byte NVMe, Write command (a NVM command) that is suitable for:
#       sg_raw --cmdfile=<this_file_name> --nvm --request=2048 <nvme_device>
#
# The address field (at byte offset 24, 8 bytes and little endian) gives
# special meaning to the highest address pointers:
#    ffffffff fffffffe         use address of data-in buffer
#    ffffffff fffffffd         use address of data-out buffer
#
# The data length field (at byte offset 36, 4 bytes and little endian)
# gives special meaning to the highest block counts:
#    fffffffe                  use byte length of data-in buffer
#    fffffffd                  use byte length of data-out buffer
#
# 512 byte logical block size is assumed. Write 4 blocks hence 2048 bytes.
# The first LBA written is 0x12345 and the namespace is 1. If successful the
# four blocks will be written out of the data-out buffer. Submission queue 
# is used (the same queue that Admin commands use). The NVM opcode for the
# Write command is 0x1 and appears in the first command byte.

01 00 00 00 01 00 00 00  00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00  fd ff ff ff ff ff ff ff
00 00 00 00 fd ff ff ff  45 23 01 00 00 00 00 00
03 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00

# Notice NVMe uses its quirky "0's based" number of blocks so
# 03 appears at byte offset 48 to mean "write 4 blocks".
#
# A typical invocation in Linux and FreeBSD would look like this:
#    sg_raw --cmdfile=nvme_write_ctl.hex --nvm -s 2048
#           --infile=t.bin /dev/nvme0
#
# Notice the '--nvm' option which is needed to distinguish a NVM
# command from an Admin command as Admin commands are the default
# in this utility.
#
# This utility (and most others in the package) aligns data-in and
# data-out buffers to the beginning of pages which are 4096 bytes
# long at a minimum. This is the way NVMe likes things as well.