|
| 1 | +// This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | +// License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 | +// file, You can obtain one at https://mozilla.org/MPL/2.0/ |
| 4 | +// |
| 5 | +// Copyright 2026 Oxide Computer Company |
| 6 | + |
| 7 | +//! Fuse data types for Tofino ASICs. |
| 8 | +//! |
| 9 | +//! Chip revision info is exposed in oximeter metrics via the `asic_lot` field |
| 10 | +//! (e.g., "FL1234-B1"). |
| 11 | +//! |
| 12 | +//! TODO: Add a dedicated `asic_chip_rev` field to oximeter timeseries when |
| 13 | +//! reconfigurator supports oximeter schema migration. Currently there is no |
| 14 | +//! window during online updates where all switches stop producing data, so the |
| 15 | +//! old schema cannot be safely updated. |
| 16 | +
|
| 17 | +use schemars::JsonSchema; |
| 18 | +use serde::Serialize; |
| 19 | + |
| 20 | +/// Chip revision derived from device_id and rev_num fuse fields. |
| 21 | +#[derive(Clone, Debug, JsonSchema, Serialize)] |
| 22 | +pub struct ChipRevision { |
| 23 | + /// Computed revision string (e.g., "A0", "B0", "B1"). |
| 24 | + pub rev: String, |
| 25 | + /// Raw device ID from fuse. |
| 26 | + pub device_id: u16, |
| 27 | + /// Raw revision number from fuse. |
| 28 | + pub rev_num: u8, |
| 29 | +} |
| 30 | + |
| 31 | +impl ChipRevision { |
| 32 | + /// Compute chip revision from device_id and rev_num. |
| 33 | + pub fn from_fuse(device_id: u16, rev_num: u8) -> Self { |
| 34 | + let rev = match device_id { |
| 35 | + 0x0100 => "A0".to_string(), |
| 36 | + 0x0110 => match rev_num { |
| 37 | + 0 => "B0".to_string(), |
| 38 | + 2 => "B1".to_string(), |
| 39 | + _ => format!("{:04x}", device_id), |
| 40 | + }, |
| 41 | + _ => format!("{:04x}", device_id), |
| 42 | + }; |
| 43 | + Self { rev, device_id, rev_num } |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +/// Part identification from fuse data. |
| 48 | +#[derive(Clone, Debug, JsonSchema, Serialize)] |
| 49 | +pub struct PartInfo { |
| 50 | + /// Part number (13 bits). |
| 51 | + pub part_num: u16, |
| 52 | + /// Package ID (2 bits). |
| 53 | + pub pkg_id: u8, |
| 54 | + /// Fuse version (2 bits). |
| 55 | + pub version: u8, |
| 56 | +} |
| 57 | + |
| 58 | +/// Features disabled via fuse programming. |
| 59 | +#[derive(Clone, Debug, JsonSchema, Serialize)] |
| 60 | +pub struct DisabledFeatures { |
| 61 | + /// Disabled pipes (4-bit bitmap). |
| 62 | + pub pipes: u8, |
| 63 | + /// Disabled ports (40-bit bitmap). |
| 64 | + pub ports: u64, |
| 65 | + /// Disabled speeds (64-bit bitmap). |
| 66 | + pub speeds: u64, |
| 67 | + /// Disabled MAUs per pipe (21 bits each). |
| 68 | + pub mau: [u32; 4], |
| 69 | + /// Disabled traffic manager memory (32-bit bitmap). |
| 70 | + pub tm_mem: u32, |
| 71 | + /// Buffer sync disabled. |
| 72 | + pub bsync: bool, |
| 73 | + /// Packet generator disabled. |
| 74 | + pub pgen: bool, |
| 75 | + /// Resubmit disabled. |
| 76 | + pub resub: bool, |
| 77 | +} |
| 78 | + |
| 79 | +/// Frequency settings from fuse data. |
| 80 | +#[derive(Clone, Debug, JsonSchema, Serialize)] |
| 81 | +pub struct FrequencySettings { |
| 82 | + /// Frequency disabled. |
| 83 | + pub disabled: bool, |
| 84 | + /// Backplane port speed frequency (2 bits). |
| 85 | + pub bps: u8, |
| 86 | + /// Packet processing speed frequency (2 bits). |
| 87 | + pub pps: u8, |
| 88 | + /// Extended backplane frequency (4 bits). |
| 89 | + pub bps_ext: u8, |
| 90 | + /// Extended packet speed frequency (4 bits). |
| 91 | + pub pps_ext: u8, |
| 92 | + /// PCIe disabled (2 bits). |
| 93 | + pub pcie_dis: u8, |
| 94 | + /// CPU speed disabled (2 bits). |
| 95 | + pub cpu_speed_dis: u8, |
| 96 | +} |
| 97 | + |
| 98 | +/// Manufacturing and repair data from fuse. |
| 99 | +#[derive(Clone, Debug, JsonSchema, Serialize)] |
| 100 | +pub struct ManufacturingData { |
| 101 | + /// Voltage scaling value (12 bits). |
| 102 | + pub voltage_scaling: u16, |
| 103 | + /// PMRO and skew value (12 bits). |
| 104 | + pub pmro_and_skew: u16, |
| 105 | + /// Die rotation. |
| 106 | + pub die_rotation: bool, |
| 107 | + /// Silent spin (2 bits). |
| 108 | + pub silent_spin: u8, |
| 109 | + /// Wafer core repair applied. |
| 110 | + pub wf_core_repair: bool, |
| 111 | + /// Core repair applied. |
| 112 | + pub core_repair: bool, |
| 113 | + /// Tile repair applied. |
| 114 | + pub tile_repair: bool, |
| 115 | + /// Soft pipe disable (4 bits). |
| 116 | + pub soft_pipe_dis: u8, |
| 117 | +} |
| 118 | + |
| 119 | +/// Organized fuse data from the Tofino ASIC. |
| 120 | +#[derive(Clone, Debug, JsonSchema, Serialize)] |
| 121 | +pub struct FuseData { |
| 122 | + /// Chip revision information. |
| 123 | + pub chip_rev: ChipRevision, |
| 124 | + /// Part identification. |
| 125 | + pub part: PartInfo, |
| 126 | + /// Disabled features. |
| 127 | + pub disabled: DisabledFeatures, |
| 128 | + /// Frequency settings. |
| 129 | + pub frequency: FrequencySettings, |
| 130 | + /// Manufacturing and repair data. |
| 131 | + pub manufacturing: ManufacturingData, |
| 132 | +} |
| 133 | + |
| 134 | +#[cfg(test)] |
| 135 | +mod tests { |
| 136 | + use super::*; |
| 137 | + |
| 138 | + #[test] |
| 139 | + fn chip_revision_a0() { |
| 140 | + let rev = ChipRevision::from_fuse(0x0100, 0); |
| 141 | + assert_eq!(rev.rev, "A0"); |
| 142 | + assert_eq!(rev.device_id, 0x0100); |
| 143 | + assert_eq!(rev.rev_num, 0); |
| 144 | + } |
| 145 | + |
| 146 | + #[test] |
| 147 | + fn chip_revision_b0() { |
| 148 | + let rev = ChipRevision::from_fuse(0x0110, 0); |
| 149 | + assert_eq!(rev.rev, "B0"); |
| 150 | + assert_eq!(rev.device_id, 0x0110); |
| 151 | + assert_eq!(rev.rev_num, 0); |
| 152 | + } |
| 153 | + |
| 154 | + #[test] |
| 155 | + fn chip_revision_b1() { |
| 156 | + let rev = ChipRevision::from_fuse(0x0110, 2); |
| 157 | + assert_eq!(rev.rev, "B1"); |
| 158 | + assert_eq!(rev.device_id, 0x0110); |
| 159 | + assert_eq!(rev.rev_num, 2); |
| 160 | + } |
| 161 | + |
| 162 | + #[test] |
| 163 | + fn chip_revision_unknown_rev_num() { |
| 164 | + let rev = ChipRevision::from_fuse(0x0110, 5); |
| 165 | + assert_eq!(rev.rev, "0110"); |
| 166 | + assert_eq!(rev.device_id, 0x0110); |
| 167 | + assert_eq!(rev.rev_num, 5); |
| 168 | + } |
| 169 | + |
| 170 | + #[test] |
| 171 | + fn chip_revision_unknown_device_id() { |
| 172 | + let rev = ChipRevision::from_fuse(0x0200, 0); |
| 173 | + assert_eq!(rev.rev, "0200"); |
| 174 | + assert_eq!(rev.device_id, 0x0200); |
| 175 | + assert_eq!(rev.rev_num, 0); |
| 176 | + } |
| 177 | +} |
0 commit comments