56static const char*
s_tag =
"ETH";
71typedef enum : uint8_t {
86typedef enum : uint16_t {
103typedef enum : uint32_t {
195typedef enum : uintptr_t {
313 if (*counter != UINT32_MAX) {
342 for (uint32_t i = 0U; i < n; ++i) {
543 const uint32_t mask = reg->
ESWM_STS;
659 uint16_t tx_count = 0U;
660 uint16_t rx_count = 0U;
661 uint16_t buf_size = 0U;
792 ra8_eth_link_t link = {.link_up = 0U, .speed_mbps = 0U, .full_duplex = 0U, .bmsr = 0U};
889typedef enum : uint32_t {
890 k_ra8_eth_test_ds_low_mask = 0xFFU,
891 k_ra8_eth_test_ds_high_shift = 8U,
892 k_ra8_eth_test_ds_high_mask = 0x0FU,
893} ra8_eth_test_ds_bits_t;
917static uint32_t internal_test_rx_slot(
void)
951ra8_err_t ra8_eth_test_inject_rx(
const uint8_t* payload, uint32_t len)
957 const uint32_t slot = internal_test_rx_slot();
959 uint32_t copy_len = len;
967 uint8_t*
const pool_slot =
970 desc->
ds_l = (uint8_t)(copy_len & (uint32_t)k_ra8_eth_test_ds_low_mask);
971 desc->
ds_h = (uint8_t)((copy_len >> (uint32_t)k_ra8_eth_test_ds_high_shift) &
972 (uint32_t)k_ra8_eth_test_ds_high_mask);
static const char * s_tag
Logging / check tag.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_ISR_SAFE
The function is callable from interrupt context.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_RETURN_ON_ERROR(err, tag, message)
Early return on error, propagating the code upward.
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
Error Code Definitions for ra8-firmware.
@ k_ra8_err_no_data
No application data available (e.g.
@ k_ra8_err_invalid_arg
Invalid function argument.
@ k_ra8_err_not_initialized
Module not initialized – _init() not yet called successfully.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
static ra8_gwca_basic_descriptor_t s_linkfix_table[k_ra8_eth_linkfix_count]
Static LINKFIX table covering RX + TX queues + slack.
static ra8_eth_event_fn_t s_eth_fn
Attached ESWM event callback (nullptr if none).
eth_fwpbfc_t
Per-port FWPBFC filter mask (7-bit).
@ k_eth_fwpbfc_mask
Ethernet fwpbfc mask.
static ra8_gwca_ext_descriptor_t s_tx_chain[k_ra8_eth_tx_ring_depth]
Static TX descriptor chain (BSS, 16-byte aligned).
ra8_err_t ra8_eth_enter_stop(void)
Put the ethernet switch into MSTP-gated stop.
ra8_rmac_port_t priv_ra8_eth_channel_to_port(uint8_t channel)
Map a logical channel index to an RMAC port identifier.
ra8_err_t ra8_eth_get_status(uint32_t *out_mask)
Read the ESWM_STS status register.
ra8_err_t ra8_eth_close(void)
Close the NIC: gate clocks and idle the descriptor rings.
static ra8_eth_gwca_default_state_t s_gwca_state
GWCA default-state block backing ra8_eth_open / write / read.
static ra8_gwca_basic_descriptor_t s_rx_chain[k_ra8_eth_rx_ring_depth]
Static RX descriptor chain (BSS, 16-byte aligned).
static ra8_err_t internal_open_prep(const ra8_eth_cfg_t *cfg)
Validate cfg, resolve ring sizes, and bring up MSTP + RMAC.
static void internal_capture_state(const ra8_eth_cfg_t *cfg)
Capture cfg into s_eth_state and reset the counters.
ra8_eth_step_t
Step values bumped through g_ra8_eth_open_step for bench-side post-mortem via J-Link mem32.
@ k_ra8_eth_step_fail_3
RA8 Ethernet step fail 3.
@ k_ra8_eth_step_ok_4
RA8 Ethernet step ok 4.
@ k_ra8_eth_step_fail_4
RA8 Ethernet step fail 4.
@ k_ra8_eth_step_fail_1
RA8 Ethernet step fail 1.
@ k_ra8_eth_step_ok_3
RA8 Ethernet step ok 3.
@ k_ra8_eth_step_ok_2
RA8 Ethernet step ok 2.
@ k_ra8_eth_step_ok_1
RA8 Ethernet step ok 1.
ra8_err_t ra8_eth_get_stats(ra8_eth_stats_t *out_stats)
Read the NIC software counters.
ra8_err_t ra8_eth_exit_stop(void)
Exit MSTP-gated stop.
static void internal_stat_inc(uint32_t *counter)
Saturating-add helper for the 32-bit software counters.
static uint8_t s_rx_pool_storage[k_ra8_eth_num_rx_desc *k_ra8_eth_buf_size]
Static RX buffer pool, one k_ra8_eth_buf_size slice per slot.
static ra8_err_t internal_resolve_sizes(const ra8_eth_cfg_t *cfg, uint16_t *tx_count, uint16_t *rx_count, uint16_t *buf_size)
Validate the cfg ring sizes and resolve zero-as-default values.
void ra8_eth_dispatch(void)
Dispatch an ESWM event – snapshot + fire callback.
ra8_eth_state_t s_eth_state
Singleton NIC runtime state.
volatile uint32_t g_ra8_eth_open_step
Bench-side debug trail – bumped by ra8_eth_open to record the highest open-sub-step the chip reached ...
ra8_err_t ra8_eth_write(const uint8_t *buf, uint32_t len)
Transmit a frame through the GWCA TX queue.
static uint8_t s_tx_pool_storage[k_ra8_eth_num_tx_desc *k_ra8_eth_buf_size]
Static TX buffer pool, one k_ra8_eth_buf_size slice per slot.
static void * s_eth_ctx
Opaque cookie passed to s_eth_fn on dispatch.
ra8_eth_host_pool_layout_t
Host-test pool addresses in the fake mmap'd SRAM region.
@ k_ra8_eth_host_tx_pool_addr
Host TX pool base.
@ k_ra8_eth_host_rx_pool_addr
Host RX pool base.
ra8_eth_layout_t
Static layout constants for the GWCA-backed NIC rings.
@ k_ra8_eth_tx_ring_depth
+1 LINK term.
@ k_ra8_eth_linkfix_count
LINKFIX entries.
@ k_ra8_eth_rx_ring_depth
+1 LINK term.
@ k_ra8_eth_def_tx_q_idx
TX LINKFIX index.
@ k_ra8_eth_def_rx_q_idx
RX LINKFIX index.
bool g_eth_mac_speed_resynced
Latch – true once ra8_eth_link_status has re-programmed MPIC.LSC / MPIC.PIPP to match the PHY's negot...
static ra8_err_t internal_bring_up_rmac(const ra8_eth_cfg_t *cfg)
Bring the per-channel RMAC port up and program the MAC address.
ra8_err_t ra8_eth_open(const ra8_eth_cfg_t *cfg)
Open the NIC: bring up the controller stack and the descriptor rings.
void ra8_eth_attach_handler(ra8_eth_event_fn_t fn, void *ctx)
Replace the shared Ethernet event callback.
static uint8_t * internal_eth_rx_pool(void)
Resolve the RX buffer pool pointer for the current build.
ra8_err_t ra8_eth_deinit(void)
Tear down the ESWM block.
static void internal_populate_gwca_state(const ra8_eth_cfg_t *cfg)
Populate s_gwca_state with the static rings + pools + queue indices.
ra8_err_t ra8_eth_init(void)
Initialise the ESWM block (MSTP enable + reset regs).
static uint8_t * internal_eth_tx_pool(void)
Resolve the TX buffer pool pointer for the current build.
ra8_err_t ra8_eth_read(uint8_t *buf, uint32_t max_len, uint32_t *got_len)
Pop the next received frame from the RX descriptor ring.
static void internal_byte_copy(uint8_t *dst, const uint8_t *src, uint32_t n)
Bytewise-copy n bytes from src into dst.
static ra8_err_t internal_open_gwca_path(void)
Walk the GWCA bring-up + MFWD routing setup for ra8_eth_open.
ra8_err_t ra8_eth_clear_status(uint32_t mask)
Clear bits in ESWM_STS via ESWM_ICLR.
Ethernet Switch Module (ESWM) + frame TX/RX driver.
void(* ra8_eth_event_fn_t)(void *ctx, uint32_t status_mask)
Ethernet switch event callback.
ra8_err_t ra8_eth_link_status(ra8_eth_link_t *out_status)
Query the PHY link state via MIIM (RMAC MDIO Clause-22).
@ k_ra8_eth_buf_size
Per-descriptor buffer size in bytes.
@ k_ra8_eth_max_frame
Maximum 802.3 untagged frame.
@ k_ra8_eth_num_rx_desc
Number of RX descriptors in the ring.
@ k_ra8_eth_mac_len
Length of an Ethernet MAC address.
@ k_ra8_eth_num_tx_desc
Number of TX descriptors in the ring.
@ k_ra8_eth_min_frame
Minimum 802.3 frame (excl.
Ethernet CPU Agent (GWCA) driver.
ra8_err_t ra8_eth_gwca_default_open(ra8_eth_gwca_default_state_t *state)
One-call GWCA bring-up: install LINKFIX, configure RX + TX, OPERATION.
ra8_err_t ra8_eth_gwca_deinit(void)
Tear down GWCA.
ra8_err_t ra8_eth_gwca_default_recv(ra8_eth_gwca_default_state_t *state, uint8_t *out_frame, uint32_t out_capacity, uint32_t *out_len)
One-call RX: dequeue next frame from state->rx_chain.
ra8_err_t ra8_eth_gwca_set_operation_mode(ra8_gwmc_opc_t mode)
Transition the GWCA / ESWM state machine to a new OPC mode.
ra8_err_t ra8_eth_gwca_default_send(ra8_eth_gwca_default_state_t *state, const uint8_t *frame, uint32_t len)
One-call TX: enqueue frame on state->tx_chain + kick.
Cross-TU shared surface for the ra8_eth driver split.
Ethernet Message Forwarding Engine (MFWD) driver.
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.
Per-port Ethernet Agent (ETHA) driver – HUM Ch 32 (p 1627-1702).
ra8_err_t ra8_etha_set_mode(ra8_etha_port_t port, ra8_etha_opc_t mode)
Issue an explicit EAMC mode-change command.
Ethernet Agent (ETHA) per-port register layout for the RA8D2.
ra8_etha_port_t
ETHA port index (m = 0, 1).
@ k_ra8_etha_port_0
ETHA port 0 (base 0x403C_A000).
@ k_ra8_etha_port_1
ETHA port 1 (base 0x403C_C000).
@ k_ra8_etha_opc_operation
Enter OPERATION mode.
@ k_ra8_etha_opc_config
Enter CONFIG mode.
@ k_ra8_etha_opc_disable
Enter DISABLE mode.
Ethernet controller base addresses for the Renesas RA8D2.
@ k_ra8_gwdcc_dt_fsingle
FSINGLE – single-fragment frame.
@ k_ra8_gwmc_opc_disable
DR: Disable request.
static volatile r_eswm_regs_t * ra8_eswm(void)
Get pointer to the ESWM register block.
Lightweight Logging Interface for ra8-firmware.
#define ra8_log_info(tag, message)
RA8 log info.
#define ra8_log_error(tag, message)
RA8 log error.
Ref-counted Module Stop Control wrapper for the RA8D2.
ra8_err_t ra8_mstp_enable(ra8_mstp_t id)
Reference-counted "ungate this peripheral" request.
ra8_err_t ra8_mstp_disable(ra8_mstp_t id)
Reference-counted "gate this peripheral" request.
Module Stop Control (MSTP) register layout for the Renesas RA8D2.
@ k_ra8_mstp_eswm
MSTPC30 ESWM.
Per-port Ethernet MAC (RMAC) driver – HUM Ch 33.
ra8_err_t ra8_rmac_deinit(ra8_rmac_port_t port)
Tear down an RMAC port.
ra8_err_t ra8_rmac_set_mac_address(ra8_rmac_port_t port, const uint8_t mac[k_ra8_rmac_mac_byte_count])
Program the reception MAC address (MRMAC0 / MRMAC1).
Ethernet MAC (RMAC) per-port register layout for the RA8D2.
ra8_rmac_port_t
RMAC port index (m = 0, 1).
@ k_ra8_rmac_port_1
RMAC port 1 (base 0x403C_D000).
@ k_ra8_rmac_port_0
RMAC port 0 (base 0x403C_B000).
SysTick-based tick counter, delay and timestamp helpers.
Minimal Ethernet Switch Module (ESWM) register window.
volatile uint32_t ESWM_CTRL
+0x00 Control.
volatile uint32_t ESWM_STS
+0x04 Status.
volatile uint32_t ESWM_IE
+0x08 Interrupt Enable.
volatile uint32_t ESWM_ICLR
+0x0C Interrupt Clear.
Per-channel NIC configuration.
uint16_t buffer_size
Buffer size per descriptor.
uint8_t mac_address[6]
Local MAC address (octets 0..5).
uint8_t channel
Logical channel index (0..1).
uint16_t num_tx_descriptors
Active TX descriptors (<=8, 0=def).
uint16_t num_rx_descriptors
Active RX descriptors (<=8, 0=def).
State block for ra8_eth_gwca_default_open / _send / _recv.
Driver-private NIC state.
8-byte basic descriptor (HUM Ch 34.5.1.2 "General Formats").
volatile uint8_t dt
20..23 Descriptor type (ra8_gwdcc_dt_t).
volatile uint8_t ds_h
8..11 Descriptor size (high nibble).
volatile uint8_t ds_l
0..7 Descriptor size (low byte).
16-byte extended descriptor (HUM Ch 34.5.1.2 "Extended descriptor", GWDCCi.ETS == 0 && GWDCCi....