1 #ifndef SG_VPD_H 2 #define SG_VPD_H 3 4 /* 5 * Copyright (c) 2022 Douglas Gilbert. 6 * All rights reserved. 7 * Use of this source code is governed by a BSD-style 8 * license that can be found in the BSD_LICENSE file. 9 * 10 * SPDX-License-Identifier: BSD-2-Clause 11 */ 12 13 /* This is a common header file for the sg_inq and sg_vpd utilities */ 14 15 #include <stdint.h> 16 #include <stdbool.h> 17 18 #ifdef HAVE_CONFIG_H 19 #include "config.h" 20 #endif 21 22 #include "sg_lib.h" 23 #include "sg_pr2serr.h" 24 25 #ifdef __cplusplus 26 extern "C" { 27 #endif 28 29 /* standard VPD pages, in ascending page number order */ 30 #define VPD_SUPPORTED_VPDS 0x0 31 #define VPD_UNIT_SERIAL_NUM 0x80 32 #define VPD_IMP_OP_DEF 0x81 /* obsolete in SPC-2 */ 33 #define VPD_ASCII_OP_DEF 0x82 /* obsolete in SPC-2 */ 34 #define VPD_DEVICE_ID 0x83 35 #define VPD_SOFTW_INF_ID 0x84 36 #define VPD_MAN_NET_ADDR 0x85 37 #define VPD_EXT_INQ 0x86 /* Extended Inquiry */ 38 #define VPD_MODE_PG_POLICY 0x87 39 #define VPD_SCSI_PORTS 0x88 40 #define VPD_ATA_INFO 0x89 41 #define VPD_POWER_CONDITION 0x8a 42 #define VPD_DEVICE_CONSTITUENTS 0x8b 43 #define VPD_CFA_PROFILE_INFO 0x8c 44 #define VPD_POWER_CONSUMPTION 0x8d 45 #define VPD_3PARTY_COPY 0x8f /* 3PC, XCOPY, SPC-5, SBC-4 */ 46 #define VPD_PROTO_LU 0x90 47 #define VPD_PROTO_PORT 0x91 48 #define VPD_SCSI_FEATURE_SETS 0x92 /* spc5r11 */ 49 #define VPD_BLOCK_LIMITS 0xb0 /* SBC-3 */ 50 #define VPD_SA_DEV_CAP 0xb0 /* SSC-3 */ 51 #define VPD_OSD_INFO 0xb0 /* OSD */ 52 #define VPD_BLOCK_DEV_CHARS 0xb1 /* SBC-3 */ 53 #define VPD_MAN_ASS_SN 0xb1 /* SSC-3, ADC-2 */ 54 #define VPD_SECURITY_TOKEN 0xb1 /* OSD */ 55 #define VPD_TA_SUPPORTED 0xb2 /* SSC-3 */ 56 #define VPD_LB_PROVISIONING 0xb2 /* SBC-3 */ 57 #define VPD_REFERRALS 0xb3 /* SBC-3 */ 58 #define VPD_AUTOMATION_DEV_SN 0xb3 /* SSC-3 */ 59 #define VPD_SUP_BLOCK_LENS 0xb4 /* sbc4r01 */ 60 #define VPD_DTDE_ADDRESS 0xb4 /* SSC-4 */ 61 #define VPD_BLOCK_DEV_C_EXTENS 0xb5 /* sbc4r02 */ 62 #define VPD_LB_PROTECTION 0xb5 /* SSC-5 */ 63 #define VPD_ZBC_DEV_CHARS 0xb6 /* zbc-r01b */ 64 #define VPD_BLOCK_LIMITS_EXT 0xb7 /* sbc4r08 */ 65 #define VPD_FORMAT_PRESETS 0xb8 /* sbc4r18 */ 66 #define VPD_CON_POS_RANGE 0xb9 /* sbc5r01 */ 67 #define VPD_NOPE_WANT_STD_INQ -2 /* request for standard inquiry */ 68 69 /* vendor/product identifiers */ 70 #define VPD_VP_SEAGATE 0 71 #define VPD_VP_RDAC 1 72 #define VPD_VP_EMC 2 73 #define VPD_VP_DDS 3 74 #define VPD_VP_HP3PAR 4 75 #define VPD_VP_IBM_LTO 5 76 #define VPD_VP_HP_LTO 6 77 #define VPD_VP_WDC_HITACHI 7 78 #define VPD_VP_NVME 8 79 #define VPD_VP_SG 9 /* this package/library as a vendor */ 80 81 82 /* vendor VPD pages */ 83 #define VPD_V_HIT_PG3 0x3 84 #define VPD_V_HP3PAR 0xc0 85 #define VPD_V_FIRM_SEA 0xc0 86 #define VPD_V_UPR_EMC 0xc0 87 #define VPD_V_HVER_RDAC 0xc0 88 #define VPD_V_FVER_DDS 0xc0 89 #define VPD_V_FVER_LTO 0xc0 90 #define VPD_V_DCRL_LTO 0xc0 91 #define VPD_V_DATC_SEA 0xc1 92 #define VPD_V_FVER_RDAC 0xc1 93 #define VPD_V_HVER_LTO 0xc1 94 #define VPD_V_DSN_LTO 0xc1 95 #define VPD_V_JUMP_SEA 0xc2 96 #define VPD_V_SVER_RDAC 0xc2 97 #define VPD_V_PCA_LTO 0xc2 98 #define VPD_V_DEV_BEH_SEA 0xc3 99 #define VPD_V_FEAT_RDAC 0xc3 100 #define VPD_V_MECH_LTO 0xc3 101 #define VPD_V_SUBS_RDAC 0xc4 102 #define VPD_V_HEAD_LTO 0xc4 103 #define VPD_V_ACI_LTO 0xc5 104 #define VPD_V_DUCD_LTO 0xc7 105 #define VPD_V_EDID_RDAC 0xc8 106 #define VPD_V_MPDS_LTO 0xc8 107 #define VPD_V_VAC_RDAC 0xc9 108 #define VPD_V_RVSI_RDAC 0xca 109 #define VPD_V_SAID_RDAC 0xd0 110 #define VPD_V_HIT_PG_D1 0xd1 111 #define VPD_V_HIT_PG_D2 0xd2 112 113 #ifndef SG_NVME_VPD_NICR 114 #define SG_NVME_VPD_NICR 0xde /* NVME Identify Controller Response */ 115 #endif 116 117 #define DEF_ALLOC_LEN 252 118 #define MX_ALLOC_LEN (0xc000 + 0x80) 119 #define DEF_PT_TIMEOUT 60 /* 60 seconds */ 120 121 enum sg_vpd_invoker_e { 122 SG_VPD_INV_NONE = 0, 123 SG_VPD_INV_SG_INQ, 124 SG_VPD_INV_SG_VPD, 125 }; 126 127 /* This structure holds the union of options available in sg_inq and sg_vpd */ 128 struct opts_t { 129 enum sg_vpd_invoker_e invoker; /* indicates if for sg_inq or sg_vpd */ 130 bool do_all; /* sg_vpd */ 131 bool do_ata; /* sg_inq */ 132 bool do_decode; /* sg_inq */ 133 bool do_descriptors; /* sg_inq */ 134 bool do_enum; /* sg_enum */ 135 bool do_export; /* sg_inq */ 136 bool do_force; /* sg_inq + sg_vpd */ 137 bool do_only; /* sg_inq: --only after stdinq: don't fetch VPD page 0x80 */ 138 bool do_quiet; /* sg_vpd */ 139 bool examine_given; /* sg_vpd */ 140 bool page_given; /* sg_inq + sg_vpd */ 141 bool possible_nvme; /* sg_inq */ 142 bool protect_not_sure; /* sg_vpd */ 143 bool verbose_given; /* sg_inq + sg_vpd */ 144 bool version_given; /* sg_inq + sg_vpd */ 145 bool do_vpd; /* sg_inq */ 146 bool std_inq_a_valid; /* sg_inq + sg_vpd */ 147 #ifdef SG_SCSI_STRINGS 148 bool opt_new; /* sg_inq */ 149 #endif 150 int do_block; /* do_block */ 151 int do_cmddt; /* sg_inq */ 152 int do_help; /* sg_inq */ 153 int do_hex; /* sg_inq + sg_vpd */ 154 int do_ident; /* sg_vpd */ 155 int do_long; /* sg_inq[int] + sg_vpd[bool] */ 156 int do_raw; /* sg_inq + sg_vpd */ 157 int do_vendor; /* sg_inq */ 158 int examine; /* sg_vpd */ 159 int maxlen; /* sg_inq[was: resp_len] + sg_vpd */ 160 int num_pages; /* sg_inq */ 161 int page_pdt; /* sg_inq */ 162 int vend_prod_num; /* sg_vpd */ 163 int verbose; /* sg_inq + sg_vpd */ 164 int vpd_pn; /* sg_vpd */ 165 const char * device_name; /* sg_inq + sg_vpd */ 166 const char * page_str; /* sg_inq + sg_vpd */ 167 const char * inhex_fn; /* sg_inq + sg_vpd */ 168 const char * sinq_inraw_fn; /* sg_inq + sg_vpd */ 169 const char * vend_prod; /* sg_vpd */ 170 sgj_state json_st; 171 uint8_t std_inq_a[36]; 172 }; 173 174 struct svpd_values_name_t { 175 int value; /* VPD page number */ 176 int subvalue; /* to differentiate if value+pdt are not unique */ 177 int pdt; /* peripheral device type id, -1 is the default */ 178 /* (all or not applicable) value */ 179 const char * acron; 180 const char * name; 181 }; 182 183 struct svpd_vp_name_t { 184 int vend_prod_num; /* vendor/product identifier */ 185 const char * acron; 186 const char * name; 187 }; 188 189 typedef int (*recurse_vpd_decodep)(struct opts_t *, sgj_opaque_p jop, int off); 190 191 192 sgj_opaque_p sg_vpd_js_hdr(sgj_state * jsp, sgj_opaque_p jop, 193 const char * name, const uint8_t * vpd_hdrp); 194 void decode_net_man_vpd(const uint8_t * buff, int len, struct opts_t * op, 195 sgj_opaque_p jap); 196 void decode_x_inq_vpd(const uint8_t * b, int len, bool protect, 197 struct opts_t * op, sgj_opaque_p jop); 198 void decode_softw_inf_id(const uint8_t * buff, int len, struct opts_t * op, 199 sgj_opaque_p jap); 200 void decode_mode_policy_vpd(const uint8_t * buff, int len, struct opts_t * op, 201 sgj_opaque_p jap); 202 void decode_cga_profile_vpd(const uint8_t * buff, int len, struct opts_t * op, 203 sgj_opaque_p jap); 204 void decode_power_condition(const uint8_t * buff, int len, struct opts_t * op, 205 sgj_opaque_p jop); 206 int filter_json_dev_ids(uint8_t * buff, int len, int m_assoc, 207 struct opts_t * op, sgj_opaque_p jap); 208 void decode_ata_info_vpd(const uint8_t * buff, int len, struct opts_t * op, 209 sgj_opaque_p jop); 210 void decode_feature_sets_vpd(const uint8_t * buff, int len, struct opts_t * op, 211 sgj_opaque_p jap); 212 void decode_dev_constit_vpd(const uint8_t * buff, int len, 213 struct opts_t * op, sgj_opaque_p jap, 214 recurse_vpd_decodep fp); 215 sgj_opaque_p std_inq_decode_js(const uint8_t * b, int len, 216 struct opts_t * op, sgj_opaque_p jop); 217 void decode_power_consumption(const uint8_t * buff, int len, 218 struct opts_t * op, sgj_opaque_p jap); 219 void decode_block_limits_vpd(const uint8_t * buff, int len, 220 struct opts_t * op, sgj_opaque_p jop); 221 void decode_block_dev_ch_vpd(const uint8_t * buff, int len, 222 struct opts_t * op, sgj_opaque_p jop); 223 int decode_block_lb_prov_vpd(const uint8_t * buff, int len, 224 struct opts_t * op, sgj_opaque_p jop); 225 void decode_referrals_vpd(const uint8_t * buff, int len, struct opts_t * op, 226 sgj_opaque_p jop); 227 void decode_sup_block_lens_vpd(const uint8_t * buff, int len, 228 struct opts_t * op, sgj_opaque_p jap); 229 void decode_block_dev_char_ext_vpd(const uint8_t * buff, int len, 230 struct opts_t * op, sgj_opaque_p jop); 231 void decode_zbdch_vpd(const uint8_t * buff, int len, struct opts_t * op, 232 sgj_opaque_p jop); 233 void decode_block_limits_ext_vpd(const uint8_t * buff, int len, 234 struct opts_t * op, sgj_opaque_p jop); 235 void decode_format_presets_vpd(const uint8_t * buff, int len, 236 struct opts_t * op, sgj_opaque_p jap); 237 void decode_con_pos_range_vpd(const uint8_t * buff, int len, 238 struct opts_t * op, sgj_opaque_p jap); 239 void decode_3party_copy_vpd(const uint8_t * buff, int len, struct opts_t * op, 240 sgj_opaque_p jap); 241 void 242 decode_proto_lu_vpd(const uint8_t * buff, int len, struct opts_t * op, 243 sgj_opaque_p jap); 244 void 245 decode_proto_port_vpd(const uint8_t * buff, int len, struct opts_t * op, 246 sgj_opaque_p jap); 247 void 248 decode_lb_protection_vpd(const uint8_t * buff, int len, struct opts_t * op, 249 sgj_opaque_p jap); 250 void 251 decode_tapealert_supported_vpd(const uint8_t * buff, int len, 252 struct opts_t * op, sgj_opaque_p jop); 253 /* Share some vendor specific VPD pages as well */ 254 void 255 decode_upr_vpd_c0_emc(uint8_t * buff, int len, struct opts_t * op, 256 sgj_opaque_p jop); 257 void 258 decode_rdac_vpd_c2(uint8_t * buff, int len, struct opts_t * op, 259 sgj_opaque_p jop); 260 void 261 decode_rdac_vpd_c9(uint8_t * buff, int len, struct opts_t * op, 262 sgj_opaque_p jop); 263 264 const char * pqual_str(int pqual); 265 int no_ascii_4hex(const struct opts_t * op); 266 267 void svpd_enumerate_vendor(int vend_prod_num); 268 int svpd_count_vendor_vpds(int vpd_pn, int vend_prod_num); 269 int svpd_decode_vendor(int sg_fd, struct opts_t * op, sgj_opaque_p jop, 270 int off); 271 const struct svpd_values_name_t * svpd_find_vendor_by_acron(const char * ap); 272 int svpd_find_vp_num_by_acron(const char * vp_ap); 273 const struct svpd_values_name_t * svpd_find_vendor_by_num(int page_num, 274 int vend_prod_num); 275 int vpd_fetch_page(int sg_fd, uint8_t * rp, int page, int mxlen, 276 bool qt, int vb, int * rlenp); 277 void dup_sanity_chk(int sz_opts_t, int sz_values_name_t); 278 279 extern uint8_t * rsp_buff; 280 extern const char * t10_vendor_id_hr; 281 extern const char * t10_vendor_id_js; 282 extern const char * product_id_hr; 283 extern const char * product_id_js; 284 extern const char * product_rev_lev_hr; 285 extern const char * product_rev_lev_js; 286 extern struct svpd_vp_name_t vp_arr[]; 287 extern struct svpd_values_name_t vendor_vpd_pg[]; 288 289 290 #ifdef __cplusplus 291 } 292 #endif 293 294 #endif /* end of SG_VPD_H */ 295