17 #include <satcat5/ethernet.h>
56 constexpr u32 VRATE_SCALE_1X = 0x00000000u;
57 constexpr u32 VRATE_SCALE_256X = 0x08000000u;
58 constexpr u64 VRATE_THRESHOLD = 100000000;
76 {
return u32(
value & 0x00FF0000); }
77 inline unsigned port()
const
78 {
return unsigned(
value >> 24); }
114 return (rate_bps < VRATE_THRESHOLD)
115 ? u32(rate_bps / 8000)
116 : u32(rate_bps / 2000000);
130 rate_bps < VRATE_THRESHOLD
131 ? (policy | VRATE_SCALE_1X)
132 : (policy | VRATE_SCALE_256X))
279 static constexpr
unsigned
301 {
return 512 + 16*idx;}
ConfigBus core definitions.
Pointer-like wrapper for one or more ConfigBus registers.
Management functions for a SatCat5 Ethernet switch.
void mactbl_log(const char *label)
Log the contents of the MAC-address table.
bool mactbl_write(unsigned port_idx, const satcat5::eth::MacAddr &mac_addr)
Write a new entry to the MAC-address table.
static constexpr unsigned REG_MACTBL_CTRL
MAC-table control (read-write)
static constexpr unsigned REG_MACTBL_LSB
MAC-table control (read-write)
static constexpr unsigned REG_VLAN_VID
VLAN connections: set VID (read-write)
void vlan_reset(bool lockdown=false)
Revert all VLAN settings to default.
u32 get_miss_mask()
Identify which ports are currently in "miss-as-broadcast" mode.
bool priority_set(u16 etype, unsigned plen=16)
Designate specific EtherType range(s) as high-priority.
u16 get_frame_max()
Get the maximum allowed frame size, in bytes.
static constexpr unsigned REG_PORT(unsigned idx)
Base address for per-port registers.
void vlan_set_mask(u16 vid, u32 mask)
Set connected port-mask for the designated VLAN.
static constexpr unsigned REG_MACCOUNT
MAC-address table size (read-only)
void ptp_set_2step(unsigned port_idx, bool enable)
PTP configuration for each port.
static constexpr unsigned REG_VLAN_PORT
VLAN port configuration (write-only)
void vlan_leave(u16 vid, unsigned port)
Remote a given port from the designated VLAN.
SwitchConfig(satcat5::cfg::ConfigBus *cfg, unsigned devaddr)
Attach to the designated ConfigBus address.
void set_miss_bcast(unsigned port_idx, bool enable)
Enable or disable "miss-as-broadcast" flag on the specified port.
static constexpr unsigned REG_FRAMESIZE
Frame size limits (read-only)
bool mactbl_clear()
Clear MAC-address table contents.
void vlan_join(u16 vid, unsigned port)
Join a given port to the designated VLAN.
unsigned mactbl_size()
Read the maximum size of the MAC-address table.
void set_miss_mask(u32 mask)
Enable or disable all "miss-as-broadcast" flags at once.
static constexpr unsigned REG_CORECLOCK
Core clock frequency, in Hz (read-only)
static constexpr unsigned REG_DATAPATH
Datapath width, in bits (read-only)
static constexpr unsigned REG_PROMISC
Promisicuous port mask (read-write)
void ptp_set_offset_tx(unsigned port_idx, s32 subns)
PTP configuration for each port.
bool mactbl_wait_idle()
Wait for MAC-table access.
static constexpr unsigned REG_PRIORITY
Packet prioritization (read-write, optional)
void vlan_set_port(const VtagPolicy &cfg)
Set tag policy and other per-port settings.
static constexpr unsigned REG_MISS_BCAST
Miss-as-broadcast port mask (read-write)
u32 get_promiscuous_mask()
Identify which ports are currently promiscuous.
static constexpr unsigned REG_MACTBL_MSB
MAC-table control (read-write)
u32 vlan_get_mask(u16 vid)
Get connected port-mask for the designated VLAN.
u32 m_pri_wridx
Next index in priority table.
static constexpr unsigned REG_PTP_TX(unsigned idx)
Tx timestamp offset for Nth port.
static constexpr unsigned REG_VLAN_RATE
VLAN rate-control configuration (write-only)
u16 get_traffic_filter() const
Query the current traffic filter setting.
u32 ptp_get_2step_mask()
PTP configuration for each port.
u32 get_traffic_count()
Report matching frames since last call to get_traffic_count().
satcat5::cfg::Register m_reg
ConfigBus register space.
static constexpr unsigned REG_PTP_2STEP
PTP "twoStep" mode flag (read-write)
void priority_reset()
Clear all EtherType-based priority settings.
void set_traffic_filter(u16 etype=0)
Set EtherType filter for traffic reporting. (0 = Any type)
s32 ptp_get_offset_rx(unsigned port_idx)
PTP configuration for each port.
void set_promiscuous_mask(u32 mask)
Set the "promiscuous" flag for all ports at once.
u32 port_count()
Number of ports on this switch.
static constexpr unsigned REG_PTP_RX(unsigned idx)
Rx timestamp offset for Nth port.
static constexpr unsigned REG_PORTCOUNT
Number of ports (read-only)
void set_promiscuous(unsigned port_idx, bool enable)
Enable or disable "promiscuous" flag on the specified port index.
satcat5::cfg::Register get_log_register()
Get packet-logging register.
static constexpr unsigned REG_LOGGING
Packet logging diagnostics (read-only)
bool mactbl_read(unsigned tbl_idx, unsigned &port_idx, satcat5::eth::MacAddr &mac_addr)
Read the Nth entry from the MAC-address table.
void log_info(const char *label)
Log some basic info about this switch.
static constexpr unsigned REG_VLAN_MASK
VLAN connections: set mask (read-write)
void ptp_set_offset_rx(unsigned port_idx, s32 subns)
PTP configuration for each port.
s32 ptp_get_offset_tx(unsigned port_idx)
PTP configuration for each port.
u16 get_frame_min()
Get the minimum allowed frame size, in bytes.
void vlan_set_rate(u16 vid, const satcat5::eth::VlanRate &cfg)
Set the maximum aggregated throughput for a given VID.
u16 m_stats_filter
Filter stats by EtherType.
bool mactbl_learn(bool enable)
Enable automatic learning of new MAC addresses?
static constexpr unsigned REG_PKTCOUNT
Packet-counting w/ filter (read-write)
An Ethernet MAC address (with serializable interface).
Data structure for configuring VLAN rate-limiter parameters.
u32 tok_rate
Tokens per millisecond.
u32 tok_max
Maximum accumulated tokens.
constexpr VlanRate(u32 policy, u64 rate_bps, u32 burst_msec=1)
Constructor for any other policy.
u32 tok_policy
Policy and scaling.
constexpr VlanRate()
Constructof for the default unlimited policy.
static constexpr u32 bps2rate(u64 rate_bps)
Convert bits-per-second to internal configuration word.
Header contents for an 802.1Q Virtual-LAN tag.
Data structure for configuring VLAN tagging policy of each port.
VtagPolicy & operator=(const VtagPolicy &other)
Each constructors creates a packed configuration word.
u32 value
Packed value holds the tag policy, port number, and default VID.
constexpr VtagPolicy(u32 port, u32 policy, VlanTag vtag=VTAG_DEFAULT)
Each constructors creates a packed configuration word.
u32 policy() const
Accessors for each individual field.
constexpr VtagPolicy(const VtagPolicy &other)
Each constructors creates a packed configuration word.
constexpr VtagPolicy(u32 other)
Each constructors creates a packed configuration word.
unsigned port() const
Accessors for each individual field.
satcat5::eth::VlanTag vtag() const
Accessors for each individual field.
constexpr VtagPolicy()
Each constructors creates a packed configuration word.
constexpr satcat5::eth::VtagPolicy VCFG_DEFAULT(0, VTAG_ADMIT_ALL, VTAG_DEFAULT)
Default VLAN tagging policy.
constexpr satcat5::eth::VlanRate VRATE_32KBPS(VPOL_STRICT, 32000ull, 1024)
Define some commonly-used rate-limiter configurations.
constexpr u32 VTAG_RESTRICT
Define VLAN policy modes for a given switch port.
constexpr satcat5::eth::VlanRate VRATE_16MBPS(VPOL_STRICT, 16000000ull, 2)
Define some commonly-used rate-limiter configurations.
constexpr satcat5::eth::VlanRate VRATE_16KBPS(VPOL_STRICT, 16000ull, 2048)
Define some commonly-used rate-limiter configurations.
constexpr satcat5::eth::VlanRate VRATE_100MBPS(VPOL_STRICT, 100000000ull)
Define some commonly-used rate-limiter configurations.
constexpr satcat5::eth::VlanRate VRATE_1GBPS(VPOL_STRICT, 1000000000ull)
Define some commonly-used rate-limiter configurations.
constexpr satcat5::eth::VlanRate VRATE_10GBPS(VPOL_STRICT, 10000000000ull)
Define some commonly-used rate-limiter configurations.
constexpr u32 VTAG_ADMIT_ALL
Define VLAN policy modes for a given switch port.
constexpr u32 VPOL_UNLIMITED
Define VLAN rate-limiter modes for each VID.
constexpr satcat5::eth::VlanRate VRATE_256KBPS(VPOL_STRICT, 256000ull, 128)
Define some commonly-used rate-limiter configurations.
constexpr u32 VLAN_CONNECT_ALL
Common port-connection masks.
constexpr satcat5::eth::VlanRate VRATE_ZERO(VPOL_STRICT, 0, 0)
Define some commonly-used rate-limiter configurations.
constexpr satcat5::eth::VlanRate VRATE_64KBPS(VPOL_STRICT, 64000ull, 512)
Define some commonly-used rate-limiter configurations.
constexpr u32 VLAN_CONNECT_NONE
Common port-connection masks.
constexpr satcat5::eth::VlanRate VRATE_1MBPS(VPOL_STRICT, 1000000ull, 32)
Define some commonly-used rate-limiter configurations.
constexpr u32 VPOL_STRICT
Define VLAN rate-limiter modes for each VID.
constexpr satcat5::eth::VlanRate VRATE_UNLIMITED(VPOL_UNLIMITED, 0, 0)
Define some commonly-used rate-limiter configurations.
constexpr satcat5::eth::VlanRate VRATE_8KBPS(VPOL_STRICT, 8000ull, 4096)
Define some commonly-used rate-limiter configurations.
constexpr u32 VTAG_MANDATORY
Define VLAN policy modes for a given switch port.
constexpr u32 VPOL_AUTO
Define VLAN rate-limiter modes for each VID.
constexpr satcat5::eth::VlanRate VRATE_2MBPS(VPOL_STRICT, 2000000ull, 16)
Define some commonly-used rate-limiter configurations.
constexpr satcat5::eth::VlanRate VRATE_8MBPS(VPOL_STRICT, 8000000ull, 4)
Define some commonly-used rate-limiter configurations.
constexpr u32 VTAG_PRIORITY
Define VLAN policy modes for a given switch port.
constexpr satcat5::eth::VlanRate VRATE_10MBPS(VPOL_STRICT, 10000000ull, 3)
Define some commonly-used rate-limiter configurations.
constexpr satcat5::eth::VlanRate VRATE_128KBPS(VPOL_STRICT, 128000ull, 256)
Define some commonly-used rate-limiter configurations.
constexpr satcat5::eth::VlanRate VRATE_512KBPS(VPOL_STRICT, 512000ull, 64)
Define some commonly-used rate-limiter configurations.
constexpr satcat5::eth::VlanRate VRATE_4MBPS(VPOL_STRICT, 4000000ull, 8)
Define some commonly-used rate-limiter configurations.
constexpr u32 VPOL_DEMOTE
Define VLAN rate-limiter modes for each VID.