# MACHW
[HAL]

MAC HW Control Module. More...

Collaboration diagram for MACHW:

## Defines
#define | HW_ERROR_IRQ
| Error interrupts.
#define | HE_TIMER_BIT 0
| HE TX timeout bit.
#define | TIMEOUT_IRQ
| Timeout error interrupts.
#define | TX_IRQ
| TX interrupt bits.
#define | RX_IRQ (NXMAC_COUNTER_RX_TRIGGER_BIT | NXMAC_TIMER_RX_TRIGGER_BIT)
| RX interrupt bits.
#define | BW_DROP_IRQ 0
| Bandwidth drop interrupt bits.
#define | MAC_HW_RESET
| FSMs and FIFOs that have to be reset by the error recovery mechanism.
#define | IDLE_REQ_TIMEOUT 50000
| Timeout duration when a IDLE state is requested to the HW.
#define | TIMING_UPDATE(param, old, new)
| Macro used to apply a ratio on a MAC timing parameter when switching from one MAC core clock value to another one.
#define | HAL_MACHW_BCN_TX_DELAY_US (2048)
| Duration between AP TBTT and Beacon Transmission (in us, should be a multiple of 128us).
#define | MU_MIMO_MASTER_TX_IRQ NXMAC_SEC_USER_TX_TRIGGER_BIT
| Global Interrupt bit for TX IRQ on secondary user.
#define | TX_SEC_IRQ_BITS
| Bits indicating activity on secondary users (separated trigger and buffer).
## Enumerations
enum | { HW_IDLE = 0, HW_RESERVED, HW_DOZE, HW_ACTIVE }
| For MAC HW States. More...
enum | { MODE_802_11B = 0, MODE_802_11A, MODE_802_11G, MODE_802_11N_2_4, MODE_802_11N_5, MODE_RESERVED, MODE_802_11AC_5 }
| 802.11 modes More...
enum | { HAL_AC0_TIMER = 0, HAL_AC1_TIMER, HAL_AC2_TIMER, HAL_AC3_TIMER, HAL_BCN_TIMER, HAL_IDLE_TIMER, HAL_RX_TIMER, HAL_MM_TIMER, HAL_KE_TIMER, HAL_TIMER_MAX }
| Mapping of HW timers. More...
enum | { HAL_AC0_TIMER_BIT = CO_BIT(HAL_AC0_TIMER), HAL_AC1_TIMER_BIT = CO_BIT(HAL_AC1_TIMER), HAL_AC2_TIMER_BIT = CO_BIT(HAL_AC2_TIMER), HAL_AC3_TIMER_BIT = CO_BIT(HAL_AC3_TIMER), HAL_BCN_TIMER_BIT = CO_BIT(HAL_BCN_TIMER), HAL_IDLE_TIMER_BIT = CO_BIT(HAL_IDLE_TIMER), HAL_RX_TIMER_BIT = CO_BIT(HAL_RX_TIMER), HAL_MM_TIMER_BIT = CO_BIT(HAL_MM_TIMER), HAL_KE_TIMER_BIT = CO_BIT(HAL_KE_TIMER) }
| Bits associated to HW timers. More...
## Functions
static void | hal_machw_idle_irq_handler (void)
| IDLE Interrupt Handler.
static void | hal_machw_setfreq (uint8_t newfreq)
| Updates the MAC HW timing registers according to the frequency actually used.
void | hal_machw_idle_req (void)
| Ask to HW to move to IDLE state.
void | hal_machw_stop (void)
| Stop the operation of the MAC HW.
void | hal_machw_init (void)
| Interrupt Controller initialization.
void | hal_machw_disable_int (void)
| MAC HW interrupt disable function.
void | hal_machw_reset (void)
| MAC HW reset function.
uint8_t | hal_machw_search_addr (struct mac_addr *addr)
| Function accessing the HW address search engine.
void | hal_machw_monitor_mode (void)
| Put back the MAC HW in monitoring mode.
int | hal_machw_tsf_move (int32_t offset)
| Apply an offset (positive or negative) to the TSF timer.
bool | hal_machw_sleep_check (void)
| Check if the HW timers don expire too early to go to sleep.
static void | hal_machw_abs_timer_handler (void)
| Absolute timer interrupt Handler.
void | hal_machw_gen_handler (void)
| Interrupt Handling.
__INLINE uint32_t | hal_machw_time (void)
| Get the current HW time.
__INLINE bool | hal_machw_time_cmp (uint32_t time1, uint32_t time2)
| Compare timer absolute expiration time.
__INLINE bool | hal_machw_time_past (uint32_t time)
| Compare timer absolute expiration time.
__INLINE void | hal_machw_udelay (uint32_t us)
| Block execution for the given number of us.
__INLINE uint32_t | hal_machw_rx_bcn_duration (struct rx_hd *rhd, uint16_t len)
| Compute duration it took to transmit the received frame.
__INLINE bool | hal_machw_bfmee_support (void)
| Check whether BFMEE is supported by the MAC and PHY HW.
__INLINE bool | hal_machw_bfmer_support (void)
| Check whether BFMER is supported by the MAC and PHY HW.
__INLINE bool | hal_machw_mu_mimo_rx_support (void)
| Check whether Mu-MIMO RX is supported by the MAC and PHY HW.
__INLINE bool | hal_machw_mu_mimo_tx_support (void)
| Check whether Mu-MIMO TX is supported by the MAC and PHY HW.
__INLINE bool | hal_machw_he_support (void)
| Check whether HE is supported by the MAC and PHY HW.
## Variables
const uint8_t | rxv2macrate []
| Table of conversion between a RX vector rate to a MAC HW rate.
const uint8_t | rxv2macrate []
| Table of conversion between a RX vector rate to a MAC HW rate.

