8 #include <satcat5/router2_offload.h>
17 static const char* LBL =
"ROUTER_OFFLOAD";
18 static const unsigned REGADDR_LOG = 489;
19 static const unsigned REGADDR_IRQ = 510;
24 : Interrupt(cfg, devaddr, REGADDR_IRQ)
26 , m_ctrl((
ctrl_reg*)cfg->get_device_mmap(devaddr))
28 , m_pktlog(cfg->get_register(devaddr, REGADDR_LOG))
29 , m_port_index(router->port_count())
32 , m_policy(satcat5::router2::RULE_ALL)
35 static_assert(
sizeof(
ctrl_reg) == 4096);
42 for (
unsigned a = 0 ; a < hw_ports ; ++a) {
44 m_port_mask |= new_mask;
45 if (new_mask != satcat5::eth::idx2mask(m_port_index+a))
46 Log(CRITICAL, LBL).
write(
"Port registration error.");
53 #if SATCAT5_ALLOW_DELETION
60 satcat5::util::clr_mask(m_policy, mask);
65 satcat5::util::set_mask(m_policy, mask);
72 if (len >
sizeof(m_ctrl->txrx_buff))
return;
75 u32 hw_mask((meta.
dst_mask & m_port_mask) >> m_port_index);
80 if (m_ctrl->tx_ctrl) {
81 SATCAT5_CLOCK->busywait_usec(10);
82 if (m_ctrl->tx_ctrl)
return;
86 MultiPacket::Reader rd(meta.
pkt);
87 rd.read_bytes(len, m_ctrl->txrx_buff);
91 static const unsigned MIN_ZPAD = 60;
92 if (m_zero_pad && len < MIN_ZPAD) {
93 unsigned diff = MIN_ZPAD - len;
94 memset(m_ctrl->txrx_buff + len, 0, diff);
99 m_ctrl->tx_mask = u32(hw_mask);
100 m_ctrl->tx_ctrl = u32(len);
105 u32 status = m_ctrl->rx_ctrl;
106 u32 source = (status >> 16) & 0xFF;
107 u32 length = (status & 0xFFFF);
111 auto vlan_cfg = satcat5::eth::VCFG_DEFAULT;
115 bool ok = (length <=
sizeof(m_ctrl->txrx_buff));
116 if (ok) MultiWriter::write_bytes(length, m_ctrl->txrx_buff);
121 static_assert(SATCAT5_MBUFF_USER >= 2,
122 "SATCAT5_MBUFF_USER must be at least 2.");
126 if (ok) MultiWriter::write_finalize();
134 u32 ipaddr = m_router->ipaddr().
value;
135 u64 mac64 = m_router->macaddr().
to_u64();
136 m_ctrl->gateway = u32(mac64 >> 32) | m_policy;
137 m_ctrl->gateway = u32(mac64 >> 0);
138 m_ctrl->gateway = ipaddr;
139 return m_ctrl->gateway;
Memory-mapped local ConfigBus.
SATCAT5_PMASK_TYPE next_port_mask()
Get next available bit-mask for new SwitchPort objects.
satcat5::io::MultiPacket * m_write_pkt
Current write state.
The Log class creates and formats one log message.
Log & write(const char *str)
Formatting methods for various data types.
Packet-processing pipeline for the IPv4 router.
void set_offload(satcat5::router2::Offload *iface)
Link this dispatch unit to other parts of the IP/UDP stack.
Offload port for gateware-accelerated IPv4 routers.
void rule_allow(u32 mask)
Set specific router policy flags.
u32 reconfigure()
Reload router IP address and MAC address.
unsigned port_index(unsigned hw_idx) const
Convert hardware port index to a software port-index.
void rule_block(u32 mask)
Clear specific router policy flags.
void deliver(const satcat5::eth::PluginPacket &meta)
Deliver a given packet to the hardware queue.
void irq_event() override
Interrupt service routine.
#define SATCAT5_PMASK_TYPE
Set the integer type used to identify source and destination ports.
Diagnostic logging to UART and/or Ethernet ports.
constexpr s8 CRITICAL
Define basic priority codes for log messages.
constexpr u64 to_u64() const
Convert from MacAddr to u64.
Ephemeral data structure provided to plugin callbacks.
satcat5::io::MultiPacket * pkt
Complete packet contents.
SATCAT5_PMASK_TYPE dst_mask
Destination mask for which port(s) receive this packet.
A packet is a linked-list of memory blocks, plus metadata.
unsigned m_length
Packet length in bytes.
u32 m_user[SATCAT5_MBUFF_USER]
Packet metadata.
u32 value
Raw access to the underlying representation.
TimeRef and TimeVal define the API for monotonic timers.
Miscellaneous mathematical utility functions.