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