4965.c 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2011 Intel Corporation. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  17. *
  18. * The full GNU General Public License is included in this distribution in the
  19. * file called LICENSE.
  20. *
  21. * Contact Information:
  22. * Intel Linux Wireless <ilw@linux.intel.com>
  23. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  24. *
  25. *****************************************************************************/
  26. #include <linux/kernel.h>
  27. #include <linux/module.h>
  28. #include <linux/init.h>
  29. #include <linux/pci.h>
  30. #include <linux/dma-mapping.h>
  31. #include <linux/delay.h>
  32. #include <linux/sched.h>
  33. #include <linux/skbuff.h>
  34. #include <linux/netdevice.h>
  35. #include <net/mac80211.h>
  36. #include <linux/etherdevice.h>
  37. #include <asm/unaligned.h>
  38. #include "common.h"
  39. #include "4965.h"
  40. /**
  41. * il_verify_inst_sparse - verify runtime uCode image in card vs. host,
  42. * using sample data 100 bytes apart. If these sample points are good,
  43. * it's a pretty good bet that everything between them is good, too.
  44. */
  45. static int
  46. il4965_verify_inst_sparse(struct il_priv *il, __le32 * image, u32 len)
  47. {
  48. u32 val;
  49. int ret = 0;
  50. u32 errcnt = 0;
  51. u32 i;
  52. D_INFO("ucode inst image size is %u\n", len);
  53. for (i = 0; i < len; i += 100, image += 100 / sizeof(u32)) {
  54. /* read data comes through single port, auto-incr addr */
  55. /* NOTE: Use the debugless read so we don't flood kernel log
  56. * if IL_DL_IO is set */
  57. il_wr(il, HBUS_TARG_MEM_RADDR, i + IL4965_RTC_INST_LOWER_BOUND);
  58. val = _il_rd(il, HBUS_TARG_MEM_RDAT);
  59. if (val != le32_to_cpu(*image)) {
  60. ret = -EIO;
  61. errcnt++;
  62. if (errcnt >= 3)
  63. break;
  64. }
  65. }
  66. return ret;
  67. }
  68. /**
  69. * il4965_verify_inst_full - verify runtime uCode image in card vs. host,
  70. * looking at all data.
  71. */
  72. static int
  73. il4965_verify_inst_full(struct il_priv *il, __le32 * image, u32 len)
  74. {
  75. u32 val;
  76. u32 save_len = len;
  77. int ret = 0;
  78. u32 errcnt;
  79. D_INFO("ucode inst image size is %u\n", len);
  80. il_wr(il, HBUS_TARG_MEM_RADDR, IL4965_RTC_INST_LOWER_BOUND);
  81. errcnt = 0;
  82. for (; len > 0; len -= sizeof(u32), image++) {
  83. /* read data comes through single port, auto-incr addr */
  84. /* NOTE: Use the debugless read so we don't flood kernel log
  85. * if IL_DL_IO is set */
  86. val = _il_rd(il, HBUS_TARG_MEM_RDAT);
  87. if (val != le32_to_cpu(*image)) {
  88. IL_ERR("uCode INST section is invalid at "
  89. "offset 0x%x, is 0x%x, s/b 0x%x\n",
  90. save_len - len, val, le32_to_cpu(*image));
  91. ret = -EIO;
  92. errcnt++;
  93. if (errcnt >= 20)
  94. break;
  95. }
  96. }
  97. if (!errcnt)
  98. D_INFO("ucode image in INSTRUCTION memory is good\n");
  99. return ret;
  100. }
  101. /**
  102. * il4965_verify_ucode - determine which instruction image is in SRAM,
  103. * and verify its contents
  104. */
  105. int
  106. il4965_verify_ucode(struct il_priv *il)
  107. {
  108. __le32 *image;
  109. u32 len;
  110. int ret;
  111. /* Try bootstrap */
  112. image = (__le32 *) il->ucode_boot.v_addr;
  113. len = il->ucode_boot.len;
  114. ret = il4965_verify_inst_sparse(il, image, len);
  115. if (!ret) {
  116. D_INFO("Bootstrap uCode is good in inst SRAM\n");
  117. return 0;
  118. }
  119. /* Try initialize */
  120. image = (__le32 *) il->ucode_init.v_addr;
  121. len = il->ucode_init.len;
  122. ret = il4965_verify_inst_sparse(il, image, len);
  123. if (!ret) {
  124. D_INFO("Initialize uCode is good in inst SRAM\n");
  125. return 0;
  126. }
  127. /* Try runtime/protocol */
  128. image = (__le32 *) il->ucode_code.v_addr;
  129. len = il->ucode_code.len;
  130. ret = il4965_verify_inst_sparse(il, image, len);
  131. if (!ret) {
  132. D_INFO("Runtime uCode is good in inst SRAM\n");
  133. return 0;
  134. }
  135. IL_ERR("NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
  136. /* Since nothing seems to match, show first several data entries in
  137. * instruction SRAM, so maybe visual inspection will give a clue.
  138. * Selection of bootstrap image (vs. other images) is arbitrary. */
  139. image = (__le32 *) il->ucode_boot.v_addr;
  140. len = il->ucode_boot.len;
  141. ret = il4965_verify_inst_full(il, image, len);
  142. return ret;
  143. }
  144. /******************************************************************************
  145. *
  146. * EEPROM related functions
  147. *
  148. ******************************************************************************/
  149. /*
  150. * The device's EEPROM semaphore prevents conflicts between driver and uCode
  151. * when accessing the EEPROM; each access is a series of pulses to/from the
  152. * EEPROM chip, not a single event, so even reads could conflict if they
  153. * weren't arbitrated by the semaphore.
  154. */
  155. int
  156. il4965_eeprom_acquire_semaphore(struct il_priv *il)
  157. {
  158. u16 count;
  159. int ret;
  160. for (count = 0; count < EEPROM_SEM_RETRY_LIMIT; count++) {
  161. /* Request semaphore */
  162. il_set_bit(il, CSR_HW_IF_CONFIG_REG,
  163. CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM);
  164. /* See if we got it */
  165. ret =
  166. _il_poll_bit(il, CSR_HW_IF_CONFIG_REG,
  167. CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM,
  168. CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM,
  169. EEPROM_SEM_TIMEOUT);
  170. if (ret >= 0)
  171. return ret;
  172. }
  173. return ret;
  174. }
  175. void
  176. il4965_eeprom_release_semaphore(struct il_priv *il)
  177. {
  178. il_clear_bit(il, CSR_HW_IF_CONFIG_REG,
  179. CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM);
  180. }
  181. int
  182. il4965_eeprom_check_version(struct il_priv *il)
  183. {
  184. u16 eeprom_ver;
  185. u16 calib_ver;
  186. eeprom_ver = il_eeprom_query16(il, EEPROM_VERSION);
  187. calib_ver = il_eeprom_query16(il, EEPROM_4965_CALIB_VERSION_OFFSET);
  188. if (eeprom_ver < il->cfg->eeprom_ver ||
  189. calib_ver < il->cfg->eeprom_calib_ver)
  190. goto err;
  191. IL_INFO("device EEPROM VER=0x%x, CALIB=0x%x\n", eeprom_ver, calib_ver);
  192. return 0;
  193. err:
  194. IL_ERR("Unsupported (too old) EEPROM VER=0x%x < 0x%x "
  195. "CALIB=0x%x < 0x%x\n", eeprom_ver, il->cfg->eeprom_ver,
  196. calib_ver, il->cfg->eeprom_calib_ver);
  197. return -EINVAL;
  198. }
  199. void
  200. il4965_eeprom_get_mac(const struct il_priv *il, u8 * mac)
  201. {
  202. const u8 *addr = il_eeprom_query_addr(il,
  203. EEPROM_MAC_ADDRESS);
  204. memcpy(mac, addr, ETH_ALEN);
  205. }
  206. /* Send led command */
  207. static int
  208. il4965_send_led_cmd(struct il_priv *il, struct il_led_cmd *led_cmd)
  209. {
  210. struct il_host_cmd cmd = {
  211. .id = C_LEDS,
  212. .len = sizeof(struct il_led_cmd),
  213. .data = led_cmd,
  214. .flags = CMD_ASYNC,
  215. .callback = NULL,
  216. };
  217. u32 reg;
  218. reg = _il_rd(il, CSR_LED_REG);
  219. if (reg != (reg & CSR_LED_BSM_CTRL_MSK))
  220. _il_wr(il, CSR_LED_REG, reg & CSR_LED_BSM_CTRL_MSK);
  221. return il_send_cmd(il, &cmd);
  222. }
  223. /* Set led register off */
  224. void
  225. il4965_led_enable(struct il_priv *il)
  226. {
  227. _il_wr(il, CSR_LED_REG, CSR_LED_REG_TRUN_ON);
  228. }
  229. const struct il_led_ops il4965_led_ops = {
  230. .cmd = il4965_send_led_cmd,
  231. };
  232. static int il4965_send_tx_power(struct il_priv *il);
  233. static int il4965_hw_get_temperature(struct il_priv *il);
  234. /* Highest firmware API version supported */
  235. #define IL4965_UCODE_API_MAX 2
  236. /* Lowest firmware API version supported */
  237. #define IL4965_UCODE_API_MIN 2
  238. #define IL4965_FW_PRE "iwlwifi-4965-"
  239. #define _IL4965_MODULE_FIRMWARE(api) IL4965_FW_PRE #api ".ucode"
  240. #define IL4965_MODULE_FIRMWARE(api) _IL4965_MODULE_FIRMWARE(api)
  241. /* check contents of special bootstrap uCode SRAM */
  242. static int
  243. il4965_verify_bsm(struct il_priv *il)
  244. {
  245. __le32 *image = il->ucode_boot.v_addr;
  246. u32 len = il->ucode_boot.len;
  247. u32 reg;
  248. u32 val;
  249. D_INFO("Begin verify bsm\n");
  250. /* verify BSM SRAM contents */
  251. val = il_rd_prph(il, BSM_WR_DWCOUNT_REG);
  252. for (reg = BSM_SRAM_LOWER_BOUND; reg < BSM_SRAM_LOWER_BOUND + len;
  253. reg += sizeof(u32), image++) {
  254. val = il_rd_prph(il, reg);
  255. if (val != le32_to_cpu(*image)) {
  256. IL_ERR("BSM uCode verification failed at "
  257. "addr 0x%08X+%u (of %u), is 0x%x, s/b 0x%x\n",
  258. BSM_SRAM_LOWER_BOUND, reg - BSM_SRAM_LOWER_BOUND,
  259. len, val, le32_to_cpu(*image));
  260. return -EIO;
  261. }
  262. }
  263. D_INFO("BSM bootstrap uCode image OK\n");
  264. return 0;
  265. }
  266. /**
  267. * il4965_load_bsm - Load bootstrap instructions
  268. *
  269. * BSM operation:
  270. *
  271. * The Bootstrap State Machine (BSM) stores a short bootstrap uCode program
  272. * in special SRAM that does not power down during RFKILL. When powering back
  273. * up after power-saving sleeps (or during initial uCode load), the BSM loads
  274. * the bootstrap program into the on-board processor, and starts it.
  275. *
  276. * The bootstrap program loads (via DMA) instructions and data for a new
  277. * program from host DRAM locations indicated by the host driver in the
  278. * BSM_DRAM_* registers. Once the new program is loaded, it starts
  279. * automatically.
  280. *
  281. * When initializing the NIC, the host driver points the BSM to the
  282. * "initialize" uCode image. This uCode sets up some internal data, then
  283. * notifies host via "initialize alive" that it is complete.
  284. *
  285. * The host then replaces the BSM_DRAM_* pointer values to point to the
  286. * normal runtime uCode instructions and a backup uCode data cache buffer
  287. * (filled initially with starting data values for the on-board processor),
  288. * then triggers the "initialize" uCode to load and launch the runtime uCode,
  289. * which begins normal operation.
  290. *
  291. * When doing a power-save shutdown, runtime uCode saves data SRAM into
  292. * the backup data cache in DRAM before SRAM is powered down.
  293. *
  294. * When powering back up, the BSM loads the bootstrap program. This reloads
  295. * the runtime uCode instructions and the backup data cache into SRAM,
  296. * and re-launches the runtime uCode from where it left off.
  297. */
  298. static int
  299. il4965_load_bsm(struct il_priv *il)
  300. {
  301. __le32 *image = il->ucode_boot.v_addr;
  302. u32 len = il->ucode_boot.len;
  303. dma_addr_t pinst;
  304. dma_addr_t pdata;
  305. u32 inst_len;
  306. u32 data_len;
  307. int i;
  308. u32 done;
  309. u32 reg_offset;
  310. int ret;
  311. D_INFO("Begin load bsm\n");
  312. il->ucode_type = UCODE_RT;
  313. /* make sure bootstrap program is no larger than BSM's SRAM size */
  314. if (len > IL49_MAX_BSM_SIZE)
  315. return -EINVAL;
  316. /* Tell bootstrap uCode where to find the "Initialize" uCode
  317. * in host DRAM ... host DRAM physical address bits 35:4 for 4965.
  318. * NOTE: il_init_alive_start() will replace these values,
  319. * after the "initialize" uCode has run, to point to
  320. * runtime/protocol instructions and backup data cache.
  321. */
  322. pinst = il->ucode_init.p_addr >> 4;
  323. pdata = il->ucode_init_data.p_addr >> 4;
  324. inst_len = il->ucode_init.len;
  325. data_len = il->ucode_init_data.len;
  326. il_wr_prph(il, BSM_DRAM_INST_PTR_REG, pinst);
  327. il_wr_prph(il, BSM_DRAM_DATA_PTR_REG, pdata);
  328. il_wr_prph(il, BSM_DRAM_INST_BYTECOUNT_REG, inst_len);
  329. il_wr_prph(il, BSM_DRAM_DATA_BYTECOUNT_REG, data_len);
  330. /* Fill BSM memory with bootstrap instructions */
  331. for (reg_offset = BSM_SRAM_LOWER_BOUND;
  332. reg_offset < BSM_SRAM_LOWER_BOUND + len;
  333. reg_offset += sizeof(u32), image++)
  334. _il_wr_prph(il, reg_offset, le32_to_cpu(*image));
  335. ret = il4965_verify_bsm(il);
  336. if (ret)
  337. return ret;
  338. /* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */
  339. il_wr_prph(il, BSM_WR_MEM_SRC_REG, 0x0);
  340. il_wr_prph(il, BSM_WR_MEM_DST_REG, IL49_RTC_INST_LOWER_BOUND);
  341. il_wr_prph(il, BSM_WR_DWCOUNT_REG, len / sizeof(u32));
  342. /* Load bootstrap code into instruction SRAM now,
  343. * to prepare to load "initialize" uCode */
  344. il_wr_prph(il, BSM_WR_CTRL_REG, BSM_WR_CTRL_REG_BIT_START);
  345. /* Wait for load of bootstrap uCode to finish */
  346. for (i = 0; i < 100; i++) {
  347. done = il_rd_prph(il, BSM_WR_CTRL_REG);
  348. if (!(done & BSM_WR_CTRL_REG_BIT_START))
  349. break;
  350. udelay(10);
  351. }
  352. if (i < 100)
  353. D_INFO("BSM write complete, poll %d iterations\n", i);
  354. else {
  355. IL_ERR("BSM write did not complete!\n");
  356. return -EIO;
  357. }
  358. /* Enable future boot loads whenever power management unit triggers it
  359. * (e.g. when powering back up after power-save shutdown) */
  360. il_wr_prph(il, BSM_WR_CTRL_REG, BSM_WR_CTRL_REG_BIT_START_EN);
  361. return 0;
  362. }
  363. /**
  364. * il4965_set_ucode_ptrs - Set uCode address location
  365. *
  366. * Tell initialization uCode where to find runtime uCode.
  367. *
  368. * BSM registers initially contain pointers to initialization uCode.
  369. * We need to replace them to load runtime uCode inst and data,
  370. * and to save runtime data when powering down.
  371. */
  372. static int
  373. il4965_set_ucode_ptrs(struct il_priv *il)
  374. {
  375. dma_addr_t pinst;
  376. dma_addr_t pdata;
  377. int ret = 0;
  378. /* bits 35:4 for 4965 */
  379. pinst = il->ucode_code.p_addr >> 4;
  380. pdata = il->ucode_data_backup.p_addr >> 4;
  381. /* Tell bootstrap uCode where to find image to load */
  382. il_wr_prph(il, BSM_DRAM_INST_PTR_REG, pinst);
  383. il_wr_prph(il, BSM_DRAM_DATA_PTR_REG, pdata);
  384. il_wr_prph(il, BSM_DRAM_DATA_BYTECOUNT_REG, il->ucode_data.len);
  385. /* Inst byte count must be last to set up, bit 31 signals uCode
  386. * that all new ptr/size info is in place */
  387. il_wr_prph(il, BSM_DRAM_INST_BYTECOUNT_REG,
  388. il->ucode_code.len | BSM_DRAM_INST_LOAD);
  389. D_INFO("Runtime uCode pointers are set.\n");
  390. return ret;
  391. }
  392. /**
  393. * il4965_init_alive_start - Called after N_ALIVE notification received
  394. *
  395. * Called after N_ALIVE notification received from "initialize" uCode.
  396. *
  397. * The 4965 "initialize" ALIVE reply contains calibration data for:
  398. * Voltage, temperature, and MIMO tx gain correction, now stored in il
  399. * (3945 does not contain this data).
  400. *
  401. * Tell "initialize" uCode to go ahead and load the runtime uCode.
  402. */
  403. static void
  404. il4965_init_alive_start(struct il_priv *il)
  405. {
  406. /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
  407. * This is a paranoid check, because we would not have gotten the
  408. * "initialize" alive if code weren't properly loaded. */
  409. if (il4965_verify_ucode(il)) {
  410. /* Runtime instruction load was bad;
  411. * take it all the way back down so we can try again */
  412. D_INFO("Bad \"initialize\" uCode load.\n");
  413. goto restart;
  414. }
  415. /* Calculate temperature */
  416. il->temperature = il4965_hw_get_temperature(il);
  417. /* Send pointers to protocol/runtime uCode image ... init code will
  418. * load and launch runtime uCode, which will send us another "Alive"
  419. * notification. */
  420. D_INFO("Initialization Alive received.\n");
  421. if (il4965_set_ucode_ptrs(il)) {
  422. /* Runtime instruction load won't happen;
  423. * take it all the way back down so we can try again */
  424. D_INFO("Couldn't set up uCode pointers.\n");
  425. goto restart;
  426. }
  427. return;
  428. restart:
  429. queue_work(il->workqueue, &il->restart);
  430. }
  431. static bool
  432. iw4965_is_ht40_channel(__le32 rxon_flags)
  433. {
  434. int chan_mod =
  435. le32_to_cpu(rxon_flags & RXON_FLG_CHANNEL_MODE_MSK) >>
  436. RXON_FLG_CHANNEL_MODE_POS;
  437. return (chan_mod == CHANNEL_MODE_PURE_40 ||
  438. chan_mod == CHANNEL_MODE_MIXED);
  439. }
  440. static void
  441. il4965_nic_config(struct il_priv *il)
  442. {
  443. unsigned long flags;
  444. u16 radio_cfg;
  445. spin_lock_irqsave(&il->lock, flags);
  446. radio_cfg = il_eeprom_query16(il, EEPROM_RADIO_CONFIG);
  447. /* write radio config values to register */
  448. if (EEPROM_RF_CFG_TYPE_MSK(radio_cfg) == EEPROM_4965_RF_CFG_TYPE_MAX)
  449. il_set_bit(il, CSR_HW_IF_CONFIG_REG,
  450. EEPROM_RF_CFG_TYPE_MSK(radio_cfg) |
  451. EEPROM_RF_CFG_STEP_MSK(radio_cfg) |
  452. EEPROM_RF_CFG_DASH_MSK(radio_cfg));
  453. /* set CSR_HW_CONFIG_REG for uCode use */
  454. il_set_bit(il, CSR_HW_IF_CONFIG_REG,
  455. CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI |
  456. CSR_HW_IF_CONFIG_REG_BIT_MAC_SI);
  457. il->calib_info =
  458. (struct il_eeprom_calib_info *)
  459. il_eeprom_query_addr(il, EEPROM_4965_CALIB_TXPOWER_OFFSET);
  460. spin_unlock_irqrestore(&il->lock, flags);
  461. }
  462. /* Reset differential Rx gains in NIC to prepare for chain noise calibration.
  463. * Called after every association, but this runs only once!
  464. * ... once chain noise is calibrated the first time, it's good forever. */
  465. static void
  466. il4965_chain_noise_reset(struct il_priv *il)
  467. {
  468. struct il_chain_noise_data *data = &(il->chain_noise_data);
  469. if (data->state == IL_CHAIN_NOISE_ALIVE && il_is_any_associated(il)) {
  470. struct il_calib_diff_gain_cmd cmd;
  471. /* clear data for chain noise calibration algorithm */
  472. data->chain_noise_a = 0;
  473. data->chain_noise_b = 0;
  474. data->chain_noise_c = 0;
  475. data->chain_signal_a = 0;
  476. data->chain_signal_b = 0;
  477. data->chain_signal_c = 0;
  478. data->beacon_count = 0;
  479. memset(&cmd, 0, sizeof(cmd));
  480. cmd.hdr.op_code = IL_PHY_CALIBRATE_DIFF_GAIN_CMD;
  481. cmd.diff_gain_a = 0;
  482. cmd.diff_gain_b = 0;
  483. cmd.diff_gain_c = 0;
  484. if (il_send_cmd_pdu(il, C_PHY_CALIBRATION, sizeof(cmd), &cmd))
  485. IL_ERR("Could not send C_PHY_CALIBRATION\n");
  486. data->state = IL_CHAIN_NOISE_ACCUMULATE;
  487. D_CALIB("Run chain_noise_calibrate\n");
  488. }
  489. }
  490. static struct il_sensitivity_ranges il4965_sensitivity = {
  491. .min_nrg_cck = 97,
  492. .max_nrg_cck = 0, /* not used, set to 0 */
  493. .auto_corr_min_ofdm = 85,
  494. .auto_corr_min_ofdm_mrc = 170,
  495. .auto_corr_min_ofdm_x1 = 105,
  496. .auto_corr_min_ofdm_mrc_x1 = 220,
  497. .auto_corr_max_ofdm = 120,
  498. .auto_corr_max_ofdm_mrc = 210,
  499. .auto_corr_max_ofdm_x1 = 140,
  500. .auto_corr_max_ofdm_mrc_x1 = 270,
  501. .auto_corr_min_cck = 125,
  502. .auto_corr_max_cck = 200,
  503. .auto_corr_min_cck_mrc = 200,
  504. .auto_corr_max_cck_mrc = 400,
  505. .nrg_th_cck = 100,
  506. .nrg_th_ofdm = 100,
  507. .barker_corr_th_min = 190,
  508. .barker_corr_th_min_mrc = 390,
  509. .nrg_th_cca = 62,
  510. };
  511. static void
  512. il4965_set_ct_threshold(struct il_priv *il)
  513. {
  514. /* want Kelvin */
  515. il->hw_params.ct_kill_threshold =
  516. CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD_LEGACY);
  517. }
  518. /**
  519. * il4965_hw_set_hw_params
  520. *
  521. * Called when initializing driver
  522. */
  523. static int
  524. il4965_hw_set_hw_params(struct il_priv *il)
  525. {
  526. if (il->cfg->mod_params->num_of_queues >= IL_MIN_NUM_QUEUES &&
  527. il->cfg->mod_params->num_of_queues <= IL49_NUM_QUEUES)
  528. il->cfg->num_of_queues =
  529. il->cfg->mod_params->num_of_queues;
  530. il->hw_params.max_txq_num = il->cfg->num_of_queues;
  531. il->hw_params.dma_chnl_num = FH49_TCSR_CHNL_NUM;
  532. il->hw_params.scd_bc_tbls_size =
  533. il->cfg->num_of_queues *
  534. sizeof(struct il4965_scd_bc_tbl);
  535. il->hw_params.tfd_size = sizeof(struct il_tfd);
  536. il->hw_params.max_stations = IL4965_STATION_COUNT;
  537. il->hw_params.max_data_size = IL49_RTC_DATA_SIZE;
  538. il->hw_params.max_inst_size = IL49_RTC_INST_SIZE;
  539. il->hw_params.max_bsm_size = BSM_SRAM_SIZE;
  540. il->hw_params.ht40_channel = BIT(IEEE80211_BAND_5GHZ);
  541. il->hw_params.rx_wrt_ptr_reg = FH49_RSCSR_CHNL0_WPTR;
  542. il->hw_params.tx_chains_num = il4965_num_of_ant(il->cfg->valid_tx_ant);
  543. il->hw_params.rx_chains_num = il4965_num_of_ant(il->cfg->valid_rx_ant);
  544. il->hw_params.valid_tx_ant = il->cfg->valid_tx_ant;
  545. il->hw_params.valid_rx_ant = il->cfg->valid_rx_ant;
  546. il4965_set_ct_threshold(il);
  547. il->hw_params.sens = &il4965_sensitivity;
  548. il->hw_params.beacon_time_tsf_bits = IL4965_EXT_BEACON_TIME_POS;
  549. return 0;
  550. }
  551. static s32
  552. il4965_math_div_round(s32 num, s32 denom, s32 * res)
  553. {
  554. s32 sign = 1;
  555. if (num < 0) {
  556. sign = -sign;
  557. num = -num;
  558. }
  559. if (denom < 0) {
  560. sign = -sign;
  561. denom = -denom;
  562. }
  563. *res = 1;
  564. *res = ((num * 2 + denom) / (denom * 2)) * sign;
  565. return 1;
  566. }
  567. /**
  568. * il4965_get_voltage_compensation - Power supply voltage comp for txpower
  569. *
  570. * Determines power supply voltage compensation for txpower calculations.
  571. * Returns number of 1/2-dB steps to subtract from gain table idx,
  572. * to compensate for difference between power supply voltage during
  573. * factory measurements, vs. current power supply voltage.
  574. *
  575. * Voltage indication is higher for lower voltage.
  576. * Lower voltage requires more gain (lower gain table idx).
  577. */
  578. static s32
  579. il4965_get_voltage_compensation(s32 eeprom_voltage, s32 current_voltage)
  580. {
  581. s32 comp = 0;
  582. if (TX_POWER_IL_ILLEGAL_VOLTAGE == eeprom_voltage ||
  583. TX_POWER_IL_ILLEGAL_VOLTAGE == current_voltage)
  584. return 0;
  585. il4965_math_div_round(current_voltage - eeprom_voltage,
  586. TX_POWER_IL_VOLTAGE_CODES_PER_03V, &comp);
  587. if (current_voltage > eeprom_voltage)
  588. comp *= 2;
  589. if ((comp < -2) || (comp > 2))
  590. comp = 0;
  591. return comp;
  592. }
  593. static s32
  594. il4965_get_tx_atten_grp(u16 channel)
  595. {
  596. if (channel >= CALIB_IL_TX_ATTEN_GR5_FCH &&
  597. channel <= CALIB_IL_TX_ATTEN_GR5_LCH)
  598. return CALIB_CH_GROUP_5;
  599. if (channel >= CALIB_IL_TX_ATTEN_GR1_FCH &&
  600. channel <= CALIB_IL_TX_ATTEN_GR1_LCH)
  601. return CALIB_CH_GROUP_1;
  602. if (channel >= CALIB_IL_TX_ATTEN_GR2_FCH &&
  603. channel <= CALIB_IL_TX_ATTEN_GR2_LCH)
  604. return CALIB_CH_GROUP_2;
  605. if (channel >= CALIB_IL_TX_ATTEN_GR3_FCH &&
  606. channel <= CALIB_IL_TX_ATTEN_GR3_LCH)
  607. return CALIB_CH_GROUP_3;
  608. if (channel >= CALIB_IL_TX_ATTEN_GR4_FCH &&
  609. channel <= CALIB_IL_TX_ATTEN_GR4_LCH)
  610. return CALIB_CH_GROUP_4;
  611. return -EINVAL;
  612. }
  613. static u32
  614. il4965_get_sub_band(const struct il_priv *il, u32 channel)
  615. {
  616. s32 b = -1;
  617. for (b = 0; b < EEPROM_TX_POWER_BANDS; b++) {
  618. if (il->calib_info->band_info[b].ch_from == 0)
  619. continue;
  620. if (channel >= il->calib_info->band_info[b].ch_from &&
  621. channel <= il->calib_info->band_info[b].ch_to)
  622. break;
  623. }
  624. return b;
  625. }
  626. static s32
  627. il4965_interpolate_value(s32 x, s32 x1, s32 y1, s32 x2, s32 y2)
  628. {
  629. s32 val;
  630. if (x2 == x1)
  631. return y1;
  632. else {
  633. il4965_math_div_round((x2 - x) * (y1 - y2), (x2 - x1), &val);
  634. return val + y2;
  635. }
  636. }
  637. /**
  638. * il4965_interpolate_chan - Interpolate factory measurements for one channel
  639. *
  640. * Interpolates factory measurements from the two sample channels within a
  641. * sub-band, to apply to channel of interest. Interpolation is proportional to
  642. * differences in channel frequencies, which is proportional to differences
  643. * in channel number.
  644. */
  645. static int
  646. il4965_interpolate_chan(struct il_priv *il, u32 channel,
  647. struct il_eeprom_calib_ch_info *chan_info)
  648. {
  649. s32 s = -1;
  650. u32 c;
  651. u32 m;
  652. const struct il_eeprom_calib_measure *m1;
  653. const struct il_eeprom_calib_measure *m2;
  654. struct il_eeprom_calib_measure *omeas;
  655. u32 ch_i1;
  656. u32 ch_i2;
  657. s = il4965_get_sub_band(il, channel);
  658. if (s >= EEPROM_TX_POWER_BANDS) {
  659. IL_ERR("Tx Power can not find channel %d\n", channel);
  660. return -1;
  661. }
  662. ch_i1 = il->calib_info->band_info[s].ch1.ch_num;
  663. ch_i2 = il->calib_info->band_info[s].ch2.ch_num;
  664. chan_info->ch_num = (u8) channel;
  665. D_TXPOWER("channel %d subband %d factory cal ch %d & %d\n", channel, s,
  666. ch_i1, ch_i2);
  667. for (c = 0; c < EEPROM_TX_POWER_TX_CHAINS; c++) {
  668. for (m = 0; m < EEPROM_TX_POWER_MEASUREMENTS; m++) {
  669. m1 = &(il->calib_info->band_info[s].ch1.
  670. measurements[c][m]);
  671. m2 = &(il->calib_info->band_info[s].ch2.
  672. measurements[c][m]);
  673. omeas = &(chan_info->measurements[c][m]);
  674. omeas->actual_pow =
  675. (u8) il4965_interpolate_value(channel, ch_i1,
  676. m1->actual_pow, ch_i2,
  677. m2->actual_pow);
  678. omeas->gain_idx =
  679. (u8) il4965_interpolate_value(channel, ch_i1,
  680. m1->gain_idx, ch_i2,
  681. m2->gain_idx);
  682. omeas->temperature =
  683. (u8) il4965_interpolate_value(channel, ch_i1,
  684. m1->temperature,
  685. ch_i2,
  686. m2->temperature);
  687. omeas->pa_det =
  688. (s8) il4965_interpolate_value(channel, ch_i1,
  689. m1->pa_det, ch_i2,
  690. m2->pa_det);
  691. D_TXPOWER("chain %d meas %d AP1=%d AP2=%d AP=%d\n", c,
  692. m, m1->actual_pow, m2->actual_pow,
  693. omeas->actual_pow);
  694. D_TXPOWER("chain %d meas %d NI1=%d NI2=%d NI=%d\n", c,
  695. m, m1->gain_idx, m2->gain_idx,
  696. omeas->gain_idx);
  697. D_TXPOWER("chain %d meas %d PA1=%d PA2=%d PA=%d\n", c,
  698. m, m1->pa_det, m2->pa_det, omeas->pa_det);
  699. D_TXPOWER("chain %d meas %d T1=%d T2=%d T=%d\n", c,
  700. m, m1->temperature, m2->temperature,
  701. omeas->temperature);
  702. }
  703. }
  704. return 0;
  705. }
  706. /* bit-rate-dependent table to prevent Tx distortion, in half-dB units,
  707. * for OFDM 6, 12, 18, 24, 36, 48, 54, 60 MBit, and CCK all rates. */
  708. static s32 back_off_table[] = {
  709. 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM SISO 20 MHz */
  710. 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM MIMO 20 MHz */
  711. 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM SISO 40 MHz */
  712. 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM MIMO 40 MHz */
  713. 10 /* CCK */
  714. };
  715. /* Thermal compensation values for txpower for various frequency ranges ...
  716. * ratios from 3:1 to 4.5:1 of degrees (Celsius) per half-dB gain adjust */
  717. static struct il4965_txpower_comp_entry {
  718. s32 degrees_per_05db_a;
  719. s32 degrees_per_05db_a_denom;
  720. } tx_power_cmp_tble[CALIB_CH_GROUP_MAX] = {
  721. {
  722. 9, 2}, /* group 0 5.2, ch 34-43 */
  723. {
  724. 4, 1}, /* group 1 5.2, ch 44-70 */
  725. {
  726. 4, 1}, /* group 2 5.2, ch 71-124 */
  727. {
  728. 4, 1}, /* group 3 5.2, ch 125-200 */
  729. {
  730. 3, 1} /* group 4 2.4, ch all */
  731. };
  732. static s32
  733. get_min_power_idx(s32 rate_power_idx, u32 band)
  734. {
  735. if (!band) {
  736. if ((rate_power_idx & 7) <= 4)
  737. return MIN_TX_GAIN_IDX_52GHZ_EXT;
  738. }
  739. return MIN_TX_GAIN_IDX;
  740. }
  741. struct gain_entry {
  742. u8 dsp;
  743. u8 radio;
  744. };
  745. static const struct gain_entry gain_table[2][108] = {
  746. /* 5.2GHz power gain idx table */
  747. {
  748. {123, 0x3F}, /* highest txpower */
  749. {117, 0x3F},
  750. {110, 0x3F},
  751. {104, 0x3F},
  752. {98, 0x3F},
  753. {110, 0x3E},
  754. {104, 0x3E},
  755. {98, 0x3E},
  756. {110, 0x3D},
  757. {104, 0x3D},
  758. {98, 0x3D},
  759. {110, 0x3C},
  760. {104, 0x3C},
  761. {98, 0x3C},
  762. {110, 0x3B},
  763. {104, 0x3B},
  764. {98, 0x3B},
  765. {110, 0x3A},
  766. {104, 0x3A},
  767. {98, 0x3A},
  768. {110, 0x39},
  769. {104, 0x39},
  770. {98, 0x39},
  771. {110, 0x38},
  772. {104, 0x38},
  773. {98, 0x38},
  774. {110, 0x37},
  775. {104, 0x37},
  776. {98, 0x37},
  777. {110, 0x36},
  778. {104, 0x36},
  779. {98, 0x36},
  780. {110, 0x35},
  781. {104, 0x35},
  782. {98, 0x35},
  783. {110, 0x34},
  784. {104, 0x34},
  785. {98, 0x34},
  786. {110, 0x33},
  787. {104, 0x33},
  788. {98, 0x33},
  789. {110, 0x32},
  790. {104, 0x32},
  791. {98, 0x32},
  792. {110, 0x31},
  793. {104, 0x31},
  794. {98, 0x31},
  795. {110, 0x30},
  796. {104, 0x30},
  797. {98, 0x30},
  798. {110, 0x25},
  799. {104, 0x25},
  800. {98, 0x25},
  801. {110, 0x24},
  802. {104, 0x24},
  803. {98, 0x24},
  804. {110, 0x23},
  805. {104, 0x23},
  806. {98, 0x23},
  807. {110, 0x22},
  808. {104, 0x18},
  809. {98, 0x18},
  810. {110, 0x17},
  811. {104, 0x17},
  812. {98, 0x17},
  813. {110, 0x16},
  814. {104, 0x16},
  815. {98, 0x16},
  816. {110, 0x15},
  817. {104, 0x15},
  818. {98, 0x15},
  819. {110, 0x14},
  820. {104, 0x14},
  821. {98, 0x14},
  822. {110, 0x13},
  823. {104, 0x13},
  824. {98, 0x13},
  825. {110, 0x12},
  826. {104, 0x08},
  827. {98, 0x08},
  828. {110, 0x07},
  829. {104, 0x07},
  830. {98, 0x07},
  831. {110, 0x06},
  832. {104, 0x06},
  833. {98, 0x06},
  834. {110, 0x05},
  835. {104, 0x05},
  836. {98, 0x05},
  837. {110, 0x04},
  838. {104, 0x04},
  839. {98, 0x04},
  840. {110, 0x03},
  841. {104, 0x03},
  842. {98, 0x03},
  843. {110, 0x02},
  844. {104, 0x02},
  845. {98, 0x02},
  846. {110, 0x01},
  847. {104, 0x01},
  848. {98, 0x01},
  849. {110, 0x00},
  850. {104, 0x00},
  851. {98, 0x00},
  852. {93, 0x00},
  853. {88, 0x00},
  854. {83, 0x00},
  855. {78, 0x00},
  856. },
  857. /* 2.4GHz power gain idx table */
  858. {
  859. {110, 0x3f}, /* highest txpower */
  860. {104, 0x3f},
  861. {98, 0x3f},
  862. {110, 0x3e},
  863. {104, 0x3e},
  864. {98, 0x3e},
  865. {110, 0x3d},
  866. {104, 0x3d},
  867. {98, 0x3d},
  868. {110, 0x3c},
  869. {104, 0x3c},
  870. {98, 0x3c},
  871. {110, 0x3b},
  872. {104, 0x3b},
  873. {98, 0x3b},
  874. {110, 0x3a},
  875. {104, 0x3a},
  876. {98, 0x3a},
  877. {110, 0x39},
  878. {104, 0x39},
  879. {98, 0x39},
  880. {110, 0x38},
  881. {104, 0x38},
  882. {98, 0x38},
  883. {110, 0x37},
  884. {104, 0x37},
  885. {98, 0x37},
  886. {110, 0x36},
  887. {104, 0x36},
  888. {98, 0x36},
  889. {110, 0x35},
  890. {104, 0x35},
  891. {98, 0x35},
  892. {110, 0x34},
  893. {104, 0x34},
  894. {98, 0x34},
  895. {110, 0x33},
  896. {104, 0x33},
  897. {98, 0x33},
  898. {110, 0x32},
  899. {104, 0x32},
  900. {98, 0x32},
  901. {110, 0x31},
  902. {104, 0x31},
  903. {98, 0x31},
  904. {110, 0x30},
  905. {104, 0x30},
  906. {98, 0x30},
  907. {110, 0x6},
  908. {104, 0x6},
  909. {98, 0x6},
  910. {110, 0x5},
  911. {104, 0x5},
  912. {98, 0x5},
  913. {110, 0x4},
  914. {104, 0x4},
  915. {98, 0x4},
  916. {110, 0x3},
  917. {104, 0x3},
  918. {98, 0x3},
  919. {110, 0x2},
  920. {104, 0x2},
  921. {98, 0x2},
  922. {110, 0x1},
  923. {104, 0x1},
  924. {98, 0x1},
  925. {110, 0x0},
  926. {104, 0x0},
  927. {98, 0x0},
  928. {97, 0},
  929. {96, 0},
  930. {95, 0},
  931. {94, 0},
  932. {93, 0},
  933. {92, 0},
  934. {91, 0},
  935. {90, 0},
  936. {89, 0},
  937. {88, 0},
  938. {87, 0},
  939. {86, 0},
  940. {85, 0},
  941. {84, 0},
  942. {83, 0},
  943. {82, 0},
  944. {81, 0},
  945. {80, 0},
  946. {79, 0},
  947. {78, 0},
  948. {77, 0},
  949. {76, 0},
  950. {75, 0},
  951. {74, 0},
  952. {73, 0},
  953. {72, 0},
  954. {71, 0},
  955. {70, 0},
  956. {69, 0},
  957. {68, 0},
  958. {67, 0},
  959. {66, 0},
  960. {65, 0},
  961. {64, 0},
  962. {63, 0},
  963. {62, 0},
  964. {61, 0},
  965. {60, 0},
  966. {59, 0},
  967. }
  968. };
  969. static int
  970. il4965_fill_txpower_tbl(struct il_priv *il, u8 band, u16 channel, u8 is_ht40,
  971. u8 ctrl_chan_high,
  972. struct il4965_tx_power_db *tx_power_tbl)
  973. {
  974. u8 saturation_power;
  975. s32 target_power;
  976. s32 user_target_power;
  977. s32 power_limit;
  978. s32 current_temp;
  979. s32 reg_limit;
  980. s32 current_regulatory;
  981. s32 txatten_grp = CALIB_CH_GROUP_MAX;
  982. int i;
  983. int c;
  984. const struct il_channel_info *ch_info = NULL;
  985. struct il_eeprom_calib_ch_info ch_eeprom_info;
  986. const struct il_eeprom_calib_measure *measurement;
  987. s16 voltage;
  988. s32 init_voltage;
  989. s32 voltage_compensation;
  990. s32 degrees_per_05db_num;
  991. s32 degrees_per_05db_denom;
  992. s32 factory_temp;
  993. s32 temperature_comp[2];
  994. s32 factory_gain_idx[2];
  995. s32 factory_actual_pwr[2];
  996. s32 power_idx;
  997. /* tx_power_user_lmt is in dBm, convert to half-dBm (half-dB units
  998. * are used for idxing into txpower table) */
  999. user_target_power = 2 * il->tx_power_user_lmt;
  1000. /* Get current (RXON) channel, band, width */
  1001. D_TXPOWER("chan %d band %d is_ht40 %d\n", channel, band, is_ht40);
  1002. ch_info = il_get_channel_info(il, il->band, channel);
  1003. if (!il_is_channel_valid(ch_info))
  1004. return -EINVAL;
  1005. /* get txatten group, used to select 1) thermal txpower adjustment
  1006. * and 2) mimo txpower balance between Tx chains. */
  1007. txatten_grp = il4965_get_tx_atten_grp(channel);
  1008. if (txatten_grp < 0) {
  1009. IL_ERR("Can't find txatten group for channel %d.\n", channel);
  1010. return txatten_grp;
  1011. }
  1012. D_TXPOWER("channel %d belongs to txatten group %d\n", channel,
  1013. txatten_grp);
  1014. if (is_ht40) {
  1015. if (ctrl_chan_high)
  1016. channel -= 2;
  1017. else
  1018. channel += 2;
  1019. }
  1020. /* hardware txpower limits ...
  1021. * saturation (clipping distortion) txpowers are in half-dBm */
  1022. if (band)
  1023. saturation_power = il->calib_info->saturation_power24;
  1024. else
  1025. saturation_power = il->calib_info->saturation_power52;
  1026. if (saturation_power < IL_TX_POWER_SATURATION_MIN ||
  1027. saturation_power > IL_TX_POWER_SATURATION_MAX) {
  1028. if (band)
  1029. saturation_power = IL_TX_POWER_DEFAULT_SATURATION_24;
  1030. else
  1031. saturation_power = IL_TX_POWER_DEFAULT_SATURATION_52;
  1032. }
  1033. /* regulatory txpower limits ... reg_limit values are in half-dBm,
  1034. * max_power_avg values are in dBm, convert * 2 */
  1035. if (is_ht40)
  1036. reg_limit = ch_info->ht40_max_power_avg * 2;
  1037. else
  1038. reg_limit = ch_info->max_power_avg * 2;
  1039. if ((reg_limit < IL_TX_POWER_REGULATORY_MIN) ||
  1040. (reg_limit > IL_TX_POWER_REGULATORY_MAX)) {
  1041. if (band)
  1042. reg_limit = IL_TX_POWER_DEFAULT_REGULATORY_24;
  1043. else
  1044. reg_limit = IL_TX_POWER_DEFAULT_REGULATORY_52;
  1045. }
  1046. /* Interpolate txpower calibration values for this channel,
  1047. * based on factory calibration tests on spaced channels. */
  1048. il4965_interpolate_chan(il, channel, &ch_eeprom_info);
  1049. /* calculate tx gain adjustment based on power supply voltage */
  1050. voltage = le16_to_cpu(il->calib_info->voltage);
  1051. init_voltage = (s32) le32_to_cpu(il->card_alive_init.voltage);
  1052. voltage_compensation =
  1053. il4965_get_voltage_compensation(voltage, init_voltage);
  1054. D_TXPOWER("curr volt %d eeprom volt %d volt comp %d\n", init_voltage,
  1055. voltage, voltage_compensation);
  1056. /* get current temperature (Celsius) */
  1057. current_temp = max(il->temperature, IL_TX_POWER_TEMPERATURE_MIN);
  1058. current_temp = min(il->temperature, IL_TX_POWER_TEMPERATURE_MAX);
  1059. current_temp = KELVIN_TO_CELSIUS(current_temp);
  1060. /* select thermal txpower adjustment params, based on channel group
  1061. * (same frequency group used for mimo txatten adjustment) */
  1062. degrees_per_05db_num =
  1063. tx_power_cmp_tble[txatten_grp].degrees_per_05db_a;
  1064. degrees_per_05db_denom =
  1065. tx_power_cmp_tble[txatten_grp].degrees_per_05db_a_denom;
  1066. /* get per-chain txpower values from factory measurements */
  1067. for (c = 0; c < 2; c++) {
  1068. measurement = &ch_eeprom_info.measurements[c][1];
  1069. /* txgain adjustment (in half-dB steps) based on difference
  1070. * between factory and current temperature */
  1071. factory_temp = measurement->temperature;
  1072. il4965_math_div_round((current_temp -
  1073. factory_temp) * degrees_per_05db_denom,
  1074. degrees_per_05db_num,
  1075. &temperature_comp[c]);
  1076. factory_gain_idx[c] = measurement->gain_idx;
  1077. factory_actual_pwr[c] = measurement->actual_pow;
  1078. D_TXPOWER("chain = %d\n", c);
  1079. D_TXPOWER("fctry tmp %d, " "curr tmp %d, comp %d steps\n",
  1080. factory_temp, current_temp, temperature_comp[c]);
  1081. D_TXPOWER("fctry idx %d, fctry pwr %d\n", factory_gain_idx[c],
  1082. factory_actual_pwr[c]);
  1083. }
  1084. /* for each of 33 bit-rates (including 1 for CCK) */
  1085. for (i = 0; i < POWER_TBL_NUM_ENTRIES; i++) {
  1086. u8 is_mimo_rate;
  1087. union il4965_tx_power_dual_stream tx_power;
  1088. /* for mimo, reduce each chain's txpower by half
  1089. * (3dB, 6 steps), so total output power is regulatory
  1090. * compliant. */
  1091. if (i & 0x8) {
  1092. current_regulatory =
  1093. reg_limit -
  1094. IL_TX_POWER_MIMO_REGULATORY_COMPENSATION;
  1095. is_mimo_rate = 1;
  1096. } else {
  1097. current_regulatory = reg_limit;
  1098. is_mimo_rate = 0;
  1099. }
  1100. /* find txpower limit, either hardware or regulatory */
  1101. power_limit = saturation_power - back_off_table[i];
  1102. if (power_limit > current_regulatory)
  1103. power_limit = current_regulatory;
  1104. /* reduce user's txpower request if necessary
  1105. * for this rate on this channel */
  1106. target_power = user_target_power;
  1107. if (target_power > power_limit)
  1108. target_power = power_limit;
  1109. D_TXPOWER("rate %d sat %d reg %d usr %d tgt %d\n", i,
  1110. saturation_power - back_off_table[i],
  1111. current_regulatory, user_target_power, target_power);
  1112. /* for each of 2 Tx chains (radio transmitters) */
  1113. for (c = 0; c < 2; c++) {
  1114. s32 atten_value;
  1115. if (is_mimo_rate)
  1116. atten_value =
  1117. (s32) le32_to_cpu(il->card_alive_init.
  1118. tx_atten[txatten_grp][c]);
  1119. else
  1120. atten_value = 0;
  1121. /* calculate idx; higher idx means lower txpower */
  1122. power_idx =
  1123. (u8) (factory_gain_idx[c] -
  1124. (target_power - factory_actual_pwr[c]) -
  1125. temperature_comp[c] - voltage_compensation +
  1126. atten_value);
  1127. /* D_TXPOWER("calculated txpower idx %d\n",
  1128. power_idx); */
  1129. if (power_idx < get_min_power_idx(i, band))
  1130. power_idx = get_min_power_idx(i, band);
  1131. /* adjust 5 GHz idx to support negative idxes */
  1132. if (!band)
  1133. power_idx += 9;
  1134. /* CCK, rate 32, reduce txpower for CCK */
  1135. if (i == POWER_TBL_CCK_ENTRY)
  1136. power_idx +=
  1137. IL_TX_POWER_CCK_COMPENSATION_C_STEP;
  1138. /* stay within the table! */
  1139. if (power_idx > 107) {
  1140. IL_WARN("txpower idx %d > 107\n", power_idx);
  1141. power_idx = 107;
  1142. }
  1143. if (power_idx < 0) {
  1144. IL_WARN("txpower idx %d < 0\n", power_idx);
  1145. power_idx = 0;
  1146. }
  1147. /* fill txpower command for this rate/chain */
  1148. tx_power.s.radio_tx_gain[c] =
  1149. gain_table[band][power_idx].radio;
  1150. tx_power.s.dsp_predis_atten[c] =
  1151. gain_table[band][power_idx].dsp;
  1152. D_TXPOWER("chain %d mimo %d idx %d "
  1153. "gain 0x%02x dsp %d\n", c, atten_value,
  1154. power_idx, tx_power.s.radio_tx_gain[c],
  1155. tx_power.s.dsp_predis_atten[c]);
  1156. } /* for each chain */
  1157. tx_power_tbl->power_tbl[i].dw = cpu_to_le32(tx_power.dw);
  1158. } /* for each rate */
  1159. return 0;
  1160. }
  1161. /**
  1162. * il4965_send_tx_power - Configure the TXPOWER level user limit
  1163. *
  1164. * Uses the active RXON for channel, band, and characteristics (ht40, high)
  1165. * The power limit is taken from il->tx_power_user_lmt.
  1166. */
  1167. static int
  1168. il4965_send_tx_power(struct il_priv *il)
  1169. {
  1170. struct il4965_txpowertable_cmd cmd = { 0 };
  1171. int ret;
  1172. u8 band = 0;
  1173. bool is_ht40 = false;
  1174. u8 ctrl_chan_high = 0;
  1175. if (WARN_ONCE
  1176. (test_bit(S_SCAN_HW, &il->status),
  1177. "TX Power requested while scanning!\n"))
  1178. return -EAGAIN;
  1179. band = il->band == IEEE80211_BAND_2GHZ;
  1180. is_ht40 = iw4965_is_ht40_channel(il->active.flags);
  1181. if (is_ht40 && (il->active.flags & RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK))
  1182. ctrl_chan_high = 1;
  1183. cmd.band = band;
  1184. cmd.channel = il->active.channel;
  1185. ret =
  1186. il4965_fill_txpower_tbl(il, band, le16_to_cpu(il->active.channel),
  1187. is_ht40, ctrl_chan_high, &cmd.tx_power);
  1188. if (ret)
  1189. goto out;
  1190. ret = il_send_cmd_pdu(il, C_TX_PWR_TBL, sizeof(cmd), &cmd);
  1191. out:
  1192. return ret;
  1193. }
  1194. static int
  1195. il4965_send_rxon_assoc(struct il_priv *il)
  1196. {
  1197. int ret = 0;
  1198. struct il4965_rxon_assoc_cmd rxon_assoc;
  1199. const struct il_rxon_cmd *rxon1 = &il->staging;
  1200. const struct il_rxon_cmd *rxon2 = &il->active;
  1201. if (rxon1->flags == rxon2->flags &&
  1202. rxon1->filter_flags == rxon2->filter_flags &&
  1203. rxon1->cck_basic_rates == rxon2->cck_basic_rates &&
  1204. rxon1->ofdm_ht_single_stream_basic_rates ==
  1205. rxon2->ofdm_ht_single_stream_basic_rates &&
  1206. rxon1->ofdm_ht_dual_stream_basic_rates ==
  1207. rxon2->ofdm_ht_dual_stream_basic_rates &&
  1208. rxon1->rx_chain == rxon2->rx_chain &&
  1209. rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates) {
  1210. D_INFO("Using current RXON_ASSOC. Not resending.\n");
  1211. return 0;
  1212. }
  1213. rxon_assoc.flags = il->staging.flags;
  1214. rxon_assoc.filter_flags = il->staging.filter_flags;
  1215. rxon_assoc.ofdm_basic_rates = il->staging.ofdm_basic_rates;
  1216. rxon_assoc.cck_basic_rates = il->staging.cck_basic_rates;
  1217. rxon_assoc.reserved = 0;
  1218. rxon_assoc.ofdm_ht_single_stream_basic_rates =
  1219. il->staging.ofdm_ht_single_stream_basic_rates;
  1220. rxon_assoc.ofdm_ht_dual_stream_basic_rates =
  1221. il->staging.ofdm_ht_dual_stream_basic_rates;
  1222. rxon_assoc.rx_chain_select_flags = il->staging.rx_chain;
  1223. ret =
  1224. il_send_cmd_pdu_async(il, C_RXON_ASSOC, sizeof(rxon_assoc),
  1225. &rxon_assoc, NULL);
  1226. return ret;
  1227. }
  1228. static int
  1229. il4965_commit_rxon(struct il_priv *il)
  1230. {
  1231. /* cast away the const for active_rxon in this function */
  1232. struct il_rxon_cmd *active_rxon = (void *)&il->active;
  1233. int ret;
  1234. bool new_assoc = !!(il->staging.filter_flags & RXON_FILTER_ASSOC_MSK);
  1235. if (!il_is_alive(il))
  1236. return -EBUSY;
  1237. /* always get timestamp with Rx frame */
  1238. il->staging.flags |= RXON_FLG_TSF2HOST_MSK;
  1239. ret = il_check_rxon_cmd(il);
  1240. if (ret) {
  1241. IL_ERR("Invalid RXON configuration. Not committing.\n");
  1242. return -EINVAL;
  1243. }
  1244. /*
  1245. * receive commit_rxon request
  1246. * abort any previous channel switch if still in process
  1247. */
  1248. if (test_bit(S_CHANNEL_SWITCH_PENDING, &il->status) &&
  1249. il->switch_channel != il->staging.channel) {
  1250. D_11H("abort channel switch on %d\n",
  1251. le16_to_cpu(il->switch_channel));
  1252. il_chswitch_done(il, false);
  1253. }
  1254. /* If we don't need to send a full RXON, we can use
  1255. * il_rxon_assoc_cmd which is used to reconfigure filter
  1256. * and other flags for the current radio configuration. */
  1257. if (!il_full_rxon_required(il)) {
  1258. ret = il_send_rxon_assoc(il);
  1259. if (ret) {
  1260. IL_ERR("Error setting RXON_ASSOC (%d)\n", ret);
  1261. return ret;
  1262. }
  1263. memcpy(active_rxon, &il->staging, sizeof(*active_rxon));
  1264. il_print_rx_config_cmd(il);
  1265. /*
  1266. * We do not commit tx power settings while channel changing,
  1267. * do it now if tx power changed.
  1268. */
  1269. il_set_tx_power(il, il->tx_power_next, false);
  1270. return 0;
  1271. }
  1272. /* If we are currently associated and the new config requires
  1273. * an RXON_ASSOC and the new config wants the associated mask enabled,
  1274. * we must clear the associated from the active configuration
  1275. * before we apply the new config */
  1276. if (il_is_associated(il) && new_assoc) {
  1277. D_INFO("Toggling associated bit on current RXON\n");
  1278. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  1279. ret =
  1280. il_send_cmd_pdu(il, C_RXON,
  1281. sizeof(struct il_rxon_cmd), active_rxon);
  1282. /* If the mask clearing failed then we set
  1283. * active_rxon back to what it was previously */
  1284. if (ret) {
  1285. active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
  1286. IL_ERR("Error clearing ASSOC_MSK (%d)\n", ret);
  1287. return ret;
  1288. }
  1289. il_clear_ucode_stations(il);
  1290. il_restore_stations(il);
  1291. ret = il4965_restore_default_wep_keys(il);
  1292. if (ret) {
  1293. IL_ERR("Failed to restore WEP keys (%d)\n", ret);
  1294. return ret;
  1295. }
  1296. }
  1297. D_INFO("Sending RXON\n" "* with%s RXON_FILTER_ASSOC_MSK\n"
  1298. "* channel = %d\n" "* bssid = %pM\n", (new_assoc ? "" : "out"),
  1299. le16_to_cpu(il->staging.channel), il->staging.bssid_addr);
  1300. il_set_rxon_hwcrypto(il, !il->cfg->mod_params->sw_crypto);
  1301. /* Apply the new configuration
  1302. * RXON unassoc clears the station table in uCode so restoration of
  1303. * stations is needed after it (the RXON command) completes
  1304. */
  1305. if (!new_assoc) {
  1306. ret =
  1307. il_send_cmd_pdu(il, C_RXON,
  1308. sizeof(struct il_rxon_cmd), &il->staging);
  1309. if (ret) {
  1310. IL_ERR("Error setting new RXON (%d)\n", ret);
  1311. return ret;
  1312. }
  1313. D_INFO("Return from !new_assoc RXON.\n");
  1314. memcpy(active_rxon, &il->staging, sizeof(*active_rxon));
  1315. il_clear_ucode_stations(il);
  1316. il_restore_stations(il);
  1317. ret = il4965_restore_default_wep_keys(il);
  1318. if (ret) {
  1319. IL_ERR("Failed to restore WEP keys (%d)\n", ret);
  1320. return ret;
  1321. }
  1322. }
  1323. if (new_assoc) {
  1324. il->start_calib = 0;
  1325. /* Apply the new configuration
  1326. * RXON assoc doesn't clear the station table in uCode,
  1327. */
  1328. ret =
  1329. il_send_cmd_pdu(il, C_RXON,
  1330. sizeof(struct il_rxon_cmd), &il->staging);
  1331. if (ret) {
  1332. IL_ERR("Error setting new RXON (%d)\n", ret);
  1333. return ret;
  1334. }
  1335. memcpy(active_rxon, &il->staging, sizeof(*active_rxon));
  1336. }
  1337. il_print_rx_config_cmd(il);
  1338. il4965_init_sensitivity(il);
  1339. /* If we issue a new RXON command which required a tune then we must
  1340. * send a new TXPOWER command or we won't be able to Tx any frames */
  1341. ret = il_set_tx_power(il, il->tx_power_next, true);
  1342. if (ret) {
  1343. IL_ERR("Error sending TX power (%d)\n", ret);
  1344. return ret;
  1345. }
  1346. return 0;
  1347. }
  1348. static int
  1349. il4965_hw_channel_switch(struct il_priv *il,
  1350. struct ieee80211_channel_switch *ch_switch)
  1351. {
  1352. int rc;
  1353. u8 band = 0;
  1354. bool is_ht40 = false;
  1355. u8 ctrl_chan_high = 0;
  1356. struct il4965_channel_switch_cmd cmd;
  1357. const struct il_channel_info *ch_info;
  1358. u32 switch_time_in_usec, ucode_switch_time;
  1359. u16 ch;
  1360. u32 tsf_low;
  1361. u8 switch_count;
  1362. u16 beacon_interval = le16_to_cpu(il->timing.beacon_interval);
  1363. struct ieee80211_vif *vif = il->vif;
  1364. band = (il->band == IEEE80211_BAND_2GHZ);
  1365. if (WARN_ON_ONCE(vif == NULL))
  1366. return -EIO;
  1367. is_ht40 = iw4965_is_ht40_channel(il->staging.flags);
  1368. if (is_ht40 && (il->staging.flags & RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK))
  1369. ctrl_chan_high = 1;
  1370. cmd.band = band;
  1371. cmd.expect_beacon = 0;
  1372. ch = ch_switch->channel->hw_value;
  1373. cmd.channel = cpu_to_le16(ch);
  1374. cmd.rxon_flags = il->staging.flags;
  1375. cmd.rxon_filter_flags = il->staging.filter_flags;
  1376. switch_count = ch_switch->count;
  1377. tsf_low = ch_switch->timestamp & 0x0ffffffff;
  1378. /*
  1379. * calculate the ucode channel switch time
  1380. * adding TSF as one of the factor for when to switch
  1381. */
  1382. if (il->ucode_beacon_time > tsf_low && beacon_interval) {
  1383. if (switch_count >
  1384. ((il->ucode_beacon_time - tsf_low) / beacon_interval)) {
  1385. switch_count -=
  1386. (il->ucode_beacon_time - tsf_low) / beacon_interval;
  1387. } else
  1388. switch_count = 0;
  1389. }
  1390. if (switch_count <= 1)
  1391. cmd.switch_time = cpu_to_le32(il->ucode_beacon_time);
  1392. else {
  1393. switch_time_in_usec =
  1394. vif->bss_conf.beacon_int * switch_count * TIME_UNIT;
  1395. ucode_switch_time =
  1396. il_usecs_to_beacons(il, switch_time_in_usec,
  1397. beacon_interval);
  1398. cmd.switch_time =
  1399. il_add_beacon_time(il, il->ucode_beacon_time,
  1400. ucode_switch_time, beacon_interval);
  1401. }
  1402. D_11H("uCode time for the switch is 0x%x\n", cmd.switch_time);
  1403. ch_info = il_get_channel_info(il, il->band, ch);
  1404. if (ch_info)
  1405. cmd.expect_beacon = il_is_channel_radar(ch_info);
  1406. else {
  1407. IL_ERR("invalid channel switch from %u to %u\n",
  1408. il->active.channel, ch);
  1409. return -EFAULT;
  1410. }
  1411. rc = il4965_fill_txpower_tbl(il, band, ch, is_ht40, ctrl_chan_high,
  1412. &cmd.tx_power);
  1413. if (rc) {
  1414. D_11H("error:%d fill txpower_tbl\n", rc);
  1415. return rc;
  1416. }
  1417. return il_send_cmd_pdu(il, C_CHANNEL_SWITCH, sizeof(cmd), &cmd);
  1418. }
  1419. /**
  1420. * il4965_txq_update_byte_cnt_tbl - Set up entry in Tx byte-count array
  1421. */
  1422. static void
  1423. il4965_txq_update_byte_cnt_tbl(struct il_priv *il, struct il_tx_queue *txq,
  1424. u16 byte_cnt)
  1425. {
  1426. struct il4965_scd_bc_tbl *scd_bc_tbl = il->scd_bc_tbls.addr;
  1427. int txq_id = txq->q.id;
  1428. int write_ptr = txq->q.write_ptr;
  1429. int len = byte_cnt + IL_TX_CRC_SIZE + IL_TX_DELIMITER_SIZE;
  1430. __le16 bc_ent;
  1431. WARN_ON(len > 0xFFF || write_ptr >= TFD_QUEUE_SIZE_MAX);
  1432. bc_ent = cpu_to_le16(len & 0xFFF);
  1433. /* Set up byte count within first 256 entries */
  1434. scd_bc_tbl[txq_id].tfd_offset[write_ptr] = bc_ent;
  1435. /* If within first 64 entries, duplicate at end */
  1436. if (write_ptr < TFD_QUEUE_SIZE_BC_DUP)
  1437. scd_bc_tbl[txq_id].tfd_offset[TFD_QUEUE_SIZE_MAX + write_ptr] =
  1438. bc_ent;
  1439. }
  1440. /**
  1441. * il4965_hw_get_temperature - return the calibrated temperature (in Kelvin)
  1442. * @stats: Provides the temperature reading from the uCode
  1443. *
  1444. * A return of <0 indicates bogus data in the stats
  1445. */
  1446. static int
  1447. il4965_hw_get_temperature(struct il_priv *il)
  1448. {
  1449. s32 temperature;
  1450. s32 vt;
  1451. s32 R1, R2, R3;
  1452. u32 R4;
  1453. if (test_bit(S_TEMPERATURE, &il->status) &&
  1454. (il->_4965.stats.flag & STATS_REPLY_FLG_HT40_MODE_MSK)) {
  1455. D_TEMP("Running HT40 temperature calibration\n");
  1456. R1 = (s32) le32_to_cpu(il->card_alive_init.therm_r1[1]);
  1457. R2 = (s32) le32_to_cpu(il->card_alive_init.therm_r2[1]);
  1458. R3 = (s32) le32_to_cpu(il->card_alive_init.therm_r3[1]);
  1459. R4 = le32_to_cpu(il->card_alive_init.therm_r4[1]);
  1460. } else {
  1461. D_TEMP("Running temperature calibration\n");
  1462. R1 = (s32) le32_to_cpu(il->card_alive_init.therm_r1[0]);
  1463. R2 = (s32) le32_to_cpu(il->card_alive_init.therm_r2[0]);
  1464. R3 = (s32) le32_to_cpu(il->card_alive_init.therm_r3[0]);
  1465. R4 = le32_to_cpu(il->card_alive_init.therm_r4[0]);
  1466. }
  1467. /*
  1468. * Temperature is only 23 bits, so sign extend out to 32.
  1469. *
  1470. * NOTE If we haven't received a stats notification yet
  1471. * with an updated temperature, use R4 provided to us in the
  1472. * "initialize" ALIVE response.
  1473. */
  1474. if (!test_bit(S_TEMPERATURE, &il->status))
  1475. vt = sign_extend32(R4, 23);
  1476. else
  1477. vt = sign_extend32(le32_to_cpu
  1478. (il->_4965.stats.general.common.temperature),
  1479. 23);
  1480. D_TEMP("Calib values R[1-3]: %d %d %d R4: %d\n", R1, R2, R3, vt);
  1481. if (R3 == R1) {
  1482. IL_ERR("Calibration conflict R1 == R3\n");
  1483. return -1;
  1484. }
  1485. /* Calculate temperature in degrees Kelvin, adjust by 97%.
  1486. * Add offset to center the adjustment around 0 degrees Centigrade. */
  1487. temperature = TEMPERATURE_CALIB_A_VAL * (vt - R2);
  1488. temperature /= (R3 - R1);
  1489. temperature =
  1490. (temperature * 97) / 100 + TEMPERATURE_CALIB_KELVIN_OFFSET;
  1491. D_TEMP("Calibrated temperature: %dK, %dC\n", temperature,
  1492. KELVIN_TO_CELSIUS(temperature));
  1493. return temperature;
  1494. }
  1495. /* Adjust Txpower only if temperature variance is greater than threshold. */
  1496. #define IL_TEMPERATURE_THRESHOLD 3
  1497. /**
  1498. * il4965_is_temp_calib_needed - determines if new calibration is needed
  1499. *
  1500. * If the temperature changed has changed sufficiently, then a recalibration
  1501. * is needed.
  1502. *
  1503. * Assumes caller will replace il->last_temperature once calibration
  1504. * executed.
  1505. */
  1506. static int
  1507. il4965_is_temp_calib_needed(struct il_priv *il)
  1508. {
  1509. int temp_diff;
  1510. if (!test_bit(S_STATS, &il->status)) {
  1511. D_TEMP("Temperature not updated -- no stats.\n");
  1512. return 0;
  1513. }
  1514. temp_diff = il->temperature - il->last_temperature;
  1515. /* get absolute value */
  1516. if (temp_diff < 0) {
  1517. D_POWER("Getting cooler, delta %d\n", temp_diff);
  1518. temp_diff = -temp_diff;
  1519. } else if (temp_diff == 0)
  1520. D_POWER("Temperature unchanged\n");
  1521. else
  1522. D_POWER("Getting warmer, delta %d\n", temp_diff);
  1523. if (temp_diff < IL_TEMPERATURE_THRESHOLD) {
  1524. D_POWER(" => thermal txpower calib not needed\n");
  1525. return 0;
  1526. }
  1527. D_POWER(" => thermal txpower calib needed\n");
  1528. return 1;
  1529. }
  1530. static void
  1531. il4965_temperature_calib(struct il_priv *il)
  1532. {
  1533. s32 temp;
  1534. temp = il4965_hw_get_temperature(il);
  1535. if (IL_TX_POWER_TEMPERATURE_OUT_OF_RANGE(temp))
  1536. return;
  1537. if (il->temperature != temp) {
  1538. if (il->temperature)
  1539. D_TEMP("Temperature changed " "from %dC to %dC\n",
  1540. KELVIN_TO_CELSIUS(il->temperature),
  1541. KELVIN_TO_CELSIUS(temp));
  1542. else
  1543. D_TEMP("Temperature " "initialized to %dC\n",
  1544. KELVIN_TO_CELSIUS(temp));
  1545. }
  1546. il->temperature = temp;
  1547. set_bit(S_TEMPERATURE, &il->status);
  1548. if (!il->disable_tx_power_cal &&
  1549. unlikely(!test_bit(S_SCANNING, &il->status)) &&
  1550. il4965_is_temp_calib_needed(il))
  1551. queue_work(il->workqueue, &il->txpower_work);
  1552. }
  1553. static u16
  1554. il4965_get_hcmd_size(u8 cmd_id, u16 len)
  1555. {
  1556. switch (cmd_id) {
  1557. case C_RXON:
  1558. return (u16) sizeof(struct il4965_rxon_cmd);
  1559. default:
  1560. return len;
  1561. }
  1562. }
  1563. static u16
  1564. il4965_build_addsta_hcmd(const struct il_addsta_cmd *cmd, u8 * data)
  1565. {
  1566. struct il4965_addsta_cmd *addsta = (struct il4965_addsta_cmd *)data;
  1567. addsta->mode = cmd->mode;
  1568. memcpy(&addsta->sta, &cmd->sta, sizeof(struct sta_id_modify));
  1569. memcpy(&addsta->key, &cmd->key, sizeof(struct il4965_keyinfo));
  1570. addsta->station_flags = cmd->station_flags;
  1571. addsta->station_flags_msk = cmd->station_flags_msk;
  1572. addsta->tid_disable_tx = cmd->tid_disable_tx;
  1573. addsta->add_immediate_ba_tid = cmd->add_immediate_ba_tid;
  1574. addsta->remove_immediate_ba_tid = cmd->remove_immediate_ba_tid;
  1575. addsta->add_immediate_ba_ssn = cmd->add_immediate_ba_ssn;
  1576. addsta->sleep_tx_count = cmd->sleep_tx_count;
  1577. addsta->reserved1 = cpu_to_le16(0);
  1578. addsta->reserved2 = cpu_to_le16(0);
  1579. return (u16) sizeof(struct il4965_addsta_cmd);
  1580. }
  1581. static inline u32
  1582. il4965_get_scd_ssn(struct il4965_tx_resp *tx_resp)
  1583. {
  1584. return le32_to_cpup(&tx_resp->u.status + tx_resp->frame_count) & MAX_SN;
  1585. }
  1586. static inline u32
  1587. il4965_tx_status_to_mac80211(u32 status)
  1588. {
  1589. status &= TX_STATUS_MSK;
  1590. switch (status) {
  1591. case TX_STATUS_SUCCESS:
  1592. case TX_STATUS_DIRECT_DONE:
  1593. return IEEE80211_TX_STAT_ACK;
  1594. case TX_STATUS_FAIL_DEST_PS:
  1595. return IEEE80211_TX_STAT_TX_FILTERED;
  1596. default:
  1597. return 0;
  1598. }
  1599. }
  1600. static inline bool
  1601. il4965_is_tx_success(u32 status)
  1602. {
  1603. status &= TX_STATUS_MSK;
  1604. return (status == TX_STATUS_SUCCESS || status == TX_STATUS_DIRECT_DONE);
  1605. }
  1606. /**
  1607. * il4965_tx_status_reply_tx - Handle Tx response for frames in aggregation queue
  1608. */
  1609. static int
  1610. il4965_tx_status_reply_tx(struct il_priv *il, struct il_ht_agg *agg,
  1611. struct il4965_tx_resp *tx_resp, int txq_id,
  1612. u16 start_idx)
  1613. {
  1614. u16 status;
  1615. struct agg_tx_status *frame_status = tx_resp->u.agg_status;
  1616. struct ieee80211_tx_info *info = NULL;
  1617. struct ieee80211_hdr *hdr = NULL;
  1618. u32 rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
  1619. int i, sh, idx;
  1620. u16 seq;
  1621. if (agg->wait_for_ba)
  1622. D_TX_REPLY("got tx response w/o block-ack\n");
  1623. agg->frame_count = tx_resp->frame_count;
  1624. agg->start_idx = start_idx;
  1625. agg->rate_n_flags = rate_n_flags;
  1626. agg->bitmap = 0;
  1627. /* num frames attempted by Tx command */
  1628. if (agg->frame_count == 1) {
  1629. /* Only one frame was attempted; no block-ack will arrive */
  1630. status = le16_to_cpu(frame_status[0].status);
  1631. idx = start_idx;
  1632. D_TX_REPLY("FrameCnt = %d, StartIdx=%d idx=%d\n",
  1633. agg->frame_count, agg->start_idx, idx);
  1634. info = IEEE80211_SKB_CB(il->txq[txq_id].skbs[idx]);
  1635. info->status.rates[0].count = tx_resp->failure_frame + 1;
  1636. info->flags &= ~IEEE80211_TX_CTL_AMPDU;
  1637. info->flags |= il4965_tx_status_to_mac80211(status);
  1638. il4965_hwrate_to_tx_control(il, rate_n_flags, info);
  1639. D_TX_REPLY("1 Frame 0x%x failure :%d\n", status & 0xff,
  1640. tx_resp->failure_frame);
  1641. D_TX_REPLY("Rate Info rate_n_flags=%x\n", rate_n_flags);
  1642. agg->wait_for_ba = 0;
  1643. } else {
  1644. /* Two or more frames were attempted; expect block-ack */
  1645. u64 bitmap = 0;
  1646. int start = agg->start_idx;
  1647. struct sk_buff *skb;
  1648. /* Construct bit-map of pending frames within Tx win */
  1649. for (i = 0; i < agg->frame_count; i++) {
  1650. u16 sc;
  1651. status = le16_to_cpu(frame_status[i].status);
  1652. seq = le16_to_cpu(frame_status[i].sequence);
  1653. idx = SEQ_TO_IDX(seq);
  1654. txq_id = SEQ_TO_QUEUE(seq);
  1655. if (status &
  1656. (AGG_TX_STATE_FEW_BYTES_MSK |
  1657. AGG_TX_STATE_ABORT_MSK))
  1658. continue;
  1659. D_TX_REPLY("FrameCnt = %d, txq_id=%d idx=%d\n",
  1660. agg->frame_count, txq_id, idx);
  1661. skb = il->txq[txq_id].skbs[idx];
  1662. if (WARN_ON_ONCE(skb == NULL))
  1663. return -1;
  1664. hdr = (struct ieee80211_hdr *) skb->data;
  1665. sc = le16_to_cpu(hdr->seq_ctrl);
  1666. if (idx != (SEQ_TO_SN(sc) & 0xff)) {
  1667. IL_ERR("BUG_ON idx doesn't match seq control"
  1668. " idx=%d, seq_idx=%d, seq=%d\n", idx,
  1669. SEQ_TO_SN(sc), hdr->seq_ctrl);
  1670. return -1;
  1671. }
  1672. D_TX_REPLY("AGG Frame i=%d idx %d seq=%d\n", i, idx,
  1673. SEQ_TO_SN(sc));
  1674. sh = idx - start;
  1675. if (sh > 64) {
  1676. sh = (start - idx) + 0xff;
  1677. bitmap = bitmap << sh;
  1678. sh = 0;
  1679. start = idx;
  1680. } else if (sh < -64)
  1681. sh = 0xff - (start - idx);
  1682. else if (sh < 0) {
  1683. sh = start - idx;
  1684. start = idx;
  1685. bitmap = bitmap << sh;
  1686. sh = 0;
  1687. }
  1688. bitmap |= 1ULL << sh;
  1689. D_TX_REPLY("start=%d bitmap=0x%llx\n", start,
  1690. (unsigned long long)bitmap);
  1691. }
  1692. agg->bitmap = bitmap;
  1693. agg->start_idx = start;
  1694. D_TX_REPLY("Frames %d start_idx=%d bitmap=0x%llx\n",
  1695. agg->frame_count, agg->start_idx,
  1696. (unsigned long long)agg->bitmap);
  1697. if (bitmap)
  1698. agg->wait_for_ba = 1;
  1699. }
  1700. return 0;
  1701. }
  1702. static u8
  1703. il4965_find_station(struct il_priv *il, const u8 * addr)
  1704. {
  1705. int i;
  1706. int start = 0;
  1707. int ret = IL_INVALID_STATION;
  1708. unsigned long flags;
  1709. if ((il->iw_mode == NL80211_IFTYPE_ADHOC))
  1710. start = IL_STA_ID;
  1711. if (is_broadcast_ether_addr(addr))
  1712. return il->hw_params.bcast_id;
  1713. spin_lock_irqsave(&il->sta_lock, flags);
  1714. for (i = start; i < il->hw_params.max_stations; i++)
  1715. if (il->stations[i].used &&
  1716. (!compare_ether_addr(il->stations[i].sta.sta.addr, addr))) {
  1717. ret = i;
  1718. goto out;
  1719. }
  1720. D_ASSOC("can not find STA %pM total %d\n", addr, il->num_stations);
  1721. out:
  1722. /*
  1723. * It may be possible that more commands interacting with stations
  1724. * arrive before we completed processing the adding of
  1725. * station
  1726. */
  1727. if (ret != IL_INVALID_STATION &&
  1728. (!(il->stations[ret].used & IL_STA_UCODE_ACTIVE) ||
  1729. ((il->stations[ret].used & IL_STA_UCODE_ACTIVE) &&
  1730. (il->stations[ret].used & IL_STA_UCODE_INPROGRESS)))) {
  1731. IL_ERR("Requested station info for sta %d before ready.\n",
  1732. ret);
  1733. ret = IL_INVALID_STATION;
  1734. }
  1735. spin_unlock_irqrestore(&il->sta_lock, flags);
  1736. return ret;
  1737. }
  1738. static int
  1739. il4965_get_ra_sta_id(struct il_priv *il, struct ieee80211_hdr *hdr)
  1740. {
  1741. if (il->iw_mode == NL80211_IFTYPE_STATION) {
  1742. return IL_AP_ID;
  1743. } else {
  1744. u8 *da = ieee80211_get_DA(hdr);
  1745. return il4965_find_station(il, da);
  1746. }
  1747. }
  1748. /**
  1749. * il4965_hdl_tx - Handle standard (non-aggregation) Tx response
  1750. */
  1751. static void
  1752. il4965_hdl_tx(struct il_priv *il, struct il_rx_buf *rxb)
  1753. {
  1754. struct il_rx_pkt *pkt = rxb_addr(rxb);
  1755. u16 sequence = le16_to_cpu(pkt->hdr.sequence);
  1756. int txq_id = SEQ_TO_QUEUE(sequence);
  1757. int idx = SEQ_TO_IDX(sequence);
  1758. struct il_tx_queue *txq = &il->txq[txq_id];
  1759. struct sk_buff *skb;
  1760. struct ieee80211_hdr *hdr;
  1761. struct ieee80211_tx_info *info;
  1762. struct il4965_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
  1763. u32 status = le32_to_cpu(tx_resp->u.status);
  1764. int uninitialized_var(tid);
  1765. int sta_id;
  1766. int freed;
  1767. u8 *qc = NULL;
  1768. unsigned long flags;
  1769. if (idx >= txq->q.n_bd || il_queue_used(&txq->q, idx) == 0) {
  1770. IL_ERR("Read idx for DMA queue txq_id (%d) idx %d "
  1771. "is out of range [0-%d] %d %d\n", txq_id, idx,
  1772. txq->q.n_bd, txq->q.write_ptr, txq->q.read_ptr);
  1773. return;
  1774. }
  1775. txq->time_stamp = jiffies;
  1776. skb = txq->skbs[txq->q.read_ptr];
  1777. info = IEEE80211_SKB_CB(skb);
  1778. memset(&info->status, 0, sizeof(info->status));
  1779. hdr = (struct ieee80211_hdr *) skb->data;
  1780. if (ieee80211_is_data_qos(hdr->frame_control)) {
  1781. qc = ieee80211_get_qos_ctl(hdr);
  1782. tid = qc[0] & 0xf;
  1783. }
  1784. sta_id = il4965_get_ra_sta_id(il, hdr);
  1785. if (txq->sched_retry && unlikely(sta_id == IL_INVALID_STATION)) {
  1786. IL_ERR("Station not known\n");
  1787. return;
  1788. }
  1789. spin_lock_irqsave(&il->sta_lock, flags);
  1790. if (txq->sched_retry) {
  1791. const u32 scd_ssn = il4965_get_scd_ssn(tx_resp);
  1792. struct il_ht_agg *agg = NULL;
  1793. WARN_ON(!qc);
  1794. agg = &il->stations[sta_id].tid[tid].agg;
  1795. il4965_tx_status_reply_tx(il, agg, tx_resp, txq_id, idx);
  1796. /* check if BAR is needed */
  1797. if ((tx_resp->frame_count == 1) &&
  1798. !il4965_is_tx_success(status))
  1799. info->flags |= IEEE80211_TX_STAT_AMPDU_NO_BACK;
  1800. if (txq->q.read_ptr != (scd_ssn & 0xff)) {
  1801. idx = il_queue_dec_wrap(scd_ssn & 0xff, txq->q.n_bd);
  1802. D_TX_REPLY("Retry scheduler reclaim scd_ssn "
  1803. "%d idx %d\n", scd_ssn, idx);
  1804. freed = il4965_tx_queue_reclaim(il, txq_id, idx);
  1805. if (qc)
  1806. il4965_free_tfds_in_queue(il, sta_id, tid,
  1807. freed);
  1808. if (il->mac80211_registered &&
  1809. il_queue_space(&txq->q) > txq->q.low_mark &&
  1810. agg->state != IL_EMPTYING_HW_QUEUE_DELBA)
  1811. il_wake_queue(il, txq);
  1812. }
  1813. } else {
  1814. info->status.rates[0].count = tx_resp->failure_frame + 1;
  1815. info->flags |= il4965_tx_status_to_mac80211(status);
  1816. il4965_hwrate_to_tx_control(il,
  1817. le32_to_cpu(tx_resp->rate_n_flags),
  1818. info);
  1819. D_TX_REPLY("TXQ %d status %s (0x%08x) "
  1820. "rate_n_flags 0x%x retries %d\n", txq_id,
  1821. il4965_get_tx_fail_reason(status), status,
  1822. le32_to_cpu(tx_resp->rate_n_flags),
  1823. tx_resp->failure_frame);
  1824. freed = il4965_tx_queue_reclaim(il, txq_id, idx);
  1825. if (qc && likely(sta_id != IL_INVALID_STATION))
  1826. il4965_free_tfds_in_queue(il, sta_id, tid, freed);
  1827. else if (sta_id == IL_INVALID_STATION)
  1828. D_TX_REPLY("Station not known\n");
  1829. if (il->mac80211_registered &&
  1830. il_queue_space(&txq->q) > txq->q.low_mark)
  1831. il_wake_queue(il, txq);
  1832. }
  1833. if (qc && likely(sta_id != IL_INVALID_STATION))
  1834. il4965_txq_check_empty(il, sta_id, tid, txq_id);
  1835. il4965_check_abort_status(il, tx_resp->frame_count, status);
  1836. spin_unlock_irqrestore(&il->sta_lock, flags);
  1837. }
  1838. /* Set up 4965-specific Rx frame reply handlers */
  1839. static void
  1840. il4965_handler_setup(struct il_priv *il)
  1841. {
  1842. /* Legacy Rx frames */
  1843. il->handlers[N_RX] = il4965_hdl_rx;
  1844. /* Tx response */
  1845. il->handlers[C_TX] = il4965_hdl_tx;
  1846. }
  1847. static struct il_hcmd_ops il4965_hcmd = {
  1848. .rxon_assoc = il4965_send_rxon_assoc,
  1849. .commit_rxon = il4965_commit_rxon,
  1850. .set_rxon_chain = il4965_set_rxon_chain,
  1851. };
  1852. static void
  1853. il4965_post_scan(struct il_priv *il)
  1854. {
  1855. /*
  1856. * Since setting the RXON may have been deferred while
  1857. * performing the scan, fire one off if needed
  1858. */
  1859. if (memcmp(&il->staging, &il->active, sizeof(il->staging)))
  1860. il_commit_rxon(il);
  1861. }
  1862. static void
  1863. il4965_post_associate(struct il_priv *il)
  1864. {
  1865. struct ieee80211_vif *vif = il->vif;
  1866. struct ieee80211_conf *conf = NULL;
  1867. int ret = 0;
  1868. if (!vif || !il->is_open)
  1869. return;
  1870. if (test_bit(S_EXIT_PENDING, &il->status))
  1871. return;
  1872. il_scan_cancel_timeout(il, 200);
  1873. conf = &il->hw->conf;
  1874. il->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  1875. il_commit_rxon(il);
  1876. ret = il_send_rxon_timing(il);
  1877. if (ret)
  1878. IL_WARN("RXON timing - " "Attempting to continue.\n");
  1879. il->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
  1880. il_set_rxon_ht(il, &il->current_ht_config);
  1881. if (il->ops->hcmd->set_rxon_chain)
  1882. il->ops->hcmd->set_rxon_chain(il);
  1883. il->staging.assoc_id = cpu_to_le16(vif->bss_conf.aid);
  1884. D_ASSOC("assoc id %d beacon interval %d\n", vif->bss_conf.aid,
  1885. vif->bss_conf.beacon_int);
  1886. if (vif->bss_conf.use_short_preamble)
  1887. il->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  1888. else
  1889. il->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  1890. if (il->staging.flags & RXON_FLG_BAND_24G_MSK) {
  1891. if (vif->bss_conf.use_short_slot)
  1892. il->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
  1893. else
  1894. il->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  1895. }
  1896. il_commit_rxon(il);
  1897. D_ASSOC("Associated as %d to: %pM\n", vif->bss_conf.aid,
  1898. il->active.bssid_addr);
  1899. switch (vif->type) {
  1900. case NL80211_IFTYPE_STATION:
  1901. break;
  1902. case NL80211_IFTYPE_ADHOC:
  1903. il4965_send_beacon_cmd(il);
  1904. break;
  1905. default:
  1906. IL_ERR("%s Should not be called in %d mode\n", __func__,
  1907. vif->type);
  1908. break;
  1909. }
  1910. /* the chain noise calibration will enabled PM upon completion
  1911. * If chain noise has already been run, then we need to enable
  1912. * power management here */
  1913. if (il->chain_noise_data.state == IL_CHAIN_NOISE_DONE)
  1914. il_power_update_mode(il, false);
  1915. /* Enable Rx differential gain and sensitivity calibrations */
  1916. il4965_chain_noise_reset(il);
  1917. il->start_calib = 1;
  1918. }
  1919. static void
  1920. il4965_config_ap(struct il_priv *il)
  1921. {
  1922. struct ieee80211_vif *vif = il->vif;
  1923. int ret = 0;
  1924. lockdep_assert_held(&il->mutex);
  1925. if (test_bit(S_EXIT_PENDING, &il->status))
  1926. return;
  1927. /* The following should be done only at AP bring up */
  1928. if (!il_is_associated(il)) {
  1929. /* RXON - unassoc (to set timing command) */
  1930. il->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  1931. il_commit_rxon(il);
  1932. /* RXON Timing */
  1933. ret = il_send_rxon_timing(il);
  1934. if (ret)
  1935. IL_WARN("RXON timing failed - "
  1936. "Attempting to continue.\n");
  1937. /* AP has all antennas */
  1938. il->chain_noise_data.active_chains = il->hw_params.valid_rx_ant;
  1939. il_set_rxon_ht(il, &il->current_ht_config);
  1940. if (il->ops->hcmd->set_rxon_chain)
  1941. il->ops->hcmd->set_rxon_chain(il);
  1942. il->staging.assoc_id = 0;
  1943. if (vif->bss_conf.use_short_preamble)
  1944. il->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  1945. else
  1946. il->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  1947. if (il->staging.flags & RXON_FLG_BAND_24G_MSK) {
  1948. if (vif->bss_conf.use_short_slot)
  1949. il->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
  1950. else
  1951. il->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  1952. }
  1953. /* need to send beacon cmd before committing assoc RXON! */
  1954. il4965_send_beacon_cmd(il);
  1955. /* restore RXON assoc */
  1956. il->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
  1957. il_commit_rxon(il);
  1958. }
  1959. il4965_send_beacon_cmd(il);
  1960. }
  1961. static struct il_hcmd_utils_ops il4965_hcmd_utils = {
  1962. .get_hcmd_size = il4965_get_hcmd_size,
  1963. .build_addsta_hcmd = il4965_build_addsta_hcmd,
  1964. .request_scan = il4965_request_scan,
  1965. .post_scan = il4965_post_scan,
  1966. };
  1967. static struct il_lib_ops il4965_lib = {
  1968. .set_hw_params = il4965_hw_set_hw_params,
  1969. .txq_update_byte_cnt_tbl = il4965_txq_update_byte_cnt_tbl,
  1970. .txq_attach_buf_to_tfd = il4965_hw_txq_attach_buf_to_tfd,
  1971. .txq_free_tfd = il4965_hw_txq_free_tfd,
  1972. .txq_init = il4965_hw_tx_queue_init,
  1973. .handler_setup = il4965_handler_setup,
  1974. .is_valid_rtc_data_addr = il4965_hw_valid_rtc_data_addr,
  1975. .init_alive_start = il4965_init_alive_start,
  1976. .load_ucode = il4965_load_bsm,
  1977. .dump_nic_error_log = il4965_dump_nic_error_log,
  1978. .dump_fh = il4965_dump_fh,
  1979. .set_channel_switch = il4965_hw_channel_switch,
  1980. .apm_ops = {
  1981. .init = il_apm_init,
  1982. .config = il4965_nic_config,
  1983. },
  1984. .eeprom_ops = {
  1985. .regulatory_bands = {
  1986. EEPROM_REGULATORY_BAND_1_CHANNELS,
  1987. EEPROM_REGULATORY_BAND_2_CHANNELS,
  1988. EEPROM_REGULATORY_BAND_3_CHANNELS,
  1989. EEPROM_REGULATORY_BAND_4_CHANNELS,
  1990. EEPROM_REGULATORY_BAND_5_CHANNELS,
  1991. EEPROM_4965_REGULATORY_BAND_24_HT40_CHANNELS,
  1992. EEPROM_4965_REGULATORY_BAND_52_HT40_CHANNELS},
  1993. .acquire_semaphore = il4965_eeprom_acquire_semaphore,
  1994. .release_semaphore = il4965_eeprom_release_semaphore,
  1995. },
  1996. .send_tx_power = il4965_send_tx_power,
  1997. .update_chain_flags = il4965_update_chain_flags,
  1998. .temp_ops = {
  1999. .temperature = il4965_temperature_calib,
  2000. },
  2001. #ifdef CONFIG_IWLEGACY_DEBUGFS
  2002. .debugfs_ops = {
  2003. .rx_stats_read = il4965_ucode_rx_stats_read,
  2004. .tx_stats_read = il4965_ucode_tx_stats_read,
  2005. .general_stats_read = il4965_ucode_general_stats_read,
  2006. },
  2007. #endif
  2008. };
  2009. static const struct il_legacy_ops il4965_legacy_ops = {
  2010. .post_associate = il4965_post_associate,
  2011. .config_ap = il4965_config_ap,
  2012. .manage_ibss_station = il4965_manage_ibss_station,
  2013. .update_bcast_stations = il4965_update_bcast_stations,
  2014. };
  2015. const struct il_ops il4965_ops = {
  2016. .lib = &il4965_lib,
  2017. .hcmd = &il4965_hcmd,
  2018. .utils = &il4965_hcmd_utils,
  2019. .led = &il4965_led_ops,
  2020. .legacy = &il4965_legacy_ops,
  2021. };
  2022. struct il_cfg il4965_cfg = {
  2023. .name = "Intel(R) Wireless WiFi Link 4965AGN",
  2024. .fw_name_pre = IL4965_FW_PRE,
  2025. .ucode_api_max = IL4965_UCODE_API_MAX,
  2026. .ucode_api_min = IL4965_UCODE_API_MIN,
  2027. .sku = IL_SKU_A | IL_SKU_G | IL_SKU_N,
  2028. .valid_tx_ant = ANT_AB,
  2029. .valid_rx_ant = ANT_ABC,
  2030. .eeprom_ver = EEPROM_4965_EEPROM_VERSION,
  2031. .eeprom_calib_ver = EEPROM_4965_TX_POWER_VERSION,
  2032. .mod_params = &il4965_mod_params,
  2033. .led_mode = IL_LED_BLINK,
  2034. /*
  2035. * Force use of chains B and C for scan RX on 5 GHz band
  2036. * because the device has off-channel reception on chain A.
  2037. */
  2038. .scan_rx_antennas[IEEE80211_BAND_5GHZ] = ANT_BC,
  2039. .eeprom_size = IL4965_EEPROM_IMG_SIZE,
  2040. .num_of_queues = IL49_NUM_QUEUES,
  2041. .num_of_ampdu_queues = IL49_NUM_AMPDU_QUEUES,
  2042. .pll_cfg_val = 0,
  2043. .set_l0s = true,
  2044. .use_bsm = true,
  2045. .led_compensation = 61,
  2046. .chain_noise_num_beacons = IL4965_CAL_NUM_BEACONS,
  2047. .wd_timeout = IL_DEF_WD_TIMEOUT,
  2048. .temperature_kelvin = true,
  2049. .ucode_tracing = true,
  2050. .sensitivity_calib_by_driver = true,
  2051. .chain_noise_calib_by_driver = true,
  2052. };
  2053. /* Module firmware */
  2054. MODULE_FIRMWARE(IL4965_MODULE_FIRMWARE(IL4965_UCODE_API_MAX));