Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
edition = "2021"
# ---------------------------------------------------------------------------
# Stable features that we customize locally
# ---------------------------------------------------------------------------
max_width = 80
use_small_heuristics = "max"
edition = "2024"
style_edition = "2024"
10 changes: 8 additions & 2 deletions aal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,15 @@ pub trait TableOps<H: AsicOps> {
#[derive(Clone, Copy, Debug)]
pub enum PortUpdate {
/// Signal that a port's "enable" state has changed
Enable { asic_port_id: AsicId, enabled: bool },
Enable {
asic_port_id: AsicId,
enabled: bool,
},
/// Signal that the linkup/linkdown state of a port has changed
LinkUp { asic_port_id: AsicId, linkup: bool },
LinkUp {
asic_port_id: AsicId,
linkup: bool,
},
/// Signal that the port has transitioned from one state to another in the AN/LT finite state
/// machine
FSM {
Expand Down
10 changes: 2 additions & 8 deletions aal/src/match_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,7 @@ macro_rules! unwrap_value_entry {
impl From<Ipv6Net> for MatchLpm {
fn from(cidr: Ipv6Net) -> Self {
let v: u128 = cidr.addr().into();
MatchLpm {
prefix: v.into(),
len: cidr.width() as u16,
}
MatchLpm { prefix: v.into(), len: cidr.width() as u16 }
}
}

Expand All @@ -208,10 +205,7 @@ unwrap_lpm_entry!(Ipv6Net);
impl From<Ipv4Net> for MatchLpm {
fn from(cidr: Ipv4Net) -> Self {
let v: u32 = cidr.addr().into();
MatchLpm {
prefix: v.into(),
len: cidr.width() as u16,
}
MatchLpm { prefix: v.into(), len: cidr.width() as u16 }
}
}

Expand Down
12 changes: 2 additions & 10 deletions aal_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,11 +380,7 @@ fn get_fields<'a>(
None => name.to_string(),
};

fields.push(FieldInfo {
name,
field_name,
match_type,
});
fields.push(FieldInfo { name, field_name, match_type });
}

Ok(fields)
Expand Down Expand Up @@ -436,11 +432,7 @@ fn get_actions<'a>(
};

let action_args = get_action_args(v)?;
actions.push(Action {
name,
action_name,
action_args,
});
actions.push(Action { name, action_name, action_args });
}

