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