if_ath_alq.h revision 246945
11573Srgrimes/*- 21573Srgrimes * Copyright (c) 2012 Adrian Chadd 31573Srgrimes * All rights reserved. 41573Srgrimes * 51573Srgrimes * Redistribution and use in source and binary forms, with or without 61573Srgrimes * modification, are permitted provided that the following conditions 71573Srgrimes * are met: 81573Srgrimes * 1. Redistributions of source code must retain the above copyright 91573Srgrimes * notice, this list of conditions and the following disclaimer, 101573Srgrimes * without modification. 111573Srgrimes * 2. Redistributions in binary form must reproduce at minimum a disclaimer 121573Srgrimes * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any 131573Srgrimes * redistribution must be conditioned upon including a substantially 141573Srgrimes * similar Disclaimer requirement for further binary redistribution. 151573Srgrimes * 16148834Sstefanf * NO WARRANTY 171573Srgrimes * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 181573Srgrimes * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 191573Srgrimes * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY 201573Srgrimes * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 211573Srgrimes * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, 221573Srgrimes * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 231573Srgrimes * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 241573Srgrimes * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 251573Srgrimes * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 261573Srgrimes * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 271573Srgrimes * THE POSSIBILITY OF SUCH DAMAGES. 281573Srgrimes * 291573Srgrimes * $FreeBSD: head/sys/dev/ath/if_ath_alq.h 246945 2013-02-18 18:39:15Z adrian $ 301573Srgrimes */ 3184260Sobrien#ifndef __IF_ATH_ALQ_H__ 32237448Spfg#define __IF_ATH_ALQ_H__ 331573Srgrimes 341573Srgrimes#define ATH_ALQ_INIT_STATE 1 3560773Simpstruct if_ath_alq_init_state { 361573Srgrimes uint32_t sc_mac_version; 3760773Simp uint32_t sc_mac_revision; 3884260Sobrien uint32_t sc_phy_rev; 3984260Sobrien uint32_t sc_hal_magic; 4084260Sobrien}; 411573Srgrimes 421573Srgrimes#define ATH_ALQ_EDMA_TXSTATUS 2 431573Srgrimes#define ATH_ALQ_EDMA_RXSTATUS 3 441573Srgrimes#define ATH_ALQ_EDMA_TXDESC 4 451573Srgrimes 4660770Simp#define ATH_ALQ_TDMA_BEACON_STATE 5 4766562Sbrianstruct if_ath_alq_tdma_beacon_state { 481573Srgrimes uint64_t rx_tsf; /* RX TSF of beacon frame */ 491573Srgrimes uint64_t beacon_tsf; /* TSF inside beacon frame */ 501573Srgrimes uint64_t tsf64; 511573Srgrimes uint64_t nextslot_tsf; 52238173Spfg uint32_t nextslot_tu; 531573Srgrimes uint32_t txtime; 5484260Sobrien}; 5584260Sobrien 56148834Sstefanf#define ATH_ALQ_TDMA_TIMER_CONFIG 6 5784260Sobrienstruct if_ath_alq_tdma_timer_config { 58167464Sstefanf uint32_t tdma_slot; 591573Srgrimes uint32_t tdma_slotlen; 60148834Sstefanf uint32_t tdma_slotcnt; 61148834Sstefanf uint32_t tdma_bintval; 62148834Sstefanf uint32_t tdma_guard; 63148834Sstefanf uint32_t tdma_scbintval; 64148834Sstefanf uint32_t tdma_dbaprep; 65148834Sstefanf}; 66148834Sstefanf 67148834Sstefanf#define ATH_ALQ_TDMA_SLOT_CALC 7 68148834Sstefanfstruct if_ath_alq_tdma_slot_calc { 69148834Sstefanf uint64_t nexttbtt; 70148834Sstefanf uint64_t next_slot; 71148834Sstefanf int32_t tsfdelta; 72148834Sstefanf int32_t avg_plus; 73148834Sstefanf int32_t avg_minus; 74148834Sstefanf}; 75148834Sstefanf 76148834Sstefanf#define ATH_ALQ_TDMA_TSF_ADJUST 8 77148834Sstefanfstruct if_ath_alq_tdma_tsf_adjust { 78148834Sstefanf uint64_t tsf64_old; 79148834Sstefanf uint64_t tsf64_new; 80148834Sstefanf int32_t tsfdelta; 81148834Sstefanf}; 82148834Sstefanf 83148834Sstefanf#define ATH_ALQ_TDMA_TIMER_SET 9 84148834Sstefanfstruct if_ath_alq_tdma_timer_set { 85148834Sstefanf uint32_t bt_intval; 86148834Sstefanf uint32_t bt_nexttbtt; 87148834Sstefanf uint32_t bt_nextdba; 88148834Sstefanf uint32_t bt_nextswba; 89148834Sstefanf uint32_t bt_nextatim; 90148834Sstefanf uint32_t bt_flags; 91148834Sstefanf uint32_t sc_tdmadbaprep; 92148834Sstefanf uint32_t sc_tdmaswbaprep; 93148834Sstefanf}; 94148834Sstefanf 95148834Sstefanf#define ATH_ALQ_INTR_STATUS 10 96148834Sstefanfstruct if_ath_alq_interrupt { 97148834Sstefanf uint32_t intr_status; 98148834Sstefanf uint32_t intr_state[8]; 99148834Sstefanf uint32_t intr_syncstate; 1001573Srgrimes}; 1011573Srgrimes 10284260Sobrien/* 1031573Srgrimes * These will always be logged, regardless. 1041573Srgrimes */ 10584260Sobrien#define ATH_ALQ_LOG_ALWAYS_MASK 0x00000001 10684260Sobrien 10784260Sobrien#define ATH_ALQ_FILENAME_LEN 128 10884260Sobrien#define ATH_ALQ_DEVNAME_LEN 32 10984260Sobrien 11084260Sobrienstruct if_ath_alq { 11184260Sobrien uint32_t sc_alq_debug; /* Debug flags to report */ 11284260Sobrien struct alq * sc_alq_alq; /* alq state */ 11384260Sobrien unsigned int sc_alq_qsize; /* queue size */ 11484260Sobrien unsigned int sc_alq_numlost; /* number of "lost" entries */ 1151573Srgrimes int sc_alq_isactive; 1161573Srgrimes char sc_alq_devname[ATH_ALQ_DEVNAME_LEN]; 1171573Srgrimes char sc_alq_filename[ATH_ALQ_FILENAME_LEN]; 11884260Sobrien struct if_ath_alq_init_state sc_alq_cfg; 1191573Srgrimes}; 1201573Srgrimes 1211573Srgrimes/* 128 bytes in total */ 12284260Sobrien#define ATH_ALQ_PAYLOAD_LEN 112 1231573Srgrimes 124148834Sstefanfstruct if_ath_alq_hdr { 1251573Srgrimes uint64_t threadid; 1261573Srgrimes uint32_t tstamp_sec; 12784260Sobrien uint32_t tstamp_usec; 12884260Sobrien uint16_t op; 12984260Sobrien uint16_t len; /* Length of (optional) payload */ 1301573Srgrimes}; 13184260Sobrien 13284260Sobrienstruct if_ath_alq_payload { 13384260Sobrien struct if_ath_alq_hdr hdr; 13484260Sobrien char payload[]; 1351573Srgrimes}; 1361573Srgrimes 1371573Srgrimes#ifdef _KERNEL 13884260Sobrienstatic inline int 13984260Sobrienif_ath_alq_checkdebug(struct if_ath_alq *alq, uint16_t op) 14084260Sobrien{ 14184260Sobrien 14284260Sobrien return ((alq->sc_alq_debug | ATH_ALQ_LOG_ALWAYS_MASK) 14384260Sobrien & (1 << (op - 1))); 1441573Srgrimes} 1451573Srgrimes 14684260Sobrienextern void if_ath_alq_init(struct if_ath_alq *alq, const char *devname); 1471573Srgrimesextern void if_ath_alq_setcfg(struct if_ath_alq *alq, uint32_t macVer, 14884260Sobrien uint32_t macRev, uint32_t phyRev, uint32_t halMagic); 14984260Sobrienextern void if_ath_alq_tidyup(struct if_ath_alq *alq); 15084260Sobrienextern int if_ath_alq_start(struct if_ath_alq *alq); 1511573Srgrimesextern int if_ath_alq_stop(struct if_ath_alq *alq); 15284260Sobrienextern void if_ath_alq_post(struct if_ath_alq *alq, uint16_t op, 15384260Sobrien uint16_t len, const char *buf); 15484260Sobrien 15584260Sobrien/* XXX maybe doesn't belong here? */ 15684260Sobrienstatic inline void 1571573Srgrimesif_ath_alq_post_intr(struct if_ath_alq *alq, uint32_t status, 15884260Sobrien uint32_t *state, uint32_t sync_state) 15984260Sobrien{ 16084260Sobrien int i; 1611573Srgrimes struct if_ath_alq_interrupt intr; 16284260Sobrien 16384260Sobrien if (! if_ath_alq_checkdebug(alq, ATH_ALQ_INTR_STATUS)) 16484260Sobrien return; 16584260Sobrien 16684260Sobrien intr.intr_status = htobe32(status); 16784260Sobrien for (i = 0; i < 8; i++) 16884260Sobrien intr.intr_state[i] = htobe32(state[i]); 1691573Srgrimes intr.intr_syncstate = htobe32(sync_state); 17084260Sobrien 1711573Srgrimes if_ath_alq_post(alq, ATH_ALQ_INTR_STATUS, sizeof(intr), 17284260Sobrien (const char *) &intr); 173238173Spfg} 1741573Srgrimes 17584260Sobrien#endif /* _KERNEL */ 17684260Sobrien 17784260Sobrien#endif 1781573Srgrimes