xref: /illumos-gate/usr/src/uts/common/io/xge/hal/include/xge-defs.h (revision a07094369b21309434206d9b3601d162693466fc)
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 /*
23  *  Copyright (c) 2002-2005 Neterion, Inc.
24  *  All right Reserved.
25  *
26  *  FileName :    xge-defs.h
27  *
28  *  Description:  global definitions
29  *
30  *  Created:      13 May 2004
31  */
32 
33 #ifndef XGE_DEFS_H
34 #define XGE_DEFS_H
35 
36 #define XGE_PCI_VENDOR_ID		0x17D5
37 #define XGE_PCI_DEVICE_ID_XENA_1	0x5731
38 #define XGE_PCI_DEVICE_ID_XENA_2	0x5831
39 #define XGE_PCI_DEVICE_ID_HERC_1	0x5732
40 #define XGE_PCI_DEVICE_ID_HERC_2	0x5832
41 
42 #define XGE_DRIVER_NAME		"Xge driver"
43 #define XGE_DRIVER_VENDOR	"Neterion, Inc"
44 #define XGE_CHIP_FAMILY		"Xframe"
45 #define XGE_SUPPORTED_MEDIA_0	"Fiber"
46 
47 #include "version.h"
48 
49 /*---------------------------- DMA attributes ------------------------------*/
50 /*           Used in xge_os_dma_malloc() and xge_os_dma_map() */
51 /*---------------------------- DMA attributes ------------------------------*/
52 
53 /* XGE_OS_DMA_REQUIRES_SYNC  - should be defined or
54                              NOT defined in the Makefile */
55 #define XGE_OS_DMA_CACHELINE_ALIGNED      0x1
56 /* Either STREAMING or CONSISTENT should be used.
57    The combination of both or none is invalid */
58 #define XGE_OS_DMA_STREAMING              0x2
59 #define XGE_OS_DMA_CONSISTENT             0x4
60 #define XGE_OS_SPRINTF_STRLEN             64
61 
62 /*---------------------------- common stuffs -------------------------------*/
63 
64 #ifdef XGE_OS_MEMORY_CHECK
65 typedef struct {
66 	void *ptr;
67 	int size;
68 	char *file;
69 	int line;
70 } xge_os_malloc_t;
71 
72 #define XGE_OS_MALLOC_CNT_MAX	64*1024
73 extern xge_os_malloc_t g_malloc_arr[XGE_OS_MALLOC_CNT_MAX];
74 extern int g_malloc_cnt;
75 
76 #define XGE_OS_MEMORY_CHECK_MALLOC(_vaddr, _size, _file, _line) { \
77 	if (_vaddr) { \
78 		int i; \
79 		for (i=0; i<g_malloc_cnt; i++) { \
80 			if (g_malloc_arr[i].ptr == NULL) { \
81 				break; \
82 			} \
83 		} \
84 		if (i == g_malloc_cnt) { \
85 			g_malloc_cnt++; \
86 			if (g_malloc_cnt >= XGE_OS_MALLOC_CNT_MAX) { \
87 			  xge_os_bug("g_malloc_cnt exceed %d", \
88 						XGE_OS_MALLOC_CNT_MAX); \
89 			} \
90 		} \
91 		g_malloc_arr[i].ptr = _vaddr; \
92 		g_malloc_arr[i].size = _size; \
93 		g_malloc_arr[i].file = _file; \
94 		g_malloc_arr[i].line = _line; \
95 		for (i=0; i<_size; i++) { \
96 			*((char *)_vaddr+i) = 0x5a; \
97 		} \
98 	} \
99 }
100 
101 #define XGE_OS_MEMORY_CHECK_FREE(_vaddr, _check_size) { \
102 	int i; \
103 	for (i=0; i<XGE_OS_MALLOC_CNT_MAX; i++) { \
104 		if (g_malloc_arr[i].ptr == _vaddr) { \
105 			g_malloc_arr[i].ptr = NULL; \
106 			if(_check_size && g_malloc_arr[i].size!=_check_size) { \
107 				xge_os_printf("OSPAL: freeing with wrong " \
108 				      "size %d! allocated at %s:%d:%llx:%d", \
109 					 (int)_check_size, \
110 					 g_malloc_arr[i].file, \
111 					 g_malloc_arr[i].line, \
112 					 (unsigned long long)(ulong_t) \
113 					    g_malloc_arr[i].ptr, \
114 					 g_malloc_arr[i].size); \
115 			} \
116 			break; \
117 		} \
118 	} \
119 	if (i == XGE_OS_MALLOC_CNT_MAX) { \
120 		xge_os_printf("OSPAL: ptr %llx not found!", \
121 			    (unsigned long long)(ulong_t)_vaddr); \
122 	} \
123 }
124 #else
125 #define XGE_OS_MEMORY_CHECK_MALLOC(ptr, size, file, line)
126 #define XGE_OS_MEMORY_CHECK_FREE(vaddr, check_size)
127 #endif
128 
129 #endif /* XGE_DEFS_H */
130