common.h 91 KB

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