Ok(actions)
Expand Down
10 changes: 2 additions & 8 deletions asic/src/chaos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,7 @@ impl Handle {
/// `Chaos` member of [`AsicConfig`]. The `handle` is a [`Handle`] object.
macro_rules! unfurl {
($handle:ident, $name:ident) => {
$handle
.config
.$name
.unfurled(&$handle.log, stringify!($name))?
$handle.config.$name.unfurled(&$handle.log, stringify!($name))?
};
}
pub(crate) use unfurl;
Expand All @@ -332,10 +329,7 @@ pub(crate) use unfurl;
/// `TableChaos` member of [`AsicConfig`]. The `handle` is a [`Handle`] object.
macro_rules! table_unfurl {
($handle:ident, $id: expr, $name:ident) => {
$handle
.config
.$name
.unfurled(&$handle.log, $id, stringify!($name))?
$handle.config.$name.unfurled(&$handle.log, $id, stringify!($name))?
};
}
pub(crate) use table_unfurl;
Expand Down
5 changes: 1 addition & 4 deletions asic/src/chaos/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@ pub struct Table {
impl TableOps<Handle> for Table {
fn new(hdl: &Handle, name: &str) -> AsicResult<Table> {
table_unfurl!(hdl, name, table_new);
Ok(Table {
name: name.into(),
keys: Mutex::new(HashSet::new()),
})
Ok(Table { name: name.into(), keys: Mutex::new(HashSet::new()) })
}

fn size(&self) -> usize {
Expand Down
5 changes: 1 addition & 4 deletions asic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,7 @@ impl FsmStats {

/// Increases the counter for a single state by 1.
pub fn bump(&mut self, state: PortFsmState) {
self.0
.entry(state)
.and_modify(|count| *count += 1)
.or_insert(1);
self.0.entry(state).and_modify(|count| *count += 1).or_insert(1);
}

/// Returns the full set of possible states, giving the caller an easy way
Expand Down
7 changes: 2 additions & 5 deletions asic/src/softnpu/mgmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,8 @@ fn write_uds(msg: ManagementRequest, socket_path: &str) {
}

fn read_uart(msg: ManagementRequest) -> String {
let mut f = OpenOptions::new()
.read(true)
.write(true)
.open(SOFTNPU_TTY)
.unwrap();
let mut f =
OpenOptions::new().read(true).write(true).open(SOFTNPU_TTY).unwrap();

let mut buf = Vec::new();
buf.push(MANAGEMENT_MESSAGE_PREAMBLE);
Expand Down
30 changes: 8 additions & 22 deletions asic/src/softnpu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ impl Handle {
let mgmt_config = match config.softnpu_management {
mgmt::SoftnpuManagement::UART => mgmt::ManagementConfig::UART,
mgmt::SoftnpuManagement::UDS => match &config.uds_path {
Some(s) => mgmt::ManagementConfig::UDS {
socket_path: s.to_string(),
},
Some(s) => {
mgmt::ManagementConfig::UDS { socket_path: s.to_string() }
}
None => {
return Err(AsicError::InvalidArg(
"softnpu unix domain socket missing".to_string(),
Expand Down Expand Up @@ -198,14 +198,9 @@ impl AsicOps for Handle {
// When a port is enabled in softnpu, it automatically comes online.
// When switching between enabled and disabled, we send the main body
// of dpd the PortUpdate events we would expect to see on real hardware.
let present = PortUpdate::Presence {
asic_port_id,
presence: enabled,
};
let ena = PortUpdate::Enable {
asic_port_id,
enabled,
};
let present =
PortUpdate::Presence { asic_port_id, presence: enabled };
let ena = PortUpdate::Enable { asic_port_id, enabled };
let fsm_state = match enabled {
false => PortFsmState::Idle,
true => PortFsmState::LinkUp,
Expand All @@ -215,10 +210,7 @@ impl AsicOps for Handle {
fsm: FsmType::Port.into(),
state: fsm_state.into(),
};
let link = PortUpdate::LinkUp {
asic_port_id,
linkup: enabled,
};
let link = PortUpdate::LinkUp { asic_port_id, linkup: enabled };

for event in &[present, ena, fsm, link] {
if let Err(e) = tx.send(*event) {
Expand Down Expand Up @@ -296,13 +288,7 @@ impl AsicOps for Handle {
"Port {port_hdl:?} exists"
)));
}
ports.insert(
port_hdl,
Port {
enabled: true,
tx_eq: 0,
},
);
ports.insert(port_hdl, Port { enabled: true, tx_eq: 0 });
self.port_to_asic_id(port_hdl).map(|id| (port_hdl, id))
}

Expand Down
6 changes: 1 addition & 5 deletions asic/src/softnpu/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,7 @@ impl TableOps<Handle> for Table {
}
};

Ok(Table {
id,
dpd_id,
size: TABLE_SIZE,
})
Ok(Table { id, dpd_id, size: TABLE_SIZE })
}

fn size(&self) -> usize {
Expand Down
23 changes: 5 additions & 18 deletions asic/src/tofino_asic/bf_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,7 @@ fn sanitize_dev_port(
if dev_id != DEVICE_ID {
Err(format!("invalid device id: {dev_id}"))
} else {
port.try_into()
.map_err(|_| format!("invalid asic id: {port}"))
port.try_into().map_err(|_| format!("invalid asic id: {port}"))
}
}

Expand Down Expand Up @@ -205,10 +204,7 @@ extern "C" fn port_admin_state_cb(
};
send_port_update(
"port_admin_state_cb()",
PortUpdate::Enable {
asic_port_id,
enabled,
},
PortUpdate::Enable { asic_port_id, enabled },
);
BF_SUCCESS
}
Expand All @@ -229,10 +225,7 @@ extern "C" fn port_status_int_cb(
};
send_port_update(
"port_status_int_cb()",
PortUpdate::LinkUp {
asic_port_id,
linkup,
},
PortUpdate::LinkUp { asic_port_id, linkup },
);
BF_SUCCESS
}
Expand All @@ -254,10 +247,7 @@ extern "C" fn port_presence_cb(

send_port_update(
"port_presence_cb()",
PortUpdate::Presence {
asic_port_id,
presence,
},
PortUpdate::Presence { asic_port_id, presence },
);
BF_SUCCESS
}
Expand Down Expand Up @@ -373,10 +363,7 @@ pub fn bf_init(
let log = log.new(o!("unit" => "callback"));

assert!(cb.is_none());
*cb = Some(CallbackState {
log,
update_tx: None,
});
*cb = Some(CallbackState { log, update_tx: None });
}

let devpath = bf_driver_path(devpath)?;
Expand Down
6 changes: 1 addition & 5 deletions asic/src/tofino_asic/link_fsm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,10 +479,6 @@ pub extern "C" fn bf_pm_fsm_transition_callback(
};
bf_wrapper::send_port_update(
"port_fsm_transition_cb()",
aal::PortUpdate::FSM {
asic_port_id,
fsm,
state: to,
},
aal::PortUpdate::FSM { asic_port_id, fsm, state: to },
)
}
16 changes: 3 additions & 13 deletions asic/src/tofino_asic/mcast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,7 @@ pub fn domain_add_port(
rid: u16,
level_1_excl_id: u16,
) -> AsicResult<()> {
debug!(
hdl.log,
"adding port {} to multicast domain {}", port, group_id
);
debug!(hdl.log, "adding port {} to multicast domain {}", port, group_id);

let mut domains = hdl.domains.lock().unwrap();
let domain = match domains.get_mut(&group_id) {
Expand Down Expand Up @@ -303,10 +300,7 @@ pub fn domain_remove_port(
group_id: u16,
port: u16,
) -> AsicResult<()> {
debug!(
hdl.log,
"removing {} from multicast domain {}", port, group_id
);
debug!(hdl.log, "removing {} from multicast domain {}", port, group_id);
let mut domains = hdl.domains.lock().unwrap();
let domain = match domains.get_mut(&group_id) {
Some(d) => Ok(d),
Expand Down Expand Up @@ -341,11 +335,7 @@ pub fn domain_create(hdl: &Handle, group_id: u16) -> AsicResult<()> {
let mgrp_hdl = mgrp_create(bf.mcast_hdl, bf.dev_id, group_id)?;
domains.insert(
group_id,
DomainState {
id: group_id,
mgrp_hdl,
ports: HashMap::new(),
},
DomainState { id: group_id, mgrp_hdl, ports: HashMap::new() },
);
Ok(())
}
Expand Down
18 changes: 3 additions & 15 deletions asic/src/tofino_asic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,7 @@ pub struct AsicConfig {

impl Default for AsicConfig {
fn default() -> Self {
Self {
devpath: None,
xcvr_iface: None,
board_rev: String::from("B"),
}
Self { devpath: None, xcvr_iface: None, board_rev: String::from("B") }
}
}

Expand Down Expand Up @@ -276,16 +272,8 @@ fn wafer_loc_from_coords(
y_sign: u8,
y_pos: u8,
) -> (i16, i16) {
let x = if x_sign == 0 {
i16::from(x_pos)
} else {
-i16::from(x_pos)
};
let y = if y_sign == 0 {
i16::from(y_pos)
} else {
-i16::from(y_pos)
};
let x = if x_sign == 0 { i16::from(x_pos) } else { -i16::from(x_pos) };
let y = if y_sign == 0 { i16::from(y_pos) } else { -i16::from(y_pos) };

(x, y)
}
Expand Down
Loading