sunxi_emac.h revision 1.3 1 1.1 jmcneill /*-
2 1.1 jmcneill * Copyright (c) 2016 Jared McNeill <jmcneill (at) invisible.ca>
3 1.1 jmcneill * All rights reserved.
4 1.1 jmcneill *
5 1.1 jmcneill * Redistribution and use in source and binary forms, with or without
6 1.1 jmcneill * modification, are permitted provided that the following conditions
7 1.1 jmcneill * are met:
8 1.1 jmcneill * 1. Redistributions of source code must retain the above copyright
9 1.1 jmcneill * notice, this list of conditions and the following disclaimer.
10 1.1 jmcneill * 2. Redistributions in binary form must reproduce the above copyright
11 1.1 jmcneill * notice, this list of conditions and the following disclaimer in the
12 1.1 jmcneill * documentation and/or other materials provided with the distribution.
13 1.1 jmcneill *
14 1.1 jmcneill * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 1.1 jmcneill * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 1.1 jmcneill * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 1.1 jmcneill * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18 1.1 jmcneill * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19 1.1 jmcneill * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 1.1 jmcneill * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
21 1.1 jmcneill * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22 1.1 jmcneill * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 1.1 jmcneill * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 1.1 jmcneill * SUCH DAMAGE.
25 1.1 jmcneill *
26 1.1 jmcneill * $FreeBSD$
27 1.1 jmcneill */
28 1.1 jmcneill
29 1.1 jmcneill /*
30 1.1 jmcneill * Allwinner Gigabit Ethernet
31 1.1 jmcneill */
32 1.1 jmcneill
33 1.1 jmcneill #ifndef __SUNXI_EMAC_H__
34 1.1 jmcneill #define __SUNXI_EMAC_H__
35 1.1 jmcneill
36 1.1 jmcneill #define EMAC_BASIC_CTL_0 0x00
37 1.1 jmcneill #define BASIC_CTL_SPEED (0x3 << 2)
38 1.1 jmcneill #define BASIC_CTL_SPEED_SHIFT 2
39 1.1 jmcneill #define BASIC_CTL_SPEED_1000 0
40 1.1 jmcneill #define BASIC_CTL_SPEED_10 2
41 1.1 jmcneill #define BASIC_CTL_SPEED_100 3
42 1.1 jmcneill #define BASIC_CTL_LOOPBACK (1 << 1)
43 1.1 jmcneill #define BASIC_CTL_DUPLEX (1 << 0)
44 1.1 jmcneill #define EMAC_BASIC_CTL_1 0x04
45 1.1 jmcneill #define BASIC_CTL_BURST_LEN (0x3f << 24)
46 1.1 jmcneill #define BASIC_CTL_BURST_LEN_SHIFT 24
47 1.1 jmcneill #define BASIC_CTL_RX_TX_PRI (1 << 1)
48 1.1 jmcneill #define BASIC_CTL_SOFT_RST (1 << 0)
49 1.1 jmcneill #define EMAC_INT_STA 0x08
50 1.1 jmcneill #define RX_BUF_UA_INT (1 << 10)
51 1.1 jmcneill #define RX_INT (1 << 8)
52 1.1 jmcneill #define TX_UNDERFLOW_INT (1 << 4)
53 1.1 jmcneill #define TX_BUF_UA_INT (1 << 2)
54 1.1 jmcneill #define TX_DMA_STOPPED_INT (1 << 1)
55 1.1 jmcneill #define TX_INT (1 << 0)
56 1.1 jmcneill #define EMAC_INT_EN 0x0c
57 1.1 jmcneill #define RX_BUF_UA_INT_EN (1 << 10)
58 1.1 jmcneill #define RX_INT_EN (1 << 8)
59 1.1 jmcneill #define TX_UNDERFLOW_INT_EN (1 << 4)
60 1.1 jmcneill #define TX_BUF_UA_INT_EN (1 << 2)
61 1.1 jmcneill #define TX_DMA_STOPPED_INT_EN (1 << 1)
62 1.1 jmcneill #define TX_INT_EN (1 << 0)
63 1.1 jmcneill #define EMAC_TX_CTL_0 0x10
64 1.1 jmcneill #define TX_EN (1 << 31)
65 1.1 jmcneill #define EMAC_TX_CTL_1 0x14
66 1.1 jmcneill #define TX_DMA_START (1 << 31)
67 1.1 jmcneill #define TX_DMA_EN (1 << 30)
68 1.1 jmcneill #define TX_NEXT_FRAME (1 << 2)
69 1.1 jmcneill #define TX_MD (1 << 1)
70 1.1 jmcneill #define FLUSH_TX_FIFO (1 << 0)
71 1.1 jmcneill #define EMAC_TX_FLOW_CTL 0x1c
72 1.1 jmcneill #define PAUSE_TIME (0xffff << 4)
73 1.1 jmcneill #define PAUSE_TIME_SHIFT 4
74 1.1 jmcneill #define TX_FLOW_CTL_EN (1 << 0)
75 1.1 jmcneill #define EMAC_TX_DMA_LIST 0x20
76 1.1 jmcneill #define EMAC_RX_CTL_0 0x24
77 1.1 jmcneill #define RX_EN (1 << 31)
78 1.1 jmcneill #define JUMBO_FRM_EN (1 << 29)
79 1.1 jmcneill #define STRIP_FCS (1 << 28)
80 1.1 jmcneill #define CHECK_CRC (1 << 27)
81 1.1 jmcneill #define RX_FLOW_CTL_EN (1 << 16)
82 1.1 jmcneill #define EMAC_RX_CTL_1 0x28
83 1.1 jmcneill #define RX_DMA_START (1 << 31)
84 1.1 jmcneill #define RX_DMA_EN (1 << 30)
85 1.1 jmcneill #define RX_MD (1 << 1)
86 1.1 jmcneill #define EMAC_RX_DMA_LIST 0x34
87 1.1 jmcneill #define EMAC_RX_FRM_FLT 0x38
88 1.1 jmcneill #define DIS_ADDR_FILTER (1 << 31)
89 1.1 jmcneill #define DIS_BROADCAST (1 << 17)
90 1.1 jmcneill #define RX_ALL_MULTICAST (1 << 16)
91 1.1 jmcneill #define CTL_FRM_FILTER (0x3 << 12)
92 1.1 jmcneill #define CTL_FRM_FILTER_SHIFT 12
93 1.1 jmcneill #define HASH_MULTICAST (1 << 9)
94 1.1 jmcneill #define HASH_UNICAST (1 << 8)
95 1.1 jmcneill #define SA_FILTER_EN (1 << 6)
96 1.1 jmcneill #define SA_INV_FILTER (1 << 5)
97 1.1 jmcneill #define DA_INV_FILTER (1 << 4)
98 1.1 jmcneill #define FLT_MD (1 << 1)
99 1.1 jmcneill #define RX_ALL (1 << 0)
100 1.1 jmcneill #define EMAC_RX_HASH_0 0x40
101 1.1 jmcneill #define EMAC_RX_HASH_1 0x44
102 1.1 jmcneill #define EMAC_MII_CMD 0x48
103 1.1 jmcneill #define MDC_DIV_RATIO_M (0x7 << 20)
104 1.1 jmcneill #define MDC_DIV_RATIO_M_16 0
105 1.1 jmcneill #define MDC_DIV_RATIO_M_32 1
106 1.1 jmcneill #define MDC_DIV_RATIO_M_64 2
107 1.1 jmcneill #define MDC_DIV_RATIO_M_128 3
108 1.1 jmcneill #define MDC_DIV_RATIO_M_SHIFT 20
109 1.1 jmcneill #define PHY_ADDR (0x1f << 12)
110 1.1 jmcneill #define PHY_ADDR_SHIFT 12
111 1.1 jmcneill #define PHY_REG_ADDR (0x1f << 4)
112 1.1 jmcneill #define PHY_REG_ADDR_SHIFT 4
113 1.1 jmcneill #define MII_WR (1 << 1)
114 1.1 jmcneill #define MII_BUSY (1 << 0)
115 1.1 jmcneill #define EMAC_MII_DATA 0x4c
116 1.1 jmcneill #define EMAC_ADDR_HIGH(n) (0x50 + (n) * 8)
117 1.1 jmcneill #define EMAC_ADDR_LOW(n) (0x54 + (n) * 8)
118 1.3 jmcneill #define EMAC_TX_DMA_STA 0xb0
119 1.3 jmcneill #define EMAC_TX_DMA_CUR_DESC 0xb4
120 1.3 jmcneill #define EMAC_TX_DMA_CUR_BUF 0xb8
121 1.1 jmcneill #define EMAC_RX_DMA_STA 0xc0
122 1.1 jmcneill #define EMAC_RX_DMA_CUR_DESC 0xc4
123 1.1 jmcneill #define EMAC_RX_DMA_CUR_BUF 0xc8
124 1.1 jmcneill #define EMAC_RGMII_STA 0xd0
125 1.1 jmcneill
126 1.1 jmcneill struct sunxi_emac_desc {
127 1.1 jmcneill uint32_t status;
128 1.1 jmcneill /* Transmit */
129 1.1 jmcneill #define TX_DESC_CTL (1 << 31)
130 1.1 jmcneill #define TX_HEADER_ERR (1 << 16)
131 1.1 jmcneill #define TX_LENGTH_ERR (1 << 14)
132 1.1 jmcneill #define TX_PAYLOAD_ERR (1 << 12)
133 1.1 jmcneill #define TX_CRS_ERR (1 << 10)
134 1.1 jmcneill #define TX_COL_ERR_0 (1 << 9)
135 1.1 jmcneill #define TX_COL_ERR_1 (1 << 8)
136 1.1 jmcneill #define TX_COL_CNT (0xf << 3)
137 1.1 jmcneill #define TX_COL_CNT_SHIFT 3
138 1.1 jmcneill #define TX_DEFER_ERR (1 << 2)
139 1.1 jmcneill #define TX_UNDERFLOW_ERR (1 << 1)
140 1.1 jmcneill #define TX_DEFER (1 << 0)
141 1.1 jmcneill /* Receive */
142 1.1 jmcneill #define RX_DESC_CTL (1 << 31)
143 1.1 jmcneill #define RX_DAF_FAIL (1 << 30)
144 1.1 jmcneill #define RX_FRM_LEN (0x3fff << 16)
145 1.1 jmcneill #define RX_FRM_LEN_SHIFT 16
146 1.1 jmcneill #define RX_NO_ENOUGH_BUF_ERR (1 << 14)
147 1.1 jmcneill #define RX_SAF_FAIL (1 << 13)
148 1.1 jmcneill #define RX_OVERFLOW_ERR (1 << 11)
149 1.1 jmcneill #define RX_FIR_DESC (1 << 9)
150 1.1 jmcneill #define RX_LAST_DESC (1 << 8)
151 1.1 jmcneill #define RX_HEADER_ERR (1 << 7)
152 1.1 jmcneill #define RX_COL_ERR (1 << 6)
153 1.1 jmcneill #define RX_FRM_TYPE (1 << 5)
154 1.1 jmcneill #define RX_LENGTH_ERR (1 << 4)
155 1.1 jmcneill #define RX_PHY_ERR (1 << 3)
156 1.1 jmcneill #define RX_CRC_ERR (1 << 1)
157 1.1 jmcneill #define RX_PAYLOAD_ERR (1 << 0)
158 1.1 jmcneill
159 1.1 jmcneill uint32_t size;
160 1.1 jmcneill /* Transmit */
161 1.1 jmcneill #define TX_INT_CTL (1 << 31)
162 1.1 jmcneill #define TX_LAST_DESC (1 << 30)
163 1.1 jmcneill #define TX_FIR_DESC (1 << 29)
164 1.1 jmcneill #define TX_CHECKSUM_CTL (0x3 << 27)
165 1.1 jmcneill #define TX_CHECKSUM_CTL_IP 1
166 1.1 jmcneill #define TX_CHECKSUM_CTL_NO_PSE 2
167 1.1 jmcneill #define TX_CHECKSUM_CTL_FULL 3
168 1.1 jmcneill #define TX_CHECKSUM_CTL_SHIFT 27
169 1.1 jmcneill #define TX_CRC_CTL (1 << 26)
170 1.1 jmcneill #define TX_BUF_SIZE (0xfff << 0)
171 1.1 jmcneill #define TX_BUF_SIZE_SHIFT 0
172 1.1 jmcneill /* Receive */
173 1.1 jmcneill #define RX_INT_CTL (1 << 31)
174 1.1 jmcneill #define RX_BUF_SIZE (0xfff << 0)
175 1.1 jmcneill #define RX_BUF_SIZE_SHIFT 0
176 1.1 jmcneill
177 1.1 jmcneill uint32_t addr;
178 1.1 jmcneill
179 1.1 jmcneill uint32_t next;
180 1.1 jmcneill } __packed __aligned(CACHE_LINE_SIZE);
181 1.1 jmcneill
182 1.1 jmcneill __CTASSERT(sizeof(struct sunxi_emac_desc) == CACHE_LINE_SIZE);
183 1.1 jmcneill
184 1.1 jmcneill #endif /* !__SUNXI_EMAC_H__ */
185