iwl-5000.c 47 KB

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