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

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"
Include dependency graph for ra8_rmac_mgmt.c:

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.

Detailed Description

RMAC status read/clear + statistics snapshot + Clause-22 PHY – HUM Ch 33.

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

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):

  • IRQ status read / clear (HUM Ch 33.4 MEIS / MMIS0..2 / MEID / MMID0..2 p 1706, plus MPIM / MRMAC0 / MRMAC1 monitoring), exposed through ra8_rmac_get_status and ra8_rmac_clear_status.
  • The full statistic counter snapshot (HUM Ch 33.4 MMPFTCT .. MTXBCPL p 1706), exposed through ra8_rmac_read_stats and its three private snapshot helpers (pause/PFC/EEE, receive, transmit).
  • The IEEE 802.3 Clause-22 PHY management glue layered on the MDIO primitives in ra8_rmac.c: PHY soft-reset, advertisement program, auto-negotiation start / wait, and link-status read. These call the public ra8_rmac_mdio_c22_read / ra8_rmac_mdio_c22_write API.

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.

Enumeration Type Documentation

◆ ra8_rmac_phy_bit_t

enum ra8_rmac_phy_bit_t : uint16_t

IEEE 802.3 Clause 22 BMCR / BMSR / ANxR field bits.

Enumerator
k_ra8_rmac_phy_bmcr_an_restart 

BMCR bit 9.

k_ra8_rmac_phy_bmcr_an_enable 

BMCR bit 12.

k_ra8_rmac_phy_bmcr_reset 

BMCR bit 15.

k_ra8_rmac_phy_bmsr_link_up 

BMSR bit 2.

k_ra8_rmac_phy_bmsr_an_done 

BMSR bit 5.

k_ra8_rmac_phy_anar_selector 

ANAR bit 0 (802.3).

k_ra8_rmac_phy_anlpar_10_hd 

ANLPAR 10BASE-T HD.

k_ra8_rmac_phy_anlpar_10_fd 

ANLPAR 10BASE-T FD.

k_ra8_rmac_phy_anlpar_100_hd 

ANLPAR 100BASE-TX HD.

k_ra8_rmac_phy_anlpar_100_fd 

ANLPAR 100BASE-TX FD.

Definition at line 79 of file ra8_rmac_mgmt.c.

◆ ra8_rmac_phy_poll_t

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.

◆ ra8_rmac_phy_reg_addr_t

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.

Enumerator
k_ra8_rmac_phy_reg_bmcr 

IEEE 802.3 Clause 22 sec 22.2.4.1 BMCR.

k_ra8_rmac_phy_reg_bmsr 

IEEE 802.3 Clause 22 sec 22.2.4.2 BMSR.

k_ra8_rmac_phy_reg_anar 

IEEE 802.3 Clause 28.2.4 ANAR.

k_ra8_rmac_phy_reg_anlpar 

IEEE 802.3 Clause 28.2.4 ANLPAR.

k_ra8_rmac_phy_addr_max 

5-bit MDIO PHY address ceiling.

Definition at line 67 of file ra8_rmac_mgmt.c.

Function Documentation

◆ internal_decode_anlpar()

ra8_rmac_phy_speed_t internal_decode_anlpar ( uint16_t anlpar)
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.

Parameters
[in]anlparRaw ANLPAR contents read over MDIO.
Returns
Resolved ra8_rmac_phy_speed_t value.
Return values
k_ra8_okOperation succeeded.
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.
Since
0.1.0

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().

◆ internal_phy_args_ok()

bool internal_phy_args_ok ( ra8_rmac_port_t port,
uint8_t phy_addr )
inlinestatic

Validate the (port, phy_addr) tuple shared by every PHY helper.

Parameters
[in]portPort to validate.
[in]phy_addr5-bit PHY address to validate.
Returns
true iff both arguments are in range.

See implementation.

Return values
k_ra8_okOperation succeeded.
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.
Since
0.1.0

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().

◆ internal_snapshot_pause_pfc()

void internal_snapshot_pause_pfc ( volatile r_rmac_regs_t * reg,
ra8_rmac_stats_t * out )
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).

Parameters
[in]regSee implementation.
[in]outSee 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.
Since
0.1.0

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().

◆ internal_snapshot_rx()

