18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright (c) 2008-2011 Atheros Communications Inc. 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Permission to use, copy, modify, and/or distribute this software for any 58c2ecf20Sopenharmony_ci * purpose with or without fee is hereby granted, provided that the above 68c2ecf20Sopenharmony_ci * copyright notice and this permission notice appear in all copies. 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 98c2ecf20Sopenharmony_ci * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 108c2ecf20Sopenharmony_ci * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 118c2ecf20Sopenharmony_ci * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 128c2ecf20Sopenharmony_ci * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 138c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 148c2ecf20Sopenharmony_ci * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 158c2ecf20Sopenharmony_ci */ 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#include "hw.h" 188c2ecf20Sopenharmony_ci#include "hw-ops.h" 198c2ecf20Sopenharmony_ci#include <linux/export.h> 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_cistatic void ath9k_hw_set_txq_interrupts(struct ath_hw *ah, 228c2ecf20Sopenharmony_ci struct ath9k_tx_queue_info *qi) 238c2ecf20Sopenharmony_ci{ 248c2ecf20Sopenharmony_ci ath_dbg(ath9k_hw_common(ah), INTERRUPT, 258c2ecf20Sopenharmony_ci "tx ok 0x%x err 0x%x desc 0x%x eol 0x%x urn 0x%x\n", 268c2ecf20Sopenharmony_ci ah->txok_interrupt_mask, ah->txerr_interrupt_mask, 278c2ecf20Sopenharmony_ci ah->txdesc_interrupt_mask, ah->txeol_interrupt_mask, 288c2ecf20Sopenharmony_ci ah->txurn_interrupt_mask); 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci ENABLE_REGWRITE_BUFFER(ah); 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_IMR_S0, 338c2ecf20Sopenharmony_ci SM(ah->txok_interrupt_mask, AR_IMR_S0_QCU_TXOK) 348c2ecf20Sopenharmony_ci | SM(ah->txdesc_interrupt_mask, AR_IMR_S0_QCU_TXDESC)); 358c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_IMR_S1, 368c2ecf20Sopenharmony_ci SM(ah->txerr_interrupt_mask, AR_IMR_S1_QCU_TXERR) 378c2ecf20Sopenharmony_ci | SM(ah->txeol_interrupt_mask, AR_IMR_S1_QCU_TXEOL)); 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci ah->imrs2_reg &= ~AR_IMR_S2_QCU_TXURN; 408c2ecf20Sopenharmony_ci ah->imrs2_reg |= (ah->txurn_interrupt_mask & AR_IMR_S2_QCU_TXURN); 418c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg); 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci REGWRITE_BUFFER_FLUSH(ah); 448c2ecf20Sopenharmony_ci} 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ciu32 ath9k_hw_gettxbuf(struct ath_hw *ah, u32 q) 478c2ecf20Sopenharmony_ci{ 488c2ecf20Sopenharmony_ci return REG_READ(ah, AR_QTXDP(q)); 498c2ecf20Sopenharmony_ci} 508c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath9k_hw_gettxbuf); 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_civoid ath9k_hw_puttxbuf(struct ath_hw *ah, u32 q, u32 txdp) 538c2ecf20Sopenharmony_ci{ 548c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_QTXDP(q), txdp); 558c2ecf20Sopenharmony_ci} 568c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath9k_hw_puttxbuf); 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_civoid ath9k_hw_txstart(struct ath_hw *ah, u32 q) 598c2ecf20Sopenharmony_ci{ 608c2ecf20Sopenharmony_ci ath_dbg(ath9k_hw_common(ah), QUEUE, "Enable TXE on queue: %u\n", q); 618c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_Q_TXE, 1 << q); 628c2ecf20Sopenharmony_ci} 638c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath9k_hw_txstart); 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ciu32 ath9k_hw_numtxpending(struct ath_hw *ah, u32 q) 668c2ecf20Sopenharmony_ci{ 678c2ecf20Sopenharmony_ci u32 npend; 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci npend = REG_READ(ah, AR_QSTS(q)) & AR_Q_STS_PEND_FR_CNT; 708c2ecf20Sopenharmony_ci if (npend == 0) { 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci if (REG_READ(ah, AR_Q_TXE) & (1 << q)) 738c2ecf20Sopenharmony_ci npend = 1; 748c2ecf20Sopenharmony_ci } 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci return npend; 778c2ecf20Sopenharmony_ci} 788c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath9k_hw_numtxpending); 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci/** 818c2ecf20Sopenharmony_ci * ath9k_hw_updatetxtriglevel - adjusts the frame trigger level 828c2ecf20Sopenharmony_ci * 838c2ecf20Sopenharmony_ci * @ah: atheros hardware struct 848c2ecf20Sopenharmony_ci * @bIncTrigLevel: whether or not the frame trigger level should be updated 858c2ecf20Sopenharmony_ci * 868c2ecf20Sopenharmony_ci * The frame trigger level specifies the minimum number of bytes, 878c2ecf20Sopenharmony_ci * in units of 64 bytes, that must be DMA'ed into the PCU TX FIFO 888c2ecf20Sopenharmony_ci * before the PCU will initiate sending the frame on the air. This can 898c2ecf20Sopenharmony_ci * mean we initiate transmit before a full frame is on the PCU TX FIFO. 908c2ecf20Sopenharmony_ci * Resets to 0x1 (meaning 64 bytes or a full frame, whichever occurs 918c2ecf20Sopenharmony_ci * first) 928c2ecf20Sopenharmony_ci * 938c2ecf20Sopenharmony_ci * Caution must be taken to ensure to set the frame trigger level based 948c2ecf20Sopenharmony_ci * on the DMA request size. For example if the DMA request size is set to 958c2ecf20Sopenharmony_ci * 128 bytes the trigger level cannot exceed 6 * 64 = 384. This is because 968c2ecf20Sopenharmony_ci * there need to be enough space in the tx FIFO for the requested transfer 978c2ecf20Sopenharmony_ci * size. Hence the tx FIFO will stop with 512 - 128 = 384 bytes. If we set 988c2ecf20Sopenharmony_ci * the threshold to a value beyond 6, then the transmit will hang. 998c2ecf20Sopenharmony_ci * 1008c2ecf20Sopenharmony_ci * Current dual stream devices have a PCU TX FIFO size of 8 KB. 1018c2ecf20Sopenharmony_ci * Current single stream devices have a PCU TX FIFO size of 4 KB, however, 1028c2ecf20Sopenharmony_ci * there is a hardware issue which forces us to use 2 KB instead so the 1038c2ecf20Sopenharmony_ci * frame trigger level must not exceed 2 KB for these chipsets. 1048c2ecf20Sopenharmony_ci */ 1058c2ecf20Sopenharmony_cibool ath9k_hw_updatetxtriglevel(struct ath_hw *ah, bool bIncTrigLevel) 1068c2ecf20Sopenharmony_ci{ 1078c2ecf20Sopenharmony_ci u32 txcfg, curLevel, newLevel; 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_ci if (ah->tx_trig_level >= ah->config.max_txtrig_level) 1108c2ecf20Sopenharmony_ci return false; 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ci ath9k_hw_disable_interrupts(ah); 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ci txcfg = REG_READ(ah, AR_TXCFG); 1158c2ecf20Sopenharmony_ci curLevel = MS(txcfg, AR_FTRIG); 1168c2ecf20Sopenharmony_ci newLevel = curLevel; 1178c2ecf20Sopenharmony_ci if (bIncTrigLevel) { 1188c2ecf20Sopenharmony_ci if (curLevel < ah->config.max_txtrig_level) 1198c2ecf20Sopenharmony_ci newLevel++; 1208c2ecf20Sopenharmony_ci } else if (curLevel > MIN_TX_FIFO_THRESHOLD) 1218c2ecf20Sopenharmony_ci newLevel--; 1228c2ecf20Sopenharmony_ci if (newLevel != curLevel) 1238c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_TXCFG, 1248c2ecf20Sopenharmony_ci (txcfg & ~AR_FTRIG) | SM(newLevel, AR_FTRIG)); 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_ci ath9k_hw_enable_interrupts(ah); 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ci ah->tx_trig_level = newLevel; 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci return newLevel != curLevel; 1318c2ecf20Sopenharmony_ci} 1328c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath9k_hw_updatetxtriglevel); 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_civoid ath9k_hw_abort_tx_dma(struct ath_hw *ah) 1358c2ecf20Sopenharmony_ci{ 1368c2ecf20Sopenharmony_ci int maxdelay = 1000; 1378c2ecf20Sopenharmony_ci int i, q; 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ci if (ah->curchan) { 1408c2ecf20Sopenharmony_ci if (IS_CHAN_HALF_RATE(ah->curchan)) 1418c2ecf20Sopenharmony_ci maxdelay *= 2; 1428c2ecf20Sopenharmony_ci else if (IS_CHAN_QUARTER_RATE(ah->curchan)) 1438c2ecf20Sopenharmony_ci maxdelay *= 4; 1448c2ecf20Sopenharmony_ci } 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_Q_TXD, AR_Q_TXD_M); 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_PCU_MISC, AR_PCU_FORCE_QUIET_COLL | AR_PCU_CLEAR_VMF); 1498c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_FORCE_CH_IDLE_HIGH); 1508c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_D_GBL_IFS_MISC, AR_D_GBL_IFS_MISC_IGNORE_BACKOFF); 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_ci for (q = 0; q < AR_NUM_QCU; q++) { 1538c2ecf20Sopenharmony_ci for (i = 0; i < maxdelay; i++) { 1548c2ecf20Sopenharmony_ci if (i) 1558c2ecf20Sopenharmony_ci udelay(5); 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_ci if (!ath9k_hw_numtxpending(ah, q)) 1588c2ecf20Sopenharmony_ci break; 1598c2ecf20Sopenharmony_ci } 1608c2ecf20Sopenharmony_ci } 1618c2ecf20Sopenharmony_ci 1628c2ecf20Sopenharmony_ci REG_CLR_BIT(ah, AR_PCU_MISC, AR_PCU_FORCE_QUIET_COLL | AR_PCU_CLEAR_VMF); 1638c2ecf20Sopenharmony_ci REG_CLR_BIT(ah, AR_DIAG_SW, AR_DIAG_FORCE_CH_IDLE_HIGH); 1648c2ecf20Sopenharmony_ci REG_CLR_BIT(ah, AR_D_GBL_IFS_MISC, AR_D_GBL_IFS_MISC_IGNORE_BACKOFF); 1658c2ecf20Sopenharmony_ci 1668c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_Q_TXD, 0); 1678c2ecf20Sopenharmony_ci} 1688c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath9k_hw_abort_tx_dma); 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_cibool ath9k_hw_stop_dma_queue(struct ath_hw *ah, u32 q) 1718c2ecf20Sopenharmony_ci{ 1728c2ecf20Sopenharmony_ci#define ATH9K_TX_STOP_DMA_TIMEOUT 1000 /* usec */ 1738c2ecf20Sopenharmony_ci#define ATH9K_TIME_QUANTUM 100 /* usec */ 1748c2ecf20Sopenharmony_ci int wait_time = ATH9K_TX_STOP_DMA_TIMEOUT / ATH9K_TIME_QUANTUM; 1758c2ecf20Sopenharmony_ci int wait; 1768c2ecf20Sopenharmony_ci 1778c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_Q_TXD, 1 << q); 1788c2ecf20Sopenharmony_ci 1798c2ecf20Sopenharmony_ci for (wait = wait_time; wait != 0; wait--) { 1808c2ecf20Sopenharmony_ci if (wait != wait_time) 1818c2ecf20Sopenharmony_ci udelay(ATH9K_TIME_QUANTUM); 1828c2ecf20Sopenharmony_ci 1838c2ecf20Sopenharmony_ci if (ath9k_hw_numtxpending(ah, q) == 0) 1848c2ecf20Sopenharmony_ci break; 1858c2ecf20Sopenharmony_ci } 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_Q_TXD, 0); 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_ci return wait != 0; 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_ci#undef ATH9K_TX_STOP_DMA_TIMEOUT 1928c2ecf20Sopenharmony_ci#undef ATH9K_TIME_QUANTUM 1938c2ecf20Sopenharmony_ci} 1948c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath9k_hw_stop_dma_queue); 1958c2ecf20Sopenharmony_ci 1968c2ecf20Sopenharmony_cibool ath9k_hw_set_txq_props(struct ath_hw *ah, int q, 1978c2ecf20Sopenharmony_ci const struct ath9k_tx_queue_info *qinfo) 1988c2ecf20Sopenharmony_ci{ 1998c2ecf20Sopenharmony_ci u32 cw; 2008c2ecf20Sopenharmony_ci struct ath_common *common = ath9k_hw_common(ah); 2018c2ecf20Sopenharmony_ci struct ath9k_tx_queue_info *qi; 2028c2ecf20Sopenharmony_ci 2038c2ecf20Sopenharmony_ci qi = &ah->txq[q]; 2048c2ecf20Sopenharmony_ci if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) { 2058c2ecf20Sopenharmony_ci ath_dbg(common, QUEUE, 2068c2ecf20Sopenharmony_ci "Set TXQ properties, inactive queue: %u\n", q); 2078c2ecf20Sopenharmony_ci return false; 2088c2ecf20Sopenharmony_ci } 2098c2ecf20Sopenharmony_ci 2108c2ecf20Sopenharmony_ci ath_dbg(common, QUEUE, "Set queue properties for: %u\n", q); 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_ci qi->tqi_ver = qinfo->tqi_ver; 2138c2ecf20Sopenharmony_ci qi->tqi_subtype = qinfo->tqi_subtype; 2148c2ecf20Sopenharmony_ci qi->tqi_qflags = qinfo->tqi_qflags; 2158c2ecf20Sopenharmony_ci qi->tqi_priority = qinfo->tqi_priority; 2168c2ecf20Sopenharmony_ci if (qinfo->tqi_aifs != ATH9K_TXQ_USEDEFAULT) 2178c2ecf20Sopenharmony_ci qi->tqi_aifs = min(qinfo->tqi_aifs, 255U); 2188c2ecf20Sopenharmony_ci else 2198c2ecf20Sopenharmony_ci qi->tqi_aifs = INIT_AIFS; 2208c2ecf20Sopenharmony_ci if (qinfo->tqi_cwmin != ATH9K_TXQ_USEDEFAULT) { 2218c2ecf20Sopenharmony_ci cw = min(qinfo->tqi_cwmin, 1024U); 2228c2ecf20Sopenharmony_ci qi->tqi_cwmin = 1; 2238c2ecf20Sopenharmony_ci while (qi->tqi_cwmin < cw) 2248c2ecf20Sopenharmony_ci qi->tqi_cwmin = (qi->tqi_cwmin << 1) | 1; 2258c2ecf20Sopenharmony_ci } else 2268c2ecf20Sopenharmony_ci qi->tqi_cwmin = qinfo->tqi_cwmin; 2278c2ecf20Sopenharmony_ci if (qinfo->tqi_cwmax != ATH9K_TXQ_USEDEFAULT) { 2288c2ecf20Sopenharmony_ci cw = min(qinfo->tqi_cwmax, 1024U); 2298c2ecf20Sopenharmony_ci qi->tqi_cwmax = 1; 2308c2ecf20Sopenharmony_ci while (qi->tqi_cwmax < cw) 2318c2ecf20Sopenharmony_ci qi->tqi_cwmax = (qi->tqi_cwmax << 1) | 1; 2328c2ecf20Sopenharmony_ci } else 2338c2ecf20Sopenharmony_ci qi->tqi_cwmax = INIT_CWMAX; 2348c2ecf20Sopenharmony_ci 2358c2ecf20Sopenharmony_ci if (qinfo->tqi_shretry != 0) 2368c2ecf20Sopenharmony_ci qi->tqi_shretry = min((u32) qinfo->tqi_shretry, 15U); 2378c2ecf20Sopenharmony_ci else 2388c2ecf20Sopenharmony_ci qi->tqi_shretry = INIT_SH_RETRY; 2398c2ecf20Sopenharmony_ci if (qinfo->tqi_lgretry != 0) 2408c2ecf20Sopenharmony_ci qi->tqi_lgretry = min((u32) qinfo->tqi_lgretry, 15U); 2418c2ecf20Sopenharmony_ci else 2428c2ecf20Sopenharmony_ci qi->tqi_lgretry = INIT_LG_RETRY; 2438c2ecf20Sopenharmony_ci qi->tqi_cbrPeriod = qinfo->tqi_cbrPeriod; 2448c2ecf20Sopenharmony_ci qi->tqi_cbrOverflowLimit = qinfo->tqi_cbrOverflowLimit; 2458c2ecf20Sopenharmony_ci qi->tqi_burstTime = qinfo->tqi_burstTime; 2468c2ecf20Sopenharmony_ci qi->tqi_readyTime = qinfo->tqi_readyTime; 2478c2ecf20Sopenharmony_ci 2488c2ecf20Sopenharmony_ci switch (qinfo->tqi_subtype) { 2498c2ecf20Sopenharmony_ci case ATH9K_WME_UPSD: 2508c2ecf20Sopenharmony_ci if (qi->tqi_type == ATH9K_TX_QUEUE_DATA) 2518c2ecf20Sopenharmony_ci qi->tqi_intFlags = ATH9K_TXQ_USE_LOCKOUT_BKOFF_DIS; 2528c2ecf20Sopenharmony_ci break; 2538c2ecf20Sopenharmony_ci default: 2548c2ecf20Sopenharmony_ci break; 2558c2ecf20Sopenharmony_ci } 2568c2ecf20Sopenharmony_ci 2578c2ecf20Sopenharmony_ci return true; 2588c2ecf20Sopenharmony_ci} 2598c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath9k_hw_set_txq_props); 2608c2ecf20Sopenharmony_ci 2618c2ecf20Sopenharmony_cibool ath9k_hw_get_txq_props(struct ath_hw *ah, int q, 2628c2ecf20Sopenharmony_ci struct ath9k_tx_queue_info *qinfo) 2638c2ecf20Sopenharmony_ci{ 2648c2ecf20Sopenharmony_ci struct ath_common *common = ath9k_hw_common(ah); 2658c2ecf20Sopenharmony_ci struct ath9k_tx_queue_info *qi; 2668c2ecf20Sopenharmony_ci 2678c2ecf20Sopenharmony_ci qi = &ah->txq[q]; 2688c2ecf20Sopenharmony_ci if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) { 2698c2ecf20Sopenharmony_ci ath_dbg(common, QUEUE, 2708c2ecf20Sopenharmony_ci "Get TXQ properties, inactive queue: %u\n", q); 2718c2ecf20Sopenharmony_ci return false; 2728c2ecf20Sopenharmony_ci } 2738c2ecf20Sopenharmony_ci 2748c2ecf20Sopenharmony_ci qinfo->tqi_qflags = qi->tqi_qflags; 2758c2ecf20Sopenharmony_ci qinfo->tqi_ver = qi->tqi_ver; 2768c2ecf20Sopenharmony_ci qinfo->tqi_subtype = qi->tqi_subtype; 2778c2ecf20Sopenharmony_ci qinfo->tqi_qflags = qi->tqi_qflags; 2788c2ecf20Sopenharmony_ci qinfo->tqi_priority = qi->tqi_priority; 2798c2ecf20Sopenharmony_ci qinfo->tqi_aifs = qi->tqi_aifs; 2808c2ecf20Sopenharmony_ci qinfo->tqi_cwmin = qi->tqi_cwmin; 2818c2ecf20Sopenharmony_ci qinfo->tqi_cwmax = qi->tqi_cwmax; 2828c2ecf20Sopenharmony_ci qinfo->tqi_shretry = qi->tqi_shretry; 2838c2ecf20Sopenharmony_ci qinfo->tqi_lgretry = qi->tqi_lgretry; 2848c2ecf20Sopenharmony_ci qinfo->tqi_cbrPeriod = qi->tqi_cbrPeriod; 2858c2ecf20Sopenharmony_ci qinfo->tqi_cbrOverflowLimit = qi->tqi_cbrOverflowLimit; 2868c2ecf20Sopenharmony_ci qinfo->tqi_burstTime = qi->tqi_burstTime; 2878c2ecf20Sopenharmony_ci qinfo->tqi_readyTime = qi->tqi_readyTime; 2888c2ecf20Sopenharmony_ci 2898c2ecf20Sopenharmony_ci return true; 2908c2ecf20Sopenharmony_ci} 2918c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath9k_hw_get_txq_props); 2928c2ecf20Sopenharmony_ci 2938c2ecf20Sopenharmony_ciint ath9k_hw_setuptxqueue(struct ath_hw *ah, enum ath9k_tx_queue type, 2948c2ecf20Sopenharmony_ci const struct ath9k_tx_queue_info *qinfo) 2958c2ecf20Sopenharmony_ci{ 2968c2ecf20Sopenharmony_ci struct ath_common *common = ath9k_hw_common(ah); 2978c2ecf20Sopenharmony_ci struct ath9k_tx_queue_info *qi; 2988c2ecf20Sopenharmony_ci int q; 2998c2ecf20Sopenharmony_ci 3008c2ecf20Sopenharmony_ci switch (type) { 3018c2ecf20Sopenharmony_ci case ATH9K_TX_QUEUE_BEACON: 3028c2ecf20Sopenharmony_ci q = ATH9K_NUM_TX_QUEUES - 1; 3038c2ecf20Sopenharmony_ci break; 3048c2ecf20Sopenharmony_ci case ATH9K_TX_QUEUE_CAB: 3058c2ecf20Sopenharmony_ci q = ATH9K_NUM_TX_QUEUES - 2; 3068c2ecf20Sopenharmony_ci break; 3078c2ecf20Sopenharmony_ci case ATH9K_TX_QUEUE_PSPOLL: 3088c2ecf20Sopenharmony_ci q = 1; 3098c2ecf20Sopenharmony_ci break; 3108c2ecf20Sopenharmony_ci case ATH9K_TX_QUEUE_UAPSD: 3118c2ecf20Sopenharmony_ci q = ATH9K_NUM_TX_QUEUES - 3; 3128c2ecf20Sopenharmony_ci break; 3138c2ecf20Sopenharmony_ci case ATH9K_TX_QUEUE_DATA: 3148c2ecf20Sopenharmony_ci q = qinfo->tqi_subtype; 3158c2ecf20Sopenharmony_ci break; 3168c2ecf20Sopenharmony_ci default: 3178c2ecf20Sopenharmony_ci ath_err(common, "Invalid TX queue type: %u\n", type); 3188c2ecf20Sopenharmony_ci return -1; 3198c2ecf20Sopenharmony_ci } 3208c2ecf20Sopenharmony_ci 3218c2ecf20Sopenharmony_ci ath_dbg(common, QUEUE, "Setup TX queue: %u\n", q); 3228c2ecf20Sopenharmony_ci 3238c2ecf20Sopenharmony_ci qi = &ah->txq[q]; 3248c2ecf20Sopenharmony_ci if (qi->tqi_type != ATH9K_TX_QUEUE_INACTIVE) { 3258c2ecf20Sopenharmony_ci ath_err(common, "TX queue: %u already active\n", q); 3268c2ecf20Sopenharmony_ci return -1; 3278c2ecf20Sopenharmony_ci } 3288c2ecf20Sopenharmony_ci memset(qi, 0, sizeof(struct ath9k_tx_queue_info)); 3298c2ecf20Sopenharmony_ci qi->tqi_type = type; 3308c2ecf20Sopenharmony_ci qi->tqi_physCompBuf = qinfo->tqi_physCompBuf; 3318c2ecf20Sopenharmony_ci (void) ath9k_hw_set_txq_props(ah, q, qinfo); 3328c2ecf20Sopenharmony_ci 3338c2ecf20Sopenharmony_ci return q; 3348c2ecf20Sopenharmony_ci} 3358c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath9k_hw_setuptxqueue); 3368c2ecf20Sopenharmony_ci 3378c2ecf20Sopenharmony_cistatic void ath9k_hw_clear_queue_interrupts(struct ath_hw *ah, u32 q) 3388c2ecf20Sopenharmony_ci{ 3398c2ecf20Sopenharmony_ci ah->txok_interrupt_mask &= ~(1 << q); 3408c2ecf20Sopenharmony_ci ah->txerr_interrupt_mask &= ~(1 << q); 3418c2ecf20Sopenharmony_ci ah->txdesc_interrupt_mask &= ~(1 << q); 3428c2ecf20Sopenharmony_ci ah->txeol_interrupt_mask &= ~(1 << q); 3438c2ecf20Sopenharmony_ci ah->txurn_interrupt_mask &= ~(1 << q); 3448c2ecf20Sopenharmony_ci} 3458c2ecf20Sopenharmony_ci 3468c2ecf20Sopenharmony_cibool ath9k_hw_releasetxqueue(struct ath_hw *ah, u32 q) 3478c2ecf20Sopenharmony_ci{ 3488c2ecf20Sopenharmony_ci struct ath_common *common = ath9k_hw_common(ah); 3498c2ecf20Sopenharmony_ci struct ath9k_tx_queue_info *qi; 3508c2ecf20Sopenharmony_ci 3518c2ecf20Sopenharmony_ci qi = &ah->txq[q]; 3528c2ecf20Sopenharmony_ci if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) { 3538c2ecf20Sopenharmony_ci ath_dbg(common, QUEUE, "Release TXQ, inactive queue: %u\n", q); 3548c2ecf20Sopenharmony_ci return false; 3558c2ecf20Sopenharmony_ci } 3568c2ecf20Sopenharmony_ci 3578c2ecf20Sopenharmony_ci ath_dbg(common, QUEUE, "Release TX queue: %u\n", q); 3588c2ecf20Sopenharmony_ci 3598c2ecf20Sopenharmony_ci qi->tqi_type = ATH9K_TX_QUEUE_INACTIVE; 3608c2ecf20Sopenharmony_ci ath9k_hw_clear_queue_interrupts(ah, q); 3618c2ecf20Sopenharmony_ci ath9k_hw_set_txq_interrupts(ah, qi); 3628c2ecf20Sopenharmony_ci 3638c2ecf20Sopenharmony_ci return true; 3648c2ecf20Sopenharmony_ci} 3658c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath9k_hw_releasetxqueue); 3668c2ecf20Sopenharmony_ci 3678c2ecf20Sopenharmony_cibool ath9k_hw_resettxqueue(struct ath_hw *ah, u32 q) 3688c2ecf20Sopenharmony_ci{ 3698c2ecf20Sopenharmony_ci struct ath_common *common = ath9k_hw_common(ah); 3708c2ecf20Sopenharmony_ci struct ath9k_tx_queue_info *qi; 3718c2ecf20Sopenharmony_ci u32 cwMin, chanCwMin, value; 3728c2ecf20Sopenharmony_ci 3738c2ecf20Sopenharmony_ci qi = &ah->txq[q]; 3748c2ecf20Sopenharmony_ci if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) { 3758c2ecf20Sopenharmony_ci ath_dbg(common, QUEUE, "Reset TXQ, inactive queue: %u\n", q); 3768c2ecf20Sopenharmony_ci return true; 3778c2ecf20Sopenharmony_ci } 3788c2ecf20Sopenharmony_ci 3798c2ecf20Sopenharmony_ci ath_dbg(common, QUEUE, "Reset TX queue: %u\n", q); 3808c2ecf20Sopenharmony_ci 3818c2ecf20Sopenharmony_ci if (qi->tqi_cwmin == ATH9K_TXQ_USEDEFAULT) { 3828c2ecf20Sopenharmony_ci chanCwMin = INIT_CWMIN; 3838c2ecf20Sopenharmony_ci 3848c2ecf20Sopenharmony_ci for (cwMin = 1; cwMin < chanCwMin; cwMin = (cwMin << 1) | 1); 3858c2ecf20Sopenharmony_ci } else 3868c2ecf20Sopenharmony_ci cwMin = qi->tqi_cwmin; 3878c2ecf20Sopenharmony_ci 3888c2ecf20Sopenharmony_ci ENABLE_REGWRITE_BUFFER(ah); 3898c2ecf20Sopenharmony_ci 3908c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_DLCL_IFS(q), 3918c2ecf20Sopenharmony_ci SM(cwMin, AR_D_LCL_IFS_CWMIN) | 3928c2ecf20Sopenharmony_ci SM(qi->tqi_cwmax, AR_D_LCL_IFS_CWMAX) | 3938c2ecf20Sopenharmony_ci SM(qi->tqi_aifs, AR_D_LCL_IFS_AIFS)); 3948c2ecf20Sopenharmony_ci 3958c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_DRETRY_LIMIT(q), 3968c2ecf20Sopenharmony_ci SM(INIT_SSH_RETRY, AR_D_RETRY_LIMIT_STA_SH) | 3978c2ecf20Sopenharmony_ci SM(INIT_SLG_RETRY, AR_D_RETRY_LIMIT_STA_LG) | 3988c2ecf20Sopenharmony_ci SM(qi->tqi_shretry, AR_D_RETRY_LIMIT_FR_SH)); 3998c2ecf20Sopenharmony_ci 4008c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_QMISC(q), AR_Q_MISC_DCU_EARLY_TERM_REQ); 4018c2ecf20Sopenharmony_ci 4028c2ecf20Sopenharmony_ci if (AR_SREV_9340(ah) && !AR_SREV_9340_13_OR_LATER(ah)) 4038c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_DMISC(q), 4048c2ecf20Sopenharmony_ci AR_D_MISC_CW_BKOFF_EN | AR_D_MISC_FRAG_WAIT_EN | 0x1); 4058c2ecf20Sopenharmony_ci else 4068c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_DMISC(q), 4078c2ecf20Sopenharmony_ci AR_D_MISC_CW_BKOFF_EN | AR_D_MISC_FRAG_WAIT_EN | 0x2); 4088c2ecf20Sopenharmony_ci 4098c2ecf20Sopenharmony_ci if (qi->tqi_cbrPeriod) { 4108c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_QCBRCFG(q), 4118c2ecf20Sopenharmony_ci SM(qi->tqi_cbrPeriod, AR_Q_CBRCFG_INTERVAL) | 4128c2ecf20Sopenharmony_ci SM(qi->tqi_cbrOverflowLimit, AR_Q_CBRCFG_OVF_THRESH)); 4138c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_QMISC(q), AR_Q_MISC_FSP_CBR | 4148c2ecf20Sopenharmony_ci (qi->tqi_cbrOverflowLimit ? 4158c2ecf20Sopenharmony_ci AR_Q_MISC_CBR_EXP_CNTR_LIMIT_EN : 0)); 4168c2ecf20Sopenharmony_ci } 4178c2ecf20Sopenharmony_ci if (qi->tqi_readyTime && (qi->tqi_type != ATH9K_TX_QUEUE_CAB)) { 4188c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_QRDYTIMECFG(q), 4198c2ecf20Sopenharmony_ci SM(qi->tqi_readyTime, AR_Q_RDYTIMECFG_DURATION) | 4208c2ecf20Sopenharmony_ci AR_Q_RDYTIMECFG_EN); 4218c2ecf20Sopenharmony_ci } 4228c2ecf20Sopenharmony_ci 4238c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_DCHNTIME(q), 4248c2ecf20Sopenharmony_ci SM(qi->tqi_burstTime, AR_D_CHNTIME_DUR) | 4258c2ecf20Sopenharmony_ci (qi->tqi_burstTime ? AR_D_CHNTIME_EN : 0)); 4268c2ecf20Sopenharmony_ci 4278c2ecf20Sopenharmony_ci if (qi->tqi_burstTime 4288c2ecf20Sopenharmony_ci && (qi->tqi_qflags & TXQ_FLAG_RDYTIME_EXP_POLICY_ENABLE)) 4298c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_QMISC(q), AR_Q_MISC_RDYTIME_EXP_POLICY); 4308c2ecf20Sopenharmony_ci 4318c2ecf20Sopenharmony_ci if (qi->tqi_qflags & TXQ_FLAG_BACKOFF_DISABLE) 4328c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_DMISC(q), AR_D_MISC_POST_FR_BKOFF_DIS); 4338c2ecf20Sopenharmony_ci 4348c2ecf20Sopenharmony_ci REGWRITE_BUFFER_FLUSH(ah); 4358c2ecf20Sopenharmony_ci 4368c2ecf20Sopenharmony_ci if (qi->tqi_qflags & TXQ_FLAG_FRAG_BURST_BACKOFF_ENABLE) 4378c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_DMISC(q), AR_D_MISC_FRAG_BKOFF_EN); 4388c2ecf20Sopenharmony_ci 4398c2ecf20Sopenharmony_ci switch (qi->tqi_type) { 4408c2ecf20Sopenharmony_ci case ATH9K_TX_QUEUE_BEACON: 4418c2ecf20Sopenharmony_ci ENABLE_REGWRITE_BUFFER(ah); 4428c2ecf20Sopenharmony_ci 4438c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_QMISC(q), 4448c2ecf20Sopenharmony_ci AR_Q_MISC_FSP_DBA_GATED 4458c2ecf20Sopenharmony_ci | AR_Q_MISC_BEACON_USE 4468c2ecf20Sopenharmony_ci | AR_Q_MISC_CBR_INCR_DIS1); 4478c2ecf20Sopenharmony_ci 4488c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_DMISC(q), 4498c2ecf20Sopenharmony_ci (AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL << 4508c2ecf20Sopenharmony_ci AR_D_MISC_ARB_LOCKOUT_CNTRL_S) 4518c2ecf20Sopenharmony_ci | AR_D_MISC_BEACON_USE 4528c2ecf20Sopenharmony_ci | AR_D_MISC_POST_FR_BKOFF_DIS); 4538c2ecf20Sopenharmony_ci 4548c2ecf20Sopenharmony_ci REGWRITE_BUFFER_FLUSH(ah); 4558c2ecf20Sopenharmony_ci 4568c2ecf20Sopenharmony_ci /* 4578c2ecf20Sopenharmony_ci * cwmin and cwmax should be 0 for beacon queue 4588c2ecf20Sopenharmony_ci * but not for IBSS as we would create an imbalance 4598c2ecf20Sopenharmony_ci * on beaconing fairness for participating nodes. 4608c2ecf20Sopenharmony_ci */ 4618c2ecf20Sopenharmony_ci if (AR_SREV_9300_20_OR_LATER(ah) && 4628c2ecf20Sopenharmony_ci ah->opmode != NL80211_IFTYPE_ADHOC) { 4638c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_DLCL_IFS(q), SM(0, AR_D_LCL_IFS_CWMIN) 4648c2ecf20Sopenharmony_ci | SM(0, AR_D_LCL_IFS_CWMAX) 4658c2ecf20Sopenharmony_ci | SM(qi->tqi_aifs, AR_D_LCL_IFS_AIFS)); 4668c2ecf20Sopenharmony_ci } 4678c2ecf20Sopenharmony_ci break; 4688c2ecf20Sopenharmony_ci case ATH9K_TX_QUEUE_CAB: 4698c2ecf20Sopenharmony_ci ENABLE_REGWRITE_BUFFER(ah); 4708c2ecf20Sopenharmony_ci 4718c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_QMISC(q), 4728c2ecf20Sopenharmony_ci AR_Q_MISC_FSP_DBA_GATED 4738c2ecf20Sopenharmony_ci | AR_Q_MISC_CBR_INCR_DIS1 4748c2ecf20Sopenharmony_ci | AR_Q_MISC_CBR_INCR_DIS0); 4758c2ecf20Sopenharmony_ci value = (qi->tqi_readyTime - 4768c2ecf20Sopenharmony_ci (ah->config.sw_beacon_response_time - 4778c2ecf20Sopenharmony_ci ah->config.dma_beacon_response_time)) * 1024; 4788c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_QRDYTIMECFG(q), 4798c2ecf20Sopenharmony_ci value | AR_Q_RDYTIMECFG_EN); 4808c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_DMISC(q), 4818c2ecf20Sopenharmony_ci (AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL << 4828c2ecf20Sopenharmony_ci AR_D_MISC_ARB_LOCKOUT_CNTRL_S)); 4838c2ecf20Sopenharmony_ci 4848c2ecf20Sopenharmony_ci REGWRITE_BUFFER_FLUSH(ah); 4858c2ecf20Sopenharmony_ci 4868c2ecf20Sopenharmony_ci break; 4878c2ecf20Sopenharmony_ci case ATH9K_TX_QUEUE_PSPOLL: 4888c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_QMISC(q), AR_Q_MISC_CBR_INCR_DIS1); 4898c2ecf20Sopenharmony_ci break; 4908c2ecf20Sopenharmony_ci case ATH9K_TX_QUEUE_UAPSD: 4918c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_DMISC(q), AR_D_MISC_POST_FR_BKOFF_DIS); 4928c2ecf20Sopenharmony_ci break; 4938c2ecf20Sopenharmony_ci default: 4948c2ecf20Sopenharmony_ci break; 4958c2ecf20Sopenharmony_ci } 4968c2ecf20Sopenharmony_ci 4978c2ecf20Sopenharmony_ci if (qi->tqi_intFlags & ATH9K_TXQ_USE_LOCKOUT_BKOFF_DIS) { 4988c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_DMISC(q), 4998c2ecf20Sopenharmony_ci SM(AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL, 5008c2ecf20Sopenharmony_ci AR_D_MISC_ARB_LOCKOUT_CNTRL) | 5018c2ecf20Sopenharmony_ci AR_D_MISC_POST_FR_BKOFF_DIS); 5028c2ecf20Sopenharmony_ci } 5038c2ecf20Sopenharmony_ci 5048c2ecf20Sopenharmony_ci if (AR_SREV_9300_20_OR_LATER(ah)) 5058c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_Q_DESC_CRCCHK, AR_Q_DESC_CRCCHK_EN); 5068c2ecf20Sopenharmony_ci 5078c2ecf20Sopenharmony_ci ath9k_hw_clear_queue_interrupts(ah, q); 5088c2ecf20Sopenharmony_ci if (qi->tqi_qflags & TXQ_FLAG_TXINT_ENABLE) { 5098c2ecf20Sopenharmony_ci ah->txok_interrupt_mask |= 1 << q; 5108c2ecf20Sopenharmony_ci ah->txerr_interrupt_mask |= 1 << q; 5118c2ecf20Sopenharmony_ci } 5128c2ecf20Sopenharmony_ci if (qi->tqi_qflags & TXQ_FLAG_TXDESCINT_ENABLE) 5138c2ecf20Sopenharmony_ci ah->txdesc_interrupt_mask |= 1 << q; 5148c2ecf20Sopenharmony_ci if (qi->tqi_qflags & TXQ_FLAG_TXEOLINT_ENABLE) 5158c2ecf20Sopenharmony_ci ah->txeol_interrupt_mask |= 1 << q; 5168c2ecf20Sopenharmony_ci if (qi->tqi_qflags & TXQ_FLAG_TXURNINT_ENABLE) 5178c2ecf20Sopenharmony_ci ah->txurn_interrupt_mask |= 1 << q; 5188c2ecf20Sopenharmony_ci ath9k_hw_set_txq_interrupts(ah, qi); 5198c2ecf20Sopenharmony_ci 5208c2ecf20Sopenharmony_ci return true; 5218c2ecf20Sopenharmony_ci} 5228c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath9k_hw_resettxqueue); 5238c2ecf20Sopenharmony_ci 5248c2ecf20Sopenharmony_ciint ath9k_hw_rxprocdesc(struct ath_hw *ah, struct ath_desc *ds, 5258c2ecf20Sopenharmony_ci struct ath_rx_status *rs) 5268c2ecf20Sopenharmony_ci{ 5278c2ecf20Sopenharmony_ci struct ar5416_desc ads; 5288c2ecf20Sopenharmony_ci struct ar5416_desc *adsp = AR5416DESC(ds); 5298c2ecf20Sopenharmony_ci u32 phyerr; 5308c2ecf20Sopenharmony_ci 5318c2ecf20Sopenharmony_ci if ((adsp->ds_rxstatus8 & AR_RxDone) == 0) 5328c2ecf20Sopenharmony_ci return -EINPROGRESS; 5338c2ecf20Sopenharmony_ci 5348c2ecf20Sopenharmony_ci ads.u.rx = adsp->u.rx; 5358c2ecf20Sopenharmony_ci 5368c2ecf20Sopenharmony_ci rs->rs_status = 0; 5378c2ecf20Sopenharmony_ci rs->rs_flags = 0; 5388c2ecf20Sopenharmony_ci rs->enc_flags = 0; 5398c2ecf20Sopenharmony_ci rs->bw = RATE_INFO_BW_20; 5408c2ecf20Sopenharmony_ci 5418c2ecf20Sopenharmony_ci rs->rs_datalen = ads.ds_rxstatus1 & AR_DataLen; 5428c2ecf20Sopenharmony_ci rs->rs_tstamp = ads.AR_RcvTimestamp; 5438c2ecf20Sopenharmony_ci 5448c2ecf20Sopenharmony_ci if (ads.ds_rxstatus8 & AR_PostDelimCRCErr) { 5458c2ecf20Sopenharmony_ci rs->rs_rssi = ATH9K_RSSI_BAD; 5468c2ecf20Sopenharmony_ci rs->rs_rssi_ctl[0] = ATH9K_RSSI_BAD; 5478c2ecf20Sopenharmony_ci rs->rs_rssi_ctl[1] = ATH9K_RSSI_BAD; 5488c2ecf20Sopenharmony_ci rs->rs_rssi_ctl[2] = ATH9K_RSSI_BAD; 5498c2ecf20Sopenharmony_ci rs->rs_rssi_ext[0] = ATH9K_RSSI_BAD; 5508c2ecf20Sopenharmony_ci rs->rs_rssi_ext[1] = ATH9K_RSSI_BAD; 5518c2ecf20Sopenharmony_ci rs->rs_rssi_ext[2] = ATH9K_RSSI_BAD; 5528c2ecf20Sopenharmony_ci } else { 5538c2ecf20Sopenharmony_ci rs->rs_rssi = MS(ads.ds_rxstatus4, AR_RxRSSICombined); 5548c2ecf20Sopenharmony_ci rs->rs_rssi_ctl[0] = MS(ads.ds_rxstatus0, 5558c2ecf20Sopenharmony_ci AR_RxRSSIAnt00); 5568c2ecf20Sopenharmony_ci rs->rs_rssi_ctl[1] = MS(ads.ds_rxstatus0, 5578c2ecf20Sopenharmony_ci AR_RxRSSIAnt01); 5588c2ecf20Sopenharmony_ci rs->rs_rssi_ctl[2] = MS(ads.ds_rxstatus0, 5598c2ecf20Sopenharmony_ci AR_RxRSSIAnt02); 5608c2ecf20Sopenharmony_ci rs->rs_rssi_ext[0] = MS(ads.ds_rxstatus4, 5618c2ecf20Sopenharmony_ci AR_RxRSSIAnt10); 5628c2ecf20Sopenharmony_ci rs->rs_rssi_ext[1] = MS(ads.ds_rxstatus4, 5638c2ecf20Sopenharmony_ci AR_RxRSSIAnt11); 5648c2ecf20Sopenharmony_ci rs->rs_rssi_ext[2] = MS(ads.ds_rxstatus4, 5658c2ecf20Sopenharmony_ci AR_RxRSSIAnt12); 5668c2ecf20Sopenharmony_ci } 5678c2ecf20Sopenharmony_ci if (ads.ds_rxstatus8 & AR_RxKeyIdxValid) 5688c2ecf20Sopenharmony_ci rs->rs_keyix = MS(ads.ds_rxstatus8, AR_KeyIdx); 5698c2ecf20Sopenharmony_ci else 5708c2ecf20Sopenharmony_ci rs->rs_keyix = ATH9K_RXKEYIX_INVALID; 5718c2ecf20Sopenharmony_ci 5728c2ecf20Sopenharmony_ci rs->rs_rate = MS(ads.ds_rxstatus0, AR_RxRate); 5738c2ecf20Sopenharmony_ci rs->rs_more = (ads.ds_rxstatus1 & AR_RxMore) ? 1 : 0; 5748c2ecf20Sopenharmony_ci 5758c2ecf20Sopenharmony_ci rs->rs_firstaggr = (ads.ds_rxstatus8 & AR_RxFirstAggr) ? 1 : 0; 5768c2ecf20Sopenharmony_ci rs->rs_isaggr = (ads.ds_rxstatus8 & AR_RxAggr) ? 1 : 0; 5778c2ecf20Sopenharmony_ci rs->rs_moreaggr = (ads.ds_rxstatus8 & AR_RxMoreAggr) ? 1 : 0; 5788c2ecf20Sopenharmony_ci rs->rs_antenna = MS(ads.ds_rxstatus3, AR_RxAntenna); 5798c2ecf20Sopenharmony_ci 5808c2ecf20Sopenharmony_ci /* directly mapped flags for ieee80211_rx_status */ 5818c2ecf20Sopenharmony_ci rs->enc_flags |= 5828c2ecf20Sopenharmony_ci (ads.ds_rxstatus3 & AR_GI) ? RX_ENC_FLAG_SHORT_GI : 0; 5838c2ecf20Sopenharmony_ci rs->bw = (ads.ds_rxstatus3 & AR_2040) ? RATE_INFO_BW_40 : 5848c2ecf20Sopenharmony_ci RATE_INFO_BW_20; 5858c2ecf20Sopenharmony_ci if (AR_SREV_9280_20_OR_LATER(ah)) 5868c2ecf20Sopenharmony_ci rs->enc_flags |= 5878c2ecf20Sopenharmony_ci (ads.ds_rxstatus3 & AR_STBC) ? 5888c2ecf20Sopenharmony_ci /* we can only Nss=1 STBC */ 5898c2ecf20Sopenharmony_ci (1 << RX_ENC_FLAG_STBC_SHIFT) : 0; 5908c2ecf20Sopenharmony_ci 5918c2ecf20Sopenharmony_ci if (ads.ds_rxstatus8 & AR_PreDelimCRCErr) 5928c2ecf20Sopenharmony_ci rs->rs_flags |= ATH9K_RX_DELIM_CRC_PRE; 5938c2ecf20Sopenharmony_ci if (ads.ds_rxstatus8 & AR_PostDelimCRCErr) 5948c2ecf20Sopenharmony_ci rs->rs_flags |= ATH9K_RX_DELIM_CRC_POST; 5958c2ecf20Sopenharmony_ci if (ads.ds_rxstatus8 & AR_DecryptBusyErr) 5968c2ecf20Sopenharmony_ci rs->rs_flags |= ATH9K_RX_DECRYPT_BUSY; 5978c2ecf20Sopenharmony_ci 5988c2ecf20Sopenharmony_ci if ((ads.ds_rxstatus8 & AR_RxFrameOK) == 0) { 5998c2ecf20Sopenharmony_ci /* 6008c2ecf20Sopenharmony_ci * Treat these errors as mutually exclusive to avoid spurious 6018c2ecf20Sopenharmony_ci * extra error reports from the hardware. If a CRC error is 6028c2ecf20Sopenharmony_ci * reported, then decryption and MIC errors are irrelevant, 6038c2ecf20Sopenharmony_ci * the frame is going to be dropped either way 6048c2ecf20Sopenharmony_ci */ 6058c2ecf20Sopenharmony_ci if (ads.ds_rxstatus8 & AR_PHYErr) { 6068c2ecf20Sopenharmony_ci rs->rs_status |= ATH9K_RXERR_PHY; 6078c2ecf20Sopenharmony_ci phyerr = MS(ads.ds_rxstatus8, AR_PHYErrCode); 6088c2ecf20Sopenharmony_ci rs->rs_phyerr = phyerr; 6098c2ecf20Sopenharmony_ci } else if (ads.ds_rxstatus8 & AR_CRCErr) 6108c2ecf20Sopenharmony_ci rs->rs_status |= ATH9K_RXERR_CRC; 6118c2ecf20Sopenharmony_ci else if (ads.ds_rxstatus8 & AR_DecryptCRCErr) 6128c2ecf20Sopenharmony_ci rs->rs_status |= ATH9K_RXERR_DECRYPT; 6138c2ecf20Sopenharmony_ci else if (ads.ds_rxstatus8 & AR_MichaelErr) 6148c2ecf20Sopenharmony_ci rs->rs_status |= ATH9K_RXERR_MIC; 6158c2ecf20Sopenharmony_ci } else { 6168c2ecf20Sopenharmony_ci if (ads.ds_rxstatus8 & 6178c2ecf20Sopenharmony_ci (AR_CRCErr | AR_PHYErr | AR_DecryptCRCErr | AR_MichaelErr)) 6188c2ecf20Sopenharmony_ci rs->rs_status |= ATH9K_RXERR_CORRUPT_DESC; 6198c2ecf20Sopenharmony_ci 6208c2ecf20Sopenharmony_ci /* Only up to MCS16 supported, everything above is invalid */ 6218c2ecf20Sopenharmony_ci if (rs->rs_rate >= 0x90) 6228c2ecf20Sopenharmony_ci rs->rs_status |= ATH9K_RXERR_CORRUPT_DESC; 6238c2ecf20Sopenharmony_ci } 6248c2ecf20Sopenharmony_ci 6258c2ecf20Sopenharmony_ci if (ads.ds_rxstatus8 & AR_KeyMiss) 6268c2ecf20Sopenharmony_ci rs->rs_status |= ATH9K_RXERR_KEYMISS; 6278c2ecf20Sopenharmony_ci 6288c2ecf20Sopenharmony_ci return 0; 6298c2ecf20Sopenharmony_ci} 6308c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath9k_hw_rxprocdesc); 6318c2ecf20Sopenharmony_ci 6328c2ecf20Sopenharmony_ci/* 6338c2ecf20Sopenharmony_ci * This can stop or re-enables RX. 6348c2ecf20Sopenharmony_ci * 6358c2ecf20Sopenharmony_ci * If bool is set this will kill any frame which is currently being 6368c2ecf20Sopenharmony_ci * transferred between the MAC and baseband and also prevent any new 6378c2ecf20Sopenharmony_ci * frames from getting started. 6388c2ecf20Sopenharmony_ci */ 6398c2ecf20Sopenharmony_cibool ath9k_hw_setrxabort(struct ath_hw *ah, bool set) 6408c2ecf20Sopenharmony_ci{ 6418c2ecf20Sopenharmony_ci u32 reg; 6428c2ecf20Sopenharmony_ci 6438c2ecf20Sopenharmony_ci if (set) { 6448c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_DIAG_SW, 6458c2ecf20Sopenharmony_ci (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT)); 6468c2ecf20Sopenharmony_ci 6478c2ecf20Sopenharmony_ci if (!ath9k_hw_wait(ah, AR_OBS_BUS_1, AR_OBS_BUS_1_RX_STATE, 6488c2ecf20Sopenharmony_ci 0, AH_WAIT_TIMEOUT)) { 6498c2ecf20Sopenharmony_ci REG_CLR_BIT(ah, AR_DIAG_SW, 6508c2ecf20Sopenharmony_ci (AR_DIAG_RX_DIS | 6518c2ecf20Sopenharmony_ci AR_DIAG_RX_ABORT)); 6528c2ecf20Sopenharmony_ci 6538c2ecf20Sopenharmony_ci reg = REG_READ(ah, AR_OBS_BUS_1); 6548c2ecf20Sopenharmony_ci ath_err(ath9k_hw_common(ah), 6558c2ecf20Sopenharmony_ci "RX failed to go idle in 10 ms RXSM=0x%x\n", 6568c2ecf20Sopenharmony_ci reg); 6578c2ecf20Sopenharmony_ci 6588c2ecf20Sopenharmony_ci return false; 6598c2ecf20Sopenharmony_ci } 6608c2ecf20Sopenharmony_ci } else { 6618c2ecf20Sopenharmony_ci REG_CLR_BIT(ah, AR_DIAG_SW, 6628c2ecf20Sopenharmony_ci (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT)); 6638c2ecf20Sopenharmony_ci } 6648c2ecf20Sopenharmony_ci 6658c2ecf20Sopenharmony_ci return true; 6668c2ecf20Sopenharmony_ci} 6678c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath9k_hw_setrxabort); 6688c2ecf20Sopenharmony_ci 6698c2ecf20Sopenharmony_civoid ath9k_hw_putrxbuf(struct ath_hw *ah, u32 rxdp) 6708c2ecf20Sopenharmony_ci{ 6718c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_RXDP, rxdp); 6728c2ecf20Sopenharmony_ci} 6738c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath9k_hw_putrxbuf); 6748c2ecf20Sopenharmony_ci 6758c2ecf20Sopenharmony_civoid ath9k_hw_startpcureceive(struct ath_hw *ah, bool is_scanning) 6768c2ecf20Sopenharmony_ci{ 6778c2ecf20Sopenharmony_ci ath9k_enable_mib_counters(ah); 6788c2ecf20Sopenharmony_ci 6798c2ecf20Sopenharmony_ci ath9k_ani_reset(ah, is_scanning); 6808c2ecf20Sopenharmony_ci 6818c2ecf20Sopenharmony_ci REG_CLR_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT)); 6828c2ecf20Sopenharmony_ci} 6838c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath9k_hw_startpcureceive); 6848c2ecf20Sopenharmony_ci 6858c2ecf20Sopenharmony_civoid ath9k_hw_abortpcurecv(struct ath_hw *ah) 6868c2ecf20Sopenharmony_ci{ 6878c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_RX_ABORT | AR_DIAG_RX_DIS); 6888c2ecf20Sopenharmony_ci 6898c2ecf20Sopenharmony_ci ath9k_hw_disable_mib_counters(ah); 6908c2ecf20Sopenharmony_ci} 6918c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath9k_hw_abortpcurecv); 6928c2ecf20Sopenharmony_ci 6938c2ecf20Sopenharmony_cibool ath9k_hw_stopdmarecv(struct ath_hw *ah, bool *reset) 6948c2ecf20Sopenharmony_ci{ 6958c2ecf20Sopenharmony_ci#define AH_RX_STOP_DMA_TIMEOUT 10000 /* usec */ 6968c2ecf20Sopenharmony_ci struct ath_common *common = ath9k_hw_common(ah); 6978c2ecf20Sopenharmony_ci u32 mac_status, last_mac_status = 0; 6988c2ecf20Sopenharmony_ci int i; 6998c2ecf20Sopenharmony_ci 7008c2ecf20Sopenharmony_ci /* Enable access to the DMA observation bus */ 7018c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_MACMISC, 7028c2ecf20Sopenharmony_ci ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) | 7038c2ecf20Sopenharmony_ci (AR_MACMISC_MISC_OBS_BUS_1 << 7048c2ecf20Sopenharmony_ci AR_MACMISC_MISC_OBS_BUS_MSB_S))); 7058c2ecf20Sopenharmony_ci 7068c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_CR, AR_CR_RXD); 7078c2ecf20Sopenharmony_ci 7088c2ecf20Sopenharmony_ci /* Wait for rx enable bit to go low */ 7098c2ecf20Sopenharmony_ci for (i = AH_RX_STOP_DMA_TIMEOUT / AH_TIME_QUANTUM; i != 0; i--) { 7108c2ecf20Sopenharmony_ci if ((REG_READ(ah, AR_CR) & AR_CR_RXE) == 0) 7118c2ecf20Sopenharmony_ci break; 7128c2ecf20Sopenharmony_ci 7138c2ecf20Sopenharmony_ci if (!AR_SREV_9300_20_OR_LATER(ah)) { 7148c2ecf20Sopenharmony_ci mac_status = REG_READ(ah, AR_DMADBG_7) & 0x7f0; 7158c2ecf20Sopenharmony_ci if (mac_status == 0x1c0 && mac_status == last_mac_status) { 7168c2ecf20Sopenharmony_ci *reset = true; 7178c2ecf20Sopenharmony_ci break; 7188c2ecf20Sopenharmony_ci } 7198c2ecf20Sopenharmony_ci 7208c2ecf20Sopenharmony_ci last_mac_status = mac_status; 7218c2ecf20Sopenharmony_ci } 7228c2ecf20Sopenharmony_ci 7238c2ecf20Sopenharmony_ci udelay(AH_TIME_QUANTUM); 7248c2ecf20Sopenharmony_ci } 7258c2ecf20Sopenharmony_ci 7268c2ecf20Sopenharmony_ci if (i == 0) { 7278c2ecf20Sopenharmony_ci ath_err(common, 7288c2ecf20Sopenharmony_ci "DMA failed to stop in %d ms AR_CR=0x%08x AR_DIAG_SW=0x%08x DMADBG_7=0x%08x\n", 7298c2ecf20Sopenharmony_ci AH_RX_STOP_DMA_TIMEOUT / 1000, 7308c2ecf20Sopenharmony_ci REG_READ(ah, AR_CR), 7318c2ecf20Sopenharmony_ci REG_READ(ah, AR_DIAG_SW), 7328c2ecf20Sopenharmony_ci REG_READ(ah, AR_DMADBG_7)); 7338c2ecf20Sopenharmony_ci return false; 7348c2ecf20Sopenharmony_ci } else { 7358c2ecf20Sopenharmony_ci return true; 7368c2ecf20Sopenharmony_ci } 7378c2ecf20Sopenharmony_ci 7388c2ecf20Sopenharmony_ci#undef AH_RX_STOP_DMA_TIMEOUT 7398c2ecf20Sopenharmony_ci} 7408c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath9k_hw_stopdmarecv); 7418c2ecf20Sopenharmony_ci 7428c2ecf20Sopenharmony_ciint ath9k_hw_beaconq_setup(struct ath_hw *ah) 7438c2ecf20Sopenharmony_ci{ 7448c2ecf20Sopenharmony_ci struct ath9k_tx_queue_info qi; 7458c2ecf20Sopenharmony_ci 7468c2ecf20Sopenharmony_ci memset(&qi, 0, sizeof(qi)); 7478c2ecf20Sopenharmony_ci qi.tqi_aifs = 1; 7488c2ecf20Sopenharmony_ci qi.tqi_cwmin = 0; 7498c2ecf20Sopenharmony_ci qi.tqi_cwmax = 0; 7508c2ecf20Sopenharmony_ci 7518c2ecf20Sopenharmony_ci if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) 7528c2ecf20Sopenharmony_ci qi.tqi_qflags = TXQ_FLAG_TXINT_ENABLE; 7538c2ecf20Sopenharmony_ci 7548c2ecf20Sopenharmony_ci return ath9k_hw_setuptxqueue(ah, ATH9K_TX_QUEUE_BEACON, &qi); 7558c2ecf20Sopenharmony_ci} 7568c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath9k_hw_beaconq_setup); 7578c2ecf20Sopenharmony_ci 7588c2ecf20Sopenharmony_cibool ath9k_hw_intrpend(struct ath_hw *ah) 7598c2ecf20Sopenharmony_ci{ 7608c2ecf20Sopenharmony_ci u32 host_isr; 7618c2ecf20Sopenharmony_ci 7628c2ecf20Sopenharmony_ci if (AR_SREV_9100(ah)) 7638c2ecf20Sopenharmony_ci return true; 7648c2ecf20Sopenharmony_ci 7658c2ecf20Sopenharmony_ci host_isr = REG_READ(ah, AR_INTR_ASYNC_CAUSE); 7668c2ecf20Sopenharmony_ci 7678c2ecf20Sopenharmony_ci if (((host_isr & AR_INTR_MAC_IRQ) || 7688c2ecf20Sopenharmony_ci (host_isr & AR_INTR_ASYNC_MASK_MCI)) && 7698c2ecf20Sopenharmony_ci (host_isr != AR_INTR_SPURIOUS)) 7708c2ecf20Sopenharmony_ci return true; 7718c2ecf20Sopenharmony_ci 7728c2ecf20Sopenharmony_ci host_isr = REG_READ(ah, AR_INTR_SYNC_CAUSE); 7738c2ecf20Sopenharmony_ci if ((host_isr & AR_INTR_SYNC_DEFAULT) 7748c2ecf20Sopenharmony_ci && (host_isr != AR_INTR_SPURIOUS)) 7758c2ecf20Sopenharmony_ci return true; 7768c2ecf20Sopenharmony_ci 7778c2ecf20Sopenharmony_ci return false; 7788c2ecf20Sopenharmony_ci} 7798c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath9k_hw_intrpend); 7808c2ecf20Sopenharmony_ci 7818c2ecf20Sopenharmony_civoid ath9k_hw_kill_interrupts(struct ath_hw *ah) 7828c2ecf20Sopenharmony_ci{ 7838c2ecf20Sopenharmony_ci struct ath_common *common = ath9k_hw_common(ah); 7848c2ecf20Sopenharmony_ci 7858c2ecf20Sopenharmony_ci ath_dbg(common, INTERRUPT, "disable IER\n"); 7868c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_IER, AR_IER_DISABLE); 7878c2ecf20Sopenharmony_ci (void) REG_READ(ah, AR_IER); 7888c2ecf20Sopenharmony_ci if (!AR_SREV_9100(ah)) { 7898c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, 0); 7908c2ecf20Sopenharmony_ci (void) REG_READ(ah, AR_INTR_ASYNC_ENABLE); 7918c2ecf20Sopenharmony_ci 7928c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0); 7938c2ecf20Sopenharmony_ci (void) REG_READ(ah, AR_INTR_SYNC_ENABLE); 7948c2ecf20Sopenharmony_ci } 7958c2ecf20Sopenharmony_ci} 7968c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath9k_hw_kill_interrupts); 7978c2ecf20Sopenharmony_ci 7988c2ecf20Sopenharmony_civoid ath9k_hw_disable_interrupts(struct ath_hw *ah) 7998c2ecf20Sopenharmony_ci{ 8008c2ecf20Sopenharmony_ci if (!(ah->imask & ATH9K_INT_GLOBAL)) 8018c2ecf20Sopenharmony_ci atomic_set(&ah->intr_ref_cnt, -1); 8028c2ecf20Sopenharmony_ci else 8038c2ecf20Sopenharmony_ci atomic_dec(&ah->intr_ref_cnt); 8048c2ecf20Sopenharmony_ci 8058c2ecf20Sopenharmony_ci ath9k_hw_kill_interrupts(ah); 8068c2ecf20Sopenharmony_ci} 8078c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath9k_hw_disable_interrupts); 8088c2ecf20Sopenharmony_ci 8098c2ecf20Sopenharmony_cistatic void __ath9k_hw_enable_interrupts(struct ath_hw *ah) 8108c2ecf20Sopenharmony_ci{ 8118c2ecf20Sopenharmony_ci struct ath_common *common = ath9k_hw_common(ah); 8128c2ecf20Sopenharmony_ci u32 sync_default = AR_INTR_SYNC_DEFAULT; 8138c2ecf20Sopenharmony_ci u32 async_mask; 8148c2ecf20Sopenharmony_ci 8158c2ecf20Sopenharmony_ci if (AR_SREV_9340(ah) || AR_SREV_9550(ah) || AR_SREV_9531(ah) || 8168c2ecf20Sopenharmony_ci AR_SREV_9561(ah)) 8178c2ecf20Sopenharmony_ci sync_default &= ~AR_INTR_SYNC_HOST1_FATAL; 8188c2ecf20Sopenharmony_ci 8198c2ecf20Sopenharmony_ci async_mask = AR_INTR_MAC_IRQ; 8208c2ecf20Sopenharmony_ci 8218c2ecf20Sopenharmony_ci if (ah->imask & ATH9K_INT_MCI) 8228c2ecf20Sopenharmony_ci async_mask |= AR_INTR_ASYNC_MASK_MCI; 8238c2ecf20Sopenharmony_ci 8248c2ecf20Sopenharmony_ci ath_dbg(common, INTERRUPT, "enable IER\n"); 8258c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_IER, AR_IER_ENABLE); 8268c2ecf20Sopenharmony_ci if (!AR_SREV_9100(ah)) { 8278c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, async_mask); 8288c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_INTR_ASYNC_MASK, async_mask); 8298c2ecf20Sopenharmony_ci 8308c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_INTR_SYNC_ENABLE, sync_default); 8318c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_INTR_SYNC_MASK, sync_default); 8328c2ecf20Sopenharmony_ci } 8338c2ecf20Sopenharmony_ci ath_dbg(common, INTERRUPT, "AR_IMR 0x%x IER 0x%x\n", 8348c2ecf20Sopenharmony_ci REG_READ(ah, AR_IMR), REG_READ(ah, AR_IER)); 8358c2ecf20Sopenharmony_ci 8368c2ecf20Sopenharmony_ci if (ah->msi_enabled) { 8378c2ecf20Sopenharmony_ci u32 _msi_reg = 0; 8388c2ecf20Sopenharmony_ci u32 i = 0; 8398c2ecf20Sopenharmony_ci u32 msi_pend_addr_mask = AR_PCIE_MSI_HW_INT_PENDING_ADDR_MSI_64; 8408c2ecf20Sopenharmony_ci 8418c2ecf20Sopenharmony_ci ath_dbg(ath9k_hw_common(ah), INTERRUPT, 8428c2ecf20Sopenharmony_ci "Enabling MSI, msi_mask=0x%X\n", ah->msi_mask); 8438c2ecf20Sopenharmony_ci 8448c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_INTR_PRIO_ASYNC_ENABLE, ah->msi_mask); 8458c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_INTR_PRIO_ASYNC_MASK, ah->msi_mask); 8468c2ecf20Sopenharmony_ci ath_dbg(ath9k_hw_common(ah), INTERRUPT, 8478c2ecf20Sopenharmony_ci "AR_INTR_PRIO_ASYNC_ENABLE=0x%X, AR_INTR_PRIO_ASYNC_MASK=0x%X\n", 8488c2ecf20Sopenharmony_ci REG_READ(ah, AR_INTR_PRIO_ASYNC_ENABLE), 8498c2ecf20Sopenharmony_ci REG_READ(ah, AR_INTR_PRIO_ASYNC_MASK)); 8508c2ecf20Sopenharmony_ci 8518c2ecf20Sopenharmony_ci if (ah->msi_reg == 0) 8528c2ecf20Sopenharmony_ci ah->msi_reg = REG_READ(ah, AR_PCIE_MSI); 8538c2ecf20Sopenharmony_ci 8548c2ecf20Sopenharmony_ci ath_dbg(ath9k_hw_common(ah), INTERRUPT, 8558c2ecf20Sopenharmony_ci "AR_PCIE_MSI=0x%X, ah->msi_reg = 0x%X\n", 8568c2ecf20Sopenharmony_ci AR_PCIE_MSI, ah->msi_reg); 8578c2ecf20Sopenharmony_ci 8588c2ecf20Sopenharmony_ci i = 0; 8598c2ecf20Sopenharmony_ci do { 8608c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PCIE_MSI, 8618c2ecf20Sopenharmony_ci (ah->msi_reg | AR_PCIE_MSI_ENABLE) 8628c2ecf20Sopenharmony_ci & msi_pend_addr_mask); 8638c2ecf20Sopenharmony_ci _msi_reg = REG_READ(ah, AR_PCIE_MSI); 8648c2ecf20Sopenharmony_ci i++; 8658c2ecf20Sopenharmony_ci } while ((_msi_reg & AR_PCIE_MSI_ENABLE) == 0 && i < 200); 8668c2ecf20Sopenharmony_ci 8678c2ecf20Sopenharmony_ci if (i >= 200) 8688c2ecf20Sopenharmony_ci ath_err(ath9k_hw_common(ah), 8698c2ecf20Sopenharmony_ci "%s: _msi_reg = 0x%X\n", 8708c2ecf20Sopenharmony_ci __func__, _msi_reg); 8718c2ecf20Sopenharmony_ci } 8728c2ecf20Sopenharmony_ci} 8738c2ecf20Sopenharmony_ci 8748c2ecf20Sopenharmony_civoid ath9k_hw_resume_interrupts(struct ath_hw *ah) 8758c2ecf20Sopenharmony_ci{ 8768c2ecf20Sopenharmony_ci struct ath_common *common = ath9k_hw_common(ah); 8778c2ecf20Sopenharmony_ci 8788c2ecf20Sopenharmony_ci if (!(ah->imask & ATH9K_INT_GLOBAL)) 8798c2ecf20Sopenharmony_ci return; 8808c2ecf20Sopenharmony_ci 8818c2ecf20Sopenharmony_ci if (atomic_read(&ah->intr_ref_cnt) != 0) { 8828c2ecf20Sopenharmony_ci ath_dbg(common, INTERRUPT, "Do not enable IER ref count %d\n", 8838c2ecf20Sopenharmony_ci atomic_read(&ah->intr_ref_cnt)); 8848c2ecf20Sopenharmony_ci return; 8858c2ecf20Sopenharmony_ci } 8868c2ecf20Sopenharmony_ci 8878c2ecf20Sopenharmony_ci __ath9k_hw_enable_interrupts(ah); 8888c2ecf20Sopenharmony_ci} 8898c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath9k_hw_resume_interrupts); 8908c2ecf20Sopenharmony_ci 8918c2ecf20Sopenharmony_civoid ath9k_hw_enable_interrupts(struct ath_hw *ah) 8928c2ecf20Sopenharmony_ci{ 8938c2ecf20Sopenharmony_ci struct ath_common *common = ath9k_hw_common(ah); 8948c2ecf20Sopenharmony_ci 8958c2ecf20Sopenharmony_ci if (!(ah->imask & ATH9K_INT_GLOBAL)) 8968c2ecf20Sopenharmony_ci return; 8978c2ecf20Sopenharmony_ci 8988c2ecf20Sopenharmony_ci if (!atomic_inc_and_test(&ah->intr_ref_cnt)) { 8998c2ecf20Sopenharmony_ci ath_dbg(common, INTERRUPT, "Do not enable IER ref count %d\n", 9008c2ecf20Sopenharmony_ci atomic_read(&ah->intr_ref_cnt)); 9018c2ecf20Sopenharmony_ci return; 9028c2ecf20Sopenharmony_ci } 9038c2ecf20Sopenharmony_ci 9048c2ecf20Sopenharmony_ci __ath9k_hw_enable_interrupts(ah); 9058c2ecf20Sopenharmony_ci} 9068c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath9k_hw_enable_interrupts); 9078c2ecf20Sopenharmony_ci 9088c2ecf20Sopenharmony_civoid ath9k_hw_set_interrupts(struct ath_hw *ah) 9098c2ecf20Sopenharmony_ci{ 9108c2ecf20Sopenharmony_ci enum ath9k_int ints = ah->imask; 9118c2ecf20Sopenharmony_ci u32 mask, mask2; 9128c2ecf20Sopenharmony_ci struct ath9k_hw_capabilities *pCap = &ah->caps; 9138c2ecf20Sopenharmony_ci struct ath_common *common = ath9k_hw_common(ah); 9148c2ecf20Sopenharmony_ci 9158c2ecf20Sopenharmony_ci if (!(ints & ATH9K_INT_GLOBAL)) 9168c2ecf20Sopenharmony_ci ath9k_hw_disable_interrupts(ah); 9178c2ecf20Sopenharmony_ci 9188c2ecf20Sopenharmony_ci if (ah->msi_enabled) { 9198c2ecf20Sopenharmony_ci ath_dbg(common, INTERRUPT, "Clearing AR_INTR_PRIO_ASYNC_ENABLE\n"); 9208c2ecf20Sopenharmony_ci 9218c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_INTR_PRIO_ASYNC_ENABLE, 0); 9228c2ecf20Sopenharmony_ci REG_READ(ah, AR_INTR_PRIO_ASYNC_ENABLE); 9238c2ecf20Sopenharmony_ci } 9248c2ecf20Sopenharmony_ci 9258c2ecf20Sopenharmony_ci ath_dbg(common, INTERRUPT, "New interrupt mask 0x%x\n", ints); 9268c2ecf20Sopenharmony_ci 9278c2ecf20Sopenharmony_ci mask = ints & ATH9K_INT_COMMON; 9288c2ecf20Sopenharmony_ci mask2 = 0; 9298c2ecf20Sopenharmony_ci 9308c2ecf20Sopenharmony_ci ah->msi_mask = 0; 9318c2ecf20Sopenharmony_ci if (ints & ATH9K_INT_TX) { 9328c2ecf20Sopenharmony_ci ah->msi_mask |= AR_INTR_PRIO_TX; 9338c2ecf20Sopenharmony_ci if (ah->config.tx_intr_mitigation) 9348c2ecf20Sopenharmony_ci mask |= AR_IMR_TXMINTR | AR_IMR_TXINTM; 9358c2ecf20Sopenharmony_ci else { 9368c2ecf20Sopenharmony_ci if (ah->txok_interrupt_mask) 9378c2ecf20Sopenharmony_ci mask |= AR_IMR_TXOK; 9388c2ecf20Sopenharmony_ci if (ah->txdesc_interrupt_mask) 9398c2ecf20Sopenharmony_ci mask |= AR_IMR_TXDESC; 9408c2ecf20Sopenharmony_ci } 9418c2ecf20Sopenharmony_ci if (ah->txerr_interrupt_mask) 9428c2ecf20Sopenharmony_ci mask |= AR_IMR_TXERR; 9438c2ecf20Sopenharmony_ci if (ah->txeol_interrupt_mask) 9448c2ecf20Sopenharmony_ci mask |= AR_IMR_TXEOL; 9458c2ecf20Sopenharmony_ci } 9468c2ecf20Sopenharmony_ci if (ints & ATH9K_INT_RX) { 9478c2ecf20Sopenharmony_ci ah->msi_mask |= AR_INTR_PRIO_RXLP | AR_INTR_PRIO_RXHP; 9488c2ecf20Sopenharmony_ci if (AR_SREV_9300_20_OR_LATER(ah)) { 9498c2ecf20Sopenharmony_ci mask |= AR_IMR_RXERR | AR_IMR_RXOK_HP; 9508c2ecf20Sopenharmony_ci if (ah->config.rx_intr_mitigation) { 9518c2ecf20Sopenharmony_ci mask &= ~AR_IMR_RXOK_LP; 9528c2ecf20Sopenharmony_ci mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM; 9538c2ecf20Sopenharmony_ci } else { 9548c2ecf20Sopenharmony_ci mask |= AR_IMR_RXOK_LP; 9558c2ecf20Sopenharmony_ci } 9568c2ecf20Sopenharmony_ci } else { 9578c2ecf20Sopenharmony_ci if (ah->config.rx_intr_mitigation) 9588c2ecf20Sopenharmony_ci mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM; 9598c2ecf20Sopenharmony_ci else 9608c2ecf20Sopenharmony_ci mask |= AR_IMR_RXOK | AR_IMR_RXDESC; 9618c2ecf20Sopenharmony_ci } 9628c2ecf20Sopenharmony_ci if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) 9638c2ecf20Sopenharmony_ci mask |= AR_IMR_GENTMR; 9648c2ecf20Sopenharmony_ci } 9658c2ecf20Sopenharmony_ci 9668c2ecf20Sopenharmony_ci if (ints & ATH9K_INT_GENTIMER) 9678c2ecf20Sopenharmony_ci mask |= AR_IMR_GENTMR; 9688c2ecf20Sopenharmony_ci 9698c2ecf20Sopenharmony_ci if (ints & (ATH9K_INT_BMISC)) { 9708c2ecf20Sopenharmony_ci mask |= AR_IMR_BCNMISC; 9718c2ecf20Sopenharmony_ci if (ints & ATH9K_INT_TIM) 9728c2ecf20Sopenharmony_ci mask2 |= AR_IMR_S2_TIM; 9738c2ecf20Sopenharmony_ci if (ints & ATH9K_INT_DTIM) 9748c2ecf20Sopenharmony_ci mask2 |= AR_IMR_S2_DTIM; 9758c2ecf20Sopenharmony_ci if (ints & ATH9K_INT_DTIMSYNC) 9768c2ecf20Sopenharmony_ci mask2 |= AR_IMR_S2_DTIMSYNC; 9778c2ecf20Sopenharmony_ci if (ints & ATH9K_INT_CABEND) 9788c2ecf20Sopenharmony_ci mask2 |= AR_IMR_S2_CABEND; 9798c2ecf20Sopenharmony_ci if (ints & ATH9K_INT_TSFOOR) 9808c2ecf20Sopenharmony_ci mask2 |= AR_IMR_S2_TSFOOR; 9818c2ecf20Sopenharmony_ci } 9828c2ecf20Sopenharmony_ci 9838c2ecf20Sopenharmony_ci if (ints & (ATH9K_INT_GTT | ATH9K_INT_CST)) { 9848c2ecf20Sopenharmony_ci mask |= AR_IMR_BCNMISC; 9858c2ecf20Sopenharmony_ci if (ints & ATH9K_INT_GTT) 9868c2ecf20Sopenharmony_ci mask2 |= AR_IMR_S2_GTT; 9878c2ecf20Sopenharmony_ci if (ints & ATH9K_INT_CST) 9888c2ecf20Sopenharmony_ci mask2 |= AR_IMR_S2_CST; 9898c2ecf20Sopenharmony_ci } 9908c2ecf20Sopenharmony_ci 9918c2ecf20Sopenharmony_ci if (ah->config.hw_hang_checks & HW_BB_WATCHDOG) { 9928c2ecf20Sopenharmony_ci if (ints & ATH9K_INT_BB_WATCHDOG) { 9938c2ecf20Sopenharmony_ci mask |= AR_IMR_BCNMISC; 9948c2ecf20Sopenharmony_ci mask2 |= AR_IMR_S2_BB_WATCHDOG; 9958c2ecf20Sopenharmony_ci } 9968c2ecf20Sopenharmony_ci } 9978c2ecf20Sopenharmony_ci 9988c2ecf20Sopenharmony_ci ath_dbg(common, INTERRUPT, "new IMR 0x%x\n", mask); 9998c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_IMR, mask); 10008c2ecf20Sopenharmony_ci ah->imrs2_reg &= ~(AR_IMR_S2_TIM | 10018c2ecf20Sopenharmony_ci AR_IMR_S2_DTIM | 10028c2ecf20Sopenharmony_ci AR_IMR_S2_DTIMSYNC | 10038c2ecf20Sopenharmony_ci AR_IMR_S2_CABEND | 10048c2ecf20Sopenharmony_ci AR_IMR_S2_CABTO | 10058c2ecf20Sopenharmony_ci AR_IMR_S2_TSFOOR | 10068c2ecf20Sopenharmony_ci AR_IMR_S2_GTT | 10078c2ecf20Sopenharmony_ci AR_IMR_S2_CST); 10088c2ecf20Sopenharmony_ci 10098c2ecf20Sopenharmony_ci if (ah->config.hw_hang_checks & HW_BB_WATCHDOG) { 10108c2ecf20Sopenharmony_ci if (ints & ATH9K_INT_BB_WATCHDOG) 10118c2ecf20Sopenharmony_ci ah->imrs2_reg &= ~AR_IMR_S2_BB_WATCHDOG; 10128c2ecf20Sopenharmony_ci } 10138c2ecf20Sopenharmony_ci 10148c2ecf20Sopenharmony_ci ah->imrs2_reg |= mask2; 10158c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg); 10168c2ecf20Sopenharmony_ci 10178c2ecf20Sopenharmony_ci if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) { 10188c2ecf20Sopenharmony_ci if (ints & ATH9K_INT_TIM_TIMER) 10198c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER); 10208c2ecf20Sopenharmony_ci else 10218c2ecf20Sopenharmony_ci REG_CLR_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER); 10228c2ecf20Sopenharmony_ci } 10238c2ecf20Sopenharmony_ci 10248c2ecf20Sopenharmony_ci return; 10258c2ecf20Sopenharmony_ci} 10268c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath9k_hw_set_interrupts); 10278c2ecf20Sopenharmony_ci 10288c2ecf20Sopenharmony_ci#define ATH9K_HW_MAX_DCU 10 10298c2ecf20Sopenharmony_ci#define ATH9K_HW_SLICE_PER_DCU 16 10308c2ecf20Sopenharmony_ci#define ATH9K_HW_BIT_IN_SLICE 16 10318c2ecf20Sopenharmony_civoid ath9k_hw_set_tx_filter(struct ath_hw *ah, u8 destidx, bool set) 10328c2ecf20Sopenharmony_ci{ 10338c2ecf20Sopenharmony_ci int dcu_idx; 10348c2ecf20Sopenharmony_ci u32 filter; 10358c2ecf20Sopenharmony_ci 10368c2ecf20Sopenharmony_ci for (dcu_idx = 0; dcu_idx < 10; dcu_idx++) { 10378c2ecf20Sopenharmony_ci filter = SM(set, AR_D_TXBLK_WRITE_COMMAND); 10388c2ecf20Sopenharmony_ci filter |= SM(dcu_idx, AR_D_TXBLK_WRITE_DCU); 10398c2ecf20Sopenharmony_ci filter |= SM((destidx / ATH9K_HW_SLICE_PER_DCU), 10408c2ecf20Sopenharmony_ci AR_D_TXBLK_WRITE_SLICE); 10418c2ecf20Sopenharmony_ci filter |= BIT(destidx % ATH9K_HW_BIT_IN_SLICE); 10428c2ecf20Sopenharmony_ci ath_dbg(ath9k_hw_common(ah), PS, 10438c2ecf20Sopenharmony_ci "DCU%d staid %d set %d txfilter %08x\n", 10448c2ecf20Sopenharmony_ci dcu_idx, destidx, set, filter); 10458c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_D_TXBLK_BASE, filter); 10468c2ecf20Sopenharmony_ci } 10478c2ecf20Sopenharmony_ci} 10488c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath9k_hw_set_tx_filter); 1049