common.h 70 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2011 Intel Corporation. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  17. *
  18. * The full GNU General Public License is included in this distribution in the
  19. * file called LICENSE.
  20. *
  21. * Contact Information:
  22. * Intel Linux Wireless <ilw@linux.intel.com>
  23. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  24. *
  25. *****************************************************************************/
  26. #ifndef __il_core_h__
  27. #define __il_core_h__
  28. #include <linux/interrupt.h>
  29. #include <linux/pci.h> /* for struct pci_device_id */
  30. #include <linux/kernel.h>
  31. #include <linux/leds.h>
  32. #include <linux/wait.h>
  33. #include <net/ieee80211_radiotap.h>
  34. #include "iwl-eeprom.h"
  35. #include "csr.h"
  36. #include "iwl-prph.h"
  37. #include "iwl-debug.h"
  38. #include "iwl-led.h"
  39. #include "iwl-power.h"
  40. #include "iwl-legacy-rs.h"
  41. struct il_host_cmd;
  42. struct il_cmd;
  43. struct il_tx_queue;
  44. #define RX_QUEUE_SIZE 256
  45. #define RX_QUEUE_MASK 255
  46. #define RX_QUEUE_SIZE_LOG 8
  47. /*
  48. * RX related structures and functions
  49. */
  50. #define RX_FREE_BUFFERS 64
  51. #define RX_LOW_WATERMARK 8
  52. #define U32_PAD(n) ((4-(n))&0x3)
  53. /* CT-KILL constants */
  54. #define CT_KILL_THRESHOLD_LEGACY 110 /* in Celsius */
  55. /* Default noise level to report when noise measurement is not available.
  56. * This may be because we're:
  57. * 1) Not associated (4965, no beacon stats being sent to driver)
  58. * 2) Scanning (noise measurement does not apply to associated channel)
  59. * 3) Receiving CCK (3945 delivers noise info only for OFDM frames)
  60. * Use default noise value of -127 ... this is below the range of measurable
  61. * Rx dBm for either 3945 or 4965, so it can indicate "unmeasurable" to user.
  62. * Also, -127 works better than 0 when averaging frames with/without
  63. * noise info (e.g. averaging might be done in app); measured dBm values are
  64. * always negative ... using a negative value as the default keeps all
  65. * averages within an s8's (used in some apps) range of negative values. */
  66. #define IL_NOISE_MEAS_NOT_AVAILABLE (-127)
  67. /*
  68. * RTS threshold here is total size [2347] minus 4 FCS bytes
  69. * Per spec:
  70. * a value of 0 means RTS on all data/management packets
  71. * a value > max MSDU size means no RTS
  72. * else RTS for data/management frames where MPDU is larger
  73. * than RTS value.
  74. */
  75. #define DEFAULT_RTS_THRESHOLD 2347U
  76. #define MIN_RTS_THRESHOLD 0U
  77. #define MAX_RTS_THRESHOLD 2347U
  78. #define MAX_MSDU_SIZE 2304U
  79. #define MAX_MPDU_SIZE 2346U
  80. #define DEFAULT_BEACON_INTERVAL 100U
  81. #define DEFAULT_SHORT_RETRY_LIMIT 7U
  82. #define DEFAULT_LONG_RETRY_LIMIT 4U
  83. struct il_rx_buf {
  84. dma_addr_t page_dma;
  85. struct page *page;
  86. struct list_head list;
  87. };
  88. #define rxb_addr(r) page_address(r->page)
  89. /* defined below */
  90. struct il_device_cmd;
  91. struct il_cmd_meta {
  92. /* only for SYNC commands, iff the reply skb is wanted */
  93. struct il_host_cmd *source;
  94. /*
  95. * only for ASYNC commands
  96. * (which is somewhat stupid -- look at common.c for instance
  97. * which duplicates a bunch of code because the callback isn't
  98. * invoked for SYNC commands, if it were and its result passed
  99. * through it would be simpler...)
  100. */
  101. void (*callback)(struct il_priv *il,
  102. struct il_device_cmd *cmd,
  103. struct il_rx_pkt *pkt);
  104. /* The CMD_SIZE_HUGE flag bit indicates that the command
  105. * structure is stored at the end of the shared queue memory. */
  106. u32 flags;
  107. DEFINE_DMA_UNMAP_ADDR(mapping);
  108. DEFINE_DMA_UNMAP_LEN(len);
  109. };
  110. /*
  111. * Generic queue structure
  112. *
  113. * Contains common data for Rx and Tx queues
  114. */
  115. struct il_queue {
  116. int n_bd; /* number of BDs in this queue */
  117. int write_ptr; /* 1-st empty entry (idx) host_w*/
  118. int read_ptr; /* last used entry (idx) host_r*/
  119. /* use for monitoring and recovering the stuck queue */
  120. dma_addr_t dma_addr; /* physical addr for BD's */
  121. int n_win; /* safe queue win */
  122. u32 id;
  123. int low_mark; /* low watermark, resume queue if free
  124. * space more than this */
  125. int high_mark; /* high watermark, stop queue if free
  126. * space less than this */
  127. };
  128. /* One for each TFD */
  129. struct il_tx_info {
  130. struct sk_buff *skb;
  131. struct il_rxon_context *ctx;
  132. };
  133. /**
  134. * struct il_tx_queue - Tx Queue for DMA
  135. * @q: generic Rx/Tx queue descriptor
  136. * @bd: base of circular buffer of TFDs
  137. * @cmd: array of command/TX buffer pointers
  138. * @meta: array of meta data for each command/tx buffer
  139. * @dma_addr_cmd: physical address of cmd/tx buffer array
  140. * @txb: array of per-TFD driver data
  141. * @time_stamp: time (in jiffies) of last read_ptr change
  142. * @need_update: indicates need to update read/write idx
  143. * @sched_retry: indicates queue is high-throughput aggregation (HT AGG) enabled
  144. *
  145. * A Tx queue consists of circular buffer of BDs (a.k.a. TFDs, transmit frame
  146. * descriptors) and required locking structures.
  147. */
  148. #define TFD_TX_CMD_SLOTS 256
  149. #define TFD_CMD_SLOTS 32
  150. struct il_tx_queue {
  151. struct il_queue q;
  152. void *tfds;
  153. struct il_device_cmd **cmd;
  154. struct il_cmd_meta *meta;
  155. struct il_tx_info *txb;
  156. unsigned long time_stamp;
  157. u8 need_update;
  158. u8 sched_retry;
  159. u8 active;
  160. u8 swq_id;
  161. };
  162. #define IL_NUM_SCAN_RATES (2)
  163. struct il4965_channel_tgd_info {
  164. u8 type;
  165. s8 max_power;
  166. };
  167. struct il4965_channel_tgh_info {
  168. s64 last_radar_time;
  169. };
  170. #define IL4965_MAX_RATE (33)
  171. struct il3945_clip_group {
  172. /* maximum power level to prevent clipping for each rate, derived by
  173. * us from this band's saturation power in EEPROM */
  174. const s8 clip_powers[IL_MAX_RATES];
  175. };
  176. /* current Tx power values to use, one for each rate for each channel.
  177. * requested power is limited by:
  178. * -- regulatory EEPROM limits for this channel
  179. * -- hardware capabilities (clip-powers)
  180. * -- spectrum management
  181. * -- user preference (e.g. iwconfig)
  182. * when requested power is set, base power idx must also be set. */
  183. struct il3945_channel_power_info {
  184. struct il3945_tx_power tpc; /* actual radio and DSP gain settings */
  185. s8 power_table_idx; /* actual (compenst'd) idx into gain table */
  186. s8 base_power_idx; /* gain idx for power at factory temp. */
  187. s8 requested_power; /* power (dBm) requested for this chnl/rate */
  188. };
  189. /* current scan Tx power values to use, one for each scan rate for each
  190. * channel. */
  191. struct il3945_scan_power_info {
  192. struct il3945_tx_power tpc; /* actual radio and DSP gain settings */
  193. s8 power_table_idx; /* actual (compenst'd) idx into gain table */
  194. s8 requested_power; /* scan pwr (dBm) requested for chnl/rate */
  195. };
  196. /*
  197. * One for each channel, holds all channel setup data
  198. * Some of the fields (e.g. eeprom and flags/max_power_avg) are redundant
  199. * with one another!
  200. */
  201. struct il_channel_info {
  202. struct il4965_channel_tgd_info tgd;
  203. struct il4965_channel_tgh_info tgh;
  204. struct il_eeprom_channel eeprom; /* EEPROM regulatory limit */
  205. struct il_eeprom_channel ht40_eeprom; /* EEPROM regulatory limit for
  206. * HT40 channel */
  207. u8 channel; /* channel number */
  208. u8 flags; /* flags copied from EEPROM */
  209. s8 max_power_avg; /* (dBm) regul. eeprom, normal Tx, any rate */
  210. s8 curr_txpow; /* (dBm) regulatory/spectrum/user (not h/w) limit */
  211. s8 min_power; /* always 0 */
  212. s8 scan_power; /* (dBm) regul. eeprom, direct scans, any rate */
  213. u8 group_idx; /* 0-4, maps channel to group1/2/3/4/5 */
  214. u8 band_idx; /* 0-4, maps channel to band1/2/3/4/5 */
  215. enum ieee80211_band band;
  216. /* HT40 channel info */
  217. s8 ht40_max_power_avg; /* (dBm) regul. eeprom, normal Tx, any rate */
  218. u8 ht40_flags; /* flags copied from EEPROM */
  219. u8 ht40_extension_channel; /* HT_IE_EXT_CHANNEL_* */
  220. /* Radio/DSP gain settings for each "normal" data Tx rate.
  221. * These include, in addition to RF and DSP gain, a few fields for
  222. * remembering/modifying gain settings (idxes). */
  223. struct il3945_channel_power_info power_info[IL4965_MAX_RATE];
  224. /* Radio/DSP gain settings for each scan rate, for directed scans. */
  225. struct il3945_scan_power_info scan_pwr_info[IL_NUM_SCAN_RATES];
  226. };
  227. #define IL_TX_FIFO_BK 0 /* shared */
  228. #define IL_TX_FIFO_BE 1
  229. #define IL_TX_FIFO_VI 2 /* shared */
  230. #define IL_TX_FIFO_VO 3
  231. #define IL_TX_FIFO_UNUSED -1
  232. /* Minimum number of queues. MAX_NUM is defined in hw specific files.
  233. * Set the minimum to accommodate the 4 standard TX queues, 1 command
  234. * queue, 2 (unused) HCCA queues, and 4 HT queues (one for each AC) */
  235. #define IL_MIN_NUM_QUEUES 10
  236. #define IL_DEFAULT_CMD_QUEUE_NUM 4
  237. #define IEEE80211_DATA_LEN 2304
  238. #define IEEE80211_4ADDR_LEN 30
  239. #define IEEE80211_HLEN (IEEE80211_4ADDR_LEN)
  240. #define IEEE80211_FRAME_LEN (IEEE80211_DATA_LEN + IEEE80211_HLEN)
  241. struct il_frame {
  242. union {
  243. struct ieee80211_hdr frame;
  244. struct il_tx_beacon_cmd beacon;
  245. u8 raw[IEEE80211_FRAME_LEN];
  246. u8 cmd[360];
  247. } u;
  248. struct list_head list;
  249. };
  250. #define SEQ_TO_SN(seq) (((seq) & IEEE80211_SCTL_SEQ) >> 4)
  251. #define SN_TO_SEQ(ssn) (((ssn) << 4) & IEEE80211_SCTL_SEQ)
  252. #define MAX_SN ((IEEE80211_SCTL_SEQ) >> 4)
  253. enum {
  254. CMD_SYNC = 0,
  255. CMD_SIZE_NORMAL = 0,
  256. CMD_NO_SKB = 0,
  257. CMD_SIZE_HUGE = (1 << 0),
  258. CMD_ASYNC = (1 << 1),
  259. CMD_WANT_SKB = (1 << 2),
  260. CMD_MAPPED = (1 << 3),
  261. };
  262. #define DEF_CMD_PAYLOAD_SIZE 320
  263. /**
  264. * struct il_device_cmd
  265. *
  266. * For allocation of the command and tx queues, this establishes the overall
  267. * size of the largest command we send to uCode, except for a scan command
  268. * (which is relatively huge; space is allocated separately).
  269. */
  270. struct il_device_cmd {
  271. struct il_cmd_header hdr; /* uCode API */
  272. union {
  273. u32 flags;
  274. u8 val8;
  275. u16 val16;
  276. u32 val32;
  277. struct il_tx_cmd tx;
  278. u8 payload[DEF_CMD_PAYLOAD_SIZE];
  279. } __packed cmd;
  280. } __packed;
  281. #define TFD_MAX_PAYLOAD_SIZE (sizeof(struct il_device_cmd))
  282. struct il_host_cmd {
  283. const void *data;
  284. unsigned long reply_page;
  285. void (*callback)(struct il_priv *il,
  286. struct il_device_cmd *cmd,
  287. struct il_rx_pkt *pkt);
  288. u32 flags;
  289. u16 len;
  290. u8 id;
  291. };
  292. #define SUP_RATE_11A_MAX_NUM_CHANNELS 8
  293. #define SUP_RATE_11B_MAX_NUM_CHANNELS 4
  294. #define SUP_RATE_11G_MAX_NUM_CHANNELS 12
  295. /**
  296. * struct il_rx_queue - Rx queue
  297. * @bd: driver's pointer to buffer of receive buffer descriptors (rbd)
  298. * @bd_dma: bus address of buffer of receive buffer descriptors (rbd)
  299. * @read: Shared idx to newest available Rx buffer
  300. * @write: Shared idx to oldest written Rx packet
  301. * @free_count: Number of pre-allocated buffers in rx_free
  302. * @rx_free: list of free SKBs for use
  303. * @rx_used: List of Rx buffers with no SKB
  304. * @need_update: flag to indicate we need to update read/write idx
  305. * @rb_stts: driver's pointer to receive buffer status
  306. * @rb_stts_dma: bus address of receive buffer status
  307. *
  308. * NOTE: rx_free and rx_used are used as a FIFO for il_rx_bufs
  309. */
  310. struct il_rx_queue {
  311. __le32 *bd;
  312. dma_addr_t bd_dma;
  313. struct il_rx_buf pool[RX_QUEUE_SIZE + RX_FREE_BUFFERS];
  314. struct il_rx_buf *queue[RX_QUEUE_SIZE];
  315. u32 read;
  316. u32 write;
  317. u32 free_count;
  318. u32 write_actual;
  319. struct list_head rx_free;
  320. struct list_head rx_used;
  321. int need_update;
  322. struct il_rb_status *rb_stts;
  323. dma_addr_t rb_stts_dma;
  324. spinlock_t lock;
  325. };
  326. #define IL_SUPPORTED_RATES_IE_LEN 8
  327. #define MAX_TID_COUNT 9
  328. #define IL_INVALID_RATE 0xFF
  329. #define IL_INVALID_VALUE -1
  330. /**
  331. * struct il_ht_agg -- aggregation status while waiting for block-ack
  332. * @txq_id: Tx queue used for Tx attempt
  333. * @frame_count: # frames attempted by Tx command
  334. * @wait_for_ba: Expect block-ack before next Tx reply
  335. * @start_idx: Index of 1st Transmit Frame Descriptor (TFD) in Tx win
  336. * @bitmap0: Low order bitmap, one bit for each frame pending ACK in Tx win
  337. * @bitmap1: High order, one bit for each frame pending ACK in Tx win
  338. * @rate_n_flags: Rate at which Tx was attempted
  339. *
  340. * If C_TX indicates that aggregation was attempted, driver must wait
  341. * for block ack (N_COMPRESSED_BA). This struct stores tx reply info
  342. * until block ack arrives.
  343. */
  344. struct il_ht_agg {
  345. u16 txq_id;
  346. u16 frame_count;
  347. u16 wait_for_ba;
  348. u16 start_idx;
  349. u64 bitmap;
  350. u32 rate_n_flags;
  351. #define IL_AGG_OFF 0
  352. #define IL_AGG_ON 1
  353. #define IL_EMPTYING_HW_QUEUE_ADDBA 2
  354. #define IL_EMPTYING_HW_QUEUE_DELBA 3
  355. u8 state;
  356. };
  357. struct il_tid_data {
  358. u16 seq_number; /* 4965 only */
  359. u16 tfds_in_queue;
  360. struct il_ht_agg agg;
  361. };
  362. struct il_hw_key {
  363. u32 cipher;
  364. int keylen;
  365. u8 keyidx;
  366. u8 key[32];
  367. };
  368. union il_ht_rate_supp {
  369. u16 rates;
  370. struct {
  371. u8 siso_rate;
  372. u8 mimo_rate;
  373. };
  374. };
  375. #define CFG_HT_RX_AMPDU_FACTOR_8K (0x0)
  376. #define CFG_HT_RX_AMPDU_FACTOR_16K (0x1)
  377. #define CFG_HT_RX_AMPDU_FACTOR_32K (0x2)
  378. #define CFG_HT_RX_AMPDU_FACTOR_64K (0x3)
  379. #define CFG_HT_RX_AMPDU_FACTOR_DEF CFG_HT_RX_AMPDU_FACTOR_64K
  380. #define CFG_HT_RX_AMPDU_FACTOR_MAX CFG_HT_RX_AMPDU_FACTOR_64K
  381. #define CFG_HT_RX_AMPDU_FACTOR_MIN CFG_HT_RX_AMPDU_FACTOR_8K
  382. /*
  383. * Maximal MPDU density for TX aggregation
  384. * 4 - 2us density
  385. * 5 - 4us density
  386. * 6 - 8us density
  387. * 7 - 16us density
  388. */
  389. #define CFG_HT_MPDU_DENSITY_2USEC (0x4)
  390. #define CFG_HT_MPDU_DENSITY_4USEC (0x5)
  391. #define CFG_HT_MPDU_DENSITY_8USEC (0x6)
  392. #define CFG_HT_MPDU_DENSITY_16USEC (0x7)
  393. #define CFG_HT_MPDU_DENSITY_DEF CFG_HT_MPDU_DENSITY_4USEC
  394. #define CFG_HT_MPDU_DENSITY_MAX CFG_HT_MPDU_DENSITY_16USEC
  395. #define CFG_HT_MPDU_DENSITY_MIN (0x1)
  396. struct il_ht_config {
  397. bool single_chain_sufficient;
  398. enum ieee80211_smps_mode smps; /* current smps mode */
  399. };
  400. /* QoS structures */
  401. struct il_qos_info {
  402. int qos_active;
  403. struct il_qosparam_cmd def_qos_parm;
  404. };
  405. /*
  406. * Structure should be accessed with sta_lock held. When station addition
  407. * is in progress (IL_STA_UCODE_INPROGRESS) it is possible to access only
  408. * the commands (il_addsta_cmd and il_link_quality_cmd) without
  409. * sta_lock held.
  410. */
  411. struct il_station_entry {
  412. struct il_addsta_cmd sta;
  413. struct il_tid_data tid[MAX_TID_COUNT];
  414. u8 used, ctxid;
  415. struct il_hw_key keyinfo;
  416. struct il_link_quality_cmd *lq;
  417. };
  418. struct il_station_priv_common {
  419. struct il_rxon_context *ctx;
  420. u8 sta_id;
  421. };
  422. /*
  423. * il_station_priv: Driver's ilate station information
  424. *
  425. * When mac80211 creates a station it reserves some space (hw->sta_data_size)
  426. * in the structure for use by driver. This structure is places in that
  427. * space.
  428. *
  429. * The common struct MUST be first because it is shared between
  430. * 3945 and 4965!
  431. */
  432. struct il_station_priv {
  433. struct il_station_priv_common common;
  434. struct il_lq_sta lq_sta;
  435. atomic_t pending_frames;
  436. bool client;
  437. bool asleep;
  438. };
  439. /**
  440. * struct il_vif_priv - driver's ilate per-interface information
  441. *
  442. * When mac80211 allocates a virtual interface, it can allocate
  443. * space for us to put data into.
  444. */
  445. struct il_vif_priv {
  446. struct il_rxon_context *ctx;
  447. u8 ibss_bssid_sta_id;
  448. };
  449. /* one for each uCode image (inst/data, boot/init/runtime) */
  450. struct fw_desc {
  451. void *v_addr; /* access by driver */
  452. dma_addr_t p_addr; /* access by card's busmaster DMA */
  453. u32 len; /* bytes */
  454. };
  455. /* uCode file layout */
  456. struct il_ucode_header {
  457. __le32 ver; /* major/minor/API/serial */
  458. struct {
  459. __le32 inst_size; /* bytes of runtime code */
  460. __le32 data_size; /* bytes of runtime data */
  461. __le32 init_size; /* bytes of init code */
  462. __le32 init_data_size; /* bytes of init data */
  463. __le32 boot_size; /* bytes of bootstrap code */
  464. u8 data[0]; /* in same order as sizes */
  465. } v1;
  466. };
  467. struct il4965_ibss_seq {
  468. u8 mac[ETH_ALEN];
  469. u16 seq_num;
  470. u16 frag_num;
  471. unsigned long packet_time;
  472. struct list_head list;
  473. };
  474. struct il_sensitivity_ranges {
  475. u16 min_nrg_cck;
  476. u16 max_nrg_cck;
  477. u16 nrg_th_cck;
  478. u16 nrg_th_ofdm;
  479. u16 auto_corr_min_ofdm;
  480. u16 auto_corr_min_ofdm_mrc;
  481. u16 auto_corr_min_ofdm_x1;
  482. u16 auto_corr_min_ofdm_mrc_x1;
  483. u16 auto_corr_max_ofdm;
  484. u16 auto_corr_max_ofdm_mrc;
  485. u16 auto_corr_max_ofdm_x1;
  486. u16 auto_corr_max_ofdm_mrc_x1;
  487. u16 auto_corr_max_cck;
  488. u16 auto_corr_max_cck_mrc;
  489. u16 auto_corr_min_cck;
  490. u16 auto_corr_min_cck_mrc;
  491. u16 barker_corr_th_min;
  492. u16 barker_corr_th_min_mrc;
  493. u16 nrg_th_cca;
  494. };
  495. #define KELVIN_TO_CELSIUS(x) ((x)-273)
  496. #define CELSIUS_TO_KELVIN(x) ((x)+273)
  497. /**
  498. * struct il_hw_params
  499. * @max_txq_num: Max # Tx queues supported
  500. * @dma_chnl_num: Number of Tx DMA/FIFO channels
  501. * @scd_bc_tbls_size: size of scheduler byte count tables
  502. * @tfd_size: TFD size
  503. * @tx/rx_chains_num: Number of TX/RX chains
  504. * @valid_tx/rx_ant: usable antennas
  505. * @max_rxq_size: Max # Rx frames in Rx queue (must be power-of-2)
  506. * @max_rxq_log: Log-base-2 of max_rxq_size
  507. * @rx_page_order: Rx buffer page order
  508. * @rx_wrt_ptr_reg: FH{39}_RSCSR_CHNL0_WPTR
  509. * @max_stations:
  510. * @ht40_channel: is 40MHz width possible in band 2.4
  511. * BIT(IEEE80211_BAND_5GHZ) BIT(IEEE80211_BAND_5GHZ)
  512. * @sw_crypto: 0 for hw, 1 for sw
  513. * @max_xxx_size: for ucode uses
  514. * @ct_kill_threshold: temperature threshold
  515. * @beacon_time_tsf_bits: number of valid tsf bits for beacon time
  516. * @struct il_sensitivity_ranges: range of sensitivity values
  517. */
  518. struct il_hw_params {
  519. u8 max_txq_num;
  520. u8 dma_chnl_num;
  521. u16 scd_bc_tbls_size;
  522. u32 tfd_size;
  523. u8 tx_chains_num;
  524. u8 rx_chains_num;
  525. u8 valid_tx_ant;
  526. u8 valid_rx_ant;
  527. u16 max_rxq_size;
  528. u16 max_rxq_log;
  529. u32 rx_page_order;
  530. u32 rx_wrt_ptr_reg;
  531. u8 max_stations;
  532. u8 ht40_channel;
  533. u8 max_beacon_itrvl; /* in 1024 ms */
  534. u32 max_inst_size;
  535. u32 max_data_size;
  536. u32 max_bsm_size;
  537. u32 ct_kill_threshold; /* value in hw-dependent units */
  538. u16 beacon_time_tsf_bits;
  539. const struct il_sensitivity_ranges *sens;
  540. };
  541. /******************************************************************************
  542. *
  543. * Functions implemented in core module which are forward declared here
  544. * for use by iwl-[4-5].c
  545. *
  546. * NOTE: The implementation of these functions are not hardware specific
  547. * which is why they are in the core module files.
  548. *
  549. * Naming convention --
  550. * il_ <-- Is part of iwlwifi
  551. * iwlXXXX_ <-- Hardware specific (implemented in iwl-XXXX.c for XXXX)
  552. * il4965_bg_ <-- Called from work queue context
  553. * il4965_mac_ <-- mac80211 callback
  554. *
  555. ****************************************************************************/
  556. extern void il4965_update_chain_flags(struct il_priv *il);
  557. extern const u8 il_bcast_addr[ETH_ALEN];
  558. extern int il_queue_space(const struct il_queue *q);
  559. static inline int il_queue_used(const struct il_queue *q, int i)
  560. {
  561. return q->write_ptr >= q->read_ptr ?
  562. (i >= q->read_ptr && i < q->write_ptr) :
  563. !(i < q->read_ptr && i >= q->write_ptr);
  564. }
  565. static inline u8 il_get_cmd_idx(struct il_queue *q, u32 idx,
  566. int is_huge)
  567. {
  568. /*
  569. * This is for init calibration result and scan command which
  570. * required buffer > TFD_MAX_PAYLOAD_SIZE,
  571. * the big buffer at end of command array
  572. */
  573. if (is_huge)
  574. return q->n_win; /* must be power of 2 */
  575. /* Otherwise, use normal size buffers */
  576. return idx & (q->n_win - 1);
  577. }
  578. struct il_dma_ptr {
  579. dma_addr_t dma;
  580. void *addr;
  581. size_t size;
  582. };
  583. #define IL_OPERATION_MODE_AUTO 0
  584. #define IL_OPERATION_MODE_HT_ONLY 1
  585. #define IL_OPERATION_MODE_MIXED 2
  586. #define IL_OPERATION_MODE_20MHZ 3
  587. #define IL_TX_CRC_SIZE 4
  588. #define IL_TX_DELIMITER_SIZE 4
  589. #define TX_POWER_IL_ILLEGAL_VOLTAGE -10000
  590. /* Sensitivity and chain noise calibration */
  591. #define INITIALIZATION_VALUE 0xFFFF
  592. #define IL4965_CAL_NUM_BEACONS 20
  593. #define IL_CAL_NUM_BEACONS 16
  594. #define MAXIMUM_ALLOWED_PATHLOSS 15
  595. #define CHAIN_NOISE_MAX_DELTA_GAIN_CODE 3
  596. #define MAX_FA_OFDM 50
  597. #define MIN_FA_OFDM 5
  598. #define MAX_FA_CCK 50
  599. #define MIN_FA_CCK 5
  600. #define AUTO_CORR_STEP_OFDM 1
  601. #define AUTO_CORR_STEP_CCK 3
  602. #define AUTO_CORR_MAX_TH_CCK 160
  603. #define NRG_DIFF 2
  604. #define NRG_STEP_CCK 2
  605. #define NRG_MARGIN 8
  606. #define MAX_NUMBER_CCK_NO_FA 100
  607. #define AUTO_CORR_CCK_MIN_VAL_DEF (125)
  608. #define CHAIN_A 0
  609. #define CHAIN_B 1
  610. #define CHAIN_C 2
  611. #define CHAIN_NOISE_DELTA_GAIN_INIT_VAL 4
  612. #define ALL_BAND_FILTER 0xFF00
  613. #define IN_BAND_FILTER 0xFF
  614. #define MIN_AVERAGE_NOISE_MAX_VALUE 0xFFFFFFFF
  615. #define NRG_NUM_PREV_STAT_L 20
  616. #define NUM_RX_CHAINS 3
  617. enum il4965_false_alarm_state {
  618. IL_FA_TOO_MANY = 0,
  619. IL_FA_TOO_FEW = 1,
  620. IL_FA_GOOD_RANGE = 2,
  621. };
  622. enum il4965_chain_noise_state {
  623. IL_CHAIN_NOISE_ALIVE = 0, /* must be 0 */
  624. IL_CHAIN_NOISE_ACCUMULATE,
  625. IL_CHAIN_NOISE_CALIBRATED,
  626. IL_CHAIN_NOISE_DONE,
  627. };
  628. enum il4965_calib_enabled_state {
  629. IL_CALIB_DISABLED = 0, /* must be 0 */
  630. IL_CALIB_ENABLED = 1,
  631. };
  632. /*
  633. * enum il_calib
  634. * defines the order in which results of initial calibrations
  635. * should be sent to the runtime uCode
  636. */
  637. enum il_calib {
  638. IL_CALIB_MAX,
  639. };
  640. /* Opaque calibration results */
  641. struct il_calib_result {
  642. void *buf;
  643. size_t buf_len;
  644. };
  645. enum ucode_type {
  646. UCODE_NONE = 0,
  647. UCODE_INIT,
  648. UCODE_RT
  649. };
  650. /* Sensitivity calib data */
  651. struct il_sensitivity_data {
  652. u32 auto_corr_ofdm;
  653. u32 auto_corr_ofdm_mrc;
  654. u32 auto_corr_ofdm_x1;
  655. u32 auto_corr_ofdm_mrc_x1;
  656. u32 auto_corr_cck;
  657. u32 auto_corr_cck_mrc;
  658. u32 last_bad_plcp_cnt_ofdm;
  659. u32 last_fa_cnt_ofdm;
  660. u32 last_bad_plcp_cnt_cck;
  661. u32 last_fa_cnt_cck;
  662. u32 nrg_curr_state;
  663. u32 nrg_prev_state;
  664. u32 nrg_value[10];
  665. u8 nrg_silence_rssi[NRG_NUM_PREV_STAT_L];
  666. u32 nrg_silence_ref;
  667. u32 nrg_energy_idx;
  668. u32 nrg_silence_idx;
  669. u32 nrg_th_cck;
  670. s32 nrg_auto_corr_silence_diff;
  671. u32 num_in_cck_no_fa;
  672. u32 nrg_th_ofdm;
  673. u16 barker_corr_th_min;
  674. u16 barker_corr_th_min_mrc;
  675. u16 nrg_th_cca;
  676. };
  677. /* Chain noise (differential Rx gain) calib data */
  678. struct il_chain_noise_data {
  679. u32 active_chains;
  680. u32 chain_noise_a;
  681. u32 chain_noise_b;
  682. u32 chain_noise_c;
  683. u32 chain_signal_a;
  684. u32 chain_signal_b;
  685. u32 chain_signal_c;
  686. u16 beacon_count;
  687. u8 disconn_array[NUM_RX_CHAINS];
  688. u8 delta_gain_code[NUM_RX_CHAINS];
  689. u8 radio_write;
  690. u8 state;
  691. };
  692. #define EEPROM_SEM_TIMEOUT 10 /* milliseconds */
  693. #define EEPROM_SEM_RETRY_LIMIT 1000 /* number of attempts (not time) */
  694. #define IL_TRAFFIC_ENTRIES (256)
  695. #define IL_TRAFFIC_ENTRY_SIZE (64)
  696. enum {
  697. MEASUREMENT_READY = (1 << 0),
  698. MEASUREMENT_ACTIVE = (1 << 1),
  699. };
  700. /* interrupt stats */
  701. struct isr_stats {
  702. u32 hw;
  703. u32 sw;
  704. u32 err_code;
  705. u32 sch;
  706. u32 alive;
  707. u32 rfkill;
  708. u32 ctkill;
  709. u32 wakeup;
  710. u32 rx;
  711. u32 handlers[IL_CN_MAX];
  712. u32 tx;
  713. u32 unhandled;
  714. };
  715. /* management stats */
  716. enum il_mgmt_stats {
  717. MANAGEMENT_ASSOC_REQ = 0,
  718. MANAGEMENT_ASSOC_RESP,
  719. MANAGEMENT_REASSOC_REQ,
  720. MANAGEMENT_REASSOC_RESP,
  721. MANAGEMENT_PROBE_REQ,
  722. MANAGEMENT_PROBE_RESP,
  723. MANAGEMENT_BEACON,
  724. MANAGEMENT_ATIM,
  725. MANAGEMENT_DISASSOC,
  726. MANAGEMENT_AUTH,
  727. MANAGEMENT_DEAUTH,
  728. MANAGEMENT_ACTION,
  729. MANAGEMENT_MAX,
  730. };
  731. /* control stats */
  732. enum il_ctrl_stats {
  733. CONTROL_BACK_REQ = 0,
  734. CONTROL_BACK,
  735. CONTROL_PSPOLL,
  736. CONTROL_RTS,
  737. CONTROL_CTS,
  738. CONTROL_ACK,
  739. CONTROL_CFEND,
  740. CONTROL_CFENDACK,
  741. CONTROL_MAX,
  742. };
  743. struct traffic_stats {
  744. #ifdef CONFIG_IWLEGACY_DEBUGFS
  745. u32 mgmt[MANAGEMENT_MAX];
  746. u32 ctrl[CONTROL_MAX];
  747. u32 data_cnt;
  748. u64 data_bytes;
  749. #endif
  750. };
  751. /*
  752. * host interrupt timeout value
  753. * used with setting interrupt coalescing timer
  754. * the CSR_INT_COALESCING is an 8 bit register in 32-usec unit
  755. *
  756. * default interrupt coalescing timer is 64 x 32 = 2048 usecs
  757. * default interrupt coalescing calibration timer is 16 x 32 = 512 usecs
  758. */
  759. #define IL_HOST_INT_TIMEOUT_MAX (0xFF)
  760. #define IL_HOST_INT_TIMEOUT_DEF (0x40)
  761. #define IL_HOST_INT_TIMEOUT_MIN (0x0)
  762. #define IL_HOST_INT_CALIB_TIMEOUT_MAX (0xFF)
  763. #define IL_HOST_INT_CALIB_TIMEOUT_DEF (0x10)
  764. #define IL_HOST_INT_CALIB_TIMEOUT_MIN (0x0)
  765. #define IL_DELAY_NEXT_FORCE_FW_RELOAD (HZ*5)
  766. /* TX queue watchdog timeouts in mSecs */
  767. #define IL_DEF_WD_TIMEOUT (2000)
  768. #define IL_LONG_WD_TIMEOUT (10000)
  769. #define IL_MAX_WD_TIMEOUT (120000)
  770. struct il_force_reset {
  771. int reset_request_count;
  772. int reset_success_count;
  773. int reset_reject_count;
  774. unsigned long reset_duration;
  775. unsigned long last_force_reset_jiffies;
  776. };
  777. /* extend beacon time format bit shifting */
  778. /*
  779. * for _3945 devices
  780. * bits 31:24 - extended
  781. * bits 23:0 - interval
  782. */
  783. #define IL3945_EXT_BEACON_TIME_POS 24
  784. /*
  785. * for _4965 devices
  786. * bits 31:22 - extended
  787. * bits 21:0 - interval
  788. */
  789. #define IL4965_EXT_BEACON_TIME_POS 22
  790. struct il_rxon_context {
  791. struct ieee80211_vif *vif;
  792. const u8 *ac_to_fifo;
  793. const u8 *ac_to_queue;
  794. u8 mcast_queue;
  795. /*
  796. * We could use the vif to indicate active, but we
  797. * also need it to be active during disabling when
  798. * we already removed the vif for type setting.
  799. */
  800. bool always_active, is_active;
  801. bool ht_need_multiple_chains;
  802. int ctxid;
  803. u32 interface_modes, exclusive_interface_modes;
  804. u8 unused_devtype, ap_devtype, ibss_devtype, station_devtype;
  805. /*
  806. * We declare this const so it can only be
  807. * changed via explicit cast within the
  808. * routines that actually update the physical
  809. * hardware.
  810. */
  811. const struct il_rxon_cmd active;
  812. struct il_rxon_cmd staging;
  813. struct il_rxon_time_cmd timing;
  814. struct il_qos_info qos_data;
  815. u8 bcast_sta_id, ap_sta_id;
  816. u8 rxon_cmd, rxon_assoc_cmd, rxon_timing_cmd;
  817. u8 qos_cmd;
  818. u8 wep_key_cmd;
  819. struct il_wep_key wep_keys[WEP_KEYS_MAX];
  820. u8 key_mapping_keys;
  821. __le32 station_flags;
  822. struct {
  823. bool non_gf_sta_present;
  824. u8 protection;
  825. bool enabled, is_40mhz;
  826. u8 extension_chan_offset;
  827. } ht;
  828. };
  829. struct il_priv {
  830. /* ieee device used by generic ieee processing code */
  831. struct ieee80211_hw *hw;
  832. struct ieee80211_channel *ieee_channels;
  833. struct ieee80211_rate *ieee_rates;
  834. struct il_cfg *cfg;
  835. /* temporary frame storage list */
  836. struct list_head free_frames;
  837. int frames_count;
  838. enum ieee80211_band band;
  839. int alloc_rxb_page;
  840. void (*handlers[IL_CN_MAX])(struct il_priv *il,
  841. struct il_rx_buf *rxb);
  842. struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
  843. /* spectrum measurement report caching */
  844. struct il_spectrum_notification measure_report;
  845. u8 measurement_status;
  846. /* ucode beacon time */
  847. u32 ucode_beacon_time;
  848. int missed_beacon_threshold;
  849. /* track IBSS manager (last beacon) status */
  850. u32 ibss_manager;
  851. /* force reset */
  852. struct il_force_reset force_reset;
  853. /* we allocate array of il_channel_info for NIC's valid channels.
  854. * Access via channel # using indirect idx array */
  855. struct il_channel_info *channel_info; /* channel info array */
  856. u8 channel_count; /* # of channels */
  857. /* thermal calibration */
  858. s32 temperature; /* degrees Kelvin */
  859. s32 last_temperature;
  860. /* init calibration results */
  861. struct il_calib_result calib_results[IL_CALIB_MAX];
  862. /* Scan related variables */
  863. unsigned long scan_start;
  864. unsigned long scan_start_tsf;
  865. void *scan_cmd;
  866. enum ieee80211_band scan_band;
  867. struct cfg80211_scan_request *scan_request;
  868. struct ieee80211_vif *scan_vif;
  869. u8 scan_tx_ant[IEEE80211_NUM_BANDS];
  870. u8 mgmt_tx_ant;
  871. /* spinlock */
  872. spinlock_t lock; /* protect general shared data */
  873. spinlock_t hcmd_lock; /* protect hcmd */
  874. spinlock_t reg_lock; /* protect hw register access */
  875. struct mutex mutex;
  876. /* basic pci-network driver stuff */
  877. struct pci_dev *pci_dev;
  878. /* pci hardware address support */
  879. void __iomem *hw_base;
  880. u32 hw_rev;
  881. u32 hw_wa_rev;
  882. u8 rev_id;
  883. /* command queue number */
  884. u8 cmd_queue;
  885. /* max number of station keys */
  886. u8 sta_key_max_num;
  887. /* EEPROM MAC addresses */
  888. struct mac_address addresses[1];
  889. /* uCode images, save to reload in case of failure */
  890. int fw_idx; /* firmware we're trying to load */
  891. u32 ucode_ver; /* version of ucode, copy of
  892. il_ucode.ver */
  893. struct fw_desc ucode_code; /* runtime inst */
  894. struct fw_desc ucode_data; /* runtime data original */
  895. struct fw_desc ucode_data_backup; /* runtime data save/restore */
  896. struct fw_desc ucode_init; /* initialization inst */
  897. struct fw_desc ucode_init_data; /* initialization data */
  898. struct fw_desc ucode_boot; /* bootstrap inst */
  899. enum ucode_type ucode_type;
  900. u8 ucode_write_complete; /* the image write is complete */
  901. char firmware_name[25];
  902. struct il_rxon_context ctx;
  903. __le16 switch_channel;
  904. /* 1st responses from initialize and runtime uCode images.
  905. * _4965's initialize alive response contains some calibration data. */
  906. struct il_init_alive_resp card_alive_init;
  907. struct il_alive_resp card_alive;
  908. u16 active_rate;
  909. u8 start_calib;
  910. struct il_sensitivity_data sensitivity_data;
  911. struct il_chain_noise_data chain_noise_data;
  912. __le16 sensitivity_tbl[HD_TBL_SIZE];
  913. struct il_ht_config current_ht_config;
  914. /* Rate scaling data */
  915. u8 retry_rate;
  916. wait_queue_head_t wait_command_queue;
  917. int activity_timer_active;
  918. /* Rx and Tx DMA processing queues */
  919. struct il_rx_queue rxq;
  920. struct il_tx_queue *txq;
  921. unsigned long txq_ctx_active_msk;
  922. struct il_dma_ptr kw; /* keep warm address */
  923. struct il_dma_ptr scd_bc_tbls;
  924. u32 scd_base_addr; /* scheduler sram base address */
  925. unsigned long status;
  926. /* counts mgmt, ctl, and data packets */
  927. struct traffic_stats tx_stats;
  928. struct traffic_stats rx_stats;
  929. /* counts interrupts */
  930. struct isr_stats isr_stats;
  931. struct il_power_mgr power_data;
  932. /* context information */
  933. u8 bssid[ETH_ALEN]; /* used only on 3945 but filled by core */
  934. /* station table variables */
  935. /* Note: if lock and sta_lock are needed, lock must be acquired first */
  936. spinlock_t sta_lock;
  937. int num_stations;
  938. struct il_station_entry stations[IL_STATION_COUNT];
  939. unsigned long ucode_key_table;
  940. /* queue refcounts */
  941. #define IL_MAX_HW_QUEUES 32
  942. unsigned long queue_stopped[BITS_TO_LONGS(IL_MAX_HW_QUEUES)];
  943. /* for each AC */
  944. atomic_t queue_stop_count[4];
  945. /* Indication if ieee80211_ops->open has been called */
  946. u8 is_open;
  947. u8 mac80211_registered;
  948. /* eeprom -- this is in the card's little endian byte order */
  949. u8 *eeprom;
  950. struct il_eeprom_calib_info *calib_info;
  951. enum nl80211_iftype iw_mode;
  952. /* Last Rx'd beacon timestamp */
  953. u64 timestamp;
  954. union {
  955. #if defined(CONFIG_IWL3945) || defined(CONFIG_IWL3945_MODULE)
  956. struct {
  957. void *shared_virt;
  958. dma_addr_t shared_phys;
  959. struct delayed_work thermal_periodic;
  960. struct delayed_work rfkill_poll;
  961. struct il3945_notif_stats stats;
  962. #ifdef CONFIG_IWLEGACY_DEBUGFS
  963. struct il3945_notif_stats accum_stats;
  964. struct il3945_notif_stats delta_stats;
  965. struct il3945_notif_stats max_delta;
  966. #endif
  967. u32 sta_supp_rates;
  968. int last_rx_rssi; /* From Rx packet stats */
  969. /* Rx'd packet timing information */
  970. u32 last_beacon_time;
  971. u64 last_tsf;
  972. /*
  973. * each calibration channel group in the
  974. * EEPROM has a derived clip setting for
  975. * each rate.
  976. */
  977. const struct il3945_clip_group clip_groups[5];
  978. } _3945;
  979. #endif
  980. #if defined(CONFIG_IWL4965) || defined(CONFIG_IWL4965_MODULE)
  981. struct {
  982. struct il_rx_phy_res last_phy_res;
  983. bool last_phy_res_valid;
  984. struct completion firmware_loading_complete;
  985. /*
  986. * chain noise reset and gain commands are the
  987. * two extra calibration commands follows the standard
  988. * phy calibration commands
  989. */
  990. u8 phy_calib_chain_noise_reset_cmd;
  991. u8 phy_calib_chain_noise_gain_cmd;
  992. struct il_notif_stats stats;
  993. #ifdef CONFIG_IWLEGACY_DEBUGFS
  994. struct il_notif_stats accum_stats;
  995. struct il_notif_stats delta_stats;
  996. struct il_notif_stats max_delta;
  997. #endif
  998. } _4965;
  999. #endif
  1000. };
  1001. struct il_hw_params hw_params;
  1002. u32 inta_mask;
  1003. struct workqueue_struct *workqueue;
  1004. struct work_struct restart;
  1005. struct work_struct scan_completed;
  1006. struct work_struct rx_replenish;
  1007. struct work_struct abort_scan;
  1008. struct il_rxon_context *beacon_ctx;
  1009. struct sk_buff *beacon_skb;
  1010. struct work_struct tx_flush;
  1011. struct tasklet_struct irq_tasklet;
  1012. struct delayed_work init_alive_start;
  1013. struct delayed_work alive_start;
  1014. struct delayed_work scan_check;
  1015. /* TX Power */
  1016. s8 tx_power_user_lmt;
  1017. s8 tx_power_device_lmt;
  1018. s8 tx_power_next;
  1019. #ifdef CONFIG_IWLEGACY_DEBUG
  1020. /* debugging info */
  1021. u32 debug_level; /* per device debugging will override global
  1022. il_debug_level if set */
  1023. #endif /* CONFIG_IWLEGACY_DEBUG */
  1024. #ifdef CONFIG_IWLEGACY_DEBUGFS
  1025. /* debugfs */
  1026. u16 tx_traffic_idx;
  1027. u16 rx_traffic_idx;
  1028. u8 *tx_traffic;
  1029. u8 *rx_traffic;
  1030. struct dentry *debugfs_dir;
  1031. u32 dbgfs_sram_offset, dbgfs_sram_len;
  1032. bool disable_ht40;
  1033. #endif /* CONFIG_IWLEGACY_DEBUGFS */
  1034. struct work_struct txpower_work;
  1035. u32 disable_sens_cal;
  1036. u32 disable_chain_noise_cal;
  1037. u32 disable_tx_power_cal;
  1038. struct work_struct run_time_calib_work;
  1039. struct timer_list stats_periodic;
  1040. struct timer_list watchdog;
  1041. bool hw_ready;
  1042. struct led_classdev led;
  1043. unsigned long blink_on, blink_off;
  1044. bool led_registered;
  1045. }; /*il_priv */
  1046. static inline void il_txq_ctx_activate(struct il_priv *il, int txq_id)
  1047. {
  1048. set_bit(txq_id, &il->txq_ctx_active_msk);
  1049. }
  1050. static inline void il_txq_ctx_deactivate(struct il_priv *il, int txq_id)
  1051. {
  1052. clear_bit(txq_id, &il->txq_ctx_active_msk);
  1053. }
  1054. #ifdef CONFIG_IWLEGACY_DEBUG
  1055. /*
  1056. * il_get_debug_level: Return active debug level for device
  1057. *
  1058. * Using sysfs it is possible to set per device debug level. This debug
  1059. * level will be used if set, otherwise the global debug level which can be
  1060. * set via module parameter is used.
  1061. */
  1062. static inline u32 il_get_debug_level(struct il_priv *il)
  1063. {
  1064. if (il->debug_level)
  1065. return il->debug_level;
  1066. else
  1067. return il_debug_level;
  1068. }
  1069. #else
  1070. static inline u32 il_get_debug_level(struct il_priv *il)
  1071. {
  1072. return il_debug_level;
  1073. }
  1074. #endif
  1075. static inline struct ieee80211_hdr *
  1076. il_tx_queue_get_hdr(struct il_priv *il,
  1077. int txq_id, int idx)
  1078. {
  1079. if (il->txq[txq_id].txb[idx].skb)
  1080. return (struct ieee80211_hdr *)il->txq[txq_id].
  1081. txb[idx].skb->data;
  1082. return NULL;
  1083. }
  1084. static inline struct il_rxon_context *
  1085. il_rxon_ctx_from_vif(struct ieee80211_vif *vif)
  1086. {
  1087. struct il_vif_priv *vif_priv = (void *)vif->drv_priv;
  1088. return vif_priv->ctx;
  1089. }
  1090. #define for_each_context(il, _ctx) \
  1091. for (_ctx = &il->ctx; _ctx == &il->ctx; _ctx++)
  1092. static inline int il_is_associated(struct il_priv *il)
  1093. {
  1094. return (il->ctx.active.filter_flags & RXON_FILTER_ASSOC_MSK) ? 1 : 0;
  1095. }
  1096. static inline int il_is_any_associated(struct il_priv *il)
  1097. {
  1098. return il_is_associated(il);
  1099. }
  1100. static inline int il_is_associated_ctx(struct il_rxon_context *ctx)
  1101. {
  1102. return (ctx->active.filter_flags & RXON_FILTER_ASSOC_MSK) ? 1 : 0;
  1103. }
  1104. static inline int il_is_channel_valid(const struct il_channel_info *ch_info)
  1105. {
  1106. if (ch_info == NULL)
  1107. return 0;
  1108. return (ch_info->flags & EEPROM_CHANNEL_VALID) ? 1 : 0;
  1109. }
  1110. static inline int il_is_channel_radar(const struct il_channel_info *ch_info)
  1111. {
  1112. return (ch_info->flags & EEPROM_CHANNEL_RADAR) ? 1 : 0;
  1113. }
  1114. static inline u8 il_is_channel_a_band(const struct il_channel_info *ch_info)
  1115. {
  1116. return ch_info->band == IEEE80211_BAND_5GHZ;
  1117. }
  1118. static inline int
  1119. il_is_channel_passive(const struct il_channel_info *ch)
  1120. {
  1121. return (!(ch->flags & EEPROM_CHANNEL_ACTIVE)) ? 1 : 0;
  1122. }
  1123. static inline int
  1124. il_is_channel_ibss(const struct il_channel_info *ch)
  1125. {
  1126. return (ch->flags & EEPROM_CHANNEL_IBSS) ? 1 : 0;
  1127. }
  1128. static inline void
  1129. __il_free_pages(struct il_priv *il, struct page *page)
  1130. {
  1131. __free_pages(page, il->hw_params.rx_page_order);
  1132. il->alloc_rxb_page--;
  1133. }
  1134. static inline void il_free_pages(struct il_priv *il, unsigned long page)
  1135. {
  1136. free_pages(page, il->hw_params.rx_page_order);
  1137. il->alloc_rxb_page--;
  1138. }
  1139. #define IWLWIFI_VERSION "in-tree:"
  1140. #define DRV_COPYRIGHT "Copyright(c) 2003-2011 Intel Corporation"
  1141. #define DRV_AUTHOR "<ilw@linux.intel.com>"
  1142. #define IL_PCI_DEVICE(dev, subdev, cfg) \
  1143. .vendor = PCI_VENDOR_ID_INTEL, .device = (dev), \
  1144. .subvendor = PCI_ANY_ID, .subdevice = (subdev), \
  1145. .driver_data = (kernel_ulong_t)&(cfg)
  1146. #define TIME_UNIT 1024
  1147. #define IL_SKU_G 0x1
  1148. #define IL_SKU_A 0x2
  1149. #define IL_SKU_N 0x8
  1150. #define IL_CMD(x) case x: return #x
  1151. /* Size of one Rx buffer in host DRAM */
  1152. #define IL_RX_BUF_SIZE_3K (3 * 1000) /* 3945 only */
  1153. #define IL_RX_BUF_SIZE_4K (4 * 1024)
  1154. #define IL_RX_BUF_SIZE_8K (8 * 1024)
  1155. struct il_hcmd_ops {
  1156. int (*rxon_assoc)(struct il_priv *il, struct il_rxon_context *ctx);
  1157. int (*commit_rxon)(struct il_priv *il, struct il_rxon_context *ctx);
  1158. void (*set_rxon_chain)(struct il_priv *il,
  1159. struct il_rxon_context *ctx);
  1160. };
  1161. struct il_hcmd_utils_ops {
  1162. u16 (*get_hcmd_size)(u8 cmd_id, u16 len);
  1163. u16 (*build_addsta_hcmd)(const struct il_addsta_cmd *cmd,
  1164. u8 *data);
  1165. int (*request_scan)(struct il_priv *il, struct ieee80211_vif *vif);
  1166. void (*post_scan)(struct il_priv *il);
  1167. };
  1168. struct il_apm_ops {
  1169. int (*init)(struct il_priv *il);
  1170. void (*config)(struct il_priv *il);
  1171. };
  1172. struct il_debugfs_ops {
  1173. ssize_t (*rx_stats_read)(struct file *file, char __user *user_buf,
  1174. size_t count, loff_t *ppos);
  1175. ssize_t (*tx_stats_read)(struct file *file, char __user *user_buf,
  1176. size_t count, loff_t *ppos);
  1177. ssize_t (*general_stats_read)(struct file *file, char __user *user_buf,
  1178. size_t count, loff_t *ppos);
  1179. };
  1180. struct il_temp_ops {
  1181. void (*temperature)(struct il_priv *il);
  1182. };
  1183. struct il_lib_ops {
  1184. /* set hw dependent parameters */
  1185. int (*set_hw_params)(struct il_priv *il);
  1186. /* Handling TX */
  1187. void (*txq_update_byte_cnt_tbl)(struct il_priv *il,
  1188. struct il_tx_queue *txq,
  1189. u16 byte_cnt);
  1190. int (*txq_attach_buf_to_tfd)(struct il_priv *il,
  1191. struct il_tx_queue *txq,
  1192. dma_addr_t addr,
  1193. u16 len, u8 reset, u8 pad);
  1194. void (*txq_free_tfd)(struct il_priv *il,
  1195. struct il_tx_queue *txq);
  1196. int (*txq_init)(struct il_priv *il,
  1197. struct il_tx_queue *txq);
  1198. /* setup Rx handler */
  1199. void (*handler_setup)(struct il_priv *il);
  1200. /* alive notification after init uCode load */
  1201. void (*init_alive_start)(struct il_priv *il);
  1202. /* check validity of rtc data address */
  1203. int (*is_valid_rtc_data_addr)(u32 addr);
  1204. /* 1st ucode load */
  1205. int (*load_ucode)(struct il_priv *il);
  1206. void (*dump_nic_error_log)(struct il_priv *il);
  1207. int (*dump_fh)(struct il_priv *il, char **buf, bool display);
  1208. int (*set_channel_switch)(struct il_priv *il,
  1209. struct ieee80211_channel_switch *ch_switch);
  1210. /* power management */
  1211. struct il_apm_ops apm_ops;
  1212. /* power */
  1213. int (*send_tx_power) (struct il_priv *il);
  1214. void (*update_chain_flags)(struct il_priv *il);
  1215. /* eeprom operations (as defined in iwl-eeprom.h) */
  1216. struct il_eeprom_ops eeprom_ops;
  1217. /* temperature */
  1218. struct il_temp_ops temp_ops;
  1219. struct il_debugfs_ops debugfs_ops;
  1220. };
  1221. struct il_led_ops {
  1222. int (*cmd)(struct il_priv *il, struct il_led_cmd *led_cmd);
  1223. };
  1224. struct il_legacy_ops {
  1225. void (*post_associate)(struct il_priv *il);
  1226. void (*config_ap)(struct il_priv *il);
  1227. /* station management */
  1228. int (*update_bcast_stations)(struct il_priv *il);
  1229. int (*manage_ibss_station)(struct il_priv *il,
  1230. struct ieee80211_vif *vif, bool add);
  1231. };
  1232. struct il_ops {
  1233. const struct il_lib_ops *lib;
  1234. const struct il_hcmd_ops *hcmd;
  1235. const struct il_hcmd_utils_ops *utils;
  1236. const struct il_led_ops *led;
  1237. const struct il_nic_ops *nic;
  1238. const struct il_legacy_ops *legacy;
  1239. const struct ieee80211_ops *ieee80211_ops;
  1240. };
  1241. struct il_mod_params {
  1242. int sw_crypto; /* def: 0 = using hardware encryption */
  1243. int disable_hw_scan; /* def: 0 = use h/w scan */
  1244. int num_of_queues; /* def: HW dependent */
  1245. int disable_11n; /* def: 0 = 11n capabilities enabled */
  1246. int amsdu_size_8K; /* def: 1 = enable 8K amsdu size */
  1247. int antenna; /* def: 0 = both antennas (use diversity) */
  1248. int restart_fw; /* def: 1 = restart firmware */
  1249. };
  1250. /*
  1251. * @led_compensation: compensate on the led on/off time per HW according
  1252. * to the deviation to achieve the desired led frequency.
  1253. * The detail algorithm is described in iwl-led.c
  1254. * @chain_noise_num_beacons: number of beacons used to compute chain noise
  1255. * @wd_timeout: TX queues watchdog timeout
  1256. * @temperature_kelvin: temperature report by uCode in kelvin
  1257. * @ucode_tracing: support ucode continuous tracing
  1258. * @sensitivity_calib_by_driver: driver has the capability to perform
  1259. * sensitivity calibration operation
  1260. * @chain_noise_calib_by_driver: driver has the capability to perform
  1261. * chain noise calibration operation
  1262. */
  1263. struct il_base_params {
  1264. int eeprom_size;
  1265. int num_of_queues; /* def: HW dependent */
  1266. int num_of_ampdu_queues;/* def: HW dependent */
  1267. /* for il_apm_init() */
  1268. u32 pll_cfg_val;
  1269. bool set_l0s;
  1270. bool use_bsm;
  1271. u16 led_compensation;
  1272. int chain_noise_num_beacons;
  1273. unsigned int wd_timeout;
  1274. bool temperature_kelvin;
  1275. const bool ucode_tracing;
  1276. const bool sensitivity_calib_by_driver;
  1277. const bool chain_noise_calib_by_driver;
  1278. };
  1279. /**
  1280. * struct il_cfg
  1281. * @fw_name_pre: Firmware filename prefix. The api version and extension
  1282. * (.ucode) will be added to filename before loading from disk. The
  1283. * filename is constructed as fw_name_pre<api>.ucode.
  1284. * @ucode_api_max: Highest version of uCode API supported by driver.
  1285. * @ucode_api_min: Lowest version of uCode API supported by driver.
  1286. * @scan_antennas: available antenna for scan operation
  1287. * @led_mode: 0=blinking, 1=On(RF On)/Off(RF Off)
  1288. *
  1289. * We enable the driver to be backward compatible wrt API version. The
  1290. * driver specifies which APIs it supports (with @ucode_api_max being the
  1291. * highest and @ucode_api_min the lowest). Firmware will only be loaded if
  1292. * it has a supported API version. The firmware's API version will be
  1293. * stored in @il_priv, enabling the driver to make runtime changes based
  1294. * on firmware version used.
  1295. *
  1296. * For example,
  1297. * if (IL_UCODE_API(il->ucode_ver) >= 2) {
  1298. * Driver interacts with Firmware API version >= 2.
  1299. * } else {
  1300. * Driver interacts with Firmware API version 1.
  1301. * }
  1302. *
  1303. * The ideal usage of this infrastructure is to treat a new ucode API
  1304. * release as a new hardware revision. That is, through utilizing the
  1305. * il_hcmd_utils_ops etc. we accommodate different command structures
  1306. * and flows between hardware versions as well as their API
  1307. * versions.
  1308. *
  1309. */
  1310. struct il_cfg {
  1311. /* params specific to an individual device within a device family */
  1312. const char *name;
  1313. const char *fw_name_pre;
  1314. const unsigned int ucode_api_max;
  1315. const unsigned int ucode_api_min;
  1316. u8 valid_tx_ant;
  1317. u8 valid_rx_ant;
  1318. unsigned int sku;
  1319. u16 eeprom_ver;
  1320. u16 eeprom_calib_ver;
  1321. const struct il_ops *ops;
  1322. /* module based parameters which can be set from modprobe cmd */
  1323. const struct il_mod_params *mod_params;
  1324. /* params not likely to change within a device family */
  1325. struct il_base_params *base_params;
  1326. /* params likely to change within a device family */
  1327. u8 scan_rx_antennas[IEEE80211_NUM_BANDS];
  1328. enum il_led_mode led_mode;
  1329. };
  1330. /***************************
  1331. * L i b *
  1332. ***************************/
  1333. struct ieee80211_hw *il_alloc_all(struct il_cfg *cfg);
  1334. int il_mac_conf_tx(struct ieee80211_hw *hw,
  1335. struct ieee80211_vif *vif, u16 queue,
  1336. const struct ieee80211_tx_queue_params *params);
  1337. int il_mac_tx_last_beacon(struct ieee80211_hw *hw);
  1338. void il_set_rxon_hwcrypto(struct il_priv *il,
  1339. struct il_rxon_context *ctx,
  1340. int hw_decrypt);
  1341. int il_check_rxon_cmd(struct il_priv *il,
  1342. struct il_rxon_context *ctx);
  1343. int il_full_rxon_required(struct il_priv *il,
  1344. struct il_rxon_context *ctx);
  1345. int il_set_rxon_channel(struct il_priv *il,
  1346. struct ieee80211_channel *ch,
  1347. struct il_rxon_context *ctx);
  1348. void il_set_flags_for_band(struct il_priv *il,
  1349. struct il_rxon_context *ctx,
  1350. enum ieee80211_band band,
  1351. struct ieee80211_vif *vif);
  1352. u8 il_get_single_channel_number(struct il_priv *il,
  1353. enum ieee80211_band band);
  1354. void il_set_rxon_ht(struct il_priv *il,
  1355. struct il_ht_config *ht_conf);
  1356. bool il_is_ht40_tx_allowed(struct il_priv *il,
  1357. struct il_rxon_context *ctx,
  1358. struct ieee80211_sta_ht_cap *ht_cap);
  1359. void il_connection_init_rx_config(struct il_priv *il,
  1360. struct il_rxon_context *ctx);
  1361. void il_set_rate(struct il_priv *il);
  1362. int il_set_decrypted_flag(struct il_priv *il,
  1363. struct ieee80211_hdr *hdr,
  1364. u32 decrypt_res,
  1365. struct ieee80211_rx_status *stats);
  1366. void il_irq_handle_error(struct il_priv *il);
  1367. int il_mac_add_interface(struct ieee80211_hw *hw,
  1368. struct ieee80211_vif *vif);
  1369. void il_mac_remove_interface(struct ieee80211_hw *hw,
  1370. struct ieee80211_vif *vif);
  1371. int il_mac_change_interface(struct ieee80211_hw *hw,
  1372. struct ieee80211_vif *vif,
  1373. enum nl80211_iftype newtype, bool newp2p);
  1374. int il_alloc_txq_mem(struct il_priv *il);
  1375. void il_txq_mem(struct il_priv *il);
  1376. #ifdef CONFIG_IWLEGACY_DEBUGFS
  1377. int il_alloc_traffic_mem(struct il_priv *il);
  1378. void il_free_traffic_mem(struct il_priv *il);
  1379. void il_reset_traffic_log(struct il_priv *il);
  1380. void il_dbg_log_tx_data_frame(struct il_priv *il,
  1381. u16 length, struct ieee80211_hdr *header);
  1382. void il_dbg_log_rx_data_frame(struct il_priv *il,
  1383. u16 length, struct ieee80211_hdr *header);
  1384. const char *il_get_mgmt_string(int cmd);
  1385. const char *il_get_ctrl_string(int cmd);
  1386. void il_clear_traffic_stats(struct il_priv *il);
  1387. void il_update_stats(struct il_priv *il, bool is_tx, __le16 fc,
  1388. u16 len);
  1389. #else
  1390. static inline int il_alloc_traffic_mem(struct il_priv *il)
  1391. {
  1392. return 0;
  1393. }
  1394. static inline void il_free_traffic_mem(struct il_priv *il)
  1395. {
  1396. }
  1397. static inline void il_reset_traffic_log(struct il_priv *il)
  1398. {
  1399. }
  1400. static inline void il_dbg_log_tx_data_frame(struct il_priv *il,
  1401. u16 length, struct ieee80211_hdr *header)
  1402. {
  1403. }
  1404. static inline void il_dbg_log_rx_data_frame(struct il_priv *il,
  1405. u16 length, struct ieee80211_hdr *header)
  1406. {
  1407. }
  1408. static inline void il_update_stats(struct il_priv *il, bool is_tx,
  1409. __le16 fc, u16 len)
  1410. {
  1411. }
  1412. #endif
  1413. /*****************************************************
  1414. * RX handlers.
  1415. * **************************************************/
  1416. void il_hdl_pm_sleep(struct il_priv *il,
  1417. struct il_rx_buf *rxb);
  1418. void il_hdl_pm_debug_stats(struct il_priv *il,
  1419. struct il_rx_buf *rxb);
  1420. void il_hdl_error(struct il_priv *il,
  1421. struct il_rx_buf *rxb);
  1422. /*****************************************************
  1423. * RX
  1424. ******************************************************/
  1425. void il_cmd_queue_unmap(struct il_priv *il);
  1426. void il_cmd_queue_free(struct il_priv *il);
  1427. int il_rx_queue_alloc(struct il_priv *il);
  1428. void il_rx_queue_update_write_ptr(struct il_priv *il,
  1429. struct il_rx_queue *q);
  1430. int il_rx_queue_space(const struct il_rx_queue *q);
  1431. void il_tx_cmd_complete(struct il_priv *il,
  1432. struct il_rx_buf *rxb);
  1433. /* Handlers */
  1434. void il_hdl_spectrum_measurement(struct il_priv *il,
  1435. struct il_rx_buf *rxb);
  1436. void il_recover_from_stats(struct il_priv *il,
  1437. struct il_rx_pkt *pkt);
  1438. void il_chswitch_done(struct il_priv *il, bool is_success);
  1439. void il_hdl_csa(struct il_priv *il, struct il_rx_buf *rxb);
  1440. /* TX helpers */
  1441. /*****************************************************
  1442. * TX
  1443. ******************************************************/
  1444. void il_txq_update_write_ptr(struct il_priv *il,
  1445. struct il_tx_queue *txq);
  1446. int il_tx_queue_init(struct il_priv *il, struct il_tx_queue *txq,
  1447. int slots_num, u32 txq_id);
  1448. void il_tx_queue_reset(struct il_priv *il,
  1449. struct il_tx_queue *txq,
  1450. int slots_num, u32 txq_id);
  1451. void il_tx_queue_unmap(struct il_priv *il, int txq_id);
  1452. void il_tx_queue_free(struct il_priv *il, int txq_id);
  1453. void il_setup_watchdog(struct il_priv *il);
  1454. /*****************************************************
  1455. * TX power
  1456. ****************************************************/
  1457. int il_set_tx_power(struct il_priv *il, s8 tx_power, bool force);
  1458. /*******************************************************************************
  1459. * Rate
  1460. ******************************************************************************/
  1461. u8 il_get_lowest_plcp(struct il_priv *il,
  1462. struct il_rxon_context *ctx);
  1463. /*******************************************************************************
  1464. * Scanning
  1465. ******************************************************************************/
  1466. void il_init_scan_params(struct il_priv *il);
  1467. int il_scan_cancel(struct il_priv *il);
  1468. int il_scan_cancel_timeout(struct il_priv *il, unsigned long ms);
  1469. void il_force_scan_end(struct il_priv *il);
  1470. int il_mac_hw_scan(struct ieee80211_hw *hw,
  1471. struct ieee80211_vif *vif,
  1472. struct cfg80211_scan_request *req);
  1473. void il_internal_short_hw_scan(struct il_priv *il);
  1474. int il_force_reset(struct il_priv *il, bool external);
  1475. u16 il_fill_probe_req(struct il_priv *il,
  1476. struct ieee80211_mgmt *frame,
  1477. const u8 *ta, const u8 *ie, int ie_len, int left);
  1478. void il_setup_rx_scan_handlers(struct il_priv *il);
  1479. u16 il_get_active_dwell_time(struct il_priv *il,
  1480. enum ieee80211_band band,
  1481. u8 n_probes);
  1482. u16 il_get_passive_dwell_time(struct il_priv *il,
  1483. enum ieee80211_band band,
  1484. struct ieee80211_vif *vif);
  1485. void il_setup_scan_deferred_work(struct il_priv *il);
  1486. void il_cancel_scan_deferred_work(struct il_priv *il);
  1487. /* For faster active scanning, scan will move to the next channel if fewer than
  1488. * PLCP_QUIET_THRESH packets are heard on this channel within
  1489. * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell
  1490. * time if it's a quiet channel (nothing responded to our probe, and there's
  1491. * no other traffic).
  1492. * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */
  1493. #define IL_ACTIVE_QUIET_TIME cpu_to_le16(10) /* msec */
  1494. #define IL_PLCP_QUIET_THRESH cpu_to_le16(1) /* packets */
  1495. #define IL_SCAN_CHECK_WATCHDOG (HZ * 7)
  1496. /*****************************************************
  1497. * S e n d i n g H o s t C o m m a n d s *
  1498. *****************************************************/
  1499. const char *il_get_cmd_string(u8 cmd);
  1500. int __must_check il_send_cmd_sync(struct il_priv *il,
  1501. struct il_host_cmd *cmd);
  1502. int il_send_cmd(struct il_priv *il, struct il_host_cmd *cmd);
  1503. int __must_check il_send_cmd_pdu(struct il_priv *il, u8 id,
  1504. u16 len, const void *data);
  1505. int il_send_cmd_pdu_async(struct il_priv *il, u8 id, u16 len,
  1506. const void *data,
  1507. void (*callback)(struct il_priv *il,
  1508. struct il_device_cmd *cmd,
  1509. struct il_rx_pkt *pkt));
  1510. int il_enqueue_hcmd(struct il_priv *il, struct il_host_cmd *cmd);
  1511. /*****************************************************
  1512. * PCI *
  1513. *****************************************************/
  1514. static inline u16 il_pcie_link_ctl(struct il_priv *il)
  1515. {
  1516. int pos;
  1517. u16 pci_lnk_ctl;
  1518. pos = pci_pcie_cap(il->pci_dev);
  1519. pci_read_config_word(il->pci_dev, pos + PCI_EXP_LNKCTL, &pci_lnk_ctl);
  1520. return pci_lnk_ctl;
  1521. }
  1522. void il_bg_watchdog(unsigned long data);
  1523. u32 il_usecs_to_beacons(struct il_priv *il,
  1524. u32 usec, u32 beacon_interval);
  1525. __le32 il_add_beacon_time(struct il_priv *il, u32 base,
  1526. u32 addon, u32 beacon_interval);
  1527. #ifdef CONFIG_PM
  1528. int il_pci_suspend(struct device *device);
  1529. int il_pci_resume(struct device *device);
  1530. extern const struct dev_pm_ops il_pm_ops;
  1531. #define IL_LEGACY_PM_OPS (&il_pm_ops)
  1532. #else /* !CONFIG_PM */
  1533. #define IL_LEGACY_PM_OPS NULL
  1534. #endif /* !CONFIG_PM */
  1535. /*****************************************************
  1536. * Error Handling Debugging
  1537. ******************************************************/
  1538. void il4965_dump_nic_error_log(struct il_priv *il);
  1539. #ifdef CONFIG_IWLEGACY_DEBUG
  1540. void il_print_rx_config_cmd(struct il_priv *il,
  1541. struct il_rxon_context *ctx);
  1542. #else
  1543. static inline void il_print_rx_config_cmd(struct il_priv *il,
  1544. struct il_rxon_context *ctx)
  1545. {
  1546. }
  1547. #endif
  1548. void il_clear_isr_stats(struct il_priv *il);
  1549. /*****************************************************
  1550. * GEOS
  1551. ******************************************************/
  1552. int il_init_geos(struct il_priv *il);
  1553. void il_free_geos(struct il_priv *il);
  1554. /*************** DRIVER STATUS FUNCTIONS *****/
  1555. #define S_HCMD_ACTIVE 0 /* host command in progress */
  1556. /* 1 is unused (used to be S_HCMD_SYNC_ACTIVE) */
  1557. #define S_INT_ENABLED 2
  1558. #define S_RF_KILL_HW 3
  1559. #define S_CT_KILL 4
  1560. #define S_INIT 5
  1561. #define S_ALIVE 6
  1562. #define S_READY 7
  1563. #define S_TEMPERATURE 8
  1564. #define S_GEO_CONFIGURED 9
  1565. #define S_EXIT_PENDING 10
  1566. #define S_STATS 12
  1567. #define S_SCANNING 13
  1568. #define S_SCAN_ABORTING 14
  1569. #define S_SCAN_HW 15
  1570. #define S_POWER_PMI 16
  1571. #define S_FW_ERROR 17
  1572. #define S_CHANNEL_SWITCH_PENDING 18
  1573. static inline int il_is_ready(struct il_priv *il)
  1574. {
  1575. /* The adapter is 'ready' if READY and GEO_CONFIGURED bits are
  1576. * set but EXIT_PENDING is not */
  1577. return test_bit(S_READY, &il->status) &&
  1578. test_bit(S_GEO_CONFIGURED, &il->status) &&
  1579. !test_bit(S_EXIT_PENDING, &il->status);
  1580. }
  1581. static inline int il_is_alive(struct il_priv *il)
  1582. {
  1583. return test_bit(S_ALIVE, &il->status);
  1584. }
  1585. static inline int il_is_init(struct il_priv *il)
  1586. {
  1587. return test_bit(S_INIT, &il->status);
  1588. }
  1589. static inline int il_is_rfkill_hw(struct il_priv *il)
  1590. {
  1591. return test_bit(S_RF_KILL_HW, &il->status);
  1592. }
  1593. static inline int il_is_rfkill(struct il_priv *il)
  1594. {
  1595. return il_is_rfkill_hw(il);
  1596. }
  1597. static inline int il_is_ctkill(struct il_priv *il)
  1598. {
  1599. return test_bit(S_CT_KILL, &il->status);
  1600. }
  1601. static inline int il_is_ready_rf(struct il_priv *il)
  1602. {
  1603. if (il_is_rfkill(il))
  1604. return 0;
  1605. return il_is_ready(il);
  1606. }
  1607. extern void il_send_bt_config(struct il_priv *il);
  1608. extern int il_send_stats_request(struct il_priv *il,
  1609. u8 flags, bool clear);
  1610. void il_apm_stop(struct il_priv *il);
  1611. int il_apm_init(struct il_priv *il);
  1612. int il_send_rxon_timing(struct il_priv *il,
  1613. struct il_rxon_context *ctx);
  1614. static inline int il_send_rxon_assoc(struct il_priv *il,
  1615. struct il_rxon_context *ctx)
  1616. {
  1617. return il->cfg->ops->hcmd->rxon_assoc(il, ctx);
  1618. }
  1619. static inline int il_commit_rxon(struct il_priv *il,
  1620. struct il_rxon_context *ctx)
  1621. {
  1622. return il->cfg->ops->hcmd->commit_rxon(il, ctx);
  1623. }
  1624. static inline const struct ieee80211_supported_band *il_get_hw_mode(
  1625. struct il_priv *il, enum ieee80211_band band)
  1626. {
  1627. return il->hw->wiphy->bands[band];
  1628. }
  1629. /* mac80211 handlers */
  1630. int il_mac_config(struct ieee80211_hw *hw, u32 changed);
  1631. void il_mac_reset_tsf(struct ieee80211_hw *hw,
  1632. struct ieee80211_vif *vif);
  1633. void il_mac_bss_info_changed(struct ieee80211_hw *hw,
  1634. struct ieee80211_vif *vif,
  1635. struct ieee80211_bss_conf *bss_conf,
  1636. u32 changes);
  1637. void il_tx_cmd_protection(struct il_priv *il,
  1638. struct ieee80211_tx_info *info,
  1639. __le16 fc, __le32 *tx_flags);
  1640. irqreturn_t il_isr(int irq, void *data);
  1641. #include <linux/io.h>
  1642. static inline void _il_write8(struct il_priv *il, u32 ofs, u8 val)
  1643. {
  1644. iowrite8(val, il->hw_base + ofs);
  1645. }
  1646. #define il_write8(il, ofs, val) _il_write8(il, ofs, val)
  1647. static inline void _il_wr(struct il_priv *il, u32 ofs, u32 val)
  1648. {
  1649. iowrite32(val, il->hw_base + ofs);
  1650. }
  1651. static inline u32 _il_rd(struct il_priv *il, u32 ofs)
  1652. {
  1653. return ioread32(il->hw_base + ofs);
  1654. }
  1655. #define IL_POLL_INTERVAL 10 /* microseconds */
  1656. static inline int
  1657. _il_poll_bit(struct il_priv *il, u32 addr,
  1658. u32 bits, u32 mask, int timeout)
  1659. {
  1660. int t = 0;
  1661. do {
  1662. if ((_il_rd(il, addr) & mask) == (bits & mask))
  1663. return t;
  1664. udelay(IL_POLL_INTERVAL);
  1665. t += IL_POLL_INTERVAL;
  1666. } while (t < timeout);
  1667. return -ETIMEDOUT;
  1668. }
  1669. static inline void _il_set_bit(struct il_priv *il, u32 reg, u32 mask)
  1670. {
  1671. _il_wr(il, reg, _il_rd(il, reg) | mask);
  1672. }
  1673. static inline void il_set_bit(struct il_priv *p, u32 r, u32 m)
  1674. {
  1675. unsigned long reg_flags;
  1676. spin_lock_irqsave(&p->reg_lock, reg_flags);
  1677. _il_set_bit(p, r, m);
  1678. spin_unlock_irqrestore(&p->reg_lock, reg_flags);
  1679. }
  1680. static inline void
  1681. _il_clear_bit(struct il_priv *il, u32 reg, u32 mask)
  1682. {
  1683. _il_wr(il, reg, _il_rd(il, reg) & ~mask);
  1684. }
  1685. static inline void il_clear_bit(struct il_priv *p, u32 r, u32 m)
  1686. {
  1687. unsigned long reg_flags;
  1688. spin_lock_irqsave(&p->reg_lock, reg_flags);
  1689. _il_clear_bit(p, r, m);
  1690. spin_unlock_irqrestore(&p->reg_lock, reg_flags);
  1691. }
  1692. static inline int _il_grab_nic_access(struct il_priv *il)
  1693. {
  1694. int ret;
  1695. u32 val;
  1696. /* this bit wakes up the NIC */
  1697. _il_set_bit(il, CSR_GP_CNTRL,
  1698. CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  1699. /*
  1700. * These bits say the device is running, and should keep running for
  1701. * at least a short while (at least as long as MAC_ACCESS_REQ stays 1),
  1702. * but they do not indicate that embedded SRAM is restored yet;
  1703. * 3945 and 4965 have volatile SRAM, and must save/restore contents
  1704. * to/from host DRAM when sleeping/waking for power-saving.
  1705. * Each direction takes approximately 1/4 millisecond; with this
  1706. * overhead, it's a good idea to grab and hold MAC_ACCESS_REQUEST if a
  1707. * series of register accesses are expected (e.g. reading Event Log),
  1708. * to keep device from sleeping.
  1709. *
  1710. * CSR_UCODE_DRV_GP1 register bit MAC_SLEEP == 0 indicates that
  1711. * SRAM is okay/restored. We don't check that here because this call
  1712. * is just for hardware register access; but GP1 MAC_SLEEP check is a
  1713. * good idea before accessing 3945/4965 SRAM (e.g. reading Event Log).
  1714. *
  1715. */
  1716. ret = _il_poll_bit(il, CSR_GP_CNTRL,
  1717. CSR_GP_CNTRL_REG_VAL_MAC_ACCESS_EN,
  1718. (CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY |
  1719. CSR_GP_CNTRL_REG_FLAG_GOING_TO_SLEEP), 15000);
  1720. if (ret < 0) {
  1721. val = _il_rd(il, CSR_GP_CNTRL);
  1722. IL_ERR(
  1723. "MAC is in deep sleep!. CSR_GP_CNTRL = 0x%08X\n", val);
  1724. _il_wr(il, CSR_RESET,
  1725. CSR_RESET_REG_FLAG_FORCE_NMI);
  1726. return -EIO;
  1727. }
  1728. return 0;
  1729. }
  1730. static inline void _il_release_nic_access(struct il_priv *il)
  1731. {
  1732. _il_clear_bit(il, CSR_GP_CNTRL,
  1733. CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  1734. }
  1735. static inline u32 il_rd(struct il_priv *il, u32 reg)
  1736. {
  1737. u32 value;
  1738. unsigned long reg_flags;
  1739. spin_lock_irqsave(&il->reg_lock, reg_flags);
  1740. _il_grab_nic_access(il);
  1741. value = _il_rd(il, reg);
  1742. _il_release_nic_access(il);
  1743. spin_unlock_irqrestore(&il->reg_lock, reg_flags);
  1744. return value;
  1745. }
  1746. static inline void
  1747. il_wr(struct il_priv *il, u32 reg, u32 value)
  1748. {
  1749. unsigned long reg_flags;
  1750. spin_lock_irqsave(&il->reg_lock, reg_flags);
  1751. if (!_il_grab_nic_access(il)) {
  1752. _il_wr(il, reg, value);
  1753. _il_release_nic_access(il);
  1754. }
  1755. spin_unlock_irqrestore(&il->reg_lock, reg_flags);
  1756. }
  1757. static inline void il_write_reg_buf(struct il_priv *il,
  1758. u32 reg, u32 len, u32 *values)
  1759. {
  1760. u32 count = sizeof(u32);
  1761. if (il != NULL && values != NULL) {
  1762. for (; 0 < len; len -= count, reg += count, values++)
  1763. il_wr(il, reg, *values);
  1764. }
  1765. }
  1766. static inline int il_poll_bit(struct il_priv *il, u32 addr,
  1767. u32 mask, int timeout)
  1768. {
  1769. int t = 0;
  1770. do {
  1771. if ((il_rd(il, addr) & mask) == mask)
  1772. return t;
  1773. udelay(IL_POLL_INTERVAL);
  1774. t += IL_POLL_INTERVAL;
  1775. } while (t < timeout);
  1776. return -ETIMEDOUT;
  1777. }
  1778. static inline u32 _il_rd_prph(struct il_priv *il, u32 reg)
  1779. {
  1780. _il_wr(il, HBUS_TARG_PRPH_RADDR, reg | (3 << 24));
  1781. rmb();
  1782. return _il_rd(il, HBUS_TARG_PRPH_RDAT);
  1783. }
  1784. static inline u32 il_rd_prph(struct il_priv *il, u32 reg)
  1785. {
  1786. unsigned long reg_flags;
  1787. u32 val;
  1788. spin_lock_irqsave(&il->reg_lock, reg_flags);
  1789. _il_grab_nic_access(il);
  1790. val = _il_rd_prph(il, reg);
  1791. _il_release_nic_access(il);
  1792. spin_unlock_irqrestore(&il->reg_lock, reg_flags);
  1793. return val;
  1794. }
  1795. static inline void _il_wr_prph(struct il_priv *il,
  1796. u32 addr, u32 val)
  1797. {
  1798. _il_wr(il, HBUS_TARG_PRPH_WADDR,
  1799. ((addr & 0x0000FFFF) | (3 << 24)));
  1800. wmb();
  1801. _il_wr(il, HBUS_TARG_PRPH_WDAT, val);
  1802. }
  1803. static inline void
  1804. il_wr_prph(struct il_priv *il, u32 addr, u32 val)
  1805. {
  1806. unsigned long reg_flags;
  1807. spin_lock_irqsave(&il->reg_lock, reg_flags);
  1808. if (!_il_grab_nic_access(il)) {
  1809. _il_wr_prph(il, addr, val);
  1810. _il_release_nic_access(il);
  1811. }
  1812. spin_unlock_irqrestore(&il->reg_lock, reg_flags);
  1813. }
  1814. #define _il_set_bits_prph(il, reg, mask) \
  1815. _il_wr_prph(il, reg, (_il_rd_prph(il, reg) | mask))
  1816. static inline void
  1817. il_set_bits_prph(struct il_priv *il, u32 reg, u32 mask)
  1818. {
  1819. unsigned long reg_flags;
  1820. spin_lock_irqsave(&il->reg_lock, reg_flags);
  1821. _il_grab_nic_access(il);
  1822. _il_set_bits_prph(il, reg, mask);
  1823. _il_release_nic_access(il);
  1824. spin_unlock_irqrestore(&il->reg_lock, reg_flags);
  1825. }
  1826. #define _il_set_bits_mask_prph(il, reg, bits, mask) \
  1827. _il_wr_prph(il, reg, \
  1828. ((_il_rd_prph(il, reg) & mask) | bits))
  1829. static inline void il_set_bits_mask_prph(struct il_priv *il, u32 reg,
  1830. u32 bits, u32 mask)
  1831. {
  1832. unsigned long reg_flags;
  1833. spin_lock_irqsave(&il->reg_lock, reg_flags);
  1834. _il_grab_nic_access(il);
  1835. _il_set_bits_mask_prph(il, reg, bits, mask);
  1836. _il_release_nic_access(il);
  1837. spin_unlock_irqrestore(&il->reg_lock, reg_flags);
  1838. }
  1839. static inline void il_clear_bits_prph(struct il_priv
  1840. *il, u32 reg, u32 mask)
  1841. {
  1842. unsigned long reg_flags;
  1843. u32 val;
  1844. spin_lock_irqsave(&il->reg_lock, reg_flags);
  1845. _il_grab_nic_access(il);
  1846. val = _il_rd_prph(il, reg);
  1847. _il_wr_prph(il, reg, (val & ~mask));
  1848. _il_release_nic_access(il);
  1849. spin_unlock_irqrestore(&il->reg_lock, reg_flags);
  1850. }
  1851. static inline u32 il_read_targ_mem(struct il_priv *il, u32 addr)
  1852. {
  1853. unsigned long reg_flags;
  1854. u32 value;
  1855. spin_lock_irqsave(&il->reg_lock, reg_flags);
  1856. _il_grab_nic_access(il);
  1857. _il_wr(il, HBUS_TARG_MEM_RADDR, addr);
  1858. rmb();
  1859. value = _il_rd(il, HBUS_TARG_MEM_RDAT);
  1860. _il_release_nic_access(il);
  1861. spin_unlock_irqrestore(&il->reg_lock, reg_flags);
  1862. return value;
  1863. }
  1864. static inline void
  1865. il_write_targ_mem(struct il_priv *il, u32 addr, u32 val)
  1866. {
  1867. unsigned long reg_flags;
  1868. spin_lock_irqsave(&il->reg_lock, reg_flags);
  1869. if (!_il_grab_nic_access(il)) {
  1870. _il_wr(il, HBUS_TARG_MEM_WADDR, addr);
  1871. wmb();
  1872. _il_wr(il, HBUS_TARG_MEM_WDAT, val);
  1873. _il_release_nic_access(il);
  1874. }
  1875. spin_unlock_irqrestore(&il->reg_lock, reg_flags);
  1876. }
  1877. static inline void
  1878. il_write_targ_mem_buf(struct il_priv *il, u32 addr,
  1879. u32 len, u32 *values)
  1880. {
  1881. unsigned long reg_flags;
  1882. spin_lock_irqsave(&il->reg_lock, reg_flags);
  1883. if (!_il_grab_nic_access(il)) {
  1884. _il_wr(il, HBUS_TARG_MEM_WADDR, addr);
  1885. wmb();
  1886. for (; 0 < len; len -= sizeof(u32), values++)
  1887. _il_wr(il,
  1888. HBUS_TARG_MEM_WDAT, *values);
  1889. _il_release_nic_access(il);
  1890. }
  1891. spin_unlock_irqrestore(&il->reg_lock, reg_flags);
  1892. }
  1893. #define HW_KEY_DYNAMIC 0
  1894. #define HW_KEY_DEFAULT 1
  1895. #define IL_STA_DRIVER_ACTIVE BIT(0) /* driver entry is active */
  1896. #define IL_STA_UCODE_ACTIVE BIT(1) /* ucode entry is active */
  1897. #define IL_STA_UCODE_INPROGRESS BIT(2) /* ucode entry is in process of
  1898. being activated */
  1899. #define IL_STA_LOCAL BIT(3) /* station state not directed by mac80211;
  1900. (this is for the IBSS BSSID stations) */
  1901. #define IL_STA_BCAST BIT(4) /* this station is the special bcast station */
  1902. void il_restore_stations(struct il_priv *il,
  1903. struct il_rxon_context *ctx);
  1904. void il_clear_ucode_stations(struct il_priv *il,
  1905. struct il_rxon_context *ctx);
  1906. void il_dealloc_bcast_stations(struct il_priv *il);
  1907. int il_get_free_ucode_key_idx(struct il_priv *il);
  1908. int il_send_add_sta(struct il_priv *il,
  1909. struct il_addsta_cmd *sta, u8 flags);
  1910. int il_add_station_common(struct il_priv *il,
  1911. struct il_rxon_context *ctx,
  1912. const u8 *addr, bool is_ap,
  1913. struct ieee80211_sta *sta, u8 *sta_id_r);
  1914. int il_remove_station(struct il_priv *il,
  1915. const u8 sta_id,
  1916. const u8 *addr);
  1917. int il_mac_sta_remove(struct ieee80211_hw *hw,
  1918. struct ieee80211_vif *vif,
  1919. struct ieee80211_sta *sta);
  1920. u8 il_prep_station(struct il_priv *il,
  1921. struct il_rxon_context *ctx,
  1922. const u8 *addr, bool is_ap,
  1923. struct ieee80211_sta *sta);
  1924. int il_send_lq_cmd(struct il_priv *il,
  1925. struct il_rxon_context *ctx,
  1926. struct il_link_quality_cmd *lq,
  1927. u8 flags, bool init);
  1928. /**
  1929. * il_clear_driver_stations - clear knowledge of all stations from driver
  1930. * @il: iwl il struct
  1931. *
  1932. * This is called during il_down() to make sure that in the case
  1933. * we're coming there from a hardware restart mac80211 will be
  1934. * able to reconfigure stations -- if we're getting there in the
  1935. * normal down flow then the stations will already be cleared.
  1936. */
  1937. static inline void il_clear_driver_stations(struct il_priv *il)
  1938. {
  1939. unsigned long flags;
  1940. struct il_rxon_context *ctx = &il->ctx;
  1941. spin_lock_irqsave(&il->sta_lock, flags);
  1942. memset(il->stations, 0, sizeof(il->stations));
  1943. il->num_stations = 0;
  1944. il->ucode_key_table = 0;
  1945. /*
  1946. * Remove all key information that is not stored as part
  1947. * of station information since mac80211 may not have had
  1948. * a chance to remove all the keys. When device is
  1949. * reconfigured by mac80211 after an error all keys will
  1950. * be reconfigured.
  1951. */
  1952. memset(ctx->wep_keys, 0, sizeof(ctx->wep_keys));
  1953. ctx->key_mapping_keys = 0;
  1954. spin_unlock_irqrestore(&il->sta_lock, flags);
  1955. }
  1956. static inline int il_sta_id(struct ieee80211_sta *sta)
  1957. {
  1958. if (WARN_ON(!sta))
  1959. return IL_INVALID_STATION;
  1960. return ((struct il_station_priv_common *)sta->drv_priv)->sta_id;
  1961. }
  1962. /**
  1963. * il_sta_id_or_broadcast - return sta_id or broadcast sta
  1964. * @il: iwl il
  1965. * @context: the current context
  1966. * @sta: mac80211 station
  1967. *
  1968. * In certain circumstances mac80211 passes a station pointer
  1969. * that may be %NULL, for example during TX or key setup. In
  1970. * that case, we need to use the broadcast station, so this
  1971. * inline wraps that pattern.
  1972. */
  1973. static inline int il_sta_id_or_broadcast(struct il_priv *il,
  1974. struct il_rxon_context *context,
  1975. struct ieee80211_sta *sta)
  1976. {
  1977. int sta_id;
  1978. if (!sta)
  1979. return context->bcast_sta_id;
  1980. sta_id = il_sta_id(sta);
  1981. /*
  1982. * mac80211 should not be passing a partially
  1983. * initialised station!
  1984. */
  1985. WARN_ON(sta_id == IL_INVALID_STATION);
  1986. return sta_id;
  1987. }
  1988. /**
  1989. * il_queue_inc_wrap - increment queue idx, wrap back to beginning
  1990. * @idx -- current idx
  1991. * @n_bd -- total number of entries in queue (must be power of 2)
  1992. */
  1993. static inline int il_queue_inc_wrap(int idx, int n_bd)
  1994. {
  1995. return ++idx & (n_bd - 1);
  1996. }
  1997. /**
  1998. * il_queue_dec_wrap - decrement queue idx, wrap back to end
  1999. * @idx -- current idx
  2000. * @n_bd -- total number of entries in queue (must be power of 2)
  2001. */
  2002. static inline int il_queue_dec_wrap(int idx, int n_bd)
  2003. {
  2004. return --idx & (n_bd - 1);
  2005. }
  2006. /* TODO: Move fw_desc functions to iwl-pci.ko */
  2007. static inline void il_free_fw_desc(struct pci_dev *pci_dev,
  2008. struct fw_desc *desc)
  2009. {
  2010. if (desc->v_addr)
  2011. dma_free_coherent(&pci_dev->dev, desc->len,
  2012. desc->v_addr, desc->p_addr);
  2013. desc->v_addr = NULL;
  2014. desc->len = 0;
  2015. }
  2016. static inline int il_alloc_fw_desc(struct pci_dev *pci_dev,
  2017. struct fw_desc *desc)
  2018. {
  2019. if (!desc->len) {
  2020. desc->v_addr = NULL;
  2021. return -EINVAL;
  2022. }
  2023. desc->v_addr = dma_alloc_coherent(&pci_dev->dev, desc->len,
  2024. &desc->p_addr, GFP_KERNEL);
  2025. return (desc->v_addr != NULL) ? 0 : -ENOMEM;
  2026. }
  2027. /*
  2028. * we have 8 bits used like this:
  2029. *
  2030. * 7 6 5 4 3 2 1 0
  2031. * | | | | | | | |
  2032. * | | | | | | +-+-------- AC queue (0-3)
  2033. * | | | | | |
  2034. * | +-+-+-+-+------------ HW queue ID
  2035. * |
  2036. * +---------------------- unused
  2037. */
  2038. static inline void
  2039. il_set_swq_id(struct il_tx_queue *txq, u8 ac, u8 hwq)
  2040. {
  2041. BUG_ON(ac > 3); /* only have 2 bits */
  2042. BUG_ON(hwq > 31); /* only use 5 bits */
  2043. txq->swq_id = (hwq << 2) | ac;
  2044. }
  2045. static inline void il_wake_queue(struct il_priv *il,
  2046. struct il_tx_queue *txq)
  2047. {
  2048. u8 queue = txq->swq_id;
  2049. u8 ac = queue & 3;
  2050. u8 hwq = (queue >> 2) & 0x1f;
  2051. if (test_and_clear_bit(hwq, il->queue_stopped))
  2052. if (atomic_dec_return(&il->queue_stop_count[ac]) <= 0)
  2053. ieee80211_wake_queue(il->hw, ac);
  2054. }
  2055. static inline void il_stop_queue(struct il_priv *il,
  2056. struct il_tx_queue *txq)
  2057. {
  2058. u8 queue = txq->swq_id;
  2059. u8 ac = queue & 3;
  2060. u8 hwq = (queue >> 2) & 0x1f;
  2061. if (!test_and_set_bit(hwq, il->queue_stopped))
  2062. if (atomic_inc_return(&il->queue_stop_count[ac]) > 0)
  2063. ieee80211_stop_queue(il->hw, ac);
  2064. }
  2065. #ifdef ieee80211_stop_queue
  2066. #undef ieee80211_stop_queue
  2067. #endif
  2068. #define ieee80211_stop_queue DO_NOT_USE_ieee80211_stop_queue
  2069. #ifdef ieee80211_wake_queue
  2070. #undef ieee80211_wake_queue
  2071. #endif
  2072. #define ieee80211_wake_queue DO_NOT_USE_ieee80211_wake_queue
  2073. static inline void il_disable_interrupts(struct il_priv *il)
  2074. {
  2075. clear_bit(S_INT_ENABLED, &il->status);
  2076. /* disable interrupts from uCode/NIC to host */
  2077. _il_wr(il, CSR_INT_MASK, 0x00000000);
  2078. /* acknowledge/clear/reset any interrupts still pending
  2079. * from uCode or flow handler (Rx/Tx DMA) */
  2080. _il_wr(il, CSR_INT, 0xffffffff);
  2081. _il_wr(il, CSR_FH_INT_STATUS, 0xffffffff);
  2082. D_ISR("Disabled interrupts\n");
  2083. }
  2084. static inline void il_enable_rfkill_int(struct il_priv *il)
  2085. {
  2086. D_ISR("Enabling rfkill interrupt\n");
  2087. _il_wr(il, CSR_INT_MASK, CSR_INT_BIT_RF_KILL);
  2088. }
  2089. static inline void il_enable_interrupts(struct il_priv *il)
  2090. {
  2091. D_ISR("Enabling interrupts\n");
  2092. set_bit(S_INT_ENABLED, &il->status);
  2093. _il_wr(il, CSR_INT_MASK, il->inta_mask);
  2094. }
  2095. /**
  2096. * il_beacon_time_mask_low - mask of lower 32 bit of beacon time
  2097. * @il -- pointer to il_priv data structure
  2098. * @tsf_bits -- number of bits need to shift for masking)
  2099. */
  2100. static inline u32 il_beacon_time_mask_low(struct il_priv *il,
  2101. u16 tsf_bits)
  2102. {
  2103. return (1 << tsf_bits) - 1;
  2104. }
  2105. /**
  2106. * il_beacon_time_mask_high - mask of higher 32 bit of beacon time
  2107. * @il -- pointer to il_priv data structure
  2108. * @tsf_bits -- number of bits need to shift for masking)
  2109. */
  2110. static inline u32 il_beacon_time_mask_high(struct il_priv *il,
  2111. u16 tsf_bits)
  2112. {
  2113. return ((1 << (32 - tsf_bits)) - 1) << tsf_bits;
  2114. }
  2115. /**
  2116. * struct il_rb_status - reseve buffer status host memory mapped FH registers
  2117. *
  2118. * @closed_rb_num [0:11] - Indicates the idx of the RB which was closed
  2119. * @closed_fr_num [0:11] - Indicates the idx of the RX Frame which was closed
  2120. * @finished_rb_num [0:11] - Indicates the idx of the current RB
  2121. * in which the last frame was written to
  2122. * @finished_fr_num [0:11] - Indicates the idx of the RX Frame
  2123. * which was transferred
  2124. */
  2125. struct il_rb_status {
  2126. __le16 closed_rb_num;
  2127. __le16 closed_fr_num;
  2128. __le16 finished_rb_num;
  2129. __le16 finished_fr_nam;
  2130. __le32 __unused; /* 3945 only */
  2131. } __packed;
  2132. #define TFD_QUEUE_SIZE_MAX (256)
  2133. #define TFD_QUEUE_SIZE_BC_DUP (64)
  2134. #define TFD_QUEUE_BC_SIZE (TFD_QUEUE_SIZE_MAX + TFD_QUEUE_SIZE_BC_DUP)
  2135. #define IL_TX_DMA_MASK DMA_BIT_MASK(36)
  2136. #define IL_NUM_OF_TBS 20
  2137. static inline u8 il_get_dma_hi_addr(dma_addr_t addr)
  2138. {
  2139. return (sizeof(addr) > sizeof(u32) ? (addr >> 16) >> 16 : 0) & 0xF;
  2140. }
  2141. /**
  2142. * struct il_tfd_tb transmit buffer descriptor within transmit frame descriptor
  2143. *
  2144. * This structure contains dma address and length of transmission address
  2145. *
  2146. * @lo: low [31:0] portion of the dma address of TX buffer
  2147. * every even is unaligned on 16 bit boundary
  2148. * @hi_n_len 0-3 [35:32] portion of dma
  2149. * 4-15 length of the tx buffer
  2150. */
  2151. struct il_tfd_tb {
  2152. __le32 lo;
  2153. __le16 hi_n_len;
  2154. } __packed;
  2155. /**
  2156. * struct il_tfd
  2157. *
  2158. * Transmit Frame Descriptor (TFD)
  2159. *
  2160. * @ __reserved1[3] reserved
  2161. * @ num_tbs 0-4 number of active tbs
  2162. * 5 reserved
  2163. * 6-7 padding (not used)
  2164. * @ tbs[20] transmit frame buffer descriptors
  2165. * @ __pad padding
  2166. *
  2167. * Each Tx queue uses a circular buffer of 256 TFDs stored in host DRAM.
  2168. * Both driver and device share these circular buffers, each of which must be
  2169. * contiguous 256 TFDs x 128 bytes-per-TFD = 32 KBytes
  2170. *
  2171. * Driver must indicate the physical address of the base of each
  2172. * circular buffer via the FH_MEM_CBBC_QUEUE registers.
  2173. *
  2174. * Each TFD contains pointer/size information for up to 20 data buffers
  2175. * in host DRAM. These buffers collectively contain the (one) frame described
  2176. * by the TFD. Each buffer must be a single contiguous block of memory within
  2177. * itself, but buffers may be scattered in host DRAM. Each buffer has max size
  2178. * of (4K - 4). The concatenates all of a TFD's buffers into a single
  2179. * Tx frame, up to 8 KBytes in size.
  2180. *
  2181. * A maximum of 255 (not 256!) TFDs may be on a queue waiting for Tx.
  2182. */
  2183. struct il_tfd {
  2184. u8 __reserved1[3];
  2185. u8 num_tbs;
  2186. struct il_tfd_tb tbs[IL_NUM_OF_TBS];
  2187. __le32 __pad;
  2188. } __packed;
  2189. /* PCI registers */
  2190. #define PCI_CFG_RETRY_TIMEOUT 0x041
  2191. /* PCI register values */
  2192. #define PCI_CFG_LINK_CTRL_VAL_L0S_EN 0x01
  2193. #define PCI_CFG_LINK_CTRL_VAL_L1_EN 0x02
  2194. #endif /* __il_core_h__ */