## Detailed Description

MAC HW Control Module.

## Define Documentation

#define HW_ERROR_IRQ

Value:

    (NXMAC_RX_FIFO_OVER_FLOW_BIT | NXMAC_MAC_PHYIF_OVERFLOW_BIT |      \
                          NXMAC_PT_ERROR_BIT | NXMAC_HW_ERR_BIT | NXMAC_PHY_ERR_BIT |       \
                          NXMAC_AC_0_TX_DMA_DEAD_BIT | NXMAC_AC_1_TX_DMA_DEAD_BIT |         \
                          NXMAC_AC_2_TX_DMA_DEAD_BIT | NXMAC_AC_3_TX_DMA_DEAD_BIT |         \
                          NXMAC_BCN_TX_DMA_DEAD_BIT | NXMAC_MAC_PHYIF_UNDER_RUN_BIT |       \
                          NXMAC_RX_HEADER_DMA_DEAD_BIT | NXMAC_RX_PAYLOAD_DMA_DEAD_BIT)

Error interrupts.

Definition at line 47 of file hal_machw.c.

#define MAC_HW_RESET

Value:

    (NXMAC_HW_FSM_RESET_BIT | NXMAC_RX_FIFO_RESET_BIT |                \
                          NXMAC_TX_FIFO_RESET_BIT | NXMAC_MAC_PHYIFFIFO_RESET_BIT |         \
                          NXMAC_ENCR_RX_FIFO_RESET_BIT)

FSMs and FIFOs that have to be reset by the error recovery mechanism.

Definition at line 98 of file hal_machw.c.

#define TIMEOUT_IRQ

Value:

    (HAL_AC0_TIMER_BIT | HAL_AC1_TIMER_BIT | HAL_AC2_TIMER_BIT |       \
                          HAL_AC3_TIMER_BIT | HAL_BCN_TIMER_BIT | HAL_IDLE_TIMER_BIT |      \
                          HE_TIMER_BIT)

Timeout error interrupts.

Definition at line 62 of file hal_machw.c.

#define TIMING_UPDATE | ( | param,
|  | old,
|  | new |  | ) |

