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 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #ifndef _DAVINCI_EMAC_H_
23 #define _DAVINCI_EMAC_H_
24 /* Ethernet Min/Max packet size */
25 #define EMAC_MIN_ETHERNET_PKT_SIZE 60
26 #define EMAC_MAX_ETHERNET_PKT_SIZE 1518
27 /* Buffer size (should be aligned on 32 byte and cache line) */
28 #define EMAC_RXBUF_SIZE ALIGN(ALIGN(EMAC_MAX_ETHERNET_PKT_SIZE, 32),\
31 /* Number of RX packet buffers
32 * NOTE: Only 1 buffer supported as of now
34 #define EMAC_MAX_RX_BUFFERS 10
37 /***********************************************
38 ******** Internally used macros ***************
39 ***********************************************/
44 /* Each descriptor occupies 4 words, lets start RX desc's at 0 and
45 * reserve space for 64 descriptors max
47 #define EMAC_RX_DESC_BASE 0x0
48 #define EMAC_TX_DESC_BASE 0x1000
50 /* EMAC Teardown value */
51 #define EMAC_TEARDOWN_VALUE 0xfffffffc
53 /* MII Status Register */
54 #define MII_STATUS_REG 1
56 /* Number of statistics registers */
57 #define EMAC_NUM_STATS 36
61 typedef volatile struct _emac_desc
63 u_int32_t next; /* Pointer to next descriptor
65 u_int8_t *buffer; /* Pointer to data buffer */
66 u_int32_t buff_off_len; /* Buffer Offset(MSW) and Length(LSW) */
67 u_int32_t pkt_flag_len; /* Packet Flags(MSW) and Length(LSW) */
70 /* CPPI bit positions */
71 #define EMAC_CPPI_SOP_BIT (0x80000000)
72 #define EMAC_CPPI_EOP_BIT (0x40000000)
73 #define EMAC_CPPI_OWNERSHIP_BIT (0x20000000)
74 #define EMAC_CPPI_EOQ_BIT (0x10000000)
75 #define EMAC_CPPI_TEARDOWN_COMPLETE_BIT (0x08000000)
76 #define EMAC_CPPI_PASS_CRC_BIT (0x04000000)
78 #define EMAC_CPPI_RX_ERROR_FRAME (0x03fc0000)
80 #define EMAC_MACCONTROL_MIIEN_ENABLE (0x20)
81 #define EMAC_MACCONTROL_FULLDUPLEX_ENABLE (0x1)
82 #define EMAC_MACCONTROL_GIGABIT_ENABLE (1 << 7)
83 #define EMAC_MACCONTROL_GIGFORCE (1 << 17)
84 #define EMAC_MACCONTROL_RMIISPEED_100 (1 << 15)
86 #define EMAC_MAC_ADDR_MATCH (1 << 19)
87 #define EMAC_MAC_ADDR_IS_VALID (1 << 20)
89 #define EMAC_RXMBPENABLE_RXCAFEN_ENABLE (0x200000)
90 #define EMAC_RXMBPENABLE_RXBROADEN (0x2000)
93 #define MDIO_CONTROL_IDLE (0x80000000)
94 #define MDIO_CONTROL_ENABLE (0x40000000)
95 #define MDIO_CONTROL_FAULT_ENABLE (0x40000)
96 #define MDIO_CONTROL_FAULT (0x80000)
97 #define MDIO_USERACCESS0_GO (0x80000000)
98 #define MDIO_USERACCESS0_WRITE_READ (0x0)
99 #define MDIO_USERACCESS0_WRITE_WRITE (0x40000000)
100 #define MDIO_USERACCESS0_ACK (0x20000000)
102 /* Ethernet MAC Registers Structure */
113 dv_reg TXINTSTATMASKED;
115 dv_reg TXINTMASKCLEAR;
119 dv_reg RXINTSTATMASKED;
121 dv_reg RXINTMASKCLEAR;
122 dv_reg MACINTSTATRAW;
123 dv_reg MACINTSTATMASKED;
124 dv_reg MACINTMASKSET;
125 dv_reg MACINTMASKCLEAR;
129 dv_reg RXUNICASTCLEAR;
131 dv_reg RXBUFFEROFFSET;
132 dv_reg RXFILTERLOWTHRESH;
134 dv_reg RX0FLOWTHRESH;
135 dv_reg RX1FLOWTHRESH;
136 dv_reg RX2FLOWTHRESH;
137 dv_reg RX3FLOWTHRESH;
138 dv_reg RX4FLOWTHRESH;
139 dv_reg RX5FLOWTHRESH;
140 dv_reg RX6FLOWTHRESH;
141 dv_reg RX7FLOWTHRESH;
142 dv_reg RX0FREEBUFFER;
143 dv_reg RX1FREEBUFFER;
144 dv_reg RX2FREEBUFFER;
145 dv_reg RX3FREEBUFFER;
146 dv_reg RX4FREEBUFFER;
147 dv_reg RX5FREEBUFFER;
148 dv_reg RX6FREEBUFFER;
149 dv_reg RX7FREEBUFFER;
167 dv_reg RXBCASTFRAMES;
168 dv_reg RXMCASTFRAMES;
169 dv_reg RXPAUSEFRAMES;
171 dv_reg RXALIGNCODEERRORS;
177 dv_reg RXQOSFILTERED;
180 dv_reg TXBCASTFRAMES;
181 dv_reg TXMCASTFRAMES;
182 dv_reg TXPAUSEFRAMES;
187 dv_reg TXEXCESSIVECOLL;
190 dv_reg TXCARRIERSENSE;
196 dv_reg FRAME512T1023;
199 dv_reg RXSOFOVERRUNS;
200 dv_reg RXMOFOVERRUNS;
201 dv_reg RXDMAOVERRUNS;
241 /* EMAC Wrapper Registers Structure */
243 #ifdef DAVINCI_EMAC_VERSION2
259 dv_reg c0rxthreshstat;
263 dv_reg c1rxthreshstat;
267 dv_reg c2rxthreshstat;
278 u_int8_t RSVD0[4100];
284 /* EMAC MDIO Registers Structure */
291 dv_reg LINKINTMASKED;
294 dv_reg USERINTMASKED;
295 dv_reg USERINTMASKSET;
296 dv_reg USERINTMASKCLEAR;
304 int davinci_eth_phy_read(u_int8_t phy_addr, u_int8_t reg_num, u_int16_t *data);
305 int davinci_eth_phy_write(u_int8_t phy_addr, u_int8_t reg_num, u_int16_t data);
309 int (*init)(int phy_addr);
310 int (*is_phy_connected)(int phy_addr);
311 int (*get_link_speed)(int phy_addr);
312 int (*auto_negotiate)(int phy_addr);
315 #endif /* _DAVINCI_EMAC_H_ */