1 /* 2 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 3 * Use is subject to license terms. 4 */ 5 6 /* 7 * Copyright (c) 2007, 2008 8 * Damien Bergamini <damien.bergamini@free.fr> 9 * 10 * Permission to use, copy, modify, and distribute this software for any 11 * purpose with or without fee is hereby granted, provided that the above 12 * copyright notice and this permission notice appear in all copies. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 15 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 16 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 17 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 18 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 19 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 20 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 21 */ 22 23 #ifndef _RT2860_VAR_H 24 #define _RT2860_VAR_H 25 26 #include <sys/queue.h> 27 28 #ifdef __cplusplus 29 extern "C" { 30 #endif 31 32 /* 33 * EDCA Access Categories. 34 */ 35 enum ieee80211_edca_ac { 36 EDCA_AC_BK = 1, /* Background */ 37 EDCA_AC_BE = 0, /* Best Effort */ 38 EDCA_AC_VI = 2, /* Video */ 39 EDCA_AC_VO = 3 /* Voice */ 40 }; 41 #define EDCA_NUM_AC 4 42 43 #define RT2860_SUCCESS 0 44 45 #define RT2860_TX_RING_COUNT 64 46 #define RT2860_RX_RING_COUNT 128 47 #define RT2860_TX_POOL_COUNT (RT2860_TX_RING_COUNT * 2) 48 49 #define RT2860_MAX_SCATTER ((RT2860_TX_RING_COUNT * 2) - 1) 50 51 /* HW supports up to 255 STAs */ 52 #define RT2860_WCID_MAX 254 53 #define RT2860_AID2WCID(aid) ((aid) & 0xff) 54 55 struct dma_area { 56 ddi_acc_handle_t acc_hdl; /* handle for memory */ 57 caddr_t mem_va; /* CPU VA of memory */ 58 uint32_t nslots; /* number of slots */ 59 uint32_t size; /* size per slot */ 60 size_t alength; /* allocated size */ 61 62 ddi_dma_handle_t dma_hdl; /* DMA handle */ 63 offset_t offset; /* relative to handle */ 64 ddi_dma_cookie_t cookie; /* associated cookie */ 65 uint32_t ncookies; /* must be 1 */ 66 uint32_t token; /* arbitrary identifier */ 67 }; 68 69 struct rt2860_txd; 70 71 struct rt2860_tx_data { 72 struct dma_area txbuf_dma; 73 struct rt2860_txwi *txwi; 74 uint32_t paddr; 75 struct ieee80211_node *ni; 76 SLIST_ENTRY(rt2860_tx_data) next; 77 }; 78 79 struct rt2860_tx_ring { 80 struct dma_area txdesc_dma; 81 struct rt2860_txd *txd; 82 uint32_t paddr; 83 struct rt2860_tx_data *data[RT2860_TX_RING_COUNT]; 84 int cur; 85 int next; 86 int queued; 87 }; 88 89 struct rt2860_rx_data { 90 struct dma_area rxbuf_dma; 91 }; 92 93 struct rt2860_rx_ring { 94 struct dma_area rxdesc_dma; 95 struct rt2860_rxd *rxd; 96 uint32_t paddr; 97 unsigned int cur; /* must be unsigned */ 98 struct rt2860_rx_data data[RT2860_RX_RING_COUNT]; 99 }; 100 101 struct rt2860_amrr { 102 uint_t amrr_min_success_threshold; 103 uint_t amrr_max_success_threshold; 104 }; 105 106 struct rt2860_amrr_node { 107 int amn_success; 108 int amn_recovery; 109 int amn_success_threshold; 110 int amn_txcnt; 111 int amn_retrycnt; 112 }; 113 114 #define RT2860_DMA_SYNC(area, flag) ((void) ddi_dma_sync((area).dma_hdl,\ 115 (area).offset, (area).alength, (flag))) 116 #define RT2860_IS_RUNNING(_sc) (((_sc)->sc_flags & RT2860_F_RUNNING)) 117 #define RT2860_IS_INITED(_sc) ((_sc)->sc_flags & RT2860_F_RUNNING) 118 #define RT2860_IS_SUSPEND(_sc) ((_sc)->sc_flags & RT2860_F_SUSPEND) 119 #define RT2860_GLOCK(_sc) mutex_enter(&(_sc)->sc_genlock) 120 #define RT2860_GUNLOCK(_sc) mutex_exit(&(_sc)->sc_genlock) 121 122 123 struct rt2860_softc { 124 struct ieee80211com sc_ic; 125 dev_info_t *sc_dev; 126 127 /* ddi reg handler */ 128 ddi_acc_handle_t sc_cfg_handle; 129 caddr_t sc_cfg_base; 130 /* ddi i/o handler */ 131 ddi_acc_handle_t sc_io_handle; 132 caddr_t sc_io_base; 133 /* interrupt */ 134 ddi_iblock_cookie_t sc_iblock; 135 kmutex_t sc_genlock; 136 kmutex_t sc_txlock; 137 kmutex_t sc_rxlock; 138 timeout_id_t sc_scan_id; 139 timeout_id_t sc_rssadapt_id; 140 timeout_id_t sc_state_id; 141 struct rt2860_amrr amrr; 142 enum ieee80211_state sc_ostate; 143 144 #define RT2860_ENABLED (1 << 0) 145 #define RT2860_FWLOADED (1 << 1) 146 #define RT2860_UPD_BEACON (1 << 2) 147 #define RT2860_ADVANCED_PS (1 << 3) 148 #define RT2860_F_RUNNING (1 << 4) 149 #define RT2860_F_SUSPEND (1 << 5) 150 #define RT2860_F_QUIESCE (1 << 6) 151 152 uint32_t sc_ic_flags; 153 uint32_t sc_dmabuf_size; 154 struct rt2860_tx_ring txq[6]; 155 struct rt2860_rx_ring rxq; 156 157 struct dma_area txpool_dma; 158 struct rt2860_txwi *txwi; 159 struct rt2860_tx_data data[RT2860_TX_POOL_COUNT]; 160 SLIST_HEAD(, rt2860_tx_data) data_pool; 161 162 int sc_tx_timer; 163 int mgtqid; 164 int sifs; 165 166 /* firmware related info */ 167 uint32_t mac_rev; 168 uint8_t rf_rev; 169 uint8_t freq; 170 uint8_t ntxchains; 171 uint8_t nrxchains; 172 uint8_t pslevel; 173 int8_t txpow1[50]; 174 int8_t txpow2[50]; 175 int8_t rssi_2ghz[3]; 176 int8_t rssi_5ghz[3]; 177 uint8_t lna[4]; 178 uint8_t calib_2ghz; 179 uint8_t calib_5ghz; 180 uint8_t tssi_2ghz[9]; 181 uint8_t tssi_5ghz[9]; 182 uint8_t step_2ghz; 183 uint8_t step_5ghz; 184 185 uint32_t sc_need_sched; 186 uint32_t sc_flags; 187 /* RT2860 RCR */ 188 uint32_t sc_rcr; 189 190 uint16_t sc_cachelsz; 191 ddi_softintr_t sc_softintr_hdl; 192 193 uint32_t sc_rx_pend; 194 195 uint32_t rf_regs[4]; 196 uint8_t txpow[14]; 197 198 struct { 199 uint8_t reg; 200 uint8_t val; 201 } bbp[8]; 202 uint8_t leds; 203 uint16_t led[3]; 204 uint32_t txpow20mhz[5]; 205 uint32_t txpow40mhz_2ghz[5]; 206 uint32_t txpow40mhz_5ghz[5]; 207 208 struct rt2860_amrr_node amn[RT2860_WCID_MAX + 1]; 209 210 int led_mode; 211 int hw_radio; 212 int rx_ant; 213 int tx_ant; 214 int nb_ant; 215 216 int dwelltime; 217 218 /* kstats */ 219 uint32_t sc_tx_nobuf; 220 uint32_t sc_rx_nobuf; 221 uint32_t sc_tx_err; 222 uint32_t sc_rx_err; 223 uint32_t sc_tx_retries; 224 225 int (*sc_newstate)(struct ieee80211com *, 226 enum ieee80211_state, int); 227 }; 228 229 #ifdef __cplusplus 230 } 231 #endif 232 233 #endif /* _RT2860_VAR_H */ 234