ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_eth_mfwd.c File Reference

Ethernet Message Forwarding Engine driver implementation. More...

#include "ra8_eth_mfwd.h"
#include <stdint.h>
#include "ra8_attributes.h"
#include "ra8_check.h"
#include "ra8_err.h"
#include "ra8_ether_regs.h"
#include "ra8_log.h"
#include "ra8_mstp.h"
#include "ra8_mstp_regs.h"
Include dependency graph for ra8_eth_mfwd.c:

Go to the source code of this file.

Enumerations

enum  ra8_eth_mfwd_internal_t : uint32_t {
  k_ra8_mfwd_off_fwpbfc0_base = 0x4A00UL ,
  k_ra8_mfwd_off_fwpbfcsdc0_base = 0x4A04UL ,
  k_ra8_mfwd_fwpbfcsdc_stride = 0x10UL ,
  k_ra8_mfwd_pbdv_mask = 0x7FUL ,
  k_ra8_mfwd_pbcsd_mask = 0x7FUL ,
  k_ra8_mfwd_port_count = 3UL ,
  k_ra8_mfwd_max_port = 1UL ,
  k_ra8_mfwd_max_queue = 31UL
}
 MFWD register offsets used by the routing programming path. More...

Functions

ra8_err_t ra8_eth_mfwd_init (void)
 Initialise the MFWD block (MSTP enable + reset regs).
ra8_err_t ra8_eth_mfwd_deinit (void)
 Tear down the MFWD block.
ra8_err_t ra8_eth_mfwd_get_status (uint32_t *out_mask)
 Read the MFWD_STS status register.
ra8_err_t ra8_eth_mfwd_clear_status (uint32_t mask)
 Clear bits in MFWD_STS via MFWD_ICLR.
ra8_err_t ra8_eth_mfwd_attach_handler (ra8_eth_mfwd_event_fn_t fn, void *ctx)
 Attach the shared event handler.
void ra8_eth_mfwd_dispatch (void)
 Dispatch an MFWD event.
ra8_err_t ra8_eth_mfwd_enter_stop (void)
 Put MFWD into MSTP-gated stop.
ra8_err_t ra8_eth_mfwd_exit_stop (void)
 Exit MSTP-gated stop.
static volatile uint32_t * internal_mfwd_fwpbfcsdc (uint8_t port)
 Return a typed pointer to FWPBFCSDC0[port] inside MFWD.
ra8_err_t ra8_eth_mfwd_set_forwarding_masks (const uint8_t port_masks[3])
 Program the per-port forwarding-destination masks (FWPBFC0).
ra8_err_t ra8_eth_mfwd_route_queue (uint8_t port, uint8_t queue_index)
 Route inbound frames from a GMAC port into a GWCA RX queue.

Variables

static const char * s_tag = "ETHMFW"
static ra8_eth_mfwd_event_fn_t s_mfwd_fn
static void * s_mfwd_ctx

Detailed Description

Ethernet Message Forwarding Engine driver implementation.

Tag
[Ring 3 / HAL] {World: NS}

driver for the RA8D2 MFWD block. The MFWD shares the Ethernet Switch MSTP gate (ESWM) so the lifecycle calls below piggyback on k_ra8_mstp_eswm rather than a per-block bit. Every register access carries a HUM Ch 30 citation.

Definition in file ra8_eth_mfwd.c.

Enumeration Type Documentation

◆ ra8_eth_mfwd_internal_t

enum ra8_eth_mfwd_internal_t : uint32_t

MFWD register offsets used by the routing programming path.

Per CMSIS R7KA8D2KF_core0.h: FWPBFCSDC00 sits at offset 0x4A04 in the MFWD register window (port 0), with each subsequent port advancing 0x10 bytes (so port 1 -> 0x4A14, port 2 -> 0x4A24). PBCSD (Port Based Forwarding CSD) is the low 7 bits.

Enumerator
k_ra8_mfwd_off_fwpbfc0_base 

FWPBFC0[0] offset.

k_ra8_mfwd_off_fwpbfcsdc0_base 

FWPBFCSDC00 offset.

k_ra8_mfwd_fwpbfcsdc_stride 

Per-port stride.

k_ra8_mfwd_pbdv_mask 

FWPBFC0.PBDV mask.

k_ra8_mfwd_pbcsd_mask 

PBCSD field mask.

k_ra8_mfwd_port_count 

Port[0] + Port[1] + host.

k_ra8_mfwd_max_port 

Highest GMAC port index.

