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/ar5212/ar5212desc.h> 34 35 #include "ar5212_ds.h" 36 37 #define MS(_v, _f) ( ((_v) & (_f)) >> _f##_S ) 38 #define MF(_v, _f) ( !! ((_v) & (_f))) 39 40 static void 41 ar5212_decode_txstatus(struct if_ath_alq_payload *a) 42 { 43 struct ar5212_desc txs; 44 45 /* XXX assumes txs is smaller than PAYLOAD_LEN! */ 46 memcpy(&txs, &a->payload, sizeof(struct ar5212_desc)); 47 48 printf("[%u.%06u] [%llu] TXSTATUS: TxDone=%d, TS=0x%08x\n\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 MF(txs.u.tx.status1, AR_Done), 53 MS(txs.u.tx.status0, AR_SendTimestamp)); 54 55 /* ds_txstatus0 */ 56 printf(" Frmok=%d, xretries=%d, fifounderrun=%d, filt=%d\n", 57 MF(txs.u.tx.status0, AR_FrmXmitOK), 58 MF(txs.u.tx.status0, AR_ExcessiveRetries), 59 MF(txs.u.tx.status0, AR_FIFOUnderrun), 60 MF(txs.u.tx.status0, AR_Filtered)); 61 printf(" RTScnt=%d, FailCnt=%d, VCollCnt=%d\n", 62 MS(txs.u.tx.status0, AR_RTSFailCnt), 63 MS(txs.u.tx.status0, AR_DataFailCnt), 64 MS(txs.u.tx.status0, AR_VirtCollCnt)); 65 printf(" SndTimestamp=0x%04x\n", 66 MS(txs.u.tx.status0, AR_SendTimestamp)); 67 68 /* ds_txstatus1 */ 69 printf(" Done=%d, SeqNum=0x%04x, AckRSSI=%d, FinalTSI=%d\n", 70 MF(txs.u.tx.status1, AR_Done), 71 MS(txs.u.tx.status1, AR_SeqNum), 72 MS(txs.u.tx.status1, AR_AckSigStrength), 73 MS(txs.u.tx.status1, AR_FinalTSIndex)); 74 printf(" CompSuccess=%d, XmitAntenna=%d\n", 75 MF(txs.u.tx.status1, AR_CompSuccess), 76 MF(txs.u.tx.status1, AR_XmitAtenna)); 77 78 printf("\n ------\n"); 79 } 80 81 static void 82 ar5212_decode_txdesc(struct if_ath_alq_payload *a) 83 { 84 struct ar5212_desc txc; 85 86 /* XXX assumes txs is smaller than PAYLOAD_LEN! */ 87 memcpy(&txc, &a->payload, sizeof(struct ar5212_desc)); 88 89 printf("[%u.%06u] [%llu] TXD\n", 90 (unsigned int) be32toh(a->hdr.tstamp_sec), 91 (unsigned int) be32toh(a->hdr.tstamp_usec), 92 (unsigned long long) be64toh(a->hdr.threadid)); 93 94 printf(" link=0x%08x, data=0x%08x\n", 95 txc.ds_link, 96 txc.ds_data); 97 98 /* ds_ctl0 */ 99 printf(" Frame Len=%d\n", txc.ds_ctl0 & AR_FrameLen); 100 printf(" TX power0=%d, RtsEna=%d, Veol=%d, ClrDstMask=%d AntModeXmit=0x%02x\n", 101 MS(txc.ds_ctl0, AR_XmitPower), 102 MF(txc.ds_ctl0, AR_RTSCTSEnable), 103 MF(txc.ds_ctl0, AR_VEOL), 104 MF(txc.ds_ctl0, AR_ClearDestMask), 105 MF(txc.ds_ctl0, AR_AntModeXmit)); 106 printf(" TxIntrReq=%d, DestIdxValid=%d, CtsEnable=%d\n", 107 MF(txc.ds_ctl0, AR_TxInterReq), 108 MF(txc.ds_ctl0, AR_DestIdxValid), 109 MF(txc.ds_ctl0, AR_CTSEnable)); 110 111 /* ds_ctl1 */ 112 printf(" BufLen=%d, TxMore=%d, DestIdx=%d," 113 " FrType=0x%x\n", 114 txc.ds_ctl1 & AR_BufLen, 115 MF(txc.ds_ctl1, AR_More), 116 MS(txc.ds_ctl1, AR_DestIdx), 117 MS(txc.ds_ctl1, AR_FrmType)); 118 printf(" NoAck=%d, CompProc=%d, CompIVLen=%d, CompICVLen=%d\n", 119 MF(txc.ds_ctl1, AR_NoAck), 120 MS(txc.ds_ctl1, AR_CompProc), 121 MS(txc.ds_ctl1, AR_CompIVLen), 122 MS(txc.ds_ctl1, AR_CompICVLen)); 123 124 /* ds_ctl2 */ 125 printf(" DurUpEna=%d, Burstdur=0x%04x\n", 126 MF(txc.ds_ctl2, AR_DurUpdateEna), 127 MS(txc.ds_ctl2, AR_RTSCTSDuration)); 128 printf(" Try0=%d, Try1=%d, Try2=%d, Try3=%d\n", 129 MS(txc.ds_ctl2, AR_XmitDataTries0), 130 MS(txc.ds_ctl2, AR_XmitDataTries1), 131 MS(txc.ds_ctl2, AR_XmitDataTries2), 132 MS(txc.ds_ctl2, AR_XmitDataTries3)); 133 134 /* ds_ctl3 */ 135 printf(" rate0=0x%02x, rate1=0x%02x, rate2=0x%02x, rate3=0x%02x\n", 136 MS(txc.ds_ctl3, AR_XmitRate0), 137 MS(txc.ds_ctl3, AR_XmitRate1), 138 MS(txc.ds_ctl3, AR_XmitRate2), 139 MS(txc.ds_ctl3, AR_XmitRate3)); 140 printf(" RtsCtsRate=0x%02x\n", 141 MS(txc.ds_ctl3, AR_RTSCTSRate)); 142 143 printf("\n ------ \n"); 144 } 145 146 static void 147 ar5212_decode_rxstatus(struct if_ath_alq_payload *a) 148 { 149 struct ar5212_desc rxs; 150 151 /* XXX assumes rxs is smaller than PAYLOAD_LEN! */ 152 memcpy(&rxs, &a->payload, sizeof(struct ar5212_desc)); 153 154 printf("[%u.%06u] [%llu] RXSTATUS: RxOK=%d TS=0x%08x\n", 155 (unsigned int) be32toh(a->hdr.tstamp_sec), 156 (unsigned int) be32toh(a->hdr.tstamp_usec), 157 (unsigned long long) be64toh(a->hdr.threadid), 158 MF(rxs.ds_rxstatus1, AR_Done), 159 MS(rxs.ds_rxstatus1, AR_RcvTimestamp)); 160 161 printf(" link=0x%08x, data=0x%08x, ctl0=0x%08x, ctl2=0x%08x\n", 162 rxs.ds_link, 163 rxs.ds_data, 164 rxs.ds_ctl0, 165 rxs.ds_ctl1); 166 167 /* ds_rxstatus0 */ 168 printf(" DataLen=%d, ArMore=%d, DecompCrcError=%d, RcvRate=0x%02x\n", 169 rxs.ds_rxstatus0 & AR_DataLen, 170 MF(rxs.ds_rxstatus0, AR_More), 171 MF(rxs.ds_rxstatus0, AR_DecompCRCErr), 172 MS(rxs.ds_rxstatus0, AR_RcvRate)); 173 printf(" RSSI=%d, RcvAntenna=0x%x\n", 174 MS(rxs.ds_rxstatus0, AR_RcvSigStrength), 175 MS(rxs.ds_rxstatus0, AR_RcvAntenna)); 176 177 /* ds_rxstatus1 */ 178 printf(" RxDone=%d, RxFrameOk=%d, CrcErr=%d, DecryptCrcErr=%d\n", 179 MF(rxs.ds_rxstatus1, AR_Done), 180 MF(rxs.ds_rxstatus1, AR_FrmRcvOK), 181 MF(rxs.ds_rxstatus1, AR_CRCErr), 182 MF(rxs.ds_rxstatus1, AR_DecryptCRCErr)); 183 printf(" PhyErr=%d, MichaelErr=%d, KeyIdxValid=%d\n", 184 MF(rxs.ds_rxstatus1, AR_PHYErr), 185 MF(rxs.ds_rxstatus1, AR_MichaelErr), 186 MF(rxs.ds_rxstatus1, AR_KeyIdxValid)); 187 188 /* If PHY error, print that out. Otherwise, the key index */ 189 if (MF(rxs.ds_rxstatus1, AR_PHYErr)) 190 printf(" PhyErrCode=0x%02x\n", 191 MS(rxs.ds_rxstatus1, AR_PHYErrCode)); 192 else 193 printf(" KeyIdx=0x%02x\n", 194 MS(rxs.ds_rxstatus1, AR_KeyIdx)); 195 196 printf(" KeyMiss=%d\n", 197 MF(rxs.ds_rxstatus1, AR_KeyCacheMiss)); 198 199 printf(" Timetamp: 0x%05x\n", 200 MS(rxs.ds_rxstatus1, AR_RcvTimestamp)); 201 202 printf("\n ------\n"); 203 } 204 205 void 206 ar5212_alq_payload(struct if_ath_alq_payload *a) 207 { 208 209 switch (be16toh(a->hdr.op)) { 210 case ATH_ALQ_EDMA_TXSTATUS: /* TXSTATUS */ 211 ar5212_decode_txstatus(a); 212 break; 213 case ATH_ALQ_EDMA_RXSTATUS: /* RXSTATUS */ 214 ar5212_decode_rxstatus(a); 215 break; 216 case ATH_ALQ_EDMA_TXDESC: /* TXDESC */ 217 ar5212_decode_txdesc(a); 218 break; 219 default: 220 printf("[%d.%06d] [%lld] op: %d; len %d\n", 221 be32toh(a->hdr.tstamp_sec), 222 be32toh(a->hdr.tstamp_usec), 223 be64toh(a->hdr.threadid), 224 be16toh(a->hdr.op), be16toh(a->hdr.len)); 225 } 226 } 227