|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
RMAC status read/clear + statistics snapshot + Clause-22 PHY – HUM Ch 33. More...
#include <stdint.h>#include "ra8_attributes.h"#include "ra8_check.h"#include "ra8_err.h"#include "ra8_hal_internal.h"#include "ra8_log.h"#include "ra8_rmac.h"#include "ra8_rmac_regs.h"Go to the source code of this file.
Enumerations | |
| enum | ra8_rmac_phy_poll_t : uint32_t { k_ra8_rmac_phy_reset_iter_cap = 4096UL , k_ra8_rmac_phy_anwait_iter_cap = 65536UL , k_ra8_rmac_phy_anwait_iters_per_ms = 100UL } |
| PHY-management bounded poll budgets. More... | |
| enum | ra8_rmac_phy_reg_addr_t : uint8_t { k_ra8_rmac_phy_reg_bmcr = 0U , k_ra8_rmac_phy_reg_bmsr = 1U , k_ra8_rmac_phy_reg_anar = 4U , k_ra8_rmac_phy_reg_anlpar = 5U , k_ra8_rmac_phy_addr_max = 31U } |
| IEEE 802.3 Clause 22 register addresses. More... | |
| enum | ra8_rmac_phy_bit_t : uint16_t { k_ra8_rmac_phy_bmcr_an_restart = 0x0200U , k_ra8_rmac_phy_bmcr_an_enable = 0x1000U , k_ra8_rmac_phy_bmcr_reset = 0x8000U , k_ra8_rmac_phy_bmsr_link_up = 0x0004U , k_ra8_rmac_phy_bmsr_an_done = 0x0020U , k_ra8_rmac_phy_anar_selector = 0x0001U , k_ra8_rmac_phy_anlpar_10_hd = 0x0020U , k_ra8_rmac_phy_anlpar_10_fd = 0x0040U , k_ra8_rmac_phy_anlpar_100_hd = 0x0080U , k_ra8_rmac_phy_anlpar_100_fd = 0x0100U } |
| IEEE 802.3 Clause 22 BMCR / BMSR / ANxR field bits. More... | |
Functions | |
| ra8_err_t | ra8_rmac_get_status (ra8_rmac_port_t port, ra8_rmac_status_t *out) |
| Read a port's status snapshot (MEIS + MMIS0..2 + MPIM + MAC). | |
| ra8_err_t | ra8_rmac_clear_status (ra8_rmac_port_t port, uint32_t err_mask, uint32_t mon0_mask, uint32_t mon1_mask, uint32_t mon2_mask) |
| Clear bits in MEIS / MMIS0 / MMIS1 / MMIS2. | |
| static void | internal_snapshot_pause_pfc (volatile r_rmac_regs_t *reg, ra8_rmac_stats_t *out) |
| Snapshot the pause / PFC / EEE counters into out. | |
| static void | internal_snapshot_rx (volatile const r_rmac_regs_t *reg, ra8_rmac_stats_t *out) |
| Snapshot the receive counters into out. | |
| static void | internal_snapshot_tx (volatile const r_rmac_regs_t *reg, ra8_rmac_stats_t *out) |
| Snapshot the transmit counters into out. | |
| ra8_err_t | ra8_rmac_read_stats (ra8_rmac_port_t port, ra8_rmac_stats_t *out) |
| Read the full statistic counter snapshot (HUM Ch 33.4). | |
| static bool | internal_phy_args_ok (ra8_rmac_port_t port, uint8_t phy_addr) |
| Validate the (port, phy_addr) tuple shared by every PHY helper. | |
| static ra8_rmac_phy_speed_t | internal_decode_anlpar (uint16_t anlpar) |
| Decode an ANLPAR snapshot into the highest-priority capability. | |
| ra8_err_t | ra8_rmac_phy_reset (ra8_rmac_port_t port, uint8_t phy_addr) |
| Software-reset an off-chip PHY via Clause-22 MDIO. | |
| ra8_err_t | ra8_rmac_phy_set_advertise (ra8_rmac_port_t port, uint8_t phy_addr, uint16_t capabilities) |
| Program the off-chip PHY's auto-negotiation advertisement. | |
| ra8_err_t | ra8_rmac_phy_auto_neg_start (ra8_rmac_port_t port, uint8_t phy_addr) |
| Kick off (or restart) auto-negotiation on the off-chip PHY. | |
| ra8_err_t | ra8_rmac_phy_auto_neg_wait (ra8_rmac_port_t port, uint8_t phy_addr, uint32_t timeout_ms, ra8_rmac_phy_link_t *out_link) |
| Block (with a bounded poll) until the PHY reports AN_COMPLETE. | |
| ra8_err_t | ra8_rmac_phy_link_status (ra8_rmac_port_t port, uint8_t phy_addr, ra8_rmac_phy_link_t *out_link) |
| Quick poll of BMSR.LINK_STATUS (no auto-neg block). | |
Variables | |
| static const char * | s_tag = "RMAC" |
| Logger tag used by every ra8_rmac_* call in this TU. | |
RMAC status read/clear + statistics snapshot + Clause-22 PHY – HUM Ch 33.
Companion translation unit to ra8_rmac.c, split out so each file stays well under the per-file line cap. This unit owns three cohesive sub-responsibilities of the RA8D2 RMAC block (HUM Ch 33, p 1703-1786):
Every register access carries a HUM Ch 33 citation. The driver-private logger tag is a private read-only copy of the ra8_rmac.c tag so the two units log under the same "RMAC" name without sharing a linker symbol.
Definition in file ra8_rmac_mgmt.c.
| enum ra8_rmac_phy_bit_t : uint16_t |
IEEE 802.3 Clause 22 BMCR / BMSR / ANxR field bits.
Definition at line 79 of file ra8_rmac_mgmt.c.
| enum ra8_rmac_phy_poll_t : uint32_t |
PHY-management bounded poll budgets.
| Enumerator | |
|---|---|
| k_ra8_rmac_phy_reset_iter_cap | BMCR.RESET self-clear cap. |
| k_ra8_rmac_phy_anwait_iter_cap | Auto-neg internal cap. |
| k_ra8_rmac_phy_anwait_iters_per_ms | 10us per spin -> 100/ms. |
Definition at line 52 of file ra8_rmac_mgmt.c.
| enum ra8_rmac_phy_reg_addr_t : uint8_t |
IEEE 802.3 Clause 22 register addresses.
Reference: IEEE Std 802.3-2018 Clause 22 sec 22.2.4 "Management register set". These five registers are the only ones the RMAC PHY-control glue touches; everything else is vendor-specific.
Definition at line 67 of file ra8_rmac_mgmt.c.
|
static |
Decode an ANLPAR snapshot into the highest-priority capability.
IEEE 802.3 Clause 28.2.4.4 "Link Partner Ability Register" defines the priority order for resolved capabilities.
| [in] | anlpar | Raw ANLPAR contents read over MDIO. |
| k_ra8_ok | Operation succeeded. |
Definition at line 315 of file ra8_rmac_mgmt.c.
References k_ra8_rmac_phy_anlpar_100_fd, k_ra8_rmac_phy_anlpar_100_hd, k_ra8_rmac_phy_anlpar_10_fd, k_ra8_rmac_phy_anlpar_10_hd, k_ra8_rmac_phy_speed_100_fd, k_ra8_rmac_phy_speed_100_hd, k_ra8_rmac_phy_speed_10_fd, k_ra8_rmac_phy_speed_10_hd, and k_ra8_rmac_phy_speed_unknown.
Referenced by ra8_rmac_phy_auto_neg_wait(), and ra8_rmac_phy_link_status().
|
inlinestatic |
Validate the (port, phy_addr) tuple shared by every PHY helper.
| [in] | port | Port to validate. |
| [in] | phy_addr | 5-bit PHY address to validate. |
See implementation.
| k_ra8_ok | Operation succeeded. |
Definition at line 291 of file ra8_rmac_mgmt.c.
References internal_port_ok(), and k_ra8_rmac_phy_addr_max.
Referenced by ra8_rmac_phy_auto_neg_start(), ra8_rmac_phy_auto_neg_wait(), ra8_rmac_phy_link_status(), ra8_rmac_phy_reset(), and ra8_rmac_phy_set_advertise().
|
static |
Snapshot the pause / PFC / EEE counters into out.
HUM Ch 33.4 MMPFTCT / MAPFTCT / MPFRCT / MFCICT / MEEECT and the MMPCFTCT / MAPCFTCT / MPCFRCT counter banks (p 1706).
| [in] | reg | See implementation. |
| [in] | out | See implementation. |
Definition at line 170 of file ra8_rmac_mgmt.c.
References ra8_rmac_stats_t::eee_count, ra8_rmac_stats_t::false_carrier, k_ra8_rmac_pfc_group_count, k_ra8_rmac_pfc_rx_count, r_rmac_regs_t::MAPCFTCT, r_rmac_regs_t::MAPFTCT, r_rmac_regs_t::MEEECT, r_rmac_regs_t::MFCICT, r_rmac_regs_t::MMPCFTCT, r_rmac_regs_t::MMPFTCT, r_rmac_regs_t::MPCFRCT, r_rmac_regs_t::MPFRCT, ra8_rmac_stats_t::pause_rx, ra8_rmac_stats_t::pause_tx_auto, ra8_rmac_stats_t::pause_tx_manual, ra8_rmac_stats_t::pfc_rx, ra8_rmac_stats_t::pfc_tx_auto, and ra8_rmac_stats_t::pfc_tx_manual.
Referenced by ra8_rmac_read_stats().
|
static |
Snapshot the receive counters into out.
HUM Ch 33.4 MROVFC ... MRXBCPL p 1706.
| [in] | reg | See implementation. |
| [in] | out | See implementation. |
Definition at line 202 of file ra8_rmac_mgmt.c.
References r_rmac_regs_t::MRBFC, r_rmac_regs_t::MRBOEFC, r_rmac_regs_t::MRBUEFC, r_rmac_regs_t::MRCFCEFC, r_rmac_regs_t::MRFC, r_rmac_regs_t::MRFCEFC, r_rmac_regs_t::MRFFMEFC, r_rmac_regs_t::MRFMEFC, r_rmac_regs_t::MRGFCE, r_rmac_regs_t::MRGFCP, r_rmac_regs_t::MRGOEFC, r_rmac_regs_t::MRGUEFC, r_rmac_regs_t::MRHCRCEC, r_rmac_regs_t::MRMFC, r_rmac_regs_t::MRNEFC, r_rmac_regs_t::MROVFC, r_rmac_regs_t::MRPEFC, r_rmac_regs_t::MRRCFEFC, r_rmac_regs_t::MRUFC, r_rmac_regs_t::MRXBCEL, r_rmac_regs_t::MRXBCEU, r_rmac_regs_t::MRXBCPL, r_rmac_regs_t::MRXBCPU, ra8_rmac_stats_t::rx_bad_oversize, ra8_rmac_stats_t::rx_bad_undersize, ra8_rmac_stats_t::rx_broadcast, ra8_rmac_stats_t::rx_bytes_e_lower, ra8_rmac_stats_t::rx_bytes_e_upper, ra8_rmac_stats_t::rx_bytes_p_lower, ra8_rmac_stats_t::rx_bytes_p_upper, ra8_rmac_stats_t::rx_c_frag_err, ra8_rmac_stats_t::rx_fcs_err, ra8_rmac_stats_t::rx_filter_rejected, ra8_rmac_stats_t::rx_final_frag_miss, ra8_rmac_stats_t::rx_frag_count_err, ra8_rmac_stats_t::rx_good_e, ra8_rmac_stats_t::rx_good_oversize, ra8_rmac_stats_t::rx_good_p, ra8_rmac_stats_t::rx_good_undersize, ra8_rmac_stats_t::rx_hdr_crc_err, ra8_rmac_stats_t::rx_multicast, ra8_rmac_stats_t::rx_nibble_err, ra8_rmac_stats_t::rx_overflow, ra8_rmac_stats_t::rx_phy_err, ra8_rmac_stats_t::rx_total, and ra8_rmac_stats_t::rx_unicast.
Referenced by ra8_rmac_read_stats().
|
static |
Snapshot the transmit counters into out.
HUM Ch 33.4 MTGFCE ... MTXBCPL p 1706.
| [in] | reg | See implementation. |
| [in] | out | See implementation. |
Definition at line 245 of file ra8_rmac_mgmt.c.
References r_rmac_regs_t::MTBFC, r_rmac_regs_t::MTEFC, r_rmac_regs_t::MTGFCE, r_rmac_regs_t::MTGFCP, r_rmac_regs_t::MTMFC, r_rmac_regs_t::MTUFC, r_rmac_regs_t::MTXBCEL, r_rmac_regs_t::MTXBCEU, r_rmac_regs_t::MTXBCPL, r_rmac_regs_t::MTXBCPU, ra8_rmac_stats_t::tx_broadcast, ra8_rmac_stats_t::tx_bytes_e_lower, ra8_rmac_stats_t::tx_bytes_e_upper, ra8_rmac_stats_t::tx_bytes_p_lower, ra8_rmac_stats_t::tx_bytes_p_upper, ra8_rmac_stats_t::tx_error, ra8_rmac_stats_t::tx_good_e, ra8_rmac_stats_t::tx_good_p, ra8_rmac_stats_t::tx_multicast, and ra8_rmac_stats_t::tx_unicast.
Referenced by ra8_rmac_read_stats().
|
nodiscard |
Clear bits in MEIS / MMIS0 / MMIS1 / MMIS2.
| [in] | port | Port identifier. |
| [in] | err_mask | Bits to clear in MEIS via MEID. |
| [in] | mon0_mask | Bits to clear in MMIS0 via MMID0. |
| [in] | mon1_mask | Bits to clear in MMIS1 via MMID1. |
| [in] | mon2_mask | Bits to clear in MMIS2 via MMID2. |
Definition at line 118 of file ra8_rmac_mgmt.c.
References internal_port_ok(), k_ra8_err_invalid_arg, k_ra8_ok, r_rmac_regs_t::MEID, r_rmac_regs_t::MEIS, r_rmac_regs_t::MMID0, r_rmac_regs_t::MMID1, r_rmac_regs_t::MMID2, r_rmac_regs_t::MMIS0, r_rmac_regs_t::MMIS1, r_rmac_regs_t::MMIS2, ra8_log_error, ra8_rmac(), and s_tag.
|
nodiscard |
Read a port's status snapshot (MEIS + MMIS0..2 + MPIM + MAC).
| [in] | port | Port identifier. |
| [out] | out | Destination for the status snapshot. |
Definition at line 92 of file ra8_rmac_mgmt.c.
References ra8_rmac_status_t::err_status, internal_port_ok(), k_ra8_err_invalid_arg, k_ra8_ok, r_rmac_regs_t::MEIS, r_rmac_regs_t::MMIS0, r_rmac_regs_t::MMIS1, r_rmac_regs_t::MMIS2, ra8_rmac_status_t::mon_status, r_rmac_regs_t::MPIM, r_rmac_regs_t::MRMAC0, ra8_rmac_status_t::mrmac0, r_rmac_regs_t::MRMAC1, ra8_rmac_status_t::mrmac1, ra8_rmac_status_t::phy_monitor, RA8_CHECK_NULL_PTR, ra8_log_error, ra8_rmac(), and s_tag.
|
nodiscard |
Kick off (or restart) auto-negotiation on the off-chip PHY.
Sets IEEE 802.3 Clause 22 BMCR.AN_ENABLE (bit 12) and BMCR.AN_RESTART (bit 9) in a single MDIO write. Pair this call with ra8_rmac_phy_auto_neg_wait to block until the PHY reports AN_COMPLETE in BMSR.
| [in] | port | Port identifier. |
| [in] | phy_addr | 5-bit PHY address. |
| k_ra8_ok | AN restart issued. |
| k_ra8_err_invalid_arg | port or phy_addr out of range. |
| k_ra8_err_hw_timeout | MDIO transaction never completed. |
Definition at line 380 of file ra8_rmac_mgmt.c.
References internal_phy_args_ok(), k_ra8_err_invalid_arg, k_ra8_rmac_phy_bmcr_an_enable, k_ra8_rmac_phy_bmcr_an_restart, k_ra8_rmac_phy_reg_bmcr, ra8_log_error, ra8_rmac_mdio_c22_write(), and s_tag.
Referenced by ra8_etha_open().
|
nodiscard |
Block (with a bounded poll) until the PHY reports AN_COMPLETE.
Reads IEEE 802.3 Clause 22 BMSR (register 1) in a loop; each iteration costs one MDIO transaction. Returns success when both BMSR.AN_COMPLETE (bit 5) and BMSR.LINK_STATUS (bit 2) are observed set in the same read. The resolved speed/duplex is decoded from the negotiated 10/100 capability bits in ANLPAR (register 5) once AN_COMPLETE asserts.
| [in] | port | Port identifier. |
| [in] | phy_addr | 5-bit PHY address. |
| [in] | timeout_ms | Maximum wait in milliseconds (0 -> internal cap). |
| [out] | out_link | Resolved link state on success. |
| k_ra8_ok | AN_COMPLETE + LINK_STATUS observed. |
| k_ra8_err_null_ptr | out_link is nullptr. |
| k_ra8_err_invalid_arg | port or phy_addr out of range. |
| k_ra8_err_hw_timeout | AN_COMPLETE never asserted. |
Definition at line 394 of file ra8_rmac_mgmt.c.
References internal_decode_anlpar(), internal_phy_args_ok(), k_ra8_err_hw_timeout, k_ra8_err_invalid_arg, k_ra8_ok, k_ra8_rmac_phy_anwait_iter_cap, k_ra8_rmac_phy_anwait_iters_per_ms, k_ra8_rmac_phy_bmsr_an_done, k_ra8_rmac_phy_bmsr_link_up, k_ra8_rmac_phy_reg_anlpar, k_ra8_rmac_phy_reg_bmsr, k_ra8_rmac_phy_speed_unknown, RA8_CHECK_NULL_PTR, ra8_log_error, ra8_rmac_mdio_c22_read(), s_tag, ra8_rmac_phy_link_t::speed, and ra8_rmac_phy_link_t::up.
Referenced by ra8_etha_open().
|
nodiscard |
Quick poll of BMSR.LINK_STATUS (no auto-neg block).
Single MDIO read of IEEE 802.3 Clause 22 BMSR. Reports up/down via out_link->up. When up is true the speed field is decoded from ANLPAR if AN_COMPLETE is set, otherwise it is left as k_ra8_rmac_phy_speed_unknown.
| [in] | port | Port identifier. |
| [in] | phy_addr | 5-bit PHY address. |
| [out] | out_link | Destination for the snapshot. |
| k_ra8_ok | BMSR read OK. |
| k_ra8_err_null_ptr | out_link is nullptr. |
| k_ra8_err_invalid_arg | port or phy_addr out of range. |
| k_ra8_err_hw_timeout | MDIO transaction never completed. |
Definition at line 444 of file ra8_rmac_mgmt.c.
References internal_decode_anlpar(), internal_phy_args_ok(), k_ra8_err_invalid_arg, k_ra8_ok, k_ra8_rmac_phy_bmsr_an_done, k_ra8_rmac_phy_bmsr_link_up, k_ra8_rmac_phy_reg_anlpar, k_ra8_rmac_phy_reg_bmsr, k_ra8_rmac_phy_speed_unknown, RA8_CHECK_NULL_PTR, ra8_log_error, ra8_rmac_mdio_c22_read(), s_tag, ra8_rmac_phy_link_t::speed, and ra8_rmac_phy_link_t::up.
|
nodiscard |
Software-reset an off-chip PHY via Clause-22 MDIO.
Writes IEEE 802.3 Clause 22 BMCR.RESET (bit 15), then polls BMCR until the reset bit self-clears or a bounded poll budget is exhausted.
| [in] | port | Port identifier (k_ra8_rmac_port_0 / _1). |
| [in] | phy_addr | 5-bit PHY address on the MDIO bus (0..31). |
| k_ra8_ok | PHY reset complete. |
| k_ra8_err_invalid_arg | port or phy_addr out of range. |
| k_ra8_err_hw_timeout | BMCR.RESET never self-cleared. |
Definition at line 332 of file ra8_rmac_mgmt.c.
References internal_phy_args_ok(), k_ra8_err_hw_timeout, k_ra8_err_invalid_arg, k_ra8_ok, k_ra8_rmac_phy_bmcr_reset, k_ra8_rmac_phy_reg_bmcr, k_ra8_rmac_phy_reset_iter_cap, ra8_log_error, ra8_rmac_mdio_c22_read(), ra8_rmac_mdio_c22_write(), and s_tag.
Referenced by ra8_etha_open().
|
nodiscard |
Program the off-chip PHY's auto-negotiation advertisement.
Writes the IEEE 802.3 Clause 22 ANAR register (register 4) with the supplied capability mask plus the IEEE 802.3 selector field (00001 in bits [4:0]). After updating the advertisement, callers typically invoke ra8_rmac_phy_auto_neg_start to cause the PHY to restart auto-negotiation with the new capabilities.
| [in] | port | Port identifier. |
| [in] | phy_addr | 5-bit PHY address (0..31). |
| [in] | capabilities | OR of ra8_rmac_phy_advert_t bits. |
| k_ra8_ok | ANAR programmed. |
| k_ra8_err_invalid_arg | port or phy_addr out of range. |
| k_ra8_err_hw_timeout | MDIO transaction never completed. |
Definition at line 368 of file ra8_rmac_mgmt.c.
References internal_phy_args_ok(), k_ra8_err_invalid_arg, k_ra8_rmac_phy_anar_selector, k_ra8_rmac_phy_reg_anar, ra8_log_error, ra8_rmac_mdio_c22_write(), and s_tag.
Referenced by ra8_etha_open().
|
nodiscard |
Read the full statistic counter snapshot (HUM Ch 33.4).
| [in] | port | Port identifier. |
| [out] | out | Destination for the counter snapshot. |
Definition at line 259 of file ra8_rmac_mgmt.c.
References internal_port_ok(), internal_snapshot_pause_pfc(), internal_snapshot_rx(), internal_snapshot_tx(), k_ra8_err_invalid_arg, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_log_error, ra8_rmac(), and s_tag.
|
static |
Logger tag used by every ra8_rmac_* call in this TU.
Definition at line 46 of file ra8_rmac_mgmt.c.