iwl-5000.c 54 KB

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