Value:

    (nxmac_ ## param ## _in_mac_clk_setf((uint32_t)           \
                                            nxmac_ ## param ## _in_mac_clk_getf()  \
                                              * (uint32_t)(new) / (uint32_t)(old)))

Macro used to apply a ratio on a MAC timing parameter when switching from one MAC core clock value to another one.

The macro first reads the parameter in the MAC HW register, apply the ratio and then write it back to the register.

Parameters:

  `[in]` | param | Name of the parameter
  `[in]` | old | Old clock value
  `[in]` | new | New clock value

Definition at line 115 of file hal_machw.c.

Referenced by hal_machw_setfreq().

#define TX_IRQ

Value:

    (NXMAC_AC_0_TX_TRIGGER_BIT | NXMAC_AC_1_TX_TRIGGER_BIT |                 \
                    NXMAC_AC_2_TX_TRIGGER_BIT | NXMAC_AC_3_TX_TRIGGER_BIT |                 \
                    NXMAC_BCN_TX_TRIGGER_BIT | NXMAC_AC_0_TX_BUF_TRIGGER_BIT |              \
                    NXMAC_AC_1_TX_BUF_TRIGGER_BIT | NXMAC_AC_2_TX_BUF_TRIGGER_BIT |         \
                    NXMAC_AC_3_TX_BUF_TRIGGER_BIT | NXMAC_BCN_TX_BUF_TRIGGER_BIT | MU_MIMO_MASTER_TX_IRQ)

TX interrupt bits.

Definition at line 68 of file hal_machw.c.

#define TX_SEC_IRQ_BITS

Value:

    ( NXMAC_SEC_U_3AC_3_TX_BUF_TRIGGER_BIT |             \
                               NXMAC_SEC_U_3AC_2_TX_BUF_TRIGGER_BIT |             \
                               NXMAC_SEC_U_3AC_1_TX_BUF_TRIGGER_BIT |             \
                               NXMAC_SEC_U_3AC_0_TX_BUF_TRIGGER_BIT |             \
                               NXMAC_SEC_U_3AC_3_TX_TRIGGER_BIT     |             \
                               NXMAC_SEC_U_3AC_2_TX_TRIGGER_BIT     |             \
                               NXMAC_SEC_U_3AC_1_TX_TRIGGER_BIT     |             \
                               NXMAC_SEC_U_3AC_0_TX_TRIGGER_BIT     |             \
                               NXMAC_SEC_U_2AC_3_TX_BUF_TRIGGER_BIT |             \
                               NXMAC_SEC_U_2AC_2_TX_BUF_TRIGGER_BIT |             \
                               NXMAC_SEC_U_2AC_1_TX_BUF_TRIGGER_BIT |             \
                               NXMAC_SEC_U_2AC_0_TX_BUF_TRIGGER_BIT |             \
                               NXMAC_SEC_U_2AC_3_TX_TRIGGER_BIT     |             \
                               NXMAC_SEC_U_2AC_2_TX_TRIGGER_BIT     |             \
                               NXMAC_SEC_U_2AC_1_TX_TRIGGER_BIT     |             \
                               NXMAC_SEC_U_2AC_0_TX_TRIGGER_BIT     |             \
                               NXMAC_SEC_U_1AC_3_TX_BUF_TRIGGER_BIT |             \
                               NXMAC_SEC_U_1AC_2_TX_BUF_TRIGGER_BIT |             \
                               NXMAC_SEC_U_1AC_1_TX_BUF_TRIGGER_BIT |             \
                               NXMAC_SEC_U_1AC_0_TX_BUF_TRIGGER_BIT |             \
                               NXMAC_SEC_U_1AC_3_TX_TRIGGER_BIT     |             \
                               NXMAC_SEC_U_1AC_2_TX_TRIGGER_BIT     |             \
                               NXMAC_SEC_U_1AC_1_TX_TRIGGER_BIT     |             \
                               NXMAC_SEC_U_1AC_0_TX_TRIGGER_BIT )

Bits indicating activity on secondary users (separated trigger and buffer).

