common.h 91 KB

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