ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_eth_mfwd.c
Go to the documentation of this file.
1
17
18#include "ra8_eth_mfwd.h"
19
20#include <stdint.h>
21
22#include "ra8_attributes.h"
23#include "ra8_check.h"
24#include "ra8_err.h"
25#include "ra8_ether_regs.h"
26#include "ra8_log.h"
27#include "ra8_mstp.h"
28#include "ra8_mstp_regs.h"
29
30static const char* s_tag = "ETHMFW";
31
33static void* s_mfwd_ctx;
34
36{
37 /* HUM Ch 11.2.8 "MSTPCRC : Module Stop Control Register C" p 446 */
39 /* GCOVR_EXCL_BR_START -- MSTP HW readback */
40 RA8_RETURN_ON_ERROR(mst_err, s_tag, "mfwd_init: mstp enable");
41 /* GCOVR_EXCL_BR_STOP */
42
43 volatile r_mfwd_regs_t* reg = ra8_mfwd();
44 /* HUM Ch 30 "Ethernet Message Forwarding Engine (MFWD)" p 1321 */
45 reg->MFWD_CTRL = 0U;
46 reg->MFWD_STS = 0U;
47 reg->MFWD_IE = 0U;
48 reg->MFWD_ICLR = 0U;
49 ra8_log_info(s_tag, "mfwd_init");
50 return k_ra8_ok;
51}
52
54{
55 volatile r_mfwd_regs_t* reg = ra8_mfwd();
56 /* HUM Ch 30 "Ethernet Message Forwarding Engine (MFWD)" p 1321 */
57 reg->MFWD_CTRL = 0U;
58 reg->MFWD_IE = 0U;
59 s_mfwd_fn = nullptr;
60 s_mfwd_ctx = nullptr;
62}
63
65{
66 RA8_CHECK_NULL_PTR(out_mask, s_tag, "out_mask must not be nullptr");
67 /* HUM Ch 30 "Ethernet Message Forwarding Engine (MFWD)" p 1321 */
68 *out_mask = ra8_mfwd()->MFWD_STS;
69 return k_ra8_ok;
70}
71
73{
74 volatile r_mfwd_regs_t* reg = ra8_mfwd();
75 /* HUM Ch 30 "Ethernet Message Forwarding Engine (MFWD)" p 1321 */
76 reg->MFWD_ICLR = mask;
77 reg->MFWD_STS = reg->MFWD_STS & ~mask;
78 return k_ra8_ok;
79}
80
87
90{
91 volatile r_mfwd_regs_t* reg = ra8_mfwd();
92 /* HUM Ch 30 "Ethernet Message Forwarding Engine (MFWD)" p 1321 */
93 const uint32_t mask = reg->MFWD_STS;
95 void* const ctx = s_mfwd_ctx;
96 reg->MFWD_ICLR = mask;
97 reg->MFWD_STS = 0U;
98 if (fn != nullptr) {
99 fn(ctx, mask);
100 }
101}
102
104{
105 /* HUM Ch 30 "Ethernet Message Forwarding Engine (MFWD)" p 1321 */
106 ra8_mfwd()->MFWD_CTRL = 0U;
108}
109
114
134
155RA8_INTERNAL static inline volatile uint32_t* internal_mfwd_fwpbfcsdc(uint8_t port)
156{
157 const uintptr_t addr =
158 (uintptr_t)k_ra8_mfwd_base_addr +
159 (uintptr_t)(k_ra8_mfwd_off_fwpbfcsdc0_base + ((uint32_t)port * k_ra8_mfwd_fwpbfcsdc_stride));
160 return (volatile uint32_t*)addr;
161}
162
164{
165 RA8_CHECK_NULL_PTR(port_masks, s_tag, "set_forwarding_masks: null arg");
166 for (uint32_t i = 0U; i < (uint32_t)k_ra8_mfwd_port_count; ++i) {
167 /* HUM Ch 30 "Ethernet Message Forwarding Engine (MFWD)" p 1321 */
168 volatile uint32_t* const reg =
169 (volatile uint32_t*)(k_ra8_mfwd_base_addr + (uintptr_t)(k_ra8_mfwd_off_fwpbfc0_base +
171 const uint32_t cur = *reg & ~(uint32_t)k_ra8_mfwd_pbdv_mask;
172 *reg = cur | ((uint32_t)port_masks[i] & (uint32_t)k_ra8_mfwd_pbdv_mask);
173 }
174 return k_ra8_ok;
175}
176
177ra8_err_t ra8_eth_mfwd_route_queue(uint8_t port, uint8_t queue_index)
178{
179 if ((port > (uint8_t)k_ra8_mfwd_max_port) || (queue_index > (uint8_t)k_ra8_mfwd_max_queue)) {
180 ra8_log_error(s_tag, "mfwd_route_queue: invalid port or queue");
182 }
183 /* FWPBFCSDC0[port].PBCSD -- port-to-host queue routing. */
184 /* HUM Ch 30 "Ethernet Message Forwarding Engine (MFWD)" p 1321 */
185 volatile uint32_t* reg = internal_mfwd_fwpbfcsdc(port);
186 const uint32_t val = (*reg & ~(uint32_t)k_ra8_mfwd_pbcsd_mask) |
187 ((uint32_t)queue_index & (uint32_t)k_ra8_mfwd_pbcsd_mask);
188 *reg = val;
189 return k_ra8_ok;
190}
static const char * s_tag
Logging / check tag.
Definition ra8_app.c:17
Annotation-attribute framework macros for ra8-firmware.
#define RA8_HW_REGISTER_ACCESS
Mark an MMIO accessor function (returns volatile register pointer).
#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.
Definition ra8_check.h:184
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
Definition ra8_check.h:243
Error Code Definitions for ra8-firmware.
@ k_ra8_err_invalid_arg
Invalid function argument.
Definition ra8_err.h:152
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
ra8_err_t ra8_eth_mfwd_set_forwarding_masks(const uint8_t port_masks[3])
Program the per-port forwarding-destination masks (FWPBFC0).
static volatile uint32_t * internal_mfwd_fwpbfcsdc(uint8_t port)
Return a typed pointer to FWPBFCSDC0[port] inside MFWD.
void ra8_eth_mfwd_dispatch(void)
Dispatch an MFWD event.
static void * s_mfwd_ctx
ra8_err_t ra8_eth_mfwd_attach_handler(ra8_eth_mfwd_event_fn_t fn, void *ctx)
Attach the shared event handler.
ra8_err_t ra8_eth_mfwd_init(void)
Initialise the MFWD block (MSTP enable + reset regs).
ra8_eth_mfwd_internal_t
MFWD register offsets used by the routing programming path.
@ k_ra8_mfwd_pbdv_mask
FWPBFC0.PBDV mask.
@ k_ra8_mfwd_max_queue
Highest GWCA queue.
@ k_ra8_mfwd_fwpbfcsdc_stride
Per-port stride.
@ k_ra8_mfwd_max_port
Highest GMAC port index.
@ k_ra8_mfwd_pbcsd_mask
PBCSD field mask.
@ k_ra8_mfwd_off_fwpbfcsdc0_base
FWPBFCSDC00 offset.
@ k_ra8_mfwd_port_count
Port[0] + Port[1] + host.
@ k_ra8_mfwd_off_fwpbfc0_base
FWPBFC0[0] offset.
ra8_err_t ra8_eth_mfwd_exit_stop(void)
Exit MSTP-gated stop.
ra8_err_t ra8_eth_mfwd_deinit(void)
Tear down the MFWD block.
static ra8_eth_mfwd_event_fn_t s_mfwd_fn
ra8_err_t ra8_eth_mfwd_enter_stop(void)
Put MFWD into MSTP-gated stop.
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.
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_get_status(uint32_t *out_mask)
Read the MFWD_STS status register.
Ethernet Message Forwarding Engine (MFWD) driver.
void(* ra8_eth_mfwd_event_fn_t)(void *ctx, uint32_t status_mask)
MFWD event callback.
Ethernet controller base addresses for the Renesas RA8D2.
@ k_ra8_mfwd_base_addr
RA8 mfwd base address.
static volatile r_mfwd_regs_t * ra8_mfwd(void)
Get pointer to the MFWD register block.
Lightweight Logging Interface for ra8-firmware.
#define ra8_log_info(tag, message)
RA8 log info.
Definition ra8_log.h:364
#define ra8_log_error(tag, message)
RA8 log error.
Definition ra8_log.h:335
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.
Definition ra8_mstp.c:343
ra8_err_t ra8_mstp_disable(ra8_mstp_t id)
Reference-counted "gate this peripheral" request.
Definition ra8_mstp.c:382
Module Stop Control (MSTP) register layout for the Renesas RA8D2.
@ k_ra8_mstp_eswm
MSTPC30 ESWM.
Minimal Message Forwarding Engine (MFWD) register window.
volatile uint32_t MFWD_ICLR
+0x0C Interrupt Clear.
volatile uint32_t MFWD_STS
+0x04 Status.
volatile uint32_t MFWD_CTRL
+0x00 Forwarding Control.
volatile uint32_t MFWD_IE
+0x08 Interrupt Enable.