xref: /netbsd/sys/dev/pci/if_tireg.h (revision bf9ec67e)
1 /* $NetBSD: if_tireg.h,v 1.11 2001/06/30 17:53:59 bjh21 Exp $ */
2 
3 /*
4  * Copyright (c) 1997, 1998, 1999
5  *	Bill Paul <wpaul@ctr.columbia.edu>.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *	This product includes software developed by Bill Paul.
18  * 4. Neither the name of the author nor the names of any co-contributors
19  *    may be used to endorse or promote products derived from this software
20  *    without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
26  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32  * THE POSSIBILITY OF SUCH DAMAGE.
33  *
34  *	FreeBSD Id: if_tireg.h,v 1.9 1999/07/27 03:54:48 wpaul Exp
35  */
36 
37 /*
38  * Tigon register offsets. These are memory mapped registers
39  * which can be accessed with the CSR_READ_4()/CSR_WRITE_4() macros.
40  * Each register must be accessed using 32 bit operations.
41  *
42  * All reegisters are accessed through a 16K shared memory block.
43  * The first group of registers are actually copies of the PCI
44  * configuration space registers.
45  */
46 
47 /*
48  * Tigon configuration and control registers.
49  */
50 #define TI_MISC_HOST_CTL		0x040
51 #define TI_MISC_LOCAL_CTL		0x044
52 #define TI_SEM_AB			0x048 /* Tigon 2 only */
53 #define TI_MISC_CONF			0x050 /* Tigon 2 only */
54 #define TI_TIMER_BITS			0x054
55 #define TI_TIMERREF			0x058
56 #define TI_PCI_STATE			0x05C
57 #define TI_MAIN_EVENT_A			0x060
58 #define TI_MAILBOX_EVENT_A		0x064
59 #define TI_WINBASE			0x068
60 #define TI_WINDATA			0x06C
61 #define TI_MAIN_EVENT_B			0x070 /* Tigon 2 only */
62 #define TI_MAILBOX_EVENT_B		0x074 /* Tigon 2 only */
63 #define TI_TIMERREF_B			0x078 /* Tigon 2 only */
64 #define TI_SERIAL			0x07C
65 
66 /*
67  * Misc host control bits.
68  */
69 #define TI_MHC_INTSTATE			0x00000001
70 #define TI_MHC_CLEARINT			0x00000002
71 #define TI_MHC_RESET			0x00000008
72 #define TI_MHC_BYTE_SWAP_ENB		0x00000010
73 #define TI_MHC_WORD_SWAP_ENB		0x00000020
74 #define TI_MHC_MASK_INTS		0x00000040
75 #define TI_MHC_CHIP_REV_MASK		0xF0000000
76 
77 #define TI_MHC_BIGENDIAN_INIT	\
78 	(TI_MHC_BYTE_SWAP_ENB|TI_MHC_WORD_SWAP_ENB|TI_MHC_CLEARINT)
79 
80 #define TI_MHC_LITTLEENDIAN_INIT	\
81 	(TI_MHC_WORD_SWAP_ENB|TI_MHC_CLEARINT)
82 
83 /*
84  * Tigon chip rev values. Rev 4 is the Tigon 1. Rev 6 is the Tigon 2.
85  * Rev 5 is also the Tigon 2, but is a broken version which was never
86  * used in any actual hardware, so we ignore it.
87  */
88 #define TI_REV_TIGON_I			0x40000000
89 #define TI_REV_TIGON_II			0x60000000
90 
91 /*
92  * Firmware revision that we want.
93  */
94 #define TI_FIRMWARE_MAJOR		0xc
95 #define TI_FIRMWARE_MINOR		0x4
96 #define TI_FIRMWARE_FIX			0xd
97 
98 /*
99  * Miscelaneous Local Control register.
100  */
101 #define TI_MLC_EE_WRITE_ENB		0x00000010
102 #define TI_MLC_SRAM_BANK_256K		0x00000200
103 #define TI_MLC_SRAM_BANK_SIZE		0x00000300 /* Tigon 2 only */
104 #define TI_MLC_LOCALADDR_21		0x00004000
105 #define TI_MLC_LOCALADDR_22		0x00008000
106 #define TI_MLC_SBUS_WRITEERR		0x00080000
107 #define TI_MLC_EE_CLK			0x00100000
108 #define TI_MLC_EE_TXEN			0x00200000
109 #define TI_MLC_EE_DOUT			0x00400000
110 #define TI_MLC_EE_DIN			0x00800000
111 
112 /*
113  * Offset of MAC address inside EEPROM.
114  */
115 #define TI_EE_MAC_OFFSET		0x8c
116 
117 #define TI_DMA_ASSIST			0x11C
118 #define TI_CPU_STATE			0x140
119 #define TI_CPU_PROGRAM_COUNTER		0x144
120 #define TI_SRAM_ADDR			0x154
121 #define TI_SRAM_DATA			0x158
122 #define TI_GEN_0			0x180
123 #define TI_GEN_X			0x1FC
124 #define TI_MAC_TX_STATE			0x200
125 #define TI_MAC_RX_STATE			0x220
126 #define TI_CPU_CTL_B			0x240 /* Tigon 2 only */
127 #define TI_CPU_PROGRAM_COUNTER_B	0x244 /* Tigon 2 only */
128 #define TI_SRAM_ADDR_B			0x254 /* Tigon 2 only */
129 #define TI_SRAM_DATA_B			0x258 /* Tigon 2 only */
130 #define TI_GEN_B_0			0x280 /* Tigon 2 only */
131 #define TI_GEN_B_X			0x2FC /* Tigon 2 only */
132 
133 /*
134  * Misc config register.
135  */
136 #define TI_MCR_SRAM_SYNCHRONOUS		0x00100000 /* Tigon 2 only */
137 
138 /*
139  * PCI state register.
140  */
141 #define TI_PCISTATE_FORCE_RESET		0x00000001
142 #define TI_PCISTATE_PROVIDE_LEN		0x00000002
143 #define TI_PCISTATE_READ_MAXDMA		0x0000001C
144 #define TI_PCISTATE_WRITE_MAXDMA	0x000000E0
145 #define TI_PCISTATE_MINDMA		0x0000FF00
146 #define TI_PCISTATE_FIFO_RETRY_ENB	0x00010000
147 #define TI_PCISTATE_USE_MEM_RD_MULT	0x00020000
148 #define TI_PCISTATE_NO_SWAP_READ_DMA	0x00040000
149 #define TI_PCISTATE_NO_SWAP_WRITE_DMA	0x00080000
150 #define TI_PCISTATE_66MHZ_BUS		0x00080000 /* Tigon 2 only */
151 #define TI_PCISTATE_32BIT_BUS		0x00100000 /* Tigon 2 only */
152 #define TI_PCISTATE_ENB_BYTE_ENABLES	0x00800000 /* Tigon 2 only */
153 #define TI_PCISTATE_READ_CMD		0x0F000000
154 #define TI_PCISTATE_WRITE_CMD		0xF0000000
155 
156 #define TI_PCI_READMAX_4		0x04
157 #define TI_PCI_READMAX_16		0x08
158 #define TI_PCI_READMAX_32		0x0C
159 #define TI_PCI_READMAX_64		0x10
160 #define TI_PCI_READMAX_128		0x14
161 #define TI_PCI_READMAX_256		0x18
162 #define TI_PCI_READMAX_1024		0x1C
163 
164 #define TI_PCI_WRITEMAX_4		0x20
165 #define TI_PCI_WRITEMAX_16		0x40
166 #define TI_PCI_WRITEMAX_32		0x60
167 #define TI_PCI_WRITEMAX_64		0x80
168 #define TI_PCI_WRITEMAX_128		0xA0
169 #define TI_PCI_WRITEMAX_256		0xC0
170 #define TI_PCI_WRITEMAX_1024		0xE0
171 
172 #define TI_PCI_READ_CMD			0x06000000
173 #define TI_PCI_WRITE_CMD		0x70000000
174 
175 /*
176  * DMA state register.
177  */
178 #define TI_DMASTATE_ENABLE		0x00000001
179 #define TI_DMASTATE_PAUSE		0x00000002
180 
181 /*
182  * CPU state register.
183  */
184 #define TI_CPUSTATE_RESET		0x00000001
185 #define TI_CPUSTATE_STEP		0x00000002
186 #define TI_CPUSTATE_ROMFAIL		0x00000010
187 #define TI_CPUSTATE_HALT		0x00010000
188 /*
189  * MAC TX state register
190  */
191 #define TI_TXSTATE_RESET		0x00000001
192 #define TI_TXSTATE_ENB			0x00000002
193 #define TI_TXSTATE_STOP			0x00000004
194 
195 /*
196  * MAC RX state register
197  */
198 #define TI_RXSTATE_RESET		0x00000001
199 #define TI_RXSTATE_ENB			0x00000002
200 #define TI_RXSTATE_STOP			0x00000004
201 
202 /*
203  * Tigon 2 mailbox registers. The mailbox area consists of 256 bytes
204  * split into 64 bit registers. Only the lower 32 bits of each mailbox
205  * are used.
206  */
207 #define TI_MB_HOSTINTR_HI		0x500
208 #define TI_MB_HOSTINTR_LO		0x504
209 #define TI_MB_HOSTINTR			TI_MB_HOSTINTR_LO
210 #define TI_MB_CMDPROD_IDX_HI		0x508
211 #define TI_MB_CMDPROD_IDX_LO		0x50C
212 #define TI_MB_CMDPROD_IDX		TI_MB_CMDPROD_IDX_LO
213 #define TI_MB_SENDPROD_IDX_HI		0x510
214 #define TI_MB_SENDPROD_IDX_LO		0x514
215 #define TI_MB_SENDPROD_IDX		TI_MB_SENDPROD_IDX_LO
216 #define TI_MB_STDRXPROD_IDX_HI		0x518 /* Tigon 2 only */
217 #define TI_MB_STDRXPROD_IDX_LO		0x51C /* Tigon 2 only */
218 #define TI_MB_STDRXPROD_IDX		TI_MB_STDRXPROD_IDX_LO
219 #define TI_MB_JUMBORXPROD_IDX_HI	0x520 /* Tigon 2 only */
220 #define TI_MB_JUMBORXPROD_IDX_LO	0x524 /* Tigon 2 only */
221 #define TI_MB_JUMBORXPROD_IDX		TI_MB_JUMBORXPROD_IDX_LO
222 #define TI_MB_MINIRXPROD_IDX_HI		0x528 /* Tigon 2 only */
223 #define TI_MB_MINIRXPROD_IDX_LO		0x52C /* Tigon 2 only */
224 #define TI_MB_MINIRXPROD_IDX		TI_MB_MINIRXPROD_IDX_LO
225 #define TI_MB_RSVD			0x530
226 
227 /*
228  * Tigon 2 general communication registers. These are 64 and 32 bit
229  * registers which are only valid after the firmware has been
230  * loaded and started. They actually exist in NIC memory but are
231  * mapped into the host memory via the shared memory region.
232  *
233  * The NIC internally maps these registers starting at address 0,
234  * so to determine the NIC address of any of these registers, we
235  * subtract 0x600 (the address of the first register).
236  */
237 
238 #define TI_GCR_BASE			0x600
239 #define TI_GCR_MACADDR			0x600
240 #define TI_GCR_PAR0			0x600
241 #define TI_GCR_PAR1			0x604
242 #define TI_GCR_GENINFO_HI		0x608
243 #define TI_GCR_GENINFO_LO		0x60C
244 #define TI_GCR_MCASTADDR		0x610 /* obsolete */
245 #define TI_GCR_MAR0			0x610 /* obsolete */
246 #define TI_GCR_MAR1			0x614 /* obsolete */
247 #define TI_GCR_OPMODE			0x618
248 #define TI_GCR_DMA_READCFG		0x61C
249 #define TI_GCR_DMA_WRITECFG		0x620
250 #define TI_GCR_TX_BUFFER_RATIO		0x624
251 #define TI_GCR_EVENTCONS_IDX		0x628
252 #define TI_GCR_CMDCONS_IDX		0x62C
253 #define TI_GCR_TUNEPARMS		0x630
254 #define TI_GCR_RX_COAL_TICKS		0x630
255 #define TI_GCR_TX_COAL_TICKS		0x634
256 #define TI_GCR_STAT_TICKS		0x638
257 #define TI_GCR_TX_MAX_COAL_BD		0x63C
258 #define TI_GCR_RX_MAX_COAL_BD		0x640
259 #define TI_GCR_NIC_TRACING		0x644
260 #define TI_GCR_GLINK			0x648
261 #define TI_GCR_LINK			0x64C
262 #define TI_GCR_NICTRACE_PTR		0x650
263 #define TI_GCR_NICTRACE_START		0x654
264 #define TI_GCR_NICTRACE_LEN		0x658
265 #define TI_GCR_IFINDEX			0x65C
266 #define TI_GCR_IFMTU			0x660
267 #define TI_GCR_MASK_INTRS		0x664
268 #define TI_GCR_GLINK_STAT		0x668
269 #define TI_GCR_LINK_STAT		0x66C
270 #define TI_GCR_RXRETURNCONS_IDX		0x680
271 #define TI_GCR_CMDRING			0x700
272 
273 #define TI_GCR_NIC_ADDR(x)		(x - TI_GCR_BASE);
274 
275 /*
276  * Local memory window. The local memory window is a 2K shared
277  * memory region which can be used to access the NIC's internal
278  * SRAM. The window can be mapped to a given 2K region using
279  * the TI_WINDOW_BASE register.
280  */
281 #define TI_WINDOW			0x800
282 #define TI_WINLEN			0x800
283 
284 #define TI_TICKS_PER_SEC		1000000
285 
286 /*
287  * Operation mode register.
288  */
289 #define TI_OPMODE_BYTESWAP_BD		0x00000002
290 #define TI_OPMODE_WORDSWAP_BD		0x00000004
291 #define TI_OPMODE_WARN_ENB		0x00000008 /* not yet implimented */
292 #define TI_OPMODE_BYTESWAP_DATA		0x00000010
293 #define TI_OPMODE_1_DMA_ACTIVE		0x00000040
294 #define TI_OPMODE_SBUS			0x00000100
295 #define TI_OPMODE_DONT_FRAG_JUMBO	0x00000200
296 #define TI_OPMODE_INCLUDE_CRC		0x00000400
297 #define TI_OPMODE_RX_BADFRAMES		0x00000800
298 #define TI_OPMODE_NO_EVENT_INTRS	0x00001000
299 #define TI_OPMODE_NO_TX_INTRS		0x00002000
300 #define TI_OPMODE_NO_RX_INTRS		0x00004000
301 #define TI_OPMODE_FATAL_ENB		0x40000000 /* not yet implimented */
302 
303 /*
304  * DMA configuration thresholds.
305  */
306 #define TI_DMA_STATE_THRESH_16W		0x00000100
307 #define TI_DMA_STATE_THRESH_8W		0x00000080
308 #define TI_DMA_STATE_THRESH_4W		0x00000040
309 #define TI_DMA_STATE_THRESH_2W		0x00000020
310 #define TI_DMA_STATE_THRESH_1W		0x00000010
311 
312 #define TI_DMA_STATE_FORCE_32_BIT	0x00000008
313 
314 /*
315  * Gigabit link status bits.
316  */
317 #define TI_GLNK_SENSE_NO_BEG		0x00002000
318 #define TI_GLNK_LOOPBACK		0x00004000
319 #define TI_GLNK_PREF			0x00008000
320 #define TI_GLNK_1000MB			0x00040000
321 #define TI_GLNK_FULL_DUPLEX		0x00080000
322 #define TI_GLNK_TX_FLOWCTL_Y		0x00200000 /* Tigon 2 only */
323 #define TI_GLNK_RX_FLOWCTL_Y		0x00800000
324 #define TI_GLNK_AUTONEGENB		0x20000000
325 #define TI_GLNK_ENB			0x40000000
326 
327 /*
328  * Link status bits.
329  */
330 #define TI_LNK_LOOPBACK			0x00004000
331 #define TI_LNK_PREF			0x00008000
332 #define TI_LNK_10MB			0x00010000
333 #define TI_LNK_100MB			0x00020000
334 #define TI_LNK_1000MB			0x00040000
335 #define TI_LNK_FULL_DUPLEX		0x00080000
336 #define TI_LNK_HALF_DUPLEX		0x00100000
337 #define TI_LNK_TX_FLOWCTL_Y		0x00200000 /* Tigon 2 only */
338 #define TI_LNK_RX_FLOWCTL_Y		0x00800000
339 #define TI_LNK_AUTONEGENB		0x20000000
340 #define TI_LNK_ENB			0x40000000
341 
342 /*
343  * Ring size constants.
344  */
345 #define TI_EVENT_RING_CNT	256
346 #define TI_CMD_RING_CNT		64
347 #define TI_STD_RX_RING_CNT	512
348 #define TI_JUMBO_RX_RING_CNT	256
349 #define TI_MINI_RX_RING_CNT	1024
350 #define TI_RETURN_RING_CNT	2048
351 
352 /*
353  * Possible TX ring sizes.
354  */
355 #define TI_TX_RING_CNT_128	128
356 #define TI_TX_RING_BASE_128	0x3800
357 
358 #define TI_TX_RING_CNT_256	256
359 #define TI_TX_RING_BASE_256	0x3000
360 
361 #define TI_TX_RING_CNT_512	512
362 #define TI_TX_RING_BASE_512	0x2000
363 
364 #define TI_TX_RING_CNT		TI_TX_RING_CNT_512
365 #define TI_TX_RING_BASE		TI_TX_RING_BASE_512
366 
367 /*
368  * The Tigon can have up to 8MB of external SRAM, however the Tigon 1
369  * is limited to 2MB total, and in general I think most adapters have
370  * around 1MB. We use this value for zeroing the NIC's SRAM, so to
371  * be safe we use the largest possible value (zeroing memory that
372  * isn't there doesn't hurt anything).
373  */
374 #define TI_MEM_MAX		0x7FFFFF
375 
376 /*
377  * Even on the alpha, pci addresses are 32-bit quantities
378  */
379 
380 #ifdef __64_bit_pci_addressing__
381 typedef struct {
382 	u_int64_t		ti_addr;
383 } ti_hostaddr;
384 #define TI_HOSTADDR(x)	x.ti_addr
385 #else
386 typedef struct {
387 	u_int32_t		ti_addr_hi;
388 	u_int32_t		ti_addr_lo;
389 } ti_hostaddr;
390 #define TI_HOSTADDR(x)	x.ti_addr_lo
391 #endif
392 
393 /*
394  * Ring control block structure. The rules for the max_len field
395  * are as follows:
396  *
397  * For the send ring, max_len indicates the number of entries in the
398  * ring (128, 256 or 512).
399  *
400  * For the standard receive ring, max_len indicates the threshold
401  * used to decide when a frame should be put in the jumbo receive ring
402  * instead of the standard one.
403  *
404  * For the mini ring, max_len indicates the size of the buffers in the
405  * ring. This is the value used to decide when a frame is small enough
406  * to be placed in the mini ring.
407  *
408  * For the return receive ring, max_len indicates the number of entries
409  * in the ring. It can be one of 2048, 1024 or 0 (which is the same as
410  * 2048 for backwards compatibility). The value 1024 can only be used
411  * if the mini ring is disabled.
412  */
413 struct ti_rcb {
414 	ti_hostaddr		ti_hostaddr;
415 #if BYTE_ORDER == BIG_ENDIAN
416 	u_int16_t		ti_max_len;
417 	u_int16_t		ti_flags;
418 #else
419 	u_int16_t		ti_flags;
420 	u_int16_t		ti_max_len;
421 #endif
422 	u_int32_t		ti_unused;
423 };
424 
425 #define TI_RCB_FLAG_TCP_UDP_CKSUM	0x00000001
426 #define TI_RCB_FLAG_IP_CKSUM		0x00000002
427 #define TI_RCB_FLAG_NO_PHDR_CKSUM	0x00000008
428 #define TI_RCB_FLAG_VLAN_ASSIST		0x00000010
429 #define TI_RCB_FLAG_COAL_UPD_ONLY	0x00000020
430 #define TI_RCB_FLAG_HOST_RING		0x00000040
431 #define TI_RCB_FLAG_IEEE_SNAP_CKSUM	0x00000080
432 #define TI_RCB_FLAG_USE_EXT_RX_BD	0x00000100
433 #define TI_RCB_FLAG_RING_DISABLED	0x00000200
434 
435 struct ti_producer {
436 	u_int32_t		ti_idx;
437 	u_int32_t		ti_unused;
438 };
439 
440 /*
441  * Tigon statistics counters.
442  */
443 struct ti_stats {
444 	/*
445 	 * MAC stats, taken from RFC 1643, ethernet-like MIB
446 	 */
447 	volatile u_int32_t dot3StatsAlignmentErrors;		/* 0 */
448 	volatile u_int32_t dot3StatsFCSErrors;			/* 1 */
449 	volatile u_int32_t dot3StatsSingleCollisionFrames;	/* 2 */
450 	volatile u_int32_t dot3StatsMultipleCollisionFrames;	/* 3 */
451 	volatile u_int32_t dot3StatsSQETestErrors;		/* 4 */
452 	volatile u_int32_t dot3StatsDeferredTransmissions;	/* 5 */
453 	volatile u_int32_t dot3StatsLateCollisions;		/* 6 */
454 	volatile u_int32_t dot3StatsExcessiveCollisions;	/* 7 */
455 	volatile u_int32_t dot3StatsInternalMacTransmitErrors;	/* 8 */
456 	volatile u_int32_t dot3StatsCarrierSenseErrors;		/* 9 */
457 	volatile u_int32_t dot3StatsFrameTooLongs;		/* 10 */
458 	volatile u_int32_t dot3StatsInternalMacReceiveErrors;	/* 11 */
459 	/*
460 	 * interface stats, taken from RFC 1213, MIB-II, interfaces group
461 	 */
462 	volatile u_int32_t ifIndex;				/* 12 */
463 	volatile u_int32_t ifType;				/* 13 */
464 	volatile u_int32_t ifMtu;				/* 14 */
465 	volatile u_int32_t ifSpeed;				/* 15 */
466 	volatile u_int32_t ifAdminStatus;			/* 16 */
467 #define IF_ADMIN_STATUS_UP      1
468 #define IF_ADMIN_STATUS_DOWN    2
469 #define IF_ADMIN_STATUS_TESTING 3
470 	volatile u_int32_t ifOperStatus;			/* 17 */
471 #define IF_OPER_STATUS_UP       1
472 #define IF_OPER_STATUS_DOWN     2
473 #define IF_OPER_STATUS_TESTING  3
474 #define IF_OPER_STATUS_UNKNOWN  4
475 #define IF_OPER_STATUS_DORMANT  5
476 	volatile u_int32_t ifLastChange;			/* 18 */
477 	volatile u_int32_t ifInDiscards;			/* 19 */
478 	volatile u_int32_t ifInErrors;				/* 20 */
479 	volatile u_int32_t ifInUnknownProtos;			/* 21 */
480 	volatile u_int32_t ifOutDiscards;			/* 22 */
481 	volatile u_int32_t ifOutErrors;				/* 23 */
482 	volatile u_int32_t ifOutQLen;     /* deprecated */	/* 24 */
483 	volatile u_int8_t  ifPhysAddress[8]; /* 8 bytes */	/* 25 - 26 */
484 	volatile u_int8_t  ifDescr[32];				/* 27 - 34 */
485 	u_int32_t alignIt;      /* align to 64 bit for u_int64_ts following */
486 	/*
487 	 * more interface stats, taken from RFC 1573, MIB-IIupdate,
488 	 * interfaces group
489 	 */
490 	volatile u_int64_t ifHCInOctets;			/* 36 - 37 */
491 	volatile u_int64_t ifHCInUcastPkts;			/* 38 - 39 */
492 	volatile u_int64_t ifHCInMulticastPkts;			/* 40 - 41 */
493 	volatile u_int64_t ifHCInBroadcastPkts;			/* 42 - 43 */
494 	volatile u_int64_t ifHCOutOctets;			/* 44 - 45 */
495 	volatile u_int64_t ifHCOutUcastPkts;			/* 46 - 47 */
496 	volatile u_int64_t ifHCOutMulticastPkts;		/* 48 - 49 */
497 	volatile u_int64_t ifHCOutBroadcastPkts;		/* 50 - 51 */
498 	volatile u_int32_t ifLinkUpDownTrapEnable;		/* 52 */
499 	volatile u_int32_t ifHighSpeed;				/* 53 */
500 	volatile u_int32_t ifPromiscuousMode; 			/* 54 */
501 	volatile u_int32_t ifConnectorPresent; /* follow link state 55 */
502 	/*
503 	 * Host Commands
504 	 */
505 	volatile u_int32_t nicCmdsHostState;			/* 56 */
506 	volatile u_int32_t nicCmdsFDRFiltering;			/* 57 */
507 	volatile u_int32_t nicCmdsSetRecvProdIndex;		/* 58 */
508 	volatile u_int32_t nicCmdsUpdateGencommStats;		/* 59 */
509 	volatile u_int32_t nicCmdsResetJumboRing;		/* 60 */
510 	volatile u_int32_t nicCmdsAddMCastAddr;			/* 61 */
511 	volatile u_int32_t nicCmdsDelMCastAddr;			/* 62 */
512 	volatile u_int32_t nicCmdsSetPromiscMode;		/* 63 */
513 	volatile u_int32_t nicCmdsLinkNegotiate;		/* 64 */
514 	volatile u_int32_t nicCmdsSetMACAddr;			/* 65 */
515 	volatile u_int32_t nicCmdsClearProfile;			/* 66 */
516 	volatile u_int32_t nicCmdsSetMulticastMode;		/* 67 */
517 	volatile u_int32_t nicCmdsClearStats;			/* 68 */
518 	volatile u_int32_t nicCmdsSetRecvJumboProdIndex;	/* 69 */
519 	volatile u_int32_t nicCmdsSetRecvMiniProdIndex;		/* 70 */
520 	volatile u_int32_t nicCmdsRefreshStats;			/* 71 */
521 	volatile u_int32_t nicCmdsUnknown;			/* 72 */
522 	/*
523 	 * NIC Events
524 	 */
525 	volatile u_int32_t nicEventsNICFirmwareOperational;	/* 73 */
526 	volatile u_int32_t nicEventsStatsUpdated;		/* 74 */
527 	volatile u_int32_t nicEventsLinkStateChanged;		/* 75 */
528 	volatile u_int32_t nicEventsError;			/* 76 */
529 	volatile u_int32_t nicEventsMCastListUpdated;		/* 77 */
530 	volatile u_int32_t nicEventsResetJumboRing;		/* 78 */
531 	/*
532 	 * Ring manipulation
533 	 */
534 	volatile u_int32_t nicRingSetSendProdIndex;		/* 79 */
535 	volatile u_int32_t nicRingSetSendConsIndex;		/* 80 */
536 	volatile u_int32_t nicRingSetRecvReturnProdIndex;	/* 81 */
537 	/*
538 	 * Interrupts
539 	 */
540 	volatile u_int32_t nicInterrupts;			/* 82 */
541 	volatile u_int32_t nicAvoidedInterrupts;		/* 83 */
542 	/*
543 	 * BD Coalessing Thresholds
544 	 */
545 	volatile u_int32_t nicEventThresholdHit;		/* 84 */
546 	volatile u_int32_t nicSendThresholdHit;			/* 85 */
547 	volatile u_int32_t nicRecvThresholdHit;			/* 86 */
548 	/*
549 	 * DMA Attentions
550 	 */
551 	volatile u_int32_t nicDmaRdOverrun;			/* 87 */
552 	volatile u_int32_t nicDmaRdUnderrun;			/* 88 */
553 	volatile u_int32_t nicDmaWrOverrun;			/* 89 */
554 	volatile u_int32_t nicDmaWrUnderrun;			/* 90 */
555 	volatile u_int32_t nicDmaWrMasterAborts;		/* 91 */
556 	volatile u_int32_t nicDmaRdMasterAborts;		/* 92 */
557 	/*
558 	 * NIC Resources
559 	 */
560 	volatile u_int32_t nicDmaWriteRingFull;			/* 93 */
561 	volatile u_int32_t nicDmaReadRingFull;			/* 94 */
562 	volatile u_int32_t nicEventRingFull;			/* 95 */
563 	volatile u_int32_t nicEventProducerRingFull;		/* 96 */
564 	volatile u_int32_t nicTxMacDescrRingFull;		/* 97 */
565 	volatile u_int32_t nicOutOfTxBufSpaceFrameRetry;	/* 98 */
566 	volatile u_int32_t nicNoMoreWrDMADescriptors;		/* 99 */
567 	volatile u_int32_t nicNoMoreRxBDs;			/* 100 */
568 	volatile u_int32_t nicNoSpaceInReturnRing;		/* 101 */
569 	volatile u_int32_t nicSendBDs;            /* current count 102 */
570 	volatile u_int32_t nicRecvBDs;            /* current count 103 */
571 	volatile u_int32_t nicJumboRecvBDs;       /* current count 104 */
572 	volatile u_int32_t nicMiniRecvBDs;        /* current count 105 */
573 	volatile u_int32_t nicTotalRecvBDs;       /* current count 106 */
574 	volatile u_int32_t nicTotalSendBDs;       /* current count 107 */
575 	volatile u_int32_t nicJumboSpillOver;			/* 108 */
576 	volatile u_int32_t nicSbusHangCleared;			/* 109 */
577 	volatile u_int32_t nicEnqEventDelayed;			/* 110 */
578 	/*
579 	 * Stats from MAC rx completion
580 	 */
581 	volatile u_int32_t nicMacRxLateColls;			/* 111 */
582 	volatile u_int32_t nicMacRxLinkLostDuringPkt;		/* 112 */
583 	volatile u_int32_t nicMacRxPhyDecodeErr;		/* 113 */
584 	volatile u_int32_t nicMacRxMacAbort;			/* 114 */
585 	volatile u_int32_t nicMacRxTruncNoResources;		/* 115 */
586 	/*
587 	 * Stats from the mac_stats area
588 	 */
589 	volatile u_int32_t nicMacRxDropUla;			/* 116 */
590 	volatile u_int32_t nicMacRxDropMcast;			/* 117 */
591 	volatile u_int32_t nicMacRxFlowControl;			/* 118 */
592 	volatile u_int32_t nicMacRxDropSpace;			/* 119 */
593 	volatile u_int32_t nicMacRxColls;			/* 120 */
594 	/*
595  	 * MAC RX Attentions
596 	 */
597 	volatile u_int32_t nicMacRxTotalAttns;			/* 121 */
598 	volatile u_int32_t nicMacRxLinkAttns;			/* 122 */
599 	volatile u_int32_t nicMacRxSyncAttns;			/* 123 */
600 	volatile u_int32_t nicMacRxConfigAttns;			/* 124 */
601 	volatile u_int32_t nicMacReset;				/* 125 */
602 	volatile u_int32_t nicMacRxBufDescrAttns;		/* 126 */
603 	volatile u_int32_t nicMacRxBufAttns;			/* 127 */
604 	volatile u_int32_t nicMacRxZeroFrameCleanup;		/* 128 */
605 	volatile u_int32_t nicMacRxOneFrameCleanup;		/* 129 */
606 	volatile u_int32_t nicMacRxMultipleFrameCleanup;	/* 130 */
607 	volatile u_int32_t nicMacRxTimerCleanup;		/* 131 */
608 	volatile u_int32_t nicMacRxDmaCleanup;			/* 132 */
609 	/*
610 	 * Stats from the mac_stats area
611 	 */
612 	volatile u_int32_t nicMacTxCollisionHistogram[15];	/* 133 */
613 	/*
614 	 * MAC TX Attentions
615 	 */
616 	volatile u_int32_t nicMacTxTotalAttns;			/* 134 */
617 	/*
618 	 * NIC Profile
619 	 */
620 	volatile u_int32_t nicProfile[32];			/* 135 */
621 	/*
622 	 * Pat to 1024 bytes.
623 	 */
624 	u_int32_t		pad[75];
625 };
626 /*
627  * Tigon general information block. This resides in host memory
628  * and contains the status counters, ring control blocks and
629  * producer pointers.
630  */
631 
632 struct ti_gib {
633 	struct ti_stats		ti_stats;
634 	struct ti_rcb		ti_ev_rcb;
635 	struct ti_rcb		ti_cmd_rcb;
636 	struct ti_rcb		ti_tx_rcb;
637 	struct ti_rcb		ti_std_rx_rcb;
638 	struct ti_rcb		ti_jumbo_rx_rcb;
639 	struct ti_rcb		ti_mini_rx_rcb;
640 	struct ti_rcb		ti_return_rcb;
641 	ti_hostaddr		ti_ev_prodidx_ptr;
642 	ti_hostaddr		ti_return_prodidx_ptr;
643 	ti_hostaddr		ti_tx_considx_ptr;
644 	ti_hostaddr		ti_refresh_stats_ptr;
645 };
646 
647 /*
648  * Buffer descriptor structures. There are basically three types
649  * of structures: normal receive descriptors, extended receive
650  * descriptors and transmit descriptors. The extended receive
651  * descriptors are optionally used only for the jumbo receive ring.
652  */
653 
654 struct ti_rx_desc {
655 	ti_hostaddr		ti_addr;
656 #if BYTE_ORDER == BIG_ENDIAN
657 	u_int16_t		ti_idx;
658 	u_int16_t		ti_len;
659 #else
660 	u_int16_t		ti_len;
661 	u_int16_t		ti_idx;
662 #endif
663 #if BYTE_ORDER == BIG_ENDIAN
664 	u_int16_t		ti_type;
665 	u_int16_t		ti_flags;
666 #else
667 	u_int16_t		ti_flags;
668 	u_int16_t		ti_type;
669 #endif
670 #if BYTE_ORDER == BIG_ENDIAN
671 	u_int16_t		ti_ip_cksum;
672 	u_int16_t		ti_tcp_udp_cksum;
673 #else
674 	u_int16_t		ti_tcp_udp_cksum;
675 	u_int16_t		ti_ip_cksum;
676 #endif
677 #if BYTE_ORDER == BIG_ENDIAN
678 	u_int16_t		ti_error_flags;
679 	u_int16_t		ti_vlan_tag;
680 #else
681 	u_int16_t		ti_vlan_tag;
682 	u_int16_t		ti_error_flags;
683 #endif
684 	u_int32_t		ti_rsvd;
685 	u_int32_t		ti_opaque;
686 };
687 
688 struct ti_rx_desc_ext {
689 	ti_hostaddr		ti_addr1;
690 	ti_hostaddr		ti_addr2;
691 	ti_hostaddr		ti_addr3;
692 #if BYTE_ORDER == BIG_ENDIAN
693 	u_int16_t		ti_len1;
694 	u_int16_t		ti_len2;
695 #else
696 	u_int16_t		ti_len2;
697 	u_int16_t		ti_len1;
698 #endif
699 #if BYTE_ORDER == BIG_ENDIAN
700 	u_int16_t		ti_len3;
701 	u_int16_t		ti_rsvd0;
702 #else
703 	u_int16_t		ti_rsvd0;
704 	u_int16_t		ti_len3;
705 #endif
706 	ti_hostaddr		ti_addr0;
707 #if BYTE_ORDER == BIG_ENDIAN
708 	u_int16_t		ti_idx;
709 	u_int16_t		ti_len0;
710 #else
711 	u_int16_t		ti_len0;
712 	u_int16_t		ti_idx;
713 #endif
714 #if BYTE_ORDER == BIG_ENDIAN
715 	u_int16_t		ti_type;
716 	u_int16_t		ti_flags;
717 #else
718 	u_int16_t		ti_flags;
719 	u_int16_t		ti_type;
720 #endif
721 #if BYTE_ORDER == BIG_ENDIAN
722 	u_int16_t		ti_ip_cksum;
723 	u_int16_t		ti_tcp_udp_cksum;
724 #else
725 	u_int16_t		ti_tcp_udp_cksum;
726 	u_int16_t		ti_ip_cksum;
727 #endif
728 #if BYTE_ORDER == BIG_ENDIAN
729 	u_int16_t		ti_error_flags;
730 	u_int16_t		ti_vlan_tag;
731 #else
732 	u_int16_t		ti_vlan_tag;
733 	u_int16_t		ti_error_flags;
734 #endif
735 	u_int32_t		ti_rsvd1;
736 	u_int32_t		ti_opaque;
737 };
738 
739 /*
740  * Transmit descriptors are, mercifully, very small.
741  */
742 struct ti_tx_desc {
743 	ti_hostaddr		ti_addr;
744 #if BYTE_ORDER == BIG_ENDIAN
745 	u_int16_t		ti_len;
746 	u_int16_t		ti_flags;
747 #else
748 	u_int16_t		ti_flags;
749 	u_int16_t		ti_len;
750 #endif
751 #if BYTE_ORDER == BIG_ENDIAN
752 	u_int16_t		ti_rsvd;
753 	u_int16_t		ti_vlan_tag;
754 #else
755 	u_int16_t		ti_vlan_tag;
756 	u_int16_t		ti_rsvd;
757 #endif
758 };
759 
760 /*
761  * NOTE!  On the Alpha, we have an alignment constraint.
762  * The first thing in the packet is a 14-byte Ethernet header.
763  * This means that the packet is misaligned.  To compensate,
764  * we actually offset the data 2 bytes into the cluster.  This
765  * alignes the packet after the Ethernet header at a 32-bit
766  * boundary.
767  */
768 
769 #define ETHER_ALIGN 2
770 
771 #define TI_PAGE_SIZE		PAGE_SIZE
772 
773 /*
774  * Buffer descriptor error flags.
775  */
776 #define TI_BDERR_CRC			0x0001
777 #define TI_BDERR_COLLDETECT		0x0002
778 #define TI_BDERR_LINKLOST		0x0004
779 #define TI_BDERR_DECODE			0x0008
780 #define TI_BDERR_ODD_NIBBLES		0x0010
781 #define TI_BDERR_MAC_ABRT		0x0020
782 #define TI_BDERR_RUNT			0x0040
783 #define TI_BDERR_TRUNC			0x0080
784 #define TI_BDERR_GIANT			0x0100
785 
786 /*
787  * Buffer descriptor flags.
788  */
789 #define TI_BDFLAG_TCP_UDP_CKSUM		0x0001
790 #define TI_BDFLAG_IP_CKSUM		0x0002
791 #define TI_BDFLAG_END			0x0004
792 #define TI_BDFLAG_MORE			0x0008
793 #define TI_BDFLAG_JUMBO_RING		0x0010
794 #define TI_BDFLAG_UCAST_PKT		0x0020
795 #define TI_BDFLAG_MCAST_PKT		0x0040
796 #define TI_BDFLAG_BCAST_PKT		0x0060
797 #define TI_BDFLAG_IP_FRAG		0x0080
798 #define TI_BDFLAG_IP_FRAG_END		0x0100
799 #define TI_BDFLAG_VLAN_TAG		0x0200
800 #define TI_BDFLAG_ERROR			0x0400
801 #define TI_BDFLAG_COAL_NOW		0x0800
802 #define	TI_BDFLAG_MINI_RING		0x1000
803 
804 /*
805  * Descriptor type flags. I think these only have meaning for
806  * the Tigon 1. I had to extract them from the sample driver source
807  * since they aren't in the manual.
808  */
809 #define TI_BDTYPE_TYPE_NULL			0x0000
810 #define TI_BDTYPE_SEND_BD			0x0001
811 #define TI_BDTYPE_RECV_BD			0x0002
812 #define TI_BDTYPE_RECV_JUMBO_BD			0x0003
813 #define TI_BDTYPE_RECV_BD_LAST			0x0004
814 #define TI_BDTYPE_SEND_DATA			0x0005
815 #define TI_BDTYPE_SEND_DATA_LAST		0x0006
816 #define TI_BDTYPE_RECV_DATA			0x0007
817 #define TI_BDTYPE_RECV_DATA_LAST		0x000b
818 #define TI_BDTYPE_EVENT_RUPT			0x000c
819 #define TI_BDTYPE_EVENT_NO_RUPT			0x000d
820 #define TI_BDTYPE_ODD_START			0x000e
821 #define TI_BDTYPE_UPDATE_STATS			0x000f
822 #define TI_BDTYPE_SEND_DUMMY_DMA		0x0010
823 #define TI_BDTYPE_EVENT_PROD			0x0011
824 #define TI_BDTYPE_TX_CONS			0x0012
825 #define TI_BDTYPE_RX_PROD			0x0013
826 #define TI_BDTYPE_REFRESH_STATS			0x0014
827 #define TI_BDTYPE_SEND_DATA_LAST_VLAN		0x0015
828 #define TI_BDTYPE_SEND_DATA_COAL		0x0016
829 #define TI_BDTYPE_SEND_DATA_LAST_COAL		0x0017
830 #define TI_BDTYPE_SEND_DATA_LAST_VLAN_COAL	0x0018
831 #define TI_BDTYPE_TX_CONS_NO_INTR		0x0019
832 
833 /*
834  * Tigon command structure.
835  */
836 struct ti_cmd_desc {
837 #if BYTE_ORDER == BIG_ENDIAN
838 	u_int32_t		ti_cmd:8;
839 	u_int32_t		ti_code:12;
840 	u_int32_t		ti_idx:12;
841 #else
842 	u_int32_t		ti_idx:12;
843 	u_int32_t		ti_code:12;
844 	u_int32_t		ti_cmd:8;
845 #endif
846 };
847 
848 #define TI_CMD_HOST_STATE		0x01
849 #define TI_CMD_CODE_STACK_UP		0x01
850 #define TI_CMD_CODE_STACK_DOWN		0x02
851 
852 /*
853  * This command enables software address filtering. It's a workaround
854  * for a bug in the Tigon 1 and not implemented for the Tigon 2.
855  */
856 #define TI_CMD_FDR_FILTERING		0x02
857 #define TI_CMD_CODE_FILT_ENB		0x01
858 #define TI_CMD_CODE_FILT_DIS		0x02
859 
860 #define TI_CMD_SET_RX_PROD_IDX		0x03 /* obsolete */
861 #define TI_CMD_UPDATE_GENCOM		0x04
862 #define TI_CMD_RESET_JUMBO_RING		0x05
863 #define TI_CMD_SET_PARTIAL_RX_CNT	0x06
864 #define TI_CMD_ADD_MCAST_ADDR		0x08 /* obsolete */
865 #define TI_CMD_DEL_MCAST_ADDR		0x09 /* obsolete */
866 
867 #define TI_CMD_SET_PROMISC_MODE		0x0A
868 #define TI_CMD_CODE_PROMISC_ENB		0x01
869 #define TI_CMD_CODE_PROMISC_DIS		0x02
870 
871 #define TI_CMD_LINK_NEGOTIATION		0x0B
872 #define TI_CMD_CODE_NEGOTIATE_BOTH	0x00
873 #define TI_CMD_CODE_NEGOTIATE_GIGABIT	0x01
874 #define TI_CMD_CODE_NEGOTIATE_10_100	0x02
875 
876 #define TI_CMD_SET_MAC_ADDR		0x0C
877 #define TI_CMD_CLR_PROFILE		0x0D
878 
879 #define TI_CMD_SET_ALLMULTI		0x0E
880 #define TI_CMD_CODE_ALLMULTI_ENB	0x01
881 #define TI_CMD_CODE_ALLMULTI_DIS	0x02
882 
883 #define TI_CMD_CLR_STATS		0x0F
884 #define TI_CMD_SET_RX_JUMBO_PROD_IDX	0x10 /* obsolete */
885 #define TI_CMD_RFRSH_STATS		0x11
886 
887 #define TI_CMD_EXT_ADD_MCAST		0x12
888 #define TI_CMD_EXT_DEL_MCAST		0x13
889 
890 /*
891  * Utility macros to make issuing commands a little simpler. Assumes
892  * that 'sc' and 'cmd' are in local scope.
893  */
894 #define TI_DO_CMD(x, y, z)		\
895 	cmd.ti_cmd = x;			\
896 	cmd.ti_code = y;		\
897 	cmd.ti_idx = z;			\
898 	ti_cmd(sc, &cmd);
899 
900 #define TI_DO_CMD_EXT(x, y, z, v, w)	\
901 	cmd.ti_cmd = x;			\
902 	cmd.ti_code = y;		\
903 	cmd.ti_idx = z;			\
904 	ti_cmd_ext(sc, &cmd, v, w);
905 
906 /*
907  * Other utility macros.
908  */
909 #define TI_INC(x, y)	(x) = (x + 1) % y
910 
911 #define TI_UPDATE_JUMBOPROD(x, y)					\
912 	if (x->ti_hwrev == TI_HWREV_TIGON) {				\
913 		TI_DO_CMD(TI_CMD_SET_RX_JUMBO_PROD_IDX, 0, y);	\
914 	} else {							\
915 		CSR_WRITE_4(x, TI_MB_JUMBORXPROD_IDX, y);		\
916 	}
917 
918 #define TI_UPDATE_MINIPROD(x, y)					\
919 		CSR_WRITE_4(x, TI_MB_MINIRXPROD_IDX, y);
920 
921 #define TI_UPDATE_STDPROD(x, y)						\
922 	if (x->ti_hwrev == TI_HWREV_TIGON) {				\
923 		TI_DO_CMD(TI_CMD_SET_RX_PROD_IDX, 0, y);		\
924 	} else {							\
925 		CSR_WRITE_4(x, TI_MB_STDRXPROD_IDX, y);			\
926 	}
927 
928 
929 /*
930  * Tigon event structure.
931  */
932 struct ti_event_desc {
933 #if BYTE_ORDER == BIG_ENDIAN
934 	u_int32_t		ti_event:8;
935 	u_int32_t		ti_code:12;
936 	u_int32_t		ti_idx:12;
937 #else
938 	u_int32_t		ti_idx:12;
939 	u_int32_t		ti_code:12;
940 	u_int32_t		ti_event:8;
941 #endif
942 	u_int32_t		ti_rsvd;
943 };
944 
945 /*
946  * Tigon events.
947  */
948 #define TI_EV_FIRMWARE_UP		0x01
949 #define TI_EV_STATS_UPDATED		0x04
950 
951 #define TI_EV_LINKSTAT_CHANGED		0x06
952 #define TI_EV_CODE_GIG_LINK_UP		0x01
953 #define TI_EV_CODE_LINK_DOWN		0x02
954 #define TI_EV_CODE_LINK_UP		0x03
955 
956 #define TI_EV_ERROR			0x07
957 #define TI_EV_CODE_ERR_INVAL_CMD	0x01
958 #define TI_EV_CODE_ERR_UNIMP_CMD	0x02
959 #define TI_EV_CODE_ERR_BADCFG		0x03
960 
961 #define TI_EV_MCAST_UPDATED		0x08
962 #define TI_EV_CODE_MCAST_ADD		0x01
963 #define TI_EV_CODE_MCAST_DEL		0x02
964 
965 #define TI_EV_RESET_JUMBO_RING		0x09
966 /*
967  * Register access macros. The Tigon always uses memory mapped register
968  * accesses and all registers must be accessed with 32 bit operations.
969  */
970 
971 #define CSR_WRITE_4(sc, reg, val)	\
972 	bus_space_write_4(sc->ti_btag, sc->ti_bhandle, (reg), (val))
973 
974 #define CSR_READ_4(sc, reg)		\
975 	bus_space_read_4(sc->ti_btag, sc->ti_bhandle, (reg))
976 
977 #define TI_SETBIT(sc, reg, x)	\
978 	CSR_WRITE_4(sc, (reg), (CSR_READ_4(sc, (reg)) | (x)))
979 #define TI_CLRBIT(sc, reg, x)	\
980 	CSR_WRITE_4(sc, (reg), (CSR_READ_4(sc, (reg)) & ~(x)))
981 
982 /*
983  * Memory management stuff. Note: the SSLOTS, MSLOTS and JSLOTS
984  * values are tuneable. They control the actual amount of buffers
985  * allocated for the standard, mini and jumbo receive rings.
986  */
987 
988 #define TI_SSLOTS	64 /* 256 */
989 #define TI_MSLOTS	64 /* 256 */
990 #define TI_JSLOTS	64 /* 256 */
991 #define TI_RSLOTS	128
992 
993 #define TI_JRAWLEN (ETHER_MAX_LEN_JUMBO + ETHER_ALIGN + sizeof(u_int64_t))
994 #define TI_JLEN (TI_JRAWLEN + (sizeof(u_int64_t) - \
995 	(TI_JRAWLEN % sizeof(u_int64_t))))
996 #define TI_JPAGESZ PAGE_SIZE
997 #define TI_RESID (TI_JPAGESZ - (TI_JLEN * TI_JSLOTS) % TI_JPAGESZ)
998 #define TI_JMEM ((TI_JLEN * TI_JSLOTS) + TI_RESID)
999 
1000 /*
1001  * Ring structures. Most of these reside in host memory and we tell
1002  * the NIC where they are via the ring control blocks. The exceptions
1003  * are the tx and command rings, which live in NIC memory and which
1004  * we access via the shared memory window.
1005  */
1006 struct ti_ring_data {
1007 	struct ti_rx_desc	ti_rx_std_ring[TI_STD_RX_RING_CNT];
1008 	struct ti_rx_desc	ti_rx_jumbo_ring[TI_JUMBO_RX_RING_CNT];
1009 	struct ti_rx_desc	ti_rx_mini_ring[TI_MINI_RX_RING_CNT];
1010 	struct ti_rx_desc	ti_rx_return_ring[TI_RETURN_RING_CNT];
1011 	struct ti_event_desc	ti_event_ring[TI_EVENT_RING_CNT];
1012 	struct ti_tx_desc	ti_tx_ring[TI_TX_RING_CNT];
1013 	/*
1014 	 * Make sure producer structures are aligned on 32-byte cache
1015 	 * line boundaries.
1016 	 */
1017 	struct ti_producer	ti_ev_prodidx_r;
1018 	u_int32_t		ti_pad0[6];
1019 	struct ti_producer	ti_return_prodidx_r;
1020 	u_int32_t		ti_pad1[6];
1021 	struct ti_producer	ti_tx_considx_r;
1022 	u_int32_t		ti_pad2[6];
1023 	struct ti_gib		ti_info;
1024 };
1025 
1026 #define	TI_CDOFF(x)		offsetof(struct ti_ring_data, x)
1027 #define	TI_CDRXSTDOFF(x)	TI_CDOFF(ti_rx_std_ring[(x)])
1028 #define	TI_CDRXJUMBOOFF(x)	TI_CDOFF(ti_rx_jumbo_ring[(x)])
1029 #define	TI_CDRXMINIOFF(x)	TI_CDOFF(ti_rx_mini_ring[(x)])
1030 #define	TI_CDRXRTNOFF(x)	TI_CDOFF(ti_rx_return_ring[(x)])
1031 #define	TI_CDEVENTOFF(x)	TI_CDOFF(ti_event_ring[(x)])
1032 #define	TI_CDTXOFF(x)		TI_CDOFF(ti_tx_ring[(x)])
1033 #define	TI_CDEVPRODOFF		TI_CDOFF(ti_ev_prodidx_r)
1034 #define	TI_CDRTNPRODOFF		TI_CDOFF(ti_return_prodidx_r)
1035 #define	TI_CDTXCONSOFF		TI_CDOFF(ti_tx_considx_r)
1036 #define	TI_CDGIBOFF		TI_CDOFF(ti_info)
1037 #define	TI_CDSTATSOFF		TI_CDOFF(ti_info.ti_stats)
1038 
1039 /*
1040  * Mbuf pointers. We need these to keep track of the virtual addresses
1041  * of our mbuf chains since we can only convert from physical to virtual,
1042  * not the other way around.
1043  */
1044 struct ti_chain_data {
1045 	struct mbuf		*ti_tx_chain[TI_TX_RING_CNT];
1046 	struct mbuf		*ti_rx_std_chain[TI_STD_RX_RING_CNT];
1047 	struct mbuf		*ti_rx_jumbo_chain[TI_JUMBO_RX_RING_CNT];
1048 	struct mbuf		*ti_rx_mini_chain[TI_MINI_RX_RING_CNT];
1049 	/* Stick the jumbo mem management stuff here too. */
1050 	caddr_t			ti_jslots[TI_JSLOTS];
1051 	void			*ti_jumbo_buf;
1052 };
1053 
1054 struct ti_type {
1055 	u_int16_t		ti_vid;
1056 	u_int16_t		ti_did;
1057 	char			*ti_name;
1058 };
1059 
1060 #define TI_HWREV_TIGON		0x01
1061 #define TI_HWREV_TIGON_II	0x02
1062 #define TI_TIMEOUT		1000
1063 #define TI_TXCONS_UNSET		0xFFFF	/* impossible value */
1064 
1065 struct ti_mc_entry {
1066 	struct ether_addr		mc_addr;
1067 	SIMPLEQ_ENTRY(ti_mc_entry)	mc_entries;
1068 };
1069 
1070 struct ti_jpool_entry {
1071 	int                             slot;
1072 	SIMPLEQ_ENTRY(ti_jpool_entry)	jpool_entries;
1073 };
1074 
1075 struct txdmamap_pool_entry {
1076 	bus_dmamap_t dmamap;
1077 	SIMPLEQ_ENTRY(txdmamap_pool_entry) link;
1078 };
1079 
1080 struct ti_softc {
1081 	struct device sc_dev;
1082 	struct ethercom		ethercom;	/* interface info */
1083 	bus_space_handle_t	ti_bhandle;
1084 	char			*ti_vhandle;
1085 	bus_space_tag_t		ti_btag;
1086 	void			*ti_intrhand;
1087 
1088 	struct ifmedia		ifmedia;	/* media info */
1089 
1090 	u_int8_t		ti_hwrev;	/* Tigon rev (1 or 2) */
1091 	u_int8_t		ti_copper;	/* 1000baseT card */
1092 	u_int8_t		ti_linkstat;	/* Link state */
1093 	struct ti_ring_data	*ti_rdata;	/* rings */
1094 #define ti_ev_prodidx		ti_rdata->ti_ev_prodidx_r
1095 #define ti_return_prodidx	ti_rdata->ti_return_prodidx_r
1096 #define ti_tx_considx		ti_rdata->ti_tx_considx_r
1097 
1098 	struct ti_tx_desc	*ti_tx_ring_nic;/* pointer to shared mem */
1099 
1100 	struct ti_chain_data	ti_cdata;	/* mbufs */
1101 
1102 	/*
1103 	 * Function pointers to deal with Tigon 1 vs. Tigon 2 differences.
1104 	 */
1105 	int			(*sc_tx_encap)(struct ti_softc *,
1106 				    struct mbuf *, uint32_t *);
1107 	void			(*sc_tx_eof)(struct ti_softc *);
1108 
1109 	u_int16_t		ti_tx_saved_considx;
1110 	u_int16_t		ti_rx_saved_considx;
1111 	u_int16_t		ti_ev_saved_considx;
1112 	u_int16_t		ti_cmd_saved_prodidx;
1113 	u_int16_t		ti_std;		/* current std ring head */
1114 	u_int16_t		ti_mini;	/* current mini ring head */
1115 	u_int16_t		ti_jumbo;	/* current jumo ring head */
1116 	SIMPLEQ_HEAD(, ti_mc_entry)	ti_mc_listhead;
1117 	SIMPLEQ_HEAD(, ti_jpool_entry)	ti_jfree_listhead;
1118 	SIMPLEQ_HEAD(, ti_jpool_entry)	ti_jinuse_listhead;
1119 	u_int32_t		ti_stat_ticks;
1120 	u_int32_t		ti_rx_coal_ticks;
1121 	u_int32_t		ti_tx_coal_ticks;
1122 	u_int32_t		ti_rx_max_coal_bds;
1123 	u_int32_t		ti_tx_max_coal_bds;
1124 	u_int32_t		ti_tx_buf_ratio;
1125 	int			ti_if_flags;
1126 	int			ti_txcnt;
1127 	void *sc_ih;
1128 	bus_dma_tag_t sc_dmat;
1129 	bus_dmamap_t info_dmamap; /* holds ti_rdata */
1130 	u_int32_t info_dmaaddr; /* XXX 64-bit PCI addresses? */
1131 	bus_dmamap_t jumbo_dmamap;
1132 	u_int32_t jumbo_dmaaddr; /* XXX 64-bit PCI addresses? */
1133 	bus_dmamap_t mini_dmamap[TI_MINI_RX_RING_CNT];
1134 	bus_dmamap_t std_dmamap[TI_STD_RX_RING_CNT];
1135 	SIMPLEQ_HEAD(, txdmamap_pool_entry) txdma_list;
1136 	struct txdmamap_pool_entry *txdma[TI_TX_RING_CNT];
1137 };
1138 
1139 #define	TI_CDRXSTDADDR(sc, x)	((sc)->info_dmaaddr + TI_CDRXSTDOFF((x)))
1140 #define	TI_CDRXJUMBOADDR(sc, x)	((sc)->info_dmaaddr + TI_CDRXJUMBOOFF((x)))
1141 #define	TI_CDRXMINIADDR(sc, x)	((sc)->info_dmaaddr + TI_CDRXMINIOFF((x)))
1142 #define	TI_CDRXRTNADDR(sc, x)	((sc)->info_dmaaddr + TI_CDRXRTNOFF((x)))
1143 #define	TI_CDEVENTADDR(sc, x)	((sc)->info_dmaaddr + TI_CDEVENTOFF((x)))
1144 #define	TI_CDTXADDR(sc, x)	((sc)->info_dmaaddr + TI_CDTXOFF((x)))
1145 #define	TI_CDEVPRODADDR(sc)	((sc)->info_dmaaddr + TI_CDEVPRODOFF)
1146 #define	TI_CDRTNPRODADDR(sc)	((sc)->info_dmaaddr + TI_CDRTNPRODOFF)
1147 #define	TI_CDTXCONSADDR(sc)	((sc)->info_dmaaddr + TI_CDTXCONSOFF)
1148 #define	TI_CDGIBADDR(sc)	((sc)->info_dmaaddr + TI_CDGIBOFF)
1149 #define	TI_CDSTATSADDR(sc)	((sc)->info_dmaaddr + TI_CDSTATSOFF)
1150 
1151 #define	TI_CDRXSTDSYNC(sc, x, ops)					\
1152 	bus_dmamap_sync((sc)->sc_dmat, (sc)->info_dmamap,		\
1153 	    TI_CDRXSTDOFF((x)), sizeof(struct ti_rx_desc), (ops))
1154 
1155 #define	TI_CDRXJUMBOSYNC(sc, x, ops)					\
1156 	bus_dmamap_sync((sc)->sc_dmat, (sc)->info_dmamap,		\
1157 	    TI_CDRXJUMBOOFF((x)), sizeof(struct ti_rx_desc), (ops))
1158 
1159 #define	TI_CDRXMINISYNC(sc, x, ops)					\
1160 	bus_dmamap_sync((sc)->sc_dmat, (sc)->info_dmamap,		\
1161 	    TI_CDRXMINIOFF((x)), sizeof(struct ti_rx_desc), (ops))
1162 
1163 #define	TI_CDRXRTNSYNC(sc, x, ops)					\
1164 	bus_dmamap_sync((sc)->sc_dmat, (sc)->info_dmamap,		\
1165 	    TI_CDRXRTNOFF((x)), sizeof(struct ti_rx_desc), (ops))
1166 
1167 #define	TI_CDEVENTSYNC(sc, x, ops)					\
1168 	bus_dmamap_sync((sc)->sc_dmat, (sc)->info_dmamap,		\
1169 	    TI_CDEVENTOFF((x)), sizeof(struct ti_event_desc), (ops))
1170 
1171 #define	TI_CDTXSYNC(sc, x, n, ops)					\
1172 do {									\
1173 	int __x, __n;							\
1174 									\
1175 	__x = (x);							\
1176 	__n = (n);							\
1177 									\
1178 	/* If it will wrap around, sync to the end of the ring. */	\
1179 	if ((__x + __n) > TI_TX_RING_CNT) {				\
1180 		bus_dmamap_sync((sc)->sc_dmat, (sc)->info_dmamap,	\
1181 		    TI_CDTXOFF(__x), sizeof(struct ti_tx_desc) *	\
1182 		    (TI_TX_RING_CNT - __x), (ops));			\
1183 		__n -= (TI_TX_RING_CNT - __x);				\
1184 		__x = 0;						\
1185 	}								\
1186 									\
1187 	/* Now sync whatever is left. */				\
1188 	bus_dmamap_sync((sc)->sc_dmat, (sc)->info_dmamap,		\
1189 	    TI_CDTXOFF(__x), sizeof(struct ti_tx_desc) * (__n), (ops));	\
1190 } while (/*CONSTCOND*/0)
1191 
1192 #define	TI_CEVPRODSYNC(sc, ops)						\
1193 	bus_dmamap_sync((sc)->sc_dmat, (sc)->info_dmamap,		\
1194 	    TI_CDEVPRODOFF, sizeof(struct ti_producer), (ops))
1195 
1196 #define	TI_CDRTNPRODSYNC(sc, ops)					\
1197 	bus_dmamap_sync((sc)->sc_dmat, (sc)->info_dmamap,		\
1198 	    TI_CDRTNPRODOFF, sizeof(struct ti_producer), (ops))
1199 
1200 #define	TI_CDTXCONSSYNC(sc, ops)					\
1201 	bus_dmamap_sync((sc)->sc_dmat, (sc)->info_dmamap,		\
1202 	    TI_CDTXCONSOFF, sizeof(struct ti_producer), (ops))
1203 
1204 #define	TI_CDGIBSYNC(sc, ops)						\
1205 	bus_dmamap_sync((sc)->sc_dmat, (sc)->info_dmamap,		\
1206 	    TI_CDGIBOFF, sizeof(struct ti_gib), (ops))
1207 
1208 #define	TI_CDSTATSSYNC(sc, ops)						\
1209 	bus_dmamap_sync((sc)->sc_dmat, (sc)->info_dmamap,		\
1210 	    TI_CDSTATSOFF, sizeof(struct ti_stats), (ops))
1211 
1212 /*
1213  * Microchip Technology 24Cxx EEPROM control bytes
1214  */
1215 #define EEPROM_CTL_READ			0xA1	/* 0101 0001 */
1216 #define EEPROM_CTL_WRITE		0xA0	/* 0101 0000 */
1217 
1218 /*
1219  * Note that EEPROM_START leaves transmission enabled.
1220  */
1221 #define EEPROM_START							\
1222 	TI_SETBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_CLK); /* Pull clock pin high */\
1223 	TI_SETBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_DOUT); /* Set DATA bit to 1 */	\
1224 	TI_SETBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_TXEN); /* Enable xmit to write bit */\
1225 	TI_CLRBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_DOUT); /* Pull DATA bit to 0 again */\
1226 	TI_CLRBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_CLK); /* Pull clock low again */
1227 
1228 /*
1229  * EEPROM_STOP ends access to the EEPROM and clears the ETXEN bit so
1230  * that no further data can be written to the EEPROM I/O pin.
1231  */
1232 #define EEPROM_STOP							\
1233 	TI_CLRBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_TXEN); /* Disable xmit */	\
1234 	TI_CLRBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_DOUT); /* Pull DATA to 0 */	\
1235 	TI_SETBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_CLK); /* Pull clock high */	\
1236 	TI_SETBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_TXEN); /* Enable xmit */	\
1237 	TI_SETBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_DOUT); /* Toggle DATA to 1 */	\
1238 	TI_CLRBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_TXEN); /* Disable xmit. */	\
1239 	TI_CLRBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_CLK); /* Pull clock low again */
1240