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