Loading...
Searching...
No Matches
greth.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2026 Matvii Ivashchenko
3 * SPDX-License-Identifier: LGPL-2.1-only
4 */
5
6#pragma once
7
33
34#include <stdint.h>
35#include <stdbool.h>
36
37#include "net/netdev.h"
38#include "net/netdev/eth.h"
39
40#ifdef __cplusplus
41extern "C" {
42#endif
43
48
54#ifndef CONFIG_GRETH_RX_DESC_NUM
55#define CONFIG_GRETH_RX_DESC_NUM (8U)
56#endif
57
63#ifndef CONFIG_GRETH_TX_DESC_NUM
64#define CONFIG_GRETH_TX_DESC_NUM (4U)
65#endif
66
70#define GRETH_MAX_FRAME_LEN (1518U)
71
75#define GRETH_BUF_SIZE (1536U)
76
80#define GRETH_ANEG_TIMEOUT (100000U)
82
89typedef struct {
90 volatile uint32_t ctrl;
91 volatile uint32_t addr;
93
97typedef struct {
98 uint32_t base_addr;
99 unsigned irq;
100 uint8_t mac[6];
102
109typedef struct {
111
115 uint8_t *tx_buf;
116
117 unsigned rx_idx;
118 unsigned tx_idx;
119
120 unsigned phy_addr;
121 bool gbit;
122} greth_t;
123
134void greth_setup(greth_t *dev, const greth_params_t *params, uint8_t index);
135
136#ifdef __cplusplus
137}
138#endif
139
Definitions for netdev common ethernet code.
Definitions low-level network driver interface.
void greth_setup(greth_t *dev, const greth_params_t *params, uint8_t index)
Set up the GRETH device descriptor.
struct netdev netdev_t
Forward declaration for netdev struct.
Definition netdev.h:285
GRETH buffer descriptor (8 bytes, must be kept at natural alignment)
Definition greth.h:89
volatile uint32_t addr
Physical address of the data buffer.
Definition greth.h:91
volatile uint32_t ctrl
Control/status word (see GRETH_BD_*)
Definition greth.h:90
GRETH driver parameters (board-level configuration)
Definition greth.h:97
unsigned irq
PLIC interrupt source number (e.g.
Definition greth.h:99
uint32_t base_addr
APB base address (e.g.
Definition greth.h:98
uint8_t mac[6]
Ethernet MAC address.
Definition greth.h:100
GRETH driver device descriptor.
Definition greth.h:109
bool gbit
True if gigabit mode is available.
Definition greth.h:121
unsigned phy_addr
PHY MDIO address, read from hardware.
Definition greth.h:120
unsigned rx_idx
Index of next RX descriptor to check.
Definition greth.h:117
greth_desc_t * tx_desc
TX descriptor ring.
Definition greth.h:113
unsigned tx_idx
Index of next TX descriptor to use.
Definition greth.h:118
greth_desc_t * rx_desc
RX descriptor ring.
Definition greth.h:114
uint8_t * tx_buf
flat TX frame buffer
Definition greth.h:115
const greth_params_t * params
Pointer to board configuration.
Definition greth.h:112
netdev_t netdev
netdev base — MUST be first
Definition greth.h:110