10 namespace eth = satcat5::eth;
11 namespace log = satcat5::log;
12 namespace util = satcat5::util;
18 constexpr u32 MACTBL_OPCODE_MASK = 0xFF000000u;
19 constexpr u32 MACTBL_ARGVAL_MASK = 0x00FFFFFFu;
20 constexpr u32 MACTBL_IDLE = 0;
21 constexpr u32 MACTBL_READ(
unsigned tbl_idx) {
return (u32)(0x01000000 + tbl_idx);}
22 constexpr u32 MACTBL_WRITE(
unsigned port_idx) {
return (u32)(0x02000000 + port_idx);}
23 constexpr u32 MACTBL_CLEAR() {
return (u32)(0x03000000);}
24 constexpr u32 MACTBL_LEARN(
unsigned enable) {
return (u32)(0x04000000 + enable);}
27 : m_reg(cfg->get_register(devaddr, 0))
51 for (u32 a = 0 ; a < tsize ; ++a) {
63 log::Log(log::WARNING,
"MAC priority-table overflow.");
65 }
else if (etype < 1536 || plen > 16) {
66 log::Log(log::WARNING,
"Invalid MAC-priority entry.");
71 u32 wcl = (u32)(16 - plen);
72 u32 cmd = (
m_pri_wridx << 24) | (wcl << 16) | etype;
82 u32 mask = (1u << port_idx);
83 util::set_mask_if(temp, mask, enable);
97 u32 mask = (1u << port_idx);
98 util::set_mask_if(temp, mask, enable);
120 for (
volatile unsigned a = 0 ; a < 16 ; ++a) {}
126 return (u16)((regval >> 0) & 0xFFFF);
131 return (u16)((regval >> 16) & 0xFFFF);
160 u32 mask = (1u << port_idx);
161 util::set_mask_if(temp, mask, enable);
173 for (
unsigned port = 0 ; port < pcount ; ++port) {
174 VtagPolicy vtag(port, policy, eth::VTAG_DEFAULT);
181 for (u16 vid = eth::VID_MIN ; vid <= eth::VID_MAX ; ++vid)
186 for (u16 vid = eth::VID_MIN ; vid <= eth::VID_MAX ; ++vid)
217 util::set_mask_u32(mask, 1u << port);
227 util::clr_mask_u32(mask, 1u << port);
248 port_idx = (unsigned)(status & MACTBL_ARGVAL_MASK);
249 util::write_be_u16(mac_addr.
addr + 0, mac_msb);
250 util::write_be_u32(mac_addr.
addr + 2, mac_lsb);
253 return (mac_addr != MACADDR_NONE)
254 && (mac_addr != MACADDR_BROADCAST);
302 for (
unsigned tbl_idx = 0 ; tbl_idx < table_size ; ++tbl_idx) {
309 msg.
write(
": Empty");
317 for (
unsigned a = 0 ; a < 100 ; ++a) {
319 if ((status & MACTBL_OPCODE_MASK) == MACTBL_IDLE)
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.
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.
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)
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)
The Log class creates and formats one log message.
Log & write10(s32 val)
Print integer as a decimal value with no leading zeros.
Log & write(const char *str)
Formatting methods for various data types.
Diagnostic logging to UART and/or Ethernet ports.
An Ethernet MAC address (with serializable interface).
u8 addr[6]
Byte array in network order (Index 0 = MSB)
Data structure for configuring VLAN rate-limiter parameters.
u32 tok_rate
Tokens per millisecond.
u32 tok_max
Maximum accumulated tokens.
u32 tok_policy
Policy and scaling.
Data structure for configuring VLAN tagging policy of each port.
u32 value
Packed value holds the tag policy, port number, and default VID.
Configuration for a managed SatCat5 switch.
constexpr u32 VTAG_RESTRICT
Define VLAN policy modes for a given switch port.
constexpr u32 VTAG_ADMIT_ALL
Define VLAN policy modes for a given switch port.
constexpr u32 VLAN_CONNECT_ALL
Common port-connection masks.
constexpr u32 VLAN_CONNECT_NONE
Common port-connection masks.
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.
Miscellaneous mathematical utility functions.