iwl-5000.c 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2009 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 Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  23. *
  24. *****************************************************************************/
  25. #include <linux/kernel.h>
  26. #include <linux/module.h>
  27. #include <linux/init.h>
  28. #include <linux/pci.h>
  29. #include <linux/dma-mapping.h>
  30. #include <linux/delay.h>
  31. #include <linux/skbuff.h>
  32. #include <linux/netdevice.h>
  33. #include <linux/wireless.h>
  34. #include <net/mac80211.h>
  35. #include <linux/etherdevice.h>
  36. #include <asm/unaligned.h>
  37. #include "iwl-eeprom.h"
  38. #include "iwl-dev.h"
  39. #include "iwl-core.h"
  40. #include "iwl-io.h"
  41. #include "iwl-sta.h"
  42. #include "iwl-helpers.h"
  43. #include "iwl-5000-hw.h"
  44. #include "iwl-6000-hw.h"
  45. /* Highest firmware API version supported */
  46. #define IWL5000_UCODE_API_MAX 2
  47. #define IWL5150_UCODE_API_MAX 2
  48. /* Lowest firmware API version supported */
  49. #define IWL5000_UCODE_API_MIN 1
  50. #define IWL5150_UCODE_API_MIN 1
  51. #define IWL5000_FW_PRE "iwlwifi-5000-"
  52. #define _IWL5000_MODULE_FIRMWARE(api) IWL5000_FW_PRE #api ".ucode"
  53. #define IWL5000_MODULE_FIRMWARE(api) _IWL5000_MODULE_FIRMWARE(api)
  54. #define IWL5150_FW_PRE "iwlwifi-5150-"
  55. #define _IWL5150_MODULE_FIRMWARE(api) IWL5150_FW_PRE #api ".ucode"
  56. #define IWL5150_MODULE_FIRMWARE(api) _IWL5150_MODULE_FIRMWARE(api)
  57. static const u16 iwl5000_default_queue_to_tx_fifo[] = {
  58. IWL_TX_FIFO_AC3,
  59. IWL_TX_FIFO_AC2,
  60. IWL_TX_FIFO_AC1,
  61. IWL_TX_FIFO_AC0,
  62. IWL50_CMD_FIFO_NUM,
  63. IWL_TX_FIFO_HCCA_1,
  64. IWL_TX_FIFO_HCCA_2
  65. };
  66. /* FIXME: same implementation as 4965 */
  67. static int iwl5000_apm_stop_master(struct iwl_priv *priv)
  68. {
  69. unsigned long flags;
  70. spin_lock_irqsave(&priv->lock, flags);
  71. /* set stop master bit */
  72. iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER);
  73. iwl_poll_direct_bit(priv, CSR_RESET,
  74. CSR_RESET_REG_FLAG_MASTER_DISABLED, 100);
  75. spin_unlock_irqrestore(&priv->lock, flags);
  76. IWL_DEBUG_INFO(priv, "stop master\n");
  77. return 0;
  78. }
  79. static int iwl5000_apm_init(struct iwl_priv *priv)
  80. {
  81. int ret = 0;
  82. iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
  83. CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
  84. /* disable L0s without affecting L1 :don't wait for ICH L0s bug W/A) */
  85. iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
  86. CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX);
  87. /* Set FH wait threshold to maximum (HW error during stress W/A) */
  88. iwl_set_bit(priv, CSR_DBG_HPET_MEM_REG, CSR_DBG_HPET_MEM_REG_VAL);
  89. /* enable HAP INTA to move device L1a -> L0s */
  90. iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
  91. CSR_HW_IF_CONFIG_REG_BIT_HAP_WAKE_L1A);
  92. if (priv->cfg->need_pll_cfg)
  93. iwl_set_bit(priv, CSR_ANA_PLL_CFG, CSR50_ANA_PLL_CFG_VAL);
  94. /* set "initialization complete" bit to move adapter
  95. * D0U* --> D0A* state */
  96. iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  97. /* wait for clock stabilization */
  98. ret = iwl_poll_direct_bit(priv, CSR_GP_CNTRL,
  99. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
  100. if (ret < 0) {
  101. IWL_DEBUG_INFO(priv, "Failed to init the card\n");
  102. return ret;
  103. }
  104. /* enable DMA */
  105. iwl_write_prph(priv, APMG_CLK_EN_REG, APMG_CLK_VAL_DMA_CLK_RQT);
  106. udelay(20);
  107. /* disable L1-Active */
  108. iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
  109. APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
  110. return ret;
  111. }
  112. /* FIXME: this is identical to 4965 */
  113. static void iwl5000_apm_stop(struct iwl_priv *priv)
  114. {
  115. unsigned long flags;
  116. iwl5000_apm_stop_master(priv);
  117. spin_lock_irqsave(&priv->lock, flags);
  118. iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
  119. udelay(10);
  120. /* clear "init complete" move adapter D0A* --> D0U state */
  121. iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  122. spin_unlock_irqrestore(&priv->lock, flags);
  123. }
  124. static int iwl5000_apm_reset(struct iwl_priv *priv)
  125. {
  126. int ret = 0;
  127. iwl5000_apm_stop_master(priv);
  128. iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
  129. udelay(10);
  130. /* FIXME: put here L1A -L0S w/a */
  131. if (priv->cfg->need_pll_cfg)
  132. iwl_set_bit(priv, CSR_ANA_PLL_CFG, CSR50_ANA_PLL_CFG_VAL);
  133. /* set "initialization complete" bit to move adapter
  134. * D0U* --> D0A* state */
  135. iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  136. /* wait for clock stabilization */
  137. ret = iwl_poll_direct_bit(priv, CSR_GP_CNTRL,
  138. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
  139. if (ret < 0) {
  140. IWL_DEBUG_INFO(priv, "Failed to init the card\n");
  141. goto out;
  142. }
  143. /* enable DMA */
  144. iwl_write_prph(priv, APMG_CLK_EN_REG, APMG_CLK_VAL_DMA_CLK_RQT);
  145. udelay(20);
  146. /* disable L1-Active */
  147. iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
  148. APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
  149. out:
  150. return ret;
  151. }
  152. static void iwl5000_nic_config(struct iwl_priv *priv)
  153. {
  154. unsigned long flags;
  155. u16 radio_cfg;
  156. u16 lctl;
  157. spin_lock_irqsave(&priv->lock, flags);
  158. lctl = iwl_pcie_link_ctl(priv);
  159. /* HW bug W/A */
  160. /* L1-ASPM is enabled by BIOS */
  161. if ((lctl & PCI_CFG_LINK_CTRL_VAL_L1_EN) == PCI_CFG_LINK_CTRL_VAL_L1_EN)
  162. /* L1-APSM enabled: disable L0S */
  163. iwl_set_bit(priv, CSR_GIO_REG, CSR_GIO_REG_VAL_L0S_ENABLED);
  164. else
  165. /* L1-ASPM disabled: enable L0S */
  166. iwl_clear_bit(priv, CSR_GIO_REG, CSR_GIO_REG_VAL_L0S_ENABLED);
  167. radio_cfg = iwl_eeprom_query16(priv, EEPROM_RADIO_CONFIG);
  168. /* write radio config values to register */
  169. if (EEPROM_RF_CFG_TYPE_MSK(radio_cfg) < EEPROM_5000_RF_CFG_TYPE_MAX)
  170. iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
  171. EEPROM_RF_CFG_TYPE_MSK(radio_cfg) |
  172. EEPROM_RF_CFG_STEP_MSK(radio_cfg) |
  173. EEPROM_RF_CFG_DASH_MSK(radio_cfg));
  174. /* set CSR_HW_CONFIG_REG for uCode use */
  175. iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
  176. CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI |
  177. CSR_HW_IF_CONFIG_REG_BIT_MAC_SI);
  178. /* W/A : NIC is stuck in a reset state after Early PCIe power off
  179. * (PCIe power is lost before PERST# is asserted),
  180. * causing ME FW to lose ownership and not being able to obtain it back.
  181. */
  182. iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
  183. APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS,
  184. ~APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS);
  185. if ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_1000) {
  186. /* Setting digital SVR for 1000 card to 1.32V */
  187. iwl_set_bits_mask_prph(priv, APMG_DIGITAL_SVR_REG,
  188. APMG_SVR_DIGITAL_VOLTAGE_1_32,
  189. ~APMG_SVR_VOLTAGE_CONFIG_BIT_MSK);
  190. }
  191. spin_unlock_irqrestore(&priv->lock, flags);
  192. }
  193. /*
  194. * EEPROM
  195. */
  196. static u32 eeprom_indirect_address(const struct iwl_priv *priv, u32 address)
  197. {
  198. u16 offset = 0;
  199. if ((address & INDIRECT_ADDRESS) == 0)
  200. return address;
  201. switch (address & INDIRECT_TYPE_MSK) {
  202. case INDIRECT_HOST:
  203. offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_HOST);
  204. break;
  205. case INDIRECT_GENERAL:
  206. offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_GENERAL);
  207. break;
  208. case INDIRECT_REGULATORY:
  209. offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_REGULATORY);
  210. break;
  211. case INDIRECT_CALIBRATION:
  212. offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_CALIBRATION);
  213. break;
  214. case INDIRECT_PROCESS_ADJST:
  215. offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_PROCESS_ADJST);
  216. break;
  217. case INDIRECT_OTHERS:
  218. offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_OTHERS);
  219. break;
  220. default:
  221. IWL_ERR(priv, "illegal indirect type: 0x%X\n",
  222. address & INDIRECT_TYPE_MSK);
  223. break;
  224. }
  225. /* translate the offset from words to byte */
  226. return (address & ADDRESS_MSK) + (offset << 1);
  227. }
  228. static u16 iwl5000_eeprom_calib_version(struct iwl_priv *priv)
  229. {
  230. struct iwl_eeprom_calib_hdr {
  231. u8 version;
  232. u8 pa_type;
  233. u16 voltage;
  234. } *hdr;
  235. hdr = (struct iwl_eeprom_calib_hdr *)iwl_eeprom_query_addr(priv,
  236. EEPROM_5000_CALIB_ALL);
  237. return hdr->version;
  238. }
  239. static void iwl5000_gain_computation(struct iwl_priv *priv,
  240. u32 average_noise[NUM_RX_CHAINS],
  241. u16 min_average_noise_antenna_i,
  242. u32 min_average_noise)
  243. {
  244. int i;
  245. s32 delta_g;
  246. struct iwl_chain_noise_data *data = &priv->chain_noise_data;
  247. /* Find Gain Code for the antennas B and C */
  248. for (i = 1; i < NUM_RX_CHAINS; i++) {
  249. if ((data->disconn_array[i])) {
  250. data->delta_gain_code[i] = 0;
  251. continue;
  252. }
  253. delta_g = (1000 * ((s32)average_noise[0] -
  254. (s32)average_noise[i])) / 1500;
  255. /* bound gain by 2 bits value max, 3rd bit is sign */
  256. data->delta_gain_code[i] =
  257. min(abs(delta_g), CHAIN_NOISE_MAX_DELTA_GAIN_CODE);
  258. if (delta_g < 0)
  259. /* set negative sign */
  260. data->delta_gain_code[i] |= (1 << 2);
  261. }
  262. IWL_DEBUG_CALIB(priv, "Delta gains: ANT_B = %d ANT_C = %d\n",
  263. data->delta_gain_code[1], data->delta_gain_code[2]);
  264. if (!data->radio_write) {
  265. struct iwl_calib_chain_noise_gain_cmd cmd;
  266. memset(&cmd, 0, sizeof(cmd));
  267. cmd.hdr.op_code = IWL_PHY_CALIBRATE_CHAIN_NOISE_GAIN_CMD;
  268. cmd.hdr.first_group = 0;
  269. cmd.hdr.groups_num = 1;
  270. cmd.hdr.data_valid = 1;
  271. cmd.delta_gain_1 = data->delta_gain_code[1];
  272. cmd.delta_gain_2 = data->delta_gain_code[2];
  273. iwl_send_cmd_pdu_async(priv, REPLY_PHY_CALIBRATION_CMD,
  274. sizeof(cmd), &cmd, NULL);
  275. data->radio_write = 1;
  276. data->state = IWL_CHAIN_NOISE_CALIBRATED;
  277. }
  278. data->chain_noise_a = 0;
  279. data->chain_noise_b = 0;
  280. data->chain_noise_c = 0;
  281. data->chain_signal_a = 0;
  282. data->chain_signal_b = 0;
  283. data->chain_signal_c = 0;
  284. data->beacon_count = 0;
  285. }
  286. static void iwl5000_chain_noise_reset(struct iwl_priv *priv)
  287. {
  288. struct iwl_chain_noise_data *data = &priv->chain_noise_data;
  289. int ret;
  290. if ((data->state == IWL_CHAIN_NOISE_ALIVE) && iwl_is_associated(priv)) {
  291. struct iwl_calib_chain_noise_reset_cmd cmd;
  292. memset(&cmd, 0, sizeof(cmd));
  293. cmd.hdr.op_code = IWL_PHY_CALIBRATE_CHAIN_NOISE_RESET_CMD;
  294. cmd.hdr.first_group = 0;
  295. cmd.hdr.groups_num = 1;
  296. cmd.hdr.data_valid = 1;
  297. ret = iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
  298. sizeof(cmd), &cmd);
  299. if (ret)
  300. IWL_ERR(priv,
  301. "Could not send REPLY_PHY_CALIBRATION_CMD\n");
  302. data->state = IWL_CHAIN_NOISE_ACCUMULATE;
  303. IWL_DEBUG_CALIB(priv, "Run chain_noise_calibrate\n");
  304. }
  305. }
  306. void iwl5000_rts_tx_cmd_flag(struct ieee80211_tx_info *info,
  307. __le32 *tx_flags)
  308. {
  309. if ((info->control.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) ||
  310. (info->control.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT))
  311. *tx_flags |= TX_CMD_FLG_RTS_CTS_MSK;
  312. else
  313. *tx_flags &= ~TX_CMD_FLG_RTS_CTS_MSK;
  314. }
  315. static struct iwl_sensitivity_ranges iwl5000_sensitivity = {
  316. .min_nrg_cck = 95,
  317. .max_nrg_cck = 0, /* not used, set to 0 */
  318. .auto_corr_min_ofdm = 90,
  319. .auto_corr_min_ofdm_mrc = 170,
  320. .auto_corr_min_ofdm_x1 = 120,
  321. .auto_corr_min_ofdm_mrc_x1 = 240,
  322. .auto_corr_max_ofdm = 120,
  323. .auto_corr_max_ofdm_mrc = 210,
  324. .auto_corr_max_ofdm_x1 = 155,
  325. .auto_corr_max_ofdm_mrc_x1 = 290,
  326. .auto_corr_min_cck = 125,
  327. .auto_corr_max_cck = 200,
  328. .auto_corr_min_cck_mrc = 170,
  329. .auto_corr_max_cck_mrc = 400,
  330. .nrg_th_cck = 95,
  331. .nrg_th_ofdm = 95,
  332. };
  333. static struct iwl_sensitivity_ranges iwl5150_sensitivity = {
  334. .min_nrg_cck = 95,
  335. .max_nrg_cck = 0, /* not used, set to 0 */
  336. .auto_corr_min_ofdm = 90,
  337. .auto_corr_min_ofdm_mrc = 170,
  338. .auto_corr_min_ofdm_x1 = 105,
  339. .auto_corr_min_ofdm_mrc_x1 = 220,
  340. .auto_corr_max_ofdm = 120,
  341. .auto_corr_max_ofdm_mrc = 210,
  342. /* max = min for performance bug in 5150 DSP */
  343. .auto_corr_max_ofdm_x1 = 105,
  344. .auto_corr_max_ofdm_mrc_x1 = 220,
  345. .auto_corr_min_cck = 125,
  346. .auto_corr_max_cck = 200,
  347. .auto_corr_min_cck_mrc = 170,
  348. .auto_corr_max_cck_mrc = 400,
  349. .nrg_th_cck = 95,
  350. .nrg_th_ofdm = 95,
  351. };
  352. static const u8 *iwl5000_eeprom_query_addr(const struct iwl_priv *priv,
  353. size_t offset)
  354. {
  355. u32 address = eeprom_indirect_address(priv, offset);
  356. BUG_ON(address >= priv->cfg->eeprom_size);
  357. return &priv->eeprom[address];
  358. }
  359. static void iwl5150_set_ct_threshold(struct iwl_priv *priv)
  360. {
  361. const s32 volt2temp_coef = IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF;
  362. s32 threshold = (s32)CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD) -
  363. iwl_temp_calib_to_offset(priv);
  364. priv->hw_params.ct_kill_threshold = threshold * volt2temp_coef;
  365. }
  366. static void iwl5000_set_ct_threshold(struct iwl_priv *priv)
  367. {
  368. /* want Celsius */
  369. priv->hw_params.ct_kill_threshold = CT_KILL_THRESHOLD;
  370. }
  371. /*
  372. * Calibration
  373. */
  374. static int iwl5000_set_Xtal_calib(struct iwl_priv *priv)
  375. {
  376. struct iwl_calib_xtal_freq_cmd cmd;
  377. u16 *xtal_calib = (u16 *)iwl_eeprom_query_addr(priv, EEPROM_5000_XTAL);
  378. cmd.hdr.op_code = IWL_PHY_CALIBRATE_CRYSTAL_FRQ_CMD;
  379. cmd.hdr.first_group = 0;
  380. cmd.hdr.groups_num = 1;
  381. cmd.hdr.data_valid = 1;
  382. cmd.cap_pin1 = (u8)xtal_calib[0];
  383. cmd.cap_pin2 = (u8)xtal_calib[1];
  384. return iwl_calib_set(&priv->calib_results[IWL_CALIB_XTAL],
  385. (u8 *)&cmd, sizeof(cmd));
  386. }
  387. static int iwl5000_send_calib_cfg(struct iwl_priv *priv)
  388. {
  389. struct iwl_calib_cfg_cmd calib_cfg_cmd;
  390. struct iwl_host_cmd cmd = {
  391. .id = CALIBRATION_CFG_CMD,
  392. .len = sizeof(struct iwl_calib_cfg_cmd),
  393. .data = &calib_cfg_cmd,
  394. };
  395. memset(&calib_cfg_cmd, 0, sizeof(calib_cfg_cmd));
  396. calib_cfg_cmd.ucd_calib_cfg.once.is_enable = IWL_CALIB_INIT_CFG_ALL;
  397. calib_cfg_cmd.ucd_calib_cfg.once.start = IWL_CALIB_INIT_CFG_ALL;
  398. calib_cfg_cmd.ucd_calib_cfg.once.send_res = IWL_CALIB_INIT_CFG_ALL;
  399. calib_cfg_cmd.ucd_calib_cfg.flags = IWL_CALIB_INIT_CFG_ALL;
  400. return iwl_send_cmd(priv, &cmd);
  401. }
  402. static void iwl5000_rx_calib_result(struct iwl_priv *priv,
  403. struct iwl_rx_mem_buffer *rxb)
  404. {
  405. struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
  406. struct iwl_calib_hdr *hdr = (struct iwl_calib_hdr *)pkt->u.raw;
  407. int len = le32_to_cpu(pkt->len) & FH_RSCSR_FRAME_SIZE_MSK;
  408. int index;
  409. /* reduce the size of the length field itself */
  410. len -= 4;
  411. /* Define the order in which the results will be sent to the runtime
  412. * uCode. iwl_send_calib_results sends them in a row according to their
  413. * index. We sort them here */
  414. switch (hdr->op_code) {
  415. case IWL_PHY_CALIBRATE_DC_CMD:
  416. index = IWL_CALIB_DC;
  417. break;
  418. case IWL_PHY_CALIBRATE_LO_CMD:
  419. index = IWL_CALIB_LO;
  420. break;
  421. case IWL_PHY_CALIBRATE_TX_IQ_CMD:
  422. index = IWL_CALIB_TX_IQ;
  423. break;
  424. case IWL_PHY_CALIBRATE_TX_IQ_PERD_CMD:
  425. index = IWL_CALIB_TX_IQ_PERD;
  426. break;
  427. case IWL_PHY_CALIBRATE_BASE_BAND_CMD:
  428. index = IWL_CALIB_BASE_BAND;
  429. break;
  430. default:
  431. IWL_ERR(priv, "Unknown calibration notification %d\n",
  432. hdr->op_code);
  433. return;
  434. }
  435. iwl_calib_set(&priv->calib_results[index], pkt->u.raw, len);
  436. }
  437. static void iwl5000_rx_calib_complete(struct iwl_priv *priv,
  438. struct iwl_rx_mem_buffer *rxb)
  439. {
  440. IWL_DEBUG_INFO(priv, "Init. calibration is completed, restarting fw.\n");
  441. queue_work(priv->workqueue, &priv->restart);
  442. }
  443. /*
  444. * ucode
  445. */
  446. static int iwl5000_load_section(struct iwl_priv *priv,
  447. struct fw_desc *image,
  448. u32 dst_addr)
  449. {
  450. dma_addr_t phy_addr = image->p_addr;
  451. u32 byte_cnt = image->len;
  452. iwl_write_direct32(priv,
  453. FH_TCSR_CHNL_TX_CONFIG_REG(FH_SRVC_CHNL),
  454. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE);
  455. iwl_write_direct32(priv,
  456. FH_SRVC_CHNL_SRAM_ADDR_REG(FH_SRVC_CHNL), dst_addr);
  457. iwl_write_direct32(priv,
  458. FH_TFDIB_CTRL0_REG(FH_SRVC_CHNL),
  459. phy_addr & FH_MEM_TFDIB_DRAM_ADDR_LSB_MSK);
  460. iwl_write_direct32(priv,
  461. FH_TFDIB_CTRL1_REG(FH_SRVC_CHNL),
  462. (iwl_get_dma_hi_addr(phy_addr)
  463. << FH_MEM_TFDIB_REG1_ADDR_BITSHIFT) | byte_cnt);
  464. iwl_write_direct32(priv,
  465. FH_TCSR_CHNL_TX_BUF_STS_REG(FH_SRVC_CHNL),
  466. 1 << FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_NUM |
  467. 1 << FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_IDX |
  468. FH_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_VALID);
  469. iwl_write_direct32(priv,
  470. FH_TCSR_CHNL_TX_CONFIG_REG(FH_SRVC_CHNL),
  471. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE |
  472. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_DISABLE |
  473. FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_ENDTFD);
  474. return 0;
  475. }
  476. static int iwl5000_load_given_ucode(struct iwl_priv *priv,
  477. struct fw_desc *inst_image,
  478. struct fw_desc *data_image)
  479. {
  480. int ret = 0;
  481. ret = iwl5000_load_section(priv, inst_image,
  482. IWL50_RTC_INST_LOWER_BOUND);
  483. if (ret)
  484. return ret;
  485. IWL_DEBUG_INFO(priv, "INST uCode section being loaded...\n");
  486. ret = wait_event_interruptible_timeout(priv->wait_command_queue,
  487. priv->ucode_write_complete, 5 * HZ);
  488. if (ret == -ERESTARTSYS) {
  489. IWL_ERR(priv, "Could not load the INST uCode section due "
  490. "to interrupt\n");
  491. return ret;
  492. }
  493. if (!ret) {
  494. IWL_ERR(priv, "Could not load the INST uCode section\n");
  495. return -ETIMEDOUT;
  496. }
  497. priv->ucode_write_complete = 0;
  498. ret = iwl5000_load_section(
  499. priv, data_image, IWL50_RTC_DATA_LOWER_BOUND);
  500. if (ret)
  501. return ret;
  502. IWL_DEBUG_INFO(priv, "DATA uCode section being loaded...\n");
  503. ret = wait_event_interruptible_timeout(priv->wait_command_queue,
  504. priv->ucode_write_complete, 5 * HZ);
  505. if (ret == -ERESTARTSYS) {
  506. IWL_ERR(priv, "Could not load the INST uCode section due "
  507. "to interrupt\n");
  508. return ret;
  509. } else if (!ret) {
  510. IWL_ERR(priv, "Could not load the DATA uCode section\n");
  511. return -ETIMEDOUT;
  512. } else
  513. ret = 0;
  514. priv->ucode_write_complete = 0;
  515. return ret;
  516. }
  517. static int iwl5000_load_ucode(struct iwl_priv *priv)
  518. {
  519. int ret = 0;
  520. /* check whether init ucode should be loaded, or rather runtime ucode */
  521. if (priv->ucode_init.len && (priv->ucode_type == UCODE_NONE)) {
  522. IWL_DEBUG_INFO(priv, "Init ucode found. Loading init ucode...\n");
  523. ret = iwl5000_load_given_ucode(priv,
  524. &priv->ucode_init, &priv->ucode_init_data);
  525. if (!ret) {
  526. IWL_DEBUG_INFO(priv, "Init ucode load complete.\n");
  527. priv->ucode_type = UCODE_INIT;
  528. }
  529. } else {
  530. IWL_DEBUG_INFO(priv, "Init ucode not found, or already loaded. "
  531. "Loading runtime ucode...\n");
  532. ret = iwl5000_load_given_ucode(priv,
  533. &priv->ucode_code, &priv->ucode_data);
  534. if (!ret) {
  535. IWL_DEBUG_INFO(priv, "Runtime ucode load complete.\n");
  536. priv->ucode_type = UCODE_RT;
  537. }
  538. }
  539. return ret;
  540. }
  541. static void iwl5000_init_alive_start(struct iwl_priv *priv)
  542. {
  543. int ret = 0;
  544. /* Check alive response for "valid" sign from uCode */
  545. if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
  546. /* We had an error bringing up the hardware, so take it
  547. * all the way back down so we can try again */
  548. IWL_DEBUG_INFO(priv, "Initialize Alive failed.\n");
  549. goto restart;
  550. }
  551. /* initialize uCode was loaded... verify inst image.
  552. * This is a paranoid check, because we would not have gotten the
  553. * "initialize" alive if code weren't properly loaded. */
  554. if (iwl_verify_ucode(priv)) {
  555. /* Runtime instruction load was bad;
  556. * take it all the way back down so we can try again */
  557. IWL_DEBUG_INFO(priv, "Bad \"initialize\" uCode load.\n");
  558. goto restart;
  559. }
  560. iwl_clear_stations_table(priv);
  561. ret = priv->cfg->ops->lib->alive_notify(priv);
  562. if (ret) {
  563. IWL_WARN(priv,
  564. "Could not complete ALIVE transition: %d\n", ret);
  565. goto restart;
  566. }
  567. iwl5000_send_calib_cfg(priv);
  568. return;
  569. restart:
  570. /* real restart (first load init_ucode) */
  571. queue_work(priv->workqueue, &priv->restart);
  572. }
  573. static void iwl5000_set_wr_ptrs(struct iwl_priv *priv,
  574. int txq_id, u32 index)
  575. {
  576. iwl_write_direct32(priv, HBUS_TARG_WRPTR,
  577. (index & 0xff) | (txq_id << 8));
  578. iwl_write_prph(priv, IWL50_SCD_QUEUE_RDPTR(txq_id), index);
  579. }
  580. static void iwl5000_tx_queue_set_status(struct iwl_priv *priv,
  581. struct iwl_tx_queue *txq,
  582. int tx_fifo_id, int scd_retry)
  583. {
  584. int txq_id = txq->q.id;
  585. int active = test_bit(txq_id, &priv->txq_ctx_active_msk) ? 1 : 0;
  586. iwl_write_prph(priv, IWL50_SCD_QUEUE_STATUS_BITS(txq_id),
  587. (active << IWL50_SCD_QUEUE_STTS_REG_POS_ACTIVE) |
  588. (tx_fifo_id << IWL50_SCD_QUEUE_STTS_REG_POS_TXF) |
  589. (1 << IWL50_SCD_QUEUE_STTS_REG_POS_WSL) |
  590. IWL50_SCD_QUEUE_STTS_REG_MSK);
  591. txq->sched_retry = scd_retry;
  592. IWL_DEBUG_INFO(priv, "%s %s Queue %d on AC %d\n",
  593. active ? "Activate" : "Deactivate",
  594. scd_retry ? "BA" : "AC", txq_id, tx_fifo_id);
  595. }
  596. static int iwl5000_send_wimax_coex(struct iwl_priv *priv)
  597. {
  598. struct iwl_wimax_coex_cmd coex_cmd;
  599. memset(&coex_cmd, 0, sizeof(coex_cmd));
  600. return iwl_send_cmd_pdu(priv, COEX_PRIORITY_TABLE_CMD,
  601. sizeof(coex_cmd), &coex_cmd);
  602. }
  603. static int iwl5000_alive_notify(struct iwl_priv *priv)
  604. {
  605. u32 a;
  606. unsigned long flags;
  607. int i, chan;
  608. u32 reg_val;
  609. spin_lock_irqsave(&priv->lock, flags);
  610. priv->scd_base_addr = iwl_read_prph(priv, IWL50_SCD_SRAM_BASE_ADDR);
  611. a = priv->scd_base_addr + IWL50_SCD_CONTEXT_DATA_OFFSET;
  612. for (; a < priv->scd_base_addr + IWL50_SCD_TX_STTS_BITMAP_OFFSET;
  613. a += 4)
  614. iwl_write_targ_mem(priv, a, 0);
  615. for (; a < priv->scd_base_addr + IWL50_SCD_TRANSLATE_TBL_OFFSET;
  616. a += 4)
  617. iwl_write_targ_mem(priv, a, 0);
  618. for (; a < sizeof(u16) * priv->hw_params.max_txq_num; a += 4)
  619. iwl_write_targ_mem(priv, a, 0);
  620. iwl_write_prph(priv, IWL50_SCD_DRAM_BASE_ADDR,
  621. priv->scd_bc_tbls.dma >> 10);
  622. /* Enable DMA channel */
  623. for (chan = 0; chan < FH50_TCSR_CHNL_NUM ; chan++)
  624. iwl_write_direct32(priv, FH_TCSR_CHNL_TX_CONFIG_REG(chan),
  625. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE |
  626. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE);
  627. /* Update FH chicken bits */
  628. reg_val = iwl_read_direct32(priv, FH_TX_CHICKEN_BITS_REG);
  629. iwl_write_direct32(priv, FH_TX_CHICKEN_BITS_REG,
  630. reg_val | FH_TX_CHICKEN_BITS_SCD_AUTO_RETRY_EN);
  631. iwl_write_prph(priv, IWL50_SCD_QUEUECHAIN_SEL,
  632. IWL50_SCD_QUEUECHAIN_SEL_ALL(priv->hw_params.max_txq_num));
  633. iwl_write_prph(priv, IWL50_SCD_AGGR_SEL, 0);
  634. /* initiate the queues */
  635. for (i = 0; i < priv->hw_params.max_txq_num; i++) {
  636. iwl_write_prph(priv, IWL50_SCD_QUEUE_RDPTR(i), 0);
  637. iwl_write_direct32(priv, HBUS_TARG_WRPTR, 0 | (i << 8));
  638. iwl_write_targ_mem(priv, priv->scd_base_addr +
  639. IWL50_SCD_CONTEXT_QUEUE_OFFSET(i), 0);
  640. iwl_write_targ_mem(priv, priv->scd_base_addr +
  641. IWL50_SCD_CONTEXT_QUEUE_OFFSET(i) +
  642. sizeof(u32),
  643. ((SCD_WIN_SIZE <<
  644. IWL50_SCD_QUEUE_CTX_REG2_WIN_SIZE_POS) &
  645. IWL50_SCD_QUEUE_CTX_REG2_WIN_SIZE_MSK) |
  646. ((SCD_FRAME_LIMIT <<
  647. IWL50_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) &
  648. IWL50_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK));
  649. }
  650. iwl_write_prph(priv, IWL50_SCD_INTERRUPT_MASK,
  651. IWL_MASK(0, priv->hw_params.max_txq_num));
  652. /* Activate all Tx DMA/FIFO channels */
  653. priv->cfg->ops->lib->txq_set_sched(priv, IWL_MASK(0, 7));
  654. iwl5000_set_wr_ptrs(priv, IWL_CMD_QUEUE_NUM, 0);
  655. /* map qos queues to fifos one-to-one */
  656. for (i = 0; i < ARRAY_SIZE(iwl5000_default_queue_to_tx_fifo); i++) {
  657. int ac = iwl5000_default_queue_to_tx_fifo[i];
  658. iwl_txq_ctx_activate(priv, i);
  659. iwl5000_tx_queue_set_status(priv, &priv->txq[i], ac, 0);
  660. }
  661. /* TODO - need to initialize those FIFOs inside the loop above,
  662. * not only mark them as active */
  663. iwl_txq_ctx_activate(priv, 4);
  664. iwl_txq_ctx_activate(priv, 7);
  665. iwl_txq_ctx_activate(priv, 8);
  666. iwl_txq_ctx_activate(priv, 9);
  667. spin_unlock_irqrestore(&priv->lock, flags);
  668. iwl5000_send_wimax_coex(priv);
  669. iwl5000_set_Xtal_calib(priv);
  670. iwl_send_calib_results(priv);
  671. return 0;
  672. }
  673. static int iwl5000_hw_set_hw_params(struct iwl_priv *priv)
  674. {
  675. if ((priv->cfg->mod_params->num_of_queues > IWL50_NUM_QUEUES) ||
  676. (priv->cfg->mod_params->num_of_queues < IWL_MIN_NUM_QUEUES)) {
  677. IWL_ERR(priv,
  678. "invalid queues_num, should be between %d and %d\n",
  679. IWL_MIN_NUM_QUEUES, IWL50_NUM_QUEUES);
  680. return -EINVAL;
  681. }
  682. priv->hw_params.max_txq_num = priv->cfg->mod_params->num_of_queues;
  683. priv->hw_params.dma_chnl_num = FH50_TCSR_CHNL_NUM;
  684. priv->hw_params.scd_bc_tbls_size =
  685. IWL50_NUM_QUEUES * sizeof(struct iwl5000_scd_bc_tbl);
  686. priv->hw_params.tfd_size = sizeof(struct iwl_tfd);
  687. priv->hw_params.max_stations = IWL5000_STATION_COUNT;
  688. priv->hw_params.bcast_sta_id = IWL5000_BROADCAST_ID;
  689. switch (priv->hw_rev & CSR_HW_REV_TYPE_MSK) {
  690. case CSR_HW_REV_TYPE_6x00:
  691. case CSR_HW_REV_TYPE_6x50:
  692. priv->hw_params.max_data_size = IWL60_RTC_DATA_SIZE;
  693. priv->hw_params.max_inst_size = IWL60_RTC_INST_SIZE;
  694. break;
  695. default:
  696. priv->hw_params.max_data_size = IWL50_RTC_DATA_SIZE;
  697. priv->hw_params.max_inst_size = IWL50_RTC_INST_SIZE;
  698. }
  699. priv->hw_params.max_bsm_size = 0;
  700. priv->hw_params.fat_channel = BIT(IEEE80211_BAND_2GHZ) |
  701. BIT(IEEE80211_BAND_5GHZ);
  702. priv->hw_params.rx_wrt_ptr_reg = FH_RSCSR_CHNL0_WPTR;
  703. priv->hw_params.tx_chains_num = num_of_ant(priv->cfg->valid_tx_ant);
  704. priv->hw_params.rx_chains_num = num_of_ant(priv->cfg->valid_rx_ant);
  705. priv->hw_params.valid_tx_ant = priv->cfg->valid_tx_ant;
  706. priv->hw_params.valid_rx_ant = priv->cfg->valid_rx_ant;
  707. if (priv->cfg->ops->lib->temp_ops.set_ct_kill)
  708. priv->cfg->ops->lib->temp_ops.set_ct_kill(priv);
  709. /* Set initial sensitivity parameters */
  710. /* Set initial calibration set */
  711. switch (priv->hw_rev & CSR_HW_REV_TYPE_MSK) {
  712. case CSR_HW_REV_TYPE_5150:
  713. priv->hw_params.sens = &iwl5150_sensitivity;
  714. priv->hw_params.calib_init_cfg =
  715. BIT(IWL_CALIB_DC) |
  716. BIT(IWL_CALIB_LO) |
  717. BIT(IWL_CALIB_TX_IQ) |
  718. BIT(IWL_CALIB_BASE_BAND);
  719. break;
  720. default:
  721. priv->hw_params.sens = &iwl5000_sensitivity;
  722. priv->hw_params.calib_init_cfg =
  723. BIT(IWL_CALIB_XTAL) |
  724. BIT(IWL_CALIB_LO) |
  725. BIT(IWL_CALIB_TX_IQ) |
  726. BIT(IWL_CALIB_TX_IQ_PERD) |
  727. BIT(IWL_CALIB_BASE_BAND);
  728. break;
  729. }
  730. return 0;
  731. }
  732. /**
  733. * iwl5000_txq_update_byte_cnt_tbl - Set up entry in Tx byte-count array
  734. */
  735. static void iwl5000_txq_update_byte_cnt_tbl(struct iwl_priv *priv,
  736. struct iwl_tx_queue *txq,
  737. u16 byte_cnt)
  738. {
  739. struct iwl5000_scd_bc_tbl *scd_bc_tbl = priv->scd_bc_tbls.addr;
  740. int write_ptr = txq->q.write_ptr;
  741. int txq_id = txq->q.id;
  742. u8 sec_ctl = 0;
  743. u8 sta_id = 0;
  744. u16 len = byte_cnt + IWL_TX_CRC_SIZE + IWL_TX_DELIMITER_SIZE;
  745. __le16 bc_ent;
  746. WARN_ON(len > 0xFFF || write_ptr >= TFD_QUEUE_SIZE_MAX);
  747. if (txq_id != IWL_CMD_QUEUE_NUM) {
  748. sta_id = txq->cmd[txq->q.write_ptr]->cmd.tx.sta_id;
  749. sec_ctl = txq->cmd[txq->q.write_ptr]->cmd.tx.sec_ctl;
  750. switch (sec_ctl & TX_CMD_SEC_MSK) {
  751. case TX_CMD_SEC_CCM:
  752. len += CCMP_MIC_LEN;
  753. break;
  754. case TX_CMD_SEC_TKIP:
  755. len += TKIP_ICV_LEN;
  756. break;
  757. case TX_CMD_SEC_WEP:
  758. len += WEP_IV_LEN + WEP_ICV_LEN;
  759. break;
  760. }
  761. }
  762. bc_ent = cpu_to_le16((len & 0xFFF) | (sta_id << 12));
  763. scd_bc_tbl[txq_id].tfd_offset[write_ptr] = bc_ent;
  764. if (txq->q.write_ptr < TFD_QUEUE_SIZE_BC_DUP)
  765. scd_bc_tbl[txq_id].
  766. tfd_offset[TFD_QUEUE_SIZE_MAX + write_ptr] = bc_ent;
  767. }
  768. static void iwl5000_txq_inval_byte_cnt_tbl(struct iwl_priv *priv,
  769. struct iwl_tx_queue *txq)
  770. {
  771. struct iwl5000_scd_bc_tbl *scd_bc_tbl = priv->scd_bc_tbls.addr;
  772. int txq_id = txq->q.id;
  773. int read_ptr = txq->q.read_ptr;
  774. u8 sta_id = 0;
  775. __le16 bc_ent;
  776. WARN_ON(read_ptr >= TFD_QUEUE_SIZE_MAX);
  777. if (txq_id != IWL_CMD_QUEUE_NUM)
  778. sta_id = txq->cmd[read_ptr]->cmd.tx.sta_id;
  779. bc_ent = cpu_to_le16(1 | (sta_id << 12));
  780. scd_bc_tbl[txq_id].tfd_offset[read_ptr] = bc_ent;
  781. if (txq->q.write_ptr < TFD_QUEUE_SIZE_BC_DUP)
  782. scd_bc_tbl[txq_id].
  783. tfd_offset[TFD_QUEUE_SIZE_MAX + read_ptr] = bc_ent;
  784. }
  785. static int iwl5000_tx_queue_set_q2ratid(struct iwl_priv *priv, u16 ra_tid,
  786. u16 txq_id)
  787. {
  788. u32 tbl_dw_addr;
  789. u32 tbl_dw;
  790. u16 scd_q2ratid;
  791. scd_q2ratid = ra_tid & IWL_SCD_QUEUE_RA_TID_MAP_RATID_MSK;
  792. tbl_dw_addr = priv->scd_base_addr +
  793. IWL50_SCD_TRANSLATE_TBL_OFFSET_QUEUE(txq_id);
  794. tbl_dw = iwl_read_targ_mem(priv, tbl_dw_addr);
  795. if (txq_id & 0x1)
  796. tbl_dw = (scd_q2ratid << 16) | (tbl_dw & 0x0000FFFF);
  797. else
  798. tbl_dw = scd_q2ratid | (tbl_dw & 0xFFFF0000);
  799. iwl_write_targ_mem(priv, tbl_dw_addr, tbl_dw);
  800. return 0;
  801. }
  802. static void iwl5000_tx_queue_stop_scheduler(struct iwl_priv *priv, u16 txq_id)
  803. {
  804. /* Simply stop the queue, but don't change any configuration;
  805. * the SCD_ACT_EN bit is the write-enable mask for the ACTIVE bit. */
  806. iwl_write_prph(priv,
  807. IWL50_SCD_QUEUE_STATUS_BITS(txq_id),
  808. (0 << IWL50_SCD_QUEUE_STTS_REG_POS_ACTIVE)|
  809. (1 << IWL50_SCD_QUEUE_STTS_REG_POS_SCD_ACT_EN));
  810. }
  811. static int iwl5000_txq_agg_enable(struct iwl_priv *priv, int txq_id,
  812. int tx_fifo, int sta_id, int tid, u16 ssn_idx)
  813. {
  814. unsigned long flags;
  815. u16 ra_tid;
  816. if ((IWL50_FIRST_AMPDU_QUEUE > txq_id) ||
  817. (IWL50_FIRST_AMPDU_QUEUE + IWL50_NUM_AMPDU_QUEUES <= txq_id)) {
  818. IWL_WARN(priv,
  819. "queue number out of range: %d, must be %d to %d\n",
  820. txq_id, IWL50_FIRST_AMPDU_QUEUE,
  821. IWL50_FIRST_AMPDU_QUEUE + IWL50_NUM_AMPDU_QUEUES - 1);
  822. return -EINVAL;
  823. }
  824. ra_tid = BUILD_RAxTID(sta_id, tid);
  825. /* Modify device's station table to Tx this TID */
  826. iwl_sta_tx_modify_enable_tid(priv, sta_id, tid);
  827. spin_lock_irqsave(&priv->lock, flags);
  828. /* Stop this Tx queue before configuring it */
  829. iwl5000_tx_queue_stop_scheduler(priv, txq_id);
  830. /* Map receiver-address / traffic-ID to this queue */
  831. iwl5000_tx_queue_set_q2ratid(priv, ra_tid, txq_id);
  832. /* Set this queue as a chain-building queue */
  833. iwl_set_bits_prph(priv, IWL50_SCD_QUEUECHAIN_SEL, (1<<txq_id));
  834. /* enable aggregations for the queue */
  835. iwl_set_bits_prph(priv, IWL50_SCD_AGGR_SEL, (1<<txq_id));
  836. /* Place first TFD at index corresponding to start sequence number.
  837. * Assumes that ssn_idx is valid (!= 0xFFF) */
  838. priv->txq[txq_id].q.read_ptr = (ssn_idx & 0xff);
  839. priv->txq[txq_id].q.write_ptr = (ssn_idx & 0xff);
  840. iwl5000_set_wr_ptrs(priv, txq_id, ssn_idx);
  841. /* Set up Tx window size and frame limit for this queue */
  842. iwl_write_targ_mem(priv, priv->scd_base_addr +
  843. IWL50_SCD_CONTEXT_QUEUE_OFFSET(txq_id) +
  844. sizeof(u32),
  845. ((SCD_WIN_SIZE <<
  846. IWL50_SCD_QUEUE_CTX_REG2_WIN_SIZE_POS) &
  847. IWL50_SCD_QUEUE_CTX_REG2_WIN_SIZE_MSK) |
  848. ((SCD_FRAME_LIMIT <<
  849. IWL50_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) &
  850. IWL50_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK));
  851. iwl_set_bits_prph(priv, IWL50_SCD_INTERRUPT_MASK, (1 << txq_id));
  852. /* Set up Status area in SRAM, map to Tx DMA/FIFO, activate the queue */
  853. iwl5000_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 1);
  854. spin_unlock_irqrestore(&priv->lock, flags);
  855. return 0;
  856. }
  857. static int iwl5000_txq_agg_disable(struct iwl_priv *priv, u16 txq_id,
  858. u16 ssn_idx, u8 tx_fifo)
  859. {
  860. if ((IWL50_FIRST_AMPDU_QUEUE > txq_id) ||
  861. (IWL50_FIRST_AMPDU_QUEUE + IWL50_NUM_AMPDU_QUEUES <= txq_id)) {
  862. IWL_ERR(priv,
  863. "queue number out of range: %d, must be %d to %d\n",
  864. txq_id, IWL50_FIRST_AMPDU_QUEUE,
  865. IWL50_FIRST_AMPDU_QUEUE + IWL50_NUM_AMPDU_QUEUES - 1);
  866. return -EINVAL;
  867. }
  868. iwl5000_tx_queue_stop_scheduler(priv, txq_id);
  869. iwl_clear_bits_prph(priv, IWL50_SCD_AGGR_SEL, (1 << txq_id));
  870. priv->txq[txq_id].q.read_ptr = (ssn_idx & 0xff);
  871. priv->txq[txq_id].q.write_ptr = (ssn_idx & 0xff);
  872. /* supposes that ssn_idx is valid (!= 0xFFF) */
  873. iwl5000_set_wr_ptrs(priv, txq_id, ssn_idx);
  874. iwl_clear_bits_prph(priv, IWL50_SCD_INTERRUPT_MASK, (1 << txq_id));
  875. iwl_txq_ctx_deactivate(priv, txq_id);
  876. iwl5000_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 0);
  877. return 0;
  878. }
  879. u16 iwl5000_build_addsta_hcmd(const struct iwl_addsta_cmd *cmd, u8 *data)
  880. {
  881. u16 size = (u16)sizeof(struct iwl_addsta_cmd);
  882. struct iwl_addsta_cmd *addsta = (struct iwl_addsta_cmd *)data;
  883. memcpy(addsta, cmd, size);
  884. /* resrved in 5000 */
  885. addsta->rate_n_flags = cpu_to_le16(0);
  886. return size;
  887. }
  888. /*
  889. * Activate/Deactivate Tx DMA/FIFO channels according tx fifos mask
  890. * must be called under priv->lock and mac access
  891. */
  892. static void iwl5000_txq_set_sched(struct iwl_priv *priv, u32 mask)
  893. {
  894. iwl_write_prph(priv, IWL50_SCD_TXFACT, mask);
  895. }
  896. static inline u32 iwl5000_get_scd_ssn(struct iwl5000_tx_resp *tx_resp)
  897. {
  898. return le32_to_cpup((__le32 *)&tx_resp->status +
  899. tx_resp->frame_count) & MAX_SN;
  900. }
  901. static int iwl5000_tx_status_reply_tx(struct iwl_priv *priv,
  902. struct iwl_ht_agg *agg,
  903. struct iwl5000_tx_resp *tx_resp,
  904. int txq_id, u16 start_idx)
  905. {
  906. u16 status;
  907. struct agg_tx_status *frame_status = &tx_resp->status;
  908. struct ieee80211_tx_info *info = NULL;
  909. struct ieee80211_hdr *hdr = NULL;
  910. u32 rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
  911. int i, sh, idx;
  912. u16 seq;
  913. if (agg->wait_for_ba)
  914. IWL_DEBUG_TX_REPLY(priv, "got tx response w/o block-ack\n");
  915. agg->frame_count = tx_resp->frame_count;
  916. agg->start_idx = start_idx;
  917. agg->rate_n_flags = rate_n_flags;
  918. agg->bitmap = 0;
  919. /* # frames attempted by Tx command */
  920. if (agg->frame_count == 1) {
  921. /* Only one frame was attempted; no block-ack will arrive */
  922. status = le16_to_cpu(frame_status[0].status);
  923. idx = start_idx;
  924. /* FIXME: code repetition */
  925. IWL_DEBUG_TX_REPLY(priv, "FrameCnt = %d, StartIdx=%d idx=%d\n",
  926. agg->frame_count, agg->start_idx, idx);
  927. info = IEEE80211_SKB_CB(priv->txq[txq_id].txb[idx].skb[0]);
  928. info->status.rates[0].count = tx_resp->failure_frame + 1;
  929. info->flags &= ~IEEE80211_TX_CTL_AMPDU;
  930. info->flags |= iwl_is_tx_success(status) ?
  931. IEEE80211_TX_STAT_ACK : 0;
  932. iwl_hwrate_to_tx_control(priv, rate_n_flags, info);
  933. /* FIXME: code repetition end */
  934. IWL_DEBUG_TX_REPLY(priv, "1 Frame 0x%x failure :%d\n",
  935. status & 0xff, tx_resp->failure_frame);
  936. IWL_DEBUG_TX_REPLY(priv, "Rate Info rate_n_flags=%x\n", rate_n_flags);
  937. agg->wait_for_ba = 0;
  938. } else {
  939. /* Two or more frames were attempted; expect block-ack */
  940. u64 bitmap = 0;
  941. int start = agg->start_idx;
  942. /* Construct bit-map of pending frames within Tx window */
  943. for (i = 0; i < agg->frame_count; i++) {
  944. u16 sc;
  945. status = le16_to_cpu(frame_status[i].status);
  946. seq = le16_to_cpu(frame_status[i].sequence);
  947. idx = SEQ_TO_INDEX(seq);
  948. txq_id = SEQ_TO_QUEUE(seq);
  949. if (status & (AGG_TX_STATE_FEW_BYTES_MSK |
  950. AGG_TX_STATE_ABORT_MSK))
  951. continue;
  952. IWL_DEBUG_TX_REPLY(priv, "FrameCnt = %d, txq_id=%d idx=%d\n",
  953. agg->frame_count, txq_id, idx);
  954. hdr = iwl_tx_queue_get_hdr(priv, txq_id, idx);
  955. sc = le16_to_cpu(hdr->seq_ctrl);
  956. if (idx != (SEQ_TO_SN(sc) & 0xff)) {
  957. IWL_ERR(priv,
  958. "BUG_ON idx doesn't match seq control"
  959. " idx=%d, seq_idx=%d, seq=%d\n",
  960. idx, SEQ_TO_SN(sc),
  961. hdr->seq_ctrl);
  962. return -1;
  963. }
  964. IWL_DEBUG_TX_REPLY(priv, "AGG Frame i=%d idx %d seq=%d\n",
  965. i, idx, SEQ_TO_SN(sc));
  966. sh = idx - start;
  967. if (sh > 64) {
  968. sh = (start - idx) + 0xff;
  969. bitmap = bitmap << sh;
  970. sh = 0;
  971. start = idx;
  972. } else if (sh < -64)
  973. sh = 0xff - (start - idx);
  974. else if (sh < 0) {
  975. sh = start - idx;
  976. start = idx;
  977. bitmap = bitmap << sh;
  978. sh = 0;
  979. }
  980. bitmap |= 1ULL << sh;
  981. IWL_DEBUG_TX_REPLY(priv, "start=%d bitmap=0x%llx\n",
  982. start, (unsigned long long)bitmap);
  983. }
  984. agg->bitmap = bitmap;
  985. agg->start_idx = start;
  986. IWL_DEBUG_TX_REPLY(priv, "Frames %d start_idx=%d bitmap=0x%llx\n",
  987. agg->frame_count, agg->start_idx,
  988. (unsigned long long)agg->bitmap);
  989. if (bitmap)
  990. agg->wait_for_ba = 1;
  991. }
  992. return 0;
  993. }
  994. static void iwl5000_rx_reply_tx(struct iwl_priv *priv,
  995. struct iwl_rx_mem_buffer *rxb)
  996. {
  997. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  998. u16 sequence = le16_to_cpu(pkt->hdr.sequence);
  999. int txq_id = SEQ_TO_QUEUE(sequence);
  1000. int index = SEQ_TO_INDEX(sequence);
  1001. struct iwl_tx_queue *txq = &priv->txq[txq_id];
  1002. struct ieee80211_tx_info *info;
  1003. struct iwl5000_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
  1004. u32 status = le16_to_cpu(tx_resp->status.status);
  1005. int tid;
  1006. int sta_id;
  1007. int freed;
  1008. if ((index >= txq->q.n_bd) || (iwl_queue_used(&txq->q, index) == 0)) {
  1009. IWL_ERR(priv, "Read index for DMA queue txq_id (%d) index %d "
  1010. "is out of range [0-%d] %d %d\n", txq_id,
  1011. index, txq->q.n_bd, txq->q.write_ptr,
  1012. txq->q.read_ptr);
  1013. return;
  1014. }
  1015. info = IEEE80211_SKB_CB(txq->txb[txq->q.read_ptr].skb[0]);
  1016. memset(&info->status, 0, sizeof(info->status));
  1017. tid = (tx_resp->ra_tid & IWL50_TX_RES_TID_MSK) >> IWL50_TX_RES_TID_POS;
  1018. sta_id = (tx_resp->ra_tid & IWL50_TX_RES_RA_MSK) >> IWL50_TX_RES_RA_POS;
  1019. if (txq->sched_retry) {
  1020. const u32 scd_ssn = iwl5000_get_scd_ssn(tx_resp);
  1021. struct iwl_ht_agg *agg = NULL;
  1022. agg = &priv->stations[sta_id].tid[tid].agg;
  1023. iwl5000_tx_status_reply_tx(priv, agg, tx_resp, txq_id, index);
  1024. /* check if BAR is needed */
  1025. if ((tx_resp->frame_count == 1) && !iwl_is_tx_success(status))
  1026. info->flags |= IEEE80211_TX_STAT_AMPDU_NO_BACK;
  1027. if (txq->q.read_ptr != (scd_ssn & 0xff)) {
  1028. index = iwl_queue_dec_wrap(scd_ssn & 0xff, txq->q.n_bd);
  1029. IWL_DEBUG_TX_REPLY(priv, "Retry scheduler reclaim "
  1030. "scd_ssn=%d idx=%d txq=%d swq=%d\n",
  1031. scd_ssn , index, txq_id, txq->swq_id);
  1032. freed = iwl_tx_queue_reclaim(priv, txq_id, index);
  1033. priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
  1034. if (priv->mac80211_registered &&
  1035. (iwl_queue_space(&txq->q) > txq->q.low_mark) &&
  1036. (agg->state != IWL_EMPTYING_HW_QUEUE_DELBA)) {
  1037. if (agg->state == IWL_AGG_OFF)
  1038. iwl_wake_queue(priv, txq_id);
  1039. else
  1040. iwl_wake_queue(priv, txq->swq_id);
  1041. }
  1042. }
  1043. } else {
  1044. BUG_ON(txq_id != txq->swq_id);
  1045. info->status.rates[0].count = tx_resp->failure_frame + 1;
  1046. info->flags |= iwl_is_tx_success(status) ?
  1047. IEEE80211_TX_STAT_ACK : 0;
  1048. iwl_hwrate_to_tx_control(priv,
  1049. le32_to_cpu(tx_resp->rate_n_flags),
  1050. info);
  1051. IWL_DEBUG_TX_REPLY(priv, "TXQ %d status %s (0x%08x) rate_n_flags "
  1052. "0x%x retries %d\n",
  1053. txq_id,
  1054. iwl_get_tx_fail_reason(status), status,
  1055. le32_to_cpu(tx_resp->rate_n_flags),
  1056. tx_resp->failure_frame);
  1057. freed = iwl_tx_queue_reclaim(priv, txq_id, index);
  1058. if (ieee80211_is_data_qos(tx_resp->frame_ctrl))
  1059. priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
  1060. if (priv->mac80211_registered &&
  1061. (iwl_queue_space(&txq->q) > txq->q.low_mark))
  1062. iwl_wake_queue(priv, txq_id);
  1063. }
  1064. if (ieee80211_is_data_qos(tx_resp->frame_ctrl))
  1065. iwl_txq_check_empty(priv, sta_id, tid, txq_id);
  1066. if (iwl_check_bits(status, TX_ABORT_REQUIRED_MSK))
  1067. IWL_ERR(priv, "TODO: Implement Tx ABORT REQUIRED!!!\n");
  1068. }
  1069. /* Currently 5000 is the superset of everything */
  1070. u16 iwl5000_get_hcmd_size(u8 cmd_id, u16 len)
  1071. {
  1072. return len;
  1073. }
  1074. static void iwl5000_setup_deferred_work(struct iwl_priv *priv)
  1075. {
  1076. /* in 5000 the tx power calibration is done in uCode */
  1077. priv->disable_tx_power_cal = 1;
  1078. }
  1079. static void iwl5000_rx_handler_setup(struct iwl_priv *priv)
  1080. {
  1081. /* init calibration handlers */
  1082. priv->rx_handlers[CALIBRATION_RES_NOTIFICATION] =
  1083. iwl5000_rx_calib_result;
  1084. priv->rx_handlers[CALIBRATION_COMPLETE_NOTIFICATION] =
  1085. iwl5000_rx_calib_complete;
  1086. priv->rx_handlers[REPLY_TX] = iwl5000_rx_reply_tx;
  1087. }
  1088. static int iwl5000_hw_valid_rtc_data_addr(u32 addr)
  1089. {
  1090. return (addr >= IWL50_RTC_DATA_LOWER_BOUND) &&
  1091. (addr < IWL50_RTC_DATA_UPPER_BOUND);
  1092. }
  1093. static int iwl5000_send_rxon_assoc(struct iwl_priv *priv)
  1094. {
  1095. int ret = 0;
  1096. struct iwl5000_rxon_assoc_cmd rxon_assoc;
  1097. const struct iwl_rxon_cmd *rxon1 = &priv->staging_rxon;
  1098. const struct iwl_rxon_cmd *rxon2 = &priv->active_rxon;
  1099. if ((rxon1->flags == rxon2->flags) &&
  1100. (rxon1->filter_flags == rxon2->filter_flags) &&
  1101. (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
  1102. (rxon1->ofdm_ht_single_stream_basic_rates ==
  1103. rxon2->ofdm_ht_single_stream_basic_rates) &&
  1104. (rxon1->ofdm_ht_dual_stream_basic_rates ==
  1105. rxon2->ofdm_ht_dual_stream_basic_rates) &&
  1106. (rxon1->ofdm_ht_triple_stream_basic_rates ==
  1107. rxon2->ofdm_ht_triple_stream_basic_rates) &&
  1108. (rxon1->acquisition_data == rxon2->acquisition_data) &&
  1109. (rxon1->rx_chain == rxon2->rx_chain) &&
  1110. (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
  1111. IWL_DEBUG_INFO(priv, "Using current RXON_ASSOC. Not resending.\n");
  1112. return 0;
  1113. }
  1114. rxon_assoc.flags = priv->staging_rxon.flags;
  1115. rxon_assoc.filter_flags = priv->staging_rxon.filter_flags;
  1116. rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates;
  1117. rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates;
  1118. rxon_assoc.reserved1 = 0;
  1119. rxon_assoc.reserved2 = 0;
  1120. rxon_assoc.reserved3 = 0;
  1121. rxon_assoc.ofdm_ht_single_stream_basic_rates =
  1122. priv->staging_rxon.ofdm_ht_single_stream_basic_rates;
  1123. rxon_assoc.ofdm_ht_dual_stream_basic_rates =
  1124. priv->staging_rxon.ofdm_ht_dual_stream_basic_rates;
  1125. rxon_assoc.rx_chain_select_flags = priv->staging_rxon.rx_chain;
  1126. rxon_assoc.ofdm_ht_triple_stream_basic_rates =
  1127. priv->staging_rxon.ofdm_ht_triple_stream_basic_rates;
  1128. rxon_assoc.acquisition_data = priv->staging_rxon.acquisition_data;
  1129. ret = iwl_send_cmd_pdu_async(priv, REPLY_RXON_ASSOC,
  1130. sizeof(rxon_assoc), &rxon_assoc, NULL);
  1131. if (ret)
  1132. return ret;
  1133. return ret;
  1134. }
  1135. static int iwl5000_send_tx_power(struct iwl_priv *priv)
  1136. {
  1137. struct iwl5000_tx_power_dbm_cmd tx_power_cmd;
  1138. u8 tx_ant_cfg_cmd;
  1139. /* half dBm need to multiply */
  1140. tx_power_cmd.global_lmt = (s8)(2 * priv->tx_power_user_lmt);
  1141. tx_power_cmd.flags = IWL50_TX_POWER_NO_CLOSED;
  1142. tx_power_cmd.srv_chan_lmt = IWL50_TX_POWER_AUTO;
  1143. if (IWL_UCODE_API(priv->ucode_ver) == 1)
  1144. tx_ant_cfg_cmd = REPLY_TX_POWER_DBM_CMD_V1;
  1145. else
  1146. tx_ant_cfg_cmd = REPLY_TX_POWER_DBM_CMD;
  1147. return iwl_send_cmd_pdu_async(priv, tx_ant_cfg_cmd,
  1148. sizeof(tx_power_cmd), &tx_power_cmd,
  1149. NULL);
  1150. }
  1151. static void iwl5000_temperature(struct iwl_priv *priv)
  1152. {
  1153. /* store temperature from statistics (in Celsius) */
  1154. priv->temperature = le32_to_cpu(priv->statistics.general.temperature);
  1155. }
  1156. static void iwl5150_temperature(struct iwl_priv *priv)
  1157. {
  1158. u32 vt = 0;
  1159. s32 offset = iwl_temp_calib_to_offset(priv);
  1160. vt = le32_to_cpu(priv->statistics.general.temperature);
  1161. vt = vt / IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF + offset;
  1162. /* now vt hold the temperature in Kelvin */
  1163. priv->temperature = KELVIN_TO_CELSIUS(vt);
  1164. }
  1165. /* Calc max signal level (dBm) among 3 possible receivers */
  1166. int iwl5000_calc_rssi(struct iwl_priv *priv,
  1167. struct iwl_rx_phy_res *rx_resp)
  1168. {
  1169. /* data from PHY/DSP regarding signal strength, etc.,
  1170. * contents are always there, not configurable by host
  1171. */
  1172. struct iwl5000_non_cfg_phy *ncphy =
  1173. (struct iwl5000_non_cfg_phy *)rx_resp->non_cfg_phy_buf;
  1174. u32 val, rssi_a, rssi_b, rssi_c, max_rssi;
  1175. u8 agc;
  1176. val = le32_to_cpu(ncphy->non_cfg_phy[IWL50_RX_RES_AGC_IDX]);
  1177. agc = (val & IWL50_OFDM_AGC_MSK) >> IWL50_OFDM_AGC_BIT_POS;
  1178. /* Find max rssi among 3 possible receivers.
  1179. * These values are measured by the digital signal processor (DSP).
  1180. * They should stay fairly constant even as the signal strength varies,
  1181. * if the radio's automatic gain control (AGC) is working right.
  1182. * AGC value (see below) will provide the "interesting" info.
  1183. */
  1184. val = le32_to_cpu(ncphy->non_cfg_phy[IWL50_RX_RES_RSSI_AB_IDX]);
  1185. rssi_a = (val & IWL50_OFDM_RSSI_A_MSK) >> IWL50_OFDM_RSSI_A_BIT_POS;
  1186. rssi_b = (val & IWL50_OFDM_RSSI_B_MSK) >> IWL50_OFDM_RSSI_B_BIT_POS;
  1187. val = le32_to_cpu(ncphy->non_cfg_phy[IWL50_RX_RES_RSSI_C_IDX]);
  1188. rssi_c = (val & IWL50_OFDM_RSSI_C_MSK) >> IWL50_OFDM_RSSI_C_BIT_POS;
  1189. max_rssi = max_t(u32, rssi_a, rssi_b);
  1190. max_rssi = max_t(u32, max_rssi, rssi_c);
  1191. IWL_DEBUG_STATS(priv, "Rssi In A %d B %d C %d Max %d AGC dB %d\n",
  1192. rssi_a, rssi_b, rssi_c, max_rssi, agc);
  1193. /* dBm = max_rssi dB - agc dB - constant.
  1194. * Higher AGC (higher radio gain) means lower signal. */
  1195. return max_rssi - agc - IWL49_RSSI_OFFSET;
  1196. }
  1197. struct iwl_hcmd_ops iwl5000_hcmd = {
  1198. .rxon_assoc = iwl5000_send_rxon_assoc,
  1199. .commit_rxon = iwl_commit_rxon,
  1200. .set_rxon_chain = iwl_set_rxon_chain,
  1201. };
  1202. struct iwl_hcmd_utils_ops iwl5000_hcmd_utils = {
  1203. .get_hcmd_size = iwl5000_get_hcmd_size,
  1204. .build_addsta_hcmd = iwl5000_build_addsta_hcmd,
  1205. .gain_computation = iwl5000_gain_computation,
  1206. .chain_noise_reset = iwl5000_chain_noise_reset,
  1207. .rts_tx_cmd_flag = iwl5000_rts_tx_cmd_flag,
  1208. .calc_rssi = iwl5000_calc_rssi,
  1209. };
  1210. struct iwl_lib_ops iwl5000_lib = {
  1211. .set_hw_params = iwl5000_hw_set_hw_params,
  1212. .txq_update_byte_cnt_tbl = iwl5000_txq_update_byte_cnt_tbl,
  1213. .txq_inval_byte_cnt_tbl = iwl5000_txq_inval_byte_cnt_tbl,
  1214. .txq_set_sched = iwl5000_txq_set_sched,
  1215. .txq_agg_enable = iwl5000_txq_agg_enable,
  1216. .txq_agg_disable = iwl5000_txq_agg_disable,
  1217. .txq_attach_buf_to_tfd = iwl_hw_txq_attach_buf_to_tfd,
  1218. .txq_free_tfd = iwl_hw_txq_free_tfd,
  1219. .txq_init = iwl_hw_tx_queue_init,
  1220. .rx_handler_setup = iwl5000_rx_handler_setup,
  1221. .setup_deferred_work = iwl5000_setup_deferred_work,
  1222. .is_valid_rtc_data_addr = iwl5000_hw_valid_rtc_data_addr,
  1223. .load_ucode = iwl5000_load_ucode,
  1224. .init_alive_start = iwl5000_init_alive_start,
  1225. .alive_notify = iwl5000_alive_notify,
  1226. .send_tx_power = iwl5000_send_tx_power,
  1227. .update_chain_flags = iwl_update_chain_flags,
  1228. .apm_ops = {
  1229. .init = iwl5000_apm_init,
  1230. .reset = iwl5000_apm_reset,
  1231. .stop = iwl5000_apm_stop,
  1232. .config = iwl5000_nic_config,
  1233. .set_pwr_src = iwl_set_pwr_src,
  1234. },
  1235. .eeprom_ops = {
  1236. .regulatory_bands = {
  1237. EEPROM_5000_REG_BAND_1_CHANNELS,
  1238. EEPROM_5000_REG_BAND_2_CHANNELS,
  1239. EEPROM_5000_REG_BAND_3_CHANNELS,
  1240. EEPROM_5000_REG_BAND_4_CHANNELS,
  1241. EEPROM_5000_REG_BAND_5_CHANNELS,
  1242. EEPROM_5000_REG_BAND_24_FAT_CHANNELS,
  1243. EEPROM_5000_REG_BAND_52_FAT_CHANNELS
  1244. },
  1245. .verify_signature = iwlcore_eeprom_verify_signature,
  1246. .acquire_semaphore = iwlcore_eeprom_acquire_semaphore,
  1247. .release_semaphore = iwlcore_eeprom_release_semaphore,
  1248. .calib_version = iwl5000_eeprom_calib_version,
  1249. .query_addr = iwl5000_eeprom_query_addr,
  1250. },
  1251. .post_associate = iwl_post_associate,
  1252. .isr = iwl_isr_ict,
  1253. .config_ap = iwl_config_ap,
  1254. .temp_ops = {
  1255. .temperature = iwl5000_temperature,
  1256. .set_ct_kill = iwl5000_set_ct_threshold,
  1257. },
  1258. };
  1259. static struct iwl_lib_ops iwl5150_lib = {
  1260. .set_hw_params = iwl5000_hw_set_hw_params,
  1261. .txq_update_byte_cnt_tbl = iwl5000_txq_update_byte_cnt_tbl,
  1262. .txq_inval_byte_cnt_tbl = iwl5000_txq_inval_byte_cnt_tbl,
  1263. .txq_set_sched = iwl5000_txq_set_sched,
  1264. .txq_agg_enable = iwl5000_txq_agg_enable,
  1265. .txq_agg_disable = iwl5000_txq_agg_disable,
  1266. .txq_attach_buf_to_tfd = iwl_hw_txq_attach_buf_to_tfd,
  1267. .txq_free_tfd = iwl_hw_txq_free_tfd,
  1268. .txq_init = iwl_hw_tx_queue_init,
  1269. .rx_handler_setup = iwl5000_rx_handler_setup,
  1270. .setup_deferred_work = iwl5000_setup_deferred_work,
  1271. .is_valid_rtc_data_addr = iwl5000_hw_valid_rtc_data_addr,
  1272. .load_ucode = iwl5000_load_ucode,
  1273. .init_alive_start = iwl5000_init_alive_start,
  1274. .alive_notify = iwl5000_alive_notify,
  1275. .send_tx_power = iwl5000_send_tx_power,
  1276. .update_chain_flags = iwl_update_chain_flags,
  1277. .apm_ops = {
  1278. .init = iwl5000_apm_init,
  1279. .reset = iwl5000_apm_reset,
  1280. .stop = iwl5000_apm_stop,
  1281. .config = iwl5000_nic_config,
  1282. .set_pwr_src = iwl_set_pwr_src,
  1283. },
  1284. .eeprom_ops = {
  1285. .regulatory_bands = {
  1286. EEPROM_5000_REG_BAND_1_CHANNELS,
  1287. EEPROM_5000_REG_BAND_2_CHANNELS,
  1288. EEPROM_5000_REG_BAND_3_CHANNELS,
  1289. EEPROM_5000_REG_BAND_4_CHANNELS,
  1290. EEPROM_5000_REG_BAND_5_CHANNELS,
  1291. EEPROM_5000_REG_BAND_24_FAT_CHANNELS,
  1292. EEPROM_5000_REG_BAND_52_FAT_CHANNELS
  1293. },
  1294. .verify_signature = iwlcore_eeprom_verify_signature,
  1295. .acquire_semaphore = iwlcore_eeprom_acquire_semaphore,
  1296. .release_semaphore = iwlcore_eeprom_release_semaphore,
  1297. .calib_version = iwl5000_eeprom_calib_version,
  1298. .query_addr = iwl5000_eeprom_query_addr,
  1299. },
  1300. .post_associate = iwl_post_associate,
  1301. .isr = iwl_isr_ict,
  1302. .config_ap = iwl_config_ap,
  1303. .temp_ops = {
  1304. .temperature = iwl5150_temperature,
  1305. .set_ct_kill = iwl5150_set_ct_threshold,
  1306. },
  1307. };
  1308. struct iwl_ops iwl5000_ops = {
  1309. .lib = &iwl5000_lib,
  1310. .hcmd = &iwl5000_hcmd,
  1311. .utils = &iwl5000_hcmd_utils,
  1312. };
  1313. static struct iwl_ops iwl5150_ops = {
  1314. .lib = &iwl5150_lib,
  1315. .hcmd = &iwl5000_hcmd,
  1316. .utils = &iwl5000_hcmd_utils,
  1317. };
  1318. struct iwl_mod_params iwl50_mod_params = {
  1319. .num_of_queues = IWL50_NUM_QUEUES,
  1320. .num_of_ampdu_queues = IWL50_NUM_AMPDU_QUEUES,
  1321. .amsdu_size_8K = 1,
  1322. .restart_fw = 1,
  1323. /* the rest are 0 by default */
  1324. };
  1325. struct iwl_cfg iwl5300_agn_cfg = {
  1326. .name = "5300AGN",
  1327. .fw_name_pre = IWL5000_FW_PRE,
  1328. .ucode_api_max = IWL5000_UCODE_API_MAX,
  1329. .ucode_api_min = IWL5000_UCODE_API_MIN,
  1330. .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
  1331. .ops = &iwl5000_ops,
  1332. .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
  1333. .eeprom_ver = EEPROM_5000_EEPROM_VERSION,
  1334. .eeprom_calib_ver = EEPROM_5000_TX_POWER_VERSION,
  1335. .mod_params = &iwl50_mod_params,
  1336. .valid_tx_ant = ANT_ABC,
  1337. .valid_rx_ant = ANT_ABC,
  1338. .need_pll_cfg = true,
  1339. };
  1340. struct iwl_cfg iwl5100_bg_cfg = {
  1341. .name = "5100BG",
  1342. .fw_name_pre = IWL5000_FW_PRE,
  1343. .ucode_api_max = IWL5000_UCODE_API_MAX,
  1344. .ucode_api_min = IWL5000_UCODE_API_MIN,
  1345. .sku = IWL_SKU_G,
  1346. .ops = &iwl5000_ops,
  1347. .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
  1348. .eeprom_ver = EEPROM_5000_EEPROM_VERSION,
  1349. .eeprom_calib_ver = EEPROM_5000_TX_POWER_VERSION,
  1350. .mod_params = &iwl50_mod_params,
  1351. .valid_tx_ant = ANT_B,
  1352. .valid_rx_ant = ANT_AB,
  1353. .need_pll_cfg = true,
  1354. };
  1355. struct iwl_cfg iwl5100_abg_cfg = {
  1356. .name = "5100ABG",
  1357. .fw_name_pre = IWL5000_FW_PRE,
  1358. .ucode_api_max = IWL5000_UCODE_API_MAX,
  1359. .ucode_api_min = IWL5000_UCODE_API_MIN,
  1360. .sku = IWL_SKU_A|IWL_SKU_G,
  1361. .ops = &iwl5000_ops,
  1362. .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
  1363. .eeprom_ver = EEPROM_5000_EEPROM_VERSION,
  1364. .eeprom_calib_ver = EEPROM_5000_TX_POWER_VERSION,
  1365. .mod_params = &iwl50_mod_params,
  1366. .valid_tx_ant = ANT_B,
  1367. .valid_rx_ant = ANT_AB,
  1368. .need_pll_cfg = true,
  1369. };
  1370. struct iwl_cfg iwl5100_agn_cfg = {
  1371. .name = "5100AGN",
  1372. .fw_name_pre = IWL5000_FW_PRE,
  1373. .ucode_api_max = IWL5000_UCODE_API_MAX,
  1374. .ucode_api_min = IWL5000_UCODE_API_MIN,
  1375. .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
  1376. .ops = &iwl5000_ops,
  1377. .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
  1378. .eeprom_ver = EEPROM_5000_EEPROM_VERSION,
  1379. .eeprom_calib_ver = EEPROM_5000_TX_POWER_VERSION,
  1380. .mod_params = &iwl50_mod_params,
  1381. .valid_tx_ant = ANT_B,
  1382. .valid_rx_ant = ANT_AB,
  1383. .need_pll_cfg = true,
  1384. };
  1385. struct iwl_cfg iwl5350_agn_cfg = {
  1386. .name = "5350AGN",
  1387. .fw_name_pre = IWL5000_FW_PRE,
  1388. .ucode_api_max = IWL5000_UCODE_API_MAX,
  1389. .ucode_api_min = IWL5000_UCODE_API_MIN,
  1390. .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
  1391. .ops = &iwl5000_ops,
  1392. .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
  1393. .eeprom_ver = EEPROM_5050_EEPROM_VERSION,
  1394. .eeprom_calib_ver = EEPROM_5050_TX_POWER_VERSION,
  1395. .mod_params = &iwl50_mod_params,
  1396. .valid_tx_ant = ANT_ABC,
  1397. .valid_rx_ant = ANT_ABC,
  1398. .need_pll_cfg = true,
  1399. };
  1400. struct iwl_cfg iwl5150_agn_cfg = {
  1401. .name = "5150AGN",
  1402. .fw_name_pre = IWL5150_FW_PRE,
  1403. .ucode_api_max = IWL5150_UCODE_API_MAX,
  1404. .ucode_api_min = IWL5150_UCODE_API_MIN,
  1405. .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
  1406. .ops = &iwl5150_ops,
  1407. .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
  1408. .eeprom_ver = EEPROM_5050_EEPROM_VERSION,
  1409. .eeprom_calib_ver = EEPROM_5050_TX_POWER_VERSION,
  1410. .mod_params = &iwl50_mod_params,
  1411. .valid_tx_ant = ANT_A,
  1412. .valid_rx_ant = ANT_AB,
  1413. .need_pll_cfg = true,
  1414. };
  1415. MODULE_FIRMWARE(IWL5000_MODULE_FIRMWARE(IWL5000_UCODE_API_MAX));
  1416. MODULE_FIRMWARE(IWL5150_MODULE_FIRMWARE(IWL5150_UCODE_API_MAX));
  1417. module_param_named(swcrypto50, iwl50_mod_params.sw_crypto, bool, 0444);
  1418. MODULE_PARM_DESC(swcrypto50,
  1419. "using software crypto engine (default 0 [hardware])\n");
  1420. module_param_named(debug50, iwl50_mod_params.debug, uint, 0444);
  1421. MODULE_PARM_DESC(debug50, "50XX debug output mask");
  1422. module_param_named(queues_num50, iwl50_mod_params.num_of_queues, int, 0444);
  1423. MODULE_PARM_DESC(queues_num50, "number of hw queues in 50xx series");
  1424. module_param_named(11n_disable50, iwl50_mod_params.disable_11n, int, 0444);
  1425. MODULE_PARM_DESC(11n_disable50, "disable 50XX 11n functionality");
  1426. module_param_named(amsdu_size_8K50, iwl50_mod_params.amsdu_size_8K, int, 0444);
  1427. MODULE_PARM_DESC(amsdu_size_8K50, "enable 8K amsdu size in 50XX series");
  1428. module_param_named(fw_restart50, iwl50_mod_params.restart_fw, int, 0444);
  1429. MODULE_PARM_DESC(fw_restart50, "restart firmware in case of error");