SemiDrive SSDK Appication Program Interface PTG3.0
sdrv_eth.h
Go to the documentation of this file.
1
12#ifndef DWC_ETH_QOS_H
13#define DWC_ETH_QOS_H
14
15#include <stdint.h>
16#include <stdbool.h>
17#include "sdrv_ckgen.h"
18#include "sdrv_rstgen.h"
19#include "netdev.h"
20#include "../source/eth/sdrv_mac_lld.h"
21#include "../source/eth/phy/phy.h"
22
23#ifndef CONFIG_ETH_RX_DESCRIPTOR_NUM
24#define CONFIG_ETH_RX_DESCRIPTOR_NUM 32
25#endif
26
27#ifndef CONFIG_ETH_TX_DESCRIPTOR_NUM
28#define CONFIG_ETH_TX_DESCRIPTOR_NUM 32
29#endif
30
31/* assume ARCH_DMA_MINALIGN >= 16; 16 is the EQOS HW minimum */
32#define ARCH_DMA_MINALIGN CONFIG_ARCH_CACHE_LINE /* Should be cache line aligned */
33
34#define EQOS_DESCRIPTOR_ALIGN ARCH_DMA_MINALIGN
35#define EQOS_DESCRIPTORS_TX CONFIG_ETH_TX_DESCRIPTOR_NUM
36#define EQOS_DESCRIPTORS_RX CONFIG_ETH_RX_DESCRIPTOR_NUM
37#define EQOS_DESCRIPTORS_NUM (EQOS_DESCRIPTORS_TX + EQOS_DESCRIPTORS_RX)
38#define EQOS_BUFFER_ALIGN ARCH_DMA_MINALIGN
39#define EQOS_MAX_PACKET_SIZE ALIGN(1568, ARCH_DMA_MINALIGN)
40#define EQOS_RX_BUFFER_SIZE (EQOS_DESCRIPTORS_RX * EQOS_MAX_PACKET_SIZE)
41#define EQOS_TX_BUFFER_SIZE (EQOS_DESCRIPTORS_TX * EQOS_MAX_PACKET_SIZE)
42
43/* If rx api thread safe is guranteed by driver,
44 * the two following macros should be defined.
45 */
46#ifndef EQOS_RX_LOCK
47#define EQOS_RX_LOCK(eqos)
48#endif
49#ifndef EQOS_RX_UNLOCK
50#define EQOS_RX_UNLOCK(eqos)
51#endif
52
53/* If tx api thread safe is guranteed by driver,
54 * the two following macros should be defined.
55 */
56#ifndef EQOS_TX_LOCK
57#define EQOS_TX_LOCK(eqos)
58#endif
59#ifndef EQOS_TX_UNLOCK
60#define EQOS_TX_UNLOCK(eqos)
61#endif
62
63/* DMA descriptor */
64/* DO NOT align this struct to cache line length,
65 * because length of this struct is used to caculate
66 * DSL bit value of DMA_CH_CONTROL register.
67 * Aligning eqos dma descriptors to cache line length
68 * is done when allocating descriptors.
69 */
70struct eqos_desc {
71 volatile uint32_t des0;
72 volatile uint32_t des1;
73 volatile uint32_t des2;
74 volatile uint32_t des3;
75};
76
77#define EQOS_DESC3_OWN BIT(31)
78#define EQOS_DESC3_IOC BIT(30)
79#define EQOS_DESC3_FD BIT(29)
80#define EQOS_DESC3_LD BIT(28)
81#define EQOS_DESC3_BUF1V BIT(24)
82
83typedef enum {
87
88typedef enum {
89 /* Controller Disable */
91 /* Controller Enable */
94
95typedef enum {
96 /* add the MAC address to the filter, meaning allow reception */
98 /* remove the MAC address from the filter, meaning reception is blocked in the lower layer */
100
102
103typedef enum {
109
110typedef enum {
111 /* MAC layer interface (data) bandwith class 1Gbit/s (e.g. GMII, RGMII, SGMII, RvGMII, USGMII)*/
113 /* MAC layer interface (data) bandwith class 100Mbit/s (e.g. RMII, RvMII, SMII, RvMII) */
115 /* MAC layer interface (data) bandwith class 10Gbit/s */
118
119typedef enum {
120 LIGHT = 0,
127
128typedef enum {
139
140typedef struct {
141 uint32_t base;
142 uint32_t irq_num;
143 uint32_t mtu;
144 uint8_t *mac_addr;
145
146 /* Bus width, unit: bit. */
148
149 /* clock & reset */
155
156 /* mii interface config */
158 void (*set_phy_intf)(uint32_t base,
160
161 /* ipv4 config */
162 uint8_t ip[4];
163 uint8_t mask[4];
164
165 /* All PHYs connected to this mac */
166 phy_dev_t *phy;
168
169struct eqos_priv {
170 void *descs;
172 unsigned int desc_size;
173 /* Channel control register DSL bits. */
174 uint32_t dsl;
178};
179
180typedef void (*dma_rx_int_cb_t)(struct net_driver_s *dev);
181
182typedef struct dwc_eth_dev {
183 bool init;
187 phy_bus_t phy_bus;
188 void *(*to_cpu_addr)(void *slave_addr);
190
199void dwc_eth_enable_dma_rx_int(struct net_driver_s *dev, dma_rx_int_cb_t callback);
200
214int dwc_eth_rx(struct net_driver_s *dev, bool pool);
215
223int dwc_eth_probe(struct net_driver_s *dev, dwc_eth_config_t *cfg);
224
225#endif
SemiDrive clock generator driver header file.
eth_mac_layer_speed_type
Definition: sdrv_eth.h:103
@ ETH_MAC_LAYER_SPEED_1G
Definition: sdrv_eth.h:107
@ ETH_MAC_LAYER_SPEED_10G
Definition: sdrv_eth.h:105
@ ETH_MAC_LAYER_SPEED_10M
Definition: sdrv_eth.h:106
@ ETH_MAC_LAYER_SPEED_100M
Definition: sdrv_eth.h:104
eth_mode_type
Definition: sdrv_eth.h:88
@ ETH_MODE_DOWN
Definition: sdrv_eth.h:90
@ ETH_MODE_ACTIVE
Definition: sdrv_eth.h:92
eth_phy_intf_mode_type
Definition: sdrv_eth.h:128
@ ETH_PHY_INTF_SEL_SGMII
Definition: sdrv_eth.h:131
@ ETH_PHY_INTF_SEL_RMII
Definition: sdrv_eth.h:133
@ ETH_PHY_INTF_SEL_SMII
Definition: sdrv_eth.h:135
@ ETH_PHY_INTF_SEL_RTBI
Definition: sdrv_eth.h:134
@ ETH_PHY_INTF_SEL_RGMII
Definition: sdrv_eth.h:130
@ ETH_PHY_INTF_SEL_TBI
Definition: sdrv_eth.h:132
@ ETH_PHY_INTF_SEL_MII
Definition: sdrv_eth.h:137
@ ETH_PHY_INTF_SEL_REVMII
Definition: sdrv_eth.h:136
@ ETH_PHY_INTF_SEL_GMII
Definition: sdrv_eth.h:129
int dwc_eth_rx(struct net_driver_s *dev, bool pool)
try to read rx packet and send the packet to lwip stack. Should be called in thread context....
eth_filter_action_type
Definition: sdrv_eth.h:95
@ ETH_ADD_TO_FILTER
Definition: sdrv_eth.h:97
@ ETH_REMOVE_FROM_FILTER
Definition: sdrv_eth.h:99
eth_mac_layer_sub_type
Definition: sdrv_eth.h:119
@ REVERSED
Definition: sdrv_eth.h:122
@ STANDARD
Definition: sdrv_eth.h:124
@ REDUCED
Definition: sdrv_eth.h:121
@ SERIAL
Definition: sdrv_eth.h:123
@ UNIVERSAL_SERIAL
Definition: sdrv_eth.h:125
@ LIGHT
Definition: sdrv_eth.h:120
void(* dma_rx_int_cb_t)(struct net_driver_s *dev)
Definition: sdrv_eth.h:180
int dwc_eth_probe(struct net_driver_s *dev, dwc_eth_config_t *cfg)
Initializes net driver.
eth_mac_layer_type
Definition: sdrv_eth.h:110
@ ETH_MAC_LAYER_TYPE_XMII
Definition: sdrv_eth.h:114
@ ETH_MAC_LAYER_TYPE_XXGMII
Definition: sdrv_eth.h:116
@ ETH_MAC_LAYER_TYPE_XGMII
Definition: sdrv_eth.h:112
eth_idx_type
Definition: sdrv_eth.h:83
@ ETHERNET1_IDX
Definition: sdrv_eth.h:84
@ ETHERNET2_IDX
Definition: sdrv_eth.h:85
struct dwc_eth_dev dwc_eth_dev_t
void dwc_eth_enable_dma_rx_int(struct net_driver_s *dev, dma_rx_int_cb_t callback)
Enable rx interrupt.
SemiDrive Reset driver header file.
Definition: sdrv_eth.h:140
uint32_t base
Definition: sdrv_eth.h:141
uint8_t * mac_addr
Definition: sdrv_eth.h:144
uint8_t dma_bus_width
Definition: sdrv_eth.h:147
uint32_t mtu
Definition: sdrv_eth.h:143
sdrv_ckgen_node_t * rmii_clk
Definition: sdrv_eth.h:151
eth_phy_intf_mode_type phy_intf_mode
Definition: sdrv_eth.h:157
sdrv_ckgen_node_t * phy_ref_clk
Definition: sdrv_eth.h:152
phy_dev_t * phy
Definition: sdrv_eth.h:166
sdrv_rstgen_sig_t * rst
Definition: sdrv_eth.h:154
sdrv_ckgen_node_t * timer_sec_clk
Definition: sdrv_eth.h:153
sdrv_ckgen_node_t * tx_clk
Definition: sdrv_eth.h:150
uint32_t irq_num
Definition: sdrv_eth.h:142
Definition: sdrv_eth.h:182
struct eqos_priv * eqos
Definition: sdrv_eth.h:185
bool init
Definition: sdrv_eth.h:183
dma_rx_int_cb_t rx_cb
Definition: sdrv_eth.h:186
phy_bus_t phy_bus
Definition: sdrv_eth.h:187
dwc_eth_config_t * config
Definition: sdrv_eth.h:184
Definition: sdrv_eth.h:70
volatile uint32_t des3
Definition: sdrv_eth.h:74
volatile uint32_t des2
Definition: sdrv_eth.h:73
volatile uint32_t des1
Definition: sdrv_eth.h:72
volatile uint32_t des0
Definition: sdrv_eth.h:71
Definition: sdrv_eth.h:169
void * rx_dma_buf
Definition: sdrv_eth.h:176
void * descs
Definition: sdrv_eth.h:170
void * tx_dma_buf
Definition: sdrv_eth.h:175
bool started
Definition: sdrv_eth.h:177
int rx_desc_idx
Definition: sdrv_eth.h:171
int tx_desc_idx
Definition: sdrv_eth.h:171
uint32_t dsl
Definition: sdrv_eth.h:174
unsigned int desc_size
Definition: sdrv_eth.h:172
Abstract clock common node for driver operate.
Definition: sdrv_ckgen.h:175
SDRV rstgen signal.
Definition: sdrv_rstgen.h:84