rt2x00.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215
  1. /*
  2. Copyright (C) 2010 Willow Garage <http://www.willowgarage.com>
  3. Copyright (C) 2004 - 2010 Ivo van Doorn <IvDoorn@gmail.com>
  4. Copyright (C) 2004 - 2009 Gertjan van Wingerde <gwingerde@gmail.com>
  5. <http://rt2x00.serialmonkey.com>
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  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. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the
  16. Free Software Foundation, Inc.,
  17. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19. /*
  20. Module: rt2x00
  21. Abstract: rt2x00 global information.
  22. */
  23. #ifndef RT2X00_H
  24. #define RT2X00_H
  25. #include <linux/bitops.h>
  26. #include <linux/skbuff.h>
  27. #include <linux/workqueue.h>
  28. #include <linux/firmware.h>
  29. #include <linux/leds.h>
  30. #include <linux/mutex.h>
  31. #include <linux/etherdevice.h>
  32. #include <linux/input-polldev.h>
  33. #include <linux/kfifo.h>
  34. #include <net/mac80211.h>
  35. #include "rt2x00debug.h"
  36. #include "rt2x00dump.h"
  37. #include "rt2x00leds.h"
  38. #include "rt2x00reg.h"
  39. #include "rt2x00queue.h"
  40. /*
  41. * Module information.
  42. */
  43. #define DRV_VERSION "2.3.0"
  44. #define DRV_PROJECT "http://rt2x00.serialmonkey.com"
  45. /*
  46. * Debug definitions.
  47. * Debug output has to be enabled during compile time.
  48. */
  49. #define DEBUG_PRINTK_MSG(__dev, __kernlvl, __lvl, __msg, __args...) \
  50. printk(__kernlvl "%s -> %s: %s - " __msg, \
  51. wiphy_name((__dev)->hw->wiphy), __func__, __lvl, ##__args)
  52. #define DEBUG_PRINTK_PROBE(__kernlvl, __lvl, __msg, __args...) \
  53. printk(__kernlvl "%s -> %s: %s - " __msg, \
  54. KBUILD_MODNAME, __func__, __lvl, ##__args)
  55. #ifdef CONFIG_RT2X00_DEBUG
  56. #define DEBUG_PRINTK(__dev, __kernlvl, __lvl, __msg, __args...) \
  57. DEBUG_PRINTK_MSG(__dev, __kernlvl, __lvl, __msg, ##__args)
  58. #else
  59. #define DEBUG_PRINTK(__dev, __kernlvl, __lvl, __msg, __args...) \
  60. do { } while (0)
  61. #endif /* CONFIG_RT2X00_DEBUG */
  62. /*
  63. * Various debug levels.
  64. * The debug levels PANIC and ERROR both indicate serious problems,
  65. * for this reason they should never be ignored.
  66. * The special ERROR_PROBE message is for messages that are generated
  67. * when the rt2x00_dev is not yet initialized.
  68. */
  69. #define PANIC(__dev, __msg, __args...) \
  70. DEBUG_PRINTK_MSG(__dev, KERN_CRIT, "Panic", __msg, ##__args)
  71. #define ERROR(__dev, __msg, __args...) \
  72. DEBUG_PRINTK_MSG(__dev, KERN_ERR, "Error", __msg, ##__args)
  73. #define ERROR_PROBE(__msg, __args...) \
  74. DEBUG_PRINTK_PROBE(KERN_ERR, "Error", __msg, ##__args)
  75. #define WARNING(__dev, __msg, __args...) \
  76. DEBUG_PRINTK(__dev, KERN_WARNING, "Warning", __msg, ##__args)
  77. #define NOTICE(__dev, __msg, __args...) \
  78. DEBUG_PRINTK(__dev, KERN_NOTICE, "Notice", __msg, ##__args)
  79. #define INFO(__dev, __msg, __args...) \
  80. DEBUG_PRINTK(__dev, KERN_INFO, "Info", __msg, ##__args)
  81. #define DEBUG(__dev, __msg, __args...) \
  82. DEBUG_PRINTK(__dev, KERN_DEBUG, "Debug", __msg, ##__args)
  83. #define EEPROM(__dev, __msg, __args...) \
  84. DEBUG_PRINTK(__dev, KERN_DEBUG, "EEPROM recovery", __msg, ##__args)
  85. /*
  86. * Duration calculations
  87. * The rate variable passed is: 100kbs.
  88. * To convert from bytes to bits we multiply size with 8,
  89. * then the size is multiplied with 10 to make the
  90. * real rate -> rate argument correction.
  91. */
  92. #define GET_DURATION(__size, __rate) (((__size) * 8 * 10) / (__rate))
  93. #define GET_DURATION_RES(__size, __rate)(((__size) * 8 * 10) % (__rate))
  94. /*
  95. * Determine the number of L2 padding bytes required between the header and
  96. * the payload.
  97. */
  98. #define L2PAD_SIZE(__hdrlen) (-(__hdrlen) & 3)
  99. /*
  100. * Determine the alignment requirement,
  101. * to make sure the 802.11 payload is padded to a 4-byte boundrary
  102. * we must determine the address of the payload and calculate the
  103. * amount of bytes needed to move the data.
  104. */
  105. #define ALIGN_SIZE(__skb, __header) \
  106. ( ((unsigned long)((__skb)->data + (__header))) & 3 )
  107. /*
  108. * Constants for extra TX headroom for alignment purposes.
  109. */
  110. #define RT2X00_ALIGN_SIZE 4 /* Only whole frame needs alignment */
  111. #define RT2X00_L2PAD_SIZE 8 /* Both header & payload need alignment */
  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 + DIFS + \
  130. GET_DURATION(IEEE80211_HEADER + ACK_SIZE, 10) )
  131. #define SHORT_EIFS ( SIFS + SHORT_DIFS + \
  132. GET_DURATION(IEEE80211_HEADER + ACK_SIZE, 10) )
  133. /*
  134. * Structure for average calculation
  135. * The avg field contains the actual average value,
  136. * but avg_weight is internally used during calculations
  137. * to prevent rounding errors.
  138. */
  139. struct avg_val {
  140. int avg;
  141. int avg_weight;
  142. };
  143. enum rt2x00_chip_intf {
  144. RT2X00_CHIP_INTF_PCI,
  145. RT2X00_CHIP_INTF_PCIE,
  146. RT2X00_CHIP_INTF_USB,
  147. RT2X00_CHIP_INTF_SOC,
  148. };
  149. /*
  150. * Chipset identification
  151. * The chipset on the device is composed of a RT and RF chip.
  152. * The chipset combination is important for determining device capabilities.
  153. */
  154. struct rt2x00_chip {
  155. u16 rt;
  156. #define RT2460 0x2460
  157. #define RT2560 0x2560
  158. #define RT2570 0x2570
  159. #define RT2661 0x2661
  160. #define RT2573 0x2573
  161. #define RT2860 0x2860 /* 2.4GHz */
  162. #define RT2872 0x2872 /* WSOC */
  163. #define RT2883 0x2883 /* WSOC */
  164. #define RT3070 0x3070
  165. #define RT3071 0x3071
  166. #define RT3090 0x3090 /* 2.4GHz PCIe */
  167. #define RT3390 0x3390
  168. #define RT3572 0x3572
  169. #define RT3593 0x3593 /* PCIe */
  170. #define RT3883 0x3883 /* WSOC */
  171. u16 rf;
  172. u16 rev;
  173. enum rt2x00_chip_intf intf;
  174. };
  175. /*
  176. * RF register values that belong to a particular channel.
  177. */
  178. struct rf_channel {
  179. int channel;
  180. u32 rf1;
  181. u32 rf2;
  182. u32 rf3;
  183. u32 rf4;
  184. };
  185. /*
  186. * Channel information structure
  187. */
  188. struct channel_info {
  189. unsigned int flags;
  190. #define GEOGRAPHY_ALLOWED 0x00000001
  191. short max_power;
  192. short default_power1;
  193. short default_power2;
  194. };
  195. /*
  196. * Antenna setup values.
  197. */
  198. struct antenna_setup {
  199. enum antenna rx;
  200. enum antenna tx;
  201. };
  202. /*
  203. * Quality statistics about the currently active link.
  204. */
  205. struct link_qual {
  206. /*
  207. * Statistics required for Link tuning by driver
  208. * The rssi value is provided by rt2x00lib during the
  209. * link_tuner() callback function.
  210. * The false_cca field is filled during the link_stats()
  211. * callback function and could be used during the
  212. * link_tuner() callback function.
  213. */
  214. int rssi;
  215. int false_cca;
  216. /*
  217. * VGC levels
  218. * Hardware driver will tune the VGC level during each call
  219. * to the link_tuner() callback function. This vgc_level is
  220. * is determined based on the link quality statistics like
  221. * average RSSI and the false CCA count.
  222. *
  223. * In some cases the drivers need to differentiate between
  224. * the currently "desired" VGC level and the level configured
  225. * in the hardware. The latter is important to reduce the
  226. * number of BBP register reads to reduce register access
  227. * overhead. For this reason we store both values here.
  228. */
  229. u8 vgc_level;
  230. u8 vgc_level_reg;
  231. /*
  232. * Statistics required for Signal quality calculation.
  233. * These fields might be changed during the link_stats()
  234. * callback function.
  235. */
  236. int rx_success;
  237. int rx_failed;
  238. int tx_success;
  239. int tx_failed;
  240. };
  241. /*
  242. * Antenna settings about the currently active link.
  243. */
  244. struct link_ant {
  245. /*
  246. * Antenna flags
  247. */
  248. unsigned int flags;
  249. #define ANTENNA_RX_DIVERSITY 0x00000001
  250. #define ANTENNA_TX_DIVERSITY 0x00000002
  251. #define ANTENNA_MODE_SAMPLE 0x00000004
  252. /*
  253. * Currently active TX/RX antenna setup.
  254. * When software diversity is used, this will indicate
  255. * which antenna is actually used at this time.
  256. */
  257. struct antenna_setup active;
  258. /*
  259. * RSSI history information for the antenna.
  260. * Used to determine when to switch antenna
  261. * when using software diversity.
  262. */
  263. int rssi_history;
  264. /*
  265. * Current RSSI average of the currently active antenna.
  266. * Similar to the avg_rssi in the link_qual structure
  267. * this value is updated by using the walking average.
  268. */
  269. struct avg_val rssi_ant;
  270. };
  271. /*
  272. * To optimize the quality of the link we need to store
  273. * the quality of received frames and periodically
  274. * optimize the link.
  275. */
  276. struct link {
  277. /*
  278. * Link tuner counter
  279. * The number of times the link has been tuned
  280. * since the radio has been switched on.
  281. */
  282. u32 count;
  283. /*
  284. * Quality measurement values.
  285. */
  286. struct link_qual qual;
  287. /*
  288. * TX/RX antenna setup.
  289. */
  290. struct link_ant ant;
  291. /*
  292. * Currently active average RSSI value
  293. */
  294. struct avg_val avg_rssi;
  295. /*
  296. * Work structure for scheduling periodic link tuning.
  297. */
  298. struct delayed_work work;
  299. /*
  300. * Work structure for scheduling periodic watchdog monitoring.
  301. * This work must be scheduled on the kernel workqueue, while
  302. * all other work structures must be queued on the mac80211
  303. * workqueue. This guarantees that the watchdog can schedule
  304. * other work structures and wait for their completion in order
  305. * to bring the device/driver back into the desired state.
  306. */
  307. struct delayed_work watchdog_work;
  308. };
  309. enum rt2x00_delayed_flags {
  310. DELAYED_UPDATE_BEACON,
  311. };
  312. /*
  313. * Interface structure
  314. * Per interface configuration details, this structure
  315. * is allocated as the private data for ieee80211_vif.
  316. */
  317. struct rt2x00_intf {
  318. /*
  319. * beacon->skb must be protected with the mutex.
  320. */
  321. struct mutex beacon_skb_mutex;
  322. /*
  323. * Entry in the beacon queue which belongs to
  324. * this interface. Each interface has its own
  325. * dedicated beacon entry.
  326. */
  327. struct queue_entry *beacon;
  328. /*
  329. * Actions that needed rescheduling.
  330. */
  331. unsigned long delayed_flags;
  332. /*
  333. * Software sequence counter, this is only required
  334. * for hardware which doesn't support hardware
  335. * sequence counting.
  336. */
  337. spinlock_t seqlock;
  338. u16 seqno;
  339. };
  340. static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
  341. {
  342. return (struct rt2x00_intf *)vif->drv_priv;
  343. }
  344. /**
  345. * struct hw_mode_spec: Hardware specifications structure
  346. *
  347. * Details about the supported modes, rates and channels
  348. * of a particular chipset. This is used by rt2x00lib
  349. * to build the ieee80211_hw_mode array for mac80211.
  350. *
  351. * @supported_bands: Bitmask contained the supported bands (2.4GHz, 5.2GHz).
  352. * @supported_rates: Rate types which are supported (CCK, OFDM).
  353. * @num_channels: Number of supported channels. This is used as array size
  354. * for @tx_power_a, @tx_power_bg and @channels.
  355. * @channels: Device/chipset specific channel values (See &struct rf_channel).
  356. * @channels_info: Additional information for channels (See &struct channel_info).
  357. * @ht: Driver HT Capabilities (See &ieee80211_sta_ht_cap).
  358. */
  359. struct hw_mode_spec {
  360. unsigned int supported_bands;
  361. #define SUPPORT_BAND_2GHZ 0x00000001
  362. #define SUPPORT_BAND_5GHZ 0x00000002
  363. unsigned int supported_rates;
  364. #define SUPPORT_RATE_CCK 0x00000001
  365. #define SUPPORT_RATE_OFDM 0x00000002
  366. unsigned int num_channels;
  367. const struct rf_channel *channels;
  368. const struct channel_info *channels_info;
  369. struct ieee80211_sta_ht_cap ht;
  370. };
  371. /*
  372. * Configuration structure wrapper around the
  373. * mac80211 configuration structure.
  374. * When mac80211 configures the driver, rt2x00lib
  375. * can precalculate values which are equal for all
  376. * rt2x00 drivers. Those values can be stored in here.
  377. */
  378. struct rt2x00lib_conf {
  379. struct ieee80211_conf *conf;
  380. struct rf_channel rf;
  381. struct channel_info channel;
  382. };
  383. /*
  384. * Configuration structure for erp settings.
  385. */
  386. struct rt2x00lib_erp {
  387. int short_preamble;
  388. int cts_protection;
  389. u32 basic_rates;
  390. int slot_time;
  391. short sifs;
  392. short pifs;
  393. short difs;
  394. short eifs;
  395. u16 beacon_int;
  396. u16 ht_opmode;
  397. };
  398. /*
  399. * Configuration structure for hardware encryption.
  400. */
  401. struct rt2x00lib_crypto {
  402. enum cipher cipher;
  403. enum set_key_cmd cmd;
  404. const u8 *address;
  405. u32 bssidx;
  406. u32 aid;
  407. u8 key[16];
  408. u8 tx_mic[8];
  409. u8 rx_mic[8];
  410. };
  411. /*
  412. * Configuration structure wrapper around the
  413. * rt2x00 interface configuration handler.
  414. */
  415. struct rt2x00intf_conf {
  416. /*
  417. * Interface type
  418. */
  419. enum nl80211_iftype type;
  420. /*
  421. * TSF sync value, this is dependant on the operation type.
  422. */
  423. enum tsf_sync sync;
  424. /*
  425. * The MAC and BSSID addressess are simple array of bytes,
  426. * these arrays are little endian, so when sending the addressess
  427. * to the drivers, copy the it into a endian-signed variable.
  428. *
  429. * Note that all devices (except rt2500usb) have 32 bits
  430. * register word sizes. This means that whatever variable we
  431. * pass _must_ be a multiple of 32 bits. Otherwise the device
  432. * might not accept what we are sending to it.
  433. * This will also make it easier for the driver to write
  434. * the data to the device.
  435. */
  436. __le32 mac[2];
  437. __le32 bssid[2];
  438. };
  439. /*
  440. * rt2x00lib callback functions.
  441. */
  442. struct rt2x00lib_ops {
  443. /*
  444. * Interrupt handlers.
  445. */
  446. irq_handler_t irq_handler;
  447. /*
  448. * Threaded Interrupt handlers.
  449. */
  450. irq_handler_t irq_handler_thread;
  451. /*
  452. * TX status tasklet handler.
  453. */
  454. void (*txstatus_tasklet) (unsigned long data);
  455. /*
  456. * Device init handlers.
  457. */
  458. int (*probe_hw) (struct rt2x00_dev *rt2x00dev);
  459. char *(*get_firmware_name) (struct rt2x00_dev *rt2x00dev);
  460. int (*check_firmware) (struct rt2x00_dev *rt2x00dev,
  461. const u8 *data, const size_t len);
  462. int (*load_firmware) (struct rt2x00_dev *rt2x00dev,
  463. const u8 *data, const size_t len);
  464. /*
  465. * Device initialization/deinitialization handlers.
  466. */
  467. int (*initialize) (struct rt2x00_dev *rt2x00dev);
  468. void (*uninitialize) (struct rt2x00_dev *rt2x00dev);
  469. /*
  470. * queue initialization handlers
  471. */
  472. bool (*get_entry_state) (struct queue_entry *entry);
  473. void (*clear_entry) (struct queue_entry *entry);
  474. /*
  475. * Radio control handlers.
  476. */
  477. int (*set_device_state) (struct rt2x00_dev *rt2x00dev,
  478. enum dev_state state);
  479. int (*rfkill_poll) (struct rt2x00_dev *rt2x00dev);
  480. void (*link_stats) (struct rt2x00_dev *rt2x00dev,
  481. struct link_qual *qual);
  482. void (*reset_tuner) (struct rt2x00_dev *rt2x00dev,
  483. struct link_qual *qual);
  484. void (*link_tuner) (struct rt2x00_dev *rt2x00dev,
  485. struct link_qual *qual, const u32 count);
  486. /*
  487. * Data queue handlers.
  488. */
  489. void (*watchdog) (struct rt2x00_dev *rt2x00dev);
  490. void (*start_queue) (struct data_queue *queue);
  491. void (*kick_queue) (struct data_queue *queue);
  492. void (*stop_queue) (struct data_queue *queue);
  493. void (*flush_queue) (struct data_queue *queue);
  494. /*
  495. * TX control handlers
  496. */
  497. void (*write_tx_desc) (struct queue_entry *entry,
  498. struct txentry_desc *txdesc);
  499. void (*write_tx_data) (struct queue_entry *entry,
  500. struct txentry_desc *txdesc);
  501. void (*write_beacon) (struct queue_entry *entry,
  502. struct txentry_desc *txdesc);
  503. int (*get_tx_data_len) (struct queue_entry *entry);
  504. /*
  505. * RX control handlers
  506. */
  507. void (*fill_rxdone) (struct queue_entry *entry,
  508. struct rxdone_entry_desc *rxdesc);
  509. /*
  510. * Configuration handlers.
  511. */
  512. int (*config_shared_key) (struct rt2x00_dev *rt2x00dev,
  513. struct rt2x00lib_crypto *crypto,
  514. struct ieee80211_key_conf *key);
  515. int (*config_pairwise_key) (struct rt2x00_dev *rt2x00dev,
  516. struct rt2x00lib_crypto *crypto,
  517. struct ieee80211_key_conf *key);
  518. void (*config_filter) (struct rt2x00_dev *rt2x00dev,
  519. const unsigned int filter_flags);
  520. void (*config_intf) (struct rt2x00_dev *rt2x00dev,
  521. struct rt2x00_intf *intf,
  522. struct rt2x00intf_conf *conf,
  523. const unsigned int flags);
  524. #define CONFIG_UPDATE_TYPE ( 1 << 1 )
  525. #define CONFIG_UPDATE_MAC ( 1 << 2 )
  526. #define CONFIG_UPDATE_BSSID ( 1 << 3 )
  527. void (*config_erp) (struct rt2x00_dev *rt2x00dev,
  528. struct rt2x00lib_erp *erp,
  529. u32 changed);
  530. void (*config_ant) (struct rt2x00_dev *rt2x00dev,
  531. struct antenna_setup *ant);
  532. void (*config) (struct rt2x00_dev *rt2x00dev,
  533. struct rt2x00lib_conf *libconf,
  534. const unsigned int changed_flags);
  535. };
  536. /*
  537. * rt2x00 driver callback operation structure.
  538. */
  539. struct rt2x00_ops {
  540. const char *name;
  541. const unsigned int max_sta_intf;
  542. const unsigned int max_ap_intf;
  543. const unsigned int eeprom_size;
  544. const unsigned int rf_size;
  545. const unsigned int tx_queues;
  546. const unsigned int extra_tx_headroom;
  547. const struct data_queue_desc *rx;
  548. const struct data_queue_desc *tx;
  549. const struct data_queue_desc *bcn;
  550. const struct data_queue_desc *atim;
  551. const struct rt2x00lib_ops *lib;
  552. const void *drv;
  553. const struct ieee80211_ops *hw;
  554. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  555. const struct rt2x00debug *debugfs;
  556. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  557. };
  558. /*
  559. * rt2x00 device flags
  560. */
  561. enum rt2x00_flags {
  562. /*
  563. * Device state flags
  564. */
  565. DEVICE_STATE_PRESENT,
  566. DEVICE_STATE_REGISTERED_HW,
  567. DEVICE_STATE_INITIALIZED,
  568. DEVICE_STATE_STARTED,
  569. DEVICE_STATE_ENABLED_RADIO,
  570. DEVICE_STATE_SCANNING,
  571. /*
  572. * Driver requirements
  573. */
  574. DRIVER_REQUIRE_FIRMWARE,
  575. DRIVER_REQUIRE_BEACON_GUARD,
  576. DRIVER_REQUIRE_ATIM_QUEUE,
  577. DRIVER_REQUIRE_DMA,
  578. DRIVER_REQUIRE_COPY_IV,
  579. DRIVER_REQUIRE_L2PAD,
  580. DRIVER_REQUIRE_TXSTATUS_FIFO,
  581. DRIVER_REQUIRE_TASKLET_CONTEXT,
  582. /*
  583. * Driver features
  584. */
  585. CONFIG_SUPPORT_HW_BUTTON,
  586. CONFIG_SUPPORT_HW_CRYPTO,
  587. DRIVER_SUPPORT_CONTROL_FILTERS,
  588. DRIVER_SUPPORT_CONTROL_FILTER_PSPOLL,
  589. DRIVER_SUPPORT_PRE_TBTT_INTERRUPT,
  590. DRIVER_SUPPORT_LINK_TUNING,
  591. DRIVER_SUPPORT_WATCHDOG,
  592. /*
  593. * Driver configuration
  594. */
  595. CONFIG_FRAME_TYPE,
  596. CONFIG_RF_SEQUENCE,
  597. CONFIG_EXTERNAL_LNA_A,
  598. CONFIG_EXTERNAL_LNA_BG,
  599. CONFIG_DOUBLE_ANTENNA,
  600. CONFIG_CHANNEL_HT40,
  601. };
  602. /*
  603. * rt2x00 device structure.
  604. */
  605. struct rt2x00_dev {
  606. /*
  607. * Device structure.
  608. * The structure stored in here depends on the
  609. * system bus (PCI or USB).
  610. * When accessing this variable, the rt2x00dev_{pci,usb}
  611. * macros should be used for correct typecasting.
  612. */
  613. struct device *dev;
  614. /*
  615. * Callback functions.
  616. */
  617. const struct rt2x00_ops *ops;
  618. /*
  619. * IEEE80211 control structure.
  620. */
  621. struct ieee80211_hw *hw;
  622. struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
  623. enum ieee80211_band curr_band;
  624. int curr_freq;
  625. /*
  626. * If enabled, the debugfs interface structures
  627. * required for deregistration of debugfs.
  628. */
  629. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  630. struct rt2x00debug_intf *debugfs_intf;
  631. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  632. /*
  633. * LED structure for changing the LED status
  634. * by mac8011 or the kernel.
  635. */
  636. #ifdef CONFIG_RT2X00_LIB_LEDS
  637. struct rt2x00_led led_radio;
  638. struct rt2x00_led led_assoc;
  639. struct rt2x00_led led_qual;
  640. u16 led_mcu_reg;
  641. #endif /* CONFIG_RT2X00_LIB_LEDS */
  642. /*
  643. * Device flags.
  644. * In these flags the current status and some
  645. * of the device capabilities are stored.
  646. */
  647. unsigned long flags;
  648. /*
  649. * Device information, Bus IRQ and name (PCI, SoC)
  650. */
  651. int irq;
  652. const char *name;
  653. /*
  654. * Chipset identification.
  655. */
  656. struct rt2x00_chip chip;
  657. /*
  658. * hw capability specifications.
  659. */
  660. struct hw_mode_spec spec;
  661. /*
  662. * This is the default TX/RX antenna setup as indicated
  663. * by the device's EEPROM.
  664. */
  665. struct antenna_setup default_ant;
  666. /*
  667. * Register pointers
  668. * csr.base: CSR base register address. (PCI)
  669. * csr.cache: CSR cache for usb_control_msg. (USB)
  670. */
  671. union csr {
  672. void __iomem *base;
  673. void *cache;
  674. } csr;
  675. /*
  676. * Mutex to protect register accesses.
  677. * For PCI and USB devices it protects against concurrent indirect
  678. * register access (BBP, RF, MCU) since accessing those
  679. * registers require multiple calls to the CSR registers.
  680. * For USB devices it also protects the csr_cache since that
  681. * field is used for normal CSR access and it cannot support
  682. * multiple callers simultaneously.
  683. */
  684. struct mutex csr_mutex;
  685. /*
  686. * Current packet filter configuration for the device.
  687. * This contains all currently active FIF_* flags send
  688. * to us by mac80211 during configure_filter().
  689. */
  690. unsigned int packet_filter;
  691. /*
  692. * Interface details:
  693. * - Open ap interface count.
  694. * - Open sta interface count.
  695. * - Association count.
  696. */
  697. unsigned int intf_ap_count;
  698. unsigned int intf_sta_count;
  699. unsigned int intf_associated;
  700. /*
  701. * Link quality
  702. */
  703. struct link link;
  704. /*
  705. * EEPROM data.
  706. */
  707. __le16 *eeprom;
  708. /*
  709. * Active RF register values.
  710. * These are stored here so we don't need
  711. * to read the rf registers and can directly
  712. * use this value instead.
  713. * This field should be accessed by using
  714. * rt2x00_rf_read() and rt2x00_rf_write().
  715. */
  716. u32 *rf;
  717. /*
  718. * LNA gain
  719. */
  720. short lna_gain;
  721. /*
  722. * Current TX power value.
  723. */
  724. u16 tx_power;
  725. /*
  726. * Current retry values.
  727. */
  728. u8 short_retry;
  729. u8 long_retry;
  730. /*
  731. * Rssi <-> Dbm offset
  732. */
  733. u8 rssi_offset;
  734. /*
  735. * Frequency offset (for rt61pci & rt73usb).
  736. */
  737. u8 freq_offset;
  738. /*
  739. * Calibration information (for rt2800usb & rt2800pci).
  740. * [0] -> BW20
  741. * [1] -> BW40
  742. */
  743. u8 calibration[2];
  744. /*
  745. * Beacon interval.
  746. */
  747. u16 beacon_int;
  748. /*
  749. * Low level statistics which will have
  750. * to be kept up to date while device is running.
  751. */
  752. struct ieee80211_low_level_stats low_level_stats;
  753. /*
  754. * Scheduled work.
  755. * NOTE: intf_work will use ieee80211_iterate_active_interfaces()
  756. * which means it cannot be placed on the hw->workqueue
  757. * due to RTNL locking requirements.
  758. */
  759. struct work_struct intf_work;
  760. /**
  761. * Scheduled work for TX/RX done handling (USB devices)
  762. */
  763. struct work_struct rxdone_work;
  764. struct work_struct txdone_work;
  765. /*
  766. * Data queue arrays for RX, TX and Beacon.
  767. * The Beacon array also contains the Atim queue
  768. * if that is supported by the device.
  769. */
  770. unsigned int data_queues;
  771. struct data_queue *rx;
  772. struct data_queue *tx;
  773. struct data_queue *bcn;
  774. /*
  775. * Firmware image.
  776. */
  777. const struct firmware *fw;
  778. /*
  779. * Interrupt values, stored between interrupt service routine
  780. * and interrupt thread routine.
  781. */
  782. u32 irqvalue[2];
  783. /*
  784. * FIFO for storing tx status reports between isr and tasklet.
  785. */
  786. DECLARE_KFIFO_PTR(txstatus_fifo, u32);
  787. /*
  788. * Tasklet for processing tx status reports (rt2800pci).
  789. */
  790. struct tasklet_struct txstatus_tasklet;
  791. };
  792. /*
  793. * Register defines.
  794. * Some registers require multiple attempts before success,
  795. * in those cases REGISTER_BUSY_COUNT attempts should be
  796. * taken with a REGISTER_BUSY_DELAY interval.
  797. */
  798. #define REGISTER_BUSY_COUNT 100
  799. #define REGISTER_BUSY_DELAY 100
  800. /*
  801. * Generic RF access.
  802. * The RF is being accessed by word index.
  803. */
  804. static inline void rt2x00_rf_read(struct rt2x00_dev *rt2x00dev,
  805. const unsigned int word, u32 *data)
  806. {
  807. BUG_ON(word < 1 || word > rt2x00dev->ops->rf_size / sizeof(u32));
  808. *data = rt2x00dev->rf[word - 1];
  809. }
  810. static inline void rt2x00_rf_write(struct rt2x00_dev *rt2x00dev,
  811. const unsigned int word, u32 data)
  812. {
  813. BUG_ON(word < 1 || word > rt2x00dev->ops->rf_size / sizeof(u32));
  814. rt2x00dev->rf[word - 1] = data;
  815. }
  816. /*
  817. * Generic EEPROM access.
  818. * The EEPROM is being accessed by word index.
  819. */
  820. static inline void *rt2x00_eeprom_addr(struct rt2x00_dev *rt2x00dev,
  821. const unsigned int word)
  822. {
  823. return (void *)&rt2x00dev->eeprom[word];
  824. }
  825. static inline void rt2x00_eeprom_read(struct rt2x00_dev *rt2x00dev,
  826. const unsigned int word, u16 *data)
  827. {
  828. *data = le16_to_cpu(rt2x00dev->eeprom[word]);
  829. }
  830. static inline void rt2x00_eeprom_write(struct rt2x00_dev *rt2x00dev,
  831. const unsigned int word, u16 data)
  832. {
  833. rt2x00dev->eeprom[word] = cpu_to_le16(data);
  834. }
  835. /*
  836. * Chipset handlers
  837. */
  838. static inline void rt2x00_set_chip(struct rt2x00_dev *rt2x00dev,
  839. const u16 rt, const u16 rf, const u16 rev)
  840. {
  841. rt2x00dev->chip.rt = rt;
  842. rt2x00dev->chip.rf = rf;
  843. rt2x00dev->chip.rev = rev;
  844. INFO(rt2x00dev,
  845. "Chipset detected - rt: %04x, rf: %04x, rev: %04x.\n",
  846. rt2x00dev->chip.rt, rt2x00dev->chip.rf, rt2x00dev->chip.rev);
  847. }
  848. static inline bool rt2x00_rt(struct rt2x00_dev *rt2x00dev, const u16 rt)
  849. {
  850. return (rt2x00dev->chip.rt == rt);
  851. }
  852. static inline bool rt2x00_rf(struct rt2x00_dev *rt2x00dev, const u16 rf)
  853. {
  854. return (rt2x00dev->chip.rf == rf);
  855. }
  856. static inline u16 rt2x00_rev(struct rt2x00_dev *rt2x00dev)
  857. {
  858. return rt2x00dev->chip.rev;
  859. }
  860. static inline bool rt2x00_rt_rev(struct rt2x00_dev *rt2x00dev,
  861. const u16 rt, const u16 rev)
  862. {
  863. return (rt2x00_rt(rt2x00dev, rt) && rt2x00_rev(rt2x00dev) == rev);
  864. }
  865. static inline bool rt2x00_rt_rev_lt(struct rt2x00_dev *rt2x00dev,
  866. const u16 rt, const u16 rev)
  867. {
  868. return (rt2x00_rt(rt2x00dev, rt) && rt2x00_rev(rt2x00dev) < rev);
  869. }
  870. static inline bool rt2x00_rt_rev_gte(struct rt2x00_dev *rt2x00dev,
  871. const u16 rt, const u16 rev)
  872. {
  873. return (rt2x00_rt(rt2x00dev, rt) && rt2x00_rev(rt2x00dev) >= rev);
  874. }
  875. static inline void rt2x00_set_chip_intf(struct rt2x00_dev *rt2x00dev,
  876. enum rt2x00_chip_intf intf)
  877. {
  878. rt2x00dev->chip.intf = intf;
  879. }
  880. static inline bool rt2x00_intf(struct rt2x00_dev *rt2x00dev,
  881. enum rt2x00_chip_intf intf)
  882. {
  883. return (rt2x00dev->chip.intf == intf);
  884. }
  885. static inline bool rt2x00_is_pci(struct rt2x00_dev *rt2x00dev)
  886. {
  887. return rt2x00_intf(rt2x00dev, RT2X00_CHIP_INTF_PCI) ||
  888. rt2x00_intf(rt2x00dev, RT2X00_CHIP_INTF_PCIE);
  889. }
  890. static inline bool rt2x00_is_pcie(struct rt2x00_dev *rt2x00dev)
  891. {
  892. return rt2x00_intf(rt2x00dev, RT2X00_CHIP_INTF_PCIE);
  893. }
  894. static inline bool rt2x00_is_usb(struct rt2x00_dev *rt2x00dev)
  895. {
  896. return rt2x00_intf(rt2x00dev, RT2X00_CHIP_INTF_USB);
  897. }
  898. static inline bool rt2x00_is_soc(struct rt2x00_dev *rt2x00dev)
  899. {
  900. return rt2x00_intf(rt2x00dev, RT2X00_CHIP_INTF_SOC);
  901. }
  902. /**
  903. * rt2x00queue_map_txskb - Map a skb into DMA for TX purposes.
  904. * @entry: Pointer to &struct queue_entry
  905. */
  906. void rt2x00queue_map_txskb(struct queue_entry *entry);
  907. /**
  908. * rt2x00queue_unmap_skb - Unmap a skb from DMA.
  909. * @entry: Pointer to &struct queue_entry
  910. */
  911. void rt2x00queue_unmap_skb(struct queue_entry *entry);
  912. /**
  913. * rt2x00queue_get_queue - Convert queue index to queue pointer
  914. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  915. * @queue: rt2x00 queue index (see &enum data_queue_qid).
  916. */
  917. struct data_queue *rt2x00queue_get_queue(struct rt2x00_dev *rt2x00dev,
  918. const enum data_queue_qid queue);
  919. /**
  920. * rt2x00queue_get_entry - Get queue entry where the given index points to.
  921. * @queue: Pointer to &struct data_queue from where we obtain the entry.
  922. * @index: Index identifier for obtaining the correct index.
  923. */
  924. struct queue_entry *rt2x00queue_get_entry(struct data_queue *queue,
  925. enum queue_index index);
  926. /**
  927. * rt2x00queue_pause_queue - Pause a data queue
  928. * @queue: Pointer to &struct data_queue.
  929. *
  930. * This function will pause the data queue locally, preventing
  931. * new frames to be added to the queue (while the hardware is
  932. * still allowed to run).
  933. */
  934. void rt2x00queue_pause_queue(struct data_queue *queue);
  935. /**
  936. * rt2x00queue_unpause_queue - unpause a data queue
  937. * @queue: Pointer to &struct data_queue.
  938. *
  939. * This function will unpause the data queue locally, allowing
  940. * new frames to be added to the queue again.
  941. */
  942. void rt2x00queue_unpause_queue(struct data_queue *queue);
  943. /**
  944. * rt2x00queue_start_queue - Start a data queue
  945. * @queue: Pointer to &struct data_queue.
  946. *
  947. * This function will start handling all pending frames in the queue.
  948. */
  949. void rt2x00queue_start_queue(struct data_queue *queue);
  950. /**
  951. * rt2x00queue_stop_queue - Halt a data queue
  952. * @queue: Pointer to &struct data_queue.
  953. *
  954. * This function will stop all pending frames in the queue.
  955. */
  956. void rt2x00queue_stop_queue(struct data_queue *queue);
  957. /**
  958. * rt2x00queue_flush_queue - Flush a data queue
  959. * @queue: Pointer to &struct data_queue.
  960. * @drop: True to drop all pending frames.
  961. *
  962. * This function will flush the queue. After this call
  963. * the queue is guarenteed to be empty.
  964. */
  965. void rt2x00queue_flush_queue(struct data_queue *queue, bool drop);
  966. /**
  967. * rt2x00queue_start_queues - Start all data queues
  968. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  969. *
  970. * This function will loop through all available queues to start them
  971. */
  972. void rt2x00queue_start_queues(struct rt2x00_dev *rt2x00dev);
  973. /**
  974. * rt2x00queue_stop_queues - Halt all data queues
  975. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  976. *
  977. * This function will loop through all available queues to stop
  978. * any pending frames.
  979. */
  980. void rt2x00queue_stop_queues(struct rt2x00_dev *rt2x00dev);
  981. /**
  982. * rt2x00queue_flush_queues - Flush all data queues
  983. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  984. * @drop: True to drop all pending frames.
  985. *
  986. * This function will loop through all available queues to flush
  987. * any pending frames.
  988. */
  989. void rt2x00queue_flush_queues(struct rt2x00_dev *rt2x00dev, bool drop);
  990. /*
  991. * Debugfs handlers.
  992. */
  993. /**
  994. * rt2x00debug_dump_frame - Dump a frame to userspace through debugfs.
  995. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  996. * @type: The type of frame that is being dumped.
  997. * @skb: The skb containing the frame to be dumped.
  998. */
  999. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  1000. void rt2x00debug_dump_frame(struct rt2x00_dev *rt2x00dev,
  1001. enum rt2x00_dump_type type, struct sk_buff *skb);
  1002. #else
  1003. static inline void rt2x00debug_dump_frame(struct rt2x00_dev *rt2x00dev,
  1004. enum rt2x00_dump_type type,
  1005. struct sk_buff *skb)
  1006. {
  1007. }
  1008. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  1009. /*
  1010. * Interrupt context handlers.
  1011. */
  1012. void rt2x00lib_beacondone(struct rt2x00_dev *rt2x00dev);
  1013. void rt2x00lib_pretbtt(struct rt2x00_dev *rt2x00dev);
  1014. void rt2x00lib_dmastart(struct queue_entry *entry);
  1015. void rt2x00lib_dmadone(struct queue_entry *entry);
  1016. void rt2x00lib_txdone(struct queue_entry *entry,
  1017. struct txdone_entry_desc *txdesc);
  1018. void rt2x00lib_txdone_noinfo(struct queue_entry *entry, u32 status);
  1019. void rt2x00lib_rxdone(struct queue_entry *entry);
  1020. /*
  1021. * mac80211 handlers.
  1022. */
  1023. int rt2x00mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb);
  1024. int rt2x00mac_start(struct ieee80211_hw *hw);
  1025. void rt2x00mac_stop(struct ieee80211_hw *hw);
  1026. int rt2x00mac_add_interface(struct ieee80211_hw *hw,
  1027. struct ieee80211_vif *vif);
  1028. void rt2x00mac_remove_interface(struct ieee80211_hw *hw,
  1029. struct ieee80211_vif *vif);
  1030. int rt2x00mac_config(struct ieee80211_hw *hw, u32 changed);
  1031. void rt2x00mac_configure_filter(struct ieee80211_hw *hw,
  1032. unsigned int changed_flags,
  1033. unsigned int *total_flags,
  1034. u64 multicast);
  1035. int rt2x00mac_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
  1036. bool set);
  1037. #ifdef CONFIG_RT2X00_LIB_CRYPTO
  1038. int rt2x00mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  1039. struct ieee80211_vif *vif, struct ieee80211_sta *sta,
  1040. struct ieee80211_key_conf *key);
  1041. #else
  1042. #define rt2x00mac_set_key NULL
  1043. #endif /* CONFIG_RT2X00_LIB_CRYPTO */
  1044. void rt2x00mac_sw_scan_start(struct ieee80211_hw *hw);
  1045. void rt2x00mac_sw_scan_complete(struct ieee80211_hw *hw);
  1046. int rt2x00mac_get_stats(struct ieee80211_hw *hw,
  1047. struct ieee80211_low_level_stats *stats);
  1048. void rt2x00mac_bss_info_changed(struct ieee80211_hw *hw,
  1049. struct ieee80211_vif *vif,
  1050. struct ieee80211_bss_conf *bss_conf,
  1051. u32 changes);
  1052. int rt2x00mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
  1053. const struct ieee80211_tx_queue_params *params);
  1054. void rt2x00mac_rfkill_poll(struct ieee80211_hw *hw);
  1055. void rt2x00mac_flush(struct ieee80211_hw *hw, bool drop);
  1056. /*
  1057. * Driver allocation handlers.
  1058. */
  1059. int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev);
  1060. void rt2x00lib_remove_dev(struct rt2x00_dev *rt2x00dev);
  1061. #ifdef CONFIG_PM
  1062. int rt2x00lib_suspend(struct rt2x00_dev *rt2x00dev, pm_message_t state);
  1063. int rt2x00lib_resume(struct rt2x00_dev *rt2x00dev);
  1064. #endif /* CONFIG_PM */
  1065. #endif /* RT2X00_H */