void internal_snapshot_rx ( volatile const r_rmac_regs_t * reg,
ra8_rmac_stats_t * out )
static

Snapshot the receive counters into out.

HUM Ch 33.4 MROVFC ... MRXBCPL p 1706.

Parameters
[in]regSee implementation.
[in]outSee 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.
Since
0.1.0

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().

◆ internal_snapshot_tx()

void internal_snapshot_tx ( volatile const r_rmac_regs_t * reg,
ra8_rmac_stats_t * out )
static

Snapshot the transmit counters into out.

HUM Ch 33.4 MTGFCE ... MTXBCPL p 1706.

Parameters
[in]regSee implementation.
[in]outSee 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.
Since
0.1.0

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().

◆ ra8_rmac_clear_status()

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 )
nodiscard

Clear bits in MEIS / MMIS0 / MMIS1 / MMIS2.

Parameters
[in]portPort identifier.
[in]err_maskBits to clear in MEIS via MEID.
[in]mon0_maskBits to clear in MMIS0 via MMID0.
[in]mon1_maskBits to clear in MMIS1 via MMID1.
[in]mon2_maskBits to clear in MMIS2 via MMID2.
Returns
ra8_err_t Error code.
Precondition
Port previously brought up via ra8_rmac_init.
Caller has read the status registers via ra8_rmac_get_status.
Postcondition
Bits in masks are cleared in their respective status registers.
Re-reads of the status registers exclude the cleared bits.
Note
IRQ-safe; the underlying writes are atomic on Cortex-M85.
Since
0.1.0

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.

◆ ra8_rmac_get_status()

ra8_err_t ra8_rmac_get_status ( ra8_rmac_port_t port,
ra8_rmac_status_t * out )
nodiscard

Read a port's status snapshot (MEIS + MMIS0..2 + MPIM + MAC).

Parameters
[in]portPort identifier.
[out]outDestination for the status snapshot.
Returns
ra8_err_t Error code.
Precondition
Port has been brought up via ra8_rmac_init.
out is a writable pointer.
Postcondition
out->err_status reflects MEIS at the call site.
out->mon_status[i] reflect MMIS{i} for i in 0..2.
Note
Reads are non-destructive; status bits are cleared via ra8_rmac_clear_status.
See also
ra8_rmac_clear_status
Since
0.1.0

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.

◆ ra8_rmac_phy_auto_neg_start()

ra8_err_t ra8_rmac_phy_auto_neg_start ( ra8_rmac_port_t port,
uint8_t phy_addr )
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.

Parameters
[in]portPort identifier.
[in]phy_addr5-bit PHY address.
Returns
ra8_err_t Error code.
Return values
k_ra8_okAN restart issued.
k_ra8_err_invalid_argport or phy_addr out of range.
k_ra8_err_hw_timeoutMDIO transaction never completed.
Precondition
Port previously brought up via ra8_rmac_init.
PHY ANAR programmed (see ra8_rmac_phy_set_advertise).
Postcondition
BMCR.AN_ENABLE = 1; BMCR.AN_RESTART = 1.
PHY transitions to AN_ABILITY_DETECT per IEEE 802.3 Clause 28.
Note
IEEE 802.3 Clause 22 sec 22.2.4.1 "BMCR" bit definitions.
See also
ra8_rmac_phy_auto_neg_wait
Since
0.1.0

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().

◆ ra8_rmac_phy_auto_neg_wait()

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 )
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.

Parameters
[in]portPort identifier.
[in]phy_addr5-bit PHY address.
[in]timeout_msMaximum wait in milliseconds (0 -> internal cap).
[out]out_linkResolved link state on success.
Returns
ra8_err_t Error code.
Return values
k_ra8_okAN_COMPLETE + LINK_STATUS observed.
k_ra8_err_null_ptrout_link is nullptr.
k_ra8_err_invalid_argport or phy_addr out of range.
k_ra8_err_hw_timeoutAN_COMPLETE never asserted.
Precondition
Port previously brought up via ra8_rmac_init.
Auto-neg started via ra8_rmac_phy_auto_neg_start.
Postcondition
On k_ra8_ok, *out_link reflects negotiated speed/duplex/link.
On k_ra8_err_hw_timeout, *out_link->up = false.
Note
IEEE 802.3 Clause 22 sec 22.2.4.2 "BMSR" defines AN_COMPLETE and LINK_STATUS; Clause 28.2.4.4 "ANLPAR" defines the resolved-capability bit layout this helper decodes.
See also
ra8_rmac_phy_auto_neg_start
Since
0.1.0

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().

