Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1 | /* |
Ivo van Doorn | 811aa9c | 2008-02-03 15:42:53 +0100 | [diff] [blame] | 2 | Copyright (C) 2004 - 2008 rt2x00 SourceForge Project |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 3 | <http://rt2x00.serialmonkey.com> |
| 4 | |
| 5 | This program is free software; you can redistribute it and/or modify |
| 6 | it under the terms of the GNU General Public License as published by |
| 7 | the Free Software Foundation; either version 2 of the License, or |
| 8 | (at your option) any later version. |
| 9 | |
| 10 | This program is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | GNU General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License |
| 16 | along with this program; if not, write to the |
| 17 | Free Software Foundation, Inc., |
| 18 | 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 19 | */ |
| 20 | |
| 21 | /* |
| 22 | Module: rt2x00mac |
| 23 | Abstract: rt2x00 generic mac80211 routines. |
| 24 | */ |
| 25 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 26 | #include <linux/kernel.h> |
| 27 | #include <linux/module.h> |
| 28 | |
| 29 | #include "rt2x00.h" |
| 30 | #include "rt2x00lib.h" |
| 31 | |
| 32 | static int rt2x00mac_tx_rts_cts(struct rt2x00_dev *rt2x00dev, |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 33 | struct data_queue *queue, |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 34 | struct sk_buff *frag_skb, |
| 35 | struct ieee80211_tx_control *control) |
| 36 | { |
| 37 | struct sk_buff *skb; |
| 38 | int size; |
| 39 | |
| 40 | if (control->flags & IEEE80211_TXCTL_USE_CTS_PROTECT) |
| 41 | size = sizeof(struct ieee80211_cts); |
| 42 | else |
| 43 | size = sizeof(struct ieee80211_rts); |
| 44 | |
| 45 | skb = dev_alloc_skb(size + rt2x00dev->hw->extra_tx_headroom); |
| 46 | if (!skb) { |
| 47 | WARNING(rt2x00dev, "Failed to create RTS/CTS frame.\n"); |
| 48 | return NETDEV_TX_BUSY; |
| 49 | } |
| 50 | |
| 51 | skb_reserve(skb, rt2x00dev->hw->extra_tx_headroom); |
| 52 | skb_put(skb, size); |
| 53 | |
| 54 | if (control->flags & IEEE80211_TXCTL_USE_CTS_PROTECT) |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame^] | 55 | ieee80211_ctstoself_get(rt2x00dev->hw, control->vif, |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 56 | frag_skb->data, frag_skb->len, control, |
| 57 | (struct ieee80211_cts *)(skb->data)); |
| 58 | else |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame^] | 59 | ieee80211_rts_get(rt2x00dev->hw, control->vif, |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 60 | frag_skb->data, frag_skb->len, control, |
| 61 | (struct ieee80211_rts *)(skb->data)); |
| 62 | |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 63 | if (rt2x00dev->ops->lib->write_tx_data(rt2x00dev, queue, skb, control)) { |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 64 | WARNING(rt2x00dev, "Failed to send RTS/CTS frame.\n"); |
| 65 | return NETDEV_TX_BUSY; |
| 66 | } |
| 67 | |
| 68 | return NETDEV_TX_OK; |
| 69 | } |
| 70 | |
| 71 | int rt2x00mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb, |
| 72 | struct ieee80211_tx_control *control) |
| 73 | { |
| 74 | struct rt2x00_dev *rt2x00dev = hw->priv; |
| 75 | struct ieee80211_hdr *ieee80211hdr = (struct ieee80211_hdr *)skb->data; |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 76 | struct data_queue *queue; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 77 | u16 frame_control; |
| 78 | |
| 79 | /* |
Ivo van Doorn | 066cb63 | 2007-09-25 20:55:39 +0200 | [diff] [blame] | 80 | * Mac80211 might be calling this function while we are trying |
| 81 | * to remove the device or perhaps suspending it. |
| 82 | * Note that we can only stop the TX queues inside the TX path |
| 83 | * due to possible race conditions in mac80211. |
| 84 | */ |
| 85 | if (!test_bit(DEVICE_PRESENT, &rt2x00dev->flags)) { |
| 86 | ieee80211_stop_queues(hw); |
Ivo van Doorn | 1230cb8 | 2008-01-06 23:38:34 +0100 | [diff] [blame] | 87 | return NETDEV_TX_OK; |
Ivo van Doorn | 066cb63 | 2007-09-25 20:55:39 +0200 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | /* |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 91 | * Determine which queue to put packet on. |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 92 | */ |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 93 | queue = rt2x00queue_get_queue(rt2x00dev, control->queue); |
| 94 | if (unlikely(!queue)) { |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 95 | ERROR(rt2x00dev, |
| 96 | "Attempt to send packet over invalid queue %d.\n" |
| 97 | "Please file bug report to %s.\n", |
| 98 | control->queue, DRV_PROJECT); |
| 99 | dev_kfree_skb_any(skb); |
| 100 | return NETDEV_TX_OK; |
| 101 | } |
| 102 | |
| 103 | /* |
| 104 | * If CTS/RTS is required. and this frame is not CTS or RTS, |
| 105 | * create and queue that frame first. But make sure we have |
| 106 | * at least enough entries available to send this CTS/RTS |
| 107 | * frame as well as the data frame. |
| 108 | */ |
| 109 | frame_control = le16_to_cpu(ieee80211hdr->frame_control); |
| 110 | if (!is_rts_frame(frame_control) && !is_cts_frame(frame_control) && |
| 111 | (control->flags & (IEEE80211_TXCTL_USE_RTS_CTS | |
| 112 | IEEE80211_TXCTL_USE_CTS_PROTECT))) { |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 113 | if (rt2x00queue_available(queue) <= 1) { |
Ivo van Doorn | 1230cb8 | 2008-01-06 23:38:34 +0100 | [diff] [blame] | 114 | ieee80211_stop_queue(rt2x00dev->hw, control->queue); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 115 | return NETDEV_TX_BUSY; |
Ivo van Doorn | 1230cb8 | 2008-01-06 23:38:34 +0100 | [diff] [blame] | 116 | } |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 117 | |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 118 | if (rt2x00mac_tx_rts_cts(rt2x00dev, queue, skb, control)) { |
Ivo van Doorn | 1230cb8 | 2008-01-06 23:38:34 +0100 | [diff] [blame] | 119 | ieee80211_stop_queue(rt2x00dev->hw, control->queue); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 120 | return NETDEV_TX_BUSY; |
Ivo van Doorn | 1230cb8 | 2008-01-06 23:38:34 +0100 | [diff] [blame] | 121 | } |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 122 | } |
| 123 | |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 124 | if (rt2x00dev->ops->lib->write_tx_data(rt2x00dev, queue, skb, control)) { |
Ivo van Doorn | 1230cb8 | 2008-01-06 23:38:34 +0100 | [diff] [blame] | 125 | ieee80211_stop_queue(rt2x00dev->hw, control->queue); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 126 | return NETDEV_TX_BUSY; |
Ivo van Doorn | 1230cb8 | 2008-01-06 23:38:34 +0100 | [diff] [blame] | 127 | } |
| 128 | |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 129 | if (rt2x00queue_full(queue)) |
Ivo van Doorn | 1230cb8 | 2008-01-06 23:38:34 +0100 | [diff] [blame] | 130 | ieee80211_stop_queue(rt2x00dev->hw, control->queue); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 131 | |
| 132 | if (rt2x00dev->ops->lib->kick_tx_queue) |
| 133 | rt2x00dev->ops->lib->kick_tx_queue(rt2x00dev, control->queue); |
| 134 | |
| 135 | return NETDEV_TX_OK; |
| 136 | } |
| 137 | EXPORT_SYMBOL_GPL(rt2x00mac_tx); |
| 138 | |
| 139 | int rt2x00mac_start(struct ieee80211_hw *hw) |
| 140 | { |
| 141 | struct rt2x00_dev *rt2x00dev = hw->priv; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 142 | |
Ivo van Doorn | e37ea21 | 2008-01-06 23:40:07 +0100 | [diff] [blame] | 143 | if (!test_bit(DEVICE_PRESENT, &rt2x00dev->flags)) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 144 | return 0; |
| 145 | |
Ivo van Doorn | e37ea21 | 2008-01-06 23:40:07 +0100 | [diff] [blame] | 146 | return rt2x00lib_start(rt2x00dev); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 147 | } |
| 148 | EXPORT_SYMBOL_GPL(rt2x00mac_start); |
| 149 | |
| 150 | void rt2x00mac_stop(struct ieee80211_hw *hw) |
| 151 | { |
| 152 | struct rt2x00_dev *rt2x00dev = hw->priv; |
| 153 | |
Ivo van Doorn | 066cb63 | 2007-09-25 20:55:39 +0200 | [diff] [blame] | 154 | if (!test_bit(DEVICE_PRESENT, &rt2x00dev->flags)) |
| 155 | return; |
| 156 | |
Ivo van Doorn | e37ea21 | 2008-01-06 23:40:07 +0100 | [diff] [blame] | 157 | rt2x00lib_stop(rt2x00dev); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 158 | } |
| 159 | EXPORT_SYMBOL_GPL(rt2x00mac_stop); |
| 160 | |
| 161 | int rt2x00mac_add_interface(struct ieee80211_hw *hw, |
| 162 | struct ieee80211_if_init_conf *conf) |
| 163 | { |
| 164 | struct rt2x00_dev *rt2x00dev = hw->priv; |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame^] | 165 | struct rt2x00_intf *intf = vif_to_intf(conf->vif); |
| 166 | struct data_queue *queue = |
| 167 | rt2x00queue_get_queue(rt2x00dev, IEEE80211_TX_QUEUE_BEACON); |
| 168 | struct queue_entry *entry = NULL; |
| 169 | unsigned int i; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 170 | |
| 171 | /* |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame^] | 172 | * Don't allow interfaces to be added |
| 173 | * the device has disappeared. |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 174 | */ |
Ivo van Doorn | 066cb63 | 2007-09-25 20:55:39 +0200 | [diff] [blame] | 175 | if (!test_bit(DEVICE_PRESENT, &rt2x00dev->flags) || |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame^] | 176 | !test_bit(DEVICE_STARTED, &rt2x00dev->flags)) |
| 177 | return -ENODEV; |
| 178 | |
| 179 | /* |
| 180 | * When we don't support mixed interfaces (a combination |
| 181 | * of sta and ap virtual interfaces) then we can only |
| 182 | * add this interface when the rival interface count is 0. |
| 183 | */ |
| 184 | if (!test_bit(DRIVER_SUPPORT_MIXED_INTERFACES, &rt2x00dev->flags) && |
| 185 | ((conf->type == IEEE80211_IF_TYPE_AP && rt2x00dev->intf_sta_count) || |
| 186 | (conf->type != IEEE80211_IF_TYPE_AP && rt2x00dev->intf_ap_count))) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 187 | return -ENOBUFS; |
| 188 | |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame^] | 189 | /* |
| 190 | * Check if we exceeded the maximum amount of supported interfaces. |
| 191 | */ |
| 192 | if ((conf->type == IEEE80211_IF_TYPE_AP && |
| 193 | rt2x00dev->intf_ap_count >= rt2x00dev->ops->max_ap_intf) || |
| 194 | (conf->type != IEEE80211_IF_TYPE_AP && |
| 195 | rt2x00dev->intf_sta_count >= rt2x00dev->ops->max_sta_intf)) |
| 196 | return -ENOBUFS; |
| 197 | |
| 198 | /* |
| 199 | * Loop through all beacon queues to find a free |
| 200 | * entry. Since there are as much beacon entries |
| 201 | * as the maximum interfaces, this search shouldn't |
| 202 | * fail. |
| 203 | */ |
| 204 | for (i = 0; i < queue->limit; i++) { |
| 205 | entry = &queue->entries[i]; |
| 206 | if (!__test_and_set_bit(ENTRY_BCN_ASSIGNED, &entry->flags)) |
| 207 | break; |
| 208 | } |
| 209 | |
| 210 | if (unlikely(i == queue->limit)) |
| 211 | return -ENOBUFS; |
| 212 | |
| 213 | /* |
| 214 | * We are now absolutely sure the interface can be created, |
| 215 | * increase interface count and start initialization. |
| 216 | */ |
| 217 | |
| 218 | if (conf->type == IEEE80211_IF_TYPE_AP) |
| 219 | rt2x00dev->intf_ap_count++; |
| 220 | else |
| 221 | rt2x00dev->intf_sta_count++; |
| 222 | |
| 223 | spin_lock_init(&intf->lock); |
| 224 | intf->beacon = entry; |
| 225 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 226 | if (conf->type == IEEE80211_IF_TYPE_AP) |
| 227 | memcpy(&intf->bssid, conf->mac_addr, ETH_ALEN); |
| 228 | memcpy(&intf->mac, conf->mac_addr, ETH_ALEN); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 229 | |
| 230 | /* |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 231 | * The MAC adddress must be configured after the device |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 232 | * has been initialized. Otherwise the device can reset |
| 233 | * the MAC registers. |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 234 | */ |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame^] | 235 | rt2x00lib_config_intf(rt2x00dev, intf, conf->type, intf->mac, NULL); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 236 | |
| 237 | return 0; |
| 238 | } |
| 239 | EXPORT_SYMBOL_GPL(rt2x00mac_add_interface); |
| 240 | |
| 241 | void rt2x00mac_remove_interface(struct ieee80211_hw *hw, |
| 242 | struct ieee80211_if_init_conf *conf) |
| 243 | { |
| 244 | struct rt2x00_dev *rt2x00dev = hw->priv; |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame^] | 245 | struct rt2x00_intf *intf = vif_to_intf(conf->vif); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 246 | |
| 247 | /* |
Ivo van Doorn | 066cb63 | 2007-09-25 20:55:39 +0200 | [diff] [blame] | 248 | * Don't allow interfaces to be remove while |
| 249 | * either the device has disappeared or when |
| 250 | * no interface is present. |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 251 | */ |
Ivo van Doorn | 066cb63 | 2007-09-25 20:55:39 +0200 | [diff] [blame] | 252 | if (!test_bit(DEVICE_PRESENT, &rt2x00dev->flags) || |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame^] | 253 | (conf->type == IEEE80211_IF_TYPE_AP && !rt2x00dev->intf_ap_count) || |
| 254 | (conf->type != IEEE80211_IF_TYPE_AP && !rt2x00dev->intf_sta_count)) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 255 | return; |
| 256 | |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame^] | 257 | if (conf->type == IEEE80211_IF_TYPE_AP) |
| 258 | rt2x00dev->intf_ap_count--; |
| 259 | else |
| 260 | rt2x00dev->intf_sta_count--; |
| 261 | |
| 262 | /* |
| 263 | * Release beacon entry so it is available for |
| 264 | * new interfaces again. |
| 265 | */ |
| 266 | __clear_bit(ENTRY_BCN_ASSIGNED, &intf->beacon->flags); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 267 | |
| 268 | /* |
| 269 | * Make sure the bssid and mac address registers |
| 270 | * are cleared to prevent false ACKing of frames. |
| 271 | */ |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame^] | 272 | rt2x00lib_config_intf(rt2x00dev, intf, |
| 273 | IEEE80211_IF_TYPE_INVALID, NULL, NULL); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 274 | } |
| 275 | EXPORT_SYMBOL_GPL(rt2x00mac_remove_interface); |
| 276 | |
| 277 | int rt2x00mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf) |
| 278 | { |
| 279 | struct rt2x00_dev *rt2x00dev = hw->priv; |
| 280 | |
| 281 | /* |
Ivo van Doorn | 066cb63 | 2007-09-25 20:55:39 +0200 | [diff] [blame] | 282 | * Mac80211 might be calling this function while we are trying |
| 283 | * to remove the device or perhaps suspending it. |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 284 | */ |
Ivo van Doorn | 066cb63 | 2007-09-25 20:55:39 +0200 | [diff] [blame] | 285 | if (!test_bit(DEVICE_PRESENT, &rt2x00dev->flags)) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 286 | return 0; |
| 287 | |
| 288 | /* |
| 289 | * Check if we need to disable the radio, |
| 290 | * if this is not the case, at least the RX must be disabled. |
| 291 | */ |
| 292 | if (test_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags)) { |
| 293 | if (!conf->radio_enabled) |
| 294 | rt2x00lib_disable_radio(rt2x00dev); |
| 295 | else |
Ivo van Doorn | 5cbf830 | 2007-10-06 14:16:09 +0200 | [diff] [blame] | 296 | rt2x00lib_toggle_rx(rt2x00dev, STATE_RADIO_RX_OFF); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 297 | } |
| 298 | |
Ivo van Doorn | 066cb63 | 2007-09-25 20:55:39 +0200 | [diff] [blame] | 299 | rt2x00lib_config(rt2x00dev, conf, 0); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 300 | |
| 301 | /* |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 302 | * Reenable RX only if the radio should be on. |
| 303 | */ |
| 304 | if (test_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags)) |
Ivo van Doorn | 5cbf830 | 2007-10-06 14:16:09 +0200 | [diff] [blame] | 305 | rt2x00lib_toggle_rx(rt2x00dev, STATE_RADIO_RX_ON); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 306 | else if (conf->radio_enabled) |
| 307 | return rt2x00lib_enable_radio(rt2x00dev); |
| 308 | |
| 309 | return 0; |
| 310 | } |
| 311 | EXPORT_SYMBOL_GPL(rt2x00mac_config); |
| 312 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 313 | int rt2x00mac_config_interface(struct ieee80211_hw *hw, |
| 314 | struct ieee80211_vif *vif, |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 315 | struct ieee80211_if_conf *conf) |
| 316 | { |
| 317 | struct rt2x00_dev *rt2x00dev = hw->priv; |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame^] | 318 | struct rt2x00_intf *intf = vif_to_intf(vif); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 319 | int status; |
| 320 | |
| 321 | /* |
Ivo van Doorn | 066cb63 | 2007-09-25 20:55:39 +0200 | [diff] [blame] | 322 | * Mac80211 might be calling this function while we are trying |
| 323 | * to remove the device or perhaps suspending it. |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 324 | */ |
Ivo van Doorn | 066cb63 | 2007-09-25 20:55:39 +0200 | [diff] [blame] | 325 | if (!test_bit(DEVICE_PRESENT, &rt2x00dev->flags)) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 326 | return 0; |
| 327 | |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame^] | 328 | spin_lock(&intf->lock); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 329 | |
| 330 | /* |
| 331 | * If the interface does not work in master mode, |
| 332 | * then the bssid value in the interface structure |
| 333 | * should now be set. |
| 334 | */ |
| 335 | if (conf->type != IEEE80211_IF_TYPE_AP) |
| 336 | memcpy(&intf->bssid, conf->bssid, ETH_ALEN); |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame^] | 337 | rt2x00lib_config_intf(rt2x00dev, intf, conf->type, NULL, intf->bssid); |
| 338 | |
| 339 | spin_unlock(&intf->lock); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 340 | |
| 341 | /* |
| 342 | * We only need to initialize the beacon when master mode is enabled. |
| 343 | */ |
| 344 | if (conf->type != IEEE80211_IF_TYPE_AP || !conf->beacon) |
| 345 | return 0; |
| 346 | |
| 347 | status = rt2x00dev->ops->hw->beacon_update(rt2x00dev->hw, |
| 348 | conf->beacon, |
| 349 | conf->beacon_control); |
| 350 | if (status) |
| 351 | dev_kfree_skb(conf->beacon); |
| 352 | |
| 353 | return status; |
| 354 | } |
| 355 | EXPORT_SYMBOL_GPL(rt2x00mac_config_interface); |
| 356 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 357 | int rt2x00mac_get_stats(struct ieee80211_hw *hw, |
| 358 | struct ieee80211_low_level_stats *stats) |
| 359 | { |
| 360 | struct rt2x00_dev *rt2x00dev = hw->priv; |
| 361 | |
| 362 | /* |
| 363 | * The dot11ACKFailureCount, dot11RTSFailureCount and |
| 364 | * dot11RTSSuccessCount are updated in interrupt time. |
| 365 | * dot11FCSErrorCount is updated in the link tuner. |
| 366 | */ |
| 367 | memcpy(stats, &rt2x00dev->low_level_stats, sizeof(*stats)); |
| 368 | |
| 369 | return 0; |
| 370 | } |
| 371 | EXPORT_SYMBOL_GPL(rt2x00mac_get_stats); |
| 372 | |
| 373 | int rt2x00mac_get_tx_stats(struct ieee80211_hw *hw, |
| 374 | struct ieee80211_tx_queue_stats *stats) |
| 375 | { |
| 376 | struct rt2x00_dev *rt2x00dev = hw->priv; |
| 377 | unsigned int i; |
| 378 | |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 379 | for (i = 0; i < hw->queues; i++) { |
| 380 | stats->data[i].len = rt2x00dev->tx[i].length; |
| 381 | stats->data[i].limit = rt2x00dev->tx[i].limit; |
| 382 | stats->data[i].count = rt2x00dev->tx[i].count; |
| 383 | } |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 384 | |
| 385 | return 0; |
| 386 | } |
| 387 | EXPORT_SYMBOL_GPL(rt2x00mac_get_tx_stats); |
| 388 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 389 | void rt2x00mac_bss_info_changed(struct ieee80211_hw *hw, |
| 390 | struct ieee80211_vif *vif, |
| 391 | struct ieee80211_bss_conf *bss_conf, |
| 392 | u32 changes) |
Ivo van Doorn | 5c58ee5 | 2007-10-06 13:34:52 +0200 | [diff] [blame] | 393 | { |
| 394 | struct rt2x00_dev *rt2x00dev = hw->priv; |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame^] | 395 | struct rt2x00_intf *intf = vif_to_intf(vif); |
Ivo van Doorn | 5c58ee5 | 2007-10-06 13:34:52 +0200 | [diff] [blame] | 396 | |
| 397 | /* |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame^] | 398 | * When the association status has changed we must reset the link |
| 399 | * tuner counter. This is because some drivers determine if they |
| 400 | * should perform link tuning based on the number of seconds |
| 401 | * while associated or not associated. |
Ivo van Doorn | 5c58ee5 | 2007-10-06 13:34:52 +0200 | [diff] [blame] | 402 | */ |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame^] | 403 | if (changes & BSS_CHANGED_ASSOC) { |
| 404 | rt2x00dev->link.count = 0; |
Ivo van Doorn | 5c58ee5 | 2007-10-06 13:34:52 +0200 | [diff] [blame] | 405 | |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame^] | 406 | if (bss_conf->assoc) |
| 407 | rt2x00dev->intf_associated++; |
| 408 | else |
| 409 | rt2x00dev->intf_associated--; |
| 410 | } |
Ivo van Doorn | 5c58ee5 | 2007-10-06 13:34:52 +0200 | [diff] [blame] | 411 | |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame^] | 412 | /* |
| 413 | * When the preamble mode has changed, we should perform additional |
| 414 | * configuration steps. For all other changes we are already done. |
| 415 | */ |
| 416 | if (changes & BSS_CHANGED_ERP_PREAMBLE) { |
| 417 | rt2x00lib_config_preamble(rt2x00dev, intf, |
| 418 | bss_conf->use_short_preamble); |
Ivo van Doorn | 5c58ee5 | 2007-10-06 13:34:52 +0200 | [diff] [blame] | 419 | |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame^] | 420 | spin_lock(&intf->lock); |
| 421 | memcpy(&intf->conf, bss_conf, sizeof(*bss_conf)); |
| 422 | spin_unlock(&intf->lock); |
| 423 | } |
Ivo van Doorn | 5c58ee5 | 2007-10-06 13:34:52 +0200 | [diff] [blame] | 424 | } |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 425 | EXPORT_SYMBOL_GPL(rt2x00mac_bss_info_changed); |
Ivo van Doorn | 5c58ee5 | 2007-10-06 13:34:52 +0200 | [diff] [blame] | 426 | |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 427 | int rt2x00mac_conf_tx(struct ieee80211_hw *hw, int queue_idx, |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 428 | const struct ieee80211_tx_queue_params *params) |
| 429 | { |
| 430 | struct rt2x00_dev *rt2x00dev = hw->priv; |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 431 | struct data_queue *queue; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 432 | |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 433 | queue = rt2x00queue_get_queue(rt2x00dev, queue_idx); |
| 434 | if (unlikely(!queue)) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 435 | return -EINVAL; |
| 436 | |
| 437 | /* |
| 438 | * The passed variables are stored as real value ((2^n)-1). |
| 439 | * Ralink registers require to know the bit number 'n'. |
| 440 | */ |
Ivo van Doorn | 3b3618a | 2008-02-03 15:47:30 +0100 | [diff] [blame] | 441 | if (params->cw_min > 0) |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 442 | queue->cw_min = fls(params->cw_min); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 443 | else |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 444 | queue->cw_min = 5; /* cw_min: 2^5 = 32. */ |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 445 | |
Ivo van Doorn | 3b3618a | 2008-02-03 15:47:30 +0100 | [diff] [blame] | 446 | if (params->cw_max > 0) |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 447 | queue->cw_max = fls(params->cw_max); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 448 | else |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 449 | queue->cw_max = 10; /* cw_min: 2^10 = 1024. */ |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 450 | |
Ivo van Doorn | 3b3618a | 2008-02-03 15:47:30 +0100 | [diff] [blame] | 451 | if (params->aifs >= 0) |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 452 | queue->aifs = params->aifs; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 453 | else |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 454 | queue->aifs = 2; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 455 | |
| 456 | INFO(rt2x00dev, |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 457 | "Configured TX queue %d - CWmin: %d, CWmax: %d, Aifs: %d.\n", |
| 458 | queue_idx, queue->cw_min, queue->cw_max, queue->aifs); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 459 | |
| 460 | return 0; |
| 461 | } |
| 462 | EXPORT_SYMBOL_GPL(rt2x00mac_conf_tx); |