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