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