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/ar5210/ar5210desc.h> 34 35 #include "ar5210_ds.h" 36 37 #define MS(_v, _f) ( ((_v) & (_f)) >> _f##_S ) 38 #define MF(_v, _f) ( !! ((_v) & (_f))) 39 40 static void 41 ar5210_decode_txstatus(struct if_ath_alq_payload *a) 42 { 43 struct ar5210_desc txs; 44 45 /* XXX assumes txs is smaller than PAYLOAD_LEN! */ 46 memcpy(&txs, &a->payload, sizeof(struct ar5210_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\n", 60 MS(txs.ds_status0, AR_LongRetryCnt), 61 MS(txs.ds_status0, AR_ShortRetryCnt)); 62 printf(" SndTimestamp=0x%04x\n", 63 MS(txs.ds_status0, AR_SendTimestamp)); 64 65 /* ds_txstatus1 */ 66 printf(" Done=%d, SeqNum=0x%04x, AckRSSI=%d\n", 67 MF(txs.ds_status1, AR_Done), 68 txs.ds_status1 & AR_SeqNum, 69 MS(txs.ds_status1, AR_AckSigStrength)); 70 71 printf("\n ------\n"); 72 } 73 74 static void 75 ar5210_decode_txdesc(struct if_ath_alq_payload *a) 76 { 77 struct ar5210_desc txc; 78 79 /* XXX assumes txs is smaller than PAYLOAD_LEN! */ 80 memcpy(&txc, &a->payload, sizeof(struct ar5210_desc)); 81 82 printf("[%u.%06u] [%llu] TXD\n", 83 (unsigned int) be32toh(a->hdr.tstamp_sec), 84 (unsigned int) be32toh(a->hdr.tstamp_usec), 85 (unsigned long long) be64toh(a->hdr.threadid)); 86 87 printf(" link=0x%08x, data=0x%08x\n", 88 txc.ds_link, 89 txc.ds_data); 90 91 /* ds_ctl0 */ 92 printf(" Frame Len=%d\n", txc.ds_ctl0 & AR_FrameLen); 93 printf(" TX Rate=0x%02x, RtsEna=%d, ClrDstMask=%d AntModeXmit=0x%02x\n", 94 MS(txc.ds_ctl0, AR_XmitRate), 95 MF(txc.ds_ctl0, AR_RTSCTSEnable), 96 MF(txc.ds_ctl0, AR_ClearDestMask), 97 MF(txc.ds_ctl0, AR_AntModeXmit)); 98 printf(" FrmType=0x%02x, TxIntrReq=%d\n", 99 MS(txc.ds_ctl0, AR_FrmType), 100 MF(txc.ds_ctl0, AR_TxInterReq)); 101 printf(" LongPkt=%d\n", MF(txc.ds_ctl0, AR_LongPkt)); 102 103 /* ds_ctl1 */ 104 printf(" BufLen=%d, TxMore=%d, EncryptKeyIdx=%d, RtsDuration=%d\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_RTSDuration)); 109 110 printf("\n ------ \n"); 111 } 112 113 static void 114 ar5210_decode_rxstatus(struct if_ath_alq_payload *a) 115 { 116 struct ar5210_desc rxs; 117 118 /* XXX assumes rxs is smaller than PAYLOAD_LEN! */ 119 memcpy(&rxs, &a->payload, sizeof(struct ar5210_desc)); 120 121 printf("[%u.%06u] [%llu] RXSTATUS\n", 122 (unsigned int) be32toh(a->hdr.tstamp_sec), 123 (unsigned int) be32toh(a->hdr.tstamp_usec), 124 (unsigned long long) be64toh(a->hdr.threadid)); 125 126 printf(" link=0x%08x, data=0x%08x\n", 127 rxs.ds_link, 128 rxs.ds_data); 129 130 /* ds_rxstatus0 */ 131 printf(" DataLen=%d, ArMore=%d, RSSI=%d, RcvAntenna=0x%x\n", 132 rxs.ds_status0 & AR_DataLen, 133 MF(rxs.ds_status0, AR_More), 134 MS(rxs.ds_status0, AR_RcvSigStrength), 135 MF(rxs.ds_status0, AR_RcvAntenna)); 136 137 /* ds_rxstatus1 */ 138 printf(" RxDone=%d, RxFrameOk=%d, CrcErr=%d, DecryptCrcErr=%d\n", 139 MF(rxs.ds_status1, AR_Done), 140 MF(rxs.ds_status1, AR_FrmRcvOK), 141 MF(rxs.ds_status1, AR_CRCErr), 142 MF(rxs.ds_status1, AR_DecryptCRCErr)); 143 printf(" KeyIdxValid=%d\n", 144 MF(rxs.ds_status1, AR_KeyIdxValid)); 145 146 printf(" PhyErrCode=0x%02x\n", 147 MS(rxs.ds_status1, AR_PHYErr)); 148 149 printf(" KeyMiss=%d\n", 150 MF(rxs.ds_status1, AR_KeyCacheMiss)); 151 152 printf(" Timetamp: 0x%05x\n", 153 MS(rxs.ds_status1, AR_RcvTimestamp)); 154 155 printf("\n ------\n"); 156 } 157 158 void 159 ar5210_alq_payload(struct if_ath_alq_payload *a) 160 { 161 162 switch (be16toh(a->hdr.op)) { 163 case ATH_ALQ_EDMA_TXSTATUS: /* TXSTATUS */ 164 ar5210_decode_txstatus(a); 165 break; 166 case ATH_ALQ_EDMA_RXSTATUS: /* RXSTATUS */ 167 ar5210_decode_rxstatus(a); 168 break; 169 case ATH_ALQ_EDMA_TXDESC: /* TXDESC */ 170 ar5210_decode_txdesc(a); 171 break; 172 default: 173 printf("[%d.%06d] [%lld] op: %d; len %d\n", 174 be32toh(a->hdr.tstamp_sec), 175 be32toh(a->hdr.tstamp_usec), 176 be64toh(a->hdr.threadid), 177 be16toh(a->hdr.op), be16toh(a->hdr.len)); 178 } 179 } 180