common.h 88 KB

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