Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2010 Broadcom Corporation |
| 3 | * |
| 4 | * Permission to use, copy, modify, and/or distribute this software for any |
| 5 | * purpose with or without fee is hereby granted, provided that the above |
| 6 | * copyright notice and this permission notice appear in all copies. |
| 7 | * |
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 11 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
| 13 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 14 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 | */ |
Brett Rudley | 3327989 | 2010-10-01 18:03:27 -0700 | [diff] [blame] | 16 | #include <linux/kernel.h> |
Andy Shevchenko | 48c51a8 | 2010-09-15 12:47:18 +0300 | [diff] [blame] | 17 | #include <linux/ctype.h> |
Greg Kroah-Hartman | a1c16ed | 2010-10-21 11:17:44 -0700 | [diff] [blame] | 18 | #include <bcmdefs.h> |
Brett Rudley | a52ba66 | 2010-10-26 09:17:06 -0700 | [diff] [blame] | 19 | #include <bcmdevs.h> |
Greg Kroah-Hartman | a1c16ed | 2010-10-21 11:17:44 -0700 | [diff] [blame] | 20 | #include <wlc_cfg.h> |
Greg Kroah-Hartman | a1c16ed | 2010-10-21 11:17:44 -0700 | [diff] [blame] | 21 | #include <osl.h> |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 22 | #include <bcmutils.h> |
| 23 | #include <bcmwifi.h> |
| 24 | #include <siutils.h> |
| 25 | #include <bcmendian.h> |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 26 | #include <proto/wpa.h> |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 27 | #include <pcicfg.h> |
| 28 | #include <bcmsrom.h> |
| 29 | #include <wlioctl.h> |
Brett Rudley | a52ba66 | 2010-10-26 09:17:06 -0700 | [diff] [blame] | 30 | #include <sbhndpio.h> |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 31 | #include <sbhnddma.h> |
| 32 | #include <hnddma.h> |
| 33 | #include <hndpmu.h> |
| 34 | #include <d11.h> |
| 35 | #include <wlc_rate.h> |
| 36 | #include <wlc_pub.h> |
| 37 | #include <wlc_key.h> |
| 38 | #include <wlc_bsscfg.h> |
| 39 | #include <wlc_channel.h> |
Brett Rudley | 69ec303 | 2010-11-05 19:20:16 -0700 | [diff] [blame] | 40 | #include <wlc_event.h> |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 41 | #include <wlc_mac80211.h> |
| 42 | #include <wlc_bmac.h> |
| 43 | #include <wlc_scb.h> |
| 44 | #include <wlc_phy_hal.h> |
| 45 | #include <wlc_phy_shim.h> |
| 46 | #include <wlc_antsel.h> |
| 47 | #include <wlc_stf.h> |
| 48 | #include <wlc_ampdu.h> |
| 49 | #include <wlc_event.h> |
| 50 | #include <wl_export.h> |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 51 | #include "d11ucode_ext.h" |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 52 | #include <wlc_alloc.h> |
| 53 | #include <net/mac80211.h> |
Brett Rudley | 69ec303 | 2010-11-05 19:20:16 -0700 | [diff] [blame] | 54 | #include <wl_dbg.h> |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 55 | |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 56 | |
| 57 | /* |
| 58 | * buffer length needed for wlc_format_ssid |
| 59 | * 32 SSID chars, max of 4 chars for each SSID char "\xFF", plus NULL. |
| 60 | */ |
| 61 | #define SSID_FMT_BUF_LEN ((4 * DOT11_MAX_SSID_LEN) + 1) |
| 62 | |
| 63 | #define TIMER_INTERVAL_WATCHDOG 1000 /* watchdog timer, in unit of ms */ |
| 64 | #define TIMER_INTERVAL_RADIOCHK 800 /* radio monitor timer, in unit of ms */ |
| 65 | |
| 66 | #ifndef WLC_MPC_MAX_DELAYCNT |
| 67 | #define WLC_MPC_MAX_DELAYCNT 10 /* Max MPC timeout, in unit of watchdog */ |
| 68 | #endif |
| 69 | #define WLC_MPC_MIN_DELAYCNT 1 /* Min MPC timeout, in unit of watchdog */ |
| 70 | #define WLC_MPC_THRESHOLD 3 /* MPC count threshold level */ |
| 71 | |
| 72 | #define BEACON_INTERVAL_DEFAULT 100 /* beacon interval, in unit of 1024TU */ |
| 73 | #define DTIM_INTERVAL_DEFAULT 3 /* DTIM interval, in unit of beacon interval */ |
| 74 | |
| 75 | /* Scale down delays to accommodate QT slow speed */ |
| 76 | #define BEACON_INTERVAL_DEF_QT 20 /* beacon interval, in unit of 1024TU */ |
| 77 | #define DTIM_INTERVAL_DEF_QT 1 /* DTIM interval, in unit of beacon interval */ |
| 78 | |
| 79 | #define TBTT_ALIGN_LEEWAY_US 100 /* min leeway before first TBTT in us */ |
| 80 | |
| 81 | /* |
| 82 | * driver maintains internal 'tick'(wlc->pub->now) which increments in 1s OS timer(soft |
| 83 | * watchdog) it is not a wall clock and won't increment when driver is in "down" state |
| 84 | * this low resolution driver tick can be used for maintenance tasks such as phy |
| 85 | * calibration and scb update |
| 86 | */ |
| 87 | |
| 88 | /* watchdog trigger mode: OSL timer or TBTT */ |
| 89 | #define WLC_WATCHDOG_TBTT(wlc) \ |
| 90 | (wlc->stas_associated > 0 && wlc->PM != PM_OFF && wlc->pub->align_wd_tbtt) |
| 91 | |
| 92 | /* To inform the ucode of the last mcast frame posted so that it can clear moredata bit */ |
| 93 | #define BCMCFID(wlc, fid) wlc_bmac_write_shm((wlc)->hw, M_BCMC_FID, (fid)) |
| 94 | |
Brett Rudley | fa7a1db | 2010-11-23 15:30:02 -0800 | [diff] [blame] | 95 | #define WLC_WAR16165(wlc) (wlc->pub->sih->bustype == PCI_BUS && \ |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 96 | (!AP_ENAB(wlc->pub)) && (wlc->war16165)) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 97 | |
| 98 | /* debug/trace */ |
| 99 | uint wl_msg_level = |
| 100 | #if defined(BCMDBG) |
| 101 | WL_ERROR_VAL; |
| 102 | #else |
| 103 | 0; |
| 104 | #endif /* BCMDBG */ |
| 105 | |
| 106 | /* Find basic rate for a given rate */ |
| 107 | #define WLC_BASIC_RATE(wlc, rspec) (IS_MCS(rspec) ? \ |
| 108 | (wlc)->band->basic_rate[mcs_table[rspec & RSPEC_RATE_MASK].leg_ofdm] : \ |
| 109 | (wlc)->band->basic_rate[rspec & RSPEC_RATE_MASK]) |
| 110 | |
| 111 | #define FRAMETYPE(r, mimoframe) (IS_MCS(r) ? mimoframe : (IS_CCK(r) ? FT_CCK : FT_OFDM)) |
| 112 | |
| 113 | #define RFDISABLE_DEFAULT 10000000 /* rfdisable delay timer 500 ms, runs of ALP clock */ |
| 114 | |
| 115 | #define WLC_TEMPSENSE_PERIOD 10 /* 10 second timeout */ |
| 116 | |
| 117 | #define SCAN_IN_PROGRESS(x) 0 |
| 118 | |
Brett Rudley | 4766ae6 | 2010-10-27 15:47:53 -0700 | [diff] [blame] | 119 | #define EPI_VERSION_NUM 0x054b0b00 |
| 120 | |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 121 | #ifdef BCMDBG |
| 122 | /* pointer to most recently allocated wl/wlc */ |
| 123 | static wlc_info_t *wlc_info_dbg = (wlc_info_t *) (NULL); |
| 124 | #endif |
| 125 | |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 126 | /* IOVar table */ |
| 127 | |
| 128 | /* Parameter IDs, for use only internally to wlc -- in the wlc_iovars |
| 129 | * table and by the wlc_doiovar() function. No ordering is imposed: |
| 130 | * the table is keyed by name, and the function uses a switch. |
| 131 | */ |
| 132 | enum { |
| 133 | IOV_MPC = 1, |
| 134 | IOV_QTXPOWER, |
| 135 | IOV_BCN_LI_BCN, /* Beacon listen interval in # of beacons */ |
| 136 | IOV_LAST /* In case of a need to check max ID number */ |
| 137 | }; |
| 138 | |
| 139 | const bcm_iovar_t wlc_iovars[] = { |
| 140 | {"mpc", IOV_MPC, (IOVF_OPEN_ALLOW), IOVT_BOOL, 0}, |
| 141 | {"qtxpower", IOV_QTXPOWER, (IOVF_WHL | IOVF_OPEN_ALLOW), IOVT_UINT32, |
| 142 | 0}, |
| 143 | {"bcn_li_bcn", IOV_BCN_LI_BCN, 0, IOVT_UINT8, 0}, |
| 144 | {NULL, 0, 0, 0, 0} |
| 145 | }; |
| 146 | |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 147 | const u8 prio2fifo[NUMPRIO] = { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 148 | TX_AC_BE_FIFO, /* 0 BE AC_BE Best Effort */ |
| 149 | TX_AC_BK_FIFO, /* 1 BK AC_BK Background */ |
| 150 | TX_AC_BK_FIFO, /* 2 -- AC_BK Background */ |
| 151 | TX_AC_BE_FIFO, /* 3 EE AC_BE Best Effort */ |
| 152 | TX_AC_VI_FIFO, /* 4 CL AC_VI Video */ |
| 153 | TX_AC_VI_FIFO, /* 5 VI AC_VI Video */ |
| 154 | TX_AC_VO_FIFO, /* 6 VO AC_VO Voice */ |
| 155 | TX_AC_VO_FIFO /* 7 NC AC_VO Voice */ |
| 156 | }; |
| 157 | |
| 158 | /* precedences numbers for wlc queues. These are twice as may levels as |
| 159 | * 802.1D priorities. |
| 160 | * Odd numbers are used for HI priority traffic at same precedence levels |
| 161 | * These constants are used ONLY by wlc_prio2prec_map. Do not use them elsewhere. |
| 162 | */ |
| 163 | #define _WLC_PREC_NONE 0 /* None = - */ |
| 164 | #define _WLC_PREC_BK 2 /* BK - Background */ |
| 165 | #define _WLC_PREC_BE 4 /* BE - Best-effort */ |
| 166 | #define _WLC_PREC_EE 6 /* EE - Excellent-effort */ |
| 167 | #define _WLC_PREC_CL 8 /* CL - Controlled Load */ |
| 168 | #define _WLC_PREC_VI 10 /* Vi - Video */ |
| 169 | #define _WLC_PREC_VO 12 /* Vo - Voice */ |
| 170 | #define _WLC_PREC_NC 14 /* NC - Network Control */ |
| 171 | |
| 172 | /* 802.1D Priority to precedence queue mapping */ |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 173 | const u8 wlc_prio2prec_map[] = { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 174 | _WLC_PREC_BE, /* 0 BE - Best-effort */ |
| 175 | _WLC_PREC_BK, /* 1 BK - Background */ |
| 176 | _WLC_PREC_NONE, /* 2 None = - */ |
| 177 | _WLC_PREC_EE, /* 3 EE - Excellent-effort */ |
| 178 | _WLC_PREC_CL, /* 4 CL - Controlled Load */ |
| 179 | _WLC_PREC_VI, /* 5 Vi - Video */ |
| 180 | _WLC_PREC_VO, /* 6 Vo - Voice */ |
| 181 | _WLC_PREC_NC, /* 7 NC - Network Control */ |
| 182 | }; |
| 183 | |
| 184 | /* Sanity check for tx_prec_map and fifo synchup |
| 185 | * Either there are some packets pending for the fifo, else if fifo is empty then |
| 186 | * all the corresponding precmap bits should be set |
| 187 | */ |
| 188 | #define WLC_TX_FIFO_CHECK(wlc, fifo) (TXPKTPENDGET((wlc), (fifo)) || \ |
| 189 | (TXPKTPENDGET((wlc), (fifo)) == 0 && \ |
| 190 | ((wlc)->tx_prec_map & (wlc)->fifo2prec_map[(fifo)]) == \ |
| 191 | (wlc)->fifo2prec_map[(fifo)])) |
| 192 | |
| 193 | /* TX FIFO number to WME/802.1E Access Category */ |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 194 | const u8 wme_fifo2ac[] = { AC_BK, AC_BE, AC_VI, AC_VO, AC_BE, AC_BE }; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 195 | |
| 196 | /* WME/802.1E Access Category to TX FIFO number */ |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 197 | static const u8 wme_ac2fifo[] = { 1, 0, 2, 3 }; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 198 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 199 | static bool in_send_q = false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 200 | |
| 201 | /* Shared memory location index for various AC params */ |
| 202 | #define wme_shmemacindex(ac) wme_ac2fifo[ac] |
| 203 | |
| 204 | #ifdef BCMDBG |
Jason Cooper | e5c4536 | 2010-09-14 09:45:35 -0400 | [diff] [blame] | 205 | static const char *fifo_names[] = { |
| 206 | "AC_BK", "AC_BE", "AC_VI", "AC_VO", "BCMC", "ATIM" }; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 207 | const char *aci_names[] = { "AC_BE", "AC_BK", "AC_VI", "AC_VO" }; |
| 208 | #endif |
| 209 | |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 210 | static const u8 acbitmap2maxprio[] = { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 211 | PRIO_8021D_BE, PRIO_8021D_BE, PRIO_8021D_BK, PRIO_8021D_BK, |
| 212 | PRIO_8021D_VI, PRIO_8021D_VI, PRIO_8021D_VI, PRIO_8021D_VI, |
| 213 | PRIO_8021D_VO, PRIO_8021D_VO, PRIO_8021D_VO, PRIO_8021D_VO, |
| 214 | PRIO_8021D_VO, PRIO_8021D_VO, PRIO_8021D_VO, PRIO_8021D_VO |
| 215 | }; |
| 216 | |
| 217 | /* currently the best mechanism for determining SIFS is the band in use */ |
| 218 | #define SIFS(band) ((band)->bandtype == WLC_BAND_5G ? APHY_SIFS_TIME : BPHY_SIFS_TIME); |
| 219 | |
| 220 | /* value for # replay counters currently supported */ |
| 221 | #define WLC_REPLAY_CNTRS_VALUE WPA_CAP_16_REPLAY_CNTRS |
| 222 | |
| 223 | /* local prototypes */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 224 | static u16 BCMFASTPATH wlc_d11hdrs_mac80211(wlc_info_t *wlc, |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 225 | struct ieee80211_hw *hw, |
| 226 | struct sk_buff *p, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 227 | struct scb *scb, uint frag, |
| 228 | uint nfrags, uint queue, |
| 229 | uint next_frag_len, |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 230 | wsec_key_t *key, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 231 | ratespec_t rspec_override); |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 232 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 233 | static void wlc_bss_default_init(wlc_info_t *wlc); |
| 234 | static void wlc_ucode_mac_upd(wlc_info_t *wlc); |
| 235 | static ratespec_t mac80211_wlc_set_nrate(wlc_info_t *wlc, wlcband_t *cur_band, |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 236 | u32 int_val); |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 237 | static void wlc_tx_prec_map_init(wlc_info_t *wlc); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 238 | static void wlc_watchdog(void *arg); |
| 239 | static void wlc_watchdog_by_timer(void *arg); |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 240 | static int wlc_set_rateset(wlc_info_t *wlc, wlc_rateset_t *rs_arg); |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 241 | static int wlc_iovar_rangecheck(wlc_info_t *wlc, u32 val, |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 242 | const bcm_iovar_t *vi); |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 243 | static u8 wlc_local_constraint_qdbm(wlc_info_t *wlc); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 244 | |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 245 | /* send and receive */ |
Brett Rudley | e69284f | 2010-11-16 15:45:48 -0800 | [diff] [blame] | 246 | static wlc_txq_info_t *wlc_txq_alloc(wlc_info_t *wlc, struct osl_info *osh); |
| 247 | static void wlc_txq_free(wlc_info_t *wlc, struct osl_info *osh, |
| 248 | wlc_txq_info_t *qi); |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 249 | static void wlc_txflowcontrol_signal(wlc_info_t *wlc, wlc_txq_info_t *qi, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 250 | bool on, int prio); |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 251 | static void wlc_txflowcontrol_reset(wlc_info_t *wlc); |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 252 | static u16 wlc_compute_airtime(wlc_info_t *wlc, ratespec_t rspec, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 253 | uint length); |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 254 | static void wlc_compute_cck_plcp(ratespec_t rate, uint length, u8 *plcp); |
| 255 | static void wlc_compute_ofdm_plcp(ratespec_t rate, uint length, u8 *plcp); |
| 256 | static void wlc_compute_mimo_plcp(ratespec_t rate, uint length, u8 *plcp); |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 257 | static u16 wlc_compute_frame_dur(wlc_info_t *wlc, ratespec_t rate, |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 258 | u8 preamble_type, uint next_frag_len); |
Brett Rudley | e69284f | 2010-11-16 15:45:48 -0800 | [diff] [blame] | 259 | static void wlc_recvctl(wlc_info_t *wlc, struct osl_info *osh, d11rxhdr_t *rxh, |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 260 | struct sk_buff *p); |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 261 | static uint wlc_calc_frame_len(wlc_info_t *wlc, ratespec_t rate, |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 262 | u8 preamble_type, uint dur); |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 263 | static uint wlc_calc_ack_time(wlc_info_t *wlc, ratespec_t rate, |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 264 | u8 preamble_type); |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 265 | static uint wlc_calc_cts_time(wlc_info_t *wlc, ratespec_t rate, |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 266 | u8 preamble_type); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 267 | /* interrupt, up/down, band */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 268 | static void wlc_setband(wlc_info_t *wlc, uint bandunit); |
| 269 | static chanspec_t wlc_init_chanspec(wlc_info_t *wlc); |
| 270 | static void wlc_bandinit_ordered(wlc_info_t *wlc, chanspec_t chanspec); |
| 271 | static void wlc_bsinit(wlc_info_t *wlc); |
| 272 | static int wlc_duty_cycle_set(wlc_info_t *wlc, int duty_cycle, bool isOFDM, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 273 | bool writeToShm); |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 274 | static void wlc_radio_hwdisable_upd(wlc_info_t *wlc); |
| 275 | static bool wlc_radio_monitor_start(wlc_info_t *wlc); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 276 | static void wlc_radio_timer(void *arg); |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 277 | static void wlc_radio_enable(wlc_info_t *wlc); |
| 278 | static void wlc_radio_upd(wlc_info_t *wlc); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 279 | |
| 280 | /* scan, association, BSS */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 281 | static uint wlc_calc_ba_time(wlc_info_t *wlc, ratespec_t rate, |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 282 | u8 preamble_type); |
| 283 | static void wlc_update_mimo_band_bwcap(wlc_info_t *wlc, u8 bwcap); |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 284 | static void wlc_ht_update_sgi_rx(wlc_info_t *wlc, int val); |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 285 | void wlc_ht_mimops_cap_update(wlc_info_t *wlc, u8 mimops_mode); |
Greg Kroah-Hartman | 562c885 | 2010-10-05 11:04:17 -0700 | [diff] [blame] | 286 | static void wlc_ht_update_ldpc(wlc_info_t *wlc, s8 val); |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 287 | static void wlc_war16165(wlc_info_t *wlc, bool tx); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 288 | |
| 289 | static void wlc_process_eventq(void *arg); |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 290 | static void wlc_wme_retries_write(wlc_info_t *wlc); |
| 291 | static bool wlc_attach_stf_ant_init(wlc_info_t *wlc); |
| 292 | static uint wlc_attach_module(wlc_info_t *wlc); |
| 293 | static void wlc_detach_module(wlc_info_t *wlc); |
| 294 | static void wlc_timers_deinit(wlc_info_t *wlc); |
| 295 | static void wlc_down_led_upd(wlc_info_t *wlc); |
| 296 | static uint wlc_down_del_timer(wlc_info_t *wlc); |
| 297 | static void wlc_ofdm_rateset_war(wlc_info_t *wlc); |
| 298 | static int _wlc_ioctl(wlc_info_t *wlc, int cmd, void *arg, int len, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 299 | struct wlc_if *wlcif); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 300 | |
| 301 | #if defined(BCMDBG) |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 302 | void wlc_get_rcmta(wlc_info_t *wlc, int idx, struct ether_addr *addr) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 303 | { |
| 304 | d11regs_t *regs = wlc->regs; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 305 | u32 v32; |
Brett Rudley | e69284f | 2010-11-16 15:45:48 -0800 | [diff] [blame] | 306 | struct osl_info *osh; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 307 | |
| 308 | WL_TRACE(("wl%d: %s\n", WLCWLUNIT(wlc), __func__)); |
| 309 | |
| 310 | ASSERT(wlc->pub->corerev > 4); |
| 311 | |
| 312 | osh = wlc->osh; |
| 313 | |
| 314 | W_REG(osh, ®s->objaddr, (OBJADDR_RCMTA_SEL | (idx * 2))); |
| 315 | (void)R_REG(osh, ®s->objaddr); |
| 316 | v32 = R_REG(osh, ®s->objdata); |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 317 | addr->octet[0] = (u8) v32; |
| 318 | addr->octet[1] = (u8) (v32 >> 8); |
| 319 | addr->octet[2] = (u8) (v32 >> 16); |
| 320 | addr->octet[3] = (u8) (v32 >> 24); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 321 | W_REG(osh, ®s->objaddr, (OBJADDR_RCMTA_SEL | ((idx * 2) + 1))); |
| 322 | (void)R_REG(osh, ®s->objaddr); |
Greg Kroah-Hartman | e88cf8e | 2010-10-12 13:20:19 -0700 | [diff] [blame] | 323 | v32 = R_REG(osh, (volatile u16 *)®s->objdata); |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 324 | addr->octet[4] = (u8) v32; |
| 325 | addr->octet[5] = (u8) (v32 >> 8); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 326 | } |
| 327 | #endif /* defined(BCMDBG) */ |
| 328 | |
| 329 | /* keep the chip awake if needed */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 330 | bool wlc_stay_awake(wlc_info_t *wlc) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 331 | { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 332 | return true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | /* conditions under which the PM bit should be set in outgoing frames and STAY_AWAKE is meaningful |
| 336 | */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 337 | bool wlc_ps_allowed(wlc_info_t *wlc) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 338 | { |
| 339 | int idx; |
| 340 | wlc_bsscfg_t *cfg; |
| 341 | |
| 342 | /* disallow PS when one of the following global conditions meets */ |
| 343 | if (!wlc->pub->associated || !wlc->PMenabled || wlc->PM_override) |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 344 | return false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 345 | |
| 346 | /* disallow PS when one of these meets when not scanning */ |
| 347 | if (!wlc->PMblocked) { |
| 348 | if (AP_ACTIVE(wlc) || wlc->monitor) |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 349 | return false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | FOREACH_AS_STA(wlc, idx, cfg) { |
| 353 | /* disallow PS when one of the following bsscfg specific conditions meets */ |
| 354 | if (!cfg->BSS || !WLC_PORTOPEN(cfg)) |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 355 | return false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 356 | |
| 357 | if (!cfg->dtim_programmed) |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 358 | return false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 359 | } |
| 360 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 361 | return true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 362 | } |
| 363 | |
Jason Cooper | b4f790e | 2010-10-11 10:02:58 -0400 | [diff] [blame] | 364 | void wlc_reset(wlc_info_t *wlc) |
Jason Cooper | a2627bc | 2010-09-14 09:45:31 -0400 | [diff] [blame] | 365 | { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 366 | WL_TRACE(("wl%d: wlc_reset\n", wlc->pub->unit)); |
| 367 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 368 | wlc->check_for_unaligned_tbtt = false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 369 | |
| 370 | /* slurp up hw mac counters before core reset */ |
| 371 | if (WLC_UPDATE_STATS(wlc)) { |
| 372 | wlc_statsupd(wlc); |
| 373 | |
| 374 | /* reset our snapshot of macstat counters */ |
Brett Rudley | 9249ede | 2010-11-30 20:09:49 -0800 | [diff] [blame^] | 375 | memset((char *)wlc->core->macstat_snapshot, 0, |
| 376 | sizeof(macstat_t)); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | wlc_bmac_reset(wlc->hw); |
| 380 | wlc_ampdu_reset(wlc->ampdu); |
| 381 | wlc->txretried = 0; |
| 382 | |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 383 | } |
| 384 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 385 | void wlc_fatal_error(wlc_info_t *wlc) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 386 | { |
| 387 | WL_ERROR(("wl%d: fatal error, reinitializing\n", wlc->pub->unit)); |
| 388 | wl_init(wlc->wl); |
| 389 | } |
| 390 | |
| 391 | /* Return the channel the driver should initialize during wlc_init. |
| 392 | * the channel may have to be changed from the currently configured channel |
| 393 | * if other configurations are in conflict (bandlocked, 11n mode disabled, |
| 394 | * invalid channel for current country, etc.) |
| 395 | */ |
Jason Cooper | b4f790e | 2010-10-11 10:02:58 -0400 | [diff] [blame] | 396 | static chanspec_t wlc_init_chanspec(wlc_info_t *wlc) |
Jason Cooper | a2627bc | 2010-09-14 09:45:31 -0400 | [diff] [blame] | 397 | { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 398 | chanspec_t chanspec = |
| 399 | 1 | WL_CHANSPEC_BW_20 | WL_CHANSPEC_CTL_SB_NONE | |
| 400 | WL_CHANSPEC_BAND_2G; |
| 401 | |
| 402 | /* make sure the channel is on the supported band if we are band-restricted */ |
| 403 | if (wlc->bandlocked || NBANDS(wlc) == 1) { |
| 404 | ASSERT(CHSPEC_WLCBANDUNIT(chanspec) == wlc->band->bandunit); |
| 405 | } |
| 406 | ASSERT(wlc_valid_chanspec_db(wlc->cmi, chanspec)); |
| 407 | return chanspec; |
| 408 | } |
| 409 | |
| 410 | struct scb global_scb; |
| 411 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 412 | static void wlc_init_scb(wlc_info_t *wlc, struct scb *scb) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 413 | { |
| 414 | int i; |
| 415 | scb->flags = SCB_WMECAP | SCB_HTCAP; |
| 416 | for (i = 0; i < NUMPRIO; i++) |
| 417 | scb->seqnum[i] = 0; |
| 418 | } |
| 419 | |
Jason Cooper | b4f790e | 2010-10-11 10:02:58 -0400 | [diff] [blame] | 420 | void wlc_init(wlc_info_t *wlc) |
Jason Cooper | a2627bc | 2010-09-14 09:45:31 -0400 | [diff] [blame] | 421 | { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 422 | d11regs_t *regs; |
| 423 | chanspec_t chanspec; |
| 424 | int i; |
| 425 | wlc_bsscfg_t *bsscfg; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 426 | bool mute = false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 427 | |
| 428 | WL_TRACE(("wl%d: wlc_init\n", wlc->pub->unit)); |
| 429 | |
| 430 | regs = wlc->regs; |
| 431 | |
| 432 | /* This will happen if a big-hammer was executed. In that case, we want to go back |
| 433 | * to the channel that we were on and not new channel |
| 434 | */ |
| 435 | if (wlc->pub->associated) |
| 436 | chanspec = wlc->home_chanspec; |
| 437 | else |
| 438 | chanspec = wlc_init_chanspec(wlc); |
| 439 | |
| 440 | wlc_bmac_init(wlc->hw, chanspec, mute); |
| 441 | |
| 442 | wlc->seckeys = wlc_bmac_read_shm(wlc->hw, M_SECRXKEYS_PTR) * 2; |
| 443 | if (D11REV_GE(wlc->pub->corerev, 15) && (wlc->machwcap & MCAP_TKIPMIC)) |
| 444 | wlc->tkmickeys = |
| 445 | wlc_bmac_read_shm(wlc->hw, M_TKMICKEYS_PTR) * 2; |
| 446 | |
| 447 | /* update beacon listen interval */ |
| 448 | wlc_bcn_li_upd(wlc); |
| 449 | wlc->bcn_wait_prd = |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 450 | (u8) (wlc_bmac_read_shm(wlc->hw, M_NOSLPZNATDTIM) >> 10); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 451 | ASSERT(wlc->bcn_wait_prd > 0); |
| 452 | |
| 453 | /* the world is new again, so is our reported rate */ |
| 454 | wlc_reprate_init(wlc); |
| 455 | |
| 456 | /* write ethernet address to core */ |
| 457 | FOREACH_BSS(wlc, i, bsscfg) { |
| 458 | wlc_set_mac(bsscfg); |
| 459 | wlc_set_bssid(bsscfg); |
| 460 | } |
| 461 | |
| 462 | /* Update tsf_cfprep if associated and up */ |
| 463 | if (wlc->pub->associated) { |
| 464 | FOREACH_BSS(wlc, i, bsscfg) { |
| 465 | if (bsscfg->up) { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 466 | u32 bi; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 467 | |
| 468 | /* get beacon period from bsscfg and convert to uS */ |
| 469 | bi = bsscfg->current_bss->beacon_period << 10; |
| 470 | /* update the tsf_cfprep register */ |
| 471 | /* since init path would reset to default value */ |
| 472 | W_REG(wlc->osh, ®s->tsf_cfprep, |
| 473 | (bi << CFPREP_CBI_SHIFT)); |
| 474 | |
| 475 | /* Update maccontrol PM related bits */ |
| 476 | wlc_set_ps_ctrl(wlc); |
| 477 | |
| 478 | break; |
| 479 | } |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | wlc_key_hw_init_all(wlc); |
| 484 | |
| 485 | wlc_bandinit_ordered(wlc, chanspec); |
| 486 | |
| 487 | wlc_init_scb(wlc, &global_scb); |
| 488 | |
| 489 | /* init probe response timeout */ |
| 490 | wlc_write_shm(wlc, M_PRS_MAXTIME, wlc->prb_resp_timeout); |
| 491 | |
| 492 | /* init max burst txop (framebursting) */ |
| 493 | wlc_write_shm(wlc, M_MBURST_TXOP, |
| 494 | (wlc-> |
| 495 | _rifs ? (EDCF_AC_VO_TXOP_AP << 5) : MAXFRAMEBURST_TXOP)); |
| 496 | |
| 497 | /* initialize maximum allowed duty cycle */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 498 | wlc_duty_cycle_set(wlc, wlc->tx_duty_cycle_ofdm, true, true); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 499 | wlc_duty_cycle_set(wlc, wlc->tx_duty_cycle_cck, false, true); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 500 | |
| 501 | /* Update some shared memory locations related to max AMPDU size allowed to received */ |
| 502 | wlc_ampdu_shm_upd(wlc->ampdu); |
| 503 | |
| 504 | /* band-specific inits */ |
| 505 | wlc_bsinit(wlc); |
| 506 | |
| 507 | /* Enable EDCF mode (while the MAC is suspended) */ |
| 508 | if (EDCF_ENAB(wlc->pub)) { |
| 509 | OR_REG(wlc->osh, ®s->ifs_ctl, IFS_USEEDCF); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 510 | wlc_edcf_setparams(wlc->cfg, false); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | /* Init precedence maps for empty FIFOs */ |
| 514 | wlc_tx_prec_map_init(wlc); |
| 515 | |
| 516 | /* read the ucode version if we have not yet done so */ |
| 517 | if (wlc->ucode_rev == 0) { |
| 518 | wlc->ucode_rev = |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 519 | wlc_read_shm(wlc, M_BOM_REV_MAJOR) << NBITS(u16); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 520 | wlc->ucode_rev |= wlc_read_shm(wlc, M_BOM_REV_MINOR); |
| 521 | } |
| 522 | |
| 523 | /* ..now really unleash hell (allow the MAC out of suspend) */ |
| 524 | wlc_enable_mac(wlc); |
| 525 | |
| 526 | /* clear tx flow control */ |
| 527 | wlc_txflowcontrol_reset(wlc); |
| 528 | |
| 529 | /* clear tx data fifo suspends */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 530 | wlc->tx_suspended = false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 531 | |
| 532 | /* enable the RF Disable Delay timer */ |
| 533 | if (D11REV_GE(wlc->pub->corerev, 10)) |
| 534 | W_REG(wlc->osh, &wlc->regs->rfdisabledly, RFDISABLE_DEFAULT); |
| 535 | |
| 536 | /* initialize mpc delay */ |
| 537 | wlc->mpc_delay_off = wlc->mpc_dlycnt = WLC_MPC_MIN_DELAYCNT; |
| 538 | |
| 539 | /* |
| 540 | * Initialize WME parameters; if they haven't been set by some other |
| 541 | * mechanism (IOVar, etc) then read them from the hardware. |
| 542 | */ |
| 543 | if (WLC_WME_RETRY_SHORT_GET(wlc, 0) == 0) { /* Unintialized; read from HW */ |
| 544 | int ac; |
| 545 | |
| 546 | ASSERT(wlc->clk); |
| 547 | for (ac = 0; ac < AC_COUNT; ac++) { |
| 548 | wlc->wme_retries[ac] = |
| 549 | wlc_read_shm(wlc, M_AC_TXLMT_ADDR(ac)); |
| 550 | } |
| 551 | } |
| 552 | } |
| 553 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 554 | void wlc_mac_bcn_promisc_change(wlc_info_t *wlc, bool promisc) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 555 | { |
| 556 | wlc->bcnmisc_monitor = promisc; |
| 557 | wlc_mac_bcn_promisc(wlc); |
| 558 | } |
| 559 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 560 | void wlc_mac_bcn_promisc(wlc_info_t *wlc) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 561 | { |
| 562 | if ((AP_ENAB(wlc->pub) && (N_ENAB(wlc->pub) || wlc->band->gmode)) || |
| 563 | wlc->bcnmisc_ibss || wlc->bcnmisc_scan || wlc->bcnmisc_monitor) |
| 564 | wlc_mctrl(wlc, MCTL_BCNS_PROMISC, MCTL_BCNS_PROMISC); |
| 565 | else |
| 566 | wlc_mctrl(wlc, MCTL_BCNS_PROMISC, 0); |
| 567 | } |
| 568 | |
| 569 | /* set or clear maccontrol bits MCTL_PROMISC and MCTL_KEEPCONTROL */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 570 | void wlc_mac_promisc(wlc_info_t *wlc) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 571 | { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 572 | u32 promisc_bits = 0; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 573 | |
| 574 | /* promiscuous mode just sets MCTL_PROMISC |
| 575 | * Note: APs get all BSS traffic without the need to set the MCTL_PROMISC bit |
| 576 | * since all BSS data traffic is directed at the AP |
| 577 | */ |
| 578 | if (PROMISC_ENAB(wlc->pub) && !AP_ENAB(wlc->pub) && !wlc->wet) |
| 579 | promisc_bits |= MCTL_PROMISC; |
| 580 | |
| 581 | /* monitor mode needs both MCTL_PROMISC and MCTL_KEEPCONTROL |
| 582 | * Note: monitor mode also needs MCTL_BCNS_PROMISC, but that is |
| 583 | * handled in wlc_mac_bcn_promisc() |
| 584 | */ |
| 585 | if (MONITOR_ENAB(wlc)) |
| 586 | promisc_bits |= MCTL_PROMISC | MCTL_KEEPCONTROL; |
| 587 | |
| 588 | wlc_mctrl(wlc, MCTL_PROMISC | MCTL_KEEPCONTROL, promisc_bits); |
| 589 | } |
| 590 | |
| 591 | /* check if hps and wake states of sw and hw are in sync */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 592 | bool wlc_ps_check(wlc_info_t *wlc) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 593 | { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 594 | bool res = true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 595 | bool hps, wake; |
| 596 | bool wake_ok; |
| 597 | |
| 598 | if (!AP_ACTIVE(wlc)) { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 599 | volatile u32 tmp; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 600 | tmp = R_REG(wlc->osh, &wlc->regs->maccontrol); |
| 601 | |
| 602 | /* If deviceremoved is detected, then don't take any action as this can be called |
| 603 | * in any context. Assume that caller will take care of the condition. This is just |
| 604 | * to avoid assert |
| 605 | */ |
| 606 | if (tmp == 0xffffffff) { |
| 607 | WL_ERROR(("wl%d: %s: dead chip\n", wlc->pub->unit, |
| 608 | __func__)); |
| 609 | return DEVICEREMOVED(wlc); |
| 610 | } |
| 611 | |
| 612 | hps = PS_ALLOWED(wlc); |
| 613 | |
| 614 | if (hps != ((tmp & MCTL_HPS) != 0)) { |
| 615 | int idx; |
| 616 | wlc_bsscfg_t *cfg; |
| 617 | WL_ERROR(("wl%d: hps not sync, sw %d, maccontrol 0x%x\n", wlc->pub->unit, hps, tmp)); |
| 618 | FOREACH_BSS(wlc, idx, cfg) { |
| 619 | if (!BSSCFG_STA(cfg)) |
| 620 | continue; |
| 621 | } |
| 622 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 623 | res = false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 624 | } |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 625 | /* For a monolithic build the wake check can be exact since it looks at wake |
| 626 | * override bits. The MCTL_WAKE bit should match the 'wake' value. |
| 627 | */ |
| 628 | wake = STAY_AWAKE(wlc) || wlc->hw->wake_override; |
| 629 | wake_ok = (wake == ((tmp & MCTL_WAKE) != 0)); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 630 | if (hps && !wake_ok) { |
| 631 | WL_ERROR(("wl%d: wake not sync, sw %d maccontrol 0x%x\n", wlc->pub->unit, wake, tmp)); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 632 | res = false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 633 | } |
| 634 | } |
| 635 | ASSERT(res); |
| 636 | return res; |
| 637 | } |
| 638 | |
| 639 | /* push sw hps and wake state through hardware */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 640 | void wlc_set_ps_ctrl(wlc_info_t *wlc) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 641 | { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 642 | u32 v1, v2; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 643 | bool hps, wake; |
| 644 | bool awake_before; |
| 645 | |
| 646 | hps = PS_ALLOWED(wlc); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 647 | wake = hps ? (STAY_AWAKE(wlc)) : true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 648 | |
| 649 | WL_TRACE(("wl%d: wlc_set_ps_ctrl: hps %d wake %d\n", wlc->pub->unit, |
| 650 | hps, wake)); |
| 651 | |
| 652 | v1 = R_REG(wlc->osh, &wlc->regs->maccontrol); |
| 653 | v2 = 0; |
| 654 | if (hps) |
| 655 | v2 |= MCTL_HPS; |
| 656 | if (wake) |
| 657 | v2 |= MCTL_WAKE; |
| 658 | |
| 659 | wlc_mctrl(wlc, MCTL_WAKE | MCTL_HPS, v2); |
| 660 | |
| 661 | awake_before = ((v1 & MCTL_WAKE) || ((v1 & MCTL_HPS) == 0)); |
| 662 | |
| 663 | if (wake && !awake_before) |
| 664 | wlc_bmac_wait_for_wake(wlc->hw); |
| 665 | |
| 666 | } |
| 667 | |
| 668 | /* |
| 669 | * Write this BSS config's MAC address to core. |
| 670 | * Updates RXE match engine. |
| 671 | */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 672 | int wlc_set_mac(wlc_bsscfg_t *cfg) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 673 | { |
| 674 | int err = 0; |
| 675 | wlc_info_t *wlc = cfg->wlc; |
| 676 | |
| 677 | if (cfg == wlc->cfg) { |
| 678 | /* enter the MAC addr into the RXE match registers */ |
| 679 | wlc_set_addrmatch(wlc, RCM_MAC_OFFSET, &cfg->cur_etheraddr); |
| 680 | } |
| 681 | |
| 682 | wlc_ampdu_macaddr_upd(wlc); |
| 683 | |
| 684 | return err; |
| 685 | } |
| 686 | |
| 687 | /* Write the BSS config's BSSID address to core (set_bssid in d11procs.tcl). |
| 688 | * Updates RXE match engine. |
| 689 | */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 690 | void wlc_set_bssid(wlc_bsscfg_t *cfg) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 691 | { |
| 692 | wlc_info_t *wlc = cfg->wlc; |
| 693 | |
| 694 | /* if primary config, we need to update BSSID in RXE match registers */ |
| 695 | if (cfg == wlc->cfg) { |
| 696 | wlc_set_addrmatch(wlc, RCM_BSSID_OFFSET, &cfg->BSSID); |
| 697 | } |
| 698 | #ifdef SUPPORT_HWKEYS |
| 699 | else if (BSSCFG_STA(cfg) && cfg->BSS) { |
| 700 | wlc_rcmta_add_bssid(wlc, cfg); |
| 701 | } |
| 702 | #endif |
| 703 | } |
| 704 | |
| 705 | /* |
| 706 | * Suspend the the MAC and update the slot timing |
| 707 | * for standard 11b/g (20us slots) or shortslot 11g (9us slots). |
| 708 | */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 709 | void wlc_switch_shortslot(wlc_info_t *wlc, bool shortslot) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 710 | { |
| 711 | int idx; |
| 712 | wlc_bsscfg_t *cfg; |
| 713 | |
| 714 | ASSERT(wlc->band->gmode); |
| 715 | |
| 716 | /* use the override if it is set */ |
| 717 | if (wlc->shortslot_override != WLC_SHORTSLOT_AUTO) |
| 718 | shortslot = (wlc->shortslot_override == WLC_SHORTSLOT_ON); |
| 719 | |
| 720 | if (wlc->shortslot == shortslot) |
| 721 | return; |
| 722 | |
| 723 | wlc->shortslot = shortslot; |
| 724 | |
| 725 | /* update the capability based on current shortslot mode */ |
| 726 | FOREACH_BSS(wlc, idx, cfg) { |
| 727 | if (!cfg->associated) |
| 728 | continue; |
| 729 | cfg->current_bss->capability &= ~DOT11_CAP_SHORTSLOT; |
| 730 | if (wlc->shortslot) |
| 731 | cfg->current_bss->capability |= DOT11_CAP_SHORTSLOT; |
| 732 | } |
| 733 | |
| 734 | wlc_bmac_set_shortslot(wlc->hw, shortslot); |
| 735 | } |
| 736 | |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 737 | static u8 wlc_local_constraint_qdbm(wlc_info_t *wlc) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 738 | { |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 739 | u8 local; |
Greg Kroah-Hartman | e59fe08 | 2010-10-07 17:08:21 -0700 | [diff] [blame] | 740 | s16 local_max; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 741 | |
| 742 | local = WLC_TXPWR_MAX; |
| 743 | if (wlc->pub->associated && |
| 744 | (wf_chspec_ctlchan(wlc->chanspec) == |
| 745 | wf_chspec_ctlchan(wlc->home_chanspec))) { |
| 746 | |
| 747 | /* get the local power constraint if we are on the AP's |
| 748 | * channel [802.11h, 7.3.2.13] |
| 749 | */ |
| 750 | /* Clamp the value between 0 and WLC_TXPWR_MAX w/o overflowing the target */ |
| 751 | local_max = |
| 752 | (wlc->txpwr_local_max - |
| 753 | wlc->txpwr_local_constraint) * WLC_TXPWR_DB_FACTOR; |
| 754 | if (local_max > 0 && local_max < WLC_TXPWR_MAX) |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 755 | return (u8) local_max; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 756 | if (local_max < 0) |
| 757 | return 0; |
| 758 | } |
| 759 | |
| 760 | return local; |
| 761 | } |
| 762 | |
| 763 | /* propagate home chanspec to all bsscfgs in case bsscfg->current_bss->chanspec is referenced */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 764 | void wlc_set_home_chanspec(wlc_info_t *wlc, chanspec_t chanspec) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 765 | { |
| 766 | if (wlc->home_chanspec != chanspec) { |
| 767 | int idx; |
| 768 | wlc_bsscfg_t *cfg; |
| 769 | |
| 770 | wlc->home_chanspec = chanspec; |
| 771 | |
| 772 | FOREACH_BSS(wlc, idx, cfg) { |
| 773 | if (!cfg->associated) |
| 774 | continue; |
| 775 | cfg->target_bss->chanspec = chanspec; |
| 776 | cfg->current_bss->chanspec = chanspec; |
| 777 | } |
| 778 | |
| 779 | } |
| 780 | } |
| 781 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 782 | static void wlc_set_phy_chanspec(wlc_info_t *wlc, chanspec_t chanspec) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 783 | { |
| 784 | /* Save our copy of the chanspec */ |
| 785 | wlc->chanspec = chanspec; |
| 786 | |
| 787 | /* Set the chanspec and power limits for this locale after computing |
| 788 | * any 11h local tx power constraints. |
| 789 | */ |
| 790 | wlc_channel_set_chanspec(wlc->cmi, chanspec, |
| 791 | wlc_local_constraint_qdbm(wlc)); |
| 792 | |
| 793 | if (wlc->stf->ss_algosel_auto) |
| 794 | wlc_stf_ss_algo_channel_get(wlc, &wlc->stf->ss_algo_channel, |
| 795 | chanspec); |
| 796 | |
| 797 | wlc_stf_ss_update(wlc, wlc->band); |
| 798 | |
| 799 | } |
| 800 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 801 | void wlc_set_chanspec(wlc_info_t *wlc, chanspec_t chanspec) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 802 | { |
| 803 | uint bandunit; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 804 | bool switchband = false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 805 | chanspec_t old_chanspec = wlc->chanspec; |
| 806 | |
| 807 | if (!wlc_valid_chanspec_db(wlc->cmi, chanspec)) { |
| 808 | WL_ERROR(("wl%d: %s: Bad channel %d\n", |
| 809 | wlc->pub->unit, __func__, CHSPEC_CHANNEL(chanspec))); |
| 810 | ASSERT(wlc_valid_chanspec_db(wlc->cmi, chanspec)); |
| 811 | return; |
| 812 | } |
| 813 | |
| 814 | /* Switch bands if necessary */ |
| 815 | if (NBANDS(wlc) > 1) { |
| 816 | bandunit = CHSPEC_WLCBANDUNIT(chanspec); |
| 817 | if (wlc->band->bandunit != bandunit || wlc->bandinit_pending) { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 818 | switchband = true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 819 | if (wlc->bandlocked) { |
| 820 | WL_ERROR(("wl%d: %s: chspec %d band is locked!\n", wlc->pub->unit, __func__, CHSPEC_CHANNEL(chanspec))); |
| 821 | return; |
| 822 | } |
| 823 | /* BMAC_NOTE: should the setband call come after the wlc_bmac_chanspec() ? |
| 824 | * if the setband updates (wlc_bsinit) use low level calls to inspect and |
| 825 | * set state, the state inspected may be from the wrong band, or the |
| 826 | * following wlc_bmac_set_chanspec() may undo the work. |
| 827 | */ |
| 828 | wlc_setband(wlc, bandunit); |
| 829 | } |
| 830 | } |
| 831 | |
| 832 | ASSERT(N_ENAB(wlc->pub) || !CHSPEC_IS40(chanspec)); |
| 833 | |
| 834 | /* sync up phy/radio chanspec */ |
| 835 | wlc_set_phy_chanspec(wlc, chanspec); |
| 836 | |
| 837 | /* init antenna selection */ |
| 838 | if (CHSPEC_WLC_BW(old_chanspec) != CHSPEC_WLC_BW(chanspec)) { |
| 839 | if (WLANTSEL_ENAB(wlc)) |
| 840 | wlc_antsel_init(wlc->asi); |
| 841 | |
| 842 | /* Fix the hardware rateset based on bw. |
| 843 | * Mainly add MCS32 for 40Mhz, remove MCS 32 for 20Mhz |
| 844 | */ |
| 845 | wlc_rateset_bw_mcs_filter(&wlc->band->hw_rateset, |
| 846 | wlc->band-> |
| 847 | mimo_cap_40 ? CHSPEC_WLC_BW(chanspec) |
| 848 | : 0); |
| 849 | } |
| 850 | |
| 851 | /* update some mac configuration since chanspec changed */ |
| 852 | wlc_ucode_mac_upd(wlc); |
| 853 | } |
| 854 | |
| 855 | #if defined(BCMDBG) |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 856 | static int wlc_get_current_txpwr(wlc_info_t *wlc, void *pwr, uint len) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 857 | { |
| 858 | txpwr_limits_t txpwr; |
| 859 | tx_power_t power; |
| 860 | tx_power_legacy_t *old_power = NULL; |
| 861 | int r, c; |
| 862 | uint qdbm; |
| 863 | bool override; |
| 864 | |
| 865 | if (len == sizeof(tx_power_legacy_t)) |
| 866 | old_power = (tx_power_legacy_t *) pwr; |
| 867 | else if (len < sizeof(tx_power_t)) |
| 868 | return BCME_BUFTOOSHORT; |
| 869 | |
Brett Rudley | 9249ede | 2010-11-30 20:09:49 -0800 | [diff] [blame^] | 870 | memset(&power, 0, sizeof(tx_power_t)); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 871 | |
| 872 | power.chanspec = WLC_BAND_PI_RADIO_CHANSPEC; |
| 873 | if (wlc->pub->associated) |
| 874 | power.local_chanspec = wlc->home_chanspec; |
| 875 | |
| 876 | /* Return the user target tx power limits for the various rates. Note wlc_phy.c's |
| 877 | * public interface only implements getting and setting a single value for all of |
| 878 | * rates, so we need to fill the array ourselves. |
| 879 | */ |
| 880 | wlc_phy_txpower_get(wlc->band->pi, &qdbm, &override); |
| 881 | for (r = 0; r < WL_TX_POWER_RATES; r++) { |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 882 | power.user_limit[r] = (u8) qdbm; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | power.local_max = wlc->txpwr_local_max * WLC_TXPWR_DB_FACTOR; |
| 886 | power.local_constraint = |
| 887 | wlc->txpwr_local_constraint * WLC_TXPWR_DB_FACTOR; |
| 888 | |
| 889 | power.antgain[0] = wlc->bandstate[BAND_2G_INDEX]->antgain; |
| 890 | power.antgain[1] = wlc->bandstate[BAND_5G_INDEX]->antgain; |
| 891 | |
| 892 | wlc_channel_reg_limits(wlc->cmi, power.chanspec, &txpwr); |
| 893 | |
| 894 | #if WL_TX_POWER_CCK_NUM != WLC_NUM_RATES_CCK |
| 895 | #error "WL_TX_POWER_CCK_NUM != WLC_NUM_RATES_CCK" |
| 896 | #endif |
| 897 | |
| 898 | /* CCK tx power limits */ |
| 899 | for (c = 0, r = WL_TX_POWER_CCK_FIRST; c < WL_TX_POWER_CCK_NUM; |
| 900 | c++, r++) |
| 901 | power.reg_limit[r] = txpwr.cck[c]; |
| 902 | |
| 903 | #if WL_TX_POWER_OFDM_NUM != WLC_NUM_RATES_OFDM |
| 904 | #error "WL_TX_POWER_OFDM_NUM != WLC_NUM_RATES_OFDM" |
| 905 | #endif |
| 906 | |
| 907 | /* 20 MHz OFDM SISO tx power limits */ |
| 908 | for (c = 0, r = WL_TX_POWER_OFDM_FIRST; c < WL_TX_POWER_OFDM_NUM; |
| 909 | c++, r++) |
| 910 | power.reg_limit[r] = txpwr.ofdm[c]; |
| 911 | |
| 912 | if (WLC_PHY_11N_CAP(wlc->band)) { |
| 913 | |
| 914 | /* 20 MHz OFDM CDD tx power limits */ |
| 915 | for (c = 0, r = WL_TX_POWER_OFDM20_CDD_FIRST; |
| 916 | c < WL_TX_POWER_OFDM_NUM; c++, r++) |
| 917 | power.reg_limit[r] = txpwr.ofdm_cdd[c]; |
| 918 | |
| 919 | /* 40 MHz OFDM SISO tx power limits */ |
| 920 | for (c = 0, r = WL_TX_POWER_OFDM40_SISO_FIRST; |
| 921 | c < WL_TX_POWER_OFDM_NUM; c++, r++) |
| 922 | power.reg_limit[r] = txpwr.ofdm_40_siso[c]; |
| 923 | |
| 924 | /* 40 MHz OFDM CDD tx power limits */ |
| 925 | for (c = 0, r = WL_TX_POWER_OFDM40_CDD_FIRST; |
| 926 | c < WL_TX_POWER_OFDM_NUM; c++, r++) |
| 927 | power.reg_limit[r] = txpwr.ofdm_40_cdd[c]; |
| 928 | |
| 929 | #if WL_TX_POWER_MCS_1_STREAM_NUM != WLC_NUM_RATES_MCS_1_STREAM |
| 930 | #error "WL_TX_POWER_MCS_1_STREAM_NUM != WLC_NUM_RATES_MCS_1_STREAM" |
| 931 | #endif |
| 932 | |
| 933 | /* 20MHz MCS0-7 SISO tx power limits */ |
| 934 | for (c = 0, r = WL_TX_POWER_MCS20_SISO_FIRST; |
| 935 | c < WLC_NUM_RATES_MCS_1_STREAM; c++, r++) |
| 936 | power.reg_limit[r] = txpwr.mcs_20_siso[c]; |
| 937 | |
| 938 | /* 20MHz MCS0-7 CDD tx power limits */ |
| 939 | for (c = 0, r = WL_TX_POWER_MCS20_CDD_FIRST; |
| 940 | c < WLC_NUM_RATES_MCS_1_STREAM; c++, r++) |
| 941 | power.reg_limit[r] = txpwr.mcs_20_cdd[c]; |
| 942 | |
| 943 | /* 20MHz MCS0-7 STBC tx power limits */ |
| 944 | for (c = 0, r = WL_TX_POWER_MCS20_STBC_FIRST; |
| 945 | c < WLC_NUM_RATES_MCS_1_STREAM; c++, r++) |
| 946 | power.reg_limit[r] = txpwr.mcs_20_stbc[c]; |
| 947 | |
| 948 | /* 40MHz MCS0-7 SISO tx power limits */ |
| 949 | for (c = 0, r = WL_TX_POWER_MCS40_SISO_FIRST; |
| 950 | c < WLC_NUM_RATES_MCS_1_STREAM; c++, r++) |
| 951 | power.reg_limit[r] = txpwr.mcs_40_siso[c]; |
| 952 | |
| 953 | /* 40MHz MCS0-7 CDD tx power limits */ |
| 954 | for (c = 0, r = WL_TX_POWER_MCS40_CDD_FIRST; |
| 955 | c < WLC_NUM_RATES_MCS_1_STREAM; c++, r++) |
| 956 | power.reg_limit[r] = txpwr.mcs_40_cdd[c]; |
| 957 | |
| 958 | /* 40MHz MCS0-7 STBC tx power limits */ |
| 959 | for (c = 0, r = WL_TX_POWER_MCS40_STBC_FIRST; |
| 960 | c < WLC_NUM_RATES_MCS_1_STREAM; c++, r++) |
| 961 | power.reg_limit[r] = txpwr.mcs_40_stbc[c]; |
| 962 | |
| 963 | #if WL_TX_POWER_MCS_2_STREAM_NUM != WLC_NUM_RATES_MCS_2_STREAM |
| 964 | #error "WL_TX_POWER_MCS_2_STREAM_NUM != WLC_NUM_RATES_MCS_2_STREAM" |
| 965 | #endif |
| 966 | |
| 967 | /* 20MHz MCS8-15 SDM tx power limits */ |
| 968 | for (c = 0, r = WL_TX_POWER_MCS20_SDM_FIRST; |
| 969 | c < WLC_NUM_RATES_MCS_2_STREAM; c++, r++) |
| 970 | power.reg_limit[r] = txpwr.mcs_20_mimo[c]; |
| 971 | |
| 972 | /* 40MHz MCS8-15 SDM tx power limits */ |
| 973 | for (c = 0, r = WL_TX_POWER_MCS40_SDM_FIRST; |
| 974 | c < WLC_NUM_RATES_MCS_2_STREAM; c++, r++) |
| 975 | power.reg_limit[r] = txpwr.mcs_40_mimo[c]; |
| 976 | |
| 977 | /* MCS 32 */ |
| 978 | power.reg_limit[WL_TX_POWER_MCS_32] = txpwr.mcs32; |
| 979 | } |
| 980 | |
| 981 | wlc_phy_txpower_get_current(wlc->band->pi, &power, |
| 982 | CHSPEC_CHANNEL(power.chanspec)); |
| 983 | |
| 984 | /* copy the tx_power_t struct to the return buffer, |
| 985 | * or convert to a tx_power_legacy_t struct |
| 986 | */ |
| 987 | if (!old_power) { |
| 988 | bcopy(&power, pwr, sizeof(tx_power_t)); |
| 989 | } else { |
| 990 | int band_idx = CHSPEC_IS2G(power.chanspec) ? 0 : 1; |
| 991 | |
Brett Rudley | 9249ede | 2010-11-30 20:09:49 -0800 | [diff] [blame^] | 992 | memset(old_power, 0, sizeof(tx_power_legacy_t)); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 993 | |
| 994 | old_power->txpwr_local_max = power.local_max; |
| 995 | old_power->txpwr_local_constraint = power.local_constraint; |
| 996 | if (CHSPEC_IS2G(power.chanspec)) { |
| 997 | old_power->txpwr_chan_reg_max = txpwr.cck[0]; |
| 998 | old_power->txpwr_est_Pout[band_idx] = |
| 999 | power.est_Pout_cck; |
| 1000 | old_power->txpwr_est_Pout_gofdm = power.est_Pout[0]; |
| 1001 | } else { |
| 1002 | old_power->txpwr_chan_reg_max = txpwr.ofdm[0]; |
| 1003 | old_power->txpwr_est_Pout[band_idx] = power.est_Pout[0]; |
| 1004 | } |
| 1005 | old_power->txpwr_antgain[0] = power.antgain[0]; |
| 1006 | old_power->txpwr_antgain[1] = power.antgain[1]; |
| 1007 | |
| 1008 | for (r = 0; r < NUM_PWRCTRL_RATES; r++) { |
| 1009 | old_power->txpwr_band_max[r] = power.user_limit[r]; |
| 1010 | old_power->txpwr_limit[r] = power.reg_limit[r]; |
| 1011 | old_power->txpwr_target[band_idx][r] = power.target[r]; |
| 1012 | if (CHSPEC_IS2G(power.chanspec)) |
| 1013 | old_power->txpwr_bphy_cck_max[r] = |
| 1014 | power.board_limit[r]; |
| 1015 | else |
| 1016 | old_power->txpwr_aphy_max[r] = |
| 1017 | power.board_limit[r]; |
| 1018 | } |
| 1019 | } |
| 1020 | |
| 1021 | return 0; |
| 1022 | } |
| 1023 | #endif /* defined(BCMDBG) */ |
| 1024 | |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1025 | static u32 wlc_watchdog_backup_bi(wlc_info_t *wlc) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1026 | { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1027 | u32 bi; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1028 | bi = 2 * wlc->cfg->current_bss->dtim_period * |
| 1029 | wlc->cfg->current_bss->beacon_period; |
| 1030 | if (wlc->bcn_li_dtim) |
| 1031 | bi *= wlc->bcn_li_dtim; |
| 1032 | else if (wlc->bcn_li_bcn) |
| 1033 | /* recalculate bi based on bcn_li_bcn */ |
| 1034 | bi = 2 * wlc->bcn_li_bcn * wlc->cfg->current_bss->beacon_period; |
| 1035 | |
| 1036 | if (bi < 2 * TIMER_INTERVAL_WATCHDOG) |
| 1037 | bi = 2 * TIMER_INTERVAL_WATCHDOG; |
| 1038 | return bi; |
| 1039 | } |
| 1040 | |
| 1041 | /* Change to run the watchdog either from a periodic timer or from tbtt handler. |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1042 | * Call watchdog from tbtt handler if tbtt is true, watchdog timer otherwise. |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1043 | */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 1044 | void wlc_watchdog_upd(wlc_info_t *wlc, bool tbtt) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1045 | { |
| 1046 | /* make sure changing watchdog driver is allowed */ |
| 1047 | if (!wlc->pub->up || !wlc->pub->align_wd_tbtt) |
| 1048 | return; |
| 1049 | if (!tbtt && wlc->WDarmed) { |
| 1050 | wl_del_timer(wlc->wl, wlc->wdtimer); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1051 | wlc->WDarmed = false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1052 | } |
| 1053 | |
| 1054 | /* stop watchdog timer and use tbtt interrupt to drive watchdog */ |
| 1055 | if (tbtt && wlc->WDarmed) { |
| 1056 | wl_del_timer(wlc->wl, wlc->wdtimer); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1057 | wlc->WDarmed = false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1058 | wlc->WDlast = OSL_SYSUPTIME(); |
| 1059 | } |
| 1060 | /* arm watchdog timer and drive the watchdog there */ |
| 1061 | else if (!tbtt && !wlc->WDarmed) { |
| 1062 | wl_add_timer(wlc->wl, wlc->wdtimer, TIMER_INTERVAL_WATCHDOG, |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1063 | true); |
| 1064 | wlc->WDarmed = true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1065 | } |
| 1066 | if (tbtt && !wlc->WDarmed) { |
| 1067 | wl_add_timer(wlc->wl, wlc->wdtimer, wlc_watchdog_backup_bi(wlc), |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1068 | true); |
| 1069 | wlc->WDarmed = true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1070 | } |
| 1071 | } |
| 1072 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 1073 | ratespec_t wlc_lowest_basic_rspec(wlc_info_t *wlc, wlc_rateset_t *rs) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1074 | { |
| 1075 | ratespec_t lowest_basic_rspec; |
| 1076 | uint i; |
| 1077 | |
| 1078 | /* Use the lowest basic rate */ |
| 1079 | lowest_basic_rspec = rs->rates[0] & RATE_MASK; |
| 1080 | for (i = 0; i < rs->count; i++) { |
| 1081 | if (rs->rates[i] & WLC_RATE_FLAG) { |
| 1082 | lowest_basic_rspec = rs->rates[i] & RATE_MASK; |
| 1083 | break; |
| 1084 | } |
| 1085 | } |
| 1086 | #if NCONF |
| 1087 | /* pick siso/cdd as default for OFDM (note no basic rate MCSs are supported yet) */ |
| 1088 | if (IS_OFDM(lowest_basic_rspec)) { |
| 1089 | lowest_basic_rspec |= (wlc->stf->ss_opmode << RSPEC_STF_SHIFT); |
| 1090 | } |
| 1091 | #endif |
| 1092 | |
Jason Cooper | 90ea229 | 2010-09-14 09:45:32 -0400 | [diff] [blame] | 1093 | return lowest_basic_rspec; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1094 | } |
| 1095 | |
| 1096 | /* This function changes the phytxctl for beacon based on current beacon ratespec AND txant |
| 1097 | * setting as per this table: |
| 1098 | * ratespec CCK ant = wlc->stf->txant |
| 1099 | * OFDM ant = 3 |
| 1100 | */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 1101 | void wlc_beacon_phytxctl_txant_upd(wlc_info_t *wlc, ratespec_t bcn_rspec) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1102 | { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 1103 | u16 phyctl; |
| 1104 | u16 phytxant = wlc->stf->phytxant; |
| 1105 | u16 mask = PHY_TXC_ANT_MASK; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1106 | |
| 1107 | /* for non-siso rates or default setting, use the available chains */ |
| 1108 | if (WLC_PHY_11N_CAP(wlc->band)) { |
| 1109 | phytxant = wlc_stf_phytxchain_sel(wlc, bcn_rspec); |
| 1110 | } |
| 1111 | |
| 1112 | phyctl = wlc_read_shm(wlc, M_BCN_PCTLWD); |
| 1113 | phyctl = (phyctl & ~mask) | phytxant; |
| 1114 | wlc_write_shm(wlc, M_BCN_PCTLWD, phyctl); |
| 1115 | } |
| 1116 | |
| 1117 | /* centralized protection config change function to simplify debugging, no consistency checking |
| 1118 | * this should be called only on changes to avoid overhead in periodic function |
| 1119 | */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 1120 | void wlc_protection_upd(wlc_info_t *wlc, uint idx, int val) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1121 | { |
| 1122 | WL_TRACE(("wlc_protection_upd: idx %d, val %d\n", idx, val)); |
| 1123 | |
| 1124 | switch (idx) { |
| 1125 | case WLC_PROT_G_SPEC: |
| 1126 | wlc->protection->_g = (bool) val; |
| 1127 | break; |
| 1128 | case WLC_PROT_G_OVR: |
Greg Kroah-Hartman | 562c885 | 2010-10-05 11:04:17 -0700 | [diff] [blame] | 1129 | wlc->protection->g_override = (s8) val; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1130 | break; |
| 1131 | case WLC_PROT_G_USER: |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 1132 | wlc->protection->gmode_user = (u8) val; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1133 | break; |
| 1134 | case WLC_PROT_OVERLAP: |
Greg Kroah-Hartman | 562c885 | 2010-10-05 11:04:17 -0700 | [diff] [blame] | 1135 | wlc->protection->overlap = (s8) val; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1136 | break; |
| 1137 | case WLC_PROT_N_USER: |
Greg Kroah-Hartman | 562c885 | 2010-10-05 11:04:17 -0700 | [diff] [blame] | 1138 | wlc->protection->nmode_user = (s8) val; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1139 | break; |
| 1140 | case WLC_PROT_N_CFG: |
Greg Kroah-Hartman | 562c885 | 2010-10-05 11:04:17 -0700 | [diff] [blame] | 1141 | wlc->protection->n_cfg = (s8) val; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1142 | break; |
| 1143 | case WLC_PROT_N_CFG_OVR: |
Greg Kroah-Hartman | 562c885 | 2010-10-05 11:04:17 -0700 | [diff] [blame] | 1144 | wlc->protection->n_cfg_override = (s8) val; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1145 | break; |
| 1146 | case WLC_PROT_N_NONGF: |
| 1147 | wlc->protection->nongf = (bool) val; |
| 1148 | break; |
| 1149 | case WLC_PROT_N_NONGF_OVR: |
Greg Kroah-Hartman | 562c885 | 2010-10-05 11:04:17 -0700 | [diff] [blame] | 1150 | wlc->protection->nongf_override = (s8) val; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1151 | break; |
| 1152 | case WLC_PROT_N_PAM_OVR: |
Greg Kroah-Hartman | 562c885 | 2010-10-05 11:04:17 -0700 | [diff] [blame] | 1153 | wlc->protection->n_pam_override = (s8) val; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1154 | break; |
| 1155 | case WLC_PROT_N_OBSS: |
| 1156 | wlc->protection->n_obss = (bool) val; |
| 1157 | break; |
| 1158 | |
| 1159 | default: |
| 1160 | ASSERT(0); |
| 1161 | break; |
| 1162 | } |
| 1163 | |
| 1164 | } |
| 1165 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 1166 | static void wlc_ht_update_sgi_rx(wlc_info_t *wlc, int val) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1167 | { |
| 1168 | wlc->ht_cap.cap &= ~(HT_CAP_SHORT_GI_20 | HT_CAP_SHORT_GI_40); |
| 1169 | wlc->ht_cap.cap |= (val & WLC_N_SGI_20) ? HT_CAP_SHORT_GI_20 : 0; |
| 1170 | wlc->ht_cap.cap |= (val & WLC_N_SGI_40) ? HT_CAP_SHORT_GI_40 : 0; |
| 1171 | |
| 1172 | if (wlc->pub->up) { |
| 1173 | wlc_update_beacon(wlc); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1174 | wlc_update_probe_resp(wlc, true); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1175 | } |
| 1176 | } |
| 1177 | |
Greg Kroah-Hartman | 562c885 | 2010-10-05 11:04:17 -0700 | [diff] [blame] | 1178 | static void wlc_ht_update_ldpc(wlc_info_t *wlc, s8 val) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1179 | { |
| 1180 | wlc->stf->ldpc = val; |
| 1181 | |
| 1182 | wlc->ht_cap.cap &= ~HT_CAP_LDPC_CODING; |
| 1183 | if (wlc->stf->ldpc != OFF) |
| 1184 | wlc->ht_cap.cap |= HT_CAP_LDPC_CODING; |
| 1185 | |
| 1186 | if (wlc->pub->up) { |
| 1187 | wlc_update_beacon(wlc); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1188 | wlc_update_probe_resp(wlc, true); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1189 | wlc_phy_ldpc_override_set(wlc->band->pi, (val ? true : false)); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1190 | } |
| 1191 | } |
| 1192 | |
| 1193 | /* |
| 1194 | * ucode, hwmac update |
| 1195 | * Channel dependent updates for ucode and hw |
| 1196 | */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 1197 | static void wlc_ucode_mac_upd(wlc_info_t *wlc) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1198 | { |
| 1199 | /* enable or disable any active IBSSs depending on whether or not |
| 1200 | * we are on the home channel |
| 1201 | */ |
| 1202 | if (wlc->home_chanspec == WLC_BAND_PI_RADIO_CHANSPEC) { |
| 1203 | if (wlc->pub->associated) { |
| 1204 | /* BMAC_NOTE: This is something that should be fixed in ucode inits. |
| 1205 | * I think that the ucode inits set up the bcn templates and shm values |
| 1206 | * with a bogus beacon. This should not be done in the inits. If ucode needs |
| 1207 | * to set up a beacon for testing, the test routines should write it down, |
| 1208 | * not expect the inits to populate a bogus beacon. |
| 1209 | */ |
| 1210 | if (WLC_PHY_11N_CAP(wlc->band)) { |
| 1211 | wlc_write_shm(wlc, M_BCN_TXTSF_OFFSET, |
| 1212 | wlc->band->bcntsfoff); |
| 1213 | } |
| 1214 | } |
| 1215 | } else { |
| 1216 | /* disable an active IBSS if we are not on the home channel */ |
| 1217 | } |
| 1218 | |
| 1219 | /* update the various promisc bits */ |
| 1220 | wlc_mac_bcn_promisc(wlc); |
| 1221 | wlc_mac_promisc(wlc); |
| 1222 | } |
| 1223 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 1224 | static void wlc_bandinit_ordered(wlc_info_t *wlc, chanspec_t chanspec) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1225 | { |
| 1226 | wlc_rateset_t default_rateset; |
| 1227 | uint parkband; |
| 1228 | uint i, band_order[2]; |
| 1229 | |
| 1230 | WL_TRACE(("wl%d: wlc_bandinit_ordered\n", wlc->pub->unit)); |
| 1231 | /* |
| 1232 | * We might have been bandlocked during down and the chip power-cycled (hibernate). |
| 1233 | * figure out the right band to park on |
| 1234 | */ |
| 1235 | if (wlc->bandlocked || NBANDS(wlc) == 1) { |
| 1236 | ASSERT(CHSPEC_WLCBANDUNIT(chanspec) == wlc->band->bandunit); |
| 1237 | |
| 1238 | parkband = wlc->band->bandunit; /* updated in wlc_bandlock() */ |
| 1239 | band_order[0] = band_order[1] = parkband; |
| 1240 | } else { |
| 1241 | /* park on the band of the specified chanspec */ |
| 1242 | parkband = CHSPEC_WLCBANDUNIT(chanspec); |
| 1243 | |
| 1244 | /* order so that parkband initialize last */ |
| 1245 | band_order[0] = parkband ^ 1; |
| 1246 | band_order[1] = parkband; |
| 1247 | } |
| 1248 | |
| 1249 | /* make each band operational, software state init */ |
| 1250 | for (i = 0; i < NBANDS(wlc); i++) { |
| 1251 | uint j = band_order[i]; |
| 1252 | |
| 1253 | wlc->band = wlc->bandstate[j]; |
| 1254 | |
| 1255 | wlc_default_rateset(wlc, &default_rateset); |
| 1256 | |
| 1257 | /* fill in hw_rate */ |
| 1258 | wlc_rateset_filter(&default_rateset, &wlc->band->hw_rateset, |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1259 | false, WLC_RATES_CCK_OFDM, RATE_MASK, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1260 | (bool) N_ENAB(wlc->pub)); |
| 1261 | |
| 1262 | /* init basic rate lookup */ |
| 1263 | wlc_rate_lookup_init(wlc, &default_rateset); |
| 1264 | } |
| 1265 | |
| 1266 | /* sync up phy/radio chanspec */ |
| 1267 | wlc_set_phy_chanspec(wlc, chanspec); |
| 1268 | } |
| 1269 | |
| 1270 | /* band-specific init */ |
Jason Cooper | a2627bc | 2010-09-14 09:45:31 -0400 | [diff] [blame] | 1271 | static void WLBANDINITFN(wlc_bsinit) (wlc_info_t *wlc) |
| 1272 | { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1273 | WL_TRACE(("wl%d: wlc_bsinit: bandunit %d\n", wlc->pub->unit, |
| 1274 | wlc->band->bandunit)); |
| 1275 | |
| 1276 | /* write ucode ACK/CTS rate table */ |
| 1277 | wlc_set_ratetable(wlc); |
| 1278 | |
| 1279 | /* update some band specific mac configuration */ |
| 1280 | wlc_ucode_mac_upd(wlc); |
| 1281 | |
| 1282 | /* init antenna selection */ |
| 1283 | if (WLANTSEL_ENAB(wlc)) |
| 1284 | wlc_antsel_init(wlc->asi); |
| 1285 | |
| 1286 | } |
| 1287 | |
| 1288 | /* switch to and initialize new band */ |
Jason Cooper | a2627bc | 2010-09-14 09:45:31 -0400 | [diff] [blame] | 1289 | static void WLBANDINITFN(wlc_setband) (wlc_info_t *wlc, uint bandunit) |
| 1290 | { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1291 | int idx; |
| 1292 | wlc_bsscfg_t *cfg; |
| 1293 | |
| 1294 | ASSERT(NBANDS(wlc) > 1); |
| 1295 | ASSERT(!wlc->bandlocked); |
| 1296 | ASSERT(bandunit != wlc->band->bandunit || wlc->bandinit_pending); |
| 1297 | |
| 1298 | wlc->band = wlc->bandstate[bandunit]; |
| 1299 | |
| 1300 | if (!wlc->pub->up) |
| 1301 | return; |
| 1302 | |
| 1303 | /* wait for at least one beacon before entering sleeping state */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1304 | wlc->PMawakebcn = true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1305 | FOREACH_AS_STA(wlc, idx, cfg) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1306 | cfg->PMawakebcn = true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1307 | wlc_set_ps_ctrl(wlc); |
| 1308 | |
| 1309 | /* band-specific initializations */ |
| 1310 | wlc_bsinit(wlc); |
| 1311 | } |
| 1312 | |
| 1313 | /* Initialize a WME Parameter Info Element with default STA parameters from WMM Spec, Table 12 */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 1314 | void wlc_wme_initparams_sta(wlc_info_t *wlc, wme_param_ie_t *pe) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1315 | { |
| 1316 | static const wme_param_ie_t stadef = { |
| 1317 | WME_OUI, |
| 1318 | WME_TYPE, |
| 1319 | WME_SUBTYPE_PARAM_IE, |
| 1320 | WME_VER, |
| 1321 | 0, |
| 1322 | 0, |
| 1323 | { |
| 1324 | {EDCF_AC_BE_ACI_STA, EDCF_AC_BE_ECW_STA, |
| 1325 | HTOL16(EDCF_AC_BE_TXOP_STA)}, |
| 1326 | {EDCF_AC_BK_ACI_STA, EDCF_AC_BK_ECW_STA, |
| 1327 | HTOL16(EDCF_AC_BK_TXOP_STA)}, |
| 1328 | {EDCF_AC_VI_ACI_STA, EDCF_AC_VI_ECW_STA, |
| 1329 | HTOL16(EDCF_AC_VI_TXOP_STA)}, |
| 1330 | {EDCF_AC_VO_ACI_STA, EDCF_AC_VO_ECW_STA, |
| 1331 | HTOL16(EDCF_AC_VO_TXOP_STA)} |
| 1332 | } |
| 1333 | }; |
| 1334 | |
| 1335 | ASSERT(sizeof(*pe) == WME_PARAM_IE_LEN); |
| 1336 | memcpy(pe, &stadef, sizeof(*pe)); |
| 1337 | } |
| 1338 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 1339 | void wlc_wme_setparams(wlc_info_t *wlc, u16 aci, void *arg, bool suspend) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1340 | { |
| 1341 | int i; |
| 1342 | shm_acparams_t acp_shm; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 1343 | u16 *shm_entry; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1344 | struct ieee80211_tx_queue_params *params = arg; |
| 1345 | |
| 1346 | ASSERT(wlc); |
| 1347 | |
| 1348 | /* Only apply params if the core is out of reset and has clocks */ |
| 1349 | if (!wlc->clk) { |
| 1350 | WL_ERROR(("wl%d: %s : no-clock\n", wlc->pub->unit, __func__)); |
| 1351 | return; |
| 1352 | } |
| 1353 | |
| 1354 | /* |
| 1355 | * AP uses AC params from wme_param_ie_ap. |
| 1356 | * AP advertises AC params from wme_param_ie. |
| 1357 | * STA uses AC params from wme_param_ie. |
| 1358 | */ |
| 1359 | |
| 1360 | wlc->wme_admctl = 0; |
| 1361 | |
| 1362 | do { |
Brett Rudley | 9249ede | 2010-11-30 20:09:49 -0800 | [diff] [blame^] | 1363 | memset((char *)&acp_shm, 0, sizeof(shm_acparams_t)); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1364 | /* find out which ac this set of params applies to */ |
| 1365 | ASSERT(aci < AC_COUNT); |
| 1366 | /* set the admission control policy for this AC */ |
| 1367 | /* wlc->wme_admctl |= 1 << aci; *//* should be set ?? seems like off by default */ |
| 1368 | |
| 1369 | /* fill in shm ac params struct */ |
| 1370 | acp_shm.txop = ltoh16(params->txop); |
| 1371 | /* convert from units of 32us to us for ucode */ |
| 1372 | wlc->edcf_txop[aci & 0x3] = acp_shm.txop = |
| 1373 | EDCF_TXOP2USEC(acp_shm.txop); |
| 1374 | acp_shm.aifs = (params->aifs & EDCF_AIFSN_MASK); |
| 1375 | |
| 1376 | if (aci == AC_VI && acp_shm.txop == 0 |
| 1377 | && acp_shm.aifs < EDCF_AIFSN_MAX) |
| 1378 | acp_shm.aifs++; |
| 1379 | |
| 1380 | if (acp_shm.aifs < EDCF_AIFSN_MIN |
| 1381 | || acp_shm.aifs > EDCF_AIFSN_MAX) { |
| 1382 | WL_ERROR(("wl%d: wlc_edcf_setparams: bad aifs %d\n", |
| 1383 | wlc->pub->unit, acp_shm.aifs)); |
| 1384 | continue; |
| 1385 | } |
| 1386 | |
| 1387 | acp_shm.cwmin = params->cw_min; |
| 1388 | acp_shm.cwmax = params->cw_max; |
| 1389 | acp_shm.cwcur = acp_shm.cwmin; |
| 1390 | acp_shm.bslots = |
| 1391 | R_REG(wlc->osh, &wlc->regs->tsf_random) & acp_shm.cwcur; |
| 1392 | acp_shm.reggap = acp_shm.bslots + acp_shm.aifs; |
| 1393 | /* Indicate the new params to the ucode */ |
| 1394 | acp_shm.status = wlc_read_shm(wlc, (M_EDCF_QINFO + |
| 1395 | wme_shmemacindex(aci) * |
| 1396 | M_EDCF_QLEN + |
| 1397 | M_EDCF_STATUS_OFF)); |
| 1398 | acp_shm.status |= WME_STATUS_NEWAC; |
| 1399 | |
| 1400 | /* Fill in shm acparam table */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 1401 | shm_entry = (u16 *) &acp_shm; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1402 | for (i = 0; i < (int)sizeof(shm_acparams_t); i += 2) |
| 1403 | wlc_write_shm(wlc, |
| 1404 | M_EDCF_QINFO + |
| 1405 | wme_shmemacindex(aci) * M_EDCF_QLEN + i, |
| 1406 | *shm_entry++); |
| 1407 | |
| 1408 | } while (0); |
| 1409 | |
| 1410 | if (suspend) |
| 1411 | wlc_suspend_mac_and_wait(wlc); |
| 1412 | |
| 1413 | if (suspend) |
| 1414 | wlc_enable_mac(wlc); |
| 1415 | |
| 1416 | } |
| 1417 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 1418 | void wlc_edcf_setparams(wlc_bsscfg_t *cfg, bool suspend) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1419 | { |
| 1420 | wlc_info_t *wlc = cfg->wlc; |
| 1421 | uint aci, i, j; |
| 1422 | edcf_acparam_t *edcf_acp; |
| 1423 | shm_acparams_t acp_shm; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 1424 | u16 *shm_entry; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1425 | |
| 1426 | ASSERT(cfg); |
| 1427 | ASSERT(wlc); |
| 1428 | |
| 1429 | /* Only apply params if the core is out of reset and has clocks */ |
| 1430 | if (!wlc->clk) |
| 1431 | return; |
| 1432 | |
| 1433 | /* |
| 1434 | * AP uses AC params from wme_param_ie_ap. |
| 1435 | * AP advertises AC params from wme_param_ie. |
| 1436 | * STA uses AC params from wme_param_ie. |
| 1437 | */ |
| 1438 | |
Jason Cooper | 29c4275 | 2010-09-14 09:45:43 -0400 | [diff] [blame] | 1439 | edcf_acp = (edcf_acparam_t *) &wlc->wme_param_ie.acparam[0]; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1440 | |
| 1441 | wlc->wme_admctl = 0; |
| 1442 | |
| 1443 | for (i = 0; i < AC_COUNT; i++, edcf_acp++) { |
Brett Rudley | 9249ede | 2010-11-30 20:09:49 -0800 | [diff] [blame^] | 1444 | memset((char *)&acp_shm, 0, sizeof(shm_acparams_t)); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1445 | /* find out which ac this set of params applies to */ |
| 1446 | aci = (edcf_acp->ACI & EDCF_ACI_MASK) >> EDCF_ACI_SHIFT; |
| 1447 | ASSERT(aci < AC_COUNT); |
| 1448 | /* set the admission control policy for this AC */ |
| 1449 | if (edcf_acp->ACI & EDCF_ACM_MASK) { |
| 1450 | wlc->wme_admctl |= 1 << aci; |
| 1451 | } |
| 1452 | |
| 1453 | /* fill in shm ac params struct */ |
| 1454 | acp_shm.txop = ltoh16(edcf_acp->TXOP); |
| 1455 | /* convert from units of 32us to us for ucode */ |
| 1456 | wlc->edcf_txop[aci] = acp_shm.txop = |
| 1457 | EDCF_TXOP2USEC(acp_shm.txop); |
| 1458 | acp_shm.aifs = (edcf_acp->ACI & EDCF_AIFSN_MASK); |
| 1459 | |
| 1460 | if (aci == AC_VI && acp_shm.txop == 0 |
| 1461 | && acp_shm.aifs < EDCF_AIFSN_MAX) |
| 1462 | acp_shm.aifs++; |
| 1463 | |
| 1464 | if (acp_shm.aifs < EDCF_AIFSN_MIN |
| 1465 | || acp_shm.aifs > EDCF_AIFSN_MAX) { |
| 1466 | WL_ERROR(("wl%d: wlc_edcf_setparams: bad aifs %d\n", |
| 1467 | wlc->pub->unit, acp_shm.aifs)); |
| 1468 | continue; |
| 1469 | } |
| 1470 | |
| 1471 | /* CWmin = 2^(ECWmin) - 1 */ |
| 1472 | acp_shm.cwmin = EDCF_ECW2CW(edcf_acp->ECW & EDCF_ECWMIN_MASK); |
| 1473 | /* CWmax = 2^(ECWmax) - 1 */ |
| 1474 | acp_shm.cwmax = EDCF_ECW2CW((edcf_acp->ECW & EDCF_ECWMAX_MASK) |
| 1475 | >> EDCF_ECWMAX_SHIFT); |
| 1476 | acp_shm.cwcur = acp_shm.cwmin; |
| 1477 | acp_shm.bslots = |
| 1478 | R_REG(wlc->osh, &wlc->regs->tsf_random) & acp_shm.cwcur; |
| 1479 | acp_shm.reggap = acp_shm.bslots + acp_shm.aifs; |
| 1480 | /* Indicate the new params to the ucode */ |
| 1481 | acp_shm.status = wlc_read_shm(wlc, (M_EDCF_QINFO + |
| 1482 | wme_shmemacindex(aci) * |
| 1483 | M_EDCF_QLEN + |
| 1484 | M_EDCF_STATUS_OFF)); |
| 1485 | acp_shm.status |= WME_STATUS_NEWAC; |
| 1486 | |
| 1487 | /* Fill in shm acparam table */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 1488 | shm_entry = (u16 *) &acp_shm; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1489 | for (j = 0; j < (int)sizeof(shm_acparams_t); j += 2) |
| 1490 | wlc_write_shm(wlc, |
| 1491 | M_EDCF_QINFO + |
| 1492 | wme_shmemacindex(aci) * M_EDCF_QLEN + j, |
| 1493 | *shm_entry++); |
| 1494 | } |
| 1495 | |
| 1496 | if (suspend) |
| 1497 | wlc_suspend_mac_and_wait(wlc); |
| 1498 | |
| 1499 | if (AP_ENAB(wlc->pub) && WME_ENAB(wlc->pub)) { |
| 1500 | wlc_update_beacon(wlc); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1501 | wlc_update_probe_resp(wlc, false); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1502 | } |
| 1503 | |
| 1504 | if (suspend) |
| 1505 | wlc_enable_mac(wlc); |
| 1506 | |
| 1507 | } |
| 1508 | |
Greg Kroah-Hartman | 0d2f072 | 2010-10-08 14:28:21 -0700 | [diff] [blame] | 1509 | bool wlc_timers_init(wlc_info_t *wlc, int unit) |
Jason Cooper | a2627bc | 2010-09-14 09:45:31 -0400 | [diff] [blame] | 1510 | { |
Jason Cooper | ca8c1e5 | 2010-09-14 09:45:33 -0400 | [diff] [blame] | 1511 | wlc->wdtimer = wl_init_timer(wlc->wl, wlc_watchdog_by_timer, |
| 1512 | wlc, "watchdog"); |
| 1513 | if (!wlc->wdtimer) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1514 | WL_ERROR(("wl%d: wl_init_timer for wdtimer failed\n", unit)); |
| 1515 | goto fail; |
| 1516 | } |
| 1517 | |
Jason Cooper | ca8c1e5 | 2010-09-14 09:45:33 -0400 | [diff] [blame] | 1518 | wlc->radio_timer = wl_init_timer(wlc->wl, wlc_radio_timer, |
| 1519 | wlc, "radio"); |
| 1520 | if (!wlc->radio_timer) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1521 | WL_ERROR(("wl%d: wl_init_timer for radio_timer failed\n", |
| 1522 | unit)); |
| 1523 | goto fail; |
| 1524 | } |
| 1525 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1526 | return true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1527 | |
| 1528 | fail: |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1529 | return false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1530 | } |
| 1531 | |
| 1532 | /* |
| 1533 | * Initialize wlc_info default values ... |
| 1534 | * may get overrides later in this function |
| 1535 | */ |
Greg Kroah-Hartman | 0d2f072 | 2010-10-08 14:28:21 -0700 | [diff] [blame] | 1536 | void wlc_info_init(wlc_info_t *wlc, int unit) |
Jason Cooper | a2627bc | 2010-09-14 09:45:31 -0400 | [diff] [blame] | 1537 | { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1538 | int i; |
| 1539 | /* Assume the device is there until proven otherwise */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1540 | wlc->device_present = true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1541 | |
| 1542 | /* set default power output percentage to 100 percent */ |
| 1543 | wlc->txpwr_percent = 100; |
| 1544 | |
| 1545 | /* Save our copy of the chanspec */ |
| 1546 | wlc->chanspec = CH20MHZ_CHSPEC(1); |
| 1547 | |
| 1548 | /* initialize CCK preamble mode to unassociated state */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1549 | wlc->shortpreamble = false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1550 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1551 | wlc->legacy_probe = true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1552 | |
| 1553 | /* various 802.11g modes */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1554 | wlc->shortslot = false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1555 | wlc->shortslot_override = WLC_SHORTSLOT_AUTO; |
| 1556 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1557 | wlc->barker_overlap_control = true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1558 | wlc->barker_preamble = WLC_BARKER_SHORT_ALLOWED; |
| 1559 | wlc->txburst_limit_override = AUTO; |
| 1560 | |
| 1561 | wlc_protection_upd(wlc, WLC_PROT_G_OVR, WLC_PROTECTION_AUTO); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1562 | wlc_protection_upd(wlc, WLC_PROT_G_SPEC, false); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1563 | |
| 1564 | wlc_protection_upd(wlc, WLC_PROT_N_CFG_OVR, WLC_PROTECTION_AUTO); |
| 1565 | wlc_protection_upd(wlc, WLC_PROT_N_CFG, WLC_N_PROTECTION_OFF); |
| 1566 | wlc_protection_upd(wlc, WLC_PROT_N_NONGF_OVR, WLC_PROTECTION_AUTO); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1567 | wlc_protection_upd(wlc, WLC_PROT_N_NONGF, false); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1568 | wlc_protection_upd(wlc, WLC_PROT_N_PAM_OVR, AUTO); |
| 1569 | |
| 1570 | wlc_protection_upd(wlc, WLC_PROT_OVERLAP, WLC_PROTECTION_CTL_OVERLAP); |
| 1571 | |
| 1572 | /* 802.11g draft 4.0 NonERP elt advertisement */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1573 | wlc->include_legacy_erp = true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1574 | |
| 1575 | wlc->stf->ant_rx_ovr = ANT_RX_DIV_DEF; |
| 1576 | wlc->stf->txant = ANT_TX_DEF; |
| 1577 | |
| 1578 | wlc->prb_resp_timeout = WLC_PRB_RESP_TIMEOUT; |
| 1579 | |
| 1580 | wlc->usr_fragthresh = DOT11_DEFAULT_FRAG_LEN; |
| 1581 | for (i = 0; i < NFIFO; i++) |
| 1582 | wlc->fragthresh[i] = DOT11_DEFAULT_FRAG_LEN; |
| 1583 | wlc->RTSThresh = DOT11_DEFAULT_RTS_LEN; |
| 1584 | |
| 1585 | /* default rate fallback retry limits */ |
| 1586 | wlc->SFBL = RETRY_SHORT_FB; |
| 1587 | wlc->LFBL = RETRY_LONG_FB; |
| 1588 | |
| 1589 | /* default mac retry limits */ |
| 1590 | wlc->SRL = RETRY_SHORT_DEF; |
| 1591 | wlc->LRL = RETRY_LONG_DEF; |
| 1592 | |
| 1593 | /* init PM state */ |
| 1594 | wlc->PM = PM_OFF; /* User's setting of PM mode through IOCTL */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1595 | wlc->PM_override = false; /* Prevents from going to PM if our AP is 'ill' */ |
| 1596 | wlc->PMenabled = false; /* Current PM state */ |
| 1597 | wlc->PMpending = false; /* Tracks whether STA indicated PM in the last attempt */ |
| 1598 | wlc->PMblocked = false; /* To allow blocking going into PM during RM and scans */ |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1599 | |
| 1600 | /* In WMM Auto mode, PM is allowed if association is a UAPSD association */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1601 | wlc->WME_PM_blocked = false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1602 | |
| 1603 | /* Init wme queuing method */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1604 | wlc->wme_prec_queuing = false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1605 | |
| 1606 | /* Overrides for the core to stay awake under zillion conditions Look for STAY_AWAKE */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1607 | wlc->wake = false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1608 | /* Are we waiting for a response to PS-Poll that we sent */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1609 | wlc->PSpoll = false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1610 | |
| 1611 | /* APSD defaults */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1612 | wlc->wme_apsd = true; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1613 | wlc->apsd_sta_usp = false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1614 | wlc->apsd_trigger_timeout = 0; /* disable the trigger timer */ |
| 1615 | wlc->apsd_trigger_ac = AC_BITMAP_ALL; |
| 1616 | |
| 1617 | /* Set flag to indicate that hw keys should be used when available. */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1618 | wlc->wsec_swkeys = false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1619 | |
| 1620 | /* init the 4 static WEP default keys */ |
| 1621 | for (i = 0; i < WSEC_MAX_DEFAULT_KEYS; i++) { |
| 1622 | wlc->wsec_keys[i] = wlc->wsec_def_keys[i]; |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 1623 | wlc->wsec_keys[i]->idx = (u8) i; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1624 | } |
| 1625 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1626 | wlc->_regulatory_domain = false; /* 802.11d */ |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1627 | |
| 1628 | /* WME QoS mode is Auto by default */ |
| 1629 | wlc->pub->_wme = AUTO; |
| 1630 | |
| 1631 | #ifdef BCMSDIODEV_ENABLED |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1632 | wlc->pub->_priofc = true; /* enable priority flow control for sdio dongle */ |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1633 | #endif |
| 1634 | |
| 1635 | wlc->pub->_ampdu = AMPDU_AGG_HOST; |
| 1636 | wlc->pub->bcmerror = 0; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1637 | wlc->ibss_allowed = true; |
| 1638 | wlc->ibss_coalesce_allowed = true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1639 | wlc->pub->_coex = ON; |
| 1640 | |
| 1641 | /* intialize mpc delay */ |
| 1642 | wlc->mpc_delay_off = wlc->mpc_dlycnt = WLC_MPC_MIN_DELAYCNT; |
| 1643 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1644 | wlc->pr80838_war = true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1645 | } |
| 1646 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 1647 | static bool wlc_state_bmac_sync(wlc_info_t *wlc) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1648 | { |
| 1649 | wlc_bmac_state_t state_bmac; |
| 1650 | |
| 1651 | if (wlc_bmac_state_get(wlc->hw, &state_bmac) != 0) |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1652 | return false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1653 | |
| 1654 | wlc->machwcap = state_bmac.machwcap; |
| 1655 | wlc_protection_upd(wlc, WLC_PROT_N_PAM_OVR, |
Greg Kroah-Hartman | 562c885 | 2010-10-05 11:04:17 -0700 | [diff] [blame] | 1656 | (s8) state_bmac.preamble_ovr); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1657 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1658 | return true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1659 | } |
| 1660 | |
Greg Kroah-Hartman | 0d2f072 | 2010-10-08 14:28:21 -0700 | [diff] [blame] | 1661 | static uint wlc_attach_module(wlc_info_t *wlc) |
Jason Cooper | a2627bc | 2010-09-14 09:45:31 -0400 | [diff] [blame] | 1662 | { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1663 | uint err = 0; |
| 1664 | uint unit; |
| 1665 | unit = wlc->pub->unit; |
| 1666 | |
Jason Cooper | ca8c1e5 | 2010-09-14 09:45:33 -0400 | [diff] [blame] | 1667 | wlc->asi = wlc_antsel_attach(wlc, wlc->osh, wlc->pub, wlc->hw); |
| 1668 | if (wlc->asi == NULL) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1669 | WL_ERROR(("wl%d: wlc_attach: wlc_antsel_attach failed\n", |
| 1670 | unit)); |
| 1671 | err = 44; |
| 1672 | goto fail; |
| 1673 | } |
| 1674 | |
Jason Cooper | ca8c1e5 | 2010-09-14 09:45:33 -0400 | [diff] [blame] | 1675 | wlc->ampdu = wlc_ampdu_attach(wlc); |
| 1676 | if (wlc->ampdu == NULL) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1677 | WL_ERROR(("wl%d: wlc_attach: wlc_ampdu_attach failed\n", unit)); |
| 1678 | err = 50; |
| 1679 | goto fail; |
| 1680 | } |
| 1681 | |
| 1682 | /* Initialize event queue; needed before following calls */ |
| 1683 | wlc->eventq = |
| 1684 | wlc_eventq_attach(wlc->pub, wlc, wlc->wl, wlc_process_eventq); |
| 1685 | if (wlc->eventq == NULL) { |
| 1686 | WL_ERROR(("wl%d: wlc_attach: wlc_eventq_attachfailed\n", unit)); |
| 1687 | err = 57; |
| 1688 | goto fail; |
| 1689 | } |
| 1690 | |
| 1691 | if ((wlc_stf_attach(wlc) != 0)) { |
| 1692 | WL_ERROR(("wl%d: wlc_attach: wlc_stf_attach failed\n", unit)); |
| 1693 | err = 68; |
| 1694 | goto fail; |
| 1695 | } |
| 1696 | fail: |
| 1697 | return err; |
| 1698 | } |
| 1699 | |
| 1700 | wlc_pub_t *wlc_pub(void *wlc) |
| 1701 | { |
| 1702 | return ((wlc_info_t *) wlc)->pub; |
| 1703 | } |
| 1704 | |
| 1705 | #define CHIP_SUPPORTS_11N(wlc) 1 |
| 1706 | |
| 1707 | /* |
| 1708 | * The common driver entry routine. Error codes should be unique |
| 1709 | */ |
Greg Kroah-Hartman | 0d2f072 | 2010-10-08 14:28:21 -0700 | [diff] [blame] | 1710 | void *wlc_attach(void *wl, u16 vendor, u16 device, uint unit, bool piomode, |
Brett Rudley | e69284f | 2010-11-16 15:45:48 -0800 | [diff] [blame] | 1711 | struct osl_info *osh, void *regsva, uint bustype, |
| 1712 | void *btparam, uint *perr) |
Greg Kroah-Hartman | 0d2f072 | 2010-10-08 14:28:21 -0700 | [diff] [blame] | 1713 | { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1714 | wlc_info_t *wlc; |
| 1715 | uint err = 0; |
| 1716 | uint j; |
| 1717 | wlc_pub_t *pub; |
| 1718 | wlc_txq_info_t *qi; |
| 1719 | uint n_disabled; |
| 1720 | |
| 1721 | WL_NONE(("wl%d: %s: vendor 0x%x device 0x%x\n", unit, __func__, vendor, |
| 1722 | device)); |
| 1723 | |
| 1724 | ASSERT(WSEC_MAX_RCMTA_KEYS <= WSEC_MAX_KEYS); |
| 1725 | ASSERT(WSEC_MAX_DEFAULT_KEYS == WLC_DEFAULT_KEYS); |
| 1726 | |
| 1727 | /* some code depends on packed structures */ |
| 1728 | ASSERT(sizeof(struct ether_addr) == ETHER_ADDR_LEN); |
| 1729 | ASSERT(sizeof(struct ether_header) == ETHER_HDR_LEN); |
| 1730 | ASSERT(sizeof(d11regs_t) == SI_CORE_SIZE); |
| 1731 | ASSERT(sizeof(ofdm_phy_hdr_t) == D11_PHY_HDR_LEN); |
| 1732 | ASSERT(sizeof(cck_phy_hdr_t) == D11_PHY_HDR_LEN); |
| 1733 | ASSERT(sizeof(d11txh_t) == D11_TXH_LEN); |
| 1734 | ASSERT(sizeof(d11rxhdr_t) == RXHDR_LEN); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1735 | ASSERT(sizeof(struct dot11_header) == DOT11_A4_HDR_LEN); |
| 1736 | ASSERT(sizeof(struct dot11_rts_frame) == DOT11_RTS_LEN); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1737 | ASSERT(sizeof(struct dot11_management_header) == DOT11_MGMT_HDR_LEN); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1738 | ASSERT(sizeof(struct dot11_bcn_prb) == DOT11_BCN_PRB_LEN); |
| 1739 | ASSERT(sizeof(tx_status_t) == TXSTATUS_LEN); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1740 | ASSERT(sizeof(ht_cap_ie_t) == HT_CAP_IE_LEN); |
Brett Rudley | eb81603 | 2010-10-26 18:37:24 -0700 | [diff] [blame] | 1741 | #ifdef BRCM_FULLMAC |
Greg Kroah-Hartman | ce0f1b8 | 2010-10-08 11:44:45 -0700 | [diff] [blame] | 1742 | ASSERT(offsetof(wl_scan_params_t, channel_list) == |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1743 | WL_SCAN_PARAMS_FIXED_SIZE); |
Brett Rudley | eb81603 | 2010-10-26 18:37:24 -0700 | [diff] [blame] | 1744 | #endif |
Greg Kroah-Hartman | 36c63ff | 2010-10-08 11:55:40 -0700 | [diff] [blame] | 1745 | ASSERT(IS_ALIGNED(offsetof(wsec_key_t, data), sizeof(u32))); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1746 | ASSERT(ISPOWEROF2(MA_WINDOW_SZ)); |
| 1747 | |
| 1748 | ASSERT(sizeof(wlc_d11rxhdr_t) <= WL_HWRXOFF); |
| 1749 | |
| 1750 | /* |
| 1751 | * Number of replay counters value used in WPA IE must match # rxivs |
| 1752 | * supported in wsec_key_t struct. See 802.11i/D3.0 sect. 7.3.2.17 |
| 1753 | * 'RSN Information Element' figure 8 for this mapping. |
| 1754 | */ |
| 1755 | ASSERT((WPA_CAP_16_REPLAY_CNTRS == WLC_REPLAY_CNTRS_VALUE |
| 1756 | && 16 == WLC_NUMRXIVS) |
| 1757 | || (WPA_CAP_4_REPLAY_CNTRS == WLC_REPLAY_CNTRS_VALUE |
| 1758 | && 4 == WLC_NUMRXIVS)); |
| 1759 | |
| 1760 | /* allocate wlc_info_t state and its substructures */ |
Jason Cooper | ca8c1e5 | 2010-09-14 09:45:33 -0400 | [diff] [blame] | 1761 | wlc = (wlc_info_t *) wlc_attach_malloc(osh, unit, &err, device); |
| 1762 | if (wlc == NULL) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1763 | goto fail; |
| 1764 | wlc->osh = osh; |
| 1765 | pub = wlc->pub; |
| 1766 | |
| 1767 | #if defined(BCMDBG) |
| 1768 | wlc_info_dbg = wlc; |
| 1769 | #endif |
| 1770 | |
| 1771 | wlc->band = wlc->bandstate[0]; |
| 1772 | wlc->core = wlc->corestate; |
| 1773 | wlc->wl = wl; |
| 1774 | pub->unit = unit; |
| 1775 | pub->osh = osh; |
| 1776 | wlc->btparam = btparam; |
| 1777 | pub->_piomode = piomode; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1778 | wlc->bandinit_pending = false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1779 | /* By default restrict TKIP associations from 11n STA's */ |
| 1780 | wlc->ht_wsec_restriction = WLC_HT_TKIP_RESTRICT; |
| 1781 | |
| 1782 | /* populate wlc_info_t with default values */ |
| 1783 | wlc_info_init(wlc, unit); |
| 1784 | |
| 1785 | /* update sta/ap related parameters */ |
| 1786 | wlc_ap_upd(wlc); |
| 1787 | |
| 1788 | /* 11n_disable nvram */ |
| 1789 | n_disabled = getintvar(pub->vars, "11n_disable"); |
| 1790 | |
| 1791 | /* register a module (to handle iovars) */ |
| 1792 | wlc_module_register(wlc->pub, wlc_iovars, "wlc_iovars", wlc, |
| 1793 | wlc_doiovar, NULL, NULL); |
| 1794 | |
| 1795 | /* low level attach steps(all hw accesses go inside, no more in rest of the attach) */ |
| 1796 | err = wlc_bmac_attach(wlc, vendor, device, unit, piomode, osh, regsva, |
| 1797 | bustype, btparam); |
| 1798 | if (err) |
| 1799 | goto fail; |
| 1800 | |
| 1801 | /* for some states, due to different info pointer(e,g, wlc, wlc_hw) or master/slave split, |
| 1802 | * HIGH driver(both monolithic and HIGH_ONLY) needs to sync states FROM BMAC portion driver |
| 1803 | */ |
| 1804 | if (!wlc_state_bmac_sync(wlc)) { |
| 1805 | err = 20; |
| 1806 | goto fail; |
| 1807 | } |
| 1808 | |
| 1809 | pub->phy_11ncapable = WLC_PHY_11N_CAP(wlc->band); |
| 1810 | |
| 1811 | /* propagate *vars* from BMAC driver to high driver */ |
| 1812 | wlc_bmac_copyfrom_vars(wlc->hw, &pub->vars, &wlc->vars_size); |
| 1813 | |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1814 | |
| 1815 | /* set maximum allowed duty cycle */ |
| 1816 | wlc->tx_duty_cycle_ofdm = |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 1817 | (u16) getintvar(pub->vars, "tx_duty_cycle_ofdm"); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1818 | wlc->tx_duty_cycle_cck = |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 1819 | (u16) getintvar(pub->vars, "tx_duty_cycle_cck"); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1820 | |
| 1821 | wlc_stf_phy_chain_calc(wlc); |
| 1822 | |
| 1823 | /* txchain 1: txant 0, txchain 2: txant 1 */ |
| 1824 | if (WLCISNPHY(wlc->band) && (wlc->stf->txstreams == 1)) |
| 1825 | wlc->stf->txant = wlc->stf->hw_txchain - 1; |
| 1826 | |
| 1827 | /* push to BMAC driver */ |
| 1828 | wlc_phy_stf_chain_init(wlc->band->pi, wlc->stf->hw_txchain, |
| 1829 | wlc->stf->hw_rxchain); |
| 1830 | |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1831 | /* pull up some info resulting from the low attach */ |
| 1832 | { |
| 1833 | int i; |
| 1834 | for (i = 0; i < NFIFO; i++) |
| 1835 | wlc->core->txavail[i] = wlc->hw->txavail[i]; |
| 1836 | } |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1837 | |
| 1838 | wlc_bmac_hw_etheraddr(wlc->hw, &wlc->perm_etheraddr); |
| 1839 | |
| 1840 | bcopy((char *)&wlc->perm_etheraddr, (char *)&pub->cur_etheraddr, |
| 1841 | ETHER_ADDR_LEN); |
| 1842 | |
| 1843 | for (j = 0; j < NBANDS(wlc); j++) { |
| 1844 | /* Use band 1 for single band 11a */ |
| 1845 | if (IS_SINGLEBAND_5G(wlc->deviceid)) |
| 1846 | j = BAND_5G_INDEX; |
| 1847 | |
| 1848 | wlc->band = wlc->bandstate[j]; |
| 1849 | |
| 1850 | if (!wlc_attach_stf_ant_init(wlc)) { |
| 1851 | err = 24; |
| 1852 | goto fail; |
| 1853 | } |
| 1854 | |
| 1855 | /* default contention windows size limits */ |
| 1856 | wlc->band->CWmin = APHY_CWMIN; |
| 1857 | wlc->band->CWmax = PHY_CWMAX; |
| 1858 | |
| 1859 | /* init gmode value */ |
| 1860 | if (BAND_2G(wlc->band->bandtype)) { |
| 1861 | wlc->band->gmode = GMODE_AUTO; |
| 1862 | wlc_protection_upd(wlc, WLC_PROT_G_USER, |
| 1863 | wlc->band->gmode); |
| 1864 | } |
| 1865 | |
| 1866 | /* init _n_enab supported mode */ |
| 1867 | if (WLC_PHY_11N_CAP(wlc->band) && CHIP_SUPPORTS_11N(wlc)) { |
| 1868 | if (n_disabled & WLFEATURE_DISABLE_11N) { |
| 1869 | pub->_n_enab = OFF; |
| 1870 | wlc_protection_upd(wlc, WLC_PROT_N_USER, OFF); |
| 1871 | } else { |
| 1872 | pub->_n_enab = SUPPORT_11N; |
| 1873 | wlc_protection_upd(wlc, WLC_PROT_N_USER, |
| 1874 | ((pub->_n_enab == |
| 1875 | SUPPORT_11N) ? WL_11N_2x2 : |
| 1876 | WL_11N_3x3)); |
| 1877 | } |
| 1878 | } |
| 1879 | |
| 1880 | /* init per-band default rateset, depend on band->gmode */ |
| 1881 | wlc_default_rateset(wlc, &wlc->band->defrateset); |
| 1882 | |
| 1883 | /* fill in hw_rateset (used early by WLC_SET_RATESET) */ |
| 1884 | wlc_rateset_filter(&wlc->band->defrateset, |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1885 | &wlc->band->hw_rateset, false, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1886 | WLC_RATES_CCK_OFDM, RATE_MASK, |
| 1887 | (bool) N_ENAB(wlc->pub)); |
| 1888 | } |
| 1889 | |
| 1890 | /* update antenna config due to wlc->stf->txant/txchain/ant_rx_ovr change */ |
| 1891 | wlc_stf_phy_txant_upd(wlc); |
| 1892 | |
| 1893 | /* attach each modules */ |
| 1894 | err = wlc_attach_module(wlc); |
| 1895 | if (err != 0) |
| 1896 | goto fail; |
| 1897 | |
| 1898 | if (!wlc_timers_init(wlc, unit)) { |
| 1899 | WL_ERROR(("wl%d: %s: wlc_init_timer failed\n", unit, __func__)); |
| 1900 | err = 32; |
| 1901 | goto fail; |
| 1902 | } |
| 1903 | |
| 1904 | /* depend on rateset, gmode */ |
| 1905 | wlc->cmi = wlc_channel_mgr_attach(wlc); |
| 1906 | if (!wlc->cmi) { |
| 1907 | WL_ERROR(("wl%d: %s: wlc_channel_mgr_attach failed\n", unit, |
| 1908 | __func__)); |
| 1909 | err = 33; |
| 1910 | goto fail; |
| 1911 | } |
| 1912 | |
| 1913 | /* init default when all parameters are ready, i.e. ->rateset */ |
| 1914 | wlc_bss_default_init(wlc); |
| 1915 | |
| 1916 | /* |
| 1917 | * Complete the wlc default state initializations.. |
| 1918 | */ |
| 1919 | |
| 1920 | /* allocate our initial queue */ |
| 1921 | qi = wlc_txq_alloc(wlc, osh); |
| 1922 | if (qi == NULL) { |
| 1923 | WL_ERROR(("wl%d: %s: failed to malloc tx queue\n", unit, |
| 1924 | __func__)); |
| 1925 | err = 100; |
| 1926 | goto fail; |
| 1927 | } |
| 1928 | wlc->active_queue = qi; |
| 1929 | |
| 1930 | wlc->bsscfg[0] = wlc->cfg; |
| 1931 | wlc->cfg->_idx = 0; |
| 1932 | wlc->cfg->wlc = wlc; |
| 1933 | pub->txmaxpkts = MAXTXPKTS; |
| 1934 | |
| 1935 | WLCNTSET(pub->_cnt->version, WL_CNT_T_VERSION); |
| 1936 | WLCNTSET(pub->_cnt->length, sizeof(wl_cnt_t)); |
| 1937 | |
| 1938 | WLCNTSET(pub->_wme_cnt->version, WL_WME_CNT_VERSION); |
| 1939 | WLCNTSET(pub->_wme_cnt->length, sizeof(wl_wme_cnt_t)); |
| 1940 | |
| 1941 | wlc_wme_initparams_sta(wlc, &wlc->wme_param_ie); |
| 1942 | |
| 1943 | wlc->mimoft = FT_HT; |
| 1944 | wlc->ht_cap.cap = HT_CAP; |
| 1945 | if (HT_ENAB(wlc->pub)) |
| 1946 | wlc->stf->ldpc = AUTO; |
| 1947 | |
| 1948 | wlc->mimo_40txbw = AUTO; |
| 1949 | wlc->ofdm_40txbw = AUTO; |
| 1950 | wlc->cck_40txbw = AUTO; |
| 1951 | wlc_update_mimo_band_bwcap(wlc, WLC_N_BW_20IN2G_40IN5G); |
| 1952 | |
| 1953 | /* Enable setting the RIFS Mode bit by default in HT Info IE */ |
| 1954 | wlc->rifs_advert = AUTO; |
| 1955 | |
| 1956 | /* Set default values of SGI */ |
| 1957 | if (WLC_SGI_CAP_PHY(wlc)) { |
| 1958 | wlc_ht_update_sgi_rx(wlc, (WLC_N_SGI_20 | WLC_N_SGI_40)); |
| 1959 | wlc->sgi_tx = AUTO; |
| 1960 | } else if (WLCISSSLPNPHY(wlc->band)) { |
| 1961 | wlc_ht_update_sgi_rx(wlc, (WLC_N_SGI_20 | WLC_N_SGI_40)); |
| 1962 | wlc->sgi_tx = AUTO; |
| 1963 | } else { |
| 1964 | wlc_ht_update_sgi_rx(wlc, 0); |
| 1965 | wlc->sgi_tx = OFF; |
| 1966 | } |
| 1967 | |
| 1968 | /* *******nvram 11n config overrides Start ********* */ |
| 1969 | |
| 1970 | /* apply the sgi override from nvram conf */ |
| 1971 | if (n_disabled & WLFEATURE_DISABLE_11N_SGI_TX) |
| 1972 | wlc->sgi_tx = OFF; |
| 1973 | |
| 1974 | if (n_disabled & WLFEATURE_DISABLE_11N_SGI_RX) |
| 1975 | wlc_ht_update_sgi_rx(wlc, 0); |
| 1976 | |
| 1977 | /* apply the stbc override from nvram conf */ |
| 1978 | if (n_disabled & WLFEATURE_DISABLE_11N_STBC_TX) { |
| 1979 | wlc->bandstate[BAND_2G_INDEX]->band_stf_stbc_tx = OFF; |
| 1980 | wlc->bandstate[BAND_5G_INDEX]->band_stf_stbc_tx = OFF; |
| 1981 | wlc->ht_cap.cap &= ~HT_CAP_TX_STBC; |
| 1982 | } |
| 1983 | if (n_disabled & WLFEATURE_DISABLE_11N_STBC_RX) |
| 1984 | wlc_stf_stbc_rx_set(wlc, HT_CAP_RX_STBC_NO); |
| 1985 | |
| 1986 | /* apply the GF override from nvram conf */ |
| 1987 | if (n_disabled & WLFEATURE_DISABLE_11N_GF) |
| 1988 | wlc->ht_cap.cap &= ~HT_CAP_GF; |
| 1989 | |
| 1990 | /* initialize radio_mpc_disable according to wlc->mpc */ |
| 1991 | wlc_radio_mpc_upd(wlc); |
| 1992 | |
| 1993 | if (WLANTSEL_ENAB(wlc)) { |
| 1994 | if ((CHIPID(wlc->pub->sih->chip)) == BCM43235_CHIP_ID) { |
| 1995 | if ((getintvar(wlc->pub->vars, "aa2g") == 7) || |
| 1996 | (getintvar(wlc->pub->vars, "aa5g") == 7)) { |
| 1997 | wlc_bmac_antsel_set(wlc->hw, 1); |
| 1998 | } |
| 1999 | } else { |
| 2000 | wlc_bmac_antsel_set(wlc->hw, wlc->asi->antsel_avail); |
| 2001 | } |
| 2002 | } |
| 2003 | |
| 2004 | if (perr) |
| 2005 | *perr = 0; |
| 2006 | |
Jason Cooper | 90ea229 | 2010-09-14 09:45:32 -0400 | [diff] [blame] | 2007 | return (void *)wlc; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2008 | |
| 2009 | fail: |
| 2010 | WL_ERROR(("wl%d: %s: failed with err %d\n", unit, __func__, err)); |
| 2011 | if (wlc) |
| 2012 | wlc_detach(wlc); |
| 2013 | |
| 2014 | if (perr) |
| 2015 | *perr = err; |
Jason Cooper | 90ea229 | 2010-09-14 09:45:32 -0400 | [diff] [blame] | 2016 | return NULL; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2017 | } |
| 2018 | |
Jason Cooper | a9d0fff | 2010-10-11 10:03:00 -0400 | [diff] [blame] | 2019 | static void wlc_attach_antgain_init(wlc_info_t *wlc) |
Jason Cooper | a2627bc | 2010-09-14 09:45:31 -0400 | [diff] [blame] | 2020 | { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2021 | uint unit; |
| 2022 | unit = wlc->pub->unit; |
| 2023 | |
| 2024 | if ((wlc->band->antgain == -1) && (wlc->pub->sromrev == 1)) { |
| 2025 | /* default antenna gain for srom rev 1 is 2 dBm (8 qdbm) */ |
| 2026 | wlc->band->antgain = 8; |
| 2027 | } else if (wlc->band->antgain == -1) { |
| 2028 | WL_ERROR(("wl%d: %s: Invalid antennas available in srom, using 2dB\n", unit, __func__)); |
| 2029 | wlc->band->antgain = 8; |
| 2030 | } else { |
Greg Kroah-Hartman | 562c885 | 2010-10-05 11:04:17 -0700 | [diff] [blame] | 2031 | s8 gain, fract; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2032 | /* Older sroms specified gain in whole dbm only. In order |
| 2033 | * be able to specify qdbm granularity and remain backward compatible |
| 2034 | * the whole dbms are now encoded in only low 6 bits and remaining qdbms |
| 2035 | * are encoded in the hi 2 bits. 6 bit signed number ranges from |
| 2036 | * -32 - 31. Examples: 0x1 = 1 db, |
| 2037 | * 0xc1 = 1.75 db (1 + 3 quarters), |
| 2038 | * 0x3f = -1 (-1 + 0 quarters), |
| 2039 | * 0x7f = -.75 (-1 in low 6 bits + 1 quarters in hi 2 bits) = -3 qdbm. |
| 2040 | * 0xbf = -.50 (-1 in low 6 bits + 2 quarters in hi 2 bits) = -2 qdbm. |
| 2041 | */ |
| 2042 | gain = wlc->band->antgain & 0x3f; |
| 2043 | gain <<= 2; /* Sign extend */ |
| 2044 | gain >>= 2; |
| 2045 | fract = (wlc->band->antgain & 0xc0) >> 6; |
| 2046 | wlc->band->antgain = 4 * gain + fract; |
| 2047 | } |
| 2048 | } |
| 2049 | |
Greg Kroah-Hartman | 0d2f072 | 2010-10-08 14:28:21 -0700 | [diff] [blame] | 2050 | static bool wlc_attach_stf_ant_init(wlc_info_t *wlc) |
Jason Cooper | a2627bc | 2010-09-14 09:45:31 -0400 | [diff] [blame] | 2051 | { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2052 | int aa; |
| 2053 | uint unit; |
| 2054 | char *vars; |
| 2055 | int bandtype; |
| 2056 | |
| 2057 | unit = wlc->pub->unit; |
| 2058 | vars = wlc->pub->vars; |
| 2059 | bandtype = wlc->band->bandtype; |
| 2060 | |
| 2061 | /* get antennas available */ |
Greg Kroah-Hartman | 562c885 | 2010-10-05 11:04:17 -0700 | [diff] [blame] | 2062 | aa = (s8) getintvar(vars, (BAND_5G(bandtype) ? "aa5g" : "aa2g")); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2063 | if (aa == 0) |
Greg Kroah-Hartman | 562c885 | 2010-10-05 11:04:17 -0700 | [diff] [blame] | 2064 | aa = (s8) getintvar(vars, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2065 | (BAND_5G(bandtype) ? "aa1" : "aa0")); |
| 2066 | if ((aa < 1) || (aa > 15)) { |
| 2067 | WL_ERROR(("wl%d: %s: Invalid antennas available in srom (0x%x), using 3.\n", unit, __func__, aa)); |
| 2068 | aa = 3; |
| 2069 | } |
| 2070 | |
| 2071 | /* reset the defaults if we have a single antenna */ |
| 2072 | if (aa == 1) { |
| 2073 | wlc->stf->ant_rx_ovr = ANT_RX_DIV_FORCE_0; |
| 2074 | wlc->stf->txant = ANT_TX_FORCE_0; |
| 2075 | } else if (aa == 2) { |
| 2076 | wlc->stf->ant_rx_ovr = ANT_RX_DIV_FORCE_1; |
| 2077 | wlc->stf->txant = ANT_TX_FORCE_1; |
| 2078 | } else { |
| 2079 | } |
| 2080 | |
| 2081 | /* Compute Antenna Gain */ |
| 2082 | wlc->band->antgain = |
Greg Kroah-Hartman | 562c885 | 2010-10-05 11:04:17 -0700 | [diff] [blame] | 2083 | (s8) getintvar(vars, (BAND_5G(bandtype) ? "ag1" : "ag0")); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2084 | wlc_attach_antgain_init(wlc); |
| 2085 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2086 | return true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2087 | } |
| 2088 | |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2089 | |
Greg Kroah-Hartman | 0d2f072 | 2010-10-08 14:28:21 -0700 | [diff] [blame] | 2090 | static void wlc_timers_deinit(wlc_info_t *wlc) |
Jason Cooper | a2627bc | 2010-09-14 09:45:31 -0400 | [diff] [blame] | 2091 | { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2092 | /* free timer state */ |
| 2093 | if (wlc->wdtimer) { |
| 2094 | wl_free_timer(wlc->wl, wlc->wdtimer); |
| 2095 | wlc->wdtimer = NULL; |
| 2096 | } |
| 2097 | if (wlc->radio_timer) { |
| 2098 | wl_free_timer(wlc->wl, wlc->radio_timer); |
| 2099 | wlc->radio_timer = NULL; |
| 2100 | } |
| 2101 | } |
| 2102 | |
Greg Kroah-Hartman | 0d2f072 | 2010-10-08 14:28:21 -0700 | [diff] [blame] | 2103 | static void wlc_detach_module(wlc_info_t *wlc) |
Jason Cooper | a2627bc | 2010-09-14 09:45:31 -0400 | [diff] [blame] | 2104 | { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2105 | if (wlc->asi) { |
| 2106 | wlc_antsel_detach(wlc->asi); |
| 2107 | wlc->asi = NULL; |
| 2108 | } |
| 2109 | |
| 2110 | if (wlc->ampdu) { |
| 2111 | wlc_ampdu_detach(wlc->ampdu); |
| 2112 | wlc->ampdu = NULL; |
| 2113 | } |
| 2114 | |
| 2115 | wlc_stf_detach(wlc); |
| 2116 | } |
| 2117 | |
| 2118 | /* |
| 2119 | * Return a count of the number of driver callbacks still pending. |
| 2120 | * |
| 2121 | * General policy is that wlc_detach can only dealloc/free software states. It can NOT |
| 2122 | * touch hardware registers since the d11core may be in reset and clock may not be available. |
| 2123 | * One exception is sb register access, which is possible if crystal is turned on |
| 2124 | * After "down" state, driver should avoid software timer with the exception of radio_monitor. |
| 2125 | */ |
Greg Kroah-Hartman | 0d2f072 | 2010-10-08 14:28:21 -0700 | [diff] [blame] | 2126 | uint wlc_detach(wlc_info_t *wlc) |
Jason Cooper | a2627bc | 2010-09-14 09:45:31 -0400 | [diff] [blame] | 2127 | { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2128 | uint i; |
| 2129 | uint callbacks = 0; |
| 2130 | |
| 2131 | if (wlc == NULL) |
| 2132 | return 0; |
| 2133 | |
| 2134 | WL_TRACE(("wl%d: %s\n", wlc->pub->unit, __func__)); |
| 2135 | |
| 2136 | ASSERT(!wlc->pub->up); |
| 2137 | |
| 2138 | callbacks += wlc_bmac_detach(wlc); |
| 2139 | |
| 2140 | /* delete software timers */ |
| 2141 | if (!wlc_radio_monitor_stop(wlc)) |
| 2142 | callbacks++; |
| 2143 | |
| 2144 | if (wlc->eventq) { |
| 2145 | wlc_eventq_detach(wlc->eventq); |
| 2146 | wlc->eventq = NULL; |
| 2147 | } |
| 2148 | |
| 2149 | wlc_channel_mgr_detach(wlc->cmi); |
| 2150 | |
| 2151 | wlc_timers_deinit(wlc); |
| 2152 | |
| 2153 | wlc_detach_module(wlc); |
| 2154 | |
| 2155 | /* free other state */ |
| 2156 | |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2157 | |
| 2158 | #ifdef BCMDBG |
| 2159 | if (wlc->country_ie_override) { |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 2160 | kfree(wlc->country_ie_override); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2161 | wlc->country_ie_override = NULL; |
| 2162 | } |
| 2163 | #endif /* BCMDBG */ |
| 2164 | |
| 2165 | { |
| 2166 | /* free dumpcb list */ |
| 2167 | dumpcb_t *prev, *ptr; |
| 2168 | prev = ptr = wlc->dumpcb_head; |
| 2169 | while (ptr) { |
| 2170 | ptr = prev->next; |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 2171 | kfree(prev); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2172 | prev = ptr; |
| 2173 | } |
| 2174 | wlc->dumpcb_head = NULL; |
| 2175 | } |
| 2176 | |
| 2177 | /* Detach from iovar manager */ |
| 2178 | wlc_module_unregister(wlc->pub, "wlc_iovars", wlc); |
| 2179 | |
| 2180 | /* |
| 2181 | if (wlc->ap) { |
| 2182 | wlc_ap_detach(wlc->ap); |
| 2183 | wlc->ap = NULL; |
| 2184 | } |
| 2185 | */ |
| 2186 | |
| 2187 | while (wlc->tx_queues != NULL) { |
| 2188 | wlc_txq_free(wlc, wlc->osh, wlc->tx_queues); |
| 2189 | } |
| 2190 | |
| 2191 | /* |
| 2192 | * consistency check: wlc_module_register/wlc_module_unregister calls |
| 2193 | * should match therefore nothing should be left here. |
| 2194 | */ |
| 2195 | for (i = 0; i < WLC_MAXMODULES; i++) |
| 2196 | ASSERT(wlc->modulecb[i].name[0] == '\0'); |
| 2197 | |
| 2198 | wlc_detach_mfree(wlc, wlc->osh); |
Jason Cooper | 90ea229 | 2010-09-14 09:45:32 -0400 | [diff] [blame] | 2199 | return callbacks; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2200 | } |
| 2201 | |
| 2202 | /* update state that depends on the current value of "ap" */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 2203 | void wlc_ap_upd(wlc_info_t *wlc) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2204 | { |
| 2205 | if (AP_ENAB(wlc->pub)) |
| 2206 | wlc->PLCPHdr_override = WLC_PLCP_AUTO; /* AP: short not allowed, but not enforced */ |
| 2207 | else |
| 2208 | wlc->PLCPHdr_override = WLC_PLCP_SHORT; /* STA-BSS; short capable */ |
| 2209 | |
| 2210 | /* disable vlan_mode on AP since some legacy STAs cannot rx tagged pkts */ |
| 2211 | wlc->vlan_mode = AP_ENAB(wlc->pub) ? OFF : AUTO; |
| 2212 | |
| 2213 | /* fixup mpc */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2214 | wlc->mpc = true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2215 | } |
| 2216 | |
| 2217 | /* read hwdisable state and propagate to wlc flag */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 2218 | static void wlc_radio_hwdisable_upd(wlc_info_t *wlc) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2219 | { |
| 2220 | if (wlc->pub->wlfeatureflag & WL_SWFL_NOHWRADIO || wlc->pub->hw_off) |
| 2221 | return; |
| 2222 | |
| 2223 | if (wlc_bmac_radio_read_hwdisabled(wlc->hw)) { |
| 2224 | mboolset(wlc->pub->radio_disabled, WL_RADIO_HW_DISABLE); |
| 2225 | } else { |
| 2226 | mboolclr(wlc->pub->radio_disabled, WL_RADIO_HW_DISABLE); |
| 2227 | } |
| 2228 | } |
| 2229 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2230 | /* return true if Minimum Power Consumption should be entered, false otherwise */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 2231 | bool wlc_is_non_delay_mpc(wlc_info_t *wlc) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2232 | { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2233 | return false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2234 | } |
| 2235 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 2236 | bool wlc_ismpc(wlc_info_t *wlc) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2237 | { |
Jason Cooper | 90ea229 | 2010-09-14 09:45:32 -0400 | [diff] [blame] | 2238 | return (wlc->mpc_delay_off == 0) && (wlc_is_non_delay_mpc(wlc)); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2239 | } |
| 2240 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 2241 | void wlc_radio_mpc_upd(wlc_info_t *wlc) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2242 | { |
| 2243 | bool mpc_radio, radio_state; |
| 2244 | |
| 2245 | /* |
| 2246 | * Clear the WL_RADIO_MPC_DISABLE bit when mpc feature is disabled |
| 2247 | * in case the WL_RADIO_MPC_DISABLE bit was set. Stop the radio |
| 2248 | * monitor also when WL_RADIO_MPC_DISABLE is the only reason that |
| 2249 | * the radio is going down. |
| 2250 | */ |
| 2251 | if (!wlc->mpc) { |
| 2252 | if (!wlc->pub->radio_disabled) |
| 2253 | return; |
| 2254 | mboolclr(wlc->pub->radio_disabled, WL_RADIO_MPC_DISABLE); |
| 2255 | wlc_radio_upd(wlc); |
| 2256 | if (!wlc->pub->radio_disabled) |
| 2257 | wlc_radio_monitor_stop(wlc); |
| 2258 | return; |
| 2259 | } |
| 2260 | |
| 2261 | /* |
| 2262 | * sync ismpc logic with WL_RADIO_MPC_DISABLE bit in wlc->pub->radio_disabled |
| 2263 | * to go ON, always call radio_upd synchronously |
| 2264 | * to go OFF, postpone radio_upd to later when context is safe(e.g. watchdog) |
| 2265 | */ |
| 2266 | radio_state = |
| 2267 | (mboolisset(wlc->pub->radio_disabled, WL_RADIO_MPC_DISABLE) ? OFF : |
| 2268 | ON); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2269 | mpc_radio = (wlc_ismpc(wlc) == true) ? OFF : ON; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2270 | |
| 2271 | if (radio_state == ON && mpc_radio == OFF) |
| 2272 | wlc->mpc_delay_off = wlc->mpc_dlycnt; |
| 2273 | else if (radio_state == OFF && mpc_radio == ON) { |
| 2274 | mboolclr(wlc->pub->radio_disabled, WL_RADIO_MPC_DISABLE); |
| 2275 | wlc_radio_upd(wlc); |
| 2276 | if (wlc->mpc_offcnt < WLC_MPC_THRESHOLD) { |
| 2277 | wlc->mpc_dlycnt = WLC_MPC_MAX_DELAYCNT; |
| 2278 | } else |
| 2279 | wlc->mpc_dlycnt = WLC_MPC_MIN_DELAYCNT; |
| 2280 | wlc->mpc_dur += OSL_SYSUPTIME() - wlc->mpc_laston_ts; |
| 2281 | } |
| 2282 | /* Below logic is meant to capture the transition from mpc off to mpc on for reasons |
| 2283 | * other than wlc->mpc_delay_off keeping the mpc off. In that case reset |
| 2284 | * wlc->mpc_delay_off to wlc->mpc_dlycnt, so that we restart the countdown of mpc_delay_off |
| 2285 | */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2286 | if ((wlc->prev_non_delay_mpc == false) && |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2287 | (wlc_is_non_delay_mpc(wlc) == true) && wlc->mpc_delay_off) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2288 | wlc->mpc_delay_off = wlc->mpc_dlycnt; |
| 2289 | } |
| 2290 | wlc->prev_non_delay_mpc = wlc_is_non_delay_mpc(wlc); |
| 2291 | } |
| 2292 | |
| 2293 | /* |
| 2294 | * centralized radio disable/enable function, |
| 2295 | * invoke radio enable/disable after updating hwradio status |
| 2296 | */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 2297 | static void wlc_radio_upd(wlc_info_t *wlc) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2298 | { |
| 2299 | if (wlc->pub->radio_disabled) |
| 2300 | wlc_radio_disable(wlc); |
| 2301 | else |
| 2302 | wlc_radio_enable(wlc); |
| 2303 | } |
| 2304 | |
| 2305 | /* maintain LED behavior in down state */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 2306 | static void wlc_down_led_upd(wlc_info_t *wlc) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2307 | { |
| 2308 | ASSERT(!wlc->pub->up); |
| 2309 | |
| 2310 | /* maintain LEDs while in down state, turn on sbclk if not available yet */ |
| 2311 | /* turn on sbclk if necessary */ |
| 2312 | if (!AP_ENAB(wlc->pub)) { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2313 | wlc_pllreq(wlc, true, WLC_PLLREQ_FLIP); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2314 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2315 | wlc_pllreq(wlc, false, WLC_PLLREQ_FLIP); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2316 | } |
| 2317 | } |
| 2318 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 2319 | void wlc_radio_disable(wlc_info_t *wlc) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2320 | { |
| 2321 | if (!wlc->pub->up) { |
| 2322 | wlc_down_led_upd(wlc); |
| 2323 | return; |
| 2324 | } |
| 2325 | |
| 2326 | wlc_radio_monitor_start(wlc); |
| 2327 | wl_down(wlc->wl); |
| 2328 | } |
| 2329 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 2330 | static void wlc_radio_enable(wlc_info_t *wlc) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2331 | { |
| 2332 | if (wlc->pub->up) |
| 2333 | return; |
| 2334 | |
| 2335 | if (DEVICEREMOVED(wlc)) |
| 2336 | return; |
| 2337 | |
| 2338 | if (!wlc->down_override) { /* imposed by wl down/out ioctl */ |
| 2339 | wl_up(wlc->wl); |
| 2340 | } |
| 2341 | } |
| 2342 | |
| 2343 | /* periodical query hw radio button while driver is "down" */ |
| 2344 | static void wlc_radio_timer(void *arg) |
| 2345 | { |
| 2346 | wlc_info_t *wlc = (wlc_info_t *) arg; |
| 2347 | |
| 2348 | if (DEVICEREMOVED(wlc)) { |
| 2349 | WL_ERROR(("wl%d: %s: dead chip\n", wlc->pub->unit, __func__)); |
| 2350 | wl_down(wlc->wl); |
| 2351 | return; |
| 2352 | } |
| 2353 | |
| 2354 | /* cap mpc off count */ |
| 2355 | if (wlc->mpc_offcnt < WLC_MPC_MAX_DELAYCNT) |
| 2356 | wlc->mpc_offcnt++; |
| 2357 | |
| 2358 | /* validate all the reasons driver could be down and running this radio_timer */ |
| 2359 | ASSERT(wlc->pub->radio_disabled || wlc->down_override); |
| 2360 | wlc_radio_hwdisable_upd(wlc); |
| 2361 | wlc_radio_upd(wlc); |
| 2362 | } |
| 2363 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 2364 | static bool wlc_radio_monitor_start(wlc_info_t *wlc) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2365 | { |
| 2366 | /* Don't start the timer if HWRADIO feature is disabled */ |
| 2367 | if (wlc->radio_monitor || (wlc->pub->wlfeatureflag & WL_SWFL_NOHWRADIO)) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2368 | return true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2369 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2370 | wlc->radio_monitor = true; |
| 2371 | wlc_pllreq(wlc, true, WLC_PLLREQ_RADIO_MON); |
| 2372 | wl_add_timer(wlc->wl, wlc->radio_timer, TIMER_INTERVAL_RADIOCHK, true); |
| 2373 | return true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2374 | } |
| 2375 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 2376 | bool wlc_radio_monitor_stop(wlc_info_t *wlc) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2377 | { |
| 2378 | if (!wlc->radio_monitor) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2379 | return true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2380 | |
| 2381 | ASSERT((wlc->pub->wlfeatureflag & WL_SWFL_NOHWRADIO) != |
| 2382 | WL_SWFL_NOHWRADIO); |
| 2383 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2384 | wlc->radio_monitor = false; |
| 2385 | wlc_pllreq(wlc, false, WLC_PLLREQ_RADIO_MON); |
Jason Cooper | 90ea229 | 2010-09-14 09:45:32 -0400 | [diff] [blame] | 2386 | return wl_del_timer(wlc->wl, wlc->radio_timer); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2387 | } |
| 2388 | |
| 2389 | /* bring the driver down, but don't reset hardware */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 2390 | void wlc_out(wlc_info_t *wlc) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2391 | { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2392 | wlc_bmac_set_noreset(wlc->hw, true); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2393 | wlc_radio_upd(wlc); |
| 2394 | wl_down(wlc->wl); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2395 | wlc_bmac_set_noreset(wlc->hw, false); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2396 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2397 | /* core clk is true in BMAC driver due to noreset, need to mirror it in HIGH */ |
| 2398 | wlc->clk = true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2399 | |
| 2400 | /* This will make sure that when 'up' is done |
| 2401 | * after 'out' it'll restore hardware (especially gpios) |
| 2402 | */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2403 | wlc->pub->hw_up = false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2404 | } |
| 2405 | |
| 2406 | #if defined(BCMDBG) |
| 2407 | /* Verify the sanity of wlc->tx_prec_map. This can be done only by making sure that |
| 2408 | * if there is no packet pending for the FIFO, then the corresponding prec bits should be set |
| 2409 | * in prec_map. Of course, ignore this rule when block_datafifo is set |
| 2410 | */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 2411 | static bool wlc_tx_prec_map_verify(wlc_info_t *wlc) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2412 | { |
| 2413 | /* For non-WME, both fifos have overlapping prec_map. So it's an error only if both |
| 2414 | * fail the check. |
| 2415 | */ |
| 2416 | if (!EDCF_ENAB(wlc->pub)) { |
| 2417 | if (!(WLC_TX_FIFO_CHECK(wlc, TX_DATA_FIFO) || |
| 2418 | WLC_TX_FIFO_CHECK(wlc, TX_CTL_FIFO))) |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2419 | return false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2420 | else |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2421 | return true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2422 | } |
| 2423 | |
Jason Cooper | 90ea229 | 2010-09-14 09:45:32 -0400 | [diff] [blame] | 2424 | return WLC_TX_FIFO_CHECK(wlc, TX_AC_BK_FIFO) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2425 | && WLC_TX_FIFO_CHECK(wlc, TX_AC_BE_FIFO) |
| 2426 | && WLC_TX_FIFO_CHECK(wlc, TX_AC_VI_FIFO) |
Jason Cooper | 90ea229 | 2010-09-14 09:45:32 -0400 | [diff] [blame] | 2427 | && WLC_TX_FIFO_CHECK(wlc, TX_AC_VO_FIFO); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2428 | } |
| 2429 | #endif /* BCMDBG */ |
| 2430 | |
| 2431 | static void wlc_watchdog_by_timer(void *arg) |
| 2432 | { |
| 2433 | wlc_info_t *wlc = (wlc_info_t *) arg; |
| 2434 | wlc_watchdog(arg); |
| 2435 | if (WLC_WATCHDOG_TBTT(wlc)) { |
| 2436 | /* set to normal osl watchdog period */ |
| 2437 | wl_del_timer(wlc->wl, wlc->wdtimer); |
| 2438 | wl_add_timer(wlc->wl, wlc->wdtimer, TIMER_INTERVAL_WATCHDOG, |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2439 | true); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2440 | } |
| 2441 | } |
| 2442 | |
| 2443 | /* common watchdog code */ |
| 2444 | static void wlc_watchdog(void *arg) |
| 2445 | { |
| 2446 | wlc_info_t *wlc = (wlc_info_t *) arg; |
| 2447 | int i; |
| 2448 | wlc_bsscfg_t *cfg; |
| 2449 | |
| 2450 | WL_TRACE(("wl%d: wlc_watchdog\n", wlc->pub->unit)); |
| 2451 | |
| 2452 | if (!wlc->pub->up) |
| 2453 | return; |
| 2454 | |
| 2455 | if (DEVICEREMOVED(wlc)) { |
| 2456 | WL_ERROR(("wl%d: %s: dead chip\n", wlc->pub->unit, __func__)); |
| 2457 | wl_down(wlc->wl); |
| 2458 | return; |
| 2459 | } |
| 2460 | |
| 2461 | /* increment second count */ |
| 2462 | wlc->pub->now++; |
| 2463 | |
| 2464 | /* delay radio disable */ |
| 2465 | if (wlc->mpc_delay_off) { |
| 2466 | if (--wlc->mpc_delay_off == 0) { |
| 2467 | mboolset(wlc->pub->radio_disabled, |
| 2468 | WL_RADIO_MPC_DISABLE); |
| 2469 | if (wlc->mpc && wlc_ismpc(wlc)) |
| 2470 | wlc->mpc_offcnt = 0; |
| 2471 | wlc->mpc_laston_ts = OSL_SYSUPTIME(); |
| 2472 | } |
| 2473 | } |
| 2474 | |
| 2475 | /* mpc sync */ |
| 2476 | wlc_radio_mpc_upd(wlc); |
| 2477 | /* radio sync: sw/hw/mpc --> radio_disable/radio_enable */ |
| 2478 | wlc_radio_hwdisable_upd(wlc); |
| 2479 | wlc_radio_upd(wlc); |
| 2480 | /* if ismpc, driver should be in down state if up/down is allowed */ |
| 2481 | if (wlc->mpc && wlc_ismpc(wlc)) |
| 2482 | ASSERT(!wlc->pub->up); |
| 2483 | /* if radio is disable, driver may be down, quit here */ |
| 2484 | if (wlc->pub->radio_disabled) |
| 2485 | return; |
| 2486 | |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2487 | wlc_bmac_watchdog(wlc); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2488 | |
| 2489 | /* occasionally sample mac stat counters to detect 16-bit counter wrap */ |
| 2490 | if ((WLC_UPDATE_STATS(wlc)) |
| 2491 | && (!(wlc->pub->now % SW_TIMER_MAC_STAT_UPD))) |
| 2492 | wlc_statsupd(wlc); |
| 2493 | |
| 2494 | /* Manage TKIP countermeasures timers */ |
| 2495 | FOREACH_BSS(wlc, i, cfg) { |
| 2496 | if (cfg->tk_cm_dt) { |
| 2497 | cfg->tk_cm_dt--; |
| 2498 | } |
| 2499 | if (cfg->tk_cm_bt) { |
| 2500 | cfg->tk_cm_bt--; |
| 2501 | } |
| 2502 | } |
| 2503 | |
| 2504 | /* Call any registered watchdog handlers */ |
| 2505 | for (i = 0; i < WLC_MAXMODULES; i++) { |
| 2506 | if (wlc->modulecb[i].watchdog_fn) |
| 2507 | wlc->modulecb[i].watchdog_fn(wlc->modulecb[i].hdl); |
| 2508 | } |
| 2509 | |
| 2510 | if (WLCISNPHY(wlc->band) && !wlc->pub->tempsense_disable && |
| 2511 | ((wlc->pub->now - wlc->tempsense_lasttime) >= |
| 2512 | WLC_TEMPSENSE_PERIOD)) { |
| 2513 | wlc->tempsense_lasttime = wlc->pub->now; |
| 2514 | wlc_tempsense_upd(wlc); |
| 2515 | } |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2516 | /* BMAC_NOTE: for HIGH_ONLY driver, this seems being called after RPC bus failed */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2517 | ASSERT(wlc_bmac_taclear(wlc->hw, true)); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2518 | |
| 2519 | /* Verify that tx_prec_map and fifos are in sync to avoid lock ups */ |
| 2520 | ASSERT(wlc_tx_prec_map_verify(wlc)); |
| 2521 | |
| 2522 | ASSERT(wlc_ps_check(wlc)); |
| 2523 | } |
| 2524 | |
| 2525 | /* make interface operational */ |
Jason Cooper | b4f790e | 2010-10-11 10:02:58 -0400 | [diff] [blame] | 2526 | int wlc_up(wlc_info_t *wlc) |
Jason Cooper | a2627bc | 2010-09-14 09:45:31 -0400 | [diff] [blame] | 2527 | { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2528 | WL_TRACE(("wl%d: %s:\n", wlc->pub->unit, __func__)); |
| 2529 | |
| 2530 | /* HW is turned off so don't try to access it */ |
| 2531 | if (wlc->pub->hw_off || DEVICEREMOVED(wlc)) |
| 2532 | return BCME_RADIOOFF; |
| 2533 | |
| 2534 | if (!wlc->pub->hw_up) { |
| 2535 | wlc_bmac_hw_up(wlc->hw); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2536 | wlc->pub->hw_up = true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2537 | } |
| 2538 | |
| 2539 | if ((wlc->pub->boardflags & BFL_FEM) |
| 2540 | && (CHIPID(wlc->pub->sih->chip) == BCM4313_CHIP_ID)) { |
| 2541 | if (wlc->pub->boardrev >= 0x1250 |
| 2542 | && (wlc->pub->boardflags & BFL_FEM_BT)) { |
| 2543 | wlc_mhf(wlc, MHF5, MHF5_4313_GPIOCTRL, |
| 2544 | MHF5_4313_GPIOCTRL, WLC_BAND_ALL); |
| 2545 | } else { |
| 2546 | wlc_mhf(wlc, MHF4, MHF4_EXTPA_ENABLE, MHF4_EXTPA_ENABLE, |
| 2547 | WLC_BAND_ALL); |
| 2548 | } |
| 2549 | } |
| 2550 | |
| 2551 | /* |
| 2552 | * Need to read the hwradio status here to cover the case where the system |
| 2553 | * is loaded with the hw radio disabled. We do not want to bring the driver up in this case. |
| 2554 | * if radio is disabled, abort up, lower power, start radio timer and return 0(for NDIS) |
| 2555 | * don't call radio_update to avoid looping wlc_up. |
| 2556 | * |
| 2557 | * wlc_bmac_up_prep() returns either 0 or BCME_RADIOOFF only |
| 2558 | */ |
| 2559 | if (!wlc->pub->radio_disabled) { |
| 2560 | int status = wlc_bmac_up_prep(wlc->hw); |
| 2561 | if (status == BCME_RADIOOFF) { |
| 2562 | if (!mboolisset |
| 2563 | (wlc->pub->radio_disabled, WL_RADIO_HW_DISABLE)) { |
| 2564 | int idx; |
| 2565 | wlc_bsscfg_t *bsscfg; |
| 2566 | mboolset(wlc->pub->radio_disabled, |
| 2567 | WL_RADIO_HW_DISABLE); |
| 2568 | |
| 2569 | FOREACH_BSS(wlc, idx, bsscfg) { |
| 2570 | if (!BSSCFG_STA(bsscfg) |
| 2571 | || !bsscfg->enable || !bsscfg->BSS) |
| 2572 | continue; |
| 2573 | WL_ERROR(("wl%d.%d: wlc_up: rfdisable -> " "wlc_bsscfg_disable()\n", wlc->pub->unit, idx)); |
| 2574 | } |
| 2575 | } |
| 2576 | } else |
| 2577 | ASSERT(!status); |
| 2578 | } |
| 2579 | |
| 2580 | if (wlc->pub->radio_disabled) { |
| 2581 | wlc_radio_monitor_start(wlc); |
| 2582 | return 0; |
| 2583 | } |
| 2584 | |
| 2585 | /* wlc_bmac_up_prep has done wlc_corereset(). so clk is on, set it */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2586 | wlc->clk = true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2587 | |
| 2588 | wlc_radio_monitor_stop(wlc); |
| 2589 | |
| 2590 | /* Set EDCF hostflags */ |
| 2591 | if (EDCF_ENAB(wlc->pub)) { |
| 2592 | wlc_mhf(wlc, MHF1, MHF1_EDCF, MHF1_EDCF, WLC_BAND_ALL); |
| 2593 | } else { |
| 2594 | wlc_mhf(wlc, MHF1, MHF1_EDCF, 0, WLC_BAND_ALL); |
| 2595 | } |
| 2596 | |
| 2597 | if (WLC_WAR16165(wlc)) |
| 2598 | wlc_mhf(wlc, MHF2, MHF2_PCISLOWCLKWAR, MHF2_PCISLOWCLKWAR, |
| 2599 | WLC_BAND_ALL); |
| 2600 | |
| 2601 | wl_init(wlc->wl); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2602 | wlc->pub->up = true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2603 | |
| 2604 | if (wlc->bandinit_pending) { |
| 2605 | wlc_suspend_mac_and_wait(wlc); |
| 2606 | wlc_set_chanspec(wlc, wlc->default_bss->chanspec); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2607 | wlc->bandinit_pending = false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2608 | wlc_enable_mac(wlc); |
| 2609 | } |
| 2610 | |
| 2611 | wlc_bmac_up_finish(wlc->hw); |
| 2612 | |
| 2613 | /* other software states up after ISR is running */ |
| 2614 | /* start APs that were to be brought up but are not up yet */ |
| 2615 | /* if (AP_ENAB(wlc->pub)) wlc_restart_ap(wlc->ap); */ |
| 2616 | |
| 2617 | /* Program the TX wme params with the current settings */ |
| 2618 | wlc_wme_retries_write(wlc); |
| 2619 | |
| 2620 | /* start one second watchdog timer */ |
| 2621 | ASSERT(!wlc->WDarmed); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2622 | wl_add_timer(wlc->wl, wlc->wdtimer, TIMER_INTERVAL_WATCHDOG, true); |
| 2623 | wlc->WDarmed = true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2624 | |
| 2625 | /* ensure antenna config is up to date */ |
| 2626 | wlc_stf_phy_txant_upd(wlc); |
| 2627 | /* ensure LDPC config is in sync */ |
| 2628 | wlc_ht_update_ldpc(wlc, wlc->stf->ldpc); |
| 2629 | |
Jason Cooper | 90ea229 | 2010-09-14 09:45:32 -0400 | [diff] [blame] | 2630 | return 0; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2631 | } |
| 2632 | |
| 2633 | /* Initialize the base precedence map for dequeueing from txq based on WME settings */ |
Jason Cooper | b4f790e | 2010-10-11 10:02:58 -0400 | [diff] [blame] | 2634 | static void wlc_tx_prec_map_init(wlc_info_t *wlc) |
Jason Cooper | a2627bc | 2010-09-14 09:45:31 -0400 | [diff] [blame] | 2635 | { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2636 | wlc->tx_prec_map = WLC_PREC_BMP_ALL; |
Brett Rudley | 9249ede | 2010-11-30 20:09:49 -0800 | [diff] [blame^] | 2637 | memset(wlc->fifo2prec_map, 0, NFIFO * sizeof(u16)); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2638 | |
| 2639 | /* For non-WME, both fifos have overlapping MAXPRIO. So just disable all precedences |
| 2640 | * if either is full. |
| 2641 | */ |
| 2642 | if (!EDCF_ENAB(wlc->pub)) { |
| 2643 | wlc->fifo2prec_map[TX_DATA_FIFO] = WLC_PREC_BMP_ALL; |
| 2644 | wlc->fifo2prec_map[TX_CTL_FIFO] = WLC_PREC_BMP_ALL; |
| 2645 | } else { |
| 2646 | wlc->fifo2prec_map[TX_AC_BK_FIFO] = WLC_PREC_BMP_AC_BK; |
| 2647 | wlc->fifo2prec_map[TX_AC_BE_FIFO] = WLC_PREC_BMP_AC_BE; |
| 2648 | wlc->fifo2prec_map[TX_AC_VI_FIFO] = WLC_PREC_BMP_AC_VI; |
| 2649 | wlc->fifo2prec_map[TX_AC_VO_FIFO] = WLC_PREC_BMP_AC_VO; |
| 2650 | } |
| 2651 | } |
| 2652 | |
Jason Cooper | 9927fc2 | 2010-10-11 10:02:59 -0400 | [diff] [blame] | 2653 | static uint wlc_down_del_timer(wlc_info_t *wlc) |
Jason Cooper | a2627bc | 2010-09-14 09:45:31 -0400 | [diff] [blame] | 2654 | { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2655 | uint callbacks = 0; |
| 2656 | |
| 2657 | return callbacks; |
| 2658 | } |
| 2659 | |
| 2660 | /* |
| 2661 | * Mark the interface nonoperational, stop the software mechanisms, |
| 2662 | * disable the hardware, free any transient buffer state. |
| 2663 | * Return a count of the number of driver callbacks still pending. |
| 2664 | */ |
Jason Cooper | 9927fc2 | 2010-10-11 10:02:59 -0400 | [diff] [blame] | 2665 | uint wlc_down(wlc_info_t *wlc) |
Jason Cooper | a2627bc | 2010-09-14 09:45:31 -0400 | [diff] [blame] | 2666 | { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2667 | |
| 2668 | uint callbacks = 0; |
| 2669 | int i; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2670 | bool dev_gone = false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2671 | wlc_txq_info_t *qi; |
| 2672 | |
| 2673 | WL_TRACE(("wl%d: %s:\n", wlc->pub->unit, __func__)); |
| 2674 | |
| 2675 | /* check if we are already in the going down path */ |
| 2676 | if (wlc->going_down) { |
| 2677 | WL_ERROR(("wl%d: %s: Driver going down so return\n", |
| 2678 | wlc->pub->unit, __func__)); |
| 2679 | return 0; |
| 2680 | } |
| 2681 | if (!wlc->pub->up) |
Jason Cooper | 90ea229 | 2010-09-14 09:45:32 -0400 | [diff] [blame] | 2682 | return callbacks; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2683 | |
| 2684 | /* in between, mpc could try to bring down again.. */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2685 | wlc->going_down = true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2686 | |
| 2687 | callbacks += wlc_bmac_down_prep(wlc->hw); |
| 2688 | |
| 2689 | dev_gone = DEVICEREMOVED(wlc); |
| 2690 | |
| 2691 | /* Call any registered down handlers */ |
| 2692 | for (i = 0; i < WLC_MAXMODULES; i++) { |
| 2693 | if (wlc->modulecb[i].down_fn) |
| 2694 | callbacks += |
| 2695 | wlc->modulecb[i].down_fn(wlc->modulecb[i].hdl); |
| 2696 | } |
| 2697 | |
| 2698 | /* cancel the watchdog timer */ |
| 2699 | if (wlc->WDarmed) { |
| 2700 | if (!wl_del_timer(wlc->wl, wlc->wdtimer)) |
| 2701 | callbacks++; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2702 | wlc->WDarmed = false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2703 | } |
| 2704 | /* cancel all other timers */ |
| 2705 | callbacks += wlc_down_del_timer(wlc); |
| 2706 | |
| 2707 | /* interrupt must have been blocked */ |
| 2708 | ASSERT((wlc->macintmask == 0) || !wlc->pub->up); |
| 2709 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2710 | wlc->pub->up = false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2711 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2712 | wlc_phy_mute_upd(wlc->band->pi, false, PHY_MUTE_ALL); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2713 | |
| 2714 | /* clear txq flow control */ |
| 2715 | wlc_txflowcontrol_reset(wlc); |
| 2716 | |
| 2717 | /* flush tx queues */ |
| 2718 | for (qi = wlc->tx_queues; qi != NULL; qi = qi->next) { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2719 | pktq_flush(wlc->osh, &qi->q, true, NULL, 0); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2720 | ASSERT(pktq_empty(&qi->q)); |
| 2721 | } |
| 2722 | |
| 2723 | /* flush event queue. |
| 2724 | * Should be the last thing done after all the events are generated |
| 2725 | * Just delivers the events synchronously instead of waiting for a timer |
| 2726 | */ |
| 2727 | callbacks += wlc_eventq_down(wlc->eventq); |
| 2728 | |
| 2729 | callbacks += wlc_bmac_down_finish(wlc->hw); |
| 2730 | |
| 2731 | /* wlc_bmac_down_finish has done wlc_coredisable(). so clk is off */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2732 | wlc->clk = false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2733 | |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2734 | |
| 2735 | /* Verify all packets are flushed from the driver */ |
Arend van Spriel | 3be727c | 2010-11-23 22:20:30 +0100 | [diff] [blame] | 2736 | if (wlc->osh->pub.pktalloced != 0) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2737 | WL_ERROR(("%d packets not freed at wlc_down!!!!!!\n", |
Arend van Spriel | 3be727c | 2010-11-23 22:20:30 +0100 | [diff] [blame] | 2738 | wlc->osh->pub.pktalloced)); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2739 | } |
| 2740 | #ifdef BCMDBG |
| 2741 | /* Since all the packets should have been freed, |
| 2742 | * all callbacks should have been called |
| 2743 | */ |
| 2744 | for (i = 1; i <= wlc->pub->tunables->maxpktcb; i++) |
| 2745 | ASSERT(wlc->pkt_callback[i].fn == NULL); |
| 2746 | #endif |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2747 | wlc->going_down = false; |
Jason Cooper | 90ea229 | 2010-09-14 09:45:32 -0400 | [diff] [blame] | 2748 | return callbacks; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2749 | } |
| 2750 | |
| 2751 | /* Set the current gmode configuration */ |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 2752 | int wlc_set_gmode(wlc_info_t *wlc, u8 gmode, bool config) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2753 | { |
| 2754 | int ret = 0; |
| 2755 | uint i; |
| 2756 | wlc_rateset_t rs; |
| 2757 | /* Default to 54g Auto */ |
Greg Kroah-Hartman | 562c885 | 2010-10-05 11:04:17 -0700 | [diff] [blame] | 2758 | s8 shortslot = WLC_SHORTSLOT_AUTO; /* Advertise and use shortslot (-1/0/1 Auto/Off/On) */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2759 | bool shortslot_restrict = false; /* Restrict association to stations that support shortslot |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2760 | */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2761 | bool ignore_bcns = true; /* Ignore legacy beacons on the same channel */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2762 | bool ofdm_basic = false; /* Make 6, 12, and 24 basic rates */ |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2763 | int preamble = WLC_PLCP_LONG; /* Advertise and use short preambles (-1/0/1 Auto/Off/On) */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2764 | bool preamble_restrict = false; /* Restrict association to stations that support short |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2765 | * preambles |
| 2766 | */ |
| 2767 | wlcband_t *band; |
| 2768 | |
| 2769 | /* if N-support is enabled, allow Gmode set as long as requested |
| 2770 | * Gmode is not GMODE_LEGACY_B |
| 2771 | */ |
| 2772 | if (N_ENAB(wlc->pub) && gmode == GMODE_LEGACY_B) |
| 2773 | return BCME_UNSUPPORTED; |
| 2774 | |
| 2775 | /* verify that we are dealing with 2G band and grab the band pointer */ |
| 2776 | if (wlc->band->bandtype == WLC_BAND_2G) |
| 2777 | band = wlc->band; |
| 2778 | else if ((NBANDS(wlc) > 1) && |
| 2779 | (wlc->bandstate[OTHERBANDUNIT(wlc)]->bandtype == WLC_BAND_2G)) |
| 2780 | band = wlc->bandstate[OTHERBANDUNIT(wlc)]; |
| 2781 | else |
| 2782 | return BCME_BADBAND; |
| 2783 | |
| 2784 | /* Legacy or bust when no OFDM is supported by regulatory */ |
| 2785 | if ((wlc_channel_locale_flags_in_band(wlc->cmi, band->bandunit) & |
| 2786 | WLC_NO_OFDM) && (gmode != GMODE_LEGACY_B)) |
| 2787 | return BCME_RANGE; |
| 2788 | |
| 2789 | /* update configuration value */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2790 | if (config == true) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2791 | wlc_protection_upd(wlc, WLC_PROT_G_USER, gmode); |
| 2792 | |
| 2793 | /* Clear supported rates filter */ |
Brett Rudley | 9249ede | 2010-11-30 20:09:49 -0800 | [diff] [blame^] | 2794 | memset(&wlc->sup_rates_override, 0, sizeof(wlc_rateset_t)); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2795 | |
| 2796 | /* Clear rateset override */ |
Brett Rudley | 9249ede | 2010-11-30 20:09:49 -0800 | [diff] [blame^] | 2797 | memset(&rs, 0, sizeof(wlc_rateset_t)); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2798 | |
| 2799 | switch (gmode) { |
| 2800 | case GMODE_LEGACY_B: |
| 2801 | shortslot = WLC_SHORTSLOT_OFF; |
| 2802 | wlc_rateset_copy(&gphy_legacy_rates, &rs); |
| 2803 | |
| 2804 | break; |
| 2805 | |
| 2806 | case GMODE_LRS: |
| 2807 | if (AP_ENAB(wlc->pub)) |
| 2808 | wlc_rateset_copy(&cck_rates, &wlc->sup_rates_override); |
| 2809 | break; |
| 2810 | |
| 2811 | case GMODE_AUTO: |
| 2812 | /* Accept defaults */ |
| 2813 | break; |
| 2814 | |
| 2815 | case GMODE_ONLY: |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2816 | ofdm_basic = true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2817 | preamble = WLC_PLCP_SHORT; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2818 | preamble_restrict = true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2819 | break; |
| 2820 | |
| 2821 | case GMODE_PERFORMANCE: |
| 2822 | if (AP_ENAB(wlc->pub)) /* Put all rates into the Supported Rates element */ |
| 2823 | wlc_rateset_copy(&cck_ofdm_rates, |
| 2824 | &wlc->sup_rates_override); |
| 2825 | |
| 2826 | shortslot = WLC_SHORTSLOT_ON; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2827 | shortslot_restrict = true; |
| 2828 | ofdm_basic = true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2829 | preamble = WLC_PLCP_SHORT; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2830 | preamble_restrict = true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2831 | break; |
| 2832 | |
| 2833 | default: |
| 2834 | /* Error */ |
| 2835 | WL_ERROR(("wl%d: %s: invalid gmode %d\n", wlc->pub->unit, |
| 2836 | __func__, gmode)); |
| 2837 | return BCME_UNSUPPORTED; |
| 2838 | } |
| 2839 | |
| 2840 | /* |
| 2841 | * If we are switching to gmode == GMODE_LEGACY_B, |
| 2842 | * clean up rate info that may refer to OFDM rates. |
| 2843 | */ |
| 2844 | if ((gmode == GMODE_LEGACY_B) && (band->gmode != GMODE_LEGACY_B)) { |
| 2845 | band->gmode = gmode; |
| 2846 | if (band->rspec_override && !IS_CCK(band->rspec_override)) { |
| 2847 | band->rspec_override = 0; |
| 2848 | wlc_reprate_init(wlc); |
| 2849 | } |
| 2850 | if (band->mrspec_override && !IS_CCK(band->mrspec_override)) { |
| 2851 | band->mrspec_override = 0; |
| 2852 | } |
| 2853 | } |
| 2854 | |
| 2855 | band->gmode = gmode; |
| 2856 | |
| 2857 | wlc->ignore_bcns = ignore_bcns; |
| 2858 | |
| 2859 | wlc->shortslot_override = shortslot; |
| 2860 | |
| 2861 | if (AP_ENAB(wlc->pub)) { |
| 2862 | /* wlc->ap->shortslot_restrict = shortslot_restrict; */ |
| 2863 | wlc->PLCPHdr_override = |
| 2864 | (preamble != |
| 2865 | WLC_PLCP_LONG) ? WLC_PLCP_SHORT : WLC_PLCP_AUTO; |
| 2866 | } |
| 2867 | |
| 2868 | if ((AP_ENAB(wlc->pub) && preamble != WLC_PLCP_LONG) |
| 2869 | || preamble == WLC_PLCP_SHORT) |
| 2870 | wlc->default_bss->capability |= DOT11_CAP_SHORT; |
| 2871 | else |
| 2872 | wlc->default_bss->capability &= ~DOT11_CAP_SHORT; |
| 2873 | |
| 2874 | /* Update shortslot capability bit for AP and IBSS */ |
| 2875 | if ((AP_ENAB(wlc->pub) && shortslot == WLC_SHORTSLOT_AUTO) || |
| 2876 | shortslot == WLC_SHORTSLOT_ON) |
| 2877 | wlc->default_bss->capability |= DOT11_CAP_SHORTSLOT; |
| 2878 | else |
| 2879 | wlc->default_bss->capability &= ~DOT11_CAP_SHORTSLOT; |
| 2880 | |
| 2881 | /* Use the default 11g rateset */ |
| 2882 | if (!rs.count) |
| 2883 | wlc_rateset_copy(&cck_ofdm_rates, &rs); |
| 2884 | |
| 2885 | if (ofdm_basic) { |
| 2886 | for (i = 0; i < rs.count; i++) { |
| 2887 | if (rs.rates[i] == WLC_RATE_6M |
| 2888 | || rs.rates[i] == WLC_RATE_12M |
| 2889 | || rs.rates[i] == WLC_RATE_24M) |
| 2890 | rs.rates[i] |= WLC_RATE_FLAG; |
| 2891 | } |
| 2892 | } |
| 2893 | |
| 2894 | /* Set default bss rateset */ |
| 2895 | wlc->default_bss->rateset.count = rs.count; |
| 2896 | bcopy((char *)rs.rates, (char *)wlc->default_bss->rateset.rates, |
| 2897 | sizeof(wlc->default_bss->rateset.rates)); |
| 2898 | |
| 2899 | return ret; |
| 2900 | } |
| 2901 | |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2902 | static int wlc_nmode_validate(wlc_info_t *wlc, s32 nmode) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2903 | { |
| 2904 | int err = 0; |
| 2905 | |
| 2906 | switch (nmode) { |
| 2907 | |
| 2908 | case OFF: |
| 2909 | break; |
| 2910 | |
| 2911 | case AUTO: |
| 2912 | case WL_11N_2x2: |
| 2913 | case WL_11N_3x3: |
| 2914 | if (!(WLC_PHY_11N_CAP(wlc->band))) |
| 2915 | err = BCME_BADBAND; |
| 2916 | break; |
| 2917 | |
| 2918 | default: |
| 2919 | err = BCME_RANGE; |
| 2920 | break; |
| 2921 | } |
| 2922 | |
| 2923 | return err; |
| 2924 | } |
| 2925 | |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2926 | int wlc_set_nmode(wlc_info_t *wlc, s32 nmode) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2927 | { |
| 2928 | uint i; |
| 2929 | int err; |
| 2930 | |
| 2931 | err = wlc_nmode_validate(wlc, nmode); |
| 2932 | ASSERT(err == 0); |
| 2933 | if (err) |
| 2934 | return err; |
| 2935 | |
| 2936 | switch (nmode) { |
| 2937 | case OFF: |
| 2938 | wlc->pub->_n_enab = OFF; |
| 2939 | wlc->default_bss->flags &= ~WLC_BSS_HT; |
| 2940 | /* delete the mcs rates from the default and hw ratesets */ |
| 2941 | wlc_rateset_mcs_clear(&wlc->default_bss->rateset); |
| 2942 | for (i = 0; i < NBANDS(wlc); i++) { |
| 2943 | memset(wlc->bandstate[i]->hw_rateset.mcs, 0, |
| 2944 | MCSSET_LEN); |
| 2945 | if (IS_MCS(wlc->band->rspec_override)) { |
| 2946 | wlc->bandstate[i]->rspec_override = 0; |
| 2947 | wlc_reprate_init(wlc); |
| 2948 | } |
| 2949 | if (IS_MCS(wlc->band->mrspec_override)) |
| 2950 | wlc->bandstate[i]->mrspec_override = 0; |
| 2951 | } |
| 2952 | break; |
| 2953 | |
| 2954 | case AUTO: |
| 2955 | if (wlc->stf->txstreams == WL_11N_3x3) |
| 2956 | nmode = WL_11N_3x3; |
| 2957 | else |
| 2958 | nmode = WL_11N_2x2; |
| 2959 | case WL_11N_2x2: |
| 2960 | case WL_11N_3x3: |
| 2961 | ASSERT(WLC_PHY_11N_CAP(wlc->band)); |
| 2962 | /* force GMODE_AUTO if NMODE is ON */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2963 | wlc_set_gmode(wlc, GMODE_AUTO, true); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2964 | if (nmode == WL_11N_3x3) |
| 2965 | wlc->pub->_n_enab = SUPPORT_HT; |
| 2966 | else |
| 2967 | wlc->pub->_n_enab = SUPPORT_11N; |
| 2968 | wlc->default_bss->flags |= WLC_BSS_HT; |
| 2969 | /* add the mcs rates to the default and hw ratesets */ |
| 2970 | wlc_rateset_mcs_build(&wlc->default_bss->rateset, |
| 2971 | wlc->stf->txstreams); |
| 2972 | for (i = 0; i < NBANDS(wlc); i++) |
| 2973 | memcpy(wlc->bandstate[i]->hw_rateset.mcs, |
| 2974 | wlc->default_bss->rateset.mcs, MCSSET_LEN); |
| 2975 | break; |
| 2976 | |
| 2977 | default: |
| 2978 | ASSERT(0); |
| 2979 | break; |
| 2980 | } |
| 2981 | |
| 2982 | return err; |
| 2983 | } |
| 2984 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 2985 | static int wlc_set_rateset(wlc_info_t *wlc, wlc_rateset_t *rs_arg) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2986 | { |
| 2987 | wlc_rateset_t rs, new; |
| 2988 | uint bandunit; |
| 2989 | |
| 2990 | bcopy((char *)rs_arg, (char *)&rs, sizeof(wlc_rateset_t)); |
| 2991 | |
| 2992 | /* check for bad count value */ |
| 2993 | if ((rs.count == 0) || (rs.count > WLC_NUMRATES)) |
| 2994 | return BCME_BADRATESET; |
| 2995 | |
| 2996 | /* try the current band */ |
| 2997 | bandunit = wlc->band->bandunit; |
| 2998 | bcopy((char *)&rs, (char *)&new, sizeof(wlc_rateset_t)); |
| 2999 | if (wlc_rate_hwrs_filter_sort_validate |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3000 | (&new, &wlc->bandstate[bandunit]->hw_rateset, true, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3001 | wlc->stf->txstreams)) |
| 3002 | goto good; |
| 3003 | |
| 3004 | /* try the other band */ |
| 3005 | if (IS_MBAND_UNLOCKED(wlc)) { |
| 3006 | bandunit = OTHERBANDUNIT(wlc); |
| 3007 | bcopy((char *)&rs, (char *)&new, sizeof(wlc_rateset_t)); |
| 3008 | if (wlc_rate_hwrs_filter_sort_validate(&new, |
| 3009 | &wlc-> |
| 3010 | bandstate[bandunit]-> |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3011 | hw_rateset, true, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3012 | wlc->stf->txstreams)) |
| 3013 | goto good; |
| 3014 | } |
| 3015 | |
| 3016 | return BCME_ERROR; |
| 3017 | |
| 3018 | good: |
| 3019 | /* apply new rateset */ |
| 3020 | bcopy((char *)&new, (char *)&wlc->default_bss->rateset, |
| 3021 | sizeof(wlc_rateset_t)); |
| 3022 | bcopy((char *)&new, (char *)&wlc->bandstate[bandunit]->defrateset, |
| 3023 | sizeof(wlc_rateset_t)); |
Jason Cooper | 90ea229 | 2010-09-14 09:45:32 -0400 | [diff] [blame] | 3024 | return 0; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3025 | } |
| 3026 | |
| 3027 | /* simplified integer set interface for common ioctl handler */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 3028 | int wlc_set(wlc_info_t *wlc, int cmd, int arg) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3029 | { |
| 3030 | return wlc_ioctl(wlc, cmd, (void *)&arg, sizeof(arg), NULL); |
| 3031 | } |
| 3032 | |
| 3033 | /* simplified integer get interface for common ioctl handler */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 3034 | int wlc_get(wlc_info_t *wlc, int cmd, int *arg) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3035 | { |
| 3036 | return wlc_ioctl(wlc, cmd, arg, sizeof(int), NULL); |
| 3037 | } |
| 3038 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 3039 | static void wlc_ofdm_rateset_war(wlc_info_t *wlc) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3040 | { |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 3041 | u8 r; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3042 | bool war = false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3043 | |
| 3044 | if (wlc->cfg->associated) |
| 3045 | r = wlc->cfg->current_bss->rateset.rates[0]; |
| 3046 | else |
| 3047 | r = wlc->default_bss->rateset.rates[0]; |
| 3048 | |
| 3049 | wlc_phy_ofdm_rateset_war(wlc->band->pi, war); |
| 3050 | |
| 3051 | return; |
| 3052 | } |
| 3053 | |
| 3054 | int |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 3055 | wlc_ioctl(wlc_info_t *wlc, int cmd, void *arg, int len, struct wlc_if *wlcif) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3056 | { |
Jason Cooper | 90ea229 | 2010-09-14 09:45:32 -0400 | [diff] [blame] | 3057 | return _wlc_ioctl(wlc, cmd, arg, len, wlcif); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3058 | } |
| 3059 | |
| 3060 | /* common ioctl handler. return: 0=ok, -1=error, positive=particular error */ |
| 3061 | static int |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 3062 | _wlc_ioctl(wlc_info_t *wlc, int cmd, void *arg, int len, struct wlc_if *wlcif) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3063 | { |
| 3064 | int val, *pval; |
| 3065 | bool bool_val; |
| 3066 | int bcmerror; |
| 3067 | d11regs_t *regs; |
| 3068 | uint i; |
| 3069 | struct scb *nextscb; |
| 3070 | bool ta_ok; |
| 3071 | uint band; |
| 3072 | rw_reg_t *r; |
| 3073 | wlc_bsscfg_t *bsscfg; |
Brett Rudley | e69284f | 2010-11-16 15:45:48 -0800 | [diff] [blame] | 3074 | struct osl_info *osh; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3075 | wlc_bss_info_t *current_bss; |
| 3076 | |
| 3077 | /* update bsscfg pointer */ |
| 3078 | bsscfg = NULL; /* XXX: Hack bsscfg to be size one and use this globally */ |
| 3079 | current_bss = NULL; |
| 3080 | |
| 3081 | /* initialize the following to get rid of compiler warning */ |
| 3082 | nextscb = NULL; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3083 | ta_ok = false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3084 | band = 0; |
| 3085 | r = NULL; |
| 3086 | |
| 3087 | /* If the device is turned off, then it's not "removed" */ |
| 3088 | if (!wlc->pub->hw_off && DEVICEREMOVED(wlc)) { |
| 3089 | WL_ERROR(("wl%d: %s: dead chip\n", wlc->pub->unit, __func__)); |
| 3090 | wl_down(wlc->wl); |
| 3091 | return BCME_ERROR; |
| 3092 | } |
| 3093 | |
| 3094 | ASSERT(!(wlc->pub->hw_off && wlc->pub->up)); |
| 3095 | |
| 3096 | /* default argument is generic integer */ |
Jason Cooper | 2ae3b7e | 2010-09-14 09:45:48 -0400 | [diff] [blame] | 3097 | pval = arg ? (int *)arg:NULL; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3098 | |
| 3099 | /* This will prevent the misaligned access */ |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 3100 | if (pval && (u32) len >= sizeof(val)) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3101 | bcopy(pval, &val, sizeof(val)); |
| 3102 | else |
| 3103 | val = 0; |
| 3104 | |
| 3105 | /* bool conversion to avoid duplication below */ |
| 3106 | bool_val = val != 0; |
| 3107 | |
| 3108 | if (cmd != WLC_SET_CHANNEL) |
| 3109 | WL_NONE(("WLC_IOCTL: cmd %d val 0x%x (%d) len %d\n", cmd, |
| 3110 | (uint) val, val, len)); |
| 3111 | |
| 3112 | bcmerror = 0; |
| 3113 | regs = wlc->regs; |
| 3114 | osh = wlc->osh; |
| 3115 | |
| 3116 | /* A few commands don't need any arguments; all the others do. */ |
| 3117 | switch (cmd) { |
| 3118 | case WLC_UP: |
| 3119 | case WLC_OUT: |
| 3120 | case WLC_DOWN: |
| 3121 | case WLC_DISASSOC: |
| 3122 | case WLC_RESTART: |
| 3123 | case WLC_REBOOT: |
| 3124 | case WLC_START_CHANNEL_QA: |
| 3125 | case WLC_INIT: |
| 3126 | break; |
| 3127 | |
| 3128 | default: |
| 3129 | if ((arg == NULL) || (len <= 0)) { |
| 3130 | WL_ERROR(("wl%d: %s: Command %d needs arguments\n", |
| 3131 | wlc->pub->unit, __func__, cmd)); |
| 3132 | bcmerror = BCME_BADARG; |
| 3133 | goto done; |
| 3134 | } |
| 3135 | } |
| 3136 | |
| 3137 | switch (cmd) { |
| 3138 | |
| 3139 | #if defined(BCMDBG) |
| 3140 | case WLC_GET_MSGLEVEL: |
| 3141 | *pval = wl_msg_level; |
| 3142 | break; |
| 3143 | |
| 3144 | case WLC_SET_MSGLEVEL: |
| 3145 | wl_msg_level = val; |
| 3146 | break; |
| 3147 | #endif |
| 3148 | |
| 3149 | case WLC_GET_INSTANCE: |
| 3150 | *pval = wlc->pub->unit; |
| 3151 | break; |
| 3152 | |
| 3153 | case WLC_GET_CHANNEL:{ |
| 3154 | channel_info_t *ci = (channel_info_t *) arg; |
| 3155 | |
| 3156 | ASSERT(len > (int)sizeof(ci)); |
| 3157 | |
| 3158 | ci->hw_channel = |
| 3159 | CHSPEC_CHANNEL(WLC_BAND_PI_RADIO_CHANSPEC); |
| 3160 | ci->target_channel = |
| 3161 | CHSPEC_CHANNEL(wlc->default_bss->chanspec); |
| 3162 | ci->scan_channel = 0; |
| 3163 | |
| 3164 | break; |
| 3165 | } |
| 3166 | |
| 3167 | case WLC_SET_CHANNEL:{ |
| 3168 | chanspec_t chspec = CH20MHZ_CHSPEC(val); |
| 3169 | |
| 3170 | if (val < 0 || val > MAXCHANNEL) { |
| 3171 | bcmerror = BCME_OUTOFRANGECHAN; |
| 3172 | break; |
| 3173 | } |
| 3174 | |
| 3175 | if (!wlc_valid_chanspec_db(wlc->cmi, chspec)) { |
| 3176 | bcmerror = BCME_BADCHAN; |
| 3177 | break; |
| 3178 | } |
| 3179 | |
| 3180 | if (!wlc->pub->up && IS_MBAND_UNLOCKED(wlc)) { |
| 3181 | if (wlc->band->bandunit != |
| 3182 | CHSPEC_WLCBANDUNIT(chspec)) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3183 | wlc->bandinit_pending = true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3184 | else |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3185 | wlc->bandinit_pending = false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3186 | } |
| 3187 | |
| 3188 | wlc->default_bss->chanspec = chspec; |
| 3189 | /* wlc_BSSinit() will sanitize the rateset before using it.. */ |
| 3190 | if (wlc->pub->up && !wlc->pub->associated && |
| 3191 | (WLC_BAND_PI_RADIO_CHANSPEC != chspec)) { |
| 3192 | wlc_set_home_chanspec(wlc, chspec); |
| 3193 | wlc_suspend_mac_and_wait(wlc); |
| 3194 | wlc_set_chanspec(wlc, chspec); |
| 3195 | wlc_enable_mac(wlc); |
| 3196 | } |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3197 | break; |
| 3198 | } |
| 3199 | |
| 3200 | #if defined(BCMDBG) |
| 3201 | case WLC_GET_UCFLAGS: |
| 3202 | if (!wlc->pub->up) { |
| 3203 | bcmerror = BCME_NOTUP; |
| 3204 | break; |
| 3205 | } |
| 3206 | |
| 3207 | /* optional band is stored in the second integer of incoming buffer */ |
| 3208 | band = |
| 3209 | (len < |
| 3210 | (int)(2 * sizeof(int))) ? WLC_BAND_AUTO : ((int *)arg)[1]; |
| 3211 | |
| 3212 | /* bcmerror checking */ |
Jason Cooper | ca8c1e5 | 2010-09-14 09:45:33 -0400 | [diff] [blame] | 3213 | bcmerror = wlc_iocregchk(wlc, band); |
| 3214 | if (bcmerror) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3215 | break; |
| 3216 | |
| 3217 | if (val >= MHFMAX) { |
| 3218 | bcmerror = BCME_RANGE; |
| 3219 | break; |
| 3220 | } |
| 3221 | |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 3222 | *pval = wlc_bmac_mhf_get(wlc->hw, (u8) val, WLC_BAND_AUTO); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3223 | break; |
| 3224 | |
| 3225 | case WLC_SET_UCFLAGS: |
| 3226 | if (!wlc->pub->up) { |
| 3227 | bcmerror = BCME_NOTUP; |
| 3228 | break; |
| 3229 | } |
| 3230 | |
| 3231 | /* optional band is stored in the second integer of incoming buffer */ |
| 3232 | band = |
| 3233 | (len < |
| 3234 | (int)(2 * sizeof(int))) ? WLC_BAND_AUTO : ((int *)arg)[1]; |
| 3235 | |
| 3236 | /* bcmerror checking */ |
Jason Cooper | ca8c1e5 | 2010-09-14 09:45:33 -0400 | [diff] [blame] | 3237 | bcmerror = wlc_iocregchk(wlc, band); |
| 3238 | if (bcmerror) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3239 | break; |
| 3240 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3241 | i = (u16) val; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3242 | if (i >= MHFMAX) { |
| 3243 | bcmerror = BCME_RANGE; |
| 3244 | break; |
| 3245 | } |
| 3246 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3247 | wlc_mhf(wlc, (u8) i, 0xffff, (u16) (val >> NBITS(u16)), |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3248 | WLC_BAND_AUTO); |
| 3249 | break; |
| 3250 | |
| 3251 | case WLC_GET_SHMEM: |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3252 | ta_ok = true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3253 | |
| 3254 | /* optional band is stored in the second integer of incoming buffer */ |
| 3255 | band = |
| 3256 | (len < |
| 3257 | (int)(2 * sizeof(int))) ? WLC_BAND_AUTO : ((int *)arg)[1]; |
| 3258 | |
| 3259 | /* bcmerror checking */ |
Jason Cooper | ca8c1e5 | 2010-09-14 09:45:33 -0400 | [diff] [blame] | 3260 | bcmerror = wlc_iocregchk(wlc, band); |
| 3261 | if (bcmerror) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3262 | break; |
| 3263 | |
| 3264 | if (val & 1) { |
| 3265 | bcmerror = BCME_BADADDR; |
| 3266 | break; |
| 3267 | } |
| 3268 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3269 | *pval = wlc_read_shm(wlc, (u16) val); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3270 | break; |
| 3271 | |
| 3272 | case WLC_SET_SHMEM: |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3273 | ta_ok = true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3274 | |
| 3275 | /* optional band is stored in the second integer of incoming buffer */ |
| 3276 | band = |
| 3277 | (len < |
| 3278 | (int)(2 * sizeof(int))) ? WLC_BAND_AUTO : ((int *)arg)[1]; |
| 3279 | |
| 3280 | /* bcmerror checking */ |
Jason Cooper | ca8c1e5 | 2010-09-14 09:45:33 -0400 | [diff] [blame] | 3281 | bcmerror = wlc_iocregchk(wlc, band); |
| 3282 | if (bcmerror) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3283 | break; |
| 3284 | |
| 3285 | if (val & 1) { |
| 3286 | bcmerror = BCME_BADADDR; |
| 3287 | break; |
| 3288 | } |
| 3289 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3290 | wlc_write_shm(wlc, (u16) val, |
| 3291 | (u16) (val >> NBITS(u16))); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3292 | break; |
| 3293 | |
| 3294 | case WLC_R_REG: /* MAC registers */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3295 | ta_ok = true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3296 | r = (rw_reg_t *) arg; |
| 3297 | band = WLC_BAND_AUTO; |
| 3298 | |
| 3299 | if (len < (int)(sizeof(rw_reg_t) - sizeof(uint))) { |
| 3300 | bcmerror = BCME_BUFTOOSHORT; |
| 3301 | break; |
| 3302 | } |
| 3303 | |
| 3304 | if (len >= (int)sizeof(rw_reg_t)) |
| 3305 | band = r->band; |
| 3306 | |
| 3307 | /* bcmerror checking */ |
Jason Cooper | ca8c1e5 | 2010-09-14 09:45:33 -0400 | [diff] [blame] | 3308 | bcmerror = wlc_iocregchk(wlc, band); |
| 3309 | if (bcmerror) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3310 | break; |
| 3311 | |
| 3312 | if ((r->byteoff + r->size) > sizeof(d11regs_t)) { |
| 3313 | bcmerror = BCME_BADADDR; |
| 3314 | break; |
| 3315 | } |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 3316 | if (r->size == sizeof(u32)) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3317 | r->val = |
| 3318 | R_REG(osh, |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 3319 | (u32 *)((unsigned char *)(unsigned long)regs + |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3320 | r->byteoff)); |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3321 | else if (r->size == sizeof(u16)) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3322 | r->val = |
| 3323 | R_REG(osh, |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 3324 | (u16 *)((unsigned char *)(unsigned long)regs + |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3325 | r->byteoff)); |
| 3326 | else |
| 3327 | bcmerror = BCME_BADADDR; |
| 3328 | break; |
| 3329 | |
| 3330 | case WLC_W_REG: |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3331 | ta_ok = true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3332 | r = (rw_reg_t *) arg; |
| 3333 | band = WLC_BAND_AUTO; |
| 3334 | |
| 3335 | if (len < (int)(sizeof(rw_reg_t) - sizeof(uint))) { |
| 3336 | bcmerror = BCME_BUFTOOSHORT; |
| 3337 | break; |
| 3338 | } |
| 3339 | |
| 3340 | if (len >= (int)sizeof(rw_reg_t)) |
| 3341 | band = r->band; |
| 3342 | |
| 3343 | /* bcmerror checking */ |
Jason Cooper | ca8c1e5 | 2010-09-14 09:45:33 -0400 | [diff] [blame] | 3344 | bcmerror = wlc_iocregchk(wlc, band); |
| 3345 | if (bcmerror) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3346 | break; |
| 3347 | |
| 3348 | if (r->byteoff + r->size > sizeof(d11regs_t)) { |
| 3349 | bcmerror = BCME_BADADDR; |
| 3350 | break; |
| 3351 | } |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 3352 | if (r->size == sizeof(u32)) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3353 | W_REG(osh, |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 3354 | (u32 *)((unsigned char *)(unsigned long) regs + |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3355 | r->byteoff), r->val); |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3356 | else if (r->size == sizeof(u16)) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3357 | W_REG(osh, |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 3358 | (u16 *)((unsigned char *)(unsigned long) regs + |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3359 | r->byteoff), r->val); |
| 3360 | else |
| 3361 | bcmerror = BCME_BADADDR; |
| 3362 | break; |
| 3363 | #endif /* BCMDBG */ |
| 3364 | |
| 3365 | case WLC_GET_TXANT: |
| 3366 | *pval = wlc->stf->txant; |
| 3367 | break; |
| 3368 | |
| 3369 | case WLC_SET_TXANT: |
Greg Kroah-Hartman | 562c885 | 2010-10-05 11:04:17 -0700 | [diff] [blame] | 3370 | bcmerror = wlc_stf_ant_txant_validate(wlc, (s8) val); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3371 | if (bcmerror < 0) |
| 3372 | break; |
| 3373 | |
Greg Kroah-Hartman | 562c885 | 2010-10-05 11:04:17 -0700 | [diff] [blame] | 3374 | wlc->stf->txant = (s8) val; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3375 | |
| 3376 | /* if down, we are done */ |
| 3377 | if (!wlc->pub->up) |
| 3378 | break; |
| 3379 | |
| 3380 | wlc_suspend_mac_and_wait(wlc); |
| 3381 | |
| 3382 | wlc_stf_phy_txant_upd(wlc); |
| 3383 | wlc_beacon_phytxctl_txant_upd(wlc, wlc->bcn_rspec); |
| 3384 | |
| 3385 | wlc_enable_mac(wlc); |
| 3386 | |
| 3387 | break; |
| 3388 | |
| 3389 | case WLC_GET_ANTDIV:{ |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 3390 | u8 phy_antdiv; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3391 | |
| 3392 | /* return configured value if core is down */ |
| 3393 | if (!wlc->pub->up) { |
| 3394 | *pval = wlc->stf->ant_rx_ovr; |
| 3395 | |
| 3396 | } else { |
| 3397 | if (wlc_phy_ant_rxdiv_get |
| 3398 | (wlc->band->pi, &phy_antdiv)) |
| 3399 | *pval = (int)phy_antdiv; |
| 3400 | else |
| 3401 | *pval = (int)wlc->stf->ant_rx_ovr; |
| 3402 | } |
| 3403 | |
| 3404 | break; |
| 3405 | } |
| 3406 | case WLC_SET_ANTDIV: |
| 3407 | /* values are -1=driver default, 0=force0, 1=force1, 2=start1, 3=start0 */ |
| 3408 | if ((val < -1) || (val > 3)) { |
| 3409 | bcmerror = BCME_RANGE; |
| 3410 | break; |
| 3411 | } |
| 3412 | |
| 3413 | if (val == -1) |
| 3414 | val = ANT_RX_DIV_DEF; |
| 3415 | |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 3416 | wlc->stf->ant_rx_ovr = (u8) val; |
| 3417 | wlc_phy_ant_rxdiv_set(wlc->band->pi, (u8) val); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3418 | break; |
| 3419 | |
| 3420 | case WLC_GET_RX_ANT:{ /* get latest used rx antenna */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3421 | u16 rxstatus; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3422 | |
| 3423 | if (!wlc->pub->up) { |
| 3424 | bcmerror = BCME_NOTUP; |
| 3425 | break; |
| 3426 | } |
| 3427 | |
| 3428 | rxstatus = R_REG(wlc->osh, &wlc->regs->phyrxstatus0); |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3429 | if (rxstatus == 0xdead || rxstatus == (u16) -1) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3430 | bcmerror = BCME_ERROR; |
| 3431 | break; |
| 3432 | } |
| 3433 | *pval = (rxstatus & PRXS0_RXANT_UPSUBBAND) ? 1 : 0; |
| 3434 | break; |
| 3435 | } |
| 3436 | |
| 3437 | #if defined(BCMDBG) |
| 3438 | case WLC_GET_UCANTDIV: |
| 3439 | if (!wlc->clk) { |
| 3440 | bcmerror = BCME_NOCLK; |
| 3441 | break; |
| 3442 | } |
| 3443 | |
| 3444 | *pval = |
| 3445 | (wlc_bmac_mhf_get(wlc->hw, MHF1, WLC_BAND_AUTO) & |
| 3446 | MHF1_ANTDIV); |
| 3447 | break; |
| 3448 | |
| 3449 | case WLC_SET_UCANTDIV:{ |
| 3450 | if (!wlc->pub->up) { |
| 3451 | bcmerror = BCME_NOTUP; |
| 3452 | break; |
| 3453 | } |
| 3454 | |
| 3455 | /* if multiband, band must be locked */ |
| 3456 | if (IS_MBAND_UNLOCKED(wlc)) { |
| 3457 | bcmerror = BCME_NOTBANDLOCKED; |
| 3458 | break; |
| 3459 | } |
| 3460 | |
| 3461 | /* 4322 supports antdiv in phy, no need to set it to ucode */ |
| 3462 | if (WLCISNPHY(wlc->band) |
| 3463 | && D11REV_IS(wlc->pub->corerev, 16)) { |
| 3464 | WL_ERROR(("wl%d: can't set ucantdiv for 4322\n", |
| 3465 | wlc->pub->unit)); |
| 3466 | bcmerror = BCME_UNSUPPORTED; |
| 3467 | } else |
| 3468 | wlc_mhf(wlc, MHF1, MHF1_ANTDIV, |
| 3469 | (val ? MHF1_ANTDIV : 0), WLC_BAND_AUTO); |
| 3470 | break; |
| 3471 | } |
| 3472 | #endif /* defined(BCMDBG) */ |
| 3473 | |
| 3474 | case WLC_GET_SRL: |
| 3475 | *pval = wlc->SRL; |
| 3476 | break; |
| 3477 | |
| 3478 | case WLC_SET_SRL: |
| 3479 | if (val >= 1 && val <= RETRY_SHORT_MAX) { |
| 3480 | int ac; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3481 | wlc->SRL = (u16) val; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3482 | |
| 3483 | wlc_bmac_retrylimit_upd(wlc->hw, wlc->SRL, wlc->LRL); |
| 3484 | |
| 3485 | for (ac = 0; ac < AC_COUNT; ac++) { |
| 3486 | WLC_WME_RETRY_SHORT_SET(wlc, ac, wlc->SRL); |
| 3487 | } |
| 3488 | wlc_wme_retries_write(wlc); |
| 3489 | } else |
| 3490 | bcmerror = BCME_RANGE; |
| 3491 | break; |
| 3492 | |
| 3493 | case WLC_GET_LRL: |
| 3494 | *pval = wlc->LRL; |
| 3495 | break; |
| 3496 | |
| 3497 | case WLC_SET_LRL: |
| 3498 | if (val >= 1 && val <= 255) { |
| 3499 | int ac; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3500 | wlc->LRL = (u16) val; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3501 | |
| 3502 | wlc_bmac_retrylimit_upd(wlc->hw, wlc->SRL, wlc->LRL); |
| 3503 | |
| 3504 | for (ac = 0; ac < AC_COUNT; ac++) { |
| 3505 | WLC_WME_RETRY_LONG_SET(wlc, ac, wlc->LRL); |
| 3506 | } |
| 3507 | wlc_wme_retries_write(wlc); |
| 3508 | } else |
| 3509 | bcmerror = BCME_RANGE; |
| 3510 | break; |
| 3511 | |
| 3512 | case WLC_GET_CWMIN: |
| 3513 | *pval = wlc->band->CWmin; |
| 3514 | break; |
| 3515 | |
| 3516 | case WLC_SET_CWMIN: |
| 3517 | if (!wlc->clk) { |
| 3518 | bcmerror = BCME_NOCLK; |
| 3519 | break; |
| 3520 | } |
| 3521 | |
| 3522 | if (val >= 1 && val <= 255) { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3523 | wlc_set_cwmin(wlc, (u16) val); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3524 | } else |
| 3525 | bcmerror = BCME_RANGE; |
| 3526 | break; |
| 3527 | |
| 3528 | case WLC_GET_CWMAX: |
| 3529 | *pval = wlc->band->CWmax; |
| 3530 | break; |
| 3531 | |
| 3532 | case WLC_SET_CWMAX: |
| 3533 | if (!wlc->clk) { |
| 3534 | bcmerror = BCME_NOCLK; |
| 3535 | break; |
| 3536 | } |
| 3537 | |
| 3538 | if (val >= 255 && val <= 2047) { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3539 | wlc_set_cwmax(wlc, (u16) val); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3540 | } else |
| 3541 | bcmerror = BCME_RANGE; |
| 3542 | break; |
| 3543 | |
| 3544 | case WLC_GET_RADIO: /* use mask if don't want to expose some internal bits */ |
| 3545 | *pval = wlc->pub->radio_disabled; |
| 3546 | break; |
| 3547 | |
| 3548 | case WLC_SET_RADIO:{ /* 32 bits input, higher 16 bits are mask, lower 16 bits are value to |
| 3549 | * set |
| 3550 | */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3551 | u16 radiomask, radioval; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3552 | uint validbits = |
| 3553 | WL_RADIO_SW_DISABLE | WL_RADIO_HW_DISABLE; |
| 3554 | mbool new = 0; |
| 3555 | |
| 3556 | radiomask = (val & 0xffff0000) >> 16; |
| 3557 | radioval = val & 0x0000ffff; |
| 3558 | |
| 3559 | if ((radiomask == 0) || (radiomask & ~validbits) |
| 3560 | || (radioval & ~validbits) |
| 3561 | || ((radioval & ~radiomask) != 0)) { |
| 3562 | WL_ERROR(("SET_RADIO with wrong bits 0x%x\n", |
| 3563 | val)); |
| 3564 | bcmerror = BCME_RANGE; |
| 3565 | break; |
| 3566 | } |
| 3567 | |
| 3568 | new = |
| 3569 | (wlc->pub->radio_disabled & ~radiomask) | radioval; |
| 3570 | wlc->pub->radio_disabled = new; |
| 3571 | |
| 3572 | wlc_radio_hwdisable_upd(wlc); |
| 3573 | wlc_radio_upd(wlc); |
| 3574 | break; |
| 3575 | } |
| 3576 | |
| 3577 | case WLC_GET_PHYTYPE: |
| 3578 | *pval = WLC_PHYTYPE(wlc->band->phytype); |
| 3579 | break; |
| 3580 | |
| 3581 | #if defined(BCMDBG) |
| 3582 | case WLC_GET_KEY: |
| 3583 | if ((val >= 0) && (val < WLC_MAX_WSEC_KEYS(wlc))) { |
| 3584 | wl_wsec_key_t key; |
| 3585 | |
| 3586 | wsec_key_t *src_key = wlc->wsec_keys[val]; |
| 3587 | |
| 3588 | if (len < (int)sizeof(key)) { |
| 3589 | bcmerror = BCME_BUFTOOSHORT; |
| 3590 | break; |
| 3591 | } |
| 3592 | |
Brett Rudley | 9249ede | 2010-11-30 20:09:49 -0800 | [diff] [blame^] | 3593 | memset((char *)&key, 0, sizeof(key)); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3594 | if (src_key) { |
| 3595 | key.index = src_key->id; |
| 3596 | key.len = src_key->len; |
| 3597 | bcopy(src_key->data, key.data, key.len); |
| 3598 | key.algo = src_key->algo; |
| 3599 | if (WSEC_SOFTKEY(wlc, src_key, bsscfg)) |
| 3600 | key.flags |= WL_SOFT_KEY; |
| 3601 | if (src_key->flags & WSEC_PRIMARY_KEY) |
| 3602 | key.flags |= WL_PRIMARY_KEY; |
| 3603 | |
| 3604 | bcopy(src_key->ea.octet, key.ea.octet, |
| 3605 | ETHER_ADDR_LEN); |
| 3606 | } |
| 3607 | |
| 3608 | bcopy((char *)&key, arg, sizeof(key)); |
| 3609 | } else |
| 3610 | bcmerror = BCME_BADKEYIDX; |
| 3611 | break; |
| 3612 | #endif /* defined(BCMDBG) */ |
| 3613 | |
| 3614 | case WLC_SET_KEY: |
| 3615 | bcmerror = |
| 3616 | wlc_iovar_op(wlc, "wsec_key", NULL, 0, arg, len, IOV_SET, |
| 3617 | wlcif); |
| 3618 | break; |
| 3619 | |
| 3620 | case WLC_GET_KEY_SEQ:{ |
| 3621 | wsec_key_t *key; |
| 3622 | |
| 3623 | if (len < DOT11_WPA_KEY_RSC_LEN) { |
| 3624 | bcmerror = BCME_BUFTOOSHORT; |
| 3625 | break; |
| 3626 | } |
| 3627 | |
| 3628 | /* Return the key's tx iv as an EAPOL sequence counter. |
| 3629 | * This will be used to supply the RSC value to a supplicant. |
| 3630 | * The format is 8 bytes, with least significant in seq[0]. |
| 3631 | */ |
| 3632 | |
Jason Cooper | ca8c1e5 | 2010-09-14 09:45:33 -0400 | [diff] [blame] | 3633 | key = WSEC_KEY(wlc, val); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3634 | if ((val >= 0) && (val < WLC_MAX_WSEC_KEYS(wlc)) && |
Jason Cooper | ca8c1e5 | 2010-09-14 09:45:33 -0400 | [diff] [blame] | 3635 | (key != NULL)) { |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 3636 | u8 seq[DOT11_WPA_KEY_RSC_LEN]; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3637 | u16 lo; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 3638 | u32 hi; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3639 | /* group keys in WPA-NONE (IBSS only, AES and TKIP) use a global TXIV */ |
| 3640 | if ((bsscfg->WPA_auth & WPA_AUTH_NONE) |
| 3641 | && ETHER_ISNULLADDR(&key->ea)) { |
| 3642 | lo = bsscfg->wpa_none_txiv.lo; |
| 3643 | hi = bsscfg->wpa_none_txiv.hi; |
| 3644 | } else { |
| 3645 | lo = key->txiv.lo; |
| 3646 | hi = key->txiv.hi; |
| 3647 | } |
| 3648 | |
| 3649 | /* format the buffer, low to high */ |
| 3650 | seq[0] = lo & 0xff; |
| 3651 | seq[1] = (lo >> 8) & 0xff; |
| 3652 | seq[2] = hi & 0xff; |
| 3653 | seq[3] = (hi >> 8) & 0xff; |
| 3654 | seq[4] = (hi >> 16) & 0xff; |
| 3655 | seq[5] = (hi >> 24) & 0xff; |
| 3656 | seq[6] = 0; |
| 3657 | seq[7] = 0; |
| 3658 | |
| 3659 | bcopy((char *)seq, arg, sizeof(seq)); |
| 3660 | } else { |
| 3661 | bcmerror = BCME_BADKEYIDX; |
| 3662 | } |
| 3663 | break; |
| 3664 | } |
| 3665 | |
| 3666 | case WLC_GET_CURR_RATESET:{ |
| 3667 | wl_rateset_t *ret_rs = (wl_rateset_t *) arg; |
| 3668 | wlc_rateset_t *rs; |
| 3669 | |
| 3670 | if (bsscfg->associated) |
| 3671 | rs = ¤t_bss->rateset; |
| 3672 | else |
| 3673 | rs = &wlc->default_bss->rateset; |
| 3674 | |
| 3675 | if (len < (int)(rs->count + sizeof(rs->count))) { |
| 3676 | bcmerror = BCME_BUFTOOSHORT; |
| 3677 | break; |
| 3678 | } |
| 3679 | |
| 3680 | /* Copy only legacy rateset section */ |
| 3681 | ret_rs->count = rs->count; |
| 3682 | bcopy(&rs->rates, &ret_rs->rates, rs->count); |
| 3683 | break; |
| 3684 | } |
| 3685 | |
| 3686 | case WLC_GET_RATESET:{ |
| 3687 | wlc_rateset_t rs; |
| 3688 | wl_rateset_t *ret_rs = (wl_rateset_t *) arg; |
| 3689 | |
Brett Rudley | 9249ede | 2010-11-30 20:09:49 -0800 | [diff] [blame^] | 3690 | memset(&rs, 0, sizeof(wlc_rateset_t)); |
Jason Cooper | 29c4275 | 2010-09-14 09:45:43 -0400 | [diff] [blame] | 3691 | wlc_default_rateset(wlc, (wlc_rateset_t *) &rs); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3692 | |
| 3693 | if (len < (int)(rs.count + sizeof(rs.count))) { |
| 3694 | bcmerror = BCME_BUFTOOSHORT; |
| 3695 | break; |
| 3696 | } |
| 3697 | |
| 3698 | /* Copy only legacy rateset section */ |
| 3699 | ret_rs->count = rs.count; |
| 3700 | bcopy(&rs.rates, &ret_rs->rates, rs.count); |
| 3701 | break; |
| 3702 | } |
| 3703 | |
| 3704 | case WLC_SET_RATESET:{ |
| 3705 | wlc_rateset_t rs; |
| 3706 | wl_rateset_t *in_rs = (wl_rateset_t *) arg; |
| 3707 | |
| 3708 | if (len < (int)(in_rs->count + sizeof(in_rs->count))) { |
| 3709 | bcmerror = BCME_BUFTOOSHORT; |
| 3710 | break; |
| 3711 | } |
| 3712 | |
| 3713 | if (in_rs->count > WLC_NUMRATES) { |
| 3714 | bcmerror = BCME_BUFTOOLONG; |
| 3715 | break; |
| 3716 | } |
| 3717 | |
Brett Rudley | 9249ede | 2010-11-30 20:09:49 -0800 | [diff] [blame^] | 3718 | memset(&rs, 0, sizeof(wlc_rateset_t)); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3719 | |
| 3720 | /* Copy only legacy rateset section */ |
| 3721 | rs.count = in_rs->count; |
| 3722 | bcopy(&in_rs->rates, &rs.rates, rs.count); |
| 3723 | |
| 3724 | /* merge rateset coming in with the current mcsset */ |
| 3725 | if (N_ENAB(wlc->pub)) { |
| 3726 | if (bsscfg->associated) |
| 3727 | bcopy(¤t_bss->rateset.mcs[0], |
| 3728 | rs.mcs, MCSSET_LEN); |
| 3729 | else |
| 3730 | bcopy(&wlc->default_bss->rateset.mcs[0], |
| 3731 | rs.mcs, MCSSET_LEN); |
| 3732 | } |
| 3733 | |
| 3734 | bcmerror = wlc_set_rateset(wlc, &rs); |
| 3735 | |
| 3736 | if (!bcmerror) |
| 3737 | wlc_ofdm_rateset_war(wlc); |
| 3738 | |
| 3739 | break; |
| 3740 | } |
| 3741 | |
| 3742 | case WLC_GET_BCNPRD: |
| 3743 | if (BSSCFG_STA(bsscfg) && bsscfg->BSS && bsscfg->associated) |
| 3744 | *pval = current_bss->beacon_period; |
| 3745 | else |
| 3746 | *pval = wlc->default_bss->beacon_period; |
| 3747 | break; |
| 3748 | |
| 3749 | case WLC_SET_BCNPRD: |
| 3750 | /* range [1, 0xffff] */ |
| 3751 | if (val >= DOT11_MIN_BEACON_PERIOD |
| 3752 | && val <= DOT11_MAX_BEACON_PERIOD) { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3753 | wlc->default_bss->beacon_period = (u16) val; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3754 | } else |
| 3755 | bcmerror = BCME_RANGE; |
| 3756 | break; |
| 3757 | |
| 3758 | case WLC_GET_DTIMPRD: |
| 3759 | if (BSSCFG_STA(bsscfg) && bsscfg->BSS && bsscfg->associated) |
| 3760 | *pval = current_bss->dtim_period; |
| 3761 | else |
| 3762 | *pval = wlc->default_bss->dtim_period; |
| 3763 | break; |
| 3764 | |
| 3765 | case WLC_SET_DTIMPRD: |
| 3766 | /* range [1, 0xff] */ |
| 3767 | if (val >= DOT11_MIN_DTIM_PERIOD |
| 3768 | && val <= DOT11_MAX_DTIM_PERIOD) { |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 3769 | wlc->default_bss->dtim_period = (u8) val; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3770 | } else |
| 3771 | bcmerror = BCME_RANGE; |
| 3772 | break; |
| 3773 | |
| 3774 | #ifdef SUPPORT_PS |
| 3775 | case WLC_GET_PM: |
| 3776 | *pval = wlc->PM; |
| 3777 | break; |
| 3778 | |
| 3779 | case WLC_SET_PM: |
| 3780 | if ((val >= PM_OFF) && (val <= PM_MAX)) { |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 3781 | wlc->PM = (u8) val; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3782 | if (wlc->pub->up) { |
| 3783 | } |
| 3784 | /* Change watchdog driver to align watchdog with tbtt if possible */ |
| 3785 | wlc_watchdog_upd(wlc, PS_ALLOWED(wlc)); |
| 3786 | } else |
| 3787 | bcmerror = BCME_ERROR; |
| 3788 | break; |
| 3789 | #endif /* SUPPORT_PS */ |
| 3790 | |
| 3791 | #ifdef SUPPORT_PS |
| 3792 | #ifdef BCMDBG |
| 3793 | case WLC_GET_WAKE: |
| 3794 | if (AP_ENAB(wlc->pub)) { |
| 3795 | bcmerror = BCME_NOTSTA; |
| 3796 | break; |
| 3797 | } |
| 3798 | *pval = wlc->wake; |
| 3799 | break; |
| 3800 | |
| 3801 | case WLC_SET_WAKE: |
| 3802 | if (AP_ENAB(wlc->pub)) { |
| 3803 | bcmerror = BCME_NOTSTA; |
| 3804 | break; |
| 3805 | } |
| 3806 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3807 | wlc->wake = val ? true : false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3808 | |
| 3809 | /* if down, we're done */ |
| 3810 | if (!wlc->pub->up) |
| 3811 | break; |
| 3812 | |
| 3813 | /* apply to the mac */ |
| 3814 | wlc_set_ps_ctrl(wlc); |
| 3815 | break; |
| 3816 | #endif /* BCMDBG */ |
| 3817 | #endif /* SUPPORT_PS */ |
| 3818 | |
| 3819 | case WLC_GET_REVINFO: |
| 3820 | bcmerror = wlc_get_revision_info(wlc, arg, (uint) len); |
| 3821 | break; |
| 3822 | |
| 3823 | case WLC_GET_AP: |
| 3824 | *pval = (int)AP_ENAB(wlc->pub); |
| 3825 | break; |
| 3826 | |
| 3827 | case WLC_GET_ATIM: |
| 3828 | if (bsscfg->associated) |
| 3829 | *pval = (int)current_bss->atim_window; |
| 3830 | else |
| 3831 | *pval = (int)wlc->default_bss->atim_window; |
| 3832 | break; |
| 3833 | |
| 3834 | case WLC_SET_ATIM: |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 3835 | wlc->default_bss->atim_window = (u32) val; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3836 | break; |
| 3837 | |
| 3838 | case WLC_GET_PKTCNTS:{ |
| 3839 | get_pktcnt_t *pktcnt = (get_pktcnt_t *) pval; |
| 3840 | if (WLC_UPDATE_STATS(wlc)) |
| 3841 | wlc_statsupd(wlc); |
| 3842 | pktcnt->rx_good_pkt = WLCNTVAL(wlc->pub->_cnt->rxframe); |
| 3843 | pktcnt->rx_bad_pkt = WLCNTVAL(wlc->pub->_cnt->rxerror); |
| 3844 | pktcnt->tx_good_pkt = |
| 3845 | WLCNTVAL(wlc->pub->_cnt->txfrmsnt); |
| 3846 | pktcnt->tx_bad_pkt = |
| 3847 | WLCNTVAL(wlc->pub->_cnt->txerror) + |
| 3848 | WLCNTVAL(wlc->pub->_cnt->txfail); |
| 3849 | if (len >= (int)sizeof(get_pktcnt_t)) { |
| 3850 | /* Be backward compatible - only if buffer is large enough */ |
| 3851 | pktcnt->rx_ocast_good_pkt = |
| 3852 | WLCNTVAL(wlc->pub->_cnt->rxmfrmocast); |
| 3853 | } |
| 3854 | break; |
| 3855 | } |
| 3856 | |
| 3857 | #ifdef SUPPORT_HWKEY |
| 3858 | case WLC_GET_WSEC: |
| 3859 | bcmerror = |
| 3860 | wlc_iovar_op(wlc, "wsec", NULL, 0, arg, len, IOV_GET, |
| 3861 | wlcif); |
| 3862 | break; |
| 3863 | |
| 3864 | case WLC_SET_WSEC: |
| 3865 | bcmerror = |
| 3866 | wlc_iovar_op(wlc, "wsec", NULL, 0, arg, len, IOV_SET, |
| 3867 | wlcif); |
| 3868 | break; |
| 3869 | |
| 3870 | case WLC_GET_WPA_AUTH: |
| 3871 | *pval = (int)bsscfg->WPA_auth; |
| 3872 | break; |
| 3873 | |
| 3874 | case WLC_SET_WPA_AUTH: |
| 3875 | /* change of WPA_Auth modifies the PS_ALLOWED state */ |
| 3876 | if (BSSCFG_STA(bsscfg)) { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3877 | bsscfg->WPA_auth = (u16) val; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3878 | } else |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3879 | bsscfg->WPA_auth = (u16) val; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3880 | break; |
| 3881 | #endif /* SUPPORT_HWKEY */ |
| 3882 | |
| 3883 | case WLC_GET_BANDLIST: |
| 3884 | /* count of number of bands, followed by each band type */ |
| 3885 | *pval++ = NBANDS(wlc); |
| 3886 | *pval++ = wlc->band->bandtype; |
| 3887 | if (NBANDS(wlc) > 1) |
| 3888 | *pval++ = wlc->bandstate[OTHERBANDUNIT(wlc)]->bandtype; |
| 3889 | break; |
| 3890 | |
| 3891 | case WLC_GET_BAND: |
| 3892 | *pval = wlc->bandlocked ? wlc->band->bandtype : WLC_BAND_AUTO; |
| 3893 | break; |
| 3894 | |
| 3895 | case WLC_GET_PHYLIST: |
| 3896 | { |
Greg Kroah-Hartman | 580a0bd | 2010-10-05 11:09:48 -0700 | [diff] [blame] | 3897 | unsigned char *cp = arg; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3898 | if (len < 3) { |
| 3899 | bcmerror = BCME_BUFTOOSHORT; |
| 3900 | break; |
| 3901 | } |
| 3902 | |
| 3903 | if (WLCISNPHY(wlc->band)) { |
| 3904 | *cp++ = 'n'; |
| 3905 | } else if (WLCISLCNPHY(wlc->band)) { |
| 3906 | *cp++ = 'c'; |
| 3907 | } else if (WLCISSSLPNPHY(wlc->band)) { |
| 3908 | *cp++ = 's'; |
| 3909 | } |
| 3910 | *cp = '\0'; |
| 3911 | break; |
| 3912 | } |
| 3913 | |
| 3914 | case WLC_GET_SHORTSLOT: |
| 3915 | *pval = wlc->shortslot; |
| 3916 | break; |
| 3917 | |
| 3918 | case WLC_GET_SHORTSLOT_OVERRIDE: |
| 3919 | *pval = wlc->shortslot_override; |
| 3920 | break; |
| 3921 | |
| 3922 | case WLC_SET_SHORTSLOT_OVERRIDE: |
| 3923 | if ((val != WLC_SHORTSLOT_AUTO) && |
| 3924 | (val != WLC_SHORTSLOT_OFF) && (val != WLC_SHORTSLOT_ON)) { |
| 3925 | bcmerror = BCME_RANGE; |
| 3926 | break; |
| 3927 | } |
| 3928 | |
Greg Kroah-Hartman | 562c885 | 2010-10-05 11:04:17 -0700 | [diff] [blame] | 3929 | wlc->shortslot_override = (s8) val; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3930 | |
| 3931 | /* shortslot is an 11g feature, so no more work if we are |
| 3932 | * currently on the 5G band |
| 3933 | */ |
| 3934 | if (BAND_5G(wlc->band->bandtype)) |
| 3935 | break; |
| 3936 | |
| 3937 | if (wlc->pub->up && wlc->pub->associated) { |
| 3938 | /* let watchdog or beacon processing update shortslot */ |
| 3939 | } else if (wlc->pub->up) { |
| 3940 | /* unassociated shortslot is off */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3941 | wlc_switch_shortslot(wlc, false); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3942 | } else { |
| 3943 | /* driver is down, so just update the wlc_info value */ |
| 3944 | if (wlc->shortslot_override == WLC_SHORTSLOT_AUTO) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3945 | wlc->shortslot = false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3946 | } else { |
| 3947 | wlc->shortslot = |
| 3948 | (wlc->shortslot_override == |
| 3949 | WLC_SHORTSLOT_ON); |
| 3950 | } |
| 3951 | } |
| 3952 | |
| 3953 | break; |
| 3954 | |
| 3955 | case WLC_GET_LEGACY_ERP: |
| 3956 | *pval = wlc->include_legacy_erp; |
| 3957 | break; |
| 3958 | |
| 3959 | case WLC_SET_LEGACY_ERP: |
| 3960 | if (wlc->include_legacy_erp == bool_val) |
| 3961 | break; |
| 3962 | |
| 3963 | wlc->include_legacy_erp = bool_val; |
| 3964 | |
| 3965 | if (AP_ENAB(wlc->pub) && wlc->clk) { |
| 3966 | wlc_update_beacon(wlc); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3967 | wlc_update_probe_resp(wlc, true); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3968 | } |
| 3969 | break; |
| 3970 | |
| 3971 | case WLC_GET_GMODE: |
| 3972 | if (wlc->band->bandtype == WLC_BAND_2G) |
| 3973 | *pval = wlc->band->gmode; |
| 3974 | else if (NBANDS(wlc) > 1) |
| 3975 | *pval = wlc->bandstate[OTHERBANDUNIT(wlc)]->gmode; |
| 3976 | break; |
| 3977 | |
| 3978 | case WLC_SET_GMODE: |
| 3979 | if (!wlc->pub->associated) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3980 | bcmerror = wlc_set_gmode(wlc, (u8) val, true); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 3981 | else { |
| 3982 | bcmerror = BCME_ASSOCIATED; |
| 3983 | break; |
| 3984 | } |
| 3985 | break; |
| 3986 | |
| 3987 | case WLC_GET_GMODE_PROTECTION: |
| 3988 | *pval = wlc->protection->_g; |
| 3989 | break; |
| 3990 | |
| 3991 | case WLC_GET_PROTECTION_CONTROL: |
| 3992 | *pval = wlc->protection->overlap; |
| 3993 | break; |
| 3994 | |
| 3995 | case WLC_SET_PROTECTION_CONTROL: |
| 3996 | if ((val != WLC_PROTECTION_CTL_OFF) && |
| 3997 | (val != WLC_PROTECTION_CTL_LOCAL) && |
| 3998 | (val != WLC_PROTECTION_CTL_OVERLAP)) { |
| 3999 | bcmerror = BCME_RANGE; |
| 4000 | break; |
| 4001 | } |
| 4002 | |
Greg Kroah-Hartman | 562c885 | 2010-10-05 11:04:17 -0700 | [diff] [blame] | 4003 | wlc_protection_upd(wlc, WLC_PROT_OVERLAP, (s8) val); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4004 | |
| 4005 | /* Current g_protection will sync up to the specified control alg in watchdog |
| 4006 | * if the driver is up and associated. |
| 4007 | * If the driver is down or not associated, the control setting has no effect. |
| 4008 | */ |
| 4009 | break; |
| 4010 | |
| 4011 | case WLC_GET_GMODE_PROTECTION_OVERRIDE: |
| 4012 | *pval = wlc->protection->g_override; |
| 4013 | break; |
| 4014 | |
| 4015 | case WLC_SET_GMODE_PROTECTION_OVERRIDE: |
| 4016 | if ((val != WLC_PROTECTION_AUTO) && |
| 4017 | (val != WLC_PROTECTION_OFF) && (val != WLC_PROTECTION_ON)) { |
| 4018 | bcmerror = BCME_RANGE; |
| 4019 | break; |
| 4020 | } |
| 4021 | |
Greg Kroah-Hartman | 562c885 | 2010-10-05 11:04:17 -0700 | [diff] [blame] | 4022 | wlc_protection_upd(wlc, WLC_PROT_G_OVR, (s8) val); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4023 | |
| 4024 | break; |
| 4025 | |
| 4026 | case WLC_SET_SUP_RATESET_OVERRIDE:{ |
| 4027 | wlc_rateset_t rs, new; |
| 4028 | |
| 4029 | /* copyin */ |
| 4030 | if (len < (int)sizeof(wlc_rateset_t)) { |
| 4031 | bcmerror = BCME_BUFTOOSHORT; |
| 4032 | break; |
| 4033 | } |
| 4034 | bcopy((char *)arg, (char *)&rs, sizeof(wlc_rateset_t)); |
| 4035 | |
| 4036 | /* check for bad count value */ |
| 4037 | if (rs.count > WLC_NUMRATES) { |
| 4038 | bcmerror = BCME_BADRATESET; /* invalid rateset */ |
| 4039 | break; |
| 4040 | } |
| 4041 | |
| 4042 | /* this command is only appropriate for gmode operation */ |
| 4043 | if (!(wlc->band->gmode || |
| 4044 | ((NBANDS(wlc) > 1) |
| 4045 | && wlc->bandstate[OTHERBANDUNIT(wlc)]->gmode))) { |
| 4046 | bcmerror = BCME_BADBAND; /* gmode only command when not in gmode */ |
| 4047 | break; |
| 4048 | } |
| 4049 | |
| 4050 | /* check for an empty rateset to clear the override */ |
| 4051 | if (rs.count == 0) { |
Brett Rudley | 9249ede | 2010-11-30 20:09:49 -0800 | [diff] [blame^] | 4052 | memset(&wlc->sup_rates_override, 0, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4053 | sizeof(wlc_rateset_t)); |
| 4054 | break; |
| 4055 | } |
| 4056 | |
| 4057 | /* validate rateset by comparing pre and post sorted against 11g hw rates */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4058 | wlc_rateset_filter(&rs, &new, false, WLC_RATES_CCK_OFDM, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4059 | RATE_MASK, BSS_N_ENAB(wlc, bsscfg)); |
| 4060 | wlc_rate_hwrs_filter_sort_validate(&new, |
| 4061 | &cck_ofdm_rates, |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4062 | false, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4063 | wlc->stf->txstreams); |
| 4064 | if (rs.count != new.count) { |
| 4065 | bcmerror = BCME_BADRATESET; /* invalid rateset */ |
| 4066 | break; |
| 4067 | } |
| 4068 | |
| 4069 | /* apply new rateset to the override */ |
| 4070 | bcopy((char *)&new, (char *)&wlc->sup_rates_override, |
| 4071 | sizeof(wlc_rateset_t)); |
| 4072 | |
| 4073 | /* update bcn and probe resp if needed */ |
| 4074 | if (wlc->pub->up && AP_ENAB(wlc->pub) |
| 4075 | && wlc->pub->associated) { |
| 4076 | wlc_update_beacon(wlc); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4077 | wlc_update_probe_resp(wlc, true); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4078 | } |
| 4079 | break; |
| 4080 | } |
| 4081 | |
| 4082 | case WLC_GET_SUP_RATESET_OVERRIDE: |
| 4083 | /* this command is only appropriate for gmode operation */ |
| 4084 | if (!(wlc->band->gmode || |
| 4085 | ((NBANDS(wlc) > 1) |
| 4086 | && wlc->bandstate[OTHERBANDUNIT(wlc)]->gmode))) { |
| 4087 | bcmerror = BCME_BADBAND; /* gmode only command when not in gmode */ |
| 4088 | break; |
| 4089 | } |
| 4090 | if (len < (int)sizeof(wlc_rateset_t)) { |
| 4091 | bcmerror = BCME_BUFTOOSHORT; |
| 4092 | break; |
| 4093 | } |
| 4094 | bcopy((char *)&wlc->sup_rates_override, (char *)arg, |
| 4095 | sizeof(wlc_rateset_t)); |
| 4096 | |
| 4097 | break; |
| 4098 | |
| 4099 | case WLC_GET_PRB_RESP_TIMEOUT: |
| 4100 | *pval = wlc->prb_resp_timeout; |
| 4101 | break; |
| 4102 | |
| 4103 | case WLC_SET_PRB_RESP_TIMEOUT: |
| 4104 | if (wlc->pub->up) { |
| 4105 | bcmerror = BCME_NOTDOWN; |
| 4106 | break; |
| 4107 | } |
| 4108 | if (val < 0 || val >= 0xFFFF) { |
| 4109 | bcmerror = BCME_RANGE; /* bad value */ |
| 4110 | break; |
| 4111 | } |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 4112 | wlc->prb_resp_timeout = (u16) val; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4113 | break; |
| 4114 | |
| 4115 | case WLC_GET_KEY_PRIMARY:{ |
| 4116 | wsec_key_t *key; |
| 4117 | |
| 4118 | /* treat the 'val' parm as the key id */ |
Jason Cooper | ca8c1e5 | 2010-09-14 09:45:33 -0400 | [diff] [blame] | 4119 | key = WSEC_BSS_DEFAULT_KEY(bsscfg); |
| 4120 | if (key != NULL) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4121 | *pval = key->id == val ? true : false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4122 | } else { |
| 4123 | bcmerror = BCME_BADKEYIDX; |
| 4124 | } |
| 4125 | break; |
| 4126 | } |
| 4127 | |
| 4128 | case WLC_SET_KEY_PRIMARY:{ |
| 4129 | wsec_key_t *key, *old_key; |
| 4130 | |
| 4131 | bcmerror = BCME_BADKEYIDX; |
| 4132 | |
| 4133 | /* treat the 'val' parm as the key id */ |
| 4134 | for (i = 0; i < WSEC_MAX_DEFAULT_KEYS; i++) { |
Jason Cooper | ca8c1e5 | 2010-09-14 09:45:33 -0400 | [diff] [blame] | 4135 | key = bsscfg->bss_def_keys[i]; |
| 4136 | if (key != NULL && key->id == val) { |
| 4137 | old_key = WSEC_BSS_DEFAULT_KEY(bsscfg); |
| 4138 | if (old_key != NULL) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4139 | old_key->flags &= |
| 4140 | ~WSEC_PRIMARY_KEY; |
| 4141 | key->flags |= WSEC_PRIMARY_KEY; |
| 4142 | bsscfg->wsec_index = i; |
| 4143 | bcmerror = BCME_OK; |
| 4144 | } |
| 4145 | } |
| 4146 | break; |
| 4147 | } |
| 4148 | |
| 4149 | #ifdef BCMDBG |
| 4150 | case WLC_INIT: |
| 4151 | wl_init(wlc->wl); |
| 4152 | break; |
| 4153 | #endif |
| 4154 | |
| 4155 | case WLC_SET_VAR: |
| 4156 | case WLC_GET_VAR:{ |
| 4157 | char *name; |
| 4158 | /* validate the name value */ |
| 4159 | name = (char *)arg; |
| 4160 | for (i = 0; i < (uint) len && *name != '\0'; |
Jason Cooper | 6214582 | 2010-09-14 09:45:34 -0400 | [diff] [blame] | 4161 | i++, name++) |
| 4162 | ; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4163 | |
| 4164 | if (i == (uint) len) { |
| 4165 | bcmerror = BCME_BUFTOOSHORT; |
| 4166 | break; |
| 4167 | } |
| 4168 | i++; /* include the null in the string length */ |
| 4169 | |
| 4170 | if (cmd == WLC_GET_VAR) { |
| 4171 | bcmerror = |
| 4172 | wlc_iovar_op(wlc, arg, |
Greg Kroah-Hartman | 562c885 | 2010-10-05 11:04:17 -0700 | [diff] [blame] | 4173 | (void *)((s8 *) arg + i), |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4174 | len - i, arg, len, IOV_GET, |
| 4175 | wlcif); |
| 4176 | } else |
| 4177 | bcmerror = |
| 4178 | wlc_iovar_op(wlc, arg, NULL, 0, |
Greg Kroah-Hartman | 562c885 | 2010-10-05 11:04:17 -0700 | [diff] [blame] | 4179 | (void *)((s8 *) arg + i), |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4180 | len - i, IOV_SET, wlcif); |
| 4181 | |
| 4182 | break; |
| 4183 | } |
| 4184 | |
| 4185 | case WLC_SET_WSEC_PMK: |
| 4186 | bcmerror = BCME_UNSUPPORTED; |
| 4187 | break; |
| 4188 | |
| 4189 | #if defined(BCMDBG) |
| 4190 | case WLC_CURRENT_PWR: |
| 4191 | if (!wlc->pub->up) |
| 4192 | bcmerror = BCME_NOTUP; |
| 4193 | else |
| 4194 | bcmerror = wlc_get_current_txpwr(wlc, arg, len); |
| 4195 | break; |
| 4196 | #endif |
| 4197 | |
| 4198 | case WLC_LAST: |
| 4199 | WL_ERROR(("%s: WLC_LAST\n", __func__)); |
| 4200 | } |
| 4201 | done: |
| 4202 | |
| 4203 | if (bcmerror) { |
| 4204 | if (VALID_BCMERROR(bcmerror)) |
| 4205 | wlc->pub->bcmerror = bcmerror; |
| 4206 | else { |
| 4207 | bcmerror = 0; |
| 4208 | } |
| 4209 | |
| 4210 | } |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4211 | /* BMAC_NOTE: for HIGH_ONLY driver, this seems being called after RPC bus failed */ |
| 4212 | /* In hw_off condition, IOCTLs that reach here are deemed safe but taclear would |
| 4213 | * certainly result in getting -1 for register reads. So skip ta_clear altogether |
| 4214 | */ |
| 4215 | if (!(wlc->pub->hw_off)) |
| 4216 | ASSERT(wlc_bmac_taclear(wlc->hw, ta_ok) || !ta_ok); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4217 | |
Jason Cooper | 90ea229 | 2010-09-14 09:45:32 -0400 | [diff] [blame] | 4218 | return bcmerror; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4219 | } |
| 4220 | |
| 4221 | #if defined(BCMDBG) |
| 4222 | /* consolidated register access ioctl error checking */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 4223 | int wlc_iocregchk(wlc_info_t *wlc, uint band) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4224 | { |
| 4225 | /* if band is specified, it must be the current band */ |
| 4226 | if ((band != WLC_BAND_AUTO) && (band != (uint) wlc->band->bandtype)) |
Jason Cooper | 90ea229 | 2010-09-14 09:45:32 -0400 | [diff] [blame] | 4227 | return BCME_BADBAND; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4228 | |
| 4229 | /* if multiband and band is not specified, band must be locked */ |
| 4230 | if ((band == WLC_BAND_AUTO) && IS_MBAND_UNLOCKED(wlc)) |
Jason Cooper | 90ea229 | 2010-09-14 09:45:32 -0400 | [diff] [blame] | 4231 | return BCME_NOTBANDLOCKED; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4232 | |
| 4233 | /* must have core clocks */ |
| 4234 | if (!wlc->clk) |
Jason Cooper | 90ea229 | 2010-09-14 09:45:32 -0400 | [diff] [blame] | 4235 | return BCME_NOCLK; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4236 | |
Jason Cooper | 90ea229 | 2010-09-14 09:45:32 -0400 | [diff] [blame] | 4237 | return 0; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4238 | } |
| 4239 | #endif /* defined(BCMDBG) */ |
| 4240 | |
| 4241 | #if defined(BCMDBG) |
| 4242 | /* For some ioctls, make sure that the pi pointer matches the current phy */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 4243 | int wlc_iocpichk(wlc_info_t *wlc, uint phytype) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4244 | { |
| 4245 | if (wlc->band->phytype != phytype) |
| 4246 | return BCME_BADBAND; |
| 4247 | return 0; |
| 4248 | } |
| 4249 | #endif |
| 4250 | |
| 4251 | /* Look up the given var name in the given table */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 4252 | static const bcm_iovar_t *wlc_iovar_lookup(const bcm_iovar_t *table, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4253 | const char *name) |
| 4254 | { |
| 4255 | const bcm_iovar_t *vi; |
| 4256 | const char *lookup_name; |
| 4257 | |
| 4258 | /* skip any ':' delimited option prefixes */ |
| 4259 | lookup_name = strrchr(name, ':'); |
| 4260 | if (lookup_name != NULL) |
| 4261 | lookup_name++; |
| 4262 | else |
| 4263 | lookup_name = name; |
| 4264 | |
| 4265 | ASSERT(table != NULL); |
| 4266 | |
| 4267 | for (vi = table; vi->name; vi++) { |
| 4268 | if (!strcmp(vi->name, lookup_name)) |
| 4269 | return vi; |
| 4270 | } |
| 4271 | /* ran to end of table */ |
| 4272 | |
| 4273 | return NULL; /* var name not found */ |
| 4274 | } |
| 4275 | |
| 4276 | /* simplified integer get interface for common WLC_GET_VAR ioctl handler */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 4277 | int wlc_iovar_getint(wlc_info_t *wlc, const char *name, int *arg) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4278 | { |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 4279 | return wlc_iovar_op(wlc, name, NULL, 0, arg, sizeof(s32), IOV_GET, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4280 | NULL); |
| 4281 | } |
| 4282 | |
| 4283 | /* simplified integer set interface for common WLC_SET_VAR ioctl handler */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 4284 | int wlc_iovar_setint(wlc_info_t *wlc, const char *name, int arg) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4285 | { |
| 4286 | return wlc_iovar_op(wlc, name, NULL, 0, (void *)&arg, sizeof(arg), |
| 4287 | IOV_SET, NULL); |
| 4288 | } |
| 4289 | |
Greg Kroah-Hartman | 562c885 | 2010-10-05 11:04:17 -0700 | [diff] [blame] | 4290 | /* simplified s8 get interface for common WLC_GET_VAR ioctl handler */ |
| 4291 | int wlc_iovar_gets8(wlc_info_t *wlc, const char *name, s8 *arg) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4292 | { |
| 4293 | int iovar_int; |
| 4294 | int err; |
| 4295 | |
| 4296 | err = |
| 4297 | wlc_iovar_op(wlc, name, NULL, 0, &iovar_int, sizeof(iovar_int), |
| 4298 | IOV_GET, NULL); |
| 4299 | if (!err) |
Greg Kroah-Hartman | 562c885 | 2010-10-05 11:04:17 -0700 | [diff] [blame] | 4300 | *arg = (s8) iovar_int; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4301 | |
| 4302 | return err; |
| 4303 | } |
| 4304 | |
| 4305 | /* |
| 4306 | * register iovar table, watchdog and down handlers. |
| 4307 | * calling function must keep 'iovars' until wlc_module_unregister is called. |
| 4308 | * 'iovar' must have the last entry's name field being NULL as terminator. |
| 4309 | */ |
Greg Kroah-Hartman | 0d2f072 | 2010-10-08 14:28:21 -0700 | [diff] [blame] | 4310 | int wlc_module_register(wlc_pub_t *pub, const bcm_iovar_t *iovars, |
| 4311 | const char *name, void *hdl, iovar_fn_t i_fn, |
| 4312 | watchdog_fn_t w_fn, down_fn_t d_fn) |
| 4313 | { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4314 | wlc_info_t *wlc = (wlc_info_t *) pub->wlc; |
| 4315 | int i; |
| 4316 | |
| 4317 | ASSERT(name != NULL); |
| 4318 | ASSERT(i_fn != NULL || w_fn != NULL || d_fn != NULL); |
| 4319 | |
| 4320 | /* find an empty entry and just add, no duplication check! */ |
| 4321 | for (i = 0; i < WLC_MAXMODULES; i++) { |
| 4322 | if (wlc->modulecb[i].name[0] == '\0') { |
| 4323 | strncpy(wlc->modulecb[i].name, name, |
| 4324 | sizeof(wlc->modulecb[i].name) - 1); |
| 4325 | wlc->modulecb[i].iovars = iovars; |
| 4326 | wlc->modulecb[i].hdl = hdl; |
| 4327 | wlc->modulecb[i].iovar_fn = i_fn; |
| 4328 | wlc->modulecb[i].watchdog_fn = w_fn; |
| 4329 | wlc->modulecb[i].down_fn = d_fn; |
| 4330 | return 0; |
| 4331 | } |
| 4332 | } |
| 4333 | |
| 4334 | /* it is time to increase the capacity */ |
| 4335 | ASSERT(i < WLC_MAXMODULES); |
| 4336 | return BCME_NORESOURCE; |
| 4337 | } |
| 4338 | |
| 4339 | /* unregister module callbacks */ |
Greg Kroah-Hartman | 0d2f072 | 2010-10-08 14:28:21 -0700 | [diff] [blame] | 4340 | int wlc_module_unregister(wlc_pub_t *pub, const char *name, void *hdl) |
| 4341 | { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4342 | wlc_info_t *wlc = (wlc_info_t *) pub->wlc; |
| 4343 | int i; |
| 4344 | |
| 4345 | if (wlc == NULL) |
| 4346 | return BCME_NOTFOUND; |
| 4347 | |
| 4348 | ASSERT(name != NULL); |
| 4349 | |
| 4350 | for (i = 0; i < WLC_MAXMODULES; i++) { |
| 4351 | if (!strcmp(wlc->modulecb[i].name, name) && |
| 4352 | (wlc->modulecb[i].hdl == hdl)) { |
Brett Rudley | 9249ede | 2010-11-30 20:09:49 -0800 | [diff] [blame^] | 4353 | memset(&wlc->modulecb[i], 0, sizeof(modulecb_t)); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4354 | return 0; |
| 4355 | } |
| 4356 | } |
| 4357 | |
| 4358 | /* table not found! */ |
| 4359 | return BCME_NOTFOUND; |
| 4360 | } |
| 4361 | |
| 4362 | /* Write WME tunable parameters for retransmit/max rate from wlc struct to ucode */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 4363 | static void wlc_wme_retries_write(wlc_info_t *wlc) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4364 | { |
| 4365 | int ac; |
| 4366 | |
| 4367 | /* Need clock to do this */ |
| 4368 | if (!wlc->clk) |
| 4369 | return; |
| 4370 | |
| 4371 | for (ac = 0; ac < AC_COUNT; ac++) { |
| 4372 | wlc_write_shm(wlc, M_AC_TXLMT_ADDR(ac), wlc->wme_retries[ac]); |
| 4373 | } |
| 4374 | } |
| 4375 | |
| 4376 | /* Get or set an iovar. The params/p_len pair specifies any additional |
| 4377 | * qualifying parameters (e.g. an "element index") for a get, while the |
| 4378 | * arg/len pair is the buffer for the value to be set or retrieved. |
| 4379 | * Operation (get/set) is specified by the last argument. |
| 4380 | * interface context provided by wlcif |
| 4381 | * |
| 4382 | * All pointers may point into the same buffer. |
| 4383 | */ |
| 4384 | int |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 4385 | wlc_iovar_op(wlc_info_t *wlc, const char *name, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4386 | void *params, int p_len, void *arg, int len, |
| 4387 | bool set, struct wlc_if *wlcif) |
| 4388 | { |
| 4389 | int err = 0; |
| 4390 | int val_size; |
| 4391 | const bcm_iovar_t *vi = NULL; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 4392 | u32 actionid; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4393 | int i; |
| 4394 | |
| 4395 | ASSERT(name != NULL); |
| 4396 | |
| 4397 | ASSERT(len >= 0); |
| 4398 | |
| 4399 | /* Get MUST have return space */ |
| 4400 | ASSERT(set || (arg && len)); |
| 4401 | |
| 4402 | ASSERT(!(wlc->pub->hw_off && wlc->pub->up)); |
| 4403 | |
| 4404 | /* Set does NOT take qualifiers */ |
| 4405 | ASSERT(!set || (!params && !p_len)); |
| 4406 | |
| 4407 | if (!set && (len == sizeof(int)) && |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 4408 | !(IS_ALIGNED((unsigned long)(arg), (uint) sizeof(int)))) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4409 | WL_ERROR(("wl%d: %s unaligned get ptr for %s\n", |
| 4410 | wlc->pub->unit, __func__, name)); |
| 4411 | ASSERT(0); |
| 4412 | } |
| 4413 | |
| 4414 | /* find the given iovar name */ |
| 4415 | for (i = 0; i < WLC_MAXMODULES; i++) { |
| 4416 | if (!wlc->modulecb[i].iovars) |
| 4417 | continue; |
Jason Cooper | ca8c1e5 | 2010-09-14 09:45:33 -0400 | [diff] [blame] | 4418 | vi = wlc_iovar_lookup(wlc->modulecb[i].iovars, name); |
| 4419 | if (vi) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4420 | break; |
| 4421 | } |
| 4422 | /* iovar name not found */ |
| 4423 | if (i >= WLC_MAXMODULES) { |
| 4424 | err = BCME_UNSUPPORTED; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4425 | goto exit; |
| 4426 | } |
| 4427 | |
| 4428 | /* set up 'params' pointer in case this is a set command so that |
| 4429 | * the convenience int and bool code can be common to set and get |
| 4430 | */ |
| 4431 | if (params == NULL) { |
| 4432 | params = arg; |
| 4433 | p_len = len; |
| 4434 | } |
| 4435 | |
| 4436 | if (vi->type == IOVT_VOID) |
| 4437 | val_size = 0; |
| 4438 | else if (vi->type == IOVT_BUFFER) |
| 4439 | val_size = len; |
| 4440 | else |
| 4441 | /* all other types are integer sized */ |
| 4442 | val_size = sizeof(int); |
| 4443 | |
| 4444 | actionid = set ? IOV_SVAL(vi->varid) : IOV_GVAL(vi->varid); |
| 4445 | |
| 4446 | /* Do the actual parameter implementation */ |
| 4447 | err = wlc->modulecb[i].iovar_fn(wlc->modulecb[i].hdl, vi, actionid, |
| 4448 | name, params, p_len, arg, len, val_size, |
| 4449 | wlcif); |
| 4450 | |
| 4451 | exit: |
| 4452 | return err; |
| 4453 | } |
| 4454 | |
| 4455 | int |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 4456 | wlc_iovar_check(wlc_pub_t *pub, const bcm_iovar_t *vi, void *arg, int len, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4457 | bool set) |
| 4458 | { |
| 4459 | wlc_info_t *wlc = (wlc_info_t *) pub->wlc; |
| 4460 | int err = 0; |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 4461 | s32 int_val = 0; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4462 | |
| 4463 | /* check generic condition flags */ |
| 4464 | if (set) { |
| 4465 | if (((vi->flags & IOVF_SET_DOWN) && wlc->pub->up) || |
| 4466 | ((vi->flags & IOVF_SET_UP) && !wlc->pub->up)) { |
| 4467 | err = (wlc->pub->up ? BCME_NOTDOWN : BCME_NOTUP); |
| 4468 | } else if ((vi->flags & IOVF_SET_BAND) |
| 4469 | && IS_MBAND_UNLOCKED(wlc)) { |
| 4470 | err = BCME_NOTBANDLOCKED; |
| 4471 | } else if ((vi->flags & IOVF_SET_CLK) && !wlc->clk) { |
| 4472 | err = BCME_NOCLK; |
| 4473 | } |
| 4474 | } else { |
| 4475 | if (((vi->flags & IOVF_GET_DOWN) && wlc->pub->up) || |
| 4476 | ((vi->flags & IOVF_GET_UP) && !wlc->pub->up)) { |
| 4477 | err = (wlc->pub->up ? BCME_NOTDOWN : BCME_NOTUP); |
| 4478 | } else if ((vi->flags & IOVF_GET_BAND) |
| 4479 | && IS_MBAND_UNLOCKED(wlc)) { |
| 4480 | err = BCME_NOTBANDLOCKED; |
| 4481 | } else if ((vi->flags & IOVF_GET_CLK) && !wlc->clk) { |
| 4482 | err = BCME_NOCLK; |
| 4483 | } |
| 4484 | } |
| 4485 | |
| 4486 | if (err) |
| 4487 | goto exit; |
| 4488 | |
| 4489 | /* length check on io buf */ |
Jason Cooper | ca8c1e5 | 2010-09-14 09:45:33 -0400 | [diff] [blame] | 4490 | err = bcm_iovar_lencheck(vi, arg, len, set); |
| 4491 | if (err) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4492 | goto exit; |
| 4493 | |
| 4494 | /* On set, check value ranges for integer types */ |
| 4495 | if (set) { |
| 4496 | switch (vi->type) { |
| 4497 | case IOVT_BOOL: |
| 4498 | case IOVT_INT8: |
| 4499 | case IOVT_INT16: |
| 4500 | case IOVT_INT32: |
| 4501 | case IOVT_UINT8: |
| 4502 | case IOVT_UINT16: |
| 4503 | case IOVT_UINT32: |
| 4504 | bcopy(arg, &int_val, sizeof(int)); |
| 4505 | err = wlc_iovar_rangecheck(wlc, int_val, vi); |
| 4506 | break; |
| 4507 | } |
| 4508 | } |
| 4509 | exit: |
| 4510 | return err; |
| 4511 | } |
| 4512 | |
| 4513 | /* handler for iovar table wlc_iovars */ |
| 4514 | /* |
| 4515 | * IMPLEMENTATION NOTE: In order to avoid checking for get/set in each |
| 4516 | * iovar case, the switch statement maps the iovar id into separate get |
| 4517 | * and set values. If you add a new iovar to the switch you MUST use |
| 4518 | * IOV_GVAL and/or IOV_SVAL in the case labels to avoid conflict with |
| 4519 | * another case. |
| 4520 | * Please use params for additional qualifying parameters. |
| 4521 | */ |
| 4522 | int |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 4523 | wlc_doiovar(void *hdl, const bcm_iovar_t *vi, u32 actionid, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4524 | const char *name, void *params, uint p_len, void *arg, int len, |
| 4525 | int val_size, struct wlc_if *wlcif) |
| 4526 | { |
| 4527 | wlc_info_t *wlc = hdl; |
| 4528 | wlc_bsscfg_t *bsscfg; |
| 4529 | int err = 0; |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 4530 | s32 int_val = 0; |
| 4531 | s32 int_val2 = 0; |
| 4532 | s32 *ret_int_ptr; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4533 | bool bool_val; |
| 4534 | bool bool_val2; |
| 4535 | wlc_bss_info_t *current_bss; |
| 4536 | |
| 4537 | WL_TRACE(("wl%d: %s\n", wlc->pub->unit, __func__)); |
| 4538 | |
| 4539 | bsscfg = NULL; |
| 4540 | current_bss = NULL; |
| 4541 | |
Jason Cooper | ca8c1e5 | 2010-09-14 09:45:33 -0400 | [diff] [blame] | 4542 | err = wlc_iovar_check(wlc->pub, vi, arg, len, IOV_ISSET(actionid)); |
| 4543 | if (err != 0) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4544 | return err; |
| 4545 | |
| 4546 | /* convenience int and bool vals for first 8 bytes of buffer */ |
| 4547 | if (p_len >= (int)sizeof(int_val)) |
| 4548 | bcopy(params, &int_val, sizeof(int_val)); |
| 4549 | |
| 4550 | if (p_len >= (int)sizeof(int_val) * 2) |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 4551 | bcopy((void *)((unsigned long)params + sizeof(int_val)), &int_val2, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4552 | sizeof(int_val)); |
| 4553 | |
| 4554 | /* convenience int ptr for 4-byte gets (requires int aligned arg) */ |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 4555 | ret_int_ptr = (s32 *) arg; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4556 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4557 | bool_val = (int_val != 0) ? true : false; |
| 4558 | bool_val2 = (int_val2 != 0) ? true : false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4559 | |
| 4560 | WL_TRACE(("wl%d: %s: id %d\n", wlc->pub->unit, __func__, |
| 4561 | IOV_ID(actionid))); |
| 4562 | /* Do the actual parameter implementation */ |
| 4563 | switch (actionid) { |
| 4564 | |
| 4565 | case IOV_GVAL(IOV_QTXPOWER):{ |
| 4566 | uint qdbm; |
| 4567 | bool override; |
| 4568 | |
Jason Cooper | ca8c1e5 | 2010-09-14 09:45:33 -0400 | [diff] [blame] | 4569 | err = wlc_phy_txpower_get(wlc->band->pi, &qdbm, |
| 4570 | &override); |
| 4571 | if (err != BCME_OK) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4572 | return err; |
| 4573 | |
| 4574 | /* Return qdbm units */ |
| 4575 | *ret_int_ptr = |
| 4576 | qdbm | (override ? WL_TXPWR_OVERRIDE : 0); |
| 4577 | break; |
| 4578 | } |
| 4579 | |
| 4580 | /* As long as override is false, this only sets the *user* targets. |
| 4581 | User can twiddle this all he wants with no harm. |
| 4582 | wlc_phy_txpower_set() explicitly sets override to false if |
| 4583 | not internal or test. |
| 4584 | */ |
| 4585 | case IOV_SVAL(IOV_QTXPOWER):{ |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 4586 | u8 qdbm; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4587 | bool override; |
| 4588 | |
| 4589 | /* Remove override bit and clip to max qdbm value */ |
Greg Kroah-Hartman | a300ce9 | 2010-10-08 12:28:02 -0700 | [diff] [blame] | 4590 | qdbm = (u8)min_t(u32, (int_val & ~WL_TXPWR_OVERRIDE), 0xff); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4591 | /* Extract override setting */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4592 | override = (int_val & WL_TXPWR_OVERRIDE) ? true : false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4593 | err = |
| 4594 | wlc_phy_txpower_set(wlc->band->pi, qdbm, override); |
| 4595 | break; |
| 4596 | } |
| 4597 | |
| 4598 | case IOV_GVAL(IOV_MPC): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 4599 | *ret_int_ptr = (s32) wlc->mpc; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4600 | break; |
| 4601 | |
| 4602 | case IOV_SVAL(IOV_MPC): |
| 4603 | wlc->mpc = bool_val; |
| 4604 | wlc_radio_mpc_upd(wlc); |
| 4605 | |
| 4606 | break; |
| 4607 | |
| 4608 | case IOV_GVAL(IOV_BCN_LI_BCN): |
| 4609 | *ret_int_ptr = wlc->bcn_li_bcn; |
| 4610 | break; |
| 4611 | |
| 4612 | case IOV_SVAL(IOV_BCN_LI_BCN): |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 4613 | wlc->bcn_li_bcn = (u8) int_val; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4614 | if (wlc->pub->up) |
| 4615 | wlc_bcn_li_upd(wlc); |
| 4616 | break; |
| 4617 | |
| 4618 | default: |
| 4619 | WL_ERROR(("wl%d: %s: unsupported\n", wlc->pub->unit, __func__)); |
| 4620 | err = BCME_UNSUPPORTED; |
| 4621 | break; |
| 4622 | } |
| 4623 | |
| 4624 | goto exit; /* avoid unused label warning */ |
| 4625 | |
| 4626 | exit: |
| 4627 | return err; |
| 4628 | } |
| 4629 | |
| 4630 | static int |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 4631 | wlc_iovar_rangecheck(wlc_info_t *wlc, u32 val, const bcm_iovar_t *vi) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4632 | { |
| 4633 | int err = 0; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 4634 | u32 min_val = 0; |
| 4635 | u32 max_val = 0; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4636 | |
| 4637 | /* Only ranged integers are checked */ |
| 4638 | switch (vi->type) { |
| 4639 | case IOVT_INT32: |
| 4640 | max_val |= 0x7fffffff; |
| 4641 | /* fall through */ |
| 4642 | case IOVT_INT16: |
| 4643 | max_val |= 0x00007fff; |
| 4644 | /* fall through */ |
| 4645 | case IOVT_INT8: |
| 4646 | max_val |= 0x0000007f; |
| 4647 | min_val = ~max_val; |
| 4648 | if (vi->flags & IOVF_NTRL) |
| 4649 | min_val = 1; |
| 4650 | else if (vi->flags & IOVF_WHL) |
| 4651 | min_val = 0; |
| 4652 | /* Signed values are checked against max_val and min_val */ |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 4653 | if ((s32) val < (s32) min_val |
| 4654 | || (s32) val > (s32) max_val) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4655 | err = BCME_RANGE; |
| 4656 | break; |
| 4657 | |
| 4658 | case IOVT_UINT32: |
| 4659 | max_val |= 0xffffffff; |
| 4660 | /* fall through */ |
| 4661 | case IOVT_UINT16: |
| 4662 | max_val |= 0x0000ffff; |
| 4663 | /* fall through */ |
| 4664 | case IOVT_UINT8: |
| 4665 | max_val |= 0x000000ff; |
| 4666 | if (vi->flags & IOVF_NTRL) |
| 4667 | min_val = 1; |
| 4668 | if ((val < min_val) || (val > max_val)) |
| 4669 | err = BCME_RANGE; |
| 4670 | break; |
| 4671 | } |
| 4672 | |
| 4673 | return err; |
| 4674 | } |
| 4675 | |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4676 | #ifdef BCMDBG |
| 4677 | static const char *supr_reason[] = { |
| 4678 | "None", "PMQ Entry", "Flush request", |
| 4679 | "Previous frag failure", "Channel mismatch", |
| 4680 | "Lifetime Expiry", "Underflow" |
| 4681 | }; |
| 4682 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 4683 | static void wlc_print_txs_status(u16 s) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4684 | { |
| 4685 | printf("[15:12] %d frame attempts\n", (s & TX_STATUS_FRM_RTX_MASK) >> |
| 4686 | TX_STATUS_FRM_RTX_SHIFT); |
| 4687 | printf(" [11:8] %d rts attempts\n", (s & TX_STATUS_RTS_RTX_MASK) >> |
| 4688 | TX_STATUS_RTS_RTX_SHIFT); |
| 4689 | printf(" [7] %d PM mode indicated\n", |
| 4690 | ((s & TX_STATUS_PMINDCTD) ? 1 : 0)); |
| 4691 | printf(" [6] %d intermediate status\n", |
| 4692 | ((s & TX_STATUS_INTERMEDIATE) ? 1 : 0)); |
| 4693 | printf(" [5] %d AMPDU\n", (s & TX_STATUS_AMPDU) ? 1 : 0); |
| 4694 | printf(" [4:2] %d Frame Suppressed Reason (%s)\n", |
| 4695 | ((s & TX_STATUS_SUPR_MASK) >> TX_STATUS_SUPR_SHIFT), |
| 4696 | supr_reason[(s & TX_STATUS_SUPR_MASK) >> TX_STATUS_SUPR_SHIFT]); |
| 4697 | printf(" [1] %d acked\n", ((s & TX_STATUS_ACK_RCV) ? 1 : 0)); |
| 4698 | } |
| 4699 | #endif /* BCMDBG */ |
| 4700 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 4701 | void wlc_print_txstatus(tx_status_t *txs) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4702 | { |
| 4703 | #if defined(BCMDBG) |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 4704 | u16 s = txs->status; |
| 4705 | u16 ackphyrxsh = txs->ackphyrxsh; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4706 | |
| 4707 | printf("\ntxpkt (MPDU) Complete\n"); |
| 4708 | |
| 4709 | printf("FrameID: %04x ", txs->frameid); |
| 4710 | printf("TxStatus: %04x", s); |
| 4711 | printf("\n"); |
| 4712 | #ifdef BCMDBG |
| 4713 | wlc_print_txs_status(s); |
| 4714 | #endif |
| 4715 | printf("LastTxTime: %04x ", txs->lasttxtime); |
| 4716 | printf("Seq: %04x ", txs->sequence); |
| 4717 | printf("PHYTxStatus: %04x ", txs->phyerr); |
| 4718 | printf("RxAckRSSI: %04x ", |
| 4719 | (ackphyrxsh & PRXS1_JSSI_MASK) >> PRXS1_JSSI_SHIFT); |
| 4720 | printf("RxAckSQ: %04x", (ackphyrxsh & PRXS1_SQ_MASK) >> PRXS1_SQ_SHIFT); |
| 4721 | printf("\n"); |
| 4722 | #endif /* defined(BCMDBG) */ |
| 4723 | } |
| 4724 | |
| 4725 | #define MACSTATUPD(name) \ |
| 4726 | wlc_ctrupd_cache(macstats.name, &wlc->core->macstat_snapshot->name, &wlc->pub->_cnt->name) |
| 4727 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 4728 | void wlc_statsupd(wlc_info_t *wlc) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4729 | { |
| 4730 | int i; |
| 4731 | #ifdef BCMDBG |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 4732 | u16 delta; |
| 4733 | u16 rxf0ovfl; |
| 4734 | u16 txfunfl[NFIFO]; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4735 | #endif /* BCMDBG */ |
| 4736 | |
| 4737 | /* if driver down, make no sense to update stats */ |
| 4738 | if (!wlc->pub->up) |
| 4739 | return; |
| 4740 | |
| 4741 | #ifdef BCMDBG |
| 4742 | /* save last rx fifo 0 overflow count */ |
| 4743 | rxf0ovfl = wlc->core->macstat_snapshot->rxf0ovfl; |
| 4744 | |
| 4745 | /* save last tx fifo underflow count */ |
| 4746 | for (i = 0; i < NFIFO; i++) |
| 4747 | txfunfl[i] = wlc->core->macstat_snapshot->txfunfl[i]; |
| 4748 | #endif /* BCMDBG */ |
| 4749 | |
| 4750 | #ifdef BCMDBG |
| 4751 | /* check for rx fifo 0 overflow */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 4752 | delta = (u16) (wlc->core->macstat_snapshot->rxf0ovfl - rxf0ovfl); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4753 | if (delta) |
| 4754 | WL_ERROR(("wl%d: %u rx fifo 0 overflows!\n", wlc->pub->unit, |
| 4755 | delta)); |
| 4756 | |
| 4757 | /* check for tx fifo underflows */ |
| 4758 | for (i = 0; i < NFIFO; i++) { |
| 4759 | delta = |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 4760 | (u16) (wlc->core->macstat_snapshot->txfunfl[i] - |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4761 | txfunfl[i]); |
| 4762 | if (delta) |
| 4763 | WL_ERROR(("wl%d: %u tx fifo %d underflows!\n", |
| 4764 | wlc->pub->unit, delta, i)); |
| 4765 | } |
| 4766 | #endif /* BCMDBG */ |
| 4767 | |
| 4768 | /* dot11 counter update */ |
| 4769 | |
| 4770 | WLCNTSET(wlc->pub->_cnt->txrts, |
| 4771 | (wlc->pub->_cnt->rxctsucast - |
| 4772 | wlc->pub->_cnt->d11cnt_txrts_off)); |
| 4773 | WLCNTSET(wlc->pub->_cnt->rxcrc, |
| 4774 | (wlc->pub->_cnt->rxbadfcs - wlc->pub->_cnt->d11cnt_rxcrc_off)); |
| 4775 | WLCNTSET(wlc->pub->_cnt->txnocts, |
| 4776 | ((wlc->pub->_cnt->txrtsfrm - wlc->pub->_cnt->rxctsucast) - |
| 4777 | wlc->pub->_cnt->d11cnt_txnocts_off)); |
| 4778 | |
| 4779 | /* merge counters from dma module */ |
| 4780 | for (i = 0; i < NFIFO; i++) { |
| 4781 | if (wlc->hw->di[i]) { |
| 4782 | WLCNTADD(wlc->pub->_cnt->txnobuf, |
| 4783 | (wlc->hw->di[i])->txnobuf); |
| 4784 | WLCNTADD(wlc->pub->_cnt->rxnobuf, |
| 4785 | (wlc->hw->di[i])->rxnobuf); |
| 4786 | WLCNTADD(wlc->pub->_cnt->rxgiant, |
| 4787 | (wlc->hw->di[i])->rxgiants); |
| 4788 | dma_counterreset(wlc->hw->di[i]); |
| 4789 | } |
| 4790 | } |
| 4791 | |
| 4792 | /* |
| 4793 | * Aggregate transmit and receive errors that probably resulted |
| 4794 | * in the loss of a frame are computed on the fly. |
| 4795 | */ |
| 4796 | WLCNTSET(wlc->pub->_cnt->txerror, |
| 4797 | wlc->pub->_cnt->txnobuf + wlc->pub->_cnt->txnoassoc + |
| 4798 | wlc->pub->_cnt->txuflo + wlc->pub->_cnt->txrunt + |
| 4799 | wlc->pub->_cnt->dmade + wlc->pub->_cnt->dmada + |
| 4800 | wlc->pub->_cnt->dmape); |
| 4801 | WLCNTSET(wlc->pub->_cnt->rxerror, |
| 4802 | wlc->pub->_cnt->rxoflo + wlc->pub->_cnt->rxnobuf + |
| 4803 | wlc->pub->_cnt->rxfragerr + wlc->pub->_cnt->rxrunt + |
| 4804 | wlc->pub->_cnt->rxgiant + wlc->pub->_cnt->rxnoscb + |
| 4805 | wlc->pub->_cnt->rxbadsrcmac); |
| 4806 | for (i = 0; i < NFIFO; i++) |
| 4807 | WLCNTADD(wlc->pub->_cnt->rxerror, wlc->pub->_cnt->rxuflo[i]); |
| 4808 | } |
| 4809 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 4810 | bool wlc_chipmatch(u16 vendor, u16 device) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4811 | { |
| 4812 | if (vendor != VENDOR_BROADCOM) { |
| 4813 | WL_ERROR(("wlc_chipmatch: unknown vendor id %04x\n", vendor)); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4814 | return false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4815 | } |
| 4816 | |
| 4817 | if ((device == BCM43224_D11N_ID) || (device == BCM43225_D11N2G_ID)) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4818 | return true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4819 | |
| 4820 | if (device == BCM4313_D11N2G_ID) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4821 | return true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4822 | if ((device == BCM43236_D11N_ID) || (device == BCM43236_D11N2G_ID)) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4823 | return true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4824 | |
| 4825 | WL_ERROR(("wlc_chipmatch: unknown device id %04x\n", device)); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4826 | return false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4827 | } |
| 4828 | |
| 4829 | #if defined(BCMDBG) |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 4830 | void wlc_print_txdesc(d11txh_t *txh) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4831 | { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 4832 | u16 mtcl = ltoh16(txh->MacTxControlLow); |
| 4833 | u16 mtch = ltoh16(txh->MacTxControlHigh); |
| 4834 | u16 mfc = ltoh16(txh->MacFrameControl); |
| 4835 | u16 tfest = ltoh16(txh->TxFesTimeNormal); |
| 4836 | u16 ptcw = ltoh16(txh->PhyTxControlWord); |
| 4837 | u16 ptcw_1 = ltoh16(txh->PhyTxControlWord_1); |
| 4838 | u16 ptcw_1_Fbr = ltoh16(txh->PhyTxControlWord_1_Fbr); |
| 4839 | u16 ptcw_1_Rts = ltoh16(txh->PhyTxControlWord_1_Rts); |
| 4840 | u16 ptcw_1_FbrRts = ltoh16(txh->PhyTxControlWord_1_FbrRts); |
| 4841 | u16 mainrates = ltoh16(txh->MainRates); |
| 4842 | u16 xtraft = ltoh16(txh->XtraFrameTypes); |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 4843 | u8 *iv = txh->IV; |
| 4844 | u8 *ra = txh->TxFrameRA; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 4845 | u16 tfestfb = ltoh16(txh->TxFesTimeFallback); |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 4846 | u8 *rtspfb = txh->RTSPLCPFallback; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 4847 | u16 rtsdfb = ltoh16(txh->RTSDurFallback); |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 4848 | u8 *fragpfb = txh->FragPLCPFallback; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 4849 | u16 fragdfb = ltoh16(txh->FragDurFallback); |
| 4850 | u16 mmodelen = ltoh16(txh->MModeLen); |
| 4851 | u16 mmodefbrlen = ltoh16(txh->MModeFbrLen); |
| 4852 | u16 tfid = ltoh16(txh->TxFrameID); |
| 4853 | u16 txs = ltoh16(txh->TxStatus); |
| 4854 | u16 mnmpdu = ltoh16(txh->MaxNMpdus); |
| 4855 | u16 mabyte = ltoh16(txh->MaxABytes_MRT); |
| 4856 | u16 mabyte_f = ltoh16(txh->MaxABytes_FBR); |
| 4857 | u16 mmbyte = ltoh16(txh->MinMBytes); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4858 | |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 4859 | u8 *rtsph = txh->RTSPhyHeader; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4860 | struct dot11_rts_frame rts = txh->rts_frame; |
| 4861 | char hexbuf[256]; |
| 4862 | |
| 4863 | /* add plcp header along with txh descriptor */ |
Greg Kroah-Hartman | 580a0bd | 2010-10-05 11:09:48 -0700 | [diff] [blame] | 4864 | prhex("Raw TxDesc + plcp header", (unsigned char *) txh, sizeof(d11txh_t) + 48); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4865 | |
| 4866 | printf("TxCtlLow: %04x ", mtcl); |
| 4867 | printf("TxCtlHigh: %04x ", mtch); |
| 4868 | printf("FC: %04x ", mfc); |
| 4869 | printf("FES Time: %04x\n", tfest); |
| 4870 | printf("PhyCtl: %04x%s ", ptcw, |
| 4871 | (ptcw & PHY_TXC_SHORT_HDR) ? " short" : ""); |
| 4872 | printf("PhyCtl_1: %04x ", ptcw_1); |
| 4873 | printf("PhyCtl_1_Fbr: %04x\n", ptcw_1_Fbr); |
| 4874 | printf("PhyCtl_1_Rts: %04x ", ptcw_1_Rts); |
| 4875 | printf("PhyCtl_1_Fbr_Rts: %04x\n", ptcw_1_FbrRts); |
| 4876 | printf("MainRates: %04x ", mainrates); |
| 4877 | printf("XtraFrameTypes: %04x ", xtraft); |
| 4878 | printf("\n"); |
| 4879 | |
| 4880 | bcm_format_hex(hexbuf, iv, sizeof(txh->IV)); |
| 4881 | printf("SecIV: %s\n", hexbuf); |
| 4882 | bcm_format_hex(hexbuf, ra, sizeof(txh->TxFrameRA)); |
| 4883 | printf("RA: %s\n", hexbuf); |
| 4884 | |
| 4885 | printf("Fb FES Time: %04x ", tfestfb); |
| 4886 | bcm_format_hex(hexbuf, rtspfb, sizeof(txh->RTSPLCPFallback)); |
| 4887 | printf("RTS PLCP: %s ", hexbuf); |
| 4888 | printf("RTS DUR: %04x ", rtsdfb); |
| 4889 | bcm_format_hex(hexbuf, fragpfb, sizeof(txh->FragPLCPFallback)); |
| 4890 | printf("PLCP: %s ", hexbuf); |
| 4891 | printf("DUR: %04x", fragdfb); |
| 4892 | printf("\n"); |
| 4893 | |
| 4894 | printf("MModeLen: %04x ", mmodelen); |
| 4895 | printf("MModeFbrLen: %04x\n", mmodefbrlen); |
| 4896 | |
| 4897 | printf("FrameID: %04x\n", tfid); |
| 4898 | printf("TxStatus: %04x\n", txs); |
| 4899 | |
| 4900 | printf("MaxNumMpdu: %04x\n", mnmpdu); |
| 4901 | printf("MaxAggbyte: %04x\n", mabyte); |
| 4902 | printf("MaxAggbyte_fb: %04x\n", mabyte_f); |
| 4903 | printf("MinByte: %04x\n", mmbyte); |
| 4904 | |
| 4905 | bcm_format_hex(hexbuf, rtsph, sizeof(txh->RTSPhyHeader)); |
| 4906 | printf("RTS PLCP: %s ", hexbuf); |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 4907 | bcm_format_hex(hexbuf, (u8 *) &rts, sizeof(txh->rts_frame)); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4908 | printf("RTS Frame: %s", hexbuf); |
| 4909 | printf("\n"); |
| 4910 | |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4911 | } |
| 4912 | #endif /* defined(BCMDBG) */ |
| 4913 | |
| 4914 | #if defined(BCMDBG) |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 4915 | void wlc_print_rxh(d11rxhdr_t *rxh) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4916 | { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 4917 | u16 len = rxh->RxFrameSize; |
| 4918 | u16 phystatus_0 = rxh->PhyRxStatus_0; |
| 4919 | u16 phystatus_1 = rxh->PhyRxStatus_1; |
| 4920 | u16 phystatus_2 = rxh->PhyRxStatus_2; |
| 4921 | u16 phystatus_3 = rxh->PhyRxStatus_3; |
| 4922 | u16 macstatus1 = rxh->RxStatus1; |
| 4923 | u16 macstatus2 = rxh->RxStatus2; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4924 | char flagstr[64]; |
| 4925 | char lenbuf[20]; |
| 4926 | static const bcm_bit_desc_t macstat_flags[] = { |
| 4927 | {RXS_FCSERR, "FCSErr"}, |
| 4928 | {RXS_RESPFRAMETX, "Reply"}, |
| 4929 | {RXS_PBPRES, "PADDING"}, |
| 4930 | {RXS_DECATMPT, "DeCr"}, |
| 4931 | {RXS_DECERR, "DeCrErr"}, |
| 4932 | {RXS_BCNSENT, "Bcn"}, |
| 4933 | {0, NULL} |
| 4934 | }; |
| 4935 | |
Greg Kroah-Hartman | 580a0bd | 2010-10-05 11:09:48 -0700 | [diff] [blame] | 4936 | prhex("Raw RxDesc", (unsigned char *) rxh, sizeof(d11rxhdr_t)); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4937 | |
| 4938 | bcm_format_flags(macstat_flags, macstatus1, flagstr, 64); |
| 4939 | |
| 4940 | snprintf(lenbuf, sizeof(lenbuf), "0x%x", len); |
| 4941 | |
| 4942 | printf("RxFrameSize: %6s (%d)%s\n", lenbuf, len, |
| 4943 | (rxh->PhyRxStatus_0 & PRXS0_SHORTH) ? " short preamble" : ""); |
| 4944 | printf("RxPHYStatus: %04x %04x %04x %04x\n", |
| 4945 | phystatus_0, phystatus_1, phystatus_2, phystatus_3); |
| 4946 | printf("RxMACStatus: %x %s\n", macstatus1, flagstr); |
| 4947 | printf("RXMACaggtype: %x\n", (macstatus2 & RXS_AGGTYPE_MASK)); |
| 4948 | printf("RxTSFTime: %04x\n", rxh->RxTSFTime); |
| 4949 | } |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4950 | #endif /* defined(BCMDBG) */ |
| 4951 | |
| 4952 | #if defined(BCMDBG) |
Greg Kroah-Hartman | 580a0bd | 2010-10-05 11:09:48 -0700 | [diff] [blame] | 4953 | int wlc_format_ssid(char *buf, const unsigned char ssid[], uint ssid_len) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4954 | { |
| 4955 | uint i, c; |
| 4956 | char *p = buf; |
| 4957 | char *endp = buf + SSID_FMT_BUF_LEN; |
| 4958 | |
| 4959 | if (ssid_len > DOT11_MAX_SSID_LEN) |
| 4960 | ssid_len = DOT11_MAX_SSID_LEN; |
| 4961 | |
| 4962 | for (i = 0; i < ssid_len; i++) { |
| 4963 | c = (uint) ssid[i]; |
| 4964 | if (c == '\\') { |
| 4965 | *p++ = '\\'; |
| 4966 | *p++ = '\\'; |
Greg Kroah-Hartman | 580a0bd | 2010-10-05 11:09:48 -0700 | [diff] [blame] | 4967 | } else if (isprint((unsigned char) c)) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4968 | *p++ = (char)c; |
| 4969 | } else { |
| 4970 | p += snprintf(p, (endp - p), "\\x%02X", c); |
| 4971 | } |
| 4972 | } |
| 4973 | *p = '\0'; |
| 4974 | ASSERT(p < endp); |
| 4975 | |
| 4976 | return (int)(p - buf); |
| 4977 | } |
| 4978 | #endif /* defined(BCMDBG) */ |
| 4979 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 4980 | u16 wlc_rate_shm_offset(wlc_info_t *wlc, u8 rate) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4981 | { |
Jason Cooper | 90ea229 | 2010-09-14 09:45:32 -0400 | [diff] [blame] | 4982 | return wlc_bmac_rate_shm_offset(wlc->hw, rate); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4983 | } |
| 4984 | |
| 4985 | /* Callback for device removed */ |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4986 | |
| 4987 | /* |
| 4988 | * Attempts to queue a packet onto a multiple-precedence queue, |
| 4989 | * if necessary evicting a lower precedence packet from the queue. |
| 4990 | * |
| 4991 | * 'prec' is the precedence number that has already been mapped |
| 4992 | * from the packet priority. |
| 4993 | * |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4994 | * Returns true if packet consumed (queued), false if not. |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4995 | */ |
| 4996 | bool BCMFASTPATH |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 4997 | wlc_prec_enq(wlc_info_t *wlc, struct pktq *q, void *pkt, int prec) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 4998 | { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4999 | return wlc_prec_enq_head(wlc, q, pkt, prec, false); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5000 | } |
| 5001 | |
| 5002 | bool BCMFASTPATH |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 5003 | wlc_prec_enq_head(wlc_info_t *wlc, struct pktq *q, struct sk_buff *pkt, |
| 5004 | int prec, bool head) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5005 | { |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 5006 | struct sk_buff *p; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5007 | int eprec = -1; /* precedence to evict from */ |
| 5008 | |
| 5009 | /* Determine precedence from which to evict packet, if any */ |
| 5010 | if (pktq_pfull(q, prec)) |
| 5011 | eprec = prec; |
| 5012 | else if (pktq_full(q)) { |
| 5013 | p = pktq_peek_tail(q, &eprec); |
| 5014 | ASSERT(p != NULL); |
| 5015 | if (eprec > prec) { |
| 5016 | WL_ERROR(("%s: Failing: eprec %d > prec %d\n", __func__, |
| 5017 | eprec, prec)); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5018 | return false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5019 | } |
| 5020 | } |
| 5021 | |
| 5022 | /* Evict if needed */ |
| 5023 | if (eprec >= 0) { |
| 5024 | bool discard_oldest; |
| 5025 | |
| 5026 | /* Detect queueing to unconfigured precedence */ |
| 5027 | ASSERT(!pktq_pempty(q, eprec)); |
| 5028 | |
| 5029 | discard_oldest = AC_BITMAP_TST(wlc->wme_dp, eprec); |
| 5030 | |
| 5031 | /* Refuse newer packet unless configured to discard oldest */ |
| 5032 | if (eprec == prec && !discard_oldest) { |
| 5033 | WL_ERROR(("%s: No where to go, prec == %d\n", __func__, |
| 5034 | prec)); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5035 | return false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5036 | } |
| 5037 | |
| 5038 | /* Evict packet according to discard policy */ |
| 5039 | p = discard_oldest ? pktq_pdeq(q, eprec) : pktq_pdeq_tail(q, |
| 5040 | eprec); |
| 5041 | ASSERT(p != NULL); |
| 5042 | |
| 5043 | /* Increment wme stats */ |
| 5044 | if (WME_ENAB(wlc->pub)) { |
| 5045 | WLCNTINCR(wlc->pub->_wme_cnt-> |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 5046 | tx_failed[WME_PRIO2AC(p->priority)].packets); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5047 | WLCNTADD(wlc->pub->_wme_cnt-> |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 5048 | tx_failed[WME_PRIO2AC(p->priority)].bytes, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5049 | pkttotlen(wlc->osh, p)); |
| 5050 | } |
| 5051 | |
| 5052 | ASSERT(0); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5053 | PKTFREE(wlc->osh, p, true); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5054 | WLCNTINCR(wlc->pub->_cnt->txnobuf); |
| 5055 | } |
| 5056 | |
| 5057 | /* Enqueue */ |
| 5058 | if (head) |
| 5059 | p = pktq_penq_head(q, prec, pkt); |
| 5060 | else |
| 5061 | p = pktq_penq(q, prec, pkt); |
| 5062 | ASSERT(p != NULL); |
| 5063 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5064 | return true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5065 | } |
| 5066 | |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 5067 | void BCMFASTPATH wlc_txq_enq(void *ctx, struct scb *scb, struct sk_buff *sdu, |
| 5068 | uint prec) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5069 | { |
| 5070 | wlc_info_t *wlc = (wlc_info_t *) ctx; |
| 5071 | wlc_txq_info_t *qi = wlc->active_queue; /* Check me */ |
| 5072 | struct pktq *q = &qi->q; |
| 5073 | int prio; |
| 5074 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 5075 | prio = sdu->priority; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5076 | |
| 5077 | ASSERT(pktq_max(q) >= wlc->pub->tunables->datahiwat); |
| 5078 | |
| 5079 | if (!wlc_prec_enq(wlc, q, sdu, prec)) { |
| 5080 | if (!EDCF_ENAB(wlc->pub) |
| 5081 | || (wlc->pub->wlfeatureflag & WL_SWFL_FLOWCONTROL)) |
| 5082 | WL_ERROR(("wl%d: wlc_txq_enq: txq overflow\n", |
| 5083 | wlc->pub->unit)); |
| 5084 | |
| 5085 | /* ASSERT(9 == 8); *//* XXX we might hit this condtion in case packet flooding from mac80211 stack */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5086 | PKTFREE(wlc->osh, sdu, true); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5087 | WLCNTINCR(wlc->pub->_cnt->txnobuf); |
| 5088 | } |
| 5089 | |
| 5090 | /* Check if flow control needs to be turned on after enqueuing the packet |
| 5091 | * Don't turn on flow control if EDCF is enabled. Driver would make the decision on what |
| 5092 | * to drop instead of relying on stack to make the right decision |
| 5093 | */ |
| 5094 | if (!EDCF_ENAB(wlc->pub) |
| 5095 | || (wlc->pub->wlfeatureflag & WL_SWFL_FLOWCONTROL)) { |
| 5096 | if (pktq_len(q) >= wlc->pub->tunables->datahiwat) { |
| 5097 | wlc_txflowcontrol(wlc, qi, ON, ALLPRIO); |
| 5098 | } |
| 5099 | } else if (wlc->pub->_priofc) { |
| 5100 | if (pktq_plen(q, wlc_prio2prec_map[prio]) >= |
| 5101 | wlc->pub->tunables->datahiwat) { |
| 5102 | wlc_txflowcontrol(wlc, qi, ON, prio); |
| 5103 | } |
| 5104 | } |
| 5105 | } |
| 5106 | |
| 5107 | bool BCMFASTPATH |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 5108 | wlc_sendpkt_mac80211(wlc_info_t *wlc, struct sk_buff *sdu, |
| 5109 | struct ieee80211_hw *hw) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5110 | { |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 5111 | u8 prio; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5112 | uint fifo; |
| 5113 | void *pkt; |
| 5114 | struct scb *scb = &global_scb; |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 5115 | struct dot11_header *d11_header = (struct dot11_header *)(sdu->data); |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 5116 | u16 type, fc; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5117 | |
| 5118 | ASSERT(sdu); |
| 5119 | |
| 5120 | fc = ltoh16(d11_header->fc); |
| 5121 | type = FC_TYPE(fc); |
| 5122 | |
| 5123 | /* 802.11 standard requires management traffic to go at highest priority */ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 5124 | prio = (type == FC_TYPE_DATA ? sdu->priority : MAXPRIO); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5125 | fifo = prio2fifo[prio]; |
| 5126 | |
Arend van Spriel | 3be727c | 2010-11-23 22:20:30 +0100 | [diff] [blame] | 5127 | ASSERT((uint) skb_headroom(sdu) >= TXOFF); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 5128 | ASSERT(!(sdu->cloned)); |
| 5129 | ASSERT(!(sdu->next)); |
| 5130 | ASSERT(!(sdu->prev)); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5131 | ASSERT(fifo < NFIFO); |
| 5132 | |
| 5133 | pkt = sdu; |
| 5134 | if (unlikely |
| 5135 | (wlc_d11hdrs_mac80211(wlc, hw, pkt, scb, 0, 1, fifo, 0, NULL, 0))) |
| 5136 | return -EINVAL; |
| 5137 | wlc_txq_enq(wlc, scb, pkt, WLC_PRIO_TO_PREC(prio)); |
| 5138 | wlc_send_q(wlc, wlc->active_queue); |
| 5139 | |
| 5140 | WLCNTINCR(wlc->pub->_cnt->ieee_tx); |
| 5141 | return 0; |
| 5142 | } |
| 5143 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 5144 | void BCMFASTPATH wlc_send_q(wlc_info_t *wlc, wlc_txq_info_t *qi) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5145 | { |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 5146 | struct sk_buff *pkt[DOT11_MAXNUMFRAGS]; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5147 | int prec; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 5148 | u16 prec_map; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5149 | int err = 0, i, count; |
| 5150 | uint fifo; |
| 5151 | struct pktq *q = &qi->q; |
| 5152 | struct ieee80211_tx_info *tx_info; |
| 5153 | |
| 5154 | /* only do work for the active queue */ |
| 5155 | if (qi != wlc->active_queue) |
| 5156 | return; |
| 5157 | |
| 5158 | if (in_send_q) |
| 5159 | return; |
| 5160 | else |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5161 | in_send_q = true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5162 | |
| 5163 | prec_map = wlc->tx_prec_map; |
| 5164 | |
| 5165 | /* Send all the enq'd pkts that we can. |
| 5166 | * Dequeue packets with precedence with empty HW fifo only |
| 5167 | */ |
| 5168 | while (prec_map && (pkt[0] = pktq_mdeq(q, prec_map, &prec))) { |
| 5169 | tx_info = IEEE80211_SKB_CB(pkt[0]); |
| 5170 | if (tx_info->flags & IEEE80211_TX_CTL_AMPDU) { |
| 5171 | err = wlc_sendampdu(wlc->ampdu, qi, pkt, prec); |
| 5172 | } else { |
| 5173 | count = 1; |
| 5174 | err = wlc_prep_pdu(wlc, pkt[0], &fifo); |
| 5175 | if (!err) { |
| 5176 | for (i = 0; i < count; i++) { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5177 | wlc_txfifo(wlc, fifo, pkt[i], true, 1); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5178 | } |
| 5179 | } |
| 5180 | } |
| 5181 | |
| 5182 | if (err == BCME_BUSY) { |
| 5183 | pktq_penq_head(q, prec, pkt[0]); |
| 5184 | /* If send failed due to any other reason than a change in |
| 5185 | * HW FIFO condition, quit. Otherwise, read the new prec_map! |
| 5186 | */ |
| 5187 | if (prec_map == wlc->tx_prec_map) |
| 5188 | break; |
| 5189 | prec_map = wlc->tx_prec_map; |
| 5190 | } |
| 5191 | } |
| 5192 | |
| 5193 | /* Check if flow control needs to be turned off after sending the packet */ |
| 5194 | if (!EDCF_ENAB(wlc->pub) |
| 5195 | || (wlc->pub->wlfeatureflag & WL_SWFL_FLOWCONTROL)) { |
| 5196 | if (wlc_txflowcontrol_prio_isset(wlc, qi, ALLPRIO) |
| 5197 | && (pktq_len(q) < wlc->pub->tunables->datahiwat / 2)) { |
| 5198 | wlc_txflowcontrol(wlc, qi, OFF, ALLPRIO); |
| 5199 | } |
| 5200 | } else if (wlc->pub->_priofc) { |
| 5201 | int prio; |
| 5202 | for (prio = MAXPRIO; prio >= 0; prio--) { |
| 5203 | if (wlc_txflowcontrol_prio_isset(wlc, qi, prio) && |
| 5204 | (pktq_plen(q, wlc_prio2prec_map[prio]) < |
| 5205 | wlc->pub->tunables->datahiwat / 2)) { |
| 5206 | wlc_txflowcontrol(wlc, qi, OFF, prio); |
| 5207 | } |
| 5208 | } |
| 5209 | } |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5210 | in_send_q = false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5211 | } |
| 5212 | |
| 5213 | /* |
| 5214 | * bcmc_fid_generate: |
| 5215 | * Generate frame ID for a BCMC packet. The frag field is not used |
| 5216 | * for MC frames so is used as part of the sequence number. |
| 5217 | */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 5218 | static inline u16 |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 5219 | bcmc_fid_generate(wlc_info_t *wlc, wlc_bsscfg_t *bsscfg, d11txh_t *txh) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5220 | { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 5221 | u16 frameid; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5222 | |
| 5223 | frameid = ltoh16(txh->TxFrameID) & ~(TXFID_SEQ_MASK | TXFID_QUEUE_MASK); |
| 5224 | frameid |= |
| 5225 | (((wlc-> |
| 5226 | mc_fid_counter++) << TXFID_SEQ_SHIFT) & TXFID_SEQ_MASK) | |
| 5227 | TX_BCMC_FIFO; |
| 5228 | |
| 5229 | return frameid; |
| 5230 | } |
| 5231 | |
| 5232 | void BCMFASTPATH |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 5233 | wlc_txfifo(wlc_info_t *wlc, uint fifo, struct sk_buff *p, bool commit, |
| 5234 | s8 txpktpend) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5235 | { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 5236 | u16 frameid = INVALIDFID; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5237 | d11txh_t *txh; |
| 5238 | |
| 5239 | ASSERT(fifo < NFIFO); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 5240 | txh = (d11txh_t *) (p->data); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5241 | |
| 5242 | /* When a BC/MC frame is being committed to the BCMC fifo via DMA (NOT PIO), update |
| 5243 | * ucode or BSS info as appropriate. |
| 5244 | */ |
| 5245 | if (fifo == TX_BCMC_FIFO) { |
| 5246 | frameid = ltoh16(txh->TxFrameID); |
| 5247 | |
| 5248 | } |
| 5249 | |
| 5250 | if (WLC_WAR16165(wlc)) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5251 | wlc_war16165(wlc, true); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5252 | |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5253 | |
| 5254 | /* Bump up pending count for if not using rpc. If rpc is used, this will be handled |
| 5255 | * in wlc_bmac_txfifo() |
| 5256 | */ |
| 5257 | if (commit) { |
| 5258 | TXPKTPENDINC(wlc, fifo, txpktpend); |
| 5259 | WL_TRACE(("wlc_txfifo, pktpend inc %d to %d\n", txpktpend, |
| 5260 | TXPKTPENDGET(wlc, fifo))); |
| 5261 | } |
| 5262 | |
| 5263 | /* Commit BCMC sequence number in the SHM frame ID location */ |
| 5264 | if (frameid != INVALIDFID) |
| 5265 | BCMCFID(wlc, frameid); |
| 5266 | |
| 5267 | if (dma_txfast(wlc->hw->di[fifo], p, commit) < 0) { |
| 5268 | WL_ERROR(("wlc_txfifo: fatal, toss frames !!!\n")); |
| 5269 | } |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5270 | } |
| 5271 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 5272 | static u16 |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 5273 | wlc_compute_airtime(wlc_info_t *wlc, ratespec_t rspec, uint length) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5274 | { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 5275 | u16 usec = 0; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5276 | uint mac_rate = RSPEC2RATE(rspec); |
| 5277 | uint nsyms; |
| 5278 | |
| 5279 | if (IS_MCS(rspec)) { |
| 5280 | /* not supported yet */ |
| 5281 | ASSERT(0); |
| 5282 | } else if (IS_OFDM(rspec)) { |
| 5283 | /* nsyms = Ceiling(Nbits / (Nbits/sym)) |
| 5284 | * |
| 5285 | * Nbits = length * 8 |
| 5286 | * Nbits/sym = Mbps * 4 = mac_rate * 2 |
| 5287 | */ |
| 5288 | nsyms = CEIL((length * 8), (mac_rate * 2)); |
| 5289 | |
| 5290 | /* usec = symbols * usec/symbol */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 5291 | usec = (u16) (nsyms * APHY_SYMBOL_TIME); |
Jason Cooper | 90ea229 | 2010-09-14 09:45:32 -0400 | [diff] [blame] | 5292 | return usec; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5293 | } else { |
| 5294 | switch (mac_rate) { |
| 5295 | case WLC_RATE_1M: |
| 5296 | usec = length << 3; |
| 5297 | break; |
| 5298 | case WLC_RATE_2M: |
| 5299 | usec = length << 2; |
| 5300 | break; |
| 5301 | case WLC_RATE_5M5: |
| 5302 | usec = (length << 4) / 11; |
| 5303 | break; |
| 5304 | case WLC_RATE_11M: |
| 5305 | usec = (length << 3) / 11; |
| 5306 | break; |
| 5307 | default: |
| 5308 | WL_ERROR(("wl%d: wlc_compute_airtime: unsupported rspec 0x%x\n", wlc->pub->unit, rspec)); |
| 5309 | ASSERT((const char *)"Bad phy_rate" == NULL); |
| 5310 | break; |
| 5311 | } |
| 5312 | } |
| 5313 | |
Jason Cooper | 90ea229 | 2010-09-14 09:45:32 -0400 | [diff] [blame] | 5314 | return usec; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5315 | } |
| 5316 | |
| 5317 | void BCMFASTPATH |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 5318 | wlc_compute_plcp(wlc_info_t *wlc, ratespec_t rspec, uint length, u8 *plcp) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5319 | { |
| 5320 | if (IS_MCS(rspec)) { |
| 5321 | wlc_compute_mimo_plcp(rspec, length, plcp); |
| 5322 | } else if (IS_OFDM(rspec)) { |
| 5323 | wlc_compute_ofdm_plcp(rspec, length, plcp); |
| 5324 | } else { |
| 5325 | wlc_compute_cck_plcp(rspec, length, plcp); |
| 5326 | } |
| 5327 | return; |
| 5328 | } |
| 5329 | |
| 5330 | /* Rate: 802.11 rate code, length: PSDU length in octets */ |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 5331 | static void wlc_compute_mimo_plcp(ratespec_t rspec, uint length, u8 *plcp) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5332 | { |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 5333 | u8 mcs = (u8) (rspec & RSPEC_RATE_MASK); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5334 | ASSERT(IS_MCS(rspec)); |
| 5335 | plcp[0] = mcs; |
| 5336 | if (RSPEC_IS40MHZ(rspec) || (mcs == 32)) |
| 5337 | plcp[0] |= MIMO_PLCP_40MHZ; |
| 5338 | WLC_SET_MIMO_PLCP_LEN(plcp, length); |
| 5339 | plcp[3] = RSPEC_MIMOPLCP3(rspec); /* rspec already holds this byte */ |
| 5340 | plcp[3] |= 0x7; /* set smoothing, not sounding ppdu & reserved */ |
| 5341 | plcp[4] = 0; /* number of extension spatial streams bit 0 & 1 */ |
| 5342 | plcp[5] = 0; |
| 5343 | } |
| 5344 | |
| 5345 | /* Rate: 802.11 rate code, length: PSDU length in octets */ |
| 5346 | static void BCMFASTPATH |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 5347 | wlc_compute_ofdm_plcp(ratespec_t rspec, u32 length, u8 *plcp) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5348 | { |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 5349 | u8 rate_signal; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 5350 | u32 tmp = 0; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5351 | int rate = RSPEC2RATE(rspec); |
| 5352 | |
| 5353 | ASSERT(IS_OFDM(rspec)); |
| 5354 | |
| 5355 | /* encode rate per 802.11a-1999 sec 17.3.4.1, with lsb transmitted first */ |
| 5356 | rate_signal = rate_info[rate] & RATE_MASK; |
| 5357 | ASSERT(rate_signal != 0); |
| 5358 | |
Brett Rudley | 9249ede | 2010-11-30 20:09:49 -0800 | [diff] [blame^] | 5359 | memset(plcp, 0, D11_PHY_HDR_LEN); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5360 | D11A_PHY_HDR_SRATE((ofdm_phy_hdr_t *) plcp, rate_signal); |
| 5361 | |
| 5362 | tmp = (length & 0xfff) << 5; |
| 5363 | plcp[2] |= (tmp >> 16) & 0xff; |
| 5364 | plcp[1] |= (tmp >> 8) & 0xff; |
| 5365 | plcp[0] |= tmp & 0xff; |
| 5366 | |
| 5367 | return; |
| 5368 | } |
| 5369 | |
| 5370 | /* |
| 5371 | * Compute PLCP, but only requires actual rate and length of pkt. |
| 5372 | * Rate is given in the driver standard multiple of 500 kbps. |
| 5373 | * le is set for 11 Mbps rate if necessary. |
| 5374 | * Broken out for PRQ. |
| 5375 | */ |
| 5376 | |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 5377 | static void wlc_cck_plcp_set(int rate_500, uint length, u8 *plcp) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5378 | { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 5379 | u16 usec = 0; |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 5380 | u8 le = 0; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5381 | |
| 5382 | switch (rate_500) { |
| 5383 | case WLC_RATE_1M: |
| 5384 | usec = length << 3; |
| 5385 | break; |
| 5386 | case WLC_RATE_2M: |
| 5387 | usec = length << 2; |
| 5388 | break; |
| 5389 | case WLC_RATE_5M5: |
| 5390 | usec = (length << 4) / 11; |
| 5391 | if ((length << 4) - (usec * 11) > 0) |
| 5392 | usec++; |
| 5393 | break; |
| 5394 | case WLC_RATE_11M: |
| 5395 | usec = (length << 3) / 11; |
| 5396 | if ((length << 3) - (usec * 11) > 0) { |
| 5397 | usec++; |
| 5398 | if ((usec * 11) - (length << 3) >= 8) |
| 5399 | le = D11B_PLCP_SIGNAL_LE; |
| 5400 | } |
| 5401 | break; |
| 5402 | |
| 5403 | default: |
| 5404 | WL_ERROR(("wlc_cck_plcp_set: unsupported rate %d\n", rate_500)); |
| 5405 | rate_500 = WLC_RATE_1M; |
| 5406 | usec = length << 3; |
| 5407 | break; |
| 5408 | } |
| 5409 | /* PLCP signal byte */ |
| 5410 | plcp[0] = rate_500 * 5; /* r (500kbps) * 5 == r (100kbps) */ |
| 5411 | /* PLCP service byte */ |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 5412 | plcp[1] = (u8) (le | D11B_PLCP_SIGNAL_LOCKED); |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 5413 | /* PLCP length u16, little endian */ |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5414 | plcp[2] = usec & 0xff; |
| 5415 | plcp[3] = (usec >> 8) & 0xff; |
| 5416 | /* PLCP CRC16 */ |
| 5417 | plcp[4] = 0; |
| 5418 | plcp[5] = 0; |
| 5419 | } |
| 5420 | |
| 5421 | /* Rate: 802.11 rate code, length: PSDU length in octets */ |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 5422 | static void wlc_compute_cck_plcp(ratespec_t rspec, uint length, u8 *plcp) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5423 | { |
| 5424 | int rate = RSPEC2RATE(rspec); |
| 5425 | |
| 5426 | ASSERT(IS_CCK(rspec)); |
| 5427 | |
| 5428 | wlc_cck_plcp_set(rate, length, plcp); |
| 5429 | } |
| 5430 | |
| 5431 | /* wlc_compute_frame_dur() |
| 5432 | * |
| 5433 | * Calculate the 802.11 MAC header DUR field for MPDU |
| 5434 | * DUR for a single frame = 1 SIFS + 1 ACK |
| 5435 | * DUR for a frame with following frags = 3 SIFS + 2 ACK + next frag time |
| 5436 | * |
| 5437 | * rate MPDU rate in unit of 500kbps |
| 5438 | * next_frag_len next MPDU length in bytes |
| 5439 | * preamble_type use short/GF or long/MM PLCP header |
| 5440 | */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 5441 | static u16 BCMFASTPATH |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 5442 | wlc_compute_frame_dur(wlc_info_t *wlc, ratespec_t rate, u8 preamble_type, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5443 | uint next_frag_len) |
| 5444 | { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 5445 | u16 dur, sifs; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5446 | |
| 5447 | sifs = SIFS(wlc->band); |
| 5448 | |
| 5449 | dur = sifs; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 5450 | dur += (u16) wlc_calc_ack_time(wlc, rate, preamble_type); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5451 | |
| 5452 | if (next_frag_len) { |
| 5453 | /* Double the current DUR to get 2 SIFS + 2 ACKs */ |
| 5454 | dur *= 2; |
| 5455 | /* add another SIFS and the frag time */ |
| 5456 | dur += sifs; |
| 5457 | dur += |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 5458 | (u16) wlc_calc_frame_time(wlc, rate, preamble_type, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5459 | next_frag_len); |
| 5460 | } |
Jason Cooper | 90ea229 | 2010-09-14 09:45:32 -0400 | [diff] [blame] | 5461 | return dur; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5462 | } |
| 5463 | |
| 5464 | /* wlc_compute_rtscts_dur() |
| 5465 | * |
| 5466 | * Calculate the 802.11 MAC header DUR field for an RTS or CTS frame |
| 5467 | * DUR for normal RTS/CTS w/ frame = 3 SIFS + 1 CTS + next frame time + 1 ACK |
| 5468 | * DUR for CTS-TO-SELF w/ frame = 2 SIFS + next frame time + 1 ACK |
| 5469 | * |
| 5470 | * cts cts-to-self or rts/cts |
| 5471 | * rts_rate rts or cts rate in unit of 500kbps |
| 5472 | * rate next MPDU rate in unit of 500kbps |
| 5473 | * frame_len next MPDU frame length in bytes |
| 5474 | */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 5475 | u16 BCMFASTPATH |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 5476 | wlc_compute_rtscts_dur(wlc_info_t *wlc, bool cts_only, ratespec_t rts_rate, |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 5477 | ratespec_t frame_rate, u8 rts_preamble_type, |
| 5478 | u8 frame_preamble_type, uint frame_len, bool ba) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5479 | { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 5480 | u16 dur, sifs; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5481 | |
| 5482 | sifs = SIFS(wlc->band); |
| 5483 | |
| 5484 | if (!cts_only) { /* RTS/CTS */ |
| 5485 | dur = 3 * sifs; |
| 5486 | dur += |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 5487 | (u16) wlc_calc_cts_time(wlc, rts_rate, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5488 | rts_preamble_type); |
| 5489 | } else { /* CTS-TO-SELF */ |
| 5490 | dur = 2 * sifs; |
| 5491 | } |
| 5492 | |
| 5493 | dur += |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 5494 | (u16) wlc_calc_frame_time(wlc, frame_rate, frame_preamble_type, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5495 | frame_len); |
| 5496 | if (ba) |
| 5497 | dur += |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 5498 | (u16) wlc_calc_ba_time(wlc, frame_rate, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5499 | WLC_SHORT_PREAMBLE); |
| 5500 | else |
| 5501 | dur += |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 5502 | (u16) wlc_calc_ack_time(wlc, frame_rate, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5503 | frame_preamble_type); |
Jason Cooper | 90ea229 | 2010-09-14 09:45:32 -0400 | [diff] [blame] | 5504 | return dur; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5505 | } |
| 5506 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 5507 | static bool wlc_phy_rspec_check(wlc_info_t *wlc, u16 bw, ratespec_t rspec) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5508 | { |
| 5509 | if (IS_MCS(rspec)) { |
| 5510 | uint mcs = rspec & RSPEC_RATE_MASK; |
| 5511 | |
| 5512 | if (mcs < 8) { |
| 5513 | ASSERT(RSPEC_STF(rspec) < PHY_TXC1_MODE_SDM); |
| 5514 | } else if ((mcs >= 8) && (mcs <= 23)) { |
| 5515 | ASSERT(RSPEC_STF(rspec) == PHY_TXC1_MODE_SDM); |
| 5516 | } else if (mcs == 32) { |
| 5517 | ASSERT(RSPEC_STF(rspec) < PHY_TXC1_MODE_SDM); |
| 5518 | ASSERT(bw == PHY_TXC1_BW_40MHZ_DUP); |
| 5519 | } |
| 5520 | } else if (IS_OFDM(rspec)) { |
| 5521 | ASSERT(RSPEC_STF(rspec) < PHY_TXC1_MODE_STBC); |
| 5522 | } else { |
| 5523 | ASSERT(IS_CCK(rspec)); |
| 5524 | |
| 5525 | ASSERT((bw == PHY_TXC1_BW_20MHZ) |
| 5526 | || (bw == PHY_TXC1_BW_20MHZ_UP)); |
| 5527 | ASSERT(RSPEC_STF(rspec) == PHY_TXC1_MODE_SISO); |
| 5528 | } |
| 5529 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5530 | return true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5531 | } |
| 5532 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 5533 | u16 BCMFASTPATH wlc_phytxctl1_calc(wlc_info_t *wlc, ratespec_t rspec) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5534 | { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 5535 | u16 phyctl1 = 0; |
| 5536 | u16 bw; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5537 | |
| 5538 | if (WLCISLCNPHY(wlc->band)) { |
| 5539 | bw = PHY_TXC1_BW_20MHZ; |
| 5540 | } else { |
| 5541 | bw = RSPEC_GET_BW(rspec); |
| 5542 | /* 10Mhz is not supported yet */ |
| 5543 | if (bw < PHY_TXC1_BW_20MHZ) { |
| 5544 | WL_ERROR(("wlc_phytxctl1_calc: bw %d is not supported yet, set to 20L\n", bw)); |
| 5545 | bw = PHY_TXC1_BW_20MHZ; |
| 5546 | } |
| 5547 | |
| 5548 | wlc_phy_rspec_check(wlc, bw, rspec); |
| 5549 | } |
| 5550 | |
| 5551 | if (IS_MCS(rspec)) { |
| 5552 | uint mcs = rspec & RSPEC_RATE_MASK; |
| 5553 | |
| 5554 | /* bw, stf, coding-type is part of RSPEC_PHYTXBYTE2 returns */ |
| 5555 | phyctl1 = RSPEC_PHYTXBYTE2(rspec); |
| 5556 | /* set the upper byte of phyctl1 */ |
| 5557 | phyctl1 |= (mcs_table[mcs].tx_phy_ctl3 << 8); |
| 5558 | } else if (IS_CCK(rspec) && !WLCISLCNPHY(wlc->band) |
| 5559 | && !WLCISSSLPNPHY(wlc->band)) { |
| 5560 | /* In CCK mode LPPHY overloads OFDM Modulation bits with CCK Data Rate */ |
| 5561 | /* Eventually MIMOPHY would also be converted to this format */ |
| 5562 | /* 0 = 1Mbps; 1 = 2Mbps; 2 = 5.5Mbps; 3 = 11Mbps */ |
| 5563 | phyctl1 = (bw | (RSPEC_STF(rspec) << PHY_TXC1_MODE_SHIFT)); |
| 5564 | } else { /* legacy OFDM/CCK */ |
Greg Kroah-Hartman | e59fe08 | 2010-10-07 17:08:21 -0700 | [diff] [blame] | 5565 | s16 phycfg; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5566 | /* get the phyctl byte from rate phycfg table */ |
Jason Cooper | ca8c1e5 | 2010-09-14 09:45:33 -0400 | [diff] [blame] | 5567 | phycfg = wlc_rate_legacy_phyctl(RSPEC2RATE(rspec)); |
| 5568 | if (phycfg == -1) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5569 | WL_ERROR(("wlc_phytxctl1_calc: wrong legacy OFDM/CCK rate\n")); |
| 5570 | ASSERT(0); |
| 5571 | phycfg = 0; |
| 5572 | } |
| 5573 | /* set the upper byte of phyctl1 */ |
| 5574 | phyctl1 = |
| 5575 | (bw | (phycfg << 8) | |
| 5576 | (RSPEC_STF(rspec) << PHY_TXC1_MODE_SHIFT)); |
| 5577 | } |
| 5578 | |
| 5579 | #ifdef BCMDBG |
| 5580 | /* phy clock must support 40Mhz if tx descriptor uses it */ |
| 5581 | if ((phyctl1 & PHY_TXC1_BW_MASK) >= PHY_TXC1_BW_40MHZ) { |
| 5582 | ASSERT(CHSPEC_WLC_BW(wlc->chanspec) == WLC_40_MHZ); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5583 | ASSERT(wlc->chanspec == wlc_phy_chanspec_get(wlc->band->pi)); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5584 | } |
| 5585 | #endif /* BCMDBG */ |
| 5586 | return phyctl1; |
| 5587 | } |
| 5588 | |
| 5589 | ratespec_t BCMFASTPATH |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 5590 | wlc_rspec_to_rts_rspec(wlc_info_t *wlc, ratespec_t rspec, bool use_rspec, |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 5591 | u16 mimo_ctlchbw) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5592 | { |
| 5593 | ratespec_t rts_rspec = 0; |
| 5594 | |
| 5595 | if (use_rspec) { |
| 5596 | /* use frame rate as rts rate */ |
| 5597 | rts_rspec = rspec; |
| 5598 | |
| 5599 | } else if (wlc->band->gmode && wlc->protection->_g && !IS_CCK(rspec)) { |
| 5600 | /* Use 11Mbps as the g protection RTS target rate and fallback. |
| 5601 | * Use the WLC_BASIC_RATE() lookup to find the best basic rate under the |
| 5602 | * target in case 11 Mbps is not Basic. |
| 5603 | * 6 and 9 Mbps are not usually selected by rate selection, but even |
| 5604 | * if the OFDM rate we are protecting is 6 or 9 Mbps, 11 is more robust. |
| 5605 | */ |
| 5606 | rts_rspec = WLC_BASIC_RATE(wlc, WLC_RATE_11M); |
| 5607 | } else { |
| 5608 | /* calculate RTS rate and fallback rate based on the frame rate |
| 5609 | * RTS must be sent at a basic rate since it is a |
| 5610 | * control frame, sec 9.6 of 802.11 spec |
| 5611 | */ |
| 5612 | rts_rspec = WLC_BASIC_RATE(wlc, rspec); |
| 5613 | } |
| 5614 | |
| 5615 | if (WLC_PHY_11N_CAP(wlc->band)) { |
| 5616 | /* set rts txbw to correct side band */ |
| 5617 | rts_rspec &= ~RSPEC_BW_MASK; |
| 5618 | |
| 5619 | /* if rspec/rspec_fallback is 40MHz, then send RTS on both 20MHz channel |
| 5620 | * (DUP), otherwise send RTS on control channel |
| 5621 | */ |
| 5622 | if (RSPEC_IS40MHZ(rspec) && !IS_CCK(rts_rspec)) |
| 5623 | rts_rspec |= (PHY_TXC1_BW_40MHZ_DUP << RSPEC_BW_SHIFT); |
| 5624 | else |
| 5625 | rts_rspec |= (mimo_ctlchbw << RSPEC_BW_SHIFT); |
| 5626 | |
| 5627 | /* pick siso/cdd as default for ofdm */ |
| 5628 | if (IS_OFDM(rts_rspec)) { |
| 5629 | rts_rspec &= ~RSPEC_STF_MASK; |
| 5630 | rts_rspec |= (wlc->stf->ss_opmode << RSPEC_STF_SHIFT); |
| 5631 | } |
| 5632 | } |
| 5633 | return rts_rspec; |
| 5634 | } |
| 5635 | |
| 5636 | /* |
| 5637 | * Add d11txh_t, cck_phy_hdr_t. |
| 5638 | * |
| 5639 | * 'p' data must start with 802.11 MAC header |
| 5640 | * 'p' must allow enough bytes of local headers to be "pushed" onto the packet |
| 5641 | * |
| 5642 | * headroom == D11_PHY_HDR_LEN + D11_TXH_LEN (D11_TXH_LEN is now 104 bytes) |
| 5643 | * |
| 5644 | */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 5645 | static u16 BCMFASTPATH |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 5646 | wlc_d11hdrs_mac80211(wlc_info_t *wlc, struct ieee80211_hw *hw, |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 5647 | struct sk_buff *p, struct scb *scb, uint frag, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5648 | uint nfrags, uint queue, uint next_frag_len, |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 5649 | wsec_key_t *key, ratespec_t rspec_override) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5650 | { |
| 5651 | struct dot11_header *h; |
| 5652 | d11txh_t *txh; |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 5653 | u8 *plcp, plcp_fallback[D11_PHY_HDR_LEN]; |
Brett Rudley | e69284f | 2010-11-16 15:45:48 -0800 | [diff] [blame] | 5654 | struct osl_info *osh; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5655 | int len, phylen, rts_phylen; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 5656 | u16 fc, type, frameid, mch, phyctl, xfts, mainrates; |
| 5657 | u16 seq = 0, mcl = 0, status = 0; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5658 | ratespec_t rspec[2] = { WLC_RATE_1M, WLC_RATE_1M }, rts_rspec[2] = { |
| 5659 | WLC_RATE_1M, WLC_RATE_1M}; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5660 | bool use_rts = false; |
| 5661 | bool use_cts = false; |
| 5662 | bool use_rifs = false; |
| 5663 | bool short_preamble[2] = { false, false }; |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 5664 | u8 preamble_type[2] = { WLC_LONG_PREAMBLE, WLC_LONG_PREAMBLE }; |
| 5665 | u8 rts_preamble_type[2] = { WLC_LONG_PREAMBLE, WLC_LONG_PREAMBLE }; |
| 5666 | u8 *rts_plcp, rts_plcp_fallback[D11_PHY_HDR_LEN]; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5667 | struct dot11_rts_frame *rts = NULL; |
| 5668 | bool qos; |
| 5669 | uint ac; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 5670 | u32 rate_val[2]; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5671 | bool hwtkmic = false; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 5672 | u16 mimo_ctlchbw = PHY_TXC1_BW_20MHZ; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5673 | #ifdef WLANTSEL |
| 5674 | #define ANTCFG_NONE 0xFF |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 5675 | u8 antcfg = ANTCFG_NONE; |
| 5676 | u8 fbantcfg = ANTCFG_NONE; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5677 | #endif |
| 5678 | uint phyctl1_stf = 0; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 5679 | u16 durid = 0; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5680 | struct ieee80211_tx_rate *txrate[2]; |
| 5681 | int k; |
| 5682 | struct ieee80211_tx_info *tx_info; |
| 5683 | bool is_mcs[2]; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 5684 | u16 mimo_txbw; |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 5685 | u8 mimo_preamble_type; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5686 | |
| 5687 | frameid = 0; |
| 5688 | |
| 5689 | ASSERT(queue < NFIFO); |
| 5690 | |
| 5691 | osh = wlc->osh; |
| 5692 | |
| 5693 | /* locate 802.11 MAC header */ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 5694 | h = (struct dot11_header *)(p->data); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5695 | fc = ltoh16(h->fc); |
| 5696 | type = FC_TYPE(fc); |
| 5697 | |
| 5698 | qos = (type == FC_TYPE_DATA && FC_SUBTYPE_ANY_QOS(FC_SUBTYPE(fc))); |
| 5699 | |
| 5700 | /* compute length of frame in bytes for use in PLCP computations */ |
| 5701 | len = pkttotlen(osh, p); |
| 5702 | phylen = len + DOT11_FCS_LEN; |
| 5703 | |
| 5704 | /* If WEP enabled, add room in phylen for the additional bytes of |
| 5705 | * ICV which MAC generates. We do NOT add the additional bytes to |
| 5706 | * the packet itself, thus phylen = packet length + ICV_LEN + FCS_LEN |
| 5707 | * in this case |
| 5708 | */ |
| 5709 | if (key) { |
| 5710 | phylen += key->icv_len; |
| 5711 | } |
| 5712 | |
| 5713 | /* Get tx_info */ |
| 5714 | tx_info = IEEE80211_SKB_CB(p); |
| 5715 | ASSERT(tx_info); |
| 5716 | |
| 5717 | /* add PLCP */ |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 5718 | plcp = skb_push(p, D11_PHY_HDR_LEN); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5719 | |
| 5720 | /* add Broadcom tx descriptor header */ |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 5721 | txh = (d11txh_t *) skb_push(p, D11_TXH_LEN); |
Brett Rudley | 9249ede | 2010-11-30 20:09:49 -0800 | [diff] [blame^] | 5722 | memset((char *)txh, 0, D11_TXH_LEN); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5723 | |
| 5724 | /* setup frameid */ |
| 5725 | if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) { |
| 5726 | /* non-AP STA should never use BCMC queue */ |
| 5727 | ASSERT(queue != TX_BCMC_FIFO); |
| 5728 | if (queue == TX_BCMC_FIFO) { |
| 5729 | WL_ERROR(("wl%d: %s: ASSERT queue == TX_BCMC!\n", |
| 5730 | WLCWLUNIT(wlc), __func__)); |
| 5731 | frameid = bcmc_fid_generate(wlc, NULL, txh); |
| 5732 | } else { |
| 5733 | /* Increment the counter for first fragment */ |
| 5734 | if (tx_info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT) { |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 5735 | SCB_SEQNUM(scb, p->priority)++; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5736 | } |
| 5737 | |
| 5738 | /* extract fragment number from frame first */ |
| 5739 | seq = ltoh16(seq) & FRAGNUM_MASK; |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 5740 | seq |= (SCB_SEQNUM(scb, p->priority) << SEQNUM_SHIFT); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5741 | h->seq = htol16(seq); |
| 5742 | |
| 5743 | frameid = ((seq << TXFID_SEQ_SHIFT) & TXFID_SEQ_MASK) | |
| 5744 | (queue & TXFID_QUEUE_MASK); |
| 5745 | } |
| 5746 | } |
| 5747 | frameid |= queue & TXFID_QUEUE_MASK; |
| 5748 | |
| 5749 | /* set the ignpmq bit for all pkts tx'd in PS mode and for beacons */ |
| 5750 | if (SCB_PS(scb) || ((fc & FC_KIND_MASK) == FC_BEACON)) |
| 5751 | mcl |= TXC_IGNOREPMQ; |
| 5752 | |
| 5753 | ASSERT(hw->max_rates <= IEEE80211_TX_MAX_RATES); |
| 5754 | ASSERT(hw->max_rates == 2); |
| 5755 | |
| 5756 | txrate[0] = tx_info->control.rates; |
| 5757 | txrate[1] = txrate[0] + 1; |
| 5758 | |
| 5759 | ASSERT(txrate[0]->idx >= 0); |
| 5760 | /* if rate control algorithm didn't give us a fallback rate, use the primary rate */ |
| 5761 | if (txrate[1]->idx < 0) { |
| 5762 | txrate[1] = txrate[0]; |
| 5763 | } |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5764 | |
| 5765 | for (k = 0; k < hw->max_rates; k++) { |
| 5766 | is_mcs[k] = |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5767 | txrate[k]->flags & IEEE80211_TX_RC_MCS ? true : false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5768 | if (!is_mcs[k]) { |
| 5769 | ASSERT(!(tx_info->flags & IEEE80211_TX_CTL_AMPDU)); |
| 5770 | if ((txrate[k]->idx >= 0) |
| 5771 | && (txrate[k]->idx < |
| 5772 | hw->wiphy->bands[tx_info->band]->n_bitrates)) { |
| 5773 | rate_val[k] = |
| 5774 | hw->wiphy->bands[tx_info->band]-> |
| 5775 | bitrates[txrate[k]->idx].hw_value; |
| 5776 | short_preamble[k] = |
| 5777 | txrate[k]-> |
| 5778 | flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE ? |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5779 | true : false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5780 | } else { |
| 5781 | ASSERT((txrate[k]->idx >= 0) && |
| 5782 | (txrate[k]->idx < |
| 5783 | hw->wiphy->bands[tx_info->band]-> |
| 5784 | n_bitrates)); |
| 5785 | rate_val[k] = WLC_RATE_1M; |
| 5786 | } |
| 5787 | } else { |
| 5788 | rate_val[k] = txrate[k]->idx; |
| 5789 | } |
| 5790 | /* Currently only support same setting for primay and fallback rates. |
| 5791 | * Unify flags for each rate into a single value for the frame |
| 5792 | */ |
| 5793 | use_rts |= |
| 5794 | txrate[k]-> |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5795 | flags & IEEE80211_TX_RC_USE_RTS_CTS ? true : false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5796 | use_cts |= |
| 5797 | txrate[k]-> |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5798 | flags & IEEE80211_TX_RC_USE_CTS_PROTECT ? true : false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5799 | |
| 5800 | if (is_mcs[k]) |
| 5801 | rate_val[k] |= NRATE_MCS_INUSE; |
| 5802 | |
| 5803 | rspec[k] = mac80211_wlc_set_nrate(wlc, wlc->band, rate_val[k]); |
| 5804 | |
| 5805 | /* (1) RATE: determine and validate primary rate and fallback rates */ |
| 5806 | if (!RSPEC_ACTIVE(rspec[k])) { |
| 5807 | ASSERT(RSPEC_ACTIVE(rspec[k])); |
| 5808 | rspec[k] = WLC_RATE_1M; |
| 5809 | } else { |
| 5810 | if (WLANTSEL_ENAB(wlc) && !ETHER_ISMULTI(&h->a1)) { |
| 5811 | /* set tx antenna config */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5812 | wlc_antsel_antcfg_get(wlc->asi, false, false, 0, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5813 | 0, &antcfg, &fbantcfg); |
| 5814 | } |
| 5815 | } |
| 5816 | } |
| 5817 | |
| 5818 | phyctl1_stf = wlc->stf->ss_opmode; |
| 5819 | |
| 5820 | if (N_ENAB(wlc->pub)) { |
| 5821 | for (k = 0; k < hw->max_rates; k++) { |
| 5822 | /* apply siso/cdd to single stream mcs's or ofdm if rspec is auto selected */ |
| 5823 | if (((IS_MCS(rspec[k]) && |
| 5824 | IS_SINGLE_STREAM(rspec[k] & RSPEC_RATE_MASK)) || |
| 5825 | IS_OFDM(rspec[k])) |
| 5826 | && ((rspec[k] & RSPEC_OVERRIDE_MCS_ONLY) |
| 5827 | || !(rspec[k] & RSPEC_OVERRIDE))) { |
| 5828 | rspec[k] &= ~(RSPEC_STF_MASK | RSPEC_STC_MASK); |
| 5829 | |
| 5830 | /* For SISO MCS use STBC if possible */ |
| 5831 | if (IS_MCS(rspec[k]) |
| 5832 | && WLC_STF_SS_STBC_TX(wlc, scb)) { |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 5833 | u8 stc; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5834 | |
| 5835 | ASSERT(WLC_STBC_CAP_PHY(wlc)); |
| 5836 | stc = 1; /* Nss for single stream is always 1 */ |
| 5837 | rspec[k] |= |
| 5838 | (PHY_TXC1_MODE_STBC << |
| 5839 | RSPEC_STF_SHIFT) | (stc << |
| 5840 | RSPEC_STC_SHIFT); |
| 5841 | } else |
| 5842 | rspec[k] |= |
| 5843 | (phyctl1_stf << RSPEC_STF_SHIFT); |
| 5844 | } |
| 5845 | |
| 5846 | /* Is the phy configured to use 40MHZ frames? If so then pick the desired txbw */ |
| 5847 | if (CHSPEC_WLC_BW(wlc->chanspec) == WLC_40_MHZ) { |
| 5848 | /* default txbw is 20in40 SB */ |
| 5849 | mimo_ctlchbw = mimo_txbw = |
| 5850 | CHSPEC_SB_UPPER(WLC_BAND_PI_RADIO_CHANSPEC) |
| 5851 | ? PHY_TXC1_BW_20MHZ_UP : PHY_TXC1_BW_20MHZ; |
| 5852 | |
| 5853 | if (IS_MCS(rspec[k])) { |
| 5854 | /* mcs 32 must be 40b/w DUP */ |
| 5855 | if ((rspec[k] & RSPEC_RATE_MASK) == 32) { |
| 5856 | mimo_txbw = |
| 5857 | PHY_TXC1_BW_40MHZ_DUP; |
| 5858 | /* use override */ |
| 5859 | } else if (wlc->mimo_40txbw != AUTO) |
| 5860 | mimo_txbw = wlc->mimo_40txbw; |
| 5861 | /* else check if dst is using 40 Mhz */ |
| 5862 | else if (scb->flags & SCB_IS40) |
| 5863 | mimo_txbw = PHY_TXC1_BW_40MHZ; |
| 5864 | } else if (IS_OFDM(rspec[k])) { |
| 5865 | if (wlc->ofdm_40txbw != AUTO) |
| 5866 | mimo_txbw = wlc->ofdm_40txbw; |
| 5867 | } else { |
| 5868 | ASSERT(IS_CCK(rspec[k])); |
| 5869 | if (wlc->cck_40txbw != AUTO) |
| 5870 | mimo_txbw = wlc->cck_40txbw; |
| 5871 | } |
| 5872 | } else { |
| 5873 | /* mcs32 is 40 b/w only. |
| 5874 | * This is possible for probe packets on a STA during SCAN |
| 5875 | */ |
| 5876 | if ((rspec[k] & RSPEC_RATE_MASK) == 32) { |
| 5877 | /* mcs 0 */ |
| 5878 | rspec[k] = RSPEC_MIMORATE; |
| 5879 | } |
| 5880 | mimo_txbw = PHY_TXC1_BW_20MHZ; |
| 5881 | } |
| 5882 | |
| 5883 | /* Set channel width */ |
| 5884 | rspec[k] &= ~RSPEC_BW_MASK; |
| 5885 | if ((k == 0) || ((k > 0) && IS_MCS(rspec[k]))) |
| 5886 | rspec[k] |= (mimo_txbw << RSPEC_BW_SHIFT); |
| 5887 | else |
| 5888 | rspec[k] |= (mimo_ctlchbw << RSPEC_BW_SHIFT); |
| 5889 | |
| 5890 | /* Set Short GI */ |
| 5891 | #ifdef NOSGIYET |
| 5892 | if (IS_MCS(rspec[k]) |
| 5893 | && (txrate[k]->flags & IEEE80211_TX_RC_SHORT_GI)) |
| 5894 | rspec[k] |= RSPEC_SHORT_GI; |
| 5895 | else if (!(txrate[k]->flags & IEEE80211_TX_RC_SHORT_GI)) |
| 5896 | rspec[k] &= ~RSPEC_SHORT_GI; |
| 5897 | #else |
| 5898 | rspec[k] &= ~RSPEC_SHORT_GI; |
| 5899 | #endif |
| 5900 | |
| 5901 | mimo_preamble_type = WLC_MM_PREAMBLE; |
| 5902 | if (txrate[k]->flags & IEEE80211_TX_RC_GREEN_FIELD) |
| 5903 | mimo_preamble_type = WLC_GF_PREAMBLE; |
| 5904 | |
| 5905 | if ((txrate[k]->flags & IEEE80211_TX_RC_MCS) |
| 5906 | && (!IS_MCS(rspec[k]))) { |
| 5907 | WL_ERROR(("wl%d: %s: IEEE80211_TX_RC_MCS != IS_MCS(rspec)\n", WLCWLUNIT(wlc), __func__)); |
| 5908 | ASSERT(0 && "Rate mismatch"); |
| 5909 | } |
| 5910 | |
| 5911 | if (IS_MCS(rspec[k])) { |
| 5912 | preamble_type[k] = mimo_preamble_type; |
| 5913 | |
| 5914 | /* if SGI is selected, then forced mm for single stream */ |
| 5915 | if ((rspec[k] & RSPEC_SHORT_GI) |
| 5916 | && IS_SINGLE_STREAM(rspec[k] & |
| 5917 | RSPEC_RATE_MASK)) { |
| 5918 | preamble_type[k] = WLC_MM_PREAMBLE; |
| 5919 | } |
| 5920 | } |
| 5921 | |
| 5922 | /* mimo bw field MUST now be valid in the rspec (it affects duration calculations) */ |
| 5923 | ASSERT(VALID_RATE_DBG(wlc, rspec[0])); |
| 5924 | |
| 5925 | /* should be better conditionalized */ |
| 5926 | if (!IS_MCS(rspec[0]) |
| 5927 | && (tx_info->control.rates[0]. |
| 5928 | flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)) |
| 5929 | preamble_type[k] = WLC_SHORT_PREAMBLE; |
| 5930 | |
| 5931 | ASSERT(!IS_MCS(rspec[0]) |
| 5932 | || WLC_IS_MIMO_PREAMBLE(preamble_type[k])); |
| 5933 | } |
| 5934 | } else { |
| 5935 | for (k = 0; k < hw->max_rates; k++) { |
| 5936 | /* Set ctrlchbw as 20Mhz */ |
| 5937 | ASSERT(!IS_MCS(rspec[k])); |
| 5938 | rspec[k] &= ~RSPEC_BW_MASK; |
| 5939 | rspec[k] |= (PHY_TXC1_BW_20MHZ << RSPEC_BW_SHIFT); |
| 5940 | |
| 5941 | /* for nphy, stf of ofdm frames must follow policies */ |
| 5942 | if (WLCISNPHY(wlc->band) && IS_OFDM(rspec[k])) { |
| 5943 | rspec[k] &= ~RSPEC_STF_MASK; |
| 5944 | rspec[k] |= phyctl1_stf << RSPEC_STF_SHIFT; |
| 5945 | } |
| 5946 | } |
| 5947 | } |
| 5948 | |
| 5949 | /* Reset these for use with AMPDU's */ |
| 5950 | txrate[0]->count = 0; |
| 5951 | txrate[1]->count = 0; |
| 5952 | |
| 5953 | /* (3) PLCP: determine PLCP header and MAC duration, fill d11txh_t */ |
| 5954 | wlc_compute_plcp(wlc, rspec[0], phylen, plcp); |
| 5955 | wlc_compute_plcp(wlc, rspec[1], phylen, plcp_fallback); |
| 5956 | bcopy(plcp_fallback, (char *)&txh->FragPLCPFallback, |
| 5957 | sizeof(txh->FragPLCPFallback)); |
| 5958 | |
| 5959 | /* Length field now put in CCK FBR CRC field */ |
| 5960 | if (IS_CCK(rspec[1])) { |
| 5961 | txh->FragPLCPFallback[4] = phylen & 0xff; |
| 5962 | txh->FragPLCPFallback[5] = (phylen & 0xff00) >> 8; |
| 5963 | } |
| 5964 | |
| 5965 | /* MIMO-RATE: need validation ?? */ |
| 5966 | mainrates = |
| 5967 | IS_OFDM(rspec[0]) ? D11A_PHY_HDR_GRATE((ofdm_phy_hdr_t *) plcp) : |
| 5968 | plcp[0]; |
| 5969 | |
| 5970 | /* DUR field for main rate */ |
| 5971 | if ((fc != FC_PS_POLL) && !ETHER_ISMULTI(&h->a1) && !use_rifs) { |
| 5972 | durid = |
| 5973 | wlc_compute_frame_dur(wlc, rspec[0], preamble_type[0], |
| 5974 | next_frag_len); |
| 5975 | h->durid = htol16(durid); |
| 5976 | } else if (use_rifs) { |
| 5977 | /* NAV protect to end of next max packet size */ |
| 5978 | durid = |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 5979 | (u16) wlc_calc_frame_time(wlc, rspec[0], |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 5980 | preamble_type[0], |
| 5981 | DOT11_MAX_FRAG_LEN); |
| 5982 | durid += RIFS_11N_TIME; |
| 5983 | h->durid = htol16(durid); |
| 5984 | } |
| 5985 | |
| 5986 | /* DUR field for fallback rate */ |
| 5987 | if (fc == FC_PS_POLL) |
| 5988 | txh->FragDurFallback = h->durid; |
| 5989 | else if (ETHER_ISMULTI(&h->a1) || use_rifs) |
| 5990 | txh->FragDurFallback = 0; |
| 5991 | else { |
| 5992 | durid = wlc_compute_frame_dur(wlc, rspec[1], |
| 5993 | preamble_type[1], next_frag_len); |
| 5994 | txh->FragDurFallback = htol16(durid); |
| 5995 | } |
| 5996 | |
| 5997 | /* (4) MAC-HDR: MacTxControlLow */ |
| 5998 | if (frag == 0) |
| 5999 | mcl |= TXC_STARTMSDU; |
| 6000 | |
| 6001 | if (!ETHER_ISMULTI(&h->a1)) |
| 6002 | mcl |= TXC_IMMEDACK; |
| 6003 | |
| 6004 | if (BAND_5G(wlc->band->bandtype)) |
| 6005 | mcl |= TXC_FREQBAND_5G; |
| 6006 | |
| 6007 | if (CHSPEC_IS40(WLC_BAND_PI_RADIO_CHANSPEC)) |
| 6008 | mcl |= TXC_BW_40; |
| 6009 | |
| 6010 | /* set AMIC bit if using hardware TKIP MIC */ |
| 6011 | if (hwtkmic) |
| 6012 | mcl |= TXC_AMIC; |
| 6013 | |
| 6014 | txh->MacTxControlLow = htol16(mcl); |
| 6015 | |
| 6016 | /* MacTxControlHigh */ |
| 6017 | mch = 0; |
| 6018 | |
| 6019 | /* Set fallback rate preamble type */ |
| 6020 | if ((preamble_type[1] == WLC_SHORT_PREAMBLE) || |
| 6021 | (preamble_type[1] == WLC_GF_PREAMBLE)) { |
| 6022 | ASSERT((preamble_type[1] == WLC_GF_PREAMBLE) || |
| 6023 | (!IS_MCS(rspec[1]))); |
| 6024 | if (RSPEC2RATE(rspec[1]) != WLC_RATE_1M) |
| 6025 | mch |= TXC_PREAMBLE_DATA_FB_SHORT; |
| 6026 | } |
| 6027 | |
| 6028 | /* MacFrameControl */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 6029 | bcopy((char *)&h->fc, (char *)&txh->MacFrameControl, sizeof(u16)); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6030 | |
| 6031 | txh->TxFesTimeNormal = htol16(0); |
| 6032 | |
| 6033 | txh->TxFesTimeFallback = htol16(0); |
| 6034 | |
| 6035 | /* TxFrameRA */ |
| 6036 | bcopy((char *)&h->a1, (char *)&txh->TxFrameRA, ETHER_ADDR_LEN); |
| 6037 | |
| 6038 | /* TxFrameID */ |
| 6039 | txh->TxFrameID = htol16(frameid); |
| 6040 | |
| 6041 | /* TxStatus, Note the case of recreating the first frag of a suppressed frame |
| 6042 | * then we may need to reset the retry cnt's via the status reg |
| 6043 | */ |
| 6044 | txh->TxStatus = htol16(status); |
| 6045 | |
| 6046 | if (D11REV_GE(wlc->pub->corerev, 16)) { |
| 6047 | /* extra fields for ucode AMPDU aggregation, the new fields are added to |
| 6048 | * the END of previous structure so that it's compatible in driver. |
| 6049 | * In old rev ucode, these fields should be ignored |
| 6050 | */ |
| 6051 | txh->MaxNMpdus = htol16(0); |
| 6052 | txh->MaxABytes_MRT = htol16(0); |
| 6053 | txh->MaxABytes_FBR = htol16(0); |
| 6054 | txh->MinMBytes = htol16(0); |
| 6055 | } |
| 6056 | |
| 6057 | /* (5) RTS/CTS: determine RTS/CTS PLCP header and MAC duration, furnish d11txh_t */ |
| 6058 | /* RTS PLCP header and RTS frame */ |
| 6059 | if (use_rts || use_cts) { |
| 6060 | if (use_rts && use_cts) |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 6061 | use_cts = false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6062 | |
| 6063 | for (k = 0; k < 2; k++) { |
| 6064 | rts_rspec[k] = wlc_rspec_to_rts_rspec(wlc, rspec[k], |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 6065 | false, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6066 | mimo_ctlchbw); |
| 6067 | } |
| 6068 | |
| 6069 | if (!IS_OFDM(rts_rspec[0]) && |
| 6070 | !((RSPEC2RATE(rts_rspec[0]) == WLC_RATE_1M) || |
| 6071 | (wlc->PLCPHdr_override == WLC_PLCP_LONG))) { |
| 6072 | rts_preamble_type[0] = WLC_SHORT_PREAMBLE; |
| 6073 | mch |= TXC_PREAMBLE_RTS_MAIN_SHORT; |
| 6074 | } |
| 6075 | |
| 6076 | if (!IS_OFDM(rts_rspec[1]) && |
| 6077 | !((RSPEC2RATE(rts_rspec[1]) == WLC_RATE_1M) || |
| 6078 | (wlc->PLCPHdr_override == WLC_PLCP_LONG))) { |
| 6079 | rts_preamble_type[1] = WLC_SHORT_PREAMBLE; |
| 6080 | mch |= TXC_PREAMBLE_RTS_FB_SHORT; |
| 6081 | } |
| 6082 | |
| 6083 | /* RTS/CTS additions to MacTxControlLow */ |
| 6084 | if (use_cts) { |
| 6085 | txh->MacTxControlLow |= htol16(TXC_SENDCTS); |
| 6086 | } else { |
| 6087 | txh->MacTxControlLow |= htol16(TXC_SENDRTS); |
| 6088 | txh->MacTxControlLow |= htol16(TXC_LONGFRAME); |
| 6089 | } |
| 6090 | |
| 6091 | /* RTS PLCP header */ |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 6092 | ASSERT(IS_ALIGNED((unsigned long)txh->RTSPhyHeader, sizeof(u16))); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6093 | rts_plcp = txh->RTSPhyHeader; |
| 6094 | if (use_cts) |
| 6095 | rts_phylen = DOT11_CTS_LEN + DOT11_FCS_LEN; |
| 6096 | else |
| 6097 | rts_phylen = DOT11_RTS_LEN + DOT11_FCS_LEN; |
| 6098 | |
| 6099 | wlc_compute_plcp(wlc, rts_rspec[0], rts_phylen, rts_plcp); |
| 6100 | |
| 6101 | /* fallback rate version of RTS PLCP header */ |
| 6102 | wlc_compute_plcp(wlc, rts_rspec[1], rts_phylen, |
| 6103 | rts_plcp_fallback); |
| 6104 | bcopy(rts_plcp_fallback, (char *)&txh->RTSPLCPFallback, |
| 6105 | sizeof(txh->RTSPLCPFallback)); |
| 6106 | |
| 6107 | /* RTS frame fields... */ |
| 6108 | rts = (struct dot11_rts_frame *)&txh->rts_frame; |
| 6109 | |
| 6110 | durid = wlc_compute_rtscts_dur(wlc, use_cts, rts_rspec[0], |
| 6111 | rspec[0], rts_preamble_type[0], |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 6112 | preamble_type[0], phylen, false); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6113 | rts->durid = htol16(durid); |
| 6114 | /* fallback rate version of RTS DUR field */ |
| 6115 | durid = wlc_compute_rtscts_dur(wlc, use_cts, |
| 6116 | rts_rspec[1], rspec[1], |
| 6117 | rts_preamble_type[1], |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 6118 | preamble_type[1], phylen, false); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6119 | txh->RTSDurFallback = htol16(durid); |
| 6120 | |
| 6121 | if (use_cts) { |
| 6122 | rts->fc = htol16(FC_CTS); |
| 6123 | bcopy((char *)&h->a2, (char *)&rts->ra, ETHER_ADDR_LEN); |
| 6124 | } else { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 6125 | rts->fc = htol16((u16) FC_RTS); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6126 | bcopy((char *)&h->a1, (char *)&rts->ra, |
| 6127 | 2 * ETHER_ADDR_LEN); |
| 6128 | } |
| 6129 | |
| 6130 | /* mainrate |
| 6131 | * low 8 bits: main frag rate/mcs, |
| 6132 | * high 8 bits: rts/cts rate/mcs |
| 6133 | */ |
| 6134 | mainrates |= (IS_OFDM(rts_rspec[0]) ? |
| 6135 | D11A_PHY_HDR_GRATE((ofdm_phy_hdr_t *) rts_plcp) : |
| 6136 | rts_plcp[0]) << 8; |
| 6137 | } else { |
Brett Rudley | 9249ede | 2010-11-30 20:09:49 -0800 | [diff] [blame^] | 6138 | memset((char *)txh->RTSPhyHeader, 0, D11_PHY_HDR_LEN); |
| 6139 | memset((char *)&txh->rts_frame, 0, |
| 6140 | sizeof(struct dot11_rts_frame)); |
| 6141 | memset((char *)txh->RTSPLCPFallback, 0, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6142 | sizeof(txh->RTSPLCPFallback)); |
| 6143 | txh->RTSDurFallback = 0; |
| 6144 | } |
| 6145 | |
| 6146 | #ifdef SUPPORT_40MHZ |
| 6147 | /* add null delimiter count */ |
| 6148 | if ((tx_info->flags & IEEE80211_TX_CTL_AMPDU) && IS_MCS(rspec)) { |
| 6149 | txh->RTSPLCPFallback[AMPDU_FBR_NULL_DELIM] = |
| 6150 | wlc_ampdu_null_delim_cnt(wlc->ampdu, scb, rspec, phylen); |
| 6151 | } |
| 6152 | #endif |
| 6153 | |
| 6154 | /* Now that RTS/RTS FB preamble types are updated, write the final value */ |
| 6155 | txh->MacTxControlHigh = htol16(mch); |
| 6156 | |
| 6157 | /* MainRates (both the rts and frag plcp rates have been calculated now) */ |
| 6158 | txh->MainRates = htol16(mainrates); |
| 6159 | |
| 6160 | /* XtraFrameTypes */ |
| 6161 | xfts = FRAMETYPE(rspec[1], wlc->mimoft); |
| 6162 | xfts |= (FRAMETYPE(rts_rspec[0], wlc->mimoft) << XFTS_RTS_FT_SHIFT); |
| 6163 | xfts |= (FRAMETYPE(rts_rspec[1], wlc->mimoft) << XFTS_FBRRTS_FT_SHIFT); |
| 6164 | xfts |= |
| 6165 | CHSPEC_CHANNEL(WLC_BAND_PI_RADIO_CHANSPEC) << XFTS_CHANNEL_SHIFT; |
| 6166 | txh->XtraFrameTypes = htol16(xfts); |
| 6167 | |
| 6168 | /* PhyTxControlWord */ |
| 6169 | phyctl = FRAMETYPE(rspec[0], wlc->mimoft); |
| 6170 | if ((preamble_type[0] == WLC_SHORT_PREAMBLE) || |
| 6171 | (preamble_type[0] == WLC_GF_PREAMBLE)) { |
| 6172 | ASSERT((preamble_type[0] == WLC_GF_PREAMBLE) |
| 6173 | || !IS_MCS(rspec[0])); |
| 6174 | if (RSPEC2RATE(rspec[0]) != WLC_RATE_1M) |
| 6175 | phyctl |= PHY_TXC_SHORT_HDR; |
| 6176 | WLCNTINCR(wlc->pub->_cnt->txprshort); |
| 6177 | } |
| 6178 | |
| 6179 | /* phytxant is properly bit shifted */ |
| 6180 | phyctl |= wlc_stf_d11hdrs_phyctl_txant(wlc, rspec[0]); |
| 6181 | txh->PhyTxControlWord = htol16(phyctl); |
| 6182 | |
| 6183 | /* PhyTxControlWord_1 */ |
| 6184 | if (WLC_PHY_11N_CAP(wlc->band)) { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 6185 | u16 phyctl1 = 0; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6186 | |
| 6187 | phyctl1 = wlc_phytxctl1_calc(wlc, rspec[0]); |
| 6188 | txh->PhyTxControlWord_1 = htol16(phyctl1); |
| 6189 | phyctl1 = wlc_phytxctl1_calc(wlc, rspec[1]); |
| 6190 | txh->PhyTxControlWord_1_Fbr = htol16(phyctl1); |
| 6191 | |
| 6192 | if (use_rts || use_cts) { |
| 6193 | phyctl1 = wlc_phytxctl1_calc(wlc, rts_rspec[0]); |
| 6194 | txh->PhyTxControlWord_1_Rts = htol16(phyctl1); |
| 6195 | phyctl1 = wlc_phytxctl1_calc(wlc, rts_rspec[1]); |
| 6196 | txh->PhyTxControlWord_1_FbrRts = htol16(phyctl1); |
| 6197 | } |
| 6198 | |
| 6199 | /* |
| 6200 | * For mcs frames, if mixedmode(overloaded with long preamble) is going to be set, |
| 6201 | * fill in non-zero MModeLen and/or MModeFbrLen |
| 6202 | * it will be unnecessary if they are separated |
| 6203 | */ |
| 6204 | if (IS_MCS(rspec[0]) && (preamble_type[0] == WLC_MM_PREAMBLE)) { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 6205 | u16 mmodelen = |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6206 | wlc_calc_lsig_len(wlc, rspec[0], phylen); |
| 6207 | txh->MModeLen = htol16(mmodelen); |
| 6208 | } |
| 6209 | |
| 6210 | if (IS_MCS(rspec[1]) && (preamble_type[1] == WLC_MM_PREAMBLE)) { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 6211 | u16 mmodefbrlen = |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6212 | wlc_calc_lsig_len(wlc, rspec[1], phylen); |
| 6213 | txh->MModeFbrLen = htol16(mmodefbrlen); |
| 6214 | } |
| 6215 | } |
| 6216 | |
| 6217 | if (IS_MCS(rspec[0])) |
| 6218 | ASSERT(IS_MCS(rspec[1])); |
| 6219 | |
| 6220 | ASSERT(!IS_MCS(rspec[0]) || |
| 6221 | ((preamble_type[0] == WLC_MM_PREAMBLE) == (txh->MModeLen != 0))); |
| 6222 | ASSERT(!IS_MCS(rspec[1]) || |
| 6223 | ((preamble_type[1] == WLC_MM_PREAMBLE) == |
| 6224 | (txh->MModeFbrLen != 0))); |
| 6225 | |
Jason Cooper | ca8c1e5 | 2010-09-14 09:45:33 -0400 | [diff] [blame] | 6226 | ac = wme_fifo2ac[queue]; |
| 6227 | if (SCB_WME(scb) && qos && wlc->edcf_txop[ac]) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6228 | uint frag_dur, dur, dur_fallback; |
| 6229 | |
| 6230 | ASSERT(!ETHER_ISMULTI(&h->a1)); |
| 6231 | |
| 6232 | /* WME: Update TXOP threshold */ |
| 6233 | if ((!(tx_info->flags & IEEE80211_TX_CTL_AMPDU)) && (frag == 0)) { |
| 6234 | frag_dur = |
| 6235 | wlc_calc_frame_time(wlc, rspec[0], preamble_type[0], |
| 6236 | phylen); |
| 6237 | |
| 6238 | if (rts) { |
| 6239 | /* 1 RTS or CTS-to-self frame */ |
| 6240 | dur = |
| 6241 | wlc_calc_cts_time(wlc, rts_rspec[0], |
| 6242 | rts_preamble_type[0]); |
| 6243 | dur_fallback = |
| 6244 | wlc_calc_cts_time(wlc, rts_rspec[1], |
| 6245 | rts_preamble_type[1]); |
| 6246 | /* (SIFS + CTS) + SIFS + frame + SIFS + ACK */ |
| 6247 | dur += ltoh16(rts->durid); |
| 6248 | dur_fallback += ltoh16(txh->RTSDurFallback); |
| 6249 | } else if (use_rifs) { |
| 6250 | dur = frag_dur; |
| 6251 | dur_fallback = 0; |
| 6252 | } else { |
| 6253 | /* frame + SIFS + ACK */ |
| 6254 | dur = frag_dur; |
| 6255 | dur += |
| 6256 | wlc_compute_frame_dur(wlc, rspec[0], |
| 6257 | preamble_type[0], 0); |
| 6258 | |
| 6259 | dur_fallback = |
| 6260 | wlc_calc_frame_time(wlc, rspec[1], |
| 6261 | preamble_type[1], |
| 6262 | phylen); |
| 6263 | dur_fallback += |
| 6264 | wlc_compute_frame_dur(wlc, rspec[1], |
| 6265 | preamble_type[1], 0); |
| 6266 | } |
| 6267 | /* NEED to set TxFesTimeNormal (hard) */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 6268 | txh->TxFesTimeNormal = htol16((u16) dur); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6269 | /* NEED to set fallback rate version of TxFesTimeNormal (hard) */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 6270 | txh->TxFesTimeFallback = htol16((u16) dur_fallback); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6271 | |
| 6272 | /* update txop byte threshold (txop minus intraframe overhead) */ |
| 6273 | if (wlc->edcf_txop[ac] >= (dur - frag_dur)) { |
| 6274 | { |
| 6275 | uint newfragthresh; |
| 6276 | |
| 6277 | newfragthresh = |
| 6278 | wlc_calc_frame_len(wlc, rspec[0], |
| 6279 | preamble_type[0], |
| 6280 | (wlc-> |
| 6281 | edcf_txop[ac] - |
| 6282 | (dur - |
| 6283 | frag_dur))); |
| 6284 | /* range bound the fragthreshold */ |
| 6285 | if (newfragthresh < DOT11_MIN_FRAG_LEN) |
| 6286 | newfragthresh = |
| 6287 | DOT11_MIN_FRAG_LEN; |
| 6288 | else if (newfragthresh > |
| 6289 | wlc->usr_fragthresh) |
| 6290 | newfragthresh = |
| 6291 | wlc->usr_fragthresh; |
| 6292 | /* update the fragthresh and do txc update */ |
| 6293 | if (wlc->fragthresh[queue] != |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 6294 | (u16) newfragthresh) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6295 | wlc->fragthresh[queue] = |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 6296 | (u16) newfragthresh; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6297 | } |
| 6298 | } |
| 6299 | } else |
| 6300 | WL_ERROR(("wl%d: %s txop invalid for rate %d\n", |
| 6301 | wlc->pub->unit, fifo_names[queue], |
| 6302 | RSPEC2RATE(rspec[0]))); |
| 6303 | |
| 6304 | if (dur > wlc->edcf_txop[ac]) |
| 6305 | WL_ERROR(("wl%d: %s: %s txop exceeded phylen %d/%d dur %d/%d\n", wlc->pub->unit, __func__, fifo_names[queue], phylen, wlc->fragthresh[queue], dur, wlc->edcf_txop[ac])); |
| 6306 | } |
| 6307 | } |
| 6308 | |
| 6309 | return 0; |
| 6310 | } |
| 6311 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 6312 | void wlc_tbtt(wlc_info_t *wlc, d11regs_t *regs) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6313 | { |
| 6314 | wlc_bsscfg_t *cfg = wlc->cfg; |
| 6315 | |
| 6316 | WLCNTINCR(wlc->pub->_cnt->tbtt); |
| 6317 | |
| 6318 | if (BSSCFG_STA(cfg)) { |
| 6319 | /* run watchdog here if the watchdog timer is not armed */ |
| 6320 | if (WLC_WATCHDOG_TBTT(wlc)) { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 6321 | u32 cur, delta; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6322 | if (wlc->WDarmed) { |
| 6323 | wl_del_timer(wlc->wl, wlc->wdtimer); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 6324 | wlc->WDarmed = false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6325 | } |
| 6326 | |
| 6327 | cur = OSL_SYSUPTIME(); |
| 6328 | delta = cur > wlc->WDlast ? cur - wlc->WDlast : |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 6329 | (u32) ~0 - wlc->WDlast + cur + 1; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6330 | if (delta >= TIMER_INTERVAL_WATCHDOG) { |
| 6331 | wlc_watchdog((void *)wlc); |
| 6332 | wlc->WDlast = cur; |
| 6333 | } |
| 6334 | |
| 6335 | wl_add_timer(wlc->wl, wlc->wdtimer, |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 6336 | wlc_watchdog_backup_bi(wlc), true); |
| 6337 | wlc->WDarmed = true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6338 | } |
| 6339 | } |
| 6340 | |
| 6341 | if (!cfg->BSS) { |
| 6342 | /* DirFrmQ is now valid...defer setting until end of ATIM window */ |
| 6343 | wlc->qvalid |= MCMD_DIRFRMQVAL; |
| 6344 | } |
| 6345 | } |
| 6346 | |
| 6347 | /* GP timer is a freerunning 32 bit counter, decrements at 1 us rate */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 6348 | void wlc_hwtimer_gptimer_set(wlc_info_t *wlc, uint us) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6349 | { |
| 6350 | ASSERT(wlc->pub->corerev >= 3); /* no gptimer in earlier revs */ |
| 6351 | W_REG(wlc->osh, &wlc->regs->gptimer, us); |
| 6352 | } |
| 6353 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 6354 | void wlc_hwtimer_gptimer_abort(wlc_info_t *wlc) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6355 | { |
| 6356 | ASSERT(wlc->pub->corerev >= 3); |
| 6357 | W_REG(wlc->osh, &wlc->regs->gptimer, 0); |
| 6358 | } |
| 6359 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 6360 | static void wlc_hwtimer_gptimer_cb(wlc_info_t *wlc) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6361 | { |
| 6362 | /* when interrupt is generated, the counter is loaded with last value |
| 6363 | * written and continue to decrement. So it has to be cleaned first |
| 6364 | */ |
| 6365 | W_REG(wlc->osh, &wlc->regs->gptimer, 0); |
| 6366 | } |
| 6367 | |
| 6368 | /* |
| 6369 | * This fn has all the high level dpc processing from wlc_dpc. |
| 6370 | * POLICY: no macinstatus change, no bounding loop. |
| 6371 | * All dpc bounding should be handled in BMAC dpc, like txstatus and rxint |
| 6372 | */ |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 6373 | void wlc_high_dpc(wlc_info_t *wlc, u32 macintstatus) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6374 | { |
| 6375 | d11regs_t *regs = wlc->regs; |
| 6376 | #ifdef BCMDBG |
| 6377 | char flagstr[128]; |
| 6378 | static const bcm_bit_desc_t int_flags[] = { |
| 6379 | {MI_MACSSPNDD, "MACSSPNDD"}, |
| 6380 | {MI_BCNTPL, "BCNTPL"}, |
| 6381 | {MI_TBTT, "TBTT"}, |
| 6382 | {MI_BCNSUCCESS, "BCNSUCCESS"}, |
| 6383 | {MI_BCNCANCLD, "BCNCANCLD"}, |
| 6384 | {MI_ATIMWINEND, "ATIMWINEND"}, |
| 6385 | {MI_PMQ, "PMQ"}, |
| 6386 | {MI_NSPECGEN_0, "NSPECGEN_0"}, |
| 6387 | {MI_NSPECGEN_1, "NSPECGEN_1"}, |
| 6388 | {MI_MACTXERR, "MACTXERR"}, |
| 6389 | {MI_NSPECGEN_3, "NSPECGEN_3"}, |
| 6390 | {MI_PHYTXERR, "PHYTXERR"}, |
| 6391 | {MI_PME, "PME"}, |
| 6392 | {MI_GP0, "GP0"}, |
| 6393 | {MI_GP1, "GP1"}, |
| 6394 | {MI_DMAINT, "DMAINT"}, |
| 6395 | {MI_TXSTOP, "TXSTOP"}, |
| 6396 | {MI_CCA, "CCA"}, |
| 6397 | {MI_BG_NOISE, "BG_NOISE"}, |
| 6398 | {MI_DTIM_TBTT, "DTIM_TBTT"}, |
| 6399 | {MI_PRQ, "PRQ"}, |
| 6400 | {MI_PWRUP, "PWRUP"}, |
| 6401 | {MI_RFDISABLE, "RFDISABLE"}, |
| 6402 | {MI_TFS, "TFS"}, |
| 6403 | {MI_PHYCHANGED, "PHYCHANGED"}, |
| 6404 | {MI_TO, "TO"}, |
| 6405 | {0, NULL} |
| 6406 | }; |
| 6407 | |
| 6408 | if (macintstatus & ~(MI_TBTT | MI_TXSTOP)) { |
| 6409 | bcm_format_flags(int_flags, macintstatus, flagstr, |
| 6410 | sizeof(flagstr)); |
| 6411 | WL_TRACE(("wl%d: macintstatus 0x%x %s\n", wlc->pub->unit, |
| 6412 | macintstatus, flagstr)); |
| 6413 | } |
| 6414 | #endif /* BCMDBG */ |
| 6415 | |
| 6416 | if (macintstatus & MI_PRQ) { |
| 6417 | /* Process probe request FIFO */ |
| 6418 | ASSERT(0 && "PRQ Interrupt in non-MBSS"); |
| 6419 | } |
| 6420 | |
| 6421 | /* TBTT indication */ |
| 6422 | /* ucode only gives either TBTT or DTIM_TBTT, not both */ |
| 6423 | if (macintstatus & (MI_TBTT | MI_DTIM_TBTT)) |
| 6424 | wlc_tbtt(wlc, regs); |
| 6425 | |
| 6426 | if (macintstatus & MI_GP0) { |
| 6427 | WL_ERROR(("wl%d: PSM microcode watchdog fired at %d (seconds). Resetting.\n", wlc->pub->unit, wlc->pub->now)); |
| 6428 | |
| 6429 | printk_once("%s : PSM Watchdog, chipid 0x%x, chiprev 0x%x\n", |
| 6430 | __func__, CHIPID(wlc->pub->sih->chip), |
| 6431 | CHIPREV(wlc->pub->sih->chiprev)); |
| 6432 | |
| 6433 | WLCNTINCR(wlc->pub->_cnt->psmwds); |
| 6434 | |
| 6435 | /* big hammer */ |
| 6436 | wl_init(wlc->wl); |
| 6437 | } |
| 6438 | |
| 6439 | /* gptimer timeout */ |
| 6440 | if (macintstatus & MI_TO) { |
| 6441 | wlc_hwtimer_gptimer_cb(wlc); |
| 6442 | } |
| 6443 | |
| 6444 | if (macintstatus & MI_RFDISABLE) { |
| 6445 | WL_ERROR(("wl%d: MAC Detected a change on the RF Disable Input 0x%x\n", wlc->pub->unit, R_REG(wlc->osh, ®s->phydebug) & PDBG_RFD)); |
| 6446 | /* delay the cleanup to wl_down in IBSS case */ |
| 6447 | if ((R_REG(wlc->osh, ®s->phydebug) & PDBG_RFD)) { |
| 6448 | int idx; |
| 6449 | wlc_bsscfg_t *bsscfg; |
| 6450 | FOREACH_BSS(wlc, idx, bsscfg) { |
| 6451 | if (!BSSCFG_STA(bsscfg) || !bsscfg->enable |
| 6452 | || !bsscfg->BSS) |
| 6453 | continue; |
| 6454 | WL_ERROR(("wl%d: wlc_dpc: rfdisable -> wlc_bsscfg_disable()\n", wlc->pub->unit)); |
| 6455 | } |
| 6456 | } |
| 6457 | } |
| 6458 | |
| 6459 | /* send any enq'd tx packets. Just makes sure to jump start tx */ |
| 6460 | if (!pktq_empty(&wlc->active_queue->q)) |
| 6461 | wlc_send_q(wlc, wlc->active_queue); |
| 6462 | |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6463 | ASSERT(wlc_ps_check(wlc)); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6464 | } |
| 6465 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 6466 | static void *wlc_15420war(wlc_info_t *wlc, uint queue) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6467 | { |
| 6468 | hnddma_t *di; |
| 6469 | void *p; |
| 6470 | |
| 6471 | ASSERT(queue < NFIFO); |
| 6472 | |
| 6473 | if ((D11REV_IS(wlc->pub->corerev, 4)) |
| 6474 | || (D11REV_GT(wlc->pub->corerev, 6))) |
Jason Cooper | 90ea229 | 2010-09-14 09:45:32 -0400 | [diff] [blame] | 6475 | return NULL; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6476 | |
| 6477 | di = wlc->hw->di[queue]; |
| 6478 | ASSERT(di != NULL); |
| 6479 | |
| 6480 | /* get next packet, ignoring XmtStatus.Curr */ |
| 6481 | p = dma_getnexttxp(di, HNDDMA_RANGE_ALL); |
| 6482 | |
| 6483 | /* sw block tx dma */ |
| 6484 | dma_txblock(di); |
| 6485 | |
| 6486 | /* if tx ring is now empty, reset and re-init the tx dma channel */ |
| 6487 | if (dma_txactive(wlc->hw->di[queue]) == 0) { |
| 6488 | WLCNTINCR(wlc->pub->_cnt->txdmawar); |
| 6489 | if (!dma_txreset(di)) |
| 6490 | WL_ERROR(("wl%d: %s: dma_txreset[%d]: cannot stop dma\n", wlc->pub->unit, __func__, queue)); |
| 6491 | dma_txinit(di); |
| 6492 | } |
Jason Cooper | 90ea229 | 2010-09-14 09:45:32 -0400 | [diff] [blame] | 6493 | return p; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6494 | } |
| 6495 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 6496 | static void wlc_war16165(wlc_info_t *wlc, bool tx) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6497 | { |
| 6498 | if (tx) { |
| 6499 | /* the post-increment is used in STAY_AWAKE macro */ |
| 6500 | if (wlc->txpend16165war++ == 0) |
| 6501 | wlc_set_ps_ctrl(wlc); |
| 6502 | } else { |
| 6503 | wlc->txpend16165war--; |
| 6504 | if (wlc->txpend16165war == 0) |
| 6505 | wlc_set_ps_ctrl(wlc); |
| 6506 | } |
| 6507 | } |
| 6508 | |
| 6509 | /* process an individual tx_status_t */ |
| 6510 | /* WLC_HIGH_API */ |
| 6511 | bool BCMFASTPATH |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 6512 | wlc_dotxstatus(wlc_info_t *wlc, tx_status_t *txs, u32 frm_tx2) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6513 | { |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 6514 | struct sk_buff *p; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6515 | uint queue; |
| 6516 | d11txh_t *txh; |
| 6517 | struct scb *scb = NULL; |
| 6518 | bool free_pdu; |
Brett Rudley | e69284f | 2010-11-16 15:45:48 -0800 | [diff] [blame] | 6519 | struct osl_info *osh; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6520 | int tx_rts, tx_frame_count, tx_rts_count; |
| 6521 | uint totlen, supr_status; |
| 6522 | bool lastframe; |
| 6523 | struct dot11_header *h; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 6524 | u16 fc; |
| 6525 | u16 mcl; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6526 | struct ieee80211_tx_info *tx_info; |
| 6527 | struct ieee80211_tx_rate *txrate; |
| 6528 | int i; |
| 6529 | |
| 6530 | (void)(frm_tx2); /* Compiler reference to avoid unused variable warning */ |
| 6531 | |
| 6532 | /* discard intermediate indications for ucode with one legitimate case: |
| 6533 | * e.g. if "useRTS" is set. ucode did a successful rts/cts exchange, but the subsequent |
| 6534 | * tx of DATA failed. so it will start rts/cts from the beginning (resetting the rts |
| 6535 | * transmission count) |
| 6536 | */ |
| 6537 | if (!(txs->status & TX_STATUS_AMPDU) |
| 6538 | && (txs->status & TX_STATUS_INTERMEDIATE)) { |
| 6539 | WLCNTADD(wlc->pub->_cnt->txnoack, |
| 6540 | ((txs-> |
| 6541 | status & TX_STATUS_FRM_RTX_MASK) >> |
| 6542 | TX_STATUS_FRM_RTX_SHIFT)); |
| 6543 | WL_ERROR(("%s: INTERMEDIATE but not AMPDU\n", __func__)); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 6544 | return false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6545 | } |
| 6546 | |
| 6547 | osh = wlc->osh; |
| 6548 | queue = txs->frameid & TXFID_QUEUE_MASK; |
| 6549 | ASSERT(queue < NFIFO); |
| 6550 | if (queue >= NFIFO) { |
| 6551 | p = NULL; |
| 6552 | goto fatal; |
| 6553 | } |
| 6554 | |
| 6555 | p = GETNEXTTXP(wlc, queue); |
| 6556 | if (WLC_WAR16165(wlc)) |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 6557 | wlc_war16165(wlc, false); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6558 | if (p == NULL) |
| 6559 | p = wlc_15420war(wlc, queue); |
| 6560 | ASSERT(p != NULL); |
| 6561 | if (p == NULL) |
| 6562 | goto fatal; |
| 6563 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 6564 | txh = (d11txh_t *) (p->data); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6565 | mcl = ltoh16(txh->MacTxControlLow); |
| 6566 | |
| 6567 | if (txs->phyerr) { |
| 6568 | WL_ERROR(("phyerr 0x%x, rate 0x%x\n", txs->phyerr, |
| 6569 | txh->MainRates)); |
| 6570 | wlc_print_txdesc(txh); |
| 6571 | wlc_print_txstatus(txs); |
| 6572 | } |
| 6573 | |
| 6574 | ASSERT(txs->frameid == htol16(txh->TxFrameID)); |
| 6575 | if (txs->frameid != htol16(txh->TxFrameID)) |
| 6576 | goto fatal; |
| 6577 | |
| 6578 | tx_info = IEEE80211_SKB_CB(p); |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 6579 | h = (struct dot11_header *)((u8 *) (txh + 1) + D11_PHY_HDR_LEN); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6580 | fc = ltoh16(h->fc); |
| 6581 | |
| 6582 | scb = (struct scb *)tx_info->control.sta->drv_priv; |
| 6583 | |
| 6584 | if (N_ENAB(wlc->pub)) { |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 6585 | u8 *plcp = (u8 *) (txh + 1); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6586 | if (PLCP3_ISSGI(plcp[3])) |
| 6587 | WLCNTINCR(wlc->pub->_cnt->txmpdu_sgi); |
| 6588 | if (PLCP3_ISSTBC(plcp[3])) |
| 6589 | WLCNTINCR(wlc->pub->_cnt->txmpdu_stbc); |
| 6590 | } |
| 6591 | |
| 6592 | if (tx_info->flags & IEEE80211_TX_CTL_AMPDU) { |
| 6593 | ASSERT((mcl & TXC_AMPDU_MASK) != TXC_AMPDU_NONE); |
| 6594 | wlc_ampdu_dotxstatus(wlc->ampdu, scb, p, txs); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 6595 | return false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6596 | } |
| 6597 | |
| 6598 | supr_status = txs->status & TX_STATUS_SUPR_MASK; |
| 6599 | if (supr_status == TX_STATUS_SUPR_BADCH) |
| 6600 | WL_NONE(("%s: Pkt tx suppressed, possibly channel %d\n", |
| 6601 | __func__, CHSPEC_CHANNEL(wlc->default_bss->chanspec))); |
| 6602 | |
| 6603 | tx_rts = htol16(txh->MacTxControlLow) & TXC_SENDRTS; |
| 6604 | tx_frame_count = |
| 6605 | (txs->status & TX_STATUS_FRM_RTX_MASK) >> TX_STATUS_FRM_RTX_SHIFT; |
| 6606 | tx_rts_count = |
| 6607 | (txs->status & TX_STATUS_RTS_RTX_MASK) >> TX_STATUS_RTS_RTX_SHIFT; |
| 6608 | |
| 6609 | lastframe = (fc & FC_MOREFRAG) == 0; |
| 6610 | |
| 6611 | if (!lastframe) { |
| 6612 | WL_ERROR(("Not last frame!\n")); |
| 6613 | } else { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 6614 | u16 sfbl, lfbl; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6615 | ieee80211_tx_info_clear_status(tx_info); |
| 6616 | if (queue < AC_COUNT) { |
| 6617 | sfbl = WLC_WME_RETRY_SFB_GET(wlc, wme_fifo2ac[queue]); |
| 6618 | lfbl = WLC_WME_RETRY_LFB_GET(wlc, wme_fifo2ac[queue]); |
| 6619 | } else { |
| 6620 | sfbl = wlc->SFBL; |
| 6621 | lfbl = wlc->LFBL; |
| 6622 | } |
| 6623 | |
| 6624 | txrate = tx_info->status.rates; |
| 6625 | /* FIXME: this should use a combination of sfbl, lfbl depending on frame length and RTS setting */ |
| 6626 | if ((tx_frame_count > sfbl) && (txrate[1].idx >= 0)) { |
| 6627 | /* rate selection requested a fallback rate and we used it */ |
| 6628 | txrate->count = lfbl; |
| 6629 | txrate[1].count = tx_frame_count - lfbl; |
| 6630 | } else { |
| 6631 | /* rate selection did not request fallback rate, or we didn't need it */ |
| 6632 | txrate->count = tx_frame_count; |
| 6633 | /* rc80211_minstrel.c:minstrel_tx_status() expects unused rates to be marked with idx = -1 */ |
| 6634 | txrate[1].idx = -1; |
| 6635 | txrate[1].count = 0; |
| 6636 | } |
| 6637 | |
| 6638 | /* clear the rest of the rates */ |
| 6639 | for (i = 2; i < IEEE80211_TX_MAX_RATES; i++) { |
| 6640 | txrate[i].idx = -1; |
| 6641 | txrate[i].count = 0; |
| 6642 | } |
| 6643 | |
| 6644 | if (txs->status & TX_STATUS_ACK_RCV) |
| 6645 | tx_info->flags |= IEEE80211_TX_STAT_ACK; |
| 6646 | } |
| 6647 | |
| 6648 | totlen = pkttotlen(osh, p); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 6649 | free_pdu = true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6650 | |
| 6651 | wlc_txfifo_complete(wlc, queue, 1); |
| 6652 | |
| 6653 | if (lastframe) { |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 6654 | p->next = NULL; |
| 6655 | p->prev = NULL; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6656 | wlc->txretried = 0; |
| 6657 | /* remove PLCP & Broadcom tx descriptor header */ |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 6658 | skb_pull(p, D11_PHY_HDR_LEN); |
| 6659 | skb_pull(p, D11_TXH_LEN); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6660 | ieee80211_tx_status_irqsafe(wlc->pub->ieee_hw, p); |
| 6661 | WLCNTINCR(wlc->pub->_cnt->ieee_tx_status); |
| 6662 | } else { |
| 6663 | WL_ERROR(("%s: Not last frame => not calling tx_status\n", |
| 6664 | __func__)); |
| 6665 | } |
| 6666 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 6667 | return false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6668 | |
| 6669 | fatal: |
| 6670 | ASSERT(0); |
| 6671 | if (p) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 6672 | PKTFREE(osh, p, true); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6673 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 6674 | return true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6675 | |
| 6676 | } |
| 6677 | |
| 6678 | void BCMFASTPATH |
Greg Kroah-Hartman | 562c885 | 2010-10-05 11:04:17 -0700 | [diff] [blame] | 6679 | wlc_txfifo_complete(wlc_info_t *wlc, uint fifo, s8 txpktpend) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6680 | { |
| 6681 | TXPKTPENDDEC(wlc, fifo, txpktpend); |
| 6682 | WL_TRACE(("wlc_txfifo_complete, pktpend dec %d to %d\n", txpktpend, |
| 6683 | TXPKTPENDGET(wlc, fifo))); |
| 6684 | |
| 6685 | /* There is more room; mark precedences related to this FIFO sendable */ |
| 6686 | WLC_TX_FIFO_ENAB(wlc, fifo); |
| 6687 | ASSERT(TXPKTPENDGET(wlc, fifo) >= 0); |
| 6688 | |
| 6689 | if (!TXPKTPENDTOT(wlc)) { |
| 6690 | if (wlc->block_datafifo & DATA_BLOCK_TX_SUPR) |
| 6691 | wlc_bsscfg_tx_check(wlc); |
| 6692 | } |
| 6693 | |
| 6694 | /* Clear MHF2_TXBCMC_NOW flag if BCMC fifo has drained */ |
| 6695 | if (AP_ENAB(wlc->pub) && |
| 6696 | wlc->bcmcfifo_drain && !TXPKTPENDGET(wlc, TX_BCMC_FIFO)) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 6697 | wlc->bcmcfifo_drain = false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6698 | wlc_mhf(wlc, MHF2, MHF2_TXBCMC_NOW, 0, WLC_BAND_AUTO); |
| 6699 | } |
| 6700 | |
| 6701 | /* figure out which bsscfg is being worked on... */ |
| 6702 | } |
| 6703 | |
| 6704 | /* Given the beacon interval in kus, and a 64 bit TSF in us, |
| 6705 | * return the offset (in us) of the TSF from the last TBTT |
| 6706 | */ |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 6707 | u32 wlc_calc_tbtt_offset(u32 bp, u32 tsf_h, u32 tsf_l) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6708 | { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 6709 | u32 k, btklo, btkhi, offset; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6710 | |
| 6711 | /* TBTT is always an even multiple of the beacon_interval, |
| 6712 | * so the TBTT less than or equal to the beacon timestamp is |
| 6713 | * the beacon timestamp minus the beacon timestamp modulo |
| 6714 | * the beacon interval. |
| 6715 | * |
| 6716 | * TBTT = BT - (BT % BIu) |
| 6717 | * = (BTk - (BTk % BP)) * 2^10 |
| 6718 | * |
| 6719 | * BT = beacon timestamp (usec, 64bits) |
| 6720 | * BTk = beacon timestamp (Kusec, 54bits) |
| 6721 | * BP = beacon interval (Kusec, 16bits) |
| 6722 | * BIu = BP * 2^10 = beacon interval (usec, 26bits) |
| 6723 | * |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 6724 | * To keep the calculations in u32s, the modulo operation |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6725 | * on the high part of BT needs to be done in parts using the |
| 6726 | * relations: |
| 6727 | * X*Y mod Z = ((X mod Z) * (Y mod Z)) mod Z |
| 6728 | * and |
| 6729 | * (X + Y) mod Z = ((X mod Z) + (Y mod Z)) mod Z |
| 6730 | * |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 6731 | * So, if BTk[n] = u16 n [0,3] of BTk. |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6732 | * BTk % BP = SUM((BTk[n] * 2^16n) % BP , 0<=n<4) % BP |
| 6733 | * and the SUM term can be broken down: |
| 6734 | * (BTk[n] * 2^16n) % BP |
| 6735 | * (BTk[n] * (2^16n % BP)) % BP |
| 6736 | * |
| 6737 | * Create a set of power of 2 mod BP constants: |
| 6738 | * K[n] = 2^(16n) % BP |
| 6739 | * = (K[n-1] * 2^16) % BP |
| 6740 | * K[2] = 2^32 % BP = ((2^16 % BP) * 2^16) % BP |
| 6741 | * |
| 6742 | * BTk % BP = BTk[0-1] % BP + |
| 6743 | * (BTk[2] * K[2]) % BP + |
| 6744 | * (BTk[3] * K[3]) % BP |
| 6745 | * |
| 6746 | * Since K[n] < 2^16 and BTk[n] is < 2^16, then BTk[n] * K[n] < 2^32 |
| 6747 | */ |
| 6748 | |
| 6749 | /* BTk = BT >> 10, btklo = BTk[0-3], bkthi = BTk[4-6] */ |
| 6750 | btklo = (tsf_h << 22) | (tsf_l >> 10); |
| 6751 | btkhi = tsf_h >> 10; |
| 6752 | |
| 6753 | /* offset = BTk % BP */ |
| 6754 | offset = btklo % bp; |
| 6755 | |
| 6756 | /* K[2] = ((2^16 % BP) * 2^16) % BP */ |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 6757 | k = (u32) (1 << 16) % bp; |
| 6758 | k = (u32) (k * 1 << 16) % (u32) bp; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6759 | |
| 6760 | /* offset += (BTk[2] * K[2]) % BP */ |
| 6761 | offset += ((btkhi & 0xffff) * k) % bp; |
| 6762 | |
| 6763 | /* BTk[3] */ |
| 6764 | btkhi = btkhi >> 16; |
| 6765 | |
| 6766 | /* k[3] = (K[2] * 2^16) % BP */ |
| 6767 | k = (k << 16) % bp; |
| 6768 | |
| 6769 | /* offset += (BTk[3] * K[3]) % BP */ |
| 6770 | offset += ((btkhi & 0xffff) * k) % bp; |
| 6771 | |
| 6772 | offset = offset % bp; |
| 6773 | |
| 6774 | /* convert offset from kus to us by shifting up 10 bits and |
| 6775 | * add in the low 10 bits of tsf that we ignored |
| 6776 | */ |
| 6777 | offset = (offset << 10) + (tsf_l & 0x3FF); |
| 6778 | |
| 6779 | return offset; |
| 6780 | } |
| 6781 | |
| 6782 | /* Update beacon listen interval in shared memory */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 6783 | void wlc_bcn_li_upd(wlc_info_t *wlc) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6784 | { |
| 6785 | if (AP_ENAB(wlc->pub)) |
| 6786 | return; |
| 6787 | |
| 6788 | /* wake up every DTIM is the default */ |
| 6789 | if (wlc->bcn_li_dtim == 1) |
| 6790 | wlc_write_shm(wlc, M_BCN_LI, 0); |
| 6791 | else |
| 6792 | wlc_write_shm(wlc, M_BCN_LI, |
| 6793 | (wlc->bcn_li_dtim << 8) | wlc->bcn_li_bcn); |
| 6794 | } |
| 6795 | |
| 6796 | static void |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 6797 | prep_mac80211_status(wlc_info_t *wlc, d11rxhdr_t *rxh, struct sk_buff *p, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6798 | struct ieee80211_rx_status *rx_status) |
| 6799 | { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 6800 | u32 tsf_l, tsf_h; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6801 | wlc_d11rxhdr_t *wlc_rxh = (wlc_d11rxhdr_t *) rxh; |
| 6802 | int preamble; |
| 6803 | int channel; |
| 6804 | ratespec_t rspec; |
Greg Kroah-Hartman | 580a0bd | 2010-10-05 11:09:48 -0700 | [diff] [blame] | 6805 | unsigned char *plcp; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6806 | |
| 6807 | wlc_read_tsf(wlc, &tsf_l, &tsf_h); /* mactime */ |
| 6808 | rx_status->mactime = tsf_h; |
| 6809 | rx_status->mactime <<= 32; |
| 6810 | rx_status->mactime |= tsf_l; |
| 6811 | rx_status->flag |= RX_FLAG_TSFT; |
| 6812 | |
| 6813 | channel = WLC_CHAN_CHANNEL(rxh->RxChan); |
| 6814 | |
| 6815 | /* XXX Channel/badn needs to be filtered against whether we are single/dual band card */ |
| 6816 | if (channel > 14) { |
| 6817 | rx_status->band = IEEE80211_BAND_5GHZ; |
| 6818 | rx_status->freq = wf_channel2mhz(channel, WF_CHAN_FACTOR_5_G); |
| 6819 | } else { |
| 6820 | rx_status->band = IEEE80211_BAND_2GHZ; |
| 6821 | rx_status->freq = wf_channel2mhz(channel, WF_CHAN_FACTOR_2_4_G); |
| 6822 | } |
| 6823 | |
| 6824 | rx_status->signal = wlc_rxh->rssi; /* signal */ |
| 6825 | |
| 6826 | /* noise */ |
| 6827 | /* qual */ |
| 6828 | rx_status->antenna = (rxh->PhyRxStatus_0 & PRXS0_RXANT_UPSUBBAND) ? 1 : 0; /* ant */ |
| 6829 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 6830 | plcp = p->data; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6831 | |
| 6832 | rspec = wlc_compute_rspec(rxh, plcp); |
| 6833 | if (IS_MCS(rspec)) { |
| 6834 | rx_status->rate_idx = rspec & RSPEC_RATE_MASK; |
| 6835 | rx_status->flag |= RX_FLAG_HT; |
| 6836 | if (RSPEC_IS40MHZ(rspec)) |
| 6837 | rx_status->flag |= RX_FLAG_40MHZ; |
| 6838 | } else { |
| 6839 | switch (RSPEC2RATE(rspec)) { |
| 6840 | case WLC_RATE_1M: |
| 6841 | rx_status->rate_idx = 0; |
| 6842 | break; |
| 6843 | case WLC_RATE_2M: |
| 6844 | rx_status->rate_idx = 1; |
| 6845 | break; |
| 6846 | case WLC_RATE_5M5: |
| 6847 | rx_status->rate_idx = 2; |
| 6848 | break; |
| 6849 | case WLC_RATE_11M: |
| 6850 | rx_status->rate_idx = 3; |
| 6851 | break; |
| 6852 | case WLC_RATE_6M: |
| 6853 | rx_status->rate_idx = 4; |
| 6854 | break; |
| 6855 | case WLC_RATE_9M: |
| 6856 | rx_status->rate_idx = 5; |
| 6857 | break; |
| 6858 | case WLC_RATE_12M: |
| 6859 | rx_status->rate_idx = 6; |
| 6860 | break; |
| 6861 | case WLC_RATE_18M: |
| 6862 | rx_status->rate_idx = 7; |
| 6863 | break; |
| 6864 | case WLC_RATE_24M: |
| 6865 | rx_status->rate_idx = 8; |
| 6866 | break; |
| 6867 | case WLC_RATE_36M: |
| 6868 | rx_status->rate_idx = 9; |
| 6869 | break; |
| 6870 | case WLC_RATE_48M: |
| 6871 | rx_status->rate_idx = 10; |
| 6872 | break; |
| 6873 | case WLC_RATE_54M: |
| 6874 | rx_status->rate_idx = 11; |
| 6875 | break; |
| 6876 | default: |
| 6877 | WL_ERROR(("%s: Unknown rate\n", __func__)); |
| 6878 | } |
| 6879 | |
| 6880 | /* Determine short preamble and rate_idx */ |
| 6881 | preamble = 0; |
| 6882 | if (IS_CCK(rspec)) { |
| 6883 | if (rxh->PhyRxStatus_0 & PRXS0_SHORTH) |
| 6884 | WL_ERROR(("Short CCK\n")); |
| 6885 | rx_status->flag |= RX_FLAG_SHORTPRE; |
| 6886 | } else if (IS_OFDM(rspec)) { |
| 6887 | rx_status->flag |= RX_FLAG_SHORTPRE; |
| 6888 | } else { |
| 6889 | WL_ERROR(("%s: Unknown modulation\n", __func__)); |
| 6890 | } |
| 6891 | } |
| 6892 | |
| 6893 | if (PLCP3_ISSGI(plcp[3])) |
| 6894 | rx_status->flag |= RX_FLAG_SHORT_GI; |
| 6895 | |
| 6896 | if (rxh->RxStatus1 & RXS_DECERR) { |
| 6897 | rx_status->flag |= RX_FLAG_FAILED_PLCP_CRC; |
| 6898 | WL_ERROR(("%s: RX_FLAG_FAILED_PLCP_CRC\n", __func__)); |
| 6899 | } |
| 6900 | if (rxh->RxStatus1 & RXS_FCSERR) { |
| 6901 | rx_status->flag |= RX_FLAG_FAILED_FCS_CRC; |
| 6902 | WL_ERROR(("%s: RX_FLAG_FAILED_FCS_CRC\n", __func__)); |
| 6903 | } |
| 6904 | } |
| 6905 | |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6906 | static void |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 6907 | wlc_recvctl(wlc_info_t *wlc, struct osl_info *osh, d11rxhdr_t *rxh, |
| 6908 | struct sk_buff *p) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6909 | { |
| 6910 | int len_mpdu; |
| 6911 | struct ieee80211_rx_status rx_status; |
| 6912 | #if defined(BCMDBG) |
| 6913 | struct sk_buff *skb = p; |
| 6914 | #endif /* BCMDBG */ |
| 6915 | /* Todo: |
| 6916 | * Cache plcp for first MPDU of AMPD and use chacched version for INTERMEDIATE. |
| 6917 | * Test for INTERMEDIATE like so: |
| 6918 | * if (!(plcp[0] | plcp[1] | plcp[2])) |
| 6919 | */ |
| 6920 | |
| 6921 | memset(&rx_status, 0, sizeof(rx_status)); |
| 6922 | prep_mac80211_status(wlc, rxh, p, &rx_status); |
| 6923 | |
| 6924 | /* mac header+body length, exclude CRC and plcp header */ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 6925 | len_mpdu = p->len - D11_PHY_HDR_LEN - DOT11_FCS_LEN; |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 6926 | skb_pull(p, D11_PHY_HDR_LEN); |
Arend van Spriel | 2cb8ada | 2010-11-18 20:46:44 +0100 | [diff] [blame] | 6927 | __skb_trim(p, len_mpdu); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6928 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 6929 | ASSERT(!(p->next)); |
| 6930 | ASSERT(!(p->prev)); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6931 | |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 6932 | ASSERT(IS_ALIGNED((unsigned long)skb->data, 2)); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6933 | |
| 6934 | memcpy(IEEE80211_SKB_RXCB(p), &rx_status, sizeof(rx_status)); |
| 6935 | ieee80211_rx_irqsafe(wlc->pub->ieee_hw, p); |
| 6936 | |
| 6937 | WLCNTINCR(wlc->pub->_cnt->ieee_rx); |
Arend van Spriel | 3be727c | 2010-11-23 22:20:30 +0100 | [diff] [blame] | 6938 | osh->pub.pktalloced--; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6939 | return; |
| 6940 | } |
| 6941 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 6942 | void wlc_bss_list_free(wlc_info_t *wlc, wlc_bss_list_t *bss_list) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6943 | { |
| 6944 | uint index; |
| 6945 | wlc_bss_info_t *bi; |
| 6946 | |
| 6947 | if (!bss_list) { |
| 6948 | WL_ERROR(("%s: Attempting to free NULL list\n", __func__)); |
| 6949 | return; |
| 6950 | } |
| 6951 | /* inspect all BSS descriptor */ |
| 6952 | for (index = 0; index < bss_list->count; index++) { |
| 6953 | bi = bss_list->ptrs[index]; |
| 6954 | if (bi) { |
| 6955 | if (bi->bcn_prb) { |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 6956 | kfree(bi->bcn_prb); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6957 | } |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 6958 | kfree(bi); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6959 | bss_list->ptrs[index] = NULL; |
| 6960 | } |
| 6961 | } |
| 6962 | bss_list->count = 0; |
| 6963 | } |
| 6964 | |
| 6965 | /* Process received frames */ |
| 6966 | /* |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 6967 | * Return true if more frames need to be processed. false otherwise. |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6968 | * Param 'bound' indicates max. # frames to process before break out. |
| 6969 | */ |
| 6970 | /* WLC_HIGH_API */ |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 6971 | void BCMFASTPATH wlc_recv(wlc_info_t *wlc, struct sk_buff *p) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6972 | { |
| 6973 | d11rxhdr_t *rxh; |
| 6974 | struct dot11_header *h; |
Brett Rudley | e69284f | 2010-11-16 15:45:48 -0800 | [diff] [blame] | 6975 | struct osl_info *osh; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 6976 | u16 fc; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6977 | uint len; |
| 6978 | bool is_amsdu; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6979 | |
| 6980 | WL_TRACE(("wl%d: wlc_recv\n", wlc->pub->unit)); |
| 6981 | |
| 6982 | osh = wlc->osh; |
| 6983 | |
| 6984 | /* frame starts with rxhdr */ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 6985 | rxh = (d11rxhdr_t *) (p->data); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6986 | |
| 6987 | /* strip off rxhdr */ |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 6988 | skb_pull(p, wlc->hwrxoff); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6989 | |
| 6990 | /* fixup rx header endianness */ |
| 6991 | ltoh16_buf((void *)rxh, sizeof(d11rxhdr_t)); |
| 6992 | |
| 6993 | /* MAC inserts 2 pad bytes for a4 headers or QoS or A-MSDU subframes */ |
| 6994 | if (rxh->RxStatus1 & RXS_PBPRES) { |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 6995 | if (p->len < 2) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6996 | WLCNTINCR(wlc->pub->_cnt->rxrunt); |
| 6997 | WL_ERROR(("wl%d: wlc_recv: rcvd runt of len %d\n", |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 6998 | wlc->pub->unit, p->len)); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 6999 | goto toss; |
| 7000 | } |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 7001 | skb_pull(p, 2); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7002 | } |
| 7003 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 7004 | h = (struct dot11_header *)(p->data + D11_PHY_HDR_LEN); |
| 7005 | len = p->len; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7006 | |
| 7007 | if (rxh->RxStatus1 & RXS_FCSERR) { |
| 7008 | if (wlc->pub->mac80211_state & MAC80211_PROMISC_BCNS) { |
| 7009 | WL_ERROR(("FCSERR while scanning******* - tossing\n")); |
| 7010 | goto toss; |
| 7011 | } else { |
| 7012 | WL_ERROR(("RCSERR!!!\n")); |
| 7013 | goto toss; |
| 7014 | } |
| 7015 | } |
| 7016 | |
| 7017 | /* check received pkt has at least frame control field */ |
| 7018 | if (len >= D11_PHY_HDR_LEN + sizeof(h->fc)) { |
| 7019 | fc = ltoh16(h->fc); |
| 7020 | } else { |
| 7021 | WLCNTINCR(wlc->pub->_cnt->rxrunt); |
| 7022 | goto toss; |
| 7023 | } |
| 7024 | |
| 7025 | is_amsdu = rxh->RxStatus2 & RXS_AMSDU_MASK; |
| 7026 | |
| 7027 | /* explicitly test bad src address to avoid sending bad deauth */ |
| 7028 | if (!is_amsdu) { |
| 7029 | /* CTS and ACK CTL frames are w/o a2 */ |
| 7030 | if (FC_TYPE(fc) == FC_TYPE_DATA || FC_TYPE(fc) == FC_TYPE_MNG) { |
| 7031 | if ((ETHER_ISNULLADDR(&h->a2) || ETHER_ISMULTI(&h->a2))) { |
Andy Shevchenko | ba07d0c | 2010-10-11 16:58:33 +0300 | [diff] [blame] | 7032 | WL_ERROR(("wl%d: %s: dropping a frame with " |
| 7033 | "invalid src mac address, a2: %pM\n", |
| 7034 | wlc->pub->unit, __func__, &h->a2)); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7035 | WLCNTINCR(wlc->pub->_cnt->rxbadsrcmac); |
| 7036 | goto toss; |
| 7037 | } |
| 7038 | WLCNTINCR(wlc->pub->_cnt->rxfrag); |
| 7039 | } |
| 7040 | } |
| 7041 | |
| 7042 | /* due to sheer numbers, toss out probe reqs for now */ |
| 7043 | if (FC_TYPE(fc) == FC_TYPE_MNG) { |
| 7044 | if ((fc & FC_KIND_MASK) == FC_PROBE_REQ) |
| 7045 | goto toss; |
| 7046 | } |
| 7047 | |
| 7048 | if (is_amsdu) { |
| 7049 | WL_ERROR(("%s: is_amsdu causing toss\n", __func__)); |
| 7050 | goto toss; |
| 7051 | } |
| 7052 | |
| 7053 | wlc_recvctl(wlc, osh, rxh, p); |
| 7054 | return; |
| 7055 | |
| 7056 | toss: |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 7057 | PKTFREE(osh, p, false); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7058 | } |
| 7059 | |
| 7060 | /* calculate frame duration for Mixed-mode L-SIG spoofing, return |
| 7061 | * number of bytes goes in the length field |
| 7062 | * |
| 7063 | * Formula given by HT PHY Spec v 1.13 |
| 7064 | * len = 3(nsyms + nstream + 3) - 3 |
| 7065 | */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 7066 | u16 BCMFASTPATH |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 7067 | wlc_calc_lsig_len(wlc_info_t *wlc, ratespec_t ratespec, uint mac_len) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7068 | { |
| 7069 | uint nsyms, len = 0, kNdps; |
| 7070 | |
| 7071 | WL_TRACE(("wl%d: wlc_calc_lsig_len: rate %d, len%d\n", wlc->pub->unit, |
| 7072 | RSPEC2RATE(ratespec), mac_len)); |
| 7073 | |
| 7074 | if (IS_MCS(ratespec)) { |
| 7075 | uint mcs = ratespec & RSPEC_RATE_MASK; |
| 7076 | /* MCS_TXS(mcs) returns num tx streams - 1 */ |
| 7077 | int tot_streams = (MCS_TXS(mcs) + 1) + RSPEC_STC(ratespec); |
| 7078 | |
| 7079 | ASSERT(WLC_PHY_11N_CAP(wlc->band)); |
| 7080 | /* the payload duration calculation matches that of regular ofdm */ |
| 7081 | /* 1000Ndbps = kbps * 4 */ |
| 7082 | kNdps = |
| 7083 | MCS_RATE(mcs, RSPEC_IS40MHZ(ratespec), |
| 7084 | RSPEC_ISSGI(ratespec)) * 4; |
| 7085 | |
| 7086 | if (RSPEC_STC(ratespec) == 0) |
| 7087 | /* NSyms = CEILING((SERVICE + 8*NBytes + TAIL) / Ndbps) */ |
| 7088 | nsyms = |
| 7089 | CEIL((APHY_SERVICE_NBITS + 8 * mac_len + |
| 7090 | APHY_TAIL_NBITS) * 1000, kNdps); |
| 7091 | else |
| 7092 | /* STBC needs to have even number of symbols */ |
| 7093 | nsyms = |
| 7094 | 2 * |
| 7095 | CEIL((APHY_SERVICE_NBITS + 8 * mac_len + |
| 7096 | APHY_TAIL_NBITS) * 1000, 2 * kNdps); |
| 7097 | |
| 7098 | nsyms += (tot_streams + 3); /* (+3) account for HT-SIG(2) and HT-STF(1) */ |
| 7099 | /* 3 bytes/symbol @ legacy 6Mbps rate */ |
| 7100 | len = (3 * nsyms) - 3; /* (-3) excluding service bits and tail bits */ |
| 7101 | } |
| 7102 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 7103 | return (u16) len; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7104 | } |
| 7105 | |
| 7106 | /* calculate frame duration of a given rate and length, return time in usec unit */ |
| 7107 | uint BCMFASTPATH |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 7108 | wlc_calc_frame_time(wlc_info_t *wlc, ratespec_t ratespec, u8 preamble_type, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7109 | uint mac_len) |
| 7110 | { |
| 7111 | uint nsyms, dur = 0, Ndps, kNdps; |
| 7112 | uint rate = RSPEC2RATE(ratespec); |
| 7113 | |
| 7114 | if (rate == 0) { |
| 7115 | ASSERT(0); |
| 7116 | WL_ERROR(("wl%d: WAR: using rate of 1 mbps\n", wlc->pub->unit)); |
| 7117 | rate = WLC_RATE_1M; |
| 7118 | } |
| 7119 | |
| 7120 | WL_TRACE(("wl%d: wlc_calc_frame_time: rspec 0x%x, preamble_type %d, len%d\n", wlc->pub->unit, ratespec, preamble_type, mac_len)); |
| 7121 | |
| 7122 | if (IS_MCS(ratespec)) { |
| 7123 | uint mcs = ratespec & RSPEC_RATE_MASK; |
| 7124 | int tot_streams = MCS_TXS(mcs) + RSPEC_STC(ratespec); |
| 7125 | ASSERT(WLC_PHY_11N_CAP(wlc->band)); |
| 7126 | ASSERT(WLC_IS_MIMO_PREAMBLE(preamble_type)); |
| 7127 | |
| 7128 | dur = PREN_PREAMBLE + (tot_streams * PREN_PREAMBLE_EXT); |
| 7129 | if (preamble_type == WLC_MM_PREAMBLE) |
| 7130 | dur += PREN_MM_EXT; |
| 7131 | /* 1000Ndbps = kbps * 4 */ |
| 7132 | kNdps = |
| 7133 | MCS_RATE(mcs, RSPEC_IS40MHZ(ratespec), |
| 7134 | RSPEC_ISSGI(ratespec)) * 4; |
| 7135 | |
| 7136 | if (RSPEC_STC(ratespec) == 0) |
| 7137 | /* NSyms = CEILING((SERVICE + 8*NBytes + TAIL) / Ndbps) */ |
| 7138 | nsyms = |
| 7139 | CEIL((APHY_SERVICE_NBITS + 8 * mac_len + |
| 7140 | APHY_TAIL_NBITS) * 1000, kNdps); |
| 7141 | else |
| 7142 | /* STBC needs to have even number of symbols */ |
| 7143 | nsyms = |
| 7144 | 2 * |
| 7145 | CEIL((APHY_SERVICE_NBITS + 8 * mac_len + |
| 7146 | APHY_TAIL_NBITS) * 1000, 2 * kNdps); |
| 7147 | |
| 7148 | dur += APHY_SYMBOL_TIME * nsyms; |
| 7149 | if (BAND_2G(wlc->band->bandtype)) |
| 7150 | dur += DOT11_OFDM_SIGNAL_EXTENSION; |
| 7151 | } else if (IS_OFDM(rate)) { |
| 7152 | dur = APHY_PREAMBLE_TIME; |
| 7153 | dur += APHY_SIGNAL_TIME; |
| 7154 | /* Ndbps = Mbps * 4 = rate(500Kbps) * 2 */ |
| 7155 | Ndps = rate * 2; |
| 7156 | /* NSyms = CEILING((SERVICE + 8*NBytes + TAIL) / Ndbps) */ |
| 7157 | nsyms = |
| 7158 | CEIL((APHY_SERVICE_NBITS + 8 * mac_len + APHY_TAIL_NBITS), |
| 7159 | Ndps); |
| 7160 | dur += APHY_SYMBOL_TIME * nsyms; |
| 7161 | if (BAND_2G(wlc->band->bandtype)) |
| 7162 | dur += DOT11_OFDM_SIGNAL_EXTENSION; |
| 7163 | } else { |
| 7164 | /* calc # bits * 2 so factor of 2 in rate (1/2 mbps) will divide out */ |
| 7165 | mac_len = mac_len * 8 * 2; |
| 7166 | /* calc ceiling of bits/rate = microseconds of air time */ |
| 7167 | dur = (mac_len + rate - 1) / rate; |
| 7168 | if (preamble_type & WLC_SHORT_PREAMBLE) |
| 7169 | dur += BPHY_PLCP_SHORT_TIME; |
| 7170 | else |
| 7171 | dur += BPHY_PLCP_TIME; |
| 7172 | } |
| 7173 | return dur; |
| 7174 | } |
| 7175 | |
| 7176 | /* The opposite of wlc_calc_frame_time */ |
| 7177 | static uint |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 7178 | wlc_calc_frame_len(wlc_info_t *wlc, ratespec_t ratespec, u8 preamble_type, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7179 | uint dur) |
| 7180 | { |
| 7181 | uint nsyms, mac_len, Ndps, kNdps; |
| 7182 | uint rate = RSPEC2RATE(ratespec); |
| 7183 | |
| 7184 | WL_TRACE(("wl%d: wlc_calc_frame_len: rspec 0x%x, preamble_type %d, dur %d\n", wlc->pub->unit, ratespec, preamble_type, dur)); |
| 7185 | |
| 7186 | if (IS_MCS(ratespec)) { |
| 7187 | uint mcs = ratespec & RSPEC_RATE_MASK; |
| 7188 | int tot_streams = MCS_TXS(mcs) + RSPEC_STC(ratespec); |
| 7189 | ASSERT(WLC_PHY_11N_CAP(wlc->band)); |
| 7190 | dur -= PREN_PREAMBLE + (tot_streams * PREN_PREAMBLE_EXT); |
| 7191 | /* payload calculation matches that of regular ofdm */ |
| 7192 | if (BAND_2G(wlc->band->bandtype)) |
| 7193 | dur -= DOT11_OFDM_SIGNAL_EXTENSION; |
| 7194 | /* kNdbps = kbps * 4 */ |
| 7195 | kNdps = |
| 7196 | MCS_RATE(mcs, RSPEC_IS40MHZ(ratespec), |
| 7197 | RSPEC_ISSGI(ratespec)) * 4; |
| 7198 | nsyms = dur / APHY_SYMBOL_TIME; |
| 7199 | mac_len = |
| 7200 | ((nsyms * kNdps) - |
| 7201 | ((APHY_SERVICE_NBITS + APHY_TAIL_NBITS) * 1000)) / 8000; |
| 7202 | } else if (IS_OFDM(ratespec)) { |
| 7203 | dur -= APHY_PREAMBLE_TIME; |
| 7204 | dur -= APHY_SIGNAL_TIME; |
| 7205 | /* Ndbps = Mbps * 4 = rate(500Kbps) * 2 */ |
| 7206 | Ndps = rate * 2; |
| 7207 | nsyms = dur / APHY_SYMBOL_TIME; |
| 7208 | mac_len = |
| 7209 | ((nsyms * Ndps) - |
| 7210 | (APHY_SERVICE_NBITS + APHY_TAIL_NBITS)) / 8; |
| 7211 | } else { |
| 7212 | if (preamble_type & WLC_SHORT_PREAMBLE) |
| 7213 | dur -= BPHY_PLCP_SHORT_TIME; |
| 7214 | else |
| 7215 | dur -= BPHY_PLCP_TIME; |
| 7216 | mac_len = dur * rate; |
| 7217 | /* divide out factor of 2 in rate (1/2 mbps) */ |
| 7218 | mac_len = mac_len / 8 / 2; |
| 7219 | } |
| 7220 | return mac_len; |
| 7221 | } |
| 7222 | |
| 7223 | static uint |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 7224 | wlc_calc_ba_time(wlc_info_t *wlc, ratespec_t rspec, u8 preamble_type) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7225 | { |
| 7226 | WL_TRACE(("wl%d: wlc_calc_ba_time: rspec 0x%x, preamble_type %d\n", |
| 7227 | wlc->pub->unit, rspec, preamble_type)); |
| 7228 | /* Spec 9.6: ack rate is the highest rate in BSSBasicRateSet that is less than |
| 7229 | * or equal to the rate of the immediately previous frame in the FES |
| 7230 | */ |
| 7231 | rspec = WLC_BASIC_RATE(wlc, rspec); |
| 7232 | ASSERT(VALID_RATE_DBG(wlc, rspec)); |
| 7233 | |
| 7234 | /* BA len == 32 == 16(ctl hdr) + 4(ba len) + 8(bitmap) + 4(fcs) */ |
| 7235 | return wlc_calc_frame_time(wlc, rspec, preamble_type, |
| 7236 | (DOT11_BA_LEN + DOT11_BA_BITMAP_LEN + |
| 7237 | DOT11_FCS_LEN)); |
| 7238 | } |
| 7239 | |
| 7240 | static uint BCMFASTPATH |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 7241 | wlc_calc_ack_time(wlc_info_t *wlc, ratespec_t rspec, u8 preamble_type) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7242 | { |
| 7243 | uint dur = 0; |
| 7244 | |
| 7245 | WL_TRACE(("wl%d: wlc_calc_ack_time: rspec 0x%x, preamble_type %d\n", |
| 7246 | wlc->pub->unit, rspec, preamble_type)); |
| 7247 | /* Spec 9.6: ack rate is the highest rate in BSSBasicRateSet that is less than |
| 7248 | * or equal to the rate of the immediately previous frame in the FES |
| 7249 | */ |
| 7250 | rspec = WLC_BASIC_RATE(wlc, rspec); |
| 7251 | ASSERT(VALID_RATE_DBG(wlc, rspec)); |
| 7252 | |
| 7253 | /* ACK frame len == 14 == 2(fc) + 2(dur) + 6(ra) + 4(fcs) */ |
| 7254 | dur = |
| 7255 | wlc_calc_frame_time(wlc, rspec, preamble_type, |
| 7256 | (DOT11_ACK_LEN + DOT11_FCS_LEN)); |
| 7257 | return dur; |
| 7258 | } |
| 7259 | |
| 7260 | static uint |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 7261 | wlc_calc_cts_time(wlc_info_t *wlc, ratespec_t rspec, u8 preamble_type) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7262 | { |
| 7263 | WL_TRACE(("wl%d: wlc_calc_cts_time: ratespec 0x%x, preamble_type %d\n", |
| 7264 | wlc->pub->unit, rspec, preamble_type)); |
| 7265 | return wlc_calc_ack_time(wlc, rspec, preamble_type); |
| 7266 | } |
| 7267 | |
| 7268 | /* derive wlc->band->basic_rate[] table from 'rateset' */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 7269 | void wlc_rate_lookup_init(wlc_info_t *wlc, wlc_rateset_t *rateset) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7270 | { |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 7271 | u8 rate; |
| 7272 | u8 mandatory; |
| 7273 | u8 cck_basic = 0; |
| 7274 | u8 ofdm_basic = 0; |
| 7275 | u8 *br = wlc->band->basic_rate; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7276 | uint i; |
| 7277 | |
| 7278 | /* incoming rates are in 500kbps units as in 802.11 Supported Rates */ |
Brett Rudley | 9249ede | 2010-11-30 20:09:49 -0800 | [diff] [blame^] | 7279 | memset(br, 0, WLC_MAXRATE + 1); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7280 | |
| 7281 | /* For each basic rate in the rates list, make an entry in the |
| 7282 | * best basic lookup. |
| 7283 | */ |
| 7284 | for (i = 0; i < rateset->count; i++) { |
| 7285 | /* only make an entry for a basic rate */ |
| 7286 | if (!(rateset->rates[i] & WLC_RATE_FLAG)) |
| 7287 | continue; |
| 7288 | |
| 7289 | /* mask off basic bit */ |
| 7290 | rate = (rateset->rates[i] & RATE_MASK); |
| 7291 | |
| 7292 | if (rate > WLC_MAXRATE) { |
| 7293 | WL_ERROR(("wlc_rate_lookup_init: invalid rate 0x%X in rate set\n", rateset->rates[i])); |
| 7294 | continue; |
| 7295 | } |
| 7296 | |
| 7297 | br[rate] = rate; |
| 7298 | } |
| 7299 | |
| 7300 | /* The rate lookup table now has non-zero entries for each |
| 7301 | * basic rate, equal to the basic rate: br[basicN] = basicN |
| 7302 | * |
| 7303 | * To look up the best basic rate corresponding to any |
| 7304 | * particular rate, code can use the basic_rate table |
| 7305 | * like this |
| 7306 | * |
| 7307 | * basic_rate = wlc->band->basic_rate[tx_rate] |
| 7308 | * |
| 7309 | * Make sure there is a best basic rate entry for |
| 7310 | * every rate by walking up the table from low rates |
| 7311 | * to high, filling in holes in the lookup table |
| 7312 | */ |
| 7313 | |
| 7314 | for (i = 0; i < wlc->band->hw_rateset.count; i++) { |
| 7315 | rate = wlc->band->hw_rateset.rates[i]; |
| 7316 | ASSERT(rate <= WLC_MAXRATE); |
| 7317 | |
| 7318 | if (br[rate] != 0) { |
| 7319 | /* This rate is a basic rate. |
| 7320 | * Keep track of the best basic rate so far by |
| 7321 | * modulation type. |
| 7322 | */ |
| 7323 | if (IS_OFDM(rate)) |
| 7324 | ofdm_basic = rate; |
| 7325 | else |
| 7326 | cck_basic = rate; |
| 7327 | |
| 7328 | continue; |
| 7329 | } |
| 7330 | |
| 7331 | /* This rate is not a basic rate so figure out the |
| 7332 | * best basic rate less than this rate and fill in |
| 7333 | * the hole in the table |
| 7334 | */ |
| 7335 | |
| 7336 | br[rate] = IS_OFDM(rate) ? ofdm_basic : cck_basic; |
| 7337 | |
| 7338 | if (br[rate] != 0) |
| 7339 | continue; |
| 7340 | |
| 7341 | if (IS_OFDM(rate)) { |
| 7342 | /* In 11g and 11a, the OFDM mandatory rates are 6, 12, and 24 Mbps */ |
| 7343 | if (rate >= WLC_RATE_24M) |
| 7344 | mandatory = WLC_RATE_24M; |
| 7345 | else if (rate >= WLC_RATE_12M) |
| 7346 | mandatory = WLC_RATE_12M; |
| 7347 | else |
| 7348 | mandatory = WLC_RATE_6M; |
| 7349 | } else { |
| 7350 | /* In 11b, all the CCK rates are mandatory 1 - 11 Mbps */ |
| 7351 | mandatory = rate; |
| 7352 | } |
| 7353 | |
| 7354 | br[rate] = mandatory; |
| 7355 | } |
| 7356 | } |
| 7357 | |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 7358 | static void wlc_write_rate_shm(wlc_info_t *wlc, u8 rate, u8 basic_rate) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7359 | { |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 7360 | u8 phy_rate, index; |
| 7361 | u8 basic_phy_rate, basic_index; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 7362 | u16 dir_table, basic_table; |
| 7363 | u16 basic_ptr; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7364 | |
| 7365 | /* Shared memory address for the table we are reading */ |
| 7366 | dir_table = IS_OFDM(basic_rate) ? M_RT_DIRMAP_A : M_RT_DIRMAP_B; |
| 7367 | |
| 7368 | /* Shared memory address for the table we are writing */ |
| 7369 | basic_table = IS_OFDM(rate) ? M_RT_BBRSMAP_A : M_RT_BBRSMAP_B; |
| 7370 | |
| 7371 | /* |
| 7372 | * for a given rate, the LS-nibble of the PLCP SIGNAL field is |
| 7373 | * the index into the rate table. |
| 7374 | */ |
| 7375 | phy_rate = rate_info[rate] & RATE_MASK; |
| 7376 | basic_phy_rate = rate_info[basic_rate] & RATE_MASK; |
| 7377 | index = phy_rate & 0xf; |
| 7378 | basic_index = basic_phy_rate & 0xf; |
| 7379 | |
| 7380 | /* Find the SHM pointer to the ACK rate entry by looking in the |
| 7381 | * Direct-map Table |
| 7382 | */ |
| 7383 | basic_ptr = wlc_read_shm(wlc, (dir_table + basic_index * 2)); |
| 7384 | |
| 7385 | /* Update the SHM BSS-basic-rate-set mapping table with the pointer |
| 7386 | * to the correct basic rate for the given incoming rate |
| 7387 | */ |
| 7388 | wlc_write_shm(wlc, (basic_table + index * 2), basic_ptr); |
| 7389 | } |
| 7390 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 7391 | static const wlc_rateset_t *wlc_rateset_get_hwrs(wlc_info_t *wlc) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7392 | { |
| 7393 | const wlc_rateset_t *rs_dflt; |
| 7394 | |
| 7395 | if (WLC_PHY_11N_CAP(wlc->band)) { |
| 7396 | if (BAND_5G(wlc->band->bandtype)) |
| 7397 | rs_dflt = &ofdm_mimo_rates; |
| 7398 | else |
| 7399 | rs_dflt = &cck_ofdm_mimo_rates; |
| 7400 | } else if (wlc->band->gmode) |
| 7401 | rs_dflt = &cck_ofdm_rates; |
| 7402 | else |
| 7403 | rs_dflt = &cck_rates; |
| 7404 | |
| 7405 | return rs_dflt; |
| 7406 | } |
| 7407 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 7408 | void wlc_set_ratetable(wlc_info_t *wlc) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7409 | { |
| 7410 | const wlc_rateset_t *rs_dflt; |
| 7411 | wlc_rateset_t rs; |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 7412 | u8 rate, basic_rate; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7413 | uint i; |
| 7414 | |
| 7415 | rs_dflt = wlc_rateset_get_hwrs(wlc); |
| 7416 | ASSERT(rs_dflt != NULL); |
| 7417 | |
| 7418 | wlc_rateset_copy(rs_dflt, &rs); |
| 7419 | wlc_rateset_mcs_upd(&rs, wlc->stf->txstreams); |
| 7420 | |
| 7421 | /* walk the phy rate table and update SHM basic rate lookup table */ |
| 7422 | for (i = 0; i < rs.count; i++) { |
| 7423 | rate = rs.rates[i] & RATE_MASK; |
| 7424 | |
| 7425 | /* for a given rate WLC_BASIC_RATE returns the rate at |
| 7426 | * which a response ACK/CTS should be sent. |
| 7427 | */ |
| 7428 | basic_rate = WLC_BASIC_RATE(wlc, rate); |
| 7429 | if (basic_rate == 0) { |
| 7430 | /* This should only happen if we are using a |
| 7431 | * restricted rateset. |
| 7432 | */ |
| 7433 | basic_rate = rs.rates[0] & RATE_MASK; |
| 7434 | } |
| 7435 | |
| 7436 | wlc_write_rate_shm(wlc, rate, basic_rate); |
| 7437 | } |
| 7438 | } |
| 7439 | |
| 7440 | /* |
| 7441 | * Return true if the specified rate is supported by the specified band. |
| 7442 | * WLC_BAND_AUTO indicates the current band. |
| 7443 | */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 7444 | bool wlc_valid_rate(wlc_info_t *wlc, ratespec_t rspec, int band, bool verbose) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7445 | { |
| 7446 | wlc_rateset_t *hw_rateset; |
| 7447 | uint i; |
| 7448 | |
| 7449 | if ((band == WLC_BAND_AUTO) || (band == wlc->band->bandtype)) { |
| 7450 | hw_rateset = &wlc->band->hw_rateset; |
| 7451 | } else if (NBANDS(wlc) > 1) { |
| 7452 | hw_rateset = &wlc->bandstate[OTHERBANDUNIT(wlc)]->hw_rateset; |
| 7453 | } else { |
| 7454 | /* other band specified and we are a single band device */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 7455 | return false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7456 | } |
| 7457 | |
| 7458 | /* check if this is a mimo rate */ |
| 7459 | if (IS_MCS(rspec)) { |
| 7460 | if (!VALID_MCS((rspec & RSPEC_RATE_MASK))) |
| 7461 | goto error; |
| 7462 | |
| 7463 | return isset(hw_rateset->mcs, (rspec & RSPEC_RATE_MASK)); |
| 7464 | } |
| 7465 | |
| 7466 | for (i = 0; i < hw_rateset->count; i++) |
| 7467 | if (hw_rateset->rates[i] == RSPEC2RATE(rspec)) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 7468 | return true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7469 | error: |
| 7470 | if (verbose) { |
| 7471 | WL_ERROR(("wl%d: wlc_valid_rate: rate spec 0x%x not in hw_rateset\n", wlc->pub->unit, rspec)); |
| 7472 | } |
| 7473 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 7474 | return false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7475 | } |
| 7476 | |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 7477 | static void wlc_update_mimo_band_bwcap(wlc_info_t *wlc, u8 bwcap) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7478 | { |
| 7479 | uint i; |
| 7480 | wlcband_t *band; |
| 7481 | |
| 7482 | for (i = 0; i < NBANDS(wlc); i++) { |
| 7483 | if (IS_SINGLEBAND_5G(wlc->deviceid)) |
| 7484 | i = BAND_5G_INDEX; |
| 7485 | band = wlc->bandstate[i]; |
| 7486 | if (band->bandtype == WLC_BAND_5G) { |
| 7487 | if ((bwcap == WLC_N_BW_40ALL) |
| 7488 | || (bwcap == WLC_N_BW_20IN2G_40IN5G)) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 7489 | band->mimo_cap_40 = true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7490 | else |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 7491 | band->mimo_cap_40 = false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7492 | } else { |
| 7493 | ASSERT(band->bandtype == WLC_BAND_2G); |
| 7494 | if (bwcap == WLC_N_BW_40ALL) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 7495 | band->mimo_cap_40 = true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7496 | else |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 7497 | band->mimo_cap_40 = false; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7498 | } |
| 7499 | } |
| 7500 | |
| 7501 | wlc->mimo_band_bwcap = bwcap; |
| 7502 | } |
| 7503 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 7504 | void wlc_mod_prb_rsp_rate_table(wlc_info_t *wlc, uint frame_len) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7505 | { |
| 7506 | const wlc_rateset_t *rs_dflt; |
| 7507 | wlc_rateset_t rs; |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 7508 | u8 rate; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 7509 | u16 entry_ptr; |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 7510 | u8 plcp[D11_PHY_HDR_LEN]; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 7511 | u16 dur, sifs; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7512 | uint i; |
| 7513 | |
| 7514 | sifs = SIFS(wlc->band); |
| 7515 | |
| 7516 | rs_dflt = wlc_rateset_get_hwrs(wlc); |
| 7517 | ASSERT(rs_dflt != NULL); |
| 7518 | |
| 7519 | wlc_rateset_copy(rs_dflt, &rs); |
| 7520 | wlc_rateset_mcs_upd(&rs, wlc->stf->txstreams); |
| 7521 | |
| 7522 | /* walk the phy rate table and update MAC core SHM basic rate table entries */ |
| 7523 | for (i = 0; i < rs.count; i++) { |
| 7524 | rate = rs.rates[i] & RATE_MASK; |
| 7525 | |
| 7526 | entry_ptr = wlc_rate_shm_offset(wlc, rate); |
| 7527 | |
| 7528 | /* Calculate the Probe Response PLCP for the given rate */ |
| 7529 | wlc_compute_plcp(wlc, rate, frame_len, plcp); |
| 7530 | |
| 7531 | /* Calculate the duration of the Probe Response frame plus SIFS for the MAC */ |
| 7532 | dur = |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 7533 | (u16) wlc_calc_frame_time(wlc, rate, WLC_LONG_PREAMBLE, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7534 | frame_len); |
| 7535 | dur += sifs; |
| 7536 | |
| 7537 | /* Update the SHM Rate Table entry Probe Response values */ |
| 7538 | wlc_write_shm(wlc, entry_ptr + M_RT_PRS_PLCP_POS, |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 7539 | (u16) (plcp[0] + (plcp[1] << 8))); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7540 | wlc_write_shm(wlc, entry_ptr + M_RT_PRS_PLCP_POS + 2, |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 7541 | (u16) (plcp[2] + (plcp[3] << 8))); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7542 | wlc_write_shm(wlc, entry_ptr + M_RT_PRS_DUR_POS, dur); |
| 7543 | } |
| 7544 | } |
| 7545 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 7546 | u16 |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 7547 | wlc_compute_bcntsfoff(wlc_info_t *wlc, ratespec_t rspec, bool short_preamble, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7548 | bool phydelay) |
| 7549 | { |
| 7550 | uint bcntsfoff = 0; |
| 7551 | |
| 7552 | if (IS_MCS(rspec)) { |
| 7553 | WL_ERROR(("wl%d: recd beacon with mcs rate; rspec 0x%x\n", |
| 7554 | wlc->pub->unit, rspec)); |
| 7555 | } else if (IS_OFDM(rspec)) { |
| 7556 | /* tx delay from MAC through phy to air (2.1 usec) + |
| 7557 | * phy header time (preamble + PLCP SIGNAL == 20 usec) + |
| 7558 | * PLCP SERVICE + MAC header time (SERVICE + FC + DUR + A1 + A2 + A3 + SEQ == 26 |
| 7559 | * bytes at beacon rate) |
| 7560 | */ |
| 7561 | bcntsfoff += phydelay ? D11A_PHY_TX_DELAY : 0; |
| 7562 | bcntsfoff += APHY_PREAMBLE_TIME + APHY_SIGNAL_TIME; |
| 7563 | bcntsfoff += |
| 7564 | wlc_compute_airtime(wlc, rspec, |
| 7565 | APHY_SERVICE_NBITS / 8 + |
| 7566 | DOT11_MAC_HDR_LEN); |
| 7567 | } else { |
| 7568 | /* tx delay from MAC through phy to air (3.4 usec) + |
| 7569 | * phy header time (long preamble + PLCP == 192 usec) + |
| 7570 | * MAC header time (FC + DUR + A1 + A2 + A3 + SEQ == 24 bytes at beacon rate) |
| 7571 | */ |
| 7572 | bcntsfoff += phydelay ? D11B_PHY_TX_DELAY : 0; |
| 7573 | bcntsfoff += |
| 7574 | short_preamble ? D11B_PHY_SPREHDR_TIME : |
| 7575 | D11B_PHY_LPREHDR_TIME; |
| 7576 | bcntsfoff += wlc_compute_airtime(wlc, rspec, DOT11_MAC_HDR_LEN); |
| 7577 | } |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 7578 | return (u16) (bcntsfoff); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7579 | } |
| 7580 | |
| 7581 | /* Max buffering needed for beacon template/prb resp template is 142 bytes. |
| 7582 | * |
| 7583 | * PLCP header is 6 bytes. |
| 7584 | * 802.11 A3 header is 24 bytes. |
| 7585 | * Max beacon frame body template length is 112 bytes. |
| 7586 | * Max probe resp frame body template length is 110 bytes. |
| 7587 | * |
| 7588 | * *len on input contains the max length of the packet available. |
| 7589 | * |
| 7590 | * The *len value is set to the number of bytes in buf used, and starts with the PLCP |
| 7591 | * and included up to, but not including, the 4 byte FCS. |
| 7592 | */ |
| 7593 | static void |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 7594 | wlc_bcn_prb_template(wlc_info_t *wlc, uint type, ratespec_t bcn_rspec, |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 7595 | wlc_bsscfg_t *cfg, u16 *buf, int *len) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7596 | { |
| 7597 | cck_phy_hdr_t *plcp; |
| 7598 | struct dot11_management_header *h; |
| 7599 | int hdr_len, body_len; |
| 7600 | |
| 7601 | ASSERT(*len >= 142); |
| 7602 | ASSERT(type == FC_BEACON || type == FC_PROBE_RESP); |
| 7603 | |
| 7604 | if (MBSS_BCN_ENAB(cfg) && type == FC_BEACON) |
| 7605 | hdr_len = DOT11_MAC_HDR_LEN; |
| 7606 | else |
| 7607 | hdr_len = D11_PHY_HDR_LEN + DOT11_MAC_HDR_LEN; |
| 7608 | body_len = *len - hdr_len; /* calc buffer size provided for frame body */ |
| 7609 | |
| 7610 | *len = hdr_len + body_len; /* return actual size */ |
| 7611 | |
| 7612 | /* format PHY and MAC headers */ |
Brett Rudley | 9249ede | 2010-11-30 20:09:49 -0800 | [diff] [blame^] | 7613 | memset((char *)buf, 0, hdr_len); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7614 | |
| 7615 | plcp = (cck_phy_hdr_t *) buf; |
| 7616 | |
| 7617 | /* PLCP for Probe Response frames are filled in from core's rate table */ |
| 7618 | if (type == FC_BEACON && !MBSS_BCN_ENAB(cfg)) { |
| 7619 | /* fill in PLCP */ |
| 7620 | wlc_compute_plcp(wlc, bcn_rspec, |
| 7621 | (DOT11_MAC_HDR_LEN + body_len + DOT11_FCS_LEN), |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 7622 | (u8 *) plcp); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7623 | |
| 7624 | } |
| 7625 | /* "Regular" and 16 MBSS but not for 4 MBSS */ |
| 7626 | /* Update the phytxctl for the beacon based on the rspec */ |
| 7627 | if (!SOFTBCN_ENAB(cfg)) |
| 7628 | wlc_beacon_phytxctl_txant_upd(wlc, bcn_rspec); |
| 7629 | |
| 7630 | if (MBSS_BCN_ENAB(cfg) && type == FC_BEACON) |
| 7631 | h = (struct dot11_management_header *)&plcp[0]; |
| 7632 | else |
| 7633 | h = (struct dot11_management_header *)&plcp[1]; |
| 7634 | |
| 7635 | /* fill in 802.11 header */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 7636 | h->fc = htol16((u16) type); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7637 | |
| 7638 | /* DUR is 0 for multicast bcn, or filled in by MAC for prb resp */ |
| 7639 | /* A1 filled in by MAC for prb resp, broadcast for bcn */ |
| 7640 | if (type == FC_BEACON) |
| 7641 | bcopy((const char *)ðer_bcast, (char *)&h->da, |
| 7642 | ETHER_ADDR_LEN); |
| 7643 | bcopy((char *)&cfg->cur_etheraddr, (char *)&h->sa, ETHER_ADDR_LEN); |
| 7644 | bcopy((char *)&cfg->BSSID, (char *)&h->bssid, ETHER_ADDR_LEN); |
| 7645 | |
| 7646 | /* SEQ filled in by MAC */ |
| 7647 | |
| 7648 | return; |
| 7649 | } |
| 7650 | |
| 7651 | int wlc_get_header_len() |
| 7652 | { |
| 7653 | return TXOFF; |
| 7654 | } |
| 7655 | |
| 7656 | /* Update a beacon for a particular BSS |
| 7657 | * For MBSS, this updates the software template and sets "latest" to the index of the |
| 7658 | * template updated. |
| 7659 | * Otherwise, it updates the hardware template. |
| 7660 | */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 7661 | void wlc_bss_update_beacon(wlc_info_t *wlc, wlc_bsscfg_t *cfg) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7662 | { |
| 7663 | int len = BCN_TMPL_LEN; |
| 7664 | |
| 7665 | /* Clear the soft intmask */ |
| 7666 | wlc->defmacintmask &= ~MI_BCNTPL; |
| 7667 | |
| 7668 | if (!cfg->up) { /* Only allow updates on an UP bss */ |
| 7669 | return; |
| 7670 | } |
| 7671 | |
| 7672 | if (MBSS_BCN_ENAB(cfg)) { /* Optimize: Some of if/else could be combined */ |
| 7673 | } else if (HWBCN_ENAB(cfg)) { /* Hardware beaconing for this config */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 7674 | u16 bcn[BCN_TMPL_LEN / 2]; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 7675 | u32 both_valid = MCMD_BCN0VLD | MCMD_BCN1VLD; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7676 | d11regs_t *regs = wlc->regs; |
Brett Rudley | e69284f | 2010-11-16 15:45:48 -0800 | [diff] [blame] | 7677 | struct osl_info *osh = NULL; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7678 | |
| 7679 | osh = wlc->osh; |
| 7680 | |
| 7681 | /* Check if both templates are in use, if so sched. an interrupt |
| 7682 | * that will call back into this routine |
| 7683 | */ |
| 7684 | if ((R_REG(osh, ®s->maccommand) & both_valid) == both_valid) { |
| 7685 | /* clear any previous status */ |
| 7686 | W_REG(osh, ®s->macintstatus, MI_BCNTPL); |
| 7687 | } |
| 7688 | /* Check that after scheduling the interrupt both of the |
| 7689 | * templates are still busy. if not clear the int. & remask |
| 7690 | */ |
| 7691 | if ((R_REG(osh, ®s->maccommand) & both_valid) == both_valid) { |
| 7692 | wlc->defmacintmask |= MI_BCNTPL; |
| 7693 | return; |
| 7694 | } |
| 7695 | |
| 7696 | wlc->bcn_rspec = |
| 7697 | wlc_lowest_basic_rspec(wlc, &cfg->current_bss->rateset); |
| 7698 | ASSERT(wlc_valid_rate |
| 7699 | (wlc, wlc->bcn_rspec, |
| 7700 | CHSPEC_IS2G(cfg->current_bss-> |
| 7701 | chanspec) ? WLC_BAND_2G : WLC_BAND_5G, |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 7702 | true)); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7703 | |
| 7704 | /* update the template and ucode shm */ |
| 7705 | wlc_bcn_prb_template(wlc, FC_BEACON, wlc->bcn_rspec, cfg, bcn, |
| 7706 | &len); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 7707 | wlc_write_hw_bcntemplates(wlc, bcn, len, false); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7708 | } |
| 7709 | } |
| 7710 | |
| 7711 | /* |
| 7712 | * Update all beacons for the system. |
| 7713 | */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 7714 | void wlc_update_beacon(wlc_info_t *wlc) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7715 | { |
| 7716 | int idx; |
| 7717 | wlc_bsscfg_t *bsscfg; |
| 7718 | |
| 7719 | /* update AP or IBSS beacons */ |
| 7720 | FOREACH_BSS(wlc, idx, bsscfg) { |
| 7721 | if (bsscfg->up && (BSSCFG_AP(bsscfg) || !bsscfg->BSS)) |
| 7722 | wlc_bss_update_beacon(wlc, bsscfg); |
| 7723 | } |
| 7724 | } |
| 7725 | |
| 7726 | /* Write ssid into shared memory */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 7727 | void wlc_shm_ssid_upd(wlc_info_t *wlc, wlc_bsscfg_t *cfg) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7728 | { |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 7729 | u8 *ssidptr = cfg->SSID; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 7730 | u16 base = M_SSID; |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 7731 | u8 ssidbuf[DOT11_MAX_SSID_LEN]; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7732 | |
| 7733 | /* padding the ssid with zero and copy it into shm */ |
Brett Rudley | 9249ede | 2010-11-30 20:09:49 -0800 | [diff] [blame^] | 7734 | memset(ssidbuf, 0, DOT11_MAX_SSID_LEN); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7735 | bcopy(ssidptr, ssidbuf, cfg->SSID_len); |
| 7736 | |
| 7737 | wlc_copyto_shm(wlc, base, ssidbuf, DOT11_MAX_SSID_LEN); |
| 7738 | |
| 7739 | if (!MBSS_BCN_ENAB(cfg)) |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 7740 | wlc_write_shm(wlc, M_SSIDLEN, (u16) cfg->SSID_len); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7741 | } |
| 7742 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 7743 | void wlc_update_probe_resp(wlc_info_t *wlc, bool suspend) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7744 | { |
| 7745 | int idx; |
| 7746 | wlc_bsscfg_t *bsscfg; |
| 7747 | |
| 7748 | /* update AP or IBSS probe responses */ |
| 7749 | FOREACH_BSS(wlc, idx, bsscfg) { |
| 7750 | if (bsscfg->up && (BSSCFG_AP(bsscfg) || !bsscfg->BSS)) |
| 7751 | wlc_bss_update_probe_resp(wlc, bsscfg, suspend); |
| 7752 | } |
| 7753 | } |
| 7754 | |
| 7755 | void |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 7756 | wlc_bss_update_probe_resp(wlc_info_t *wlc, wlc_bsscfg_t *cfg, bool suspend) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7757 | { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 7758 | u16 prb_resp[BCN_TMPL_LEN / 2]; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7759 | int len = BCN_TMPL_LEN; |
| 7760 | |
| 7761 | /* write the probe response to hardware, or save in the config structure */ |
| 7762 | if (!MBSS_PRB_ENAB(cfg)) { |
| 7763 | |
| 7764 | /* create the probe response template */ |
| 7765 | wlc_bcn_prb_template(wlc, FC_PROBE_RESP, 0, cfg, prb_resp, |
| 7766 | &len); |
| 7767 | |
| 7768 | if (suspend) |
| 7769 | wlc_suspend_mac_and_wait(wlc); |
| 7770 | |
| 7771 | /* write the probe response into the template region */ |
| 7772 | wlc_bmac_write_template_ram(wlc->hw, T_PRS_TPL_BASE, |
| 7773 | (len + 3) & ~3, prb_resp); |
| 7774 | |
| 7775 | /* write the length of the probe response frame (+PLCP/-FCS) */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 7776 | wlc_write_shm(wlc, M_PRB_RESP_FRM_LEN, (u16) len); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7777 | |
| 7778 | /* write the SSID and SSID length */ |
| 7779 | wlc_shm_ssid_upd(wlc, cfg); |
| 7780 | |
| 7781 | /* |
| 7782 | * Write PLCP headers and durations for probe response frames at all rates. |
| 7783 | * Use the actual frame length covered by the PLCP header for the call to |
| 7784 | * wlc_mod_prb_rsp_rate_table() by subtracting the PLCP len and adding the FCS. |
| 7785 | */ |
| 7786 | len += (-D11_PHY_HDR_LEN + DOT11_FCS_LEN); |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 7787 | wlc_mod_prb_rsp_rate_table(wlc, (u16) len); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7788 | |
| 7789 | if (suspend) |
| 7790 | wlc_enable_mac(wlc); |
| 7791 | } else { /* Generating probe resp in sw; update local template */ |
| 7792 | ASSERT(0 && "No software probe response support without MBSS"); |
| 7793 | } |
| 7794 | } |
| 7795 | |
| 7796 | /* prepares pdu for transmission. returns BCM error codes */ |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 7797 | int wlc_prep_pdu(wlc_info_t *wlc, struct sk_buff *pdu, uint *fifop) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7798 | { |
Brett Rudley | e69284f | 2010-11-16 15:45:48 -0800 | [diff] [blame] | 7799 | struct osl_info *osh; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7800 | uint fifo; |
| 7801 | d11txh_t *txh; |
| 7802 | struct dot11_header *h; |
| 7803 | struct scb *scb; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 7804 | u16 fc; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7805 | |
| 7806 | osh = wlc->osh; |
| 7807 | |
| 7808 | ASSERT(pdu); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 7809 | txh = (d11txh_t *) (pdu->data); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7810 | ASSERT(txh); |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 7811 | h = (struct dot11_header *)((u8 *) (txh + 1) + D11_PHY_HDR_LEN); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7812 | ASSERT(h); |
| 7813 | fc = ltoh16(h->fc); |
| 7814 | |
| 7815 | /* get the pkt queue info. This was put at wlc_sendctl or wlc_send for PDU */ |
| 7816 | fifo = ltoh16(txh->TxFrameID) & TXFID_QUEUE_MASK; |
| 7817 | |
| 7818 | scb = NULL; |
| 7819 | |
| 7820 | *fifop = fifo; |
| 7821 | |
| 7822 | /* return if insufficient dma resources */ |
| 7823 | if (TXAVAIL(wlc, fifo) < MAX_DMA_SEGS) { |
| 7824 | /* Mark precedences related to this FIFO, unsendable */ |
| 7825 | WLC_TX_FIFO_CLEAR(wlc, fifo); |
| 7826 | return BCME_BUSY; |
| 7827 | } |
| 7828 | |
| 7829 | if (FC_TYPE(ltoh16(txh->MacFrameControl)) != FC_TYPE_DATA) |
| 7830 | WLCNTINCR(wlc->pub->_cnt->txctl); |
| 7831 | |
| 7832 | return 0; |
| 7833 | } |
| 7834 | |
| 7835 | /* init tx reported rate mechanism */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 7836 | void wlc_reprate_init(wlc_info_t *wlc) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7837 | { |
| 7838 | int i; |
| 7839 | wlc_bsscfg_t *bsscfg; |
| 7840 | |
| 7841 | FOREACH_BSS(wlc, i, bsscfg) { |
| 7842 | wlc_bsscfg_reprate_init(bsscfg); |
| 7843 | } |
| 7844 | } |
| 7845 | |
| 7846 | /* per bsscfg init tx reported rate mechanism */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 7847 | void wlc_bsscfg_reprate_init(wlc_bsscfg_t *bsscfg) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7848 | { |
| 7849 | bsscfg->txrspecidx = 0; |
Brett Rudley | 9249ede | 2010-11-30 20:09:49 -0800 | [diff] [blame^] | 7850 | memset((char *)bsscfg->txrspec, 0, sizeof(bsscfg->txrspec)); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7851 | } |
| 7852 | |
| 7853 | /* Retrieve a consolidated set of revision information, |
| 7854 | * typically for the WLC_GET_REVINFO ioctl |
| 7855 | */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 7856 | int wlc_get_revision_info(wlc_info_t *wlc, void *buf, uint len) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7857 | { |
| 7858 | wlc_rev_info_t *rinfo = (wlc_rev_info_t *) buf; |
| 7859 | |
| 7860 | if (len < WL_REV_INFO_LEGACY_LENGTH) |
| 7861 | return BCME_BUFTOOSHORT; |
| 7862 | |
| 7863 | rinfo->vendorid = wlc->vendorid; |
| 7864 | rinfo->deviceid = wlc->deviceid; |
| 7865 | rinfo->radiorev = (wlc->band->radiorev << IDCODE_REV_SHIFT) | |
| 7866 | (wlc->band->radioid << IDCODE_ID_SHIFT); |
| 7867 | rinfo->chiprev = wlc->pub->sih->chiprev; |
| 7868 | rinfo->corerev = wlc->pub->corerev; |
| 7869 | rinfo->boardid = wlc->pub->sih->boardtype; |
| 7870 | rinfo->boardvendor = wlc->pub->sih->boardvendor; |
| 7871 | rinfo->boardrev = wlc->pub->boardrev; |
| 7872 | rinfo->ucoderev = wlc->ucode_rev; |
| 7873 | rinfo->driverrev = EPI_VERSION_NUM; |
| 7874 | rinfo->bus = wlc->pub->sih->bustype; |
| 7875 | rinfo->chipnum = wlc->pub->sih->chip; |
| 7876 | |
Greg Kroah-Hartman | ce0f1b8 | 2010-10-08 11:44:45 -0700 | [diff] [blame] | 7877 | if (len >= (offsetof(wlc_rev_info_t, chippkg))) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7878 | rinfo->phytype = wlc->band->phytype; |
| 7879 | rinfo->phyrev = wlc->band->phyrev; |
| 7880 | rinfo->anarev = 0; /* obsolete stuff, suppress */ |
| 7881 | } |
| 7882 | |
| 7883 | if (len >= sizeof(*rinfo)) { |
| 7884 | rinfo->chippkg = wlc->pub->sih->chippkg; |
| 7885 | } |
| 7886 | |
| 7887 | return BCME_OK; |
| 7888 | } |
| 7889 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 7890 | void wlc_default_rateset(wlc_info_t *wlc, wlc_rateset_t *rs) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7891 | { |
| 7892 | wlc_rateset_default(rs, NULL, wlc->band->phytype, wlc->band->bandtype, |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 7893 | false, RATE_MASK_FULL, (bool) N_ENAB(wlc->pub), |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7894 | CHSPEC_WLC_BW(wlc->default_bss->chanspec), |
| 7895 | wlc->stf->txstreams); |
| 7896 | } |
| 7897 | |
Greg Kroah-Hartman | 0d2f072 | 2010-10-08 14:28:21 -0700 | [diff] [blame] | 7898 | static void wlc_bss_default_init(wlc_info_t *wlc) |
Jason Cooper | a2627bc | 2010-09-14 09:45:31 -0400 | [diff] [blame] | 7899 | { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7900 | chanspec_t chanspec; |
| 7901 | wlcband_t *band; |
| 7902 | wlc_bss_info_t *bi = wlc->default_bss; |
| 7903 | |
| 7904 | /* init default and target BSS with some sane initial values */ |
Brett Rudley | 9249ede | 2010-11-30 20:09:49 -0800 | [diff] [blame^] | 7905 | memset((char *)(bi), 0, sizeof(wlc_bss_info_t)); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7906 | bi->beacon_period = ISSIM_ENAB(wlc->pub->sih) ? BEACON_INTERVAL_DEF_QT : |
| 7907 | BEACON_INTERVAL_DEFAULT; |
| 7908 | bi->dtim_period = ISSIM_ENAB(wlc->pub->sih) ? DTIM_INTERVAL_DEF_QT : |
| 7909 | DTIM_INTERVAL_DEFAULT; |
| 7910 | |
| 7911 | /* fill the default channel as the first valid channel |
| 7912 | * starting from the 2G channels |
| 7913 | */ |
| 7914 | chanspec = CH20MHZ_CHSPEC(1); |
| 7915 | ASSERT(chanspec != INVCHANSPEC); |
| 7916 | |
| 7917 | wlc->home_chanspec = bi->chanspec = chanspec; |
| 7918 | |
| 7919 | /* find the band of our default channel */ |
| 7920 | band = wlc->band; |
| 7921 | if (NBANDS(wlc) > 1 && band->bandunit != CHSPEC_WLCBANDUNIT(chanspec)) |
| 7922 | band = wlc->bandstate[OTHERBANDUNIT(wlc)]; |
| 7923 | |
| 7924 | /* init bss rates to the band specific default rate set */ |
| 7925 | wlc_rateset_default(&bi->rateset, NULL, band->phytype, band->bandtype, |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 7926 | false, RATE_MASK_FULL, (bool) N_ENAB(wlc->pub), |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7927 | CHSPEC_WLC_BW(chanspec), wlc->stf->txstreams); |
| 7928 | |
| 7929 | if (N_ENAB(wlc->pub)) |
| 7930 | bi->flags |= WLC_BSS_HT; |
| 7931 | } |
| 7932 | |
| 7933 | /* Deferred event processing */ |
| 7934 | static void wlc_process_eventq(void *arg) |
| 7935 | { |
| 7936 | wlc_info_t *wlc = (wlc_info_t *) arg; |
| 7937 | wlc_event_t *etmp; |
| 7938 | |
| 7939 | while ((etmp = wlc_eventq_deq(wlc->eventq))) { |
| 7940 | /* Perform OS specific event processing */ |
| 7941 | wl_event(wlc->wl, etmp->event.ifname, etmp); |
| 7942 | if (etmp->data) { |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 7943 | kfree(etmp->data); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7944 | etmp->data = NULL; |
| 7945 | } |
| 7946 | wlc_event_free(wlc->eventq, etmp); |
| 7947 | } |
| 7948 | } |
| 7949 | |
| 7950 | void |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 7951 | wlc_uint64_sub(u32 *a_high, u32 *a_low, u32 b_high, u32 b_low) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7952 | { |
| 7953 | if (b_low > *a_low) { |
| 7954 | /* low half needs a carry */ |
| 7955 | b_high += 1; |
| 7956 | } |
| 7957 | *a_low -= b_low; |
| 7958 | *a_high -= b_high; |
| 7959 | } |
| 7960 | |
| 7961 | static ratespec_t |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 7962 | mac80211_wlc_set_nrate(wlc_info_t *wlc, wlcband_t *cur_band, u32 int_val) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7963 | { |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 7964 | u8 stf = (int_val & NRATE_STF_MASK) >> NRATE_STF_SHIFT; |
| 7965 | u8 rate = int_val & NRATE_RATE_MASK; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 7966 | ratespec_t rspec; |
| 7967 | bool ismcs = ((int_val & NRATE_MCS_INUSE) == NRATE_MCS_INUSE); |
| 7968 | bool issgi = ((int_val & NRATE_SGI_MASK) >> NRATE_SGI_SHIFT); |
| 7969 | bool override_mcs_only = ((int_val & NRATE_OVERRIDE_MCS_ONLY) |
| 7970 | == NRATE_OVERRIDE_MCS_ONLY); |
| 7971 | int bcmerror = 0; |
| 7972 | |
| 7973 | if (!ismcs) { |
| 7974 | return (ratespec_t) rate; |
| 7975 | } |
| 7976 | |
| 7977 | /* validate the combination of rate/mcs/stf is allowed */ |
| 7978 | if (N_ENAB(wlc->pub) && ismcs) { |
| 7979 | /* mcs only allowed when nmode */ |
| 7980 | if (stf > PHY_TXC1_MODE_SDM) { |
| 7981 | WL_ERROR(("wl%d: %s: Invalid stf\n", WLCWLUNIT(wlc), |
| 7982 | __func__)); |
| 7983 | bcmerror = BCME_RANGE; |
| 7984 | goto done; |
| 7985 | } |
| 7986 | |
| 7987 | /* mcs 32 is a special case, DUP mode 40 only */ |
| 7988 | if (rate == 32) { |
| 7989 | if (!CHSPEC_IS40(wlc->home_chanspec) || |
| 7990 | ((stf != PHY_TXC1_MODE_SISO) |
| 7991 | && (stf != PHY_TXC1_MODE_CDD))) { |
| 7992 | WL_ERROR(("wl%d: %s: Invalid mcs 32\n", |
| 7993 | WLCWLUNIT(wlc), __func__)); |
| 7994 | bcmerror = BCME_RANGE; |
| 7995 | goto done; |
| 7996 | } |
| 7997 | /* mcs > 7 must use stf SDM */ |
| 7998 | } else if (rate > HIGHEST_SINGLE_STREAM_MCS) { |
| 7999 | /* mcs > 7 must use stf SDM */ |
| 8000 | if (stf != PHY_TXC1_MODE_SDM) { |
| 8001 | WL_TRACE(("wl%d: %s: enabling SDM mode for mcs %d\n", WLCWLUNIT(wlc), __func__, rate)); |
| 8002 | stf = PHY_TXC1_MODE_SDM; |
| 8003 | } |
| 8004 | } else { |
| 8005 | /* MCS 0-7 may use SISO, CDD, and for phy_rev >= 3 STBC */ |
| 8006 | if ((stf > PHY_TXC1_MODE_STBC) || |
| 8007 | (!WLC_STBC_CAP_PHY(wlc) |
| 8008 | && (stf == PHY_TXC1_MODE_STBC))) { |
| 8009 | WL_ERROR(("wl%d: %s: Invalid STBC\n", |
| 8010 | WLCWLUNIT(wlc), __func__)); |
| 8011 | bcmerror = BCME_RANGE; |
| 8012 | goto done; |
| 8013 | } |
| 8014 | } |
| 8015 | } else if (IS_OFDM(rate)) { |
| 8016 | if ((stf != PHY_TXC1_MODE_CDD) && (stf != PHY_TXC1_MODE_SISO)) { |
| 8017 | WL_ERROR(("wl%d: %s: Invalid OFDM\n", WLCWLUNIT(wlc), |
| 8018 | __func__)); |
| 8019 | bcmerror = BCME_RANGE; |
| 8020 | goto done; |
| 8021 | } |
| 8022 | } else if (IS_CCK(rate)) { |
| 8023 | if ((cur_band->bandtype != WLC_BAND_2G) |
| 8024 | || (stf != PHY_TXC1_MODE_SISO)) { |
| 8025 | WL_ERROR(("wl%d: %s: Invalid CCK\n", WLCWLUNIT(wlc), |
| 8026 | __func__)); |
| 8027 | bcmerror = BCME_RANGE; |
| 8028 | goto done; |
| 8029 | } |
| 8030 | } else { |
| 8031 | WL_ERROR(("wl%d: %s: Unknown rate type\n", WLCWLUNIT(wlc), |
| 8032 | __func__)); |
| 8033 | bcmerror = BCME_RANGE; |
| 8034 | goto done; |
| 8035 | } |
| 8036 | /* make sure multiple antennae are available for non-siso rates */ |
| 8037 | if ((stf != PHY_TXC1_MODE_SISO) && (wlc->stf->txstreams == 1)) { |
| 8038 | WL_ERROR(("wl%d: %s: SISO antenna but !SISO request\n", |
| 8039 | WLCWLUNIT(wlc), __func__)); |
| 8040 | bcmerror = BCME_RANGE; |
| 8041 | goto done; |
| 8042 | } |
| 8043 | |
| 8044 | rspec = rate; |
| 8045 | if (ismcs) { |
| 8046 | rspec |= RSPEC_MIMORATE; |
| 8047 | /* For STBC populate the STC field of the ratespec */ |
| 8048 | if (stf == PHY_TXC1_MODE_STBC) { |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 8049 | u8 stc; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 8050 | stc = 1; /* Nss for single stream is always 1 */ |
| 8051 | rspec |= (stc << RSPEC_STC_SHIFT); |
| 8052 | } |
| 8053 | } |
| 8054 | |
| 8055 | rspec |= (stf << RSPEC_STF_SHIFT); |
| 8056 | |
| 8057 | if (override_mcs_only) |
| 8058 | rspec |= RSPEC_OVERRIDE_MCS_ONLY; |
| 8059 | |
| 8060 | if (issgi) |
| 8061 | rspec |= RSPEC_SHORT_GI; |
| 8062 | |
| 8063 | if ((rate != 0) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 8064 | && !wlc_valid_rate(wlc, rspec, cur_band->bandtype, true)) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 8065 | return rate; |
| 8066 | } |
| 8067 | |
| 8068 | return rspec; |
| 8069 | done: |
| 8070 | WL_ERROR(("Hoark\n")); |
| 8071 | return rate; |
| 8072 | } |
| 8073 | |
| 8074 | /* formula: IDLE_BUSY_RATIO_X_16 = (100-duty_cycle)/duty_cycle*16 */ |
| 8075 | static int |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 8076 | wlc_duty_cycle_set(wlc_info_t *wlc, int duty_cycle, bool isOFDM, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 8077 | bool writeToShm) |
| 8078 | { |
| 8079 | int idle_busy_ratio_x_16 = 0; |
| 8080 | uint offset = |
| 8081 | isOFDM ? M_TX_IDLE_BUSY_RATIO_X_16_OFDM : |
| 8082 | M_TX_IDLE_BUSY_RATIO_X_16_CCK; |
| 8083 | if (duty_cycle > 100 || duty_cycle < 0) { |
| 8084 | WL_ERROR(("wl%d: duty cycle value off limit\n", |
| 8085 | wlc->pub->unit)); |
| 8086 | return BCME_RANGE; |
| 8087 | } |
| 8088 | if (duty_cycle) |
| 8089 | idle_busy_ratio_x_16 = (100 - duty_cycle) * 16 / duty_cycle; |
| 8090 | /* Only write to shared memory when wl is up */ |
| 8091 | if (writeToShm) |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 8092 | wlc_write_shm(wlc, offset, (u16) idle_busy_ratio_x_16); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 8093 | |
| 8094 | if (isOFDM) |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 8095 | wlc->tx_duty_cycle_ofdm = (u16) duty_cycle; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 8096 | else |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 8097 | wlc->tx_duty_cycle_cck = (u16) duty_cycle; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 8098 | |
| 8099 | return BCME_OK; |
| 8100 | } |
| 8101 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 8102 | /* Read a single u16 from shared memory. |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 8103 | * SHM 'offset' needs to be an even address |
| 8104 | */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 8105 | u16 wlc_read_shm(wlc_info_t *wlc, uint offset) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 8106 | { |
| 8107 | return wlc_bmac_read_shm(wlc->hw, offset); |
| 8108 | } |
| 8109 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 8110 | /* Write a single u16 to shared memory. |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 8111 | * SHM 'offset' needs to be an even address |
| 8112 | */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 8113 | void wlc_write_shm(wlc_info_t *wlc, uint offset, u16 v) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 8114 | { |
| 8115 | wlc_bmac_write_shm(wlc->hw, offset, v); |
| 8116 | } |
| 8117 | |
| 8118 | /* Set a range of shared memory to a value. |
| 8119 | * SHM 'offset' needs to be an even address and |
| 8120 | * Range length 'len' must be an even number of bytes |
| 8121 | */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 8122 | void wlc_set_shm(wlc_info_t *wlc, uint offset, u16 v, int len) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 8123 | { |
| 8124 | /* offset and len need to be even */ |
| 8125 | ASSERT((offset & 1) == 0); |
| 8126 | ASSERT((len & 1) == 0); |
| 8127 | |
| 8128 | if (len <= 0) |
| 8129 | return; |
| 8130 | |
| 8131 | wlc_bmac_set_shm(wlc->hw, offset, v, len); |
| 8132 | } |
| 8133 | |
| 8134 | /* Copy a buffer to shared memory. |
| 8135 | * SHM 'offset' needs to be an even address and |
| 8136 | * Buffer length 'len' must be an even number of bytes |
| 8137 | */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 8138 | void wlc_copyto_shm(wlc_info_t *wlc, uint offset, const void *buf, int len) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 8139 | { |
| 8140 | /* offset and len need to be even */ |
| 8141 | ASSERT((offset & 1) == 0); |
| 8142 | ASSERT((len & 1) == 0); |
| 8143 | |
| 8144 | if (len <= 0) |
| 8145 | return; |
| 8146 | wlc_bmac_copyto_objmem(wlc->hw, offset, buf, len, OBJADDR_SHM_SEL); |
| 8147 | |
| 8148 | } |
| 8149 | |
| 8150 | /* Copy from shared memory to a buffer. |
| 8151 | * SHM 'offset' needs to be an even address and |
| 8152 | * Buffer length 'len' must be an even number of bytes |
| 8153 | */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 8154 | void wlc_copyfrom_shm(wlc_info_t *wlc, uint offset, void *buf, int len) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 8155 | { |
| 8156 | /* offset and len need to be even */ |
| 8157 | ASSERT((offset & 1) == 0); |
| 8158 | ASSERT((len & 1) == 0); |
| 8159 | |
| 8160 | if (len <= 0) |
| 8161 | return; |
| 8162 | |
| 8163 | wlc_bmac_copyfrom_objmem(wlc->hw, offset, buf, len, OBJADDR_SHM_SEL); |
| 8164 | } |
| 8165 | |
| 8166 | /* wrapper BMAC functions to for HIGH driver access */ |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 8167 | void wlc_mctrl(wlc_info_t *wlc, u32 mask, u32 val) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 8168 | { |
| 8169 | wlc_bmac_mctrl(wlc->hw, mask, val); |
| 8170 | } |
| 8171 | |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 8172 | void wlc_corereset(wlc_info_t *wlc, u32 flags) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 8173 | { |
| 8174 | wlc_bmac_corereset(wlc->hw, flags); |
| 8175 | } |
| 8176 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 8177 | void wlc_mhf(wlc_info_t *wlc, u8 idx, u16 mask, u16 val, int bands) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 8178 | { |
| 8179 | wlc_bmac_mhf(wlc->hw, idx, mask, val, bands); |
| 8180 | } |
| 8181 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 8182 | u16 wlc_mhf_get(wlc_info_t *wlc, u8 idx, int bands) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 8183 | { |
| 8184 | return wlc_bmac_mhf_get(wlc->hw, idx, bands); |
| 8185 | } |
| 8186 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 8187 | int wlc_xmtfifo_sz_get(wlc_info_t *wlc, uint fifo, uint *blocks) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 8188 | { |
| 8189 | return wlc_bmac_xmtfifo_sz_get(wlc->hw, fifo, blocks); |
| 8190 | } |
| 8191 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 8192 | void wlc_write_template_ram(wlc_info_t *wlc, int offset, int len, void *buf) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 8193 | { |
| 8194 | wlc_bmac_write_template_ram(wlc->hw, offset, len, buf); |
| 8195 | } |
| 8196 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 8197 | void wlc_write_hw_bcntemplates(wlc_info_t *wlc, void *bcn, int len, bool both) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 8198 | { |
| 8199 | wlc_bmac_write_hw_bcntemplates(wlc->hw, bcn, len, both); |
| 8200 | } |
| 8201 | |
| 8202 | void |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 8203 | wlc_set_addrmatch(wlc_info_t *wlc, int match_reg_offset, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 8204 | const struct ether_addr *addr) |
| 8205 | { |
| 8206 | wlc_bmac_set_addrmatch(wlc->hw, match_reg_offset, addr); |
| 8207 | } |
| 8208 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 8209 | void wlc_set_rcmta(wlc_info_t *wlc, int idx, const struct ether_addr *addr) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 8210 | { |
| 8211 | wlc_bmac_set_rcmta(wlc->hw, idx, addr); |
| 8212 | } |
| 8213 | |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 8214 | void wlc_read_tsf(wlc_info_t *wlc, u32 *tsf_l_ptr, u32 *tsf_h_ptr) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 8215 | { |
| 8216 | wlc_bmac_read_tsf(wlc->hw, tsf_l_ptr, tsf_h_ptr); |
| 8217 | } |
| 8218 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 8219 | void wlc_set_cwmin(wlc_info_t *wlc, u16 newmin) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 8220 | { |
| 8221 | wlc->band->CWmin = newmin; |
| 8222 | wlc_bmac_set_cwmin(wlc->hw, newmin); |
| 8223 | } |
| 8224 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 8225 | void wlc_set_cwmax(wlc_info_t *wlc, u16 newmax) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 8226 | { |
| 8227 | wlc->band->CWmax = newmax; |
| 8228 | wlc_bmac_set_cwmax(wlc->hw, newmax); |
| 8229 | } |
| 8230 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 8231 | void wlc_fifoerrors(wlc_info_t *wlc) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 8232 | { |
| 8233 | |
| 8234 | wlc_bmac_fifoerrors(wlc->hw); |
| 8235 | } |
| 8236 | |
| 8237 | /* Search mem rw utilities */ |
| 8238 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 8239 | void wlc_pllreq(wlc_info_t *wlc, bool set, mbool req_bit) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 8240 | { |
| 8241 | wlc_bmac_pllreq(wlc->hw, set, req_bit); |
| 8242 | } |
| 8243 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 8244 | void wlc_reset_bmac_done(wlc_info_t *wlc) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 8245 | { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 8246 | } |
| 8247 | |
Greg Kroah-Hartman | 41feb5e | 2010-10-05 10:09:00 -0700 | [diff] [blame] | 8248 | void wlc_ht_mimops_cap_update(wlc_info_t *wlc, u8 mimops_mode) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 8249 | { |
| 8250 | wlc->ht_cap.cap &= ~HT_CAP_MIMO_PS_MASK; |
| 8251 | wlc->ht_cap.cap |= (mimops_mode << HT_CAP_MIMO_PS_SHIFT); |
| 8252 | |
| 8253 | if (AP_ENAB(wlc->pub) && wlc->clk) { |
| 8254 | wlc_update_beacon(wlc); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 8255 | wlc_update_probe_resp(wlc, true); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 8256 | } |
| 8257 | } |
| 8258 | |
| 8259 | /* check for the particular priority flow control bit being set */ |
| 8260 | bool |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 8261 | wlc_txflowcontrol_prio_isset(wlc_info_t *wlc, wlc_txq_info_t *q, int prio) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 8262 | { |
| 8263 | uint prio_mask; |
| 8264 | |
| 8265 | if (prio == ALLPRIO) { |
| 8266 | prio_mask = TXQ_STOP_FOR_PRIOFC_MASK; |
| 8267 | } else { |
| 8268 | ASSERT(prio >= 0 && prio <= MAXPRIO); |
| 8269 | prio_mask = NBITVAL(prio); |
| 8270 | } |
| 8271 | |
| 8272 | return (q->stopped & prio_mask) == prio_mask; |
| 8273 | } |
| 8274 | |
| 8275 | /* propogate the flow control to all interfaces using the given tx queue */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 8276 | void wlc_txflowcontrol(wlc_info_t *wlc, wlc_txq_info_t *qi, bool on, int prio) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 8277 | { |
| 8278 | uint prio_bits; |
| 8279 | uint cur_bits; |
| 8280 | |
| 8281 | WL_ERROR(("%s: flow contro kicks in\n", __func__)); |
| 8282 | |
| 8283 | if (prio == ALLPRIO) { |
| 8284 | prio_bits = TXQ_STOP_FOR_PRIOFC_MASK; |
| 8285 | } else { |
| 8286 | ASSERT(prio >= 0 && prio <= MAXPRIO); |
| 8287 | prio_bits = NBITVAL(prio); |
| 8288 | } |
| 8289 | |
| 8290 | cur_bits = qi->stopped & prio_bits; |
| 8291 | |
| 8292 | /* Check for the case of no change and return early |
| 8293 | * Otherwise update the bit and continue |
| 8294 | */ |
| 8295 | if (on) { |
| 8296 | if (cur_bits == prio_bits) { |
| 8297 | return; |
| 8298 | } |
| 8299 | mboolset(qi->stopped, prio_bits); |
| 8300 | } else { |
| 8301 | if (cur_bits == 0) { |
| 8302 | return; |
| 8303 | } |
| 8304 | mboolclr(qi->stopped, prio_bits); |
| 8305 | } |
| 8306 | |
| 8307 | /* If there is a flow control override we will not change the external |
| 8308 | * flow control state. |
| 8309 | */ |
| 8310 | if (qi->stopped & ~TXQ_STOP_FOR_PRIOFC_MASK) { |
| 8311 | return; |
| 8312 | } |
| 8313 | |
| 8314 | wlc_txflowcontrol_signal(wlc, qi, on, prio); |
| 8315 | } |
| 8316 | |
| 8317 | void |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 8318 | wlc_txflowcontrol_override(wlc_info_t *wlc, wlc_txq_info_t *qi, bool on, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 8319 | uint override) |
| 8320 | { |
| 8321 | uint prev_override; |
| 8322 | |
| 8323 | ASSERT(override != 0); |
| 8324 | ASSERT((override & TXQ_STOP_FOR_PRIOFC_MASK) == 0); |
| 8325 | |
| 8326 | prev_override = (qi->stopped & ~TXQ_STOP_FOR_PRIOFC_MASK); |
| 8327 | |
| 8328 | /* Update the flow control bits and do an early return if there is |
| 8329 | * no change in the external flow control state. |
| 8330 | */ |
| 8331 | if (on) { |
| 8332 | mboolset(qi->stopped, override); |
| 8333 | /* if there was a previous override bit on, then setting this |
| 8334 | * makes no difference. |
| 8335 | */ |
| 8336 | if (prev_override) { |
| 8337 | return; |
| 8338 | } |
| 8339 | |
| 8340 | wlc_txflowcontrol_signal(wlc, qi, ON, ALLPRIO); |
| 8341 | } else { |
| 8342 | mboolclr(qi->stopped, override); |
| 8343 | /* clearing an override bit will only make a difference for |
| 8344 | * flow control if it was the only bit set. For any other |
| 8345 | * override setting, just return |
| 8346 | */ |
| 8347 | if (prev_override != override) { |
| 8348 | return; |
| 8349 | } |
| 8350 | |
| 8351 | if (qi->stopped == 0) { |
| 8352 | wlc_txflowcontrol_signal(wlc, qi, OFF, ALLPRIO); |
| 8353 | } else { |
| 8354 | int prio; |
| 8355 | |
| 8356 | for (prio = MAXPRIO; prio >= 0; prio--) { |
| 8357 | if (!mboolisset(qi->stopped, NBITVAL(prio))) |
| 8358 | wlc_txflowcontrol_signal(wlc, qi, OFF, |
| 8359 | prio); |
| 8360 | } |
| 8361 | } |
| 8362 | } |
| 8363 | } |
| 8364 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 8365 | static void wlc_txflowcontrol_reset(wlc_info_t *wlc) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 8366 | { |
| 8367 | wlc_txq_info_t *qi; |
| 8368 | |
| 8369 | for (qi = wlc->tx_queues; qi != NULL; qi = qi->next) { |
| 8370 | if (qi->stopped) { |
| 8371 | wlc_txflowcontrol_signal(wlc, qi, OFF, ALLPRIO); |
| 8372 | qi->stopped = 0; |
| 8373 | } |
| 8374 | } |
| 8375 | } |
| 8376 | |
| 8377 | static void |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 8378 | wlc_txflowcontrol_signal(wlc_info_t *wlc, wlc_txq_info_t *qi, bool on, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 8379 | int prio) |
| 8380 | { |
| 8381 | wlc_if_t *wlcif; |
| 8382 | |
| 8383 | for (wlcif = wlc->wlcif_list; wlcif != NULL; wlcif = wlcif->next) { |
| 8384 | if (wlcif->qi == qi && wlcif->flags & WLC_IF_LINKED) |
| 8385 | wl_txflowcontrol(wlc->wl, wlcif->wlif, on, prio); |
| 8386 | } |
| 8387 | } |
| 8388 | |
Brett Rudley | e69284f | 2010-11-16 15:45:48 -0800 | [diff] [blame] | 8389 | static wlc_txq_info_t *wlc_txq_alloc(wlc_info_t *wlc, struct osl_info *osh) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 8390 | { |
| 8391 | wlc_txq_info_t *qi, *p; |
| 8392 | |
| 8393 | qi = (wlc_txq_info_t *) wlc_calloc(osh, wlc->pub->unit, |
| 8394 | sizeof(wlc_txq_info_t)); |
| 8395 | if (qi == NULL) { |
| 8396 | return NULL; |
| 8397 | } |
| 8398 | |
| 8399 | /* Have enough room for control packets along with HI watermark */ |
| 8400 | /* Also, add room to txq for total psq packets if all the SCBs leave PS mode */ |
| 8401 | /* The watermark for flowcontrol to OS packets will remain the same */ |
| 8402 | pktq_init(&qi->q, WLC_PREC_COUNT, |
| 8403 | (2 * wlc->pub->tunables->datahiwat) + PKTQ_LEN_DEFAULT + |
| 8404 | wlc->pub->psq_pkts_total); |
| 8405 | |
| 8406 | /* add this queue to the the global list */ |
| 8407 | p = wlc->tx_queues; |
| 8408 | if (p == NULL) { |
| 8409 | wlc->tx_queues = qi; |
| 8410 | } else { |
| 8411 | while (p->next != NULL) |
| 8412 | p = p->next; |
| 8413 | p->next = qi; |
| 8414 | } |
| 8415 | |
| 8416 | return qi; |
| 8417 | } |
| 8418 | |
Brett Rudley | e69284f | 2010-11-16 15:45:48 -0800 | [diff] [blame] | 8419 | static void wlc_txq_free(wlc_info_t *wlc, struct osl_info *osh, |
| 8420 | wlc_txq_info_t *qi) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 8421 | { |
| 8422 | wlc_txq_info_t *p; |
| 8423 | |
| 8424 | if (qi == NULL) |
| 8425 | return; |
| 8426 | |
| 8427 | /* remove the queue from the linked list */ |
| 8428 | p = wlc->tx_queues; |
| 8429 | if (p == qi) |
| 8430 | wlc->tx_queues = p->next; |
| 8431 | else { |
| 8432 | while (p != NULL && p->next != qi) |
| 8433 | p = p->next; |
| 8434 | ASSERT(p->next == qi); |
| 8435 | if (p != NULL) |
| 8436 | p->next = p->next->next; |
| 8437 | } |
| 8438 | |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 8439 | kfree(qi); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 8440 | } |