rt2x00.h 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. Copyright (C) 2010 Willow Garage <http://www.willowgarage.com>
  4. Copyright (C) 2004 - 2010 Ivo van Doorn <[email protected]>
  5. Copyright (C) 2004 - 2009 Gertjan van Wingerde <[email protected]>
  6. <http://rt2x00.serialmonkey.com>
  7. */
  8. /*
  9. Module: rt2x00
  10. Abstract: rt2x00 global information.
  11. */
  12. #ifndef RT2X00_H
  13. #define RT2X00_H
  14. #include <linux/bitops.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/skbuff.h>
  17. #include <linux/workqueue.h>
  18. #include <linux/firmware.h>
  19. #include <linux/leds.h>
  20. #include <linux/mutex.h>
  21. #include <linux/etherdevice.h>
  22. #include <linux/kfifo.h>
  23. #include <linux/hrtimer.h>
  24. #include <linux/average.h>
  25. #include <linux/usb.h>
  26. #include <linux/clk.h>
  27. #include <net/mac80211.h>
  28. #include "rt2x00debug.h"
  29. #include "rt2x00dump.h"
  30. #include "rt2x00leds.h"
  31. #include "rt2x00reg.h"
  32. #include "rt2x00queue.h"
  33. /*
  34. * Module information.
  35. */
  36. #define DRV_VERSION "2.3.0"
  37. #define DRV_PROJECT "http://rt2x00.serialmonkey.com"
  38. /* Debug definitions.
  39. * Debug output has to be enabled during compile time.
  40. */
  41. #ifdef CONFIG_RT2X00_DEBUG
  42. #define DEBUG
  43. #endif /* CONFIG_RT2X00_DEBUG */
  44. /* Utility printing macros
  45. * rt2x00_probe_err is for messages when rt2x00_dev is uninitialized
  46. */
  47. #define rt2x00_probe_err(fmt, ...) \
  48. printk(KERN_ERR KBUILD_MODNAME ": %s: Error - " fmt, \
  49. __func__, ##__VA_ARGS__)
  50. #define rt2x00_err(dev, fmt, ...) \
  51. wiphy_err_ratelimited((dev)->hw->wiphy, "%s: Error - " fmt, \
  52. __func__, ##__VA_ARGS__)
  53. #define rt2x00_warn(dev, fmt, ...) \
  54. wiphy_warn_ratelimited((dev)->hw->wiphy, "%s: Warning - " fmt, \
  55. __func__, ##__VA_ARGS__)
  56. #define rt2x00_info(dev, fmt, ...) \
  57. wiphy_info((dev)->hw->wiphy, "%s: Info - " fmt, \
  58. __func__, ##__VA_ARGS__)
  59. /* Various debug levels */
  60. #define rt2x00_dbg(dev, fmt, ...) \
  61. wiphy_dbg((dev)->hw->wiphy, "%s: Debug - " fmt, \
  62. __func__, ##__VA_ARGS__)
  63. #define rt2x00_eeprom_dbg(dev, fmt, ...) \
  64. wiphy_dbg((dev)->hw->wiphy, "%s: EEPROM recovery - " fmt, \
  65. __func__, ##__VA_ARGS__)
  66. /*
  67. * Duration calculations
  68. * The rate variable passed is: 100kbs.
  69. * To convert from bytes to bits we multiply size with 8,
  70. * then the size is multiplied with 10 to make the
  71. * real rate -> rate argument correction.
  72. */
  73. #define GET_DURATION(__size, __rate) (((__size) * 8 * 10) / (__rate))
  74. #define GET_DURATION_RES(__size, __rate)(((__size) * 8 * 10) % (__rate))
  75. /*
  76. * Determine the number of L2 padding bytes required between the header and
  77. * the payload.
  78. */
  79. #define L2PAD_SIZE(__hdrlen) (-(__hdrlen) & 3)
  80. /*
  81. * Determine the alignment requirement,
  82. * to make sure the 802.11 payload is padded to a 4-byte boundrary
  83. * we must determine the address of the payload and calculate the
  84. * amount of bytes needed to move the data.
  85. */
  86. #define ALIGN_SIZE(__skb, __header) \
  87. (((unsigned long)((__skb)->data + (__header))) & 3)
  88. /*
  89. * Constants for extra TX headroom for alignment purposes.
  90. */
  91. #define RT2X00_ALIGN_SIZE 4 /* Only whole frame needs alignment */
  92. #define RT2X00_L2PAD_SIZE 8 /* Both header & payload need alignment */
  93. /*
  94. * Standard timing and size defines.
  95. * These values should follow the ieee80211 specifications.
  96. */
  97. #define ACK_SIZE 14
  98. #define IEEE80211_HEADER 24
  99. #define PLCP 48
  100. #define BEACON 100
  101. #define PREAMBLE 144
  102. #define SHORT_PREAMBLE 72
  103. #define SLOT_TIME 20
  104. #define SHORT_SLOT_TIME 9
  105. #define SIFS 10
  106. #define PIFS (SIFS + SLOT_TIME)
  107. #define SHORT_PIFS (SIFS + SHORT_SLOT_TIME)
  108. #define DIFS (PIFS + SLOT_TIME)
  109. #define SHORT_DIFS (SHORT_PIFS + SHORT_SLOT_TIME)
  110. #define EIFS (SIFS + DIFS + \
  111. GET_DURATION(IEEE80211_HEADER + ACK_SIZE, 10))
  112. #define SHORT_EIFS (SIFS + SHORT_DIFS + \
  113. GET_DURATION(IEEE80211_HEADER + ACK_SIZE, 10))
  114. enum rt2x00_chip_intf {
  115. RT2X00_CHIP_INTF_PCI,
  116. RT2X00_CHIP_INTF_PCIE,
  117. RT2X00_CHIP_INTF_USB,
  118. RT2X00_CHIP_INTF_SOC,
  119. };
  120. /*
  121. * Chipset identification
  122. * The chipset on the device is composed of a RT and RF chip.
  123. * The chipset combination is important for determining device capabilities.
  124. */
  125. struct rt2x00_chip {
  126. u16 rt;
  127. #define RT2460 0x2460
  128. #define RT2560 0x2560
  129. #define RT2570 0x2570
  130. #define RT2661 0x2661
  131. #define RT2573 0x2573
  132. #define RT2860 0x2860 /* 2.4GHz */
  133. #define RT2872 0x2872 /* WSOC */
  134. #define RT2883 0x2883 /* WSOC */
  135. #define RT3070 0x3070
  136. #define RT3071 0x3071
  137. #define RT3090 0x3090 /* 2.4GHz PCIe */
  138. #define RT3290 0x3290
  139. #define RT3352 0x3352 /* WSOC */
  140. #define RT3390 0x3390
  141. #define RT3572 0x3572
  142. #define RT3593 0x3593
  143. #define RT3883 0x3883 /* WSOC */
  144. #define RT5350 0x5350 /* WSOC 2.4GHz */
  145. #define RT5390 0x5390 /* 2.4GHz */
  146. #define RT5392 0x5392 /* 2.4GHz */
  147. #define RT5592 0x5592
  148. #define RT6352 0x6352 /* WSOC 2.4GHz */
  149. u16 rf;
  150. u16 rev;
  151. enum rt2x00_chip_intf intf;
  152. };
  153. /*
  154. * RF register values that belong to a particular channel.
  155. */
  156. struct rf_channel {
  157. int channel;
  158. u32 rf1;
  159. u32 rf2;
  160. u32 rf3;
  161. u32 rf4;
  162. };
  163. /*
  164. * Information structure for channel survey.
  165. */
  166. struct rt2x00_chan_survey {
  167. u64 time_idle;
  168. u64 time_busy;
  169. u64 time_ext_busy;
  170. };
  171. /*
  172. * Channel information structure
  173. */
  174. struct channel_info {
  175. unsigned int flags;
  176. #define GEOGRAPHY_ALLOWED 0x00000001
  177. short max_power;
  178. short default_power1;
  179. short default_power2;
  180. short default_power3;
  181. };
  182. /*
  183. * Antenna setup values.
  184. */
  185. struct antenna_setup {
  186. enum antenna rx;
  187. enum antenna tx;
  188. u8 rx_chain_num;
  189. u8 tx_chain_num;
  190. };
  191. /*
  192. * Quality statistics about the currently active link.
  193. */
  194. struct link_qual {
  195. /*
  196. * Statistics required for Link tuning by driver
  197. * The rssi value is provided by rt2x00lib during the
  198. * link_tuner() callback function.
  199. * The false_cca field is filled during the link_stats()
  200. * callback function and could be used during the
  201. * link_tuner() callback function.
  202. */
  203. int rssi;
  204. int false_cca;
  205. /*
  206. * VGC levels
  207. * Hardware driver will tune the VGC level during each call
  208. * to the link_tuner() callback function. This vgc_level is
  209. * determined based on the link quality statistics like
  210. * average RSSI and the false CCA count.
  211. *
  212. * In some cases the drivers need to differentiate between
  213. * the currently "desired" VGC level and the level configured
  214. * in the hardware. The latter is important to reduce the
  215. * number of BBP register reads to reduce register access
  216. * overhead. For this reason we store both values here.
  217. */
  218. u8 vgc_level;
  219. u8 vgc_level_reg;
  220. /*
  221. * Statistics required for Signal quality calculation.
  222. * These fields might be changed during the link_stats()
  223. * callback function.
  224. */
  225. int rx_success;
  226. int rx_failed;
  227. int tx_success;
  228. int tx_failed;
  229. };
  230. DECLARE_EWMA(rssi, 10, 8)
  231. /*
  232. * Antenna settings about the currently active link.
  233. */
  234. struct link_ant {
  235. /*
  236. * Antenna flags
  237. */
  238. unsigned int flags;
  239. #define ANTENNA_RX_DIVERSITY 0x00000001
  240. #define ANTENNA_TX_DIVERSITY 0x00000002
  241. #define ANTENNA_MODE_SAMPLE 0x00000004
  242. /*
  243. * Currently active TX/RX antenna setup.
  244. * When software diversity is used, this will indicate
  245. * which antenna is actually used at this time.
  246. */
  247. struct antenna_setup active;
  248. /*
  249. * RSSI history information for the antenna.
  250. * Used to determine when to switch antenna
  251. * when using software diversity.
  252. */
  253. int rssi_history;
  254. /*
  255. * Current RSSI average of the currently active antenna.
  256. * Similar to the avg_rssi in the link_qual structure
  257. * this value is updated by using the walking average.
  258. */
  259. struct ewma_rssi rssi_ant;
  260. };
  261. /*
  262. * To optimize the quality of the link we need to store
  263. * the quality of received frames and periodically
  264. * optimize the link.
  265. */
  266. struct link {
  267. /*
  268. * Link tuner counter
  269. * The number of times the link has been tuned
  270. * since the radio has been switched on.
  271. */
  272. u32 count;
  273. /*
  274. * Quality measurement values.
  275. */
  276. struct link_qual qual;
  277. /*
  278. * TX/RX antenna setup.
  279. */
  280. struct link_ant ant;
  281. /*
  282. * Currently active average RSSI value
  283. */
  284. struct ewma_rssi avg_rssi;
  285. /*
  286. * Work structure for scheduling periodic link tuning.
  287. */
  288. struct delayed_work work;
  289. /*
  290. * Work structure for scheduling periodic watchdog monitoring.
  291. * This work must be scheduled on the kernel workqueue, while
  292. * all other work structures must be queued on the mac80211
  293. * workqueue. This guarantees that the watchdog can schedule
  294. * other work structures and wait for their completion in order
  295. * to bring the device/driver back into the desired state.
  296. */
  297. struct delayed_work watchdog_work;
  298. unsigned int watchdog_interval;
  299. bool watchdog_disabled;
  300. /*
  301. * Work structure for scheduling periodic AGC adjustments.
  302. */
  303. struct delayed_work agc_work;
  304. /*
  305. * Work structure for scheduling periodic VCO calibration.
  306. */
  307. struct delayed_work vco_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. atomic_t 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. u8 key[16];
  407. u8 tx_mic[8];
  408. u8 rx_mic[8];
  409. int wcid;
  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 dependent on the operation type.
  422. */
  423. enum tsf_sync sync;
  424. /*
  425. * The MAC and BSSID addresses are simple array of bytes,
  426. * these arrays are little endian, so when sending the addresses
  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. * Private structure for storing STA details
  441. * wcid: Wireless Client ID
  442. */
  443. struct rt2x00_sta {
  444. int wcid;
  445. };
  446. static inline struct rt2x00_sta* sta_to_rt2x00_sta(struct ieee80211_sta *sta)
  447. {
  448. return (struct rt2x00_sta *)sta->drv_priv;
  449. }
  450. /*
  451. * rt2x00lib callback functions.
  452. */
  453. struct rt2x00lib_ops {
  454. /*
  455. * Interrupt handlers.
  456. */
  457. irq_handler_t irq_handler;
  458. /*
  459. * TX status tasklet handler.
  460. */
  461. void (*txstatus_tasklet) (struct tasklet_struct *t);
  462. void (*pretbtt_tasklet) (struct tasklet_struct *t);
  463. void (*tbtt_tasklet) (struct tasklet_struct *t);
  464. void (*rxdone_tasklet) (struct tasklet_struct *t);
  465. void (*autowake_tasklet) (struct tasklet_struct *t);
  466. /*
  467. * Device init handlers.
  468. */
  469. int (*probe_hw) (struct rt2x00_dev *rt2x00dev);
  470. char *(*get_firmware_name) (struct rt2x00_dev *rt2x00dev);
  471. int (*check_firmware) (struct rt2x00_dev *rt2x00dev,
  472. const u8 *data, const size_t len);
  473. int (*load_firmware) (struct rt2x00_dev *rt2x00dev,
  474. const u8 *data, const size_t len);
  475. /*
  476. * Device initialization/deinitialization handlers.
  477. */
  478. int (*initialize) (struct rt2x00_dev *rt2x00dev);
  479. void (*uninitialize) (struct rt2x00_dev *rt2x00dev);
  480. /*
  481. * queue initialization handlers
  482. */
  483. bool (*get_entry_state) (struct queue_entry *entry);
  484. void (*clear_entry) (struct queue_entry *entry);
  485. /*
  486. * Radio control handlers.
  487. */
  488. int (*set_device_state) (struct rt2x00_dev *rt2x00dev,
  489. enum dev_state state);
  490. int (*rfkill_poll) (struct rt2x00_dev *rt2x00dev);
  491. void (*link_stats) (struct rt2x00_dev *rt2x00dev,
  492. struct link_qual *qual);
  493. void (*reset_tuner) (struct rt2x00_dev *rt2x00dev,
  494. struct link_qual *qual);
  495. void (*link_tuner) (struct rt2x00_dev *rt2x00dev,
  496. struct link_qual *qual, const u32 count);
  497. void (*gain_calibration) (struct rt2x00_dev *rt2x00dev);
  498. void (*vco_calibration) (struct rt2x00_dev *rt2x00dev);
  499. /*
  500. * Data queue handlers.
  501. */
  502. void (*watchdog) (struct rt2x00_dev *rt2x00dev);
  503. void (*start_queue) (struct data_queue *queue);
  504. void (*kick_queue) (struct data_queue *queue);
  505. void (*stop_queue) (struct data_queue *queue);
  506. void (*flush_queue) (struct data_queue *queue, bool drop);
  507. void (*tx_dma_done) (struct queue_entry *entry);
  508. /*
  509. * TX control handlers
  510. */
  511. void (*write_tx_desc) (struct queue_entry *entry,
  512. struct txentry_desc *txdesc);
  513. void (*write_tx_data) (struct queue_entry *entry,
  514. struct txentry_desc *txdesc);
  515. void (*write_beacon) (struct queue_entry *entry,
  516. struct txentry_desc *txdesc);
  517. void (*clear_beacon) (struct queue_entry *entry);
  518. int (*get_tx_data_len) (struct queue_entry *entry);
  519. /*
  520. * RX control handlers
  521. */
  522. void (*fill_rxdone) (struct queue_entry *entry,
  523. struct rxdone_entry_desc *rxdesc);
  524. /*
  525. * Configuration handlers.
  526. */
  527. int (*config_shared_key) (struct rt2x00_dev *rt2x00dev,
  528. struct rt2x00lib_crypto *crypto,
  529. struct ieee80211_key_conf *key);
  530. int (*config_pairwise_key) (struct rt2x00_dev *rt2x00dev,
  531. struct rt2x00lib_crypto *crypto,
  532. struct ieee80211_key_conf *key);
  533. void (*config_filter) (struct rt2x00_dev *rt2x00dev,
  534. const unsigned int filter_flags);
  535. void (*config_intf) (struct rt2x00_dev *rt2x00dev,
  536. struct rt2x00_intf *intf,
  537. struct rt2x00intf_conf *conf,
  538. const unsigned int flags);
  539. #define CONFIG_UPDATE_TYPE ( 1 << 1 )
  540. #define CONFIG_UPDATE_MAC ( 1 << 2 )
  541. #define CONFIG_UPDATE_BSSID ( 1 << 3 )
  542. void (*config_erp) (struct rt2x00_dev *rt2x00dev,
  543. struct rt2x00lib_erp *erp,
  544. u32 changed);
  545. void (*config_ant) (struct rt2x00_dev *rt2x00dev,
  546. struct antenna_setup *ant);
  547. void (*config) (struct rt2x00_dev *rt2x00dev,
  548. struct rt2x00lib_conf *libconf,
  549. const unsigned int changed_flags);
  550. void (*pre_reset_hw) (struct rt2x00_dev *rt2x00dev);
  551. int (*sta_add) (struct rt2x00_dev *rt2x00dev,
  552. struct ieee80211_vif *vif,
  553. struct ieee80211_sta *sta);
  554. int (*sta_remove) (struct rt2x00_dev *rt2x00dev,
  555. struct ieee80211_sta *sta);
  556. };
  557. /*
  558. * rt2x00 driver callback operation structure.
  559. */
  560. struct rt2x00_ops {
  561. const char *name;
  562. const unsigned int drv_data_size;
  563. const unsigned int max_ap_intf;
  564. const unsigned int eeprom_size;
  565. const unsigned int rf_size;
  566. const unsigned int tx_queues;
  567. void (*queue_init)(struct data_queue *queue);
  568. const struct rt2x00lib_ops *lib;
  569. const void *drv;
  570. const struct ieee80211_ops *hw;
  571. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  572. const struct rt2x00debug *debugfs;
  573. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  574. };
  575. /*
  576. * rt2x00 state flags
  577. */
  578. enum rt2x00_state_flags {
  579. /*
  580. * Device flags
  581. */
  582. DEVICE_STATE_PRESENT,
  583. DEVICE_STATE_REGISTERED_HW,
  584. DEVICE_STATE_INITIALIZED,
  585. DEVICE_STATE_STARTED,
  586. DEVICE_STATE_ENABLED_RADIO,
  587. DEVICE_STATE_SCANNING,
  588. DEVICE_STATE_FLUSHING,
  589. DEVICE_STATE_RESET,
  590. /*
  591. * Driver configuration
  592. */
  593. CONFIG_CHANNEL_HT40,
  594. CONFIG_POWERSAVING,
  595. CONFIG_HT_DISABLED,
  596. CONFIG_MONITORING,
  597. /*
  598. * Mark we currently are sequentially reading TX_STA_FIFO register
  599. * FIXME: this is for only rt2800usb, should go to private data
  600. */
  601. TX_STATUS_READING,
  602. };
  603. /*
  604. * rt2x00 capability flags
  605. */
  606. enum rt2x00_capability_flags {
  607. /*
  608. * Requirements
  609. */
  610. REQUIRE_FIRMWARE,
  611. REQUIRE_BEACON_GUARD,
  612. REQUIRE_ATIM_QUEUE,
  613. REQUIRE_DMA,
  614. REQUIRE_COPY_IV,
  615. REQUIRE_L2PAD,
  616. REQUIRE_TXSTATUS_FIFO,
  617. REQUIRE_TASKLET_CONTEXT,
  618. REQUIRE_SW_SEQNO,
  619. REQUIRE_HT_TX_DESC,
  620. REQUIRE_PS_AUTOWAKE,
  621. REQUIRE_DELAYED_RFKILL,
  622. /*
  623. * Capabilities
  624. */
  625. CAPABILITY_HW_BUTTON,
  626. CAPABILITY_HW_CRYPTO,
  627. CAPABILITY_POWER_LIMIT,
  628. CAPABILITY_CONTROL_FILTERS,
  629. CAPABILITY_CONTROL_FILTER_PSPOLL,
  630. CAPABILITY_PRE_TBTT_INTERRUPT,
  631. CAPABILITY_LINK_TUNING,
  632. CAPABILITY_FRAME_TYPE,
  633. CAPABILITY_RF_SEQUENCE,
  634. CAPABILITY_EXTERNAL_LNA_A,
  635. CAPABILITY_EXTERNAL_LNA_BG,
  636. CAPABILITY_DOUBLE_ANTENNA,
  637. CAPABILITY_BT_COEXIST,
  638. CAPABILITY_VCO_RECALIBRATION,
  639. CAPABILITY_EXTERNAL_PA_TX0,
  640. CAPABILITY_EXTERNAL_PA_TX1,
  641. CAPABILITY_RESTART_HW,
  642. };
  643. /*
  644. * Interface combinations
  645. */
  646. enum {
  647. IF_COMB_AP = 0,
  648. NUM_IF_COMB,
  649. };
  650. /*
  651. * rt2x00 device structure.
  652. */
  653. struct rt2x00_dev {
  654. /*
  655. * Device structure.
  656. * The structure stored in here depends on the
  657. * system bus (PCI or USB).
  658. * When accessing this variable, the rt2x00dev_{pci,usb}
  659. * macros should be used for correct typecasting.
  660. */
  661. struct device *dev;
  662. /*
  663. * Callback functions.
  664. */
  665. const struct rt2x00_ops *ops;
  666. /*
  667. * Driver data.
  668. */
  669. void *drv_data;
  670. /*
  671. * IEEE80211 control structure.
  672. */
  673. struct ieee80211_hw *hw;
  674. struct ieee80211_supported_band bands[NUM_NL80211_BANDS];
  675. struct rt2x00_chan_survey *chan_survey;
  676. enum nl80211_band curr_band;
  677. int curr_freq;
  678. /*
  679. * If enabled, the debugfs interface structures
  680. * required for deregistration of debugfs.
  681. */
  682. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  683. struct rt2x00debug_intf *debugfs_intf;
  684. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  685. /*
  686. * LED structure for changing the LED status
  687. * by mac8011 or the kernel.
  688. */
  689. #ifdef CONFIG_RT2X00_LIB_LEDS
  690. struct rt2x00_led led_radio;
  691. struct rt2x00_led led_assoc;
  692. struct rt2x00_led led_qual;
  693. u16 led_mcu_reg;
  694. #endif /* CONFIG_RT2X00_LIB_LEDS */
  695. /*
  696. * Device state flags.
  697. * In these flags the current status is stored.
  698. * Access to these flags should occur atomically.
  699. */
  700. unsigned long flags;
  701. /*
  702. * Device capabiltiy flags.
  703. * In these flags the device/driver capabilities are stored.
  704. * Access to these flags should occur non-atomically.
  705. */
  706. unsigned long cap_flags;
  707. /*
  708. * Device information, Bus IRQ and name (PCI, SoC)
  709. */
  710. int irq;
  711. const char *name;
  712. /*
  713. * Chipset identification.
  714. */
  715. struct rt2x00_chip chip;
  716. /*
  717. * hw capability specifications.
  718. */
  719. struct hw_mode_spec spec;
  720. /*
  721. * This is the default TX/RX antenna setup as indicated
  722. * by the device's EEPROM.
  723. */
  724. struct antenna_setup default_ant;
  725. /*
  726. * Register pointers
  727. * csr.base: CSR base register address. (PCI)
  728. * csr.cache: CSR cache for usb_control_msg. (USB)
  729. */
  730. union csr {
  731. void __iomem *base;
  732. void *cache;
  733. } csr;
  734. /*
  735. * Mutex to protect register accesses.
  736. * For PCI and USB devices it protects against concurrent indirect
  737. * register access (BBP, RF, MCU) since accessing those
  738. * registers require multiple calls to the CSR registers.
  739. * For USB devices it also protects the csr_cache since that
  740. * field is used for normal CSR access and it cannot support
  741. * multiple callers simultaneously.
  742. */
  743. struct mutex csr_mutex;
  744. /*
  745. * Mutex to synchronize config and link tuner.
  746. */
  747. struct mutex conf_mutex;
  748. /*
  749. * Current packet filter configuration for the device.
  750. * This contains all currently active FIF_* flags send
  751. * to us by mac80211 during configure_filter().
  752. */
  753. unsigned int packet_filter;
  754. /*
  755. * Interface details:
  756. * - Open ap interface count.
  757. * - Open sta interface count.
  758. * - Association count.
  759. * - Beaconing enabled count.
  760. */
  761. unsigned int intf_ap_count;
  762. unsigned int intf_sta_count;
  763. unsigned int intf_associated;
  764. unsigned int intf_beaconing;
  765. /*
  766. * Interface combinations
  767. */
  768. struct ieee80211_iface_limit if_limits_ap;
  769. struct ieee80211_iface_combination if_combinations[NUM_IF_COMB];
  770. /*
  771. * Link quality
  772. */
  773. struct link link;
  774. /*
  775. * EEPROM data.
  776. */
  777. __le16 *eeprom;
  778. /*
  779. * Active RF register values.
  780. * These are stored here so we don't need
  781. * to read the rf registers and can directly
  782. * use this value instead.
  783. * This field should be accessed by using
  784. * rt2x00_rf_read() and rt2x00_rf_write().
  785. */
  786. u32 *rf;
  787. /*
  788. * LNA gain
  789. */
  790. short lna_gain;
  791. /*
  792. * Current TX power value.
  793. */
  794. u16 tx_power;
  795. /*
  796. * Current retry values.
  797. */
  798. u8 short_retry;
  799. u8 long_retry;
  800. /*
  801. * Rssi <-> Dbm offset
  802. */
  803. u8 rssi_offset;
  804. /*
  805. * Frequency offset.
  806. */
  807. u8 freq_offset;
  808. /*
  809. * Association id.
  810. */
  811. u16 aid;
  812. /*
  813. * Beacon interval.
  814. */
  815. u16 beacon_int;
  816. /**
  817. * Timestamp of last received beacon
  818. */
  819. unsigned long last_beacon;
  820. /*
  821. * Low level statistics which will have
  822. * to be kept up to date while device is running.
  823. */
  824. struct ieee80211_low_level_stats low_level_stats;
  825. /**
  826. * Work queue for all work which should not be placed
  827. * on the mac80211 workqueue (because of dependencies
  828. * between various work structures).
  829. */
  830. struct workqueue_struct *workqueue;
  831. /*
  832. * Scheduled work.
  833. * NOTE: intf_work will use ieee80211_iterate_active_interfaces()
  834. * which means it cannot be placed on the hw->workqueue
  835. * due to RTNL locking requirements.
  836. */
  837. struct work_struct intf_work;
  838. /**
  839. * Scheduled work for TX/RX done handling (USB devices)
  840. */
  841. struct work_struct rxdone_work;
  842. struct work_struct txdone_work;
  843. /*
  844. * Powersaving work
  845. */
  846. struct delayed_work autowakeup_work;
  847. struct work_struct sleep_work;
  848. /*
  849. * Data queue arrays for RX, TX, Beacon and ATIM.
  850. */
  851. unsigned int data_queues;
  852. struct data_queue *rx;
  853. struct data_queue *tx;
  854. struct data_queue *bcn;
  855. struct data_queue *atim;
  856. /*
  857. * Firmware image.
  858. */
  859. const struct firmware *fw;
  860. /*
  861. * FIFO for storing tx status reports between isr and tasklet.
  862. */
  863. DECLARE_KFIFO_PTR(txstatus_fifo, u32);
  864. /*
  865. * Timer to ensure tx status reports are read (rt2800usb).
  866. */
  867. struct hrtimer txstatus_timer;
  868. /*
  869. * Tasklet for processing tx status reports (rt2800pci).
  870. */
  871. struct tasklet_struct txstatus_tasklet;
  872. struct tasklet_struct pretbtt_tasklet;
  873. struct tasklet_struct tbtt_tasklet;
  874. struct tasklet_struct rxdone_tasklet;
  875. struct tasklet_struct autowake_tasklet;
  876. /*
  877. * Used for VCO periodic calibration.
  878. */
  879. int rf_channel;
  880. /*
  881. * Protect the interrupt mask register.
  882. */
  883. spinlock_t irqmask_lock;
  884. /*
  885. * List of BlockAckReq TX entries that need driver BlockAck processing.
  886. */
  887. struct list_head bar_list;
  888. spinlock_t bar_list_lock;
  889. /* Extra TX headroom required for alignment purposes. */
  890. unsigned int extra_tx_headroom;
  891. struct usb_anchor *anchor;
  892. unsigned int num_proto_errs;
  893. /* Clock for System On Chip devices. */
  894. struct clk *clk;
  895. };
  896. struct rt2x00_bar_list_entry {
  897. struct list_head list;
  898. struct rcu_head head;
  899. struct queue_entry *entry;
  900. int block_acked;
  901. /* Relevant parts of the IEEE80211 BAR header */
  902. __u8 ra[6];
  903. __u8 ta[6];
  904. __le16 control;
  905. __le16 start_seq_num;
  906. };
  907. /*
  908. * Register defines.
  909. * Some registers require multiple attempts before success,
  910. * in those cases REGISTER_BUSY_COUNT attempts should be
  911. * taken with a REGISTER_BUSY_DELAY interval. Due to USB
  912. * bus delays, we do not have to loop so many times to wait
  913. * for valid register value on that bus.
  914. */
  915. #define REGISTER_BUSY_COUNT 100
  916. #define REGISTER_USB_BUSY_COUNT 20
  917. #define REGISTER_BUSY_DELAY 100
  918. /*
  919. * Generic RF access.
  920. * The RF is being accessed by word index.
  921. */
  922. static inline u32 rt2x00_rf_read(struct rt2x00_dev *rt2x00dev,
  923. const unsigned int word)
  924. {
  925. BUG_ON(word < 1 || word > rt2x00dev->ops->rf_size / sizeof(u32));
  926. return rt2x00dev->rf[word - 1];
  927. }
  928. static inline void rt2x00_rf_write(struct rt2x00_dev *rt2x00dev,
  929. const unsigned int word, u32 data)
  930. {
  931. BUG_ON(word < 1 || word > rt2x00dev->ops->rf_size / sizeof(u32));
  932. rt2x00dev->rf[word - 1] = data;
  933. }
  934. /*
  935. * Generic EEPROM access. The EEPROM is being accessed by word or byte index.
  936. */
  937. static inline void *rt2x00_eeprom_addr(struct rt2x00_dev *rt2x00dev,
  938. const unsigned int word)
  939. {
  940. return (void *)&rt2x00dev->eeprom[word];
  941. }
  942. static inline u16 rt2x00_eeprom_read(struct rt2x00_dev *rt2x00dev,
  943. const unsigned int word)
  944. {
  945. return le16_to_cpu(rt2x00dev->eeprom[word]);
  946. }
  947. static inline void rt2x00_eeprom_write(struct rt2x00_dev *rt2x00dev,
  948. const unsigned int word, u16 data)
  949. {
  950. rt2x00dev->eeprom[word] = cpu_to_le16(data);
  951. }
  952. static inline u8 rt2x00_eeprom_byte(struct rt2x00_dev *rt2x00dev,
  953. const unsigned int byte)
  954. {
  955. return *(((u8 *)rt2x00dev->eeprom) + byte);
  956. }
  957. /*
  958. * Chipset handlers
  959. */
  960. static inline void rt2x00_set_chip(struct rt2x00_dev *rt2x00dev,
  961. const u16 rt, const u16 rf, const u16 rev)
  962. {
  963. rt2x00dev->chip.rt = rt;
  964. rt2x00dev->chip.rf = rf;
  965. rt2x00dev->chip.rev = rev;
  966. rt2x00_info(rt2x00dev, "Chipset detected - rt: %04x, rf: %04x, rev: %04x\n",
  967. rt2x00dev->chip.rt, rt2x00dev->chip.rf,
  968. rt2x00dev->chip.rev);
  969. }
  970. static inline void rt2x00_set_rt(struct rt2x00_dev *rt2x00dev,
  971. const u16 rt, const u16 rev)
  972. {
  973. rt2x00dev->chip.rt = rt;
  974. rt2x00dev->chip.rev = rev;
  975. rt2x00_info(rt2x00dev, "RT chipset %04x, rev %04x detected\n",
  976. rt2x00dev->chip.rt, rt2x00dev->chip.rev);
  977. }
  978. static inline void rt2x00_set_rf(struct rt2x00_dev *rt2x00dev, const u16 rf)
  979. {
  980. rt2x00dev->chip.rf = rf;
  981. rt2x00_info(rt2x00dev, "RF chipset %04x detected\n",
  982. rt2x00dev->chip.rf);
  983. }
  984. static inline bool rt2x00_rt(struct rt2x00_dev *rt2x00dev, const u16 rt)
  985. {
  986. return (rt2x00dev->chip.rt == rt);
  987. }
  988. static inline bool rt2x00_rf(struct rt2x00_dev *rt2x00dev, const u16 rf)
  989. {
  990. return (rt2x00dev->chip.rf == rf);
  991. }
  992. static inline u16 rt2x00_rev(struct rt2x00_dev *rt2x00dev)
  993. {
  994. return rt2x00dev->chip.rev;
  995. }
  996. static inline bool rt2x00_rt_rev(struct rt2x00_dev *rt2x00dev,
  997. const u16 rt, const u16 rev)
  998. {
  999. return (rt2x00_rt(rt2x00dev, rt) && rt2x00_rev(rt2x00dev) == rev);
  1000. }
  1001. static inline bool rt2x00_rt_rev_lt(struct rt2x00_dev *rt2x00dev,
  1002. const u16 rt, const u16 rev)
  1003. {
  1004. return (rt2x00_rt(rt2x00dev, rt) && rt2x00_rev(rt2x00dev) < rev);
  1005. }
  1006. static inline bool rt2x00_rt_rev_gte(struct rt2x00_dev *rt2x00dev,
  1007. const u16 rt, const u16 rev)
  1008. {
  1009. return (rt2x00_rt(rt2x00dev, rt) && rt2x00_rev(rt2x00dev) >= rev);
  1010. }
  1011. static inline void rt2x00_set_chip_intf(struct rt2x00_dev *rt2x00dev,
  1012. enum rt2x00_chip_intf intf)
  1013. {
  1014. rt2x00dev->chip.intf = intf;
  1015. }
  1016. static inline bool rt2x00_intf(struct rt2x00_dev *rt2x00dev,
  1017. enum rt2x00_chip_intf intf)
  1018. {
  1019. return (rt2x00dev->chip.intf == intf);
  1020. }
  1021. static inline bool rt2x00_is_pci(struct rt2x00_dev *rt2x00dev)
  1022. {
  1023. return rt2x00_intf(rt2x00dev, RT2X00_CHIP_INTF_PCI) ||
  1024. rt2x00_intf(rt2x00dev, RT2X00_CHIP_INTF_PCIE);
  1025. }
  1026. static inline bool rt2x00_is_pcie(struct rt2x00_dev *rt2x00dev)
  1027. {
  1028. return rt2x00_intf(rt2x00dev, RT2X00_CHIP_INTF_PCIE);
  1029. }
  1030. static inline bool rt2x00_is_usb(struct rt2x00_dev *rt2x00dev)
  1031. {
  1032. return rt2x00_intf(rt2x00dev, RT2X00_CHIP_INTF_USB);
  1033. }
  1034. static inline bool rt2x00_is_soc(struct rt2x00_dev *rt2x00dev)
  1035. {
  1036. return rt2x00_intf(rt2x00dev, RT2X00_CHIP_INTF_SOC);
  1037. }
  1038. /* Helpers for capability flags */
  1039. static inline bool
  1040. rt2x00_has_cap_flag(struct rt2x00_dev *rt2x00dev,
  1041. enum rt2x00_capability_flags cap_flag)
  1042. {
  1043. return test_bit(cap_flag, &rt2x00dev->cap_flags);
  1044. }
  1045. static inline bool
  1046. rt2x00_has_cap_hw_crypto(struct rt2x00_dev *rt2x00dev)
  1047. {
  1048. return rt2x00_has_cap_flag(rt2x00dev, CAPABILITY_HW_CRYPTO);
  1049. }
  1050. static inline bool
  1051. rt2x00_has_cap_power_limit(struct rt2x00_dev *rt2x00dev)
  1052. {
  1053. return rt2x00_has_cap_flag(rt2x00dev, CAPABILITY_POWER_LIMIT);
  1054. }
  1055. static inline bool
  1056. rt2x00_has_cap_control_filters(struct rt2x00_dev *rt2x00dev)
  1057. {
  1058. return rt2x00_has_cap_flag(rt2x00dev, CAPABILITY_CONTROL_FILTERS);
  1059. }
  1060. static inline bool
  1061. rt2x00_has_cap_control_filter_pspoll(struct rt2x00_dev *rt2x00dev)
  1062. {
  1063. return rt2x00_has_cap_flag(rt2x00dev, CAPABILITY_CONTROL_FILTER_PSPOLL);
  1064. }
  1065. static inline bool
  1066. rt2x00_has_cap_pre_tbtt_interrupt(struct rt2x00_dev *rt2x00dev)
  1067. {
  1068. return rt2x00_has_cap_flag(rt2x00dev, CAPABILITY_PRE_TBTT_INTERRUPT);
  1069. }
  1070. static inline bool
  1071. rt2x00_has_cap_link_tuning(struct rt2x00_dev *rt2x00dev)
  1072. {
  1073. return rt2x00_has_cap_flag(rt2x00dev, CAPABILITY_LINK_TUNING);
  1074. }
  1075. static inline bool
  1076. rt2x00_has_cap_frame_type(struct rt2x00_dev *rt2x00dev)
  1077. {
  1078. return rt2x00_has_cap_flag(rt2x00dev, CAPABILITY_FRAME_TYPE);
  1079. }
  1080. static inline bool
  1081. rt2x00_has_cap_rf_sequence(struct rt2x00_dev *rt2x00dev)
  1082. {
  1083. return rt2x00_has_cap_flag(rt2x00dev, CAPABILITY_RF_SEQUENCE);
  1084. }
  1085. static inline bool
  1086. rt2x00_has_cap_external_lna_a(struct rt2x00_dev *rt2x00dev)
  1087. {
  1088. return rt2x00_has_cap_flag(rt2x00dev, CAPABILITY_EXTERNAL_LNA_A);
  1089. }
  1090. static inline bool
  1091. rt2x00_has_cap_external_lna_bg(struct rt2x00_dev *rt2x00dev)
  1092. {
  1093. return rt2x00_has_cap_flag(rt2x00dev, CAPABILITY_EXTERNAL_LNA_BG);
  1094. }
  1095. static inline bool
  1096. rt2x00_has_cap_double_antenna(struct rt2x00_dev *rt2x00dev)
  1097. {
  1098. return rt2x00_has_cap_flag(rt2x00dev, CAPABILITY_DOUBLE_ANTENNA);
  1099. }
  1100. static inline bool
  1101. rt2x00_has_cap_bt_coexist(struct rt2x00_dev *rt2x00dev)
  1102. {
  1103. return rt2x00_has_cap_flag(rt2x00dev, CAPABILITY_BT_COEXIST);
  1104. }
  1105. static inline bool
  1106. rt2x00_has_cap_vco_recalibration(struct rt2x00_dev *rt2x00dev)
  1107. {
  1108. return rt2x00_has_cap_flag(rt2x00dev, CAPABILITY_VCO_RECALIBRATION);
  1109. }
  1110. static inline bool
  1111. rt2x00_has_cap_restart_hw(struct rt2x00_dev *rt2x00dev)
  1112. {
  1113. return rt2x00_has_cap_flag(rt2x00dev, CAPABILITY_RESTART_HW);
  1114. }
  1115. /**
  1116. * rt2x00queue_map_txskb - Map a skb into DMA for TX purposes.
  1117. * @entry: Pointer to &struct queue_entry
  1118. *
  1119. * Returns -ENOMEM if mapping fail, 0 otherwise.
  1120. */
  1121. int rt2x00queue_map_txskb(struct queue_entry *entry);
  1122. /**
  1123. * rt2x00queue_unmap_skb - Unmap a skb from DMA.
  1124. * @entry: Pointer to &struct queue_entry
  1125. */
  1126. void rt2x00queue_unmap_skb(struct queue_entry *entry);
  1127. /**
  1128. * rt2x00queue_get_tx_queue - Convert tx queue index to queue pointer
  1129. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  1130. * @queue: rt2x00 queue index (see &enum data_queue_qid).
  1131. *
  1132. * Returns NULL for non tx queues.
  1133. */
  1134. static inline struct data_queue *
  1135. rt2x00queue_get_tx_queue(struct rt2x00_dev *rt2x00dev,
  1136. enum data_queue_qid queue)
  1137. {
  1138. if (queue >= rt2x00dev->ops->tx_queues && queue < IEEE80211_NUM_ACS)
  1139. queue = rt2x00dev->ops->tx_queues - 1;
  1140. if (queue < rt2x00dev->ops->tx_queues && rt2x00dev->tx)
  1141. return &rt2x00dev->tx[queue];
  1142. if (queue == QID_ATIM)
  1143. return rt2x00dev->atim;
  1144. return NULL;
  1145. }
  1146. /**
  1147. * rt2x00queue_get_entry - Get queue entry where the given index points to.
  1148. * @queue: Pointer to &struct data_queue from where we obtain the entry.
  1149. * @index: Index identifier for obtaining the correct index.
  1150. */
  1151. struct queue_entry *rt2x00queue_get_entry(struct data_queue *queue,
  1152. enum queue_index index);
  1153. /**
  1154. * rt2x00queue_pause_queue - Pause a data queue
  1155. * @queue: Pointer to &struct data_queue.
  1156. *
  1157. * This function will pause the data queue locally, preventing
  1158. * new frames to be added to the queue (while the hardware is
  1159. * still allowed to run).
  1160. */
  1161. void rt2x00queue_pause_queue(struct data_queue *queue);
  1162. /**
  1163. * rt2x00queue_unpause_queue - unpause a data queue
  1164. * @queue: Pointer to &struct data_queue.
  1165. *
  1166. * This function will unpause the data queue locally, allowing
  1167. * new frames to be added to the queue again.
  1168. */
  1169. void rt2x00queue_unpause_queue(struct data_queue *queue);
  1170. /**
  1171. * rt2x00queue_start_queue - Start a data queue
  1172. * @queue: Pointer to &struct data_queue.
  1173. *
  1174. * This function will start handling all pending frames in the queue.
  1175. */
  1176. void rt2x00queue_start_queue(struct data_queue *queue);
  1177. /**
  1178. * rt2x00queue_stop_queue - Halt a data queue
  1179. * @queue: Pointer to &struct data_queue.
  1180. *
  1181. * This function will stop all pending frames in the queue.
  1182. */
  1183. void rt2x00queue_stop_queue(struct data_queue *queue);
  1184. /**
  1185. * rt2x00queue_flush_queue - Flush a data queue
  1186. * @queue: Pointer to &struct data_queue.
  1187. * @drop: True to drop all pending frames.
  1188. *
  1189. * This function will flush the queue. After this call
  1190. * the queue is guaranteed to be empty.
  1191. */
  1192. void rt2x00queue_flush_queue(struct data_queue *queue, bool drop);
  1193. /**
  1194. * rt2x00queue_start_queues - Start all data queues
  1195. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  1196. *
  1197. * This function will loop through all available queues to start them
  1198. */
  1199. void rt2x00queue_start_queues(struct rt2x00_dev *rt2x00dev);
  1200. /**
  1201. * rt2x00queue_stop_queues - Halt all data queues
  1202. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  1203. *
  1204. * This function will loop through all available queues to stop
  1205. * any pending frames.
  1206. */
  1207. void rt2x00queue_stop_queues(struct rt2x00_dev *rt2x00dev);
  1208. /**
  1209. * rt2x00queue_flush_queues - Flush all data queues
  1210. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  1211. * @drop: True to drop all pending frames.
  1212. *
  1213. * This function will loop through all available queues to flush
  1214. * any pending frames.
  1215. */
  1216. void rt2x00queue_flush_queues(struct rt2x00_dev *rt2x00dev, bool drop);
  1217. /*
  1218. * Debugfs handlers.
  1219. */
  1220. /**
  1221. * rt2x00debug_dump_frame - Dump a frame to userspace through debugfs.
  1222. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  1223. * @type: The type of frame that is being dumped.
  1224. * @entry: The queue entry containing the frame to be dumped.
  1225. */
  1226. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  1227. void rt2x00debug_dump_frame(struct rt2x00_dev *rt2x00dev,
  1228. enum rt2x00_dump_type type, struct queue_entry *entry);
  1229. #else
  1230. static inline void rt2x00debug_dump_frame(struct rt2x00_dev *rt2x00dev,
  1231. enum rt2x00_dump_type type,
  1232. struct queue_entry *entry)
  1233. {
  1234. }
  1235. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  1236. /*
  1237. * Utility functions.
  1238. */
  1239. u32 rt2x00lib_get_bssidx(struct rt2x00_dev *rt2x00dev,
  1240. struct ieee80211_vif *vif);
  1241. void rt2x00lib_set_mac_address(struct rt2x00_dev *rt2x00dev, u8 *eeprom_mac_addr);
  1242. /*
  1243. * Interrupt context handlers.
  1244. */
  1245. void rt2x00lib_beacondone(struct rt2x00_dev *rt2x00dev);
  1246. void rt2x00lib_pretbtt(struct rt2x00_dev *rt2x00dev);
  1247. void rt2x00lib_dmastart(struct queue_entry *entry);
  1248. void rt2x00lib_dmadone(struct queue_entry *entry);
  1249. void rt2x00lib_txdone(struct queue_entry *entry,
  1250. struct txdone_entry_desc *txdesc);
  1251. void rt2x00lib_txdone_nomatch(struct queue_entry *entry,
  1252. struct txdone_entry_desc *txdesc);
  1253. void rt2x00lib_txdone_noinfo(struct queue_entry *entry, u32 status);
  1254. void rt2x00lib_rxdone(struct queue_entry *entry, gfp_t gfp);
  1255. /*
  1256. * mac80211 handlers.
  1257. */
  1258. void rt2x00mac_tx(struct ieee80211_hw *hw,
  1259. struct ieee80211_tx_control *control,
  1260. struct sk_buff *skb);
  1261. int rt2x00mac_start(struct ieee80211_hw *hw);
  1262. void rt2x00mac_stop(struct ieee80211_hw *hw);
  1263. void rt2x00mac_reconfig_complete(struct ieee80211_hw *hw,
  1264. enum ieee80211_reconfig_type reconfig_type);
  1265. int rt2x00mac_add_interface(struct ieee80211_hw *hw,
  1266. struct ieee80211_vif *vif);
  1267. void rt2x00mac_remove_interface(struct ieee80211_hw *hw,
  1268. struct ieee80211_vif *vif);
  1269. int rt2x00mac_config(struct ieee80211_hw *hw, u32 changed);
  1270. void rt2x00mac_configure_filter(struct ieee80211_hw *hw,
  1271. unsigned int changed_flags,
  1272. unsigned int *total_flags,
  1273. u64 multicast);
  1274. int rt2x00mac_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
  1275. bool set);
  1276. #ifdef CONFIG_RT2X00_LIB_CRYPTO
  1277. int rt2x00mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  1278. struct ieee80211_vif *vif, struct ieee80211_sta *sta,
  1279. struct ieee80211_key_conf *key);
  1280. #else
  1281. #define rt2x00mac_set_key NULL
  1282. #endif /* CONFIG_RT2X00_LIB_CRYPTO */
  1283. void rt2x00mac_sw_scan_start(struct ieee80211_hw *hw,
  1284. struct ieee80211_vif *vif,
  1285. const u8 *mac_addr);
  1286. void rt2x00mac_sw_scan_complete(struct ieee80211_hw *hw,
  1287. struct ieee80211_vif *vif);
  1288. int rt2x00mac_get_stats(struct ieee80211_hw *hw,
  1289. struct ieee80211_low_level_stats *stats);
  1290. void rt2x00mac_bss_info_changed(struct ieee80211_hw *hw,
  1291. struct ieee80211_vif *vif,
  1292. struct ieee80211_bss_conf *bss_conf,
  1293. u64 changes);
  1294. int rt2x00mac_conf_tx(struct ieee80211_hw *hw,
  1295. struct ieee80211_vif *vif,
  1296. unsigned int link_id, u16 queue,
  1297. const struct ieee80211_tx_queue_params *params);
  1298. void rt2x00mac_rfkill_poll(struct ieee80211_hw *hw);
  1299. void rt2x00mac_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  1300. u32 queues, bool drop);
  1301. int rt2x00mac_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant);
  1302. int rt2x00mac_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant);
  1303. void rt2x00mac_get_ringparam(struct ieee80211_hw *hw,
  1304. u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max);
  1305. bool rt2x00mac_tx_frames_pending(struct ieee80211_hw *hw);
  1306. /*
  1307. * Driver allocation handlers.
  1308. */
  1309. int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev);
  1310. void rt2x00lib_remove_dev(struct rt2x00_dev *rt2x00dev);
  1311. int rt2x00lib_suspend(struct rt2x00_dev *rt2x00dev);
  1312. int rt2x00lib_resume(struct rt2x00_dev *rt2x00dev);
  1313. #endif /* RT2X00_H */