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