|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 | + |
| 3 | +#include <inttypes.h> |
| 4 | + |
| 5 | +#define FMT_RED "\x1b[31m" |
| 6 | +#define FMT_GREEN "\x1b[32m" |
| 7 | +#define FMT_YELLOW "\x1b[33m" |
| 8 | +#define FMT_BLUE "\x1b[34m" |
| 9 | +#define FMT_RESET "\x1b[0m" |
| 10 | + |
| 11 | + |
| 12 | +enum { |
| 13 | + SFX_LOG_LATENCY_READ_STATS = 0xc1, |
| 14 | + SFX_LOG_EXTENDED_HEALTH = 0xc2, |
| 15 | + SFX_LOG_LATENCY_WRITE_STATS = 0xc3, |
| 16 | + SFX_LOG_QUAL = 0xc4, |
| 17 | + SFX_LOG_MISMATCHLBA = 0xc5, |
| 18 | + SFX_LOG_MEDIA = 0xc6, |
| 19 | + SFX_LOG_BBT = 0xc7, |
| 20 | + SFX_LOG_IDENTIFY = 0xcc, |
| 21 | + SFX_FEAT_ATOMIC = 0x01, |
| 22 | + SFX_FEAT_UP_P_CAP = 0xac, |
| 23 | + SFX_LOG_EXTENDED_HEALTH_ALT = 0xd2, |
| 24 | + SFX_FEAT_CLR_CARD = 0xdc, |
| 25 | +}; |
| 26 | + |
| 27 | +enum { |
| 28 | + SFX_CRIT_PWR_FAIL_DATA_LOSS = 0x01, |
| 29 | + SFX_CRIT_OVER_CAP = 0x02, |
| 30 | + SFX_CRIT_RW_LOCK = 0x04, |
| 31 | +}; |
| 32 | + |
| 33 | +enum sfx_nvme_admin_opcode { |
| 34 | + nvme_admin_query_cap_info = 0xd3, |
| 35 | + nvme_admin_change_cap = 0xd4, |
| 36 | + nvme_admin_sfx_set_features = 0xd5, |
| 37 | + nvme_admin_sfx_get_features = 0xd6, |
| 38 | +}; |
| 39 | + |
| 40 | +struct sfx_freespace_ctx { |
| 41 | + __u64 free_space; |
| 42 | + __u64 phy_cap; /* physical capacity, in unit of sector */ |
| 43 | + __u64 phy_space; /* physical space considering OP, in unit of sector */ |
| 44 | + __u64 user_space; /* user required space, in unit of sector*/ |
| 45 | + __u64 hw_used; /* hw space used in 4K */ |
| 46 | + __u64 app_written; /* app data written in 4K */ |
| 47 | + __u64 out_of_space; |
| 48 | + __u64 map_unit; |
| 49 | + __u64 max_user_space; |
| 50 | + __u64 extendible_user_cap_lba_count; |
| 51 | + __u64 friendly_change_cap_support; |
| 52 | +}; |
| 53 | + |
| 54 | +struct nvme_capacity_info { |
| 55 | + __u64 lba_sec_sz; |
| 56 | + __u64 phy_sec_sz; |
| 57 | + __u64 used_space; |
| 58 | + __u64 free_space; |
| 59 | +}; |
| 60 | + |
| 61 | +struct __packed nvme_additional_smart_log_item { |
| 62 | + __u8 key; |
| 63 | + __u8 _kp[2]; |
| 64 | + __u8 norm; |
| 65 | + __u8 _np; |
| 66 | + union __packed { |
| 67 | + __u8 raw[6]; |
| 68 | + struct __packed wear_level { |
| 69 | + __le16 min; |
| 70 | + __le16 max; |
| 71 | + __le16 avg; |
| 72 | + } wear_level; |
| 73 | + struct __packed thermal_throttle { |
| 74 | + __u8 pct; |
| 75 | + __u32 count; |
| 76 | + } thermal_throttle; |
| 77 | + }; |
| 78 | + __u8 _rp; |
| 79 | +}; |
| 80 | + |
| 81 | +struct __packed sfx_lat_stats_vanda { |
| 82 | + __u16 maj; |
| 83 | + __u16 min; |
| 84 | + __u32 bucket_1[32]; /* 0~1ms, step 32us */ |
| 85 | + __u32 bucket_2[31]; /* 1~32ms, step 1ms */ |
| 86 | + __u32 bucket_3[31]; /* 32ms~1s, step 32ms */ |
| 87 | + __u32 bucket_4[1]; /* 1s~2s, specifically 1024ms~2047ms */ |
| 88 | + __u32 bucket_5[1]; /* 2s~4s, specifically 2048ms~4095ms */ |
| 89 | + __u32 bucket_6[1]; /* 4s+, specifically 4096ms+ */ |
| 90 | +}; |
| 91 | + |
| 92 | +struct __packed sfx_lat_stats_myrtle { |
| 93 | + __u16 maj; |
| 94 | + __u16 min; |
| 95 | + __u32 bucket_1[64]; /* 0us~63us, step 1us */ |
| 96 | + __u32 bucket_2[64]; /* 63us~127us, step 1us */ |
| 97 | + __u32 bucket_3[64]; /* 127us~255us, step 2us */ |
| 98 | + __u32 bucket_4[64]; /* 255us~510us, step 4us */ |
| 99 | + __u32 bucket_5[64]; /* 510us~1.02ms step 8us */ |
| 100 | + __u32 bucket_6[64]; /* 1.02ms~2.04ms step 16us */ |
| 101 | + __u32 bucket_7[64]; /* 2.04ms~4.08ms step 32us */ |
| 102 | + __u32 bucket_8[64]; /* 4.08ms~8.16ms step 64us */ |
| 103 | + __u32 bucket_9[64]; /* 8.16ms~16.32ms step 128us */ |
| 104 | + __u32 bucket_10[64]; /* 16.32ms~32.64ms step 256us */ |
| 105 | + __u32 bucket_11[64]; /* 32.64ms~65.28ms step 512us */ |
| 106 | + __u32 bucket_12[64]; /* 65.28ms~130.56ms step 1.024ms */ |
| 107 | + __u32 bucket_13[64]; /* 130.56ms~261.12ms step 2.048ms */ |
| 108 | + __u32 bucket_14[64]; /* 261.12ms~522.24ms step 4.096ms */ |
| 109 | + __u32 bucket_15[64]; /* 522.24ms~1.04s step 8.192ms */ |
| 110 | + __u32 bucket_16[64]; /* 1.04s~2.09s step 16.384ms */ |
| 111 | + __u32 bucket_17[64]; /* 2.09s~4.18s step 32.768ms */ |
| 112 | + __u32 bucket_18[64]; /* 4.18s~8.36s step 65.536ms */ |
| 113 | + __u32 bucket_19[64]; /* 8.36s~ step 131.072ms */ |
| 114 | + __u64 average; /* average latency statistics */ |
| 115 | +}; |
| 116 | + |
| 117 | + |
| 118 | +struct __packed sfx_lat_status_ver { |
| 119 | + __u16 maj; |
| 120 | + __u16 min; |
| 121 | +}; |
| 122 | + |
| 123 | +struct sfx_lat_stats { |
| 124 | + union { |
| 125 | + struct sfx_lat_status_ver ver; |
| 126 | + struct sfx_lat_stats_vanda vanda; |
| 127 | + struct sfx_lat_stats_myrtle myrtle; |
| 128 | + }; |
| 129 | +}; |
| 130 | + |
| 131 | +struct nvme_additional_smart_log { |
| 132 | + struct nvme_additional_smart_log_item program_fail_cnt; |
| 133 | + struct nvme_additional_smart_log_item erase_fail_cnt; |
| 134 | + struct nvme_additional_smart_log_item wear_leveling_cnt; |
| 135 | + struct nvme_additional_smart_log_item e2e_err_cnt; |
| 136 | + struct nvme_additional_smart_log_item crc_err_cnt; |
| 137 | + struct nvme_additional_smart_log_item timed_workload_media_wear; |
| 138 | + struct nvme_additional_smart_log_item timed_workload_host_reads; |
| 139 | + struct nvme_additional_smart_log_item timed_workload_timer; |
| 140 | + struct nvme_additional_smart_log_item thermal_throttle_status; |
| 141 | + struct nvme_additional_smart_log_item retry_buffer_overflow_cnt; |
| 142 | + struct nvme_additional_smart_log_item pll_lock_loss_cnt; |
| 143 | + struct nvme_additional_smart_log_item nand_bytes_written; |
| 144 | + struct nvme_additional_smart_log_item host_bytes_written; |
| 145 | + struct nvme_additional_smart_log_item raid_recover_cnt; |
| 146 | + /* errors which can be recovered by RAID */ |
| 147 | + struct nvme_additional_smart_log_item prog_timeout_cnt; |
| 148 | + struct nvme_additional_smart_log_item erase_timeout_cnt; |
| 149 | + struct nvme_additional_smart_log_item read_timeout_cnt; |
| 150 | + struct nvme_additional_smart_log_item read_ecc_cnt; /* retry cnt */ |
| 151 | + struct nvme_additional_smart_log_item non_media_crc_err_cnt; |
| 152 | + struct nvme_additional_smart_log_item compression_path_err_cnt; |
| 153 | + struct nvme_additional_smart_log_item out_of_space_flag; |
| 154 | + struct nvme_additional_smart_log_item physical_usage_ratio; |
| 155 | + struct nvme_additional_smart_log_item grown_bb; /* grown bad block */ |
| 156 | +}; |
| 157 | + |
| 158 | + |
| 159 | +struct __packed extended_health_info_myrtle { |
| 160 | + __u32 soft_read_recoverable_errs; |
| 161 | + __u32 flash_die_raid_recoverable_errs; |
| 162 | + __u32 pcie_rx_correct_errs; |
| 163 | + __u32 pcie_rx_uncorrect_errs; |
| 164 | + __u32 data_read_from_flash; |
| 165 | + __u32 data_write_to_flash; |
| 166 | + __u32 temp_throttle_info;// bit0: 0--> normal, 1 --> throttled |
| 167 | + // bit 31:1 --> throttle events count, resets on power cycle |
| 168 | + __u32 power_consumption; |
| 169 | + __u32 pf_bbd_read_cnt; |
| 170 | + __u32 sfx_critical_warning; |
| 171 | + __u32 raid_recovery_total_count; |
| 172 | + __u32 rsvd; |
| 173 | + __u8 opn[32]; |
| 174 | + __u64 total_physical_capability; |
| 175 | + __u64 free_physical_capability; |
| 176 | + __u32 physical_usage_ratio; |
| 177 | + __u32 comp_ratio; |
| 178 | + __u32 otp_rsa_en; |
| 179 | + __u32 power_mw_consumption; |
| 180 | + __u32 io_speed; |
| 181 | + __u64 max_formatted_capability; |
| 182 | + __u32 map_unit; |
| 183 | + __u64 extendible_cap_lbacount; |
| 184 | + __u32 friendly_changecap_support; |
| 185 | + __u32 rvd1; |
| 186 | + __u64 cur_formatted_capability; |
| 187 | +}; |
| 188 | + |
| 189 | + |
0 commit comments