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 u32 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;
trace_aq_tx_descr(int ring_idx,unsigned int pointer,volatile u64 descr[2])58 void trace_aq_tx_descr(int ring_idx, unsigned int pointer, volatile u64 descr[2])
59 {
60 #if AQ_CFG_DEBUG_LVL > 2
61 struct __entry{
62 __field(unsigned int, ring_idx)
63 __field(unsigned int, pointer)
64 /* Tx Descriptor */
65 __field(u64, data_buf_addr)
66 __field(u32, pay_len)
67 __field(u8, ct_en)
68 __field(u8, ct_idx)
69 __field(u16, rsvd2)
70 __field(u8, tx_cmd)
71 __field(u8, eop)
72 __field(u8, dd)
73 __field(u16, buf_len)
74 __field(u8, rsvd1)
75 __field(u8, des_typ)
76 } entry;
77
78 entry.ring_idx = ring_idx;
79 entry.pointer = pointer;
80 entry.data_buf_addr = descr[0];
81 entry.pay_len = DESCR_FIELD(descr[1], 63, 46);
82 entry.ct_en = DESCR_FIELD(descr[1], 45, 45);
83 entry.ct_idx = DESCR_FIELD(descr[1], 44, 44);
84 entry.rsvd2 = DESCR_FIELD(descr[1], 43, 30);
85 entry.tx_cmd = DESCR_FIELD(descr[1], 29, 22);
86 entry.eop = DESCR_FIELD(descr[1], 21, 21);
87 entry.dd = DESCR_FIELD(descr[1], 20, 20);
88 entry.buf_len = DESCR_FIELD(descr[1], 19, 4);
89 entry.rsvd1 = DESCR_FIELD(descr[1], 3, 3);
90 entry.des_typ = DESCR_FIELD(descr[1], 2, 0);
91
92
93 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",
94 entry.ring_idx, entry.pointer, entry.pay_len,
95 entry.ct_en, entry.ct_idx, entry.rsvd2,
96 entry.tx_cmd, entry.eop, entry.dd, entry.buf_len,
97 entry.rsvd1, entry.des_typ);
98 #endif
99 }
100
trace_aq_rx_descr(int ring_idx,unsigned int pointer,volatile u64 descr[2])101 void trace_aq_rx_descr(int ring_idx, unsigned int pointer, volatile u64 descr[2])
102 {
103 #if AQ_CFG_DEBUG_LVL > 2
104 u8 dd;
105 u8 eop;
106 u8 rx_stat;
107 u8 rx_estat;
108 u8 rsc_cnt;
109 u16 pkt_len;
110 u16 next_desp;
111 u16 vlan_tag;
112
113 u8 rss_type;
114 u8 pkt_type;
115 u8 rdm_err;
116 u8 avb_ts;
117 u8 rsvd;
118 u8 rx_cntl;
119 u8 sph;
120 u16 hdr_len;
121 u32 rss_hash;
122
123 rss_hash = DESCR_FIELD(descr[0], 63, 32);
124 hdr_len = DESCR_FIELD(descr[0], 31, 22);
125 sph = DESCR_FIELD(descr[0], 21, 21);
126 rx_cntl = DESCR_FIELD(descr[0], 20, 19);
127 rsvd = DESCR_FIELD(descr[0], 18, 14);
128 avb_ts = DESCR_FIELD(descr[0], 13, 13);
129 rdm_err = DESCR_FIELD(descr[0], 12, 12);
130 pkt_type = DESCR_FIELD(descr[0], 11, 4);
131 rss_type = DESCR_FIELD(descr[0], 3, 0);
132
133 vlan_tag = DESCR_FIELD(descr[1], 63, 48);
134 next_desp = DESCR_FIELD(descr[1], 47, 32);
135 pkt_len = DESCR_FIELD(descr[1], 31, 16);
136 rsc_cnt = DESCR_FIELD(descr[1], 15, 12);
137 rx_estat = DESCR_FIELD(descr[1], 11, 6);
138 rx_stat = DESCR_FIELD(descr[1], 5, 2);
139 eop = DESCR_FIELD(descr[1], 1, 1);
140 dd = DESCR_FIELD(descr[1], 0, 0);
141
142 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",
143 ring_idx, pointer, rss_hash,
144 hdr_len, sph, rx_cntl,
145 rsvd, avb_ts, rdm_err,
146 pkt_type, rss_type, vlan_tag,
147 next_desp, pkt_len, rsc_cnt,
148 rx_estat, rx_stat, eop, dd);
149 #endif
150 }
151
trace_aq_tx_context_descr(int ring_idx,unsigned int pointer,volatile u64 descr[2])152 void trace_aq_tx_context_descr(int ring_idx, unsigned int pointer, volatile u64 descr[2])
153 {
154 #if AQ_CFG_DEBUG_LVL > 2
155 struct __entry_s{
156 __field(unsigned int, ring_idx)
157 __field(unsigned int, pointer)
158 /* Tx Context Descriptor */
159 __field(u16, out_len)
160 __field(u8, tun_len)
161 __field(u64, resvd3)
162 __field(u16, mss_len)
163 __field(u8, l4_len)
164 __field(u8, l3_len)
165 __field(u8, l2_len)
166 __field(u8, ct_cmd)
167 __field(u16, vlan_tag)
168 __field(u8, ct_idx)
169 __field(u8, des_typ)
170 } entry;
171 struct __entry_s *__entry = &entry;
172 __entry->ring_idx = ring_idx;
173 __entry->pointer = pointer;
174 __entry->out_len = DESCR_FIELD(descr[0], 63, 48);
175 __entry->tun_len = DESCR_FIELD(descr[0], 47, 40);
176 __entry->resvd3 = DESCR_FIELD(descr[0], 39, 0);
177 __entry->mss_len = DESCR_FIELD(descr[1], 63, 48);
178 __entry->l4_len = DESCR_FIELD(descr[1], 47, 40);
179 __entry->l3_len = DESCR_FIELD(descr[1], 39, 31);
180 __entry->l2_len = DESCR_FIELD(descr[1], 30, 24);
181 __entry->ct_cmd = DESCR_FIELD(descr[1], 23, 20);
182 __entry->vlan_tag = DESCR_FIELD(descr[1], 19, 4);
183 __entry->ct_idx = DESCR_FIELD(descr[1], 3, 3);
184 __entry->des_typ = DESCR_FIELD(descr[1], 2, 0);
185
186 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",
187 __entry->ring_idx, __entry->pointer, __entry->out_len,
188 __entry->tun_len, __entry->resvd3, __entry->mss_len,
189 __entry->l4_len, __entry->l3_len, __entry->l2_len,
190 __entry->ct_cmd, __entry->vlan_tag, __entry->ct_idx,
191 __entry->des_typ);
192 #endif
193 }
194
DumpHex(const void * data,size_t size)195 void DumpHex(const void* data, size_t size) {
196 #if AQ_CFG_DEBUG_LVL > 3
197 char ascii[17];
198 size_t i, j;
199 char line[256];
200 char buf[256];
201
202 ascii[16] = '\0';
203 line[0] = '\0';
204 printf("packet at %p\n", data);
205
206 for (i = 0; i < size; ++i) {
207 sprintf(buf, "%02X ", ((const unsigned char*)data)[i]);
208 strcat(line, buf);
209 if (((const unsigned char*)data)[i] >= ' ' && ((const unsigned char*)data)[i] <= '~') {
210 ascii[i % 16] = ((const unsigned char*)data)[i];
211 } else {
212 ascii[i % 16] = '.';
213 }
214 if ((i+1) % 8 == 0 || i+1 == size) {
215 strcat(line, " ");
216 if ((i+1) % 16 == 0) {
217 sprintf(buf, "| %s \n", ascii);
218 strcat(line, buf);
219 printf("%s", line);
220 line[0] = '\0';
221 } else if (i+1 == size) {
222 ascii[(i+1) % 16] = '\0';
223 if ((i+1) % 16 <= 8) {
224 strcat(line, " ");
225 }
226 for (j = (i+1) % 16; j < 16; ++j) {
227 strcat(line, " ");
228 }
229 sprintf(buf, "| %s \n", ascii);
230 strcat(line, buf);
231 printf("%s", line);
232 line[0] = '\0';
233 }
234 }
235 }
236 #endif
237 }