xref: /freebsd/usr.sbin/cxgbetool/tcb_common.h (revision e0c4386e7e71d93b0edc0c8fa156263fc4a8b0b6)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2018 Chelsio Communications, 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  */
29 
30 #ifndef	__tcb_common_h
31 #define	__tcb_common_h
32 
33 /* ANSI C standard includes */
34 #include        <assert.h>
35 #include        <stdlib.h>
36 #include        <string.h>
37 #include        <ctype.h>
38 #include        <stdio.h>
39 #include        <stdarg.h>
40 
41 
42 #ifndef FALSE
43 #define FALSE 0
44 #endif
45 
46 #ifndef EOS
47 #define EOS  '\0'
48 #endif
49 
50 #ifndef __variable_sizes
51 
52 /* windows has _UI64_MAX.  C99 has ULLONG_MAX, but I don't compile
53 with C99 for portability with windows, so the ui64 is a guess.
54 I'll add an assert to cl_main to confirm these sizes are accurate.
55 */
56 #ifdef _UI64_MAX   /* windows */
57 #if   (_UI64_MAX ==  0xFFFFFFFFFFFFFFFF)
58 typedef __int64                      si64;
59 typedef unsigned __int64             ui64;
60 #endif
61 #else  /*else of #ifdef _UI64_MAX */
62 typedef long long int                si64;
63 typedef unsigned long long int       ui64;
64 #endif /*endif of #ifdef _UI64_MAX */
65 #endif /* endif of #ifndef __variable_sizes */
66 
67 
68 
69 
70 typedef struct tcb_var {
71   char *name;
72   int   aux;
73   int   lo;
74   int   hi;
75 
76   char *faka;
77   int  flo;
78   int  fhi;
79 
80   char *aka;
81 
82   int   comp;
83 
84   char *desc;
85   char *akadesc;
86 
87   ui64 rawval;
88   unsigned val;
89 
90 } _TCBVAR;
91 
92 
93 enum comp_types {
94 
95   COMP_NONE=0,
96   COMP_ULP,
97   COMP_TX_MAX,
98   COMP_RCV_NXT,
99   COMP_PTR,
100   COMP_LEN,
101 
102 };
103 
104 
105 enum tidtypes {
106   TIDTYPE_TCB=0,
107   TIDTYPE_SCB=1,
108   TIDTYPE_FCB=2,
109 
110 };
111 
112 
113 enum prntstyls {
114   PRNTSTYL_VERBOSE=0,
115   PRNTSTYL_LIST=1,
116   PRNTSTYL_COMP=2,
117   PRNTSTYL_RAW=3,
118 
119 };
120 
121 
122 /* from tp/src/tp.h */
123 #define PM_MODE_PASS  0
124 #define PM_MODE_DDP   1
125 #define PM_MODE_ISCSI 2
126 #define PM_MODE_IWARP 3
127 #define PM_MODE_RDDP  4
128 #define PM_MODE_IANDP 5
129 #define PM_MODE_FCOE  6
130 #define PM_MODE_USER  7
131 #define PM_MODE_TLS   8
132 #define PM_MODE_DTLS  9
133 
134 
135 
136 #define SEQ_ADD(a,b)    (((a)+(b)) & 0xFFFFFFFF)
137 #define SEQ_SUB(a,b)    (((a)-(b)) & 0xFFFFFFFF)
138 
139 ///* functions needed by the tcbshowtN.c code */
140 extern unsigned val(char *name);
141 extern ui64 val64(char *name);
142 extern void PR(char *fmt, ...);
143 extern char *spr_tcp_state(unsigned state);
144 extern char *spr_ip_version(unsigned ipver);
145 extern char *spr_cctrl_sel(unsigned cctrl_sel0,unsigned cctrl_sel1);
146 extern char *spr_ulp_type(unsigned ulp_type);
147 
148 
149 extern unsigned parse_tcb( _TCBVAR *base_tvp, unsigned char *buf);
150 extern void display_tcb(_TCBVAR *tvp,unsigned char *buf,int aux);
151 extern void parse_n_display_xcb(unsigned char *buf);
152 
153 extern void swizzle_tcb(unsigned char *buf);
154 extern void  set_tidtype(unsigned int tidtype);
155 extern void set_tcb_info(unsigned int tidtype, unsigned int cardtype);
156 extern void set_print_style(unsigned int prntstyl);
157 
158 #endif /* __tcb_common_h */
159