k_ra8_mfwd_max_queue 

Highest GWCA queue.

Definition at line 124 of file ra8_eth_mfwd.c.

Function Documentation

◆ internal_mfwd_fwpbfcsdc()

volatile uint32_t * internal_mfwd_fwpbfcsdc ( uint8_t port)
inlinestatic

Return a typed pointer to FWPBFCSDC0[port] inside MFWD.

Helper that computes the register address from the MFWD base + per-port offset so the caller's body stays readable. Per project policy hardware register access is via inline accessors, never preprocessor macros.

Parameters
[in]portPort index (already bounds-checked by the caller).
Returns
Volatile pointer to the per-port routing register.
Precondition
port <= k_ra8_mfwd_max_port.
MFWD MSTP gate is on.
Postcondition
Returned pointer maps to the MFWD register window.
Returned pointer is non-null.
Note
Not thread-safe.
Since
0.1.0

Definition at line 155 of file ra8_eth_mfwd.c.

References k_ra8_mfwd_base_addr, k_ra8_mfwd_fwpbfcsdc_stride, k_ra8_mfwd_off_fwpbfcsdc0_base, and RA8_INTERNAL.

Referenced by ra8_eth_mfwd_route_queue().

◆ ra8_eth_mfwd_attach_handler()

ra8_err_t ra8_eth_mfwd_attach_handler ( ra8_eth_mfwd_event_fn_t fn,
void * ctx )
nodiscard

Attach the shared event handler.

Since
0.1.0

Definition at line 81 of file ra8_eth_mfwd.c.

References k_ra8_ok, s_mfwd_ctx, and s_mfwd_fn.

◆ ra8_eth_mfwd_clear_status()

ra8_err_t ra8_eth_mfwd_clear_status ( uint32_t mask)
nodiscard

Clear bits in MFWD_STS via MFWD_ICLR.

Since
0.1.0

Definition at line 72 of file ra8_eth_mfwd.c.

References k_ra8_ok, r_mfwd_regs_t::MFWD_ICLR, r_mfwd_regs_t::MFWD_STS, and ra8_mfwd().

◆ ra8_eth_mfwd_deinit()

ra8_err_t ra8_eth_mfwd_deinit ( void )
nodiscard

Tear down the MFWD block.

Since
0.1.0

Definition at line 53 of file ra8_eth_mfwd.c.

References k_ra8_mstp_eswm, r_mfwd_regs_t::MFWD_CTRL, r_mfwd_regs_t::MFWD_IE, ra8_mfwd(), ra8_mstp_disable(), s_mfwd_ctx, and s_mfwd_fn.

◆ ra8_eth_mfwd_dispatch()

void ra8_eth_mfwd_dispatch ( void )

Dispatch an MFWD event.

Since
0.1.0

See implementation.

Precondition
Module state is consistent.
Module state is consistent.
Postcondition
Caller-visible state matches the documented contract.
Caller-visible state matches the documented contract.
Note
Not thread-safe unless documented otherwise.

Definition at line 89 of file ra8_eth_mfwd.c.

References r_mfwd_regs_t::MFWD_ICLR, r_mfwd_regs_t::MFWD_STS, ra8_mfwd(), s_mfwd_ctx, and s_mfwd_fn.

◆ ra8_eth_mfwd_enter_stop()

ra8_err_t ra8_eth_mfwd_enter_stop ( void )
nodiscard

Put MFWD into MSTP-gated stop.

Since
0.1.0

Definition at line 103 of file ra8_eth_mfwd.c.

References k_ra8_mstp_eswm, r_mfwd_regs_t::MFWD_CTRL, ra8_mfwd(), and ra8_mstp_disable().

◆ ra8_eth_mfwd_exit_stop()

ra8_err_t ra8_eth_mfwd_exit_stop ( void )
nodiscard

Exit MSTP-gated stop.

Since
0.1.0

Definition at line 110 of file ra8_eth_mfwd.c.

References k_ra8_mstp_eswm, and ra8_mstp_enable().

◆ ra8_eth_mfwd_get_status()

ra8_err_t ra8_eth_mfwd_get_status ( uint32_t * out_mask)
nodiscard

Read the MFWD_STS status register.

Since
0.1.0

Definition at line 64 of file ra8_eth_mfwd.c.

References k_ra8_ok, r_mfwd_regs_t::MFWD_STS, RA8_CHECK_NULL_PTR, ra8_mfwd(), and s_tag.

Referenced by l3_program_forwarding().

