common.h 82 KB

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