Christian Lamparter | 0ac0d6c | 2009-06-23 10:38:49 -0500 | [diff] [blame] | 1 | /* |
| 2 | * mac80211 glue code for mac80211 Prism54 drivers |
| 3 | * |
| 4 | * Copyright (c) 2006, Michael Wu <flamingice@sourmilk.net> |
| 5 | * Copyright (c) 2007-2009, Christian Lamparter <chunkeey@web.de> |
| 6 | * Copyright 2008, Johannes Berg <johannes@sipsolutions.net> |
| 7 | * |
| 8 | * Based on: |
| 9 | * - the islsm (softmac prism54) driver, which is: |
| 10 | * Copyright 2004-2006 Jean-Baptiste Note <jbnote@gmail.com>, et al. |
| 11 | * - stlc45xx driver |
| 12 | * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). |
| 13 | * |
| 14 | * This program is free software; you can redistribute it and/or modify |
| 15 | * it under the terms of the GNU General Public License version 2 as |
| 16 | * published by the Free Software Foundation. |
| 17 | */ |
| 18 | |
| 19 | #include <linux/init.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 20 | #include <linux/slab.h> |
Christian Lamparter | 0ac0d6c | 2009-06-23 10:38:49 -0500 | [diff] [blame] | 21 | #include <linux/firmware.h> |
| 22 | #include <linux/etherdevice.h> |
| 23 | |
| 24 | #include <net/mac80211.h> |
| 25 | |
| 26 | #include "p54.h" |
| 27 | #include "lmac.h" |
| 28 | |
| 29 | static int modparam_nohwcrypt; |
| 30 | module_param_named(nohwcrypt, modparam_nohwcrypt, bool, S_IRUGO); |
| 31 | MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption."); |
| 32 | MODULE_AUTHOR("Michael Wu <flamingice@sourmilk.net>"); |
| 33 | MODULE_DESCRIPTION("Softmac Prism54 common code"); |
| 34 | MODULE_LICENSE("GPL"); |
| 35 | MODULE_ALIAS("prism54common"); |
| 36 | |
Johannes Berg | 17f6f05 | 2010-02-19 19:06:54 +0100 | [diff] [blame] | 37 | static int p54_sta_add_remove(struct ieee80211_hw *hw, |
| 38 | struct ieee80211_vif *vif, |
| 39 | struct ieee80211_sta *sta) |
| 40 | { |
| 41 | struct p54_common *priv = hw->priv; |
| 42 | |
| 43 | /* |
| 44 | * Notify the firmware that we don't want or we don't |
| 45 | * need to buffer frames for this station anymore. |
| 46 | */ |
| 47 | |
| 48 | p54_sta_unlock(priv, sta->addr); |
| 49 | |
| 50 | return 0; |
| 51 | } |
| 52 | |
Christian Lamparter | 0ac0d6c | 2009-06-23 10:38:49 -0500 | [diff] [blame] | 53 | static void p54_sta_notify(struct ieee80211_hw *dev, struct ieee80211_vif *vif, |
| 54 | enum sta_notify_cmd notify_cmd, |
| 55 | struct ieee80211_sta *sta) |
| 56 | { |
| 57 | struct p54_common *priv = dev->priv; |
Christian Lamparter | 0ac0d6c | 2009-06-23 10:38:49 -0500 | [diff] [blame] | 58 | |
Johannes Berg | 17f6f05 | 2010-02-19 19:06:54 +0100 | [diff] [blame] | 59 | switch (notify_cmd) { |
Christian Lamparter | 0ac0d6c | 2009-06-23 10:38:49 -0500 | [diff] [blame] | 60 | case STA_NOTIFY_AWAKE: |
| 61 | /* update the firmware's filter table */ |
| 62 | p54_sta_unlock(priv, sta->addr); |
| 63 | break; |
| 64 | default: |
| 65 | break; |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | static int p54_set_tim(struct ieee80211_hw *dev, struct ieee80211_sta *sta, |
| 70 | bool set) |
| 71 | { |
| 72 | struct p54_common *priv = dev->priv; |
| 73 | |
| 74 | return p54_update_beacon_tim(priv, sta->aid, set); |
| 75 | } |
| 76 | |
Christian Lamparter | e0f114e | 2009-07-07 19:08:07 +0200 | [diff] [blame] | 77 | u8 *p54_find_ie(struct sk_buff *skb, u8 ie) |
| 78 | { |
| 79 | struct ieee80211_mgmt *mgmt = (void *)skb->data; |
| 80 | u8 *pos, *end; |
| 81 | |
| 82 | if (skb->len <= sizeof(mgmt)) |
| 83 | return NULL; |
| 84 | |
| 85 | pos = (u8 *)mgmt->u.beacon.variable; |
| 86 | end = skb->data + skb->len; |
| 87 | while (pos < end) { |
| 88 | if (pos + 2 + pos[1] > end) |
| 89 | return NULL; |
| 90 | |
| 91 | if (pos[0] == ie) |
| 92 | return pos; |
| 93 | |
| 94 | pos += 2 + pos[1]; |
| 95 | } |
| 96 | return NULL; |
| 97 | } |
| 98 | |
Christian Lamparter | 0ac0d6c | 2009-06-23 10:38:49 -0500 | [diff] [blame] | 99 | static int p54_beacon_format_ie_tim(struct sk_buff *skb) |
| 100 | { |
| 101 | /* |
| 102 | * the good excuse for this mess is ... the firmware. |
| 103 | * The dummy TIM MUST be at the end of the beacon frame, |
| 104 | * because it'll be overwritten! |
| 105 | */ |
Christian Lamparter | e0f114e | 2009-07-07 19:08:07 +0200 | [diff] [blame] | 106 | u8 *tim; |
| 107 | u8 dtim_len; |
| 108 | u8 dtim_period; |
| 109 | u8 *next; |
Christian Lamparter | 0ac0d6c | 2009-06-23 10:38:49 -0500 | [diff] [blame] | 110 | |
Christian Lamparter | e0f114e | 2009-07-07 19:08:07 +0200 | [diff] [blame] | 111 | tim = p54_find_ie(skb, WLAN_EID_TIM); |
| 112 | if (!tim) |
| 113 | return 0; |
Christian Lamparter | 0ac0d6c | 2009-06-23 10:38:49 -0500 | [diff] [blame] | 114 | |
Christian Lamparter | e0f114e | 2009-07-07 19:08:07 +0200 | [diff] [blame] | 115 | dtim_len = tim[1]; |
| 116 | dtim_period = tim[3]; |
| 117 | next = tim + 2 + dtim_len; |
| 118 | |
| 119 | if (dtim_len < 3) |
Christian Lamparter | 0ac0d6c | 2009-06-23 10:38:49 -0500 | [diff] [blame] | 120 | return -EINVAL; |
| 121 | |
Christian Lamparter | e0f114e | 2009-07-07 19:08:07 +0200 | [diff] [blame] | 122 | memmove(tim, next, skb_tail_pointer(skb) - next); |
| 123 | tim = skb_tail_pointer(skb) - (dtim_len + 2); |
Christian Lamparter | 0ac0d6c | 2009-06-23 10:38:49 -0500 | [diff] [blame] | 124 | |
Christian Lamparter | e0f114e | 2009-07-07 19:08:07 +0200 | [diff] [blame] | 125 | /* add the dummy at the end */ |
| 126 | tim[0] = WLAN_EID_TIM; |
| 127 | tim[1] = 3; |
| 128 | tim[2] = 0; |
| 129 | tim[3] = dtim_period; |
| 130 | tim[4] = 0; |
Christian Lamparter | 0ac0d6c | 2009-06-23 10:38:49 -0500 | [diff] [blame] | 131 | |
Christian Lamparter | e0f114e | 2009-07-07 19:08:07 +0200 | [diff] [blame] | 132 | if (dtim_len > 3) |
| 133 | skb_trim(skb, skb->len - (dtim_len - 3)); |
Christian Lamparter | 0ac0d6c | 2009-06-23 10:38:49 -0500 | [diff] [blame] | 134 | |
Christian Lamparter | 0ac0d6c | 2009-06-23 10:38:49 -0500 | [diff] [blame] | 135 | return 0; |
| 136 | } |
| 137 | |
| 138 | static int p54_beacon_update(struct p54_common *priv, |
| 139 | struct ieee80211_vif *vif) |
| 140 | { |
| 141 | struct sk_buff *beacon; |
Christian Lamparter | 0ac0d6c | 2009-06-23 10:38:49 -0500 | [diff] [blame] | 142 | int ret; |
| 143 | |
| 144 | beacon = ieee80211_beacon_get(priv->hw, vif); |
| 145 | if (!beacon) |
| 146 | return -ENOMEM; |
| 147 | ret = p54_beacon_format_ie_tim(beacon); |
| 148 | if (ret) |
| 149 | return ret; |
| 150 | |
Christian Lamparter | 46df10a | 2009-07-16 20:03:47 +0200 | [diff] [blame] | 151 | /* |
| 152 | * During operation, the firmware takes care of beaconing. |
| 153 | * The driver only needs to upload a new beacon template, once |
| 154 | * the template was changed by the stack or userspace. |
| 155 | * |
| 156 | * LMAC API 3.2.2 also specifies that the driver does not need |
| 157 | * to cancel the old beacon template by hand, instead the firmware |
| 158 | * will release the previous one through the feedback mechanism. |
| 159 | */ |
| 160 | WARN_ON(p54_tx_80211(priv->hw, beacon)); |
Christian Lamparter | 0ac0d6c | 2009-06-23 10:38:49 -0500 | [diff] [blame] | 161 | priv->tsf_high32 = 0; |
| 162 | priv->tsf_low32 = 0; |
| 163 | |
| 164 | return 0; |
| 165 | } |
| 166 | |
| 167 | static int p54_start(struct ieee80211_hw *dev) |
| 168 | { |
| 169 | struct p54_common *priv = dev->priv; |
| 170 | int err; |
| 171 | |
| 172 | mutex_lock(&priv->conf_mutex); |
| 173 | err = priv->open(dev); |
| 174 | if (err) |
| 175 | goto out; |
| 176 | P54_SET_QUEUE(priv->qos_params[0], 0x0002, 0x0003, 0x0007, 47); |
| 177 | P54_SET_QUEUE(priv->qos_params[1], 0x0002, 0x0007, 0x000f, 94); |
| 178 | P54_SET_QUEUE(priv->qos_params[2], 0x0003, 0x000f, 0x03ff, 0); |
| 179 | P54_SET_QUEUE(priv->qos_params[3], 0x0007, 0x000f, 0x03ff, 0); |
| 180 | err = p54_set_edcf(priv); |
| 181 | if (err) |
| 182 | goto out; |
| 183 | |
| 184 | memset(priv->bssid, ~0, ETH_ALEN); |
| 185 | priv->mode = NL80211_IFTYPE_MONITOR; |
| 186 | err = p54_setup_mac(priv); |
| 187 | if (err) { |
| 188 | priv->mode = NL80211_IFTYPE_UNSPECIFIED; |
| 189 | goto out; |
| 190 | } |
| 191 | |
Luis R. Rodriguez | 42935ec | 2009-07-29 20:08:07 -0400 | [diff] [blame] | 192 | ieee80211_queue_delayed_work(dev, &priv->work, 0); |
Christian Lamparter | 0ac0d6c | 2009-06-23 10:38:49 -0500 | [diff] [blame] | 193 | |
| 194 | priv->softled_state = 0; |
| 195 | err = p54_set_leds(priv); |
| 196 | |
| 197 | out: |
| 198 | mutex_unlock(&priv->conf_mutex); |
| 199 | return err; |
| 200 | } |
| 201 | |
| 202 | static void p54_stop(struct ieee80211_hw *dev) |
| 203 | { |
| 204 | struct p54_common *priv = dev->priv; |
| 205 | int i; |
| 206 | |
| 207 | mutex_lock(&priv->conf_mutex); |
| 208 | priv->mode = NL80211_IFTYPE_UNSPECIFIED; |
| 209 | priv->softled_state = 0; |
| 210 | p54_set_leds(priv); |
| 211 | |
| 212 | cancel_delayed_work_sync(&priv->work); |
| 213 | |
| 214 | priv->stop(dev); |
| 215 | skb_queue_purge(&priv->tx_pending); |
| 216 | skb_queue_purge(&priv->tx_queue); |
| 217 | for (i = 0; i < P54_QUEUE_NUM; i++) { |
| 218 | priv->tx_stats[i].count = 0; |
| 219 | priv->tx_stats[i].len = 0; |
| 220 | } |
| 221 | |
| 222 | priv->beacon_req_id = cpu_to_le32(0); |
| 223 | priv->tsf_high32 = priv->tsf_low32 = 0; |
| 224 | mutex_unlock(&priv->conf_mutex); |
| 225 | } |
| 226 | |
| 227 | static int p54_add_interface(struct ieee80211_hw *dev, |
Johannes Berg | 1ed32e4 | 2009-12-23 13:15:45 +0100 | [diff] [blame] | 228 | struct ieee80211_vif *vif) |
Christian Lamparter | 0ac0d6c | 2009-06-23 10:38:49 -0500 | [diff] [blame] | 229 | { |
| 230 | struct p54_common *priv = dev->priv; |
| 231 | |
| 232 | mutex_lock(&priv->conf_mutex); |
| 233 | if (priv->mode != NL80211_IFTYPE_MONITOR) { |
| 234 | mutex_unlock(&priv->conf_mutex); |
| 235 | return -EOPNOTSUPP; |
| 236 | } |
| 237 | |
Johannes Berg | 1ed32e4 | 2009-12-23 13:15:45 +0100 | [diff] [blame] | 238 | priv->vif = vif; |
Christian Lamparter | 0ac0d6c | 2009-06-23 10:38:49 -0500 | [diff] [blame] | 239 | |
Johannes Berg | 1ed32e4 | 2009-12-23 13:15:45 +0100 | [diff] [blame] | 240 | switch (vif->type) { |
Christian Lamparter | 0ac0d6c | 2009-06-23 10:38:49 -0500 | [diff] [blame] | 241 | case NL80211_IFTYPE_STATION: |
| 242 | case NL80211_IFTYPE_ADHOC: |
| 243 | case NL80211_IFTYPE_AP: |
| 244 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 1ed32e4 | 2009-12-23 13:15:45 +0100 | [diff] [blame] | 245 | priv->mode = vif->type; |
Christian Lamparter | 0ac0d6c | 2009-06-23 10:38:49 -0500 | [diff] [blame] | 246 | break; |
| 247 | default: |
| 248 | mutex_unlock(&priv->conf_mutex); |
| 249 | return -EOPNOTSUPP; |
| 250 | } |
| 251 | |
Johannes Berg | 1ed32e4 | 2009-12-23 13:15:45 +0100 | [diff] [blame] | 252 | memcpy(priv->mac_addr, vif->addr, ETH_ALEN); |
Christian Lamparter | 0ac0d6c | 2009-06-23 10:38:49 -0500 | [diff] [blame] | 253 | p54_setup_mac(priv); |
| 254 | mutex_unlock(&priv->conf_mutex); |
| 255 | return 0; |
| 256 | } |
| 257 | |
| 258 | static void p54_remove_interface(struct ieee80211_hw *dev, |
Johannes Berg | 1ed32e4 | 2009-12-23 13:15:45 +0100 | [diff] [blame] | 259 | struct ieee80211_vif *vif) |
Christian Lamparter | 0ac0d6c | 2009-06-23 10:38:49 -0500 | [diff] [blame] | 260 | { |
| 261 | struct p54_common *priv = dev->priv; |
| 262 | |
| 263 | mutex_lock(&priv->conf_mutex); |
| 264 | priv->vif = NULL; |
Christian Lamparter | 46df10a | 2009-07-16 20:03:47 +0200 | [diff] [blame] | 265 | |
| 266 | /* |
| 267 | * LMAC API 3.2.2 states that any active beacon template must be |
| 268 | * canceled by the driver before attempting a mode transition. |
| 269 | */ |
| 270 | if (le32_to_cpu(priv->beacon_req_id) != 0) { |
Christian Lamparter | 0ac0d6c | 2009-06-23 10:38:49 -0500 | [diff] [blame] | 271 | p54_tx_cancel(priv, priv->beacon_req_id); |
Christian Lamparter | 46df10a | 2009-07-16 20:03:47 +0200 | [diff] [blame] | 272 | wait_for_completion_interruptible_timeout(&priv->beacon_comp, HZ); |
Christian Lamparter | 0ac0d6c | 2009-06-23 10:38:49 -0500 | [diff] [blame] | 273 | } |
| 274 | priv->mode = NL80211_IFTYPE_MONITOR; |
| 275 | memset(priv->mac_addr, 0, ETH_ALEN); |
| 276 | memset(priv->bssid, 0, ETH_ALEN); |
| 277 | p54_setup_mac(priv); |
| 278 | mutex_unlock(&priv->conf_mutex); |
| 279 | } |
| 280 | |
| 281 | static int p54_config(struct ieee80211_hw *dev, u32 changed) |
| 282 | { |
| 283 | int ret = 0; |
| 284 | struct p54_common *priv = dev->priv; |
| 285 | struct ieee80211_conf *conf = &dev->conf; |
| 286 | |
| 287 | mutex_lock(&priv->conf_mutex); |
| 288 | if (changed & IEEE80211_CONF_CHANGE_POWER) |
| 289 | priv->output_power = conf->power_level << 2; |
| 290 | if (changed & IEEE80211_CONF_CHANGE_CHANNEL) { |
| 291 | ret = p54_scan(priv, P54_SCAN_EXIT, 0); |
| 292 | if (ret) |
| 293 | goto out; |
| 294 | } |
| 295 | if (changed & IEEE80211_CONF_CHANGE_PS) { |
| 296 | ret = p54_set_ps(priv); |
| 297 | if (ret) |
| 298 | goto out; |
| 299 | } |
Christian Lamparter | 6208f8b | 2009-08-07 19:39:05 +0200 | [diff] [blame] | 300 | if (changed & IEEE80211_CONF_CHANGE_IDLE) { |
| 301 | ret = p54_setup_mac(priv); |
| 302 | if (ret) |
| 303 | goto out; |
| 304 | } |
Christian Lamparter | 0ac0d6c | 2009-06-23 10:38:49 -0500 | [diff] [blame] | 305 | |
| 306 | out: |
| 307 | mutex_unlock(&priv->conf_mutex); |
| 308 | return ret; |
| 309 | } |
| 310 | |
| 311 | static void p54_configure_filter(struct ieee80211_hw *dev, |
| 312 | unsigned int changed_flags, |
| 313 | unsigned int *total_flags, |
Johannes Berg | 3ac64be | 2009-08-17 16:16:53 +0200 | [diff] [blame] | 314 | u64 multicast) |
Christian Lamparter | 0ac0d6c | 2009-06-23 10:38:49 -0500 | [diff] [blame] | 315 | { |
| 316 | struct p54_common *priv = dev->priv; |
| 317 | |
| 318 | *total_flags &= FIF_PROMISC_IN_BSS | |
| 319 | FIF_OTHER_BSS; |
| 320 | |
| 321 | priv->filter_flags = *total_flags; |
| 322 | |
| 323 | if (changed_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS)) |
| 324 | p54_setup_mac(priv); |
| 325 | } |
| 326 | |
| 327 | static int p54_conf_tx(struct ieee80211_hw *dev, u16 queue, |
| 328 | const struct ieee80211_tx_queue_params *params) |
| 329 | { |
| 330 | struct p54_common *priv = dev->priv; |
| 331 | int ret; |
| 332 | |
| 333 | mutex_lock(&priv->conf_mutex); |
Christian Lamparter | 718126a | 2009-08-07 19:38:51 +0200 | [diff] [blame] | 334 | if (queue < dev->queues) { |
Christian Lamparter | 0ac0d6c | 2009-06-23 10:38:49 -0500 | [diff] [blame] | 335 | P54_SET_QUEUE(priv->qos_params[queue], params->aifs, |
| 336 | params->cw_min, params->cw_max, params->txop); |
| 337 | ret = p54_set_edcf(priv); |
| 338 | } else |
| 339 | ret = -EINVAL; |
| 340 | mutex_unlock(&priv->conf_mutex); |
| 341 | return ret; |
| 342 | } |
| 343 | |
| 344 | static void p54_work(struct work_struct *work) |
| 345 | { |
| 346 | struct p54_common *priv = container_of(work, struct p54_common, |
| 347 | work.work); |
| 348 | |
| 349 | if (unlikely(priv->mode == NL80211_IFTYPE_UNSPECIFIED)) |
| 350 | return ; |
| 351 | |
| 352 | /* |
| 353 | * TODO: walk through tx_queue and do the following tasks |
| 354 | * 1. initiate bursts. |
| 355 | * 2. cancel stuck frames / reset the device if necessary. |
| 356 | */ |
| 357 | |
| 358 | p54_fetch_statistics(priv); |
| 359 | } |
| 360 | |
| 361 | static int p54_get_stats(struct ieee80211_hw *dev, |
| 362 | struct ieee80211_low_level_stats *stats) |
| 363 | { |
| 364 | struct p54_common *priv = dev->priv; |
| 365 | |
| 366 | memcpy(stats, &priv->stats, sizeof(*stats)); |
| 367 | return 0; |
| 368 | } |
| 369 | |
Christian Lamparter | 0ac0d6c | 2009-06-23 10:38:49 -0500 | [diff] [blame] | 370 | static void p54_bss_info_changed(struct ieee80211_hw *dev, |
| 371 | struct ieee80211_vif *vif, |
| 372 | struct ieee80211_bss_conf *info, |
| 373 | u32 changed) |
| 374 | { |
| 375 | struct p54_common *priv = dev->priv; |
| 376 | |
| 377 | mutex_lock(&priv->conf_mutex); |
| 378 | if (changed & BSS_CHANGED_BSSID) { |
| 379 | memcpy(priv->bssid, info->bssid, ETH_ALEN); |
| 380 | p54_setup_mac(priv); |
| 381 | } |
| 382 | |
| 383 | if (changed & BSS_CHANGED_BEACON) { |
| 384 | p54_scan(priv, P54_SCAN_EXIT, 0); |
| 385 | p54_setup_mac(priv); |
| 386 | p54_beacon_update(priv, vif); |
| 387 | p54_set_edcf(priv); |
| 388 | } |
| 389 | |
| 390 | if (changed & (BSS_CHANGED_ERP_SLOT | BSS_CHANGED_BEACON)) { |
| 391 | priv->use_short_slot = info->use_short_slot; |
| 392 | p54_set_edcf(priv); |
| 393 | } |
| 394 | if (changed & BSS_CHANGED_BASIC_RATES) { |
| 395 | if (dev->conf.channel->band == IEEE80211_BAND_5GHZ) |
| 396 | priv->basic_rate_mask = (info->basic_rates << 4); |
| 397 | else |
| 398 | priv->basic_rate_mask = info->basic_rates; |
| 399 | p54_setup_mac(priv); |
| 400 | if (priv->fw_var >= 0x500) |
| 401 | p54_scan(priv, P54_SCAN_EXIT, 0); |
| 402 | } |
| 403 | if (changed & BSS_CHANGED_ASSOC) { |
| 404 | if (info->assoc) { |
| 405 | priv->aid = info->aid; |
| 406 | priv->wakeup_timer = info->beacon_int * |
| 407 | info->dtim_period * 5; |
| 408 | p54_setup_mac(priv); |
Christian Lamparter | e0f114e | 2009-07-07 19:08:07 +0200 | [diff] [blame] | 409 | } else { |
| 410 | priv->wakeup_timer = 500; |
| 411 | priv->aid = 0; |
Christian Lamparter | 0ac0d6c | 2009-06-23 10:38:49 -0500 | [diff] [blame] | 412 | } |
| 413 | } |
| 414 | |
| 415 | mutex_unlock(&priv->conf_mutex); |
| 416 | } |
| 417 | |
| 418 | static int p54_set_key(struct ieee80211_hw *dev, enum set_key_cmd cmd, |
| 419 | struct ieee80211_vif *vif, struct ieee80211_sta *sta, |
| 420 | struct ieee80211_key_conf *key) |
| 421 | { |
| 422 | struct p54_common *priv = dev->priv; |
| 423 | int slot, ret = 0; |
| 424 | u8 algo = 0; |
| 425 | u8 *addr = NULL; |
| 426 | |
| 427 | if (modparam_nohwcrypt) |
| 428 | return -EOPNOTSUPP; |
| 429 | |
| 430 | mutex_lock(&priv->conf_mutex); |
| 431 | if (cmd == SET_KEY) { |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 432 | switch (key->cipher) { |
| 433 | case WLAN_CIPHER_SUITE_TKIP: |
Christian Lamparter | 0ac0d6c | 2009-06-23 10:38:49 -0500 | [diff] [blame] | 434 | if (!(priv->privacy_caps & (BR_DESC_PRIV_CAP_MICHAEL | |
| 435 | BR_DESC_PRIV_CAP_TKIP))) { |
| 436 | ret = -EOPNOTSUPP; |
| 437 | goto out_unlock; |
| 438 | } |
| 439 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
| 440 | algo = P54_CRYPTO_TKIPMICHAEL; |
| 441 | break; |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 442 | case WLAN_CIPHER_SUITE_WEP40: |
| 443 | case WLAN_CIPHER_SUITE_WEP104: |
Christian Lamparter | 0ac0d6c | 2009-06-23 10:38:49 -0500 | [diff] [blame] | 444 | if (!(priv->privacy_caps & BR_DESC_PRIV_CAP_WEP)) { |
| 445 | ret = -EOPNOTSUPP; |
| 446 | goto out_unlock; |
| 447 | } |
| 448 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
| 449 | algo = P54_CRYPTO_WEP; |
| 450 | break; |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 451 | case WLAN_CIPHER_SUITE_CCMP: |
Christian Lamparter | 0ac0d6c | 2009-06-23 10:38:49 -0500 | [diff] [blame] | 452 | if (!(priv->privacy_caps & BR_DESC_PRIV_CAP_AESCCMP)) { |
| 453 | ret = -EOPNOTSUPP; |
| 454 | goto out_unlock; |
| 455 | } |
| 456 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
| 457 | algo = P54_CRYPTO_AESCCMP; |
| 458 | break; |
| 459 | default: |
| 460 | ret = -EOPNOTSUPP; |
| 461 | goto out_unlock; |
| 462 | } |
| 463 | slot = bitmap_find_free_region(priv->used_rxkeys, |
| 464 | priv->rx_keycache_size, 0); |
| 465 | |
| 466 | if (slot < 0) { |
| 467 | /* |
| 468 | * The device supports the choosen algorithm, but the |
| 469 | * firmware does not provide enough key slots to store |
| 470 | * all of them. |
| 471 | * But encryption offload for outgoing frames is always |
| 472 | * possible, so we just pretend that the upload was |
| 473 | * successful and do the decryption in software. |
| 474 | */ |
| 475 | |
| 476 | /* mark the key as invalid. */ |
| 477 | key->hw_key_idx = 0xff; |
| 478 | goto out_unlock; |
| 479 | } |
| 480 | } else { |
| 481 | slot = key->hw_key_idx; |
| 482 | |
| 483 | if (slot == 0xff) { |
| 484 | /* This key was not uploaded into the rx key cache. */ |
| 485 | |
| 486 | goto out_unlock; |
| 487 | } |
| 488 | |
| 489 | bitmap_release_region(priv->used_rxkeys, slot, 0); |
| 490 | algo = 0; |
| 491 | } |
| 492 | |
| 493 | if (sta) |
| 494 | addr = sta->addr; |
| 495 | |
| 496 | ret = p54_upload_key(priv, algo, slot, key->keyidx, |
| 497 | key->keylen, addr, key->key); |
| 498 | if (ret) { |
| 499 | bitmap_release_region(priv->used_rxkeys, slot, 0); |
| 500 | ret = -EOPNOTSUPP; |
| 501 | goto out_unlock; |
| 502 | } |
| 503 | |
| 504 | key->hw_key_idx = slot; |
| 505 | |
| 506 | out_unlock: |
| 507 | mutex_unlock(&priv->conf_mutex); |
| 508 | return ret; |
| 509 | } |
| 510 | |
John W. Linville | 1b2fb7d | 2010-05-03 16:06:47 -0400 | [diff] [blame] | 511 | static int p54_get_survey(struct ieee80211_hw *dev, int idx, |
| 512 | struct survey_info *survey) |
| 513 | { |
| 514 | struct p54_common *priv = dev->priv; |
| 515 | struct ieee80211_conf *conf = &dev->conf; |
| 516 | |
| 517 | if (idx != 0) |
| 518 | return -ENOENT; |
| 519 | |
| 520 | survey->channel = conf->channel; |
| 521 | survey->filled = SURVEY_INFO_NOISE_DBM; |
| 522 | survey->noise = clamp_t(s8, priv->noise, -128, 127); |
| 523 | |
| 524 | return 0; |
| 525 | } |
| 526 | |
Christian Lamparter | 0d4171e | 2011-02-16 19:43:06 +0100 | [diff] [blame^] | 527 | static unsigned int p54_flush_count(struct p54_common *priv) |
| 528 | { |
| 529 | unsigned int total = 0, i; |
| 530 | |
| 531 | BUILD_BUG_ON(P54_QUEUE_NUM > ARRAY_SIZE(priv->tx_stats)); |
| 532 | |
| 533 | /* |
| 534 | * Because the firmware has the sole control over any frames |
| 535 | * in the P54_QUEUE_BEACON or P54_QUEUE_SCAN queues, they |
| 536 | * don't really count as pending or active. |
| 537 | */ |
| 538 | for (i = P54_QUEUE_MGMT; i < P54_QUEUE_NUM; i++) |
| 539 | total += priv->tx_stats[i].len; |
| 540 | return total; |
| 541 | } |
| 542 | |
| 543 | static void p54_flush(struct ieee80211_hw *dev, bool drop) |
| 544 | { |
| 545 | struct p54_common *priv = dev->priv; |
| 546 | unsigned int total, i; |
| 547 | |
| 548 | /* |
| 549 | * Currently, it wouldn't really matter if we wait for one second |
| 550 | * or 15 minutes. But once someone gets around and completes the |
| 551 | * TODOs [ancel stuck frames / reset device] in p54_work, it will |
| 552 | * suddenly make sense to wait that long. |
| 553 | */ |
| 554 | i = P54_STATISTICS_UPDATE * 2 / 20; |
| 555 | |
| 556 | /* |
| 557 | * In this case no locking is required because as we speak the |
| 558 | * queues have already been stopped and no new frames can sneak |
| 559 | * up from behind. |
| 560 | */ |
| 561 | while ((total = p54_flush_count(priv) && i--)) { |
| 562 | /* waste time */ |
| 563 | msleep(20); |
| 564 | } |
| 565 | |
| 566 | WARN(total, "tx flush timeout, unresponsive firmware"); |
| 567 | } |
| 568 | |
Christian Lamparter | 0ac0d6c | 2009-06-23 10:38:49 -0500 | [diff] [blame] | 569 | static const struct ieee80211_ops p54_ops = { |
| 570 | .tx = p54_tx_80211, |
| 571 | .start = p54_start, |
| 572 | .stop = p54_stop, |
| 573 | .add_interface = p54_add_interface, |
| 574 | .remove_interface = p54_remove_interface, |
| 575 | .set_tim = p54_set_tim, |
| 576 | .sta_notify = p54_sta_notify, |
Johannes Berg | 17f6f05 | 2010-02-19 19:06:54 +0100 | [diff] [blame] | 577 | .sta_add = p54_sta_add_remove, |
| 578 | .sta_remove = p54_sta_add_remove, |
Christian Lamparter | 0ac0d6c | 2009-06-23 10:38:49 -0500 | [diff] [blame] | 579 | .set_key = p54_set_key, |
| 580 | .config = p54_config, |
Christian Lamparter | 0d4171e | 2011-02-16 19:43:06 +0100 | [diff] [blame^] | 581 | .flush = p54_flush, |
Christian Lamparter | 0ac0d6c | 2009-06-23 10:38:49 -0500 | [diff] [blame] | 582 | .bss_info_changed = p54_bss_info_changed, |
| 583 | .configure_filter = p54_configure_filter, |
| 584 | .conf_tx = p54_conf_tx, |
| 585 | .get_stats = p54_get_stats, |
John W. Linville | 1b2fb7d | 2010-05-03 16:06:47 -0400 | [diff] [blame] | 586 | .get_survey = p54_get_survey, |
Christian Lamparter | 0ac0d6c | 2009-06-23 10:38:49 -0500 | [diff] [blame] | 587 | }; |
| 588 | |
| 589 | struct ieee80211_hw *p54_init_common(size_t priv_data_len) |
| 590 | { |
| 591 | struct ieee80211_hw *dev; |
| 592 | struct p54_common *priv; |
| 593 | |
| 594 | dev = ieee80211_alloc_hw(priv_data_len, &p54_ops); |
| 595 | if (!dev) |
| 596 | return NULL; |
| 597 | |
| 598 | priv = dev->priv; |
| 599 | priv->hw = dev; |
| 600 | priv->mode = NL80211_IFTYPE_UNSPECIFIED; |
| 601 | priv->basic_rate_mask = 0x15f; |
| 602 | spin_lock_init(&priv->tx_stats_lock); |
| 603 | skb_queue_head_init(&priv->tx_queue); |
| 604 | skb_queue_head_init(&priv->tx_pending); |
| 605 | dev->flags = IEEE80211_HW_RX_INCLUDES_FCS | |
| 606 | IEEE80211_HW_SIGNAL_DBM | |
Christian Lamparter | e0f114e | 2009-07-07 19:08:07 +0200 | [diff] [blame] | 607 | IEEE80211_HW_SUPPORTS_PS | |
| 608 | IEEE80211_HW_PS_NULLFUNC_STACK | |
| 609 | IEEE80211_HW_BEACON_FILTER | |
John W. Linville | f5c044e | 2010-04-30 15:37:00 -0400 | [diff] [blame] | 610 | IEEE80211_HW_REPORTS_TX_ACK_STATUS; |
Christian Lamparter | 0ac0d6c | 2009-06-23 10:38:49 -0500 | [diff] [blame] | 611 | |
| 612 | dev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | |
| 613 | BIT(NL80211_IFTYPE_ADHOC) | |
| 614 | BIT(NL80211_IFTYPE_AP) | |
| 615 | BIT(NL80211_IFTYPE_MESH_POINT); |
| 616 | |
| 617 | dev->channel_change_time = 1000; /* TODO: find actual value */ |
Christian Lamparter | 46df10a | 2009-07-16 20:03:47 +0200 | [diff] [blame] | 618 | priv->beacon_req_id = cpu_to_le32(0); |
Christian Lamparter | 0ac0d6c | 2009-06-23 10:38:49 -0500 | [diff] [blame] | 619 | priv->tx_stats[P54_QUEUE_BEACON].limit = 1; |
| 620 | priv->tx_stats[P54_QUEUE_FWSCAN].limit = 1; |
| 621 | priv->tx_stats[P54_QUEUE_MGMT].limit = 3; |
| 622 | priv->tx_stats[P54_QUEUE_CAB].limit = 3; |
| 623 | priv->tx_stats[P54_QUEUE_DATA].limit = 5; |
| 624 | dev->queues = 1; |
| 625 | priv->noise = -94; |
| 626 | /* |
| 627 | * We support at most 8 tries no matter which rate they're at, |
| 628 | * we cannot support max_rates * max_rate_tries as we set it |
| 629 | * here, but setting it correctly to 4/2 or so would limit us |
| 630 | * artificially if the RC algorithm wants just two rates, so |
| 631 | * let's say 4/7, we'll redistribute it at TX time, see the |
| 632 | * comments there. |
| 633 | */ |
| 634 | dev->max_rates = 4; |
| 635 | dev->max_rate_tries = 7; |
| 636 | dev->extra_tx_headroom = sizeof(struct p54_hdr) + 4 + |
| 637 | sizeof(struct p54_tx_data); |
| 638 | |
Christian Lamparter | c46aaba | 2009-08-14 13:23:05 +0200 | [diff] [blame] | 639 | /* |
| 640 | * For now, disable PS by default because it affects |
| 641 | * link stability significantly. |
| 642 | */ |
Johannes Berg | 5be83de | 2009-11-19 00:56:28 +0100 | [diff] [blame] | 643 | dev->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT; |
Christian Lamparter | c46aaba | 2009-08-14 13:23:05 +0200 | [diff] [blame] | 644 | |
Christian Lamparter | 0ac0d6c | 2009-06-23 10:38:49 -0500 | [diff] [blame] | 645 | mutex_init(&priv->conf_mutex); |
| 646 | mutex_init(&priv->eeprom_mutex); |
| 647 | init_completion(&priv->eeprom_comp); |
Christian Lamparter | 46df10a | 2009-07-16 20:03:47 +0200 | [diff] [blame] | 648 | init_completion(&priv->beacon_comp); |
Christian Lamparter | 0ac0d6c | 2009-06-23 10:38:49 -0500 | [diff] [blame] | 649 | INIT_DELAYED_WORK(&priv->work, p54_work); |
| 650 | |
| 651 | return dev; |
| 652 | } |
| 653 | EXPORT_SYMBOL_GPL(p54_init_common); |
| 654 | |
| 655 | int p54_register_common(struct ieee80211_hw *dev, struct device *pdev) |
| 656 | { |
Larry Finger | fe0b7c6 | 2011-02-15 09:37:06 -0600 | [diff] [blame] | 657 | struct p54_common __maybe_unused *priv = dev->priv; |
Christian Lamparter | 0ac0d6c | 2009-06-23 10:38:49 -0500 | [diff] [blame] | 658 | int err; |
| 659 | |
| 660 | err = ieee80211_register_hw(dev); |
| 661 | if (err) { |
| 662 | dev_err(pdev, "Cannot register device (%d).\n", err); |
| 663 | return err; |
| 664 | } |
| 665 | |
| 666 | #ifdef CONFIG_P54_LEDS |
| 667 | err = p54_init_leds(priv); |
| 668 | if (err) |
| 669 | return err; |
| 670 | #endif /* CONFIG_P54_LEDS */ |
| 671 | |
| 672 | dev_info(pdev, "is registered as '%s'\n", wiphy_name(dev->wiphy)); |
| 673 | return 0; |
| 674 | } |
| 675 | EXPORT_SYMBOL_GPL(p54_register_common); |
| 676 | |
| 677 | void p54_free_common(struct ieee80211_hw *dev) |
| 678 | { |
| 679 | struct p54_common *priv = dev->priv; |
Christian Lamparter | 1a9b667 | 2009-07-11 01:22:26 +0200 | [diff] [blame] | 680 | unsigned int i; |
| 681 | |
| 682 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
| 683 | kfree(priv->band_table[i]); |
Christian Lamparter | 0ac0d6c | 2009-06-23 10:38:49 -0500 | [diff] [blame] | 684 | |
| 685 | kfree(priv->iq_autocal); |
| 686 | kfree(priv->output_limit); |
| 687 | kfree(priv->curve_data); |
Christian Lamparter | 7a047f4 | 2011-02-12 22:32:49 +0100 | [diff] [blame] | 688 | kfree(priv->rssi_db); |
Christian Lamparter | 0ac0d6c | 2009-06-23 10:38:49 -0500 | [diff] [blame] | 689 | kfree(priv->used_rxkeys); |
| 690 | priv->iq_autocal = NULL; |
| 691 | priv->output_limit = NULL; |
| 692 | priv->curve_data = NULL; |
Christian Lamparter | 7a047f4 | 2011-02-12 22:32:49 +0100 | [diff] [blame] | 693 | priv->rssi_db = NULL; |
Christian Lamparter | 0ac0d6c | 2009-06-23 10:38:49 -0500 | [diff] [blame] | 694 | priv->used_rxkeys = NULL; |
| 695 | ieee80211_free_hw(dev); |
| 696 | } |
| 697 | EXPORT_SYMBOL_GPL(p54_free_common); |
| 698 | |
| 699 | void p54_unregister_common(struct ieee80211_hw *dev) |
| 700 | { |
| 701 | struct p54_common *priv = dev->priv; |
| 702 | |
| 703 | #ifdef CONFIG_P54_LEDS |
| 704 | p54_unregister_leds(priv); |
| 705 | #endif /* CONFIG_P54_LEDS */ |
| 706 | |
| 707 | ieee80211_unregister_hw(dev); |
| 708 | mutex_destroy(&priv->conf_mutex); |
| 709 | mutex_destroy(&priv->eeprom_mutex); |
| 710 | } |
| 711 | EXPORT_SYMBOL_GPL(p54_unregister_common); |