ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_eth.c
Go to the documentation of this file.
1
31
32#include "ra8_eth.h"
33
34#include <stdint.h>
35
36#include "ra8_attributes.h"
37#include "ra8_check.h"
38#include "ra8_err.h"
39#include "ra8_eth_gwca.h"
40#include "ra8_eth_internal.h"
41#include "ra8_eth_mfwd.h"
42#include "ra8_etha.h"
43#include "ra8_etha_regs.h"
44#include "ra8_ether_regs.h"
45#include "ra8_log.h"
46#include "ra8_mstp.h"
47#include "ra8_mstp_regs.h"
48#include "ra8_rmac.h"
49#include "ra8_rmac_regs.h"
50#include "ra8_time.h"
51
56static const char* s_tag = "ETH";
57
63
68static void* s_eth_ctx;
69
71typedef enum : uint8_t {
74
93
112
126
138
154
155#ifndef UNIT_TEST
171
182#endif /* UNIT_TEST */
183
195typedef enum : uintptr_t {
199
217static inline uint8_t* internal_eth_rx_pool(void)
218{
219#ifdef UNIT_TEST
220 return (uint8_t*)k_ra8_eth_host_rx_pool_addr;
221#else
222 return s_rx_pool_storage;
223#endif
224}
225
243static inline uint8_t* internal_eth_tx_pool(void)
244{
245#ifdef UNIT_TEST
246 return (uint8_t*)k_ra8_eth_host_tx_pool_addr;
247#else
248 return s_tx_pool_storage;
249#endif
250}
251
265
278
295
311static inline void internal_stat_inc(uint32_t* counter)
312{
313 if (*counter != UINT32_MAX) {
314 *counter += 1U;
315 }
316}
317
340static inline void internal_byte_copy(uint8_t* dst, const uint8_t* src, uint32_t n)
341{
342 for (uint32_t i = 0U; i < n; ++i) {
343 dst[i] = src[i];
344 }
345}
346
348{
349 if (channel == 0U) {
350 return k_ra8_rmac_port_0;
351 }
352 return k_ra8_rmac_port_1;
353}
354
378 uint16_t* tx_count,
379 uint16_t* rx_count,
380 uint16_t* buf_size)
381{
382 uint16_t tx = cfg->num_tx_descriptors;
383 uint16_t rx = cfg->num_rx_descriptors;
384 uint16_t bs = cfg->buffer_size;
385 if (tx == 0U) {
387 }
388 if (rx == 0U) {
390 }
391 if (bs == 0U) {
393 }
394 if (tx > k_ra8_eth_num_tx_desc) {
396 }
397 if (rx > k_ra8_eth_num_rx_desc) {
399 }
400 if ((bs < k_ra8_eth_min_frame) || (bs > k_ra8_eth_buf_size)) {
402 }
403 *tx_count = tx;
404 *rx_count = rx;
405 *buf_size = bs;
406 return k_ra8_ok;
407}
408
427{
428 /* The board-level ``ra8_board_ethernet_init`` (or its equivalent for
429 * non-EK boards) is expected to have already programmed RMAC's MPIC
430 * (PIS / LSC / PIPP / PSMCS), enabled the MSTP gate, and brought the
431 * matching ETHA into OPERATION mode. Overwriting MPIC here would
432 * clobber the carefully-computed MDC clock divider (PSMCS) and force
433 * the wrong PHY interface mode (MII instead of RGMII). The only
434 * RMAC-level state ``ra8_eth_open`` still has to programme is the
435 * MAC address the application chose.
436 *
437 * HUM Ch 33.4 "MRMAC0 / MRMAC1" p 1707 -- the MAC address registers
438 * are paired with MPIC under the same write-once gate: silent on
439 * MAC writes while ETHA is in OPERATION. Bench-confirmed on
440 * EK-RA8D2: without the DISABLE -> CONFIG -> {MAC write} -> DISABLE
441 * -> OPERATION bracket, MRMAC0 / MRMAC1 read back as 0 after
442 * ra8_eth_open completes, and every wire-side ARP "who-has 192.168.
443 * .1.42" gets dropped at the RMAC perfect-match comparator before
444 * the GWCA descriptor ring ever sees it.
445 *
446 * The board layer ran the bracket once during ra8_rmac_init; we have
447 * to repeat it here so the application-supplied MAC actually lands
448 * in MRMAC0/MRMAC1. */
450 const ra8_etha_port_t etha_port =
452 uint8_t mac_copy[k_ra8_eth_mac_len];
453 for (uint8_t i = 0U; i < (uint8_t)k_ra8_eth_mac_len; ++i) {
454 mac_copy[i] = cfg->mac_address[i];
455 }
456
457 /* HUM Ch 32.3.1.1 "EAMC : Mode Command Register" p 1631 -- ETHA
458 * mode-transition sequence. DISABLE before CONFIG so the ESWM
459 * accepts the request even if the port was already in OPERATION. */
461 if (err != k_ra8_ok) {
462 return err;
463 }
465 if (err != k_ra8_ok) {
466 return err;
467 }
468
469 /* HUM Ch 33.4 "MRMAC0 / MRMAC1" p 1707 -- writes only stick while
470 * the paired ETHA is in CONFIG. */
471 const ra8_err_t mac_err = ra8_rmac_set_mac_address(rmac_port, mac_copy);
472
473 /* Always return to OPERATION even on MAC write failure so the chip
474 * doesn't end up parked in CONFIG. */
475 const ra8_err_t dis_err = ra8_etha_set_mode(etha_port, k_ra8_etha_opc_disable);
476 const ra8_err_t op_err = ra8_etha_set_mode(etha_port, k_ra8_etha_opc_operation);
477 if (mac_err != k_ra8_ok) {
478 return mac_err;
479 }
480 if (dis_err != k_ra8_ok) {
481 return dis_err;
482 }
483 return op_err;
484}
485
487{
488 /* HUM Ch 11.2.8 "MSTPCRC : Module Stop Control Register C" p 446 */
490 /* GCOVR_EXCL_BR_START -- MSTP HW readback */
491 RA8_RETURN_ON_ERROR(mst_err, s_tag, "eth_init: mstp enable");
492 /* GCOVR_EXCL_BR_STOP */
493
494 volatile r_eswm_regs_t* reg = ra8_eswm();
495 /* HUM Ch 29 "Layer 3 Ethernet Switch Module (ESWM)" p 1287 */
496 reg->ESWM_CTRL = 0U;
497 reg->ESWM_STS = 0U;
498 reg->ESWM_IE = 0U;
499 reg->ESWM_ICLR = 0U;
500 ra8_log_info(s_tag, "eth_init (ESWM)");
501 return k_ra8_ok;
502}
503
505{
506 volatile r_eswm_regs_t* reg = ra8_eswm();
507 /* HUM Ch 29 "Layer 3 Ethernet Switch Module (ESWM)" p 1287 */
508 reg->ESWM_CTRL = 0U;
509 reg->ESWM_IE = 0U;
510 s_eth_fn = nullptr;
511 s_eth_ctx = nullptr;
513}
514
515ra8_err_t ra8_eth_get_status(uint32_t* out_mask)
516{
517 RA8_CHECK_NULL_PTR(out_mask, s_tag, "out_mask must not be nullptr");
518 /* HUM Ch 29 "Layer 3 Ethernet Switch Module (ESWM)" p 1287 */
519 *out_mask = ra8_eswm()->ESWM_STS;
520 return k_ra8_ok;
521}
522
524{
525 volatile r_eswm_regs_t* reg = ra8_eswm();
526 /* HUM Ch 29 "Layer 3 Ethernet Switch Module (ESWM)" p 1287 */
527 reg->ESWM_ICLR = mask;
528 reg->ESWM_STS = reg->ESWM_STS & ~mask;
529 return k_ra8_ok;
530}
531
533{
534 s_eth_fn = fn;
535 s_eth_ctx = ctx;
536}
537
540{
541 volatile r_eswm_regs_t* reg = ra8_eswm();
542 /* HUM Ch 29 "Layer 3 Ethernet Switch Module (ESWM)" p 1287 */
543 const uint32_t mask = reg->ESWM_STS;
544 const ra8_eth_event_fn_t fn = s_eth_fn;
545 void* const ctx = s_eth_ctx;
546 reg->ESWM_ICLR = mask;
547 reg->ESWM_STS = 0U;
548 if (fn != nullptr) {
549 fn(ctx, mask);
550 }
551}
552
554{
555 /* HUM Ch 29 "Layer 3 Ethernet Switch Module (ESWM)" p 1287 */
556 ra8_eswm()->ESWM_CTRL = 0U;
558}
559
564
565/* -----------------------------------------------------------------------
566 * Frame-level NIC API.
567 * -------------------------------------------------------------------- */
568
585{
586 s_eth_state.opened = 1U;
587 s_eth_state.cfg = *cfg;
588 s_eth_state.stats.tx_ok = 0U;
589 s_eth_state.stats.rx_ok = 0U;
590 s_eth_state.stats.tx_err = 0U;
591 s_eth_state.stats.rx_err = 0U;
592}
593
610{
611 s_gwca_state.linkfix_table = s_linkfix_table;
612 s_gwca_state.linkfix_count = (uint32_t)k_ra8_eth_linkfix_count;
613 s_gwca_state.rx_chain = s_rx_chain;
614 s_gwca_state.rx_depth = (uint32_t)k_ra8_eth_rx_ring_depth;
615 s_gwca_state.rx_slot_bytes = (uint32_t)k_ra8_eth_buf_size;
617 s_gwca_state.rx_queue_index = (uint32_t)k_ra8_eth_def_rx_q_idx;
618 s_gwca_state.rx_head = 0U;
619 s_gwca_state.tx_chain = s_tx_chain;
620 s_gwca_state.tx_depth = (uint32_t)k_ra8_eth_tx_ring_depth;
621 s_gwca_state.tx_slot_bytes = (uint32_t)k_ra8_eth_buf_size;
623 s_gwca_state.tx_queue_index = (uint32_t)k_ra8_eth_def_tx_q_idx;
624 s_gwca_state.tx_tail = 0U;
625 s_gwca_state.mac_port = cfg->channel;
626}
627
654{
655 if (cfg->channel > 1U) {
656 ra8_log_error(s_tag, "open: channel out of range");
658 }
659 uint16_t tx_count = 0U;
660 uint16_t rx_count = 0U;
661 uint16_t buf_size = 0U;
662 const ra8_err_t resolve_rc = internal_resolve_sizes(cfg, &tx_count, &rx_count, &buf_size);
663 if (resolve_rc != k_ra8_ok) {
664 return resolve_rc;
665 }
667 if (mst_err != k_ra8_ok) {
668 return mst_err;
669 }
670 return internal_bring_up_rmac(cfg);
671}
672
691volatile uint32_t g_ra8_eth_open_step;
692
724{
725 /* Note: ``ra8_board_ethernet_init`` already runs its own COMA reset
726 * (RR pulse + RCEC|ACE enable) via ``internal_eth_coma_reset`` --
727 * the full FSP CABPIRM.BPIOG/BPR handshake is intentionally skipped
728 * there because BPR never asserts on EK-RA8D2 silicon unless GWCA
729 * is also being brought up, and the board can't depend on that. */
730
731 /* Per FSP r_layer3_switch_open: program the per-port forwarding
732 * destination masks BEFORE bringing the GWCA up. 0x7F = allow all
733 * destinations (permissive baseline; tightens once L3 filtering
734 * lands). */
735 static const uint8_t local_fwpbfc_masks[3] = {k_eth_fwpbfc_mask,
738 (void)ra8_eth_mfwd_set_forwarding_masks(local_fwpbfc_masks);
739
741 if (err != k_ra8_ok) {
743 return err;
744 }
746 const ra8_err_t mfwd_err =
747 ra8_eth_mfwd_route_queue(s_gwca_state.mac_port, (uint8_t)s_gwca_state.rx_queue_index);
748 if (mfwd_err != k_ra8_ok) {
750 return mfwd_err;
751 }
753 return k_ra8_ok;
754}
755
757{
758 RA8_CHECK_NULL_PTR(cfg, s_tag, "open: cfg must not be nullptr");
759
761 const ra8_err_t prep_rc = internal_open_prep(cfg);
762 if (prep_rc != k_ra8_ok) {
764 return prep_rc;
765 }
767
770
771 const ra8_err_t bring_up_rc = internal_open_gwca_path();
772 if (bring_up_rc != k_ra8_ok) {
773 return bring_up_rc;
774 }
775
776 /* Force a fresh MPIC re-sync on the next ::ra8_eth_link_status call
777 * so the on-chip RMAC's MPIC.LSC matches whatever speed the PHY
778 * actually negotiated (HUM Ch 33.4.1.2 "MPIC : PHY Interfaces
779 * Configuration Register" p 1707). */
781
783
784 /* Bench-confirmed (issue #1 follow-up): leaving MPIC.PIS at the
785 * default GMII (1000mbit) configured by ra8_board_ethernet_init
786 * silently drops every RX frame when the actual link auto-
787 * negotiates to 100 Mbps. The PIS must match the *internal* xMII
788 * timing (MII for 10/100, GMII for 1G). Force a resync at the end
789 * of open so the MAC is ready for RX before the IP stack hits the
790 * driver -- without it MRGFCE stays at zero until something else
791 * calls ra8_eth_link_status, which NetX never does at boot. */
792 ra8_eth_link_t link = {.link_up = 0U, .speed_mbps = 0U, .full_duplex = 0U, .bmsr = 0U};
793 (void)ra8_eth_link_status(&link);
794
795 ra8_log_info(s_tag, "eth_open: gwca rings ready");
796 return k_ra8_ok;
797}
798
800{
801 if (s_eth_state.opened == 0U) {
803 }
804
805 /* Park the GWCA state machine in DISABLE. Best-effort -- ignore
806 * the err so teardown always reaches the MSTP-gate balance below.
807 * HUM Ch 34.3.1 "GWMC : Mode Configuration Register" p 1797 */
809
810 /* Tear down the local RMAC port (MSTP-gate ref-counted). */
811 const ra8_rmac_port_t rmac_port = priv_ra8_eth_channel_to_port(s_eth_state.cfg.channel);
812 (void)ra8_rmac_deinit(rmac_port);
813
814 /* Balance the second ESWM-MSTP enable that ::ra8_eth_gwca_default_open
815 * acquired via ::ra8_eth_gwca_init. The first enable, owned by
816 * ::internal_open_prep, is balanced by the final ra8_mstp_disable
817 * call below. */
818 (void)ra8_eth_gwca_deinit();
819
820 s_eth_state.opened = 0U;
823}
824
825ra8_err_t ra8_eth_write(const uint8_t* buf, uint32_t len)
826{
827 RA8_CHECK_NULL_PTR(buf, s_tag, "write: buf must not be nullptr");
828 if (s_eth_state.opened == 0U) {
830 }
831 if ((len < k_ra8_eth_min_frame) || (len > k_ra8_eth_max_frame)) {
832 ra8_log_error(s_tag, "write: frame length out of range");
834 }
835
836 const ra8_err_t err = ra8_eth_gwca_default_send(&s_gwca_state, buf, len);
837 if (err == k_ra8_ok) {
838 internal_stat_inc(&s_eth_state.stats.tx_ok);
839 return k_ra8_ok;
840 }
841 internal_stat_inc(&s_eth_state.stats.tx_err);
842 return err;
843}
844
845ra8_err_t ra8_eth_read(uint8_t* buf, uint32_t max_len, uint32_t* got_len)
846{
847 RA8_CHECK_NULL_PTR(buf, s_tag, "read: buf must not be nullptr");
848 RA8_CHECK_NULL_PTR(got_len, s_tag, "read: got_len must not be nullptr");
849 if (s_eth_state.opened == 0U) {
851 }
852 if (max_len == 0U) {
854 }
855
856 const ra8_err_t err = ra8_eth_gwca_default_recv(&s_gwca_state, buf, max_len, got_len);
857 if (err == k_ra8_ok) {
858 internal_stat_inc(&s_eth_state.stats.rx_ok);
859 return k_ra8_ok;
860 }
861 internal_stat_inc(&s_eth_state.stats.rx_err);
862 if (err == k_ra8_err_no_data) {
863 *got_len = 0U;
864 return k_ra8_err_no_data;
865 }
866 return err;
867}
868
870{
871 RA8_CHECK_NULL_PTR(out_stats, s_tag, "get_stats: out must not be nullptr");
872 if (s_eth_state.opened == 0U) {
874 }
875 *out_stats = s_eth_state.stats;
876 return k_ra8_ok;
877}
878
879#ifdef UNIT_TEST
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;
894
917static uint32_t internal_test_rx_slot(void)
918{
919 const uint32_t data_slots = s_gwca_state.rx_depth - 1U;
920 return s_gwca_state.rx_head % data_slots;
921}
922
951ra8_err_t ra8_eth_test_inject_rx(const uint8_t* payload, uint32_t len)
952{
953 RA8_CHECK_NULL_PTR(payload, s_tag, "test_inject_rx: payload nullptr");
954 if (s_eth_state.opened == 0U) {
956 }
957 const uint32_t slot = internal_test_rx_slot();
959 uint32_t copy_len = len;
960 if (copy_len > (uint32_t)k_ra8_eth_buf_size) {
961 copy_len = (uint32_t)k_ra8_eth_buf_size;
962 }
963 /* The descriptor's PTR was set by ::ra8_eth_gwca_attach_buffers
964 * during open. ::internal_eth_rx_pool returns the same low-address
965 * (or BSS-on-chip) base; copy the payload to the matching slice so
966 * default_recv pops the same bytes. */
967 uint8_t* const pool_slot =
968 internal_eth_rx_pool() + ((uintptr_t)slot * (uintptr_t)k_ra8_eth_buf_size);
969 internal_byte_copy(pool_slot, payload, copy_len);
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);
973 desc->dt = (uint8_t)k_ra8_gwdcc_dt_fsingle;
974 return k_ra8_ok;
975}
976#endif /* UNIT_TEST */
static const char * s_tag
Logging / check tag.
Definition ra8_app.c:17
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.
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_no_data
No application data available (e.g.
Definition ra8_err.h:202
@ k_ra8_err_invalid_arg
Invalid function argument.
Definition ra8_err.h:152
@ k_ra8_err_not_initialized
Module not initialized – _init() not yet called successfully.
Definition ra8_err.h:235
@ 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
static ra8_gwca_basic_descriptor_t s_linkfix_table[k_ra8_eth_linkfix_count]
Static LINKFIX table covering RX + TX queues + slack.
Definition ra8_eth.c:125
static ra8_eth_event_fn_t s_eth_fn
Attached ESWM event callback (nullptr if none).
Definition ra8_eth.c:62
eth_fwpbfc_t
Per-port FWPBFC filter mask (7-bit).
Definition ra8_eth.c:71
@ k_eth_fwpbfc_mask
Ethernet fwpbfc mask.
Definition ra8_eth.c:72
static ra8_gwca_ext_descriptor_t s_tx_chain[k_ra8_eth_tx_ring_depth]
Static TX descriptor chain (BSS, 16-byte aligned).
Definition ra8_eth.c:153
ra8_err_t ra8_eth_enter_stop(void)
Put the ethernet switch into MSTP-gated stop.
Definition ra8_eth.c:553
ra8_rmac_port_t priv_ra8_eth_channel_to_port(uint8_t channel)
Map a logical channel index to an RMAC port identifier.
Definition ra8_eth.c:347
ra8_err_t ra8_eth_get_status(uint32_t *out_mask)
Read the ESWM_STS status register.
Definition ra8_eth.c:515
ra8_err_t ra8_eth_close(void)
Close the NIC: gate clocks and idle the descriptor rings.
Definition ra8_eth.c:799
static ra8_eth_gwca_default_state_t s_gwca_state
GWCA default-state block backing ra8_eth_open / write / read.
Definition ra8_eth.c:264
static ra8_gwca_basic_descriptor_t s_rx_chain[k_ra8_eth_rx_ring_depth]
Static RX descriptor chain (BSS, 16-byte aligned).
Definition ra8_eth.c:137
static ra8_err_t internal_open_prep(const ra8_eth_cfg_t *cfg)
Validate cfg, resolve ring sizes, and bring up MSTP + RMAC.
Definition ra8_eth.c:653
static void internal_capture_state(const ra8_eth_cfg_t *cfg)
Capture cfg into s_eth_state and reset the counters.
Definition ra8_eth.c:584
ra8_eth_step_t
Step values bumped through g_ra8_eth_open_step for bench-side post-mortem via J-Link mem32.
Definition ra8_eth.c:103
@ k_ra8_eth_step_fail_3
RA8 Ethernet step fail 3.
Definition ra8_eth.c:109
@ k_ra8_eth_step_ok_4
RA8 Ethernet step ok 4.
Definition ra8_eth.c:107
@ k_ra8_eth_step_fail_4
RA8 Ethernet step fail 4.
Definition ra8_eth.c:110
@ k_ra8_eth_step_fail_1
RA8 Ethernet step fail 1.
Definition ra8_eth.c:108
@ k_ra8_eth_step_ok_3
RA8 Ethernet step ok 3.
Definition ra8_eth.c:106
@ k_ra8_eth_step_ok_2
RA8 Ethernet step ok 2.
Definition ra8_eth.c:105
@ k_ra8_eth_step_ok_1
RA8 Ethernet step ok 1.
Definition ra8_eth.c:104
ra8_err_t ra8_eth_get_stats(ra8_eth_stats_t *out_stats)
Read the NIC software counters.
Definition ra8_eth.c:869
ra8_err_t ra8_eth_exit_stop(void)
Exit MSTP-gated stop.
Definition ra8_eth.c:560
static void internal_stat_inc(uint32_t *counter)
Saturating-add helper for the 32-bit software counters.
Definition ra8_eth.c:311
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.
Definition ra8_eth.c:170
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.
Definition ra8_eth.c:377
void ra8_eth_dispatch(void)
Dispatch an ESWM event – snapshot + fire callback.
Definition ra8_eth.c:539
ra8_eth_state_t s_eth_state
Singleton NIC runtime state.
Definition ra8_eth.c:277
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 ...
Definition ra8_eth.c:691
ra8_err_t ra8_eth_write(const uint8_t *buf, uint32_t len)
Transmit a frame through the GWCA TX queue.
Definition ra8_eth.c:825
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.
Definition ra8_eth.c:181
static void * s_eth_ctx
Opaque cookie passed to s_eth_fn on dispatch.
Definition ra8_eth.c:68
ra8_eth_host_pool_layout_t
Host-test pool addresses in the fake mmap'd SRAM region.
Definition ra8_eth.c:195
@ k_ra8_eth_host_tx_pool_addr
Host TX pool base.
Definition ra8_eth.c:197
@ k_ra8_eth_host_rx_pool_addr
Host RX pool base.
Definition ra8_eth.c:196
ra8_eth_layout_t
Static layout constants for the GWCA-backed NIC rings.
Definition ra8_eth.c:86
@ k_ra8_eth_tx_ring_depth
+1 LINK term.
Definition ra8_eth.c:91
@ k_ra8_eth_linkfix_count
LINKFIX entries.
Definition ra8_eth.c:87
@ k_ra8_eth_rx_ring_depth
+1 LINK term.
Definition ra8_eth.c:90
@ k_ra8_eth_def_tx_q_idx
TX LINKFIX index.
Definition ra8_eth.c:89
@ k_ra8_eth_def_rx_q_idx
RX LINKFIX index.
Definition ra8_eth.c:88
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...
Definition ra8_eth.c:294
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.
Definition ra8_eth.c:426
ra8_err_t ra8_eth_open(const ra8_eth_cfg_t *cfg)
Open the NIC: bring up the controller stack and the descriptor rings.
Definition ra8_eth.c:756
void ra8_eth_attach_handler(ra8_eth_event_fn_t fn, void *ctx)
Replace the shared Ethernet event callback.
Definition ra8_eth.c:532
static uint8_t * internal_eth_rx_pool(void)
Resolve the RX buffer pool pointer for the current build.
Definition ra8_eth.c:217
ra8_err_t ra8_eth_deinit(void)
Tear down the ESWM block.
Definition ra8_eth.c:504
static void internal_populate_gwca_state(const ra8_eth_cfg_t *cfg)
Populate s_gwca_state with the static rings + pools + queue indices.
Definition ra8_eth.c:609
ra8_err_t ra8_eth_init(void)
Initialise the ESWM block (MSTP enable + reset regs).
Definition ra8_eth.c:486
static uint8_t * internal_eth_tx_pool(void)
Resolve the TX buffer pool pointer for the current build.
Definition ra8_eth.c:243
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.
Definition ra8_eth.c:845
static void internal_byte_copy(uint8_t *dst, const uint8_t *src, uint32_t n)
Bytewise-copy n bytes from src into dst.
Definition ra8_eth.c:340
static ra8_err_t internal_open_gwca_path(void)
Walk the GWCA bring-up + MFWD routing setup for ra8_eth_open.
Definition ra8_eth.c:723
ra8_err_t ra8_eth_clear_status(uint32_t mask)
Clear bits in ESWM_STS via ESWM_ICLR.
Definition ra8_eth.c:523
Ethernet Switch Module (ESWM) + frame TX/RX driver.
void(* ra8_eth_event_fn_t)(void *ctx, uint32_t status_mask)
Ethernet switch event callback.
Definition ra8_eth.h:53
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.
Definition ra8_eth.h:210
@ k_ra8_eth_max_frame
Maximum 802.3 untagged frame.
Definition ra8_eth.h:214
@ k_ra8_eth_num_rx_desc
Number of RX descriptors in the ring.
Definition ra8_eth.h:209
@ k_ra8_eth_mac_len
Length of an Ethernet MAC address.
Definition ra8_eth.h:211
@ k_ra8_eth_num_tx_desc
Number of TX descriptors in the ring.
Definition ra8_eth.h:208
@ k_ra8_eth_min_frame
Minimum 802.3 frame (excl.
Definition ra8_eth.h:213
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.
Definition ra8_etha.c:494
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.
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.
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.
Definition ra8_rmac.c:515
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).
Definition ra8_rmac.c:573
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.
Definition ra8_eth.h:228
uint16_t buffer_size
Buffer size per descriptor.
Definition ra8_eth.h:233
uint8_t mac_address[6]
Local MAC address (octets 0..5).
Definition ra8_eth.h:229
uint8_t channel
Logical channel index (0..1).
Definition ra8_eth.h:230
uint16_t num_tx_descriptors
Active TX descriptors (<=8, 0=def).
Definition ra8_eth.h:231
uint16_t num_rx_descriptors
Active RX descriptors (<=8, 0=def).
Definition ra8_eth.h:232
State block for ra8_eth_gwca_default_open / _send / _recv.
Driver-private NIC state.
NIC software counters.
Definition ra8_eth.h:260
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....