| Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | Copyright (C) 2004 - 2007 rt2x00 SourceForge Project | 
|  | 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: rt2x00 | 
|  | 23 | Abstract: rt2x00 global information. | 
|  | 24 | */ | 
|  | 25 |  | 
|  | 26 | #ifndef RT2X00_H | 
|  | 27 | #define RT2X00_H | 
|  | 28 |  | 
|  | 29 | #include <linux/bitops.h> | 
|  | 30 | #include <linux/prefetch.h> | 
|  | 31 | #include <linux/skbuff.h> | 
|  | 32 | #include <linux/workqueue.h> | 
|  | 33 | #include <linux/firmware.h> | 
|  | 34 |  | 
|  | 35 | #include <net/mac80211.h> | 
|  | 36 |  | 
|  | 37 | #include "rt2x00debug.h" | 
|  | 38 | #include "rt2x00reg.h" | 
|  | 39 | #include "rt2x00ring.h" | 
|  | 40 |  | 
|  | 41 | /* | 
|  | 42 | * Module information. | 
|  | 43 | * DRV_NAME should be set within the individual module source files. | 
|  | 44 | */ | 
| Ivo van Doorn | 515ea24 | 2007-10-06 14:18:41 +0200 | [diff] [blame] | 45 | #define DRV_VERSION	"2.0.10" | 
| Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 46 | #define DRV_PROJECT	"http://rt2x00.serialmonkey.com" | 
|  | 47 |  | 
|  | 48 | /* | 
|  | 49 | * Debug definitions. | 
|  | 50 | * Debug output has to be enabled during compile time. | 
|  | 51 | */ | 
|  | 52 | #define DEBUG_PRINTK_MSG(__dev, __kernlvl, __lvl, __msg, __args...)	\ | 
|  | 53 | printk(__kernlvl "%s -> %s: %s - " __msg,			\ | 
|  | 54 | wiphy_name((__dev)->hw->wiphy), __FUNCTION__, __lvl, ##__args) | 
|  | 55 |  | 
|  | 56 | #define DEBUG_PRINTK_PROBE(__kernlvl, __lvl, __msg, __args...)	\ | 
|  | 57 | printk(__kernlvl "%s -> %s: %s - " __msg,		\ | 
|  | 58 | DRV_NAME, __FUNCTION__, __lvl, ##__args) | 
|  | 59 |  | 
|  | 60 | #ifdef CONFIG_RT2X00_DEBUG | 
|  | 61 | #define DEBUG_PRINTK(__dev, __kernlvl, __lvl, __msg, __args...)	\ | 
|  | 62 | DEBUG_PRINTK_MSG(__dev, __kernlvl, __lvl, __msg, ##__args); | 
|  | 63 | #else | 
|  | 64 | #define DEBUG_PRINTK(__dev, __kernlvl, __lvl, __msg, __args...)	\ | 
|  | 65 | do { } while (0) | 
|  | 66 | #endif /* CONFIG_RT2X00_DEBUG */ | 
|  | 67 |  | 
|  | 68 | /* | 
|  | 69 | * Various debug levels. | 
|  | 70 | * The debug levels PANIC and ERROR both indicate serious problems, | 
|  | 71 | * for this reason they should never be ignored. | 
|  | 72 | * The special ERROR_PROBE message is for messages that are generated | 
|  | 73 | * when the rt2x00_dev is not yet initialized. | 
|  | 74 | */ | 
|  | 75 | #define PANIC(__dev, __msg, __args...) \ | 
|  | 76 | DEBUG_PRINTK_MSG(__dev, KERN_CRIT, "Panic", __msg, ##__args) | 
|  | 77 | #define ERROR(__dev, __msg, __args...)	\ | 
|  | 78 | DEBUG_PRINTK_MSG(__dev, KERN_ERR, "Error", __msg, ##__args) | 
|  | 79 | #define ERROR_PROBE(__msg, __args...) \ | 
|  | 80 | DEBUG_PRINTK_PROBE(KERN_ERR, "Error", __msg, ##__args) | 
|  | 81 | #define WARNING(__dev, __msg, __args...) \ | 
|  | 82 | DEBUG_PRINTK(__dev, KERN_WARNING, "Warning", __msg, ##__args) | 
|  | 83 | #define NOTICE(__dev, __msg, __args...) \ | 
|  | 84 | DEBUG_PRINTK(__dev, KERN_NOTICE, "Notice", __msg, ##__args) | 
|  | 85 | #define INFO(__dev, __msg, __args...) \ | 
|  | 86 | DEBUG_PRINTK(__dev, KERN_INFO, "Info", __msg, ##__args) | 
|  | 87 | #define DEBUG(__dev, __msg, __args...) \ | 
|  | 88 | DEBUG_PRINTK(__dev, KERN_DEBUG, "Debug", __msg, ##__args) | 
|  | 89 | #define EEPROM(__dev, __msg, __args...) \ | 
|  | 90 | DEBUG_PRINTK(__dev, KERN_DEBUG, "EEPROM recovery", __msg, ##__args) | 
|  | 91 |  | 
|  | 92 | /* | 
|  | 93 | * Ring sizes. | 
|  | 94 | * Ralink PCI devices demand the Frame size to be a multiple of 128 bytes. | 
|  | 95 | * DATA_FRAME_SIZE is used for TX, RX, ATIM and PRIO rings. | 
|  | 96 | * MGMT_FRAME_SIZE is used for the BEACON ring. | 
|  | 97 | */ | 
|  | 98 | #define DATA_FRAME_SIZE	2432 | 
|  | 99 | #define MGMT_FRAME_SIZE	256 | 
|  | 100 |  | 
|  | 101 | /* | 
|  | 102 | * Number of entries in a packet ring. | 
|  | 103 | * PCI devices only need 1 Beacon entry, | 
|  | 104 | * but USB devices require a second because they | 
|  | 105 | * have to send a Guardian byte first. | 
|  | 106 | */ | 
|  | 107 | #define RX_ENTRIES	12 | 
|  | 108 | #define TX_ENTRIES	12 | 
|  | 109 | #define ATIM_ENTRIES	1 | 
|  | 110 | #define BEACON_ENTRIES	2 | 
|  | 111 |  | 
|  | 112 | /* | 
|  | 113 | * Standard timing and size defines. | 
|  | 114 | * These values should follow the ieee80211 specifications. | 
|  | 115 | */ | 
|  | 116 | #define ACK_SIZE		14 | 
|  | 117 | #define IEEE80211_HEADER	24 | 
|  | 118 | #define PLCP			48 | 
|  | 119 | #define BEACON			100 | 
|  | 120 | #define PREAMBLE		144 | 
|  | 121 | #define SHORT_PREAMBLE		72 | 
|  | 122 | #define SLOT_TIME		20 | 
|  | 123 | #define SHORT_SLOT_TIME		9 | 
|  | 124 | #define SIFS			10 | 
|  | 125 | #define PIFS			( SIFS + SLOT_TIME ) | 
|  | 126 | #define SHORT_PIFS		( SIFS + SHORT_SLOT_TIME ) | 
|  | 127 | #define DIFS			( PIFS + SLOT_TIME ) | 
|  | 128 | #define SHORT_DIFS		( SHORT_PIFS + SHORT_SLOT_TIME ) | 
|  | 129 | #define EIFS			( SIFS + (8 * (IEEE80211_HEADER + ACK_SIZE)) ) | 
|  | 130 |  | 
|  | 131 | /* | 
|  | 132 | * IEEE802.11 header defines | 
|  | 133 | */ | 
|  | 134 | static inline int is_rts_frame(u16 fc) | 
|  | 135 | { | 
|  | 136 | return !!(((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) && | 
|  | 137 | ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_RTS)); | 
|  | 138 | } | 
|  | 139 |  | 
|  | 140 | static inline int is_cts_frame(u16 fc) | 
|  | 141 | { | 
|  | 142 | return !!(((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) && | 
|  | 143 | ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_CTS)); | 
|  | 144 | } | 
|  | 145 |  | 
|  | 146 | static inline int is_probe_resp(u16 fc) | 
|  | 147 | { | 
|  | 148 | return !!(((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) && | 
|  | 149 | ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP)); | 
|  | 150 | } | 
|  | 151 |  | 
|  | 152 | /* | 
|  | 153 | * Chipset identification | 
|  | 154 | * The chipset on the device is composed of a RT and RF chip. | 
|  | 155 | * The chipset combination is important for determining device capabilities. | 
|  | 156 | */ | 
|  | 157 | struct rt2x00_chip { | 
|  | 158 | u16 rt; | 
|  | 159 | #define RT2460		0x0101 | 
|  | 160 | #define RT2560		0x0201 | 
|  | 161 | #define RT2570		0x1201 | 
| Ivo van Doorn | 12dadb9 | 2007-09-25 20:54:44 +0200 | [diff] [blame] | 162 | #define RT2561s		0x0301	/* Turbo */ | 
|  | 163 | #define RT2561		0x0302 | 
| Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 164 | #define RT2661		0x0401 | 
|  | 165 | #define RT2571		0x1300 | 
|  | 166 |  | 
|  | 167 | u16 rf; | 
|  | 168 | u32 rev; | 
|  | 169 | }; | 
|  | 170 |  | 
|  | 171 | /* | 
|  | 172 | * RF register values that belong to a particular channel. | 
|  | 173 | */ | 
|  | 174 | struct rf_channel { | 
|  | 175 | int channel; | 
|  | 176 | u32 rf1; | 
|  | 177 | u32 rf2; | 
|  | 178 | u32 rf3; | 
|  | 179 | u32 rf4; | 
|  | 180 | }; | 
|  | 181 |  | 
|  | 182 | /* | 
|  | 183 | * To optimize the quality of the link we need to store | 
|  | 184 | * the quality of received frames and periodically | 
|  | 185 | * optimize the link. | 
|  | 186 | */ | 
|  | 187 | struct link { | 
|  | 188 | /* | 
|  | 189 | * Link tuner counter | 
|  | 190 | * The number of times the link has been tuned | 
|  | 191 | * since the radio has been switched on. | 
|  | 192 | */ | 
|  | 193 | u32 count; | 
|  | 194 |  | 
|  | 195 | /* | 
|  | 196 | * Statistics required for Link tuning. | 
|  | 197 | * For the average RSSI value we use the "Walking average" approach. | 
|  | 198 | * When adding RSSI to the average value the following calculation | 
|  | 199 | * is needed: | 
|  | 200 | * | 
|  | 201 | *        avg_rssi = ((avg_rssi * 7) + rssi) / 8; | 
|  | 202 | * | 
|  | 203 | * The advantage of this approach is that we only need 1 variable | 
|  | 204 | * to store the average in (No need for a count and a total). | 
|  | 205 | * But more importantly, normal average values will over time | 
|  | 206 | * move less and less towards newly added values this results | 
|  | 207 | * that with link tuning, the device can have a very good RSSI | 
|  | 208 | * for a few minutes but when the device is moved away from the AP | 
|  | 209 | * the average will not decrease fast enough to compensate. | 
|  | 210 | * The walking average compensates this and will move towards | 
|  | 211 | * the new values correctly allowing a effective link tuning. | 
|  | 212 | */ | 
|  | 213 | int avg_rssi; | 
|  | 214 | int vgc_level; | 
|  | 215 | int false_cca; | 
|  | 216 |  | 
|  | 217 | /* | 
|  | 218 | * Statistics required for Signal quality calculation. | 
|  | 219 | * For calculating the Signal quality we have to determine | 
|  | 220 | * the total number of success and failed RX and TX frames. | 
|  | 221 | * After that we also use the average RSSI value to help | 
|  | 222 | * determining the signal quality. | 
|  | 223 | * For the calculation we will use the following algorithm: | 
|  | 224 | * | 
|  | 225 | *         rssi_percentage = (avg_rssi * 100) / rssi_offset | 
|  | 226 | *         rx_percentage = (rx_success * 100) / rx_total | 
|  | 227 | *         tx_percentage = (tx_success * 100) / tx_total | 
|  | 228 | *         avg_signal = ((WEIGHT_RSSI * avg_rssi) + | 
|  | 229 | *                       (WEIGHT_TX * tx_percentage) + | 
|  | 230 | *                       (WEIGHT_RX * rx_percentage)) / 100 | 
|  | 231 | * | 
|  | 232 | * This value should then be checked to not be greated then 100. | 
|  | 233 | */ | 
|  | 234 | int rx_percentage; | 
|  | 235 | int rx_success; | 
|  | 236 | int rx_failed; | 
|  | 237 | int tx_percentage; | 
|  | 238 | int tx_success; | 
|  | 239 | int tx_failed; | 
|  | 240 | #define WEIGHT_RSSI	20 | 
|  | 241 | #define WEIGHT_RX	40 | 
|  | 242 | #define WEIGHT_TX	40 | 
|  | 243 |  | 
|  | 244 | /* | 
|  | 245 | * Work structure for scheduling periodic link tuning. | 
|  | 246 | */ | 
|  | 247 | struct delayed_work work; | 
|  | 248 | }; | 
|  | 249 |  | 
|  | 250 | /* | 
|  | 251 | * Clear all counters inside the link structure. | 
|  | 252 | * This can be easiest achieved by memsetting everything | 
|  | 253 | * except for the work structure at the end. | 
|  | 254 | */ | 
|  | 255 | static inline void rt2x00_clear_link(struct link *link) | 
|  | 256 | { | 
|  | 257 | memset(link, 0x00, sizeof(*link) - sizeof(link->work)); | 
|  | 258 | link->rx_percentage = 50; | 
|  | 259 | link->tx_percentage = 50; | 
|  | 260 | } | 
|  | 261 |  | 
|  | 262 | /* | 
|  | 263 | * Update the rssi using the walking average approach. | 
|  | 264 | */ | 
|  | 265 | static inline void rt2x00_update_link_rssi(struct link *link, int rssi) | 
|  | 266 | { | 
|  | 267 | if (!link->avg_rssi) | 
|  | 268 | link->avg_rssi = rssi; | 
|  | 269 | else | 
|  | 270 | link->avg_rssi = ((link->avg_rssi * 7) + rssi) / 8; | 
|  | 271 | } | 
|  | 272 |  | 
|  | 273 | /* | 
|  | 274 | * When the avg_rssi is unset or no frames  have been received), | 
|  | 275 | * we need to return the default value which needs to be less | 
|  | 276 | * than -80 so the device will select the maximum sensitivity. | 
|  | 277 | */ | 
|  | 278 | static inline int rt2x00_get_link_rssi(struct link *link) | 
|  | 279 | { | 
|  | 280 | return (link->avg_rssi && link->rx_success) ? link->avg_rssi : -128; | 
|  | 281 | } | 
|  | 282 |  | 
|  | 283 | /* | 
|  | 284 | * Interface structure | 
|  | 285 | * Configuration details about the current interface. | 
|  | 286 | */ | 
|  | 287 | struct interface { | 
|  | 288 | /* | 
|  | 289 | * Interface identification. The value is assigned | 
|  | 290 | * to us by the 80211 stack, and is used to request | 
|  | 291 | * new beacons. | 
|  | 292 | */ | 
|  | 293 | int id; | 
|  | 294 |  | 
|  | 295 | /* | 
|  | 296 | * Current working type (IEEE80211_IF_TYPE_*). | 
| Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 297 | * When set to INVALID_INTERFACE, no interface is configured. | 
|  | 298 | */ | 
|  | 299 | int type; | 
| Johannes Berg | a289755 | 2007-09-28 14:01:25 +0200 | [diff] [blame] | 300 | #define INVALID_INTERFACE	IEEE80211_IF_TYPE_INVALID | 
| Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 301 |  | 
|  | 302 | /* | 
|  | 303 | * MAC of the device. | 
|  | 304 | */ | 
|  | 305 | u8 mac[ETH_ALEN]; | 
|  | 306 |  | 
|  | 307 | /* | 
|  | 308 | * BBSID of the AP to associate with. | 
|  | 309 | */ | 
|  | 310 | u8 bssid[ETH_ALEN]; | 
|  | 311 |  | 
|  | 312 | /* | 
|  | 313 | * Store the packet filter mode for the current interface. | 
| Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 314 | */ | 
| Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 315 | unsigned int filter; | 
| Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 316 | }; | 
|  | 317 |  | 
|  | 318 | static inline int is_interface_present(struct interface *intf) | 
|  | 319 | { | 
|  | 320 | return !!intf->id; | 
|  | 321 | } | 
|  | 322 |  | 
| Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 323 | static inline int is_interface_type(struct interface *intf, int type) | 
| Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 324 | { | 
| Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 325 | return intf->type == type; | 
| Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 326 | } | 
|  | 327 |  | 
|  | 328 | /* | 
|  | 329 | * Details about the supported modes, rates and channels | 
|  | 330 | * of a particular chipset. This is used by rt2x00lib | 
|  | 331 | * to build the ieee80211_hw_mode array for mac80211. | 
|  | 332 | */ | 
|  | 333 | struct hw_mode_spec { | 
|  | 334 | /* | 
|  | 335 | * Number of modes, rates and channels. | 
|  | 336 | */ | 
|  | 337 | int num_modes; | 
|  | 338 | int num_rates; | 
|  | 339 | int num_channels; | 
|  | 340 |  | 
|  | 341 | /* | 
|  | 342 | * txpower values. | 
|  | 343 | */ | 
|  | 344 | const u8 *tx_power_a; | 
|  | 345 | const u8 *tx_power_bg; | 
|  | 346 | u8 tx_power_default; | 
|  | 347 |  | 
|  | 348 | /* | 
|  | 349 | * Device/chipset specific value. | 
|  | 350 | */ | 
|  | 351 | const struct rf_channel *channels; | 
|  | 352 | }; | 
|  | 353 |  | 
|  | 354 | /* | 
| Ivo van Doorn | 5c58ee5 | 2007-10-06 13:34:52 +0200 | [diff] [blame] | 355 | * Configuration structure wrapper around the | 
|  | 356 | * mac80211 configuration structure. | 
|  | 357 | * When mac80211 configures the driver, rt2x00lib | 
|  | 358 | * can precalculate values which are equal for all | 
|  | 359 | * rt2x00 drivers. Those values can be stored in here. | 
|  | 360 | */ | 
|  | 361 | struct rt2x00lib_conf { | 
|  | 362 | struct ieee80211_conf *conf; | 
|  | 363 | struct rf_channel rf; | 
|  | 364 |  | 
|  | 365 | int phymode; | 
|  | 366 |  | 
|  | 367 | int basic_rates; | 
|  | 368 | int slot_time; | 
|  | 369 |  | 
|  | 370 | short sifs; | 
|  | 371 | short pifs; | 
|  | 372 | short difs; | 
|  | 373 | short eifs; | 
|  | 374 | }; | 
|  | 375 |  | 
|  | 376 | /* | 
| Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 377 | * rt2x00lib callback functions. | 
|  | 378 | */ | 
|  | 379 | struct rt2x00lib_ops { | 
|  | 380 | /* | 
|  | 381 | * Interrupt handlers. | 
|  | 382 | */ | 
|  | 383 | irq_handler_t irq_handler; | 
|  | 384 |  | 
|  | 385 | /* | 
|  | 386 | * Device init handlers. | 
|  | 387 | */ | 
|  | 388 | int (*probe_hw) (struct rt2x00_dev *rt2x00dev); | 
|  | 389 | char *(*get_firmware_name) (struct rt2x00_dev *rt2x00dev); | 
|  | 390 | int (*load_firmware) (struct rt2x00_dev *rt2x00dev, void *data, | 
|  | 391 | const size_t len); | 
|  | 392 |  | 
|  | 393 | /* | 
|  | 394 | * Device initialization/deinitialization handlers. | 
|  | 395 | */ | 
|  | 396 | int (*initialize) (struct rt2x00_dev *rt2x00dev); | 
|  | 397 | void (*uninitialize) (struct rt2x00_dev *rt2x00dev); | 
|  | 398 |  | 
|  | 399 | /* | 
|  | 400 | * Radio control handlers. | 
|  | 401 | */ | 
|  | 402 | int (*set_device_state) (struct rt2x00_dev *rt2x00dev, | 
|  | 403 | enum dev_state state); | 
|  | 404 | int (*rfkill_poll) (struct rt2x00_dev *rt2x00dev); | 
|  | 405 | void (*link_stats) (struct rt2x00_dev *rt2x00dev); | 
|  | 406 | void (*reset_tuner) (struct rt2x00_dev *rt2x00dev); | 
|  | 407 | void (*link_tuner) (struct rt2x00_dev *rt2x00dev); | 
|  | 408 |  | 
|  | 409 | /* | 
|  | 410 | * TX control handlers | 
|  | 411 | */ | 
|  | 412 | void (*write_tx_desc) (struct rt2x00_dev *rt2x00dev, | 
|  | 413 | struct data_desc *txd, | 
| Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 414 | struct txdata_entry_desc *desc, | 
| Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 415 | struct ieee80211_hdr *ieee80211hdr, | 
|  | 416 | unsigned int length, | 
|  | 417 | struct ieee80211_tx_control *control); | 
|  | 418 | int (*write_tx_data) (struct rt2x00_dev *rt2x00dev, | 
|  | 419 | struct data_ring *ring, struct sk_buff *skb, | 
|  | 420 | struct ieee80211_tx_control *control); | 
| Ivo van Doorn | dd9fa2d | 2007-10-06 14:15:46 +0200 | [diff] [blame] | 421 | int (*get_tx_data_len) (struct rt2x00_dev *rt2x00dev, int maxpacket, | 
|  | 422 | struct sk_buff *skb); | 
| Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 423 | void (*kick_tx_queue) (struct rt2x00_dev *rt2x00dev, | 
|  | 424 | unsigned int queue); | 
|  | 425 |  | 
|  | 426 | /* | 
|  | 427 | * RX control handlers | 
|  | 428 | */ | 
| Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 429 | void (*fill_rxdone) (struct data_entry *entry, | 
|  | 430 | struct rxdata_entry_desc *desc); | 
| Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 431 |  | 
|  | 432 | /* | 
|  | 433 | * Configuration handlers. | 
|  | 434 | */ | 
| Ivo van Doorn | 4abee4b | 2007-10-06 14:11:46 +0200 | [diff] [blame] | 435 | void (*config_mac_addr) (struct rt2x00_dev *rt2x00dev, __le32 *mac); | 
|  | 436 | void (*config_bssid) (struct rt2x00_dev *rt2x00dev, __le32 *bssid); | 
| Ivo van Doorn | feb2469 | 2007-10-06 14:14:29 +0200 | [diff] [blame] | 437 | void (*config_type) (struct rt2x00_dev *rt2x00dev, const int type, | 
|  | 438 | const int tsf_sync); | 
| Ivo van Doorn | 5c58ee5 | 2007-10-06 13:34:52 +0200 | [diff] [blame] | 439 | void (*config_preamble) (struct rt2x00_dev *rt2x00dev, | 
|  | 440 | const int short_preamble, | 
|  | 441 | const int ack_timeout, | 
|  | 442 | const int ack_consume_time); | 
| Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 443 | void (*config) (struct rt2x00_dev *rt2x00dev, const unsigned int flags, | 
| Ivo van Doorn | 5c58ee5 | 2007-10-06 13:34:52 +0200 | [diff] [blame] | 444 | struct rt2x00lib_conf *libconf); | 
| Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 445 | #define CONFIG_UPDATE_PHYMODE		( 1 << 1 ) | 
|  | 446 | #define CONFIG_UPDATE_CHANNEL		( 1 << 2 ) | 
|  | 447 | #define CONFIG_UPDATE_TXPOWER		( 1 << 3 ) | 
|  | 448 | #define CONFIG_UPDATE_ANTENNA		( 1 << 4 ) | 
|  | 449 | #define CONFIG_UPDATE_SLOT_TIME 	( 1 << 5 ) | 
|  | 450 | #define CONFIG_UPDATE_BEACON_INT	( 1 << 6 ) | 
|  | 451 | #define CONFIG_UPDATE_ALL		0xffff | 
|  | 452 | }; | 
|  | 453 |  | 
|  | 454 | /* | 
|  | 455 | * rt2x00 driver callback operation structure. | 
|  | 456 | */ | 
|  | 457 | struct rt2x00_ops { | 
|  | 458 | const char *name; | 
|  | 459 | const unsigned int rxd_size; | 
|  | 460 | const unsigned int txd_size; | 
|  | 461 | const unsigned int eeprom_size; | 
|  | 462 | const unsigned int rf_size; | 
|  | 463 | const struct rt2x00lib_ops *lib; | 
|  | 464 | const struct ieee80211_ops *hw; | 
|  | 465 | #ifdef CONFIG_RT2X00_LIB_DEBUGFS | 
|  | 466 | const struct rt2x00debug *debugfs; | 
|  | 467 | #endif /* CONFIG_RT2X00_LIB_DEBUGFS */ | 
|  | 468 | }; | 
|  | 469 |  | 
|  | 470 | /* | 
| Ivo van Doorn | 483272f | 2007-10-06 14:13:06 +0200 | [diff] [blame] | 471 | * rt2x00 device flags | 
|  | 472 | */ | 
|  | 473 | enum rt2x00_flags { | 
|  | 474 | /* | 
|  | 475 | * Device state flags | 
|  | 476 | */ | 
|  | 477 | DEVICE_PRESENT, | 
|  | 478 | DEVICE_REGISTERED_HW, | 
|  | 479 | DEVICE_INITIALIZED, | 
|  | 480 | DEVICE_STARTED, | 
|  | 481 | DEVICE_STARTED_SUSPEND, | 
|  | 482 | DEVICE_ENABLED_RADIO, | 
| Ivo van Doorn | 81873e9 | 2007-10-06 14:14:06 +0200 | [diff] [blame] | 483 | DEVICE_DISABLED_RADIO_HW, | 
| Ivo van Doorn | 483272f | 2007-10-06 14:13:06 +0200 | [diff] [blame] | 484 |  | 
|  | 485 | /* | 
|  | 486 | * Driver features | 
|  | 487 | */ | 
|  | 488 | DRIVER_REQUIRE_FIRMWARE, | 
|  | 489 | DRIVER_REQUIRE_BEACON_RING, | 
|  | 490 |  | 
|  | 491 | /* | 
|  | 492 | * Driver configuration | 
|  | 493 | */ | 
|  | 494 | CONFIG_SUPPORT_HW_BUTTON, | 
|  | 495 | CONFIG_FRAME_TYPE, | 
|  | 496 | CONFIG_RF_SEQUENCE, | 
|  | 497 | CONFIG_EXTERNAL_LNA_A, | 
|  | 498 | CONFIG_EXTERNAL_LNA_BG, | 
|  | 499 | CONFIG_DOUBLE_ANTENNA, | 
|  | 500 | CONFIG_DISABLE_LINK_TUNING, | 
| Ivo van Doorn | 5c58ee5 | 2007-10-06 13:34:52 +0200 | [diff] [blame] | 501 | CONFIG_SHORT_PREAMBLE, | 
| Ivo van Doorn | 483272f | 2007-10-06 14:13:06 +0200 | [diff] [blame] | 502 | }; | 
|  | 503 |  | 
|  | 504 | /* | 
| Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 505 | * rt2x00 device structure. | 
|  | 506 | */ | 
|  | 507 | struct rt2x00_dev { | 
|  | 508 | /* | 
|  | 509 | * Device structure. | 
|  | 510 | * The structure stored in here depends on the | 
|  | 511 | * system bus (PCI or USB). | 
|  | 512 | * When accessing this variable, the rt2x00dev_{pci,usb} | 
|  | 513 | * macro's should be used for correct typecasting. | 
|  | 514 | */ | 
|  | 515 | void *dev; | 
|  | 516 | #define rt2x00dev_pci(__dev)	( (struct pci_dev*)(__dev)->dev ) | 
|  | 517 | #define rt2x00dev_usb(__dev)	( (struct usb_interface*)(__dev)->dev ) | 
|  | 518 |  | 
|  | 519 | /* | 
|  | 520 | * Callback functions. | 
|  | 521 | */ | 
|  | 522 | const struct rt2x00_ops *ops; | 
|  | 523 |  | 
|  | 524 | /* | 
|  | 525 | * IEEE80211 control structure. | 
|  | 526 | */ | 
|  | 527 | struct ieee80211_hw *hw; | 
|  | 528 | struct ieee80211_hw_mode *hwmodes; | 
|  | 529 | unsigned int curr_hwmode; | 
|  | 530 | #define HWMODE_B	0 | 
|  | 531 | #define HWMODE_G	1 | 
|  | 532 | #define HWMODE_A	2 | 
|  | 533 |  | 
|  | 534 | /* | 
|  | 535 | * rfkill structure for RF state switching support. | 
|  | 536 | * This will only be compiled in when required. | 
|  | 537 | */ | 
|  | 538 | #ifdef CONFIG_RT2X00_LIB_RFKILL | 
|  | 539 | struct rfkill *rfkill; | 
|  | 540 | struct input_polled_dev *poll_dev; | 
|  | 541 | #endif /* CONFIG_RT2X00_LIB_RFKILL */ | 
|  | 542 |  | 
|  | 543 | /* | 
|  | 544 | * If enabled, the debugfs interface structures | 
|  | 545 | * required for deregistration of debugfs. | 
|  | 546 | */ | 
|  | 547 | #ifdef CONFIG_RT2X00_LIB_DEBUGFS | 
|  | 548 | const struct rt2x00debug_intf *debugfs_intf; | 
|  | 549 | #endif /* CONFIG_RT2X00_LIB_DEBUGFS */ | 
|  | 550 |  | 
|  | 551 | /* | 
|  | 552 | * Device flags. | 
|  | 553 | * In these flags the current status and some | 
|  | 554 | * of the device capabilities are stored. | 
|  | 555 | */ | 
|  | 556 | unsigned long flags; | 
| Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 557 |  | 
|  | 558 | /* | 
|  | 559 | * Chipset identification. | 
|  | 560 | */ | 
|  | 561 | struct rt2x00_chip chip; | 
|  | 562 |  | 
|  | 563 | /* | 
|  | 564 | * hw capability specifications. | 
|  | 565 | */ | 
|  | 566 | struct hw_mode_spec spec; | 
|  | 567 |  | 
|  | 568 | /* | 
|  | 569 | * Register pointers | 
|  | 570 | * csr_addr: Base register address. (PCI) | 
|  | 571 | * csr_cache: CSR cache for usb_control_msg. (USB) | 
|  | 572 | */ | 
|  | 573 | void __iomem *csr_addr; | 
|  | 574 | void *csr_cache; | 
|  | 575 |  | 
|  | 576 | /* | 
|  | 577 | * Interface configuration. | 
|  | 578 | */ | 
|  | 579 | struct interface interface; | 
|  | 580 |  | 
|  | 581 | /* | 
|  | 582 | * Link quality | 
|  | 583 | */ | 
|  | 584 | struct link link; | 
|  | 585 |  | 
|  | 586 | /* | 
|  | 587 | * EEPROM data. | 
|  | 588 | */ | 
|  | 589 | __le16 *eeprom; | 
|  | 590 |  | 
|  | 591 | /* | 
|  | 592 | * Active RF register values. | 
|  | 593 | * These are stored here so we don't need | 
|  | 594 | * to read the rf registers and can directly | 
|  | 595 | * use this value instead. | 
|  | 596 | * This field should be accessed by using | 
|  | 597 | * rt2x00_rf_read() and rt2x00_rf_write(). | 
|  | 598 | */ | 
|  | 599 | u32 *rf; | 
|  | 600 |  | 
|  | 601 | /* | 
|  | 602 | * Current TX power value. | 
|  | 603 | */ | 
|  | 604 | u16 tx_power; | 
|  | 605 |  | 
|  | 606 | /* | 
|  | 607 | * LED register (for rt61pci & rt73usb). | 
|  | 608 | */ | 
|  | 609 | u16 led_reg; | 
|  | 610 |  | 
|  | 611 | /* | 
|  | 612 | * Led mode (LED_MODE_*) | 
|  | 613 | */ | 
|  | 614 | u8 led_mode; | 
|  | 615 |  | 
|  | 616 | /* | 
|  | 617 | * Rssi <-> Dbm offset | 
|  | 618 | */ | 
|  | 619 | u8 rssi_offset; | 
|  | 620 |  | 
|  | 621 | /* | 
|  | 622 | * Frequency offset (for rt61pci & rt73usb). | 
|  | 623 | */ | 
|  | 624 | u8 freq_offset; | 
|  | 625 |  | 
|  | 626 | /* | 
|  | 627 | * Low level statistics which will have | 
|  | 628 | * to be kept up to date while device is running. | 
|  | 629 | */ | 
|  | 630 | struct ieee80211_low_level_stats low_level_stats; | 
|  | 631 |  | 
|  | 632 | /* | 
|  | 633 | * RX configuration information. | 
|  | 634 | */ | 
|  | 635 | struct ieee80211_rx_status rx_status; | 
|  | 636 |  | 
|  | 637 | /* | 
| Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 638 | * Scheduled work. | 
| Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 639 | */ | 
|  | 640 | struct work_struct beacon_work; | 
| Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 641 | struct work_struct filter_work; | 
| Ivo van Doorn | 5c58ee5 | 2007-10-06 13:34:52 +0200 | [diff] [blame] | 642 | struct work_struct config_work; | 
| Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 643 |  | 
|  | 644 | /* | 
|  | 645 | * Data ring arrays for RX, TX and Beacon. | 
|  | 646 | * The Beacon array also contains the Atim ring | 
|  | 647 | * if that is supported by the device. | 
|  | 648 | */ | 
|  | 649 | int data_rings; | 
|  | 650 | struct data_ring *rx; | 
|  | 651 | struct data_ring *tx; | 
|  | 652 | struct data_ring *bcn; | 
|  | 653 |  | 
|  | 654 | /* | 
|  | 655 | * Firmware image. | 
|  | 656 | */ | 
|  | 657 | const struct firmware *fw; | 
|  | 658 | }; | 
|  | 659 |  | 
|  | 660 | /* | 
|  | 661 | * For-each loop for the ring array. | 
|  | 662 | * All rings have been allocated as a single array, | 
|  | 663 | * this means we can create a very simply loop macro | 
|  | 664 | * that is capable of looping through all rings. | 
|  | 665 | * ring_end(), txring_end() and ring_loop() are helper macro's which | 
|  | 666 | * should not be used directly. Instead the following should be used: | 
|  | 667 | * ring_for_each() - Loops through all rings (RX, TX, Beacon & Atim) | 
|  | 668 | * txring_for_each() - Loops through TX data rings (TX only) | 
|  | 669 | * txringall_for_each() - Loops through all TX rings (TX, Beacon & Atim) | 
|  | 670 | */ | 
|  | 671 | #define ring_end(__dev) \ | 
|  | 672 | &(__dev)->rx[(__dev)->data_rings] | 
|  | 673 |  | 
|  | 674 | #define txring_end(__dev) \ | 
|  | 675 | &(__dev)->tx[(__dev)->hw->queues] | 
|  | 676 |  | 
|  | 677 | #define ring_loop(__entry, __start, __end)			\ | 
|  | 678 | for ((__entry) = (__start);				\ | 
|  | 679 | prefetch(&(__entry)[1]), (__entry) != (__end);	\ | 
|  | 680 | (__entry) = &(__entry)[1]) | 
|  | 681 |  | 
|  | 682 | #define ring_for_each(__dev, __entry) \ | 
|  | 683 | ring_loop(__entry, (__dev)->rx, ring_end(__dev)) | 
|  | 684 |  | 
|  | 685 | #define txring_for_each(__dev, __entry) \ | 
|  | 686 | ring_loop(__entry, (__dev)->tx, txring_end(__dev)) | 
|  | 687 |  | 
|  | 688 | #define txringall_for_each(__dev, __entry) \ | 
|  | 689 | ring_loop(__entry, (__dev)->tx, ring_end(__dev)) | 
|  | 690 |  | 
|  | 691 | /* | 
|  | 692 | * Generic RF access. | 
|  | 693 | * The RF is being accessed by word index. | 
|  | 694 | */ | 
|  | 695 | static inline void rt2x00_rf_read(const struct rt2x00_dev *rt2x00dev, | 
|  | 696 | const unsigned int word, u32 *data) | 
|  | 697 | { | 
|  | 698 | *data = rt2x00dev->rf[word]; | 
|  | 699 | } | 
|  | 700 |  | 
|  | 701 | static inline void rt2x00_rf_write(const struct rt2x00_dev *rt2x00dev, | 
|  | 702 | const unsigned int word, u32 data) | 
|  | 703 | { | 
|  | 704 | rt2x00dev->rf[word] = data; | 
|  | 705 | } | 
|  | 706 |  | 
|  | 707 | /* | 
|  | 708 | *  Generic EEPROM access. | 
|  | 709 | * The EEPROM is being accessed by word index. | 
|  | 710 | */ | 
|  | 711 | static inline void *rt2x00_eeprom_addr(const struct rt2x00_dev *rt2x00dev, | 
|  | 712 | const unsigned int word) | 
|  | 713 | { | 
|  | 714 | return (void *)&rt2x00dev->eeprom[word]; | 
|  | 715 | } | 
|  | 716 |  | 
|  | 717 | static inline void rt2x00_eeprom_read(const struct rt2x00_dev *rt2x00dev, | 
|  | 718 | const unsigned int word, u16 *data) | 
|  | 719 | { | 
|  | 720 | *data = le16_to_cpu(rt2x00dev->eeprom[word]); | 
|  | 721 | } | 
|  | 722 |  | 
|  | 723 | static inline void rt2x00_eeprom_write(const struct rt2x00_dev *rt2x00dev, | 
|  | 724 | const unsigned int word, u16 data) | 
|  | 725 | { | 
|  | 726 | rt2x00dev->eeprom[word] = cpu_to_le16(data); | 
|  | 727 | } | 
|  | 728 |  | 
|  | 729 | /* | 
|  | 730 | * Chipset handlers | 
|  | 731 | */ | 
|  | 732 | static inline void rt2x00_set_chip(struct rt2x00_dev *rt2x00dev, | 
|  | 733 | const u16 rt, const u16 rf, const u32 rev) | 
|  | 734 | { | 
|  | 735 | INFO(rt2x00dev, | 
|  | 736 | "Chipset detected - rt: %04x, rf: %04x, rev: %08x.\n", | 
|  | 737 | rt, rf, rev); | 
|  | 738 |  | 
|  | 739 | rt2x00dev->chip.rt = rt; | 
|  | 740 | rt2x00dev->chip.rf = rf; | 
|  | 741 | rt2x00dev->chip.rev = rev; | 
|  | 742 | } | 
|  | 743 |  | 
|  | 744 | static inline char rt2x00_rt(const struct rt2x00_chip *chipset, const u16 chip) | 
|  | 745 | { | 
|  | 746 | return (chipset->rt == chip); | 
|  | 747 | } | 
|  | 748 |  | 
|  | 749 | static inline char rt2x00_rf(const struct rt2x00_chip *chipset, const u16 chip) | 
|  | 750 | { | 
|  | 751 | return (chipset->rf == chip); | 
|  | 752 | } | 
|  | 753 |  | 
|  | 754 | static inline u16 rt2x00_get_rev(const struct rt2x00_chip *chipset) | 
|  | 755 | { | 
|  | 756 | return chipset->rev; | 
|  | 757 | } | 
|  | 758 |  | 
|  | 759 | static inline u16 rt2x00_rev(const struct rt2x00_chip *chipset, const u32 mask) | 
|  | 760 | { | 
|  | 761 | return chipset->rev & mask; | 
|  | 762 | } | 
|  | 763 |  | 
|  | 764 | /* | 
|  | 765 | * Duration calculations | 
|  | 766 | * The rate variable passed is: 100kbs. | 
|  | 767 | * To convert from bytes to bits we multiply size with 8, | 
|  | 768 | * then the size is multiplied with 10 to make the | 
|  | 769 | * real rate -> rate argument correction. | 
|  | 770 | */ | 
|  | 771 | static inline u16 get_duration(const unsigned int size, const u8 rate) | 
|  | 772 | { | 
|  | 773 | return ((size * 8 * 10) / rate); | 
|  | 774 | } | 
|  | 775 |  | 
|  | 776 | static inline u16 get_duration_res(const unsigned int size, const u8 rate) | 
|  | 777 | { | 
|  | 778 | return ((size * 8 * 10) % rate); | 
|  | 779 | } | 
|  | 780 |  | 
|  | 781 | /* | 
|  | 782 | * Library functions. | 
|  | 783 | */ | 
|  | 784 | struct data_ring *rt2x00lib_get_ring(struct rt2x00_dev *rt2x00dev, | 
|  | 785 | const unsigned int queue); | 
|  | 786 |  | 
|  | 787 | /* | 
|  | 788 | * Interrupt context handlers. | 
|  | 789 | */ | 
|  | 790 | void rt2x00lib_beacondone(struct rt2x00_dev *rt2x00dev); | 
|  | 791 | void rt2x00lib_txdone(struct data_entry *entry, | 
|  | 792 | const int status, const int retry); | 
|  | 793 | void rt2x00lib_rxdone(struct data_entry *entry, struct sk_buff *skb, | 
| Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 794 | struct rxdata_entry_desc *desc); | 
| Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 795 |  | 
|  | 796 | /* | 
|  | 797 | * TX descriptor initializer | 
|  | 798 | */ | 
|  | 799 | void rt2x00lib_write_tx_desc(struct rt2x00_dev *rt2x00dev, | 
|  | 800 | struct data_desc *txd, | 
|  | 801 | struct ieee80211_hdr *ieee80211hdr, | 
|  | 802 | unsigned int length, | 
|  | 803 | struct ieee80211_tx_control *control); | 
|  | 804 |  | 
|  | 805 | /* | 
|  | 806 | * mac80211 handlers. | 
|  | 807 | */ | 
|  | 808 | int rt2x00mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb, | 
|  | 809 | struct ieee80211_tx_control *control); | 
|  | 810 | int rt2x00mac_start(struct ieee80211_hw *hw); | 
|  | 811 | void rt2x00mac_stop(struct ieee80211_hw *hw); | 
|  | 812 | int rt2x00mac_add_interface(struct ieee80211_hw *hw, | 
|  | 813 | struct ieee80211_if_init_conf *conf); | 
|  | 814 | void rt2x00mac_remove_interface(struct ieee80211_hw *hw, | 
|  | 815 | struct ieee80211_if_init_conf *conf); | 
|  | 816 | int rt2x00mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf); | 
|  | 817 | int rt2x00mac_config_interface(struct ieee80211_hw *hw, int if_id, | 
|  | 818 | struct ieee80211_if_conf *conf); | 
| Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 819 | int rt2x00mac_get_stats(struct ieee80211_hw *hw, | 
|  | 820 | struct ieee80211_low_level_stats *stats); | 
|  | 821 | int rt2x00mac_get_tx_stats(struct ieee80211_hw *hw, | 
|  | 822 | struct ieee80211_tx_queue_stats *stats); | 
| Ivo van Doorn | 5c58ee5 | 2007-10-06 13:34:52 +0200 | [diff] [blame] | 823 | void rt2x00mac_erp_ie_changed(struct ieee80211_hw *hw, u8 changes, | 
|  | 824 | int cts_protection, int preamble); | 
| Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 825 | int rt2x00mac_conf_tx(struct ieee80211_hw *hw, int queue, | 
|  | 826 | const struct ieee80211_tx_queue_params *params); | 
|  | 827 |  | 
|  | 828 | /* | 
|  | 829 | * Driver allocation handlers. | 
|  | 830 | */ | 
|  | 831 | int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev); | 
|  | 832 | void rt2x00lib_remove_dev(struct rt2x00_dev *rt2x00dev); | 
|  | 833 | #ifdef CONFIG_PM | 
|  | 834 | int rt2x00lib_suspend(struct rt2x00_dev *rt2x00dev, pm_message_t state); | 
|  | 835 | int rt2x00lib_resume(struct rt2x00_dev *rt2x00dev); | 
|  | 836 | #endif /* CONFIG_PM */ | 
|  | 837 |  | 
|  | 838 | #endif /* RT2X00_H */ |