xref: /titanic_41/usr/src/uts/common/sys/nxge/nxge_common.h (revision cc1a9a89a73172cc2db053635fab3b1b91691657)
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 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_NXGE_NXGE_COMMON_H
27 #define	_SYS_NXGE_NXGE_COMMON_H
28 
29 #ifdef	__cplusplus
30 extern "C" {
31 #endif
32 
33 #define	NXGE_DMA_START			B_TRUE
34 #define	NXGE_DMA_STOP			B_FALSE
35 
36 /*
37  * Default DMA configurations.
38  */
39 #define	NXGE_RDMA_PER_NIU_PORT		(NXGE_MAX_RDCS/NXGE_PORTS_NIU)
40 #define	NXGE_TDMA_PER_NIU_PORT		(NXGE_MAX_TDCS_NIU/NXGE_PORTS_NIU)
41 #define	NXGE_RDMA_PER_NEP_PORT		(NXGE_MAX_RDCS/NXGE_PORTS_NEPTUNE)
42 #define	NXGE_TDMA_PER_NEP_PORT		(NXGE_MAX_TDCS/NXGE_PORTS_NEPTUNE)
43 #define	NXGE_RDCGRP_PER_NIU_PORT	(NXGE_MAX_RDC_GROUPS/NXGE_PORTS_NIU)
44 #define	NXGE_RDCGRP_PER_NEP_PORT	(NXGE_MAX_RDC_GROUPS/NXGE_PORTS_NEPTUNE)
45 
46 #define	NXGE_TIMER_RESO			2
47 
48 #define	NXGE_TIMER_LDG			2
49 
50 /*
51  * Receive and Transmit DMA definitions
52  */
53 #if	defined(sun4v) && defined(NIU_LP_WORKAROUND)
54 /*
55  * N2/NIU: Maximum descriptors if we need to call
56  *	   Hypervisor to set up the logical pages
57  *	   and the driver must use contiguous memory.
58  */
59 #define	NXGE_NIU_MAX_ENTRY		(1 << 9) /* 512 */
60 #define	NXGE_NIU_CONTIG_RBR_MAX		(NXGE_NIU_MAX_ENTRY)
61 #define	NXGE_NIU_CONTIG_RCR_MAX		(NXGE_NIU_MAX_ENTRY)
62 #define	NXGE_NIU_CONTIG_TX_MAX		(NXGE_NIU_MAX_ENTRY)
63 #endif
64 
65 #ifdef	_DMA_USES_VIRTADDR
66 #ifdef	NIU_PA_WORKAROUND
67 #define	NXGE_DMA_BLOCK		(16 * 64 * 4)
68 #else
69 #define	NXGE_DMA_BLOCK		1
70 #endif
71 #else
72 #define	NXGE_DMA_BLOCK		(64 * 64)
73 #endif
74 
75 #define	NXGE_RBR_RBB_MIN	(128)
76 #define	NXGE_RBR_RBB_MAX	(64 * 128 -1)
77 
78 #if	defined(sun4v) && defined(NIU_LP_WORKAROUND)
79 #define	NXGE_RBR_RBB_DEFAULT	512
80 #define	NXGE_RBR_SPARE		0
81 #else
82 #if	defined(__i386)
83 #define	NXGE_RBR_RBB_DEFAULT	256
84 #else
85 #define	NXGE_RBR_RBB_DEFAULT	(64 * 16) /* x86 hello */
86 #endif
87 #define	NXGE_RBR_SPARE		0
88 #endif
89 
90 
91 #define	NXGE_RCR_MIN		(NXGE_RBR_RBB_MIN * 2)
92 
93 #if	defined(sun4v) && defined(NIU_LP_WORKAROUND)
94 #define	NXGE_RCR_MAX		(8192)
95 #define	NXGE_RCR_DEFAULT	(512)
96 #define	NXGE_TX_RING_DEFAULT	(512)
97 #else
98 #ifndef	NIU_PA_WORKAROUND
99 #define	NXGE_RCR_MAX		(65355) /* MAX hardware supported */
100 #if defined(_BIG_ENDIAN)
101 #define	NXGE_RCR_DEFAULT	(NXGE_RBR_RBB_DEFAULT * 8)
102 #else
103 #ifdef USE_RX_BIG_BUF
104 #define	NXGE_RCR_DEFAULT	(NXGE_RBR_RBB_DEFAULT * 8)
105 #else
106 #define	NXGE_RCR_DEFAULT	(NXGE_RBR_RBB_DEFAULT * 4)
107 #endif
108 #endif
109 #if	defined(__i386)
110 #define	NXGE_TX_RING_DEFAULT	(256)
111 #else
112 #define	NXGE_TX_RING_DEFAULT	(1024)
113 #endif
114 #define	NXGE_TX_RING_MAX	(64 * 128 - 1)
115 #else
116 #if	defined(__i386)
117 #define	NXGE_RCR_DEFAULT	(256)
118 #define	NXGE_TX_RING_DEFAULT	(256)
119 #else
120 #define	NXGE_RCR_DEFAULT	(512)
121 #define	NXGE_TX_RING_DEFAULT	(512)
122 #endif
123 #define	NXGE_RCR_MAX		(1024)
124 #define	NXGE_TX_RING_MAX	(1024)
125 #endif
126 #endif
127 
128 #define	NXGE_TX_RECLAIM 	32
129 
130 /* per receive DMA channel configuration data structure */
131 typedef struct  nxge_rdc_cfg {
132 	uint32_t	flag;		/* 0: not configured, 1: configured */
133 	struct nxge_hw_list *nxge_hw_p;
134 	uint32_t	partition_id;
135 	uint32_t	port;		/* function number */
136 	uint32_t	rx_group_id;
137 
138 	/* Partitioning, DMC function zero. */
139 	uint32_t	rx_log_page_vld_page0;	/* TRUE or FALSE */
140 	uint32_t	rx_log_page_vld_page1;	/* TRUE or FALSE */
141 	uint64_t	rx_log_mask1;
142 	uint64_t	rx_log_value1;
143 	uint64_t	rx_log_mask2;
144 	uint64_t	rx_log_value2;
145 	uint64_t	rx_log_page_relo1;
146 	uint64_t	rx_log_page_relo2;
147 	uint64_t	rx_log_page_hdl;
148 
149 	/* WRED parameters, DMC function zero */
150 	uint32_t	red_enable;
151 
152 	uint32_t	thre_syn;
153 	uint32_t	win_syn;
154 	uint32_t	threshold;
155 	uint32_t	win_non_syn;
156 
157 	/* RXDMA configuration, DMC */
158 	char		*rdc_mbaddr_p;	/* mailbox address */
159 	uint32_t	min_flag;	/* TRUE for 18 bytes header */
160 
161 	/* Software Reserved Packet Buffer Offset, DMC */
162 	uint32_t	sw_offset;
163 
164 	/* RBR Configuration A */
165 	uint64_t	rbr_staddr;	/* starting address of RBR */
166 	uint32_t	rbr_nblks;	/* # of RBR entries */
167 	uint32_t	rbr_len;	/* # of RBR entries in 64B lines */
168 
169 	/* RBR Configuration B */
170 	uint32_t	bksize;		/* Block size is fixed. */
171 #define	RBR_BKSIZE_4K			0
172 #define	RBR_BKSIZE_4K_BYTES		(4 * 1024)
173 #define	RBR_BKSIZE_8K			1
174 #define	RBR_BKSIZE_8K_BYTES		(8 * 1024)
175 #define	RBR_BKSIZE_16K			2
176 #define	RBR_BKSIZE_16K_BYTES		(16 * 1024)
177 #define	RBR_BKSIZE_32K			3
178 #define	RBR_BKSIZE_32K_BYTES		(32 * 1024)
179 
180 	uint32_t	bufsz2;
181 #define	RBR_BUFSZ2_2K			0
182 #define	RBR_BUFSZ2_2K_BYTES		(2 * 1024)
183 #define	RBR_BUFSZ2_4K			1
184 #define	RBR_BUFSZ2_4K_BYTES		(4 * 1024)
185 #define	RBR_BUFSZ2_8K			2
186 #define	RBR_BUFSZ2_8K_BYTES		(8 * 1024)
187 #define	RBR_BUFSZ2_16K			3
188 #define	RBR_BUFSZ2_16K_BYTES		(16 * 1024)
189 
190 	uint32_t	bufsz1;
191 #define	RBR_BUFSZ1_1K			0
192 #define	RBR_BUFSZ1_1K_BYTES		1024
193 #define	RBR_BUFSZ1_2K			1
194 #define	RBR_BUFSZ1_2K_BYTES		(2 * 1024)
195 #define	RBR_BUFSZ1_4K			2
196 #define	RBR_BUFSZ1_4K_BYTES		(4 * 1024)
197 #define	RBR_BUFSZ1_8K			3
198 #define	RBR_BUFSZ1_8K_BYTES		(8 * 1024)
199 
200 	uint32_t	bufsz0;
201 #define	RBR_BUFSZ0_256B			0
202 #define	RBR_BUFSZ0_256_BYTES		256
203 #define	RBR_BUFSZ0_512B			1
204 #define	RBR_BUFSZ0_512B_BYTES		512
205 #define	RBR_BUFSZ0_1K			2
206 #define	RBR_BUFSZ0_1K_BYTES		(1024)
207 #define	RBR_BUFSZ0_2K			3
208 #define	RBR_BUFSZ0_2K_BYTES		(2 * 1024)
209 
210 	/* Receive buffers added by the software */
211 	uint32_t	bkadd;		/* maximum size is 1 million */
212 
213 	/* Receive Completion Ring Configuration A */
214 	uint32_t	rcr_len;	/* # of 64B blocks, each RCR is 8B */
215 	uint64_t	rcr_staddr;
216 
217 	/* Receive Completion Ring Configuration B */
218 	uint32_t	pthres;		/* packet threshold */
219 	uint32_t	entout;		/* enable timeout */
220 	uint32_t	timeout;	/* timeout value */
221 
222 	/* Logical Device Group Number */
223 	uint16_t	rx_ldg;
224 	uint16_t	rx_ld_state_flags;
225 
226 	/* Receive DMA Channel Event Mask */
227 	uint64_t	rx_dma_ent_mask;
228 
229 	/* 32 bit (set to 1) or 64 bit (set to 0) addressing mode */
230 	uint32_t	rx_addr_md;
231 } nxge_rdc_cfg_t, *p_nxge_rdc_cfg_t;
232 
233 /*
234  * Per Transmit DMA Channel Configuration Data Structure (32 TDC)
235  */
236 typedef struct  nxge_tdc_cfg {
237 	uint32_t	flag;		/* 0: not configured 1: configured */
238 	struct nxge_hw_list *nxge_hw_p;
239 	uint32_t	port; 		/* function number */
240 	/* partitioning, DMC function zero (All 0s for non-partitioning) */
241 	uint32_t	tx_log_page_vld_page0;	/* TRUE or FALSE */
242 	uint32_t	tx_log_page_vld_page1;	/* TRUE or FALSE */
243 	uint64_t	tx_log_mask1;
244 	uint64_t	tx_log_value1;
245 	uint64_t	tx_log_mask2;
246 	uint64_t	tx_log_value2;
247 	uint64_t	tx_log_page_relo1;
248 	uint64_t	tx_log_page_relo2;
249 	uint64_t	tx_log_page_hdl;
250 
251 	/* Transmit Ring Configuration */
252 	uint64_t	tx_staddr;
253 	uint64_t	tx_rng_len;	/* in 64 B Blocks */
254 #define	TX_MAX_BUF_SIZE			4096
255 
256 	/* TXDMA configuration, DMC */
257 	char		*tdc_mbaddr_p;	/* mailbox address */
258 
259 	/* Logical Device Group Number */
260 	uint16_t	tx_ldg;
261 	uint16_t	tx_ld_state_flags;
262 
263 	/* TXDMA event flags */
264 	uint64_t	tx_event_mask;
265 
266 	/* Transmit threshold before reclamation */
267 	uint32_t	tx_rng_threshold;
268 #define	TX_RING_THRESHOLD		(TX_DEFAULT_MAX_GPS/4)
269 #define	TX_RING_JUMBO_THRESHOLD		(TX_DEFAULT_JUMBO_MAX_GPS/4)
270 
271 	/* For reclaim: a wrap-around counter (packets transmitted) */
272 	uint32_t	tx_pkt_cnt;
273 	/* last packet with the mark bit set */
274 	uint32_t	tx_lastmark;
275 } nxge_tdc_cfg_t, *p_nxge_tdc_cfg_t;
276 
277 #define	RDC_TABLE_ENTRY_METHOD_SEQ	0
278 #define	RDC_TABLE_ENTRY_METHOD_REP	1
279 
280 /* per receive DMA channel table group data structure */
281 typedef struct nxge_rdc_grp {
282 	uint32_t	flag;		/* 0: not configured 1: configured */
283 	uint8_t		port;
284 	uint8_t		start_rdc;	/* assume assigned in sequence	*/
285 	uint8_t		max_rdcs;
286 	uint8_t		def_rdc;
287 	dc_map_t	map;
288 	uint16_t	config_method;
289 } nxge_rdc_grp_t, *p_nxge_rdc_grp_t;
290 
291 #define	RDC_MAP_IN(map, rdc) \
292 	(map |= (1 << rdc))
293 
294 #define	RDC_MAP_OUT(map, rdc) \
295 	(map &= (~(1 << rdc)))
296 
297 /* Common RDC and TDC configuration of DMC */
298 typedef struct _nxge_dma_common_cfg_t {
299 	uint16_t	rdc_red_ran_init; /* RED initial seed value */
300 
301 	/* Transmit Ring */
302 } nxge_dma_common_cfg_t, *p_nxge_dma_common_cfg_t;
303 
304 /*
305  * VLAN and MAC table configurations:
306  *  Each VLAN ID should belong to at most one RDC group.
307  *  Each port could own multiple RDC groups.
308  *  Each MAC should belong to one RDC group.
309  */
310 typedef struct nxge_mv_cfg {
311 	uint8_t		flag;			/* 0:unconfigure 1:configured */
312 	uint8_t		rdctbl;			/* RDC channel table group */
313 	uint8_t		mpr_npr;		/* MAC and VLAN preference */
314 } nxge_mv_cfg_t, *p_nxge_mv_cfg_t;
315 
316 typedef struct nxge_param_map {
317 #if defined(_BIG_ENDIAN)
318 	uint32_t		rsrvd2:2;	/* [30:31] rsrvd */
319 	uint32_t		remove:1;	/* [29] Remove */
320 	uint32_t		pref:1;		/* [28] preference */
321 	uint32_t		rsrv:4;		/* [27:24] preference */
322 	uint32_t		map_to:8;	/* [23:16] map to resource */
323 	uint32_t		param_id:16;	/* [15:0] Param ID */
324 #else
325 	uint32_t		param_id:16;	/* [15:0] Param ID */
326 	uint32_t		map_to:8;	/* [23:16] map to resource */
327 	uint32_t		rsrv:4;		/* [27:24] preference */
328 	uint32_t		pref:1;		/* [28] preference */
329 	uint32_t		remove:1;	/* [29] Remove */
330 	uint32_t		rsrvd2:2;	/* [30:31] rsrvd */
331 #endif
332 } nxge_param_map_t, *p_nxge_param_map_t;
333 
334 typedef struct nxge_rcr_param {
335 #if defined(_BIG_ENDIAN)
336 	uint32_t		rsrvd2:2;	/* [30:31] rsrvd */
337 	uint32_t		remove:1;	/* [29] Remove */
338 	uint32_t		rsrv:5;		/* [28:24] preference */
339 	uint32_t		rdc:8;		/* [23:16] rdc # */
340 	uint32_t		cfg_val:16;	/* [15:0] interrupt parameter */
341 #else
342 	uint32_t		cfg_val:16;	/* [15:0] interrupt parameter */
343 	uint32_t		rdc:8;		/* [23:16] rdc # */
344 	uint32_t		rsrv:5;		/* [28:24] preference */
345 	uint32_t		remove:1;	/* [29] Remove */
346 	uint32_t		rsrvd2:2;	/* [30:31] rsrvd */
347 #endif
348 } nxge_rcr_param_t, *p_nxge_rcr_param_t;
349 
350 /*
351  * These are the properties of the TxDMA channels for this
352  * port (instance).
353  * <start> is the index of the first TDC that is being managed
354  *		by this port.
355  * <count> is the number of TDCs being managed by this port.
356  * <owned> is the number of TDCs currently being utilized by this port.
357  *
358  * <owned> may be less than <count> in hybrid I/O systems.
359  */
360 typedef struct {
361 	int		start;	/* start TDC (0 - 31) */
362 	int		count;	/* 8 - 32 */
363 	int		owned;	/* 1 - count */
364 } tdc_cfg_t;
365 
366 /* Needs to have entries in the ndd table */
367 /*
368  * Hardware properties created by fcode.
369  * In order for those properties visible to the user
370  * command ndd, we need to add the following properties
371  * to the ndd defined parameter array and data structures.
372  *
373  * Use default static configuration for x86.
374  */
375 typedef struct nxge_hw_pt_cfg {
376 	uint32_t	function_number; /* function number		*/
377 	tdc_cfg_t	tdc;
378 	uint32_t	start_rdc;	 /* start RDC (0 - 31)		*/
379 	uint32_t	max_rdcs;	 /* max rdc in sequence		*/
380 	uint32_t	ninterrupts;	/* obp interrupts(mac/mif/syserr) */
381 	uint32_t	mac_ldvid;
382 	uint32_t	mif_ldvid;
383 	uint32_t	ser_ldvid;
384 	uint32_t	def_rdc;	 /* default RDC			*/
385 	uint32_t	drr_wt;		 /* port DRR weight		*/
386 	uint32_t	start_grpid;	 /* starting group ID		*/
387 	uint32_t	max_grpids;	 /* max group ID		*/
388 	uint32_t	grpids[NXGE_MAX_RDCS]; /* RDC group IDs		*/
389 	uint32_t	max_rdc_grpids;	 /* max RDC group ID		*/
390 	uint32_t	start_ldg;	 /* starting logical group # 	*/
391 	uint32_t	max_ldgs;	 /* max logical device group	*/
392 	uint32_t	max_ldvs;	 /* max logical devices		*/
393 	uint32_t	start_mac_entry; /* where to put the first mac	*/
394 	uint32_t	max_macs;	 /* the max mac entry allowed	*/
395 	uint32_t	mac_pref;	 /* preference over VLAN	*/
396 	uint32_t	def_mac_rxdma_grpid; /* default RDC group ID	*/
397 	uint32_t	vlan_pref;	 /* preference over MAC		*/
398 
399 	/* Expand if we have more hardware or default configurations    */
400 	uint16_t	ldg[NXGE_INT_MAX_LDG];
401 	uint16_t	ldg_chn_start;
402 } nxge_hw_pt_cfg_t, *p_nxge_hw_pt_cfg_t;
403 
404 
405 /* per port configuration */
406 typedef struct nxge_dma_pt_cfg {
407 	uint8_t		mac_port;	/* MAC port (function)		*/
408 	nxge_hw_pt_cfg_t hw_config;	/* hardware configuration 	*/
409 
410 	uint32_t alloc_buf_size;
411 	uint32_t rbr_size;
412 	uint32_t rcr_size;
413 
414 	/*
415 	 * Configuration for hardware initialization based on the
416 	 * hardware properties or the default properties.
417 	 */
418 	uint32_t	tx_dma_map;	/* Transmit DMA channel bit map */
419 
420 	/* Receive DMA channel */
421 	nxge_rdc_grp_t	rdc_grps[NXGE_MAX_RDC_GROUPS];
422 
423 	uint16_t	rcr_timeout[NXGE_MAX_RDCS];
424 	uint16_t	rcr_threshold[NXGE_MAX_RDCS];
425 	uint8_t	rcr_full_header;
426 	uint16_t	rx_drr_weight;
427 
428 	/* Add more stuff later */
429 } nxge_dma_pt_cfg_t, *p_nxge_dma_pt_cfg_t;
430 
431 /* classification configuration */
432 typedef struct nxge_class_pt_cfg {
433 
434 	/* MAC table */
435 	nxge_mv_cfg_t	mac_host_info[NXGE_MAX_MACS];
436 
437 	/* VLAN table */
438 	nxge_mv_cfg_t	vlan_tbl[NXGE_MAX_VLANS];
439 	/* class config value */
440 	uint32_t	init_h1;
441 	uint16_t	init_h2;
442 	uint8_t mcast_rdcgrp;
443 	uint8_t mac_rdcgrp;
444 	uint32_t	class_cfg[TCAM_CLASS_MAX];
445 } nxge_class_pt_cfg_t, *p_nxge_class_pt_cfg_t;
446 
447 /* per Neptune sharable resources among ports */
448 typedef struct nxge_common {
449 	uint32_t		partition_id;
450 	boolean_t		mode32;
451 	/* DMA Channels: RDC and TDC */
452 	nxge_rdc_cfg_t		rdc_config[NXGE_MAX_RDCS];
453 	nxge_tdc_cfg_t		tdc_config[NXGE_MAX_TDCS];
454 	nxge_dma_common_cfg_t	dma_common_config;
455 
456 	uint32_t		timer_res;
457 	boolean_t		ld_sys_error_set;
458 	uint8_t			sys_error_owner;
459 
460 	/* Layer 2/3/4 */
461 	uint16_t		class2_etype;
462 	uint16_t		class3_etype;
463 
464 	/* FCRAM (hashing) */
465 	uint32_t		hash1_initval;
466 	uint32_t		hash2_initval;
467 } nxge_common_t, *p_nxge_common_t;
468 
469 /*
470  * Partition (logical domain) configuration per Neptune/NIU.
471  */
472 typedef struct nxge_part_cfg {
473 	uint32_t	rdc_grpbits;	/* RDC group bit masks */
474 	uint32_t	tdc_bitmap;	/* bounded TDC */
475 	nxge_dma_pt_cfg_t pt_config[NXGE_MAX_PORTS];
476 
477 	/* Flow Classification Partition (flow partition select register) */
478 	uint8_t		hash_lookup;	/* external lookup is available */
479 	uint8_t		base_mask;	/* select bits in base_h1 to replace */
480 					/* bits [19:15} in Hash 1. */
481 	uint8_t		base_h1;	/* value to replace Hash 1 [19:15]. */
482 
483 	/* Add more here */
484 	uint32_t	attributes;	/* permission and attribute bits */
485 #define	FZC_SERVICE_ENTITY		0x01
486 #define	FZC_READ_WRITE			0x02
487 #define	FZC_READ_ONLY			0x04
488 } nxge_part_cfg_t, *p_nxge_part_cfg_t;
489 
490 typedef struct nxge_hw_list {
491 	struct nxge_hw_list 	*next;
492 	nxge_os_mutex_t 	nxge_cfg_lock;
493 	nxge_os_mutex_t 	nxge_tcam_lock;
494 	nxge_os_mutex_t 	nxge_vlan_lock;
495 	nxge_os_mutex_t 	nxge_mdio_lock;
496 
497 	nxge_dev_info_t		*parent_devp;
498 	struct _nxge_t		*nxge_p[NXGE_MAX_PORTS];
499 	uint32_t		ndevs;
500 	uint32_t 		flags;
501 	uint32_t 		magic;
502 	uint32_t		niu_type;
503 	uint32_t		platform_type;
504 	uint8_t			xcvr_addr[NXGE_MAX_PORTS];
505 	uintptr_t		hio;
506 } nxge_hw_list_t, *p_nxge_hw_list_t;
507 
508 #ifdef	__cplusplus
509 }
510 #endif
511 
512 #endif	/* _SYS_NXGE_NXGE_COMMON_H */
513