Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [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 | */ |
| 16 | |
Joe Perches | 02f7719 | 2012-01-15 00:38:44 -0800 | [diff] [blame] | 17 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 18 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 19 | #include <linux/pci_ids.h> |
| 20 | #include <linux/if_ether.h> |
Seth Forshee | edc7651 | 2012-06-16 07:47:56 -0500 | [diff] [blame] | 21 | #include <net/cfg80211.h> |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 22 | #include <net/mac80211.h> |
| 23 | #include <brcm_hw_ids.h> |
| 24 | #include <aiutils.h> |
| 25 | #include <chipcommon.h> |
| 26 | #include "rate.h" |
| 27 | #include "scb.h" |
| 28 | #include "phy/phy_hal.h" |
| 29 | #include "channel.h" |
| 30 | #include "antsel.h" |
| 31 | #include "stf.h" |
| 32 | #include "ampdu.h" |
| 33 | #include "mac80211_if.h" |
| 34 | #include "ucode_loader.h" |
| 35 | #include "main.h" |
Alwin Beukers | 2303821 | 2011-10-18 14:02:58 +0200 | [diff] [blame] | 36 | #include "soc.h" |
Seth Forshee | e041f65 | 2012-11-15 08:07:56 -0600 | [diff] [blame] | 37 | #include "dma.h" |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 38 | #include "debug.h" |
Seth Forshee | cdf4352 | 2012-11-15 08:08:09 -0600 | [diff] [blame] | 39 | #include "brcms_trace_events.h" |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 40 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 41 | /* watchdog timer, in unit of ms */ |
Alwin Beukers | 73ffc2f | 2011-10-18 14:02:57 +0200 | [diff] [blame] | 42 | #define TIMER_INTERVAL_WATCHDOG 1000 |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 43 | /* radio monitor timer, in unit of ms */ |
Alwin Beukers | 73ffc2f | 2011-10-18 14:02:57 +0200 | [diff] [blame] | 44 | #define TIMER_INTERVAL_RADIOCHK 800 |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 45 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 46 | /* beacon interval, in unit of 1024TU */ |
Alwin Beukers | 73ffc2f | 2011-10-18 14:02:57 +0200 | [diff] [blame] | 47 | #define BEACON_INTERVAL_DEFAULT 100 |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 48 | |
| 49 | /* n-mode support capability */ |
| 50 | /* 2x2 includes both 1x1 & 2x2 devices |
| 51 | * reserved #define 2 for future when we want to separate 1x1 & 2x2 and |
| 52 | * control it independently |
| 53 | */ |
| 54 | #define WL_11N_2x2 1 |
| 55 | #define WL_11N_3x3 3 |
| 56 | #define WL_11N_4x4 4 |
| 57 | |
Alwin Beukers | 73ffc2f | 2011-10-18 14:02:57 +0200 | [diff] [blame] | 58 | #define EDCF_ACI_MASK 0x60 |
| 59 | #define EDCF_ACI_SHIFT 5 |
| 60 | #define EDCF_ECWMIN_MASK 0x0f |
| 61 | #define EDCF_ECWMAX_SHIFT 4 |
| 62 | #define EDCF_AIFSN_MASK 0x0f |
| 63 | #define EDCF_AIFSN_MAX 15 |
| 64 | #define EDCF_ECWMAX_MASK 0xf0 |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 65 | |
Alwin Beukers | 73ffc2f | 2011-10-18 14:02:57 +0200 | [diff] [blame] | 66 | #define EDCF_AC_BE_TXOP_STA 0x0000 |
| 67 | #define EDCF_AC_BK_TXOP_STA 0x0000 |
| 68 | #define EDCF_AC_VO_ACI_STA 0x62 |
| 69 | #define EDCF_AC_VO_ECW_STA 0x32 |
| 70 | #define EDCF_AC_VI_ACI_STA 0x42 |
| 71 | #define EDCF_AC_VI_ECW_STA 0x43 |
| 72 | #define EDCF_AC_BK_ECW_STA 0xA4 |
| 73 | #define EDCF_AC_VI_TXOP_STA 0x005e |
| 74 | #define EDCF_AC_VO_TXOP_STA 0x002f |
| 75 | #define EDCF_AC_BE_ACI_STA 0x03 |
| 76 | #define EDCF_AC_BE_ECW_STA 0xA4 |
| 77 | #define EDCF_AC_BK_ACI_STA 0x27 |
| 78 | #define EDCF_AC_VO_TXOP_AP 0x002f |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 79 | |
Alwin Beukers | 73ffc2f | 2011-10-18 14:02:57 +0200 | [diff] [blame] | 80 | #define EDCF_TXOP2USEC(txop) ((txop) << 5) |
| 81 | #define EDCF_ECW2CW(exp) ((1 << (exp)) - 1) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 82 | |
Alwin Beukers | 73ffc2f | 2011-10-18 14:02:57 +0200 | [diff] [blame] | 83 | #define APHY_SYMBOL_TIME 4 |
| 84 | #define APHY_PREAMBLE_TIME 16 |
| 85 | #define APHY_SIGNAL_TIME 4 |
| 86 | #define APHY_SIFS_TIME 16 |
| 87 | #define APHY_SERVICE_NBITS 16 |
| 88 | #define APHY_TAIL_NBITS 6 |
| 89 | #define BPHY_SIFS_TIME 10 |
| 90 | #define BPHY_PLCP_SHORT_TIME 96 |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 91 | |
Alwin Beukers | 73ffc2f | 2011-10-18 14:02:57 +0200 | [diff] [blame] | 92 | #define PREN_PREAMBLE 24 |
| 93 | #define PREN_MM_EXT 12 |
| 94 | #define PREN_PREAMBLE_EXT 4 |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 95 | |
| 96 | #define DOT11_MAC_HDR_LEN 24 |
Alwin Beukers | 73ffc2f | 2011-10-18 14:02:57 +0200 | [diff] [blame] | 97 | #define DOT11_ACK_LEN 10 |
| 98 | #define DOT11_BA_LEN 4 |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 99 | #define DOT11_OFDM_SIGNAL_EXTENSION 6 |
| 100 | #define DOT11_MIN_FRAG_LEN 256 |
Alwin Beukers | 73ffc2f | 2011-10-18 14:02:57 +0200 | [diff] [blame] | 101 | #define DOT11_RTS_LEN 16 |
| 102 | #define DOT11_CTS_LEN 10 |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 103 | #define DOT11_BA_BITMAP_LEN 128 |
| 104 | #define DOT11_MIN_BEACON_PERIOD 1 |
| 105 | #define DOT11_MAX_BEACON_PERIOD 0xFFFF |
Alwin Beukers | 73ffc2f | 2011-10-18 14:02:57 +0200 | [diff] [blame] | 106 | #define DOT11_MAXNUMFRAGS 16 |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 107 | #define DOT11_MAX_FRAG_LEN 2346 |
| 108 | |
Alwin Beukers | 73ffc2f | 2011-10-18 14:02:57 +0200 | [diff] [blame] | 109 | #define BPHY_PLCP_TIME 192 |
| 110 | #define RIFS_11N_TIME 2 |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 111 | |
Alwin Beukers | 73ffc2f | 2011-10-18 14:02:57 +0200 | [diff] [blame] | 112 | /* length of the BCN template area */ |
| 113 | #define BCN_TMPL_LEN 512 |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 114 | |
| 115 | /* brcms_bss_info flag bit values */ |
Alwin Beukers | 73ffc2f | 2011-10-18 14:02:57 +0200 | [diff] [blame] | 116 | #define BRCMS_BSS_HT 0x0020 /* BSS is HT (MIMO) capable */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 117 | |
Alwin Beukers | 73ffc2f | 2011-10-18 14:02:57 +0200 | [diff] [blame] | 118 | /* chip rx buffer offset */ |
| 119 | #define BRCMS_HWRXOFF 38 |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 120 | |
| 121 | /* rfdisable delay timer 500 ms, runs of ALP clock */ |
Alwin Beukers | 73ffc2f | 2011-10-18 14:02:57 +0200 | [diff] [blame] | 122 | #define RFDISABLE_DEFAULT 10000000 |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 123 | |
| 124 | #define BRCMS_TEMPSENSE_PERIOD 10 /* 10 second timeout */ |
| 125 | |
Alwin Beukers | 73ffc2f | 2011-10-18 14:02:57 +0200 | [diff] [blame] | 126 | /* synthpu_dly times in us */ |
| 127 | #define SYNTHPU_DLY_APHY_US 3700 |
| 128 | #define SYNTHPU_DLY_BPHY_US 1050 |
| 129 | #define SYNTHPU_DLY_NPHY_US 2048 |
| 130 | #define SYNTHPU_DLY_LPPHY_US 300 |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 131 | |
Alwin Beukers | 73ffc2f | 2011-10-18 14:02:57 +0200 | [diff] [blame] | 132 | #define ANTCNT 10 /* vanilla M_MAX_ANTCNT val */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 133 | |
| 134 | /* Per-AC retry limit register definitions; uses defs.h bitfield macros */ |
Alwin Beukers | 73ffc2f | 2011-10-18 14:02:57 +0200 | [diff] [blame] | 135 | #define EDCF_SHORT_S 0 |
| 136 | #define EDCF_SFB_S 4 |
| 137 | #define EDCF_LONG_S 8 |
| 138 | #define EDCF_LFB_S 12 |
| 139 | #define EDCF_SHORT_M BITFIELD_MASK(4) |
| 140 | #define EDCF_SFB_M BITFIELD_MASK(4) |
| 141 | #define EDCF_LONG_M BITFIELD_MASK(4) |
| 142 | #define EDCF_LFB_M BITFIELD_MASK(4) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 143 | |
Alwin Beukers | 73ffc2f | 2011-10-18 14:02:57 +0200 | [diff] [blame] | 144 | #define RETRY_SHORT_DEF 7 /* Default Short retry Limit */ |
| 145 | #define RETRY_SHORT_MAX 255 /* Maximum Short retry Limit */ |
| 146 | #define RETRY_LONG_DEF 4 /* Default Long retry count */ |
| 147 | #define RETRY_SHORT_FB 3 /* Short count for fb rate */ |
| 148 | #define RETRY_LONG_FB 2 /* Long count for fb rate */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 149 | |
Alwin Beukers | 73ffc2f | 2011-10-18 14:02:57 +0200 | [diff] [blame] | 150 | #define APHY_CWMIN 15 |
| 151 | #define PHY_CWMAX 1023 |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 152 | |
Alwin Beukers | 73ffc2f | 2011-10-18 14:02:57 +0200 | [diff] [blame] | 153 | #define EDCF_AIFSN_MIN 1 |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 154 | |
Alwin Beukers | 73ffc2f | 2011-10-18 14:02:57 +0200 | [diff] [blame] | 155 | #define FRAGNUM_MASK 0xF |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 156 | |
Alwin Beukers | 73ffc2f | 2011-10-18 14:02:57 +0200 | [diff] [blame] | 157 | #define APHY_SLOT_TIME 9 |
| 158 | #define BPHY_SLOT_TIME 20 |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 159 | |
Alwin Beukers | 73ffc2f | 2011-10-18 14:02:57 +0200 | [diff] [blame] | 160 | #define WL_SPURAVOID_OFF 0 |
| 161 | #define WL_SPURAVOID_ON1 1 |
| 162 | #define WL_SPURAVOID_ON2 2 |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 163 | |
| 164 | /* invalid core flags, use the saved coreflags */ |
Alwin Beukers | 73ffc2f | 2011-10-18 14:02:57 +0200 | [diff] [blame] | 165 | #define BRCMS_USE_COREFLAGS 0xffffffff |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 166 | |
| 167 | /* values for PLCPHdr_override */ |
Alwin Beukers | 73ffc2f | 2011-10-18 14:02:57 +0200 | [diff] [blame] | 168 | #define BRCMS_PLCP_AUTO -1 |
| 169 | #define BRCMS_PLCP_SHORT 0 |
| 170 | #define BRCMS_PLCP_LONG 1 |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 171 | |
| 172 | /* values for g_protection_override and n_protection_override */ |
| 173 | #define BRCMS_PROTECTION_AUTO -1 |
| 174 | #define BRCMS_PROTECTION_OFF 0 |
| 175 | #define BRCMS_PROTECTION_ON 1 |
| 176 | #define BRCMS_PROTECTION_MMHDR_ONLY 2 |
Alwin Beukers | 73ffc2f | 2011-10-18 14:02:57 +0200 | [diff] [blame] | 177 | #define BRCMS_PROTECTION_CTS_ONLY 3 |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 178 | |
| 179 | /* values for g_protection_control and n_protection_control */ |
Alwin Beukers | 73ffc2f | 2011-10-18 14:02:57 +0200 | [diff] [blame] | 180 | #define BRCMS_PROTECTION_CTL_OFF 0 |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 181 | #define BRCMS_PROTECTION_CTL_LOCAL 1 |
| 182 | #define BRCMS_PROTECTION_CTL_OVERLAP 2 |
| 183 | |
| 184 | /* values for n_protection */ |
| 185 | #define BRCMS_N_PROTECTION_OFF 0 |
| 186 | #define BRCMS_N_PROTECTION_OPTIONAL 1 |
Alwin Beukers | 73ffc2f | 2011-10-18 14:02:57 +0200 | [diff] [blame] | 187 | #define BRCMS_N_PROTECTION_20IN40 2 |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 188 | #define BRCMS_N_PROTECTION_MIXEDMODE 3 |
| 189 | |
| 190 | /* values for band specific 40MHz capabilities */ |
Alwin Beukers | 73ffc2f | 2011-10-18 14:02:57 +0200 | [diff] [blame] | 191 | #define BRCMS_N_BW_20ALL 0 |
| 192 | #define BRCMS_N_BW_40ALL 1 |
| 193 | #define BRCMS_N_BW_20IN2G_40IN5G 2 |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 194 | |
| 195 | /* bitflags for SGI support (sgi_rx iovar) */ |
| 196 | #define BRCMS_N_SGI_20 0x01 |
| 197 | #define BRCMS_N_SGI_40 0x02 |
| 198 | |
| 199 | /* defines used by the nrate iovar */ |
| 200 | /* MSC in use,indicates b0-6 holds an mcs */ |
Alwin Beukers | 73ffc2f | 2011-10-18 14:02:57 +0200 | [diff] [blame] | 201 | #define NRATE_MCS_INUSE 0x00000080 |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 202 | /* rate/mcs value */ |
Alwin Beukers | 73ffc2f | 2011-10-18 14:02:57 +0200 | [diff] [blame] | 203 | #define NRATE_RATE_MASK 0x0000007f |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 204 | /* stf mode mask: siso, cdd, stbc, sdm */ |
Alwin Beukers | 73ffc2f | 2011-10-18 14:02:57 +0200 | [diff] [blame] | 205 | #define NRATE_STF_MASK 0x0000ff00 |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 206 | /* stf mode shift */ |
Alwin Beukers | 73ffc2f | 2011-10-18 14:02:57 +0200 | [diff] [blame] | 207 | #define NRATE_STF_SHIFT 8 |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 208 | /* bit indicate to override mcs only */ |
Alwin Beukers | 73ffc2f | 2011-10-18 14:02:57 +0200 | [diff] [blame] | 209 | #define NRATE_OVERRIDE_MCS_ONLY 0x40000000 |
| 210 | #define NRATE_SGI_MASK 0x00800000 /* sgi mode */ |
| 211 | #define NRATE_SGI_SHIFT 23 /* sgi mode */ |
| 212 | #define NRATE_LDPC_CODING 0x00400000 /* adv coding in use */ |
| 213 | #define NRATE_LDPC_SHIFT 22 /* ldpc shift */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 214 | |
Alwin Beukers | 73ffc2f | 2011-10-18 14:02:57 +0200 | [diff] [blame] | 215 | #define NRATE_STF_SISO 0 /* stf mode SISO */ |
| 216 | #define NRATE_STF_CDD 1 /* stf mode CDD */ |
| 217 | #define NRATE_STF_STBC 2 /* stf mode STBC */ |
| 218 | #define NRATE_STF_SDM 3 /* stf mode SDM */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 219 | |
Alwin Beukers | 73ffc2f | 2011-10-18 14:02:57 +0200 | [diff] [blame] | 220 | #define MAX_DMA_SEGS 4 |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 221 | |
Seth Forshee | 75be3e2 | 2012-11-15 08:07:58 -0600 | [diff] [blame] | 222 | /* # of entries in Tx FIFO */ |
| 223 | #define NTXD 64 |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 224 | /* Max # of entries in Rx FIFO based on 4kb page size */ |
Alwin Beukers | 73ffc2f | 2011-10-18 14:02:57 +0200 | [diff] [blame] | 225 | #define NRXD 256 |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 226 | |
Seth Forshee | e041f65 | 2012-11-15 08:07:56 -0600 | [diff] [blame] | 227 | /* Amount of headroom to leave in Tx FIFO */ |
| 228 | #define TX_HEADROOM 4 |
| 229 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 230 | /* try to keep this # rbufs posted to the chip */ |
Alwin Beukers | 73ffc2f | 2011-10-18 14:02:57 +0200 | [diff] [blame] | 231 | #define NRXBUFPOST 32 |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 232 | |
Alwin Beukers | 73ffc2f | 2011-10-18 14:02:57 +0200 | [diff] [blame] | 233 | /* max # frames to process in brcms_c_recv() */ |
| 234 | #define RXBND 8 |
| 235 | /* max # tx status to process in wlc_txstatus() */ |
| 236 | #define TXSBND 8 |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 237 | |
Alwin Beukers | 4476065 | 2011-10-12 20:51:31 +0200 | [diff] [blame] | 238 | /* brcmu_format_flags() bit description structure */ |
| 239 | struct brcms_c_bit_desc { |
| 240 | u32 bit; |
| 241 | const char *name; |
| 242 | }; |
| 243 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 244 | /* |
| 245 | * The following table lists the buffer memory allocated to xmt fifos in HW. |
| 246 | * the size is in units of 256bytes(one block), total size is HW dependent |
| 247 | * ucode has default fifo partition, sw can overwrite if necessary |
| 248 | * |
| 249 | * This is documented in twiki under the topic UcodeTxFifo. Please ensure |
| 250 | * the twiki is updated before making changes. |
| 251 | */ |
| 252 | |
| 253 | /* Starting corerev for the fifo size table */ |
Hauke Mehrtens | 093cd33 | 2012-07-02 20:15:51 +0200 | [diff] [blame] | 254 | #define XMTFIFOTBL_STARTREV 17 |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 255 | |
| 256 | struct d11init { |
| 257 | __le16 addr; |
| 258 | __le16 size; |
| 259 | __le32 value; |
| 260 | }; |
| 261 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 262 | struct edcf_acparam { |
| 263 | u8 ACI; |
| 264 | u8 ECW; |
| 265 | u16 TXOP; |
| 266 | } __packed; |
| 267 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 268 | /* debug/trace */ |
Seth Forshee | b034174 | 2012-11-15 08:08:01 -0600 | [diff] [blame] | 269 | uint brcm_msg_level; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 270 | |
| 271 | /* TX FIFO number to WME/802.1E Access Category */ |
Arend van Spriel | b7eec42 | 2011-11-10 20:30:18 +0100 | [diff] [blame] | 272 | static const u8 wme_fifo2ac[] = { |
| 273 | IEEE80211_AC_BK, |
| 274 | IEEE80211_AC_BE, |
| 275 | IEEE80211_AC_VI, |
| 276 | IEEE80211_AC_VO, |
| 277 | IEEE80211_AC_BE, |
| 278 | IEEE80211_AC_BE |
| 279 | }; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 280 | |
Arend van Spriel | b7eec42 | 2011-11-10 20:30:18 +0100 | [diff] [blame] | 281 | /* ieee80211 Access Category to TX FIFO number */ |
| 282 | static const u8 wme_ac2fifo[] = { |
| 283 | TX_AC_VO_FIFO, |
| 284 | TX_AC_VI_FIFO, |
| 285 | TX_AC_BE_FIFO, |
| 286 | TX_AC_BK_FIFO |
| 287 | }; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 288 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 289 | static const u16 xmtfifo_sz[][NFIFO] = { |
Hauke Mehrtens | 093cd33 | 2012-07-02 20:15:51 +0200 | [diff] [blame] | 290 | /* corerev 17: 5120, 49152, 49152, 5376, 4352, 1280 */ |
| 291 | {20, 192, 192, 21, 17, 5}, |
| 292 | /* corerev 18: */ |
| 293 | {0, 0, 0, 0, 0, 0}, |
| 294 | /* corerev 19: */ |
| 295 | {0, 0, 0, 0, 0, 0}, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 296 | /* corerev 20: 5120, 49152, 49152, 5376, 4352, 1280 */ |
| 297 | {20, 192, 192, 21, 17, 5}, |
| 298 | /* corerev 21: 2304, 14848, 5632, 3584, 3584, 1280 */ |
| 299 | {9, 58, 22, 14, 14, 5}, |
| 300 | /* corerev 22: 5120, 49152, 49152, 5376, 4352, 1280 */ |
| 301 | {20, 192, 192, 21, 17, 5}, |
| 302 | /* corerev 23: 5120, 49152, 49152, 5376, 4352, 1280 */ |
| 303 | {20, 192, 192, 21, 17, 5}, |
| 304 | /* corerev 24: 2304, 14848, 5632, 3584, 3584, 1280 */ |
| 305 | {9, 58, 22, 14, 14, 5}, |
Hauke Mehrtens | 093cd33 | 2012-07-02 20:15:51 +0200 | [diff] [blame] | 306 | /* corerev 25: */ |
| 307 | {0, 0, 0, 0, 0, 0}, |
| 308 | /* corerev 26: */ |
| 309 | {0, 0, 0, 0, 0, 0}, |
| 310 | /* corerev 27: */ |
| 311 | {0, 0, 0, 0, 0, 0}, |
| 312 | /* corerev 28: 2304, 14848, 5632, 3584, 3584, 1280 */ |
| 313 | {9, 58, 22, 14, 14, 5}, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 314 | }; |
| 315 | |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 316 | #ifdef DEBUG |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 317 | static const char * const fifo_names[] = { |
| 318 | "AC_BK", "AC_BE", "AC_VI", "AC_VO", "BCMC", "ATIM" }; |
| 319 | #else |
| 320 | static const char fifo_names[6][0]; |
| 321 | #endif |
| 322 | |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 323 | #ifdef DEBUG |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 324 | /* pointer to most recently allocated wl/wlc */ |
| 325 | static struct brcms_c_info *wlc_info_dbg = (struct brcms_c_info *) (NULL); |
| 326 | #endif |
| 327 | |
Seth Forshee | 32d0f12 | 2012-11-15 08:07:55 -0600 | [diff] [blame] | 328 | /* Mapping of ieee80211 AC numbers to tx fifos */ |
| 329 | static const u8 ac_to_fifo_mapping[IEEE80211_NUM_ACS] = { |
| 330 | [IEEE80211_AC_VO] = TX_AC_VO_FIFO, |
| 331 | [IEEE80211_AC_VI] = TX_AC_VI_FIFO, |
| 332 | [IEEE80211_AC_BE] = TX_AC_BE_FIFO, |
| 333 | [IEEE80211_AC_BK] = TX_AC_BK_FIFO, |
| 334 | }; |
| 335 | |
Seth Forshee | e041f65 | 2012-11-15 08:07:56 -0600 | [diff] [blame] | 336 | /* Mapping of tx fifos to ieee80211 AC numbers */ |
| 337 | static const u8 fifo_to_ac_mapping[IEEE80211_NUM_ACS] = { |
| 338 | [TX_AC_BK_FIFO] = IEEE80211_AC_BK, |
| 339 | [TX_AC_BE_FIFO] = IEEE80211_AC_BE, |
| 340 | [TX_AC_VI_FIFO] = IEEE80211_AC_VI, |
| 341 | [TX_AC_VO_FIFO] = IEEE80211_AC_VO, |
| 342 | }; |
| 343 | |
Seth Forshee | 32d0f12 | 2012-11-15 08:07:55 -0600 | [diff] [blame] | 344 | static u8 brcms_ac_to_fifo(u8 ac) |
| 345 | { |
| 346 | if (ac >= ARRAY_SIZE(ac_to_fifo_mapping)) |
| 347 | return TX_AC_BE_FIFO; |
| 348 | return ac_to_fifo_mapping[ac]; |
| 349 | } |
| 350 | |
Seth Forshee | e041f65 | 2012-11-15 08:07:56 -0600 | [diff] [blame] | 351 | static u8 brcms_fifo_to_ac(u8 fifo) |
| 352 | { |
| 353 | if (fifo >= ARRAY_SIZE(fifo_to_ac_mapping)) |
| 354 | return IEEE80211_AC_BE; |
| 355 | return fifo_to_ac_mapping[fifo]; |
| 356 | } |
| 357 | |
Alwin Beukers | 73ffc2f | 2011-10-18 14:02:57 +0200 | [diff] [blame] | 358 | /* Find basic rate for a given rate */ |
| 359 | static u8 brcms_basic_rate(struct brcms_c_info *wlc, u32 rspec) |
| 360 | { |
| 361 | if (is_mcs_rate(rspec)) |
| 362 | return wlc->band->basic_rate[mcs_table[rspec & RSPEC_RATE_MASK] |
| 363 | .leg_ofdm]; |
| 364 | return wlc->band->basic_rate[rspec & RSPEC_RATE_MASK]; |
| 365 | } |
| 366 | |
| 367 | static u16 frametype(u32 rspec, u8 mimoframe) |
| 368 | { |
| 369 | if (is_mcs_rate(rspec)) |
| 370 | return mimoframe; |
| 371 | return is_cck_rate(rspec) ? FT_CCK : FT_OFDM; |
| 372 | } |
| 373 | |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 374 | /* currently the best mechanism for determining SIFS is the band in use */ |
| 375 | static u16 get_sifs(struct brcms_band *band) |
| 376 | { |
| 377 | return band->bandtype == BRCM_BAND_5G ? APHY_SIFS_TIME : |
| 378 | BPHY_SIFS_TIME; |
| 379 | } |
| 380 | |
| 381 | /* |
| 382 | * Detect Card removed. |
| 383 | * Even checking an sbconfig register read will not false trigger when the core |
| 384 | * is in reset it breaks CF address mechanism. Accessing gphy phyversion will |
| 385 | * cause SB error if aphy is in reset on 4306B0-DB. Need a simple accessible |
| 386 | * reg with fixed 0/1 pattern (some platforms return all 0). |
| 387 | * If clocks are present, call the sb routine which will figure out if the |
| 388 | * device is removed. |
| 389 | */ |
| 390 | static bool brcms_deviceremoved(struct brcms_c_info *wlc) |
| 391 | { |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 392 | u32 macctrl; |
| 393 | |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 394 | if (!wlc->hw->clk) |
| 395 | return ai_deviceremoved(wlc->hw->sih); |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 396 | macctrl = bcma_read32(wlc->hw->d11core, |
| 397 | D11REGOFFS(maccontrol)); |
| 398 | return (macctrl & (MCTL_PSM_JMP_0 | MCTL_IHR_EN)) != MCTL_IHR_EN; |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | /* sum the individual fifo tx pending packet counts */ |
Seth Forshee | e041f65 | 2012-11-15 08:07:56 -0600 | [diff] [blame] | 402 | static int brcms_txpktpendtot(struct brcms_c_info *wlc) |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 403 | { |
Seth Forshee | e041f65 | 2012-11-15 08:07:56 -0600 | [diff] [blame] | 404 | int i; |
| 405 | int pending = 0; |
| 406 | |
| 407 | for (i = 0; i < ARRAY_SIZE(wlc->hw->di); i++) |
| 408 | if (wlc->hw->di[i]) |
| 409 | pending += dma_txpending(wlc->hw->di[i]); |
| 410 | return pending; |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | static bool brcms_is_mband_unlocked(struct brcms_c_info *wlc) |
| 414 | { |
| 415 | return wlc->pub->_nbands > 1 && !wlc->bandlocked; |
| 416 | } |
| 417 | |
| 418 | static int brcms_chspec_bw(u16 chanspec) |
| 419 | { |
| 420 | if (CHSPEC_IS40(chanspec)) |
| 421 | return BRCMS_40_MHZ; |
| 422 | if (CHSPEC_IS20(chanspec)) |
| 423 | return BRCMS_20_MHZ; |
| 424 | |
| 425 | return BRCMS_10_MHZ; |
| 426 | } |
| 427 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 428 | static void brcms_c_bsscfg_mfree(struct brcms_bss_cfg *cfg) |
| 429 | { |
| 430 | if (cfg == NULL) |
| 431 | return; |
| 432 | |
| 433 | kfree(cfg->current_bss); |
| 434 | kfree(cfg); |
| 435 | } |
| 436 | |
| 437 | static void brcms_c_detach_mfree(struct brcms_c_info *wlc) |
| 438 | { |
| 439 | if (wlc == NULL) |
| 440 | return; |
| 441 | |
| 442 | brcms_c_bsscfg_mfree(wlc->bsscfg); |
| 443 | kfree(wlc->pub); |
| 444 | kfree(wlc->modulecb); |
| 445 | kfree(wlc->default_bss); |
| 446 | kfree(wlc->protection); |
| 447 | kfree(wlc->stf); |
| 448 | kfree(wlc->bandstate[0]); |
| 449 | kfree(wlc->corestate->macstat_snapshot); |
| 450 | kfree(wlc->corestate); |
| 451 | kfree(wlc->hw->bandstate[0]); |
| 452 | kfree(wlc->hw); |
| 453 | |
| 454 | /* free the wlc */ |
| 455 | kfree(wlc); |
| 456 | wlc = NULL; |
| 457 | } |
| 458 | |
| 459 | static struct brcms_bss_cfg *brcms_c_bsscfg_malloc(uint unit) |
| 460 | { |
| 461 | struct brcms_bss_cfg *cfg; |
| 462 | |
| 463 | cfg = kzalloc(sizeof(struct brcms_bss_cfg), GFP_ATOMIC); |
| 464 | if (cfg == NULL) |
| 465 | goto fail; |
| 466 | |
| 467 | cfg->current_bss = kzalloc(sizeof(struct brcms_bss_info), GFP_ATOMIC); |
| 468 | if (cfg->current_bss == NULL) |
| 469 | goto fail; |
| 470 | |
| 471 | return cfg; |
| 472 | |
| 473 | fail: |
| 474 | brcms_c_bsscfg_mfree(cfg); |
| 475 | return NULL; |
| 476 | } |
| 477 | |
| 478 | static struct brcms_c_info * |
| 479 | brcms_c_attach_malloc(uint unit, uint *err, uint devid) |
| 480 | { |
| 481 | struct brcms_c_info *wlc; |
| 482 | |
| 483 | wlc = kzalloc(sizeof(struct brcms_c_info), GFP_ATOMIC); |
| 484 | if (wlc == NULL) { |
| 485 | *err = 1002; |
| 486 | goto fail; |
| 487 | } |
| 488 | |
| 489 | /* allocate struct brcms_c_pub state structure */ |
| 490 | wlc->pub = kzalloc(sizeof(struct brcms_pub), GFP_ATOMIC); |
| 491 | if (wlc->pub == NULL) { |
| 492 | *err = 1003; |
| 493 | goto fail; |
| 494 | } |
| 495 | wlc->pub->wlc = wlc; |
| 496 | |
| 497 | /* allocate struct brcms_hardware state structure */ |
| 498 | |
| 499 | wlc->hw = kzalloc(sizeof(struct brcms_hardware), GFP_ATOMIC); |
| 500 | if (wlc->hw == NULL) { |
| 501 | *err = 1005; |
| 502 | goto fail; |
| 503 | } |
| 504 | wlc->hw->wlc = wlc; |
| 505 | |
| 506 | wlc->hw->bandstate[0] = |
| 507 | kzalloc(sizeof(struct brcms_hw_band) * MAXBANDS, GFP_ATOMIC); |
| 508 | if (wlc->hw->bandstate[0] == NULL) { |
| 509 | *err = 1006; |
| 510 | goto fail; |
| 511 | } else { |
| 512 | int i; |
| 513 | |
| 514 | for (i = 1; i < MAXBANDS; i++) |
| 515 | wlc->hw->bandstate[i] = (struct brcms_hw_band *) |
| 516 | ((unsigned long)wlc->hw->bandstate[0] + |
| 517 | (sizeof(struct brcms_hw_band) * i)); |
| 518 | } |
| 519 | |
| 520 | wlc->modulecb = |
| 521 | kzalloc(sizeof(struct modulecb) * BRCMS_MAXMODULES, GFP_ATOMIC); |
| 522 | if (wlc->modulecb == NULL) { |
| 523 | *err = 1009; |
| 524 | goto fail; |
| 525 | } |
| 526 | |
| 527 | wlc->default_bss = kzalloc(sizeof(struct brcms_bss_info), GFP_ATOMIC); |
| 528 | if (wlc->default_bss == NULL) { |
| 529 | *err = 1010; |
| 530 | goto fail; |
| 531 | } |
| 532 | |
| 533 | wlc->bsscfg = brcms_c_bsscfg_malloc(unit); |
| 534 | if (wlc->bsscfg == NULL) { |
| 535 | *err = 1011; |
| 536 | goto fail; |
| 537 | } |
| 538 | |
| 539 | wlc->protection = kzalloc(sizeof(struct brcms_protection), |
| 540 | GFP_ATOMIC); |
| 541 | if (wlc->protection == NULL) { |
| 542 | *err = 1016; |
| 543 | goto fail; |
| 544 | } |
| 545 | |
| 546 | wlc->stf = kzalloc(sizeof(struct brcms_stf), GFP_ATOMIC); |
| 547 | if (wlc->stf == NULL) { |
| 548 | *err = 1017; |
| 549 | goto fail; |
| 550 | } |
| 551 | |
| 552 | wlc->bandstate[0] = |
| 553 | kzalloc(sizeof(struct brcms_band)*MAXBANDS, GFP_ATOMIC); |
| 554 | if (wlc->bandstate[0] == NULL) { |
| 555 | *err = 1025; |
| 556 | goto fail; |
| 557 | } else { |
| 558 | int i; |
| 559 | |
| 560 | for (i = 1; i < MAXBANDS; i++) |
| 561 | wlc->bandstate[i] = (struct brcms_band *) |
| 562 | ((unsigned long)wlc->bandstate[0] |
| 563 | + (sizeof(struct brcms_band)*i)); |
| 564 | } |
| 565 | |
| 566 | wlc->corestate = kzalloc(sizeof(struct brcms_core), GFP_ATOMIC); |
| 567 | if (wlc->corestate == NULL) { |
| 568 | *err = 1026; |
| 569 | goto fail; |
| 570 | } |
| 571 | |
| 572 | wlc->corestate->macstat_snapshot = |
| 573 | kzalloc(sizeof(struct macstat), GFP_ATOMIC); |
| 574 | if (wlc->corestate->macstat_snapshot == NULL) { |
| 575 | *err = 1027; |
| 576 | goto fail; |
| 577 | } |
| 578 | |
| 579 | return wlc; |
| 580 | |
| 581 | fail: |
| 582 | brcms_c_detach_mfree(wlc); |
| 583 | return NULL; |
| 584 | } |
| 585 | |
| 586 | /* |
| 587 | * Update the slot timing for standard 11b/g (20us slots) |
| 588 | * or shortslot 11g (9us slots) |
| 589 | * The PSM needs to be suspended for this call. |
| 590 | */ |
| 591 | static void brcms_b_update_slot_timing(struct brcms_hardware *wlc_hw, |
| 592 | bool shortslot) |
| 593 | { |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 594 | struct bcma_device *core = wlc_hw->d11core; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 595 | |
| 596 | if (shortslot) { |
| 597 | /* 11g short slot: 11a timing */ |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 598 | bcma_write16(core, D11REGOFFS(ifs_slot), 0x0207); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 599 | brcms_b_write_shm(wlc_hw, M_DOT11_SLOT, APHY_SLOT_TIME); |
| 600 | } else { |
| 601 | /* 11g long slot: 11b timing */ |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 602 | bcma_write16(core, D11REGOFFS(ifs_slot), 0x0212); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 603 | brcms_b_write_shm(wlc_hw, M_DOT11_SLOT, BPHY_SLOT_TIME); |
| 604 | } |
| 605 | } |
| 606 | |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 607 | /* |
| 608 | * calculate frame duration of a given rate and length, return |
| 609 | * time in usec unit |
| 610 | */ |
Arend van Spriel | 094b199 | 2011-10-18 14:03:07 +0200 | [diff] [blame] | 611 | static uint brcms_c_calc_frame_time(struct brcms_c_info *wlc, u32 ratespec, |
| 612 | u8 preamble_type, uint mac_len) |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 613 | { |
| 614 | uint nsyms, dur = 0, Ndps, kNdps; |
| 615 | uint rate = rspec2rate(ratespec); |
| 616 | |
| 617 | if (rate == 0) { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 618 | brcms_err(wlc->hw->d11core, "wl%d: WAR: using rate of 1 mbps\n", |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 619 | wlc->pub->unit); |
| 620 | rate = BRCM_RATE_1M; |
| 621 | } |
| 622 | |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 623 | if (is_mcs_rate(ratespec)) { |
| 624 | uint mcs = ratespec & RSPEC_RATE_MASK; |
| 625 | int tot_streams = mcs_2_txstreams(mcs) + rspec_stc(ratespec); |
| 626 | |
| 627 | dur = PREN_PREAMBLE + (tot_streams * PREN_PREAMBLE_EXT); |
| 628 | if (preamble_type == BRCMS_MM_PREAMBLE) |
| 629 | dur += PREN_MM_EXT; |
| 630 | /* 1000Ndbps = kbps * 4 */ |
| 631 | kNdps = mcs_2_rate(mcs, rspec_is40mhz(ratespec), |
| 632 | rspec_issgi(ratespec)) * 4; |
| 633 | |
| 634 | if (rspec_stc(ratespec) == 0) |
| 635 | nsyms = |
| 636 | CEIL((APHY_SERVICE_NBITS + 8 * mac_len + |
| 637 | APHY_TAIL_NBITS) * 1000, kNdps); |
| 638 | else |
| 639 | /* STBC needs to have even number of symbols */ |
| 640 | nsyms = |
| 641 | 2 * |
| 642 | CEIL((APHY_SERVICE_NBITS + 8 * mac_len + |
| 643 | APHY_TAIL_NBITS) * 1000, 2 * kNdps); |
| 644 | |
| 645 | dur += APHY_SYMBOL_TIME * nsyms; |
| 646 | if (wlc->band->bandtype == BRCM_BAND_2G) |
| 647 | dur += DOT11_OFDM_SIGNAL_EXTENSION; |
| 648 | } else if (is_ofdm_rate(rate)) { |
| 649 | dur = APHY_PREAMBLE_TIME; |
| 650 | dur += APHY_SIGNAL_TIME; |
| 651 | /* Ndbps = Mbps * 4 = rate(500Kbps) * 2 */ |
| 652 | Ndps = rate * 2; |
| 653 | /* NSyms = CEILING((SERVICE + 8*NBytes + TAIL) / Ndbps) */ |
| 654 | nsyms = |
| 655 | CEIL((APHY_SERVICE_NBITS + 8 * mac_len + APHY_TAIL_NBITS), |
| 656 | Ndps); |
| 657 | dur += APHY_SYMBOL_TIME * nsyms; |
| 658 | if (wlc->band->bandtype == BRCM_BAND_2G) |
| 659 | dur += DOT11_OFDM_SIGNAL_EXTENSION; |
| 660 | } else { |
| 661 | /* |
| 662 | * calc # bits * 2 so factor of 2 in rate (1/2 mbps) |
| 663 | * will divide out |
| 664 | */ |
| 665 | mac_len = mac_len * 8 * 2; |
| 666 | /* calc ceiling of bits/rate = microseconds of air time */ |
| 667 | dur = (mac_len + rate - 1) / rate; |
| 668 | if (preamble_type & BRCMS_SHORT_PREAMBLE) |
| 669 | dur += BPHY_PLCP_SHORT_TIME; |
| 670 | else |
| 671 | dur += BPHY_PLCP_TIME; |
| 672 | } |
| 673 | return dur; |
| 674 | } |
| 675 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 676 | static void brcms_c_write_inits(struct brcms_hardware *wlc_hw, |
| 677 | const struct d11init *inits) |
| 678 | { |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 679 | struct bcma_device *core = wlc_hw->d11core; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 680 | int i; |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 681 | uint offset; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 682 | u16 size; |
| 683 | u32 value; |
| 684 | |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 685 | brcms_dbg_info(wlc_hw->d11core, "wl%d\n", wlc_hw->unit); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 686 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 687 | for (i = 0; inits[i].addr != cpu_to_le16(0xffff); i++) { |
| 688 | size = le16_to_cpu(inits[i].size); |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 689 | offset = le16_to_cpu(inits[i].addr); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 690 | value = le32_to_cpu(inits[i].value); |
| 691 | if (size == 2) |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 692 | bcma_write16(core, offset, value); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 693 | else if (size == 4) |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 694 | bcma_write32(core, offset, value); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 695 | else |
| 696 | break; |
| 697 | } |
| 698 | } |
| 699 | |
| 700 | static void brcms_c_write_mhf(struct brcms_hardware *wlc_hw, u16 *mhfs) |
| 701 | { |
| 702 | u8 idx; |
| 703 | u16 addr[] = { |
| 704 | M_HOST_FLAGS1, M_HOST_FLAGS2, M_HOST_FLAGS3, M_HOST_FLAGS4, |
| 705 | M_HOST_FLAGS5 |
| 706 | }; |
| 707 | |
| 708 | for (idx = 0; idx < MHFMAX; idx++) |
| 709 | brcms_b_write_shm(wlc_hw, addr[idx], mhfs[idx]); |
| 710 | } |
| 711 | |
| 712 | static void brcms_c_ucode_bsinit(struct brcms_hardware *wlc_hw) |
| 713 | { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 714 | struct brcms_ucode *ucode = &wlc_hw->wlc->wl->ucode; |
| 715 | |
| 716 | /* init microcode host flags */ |
| 717 | brcms_c_write_mhf(wlc_hw, wlc_hw->band->mhfs); |
| 718 | |
| 719 | /* do band-specific ucode IHR, SHM, and SCR inits */ |
Hauke Mehrtens | 6f80f01 | 2012-12-07 00:35:53 +0100 | [diff] [blame] | 720 | if (D11REV_IS(wlc_hw->corerev, 17) || D11REV_IS(wlc_hw->corerev, 23)) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 721 | if (BRCMS_ISNPHY(wlc_hw->band)) |
| 722 | brcms_c_write_inits(wlc_hw, ucode->d11n0bsinitvals16); |
| 723 | else |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 724 | brcms_err(wlc_hw->d11core, |
| 725 | "%s: wl%d: unsupported phy in corerev %d\n", |
| 726 | __func__, wlc_hw->unit, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 727 | wlc_hw->corerev); |
| 728 | } else { |
| 729 | if (D11REV_IS(wlc_hw->corerev, 24)) { |
| 730 | if (BRCMS_ISLCNPHY(wlc_hw->band)) |
| 731 | brcms_c_write_inits(wlc_hw, |
| 732 | ucode->d11lcn0bsinitvals24); |
| 733 | else |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 734 | brcms_err(wlc_hw->d11core, |
| 735 | "%s: wl%d: unsupported phy in core rev %d\n", |
| 736 | __func__, wlc_hw->unit, |
| 737 | wlc_hw->corerev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 738 | } else { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 739 | brcms_err(wlc_hw->d11core, |
| 740 | "%s: wl%d: unsupported corerev %d\n", |
| 741 | __func__, wlc_hw->unit, wlc_hw->corerev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 742 | } |
| 743 | } |
| 744 | } |
| 745 | |
Arend van Spriel | a8779e4 | 2011-12-08 15:06:58 -0800 | [diff] [blame] | 746 | static void brcms_b_core_ioctl(struct brcms_hardware *wlc_hw, u32 m, u32 v) |
| 747 | { |
| 748 | struct bcma_device *core = wlc_hw->d11core; |
| 749 | u32 ioctl = bcma_aread32(core, BCMA_IOCTL) & ~m; |
| 750 | |
| 751 | bcma_awrite32(core, BCMA_IOCTL, ioctl | v); |
| 752 | } |
| 753 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 754 | static void brcms_b_core_phy_clk(struct brcms_hardware *wlc_hw, bool clk) |
| 755 | { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 756 | brcms_dbg_info(wlc_hw->d11core, "wl%d: clk %d\n", wlc_hw->unit, clk); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 757 | |
| 758 | wlc_hw->phyclk = clk; |
| 759 | |
| 760 | if (OFF == clk) { /* clear gmode bit, put phy into reset */ |
| 761 | |
Arend van Spriel | a8779e4 | 2011-12-08 15:06:58 -0800 | [diff] [blame] | 762 | brcms_b_core_ioctl(wlc_hw, (SICF_PRST | SICF_FGC | SICF_GMODE), |
| 763 | (SICF_PRST | SICF_FGC)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 764 | udelay(1); |
Arend van Spriel | a8779e4 | 2011-12-08 15:06:58 -0800 | [diff] [blame] | 765 | brcms_b_core_ioctl(wlc_hw, (SICF_PRST | SICF_FGC), SICF_PRST); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 766 | udelay(1); |
| 767 | |
| 768 | } else { /* take phy out of reset */ |
| 769 | |
Arend van Spriel | a8779e4 | 2011-12-08 15:06:58 -0800 | [diff] [blame] | 770 | brcms_b_core_ioctl(wlc_hw, (SICF_PRST | SICF_FGC), SICF_FGC); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 771 | udelay(1); |
Arend van Spriel | a8779e4 | 2011-12-08 15:06:58 -0800 | [diff] [blame] | 772 | brcms_b_core_ioctl(wlc_hw, SICF_FGC, 0); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 773 | udelay(1); |
| 774 | |
| 775 | } |
| 776 | } |
| 777 | |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 778 | /* low-level band switch utility routine */ |
| 779 | static void brcms_c_setxband(struct brcms_hardware *wlc_hw, uint bandunit) |
| 780 | { |
Seth Forshee | 913911f | 2012-11-15 08:08:04 -0600 | [diff] [blame] | 781 | brcms_dbg_mac80211(wlc_hw->d11core, "wl%d: bandunit %d\n", wlc_hw->unit, |
| 782 | bandunit); |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 783 | |
| 784 | wlc_hw->band = wlc_hw->bandstate[bandunit]; |
| 785 | |
| 786 | /* |
| 787 | * BMAC_NOTE: |
| 788 | * until we eliminate need for wlc->band refs in low level code |
| 789 | */ |
| 790 | wlc_hw->wlc->band = wlc_hw->wlc->bandstate[bandunit]; |
| 791 | |
| 792 | /* set gmode core flag */ |
Arend van Spriel | a8779e4 | 2011-12-08 15:06:58 -0800 | [diff] [blame] | 793 | if (wlc_hw->sbclk && !wlc_hw->noreset) { |
| 794 | u32 gmode = 0; |
| 795 | |
| 796 | if (bandunit == 0) |
| 797 | gmode = SICF_GMODE; |
| 798 | |
| 799 | brcms_b_core_ioctl(wlc_hw, SICF_GMODE, gmode); |
| 800 | } |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 801 | } |
| 802 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 803 | /* switch to new band but leave it inactive */ |
| 804 | static u32 brcms_c_setband_inact(struct brcms_c_info *wlc, uint bandunit) |
| 805 | { |
| 806 | struct brcms_hardware *wlc_hw = wlc->hw; |
| 807 | u32 macintmask; |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 808 | u32 macctrl; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 809 | |
Seth Forshee | 913911f | 2012-11-15 08:08:04 -0600 | [diff] [blame] | 810 | brcms_dbg_mac80211(wlc_hw->d11core, "wl%d\n", wlc_hw->unit); |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 811 | macctrl = bcma_read32(wlc_hw->d11core, |
| 812 | D11REGOFFS(maccontrol)); |
| 813 | WARN_ON((macctrl & MCTL_EN_MAC) != 0); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 814 | |
| 815 | /* disable interrupts */ |
| 816 | macintmask = brcms_intrsoff(wlc->wl); |
| 817 | |
| 818 | /* radio off */ |
| 819 | wlc_phy_switch_radio(wlc_hw->band->pi, OFF); |
| 820 | |
| 821 | brcms_b_core_phy_clk(wlc_hw, OFF); |
| 822 | |
| 823 | brcms_c_setxband(wlc_hw, bandunit); |
| 824 | |
| 825 | return macintmask; |
| 826 | } |
| 827 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 828 | /* process an individual struct tx_status */ |
| 829 | static bool |
| 830 | brcms_c_dotxstatus(struct brcms_c_info *wlc, struct tx_status *txs) |
| 831 | { |
Seth Forshee | e041f65 | 2012-11-15 08:07:56 -0600 | [diff] [blame] | 832 | struct sk_buff *p = NULL; |
| 833 | uint queue = NFIFO; |
| 834 | struct dma_pub *dma = NULL; |
Seth Forshee | cdf4352 | 2012-11-15 08:08:09 -0600 | [diff] [blame] | 835 | struct d11txh *txh = NULL; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 836 | struct scb *scb = NULL; |
| 837 | bool free_pdu; |
| 838 | int tx_rts, tx_frame_count, tx_rts_count; |
| 839 | uint totlen, supr_status; |
| 840 | bool lastframe; |
| 841 | struct ieee80211_hdr *h; |
| 842 | u16 mcl; |
| 843 | struct ieee80211_tx_info *tx_info; |
| 844 | struct ieee80211_tx_rate *txrate; |
| 845 | int i; |
Seth Forshee | e041f65 | 2012-11-15 08:07:56 -0600 | [diff] [blame] | 846 | bool fatal = true; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 847 | |
Seth Forshee | cdf4352 | 2012-11-15 08:08:09 -0600 | [diff] [blame] | 848 | trace_brcms_txstatus(&wlc->hw->d11core->dev, txs->framelen, |
| 849 | txs->frameid, txs->status, txs->lasttxtime, |
| 850 | txs->sequence, txs->phyerr, txs->ackphyrxsh); |
| 851 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 852 | /* discard intermediate indications for ucode with one legitimate case: |
| 853 | * e.g. if "useRTS" is set. ucode did a successful rts/cts exchange, |
| 854 | * but the subsequent tx of DATA failed. so it will start rts/cts |
| 855 | * from the beginning (resetting the rts transmission count) |
| 856 | */ |
| 857 | if (!(txs->status & TX_STATUS_AMPDU) |
| 858 | && (txs->status & TX_STATUS_INTERMEDIATE)) { |
Seth Forshee | 5ce58bb | 2012-11-15 08:08:05 -0600 | [diff] [blame] | 859 | brcms_dbg_tx(wlc->hw->d11core, "INTERMEDIATE but not AMPDU\n"); |
Seth Forshee | e041f65 | 2012-11-15 08:07:56 -0600 | [diff] [blame] | 860 | fatal = false; |
| 861 | goto out; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 862 | } |
| 863 | |
| 864 | queue = txs->frameid & TXFID_QUEUE_MASK; |
Seth Forshee | cdf4352 | 2012-11-15 08:08:09 -0600 | [diff] [blame] | 865 | if (queue >= NFIFO) { |
| 866 | brcms_err(wlc->hw->d11core, "queue %u >= NFIFO\n", queue); |
Seth Forshee | e041f65 | 2012-11-15 08:07:56 -0600 | [diff] [blame] | 867 | goto out; |
Seth Forshee | cdf4352 | 2012-11-15 08:08:09 -0600 | [diff] [blame] | 868 | } |
Seth Forshee | e041f65 | 2012-11-15 08:07:56 -0600 | [diff] [blame] | 869 | |
| 870 | dma = wlc->hw->di[queue]; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 871 | |
| 872 | p = dma_getnexttxp(wlc->hw->di[queue], DMA_RANGE_TRANSMITTED); |
Seth Forshee | cdf4352 | 2012-11-15 08:08:09 -0600 | [diff] [blame] | 873 | if (p == NULL) { |
| 874 | brcms_err(wlc->hw->d11core, "dma_getnexttxp returned null!\n"); |
Seth Forshee | e041f65 | 2012-11-15 08:07:56 -0600 | [diff] [blame] | 875 | goto out; |
Seth Forshee | cdf4352 | 2012-11-15 08:08:09 -0600 | [diff] [blame] | 876 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 877 | |
| 878 | txh = (struct d11txh *) (p->data); |
| 879 | mcl = le16_to_cpu(txh->MacTxControlLow); |
| 880 | |
Seth Forshee | cdf4352 | 2012-11-15 08:08:09 -0600 | [diff] [blame] | 881 | if (txs->phyerr) |
| 882 | brcms_err(wlc->hw->d11core, "phyerr 0x%x, rate 0x%x\n", |
| 883 | txs->phyerr, txh->MainRates); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 884 | |
Seth Forshee | cdf4352 | 2012-11-15 08:08:09 -0600 | [diff] [blame] | 885 | if (txs->frameid != le16_to_cpu(txh->TxFrameID)) { |
| 886 | brcms_err(wlc->hw->d11core, "frameid != txh->TxFrameID\n"); |
Seth Forshee | e041f65 | 2012-11-15 08:07:56 -0600 | [diff] [blame] | 887 | goto out; |
Seth Forshee | cdf4352 | 2012-11-15 08:08:09 -0600 | [diff] [blame] | 888 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 889 | tx_info = IEEE80211_SKB_CB(p); |
| 890 | h = (struct ieee80211_hdr *)((u8 *) (txh + 1) + D11_PHY_HDR_LEN); |
| 891 | |
Thomas Huehn | 644e8c0 | 2012-07-10 14:01:37 +0200 | [diff] [blame] | 892 | if (tx_info->rate_driver_data[0]) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 893 | scb = &wlc->pri_scb; |
| 894 | |
| 895 | if (tx_info->flags & IEEE80211_TX_CTL_AMPDU) { |
| 896 | brcms_c_ampdu_dotxstatus(wlc->ampdu, scb, p, txs); |
Seth Forshee | e041f65 | 2012-11-15 08:07:56 -0600 | [diff] [blame] | 897 | fatal = false; |
| 898 | goto out; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 899 | } |
| 900 | |
Seth Forshee | cdf4352 | 2012-11-15 08:08:09 -0600 | [diff] [blame] | 901 | /* |
| 902 | * brcms_c_ampdu_dotxstatus() will trace tx descriptors for AMPDU |
| 903 | * frames; this traces them for the rest. |
| 904 | */ |
| 905 | trace_brcms_txdesc(&wlc->hw->d11core->dev, txh, sizeof(*txh)); |
| 906 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 907 | supr_status = txs->status & TX_STATUS_SUPR_MASK; |
Seth Forshee | cdf4352 | 2012-11-15 08:08:09 -0600 | [diff] [blame] | 908 | if (supr_status == TX_STATUS_SUPR_BADCH) { |
| 909 | unsigned xfts = le16_to_cpu(txh->XtraFrameTypes); |
Seth Forshee | 5ce58bb | 2012-11-15 08:08:05 -0600 | [diff] [blame] | 910 | brcms_dbg_tx(wlc->hw->d11core, |
Seth Forshee | cdf4352 | 2012-11-15 08:08:09 -0600 | [diff] [blame] | 911 | "Pkt tx suppressed, dest chan %u, current %d\n", |
| 912 | (xfts >> XFTS_CHANNEL_SHIFT) & 0xff, |
Seth Forshee | 5ce58bb | 2012-11-15 08:08:05 -0600 | [diff] [blame] | 913 | CHSPEC_CHANNEL(wlc->default_bss->chanspec)); |
Seth Forshee | cdf4352 | 2012-11-15 08:08:09 -0600 | [diff] [blame] | 914 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 915 | |
| 916 | tx_rts = le16_to_cpu(txh->MacTxControlLow) & TXC_SENDRTS; |
| 917 | tx_frame_count = |
| 918 | (txs->status & TX_STATUS_FRM_RTX_MASK) >> TX_STATUS_FRM_RTX_SHIFT; |
| 919 | tx_rts_count = |
| 920 | (txs->status & TX_STATUS_RTS_RTX_MASK) >> TX_STATUS_RTS_RTX_SHIFT; |
| 921 | |
| 922 | lastframe = !ieee80211_has_morefrags(h->frame_control); |
| 923 | |
| 924 | if (!lastframe) { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 925 | brcms_err(wlc->hw->d11core, "Not last frame!\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 926 | } else { |
| 927 | /* |
| 928 | * Set information to be consumed by Minstrel ht. |
| 929 | * |
| 930 | * The "fallback limit" is the number of tx attempts a given |
| 931 | * MPDU is sent at the "primary" rate. Tx attempts beyond that |
| 932 | * limit are sent at the "secondary" rate. |
| 933 | * A 'short frame' does not exceed RTS treshold. |
| 934 | */ |
| 935 | u16 sfbl, /* Short Frame Rate Fallback Limit */ |
| 936 | lfbl, /* Long Frame Rate Fallback Limit */ |
| 937 | fbl; |
| 938 | |
Arend van Spriel | b7eec42 | 2011-11-10 20:30:18 +0100 | [diff] [blame] | 939 | if (queue < IEEE80211_NUM_ACS) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 940 | sfbl = GFIELD(wlc->wme_retries[wme_fifo2ac[queue]], |
| 941 | EDCF_SFB); |
| 942 | lfbl = GFIELD(wlc->wme_retries[wme_fifo2ac[queue]], |
| 943 | EDCF_LFB); |
| 944 | } else { |
| 945 | sfbl = wlc->SFBL; |
| 946 | lfbl = wlc->LFBL; |
| 947 | } |
| 948 | |
| 949 | txrate = tx_info->status.rates; |
| 950 | if (txrate[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) |
| 951 | fbl = lfbl; |
| 952 | else |
| 953 | fbl = sfbl; |
| 954 | |
| 955 | ieee80211_tx_info_clear_status(tx_info); |
| 956 | |
| 957 | if ((tx_frame_count > fbl) && (txrate[1].idx >= 0)) { |
| 958 | /* |
| 959 | * rate selection requested a fallback rate |
| 960 | * and we used it |
| 961 | */ |
| 962 | txrate[0].count = fbl; |
| 963 | txrate[1].count = tx_frame_count - fbl; |
| 964 | } else { |
| 965 | /* |
| 966 | * rate selection did not request fallback rate, or |
| 967 | * we didn't need it |
| 968 | */ |
| 969 | txrate[0].count = tx_frame_count; |
| 970 | /* |
| 971 | * rc80211_minstrel.c:minstrel_tx_status() expects |
| 972 | * unused rates to be marked with idx = -1 |
| 973 | */ |
| 974 | txrate[1].idx = -1; |
| 975 | txrate[1].count = 0; |
| 976 | } |
| 977 | |
| 978 | /* clear the rest of the rates */ |
| 979 | for (i = 2; i < IEEE80211_TX_MAX_RATES; i++) { |
| 980 | txrate[i].idx = -1; |
| 981 | txrate[i].count = 0; |
| 982 | } |
| 983 | |
| 984 | if (txs->status & TX_STATUS_ACK_RCV) |
| 985 | tx_info->flags |= IEEE80211_TX_STAT_ACK; |
| 986 | } |
| 987 | |
Arend van Spriel | ad4d71f | 2011-11-10 20:30:26 +0100 | [diff] [blame] | 988 | totlen = p->len; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 989 | free_pdu = true; |
| 990 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 991 | if (lastframe) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 992 | /* remove PLCP & Broadcom tx descriptor header */ |
| 993 | skb_pull(p, D11_PHY_HDR_LEN); |
| 994 | skb_pull(p, D11_TXH_LEN); |
| 995 | ieee80211_tx_status_irqsafe(wlc->pub->ieee_hw, p); |
| 996 | } else { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 997 | brcms_err(wlc->hw->d11core, |
| 998 | "%s: Not last frame => not calling tx_status\n", |
| 999 | __func__); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1000 | } |
| 1001 | |
Seth Forshee | e041f65 | 2012-11-15 08:07:56 -0600 | [diff] [blame] | 1002 | fatal = false; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1003 | |
Seth Forshee | e041f65 | 2012-11-15 08:07:56 -0600 | [diff] [blame] | 1004 | out: |
Seth Forshee | cdf4352 | 2012-11-15 08:08:09 -0600 | [diff] [blame] | 1005 | if (fatal) { |
| 1006 | if (txh) |
| 1007 | trace_brcms_txdesc(&wlc->hw->d11core->dev, txh, |
| 1008 | sizeof(*txh)); |
| 1009 | if (p) |
| 1010 | brcmu_pkt_buf_free_skb(p); |
| 1011 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1012 | |
Seth Forshee | e041f65 | 2012-11-15 08:07:56 -0600 | [diff] [blame] | 1013 | if (dma && queue < NFIFO) { |
| 1014 | u16 ac_queue = brcms_fifo_to_ac(queue); |
| 1015 | if (dma->txavail > TX_HEADROOM && queue < TX_BCMC_FIFO && |
| 1016 | ieee80211_queue_stopped(wlc->pub->ieee_hw, ac_queue)) |
| 1017 | ieee80211_wake_queue(wlc->pub->ieee_hw, ac_queue); |
| 1018 | dma_kick_tx(dma); |
| 1019 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1020 | |
Seth Forshee | e041f65 | 2012-11-15 08:07:56 -0600 | [diff] [blame] | 1021 | return fatal; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1022 | } |
| 1023 | |
| 1024 | /* process tx completion events in BMAC |
| 1025 | * Return true if more tx status need to be processed. false otherwise. |
| 1026 | */ |
| 1027 | static bool |
| 1028 | brcms_b_txstatus(struct brcms_hardware *wlc_hw, bool bound, bool *fatal) |
| 1029 | { |
| 1030 | bool morepending = false; |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 1031 | struct bcma_device *core; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1032 | struct tx_status txstatus, *txs; |
| 1033 | u32 s1, s2; |
| 1034 | uint n = 0; |
| 1035 | /* |
| 1036 | * Param 'max_tx_num' indicates max. # tx status to process before |
| 1037 | * break out. |
| 1038 | */ |
| 1039 | uint max_tx_num = bound ? TXSBND : -1; |
| 1040 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1041 | txs = &txstatus; |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 1042 | core = wlc_hw->d11core; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1043 | *fatal = false; |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 1044 | s1 = bcma_read32(core, D11REGOFFS(frmtxstatus)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1045 | while (!(*fatal) |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 1046 | && (s1 & TXS_V)) { |
Piotr Haber | 57fe504 | 2012-11-28 21:44:07 +0100 | [diff] [blame] | 1047 | /* !give others some time to run! */ |
| 1048 | if (n >= max_tx_num) { |
| 1049 | morepending = true; |
| 1050 | break; |
| 1051 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1052 | |
| 1053 | if (s1 == 0xffffffff) { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 1054 | brcms_err(core, "wl%d: %s: dead chip\n", wlc_hw->unit, |
| 1055 | __func__); |
Piotr Haber | 57fe504 | 2012-11-28 21:44:07 +0100 | [diff] [blame] | 1056 | *fatal = true; |
| 1057 | return false; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1058 | } |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 1059 | s2 = bcma_read32(core, D11REGOFFS(frmtxstatus2)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1060 | |
| 1061 | txs->status = s1 & TXS_STATUS_MASK; |
| 1062 | txs->frameid = (s1 & TXS_FID_MASK) >> TXS_FID_SHIFT; |
| 1063 | txs->sequence = s2 & TXS_SEQ_MASK; |
| 1064 | txs->phyerr = (s2 & TXS_PTX_MASK) >> TXS_PTX_SHIFT; |
| 1065 | txs->lasttxtime = 0; |
| 1066 | |
| 1067 | *fatal = brcms_c_dotxstatus(wlc_hw->wlc, txs); |
| 1068 | |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 1069 | s1 = bcma_read32(core, D11REGOFFS(frmtxstatus)); |
Piotr Haber | 57fe504 | 2012-11-28 21:44:07 +0100 | [diff] [blame] | 1070 | n++; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1071 | } |
| 1072 | |
| 1073 | if (*fatal) |
Piotr Haber | 57fe504 | 2012-11-28 21:44:07 +0100 | [diff] [blame] | 1074 | return false; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1075 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1076 | return morepending; |
| 1077 | } |
| 1078 | |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 1079 | static void brcms_c_tbtt(struct brcms_c_info *wlc) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1080 | { |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 1081 | if (!wlc->bsscfg->BSS) |
| 1082 | /* |
| 1083 | * DirFrmQ is now valid...defer setting until end |
| 1084 | * of ATIM window |
| 1085 | */ |
| 1086 | wlc->qvalid |= MCMD_DIRFRMQVAL; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1087 | } |
| 1088 | |
| 1089 | /* set initial host flags value */ |
| 1090 | static void |
| 1091 | brcms_c_mhfdef(struct brcms_c_info *wlc, u16 *mhfs, u16 mhf2_init) |
| 1092 | { |
| 1093 | struct brcms_hardware *wlc_hw = wlc->hw; |
| 1094 | |
| 1095 | memset(mhfs, 0, MHFMAX * sizeof(u16)); |
| 1096 | |
| 1097 | mhfs[MHF2] |= mhf2_init; |
| 1098 | |
| 1099 | /* prohibit use of slowclock on multifunction boards */ |
| 1100 | if (wlc_hw->boardflags & BFL_NOPLLDOWN) |
| 1101 | mhfs[MHF1] |= MHF1_FORCEFASTCLK; |
| 1102 | |
| 1103 | if (BRCMS_ISNPHY(wlc_hw->band) && NREV_LT(wlc_hw->band->phyrev, 2)) { |
| 1104 | mhfs[MHF2] |= MHF2_NPHY40MHZ_WAR; |
| 1105 | mhfs[MHF1] |= MHF1_IQSWAP_WAR; |
| 1106 | } |
| 1107 | } |
| 1108 | |
Arend van Spriel | e81da65 | 2011-12-08 15:06:53 -0800 | [diff] [blame] | 1109 | static uint |
| 1110 | dmareg(uint direction, uint fifonum) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1111 | { |
| 1112 | if (direction == DMA_TX) |
Arend van Spriel | e81da65 | 2011-12-08 15:06:53 -0800 | [diff] [blame] | 1113 | return offsetof(struct d11regs, fifo64regs[fifonum].dmaxmt); |
| 1114 | return offsetof(struct d11regs, fifo64regs[fifonum].dmarcv); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1115 | } |
| 1116 | |
| 1117 | static bool brcms_b_attach_dmapio(struct brcms_c_info *wlc, uint j, bool wme) |
| 1118 | { |
| 1119 | uint i; |
| 1120 | char name[8]; |
| 1121 | /* |
| 1122 | * ucode host flag 2 needed for pio mode, independent of band and fifo |
| 1123 | */ |
| 1124 | u16 pio_mhf2 = 0; |
| 1125 | struct brcms_hardware *wlc_hw = wlc->hw; |
| 1126 | uint unit = wlc_hw->unit; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1127 | |
| 1128 | /* name and offsets for dma_attach */ |
| 1129 | snprintf(name, sizeof(name), "wl%d", unit); |
| 1130 | |
| 1131 | if (wlc_hw->di[0] == NULL) { /* Init FIFOs */ |
| 1132 | int dma_attach_err = 0; |
| 1133 | |
| 1134 | /* |
| 1135 | * FIFO 0 |
| 1136 | * TX: TX_AC_BK_FIFO (TX AC Background data packets) |
| 1137 | * RX: RX_FIFO (RX data packets) |
| 1138 | */ |
Seth Forshee | e041f65 | 2012-11-15 08:07:56 -0600 | [diff] [blame] | 1139 | wlc_hw->di[0] = dma_attach(name, wlc, |
Arend van Spriel | e81da65 | 2011-12-08 15:06:53 -0800 | [diff] [blame] | 1140 | (wme ? dmareg(DMA_TX, 0) : 0), |
| 1141 | dmareg(DMA_RX, 0), |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1142 | (wme ? NTXD : 0), NRXD, |
| 1143 | RXBUFSZ, -1, NRXBUFPOST, |
Seth Forshee | 90123e0 | 2012-11-15 08:08:07 -0600 | [diff] [blame] | 1144 | BRCMS_HWRXOFF); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1145 | dma_attach_err |= (NULL == wlc_hw->di[0]); |
| 1146 | |
| 1147 | /* |
| 1148 | * FIFO 1 |
| 1149 | * TX: TX_AC_BE_FIFO (TX AC Best-Effort data packets) |
| 1150 | * (legacy) TX_DATA_FIFO (TX data packets) |
| 1151 | * RX: UNUSED |
| 1152 | */ |
Seth Forshee | e041f65 | 2012-11-15 08:07:56 -0600 | [diff] [blame] | 1153 | wlc_hw->di[1] = dma_attach(name, wlc, |
Arend van Spriel | e81da65 | 2011-12-08 15:06:53 -0800 | [diff] [blame] | 1154 | dmareg(DMA_TX, 1), 0, |
Seth Forshee | 90123e0 | 2012-11-15 08:08:07 -0600 | [diff] [blame] | 1155 | NTXD, 0, 0, -1, 0, 0); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1156 | dma_attach_err |= (NULL == wlc_hw->di[1]); |
| 1157 | |
| 1158 | /* |
| 1159 | * FIFO 2 |
| 1160 | * TX: TX_AC_VI_FIFO (TX AC Video data packets) |
| 1161 | * RX: UNUSED |
| 1162 | */ |
Seth Forshee | e041f65 | 2012-11-15 08:07:56 -0600 | [diff] [blame] | 1163 | wlc_hw->di[2] = dma_attach(name, wlc, |
Arend van Spriel | e81da65 | 2011-12-08 15:06:53 -0800 | [diff] [blame] | 1164 | dmareg(DMA_TX, 2), 0, |
Seth Forshee | 90123e0 | 2012-11-15 08:08:07 -0600 | [diff] [blame] | 1165 | NTXD, 0, 0, -1, 0, 0); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1166 | dma_attach_err |= (NULL == wlc_hw->di[2]); |
| 1167 | /* |
| 1168 | * FIFO 3 |
| 1169 | * TX: TX_AC_VO_FIFO (TX AC Voice data packets) |
| 1170 | * (legacy) TX_CTL_FIFO (TX control & mgmt packets) |
| 1171 | */ |
Seth Forshee | e041f65 | 2012-11-15 08:07:56 -0600 | [diff] [blame] | 1172 | wlc_hw->di[3] = dma_attach(name, wlc, |
Arend van Spriel | e81da65 | 2011-12-08 15:06:53 -0800 | [diff] [blame] | 1173 | dmareg(DMA_TX, 3), |
| 1174 | 0, NTXD, 0, 0, -1, |
Seth Forshee | 90123e0 | 2012-11-15 08:08:07 -0600 | [diff] [blame] | 1175 | 0, 0); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1176 | dma_attach_err |= (NULL == wlc_hw->di[3]); |
| 1177 | /* Cleaner to leave this as if with AP defined */ |
| 1178 | |
| 1179 | if (dma_attach_err) { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 1180 | brcms_err(wlc_hw->d11core, |
| 1181 | "wl%d: wlc_attach: dma_attach failed\n", |
| 1182 | unit); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1183 | return false; |
| 1184 | } |
| 1185 | |
| 1186 | /* get pointer to dma engine tx flow control variable */ |
| 1187 | for (i = 0; i < NFIFO; i++) |
| 1188 | if (wlc_hw->di[i]) |
| 1189 | wlc_hw->txavail[i] = |
| 1190 | (uint *) dma_getvar(wlc_hw->di[i], |
| 1191 | "&txavail"); |
| 1192 | } |
| 1193 | |
| 1194 | /* initial ucode host flags */ |
| 1195 | brcms_c_mhfdef(wlc, wlc_hw->band->mhfs, pio_mhf2); |
| 1196 | |
| 1197 | return true; |
| 1198 | } |
| 1199 | |
| 1200 | static void brcms_b_detach_dmapio(struct brcms_hardware *wlc_hw) |
| 1201 | { |
| 1202 | uint j; |
| 1203 | |
| 1204 | for (j = 0; j < NFIFO; j++) { |
| 1205 | if (wlc_hw->di[j]) { |
| 1206 | dma_detach(wlc_hw->di[j]); |
| 1207 | wlc_hw->di[j] = NULL; |
| 1208 | } |
| 1209 | } |
| 1210 | } |
| 1211 | |
| 1212 | /* |
| 1213 | * Initialize brcms_c_info default values ... |
| 1214 | * may get overrides later in this function |
| 1215 | * BMAC_NOTES, move low out and resolve the dangling ones |
| 1216 | */ |
| 1217 | static void brcms_b_info_init(struct brcms_hardware *wlc_hw) |
| 1218 | { |
| 1219 | struct brcms_c_info *wlc = wlc_hw->wlc; |
| 1220 | |
| 1221 | /* set default sw macintmask value */ |
| 1222 | wlc->defmacintmask = DEF_MACINTMASK; |
| 1223 | |
| 1224 | /* various 802.11g modes */ |
| 1225 | wlc_hw->shortslot = false; |
| 1226 | |
| 1227 | wlc_hw->SFBL = RETRY_SHORT_FB; |
| 1228 | wlc_hw->LFBL = RETRY_LONG_FB; |
| 1229 | |
| 1230 | /* default mac retry limits */ |
| 1231 | wlc_hw->SRL = RETRY_SHORT_DEF; |
| 1232 | wlc_hw->LRL = RETRY_LONG_DEF; |
| 1233 | wlc_hw->chanspec = ch20mhz_chspec(1); |
| 1234 | } |
| 1235 | |
| 1236 | static void brcms_b_wait_for_wake(struct brcms_hardware *wlc_hw) |
| 1237 | { |
| 1238 | /* delay before first read of ucode state */ |
| 1239 | udelay(40); |
| 1240 | |
| 1241 | /* wait until ucode is no longer asleep */ |
| 1242 | SPINWAIT((brcms_b_read_shm(wlc_hw, M_UCODE_DBGST) == |
| 1243 | DBGST_ASLEEP), wlc_hw->wlc->fastpwrup_dly); |
| 1244 | } |
| 1245 | |
| 1246 | /* control chip clock to save power, enable dynamic clock or force fast clock */ |
Hauke Mehrtens | 712e3c1 | 2012-04-29 02:50:35 +0200 | [diff] [blame] | 1247 | static void brcms_b_clkctl_clk(struct brcms_hardware *wlc_hw, enum bcma_clkmode mode) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1248 | { |
Arend van Spriel | b2ffec4 | 2011-12-08 15:06:45 -0800 | [diff] [blame] | 1249 | if (ai_get_cccaps(wlc_hw->sih) & CC_CAP_PMU) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1250 | /* new chips with PMU, CCS_FORCEHT will distribute the HT clock |
| 1251 | * on backplane, but mac core will still run on ALP(not HT) when |
| 1252 | * it enters powersave mode, which means the FCA bit may not be |
| 1253 | * set. Should wakeup mac if driver wants it to run on HT. |
| 1254 | */ |
| 1255 | |
| 1256 | if (wlc_hw->clk) { |
Hauke Mehrtens | 712e3c1 | 2012-04-29 02:50:35 +0200 | [diff] [blame] | 1257 | if (mode == BCMA_CLKMODE_FAST) { |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 1258 | bcma_set32(wlc_hw->d11core, |
| 1259 | D11REGOFFS(clk_ctl_st), |
| 1260 | CCS_FORCEHT); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1261 | |
| 1262 | udelay(64); |
| 1263 | |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 1264 | SPINWAIT( |
| 1265 | ((bcma_read32(wlc_hw->d11core, |
| 1266 | D11REGOFFS(clk_ctl_st)) & |
| 1267 | CCS_HTAVAIL) == 0), |
| 1268 | PMU_MAX_TRANSITION_DLY); |
| 1269 | WARN_ON(!(bcma_read32(wlc_hw->d11core, |
| 1270 | D11REGOFFS(clk_ctl_st)) & |
| 1271 | CCS_HTAVAIL)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1272 | } else { |
Arend van Spriel | b2ffec4 | 2011-12-08 15:06:45 -0800 | [diff] [blame] | 1273 | if ((ai_get_pmurev(wlc_hw->sih) == 0) && |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 1274 | (bcma_read32(wlc_hw->d11core, |
| 1275 | D11REGOFFS(clk_ctl_st)) & |
| 1276 | (CCS_FORCEHT | CCS_HTAREQ))) |
| 1277 | SPINWAIT( |
| 1278 | ((bcma_read32(wlc_hw->d11core, |
| 1279 | offsetof(struct d11regs, |
| 1280 | clk_ctl_st)) & |
| 1281 | CCS_HTAVAIL) == 0), |
| 1282 | PMU_MAX_TRANSITION_DLY); |
| 1283 | bcma_mask32(wlc_hw->d11core, |
| 1284 | D11REGOFFS(clk_ctl_st), |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1285 | ~CCS_FORCEHT); |
| 1286 | } |
| 1287 | } |
Hauke Mehrtens | 712e3c1 | 2012-04-29 02:50:35 +0200 | [diff] [blame] | 1288 | wlc_hw->forcefastclk = (mode == BCMA_CLKMODE_FAST); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1289 | } else { |
| 1290 | |
| 1291 | /* old chips w/o PMU, force HT through cc, |
| 1292 | * then use FCA to verify mac is running fast clock |
| 1293 | */ |
| 1294 | |
| 1295 | wlc_hw->forcefastclk = ai_clkctl_cc(wlc_hw->sih, mode); |
| 1296 | |
| 1297 | /* check fast clock is available (if core is not in reset) */ |
| 1298 | if (wlc_hw->forcefastclk && wlc_hw->clk) |
Arend van Spriel | a8779e4 | 2011-12-08 15:06:58 -0800 | [diff] [blame] | 1299 | WARN_ON(!(bcma_aread32(wlc_hw->d11core, BCMA_IOST) & |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1300 | SISF_FCLKA)); |
| 1301 | |
| 1302 | /* |
| 1303 | * keep the ucode wake bit on if forcefastclk is on since we |
| 1304 | * do not want ucode to put us back to slow clock when it dozes |
| 1305 | * for PM mode. Code below matches the wake override bit with |
| 1306 | * current forcefastclk state. Only setting bit in wake_override |
| 1307 | * instead of waking ucode immediately since old code had this |
| 1308 | * behavior. Older code set wlc->forcefastclk but only had the |
| 1309 | * wake happen if the wakup_ucode work (protected by an up |
| 1310 | * check) was executed just below. |
| 1311 | */ |
| 1312 | if (wlc_hw->forcefastclk) |
| 1313 | mboolset(wlc_hw->wake_override, |
| 1314 | BRCMS_WAKE_OVERRIDE_FORCEFAST); |
| 1315 | else |
| 1316 | mboolclr(wlc_hw->wake_override, |
| 1317 | BRCMS_WAKE_OVERRIDE_FORCEFAST); |
| 1318 | } |
| 1319 | } |
| 1320 | |
| 1321 | /* set or clear ucode host flag bits |
| 1322 | * it has an optimization for no-change write |
| 1323 | * it only writes through shared memory when the core has clock; |
| 1324 | * pre-CLK changes should use wlc_write_mhf to get around the optimization |
| 1325 | * |
| 1326 | * |
| 1327 | * bands values are: BRCM_BAND_AUTO <--- Current band only |
| 1328 | * BRCM_BAND_5G <--- 5G band only |
| 1329 | * BRCM_BAND_2G <--- 2G band only |
| 1330 | * BRCM_BAND_ALL <--- All bands |
| 1331 | */ |
| 1332 | void |
| 1333 | brcms_b_mhf(struct brcms_hardware *wlc_hw, u8 idx, u16 mask, u16 val, |
| 1334 | int bands) |
| 1335 | { |
| 1336 | u16 save; |
| 1337 | u16 addr[MHFMAX] = { |
| 1338 | M_HOST_FLAGS1, M_HOST_FLAGS2, M_HOST_FLAGS3, M_HOST_FLAGS4, |
| 1339 | M_HOST_FLAGS5 |
| 1340 | }; |
| 1341 | struct brcms_hw_band *band; |
| 1342 | |
| 1343 | if ((val & ~mask) || idx >= MHFMAX) |
| 1344 | return; /* error condition */ |
| 1345 | |
| 1346 | switch (bands) { |
| 1347 | /* Current band only or all bands, |
| 1348 | * then set the band to current band |
| 1349 | */ |
| 1350 | case BRCM_BAND_AUTO: |
| 1351 | case BRCM_BAND_ALL: |
| 1352 | band = wlc_hw->band; |
| 1353 | break; |
| 1354 | case BRCM_BAND_5G: |
| 1355 | band = wlc_hw->bandstate[BAND_5G_INDEX]; |
| 1356 | break; |
| 1357 | case BRCM_BAND_2G: |
| 1358 | band = wlc_hw->bandstate[BAND_2G_INDEX]; |
| 1359 | break; |
| 1360 | default: |
| 1361 | band = NULL; /* error condition */ |
| 1362 | } |
| 1363 | |
| 1364 | if (band) { |
| 1365 | save = band->mhfs[idx]; |
| 1366 | band->mhfs[idx] = (band->mhfs[idx] & ~mask) | val; |
| 1367 | |
| 1368 | /* optimization: only write through if changed, and |
| 1369 | * changed band is the current band |
| 1370 | */ |
| 1371 | if (wlc_hw->clk && (band->mhfs[idx] != save) |
| 1372 | && (band == wlc_hw->band)) |
| 1373 | brcms_b_write_shm(wlc_hw, addr[idx], |
| 1374 | (u16) band->mhfs[idx]); |
| 1375 | } |
| 1376 | |
| 1377 | if (bands == BRCM_BAND_ALL) { |
| 1378 | wlc_hw->bandstate[0]->mhfs[idx] = |
| 1379 | (wlc_hw->bandstate[0]->mhfs[idx] & ~mask) | val; |
| 1380 | wlc_hw->bandstate[1]->mhfs[idx] = |
| 1381 | (wlc_hw->bandstate[1]->mhfs[idx] & ~mask) | val; |
| 1382 | } |
| 1383 | } |
| 1384 | |
| 1385 | /* set the maccontrol register to desired reset state and |
| 1386 | * initialize the sw cache of the register |
| 1387 | */ |
| 1388 | static void brcms_c_mctrl_reset(struct brcms_hardware *wlc_hw) |
| 1389 | { |
| 1390 | /* IHR accesses are always enabled, PSM disabled, HPS off and WAKE on */ |
| 1391 | wlc_hw->maccontrol = 0; |
| 1392 | wlc_hw->suspended_fifos = 0; |
| 1393 | wlc_hw->wake_override = 0; |
| 1394 | wlc_hw->mute_override = 0; |
| 1395 | brcms_b_mctrl(wlc_hw, ~0, MCTL_IHR_EN | MCTL_WAKE); |
| 1396 | } |
| 1397 | |
| 1398 | /* |
| 1399 | * write the software state of maccontrol and |
| 1400 | * overrides to the maccontrol register |
| 1401 | */ |
| 1402 | static void brcms_c_mctrl_write(struct brcms_hardware *wlc_hw) |
| 1403 | { |
| 1404 | u32 maccontrol = wlc_hw->maccontrol; |
| 1405 | |
| 1406 | /* OR in the wake bit if overridden */ |
| 1407 | if (wlc_hw->wake_override) |
| 1408 | maccontrol |= MCTL_WAKE; |
| 1409 | |
| 1410 | /* set AP and INFRA bits for mute if needed */ |
| 1411 | if (wlc_hw->mute_override) { |
| 1412 | maccontrol &= ~(MCTL_AP); |
| 1413 | maccontrol |= MCTL_INFRA; |
| 1414 | } |
| 1415 | |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 1416 | bcma_write32(wlc_hw->d11core, D11REGOFFS(maccontrol), |
| 1417 | maccontrol); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1418 | } |
| 1419 | |
| 1420 | /* set or clear maccontrol bits */ |
| 1421 | void brcms_b_mctrl(struct brcms_hardware *wlc_hw, u32 mask, u32 val) |
| 1422 | { |
| 1423 | u32 maccontrol; |
| 1424 | u32 new_maccontrol; |
| 1425 | |
| 1426 | if (val & ~mask) |
| 1427 | return; /* error condition */ |
| 1428 | maccontrol = wlc_hw->maccontrol; |
| 1429 | new_maccontrol = (maccontrol & ~mask) | val; |
| 1430 | |
| 1431 | /* if the new maccontrol value is the same as the old, nothing to do */ |
| 1432 | if (new_maccontrol == maccontrol) |
| 1433 | return; |
| 1434 | |
| 1435 | /* something changed, cache the new value */ |
| 1436 | wlc_hw->maccontrol = new_maccontrol; |
| 1437 | |
| 1438 | /* write the new values with overrides applied */ |
| 1439 | brcms_c_mctrl_write(wlc_hw); |
| 1440 | } |
| 1441 | |
| 1442 | void brcms_c_ucode_wake_override_set(struct brcms_hardware *wlc_hw, |
| 1443 | u32 override_bit) |
| 1444 | { |
| 1445 | if (wlc_hw->wake_override || (wlc_hw->maccontrol & MCTL_WAKE)) { |
| 1446 | mboolset(wlc_hw->wake_override, override_bit); |
| 1447 | return; |
| 1448 | } |
| 1449 | |
| 1450 | mboolset(wlc_hw->wake_override, override_bit); |
| 1451 | |
| 1452 | brcms_c_mctrl_write(wlc_hw); |
| 1453 | brcms_b_wait_for_wake(wlc_hw); |
| 1454 | } |
| 1455 | |
| 1456 | void brcms_c_ucode_wake_override_clear(struct brcms_hardware *wlc_hw, |
| 1457 | u32 override_bit) |
| 1458 | { |
| 1459 | mboolclr(wlc_hw->wake_override, override_bit); |
| 1460 | |
| 1461 | if (wlc_hw->wake_override || (wlc_hw->maccontrol & MCTL_WAKE)) |
| 1462 | return; |
| 1463 | |
| 1464 | brcms_c_mctrl_write(wlc_hw); |
| 1465 | } |
| 1466 | |
| 1467 | /* When driver needs ucode to stop beaconing, it has to make sure that |
| 1468 | * MCTL_AP is clear and MCTL_INFRA is set |
| 1469 | * Mode MCTL_AP MCTL_INFRA |
| 1470 | * AP 1 1 |
| 1471 | * STA 0 1 <--- This will ensure no beacons |
| 1472 | * IBSS 0 0 |
| 1473 | */ |
| 1474 | static void brcms_c_ucode_mute_override_set(struct brcms_hardware *wlc_hw) |
| 1475 | { |
| 1476 | wlc_hw->mute_override = 1; |
| 1477 | |
| 1478 | /* if maccontrol already has AP == 0 and INFRA == 1 without this |
| 1479 | * override, then there is no change to write |
| 1480 | */ |
| 1481 | if ((wlc_hw->maccontrol & (MCTL_AP | MCTL_INFRA)) == MCTL_INFRA) |
| 1482 | return; |
| 1483 | |
| 1484 | brcms_c_mctrl_write(wlc_hw); |
| 1485 | } |
| 1486 | |
| 1487 | /* Clear the override on AP and INFRA bits */ |
| 1488 | static void brcms_c_ucode_mute_override_clear(struct brcms_hardware *wlc_hw) |
| 1489 | { |
| 1490 | if (wlc_hw->mute_override == 0) |
| 1491 | return; |
| 1492 | |
| 1493 | wlc_hw->mute_override = 0; |
| 1494 | |
| 1495 | /* if maccontrol already has AP == 0 and INFRA == 1 without this |
| 1496 | * override, then there is no change to write |
| 1497 | */ |
| 1498 | if ((wlc_hw->maccontrol & (MCTL_AP | MCTL_INFRA)) == MCTL_INFRA) |
| 1499 | return; |
| 1500 | |
| 1501 | brcms_c_mctrl_write(wlc_hw); |
| 1502 | } |
| 1503 | |
| 1504 | /* |
| 1505 | * Write a MAC address to the given match reg offset in the RXE match engine. |
| 1506 | */ |
| 1507 | static void |
| 1508 | brcms_b_set_addrmatch(struct brcms_hardware *wlc_hw, int match_reg_offset, |
| 1509 | const u8 *addr) |
| 1510 | { |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 1511 | struct bcma_device *core = wlc_hw->d11core; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1512 | u16 mac_l; |
| 1513 | u16 mac_m; |
| 1514 | u16 mac_h; |
| 1515 | |
Seth Forshee | 5ce58bb | 2012-11-15 08:08:05 -0600 | [diff] [blame] | 1516 | brcms_dbg_rx(core, "wl%d: brcms_b_set_addrmatch\n", wlc_hw->unit); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1517 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1518 | mac_l = addr[0] | (addr[1] << 8); |
| 1519 | mac_m = addr[2] | (addr[3] << 8); |
| 1520 | mac_h = addr[4] | (addr[5] << 8); |
| 1521 | |
| 1522 | /* enter the MAC addr into the RXE match registers */ |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 1523 | bcma_write16(core, D11REGOFFS(rcm_ctl), |
| 1524 | RCM_INC_DATA | match_reg_offset); |
| 1525 | bcma_write16(core, D11REGOFFS(rcm_mat_data), mac_l); |
| 1526 | bcma_write16(core, D11REGOFFS(rcm_mat_data), mac_m); |
| 1527 | bcma_write16(core, D11REGOFFS(rcm_mat_data), mac_h); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1528 | } |
| 1529 | |
| 1530 | void |
| 1531 | brcms_b_write_template_ram(struct brcms_hardware *wlc_hw, int offset, int len, |
| 1532 | void *buf) |
| 1533 | { |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 1534 | struct bcma_device *core = wlc_hw->d11core; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1535 | u32 word; |
| 1536 | __le32 word_le; |
| 1537 | __be32 word_be; |
| 1538 | bool be_bit; |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 1539 | brcms_dbg_info(core, "wl%d\n", wlc_hw->unit); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1540 | |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 1541 | bcma_write32(core, D11REGOFFS(tplatewrptr), offset); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1542 | |
| 1543 | /* if MCTL_BIGEND bit set in mac control register, |
| 1544 | * the chip swaps data in fifo, as well as data in |
| 1545 | * template ram |
| 1546 | */ |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 1547 | be_bit = (bcma_read32(core, D11REGOFFS(maccontrol)) & MCTL_BIGEND) != 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1548 | |
| 1549 | while (len > 0) { |
| 1550 | memcpy(&word, buf, sizeof(u32)); |
| 1551 | |
| 1552 | if (be_bit) { |
| 1553 | word_be = cpu_to_be32(word); |
| 1554 | word = *(u32 *)&word_be; |
| 1555 | } else { |
| 1556 | word_le = cpu_to_le32(word); |
| 1557 | word = *(u32 *)&word_le; |
| 1558 | } |
| 1559 | |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 1560 | bcma_write32(core, D11REGOFFS(tplatewrdata), word); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1561 | |
| 1562 | buf = (u8 *) buf + sizeof(u32); |
| 1563 | len -= sizeof(u32); |
| 1564 | } |
| 1565 | } |
| 1566 | |
| 1567 | static void brcms_b_set_cwmin(struct brcms_hardware *wlc_hw, u16 newmin) |
| 1568 | { |
| 1569 | wlc_hw->band->CWmin = newmin; |
| 1570 | |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 1571 | bcma_write32(wlc_hw->d11core, D11REGOFFS(objaddr), |
| 1572 | OBJADDR_SCR_SEL | S_DOT11_CWMIN); |
| 1573 | (void)bcma_read32(wlc_hw->d11core, D11REGOFFS(objaddr)); |
| 1574 | bcma_write32(wlc_hw->d11core, D11REGOFFS(objdata), newmin); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1575 | } |
| 1576 | |
| 1577 | static void brcms_b_set_cwmax(struct brcms_hardware *wlc_hw, u16 newmax) |
| 1578 | { |
| 1579 | wlc_hw->band->CWmax = newmax; |
| 1580 | |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 1581 | bcma_write32(wlc_hw->d11core, D11REGOFFS(objaddr), |
| 1582 | OBJADDR_SCR_SEL | S_DOT11_CWMAX); |
| 1583 | (void)bcma_read32(wlc_hw->d11core, D11REGOFFS(objaddr)); |
| 1584 | bcma_write32(wlc_hw->d11core, D11REGOFFS(objdata), newmax); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1585 | } |
| 1586 | |
| 1587 | void brcms_b_bw_set(struct brcms_hardware *wlc_hw, u16 bw) |
| 1588 | { |
| 1589 | bool fastclk; |
| 1590 | |
| 1591 | /* request FAST clock if not on */ |
| 1592 | fastclk = wlc_hw->forcefastclk; |
| 1593 | if (!fastclk) |
Hauke Mehrtens | 712e3c1 | 2012-04-29 02:50:35 +0200 | [diff] [blame] | 1594 | brcms_b_clkctl_clk(wlc_hw, BCMA_CLKMODE_FAST); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1595 | |
| 1596 | wlc_phy_bw_state_set(wlc_hw->band->pi, bw); |
| 1597 | |
| 1598 | brcms_b_phy_reset(wlc_hw); |
| 1599 | wlc_phy_init(wlc_hw->band->pi, wlc_phy_chanspec_get(wlc_hw->band->pi)); |
| 1600 | |
| 1601 | /* restore the clk */ |
| 1602 | if (!fastclk) |
Hauke Mehrtens | 712e3c1 | 2012-04-29 02:50:35 +0200 | [diff] [blame] | 1603 | brcms_b_clkctl_clk(wlc_hw, BCMA_CLKMODE_DYNAMIC); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1604 | } |
| 1605 | |
| 1606 | static void brcms_b_upd_synthpu(struct brcms_hardware *wlc_hw) |
| 1607 | { |
| 1608 | u16 v; |
| 1609 | struct brcms_c_info *wlc = wlc_hw->wlc; |
| 1610 | /* update SYNTHPU_DLY */ |
| 1611 | |
| 1612 | if (BRCMS_ISLCNPHY(wlc->band)) |
| 1613 | v = SYNTHPU_DLY_LPPHY_US; |
| 1614 | else if (BRCMS_ISNPHY(wlc->band) && (NREV_GE(wlc->band->phyrev, 3))) |
| 1615 | v = SYNTHPU_DLY_NPHY_US; |
| 1616 | else |
| 1617 | v = SYNTHPU_DLY_BPHY_US; |
| 1618 | |
| 1619 | brcms_b_write_shm(wlc_hw, M_SYNTHPU_DLY, v); |
| 1620 | } |
| 1621 | |
| 1622 | static void brcms_c_ucode_txant_set(struct brcms_hardware *wlc_hw) |
| 1623 | { |
| 1624 | u16 phyctl; |
| 1625 | u16 phytxant = wlc_hw->bmac_phytxant; |
| 1626 | u16 mask = PHY_TXC_ANT_MASK; |
| 1627 | |
| 1628 | /* set the Probe Response frame phy control word */ |
| 1629 | phyctl = brcms_b_read_shm(wlc_hw, M_CTXPRS_BLK + C_CTX_PCTLWD_POS); |
| 1630 | phyctl = (phyctl & ~mask) | phytxant; |
| 1631 | brcms_b_write_shm(wlc_hw, M_CTXPRS_BLK + C_CTX_PCTLWD_POS, phyctl); |
| 1632 | |
| 1633 | /* set the Response (ACK/CTS) frame phy control word */ |
| 1634 | phyctl = brcms_b_read_shm(wlc_hw, M_RSP_PCTLWD); |
| 1635 | phyctl = (phyctl & ~mask) | phytxant; |
| 1636 | brcms_b_write_shm(wlc_hw, M_RSP_PCTLWD, phyctl); |
| 1637 | } |
| 1638 | |
| 1639 | static u16 brcms_b_ofdm_ratetable_offset(struct brcms_hardware *wlc_hw, |
| 1640 | u8 rate) |
| 1641 | { |
| 1642 | uint i; |
| 1643 | u8 plcp_rate = 0; |
| 1644 | struct plcp_signal_rate_lookup { |
| 1645 | u8 rate; |
| 1646 | u8 signal_rate; |
| 1647 | }; |
| 1648 | /* OFDM RATE sub-field of PLCP SIGNAL field, per 802.11 sec 17.3.4.1 */ |
| 1649 | const struct plcp_signal_rate_lookup rate_lookup[] = { |
| 1650 | {BRCM_RATE_6M, 0xB}, |
| 1651 | {BRCM_RATE_9M, 0xF}, |
| 1652 | {BRCM_RATE_12M, 0xA}, |
| 1653 | {BRCM_RATE_18M, 0xE}, |
| 1654 | {BRCM_RATE_24M, 0x9}, |
| 1655 | {BRCM_RATE_36M, 0xD}, |
| 1656 | {BRCM_RATE_48M, 0x8}, |
| 1657 | {BRCM_RATE_54M, 0xC} |
| 1658 | }; |
| 1659 | |
| 1660 | for (i = 0; i < ARRAY_SIZE(rate_lookup); i++) { |
| 1661 | if (rate == rate_lookup[i].rate) { |
| 1662 | plcp_rate = rate_lookup[i].signal_rate; |
| 1663 | break; |
| 1664 | } |
| 1665 | } |
| 1666 | |
| 1667 | /* Find the SHM pointer to the rate table entry by looking in the |
| 1668 | * Direct-map Table |
| 1669 | */ |
| 1670 | return 2 * brcms_b_read_shm(wlc_hw, M_RT_DIRMAP_A + (plcp_rate * 2)); |
| 1671 | } |
| 1672 | |
| 1673 | static void brcms_upd_ofdm_pctl1_table(struct brcms_hardware *wlc_hw) |
| 1674 | { |
| 1675 | u8 rate; |
| 1676 | u8 rates[8] = { |
| 1677 | BRCM_RATE_6M, BRCM_RATE_9M, BRCM_RATE_12M, BRCM_RATE_18M, |
| 1678 | BRCM_RATE_24M, BRCM_RATE_36M, BRCM_RATE_48M, BRCM_RATE_54M |
| 1679 | }; |
| 1680 | u16 entry_ptr; |
| 1681 | u16 pctl1; |
| 1682 | uint i; |
| 1683 | |
| 1684 | if (!BRCMS_PHY_11N_CAP(wlc_hw->band)) |
| 1685 | return; |
| 1686 | |
| 1687 | /* walk the phy rate table and update the entries */ |
| 1688 | for (i = 0; i < ARRAY_SIZE(rates); i++) { |
| 1689 | rate = rates[i]; |
| 1690 | |
| 1691 | entry_ptr = brcms_b_ofdm_ratetable_offset(wlc_hw, rate); |
| 1692 | |
| 1693 | /* read the SHM Rate Table entry OFDM PCTL1 values */ |
| 1694 | pctl1 = |
| 1695 | brcms_b_read_shm(wlc_hw, entry_ptr + M_RT_OFDM_PCTL1_POS); |
| 1696 | |
| 1697 | /* modify the value */ |
| 1698 | pctl1 &= ~PHY_TXC1_MODE_MASK; |
| 1699 | pctl1 |= (wlc_hw->hw_stf_ss_opmode << PHY_TXC1_MODE_SHIFT); |
| 1700 | |
| 1701 | /* Update the SHM Rate Table entry OFDM PCTL1 values */ |
| 1702 | brcms_b_write_shm(wlc_hw, entry_ptr + M_RT_OFDM_PCTL1_POS, |
| 1703 | pctl1); |
| 1704 | } |
| 1705 | } |
| 1706 | |
| 1707 | /* band-specific init */ |
| 1708 | static void brcms_b_bsinit(struct brcms_c_info *wlc, u16 chanspec) |
| 1709 | { |
| 1710 | struct brcms_hardware *wlc_hw = wlc->hw; |
| 1711 | |
Seth Forshee | 913911f | 2012-11-15 08:08:04 -0600 | [diff] [blame] | 1712 | brcms_dbg_mac80211(wlc_hw->d11core, "wl%d: bandunit %d\n", wlc_hw->unit, |
| 1713 | wlc_hw->band->bandunit); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1714 | |
| 1715 | brcms_c_ucode_bsinit(wlc_hw); |
| 1716 | |
| 1717 | wlc_phy_init(wlc_hw->band->pi, chanspec); |
| 1718 | |
| 1719 | brcms_c_ucode_txant_set(wlc_hw); |
| 1720 | |
| 1721 | /* |
| 1722 | * cwmin is band-specific, update hardware |
| 1723 | * with value for current band |
| 1724 | */ |
| 1725 | brcms_b_set_cwmin(wlc_hw, wlc_hw->band->CWmin); |
| 1726 | brcms_b_set_cwmax(wlc_hw, wlc_hw->band->CWmax); |
| 1727 | |
| 1728 | brcms_b_update_slot_timing(wlc_hw, |
| 1729 | wlc_hw->band->bandtype == BRCM_BAND_5G ? |
| 1730 | true : wlc_hw->shortslot); |
| 1731 | |
| 1732 | /* write phytype and phyvers */ |
| 1733 | brcms_b_write_shm(wlc_hw, M_PHYTYPE, (u16) wlc_hw->band->phytype); |
| 1734 | brcms_b_write_shm(wlc_hw, M_PHYVER, (u16) wlc_hw->band->phyrev); |
| 1735 | |
| 1736 | /* |
| 1737 | * initialize the txphyctl1 rate table since |
| 1738 | * shmem is shared between bands |
| 1739 | */ |
| 1740 | brcms_upd_ofdm_pctl1_table(wlc_hw); |
| 1741 | |
| 1742 | brcms_b_upd_synthpu(wlc_hw); |
| 1743 | } |
| 1744 | |
| 1745 | /* Perform a soft reset of the PHY PLL */ |
| 1746 | void brcms_b_core_phypll_reset(struct brcms_hardware *wlc_hw) |
| 1747 | { |
Arend van Spriel | 7d8e18e | 2011-12-08 15:06:56 -0800 | [diff] [blame] | 1748 | ai_cc_reg(wlc_hw->sih, offsetof(struct chipcregs, chipcontrol_addr), |
| 1749 | ~0, 0); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1750 | udelay(1); |
Arend van Spriel | 7d8e18e | 2011-12-08 15:06:56 -0800 | [diff] [blame] | 1751 | ai_cc_reg(wlc_hw->sih, offsetof(struct chipcregs, chipcontrol_data), |
| 1752 | 0x4, 0); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1753 | udelay(1); |
Arend van Spriel | 7d8e18e | 2011-12-08 15:06:56 -0800 | [diff] [blame] | 1754 | ai_cc_reg(wlc_hw->sih, offsetof(struct chipcregs, chipcontrol_data), |
| 1755 | 0x4, 4); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1756 | udelay(1); |
Arend van Spriel | 7d8e18e | 2011-12-08 15:06:56 -0800 | [diff] [blame] | 1757 | ai_cc_reg(wlc_hw->sih, offsetof(struct chipcregs, chipcontrol_data), |
| 1758 | 0x4, 0); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1759 | udelay(1); |
| 1760 | } |
| 1761 | |
| 1762 | /* light way to turn on phy clock without reset for NPHY only |
| 1763 | * refer to brcms_b_core_phy_clk for full version |
| 1764 | */ |
| 1765 | void brcms_b_phyclk_fgc(struct brcms_hardware *wlc_hw, bool clk) |
| 1766 | { |
| 1767 | /* support(necessary for NPHY and HYPHY) only */ |
| 1768 | if (!BRCMS_ISNPHY(wlc_hw->band)) |
| 1769 | return; |
| 1770 | |
| 1771 | if (ON == clk) |
Arend van Spriel | a8779e4 | 2011-12-08 15:06:58 -0800 | [diff] [blame] | 1772 | brcms_b_core_ioctl(wlc_hw, SICF_FGC, SICF_FGC); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1773 | else |
Arend van Spriel | a8779e4 | 2011-12-08 15:06:58 -0800 | [diff] [blame] | 1774 | brcms_b_core_ioctl(wlc_hw, SICF_FGC, 0); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1775 | |
| 1776 | } |
| 1777 | |
| 1778 | void brcms_b_macphyclk_set(struct brcms_hardware *wlc_hw, bool clk) |
| 1779 | { |
| 1780 | if (ON == clk) |
Arend van Spriel | a8779e4 | 2011-12-08 15:06:58 -0800 | [diff] [blame] | 1781 | brcms_b_core_ioctl(wlc_hw, SICF_MPCLKE, SICF_MPCLKE); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1782 | else |
Arend van Spriel | a8779e4 | 2011-12-08 15:06:58 -0800 | [diff] [blame] | 1783 | brcms_b_core_ioctl(wlc_hw, SICF_MPCLKE, 0); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1784 | } |
| 1785 | |
| 1786 | void brcms_b_phy_reset(struct brcms_hardware *wlc_hw) |
| 1787 | { |
| 1788 | struct brcms_phy_pub *pih = wlc_hw->band->pi; |
| 1789 | u32 phy_bw_clkbits; |
| 1790 | bool phy_in_reset = false; |
| 1791 | |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 1792 | brcms_dbg_info(wlc_hw->d11core, "wl%d: reset phy\n", wlc_hw->unit); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1793 | |
| 1794 | if (pih == NULL) |
| 1795 | return; |
| 1796 | |
| 1797 | phy_bw_clkbits = wlc_phy_clk_bwbits(wlc_hw->band->pi); |
| 1798 | |
| 1799 | /* Specific reset sequence required for NPHY rev 3 and 4 */ |
| 1800 | if (BRCMS_ISNPHY(wlc_hw->band) && NREV_GE(wlc_hw->band->phyrev, 3) && |
| 1801 | NREV_LE(wlc_hw->band->phyrev, 4)) { |
| 1802 | /* Set the PHY bandwidth */ |
Arend van Spriel | a8779e4 | 2011-12-08 15:06:58 -0800 | [diff] [blame] | 1803 | brcms_b_core_ioctl(wlc_hw, SICF_BWMASK, phy_bw_clkbits); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1804 | |
| 1805 | udelay(1); |
| 1806 | |
| 1807 | /* Perform a soft reset of the PHY PLL */ |
| 1808 | brcms_b_core_phypll_reset(wlc_hw); |
| 1809 | |
| 1810 | /* reset the PHY */ |
Arend van Spriel | a8779e4 | 2011-12-08 15:06:58 -0800 | [diff] [blame] | 1811 | brcms_b_core_ioctl(wlc_hw, (SICF_PRST | SICF_PCLKE), |
| 1812 | (SICF_PRST | SICF_PCLKE)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1813 | phy_in_reset = true; |
| 1814 | } else { |
Arend van Spriel | a8779e4 | 2011-12-08 15:06:58 -0800 | [diff] [blame] | 1815 | brcms_b_core_ioctl(wlc_hw, |
| 1816 | (SICF_PRST | SICF_PCLKE | SICF_BWMASK), |
| 1817 | (SICF_PRST | SICF_PCLKE | phy_bw_clkbits)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1818 | } |
| 1819 | |
| 1820 | udelay(2); |
| 1821 | brcms_b_core_phy_clk(wlc_hw, ON); |
| 1822 | |
| 1823 | if (pih) |
| 1824 | wlc_phy_anacore(pih, ON); |
| 1825 | } |
| 1826 | |
| 1827 | /* switch to and initialize new band */ |
| 1828 | static void brcms_b_setband(struct brcms_hardware *wlc_hw, uint bandunit, |
| 1829 | u16 chanspec) { |
| 1830 | struct brcms_c_info *wlc = wlc_hw->wlc; |
| 1831 | u32 macintmask; |
| 1832 | |
| 1833 | /* Enable the d11 core before accessing it */ |
Arend van Spriel | a8779e4 | 2011-12-08 15:06:58 -0800 | [diff] [blame] | 1834 | if (!bcma_core_is_enabled(wlc_hw->d11core)) { |
| 1835 | bcma_core_enable(wlc_hw->d11core, 0); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1836 | brcms_c_mctrl_reset(wlc_hw); |
| 1837 | } |
| 1838 | |
| 1839 | macintmask = brcms_c_setband_inact(wlc, bandunit); |
| 1840 | |
| 1841 | if (!wlc_hw->up) |
| 1842 | return; |
| 1843 | |
| 1844 | brcms_b_core_phy_clk(wlc_hw, ON); |
| 1845 | |
| 1846 | /* band-specific initializations */ |
| 1847 | brcms_b_bsinit(wlc, chanspec); |
| 1848 | |
| 1849 | /* |
| 1850 | * If there are any pending software interrupt bits, |
| 1851 | * then replace these with a harmless nonzero value |
| 1852 | * so brcms_c_dpc() will re-enable interrupts when done. |
| 1853 | */ |
| 1854 | if (wlc->macintstatus) |
| 1855 | wlc->macintstatus = MI_DMAINT; |
| 1856 | |
| 1857 | /* restore macintmask */ |
| 1858 | brcms_intrsrestore(wlc->wl, macintmask); |
| 1859 | |
| 1860 | /* ucode should still be suspended.. */ |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 1861 | WARN_ON((bcma_read32(wlc_hw->d11core, D11REGOFFS(maccontrol)) & |
| 1862 | MCTL_EN_MAC) != 0); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1863 | } |
| 1864 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1865 | static bool brcms_c_isgoodchip(struct brcms_hardware *wlc_hw) |
| 1866 | { |
| 1867 | |
| 1868 | /* reject unsupported corerev */ |
| 1869 | if (!CONF_HAS(D11CONF, wlc_hw->corerev)) { |
| 1870 | wiphy_err(wlc_hw->wlc->wiphy, "unsupported core rev %d\n", |
| 1871 | wlc_hw->corerev); |
| 1872 | return false; |
| 1873 | } |
| 1874 | |
| 1875 | return true; |
| 1876 | } |
| 1877 | |
| 1878 | /* Validate some board info parameters */ |
| 1879 | static bool brcms_c_validboardtype(struct brcms_hardware *wlc_hw) |
| 1880 | { |
| 1881 | uint boardrev = wlc_hw->boardrev; |
| 1882 | |
| 1883 | /* 4 bits each for board type, major, minor, and tiny version */ |
| 1884 | uint brt = (boardrev & 0xf000) >> 12; |
| 1885 | uint b0 = (boardrev & 0xf00) >> 8; |
| 1886 | uint b1 = (boardrev & 0xf0) >> 4; |
| 1887 | uint b2 = boardrev & 0xf; |
| 1888 | |
| 1889 | /* voards from other vendors are always considered valid */ |
Arend van Spriel | b2ffec4 | 2011-12-08 15:06:45 -0800 | [diff] [blame] | 1890 | if (ai_get_boardvendor(wlc_hw->sih) != PCI_VENDOR_ID_BROADCOM) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1891 | return true; |
| 1892 | |
| 1893 | /* do some boardrev sanity checks when boardvendor is Broadcom */ |
| 1894 | if (boardrev == 0) |
| 1895 | return false; |
| 1896 | |
| 1897 | if (boardrev <= 0xff) |
| 1898 | return true; |
| 1899 | |
| 1900 | if ((brt > 2) || (brt == 0) || (b0 > 9) || (b0 == 0) || (b1 > 9) |
| 1901 | || (b2 > 9)) |
| 1902 | return false; |
| 1903 | |
| 1904 | return true; |
| 1905 | } |
| 1906 | |
Hauke Mehrtens | 898d3c3 | 2012-04-29 02:50:25 +0200 | [diff] [blame] | 1907 | static void brcms_c_get_macaddr(struct brcms_hardware *wlc_hw, u8 etheraddr[ETH_ALEN]) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1908 | { |
Hauke Mehrtens | 898d3c3 | 2012-04-29 02:50:25 +0200 | [diff] [blame] | 1909 | struct ssb_sprom *sprom = &wlc_hw->d11core->bus->sprom; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1910 | |
| 1911 | /* If macaddr exists, use it (Sromrev4, CIS, ...). */ |
Hauke Mehrtens | 898d3c3 | 2012-04-29 02:50:25 +0200 | [diff] [blame] | 1912 | if (!is_zero_ether_addr(sprom->il0mac)) { |
| 1913 | memcpy(etheraddr, sprom->il0mac, 6); |
| 1914 | return; |
| 1915 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1916 | |
| 1917 | if (wlc_hw->_nbands > 1) |
Hauke Mehrtens | 898d3c3 | 2012-04-29 02:50:25 +0200 | [diff] [blame] | 1918 | memcpy(etheraddr, sprom->et1mac, 6); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1919 | else |
Hauke Mehrtens | 898d3c3 | 2012-04-29 02:50:25 +0200 | [diff] [blame] | 1920 | memcpy(etheraddr, sprom->il0mac, 6); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1921 | } |
| 1922 | |
| 1923 | /* power both the pll and external oscillator on/off */ |
| 1924 | static void brcms_b_xtal(struct brcms_hardware *wlc_hw, bool want) |
| 1925 | { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 1926 | brcms_dbg_info(wlc_hw->d11core, "wl%d: want %d\n", wlc_hw->unit, want); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1927 | |
| 1928 | /* |
| 1929 | * dont power down if plldown is false or |
| 1930 | * we must poll hw radio disable |
| 1931 | */ |
| 1932 | if (!want && wlc_hw->pllreq) |
| 1933 | return; |
| 1934 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1935 | wlc_hw->sbclk = want; |
| 1936 | if (!wlc_hw->sbclk) { |
| 1937 | wlc_hw->clk = false; |
| 1938 | if (wlc_hw->band && wlc_hw->band->pi) |
| 1939 | wlc_phy_hw_clk_state_upd(wlc_hw->band->pi, false); |
| 1940 | } |
| 1941 | } |
| 1942 | |
| 1943 | /* |
| 1944 | * Return true if radio is disabled, otherwise false. |
| 1945 | * hw radio disable signal is an external pin, users activate it asynchronously |
| 1946 | * this function could be called when driver is down and w/o clock |
| 1947 | * it operates on different registers depending on corerev and boardflag. |
| 1948 | */ |
| 1949 | static bool brcms_b_radio_read_hwdisabled(struct brcms_hardware *wlc_hw) |
| 1950 | { |
| 1951 | bool v, clk, xtal; |
Arend van Spriel | a8779e4 | 2011-12-08 15:06:58 -0800 | [diff] [blame] | 1952 | u32 flags = 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1953 | |
| 1954 | xtal = wlc_hw->sbclk; |
| 1955 | if (!xtal) |
| 1956 | brcms_b_xtal(wlc_hw, ON); |
| 1957 | |
| 1958 | /* may need to take core out of reset first */ |
| 1959 | clk = wlc_hw->clk; |
| 1960 | if (!clk) { |
| 1961 | /* |
| 1962 | * mac no longer enables phyclk automatically when driver |
| 1963 | * accesses phyreg throughput mac. This can be skipped since |
| 1964 | * only mac reg is accessed below |
| 1965 | */ |
Hauke Mehrtens | 0d3b9dd | 2012-06-30 15:16:15 +0200 | [diff] [blame] | 1966 | if (D11REV_GE(wlc_hw->corerev, 18)) |
| 1967 | flags |= SICF_PCLKE; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1968 | |
| 1969 | /* |
Arend van Spriel | 3b758a6 | 2011-12-12 15:15:09 -0800 | [diff] [blame] | 1970 | * TODO: test suspend/resume |
| 1971 | * |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1972 | * AI chip doesn't restore bar0win2 on |
| 1973 | * hibernation/resume, need sw fixup |
| 1974 | */ |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 1975 | |
Arend van Spriel | a8779e4 | 2011-12-08 15:06:58 -0800 | [diff] [blame] | 1976 | bcma_core_enable(wlc_hw->d11core, flags); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1977 | brcms_c_mctrl_reset(wlc_hw); |
| 1978 | } |
| 1979 | |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 1980 | v = ((bcma_read32(wlc_hw->d11core, |
| 1981 | D11REGOFFS(phydebug)) & PDBG_RFD) != 0); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1982 | |
| 1983 | /* put core back into reset */ |
| 1984 | if (!clk) |
Arend van Spriel | a8779e4 | 2011-12-08 15:06:58 -0800 | [diff] [blame] | 1985 | bcma_core_disable(wlc_hw->d11core, 0); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1986 | |
| 1987 | if (!xtal) |
| 1988 | brcms_b_xtal(wlc_hw, OFF); |
| 1989 | |
| 1990 | return v; |
| 1991 | } |
| 1992 | |
| 1993 | static bool wlc_dma_rxreset(struct brcms_hardware *wlc_hw, uint fifo) |
| 1994 | { |
| 1995 | struct dma_pub *di = wlc_hw->di[fifo]; |
| 1996 | return dma_rxreset(di); |
| 1997 | } |
| 1998 | |
| 1999 | /* d11 core reset |
| 2000 | * ensure fask clock during reset |
| 2001 | * reset dma |
| 2002 | * reset d11(out of reset) |
| 2003 | * reset phy(out of reset) |
| 2004 | * clear software macintstatus for fresh new start |
| 2005 | * one testing hack wlc_hw->noreset will bypass the d11/phy reset |
| 2006 | */ |
| 2007 | void brcms_b_corereset(struct brcms_hardware *wlc_hw, u32 flags) |
| 2008 | { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2009 | uint i; |
| 2010 | bool fastclk; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2011 | |
| 2012 | if (flags == BRCMS_USE_COREFLAGS) |
| 2013 | flags = (wlc_hw->band->pi ? wlc_hw->band->core_flags : 0); |
| 2014 | |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 2015 | brcms_dbg_info(wlc_hw->d11core, "wl%d: core reset\n", wlc_hw->unit); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2016 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2017 | /* request FAST clock if not on */ |
| 2018 | fastclk = wlc_hw->forcefastclk; |
| 2019 | if (!fastclk) |
Hauke Mehrtens | 712e3c1 | 2012-04-29 02:50:35 +0200 | [diff] [blame] | 2020 | brcms_b_clkctl_clk(wlc_hw, BCMA_CLKMODE_FAST); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2021 | |
| 2022 | /* reset the dma engines except first time thru */ |
Arend van Spriel | a8779e4 | 2011-12-08 15:06:58 -0800 | [diff] [blame] | 2023 | if (bcma_core_is_enabled(wlc_hw->d11core)) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2024 | for (i = 0; i < NFIFO; i++) |
| 2025 | if ((wlc_hw->di[i]) && (!dma_txreset(wlc_hw->di[i]))) |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 2026 | brcms_err(wlc_hw->d11core, "wl%d: %s: " |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2027 | "dma_txreset[%d]: cannot stop dma\n", |
| 2028 | wlc_hw->unit, __func__, i); |
| 2029 | |
| 2030 | if ((wlc_hw->di[RX_FIFO]) |
| 2031 | && (!wlc_dma_rxreset(wlc_hw, RX_FIFO))) |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 2032 | brcms_err(wlc_hw->d11core, "wl%d: %s: dma_rxreset" |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2033 | "[%d]: cannot stop dma\n", |
| 2034 | wlc_hw->unit, __func__, RX_FIFO); |
| 2035 | } |
| 2036 | /* if noreset, just stop the psm and return */ |
| 2037 | if (wlc_hw->noreset) { |
| 2038 | wlc_hw->wlc->macintstatus = 0; /* skip wl_dpc after down */ |
| 2039 | brcms_b_mctrl(wlc_hw, MCTL_PSM_RUN | MCTL_EN_MAC, 0); |
| 2040 | return; |
| 2041 | } |
| 2042 | |
| 2043 | /* |
| 2044 | * mac no longer enables phyclk automatically when driver accesses |
| 2045 | * phyreg throughput mac, AND phy_reset is skipped at early stage when |
| 2046 | * band->pi is invalid. need to enable PHY CLK |
| 2047 | */ |
Hauke Mehrtens | 0d3b9dd | 2012-06-30 15:16:15 +0200 | [diff] [blame] | 2048 | if (D11REV_GE(wlc_hw->corerev, 18)) |
| 2049 | flags |= SICF_PCLKE; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2050 | |
| 2051 | /* |
| 2052 | * reset the core |
| 2053 | * In chips with PMU, the fastclk request goes through d11 core |
| 2054 | * reg 0x1e0, which is cleared by the core_reset. have to re-request it. |
| 2055 | * |
| 2056 | * This adds some delay and we can optimize it by also requesting |
| 2057 | * fastclk through chipcommon during this period if necessary. But |
| 2058 | * that has to work coordinate with other driver like mips/arm since |
| 2059 | * they may touch chipcommon as well. |
| 2060 | */ |
| 2061 | wlc_hw->clk = false; |
Arend van Spriel | a8779e4 | 2011-12-08 15:06:58 -0800 | [diff] [blame] | 2062 | bcma_core_enable(wlc_hw->d11core, flags); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2063 | wlc_hw->clk = true; |
| 2064 | if (wlc_hw->band && wlc_hw->band->pi) |
| 2065 | wlc_phy_hw_clk_state_upd(wlc_hw->band->pi, true); |
| 2066 | |
| 2067 | brcms_c_mctrl_reset(wlc_hw); |
| 2068 | |
Arend van Spriel | b2ffec4 | 2011-12-08 15:06:45 -0800 | [diff] [blame] | 2069 | if (ai_get_cccaps(wlc_hw->sih) & CC_CAP_PMU) |
Hauke Mehrtens | 712e3c1 | 2012-04-29 02:50:35 +0200 | [diff] [blame] | 2070 | brcms_b_clkctl_clk(wlc_hw, BCMA_CLKMODE_FAST); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2071 | |
| 2072 | brcms_b_phy_reset(wlc_hw); |
| 2073 | |
| 2074 | /* turn on PHY_PLL */ |
| 2075 | brcms_b_core_phypll_ctl(wlc_hw, true); |
| 2076 | |
| 2077 | /* clear sw intstatus */ |
| 2078 | wlc_hw->wlc->macintstatus = 0; |
| 2079 | |
| 2080 | /* restore the clk setting */ |
| 2081 | if (!fastclk) |
Hauke Mehrtens | 712e3c1 | 2012-04-29 02:50:35 +0200 | [diff] [blame] | 2082 | brcms_b_clkctl_clk(wlc_hw, BCMA_CLKMODE_DYNAMIC); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2083 | } |
| 2084 | |
| 2085 | /* txfifo sizes needs to be modified(increased) since the newer cores |
| 2086 | * have more memory. |
| 2087 | */ |
| 2088 | static void brcms_b_corerev_fifofixup(struct brcms_hardware *wlc_hw) |
| 2089 | { |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2090 | struct bcma_device *core = wlc_hw->d11core; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2091 | u16 fifo_nu; |
| 2092 | u16 txfifo_startblk = TXFIFO_START_BLK, txfifo_endblk; |
| 2093 | u16 txfifo_def, txfifo_def1; |
| 2094 | u16 txfifo_cmd; |
| 2095 | |
| 2096 | /* tx fifos start at TXFIFO_START_BLK from the Base address */ |
| 2097 | txfifo_startblk = TXFIFO_START_BLK; |
| 2098 | |
| 2099 | /* sequence of operations: reset fifo, set fifo size, reset fifo */ |
| 2100 | for (fifo_nu = 0; fifo_nu < NFIFO; fifo_nu++) { |
| 2101 | |
| 2102 | txfifo_endblk = txfifo_startblk + wlc_hw->xmtfifo_sz[fifo_nu]; |
| 2103 | txfifo_def = (txfifo_startblk & 0xff) | |
| 2104 | (((txfifo_endblk - 1) & 0xff) << TXFIFO_FIFOTOP_SHIFT); |
| 2105 | txfifo_def1 = ((txfifo_startblk >> 8) & 0x1) | |
| 2106 | ((((txfifo_endblk - |
| 2107 | 1) >> 8) & 0x1) << TXFIFO_FIFOTOP_SHIFT); |
| 2108 | txfifo_cmd = |
| 2109 | TXFIFOCMD_RESET_MASK | (fifo_nu << TXFIFOCMD_FIFOSEL_SHIFT); |
| 2110 | |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2111 | bcma_write16(core, D11REGOFFS(xmtfifocmd), txfifo_cmd); |
| 2112 | bcma_write16(core, D11REGOFFS(xmtfifodef), txfifo_def); |
| 2113 | bcma_write16(core, D11REGOFFS(xmtfifodef1), txfifo_def1); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2114 | |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2115 | bcma_write16(core, D11REGOFFS(xmtfifocmd), txfifo_cmd); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2116 | |
| 2117 | txfifo_startblk += wlc_hw->xmtfifo_sz[fifo_nu]; |
| 2118 | } |
| 2119 | /* |
| 2120 | * need to propagate to shm location to be in sync since ucode/hw won't |
| 2121 | * do this |
| 2122 | */ |
| 2123 | brcms_b_write_shm(wlc_hw, M_FIFOSIZE0, |
| 2124 | wlc_hw->xmtfifo_sz[TX_AC_BE_FIFO]); |
| 2125 | brcms_b_write_shm(wlc_hw, M_FIFOSIZE1, |
| 2126 | wlc_hw->xmtfifo_sz[TX_AC_VI_FIFO]); |
| 2127 | brcms_b_write_shm(wlc_hw, M_FIFOSIZE2, |
| 2128 | ((wlc_hw->xmtfifo_sz[TX_AC_VO_FIFO] << 8) | wlc_hw-> |
| 2129 | xmtfifo_sz[TX_AC_BK_FIFO])); |
| 2130 | brcms_b_write_shm(wlc_hw, M_FIFOSIZE3, |
| 2131 | ((wlc_hw->xmtfifo_sz[TX_ATIM_FIFO] << 8) | wlc_hw-> |
| 2132 | xmtfifo_sz[TX_BCMC_FIFO])); |
| 2133 | } |
| 2134 | |
| 2135 | /* This function is used for changing the tsf frac register |
| 2136 | * If spur avoidance mode is off, the mac freq will be 80/120/160Mhz |
| 2137 | * If spur avoidance mode is on1, the mac freq will be 82/123/164Mhz |
| 2138 | * If spur avoidance mode is on2, the mac freq will be 84/126/168Mhz |
| 2139 | * HTPHY Formula is 2^26/freq(MHz) e.g. |
| 2140 | * For spuron2 - 126MHz -> 2^26/126 = 532610.0 |
| 2141 | * - 532610 = 0x82082 => tsf_clk_frac_h = 0x8, tsf_clk_frac_l = 0x2082 |
| 2142 | * For spuron: 123MHz -> 2^26/123 = 545600.5 |
| 2143 | * - 545601 = 0x85341 => tsf_clk_frac_h = 0x8, tsf_clk_frac_l = 0x5341 |
| 2144 | * For spur off: 120MHz -> 2^26/120 = 559240.5 |
| 2145 | * - 559241 = 0x88889 => tsf_clk_frac_h = 0x8, tsf_clk_frac_l = 0x8889 |
| 2146 | */ |
| 2147 | |
| 2148 | void brcms_b_switch_macfreq(struct brcms_hardware *wlc_hw, u8 spurmode) |
| 2149 | { |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2150 | struct bcma_device *core = wlc_hw->d11core; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2151 | |
Hauke Mehrtens | 1ef1a57 | 2012-06-30 15:16:13 +0200 | [diff] [blame] | 2152 | if ((ai_get_chip_id(wlc_hw->sih) == BCMA_CHIP_ID_BCM43224) || |
| 2153 | (ai_get_chip_id(wlc_hw->sih) == BCMA_CHIP_ID_BCM43225)) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2154 | if (spurmode == WL_SPURAVOID_ON2) { /* 126Mhz */ |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2155 | bcma_write16(core, D11REGOFFS(tsf_clk_frac_l), 0x2082); |
| 2156 | bcma_write16(core, D11REGOFFS(tsf_clk_frac_h), 0x8); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2157 | } else if (spurmode == WL_SPURAVOID_ON1) { /* 123Mhz */ |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2158 | bcma_write16(core, D11REGOFFS(tsf_clk_frac_l), 0x5341); |
| 2159 | bcma_write16(core, D11REGOFFS(tsf_clk_frac_h), 0x8); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2160 | } else { /* 120Mhz */ |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2161 | bcma_write16(core, D11REGOFFS(tsf_clk_frac_l), 0x8889); |
| 2162 | bcma_write16(core, D11REGOFFS(tsf_clk_frac_h), 0x8); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2163 | } |
| 2164 | } else if (BRCMS_ISLCNPHY(wlc_hw->band)) { |
| 2165 | if (spurmode == WL_SPURAVOID_ON1) { /* 82Mhz */ |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2166 | bcma_write16(core, D11REGOFFS(tsf_clk_frac_l), 0x7CE0); |
| 2167 | bcma_write16(core, D11REGOFFS(tsf_clk_frac_h), 0xC); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2168 | } else { /* 80Mhz */ |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2169 | bcma_write16(core, D11REGOFFS(tsf_clk_frac_l), 0xCCCD); |
| 2170 | bcma_write16(core, D11REGOFFS(tsf_clk_frac_h), 0xC); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2171 | } |
| 2172 | } |
| 2173 | } |
| 2174 | |
| 2175 | /* Initialize GPIOs that are controlled by D11 core */ |
| 2176 | static void brcms_c_gpio_init(struct brcms_c_info *wlc) |
| 2177 | { |
| 2178 | struct brcms_hardware *wlc_hw = wlc->hw; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2179 | u32 gc, gm; |
| 2180 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2181 | /* use GPIO select 0 to get all gpio signals from the gpio out reg */ |
| 2182 | brcms_b_mctrl(wlc_hw, MCTL_GPOUT_SEL_MASK, 0); |
| 2183 | |
| 2184 | /* |
| 2185 | * Common GPIO setup: |
| 2186 | * G0 = LED 0 = WLAN Activity |
| 2187 | * G1 = LED 1 = WLAN 2.4 GHz Radio State |
| 2188 | * G2 = LED 2 = WLAN 5 GHz Radio State |
| 2189 | * G4 = radio disable input (HI enabled, LO disabled) |
| 2190 | */ |
| 2191 | |
| 2192 | gc = gm = 0; |
| 2193 | |
| 2194 | /* Allocate GPIOs for mimo antenna diversity feature */ |
| 2195 | if (wlc_hw->antsel_type == ANTSEL_2x3) { |
| 2196 | /* Enable antenna diversity, use 2x3 mode */ |
| 2197 | brcms_b_mhf(wlc_hw, MHF3, MHF3_ANTSEL_EN, |
| 2198 | MHF3_ANTSEL_EN, BRCM_BAND_ALL); |
| 2199 | brcms_b_mhf(wlc_hw, MHF3, MHF3_ANTSEL_MODE, |
| 2200 | MHF3_ANTSEL_MODE, BRCM_BAND_ALL); |
| 2201 | |
| 2202 | /* init superswitch control */ |
| 2203 | wlc_phy_antsel_init(wlc_hw->band->pi, false); |
| 2204 | |
| 2205 | } else if (wlc_hw->antsel_type == ANTSEL_2x4) { |
| 2206 | gm |= gc |= (BOARD_GPIO_12 | BOARD_GPIO_13); |
| 2207 | /* |
| 2208 | * The board itself is powered by these GPIOs |
| 2209 | * (when not sending pattern) so set them high |
| 2210 | */ |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2211 | bcma_set16(wlc_hw->d11core, D11REGOFFS(psm_gpio_oe), |
| 2212 | (BOARD_GPIO_12 | BOARD_GPIO_13)); |
| 2213 | bcma_set16(wlc_hw->d11core, D11REGOFFS(psm_gpio_out), |
| 2214 | (BOARD_GPIO_12 | BOARD_GPIO_13)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2215 | |
| 2216 | /* Enable antenna diversity, use 2x4 mode */ |
| 2217 | brcms_b_mhf(wlc_hw, MHF3, MHF3_ANTSEL_EN, |
| 2218 | MHF3_ANTSEL_EN, BRCM_BAND_ALL); |
| 2219 | brcms_b_mhf(wlc_hw, MHF3, MHF3_ANTSEL_MODE, 0, |
| 2220 | BRCM_BAND_ALL); |
| 2221 | |
| 2222 | /* Configure the desired clock to be 4Mhz */ |
| 2223 | brcms_b_write_shm(wlc_hw, M_ANTSEL_CLKDIV, |
| 2224 | ANTSEL_CLKDIV_4MHZ); |
| 2225 | } |
| 2226 | |
| 2227 | /* |
| 2228 | * gpio 9 controls the PA. ucode is responsible |
| 2229 | * for wiggling out and oe |
| 2230 | */ |
| 2231 | if (wlc_hw->boardflags & BFL_PACTRL) |
| 2232 | gm |= gc |= BOARD_GPIO_PACTRL; |
| 2233 | |
| 2234 | /* apply to gpiocontrol register */ |
Hauke Mehrtens | fa0b823 | 2012-04-29 02:50:34 +0200 | [diff] [blame] | 2235 | bcma_chipco_gpio_control(&wlc_hw->d11core->bus->drv_cc, gm, gc); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2236 | } |
| 2237 | |
| 2238 | static void brcms_ucode_write(struct brcms_hardware *wlc_hw, |
| 2239 | const __le32 ucode[], const size_t nbytes) |
| 2240 | { |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2241 | struct bcma_device *core = wlc_hw->d11core; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2242 | uint i; |
| 2243 | uint count; |
| 2244 | |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 2245 | brcms_dbg_info(wlc_hw->d11core, "wl%d\n", wlc_hw->unit); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2246 | |
| 2247 | count = (nbytes / sizeof(u32)); |
| 2248 | |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2249 | bcma_write32(core, D11REGOFFS(objaddr), |
| 2250 | OBJADDR_AUTO_INC | OBJADDR_UCM_SEL); |
| 2251 | (void)bcma_read32(core, D11REGOFFS(objaddr)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2252 | for (i = 0; i < count; i++) |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2253 | bcma_write32(core, D11REGOFFS(objdata), le32_to_cpu(ucode[i])); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2254 | |
| 2255 | } |
| 2256 | |
| 2257 | static void brcms_ucode_download(struct brcms_hardware *wlc_hw) |
| 2258 | { |
| 2259 | struct brcms_c_info *wlc; |
| 2260 | struct brcms_ucode *ucode = &wlc_hw->wlc->wl->ucode; |
| 2261 | |
| 2262 | wlc = wlc_hw->wlc; |
| 2263 | |
| 2264 | if (wlc_hw->ucode_loaded) |
| 2265 | return; |
| 2266 | |
Hauke Mehrtens | 6f80f01 | 2012-12-07 00:35:53 +0100 | [diff] [blame] | 2267 | if (D11REV_IS(wlc_hw->corerev, 17) || D11REV_IS(wlc_hw->corerev, 23)) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2268 | if (BRCMS_ISNPHY(wlc_hw->band)) { |
| 2269 | brcms_ucode_write(wlc_hw, ucode->bcm43xx_16_mimo, |
| 2270 | ucode->bcm43xx_16_mimosz); |
| 2271 | wlc_hw->ucode_loaded = true; |
| 2272 | } else |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 2273 | brcms_err(wlc_hw->d11core, |
| 2274 | "%s: wl%d: unsupported phy in corerev %d\n", |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2275 | __func__, wlc_hw->unit, wlc_hw->corerev); |
| 2276 | } else if (D11REV_IS(wlc_hw->corerev, 24)) { |
| 2277 | if (BRCMS_ISLCNPHY(wlc_hw->band)) { |
| 2278 | brcms_ucode_write(wlc_hw, ucode->bcm43xx_24_lcn, |
| 2279 | ucode->bcm43xx_24_lcnsz); |
| 2280 | wlc_hw->ucode_loaded = true; |
| 2281 | } else { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 2282 | brcms_err(wlc_hw->d11core, |
| 2283 | "%s: wl%d: unsupported phy in corerev %d\n", |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2284 | __func__, wlc_hw->unit, wlc_hw->corerev); |
| 2285 | } |
| 2286 | } |
| 2287 | } |
| 2288 | |
| 2289 | void brcms_b_txant_set(struct brcms_hardware *wlc_hw, u16 phytxant) |
| 2290 | { |
| 2291 | /* update sw state */ |
| 2292 | wlc_hw->bmac_phytxant = phytxant; |
| 2293 | |
| 2294 | /* push to ucode if up */ |
| 2295 | if (!wlc_hw->up) |
| 2296 | return; |
| 2297 | brcms_c_ucode_txant_set(wlc_hw); |
| 2298 | |
| 2299 | } |
| 2300 | |
| 2301 | u16 brcms_b_get_txant(struct brcms_hardware *wlc_hw) |
| 2302 | { |
| 2303 | return (u16) wlc_hw->wlc->stf->txant; |
| 2304 | } |
| 2305 | |
| 2306 | void brcms_b_antsel_type_set(struct brcms_hardware *wlc_hw, u8 antsel_type) |
| 2307 | { |
| 2308 | wlc_hw->antsel_type = antsel_type; |
| 2309 | |
| 2310 | /* Update the antsel type for phy module to use */ |
| 2311 | wlc_phy_antsel_type_set(wlc_hw->band->pi, antsel_type); |
| 2312 | } |
| 2313 | |
| 2314 | static void brcms_b_fifoerrors(struct brcms_hardware *wlc_hw) |
| 2315 | { |
| 2316 | bool fatal = false; |
| 2317 | uint unit; |
| 2318 | uint intstatus, idx; |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2319 | struct bcma_device *core = wlc_hw->d11core; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2320 | |
| 2321 | unit = wlc_hw->unit; |
| 2322 | |
| 2323 | for (idx = 0; idx < NFIFO; idx++) { |
| 2324 | /* read intstatus register and ignore any non-error bits */ |
| 2325 | intstatus = |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2326 | bcma_read32(core, |
| 2327 | D11REGOFFS(intctrlregs[idx].intstatus)) & |
| 2328 | I_ERRORS; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2329 | if (!intstatus) |
| 2330 | continue; |
| 2331 | |
Seth Forshee | 229a41d | 2012-11-15 08:08:06 -0600 | [diff] [blame] | 2332 | brcms_dbg_int(core, "wl%d: intstatus%d 0x%x\n", |
| 2333 | unit, idx, intstatus); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2334 | |
| 2335 | if (intstatus & I_RO) { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 2336 | brcms_err(core, "wl%d: fifo %d: receive fifo " |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2337 | "overflow\n", unit, idx); |
| 2338 | fatal = true; |
| 2339 | } |
| 2340 | |
| 2341 | if (intstatus & I_PC) { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 2342 | brcms_err(core, "wl%d: fifo %d: descriptor error\n", |
| 2343 | unit, idx); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2344 | fatal = true; |
| 2345 | } |
| 2346 | |
| 2347 | if (intstatus & I_PD) { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 2348 | brcms_err(core, "wl%d: fifo %d: data error\n", unit, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2349 | idx); |
| 2350 | fatal = true; |
| 2351 | } |
| 2352 | |
| 2353 | if (intstatus & I_DE) { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 2354 | brcms_err(core, "wl%d: fifo %d: descriptor protocol " |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2355 | "error\n", unit, idx); |
| 2356 | fatal = true; |
| 2357 | } |
| 2358 | |
| 2359 | if (intstatus & I_RU) |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 2360 | brcms_err(core, "wl%d: fifo %d: receive descriptor " |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2361 | "underflow\n", idx, unit); |
| 2362 | |
| 2363 | if (intstatus & I_XU) { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 2364 | brcms_err(core, "wl%d: fifo %d: transmit fifo " |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2365 | "underflow\n", idx, unit); |
| 2366 | fatal = true; |
| 2367 | } |
| 2368 | |
| 2369 | if (fatal) { |
Roland Vossen | c261bdf | 2011-10-18 14:03:04 +0200 | [diff] [blame] | 2370 | brcms_fatal_error(wlc_hw->wlc->wl); /* big hammer */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2371 | break; |
| 2372 | } else |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2373 | bcma_write32(core, |
| 2374 | D11REGOFFS(intctrlregs[idx].intstatus), |
| 2375 | intstatus); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2376 | } |
| 2377 | } |
| 2378 | |
| 2379 | void brcms_c_intrson(struct brcms_c_info *wlc) |
| 2380 | { |
| 2381 | struct brcms_hardware *wlc_hw = wlc->hw; |
| 2382 | wlc->macintmask = wlc->defmacintmask; |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2383 | bcma_write32(wlc_hw->d11core, D11REGOFFS(macintmask), wlc->macintmask); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2384 | } |
| 2385 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2386 | u32 brcms_c_intrsoff(struct brcms_c_info *wlc) |
| 2387 | { |
| 2388 | struct brcms_hardware *wlc_hw = wlc->hw; |
| 2389 | u32 macintmask; |
| 2390 | |
| 2391 | if (!wlc_hw->clk) |
| 2392 | return 0; |
| 2393 | |
| 2394 | macintmask = wlc->macintmask; /* isr can still happen */ |
| 2395 | |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2396 | bcma_write32(wlc_hw->d11core, D11REGOFFS(macintmask), 0); |
| 2397 | (void)bcma_read32(wlc_hw->d11core, D11REGOFFS(macintmask)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2398 | udelay(1); /* ensure int line is no longer driven */ |
| 2399 | wlc->macintmask = 0; |
| 2400 | |
| 2401 | /* return previous macintmask; resolve race between us and our isr */ |
| 2402 | return wlc->macintstatus ? 0 : macintmask; |
| 2403 | } |
| 2404 | |
| 2405 | void brcms_c_intrsrestore(struct brcms_c_info *wlc, u32 macintmask) |
| 2406 | { |
| 2407 | struct brcms_hardware *wlc_hw = wlc->hw; |
| 2408 | if (!wlc_hw->clk) |
| 2409 | return; |
| 2410 | |
| 2411 | wlc->macintmask = macintmask; |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2412 | bcma_write32(wlc_hw->d11core, D11REGOFFS(macintmask), wlc->macintmask); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2413 | } |
| 2414 | |
Roland Vossen | dc46012 | 2011-10-21 16:16:28 +0200 | [diff] [blame] | 2415 | /* assumes that the d11 MAC is enabled */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2416 | static void brcms_b_tx_fifo_suspend(struct brcms_hardware *wlc_hw, |
| 2417 | uint tx_fifo) |
| 2418 | { |
| 2419 | u8 fifo = 1 << tx_fifo; |
| 2420 | |
| 2421 | /* Two clients of this code, 11h Quiet period and scanning. */ |
| 2422 | |
| 2423 | /* only suspend if not already suspended */ |
| 2424 | if ((wlc_hw->suspended_fifos & fifo) == fifo) |
| 2425 | return; |
| 2426 | |
| 2427 | /* force the core awake only if not already */ |
| 2428 | if (wlc_hw->suspended_fifos == 0) |
| 2429 | brcms_c_ucode_wake_override_set(wlc_hw, |
| 2430 | BRCMS_WAKE_OVERRIDE_TXFIFO); |
| 2431 | |
| 2432 | wlc_hw->suspended_fifos |= fifo; |
| 2433 | |
| 2434 | if (wlc_hw->di[tx_fifo]) { |
| 2435 | /* |
| 2436 | * Suspending AMPDU transmissions in the middle can cause |
| 2437 | * underflow which may result in mismatch between ucode and |
| 2438 | * driver so suspend the mac before suspending the FIFO |
| 2439 | */ |
| 2440 | if (BRCMS_PHY_11N_CAP(wlc_hw->band)) |
| 2441 | brcms_c_suspend_mac_and_wait(wlc_hw->wlc); |
| 2442 | |
| 2443 | dma_txsuspend(wlc_hw->di[tx_fifo]); |
| 2444 | |
| 2445 | if (BRCMS_PHY_11N_CAP(wlc_hw->band)) |
| 2446 | brcms_c_enable_mac(wlc_hw->wlc); |
| 2447 | } |
| 2448 | } |
| 2449 | |
| 2450 | static void brcms_b_tx_fifo_resume(struct brcms_hardware *wlc_hw, |
| 2451 | uint tx_fifo) |
| 2452 | { |
| 2453 | /* BMAC_NOTE: BRCMS_TX_FIFO_ENAB is done in brcms_c_dpc() for DMA case |
| 2454 | * but need to be done here for PIO otherwise the watchdog will catch |
| 2455 | * the inconsistency and fire |
| 2456 | */ |
| 2457 | /* Two clients of this code, 11h Quiet period and scanning. */ |
| 2458 | if (wlc_hw->di[tx_fifo]) |
| 2459 | dma_txresume(wlc_hw->di[tx_fifo]); |
| 2460 | |
| 2461 | /* allow core to sleep again */ |
| 2462 | if (wlc_hw->suspended_fifos == 0) |
| 2463 | return; |
| 2464 | else { |
| 2465 | wlc_hw->suspended_fifos &= ~(1 << tx_fifo); |
| 2466 | if (wlc_hw->suspended_fifos == 0) |
| 2467 | brcms_c_ucode_wake_override_clear(wlc_hw, |
| 2468 | BRCMS_WAKE_OVERRIDE_TXFIFO); |
| 2469 | } |
| 2470 | } |
| 2471 | |
Roland Vossen | a8bc491 | 2011-10-21 16:16:25 +0200 | [diff] [blame] | 2472 | /* precondition: requires the mac core to be enabled */ |
Roland Vossen | c6c4489 | 2011-10-21 16:16:26 +0200 | [diff] [blame] | 2473 | static void brcms_b_mute(struct brcms_hardware *wlc_hw, bool mute_tx) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2474 | { |
| 2475 | static const u8 null_ether_addr[ETH_ALEN] = {0, 0, 0, 0, 0, 0}; |
Arend van Spriel | b180b10 | 2013-01-02 15:22:36 +0100 | [diff] [blame^] | 2476 | u8 *ethaddr = wlc_hw->wlc->pub->cur_etheraddr; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2477 | |
Roland Vossen | c6c4489 | 2011-10-21 16:16:26 +0200 | [diff] [blame] | 2478 | if (mute_tx) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2479 | /* suspend tx fifos */ |
| 2480 | brcms_b_tx_fifo_suspend(wlc_hw, TX_DATA_FIFO); |
| 2481 | brcms_b_tx_fifo_suspend(wlc_hw, TX_CTL_FIFO); |
| 2482 | brcms_b_tx_fifo_suspend(wlc_hw, TX_AC_BK_FIFO); |
| 2483 | brcms_b_tx_fifo_suspend(wlc_hw, TX_AC_VI_FIFO); |
| 2484 | |
| 2485 | /* zero the address match register so we do not send ACKs */ |
Arend van Spriel | b180b10 | 2013-01-02 15:22:36 +0100 | [diff] [blame^] | 2486 | brcms_b_set_addrmatch(wlc_hw, RCM_MAC_OFFSET, null_ether_addr); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2487 | } else { |
| 2488 | /* resume tx fifos */ |
| 2489 | brcms_b_tx_fifo_resume(wlc_hw, TX_DATA_FIFO); |
| 2490 | brcms_b_tx_fifo_resume(wlc_hw, TX_CTL_FIFO); |
| 2491 | brcms_b_tx_fifo_resume(wlc_hw, TX_AC_BK_FIFO); |
| 2492 | brcms_b_tx_fifo_resume(wlc_hw, TX_AC_VI_FIFO); |
| 2493 | |
| 2494 | /* Restore address */ |
Arend van Spriel | b180b10 | 2013-01-02 15:22:36 +0100 | [diff] [blame^] | 2495 | brcms_b_set_addrmatch(wlc_hw, RCM_MAC_OFFSET, ethaddr); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2496 | } |
| 2497 | |
Roland Vossen | c6c4489 | 2011-10-21 16:16:26 +0200 | [diff] [blame] | 2498 | wlc_phy_mute_upd(wlc_hw->band->pi, mute_tx, 0); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2499 | |
Roland Vossen | c6c4489 | 2011-10-21 16:16:26 +0200 | [diff] [blame] | 2500 | if (mute_tx) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2501 | brcms_c_ucode_mute_override_set(wlc_hw); |
| 2502 | else |
| 2503 | brcms_c_ucode_mute_override_clear(wlc_hw); |
| 2504 | } |
| 2505 | |
Roland Vossen | dc46012 | 2011-10-21 16:16:28 +0200 | [diff] [blame] | 2506 | void |
| 2507 | brcms_c_mute(struct brcms_c_info *wlc, bool mute_tx) |
| 2508 | { |
| 2509 | brcms_b_mute(wlc->hw, mute_tx); |
| 2510 | } |
| 2511 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2512 | /* |
| 2513 | * Read and clear macintmask and macintstatus and intstatus registers. |
| 2514 | * This routine should be called with interrupts off |
| 2515 | * Return: |
| 2516 | * -1 if brcms_deviceremoved(wlc) evaluates to true; |
| 2517 | * 0 if the interrupt is not for us, or we are in some special cases; |
| 2518 | * device interrupt status bits otherwise. |
| 2519 | */ |
| 2520 | static inline u32 wlc_intstatus(struct brcms_c_info *wlc, bool in_isr) |
| 2521 | { |
| 2522 | struct brcms_hardware *wlc_hw = wlc->hw; |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2523 | struct bcma_device *core = wlc_hw->d11core; |
Seth Forshee | e3c0d8a | 2012-11-15 08:08:10 -0600 | [diff] [blame] | 2524 | u32 macintstatus, mask; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2525 | |
| 2526 | /* macintstatus includes a DMA interrupt summary bit */ |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2527 | macintstatus = bcma_read32(core, D11REGOFFS(macintstatus)); |
Seth Forshee | e3c0d8a | 2012-11-15 08:08:10 -0600 | [diff] [blame] | 2528 | mask = in_isr ? wlc->macintmask : wlc->defmacintmask; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2529 | |
Seth Forshee | e3c0d8a | 2012-11-15 08:08:10 -0600 | [diff] [blame] | 2530 | trace_brcms_macintstatus(&core->dev, in_isr, macintstatus, mask); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2531 | |
| 2532 | /* detect cardbus removed, in power down(suspend) and in reset */ |
| 2533 | if (brcms_deviceremoved(wlc)) |
| 2534 | return -1; |
| 2535 | |
| 2536 | /* brcms_deviceremoved() succeeds even when the core is still resetting, |
| 2537 | * handle that case here. |
| 2538 | */ |
| 2539 | if (macintstatus == 0xffffffff) |
| 2540 | return 0; |
| 2541 | |
| 2542 | /* defer unsolicited interrupts */ |
Seth Forshee | e3c0d8a | 2012-11-15 08:08:10 -0600 | [diff] [blame] | 2543 | macintstatus &= mask; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2544 | |
| 2545 | /* if not for us */ |
| 2546 | if (macintstatus == 0) |
| 2547 | return 0; |
| 2548 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2549 | /* turn off the interrupts */ |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2550 | bcma_write32(core, D11REGOFFS(macintmask), 0); |
| 2551 | (void)bcma_read32(core, D11REGOFFS(macintmask)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2552 | wlc->macintmask = 0; |
| 2553 | |
| 2554 | /* clear device interrupts */ |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2555 | bcma_write32(core, D11REGOFFS(macintstatus), macintstatus); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2556 | |
| 2557 | /* MI_DMAINT is indication of non-zero intstatus */ |
| 2558 | if (macintstatus & MI_DMAINT) |
| 2559 | /* |
| 2560 | * only fifo interrupt enabled is I_RI in |
| 2561 | * RX_FIFO. If MI_DMAINT is set, assume it |
| 2562 | * is set and clear the interrupt. |
| 2563 | */ |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2564 | bcma_write32(core, D11REGOFFS(intctrlregs[RX_FIFO].intstatus), |
| 2565 | DEF_RXINTMASK); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2566 | |
| 2567 | return macintstatus; |
| 2568 | } |
| 2569 | |
| 2570 | /* Update wlc->macintstatus and wlc->intstatus[]. */ |
| 2571 | /* Return true if they are updated successfully. false otherwise */ |
| 2572 | bool brcms_c_intrsupd(struct brcms_c_info *wlc) |
| 2573 | { |
| 2574 | u32 macintstatus; |
| 2575 | |
| 2576 | /* read and clear macintstatus and intstatus registers */ |
| 2577 | macintstatus = wlc_intstatus(wlc, false); |
| 2578 | |
| 2579 | /* device is removed */ |
| 2580 | if (macintstatus == 0xffffffff) |
| 2581 | return false; |
| 2582 | |
| 2583 | /* update interrupt status in software */ |
| 2584 | wlc->macintstatus |= macintstatus; |
| 2585 | |
| 2586 | return true; |
| 2587 | } |
| 2588 | |
| 2589 | /* |
| 2590 | * First-level interrupt processing. |
Piotr Haber | 94d9902 | 2012-11-28 21:44:06 +0100 | [diff] [blame] | 2591 | * Return true if this was our interrupt |
| 2592 | * and if further brcms_c_dpc() processing is required, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2593 | * false otherwise. |
| 2594 | */ |
Piotr Haber | 94d9902 | 2012-11-28 21:44:06 +0100 | [diff] [blame] | 2595 | bool brcms_c_isr(struct brcms_c_info *wlc) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2596 | { |
| 2597 | struct brcms_hardware *wlc_hw = wlc->hw; |
| 2598 | u32 macintstatus; |
| 2599 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2600 | if (!wlc_hw->up || !wlc->macintmask) |
| 2601 | return false; |
| 2602 | |
| 2603 | /* read and clear macintstatus and intstatus registers */ |
| 2604 | macintstatus = wlc_intstatus(wlc, true); |
| 2605 | |
Piotr Haber | 94d9902 | 2012-11-28 21:44:06 +0100 | [diff] [blame] | 2606 | if (macintstatus == 0xffffffff) { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 2607 | brcms_err(wlc_hw->d11core, |
| 2608 | "DEVICEREMOVED detected in the ISR code path\n"); |
Piotr Haber | 94d9902 | 2012-11-28 21:44:06 +0100 | [diff] [blame] | 2609 | return false; |
| 2610 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2611 | |
| 2612 | /* it is not for us */ |
| 2613 | if (macintstatus == 0) |
| 2614 | return false; |
| 2615 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2616 | /* save interrupt status bits */ |
| 2617 | wlc->macintstatus = macintstatus; |
| 2618 | |
| 2619 | return true; |
| 2620 | |
| 2621 | } |
| 2622 | |
| 2623 | void brcms_c_suspend_mac_and_wait(struct brcms_c_info *wlc) |
| 2624 | { |
| 2625 | struct brcms_hardware *wlc_hw = wlc->hw; |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2626 | struct bcma_device *core = wlc_hw->d11core; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2627 | u32 mc, mi; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2628 | |
Seth Forshee | 913911f | 2012-11-15 08:08:04 -0600 | [diff] [blame] | 2629 | brcms_dbg_mac80211(core, "wl%d: bandunit %d\n", wlc_hw->unit, |
| 2630 | wlc_hw->band->bandunit); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2631 | |
| 2632 | /* |
| 2633 | * Track overlapping suspend requests |
| 2634 | */ |
| 2635 | wlc_hw->mac_suspend_depth++; |
| 2636 | if (wlc_hw->mac_suspend_depth > 1) |
| 2637 | return; |
| 2638 | |
| 2639 | /* force the core awake */ |
| 2640 | brcms_c_ucode_wake_override_set(wlc_hw, BRCMS_WAKE_OVERRIDE_MACSUSPEND); |
| 2641 | |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2642 | mc = bcma_read32(core, D11REGOFFS(maccontrol)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2643 | |
| 2644 | if (mc == 0xffffffff) { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 2645 | brcms_err(core, "wl%d: %s: dead chip\n", wlc_hw->unit, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2646 | __func__); |
| 2647 | brcms_down(wlc->wl); |
| 2648 | return; |
| 2649 | } |
| 2650 | WARN_ON(mc & MCTL_PSM_JMP_0); |
| 2651 | WARN_ON(!(mc & MCTL_PSM_RUN)); |
| 2652 | WARN_ON(!(mc & MCTL_EN_MAC)); |
| 2653 | |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2654 | mi = bcma_read32(core, D11REGOFFS(macintstatus)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2655 | if (mi == 0xffffffff) { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 2656 | brcms_err(core, "wl%d: %s: dead chip\n", wlc_hw->unit, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2657 | __func__); |
| 2658 | brcms_down(wlc->wl); |
| 2659 | return; |
| 2660 | } |
| 2661 | WARN_ON(mi & MI_MACSSPNDD); |
| 2662 | |
| 2663 | brcms_b_mctrl(wlc_hw, MCTL_EN_MAC, 0); |
| 2664 | |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2665 | SPINWAIT(!(bcma_read32(core, D11REGOFFS(macintstatus)) & MI_MACSSPNDD), |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2666 | BRCMS_MAX_MAC_SUSPEND); |
| 2667 | |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2668 | if (!(bcma_read32(core, D11REGOFFS(macintstatus)) & MI_MACSSPNDD)) { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 2669 | brcms_err(core, "wl%d: wlc_suspend_mac_and_wait: waited %d uS" |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2670 | " and MI_MACSSPNDD is still not on.\n", |
| 2671 | wlc_hw->unit, BRCMS_MAX_MAC_SUSPEND); |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 2672 | brcms_err(core, "wl%d: psmdebug 0x%08x, phydebug 0x%08x, " |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2673 | "psm_brc 0x%04x\n", wlc_hw->unit, |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2674 | bcma_read32(core, D11REGOFFS(psmdebug)), |
| 2675 | bcma_read32(core, D11REGOFFS(phydebug)), |
| 2676 | bcma_read16(core, D11REGOFFS(psm_brc))); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2677 | } |
| 2678 | |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2679 | mc = bcma_read32(core, D11REGOFFS(maccontrol)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2680 | if (mc == 0xffffffff) { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 2681 | brcms_err(core, "wl%d: %s: dead chip\n", wlc_hw->unit, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2682 | __func__); |
| 2683 | brcms_down(wlc->wl); |
| 2684 | return; |
| 2685 | } |
| 2686 | WARN_ON(mc & MCTL_PSM_JMP_0); |
| 2687 | WARN_ON(!(mc & MCTL_PSM_RUN)); |
| 2688 | WARN_ON(mc & MCTL_EN_MAC); |
| 2689 | } |
| 2690 | |
| 2691 | void brcms_c_enable_mac(struct brcms_c_info *wlc) |
| 2692 | { |
| 2693 | struct brcms_hardware *wlc_hw = wlc->hw; |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2694 | struct bcma_device *core = wlc_hw->d11core; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2695 | u32 mc, mi; |
| 2696 | |
Seth Forshee | 913911f | 2012-11-15 08:08:04 -0600 | [diff] [blame] | 2697 | brcms_dbg_mac80211(core, "wl%d: bandunit %d\n", wlc_hw->unit, |
| 2698 | wlc->band->bandunit); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2699 | |
| 2700 | /* |
| 2701 | * Track overlapping suspend requests |
| 2702 | */ |
| 2703 | wlc_hw->mac_suspend_depth--; |
| 2704 | if (wlc_hw->mac_suspend_depth > 0) |
| 2705 | return; |
| 2706 | |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2707 | mc = bcma_read32(core, D11REGOFFS(maccontrol)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2708 | WARN_ON(mc & MCTL_PSM_JMP_0); |
| 2709 | WARN_ON(mc & MCTL_EN_MAC); |
| 2710 | WARN_ON(!(mc & MCTL_PSM_RUN)); |
| 2711 | |
| 2712 | brcms_b_mctrl(wlc_hw, MCTL_EN_MAC, MCTL_EN_MAC); |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2713 | bcma_write32(core, D11REGOFFS(macintstatus), MI_MACSSPNDD); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2714 | |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2715 | mc = bcma_read32(core, D11REGOFFS(maccontrol)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2716 | WARN_ON(mc & MCTL_PSM_JMP_0); |
| 2717 | WARN_ON(!(mc & MCTL_EN_MAC)); |
| 2718 | WARN_ON(!(mc & MCTL_PSM_RUN)); |
| 2719 | |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2720 | mi = bcma_read32(core, D11REGOFFS(macintstatus)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2721 | WARN_ON(mi & MI_MACSSPNDD); |
| 2722 | |
| 2723 | brcms_c_ucode_wake_override_clear(wlc_hw, |
| 2724 | BRCMS_WAKE_OVERRIDE_MACSUSPEND); |
| 2725 | } |
| 2726 | |
| 2727 | void brcms_b_band_stf_ss_set(struct brcms_hardware *wlc_hw, u8 stf_mode) |
| 2728 | { |
| 2729 | wlc_hw->hw_stf_ss_opmode = stf_mode; |
| 2730 | |
| 2731 | if (wlc_hw->clk) |
| 2732 | brcms_upd_ofdm_pctl1_table(wlc_hw); |
| 2733 | } |
| 2734 | |
| 2735 | static bool brcms_b_validate_chip_access(struct brcms_hardware *wlc_hw) |
| 2736 | { |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2737 | struct bcma_device *core = wlc_hw->d11core; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2738 | u32 w, val; |
| 2739 | struct wiphy *wiphy = wlc_hw->wlc->wiphy; |
| 2740 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2741 | /* Validate dchip register access */ |
| 2742 | |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2743 | bcma_write32(core, D11REGOFFS(objaddr), OBJADDR_SHM_SEL | 0); |
| 2744 | (void)bcma_read32(core, D11REGOFFS(objaddr)); |
| 2745 | w = bcma_read32(core, D11REGOFFS(objdata)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2746 | |
| 2747 | /* Can we write and read back a 32bit register? */ |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2748 | bcma_write32(core, D11REGOFFS(objaddr), OBJADDR_SHM_SEL | 0); |
| 2749 | (void)bcma_read32(core, D11REGOFFS(objaddr)); |
| 2750 | bcma_write32(core, D11REGOFFS(objdata), (u32) 0xaa5555aa); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2751 | |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2752 | bcma_write32(core, D11REGOFFS(objaddr), OBJADDR_SHM_SEL | 0); |
| 2753 | (void)bcma_read32(core, D11REGOFFS(objaddr)); |
| 2754 | val = bcma_read32(core, D11REGOFFS(objdata)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2755 | if (val != (u32) 0xaa5555aa) { |
| 2756 | wiphy_err(wiphy, "wl%d: validate_chip_access: SHM = 0x%x, " |
| 2757 | "expected 0xaa5555aa\n", wlc_hw->unit, val); |
| 2758 | return false; |
| 2759 | } |
| 2760 | |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2761 | bcma_write32(core, D11REGOFFS(objaddr), OBJADDR_SHM_SEL | 0); |
| 2762 | (void)bcma_read32(core, D11REGOFFS(objaddr)); |
| 2763 | bcma_write32(core, D11REGOFFS(objdata), (u32) 0x55aaaa55); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2764 | |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2765 | bcma_write32(core, D11REGOFFS(objaddr), OBJADDR_SHM_SEL | 0); |
| 2766 | (void)bcma_read32(core, D11REGOFFS(objaddr)); |
| 2767 | val = bcma_read32(core, D11REGOFFS(objdata)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2768 | if (val != (u32) 0x55aaaa55) { |
| 2769 | wiphy_err(wiphy, "wl%d: validate_chip_access: SHM = 0x%x, " |
| 2770 | "expected 0x55aaaa55\n", wlc_hw->unit, val); |
| 2771 | return false; |
| 2772 | } |
| 2773 | |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2774 | bcma_write32(core, D11REGOFFS(objaddr), OBJADDR_SHM_SEL | 0); |
| 2775 | (void)bcma_read32(core, D11REGOFFS(objaddr)); |
| 2776 | bcma_write32(core, D11REGOFFS(objdata), w); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2777 | |
| 2778 | /* clear CFPStart */ |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2779 | bcma_write32(core, D11REGOFFS(tsf_cfpstart), 0); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2780 | |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2781 | w = bcma_read32(core, D11REGOFFS(maccontrol)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2782 | if ((w != (MCTL_IHR_EN | MCTL_WAKE)) && |
| 2783 | (w != (MCTL_IHR_EN | MCTL_GMODE | MCTL_WAKE))) { |
| 2784 | wiphy_err(wiphy, "wl%d: validate_chip_access: maccontrol = " |
| 2785 | "0x%x, expected 0x%x or 0x%x\n", wlc_hw->unit, w, |
| 2786 | (MCTL_IHR_EN | MCTL_WAKE), |
| 2787 | (MCTL_IHR_EN | MCTL_GMODE | MCTL_WAKE)); |
| 2788 | return false; |
| 2789 | } |
| 2790 | |
| 2791 | return true; |
| 2792 | } |
| 2793 | |
| 2794 | #define PHYPLL_WAIT_US 100000 |
| 2795 | |
| 2796 | void brcms_b_core_phypll_ctl(struct brcms_hardware *wlc_hw, bool on) |
| 2797 | { |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2798 | struct bcma_device *core = wlc_hw->d11core; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2799 | u32 tmp; |
| 2800 | |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 2801 | brcms_dbg_info(core, "wl%d\n", wlc_hw->unit); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2802 | |
| 2803 | tmp = 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2804 | |
| 2805 | if (on) { |
Hauke Mehrtens | 1ef1a57 | 2012-06-30 15:16:13 +0200 | [diff] [blame] | 2806 | if ((ai_get_chip_id(wlc_hw->sih) == BCMA_CHIP_ID_BCM4313)) { |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2807 | bcma_set32(core, D11REGOFFS(clk_ctl_st), |
| 2808 | CCS_ERSRC_REQ_HT | |
| 2809 | CCS_ERSRC_REQ_D11PLL | |
| 2810 | CCS_ERSRC_REQ_PHYPLL); |
| 2811 | SPINWAIT((bcma_read32(core, D11REGOFFS(clk_ctl_st)) & |
| 2812 | CCS_ERSRC_AVAIL_HT) != CCS_ERSRC_AVAIL_HT, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2813 | PHYPLL_WAIT_US); |
| 2814 | |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2815 | tmp = bcma_read32(core, D11REGOFFS(clk_ctl_st)); |
| 2816 | if ((tmp & CCS_ERSRC_AVAIL_HT) != CCS_ERSRC_AVAIL_HT) |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 2817 | brcms_err(core, "%s: turn on PHY PLL failed\n", |
| 2818 | __func__); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2819 | } else { |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2820 | bcma_set32(core, D11REGOFFS(clk_ctl_st), |
| 2821 | tmp | CCS_ERSRC_REQ_D11PLL | |
| 2822 | CCS_ERSRC_REQ_PHYPLL); |
| 2823 | SPINWAIT((bcma_read32(core, D11REGOFFS(clk_ctl_st)) & |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2824 | (CCS_ERSRC_AVAIL_D11PLL | |
| 2825 | CCS_ERSRC_AVAIL_PHYPLL)) != |
| 2826 | (CCS_ERSRC_AVAIL_D11PLL | |
| 2827 | CCS_ERSRC_AVAIL_PHYPLL), PHYPLL_WAIT_US); |
| 2828 | |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2829 | tmp = bcma_read32(core, D11REGOFFS(clk_ctl_st)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2830 | if ((tmp & |
| 2831 | (CCS_ERSRC_AVAIL_D11PLL | CCS_ERSRC_AVAIL_PHYPLL)) |
| 2832 | != |
| 2833 | (CCS_ERSRC_AVAIL_D11PLL | CCS_ERSRC_AVAIL_PHYPLL)) |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 2834 | brcms_err(core, "%s: turn on PHY PLL failed\n", |
| 2835 | __func__); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2836 | } |
| 2837 | } else { |
| 2838 | /* |
| 2839 | * Since the PLL may be shared, other cores can still |
| 2840 | * be requesting it; so we'll deassert the request but |
| 2841 | * not wait for status to comply. |
| 2842 | */ |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2843 | bcma_mask32(core, D11REGOFFS(clk_ctl_st), |
| 2844 | ~CCS_ERSRC_REQ_PHYPLL); |
| 2845 | (void)bcma_read32(core, D11REGOFFS(clk_ctl_st)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2846 | } |
| 2847 | } |
| 2848 | |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 2849 | static void brcms_c_coredisable(struct brcms_hardware *wlc_hw) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2850 | { |
| 2851 | bool dev_gone; |
| 2852 | |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 2853 | brcms_dbg_info(wlc_hw->d11core, "wl%d: disable core\n", wlc_hw->unit); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2854 | |
| 2855 | dev_gone = brcms_deviceremoved(wlc_hw->wlc); |
| 2856 | |
| 2857 | if (dev_gone) |
| 2858 | return; |
| 2859 | |
| 2860 | if (wlc_hw->noreset) |
| 2861 | return; |
| 2862 | |
| 2863 | /* radio off */ |
| 2864 | wlc_phy_switch_radio(wlc_hw->band->pi, OFF); |
| 2865 | |
| 2866 | /* turn off analog core */ |
| 2867 | wlc_phy_anacore(wlc_hw->band->pi, OFF); |
| 2868 | |
| 2869 | /* turn off PHYPLL to save power */ |
| 2870 | brcms_b_core_phypll_ctl(wlc_hw, false); |
| 2871 | |
| 2872 | wlc_hw->clk = false; |
Arend van Spriel | a8779e4 | 2011-12-08 15:06:58 -0800 | [diff] [blame] | 2873 | bcma_core_disable(wlc_hw->d11core, 0); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2874 | wlc_phy_hw_clk_state_upd(wlc_hw->band->pi, false); |
| 2875 | } |
| 2876 | |
| 2877 | static void brcms_c_flushqueues(struct brcms_c_info *wlc) |
| 2878 | { |
| 2879 | struct brcms_hardware *wlc_hw = wlc->hw; |
| 2880 | uint i; |
| 2881 | |
| 2882 | /* free any posted tx packets */ |
Seth Forshee | e041f65 | 2012-11-15 08:07:56 -0600 | [diff] [blame] | 2883 | for (i = 0; i < NFIFO; i++) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2884 | if (wlc_hw->di[i]) { |
| 2885 | dma_txreclaim(wlc_hw->di[i], DMA_RANGE_ALL); |
Seth Forshee | e041f65 | 2012-11-15 08:07:56 -0600 | [diff] [blame] | 2886 | if (i < TX_BCMC_FIFO) |
| 2887 | ieee80211_wake_queue(wlc->pub->ieee_hw, |
| 2888 | brcms_fifo_to_ac(i)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2889 | } |
Seth Forshee | e041f65 | 2012-11-15 08:07:56 -0600 | [diff] [blame] | 2890 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2891 | |
| 2892 | /* free any posted rx packets */ |
| 2893 | dma_rxreclaim(wlc_hw->di[RX_FIFO]); |
| 2894 | } |
| 2895 | |
| 2896 | static u16 |
| 2897 | brcms_b_read_objmem(struct brcms_hardware *wlc_hw, uint offset, u32 sel) |
| 2898 | { |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2899 | struct bcma_device *core = wlc_hw->d11core; |
| 2900 | u16 objoff = D11REGOFFS(objdata); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2901 | |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2902 | bcma_write32(core, D11REGOFFS(objaddr), sel | (offset >> 2)); |
| 2903 | (void)bcma_read32(core, D11REGOFFS(objaddr)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2904 | if (offset & 2) |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2905 | objoff += 2; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2906 | |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2907 | return bcma_read16(core, objoff); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2908 | } |
| 2909 | |
| 2910 | static void |
| 2911 | brcms_b_write_objmem(struct brcms_hardware *wlc_hw, uint offset, u16 v, |
| 2912 | u32 sel) |
| 2913 | { |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2914 | struct bcma_device *core = wlc_hw->d11core; |
| 2915 | u16 objoff = D11REGOFFS(objdata); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2916 | |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2917 | bcma_write32(core, D11REGOFFS(objaddr), sel | (offset >> 2)); |
| 2918 | (void)bcma_read32(core, D11REGOFFS(objaddr)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2919 | if (offset & 2) |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 2920 | objoff += 2; |
| 2921 | |
Hauke Mehrtens | 512ae05 | 2012-12-07 17:04:13 +0100 | [diff] [blame] | 2922 | bcma_wflush16(core, objoff, v); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2923 | } |
| 2924 | |
| 2925 | /* |
| 2926 | * Read a single u16 from shared memory. |
| 2927 | * SHM 'offset' needs to be an even address |
| 2928 | */ |
| 2929 | u16 brcms_b_read_shm(struct brcms_hardware *wlc_hw, uint offset) |
| 2930 | { |
| 2931 | return brcms_b_read_objmem(wlc_hw, offset, OBJADDR_SHM_SEL); |
| 2932 | } |
| 2933 | |
| 2934 | /* |
| 2935 | * Write a single u16 to shared memory. |
| 2936 | * SHM 'offset' needs to be an even address |
| 2937 | */ |
| 2938 | void brcms_b_write_shm(struct brcms_hardware *wlc_hw, uint offset, u16 v) |
| 2939 | { |
| 2940 | brcms_b_write_objmem(wlc_hw, offset, v, OBJADDR_SHM_SEL); |
| 2941 | } |
| 2942 | |
| 2943 | /* |
| 2944 | * Copy a buffer to shared memory of specified type . |
| 2945 | * SHM 'offset' needs to be an even address and |
| 2946 | * Buffer length 'len' must be an even number of bytes |
| 2947 | * 'sel' selects the type of memory |
| 2948 | */ |
| 2949 | void |
| 2950 | brcms_b_copyto_objmem(struct brcms_hardware *wlc_hw, uint offset, |
| 2951 | const void *buf, int len, u32 sel) |
| 2952 | { |
| 2953 | u16 v; |
| 2954 | const u8 *p = (const u8 *)buf; |
| 2955 | int i; |
| 2956 | |
| 2957 | if (len <= 0 || (offset & 1) || (len & 1)) |
| 2958 | return; |
| 2959 | |
| 2960 | for (i = 0; i < len; i += 2) { |
| 2961 | v = p[i] | (p[i + 1] << 8); |
| 2962 | brcms_b_write_objmem(wlc_hw, offset + i, v, sel); |
| 2963 | } |
| 2964 | } |
| 2965 | |
| 2966 | /* |
| 2967 | * Copy a piece of shared memory of specified type to a buffer . |
| 2968 | * SHM 'offset' needs to be an even address and |
| 2969 | * Buffer length 'len' must be an even number of bytes |
| 2970 | * 'sel' selects the type of memory |
| 2971 | */ |
| 2972 | void |
| 2973 | brcms_b_copyfrom_objmem(struct brcms_hardware *wlc_hw, uint offset, void *buf, |
| 2974 | int len, u32 sel) |
| 2975 | { |
| 2976 | u16 v; |
| 2977 | u8 *p = (u8 *) buf; |
| 2978 | int i; |
| 2979 | |
| 2980 | if (len <= 0 || (offset & 1) || (len & 1)) |
| 2981 | return; |
| 2982 | |
| 2983 | for (i = 0; i < len; i += 2) { |
| 2984 | v = brcms_b_read_objmem(wlc_hw, offset + i, sel); |
| 2985 | p[i] = v & 0xFF; |
| 2986 | p[i + 1] = (v >> 8) & 0xFF; |
| 2987 | } |
| 2988 | } |
| 2989 | |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 2990 | /* Copy a buffer to shared memory. |
| 2991 | * SHM 'offset' needs to be an even address and |
| 2992 | * Buffer length 'len' must be an even number of bytes |
| 2993 | */ |
| 2994 | static void brcms_c_copyto_shm(struct brcms_c_info *wlc, uint offset, |
| 2995 | const void *buf, int len) |
| 2996 | { |
| 2997 | brcms_b_copyto_objmem(wlc->hw, offset, buf, len, OBJADDR_SHM_SEL); |
| 2998 | } |
| 2999 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3000 | static void brcms_b_retrylimit_upd(struct brcms_hardware *wlc_hw, |
| 3001 | u16 SRL, u16 LRL) |
| 3002 | { |
| 3003 | wlc_hw->SRL = SRL; |
| 3004 | wlc_hw->LRL = LRL; |
| 3005 | |
| 3006 | /* write retry limit to SCR, shouldn't need to suspend */ |
| 3007 | if (wlc_hw->up) { |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 3008 | bcma_write32(wlc_hw->d11core, D11REGOFFS(objaddr), |
| 3009 | OBJADDR_SCR_SEL | S_DOT11_SRC_LMT); |
| 3010 | (void)bcma_read32(wlc_hw->d11core, D11REGOFFS(objaddr)); |
| 3011 | bcma_write32(wlc_hw->d11core, D11REGOFFS(objdata), wlc_hw->SRL); |
| 3012 | bcma_write32(wlc_hw->d11core, D11REGOFFS(objaddr), |
| 3013 | OBJADDR_SCR_SEL | S_DOT11_LRC_LMT); |
| 3014 | (void)bcma_read32(wlc_hw->d11core, D11REGOFFS(objaddr)); |
| 3015 | bcma_write32(wlc_hw->d11core, D11REGOFFS(objdata), wlc_hw->LRL); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3016 | } |
| 3017 | } |
| 3018 | |
| 3019 | static void brcms_b_pllreq(struct brcms_hardware *wlc_hw, bool set, u32 req_bit) |
| 3020 | { |
| 3021 | if (set) { |
| 3022 | if (mboolisset(wlc_hw->pllreq, req_bit)) |
| 3023 | return; |
| 3024 | |
| 3025 | mboolset(wlc_hw->pllreq, req_bit); |
| 3026 | |
| 3027 | if (mboolisset(wlc_hw->pllreq, BRCMS_PLLREQ_FLIP)) { |
| 3028 | if (!wlc_hw->sbclk) |
| 3029 | brcms_b_xtal(wlc_hw, ON); |
| 3030 | } |
| 3031 | } else { |
| 3032 | if (!mboolisset(wlc_hw->pllreq, req_bit)) |
| 3033 | return; |
| 3034 | |
| 3035 | mboolclr(wlc_hw->pllreq, req_bit); |
| 3036 | |
| 3037 | if (mboolisset(wlc_hw->pllreq, BRCMS_PLLREQ_FLIP)) { |
| 3038 | if (wlc_hw->sbclk) |
| 3039 | brcms_b_xtal(wlc_hw, OFF); |
| 3040 | } |
| 3041 | } |
| 3042 | } |
| 3043 | |
| 3044 | static void brcms_b_antsel_set(struct brcms_hardware *wlc_hw, u32 antsel_avail) |
| 3045 | { |
| 3046 | wlc_hw->antsel_avail = antsel_avail; |
| 3047 | } |
| 3048 | |
| 3049 | /* |
| 3050 | * conditions under which the PM bit should be set in outgoing frames |
| 3051 | * and STAY_AWAKE is meaningful |
| 3052 | */ |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 3053 | static bool brcms_c_ps_allowed(struct brcms_c_info *wlc) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3054 | { |
| 3055 | struct brcms_bss_cfg *cfg = wlc->bsscfg; |
| 3056 | |
| 3057 | /* disallow PS when one of the following global conditions meets */ |
| 3058 | if (!wlc->pub->associated) |
| 3059 | return false; |
| 3060 | |
| 3061 | /* disallow PS when one of these meets when not scanning */ |
Alwin Beukers | be66766 | 2011-11-22 17:21:43 -0800 | [diff] [blame] | 3062 | if (wlc->filter_flags & FIF_PROMISC_IN_BSS) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3063 | return false; |
| 3064 | |
| 3065 | if (cfg->associated) { |
| 3066 | /* |
| 3067 | * disallow PS when one of the following |
| 3068 | * bsscfg specific conditions meets |
| 3069 | */ |
| 3070 | if (!cfg->BSS) |
| 3071 | return false; |
| 3072 | |
| 3073 | return false; |
| 3074 | } |
| 3075 | |
| 3076 | return true; |
| 3077 | } |
| 3078 | |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 3079 | static void brcms_c_statsupd(struct brcms_c_info *wlc) |
| 3080 | { |
| 3081 | int i; |
| 3082 | struct macstat macstats; |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 3083 | #ifdef DEBUG |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 3084 | u16 delta; |
| 3085 | u16 rxf0ovfl; |
| 3086 | u16 txfunfl[NFIFO]; |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 3087 | #endif /* DEBUG */ |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 3088 | |
| 3089 | /* if driver down, make no sense to update stats */ |
| 3090 | if (!wlc->pub->up) |
| 3091 | return; |
| 3092 | |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 3093 | #ifdef DEBUG |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 3094 | /* save last rx fifo 0 overflow count */ |
| 3095 | rxf0ovfl = wlc->core->macstat_snapshot->rxf0ovfl; |
| 3096 | |
| 3097 | /* save last tx fifo underflow count */ |
| 3098 | for (i = 0; i < NFIFO; i++) |
| 3099 | txfunfl[i] = wlc->core->macstat_snapshot->txfunfl[i]; |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 3100 | #endif /* DEBUG */ |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 3101 | |
| 3102 | /* Read mac stats from contiguous shared memory */ |
| 3103 | brcms_b_copyfrom_objmem(wlc->hw, M_UCODE_MACSTAT, &macstats, |
| 3104 | sizeof(struct macstat), OBJADDR_SHM_SEL); |
| 3105 | |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 3106 | #ifdef DEBUG |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 3107 | /* check for rx fifo 0 overflow */ |
| 3108 | delta = (u16) (wlc->core->macstat_snapshot->rxf0ovfl - rxf0ovfl); |
| 3109 | if (delta) |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 3110 | brcms_err(wlc->hw->d11core, "wl%d: %u rx fifo 0 overflows!\n", |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 3111 | wlc->pub->unit, delta); |
| 3112 | |
| 3113 | /* check for tx fifo underflows */ |
| 3114 | for (i = 0; i < NFIFO; i++) { |
| 3115 | delta = |
| 3116 | (u16) (wlc->core->macstat_snapshot->txfunfl[i] - |
| 3117 | txfunfl[i]); |
| 3118 | if (delta) |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 3119 | brcms_err(wlc->hw->d11core, |
| 3120 | "wl%d: %u tx fifo %d underflows!\n", |
| 3121 | wlc->pub->unit, delta, i); |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 3122 | } |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 3123 | #endif /* DEBUG */ |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 3124 | |
| 3125 | /* merge counters from dma module */ |
| 3126 | for (i = 0; i < NFIFO; i++) { |
| 3127 | if (wlc->hw->di[i]) |
| 3128 | dma_counterreset(wlc->hw->di[i]); |
| 3129 | } |
| 3130 | } |
| 3131 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3132 | static void brcms_b_reset(struct brcms_hardware *wlc_hw) |
| 3133 | { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3134 | /* reset the core */ |
| 3135 | if (!brcms_deviceremoved(wlc_hw->wlc)) |
| 3136 | brcms_b_corereset(wlc_hw, BRCMS_USE_COREFLAGS); |
| 3137 | |
| 3138 | /* purge the dma rings */ |
| 3139 | brcms_c_flushqueues(wlc_hw->wlc); |
| 3140 | } |
| 3141 | |
| 3142 | void brcms_c_reset(struct brcms_c_info *wlc) |
| 3143 | { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 3144 | brcms_dbg_info(wlc->hw->d11core, "wl%d\n", wlc->pub->unit); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3145 | |
| 3146 | /* slurp up hw mac counters before core reset */ |
| 3147 | brcms_c_statsupd(wlc); |
| 3148 | |
| 3149 | /* reset our snapshot of macstat counters */ |
| 3150 | memset((char *)wlc->core->macstat_snapshot, 0, |
| 3151 | sizeof(struct macstat)); |
| 3152 | |
| 3153 | brcms_b_reset(wlc->hw); |
| 3154 | } |
| 3155 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3156 | void brcms_c_init_scb(struct scb *scb) |
| 3157 | { |
| 3158 | int i; |
| 3159 | |
| 3160 | memset(scb, 0, sizeof(struct scb)); |
| 3161 | scb->flags = SCB_WMECAP | SCB_HTCAP; |
| 3162 | for (i = 0; i < NUMPRIO; i++) { |
| 3163 | scb->seqnum[i] = 0; |
| 3164 | scb->seqctl[i] = 0xFFFF; |
| 3165 | } |
| 3166 | |
| 3167 | scb->seqctl_nonqos = 0xFFFF; |
| 3168 | scb->magic = SCB_MAGIC; |
| 3169 | } |
| 3170 | |
| 3171 | /* d11 core init |
| 3172 | * reset PSM |
| 3173 | * download ucode/PCM |
| 3174 | * let ucode run to suspended |
| 3175 | * download ucode inits |
| 3176 | * config other core registers |
| 3177 | * init dma |
| 3178 | */ |
| 3179 | static void brcms_b_coreinit(struct brcms_c_info *wlc) |
| 3180 | { |
| 3181 | struct brcms_hardware *wlc_hw = wlc->hw; |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 3182 | struct bcma_device *core = wlc_hw->d11core; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3183 | u32 sflags; |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 3184 | u32 bcnint_us; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3185 | uint i = 0; |
| 3186 | bool fifosz_fixup = false; |
| 3187 | int err = 0; |
| 3188 | u16 buf[NFIFO]; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3189 | struct brcms_ucode *ucode = &wlc_hw->wlc->wl->ucode; |
| 3190 | |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 3191 | brcms_dbg_info(core, "wl%d: core init\n", wlc_hw->unit); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3192 | |
| 3193 | /* reset PSM */ |
| 3194 | brcms_b_mctrl(wlc_hw, ~0, (MCTL_IHR_EN | MCTL_PSM_JMP_0 | MCTL_WAKE)); |
| 3195 | |
| 3196 | brcms_ucode_download(wlc_hw); |
| 3197 | /* |
| 3198 | * FIFOSZ fixup. driver wants to controls the fifo allocation. |
| 3199 | */ |
| 3200 | fifosz_fixup = true; |
| 3201 | |
| 3202 | /* let the PSM run to the suspended state, set mode to BSS STA */ |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 3203 | bcma_write32(core, D11REGOFFS(macintstatus), -1); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3204 | brcms_b_mctrl(wlc_hw, ~0, |
| 3205 | (MCTL_IHR_EN | MCTL_INFRA | MCTL_PSM_RUN | MCTL_WAKE)); |
| 3206 | |
| 3207 | /* wait for ucode to self-suspend after auto-init */ |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 3208 | SPINWAIT(((bcma_read32(core, D11REGOFFS(macintstatus)) & |
| 3209 | MI_MACSSPNDD) == 0), 1000 * 1000); |
| 3210 | if ((bcma_read32(core, D11REGOFFS(macintstatus)) & MI_MACSSPNDD) == 0) |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 3211 | brcms_err(core, "wl%d: wlc_coreinit: ucode did not self-" |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3212 | "suspend!\n", wlc_hw->unit); |
| 3213 | |
| 3214 | brcms_c_gpio_init(wlc); |
| 3215 | |
Arend van Spriel | a8779e4 | 2011-12-08 15:06:58 -0800 | [diff] [blame] | 3216 | sflags = bcma_aread32(core, BCMA_IOST); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3217 | |
Hauke Mehrtens | 6f80f01 | 2012-12-07 00:35:53 +0100 | [diff] [blame] | 3218 | if (D11REV_IS(wlc_hw->corerev, 17) || D11REV_IS(wlc_hw->corerev, 23)) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3219 | if (BRCMS_ISNPHY(wlc_hw->band)) |
| 3220 | brcms_c_write_inits(wlc_hw, ucode->d11n0initvals16); |
| 3221 | else |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 3222 | brcms_err(core, "%s: wl%d: unsupported phy in corerev" |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3223 | " %d\n", __func__, wlc_hw->unit, |
| 3224 | wlc_hw->corerev); |
| 3225 | } else if (D11REV_IS(wlc_hw->corerev, 24)) { |
| 3226 | if (BRCMS_ISLCNPHY(wlc_hw->band)) |
| 3227 | brcms_c_write_inits(wlc_hw, ucode->d11lcn0initvals24); |
| 3228 | else |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 3229 | brcms_err(core, "%s: wl%d: unsupported phy in corerev" |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3230 | " %d\n", __func__, wlc_hw->unit, |
| 3231 | wlc_hw->corerev); |
| 3232 | } else { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 3233 | brcms_err(core, "%s: wl%d: unsupported corerev %d\n", |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3234 | __func__, wlc_hw->unit, wlc_hw->corerev); |
| 3235 | } |
| 3236 | |
| 3237 | /* For old ucode, txfifo sizes needs to be modified(increased) */ |
Joe Perches | 23677ce | 2012-02-09 11:17:23 +0000 | [diff] [blame] | 3238 | if (fifosz_fixup) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3239 | brcms_b_corerev_fifofixup(wlc_hw); |
| 3240 | |
| 3241 | /* check txfifo allocations match between ucode and driver */ |
| 3242 | buf[TX_AC_BE_FIFO] = brcms_b_read_shm(wlc_hw, M_FIFOSIZE0); |
| 3243 | if (buf[TX_AC_BE_FIFO] != wlc_hw->xmtfifo_sz[TX_AC_BE_FIFO]) { |
| 3244 | i = TX_AC_BE_FIFO; |
| 3245 | err = -1; |
| 3246 | } |
| 3247 | buf[TX_AC_VI_FIFO] = brcms_b_read_shm(wlc_hw, M_FIFOSIZE1); |
| 3248 | if (buf[TX_AC_VI_FIFO] != wlc_hw->xmtfifo_sz[TX_AC_VI_FIFO]) { |
| 3249 | i = TX_AC_VI_FIFO; |
| 3250 | err = -1; |
| 3251 | } |
| 3252 | buf[TX_AC_BK_FIFO] = brcms_b_read_shm(wlc_hw, M_FIFOSIZE2); |
| 3253 | buf[TX_AC_VO_FIFO] = (buf[TX_AC_BK_FIFO] >> 8) & 0xff; |
| 3254 | buf[TX_AC_BK_FIFO] &= 0xff; |
| 3255 | if (buf[TX_AC_BK_FIFO] != wlc_hw->xmtfifo_sz[TX_AC_BK_FIFO]) { |
| 3256 | i = TX_AC_BK_FIFO; |
| 3257 | err = -1; |
| 3258 | } |
| 3259 | if (buf[TX_AC_VO_FIFO] != wlc_hw->xmtfifo_sz[TX_AC_VO_FIFO]) { |
| 3260 | i = TX_AC_VO_FIFO; |
| 3261 | err = -1; |
| 3262 | } |
| 3263 | buf[TX_BCMC_FIFO] = brcms_b_read_shm(wlc_hw, M_FIFOSIZE3); |
| 3264 | buf[TX_ATIM_FIFO] = (buf[TX_BCMC_FIFO] >> 8) & 0xff; |
| 3265 | buf[TX_BCMC_FIFO] &= 0xff; |
| 3266 | if (buf[TX_BCMC_FIFO] != wlc_hw->xmtfifo_sz[TX_BCMC_FIFO]) { |
| 3267 | i = TX_BCMC_FIFO; |
| 3268 | err = -1; |
| 3269 | } |
| 3270 | if (buf[TX_ATIM_FIFO] != wlc_hw->xmtfifo_sz[TX_ATIM_FIFO]) { |
| 3271 | i = TX_ATIM_FIFO; |
| 3272 | err = -1; |
| 3273 | } |
| 3274 | if (err != 0) |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 3275 | brcms_err(core, "wlc_coreinit: txfifo mismatch: ucode size %d" |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3276 | " driver size %d index %d\n", buf[i], |
| 3277 | wlc_hw->xmtfifo_sz[i], i); |
| 3278 | |
| 3279 | /* make sure we can still talk to the mac */ |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 3280 | WARN_ON(bcma_read32(core, D11REGOFFS(maccontrol)) == 0xffffffff); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3281 | |
| 3282 | /* band-specific inits done by wlc_bsinit() */ |
| 3283 | |
| 3284 | /* Set up frame burst size and antenna swap threshold init values */ |
| 3285 | brcms_b_write_shm(wlc_hw, M_MBURST_SIZE, MAXTXFRAMEBURST); |
| 3286 | brcms_b_write_shm(wlc_hw, M_MAX_ANTCNT, ANTCNT); |
| 3287 | |
| 3288 | /* enable one rx interrupt per received frame */ |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 3289 | bcma_write32(core, D11REGOFFS(intrcvlazy[0]), (1 << IRL_FC_SHIFT)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3290 | |
| 3291 | /* set the station mode (BSS STA) */ |
| 3292 | brcms_b_mctrl(wlc_hw, |
| 3293 | (MCTL_INFRA | MCTL_DISCARD_PMQ | MCTL_AP), |
| 3294 | (MCTL_INFRA | MCTL_DISCARD_PMQ)); |
| 3295 | |
| 3296 | /* set up Beacon interval */ |
| 3297 | bcnint_us = 0x8000 << 10; |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 3298 | bcma_write32(core, D11REGOFFS(tsf_cfprep), |
| 3299 | (bcnint_us << CFPREP_CBI_SHIFT)); |
| 3300 | bcma_write32(core, D11REGOFFS(tsf_cfpstart), bcnint_us); |
| 3301 | bcma_write32(core, D11REGOFFS(macintstatus), MI_GP1); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3302 | |
| 3303 | /* write interrupt mask */ |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 3304 | bcma_write32(core, D11REGOFFS(intctrlregs[RX_FIFO].intmask), |
| 3305 | DEF_RXINTMASK); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3306 | |
| 3307 | /* allow the MAC to control the PHY clock (dynamic on/off) */ |
| 3308 | brcms_b_macphyclk_set(wlc_hw, ON); |
| 3309 | |
| 3310 | /* program dynamic clock control fast powerup delay register */ |
| 3311 | wlc->fastpwrup_dly = ai_clkctl_fast_pwrup_delay(wlc_hw->sih); |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 3312 | bcma_write16(core, D11REGOFFS(scc_fastpwrup_dly), wlc->fastpwrup_dly); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3313 | |
| 3314 | /* tell the ucode the corerev */ |
| 3315 | brcms_b_write_shm(wlc_hw, M_MACHW_VER, (u16) wlc_hw->corerev); |
| 3316 | |
| 3317 | /* tell the ucode MAC capabilities */ |
| 3318 | brcms_b_write_shm(wlc_hw, M_MACHW_CAP_L, |
| 3319 | (u16) (wlc_hw->machwcap & 0xffff)); |
| 3320 | brcms_b_write_shm(wlc_hw, M_MACHW_CAP_H, |
| 3321 | (u16) ((wlc_hw-> |
| 3322 | machwcap >> 16) & 0xffff)); |
| 3323 | |
| 3324 | /* write retry limits to SCR, this done after PSM init */ |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 3325 | bcma_write32(core, D11REGOFFS(objaddr), |
| 3326 | OBJADDR_SCR_SEL | S_DOT11_SRC_LMT); |
| 3327 | (void)bcma_read32(core, D11REGOFFS(objaddr)); |
| 3328 | bcma_write32(core, D11REGOFFS(objdata), wlc_hw->SRL); |
| 3329 | bcma_write32(core, D11REGOFFS(objaddr), |
| 3330 | OBJADDR_SCR_SEL | S_DOT11_LRC_LMT); |
| 3331 | (void)bcma_read32(core, D11REGOFFS(objaddr)); |
| 3332 | bcma_write32(core, D11REGOFFS(objdata), wlc_hw->LRL); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3333 | |
| 3334 | /* write rate fallback retry limits */ |
| 3335 | brcms_b_write_shm(wlc_hw, M_SFRMTXCNTFBRTHSD, wlc_hw->SFBL); |
| 3336 | brcms_b_write_shm(wlc_hw, M_LFRMTXCNTFBRTHSD, wlc_hw->LFBL); |
| 3337 | |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 3338 | bcma_mask16(core, D11REGOFFS(ifs_ctl), 0x0FFF); |
| 3339 | bcma_write16(core, D11REGOFFS(ifs_aifsn), EDCF_AIFSN_MIN); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3340 | |
| 3341 | /* init the tx dma engines */ |
| 3342 | for (i = 0; i < NFIFO; i++) { |
| 3343 | if (wlc_hw->di[i]) |
| 3344 | dma_txinit(wlc_hw->di[i]); |
| 3345 | } |
| 3346 | |
| 3347 | /* init the rx dma engine(s) and post receive buffers */ |
| 3348 | dma_rxinit(wlc_hw->di[RX_FIFO]); |
| 3349 | dma_rxfill(wlc_hw->di[RX_FIFO]); |
| 3350 | } |
| 3351 | |
| 3352 | void |
Roland Vossen | a8bc491 | 2011-10-21 16:16:25 +0200 | [diff] [blame] | 3353 | static brcms_b_init(struct brcms_hardware *wlc_hw, u16 chanspec) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3354 | u32 macintmask; |
| 3355 | bool fastclk; |
| 3356 | struct brcms_c_info *wlc = wlc_hw->wlc; |
| 3357 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3358 | /* request FAST clock if not on */ |
| 3359 | fastclk = wlc_hw->forcefastclk; |
| 3360 | if (!fastclk) |
Hauke Mehrtens | 712e3c1 | 2012-04-29 02:50:35 +0200 | [diff] [blame] | 3361 | brcms_b_clkctl_clk(wlc_hw, BCMA_CLKMODE_FAST); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3362 | |
| 3363 | /* disable interrupts */ |
| 3364 | macintmask = brcms_intrsoff(wlc->wl); |
| 3365 | |
| 3366 | /* set up the specified band and chanspec */ |
| 3367 | brcms_c_setxband(wlc_hw, chspec_bandunit(chanspec)); |
| 3368 | wlc_phy_chanspec_radio_set(wlc_hw->band->pi, chanspec); |
| 3369 | |
| 3370 | /* do one-time phy inits and calibration */ |
| 3371 | wlc_phy_cal_init(wlc_hw->band->pi); |
| 3372 | |
| 3373 | /* core-specific initialization */ |
| 3374 | brcms_b_coreinit(wlc); |
| 3375 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3376 | /* band-specific inits */ |
| 3377 | brcms_b_bsinit(wlc, chanspec); |
| 3378 | |
| 3379 | /* restore macintmask */ |
| 3380 | brcms_intrsrestore(wlc->wl, macintmask); |
| 3381 | |
| 3382 | /* seed wake_override with BRCMS_WAKE_OVERRIDE_MACSUSPEND since the mac |
| 3383 | * is suspended and brcms_c_enable_mac() will clear this override bit. |
| 3384 | */ |
| 3385 | mboolset(wlc_hw->wake_override, BRCMS_WAKE_OVERRIDE_MACSUSPEND); |
| 3386 | |
| 3387 | /* |
| 3388 | * initialize mac_suspend_depth to 1 to match ucode |
| 3389 | * initial suspended state |
| 3390 | */ |
| 3391 | wlc_hw->mac_suspend_depth = 1; |
| 3392 | |
| 3393 | /* restore the clk */ |
| 3394 | if (!fastclk) |
Hauke Mehrtens | 712e3c1 | 2012-04-29 02:50:35 +0200 | [diff] [blame] | 3395 | brcms_b_clkctl_clk(wlc_hw, BCMA_CLKMODE_DYNAMIC); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3396 | } |
| 3397 | |
| 3398 | static void brcms_c_set_phy_chanspec(struct brcms_c_info *wlc, |
| 3399 | u16 chanspec) |
| 3400 | { |
| 3401 | /* Save our copy of the chanspec */ |
| 3402 | wlc->chanspec = chanspec; |
| 3403 | |
| 3404 | /* Set the chanspec and power limits for this locale */ |
| 3405 | brcms_c_channel_set_chanspec(wlc->cmi, chanspec, BRCMS_TXPWR_MAX); |
| 3406 | |
| 3407 | if (wlc->stf->ss_algosel_auto) |
| 3408 | brcms_c_stf_ss_algo_channel_get(wlc, &wlc->stf->ss_algo_channel, |
| 3409 | chanspec); |
| 3410 | |
| 3411 | brcms_c_stf_ss_update(wlc, wlc->band); |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 3412 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3413 | |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 3414 | static void |
| 3415 | brcms_default_rateset(struct brcms_c_info *wlc, struct brcms_c_rateset *rs) |
| 3416 | { |
| 3417 | brcms_c_rateset_default(rs, NULL, wlc->band->phytype, |
| 3418 | wlc->band->bandtype, false, BRCMS_RATE_MASK_FULL, |
| 3419 | (bool) (wlc->pub->_n_enab & SUPPORT_11N), |
| 3420 | brcms_chspec_bw(wlc->default_bss->chanspec), |
| 3421 | wlc->stf->txstreams); |
| 3422 | } |
| 3423 | |
| 3424 | /* derive wlc->band->basic_rate[] table from 'rateset' */ |
| 3425 | static void brcms_c_rate_lookup_init(struct brcms_c_info *wlc, |
| 3426 | struct brcms_c_rateset *rateset) |
| 3427 | { |
| 3428 | u8 rate; |
| 3429 | u8 mandatory; |
| 3430 | u8 cck_basic = 0; |
| 3431 | u8 ofdm_basic = 0; |
| 3432 | u8 *br = wlc->band->basic_rate; |
| 3433 | uint i; |
| 3434 | |
| 3435 | /* incoming rates are in 500kbps units as in 802.11 Supported Rates */ |
| 3436 | memset(br, 0, BRCM_MAXRATE + 1); |
| 3437 | |
| 3438 | /* For each basic rate in the rates list, make an entry in the |
| 3439 | * best basic lookup. |
| 3440 | */ |
| 3441 | for (i = 0; i < rateset->count; i++) { |
| 3442 | /* only make an entry for a basic rate */ |
| 3443 | if (!(rateset->rates[i] & BRCMS_RATE_FLAG)) |
| 3444 | continue; |
| 3445 | |
| 3446 | /* mask off basic bit */ |
| 3447 | rate = (rateset->rates[i] & BRCMS_RATE_MASK); |
| 3448 | |
| 3449 | if (rate > BRCM_MAXRATE) { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 3450 | brcms_err(wlc->hw->d11core, "brcms_c_rate_lookup_init: " |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 3451 | "invalid rate 0x%X in rate set\n", |
| 3452 | rateset->rates[i]); |
| 3453 | continue; |
| 3454 | } |
| 3455 | |
| 3456 | br[rate] = rate; |
| 3457 | } |
| 3458 | |
| 3459 | /* The rate lookup table now has non-zero entries for each |
| 3460 | * basic rate, equal to the basic rate: br[basicN] = basicN |
| 3461 | * |
| 3462 | * To look up the best basic rate corresponding to any |
| 3463 | * particular rate, code can use the basic_rate table |
| 3464 | * like this |
| 3465 | * |
| 3466 | * basic_rate = wlc->band->basic_rate[tx_rate] |
| 3467 | * |
| 3468 | * Make sure there is a best basic rate entry for |
| 3469 | * every rate by walking up the table from low rates |
| 3470 | * to high, filling in holes in the lookup table |
| 3471 | */ |
| 3472 | |
| 3473 | for (i = 0; i < wlc->band->hw_rateset.count; i++) { |
| 3474 | rate = wlc->band->hw_rateset.rates[i]; |
| 3475 | |
| 3476 | if (br[rate] != 0) { |
| 3477 | /* This rate is a basic rate. |
| 3478 | * Keep track of the best basic rate so far by |
| 3479 | * modulation type. |
| 3480 | */ |
| 3481 | if (is_ofdm_rate(rate)) |
| 3482 | ofdm_basic = rate; |
| 3483 | else |
| 3484 | cck_basic = rate; |
| 3485 | |
| 3486 | continue; |
| 3487 | } |
| 3488 | |
| 3489 | /* This rate is not a basic rate so figure out the |
| 3490 | * best basic rate less than this rate and fill in |
| 3491 | * the hole in the table |
| 3492 | */ |
| 3493 | |
| 3494 | br[rate] = is_ofdm_rate(rate) ? ofdm_basic : cck_basic; |
| 3495 | |
| 3496 | if (br[rate] != 0) |
| 3497 | continue; |
| 3498 | |
| 3499 | if (is_ofdm_rate(rate)) { |
| 3500 | /* |
| 3501 | * In 11g and 11a, the OFDM mandatory rates |
| 3502 | * are 6, 12, and 24 Mbps |
| 3503 | */ |
| 3504 | if (rate >= BRCM_RATE_24M) |
| 3505 | mandatory = BRCM_RATE_24M; |
| 3506 | else if (rate >= BRCM_RATE_12M) |
| 3507 | mandatory = BRCM_RATE_12M; |
| 3508 | else |
| 3509 | mandatory = BRCM_RATE_6M; |
| 3510 | } else { |
| 3511 | /* In 11b, all CCK rates are mandatory 1 - 11 Mbps */ |
| 3512 | mandatory = rate; |
| 3513 | } |
| 3514 | |
| 3515 | br[rate] = mandatory; |
| 3516 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3517 | } |
| 3518 | |
| 3519 | static void brcms_c_bandinit_ordered(struct brcms_c_info *wlc, |
| 3520 | u16 chanspec) |
| 3521 | { |
| 3522 | struct brcms_c_rateset default_rateset; |
| 3523 | uint parkband; |
| 3524 | uint i, band_order[2]; |
| 3525 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3526 | /* |
| 3527 | * We might have been bandlocked during down and the chip |
| 3528 | * power-cycled (hibernate). Figure out the right band to park on |
| 3529 | */ |
| 3530 | if (wlc->bandlocked || wlc->pub->_nbands == 1) { |
| 3531 | /* updated in brcms_c_bandlock() */ |
| 3532 | parkband = wlc->band->bandunit; |
| 3533 | band_order[0] = band_order[1] = parkband; |
| 3534 | } else { |
| 3535 | /* park on the band of the specified chanspec */ |
| 3536 | parkband = chspec_bandunit(chanspec); |
| 3537 | |
| 3538 | /* order so that parkband initialize last */ |
| 3539 | band_order[0] = parkband ^ 1; |
| 3540 | band_order[1] = parkband; |
| 3541 | } |
| 3542 | |
| 3543 | /* make each band operational, software state init */ |
| 3544 | for (i = 0; i < wlc->pub->_nbands; i++) { |
| 3545 | uint j = band_order[i]; |
| 3546 | |
| 3547 | wlc->band = wlc->bandstate[j]; |
| 3548 | |
| 3549 | brcms_default_rateset(wlc, &default_rateset); |
| 3550 | |
| 3551 | /* fill in hw_rate */ |
| 3552 | brcms_c_rateset_filter(&default_rateset, &wlc->band->hw_rateset, |
| 3553 | false, BRCMS_RATES_CCK_OFDM, BRCMS_RATE_MASK, |
| 3554 | (bool) (wlc->pub->_n_enab & SUPPORT_11N)); |
| 3555 | |
| 3556 | /* init basic rate lookup */ |
| 3557 | brcms_c_rate_lookup_init(wlc, &default_rateset); |
| 3558 | } |
| 3559 | |
| 3560 | /* sync up phy/radio chanspec */ |
| 3561 | brcms_c_set_phy_chanspec(wlc, chanspec); |
| 3562 | } |
| 3563 | |
Alwin Beukers | 02a588a | 2011-11-10 20:30:28 +0100 | [diff] [blame] | 3564 | /* |
Alwin Beukers | be66766 | 2011-11-22 17:21:43 -0800 | [diff] [blame] | 3565 | * Set or clear filtering related maccontrol bits based on |
| 3566 | * specified filter flags |
Alwin Beukers | 02a588a | 2011-11-10 20:30:28 +0100 | [diff] [blame] | 3567 | */ |
Alwin Beukers | be66766 | 2011-11-22 17:21:43 -0800 | [diff] [blame] | 3568 | void brcms_c_mac_promisc(struct brcms_c_info *wlc, uint filter_flags) |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 3569 | { |
Alwin Beukers | 02a588a | 2011-11-10 20:30:28 +0100 | [diff] [blame] | 3570 | u32 promisc_bits = 0; |
| 3571 | |
Alwin Beukers | be66766 | 2011-11-22 17:21:43 -0800 | [diff] [blame] | 3572 | wlc->filter_flags = filter_flags; |
| 3573 | |
| 3574 | if (filter_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS)) |
| 3575 | promisc_bits |= MCTL_PROMISC; |
| 3576 | |
| 3577 | if (filter_flags & FIF_BCN_PRBRESP_PROMISC) |
Alwin Beukers | 02a588a | 2011-11-10 20:30:28 +0100 | [diff] [blame] | 3578 | promisc_bits |= MCTL_BCNS_PROMISC; |
| 3579 | |
Alwin Beukers | be66766 | 2011-11-22 17:21:43 -0800 | [diff] [blame] | 3580 | if (filter_flags & FIF_FCSFAIL) |
| 3581 | promisc_bits |= MCTL_KEEPBADFCS; |
| 3582 | |
| 3583 | if (filter_flags & (FIF_CONTROL | FIF_PSPOLL)) |
| 3584 | promisc_bits |= MCTL_KEEPCONTROL; |
Alwin Beukers | 02a588a | 2011-11-10 20:30:28 +0100 | [diff] [blame] | 3585 | |
| 3586 | brcms_b_mctrl(wlc->hw, |
Alwin Beukers | be66766 | 2011-11-22 17:21:43 -0800 | [diff] [blame] | 3587 | MCTL_PROMISC | MCTL_BCNS_PROMISC | |
| 3588 | MCTL_KEEPCONTROL | MCTL_KEEPBADFCS, |
| 3589 | promisc_bits); |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 3590 | } |
| 3591 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3592 | /* |
| 3593 | * ucode, hwmac update |
| 3594 | * Channel dependent updates for ucode and hw |
| 3595 | */ |
| 3596 | static void brcms_c_ucode_mac_upd(struct brcms_c_info *wlc) |
| 3597 | { |
| 3598 | /* enable or disable any active IBSSs depending on whether or not |
| 3599 | * we are on the home channel |
| 3600 | */ |
| 3601 | if (wlc->home_chanspec == wlc_phy_chanspec_get(wlc->band->pi)) { |
| 3602 | if (wlc->pub->associated) { |
| 3603 | /* |
| 3604 | * BMAC_NOTE: This is something that should be fixed |
| 3605 | * in ucode inits. I think that the ucode inits set |
| 3606 | * up the bcn templates and shm values with a bogus |
| 3607 | * beacon. This should not be done in the inits. If |
| 3608 | * ucode needs to set up a beacon for testing, the |
| 3609 | * test routines should write it down, not expect the |
| 3610 | * inits to populate a bogus beacon. |
| 3611 | */ |
| 3612 | if (BRCMS_PHY_11N_CAP(wlc->band)) |
| 3613 | brcms_b_write_shm(wlc->hw, |
| 3614 | M_BCN_TXTSF_OFFSET, 0); |
| 3615 | } |
| 3616 | } else { |
| 3617 | /* disable an active IBSS if we are not on the home channel */ |
| 3618 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3619 | } |
| 3620 | |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 3621 | static void brcms_c_write_rate_shm(struct brcms_c_info *wlc, u8 rate, |
| 3622 | u8 basic_rate) |
| 3623 | { |
| 3624 | u8 phy_rate, index; |
| 3625 | u8 basic_phy_rate, basic_index; |
| 3626 | u16 dir_table, basic_table; |
| 3627 | u16 basic_ptr; |
| 3628 | |
| 3629 | /* Shared memory address for the table we are reading */ |
| 3630 | dir_table = is_ofdm_rate(basic_rate) ? M_RT_DIRMAP_A : M_RT_DIRMAP_B; |
| 3631 | |
| 3632 | /* Shared memory address for the table we are writing */ |
| 3633 | basic_table = is_ofdm_rate(rate) ? M_RT_BBRSMAP_A : M_RT_BBRSMAP_B; |
| 3634 | |
| 3635 | /* |
| 3636 | * for a given rate, the LS-nibble of the PLCP SIGNAL field is |
| 3637 | * the index into the rate table. |
| 3638 | */ |
| 3639 | phy_rate = rate_info[rate] & BRCMS_RATE_MASK; |
| 3640 | basic_phy_rate = rate_info[basic_rate] & BRCMS_RATE_MASK; |
| 3641 | index = phy_rate & 0xf; |
| 3642 | basic_index = basic_phy_rate & 0xf; |
| 3643 | |
| 3644 | /* Find the SHM pointer to the ACK rate entry by looking in the |
| 3645 | * Direct-map Table |
| 3646 | */ |
| 3647 | basic_ptr = brcms_b_read_shm(wlc->hw, (dir_table + basic_index * 2)); |
| 3648 | |
| 3649 | /* Update the SHM BSS-basic-rate-set mapping table with the pointer |
| 3650 | * to the correct basic rate for the given incoming rate |
| 3651 | */ |
| 3652 | brcms_b_write_shm(wlc->hw, (basic_table + index * 2), basic_ptr); |
| 3653 | } |
| 3654 | |
| 3655 | static const struct brcms_c_rateset * |
| 3656 | brcms_c_rateset_get_hwrs(struct brcms_c_info *wlc) |
| 3657 | { |
| 3658 | const struct brcms_c_rateset *rs_dflt; |
| 3659 | |
| 3660 | if (BRCMS_PHY_11N_CAP(wlc->band)) { |
| 3661 | if (wlc->band->bandtype == BRCM_BAND_5G) |
| 3662 | rs_dflt = &ofdm_mimo_rates; |
| 3663 | else |
| 3664 | rs_dflt = &cck_ofdm_mimo_rates; |
| 3665 | } else if (wlc->band->gmode) |
| 3666 | rs_dflt = &cck_ofdm_rates; |
| 3667 | else |
| 3668 | rs_dflt = &cck_rates; |
| 3669 | |
| 3670 | return rs_dflt; |
| 3671 | } |
| 3672 | |
| 3673 | static void brcms_c_set_ratetable(struct brcms_c_info *wlc) |
| 3674 | { |
| 3675 | const struct brcms_c_rateset *rs_dflt; |
| 3676 | struct brcms_c_rateset rs; |
| 3677 | u8 rate, basic_rate; |
| 3678 | uint i; |
| 3679 | |
| 3680 | rs_dflt = brcms_c_rateset_get_hwrs(wlc); |
| 3681 | |
| 3682 | brcms_c_rateset_copy(rs_dflt, &rs); |
| 3683 | brcms_c_rateset_mcs_upd(&rs, wlc->stf->txstreams); |
| 3684 | |
| 3685 | /* walk the phy rate table and update SHM basic rate lookup table */ |
| 3686 | for (i = 0; i < rs.count; i++) { |
| 3687 | rate = rs.rates[i] & BRCMS_RATE_MASK; |
| 3688 | |
| 3689 | /* for a given rate brcms_basic_rate returns the rate at |
| 3690 | * which a response ACK/CTS should be sent. |
| 3691 | */ |
| 3692 | basic_rate = brcms_basic_rate(wlc, rate); |
| 3693 | if (basic_rate == 0) |
| 3694 | /* This should only happen if we are using a |
| 3695 | * restricted rateset. |
| 3696 | */ |
| 3697 | basic_rate = rs.rates[0] & BRCMS_RATE_MASK; |
| 3698 | |
| 3699 | brcms_c_write_rate_shm(wlc, rate, basic_rate); |
| 3700 | } |
| 3701 | } |
| 3702 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3703 | /* band-specific init */ |
| 3704 | static void brcms_c_bsinit(struct brcms_c_info *wlc) |
| 3705 | { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 3706 | brcms_dbg_info(wlc->hw->d11core, "wl%d: bandunit %d\n", |
| 3707 | wlc->pub->unit, wlc->band->bandunit); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3708 | |
| 3709 | /* write ucode ACK/CTS rate table */ |
| 3710 | brcms_c_set_ratetable(wlc); |
| 3711 | |
| 3712 | /* update some band specific mac configuration */ |
| 3713 | brcms_c_ucode_mac_upd(wlc); |
| 3714 | |
| 3715 | /* init antenna selection */ |
| 3716 | brcms_c_antsel_init(wlc->asi); |
| 3717 | |
| 3718 | } |
| 3719 | |
| 3720 | /* formula: IDLE_BUSY_RATIO_X_16 = (100-duty_cycle)/duty_cycle*16 */ |
| 3721 | static int |
| 3722 | brcms_c_duty_cycle_set(struct brcms_c_info *wlc, int duty_cycle, bool isOFDM, |
| 3723 | bool writeToShm) |
| 3724 | { |
| 3725 | int idle_busy_ratio_x_16 = 0; |
| 3726 | uint offset = |
| 3727 | isOFDM ? M_TX_IDLE_BUSY_RATIO_X_16_OFDM : |
| 3728 | M_TX_IDLE_BUSY_RATIO_X_16_CCK; |
| 3729 | if (duty_cycle > 100 || duty_cycle < 0) { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 3730 | brcms_err(wlc->hw->d11core, |
| 3731 | "wl%d: duty cycle value off limit\n", |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3732 | wlc->pub->unit); |
| 3733 | return -EINVAL; |
| 3734 | } |
| 3735 | if (duty_cycle) |
| 3736 | idle_busy_ratio_x_16 = (100 - duty_cycle) * 16 / duty_cycle; |
| 3737 | /* Only write to shared memory when wl is up */ |
| 3738 | if (writeToShm) |
| 3739 | brcms_b_write_shm(wlc->hw, offset, (u16) idle_busy_ratio_x_16); |
| 3740 | |
| 3741 | if (isOFDM) |
| 3742 | wlc->tx_duty_cycle_ofdm = (u16) duty_cycle; |
| 3743 | else |
| 3744 | wlc->tx_duty_cycle_cck = (u16) duty_cycle; |
| 3745 | |
| 3746 | return 0; |
| 3747 | } |
| 3748 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3749 | /* push sw hps and wake state through hardware */ |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 3750 | static void brcms_c_set_ps_ctrl(struct brcms_c_info *wlc) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3751 | { |
| 3752 | u32 v1, v2; |
| 3753 | bool hps; |
| 3754 | bool awake_before; |
| 3755 | |
| 3756 | hps = brcms_c_ps_allowed(wlc); |
| 3757 | |
Seth Forshee | 913911f | 2012-11-15 08:08:04 -0600 | [diff] [blame] | 3758 | brcms_dbg_mac80211(wlc->hw->d11core, "wl%d: hps %d\n", wlc->pub->unit, |
| 3759 | hps); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3760 | |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 3761 | v1 = bcma_read32(wlc->hw->d11core, D11REGOFFS(maccontrol)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3762 | v2 = MCTL_WAKE; |
| 3763 | if (hps) |
| 3764 | v2 |= MCTL_HPS; |
| 3765 | |
| 3766 | brcms_b_mctrl(wlc->hw, MCTL_WAKE | MCTL_HPS, v2); |
| 3767 | |
| 3768 | awake_before = ((v1 & MCTL_WAKE) || ((v1 & MCTL_HPS) == 0)); |
| 3769 | |
| 3770 | if (!awake_before) |
| 3771 | brcms_b_wait_for_wake(wlc->hw); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3772 | } |
| 3773 | |
| 3774 | /* |
| 3775 | * Write this BSS config's MAC address to core. |
| 3776 | * Updates RXE match engine. |
| 3777 | */ |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 3778 | static int brcms_c_set_mac(struct brcms_bss_cfg *bsscfg) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3779 | { |
| 3780 | int err = 0; |
| 3781 | struct brcms_c_info *wlc = bsscfg->wlc; |
| 3782 | |
| 3783 | /* enter the MAC addr into the RXE match registers */ |
| 3784 | brcms_c_set_addrmatch(wlc, RCM_MAC_OFFSET, bsscfg->cur_etheraddr); |
| 3785 | |
| 3786 | brcms_c_ampdu_macaddr_upd(wlc); |
| 3787 | |
| 3788 | return err; |
| 3789 | } |
| 3790 | |
| 3791 | /* Write the BSS config's BSSID address to core (set_bssid in d11procs.tcl). |
| 3792 | * Updates RXE match engine. |
| 3793 | */ |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 3794 | static void brcms_c_set_bssid(struct brcms_bss_cfg *bsscfg) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3795 | { |
| 3796 | /* we need to update BSSID in RXE match registers */ |
| 3797 | brcms_c_set_addrmatch(bsscfg->wlc, RCM_BSSID_OFFSET, bsscfg->BSSID); |
| 3798 | } |
| 3799 | |
| 3800 | static void brcms_b_set_shortslot(struct brcms_hardware *wlc_hw, bool shortslot) |
| 3801 | { |
| 3802 | wlc_hw->shortslot = shortslot; |
| 3803 | |
| 3804 | if (wlc_hw->band->bandtype == BRCM_BAND_2G && wlc_hw->up) { |
| 3805 | brcms_c_suspend_mac_and_wait(wlc_hw->wlc); |
| 3806 | brcms_b_update_slot_timing(wlc_hw, shortslot); |
| 3807 | brcms_c_enable_mac(wlc_hw->wlc); |
| 3808 | } |
| 3809 | } |
| 3810 | |
| 3811 | /* |
| 3812 | * Suspend the the MAC and update the slot timing |
| 3813 | * for standard 11b/g (20us slots) or shortslot 11g (9us slots). |
| 3814 | */ |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 3815 | static void brcms_c_switch_shortslot(struct brcms_c_info *wlc, bool shortslot) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3816 | { |
| 3817 | /* use the override if it is set */ |
| 3818 | if (wlc->shortslot_override != BRCMS_SHORTSLOT_AUTO) |
| 3819 | shortslot = (wlc->shortslot_override == BRCMS_SHORTSLOT_ON); |
| 3820 | |
| 3821 | if (wlc->shortslot == shortslot) |
| 3822 | return; |
| 3823 | |
| 3824 | wlc->shortslot = shortslot; |
| 3825 | |
| 3826 | brcms_b_set_shortslot(wlc->hw, shortslot); |
| 3827 | } |
| 3828 | |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 3829 | static void brcms_c_set_home_chanspec(struct brcms_c_info *wlc, u16 chanspec) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3830 | { |
| 3831 | if (wlc->home_chanspec != chanspec) { |
| 3832 | wlc->home_chanspec = chanspec; |
| 3833 | |
| 3834 | if (wlc->bsscfg->associated) |
| 3835 | wlc->bsscfg->current_bss->chanspec = chanspec; |
| 3836 | } |
| 3837 | } |
| 3838 | |
| 3839 | void |
| 3840 | brcms_b_set_chanspec(struct brcms_hardware *wlc_hw, u16 chanspec, |
Roland Vossen | c6c4489 | 2011-10-21 16:16:26 +0200 | [diff] [blame] | 3841 | bool mute_tx, struct txpwr_limits *txpwr) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3842 | { |
| 3843 | uint bandunit; |
| 3844 | |
Seth Forshee | 913911f | 2012-11-15 08:08:04 -0600 | [diff] [blame] | 3845 | brcms_dbg_mac80211(wlc_hw->d11core, "wl%d: 0x%x\n", wlc_hw->unit, |
| 3846 | chanspec); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3847 | |
| 3848 | wlc_hw->chanspec = chanspec; |
| 3849 | |
| 3850 | /* Switch bands if necessary */ |
| 3851 | if (wlc_hw->_nbands > 1) { |
| 3852 | bandunit = chspec_bandunit(chanspec); |
| 3853 | if (wlc_hw->band->bandunit != bandunit) { |
| 3854 | /* brcms_b_setband disables other bandunit, |
| 3855 | * use light band switch if not up yet |
| 3856 | */ |
| 3857 | if (wlc_hw->up) { |
| 3858 | wlc_phy_chanspec_radio_set(wlc_hw-> |
| 3859 | bandstate[bandunit]-> |
| 3860 | pi, chanspec); |
| 3861 | brcms_b_setband(wlc_hw, bandunit, chanspec); |
| 3862 | } else { |
| 3863 | brcms_c_setxband(wlc_hw, bandunit); |
| 3864 | } |
| 3865 | } |
| 3866 | } |
| 3867 | |
Roland Vossen | c6c4489 | 2011-10-21 16:16:26 +0200 | [diff] [blame] | 3868 | wlc_phy_initcal_enable(wlc_hw->band->pi, !mute_tx); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3869 | |
| 3870 | if (!wlc_hw->up) { |
| 3871 | if (wlc_hw->clk) |
| 3872 | wlc_phy_txpower_limit_set(wlc_hw->band->pi, txpwr, |
| 3873 | chanspec); |
| 3874 | wlc_phy_chanspec_radio_set(wlc_hw->band->pi, chanspec); |
| 3875 | } else { |
| 3876 | wlc_phy_chanspec_set(wlc_hw->band->pi, chanspec); |
| 3877 | wlc_phy_txpower_limit_set(wlc_hw->band->pi, txpwr, chanspec); |
| 3878 | |
| 3879 | /* Update muting of the channel */ |
Roland Vossen | c6c4489 | 2011-10-21 16:16:26 +0200 | [diff] [blame] | 3880 | brcms_b_mute(wlc_hw, mute_tx); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3881 | } |
| 3882 | } |
| 3883 | |
| 3884 | /* switch to and initialize new band */ |
| 3885 | static void brcms_c_setband(struct brcms_c_info *wlc, |
| 3886 | uint bandunit) |
| 3887 | { |
| 3888 | wlc->band = wlc->bandstate[bandunit]; |
| 3889 | |
| 3890 | if (!wlc->pub->up) |
| 3891 | return; |
| 3892 | |
| 3893 | /* wait for at least one beacon before entering sleeping state */ |
| 3894 | brcms_c_set_ps_ctrl(wlc); |
| 3895 | |
| 3896 | /* band-specific initializations */ |
| 3897 | brcms_c_bsinit(wlc); |
| 3898 | } |
| 3899 | |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 3900 | static void brcms_c_set_chanspec(struct brcms_c_info *wlc, u16 chanspec) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3901 | { |
| 3902 | uint bandunit; |
| 3903 | bool switchband = false; |
| 3904 | u16 old_chanspec = wlc->chanspec; |
| 3905 | |
| 3906 | if (!brcms_c_valid_chanspec_db(wlc->cmi, chanspec)) { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 3907 | brcms_err(wlc->hw->d11core, "wl%d: %s: Bad channel %d\n", |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3908 | wlc->pub->unit, __func__, CHSPEC_CHANNEL(chanspec)); |
| 3909 | return; |
| 3910 | } |
| 3911 | |
| 3912 | /* Switch bands if necessary */ |
| 3913 | if (wlc->pub->_nbands > 1) { |
| 3914 | bandunit = chspec_bandunit(chanspec); |
| 3915 | if (wlc->band->bandunit != bandunit || wlc->bandinit_pending) { |
| 3916 | switchband = true; |
| 3917 | if (wlc->bandlocked) { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 3918 | brcms_err(wlc->hw->d11core, |
| 3919 | "wl%d: %s: chspec %d band is locked!\n", |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3920 | wlc->pub->unit, __func__, |
| 3921 | CHSPEC_CHANNEL(chanspec)); |
| 3922 | return; |
| 3923 | } |
| 3924 | /* |
| 3925 | * should the setband call come after the |
| 3926 | * brcms_b_chanspec() ? if the setband updates |
| 3927 | * (brcms_c_bsinit) use low level calls to inspect and |
| 3928 | * set state, the state inspected may be from the wrong |
| 3929 | * band, or the following brcms_b_set_chanspec() may |
| 3930 | * undo the work. |
| 3931 | */ |
| 3932 | brcms_c_setband(wlc, bandunit); |
| 3933 | } |
| 3934 | } |
| 3935 | |
| 3936 | /* sync up phy/radio chanspec */ |
| 3937 | brcms_c_set_phy_chanspec(wlc, chanspec); |
| 3938 | |
| 3939 | /* init antenna selection */ |
| 3940 | if (brcms_chspec_bw(old_chanspec) != brcms_chspec_bw(chanspec)) { |
| 3941 | brcms_c_antsel_init(wlc->asi); |
| 3942 | |
| 3943 | /* Fix the hardware rateset based on bw. |
| 3944 | * Mainly add MCS32 for 40Mhz, remove MCS 32 for 20Mhz |
| 3945 | */ |
| 3946 | brcms_c_rateset_bw_mcs_filter(&wlc->band->hw_rateset, |
| 3947 | wlc->band->mimo_cap_40 ? brcms_chspec_bw(chanspec) : 0); |
| 3948 | } |
| 3949 | |
| 3950 | /* update some mac configuration since chanspec changed */ |
| 3951 | brcms_c_ucode_mac_upd(wlc); |
| 3952 | } |
| 3953 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3954 | /* |
| 3955 | * This function changes the phytxctl for beacon based on current |
| 3956 | * beacon ratespec AND txant setting as per this table: |
| 3957 | * ratespec CCK ant = wlc->stf->txant |
| 3958 | * OFDM ant = 3 |
| 3959 | */ |
| 3960 | void brcms_c_beacon_phytxctl_txant_upd(struct brcms_c_info *wlc, |
| 3961 | u32 bcn_rspec) |
| 3962 | { |
| 3963 | u16 phyctl; |
| 3964 | u16 phytxant = wlc->stf->phytxant; |
| 3965 | u16 mask = PHY_TXC_ANT_MASK; |
| 3966 | |
| 3967 | /* for non-siso rates or default setting, use the available chains */ |
| 3968 | if (BRCMS_PHY_11N_CAP(wlc->band)) |
| 3969 | phytxant = brcms_c_stf_phytxchain_sel(wlc, bcn_rspec); |
| 3970 | |
| 3971 | phyctl = brcms_b_read_shm(wlc->hw, M_BCN_PCTLWD); |
| 3972 | phyctl = (phyctl & ~mask) | phytxant; |
| 3973 | brcms_b_write_shm(wlc->hw, M_BCN_PCTLWD, phyctl); |
| 3974 | } |
| 3975 | |
| 3976 | /* |
| 3977 | * centralized protection config change function to simplify debugging, no |
| 3978 | * consistency checking this should be called only on changes to avoid overhead |
| 3979 | * in periodic function |
| 3980 | */ |
| 3981 | void brcms_c_protection_upd(struct brcms_c_info *wlc, uint idx, int val) |
| 3982 | { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 3983 | /* |
| 3984 | * Cannot use brcms_dbg_* here because this function is called |
| 3985 | * before wlc is sufficiently initialized. |
| 3986 | */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3987 | BCMMSG(wlc->wiphy, "idx %d, val %d\n", idx, val); |
| 3988 | |
| 3989 | switch (idx) { |
| 3990 | case BRCMS_PROT_G_SPEC: |
| 3991 | wlc->protection->_g = (bool) val; |
| 3992 | break; |
| 3993 | case BRCMS_PROT_G_OVR: |
| 3994 | wlc->protection->g_override = (s8) val; |
| 3995 | break; |
| 3996 | case BRCMS_PROT_G_USER: |
| 3997 | wlc->protection->gmode_user = (u8) val; |
| 3998 | break; |
| 3999 | case BRCMS_PROT_OVERLAP: |
| 4000 | wlc->protection->overlap = (s8) val; |
| 4001 | break; |
| 4002 | case BRCMS_PROT_N_USER: |
| 4003 | wlc->protection->nmode_user = (s8) val; |
| 4004 | break; |
| 4005 | case BRCMS_PROT_N_CFG: |
| 4006 | wlc->protection->n_cfg = (s8) val; |
| 4007 | break; |
| 4008 | case BRCMS_PROT_N_CFG_OVR: |
| 4009 | wlc->protection->n_cfg_override = (s8) val; |
| 4010 | break; |
| 4011 | case BRCMS_PROT_N_NONGF: |
| 4012 | wlc->protection->nongf = (bool) val; |
| 4013 | break; |
| 4014 | case BRCMS_PROT_N_NONGF_OVR: |
| 4015 | wlc->protection->nongf_override = (s8) val; |
| 4016 | break; |
| 4017 | case BRCMS_PROT_N_PAM_OVR: |
| 4018 | wlc->protection->n_pam_override = (s8) val; |
| 4019 | break; |
| 4020 | case BRCMS_PROT_N_OBSS: |
| 4021 | wlc->protection->n_obss = (bool) val; |
| 4022 | break; |
| 4023 | |
| 4024 | default: |
| 4025 | break; |
| 4026 | } |
| 4027 | |
| 4028 | } |
| 4029 | |
| 4030 | static void brcms_c_ht_update_sgi_rx(struct brcms_c_info *wlc, int val) |
| 4031 | { |
| 4032 | if (wlc->pub->up) { |
| 4033 | brcms_c_update_beacon(wlc); |
| 4034 | brcms_c_update_probe_resp(wlc, true); |
| 4035 | } |
| 4036 | } |
| 4037 | |
| 4038 | static void brcms_c_ht_update_ldpc(struct brcms_c_info *wlc, s8 val) |
| 4039 | { |
| 4040 | wlc->stf->ldpc = val; |
| 4041 | |
| 4042 | if (wlc->pub->up) { |
| 4043 | brcms_c_update_beacon(wlc); |
| 4044 | brcms_c_update_probe_resp(wlc, true); |
| 4045 | wlc_phy_ldpc_override_set(wlc->band->pi, (val ? true : false)); |
| 4046 | } |
| 4047 | } |
| 4048 | |
| 4049 | void brcms_c_wme_setparams(struct brcms_c_info *wlc, u16 aci, |
| 4050 | const struct ieee80211_tx_queue_params *params, |
| 4051 | bool suspend) |
| 4052 | { |
| 4053 | int i; |
| 4054 | struct shm_acparams acp_shm; |
| 4055 | u16 *shm_entry; |
| 4056 | |
| 4057 | /* Only apply params if the core is out of reset and has clocks */ |
| 4058 | if (!wlc->clk) { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 4059 | brcms_err(wlc->hw->d11core, "wl%d: %s : no-clock\n", |
| 4060 | wlc->pub->unit, __func__); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4061 | return; |
| 4062 | } |
| 4063 | |
| 4064 | memset((char *)&acp_shm, 0, sizeof(struct shm_acparams)); |
| 4065 | /* fill in shm ac params struct */ |
| 4066 | acp_shm.txop = params->txop; |
| 4067 | /* convert from units of 32us to us for ucode */ |
| 4068 | wlc->edcf_txop[aci & 0x3] = acp_shm.txop = |
| 4069 | EDCF_TXOP2USEC(acp_shm.txop); |
| 4070 | acp_shm.aifs = (params->aifs & EDCF_AIFSN_MASK); |
| 4071 | |
Arend van Spriel | b7eec42 | 2011-11-10 20:30:18 +0100 | [diff] [blame] | 4072 | if (aci == IEEE80211_AC_VI && acp_shm.txop == 0 |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4073 | && acp_shm.aifs < EDCF_AIFSN_MAX) |
| 4074 | acp_shm.aifs++; |
| 4075 | |
| 4076 | if (acp_shm.aifs < EDCF_AIFSN_MIN |
| 4077 | || acp_shm.aifs > EDCF_AIFSN_MAX) { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 4078 | brcms_err(wlc->hw->d11core, "wl%d: edcf_setparams: bad " |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4079 | "aifs %d\n", wlc->pub->unit, acp_shm.aifs); |
| 4080 | } else { |
| 4081 | acp_shm.cwmin = params->cw_min; |
| 4082 | acp_shm.cwmax = params->cw_max; |
| 4083 | acp_shm.cwcur = acp_shm.cwmin; |
| 4084 | acp_shm.bslots = |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 4085 | bcma_read16(wlc->hw->d11core, D11REGOFFS(tsf_random)) & |
| 4086 | acp_shm.cwcur; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4087 | acp_shm.reggap = acp_shm.bslots + acp_shm.aifs; |
| 4088 | /* Indicate the new params to the ucode */ |
| 4089 | acp_shm.status = brcms_b_read_shm(wlc->hw, (M_EDCF_QINFO + |
| 4090 | wme_ac2fifo[aci] * |
| 4091 | M_EDCF_QLEN + |
| 4092 | M_EDCF_STATUS_OFF)); |
| 4093 | acp_shm.status |= WME_STATUS_NEWAC; |
| 4094 | |
| 4095 | /* Fill in shm acparam table */ |
| 4096 | shm_entry = (u16 *) &acp_shm; |
| 4097 | for (i = 0; i < (int)sizeof(struct shm_acparams); i += 2) |
| 4098 | brcms_b_write_shm(wlc->hw, |
| 4099 | M_EDCF_QINFO + |
| 4100 | wme_ac2fifo[aci] * M_EDCF_QLEN + i, |
| 4101 | *shm_entry++); |
| 4102 | } |
| 4103 | |
| 4104 | if (suspend) { |
| 4105 | brcms_c_suspend_mac_and_wait(wlc); |
| 4106 | brcms_c_enable_mac(wlc); |
| 4107 | } |
| 4108 | } |
| 4109 | |
Arend van Spriel | 094b199 | 2011-10-18 14:03:07 +0200 | [diff] [blame] | 4110 | static void brcms_c_edcf_setparams(struct brcms_c_info *wlc, bool suspend) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4111 | { |
| 4112 | u16 aci; |
| 4113 | int i_ac; |
| 4114 | struct ieee80211_tx_queue_params txq_pars; |
| 4115 | static const struct edcf_acparam default_edcf_acparams[] = { |
| 4116 | {EDCF_AC_BE_ACI_STA, EDCF_AC_BE_ECW_STA, EDCF_AC_BE_TXOP_STA}, |
| 4117 | {EDCF_AC_BK_ACI_STA, EDCF_AC_BK_ECW_STA, EDCF_AC_BK_TXOP_STA}, |
| 4118 | {EDCF_AC_VI_ACI_STA, EDCF_AC_VI_ECW_STA, EDCF_AC_VI_TXOP_STA}, |
| 4119 | {EDCF_AC_VO_ACI_STA, EDCF_AC_VO_ECW_STA, EDCF_AC_VO_TXOP_STA} |
| 4120 | }; /* ucode needs these parameters during its initialization */ |
| 4121 | const struct edcf_acparam *edcf_acp = &default_edcf_acparams[0]; |
| 4122 | |
Arend van Spriel | b7eec42 | 2011-11-10 20:30:18 +0100 | [diff] [blame] | 4123 | for (i_ac = 0; i_ac < IEEE80211_NUM_ACS; i_ac++, edcf_acp++) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4124 | /* find out which ac this set of params applies to */ |
| 4125 | aci = (edcf_acp->ACI & EDCF_ACI_MASK) >> EDCF_ACI_SHIFT; |
| 4126 | |
| 4127 | /* fill in shm ac params struct */ |
| 4128 | txq_pars.txop = edcf_acp->TXOP; |
| 4129 | txq_pars.aifs = edcf_acp->ACI; |
| 4130 | |
| 4131 | /* CWmin = 2^(ECWmin) - 1 */ |
| 4132 | txq_pars.cw_min = EDCF_ECW2CW(edcf_acp->ECW & EDCF_ECWMIN_MASK); |
| 4133 | /* CWmax = 2^(ECWmax) - 1 */ |
| 4134 | txq_pars.cw_max = EDCF_ECW2CW((edcf_acp->ECW & EDCF_ECWMAX_MASK) |
| 4135 | >> EDCF_ECWMAX_SHIFT); |
| 4136 | brcms_c_wme_setparams(wlc, aci, &txq_pars, suspend); |
| 4137 | } |
| 4138 | |
| 4139 | if (suspend) { |
| 4140 | brcms_c_suspend_mac_and_wait(wlc); |
| 4141 | brcms_c_enable_mac(wlc); |
| 4142 | } |
| 4143 | } |
| 4144 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4145 | static void brcms_c_radio_monitor_start(struct brcms_c_info *wlc) |
| 4146 | { |
| 4147 | /* Don't start the timer if HWRADIO feature is disabled */ |
| 4148 | if (wlc->radio_monitor) |
| 4149 | return; |
| 4150 | |
| 4151 | wlc->radio_monitor = true; |
| 4152 | brcms_b_pllreq(wlc->hw, true, BRCMS_PLLREQ_RADIO_MON); |
Roland Vossen | be69c4e | 2011-10-12 20:51:11 +0200 | [diff] [blame] | 4153 | brcms_add_timer(wlc->radio_timer, TIMER_INTERVAL_RADIOCHK, true); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4154 | } |
| 4155 | |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 4156 | static bool brcms_c_radio_monitor_stop(struct brcms_c_info *wlc) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4157 | { |
| 4158 | if (!wlc->radio_monitor) |
| 4159 | return true; |
| 4160 | |
| 4161 | wlc->radio_monitor = false; |
| 4162 | brcms_b_pllreq(wlc->hw, false, BRCMS_PLLREQ_RADIO_MON); |
Roland Vossen | be69c4e | 2011-10-12 20:51:11 +0200 | [diff] [blame] | 4163 | return brcms_del_timer(wlc->radio_timer); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4164 | } |
| 4165 | |
| 4166 | /* read hwdisable state and propagate to wlc flag */ |
| 4167 | static void brcms_c_radio_hwdisable_upd(struct brcms_c_info *wlc) |
| 4168 | { |
| 4169 | if (wlc->pub->hw_off) |
| 4170 | return; |
| 4171 | |
| 4172 | if (brcms_b_radio_read_hwdisabled(wlc->hw)) |
| 4173 | mboolset(wlc->pub->radio_disabled, WL_RADIO_HW_DISABLE); |
| 4174 | else |
| 4175 | mboolclr(wlc->pub->radio_disabled, WL_RADIO_HW_DISABLE); |
| 4176 | } |
| 4177 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4178 | /* update hwradio status and return it */ |
| 4179 | bool brcms_c_check_radio_disabled(struct brcms_c_info *wlc) |
| 4180 | { |
| 4181 | brcms_c_radio_hwdisable_upd(wlc); |
| 4182 | |
| 4183 | return mboolisset(wlc->pub->radio_disabled, WL_RADIO_HW_DISABLE) ? |
| 4184 | true : false; |
| 4185 | } |
| 4186 | |
| 4187 | /* periodical query hw radio button while driver is "down" */ |
| 4188 | static void brcms_c_radio_timer(void *arg) |
| 4189 | { |
| 4190 | struct brcms_c_info *wlc = (struct brcms_c_info *) arg; |
| 4191 | |
| 4192 | if (brcms_deviceremoved(wlc)) { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 4193 | brcms_err(wlc->hw->d11core, "wl%d: %s: dead chip\n", |
| 4194 | wlc->pub->unit, __func__); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4195 | brcms_down(wlc->wl); |
| 4196 | return; |
| 4197 | } |
| 4198 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4199 | brcms_c_radio_hwdisable_upd(wlc); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4200 | } |
| 4201 | |
| 4202 | /* common low-level watchdog code */ |
Hauke Mehrtens | a5fed0c | 2012-06-30 15:16:14 +0200 | [diff] [blame] | 4203 | static void brcms_b_watchdog(struct brcms_c_info *wlc) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4204 | { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4205 | struct brcms_hardware *wlc_hw = wlc->hw; |
| 4206 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4207 | if (!wlc_hw->up) |
| 4208 | return; |
| 4209 | |
| 4210 | /* increment second count */ |
| 4211 | wlc_hw->now++; |
| 4212 | |
| 4213 | /* Check for FIFO error interrupts */ |
| 4214 | brcms_b_fifoerrors(wlc_hw); |
| 4215 | |
| 4216 | /* make sure RX dma has buffers */ |
| 4217 | dma_rxfill(wlc->hw->di[RX_FIFO]); |
| 4218 | |
| 4219 | wlc_phy_watchdog(wlc_hw->band->pi); |
| 4220 | } |
| 4221 | |
| 4222 | /* common watchdog code */ |
Hauke Mehrtens | a5fed0c | 2012-06-30 15:16:14 +0200 | [diff] [blame] | 4223 | static void brcms_c_watchdog(struct brcms_c_info *wlc) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4224 | { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 4225 | brcms_dbg_info(wlc->hw->d11core, "wl%d\n", wlc->pub->unit); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4226 | |
| 4227 | if (!wlc->pub->up) |
| 4228 | return; |
| 4229 | |
| 4230 | if (brcms_deviceremoved(wlc)) { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 4231 | brcms_err(wlc->hw->d11core, "wl%d: %s: dead chip\n", |
| 4232 | wlc->pub->unit, __func__); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4233 | brcms_down(wlc->wl); |
| 4234 | return; |
| 4235 | } |
| 4236 | |
| 4237 | /* increment second count */ |
| 4238 | wlc->pub->now++; |
| 4239 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4240 | brcms_c_radio_hwdisable_upd(wlc); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4241 | /* if radio is disable, driver may be down, quit here */ |
| 4242 | if (wlc->pub->radio_disabled) |
| 4243 | return; |
| 4244 | |
| 4245 | brcms_b_watchdog(wlc); |
| 4246 | |
| 4247 | /* |
| 4248 | * occasionally sample mac stat counters to |
| 4249 | * detect 16-bit counter wrap |
| 4250 | */ |
| 4251 | if ((wlc->pub->now % SW_TIMER_MAC_STAT_UPD) == 0) |
| 4252 | brcms_c_statsupd(wlc); |
| 4253 | |
| 4254 | if (BRCMS_ISNPHY(wlc->band) && |
| 4255 | ((wlc->pub->now - wlc->tempsense_lasttime) >= |
| 4256 | BRCMS_TEMPSENSE_PERIOD)) { |
| 4257 | wlc->tempsense_lasttime = wlc->pub->now; |
| 4258 | brcms_c_tempsense_upd(wlc); |
| 4259 | } |
| 4260 | } |
| 4261 | |
| 4262 | static void brcms_c_watchdog_by_timer(void *arg) |
| 4263 | { |
Hauke Mehrtens | a5fed0c | 2012-06-30 15:16:14 +0200 | [diff] [blame] | 4264 | struct brcms_c_info *wlc = (struct brcms_c_info *) arg; |
| 4265 | |
| 4266 | brcms_c_watchdog(wlc); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4267 | } |
| 4268 | |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 4269 | static bool brcms_c_timers_init(struct brcms_c_info *wlc, int unit) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4270 | { |
| 4271 | wlc->wdtimer = brcms_init_timer(wlc->wl, brcms_c_watchdog_by_timer, |
| 4272 | wlc, "watchdog"); |
| 4273 | if (!wlc->wdtimer) { |
| 4274 | wiphy_err(wlc->wiphy, "wl%d: wl_init_timer for wdtimer " |
| 4275 | "failed\n", unit); |
| 4276 | goto fail; |
| 4277 | } |
| 4278 | |
| 4279 | wlc->radio_timer = brcms_init_timer(wlc->wl, brcms_c_radio_timer, |
| 4280 | wlc, "radio"); |
| 4281 | if (!wlc->radio_timer) { |
| 4282 | wiphy_err(wlc->wiphy, "wl%d: wl_init_timer for radio_timer " |
| 4283 | "failed\n", unit); |
| 4284 | goto fail; |
| 4285 | } |
| 4286 | |
| 4287 | return true; |
| 4288 | |
| 4289 | fail: |
| 4290 | return false; |
| 4291 | } |
| 4292 | |
| 4293 | /* |
| 4294 | * Initialize brcms_c_info default values ... |
| 4295 | * may get overrides later in this function |
| 4296 | */ |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 4297 | static void brcms_c_info_init(struct brcms_c_info *wlc, int unit) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4298 | { |
| 4299 | int i; |
| 4300 | |
| 4301 | /* Save our copy of the chanspec */ |
| 4302 | wlc->chanspec = ch20mhz_chspec(1); |
| 4303 | |
| 4304 | /* various 802.11g modes */ |
| 4305 | wlc->shortslot = false; |
| 4306 | wlc->shortslot_override = BRCMS_SHORTSLOT_AUTO; |
| 4307 | |
| 4308 | brcms_c_protection_upd(wlc, BRCMS_PROT_G_OVR, BRCMS_PROTECTION_AUTO); |
| 4309 | brcms_c_protection_upd(wlc, BRCMS_PROT_G_SPEC, false); |
| 4310 | |
| 4311 | brcms_c_protection_upd(wlc, BRCMS_PROT_N_CFG_OVR, |
| 4312 | BRCMS_PROTECTION_AUTO); |
| 4313 | brcms_c_protection_upd(wlc, BRCMS_PROT_N_CFG, BRCMS_N_PROTECTION_OFF); |
| 4314 | brcms_c_protection_upd(wlc, BRCMS_PROT_N_NONGF_OVR, |
| 4315 | BRCMS_PROTECTION_AUTO); |
| 4316 | brcms_c_protection_upd(wlc, BRCMS_PROT_N_NONGF, false); |
| 4317 | brcms_c_protection_upd(wlc, BRCMS_PROT_N_PAM_OVR, AUTO); |
| 4318 | |
| 4319 | brcms_c_protection_upd(wlc, BRCMS_PROT_OVERLAP, |
| 4320 | BRCMS_PROTECTION_CTL_OVERLAP); |
| 4321 | |
| 4322 | /* 802.11g draft 4.0 NonERP elt advertisement */ |
| 4323 | wlc->include_legacy_erp = true; |
| 4324 | |
| 4325 | wlc->stf->ant_rx_ovr = ANT_RX_DIV_DEF; |
| 4326 | wlc->stf->txant = ANT_TX_DEF; |
| 4327 | |
| 4328 | wlc->prb_resp_timeout = BRCMS_PRB_RESP_TIMEOUT; |
| 4329 | |
| 4330 | wlc->usr_fragthresh = DOT11_DEFAULT_FRAG_LEN; |
| 4331 | for (i = 0; i < NFIFO; i++) |
| 4332 | wlc->fragthresh[i] = DOT11_DEFAULT_FRAG_LEN; |
| 4333 | wlc->RTSThresh = DOT11_DEFAULT_RTS_LEN; |
| 4334 | |
| 4335 | /* default rate fallback retry limits */ |
| 4336 | wlc->SFBL = RETRY_SHORT_FB; |
| 4337 | wlc->LFBL = RETRY_LONG_FB; |
| 4338 | |
| 4339 | /* default mac retry limits */ |
| 4340 | wlc->SRL = RETRY_SHORT_DEF; |
| 4341 | wlc->LRL = RETRY_LONG_DEF; |
| 4342 | |
| 4343 | /* WME QoS mode is Auto by default */ |
| 4344 | wlc->pub->_ampdu = AMPDU_AGG_HOST; |
| 4345 | wlc->pub->bcmerror = 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4346 | } |
| 4347 | |
| 4348 | static uint brcms_c_attach_module(struct brcms_c_info *wlc) |
| 4349 | { |
| 4350 | uint err = 0; |
| 4351 | uint unit; |
| 4352 | unit = wlc->pub->unit; |
| 4353 | |
| 4354 | wlc->asi = brcms_c_antsel_attach(wlc); |
| 4355 | if (wlc->asi == NULL) { |
| 4356 | wiphy_err(wlc->wiphy, "wl%d: attach: antsel_attach " |
| 4357 | "failed\n", unit); |
| 4358 | err = 44; |
| 4359 | goto fail; |
| 4360 | } |
| 4361 | |
| 4362 | wlc->ampdu = brcms_c_ampdu_attach(wlc); |
| 4363 | if (wlc->ampdu == NULL) { |
| 4364 | wiphy_err(wlc->wiphy, "wl%d: attach: ampdu_attach " |
| 4365 | "failed\n", unit); |
| 4366 | err = 50; |
| 4367 | goto fail; |
| 4368 | } |
| 4369 | |
| 4370 | if ((brcms_c_stf_attach(wlc) != 0)) { |
| 4371 | wiphy_err(wlc->wiphy, "wl%d: attach: stf_attach " |
| 4372 | "failed\n", unit); |
| 4373 | err = 68; |
| 4374 | goto fail; |
| 4375 | } |
| 4376 | fail: |
| 4377 | return err; |
| 4378 | } |
| 4379 | |
| 4380 | struct brcms_pub *brcms_c_pub(struct brcms_c_info *wlc) |
| 4381 | { |
| 4382 | return wlc->pub; |
| 4383 | } |
| 4384 | |
| 4385 | /* low level attach |
| 4386 | * run backplane attach, init nvram |
| 4387 | * run phy attach |
| 4388 | * initialize software state for each core and band |
| 4389 | * put the whole chip in reset(driver down state), no clock |
| 4390 | */ |
Arend van Spriel | b63337a | 2011-12-08 15:06:47 -0800 | [diff] [blame] | 4391 | static int brcms_b_attach(struct brcms_c_info *wlc, struct bcma_device *core, |
| 4392 | uint unit, bool piomode) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4393 | { |
| 4394 | struct brcms_hardware *wlc_hw; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4395 | uint err = 0; |
| 4396 | uint j; |
| 4397 | bool wme = false; |
| 4398 | struct shared_phy_params sha_params; |
| 4399 | struct wiphy *wiphy = wlc->wiphy; |
Arend van Spriel | b63337a | 2011-12-08 15:06:47 -0800 | [diff] [blame] | 4400 | struct pci_dev *pcidev = core->bus->host_pci; |
Hauke Mehrtens | 898d3c3 | 2012-04-29 02:50:25 +0200 | [diff] [blame] | 4401 | struct ssb_sprom *sprom = &core->bus->sprom; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4402 | |
Hauke Mehrtens | a06f210 | 2012-04-29 02:50:42 +0200 | [diff] [blame] | 4403 | if (core->bus->hosttype == BCMA_HOSTTYPE_PCI) |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 4404 | brcms_dbg_info(core, "wl%d: vendor 0x%x device 0x%x\n", unit, |
| 4405 | pcidev->vendor, |
| 4406 | pcidev->device); |
Hauke Mehrtens | a06f210 | 2012-04-29 02:50:42 +0200 | [diff] [blame] | 4407 | else |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 4408 | brcms_dbg_info(core, "wl%d: vendor 0x%x device 0x%x\n", unit, |
| 4409 | core->bus->boardinfo.vendor, |
| 4410 | core->bus->boardinfo.type); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4411 | |
| 4412 | wme = true; |
| 4413 | |
| 4414 | wlc_hw = wlc->hw; |
| 4415 | wlc_hw->wlc = wlc; |
| 4416 | wlc_hw->unit = unit; |
| 4417 | wlc_hw->band = wlc_hw->bandstate[0]; |
| 4418 | wlc_hw->_piomode = piomode; |
| 4419 | |
| 4420 | /* populate struct brcms_hardware with default values */ |
| 4421 | brcms_b_info_init(wlc_hw); |
| 4422 | |
| 4423 | /* |
| 4424 | * Do the hardware portion of the attach. Also initialize software |
| 4425 | * state that depends on the particular hardware we are running. |
| 4426 | */ |
Arend van Spriel | 28a5344 | 2011-12-08 15:06:49 -0800 | [diff] [blame] | 4427 | wlc_hw->sih = ai_attach(core->bus); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4428 | if (wlc_hw->sih == NULL) { |
| 4429 | wiphy_err(wiphy, "wl%d: brcms_b_attach: si_attach failed\n", |
| 4430 | unit); |
| 4431 | err = 11; |
| 4432 | goto fail; |
| 4433 | } |
| 4434 | |
| 4435 | /* verify again the device is supported */ |
Hauke Mehrtens | cacaa64 | 2012-06-30 15:16:19 +0200 | [diff] [blame] | 4436 | if (!brcms_c_chipmatch(core)) { |
| 4437 | wiphy_err(wiphy, "wl%d: brcms_b_attach: Unsupported device\n", |
| 4438 | unit); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4439 | err = 12; |
| 4440 | goto fail; |
| 4441 | } |
| 4442 | |
Hauke Mehrtens | a06f210 | 2012-04-29 02:50:42 +0200 | [diff] [blame] | 4443 | if (core->bus->hosttype == BCMA_HOSTTYPE_PCI) { |
| 4444 | wlc_hw->vendorid = pcidev->vendor; |
| 4445 | wlc_hw->deviceid = pcidev->device; |
| 4446 | } else { |
| 4447 | wlc_hw->vendorid = core->bus->boardinfo.vendor; |
| 4448 | wlc_hw->deviceid = core->bus->boardinfo.type; |
| 4449 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4450 | |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 4451 | wlc_hw->d11core = core; |
| 4452 | wlc_hw->corerev = core->id.rev; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4453 | |
| 4454 | /* validate chip, chiprev and corerev */ |
| 4455 | if (!brcms_c_isgoodchip(wlc_hw)) { |
| 4456 | err = 13; |
| 4457 | goto fail; |
| 4458 | } |
| 4459 | |
| 4460 | /* initialize power control registers */ |
| 4461 | ai_clkctl_init(wlc_hw->sih); |
| 4462 | |
| 4463 | /* request fastclock and force fastclock for the rest of attach |
| 4464 | * bring the d11 core out of reset. |
| 4465 | * For PMU chips, the first wlc_clkctl_clk is no-op since core-clk |
| 4466 | * is still false; But it will be called again inside wlc_corereset, |
| 4467 | * after d11 is out of reset. |
| 4468 | */ |
Hauke Mehrtens | 712e3c1 | 2012-04-29 02:50:35 +0200 | [diff] [blame] | 4469 | brcms_b_clkctl_clk(wlc_hw, BCMA_CLKMODE_FAST); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4470 | brcms_b_corereset(wlc_hw, BRCMS_USE_COREFLAGS); |
| 4471 | |
| 4472 | if (!brcms_b_validate_chip_access(wlc_hw)) { |
| 4473 | wiphy_err(wiphy, "wl%d: brcms_b_attach: validate_chip_access " |
| 4474 | "failed\n", unit); |
| 4475 | err = 14; |
| 4476 | goto fail; |
| 4477 | } |
| 4478 | |
| 4479 | /* get the board rev, used just below */ |
Hauke Mehrtens | 898d3c3 | 2012-04-29 02:50:25 +0200 | [diff] [blame] | 4480 | j = sprom->board_rev; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4481 | /* promote srom boardrev of 0xFF to 1 */ |
| 4482 | if (j == BOARDREV_PROMOTABLE) |
| 4483 | j = BOARDREV_PROMOTED; |
| 4484 | wlc_hw->boardrev = (u16) j; |
| 4485 | if (!brcms_c_validboardtype(wlc_hw)) { |
| 4486 | wiphy_err(wiphy, "wl%d: brcms_b_attach: Unsupported Broadcom " |
Arend van Spriel | b2ffec4 | 2011-12-08 15:06:45 -0800 | [diff] [blame] | 4487 | "board type (0x%x)" " or revision level (0x%x)\n", |
| 4488 | unit, ai_get_boardtype(wlc_hw->sih), |
| 4489 | wlc_hw->boardrev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4490 | err = 15; |
| 4491 | goto fail; |
| 4492 | } |
Hauke Mehrtens | 898d3c3 | 2012-04-29 02:50:25 +0200 | [diff] [blame] | 4493 | wlc_hw->sromrev = sprom->revision; |
| 4494 | wlc_hw->boardflags = sprom->boardflags_lo + (sprom->boardflags_hi << 16); |
| 4495 | wlc_hw->boardflags2 = sprom->boardflags2_lo + (sprom->boardflags2_hi << 16); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4496 | |
| 4497 | if (wlc_hw->boardflags & BFL_NOPLLDOWN) |
| 4498 | brcms_b_pllreq(wlc_hw, true, BRCMS_PLLREQ_SHARED); |
| 4499 | |
| 4500 | /* check device id(srom, nvram etc.) to set bands */ |
| 4501 | if (wlc_hw->deviceid == BCM43224_D11N_ID || |
Hauke Mehrtens | 9dd4ea5 | 2012-12-07 17:10:03 +0100 | [diff] [blame] | 4502 | wlc_hw->deviceid == BCM43224_D11N_ID_VEN1 || |
| 4503 | wlc_hw->deviceid == BCM43224_CHIP_ID) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4504 | /* Dualband boards */ |
| 4505 | wlc_hw->_nbands = 2; |
| 4506 | else |
| 4507 | wlc_hw->_nbands = 1; |
| 4508 | |
Hauke Mehrtens | 1ef1a57 | 2012-06-30 15:16:13 +0200 | [diff] [blame] | 4509 | if ((ai_get_chip_id(wlc_hw->sih) == BCMA_CHIP_ID_BCM43225)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4510 | wlc_hw->_nbands = 1; |
| 4511 | |
| 4512 | /* BMAC_NOTE: remove init of pub values when brcms_c_attach() |
| 4513 | * unconditionally does the init of these values |
| 4514 | */ |
| 4515 | wlc->vendorid = wlc_hw->vendorid; |
| 4516 | wlc->deviceid = wlc_hw->deviceid; |
| 4517 | wlc->pub->sih = wlc_hw->sih; |
| 4518 | wlc->pub->corerev = wlc_hw->corerev; |
| 4519 | wlc->pub->sromrev = wlc_hw->sromrev; |
| 4520 | wlc->pub->boardrev = wlc_hw->boardrev; |
| 4521 | wlc->pub->boardflags = wlc_hw->boardflags; |
| 4522 | wlc->pub->boardflags2 = wlc_hw->boardflags2; |
| 4523 | wlc->pub->_nbands = wlc_hw->_nbands; |
| 4524 | |
| 4525 | wlc_hw->physhim = wlc_phy_shim_attach(wlc_hw, wlc->wl, wlc); |
| 4526 | |
| 4527 | if (wlc_hw->physhim == NULL) { |
| 4528 | wiphy_err(wiphy, "wl%d: brcms_b_attach: wlc_phy_shim_attach " |
| 4529 | "failed\n", unit); |
| 4530 | err = 25; |
| 4531 | goto fail; |
| 4532 | } |
| 4533 | |
| 4534 | /* pass all the parameters to wlc_phy_shared_attach in one struct */ |
| 4535 | sha_params.sih = wlc_hw->sih; |
| 4536 | sha_params.physhim = wlc_hw->physhim; |
| 4537 | sha_params.unit = unit; |
| 4538 | sha_params.corerev = wlc_hw->corerev; |
| 4539 | sha_params.vid = wlc_hw->vendorid; |
| 4540 | sha_params.did = wlc_hw->deviceid; |
Arend van Spriel | b2ffec4 | 2011-12-08 15:06:45 -0800 | [diff] [blame] | 4541 | sha_params.chip = ai_get_chip_id(wlc_hw->sih); |
| 4542 | sha_params.chiprev = ai_get_chiprev(wlc_hw->sih); |
| 4543 | sha_params.chippkg = ai_get_chippkg(wlc_hw->sih); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4544 | sha_params.sromrev = wlc_hw->sromrev; |
Arend van Spriel | b2ffec4 | 2011-12-08 15:06:45 -0800 | [diff] [blame] | 4545 | sha_params.boardtype = ai_get_boardtype(wlc_hw->sih); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4546 | sha_params.boardrev = wlc_hw->boardrev; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4547 | sha_params.boardflags = wlc_hw->boardflags; |
| 4548 | sha_params.boardflags2 = wlc_hw->boardflags2; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4549 | |
| 4550 | /* alloc and save pointer to shared phy state area */ |
| 4551 | wlc_hw->phy_sh = wlc_phy_shared_attach(&sha_params); |
| 4552 | if (!wlc_hw->phy_sh) { |
| 4553 | err = 16; |
| 4554 | goto fail; |
| 4555 | } |
| 4556 | |
| 4557 | /* initialize software state for each core and band */ |
| 4558 | for (j = 0; j < wlc_hw->_nbands; j++) { |
| 4559 | /* |
| 4560 | * band0 is always 2.4Ghz |
| 4561 | * band1, if present, is 5Ghz |
| 4562 | */ |
| 4563 | |
| 4564 | brcms_c_setxband(wlc_hw, j); |
| 4565 | |
| 4566 | wlc_hw->band->bandunit = j; |
| 4567 | wlc_hw->band->bandtype = j ? BRCM_BAND_5G : BRCM_BAND_2G; |
| 4568 | wlc->band->bandunit = j; |
| 4569 | wlc->band->bandtype = j ? BRCM_BAND_5G : BRCM_BAND_2G; |
Arend van Spriel | 3b758a6 | 2011-12-12 15:15:09 -0800 | [diff] [blame] | 4570 | wlc->core->coreidx = core->core_index; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4571 | |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 4572 | wlc_hw->machwcap = bcma_read32(core, D11REGOFFS(machwcap)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4573 | wlc_hw->machwcap_backup = wlc_hw->machwcap; |
| 4574 | |
| 4575 | /* init tx fifo size */ |
Hauke Mehrtens | 093cd33 | 2012-07-02 20:15:51 +0200 | [diff] [blame] | 4576 | WARN_ON((wlc_hw->corerev - XMTFIFOTBL_STARTREV) < 0 || |
| 4577 | (wlc_hw->corerev - XMTFIFOTBL_STARTREV) > |
| 4578 | ARRAY_SIZE(xmtfifo_sz)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4579 | wlc_hw->xmtfifo_sz = |
| 4580 | xmtfifo_sz[(wlc_hw->corerev - XMTFIFOTBL_STARTREV)]; |
Hauke Mehrtens | 093cd33 | 2012-07-02 20:15:51 +0200 | [diff] [blame] | 4581 | WARN_ON(!wlc_hw->xmtfifo_sz[0]); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4582 | |
| 4583 | /* Get a phy for this band */ |
| 4584 | wlc_hw->band->pi = |
Arend van Spriel | 4b006b1 | 2011-12-08 15:06:54 -0800 | [diff] [blame] | 4585 | wlc_phy_attach(wlc_hw->phy_sh, core, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4586 | wlc_hw->band->bandtype, |
| 4587 | wlc->wiphy); |
| 4588 | if (wlc_hw->band->pi == NULL) { |
| 4589 | wiphy_err(wiphy, "wl%d: brcms_b_attach: wlc_phy_" |
| 4590 | "attach failed\n", unit); |
| 4591 | err = 17; |
| 4592 | goto fail; |
| 4593 | } |
| 4594 | |
| 4595 | wlc_phy_machwcap_set(wlc_hw->band->pi, wlc_hw->machwcap); |
| 4596 | |
| 4597 | wlc_phy_get_phyversion(wlc_hw->band->pi, &wlc_hw->band->phytype, |
| 4598 | &wlc_hw->band->phyrev, |
| 4599 | &wlc_hw->band->radioid, |
| 4600 | &wlc_hw->band->radiorev); |
| 4601 | wlc_hw->band->abgphy_encore = |
| 4602 | wlc_phy_get_encore(wlc_hw->band->pi); |
| 4603 | wlc->band->abgphy_encore = wlc_phy_get_encore(wlc_hw->band->pi); |
| 4604 | wlc_hw->band->core_flags = |
| 4605 | wlc_phy_get_coreflags(wlc_hw->band->pi); |
| 4606 | |
| 4607 | /* verify good phy_type & supported phy revision */ |
| 4608 | if (BRCMS_ISNPHY(wlc_hw->band)) { |
| 4609 | if (NCONF_HAS(wlc_hw->band->phyrev)) |
| 4610 | goto good_phy; |
| 4611 | else |
| 4612 | goto bad_phy; |
| 4613 | } else if (BRCMS_ISLCNPHY(wlc_hw->band)) { |
| 4614 | if (LCNCONF_HAS(wlc_hw->band->phyrev)) |
| 4615 | goto good_phy; |
| 4616 | else |
| 4617 | goto bad_phy; |
| 4618 | } else { |
| 4619 | bad_phy: |
| 4620 | wiphy_err(wiphy, "wl%d: brcms_b_attach: unsupported " |
| 4621 | "phy type/rev (%d/%d)\n", unit, |
| 4622 | wlc_hw->band->phytype, wlc_hw->band->phyrev); |
| 4623 | err = 18; |
| 4624 | goto fail; |
| 4625 | } |
| 4626 | |
| 4627 | good_phy: |
| 4628 | /* |
| 4629 | * BMAC_NOTE: wlc->band->pi should not be set below and should |
| 4630 | * be done in the high level attach. However we can not make |
| 4631 | * that change until all low level access is changed to |
| 4632 | * wlc_hw->band->pi. Instead do the wlc->band->pi init below, |
| 4633 | * keeping wlc_hw->band->pi as well for incremental update of |
| 4634 | * low level fns, and cut over low only init when all fns |
| 4635 | * updated. |
| 4636 | */ |
| 4637 | wlc->band->pi = wlc_hw->band->pi; |
| 4638 | wlc->band->phytype = wlc_hw->band->phytype; |
| 4639 | wlc->band->phyrev = wlc_hw->band->phyrev; |
| 4640 | wlc->band->radioid = wlc_hw->band->radioid; |
| 4641 | wlc->band->radiorev = wlc_hw->band->radiorev; |
| 4642 | |
| 4643 | /* default contention windows size limits */ |
| 4644 | wlc_hw->band->CWmin = APHY_CWMIN; |
| 4645 | wlc_hw->band->CWmax = PHY_CWMAX; |
| 4646 | |
| 4647 | if (!brcms_b_attach_dmapio(wlc, j, wme)) { |
| 4648 | err = 19; |
| 4649 | goto fail; |
| 4650 | } |
| 4651 | } |
| 4652 | |
| 4653 | /* disable core to match driver "down" state */ |
| 4654 | brcms_c_coredisable(wlc_hw); |
| 4655 | |
| 4656 | /* Match driver "down" state */ |
| 4657 | ai_pci_down(wlc_hw->sih); |
| 4658 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4659 | /* turn off pll and xtal to match driver "down" state */ |
| 4660 | brcms_b_xtal(wlc_hw, OFF); |
| 4661 | |
| 4662 | /* ******************************************************************* |
| 4663 | * The hardware is in the DOWN state at this point. D11 core |
| 4664 | * or cores are in reset with clocks off, and the board PLLs |
| 4665 | * are off if possible. |
| 4666 | * |
| 4667 | * Beyond this point, wlc->sbclk == false and chip registers |
| 4668 | * should not be touched. |
| 4669 | ********************************************************************* |
| 4670 | */ |
| 4671 | |
| 4672 | /* init etheraddr state variables */ |
Hauke Mehrtens | 898d3c3 | 2012-04-29 02:50:25 +0200 | [diff] [blame] | 4673 | brcms_c_get_macaddr(wlc_hw, wlc_hw->etheraddr); |
| 4674 | |
| 4675 | if (is_broadcast_ether_addr(wlc_hw->etheraddr) || |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4676 | is_zero_ether_addr(wlc_hw->etheraddr)) { |
Hauke Mehrtens | 898d3c3 | 2012-04-29 02:50:25 +0200 | [diff] [blame] | 4677 | wiphy_err(wiphy, "wl%d: brcms_b_attach: bad macaddr\n", |
| 4678 | unit); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4679 | err = 22; |
| 4680 | goto fail; |
| 4681 | } |
| 4682 | |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 4683 | brcms_dbg_info(wlc_hw->d11core, "deviceid 0x%x nbands %d board 0x%x\n", |
| 4684 | wlc_hw->deviceid, wlc_hw->_nbands, |
| 4685 | ai_get_boardtype(wlc_hw->sih)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4686 | |
| 4687 | return err; |
| 4688 | |
| 4689 | fail: |
| 4690 | wiphy_err(wiphy, "wl%d: brcms_b_attach: failed with err %d\n", unit, |
| 4691 | err); |
| 4692 | return err; |
| 4693 | } |
| 4694 | |
| 4695 | static void brcms_c_attach_antgain_init(struct brcms_c_info *wlc) |
| 4696 | { |
| 4697 | uint unit; |
| 4698 | unit = wlc->pub->unit; |
| 4699 | |
| 4700 | if ((wlc->band->antgain == -1) && (wlc->pub->sromrev == 1)) { |
| 4701 | /* default antenna gain for srom rev 1 is 2 dBm (8 qdbm) */ |
| 4702 | wlc->band->antgain = 8; |
| 4703 | } else if (wlc->band->antgain == -1) { |
| 4704 | wiphy_err(wlc->wiphy, "wl%d: %s: Invalid antennas available in" |
| 4705 | " srom, using 2dB\n", unit, __func__); |
| 4706 | wlc->band->antgain = 8; |
| 4707 | } else { |
| 4708 | s8 gain, fract; |
| 4709 | /* Older sroms specified gain in whole dbm only. In order |
| 4710 | * be able to specify qdbm granularity and remain backward |
| 4711 | * compatible the whole dbms are now encoded in only |
| 4712 | * low 6 bits and remaining qdbms are encoded in the hi 2 bits. |
| 4713 | * 6 bit signed number ranges from -32 - 31. |
| 4714 | * |
| 4715 | * Examples: |
| 4716 | * 0x1 = 1 db, |
| 4717 | * 0xc1 = 1.75 db (1 + 3 quarters), |
| 4718 | * 0x3f = -1 (-1 + 0 quarters), |
| 4719 | * 0x7f = -.75 (-1 + 1 quarters) = -3 qdbm. |
| 4720 | * 0xbf = -.50 (-1 + 2 quarters) = -2 qdbm. |
| 4721 | */ |
| 4722 | gain = wlc->band->antgain & 0x3f; |
| 4723 | gain <<= 2; /* Sign extend */ |
| 4724 | gain >>= 2; |
| 4725 | fract = (wlc->band->antgain & 0xc0) >> 6; |
| 4726 | wlc->band->antgain = 4 * gain + fract; |
| 4727 | } |
| 4728 | } |
| 4729 | |
| 4730 | static bool brcms_c_attach_stf_ant_init(struct brcms_c_info *wlc) |
| 4731 | { |
| 4732 | int aa; |
| 4733 | uint unit; |
| 4734 | int bandtype; |
Hauke Mehrtens | 898d3c3 | 2012-04-29 02:50:25 +0200 | [diff] [blame] | 4735 | struct ssb_sprom *sprom = &wlc->hw->d11core->bus->sprom; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4736 | |
| 4737 | unit = wlc->pub->unit; |
| 4738 | bandtype = wlc->band->bandtype; |
| 4739 | |
| 4740 | /* get antennas available */ |
| 4741 | if (bandtype == BRCM_BAND_5G) |
Hauke Mehrtens | 898d3c3 | 2012-04-29 02:50:25 +0200 | [diff] [blame] | 4742 | aa = sprom->ant_available_a; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4743 | else |
Hauke Mehrtens | 898d3c3 | 2012-04-29 02:50:25 +0200 | [diff] [blame] | 4744 | aa = sprom->ant_available_bg; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4745 | |
| 4746 | if ((aa < 1) || (aa > 15)) { |
| 4747 | wiphy_err(wlc->wiphy, "wl%d: %s: Invalid antennas available in" |
| 4748 | " srom (0x%x), using 3\n", unit, __func__, aa); |
| 4749 | aa = 3; |
| 4750 | } |
| 4751 | |
| 4752 | /* reset the defaults if we have a single antenna */ |
| 4753 | if (aa == 1) { |
| 4754 | wlc->stf->ant_rx_ovr = ANT_RX_DIV_FORCE_0; |
| 4755 | wlc->stf->txant = ANT_TX_FORCE_0; |
| 4756 | } else if (aa == 2) { |
| 4757 | wlc->stf->ant_rx_ovr = ANT_RX_DIV_FORCE_1; |
| 4758 | wlc->stf->txant = ANT_TX_FORCE_1; |
| 4759 | } else { |
| 4760 | } |
| 4761 | |
| 4762 | /* Compute Antenna Gain */ |
| 4763 | if (bandtype == BRCM_BAND_5G) |
Hauke Mehrtens | 898d3c3 | 2012-04-29 02:50:25 +0200 | [diff] [blame] | 4764 | wlc->band->antgain = sprom->antenna_gain.a1; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4765 | else |
Hauke Mehrtens | 898d3c3 | 2012-04-29 02:50:25 +0200 | [diff] [blame] | 4766 | wlc->band->antgain = sprom->antenna_gain.a0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4767 | |
| 4768 | brcms_c_attach_antgain_init(wlc); |
| 4769 | |
| 4770 | return true; |
| 4771 | } |
| 4772 | |
| 4773 | static void brcms_c_bss_default_init(struct brcms_c_info *wlc) |
| 4774 | { |
| 4775 | u16 chanspec; |
| 4776 | struct brcms_band *band; |
| 4777 | struct brcms_bss_info *bi = wlc->default_bss; |
| 4778 | |
| 4779 | /* init default and target BSS with some sane initial values */ |
| 4780 | memset((char *)(bi), 0, sizeof(struct brcms_bss_info)); |
| 4781 | bi->beacon_period = BEACON_INTERVAL_DEFAULT; |
| 4782 | |
| 4783 | /* fill the default channel as the first valid channel |
| 4784 | * starting from the 2G channels |
| 4785 | */ |
| 4786 | chanspec = ch20mhz_chspec(1); |
| 4787 | wlc->home_chanspec = bi->chanspec = chanspec; |
| 4788 | |
| 4789 | /* find the band of our default channel */ |
| 4790 | band = wlc->band; |
| 4791 | if (wlc->pub->_nbands > 1 && |
| 4792 | band->bandunit != chspec_bandunit(chanspec)) |
| 4793 | band = wlc->bandstate[OTHERBANDUNIT(wlc)]; |
| 4794 | |
| 4795 | /* init bss rates to the band specific default rate set */ |
| 4796 | brcms_c_rateset_default(&bi->rateset, NULL, band->phytype, |
| 4797 | band->bandtype, false, BRCMS_RATE_MASK_FULL, |
| 4798 | (bool) (wlc->pub->_n_enab & SUPPORT_11N), |
| 4799 | brcms_chspec_bw(chanspec), wlc->stf->txstreams); |
| 4800 | |
| 4801 | if (wlc->pub->_n_enab & SUPPORT_11N) |
| 4802 | bi->flags |= BRCMS_BSS_HT; |
| 4803 | } |
| 4804 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4805 | static void brcms_c_update_mimo_band_bwcap(struct brcms_c_info *wlc, u8 bwcap) |
| 4806 | { |
| 4807 | uint i; |
| 4808 | struct brcms_band *band; |
| 4809 | |
| 4810 | for (i = 0; i < wlc->pub->_nbands; i++) { |
| 4811 | band = wlc->bandstate[i]; |
| 4812 | if (band->bandtype == BRCM_BAND_5G) { |
| 4813 | if ((bwcap == BRCMS_N_BW_40ALL) |
| 4814 | || (bwcap == BRCMS_N_BW_20IN2G_40IN5G)) |
| 4815 | band->mimo_cap_40 = true; |
| 4816 | else |
| 4817 | band->mimo_cap_40 = false; |
| 4818 | } else { |
| 4819 | if (bwcap == BRCMS_N_BW_40ALL) |
| 4820 | band->mimo_cap_40 = true; |
| 4821 | else |
| 4822 | band->mimo_cap_40 = false; |
| 4823 | } |
| 4824 | } |
| 4825 | } |
| 4826 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4827 | static void brcms_c_timers_deinit(struct brcms_c_info *wlc) |
| 4828 | { |
| 4829 | /* free timer state */ |
| 4830 | if (wlc->wdtimer) { |
Roland Vossen | be69c4e | 2011-10-12 20:51:11 +0200 | [diff] [blame] | 4831 | brcms_free_timer(wlc->wdtimer); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4832 | wlc->wdtimer = NULL; |
| 4833 | } |
| 4834 | if (wlc->radio_timer) { |
Roland Vossen | be69c4e | 2011-10-12 20:51:11 +0200 | [diff] [blame] | 4835 | brcms_free_timer(wlc->radio_timer); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4836 | wlc->radio_timer = NULL; |
| 4837 | } |
| 4838 | } |
| 4839 | |
| 4840 | static void brcms_c_detach_module(struct brcms_c_info *wlc) |
| 4841 | { |
| 4842 | if (wlc->asi) { |
| 4843 | brcms_c_antsel_detach(wlc->asi); |
| 4844 | wlc->asi = NULL; |
| 4845 | } |
| 4846 | |
| 4847 | if (wlc->ampdu) { |
| 4848 | brcms_c_ampdu_detach(wlc->ampdu); |
| 4849 | wlc->ampdu = NULL; |
| 4850 | } |
| 4851 | |
| 4852 | brcms_c_stf_detach(wlc); |
| 4853 | } |
| 4854 | |
| 4855 | /* |
| 4856 | * low level detach |
| 4857 | */ |
| 4858 | static int brcms_b_detach(struct brcms_c_info *wlc) |
| 4859 | { |
| 4860 | uint i; |
| 4861 | struct brcms_hw_band *band; |
| 4862 | struct brcms_hardware *wlc_hw = wlc->hw; |
| 4863 | int callbacks; |
| 4864 | |
| 4865 | callbacks = 0; |
| 4866 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4867 | brcms_b_detach_dmapio(wlc_hw); |
| 4868 | |
| 4869 | band = wlc_hw->band; |
| 4870 | for (i = 0; i < wlc_hw->_nbands; i++) { |
| 4871 | if (band->pi) { |
| 4872 | /* Detach this band's phy */ |
| 4873 | wlc_phy_detach(band->pi); |
| 4874 | band->pi = NULL; |
| 4875 | } |
| 4876 | band = wlc_hw->bandstate[OTHERBANDUNIT(wlc)]; |
| 4877 | } |
| 4878 | |
| 4879 | /* Free shared phy state */ |
| 4880 | kfree(wlc_hw->phy_sh); |
| 4881 | |
| 4882 | wlc_phy_shim_detach(wlc_hw->physhim); |
| 4883 | |
| 4884 | if (wlc_hw->sih) { |
| 4885 | ai_detach(wlc_hw->sih); |
| 4886 | wlc_hw->sih = NULL; |
| 4887 | } |
| 4888 | |
| 4889 | return callbacks; |
| 4890 | |
| 4891 | } |
| 4892 | |
| 4893 | /* |
| 4894 | * Return a count of the number of driver callbacks still pending. |
| 4895 | * |
| 4896 | * General policy is that brcms_c_detach can only dealloc/free software states. |
| 4897 | * It can NOT touch hardware registers since the d11core may be in reset and |
| 4898 | * clock may not be available. |
| 4899 | * One exception is sb register access, which is possible if crystal is turned |
| 4900 | * on after "down" state, driver should avoid software timer with the exception |
| 4901 | * of radio_monitor. |
| 4902 | */ |
| 4903 | uint brcms_c_detach(struct brcms_c_info *wlc) |
| 4904 | { |
| 4905 | uint callbacks = 0; |
| 4906 | |
| 4907 | if (wlc == NULL) |
| 4908 | return 0; |
| 4909 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4910 | callbacks += brcms_b_detach(wlc); |
| 4911 | |
| 4912 | /* delete software timers */ |
| 4913 | if (!brcms_c_radio_monitor_stop(wlc)) |
| 4914 | callbacks++; |
| 4915 | |
| 4916 | brcms_c_channel_mgr_detach(wlc->cmi); |
| 4917 | |
| 4918 | brcms_c_timers_deinit(wlc); |
| 4919 | |
| 4920 | brcms_c_detach_module(wlc); |
| 4921 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4922 | brcms_c_detach_mfree(wlc); |
| 4923 | return callbacks; |
| 4924 | } |
| 4925 | |
| 4926 | /* update state that depends on the current value of "ap" */ |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 4927 | static void brcms_c_ap_upd(struct brcms_c_info *wlc) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4928 | { |
| 4929 | /* STA-BSS; short capable */ |
| 4930 | wlc->PLCPHdr_override = BRCMS_PLCP_SHORT; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4931 | } |
| 4932 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4933 | /* Initialize just the hardware when coming out of POR or S3/S5 system states */ |
| 4934 | static void brcms_b_hw_up(struct brcms_hardware *wlc_hw) |
| 4935 | { |
| 4936 | if (wlc_hw->wlc->pub->hw_up) |
| 4937 | return; |
| 4938 | |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 4939 | brcms_dbg_info(wlc_hw->d11core, "wl%d\n", wlc_hw->unit); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4940 | |
| 4941 | /* |
| 4942 | * Enable pll and xtal, initialize the power control registers, |
| 4943 | * and force fastclock for the remainder of brcms_c_up(). |
| 4944 | */ |
| 4945 | brcms_b_xtal(wlc_hw, ON); |
| 4946 | ai_clkctl_init(wlc_hw->sih); |
Hauke Mehrtens | 712e3c1 | 2012-04-29 02:50:35 +0200 | [diff] [blame] | 4947 | brcms_b_clkctl_clk(wlc_hw, BCMA_CLKMODE_FAST); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4948 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4949 | /* |
Arend van Spriel | 3b758a6 | 2011-12-12 15:15:09 -0800 | [diff] [blame] | 4950 | * TODO: test suspend/resume |
| 4951 | * |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4952 | * AI chip doesn't restore bar0win2 on |
| 4953 | * hibernation/resume, need sw fixup |
| 4954 | */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4955 | |
| 4956 | /* |
| 4957 | * Inform phy that a POR reset has occurred so |
| 4958 | * it does a complete phy init |
| 4959 | */ |
| 4960 | wlc_phy_por_inform(wlc_hw->band->pi); |
| 4961 | |
| 4962 | wlc_hw->ucode_loaded = false; |
| 4963 | wlc_hw->wlc->pub->hw_up = true; |
| 4964 | |
| 4965 | if ((wlc_hw->boardflags & BFL_FEM) |
Hauke Mehrtens | 1ef1a57 | 2012-06-30 15:16:13 +0200 | [diff] [blame] | 4966 | && (ai_get_chip_id(wlc_hw->sih) == BCMA_CHIP_ID_BCM4313)) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4967 | if (! |
| 4968 | (wlc_hw->boardrev >= 0x1250 |
| 4969 | && (wlc_hw->boardflags & BFL_FEM_BT))) |
| 4970 | ai_epa_4313war(wlc_hw->sih); |
| 4971 | } |
| 4972 | } |
| 4973 | |
| 4974 | static int brcms_b_up_prep(struct brcms_hardware *wlc_hw) |
| 4975 | { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 4976 | brcms_dbg_info(wlc_hw->d11core, "wl%d\n", wlc_hw->unit); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4977 | |
| 4978 | /* |
| 4979 | * Enable pll and xtal, initialize the power control registers, |
| 4980 | * and force fastclock for the remainder of brcms_c_up(). |
| 4981 | */ |
| 4982 | brcms_b_xtal(wlc_hw, ON); |
| 4983 | ai_clkctl_init(wlc_hw->sih); |
Hauke Mehrtens | 712e3c1 | 2012-04-29 02:50:35 +0200 | [diff] [blame] | 4984 | brcms_b_clkctl_clk(wlc_hw, BCMA_CLKMODE_FAST); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4985 | |
| 4986 | /* |
| 4987 | * Configure pci/pcmcia here instead of in brcms_c_attach() |
| 4988 | * to allow mfg hotswap: down, hotswap (chip power cycle), up. |
| 4989 | */ |
Hauke Mehrtens | dfae714 | 2012-09-29 20:40:18 +0200 | [diff] [blame] | 4990 | bcma_core_pci_irq_ctl(&wlc_hw->d11core->bus->drv_pci[0], wlc_hw->d11core, |
Hauke Mehrtens | b30ee75 | 2012-04-29 02:50:32 +0200 | [diff] [blame] | 4991 | true); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4992 | |
| 4993 | /* |
| 4994 | * Need to read the hwradio status here to cover the case where the |
| 4995 | * system is loaded with the hw radio disabled. We do not want to |
| 4996 | * bring the driver up in this case. |
| 4997 | */ |
| 4998 | if (brcms_b_radio_read_hwdisabled(wlc_hw)) { |
| 4999 | /* put SB PCI in down state again */ |
| 5000 | ai_pci_down(wlc_hw->sih); |
| 5001 | brcms_b_xtal(wlc_hw, OFF); |
| 5002 | return -ENOMEDIUM; |
| 5003 | } |
| 5004 | |
| 5005 | ai_pci_up(wlc_hw->sih); |
| 5006 | |
| 5007 | /* reset the d11 core */ |
| 5008 | brcms_b_corereset(wlc_hw, BRCMS_USE_COREFLAGS); |
| 5009 | |
| 5010 | return 0; |
| 5011 | } |
| 5012 | |
| 5013 | static int brcms_b_up_finish(struct brcms_hardware *wlc_hw) |
| 5014 | { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5015 | wlc_hw->up = true; |
| 5016 | wlc_phy_hw_state_upd(wlc_hw->band->pi, true); |
| 5017 | |
| 5018 | /* FULLY enable dynamic power control and d11 core interrupt */ |
Hauke Mehrtens | 712e3c1 | 2012-04-29 02:50:35 +0200 | [diff] [blame] | 5019 | brcms_b_clkctl_clk(wlc_hw, BCMA_CLKMODE_DYNAMIC); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5020 | brcms_intrson(wlc_hw->wlc->wl); |
| 5021 | return 0; |
| 5022 | } |
| 5023 | |
| 5024 | /* |
| 5025 | * Write WME tunable parameters for retransmit/max rate |
| 5026 | * from wlc struct to ucode |
| 5027 | */ |
| 5028 | static void brcms_c_wme_retries_write(struct brcms_c_info *wlc) |
| 5029 | { |
| 5030 | int ac; |
| 5031 | |
| 5032 | /* Need clock to do this */ |
| 5033 | if (!wlc->clk) |
| 5034 | return; |
| 5035 | |
Arend van Spriel | b7eec42 | 2011-11-10 20:30:18 +0100 | [diff] [blame] | 5036 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5037 | brcms_b_write_shm(wlc->hw, M_AC_TXLMT_ADDR(ac), |
| 5038 | wlc->wme_retries[ac]); |
| 5039 | } |
| 5040 | |
| 5041 | /* make interface operational */ |
| 5042 | int brcms_c_up(struct brcms_c_info *wlc) |
| 5043 | { |
Seth Forshee | 9169129 | 2012-06-16 07:47:49 -0500 | [diff] [blame] | 5044 | struct ieee80211_channel *ch; |
| 5045 | |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 5046 | brcms_dbg_info(wlc->hw->d11core, "wl%d\n", wlc->pub->unit); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5047 | |
| 5048 | /* HW is turned off so don't try to access it */ |
| 5049 | if (wlc->pub->hw_off || brcms_deviceremoved(wlc)) |
| 5050 | return -ENOMEDIUM; |
| 5051 | |
| 5052 | if (!wlc->pub->hw_up) { |
| 5053 | brcms_b_hw_up(wlc->hw); |
| 5054 | wlc->pub->hw_up = true; |
| 5055 | } |
| 5056 | |
| 5057 | if ((wlc->pub->boardflags & BFL_FEM) |
Hauke Mehrtens | 1ef1a57 | 2012-06-30 15:16:13 +0200 | [diff] [blame] | 5058 | && (ai_get_chip_id(wlc->hw->sih) == BCMA_CHIP_ID_BCM4313)) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5059 | if (wlc->pub->boardrev >= 0x1250 |
| 5060 | && (wlc->pub->boardflags & BFL_FEM_BT)) |
| 5061 | brcms_b_mhf(wlc->hw, MHF5, MHF5_4313_GPIOCTRL, |
| 5062 | MHF5_4313_GPIOCTRL, BRCM_BAND_ALL); |
| 5063 | else |
| 5064 | brcms_b_mhf(wlc->hw, MHF4, MHF4_EXTPA_ENABLE, |
| 5065 | MHF4_EXTPA_ENABLE, BRCM_BAND_ALL); |
| 5066 | } |
| 5067 | |
| 5068 | /* |
| 5069 | * Need to read the hwradio status here to cover the case where the |
| 5070 | * system is loaded with the hw radio disabled. We do not want to bring |
| 5071 | * the driver up in this case. If radio is disabled, abort up, lower |
| 5072 | * power, start radio timer and return 0(for NDIS) don't call |
| 5073 | * radio_update to avoid looping brcms_c_up. |
| 5074 | * |
| 5075 | * brcms_b_up_prep() returns either 0 or -BCME_RADIOOFF only |
| 5076 | */ |
| 5077 | if (!wlc->pub->radio_disabled) { |
| 5078 | int status = brcms_b_up_prep(wlc->hw); |
| 5079 | if (status == -ENOMEDIUM) { |
| 5080 | if (!mboolisset |
| 5081 | (wlc->pub->radio_disabled, WL_RADIO_HW_DISABLE)) { |
| 5082 | struct brcms_bss_cfg *bsscfg = wlc->bsscfg; |
| 5083 | mboolset(wlc->pub->radio_disabled, |
| 5084 | WL_RADIO_HW_DISABLE); |
| 5085 | |
| 5086 | if (bsscfg->enable && bsscfg->BSS) |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 5087 | brcms_err(wlc->hw->d11core, |
| 5088 | "wl%d: up: rfdisable -> " |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5089 | "bsscfg_disable()\n", |
| 5090 | wlc->pub->unit); |
| 5091 | } |
| 5092 | } |
| 5093 | } |
| 5094 | |
| 5095 | if (wlc->pub->radio_disabled) { |
| 5096 | brcms_c_radio_monitor_start(wlc); |
| 5097 | return 0; |
| 5098 | } |
| 5099 | |
| 5100 | /* brcms_b_up_prep has done brcms_c_corereset(). so clk is on, set it */ |
| 5101 | wlc->clk = true; |
| 5102 | |
| 5103 | brcms_c_radio_monitor_stop(wlc); |
| 5104 | |
| 5105 | /* Set EDCF hostflags */ |
| 5106 | brcms_b_mhf(wlc->hw, MHF1, MHF1_EDCF, MHF1_EDCF, BRCM_BAND_ALL); |
| 5107 | |
| 5108 | brcms_init(wlc->wl); |
| 5109 | wlc->pub->up = true; |
| 5110 | |
| 5111 | if (wlc->bandinit_pending) { |
Seth Forshee | 9169129 | 2012-06-16 07:47:49 -0500 | [diff] [blame] | 5112 | ch = wlc->pub->ieee_hw->conf.channel; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5113 | brcms_c_suspend_mac_and_wait(wlc); |
Seth Forshee | 9169129 | 2012-06-16 07:47:49 -0500 | [diff] [blame] | 5114 | brcms_c_set_chanspec(wlc, ch20mhz_chspec(ch->hw_value)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5115 | wlc->bandinit_pending = false; |
| 5116 | brcms_c_enable_mac(wlc); |
| 5117 | } |
| 5118 | |
| 5119 | brcms_b_up_finish(wlc->hw); |
| 5120 | |
| 5121 | /* Program the TX wme params with the current settings */ |
| 5122 | brcms_c_wme_retries_write(wlc); |
| 5123 | |
| 5124 | /* start one second watchdog timer */ |
Roland Vossen | be69c4e | 2011-10-12 20:51:11 +0200 | [diff] [blame] | 5125 | brcms_add_timer(wlc->wdtimer, TIMER_INTERVAL_WATCHDOG, true); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5126 | wlc->WDarmed = true; |
| 5127 | |
| 5128 | /* ensure antenna config is up to date */ |
| 5129 | brcms_c_stf_phy_txant_upd(wlc); |
| 5130 | /* ensure LDPC config is in sync */ |
| 5131 | brcms_c_ht_update_ldpc(wlc, wlc->stf->ldpc); |
| 5132 | |
| 5133 | return 0; |
| 5134 | } |
| 5135 | |
| 5136 | static uint brcms_c_down_del_timer(struct brcms_c_info *wlc) |
| 5137 | { |
| 5138 | uint callbacks = 0; |
| 5139 | |
| 5140 | return callbacks; |
| 5141 | } |
| 5142 | |
| 5143 | static int brcms_b_bmac_down_prep(struct brcms_hardware *wlc_hw) |
| 5144 | { |
| 5145 | bool dev_gone; |
| 5146 | uint callbacks = 0; |
| 5147 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5148 | if (!wlc_hw->up) |
| 5149 | return callbacks; |
| 5150 | |
| 5151 | dev_gone = brcms_deviceremoved(wlc_hw->wlc); |
| 5152 | |
| 5153 | /* disable interrupts */ |
| 5154 | if (dev_gone) |
| 5155 | wlc_hw->wlc->macintmask = 0; |
| 5156 | else { |
| 5157 | /* now disable interrupts */ |
| 5158 | brcms_intrsoff(wlc_hw->wlc->wl); |
| 5159 | |
| 5160 | /* ensure we're running on the pll clock again */ |
Hauke Mehrtens | 712e3c1 | 2012-04-29 02:50:35 +0200 | [diff] [blame] | 5161 | brcms_b_clkctl_clk(wlc_hw, BCMA_CLKMODE_FAST); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5162 | } |
| 5163 | /* down phy at the last of this stage */ |
| 5164 | callbacks += wlc_phy_down(wlc_hw->band->pi); |
| 5165 | |
| 5166 | return callbacks; |
| 5167 | } |
| 5168 | |
| 5169 | static int brcms_b_down_finish(struct brcms_hardware *wlc_hw) |
| 5170 | { |
| 5171 | uint callbacks = 0; |
| 5172 | bool dev_gone; |
| 5173 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5174 | if (!wlc_hw->up) |
| 5175 | return callbacks; |
| 5176 | |
| 5177 | wlc_hw->up = false; |
| 5178 | wlc_phy_hw_state_upd(wlc_hw->band->pi, false); |
| 5179 | |
| 5180 | dev_gone = brcms_deviceremoved(wlc_hw->wlc); |
| 5181 | |
| 5182 | if (dev_gone) { |
| 5183 | wlc_hw->sbclk = false; |
| 5184 | wlc_hw->clk = false; |
| 5185 | wlc_phy_hw_clk_state_upd(wlc_hw->band->pi, false); |
| 5186 | |
| 5187 | /* reclaim any posted packets */ |
| 5188 | brcms_c_flushqueues(wlc_hw->wlc); |
| 5189 | } else { |
| 5190 | |
| 5191 | /* Reset and disable the core */ |
Arend van Spriel | a8779e4 | 2011-12-08 15:06:58 -0800 | [diff] [blame] | 5192 | if (bcma_core_is_enabled(wlc_hw->d11core)) { |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 5193 | if (bcma_read32(wlc_hw->d11core, |
| 5194 | D11REGOFFS(maccontrol)) & MCTL_EN_MAC) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5195 | brcms_c_suspend_mac_and_wait(wlc_hw->wlc); |
| 5196 | callbacks += brcms_reset(wlc_hw->wlc->wl); |
| 5197 | brcms_c_coredisable(wlc_hw); |
| 5198 | } |
| 5199 | |
| 5200 | /* turn off primary xtal and pll */ |
| 5201 | if (!wlc_hw->noreset) { |
| 5202 | ai_pci_down(wlc_hw->sih); |
| 5203 | brcms_b_xtal(wlc_hw, OFF); |
| 5204 | } |
| 5205 | } |
| 5206 | |
| 5207 | return callbacks; |
| 5208 | } |
| 5209 | |
| 5210 | /* |
| 5211 | * Mark the interface nonoperational, stop the software mechanisms, |
| 5212 | * disable the hardware, free any transient buffer state. |
| 5213 | * Return a count of the number of driver callbacks still pending. |
| 5214 | */ |
| 5215 | uint brcms_c_down(struct brcms_c_info *wlc) |
| 5216 | { |
| 5217 | |
| 5218 | uint callbacks = 0; |
| 5219 | int i; |
| 5220 | bool dev_gone = false; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5221 | |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 5222 | brcms_dbg_info(wlc->hw->d11core, "wl%d\n", wlc->pub->unit); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5223 | |
| 5224 | /* check if we are already in the going down path */ |
| 5225 | if (wlc->going_down) { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 5226 | brcms_err(wlc->hw->d11core, |
| 5227 | "wl%d: %s: Driver going down so return\n", |
| 5228 | wlc->pub->unit, __func__); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5229 | return 0; |
| 5230 | } |
| 5231 | if (!wlc->pub->up) |
| 5232 | return callbacks; |
| 5233 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5234 | wlc->going_down = true; |
| 5235 | |
| 5236 | callbacks += brcms_b_bmac_down_prep(wlc->hw); |
| 5237 | |
| 5238 | dev_gone = brcms_deviceremoved(wlc); |
| 5239 | |
| 5240 | /* Call any registered down handlers */ |
| 5241 | for (i = 0; i < BRCMS_MAXMODULES; i++) { |
| 5242 | if (wlc->modulecb[i].down_fn) |
| 5243 | callbacks += |
| 5244 | wlc->modulecb[i].down_fn(wlc->modulecb[i].hdl); |
| 5245 | } |
| 5246 | |
| 5247 | /* cancel the watchdog timer */ |
| 5248 | if (wlc->WDarmed) { |
Roland Vossen | be69c4e | 2011-10-12 20:51:11 +0200 | [diff] [blame] | 5249 | if (!brcms_del_timer(wlc->wdtimer)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5250 | callbacks++; |
| 5251 | wlc->WDarmed = false; |
| 5252 | } |
| 5253 | /* cancel all other timers */ |
| 5254 | callbacks += brcms_c_down_del_timer(wlc); |
| 5255 | |
| 5256 | wlc->pub->up = false; |
| 5257 | |
| 5258 | wlc_phy_mute_upd(wlc->band->pi, false, PHY_MUTE_ALL); |
| 5259 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5260 | callbacks += brcms_b_down_finish(wlc->hw); |
| 5261 | |
| 5262 | /* brcms_b_down_finish has done brcms_c_coredisable(). so clk is off */ |
| 5263 | wlc->clk = false; |
| 5264 | |
| 5265 | wlc->going_down = false; |
| 5266 | return callbacks; |
| 5267 | } |
| 5268 | |
| 5269 | /* Set the current gmode configuration */ |
| 5270 | int brcms_c_set_gmode(struct brcms_c_info *wlc, u8 gmode, bool config) |
| 5271 | { |
| 5272 | int ret = 0; |
| 5273 | uint i; |
| 5274 | struct brcms_c_rateset rs; |
| 5275 | /* Default to 54g Auto */ |
| 5276 | /* Advertise and use shortslot (-1/0/1 Auto/Off/On) */ |
| 5277 | s8 shortslot = BRCMS_SHORTSLOT_AUTO; |
| 5278 | bool shortslot_restrict = false; /* Restrict association to stations |
| 5279 | * that support shortslot |
| 5280 | */ |
| 5281 | bool ofdm_basic = false; /* Make 6, 12, and 24 basic rates */ |
| 5282 | /* Advertise and use short preambles (-1/0/1 Auto/Off/On) */ |
| 5283 | int preamble = BRCMS_PLCP_LONG; |
| 5284 | bool preamble_restrict = false; /* Restrict association to stations |
| 5285 | * that support short preambles |
| 5286 | */ |
| 5287 | struct brcms_band *band; |
| 5288 | |
| 5289 | /* if N-support is enabled, allow Gmode set as long as requested |
| 5290 | * Gmode is not GMODE_LEGACY_B |
| 5291 | */ |
| 5292 | if ((wlc->pub->_n_enab & SUPPORT_11N) && gmode == GMODE_LEGACY_B) |
| 5293 | return -ENOTSUPP; |
| 5294 | |
| 5295 | /* verify that we are dealing with 2G band and grab the band pointer */ |
| 5296 | if (wlc->band->bandtype == BRCM_BAND_2G) |
| 5297 | band = wlc->band; |
| 5298 | else if ((wlc->pub->_nbands > 1) && |
| 5299 | (wlc->bandstate[OTHERBANDUNIT(wlc)]->bandtype == BRCM_BAND_2G)) |
| 5300 | band = wlc->bandstate[OTHERBANDUNIT(wlc)]; |
| 5301 | else |
| 5302 | return -EINVAL; |
| 5303 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5304 | /* update configuration value */ |
Joe Perches | 23677ce | 2012-02-09 11:17:23 +0000 | [diff] [blame] | 5305 | if (config) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5306 | brcms_c_protection_upd(wlc, BRCMS_PROT_G_USER, gmode); |
| 5307 | |
| 5308 | /* Clear rateset override */ |
| 5309 | memset(&rs, 0, sizeof(struct brcms_c_rateset)); |
| 5310 | |
| 5311 | switch (gmode) { |
| 5312 | case GMODE_LEGACY_B: |
| 5313 | shortslot = BRCMS_SHORTSLOT_OFF; |
| 5314 | brcms_c_rateset_copy(&gphy_legacy_rates, &rs); |
| 5315 | |
| 5316 | break; |
| 5317 | |
| 5318 | case GMODE_LRS: |
| 5319 | break; |
| 5320 | |
| 5321 | case GMODE_AUTO: |
| 5322 | /* Accept defaults */ |
| 5323 | break; |
| 5324 | |
| 5325 | case GMODE_ONLY: |
| 5326 | ofdm_basic = true; |
| 5327 | preamble = BRCMS_PLCP_SHORT; |
| 5328 | preamble_restrict = true; |
| 5329 | break; |
| 5330 | |
| 5331 | case GMODE_PERFORMANCE: |
| 5332 | shortslot = BRCMS_SHORTSLOT_ON; |
| 5333 | shortslot_restrict = true; |
| 5334 | ofdm_basic = true; |
| 5335 | preamble = BRCMS_PLCP_SHORT; |
| 5336 | preamble_restrict = true; |
| 5337 | break; |
| 5338 | |
| 5339 | default: |
| 5340 | /* Error */ |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 5341 | brcms_err(wlc->hw->d11core, "wl%d: %s: invalid gmode %d\n", |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5342 | wlc->pub->unit, __func__, gmode); |
| 5343 | return -ENOTSUPP; |
| 5344 | } |
| 5345 | |
| 5346 | band->gmode = gmode; |
| 5347 | |
| 5348 | wlc->shortslot_override = shortslot; |
| 5349 | |
| 5350 | /* Use the default 11g rateset */ |
| 5351 | if (!rs.count) |
| 5352 | brcms_c_rateset_copy(&cck_ofdm_rates, &rs); |
| 5353 | |
| 5354 | if (ofdm_basic) { |
| 5355 | for (i = 0; i < rs.count; i++) { |
| 5356 | if (rs.rates[i] == BRCM_RATE_6M |
| 5357 | || rs.rates[i] == BRCM_RATE_12M |
| 5358 | || rs.rates[i] == BRCM_RATE_24M) |
| 5359 | rs.rates[i] |= BRCMS_RATE_FLAG; |
| 5360 | } |
| 5361 | } |
| 5362 | |
| 5363 | /* Set default bss rateset */ |
| 5364 | wlc->default_bss->rateset.count = rs.count; |
| 5365 | memcpy(wlc->default_bss->rateset.rates, rs.rates, |
| 5366 | sizeof(wlc->default_bss->rateset.rates)); |
| 5367 | |
| 5368 | return ret; |
| 5369 | } |
| 5370 | |
| 5371 | int brcms_c_set_nmode(struct brcms_c_info *wlc) |
| 5372 | { |
| 5373 | uint i; |
| 5374 | s32 nmode = AUTO; |
| 5375 | |
| 5376 | if (wlc->stf->txstreams == WL_11N_3x3) |
| 5377 | nmode = WL_11N_3x3; |
| 5378 | else |
| 5379 | nmode = WL_11N_2x2; |
| 5380 | |
| 5381 | /* force GMODE_AUTO if NMODE is ON */ |
| 5382 | brcms_c_set_gmode(wlc, GMODE_AUTO, true); |
| 5383 | if (nmode == WL_11N_3x3) |
| 5384 | wlc->pub->_n_enab = SUPPORT_HT; |
| 5385 | else |
| 5386 | wlc->pub->_n_enab = SUPPORT_11N; |
| 5387 | wlc->default_bss->flags |= BRCMS_BSS_HT; |
| 5388 | /* add the mcs rates to the default and hw ratesets */ |
| 5389 | brcms_c_rateset_mcs_build(&wlc->default_bss->rateset, |
| 5390 | wlc->stf->txstreams); |
| 5391 | for (i = 0; i < wlc->pub->_nbands; i++) |
| 5392 | memcpy(wlc->bandstate[i]->hw_rateset.mcs, |
| 5393 | wlc->default_bss->rateset.mcs, MCSSET_LEN); |
| 5394 | |
| 5395 | return 0; |
| 5396 | } |
| 5397 | |
| 5398 | static int |
| 5399 | brcms_c_set_internal_rateset(struct brcms_c_info *wlc, |
| 5400 | struct brcms_c_rateset *rs_arg) |
| 5401 | { |
| 5402 | struct brcms_c_rateset rs, new; |
| 5403 | uint bandunit; |
| 5404 | |
| 5405 | memcpy(&rs, rs_arg, sizeof(struct brcms_c_rateset)); |
| 5406 | |
| 5407 | /* check for bad count value */ |
| 5408 | if ((rs.count == 0) || (rs.count > BRCMS_NUMRATES)) |
| 5409 | return -EINVAL; |
| 5410 | |
| 5411 | /* try the current band */ |
| 5412 | bandunit = wlc->band->bandunit; |
| 5413 | memcpy(&new, &rs, sizeof(struct brcms_c_rateset)); |
| 5414 | if (brcms_c_rate_hwrs_filter_sort_validate |
| 5415 | (&new, &wlc->bandstate[bandunit]->hw_rateset, true, |
| 5416 | wlc->stf->txstreams)) |
| 5417 | goto good; |
| 5418 | |
| 5419 | /* try the other band */ |
| 5420 | if (brcms_is_mband_unlocked(wlc)) { |
| 5421 | bandunit = OTHERBANDUNIT(wlc); |
| 5422 | memcpy(&new, &rs, sizeof(struct brcms_c_rateset)); |
| 5423 | if (brcms_c_rate_hwrs_filter_sort_validate(&new, |
| 5424 | &wlc-> |
| 5425 | bandstate[bandunit]-> |
| 5426 | hw_rateset, true, |
| 5427 | wlc->stf->txstreams)) |
| 5428 | goto good; |
| 5429 | } |
| 5430 | |
| 5431 | return -EBADE; |
| 5432 | |
| 5433 | good: |
| 5434 | /* apply new rateset */ |
| 5435 | memcpy(&wlc->default_bss->rateset, &new, |
| 5436 | sizeof(struct brcms_c_rateset)); |
| 5437 | memcpy(&wlc->bandstate[bandunit]->defrateset, &new, |
| 5438 | sizeof(struct brcms_c_rateset)); |
| 5439 | return 0; |
| 5440 | } |
| 5441 | |
| 5442 | static void brcms_c_ofdm_rateset_war(struct brcms_c_info *wlc) |
| 5443 | { |
| 5444 | u8 r; |
| 5445 | bool war = false; |
| 5446 | |
| 5447 | if (wlc->bsscfg->associated) |
| 5448 | r = wlc->bsscfg->current_bss->rateset.rates[0]; |
| 5449 | else |
| 5450 | r = wlc->default_bss->rateset.rates[0]; |
| 5451 | |
| 5452 | wlc_phy_ofdm_rateset_war(wlc->band->pi, war); |
| 5453 | } |
| 5454 | |
| 5455 | int brcms_c_set_channel(struct brcms_c_info *wlc, u16 channel) |
| 5456 | { |
| 5457 | u16 chspec = ch20mhz_chspec(channel); |
| 5458 | |
| 5459 | if (channel < 0 || channel > MAXCHANNEL) |
| 5460 | return -EINVAL; |
| 5461 | |
| 5462 | if (!brcms_c_valid_chanspec_db(wlc->cmi, chspec)) |
| 5463 | return -EINVAL; |
| 5464 | |
| 5465 | |
| 5466 | if (!wlc->pub->up && brcms_is_mband_unlocked(wlc)) { |
| 5467 | if (wlc->band->bandunit != chspec_bandunit(chspec)) |
| 5468 | wlc->bandinit_pending = true; |
| 5469 | else |
| 5470 | wlc->bandinit_pending = false; |
| 5471 | } |
| 5472 | |
| 5473 | wlc->default_bss->chanspec = chspec; |
| 5474 | /* brcms_c_BSSinit() will sanitize the rateset before |
| 5475 | * using it.. */ |
| 5476 | if (wlc->pub->up && (wlc_phy_chanspec_get(wlc->band->pi) != chspec)) { |
| 5477 | brcms_c_set_home_chanspec(wlc, chspec); |
| 5478 | brcms_c_suspend_mac_and_wait(wlc); |
| 5479 | brcms_c_set_chanspec(wlc, chspec); |
| 5480 | brcms_c_enable_mac(wlc); |
| 5481 | } |
| 5482 | return 0; |
| 5483 | } |
| 5484 | |
| 5485 | int brcms_c_set_rate_limit(struct brcms_c_info *wlc, u16 srl, u16 lrl) |
| 5486 | { |
| 5487 | int ac; |
| 5488 | |
| 5489 | if (srl < 1 || srl > RETRY_SHORT_MAX || |
| 5490 | lrl < 1 || lrl > RETRY_SHORT_MAX) |
| 5491 | return -EINVAL; |
| 5492 | |
| 5493 | wlc->SRL = srl; |
| 5494 | wlc->LRL = lrl; |
| 5495 | |
| 5496 | brcms_b_retrylimit_upd(wlc->hw, wlc->SRL, wlc->LRL); |
| 5497 | |
Arend van Spriel | b7eec42 | 2011-11-10 20:30:18 +0100 | [diff] [blame] | 5498 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5499 | wlc->wme_retries[ac] = SFIELD(wlc->wme_retries[ac], |
| 5500 | EDCF_SHORT, wlc->SRL); |
| 5501 | wlc->wme_retries[ac] = SFIELD(wlc->wme_retries[ac], |
| 5502 | EDCF_LONG, wlc->LRL); |
| 5503 | } |
| 5504 | brcms_c_wme_retries_write(wlc); |
| 5505 | |
| 5506 | return 0; |
| 5507 | } |
| 5508 | |
| 5509 | void brcms_c_get_current_rateset(struct brcms_c_info *wlc, |
| 5510 | struct brcm_rateset *currs) |
| 5511 | { |
| 5512 | struct brcms_c_rateset *rs; |
| 5513 | |
| 5514 | if (wlc->pub->associated) |
| 5515 | rs = &wlc->bsscfg->current_bss->rateset; |
| 5516 | else |
| 5517 | rs = &wlc->default_bss->rateset; |
| 5518 | |
| 5519 | /* Copy only legacy rateset section */ |
| 5520 | currs->count = rs->count; |
| 5521 | memcpy(&currs->rates, &rs->rates, rs->count); |
| 5522 | } |
| 5523 | |
| 5524 | int brcms_c_set_rateset(struct brcms_c_info *wlc, struct brcm_rateset *rs) |
| 5525 | { |
| 5526 | struct brcms_c_rateset internal_rs; |
| 5527 | int bcmerror; |
| 5528 | |
| 5529 | if (rs->count > BRCMS_NUMRATES) |
| 5530 | return -ENOBUFS; |
| 5531 | |
| 5532 | memset(&internal_rs, 0, sizeof(struct brcms_c_rateset)); |
| 5533 | |
| 5534 | /* Copy only legacy rateset section */ |
| 5535 | internal_rs.count = rs->count; |
| 5536 | memcpy(&internal_rs.rates, &rs->rates, internal_rs.count); |
| 5537 | |
| 5538 | /* merge rateset coming in with the current mcsset */ |
| 5539 | if (wlc->pub->_n_enab & SUPPORT_11N) { |
| 5540 | struct brcms_bss_info *mcsset_bss; |
| 5541 | if (wlc->bsscfg->associated) |
| 5542 | mcsset_bss = wlc->bsscfg->current_bss; |
| 5543 | else |
| 5544 | mcsset_bss = wlc->default_bss; |
| 5545 | memcpy(internal_rs.mcs, &mcsset_bss->rateset.mcs[0], |
| 5546 | MCSSET_LEN); |
| 5547 | } |
| 5548 | |
| 5549 | bcmerror = brcms_c_set_internal_rateset(wlc, &internal_rs); |
| 5550 | if (!bcmerror) |
| 5551 | brcms_c_ofdm_rateset_war(wlc); |
| 5552 | |
| 5553 | return bcmerror; |
| 5554 | } |
| 5555 | |
| 5556 | int brcms_c_set_beacon_period(struct brcms_c_info *wlc, u16 period) |
| 5557 | { |
| 5558 | if (period < DOT11_MIN_BEACON_PERIOD || |
| 5559 | period > DOT11_MAX_BEACON_PERIOD) |
| 5560 | return -EINVAL; |
| 5561 | |
| 5562 | wlc->default_bss->beacon_period = period; |
| 5563 | return 0; |
| 5564 | } |
| 5565 | |
| 5566 | u16 brcms_c_get_phy_type(struct brcms_c_info *wlc, int phyidx) |
| 5567 | { |
| 5568 | return wlc->band->phytype; |
| 5569 | } |
| 5570 | |
| 5571 | void brcms_c_set_shortslot_override(struct brcms_c_info *wlc, s8 sslot_override) |
| 5572 | { |
| 5573 | wlc->shortslot_override = sslot_override; |
| 5574 | |
| 5575 | /* |
| 5576 | * shortslot is an 11g feature, so no more work if we are |
| 5577 | * currently on the 5G band |
| 5578 | */ |
| 5579 | if (wlc->band->bandtype == BRCM_BAND_5G) |
| 5580 | return; |
| 5581 | |
| 5582 | if (wlc->pub->up && wlc->pub->associated) { |
| 5583 | /* let watchdog or beacon processing update shortslot */ |
| 5584 | } else if (wlc->pub->up) { |
| 5585 | /* unassociated shortslot is off */ |
| 5586 | brcms_c_switch_shortslot(wlc, false); |
| 5587 | } else { |
| 5588 | /* driver is down, so just update the brcms_c_info |
| 5589 | * value */ |
| 5590 | if (wlc->shortslot_override == BRCMS_SHORTSLOT_AUTO) |
| 5591 | wlc->shortslot = false; |
| 5592 | else |
| 5593 | wlc->shortslot = |
| 5594 | (wlc->shortslot_override == |
| 5595 | BRCMS_SHORTSLOT_ON); |
| 5596 | } |
| 5597 | } |
| 5598 | |
| 5599 | /* |
| 5600 | * register watchdog and down handlers. |
| 5601 | */ |
| 5602 | int brcms_c_module_register(struct brcms_pub *pub, |
| 5603 | const char *name, struct brcms_info *hdl, |
| 5604 | int (*d_fn)(void *handle)) |
| 5605 | { |
| 5606 | struct brcms_c_info *wlc = (struct brcms_c_info *) pub->wlc; |
| 5607 | int i; |
| 5608 | |
| 5609 | /* find an empty entry and just add, no duplication check! */ |
| 5610 | for (i = 0; i < BRCMS_MAXMODULES; i++) { |
| 5611 | if (wlc->modulecb[i].name[0] == '\0') { |
| 5612 | strncpy(wlc->modulecb[i].name, name, |
| 5613 | sizeof(wlc->modulecb[i].name) - 1); |
| 5614 | wlc->modulecb[i].hdl = hdl; |
| 5615 | wlc->modulecb[i].down_fn = d_fn; |
| 5616 | return 0; |
| 5617 | } |
| 5618 | } |
| 5619 | |
| 5620 | return -ENOSR; |
| 5621 | } |
| 5622 | |
| 5623 | /* unregister module callbacks */ |
| 5624 | int brcms_c_module_unregister(struct brcms_pub *pub, const char *name, |
| 5625 | struct brcms_info *hdl) |
| 5626 | { |
| 5627 | struct brcms_c_info *wlc = (struct brcms_c_info *) pub->wlc; |
| 5628 | int i; |
| 5629 | |
| 5630 | if (wlc == NULL) |
| 5631 | return -ENODATA; |
| 5632 | |
| 5633 | for (i = 0; i < BRCMS_MAXMODULES; i++) { |
| 5634 | if (!strcmp(wlc->modulecb[i].name, name) && |
| 5635 | (wlc->modulecb[i].hdl == hdl)) { |
| 5636 | memset(&wlc->modulecb[i], 0, sizeof(struct modulecb)); |
| 5637 | return 0; |
| 5638 | } |
| 5639 | } |
| 5640 | |
| 5641 | /* table not found! */ |
| 5642 | return -ENODATA; |
| 5643 | } |
| 5644 | |
Hauke Mehrtens | cacaa64 | 2012-06-30 15:16:19 +0200 | [diff] [blame] | 5645 | static bool brcms_c_chipmatch_pci(struct bcma_device *core) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5646 | { |
Hauke Mehrtens | cacaa64 | 2012-06-30 15:16:19 +0200 | [diff] [blame] | 5647 | struct pci_dev *pcidev = core->bus->host_pci; |
| 5648 | u16 vendor = pcidev->vendor; |
| 5649 | u16 device = pcidev->device; |
| 5650 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5651 | if (vendor != PCI_VENDOR_ID_BROADCOM) { |
Joe Perches | 02f7719 | 2012-01-15 00:38:44 -0800 | [diff] [blame] | 5652 | pr_err("unknown vendor id %04x\n", vendor); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5653 | return false; |
| 5654 | } |
| 5655 | |
Hauke Mehrtens | 9dd4ea5 | 2012-12-07 17:10:03 +0100 | [diff] [blame] | 5656 | if (device == BCM43224_D11N_ID_VEN1 || device == BCM43224_CHIP_ID) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5657 | return true; |
| 5658 | if ((device == BCM43224_D11N_ID) || (device == BCM43225_D11N2G_ID)) |
| 5659 | return true; |
| 5660 | if (device == BCM4313_D11N2G_ID) |
| 5661 | return true; |
| 5662 | if ((device == BCM43236_D11N_ID) || (device == BCM43236_D11N2G_ID)) |
| 5663 | return true; |
| 5664 | |
Joe Perches | 02f7719 | 2012-01-15 00:38:44 -0800 | [diff] [blame] | 5665 | pr_err("unknown device id %04x\n", device); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5666 | return false; |
| 5667 | } |
| 5668 | |
Hauke Mehrtens | cacaa64 | 2012-06-30 15:16:19 +0200 | [diff] [blame] | 5669 | static bool brcms_c_chipmatch_soc(struct bcma_device *core) |
| 5670 | { |
| 5671 | struct bcma_chipinfo *chipinfo = &core->bus->chipinfo; |
| 5672 | |
| 5673 | if (chipinfo->id == BCMA_CHIP_ID_BCM4716) |
| 5674 | return true; |
| 5675 | |
| 5676 | pr_err("unknown chip id %04x\n", chipinfo->id); |
| 5677 | return false; |
| 5678 | } |
| 5679 | |
| 5680 | bool brcms_c_chipmatch(struct bcma_device *core) |
| 5681 | { |
| 5682 | switch (core->bus->hosttype) { |
| 5683 | case BCMA_HOSTTYPE_PCI: |
| 5684 | return brcms_c_chipmatch_pci(core); |
| 5685 | case BCMA_HOSTTYPE_SOC: |
| 5686 | return brcms_c_chipmatch_soc(core); |
| 5687 | default: |
| 5688 | pr_err("unknown host type: %i\n", core->bus->hosttype); |
| 5689 | return false; |
| 5690 | } |
| 5691 | } |
| 5692 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5693 | u16 brcms_b_rate_shm_offset(struct brcms_hardware *wlc_hw, u8 rate) |
| 5694 | { |
| 5695 | u16 table_ptr; |
| 5696 | u8 phy_rate, index; |
| 5697 | |
| 5698 | /* get the phy specific rate encoding for the PLCP SIGNAL field */ |
| 5699 | if (is_ofdm_rate(rate)) |
| 5700 | table_ptr = M_RT_DIRMAP_A; |
| 5701 | else |
| 5702 | table_ptr = M_RT_DIRMAP_B; |
| 5703 | |
| 5704 | /* for a given rate, the LS-nibble of the PLCP SIGNAL field is |
| 5705 | * the index into the rate table. |
| 5706 | */ |
| 5707 | phy_rate = rate_info[rate] & BRCMS_RATE_MASK; |
| 5708 | index = phy_rate & 0xf; |
| 5709 | |
| 5710 | /* Find the SHM pointer to the rate table entry by looking in the |
| 5711 | * Direct-map Table |
| 5712 | */ |
| 5713 | return 2 * brcms_b_read_shm(wlc_hw, table_ptr + (index * 2)); |
| 5714 | } |
| 5715 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5716 | /* |
| 5717 | * bcmc_fid_generate: |
| 5718 | * Generate frame ID for a BCMC packet. The frag field is not used |
| 5719 | * for MC frames so is used as part of the sequence number. |
| 5720 | */ |
| 5721 | static inline u16 |
| 5722 | bcmc_fid_generate(struct brcms_c_info *wlc, struct brcms_bss_cfg *bsscfg, |
| 5723 | struct d11txh *txh) |
| 5724 | { |
| 5725 | u16 frameid; |
| 5726 | |
| 5727 | frameid = le16_to_cpu(txh->TxFrameID) & ~(TXFID_SEQ_MASK | |
| 5728 | TXFID_QUEUE_MASK); |
| 5729 | frameid |= |
| 5730 | (((wlc-> |
| 5731 | mc_fid_counter++) << TXFID_SEQ_SHIFT) & TXFID_SEQ_MASK) | |
| 5732 | TX_BCMC_FIFO; |
| 5733 | |
| 5734 | return frameid; |
| 5735 | } |
| 5736 | |
| 5737 | static uint |
| 5738 | brcms_c_calc_ack_time(struct brcms_c_info *wlc, u32 rspec, |
| 5739 | u8 preamble_type) |
| 5740 | { |
| 5741 | uint dur = 0; |
| 5742 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5743 | /* |
| 5744 | * Spec 9.6: ack rate is the highest rate in BSSBasicRateSet that |
| 5745 | * is less than or equal to the rate of the immediately previous |
| 5746 | * frame in the FES |
| 5747 | */ |
| 5748 | rspec = brcms_basic_rate(wlc, rspec); |
| 5749 | /* ACK frame len == 14 == 2(fc) + 2(dur) + 6(ra) + 4(fcs) */ |
| 5750 | dur = |
| 5751 | brcms_c_calc_frame_time(wlc, rspec, preamble_type, |
| 5752 | (DOT11_ACK_LEN + FCS_LEN)); |
| 5753 | return dur; |
| 5754 | } |
| 5755 | |
| 5756 | static uint |
| 5757 | brcms_c_calc_cts_time(struct brcms_c_info *wlc, u32 rspec, |
| 5758 | u8 preamble_type) |
| 5759 | { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5760 | return brcms_c_calc_ack_time(wlc, rspec, preamble_type); |
| 5761 | } |
| 5762 | |
| 5763 | static uint |
| 5764 | brcms_c_calc_ba_time(struct brcms_c_info *wlc, u32 rspec, |
| 5765 | u8 preamble_type) |
| 5766 | { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5767 | /* |
| 5768 | * Spec 9.6: ack rate is the highest rate in BSSBasicRateSet that |
| 5769 | * is less than or equal to the rate of the immediately previous |
| 5770 | * frame in the FES |
| 5771 | */ |
| 5772 | rspec = brcms_basic_rate(wlc, rspec); |
| 5773 | /* BA len == 32 == 16(ctl hdr) + 4(ba len) + 8(bitmap) + 4(fcs) */ |
| 5774 | return brcms_c_calc_frame_time(wlc, rspec, preamble_type, |
| 5775 | (DOT11_BA_LEN + DOT11_BA_BITMAP_LEN + |
| 5776 | FCS_LEN)); |
| 5777 | } |
| 5778 | |
| 5779 | /* brcms_c_compute_frame_dur() |
| 5780 | * |
| 5781 | * Calculate the 802.11 MAC header DUR field for MPDU |
| 5782 | * DUR for a single frame = 1 SIFS + 1 ACK |
| 5783 | * DUR for a frame with following frags = 3 SIFS + 2 ACK + next frag time |
| 5784 | * |
| 5785 | * rate MPDU rate in unit of 500kbps |
| 5786 | * next_frag_len next MPDU length in bytes |
| 5787 | * preamble_type use short/GF or long/MM PLCP header |
| 5788 | */ |
| 5789 | static u16 |
| 5790 | brcms_c_compute_frame_dur(struct brcms_c_info *wlc, u32 rate, |
| 5791 | u8 preamble_type, uint next_frag_len) |
| 5792 | { |
| 5793 | u16 dur, sifs; |
| 5794 | |
| 5795 | sifs = get_sifs(wlc->band); |
| 5796 | |
| 5797 | dur = sifs; |
| 5798 | dur += (u16) brcms_c_calc_ack_time(wlc, rate, preamble_type); |
| 5799 | |
| 5800 | if (next_frag_len) { |
| 5801 | /* Double the current DUR to get 2 SIFS + 2 ACKs */ |
| 5802 | dur *= 2; |
| 5803 | /* add another SIFS and the frag time */ |
| 5804 | dur += sifs; |
| 5805 | dur += |
| 5806 | (u16) brcms_c_calc_frame_time(wlc, rate, preamble_type, |
| 5807 | next_frag_len); |
| 5808 | } |
| 5809 | return dur; |
| 5810 | } |
| 5811 | |
| 5812 | /* The opposite of brcms_c_calc_frame_time */ |
| 5813 | static uint |
| 5814 | brcms_c_calc_frame_len(struct brcms_c_info *wlc, u32 ratespec, |
| 5815 | u8 preamble_type, uint dur) |
| 5816 | { |
| 5817 | uint nsyms, mac_len, Ndps, kNdps; |
| 5818 | uint rate = rspec2rate(ratespec); |
| 5819 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5820 | if (is_mcs_rate(ratespec)) { |
| 5821 | uint mcs = ratespec & RSPEC_RATE_MASK; |
| 5822 | int tot_streams = mcs_2_txstreams(mcs) + rspec_stc(ratespec); |
| 5823 | dur -= PREN_PREAMBLE + (tot_streams * PREN_PREAMBLE_EXT); |
| 5824 | /* payload calculation matches that of regular ofdm */ |
| 5825 | if (wlc->band->bandtype == BRCM_BAND_2G) |
| 5826 | dur -= DOT11_OFDM_SIGNAL_EXTENSION; |
| 5827 | /* kNdbps = kbps * 4 */ |
| 5828 | kNdps = mcs_2_rate(mcs, rspec_is40mhz(ratespec), |
| 5829 | rspec_issgi(ratespec)) * 4; |
| 5830 | nsyms = dur / APHY_SYMBOL_TIME; |
| 5831 | mac_len = |
| 5832 | ((nsyms * kNdps) - |
| 5833 | ((APHY_SERVICE_NBITS + APHY_TAIL_NBITS) * 1000)) / 8000; |
| 5834 | } else if (is_ofdm_rate(ratespec)) { |
| 5835 | dur -= APHY_PREAMBLE_TIME; |
| 5836 | dur -= APHY_SIGNAL_TIME; |
| 5837 | /* Ndbps = Mbps * 4 = rate(500Kbps) * 2 */ |
| 5838 | Ndps = rate * 2; |
| 5839 | nsyms = dur / APHY_SYMBOL_TIME; |
| 5840 | mac_len = |
| 5841 | ((nsyms * Ndps) - |
| 5842 | (APHY_SERVICE_NBITS + APHY_TAIL_NBITS)) / 8; |
| 5843 | } else { |
| 5844 | if (preamble_type & BRCMS_SHORT_PREAMBLE) |
| 5845 | dur -= BPHY_PLCP_SHORT_TIME; |
| 5846 | else |
| 5847 | dur -= BPHY_PLCP_TIME; |
| 5848 | mac_len = dur * rate; |
| 5849 | /* divide out factor of 2 in rate (1/2 mbps) */ |
| 5850 | mac_len = mac_len / 8 / 2; |
| 5851 | } |
| 5852 | return mac_len; |
| 5853 | } |
| 5854 | |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 5855 | /* |
| 5856 | * Return true if the specified rate is supported by the specified band. |
| 5857 | * BRCM_BAND_AUTO indicates the current band. |
| 5858 | */ |
| 5859 | static bool brcms_c_valid_rate(struct brcms_c_info *wlc, u32 rspec, int band, |
| 5860 | bool verbose) |
| 5861 | { |
| 5862 | struct brcms_c_rateset *hw_rateset; |
| 5863 | uint i; |
| 5864 | |
| 5865 | if ((band == BRCM_BAND_AUTO) || (band == wlc->band->bandtype)) |
| 5866 | hw_rateset = &wlc->band->hw_rateset; |
| 5867 | else if (wlc->pub->_nbands > 1) |
| 5868 | hw_rateset = &wlc->bandstate[OTHERBANDUNIT(wlc)]->hw_rateset; |
| 5869 | else |
| 5870 | /* other band specified and we are a single band device */ |
| 5871 | return false; |
| 5872 | |
| 5873 | /* check if this is a mimo rate */ |
| 5874 | if (is_mcs_rate(rspec)) { |
| 5875 | if ((rspec & RSPEC_RATE_MASK) >= MCS_TABLE_SIZE) |
| 5876 | goto error; |
| 5877 | |
| 5878 | return isset(hw_rateset->mcs, (rspec & RSPEC_RATE_MASK)); |
| 5879 | } |
| 5880 | |
| 5881 | for (i = 0; i < hw_rateset->count; i++) |
| 5882 | if (hw_rateset->rates[i] == rspec2rate(rspec)) |
| 5883 | return true; |
| 5884 | error: |
| 5885 | if (verbose) |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 5886 | brcms_err(wlc->hw->d11core, "wl%d: valid_rate: rate spec 0x%x " |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 5887 | "not in hw_rateset\n", wlc->pub->unit, rspec); |
| 5888 | |
| 5889 | return false; |
| 5890 | } |
| 5891 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5892 | static u32 |
| 5893 | mac80211_wlc_set_nrate(struct brcms_c_info *wlc, struct brcms_band *cur_band, |
| 5894 | u32 int_val) |
| 5895 | { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 5896 | struct bcma_device *core = wlc->hw->d11core; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5897 | u8 stf = (int_val & NRATE_STF_MASK) >> NRATE_STF_SHIFT; |
| 5898 | u8 rate = int_val & NRATE_RATE_MASK; |
| 5899 | u32 rspec; |
| 5900 | bool ismcs = ((int_val & NRATE_MCS_INUSE) == NRATE_MCS_INUSE); |
| 5901 | bool issgi = ((int_val & NRATE_SGI_MASK) >> NRATE_SGI_SHIFT); |
| 5902 | bool override_mcs_only = ((int_val & NRATE_OVERRIDE_MCS_ONLY) |
| 5903 | == NRATE_OVERRIDE_MCS_ONLY); |
| 5904 | int bcmerror = 0; |
| 5905 | |
| 5906 | if (!ismcs) |
| 5907 | return (u32) rate; |
| 5908 | |
| 5909 | /* validate the combination of rate/mcs/stf is allowed */ |
| 5910 | if ((wlc->pub->_n_enab & SUPPORT_11N) && ismcs) { |
| 5911 | /* mcs only allowed when nmode */ |
| 5912 | if (stf > PHY_TXC1_MODE_SDM) { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 5913 | brcms_err(core, "wl%d: %s: Invalid stf\n", |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5914 | wlc->pub->unit, __func__); |
| 5915 | bcmerror = -EINVAL; |
| 5916 | goto done; |
| 5917 | } |
| 5918 | |
| 5919 | /* mcs 32 is a special case, DUP mode 40 only */ |
| 5920 | if (rate == 32) { |
| 5921 | if (!CHSPEC_IS40(wlc->home_chanspec) || |
| 5922 | ((stf != PHY_TXC1_MODE_SISO) |
| 5923 | && (stf != PHY_TXC1_MODE_CDD))) { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 5924 | brcms_err(core, "wl%d: %s: Invalid mcs 32\n", |
| 5925 | wlc->pub->unit, __func__); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5926 | bcmerror = -EINVAL; |
| 5927 | goto done; |
| 5928 | } |
| 5929 | /* mcs > 7 must use stf SDM */ |
| 5930 | } else if (rate > HIGHEST_SINGLE_STREAM_MCS) { |
| 5931 | /* mcs > 7 must use stf SDM */ |
| 5932 | if (stf != PHY_TXC1_MODE_SDM) { |
Seth Forshee | 913911f | 2012-11-15 08:08:04 -0600 | [diff] [blame] | 5933 | brcms_dbg_mac80211(core, "wl%d: enabling " |
| 5934 | "SDM mode for mcs %d\n", |
| 5935 | wlc->pub->unit, rate); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5936 | stf = PHY_TXC1_MODE_SDM; |
| 5937 | } |
| 5938 | } else { |
| 5939 | /* |
| 5940 | * MCS 0-7 may use SISO, CDD, and for |
| 5941 | * phy_rev >= 3 STBC |
| 5942 | */ |
| 5943 | if ((stf > PHY_TXC1_MODE_STBC) || |
| 5944 | (!BRCMS_STBC_CAP_PHY(wlc) |
| 5945 | && (stf == PHY_TXC1_MODE_STBC))) { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 5946 | brcms_err(core, "wl%d: %s: Invalid STBC\n", |
| 5947 | wlc->pub->unit, __func__); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5948 | bcmerror = -EINVAL; |
| 5949 | goto done; |
| 5950 | } |
| 5951 | } |
| 5952 | } else if (is_ofdm_rate(rate)) { |
| 5953 | if ((stf != PHY_TXC1_MODE_CDD) && (stf != PHY_TXC1_MODE_SISO)) { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 5954 | brcms_err(core, "wl%d: %s: Invalid OFDM\n", |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5955 | wlc->pub->unit, __func__); |
| 5956 | bcmerror = -EINVAL; |
| 5957 | goto done; |
| 5958 | } |
| 5959 | } else if (is_cck_rate(rate)) { |
| 5960 | if ((cur_band->bandtype != BRCM_BAND_2G) |
| 5961 | || (stf != PHY_TXC1_MODE_SISO)) { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 5962 | brcms_err(core, "wl%d: %s: Invalid CCK\n", |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5963 | wlc->pub->unit, __func__); |
| 5964 | bcmerror = -EINVAL; |
| 5965 | goto done; |
| 5966 | } |
| 5967 | } else { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 5968 | brcms_err(core, "wl%d: %s: Unknown rate type\n", |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5969 | wlc->pub->unit, __func__); |
| 5970 | bcmerror = -EINVAL; |
| 5971 | goto done; |
| 5972 | } |
| 5973 | /* make sure multiple antennae are available for non-siso rates */ |
| 5974 | if ((stf != PHY_TXC1_MODE_SISO) && (wlc->stf->txstreams == 1)) { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 5975 | brcms_err(core, "wl%d: %s: SISO antenna but !SISO " |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5976 | "request\n", wlc->pub->unit, __func__); |
| 5977 | bcmerror = -EINVAL; |
| 5978 | goto done; |
| 5979 | } |
| 5980 | |
| 5981 | rspec = rate; |
| 5982 | if (ismcs) { |
| 5983 | rspec |= RSPEC_MIMORATE; |
| 5984 | /* For STBC populate the STC field of the ratespec */ |
| 5985 | if (stf == PHY_TXC1_MODE_STBC) { |
| 5986 | u8 stc; |
| 5987 | stc = 1; /* Nss for single stream is always 1 */ |
| 5988 | rspec |= (stc << RSPEC_STC_SHIFT); |
| 5989 | } |
| 5990 | } |
| 5991 | |
| 5992 | rspec |= (stf << RSPEC_STF_SHIFT); |
| 5993 | |
| 5994 | if (override_mcs_only) |
| 5995 | rspec |= RSPEC_OVERRIDE_MCS_ONLY; |
| 5996 | |
| 5997 | if (issgi) |
| 5998 | rspec |= RSPEC_SHORT_GI; |
| 5999 | |
| 6000 | if ((rate != 0) |
| 6001 | && !brcms_c_valid_rate(wlc, rspec, cur_band->bandtype, true)) |
| 6002 | return rate; |
| 6003 | |
| 6004 | return rspec; |
| 6005 | done: |
| 6006 | return rate; |
| 6007 | } |
| 6008 | |
| 6009 | /* |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 6010 | * Compute PLCP, but only requires actual rate and length of pkt. |
| 6011 | * Rate is given in the driver standard multiple of 500 kbps. |
| 6012 | * le is set for 11 Mbps rate if necessary. |
| 6013 | * Broken out for PRQ. |
| 6014 | */ |
| 6015 | |
| 6016 | static void brcms_c_cck_plcp_set(struct brcms_c_info *wlc, int rate_500, |
| 6017 | uint length, u8 *plcp) |
| 6018 | { |
| 6019 | u16 usec = 0; |
| 6020 | u8 le = 0; |
| 6021 | |
| 6022 | switch (rate_500) { |
| 6023 | case BRCM_RATE_1M: |
| 6024 | usec = length << 3; |
| 6025 | break; |
| 6026 | case BRCM_RATE_2M: |
| 6027 | usec = length << 2; |
| 6028 | break; |
| 6029 | case BRCM_RATE_5M5: |
| 6030 | usec = (length << 4) / 11; |
| 6031 | if ((length << 4) - (usec * 11) > 0) |
| 6032 | usec++; |
| 6033 | break; |
| 6034 | case BRCM_RATE_11M: |
| 6035 | usec = (length << 3) / 11; |
| 6036 | if ((length << 3) - (usec * 11) > 0) { |
| 6037 | usec++; |
| 6038 | if ((usec * 11) - (length << 3) >= 8) |
| 6039 | le = D11B_PLCP_SIGNAL_LE; |
| 6040 | } |
| 6041 | break; |
| 6042 | |
| 6043 | default: |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 6044 | brcms_err(wlc->hw->d11core, |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 6045 | "brcms_c_cck_plcp_set: unsupported rate %d\n", |
| 6046 | rate_500); |
| 6047 | rate_500 = BRCM_RATE_1M; |
| 6048 | usec = length << 3; |
| 6049 | break; |
| 6050 | } |
| 6051 | /* PLCP signal byte */ |
| 6052 | plcp[0] = rate_500 * 5; /* r (500kbps) * 5 == r (100kbps) */ |
| 6053 | /* PLCP service byte */ |
| 6054 | plcp[1] = (u8) (le | D11B_PLCP_SIGNAL_LOCKED); |
| 6055 | /* PLCP length u16, little endian */ |
| 6056 | plcp[2] = usec & 0xff; |
| 6057 | plcp[3] = (usec >> 8) & 0xff; |
| 6058 | /* PLCP CRC16 */ |
| 6059 | plcp[4] = 0; |
| 6060 | plcp[5] = 0; |
| 6061 | } |
| 6062 | |
| 6063 | /* Rate: 802.11 rate code, length: PSDU length in octets */ |
| 6064 | static void brcms_c_compute_mimo_plcp(u32 rspec, uint length, u8 *plcp) |
| 6065 | { |
| 6066 | u8 mcs = (u8) (rspec & RSPEC_RATE_MASK); |
| 6067 | plcp[0] = mcs; |
| 6068 | if (rspec_is40mhz(rspec) || (mcs == 32)) |
| 6069 | plcp[0] |= MIMO_PLCP_40MHZ; |
| 6070 | BRCMS_SET_MIMO_PLCP_LEN(plcp, length); |
| 6071 | plcp[3] = rspec_mimoplcp3(rspec); /* rspec already holds this byte */ |
| 6072 | plcp[3] |= 0x7; /* set smoothing, not sounding ppdu & reserved */ |
| 6073 | plcp[4] = 0; /* number of extension spatial streams bit 0 & 1 */ |
| 6074 | plcp[5] = 0; |
| 6075 | } |
| 6076 | |
| 6077 | /* Rate: 802.11 rate code, length: PSDU length in octets */ |
| 6078 | static void |
| 6079 | brcms_c_compute_ofdm_plcp(u32 rspec, u32 length, u8 *plcp) |
| 6080 | { |
| 6081 | u8 rate_signal; |
| 6082 | u32 tmp = 0; |
| 6083 | int rate = rspec2rate(rspec); |
| 6084 | |
| 6085 | /* |
| 6086 | * encode rate per 802.11a-1999 sec 17.3.4.1, with lsb |
| 6087 | * transmitted first |
| 6088 | */ |
| 6089 | rate_signal = rate_info[rate] & BRCMS_RATE_MASK; |
| 6090 | memset(plcp, 0, D11_PHY_HDR_LEN); |
| 6091 | D11A_PHY_HDR_SRATE((struct ofdm_phy_hdr *) plcp, rate_signal); |
| 6092 | |
| 6093 | tmp = (length & 0xfff) << 5; |
| 6094 | plcp[2] |= (tmp >> 16) & 0xff; |
| 6095 | plcp[1] |= (tmp >> 8) & 0xff; |
| 6096 | plcp[0] |= tmp & 0xff; |
| 6097 | } |
| 6098 | |
| 6099 | /* Rate: 802.11 rate code, length: PSDU length in octets */ |
| 6100 | static void brcms_c_compute_cck_plcp(struct brcms_c_info *wlc, u32 rspec, |
| 6101 | uint length, u8 *plcp) |
| 6102 | { |
| 6103 | int rate = rspec2rate(rspec); |
| 6104 | |
| 6105 | brcms_c_cck_plcp_set(wlc, rate, length, plcp); |
| 6106 | } |
| 6107 | |
| 6108 | static void |
| 6109 | brcms_c_compute_plcp(struct brcms_c_info *wlc, u32 rspec, |
| 6110 | uint length, u8 *plcp) |
| 6111 | { |
| 6112 | if (is_mcs_rate(rspec)) |
| 6113 | brcms_c_compute_mimo_plcp(rspec, length, plcp); |
| 6114 | else if (is_ofdm_rate(rspec)) |
| 6115 | brcms_c_compute_ofdm_plcp(rspec, length, plcp); |
| 6116 | else |
| 6117 | brcms_c_compute_cck_plcp(wlc, rspec, length, plcp); |
| 6118 | } |
| 6119 | |
| 6120 | /* brcms_c_compute_rtscts_dur() |
| 6121 | * |
| 6122 | * Calculate the 802.11 MAC header DUR field for an RTS or CTS frame |
| 6123 | * DUR for normal RTS/CTS w/ frame = 3 SIFS + 1 CTS + next frame time + 1 ACK |
| 6124 | * DUR for CTS-TO-SELF w/ frame = 2 SIFS + next frame time + 1 ACK |
| 6125 | * |
| 6126 | * cts cts-to-self or rts/cts |
| 6127 | * rts_rate rts or cts rate in unit of 500kbps |
| 6128 | * rate next MPDU rate in unit of 500kbps |
| 6129 | * frame_len next MPDU frame length in bytes |
| 6130 | */ |
| 6131 | u16 |
| 6132 | brcms_c_compute_rtscts_dur(struct brcms_c_info *wlc, bool cts_only, |
| 6133 | u32 rts_rate, |
| 6134 | u32 frame_rate, u8 rts_preamble_type, |
| 6135 | u8 frame_preamble_type, uint frame_len, bool ba) |
| 6136 | { |
| 6137 | u16 dur, sifs; |
| 6138 | |
| 6139 | sifs = get_sifs(wlc->band); |
| 6140 | |
| 6141 | if (!cts_only) { |
| 6142 | /* RTS/CTS */ |
| 6143 | dur = 3 * sifs; |
| 6144 | dur += |
| 6145 | (u16) brcms_c_calc_cts_time(wlc, rts_rate, |
| 6146 | rts_preamble_type); |
| 6147 | } else { |
| 6148 | /* CTS-TO-SELF */ |
| 6149 | dur = 2 * sifs; |
| 6150 | } |
| 6151 | |
| 6152 | dur += |
| 6153 | (u16) brcms_c_calc_frame_time(wlc, frame_rate, frame_preamble_type, |
| 6154 | frame_len); |
| 6155 | if (ba) |
| 6156 | dur += |
| 6157 | (u16) brcms_c_calc_ba_time(wlc, frame_rate, |
| 6158 | BRCMS_SHORT_PREAMBLE); |
| 6159 | else |
| 6160 | dur += |
| 6161 | (u16) brcms_c_calc_ack_time(wlc, frame_rate, |
| 6162 | frame_preamble_type); |
| 6163 | return dur; |
| 6164 | } |
| 6165 | |
| 6166 | static u16 brcms_c_phytxctl1_calc(struct brcms_c_info *wlc, u32 rspec) |
| 6167 | { |
| 6168 | u16 phyctl1 = 0; |
| 6169 | u16 bw; |
| 6170 | |
| 6171 | if (BRCMS_ISLCNPHY(wlc->band)) { |
| 6172 | bw = PHY_TXC1_BW_20MHZ; |
| 6173 | } else { |
| 6174 | bw = rspec_get_bw(rspec); |
| 6175 | /* 10Mhz is not supported yet */ |
| 6176 | if (bw < PHY_TXC1_BW_20MHZ) { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 6177 | brcms_err(wlc->hw->d11core, "phytxctl1_calc: bw %d is " |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 6178 | "not supported yet, set to 20L\n", bw); |
| 6179 | bw = PHY_TXC1_BW_20MHZ; |
| 6180 | } |
| 6181 | } |
| 6182 | |
| 6183 | if (is_mcs_rate(rspec)) { |
| 6184 | uint mcs = rspec & RSPEC_RATE_MASK; |
| 6185 | |
| 6186 | /* bw, stf, coding-type is part of rspec_phytxbyte2 returns */ |
| 6187 | phyctl1 = rspec_phytxbyte2(rspec); |
| 6188 | /* set the upper byte of phyctl1 */ |
| 6189 | phyctl1 |= (mcs_table[mcs].tx_phy_ctl3 << 8); |
| 6190 | } else if (is_cck_rate(rspec) && !BRCMS_ISLCNPHY(wlc->band) |
| 6191 | && !BRCMS_ISSSLPNPHY(wlc->band)) { |
| 6192 | /* |
| 6193 | * In CCK mode LPPHY overloads OFDM Modulation bits with CCK |
| 6194 | * Data Rate. Eventually MIMOPHY would also be converted to |
| 6195 | * this format |
| 6196 | */ |
| 6197 | /* 0 = 1Mbps; 1 = 2Mbps; 2 = 5.5Mbps; 3 = 11Mbps */ |
| 6198 | phyctl1 = (bw | (rspec_stf(rspec) << PHY_TXC1_MODE_SHIFT)); |
| 6199 | } else { /* legacy OFDM/CCK */ |
| 6200 | s16 phycfg; |
| 6201 | /* get the phyctl byte from rate phycfg table */ |
| 6202 | phycfg = brcms_c_rate_legacy_phyctl(rspec2rate(rspec)); |
| 6203 | if (phycfg == -1) { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 6204 | brcms_err(wlc->hw->d11core, "phytxctl1_calc: wrong " |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 6205 | "legacy OFDM/CCK rate\n"); |
| 6206 | phycfg = 0; |
| 6207 | } |
| 6208 | /* set the upper byte of phyctl1 */ |
| 6209 | phyctl1 = |
| 6210 | (bw | (phycfg << 8) | |
| 6211 | (rspec_stf(rspec) << PHY_TXC1_MODE_SHIFT)); |
| 6212 | } |
| 6213 | return phyctl1; |
| 6214 | } |
| 6215 | |
| 6216 | /* |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6217 | * Add struct d11txh, struct cck_phy_hdr. |
| 6218 | * |
| 6219 | * 'p' data must start with 802.11 MAC header |
| 6220 | * 'p' must allow enough bytes of local headers to be "pushed" onto the packet |
| 6221 | * |
| 6222 | * headroom == D11_PHY_HDR_LEN + D11_TXH_LEN (D11_TXH_LEN is now 104 bytes) |
| 6223 | * |
| 6224 | */ |
| 6225 | static u16 |
| 6226 | brcms_c_d11hdrs_mac80211(struct brcms_c_info *wlc, struct ieee80211_hw *hw, |
| 6227 | struct sk_buff *p, struct scb *scb, uint frag, |
| 6228 | uint nfrags, uint queue, uint next_frag_len) |
| 6229 | { |
| 6230 | struct ieee80211_hdr *h; |
| 6231 | struct d11txh *txh; |
| 6232 | u8 *plcp, plcp_fallback[D11_PHY_HDR_LEN]; |
| 6233 | int len, phylen, rts_phylen; |
| 6234 | u16 mch, phyctl, xfts, mainrates; |
| 6235 | u16 seq = 0, mcl = 0, status = 0, frameid = 0; |
| 6236 | u32 rspec[2] = { BRCM_RATE_1M, BRCM_RATE_1M }; |
| 6237 | u32 rts_rspec[2] = { BRCM_RATE_1M, BRCM_RATE_1M }; |
| 6238 | bool use_rts = false; |
| 6239 | bool use_cts = false; |
| 6240 | bool use_rifs = false; |
| 6241 | bool short_preamble[2] = { false, false }; |
| 6242 | u8 preamble_type[2] = { BRCMS_LONG_PREAMBLE, BRCMS_LONG_PREAMBLE }; |
| 6243 | u8 rts_preamble_type[2] = { BRCMS_LONG_PREAMBLE, BRCMS_LONG_PREAMBLE }; |
| 6244 | u8 *rts_plcp, rts_plcp_fallback[D11_PHY_HDR_LEN]; |
| 6245 | struct ieee80211_rts *rts = NULL; |
| 6246 | bool qos; |
| 6247 | uint ac; |
| 6248 | bool hwtkmic = false; |
| 6249 | u16 mimo_ctlchbw = PHY_TXC1_BW_20MHZ; |
| 6250 | #define ANTCFG_NONE 0xFF |
| 6251 | u8 antcfg = ANTCFG_NONE; |
| 6252 | u8 fbantcfg = ANTCFG_NONE; |
| 6253 | uint phyctl1_stf = 0; |
| 6254 | u16 durid = 0; |
| 6255 | struct ieee80211_tx_rate *txrate[2]; |
| 6256 | int k; |
| 6257 | struct ieee80211_tx_info *tx_info; |
| 6258 | bool is_mcs; |
| 6259 | u16 mimo_txbw; |
| 6260 | u8 mimo_preamble_type; |
| 6261 | |
| 6262 | /* locate 802.11 MAC header */ |
| 6263 | h = (struct ieee80211_hdr *)(p->data); |
| 6264 | qos = ieee80211_is_data_qos(h->frame_control); |
| 6265 | |
| 6266 | /* compute length of frame in bytes for use in PLCP computations */ |
Arend van Spriel | ad4d71f | 2011-11-10 20:30:26 +0100 | [diff] [blame] | 6267 | len = p->len; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6268 | phylen = len + FCS_LEN; |
| 6269 | |
| 6270 | /* Get tx_info */ |
| 6271 | tx_info = IEEE80211_SKB_CB(p); |
| 6272 | |
| 6273 | /* add PLCP */ |
| 6274 | plcp = skb_push(p, D11_PHY_HDR_LEN); |
| 6275 | |
| 6276 | /* add Broadcom tx descriptor header */ |
| 6277 | txh = (struct d11txh *) skb_push(p, D11_TXH_LEN); |
| 6278 | memset(txh, 0, D11_TXH_LEN); |
| 6279 | |
| 6280 | /* setup frameid */ |
| 6281 | if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) { |
| 6282 | /* non-AP STA should never use BCMC queue */ |
| 6283 | if (queue == TX_BCMC_FIFO) { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 6284 | brcms_err(wlc->hw->d11core, |
| 6285 | "wl%d: %s: ASSERT queue == TX_BCMC!\n", |
| 6286 | wlc->pub->unit, __func__); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6287 | frameid = bcmc_fid_generate(wlc, NULL, txh); |
| 6288 | } else { |
| 6289 | /* Increment the counter for first fragment */ |
| 6290 | if (tx_info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT) |
| 6291 | scb->seqnum[p->priority]++; |
| 6292 | |
| 6293 | /* extract fragment number from frame first */ |
| 6294 | seq = le16_to_cpu(h->seq_ctrl) & FRAGNUM_MASK; |
| 6295 | seq |= (scb->seqnum[p->priority] << SEQNUM_SHIFT); |
| 6296 | h->seq_ctrl = cpu_to_le16(seq); |
| 6297 | |
| 6298 | frameid = ((seq << TXFID_SEQ_SHIFT) & TXFID_SEQ_MASK) | |
| 6299 | (queue & TXFID_QUEUE_MASK); |
| 6300 | } |
| 6301 | } |
| 6302 | frameid |= queue & TXFID_QUEUE_MASK; |
| 6303 | |
| 6304 | /* set the ignpmq bit for all pkts tx'd in PS mode and for beacons */ |
| 6305 | if (ieee80211_is_beacon(h->frame_control)) |
| 6306 | mcl |= TXC_IGNOREPMQ; |
| 6307 | |
| 6308 | txrate[0] = tx_info->control.rates; |
| 6309 | txrate[1] = txrate[0] + 1; |
| 6310 | |
| 6311 | /* |
| 6312 | * if rate control algorithm didn't give us a fallback |
| 6313 | * rate, use the primary rate |
| 6314 | */ |
| 6315 | if (txrate[1]->idx < 0) |
| 6316 | txrate[1] = txrate[0]; |
| 6317 | |
| 6318 | for (k = 0; k < hw->max_rates; k++) { |
| 6319 | is_mcs = txrate[k]->flags & IEEE80211_TX_RC_MCS ? true : false; |
| 6320 | if (!is_mcs) { |
| 6321 | if ((txrate[k]->idx >= 0) |
| 6322 | && (txrate[k]->idx < |
| 6323 | hw->wiphy->bands[tx_info->band]->n_bitrates)) { |
| 6324 | rspec[k] = |
| 6325 | hw->wiphy->bands[tx_info->band]-> |
| 6326 | bitrates[txrate[k]->idx].hw_value; |
| 6327 | short_preamble[k] = |
| 6328 | txrate[k]-> |
| 6329 | flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE ? |
| 6330 | true : false; |
| 6331 | } else { |
| 6332 | rspec[k] = BRCM_RATE_1M; |
| 6333 | } |
| 6334 | } else { |
| 6335 | rspec[k] = mac80211_wlc_set_nrate(wlc, wlc->band, |
| 6336 | NRATE_MCS_INUSE | txrate[k]->idx); |
| 6337 | } |
| 6338 | |
| 6339 | /* |
| 6340 | * Currently only support same setting for primay and |
| 6341 | * fallback rates. Unify flags for each rate into a |
| 6342 | * single value for the frame |
| 6343 | */ |
| 6344 | use_rts |= |
| 6345 | txrate[k]-> |
| 6346 | flags & IEEE80211_TX_RC_USE_RTS_CTS ? true : false; |
| 6347 | use_cts |= |
| 6348 | txrate[k]-> |
| 6349 | flags & IEEE80211_TX_RC_USE_CTS_PROTECT ? true : false; |
| 6350 | |
| 6351 | |
| 6352 | /* |
| 6353 | * (1) RATE: |
| 6354 | * determine and validate primary rate |
| 6355 | * and fallback rates |
| 6356 | */ |
| 6357 | if (!rspec_active(rspec[k])) { |
| 6358 | rspec[k] = BRCM_RATE_1M; |
| 6359 | } else { |
| 6360 | if (!is_multicast_ether_addr(h->addr1)) { |
| 6361 | /* set tx antenna config */ |
| 6362 | brcms_c_antsel_antcfg_get(wlc->asi, false, |
| 6363 | false, 0, 0, &antcfg, &fbantcfg); |
| 6364 | } |
| 6365 | } |
| 6366 | } |
| 6367 | |
| 6368 | phyctl1_stf = wlc->stf->ss_opmode; |
| 6369 | |
| 6370 | if (wlc->pub->_n_enab & SUPPORT_11N) { |
| 6371 | for (k = 0; k < hw->max_rates; k++) { |
| 6372 | /* |
| 6373 | * apply siso/cdd to single stream mcs's or ofdm |
| 6374 | * if rspec is auto selected |
| 6375 | */ |
| 6376 | if (((is_mcs_rate(rspec[k]) && |
| 6377 | is_single_stream(rspec[k] & RSPEC_RATE_MASK)) || |
| 6378 | is_ofdm_rate(rspec[k])) |
| 6379 | && ((rspec[k] & RSPEC_OVERRIDE_MCS_ONLY) |
| 6380 | || !(rspec[k] & RSPEC_OVERRIDE))) { |
| 6381 | rspec[k] &= ~(RSPEC_STF_MASK | RSPEC_STC_MASK); |
| 6382 | |
| 6383 | /* For SISO MCS use STBC if possible */ |
| 6384 | if (is_mcs_rate(rspec[k]) |
| 6385 | && BRCMS_STF_SS_STBC_TX(wlc, scb)) { |
| 6386 | u8 stc; |
| 6387 | |
| 6388 | /* Nss for single stream is always 1 */ |
| 6389 | stc = 1; |
| 6390 | rspec[k] |= (PHY_TXC1_MODE_STBC << |
| 6391 | RSPEC_STF_SHIFT) | |
| 6392 | (stc << RSPEC_STC_SHIFT); |
| 6393 | } else |
| 6394 | rspec[k] |= |
| 6395 | (phyctl1_stf << RSPEC_STF_SHIFT); |
| 6396 | } |
| 6397 | |
| 6398 | /* |
| 6399 | * Is the phy configured to use 40MHZ frames? If |
| 6400 | * so then pick the desired txbw |
| 6401 | */ |
| 6402 | if (brcms_chspec_bw(wlc->chanspec) == BRCMS_40_MHZ) { |
| 6403 | /* default txbw is 20in40 SB */ |
| 6404 | mimo_ctlchbw = mimo_txbw = |
| 6405 | CHSPEC_SB_UPPER(wlc_phy_chanspec_get( |
| 6406 | wlc->band->pi)) |
| 6407 | ? PHY_TXC1_BW_20MHZ_UP : PHY_TXC1_BW_20MHZ; |
| 6408 | |
| 6409 | if (is_mcs_rate(rspec[k])) { |
| 6410 | /* mcs 32 must be 40b/w DUP */ |
| 6411 | if ((rspec[k] & RSPEC_RATE_MASK) |
| 6412 | == 32) { |
| 6413 | mimo_txbw = |
| 6414 | PHY_TXC1_BW_40MHZ_DUP; |
| 6415 | /* use override */ |
| 6416 | } else if (wlc->mimo_40txbw != AUTO) |
| 6417 | mimo_txbw = wlc->mimo_40txbw; |
| 6418 | /* else check if dst is using 40 Mhz */ |
| 6419 | else if (scb->flags & SCB_IS40) |
| 6420 | mimo_txbw = PHY_TXC1_BW_40MHZ; |
| 6421 | } else if (is_ofdm_rate(rspec[k])) { |
| 6422 | if (wlc->ofdm_40txbw != AUTO) |
| 6423 | mimo_txbw = wlc->ofdm_40txbw; |
| 6424 | } else if (wlc->cck_40txbw != AUTO) { |
| 6425 | mimo_txbw = wlc->cck_40txbw; |
| 6426 | } |
| 6427 | } else { |
| 6428 | /* |
| 6429 | * mcs32 is 40 b/w only. |
| 6430 | * This is possible for probe packets on |
| 6431 | * a STA during SCAN |
| 6432 | */ |
| 6433 | if ((rspec[k] & RSPEC_RATE_MASK) == 32) |
| 6434 | /* mcs 0 */ |
| 6435 | rspec[k] = RSPEC_MIMORATE; |
| 6436 | |
| 6437 | mimo_txbw = PHY_TXC1_BW_20MHZ; |
| 6438 | } |
| 6439 | |
| 6440 | /* Set channel width */ |
| 6441 | rspec[k] &= ~RSPEC_BW_MASK; |
| 6442 | if ((k == 0) || ((k > 0) && is_mcs_rate(rspec[k]))) |
| 6443 | rspec[k] |= (mimo_txbw << RSPEC_BW_SHIFT); |
| 6444 | else |
| 6445 | rspec[k] |= (mimo_ctlchbw << RSPEC_BW_SHIFT); |
| 6446 | |
| 6447 | /* Disable short GI, not supported yet */ |
| 6448 | rspec[k] &= ~RSPEC_SHORT_GI; |
| 6449 | |
| 6450 | mimo_preamble_type = BRCMS_MM_PREAMBLE; |
| 6451 | if (txrate[k]->flags & IEEE80211_TX_RC_GREEN_FIELD) |
| 6452 | mimo_preamble_type = BRCMS_GF_PREAMBLE; |
| 6453 | |
| 6454 | if ((txrate[k]->flags & IEEE80211_TX_RC_MCS) |
| 6455 | && (!is_mcs_rate(rspec[k]))) { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 6456 | brcms_err(wlc->hw->d11core, |
| 6457 | "wl%d: %s: IEEE80211_TX_" |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6458 | "RC_MCS != is_mcs_rate(rspec)\n", |
| 6459 | wlc->pub->unit, __func__); |
| 6460 | } |
| 6461 | |
| 6462 | if (is_mcs_rate(rspec[k])) { |
| 6463 | preamble_type[k] = mimo_preamble_type; |
| 6464 | |
| 6465 | /* |
| 6466 | * if SGI is selected, then forced mm |
| 6467 | * for single stream |
| 6468 | */ |
| 6469 | if ((rspec[k] & RSPEC_SHORT_GI) |
| 6470 | && is_single_stream(rspec[k] & |
| 6471 | RSPEC_RATE_MASK)) |
| 6472 | preamble_type[k] = BRCMS_MM_PREAMBLE; |
| 6473 | } |
| 6474 | |
| 6475 | /* should be better conditionalized */ |
| 6476 | if (!is_mcs_rate(rspec[0]) |
| 6477 | && (tx_info->control.rates[0]. |
| 6478 | flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)) |
| 6479 | preamble_type[k] = BRCMS_SHORT_PREAMBLE; |
| 6480 | } |
| 6481 | } else { |
| 6482 | for (k = 0; k < hw->max_rates; k++) { |
| 6483 | /* Set ctrlchbw as 20Mhz */ |
| 6484 | rspec[k] &= ~RSPEC_BW_MASK; |
| 6485 | rspec[k] |= (PHY_TXC1_BW_20MHZ << RSPEC_BW_SHIFT); |
| 6486 | |
| 6487 | /* for nphy, stf of ofdm frames must follow policies */ |
| 6488 | if (BRCMS_ISNPHY(wlc->band) && is_ofdm_rate(rspec[k])) { |
| 6489 | rspec[k] &= ~RSPEC_STF_MASK; |
| 6490 | rspec[k] |= phyctl1_stf << RSPEC_STF_SHIFT; |
| 6491 | } |
| 6492 | } |
| 6493 | } |
| 6494 | |
| 6495 | /* Reset these for use with AMPDU's */ |
| 6496 | txrate[0]->count = 0; |
| 6497 | txrate[1]->count = 0; |
| 6498 | |
| 6499 | /* (2) PROTECTION, may change rspec */ |
| 6500 | if ((ieee80211_is_data(h->frame_control) || |
| 6501 | ieee80211_is_mgmt(h->frame_control)) && |
| 6502 | (phylen > wlc->RTSThresh) && !is_multicast_ether_addr(h->addr1)) |
| 6503 | use_rts = true; |
| 6504 | |
| 6505 | /* (3) PLCP: determine PLCP header and MAC duration, |
| 6506 | * fill struct d11txh */ |
| 6507 | brcms_c_compute_plcp(wlc, rspec[0], phylen, plcp); |
| 6508 | brcms_c_compute_plcp(wlc, rspec[1], phylen, plcp_fallback); |
| 6509 | memcpy(&txh->FragPLCPFallback, |
| 6510 | plcp_fallback, sizeof(txh->FragPLCPFallback)); |
| 6511 | |
| 6512 | /* Length field now put in CCK FBR CRC field */ |
| 6513 | if (is_cck_rate(rspec[1])) { |
| 6514 | txh->FragPLCPFallback[4] = phylen & 0xff; |
| 6515 | txh->FragPLCPFallback[5] = (phylen & 0xff00) >> 8; |
| 6516 | } |
| 6517 | |
| 6518 | /* MIMO-RATE: need validation ?? */ |
| 6519 | mainrates = is_ofdm_rate(rspec[0]) ? |
| 6520 | D11A_PHY_HDR_GRATE((struct ofdm_phy_hdr *) plcp) : |
| 6521 | plcp[0]; |
| 6522 | |
| 6523 | /* DUR field for main rate */ |
| 6524 | if (!ieee80211_is_pspoll(h->frame_control) && |
| 6525 | !is_multicast_ether_addr(h->addr1) && !use_rifs) { |
| 6526 | durid = |
| 6527 | brcms_c_compute_frame_dur(wlc, rspec[0], preamble_type[0], |
| 6528 | next_frag_len); |
| 6529 | h->duration_id = cpu_to_le16(durid); |
| 6530 | } else if (use_rifs) { |
| 6531 | /* NAV protect to end of next max packet size */ |
| 6532 | durid = |
| 6533 | (u16) brcms_c_calc_frame_time(wlc, rspec[0], |
| 6534 | preamble_type[0], |
| 6535 | DOT11_MAX_FRAG_LEN); |
| 6536 | durid += RIFS_11N_TIME; |
| 6537 | h->duration_id = cpu_to_le16(durid); |
| 6538 | } |
| 6539 | |
| 6540 | /* DUR field for fallback rate */ |
| 6541 | if (ieee80211_is_pspoll(h->frame_control)) |
| 6542 | txh->FragDurFallback = h->duration_id; |
| 6543 | else if (is_multicast_ether_addr(h->addr1) || use_rifs) |
| 6544 | txh->FragDurFallback = 0; |
| 6545 | else { |
| 6546 | durid = brcms_c_compute_frame_dur(wlc, rspec[1], |
| 6547 | preamble_type[1], next_frag_len); |
| 6548 | txh->FragDurFallback = cpu_to_le16(durid); |
| 6549 | } |
| 6550 | |
| 6551 | /* (4) MAC-HDR: MacTxControlLow */ |
| 6552 | if (frag == 0) |
| 6553 | mcl |= TXC_STARTMSDU; |
| 6554 | |
| 6555 | if (!is_multicast_ether_addr(h->addr1)) |
| 6556 | mcl |= TXC_IMMEDACK; |
| 6557 | |
| 6558 | if (wlc->band->bandtype == BRCM_BAND_5G) |
| 6559 | mcl |= TXC_FREQBAND_5G; |
| 6560 | |
| 6561 | if (CHSPEC_IS40(wlc_phy_chanspec_get(wlc->band->pi))) |
| 6562 | mcl |= TXC_BW_40; |
| 6563 | |
| 6564 | /* set AMIC bit if using hardware TKIP MIC */ |
| 6565 | if (hwtkmic) |
| 6566 | mcl |= TXC_AMIC; |
| 6567 | |
| 6568 | txh->MacTxControlLow = cpu_to_le16(mcl); |
| 6569 | |
| 6570 | /* MacTxControlHigh */ |
| 6571 | mch = 0; |
| 6572 | |
| 6573 | /* Set fallback rate preamble type */ |
| 6574 | if ((preamble_type[1] == BRCMS_SHORT_PREAMBLE) || |
| 6575 | (preamble_type[1] == BRCMS_GF_PREAMBLE)) { |
| 6576 | if (rspec2rate(rspec[1]) != BRCM_RATE_1M) |
| 6577 | mch |= TXC_PREAMBLE_DATA_FB_SHORT; |
| 6578 | } |
| 6579 | |
| 6580 | /* MacFrameControl */ |
| 6581 | memcpy(&txh->MacFrameControl, &h->frame_control, sizeof(u16)); |
| 6582 | txh->TxFesTimeNormal = cpu_to_le16(0); |
| 6583 | |
| 6584 | txh->TxFesTimeFallback = cpu_to_le16(0); |
| 6585 | |
| 6586 | /* TxFrameRA */ |
| 6587 | memcpy(&txh->TxFrameRA, &h->addr1, ETH_ALEN); |
| 6588 | |
| 6589 | /* TxFrameID */ |
| 6590 | txh->TxFrameID = cpu_to_le16(frameid); |
| 6591 | |
| 6592 | /* |
| 6593 | * TxStatus, Note the case of recreating the first frag of a suppressed |
| 6594 | * frame then we may need to reset the retry cnt's via the status reg |
| 6595 | */ |
| 6596 | txh->TxStatus = cpu_to_le16(status); |
| 6597 | |
| 6598 | /* |
| 6599 | * extra fields for ucode AMPDU aggregation, the new fields are added to |
| 6600 | * the END of previous structure so that it's compatible in driver. |
| 6601 | */ |
| 6602 | txh->MaxNMpdus = cpu_to_le16(0); |
| 6603 | txh->MaxABytes_MRT = cpu_to_le16(0); |
| 6604 | txh->MaxABytes_FBR = cpu_to_le16(0); |
| 6605 | txh->MinMBytes = cpu_to_le16(0); |
| 6606 | |
| 6607 | /* (5) RTS/CTS: determine RTS/CTS PLCP header and MAC duration, |
| 6608 | * furnish struct d11txh */ |
| 6609 | /* RTS PLCP header and RTS frame */ |
| 6610 | if (use_rts || use_cts) { |
| 6611 | if (use_rts && use_cts) |
| 6612 | use_cts = false; |
| 6613 | |
| 6614 | for (k = 0; k < 2; k++) { |
| 6615 | rts_rspec[k] = brcms_c_rspec_to_rts_rspec(wlc, rspec[k], |
| 6616 | false, |
| 6617 | mimo_ctlchbw); |
| 6618 | } |
| 6619 | |
| 6620 | if (!is_ofdm_rate(rts_rspec[0]) && |
| 6621 | !((rspec2rate(rts_rspec[0]) == BRCM_RATE_1M) || |
| 6622 | (wlc->PLCPHdr_override == BRCMS_PLCP_LONG))) { |
| 6623 | rts_preamble_type[0] = BRCMS_SHORT_PREAMBLE; |
| 6624 | mch |= TXC_PREAMBLE_RTS_MAIN_SHORT; |
| 6625 | } |
| 6626 | |
| 6627 | if (!is_ofdm_rate(rts_rspec[1]) && |
| 6628 | !((rspec2rate(rts_rspec[1]) == BRCM_RATE_1M) || |
| 6629 | (wlc->PLCPHdr_override == BRCMS_PLCP_LONG))) { |
| 6630 | rts_preamble_type[1] = BRCMS_SHORT_PREAMBLE; |
| 6631 | mch |= TXC_PREAMBLE_RTS_FB_SHORT; |
| 6632 | } |
| 6633 | |
| 6634 | /* RTS/CTS additions to MacTxControlLow */ |
| 6635 | if (use_cts) { |
| 6636 | txh->MacTxControlLow |= cpu_to_le16(TXC_SENDCTS); |
| 6637 | } else { |
| 6638 | txh->MacTxControlLow |= cpu_to_le16(TXC_SENDRTS); |
| 6639 | txh->MacTxControlLow |= cpu_to_le16(TXC_LONGFRAME); |
| 6640 | } |
| 6641 | |
| 6642 | /* RTS PLCP header */ |
| 6643 | rts_plcp = txh->RTSPhyHeader; |
| 6644 | if (use_cts) |
| 6645 | rts_phylen = DOT11_CTS_LEN + FCS_LEN; |
| 6646 | else |
| 6647 | rts_phylen = DOT11_RTS_LEN + FCS_LEN; |
| 6648 | |
| 6649 | brcms_c_compute_plcp(wlc, rts_rspec[0], rts_phylen, rts_plcp); |
| 6650 | |
| 6651 | /* fallback rate version of RTS PLCP header */ |
| 6652 | brcms_c_compute_plcp(wlc, rts_rspec[1], rts_phylen, |
| 6653 | rts_plcp_fallback); |
| 6654 | memcpy(&txh->RTSPLCPFallback, rts_plcp_fallback, |
| 6655 | sizeof(txh->RTSPLCPFallback)); |
| 6656 | |
| 6657 | /* RTS frame fields... */ |
| 6658 | rts = (struct ieee80211_rts *)&txh->rts_frame; |
| 6659 | |
| 6660 | durid = brcms_c_compute_rtscts_dur(wlc, use_cts, rts_rspec[0], |
| 6661 | rspec[0], rts_preamble_type[0], |
| 6662 | preamble_type[0], phylen, false); |
| 6663 | rts->duration = cpu_to_le16(durid); |
| 6664 | /* fallback rate version of RTS DUR field */ |
| 6665 | durid = brcms_c_compute_rtscts_dur(wlc, use_cts, |
| 6666 | rts_rspec[1], rspec[1], |
| 6667 | rts_preamble_type[1], |
| 6668 | preamble_type[1], phylen, false); |
| 6669 | txh->RTSDurFallback = cpu_to_le16(durid); |
| 6670 | |
| 6671 | if (use_cts) { |
| 6672 | rts->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL | |
| 6673 | IEEE80211_STYPE_CTS); |
| 6674 | |
| 6675 | memcpy(&rts->ra, &h->addr2, ETH_ALEN); |
| 6676 | } else { |
| 6677 | rts->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL | |
| 6678 | IEEE80211_STYPE_RTS); |
| 6679 | |
| 6680 | memcpy(&rts->ra, &h->addr1, 2 * ETH_ALEN); |
| 6681 | } |
| 6682 | |
| 6683 | /* mainrate |
| 6684 | * low 8 bits: main frag rate/mcs, |
| 6685 | * high 8 bits: rts/cts rate/mcs |
| 6686 | */ |
| 6687 | mainrates |= (is_ofdm_rate(rts_rspec[0]) ? |
| 6688 | D11A_PHY_HDR_GRATE( |
| 6689 | (struct ofdm_phy_hdr *) rts_plcp) : |
| 6690 | rts_plcp[0]) << 8; |
| 6691 | } else { |
| 6692 | memset((char *)txh->RTSPhyHeader, 0, D11_PHY_HDR_LEN); |
| 6693 | memset((char *)&txh->rts_frame, 0, |
| 6694 | sizeof(struct ieee80211_rts)); |
| 6695 | memset((char *)txh->RTSPLCPFallback, 0, |
| 6696 | sizeof(txh->RTSPLCPFallback)); |
| 6697 | txh->RTSDurFallback = 0; |
| 6698 | } |
| 6699 | |
| 6700 | #ifdef SUPPORT_40MHZ |
| 6701 | /* add null delimiter count */ |
| 6702 | if ((tx_info->flags & IEEE80211_TX_CTL_AMPDU) && is_mcs_rate(rspec)) |
| 6703 | txh->RTSPLCPFallback[AMPDU_FBR_NULL_DELIM] = |
| 6704 | brcm_c_ampdu_null_delim_cnt(wlc->ampdu, scb, rspec, phylen); |
| 6705 | |
| 6706 | #endif |
| 6707 | |
| 6708 | /* |
| 6709 | * Now that RTS/RTS FB preamble types are updated, write |
| 6710 | * the final value |
| 6711 | */ |
| 6712 | txh->MacTxControlHigh = cpu_to_le16(mch); |
| 6713 | |
| 6714 | /* |
| 6715 | * MainRates (both the rts and frag plcp rates have |
| 6716 | * been calculated now) |
| 6717 | */ |
| 6718 | txh->MainRates = cpu_to_le16(mainrates); |
| 6719 | |
| 6720 | /* XtraFrameTypes */ |
| 6721 | xfts = frametype(rspec[1], wlc->mimoft); |
| 6722 | xfts |= (frametype(rts_rspec[0], wlc->mimoft) << XFTS_RTS_FT_SHIFT); |
| 6723 | xfts |= (frametype(rts_rspec[1], wlc->mimoft) << XFTS_FBRRTS_FT_SHIFT); |
| 6724 | xfts |= CHSPEC_CHANNEL(wlc_phy_chanspec_get(wlc->band->pi)) << |
| 6725 | XFTS_CHANNEL_SHIFT; |
| 6726 | txh->XtraFrameTypes = cpu_to_le16(xfts); |
| 6727 | |
| 6728 | /* PhyTxControlWord */ |
| 6729 | phyctl = frametype(rspec[0], wlc->mimoft); |
| 6730 | if ((preamble_type[0] == BRCMS_SHORT_PREAMBLE) || |
| 6731 | (preamble_type[0] == BRCMS_GF_PREAMBLE)) { |
| 6732 | if (rspec2rate(rspec[0]) != BRCM_RATE_1M) |
| 6733 | phyctl |= PHY_TXC_SHORT_HDR; |
| 6734 | } |
| 6735 | |
| 6736 | /* phytxant is properly bit shifted */ |
| 6737 | phyctl |= brcms_c_stf_d11hdrs_phyctl_txant(wlc, rspec[0]); |
| 6738 | txh->PhyTxControlWord = cpu_to_le16(phyctl); |
| 6739 | |
| 6740 | /* PhyTxControlWord_1 */ |
| 6741 | if (BRCMS_PHY_11N_CAP(wlc->band)) { |
| 6742 | u16 phyctl1 = 0; |
| 6743 | |
| 6744 | phyctl1 = brcms_c_phytxctl1_calc(wlc, rspec[0]); |
| 6745 | txh->PhyTxControlWord_1 = cpu_to_le16(phyctl1); |
| 6746 | phyctl1 = brcms_c_phytxctl1_calc(wlc, rspec[1]); |
| 6747 | txh->PhyTxControlWord_1_Fbr = cpu_to_le16(phyctl1); |
| 6748 | |
| 6749 | if (use_rts || use_cts) { |
| 6750 | phyctl1 = brcms_c_phytxctl1_calc(wlc, rts_rspec[0]); |
| 6751 | txh->PhyTxControlWord_1_Rts = cpu_to_le16(phyctl1); |
| 6752 | phyctl1 = brcms_c_phytxctl1_calc(wlc, rts_rspec[1]); |
| 6753 | txh->PhyTxControlWord_1_FbrRts = cpu_to_le16(phyctl1); |
| 6754 | } |
| 6755 | |
| 6756 | /* |
| 6757 | * For mcs frames, if mixedmode(overloaded with long preamble) |
| 6758 | * is going to be set, fill in non-zero MModeLen and/or |
| 6759 | * MModeFbrLen it will be unnecessary if they are separated |
| 6760 | */ |
| 6761 | if (is_mcs_rate(rspec[0]) && |
| 6762 | (preamble_type[0] == BRCMS_MM_PREAMBLE)) { |
| 6763 | u16 mmodelen = |
| 6764 | brcms_c_calc_lsig_len(wlc, rspec[0], phylen); |
| 6765 | txh->MModeLen = cpu_to_le16(mmodelen); |
| 6766 | } |
| 6767 | |
| 6768 | if (is_mcs_rate(rspec[1]) && |
| 6769 | (preamble_type[1] == BRCMS_MM_PREAMBLE)) { |
| 6770 | u16 mmodefbrlen = |
| 6771 | brcms_c_calc_lsig_len(wlc, rspec[1], phylen); |
| 6772 | txh->MModeFbrLen = cpu_to_le16(mmodefbrlen); |
| 6773 | } |
| 6774 | } |
| 6775 | |
| 6776 | ac = skb_get_queue_mapping(p); |
| 6777 | if ((scb->flags & SCB_WMECAP) && qos && wlc->edcf_txop[ac]) { |
| 6778 | uint frag_dur, dur, dur_fallback; |
| 6779 | |
| 6780 | /* WME: Update TXOP threshold */ |
| 6781 | if (!(tx_info->flags & IEEE80211_TX_CTL_AMPDU) && frag == 0) { |
| 6782 | frag_dur = |
| 6783 | brcms_c_calc_frame_time(wlc, rspec[0], |
| 6784 | preamble_type[0], phylen); |
| 6785 | |
| 6786 | if (rts) { |
| 6787 | /* 1 RTS or CTS-to-self frame */ |
| 6788 | dur = |
| 6789 | brcms_c_calc_cts_time(wlc, rts_rspec[0], |
| 6790 | rts_preamble_type[0]); |
| 6791 | dur_fallback = |
| 6792 | brcms_c_calc_cts_time(wlc, rts_rspec[1], |
| 6793 | rts_preamble_type[1]); |
| 6794 | /* (SIFS + CTS) + SIFS + frame + SIFS + ACK */ |
| 6795 | dur += le16_to_cpu(rts->duration); |
| 6796 | dur_fallback += |
| 6797 | le16_to_cpu(txh->RTSDurFallback); |
| 6798 | } else if (use_rifs) { |
| 6799 | dur = frag_dur; |
| 6800 | dur_fallback = 0; |
| 6801 | } else { |
| 6802 | /* frame + SIFS + ACK */ |
| 6803 | dur = frag_dur; |
| 6804 | dur += |
| 6805 | brcms_c_compute_frame_dur(wlc, rspec[0], |
| 6806 | preamble_type[0], 0); |
| 6807 | |
| 6808 | dur_fallback = |
| 6809 | brcms_c_calc_frame_time(wlc, rspec[1], |
| 6810 | preamble_type[1], |
| 6811 | phylen); |
| 6812 | dur_fallback += |
| 6813 | brcms_c_compute_frame_dur(wlc, rspec[1], |
| 6814 | preamble_type[1], 0); |
| 6815 | } |
| 6816 | /* NEED to set TxFesTimeNormal (hard) */ |
| 6817 | txh->TxFesTimeNormal = cpu_to_le16((u16) dur); |
| 6818 | /* |
| 6819 | * NEED to set fallback rate version of |
| 6820 | * TxFesTimeNormal (hard) |
| 6821 | */ |
| 6822 | txh->TxFesTimeFallback = |
| 6823 | cpu_to_le16((u16) dur_fallback); |
| 6824 | |
| 6825 | /* |
| 6826 | * update txop byte threshold (txop minus intraframe |
| 6827 | * overhead) |
| 6828 | */ |
| 6829 | if (wlc->edcf_txop[ac] >= (dur - frag_dur)) { |
| 6830 | uint newfragthresh; |
| 6831 | |
| 6832 | newfragthresh = |
| 6833 | brcms_c_calc_frame_len(wlc, |
| 6834 | rspec[0], preamble_type[0], |
| 6835 | (wlc->edcf_txop[ac] - |
| 6836 | (dur - frag_dur))); |
| 6837 | /* range bound the fragthreshold */ |
| 6838 | if (newfragthresh < DOT11_MIN_FRAG_LEN) |
| 6839 | newfragthresh = |
| 6840 | DOT11_MIN_FRAG_LEN; |
| 6841 | else if (newfragthresh > |
| 6842 | wlc->usr_fragthresh) |
| 6843 | newfragthresh = |
| 6844 | wlc->usr_fragthresh; |
| 6845 | /* update the fragthresh and do txc update */ |
| 6846 | if (wlc->fragthresh[queue] != |
| 6847 | (u16) newfragthresh) |
| 6848 | wlc->fragthresh[queue] = |
| 6849 | (u16) newfragthresh; |
| 6850 | } else { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 6851 | brcms_err(wlc->hw->d11core, |
| 6852 | "wl%d: %s txop invalid " |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6853 | "for rate %d\n", |
| 6854 | wlc->pub->unit, fifo_names[queue], |
| 6855 | rspec2rate(rspec[0])); |
| 6856 | } |
| 6857 | |
| 6858 | if (dur > wlc->edcf_txop[ac]) |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 6859 | brcms_err(wlc->hw->d11core, |
| 6860 | "wl%d: %s: %s txop " |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6861 | "exceeded phylen %d/%d dur %d/%d\n", |
| 6862 | wlc->pub->unit, __func__, |
| 6863 | fifo_names[queue], |
| 6864 | phylen, wlc->fragthresh[queue], |
| 6865 | dur, wlc->edcf_txop[ac]); |
| 6866 | } |
| 6867 | } |
| 6868 | |
| 6869 | return 0; |
| 6870 | } |
| 6871 | |
Seth Forshee | e041f65 | 2012-11-15 08:07:56 -0600 | [diff] [blame] | 6872 | static int brcms_c_tx(struct brcms_c_info *wlc, struct sk_buff *skb) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6873 | { |
Seth Forshee | e041f65 | 2012-11-15 08:07:56 -0600 | [diff] [blame] | 6874 | struct dma_pub *dma; |
| 6875 | int fifo, ret = -ENOSPC; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6876 | struct d11txh *txh; |
Seth Forshee | e041f65 | 2012-11-15 08:07:56 -0600 | [diff] [blame] | 6877 | u16 frameid = INVALIDFID; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6878 | |
Seth Forshee | e041f65 | 2012-11-15 08:07:56 -0600 | [diff] [blame] | 6879 | fifo = brcms_ac_to_fifo(skb_get_queue_mapping(skb)); |
| 6880 | dma = wlc->hw->di[fifo]; |
| 6881 | txh = (struct d11txh *)(skb->data); |
| 6882 | |
| 6883 | if (dma->txavail == 0) { |
| 6884 | /* |
| 6885 | * We sometimes get a frame from mac80211 after stopping |
| 6886 | * the queues. This only ever seems to be a single frame |
| 6887 | * and is seems likely to be a race. TX_HEADROOM should |
| 6888 | * ensure that we have enough space to handle these stray |
| 6889 | * packets, so warn if there isn't. If we're out of space |
| 6890 | * in the tx ring and the tx queue isn't stopped then |
| 6891 | * we've really got a bug; warn loudly if that happens. |
| 6892 | */ |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 6893 | brcms_warn(wlc->hw->d11core, |
Seth Forshee | e041f65 | 2012-11-15 08:07:56 -0600 | [diff] [blame] | 6894 | "Received frame for tx with no space in DMA ring\n"); |
| 6895 | WARN_ON(!ieee80211_queue_stopped(wlc->pub->ieee_hw, |
| 6896 | skb_get_queue_mapping(skb))); |
| 6897 | return -ENOSPC; |
| 6898 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6899 | |
| 6900 | /* When a BC/MC frame is being committed to the BCMC fifo |
| 6901 | * via DMA (NOT PIO), update ucode or BSS info as appropriate. |
| 6902 | */ |
| 6903 | if (fifo == TX_BCMC_FIFO) |
| 6904 | frameid = le16_to_cpu(txh->TxFrameID); |
| 6905 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6906 | /* Commit BCMC sequence number in the SHM frame ID location */ |
| 6907 | if (frameid != INVALIDFID) { |
| 6908 | /* |
| 6909 | * To inform the ucode of the last mcast frame posted |
| 6910 | * so that it can clear moredata bit |
| 6911 | */ |
| 6912 | brcms_b_write_shm(wlc->hw, M_BCMC_FID, frameid); |
| 6913 | } |
| 6914 | |
Seth Forshee | e041f65 | 2012-11-15 08:07:56 -0600 | [diff] [blame] | 6915 | ret = brcms_c_txfifo(wlc, fifo, skb); |
| 6916 | /* |
| 6917 | * The only reason for brcms_c_txfifo to fail is because |
| 6918 | * there weren't any DMA descriptors, but we've already |
| 6919 | * checked for that. So if it does fail yell loudly. |
| 6920 | */ |
| 6921 | WARN_ON_ONCE(ret); |
| 6922 | |
| 6923 | return ret; |
| 6924 | } |
| 6925 | |
Piotr Haber | c4dea35 | 2012-11-28 21:44:05 +0100 | [diff] [blame] | 6926 | bool brcms_c_sendpkt_mac80211(struct brcms_c_info *wlc, struct sk_buff *sdu, |
Seth Forshee | e041f65 | 2012-11-15 08:07:56 -0600 | [diff] [blame] | 6927 | struct ieee80211_hw *hw) |
| 6928 | { |
| 6929 | uint fifo; |
| 6930 | struct scb *scb = &wlc->pri_scb; |
| 6931 | |
| 6932 | fifo = brcms_ac_to_fifo(skb_get_queue_mapping(sdu)); |
Piotr Haber | c4dea35 | 2012-11-28 21:44:05 +0100 | [diff] [blame] | 6933 | brcms_c_d11hdrs_mac80211(wlc, hw, sdu, scb, 0, 1, fifo, 0); |
| 6934 | if (!brcms_c_tx(wlc, sdu)) |
| 6935 | return true; |
| 6936 | |
| 6937 | /* packet discarded */ |
| 6938 | dev_kfree_skb_any(sdu); |
| 6939 | return false; |
Seth Forshee | e041f65 | 2012-11-15 08:07:56 -0600 | [diff] [blame] | 6940 | } |
| 6941 | |
| 6942 | int |
| 6943 | brcms_c_txfifo(struct brcms_c_info *wlc, uint fifo, struct sk_buff *p) |
| 6944 | { |
| 6945 | struct dma_pub *dma = wlc->hw->di[fifo]; |
| 6946 | int ret; |
| 6947 | u16 queue; |
| 6948 | |
| 6949 | ret = dma_txfast(wlc, dma, p); |
| 6950 | if (ret < 0) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6951 | wiphy_err(wlc->wiphy, "txfifo: fatal, toss frames !!!\n"); |
Seth Forshee | e041f65 | 2012-11-15 08:07:56 -0600 | [diff] [blame] | 6952 | |
| 6953 | /* |
| 6954 | * Stop queue if DMA ring is full. Reserve some free descriptors, |
| 6955 | * as we sometimes receive a frame from mac80211 after the queues |
| 6956 | * are stopped. |
| 6957 | */ |
| 6958 | queue = skb_get_queue_mapping(p); |
| 6959 | if (dma->txavail <= TX_HEADROOM && fifo < TX_BCMC_FIFO && |
| 6960 | !ieee80211_queue_stopped(wlc->pub->ieee_hw, queue)) |
| 6961 | ieee80211_stop_queue(wlc->pub->ieee_hw, queue); |
| 6962 | |
| 6963 | return ret; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6964 | } |
| 6965 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6966 | u32 |
| 6967 | brcms_c_rspec_to_rts_rspec(struct brcms_c_info *wlc, u32 rspec, |
| 6968 | bool use_rspec, u16 mimo_ctlchbw) |
| 6969 | { |
| 6970 | u32 rts_rspec = 0; |
| 6971 | |
| 6972 | if (use_rspec) |
| 6973 | /* use frame rate as rts rate */ |
| 6974 | rts_rspec = rspec; |
| 6975 | else if (wlc->band->gmode && wlc->protection->_g && !is_cck_rate(rspec)) |
| 6976 | /* Use 11Mbps as the g protection RTS target rate and fallback. |
| 6977 | * Use the brcms_basic_rate() lookup to find the best basic rate |
| 6978 | * under the target in case 11 Mbps is not Basic. |
| 6979 | * 6 and 9 Mbps are not usually selected by rate selection, but |
| 6980 | * even if the OFDM rate we are protecting is 6 or 9 Mbps, 11 |
| 6981 | * is more robust. |
| 6982 | */ |
| 6983 | rts_rspec = brcms_basic_rate(wlc, BRCM_RATE_11M); |
| 6984 | else |
| 6985 | /* calculate RTS rate and fallback rate based on the frame rate |
| 6986 | * RTS must be sent at a basic rate since it is a |
| 6987 | * control frame, sec 9.6 of 802.11 spec |
| 6988 | */ |
| 6989 | rts_rspec = brcms_basic_rate(wlc, rspec); |
| 6990 | |
| 6991 | if (BRCMS_PHY_11N_CAP(wlc->band)) { |
| 6992 | /* set rts txbw to correct side band */ |
| 6993 | rts_rspec &= ~RSPEC_BW_MASK; |
| 6994 | |
| 6995 | /* |
| 6996 | * if rspec/rspec_fallback is 40MHz, then send RTS on both |
| 6997 | * 20MHz channel (DUP), otherwise send RTS on control channel |
| 6998 | */ |
| 6999 | if (rspec_is40mhz(rspec) && !is_cck_rate(rts_rspec)) |
| 7000 | rts_rspec |= (PHY_TXC1_BW_40MHZ_DUP << RSPEC_BW_SHIFT); |
| 7001 | else |
| 7002 | rts_rspec |= (mimo_ctlchbw << RSPEC_BW_SHIFT); |
| 7003 | |
| 7004 | /* pick siso/cdd as default for ofdm */ |
| 7005 | if (is_ofdm_rate(rts_rspec)) { |
| 7006 | rts_rspec &= ~RSPEC_STF_MASK; |
| 7007 | rts_rspec |= (wlc->stf->ss_opmode << RSPEC_STF_SHIFT); |
| 7008 | } |
| 7009 | } |
| 7010 | return rts_rspec; |
| 7011 | } |
| 7012 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 7013 | /* Update beacon listen interval in shared memory */ |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 7014 | static void brcms_c_bcn_li_upd(struct brcms_c_info *wlc) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 7015 | { |
| 7016 | /* wake up every DTIM is the default */ |
| 7017 | if (wlc->bcn_li_dtim == 1) |
| 7018 | brcms_b_write_shm(wlc->hw, M_BCN_LI, 0); |
| 7019 | else |
| 7020 | brcms_b_write_shm(wlc->hw, M_BCN_LI, |
| 7021 | (wlc->bcn_li_dtim << 8) | wlc->bcn_li_bcn); |
| 7022 | } |
| 7023 | |
| 7024 | static void |
| 7025 | brcms_b_read_tsf(struct brcms_hardware *wlc_hw, u32 *tsf_l_ptr, |
| 7026 | u32 *tsf_h_ptr) |
| 7027 | { |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 7028 | struct bcma_device *core = wlc_hw->d11core; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 7029 | |
| 7030 | /* read the tsf timer low, then high to get an atomic read */ |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 7031 | *tsf_l_ptr = bcma_read32(core, D11REGOFFS(tsf_timerlow)); |
| 7032 | *tsf_h_ptr = bcma_read32(core, D11REGOFFS(tsf_timerhigh)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 7033 | } |
| 7034 | |
| 7035 | /* |
| 7036 | * recover 64bit TSF value from the 16bit TSF value in the rx header |
| 7037 | * given the assumption that the TSF passed in header is within 65ms |
| 7038 | * of the current tsf. |
| 7039 | * |
| 7040 | * 6 5 4 4 3 2 1 |
| 7041 | * 3.......6.......8.......0.......2.......4.......6.......8......0 |
| 7042 | * |<---------- tsf_h ----------->||<--- tsf_l -->||<-RxTSFTime ->| |
| 7043 | * |
| 7044 | * The RxTSFTime are the lowest 16 bits and provided by the ucode. The |
| 7045 | * tsf_l is filled in by brcms_b_recv, which is done earlier in the |
| 7046 | * receive call sequence after rx interrupt. Only the higher 16 bits |
| 7047 | * are used. Finally, the tsf_h is read from the tsf register. |
| 7048 | */ |
| 7049 | static u64 brcms_c_recover_tsf64(struct brcms_c_info *wlc, |
| 7050 | struct d11rxhdr *rxh) |
| 7051 | { |
| 7052 | u32 tsf_h, tsf_l; |
| 7053 | u16 rx_tsf_0_15, rx_tsf_16_31; |
| 7054 | |
| 7055 | brcms_b_read_tsf(wlc->hw, &tsf_l, &tsf_h); |
| 7056 | |
| 7057 | rx_tsf_16_31 = (u16)(tsf_l >> 16); |
| 7058 | rx_tsf_0_15 = rxh->RxTSFTime; |
| 7059 | |
| 7060 | /* |
| 7061 | * a greater tsf time indicates the low 16 bits of |
| 7062 | * tsf_l wrapped, so decrement the high 16 bits. |
| 7063 | */ |
| 7064 | if ((u16)tsf_l < rx_tsf_0_15) { |
| 7065 | rx_tsf_16_31 -= 1; |
| 7066 | if (rx_tsf_16_31 == 0xffff) |
| 7067 | tsf_h -= 1; |
| 7068 | } |
| 7069 | |
| 7070 | return ((u64)tsf_h << 32) | (((u32)rx_tsf_16_31 << 16) + rx_tsf_0_15); |
| 7071 | } |
| 7072 | |
| 7073 | static void |
| 7074 | prep_mac80211_status(struct brcms_c_info *wlc, struct d11rxhdr *rxh, |
| 7075 | struct sk_buff *p, |
| 7076 | struct ieee80211_rx_status *rx_status) |
| 7077 | { |
| 7078 | int preamble; |
| 7079 | int channel; |
| 7080 | u32 rspec; |
| 7081 | unsigned char *plcp; |
| 7082 | |
| 7083 | /* fill in TSF and flag its presence */ |
| 7084 | rx_status->mactime = brcms_c_recover_tsf64(wlc, rxh); |
Thomas Pedersen | f4bda33 | 2012-11-13 10:46:27 -0800 | [diff] [blame] | 7085 | rx_status->flag |= RX_FLAG_MACTIME_START; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 7086 | |
| 7087 | channel = BRCMS_CHAN_CHANNEL(rxh->RxChan); |
| 7088 | |
Johannes Berg | 858a455 | 2012-07-24 17:35:57 +0200 | [diff] [blame] | 7089 | rx_status->band = |
| 7090 | channel > 14 ? IEEE80211_BAND_5GHZ : IEEE80211_BAND_2GHZ; |
| 7091 | rx_status->freq = |
| 7092 | ieee80211_channel_to_frequency(channel, rx_status->band); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 7093 | |
| 7094 | rx_status->signal = wlc_phy_rssi_compute(wlc->hw->band->pi, rxh); |
| 7095 | |
| 7096 | /* noise */ |
| 7097 | /* qual */ |
| 7098 | rx_status->antenna = |
| 7099 | (rxh->PhyRxStatus_0 & PRXS0_RXANT_UPSUBBAND) ? 1 : 0; |
| 7100 | |
| 7101 | plcp = p->data; |
| 7102 | |
| 7103 | rspec = brcms_c_compute_rspec(rxh, plcp); |
| 7104 | if (is_mcs_rate(rspec)) { |
| 7105 | rx_status->rate_idx = rspec & RSPEC_RATE_MASK; |
| 7106 | rx_status->flag |= RX_FLAG_HT; |
| 7107 | if (rspec_is40mhz(rspec)) |
| 7108 | rx_status->flag |= RX_FLAG_40MHZ; |
| 7109 | } else { |
| 7110 | switch (rspec2rate(rspec)) { |
| 7111 | case BRCM_RATE_1M: |
| 7112 | rx_status->rate_idx = 0; |
| 7113 | break; |
| 7114 | case BRCM_RATE_2M: |
| 7115 | rx_status->rate_idx = 1; |
| 7116 | break; |
| 7117 | case BRCM_RATE_5M5: |
| 7118 | rx_status->rate_idx = 2; |
| 7119 | break; |
| 7120 | case BRCM_RATE_11M: |
| 7121 | rx_status->rate_idx = 3; |
| 7122 | break; |
| 7123 | case BRCM_RATE_6M: |
| 7124 | rx_status->rate_idx = 4; |
| 7125 | break; |
| 7126 | case BRCM_RATE_9M: |
| 7127 | rx_status->rate_idx = 5; |
| 7128 | break; |
| 7129 | case BRCM_RATE_12M: |
| 7130 | rx_status->rate_idx = 6; |
| 7131 | break; |
| 7132 | case BRCM_RATE_18M: |
| 7133 | rx_status->rate_idx = 7; |
| 7134 | break; |
| 7135 | case BRCM_RATE_24M: |
| 7136 | rx_status->rate_idx = 8; |
| 7137 | break; |
| 7138 | case BRCM_RATE_36M: |
| 7139 | rx_status->rate_idx = 9; |
| 7140 | break; |
| 7141 | case BRCM_RATE_48M: |
| 7142 | rx_status->rate_idx = 10; |
| 7143 | break; |
| 7144 | case BRCM_RATE_54M: |
| 7145 | rx_status->rate_idx = 11; |
| 7146 | break; |
| 7147 | default: |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 7148 | brcms_err(wlc->hw->d11core, |
| 7149 | "%s: Unknown rate\n", __func__); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 7150 | } |
| 7151 | |
| 7152 | /* |
| 7153 | * For 5GHz, we should decrease the index as it is |
| 7154 | * a subset of the 2.4G rates. See bitrates field |
| 7155 | * of brcms_band_5GHz_nphy (in mac80211_if.c). |
| 7156 | */ |
| 7157 | if (rx_status->band == IEEE80211_BAND_5GHZ) |
| 7158 | rx_status->rate_idx -= BRCMS_LEGACY_5G_RATE_OFFSET; |
| 7159 | |
| 7160 | /* Determine short preamble and rate_idx */ |
| 7161 | preamble = 0; |
| 7162 | if (is_cck_rate(rspec)) { |
| 7163 | if (rxh->PhyRxStatus_0 & PRXS0_SHORTH) |
| 7164 | rx_status->flag |= RX_FLAG_SHORTPRE; |
| 7165 | } else if (is_ofdm_rate(rspec)) { |
| 7166 | rx_status->flag |= RX_FLAG_SHORTPRE; |
| 7167 | } else { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 7168 | brcms_err(wlc->hw->d11core, "%s: Unknown modulation\n", |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 7169 | __func__); |
| 7170 | } |
| 7171 | } |
| 7172 | |
| 7173 | if (plcp3_issgi(plcp[3])) |
| 7174 | rx_status->flag |= RX_FLAG_SHORT_GI; |
| 7175 | |
| 7176 | if (rxh->RxStatus1 & RXS_DECERR) { |
| 7177 | rx_status->flag |= RX_FLAG_FAILED_PLCP_CRC; |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 7178 | brcms_err(wlc->hw->d11core, "%s: RX_FLAG_FAILED_PLCP_CRC\n", |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 7179 | __func__); |
| 7180 | } |
| 7181 | if (rxh->RxStatus1 & RXS_FCSERR) { |
| 7182 | rx_status->flag |= RX_FLAG_FAILED_FCS_CRC; |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 7183 | brcms_err(wlc->hw->d11core, "%s: RX_FLAG_FAILED_FCS_CRC\n", |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 7184 | __func__); |
| 7185 | } |
| 7186 | } |
| 7187 | |
| 7188 | static void |
| 7189 | brcms_c_recvctl(struct brcms_c_info *wlc, struct d11rxhdr *rxh, |
| 7190 | struct sk_buff *p) |
| 7191 | { |
| 7192 | int len_mpdu; |
| 7193 | struct ieee80211_rx_status rx_status; |
Arend van Spriel | badc4f0 | 2012-04-11 11:52:51 +0200 | [diff] [blame] | 7194 | struct ieee80211_hdr *hdr; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 7195 | |
| 7196 | memset(&rx_status, 0, sizeof(rx_status)); |
| 7197 | prep_mac80211_status(wlc, rxh, p, &rx_status); |
| 7198 | |
| 7199 | /* mac header+body length, exclude CRC and plcp header */ |
| 7200 | len_mpdu = p->len - D11_PHY_HDR_LEN - FCS_LEN; |
| 7201 | skb_pull(p, D11_PHY_HDR_LEN); |
| 7202 | __skb_trim(p, len_mpdu); |
| 7203 | |
Arend van Spriel | badc4f0 | 2012-04-11 11:52:51 +0200 | [diff] [blame] | 7204 | /* unmute transmit */ |
| 7205 | if (wlc->hw->suspended_fifos) { |
| 7206 | hdr = (struct ieee80211_hdr *)p->data; |
| 7207 | if (ieee80211_is_beacon(hdr->frame_control)) |
| 7208 | brcms_b_mute(wlc->hw, false); |
| 7209 | } |
| 7210 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 7211 | memcpy(IEEE80211_SKB_RXCB(p), &rx_status, sizeof(rx_status)); |
| 7212 | ieee80211_rx_irqsafe(wlc->pub->ieee_hw, p); |
| 7213 | } |
| 7214 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 7215 | /* calculate frame duration for Mixed-mode L-SIG spoofing, return |
| 7216 | * number of bytes goes in the length field |
| 7217 | * |
| 7218 | * Formula given by HT PHY Spec v 1.13 |
| 7219 | * len = 3(nsyms + nstream + 3) - 3 |
| 7220 | */ |
| 7221 | u16 |
| 7222 | brcms_c_calc_lsig_len(struct brcms_c_info *wlc, u32 ratespec, |
| 7223 | uint mac_len) |
| 7224 | { |
| 7225 | uint nsyms, len = 0, kNdps; |
| 7226 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 7227 | if (is_mcs_rate(ratespec)) { |
| 7228 | uint mcs = ratespec & RSPEC_RATE_MASK; |
| 7229 | int tot_streams = (mcs_2_txstreams(mcs) + 1) + |
| 7230 | rspec_stc(ratespec); |
| 7231 | |
| 7232 | /* |
| 7233 | * the payload duration calculation matches that |
| 7234 | * of regular ofdm |
| 7235 | */ |
| 7236 | /* 1000Ndbps = kbps * 4 */ |
| 7237 | kNdps = mcs_2_rate(mcs, rspec_is40mhz(ratespec), |
| 7238 | rspec_issgi(ratespec)) * 4; |
| 7239 | |
| 7240 | if (rspec_stc(ratespec) == 0) |
| 7241 | nsyms = |
| 7242 | CEIL((APHY_SERVICE_NBITS + 8 * mac_len + |
| 7243 | APHY_TAIL_NBITS) * 1000, kNdps); |
| 7244 | else |
| 7245 | /* STBC needs to have even number of symbols */ |
| 7246 | nsyms = |
| 7247 | 2 * |
| 7248 | CEIL((APHY_SERVICE_NBITS + 8 * mac_len + |
| 7249 | APHY_TAIL_NBITS) * 1000, 2 * kNdps); |
| 7250 | |
| 7251 | /* (+3) account for HT-SIG(2) and HT-STF(1) */ |
| 7252 | nsyms += (tot_streams + 3); |
| 7253 | /* |
| 7254 | * 3 bytes/symbol @ legacy 6Mbps rate |
| 7255 | * (-3) excluding service bits and tail bits |
| 7256 | */ |
| 7257 | len = (3 * nsyms) - 3; |
| 7258 | } |
| 7259 | |
| 7260 | return (u16) len; |
| 7261 | } |
| 7262 | |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 7263 | static void |
| 7264 | brcms_c_mod_prb_rsp_rate_table(struct brcms_c_info *wlc, uint frame_len) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 7265 | { |
| 7266 | const struct brcms_c_rateset *rs_dflt; |
| 7267 | struct brcms_c_rateset rs; |
| 7268 | u8 rate; |
| 7269 | u16 entry_ptr; |
| 7270 | u8 plcp[D11_PHY_HDR_LEN]; |
| 7271 | u16 dur, sifs; |
| 7272 | uint i; |
| 7273 | |
| 7274 | sifs = get_sifs(wlc->band); |
| 7275 | |
| 7276 | rs_dflt = brcms_c_rateset_get_hwrs(wlc); |
| 7277 | |
| 7278 | brcms_c_rateset_copy(rs_dflt, &rs); |
| 7279 | brcms_c_rateset_mcs_upd(&rs, wlc->stf->txstreams); |
| 7280 | |
| 7281 | /* |
| 7282 | * walk the phy rate table and update MAC core SHM |
| 7283 | * basic rate table entries |
| 7284 | */ |
| 7285 | for (i = 0; i < rs.count; i++) { |
| 7286 | rate = rs.rates[i] & BRCMS_RATE_MASK; |
| 7287 | |
| 7288 | entry_ptr = brcms_b_rate_shm_offset(wlc->hw, rate); |
| 7289 | |
| 7290 | /* Calculate the Probe Response PLCP for the given rate */ |
| 7291 | brcms_c_compute_plcp(wlc, rate, frame_len, plcp); |
| 7292 | |
| 7293 | /* |
| 7294 | * Calculate the duration of the Probe Response |
| 7295 | * frame plus SIFS for the MAC |
| 7296 | */ |
| 7297 | dur = (u16) brcms_c_calc_frame_time(wlc, rate, |
| 7298 | BRCMS_LONG_PREAMBLE, frame_len); |
| 7299 | dur += sifs; |
| 7300 | |
| 7301 | /* Update the SHM Rate Table entry Probe Response values */ |
| 7302 | brcms_b_write_shm(wlc->hw, entry_ptr + M_RT_PRS_PLCP_POS, |
| 7303 | (u16) (plcp[0] + (plcp[1] << 8))); |
| 7304 | brcms_b_write_shm(wlc->hw, entry_ptr + M_RT_PRS_PLCP_POS + 2, |
| 7305 | (u16) (plcp[2] + (plcp[3] << 8))); |
| 7306 | brcms_b_write_shm(wlc->hw, entry_ptr + M_RT_PRS_DUR_POS, dur); |
| 7307 | } |
| 7308 | } |
| 7309 | |
| 7310 | /* Max buffering needed for beacon template/prb resp template is 142 bytes. |
| 7311 | * |
| 7312 | * PLCP header is 6 bytes. |
| 7313 | * 802.11 A3 header is 24 bytes. |
| 7314 | * Max beacon frame body template length is 112 bytes. |
| 7315 | * Max probe resp frame body template length is 110 bytes. |
| 7316 | * |
| 7317 | * *len on input contains the max length of the packet available. |
| 7318 | * |
| 7319 | * The *len value is set to the number of bytes in buf used, and starts |
| 7320 | * with the PLCP and included up to, but not including, the 4 byte FCS. |
| 7321 | */ |
| 7322 | static void |
| 7323 | brcms_c_bcn_prb_template(struct brcms_c_info *wlc, u16 type, |
| 7324 | u32 bcn_rspec, |
| 7325 | struct brcms_bss_cfg *cfg, u16 *buf, int *len) |
| 7326 | { |
| 7327 | static const u8 ether_bcast[ETH_ALEN] = {255, 255, 255, 255, 255, 255}; |
| 7328 | struct cck_phy_hdr *plcp; |
| 7329 | struct ieee80211_mgmt *h; |
| 7330 | int hdr_len, body_len; |
| 7331 | |
| 7332 | hdr_len = D11_PHY_HDR_LEN + DOT11_MAC_HDR_LEN; |
| 7333 | |
| 7334 | /* calc buffer size provided for frame body */ |
| 7335 | body_len = *len - hdr_len; |
| 7336 | /* return actual size */ |
| 7337 | *len = hdr_len + body_len; |
| 7338 | |
| 7339 | /* format PHY and MAC headers */ |
| 7340 | memset((char *)buf, 0, hdr_len); |
| 7341 | |
| 7342 | plcp = (struct cck_phy_hdr *) buf; |
| 7343 | |
| 7344 | /* |
| 7345 | * PLCP for Probe Response frames are filled in from |
| 7346 | * core's rate table |
| 7347 | */ |
| 7348 | if (type == IEEE80211_STYPE_BEACON) |
| 7349 | /* fill in PLCP */ |
| 7350 | brcms_c_compute_plcp(wlc, bcn_rspec, |
| 7351 | (DOT11_MAC_HDR_LEN + body_len + FCS_LEN), |
| 7352 | (u8 *) plcp); |
| 7353 | |
| 7354 | /* "Regular" and 16 MBSS but not for 4 MBSS */ |
| 7355 | /* Update the phytxctl for the beacon based on the rspec */ |
| 7356 | brcms_c_beacon_phytxctl_txant_upd(wlc, bcn_rspec); |
| 7357 | |
| 7358 | h = (struct ieee80211_mgmt *)&plcp[1]; |
| 7359 | |
| 7360 | /* fill in 802.11 header */ |
| 7361 | h->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | type); |
| 7362 | |
| 7363 | /* DUR is 0 for multicast bcn, or filled in by MAC for prb resp */ |
| 7364 | /* A1 filled in by MAC for prb resp, broadcast for bcn */ |
| 7365 | if (type == IEEE80211_STYPE_BEACON) |
| 7366 | memcpy(&h->da, ðer_bcast, ETH_ALEN); |
| 7367 | memcpy(&h->sa, &cfg->cur_etheraddr, ETH_ALEN); |
| 7368 | memcpy(&h->bssid, &cfg->BSSID, ETH_ALEN); |
| 7369 | |
| 7370 | /* SEQ filled in by MAC */ |
| 7371 | } |
| 7372 | |
| 7373 | int brcms_c_get_header_len(void) |
| 7374 | { |
| 7375 | return TXOFF; |
| 7376 | } |
| 7377 | |
| 7378 | /* |
| 7379 | * Update all beacons for the system. |
| 7380 | */ |
| 7381 | void brcms_c_update_beacon(struct brcms_c_info *wlc) |
| 7382 | { |
| 7383 | struct brcms_bss_cfg *bsscfg = wlc->bsscfg; |
| 7384 | |
| 7385 | if (bsscfg->up && !bsscfg->BSS) |
| 7386 | /* Clear the soft intmask */ |
| 7387 | wlc->defmacintmask &= ~MI_BCNTPL; |
| 7388 | } |
| 7389 | |
| 7390 | /* Write ssid into shared memory */ |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 7391 | static void |
| 7392 | brcms_c_shm_ssid_upd(struct brcms_c_info *wlc, struct brcms_bss_cfg *cfg) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 7393 | { |
| 7394 | u8 *ssidptr = cfg->SSID; |
| 7395 | u16 base = M_SSID; |
| 7396 | u8 ssidbuf[IEEE80211_MAX_SSID_LEN]; |
| 7397 | |
| 7398 | /* padding the ssid with zero and copy it into shm */ |
| 7399 | memset(ssidbuf, 0, IEEE80211_MAX_SSID_LEN); |
| 7400 | memcpy(ssidbuf, ssidptr, cfg->SSID_len); |
| 7401 | |
| 7402 | brcms_c_copyto_shm(wlc, base, ssidbuf, IEEE80211_MAX_SSID_LEN); |
| 7403 | brcms_b_write_shm(wlc->hw, M_SSIDLEN, (u16) cfg->SSID_len); |
| 7404 | } |
| 7405 | |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 7406 | static void |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 7407 | brcms_c_bss_update_probe_resp(struct brcms_c_info *wlc, |
| 7408 | struct brcms_bss_cfg *cfg, |
| 7409 | bool suspend) |
| 7410 | { |
| 7411 | u16 prb_resp[BCN_TMPL_LEN / 2]; |
| 7412 | int len = BCN_TMPL_LEN; |
| 7413 | |
| 7414 | /* |
| 7415 | * write the probe response to hardware, or save in |
| 7416 | * the config structure |
| 7417 | */ |
| 7418 | |
| 7419 | /* create the probe response template */ |
| 7420 | brcms_c_bcn_prb_template(wlc, IEEE80211_STYPE_PROBE_RESP, 0, |
| 7421 | cfg, prb_resp, &len); |
| 7422 | |
| 7423 | if (suspend) |
| 7424 | brcms_c_suspend_mac_and_wait(wlc); |
| 7425 | |
| 7426 | /* write the probe response into the template region */ |
| 7427 | brcms_b_write_template_ram(wlc->hw, T_PRS_TPL_BASE, |
| 7428 | (len + 3) & ~3, prb_resp); |
| 7429 | |
| 7430 | /* write the length of the probe response frame (+PLCP/-FCS) */ |
| 7431 | brcms_b_write_shm(wlc->hw, M_PRB_RESP_FRM_LEN, (u16) len); |
| 7432 | |
| 7433 | /* write the SSID and SSID length */ |
| 7434 | brcms_c_shm_ssid_upd(wlc, cfg); |
| 7435 | |
| 7436 | /* |
| 7437 | * Write PLCP headers and durations for probe response frames |
| 7438 | * at all rates. Use the actual frame length covered by the |
| 7439 | * PLCP header for the call to brcms_c_mod_prb_rsp_rate_table() |
| 7440 | * by subtracting the PLCP len and adding the FCS. |
| 7441 | */ |
| 7442 | len += (-D11_PHY_HDR_LEN + FCS_LEN); |
| 7443 | brcms_c_mod_prb_rsp_rate_table(wlc, (u16) len); |
| 7444 | |
| 7445 | if (suspend) |
| 7446 | brcms_c_enable_mac(wlc); |
| 7447 | } |
| 7448 | |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 7449 | void brcms_c_update_probe_resp(struct brcms_c_info *wlc, bool suspend) |
| 7450 | { |
| 7451 | struct brcms_bss_cfg *bsscfg = wlc->bsscfg; |
| 7452 | |
| 7453 | /* update AP or IBSS probe responses */ |
| 7454 | if (bsscfg->up && !bsscfg->BSS) |
| 7455 | brcms_c_bss_update_probe_resp(wlc, bsscfg, suspend); |
| 7456 | } |
| 7457 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 7458 | int brcms_b_xmtfifo_sz_get(struct brcms_hardware *wlc_hw, uint fifo, |
| 7459 | uint *blocks) |
| 7460 | { |
| 7461 | if (fifo >= NFIFO) |
| 7462 | return -EINVAL; |
| 7463 | |
| 7464 | *blocks = wlc_hw->xmtfifo_sz[fifo]; |
| 7465 | |
| 7466 | return 0; |
| 7467 | } |
| 7468 | |
| 7469 | void |
| 7470 | brcms_c_set_addrmatch(struct brcms_c_info *wlc, int match_reg_offset, |
| 7471 | const u8 *addr) |
| 7472 | { |
| 7473 | brcms_b_set_addrmatch(wlc->hw, match_reg_offset, addr); |
| 7474 | if (match_reg_offset == RCM_BSSID_OFFSET) |
| 7475 | memcpy(wlc->bsscfg->BSSID, addr, ETH_ALEN); |
| 7476 | } |
| 7477 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 7478 | /* |
| 7479 | * Flag 'scan in progress' to withhold dynamic phy calibration |
| 7480 | */ |
| 7481 | void brcms_c_scan_start(struct brcms_c_info *wlc) |
| 7482 | { |
| 7483 | wlc_phy_hold_upd(wlc->band->pi, PHY_HOLD_FOR_SCAN, true); |
| 7484 | } |
| 7485 | |
| 7486 | void brcms_c_scan_stop(struct brcms_c_info *wlc) |
| 7487 | { |
| 7488 | wlc_phy_hold_upd(wlc->band->pi, PHY_HOLD_FOR_SCAN, false); |
| 7489 | } |
| 7490 | |
| 7491 | void brcms_c_associate_upd(struct brcms_c_info *wlc, bool state) |
| 7492 | { |
| 7493 | wlc->pub->associated = state; |
| 7494 | wlc->bsscfg->associated = state; |
| 7495 | } |
| 7496 | |
| 7497 | /* |
| 7498 | * When a remote STA/AP is removed by Mac80211, or when it can no longer accept |
| 7499 | * AMPDU traffic, packets pending in hardware have to be invalidated so that |
| 7500 | * when later on hardware releases them, they can be handled appropriately. |
| 7501 | */ |
| 7502 | void brcms_c_inval_dma_pkts(struct brcms_hardware *hw, |
| 7503 | struct ieee80211_sta *sta, |
| 7504 | void (*dma_callback_fn)) |
| 7505 | { |
| 7506 | struct dma_pub *dmah; |
| 7507 | int i; |
| 7508 | for (i = 0; i < NFIFO; i++) { |
| 7509 | dmah = hw->di[i]; |
| 7510 | if (dmah != NULL) |
| 7511 | dma_walk_packets(dmah, dma_callback_fn, sta); |
| 7512 | } |
| 7513 | } |
| 7514 | |
| 7515 | int brcms_c_get_curband(struct brcms_c_info *wlc) |
| 7516 | { |
| 7517 | return wlc->band->bandunit; |
| 7518 | } |
| 7519 | |
| 7520 | void brcms_c_wait_for_tx_completion(struct brcms_c_info *wlc, bool drop) |
| 7521 | { |
Stanislaw Gruszka | f96b08a | 2012-01-17 12:38:50 +0100 | [diff] [blame] | 7522 | int timeout = 20; |
Seth Forshee | e041f65 | 2012-11-15 08:07:56 -0600 | [diff] [blame] | 7523 | int i; |
Stanislaw Gruszka | f96b08a | 2012-01-17 12:38:50 +0100 | [diff] [blame] | 7524 | |
Seth Forshee | e041f65 | 2012-11-15 08:07:56 -0600 | [diff] [blame] | 7525 | /* Kick DMA to send any pending AMPDU */ |
| 7526 | for (i = 0; i < ARRAY_SIZE(wlc->hw->di); i++) |
| 7527 | if (wlc->hw->di[i]) |
| 7528 | dma_txflush(wlc->hw->di[i]); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 7529 | |
| 7530 | /* wait for queue and DMA fifos to run dry */ |
Seth Forshee | e041f65 | 2012-11-15 08:07:56 -0600 | [diff] [blame] | 7531 | while (brcms_txpktpendtot(wlc) > 0) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 7532 | brcms_msleep(wlc->wl, 1); |
Stanislaw Gruszka | f96b08a | 2012-01-17 12:38:50 +0100 | [diff] [blame] | 7533 | |
| 7534 | if (--timeout == 0) |
| 7535 | break; |
| 7536 | } |
| 7537 | |
| 7538 | WARN_ON_ONCE(timeout == 0); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 7539 | } |
| 7540 | |
| 7541 | void brcms_c_set_beacon_listen_interval(struct brcms_c_info *wlc, u8 interval) |
| 7542 | { |
| 7543 | wlc->bcn_li_bcn = interval; |
| 7544 | if (wlc->pub->up) |
| 7545 | brcms_c_bcn_li_upd(wlc); |
| 7546 | } |
| 7547 | |
| 7548 | int brcms_c_set_tx_power(struct brcms_c_info *wlc, int txpwr) |
| 7549 | { |
| 7550 | uint qdbm; |
| 7551 | |
| 7552 | /* Remove override bit and clip to max qdbm value */ |
| 7553 | qdbm = min_t(uint, txpwr * BRCMS_TXPWR_DB_FACTOR, 0xff); |
| 7554 | return wlc_phy_txpower_set(wlc->band->pi, qdbm, false); |
| 7555 | } |
| 7556 | |
| 7557 | int brcms_c_get_tx_power(struct brcms_c_info *wlc) |
| 7558 | { |
| 7559 | uint qdbm; |
| 7560 | bool override; |
| 7561 | |
| 7562 | wlc_phy_txpower_get(wlc->band->pi, &qdbm, &override); |
| 7563 | |
| 7564 | /* Return qdbm units */ |
| 7565 | return (int)(qdbm / BRCMS_TXPWR_DB_FACTOR); |
| 7566 | } |
| 7567 | |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 7568 | /* Process received frames */ |
| 7569 | /* |
| 7570 | * Return true if more frames need to be processed. false otherwise. |
| 7571 | * Param 'bound' indicates max. # frames to process before break out. |
| 7572 | */ |
| 7573 | static void brcms_c_recv(struct brcms_c_info *wlc, struct sk_buff *p) |
| 7574 | { |
| 7575 | struct d11rxhdr *rxh; |
| 7576 | struct ieee80211_hdr *h; |
| 7577 | uint len; |
| 7578 | bool is_amsdu; |
| 7579 | |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 7580 | /* frame starts with rxhdr */ |
| 7581 | rxh = (struct d11rxhdr *) (p->data); |
| 7582 | |
| 7583 | /* strip off rxhdr */ |
| 7584 | skb_pull(p, BRCMS_HWRXOFF); |
| 7585 | |
| 7586 | /* MAC inserts 2 pad bytes for a4 headers or QoS or A-MSDU subframes */ |
| 7587 | if (rxh->RxStatus1 & RXS_PBPRES) { |
| 7588 | if (p->len < 2) { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 7589 | brcms_err(wlc->hw->d11core, |
| 7590 | "wl%d: recv: rcvd runt of len %d\n", |
| 7591 | wlc->pub->unit, p->len); |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 7592 | goto toss; |
| 7593 | } |
| 7594 | skb_pull(p, 2); |
| 7595 | } |
| 7596 | |
| 7597 | h = (struct ieee80211_hdr *)(p->data + D11_PHY_HDR_LEN); |
| 7598 | len = p->len; |
| 7599 | |
| 7600 | if (rxh->RxStatus1 & RXS_FCSERR) { |
Alwin Beukers | be66766 | 2011-11-22 17:21:43 -0800 | [diff] [blame] | 7601 | if (!(wlc->filter_flags & FIF_FCSFAIL)) |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 7602 | goto toss; |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 7603 | } |
| 7604 | |
| 7605 | /* check received pkt has at least frame control field */ |
| 7606 | if (len < D11_PHY_HDR_LEN + sizeof(h->frame_control)) |
| 7607 | goto toss; |
| 7608 | |
| 7609 | /* not supporting A-MSDU */ |
| 7610 | is_amsdu = rxh->RxStatus2 & RXS_AMSDU_MASK; |
| 7611 | if (is_amsdu) |
| 7612 | goto toss; |
| 7613 | |
| 7614 | brcms_c_recvctl(wlc, rxh, p); |
| 7615 | return; |
| 7616 | |
| 7617 | toss: |
| 7618 | brcmu_pkt_buf_free_skb(p); |
| 7619 | } |
| 7620 | |
| 7621 | /* Process received frames */ |
| 7622 | /* |
| 7623 | * Return true if more frames need to be processed. false otherwise. |
| 7624 | * Param 'bound' indicates max. # frames to process before break out. |
| 7625 | */ |
| 7626 | static bool |
| 7627 | brcms_b_recv(struct brcms_hardware *wlc_hw, uint fifo, bool bound) |
| 7628 | { |
| 7629 | struct sk_buff *p; |
Arend van Spriel | 3fd172d | 2011-10-21 16:16:31 +0200 | [diff] [blame] | 7630 | struct sk_buff *next = NULL; |
| 7631 | struct sk_buff_head recv_frames; |
| 7632 | |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 7633 | uint n = 0; |
| 7634 | uint bound_limit = bound ? RXBND : -1; |
Geert Uytterhoeven | c2397bb | 2012-12-22 22:07:14 +0100 | [diff] [blame] | 7635 | bool morepending = false; |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 7636 | |
Arend van Spriel | 3fd172d | 2011-10-21 16:16:31 +0200 | [diff] [blame] | 7637 | skb_queue_head_init(&recv_frames); |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 7638 | |
Arend van Spriel | 3fd172d | 2011-10-21 16:16:31 +0200 | [diff] [blame] | 7639 | /* gather received frames */ |
Piotr Haber | 57fe504 | 2012-11-28 21:44:07 +0100 | [diff] [blame] | 7640 | do { |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 7641 | /* !give others some time to run! */ |
Piotr Haber | 57fe504 | 2012-11-28 21:44:07 +0100 | [diff] [blame] | 7642 | if (n >= bound_limit) |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 7643 | break; |
Piotr Haber | 57fe504 | 2012-11-28 21:44:07 +0100 | [diff] [blame] | 7644 | |
| 7645 | morepending = dma_rx(wlc_hw->di[fifo], &recv_frames); |
| 7646 | n++; |
| 7647 | } while (morepending); |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 7648 | |
| 7649 | /* post more rbufs */ |
| 7650 | dma_rxfill(wlc_hw->di[fifo]); |
| 7651 | |
| 7652 | /* process each frame */ |
Arend van Spriel | 3fd172d | 2011-10-21 16:16:31 +0200 | [diff] [blame] | 7653 | skb_queue_walk_safe(&recv_frames, p, next) { |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 7654 | struct d11rxhdr_le *rxh_le; |
| 7655 | struct d11rxhdr *rxh; |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 7656 | |
Arend van Spriel | 3fd172d | 2011-10-21 16:16:31 +0200 | [diff] [blame] | 7657 | skb_unlink(p, &recv_frames); |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 7658 | rxh_le = (struct d11rxhdr_le *)p->data; |
| 7659 | rxh = (struct d11rxhdr *)p->data; |
| 7660 | |
| 7661 | /* fixup rx header endianness */ |
| 7662 | rxh->RxFrameSize = le16_to_cpu(rxh_le->RxFrameSize); |
| 7663 | rxh->PhyRxStatus_0 = le16_to_cpu(rxh_le->PhyRxStatus_0); |
| 7664 | rxh->PhyRxStatus_1 = le16_to_cpu(rxh_le->PhyRxStatus_1); |
| 7665 | rxh->PhyRxStatus_2 = le16_to_cpu(rxh_le->PhyRxStatus_2); |
| 7666 | rxh->PhyRxStatus_3 = le16_to_cpu(rxh_le->PhyRxStatus_3); |
| 7667 | rxh->PhyRxStatus_4 = le16_to_cpu(rxh_le->PhyRxStatus_4); |
| 7668 | rxh->PhyRxStatus_5 = le16_to_cpu(rxh_le->PhyRxStatus_5); |
| 7669 | rxh->RxStatus1 = le16_to_cpu(rxh_le->RxStatus1); |
| 7670 | rxh->RxStatus2 = le16_to_cpu(rxh_le->RxStatus2); |
| 7671 | rxh->RxTSFTime = le16_to_cpu(rxh_le->RxTSFTime); |
| 7672 | rxh->RxChan = le16_to_cpu(rxh_le->RxChan); |
| 7673 | |
| 7674 | brcms_c_recv(wlc_hw->wlc, p); |
| 7675 | } |
| 7676 | |
Piotr Haber | 57fe504 | 2012-11-28 21:44:07 +0100 | [diff] [blame] | 7677 | return morepending; |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 7678 | } |
| 7679 | |
| 7680 | /* second-level interrupt processing |
| 7681 | * Return true if another dpc needs to be re-scheduled. false otherwise. |
| 7682 | * Param 'bounded' indicates if applicable loops should be bounded. |
| 7683 | */ |
| 7684 | bool brcms_c_dpc(struct brcms_c_info *wlc, bool bounded) |
| 7685 | { |
| 7686 | u32 macintstatus; |
| 7687 | struct brcms_hardware *wlc_hw = wlc->hw; |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 7688 | struct bcma_device *core = wlc_hw->d11core; |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 7689 | |
| 7690 | if (brcms_deviceremoved(wlc)) { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 7691 | brcms_err(core, "wl%d: %s: dead chip\n", wlc_hw->unit, |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 7692 | __func__); |
| 7693 | brcms_down(wlc->wl); |
| 7694 | return false; |
| 7695 | } |
| 7696 | |
| 7697 | /* grab and clear the saved software intstatus bits */ |
| 7698 | macintstatus = wlc->macintstatus; |
| 7699 | wlc->macintstatus = 0; |
| 7700 | |
Seth Forshee | 229a41d | 2012-11-15 08:08:06 -0600 | [diff] [blame] | 7701 | brcms_dbg_int(core, "wl%d: macintstatus 0x%x\n", |
| 7702 | wlc_hw->unit, macintstatus); |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 7703 | |
| 7704 | WARN_ON(macintstatus & MI_PRQ); /* PRQ Interrupt in non-MBSS */ |
| 7705 | |
| 7706 | /* tx status */ |
| 7707 | if (macintstatus & MI_TFS) { |
| 7708 | bool fatal; |
| 7709 | if (brcms_b_txstatus(wlc->hw, bounded, &fatal)) |
| 7710 | wlc->macintstatus |= MI_TFS; |
| 7711 | if (fatal) { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 7712 | brcms_err(core, "MI_TFS: fatal\n"); |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 7713 | goto fatal; |
| 7714 | } |
| 7715 | } |
| 7716 | |
| 7717 | if (macintstatus & (MI_TBTT | MI_DTIM_TBTT)) |
| 7718 | brcms_c_tbtt(wlc); |
| 7719 | |
| 7720 | /* ATIM window end */ |
| 7721 | if (macintstatus & MI_ATIMWINEND) { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 7722 | brcms_dbg_info(core, "end of ATIM window\n"); |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 7723 | bcma_set32(core, D11REGOFFS(maccommand), wlc->qvalid); |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 7724 | wlc->qvalid = 0; |
| 7725 | } |
| 7726 | |
| 7727 | /* |
| 7728 | * received data or control frame, MI_DMAINT is |
| 7729 | * indication of RX_FIFO interrupt |
| 7730 | */ |
| 7731 | if (macintstatus & MI_DMAINT) |
| 7732 | if (brcms_b_recv(wlc_hw, RX_FIFO, bounded)) |
| 7733 | wlc->macintstatus |= MI_DMAINT; |
| 7734 | |
| 7735 | /* noise sample collected */ |
| 7736 | if (macintstatus & MI_BG_NOISE) |
| 7737 | wlc_phy_noise_sample_intr(wlc_hw->band->pi); |
| 7738 | |
| 7739 | if (macintstatus & MI_GP0) { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 7740 | brcms_err(core, "wl%d: PSM microcode watchdog fired at %d " |
Arend van Spriel | b2ffec4 | 2011-12-08 15:06:45 -0800 | [diff] [blame] | 7741 | "(seconds). Resetting.\n", wlc_hw->unit, wlc_hw->now); |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 7742 | |
| 7743 | printk_once("%s : PSM Watchdog, chipid 0x%x, chiprev 0x%x\n", |
Arend van Spriel | b2ffec4 | 2011-12-08 15:06:45 -0800 | [diff] [blame] | 7744 | __func__, ai_get_chip_id(wlc_hw->sih), |
| 7745 | ai_get_chiprev(wlc_hw->sih)); |
Roland Vossen | c261bdf | 2011-10-18 14:03:04 +0200 | [diff] [blame] | 7746 | brcms_fatal_error(wlc_hw->wlc->wl); |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 7747 | } |
| 7748 | |
| 7749 | /* gptimer timeout */ |
| 7750 | if (macintstatus & MI_TO) |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 7751 | bcma_write32(core, D11REGOFFS(gptimer), 0); |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 7752 | |
| 7753 | if (macintstatus & MI_RFDISABLE) { |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 7754 | brcms_dbg_info(core, "wl%d: BMAC Detected a change on the" |
| 7755 | " RF Disable Input\n", wlc_hw->unit); |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 7756 | brcms_rfkill_set_hw_state(wlc->wl); |
| 7757 | } |
| 7758 | |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 7759 | /* it isn't done and needs to be resched if macintstatus is non-zero */ |
| 7760 | return wlc->macintstatus != 0; |
| 7761 | |
| 7762 | fatal: |
Roland Vossen | c261bdf | 2011-10-18 14:03:04 +0200 | [diff] [blame] | 7763 | brcms_fatal_error(wlc_hw->wlc->wl); |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 7764 | return wlc->macintstatus != 0; |
| 7765 | } |
| 7766 | |
Roland Vossen | dc46012 | 2011-10-21 16:16:28 +0200 | [diff] [blame] | 7767 | void brcms_c_init(struct brcms_c_info *wlc, bool mute_tx) |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 7768 | { |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 7769 | struct bcma_device *core = wlc->hw->d11core; |
Seth Forshee | 9169129 | 2012-06-16 07:47:49 -0500 | [diff] [blame] | 7770 | struct ieee80211_channel *ch = wlc->pub->ieee_hw->conf.channel; |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 7771 | u16 chanspec; |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 7772 | |
Seth Forshee | b353dda | 2012-11-15 08:08:03 -0600 | [diff] [blame] | 7773 | brcms_dbg_info(core, "wl%d\n", wlc->pub->unit); |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 7774 | |
Seth Forshee | 9169129 | 2012-06-16 07:47:49 -0500 | [diff] [blame] | 7775 | chanspec = ch20mhz_chspec(ch->hw_value); |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 7776 | |
Roland Vossen | a8bc491 | 2011-10-21 16:16:25 +0200 | [diff] [blame] | 7777 | brcms_b_init(wlc->hw, chanspec); |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 7778 | |
| 7779 | /* update beacon listen interval */ |
| 7780 | brcms_c_bcn_li_upd(wlc); |
| 7781 | |
| 7782 | /* write ethernet address to core */ |
| 7783 | brcms_c_set_mac(wlc->bsscfg); |
| 7784 | brcms_c_set_bssid(wlc->bsscfg); |
| 7785 | |
| 7786 | /* Update tsf_cfprep if associated and up */ |
| 7787 | if (wlc->pub->associated && wlc->bsscfg->up) { |
| 7788 | u32 bi; |
| 7789 | |
| 7790 | /* get beacon period and convert to uS */ |
| 7791 | bi = wlc->bsscfg->current_bss->beacon_period << 10; |
| 7792 | /* |
| 7793 | * update since init path would reset |
| 7794 | * to default value |
| 7795 | */ |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 7796 | bcma_write32(core, D11REGOFFS(tsf_cfprep), |
| 7797 | bi << CFPREP_CBI_SHIFT); |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 7798 | |
| 7799 | /* Update maccontrol PM related bits */ |
| 7800 | brcms_c_set_ps_ctrl(wlc); |
| 7801 | } |
| 7802 | |
| 7803 | brcms_c_bandinit_ordered(wlc, chanspec); |
| 7804 | |
| 7805 | /* init probe response timeout */ |
| 7806 | brcms_b_write_shm(wlc->hw, M_PRS_MAXTIME, wlc->prb_resp_timeout); |
| 7807 | |
| 7808 | /* init max burst txop (framebursting) */ |
| 7809 | brcms_b_write_shm(wlc->hw, M_MBURST_TXOP, |
| 7810 | (wlc-> |
| 7811 | _rifs ? (EDCF_AC_VO_TXOP_AP << 5) : MAXFRAMEBURST_TXOP)); |
| 7812 | |
| 7813 | /* initialize maximum allowed duty cycle */ |
| 7814 | brcms_c_duty_cycle_set(wlc, wlc->tx_duty_cycle_ofdm, true, true); |
| 7815 | brcms_c_duty_cycle_set(wlc, wlc->tx_duty_cycle_cck, false, true); |
| 7816 | |
| 7817 | /* |
| 7818 | * Update some shared memory locations related to |
| 7819 | * max AMPDU size allowed to received |
| 7820 | */ |
| 7821 | brcms_c_ampdu_shm_upd(wlc->ampdu); |
| 7822 | |
| 7823 | /* band-specific inits */ |
| 7824 | brcms_c_bsinit(wlc); |
| 7825 | |
| 7826 | /* Enable EDCF mode (while the MAC is suspended) */ |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 7827 | bcma_set16(core, D11REGOFFS(ifs_ctl), IFS_USEEDCF); |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 7828 | brcms_c_edcf_setparams(wlc, false); |
| 7829 | |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 7830 | /* read the ucode version if we have not yet done so */ |
| 7831 | if (wlc->ucode_rev == 0) { |
| 7832 | wlc->ucode_rev = |
| 7833 | brcms_b_read_shm(wlc->hw, M_BOM_REV_MAJOR) << NBITS(u16); |
| 7834 | wlc->ucode_rev |= brcms_b_read_shm(wlc->hw, M_BOM_REV_MINOR); |
| 7835 | } |
| 7836 | |
| 7837 | /* ..now really unleash hell (allow the MAC out of suspend) */ |
| 7838 | brcms_c_enable_mac(wlc); |
| 7839 | |
Roland Vossen | a8bc491 | 2011-10-21 16:16:25 +0200 | [diff] [blame] | 7840 | /* suspend the tx fifos and mute the phy for preism cac time */ |
| 7841 | if (mute_tx) |
Roland Vossen | c6c4489 | 2011-10-21 16:16:26 +0200 | [diff] [blame] | 7842 | brcms_b_mute(wlc->hw, true); |
Roland Vossen | a8bc491 | 2011-10-21 16:16:25 +0200 | [diff] [blame] | 7843 | |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 7844 | /* enable the RF Disable Delay timer */ |
Arend van Spriel | 16d2812 | 2011-12-08 15:06:51 -0800 | [diff] [blame] | 7845 | bcma_write32(core, D11REGOFFS(rfdisabledly), RFDISABLE_DEFAULT); |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 7846 | |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 7847 | /* |
| 7848 | * Initialize WME parameters; if they haven't been set by some other |
| 7849 | * mechanism (IOVar, etc) then read them from the hardware. |
| 7850 | */ |
| 7851 | if (GFIELD(wlc->wme_retries[0], EDCF_SHORT) == 0) { |
| 7852 | /* Uninitialized; read from HW */ |
| 7853 | int ac; |
| 7854 | |
Arend van Spriel | b7eec42 | 2011-11-10 20:30:18 +0100 | [diff] [blame] | 7855 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 7856 | wlc->wme_retries[ac] = |
| 7857 | brcms_b_read_shm(wlc->hw, M_AC_TXLMT_ADDR(ac)); |
| 7858 | } |
| 7859 | } |
| 7860 | |
| 7861 | /* |
| 7862 | * The common driver entry routine. Error codes should be unique |
| 7863 | */ |
| 7864 | struct brcms_c_info * |
Arend van Spriel | b63337a | 2011-12-08 15:06:47 -0800 | [diff] [blame] | 7865 | brcms_c_attach(struct brcms_info *wl, struct bcma_device *core, uint unit, |
| 7866 | bool piomode, uint *perr) |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 7867 | { |
| 7868 | struct brcms_c_info *wlc; |
| 7869 | uint err = 0; |
| 7870 | uint i, j; |
| 7871 | struct brcms_pub *pub; |
| 7872 | |
| 7873 | /* allocate struct brcms_c_info state and its substructures */ |
Joe Perches | 2c20889 | 2012-06-04 12:44:17 +0000 | [diff] [blame] | 7874 | wlc = brcms_c_attach_malloc(unit, &err, 0); |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 7875 | if (wlc == NULL) |
| 7876 | goto fail; |
| 7877 | wlc->wiphy = wl->wiphy; |
| 7878 | pub = wlc->pub; |
| 7879 | |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 7880 | #if defined(DEBUG) |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 7881 | wlc_info_dbg = wlc; |
| 7882 | #endif |
| 7883 | |
| 7884 | wlc->band = wlc->bandstate[0]; |
| 7885 | wlc->core = wlc->corestate; |
| 7886 | wlc->wl = wl; |
| 7887 | pub->unit = unit; |
| 7888 | pub->_piomode = piomode; |
| 7889 | wlc->bandinit_pending = false; |
| 7890 | |
| 7891 | /* populate struct brcms_c_info with default values */ |
| 7892 | brcms_c_info_init(wlc, unit); |
| 7893 | |
| 7894 | /* update sta/ap related parameters */ |
| 7895 | brcms_c_ap_upd(wlc); |
| 7896 | |
| 7897 | /* |
| 7898 | * low level attach steps(all hw accesses go |
| 7899 | * inside, no more in rest of the attach) |
| 7900 | */ |
Arend van Spriel | b63337a | 2011-12-08 15:06:47 -0800 | [diff] [blame] | 7901 | err = brcms_b_attach(wlc, core, unit, piomode); |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 7902 | if (err) |
| 7903 | goto fail; |
| 7904 | |
| 7905 | brcms_c_protection_upd(wlc, BRCMS_PROT_N_PAM_OVR, OFF); |
| 7906 | |
| 7907 | pub->phy_11ncapable = BRCMS_PHY_11N_CAP(wlc->band); |
| 7908 | |
| 7909 | /* disable allowed duty cycle */ |
| 7910 | wlc->tx_duty_cycle_ofdm = 0; |
| 7911 | wlc->tx_duty_cycle_cck = 0; |
| 7912 | |
| 7913 | brcms_c_stf_phy_chain_calc(wlc); |
| 7914 | |
| 7915 | /* txchain 1: txant 0, txchain 2: txant 1 */ |
| 7916 | if (BRCMS_ISNPHY(wlc->band) && (wlc->stf->txstreams == 1)) |
| 7917 | wlc->stf->txant = wlc->stf->hw_txchain - 1; |
| 7918 | |
| 7919 | /* push to BMAC driver */ |
| 7920 | wlc_phy_stf_chain_init(wlc->band->pi, wlc->stf->hw_txchain, |
| 7921 | wlc->stf->hw_rxchain); |
| 7922 | |
| 7923 | /* pull up some info resulting from the low attach */ |
| 7924 | for (i = 0; i < NFIFO; i++) |
| 7925 | wlc->core->txavail[i] = wlc->hw->txavail[i]; |
| 7926 | |
| 7927 | memcpy(&wlc->perm_etheraddr, &wlc->hw->etheraddr, ETH_ALEN); |
| 7928 | memcpy(&pub->cur_etheraddr, &wlc->hw->etheraddr, ETH_ALEN); |
| 7929 | |
| 7930 | for (j = 0; j < wlc->pub->_nbands; j++) { |
| 7931 | wlc->band = wlc->bandstate[j]; |
| 7932 | |
| 7933 | if (!brcms_c_attach_stf_ant_init(wlc)) { |
| 7934 | err = 24; |
| 7935 | goto fail; |
| 7936 | } |
| 7937 | |
| 7938 | /* default contention windows size limits */ |
| 7939 | wlc->band->CWmin = APHY_CWMIN; |
| 7940 | wlc->band->CWmax = PHY_CWMAX; |
| 7941 | |
| 7942 | /* init gmode value */ |
| 7943 | if (wlc->band->bandtype == BRCM_BAND_2G) { |
| 7944 | wlc->band->gmode = GMODE_AUTO; |
| 7945 | brcms_c_protection_upd(wlc, BRCMS_PROT_G_USER, |
| 7946 | wlc->band->gmode); |
| 7947 | } |
| 7948 | |
| 7949 | /* init _n_enab supported mode */ |
| 7950 | if (BRCMS_PHY_11N_CAP(wlc->band)) { |
| 7951 | pub->_n_enab = SUPPORT_11N; |
| 7952 | brcms_c_protection_upd(wlc, BRCMS_PROT_N_USER, |
| 7953 | ((pub->_n_enab == |
| 7954 | SUPPORT_11N) ? WL_11N_2x2 : |
| 7955 | WL_11N_3x3)); |
| 7956 | } |
| 7957 | |
| 7958 | /* init per-band default rateset, depend on band->gmode */ |
| 7959 | brcms_default_rateset(wlc, &wlc->band->defrateset); |
| 7960 | |
| 7961 | /* fill in hw_rateset */ |
| 7962 | brcms_c_rateset_filter(&wlc->band->defrateset, |
| 7963 | &wlc->band->hw_rateset, false, |
| 7964 | BRCMS_RATES_CCK_OFDM, BRCMS_RATE_MASK, |
| 7965 | (bool) (wlc->pub->_n_enab & SUPPORT_11N)); |
| 7966 | } |
| 7967 | |
| 7968 | /* |
| 7969 | * update antenna config due to |
| 7970 | * wlc->stf->txant/txchain/ant_rx_ovr change |
| 7971 | */ |
| 7972 | brcms_c_stf_phy_txant_upd(wlc); |
| 7973 | |
| 7974 | /* attach each modules */ |
| 7975 | err = brcms_c_attach_module(wlc); |
| 7976 | if (err != 0) |
| 7977 | goto fail; |
| 7978 | |
| 7979 | if (!brcms_c_timers_init(wlc, unit)) { |
| 7980 | wiphy_err(wl->wiphy, "wl%d: %s: init_timer failed\n", unit, |
| 7981 | __func__); |
| 7982 | err = 32; |
| 7983 | goto fail; |
| 7984 | } |
| 7985 | |
| 7986 | /* depend on rateset, gmode */ |
| 7987 | wlc->cmi = brcms_c_channel_mgr_attach(wlc); |
| 7988 | if (!wlc->cmi) { |
| 7989 | wiphy_err(wl->wiphy, "wl%d: %s: channel_mgr_attach failed" |
| 7990 | "\n", unit, __func__); |
| 7991 | err = 33; |
| 7992 | goto fail; |
| 7993 | } |
| 7994 | |
| 7995 | /* init default when all parameters are ready, i.e. ->rateset */ |
| 7996 | brcms_c_bss_default_init(wlc); |
| 7997 | |
| 7998 | /* |
| 7999 | * Complete the wlc default state initializations.. |
| 8000 | */ |
| 8001 | |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 8002 | wlc->bsscfg->wlc = wlc; |
| 8003 | |
| 8004 | wlc->mimoft = FT_HT; |
| 8005 | wlc->mimo_40txbw = AUTO; |
| 8006 | wlc->ofdm_40txbw = AUTO; |
| 8007 | wlc->cck_40txbw = AUTO; |
| 8008 | brcms_c_update_mimo_band_bwcap(wlc, BRCMS_N_BW_20IN2G_40IN5G); |
| 8009 | |
| 8010 | /* Set default values of SGI */ |
| 8011 | if (BRCMS_SGI_CAP_PHY(wlc)) { |
| 8012 | brcms_c_ht_update_sgi_rx(wlc, (BRCMS_N_SGI_20 | |
| 8013 | BRCMS_N_SGI_40)); |
| 8014 | } else if (BRCMS_ISSSLPNPHY(wlc->band)) { |
| 8015 | brcms_c_ht_update_sgi_rx(wlc, (BRCMS_N_SGI_20 | |
| 8016 | BRCMS_N_SGI_40)); |
| 8017 | } else { |
| 8018 | brcms_c_ht_update_sgi_rx(wlc, 0); |
| 8019 | } |
| 8020 | |
Alwin Beukers | 94bdc2a | 2011-10-12 20:51:13 +0200 | [diff] [blame] | 8021 | brcms_b_antsel_set(wlc->hw, wlc->asi->antsel_avail); |
| 8022 | |
| 8023 | if (perr) |
| 8024 | *perr = 0; |
| 8025 | |
| 8026 | return wlc; |
| 8027 | |
| 8028 | fail: |
| 8029 | wiphy_err(wl->wiphy, "wl%d: %s: failed with err %d\n", |
| 8030 | unit, __func__, err); |
| 8031 | if (wlc) |
| 8032 | brcms_c_detach(wlc); |
| 8033 | |
| 8034 | if (perr) |
| 8035 | *perr = err; |
| 8036 | return NULL; |
| 8037 | } |