xge-defs.h revision 330897
111894Speter/*-
211894Speter * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
39Sjkh *
49Sjkh * Copyright (c) 2002-2007 Neterion, Inc.
511894Speter * All rights reserved.
69Sjkh *
79Sjkh * Redistribution and use in source and binary forms, with or without
89Sjkh * modification, are permitted provided that the following conditions
99Sjkh * are met:
1011894Speter * 1. Redistributions of source code must retain the above copyright
1111894Speter *    notice, this list of conditions and the following disclaimer.
129Sjkh * 2. Redistributions in binary form must reproduce the above copyright
139Sjkh *    notice, this list of conditions and the following disclaimer in the
149Sjkh *    documentation and/or other materials provided with the distribution.
159Sjkh *
169Sjkh * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
179Sjkh * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
189Sjkh * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
199Sjkh * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
209Sjkh * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
219Sjkh * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
229Sjkh * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
239Sjkh * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
249Sjkh * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
259Sjkh * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
269Sjkh * SUCH DAMAGE.
2711894Speter *
2811894Speter * $FreeBSD: stable/11/sys/dev/nxge/include/xge-defs.h 330897 2018-03-14 03:19:51Z eadler $
2911894Speter */
309Sjkh
319Sjkh#ifndef XGE_DEFS_H
329Sjkh#define XGE_DEFS_H
339Sjkh
349Sjkh#define XGE_PCI_VENDOR_ID           0x17D5
359Sjkh#define XGE_PCI_DEVICE_ID_XENA_1    0x5731
369Sjkh#define XGE_PCI_DEVICE_ID_XENA_2    0x5831
379Sjkh#define XGE_PCI_DEVICE_ID_HERC_1    0x5732
389Sjkh#define XGE_PCI_DEVICE_ID_HERC_2    0x5832
399Sjkh#define XGE_PCI_DEVICE_ID_TITAN_1   0x5733
4011894Speter#define XGE_PCI_DEVICE_ID_TITAN_2   0x5833
4111894Speter
4211894Speter#define XGE_DRIVER_NAME             "Xge driver"
4311894Speter#define XGE_DRIVER_VENDOR           "Neterion, Inc"
448858Srgrimes#define XGE_CHIP_FAMILY             "Xframe"
4511894Speter#define XGE_SUPPORTED_MEDIA_0       "Fiber"
4611894Speter
4711894Speter#include <dev/nxge/include/version.h>
4811894Speter
4911894Speter#if defined(__cplusplus)
5011894Speter#define __EXTERN_BEGIN_DECLS    extern "C" {
5111894Speter#define __EXTERN_END_DECLS  }
5211894Speter#else
5311894Speter#define __EXTERN_BEGIN_DECLS
5411894Speter#define __EXTERN_END_DECLS
5511894Speter#endif
5611894Speter
5711894Speter__EXTERN_BEGIN_DECLS
5811894Speter
5911894Speter/*---------------------------- DMA attributes ------------------------------*/
6011894Speter/*           Used in xge_os_dma_malloc() and xge_os_dma_map() */
6111894Speter/*---------------------------- DMA attributes ------------------------------*/
6211894Speter
6311894Speter/* XGE_OS_DMA_REQUIRES_SYNC  - should be defined or
6411894Speter	                         NOT defined in the Makefile */
6511894Speter#define XGE_OS_DMA_CACHELINE_ALIGNED      0x1
6611894Speter/* Either STREAMING or CONSISTENT should be used.
6711894Speter   The combination of both or none is invalid */
6811894Speter#define XGE_OS_DMA_STREAMING              0x2
6911894Speter#define XGE_OS_DMA_CONSISTENT             0x4
7011894Speter#define XGE_OS_SPRINTF_STRLEN             64
7111894Speter
7211894Speter/*---------------------------- common stuffs -------------------------------*/
7311894Speter
7411894Speter#define XGE_OS_LLXFMT       "%llx"
7511894Speter#define XGE_OS_NEWLINE      "\n"
7611894Speter#ifdef XGE_OS_MEMORY_CHECK
7711894Spetertypedef struct {
7811894Speter	void *ptr;
799Sjkh	int size;
809Sjkh	char *file;
819Sjkh	int line;
829Sjkh} xge_os_malloc_t;
839Sjkh
849Sjkh#define XGE_OS_MALLOC_CNT_MAX   64*1024
859Sjkhextern xge_os_malloc_t g_malloc_arr[XGE_OS_MALLOC_CNT_MAX];
869Sjkhextern int g_malloc_cnt;
879Sjkh
889Sjkh#define XGE_OS_MEMORY_CHECK_MALLOC(_vaddr, _size, _file, _line) { \
899Sjkh	if (_vaddr) { \
909Sjkh	    int index_mem_chk; \
919Sjkh	    for (index_mem_chk=0; index_mem_chk < g_malloc_cnt; index_mem_chk++) { \
929Sjkh	        if (g_malloc_arr[index_mem_chk].ptr == NULL) { \
939Sjkh	            break; \
949Sjkh	        } \
959Sjkh	    } \
969Sjkh	    if (index_mem_chk == g_malloc_cnt) { \
979Sjkh	        g_malloc_cnt++; \
989Sjkh	        if (g_malloc_cnt >= XGE_OS_MALLOC_CNT_MAX) { \
999Sjkh	          xge_os_bug("g_malloc_cnt exceed %d", \
1009Sjkh	                    XGE_OS_MALLOC_CNT_MAX); \
1019Sjkh	        } \
1029Sjkh	    } \
1039Sjkh	    g_malloc_arr[index_mem_chk].ptr = _vaddr; \
1049Sjkh	    g_malloc_arr[index_mem_chk].size = _size; \
1059Sjkh	    g_malloc_arr[index_mem_chk].file = _file; \
1069Sjkh	    g_malloc_arr[index_mem_chk].line = _line; \
10711894Speter	    for (index_mem_chk=0; index_mem_chk<_size; index_mem_chk++) { \
10811894Speter	        *((char *)_vaddr+index_mem_chk) = 0x5a; \
1099Sjkh	    } \
1109Sjkh	} \
1119Sjkh}
1129Sjkh
1139Sjkh#define XGE_OS_MEMORY_CHECK_FREE(_vaddr, _check_size) { \
1149Sjkh	int index_mem_chk; \
1159Sjkh	for (index_mem_chk=0; index_mem_chk < XGE_OS_MALLOC_CNT_MAX; index_mem_chk++) { \
1168858Srgrimes	    if (g_malloc_arr[index_mem_chk].ptr == _vaddr) { \
1179Sjkh	        g_malloc_arr[index_mem_chk].ptr = NULL; \
1189Sjkh	        if(_check_size && g_malloc_arr[index_mem_chk].size!=_check_size) { \
1198858Srgrimes	            xge_os_printf("OSPAL: freeing with wrong " \
1209Sjkh	                  "size %d! allocated at %s:%d:"XGE_OS_LLXFMT":%d", \
1219Sjkh	                 (int)_check_size, \
1229Sjkh	                 g_malloc_arr[index_mem_chk].file, \
1238858Srgrimes	                 g_malloc_arr[index_mem_chk].line, \
1249Sjkh	                 (unsigned long long)(ulong_t) \
1259Sjkh	                    g_malloc_arr[index_mem_chk].ptr, \
1269Sjkh	                 g_malloc_arr[index_mem_chk].size); \
1278858Srgrimes	        } \
1289Sjkh	        break; \
1299Sjkh	    } \
1308858Srgrimes	} \
1319Sjkh	if (index_mem_chk == XGE_OS_MALLOC_CNT_MAX) { \
1329Sjkh	    xge_os_printf("OSPAL: ptr "XGE_OS_LLXFMT" not found!", \
1338858Srgrimes	            (unsigned long long)(ulong_t)_vaddr); \
1349Sjkh	} \
13511894Speter}
1368858Srgrimes#else
1379Sjkh#define XGE_OS_MEMORY_CHECK_MALLOC(ptr, size, file, line)
13811894Speter#define XGE_OS_MEMORY_CHECK_FREE(vaddr, check_size)
1398858Srgrimes#endif
1409Sjkh
1419Sjkh__EXTERN_END_DECLS
1429Sjkh
1439Sjkh#endif /* XGE_DEFS_H */
1449Sjkh