iwl-5000.c 48 KB

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