| 1 | /* |
| 2 | * S/390 DIAGNOSE 320 definitions and structures |
| 3 | * |
| 4 | * Copyright 2025 IBM Corp. |
| 5 | * Author(s): Zhuoying Cai <zycai@linux.ibm.com> |
| 6 | * |
| 7 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 8 | */ |
| 9 | |
| 10 | #ifndef S390X_DIAG320_H |
| 11 | #define S390X_DIAG320_H |
| 12 | |
| 13 | #define DIAG_320_SUBC_QUERY_ISM 0 |
| 14 | #define DIAG_320_SUBC_QUERY_VCSI 1 |
| 15 | #define DIAG_320_SUBC_STORE_VC 2 |
| 16 | |
| 17 | #define DIAG_320_RC_OK 0x0001 |
| 18 | #define DIAG_320_RC_NOT_SUPPORTED 0x0102 |
| 19 | #define DIAG_320_RC_INVAL_VCSSB_LEN 0x0202 |
| 20 | #define DIAG_320_RC_INVAL_VCB_LEN 0x0204 |
| 21 | #define DIAG_320_RC_BAD_RANGE 0x0302 |
| 22 | |
| 23 | #define DIAG_320_ISM_QUERY_SUBCODES 0x80000000 |
| 24 | #define DIAG_320_ISM_QUERY_VCSI 0x40000000 |
| 25 | #define DIAG_320_ISM_STORE_VC 0x20000000 |
| 26 | |
| 27 | #define VCSSB_NO_VC 4 |
| 28 | #define VCSSB_LEN_VALID 128 |
| 29 | |
| 30 | #define CERT_NAME_MAX_LEN 64 |
| 31 | |
| 32 | /* |
| 33 | * If the VCE flags indicate an invalid certificate, |
| 34 | * the VCE length is set to 72, containing only the |
| 35 | * first five fields of VCEntry. |
| 36 | */ |
| 37 | #define VCE_INVALID_LEN 72 |
| 38 | |
| 39 | #define DIAG_320_VCE_FLAGS_VALID 0x80 |
| 40 | |
| 41 | typedef enum Diag320VceKeyType { |
| 42 | DIAG_320_VCE_KEYTYPE_SELF_DESCRIBING = 0, |
| 43 | DIAG_320_VCE_KEYTYPE_ECDSA_P521 = 1, |
| 44 | } Diag320VceKeyType; |
| 45 | |
| 46 | typedef enum Diag320VceFormat { |
| 47 | DIAG_320_VCE_FORMAT_X509_DER = 1, |
| 48 | } Diag320VceFormat; |
| 49 | |
| 50 | typedef enum Diag320VceHashType { |
| 51 | DIAG_320_VCE_HASHTYPE_SHA2_256 = 1, |
| 52 | } Diag320VceHashType; |
| 53 | |
| 54 | struct VCStorageSizeBlock { |
| 55 | uint32_t length; |
| 56 | uint8_t reserved0[3]; |
| 57 | uint8_t version; |
| 58 | uint32_t reserved1[6]; |
| 59 | uint16_t total_vc_ct; |
| 60 | uint16_t max_vc_ct; |
| 61 | uint32_t reserved3[11]; |
| 62 | uint32_t max_single_vcb_len; |
| 63 | uint32_t total_vcb_len; |
| 64 | uint32_t reserved4[10]; |
| 65 | }; |
| 66 | typedef struct VCStorageSizeBlock VCStorageSizeBlock; |
| 67 | |
| 68 | struct VCEntryHeader { |
| 69 | uint32_t len; |
| 70 | uint8_t flags; |
| 71 | uint8_t key_type; |
| 72 | uint16_t cert_idx; |
| 73 | uint8_t name[CERT_NAME_MAX_LEN]; |
| 74 | uint8_t format; |
| 75 | uint8_t reserved0; |
| 76 | uint16_t keyid_len; |
| 77 | uint8_t reserved1; |
| 78 | uint8_t hash_type; |
| 79 | uint16_t hash_len; |
| 80 | uint32_t reserved2; |
| 81 | uint32_t cert_len; |
| 82 | uint32_t reserved3[2]; |
| 83 | uint16_t hash_offset; |
| 84 | uint16_t cert_offset; |
| 85 | uint32_t reserved4[7]; |
| 86 | }; |
| 87 | typedef struct VCEntryHeader VCEntryHeader; |
| 88 | |
| 89 | struct VCEntry { |
| 90 | VCEntryHeader vce_hdr; |
| 91 | uint8_t cert_buf[]; |
| 92 | }; |
| 93 | typedef struct VCEntry VCEntry; |
| 94 | |
| 95 | #define MAX_VCENTRY_SIZE (8 * 1024) |
| 96 | #define CERT_BUF_MAX_LEN (MAX_VCENTRY_SIZE - sizeof(VCEntryHeader)) |
| 97 | |
| 98 | struct VCBlockHeader { |
| 99 | uint32_t in_len; |
| 100 | uint32_t reserved0; |
| 101 | uint16_t first_vc_index; |
| 102 | uint16_t last_vc_index; |
| 103 | uint32_t reserved1[5]; |
| 104 | uint32_t out_len; |
| 105 | uint8_t reserved2[4]; |
| 106 | uint16_t stored_ct; |
| 107 | uint16_t remain_ct; |
| 108 | uint32_t reserved3[5]; |
| 109 | }; |
| 110 | typedef struct VCBlockHeader VCBlockHeader; |
| 111 | |
| 112 | struct VCBlock { |
| 113 | VCBlockHeader vcb_hdr; |
| 114 | uint8_t vce_buf[]; |
| 115 | }; |
| 116 | typedef struct VCBlock VCBlock; |
| 117 | |
| 118 | #endif |