]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - tools/tools/ath/athalq/ar9300_ds.c
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / tools / tools / ath / athalq / ar9300_ds.c
1 /*
2  * Copyright (c) 2012 Adrian Chadd <adrian@FreeBSD.org>
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16
17 #include <sys/cdefs.h>
18 __FBSDID("$FreeBSD$");
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <unistd.h>
23 #include <fcntl.h>
24 #include <errno.h>
25 #include <string.h>
26
27 #include <sys/types.h>
28 #include <sys/alq.h>
29 #include <sys/endian.h>
30
31 #include <dev/ath/if_ath_alq.h>
32 #include <dev/ath/ath_hal/ar9300/ar9300desc.h>
33
34 #include "ar9300_ds.h"
35
36 /* XXX should break this out into if_athvar.h */
37
38 #define MS(_v, _f)      ( ((_v) & (_f)) >> _f##_S )
39 #define MF(_v, _f) ( !! ((_v) & (_f)))
40
41 static void
42 ar9300_decode_txstatus(struct if_ath_alq_payload *a)
43 {
44         struct ar9300_txs txs;
45
46         /* XXX assumes txs is smaller than PAYLOAD_LEN! */
47         memcpy(&txs, &a->payload, sizeof(struct ar9300_txs));
48
49         printf("[%u.%06u] [%llu] TXSTATUS\n",
50             (unsigned int) be32toh(a->hdr.tstamp_sec),
51             (unsigned int) be32toh(a->hdr.tstamp_usec),
52             (unsigned long long) be64toh(a->hdr.threadid));
53         printf("    DescId=0x%08x\n", txs.status1);
54
55         printf("    DescLen=%d, TxQcuNum=%d, CtrlStat=%d, DescId=0x%04x\n",
56             txs.ds_info & 0xff,
57             MS(txs.ds_info, AR_tx_qcu_num),
58             MS(txs.ds_info, AR_ctrl_stat),
59             MS(txs.ds_info, AR_desc_id));
60
61         printf("    TxTimestamp=0x%08x\n", txs.status4);
62
63         printf("    TxDone=%d, SeqNo=%d, TxOpExceed=%d, TXBFStatus=%d\n",
64             MF(txs.status8, AR_tx_done),
65             MS(txs.status8, AR_seq_num),
66             MF(txs.status8, AR_tx_op_exceeded),
67             MS(txs.status8, AR_TXBFStatus));
68
69         printf("    TXBfMismatch=%d, BFStreamMiss=%d, FinalTxIdx=%d\n",
70             MF(txs.status8, AR_tx_bf_bw_mismatch),
71             MF(txs.status8, AR_tx_bf_stream_miss),
72             MS(txs.status8, AR_final_tx_idx));
73
74         printf("    TxBfDestMiss=%d, TxBfExpired=%d, PwrMgmt=%d, Tid=%d,"
75             " FastTsBit=%d\n",
76             MF(txs.status8, AR_tx_bf_dest_miss),
77             MF(txs.status8, AR_tx_bf_expired),
78             MF(txs.status8, AR_power_mgmt),
79             MS(txs.status8, AR_tx_tid),
80             MF(txs.status8, AR_tx_fast_ts));
81
82         printf("    Frmok=%d, xretries=%d, fifounderrun=%d, filt=%d\n",
83             MF(txs.status3, AR_frm_xmit_ok),
84             MF(txs.status3, AR_excessive_retries),
85             MF(txs.status3, AR_fifounderrun),
86             MF(txs.status3, AR_filtered));
87         printf("    DelimUnderrun=%d, DataUnderun=%d, DescCfgErr=%d,"
88             " TxTimerExceeded=%d\n",
89             MF(txs.status3, AR_tx_delim_underrun),
90             MF(txs.status3, AR_tx_data_underrun),
91             MF(txs.status3, AR_desc_cfg_err),
92             MF(txs.status3, AR_tx_timer_expired));
93
94         printf("    RTScnt=%d, FailCnt=%d, VRetryCnt=%d\n",
95             MS(txs.status3, AR_rts_fail_cnt),
96             MS(txs.status3, AR_data_fail_cnt),
97             MS(txs.status3, AR_virt_retry_cnt));
98
99
100
101         printf("    RX RSSI 0 [%d %d %d]\n",
102             MS(txs.status2, AR_tx_rssi_ant00),
103             MS(txs.status2, AR_tx_rssi_ant01),
104             MS(txs.status2, AR_tx_rssi_ant02));
105
106         printf("    RX RSSI 1 [%d %d %d] Comb=%d\n",
107             MS(txs.status7, AR_tx_rssi_ant10),
108             MS(txs.status7, AR_tx_rssi_ant11),
109             MS(txs.status7, AR_tx_rssi_ant12),
110             MS(txs.status7, AR_tx_rssi_combined));
111
112         printf("    BA Valid=%d\n",
113             MF(txs.status2, AR_tx_ba_status));
114
115         printf("    BALow=0x%08x\n", txs.status5);
116         printf("    BAHigh=0x%08x\n", txs.status6);
117
118         printf("\n ------ \n");
119 }
120
121 /*
122  * Note - these are rounded up to 128 bytes; but we
123  * only use 96 bytes from it.
124  */
125 static void
126 ar9300_decode_txdesc(struct if_ath_alq_payload *a)
127 {
128         struct ar9300_txc txc;
129
130         /* XXX assumes txs is smaller than PAYLOAD_LEN! */
131         memcpy(&txc, &a->payload, 96);
132
133         printf("[%u.%06u] [%llu] TXD\n",
134             (unsigned int) be32toh(a->hdr.tstamp_sec),
135             (unsigned int) be32toh(a->hdr.tstamp_usec),
136             (unsigned long long) be64toh(a->hdr.threadid));
137
138         printf("  DescLen=%d, TxQcuNum=%d, CtrlStat=%d, DescId=0x%04x\n",
139             txc.ds_info & 0xff,
140             MS(txc.ds_info, AR_tx_qcu_num),
141             MS(txc.ds_info, AR_ctrl_stat),
142             MS(txc.ds_info, AR_desc_id));
143
144         /* link */
145         printf("    Link 0x%08x\n", txc.ds_link);
146
147         /* data0 */
148         printf("    Data0 0x%08x Len %d\n",
149             txc.ds_data0,
150             MS(txc.ds_ctl3, AR_buf_len));
151
152         /* data1 */
153         printf("    Data1 0x%08x Len %d\n",
154             txc.ds_data1,
155             MS(txc.ds_ctl5, AR_buf_len));
156
157         /* data2 */
158         printf("    Data2 0x%08x Len %d\n",
159             txc.ds_data2,
160             MS(txc.ds_ctl7, AR_buf_len));
161
162         /* data3 */
163         printf("    Data3 0x%08x Len %d\n",
164             txc.ds_data3,
165             MS(txc.ds_ctl9, AR_buf_len));
166         
167
168         /* ctl10 */
169         printf("    Desc ID=0x%04x, Chksum=0x%04x (ctl10=0x%08x)\n",
170             MS(txc.ds_ctl10, AR_tx_desc_id),
171             txc.ds_ctl10 & AR_tx_ptr_chk_sum,
172             txc.ds_ctl10);
173
174         /* ctl11 */
175         printf("    Frame Len=%d, VMF=%d, LowRxChain=%d, TxClrRetry=%d\n",
176              txc.ds_ctl11 & AR_frame_len,
177             MF(txc.ds_ctl11, AR_virt_more_frag),
178             MF(txc.ds_ctl11, AR_low_rx_chain),
179             MF(txc.ds_ctl11, AR_tx_clear_retry));
180         printf("    TX power 0 = %d, RtsEna=%d, Veol=%d, ClrDstMask=%d\n",
181             MS(txc.ds_ctl11, AR_xmit_power0),
182             MF(txc.ds_ctl11, AR_rts_enable),
183             MF(txc.ds_ctl11, AR_veol),
184             MF(txc.ds_ctl11, AR_clr_dest_mask));
185         printf("    TxIntrReq=%d, DestIdxValid=%d, CtsEnable=%d\n",
186             MF(txc.ds_ctl11, AR_tx_intr_req),
187             MF(txc.ds_ctl11, AR_dest_idx_valid),
188             MF(txc.ds_ctl11, AR_cts_enable));
189
190         /* ctl12 */
191         printf("    Paprd Chain Mask=0x%x, TxMore=%d, DestIdx=%d,"
192             " FrType=0x%x\n",
193             MS(txc.ds_ctl12, AR_paprd_chain_mask),
194             MF(txc.ds_ctl12, AR_tx_more),
195             MS(txc.ds_ctl12, AR_dest_idx),
196             MS(txc.ds_ctl12, AR_frame_type));
197         printf("    NoAck=%d, InsertTs=%d, CorruptFcs=%d, ExtOnly=%d,"
198             " ExtAndCtl=%d\n",
199             MF(txc.ds_ctl12, AR_no_ack),
200             MF(txc.ds_ctl12, AR_insert_ts),
201             MF(txc.ds_ctl12, AR_corrupt_fcs),
202             MF(txc.ds_ctl12, AR_ext_only),
203             MF(txc.ds_ctl12, AR_ext_and_ctl));
204         printf("    IsAggr=%d, MoreRifs=%d, LocMode=%d\n",
205             MF(txc.ds_ctl12, AR_is_aggr),
206             MF(txc.ds_ctl12, AR_more_rifs),
207             MF(txc.ds_ctl12, AR_loc_mode));
208
209
210         /* ctl13 */
211         printf("    DurUpEna=%d, Burstdur=0x%04x\n",
212             MF(txc.ds_ctl13, AR_dur_update_ena),
213             MS(txc.ds_ctl13, AR_burst_dur));
214         printf("    Try0=%d, Try1=%d, Try2=%d, Try3=%d\n",
215             MS(txc.ds_ctl13, AR_xmit_data_tries0),
216             MS(txc.ds_ctl13, AR_xmit_data_tries1),
217             MS(txc.ds_ctl13, AR_xmit_data_tries2),
218             MS(txc.ds_ctl13, AR_xmit_data_tries3));
219
220         /* ctl14 */
221         printf("    rate0=0x%02x, rate1=0x%02x, rate2=0x%02x, rate3=0x%02x\n",
222             MS(txc.ds_ctl14, AR_xmit_rate0),
223             MS(txc.ds_ctl14, AR_xmit_rate1),
224             MS(txc.ds_ctl14, AR_xmit_rate2),
225             MS(txc.ds_ctl14, AR_xmit_rate3));
226
227         /* ctl15 */
228         printf("    try 0: PktDur=%d, RTS/CTS ena=%d\n",
229             MS(txc.ds_ctl15, AR_packet_dur0),
230             MF(txc.ds_ctl15, AR_rts_cts_qual0));
231         printf("    try 1: PktDur=%d, RTS/CTS ena=%d\n",
232             MS(txc.ds_ctl15, AR_packet_dur1),
233             MF(txc.ds_ctl15, AR_rts_cts_qual1));
234
235         /* ctl16 */
236         printf("    try 2: PktDur=%d, RTS/CTS ena=%d\n",
237             MS(txc.ds_ctl16, AR_packet_dur2),
238             MF(txc.ds_ctl16, AR_rts_cts_qual2));
239         printf("    try 3: PktDur=%d, RTS/CTS ena=%d\n",
240             MS(txc.ds_ctl16, AR_packet_dur3),
241             MF(txc.ds_ctl16, AR_rts_cts_qual3));
242
243         /* ctl17 */
244         printf("    AggrLen=%d, PadDelim=%d, EncrType=%d, TxDcApStaSel=%d\n",
245             MS(txc.ds_ctl17, AR_aggr_len),
246             MS(txc.ds_ctl17, AR_pad_delim),
247             MS(txc.ds_ctl17, AR_encr_type),
248             MF(txc.ds_ctl17, AR_tx_dc_ap_sta_sel));
249         printf("    Calib=%d LDPC=%d\n",
250             MF(txc.ds_ctl17, AR_calibrating),
251             MF(txc.ds_ctl17, AR_ldpc));
252
253         /* ctl18 */
254         printf("    try 0: chainMask=0x%x, GI=%d, 2040=%d, STBC=%d\n",
255             MS(txc.ds_ctl18, AR_chain_sel0),
256             MF(txc.ds_ctl18, AR_gi0),
257             MF(txc.ds_ctl18, AR_2040_0),
258             MF(txc.ds_ctl18, AR_stbc0));
259         printf("    try 1: chainMask=0x%x, GI=%d, 2040=%d, STBC=%d\n",
260             MS(txc.ds_ctl18, AR_chain_sel1),
261             MF(txc.ds_ctl18, AR_gi1),
262             MF(txc.ds_ctl18, AR_2040_1),
263             MF(txc.ds_ctl18, AR_stbc1));
264         printf("    try 2: chainMask=0x%x, GI=%d, 2040=%d, STBC=%d\n",
265             MS(txc.ds_ctl18, AR_chain_sel2),
266             MF(txc.ds_ctl18, AR_gi2),
267             MF(txc.ds_ctl18, AR_2040_2),
268             MF(txc.ds_ctl18, AR_stbc2));
269         printf("    try 3: chainMask=0x%x, GI=%d, 2040=%d, STBC=%d\n",
270             MS(txc.ds_ctl18, AR_chain_sel3),
271             MF(txc.ds_ctl18, AR_gi3),
272             MF(txc.ds_ctl18, AR_2040_3),
273             MF(txc.ds_ctl18, AR_stbc3));
274
275         /* ctl19 */
276         printf("    NotSounding=%d\n",
277             MF(txc.ds_ctl19, AR_not_sounding));
278
279         printf("    try 0: ant=0x%08x, antsel=%d, ness=%d\n",
280             txc.ds_ctl19 &  AR_tx_ant0,
281             MF(txc.ds_ctl19, AR_tx_ant_sel0),
282             MS(txc.ds_ctl19, AR_ness));
283
284         /* ctl20 */
285         printf("    try 1: TxPower=%d, ant=0x%08x, antsel=%d, ness=%d\n",
286             MS(txc.ds_ctl20, AR_xmit_power1),
287             txc.ds_ctl20 &  AR_tx_ant1,
288             MF(txc.ds_ctl20, AR_tx_ant_sel1),
289             MS(txc.ds_ctl20, AR_ness1));
290
291         /* ctl21 */
292         printf("    try 2: TxPower=%d, ant=0x%08x, antsel=%d, ness=%d\n",
293             MS(txc.ds_ctl21, AR_xmit_power2),
294             txc.ds_ctl21 &  AR_tx_ant2,
295             MF(txc.ds_ctl21, AR_tx_ant_sel2),
296             MS(txc.ds_ctl21, AR_ness2));
297
298         /* ctl22 */
299         printf("    try 3: TxPower=%d, ant=0x%08x, antsel=%d, ness=%d\n",
300             MS(txc.ds_ctl22, AR_xmit_power3),
301             txc.ds_ctl22 &  AR_tx_ant3,
302             MF(txc.ds_ctl22, AR_tx_ant_sel3),
303             MS(txc.ds_ctl22, AR_ness3));
304
305         printf("\n ------ \n");
306 }
307
308 static void
309 ar9300_decode_rxstatus(struct if_ath_alq_payload *a)
310 {
311         struct ar9300_rxs rxs;
312
313         /* XXX assumes rxs is smaller than PAYLOAD_LEN! */
314         memcpy(&rxs, &a->payload, sizeof(struct ar9300_rxs));
315
316         printf("[%u.%06u] [%llu] RXSTATUS\n",
317             (unsigned int) be32toh(a->hdr.tstamp_sec),
318             (unsigned int) be32toh(a->hdr.tstamp_usec),
319             (unsigned long long) be64toh(a->hdr.threadid));
320 }
321
322 void
323 ar9300_alq_payload(struct if_ath_alq_payload *a)
324 {
325
326                 switch (be16toh(a->hdr.op)) {
327                         case ATH_ALQ_EDMA_TXSTATUS:     /* TXSTATUS */
328                                 ar9300_decode_txstatus(a);
329                                 break;
330                         case ATH_ALQ_EDMA_RXSTATUS:     /* RXSTATUS */
331                                 ar9300_decode_rxstatus(a);
332                                 break;
333                         case ATH_ALQ_EDMA_TXDESC:       /* TXDESC */
334                                 ar9300_decode_txdesc(a);
335                                 break;
336                         default:
337                                 printf("[%d.%06d] [%lld] op: %d; len %d\n",
338                                     be32toh(a->hdr.tstamp_sec),
339                                     be32toh(a->hdr.tstamp_usec),
340                                     be64toh(a->hdr.threadid),
341                                     be16toh(a->hdr.op), be16toh(a->hdr.len));
342                 }
343 }