Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 Eugene Krasnikov <k.eugene.e@gmail.com> |
| 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 | |
| 17 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 18 | |
| 19 | #include <linux/module.h> |
Pontus Fuchs | 4bda7fa | 2014-02-12 19:04:43 +0000 | [diff] [blame] | 20 | #include <linux/firmware.h> |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 21 | #include <linux/platform_device.h> |
Bjorn Andersson | 05ddce4 | 2016-06-19 23:19:45 -0700 | [diff] [blame] | 22 | #include <linux/of_address.h> |
| 23 | #include <linux/of_device.h> |
Bjorn Andersson | f303a93 | 2017-01-11 16:32:18 +0200 | [diff] [blame^] | 24 | #include <linux/of_irq.h> |
| 25 | #include <linux/soc/qcom/smd.h> |
| 26 | #include <linux/soc/qcom/smem_state.h> |
| 27 | #include <linux/soc/qcom/wcnss_ctrl.h> |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 28 | #include "wcn36xx.h" |
| 29 | |
| 30 | unsigned int wcn36xx_dbg_mask; |
| 31 | module_param_named(debug_mask, wcn36xx_dbg_mask, uint, 0644); |
| 32 | MODULE_PARM_DESC(debug_mask, "Debugging mask"); |
| 33 | |
| 34 | #define CHAN2G(_freq, _idx) { \ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 35 | .band = NL80211_BAND_2GHZ, \ |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 36 | .center_freq = (_freq), \ |
| 37 | .hw_value = (_idx), \ |
| 38 | .max_power = 25, \ |
| 39 | } |
| 40 | |
| 41 | #define CHAN5G(_freq, _idx) { \ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 42 | .band = NL80211_BAND_5GHZ, \ |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 43 | .center_freq = (_freq), \ |
| 44 | .hw_value = (_idx), \ |
| 45 | .max_power = 25, \ |
| 46 | } |
| 47 | |
| 48 | /* The wcn firmware expects channel values to matching |
| 49 | * their mnemonic values. So use these for .hw_value. */ |
| 50 | static struct ieee80211_channel wcn_2ghz_channels[] = { |
| 51 | CHAN2G(2412, 1), /* Channel 1 */ |
| 52 | CHAN2G(2417, 2), /* Channel 2 */ |
| 53 | CHAN2G(2422, 3), /* Channel 3 */ |
| 54 | CHAN2G(2427, 4), /* Channel 4 */ |
| 55 | CHAN2G(2432, 5), /* Channel 5 */ |
| 56 | CHAN2G(2437, 6), /* Channel 6 */ |
| 57 | CHAN2G(2442, 7), /* Channel 7 */ |
| 58 | CHAN2G(2447, 8), /* Channel 8 */ |
| 59 | CHAN2G(2452, 9), /* Channel 9 */ |
| 60 | CHAN2G(2457, 10), /* Channel 10 */ |
| 61 | CHAN2G(2462, 11), /* Channel 11 */ |
| 62 | CHAN2G(2467, 12), /* Channel 12 */ |
| 63 | CHAN2G(2472, 13), /* Channel 13 */ |
| 64 | CHAN2G(2484, 14) /* Channel 14 */ |
| 65 | |
| 66 | }; |
| 67 | |
| 68 | static struct ieee80211_channel wcn_5ghz_channels[] = { |
| 69 | CHAN5G(5180, 36), |
| 70 | CHAN5G(5200, 40), |
| 71 | CHAN5G(5220, 44), |
| 72 | CHAN5G(5240, 48), |
| 73 | CHAN5G(5260, 52), |
| 74 | CHAN5G(5280, 56), |
| 75 | CHAN5G(5300, 60), |
| 76 | CHAN5G(5320, 64), |
| 77 | CHAN5G(5500, 100), |
| 78 | CHAN5G(5520, 104), |
| 79 | CHAN5G(5540, 108), |
| 80 | CHAN5G(5560, 112), |
| 81 | CHAN5G(5580, 116), |
| 82 | CHAN5G(5600, 120), |
| 83 | CHAN5G(5620, 124), |
| 84 | CHAN5G(5640, 128), |
| 85 | CHAN5G(5660, 132), |
| 86 | CHAN5G(5700, 140), |
| 87 | CHAN5G(5745, 149), |
| 88 | CHAN5G(5765, 153), |
| 89 | CHAN5G(5785, 157), |
| 90 | CHAN5G(5805, 161), |
| 91 | CHAN5G(5825, 165) |
| 92 | }; |
| 93 | |
| 94 | #define RATE(_bitrate, _hw_rate, _flags) { \ |
| 95 | .bitrate = (_bitrate), \ |
| 96 | .flags = (_flags), \ |
| 97 | .hw_value = (_hw_rate), \ |
| 98 | .hw_value_short = (_hw_rate) \ |
| 99 | } |
| 100 | |
| 101 | static struct ieee80211_rate wcn_2ghz_rates[] = { |
| 102 | RATE(10, HW_RATE_INDEX_1MBPS, 0), |
| 103 | RATE(20, HW_RATE_INDEX_2MBPS, IEEE80211_RATE_SHORT_PREAMBLE), |
| 104 | RATE(55, HW_RATE_INDEX_5_5MBPS, IEEE80211_RATE_SHORT_PREAMBLE), |
| 105 | RATE(110, HW_RATE_INDEX_11MBPS, IEEE80211_RATE_SHORT_PREAMBLE), |
| 106 | RATE(60, HW_RATE_INDEX_6MBPS, 0), |
| 107 | RATE(90, HW_RATE_INDEX_9MBPS, 0), |
| 108 | RATE(120, HW_RATE_INDEX_12MBPS, 0), |
| 109 | RATE(180, HW_RATE_INDEX_18MBPS, 0), |
| 110 | RATE(240, HW_RATE_INDEX_24MBPS, 0), |
| 111 | RATE(360, HW_RATE_INDEX_36MBPS, 0), |
| 112 | RATE(480, HW_RATE_INDEX_48MBPS, 0), |
| 113 | RATE(540, HW_RATE_INDEX_54MBPS, 0) |
| 114 | }; |
| 115 | |
| 116 | static struct ieee80211_rate wcn_5ghz_rates[] = { |
| 117 | RATE(60, HW_RATE_INDEX_6MBPS, 0), |
| 118 | RATE(90, HW_RATE_INDEX_9MBPS, 0), |
| 119 | RATE(120, HW_RATE_INDEX_12MBPS, 0), |
| 120 | RATE(180, HW_RATE_INDEX_18MBPS, 0), |
| 121 | RATE(240, HW_RATE_INDEX_24MBPS, 0), |
| 122 | RATE(360, HW_RATE_INDEX_36MBPS, 0), |
| 123 | RATE(480, HW_RATE_INDEX_48MBPS, 0), |
| 124 | RATE(540, HW_RATE_INDEX_54MBPS, 0) |
| 125 | }; |
| 126 | |
| 127 | static struct ieee80211_supported_band wcn_band_2ghz = { |
| 128 | .channels = wcn_2ghz_channels, |
| 129 | .n_channels = ARRAY_SIZE(wcn_2ghz_channels), |
| 130 | .bitrates = wcn_2ghz_rates, |
| 131 | .n_bitrates = ARRAY_SIZE(wcn_2ghz_rates), |
| 132 | .ht_cap = { |
| 133 | .cap = IEEE80211_HT_CAP_GRN_FLD | |
| 134 | IEEE80211_HT_CAP_SGI_20 | |
| 135 | IEEE80211_HT_CAP_DSSSCCK40 | |
| 136 | IEEE80211_HT_CAP_LSIG_TXOP_PROT, |
| 137 | .ht_supported = true, |
| 138 | .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K, |
| 139 | .ampdu_density = IEEE80211_HT_MPDU_DENSITY_16, |
| 140 | .mcs = { |
| 141 | .rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, |
| 142 | .rx_highest = cpu_to_le16(72), |
| 143 | .tx_params = IEEE80211_HT_MCS_TX_DEFINED, |
| 144 | } |
| 145 | } |
| 146 | }; |
| 147 | |
| 148 | static struct ieee80211_supported_band wcn_band_5ghz = { |
| 149 | .channels = wcn_5ghz_channels, |
| 150 | .n_channels = ARRAY_SIZE(wcn_5ghz_channels), |
| 151 | .bitrates = wcn_5ghz_rates, |
| 152 | .n_bitrates = ARRAY_SIZE(wcn_5ghz_rates), |
| 153 | .ht_cap = { |
| 154 | .cap = IEEE80211_HT_CAP_GRN_FLD | |
| 155 | IEEE80211_HT_CAP_SGI_20 | |
| 156 | IEEE80211_HT_CAP_DSSSCCK40 | |
| 157 | IEEE80211_HT_CAP_LSIG_TXOP_PROT | |
| 158 | IEEE80211_HT_CAP_SGI_40 | |
| 159 | IEEE80211_HT_CAP_SUP_WIDTH_20_40, |
| 160 | .ht_supported = true, |
| 161 | .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K, |
| 162 | .ampdu_density = IEEE80211_HT_MPDU_DENSITY_16, |
| 163 | .mcs = { |
| 164 | .rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, |
| 165 | .rx_highest = cpu_to_le16(72), |
| 166 | .tx_params = IEEE80211_HT_MCS_TX_DEFINED, |
| 167 | } |
| 168 | } |
| 169 | }; |
| 170 | |
| 171 | #ifdef CONFIG_PM |
| 172 | |
| 173 | static const struct wiphy_wowlan_support wowlan_support = { |
| 174 | .flags = WIPHY_WOWLAN_ANY |
| 175 | }; |
| 176 | |
| 177 | #endif |
| 178 | |
| 179 | static inline u8 get_sta_index(struct ieee80211_vif *vif, |
| 180 | struct wcn36xx_sta *sta_priv) |
| 181 | { |
| 182 | return NL80211_IFTYPE_STATION == vif->type ? |
| 183 | sta_priv->bss_sta_index : |
| 184 | sta_priv->sta_index; |
| 185 | } |
| 186 | |
Pontus Fuchs | 2be6636 | 2014-02-12 19:04:44 +0000 | [diff] [blame] | 187 | static const char * const wcn36xx_caps_names[] = { |
| 188 | "MCC", /* 0 */ |
| 189 | "P2P", /* 1 */ |
| 190 | "DOT11AC", /* 2 */ |
| 191 | "SLM_SESSIONIZATION", /* 3 */ |
| 192 | "DOT11AC_OPMODE", /* 4 */ |
| 193 | "SAP32STA", /* 5 */ |
| 194 | "TDLS", /* 6 */ |
| 195 | "P2P_GO_NOA_DECOUPLE_INIT_SCAN",/* 7 */ |
| 196 | "WLANACTIVE_OFFLOAD", /* 8 */ |
| 197 | "BEACON_OFFLOAD", /* 9 */ |
| 198 | "SCAN_OFFLOAD", /* 10 */ |
| 199 | "ROAM_OFFLOAD", /* 11 */ |
| 200 | "BCN_MISS_OFFLOAD", /* 12 */ |
| 201 | "STA_POWERSAVE", /* 13 */ |
| 202 | "STA_ADVANCED_PWRSAVE", /* 14 */ |
| 203 | "AP_UAPSD", /* 15 */ |
| 204 | "AP_DFS", /* 16 */ |
| 205 | "BLOCKACK", /* 17 */ |
| 206 | "PHY_ERR", /* 18 */ |
| 207 | "BCN_FILTER", /* 19 */ |
| 208 | "RTT", /* 20 */ |
| 209 | "RATECTRL", /* 21 */ |
Bjorn Andersson | ffc03c3 | 2016-04-18 22:00:56 -0700 | [diff] [blame] | 210 | "WOW", /* 22 */ |
| 211 | "WLAN_ROAM_SCAN_OFFLOAD", /* 23 */ |
| 212 | "SPECULATIVE_PS_POLL", /* 24 */ |
| 213 | "SCAN_SCH", /* 25 */ |
| 214 | "IBSS_HEARTBEAT_OFFLOAD", /* 26 */ |
| 215 | "WLAN_SCAN_OFFLOAD", /* 27 */ |
| 216 | "WLAN_PERIODIC_TX_PTRN", /* 28 */ |
| 217 | "ADVANCE_TDLS", /* 29 */ |
| 218 | "BATCH_SCAN", /* 30 */ |
| 219 | "FW_IN_TX_PATH", /* 31 */ |
| 220 | "EXTENDED_NSOFFLOAD_SLOT", /* 32 */ |
| 221 | "CH_SWITCH_V1", /* 33 */ |
| 222 | "HT40_OBSS_SCAN", /* 34 */ |
| 223 | "UPDATE_CHANNEL_LIST", /* 35 */ |
| 224 | "WLAN_MCADDR_FLT", /* 36 */ |
| 225 | "WLAN_CH144", /* 37 */ |
| 226 | "NAN", /* 38 */ |
| 227 | "TDLS_SCAN_COEXISTENCE", /* 39 */ |
| 228 | "LINK_LAYER_STATS_MEAS", /* 40 */ |
| 229 | "MU_MIMO", /* 41 */ |
| 230 | "EXTENDED_SCAN", /* 42 */ |
| 231 | "DYNAMIC_WMM_PS", /* 43 */ |
| 232 | "MAC_SPOOFED_SCAN", /* 44 */ |
| 233 | "BMU_ERROR_GENERIC_RECOVERY", /* 45 */ |
| 234 | "DISA", /* 46 */ |
| 235 | "FW_STATS", /* 47 */ |
| 236 | "WPS_PRBRSP_TMPL", /* 48 */ |
| 237 | "BCN_IE_FLT_DELTA", /* 49 */ |
| 238 | "TDLS_OFF_CHANNEL", /* 51 */ |
| 239 | "RTT3", /* 52 */ |
| 240 | "MGMT_FRAME_LOGGING", /* 53 */ |
| 241 | "ENHANCED_TXBD_COMPLETION", /* 54 */ |
| 242 | "LOGGING_ENHANCEMENT", /* 55 */ |
| 243 | "EXT_SCAN_ENHANCED", /* 56 */ |
| 244 | "MEMORY_DUMP_SUPPORTED", /* 57 */ |
| 245 | "PER_PKT_STATS_SUPPORTED", /* 58 */ |
| 246 | "EXT_LL_STAT", /* 60 */ |
| 247 | "WIFI_CONFIG", /* 61 */ |
| 248 | "ANTENNA_DIVERSITY_SELECTION", /* 62 */ |
Pontus Fuchs | 2be6636 | 2014-02-12 19:04:44 +0000 | [diff] [blame] | 249 | }; |
| 250 | |
| 251 | static const char *wcn36xx_get_cap_name(enum place_holder_in_cap_bitmap x) |
| 252 | { |
| 253 | if (x >= ARRAY_SIZE(wcn36xx_caps_names)) |
| 254 | return "UNKNOWN"; |
| 255 | return wcn36xx_caps_names[x]; |
| 256 | } |
| 257 | |
| 258 | static void wcn36xx_feat_caps_info(struct wcn36xx *wcn) |
| 259 | { |
| 260 | int i; |
| 261 | |
| 262 | for (i = 0; i < MAX_FEATURE_SUPPORTED; i++) { |
| 263 | if (get_feat_caps(wcn->fw_feat_caps, i)) |
| 264 | wcn36xx_info("FW Cap %s\n", wcn36xx_get_cap_name(i)); |
| 265 | } |
| 266 | } |
| 267 | |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 268 | static int wcn36xx_start(struct ieee80211_hw *hw) |
| 269 | { |
| 270 | struct wcn36xx *wcn = hw->priv; |
| 271 | int ret; |
| 272 | |
| 273 | wcn36xx_dbg(WCN36XX_DBG_MAC, "mac start\n"); |
| 274 | |
| 275 | /* SMD initialization */ |
| 276 | ret = wcn36xx_smd_open(wcn); |
| 277 | if (ret) { |
| 278 | wcn36xx_err("Failed to open smd channel: %d\n", ret); |
| 279 | goto out_err; |
| 280 | } |
| 281 | |
| 282 | /* Allocate memory pools for Mgmt BD headers and Data BD headers */ |
| 283 | ret = wcn36xx_dxe_allocate_mem_pools(wcn); |
| 284 | if (ret) { |
| 285 | wcn36xx_err("Failed to alloc DXE mempool: %d\n", ret); |
| 286 | goto out_smd_close; |
| 287 | } |
| 288 | |
| 289 | ret = wcn36xx_dxe_alloc_ctl_blks(wcn); |
| 290 | if (ret) { |
| 291 | wcn36xx_err("Failed to alloc DXE ctl blocks: %d\n", ret); |
| 292 | goto out_free_dxe_pool; |
| 293 | } |
| 294 | |
| 295 | wcn->hal_buf = kmalloc(WCN36XX_HAL_BUF_SIZE, GFP_KERNEL); |
| 296 | if (!wcn->hal_buf) { |
| 297 | wcn36xx_err("Failed to allocate smd buf\n"); |
| 298 | ret = -ENOMEM; |
| 299 | goto out_free_dxe_ctl; |
| 300 | } |
| 301 | |
| 302 | ret = wcn36xx_smd_load_nv(wcn); |
| 303 | if (ret) { |
| 304 | wcn36xx_err("Failed to push NV to chip\n"); |
| 305 | goto out_free_smd_buf; |
| 306 | } |
| 307 | |
| 308 | ret = wcn36xx_smd_start(wcn); |
| 309 | if (ret) { |
| 310 | wcn36xx_err("Failed to start chip\n"); |
| 311 | goto out_free_smd_buf; |
| 312 | } |
| 313 | |
Pontus Fuchs | f2ed5d2 | 2014-02-12 19:04:45 +0000 | [diff] [blame] | 314 | if (!wcn36xx_is_fw_version(wcn, 1, 2, 2, 24)) { |
| 315 | ret = wcn36xx_smd_feature_caps_exchange(wcn); |
| 316 | if (ret) |
| 317 | wcn36xx_warn("Exchange feature caps failed\n"); |
| 318 | else |
| 319 | wcn36xx_feat_caps_info(wcn); |
| 320 | } |
| 321 | |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 322 | /* DMA channel initialization */ |
| 323 | ret = wcn36xx_dxe_init(wcn); |
| 324 | if (ret) { |
| 325 | wcn36xx_err("DXE init failed\n"); |
| 326 | goto out_smd_stop; |
| 327 | } |
| 328 | |
| 329 | wcn36xx_debugfs_init(wcn); |
| 330 | |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 331 | INIT_LIST_HEAD(&wcn->vif_list); |
Bob Copeland | 4b12462 | 2015-01-09 14:15:50 -0500 | [diff] [blame] | 332 | spin_lock_init(&wcn->dxe_lock); |
| 333 | |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 334 | return 0; |
| 335 | |
| 336 | out_smd_stop: |
| 337 | wcn36xx_smd_stop(wcn); |
| 338 | out_free_smd_buf: |
| 339 | kfree(wcn->hal_buf); |
| 340 | out_free_dxe_pool: |
| 341 | wcn36xx_dxe_free_mem_pools(wcn); |
| 342 | out_free_dxe_ctl: |
| 343 | wcn36xx_dxe_free_ctl_blks(wcn); |
| 344 | out_smd_close: |
| 345 | wcn36xx_smd_close(wcn); |
| 346 | out_err: |
| 347 | return ret; |
| 348 | } |
| 349 | |
| 350 | static void wcn36xx_stop(struct ieee80211_hw *hw) |
| 351 | { |
| 352 | struct wcn36xx *wcn = hw->priv; |
| 353 | |
| 354 | wcn36xx_dbg(WCN36XX_DBG_MAC, "mac stop\n"); |
| 355 | |
| 356 | wcn36xx_debugfs_exit(wcn); |
| 357 | wcn36xx_smd_stop(wcn); |
| 358 | wcn36xx_dxe_deinit(wcn); |
| 359 | wcn36xx_smd_close(wcn); |
| 360 | |
| 361 | wcn36xx_dxe_free_mem_pools(wcn); |
| 362 | wcn36xx_dxe_free_ctl_blks(wcn); |
| 363 | |
| 364 | kfree(wcn->hal_buf); |
| 365 | } |
| 366 | |
| 367 | static int wcn36xx_config(struct ieee80211_hw *hw, u32 changed) |
| 368 | { |
| 369 | struct wcn36xx *wcn = hw->priv; |
| 370 | struct ieee80211_vif *vif = NULL; |
| 371 | struct wcn36xx_vif *tmp; |
| 372 | |
| 373 | wcn36xx_dbg(WCN36XX_DBG_MAC, "mac config changed 0x%08x\n", changed); |
| 374 | |
| 375 | if (changed & IEEE80211_CONF_CHANGE_CHANNEL) { |
| 376 | int ch = WCN36XX_HW_CHANNEL(wcn); |
| 377 | wcn36xx_dbg(WCN36XX_DBG_MAC, "wcn36xx_config channel switch=%d\n", |
| 378 | ch); |
| 379 | list_for_each_entry(tmp, &wcn->vif_list, list) { |
Pontus Fuchs | ce75877 | 2016-04-18 22:00:41 -0700 | [diff] [blame] | 380 | vif = wcn36xx_priv_to_vif(tmp); |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 381 | wcn36xx_smd_switch_channel(wcn, vif, ch); |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | return 0; |
| 386 | } |
| 387 | |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 388 | static void wcn36xx_configure_filter(struct ieee80211_hw *hw, |
| 389 | unsigned int changed, |
| 390 | unsigned int *total, u64 multicast) |
| 391 | { |
Pontus Fuchs | 20a779e | 2016-04-18 22:00:52 -0700 | [diff] [blame] | 392 | struct wcn36xx_hal_rcv_flt_mc_addr_list_type *fp; |
| 393 | struct wcn36xx *wcn = hw->priv; |
| 394 | struct wcn36xx_vif *tmp; |
| 395 | struct ieee80211_vif *vif = NULL; |
| 396 | |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 397 | wcn36xx_dbg(WCN36XX_DBG_MAC, "mac configure filter\n"); |
| 398 | |
Pontus Fuchs | 20a779e | 2016-04-18 22:00:52 -0700 | [diff] [blame] | 399 | *total &= FIF_ALLMULTI; |
| 400 | |
| 401 | fp = (void *)(unsigned long)multicast; |
| 402 | list_for_each_entry(tmp, &wcn->vif_list, list) { |
| 403 | vif = wcn36xx_priv_to_vif(tmp); |
| 404 | |
| 405 | /* FW handles MC filtering only when connected as STA */ |
| 406 | if (*total & FIF_ALLMULTI) |
| 407 | wcn36xx_smd_set_mc_list(wcn, vif, NULL); |
| 408 | else if (NL80211_IFTYPE_STATION == vif->type && tmp->sta_assoc) |
| 409 | wcn36xx_smd_set_mc_list(wcn, vif, fp); |
| 410 | } |
| 411 | kfree(fp); |
| 412 | } |
| 413 | |
| 414 | static u64 wcn36xx_prepare_multicast(struct ieee80211_hw *hw, |
| 415 | struct netdev_hw_addr_list *mc_list) |
| 416 | { |
| 417 | struct wcn36xx_hal_rcv_flt_mc_addr_list_type *fp; |
| 418 | struct netdev_hw_addr *ha; |
| 419 | |
| 420 | wcn36xx_dbg(WCN36XX_DBG_MAC, "mac prepare multicast list\n"); |
| 421 | fp = kzalloc(sizeof(*fp), GFP_ATOMIC); |
| 422 | if (!fp) { |
| 423 | wcn36xx_err("Out of memory setting filters.\n"); |
| 424 | return 0; |
| 425 | } |
| 426 | |
| 427 | fp->mc_addr_count = 0; |
| 428 | /* update multicast filtering parameters */ |
| 429 | if (netdev_hw_addr_list_count(mc_list) <= |
| 430 | WCN36XX_HAL_MAX_NUM_MULTICAST_ADDRESS) { |
| 431 | netdev_hw_addr_list_for_each(ha, mc_list) { |
| 432 | memcpy(fp->mc_addr[fp->mc_addr_count], |
| 433 | ha->addr, ETH_ALEN); |
| 434 | fp->mc_addr_count++; |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | return (u64)(unsigned long)fp; |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | static void wcn36xx_tx(struct ieee80211_hw *hw, |
| 442 | struct ieee80211_tx_control *control, |
| 443 | struct sk_buff *skb) |
| 444 | { |
| 445 | struct wcn36xx *wcn = hw->priv; |
| 446 | struct wcn36xx_sta *sta_priv = NULL; |
| 447 | |
| 448 | if (control->sta) |
Pontus Fuchs | a92e469 | 2016-04-18 22:00:44 -0700 | [diff] [blame] | 449 | sta_priv = wcn36xx_sta_to_priv(control->sta); |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 450 | |
| 451 | if (wcn36xx_start_tx(wcn, sta_priv, skb)) |
| 452 | ieee80211_free_txskb(wcn->hw, skb); |
| 453 | } |
| 454 | |
| 455 | static int wcn36xx_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, |
| 456 | struct ieee80211_vif *vif, |
| 457 | struct ieee80211_sta *sta, |
| 458 | struct ieee80211_key_conf *key_conf) |
| 459 | { |
| 460 | struct wcn36xx *wcn = hw->priv; |
Pontus Fuchs | ce75877 | 2016-04-18 22:00:41 -0700 | [diff] [blame] | 461 | struct wcn36xx_vif *vif_priv = wcn36xx_vif_to_priv(vif); |
Pontus Fuchs | 81c6926 | 2016-04-18 22:00:45 -0700 | [diff] [blame] | 462 | struct wcn36xx_sta *sta_priv = wcn36xx_sta_to_priv(sta); |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 463 | int ret = 0; |
| 464 | u8 key[WLAN_MAX_KEY_LEN]; |
| 465 | |
| 466 | wcn36xx_dbg(WCN36XX_DBG_MAC, "mac80211 set key\n"); |
| 467 | wcn36xx_dbg(WCN36XX_DBG_MAC, "Key: cmd=0x%x algo:0x%x, id:%d, len:%d flags 0x%x\n", |
| 468 | cmd, key_conf->cipher, key_conf->keyidx, |
| 469 | key_conf->keylen, key_conf->flags); |
| 470 | wcn36xx_dbg_dump(WCN36XX_DBG_MAC, "KEY: ", |
| 471 | key_conf->key, |
| 472 | key_conf->keylen); |
| 473 | |
| 474 | switch (key_conf->cipher) { |
| 475 | case WLAN_CIPHER_SUITE_WEP40: |
| 476 | vif_priv->encrypt_type = WCN36XX_HAL_ED_WEP40; |
| 477 | break; |
| 478 | case WLAN_CIPHER_SUITE_WEP104: |
| 479 | vif_priv->encrypt_type = WCN36XX_HAL_ED_WEP40; |
| 480 | break; |
| 481 | case WLAN_CIPHER_SUITE_CCMP: |
| 482 | vif_priv->encrypt_type = WCN36XX_HAL_ED_CCMP; |
| 483 | break; |
| 484 | case WLAN_CIPHER_SUITE_TKIP: |
| 485 | vif_priv->encrypt_type = WCN36XX_HAL_ED_TKIP; |
| 486 | break; |
| 487 | default: |
| 488 | wcn36xx_err("Unsupported key type 0x%x\n", |
| 489 | key_conf->cipher); |
| 490 | ret = -EOPNOTSUPP; |
| 491 | goto out; |
| 492 | } |
| 493 | |
| 494 | switch (cmd) { |
| 495 | case SET_KEY: |
| 496 | if (WCN36XX_HAL_ED_TKIP == vif_priv->encrypt_type) { |
| 497 | /* |
| 498 | * Supplicant is sending key in the wrong order: |
| 499 | * Temporal Key (16 b) - TX MIC (8 b) - RX MIC (8 b) |
| 500 | * but HW expects it to be in the order as described in |
| 501 | * IEEE 802.11 spec (see chapter 11.7) like this: |
| 502 | * Temporal Key (16 b) - RX MIC (8 b) - TX MIC (8 b) |
| 503 | */ |
| 504 | memcpy(key, key_conf->key, 16); |
| 505 | memcpy(key + 16, key_conf->key + 24, 8); |
| 506 | memcpy(key + 24, key_conf->key + 16, 8); |
| 507 | } else { |
| 508 | memcpy(key, key_conf->key, key_conf->keylen); |
| 509 | } |
| 510 | |
| 511 | if (IEEE80211_KEY_FLAG_PAIRWISE & key_conf->flags) { |
| 512 | sta_priv->is_data_encrypted = true; |
| 513 | /* Reconfigure bss with encrypt_type */ |
| 514 | if (NL80211_IFTYPE_STATION == vif->type) |
| 515 | wcn36xx_smd_config_bss(wcn, |
| 516 | vif, |
| 517 | sta, |
| 518 | sta->addr, |
| 519 | true); |
| 520 | |
| 521 | wcn36xx_smd_set_stakey(wcn, |
| 522 | vif_priv->encrypt_type, |
| 523 | key_conf->keyidx, |
| 524 | key_conf->keylen, |
| 525 | key, |
| 526 | get_sta_index(vif, sta_priv)); |
| 527 | } else { |
| 528 | wcn36xx_smd_set_bsskey(wcn, |
| 529 | vif_priv->encrypt_type, |
| 530 | key_conf->keyidx, |
| 531 | key_conf->keylen, |
| 532 | key); |
| 533 | if ((WLAN_CIPHER_SUITE_WEP40 == key_conf->cipher) || |
| 534 | (WLAN_CIPHER_SUITE_WEP104 == key_conf->cipher)) { |
| 535 | sta_priv->is_data_encrypted = true; |
| 536 | wcn36xx_smd_set_stakey(wcn, |
| 537 | vif_priv->encrypt_type, |
| 538 | key_conf->keyidx, |
| 539 | key_conf->keylen, |
| 540 | key, |
| 541 | get_sta_index(vif, sta_priv)); |
| 542 | } |
| 543 | } |
| 544 | break; |
| 545 | case DISABLE_KEY: |
| 546 | if (!(IEEE80211_KEY_FLAG_PAIRWISE & key_conf->flags)) { |
Pontus Fuchs | 2716a8ac | 2016-04-18 22:00:50 -0700 | [diff] [blame] | 547 | vif_priv->encrypt_type = WCN36XX_HAL_ED_NONE; |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 548 | wcn36xx_smd_remove_bsskey(wcn, |
| 549 | vif_priv->encrypt_type, |
| 550 | key_conf->keyidx); |
| 551 | } else { |
| 552 | sta_priv->is_data_encrypted = false; |
| 553 | /* do not remove key if disassociated */ |
| 554 | if (sta_priv->aid) |
| 555 | wcn36xx_smd_remove_stakey(wcn, |
| 556 | vif_priv->encrypt_type, |
| 557 | key_conf->keyidx, |
| 558 | get_sta_index(vif, sta_priv)); |
| 559 | } |
| 560 | break; |
| 561 | default: |
| 562 | wcn36xx_err("Unsupported key cmd 0x%x\n", cmd); |
| 563 | ret = -EOPNOTSUPP; |
| 564 | goto out; |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | out: |
| 568 | return ret; |
| 569 | } |
| 570 | |
Johannes Berg | a344d67 | 2014-06-12 22:24:31 +0200 | [diff] [blame] | 571 | static void wcn36xx_sw_scan_start(struct ieee80211_hw *hw, |
| 572 | struct ieee80211_vif *vif, |
| 573 | const u8 *mac_addr) |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 574 | { |
| 575 | struct wcn36xx *wcn = hw->priv; |
| 576 | |
| 577 | wcn36xx_smd_init_scan(wcn, HAL_SYS_MODE_SCAN); |
| 578 | wcn36xx_smd_start_scan(wcn); |
| 579 | } |
| 580 | |
Johannes Berg | a344d67 | 2014-06-12 22:24:31 +0200 | [diff] [blame] | 581 | static void wcn36xx_sw_scan_complete(struct ieee80211_hw *hw, |
| 582 | struct ieee80211_vif *vif) |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 583 | { |
| 584 | struct wcn36xx *wcn = hw->priv; |
| 585 | |
| 586 | wcn36xx_smd_end_scan(wcn); |
| 587 | wcn36xx_smd_finish_scan(wcn, HAL_SYS_MODE_SCAN); |
| 588 | } |
| 589 | |
| 590 | static void wcn36xx_update_allowed_rates(struct ieee80211_sta *sta, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 591 | enum nl80211_band band) |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 592 | { |
| 593 | int i, size; |
| 594 | u16 *rates_table; |
Pontus Fuchs | a92e469 | 2016-04-18 22:00:44 -0700 | [diff] [blame] | 595 | struct wcn36xx_sta *sta_priv = wcn36xx_sta_to_priv(sta); |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 596 | u32 rates = sta->supp_rates[band]; |
| 597 | |
| 598 | memset(&sta_priv->supported_rates, 0, |
| 599 | sizeof(sta_priv->supported_rates)); |
| 600 | sta_priv->supported_rates.op_rate_mode = STA_11n; |
| 601 | |
| 602 | size = ARRAY_SIZE(sta_priv->supported_rates.dsss_rates); |
| 603 | rates_table = sta_priv->supported_rates.dsss_rates; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 604 | if (band == NL80211_BAND_2GHZ) { |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 605 | for (i = 0; i < size; i++) { |
| 606 | if (rates & 0x01) { |
| 607 | rates_table[i] = wcn_2ghz_rates[i].hw_value; |
| 608 | rates = rates >> 1; |
| 609 | } |
| 610 | } |
| 611 | } |
| 612 | |
| 613 | size = ARRAY_SIZE(sta_priv->supported_rates.ofdm_rates); |
| 614 | rates_table = sta_priv->supported_rates.ofdm_rates; |
| 615 | for (i = 0; i < size; i++) { |
| 616 | if (rates & 0x01) { |
| 617 | rates_table[i] = wcn_5ghz_rates[i].hw_value; |
| 618 | rates = rates >> 1; |
| 619 | } |
| 620 | } |
| 621 | |
| 622 | if (sta->ht_cap.ht_supported) { |
| 623 | BUILD_BUG_ON(sizeof(sta->ht_cap.mcs.rx_mask) > |
| 624 | sizeof(sta_priv->supported_rates.supported_mcs_set)); |
| 625 | memcpy(sta_priv->supported_rates.supported_mcs_set, |
| 626 | sta->ht_cap.mcs.rx_mask, |
| 627 | sizeof(sta->ht_cap.mcs.rx_mask)); |
| 628 | } |
| 629 | } |
| 630 | void wcn36xx_set_default_rates(struct wcn36xx_hal_supported_rates *rates) |
| 631 | { |
| 632 | u16 ofdm_rates[WCN36XX_HAL_NUM_OFDM_RATES] = { |
| 633 | HW_RATE_INDEX_6MBPS, |
| 634 | HW_RATE_INDEX_9MBPS, |
| 635 | HW_RATE_INDEX_12MBPS, |
| 636 | HW_RATE_INDEX_18MBPS, |
| 637 | HW_RATE_INDEX_24MBPS, |
| 638 | HW_RATE_INDEX_36MBPS, |
| 639 | HW_RATE_INDEX_48MBPS, |
| 640 | HW_RATE_INDEX_54MBPS |
| 641 | }; |
| 642 | u16 dsss_rates[WCN36XX_HAL_NUM_DSSS_RATES] = { |
| 643 | HW_RATE_INDEX_1MBPS, |
| 644 | HW_RATE_INDEX_2MBPS, |
| 645 | HW_RATE_INDEX_5_5MBPS, |
| 646 | HW_RATE_INDEX_11MBPS |
| 647 | }; |
| 648 | |
| 649 | rates->op_rate_mode = STA_11n; |
| 650 | memcpy(rates->dsss_rates, dsss_rates, |
| 651 | sizeof(*dsss_rates) * WCN36XX_HAL_NUM_DSSS_RATES); |
| 652 | memcpy(rates->ofdm_rates, ofdm_rates, |
| 653 | sizeof(*ofdm_rates) * WCN36XX_HAL_NUM_OFDM_RATES); |
| 654 | rates->supported_mcs_set[0] = 0xFF; |
| 655 | } |
| 656 | static void wcn36xx_bss_info_changed(struct ieee80211_hw *hw, |
| 657 | struct ieee80211_vif *vif, |
| 658 | struct ieee80211_bss_conf *bss_conf, |
| 659 | u32 changed) |
| 660 | { |
| 661 | struct wcn36xx *wcn = hw->priv; |
| 662 | struct sk_buff *skb = NULL; |
| 663 | u16 tim_off, tim_len; |
| 664 | enum wcn36xx_hal_link_state link_state; |
Pontus Fuchs | ce75877 | 2016-04-18 22:00:41 -0700 | [diff] [blame] | 665 | struct wcn36xx_vif *vif_priv = wcn36xx_vif_to_priv(vif); |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 666 | |
| 667 | wcn36xx_dbg(WCN36XX_DBG_MAC, "mac bss info changed vif %p changed 0x%08x\n", |
| 668 | vif, changed); |
| 669 | |
| 670 | if (changed & BSS_CHANGED_BEACON_INFO) { |
| 671 | wcn36xx_dbg(WCN36XX_DBG_MAC, |
| 672 | "mac bss changed dtim period %d\n", |
| 673 | bss_conf->dtim_period); |
| 674 | |
| 675 | vif_priv->dtim_period = bss_conf->dtim_period; |
| 676 | } |
| 677 | |
| 678 | if (changed & BSS_CHANGED_PS) { |
| 679 | wcn36xx_dbg(WCN36XX_DBG_MAC, |
| 680 | "mac bss PS set %d\n", |
| 681 | bss_conf->ps); |
| 682 | if (bss_conf->ps) { |
| 683 | wcn36xx_pmc_enter_bmps_state(wcn, vif); |
| 684 | } else { |
| 685 | wcn36xx_pmc_exit_bmps_state(wcn, vif); |
| 686 | } |
| 687 | } |
| 688 | |
| 689 | if (changed & BSS_CHANGED_BSSID) { |
| 690 | wcn36xx_dbg(WCN36XX_DBG_MAC, "mac bss changed_bssid %pM\n", |
| 691 | bss_conf->bssid); |
| 692 | |
| 693 | if (!is_zero_ether_addr(bss_conf->bssid)) { |
| 694 | vif_priv->is_joining = true; |
Pontus Fuchs | 90023c0 | 2016-04-18 22:00:43 -0700 | [diff] [blame] | 695 | vif_priv->bss_index = WCN36XX_HAL_BSS_INVALID_IDX; |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 696 | wcn36xx_smd_join(wcn, bss_conf->bssid, |
| 697 | vif->addr, WCN36XX_HW_CHANNEL(wcn)); |
| 698 | wcn36xx_smd_config_bss(wcn, vif, NULL, |
| 699 | bss_conf->bssid, false); |
| 700 | } else { |
| 701 | vif_priv->is_joining = false; |
| 702 | wcn36xx_smd_delete_bss(wcn, vif); |
Pontus Fuchs | 2716a8ac | 2016-04-18 22:00:50 -0700 | [diff] [blame] | 703 | vif_priv->encrypt_type = WCN36XX_HAL_ED_NONE; |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 704 | } |
| 705 | } |
| 706 | |
| 707 | if (changed & BSS_CHANGED_SSID) { |
| 708 | wcn36xx_dbg(WCN36XX_DBG_MAC, |
| 709 | "mac bss changed ssid\n"); |
| 710 | wcn36xx_dbg_dump(WCN36XX_DBG_MAC, "ssid ", |
| 711 | bss_conf->ssid, bss_conf->ssid_len); |
| 712 | |
| 713 | vif_priv->ssid.length = bss_conf->ssid_len; |
| 714 | memcpy(&vif_priv->ssid.ssid, |
| 715 | bss_conf->ssid, |
| 716 | bss_conf->ssid_len); |
| 717 | } |
| 718 | |
| 719 | if (changed & BSS_CHANGED_ASSOC) { |
| 720 | vif_priv->is_joining = false; |
| 721 | if (bss_conf->assoc) { |
| 722 | struct ieee80211_sta *sta; |
| 723 | struct wcn36xx_sta *sta_priv; |
| 724 | |
| 725 | wcn36xx_dbg(WCN36XX_DBG_MAC, |
| 726 | "mac assoc bss %pM vif %pM AID=%d\n", |
| 727 | bss_conf->bssid, |
| 728 | vif->addr, |
| 729 | bss_conf->aid); |
| 730 | |
Pontus Fuchs | 043ce54 | 2016-04-18 22:00:51 -0700 | [diff] [blame] | 731 | vif_priv->sta_assoc = true; |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 732 | rcu_read_lock(); |
| 733 | sta = ieee80211_find_sta(vif, bss_conf->bssid); |
| 734 | if (!sta) { |
| 735 | wcn36xx_err("sta %pM is not found\n", |
| 736 | bss_conf->bssid); |
| 737 | rcu_read_unlock(); |
| 738 | goto out; |
| 739 | } |
Pontus Fuchs | a92e469 | 2016-04-18 22:00:44 -0700 | [diff] [blame] | 740 | sta_priv = wcn36xx_sta_to_priv(sta); |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 741 | |
| 742 | wcn36xx_update_allowed_rates(sta, WCN36XX_BAND(wcn)); |
| 743 | |
| 744 | wcn36xx_smd_set_link_st(wcn, bss_conf->bssid, |
| 745 | vif->addr, |
| 746 | WCN36XX_HAL_LINK_POSTASSOC_STATE); |
| 747 | wcn36xx_smd_config_bss(wcn, vif, sta, |
| 748 | bss_conf->bssid, |
| 749 | true); |
| 750 | sta_priv->aid = bss_conf->aid; |
| 751 | /* |
| 752 | * config_sta must be called from because this is the |
| 753 | * place where AID is available. |
| 754 | */ |
| 755 | wcn36xx_smd_config_sta(wcn, vif, sta); |
| 756 | rcu_read_unlock(); |
| 757 | } else { |
| 758 | wcn36xx_dbg(WCN36XX_DBG_MAC, |
| 759 | "disassociated bss %pM vif %pM AID=%d\n", |
| 760 | bss_conf->bssid, |
| 761 | vif->addr, |
| 762 | bss_conf->aid); |
Pontus Fuchs | 043ce54 | 2016-04-18 22:00:51 -0700 | [diff] [blame] | 763 | vif_priv->sta_assoc = false; |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 764 | wcn36xx_smd_set_link_st(wcn, |
| 765 | bss_conf->bssid, |
| 766 | vif->addr, |
| 767 | WCN36XX_HAL_LINK_IDLE_STATE); |
| 768 | } |
| 769 | } |
| 770 | |
| 771 | if (changed & BSS_CHANGED_AP_PROBE_RESP) { |
| 772 | wcn36xx_dbg(WCN36XX_DBG_MAC, "mac bss changed ap probe resp\n"); |
| 773 | skb = ieee80211_proberesp_get(hw, vif); |
| 774 | if (!skb) { |
| 775 | wcn36xx_err("failed to alloc probereq skb\n"); |
| 776 | goto out; |
| 777 | } |
| 778 | |
| 779 | wcn36xx_smd_update_proberesp_tmpl(wcn, vif, skb); |
| 780 | dev_kfree_skb(skb); |
| 781 | } |
| 782 | |
Chun-Yeow Yeoh | b3e3f87 | 2013-10-31 14:07:45 +0800 | [diff] [blame] | 783 | if (changed & BSS_CHANGED_BEACON_ENABLED || |
| 784 | changed & BSS_CHANGED_BEACON) { |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 785 | wcn36xx_dbg(WCN36XX_DBG_MAC, |
| 786 | "mac bss changed beacon enabled %d\n", |
| 787 | bss_conf->enable_beacon); |
| 788 | |
| 789 | if (bss_conf->enable_beacon) { |
Pontus Fuchs | 908628d | 2014-02-12 19:04:48 +0000 | [diff] [blame] | 790 | vif_priv->dtim_period = bss_conf->dtim_period; |
Pontus Fuchs | 90023c0 | 2016-04-18 22:00:43 -0700 | [diff] [blame] | 791 | vif_priv->bss_index = WCN36XX_HAL_BSS_INVALID_IDX; |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 792 | wcn36xx_smd_config_bss(wcn, vif, NULL, |
| 793 | vif->addr, false); |
| 794 | skb = ieee80211_beacon_get_tim(hw, vif, &tim_off, |
| 795 | &tim_len); |
| 796 | if (!skb) { |
| 797 | wcn36xx_err("failed to alloc beacon skb\n"); |
| 798 | goto out; |
| 799 | } |
| 800 | wcn36xx_smd_send_beacon(wcn, vif, skb, tim_off, 0); |
| 801 | dev_kfree_skb(skb); |
| 802 | |
| 803 | if (vif->type == NL80211_IFTYPE_ADHOC || |
| 804 | vif->type == NL80211_IFTYPE_MESH_POINT) |
| 805 | link_state = WCN36XX_HAL_LINK_IBSS_STATE; |
| 806 | else |
| 807 | link_state = WCN36XX_HAL_LINK_AP_STATE; |
| 808 | |
| 809 | wcn36xx_smd_set_link_st(wcn, vif->addr, vif->addr, |
| 810 | link_state); |
| 811 | } else { |
Bjorn Andersson | 5443918 | 2016-04-18 22:00:54 -0700 | [diff] [blame] | 812 | wcn36xx_smd_delete_bss(wcn, vif); |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 813 | wcn36xx_smd_set_link_st(wcn, vif->addr, vif->addr, |
| 814 | WCN36XX_HAL_LINK_IDLE_STATE); |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 815 | } |
| 816 | } |
| 817 | out: |
| 818 | return; |
| 819 | } |
| 820 | |
| 821 | /* this is required when using IEEE80211_HW_HAS_RATE_CONTROL */ |
| 822 | static int wcn36xx_set_rts_threshold(struct ieee80211_hw *hw, u32 value) |
| 823 | { |
| 824 | struct wcn36xx *wcn = hw->priv; |
| 825 | wcn36xx_dbg(WCN36XX_DBG_MAC, "mac set RTS threshold %d\n", value); |
| 826 | |
| 827 | wcn36xx_smd_update_cfg(wcn, WCN36XX_HAL_CFG_RTS_THRESHOLD, value); |
| 828 | return 0; |
| 829 | } |
| 830 | |
| 831 | static void wcn36xx_remove_interface(struct ieee80211_hw *hw, |
| 832 | struct ieee80211_vif *vif) |
| 833 | { |
| 834 | struct wcn36xx *wcn = hw->priv; |
Pontus Fuchs | ce75877 | 2016-04-18 22:00:41 -0700 | [diff] [blame] | 835 | struct wcn36xx_vif *vif_priv = wcn36xx_vif_to_priv(vif); |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 836 | wcn36xx_dbg(WCN36XX_DBG_MAC, "mac remove interface vif %p\n", vif); |
| 837 | |
| 838 | list_del(&vif_priv->list); |
| 839 | wcn36xx_smd_delete_sta_self(wcn, vif->addr); |
| 840 | } |
| 841 | |
| 842 | static int wcn36xx_add_interface(struct ieee80211_hw *hw, |
| 843 | struct ieee80211_vif *vif) |
| 844 | { |
| 845 | struct wcn36xx *wcn = hw->priv; |
Pontus Fuchs | ce75877 | 2016-04-18 22:00:41 -0700 | [diff] [blame] | 846 | struct wcn36xx_vif *vif_priv = wcn36xx_vif_to_priv(vif); |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 847 | |
| 848 | wcn36xx_dbg(WCN36XX_DBG_MAC, "mac add interface vif %p type %d\n", |
| 849 | vif, vif->type); |
| 850 | |
| 851 | if (!(NL80211_IFTYPE_STATION == vif->type || |
| 852 | NL80211_IFTYPE_AP == vif->type || |
| 853 | NL80211_IFTYPE_ADHOC == vif->type || |
| 854 | NL80211_IFTYPE_MESH_POINT == vif->type)) { |
| 855 | wcn36xx_warn("Unsupported interface type requested: %d\n", |
| 856 | vif->type); |
| 857 | return -EOPNOTSUPP; |
| 858 | } |
| 859 | |
| 860 | list_add(&vif_priv->list, &wcn->vif_list); |
| 861 | wcn36xx_smd_add_sta_self(wcn, vif); |
| 862 | |
| 863 | return 0; |
| 864 | } |
| 865 | |
| 866 | static int wcn36xx_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 867 | struct ieee80211_sta *sta) |
| 868 | { |
| 869 | struct wcn36xx *wcn = hw->priv; |
Pontus Fuchs | ce75877 | 2016-04-18 22:00:41 -0700 | [diff] [blame] | 870 | struct wcn36xx_vif *vif_priv = wcn36xx_vif_to_priv(vif); |
Pontus Fuchs | a92e469 | 2016-04-18 22:00:44 -0700 | [diff] [blame] | 871 | struct wcn36xx_sta *sta_priv = wcn36xx_sta_to_priv(sta); |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 872 | wcn36xx_dbg(WCN36XX_DBG_MAC, "mac sta add vif %p sta %pM\n", |
| 873 | vif, sta->addr); |
| 874 | |
Bob Copeland | e26dc17 | 2015-01-09 14:15:52 -0500 | [diff] [blame] | 875 | spin_lock_init(&sta_priv->ampdu_lock); |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 876 | sta_priv->vif = vif_priv; |
| 877 | /* |
| 878 | * For STA mode HW will be configured on BSS_CHANGED_ASSOC because |
| 879 | * at this stage AID is not available yet. |
| 880 | */ |
| 881 | if (NL80211_IFTYPE_STATION != vif->type) { |
| 882 | wcn36xx_update_allowed_rates(sta, WCN36XX_BAND(wcn)); |
| 883 | sta_priv->aid = sta->aid; |
| 884 | wcn36xx_smd_config_sta(wcn, vif, sta); |
| 885 | } |
| 886 | return 0; |
| 887 | } |
| 888 | |
| 889 | static int wcn36xx_sta_remove(struct ieee80211_hw *hw, |
| 890 | struct ieee80211_vif *vif, |
| 891 | struct ieee80211_sta *sta) |
| 892 | { |
| 893 | struct wcn36xx *wcn = hw->priv; |
Pontus Fuchs | a92e469 | 2016-04-18 22:00:44 -0700 | [diff] [blame] | 894 | struct wcn36xx_sta *sta_priv = wcn36xx_sta_to_priv(sta); |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 895 | |
| 896 | wcn36xx_dbg(WCN36XX_DBG_MAC, "mac sta remove vif %p sta %pM index %d\n", |
| 897 | vif, sta->addr, sta_priv->sta_index); |
| 898 | |
| 899 | wcn36xx_smd_delete_sta(wcn, sta_priv->sta_index); |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 900 | sta_priv->vif = NULL; |
| 901 | return 0; |
| 902 | } |
| 903 | |
| 904 | #ifdef CONFIG_PM |
| 905 | |
| 906 | static int wcn36xx_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wow) |
| 907 | { |
| 908 | struct wcn36xx *wcn = hw->priv; |
| 909 | |
| 910 | wcn36xx_dbg(WCN36XX_DBG_MAC, "mac suspend\n"); |
| 911 | |
| 912 | flush_workqueue(wcn->hal_ind_wq); |
| 913 | wcn36xx_smd_set_power_params(wcn, true); |
| 914 | return 0; |
| 915 | } |
| 916 | |
| 917 | static int wcn36xx_resume(struct ieee80211_hw *hw) |
| 918 | { |
| 919 | struct wcn36xx *wcn = hw->priv; |
| 920 | |
| 921 | wcn36xx_dbg(WCN36XX_DBG_MAC, "mac resume\n"); |
| 922 | |
| 923 | flush_workqueue(wcn->hal_ind_wq); |
| 924 | wcn36xx_smd_set_power_params(wcn, false); |
| 925 | return 0; |
| 926 | } |
| 927 | |
| 928 | #endif |
| 929 | |
| 930 | static int wcn36xx_ampdu_action(struct ieee80211_hw *hw, |
| 931 | struct ieee80211_vif *vif, |
Sara Sharon | 50ea05e | 2015-12-30 16:06:04 +0200 | [diff] [blame] | 932 | struct ieee80211_ampdu_params *params) |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 933 | { |
| 934 | struct wcn36xx *wcn = hw->priv; |
Pontus Fuchs | a92e469 | 2016-04-18 22:00:44 -0700 | [diff] [blame] | 935 | struct wcn36xx_sta *sta_priv = wcn36xx_sta_to_priv(params->sta); |
Sara Sharon | 50ea05e | 2015-12-30 16:06:04 +0200 | [diff] [blame] | 936 | struct ieee80211_sta *sta = params->sta; |
| 937 | enum ieee80211_ampdu_mlme_action action = params->action; |
| 938 | u16 tid = params->tid; |
| 939 | u16 *ssn = ¶ms->ssn; |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 940 | |
| 941 | wcn36xx_dbg(WCN36XX_DBG_MAC, "mac ampdu action action %d tid %d\n", |
| 942 | action, tid); |
| 943 | |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 944 | switch (action) { |
| 945 | case IEEE80211_AMPDU_RX_START: |
| 946 | sta_priv->tid = tid; |
| 947 | wcn36xx_smd_add_ba_session(wcn, sta, tid, ssn, 0, |
| 948 | get_sta_index(vif, sta_priv)); |
| 949 | wcn36xx_smd_add_ba(wcn); |
| 950 | wcn36xx_smd_trigger_ba(wcn, get_sta_index(vif, sta_priv)); |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 951 | break; |
| 952 | case IEEE80211_AMPDU_RX_STOP: |
| 953 | wcn36xx_smd_del_ba(wcn, tid, get_sta_index(vif, sta_priv)); |
| 954 | break; |
| 955 | case IEEE80211_AMPDU_TX_START: |
Bob Copeland | e26dc17 | 2015-01-09 14:15:52 -0500 | [diff] [blame] | 956 | spin_lock_bh(&sta_priv->ampdu_lock); |
| 957 | sta_priv->ampdu_state[tid] = WCN36XX_AMPDU_START; |
| 958 | spin_unlock_bh(&sta_priv->ampdu_lock); |
| 959 | |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 960 | ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 961 | break; |
| 962 | case IEEE80211_AMPDU_TX_OPERATIONAL: |
Bob Copeland | e26dc17 | 2015-01-09 14:15:52 -0500 | [diff] [blame] | 963 | spin_lock_bh(&sta_priv->ampdu_lock); |
| 964 | sta_priv->ampdu_state[tid] = WCN36XX_AMPDU_OPERATIONAL; |
| 965 | spin_unlock_bh(&sta_priv->ampdu_lock); |
| 966 | |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 967 | wcn36xx_smd_add_ba_session(wcn, sta, tid, ssn, 1, |
| 968 | get_sta_index(vif, sta_priv)); |
| 969 | break; |
| 970 | case IEEE80211_AMPDU_TX_STOP_FLUSH: |
| 971 | case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: |
| 972 | case IEEE80211_AMPDU_TX_STOP_CONT: |
Bob Copeland | e26dc17 | 2015-01-09 14:15:52 -0500 | [diff] [blame] | 973 | spin_lock_bh(&sta_priv->ampdu_lock); |
| 974 | sta_priv->ampdu_state[tid] = WCN36XX_AMPDU_NONE; |
| 975 | spin_unlock_bh(&sta_priv->ampdu_lock); |
| 976 | |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 977 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 978 | break; |
| 979 | default: |
| 980 | wcn36xx_err("Unknown AMPDU action\n"); |
| 981 | } |
| 982 | |
| 983 | return 0; |
| 984 | } |
| 985 | |
| 986 | static const struct ieee80211_ops wcn36xx_ops = { |
| 987 | .start = wcn36xx_start, |
| 988 | .stop = wcn36xx_stop, |
| 989 | .add_interface = wcn36xx_add_interface, |
| 990 | .remove_interface = wcn36xx_remove_interface, |
| 991 | #ifdef CONFIG_PM |
| 992 | .suspend = wcn36xx_suspend, |
| 993 | .resume = wcn36xx_resume, |
| 994 | #endif |
| 995 | .config = wcn36xx_config, |
Pontus Fuchs | 20a779e | 2016-04-18 22:00:52 -0700 | [diff] [blame] | 996 | .prepare_multicast = wcn36xx_prepare_multicast, |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 997 | .configure_filter = wcn36xx_configure_filter, |
| 998 | .tx = wcn36xx_tx, |
| 999 | .set_key = wcn36xx_set_key, |
| 1000 | .sw_scan_start = wcn36xx_sw_scan_start, |
| 1001 | .sw_scan_complete = wcn36xx_sw_scan_complete, |
| 1002 | .bss_info_changed = wcn36xx_bss_info_changed, |
| 1003 | .set_rts_threshold = wcn36xx_set_rts_threshold, |
| 1004 | .sta_add = wcn36xx_sta_add, |
| 1005 | .sta_remove = wcn36xx_sta_remove, |
| 1006 | .ampdu_action = wcn36xx_ampdu_action, |
| 1007 | }; |
| 1008 | |
| 1009 | static int wcn36xx_init_ieee80211(struct wcn36xx *wcn) |
| 1010 | { |
| 1011 | int ret = 0; |
| 1012 | |
| 1013 | static const u32 cipher_suites[] = { |
| 1014 | WLAN_CIPHER_SUITE_WEP40, |
| 1015 | WLAN_CIPHER_SUITE_WEP104, |
| 1016 | WLAN_CIPHER_SUITE_TKIP, |
| 1017 | WLAN_CIPHER_SUITE_CCMP, |
| 1018 | }; |
| 1019 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1020 | ieee80211_hw_set(wcn->hw, TIMING_BEACON_ONLY); |
| 1021 | ieee80211_hw_set(wcn->hw, AMPDU_AGGREGATION); |
| 1022 | ieee80211_hw_set(wcn->hw, CONNECTION_MONITOR); |
| 1023 | ieee80211_hw_set(wcn->hw, SUPPORTS_PS); |
| 1024 | ieee80211_hw_set(wcn->hw, SIGNAL_DBM); |
| 1025 | ieee80211_hw_set(wcn->hw, HAS_RATE_CONTROL); |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 1026 | |
| 1027 | wcn->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | |
| 1028 | BIT(NL80211_IFTYPE_AP) | |
| 1029 | BIT(NL80211_IFTYPE_ADHOC) | |
| 1030 | BIT(NL80211_IFTYPE_MESH_POINT); |
| 1031 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1032 | wcn->hw->wiphy->bands[NL80211_BAND_2GHZ] = &wcn_band_2ghz; |
| 1033 | wcn->hw->wiphy->bands[NL80211_BAND_5GHZ] = &wcn_band_5ghz; |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 1034 | |
| 1035 | wcn->hw->wiphy->cipher_suites = cipher_suites; |
| 1036 | wcn->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites); |
| 1037 | |
| 1038 | wcn->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD; |
| 1039 | |
| 1040 | #ifdef CONFIG_PM |
| 1041 | wcn->hw->wiphy->wowlan = &wowlan_support; |
| 1042 | #endif |
| 1043 | |
| 1044 | wcn->hw->max_listen_interval = 200; |
| 1045 | |
| 1046 | wcn->hw->queues = 4; |
| 1047 | |
| 1048 | SET_IEEE80211_DEV(wcn->hw, wcn->dev); |
| 1049 | |
| 1050 | wcn->hw->sta_data_size = sizeof(struct wcn36xx_sta); |
| 1051 | wcn->hw->vif_data_size = sizeof(struct wcn36xx_vif); |
| 1052 | |
| 1053 | return ret; |
| 1054 | } |
| 1055 | |
| 1056 | static int wcn36xx_platform_get_resources(struct wcn36xx *wcn, |
| 1057 | struct platform_device *pdev) |
| 1058 | { |
Bjorn Andersson | 05ddce4 | 2016-06-19 23:19:45 -0700 | [diff] [blame] | 1059 | struct device_node *mmio_node; |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 1060 | struct resource *res; |
Bjorn Andersson | 05ddce4 | 2016-06-19 23:19:45 -0700 | [diff] [blame] | 1061 | int index; |
| 1062 | int ret; |
| 1063 | |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 1064 | /* Set TX IRQ */ |
Bjorn Andersson | f303a93 | 2017-01-11 16:32:18 +0200 | [diff] [blame^] | 1065 | res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "tx"); |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 1066 | if (!res) { |
| 1067 | wcn36xx_err("failed to get tx_irq\n"); |
| 1068 | return -ENOENT; |
| 1069 | } |
| 1070 | wcn->tx_irq = res->start; |
| 1071 | |
| 1072 | /* Set RX IRQ */ |
Bjorn Andersson | f303a93 | 2017-01-11 16:32:18 +0200 | [diff] [blame^] | 1073 | res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "rx"); |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 1074 | if (!res) { |
| 1075 | wcn36xx_err("failed to get rx_irq\n"); |
| 1076 | return -ENOENT; |
| 1077 | } |
| 1078 | wcn->rx_irq = res->start; |
| 1079 | |
Bjorn Andersson | f303a93 | 2017-01-11 16:32:18 +0200 | [diff] [blame^] | 1080 | /* Acquire SMSM tx enable handle */ |
| 1081 | wcn->tx_enable_state = qcom_smem_state_get(&pdev->dev, |
| 1082 | "tx-enable", &wcn->tx_enable_state_bit); |
| 1083 | if (IS_ERR(wcn->tx_enable_state)) { |
| 1084 | wcn36xx_err("failed to get tx-enable state\n"); |
| 1085 | return PTR_ERR(wcn->tx_enable_state); |
| 1086 | } |
| 1087 | |
| 1088 | /* Acquire SMSM tx rings empty handle */ |
| 1089 | wcn->tx_rings_empty_state = qcom_smem_state_get(&pdev->dev, |
| 1090 | "tx-rings-empty", &wcn->tx_rings_empty_state_bit); |
| 1091 | if (IS_ERR(wcn->tx_rings_empty_state)) { |
| 1092 | wcn36xx_err("failed to get tx-rings-empty state\n"); |
| 1093 | return PTR_ERR(wcn->tx_rings_empty_state); |
| 1094 | } |
| 1095 | |
Bjorn Andersson | 05ddce4 | 2016-06-19 23:19:45 -0700 | [diff] [blame] | 1096 | mmio_node = of_parse_phandle(pdev->dev.parent->of_node, "qcom,mmio", 0); |
| 1097 | if (!mmio_node) { |
| 1098 | wcn36xx_err("failed to acquire qcom,mmio reference\n"); |
| 1099 | return -EINVAL; |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 1100 | } |
Bjorn Andersson | 05ddce4 | 2016-06-19 23:19:45 -0700 | [diff] [blame] | 1101 | |
Bjorn Andersson | 6f10b4e | 2016-06-19 23:19:46 -0700 | [diff] [blame] | 1102 | wcn->is_pronto = !!of_device_is_compatible(mmio_node, "qcom,pronto"); |
| 1103 | |
Bjorn Andersson | 05ddce4 | 2016-06-19 23:19:45 -0700 | [diff] [blame] | 1104 | /* Map the CCU memory */ |
| 1105 | index = of_property_match_string(mmio_node, "reg-names", "ccu"); |
| 1106 | wcn->ccu_base = of_iomap(mmio_node, index); |
| 1107 | if (!wcn->ccu_base) { |
| 1108 | wcn36xx_err("failed to map ccu memory\n"); |
| 1109 | ret = -ENOMEM; |
| 1110 | goto put_mmio_node; |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 1111 | } |
Bjorn Andersson | 05ddce4 | 2016-06-19 23:19:45 -0700 | [diff] [blame] | 1112 | |
| 1113 | /* Map the DXE memory */ |
| 1114 | index = of_property_match_string(mmio_node, "reg-names", "dxe"); |
| 1115 | wcn->dxe_base = of_iomap(mmio_node, index); |
| 1116 | if (!wcn->dxe_base) { |
| 1117 | wcn36xx_err("failed to map dxe memory\n"); |
| 1118 | ret = -ENOMEM; |
| 1119 | goto unmap_ccu; |
| 1120 | } |
| 1121 | |
| 1122 | of_node_put(mmio_node); |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 1123 | return 0; |
Bjorn Andersson | 05ddce4 | 2016-06-19 23:19:45 -0700 | [diff] [blame] | 1124 | |
| 1125 | unmap_ccu: |
| 1126 | iounmap(wcn->ccu_base); |
| 1127 | put_mmio_node: |
| 1128 | of_node_put(mmio_node); |
| 1129 | return ret; |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 1130 | } |
| 1131 | |
| 1132 | static int wcn36xx_probe(struct platform_device *pdev) |
| 1133 | { |
| 1134 | struct ieee80211_hw *hw; |
| 1135 | struct wcn36xx *wcn; |
Bjorn Andersson | f303a93 | 2017-01-11 16:32:18 +0200 | [diff] [blame^] | 1136 | void *wcnss; |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 1137 | int ret; |
Bjorn Andersson | f303a93 | 2017-01-11 16:32:18 +0200 | [diff] [blame^] | 1138 | const u8 *addr; |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 1139 | |
| 1140 | wcn36xx_dbg(WCN36XX_DBG_MAC, "platform probe\n"); |
| 1141 | |
Bjorn Andersson | f303a93 | 2017-01-11 16:32:18 +0200 | [diff] [blame^] | 1142 | wcnss = dev_get_drvdata(pdev->dev.parent); |
| 1143 | |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 1144 | hw = ieee80211_alloc_hw(sizeof(struct wcn36xx), &wcn36xx_ops); |
| 1145 | if (!hw) { |
| 1146 | wcn36xx_err("failed to alloc hw\n"); |
| 1147 | ret = -ENOMEM; |
| 1148 | goto out_err; |
| 1149 | } |
| 1150 | platform_set_drvdata(pdev, hw); |
| 1151 | wcn = hw->priv; |
| 1152 | wcn->hw = hw; |
| 1153 | wcn->dev = &pdev->dev; |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 1154 | mutex_init(&wcn->hal_mutex); |
| 1155 | |
Bjorn Andersson | f303a93 | 2017-01-11 16:32:18 +0200 | [diff] [blame^] | 1156 | wcn->smd_channel = qcom_wcnss_open_channel(wcnss, "WLAN_CTRL", wcn36xx_smd_rsp_process); |
| 1157 | if (IS_ERR(wcn->smd_channel)) { |
| 1158 | wcn36xx_err("failed to open WLAN_CTRL channel\n"); |
| 1159 | ret = PTR_ERR(wcn->smd_channel); |
| 1160 | goto out_wq; |
| 1161 | } |
| 1162 | |
| 1163 | qcom_smd_set_drvdata(wcn->smd_channel, hw); |
| 1164 | |
| 1165 | addr = of_get_property(pdev->dev.of_node, "local-mac-address", &ret); |
| 1166 | if (addr && ret != ETH_ALEN) { |
| 1167 | wcn36xx_err("invalid local-mac-address\n"); |
| 1168 | ret = -EINVAL; |
| 1169 | goto out_wq; |
| 1170 | } else if (addr) { |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 1171 | wcn36xx_info("mac address: %pM\n", addr); |
| 1172 | SET_IEEE80211_PERM_ADDR(wcn->hw, addr); |
| 1173 | } |
| 1174 | |
| 1175 | ret = wcn36xx_platform_get_resources(wcn, pdev); |
| 1176 | if (ret) |
| 1177 | goto out_wq; |
| 1178 | |
| 1179 | wcn36xx_init_ieee80211(wcn); |
| 1180 | ret = ieee80211_register_hw(wcn->hw); |
| 1181 | if (ret) |
| 1182 | goto out_unmap; |
| 1183 | |
| 1184 | return 0; |
| 1185 | |
| 1186 | out_unmap: |
Bjorn Andersson | 05ddce4 | 2016-06-19 23:19:45 -0700 | [diff] [blame] | 1187 | iounmap(wcn->ccu_base); |
| 1188 | iounmap(wcn->dxe_base); |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 1189 | out_wq: |
| 1190 | ieee80211_free_hw(hw); |
| 1191 | out_err: |
| 1192 | return ret; |
| 1193 | } |
Bjorn Andersson | f303a93 | 2017-01-11 16:32:18 +0200 | [diff] [blame^] | 1194 | |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 1195 | static int wcn36xx_remove(struct platform_device *pdev) |
| 1196 | { |
| 1197 | struct ieee80211_hw *hw = platform_get_drvdata(pdev); |
| 1198 | struct wcn36xx *wcn = hw->priv; |
| 1199 | wcn36xx_dbg(WCN36XX_DBG_MAC, "platform remove\n"); |
| 1200 | |
Pontus Fuchs | 4bda7fa | 2014-02-12 19:04:43 +0000 | [diff] [blame] | 1201 | release_firmware(wcn->nv); |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 1202 | mutex_destroy(&wcn->hal_mutex); |
| 1203 | |
| 1204 | ieee80211_unregister_hw(hw); |
Bjorn Andersson | f303a93 | 2017-01-11 16:32:18 +0200 | [diff] [blame^] | 1205 | |
| 1206 | qcom_smem_state_put(wcn->tx_enable_state); |
| 1207 | qcom_smem_state_put(wcn->tx_rings_empty_state); |
| 1208 | |
Bjorn Andersson | 05ddce4 | 2016-06-19 23:19:45 -0700 | [diff] [blame] | 1209 | iounmap(wcn->dxe_base); |
| 1210 | iounmap(wcn->ccu_base); |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 1211 | ieee80211_free_hw(hw); |
| 1212 | |
| 1213 | return 0; |
| 1214 | } |
Bjorn Andersson | f303a93 | 2017-01-11 16:32:18 +0200 | [diff] [blame^] | 1215 | |
| 1216 | static const struct of_device_id wcn36xx_of_match[] = { |
| 1217 | { .compatible = "qcom,wcnss-wlan" }, |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 1218 | {} |
| 1219 | }; |
Bjorn Andersson | f303a93 | 2017-01-11 16:32:18 +0200 | [diff] [blame^] | 1220 | MODULE_DEVICE_TABLE(of, wcn36xx_of_match); |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 1221 | |
| 1222 | static struct platform_driver wcn36xx_driver = { |
| 1223 | .probe = wcn36xx_probe, |
| 1224 | .remove = wcn36xx_remove, |
| 1225 | .driver = { |
| 1226 | .name = "wcn36xx", |
Bjorn Andersson | f303a93 | 2017-01-11 16:32:18 +0200 | [diff] [blame^] | 1227 | .of_match_table = wcn36xx_of_match, |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 1228 | }, |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 1229 | }; |
| 1230 | |
Bjorn Andersson | f303a93 | 2017-01-11 16:32:18 +0200 | [diff] [blame^] | 1231 | module_platform_driver(wcn36xx_driver); |
Eugene Krasnikov | 8e84c25 | 2013-10-08 21:25:58 +0100 | [diff] [blame] | 1232 | |
| 1233 | MODULE_LICENSE("Dual BSD/GPL"); |
| 1234 | MODULE_AUTHOR("Eugene Krasnikov k.eugene.e@gmail.com"); |
| 1235 | MODULE_FIRMWARE(WLAN_NV_FILE); |