2 * Copyright (C) 2011 Ilya Yanok, Emcraft Systems
4 * Based on: mach-davinci/emac_defs.h
5 * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net>
7 * SPDX-License-Identifier: GPL-2.0+
10 #ifndef _DAVINCI_EMAC_H_
11 #define _DAVINCI_EMAC_H_
12 /* Ethernet Min/Max packet size */
13 #define EMAC_MIN_ETHERNET_PKT_SIZE 60
14 #define EMAC_MAX_ETHERNET_PKT_SIZE 1518
15 /* Buffer size (should be aligned on 32 byte and cache line) */
16 #define EMAC_RXBUF_SIZE ALIGN(ALIGN(EMAC_MAX_ETHERNET_PKT_SIZE, 32),\
19 /* Number of RX packet buffers
20 * NOTE: Only 1 buffer supported as of now
22 #define EMAC_MAX_RX_BUFFERS 10
25 /***********************************************
26 ******** Internally used macros ***************
27 ***********************************************/
32 /* Each descriptor occupies 4 words, lets start RX desc's at 0 and
33 * reserve space for 64 descriptors max
35 #define EMAC_RX_DESC_BASE 0x0
36 #define EMAC_TX_DESC_BASE 0x1000
38 /* EMAC Teardown value */
39 #define EMAC_TEARDOWN_VALUE 0xfffffffc
41 /* MII Status Register */
42 #define MII_STATUS_REG 1
43 /* PHY Configuration register */
44 #define PHY_CONF_TXCLKEN (1 << 5)
46 /* Number of statistics registers */
47 #define EMAC_NUM_STATS 36
51 typedef volatile struct _emac_desc
53 u_int32_t next; /* Pointer to next descriptor
55 u_int8_t *buffer; /* Pointer to data buffer */
56 u_int32_t buff_off_len; /* Buffer Offset(MSW) and Length(LSW) */
57 u_int32_t pkt_flag_len; /* Packet Flags(MSW) and Length(LSW) */
60 /* CPPI bit positions */
61 #define EMAC_CPPI_SOP_BIT (0x80000000)
62 #define EMAC_CPPI_EOP_BIT (0x40000000)
63 #define EMAC_CPPI_OWNERSHIP_BIT (0x20000000)
64 #define EMAC_CPPI_EOQ_BIT (0x10000000)
65 #define EMAC_CPPI_TEARDOWN_COMPLETE_BIT (0x08000000)
66 #define EMAC_CPPI_PASS_CRC_BIT (0x04000000)
68 #define EMAC_CPPI_RX_ERROR_FRAME (0x03fc0000)
70 #define EMAC_MACCONTROL_MIIEN_ENABLE (0x20)
71 #define EMAC_MACCONTROL_FULLDUPLEX_ENABLE (0x1)
72 #define EMAC_MACCONTROL_GIGABIT_ENABLE (1 << 7)
73 #define EMAC_MACCONTROL_GIGFORCE (1 << 17)
74 #define EMAC_MACCONTROL_RMIISPEED_100 (1 << 15)
76 #define EMAC_MAC_ADDR_MATCH (1 << 19)
77 #define EMAC_MAC_ADDR_IS_VALID (1 << 20)
79 #define EMAC_RXMBPENABLE_RXCAFEN_ENABLE (0x200000)
80 #define EMAC_RXMBPENABLE_RXBROADEN (0x2000)
83 #define MDIO_CONTROL_IDLE (0x80000000)
84 #define MDIO_CONTROL_ENABLE (0x40000000)
85 #define MDIO_CONTROL_FAULT_ENABLE (0x40000)
86 #define MDIO_CONTROL_FAULT (0x80000)
87 #define MDIO_USERACCESS0_GO (0x80000000)
88 #define MDIO_USERACCESS0_WRITE_READ (0x0)
89 #define MDIO_USERACCESS0_WRITE_WRITE (0x40000000)
90 #define MDIO_USERACCESS0_ACK (0x20000000)
92 /* Ethernet MAC Registers Structure */
103 dv_reg TXINTSTATMASKED;
105 dv_reg TXINTMASKCLEAR;
109 dv_reg RXINTSTATMASKED;
111 dv_reg RXINTMASKCLEAR;
112 dv_reg MACINTSTATRAW;
113 dv_reg MACINTSTATMASKED;
114 dv_reg MACINTMASKSET;
115 dv_reg MACINTMASKCLEAR;
119 dv_reg RXUNICASTCLEAR;
121 dv_reg RXBUFFEROFFSET;
122 dv_reg RXFILTERLOWTHRESH;
124 dv_reg RX0FLOWTHRESH;
125 dv_reg RX1FLOWTHRESH;
126 dv_reg RX2FLOWTHRESH;
127 dv_reg RX3FLOWTHRESH;
128 dv_reg RX4FLOWTHRESH;
129 dv_reg RX5FLOWTHRESH;
130 dv_reg RX6FLOWTHRESH;
131 dv_reg RX7FLOWTHRESH;
132 dv_reg RX0FREEBUFFER;
133 dv_reg RX1FREEBUFFER;
134 dv_reg RX2FREEBUFFER;
135 dv_reg RX3FREEBUFFER;
136 dv_reg RX4FREEBUFFER;
137 dv_reg RX5FREEBUFFER;
138 dv_reg RX6FREEBUFFER;
139 dv_reg RX7FREEBUFFER;
157 dv_reg RXBCASTFRAMES;
158 dv_reg RXMCASTFRAMES;
159 dv_reg RXPAUSEFRAMES;
161 dv_reg RXALIGNCODEERRORS;
167 dv_reg RXQOSFILTERED;
170 dv_reg TXBCASTFRAMES;
171 dv_reg TXMCASTFRAMES;
172 dv_reg TXPAUSEFRAMES;
177 dv_reg TXEXCESSIVECOLL;
180 dv_reg TXCARRIERSENSE;
186 dv_reg FRAME512T1023;
189 dv_reg RXSOFOVERRUNS;
190 dv_reg RXMOFOVERRUNS;
191 dv_reg RXDMAOVERRUNS;
231 /* EMAC Wrapper Registers Structure */
233 #ifdef DAVINCI_EMAC_VERSION2
249 dv_reg c0rxthreshstat;
253 dv_reg c1rxthreshstat;
257 dv_reg c2rxthreshstat;
268 u_int8_t RSVD0[4100];
274 /* EMAC MDIO Registers Structure */
281 dv_reg LINKINTMASKED;
284 dv_reg USERINTMASKED;
285 dv_reg USERINTMASKSET;
286 dv_reg USERINTMASKCLEAR;
294 int davinci_eth_phy_read(u_int8_t phy_addr, u_int8_t reg_num, u_int16_t *data);
295 int davinci_eth_phy_write(u_int8_t phy_addr, u_int8_t reg_num, u_int16_t data);
299 int (*init)(int phy_addr);
300 int (*is_phy_connected)(int phy_addr);
301 int (*get_link_speed)(int phy_addr);
302 int (*auto_negotiate)(int phy_addr);
305 #endif /* _DAVINCI_EMAC_H_ */