summaryrefslogtreecommitdiffstats
path: root/sys/dev/nxge/include/xge-defs.h
blob: 744a6b98840ba2f56229a794ad4f89236cafed1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*-
 * Copyright (c) 2002-2007 Neterion, Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $FreeBSD$
 */

/*
 *  FileName :    xge-defs.h
 *
 *  Description:  global definitions
 *
 *  Created:      13 May 2004
 */

#ifndef XGE_DEFS_H
#define XGE_DEFS_H

#define XGE_PCI_VENDOR_ID			0x17D5
#define XGE_PCI_DEVICE_ID_XENA_1	0x5731
#define XGE_PCI_DEVICE_ID_XENA_2	0x5831
#define XGE_PCI_DEVICE_ID_HERC_1	0x5732
#define XGE_PCI_DEVICE_ID_HERC_2	0x5832
#define XGE_PCI_DEVICE_ID_TITAN_1	0x5733
#define XGE_PCI_DEVICE_ID_TITAN_2	0x5833

#define XGE_DRIVER_NAME				"Xge driver"
#define XGE_DRIVER_VENDOR			"Neterion, Inc"
#define XGE_CHIP_FAMILY				"Xframe"
#define XGE_SUPPORTED_MEDIA_0		"Fiber"

#include <dev/nxge/include/version.h>

#if defined(__cplusplus)
#define __EXTERN_BEGIN_DECLS	extern "C" {
#define __EXTERN_END_DECLS	}
#else
#define __EXTERN_BEGIN_DECLS
#define __EXTERN_END_DECLS
#endif

__EXTERN_BEGIN_DECLS

/*---------------------------- DMA attributes ------------------------------*/
/*           Used in xge_os_dma_malloc() and xge_os_dma_map() */
/*---------------------------- DMA attributes ------------------------------*/

/* XGE_OS_DMA_REQUIRES_SYNC  - should be defined or
                             NOT defined in the Makefile */
#define XGE_OS_DMA_CACHELINE_ALIGNED      0x1
/* Either STREAMING or CONSISTENT should be used.
   The combination of both or none is invalid */
#define XGE_OS_DMA_STREAMING              0x2
#define XGE_OS_DMA_CONSISTENT             0x4
#define XGE_OS_SPRINTF_STRLEN             64

/*---------------------------- common stuffs -------------------------------*/

#define XGE_OS_LLXFMT		"%llx"
#define XGE_OS_NEWLINE      "\n"
#ifdef XGE_OS_MEMORY_CHECK
typedef struct {
	void *ptr;
	int size;
	char *file;
	int line;
} xge_os_malloc_t;

#define XGE_OS_MALLOC_CNT_MAX	64*1024
extern xge_os_malloc_t g_malloc_arr[XGE_OS_MALLOC_CNT_MAX];
extern int g_malloc_cnt;

#define XGE_OS_MEMORY_CHECK_MALLOC(_vaddr, _size, _file, _line) { \
	if (_vaddr) { \
		int i; \
		for (i=0; i<g_malloc_cnt; i++) { \
			if (g_malloc_arr[i].ptr == NULL) { \
				break; \
			} \
		} \
		if (i == g_malloc_cnt) { \
			g_malloc_cnt++; \
			if (g_malloc_cnt >= XGE_OS_MALLOC_CNT_MAX) { \
			  xge_os_bug("g_malloc_cnt exceed %d", \
						XGE_OS_MALLOC_CNT_MAX); \
			} \
		} \
		g_malloc_arr[i].ptr = _vaddr; \
		g_malloc_arr[i].size = _size; \
		g_malloc_arr[i].file = _file; \
		g_malloc_arr[i].line = _line; \
		for (i=0; i<_size; i++) { \
			*((char *)_vaddr+i) = 0x5a; \
		} \
	} \
}

#define XGE_OS_MEMORY_CHECK_FREE(_vaddr, _check_size) { \
	int i; \
	for (i=0; i<XGE_OS_MALLOC_CNT_MAX; i++) { \
		if (g_malloc_arr[i].ptr == _vaddr) { \
			g_malloc_arr[i].ptr = NULL; \
			if(_check_size && g_malloc_arr[i].size!=_check_size) { \
				xge_os_printf("OSPAL: freeing with wrong " \
				      "size %d! allocated at %s:%d:"XGE_OS_LLXFMT":%d", \
					 (int)_check_size, \
					 g_malloc_arr[i].file, \
					 g_malloc_arr[i].line, \
					 (unsigned long long)(ulong_t) \
					    g_malloc_arr[i].ptr, \
					 g_malloc_arr[i].size); \
			} \
			break; \
		} \
	} \
	if (i == XGE_OS_MALLOC_CNT_MAX) { \
		xge_os_printf("OSPAL: ptr "XGE_OS_LLXFMT" not found!", \
			    (unsigned long long)(ulong_t)_vaddr); \
	} \
}
#else
#define XGE_OS_MEMORY_CHECK_MALLOC(ptr, size, file, line)
#define XGE_OS_MEMORY_CHECK_FREE(vaddr, check_size)
#endif

__EXTERN_END_DECLS

#endif /* XGE_DEFS_H */
OpenPOWER on IntegriCloud