Definition at line 53 of file hal_machw.h.

## Enumeration Type Documentation

anonymous enum

Mapping of HW timers.

Enumerator:

  HAL_AC0_TIMER | AC0 TX timeout.
  HAL_AC1_TIMER | AC1 TX timeout.
  HAL_AC2_TIMER | AC2 TX timeout.
  HAL_AC3_TIMER | AC3 TX timeout.
  HAL_BCN_TIMER | BCN TX timeout.
  HAL_IDLE_TIMER | Go to IDLE timeout.
  HAL_RX_TIMER | RX interrupt mitigation timeout.
  HAL_MM_TIMER | MM timeout.
  HAL_KE_TIMER | Kernel timer.
  HAL_TIMER_MAX | Number of HW timers used.

Definition at line 119 of file hal_machw.h.

anonymous enum

Bits associated to HW timers.

Enumerator:

  HAL_AC0_TIMER_BIT | AC0 TX timeout bit.
  HAL_AC1_TIMER_BIT | AC1 TX timeout bit.
  HAL_AC2_TIMER_BIT | AC2 TX timeout bit.
  HAL_AC3_TIMER_BIT | AC3 TX timeout bit.
  HAL_BCN_TIMER_BIT | BCN TX timeout bit.
  HAL_IDLE_TIMER_BIT | Go to IDLE timeout bit.
  HAL_RX_TIMER_BIT | RX interrupt mitigation timeout bit.
  HAL_MM_TIMER_BIT | MM timeout bit.
  HAL_KE_TIMER_BIT | Kernel timer bit.

Definition at line 153 of file hal_machw.h.

anonymous enum

For MAC HW States.

Enumerator:

  HW_IDLE | MAC HW IDLE State.
  HW_RESERVED | MAC HW RESERVED State.
  HW_DOZE | MAC HW DOZE State.
  HW_ACTIVE | MAC HW ACTIVE State.

Definition at line 87 of file hal_machw.h.

anonymous enum

802.11 modes

Enumerator:

  MODE_802_11B | 802.ll b
  MODE_802_11A | 802.11 a
  MODE_802_11G | 802.11 g
  MODE_802_11N_2_4 | 802.11n at 2.4GHz
  MODE_802_11N_5 | 802.11n at 5GHz
  MODE_RESERVED | Reserved for future use.
  MODE_802_11AC_5 | 802.11ac at 5GHz

Definition at line 100 of file hal_machw.h.

## Function Documentation

static void hal_machw_abs_timer_handler | ( | void |  | ) | `[static]`

Absolute timer interrupt Handler.

This function handles the HW timer interrupts. It checks the source of the interrupt and execute the required functions.

Definition at line 594 of file hal_machw.c.

References ASSERT_REC, HAL_AC0_TIMER_BIT, HAL_AC1_TIMER_BIT, HAL_AC2_TIMER_BIT, HAL_AC3_TIMER_BIT, HAL_BCN_TIMER_BIT, HAL_IDLE_TIMER_BIT, HAL_KE_TIMER_BIT, HAL_MM_TIMER_BIT, HAL_RX_TIMER_BIT, KE_EVT_KE_TIMER_BIT, KE_EVT_MM_TIMER_BIT, ke_evt_set(), and rxl_timeout_int_handler().

__INLINE bool hal_machw_bfmee_support | ( | void |  | ) |

Check whether BFMEE is supported by the MAC and PHY HW.

Returns:
  true if supported, false otherwise

Definition at line 300 of file hal_machw.h.

References phy_bfmee_supported().

Referenced by mm_version_req_handler().

__INLINE bool hal_machw_bfmer_support | ( | void |  | ) |

Check whether BFMER is supported by the MAC and PHY HW.

Returns:
  true if supported, false otherwise

Definition at line 312 of file hal_machw.h.

References phy_bfmer_supported().

void hal_machw_disable_int | ( | void |  | ) |

MAC HW interrupt disable function.

This function is part of the recovery mechanism invoked upon an error detection in the LMAC. It disables the MAC HW interrupts.

