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: rt2x00lib |
| 23 | Abstract: rt2x00 generic device 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 | /* |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 33 | * Radio control handlers. |
| 34 | */ |
| 35 | int rt2x00lib_enable_radio(struct rt2x00_dev *rt2x00dev) |
| 36 | { |
| 37 | int status; |
| 38 | |
| 39 | /* |
| 40 | * Don't enable the radio twice. |
| 41 | * And check if the hardware button has been disabled. |
| 42 | */ |
Ivo van Doorn | 0262ab0 | 2008-08-29 21:04:26 +0200 | [diff] [blame] | 43 | if (test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags) || |
| 44 | test_bit(DEVICE_STATE_DISABLED_RADIO_HW, &rt2x00dev->flags)) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 45 | return 0; |
| 46 | |
| 47 | /* |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 48 | * Initialize all data queues. |
Ivo van Doorn | 837e7f2 | 2008-01-06 23:41:45 +0100 | [diff] [blame] | 49 | */ |
Ivo van Doorn | 798b7ad | 2008-11-08 15:25:33 +0100 | [diff] [blame] | 50 | rt2x00queue_init_queues(rt2x00dev); |
Ivo van Doorn | 837e7f2 | 2008-01-06 23:41:45 +0100 | [diff] [blame] | 51 | |
| 52 | /* |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 53 | * Enable radio. |
| 54 | */ |
Ivo van Doorn | a2e1d52 | 2008-03-31 15:53:44 +0200 | [diff] [blame] | 55 | status = |
| 56 | rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_RADIO_ON); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 57 | if (status) |
| 58 | return status; |
| 59 | |
Ivo van Doorn | 2b08da3 | 2008-06-03 18:58:56 +0200 | [diff] [blame] | 60 | rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_RADIO_IRQ_ON); |
| 61 | |
Ivo van Doorn | a2e1d52 | 2008-03-31 15:53:44 +0200 | [diff] [blame] | 62 | rt2x00leds_led_radio(rt2x00dev, true); |
Ivo van Doorn | 61c2b68 | 2008-04-21 19:01:09 +0200 | [diff] [blame] | 63 | rt2x00led_led_activity(rt2x00dev, true); |
Ivo van Doorn | a2e1d52 | 2008-03-31 15:53:44 +0200 | [diff] [blame] | 64 | |
Ivo van Doorn | 0262ab0 | 2008-08-29 21:04:26 +0200 | [diff] [blame] | 65 | set_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 66 | |
| 67 | /* |
| 68 | * Enable RX. |
| 69 | */ |
Ivo van Doorn | 5cbf830 | 2007-10-06 14:16:09 +0200 | [diff] [blame] | 70 | rt2x00lib_toggle_rx(rt2x00dev, STATE_RADIO_RX_ON); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 71 | |
| 72 | /* |
| 73 | * Start the TX queues. |
| 74 | */ |
Johannes Berg | 36d6825 | 2008-05-15 12:55:26 +0200 | [diff] [blame] | 75 | ieee80211_wake_queues(rt2x00dev->hw); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 76 | |
| 77 | return 0; |
| 78 | } |
| 79 | |
| 80 | void rt2x00lib_disable_radio(struct rt2x00_dev *rt2x00dev) |
| 81 | { |
Ivo van Doorn | 0262ab0 | 2008-08-29 21:04:26 +0200 | [diff] [blame] | 82 | if (!test_and_clear_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags)) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 83 | return; |
| 84 | |
| 85 | /* |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 86 | * Stop the TX queues. |
| 87 | */ |
| 88 | ieee80211_stop_queues(rt2x00dev->hw); |
| 89 | |
| 90 | /* |
| 91 | * Disable RX. |
| 92 | */ |
Ivo van Doorn | 5cbf830 | 2007-10-06 14:16:09 +0200 | [diff] [blame] | 93 | rt2x00lib_toggle_rx(rt2x00dev, STATE_RADIO_RX_OFF); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 94 | |
| 95 | /* |
| 96 | * Disable radio. |
| 97 | */ |
| 98 | rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_RADIO_OFF); |
Ivo van Doorn | 2b08da3 | 2008-06-03 18:58:56 +0200 | [diff] [blame] | 99 | rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_RADIO_IRQ_OFF); |
Ivo van Doorn | 61c2b68 | 2008-04-21 19:01:09 +0200 | [diff] [blame] | 100 | rt2x00led_led_activity(rt2x00dev, false); |
Ivo van Doorn | a2e1d52 | 2008-03-31 15:53:44 +0200 | [diff] [blame] | 101 | rt2x00leds_led_radio(rt2x00dev, false); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Ivo van Doorn | 5cbf830 | 2007-10-06 14:16:09 +0200 | [diff] [blame] | 104 | void rt2x00lib_toggle_rx(struct rt2x00_dev *rt2x00dev, enum dev_state state) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 105 | { |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 106 | /* |
| 107 | * When we are disabling the RX, we should also stop the link tuner. |
| 108 | */ |
Ivo van Doorn | 5cbf830 | 2007-10-06 14:16:09 +0200 | [diff] [blame] | 109 | if (state == STATE_RADIO_RX_OFF) |
Ivo van Doorn | 84e3196 | 2008-12-20 10:53:29 +0100 | [diff] [blame] | 110 | rt2x00link_stop_tuner(rt2x00dev); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 111 | |
| 112 | rt2x00dev->ops->lib->set_device_state(rt2x00dev, state); |
| 113 | |
| 114 | /* |
| 115 | * When we are enabling the RX, we should also start the link tuner. |
| 116 | */ |
Ivo van Doorn | 84e3196 | 2008-12-20 10:53:29 +0100 | [diff] [blame] | 117 | if (state == STATE_RADIO_RX_ON) |
| 118 | rt2x00link_start_tuner(rt2x00dev); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 119 | } |
| 120 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 121 | static void rt2x00lib_packetfilter_scheduled(struct work_struct *work) |
| 122 | { |
| 123 | struct rt2x00_dev *rt2x00dev = |
| 124 | container_of(work, struct rt2x00_dev, filter_work); |
Ivo van Doorn | 5886d0d | 2007-10-06 14:13:38 +0200 | [diff] [blame] | 125 | |
Ivo van Doorn | 133adf0 | 2008-04-04 00:01:43 +0200 | [diff] [blame] | 126 | rt2x00dev->ops->lib->config_filter(rt2x00dev, rt2x00dev->packet_filter); |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 127 | } |
| 128 | |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame] | 129 | static void rt2x00lib_intf_scheduled_iter(void *data, u8 *mac, |
| 130 | struct ieee80211_vif *vif) |
Ivo van Doorn | 5c58ee5 | 2007-10-06 13:34:52 +0200 | [diff] [blame] | 131 | { |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame] | 132 | struct rt2x00_dev *rt2x00dev = data; |
| 133 | struct rt2x00_intf *intf = vif_to_intf(vif); |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame] | 134 | struct ieee80211_bss_conf conf; |
| 135 | int delayed_flags; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 136 | |
| 137 | /* |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame] | 138 | * Copy all data we need during this action under the protection |
| 139 | * of a spinlock. Otherwise race conditions might occur which results |
| 140 | * into an invalid configuration. |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 141 | */ |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame] | 142 | spin_lock(&intf->lock); |
| 143 | |
Ivo van Doorn | c3fd7b4 | 2008-10-29 17:18:22 +0100 | [diff] [blame] | 144 | memcpy(&conf, &vif->bss_conf, sizeof(conf)); |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame] | 145 | delayed_flags = intf->delayed_flags; |
| 146 | intf->delayed_flags = 0; |
| 147 | |
| 148 | spin_unlock(&intf->lock); |
| 149 | |
Ivo van Doorn | 980dfcb | 2008-06-25 21:27:00 +0200 | [diff] [blame] | 150 | /* |
| 151 | * It is possible the radio was disabled while the work had been |
| 152 | * scheduled. If that happens we should return here immediately, |
| 153 | * note that in the spinlock protected area above the delayed_flags |
| 154 | * have been cleared correctly. |
| 155 | */ |
Ivo van Doorn | 0262ab0 | 2008-08-29 21:04:26 +0200 | [diff] [blame] | 156 | if (!test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags)) |
Ivo van Doorn | 980dfcb | 2008-06-25 21:27:00 +0200 | [diff] [blame] | 157 | return; |
| 158 | |
Ivo van Doorn | bd88a78 | 2008-07-09 15:12:44 +0200 | [diff] [blame] | 159 | if (delayed_flags & DELAYED_UPDATE_BEACON) |
| 160 | rt2x00queue_update_beacon(rt2x00dev, vif); |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame] | 161 | |
Ivo van Doorn | 7281037 | 2008-03-09 22:46:18 +0100 | [diff] [blame] | 162 | if (delayed_flags & DELAYED_CONFIG_ERP) |
Ivo van Doorn | 980dfcb | 2008-06-25 21:27:00 +0200 | [diff] [blame] | 163 | rt2x00lib_config_erp(rt2x00dev, intf, &conf); |
Ivo van Doorn | a2e1d52 | 2008-03-31 15:53:44 +0200 | [diff] [blame] | 164 | |
| 165 | if (delayed_flags & DELAYED_LED_ASSOC) |
| 166 | rt2x00leds_led_assoc(rt2x00dev, !!rt2x00dev->intf_associated); |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | static void rt2x00lib_intf_scheduled(struct work_struct *work) |
| 170 | { |
| 171 | struct rt2x00_dev *rt2x00dev = |
| 172 | container_of(work, struct rt2x00_dev, intf_work); |
| 173 | |
| 174 | /* |
| 175 | * Iterate over each interface and perform the |
| 176 | * requested configurations. |
| 177 | */ |
| 178 | ieee80211_iterate_active_interfaces(rt2x00dev->hw, |
| 179 | rt2x00lib_intf_scheduled_iter, |
| 180 | rt2x00dev); |
Ivo van Doorn | 5c58ee5 | 2007-10-06 13:34:52 +0200 | [diff] [blame] | 181 | } |
| 182 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 183 | /* |
| 184 | * Interrupt context handlers. |
| 185 | */ |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame] | 186 | static void rt2x00lib_beacondone_iter(void *data, u8 *mac, |
| 187 | struct ieee80211_vif *vif) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 188 | { |
Gertjan van Wingerde | c4da004 | 2008-06-16 19:56:31 +0200 | [diff] [blame] | 189 | struct rt2x00_dev *rt2x00dev = data; |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame] | 190 | struct rt2x00_intf *intf = vif_to_intf(vif); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 191 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 192 | if (vif->type != NL80211_IFTYPE_AP && |
Andrey Yurovsky | a07dbea | 2008-12-20 10:55:34 +0100 | [diff] [blame^] | 193 | vif->type != NL80211_IFTYPE_ADHOC && |
| 194 | vif->type != NL80211_IFTYPE_MESH_POINT) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 195 | return; |
| 196 | |
Gertjan van Wingerde | c95edf5 | 2008-06-16 19:55:18 +0200 | [diff] [blame] | 197 | /* |
| 198 | * Clean up the beacon skb. |
| 199 | */ |
Gertjan van Wingerde | c4da004 | 2008-06-16 19:56:31 +0200 | [diff] [blame] | 200 | rt2x00queue_free_skb(rt2x00dev, intf->beacon->skb); |
Gertjan van Wingerde | c95edf5 | 2008-06-16 19:55:18 +0200 | [diff] [blame] | 201 | intf->beacon->skb = NULL; |
| 202 | |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame] | 203 | spin_lock(&intf->lock); |
| 204 | intf->delayed_flags |= DELAYED_UPDATE_BEACON; |
| 205 | spin_unlock(&intf->lock); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | void rt2x00lib_beacondone(struct rt2x00_dev *rt2x00dev) |
| 209 | { |
Ivo van Doorn | 0262ab0 | 2008-08-29 21:04:26 +0200 | [diff] [blame] | 210 | if (!test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags)) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 211 | return; |
| 212 | |
Ivo van Doorn | 633257d | 2008-05-23 18:14:02 +0200 | [diff] [blame] | 213 | ieee80211_iterate_active_interfaces_atomic(rt2x00dev->hw, |
| 214 | rt2x00lib_beacondone_iter, |
| 215 | rt2x00dev); |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame] | 216 | |
Ivo van Doorn | 8e260c2 | 2008-07-04 13:41:31 +0200 | [diff] [blame] | 217 | schedule_work(&rt2x00dev->intf_work); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 218 | } |
| 219 | EXPORT_SYMBOL_GPL(rt2x00lib_beacondone); |
| 220 | |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 221 | void rt2x00lib_txdone(struct queue_entry *entry, |
| 222 | struct txdone_entry_desc *txdesc) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 223 | { |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 224 | struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 225 | struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(entry->skb); |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 226 | struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb); |
Ivo van Doorn | d74f5ba | 2008-06-16 19:56:54 +0200 | [diff] [blame] | 227 | enum data_queue_qid qid = skb_get_queue_mapping(entry->skb); |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 228 | u8 rate_idx, rate_flags; |
Ivo van Doorn | d74f5ba | 2008-06-16 19:56:54 +0200 | [diff] [blame] | 229 | |
| 230 | /* |
| 231 | * Unmap the skb. |
| 232 | */ |
| 233 | rt2x00queue_unmap_skb(rt2x00dev, entry->skb); |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 234 | |
| 235 | /* |
Ivo van Doorn | 2bb057d | 2008-08-04 16:37:44 +0200 | [diff] [blame] | 236 | * If the IV/EIV data was stripped from the frame before it was |
| 237 | * passed to the hardware, we should now reinsert it again because |
| 238 | * mac80211 will expect the the same data to be present it the |
| 239 | * frame as it was passed to us. |
| 240 | */ |
| 241 | if (test_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags)) |
| 242 | rt2x00crypto_tx_insert_iv(entry->skb); |
| 243 | |
| 244 | /* |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 245 | * Send frame to debugfs immediately, after this call is completed |
| 246 | * we are going to overwrite the skb->cb array. |
| 247 | */ |
| 248 | rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_TXDONE, entry->skb); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 249 | |
| 250 | /* |
| 251 | * Update TX statistics. |
| 252 | */ |
Ivo van Doorn | fb55f4d | 2008-05-10 13:42:06 +0200 | [diff] [blame] | 253 | rt2x00dev->link.qual.tx_success += |
| 254 | test_bit(TXDONE_SUCCESS, &txdesc->flags); |
| 255 | rt2x00dev->link.qual.tx_failed += |
John W. Linville | cb14cb7 | 2008-06-10 09:06:52 -0400 | [diff] [blame] | 256 | test_bit(TXDONE_FAILURE, &txdesc->flags); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 257 | |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 258 | rate_idx = skbdesc->tx_rate_idx; |
| 259 | rate_flags = skbdesc->tx_rate_flags; |
| 260 | |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 261 | /* |
| 262 | * Initialize TX status |
| 263 | */ |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 264 | memset(&tx_info->status, 0, sizeof(tx_info->status)); |
| 265 | tx_info->status.ack_signal = 0; |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 266 | tx_info->status.rates[0].idx = rate_idx; |
| 267 | tx_info->status.rates[0].flags = rate_flags; |
| 268 | tx_info->status.rates[0].count = txdesc->retry + 1; |
| 269 | tx_info->status.rates[1].idx = -1; /* terminate */ |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 270 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 271 | if (!(tx_info->flags & IEEE80211_TX_CTL_NO_ACK)) { |
Ivo van Doorn | fb55f4d | 2008-05-10 13:42:06 +0200 | [diff] [blame] | 272 | if (test_bit(TXDONE_SUCCESS, &txdesc->flags)) |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 273 | tx_info->flags |= IEEE80211_TX_STAT_ACK; |
Ivo van Doorn | fb55f4d | 2008-05-10 13:42:06 +0200 | [diff] [blame] | 274 | else if (test_bit(TXDONE_FAILURE, &txdesc->flags)) |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 275 | rt2x00dev->low_level_stats.dot11ACKFailureCount++; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 276 | } |
| 277 | |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 278 | if (rate_flags & IEEE80211_TX_RC_USE_RTS_CTS) { |
Ivo van Doorn | fb55f4d | 2008-05-10 13:42:06 +0200 | [diff] [blame] | 279 | if (test_bit(TXDONE_SUCCESS, &txdesc->flags)) |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 280 | rt2x00dev->low_level_stats.dot11RTSSuccessCount++; |
Ivo van Doorn | fb55f4d | 2008-05-10 13:42:06 +0200 | [diff] [blame] | 281 | else if (test_bit(TXDONE_FAILURE, &txdesc->flags)) |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 282 | rt2x00dev->low_level_stats.dot11RTSFailureCount++; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | /* |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 286 | * Only send the status report to mac80211 when TX status was |
| 287 | * requested by it. If this was a extra frame coming through |
| 288 | * a mac80211 library call (RTS/CTS) then we should not send the |
| 289 | * status report back. |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 290 | */ |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 291 | if (tx_info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS) |
| 292 | ieee80211_tx_status_irqsafe(rt2x00dev->hw, entry->skb); |
Ivo van Doorn | baf26a7 | 2008-02-17 17:32:08 +0100 | [diff] [blame] | 293 | else |
Ivo van Doorn | fb55f4d | 2008-05-10 13:42:06 +0200 | [diff] [blame] | 294 | dev_kfree_skb_irq(entry->skb); |
Ivo van Doorn | d74f5ba | 2008-06-16 19:56:54 +0200 | [diff] [blame] | 295 | |
| 296 | /* |
| 297 | * Make this entry available for reuse. |
| 298 | */ |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 299 | entry->skb = NULL; |
Ivo van Doorn | d74f5ba | 2008-06-16 19:56:54 +0200 | [diff] [blame] | 300 | entry->flags = 0; |
| 301 | |
Ivo van Doorn | 798b7ad | 2008-11-08 15:25:33 +0100 | [diff] [blame] | 302 | rt2x00dev->ops->lib->clear_entry(entry); |
Ivo van Doorn | d74f5ba | 2008-06-16 19:56:54 +0200 | [diff] [blame] | 303 | |
Ivo van Doorn | 0262ab0 | 2008-08-29 21:04:26 +0200 | [diff] [blame] | 304 | clear_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags); |
Ivo van Doorn | d74f5ba | 2008-06-16 19:56:54 +0200 | [diff] [blame] | 305 | rt2x00queue_index_inc(entry->queue, Q_INDEX_DONE); |
| 306 | |
| 307 | /* |
| 308 | * If the data queue was below the threshold before the txdone |
| 309 | * handler we must make sure the packet queue in the mac80211 stack |
| 310 | * is reenabled when the txdone handler has finished. |
| 311 | */ |
| 312 | if (!rt2x00queue_threshold(entry->queue)) |
| 313 | ieee80211_wake_queue(rt2x00dev->hw, qid); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 314 | } |
| 315 | EXPORT_SYMBOL_GPL(rt2x00lib_txdone); |
| 316 | |
Gertjan van Wingerde | c4da004 | 2008-06-16 19:56:31 +0200 | [diff] [blame] | 317 | void rt2x00lib_rxdone(struct rt2x00_dev *rt2x00dev, |
| 318 | struct queue_entry *entry) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 319 | { |
Gertjan van Wingerde | c4da004 | 2008-06-16 19:56:31 +0200 | [diff] [blame] | 320 | struct rxdone_entry_desc rxdesc; |
| 321 | struct sk_buff *skb; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 322 | struct ieee80211_rx_status *rx_status = &rt2x00dev->rx_status; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 323 | struct ieee80211_supported_band *sband; |
Ivo van Doorn | 70e2fed | 2008-02-03 15:50:40 +0100 | [diff] [blame] | 324 | const struct rt2x00_rate *rate; |
Ivo van Doorn | 2bb057d | 2008-08-04 16:37:44 +0200 | [diff] [blame] | 325 | unsigned int header_length; |
Gertjan van Wingerde | 239c249 | 2008-06-06 22:54:12 +0200 | [diff] [blame] | 326 | unsigned int align; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 327 | unsigned int i; |
Ivo van Doorn | 70e2fed | 2008-02-03 15:50:40 +0100 | [diff] [blame] | 328 | int idx = -1; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 329 | |
| 330 | /* |
Gertjan van Wingerde | c4da004 | 2008-06-16 19:56:31 +0200 | [diff] [blame] | 331 | * Allocate a new sk_buffer. If no new buffer available, drop the |
| 332 | * received frame and reuse the existing buffer. |
| 333 | */ |
| 334 | skb = rt2x00queue_alloc_rxskb(rt2x00dev, entry); |
| 335 | if (!skb) |
| 336 | return; |
| 337 | |
| 338 | /* |
| 339 | * Unmap the skb. |
| 340 | */ |
| 341 | rt2x00queue_unmap_skb(rt2x00dev, entry->skb); |
| 342 | |
| 343 | /* |
| 344 | * Extract the RXD details. |
| 345 | */ |
| 346 | memset(&rxdesc, 0, sizeof(rxdesc)); |
| 347 | rt2x00dev->ops->lib->fill_rxdone(entry, &rxdesc); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 348 | |
| 349 | /* |
Gertjan van Wingerde | 239c249 | 2008-06-06 22:54:12 +0200 | [diff] [blame] | 350 | * The data behind the ieee80211 header must be |
Gertjan van Wingerde | a9f853d | 2008-06-07 16:57:09 +0200 | [diff] [blame] | 351 | * aligned on a 4 byte boundary. |
Gertjan van Wingerde | 239c249 | 2008-06-06 22:54:12 +0200 | [diff] [blame] | 352 | */ |
Ivo van Doorn | 2bb057d | 2008-08-04 16:37:44 +0200 | [diff] [blame] | 353 | header_length = ieee80211_get_hdrlen_from_skb(entry->skb); |
| 354 | align = ((unsigned long)(entry->skb->data + header_length)) & 3; |
Gertjan van Wingerde | 239c249 | 2008-06-06 22:54:12 +0200 | [diff] [blame] | 355 | |
Ivo van Doorn | 2bb057d | 2008-08-04 16:37:44 +0200 | [diff] [blame] | 356 | /* |
| 357 | * Hardware might have stripped the IV/EIV/ICV data, |
| 358 | * in that case it is possible that the data was |
| 359 | * provided seperately (through hardware descriptor) |
| 360 | * in which case we should reinsert the data into the frame. |
| 361 | */ |
Ivo van Doorn | 74415ed | 2008-12-02 22:50:33 +0100 | [diff] [blame] | 362 | if ((rxdesc.dev_flags & RXDONE_CRYPTO_IV) && |
| 363 | (rxdesc.flags & RX_FLAG_IV_STRIPPED)) { |
Ivo van Doorn | 2bb057d | 2008-08-04 16:37:44 +0200 | [diff] [blame] | 364 | rt2x00crypto_rx_insert_iv(entry->skb, align, |
| 365 | header_length, &rxdesc); |
| 366 | } else if (align) { |
Gertjan van Wingerde | 239c249 | 2008-06-06 22:54:12 +0200 | [diff] [blame] | 367 | skb_push(entry->skb, align); |
| 368 | /* Move entire frame in 1 command */ |
| 369 | memmove(entry->skb->data, entry->skb->data + align, |
Gertjan van Wingerde | c4da004 | 2008-06-16 19:56:31 +0200 | [diff] [blame] | 370 | rxdesc.size); |
Gertjan van Wingerde | 239c249 | 2008-06-06 22:54:12 +0200 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | /* Update data pointers, trim buffer to correct size */ |
Gertjan van Wingerde | c4da004 | 2008-06-16 19:56:31 +0200 | [diff] [blame] | 374 | skb_trim(entry->skb, rxdesc.size); |
Gertjan van Wingerde | 239c249 | 2008-06-06 22:54:12 +0200 | [diff] [blame] | 375 | |
| 376 | /* |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 377 | * Update RX statistics. |
| 378 | */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 379 | sband = &rt2x00dev->bands[rt2x00dev->curr_band]; |
| 380 | for (i = 0; i < sband->n_bitrates; i++) { |
Ivo van Doorn | 70e2fed | 2008-02-03 15:50:40 +0100 | [diff] [blame] | 381 | rate = rt2x00_get_rate(sband->bitrates[i].hw_value); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 382 | |
Gertjan van Wingerde | c4da004 | 2008-06-16 19:56:31 +0200 | [diff] [blame] | 383 | if (((rxdesc.dev_flags & RXDONE_SIGNAL_PLCP) && |
| 384 | (rate->plcp == rxdesc.signal)) || |
Ivo van Doorn | 6c6aa3c | 2008-08-29 21:07:16 +0200 | [diff] [blame] | 385 | ((rxdesc.dev_flags & RXDONE_SIGNAL_BITRATE) && |
Gertjan van Wingerde | c4da004 | 2008-06-16 19:56:31 +0200 | [diff] [blame] | 386 | (rate->bitrate == rxdesc.signal))) { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 387 | idx = i; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 388 | break; |
| 389 | } |
| 390 | } |
| 391 | |
Ivo van Doorn | 866a050 | 2008-03-25 14:12:45 +0100 | [diff] [blame] | 392 | if (idx < 0) { |
| 393 | WARNING(rt2x00dev, "Frame received with unrecognized signal," |
Gertjan van Wingerde | c4da004 | 2008-06-16 19:56:31 +0200 | [diff] [blame] | 394 | "signal=0x%.2x, plcp=%d.\n", rxdesc.signal, |
| 395 | !!(rxdesc.dev_flags & RXDONE_SIGNAL_PLCP)); |
Ivo van Doorn | 866a050 | 2008-03-25 14:12:45 +0100 | [diff] [blame] | 396 | idx = 0; |
| 397 | } |
| 398 | |
Mattias Nissler | 61af43c | 2007-11-27 21:50:26 +0100 | [diff] [blame] | 399 | /* |
Ivo van Doorn | 84e3196 | 2008-12-20 10:53:29 +0100 | [diff] [blame] | 400 | * Update extra components |
Mattias Nissler | 61af43c | 2007-11-27 21:50:26 +0100 | [diff] [blame] | 401 | */ |
Ivo van Doorn | 84e3196 | 2008-12-20 10:53:29 +0100 | [diff] [blame] | 402 | rt2x00link_update_stats(rt2x00dev, entry->skb, &rxdesc); |
| 403 | rt2x00debug_update_crypto(rt2x00dev, &rxdesc); |
Ivo van Doorn | 69f81a2 | 2007-10-13 16:26:36 +0200 | [diff] [blame] | 404 | |
Ivo van Doorn | ae73e58 | 2008-07-04 16:14:59 +0200 | [diff] [blame] | 405 | rx_status->mactime = rxdesc.timestamp; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 406 | rx_status->rate_idx = idx; |
Ivo van Doorn | 84e3196 | 2008-12-20 10:53:29 +0100 | [diff] [blame] | 407 | rx_status->qual = rt2x00link_calculate_signal(rt2x00dev, rxdesc.rssi); |
Gertjan van Wingerde | c4da004 | 2008-06-16 19:56:31 +0200 | [diff] [blame] | 408 | rx_status->signal = rxdesc.rssi; |
| 409 | rx_status->flag = rxdesc.flags; |
Ivo van Doorn | 69f81a2 | 2007-10-13 16:26:36 +0200 | [diff] [blame] | 410 | rx_status->antenna = rt2x00dev->link.ant.active.rx; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 411 | |
| 412 | /* |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 413 | * Send frame to mac80211 & debugfs. |
| 414 | * mac80211 will clean up the skb structure. |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 415 | */ |
Ivo van Doorn | 5a6e599 | 2008-05-10 13:41:32 +0200 | [diff] [blame] | 416 | rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_RXDONE, entry->skb); |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 417 | ieee80211_rx_irqsafe(rt2x00dev->hw, entry->skb, rx_status); |
Gertjan van Wingerde | c4da004 | 2008-06-16 19:56:31 +0200 | [diff] [blame] | 418 | |
| 419 | /* |
| 420 | * Replace the skb with the freshly allocated one. |
| 421 | */ |
| 422 | entry->skb = skb; |
Ivo van Doorn | d74f5ba | 2008-06-16 19:56:54 +0200 | [diff] [blame] | 423 | entry->flags = 0; |
| 424 | |
Ivo van Doorn | 798b7ad | 2008-11-08 15:25:33 +0100 | [diff] [blame] | 425 | rt2x00dev->ops->lib->clear_entry(entry); |
Ivo van Doorn | d74f5ba | 2008-06-16 19:56:54 +0200 | [diff] [blame] | 426 | |
| 427 | rt2x00queue_index_inc(entry->queue, Q_INDEX); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 428 | } |
| 429 | EXPORT_SYMBOL_GPL(rt2x00lib_rxdone); |
| 430 | |
| 431 | /* |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 432 | * Driver initialization handlers. |
| 433 | */ |
Ivo van Doorn | 70e2fed | 2008-02-03 15:50:40 +0100 | [diff] [blame] | 434 | const struct rt2x00_rate rt2x00_supported_rates[12] = { |
| 435 | { |
Ivo van Doorn | 3d8606a | 2008-11-02 00:36:40 +0100 | [diff] [blame] | 436 | .flags = DEV_RATE_CCK, |
Ivo van Doorn | 70e2fed | 2008-02-03 15:50:40 +0100 | [diff] [blame] | 437 | .bitrate = 10, |
Ivo van Doorn | aa77672 | 2008-03-09 22:48:08 +0100 | [diff] [blame] | 438 | .ratemask = BIT(0), |
Ivo van Doorn | 70e2fed | 2008-02-03 15:50:40 +0100 | [diff] [blame] | 439 | .plcp = 0x00, |
| 440 | }, |
| 441 | { |
Ivo van Doorn | 3d8606a | 2008-11-02 00:36:40 +0100 | [diff] [blame] | 442 | .flags = DEV_RATE_CCK | DEV_RATE_SHORT_PREAMBLE, |
Ivo van Doorn | 70e2fed | 2008-02-03 15:50:40 +0100 | [diff] [blame] | 443 | .bitrate = 20, |
Ivo van Doorn | aa77672 | 2008-03-09 22:48:08 +0100 | [diff] [blame] | 444 | .ratemask = BIT(1), |
Ivo van Doorn | 70e2fed | 2008-02-03 15:50:40 +0100 | [diff] [blame] | 445 | .plcp = 0x01, |
| 446 | }, |
| 447 | { |
Ivo van Doorn | 3d8606a | 2008-11-02 00:36:40 +0100 | [diff] [blame] | 448 | .flags = DEV_RATE_CCK | DEV_RATE_SHORT_PREAMBLE, |
Ivo van Doorn | 70e2fed | 2008-02-03 15:50:40 +0100 | [diff] [blame] | 449 | .bitrate = 55, |
Ivo van Doorn | aa77672 | 2008-03-09 22:48:08 +0100 | [diff] [blame] | 450 | .ratemask = BIT(2), |
Ivo van Doorn | 70e2fed | 2008-02-03 15:50:40 +0100 | [diff] [blame] | 451 | .plcp = 0x02, |
| 452 | }, |
| 453 | { |
Ivo van Doorn | 3d8606a | 2008-11-02 00:36:40 +0100 | [diff] [blame] | 454 | .flags = DEV_RATE_CCK | DEV_RATE_SHORT_PREAMBLE, |
Ivo van Doorn | 70e2fed | 2008-02-03 15:50:40 +0100 | [diff] [blame] | 455 | .bitrate = 110, |
Ivo van Doorn | aa77672 | 2008-03-09 22:48:08 +0100 | [diff] [blame] | 456 | .ratemask = BIT(3), |
Ivo van Doorn | 70e2fed | 2008-02-03 15:50:40 +0100 | [diff] [blame] | 457 | .plcp = 0x03, |
| 458 | }, |
| 459 | { |
Ivo van Doorn | 3d8606a | 2008-11-02 00:36:40 +0100 | [diff] [blame] | 460 | .flags = DEV_RATE_OFDM, |
Ivo van Doorn | 70e2fed | 2008-02-03 15:50:40 +0100 | [diff] [blame] | 461 | .bitrate = 60, |
Ivo van Doorn | aa77672 | 2008-03-09 22:48:08 +0100 | [diff] [blame] | 462 | .ratemask = BIT(4), |
Ivo van Doorn | 70e2fed | 2008-02-03 15:50:40 +0100 | [diff] [blame] | 463 | .plcp = 0x0b, |
| 464 | }, |
| 465 | { |
| 466 | .flags = DEV_RATE_OFDM, |
| 467 | .bitrate = 90, |
Ivo van Doorn | aa77672 | 2008-03-09 22:48:08 +0100 | [diff] [blame] | 468 | .ratemask = BIT(5), |
Ivo van Doorn | 70e2fed | 2008-02-03 15:50:40 +0100 | [diff] [blame] | 469 | .plcp = 0x0f, |
| 470 | }, |
| 471 | { |
Ivo van Doorn | 3d8606a | 2008-11-02 00:36:40 +0100 | [diff] [blame] | 472 | .flags = DEV_RATE_OFDM, |
Ivo van Doorn | 70e2fed | 2008-02-03 15:50:40 +0100 | [diff] [blame] | 473 | .bitrate = 120, |
Ivo van Doorn | aa77672 | 2008-03-09 22:48:08 +0100 | [diff] [blame] | 474 | .ratemask = BIT(6), |
Ivo van Doorn | 70e2fed | 2008-02-03 15:50:40 +0100 | [diff] [blame] | 475 | .plcp = 0x0a, |
| 476 | }, |
| 477 | { |
| 478 | .flags = DEV_RATE_OFDM, |
| 479 | .bitrate = 180, |
Ivo van Doorn | aa77672 | 2008-03-09 22:48:08 +0100 | [diff] [blame] | 480 | .ratemask = BIT(7), |
Ivo van Doorn | 70e2fed | 2008-02-03 15:50:40 +0100 | [diff] [blame] | 481 | .plcp = 0x0e, |
| 482 | }, |
| 483 | { |
Ivo van Doorn | 3d8606a | 2008-11-02 00:36:40 +0100 | [diff] [blame] | 484 | .flags = DEV_RATE_OFDM, |
Ivo van Doorn | 70e2fed | 2008-02-03 15:50:40 +0100 | [diff] [blame] | 485 | .bitrate = 240, |
Ivo van Doorn | aa77672 | 2008-03-09 22:48:08 +0100 | [diff] [blame] | 486 | .ratemask = BIT(8), |
Ivo van Doorn | 70e2fed | 2008-02-03 15:50:40 +0100 | [diff] [blame] | 487 | .plcp = 0x09, |
| 488 | }, |
| 489 | { |
| 490 | .flags = DEV_RATE_OFDM, |
| 491 | .bitrate = 360, |
Ivo van Doorn | aa77672 | 2008-03-09 22:48:08 +0100 | [diff] [blame] | 492 | .ratemask = BIT(9), |
Ivo van Doorn | 70e2fed | 2008-02-03 15:50:40 +0100 | [diff] [blame] | 493 | .plcp = 0x0d, |
| 494 | }, |
| 495 | { |
| 496 | .flags = DEV_RATE_OFDM, |
| 497 | .bitrate = 480, |
Ivo van Doorn | aa77672 | 2008-03-09 22:48:08 +0100 | [diff] [blame] | 498 | .ratemask = BIT(10), |
Ivo van Doorn | 70e2fed | 2008-02-03 15:50:40 +0100 | [diff] [blame] | 499 | .plcp = 0x08, |
| 500 | }, |
| 501 | { |
| 502 | .flags = DEV_RATE_OFDM, |
| 503 | .bitrate = 540, |
Ivo van Doorn | aa77672 | 2008-03-09 22:48:08 +0100 | [diff] [blame] | 504 | .ratemask = BIT(11), |
Ivo van Doorn | 70e2fed | 2008-02-03 15:50:40 +0100 | [diff] [blame] | 505 | .plcp = 0x0c, |
| 506 | }, |
| 507 | }; |
| 508 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 509 | static void rt2x00lib_channel(struct ieee80211_channel *entry, |
| 510 | const int channel, const int tx_power, |
| 511 | const int value) |
| 512 | { |
Ivo van Doorn | f2a3c7f | 2008-02-03 15:52:45 +0100 | [diff] [blame] | 513 | entry->center_freq = ieee80211_channel_to_frequency(channel); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 514 | entry->hw_value = value; |
| 515 | entry->max_power = tx_power; |
| 516 | entry->max_antenna_gain = 0xff; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | static void rt2x00lib_rate(struct ieee80211_rate *entry, |
Ivo van Doorn | 70e2fed | 2008-02-03 15:50:40 +0100 | [diff] [blame] | 520 | const u16 index, const struct rt2x00_rate *rate) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 521 | { |
Ivo van Doorn | 70e2fed | 2008-02-03 15:50:40 +0100 | [diff] [blame] | 522 | entry->flags = 0; |
| 523 | entry->bitrate = rate->bitrate; |
Ivo van Doorn | 3ea9646 | 2009-01-04 17:33:25 +0100 | [diff] [blame] | 524 | entry->hw_value =index; |
| 525 | entry->hw_value_short = index; |
Ivo van Doorn | 70e2fed | 2008-02-03 15:50:40 +0100 | [diff] [blame] | 526 | |
Ivo van Doorn | 3ea9646 | 2009-01-04 17:33:25 +0100 | [diff] [blame] | 527 | if (rate->flags & DEV_RATE_SHORT_PREAMBLE) |
Ivo van Doorn | 70e2fed | 2008-02-03 15:50:40 +0100 | [diff] [blame] | 528 | entry->flags |= IEEE80211_RATE_SHORT_PREAMBLE; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | static int rt2x00lib_probe_hw_modes(struct rt2x00_dev *rt2x00dev, |
| 532 | struct hw_mode_spec *spec) |
| 533 | { |
| 534 | struct ieee80211_hw *hw = rt2x00dev->hw; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 535 | struct ieee80211_channel *channels; |
| 536 | struct ieee80211_rate *rates; |
Ivo van Doorn | 31562e8 | 2008-02-17 17:35:05 +0100 | [diff] [blame] | 537 | unsigned int num_rates; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 538 | unsigned int i; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 539 | |
Ivo van Doorn | 31562e8 | 2008-02-17 17:35:05 +0100 | [diff] [blame] | 540 | num_rates = 0; |
| 541 | if (spec->supported_rates & SUPPORT_RATE_CCK) |
| 542 | num_rates += 4; |
| 543 | if (spec->supported_rates & SUPPORT_RATE_OFDM) |
| 544 | num_rates += 8; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 545 | |
| 546 | channels = kzalloc(sizeof(*channels) * spec->num_channels, GFP_KERNEL); |
| 547 | if (!channels) |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 548 | return -ENOMEM; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 549 | |
Ivo van Doorn | 31562e8 | 2008-02-17 17:35:05 +0100 | [diff] [blame] | 550 | rates = kzalloc(sizeof(*rates) * num_rates, GFP_KERNEL); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 551 | if (!rates) |
| 552 | goto exit_free_channels; |
| 553 | |
| 554 | /* |
| 555 | * Initialize Rate list. |
| 556 | */ |
Ivo van Doorn | 31562e8 | 2008-02-17 17:35:05 +0100 | [diff] [blame] | 557 | for (i = 0; i < num_rates; i++) |
Ivo van Doorn | 8f5fa7f | 2008-02-03 15:54:34 +0100 | [diff] [blame] | 558 | rt2x00lib_rate(&rates[i], i, rt2x00_get_rate(i)); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 559 | |
| 560 | /* |
| 561 | * Initialize Channel list. |
| 562 | */ |
| 563 | for (i = 0; i < spec->num_channels; i++) { |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 564 | rt2x00lib_channel(&channels[i], |
Ivo van Doorn | 8c5e7a5 | 2008-08-04 16:38:47 +0200 | [diff] [blame] | 565 | spec->channels[i].channel, |
| 566 | spec->channels_info[i].tx_power1, i); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | /* |
Ivo van Doorn | 31562e8 | 2008-02-17 17:35:05 +0100 | [diff] [blame] | 570 | * Intitialize 802.11b, 802.11g |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 571 | * Rates: CCK, OFDM. |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 572 | * Channels: 2.4 GHz |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 573 | */ |
Gertjan van Wingerde | 47ac268 | 2008-02-17 17:35:55 +0100 | [diff] [blame] | 574 | if (spec->supported_bands & SUPPORT_BAND_2GHZ) { |
Ivo van Doorn | 31562e8 | 2008-02-17 17:35:05 +0100 | [diff] [blame] | 575 | rt2x00dev->bands[IEEE80211_BAND_2GHZ].n_channels = 14; |
| 576 | rt2x00dev->bands[IEEE80211_BAND_2GHZ].n_bitrates = num_rates; |
| 577 | rt2x00dev->bands[IEEE80211_BAND_2GHZ].channels = channels; |
| 578 | rt2x00dev->bands[IEEE80211_BAND_2GHZ].bitrates = rates; |
| 579 | hw->wiphy->bands[IEEE80211_BAND_2GHZ] = |
| 580 | &rt2x00dev->bands[IEEE80211_BAND_2GHZ]; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | /* |
| 584 | * Intitialize 802.11a |
| 585 | * Rates: OFDM. |
| 586 | * Channels: OFDM, UNII, HiperLAN2. |
| 587 | */ |
Gertjan van Wingerde | 47ac268 | 2008-02-17 17:35:55 +0100 | [diff] [blame] | 588 | if (spec->supported_bands & SUPPORT_BAND_5GHZ) { |
Ivo van Doorn | 31562e8 | 2008-02-17 17:35:05 +0100 | [diff] [blame] | 589 | rt2x00dev->bands[IEEE80211_BAND_5GHZ].n_channels = |
| 590 | spec->num_channels - 14; |
| 591 | rt2x00dev->bands[IEEE80211_BAND_5GHZ].n_bitrates = |
| 592 | num_rates - 4; |
| 593 | rt2x00dev->bands[IEEE80211_BAND_5GHZ].channels = &channels[14]; |
| 594 | rt2x00dev->bands[IEEE80211_BAND_5GHZ].bitrates = &rates[4]; |
| 595 | hw->wiphy->bands[IEEE80211_BAND_5GHZ] = |
| 596 | &rt2x00dev->bands[IEEE80211_BAND_5GHZ]; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 597 | } |
| 598 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 599 | return 0; |
| 600 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 601 | exit_free_channels: |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 602 | kfree(channels); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 603 | ERROR(rt2x00dev, "Allocation ieee80211 modes failed.\n"); |
| 604 | return -ENOMEM; |
| 605 | } |
| 606 | |
| 607 | static void rt2x00lib_remove_hw(struct rt2x00_dev *rt2x00dev) |
| 608 | { |
Ivo van Doorn | 0262ab0 | 2008-08-29 21:04:26 +0200 | [diff] [blame] | 609 | if (test_bit(DEVICE_STATE_REGISTERED_HW, &rt2x00dev->flags)) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 610 | ieee80211_unregister_hw(rt2x00dev->hw); |
| 611 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 612 | if (likely(rt2x00dev->hw->wiphy->bands[IEEE80211_BAND_2GHZ])) { |
| 613 | kfree(rt2x00dev->hw->wiphy->bands[IEEE80211_BAND_2GHZ]->channels); |
| 614 | kfree(rt2x00dev->hw->wiphy->bands[IEEE80211_BAND_2GHZ]->bitrates); |
| 615 | rt2x00dev->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = NULL; |
| 616 | rt2x00dev->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = NULL; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 617 | } |
Ivo van Doorn | 8c5e7a5 | 2008-08-04 16:38:47 +0200 | [diff] [blame] | 618 | |
| 619 | kfree(rt2x00dev->spec.channels_info); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | static int rt2x00lib_probe_hw(struct rt2x00_dev *rt2x00dev) |
| 623 | { |
| 624 | struct hw_mode_spec *spec = &rt2x00dev->spec; |
| 625 | int status; |
| 626 | |
Ivo van Doorn | 0262ab0 | 2008-08-29 21:04:26 +0200 | [diff] [blame] | 627 | if (test_bit(DEVICE_STATE_REGISTERED_HW, &rt2x00dev->flags)) |
| 628 | return 0; |
| 629 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 630 | /* |
| 631 | * Initialize HW modes. |
| 632 | */ |
| 633 | status = rt2x00lib_probe_hw_modes(rt2x00dev, spec); |
| 634 | if (status) |
| 635 | return status; |
| 636 | |
| 637 | /* |
Gertjan van Wingerde | 61448f8 | 2008-05-10 13:43:33 +0200 | [diff] [blame] | 638 | * Initialize HW fields. |
| 639 | */ |
| 640 | rt2x00dev->hw->queues = rt2x00dev->ops->tx_queues; |
| 641 | |
| 642 | /* |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 643 | * Register HW. |
| 644 | */ |
| 645 | status = ieee80211_register_hw(rt2x00dev->hw); |
| 646 | if (status) { |
| 647 | rt2x00lib_remove_hw(rt2x00dev); |
| 648 | return status; |
| 649 | } |
| 650 | |
Ivo van Doorn | 0262ab0 | 2008-08-29 21:04:26 +0200 | [diff] [blame] | 651 | set_bit(DEVICE_STATE_REGISTERED_HW, &rt2x00dev->flags); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 652 | |
| 653 | return 0; |
| 654 | } |
| 655 | |
| 656 | /* |
| 657 | * Initialization/uninitialization handlers. |
| 658 | */ |
Ivo van Doorn | e37ea21 | 2008-01-06 23:40:07 +0100 | [diff] [blame] | 659 | static void rt2x00lib_uninitialize(struct rt2x00_dev *rt2x00dev) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 660 | { |
Ivo van Doorn | 0262ab0 | 2008-08-29 21:04:26 +0200 | [diff] [blame] | 661 | if (!test_and_clear_bit(DEVICE_STATE_INITIALIZED, &rt2x00dev->flags)) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 662 | return; |
| 663 | |
| 664 | /* |
Ivo van Doorn | 1682fe6 | 2008-03-13 15:38:03 +0100 | [diff] [blame] | 665 | * Unregister extra components. |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 666 | */ |
| 667 | rt2x00rfkill_unregister(rt2x00dev); |
| 668 | |
| 669 | /* |
| 670 | * Allow the HW to uninitialize. |
| 671 | */ |
| 672 | rt2x00dev->ops->lib->uninitialize(rt2x00dev); |
| 673 | |
| 674 | /* |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 675 | * Free allocated queue entries. |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 676 | */ |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 677 | rt2x00queue_uninitialize(rt2x00dev); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 678 | } |
| 679 | |
Ivo van Doorn | e37ea21 | 2008-01-06 23:40:07 +0100 | [diff] [blame] | 680 | static int rt2x00lib_initialize(struct rt2x00_dev *rt2x00dev) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 681 | { |
| 682 | int status; |
| 683 | |
Ivo van Doorn | 0262ab0 | 2008-08-29 21:04:26 +0200 | [diff] [blame] | 684 | if (test_bit(DEVICE_STATE_INITIALIZED, &rt2x00dev->flags)) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 685 | return 0; |
| 686 | |
| 687 | /* |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 688 | * Allocate all queue entries. |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 689 | */ |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 690 | status = rt2x00queue_initialize(rt2x00dev); |
| 691 | if (status) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 692 | return status; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 693 | |
| 694 | /* |
| 695 | * Initialize the device. |
| 696 | */ |
| 697 | status = rt2x00dev->ops->lib->initialize(rt2x00dev); |
Ivo van Doorn | ed49998 | 2008-05-05 17:23:47 +0200 | [diff] [blame] | 698 | if (status) { |
| 699 | rt2x00queue_uninitialize(rt2x00dev); |
| 700 | return status; |
| 701 | } |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 702 | |
Ivo van Doorn | 0262ab0 | 2008-08-29 21:04:26 +0200 | [diff] [blame] | 703 | set_bit(DEVICE_STATE_INITIALIZED, &rt2x00dev->flags); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 704 | |
| 705 | /* |
Ivo van Doorn | 1682fe6 | 2008-03-13 15:38:03 +0100 | [diff] [blame] | 706 | * Register the extra components. |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 707 | */ |
Ivo van Doorn | 1682fe6 | 2008-03-13 15:38:03 +0100 | [diff] [blame] | 708 | rt2x00rfkill_register(rt2x00dev); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 709 | |
| 710 | return 0; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 711 | } |
| 712 | |
Ivo van Doorn | e37ea21 | 2008-01-06 23:40:07 +0100 | [diff] [blame] | 713 | int rt2x00lib_start(struct rt2x00_dev *rt2x00dev) |
| 714 | { |
| 715 | int retval; |
| 716 | |
Ivo van Doorn | 0262ab0 | 2008-08-29 21:04:26 +0200 | [diff] [blame] | 717 | if (test_bit(DEVICE_STATE_STARTED, &rt2x00dev->flags)) |
Ivo van Doorn | e37ea21 | 2008-01-06 23:40:07 +0100 | [diff] [blame] | 718 | return 0; |
| 719 | |
| 720 | /* |
| 721 | * If this is the first interface which is added, |
| 722 | * we should load the firmware now. |
| 723 | */ |
Ivo van Doorn | 9404ef3 | 2008-02-03 15:48:38 +0100 | [diff] [blame] | 724 | retval = rt2x00lib_load_firmware(rt2x00dev); |
| 725 | if (retval) |
| 726 | return retval; |
Ivo van Doorn | e37ea21 | 2008-01-06 23:40:07 +0100 | [diff] [blame] | 727 | |
| 728 | /* |
| 729 | * Initialize the device. |
| 730 | */ |
| 731 | retval = rt2x00lib_initialize(rt2x00dev); |
| 732 | if (retval) |
| 733 | return retval; |
| 734 | |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame] | 735 | rt2x00dev->intf_ap_count = 0; |
| 736 | rt2x00dev->intf_sta_count = 0; |
| 737 | rt2x00dev->intf_associated = 0; |
| 738 | |
Ivo van Doorn | 0262ab0 | 2008-08-29 21:04:26 +0200 | [diff] [blame] | 739 | set_bit(DEVICE_STATE_STARTED, &rt2x00dev->flags); |
Ivo van Doorn | e37ea21 | 2008-01-06 23:40:07 +0100 | [diff] [blame] | 740 | |
| 741 | return 0; |
| 742 | } |
| 743 | |
| 744 | void rt2x00lib_stop(struct rt2x00_dev *rt2x00dev) |
| 745 | { |
Ivo van Doorn | 0262ab0 | 2008-08-29 21:04:26 +0200 | [diff] [blame] | 746 | if (!test_and_clear_bit(DEVICE_STATE_STARTED, &rt2x00dev->flags)) |
Ivo van Doorn | e37ea21 | 2008-01-06 23:40:07 +0100 | [diff] [blame] | 747 | return; |
| 748 | |
| 749 | /* |
| 750 | * Perhaps we can add something smarter here, |
| 751 | * but for now just disabling the radio should do. |
| 752 | */ |
| 753 | rt2x00lib_disable_radio(rt2x00dev); |
| 754 | |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame] | 755 | rt2x00dev->intf_ap_count = 0; |
| 756 | rt2x00dev->intf_sta_count = 0; |
| 757 | rt2x00dev->intf_associated = 0; |
Ivo van Doorn | e37ea21 | 2008-01-06 23:40:07 +0100 | [diff] [blame] | 758 | } |
| 759 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 760 | /* |
| 761 | * driver allocation handlers. |
| 762 | */ |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 763 | int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev) |
| 764 | { |
| 765 | int retval = -ENOMEM; |
| 766 | |
Ivo van Doorn | 8ff48a8 | 2008-11-09 23:40:46 +0100 | [diff] [blame] | 767 | mutex_init(&rt2x00dev->csr_mutex); |
| 768 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 769 | /* |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame] | 770 | * Make room for rt2x00_intf inside the per-interface |
| 771 | * structure ieee80211_vif. |
| 772 | */ |
| 773 | rt2x00dev->hw->vif_data_size = sizeof(struct rt2x00_intf); |
| 774 | |
Ivo van Doorn | 3514a44 | 2008-10-29 17:18:46 +0100 | [diff] [blame] | 775 | /* |
| 776 | * Determine which operating modes are supported, all modes |
| 777 | * which require beaconing, depend on the availability of |
| 778 | * beacon entries. |
| 779 | */ |
| 780 | rt2x00dev->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION); |
| 781 | if (rt2x00dev->ops->bcn->entry_num > 0) |
| 782 | rt2x00dev->hw->wiphy->interface_modes |= |
| 783 | BIT(NL80211_IFTYPE_ADHOC) | |
Andrey Yurovsky | a07dbea | 2008-12-20 10:55:34 +0100 | [diff] [blame^] | 784 | BIT(NL80211_IFTYPE_AP) | |
| 785 | BIT(NL80211_IFTYPE_MESH_POINT); |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 786 | |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame] | 787 | /* |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 788 | * Let the driver probe the device to detect the capabilities. |
| 789 | */ |
| 790 | retval = rt2x00dev->ops->lib->probe_hw(rt2x00dev); |
| 791 | if (retval) { |
| 792 | ERROR(rt2x00dev, "Failed to allocate device.\n"); |
| 793 | goto exit; |
| 794 | } |
| 795 | |
| 796 | /* |
| 797 | * Initialize configuration work. |
| 798 | */ |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame] | 799 | INIT_WORK(&rt2x00dev->intf_work, rt2x00lib_intf_scheduled); |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 800 | INIT_WORK(&rt2x00dev->filter_work, rt2x00lib_packetfilter_scheduled); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 801 | |
| 802 | /* |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 803 | * Allocate queue array. |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 804 | */ |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 805 | retval = rt2x00queue_allocate(rt2x00dev); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 806 | if (retval) |
| 807 | goto exit; |
| 808 | |
| 809 | /* |
| 810 | * Initialize ieee80211 structure. |
| 811 | */ |
| 812 | retval = rt2x00lib_probe_hw(rt2x00dev); |
| 813 | if (retval) { |
| 814 | ERROR(rt2x00dev, "Failed to initialize hw.\n"); |
| 815 | goto exit; |
| 816 | } |
| 817 | |
| 818 | /* |
Ivo van Doorn | 1682fe6 | 2008-03-13 15:38:03 +0100 | [diff] [blame] | 819 | * Register extra components. |
Ivo van Doorn | a9450b7 | 2008-02-03 15:53:40 +0100 | [diff] [blame] | 820 | */ |
Ivo van Doorn | 84e3196 | 2008-12-20 10:53:29 +0100 | [diff] [blame] | 821 | rt2x00link_register(rt2x00dev); |
Ivo van Doorn | a9450b7 | 2008-02-03 15:53:40 +0100 | [diff] [blame] | 822 | rt2x00leds_register(rt2x00dev); |
Ivo van Doorn | 1682fe6 | 2008-03-13 15:38:03 +0100 | [diff] [blame] | 823 | rt2x00rfkill_allocate(rt2x00dev); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 824 | rt2x00debug_register(rt2x00dev); |
| 825 | |
Ivo van Doorn | 0262ab0 | 2008-08-29 21:04:26 +0200 | [diff] [blame] | 826 | set_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags); |
Ivo van Doorn | 066cb63 | 2007-09-25 20:55:39 +0200 | [diff] [blame] | 827 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 828 | return 0; |
| 829 | |
| 830 | exit: |
| 831 | rt2x00lib_remove_dev(rt2x00dev); |
| 832 | |
| 833 | return retval; |
| 834 | } |
| 835 | EXPORT_SYMBOL_GPL(rt2x00lib_probe_dev); |
| 836 | |
| 837 | void rt2x00lib_remove_dev(struct rt2x00_dev *rt2x00dev) |
| 838 | { |
Ivo van Doorn | 0262ab0 | 2008-08-29 21:04:26 +0200 | [diff] [blame] | 839 | clear_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags); |
Ivo van Doorn | 066cb63 | 2007-09-25 20:55:39 +0200 | [diff] [blame] | 840 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 841 | /* |
| 842 | * Disable radio. |
| 843 | */ |
| 844 | rt2x00lib_disable_radio(rt2x00dev); |
| 845 | |
| 846 | /* |
| 847 | * Uninitialize device. |
| 848 | */ |
| 849 | rt2x00lib_uninitialize(rt2x00dev); |
| 850 | |
| 851 | /* |
Ivo van Doorn | 1682fe6 | 2008-03-13 15:38:03 +0100 | [diff] [blame] | 852 | * Free extra components |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 853 | */ |
| 854 | rt2x00debug_deregister(rt2x00dev); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 855 | rt2x00rfkill_free(rt2x00dev); |
Ivo van Doorn | a9450b7 | 2008-02-03 15:53:40 +0100 | [diff] [blame] | 856 | rt2x00leds_unregister(rt2x00dev); |
| 857 | |
| 858 | /* |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 859 | * Free ieee80211_hw memory. |
| 860 | */ |
| 861 | rt2x00lib_remove_hw(rt2x00dev); |
| 862 | |
| 863 | /* |
| 864 | * Free firmware image. |
| 865 | */ |
| 866 | rt2x00lib_free_firmware(rt2x00dev); |
| 867 | |
| 868 | /* |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 869 | * Free queue structures. |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 870 | */ |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 871 | rt2x00queue_free(rt2x00dev); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 872 | } |
| 873 | EXPORT_SYMBOL_GPL(rt2x00lib_remove_dev); |
| 874 | |
| 875 | /* |
| 876 | * Device state handlers |
| 877 | */ |
| 878 | #ifdef CONFIG_PM |
| 879 | int rt2x00lib_suspend(struct rt2x00_dev *rt2x00dev, pm_message_t state) |
| 880 | { |
| 881 | int retval; |
| 882 | |
| 883 | NOTICE(rt2x00dev, "Going to sleep.\n"); |
Ivo van Doorn | 066cb63 | 2007-09-25 20:55:39 +0200 | [diff] [blame] | 884 | |
| 885 | /* |
| 886 | * Only continue if mac80211 has open interfaces. |
| 887 | */ |
Ivo van Doorn | 0262ab0 | 2008-08-29 21:04:26 +0200 | [diff] [blame] | 888 | if (!test_and_clear_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags) || |
| 889 | !test_bit(DEVICE_STATE_STARTED, &rt2x00dev->flags)) |
Ivo van Doorn | 066cb63 | 2007-09-25 20:55:39 +0200 | [diff] [blame] | 890 | goto exit; |
Ivo van Doorn | 0262ab0 | 2008-08-29 21:04:26 +0200 | [diff] [blame] | 891 | |
| 892 | set_bit(DEVICE_STATE_STARTED_SUSPEND, &rt2x00dev->flags); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 893 | |
| 894 | /* |
Ivo van Doorn | 1682fe6 | 2008-03-13 15:38:03 +0100 | [diff] [blame] | 895 | * Disable radio. |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 896 | */ |
Ivo van Doorn | e37ea21 | 2008-01-06 23:40:07 +0100 | [diff] [blame] | 897 | rt2x00lib_stop(rt2x00dev); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 898 | rt2x00lib_uninitialize(rt2x00dev); |
Ivo van Doorn | 1682fe6 | 2008-03-13 15:38:03 +0100 | [diff] [blame] | 899 | |
| 900 | /* |
| 901 | * Suspend/disable extra components. |
| 902 | */ |
Ivo van Doorn | a9450b7 | 2008-02-03 15:53:40 +0100 | [diff] [blame] | 903 | rt2x00leds_suspend(rt2x00dev); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 904 | rt2x00debug_deregister(rt2x00dev); |
| 905 | |
Ivo van Doorn | 066cb63 | 2007-09-25 20:55:39 +0200 | [diff] [blame] | 906 | exit: |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 907 | /* |
Ivo van Doorn | 9896322 | 2008-03-27 17:15:24 +0100 | [diff] [blame] | 908 | * Set device mode to sleep for power management, |
| 909 | * on some hardware this call seems to consistently fail. |
| 910 | * From the specifications it is hard to tell why it fails, |
| 911 | * and if this is a "bad thing". |
| 912 | * Overall it is safe to just ignore the failure and |
| 913 | * continue suspending. The only downside is that the |
| 914 | * device will not be in optimal power save mode, but with |
| 915 | * the radio and the other components already disabled the |
| 916 | * device is as good as disabled. |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 917 | */ |
| 918 | retval = rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_SLEEP); |
| 919 | if (retval) |
Ivo van Doorn | 9896322 | 2008-03-27 17:15:24 +0100 | [diff] [blame] | 920 | WARNING(rt2x00dev, "Device failed to enter sleep state, " |
| 921 | "continue suspending.\n"); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 922 | |
| 923 | return 0; |
| 924 | } |
| 925 | EXPORT_SYMBOL_GPL(rt2x00lib_suspend); |
| 926 | |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame] | 927 | static void rt2x00lib_resume_intf(void *data, u8 *mac, |
| 928 | struct ieee80211_vif *vif) |
| 929 | { |
| 930 | struct rt2x00_dev *rt2x00dev = data; |
| 931 | struct rt2x00_intf *intf = vif_to_intf(vif); |
| 932 | |
| 933 | spin_lock(&intf->lock); |
| 934 | |
| 935 | rt2x00lib_config_intf(rt2x00dev, intf, |
| 936 | vif->type, intf->mac, intf->bssid); |
| 937 | |
| 938 | |
| 939 | /* |
Andrey Yurovsky | a07dbea | 2008-12-20 10:55:34 +0100 | [diff] [blame^] | 940 | * AP, Ad-hoc, and Mesh Point mode require a new beacon update. |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame] | 941 | */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 942 | if (vif->type == NL80211_IFTYPE_AP || |
Andrey Yurovsky | a07dbea | 2008-12-20 10:55:34 +0100 | [diff] [blame^] | 943 | vif->type == NL80211_IFTYPE_ADHOC || |
| 944 | vif->type == NL80211_IFTYPE_MESH_POINT) |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame] | 945 | intf->delayed_flags |= DELAYED_UPDATE_BEACON; |
| 946 | |
| 947 | spin_unlock(&intf->lock); |
| 948 | } |
| 949 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 950 | int rt2x00lib_resume(struct rt2x00_dev *rt2x00dev) |
| 951 | { |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 952 | int retval; |
| 953 | |
| 954 | NOTICE(rt2x00dev, "Waking up.\n"); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 955 | |
| 956 | /* |
Ivo van Doorn | 1682fe6 | 2008-03-13 15:38:03 +0100 | [diff] [blame] | 957 | * Restore/enable extra components. |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 958 | */ |
| 959 | rt2x00debug_register(rt2x00dev); |
Ivo van Doorn | a9450b7 | 2008-02-03 15:53:40 +0100 | [diff] [blame] | 960 | rt2x00leds_resume(rt2x00dev); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 961 | |
| 962 | /* |
Ivo van Doorn | 6d7f987 | 2007-10-06 14:12:42 +0200 | [diff] [blame] | 963 | * Only continue if mac80211 had open interfaces. |
Ivo van Doorn | 066cb63 | 2007-09-25 20:55:39 +0200 | [diff] [blame] | 964 | */ |
Ivo van Doorn | 0262ab0 | 2008-08-29 21:04:26 +0200 | [diff] [blame] | 965 | if (!test_and_clear_bit(DEVICE_STATE_STARTED_SUSPEND, &rt2x00dev->flags)) |
Ivo van Doorn | 066cb63 | 2007-09-25 20:55:39 +0200 | [diff] [blame] | 966 | return 0; |
| 967 | |
| 968 | /* |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 969 | * Reinitialize device and all active interfaces. |
| 970 | */ |
Ivo van Doorn | e37ea21 | 2008-01-06 23:40:07 +0100 | [diff] [blame] | 971 | retval = rt2x00lib_start(rt2x00dev); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 972 | if (retval) |
| 973 | goto exit; |
| 974 | |
| 975 | /* |
| 976 | * Reconfigure device. |
| 977 | */ |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 978 | retval = rt2x00mac_config(rt2x00dev->hw, ~0); |
Ivo van Doorn | 74c0ee9 | 2008-07-21 11:52:44 +0200 | [diff] [blame] | 979 | if (retval) |
| 980 | goto exit; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 981 | |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame] | 982 | /* |
| 983 | * Iterator over each active interface to |
| 984 | * reconfigure the hardware. |
| 985 | */ |
| 986 | ieee80211_iterate_active_interfaces(rt2x00dev->hw, |
| 987 | rt2x00lib_resume_intf, rt2x00dev); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 988 | |
| 989 | /* |
Ivo van Doorn | e37ea21 | 2008-01-06 23:40:07 +0100 | [diff] [blame] | 990 | * We are ready again to receive requests from mac80211. |
| 991 | */ |
Ivo van Doorn | 0262ab0 | 2008-08-29 21:04:26 +0200 | [diff] [blame] | 992 | set_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags); |
Ivo van Doorn | e37ea21 | 2008-01-06 23:40:07 +0100 | [diff] [blame] | 993 | |
| 994 | /* |
Ivo van Doorn | 066cb63 | 2007-09-25 20:55:39 +0200 | [diff] [blame] | 995 | * It is possible that during that mac80211 has attempted |
| 996 | * to send frames while we were suspending or resuming. |
| 997 | * In that case we have disabled the TX queue and should |
| 998 | * now enable it again |
| 999 | */ |
Johannes Berg | 36d6825 | 2008-05-15 12:55:26 +0200 | [diff] [blame] | 1000 | ieee80211_wake_queues(rt2x00dev->hw); |
Ivo van Doorn | 066cb63 | 2007-09-25 20:55:39 +0200 | [diff] [blame] | 1001 | |
| 1002 | /* |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame] | 1003 | * During interface iteration we might have changed the |
| 1004 | * delayed_flags, time to handles the event by calling |
| 1005 | * the work handler directly. |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1006 | */ |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame] | 1007 | rt2x00lib_intf_scheduled(&rt2x00dev->intf_work); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1008 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1009 | return 0; |
| 1010 | |
| 1011 | exit: |
Ivo van Doorn | 0262ab0 | 2008-08-29 21:04:26 +0200 | [diff] [blame] | 1012 | rt2x00lib_stop(rt2x00dev); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1013 | rt2x00lib_uninitialize(rt2x00dev); |
| 1014 | rt2x00debug_deregister(rt2x00dev); |
| 1015 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1016 | return retval; |
| 1017 | } |
| 1018 | EXPORT_SYMBOL_GPL(rt2x00lib_resume); |
| 1019 | #endif /* CONFIG_PM */ |
| 1020 | |
| 1021 | /* |
| 1022 | * rt2x00lib module information. |
| 1023 | */ |
| 1024 | MODULE_AUTHOR(DRV_PROJECT); |
| 1025 | MODULE_VERSION(DRV_VERSION); |
| 1026 | MODULE_DESCRIPTION("rt2x00 library"); |
| 1027 | MODULE_LICENSE("GPL"); |