rt2x00.h 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232
  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. bool enable_beacon;
  329. /*
  330. * Actions that needed rescheduling.
  331. */
  332. unsigned long delayed_flags;
  333. /*
  334. * Software sequence counter, this is only required
  335. * for hardware which doesn't support hardware
  336. * sequence counting.
  337. */
  338. spinlock_t seqlock;
  339. u16 seqno;
  340. };
  341. static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
  342. {
  343. return (struct rt2x00_intf *)vif->drv_priv;
  344. }
  345. /**
  346. * struct hw_mode_spec: Hardware specifications structure
  347. *
  348. * Details about the supported modes, rates and channels
  349. * of a particular chipset. This is used by rt2x00lib
  350. * to build the ieee80211_hw_mode array for mac80211.
  351. *
  352. * @supported_bands: Bitmask contained the supported bands (2.4GHz, 5.2GHz).
  353. * @supported_rates: Rate types which are supported (CCK, OFDM).
  354. * @num_channels: Number of supported channels. This is used as array size
  355. * for @tx_power_a, @tx_power_bg and @channels.
  356. * @channels: Device/chipset specific channel values (See &struct rf_channel).
  357. * @channels_info: Additional information for channels (See &struct channel_info).
  358. * @ht: Driver HT Capabilities (See &ieee80211_sta_ht_cap).
  359. */
  360. struct hw_mode_spec {
  361. unsigned int supported_bands;
  362. #define SUPPORT_BAND_2GHZ 0x00000001
  363. #define SUPPORT_BAND_5GHZ 0x00000002
  364. unsigned int supported_rates;
  365. #define SUPPORT_RATE_CCK 0x00000001
  366. #define SUPPORT_RATE_OFDM 0x00000002
  367. unsigned int num_channels;
  368. const struct rf_channel *channels;
  369. const struct channel_info *channels_info;
  370. struct ieee80211_sta_ht_cap ht;
  371. };
  372. /*
  373. * Configuration structure wrapper around the
  374. * mac80211 configuration structure.
  375. * When mac80211 configures the driver, rt2x00lib
  376. * can precalculate values which are equal for all
  377. * rt2x00 drivers. Those values can be stored in here.
  378. */
  379. struct rt2x00lib_conf {
  380. struct ieee80211_conf *conf;
  381. struct rf_channel rf;
  382. struct channel_info channel;
  383. };
  384. /*
  385. * Configuration structure for erp settings.
  386. */
  387. struct rt2x00lib_erp {
  388. int short_preamble;
  389. int cts_protection;
  390. u32 basic_rates;
  391. int slot_time;
  392. short sifs;
  393. short pifs;
  394. short difs;
  395. short eifs;
  396. u16 beacon_int;
  397. u16 ht_opmode;
  398. };
  399. /*
  400. * Configuration structure for hardware encryption.
  401. */
  402. struct rt2x00lib_crypto {
  403. enum cipher cipher;
  404. enum set_key_cmd cmd;
  405. const u8 *address;
  406. u32 bssidx;
  407. u32 aid;
  408. u8 key[16];
  409. u8 tx_mic[8];
  410. u8 rx_mic[8];
  411. };
  412. /*
  413. * Configuration structure wrapper around the
  414. * rt2x00 interface configuration handler.
  415. */
  416. struct rt2x00intf_conf {
  417. /*
  418. * Interface type
  419. */
  420. enum nl80211_iftype type;
  421. /*
  422. * TSF sync value, this is dependant on the operation type.
  423. */
  424. enum tsf_sync sync;
  425. /*
  426. * The MAC and BSSID addressess are simple array of bytes,
  427. * these arrays are little endian, so when sending the addressess
  428. * to the drivers, copy the it into a endian-signed variable.
  429. *
  430. * Note that all devices (except rt2500usb) have 32 bits
  431. * register word sizes. This means that whatever variable we
  432. * pass _must_ be a multiple of 32 bits. Otherwise the device
  433. * might not accept what we are sending to it.
  434. * This will also make it easier for the driver to write
  435. * the data to the device.
  436. */
  437. __le32 mac[2];
  438. __le32 bssid[2];
  439. };
  440. /*
  441. * rt2x00lib callback functions.
  442. */
  443. struct rt2x00lib_ops {
  444. /*
  445. * Interrupt handlers.
  446. */
  447. irq_handler_t irq_handler;
  448. /*
  449. * Threaded Interrupt handlers.
  450. */
  451. irq_handler_t irq_handler_thread;
  452. /*
  453. * TX status tasklet handler.
  454. */
  455. void (*txstatus_tasklet) (unsigned long data);
  456. void (*pretbtt_tasklet) (unsigned long data);
  457. void (*tbtt_tasklet) (unsigned long data);
  458. void (*rxdone_tasklet) (unsigned long data);
  459. void (*autowake_tasklet) (unsigned long data);
  460. /*
  461. * Device init handlers.
  462. */
  463. int (*probe_hw) (struct rt2x00_dev *rt2x00dev);
  464. char *(*get_firmware_name) (struct rt2x00_dev *rt2x00dev);
  465. int (*check_firmware) (struct rt2x00_dev *rt2x00dev,
  466. const u8 *data, const size_t len);
  467. int (*load_firmware) (struct rt2x00_dev *rt2x00dev,
  468. const u8 *data, const size_t len);
  469. /*
  470. * Device initialization/deinitialization handlers.
  471. */
  472. int (*initialize) (struct rt2x00_dev *rt2x00dev);
  473. void (*uninitialize) (struct rt2x00_dev *rt2x00dev);
  474. /*
  475. * queue initialization handlers
  476. */
  477. bool (*get_entry_state) (struct queue_entry *entry);
  478. void (*clear_entry) (struct queue_entry *entry);
  479. /*
  480. * Radio control handlers.
  481. */
  482. int (*set_device_state) (struct rt2x00_dev *rt2x00dev,
  483. enum dev_state state);
  484. int (*rfkill_poll) (struct rt2x00_dev *rt2x00dev);
  485. void (*link_stats) (struct rt2x00_dev *rt2x00dev,
  486. struct link_qual *qual);
  487. void (*reset_tuner) (struct rt2x00_dev *rt2x00dev,
  488. struct link_qual *qual);
  489. void (*link_tuner) (struct rt2x00_dev *rt2x00dev,
  490. struct link_qual *qual, const u32 count);
  491. /*
  492. * Data queue handlers.
  493. */
  494. void (*watchdog) (struct rt2x00_dev *rt2x00dev);
  495. void (*start_queue) (struct data_queue *queue);
  496. void (*kick_queue) (struct data_queue *queue);
  497. void (*stop_queue) (struct data_queue *queue);
  498. void (*flush_queue) (struct data_queue *queue);
  499. /*
  500. * TX control handlers
  501. */
  502. void (*write_tx_desc) (struct queue_entry *entry,
  503. struct txentry_desc *txdesc);
  504. void (*write_tx_data) (struct queue_entry *entry,
  505. struct txentry_desc *txdesc);
  506. void (*write_beacon) (struct queue_entry *entry,
  507. struct txentry_desc *txdesc);
  508. void (*clear_beacon) (struct queue_entry *entry);
  509. int (*get_tx_data_len) (struct queue_entry *entry);
  510. /*
  511. * RX control handlers
  512. */
  513. void (*fill_rxdone) (struct queue_entry *entry,
  514. struct rxdone_entry_desc *rxdesc);
  515. /*
  516. * Configuration handlers.
  517. */
  518. int (*config_shared_key) (struct rt2x00_dev *rt2x00dev,
  519. struct rt2x00lib_crypto *crypto,
  520. struct ieee80211_key_conf *key);
  521. int (*config_pairwise_key) (struct rt2x00_dev *rt2x00dev,
  522. struct rt2x00lib_crypto *crypto,
  523. struct ieee80211_key_conf *key);
  524. void (*config_filter) (struct rt2x00_dev *rt2x00dev,
  525. const unsigned int filter_flags);
  526. void (*config_intf) (struct rt2x00_dev *rt2x00dev,
  527. struct rt2x00_intf *intf,
  528. struct rt2x00intf_conf *conf,
  529. const unsigned int flags);
  530. #define CONFIG_UPDATE_TYPE ( 1 << 1 )
  531. #define CONFIG_UPDATE_MAC ( 1 << 2 )
  532. #define CONFIG_UPDATE_BSSID ( 1 << 3 )
  533. void (*config_erp) (struct rt2x00_dev *rt2x00dev,
  534. struct rt2x00lib_erp *erp,
  535. u32 changed);
  536. void (*config_ant) (struct rt2x00_dev *rt2x00dev,
  537. struct antenna_setup *ant);
  538. void (*config) (struct rt2x00_dev *rt2x00dev,
  539. struct rt2x00lib_conf *libconf,
  540. const unsigned int changed_flags);
  541. };
  542. /*
  543. * rt2x00 driver callback operation structure.
  544. */
  545. struct rt2x00_ops {
  546. const char *name;
  547. const unsigned int max_sta_intf;
  548. const unsigned int max_ap_intf;
  549. const unsigned int eeprom_size;
  550. const unsigned int rf_size;
  551. const unsigned int tx_queues;
  552. const unsigned int extra_tx_headroom;
  553. const struct data_queue_desc *rx;
  554. const struct data_queue_desc *tx;
  555. const struct data_queue_desc *bcn;
  556. const struct data_queue_desc *atim;
  557. const struct rt2x00lib_ops *lib;
  558. const void *drv;
  559. const struct ieee80211_ops *hw;
  560. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  561. const struct rt2x00debug *debugfs;
  562. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  563. };
  564. /*
  565. * rt2x00 device flags
  566. */
  567. enum rt2x00_flags {
  568. /*
  569. * Device state flags
  570. */
  571. DEVICE_STATE_PRESENT,
  572. DEVICE_STATE_REGISTERED_HW,
  573. DEVICE_STATE_INITIALIZED,
  574. DEVICE_STATE_STARTED,
  575. DEVICE_STATE_ENABLED_RADIO,
  576. DEVICE_STATE_SCANNING,
  577. /*
  578. * Driver requirements
  579. */
  580. DRIVER_REQUIRE_FIRMWARE,
  581. DRIVER_REQUIRE_BEACON_GUARD,
  582. DRIVER_REQUIRE_ATIM_QUEUE,
  583. DRIVER_REQUIRE_DMA,
  584. DRIVER_REQUIRE_COPY_IV,
  585. DRIVER_REQUIRE_L2PAD,
  586. DRIVER_REQUIRE_TXSTATUS_FIFO,
  587. DRIVER_REQUIRE_TASKLET_CONTEXT,
  588. /*
  589. * Driver features
  590. */
  591. CONFIG_SUPPORT_HW_BUTTON,
  592. CONFIG_SUPPORT_HW_CRYPTO,
  593. DRIVER_SUPPORT_CONTROL_FILTERS,
  594. DRIVER_SUPPORT_CONTROL_FILTER_PSPOLL,
  595. DRIVER_SUPPORT_PRE_TBTT_INTERRUPT,
  596. DRIVER_SUPPORT_LINK_TUNING,
  597. DRIVER_SUPPORT_WATCHDOG,
  598. /*
  599. * Driver configuration
  600. */
  601. CONFIG_FRAME_TYPE,
  602. CONFIG_RF_SEQUENCE,
  603. CONFIG_EXTERNAL_LNA_A,
  604. CONFIG_EXTERNAL_LNA_BG,
  605. CONFIG_DOUBLE_ANTENNA,
  606. CONFIG_CHANNEL_HT40,
  607. };
  608. /*
  609. * rt2x00 device structure.
  610. */
  611. struct rt2x00_dev {
  612. /*
  613. * Device structure.
  614. * The structure stored in here depends on the
  615. * system bus (PCI or USB).
  616. * When accessing this variable, the rt2x00dev_{pci,usb}
  617. * macros should be used for correct typecasting.
  618. */
  619. struct device *dev;
  620. /*
  621. * Callback functions.
  622. */
  623. const struct rt2x00_ops *ops;
  624. /*
  625. * IEEE80211 control structure.
  626. */
  627. struct ieee80211_hw *hw;
  628. struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
  629. enum ieee80211_band curr_band;
  630. int curr_freq;
  631. /*
  632. * If enabled, the debugfs interface structures
  633. * required for deregistration of debugfs.
  634. */
  635. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  636. struct rt2x00debug_intf *debugfs_intf;
  637. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  638. /*
  639. * LED structure for changing the LED status
  640. * by mac8011 or the kernel.
  641. */
  642. #ifdef CONFIG_RT2X00_LIB_LEDS
  643. struct rt2x00_led led_radio;
  644. struct rt2x00_led led_assoc;
  645. struct rt2x00_led led_qual;
  646. u16 led_mcu_reg;
  647. #endif /* CONFIG_RT2X00_LIB_LEDS */
  648. /*
  649. * Device flags.
  650. * In these flags the current status and some
  651. * of the device capabilities are stored.
  652. */
  653. unsigned long flags;
  654. /*
  655. * Device information, Bus IRQ and name (PCI, SoC)
  656. */
  657. int irq;
  658. const char *name;
  659. /*
  660. * Chipset identification.
  661. */
  662. struct rt2x00_chip chip;
  663. /*
  664. * hw capability specifications.
  665. */
  666. struct hw_mode_spec spec;
  667. /*
  668. * This is the default TX/RX antenna setup as indicated
  669. * by the device's EEPROM.
  670. */
  671. struct antenna_setup default_ant;
  672. /*
  673. * Register pointers
  674. * csr.base: CSR base register address. (PCI)
  675. * csr.cache: CSR cache for usb_control_msg. (USB)
  676. */
  677. union csr {
  678. void __iomem *base;
  679. void *cache;
  680. } csr;
  681. /*
  682. * Mutex to protect register accesses.
  683. * For PCI and USB devices it protects against concurrent indirect
  684. * register access (BBP, RF, MCU) since accessing those
  685. * registers require multiple calls to the CSR registers.
  686. * For USB devices it also protects the csr_cache since that
  687. * field is used for normal CSR access and it cannot support
  688. * multiple callers simultaneously.
  689. */
  690. struct mutex csr_mutex;
  691. /*
  692. * Current packet filter configuration for the device.
  693. * This contains all currently active FIF_* flags send
  694. * to us by mac80211 during configure_filter().
  695. */
  696. unsigned int packet_filter;
  697. /*
  698. * Interface details:
  699. * - Open ap interface count.
  700. * - Open sta interface count.
  701. * - Association count.
  702. * - Beaconing enabled count.
  703. */
  704. unsigned int intf_ap_count;
  705. unsigned int intf_sta_count;
  706. unsigned int intf_associated;
  707. unsigned int intf_beaconing;
  708. /*
  709. * Link quality
  710. */
  711. struct link link;
  712. /*
  713. * EEPROM data.
  714. */
  715. __le16 *eeprom;
  716. /*
  717. * Active RF register values.
  718. * These are stored here so we don't need
  719. * to read the rf registers and can directly
  720. * use this value instead.
  721. * This field should be accessed by using
  722. * rt2x00_rf_read() and rt2x00_rf_write().
  723. */
  724. u32 *rf;
  725. /*
  726. * LNA gain
  727. */
  728. short lna_gain;
  729. /*
  730. * Current TX power value.
  731. */
  732. u16 tx_power;
  733. /*
  734. * Current retry values.
  735. */
  736. u8 short_retry;
  737. u8 long_retry;
  738. /*
  739. * Rssi <-> Dbm offset
  740. */
  741. u8 rssi_offset;
  742. /*
  743. * Frequency offset (for rt61pci & rt73usb).
  744. */
  745. u8 freq_offset;
  746. /*
  747. * Calibration information (for rt2800usb & rt2800pci).
  748. * [0] -> BW20
  749. * [1] -> BW40
  750. */
  751. u8 calibration[2];
  752. /*
  753. * Beacon interval.
  754. */
  755. u16 beacon_int;
  756. /*
  757. * Low level statistics which will have
  758. * to be kept up to date while device is running.
  759. */
  760. struct ieee80211_low_level_stats low_level_stats;
  761. /*
  762. * Scheduled work.
  763. * NOTE: intf_work will use ieee80211_iterate_active_interfaces()
  764. * which means it cannot be placed on the hw->workqueue
  765. * due to RTNL locking requirements.
  766. */
  767. struct work_struct intf_work;
  768. /**
  769. * Scheduled work for TX/RX done handling (USB devices)
  770. */
  771. struct work_struct rxdone_work;
  772. struct work_struct txdone_work;
  773. /*
  774. * Data queue arrays for RX, TX and Beacon.
  775. * The Beacon array also contains the Atim queue
  776. * if that is supported by the device.
  777. */
  778. unsigned int data_queues;
  779. struct data_queue *rx;
  780. struct data_queue *tx;
  781. struct data_queue *bcn;
  782. /*
  783. * Firmware image.
  784. */
  785. const struct firmware *fw;
  786. /*
  787. * Interrupt values, stored between interrupt service routine
  788. * and interrupt thread routine.
  789. */
  790. u32 irqvalue[2];
  791. /*
  792. * FIFO for storing tx status reports between isr and tasklet.
  793. */
  794. DECLARE_KFIFO_PTR(txstatus_fifo, u32);
  795. /*
  796. * Tasklet for processing tx status reports (rt2800pci).
  797. */
  798. struct tasklet_struct txstatus_tasklet;
  799. struct tasklet_struct pretbtt_tasklet;
  800. struct tasklet_struct tbtt_tasklet;
  801. struct tasklet_struct rxdone_tasklet;
  802. struct tasklet_struct autowake_tasklet;
  803. /*
  804. * Protect the interrupt mask register.
  805. */
  806. spinlock_t irqmask_lock;
  807. };
  808. /*
  809. * Register defines.
  810. * Some registers require multiple attempts before success,
  811. * in those cases REGISTER_BUSY_COUNT attempts should be
  812. * taken with a REGISTER_BUSY_DELAY interval.
  813. */
  814. #define REGISTER_BUSY_COUNT 100
  815. #define REGISTER_BUSY_DELAY 100
  816. /*
  817. * Generic RF access.
  818. * The RF is being accessed by word index.
  819. */
  820. static inline void rt2x00_rf_read(struct rt2x00_dev *rt2x00dev,
  821. const unsigned int word, u32 *data)
  822. {
  823. BUG_ON(word < 1 || word > rt2x00dev->ops->rf_size / sizeof(u32));
  824. *data = rt2x00dev->rf[word - 1];
  825. }
  826. static inline void rt2x00_rf_write(struct rt2x00_dev *rt2x00dev,
  827. const unsigned int word, u32 data)
  828. {
  829. BUG_ON(word < 1 || word > rt2x00dev->ops->rf_size / sizeof(u32));
  830. rt2x00dev->rf[word - 1] = data;
  831. }
  832. /*
  833. * Generic EEPROM access.
  834. * The EEPROM is being accessed by word index.
  835. */
  836. static inline void *rt2x00_eeprom_addr(struct rt2x00_dev *rt2x00dev,
  837. const unsigned int word)
  838. {
  839. return (void *)&rt2x00dev->eeprom[word];
  840. }
  841. static inline void rt2x00_eeprom_read(struct rt2x00_dev *rt2x00dev,
  842. const unsigned int word, u16 *data)
  843. {
  844. *data = le16_to_cpu(rt2x00dev->eeprom[word]);
  845. }
  846. static inline void rt2x00_eeprom_write(struct rt2x00_dev *rt2x00dev,
  847. const unsigned int word, u16 data)
  848. {
  849. rt2x00dev->eeprom[word] = cpu_to_le16(data);
  850. }
  851. /*
  852. * Chipset handlers
  853. */
  854. static inline void rt2x00_set_chip(struct rt2x00_dev *rt2x00dev,
  855. const u16 rt, const u16 rf, const u16 rev)
  856. {
  857. rt2x00dev->chip.rt = rt;
  858. rt2x00dev->chip.rf = rf;
  859. rt2x00dev->chip.rev = rev;
  860. INFO(rt2x00dev,
  861. "Chipset detected - rt: %04x, rf: %04x, rev: %04x.\n",
  862. rt2x00dev->chip.rt, rt2x00dev->chip.rf, rt2x00dev->chip.rev);
  863. }
  864. static inline bool rt2x00_rt(struct rt2x00_dev *rt2x00dev, const u16 rt)
  865. {
  866. return (rt2x00dev->chip.rt == rt);
  867. }
  868. static inline bool rt2x00_rf(struct rt2x00_dev *rt2x00dev, const u16 rf)
  869. {
  870. return (rt2x00dev->chip.rf == rf);
  871. }
  872. static inline u16 rt2x00_rev(struct rt2x00_dev *rt2x00dev)
  873. {
  874. return rt2x00dev->chip.rev;
  875. }
  876. static inline bool rt2x00_rt_rev(struct rt2x00_dev *rt2x00dev,
  877. const u16 rt, const u16 rev)
  878. {
  879. return (rt2x00_rt(rt2x00dev, rt) && rt2x00_rev(rt2x00dev) == rev);
  880. }
  881. static inline bool rt2x00_rt_rev_lt(struct rt2x00_dev *rt2x00dev,
  882. const u16 rt, const u16 rev)
  883. {
  884. return (rt2x00_rt(rt2x00dev, rt) && rt2x00_rev(rt2x00dev) < rev);
  885. }
  886. static inline bool rt2x00_rt_rev_gte(struct rt2x00_dev *rt2x00dev,
  887. const u16 rt, const u16 rev)
  888. {
  889. return (rt2x00_rt(rt2x00dev, rt) && rt2x00_rev(rt2x00dev) >= rev);
  890. }
  891. static inline void rt2x00_set_chip_intf(struct rt2x00_dev *rt2x00dev,
  892. enum rt2x00_chip_intf intf)
  893. {
  894. rt2x00dev->chip.intf = intf;
  895. }
  896. static inline bool rt2x00_intf(struct rt2x00_dev *rt2x00dev,
  897. enum rt2x00_chip_intf intf)
  898. {
  899. return (rt2x00dev->chip.intf == intf);
  900. }
  901. static inline bool rt2x00_is_pci(struct rt2x00_dev *rt2x00dev)
  902. {
  903. return rt2x00_intf(rt2x00dev, RT2X00_CHIP_INTF_PCI) ||
  904. rt2x00_intf(rt2x00dev, RT2X00_CHIP_INTF_PCIE);
  905. }
  906. static inline bool rt2x00_is_pcie(struct rt2x00_dev *rt2x00dev)
  907. {
  908. return rt2x00_intf(rt2x00dev, RT2X00_CHIP_INTF_PCIE);
  909. }
  910. static inline bool rt2x00_is_usb(struct rt2x00_dev *rt2x00dev)
  911. {
  912. return rt2x00_intf(rt2x00dev, RT2X00_CHIP_INTF_USB);
  913. }
  914. static inline bool rt2x00_is_soc(struct rt2x00_dev *rt2x00dev)
  915. {
  916. return rt2x00_intf(rt2x00dev, RT2X00_CHIP_INTF_SOC);
  917. }
  918. /**
  919. * rt2x00queue_map_txskb - Map a skb into DMA for TX purposes.
  920. * @entry: Pointer to &struct queue_entry
  921. */
  922. void rt2x00queue_map_txskb(struct queue_entry *entry);
  923. /**
  924. * rt2x00queue_unmap_skb - Unmap a skb from DMA.
  925. * @entry: Pointer to &struct queue_entry
  926. */
  927. void rt2x00queue_unmap_skb(struct queue_entry *entry);
  928. /**
  929. * rt2x00queue_get_queue - Convert queue index to queue pointer
  930. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  931. * @queue: rt2x00 queue index (see &enum data_queue_qid).
  932. */
  933. struct data_queue *rt2x00queue_get_queue(struct rt2x00_dev *rt2x00dev,
  934. const enum data_queue_qid queue);
  935. /**
  936. * rt2x00queue_get_entry - Get queue entry where the given index points to.
  937. * @queue: Pointer to &struct data_queue from where we obtain the entry.
  938. * @index: Index identifier for obtaining the correct index.
  939. */
  940. struct queue_entry *rt2x00queue_get_entry(struct data_queue *queue,
  941. enum queue_index index);
  942. /**
  943. * rt2x00queue_pause_queue - Pause a data queue
  944. * @queue: Pointer to &struct data_queue.
  945. *
  946. * This function will pause the data queue locally, preventing
  947. * new frames to be added to the queue (while the hardware is
  948. * still allowed to run).
  949. */
  950. void rt2x00queue_pause_queue(struct data_queue *queue);
  951. /**
  952. * rt2x00queue_unpause_queue - unpause a data queue
  953. * @queue: Pointer to &struct data_queue.
  954. *
  955. * This function will unpause the data queue locally, allowing
  956. * new frames to be added to the queue again.
  957. */
  958. void rt2x00queue_unpause_queue(struct data_queue *queue);
  959. /**
  960. * rt2x00queue_start_queue - Start a data queue
  961. * @queue: Pointer to &struct data_queue.
  962. *
  963. * This function will start handling all pending frames in the queue.
  964. */
  965. void rt2x00queue_start_queue(struct data_queue *queue);
  966. /**
  967. * rt2x00queue_stop_queue - Halt a data queue
  968. * @queue: Pointer to &struct data_queue.
  969. *
  970. * This function will stop all pending frames in the queue.
  971. */
  972. void rt2x00queue_stop_queue(struct data_queue *queue);
  973. /**
  974. * rt2x00queue_flush_queue - Flush a data queue
  975. * @queue: Pointer to &struct data_queue.
  976. * @drop: True to drop all pending frames.
  977. *
  978. * This function will flush the queue. After this call
  979. * the queue is guarenteed to be empty.
  980. */
  981. void rt2x00queue_flush_queue(struct data_queue *queue, bool drop);
  982. /**
  983. * rt2x00queue_start_queues - Start all data queues
  984. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  985. *
  986. * This function will loop through all available queues to start them
  987. */
  988. void rt2x00queue_start_queues(struct rt2x00_dev *rt2x00dev);
  989. /**
  990. * rt2x00queue_stop_queues - Halt all data queues
  991. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  992. *
  993. * This function will loop through all available queues to stop
  994. * any pending frames.
  995. */
  996. void rt2x00queue_stop_queues(struct rt2x00_dev *rt2x00dev);
  997. /**
  998. * rt2x00queue_flush_queues - Flush all data queues
  999. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  1000. * @drop: True to drop all pending frames.
  1001. *
  1002. * This function will loop through all available queues to flush
  1003. * any pending frames.
  1004. */
  1005. void rt2x00queue_flush_queues(struct rt2x00_dev *rt2x00dev, bool drop);
  1006. /*
  1007. * Debugfs handlers.
  1008. */
  1009. /**
  1010. * rt2x00debug_dump_frame - Dump a frame to userspace through debugfs.
  1011. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  1012. * @type: The type of frame that is being dumped.
  1013. * @skb: The skb containing the frame to be dumped.
  1014. */
  1015. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  1016. void rt2x00debug_dump_frame(struct rt2x00_dev *rt2x00dev,
  1017. enum rt2x00_dump_type type, struct sk_buff *skb);
  1018. #else
  1019. static inline void rt2x00debug_dump_frame(struct rt2x00_dev *rt2x00dev,
  1020. enum rt2x00_dump_type type,
  1021. struct sk_buff *skb)
  1022. {
  1023. }
  1024. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  1025. /*
  1026. * Interrupt context handlers.
  1027. */
  1028. void rt2x00lib_beacondone(struct rt2x00_dev *rt2x00dev);
  1029. void rt2x00lib_pretbtt(struct rt2x00_dev *rt2x00dev);
  1030. void rt2x00lib_dmastart(struct queue_entry *entry);
  1031. void rt2x00lib_dmadone(struct queue_entry *entry);
  1032. void rt2x00lib_txdone(struct queue_entry *entry,
  1033. struct txdone_entry_desc *txdesc);
  1034. void rt2x00lib_txdone_noinfo(struct queue_entry *entry, u32 status);
  1035. void rt2x00lib_rxdone(struct queue_entry *entry);
  1036. /*
  1037. * mac80211 handlers.
  1038. */
  1039. int rt2x00mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb);
  1040. int rt2x00mac_start(struct ieee80211_hw *hw);
  1041. void rt2x00mac_stop(struct ieee80211_hw *hw);
  1042. int rt2x00mac_add_interface(struct ieee80211_hw *hw,
  1043. struct ieee80211_vif *vif);
  1044. void rt2x00mac_remove_interface(struct ieee80211_hw *hw,
  1045. struct ieee80211_vif *vif);
  1046. int rt2x00mac_config(struct ieee80211_hw *hw, u32 changed);
  1047. void rt2x00mac_configure_filter(struct ieee80211_hw *hw,
  1048. unsigned int changed_flags,
  1049. unsigned int *total_flags,
  1050. u64 multicast);
  1051. int rt2x00mac_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
  1052. bool set);
  1053. #ifdef CONFIG_RT2X00_LIB_CRYPTO
  1054. int rt2x00mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  1055. struct ieee80211_vif *vif, struct ieee80211_sta *sta,
  1056. struct ieee80211_key_conf *key);
  1057. #else
  1058. #define rt2x00mac_set_key NULL
  1059. #endif /* CONFIG_RT2X00_LIB_CRYPTO */
  1060. void rt2x00mac_sw_scan_start(struct ieee80211_hw *hw);
  1061. void rt2x00mac_sw_scan_complete(struct ieee80211_hw *hw);
  1062. int rt2x00mac_get_stats(struct ieee80211_hw *hw,
  1063. struct ieee80211_low_level_stats *stats);
  1064. void rt2x00mac_bss_info_changed(struct ieee80211_hw *hw,
  1065. struct ieee80211_vif *vif,
  1066. struct ieee80211_bss_conf *bss_conf,
  1067. u32 changes);
  1068. int rt2x00mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
  1069. const struct ieee80211_tx_queue_params *params);
  1070. void rt2x00mac_rfkill_poll(struct ieee80211_hw *hw);
  1071. void rt2x00mac_flush(struct ieee80211_hw *hw, bool drop);
  1072. /*
  1073. * Driver allocation handlers.
  1074. */
  1075. int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev);
  1076. void rt2x00lib_remove_dev(struct rt2x00_dev *rt2x00dev);
  1077. #ifdef CONFIG_PM
  1078. int rt2x00lib_suspend(struct rt2x00_dev *rt2x00dev, pm_message_t state);
  1079. int rt2x00lib_resume(struct rt2x00_dev *rt2x00dev);
  1080. #endif /* CONFIG_PM */
  1081. #endif /* RT2X00_H */