xref: /titanic_44/usr/src/uts/intel/io/dnet/dnet.h (revision 24fe0b3bf671e123467ce1df0b67cadd3614c8e4)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _DNET_H
27 #define	_DNET_H
28 
29 /* debug flags */
30 #define	DNETTRACE		0x01
31 #define	DNETERRS		0x02
32 #define	DNETRECV		0x04
33 #define	DNETDDI			0x08
34 #define	DNETSEND		0x10
35 #define	DNETINT			0x20
36 #define	DNETSENSE		0x40
37 #define	DNETREGCFG		0x80
38 
39 #ifdef DEBUG
40 #define	DNETDEBUG 1
41 #endif
42 
43 /* Misc */
44 #define	DNETHIWAT		32768	/* driver flow control high water */
45 #define	DNETLOWAT		4096	/* driver flow control low water */
46 #define	DNETMAXPKT		1500	/* maximum media frame size */
47 #define	DNETIDNUM		0	/* DNET Id; zero works */
48 #define	DNET_MAX_FRAG		6	/* max mblk in msg before we pullup */
49 
50 /* board state */
51 #define	DNET_IDLE		0
52 #define	DNET_WAITRCV		1
53 #define	DNET_XMTBUSY		2
54 #define	DNET_ERROR		3
55 
56 #define	SUCCESS			0
57 #define	FAILURE			1
58 
59 #define	DEC_VENDOR_ID		0x1011
60 #define	DEVICE_ID_21040		0x0002
61 #define	DEVICE_ID_21041		0x0014
62 #define	DEVICE_ID_21140		0x0009
63 
64 /* Apparently, the 21143 and 142 are distinguished by revision ID */
65 #define	DEVICE_ID_21142		0x0019
66 #define	DEVICE_ID_21143		0x0019
67 #define	COGENT_EM100		0x12
68 #define	COGENT_QUARTET400	0x13
69 #define	COGENT_EM110TX		0x14
70 #define	VENDOR_ID_OFFSET	32
71 #define	VENDOR_REVISION_OFFSET	33	/* Cogent */
72 #define	ASANTE_ETHER		0x000094
73 #define	COGENT_ETHER		0x000092
74 #define	ADAPTEC_ETHER		0x0000d1
75 #define	ZNYX_ETHER		0x00c095
76 #define	COGENT_SROM_ID		0x7c
77 #define	COGENT_ANA6911A_C	0x2a
78 #define	COGENT_ANA6911AC_C	0x2b
79 enum	{ DEFAULT_TYPE, COGENT_EM_TYPE, ASANTE_TYPE};
80 
81 #define	GLD_TX_RESEND		1 	/* return code for GLD resend */
82 #define	GLD_TX_OK		0	/* return code for GLD Tx ok */
83 
84 #ifndef GLD_INTR_WAIT
85 /* Temporary until this makes it into the build environment's gld.h */
86 #define	GLD_INTR_WAIT 0x0002	/* waiting for interrupt to do scheduling */
87 #endif
88 
89 #define	MAX_TX_DESC		128	/* Should be a multiple of 4 <= 256 */
90 #define	MAX_RX_DESC_21040	16	/* Should be a multiple of 4 <= 256 */
91 #define	MAX_RX_DESC_21140	32	/* Should be a multiple of 4 <= 256 */
92 
93 #define	SROM_SIZE		128
94 #define	SETUPBUF_SIZE		192	/* Setup buffer size */
95 #define	MCASTBUF_SIZE		512	/* multicast hash table size in bits */
96 #define	PRIORITY_LEVEL		5
97 #define	HASH_POLY		0x04C11DB6
98 #define	HASH_CRC		0xFFFFFFFFU
99 
100 #define	DNET_100MBPS		100	/* 21140 chip speeds */
101 #define	DNET_10MBPS		10
102 
103 
104 /* User defined PCI config space registers */
105 #define	PCI_DNET_CONF_CFDD	0x40
106 #define	CFDD_SLEEP		(1UL<<31)
107 #define	CFDD_SNOOZE		(1UL<<30)
108 /* CSR  Description */
109 #define	BUS_MODE_REG		0x00
110 #define	TX_POLL_REG		0x08
111 #define	RX_POLL_REG		0x10
112 #define	RX_BASE_ADDR_REG	0x18
113 #define	TX_BASE_ADDR_REG	0x20
114 #define	STATUS_REG		0x28
115 #define	OPN_MODE_REG		0x30
116 #define	INT_MASK_REG		0x38
117 #define	MISSED_FRAME_REG	0x40
118 #define	ETHER_ROM_REG		0x48
119 #define	BOOT_ROM_REG		0x50 /* 041, 140A, 142 */
120 #define	FULL_DUPLEX_REG		0x58 /* 040 */
121 #define	GP_TIMER_REG		0x58 /* 140-143 */
122 #define	SIA_STATUS_REG		0x60 /* 040, 041, 142 */
123 #define	SIA_CONNECT_REG		0x68 /* 040, 041, 142 */
124 #define	SIA_TXRX_REG		0x70 /* 041, 041, 142 */
125 #define	SIA_GENERAL_REG		0x78 /* 040, 041, 142 */
126 #define	GP_REG			0x60 /* 140, 140A */
127 
128 /* Helpful defines for register access */
129 #define	REG32(reg, off)		((uint32_t *)((uintptr_t)(reg) + off))
130 #define	REG16(reg, off)		((uint16_t *)((uintptr_t)(reg) + off))
131 #define	REG8(reg, off)		((uint8_t *)((uintptr_t)(reg) + off))
132 
133 /* Bit descriptions of CSR registers */
134 
135 /* BUS_MODE_REG, CSR0 */
136 #define	SW_RESET		0x01UL
137 #define	BURST_SIZE		0x2000UL
138 #define	CACHE_ALIGN		0x04000UL /* 8 long word boundary align */
139 
140 /* TX_POLL_REG, CSR1 */
141 #define	TX_POLL_DEMAND  	0x01
142 
143 /* RX_POLL_REG, CSR2 */
144 #define	RX_POLL_DEMAND  	0x01
145 
146 /* STATUS_REG, CSR5 */
147 #define	TX_INTR			0x01UL
148 #define	TX_STOPPED		0x02UL
149 #define	TX_BUFFER_UNAVAILABLE	0x04UL
150 #define	TX_JABBER_TIMEOUT	0x08UL
151 #define	TX_UNDERFLOW		0x20UL
152 #define	RX_INTR			0x40UL
153 #define	RX_UNAVAIL_INTR		0x80UL
154 #define	RX_STOP_INTR		0x0100UL
155 #define	LINK_INTR		0x1000UL
156 #define	SYS_ERR			0x2000UL
157 #define	ABNORMAL_INTR_SUMM	0x8000UL
158 #define	NORMAL_INTR_SUMM	0x10000UL
159 #define	RECEIVE_PROCESS_STATE	0xe0000UL
160 #define	SYS_ERR_BITS		0x3800000UL
161 #define	PARITY_ERROR		0x00000000UL
162 #define	MASTER_ABORT		0x00800000UL
163 #define	TARGET_ABORT		0x01000000UL
164 
165 /* OPN_REG , CSR6  */
166 #define	HASH_FILTERING		(1UL<<0)
167 #define	START_RECEIVE		(1UL<<1)
168 #define	HASH_ONLY		(1UL<<2)
169 #define	PASSBAD			(1UL<<3)
170 #define	INV_FILTER		(1UL<<4)
171 #define	START_BACKOFF		(1UL<<5)
172 #define	PROM_MODE		(1UL<<6)
173 #define	PASS_MULTICAST		(1UL<<7)
174 #define	FULL_DUPLEX		(1UL<<9)
175 #define	OPERATING_MODE		(3UL<<10)		/* 143 */
176 #define	FORCE_COLLISION		(1UL<<12)
177 #define	START_TRANSMIT 		(1UL<<13)
178 #define	TX_THRESHOLD_160	(3UL<<14)
179 #define	CAPTURE_ENABLE		(1UL<<17)
180 #define	PORT_SELECT		(1UL<<18)		/* 140, 140A, 142 */
181 #define	HEARTBEAT_DISABLE	(1UL<<19)		/* 140, 140A, 142 */
182 #define	STORE_AND_FORWARD	(1UL<<21)		/* 140, 140A, 142 */
183 #define	TX_THRESHOLD_MODE	(1UL<<22)		/* 140, 140A, 142 */
184 #define	PCS_FUNCTION		(1UL<<23)		/* 140, 140A */
185 #define	SCRAMBLER_MODE		(1UL<<24)		/* 140, 140A */
186 #define	OPN_REG_MB1		(1UL<<25)
187 #define	RECEIVEALL		(1UL<<30)
188 #define	SPECIAL_CAPTURE		(1UL<<31)
189 
190 /* INT_MASK_REG , CSR7  */
191 #define	TX_INTERRUPT_MASK	0x01UL
192 #define	TX_STOPPED_MASK		0x02UL
193 #define	TX_BUFFER_UNAVAIL_MASK	0x04UL
194 #define	TX_JABBER_MASK		0x08UL
195 #define	TX_UNDERFLOW_MASK	0x20UL
196 #define	RX_INTERRUPT_MASK	0x40UL
197 #define	RX_UNAVAIL_MASK 	0x80UL
198 #define	RX_STOP_MASK		0x00100UL
199 #define	GPTIMER_INTR		0x800UL
200 #define	LINK_INTR_MASK   	0x01000UL
201 #define	SYSTEM_ERROR_MASK   	0x02000UL
202 #define	ABNORMAL_INTR_MASK	0x08000UL
203 #define	NORMAL_INTR_MASK	0x10000UL
204 
205 /* MISSED_FRAME_REG, CSR8 */
206 #define	MISSED_FRAME_MASK	0x0ffffUL
207 #define	OVERFLOW_COUNTER_MASK	0xffe0000UL
208 
209 /* Serial ROM Register CSR9 */
210 #define	SROM_MAX_CYCLES		5UL
211 #define	SEL_CHIP		0x01UL
212 #define	SEL_CLK			0x02UL
213 #define	DATA_IN			0x04UL
214 #define	DATA_OUT		0x08UL
215 #define	HIGH_ADDRESS_BIT	0x20UL
216 #define	SEL_ROM			0x800UL
217 #define	READ_OP			0x4000UL
218 
219 #define	MII_WRITE		((uint32_t)(0x00002000))
220 #define	MII_CLOCK		((uint32_t)(0x00010000))
221 #define	MII_WRITE_DATA		((uint32_t)(0x00020000))
222 #define	MII_DATA_IN		((uint32_t)(0x00080000))
223 #define	MII_PHY_ADDR_ALIGN	23
224 #define	MII_REG_ADDR_ALIGN	18
225 #define	MII_WRITE_DATA_POSITION	17
226 #define	MII_DATA_IN_POSITION	19
227 #define	MII_DELAY		1  /* 1 microsecond */
228 #define	MII_PRE			((uint32_t)(0xFFFFFFFF))
229 #define	MII_READ_FRAME		((uint32_t)(0x60000000))
230 #define	MII_WRITE_FRAME		((uint32_t)(0x50020000))
231 #define	MII_READ		((uint32_t)(0x00044000))
232 #define	MII_WRITE_TS		((uint32_t)(0x00042000))
233 
234 
235 /* GPR Timer reg, CSR11 */
236 #define	GPTIMER_CONT		(1UL<<16)
237 /* SIA Connectivity reg, CSR13 (040, 041, 142) */
238 #define	AUTO_CONFIG		0x05UL
239 #define	BNC_CONFIG		0x0DUL
240 #define	SIA_CONNECT_MASK	0xFFFF0000UL
241 #define	SIA_TXRX_MASK		0xFFFFFFFFUL
242 #define	SIA_GENERAL_MASK	0xFFFF0000UL
243 
244 #define	SIA_TXRX_MASK_TP	0xFFFFFFFFUL
245 #define	SIA_GENRL_MASK_TP	0x00UL
246 #define	SIA_CONN_MASK_AUI	0xEF09UL
247 #define	SIA_TXRX_MASK_AUI	0x0000F73DUL
248 #define	SIA_GENRL_MASK_AUI	0x0000000EUL
249 
250 #define	CWE_21140		0x00000100UL /* This is moved in the 21143 */
251 #define	CSR15_C
252 #define	MEDIA_TP		0
253 #define	MEDIA_BNC		1
254 #define	MEDIA_AUI		2
255 #define	MEDIA_SYM_SCR		3
256 #define	MEDIA_TP_FD		4
257 #define	MEDIA_SYM_SCR_FD	5
258 #define	MEDIA_100T4		6
259 #define	MEDIA_100FX		7
260 #define	MEDIA_100FX_FD		8
261 #define	MEDIA_MII		9
262 
263 
264 /* CSR15 */
265 #define	CWE_21143		(1UL<<11)
266 
267 #define	MEDIA_CAP_100T4		0x8000UL
268 #define	MEDIA_CAP_100FDX	0x4000UL
269 #define	MEDIA_CAP_100HDX	0x2000UL
270 #define	MEDIA_CAP_10FDX		0x1000UL
271 #define	MEDIA_CAP_10HDX		0x800UL
272 
273 /*
274  * In GPR and reset sequences in the ROM this is used to decide wheather the
275  * CWE bit should be set when writing to the GPR. However, the CWE bit is
276  * different on the 143 and 140, so we pick a bit where we can safely store
277  * this information in the ROM structure before writing it out to the GPR
278  * register itself
279  */
280 #define	GPR_CONTROL_WRITE	(1UL<<31)
281 
282 /* command block bit flags from SROM */
283 #define	CMD_PS			(1<<0)
284 #define	CMD_TTM			(1<<4)
285 #define	CMD_PCS			(1<<5)
286 #define	CMD_SCR			(1<<6)
287 #define	CMD_POL			(1<<7)
288 #define	CMD_DEFAULT_MEDIUM	(1<<14)
289 #define	CMD_ACTIVE_INVALID	(1<<15)
290 #define	CMD_MEDIABIT_MASK	0xE
291 
292 #define	MAX_SEQ			8
293 #define	MAX_ADAPTERS		8
294 #define	MAX_MEDIA		8
295 
296 
297 
298 struct dnetinstance;
299 
300 typedef void (*timercb_t)(struct dnetinstance *);
301 
302 
303 typedef struct _media_block_t {
304 	int type;
305 	uint16_t command;
306 	int gprseqlen;
307 	int rstseqlen;
308 	int media_code;
309 	uint16_t gprseq[8];
310 	uint16_t rstseq[8];
311 	unsigned int hassia:1;
312 	union {
313 		struct {
314 			int phy_num;
315 			uint16_t nwayadvert;
316 			uint16_t fdxmask;
317 			uint16_t ttmmask;
318 			uint16_t miiintr;
319 			uint16_t mediacaps;
320 		} mii;
321 		struct {
322 			uint32_t csr13;
323 			uint32_t csr14;
324 			uint32_t csr15;
325 		} sia;
326 	} un;
327 } media_block_t;
328 
329 typedef struct leaf_format {
330 	uint16_t device_number;
331 	uint16_t gpr;
332 	uint16_t selected_contype;
333 	int block_count;
334 	media_block_t *default_block;
335 	media_block_t *mii_block;
336 	media_block_t block[MAX_MEDIA];
337 	int is_static;
338 } LEAF_FORMAT;
339 
340 
341 typedef struct srom_format {
342 	int	init_from_srom;
343 	/* elements used to store Version 1,3 and proprietary formats */
344 	uchar_t version;
345 	uchar_t adapters;
346 	uchar_t netaddr[ETHERADDRL];
347 	LEAF_FORMAT *leaf;
348 } SROM_FORMAT;
349 
350 #define	SROM_VERSION		18
351 #define	SROM_ADAPTER_CNT	19
352 #define	SROM_NETADDR		20
353 #define	SROM_LEAF_OFFSET	26
354 #define	SROM_MBZ		 6
355 #define	SROM_MBZ2		15
356 #define	SROM_MBZ3		17
357 
358 #define	MEDIA_CODE_MASK		0x3F
359 #define	EXT_BIT			0x40
360 
361 struct dnetinstance {
362 	caddr_t			io_reg;		/* mapped register */
363 	int 			board_type;	/* board type: 21040 or 21140 */
364 	int			full_duplex;
365 	int 			bnc_indicator; 	/* Flag for BNC connector */
366 	uint64_t		speed;		/* data rate: 10 or 100 */
367 	int			secondary;	/* SROM read as all zero */
368 	SROM_FORMAT		sr;
369 	int			leaf;
370 	int			vendor_21140;
371 	int			vendor_revision;
372 	int			promisc;
373 	int			need_saddr;
374 	int			max_tx_desc;	/* max xmit descriptors */
375 	caddr_t 		setup_buf_vaddr; /* setup buffer (virt) */
376 	uint32_t 		setup_buf_paddr; /* setup buffer (phys) */
377 	struct tx_desc_type	*tx_desc;	/* virtual addr of xmit desc */
378 	uint32_t		tx_desc_paddr;	/* physical addr of xmit desc */
379 	struct rx_desc_type	*rx_desc;	/* virtual addr of recv desc */
380 	uint32_t		rx_desc_paddr;	/* physical addr of recv desc */
381 	char			multicast_cnt[MCASTBUF_SIZE];
382 	ddi_acc_handle_t	io_handle;	/* ddi I/O handle */
383 	dev_info_t		*devinfo;
384 	int			max_rx_desc;	/* max recv descriptors */
385 	ddi_dma_handle_t	dma_handle;
386 	ddi_dma_handle_t	dma_handle_tx;
387 	ddi_dma_handle_t	dma_handle_txdesc;
388 	ddi_dma_handle_t	dma_handle_setbuf;
389 	int			pgmask;
390 	ddi_acc_handle_t	setup_buf_acchdl;
391 	int			nxmit_desc;	/* #of xmit descriptors */
392 	int			nrecv_desc;	/* #of recv descriptors */
393 	ddi_acc_handle_t	tx_desc_acchdl;
394 	ddi_acc_handle_t	rx_desc_acchdl;
395 	mblk_t			**tx_msgbufp;	/* streams message buffers */
396 						/* used for xmit */
397 	caddr_t			*rx_buf_vaddr;	/* recv buf addresses (virt) */
398 	uint32_t		*rx_buf_paddr;	/* recv buf addresses (phys) */
399 	kmutex_t		txlock;
400 	kmutex_t		intrlock;
401 	boolean_t		suspended;
402 	boolean_t		running;
403 	int	need_gld_sched;
404 
405 	uint32_t	stat_errrcv;
406 	uint32_t	stat_overflow;
407 	uint32_t	stat_intr;
408 	uint32_t	stat_defer;
409 	uint32_t	stat_missed;
410 	uint32_t	stat_norcvbuf;
411 	uint32_t	stat_crc;
412 	uint32_t	stat_short;
413 	uint32_t	stat_frame;
414 	uint32_t	stat_errxmt;
415 	uint32_t	stat_collisions;
416 	uint32_t	stat_xmtlatecoll;
417 	uint32_t	stat_excoll;
418 	uint32_t	stat_underflow;
419 	uint32_t	stat_nocarrier;
420 	int			tx_current_desc; /* Current Tx descriptor */
421 	int 			rx_current_desc; /* Current descriptor of Rx  */
422 	int			transmitted_desc; /* Descriptor count xmitted */
423 	int 			free_desc;	/* Descriptors available */
424 	mii_handle_t		mii;
425 	int			mii_speed;
426 	int			mii_duplex;
427 	int			phyaddr;
428 	uchar_t		vendor_addr[ETHERADDRL];
429 	uchar_t		curr_macaddr[ETHERADDRL];
430 	media_block_t		*selected_media_block;
431 	uint32_t		disallowed_media;
432 	int			disable_scrambler;
433 	int			overrun_workaround;
434 	int			interrupts_disabled;
435 	int			mii_up;
436 	uint32_t		gprsia; /* Write-through for 143's gprsia reg */
437 	struct hackintr_inf	*hackintr_inf;
438 	struct {
439 		timercb_t	cb;
440 		uint32_t	start_ticks;
441 	} timer;
442 };
443 
444 #pragma pack(1)
445 
446 #define	BCOPY(from, to, len) bcopy(from, to, len)
447 
448 /*
449  * Receive descriptor description
450  */
451 struct rx_desc_type {
452 	struct {
453 		volatile uint32_t
454 				overflow	: 01,
455 				crc 		: 01,
456 				dribbling	: 01,
457 				mii_err		: 01,
458 				rcv_watchdog 	: 01,
459 				frame_type	: 01,
460 				collision	: 01,
461 				frame2long   	: 01,
462 				last_desc	: 01,
463 				first_desc	: 01,
464 				multi_frame  	: 01,
465 				runt_frame	: 01,
466 				u_data_type	: 02,
467 				desc_err	: 01,
468 				err_summary  	: 01,
469 				frame_len	: 14,
470 				filter_fail	: 01,
471 				own		: 01;
472 	} desc0;
473 	struct {
474 		volatile uint32_t
475 				buffer_size1 	: 11,
476 				buffer_size2 	: 11,
477 				not_used	: 02,
478 				chaining	: 01,
479 				end_of_ring	: 01,
480 				rsvd1		: 06;
481 	} desc1;
482 	volatile uint32_t	buffer1;
483 	volatile uint32_t	buffer2;
484 };
485 
486 /*
487  * Receive descriptor description
488  */
489 struct tx_desc_type {
490 	struct {
491 		volatile uint32_t
492 				deferred	: 1,
493 				underflow	: 1,
494 				link_fail	: 1,
495 				collision_count : 4,
496 				heartbeat_fail	: 1,
497 				excess_collision : 1,
498 				late_collision	: 1,
499 				no_carrier	: 1,
500 				carrier_loss	: 1,
501 				rsvd1		: 2,
502 				tx_jabber_to	: 1,
503 				err_summary	: 1,
504 				rsvd		: 15,
505 				own		: 1;
506 	} desc0;
507 	struct {
508 		volatile uint32_t
509 				buffer_size1 	: 11,
510 				buffer_size2 	: 11,
511 				filter_type0 	: 1,
512 				disable_padding : 1,
513 				chaining 	: 1,
514 				end_of_ring  	: 1,
515 				crc_disable  	: 1,
516 				setup_packet 	: 1,
517 				filter_type1 	: 1,
518 				first_desc   	: 1,
519 				last_desc    	: 1,
520 				int_on_comp  	: 1;
521 	} desc1;
522 	volatile uint32_t	buffer1;
523 	volatile uint32_t	buffer2;
524 };
525 
526 
527 #define	DNET_END_OF_RING	0x2000000
528 
529 #pragma pack()
530 
531 #endif	/* _DNET_H */
532