◆ ra8_rmac_phy_link_status()

ra8_err_t ra8_rmac_phy_link_status ( ra8_rmac_port_t port,
uint8_t phy_addr,
ra8_rmac_phy_link_t * out_link )
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.

Parameters
[in]portPort identifier.
[in]phy_addr5-bit PHY address.
[out]out_linkDestination for the snapshot.
Returns
ra8_err_t Error code.
Return values
k_ra8_okBMSR read OK.
k_ra8_err_null_ptrout_link is nullptr.
k_ra8_err_invalid_argport or phy_addr out of range.
k_ra8_err_hw_timeoutMDIO transaction never completed.
Precondition
Port previously brought up via ra8_rmac_init.
PHY visible on the MDIO bus.
Postcondition
out_link populated; no PHY register state changed.
Note
IEEE 802.3 Clause 22 sec 22.2.4.2 "BMSR.LINK_STATUS" is latching-low: a single read clears any latched-down event.
Since
0.1.0

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.

◆ ra8_rmac_phy_reset()

ra8_err_t ra8_rmac_phy_reset ( ra8_rmac_port_t port,
uint8_t phy_addr )
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.

Parameters
[in]portPort identifier (k_ra8_rmac_port_0 / _1).
[in]phy_addr5-bit PHY address on the MDIO bus (0..31).
Returns
ra8_err_t Error code.
Return values
k_ra8_okPHY reset complete.
k_ra8_err_invalid_argport or phy_addr out of range.
k_ra8_err_hw_timeoutBMCR.RESET never self-cleared.
Precondition
Port previously brought up via ra8_rmac_init.
MPIC.PSMCS programmed for the chosen MDC clock.
Postcondition
BMCR.RESET observed cleared by the PHY.
All other BMCR bits reset to power-on defaults by the PHY.
Note
IEEE 802.3 Clause 22 sec 22.2.4.1.1 "BMCR.RESET" defines the self-clearing semantics this function relies on.
See also
ra8_rmac_phy_auto_neg_start
Since
0.1.0

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().

◆ ra8_rmac_phy_set_advertise()

ra8_err_t ra8_rmac_phy_set_advertise ( ra8_rmac_port_t port,
uint8_t phy_addr,
uint16_t capabilities )
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.

Parameters
[in]portPort identifier.
[in]phy_addr5-bit PHY address (0..31).
[in]capabilitiesOR of ra8_rmac_phy_advert_t bits.
Returns
ra8_err_t Error code.
Return values
k_ra8_okANAR programmed.
k_ra8_err_invalid_argport or phy_addr out of range.
k_ra8_err_hw_timeoutMDIO transaction never completed.
Precondition
Port previously brought up via ra8_rmac_init.
PHY is in a state that accepts ANAR writes (post reset OK).
Postcondition
ANAR = capabilities | 0x0001 (selector field).
Auto-neg restart still required to advertise new value.
Note
IEEE 802.3 Clause 28.2.4 "AN advertisement register" defines the bit layout this helper writes.
See also
ra8_rmac_phy_auto_neg_start
Since
0.1.0

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().

◆ ra8_rmac_read_stats()

ra8_err_t ra8_rmac_read_stats ( ra8_rmac_port_t port,
ra8_rmac_stats_t * out )
nodiscard

Read the full statistic counter snapshot (HUM Ch 33.4).

Parameters
[in]portPort identifier.
[out]outDestination for the counter snapshot.
Returns
ra8_err_t Error code.
Precondition
Port has been brought up via ra8_rmac_init.
out is a writable pointer.
Postcondition
Every member in out matches its register at read time.
Hardware counters keep accumulating; this is a read-only snap.
Note
Counters are read-only; clearing happens via deinit/init or a controlled reset of the ETHA mode.
Since
0.1.0

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.

Variable Documentation

◆ s_tag

const char* s_tag = "RMAC"
static

Logger tag used by every ra8_rmac_* call in this TU.

Definition at line 46 of file ra8_rmac_mgmt.c.