Skip to content

Commit b3cdd09

Browse files
authored
move asic-specific features into api trait (#140)
1 parent 78ecc2d commit b3cdd09

9 files changed

Lines changed: 939 additions & 736 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

asic/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ doctest = false
2121
[dependencies]
2222
aal.workspace = true
2323
common.workspace = true
24+
dpd-api.workspace = true
2425

2526
propolis = { workspace = true, optional = true , features = ["falcon"] }
2627
tofino = { workspace = true, optional = true }

asic/src/tofino_asic/serdes.rs

Lines changed: 21 additions & 179 deletions
Original file line numberDiff line numberDiff line change
@@ -10,40 +10,31 @@
1010

1111
use schemars::JsonSchema;
1212
use serde::{Deserialize, Serialize};
13-
use std::convert::{From, TryFrom};
13+
use std::convert::From;
1414

1515
use crate::tofino_asic::genpd::*;
1616
use crate::tofino_asic::ports;
1717
use crate::tofino_asic::{CheckError, Handle};
1818
use aal::{AsicError, AsicResult, PortHdl};
19-
20-
/// Signal encoding
21-
#[derive(PartialEq, Deserialize, Serialize, JsonSchema)]
22-
pub enum LaneEncoding {
23-
/// Pulse Amplitude Modulation 4-level
24-
Pam4,
25-
/// Non-Return-to-Zero encoding
26-
Nrz,
27-
/// No encoding selected
28-
None,
29-
}
30-
31-
impl TryFrom<bf_serdes_encoding_mode_t> for LaneEncoding {
32-
type Error = AsicError;
33-
34-
fn try_from(mode: bf_serdes_encoding_mode_t) -> Result<Self, AsicError> {
35-
match mode {
36-
bf_serdes_encoding_mode_t_BF_SERDES_ENC_MODE_NRZ => {
37-
Ok(LaneEncoding::Nrz)
38-
}
39-
bf_serdes_encoding_mode_t_BF_SERDES_ENC_MODE_PAM4 => {
40-
Ok(LaneEncoding::Pam4)
41-
}
42-
bf_serdes_encoding_mode_t_BF_SERDES_ENC_MODE_NONE => {
43-
Ok(LaneEncoding::None)
44-
}
45-
_ => Err(AsicError::InvalidEncodingMode(mode)),
19+
use dpd_api::{
20+
AnLtStatus, AnStatus, DfeAdaptationState, EncSpeed, LaneEncoding, LaneMap,
21+
LaneStatus, LpPages, LtStatus, RxSigInfo, SerdesEye,
22+
};
23+
24+
fn try_into_lane_encoding(
25+
mode: bf_serdes_encoding_mode_t,
26+
) -> Result<LaneEncoding, AsicError> {
27+
match mode {
28+
bf_serdes_encoding_mode_t_BF_SERDES_ENC_MODE_NRZ => {
29+
Ok(LaneEncoding::Nrz)
30+
}
31+
bf_serdes_encoding_mode_t_BF_SERDES_ENC_MODE_PAM4 => {
32+
Ok(LaneEncoding::Pam4)
33+
}
34+
bf_serdes_encoding_mode_t_BF_SERDES_ENC_MODE_NONE => {
35+
Ok(LaneEncoding::None)
4636
}
37+
_ => Err(AsicError::InvalidEncodingMode(mode)),
4738
}
4839
}
4940

@@ -53,7 +44,7 @@ fn port_encoding_mode(dev_id: i32, port_id: u16) -> AsicResult<LaneEncoding> {
5344
bf_port_encoding_mode_get(dev_id, port_id as i32, &mut enc_mode)
5445
.check_error("getting lane encoding mode")?;
5546
}
56-
LaneEncoding::try_from(enc_mode)
47+
try_into_lane_encoding(enc_mode)
5748
}
5849

5950
/// Get the number of lanes configured for this port
@@ -90,45 +81,6 @@ fn mac_channel(hdl: &Handle, port_id: u16) -> AsicResult<(u32, u32)> {
9081
Ok((mac, channel))
9182
}
9283

93-
#[derive(Deserialize, Serialize, JsonSchema)]
94-
enum Polarity {
95-
Normal,
96-
Inverted,
97-
}
98-
99-
impl From<bool> for Polarity {
100-
fn from(p: bool) -> Self {
101-
match p {
102-
true => Polarity::Inverted,
103-
false => Polarity::Normal,
104-
}
105-
}
106-
}
107-
108-
/// Mapping of the logical lanes in a link to their physical instantiation in
109-
/// the MAC/serdes interface.
110-
//
111-
// For each lane assigned to the port, this captures the mac block, the logical
112-
// lane within the mac block, the physical rx and tx lanes, and the polarity of
113-
// each. All of these values are determined by the physical layout of the
114-
// board, should be identical across all sidecars with the same board revision,
115-
// and shouldn't change from run to run.
116-
#[derive(Deserialize, Serialize, JsonSchema)]
117-
pub struct LaneMap {
118-
/// MAC block in the tofino ASIC
119-
mac_block: u32,
120-
/// logical lane within the mac block for each lane
121-
logical_lane: Vec<u32>,
122-
/// Rx logical->physical mapping
123-
rx_phys: Vec<u32>,
124-
/// Tx logical->physical mapping
125-
tx_phys: Vec<u32>,
126-
/// Rx polarity
127-
rx_polarity: Vec<Polarity>,
128-
/// Tx polarity
129-
tx_polarity: Vec<Polarity>,
130-
}
131-
13284
/// Fetch the logical->physical lane mappings for the given port.
13385
pub fn lane_map_get(hdl: &Handle, port: PortHdl) -> AsicResult<LaneMap> {
13486
let port_id = ports::to_asic_id(hdl, port)?;
@@ -191,17 +143,6 @@ pub fn lane_map_get(hdl: &Handle, port: PortHdl) -> AsicResult<LaneMap> {
191143
})
192144
}
193145

194-
/// Per-lane Rx signal information
195-
#[derive(Deserialize, Serialize, JsonSchema)]
196-
pub struct RxSigInfo {
197-
/// Rx signal detected
198-
pub sig_detect: bool,
199-
/// CDR lock achieved
200-
pub phy_ready: bool,
201-
/// Apparent PPM difference between local and remote
202-
pub ppm: i32,
203-
}
204-
205146
// Fetch the Rx signal information for the given port and logical lane
206147
fn lane_rx_sig_info_get(
207148
hdl: &Handle,
@@ -405,19 +346,6 @@ pub fn port_tx_eq_set(
405346
Ok(())
406347
}
407348

408-
/// Rx DFE adaptation information
409-
#[derive(Default, Deserialize, Serialize, JsonSchema)]
410-
pub struct DfeAdaptationState {
411-
/// DFE complete
412-
pub adapt_done: bool,
413-
/// Total DFE attempts
414-
pub adapt_cnt: u32,
415-
/// DFE attempts since the last read
416-
pub readapt_cnt: u32,
417-
/// Times the signal was lost since the last read
418-
pub link_lost_cnt: u32,
419-
}
420-
421349
// Fetch the state of the Rx Decision Feedback Equalizer adaptation for the
422350
// specified port and logical lane
423351
fn lane_adapt_state_get(
@@ -459,13 +387,6 @@ pub fn port_adapt_state_get(
459387
Ok(rval)
460388
}
461389

462-
/// Eye height(s) for a single lane in mv
463-
#[derive(Deserialize, Serialize, JsonSchema)]
464-
pub enum SerdesEye {
465-
Nrz(f32),
466-
Pam4 { eye1: f32, eye2: f32, eye3: f32 },
467-
}
468-
469390
// Returns the eye height(s) for the requested port and virtual lane
470391
fn lane_eye_get(
471392
hdl: &Handle,
@@ -688,13 +609,6 @@ pub fn pam4_ffe_get(
688609
Ok(ffe)
689610
}
690611

691-
/// Signal speed and encoding for a single lane
692-
#[derive(Deserialize, Serialize, JsonSchema)]
693-
pub struct EncSpeed {
694-
pub encoding: LaneEncoding,
695-
pub gigabits: u32,
696-
}
697-
698612
// Fetch the current encoding and speed for the specified port and logical lane
699613
fn lane_encoding_speed_get(
700614
hdl: &Handle,
@@ -715,7 +629,7 @@ fn lane_encoding_speed_get(
715629
&mut enc,
716630
)
717631
.check_error("fetching lane/speed info")?;
718-
encoding = LaneEncoding::try_from(enc)?;
632+
encoding = try_into_lane_encoding(enc)?;
719633
}
720634

721635
Ok(EncSpeed { encoding, gigabits })
@@ -757,28 +671,6 @@ pub fn an_done_get(hdl: &Handle, port: PortHdl, lane: u32) -> AsicResult<bool> {
757671
Ok(an_done)
758672
}
759673

760-
/// State of a single lane during autonegotiation
761-
#[derive(Deserialize, Serialize, JsonSchema)]
762-
pub struct AnStatus {
763-
/// Can the link partner perform AN?
764-
pub lp_an_ability: bool,
765-
/// Allegedly: is the link up? In practice, this always seems to be false?
766-
/// TODO: investigate this
767-
pub link_status: bool,
768-
/// Are we capable of AN?
769-
pub an_ability: bool,
770-
/// Remote fault detected
771-
pub remote_fault: bool,
772-
/// Is autonegotiation complete?
773-
pub an_complete: bool,
774-
/// has a base page been received?
775-
pub page_rcvd: bool,
776-
/// Is extended page format supported?
777-
pub ext_np_status: bool,
778-
/// A fault has been detected via the parallel detection function
779-
pub parallel_detect_fault: bool,
780-
}
781-
782674
/// Fetch the autonegotiation state of a single port and logical lane
783675
pub fn an_status_get(
784676
hdl: &Handle,
@@ -839,14 +731,6 @@ pub fn an_lp_base_page_get(hdl: &Handle, port: PortHdl) -> AsicResult<u64> {
839731
Ok(base_page)
840732
}
841733

842-
/// Set of AN pages sent by our link partner
843-
#[derive(Default, Deserialize, Serialize, JsonSchema)]
844-
pub struct LpPages {
845-
pub base_page: u64,
846-
pub next_page1: u64,
847-
pub next_page2: u64,
848-
}
849-
850734
/// Fetch all the AN pages received from the link partner for this port
851735
pub fn an_lp_pages_get(hdl: &Handle, port: PortHdl) -> AsicResult<LpPages> {
852736
let port_id = ports::to_asic_id(hdl, port)?;
@@ -898,27 +782,6 @@ pub fn an_hcd_get(hdl: &Handle, port: PortHdl, lane: u32) -> AsicResult<AnHcd> {
898782
Ok(an_hcd)
899783
}
900784

901-
/// Link-training status for a single lane
902-
#[derive(Deserialize, Serialize, JsonSchema)]
903-
pub struct LtStatus {
904-
/// Readout for frame lock state
905-
pub readout_state: u32,
906-
/// Frame lock state
907-
pub frame_lock: bool,
908-
/// Local training finished
909-
pub rx_trained: bool,
910-
/// Training state readout
911-
pub readout_training_state: u32,
912-
/// Link training failed
913-
pub training_failure: bool,
914-
/// TX control to send training pattern
915-
pub tx_training_data_en: bool,
916-
/// Signal detect for PCS
917-
pub sig_det: bool,
918-
/// State machine readout for training arbiter
919-
pub readout_txstate: u32,
920-
}
921-
922785
pub fn lt_status_get(
923786
hdl: &Handle,
924787
port: PortHdl,
@@ -962,27 +825,6 @@ pub fn lt_status_get(
962825
})
963826
}
964827

965-
/// The combined status of a lane, with respect to the autonegotiation /
966-
/// link-training process.
967-
#[derive(Deserialize, Serialize, JsonSchema)]
968-
pub struct LaneStatus {
969-
/// Has a lane successfully completed autoneg and link training?
970-
pub lane_done: bool,
971-
/// Detailed autonegotiation status
972-
pub lane_an_status: AnStatus,
973-
/// Detailed link-training status
974-
pub lane_lt_status: LtStatus,
975-
}
976-
977-
/// A collection of the data involved in the autonegiation/link-training process
978-
#[derive(Deserialize, Serialize, JsonSchema)]
979-
pub struct AnLtStatus {
980-
/// The base and extended pages received from the link partner
981-
pub lp_pages: LpPages,
982-
/// The per-lane status
983-
pub lanes: Vec<LaneStatus>,
984-
}
985-
986828
/// Collect all of the autonegotiation and link training status for this port.
987829
///
988830
/// The returned value contains a vector of `AnLtStatus`, indexed by the logical

0 commit comments

Comments
 (0)