1/* 2 * 3 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 4 * Use is subject to license terms. 5 */ 6 7/* 8 * Copyright (c) 2006 9 * Damien Bergamini <damien.bergamini@free.fr> 10 * Copyright (c) 2006 Sam Leffler, Errno Consulting 11 * Copyright (c) 2008-2009 Weongyo Jeong <weongyo@freebsd.org> 12 * 13 * Permission to use, copy, modify, and distribute this software for any 14 * purpose with or without fee is hereby granted, provided that the above 15 * copyright notice and this permission notice appear in all copies. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 18 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 19 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 20 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 21 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 22 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 23 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 24 */ 25 26 27#ifndef _UATH_VAR_H 28#define _UATH_VAR_H 29 30#include <sys/queue.h> 31 32#ifdef __cplusplus 33extern "C" { 34#endif 35 36#define UATH_ID_BSS 2 /* Connection ID */ 37 38#define UATH_RX_DATA_LIST_COUNT 1 /* 128 */ 39#define UATH_TX_DATA_LIST_COUNT 8 /* 16 */ 40#define UATH_CMD_LIST_COUNT 8 /* 60 */ 41 42#define UATH_DATA_TIMEOUT 10000 43#define UATH_CMD_TIMEOUT 1000 44 45/* 46 * Useful combinations of channel characteristics from net80211. 47 */ 48#define UATH_CHAN_A \ 49 (IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_OFDM) 50#define UATH_CHAN_B \ 51 (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_CCK) 52#define UATH_CHAN_PUREG \ 53 (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_OFDM) 54#define UATH_CHAN_G \ 55 (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_DYN) 56 57#define UATH_IS_CHAN_A(_c) \ 58 (((_c)->ich_flags & UATH_CHAN_A) == UATH_CHAN_A) 59#define UATH_IS_CHAN_B(_c) \ 60 (((_c)->ich_flags & UATH_CHAN_B) == UATH_CHAN_B) 61#define UATH_IS_CHAN_PUREG(_c) \ 62 (((_c)->ich_flags & UATH_CHAN_PUREG) == UATH_CHAN_PUREG) 63#define UATH_IS_CHAN_G(_c) \ 64 (((_c)->ich_flags & UATH_CHAN_G) == UATH_CHAN_G) 65#define UATH_IS_CHAN_ANYG(_c) \ 66 (UATH_IS_CHAN_PUREG(_c) || UATH_IS_CHAN_G(_c)) 67 68#define UATH_IS_CHAN_OFDM(_c) \ 69 ((_c)->ich_flags & IEEE80211_CHAN_OFDM) 70#define UATH_IS_CHAN_CCK(_c) \ 71 ((_c)->ich_flags & IEEE80211_CHAN_CCK) 72 73#define UATH_NODE_QOS 0x0002 /* QoS enabled */ 74 75 76/* flags for sending firmware commands */ 77#define UATH_CMD_FLAG_ASYNC (1 << 0) 78#define UATH_CMD_FLAG_READ (1 << 1) 79#define UATH_CMD_FLAG_MAGIC (1 << 2) 80 81struct uath_cmd { 82 struct uath_softc *sc; 83 uint32_t flags; 84 uint32_t msgid; 85 uint8_t *buf; 86 uint16_t buflen; 87 void *odata; /* NB: tx only */ 88 int olen; /* space in odata */ 89 STAILQ_ENTRY(uath_cmd) next; 90}; 91typedef STAILQ_HEAD(, uath_cmd) uath_cmdhead; 92 93struct uath_data { 94 struct uath_softc *sc; 95 uint8_t *buf; 96 uint16_t buflen; 97 struct ieee80211_node *ni; /* NB: tx only */ 98 STAILQ_ENTRY(uath_data) next; 99}; 100typedef STAILQ_HEAD(, uath_data) uath_datahead; 101 102struct uath_cmd_lock { 103 boolean_t done; 104 kmutex_t mutex; 105 kcondvar_t cv; 106}; 107 108struct uath_wme_settings { 109 uint8_t aifsn; 110 uint8_t logcwmin; 111 uint8_t logcwmax; 112 uint16_t txop; 113#define UATH_TXOP_TO_US(txop) ((txop) << 5) 114 uint8_t acm; 115}; 116 117struct uath_devcap { 118 uint32_t targetVersion; 119 uint32_t targetRevision; 120 uint32_t macVersion; 121 uint32_t macRevision; 122 uint32_t phyRevision; 123 uint32_t analog5GhzRevision; 124 uint32_t analog2GhzRevision; 125 uint32_t regDomain; 126 uint32_t regCapBits; 127 uint32_t countryCode; 128 uint32_t keyCacheSize; 129 uint32_t numTxQueues; 130 uint32_t connectionIdMax; 131 uint32_t wirelessModes; 132#define UATH_WIRELESS_MODE_11A 0x01 133#define UATH_WIRELESS_MODE_TURBO 0x02 134#define UATH_WIRELESS_MODE_11B 0x04 135#define UATH_WIRELESS_MODE_11G 0x08 136#define UATH_WIRELESS_MODE_108G 0x10 137 uint32_t chanSpreadSupport; 138 uint32_t compressSupport; 139 uint32_t burstSupport; 140 uint32_t fastFramesSupport; 141 uint32_t chapTuningSupport; 142 uint32_t turboGSupport; 143 uint32_t turboPrimeSupport; 144 uint32_t deviceType; 145 uint32_t wmeSupport; 146 uint32_t low2GhzChan; 147 uint32_t high2GhzChan; 148 uint32_t low5GhzChan; 149 uint32_t high5GhzChan; 150 uint32_t supportCipherWEP; 151 uint32_t supportCipherAES_CCM; 152 uint32_t supportCipherTKIP; 153 uint32_t supportCipherMicAES_CCM; 154 uint32_t supportMicTKIP; 155 uint32_t twiceAntennaGain5G; 156 uint32_t twiceAntennaGain2G; 157}; 158 159struct uath_stat { 160 uint32_t st_badchunkseqnum; 161 uint32_t st_invalidlen; 162 uint32_t st_multichunk; 163 uint32_t st_toobigrxpkt; 164 uint32_t st_stopinprogress; 165 uint32_t st_crcerr; 166 uint32_t st_phyerr; 167 uint32_t st_decrypt_crcerr; 168 uint32_t st_decrypt_micerr; 169 uint32_t st_decomperr; 170 uint32_t st_keyerr; 171 uint32_t st_err; 172 /* not use CMD/RX/TX queues, so ignore some structure */ 173}; 174#define UATH_STAT_INC(sc, var) (sc)->sc_stat.var++ 175#define UATH_STAT_DEC(sc, var) (sc)->sc_stat.var-- 176 177struct uath_softc { 178 struct ieee80211com sc_ic; 179 dev_info_t *sc_dev; 180 181 usb_client_dev_data_t *sc_udev; /* usb dev */ 182 int dev_flags; 183 uint32_t sc_flags; 184 185 usb_pipe_handle_t rx_cmd_pipe; 186 usb_pipe_handle_t rx_data_pipe; 187 usb_pipe_handle_t tx_cmd_pipe; 188 usb_pipe_handle_t tx_data_pipe; 189 190 kmutex_t sc_genlock; 191 kmutex_t sc_rxlock_cmd; 192 kmutex_t sc_rxlock_data; 193 kmutex_t sc_txlock_cmd; 194 kmutex_t sc_txlock_data; 195 196 struct uath_cmd sc_cmd[UATH_CMD_LIST_COUNT]; 197 struct uath_data sc_rx[UATH_RX_DATA_LIST_COUNT]; 198 struct uath_data sc_tx[UATH_TX_DATA_LIST_COUNT]; 199 200 int tx_cmd_queued; 201 int rx_cmd_queued; 202 int tx_data_queued; 203 int rx_data_queued; 204 205 int sc_cmdid; 206 207 struct uath_stat sc_stat; 208 209 struct uath_cmd_lock rlock; 210 struct uath_cmd_lock wlock; 211 212 struct uath_devcap sc_devcap; 213 uint8_t sc_serial[16]; 214 215 uint32_t sc_msgid; 216 uint32_t sc_seqnum; 217 218 uint8_t sc_intrx_nextnum; 219 uint32_t sc_intrx_len; 220#define UATH_MAX_INTRX_SIZE 3616 221 222 timeout_id_t sc_scan_id; 223 timeout_id_t sc_stat_id; 224 225 uint32_t sc_need_sched; 226 227 /* kstats */ 228 uint32_t sc_tx_nobuf; 229 uint32_t sc_rx_nobuf; 230 uint32_t sc_tx_err; 231 uint32_t sc_rx_err; 232 uint32_t sc_tx_retries; 233 234 int (*sc_newstate)(struct ieee80211com *, 235 enum ieee80211_state, int); 236}; 237 238#define UATH_SUCCESS 0 239#define UATH_FAILURE -1 240 241#define UATH_FLAG_RUNNING (1 << 0) 242#define UATH_FLAG_SUSPEND (1 << 1) 243#define UATH_FLAG_RECONNECT (1 << 2) 244#define UATH_FLAG_DISCONNECT (1 << 3) 245 246#define UATH_LOCK(sc) mutex_enter(&(sc)->sc_genlock) 247#define UATH_UNLOCK(sc) mutex_exit(&(sc)->sc_genlock) 248#define UATH_IS_RUNNING(_sc) ((_sc)->sc_flags & UATH_FLAG_RUNNING) 249#define UATH_IS_SUSPEND(_sc) ((_sc)->sc_flags & UATH_FLAG_SUSPEND) 250#define UATH_IS_DISCONNECT(_sc) ((_sc)->sc_flags & UATH_FLAG_DISCONNECT) 251#define UATH_IS_RECONNECT(_sc) ((_sc)->sc_flags & UATH_FLAG_RECONNECT) 252 253#define UATH_RESET_INTRX(sc) do { \ 254 (sc)->sc_intrx_nextnum = 0; \ 255 (sc)->sc_intrx_len = 0; \ 256 _NOTE(CONSTCOND) \ 257} while (0) 258 259 260#ifdef __cplusplus 261} 262#endif 263 264#endif /* _UATH_VAR_H */ 265