iwl-5000.c 52 KB

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