Lorenz Brun | fba5da0 | 2022-12-15 11:20:47 +0000 | [diff] [blame] | 1 | package nvme |
| 2 | |
| 3 | // SecureEraseType specifices what type of secure erase should be performed by |
| 4 | // by the controller. The zero value requests no secure erase. |
| 5 | type SecureEraseType uint8 |
| 6 | |
| 7 | const ( |
| 8 | // SecureEraseTypeNone specifies that no secure erase operation is |
| 9 | // requested. |
| 10 | SecureEraseTypeNone SecureEraseType = 0 |
| 11 | // SecureEraseTypeUserData specifies that all user data should be securely |
| 12 | // erased. The controller is allowed to perform a cryptographic erase |
| 13 | // instead. |
| 14 | SecureEraseTypeUserData SecureEraseType = 1 |
| 15 | // SecureEraseTypeCryptographic specifies that the encryption key for user |
| 16 | // data should be erased. This in turn causes all current user data to |
| 17 | // become unreadable. |
| 18 | SecureEraseTypeCryptographic SecureEraseType = 2 |
| 19 | ) |
| 20 | |
| 21 | // ProtectionInformationType selects the type of end-to-end protection tags to |
| 22 | // use. NVMe supports the same types as T10 DIF (SCSI). |
| 23 | type ProtectionInformationType uint8 |
| 24 | |
| 25 | const ( |
| 26 | ProtectionInformationTypeNone ProtectionInformationType = 0 |
| 27 | ProtectionInformationType1 ProtectionInformationType = 1 |
| 28 | ProtectionInformationType2 ProtectionInformationType = 2 |
| 29 | ProtectionInformationType3 ProtectionInformationType = 3 |
| 30 | ) |
| 31 | |
| 32 | type FormatRequest struct { |
| 33 | // NamespaceID contains the ID of the namespace to format. |
| 34 | // NamespaceGlobal formats all namespaces. |
| 35 | NamespaceID uint32 |
| 36 | // SecureEraseSettings specifies the type of secure erase to perform. |
| 37 | SecureEraseSettings SecureEraseType |
| 38 | // ProtectionInformationLocation selects where protection information is |
| 39 | // transmitted. If true, it is transmitted as the first 8 bytes of metadata. |
| 40 | // If false, it is transmitted as the last 8 bytes of metadata. |
| 41 | ProtectionInformationLocation bool |
| 42 | // ProtectionInformation specifies the type of T10 DIF Protection |
| 43 | // Information to use. |
| 44 | ProtectionInformation ProtectionInformationType |
| 45 | // MetadataInline selects whether metadata is transferred as part of an |
| 46 | // extended data LBA. If false, metadata is returned in a separate buffer. |
| 47 | // If true, metadata is appended to the data buffer. |
| 48 | MetadataInline bool |
| 49 | // LBAFormat specifies the LBA format to use. This needs to be selected |
| 50 | // from the list of supported LBA formats in the Identify response. |
| 51 | LBAFormat uint8 |
| 52 | } |
| 53 | |
| 54 | // Format performs a low-level format of the NVM media. This is used for |
| 55 | // changing the block and/or metadata size. This command causes all data |
| 56 | // on the specified namespace to be lost. By setting SecureEraseSettings |
| 57 | // to the appropriate value it can also be used to securely erase data. |
| 58 | // See also the Sanitize command for just wiping the device. |
| 59 | func (d *Device) Format(req *FormatRequest) error { |
| 60 | var cdw10 uint32 |
| 61 | cdw10 |= uint32(req.SecureEraseSettings&0x7) << 9 |
| 62 | cdw10 |= uint32(req.ProtectionInformation&0x7) << 5 |
| 63 | cdw10 |= uint32(req.LBAFormat & 0x7) |
| 64 | if req.ProtectionInformationLocation { |
| 65 | cdw10 |= 1 << 8 |
| 66 | } |
| 67 | if req.MetadataInline { |
| 68 | cdw10 |= 1 << 4 |
| 69 | } |
| 70 | return d.RawCommand(&Command{ |
| 71 | Opcode: 0x80, |
| 72 | NamespaceID: req.NamespaceID, |
| 73 | CDW10: cdw10, |
| 74 | }) |
| 75 | } |