void hal_machw_gen_handler | ( | void |  | ) |

Interrupt Handling.

This function handles the general interrupts raised by the MAC HW.

__INLINE bool hal_machw_he_support | ( | void |  | ) |

Check whether HE is supported by the MAC and PHY HW.

Returns:
  true if supported, false otherwise

Definition at line 348 of file hal_machw.h.

References phy_he_supported().

Referenced by mm_set_vif_state_req_handler(), and mm_version_req_handler().

static void hal_machw_idle_irq_handler | ( | void |  | ) | `[static]`

IDLE Interrupt Handler.

This function handles the idle interrupt raised when the hardware changes to idle state. The PS module sets the HW to idle and waits for this interrupt to change the HW state to DOZE. The MAC management module uses this interrupt to program the HW to next relevant state.

Definition at line 156 of file hal_machw.c.

References ASSERT_REC, HAL_IDLE_TIMER_BIT, HW_IDLE, KE_EVT_HW_IDLE_BIT, ke_evt_set(), ps_env_tag::prevent_sleep, PROF_MM_HW_IDLE_CLR, ps_env, and PS_IDLE_REQ_PENDING.

void hal_machw_idle_req | ( | void |  | ) |

Ask to HW to move to IDLE state.

This function assumes that the HW is not in IDLE state when it is called.

Referenced by mm_force_idle_req_handler(), mm_hw_config_handler(), mm_set_idle_req_handler(), and mm_start_req_handler().

void hal_machw_init | ( | void |  | ) |

Interrupt Controller initialization.

This function initializes the interrupt control registers and enables the interrupts.

void hal_machw_monitor_mode | ( | void |  | ) |

Put back the MAC HW in monitoring mode.

This function has to be called when the last configured interface is removed.

Referenced by mm_remove_if_req_handler().

__INLINE bool hal_machw_mu_mimo_rx_support | ( | void |  | ) |

Check whether Mu-MIMO RX is supported by the MAC and PHY HW.

Returns:
  true if supported, false otherwise

Definition at line 324 of file hal_machw.h.

References phy_mu_mimo_rx_supported().

Referenced by mm_version_req_handler().

__INLINE bool hal_machw_mu_mimo_tx_support | ( | void |  | ) |

Check whether Mu-MIMO TX is supported by the MAC and PHY HW.

Returns:
  true if supported, false otherwise

Definition at line 336 of file hal_machw.h.

References phy_mu_mimo_tx_supported().

void hal_machw_reset | ( | void |  | ) |

MAC HW reset function.

This function is part of the recovery mechanism invoked upon an error detection in the LMAC. It resets the MAC HW state machines, which in consequence resets the PHY.

__INLINE uint32_t hal_machw_rx_bcn_duration | ( | struct rx_hd * | rhd,
|  | uint16_t | len |
| ) |  |  |

Compute duration it took to transmit the received frame.

Parameters:

  `[in]` | rhd | RX desciptor
  `[in]` | len | Length to consider

Returns:
  air time used to transmit `len` bytes of the received frame.

Definition at line 265 of file hal_machw.h.

References ASSERT_REC_VAL, hal_desc_get_legacy_rate(), hal_desc_get_preamble_type(), hal_desc_get_rx_format(), hal_machw_time(), rx_hd::rx_vec_1, and rxv2macrate.

uint8_t hal_machw_search_addr | ( | struct mac_addr * | addr | ) |

Function accessing the HW address search engine.

Parameters:

  `[in]` | addr | Pointer to the MAC address to search

Returns:
  The index of the station found in the address list if any, INVALID_STA_IDX otherwise

static void hal_machw_setfreq | ( | uint8_t | newfreq | ) | `[static]`

Updates the MAC HW timing registers according to the frequency actually used.

Parameters:

  `[in]` | newfreq | Frequency of the MAC HW core, in MHz

Definition at line 183 of file hal_machw.c.

References TIMING_UPDATE.

bool hal_machw_sleep_check | ( | void |  | ) |

