SatCat5
router2_offload.h
1 // Copyright 2024-2025 The Aerospace Corporation.
3 // This file is a part of SatCat5, licensed under CERN-OHL-W v2 or later.
5 // Offload port for gateware-accelerated IPv4 routers
6 
7 #pragma once
8 
9 #include <satcat5/cfgbus_interrupt.h>
10 #include <satcat5/router2_dispatch.h>
11 
12 namespace satcat5 {
13  namespace router2 {
14  // Define policy configuration flags matching "router2_gateway.vhd".
15  // Setting a policy mask blocks packets of the specified type.
16  constexpr u32
17  RULE_ALL = (0xFFFF0000u),
18  RULE_LCL_BCAST = (1u << 21),
19  RULE_NOIP_ALL = (1u << 20),
20  RULE_NOIP_BCAST = (1u << 19),
21  RULE_IPV4_MCAST = (1u << 18),
22  RULE_IPV4_BCAST = (1u << 17),
23  RULE_BAD_DMAC = (1u << 16);
24 
31  class Offload
32  : protected satcat5::cfg::Interrupt
33  , protected satcat5::io::MultiWriter
34  {
35  public:
38  Offload(
39  satcat5::cfg::ConfigBusMmap* cfg, unsigned devaddr,
40  satcat5::router2::Dispatch* router, unsigned hw_ports);
41  ~Offload() SATCAT5_OPTIONAL_DTOR;
42 
44  void rule_allow(u32 mask);
46  void rule_block(u32 mask);
48  inline void rule_zpad(bool enable)
49  { m_zero_pad = enable; }
50 
52  void deliver(const satcat5::eth::PluginPacket& meta);
53 
57  { return m_pktlog; }
58 
62  u32 reconfigure();
63 
65  inline u32 link_shdn_hw()
66  { return m_ctrl->port_shdn; }
69  { return SATCAT5_PMASK_TYPE(link_shdn_hw()) << m_port_index; }
70 
72  inline unsigned port_index(unsigned hw_idx) const
73  { return m_port_index + hw_idx; }
75  inline SATCAT5_PMASK_TYPE port_mask(unsigned hw_idx) const
76  { return satcat5::eth::idx2mask(port_index(hw_idx)); }
79  { return m_port_mask; }
80 
81  protected:
82  // Internal event-handlers.
83  void irq_event() override;
84 
85  // Hardware register map:
86  // TODO: Provide accessors for some of these hardware registers?
87  struct ctrl_reg {
88  u8 txrx_buff[1600]; // Reg 0-399
89  u32 rx_rsvd[89]; // Reg 400-488
90  volatile u32 pkt_log; // Reg 489
91  volatile u32 vlan_vid; // Reg 490
92  volatile u32 vlan_mask; // Reg 491
93  volatile u32 vlan_rate; // Reg 492
94  volatile u32 pkt_count; // Reg 493
95  volatile u32 port_shdn; // Reg 494
96  volatile u32 info; // Reg 495
97  volatile u32 ecn_red; // Reg 496
98  volatile u32 nat_ctrl; // Reg 497
99  volatile u32 gateway; // Reg 498
100  volatile u32 tx_mask; // Reg 499
101  volatile u32 tx_ctrl; // Reg 500
102  volatile u32 ptp_2step; // Reg 501
103  volatile u32 port_count; // Reg 502
104  volatile u32 data_width; // Reg 503
105  volatile u32 core_clock; // Reg 504
106  volatile u32 table_size; // Reg 505
107  volatile u32 noip_data; // Reg 506
108  volatile u32 noip_ctrl; // Reg 507
109  volatile u32 cidr_data; // Reg 508
110  volatile u32 cidr_ctrl; // Reg 509
111  volatile u32 rx_irq; // Reg 510
112  volatile u32 rx_ctrl; // Reg 511
113  u32 port_cfg[512]; // Reg 512-1023
114  };
115  ctrl_reg* const m_ctrl;
116 
117  // Connection to the parent object.
118  satcat5::router2::Dispatch* const m_router;
119  satcat5::cfg::Register m_pktlog; // Packet-logging register
120  const unsigned m_port_index; // Index of hardware port #0.
121  bool m_zero_pad; // Enable zero-padding?
122  SATCAT5_PMASK_TYPE m_port_mask; // Mask of all associated ports.
123  u32 m_policy; // Block specific packet types?
124  };
125  }
126 }
Memory-mapped local ConfigBus.
Definition: cfgbus_core.h:199
Event-handler for individual ConfigBus interrupts.
Pointer-like wrapper for one or more ConfigBus registers.
Definition: cfgbus_core.h:76
A port for writing to a MultiBuffer object.
Definition: multi_buffer.h:405
Packet-processing pipeline for the IPv4 router.
Offload port for gateware-accelerated IPv4 routers.
void rule_allow(u32 mask)
Set specific router policy flags.
void rule_zpad(bool enable)
Enable or disable zero-padding.
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.
Offload(satcat5::cfg::ConfigBusMmap *cfg, unsigned devaddr, satcat5::router2::Dispatch *router, unsigned hw_ports)
Constructor sets the number of associated hardware ports.
SATCAT5_PMASK_TYPE port_mask(unsigned hw_idx) const
Convert hardware port index to a software port-mask.
SATCAT5_PMASK_TYPE port_mask_all() const
Return a port-mask containing all connected ports.
void rule_block(u32 mask)
Clear specific router policy flags.
satcat5::cfg::Register get_log_register() const
Get packet-logging register.
u32 link_shdn_hw()
Mask indicating hardware-defined ports in the shutdown state.
void deliver(const satcat5::eth::PluginPacket &meta)
Deliver a given packet to the hardware queue.
void irq_event() override
Interrupt service routine.
SATCAT5_PMASK_TYPE link_shdn_sw()
Mask indicating software-defined ports in the shutdown state.
#define SATCAT5_PMASK_TYPE
Set the integer type used to identify source and destination ports.
Definition: eth_switch.h:41
Ephemeral data structure provided to plugin callbacks.
Definition: eth_plugin.h:48