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) |
| 55 | ieee80211_ctstoself_get(rt2x00dev->hw, rt2x00dev->interface.id, |
| 56 | frag_skb->data, frag_skb->len, control, |
| 57 | (struct ieee80211_cts *)(skb->data)); |
| 58 | else |
| 59 | ieee80211_rts_get(rt2x00dev->hw, rt2x00dev->interface.id, |
| 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; |
| 165 | struct interface *intf = &rt2x00dev->interface; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 166 | |
| 167 | /* |
Ivo van Doorn | 066cb63 | 2007-09-25 20:55:39 +0200 | [diff] [blame] | 168 | * Don't allow interfaces to be added while |
| 169 | * either the device has disappeared or when |
| 170 | * another interface is already present. |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 171 | */ |
Ivo van Doorn | 066cb63 | 2007-09-25 20:55:39 +0200 | [diff] [blame] | 172 | if (!test_bit(DEVICE_PRESENT, &rt2x00dev->flags) || |
| 173 | is_interface_present(intf)) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 174 | return -ENOBUFS; |
| 175 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 176 | intf->id = conf->vif; |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 177 | intf->type = conf->type; |
| 178 | if (conf->type == IEEE80211_IF_TYPE_AP) |
| 179 | memcpy(&intf->bssid, conf->mac_addr, ETH_ALEN); |
| 180 | memcpy(&intf->mac, conf->mac_addr, ETH_ALEN); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 181 | |
| 182 | /* |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 183 | * The MAC adddress must be configured after the device |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 184 | * has been initialized. Otherwise the device can reset |
| 185 | * the MAC registers. |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 186 | */ |
| 187 | rt2x00lib_config_mac_addr(rt2x00dev, intf->mac); |
| 188 | rt2x00lib_config_type(rt2x00dev, conf->type); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 189 | |
| 190 | return 0; |
| 191 | } |
| 192 | EXPORT_SYMBOL_GPL(rt2x00mac_add_interface); |
| 193 | |
| 194 | void rt2x00mac_remove_interface(struct ieee80211_hw *hw, |
| 195 | struct ieee80211_if_init_conf *conf) |
| 196 | { |
| 197 | struct rt2x00_dev *rt2x00dev = hw->priv; |
| 198 | struct interface *intf = &rt2x00dev->interface; |
| 199 | |
| 200 | /* |
Ivo van Doorn | 066cb63 | 2007-09-25 20:55:39 +0200 | [diff] [blame] | 201 | * Don't allow interfaces to be remove while |
| 202 | * either the device has disappeared or when |
| 203 | * no interface is present. |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 204 | */ |
Ivo van Doorn | 066cb63 | 2007-09-25 20:55:39 +0200 | [diff] [blame] | 205 | if (!test_bit(DEVICE_PRESENT, &rt2x00dev->flags) || |
| 206 | !is_interface_present(intf)) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 207 | return; |
| 208 | |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 209 | intf->id = NULL; |
Ivo van Doorn | d28c256 | 2007-11-27 21:49:50 +0100 | [diff] [blame] | 210 | intf->type = IEEE80211_IF_TYPE_INVALID; |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 211 | memset(&intf->bssid, 0x00, ETH_ALEN); |
| 212 | memset(&intf->mac, 0x00, ETH_ALEN); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 213 | |
| 214 | /* |
| 215 | * Make sure the bssid and mac address registers |
| 216 | * are cleared to prevent false ACKing of frames. |
| 217 | */ |
| 218 | rt2x00lib_config_mac_addr(rt2x00dev, intf->mac); |
| 219 | rt2x00lib_config_bssid(rt2x00dev, intf->bssid); |
| 220 | rt2x00lib_config_type(rt2x00dev, intf->type); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 221 | } |
| 222 | EXPORT_SYMBOL_GPL(rt2x00mac_remove_interface); |
| 223 | |
| 224 | int rt2x00mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf) |
| 225 | { |
| 226 | struct rt2x00_dev *rt2x00dev = hw->priv; |
| 227 | |
| 228 | /* |
Ivo van Doorn | 066cb63 | 2007-09-25 20:55:39 +0200 | [diff] [blame] | 229 | * Mac80211 might be calling this function while we are trying |
| 230 | * to remove the device or perhaps suspending it. |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 231 | */ |
Ivo van Doorn | 066cb63 | 2007-09-25 20:55:39 +0200 | [diff] [blame] | 232 | if (!test_bit(DEVICE_PRESENT, &rt2x00dev->flags)) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 233 | return 0; |
| 234 | |
| 235 | /* |
| 236 | * Check if we need to disable the radio, |
| 237 | * if this is not the case, at least the RX must be disabled. |
| 238 | */ |
| 239 | if (test_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags)) { |
| 240 | if (!conf->radio_enabled) |
| 241 | rt2x00lib_disable_radio(rt2x00dev); |
| 242 | else |
Ivo van Doorn | 5cbf830 | 2007-10-06 14:16:09 +0200 | [diff] [blame] | 243 | rt2x00lib_toggle_rx(rt2x00dev, STATE_RADIO_RX_OFF); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 244 | } |
| 245 | |
Ivo van Doorn | 066cb63 | 2007-09-25 20:55:39 +0200 | [diff] [blame] | 246 | rt2x00lib_config(rt2x00dev, conf, 0); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 247 | |
| 248 | /* |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 249 | * Reenable RX only if the radio should be on. |
| 250 | */ |
| 251 | if (test_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags)) |
Ivo van Doorn | 5cbf830 | 2007-10-06 14:16:09 +0200 | [diff] [blame] | 252 | rt2x00lib_toggle_rx(rt2x00dev, STATE_RADIO_RX_ON); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 253 | else if (conf->radio_enabled) |
| 254 | return rt2x00lib_enable_radio(rt2x00dev); |
| 255 | |
| 256 | return 0; |
| 257 | } |
| 258 | EXPORT_SYMBOL_GPL(rt2x00mac_config); |
| 259 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 260 | int rt2x00mac_config_interface(struct ieee80211_hw *hw, |
| 261 | struct ieee80211_vif *vif, |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 262 | struct ieee80211_if_conf *conf) |
| 263 | { |
| 264 | struct rt2x00_dev *rt2x00dev = hw->priv; |
| 265 | struct interface *intf = &rt2x00dev->interface; |
| 266 | int status; |
| 267 | |
| 268 | /* |
Ivo van Doorn | 066cb63 | 2007-09-25 20:55:39 +0200 | [diff] [blame] | 269 | * Mac80211 might be calling this function while we are trying |
| 270 | * to remove the device or perhaps suspending it. |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 271 | */ |
Ivo van Doorn | 066cb63 | 2007-09-25 20:55:39 +0200 | [diff] [blame] | 272 | if (!test_bit(DEVICE_PRESENT, &rt2x00dev->flags)) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 273 | return 0; |
| 274 | |
| 275 | /* |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 276 | * If the given type does not match the configured type, |
| 277 | * there has been a problem. |
| 278 | */ |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 279 | if (conf->type != intf->type) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 280 | return -EINVAL; |
| 281 | |
| 282 | /* |
| 283 | * If the interface does not work in master mode, |
| 284 | * then the bssid value in the interface structure |
| 285 | * should now be set. |
| 286 | */ |
| 287 | if (conf->type != IEEE80211_IF_TYPE_AP) |
| 288 | memcpy(&intf->bssid, conf->bssid, ETH_ALEN); |
| 289 | rt2x00lib_config_bssid(rt2x00dev, intf->bssid); |
| 290 | |
| 291 | /* |
| 292 | * We only need to initialize the beacon when master mode is enabled. |
| 293 | */ |
| 294 | if (conf->type != IEEE80211_IF_TYPE_AP || !conf->beacon) |
| 295 | return 0; |
| 296 | |
| 297 | status = rt2x00dev->ops->hw->beacon_update(rt2x00dev->hw, |
| 298 | conf->beacon, |
| 299 | conf->beacon_control); |
| 300 | if (status) |
| 301 | dev_kfree_skb(conf->beacon); |
| 302 | |
| 303 | return status; |
| 304 | } |
| 305 | EXPORT_SYMBOL_GPL(rt2x00mac_config_interface); |
| 306 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 307 | int rt2x00mac_get_stats(struct ieee80211_hw *hw, |
| 308 | struct ieee80211_low_level_stats *stats) |
| 309 | { |
| 310 | struct rt2x00_dev *rt2x00dev = hw->priv; |
| 311 | |
| 312 | /* |
| 313 | * The dot11ACKFailureCount, dot11RTSFailureCount and |
| 314 | * dot11RTSSuccessCount are updated in interrupt time. |
| 315 | * dot11FCSErrorCount is updated in the link tuner. |
| 316 | */ |
| 317 | memcpy(stats, &rt2x00dev->low_level_stats, sizeof(*stats)); |
| 318 | |
| 319 | return 0; |
| 320 | } |
| 321 | EXPORT_SYMBOL_GPL(rt2x00mac_get_stats); |
| 322 | |
| 323 | int rt2x00mac_get_tx_stats(struct ieee80211_hw *hw, |
| 324 | struct ieee80211_tx_queue_stats *stats) |
| 325 | { |
| 326 | struct rt2x00_dev *rt2x00dev = hw->priv; |
| 327 | unsigned int i; |
| 328 | |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 329 | for (i = 0; i < hw->queues; i++) { |
| 330 | stats->data[i].len = rt2x00dev->tx[i].length; |
| 331 | stats->data[i].limit = rt2x00dev->tx[i].limit; |
| 332 | stats->data[i].count = rt2x00dev->tx[i].count; |
| 333 | } |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 334 | |
| 335 | return 0; |
| 336 | } |
| 337 | EXPORT_SYMBOL_GPL(rt2x00mac_get_tx_stats); |
| 338 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 339 | void rt2x00mac_bss_info_changed(struct ieee80211_hw *hw, |
| 340 | struct ieee80211_vif *vif, |
| 341 | struct ieee80211_bss_conf *bss_conf, |
| 342 | u32 changes) |
Ivo van Doorn | 5c58ee5 | 2007-10-06 13:34:52 +0200 | [diff] [blame] | 343 | { |
| 344 | struct rt2x00_dev *rt2x00dev = hw->priv; |
| 345 | int short_preamble; |
| 346 | int ack_timeout; |
| 347 | int ack_consume_time; |
| 348 | int difs; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 349 | int preamble; |
Ivo van Doorn | 5c58ee5 | 2007-10-06 13:34:52 +0200 | [diff] [blame] | 350 | |
| 351 | /* |
| 352 | * We only support changing preamble mode. |
| 353 | */ |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 354 | if (!(changes & BSS_CHANGED_ERP_PREAMBLE)) |
Ivo van Doorn | 5c58ee5 | 2007-10-06 13:34:52 +0200 | [diff] [blame] | 355 | return; |
| 356 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 357 | short_preamble = bss_conf->use_short_preamble; |
| 358 | preamble = bss_conf->use_short_preamble ? |
| 359 | SHORT_PREAMBLE : PREAMBLE; |
Ivo van Doorn | 5c58ee5 | 2007-10-06 13:34:52 +0200 | [diff] [blame] | 360 | |
| 361 | difs = (hw->conf.flags & IEEE80211_CONF_SHORT_SLOT_TIME) ? |
| 362 | SHORT_DIFS : DIFS; |
| 363 | ack_timeout = difs + PLCP + preamble + get_duration(ACK_SIZE, 10); |
| 364 | |
| 365 | ack_consume_time = SIFS + PLCP + preamble + get_duration(ACK_SIZE, 10); |
| 366 | |
| 367 | if (short_preamble) |
| 368 | __set_bit(CONFIG_SHORT_PREAMBLE, &rt2x00dev->flags); |
| 369 | else |
| 370 | __clear_bit(CONFIG_SHORT_PREAMBLE, &rt2x00dev->flags); |
| 371 | |
| 372 | rt2x00dev->ops->lib->config_preamble(rt2x00dev, short_preamble, |
| 373 | ack_timeout, ack_consume_time); |
| 374 | } |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 375 | EXPORT_SYMBOL_GPL(rt2x00mac_bss_info_changed); |
Ivo van Doorn | 5c58ee5 | 2007-10-06 13:34:52 +0200 | [diff] [blame] | 376 | |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 377 | int rt2x00mac_conf_tx(struct ieee80211_hw *hw, int queue_idx, |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 378 | const struct ieee80211_tx_queue_params *params) |
| 379 | { |
| 380 | struct rt2x00_dev *rt2x00dev = hw->priv; |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 381 | struct data_queue *queue; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 382 | |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 383 | queue = rt2x00queue_get_queue(rt2x00dev, queue_idx); |
| 384 | if (unlikely(!queue)) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 385 | return -EINVAL; |
| 386 | |
| 387 | /* |
| 388 | * The passed variables are stored as real value ((2^n)-1). |
| 389 | * Ralink registers require to know the bit number 'n'. |
| 390 | */ |
Ivo van Doorn | 3b3618a | 2008-02-03 15:47:30 +0100 | [diff] [blame] | 391 | if (params->cw_min > 0) |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 392 | queue->cw_min = fls(params->cw_min); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 393 | else |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 394 | queue->cw_min = 5; /* cw_min: 2^5 = 32. */ |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 395 | |
Ivo van Doorn | 3b3618a | 2008-02-03 15:47:30 +0100 | [diff] [blame] | 396 | if (params->cw_max > 0) |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 397 | queue->cw_max = fls(params->cw_max); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 398 | else |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 399 | queue->cw_max = 10; /* cw_min: 2^10 = 1024. */ |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 400 | |
Ivo van Doorn | 3b3618a | 2008-02-03 15:47:30 +0100 | [diff] [blame] | 401 | if (params->aifs >= 0) |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 402 | queue->aifs = params->aifs; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 403 | else |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 404 | queue->aifs = 2; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 405 | |
| 406 | INFO(rt2x00dev, |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 407 | "Configured TX queue %d - CWmin: %d, CWmax: %d, Aifs: %d.\n", |
| 408 | queue_idx, queue->cw_min, queue->cw_max, queue->aifs); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 409 | |
| 410 | return 0; |
| 411 | } |
| 412 | EXPORT_SYMBOL_GPL(rt2x00mac_conf_tx); |