xref: /freebsd/sys/dev/nge/if_ngereg.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
1098ca2bdSWarner Losh /*-
2df57947fSPedro F. Giffuni  * SPDX-License-Identifier: BSD-4-Clause
3df57947fSPedro F. Giffuni  *
4ce4946daSBill Paul  * Copyright (c) 2001 Wind River Systems
5ce4946daSBill Paul  * Copyright (c) 1997, 1998, 1999, 2000, 2001
6ce4946daSBill Paul  *	Bill Paul <wpaul@bsdi.com>.  All rights reserved.
7ce4946daSBill Paul  *
8ce4946daSBill Paul  * Redistribution and use in source and binary forms, with or without
9ce4946daSBill Paul  * modification, are permitted provided that the following conditions
10ce4946daSBill Paul  * are met:
11ce4946daSBill Paul  * 1. Redistributions of source code must retain the above copyright
12ce4946daSBill Paul  *    notice, this list of conditions and the following disclaimer.
13ce4946daSBill Paul  * 2. Redistributions in binary form must reproduce the above copyright
14ce4946daSBill Paul  *    notice, this list of conditions and the following disclaimer in the
15ce4946daSBill Paul  *    documentation and/or other materials provided with the distribution.
16ce4946daSBill Paul  * 3. All advertising materials mentioning features or use of this software
17ce4946daSBill Paul  *    must display the following acknowledgement:
18ce4946daSBill Paul  *	This product includes software developed by Bill Paul.
19ce4946daSBill Paul  * 4. Neither the name of the author nor the names of any co-contributors
20ce4946daSBill Paul  *    may be used to endorse or promote products derived from this software
21ce4946daSBill Paul  *    without specific prior written permission.
22ce4946daSBill Paul  *
23ce4946daSBill Paul  * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
24ce4946daSBill Paul  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25ce4946daSBill Paul  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26ce4946daSBill Paul  * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
27ce4946daSBill Paul  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28ce4946daSBill Paul  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29ce4946daSBill Paul  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30ce4946daSBill Paul  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31ce4946daSBill Paul  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32ce4946daSBill Paul  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
33ce4946daSBill Paul  * THE POSSIBILITY OF SUCH DAMAGE.
34ce4946daSBill Paul  */
35ce4946daSBill Paul 
36ce4946daSBill Paul #define NGE_CSR			0x00
37ce4946daSBill Paul #define NGE_CFG			0x04
38ce4946daSBill Paul #define NGE_MEAR		0x08
39ce4946daSBill Paul #define NGE_PCITST		0x0C
40ce4946daSBill Paul #define NGE_ISR			0x10
41ce4946daSBill Paul #define NGE_IMR			0x14
42ce4946daSBill Paul #define NGE_IER			0x18
43ce4946daSBill Paul #define NGE_IHR			0x1C
44ce4946daSBill Paul #define NGE_TX_LISTPTR_LO	0x20
45ce4946daSBill Paul #define NGE_TX_LISTPTR_HI	0x24
46ce4946daSBill Paul #define NGE_TX_LISTPTR		NGE_TX_LISTPTR_LO
47ce4946daSBill Paul #define NGE_TX_CFG		0x28
48ce4946daSBill Paul #define NGE_GPIO		0x2C
49ce4946daSBill Paul #define NGE_RX_LISTPTR_LO	0x30
50ce4946daSBill Paul #define NGE_RX_LISTPTR_HI	0x34
51ce4946daSBill Paul #define NGE_RX_LISTPTR		NGE_RX_LISTPTR_LO
52ce4946daSBill Paul #define NGE_RX_CFG		0x38
53ce4946daSBill Paul #define NGE_PRIOQCTL		0x3C
54ce4946daSBill Paul #define NGE_WOLCSR		0x40
55ce4946daSBill Paul #define NGE_PAUSECSR		0x44
56ce4946daSBill Paul #define NGE_RXFILT_CTL		0x48
57ce4946daSBill Paul #define NGE_RXFILT_DATA		0x4C
58ce4946daSBill Paul #define NGE_BOOTROM_ADDR	0x50
59ce4946daSBill Paul #define NGE_BOOTROM_DATA	0x54
60ce4946daSBill Paul #define NGE_SILICONREV		0x58
61ce4946daSBill Paul #define NGE_MIBCTL		0x5C
62ce4946daSBill Paul #define NGE_MIB_RXERRPKT	0x60
63ce4946daSBill Paul #define NGE_MIB_RXERRFCS	0x64
64ce4946daSBill Paul #define NGE_MIB_RXERRMISSEDPKT	0x68
65ce4946daSBill Paul #define NGE_MIB_RXERRALIGN	0x6C
66ce4946daSBill Paul #define NGE_MIB_RXERRSYM	0x70
67ce4946daSBill Paul #define NGE_MIB_RXERRGIANT	0x74
68ce4946daSBill Paul #define NGE_MIB_RXERRRANGLEN	0x78
69ce4946daSBill Paul #define NGE_MIB_RXBADOPCODE	0x7C
70ce4946daSBill Paul #define NGE_MIB_RXPAUSEPKTS	0x80
71ce4946daSBill Paul #define NGE_MIB_TXPAUSEPKTS	0x84
72ce4946daSBill Paul #define NGE_MIB_TXERRSQE	0x88
73ce4946daSBill Paul #define NGE_TXPRIOQ_PTR1	0xA0
74ce4946daSBill Paul #define NGE_TXPRIOQ_PTR2	0xA4
75ce4946daSBill Paul #define NGE_TXPRIOQ_PTR3	0xA8
76ce4946daSBill Paul #define NGE_RXPRIOQ_PTR1	0xB0
77ce4946daSBill Paul #define NGE_RXPRIOQ_PTR2	0xB4
78ce4946daSBill Paul #define NGE_RXPRIOQ_PTR3	0xB8
79ce4946daSBill Paul #define NGE_VLAN_IP_RXCTL	0xBC
80ce4946daSBill Paul #define NGE_VLAN_IP_TXCTL	0xC0
81ce4946daSBill Paul #define NGE_VLAN_DATA		0xC4
82ce4946daSBill Paul #define NGE_CLKRUN		0xCC
83ce4946daSBill Paul #define NGE_TBI_BMCR		0xE0
84ce4946daSBill Paul #define NGE_TBI_BMSR		0xE4
85ce4946daSBill Paul #define NGE_TBI_ANAR		0xE8
86ce4946daSBill Paul #define NGE_TBI_ANLPAR		0xEC
87ce4946daSBill Paul #define NGE_TBI_ANER		0xF0
88ce4946daSBill Paul #define NGE_TBI_ESR		0xF4
89ce4946daSBill Paul 
90ce4946daSBill Paul /* Control/status register */
91ce4946daSBill Paul #define NGE_CSR_TX_ENABLE	0x00000001
92ce4946daSBill Paul #define NGE_CSR_TX_DISABLE	0x00000002
93ce4946daSBill Paul #define NGE_CSR_RX_ENABLE	0x00000004
94ce4946daSBill Paul #define NGE_CSR_RX_DISABLE	0x00000008
95ce4946daSBill Paul #define NGE_CSR_TX_RESET	0x00000010
96ce4946daSBill Paul #define NGE_CSR_RX_RESET	0x00000020
97ce4946daSBill Paul #define NGE_CSR_SOFTINTR	0x00000080
98ce4946daSBill Paul #define NGE_CSR_RESET		0x00000100
99ce4946daSBill Paul #define NGE_CSR_TX_PRIOQ_ENB0	0x00000200
100ce4946daSBill Paul #define NGE_CSR_TX_PRIOQ_ENB1	0x00000400
101ce4946daSBill Paul #define NGE_CSR_TX_PRIOQ_ENB2	0x00000800
102ce4946daSBill Paul #define NGE_CSR_TX_PRIOQ_ENB3	0x00001000
103ce4946daSBill Paul #define NGE_CSR_RX_PRIOQ_ENB0	0x00002000
104ce4946daSBill Paul #define NGE_CSR_RX_PRIOQ_ENB1	0x00004000
105ce4946daSBill Paul #define NGE_CSR_RX_PRIOQ_ENB2	0x00008000
106ce4946daSBill Paul #define NGE_CSR_RX_PRIOQ_ENB3	0x00010000
107ce4946daSBill Paul 
108ce4946daSBill Paul /* Configuration register */
109ce4946daSBill Paul #define NGE_CFG_BIGENDIAN	0x00000001
110ce4946daSBill Paul #define NGE_CFG_EXT_125MHZ	0x00000002
111ce4946daSBill Paul #define NGE_CFG_BOOTROM_DIS	0x00000004
112ce4946daSBill Paul #define NGE_CFG_PERR_DETECT	0x00000008
113ce4946daSBill Paul #define NGE_CFG_DEFER_DISABLE	0x00000010
114ce4946daSBill Paul #define NGE_CFG_OUTOFWIN_TIMER	0x00000020
115ce4946daSBill Paul #define NGE_CFG_SINGLE_BACKOFF	0x00000040
116ce4946daSBill Paul #define NGE_CFG_PCIREQ_ALG	0x00000080
117ce4946daSBill Paul #define NGE_CFG_EXTSTS_ENB	0x00000100
118ce4946daSBill Paul #define NGE_CFG_PHY_DIS		0x00000200
119ce4946daSBill Paul #define NGE_CFG_PHY_RST		0x00000400
120ce4946daSBill Paul #define NGE_CFG_64BIT_ADDR_ENB	0x00000800
121ce4946daSBill Paul #define NGE_CFG_64BIT_DATA_ENB	0x00001000
122ce4946daSBill Paul #define NGE_CFG_64BIT_PCI_DET	0x00002000
123ce4946daSBill Paul #define NGE_CFG_64BIT_TARG	0x00004000
124ce4946daSBill Paul #define NGE_CFG_MWI_DIS		0x00008000
125ce4946daSBill Paul #define NGE_CFG_MRM_DIS		0x00010000
126ce4946daSBill Paul #define NGE_CFG_TMRTST		0x00020000
127ce4946daSBill Paul #define NGE_CFG_PHYINTR_SPD	0x00040000
128ce4946daSBill Paul #define NGE_CFG_PHYINTR_LNK	0x00080000
129ce4946daSBill Paul #define NGE_CFG_PHYINTR_DUP	0x00100000
130ce4946daSBill Paul #define NGE_CFG_MODE_1000	0x00400000
1311f548804SDoug Ambrisko #define NGE_CFG_TBI_EN		0x01000000
132ce4946daSBill Paul #define NGE_CFG_DUPLEX_STS	0x10000000
133ce4946daSBill Paul #define NGE_CFG_SPEED_STS	0x60000000
134ce4946daSBill Paul #define NGE_CFG_LINK_STS	0x80000000
135ce4946daSBill Paul 
136ce4946daSBill Paul /* MII/EEPROM control register */
137ce4946daSBill Paul #define NGE_MEAR_EE_DIN		0x00000001
138ce4946daSBill Paul #define NGE_MEAR_EE_DOUT	0x00000002
139ce4946daSBill Paul #define NGE_MEAR_EE_CLK		0x00000004
140ce4946daSBill Paul #define NGE_MEAR_EE_CSEL	0x00000008
141ce4946daSBill Paul #define NGE_MEAR_MII_DATA	0x00000010
142ce4946daSBill Paul #define NGE_MEAR_MII_DIR	0x00000020
143ce4946daSBill Paul #define NGE_MEAR_MII_CLK	0x00000040
144ce4946daSBill Paul 
145ce4946daSBill Paul #define NGE_EECMD_WRITE		0x140
146ce4946daSBill Paul #define NGE_EECMD_READ		0x180
147ce4946daSBill Paul #define NGE_EECMD_ERASE		0x1c0
148ce4946daSBill Paul 
149ce4946daSBill Paul #define NGE_EE_NODEADDR		0xA
150ce4946daSBill Paul 
151ce4946daSBill Paul /* PCI control register */
152ce4946daSBill Paul #define NGE_PCICTL_SRAMADDR	0x0000001F
153ce4946daSBill Paul #define NGE_PCICTL_RAMTSTENB	0x00000020
154ce4946daSBill Paul #define NGE_PCICTL_TXTSTENB	0x00000040
155ce4946daSBill Paul #define NGE_PCICTL_RXTSTENB	0x00000080
156ce4946daSBill Paul #define NGE_PCICTL_BMTSTENB	0x00000200
157ce4946daSBill Paul #define NGE_PCICTL_RAMADDR	0x001F0000
158ce4946daSBill Paul #define NGE_PCICTL_ROMTIME	0x0F000000
159ce4946daSBill Paul #define NGE_PCICTL_DISCTEST	0x40000000
160ce4946daSBill Paul 
161ce4946daSBill Paul /* Interrupt/status register */
162ce4946daSBill Paul #define NGE_ISR_RX_OK		0x00000001
163ce4946daSBill Paul #define NGE_ISR_RX_DESC_OK	0x00000002
164ce4946daSBill Paul #define NGE_ISR_RX_ERR		0x00000004
165ce4946daSBill Paul #define NGE_ISR_RX_EARLY	0x00000008
166ce4946daSBill Paul #define NGE_ISR_RX_IDLE		0x00000010
167ce4946daSBill Paul #define NGE_ISR_RX_OFLOW	0x00000020
168ce4946daSBill Paul #define NGE_ISR_TX_OK		0x00000040
169ce4946daSBill Paul #define NGE_ISR_TX_DESC_OK	0x00000080
170ce4946daSBill Paul #define NGE_ISR_TX_ERR		0x00000100
171ce4946daSBill Paul #define NGE_ISR_TX_IDLE		0x00000200
172ce4946daSBill Paul #define NGE_ISR_TX_UFLOW	0x00000400
173ce4946daSBill Paul #define NGE_ISR_MIB_SERVICE	0x00000800
174ce4946daSBill Paul #define NGE_ISR_SOFTINTR	0x00001000
175ce4946daSBill Paul #define NGE_ISR_PME_EVENT	0x00002000
176ce4946daSBill Paul #define NGE_ISR_PHY_INTR	0x00004000
177ce4946daSBill Paul #define NGE_ISR_HIBITS		0x00008000
178ce4946daSBill Paul #define NGE_ISR_RX_FIFO_OFLOW	0x00010000
179ce4946daSBill Paul #define NGE_ISR_TGT_ABRT	0x00020000
180ce4946daSBill Paul #define NGE_ISR_BM_ABRT		0x00040000
181ce4946daSBill Paul #define NGE_ISR_SYSERR		0x00080000
182ce4946daSBill Paul #define NGE_ISR_PARITY_ERR	0x00100000
183ce4946daSBill Paul #define NGE_ISR_RX_RESET_DONE	0x00200000
184ce4946daSBill Paul #define NGE_ISR_TX_RESET_DONE	0x00400000
185ce4946daSBill Paul #define NGE_ISR_RX_PRIOQ_DESC0	0x00800000
186ce4946daSBill Paul #define NGE_ISR_RX_PRIOQ_DESC1	0x01000000
187ce4946daSBill Paul #define NGE_ISR_RX_PRIOQ_DESC2	0x02000000
188ce4946daSBill Paul #define NGE_ISR_RX_PRIOQ_DESC3	0x04000000
189ce4946daSBill Paul #define NGE_ISR_TX_PRIOQ_DESC0	0x08000000
190ce4946daSBill Paul #define NGE_ISR_TX_PRIOQ_DESC1	0x10000000
191ce4946daSBill Paul #define NGE_ISR_TX_PRIOQ_DESC2	0x20000000
192ce4946daSBill Paul #define NGE_ISR_TX_PRIOQ_DESC3	0x40000000
193ce4946daSBill Paul 
194ce4946daSBill Paul /* Interrupt mask register */
195ce4946daSBill Paul #define NGE_IMR_RX_OK		0x00000001
196ce4946daSBill Paul #define NGE_IMR_RX_DESC_OK	0x00000002
197ce4946daSBill Paul #define NGE_IMR_RX_ERR		0x00000004
198ce4946daSBill Paul #define NGE_IMR_RX_EARLY	0x00000008
199ce4946daSBill Paul #define NGE_IMR_RX_IDLE		0x00000010
200ce4946daSBill Paul #define NGE_IMR_RX_OFLOW	0x00000020
201ce4946daSBill Paul #define NGE_IMR_TX_OK		0x00000040
202ce4946daSBill Paul #define NGE_IMR_TX_DESC_OK	0x00000080
203ce4946daSBill Paul #define NGE_IMR_TX_ERR		0x00000100
204ce4946daSBill Paul #define NGE_IMR_TX_IDLE		0x00000200
205ce4946daSBill Paul #define NGE_IMR_TX_UFLOW	0x00000400
206ce4946daSBill Paul #define NGE_IMR_MIB_SERVICE	0x00000800
207ce4946daSBill Paul #define NGE_IMR_SOFTINTR	0x00001000
208ce4946daSBill Paul #define NGE_IMR_PME_EVENT	0x00002000
209ce4946daSBill Paul #define NGE_IMR_PHY_INTR	0x00004000
210ce4946daSBill Paul #define NGE_IMR_HIBITS		0x00008000
211ce4946daSBill Paul #define NGE_IMR_RX_FIFO_OFLOW	0x00010000
212ce4946daSBill Paul #define NGE_IMR_TGT_ABRT	0x00020000
213ce4946daSBill Paul #define NGE_IMR_BM_ABRT		0x00040000
214ce4946daSBill Paul #define NGE_IMR_SYSERR		0x00080000
215ce4946daSBill Paul #define NGE_IMR_PARITY_ERR	0x00100000
216ce4946daSBill Paul #define NGE_IMR_RX_RESET_DONE	0x00200000
217ce4946daSBill Paul #define NGE_IMR_TX_RESET_DONE	0x00400000
218ce4946daSBill Paul #define NGE_IMR_RX_PRIOQ_DESC0	0x00800000
219ce4946daSBill Paul #define NGE_IMR_RX_PRIOQ_DESC1	0x01000000
220ce4946daSBill Paul #define NGE_IMR_RX_PRIOQ_DESC2	0x02000000
221ce4946daSBill Paul #define NGE_IMR_RX_PRIOQ_DESC3	0x04000000
222ce4946daSBill Paul #define NGE_IMR_TX_PRIOQ_DESC0	0x08000000
223ce4946daSBill Paul #define NGE_IMR_TX_PRIOQ_DESC1	0x10000000
224ce4946daSBill Paul #define NGE_IMR_TX_PRIOQ_DESC2	0x20000000
225ce4946daSBill Paul #define NGE_IMR_TX_PRIOQ_DESC3	0x40000000
226ce4946daSBill Paul 
227ce4946daSBill Paul #define NGE_INTRS	\
228ce4946daSBill Paul 	(NGE_IMR_RX_OFLOW|NGE_IMR_TX_UFLOW|NGE_IMR_TX_OK|\
229ce4946daSBill Paul 	 NGE_IMR_TX_IDLE|NGE_IMR_RX_OK|NGE_IMR_RX_ERR|\
230ff7ed9f7SPoul-Henning Kamp 	 NGE_IMR_SYSERR|NGE_IMR_PHY_INTR|\
231ff7ed9f7SPoul-Henning Kamp 	 NGE_IMR_RX_IDLE|NGE_IMR_RX_FIFO_OFLOW)
232ce4946daSBill Paul 
233ce4946daSBill Paul /* Interrupt enable register */
234ce4946daSBill Paul #define NGE_IER_INTRENB		0x00000001
235ce4946daSBill Paul 
236ce4946daSBill Paul /* Interrupt moderation timer register */
237ce4946daSBill Paul #define NGE_IHR_HOLDOFF		0x000000FF
238ce4946daSBill Paul #define NGE_IHR_HOLDCTL		0x00000100
239ce4946daSBill Paul 
240ce4946daSBill Paul /* Transmit configuration register */
241ce4946daSBill Paul #define NGE_TXCFG_DRAIN_THRESH	0x000000FF /* 32-byte units */
242ce4946daSBill Paul #define NGE_TXCFG_FILL_THRESH	0x0000FF00 /* 32-byte units */
243ce4946daSBill Paul #define NGE_1000MB_BURST_DIS	0x00080000
244ce4946daSBill Paul #define NGE_TXCFG_DMABURST	0x00700000
245ce4946daSBill Paul #define NGE_TXCFG_ECRETRY	0x00800000
246ce4946daSBill Paul #define NGE_TXCFG_AUTOPAD	0x10000000
247ce4946daSBill Paul #define NGE_TXCFG_LOOPBK	0x20000000
248ce4946daSBill Paul #define NGE_TXCFG_IGN_HBEAT	0x40000000
249ce4946daSBill Paul #define NGE_TXCFG_IGN_CARR	0x80000000
250ce4946daSBill Paul 
251ce4946daSBill Paul #define NGE_TXCFG_DRAIN(x)	(((x) >> 5) & NGE_TXCFG_DRAIN_THRESH)
252ce4946daSBill Paul #define NGE_TXCFG_FILL(x)	((((x) >> 5) << 8) & NGE_TXCFG_FILL_THRESH)
253ce4946daSBill Paul 
254ce4946daSBill Paul #define NGE_TXDMA_1024BYTES	0x00000000
255ce4946daSBill Paul #define NGE_TXDMA_8BYTES	0x00100000
256ce4946daSBill Paul #define NGE_TXDMA_16BYTES	0x00200000
257ce4946daSBill Paul #define NGE_TXDMA_32BYTES	0x00300000
258ce4946daSBill Paul #define NGE_TXDMA_64BYTES	0x00400000
259ce4946daSBill Paul #define NGE_TXDMA_128BYTES	0x00500000
260ce4946daSBill Paul #define NGE_TXDMA_256BYTES	0x00600000
261ce4946daSBill Paul #define NGE_TXDMA_512BYTES	0x00700000
262ce4946daSBill Paul 
263ce4946daSBill Paul #define NGE_TXCFG	\
264ce4946daSBill Paul 	(NGE_TXDMA_512BYTES|NGE_TXCFG_AUTOPAD|\
265ce4946daSBill Paul 	 NGE_TXCFG_FILL(64)|NGE_TXCFG_DRAIN(6400))
266ce4946daSBill Paul 
267ce4946daSBill Paul /* GPIO register */
268ce4946daSBill Paul #define NGE_GPIO_GP1_OUT	0x00000001
269ce4946daSBill Paul #define NGE_GPIO_GP2_OUT	0x00000002
270ce4946daSBill Paul #define NGE_GPIO_GP3_OUT	0x00000004
271ce4946daSBill Paul #define NGE_GPIO_GP4_OUT	0x00000008
272ce4946daSBill Paul #define NGE_GPIO_GP5_OUT	0x00000010
273ce4946daSBill Paul #define NGE_GPIO_GP1_OUTENB	0x00000020
274ce4946daSBill Paul #define NGE_GPIO_GP2_OUTENB	0x00000040
275ce4946daSBill Paul #define NGE_GPIO_GP3_OUTENB	0x00000080
276ce4946daSBill Paul #define NGE_GPIO_GP4_OUTENB	0x00000100
277ce4946daSBill Paul #define NGE_GPIO_GP5_OUTENB	0x00000200
278ce4946daSBill Paul #define NGE_GPIO_GP1_IN		0x00000400
279ce4946daSBill Paul #define NGE_GPIO_GP2_IN		0x00000800
280ce4946daSBill Paul #define NGE_GPIO_GP3_IN		0x00001000
281ce4946daSBill Paul #define NGE_GPIO_GP4_IN		0x00002000
282ce4946daSBill Paul #define NGE_GPIO_GP5_IN		0x00004000
283ce4946daSBill Paul 
284ce4946daSBill Paul /* Receive configuration register */
285ce4946daSBill Paul #define NGE_RXCFG_DRAIN_THRESH	0x0000003E /* 8-byte units */
286ce4946daSBill Paul #define NGE_RXCFG_DMABURST	0x00700000
287ce4946daSBill Paul #define NGE_RXCFG_RX_RANGEERR	0x04000000 /* accept in-range err frames */
288ce4946daSBill Paul #define NGE_RXCFG_RX_GIANTS	0x08000000 /* accept packets > 1518 bytes */
289ce4946daSBill Paul #define NGE_RXCFG_RX_FDX	0x10000000 /* full duplex receive */
290ce4946daSBill Paul #define NGE_RXCFG_RX_NOCRC	0x20000000 /* strip CRC */
291ce4946daSBill Paul #define NGE_RXCFG_RX_RUNT	0x40000000 /* accept short frames */
292ce4946daSBill Paul #define NGE_RXCFG_RX_BADPKTS	0x80000000 /* accept error frames */
293ce4946daSBill Paul 
294ce4946daSBill Paul #define NGE_RXCFG_DRAIN(x)	((((x) >> 3) << 1) & NGE_RXCFG_DRAIN_THRESH)
295ce4946daSBill Paul 
296ce4946daSBill Paul #define NGE_RXDMA_1024BYTES	0x00000000
297ce4946daSBill Paul #define NGE_RXDMA_8BYTES	0x00100000
298ce4946daSBill Paul #define NGE_RXDMA_16BYTES	0x00200000
299ce4946daSBill Paul #define NGE_RXDMA_32YTES	0x00300000
300ce4946daSBill Paul #define NGE_RXDMA_64BYTES	0x00400000
301ce4946daSBill Paul #define NGE_RXDMA_128BYTES	0x00500000
302ce4946daSBill Paul #define NGE_RXDMA_256BYTES	0x00600000
303ce4946daSBill Paul #define NGE_RXDMA_512BYTES	0x00700000
304ce4946daSBill Paul 
305f6bc9430SPyun YongHyeon /*
306f6bc9430SPyun YongHyeon  * DP83820/DP83821 with H/W VLAN stripping does not accept short VLAN
307f6bc9430SPyun YongHyeon  * tagged packets such as ARP, short icmp echo request, etc. It seems
308f6bc9430SPyun YongHyeon  * that MAC checks frame length for VLAN tagged packets after stripping
309f6bc9430SPyun YongHyeon  * the VLAN tag. For short VLAN tagged packets it would would be 56
310f6bc9430SPyun YongHyeon  * (64 - CRC - VLAN info) bytes in length after stripping VLAN tag.
311f6bc9430SPyun YongHyeon  * If the VLAN tag stripped frames are less than 60 bytes in length
312f6bc9430SPyun YongHyeon  * the hardware think it received runt packets!
313f6bc9430SPyun YongHyeon  * Therefore we should accept runt frames to get VLAN tagged ARP
314f6bc9430SPyun YongHyeon  * packets. In addition, it is known that some revisions of
315f6bc9430SPyun YongHyeon  * DP83820/DP83821 have another bug that prevent fragmented IP packets
316f6bc9430SPyun YongHyeon  * from accepting. So we also should accept errored frames.
317f6bc9430SPyun YongHyeon  */
318ce4946daSBill Paul #define NGE_RXCFG \
319ce4946daSBill Paul 	(NGE_RXCFG_DRAIN(64) | NGE_RXDMA_256BYTES| \
320f6bc9430SPyun YongHyeon 	 NGE_RXCFG_RX_RANGEERR | NGE_RXCFG_RX_BADPKTS | NGE_RXCFG_RX_RUNT | \
321ce4946daSBill Paul 	 NGE_RXCFG_RX_GIANTS | NGE_RXCFG_RX_NOCRC)
322ce4946daSBill Paul 
323ce4946daSBill Paul /* Priority queue control */
324ce4946daSBill Paul #define NGE_PRIOQCTL_TXPRIO_ENB	0x00000001
325ce4946daSBill Paul #define NGE_PRIOQCTL_TXFAIR_ENB	0x00000002
326ce4946daSBill Paul #define NGE_PRIOQCTL_RXPRIO	0x0000000C
327ce4946daSBill Paul 
328ce4946daSBill Paul #define NGE_RXPRIOQ_DISABLED	0x00000000
329ce4946daSBill Paul #define NGE_RXPRIOQ_TWOQS	0x00000004
330ce4946daSBill Paul #define NGE_RXPRIOQ_THREEQS	0x00000008
331ce4946daSBill Paul #define NGE_RXPRIOQ_FOURQS	0x0000000C
332ce4946daSBill Paul 
333ce4946daSBill Paul /* Wake On LAN command/status register */
334ce4946daSBill Paul #define NGE_WOLCSR_WAKE_ON_PHYINTR	0x00000001
335ce4946daSBill Paul #define NGE_WOLCSR_WAKE_ON_UNICAST	0x00000002
336ce4946daSBill Paul #define NGE_WOLCSR_WAKE_ON_MULTICAST	0x00000004
337f6bc9430SPyun YongHyeon #define NGE_WOLCSR_WAKE_ON_BROADCAST	0x00000008
338ce4946daSBill Paul #define NGE_WOLCSR_WAKE_ON_ARP		0x00000010
339ce4946daSBill Paul #define NGE_WOLCSR_WAKE_ON_PAT0_MATCH	0x00000020
340ce4946daSBill Paul #define NGE_WOLCSR_WAKE_ON_PAT1_MATCH	0x00000040
341ce4946daSBill Paul #define NGE_WOLCSR_WAKE_ON_PAT2_MATCH	0x00000080
342ce4946daSBill Paul #define NGE_WOLCSR_WAKE_ON_PAT3_MATCH	0x00000100
343f6bc9430SPyun YongHyeon #define NGE_WOLCSR_WAKE_ON_MAGICPKT	0x00000200
344f6bc9430SPyun YongHyeon #define NGE_WOLCSR_SECUREON_ENB		0x00000400
345ce4946daSBill Paul #define NGE_WOLCSR_SECUREON_HACK	0x00200000
346ce4946daSBill Paul #define NGE_WOLCSR_PHYINTR		0x00400000
347ce4946daSBill Paul #define NGE_WOLCSR_UNICAST		0x00800000
348ce4946daSBill Paul #define NGE_WOLCSR_MULTICAST		0x01000000
349ce4946daSBill Paul #define NGE_WOLCSR_BROADCAST		0x02000000
350ce4946daSBill Paul #define NGE_WOLCSR_ARP_RCVD		0x04000000
351ce4946daSBill Paul #define NGE_WOLCSR_PAT0_MATCH		0x08000000
352ce4946daSBill Paul #define NGE_WOLCSR_PAT1_MATCH		0x10000000
353ce4946daSBill Paul #define NGE_WOLCSR_PAT2_MATCH		0x20000000
354ce4946daSBill Paul #define NGE_WOLCSR_PAT3_MATCH		0x40000000
355ce4946daSBill Paul #define NGE_WOLCSR_MAGICPKT		0x80000000
356ce4946daSBill Paul 
357ce4946daSBill Paul /* Pause control/status register */
358ce4946daSBill Paul #define NGE_PAUSECSR_CNT		0x0000FFFF
359ce4946daSBill Paul #define NGE_PAUSECSR_PFRAME_SENT	0x00020000
360ce4946daSBill Paul #define NGE_PAUSECSR_RX_DATAFIFO_THR_LO	0x000C0000
361ce4946daSBill Paul #define NGE_PAUSECSR_RX_DATAFIFO_THR_HI	0x00300000
362ce4946daSBill Paul #define NGE_PAUSECSR_RX_STATFIFO_THR_LO	0x00C00000
363ce4946daSBill Paul #define NGE_PAUSECSR_RX_STATFIFO_THR_HI	0x03000000
364ce4946daSBill Paul #define NGE_PAUSECSR_PFRAME_RCVD	0x08000000
365ce4946daSBill Paul #define NGE_PAUSECSR_PAUSE_ACTIVE	0x10000000
366ce4946daSBill Paul #define NGE_PAUSECSR_PAUSE_ON_DA	0x20000000 /* pause on direct addr */
367ce4946daSBill Paul #define NGE_PAUSECSR_PAUSE_ON_MCAST	0x40000000 /* pause on mcast */
368ce4946daSBill Paul #define NGE_PAUSECSR_PAUSE_ENB		0x80000000
369ce4946daSBill Paul 
370ce4946daSBill Paul /* Receive filter/match control message */
371ce4946daSBill Paul #define MGE_RXFILTCTL_ADDR	0x000003FF
372ce4946daSBill Paul #define NGE_RXFILTCTL_ULMASK	0x00080000
373ce4946daSBill Paul #define NGE_RXFILTCTL_UCHASH	0x00100000
374ce4946daSBill Paul #define NGE_RXFILTCTL_MCHASH	0x00200000
375ce4946daSBill Paul #define NGE_RXFILTCTL_ARP	0x00400000
376ce4946daSBill Paul #define NGE_RXFILTCTL_PMATCH0	0x00800000
377ce4946daSBill Paul #define NGE_RXFILTCTL_PMATCH1	0x01000000
378ce4946daSBill Paul #define NGE_RXFILTCTL_PMATCH2	0x02000000
379ce4946daSBill Paul #define NGE_RXFILTCTL_PMATCH3	0x04000000
380ce4946daSBill Paul #define NGE_RXFILTCTL_PERFECT	0x08000000
381ce4946daSBill Paul #define NGE_RXFILTCTL_ALLPHYS	0x10000000
382ce4946daSBill Paul #define NGE_RXFILTCTL_ALLMULTI	0x20000000
383ce4946daSBill Paul #define NGE_RXFILTCTL_BROAD	0x40000000
384ce4946daSBill Paul #define NGE_RXFILTCTL_ENABLE	0x80000000
385ce4946daSBill Paul 
386ce4946daSBill Paul #define NGE_FILTADDR_PAR0	0x00000000
387ce4946daSBill Paul #define NGE_FILTADDR_PAR1	0x00000002
388ce4946daSBill Paul #define NGE_FILTADDR_PAR2	0x00000004
389ce4946daSBill Paul #define NGE_FILTADDR_PMATCH0	0x00000006
390ce4946daSBill Paul #define NGE_FILTADDR_PMATCH1	0x00000008
391ce4946daSBill Paul #define NGE_FILTADDR_SOPASS0	0x0000000A
392ce4946daSBill Paul #define NGE_FILTADDR_SOPASS1	0x0000000C
393ce4946daSBill Paul #define NGE_FILTADDR_SOPASS2	0x0000000E
394ce4946daSBill Paul #define NGE_FILTADDR_FMEM_LO	0x00000100
395ce4946daSBill Paul #define NGE_FILTADDR_FMEM_HI	0x000003FE
396ce4946daSBill Paul #define NGE_FILTADDR_MCAST_LO	0x00000100 /* start of multicast filter */
397ce4946daSBill Paul #define NGE_FILTADDR_MCAST_HI	0x000001FE /* end of multicast filter */
398ce4946daSBill Paul #define NGE_MCAST_FILTER_LEN	256	   /* bytes */
399ce4946daSBill Paul #define NGE_FILTADDR_PBUF0	0x00000200 /* pattern buffer 0 */
400ce4946daSBill Paul #define NGE_FILTADDR_PBUF1	0x00000280 /* pattern buffer 1 */
401ce4946daSBill Paul #define NGE_FILTADDR_PBUF2	0x00000300 /* pattern buffer 2 */
402ce4946daSBill Paul #define NGE_FILTADDR_PBUF3	0x00000380 /* pattern buffer 3 */
403ce4946daSBill Paul 
404ce4946daSBill Paul /* MIB control register */
405ce4946daSBill Paul #define NGE_MIBCTL_WARNTEST	0x00000001
406ce4946daSBill Paul #define NGE_MIBCTL_FREEZE_CNT	0x00000002
407ce4946daSBill Paul #define NGE_MIBCTL_CLEAR_CNT	0x00000004
408ce4946daSBill Paul #define NGE_MIBCTL_STROBE_CNT	0x00000008
409ce4946daSBill Paul 
410ce4946daSBill Paul /* VLAN/IP RX control register */
411ce4946daSBill Paul #define NGE_VIPRXCTL_TAG_DETECT_ENB	0x00000001
412ce4946daSBill Paul #define NGE_VIPRXCTL_TAG_STRIP_ENB	0x00000002
413ce4946daSBill Paul #define NGE_VIPRXCTL_DROP_TAGGEDPKTS	0x00000004
414ce4946daSBill Paul #define NGE_VIPRXCTL_DROP_UNTAGGEDPKTS	0x00000008
415ce4946daSBill Paul #define NGE_VIPRXCTL_IPCSUM_ENB		0x00000010
416ce4946daSBill Paul #define NGE_VIPRXCTL_REJECT_BADIPCSUM	0x00000020
417ce4946daSBill Paul #define NGE_VIPRXCTL_REJECT_BADTCPCSUM	0x00000040
418ce4946daSBill Paul #define NGE_VIPRXCTL_REJECT_BADUDPCSUM	0x00000080
419ce4946daSBill Paul 
420ce4946daSBill Paul /* VLAN/IP TX control register */
421ce4946daSBill Paul #define NGE_VIPTXCTL_TAG_ALL		0x00000001
422ce4946daSBill Paul #define NGE_VIPTXCTL_TAG_PER_PKT	0x00000002
423ce4946daSBill Paul #define NGE_VIPTXCTL_CSUM_ALL		0x00000004
424ce4946daSBill Paul #define NGE_VIPTXCTL_CSUM_PER_PKT	0x00000008
425ce4946daSBill Paul 
426ce4946daSBill Paul /* VLAN data register */
427ce4946daSBill Paul #define NGE_VLANDATA_VTYPE	0x0000FFFF
428ce4946daSBill Paul #define NGE_VLANDATA_VTCI	0xFFFF0000
429ce4946daSBill Paul 
430ce4946daSBill Paul /* Clockrun register */
431ce4946daSBill Paul #define NGE_CLKRUN_PMESTS	0x00008000
432ce4946daSBill Paul #define NGE_CLKRUN_PMEENB	0x00000100
433ce4946daSBill Paul #define NGE_CLNRUN_CLKRUN_ENB	0x00000001
434ce4946daSBill Paul 
435ce4946daSBill Paul /* TBI BMCR */
436ce4946daSBill Paul #define NGE_TBIBMCR_RESTART_ANEG	0x00000200
437ce4946daSBill Paul #define NGE_TBIBMCR_ENABLE_ANEG		0x00001000
438ce4946daSBill Paul #define NGE_TBIBMCR_LOOPBACK		0x00004000
439ce4946daSBill Paul 
440ce4946daSBill Paul /* TBI BMSR */
441ce4946daSBill Paul #define NGE_TBIBMSR_ANEG_DONE	0x00000004
442ce4946daSBill Paul #define NGE_TBIBMSR_LINKSTAT	0x00000020
443ce4946daSBill Paul 
444ce4946daSBill Paul /* TBI ANAR */
445ce4946daSBill Paul #define NGE_TBIANAR_HDX		0x00000020
446ce4946daSBill Paul #define NGE_TBIANAR_FDX		0x00000040
4471f548804SDoug Ambrisko #define NGE_TBIANAR_PS1		0x00000080
4481f548804SDoug Ambrisko #define NGE_TBIANAR_PS2		0x00000100
449ce4946daSBill Paul #define NGE_TBIANAR_PCAP	0x00000180
450ce4946daSBill Paul #define NGE_TBIANAR_REMFAULT	0x00003000
451ce4946daSBill Paul #define NGE_TBIANAR_NEXTPAGE	0x00008000
452ce4946daSBill Paul 
453ce4946daSBill Paul /* TBI ANLPAR */
454ce4946daSBill Paul #define NGE_TBIANLPAR_HDX	0x00000020
455ce4946daSBill Paul #define NGE_TBIANLPAR_FDX	0x00000040
4561f548804SDoug Ambrisko #define NGE_TBIANAR_PS1		0x00000080
4571f548804SDoug Ambrisko #define NGE_TBIANAR_PS2		0x00000100
458ce4946daSBill Paul #define NGE_TBIANLPAR_PCAP	0x00000180
459ce4946daSBill Paul #define NGE_TBIANLPAR_REMFAULT	0x00003000
460ce4946daSBill Paul #define NGE_TBIANLPAR_NEXTPAGE	0x00008000
461ce4946daSBill Paul 
462ce4946daSBill Paul /* TBI ANER */
463ce4946daSBill Paul #define NGE_TBIANER_PAGERCVD	0x00000002
464ce4946daSBill Paul #define NGE_TBIANER_NEXTPGABLE	0x00000004
465ce4946daSBill Paul 
466ce4946daSBill Paul /* TBI EXTSTS */
467ce4946daSBill Paul #define NGE_TBIEXTSTS_HXD	0x00004000
468ce4946daSBill Paul #define NGE_TBIEXTSTS_FXD	0x00008000
469ce4946daSBill Paul 
470ce4946daSBill Paul /*
471ce4946daSBill Paul  * DMA descriptor structures. The RX and TX descriptor formats are
472ce4946daSBill Paul  * deliberately designed to be similar to facilitate passing them between
473ce4946daSBill Paul  * RX and TX queues on multiple controllers, in the case where you have
474ce4946daSBill Paul  * multiple MACs in a switching configuration. With the 83820, the pointer
475ce4946daSBill Paul  * values can be either 64 bits or 32 bits depending on how the chip is
476ce4946daSBill Paul  * configured. For the 83821, the fields are always 32-bits. There is
477ce4946daSBill Paul  * also an optional extended status field for VLAN and TCP/IP checksum
478ce4946daSBill Paul  * functions. We use the checksum feature so we enable the use of this
479ce4946daSBill Paul  * field. Descriptors must be 64-bit aligned.
480ce4946daSBill Paul  */
481ce4946daSBill Paul struct nge_desc_64 {
482ce4946daSBill Paul 	/* Hardware descriptor section */
483f6bc9430SPyun YongHyeon 	uint32_t	nge_next_lo;
484f6bc9430SPyun YongHyeon 	uint32_t	nge_next_hi;
485f6bc9430SPyun YongHyeon 	uint32_t	nge_ptr_lo;
486f6bc9430SPyun YongHyeon 	uint32_t	nge_ptr_hi;
487f6bc9430SPyun YongHyeon 	uint32_t	nge_cmdsts;
488f6bc9430SPyun YongHyeon 	uint32_t	nge_extsts;
489ce4946daSBill Paul };
490ce4946daSBill Paul 
491ad6c618bSBill Paul struct nge_desc_32 {
492ad6c618bSBill Paul 	/* Hardware descriptor section */
493f6bc9430SPyun YongHyeon 	uint32_t	nge_next;
494f6bc9430SPyun YongHyeon 	uint32_t	nge_ptr;
495f6bc9430SPyun YongHyeon 	uint32_t	nge_cmdsts;
496f6bc9430SPyun YongHyeon 	uint32_t	nge_extsts;
497ad6c618bSBill Paul };
498ad6c618bSBill Paul 
499ad6c618bSBill Paul #define nge_desc	nge_desc_32
500ad6c618bSBill Paul 
501ce4946daSBill Paul #define NGE_CMDSTS_BUFLEN	0x0000FFFF
502ce4946daSBill Paul #define NGE_CMDSTS_PKT_OK	0x08000000
503ce4946daSBill Paul #define NGE_CMDSTS_CRC		0x10000000
504ce4946daSBill Paul #define NGE_CMDSTS_INTR		0x20000000
505ce4946daSBill Paul #define NGE_CMDSTS_MORE		0x40000000
506ce4946daSBill Paul #define NGE_CMDSTS_OWN		0x80000000
507ce4946daSBill Paul 
508f6bc9430SPyun YongHyeon #define NGE_INC(x, y)		(x) = ((x) + 1) % y
509ce4946daSBill Paul 
510ce4946daSBill Paul #define NGE_RXSTAT_RANGELENERR	0x00010000
511ce4946daSBill Paul #define NGE_RXSTAT_LOOPBK	0x00020000
512ce4946daSBill Paul #define NGE_RXSTAT_ALIGNERR	0x00040000
513ce4946daSBill Paul #define NGE_RXSTAT_CRCERR	0x00080000
514ce4946daSBill Paul #define NGE_RXSTAT_SYMBOLERR	0x00100000
515ce4946daSBill Paul #define NGE_RXSTAT_RUNT		0x00200000
516ce4946daSBill Paul #define NGE_RXSTAT_GIANT	0x00400000
517ce4946daSBill Paul #define NGE_RXSTAT_DSTCLASS	0x01800000
518ce4946daSBill Paul #define NGE_RXSTAT_OVERRUN	0x02000000
519ce4946daSBill Paul #define NGE_RXSTAT_RX_ABORT	0x04000000
520ce4946daSBill Paul 
521ce4946daSBill Paul #define NGE_DSTCLASS_REJECT	0x00000000
522ce4946daSBill Paul #define NGE_DSTCLASS_UNICAST	0x00800000
523ce4946daSBill Paul #define NGE_DSTCLASS_MULTICAST	0x01000000
524ce4946daSBill Paul #define NGE_DSTCLASS_BROADCAST	0x02000000
525ce4946daSBill Paul 
526ce4946daSBill Paul #define NGE_TXSTAT_COLLCNT	0x000F0000
527ce4946daSBill Paul #define NGE_TXSTAT_EXCESSCOLLS	0x00100000
528ce4946daSBill Paul #define NGE_TXSTAT_OUTOFWINCOLL	0x00200000
529ce4946daSBill Paul #define NGE_TXSTAT_EXCESS_DEFER	0x00400000
530ce4946daSBill Paul #define NGE_TXSTAT_DEFERED	0x00800000
531ce4946daSBill Paul #define NGE_TXSTAT_CARR_LOST	0x01000000
532ce4946daSBill Paul #define NGE_TXSTAT_UNDERRUN	0x02000000
533ce4946daSBill Paul #define NGE_TXSTAT_TX_ABORT	0x04000000
534ce4946daSBill Paul 
535ce4946daSBill Paul #define NGE_TXEXTSTS_VLAN_TCI	0x0000FFFF
536ce4946daSBill Paul #define NGE_TXEXTSTS_VLANPKT	0x00010000
537ce4946daSBill Paul #define NGE_TXEXTSTS_IPCSUM	0x00020000
538ce4946daSBill Paul #define NGE_TXEXTSTS_TCPCSUM	0x00080000
539ce4946daSBill Paul #define NGE_TXEXTSTS_UDPCSUM	0x00200000
540ce4946daSBill Paul 
541ce4946daSBill Paul #define NGE_RXEXTSTS_VTCI	0x0000FFFF
542ce4946daSBill Paul #define NGE_RXEXTSTS_VLANPKT	0x00010000
543ce4946daSBill Paul #define NGE_RXEXTSTS_IPPKT	0x00020000
544ce4946daSBill Paul #define NGE_RXEXTSTS_IPCSUMERR	0x00040000
545ce4946daSBill Paul #define NGE_RXEXTSTS_TCPPKT	0x00080000
546ce4946daSBill Paul #define NGE_RXEXTSTS_TCPCSUMERR	0x00100000
547ce4946daSBill Paul #define NGE_RXEXTSTS_UDPPKT	0x00200000
548ce4946daSBill Paul #define NGE_RXEXTSTS_UDPCSUMERR	0x00400000
549ce4946daSBill Paul 
550f6bc9430SPyun YongHyeon #define NGE_TX_RING_CNT		256
551f6bc9430SPyun YongHyeon #define NGE_RX_RING_CNT		256
552f6bc9430SPyun YongHyeon #define	NGE_TX_RING_SIZE	sizeof(struct nge_desc) * NGE_TX_RING_CNT
553f6bc9430SPyun YongHyeon #define	NGE_RX_RING_SIZE	sizeof(struct nge_desc) * NGE_RX_RING_CNT
554f6bc9430SPyun YongHyeon #define	NGE_RING_ALIGN		sizeof(uint64_t)
555f6bc9430SPyun YongHyeon #define	NGE_RX_ALIGN		sizeof(uint64_t)
556f6bc9430SPyun YongHyeon #define	NGE_MAXTXSEGS		16
557ce4946daSBill Paul 
558f6bc9430SPyun YongHyeon #define	NGE_ADDR_LO(x)		((uint64_t)(x) & 0xffffffff)
559f6bc9430SPyun YongHyeon #define	NGE_ADDR_HI(x)		((uint64_t)(x) >> 32)
560f6bc9430SPyun YongHyeon #define	NGE_TX_RING_ADDR(sc, i)	\
561f6bc9430SPyun YongHyeon     ((sc)->nge_rdata.nge_tx_ring_paddr + sizeof(struct nge_desc) * (i))
562f6bc9430SPyun YongHyeon #define	NGE_RX_RING_ADDR(sc, i)	\
563f6bc9430SPyun YongHyeon     ((sc)->nge_rdata.nge_rx_ring_paddr + sizeof(struct nge_desc) * (i))
564ad6c618bSBill Paul 
565f6bc9430SPyun YongHyeon struct nge_txdesc {
566f6bc9430SPyun YongHyeon 	struct mbuf		*tx_m;
567f6bc9430SPyun YongHyeon 	bus_dmamap_t		tx_dmamap;
568ce4946daSBill Paul };
569ce4946daSBill Paul 
570f6bc9430SPyun YongHyeon struct nge_rxdesc {
571f6bc9430SPyun YongHyeon 	struct mbuf		*rx_m;
572f6bc9430SPyun YongHyeon 	bus_dmamap_t		rx_dmamap;
573f6bc9430SPyun YongHyeon };
574f6bc9430SPyun YongHyeon 
575f6bc9430SPyun YongHyeon struct nge_chain_data {
576f6bc9430SPyun YongHyeon 	bus_dma_tag_t		nge_parent_tag;
577f6bc9430SPyun YongHyeon 	bus_dma_tag_t		nge_tx_tag;
578f6bc9430SPyun YongHyeon 	struct nge_txdesc	nge_txdesc[NGE_TX_RING_CNT];
579f6bc9430SPyun YongHyeon 	bus_dma_tag_t		nge_rx_tag;
580f6bc9430SPyun YongHyeon 	struct nge_rxdesc	nge_rxdesc[NGE_RX_RING_CNT];
581f6bc9430SPyun YongHyeon 	bus_dma_tag_t		nge_tx_ring_tag;
582f6bc9430SPyun YongHyeon 	bus_dma_tag_t		nge_rx_ring_tag;
583f6bc9430SPyun YongHyeon 	bus_dmamap_t		nge_tx_ring_map;
584f6bc9430SPyun YongHyeon 	bus_dmamap_t		nge_rx_ring_map;
585f6bc9430SPyun YongHyeon 	bus_dmamap_t		nge_rx_sparemap;
586f6bc9430SPyun YongHyeon 	int			nge_tx_prod;
587f6bc9430SPyun YongHyeon 	int			nge_tx_cons;
588f6bc9430SPyun YongHyeon 	int			nge_tx_cnt;
589f6bc9430SPyun YongHyeon 	int			nge_rx_cons;
590f6bc9430SPyun YongHyeon };
591f6bc9430SPyun YongHyeon 
592f6bc9430SPyun YongHyeon struct nge_ring_data {
593f6bc9430SPyun YongHyeon 	struct nge_desc		*nge_tx_ring;
594f6bc9430SPyun YongHyeon 	bus_addr_t		nge_tx_ring_paddr;
595f6bc9430SPyun YongHyeon 	struct nge_desc		*nge_rx_ring;
596f6bc9430SPyun YongHyeon 	bus_addr_t		nge_rx_ring_paddr;
597f6bc9430SPyun YongHyeon };
598ce4946daSBill Paul 
599ce4946daSBill Paul /*
600ce4946daSBill Paul  * NatSemi PCI vendor ID.
601ce4946daSBill Paul  */
602ce4946daSBill Paul #define NGE_VENDORID		0x100B
603ce4946daSBill Paul 
604ce4946daSBill Paul /*
605ce4946daSBill Paul  * 83820/83821 PCI device IDs
606ce4946daSBill Paul  */
607ce4946daSBill Paul #define NGE_DEVICEID		0x0022
608ce4946daSBill Paul 
609ce4946daSBill Paul struct nge_type {
6103929ff51SPyun YongHyeon 	uint16_t		nge_vid;
6113929ff51SPyun YongHyeon 	uint16_t		nge_did;
6128c1093fcSMarius Strobl 	const char		*nge_name;
613ce4946daSBill Paul };
614ce4946daSBill Paul 
615f6bc9430SPyun YongHyeon #define NGE_JUMBO_FRAMELEN	9022
616f6bc9430SPyun YongHyeon #define NGE_JUMBO_MTU		\
617f6bc9430SPyun YongHyeon 	(NGE_JUMBO_FRAMELEN - sizeof(struct ether_vlan_header) - ETHER_CRC_LEN)
618ce4946daSBill Paul 
619f6bc9430SPyun YongHyeon /* Statistics counters. */
620f6bc9430SPyun YongHyeon struct nge_stats {
621f6bc9430SPyun YongHyeon 	uint32_t		rx_pkts_errs;
622f6bc9430SPyun YongHyeon 	uint32_t		rx_crc_errs;
623f6bc9430SPyun YongHyeon 	uint32_t		rx_fifo_oflows;
624f6bc9430SPyun YongHyeon 	uint32_t		rx_align_errs;
625f6bc9430SPyun YongHyeon 	uint32_t		rx_sym_errs;
626f6bc9430SPyun YongHyeon 	uint32_t		rx_pkts_jumbos;
627f6bc9430SPyun YongHyeon 	uint32_t		rx_len_errs;
628f6bc9430SPyun YongHyeon 	uint32_t		rx_unctl_frames;
629f6bc9430SPyun YongHyeon 	uint32_t		rx_pause;
630f6bc9430SPyun YongHyeon 	uint32_t		tx_pause;
631f6bc9430SPyun YongHyeon 	uint32_t		tx_seq_errs;
632ce4946daSBill Paul };
633ce4946daSBill Paul 
634ce4946daSBill Paul struct nge_softc {
635*76cb2c1cSJustin Hibbits 	if_t			nge_ifp;
6366b9f5c94SGleb Smirnoff 	device_t		nge_dev;
637ce4946daSBill Paul 	struct resource		*nge_res;
638f6bc9430SPyun YongHyeon 	int			nge_res_type;
639f6bc9430SPyun YongHyeon 	int			nge_res_id;
640ce4946daSBill Paul 	struct resource		*nge_irq;
641ce4946daSBill Paul 	void			*nge_intrhand;
642ce4946daSBill Paul 	device_t		nge_miibus;
643ce4946daSBill Paul 	int			nge_if_flags;
644f6bc9430SPyun YongHyeon 	uint32_t		nge_flags;
645f6bc9430SPyun YongHyeon #define	NGE_FLAG_TBI		0x0002
646f6bc9430SPyun YongHyeon #define	NGE_FLAG_SUSPENDED	0x2000
647f6bc9430SPyun YongHyeon #define	NGE_FLAG_DETACH		0x4000
648f6bc9430SPyun YongHyeon #define	NGE_FLAG_LINK		0x8000
649f6bc9430SPyun YongHyeon 	struct nge_chain_data	nge_cdata;
650f6bc9430SPyun YongHyeon 	struct nge_ring_data	nge_rdata;
651ad6c618bSBill Paul 	struct callout		nge_stat_ch;
652f6bc9430SPyun YongHyeon 	struct nge_stats	nge_stats;
653ce4946daSBill Paul 	struct mtx		nge_mtx;
654196c0df6SHidetoshi Shimokawa #ifdef DEVICE_POLLING
655196c0df6SHidetoshi Shimokawa 	int			rxcycles;
656196c0df6SHidetoshi Shimokawa #endif
657f6bc9430SPyun YongHyeon 	int			nge_watchdog_timer;
658f6bc9430SPyun YongHyeon 	int			nge_int_holdoff;
659ad6c618bSBill Paul 	struct mbuf		*nge_head;
660ad6c618bSBill Paul 	struct mbuf		*nge_tail;
661ce4946daSBill Paul };
662ce4946daSBill Paul 
663ad6c618bSBill Paul #define	NGE_LOCK_INIT(_sc, _name) \
664ad6c618bSBill Paul 	mtx_init(&(_sc)->nge_mtx, _name, MTX_NETWORK_LOCK, MTX_DEF)
665ad6c618bSBill Paul #define	NGE_LOCK(_sc)		mtx_lock(&(_sc)->nge_mtx)
666ad6c618bSBill Paul #define	NGE_LOCK_ASSERT(_sc)	mtx_assert(&(_sc)->nge_mtx, MA_OWNED)
667ad6c618bSBill Paul #define	NGE_UNLOCK(_sc)		mtx_unlock(&(_sc)->nge_mtx)
668ad6c618bSBill Paul #define	NGE_LOCK_DESTROY(_sc)	mtx_destroy(&(_sc)->nge_mtx)
669ad6c618bSBill Paul 
670ce4946daSBill Paul /*
671ce4946daSBill Paul  * register space access macros
672ce4946daSBill Paul  */
673ce4946daSBill Paul #define CSR_WRITE_4(sc, reg, val)	\
674f6bc9430SPyun YongHyeon 	bus_write_4((sc)->nge_res, reg, val)
6758c1093fcSMarius Strobl 
6768c1093fcSMarius Strobl #define CSR_BARRIER_4(sc, reg, flags)	\
6778c1093fcSMarius Strobl 	bus_barrier((sc)->nge_res, reg, 4, flags)
678ce4946daSBill Paul 
679ce4946daSBill Paul #define CSR_READ_4(sc, reg)		\
680f6bc9430SPyun YongHyeon 	bus_read_4((sc)->nge_res, reg)
681ce4946daSBill Paul 
682ce4946daSBill Paul #define NGE_TIMEOUT		1000
683f6bc9430SPyun YongHyeon 
684f6bc9430SPyun YongHyeon #define	NGE_INT_HOLDOFF_DEFAULT	1
685f6bc9430SPyun YongHyeon #define	NGE_INT_HOLDOFF_MIN	0
686f6bc9430SPyun YongHyeon #define	NGE_INT_HOLDOFF_MAX	255
687ce4946daSBill Paul 
688ce4946daSBill Paul /*
689ce4946daSBill Paul  * PCI low memory base and low I/O base register, and
690ce4946daSBill Paul  * other PCI registers.
691ce4946daSBill Paul  */
692ce4946daSBill Paul 
693ce4946daSBill Paul #define NGE_PCI_VENDOR_ID	0x00
694ce4946daSBill Paul #define NGE_PCI_DEVICE_ID	0x02
695ce4946daSBill Paul #define NGE_PCI_COMMAND		0x04
696ce4946daSBill Paul #define NGE_PCI_STATUS		0x06
697ce4946daSBill Paul #define NGE_PCI_REVID		0x08
698ce4946daSBill Paul #define NGE_PCI_CLASSCODE	0x09
699ce4946daSBill Paul #define NGE_PCI_CACHELEN	0x0C
700ce4946daSBill Paul #define NGE_PCI_LATENCY_TIMER	0x0D
701ce4946daSBill Paul #define NGE_PCI_HEADER_TYPE	0x0E
702ce4946daSBill Paul #define NGE_PCI_LOIO		0x10
703ce4946daSBill Paul #define NGE_PCI_LOMEM		0x14
704ce4946daSBill Paul #define NGE_PCI_BIOSROM		0x30
705ce4946daSBill Paul #define NGE_PCI_INTLINE		0x3C
706ce4946daSBill Paul #define NGE_PCI_INTPIN		0x3D
707ce4946daSBill Paul #define NGE_PCI_MINGNT		0x3E
708ce4946daSBill Paul #define NGE_PCI_MINLAT		0x0F
709ce4946daSBill Paul #define NGE_PCI_RESETOPT	0x48
710ce4946daSBill Paul #define NGE_PCI_EEPROM_DATA	0x4C
711ce4946daSBill Paul 
712ce4946daSBill Paul /* power management registers */
713ce4946daSBill Paul #define NGE_PCI_CAPID		0x50 /* 8 bits */
714ce4946daSBill Paul #define NGE_PCI_NEXTPTR		0x51 /* 8 bits */
715ce4946daSBill Paul #define NGE_PCI_PWRMGMTCAP	0x52 /* 16 bits */
716ce4946daSBill Paul #define NGE_PCI_PWRMGMTCTRL	0x54 /* 16 bits */
717ce4946daSBill Paul 
718ce4946daSBill Paul #define NGE_PSTATE_MASK		0x0003
719ce4946daSBill Paul #define NGE_PSTATE_D0		0x0000
720ce4946daSBill Paul #define NGE_PSTATE_D1		0x0001
721ce4946daSBill Paul #define NGE_PSTATE_D2		0x0002
722ce4946daSBill Paul #define NGE_PSTATE_D3		0x0003
723ce4946daSBill Paul #define NGE_PME_EN		0x0010
724ce4946daSBill Paul #define NGE_PME_STATUS		0x8000
725