xref: /src/sys/dev/aq/aq_dbg.c (revision 668423f75b4d9006f16847b415c861defb8267d7)
1 /**
2  * aQuantia Corporation Network Driver
3  * Copyright (C) 2014-2017 aQuantia Corporation. 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  *
9  *   (1) Redistributions of source code must retain the above
10  *   copyright notice, this list of conditions and the following
11  *   disclaimer.
12  *
13  *   (2) Redistributions in binary form must reproduce the above
14  *   copyright notice, this list of conditions and the following
15  *   disclaimer in the documentation and/or other materials provided
16  *   with the distribution.
17  *
18  *   (3) The name of the author may not be used to endorse or promote
19  *   products derived from this software without specific prior
20  *   written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
23  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
26  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
28  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  *
34  * @file aq_dbg.c
35  * Debugging stuff.
36  * @date 2017.12.13  @author roman.agafonov@aquantia.com
37  */
38 
39 
40 #include <sys/cdefs.h>
41 __FBSDID("$FreeBSD$");
42 
43 #include <sys/param.h>
44 #include "aq_common.h"
45 #include "aq_dbg.h"
46 
47 
48 const aq_debug_level dbg_level_ = lvl_detail;
49 const uint32_t dbg_categories_ = dbg_init | dbg_config | dbg_fw;
50 
51 
52 
53 #define DESCR_FIELD(DESCR, BIT_BEGIN, BIT_END) \
54 	((DESCR >> BIT_END) &\
55 		(BIT(BIT_BEGIN - BIT_END + 1) -1))
56 
57 #define __field(TYPE, VAR) TYPE VAR;
58 void
trace_aq_tx_descr(int ring_idx,unsigned int pointer,volatile uint64_t descr[2])59 trace_aq_tx_descr(int ring_idx, unsigned int pointer,
60     volatile uint64_t descr[2])
61 {
62 #if AQ_CFG_DEBUG_LVL > 2
63 	struct __entry{
64 		__field(unsigned int, ring_idx)
65 		__field(unsigned int, pointer)
66 		/* Tx Descriptor */
67 		__field(uint64_t, data_buf_addr)
68 		__field(uint32_t, pay_len)
69 		__field(uint8_t, ct_en)
70 		__field(uint8_t, ct_idx)
71 		__field(uint16_t, rsvd2)
72 		__field(uint8_t, tx_cmd)
73 		__field(uint8_t, eop)
74 		__field(uint8_t, dd)
75 		__field(uint16_t, buf_len)
76 		__field(uint8_t, rsvd1)
77 		__field(uint8_t, des_typ)
78 	} entry;
79 
80 	entry.ring_idx = ring_idx;
81 	entry.pointer = pointer;
82 	entry.data_buf_addr = descr[0];
83 	entry.pay_len = DESCR_FIELD(descr[1], 63, 46);
84 	entry.ct_en =  DESCR_FIELD(descr[1], 45, 45);
85 	entry.ct_idx = DESCR_FIELD(descr[1], 44, 44);
86 	entry.rsvd2 = DESCR_FIELD(descr[1], 43, 30);
87 	entry.tx_cmd = DESCR_FIELD(descr[1], 29, 22);
88 	entry.eop = DESCR_FIELD(descr[1], 21, 21);
89 	entry.dd = DESCR_FIELD(descr[1], 20, 20);
90 	entry.buf_len = DESCR_FIELD(descr[1], 19, 4);
91 	entry.rsvd1 = DESCR_FIELD(descr[1], 3, 3);
92 	entry.des_typ = DESCR_FIELD(descr[1], 2, 0);
93 
94 
95 	aq_log_detail("trace_aq_tx_descr ring=%d descr=%u pay_len=%u ct_en=%u ct_idx=%u rsvd2=0x%x tx_cmd=0x%x eop=%u dd=%u buf_len=%u rsvd1=%u des_typ=0x%x",
96 		  entry.ring_idx, entry.pointer, entry.pay_len,
97 		  entry.ct_en, entry.ct_idx, entry.rsvd2,
98 		  entry.tx_cmd, entry.eop, entry.dd, entry.buf_len,
99 		  entry.rsvd1, entry.des_typ);
100 #endif
101 }
102 
103 void
trace_aq_rx_descr(int ring_idx,unsigned int pointer,volatile uint64_t descr[2])104 trace_aq_rx_descr(int ring_idx, unsigned int pointer, volatile uint64_t descr[2])
105 {
106 #if AQ_CFG_DEBUG_LVL > 2
107 	uint8_t dd;
108 	uint8_t eop;
109 	uint8_t rx_stat;
110 	uint8_t rx_estat;
111 	uint8_t rsc_cnt;
112 	uint16_t pkt_len;
113 	uint16_t next_desp;
114 	uint16_t vlan_tag;
115 
116 	uint8_t rss_type;
117 	uint8_t pkt_type;
118 	uint8_t rdm_err;
119 	uint8_t avb_ts;
120 	uint8_t rsvd;
121 	uint8_t rx_cntl;
122 	uint8_t sph;
123 	uint16_t hdr_len;
124 	uint32_t rss_hash;
125 
126 	rss_hash = DESCR_FIELD(descr[0], 63, 32);
127 	hdr_len =  DESCR_FIELD(descr[0], 31, 22);
128 	sph = DESCR_FIELD(descr[0], 21, 21);
129 	rx_cntl = DESCR_FIELD(descr[0], 20, 19);
130 	rsvd = DESCR_FIELD(descr[0], 18, 14);
131 	avb_ts = DESCR_FIELD(descr[0], 13, 13);
132 	rdm_err = DESCR_FIELD(descr[0], 12, 12);
133 	pkt_type = DESCR_FIELD(descr[0], 11, 4);
134 	rss_type = DESCR_FIELD(descr[0], 3, 0);
135 
136 	vlan_tag = DESCR_FIELD(descr[1], 63, 48);
137 	next_desp = DESCR_FIELD(descr[1], 47, 32);
138 	pkt_len = DESCR_FIELD(descr[1], 31, 16);
139 	rsc_cnt = DESCR_FIELD(descr[1], 15, 12);
140 	rx_estat = DESCR_FIELD(descr[1], 11, 6);
141 	rx_stat = DESCR_FIELD(descr[1], 5, 2);
142 	eop = DESCR_FIELD(descr[1], 1, 1);
143 	dd = DESCR_FIELD(descr[1], 0, 0);
144 
145 	printf("trace_aq_rx_descr ring=%d descr=%u rss_hash=0x%x hdr_len=%u sph=%u rx_cntl=%u rsvd=0x%x avb_ts=%u rdm_err=%u pkt_type=%u rss_type=%u vlan_tag=%u next_desp=%u pkt_len=%u rsc_cnt=%u rx_estat=0x%x rx_stat=0x%x eop=%u dd=%u\n",
146 		  ring_idx, pointer, rss_hash,
147 		  hdr_len, sph, rx_cntl,
148 		  rsvd, avb_ts, rdm_err,
149 		  pkt_type, rss_type, vlan_tag,
150 		  next_desp, pkt_len, rsc_cnt,
151 		  rx_estat, rx_stat, eop, dd);
152 #endif
153 }
154 
155 void
trace_aq_tx_context_descr(int ring_idx,unsigned int pointer,volatile uint64_t descr[2])156 trace_aq_tx_context_descr(int ring_idx, unsigned int pointer,
157     volatile uint64_t descr[2])
158 {
159 #if AQ_CFG_DEBUG_LVL > 2
160 	struct __entry_s{
161 		__field(unsigned int, ring_idx)
162 		__field(unsigned int, pointer)
163 		/* Tx Context Descriptor */
164 		__field(uint16_t, out_len)
165 		__field(uint8_t, tun_len)
166 		__field(uint64_t, resvd3)
167 		__field(uint16_t, mss_len)
168 		__field(uint8_t, l4_len)
169 		__field(uint8_t, l3_len)
170 		__field(uint8_t, l2_len)
171 		__field(uint8_t, ct_cmd)
172 		__field(uint16_t, vlan_tag)
173 		__field(uint8_t, ct_idx)
174 		__field(uint8_t, des_typ)
175 	} entry;
176 	struct __entry_s *__entry = &entry;
177 	__entry->ring_idx = ring_idx;
178 	__entry->pointer = pointer;
179 	__entry->out_len = DESCR_FIELD(descr[0], 63, 48);
180 	__entry->tun_len = DESCR_FIELD(descr[0], 47, 40);
181 	__entry->resvd3 = DESCR_FIELD(descr[0], 39, 0);
182 	__entry->mss_len = DESCR_FIELD(descr[1], 63, 48);
183 	__entry->l4_len = DESCR_FIELD(descr[1], 47, 40);
184 	__entry->l3_len = DESCR_FIELD(descr[1], 39, 31);
185 	__entry->l2_len = DESCR_FIELD(descr[1], 30, 24);
186 	__entry->ct_cmd = DESCR_FIELD(descr[1], 23, 20);
187 	__entry->vlan_tag = DESCR_FIELD(descr[1], 19, 4);
188 	__entry->ct_idx = DESCR_FIELD(descr[1], 3, 3);
189 	__entry->des_typ = DESCR_FIELD(descr[1], 2, 0);
190 
191 	printf("trace_aq_tx_context_descr ring=%d descr=%u out_len=%u tun_len=%u resvd3=%lu mss_len=%u l4_len=%u l3_len=%u l2_len=%d ct_cmd=%u vlan_tag=%u ct_idx=%u des_typ=0x%x\n",
192 		  __entry->ring_idx, __entry->pointer, __entry->out_len,
193 		  __entry->tun_len, __entry->resvd3, __entry->mss_len,
194 		  __entry->l4_len, __entry->l3_len, __entry->l2_len,
195 		  __entry->ct_cmd, __entry->vlan_tag, __entry->ct_idx,
196 		  __entry->des_typ);
197 #endif
198 }
199 
200 void
DumpHex(const void * data,size_t size)201 DumpHex(const void* data, size_t size) {
202 #if AQ_CFG_DEBUG_LVL > 3
203 	char ascii[17];
204 	size_t i, j;
205 	char line[256];
206 	char buf[256];
207 
208 	ascii[16] = '\0';
209 	line[0] = '\0';
210 	printf("packet at %p\n", data);
211 
212 	for (i = 0; i < size; ++i) {
213 		sprintf(buf, "%02X ", ((const unsigned char*)data)[i]);
214 		strcat(line, buf);
215 		if (((const unsigned char*)data)[i] >= ' ' &&
216 		    ((const unsigned char*)data)[i] <= '~') {
217 			ascii[i % 16] = ((const unsigned char*)data)[i];
218 		} else {
219 			ascii[i % 16] = '.';
220 		}
221 		if ((i+1) % 8 == 0 || i+1 == size) {
222 			strcat(line, " ");
223 			if ((i+1) % 16 == 0) {
224 				sprintf(buf, "|  %s \n", ascii);
225 				strcat(line, buf);
226 				printf("%s", line);
227 				line[0] = '\0';
228 			} else if (i+1 == size) {
229 				ascii[(i+1) % 16] = '\0';
230 				if ((i+1) % 16 <= 8) {
231 					strcat(line, " ");
232 				}
233 				for (j = (i+1) % 16; j < 16; ++j) {
234 					strcat(line, "   ");
235 				}
236 				sprintf(buf, "|  %s \n", ascii);
237 				strcat(line, buf);
238 				printf("%s", line);
239 				line[0] = '\0';
240 			}
241 		}
242 	}
243 #endif
244 }
245