]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - tools/tools/ath/athalq/ar5211_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 / ar5211_ds.c
1 /*
2  * Copyright (c) 2012 Adrian Chadd <adrian@FreeBSD.org>
3  * All Rights Reserved.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17
18 #include <sys/cdefs.h>
19 __FBSDID("$FreeBSD$");
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <unistd.h>
24 #include <fcntl.h>
25 #include <errno.h>
26 #include <string.h>
27
28 #include <sys/types.h>
29 #include <sys/alq.h>
30 #include <sys/endian.h>
31
32 #include <dev/ath/if_ath_alq.h>
33 #include <dev/ath/ath_hal/ar5211/ar5211desc.h>
34
35 #include "ar5211_ds.h"
36
37 #define MS(_v, _f)      ( ((_v) & (_f)) >> _f##_S )
38 #define MF(_v, _f) ( !! ((_v) & (_f)))
39
40 static void
41 ar5211_decode_txstatus(struct if_ath_alq_payload *a)
42 {
43         struct ar5211_desc txs;
44
45         /* XXX assumes txs is smaller than PAYLOAD_LEN! */
46         memcpy(&txs, &a->payload, sizeof(struct ar5211_desc));
47
48         printf("[%u.%06u] [%llu] TXSTATUS\n",
49             (unsigned int) be32toh(a->hdr.tstamp_sec),
50             (unsigned int) be32toh(a->hdr.tstamp_usec),
51             (unsigned long long) be64toh(a->hdr.threadid));
52
53         /* ds_txstatus0 */
54         printf("    Frmok=%d, xretries=%d, fifounderrun=%d, filt=%d\n",
55             MF(txs.ds_status0, AR_FrmXmitOK),
56             MF(txs.ds_status0, AR_ExcessiveRetries),
57             MF(txs.ds_status0, AR_FIFOUnderrun),
58             MF(txs.ds_status0, AR_Filtered));
59         printf("    LongRetryCnt=%d, ShortRetryCnt=%d, VCollCnt=%d\n",
60             MS(txs.ds_status0, AR_LongRetryCnt),
61             MS(txs.ds_status0, AR_ShortRetryCnt),
62             MS(txs.ds_status0, AR_VirtCollCnt));
63         printf("    SndTimestamp=0x%04x\n",
64             MS(txs.ds_status0, AR_SendTimestamp));
65
66         /* ds_txstatus1 */
67         printf("    Done=%d, SeqNum=0x%04x, AckRSSI=%d\n",
68             MF(txs.ds_status1, AR_Done),
69             MS(txs.ds_status1, AR_SeqNum),
70             MS(txs.ds_status1, AR_AckSigStrength));
71
72         printf("\n ------\n");
73 }
74
75 static void
76 ar5211_decode_txdesc(struct if_ath_alq_payload *a)
77 {
78         struct ar5211_desc txc;
79
80         /* XXX assumes txs is smaller than PAYLOAD_LEN! */
81         memcpy(&txc, &a->payload, sizeof(struct ar5211_desc));
82
83         printf("[%u.%06u] [%llu] TXD\n",
84             (unsigned int) be32toh(a->hdr.tstamp_sec),
85             (unsigned int) be32toh(a->hdr.tstamp_usec),
86             (unsigned long long) be64toh(a->hdr.threadid));
87
88         printf("  link=0x%08x, data=0x%08x\n",
89             txc.ds_link,
90             txc.ds_data);
91
92         /* ds_ctl0 */
93         printf("    Frame Len=%d\n", txc.ds_ctl0 & AR_FrameLen);
94         printf("    TX Rate=0x%02x, RtsEna=%d, Veol=%d, ClrDstMask=%d AntModeXmit=0x%02x\n",
95             MS(txc.ds_ctl0, AR_XmitRate),
96             MF(txc.ds_ctl0, AR_RTSCTSEnable),
97             MF(txc.ds_ctl0, AR_VEOL),
98             MF(txc.ds_ctl0, AR_ClearDestMask),
99             MF(txc.ds_ctl0, AR_AntModeXmit));
100         printf("    TxIntrReq=%d\n",
101             MF(txc.ds_ctl0, AR_TxInterReq));
102
103         /* ds_ctl1 */
104         printf("    BufLen=%d, TxMore=%d, EncryptKeyIdx=%d,FrType=0x%x\n",
105             txc.ds_ctl1 & AR_BufLen,
106             MF(txc.ds_ctl1, AR_More),
107             MS(txc.ds_ctl1, AR_EncryptKeyIdx),
108             MS(txc.ds_ctl1, AR_FrmType));
109         printf("    NoAck=%d\n", MF(txc.ds_ctl1, AR_NoAck));
110
111         printf("\n ------ \n");
112 }
113
114 static void
115 ar5211_decode_rxstatus(struct if_ath_alq_payload *a)
116 {
117         struct ar5211_desc rxs;
118
119         /* XXX assumes rxs is smaller than PAYLOAD_LEN! */
120         memcpy(&rxs, &a->payload, sizeof(struct ar5211_desc));
121
122         printf("[%u.%06u] [%llu] RXSTATUS\n",
123             (unsigned int) be32toh(a->hdr.tstamp_sec),
124             (unsigned int) be32toh(a->hdr.tstamp_usec),
125             (unsigned long long) be64toh(a->hdr.threadid));
126
127         printf("  link=0x%08x, data=0x%08x\n",
128             rxs.ds_link,
129             rxs.ds_data);
130
131         /* ds_rxstatus0 */
132         printf("  DataLen=%d, ArMore=%d, RSSI=%d, RcvAntenna=0x%x\n",
133             rxs.ds_status0 & AR_DataLen,
134             MF(rxs.ds_status0, AR_More),
135             MS(rxs.ds_status0, AR_RcvSigStrength),
136             MS(rxs.ds_status0, AR_RcvAntenna));
137
138         /* ds_rxstatus1 */
139         printf("  RxDone=%d, RxFrameOk=%d, CrcErr=%d, DecryptCrcErr=%d\n",
140             MF(rxs.ds_status1, AR_Done),
141             MF(rxs.ds_status1, AR_FrmRcvOK),
142             MF(rxs.ds_status1, AR_CRCErr),
143             MF(rxs.ds_status1, AR_DecryptCRCErr));
144         printf("  KeyIdxValid=%d\n",
145             MF(rxs.ds_status1, AR_KeyIdxValid));
146
147         printf("  PhyErrCode=0x%02x\n",
148             MS(rxs.ds_status1, AR_PHYErr));
149
150         printf("  KeyMiss=%d\n",
151             MF(rxs.ds_status1, AR_KeyCacheMiss));
152
153         printf("  Timetamp: 0x%05x\n",
154             MS(rxs.ds_status1, AR_RcvTimestamp));
155
156         printf("\n ------\n");
157 }
158
159 void
160 ar5211_alq_payload(struct if_ath_alq_payload *a)
161 {
162
163                 switch (be16toh(a->hdr.op)) {
164                         case ATH_ALQ_EDMA_TXSTATUS:     /* TXSTATUS */
165                                 ar5211_decode_txstatus(a);
166                                 break;
167                         case ATH_ALQ_EDMA_RXSTATUS:     /* RXSTATUS */
168                                 ar5211_decode_rxstatus(a);
169                                 break;
170                         case ATH_ALQ_EDMA_TXDESC:       /* TXDESC */
171                                 ar5211_decode_txdesc(a);
172                                 break;
173                         default:
174                                 printf("[%d.%06d] [%lld] op: %d; len %d\n",
175                                     be32toh(a->hdr.tstamp_sec),
176                                     be32toh(a->hdr.tstamp_usec),
177                                     be64toh(a->hdr.threadid),
178                                     be16toh(a->hdr.op), be16toh(a->hdr.len));
179                 }
180 }