iwl-5000.c 52 KB

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