rt2x00.h 31 KB

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