◆ ra8_eth_mfwd_init()

ra8_err_t ra8_eth_mfwd_init ( void )
nodiscard

Initialise the MFWD block (MSTP enable + reset regs).

Since
0.1.0

Definition at line 35 of file ra8_eth_mfwd.c.

References k_ra8_mstp_eswm, k_ra8_ok, r_mfwd_regs_t::MFWD_CTRL, r_mfwd_regs_t::MFWD_ICLR, r_mfwd_regs_t::MFWD_IE, r_mfwd_regs_t::MFWD_STS, ra8_log_info, ra8_mfwd(), ra8_mstp_enable(), RA8_RETURN_ON_ERROR, and s_tag.

Referenced by l3_arm().

◆ ra8_eth_mfwd_route_queue()

ra8_err_t ra8_eth_mfwd_route_queue ( uint8_t port,
uint8_t queue_index )
nodiscard

Route inbound frames from a GMAC port into a GWCA RX queue.

Programs MFWD.FWPBFCSDC0[port].PBCSD = queue_index so the forwarding engine knows where to deliver port-to-host frames. Without this call the GWCA RX queue stays empty even when frames arrive on the wire. Per FSP r_layer3_switch_StartDescriptorQueue this MUST be programmed after the GWCA queue is in OPERATION and before the MAC is allowed to receive.

Parameters
[in]portGMAC port index (0..1 on RA8D2).
[in]queue_indexGWCA queue index that receives the frames (<= 31).
Returns
ra8_err_t Error code.
Return values
k_ra8_okRouting programmed.
k_ra8_err_invalid_argport > 1 or queue_index > 31.
Precondition
ra8_eth_mfwd_init succeeded earlier (or ra8_eth_init brought up the shared ESWM gate).
GWCA queue indicated by queue_index has been configured.
Postcondition
FWPBFCSDC0[port].PBCSD == queue_index on success.
Other bits of FWPBFCSDC0[port] preserved.
Note
Not thread-safe.
Since
0.1.0

Definition at line 177 of file ra8_eth_mfwd.c.

References internal_mfwd_fwpbfcsdc(), k_ra8_err_invalid_arg, k_ra8_mfwd_max_port, k_ra8_mfwd_max_queue, k_ra8_mfwd_pbcsd_mask, k_ra8_ok, ra8_log_error, and s_tag.

Referenced by internal_open_gwca_path(), and l3_program_forwarding().

◆ ra8_eth_mfwd_set_forwarding_masks()

ra8_err_t ra8_eth_mfwd_set_forwarding_masks ( const uint8_t port_masks[3])
nodiscard

Program the per-port forwarding-destination masks (FWPBFC0).

Sets MFWD.FWPBFC0[i].PBDV = mask for each port i in 0..2 (the two GMAC ports + the host/GWCA port). PBDV is a 7-bit bitmask of destination ports a frame received on this port is allowed to reach. Per FSP r_layer3_switch_open this must be programmed BEFORE the GWCA mode transitions (alongside FWPC10/11/12.DDE).

The simplest permissive setting is 0x7F (all destinations allowed) on every port – that lets wire-to-host RX flow through the switch without any L3 filtering.

Parameters
[in]port_masksArray of three masks: index 0 = port 0, index 1 = port 1, index 2 = host port. Caller-owned; only the values are read.
Returns
ra8_err_t Error code.
Return values
k_ra8_okMasks programmed.
k_ra8_err_null_ptrport_masks is null.
Precondition
ra8_eth_mfwd_init or board MSTP setup has run.
Each mask is 7 bits or fewer (extra bits are ignored).
Postcondition
FWPBFC0/1/2.PBDV reflect the supplied masks.
No other bits of FWPBFC0/1/2 are disturbed.
Note
Not thread-safe.
Since
0.1.0

Definition at line 163 of file ra8_eth_mfwd.c.

References k_ra8_mfwd_base_addr, k_ra8_mfwd_fwpbfcsdc_stride, k_ra8_mfwd_off_fwpbfc0_base, k_ra8_mfwd_pbdv_mask, k_ra8_mfwd_port_count, k_ra8_ok, RA8_CHECK_NULL_PTR, and s_tag.

Referenced by internal_open_gwca_path(), and l3_program_forwarding().

Variable Documentation

◆ s_mfwd_ctx

void* s_mfwd_ctx
static

◆ s_mfwd_fn

◆ s_tag

const char* s_tag = "ETHMFW"
static

Definition at line 30 of file ra8_eth_mfwd.c.