xge-os-pal.h revision 171095
1/*- 2 * Copyright (c) 2002-2007 Neterion, Inc. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 * $FreeBSD: head/sys/dev/nxge/include/xge-os-pal.h 171095 2007-06-29 22:47:18Z sam $ 27 */ 28 29/* 30 * FileName : xge-os-pal.h 31 * 32 * Description: top-level header file. works just like switching between 33 * os-depndent parts 34 * 35 * Created: 6st May 2004 36 */ 37 38#ifndef XGE_OS_PAL_H 39#define XGE_OS_PAL_H 40 41#include <dev/nxge/include/xge-defs.h> 42 43__EXTERN_BEGIN_DECLS 44 45/*--------------------------- platform switch ------------------------------*/ 46 47/* platform specific header */ 48#include <dev/nxge/xge-osdep.h> 49#ifdef XGEHAL_RNIC 50#define IN 51#define OUT 52#endif 53 54#if !defined(XGE_OS_PLATFORM_64BIT) && !defined(XGE_OS_PLATFORM_32BIT) 55#error "either 32bit or 64bit switch must be defined!" 56#endif 57 58#if !defined(XGE_OS_HOST_BIG_ENDIAN) && !defined(XGE_OS_HOST_LITTLE_ENDIAN) 59#error "either little endian or big endian switch must be defined!" 60#endif 61 62#if defined(XGE_OS_PLATFORM_64BIT) 63#define XGE_OS_MEMORY_DEADCODE_PAT 0x5a5a5a5a5a5a5a5a 64#else 65#define XGE_OS_MEMORY_DEADCODE_PAT 0x5a5a5a5a 66#endif 67 68#define XGE_OS_TRACE_MSGBUF_MAX 512 69typedef struct xge_os_tracebuf_t { 70 int wrapped_once; /* circular buffer been wrapped */ 71 int timestamp; /* whether timestamps are enabled */ 72 volatile int offset; /* offset within the tracebuf */ 73 int size; /* total size of trace buffer */ 74 char msg[XGE_OS_TRACE_MSGBUF_MAX]; /* each individual buffer */ 75 int msgbuf_max; /* actual size of msg buffer */ 76 char *data; /* pointer to data buffer */ 77} xge_os_tracebuf_t; 78extern xge_os_tracebuf_t *g_xge_os_tracebuf; 79 80#ifdef XGE_TRACE_INTO_CIRCULAR_ARR 81extern xge_os_tracebuf_t *g_xge_os_tracebuf; 82extern char *dmesg_start; 83 84/* Calculate the size of the msg and copy it into the global buffer */ 85#define __xge_trace(tb) { \ 86 int msgsize = xge_os_strlen(tb->msg) + 2; \ 87 int offset = tb->offset; \ 88 if (msgsize != 2 && msgsize < tb->msgbuf_max) { \ 89 int leftsize = tb->size - offset; \ 90 if ((msgsize + tb->msgbuf_max) > leftsize) { \ 91 xge_os_memzero(tb->data + offset, leftsize); \ 92 offset = 0; \ 93 tb->wrapped_once = 1; \ 94 } \ 95 xge_os_memcpy(tb->data + offset, tb->msg, msgsize-1); \ 96 *(tb->data + offset + msgsize-1) = '\n'; \ 97 *(tb->data + offset + msgsize) = 0; \ 98 offset += msgsize; \ 99 tb->offset = offset; \ 100 dmesg_start = tb->data + offset; \ 101 *tb->msg = 0; \ 102 } \ 103} 104 105#define xge_os_vatrace(tb, fmt) { \ 106 if (tb != NULL) { \ 107 char *_p = tb->msg; \ 108 if (tb->timestamp) { \ 109 xge_os_timestamp(tb->msg); \ 110 _p = tb->msg + xge_os_strlen(tb->msg); \ 111 } \ 112 xge_os_vasprintf(_p, fmt); \ 113 __xge_trace(tb); \ 114 } \ 115} 116 117#ifdef __GNUC__ 118#define xge_os_trace(tb, fmt...) { \ 119 if (tb != NULL) { \ 120 if (tb->timestamp) { \ 121 xge_os_timestamp(tb->msg); \ 122 } \ 123 xge_os_sprintf(tb->msg + xge_os_strlen(tb->msg), fmt); \ 124 __xge_trace(tb); \ 125 } \ 126} 127#endif /* __GNUC__ */ 128 129#else 130#define xge_os_vatrace(tb, fmt) 131#ifdef __GNUC__ 132#define xge_os_trace(tb, fmt...) 133#endif /* __GNUC__ */ 134#endif 135 136__EXTERN_END_DECLS 137 138#endif /* XGE_OS_PAL_H */ 139