Check if the HW timers don expire too early to go to sleep.

Returns:
  true if we can sleep, false otherwise.

void hal_machw_stop | ( | void |  | ) |

Stop the operation of the MAC HW.

This function stops the MAC HW operation and resets it.

Referenced by mm_reset_req_handler().

__INLINE uint32_t hal_machw_time | ( | void |  | ) |

Get the current HW time.

Returns:
  The value of nxmac_monotonic_counter_2_lo register.

Definition at line 198 of file hal_machw.h.

Referenced by bam_time_get(), bfr_end_calibration_for_sta(), chan_fix_ctxt_until(), chan_p2p_noa_tsf_updated(), chan_start_p2pgo_noa(), hal_machw_rx_bcn_duration(), hal_machw_time_past(), hal_machw_udelay(), ke_time(), la_dump_trace_timestamp_and_stop(), mm_ba_add_cfm_handler(), rxl_host_irq_mitigation_timeout_set(), rxu_cntrl_defrag_check(), rxu_cntrl_reord_check(), tdls_chsw_rsp_tx_cfm(), txl_frame_send_tdls_channel_switch_req_frame(), txl_timer_move(), and txl_timer_start().

__INLINE bool hal_machw_time_cmp | ( | uint32_t | time1,
|  | uint32_t | time2 |
| ) |  |  |

Compare timer absolute expiration time.

Parameters:

  `[in]` | time1 | First time to compare.
  `[in]` | time2 | Second time to compare.

Returns:
  true if time1 is earlier than time2.

Definition at line 213 of file hal_machw.h.

Referenced by chan_add_next_tbtt(), chan_fix_ctxt_until(), chan_schedule_extra_switch_from_p2pgo_ctxt(), chan_schedule_extra_switch_to_p2pgo_ctxt(), chan_schedule_switch_from_p2pgo_ctxt(), chan_schedule_switch_to_p2pgo_ctxt(), chan_start_p2pgo_noa(), chan_start_p2pgo_single_noa(), chan_tbtt_overlap(), chan_tbtt_skip_fix_ctxt(), chan_window_merge_duration(), cmp_abs_time(), hal_machw_time_past(), p2p_noa_timer_end(), and p2p_update_noa_presence_date().

__INLINE bool hal_machw_time_past | ( | uint32_t | time | ) |

Compare timer absolute expiration time.

Parameters:

  `[in]` | time | Time to compare.

Returns:
  true if time is in the past, false otherwise

Definition at line 234 of file hal_machw.h.

References hal_machw_time(), and hal_machw_time_cmp().

Referenced by bam_inactivity_timeout_ind_handler(), chan_start_p2pgo_noa(), chan_switch_set_timer(), hal_machw_udelay(), p2p_cli_noa_get_abs_time(), rxu_cntrl_reord_timeout_cb(), and tdls_check_frame_action().

int hal_machw_tsf_move | ( | int32_t | offset | ) |

Apply an offset (positive or negative) to the TSF timer.

A consequence of the TSF update will be a move of the TBTT. Note that this function should be called while the MAC HW is in IDLE state.

Parameters:

  `[in]` | offset | Offset to apply to the TSF

Returns:
  0 if the offset is applied, different from 0 otherwise.

Referenced by mm_tbtt_move_req_handler().

__INLINE void hal_machw_udelay | ( | uint32_t | us | ) |

Block execution for the given number of us.

Parameters:

  `[in]` | us | Number of us to wait for.

Definition at line 246 of file hal_machw.h.

References hal_machw_time(), and hal_machw_time_past().

## Variable Documentation

const uint8_t rxv2macrate[]

Initial value:

     {
        0,
        1,
        2,
        3,
        -1,
        -1,
        -1,
        -1,
        10,
        8,
        6,
        4,
        11,
        9,
        7,
        5
    }

Table of conversion between a RX vector rate to a MAC HW rate.

Definition at line 122 of file hal_machw.c.

Referenced by hal_machw_rx_bcn_duration().