iwl-5000.c 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774
  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-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 = (priv->cfg->chain_noise_scale *
  158. ((s32)average_noise[default_chain] -
  159. (s32)average_noise[i])) / 1500;
  160. /* bound gain by 2 bits value max, 3rd bit is sign */
  161. data->delta_gain_code[i] =
  162. min(abs(delta_g), (long) CHAIN_NOISE_MAX_DELTA_GAIN_CODE);
  163. if (delta_g < 0)
  164. /*
  165. * set negative sign ...
  166. * note to Intel developers: This is uCode API format,
  167. * not the format of any internal device registers.
  168. * Do not change this format for e.g. 6050 or similar
  169. * devices. Change format only if more resolution
  170. * (i.e. more than 2 bits magnitude) is needed.
  171. */
  172. data->delta_gain_code[i] |= (1 << 2);
  173. }
  174. IWL_DEBUG_CALIB(priv, "Delta gains: ANT_B = %d ANT_C = %d\n",
  175. data->delta_gain_code[1], data->delta_gain_code[2]);
  176. if (!data->radio_write) {
  177. struct iwl_calib_chain_noise_gain_cmd cmd;
  178. memset(&cmd, 0, sizeof(cmd));
  179. cmd.hdr.op_code = IWL_PHY_CALIBRATE_CHAIN_NOISE_GAIN_CMD;
  180. cmd.hdr.first_group = 0;
  181. cmd.hdr.groups_num = 1;
  182. cmd.hdr.data_valid = 1;
  183. cmd.delta_gain_1 = data->delta_gain_code[1];
  184. cmd.delta_gain_2 = data->delta_gain_code[2];
  185. iwl_send_cmd_pdu_async(priv, REPLY_PHY_CALIBRATION_CMD,
  186. sizeof(cmd), &cmd, NULL);
  187. data->radio_write = 1;
  188. data->state = IWL_CHAIN_NOISE_CALIBRATED;
  189. }
  190. data->chain_noise_a = 0;
  191. data->chain_noise_b = 0;
  192. data->chain_noise_c = 0;
  193. data->chain_signal_a = 0;
  194. data->chain_signal_b = 0;
  195. data->chain_signal_c = 0;
  196. data->beacon_count = 0;
  197. }
  198. static void iwl5000_chain_noise_reset(struct iwl_priv *priv)
  199. {
  200. struct iwl_chain_noise_data *data = &priv->chain_noise_data;
  201. int ret;
  202. if ((data->state == IWL_CHAIN_NOISE_ALIVE) && iwl_is_associated(priv)) {
  203. struct iwl_calib_chain_noise_reset_cmd cmd;
  204. memset(&cmd, 0, sizeof(cmd));
  205. cmd.hdr.op_code = IWL_PHY_CALIBRATE_CHAIN_NOISE_RESET_CMD;
  206. cmd.hdr.first_group = 0;
  207. cmd.hdr.groups_num = 1;
  208. cmd.hdr.data_valid = 1;
  209. ret = iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
  210. sizeof(cmd), &cmd);
  211. if (ret)
  212. IWL_ERR(priv,
  213. "Could not send REPLY_PHY_CALIBRATION_CMD\n");
  214. data->state = IWL_CHAIN_NOISE_ACCUMULATE;
  215. IWL_DEBUG_CALIB(priv, "Run chain_noise_calibrate\n");
  216. }
  217. }
  218. void iwl5000_rts_tx_cmd_flag(struct ieee80211_tx_info *info,
  219. __le32 *tx_flags)
  220. {
  221. if ((info->control.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) ||
  222. (info->control.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT))
  223. *tx_flags |= TX_CMD_FLG_RTS_CTS_MSK;
  224. else
  225. *tx_flags &= ~TX_CMD_FLG_RTS_CTS_MSK;
  226. }
  227. static struct iwl_sensitivity_ranges iwl5000_sensitivity = {
  228. .min_nrg_cck = 95,
  229. .max_nrg_cck = 0, /* not used, set to 0 */
  230. .auto_corr_min_ofdm = 90,
  231. .auto_corr_min_ofdm_mrc = 170,
  232. .auto_corr_min_ofdm_x1 = 120,
  233. .auto_corr_min_ofdm_mrc_x1 = 240,
  234. .auto_corr_max_ofdm = 120,
  235. .auto_corr_max_ofdm_mrc = 210,
  236. .auto_corr_max_ofdm_x1 = 120,
  237. .auto_corr_max_ofdm_mrc_x1 = 240,
  238. .auto_corr_min_cck = 125,
  239. .auto_corr_max_cck = 200,
  240. .auto_corr_min_cck_mrc = 170,
  241. .auto_corr_max_cck_mrc = 400,
  242. .nrg_th_cck = 95,
  243. .nrg_th_ofdm = 95,
  244. .barker_corr_th_min = 190,
  245. .barker_corr_th_min_mrc = 390,
  246. .nrg_th_cca = 62,
  247. };
  248. static struct iwl_sensitivity_ranges iwl5150_sensitivity = {
  249. .min_nrg_cck = 95,
  250. .max_nrg_cck = 0, /* not used, set to 0 */
  251. .auto_corr_min_ofdm = 90,
  252. .auto_corr_min_ofdm_mrc = 170,
  253. .auto_corr_min_ofdm_x1 = 105,
  254. .auto_corr_min_ofdm_mrc_x1 = 220,
  255. .auto_corr_max_ofdm = 120,
  256. .auto_corr_max_ofdm_mrc = 210,
  257. /* max = min for performance bug in 5150 DSP */
  258. .auto_corr_max_ofdm_x1 = 105,
  259. .auto_corr_max_ofdm_mrc_x1 = 220,
  260. .auto_corr_min_cck = 125,
  261. .auto_corr_max_cck = 200,
  262. .auto_corr_min_cck_mrc = 170,
  263. .auto_corr_max_cck_mrc = 400,
  264. .nrg_th_cck = 95,
  265. .nrg_th_ofdm = 95,
  266. .barker_corr_th_min = 190,
  267. .barker_corr_th_min_mrc = 390,
  268. .nrg_th_cca = 62,
  269. };
  270. const u8 *iwl5000_eeprom_query_addr(const struct iwl_priv *priv,
  271. size_t offset)
  272. {
  273. u32 address = eeprom_indirect_address(priv, offset);
  274. BUG_ON(address >= priv->cfg->eeprom_size);
  275. return &priv->eeprom[address];
  276. }
  277. static void iwl5150_set_ct_threshold(struct iwl_priv *priv)
  278. {
  279. const s32 volt2temp_coef = IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF;
  280. s32 threshold = (s32)CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD_LEGACY) -
  281. iwl_temp_calib_to_offset(priv);
  282. priv->hw_params.ct_kill_threshold = threshold * volt2temp_coef;
  283. }
  284. static void iwl5000_set_ct_threshold(struct iwl_priv *priv)
  285. {
  286. /* want Celsius */
  287. priv->hw_params.ct_kill_threshold = CT_KILL_THRESHOLD_LEGACY;
  288. }
  289. /*
  290. * Calibration
  291. */
  292. static int iwl5000_set_Xtal_calib(struct iwl_priv *priv)
  293. {
  294. struct iwl_calib_xtal_freq_cmd cmd;
  295. __le16 *xtal_calib =
  296. (__le16 *)iwl_eeprom_query_addr(priv, EEPROM_5000_XTAL);
  297. cmd.hdr.op_code = IWL_PHY_CALIBRATE_CRYSTAL_FRQ_CMD;
  298. cmd.hdr.first_group = 0;
  299. cmd.hdr.groups_num = 1;
  300. cmd.hdr.data_valid = 1;
  301. cmd.cap_pin1 = le16_to_cpu(xtal_calib[0]);
  302. cmd.cap_pin2 = le16_to_cpu(xtal_calib[1]);
  303. return iwl_calib_set(&priv->calib_results[IWL_CALIB_XTAL],
  304. (u8 *)&cmd, sizeof(cmd));
  305. }
  306. static int iwl5000_send_calib_cfg(struct iwl_priv *priv)
  307. {
  308. struct iwl_calib_cfg_cmd calib_cfg_cmd;
  309. struct iwl_host_cmd cmd = {
  310. .id = CALIBRATION_CFG_CMD,
  311. .len = sizeof(struct iwl_calib_cfg_cmd),
  312. .data = &calib_cfg_cmd,
  313. };
  314. memset(&calib_cfg_cmd, 0, sizeof(calib_cfg_cmd));
  315. calib_cfg_cmd.ucd_calib_cfg.once.is_enable = IWL_CALIB_INIT_CFG_ALL;
  316. calib_cfg_cmd.ucd_calib_cfg.once.start = IWL_CALIB_INIT_CFG_ALL;
  317. calib_cfg_cmd.ucd_calib_cfg.once.send_res = IWL_CALIB_INIT_CFG_ALL;
  318. calib_cfg_cmd.ucd_calib_cfg.flags = IWL_CALIB_INIT_CFG_ALL;
  319. return iwl_send_cmd(priv, &cmd);
  320. }
  321. static void iwl5000_rx_calib_result(struct iwl_priv *priv,
  322. struct iwl_rx_mem_buffer *rxb)
  323. {
  324. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  325. struct iwl_calib_hdr *hdr = (struct iwl_calib_hdr *)pkt->u.raw;
  326. int len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
  327. int index;
  328. /* reduce the size of the length field itself */
  329. len -= 4;
  330. /* Define the order in which the results will be sent to the runtime
  331. * uCode. iwl_send_calib_results sends them in a row according to their
  332. * index. We sort them here */
  333. switch (hdr->op_code) {
  334. case IWL_PHY_CALIBRATE_DC_CMD:
  335. index = IWL_CALIB_DC;
  336. break;
  337. case IWL_PHY_CALIBRATE_LO_CMD:
  338. index = IWL_CALIB_LO;
  339. break;
  340. case IWL_PHY_CALIBRATE_TX_IQ_CMD:
  341. index = IWL_CALIB_TX_IQ;
  342. break;
  343. case IWL_PHY_CALIBRATE_TX_IQ_PERD_CMD:
  344. index = IWL_CALIB_TX_IQ_PERD;
  345. break;
  346. case IWL_PHY_CALIBRATE_BASE_BAND_CMD:
  347. index = IWL_CALIB_BASE_BAND;
  348. break;
  349. default:
  350. IWL_ERR(priv, "Unknown calibration notification %d\n",
  351. hdr->op_code);
  352. return;
  353. }
  354. iwl_calib_set(&priv->calib_results[index], pkt->u.raw, len);
  355. }
  356. static void iwl5000_rx_calib_complete(struct iwl_priv *priv,
  357. struct iwl_rx_mem_buffer *rxb)
  358. {
  359. IWL_DEBUG_INFO(priv, "Init. calibration is completed, restarting fw.\n");
  360. queue_work(priv->workqueue, &priv->restart);
  361. }
  362. /*
  363. * ucode
  364. */
  365. static int iwl5000_load_section(struct iwl_priv *priv, const char *name,
  366. struct fw_desc *image, u32 dst_addr)
  367. {
  368. dma_addr_t phy_addr = image->p_addr;
  369. u32 byte_cnt = image->len;
  370. int ret;
  371. priv->ucode_write_complete = 0;
  372. iwl_write_direct32(priv,
  373. FH_TCSR_CHNL_TX_CONFIG_REG(FH_SRVC_CHNL),
  374. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE);
  375. iwl_write_direct32(priv,
  376. FH_SRVC_CHNL_SRAM_ADDR_REG(FH_SRVC_CHNL), dst_addr);
  377. iwl_write_direct32(priv,
  378. FH_TFDIB_CTRL0_REG(FH_SRVC_CHNL),
  379. phy_addr & FH_MEM_TFDIB_DRAM_ADDR_LSB_MSK);
  380. iwl_write_direct32(priv,
  381. FH_TFDIB_CTRL1_REG(FH_SRVC_CHNL),
  382. (iwl_get_dma_hi_addr(phy_addr)
  383. << FH_MEM_TFDIB_REG1_ADDR_BITSHIFT) | byte_cnt);
  384. iwl_write_direct32(priv,
  385. FH_TCSR_CHNL_TX_BUF_STS_REG(FH_SRVC_CHNL),
  386. 1 << FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_NUM |
  387. 1 << FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_IDX |
  388. FH_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_VALID);
  389. iwl_write_direct32(priv,
  390. FH_TCSR_CHNL_TX_CONFIG_REG(FH_SRVC_CHNL),
  391. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE |
  392. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_DISABLE |
  393. FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_ENDTFD);
  394. IWL_DEBUG_INFO(priv, "%s uCode section being loaded...\n", name);
  395. ret = wait_event_interruptible_timeout(priv->wait_command_queue,
  396. priv->ucode_write_complete, 5 * HZ);
  397. if (ret == -ERESTARTSYS) {
  398. IWL_ERR(priv, "Could not load the %s uCode section due "
  399. "to interrupt\n", name);
  400. return ret;
  401. }
  402. if (!ret) {
  403. IWL_ERR(priv, "Could not load the %s uCode section\n",
  404. name);
  405. return -ETIMEDOUT;
  406. }
  407. return 0;
  408. }
  409. static int iwl5000_load_given_ucode(struct iwl_priv *priv,
  410. struct fw_desc *inst_image,
  411. struct fw_desc *data_image)
  412. {
  413. int ret = 0;
  414. ret = iwl5000_load_section(priv, "INST", inst_image,
  415. IWL50_RTC_INST_LOWER_BOUND);
  416. if (ret)
  417. return ret;
  418. return iwl5000_load_section(priv, "DATA", data_image,
  419. IWL50_RTC_DATA_LOWER_BOUND);
  420. }
  421. int iwl5000_load_ucode(struct iwl_priv *priv)
  422. {
  423. int ret = 0;
  424. /* check whether init ucode should be loaded, or rather runtime ucode */
  425. if (priv->ucode_init.len && (priv->ucode_type == UCODE_NONE)) {
  426. IWL_DEBUG_INFO(priv, "Init ucode found. Loading init ucode...\n");
  427. ret = iwl5000_load_given_ucode(priv,
  428. &priv->ucode_init, &priv->ucode_init_data);
  429. if (!ret) {
  430. IWL_DEBUG_INFO(priv, "Init ucode load complete.\n");
  431. priv->ucode_type = UCODE_INIT;
  432. }
  433. } else {
  434. IWL_DEBUG_INFO(priv, "Init ucode not found, or already loaded. "
  435. "Loading runtime ucode...\n");
  436. ret = iwl5000_load_given_ucode(priv,
  437. &priv->ucode_code, &priv->ucode_data);
  438. if (!ret) {
  439. IWL_DEBUG_INFO(priv, "Runtime ucode load complete.\n");
  440. priv->ucode_type = UCODE_RT;
  441. }
  442. }
  443. return ret;
  444. }
  445. void iwl5000_init_alive_start(struct iwl_priv *priv)
  446. {
  447. int ret = 0;
  448. /* Check alive response for "valid" sign from uCode */
  449. if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
  450. /* We had an error bringing up the hardware, so take it
  451. * all the way back down so we can try again */
  452. IWL_DEBUG_INFO(priv, "Initialize Alive failed.\n");
  453. goto restart;
  454. }
  455. /* initialize uCode was loaded... verify inst image.
  456. * This is a paranoid check, because we would not have gotten the
  457. * "initialize" alive if code weren't properly loaded. */
  458. if (iwl_verify_ucode(priv)) {
  459. /* Runtime instruction load was bad;
  460. * take it all the way back down so we can try again */
  461. IWL_DEBUG_INFO(priv, "Bad \"initialize\" uCode load.\n");
  462. goto restart;
  463. }
  464. iwl_clear_stations_table(priv);
  465. ret = priv->cfg->ops->lib->alive_notify(priv);
  466. if (ret) {
  467. IWL_WARN(priv,
  468. "Could not complete ALIVE transition: %d\n", ret);
  469. goto restart;
  470. }
  471. iwl5000_send_calib_cfg(priv);
  472. return;
  473. restart:
  474. /* real restart (first load init_ucode) */
  475. queue_work(priv->workqueue, &priv->restart);
  476. }
  477. static void iwl5000_set_wr_ptrs(struct iwl_priv *priv,
  478. int txq_id, u32 index)
  479. {
  480. iwl_write_direct32(priv, HBUS_TARG_WRPTR,
  481. (index & 0xff) | (txq_id << 8));
  482. iwl_write_prph(priv, IWL50_SCD_QUEUE_RDPTR(txq_id), index);
  483. }
  484. static void iwl5000_tx_queue_set_status(struct iwl_priv *priv,
  485. struct iwl_tx_queue *txq,
  486. int tx_fifo_id, int scd_retry)
  487. {
  488. int txq_id = txq->q.id;
  489. int active = test_bit(txq_id, &priv->txq_ctx_active_msk) ? 1 : 0;
  490. iwl_write_prph(priv, IWL50_SCD_QUEUE_STATUS_BITS(txq_id),
  491. (active << IWL50_SCD_QUEUE_STTS_REG_POS_ACTIVE) |
  492. (tx_fifo_id << IWL50_SCD_QUEUE_STTS_REG_POS_TXF) |
  493. (1 << IWL50_SCD_QUEUE_STTS_REG_POS_WSL) |
  494. IWL50_SCD_QUEUE_STTS_REG_MSK);
  495. txq->sched_retry = scd_retry;
  496. IWL_DEBUG_INFO(priv, "%s %s Queue %d on AC %d\n",
  497. active ? "Activate" : "Deactivate",
  498. scd_retry ? "BA" : "AC", txq_id, tx_fifo_id);
  499. }
  500. int iwl5000_alive_notify(struct iwl_priv *priv)
  501. {
  502. u32 a;
  503. unsigned long flags;
  504. int i, chan;
  505. u32 reg_val;
  506. spin_lock_irqsave(&priv->lock, flags);
  507. priv->scd_base_addr = iwl_read_prph(priv, IWL50_SCD_SRAM_BASE_ADDR);
  508. a = priv->scd_base_addr + IWL50_SCD_CONTEXT_DATA_OFFSET;
  509. for (; a < priv->scd_base_addr + IWL50_SCD_TX_STTS_BITMAP_OFFSET;
  510. a += 4)
  511. iwl_write_targ_mem(priv, a, 0);
  512. for (; a < priv->scd_base_addr + IWL50_SCD_TRANSLATE_TBL_OFFSET;
  513. a += 4)
  514. iwl_write_targ_mem(priv, a, 0);
  515. for (; a < priv->scd_base_addr +
  516. IWL50_SCD_TRANSLATE_TBL_OFFSET_QUEUE(priv->hw_params.max_txq_num); a += 4)
  517. iwl_write_targ_mem(priv, a, 0);
  518. iwl_write_prph(priv, IWL50_SCD_DRAM_BASE_ADDR,
  519. priv->scd_bc_tbls.dma >> 10);
  520. /* Enable DMA channel */
  521. for (chan = 0; chan < FH50_TCSR_CHNL_NUM ; chan++)
  522. iwl_write_direct32(priv, FH_TCSR_CHNL_TX_CONFIG_REG(chan),
  523. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE |
  524. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE);
  525. /* Update FH chicken bits */
  526. reg_val = iwl_read_direct32(priv, FH_TX_CHICKEN_BITS_REG);
  527. iwl_write_direct32(priv, FH_TX_CHICKEN_BITS_REG,
  528. reg_val | FH_TX_CHICKEN_BITS_SCD_AUTO_RETRY_EN);
  529. iwl_write_prph(priv, IWL50_SCD_QUEUECHAIN_SEL,
  530. IWL50_SCD_QUEUECHAIN_SEL_ALL(priv->hw_params.max_txq_num));
  531. iwl_write_prph(priv, IWL50_SCD_AGGR_SEL, 0);
  532. /* initiate the queues */
  533. for (i = 0; i < priv->hw_params.max_txq_num; i++) {
  534. iwl_write_prph(priv, IWL50_SCD_QUEUE_RDPTR(i), 0);
  535. iwl_write_direct32(priv, HBUS_TARG_WRPTR, 0 | (i << 8));
  536. iwl_write_targ_mem(priv, priv->scd_base_addr +
  537. IWL50_SCD_CONTEXT_QUEUE_OFFSET(i), 0);
  538. iwl_write_targ_mem(priv, priv->scd_base_addr +
  539. IWL50_SCD_CONTEXT_QUEUE_OFFSET(i) +
  540. sizeof(u32),
  541. ((SCD_WIN_SIZE <<
  542. IWL50_SCD_QUEUE_CTX_REG2_WIN_SIZE_POS) &
  543. IWL50_SCD_QUEUE_CTX_REG2_WIN_SIZE_MSK) |
  544. ((SCD_FRAME_LIMIT <<
  545. IWL50_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) &
  546. IWL50_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK));
  547. }
  548. iwl_write_prph(priv, IWL50_SCD_INTERRUPT_MASK,
  549. IWL_MASK(0, priv->hw_params.max_txq_num));
  550. /* Activate all Tx DMA/FIFO channels */
  551. priv->cfg->ops->lib->txq_set_sched(priv, IWL_MASK(0, 7));
  552. iwl5000_set_wr_ptrs(priv, IWL_CMD_QUEUE_NUM, 0);
  553. /* make sure all queue are not stopped */
  554. memset(&priv->queue_stopped[0], 0, sizeof(priv->queue_stopped));
  555. for (i = 0; i < 4; i++)
  556. atomic_set(&priv->queue_stop_count[i], 0);
  557. /* reset to 0 to enable all the queue first */
  558. priv->txq_ctx_active_msk = 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 (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 (read_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. iwl_free_tfds_in_queue(priv, sta_id, tid, 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. iwl_free_tfds_in_queue(priv, sta_id, tid, freed);
  964. if (priv->mac80211_registered &&
  965. (iwl_queue_space(&txq->q) > txq->q.low_mark))
  966. iwl_wake_queue(priv, txq_id);
  967. }
  968. iwl_txq_check_empty(priv, sta_id, tid, txq_id);
  969. if (iwl_check_bits(status, TX_ABORT_REQUIRED_MSK))
  970. IWL_ERR(priv, "TODO: Implement Tx ABORT REQUIRED!!!\n");
  971. }
  972. /* Currently 5000 is the superset of everything */
  973. u16 iwl5000_get_hcmd_size(u8 cmd_id, u16 len)
  974. {
  975. return len;
  976. }
  977. void iwl5000_setup_deferred_work(struct iwl_priv *priv)
  978. {
  979. /* in 5000 the tx power calibration is done in uCode */
  980. priv->disable_tx_power_cal = 1;
  981. }
  982. void iwl5000_rx_handler_setup(struct iwl_priv *priv)
  983. {
  984. /* init calibration handlers */
  985. priv->rx_handlers[CALIBRATION_RES_NOTIFICATION] =
  986. iwl5000_rx_calib_result;
  987. priv->rx_handlers[CALIBRATION_COMPLETE_NOTIFICATION] =
  988. iwl5000_rx_calib_complete;
  989. priv->rx_handlers[REPLY_TX] = iwl5000_rx_reply_tx;
  990. }
  991. int iwl5000_hw_valid_rtc_data_addr(u32 addr)
  992. {
  993. return (addr >= IWL50_RTC_DATA_LOWER_BOUND) &&
  994. (addr < IWL50_RTC_DATA_UPPER_BOUND);
  995. }
  996. static int iwl5000_send_rxon_assoc(struct iwl_priv *priv)
  997. {
  998. int ret = 0;
  999. struct iwl5000_rxon_assoc_cmd rxon_assoc;
  1000. const struct iwl_rxon_cmd *rxon1 = &priv->staging_rxon;
  1001. const struct iwl_rxon_cmd *rxon2 = &priv->active_rxon;
  1002. if ((rxon1->flags == rxon2->flags) &&
  1003. (rxon1->filter_flags == rxon2->filter_flags) &&
  1004. (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
  1005. (rxon1->ofdm_ht_single_stream_basic_rates ==
  1006. rxon2->ofdm_ht_single_stream_basic_rates) &&
  1007. (rxon1->ofdm_ht_dual_stream_basic_rates ==
  1008. rxon2->ofdm_ht_dual_stream_basic_rates) &&
  1009. (rxon1->ofdm_ht_triple_stream_basic_rates ==
  1010. rxon2->ofdm_ht_triple_stream_basic_rates) &&
  1011. (rxon1->acquisition_data == rxon2->acquisition_data) &&
  1012. (rxon1->rx_chain == rxon2->rx_chain) &&
  1013. (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
  1014. IWL_DEBUG_INFO(priv, "Using current RXON_ASSOC. Not resending.\n");
  1015. return 0;
  1016. }
  1017. rxon_assoc.flags = priv->staging_rxon.flags;
  1018. rxon_assoc.filter_flags = priv->staging_rxon.filter_flags;
  1019. rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates;
  1020. rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates;
  1021. rxon_assoc.reserved1 = 0;
  1022. rxon_assoc.reserved2 = 0;
  1023. rxon_assoc.reserved3 = 0;
  1024. rxon_assoc.ofdm_ht_single_stream_basic_rates =
  1025. priv->staging_rxon.ofdm_ht_single_stream_basic_rates;
  1026. rxon_assoc.ofdm_ht_dual_stream_basic_rates =
  1027. priv->staging_rxon.ofdm_ht_dual_stream_basic_rates;
  1028. rxon_assoc.rx_chain_select_flags = priv->staging_rxon.rx_chain;
  1029. rxon_assoc.ofdm_ht_triple_stream_basic_rates =
  1030. priv->staging_rxon.ofdm_ht_triple_stream_basic_rates;
  1031. rxon_assoc.acquisition_data = priv->staging_rxon.acquisition_data;
  1032. ret = iwl_send_cmd_pdu_async(priv, REPLY_RXON_ASSOC,
  1033. sizeof(rxon_assoc), &rxon_assoc, NULL);
  1034. if (ret)
  1035. return ret;
  1036. return ret;
  1037. }
  1038. int iwl5000_send_tx_power(struct iwl_priv *priv)
  1039. {
  1040. struct iwl5000_tx_power_dbm_cmd tx_power_cmd;
  1041. u8 tx_ant_cfg_cmd;
  1042. /* half dBm need to multiply */
  1043. tx_power_cmd.global_lmt = (s8)(2 * priv->tx_power_user_lmt);
  1044. if (priv->tx_power_lmt_in_half_dbm &&
  1045. priv->tx_power_lmt_in_half_dbm < tx_power_cmd.global_lmt) {
  1046. /*
  1047. * For the newer devices which using enhanced/extend tx power
  1048. * table in EEPROM, the format is in half dBm. driver need to
  1049. * convert to dBm format before report to mac80211.
  1050. * By doing so, there is a possibility of 1/2 dBm resolution
  1051. * lost. driver will perform "round-up" operation before
  1052. * reporting, but it will cause 1/2 dBm tx power over the
  1053. * regulatory limit. Perform the checking here, if the
  1054. * "tx_power_user_lmt" is higher than EEPROM value (in
  1055. * half-dBm format), lower the tx power based on EEPROM
  1056. */
  1057. tx_power_cmd.global_lmt = priv->tx_power_lmt_in_half_dbm;
  1058. }
  1059. tx_power_cmd.flags = IWL50_TX_POWER_NO_CLOSED;
  1060. tx_power_cmd.srv_chan_lmt = IWL50_TX_POWER_AUTO;
  1061. if (IWL_UCODE_API(priv->ucode_ver) == 1)
  1062. tx_ant_cfg_cmd = REPLY_TX_POWER_DBM_CMD_V1;
  1063. else
  1064. tx_ant_cfg_cmd = REPLY_TX_POWER_DBM_CMD;
  1065. return iwl_send_cmd_pdu_async(priv, tx_ant_cfg_cmd,
  1066. sizeof(tx_power_cmd), &tx_power_cmd,
  1067. NULL);
  1068. }
  1069. void iwl5000_temperature(struct iwl_priv *priv)
  1070. {
  1071. /* store temperature from statistics (in Celsius) */
  1072. priv->temperature = le32_to_cpu(priv->statistics.general.temperature);
  1073. iwl_tt_handler(priv);
  1074. }
  1075. static void iwl5150_temperature(struct iwl_priv *priv)
  1076. {
  1077. u32 vt = 0;
  1078. s32 offset = iwl_temp_calib_to_offset(priv);
  1079. vt = le32_to_cpu(priv->statistics.general.temperature);
  1080. vt = vt / IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF + offset;
  1081. /* now vt hold the temperature in Kelvin */
  1082. priv->temperature = KELVIN_TO_CELSIUS(vt);
  1083. iwl_tt_handler(priv);
  1084. }
  1085. /* Calc max signal level (dBm) among 3 possible receivers */
  1086. int iwl5000_calc_rssi(struct iwl_priv *priv,
  1087. struct iwl_rx_phy_res *rx_resp)
  1088. {
  1089. /* data from PHY/DSP regarding signal strength, etc.,
  1090. * contents are always there, not configurable by host
  1091. */
  1092. struct iwl5000_non_cfg_phy *ncphy =
  1093. (struct iwl5000_non_cfg_phy *)rx_resp->non_cfg_phy_buf;
  1094. u32 val, rssi_a, rssi_b, rssi_c, max_rssi;
  1095. u8 agc;
  1096. val = le32_to_cpu(ncphy->non_cfg_phy[IWL50_RX_RES_AGC_IDX]);
  1097. agc = (val & IWL50_OFDM_AGC_MSK) >> IWL50_OFDM_AGC_BIT_POS;
  1098. /* Find max rssi among 3 possible receivers.
  1099. * These values are measured by the digital signal processor (DSP).
  1100. * They should stay fairly constant even as the signal strength varies,
  1101. * if the radio's automatic gain control (AGC) is working right.
  1102. * AGC value (see below) will provide the "interesting" info.
  1103. */
  1104. val = le32_to_cpu(ncphy->non_cfg_phy[IWL50_RX_RES_RSSI_AB_IDX]);
  1105. rssi_a = (val & IWL50_OFDM_RSSI_A_MSK) >> IWL50_OFDM_RSSI_A_BIT_POS;
  1106. rssi_b = (val & IWL50_OFDM_RSSI_B_MSK) >> IWL50_OFDM_RSSI_B_BIT_POS;
  1107. val = le32_to_cpu(ncphy->non_cfg_phy[IWL50_RX_RES_RSSI_C_IDX]);
  1108. rssi_c = (val & IWL50_OFDM_RSSI_C_MSK) >> IWL50_OFDM_RSSI_C_BIT_POS;
  1109. max_rssi = max_t(u32, rssi_a, rssi_b);
  1110. max_rssi = max_t(u32, max_rssi, rssi_c);
  1111. IWL_DEBUG_STATS(priv, "Rssi In A %d B %d C %d Max %d AGC dB %d\n",
  1112. rssi_a, rssi_b, rssi_c, max_rssi, agc);
  1113. /* dBm = max_rssi dB - agc dB - constant.
  1114. * Higher AGC (higher radio gain) means lower signal. */
  1115. return max_rssi - agc - IWL49_RSSI_OFFSET;
  1116. }
  1117. static int iwl5000_send_tx_ant_config(struct iwl_priv *priv, u8 valid_tx_ant)
  1118. {
  1119. struct iwl_tx_ant_config_cmd tx_ant_cmd = {
  1120. .valid = cpu_to_le32(valid_tx_ant),
  1121. };
  1122. if (IWL_UCODE_API(priv->ucode_ver) > 1) {
  1123. IWL_DEBUG_HC(priv, "select valid tx ant: %u\n", valid_tx_ant);
  1124. return iwl_send_cmd_pdu(priv, TX_ANT_CONFIGURATION_CMD,
  1125. sizeof(struct iwl_tx_ant_config_cmd),
  1126. &tx_ant_cmd);
  1127. } else {
  1128. IWL_DEBUG_HC(priv, "TX_ANT_CONFIGURATION_CMD not supported\n");
  1129. return -EOPNOTSUPP;
  1130. }
  1131. }
  1132. #define IWL5000_UCODE_GET(item) \
  1133. static u32 iwl5000_ucode_get_##item(const struct iwl_ucode_header *ucode,\
  1134. u32 api_ver) \
  1135. { \
  1136. if (api_ver <= 2) \
  1137. return le32_to_cpu(ucode->u.v1.item); \
  1138. return le32_to_cpu(ucode->u.v2.item); \
  1139. }
  1140. static u32 iwl5000_ucode_get_header_size(u32 api_ver)
  1141. {
  1142. if (api_ver <= 2)
  1143. return UCODE_HEADER_SIZE(1);
  1144. return UCODE_HEADER_SIZE(2);
  1145. }
  1146. static u32 iwl5000_ucode_get_build(const struct iwl_ucode_header *ucode,
  1147. u32 api_ver)
  1148. {
  1149. if (api_ver <= 2)
  1150. return 0;
  1151. return le32_to_cpu(ucode->u.v2.build);
  1152. }
  1153. static u8 *iwl5000_ucode_get_data(const struct iwl_ucode_header *ucode,
  1154. u32 api_ver)
  1155. {
  1156. if (api_ver <= 2)
  1157. return (u8 *) ucode->u.v1.data;
  1158. return (u8 *) ucode->u.v2.data;
  1159. }
  1160. IWL5000_UCODE_GET(inst_size);
  1161. IWL5000_UCODE_GET(data_size);
  1162. IWL5000_UCODE_GET(init_size);
  1163. IWL5000_UCODE_GET(init_data_size);
  1164. IWL5000_UCODE_GET(boot_size);
  1165. static int iwl5000_hw_channel_switch(struct iwl_priv *priv, u16 channel)
  1166. {
  1167. struct iwl5000_channel_switch_cmd cmd;
  1168. const struct iwl_channel_info *ch_info;
  1169. struct iwl_host_cmd hcmd = {
  1170. .id = REPLY_CHANNEL_SWITCH,
  1171. .len = sizeof(cmd),
  1172. .flags = CMD_SIZE_HUGE,
  1173. .data = &cmd,
  1174. };
  1175. IWL_DEBUG_11H(priv, "channel switch from %d to %d\n",
  1176. priv->active_rxon.channel, channel);
  1177. cmd.band = priv->band == IEEE80211_BAND_2GHZ;
  1178. cmd.channel = cpu_to_le16(channel);
  1179. cmd.rxon_flags = priv->staging_rxon.flags;
  1180. cmd.rxon_filter_flags = priv->staging_rxon.filter_flags;
  1181. cmd.switch_time = cpu_to_le32(priv->ucode_beacon_time);
  1182. ch_info = iwl_get_channel_info(priv, priv->band, channel);
  1183. if (ch_info)
  1184. cmd.expect_beacon = is_channel_radar(ch_info);
  1185. else {
  1186. IWL_ERR(priv, "invalid channel switch from %u to %u\n",
  1187. priv->active_rxon.channel, channel);
  1188. return -EFAULT;
  1189. }
  1190. priv->switch_rxon.channel = cpu_to_le16(channel);
  1191. priv->switch_rxon.switch_in_progress = true;
  1192. return iwl_send_cmd_sync(priv, &hcmd);
  1193. }
  1194. struct iwl_hcmd_ops iwl5000_hcmd = {
  1195. .rxon_assoc = iwl5000_send_rxon_assoc,
  1196. .commit_rxon = iwl_commit_rxon,
  1197. .set_rxon_chain = iwl_set_rxon_chain,
  1198. .set_tx_ant = iwl5000_send_tx_ant_config,
  1199. };
  1200. struct iwl_hcmd_utils_ops iwl5000_hcmd_utils = {
  1201. .get_hcmd_size = iwl5000_get_hcmd_size,
  1202. .build_addsta_hcmd = iwl5000_build_addsta_hcmd,
  1203. .gain_computation = iwl5000_gain_computation,
  1204. .chain_noise_reset = iwl5000_chain_noise_reset,
  1205. .rts_tx_cmd_flag = iwl5000_rts_tx_cmd_flag,
  1206. .calc_rssi = iwl5000_calc_rssi,
  1207. };
  1208. struct iwl_ucode_ops iwl5000_ucode = {
  1209. .get_header_size = iwl5000_ucode_get_header_size,
  1210. .get_build = iwl5000_ucode_get_build,
  1211. .get_inst_size = iwl5000_ucode_get_inst_size,
  1212. .get_data_size = iwl5000_ucode_get_data_size,
  1213. .get_init_size = iwl5000_ucode_get_init_size,
  1214. .get_init_data_size = iwl5000_ucode_get_init_data_size,
  1215. .get_boot_size = iwl5000_ucode_get_boot_size,
  1216. .get_data = iwl5000_ucode_get_data,
  1217. };
  1218. struct iwl_lib_ops iwl5000_lib = {
  1219. .set_hw_params = iwl5000_hw_set_hw_params,
  1220. .txq_update_byte_cnt_tbl = iwl5000_txq_update_byte_cnt_tbl,
  1221. .txq_inval_byte_cnt_tbl = iwl5000_txq_inval_byte_cnt_tbl,
  1222. .txq_set_sched = iwl5000_txq_set_sched,
  1223. .txq_agg_enable = iwl5000_txq_agg_enable,
  1224. .txq_agg_disable = iwl5000_txq_agg_disable,
  1225. .txq_attach_buf_to_tfd = iwl_hw_txq_attach_buf_to_tfd,
  1226. .txq_free_tfd = iwl_hw_txq_free_tfd,
  1227. .txq_init = iwl_hw_tx_queue_init,
  1228. .rx_handler_setup = iwl5000_rx_handler_setup,
  1229. .setup_deferred_work = iwl5000_setup_deferred_work,
  1230. .is_valid_rtc_data_addr = iwl5000_hw_valid_rtc_data_addr,
  1231. .dump_nic_event_log = iwl_dump_nic_event_log,
  1232. .dump_nic_error_log = iwl_dump_nic_error_log,
  1233. .dump_csr = iwl_dump_csr,
  1234. .dump_fh = iwl_dump_fh,
  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. .add_bcast_station = iwl_add_bcast_station,
  1271. };
  1272. static struct iwl_lib_ops iwl5150_lib = {
  1273. .set_hw_params = iwl5000_hw_set_hw_params,
  1274. .txq_update_byte_cnt_tbl = iwl5000_txq_update_byte_cnt_tbl,
  1275. .txq_inval_byte_cnt_tbl = iwl5000_txq_inval_byte_cnt_tbl,
  1276. .txq_set_sched = iwl5000_txq_set_sched,
  1277. .txq_agg_enable = iwl5000_txq_agg_enable,
  1278. .txq_agg_disable = iwl5000_txq_agg_disable,
  1279. .txq_attach_buf_to_tfd = iwl_hw_txq_attach_buf_to_tfd,
  1280. .txq_free_tfd = iwl_hw_txq_free_tfd,
  1281. .txq_init = iwl_hw_tx_queue_init,
  1282. .rx_handler_setup = iwl5000_rx_handler_setup,
  1283. .setup_deferred_work = iwl5000_setup_deferred_work,
  1284. .is_valid_rtc_data_addr = iwl5000_hw_valid_rtc_data_addr,
  1285. .dump_nic_event_log = iwl_dump_nic_event_log,
  1286. .dump_nic_error_log = iwl_dump_nic_error_log,
  1287. .dump_csr = iwl_dump_csr,
  1288. .load_ucode = iwl5000_load_ucode,
  1289. .init_alive_start = iwl5000_init_alive_start,
  1290. .alive_notify = iwl5000_alive_notify,
  1291. .send_tx_power = iwl5000_send_tx_power,
  1292. .update_chain_flags = iwl_update_chain_flags,
  1293. .set_channel_switch = iwl5000_hw_channel_switch,
  1294. .apm_ops = {
  1295. .init = iwl_apm_init,
  1296. .stop = iwl_apm_stop,
  1297. .config = iwl5000_nic_config,
  1298. .set_pwr_src = iwl_set_pwr_src,
  1299. },
  1300. .eeprom_ops = {
  1301. .regulatory_bands = {
  1302. EEPROM_5000_REG_BAND_1_CHANNELS,
  1303. EEPROM_5000_REG_BAND_2_CHANNELS,
  1304. EEPROM_5000_REG_BAND_3_CHANNELS,
  1305. EEPROM_5000_REG_BAND_4_CHANNELS,
  1306. EEPROM_5000_REG_BAND_5_CHANNELS,
  1307. EEPROM_5000_REG_BAND_24_HT40_CHANNELS,
  1308. EEPROM_5000_REG_BAND_52_HT40_CHANNELS
  1309. },
  1310. .verify_signature = iwlcore_eeprom_verify_signature,
  1311. .acquire_semaphore = iwlcore_eeprom_acquire_semaphore,
  1312. .release_semaphore = iwlcore_eeprom_release_semaphore,
  1313. .calib_version = iwl5000_eeprom_calib_version,
  1314. .query_addr = iwl5000_eeprom_query_addr,
  1315. },
  1316. .post_associate = iwl_post_associate,
  1317. .isr = iwl_isr_ict,
  1318. .config_ap = iwl_config_ap,
  1319. .temp_ops = {
  1320. .temperature = iwl5150_temperature,
  1321. .set_ct_kill = iwl5150_set_ct_threshold,
  1322. },
  1323. .add_bcast_station = iwl_add_bcast_station,
  1324. };
  1325. static const struct iwl_ops iwl5000_ops = {
  1326. .ucode = &iwl5000_ucode,
  1327. .lib = &iwl5000_lib,
  1328. .hcmd = &iwl5000_hcmd,
  1329. .utils = &iwl5000_hcmd_utils,
  1330. .led = &iwlagn_led_ops,
  1331. };
  1332. static const struct iwl_ops iwl5150_ops = {
  1333. .ucode = &iwl5000_ucode,
  1334. .lib = &iwl5150_lib,
  1335. .hcmd = &iwl5000_hcmd,
  1336. .utils = &iwl5000_hcmd_utils,
  1337. .led = &iwlagn_led_ops,
  1338. };
  1339. struct iwl_mod_params iwl50_mod_params = {
  1340. .amsdu_size_8K = 1,
  1341. .restart_fw = 1,
  1342. /* the rest are 0 by default */
  1343. };
  1344. struct iwl_cfg iwl5300_agn_cfg = {
  1345. .name = "5300AGN",
  1346. .fw_name_pre = IWL5000_FW_PRE,
  1347. .ucode_api_max = IWL5000_UCODE_API_MAX,
  1348. .ucode_api_min = IWL5000_UCODE_API_MIN,
  1349. .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
  1350. .ops = &iwl5000_ops,
  1351. .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
  1352. .eeprom_ver = EEPROM_5000_EEPROM_VERSION,
  1353. .eeprom_calib_ver = EEPROM_5000_TX_POWER_VERSION,
  1354. .num_of_queues = IWL50_NUM_QUEUES,
  1355. .num_of_ampdu_queues = IWL50_NUM_AMPDU_QUEUES,
  1356. .mod_params = &iwl50_mod_params,
  1357. .valid_tx_ant = ANT_ABC,
  1358. .valid_rx_ant = ANT_ABC,
  1359. .pll_cfg_val = CSR50_ANA_PLL_CFG_VAL,
  1360. .set_l0s = true,
  1361. .use_bsm = false,
  1362. .ht_greenfield_support = true,
  1363. .led_compensation = 51,
  1364. .use_rts_for_ht = true, /* use rts/cts protection */
  1365. .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
  1366. .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF,
  1367. .chain_noise_scale = 1000,
  1368. };
  1369. struct iwl_cfg iwl5100_bgn_cfg = {
  1370. .name = "5100BGN",
  1371. .fw_name_pre = IWL5000_FW_PRE,
  1372. .ucode_api_max = IWL5000_UCODE_API_MAX,
  1373. .ucode_api_min = IWL5000_UCODE_API_MIN,
  1374. .sku = IWL_SKU_G|IWL_SKU_N,
  1375. .ops = &iwl5000_ops,
  1376. .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
  1377. .eeprom_ver = EEPROM_5000_EEPROM_VERSION,
  1378. .eeprom_calib_ver = EEPROM_5000_TX_POWER_VERSION,
  1379. .num_of_queues = IWL50_NUM_QUEUES,
  1380. .num_of_ampdu_queues = IWL50_NUM_AMPDU_QUEUES,
  1381. .mod_params = &iwl50_mod_params,
  1382. .valid_tx_ant = ANT_B,
  1383. .valid_rx_ant = ANT_AB,
  1384. .pll_cfg_val = CSR50_ANA_PLL_CFG_VAL,
  1385. .set_l0s = true,
  1386. .use_bsm = false,
  1387. .ht_greenfield_support = true,
  1388. .led_compensation = 51,
  1389. .use_rts_for_ht = true, /* use rts/cts protection */
  1390. .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
  1391. .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF,
  1392. .chain_noise_scale = 1000,
  1393. };
  1394. struct iwl_cfg iwl5100_abg_cfg = {
  1395. .name = "5100ABG",
  1396. .fw_name_pre = IWL5000_FW_PRE,
  1397. .ucode_api_max = IWL5000_UCODE_API_MAX,
  1398. .ucode_api_min = IWL5000_UCODE_API_MIN,
  1399. .sku = IWL_SKU_A|IWL_SKU_G,
  1400. .ops = &iwl5000_ops,
  1401. .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
  1402. .eeprom_ver = EEPROM_5000_EEPROM_VERSION,
  1403. .eeprom_calib_ver = EEPROM_5000_TX_POWER_VERSION,
  1404. .num_of_queues = IWL50_NUM_QUEUES,
  1405. .num_of_ampdu_queues = IWL50_NUM_AMPDU_QUEUES,
  1406. .mod_params = &iwl50_mod_params,
  1407. .valid_tx_ant = ANT_B,
  1408. .valid_rx_ant = ANT_AB,
  1409. .pll_cfg_val = CSR50_ANA_PLL_CFG_VAL,
  1410. .set_l0s = true,
  1411. .use_bsm = false,
  1412. .led_compensation = 51,
  1413. .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
  1414. .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF,
  1415. .chain_noise_scale = 1000,
  1416. };
  1417. struct iwl_cfg iwl5100_agn_cfg = {
  1418. .name = "5100AGN",
  1419. .fw_name_pre = IWL5000_FW_PRE,
  1420. .ucode_api_max = IWL5000_UCODE_API_MAX,
  1421. .ucode_api_min = IWL5000_UCODE_API_MIN,
  1422. .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
  1423. .ops = &iwl5000_ops,
  1424. .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
  1425. .eeprom_ver = EEPROM_5000_EEPROM_VERSION,
  1426. .eeprom_calib_ver = EEPROM_5000_TX_POWER_VERSION,
  1427. .num_of_queues = IWL50_NUM_QUEUES,
  1428. .num_of_ampdu_queues = IWL50_NUM_AMPDU_QUEUES,
  1429. .mod_params = &iwl50_mod_params,
  1430. .valid_tx_ant = ANT_B,
  1431. .valid_rx_ant = ANT_AB,
  1432. .pll_cfg_val = CSR50_ANA_PLL_CFG_VAL,
  1433. .set_l0s = true,
  1434. .use_bsm = false,
  1435. .ht_greenfield_support = true,
  1436. .led_compensation = 51,
  1437. .use_rts_for_ht = true, /* use rts/cts protection */
  1438. .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
  1439. .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF,
  1440. .chain_noise_scale = 1000,
  1441. };
  1442. struct iwl_cfg iwl5350_agn_cfg = {
  1443. .name = "5350AGN",
  1444. .fw_name_pre = IWL5000_FW_PRE,
  1445. .ucode_api_max = IWL5000_UCODE_API_MAX,
  1446. .ucode_api_min = IWL5000_UCODE_API_MIN,
  1447. .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
  1448. .ops = &iwl5000_ops,
  1449. .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
  1450. .eeprom_ver = EEPROM_5050_EEPROM_VERSION,
  1451. .eeprom_calib_ver = EEPROM_5050_TX_POWER_VERSION,
  1452. .num_of_queues = IWL50_NUM_QUEUES,
  1453. .num_of_ampdu_queues = IWL50_NUM_AMPDU_QUEUES,
  1454. .mod_params = &iwl50_mod_params,
  1455. .valid_tx_ant = ANT_ABC,
  1456. .valid_rx_ant = ANT_ABC,
  1457. .pll_cfg_val = CSR50_ANA_PLL_CFG_VAL,
  1458. .set_l0s = true,
  1459. .use_bsm = false,
  1460. .ht_greenfield_support = true,
  1461. .led_compensation = 51,
  1462. .use_rts_for_ht = true, /* use rts/cts protection */
  1463. .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
  1464. .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF,
  1465. .chain_noise_scale = 1000,
  1466. };
  1467. struct iwl_cfg iwl5150_agn_cfg = {
  1468. .name = "5150AGN",
  1469. .fw_name_pre = IWL5150_FW_PRE,
  1470. .ucode_api_max = IWL5150_UCODE_API_MAX,
  1471. .ucode_api_min = IWL5150_UCODE_API_MIN,
  1472. .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
  1473. .ops = &iwl5150_ops,
  1474. .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
  1475. .eeprom_ver = EEPROM_5050_EEPROM_VERSION,
  1476. .eeprom_calib_ver = EEPROM_5050_TX_POWER_VERSION,
  1477. .num_of_queues = IWL50_NUM_QUEUES,
  1478. .num_of_ampdu_queues = IWL50_NUM_AMPDU_QUEUES,
  1479. .mod_params = &iwl50_mod_params,
  1480. .valid_tx_ant = ANT_A,
  1481. .valid_rx_ant = ANT_AB,
  1482. .pll_cfg_val = CSR50_ANA_PLL_CFG_VAL,
  1483. .set_l0s = true,
  1484. .use_bsm = false,
  1485. .ht_greenfield_support = true,
  1486. .led_compensation = 51,
  1487. .use_rts_for_ht = true, /* use rts/cts protection */
  1488. .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
  1489. .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF,
  1490. .chain_noise_scale = 1000,
  1491. };
  1492. struct iwl_cfg iwl5150_abg_cfg = {
  1493. .name = "5150ABG",
  1494. .fw_name_pre = IWL5150_FW_PRE,
  1495. .ucode_api_max = IWL5150_UCODE_API_MAX,
  1496. .ucode_api_min = IWL5150_UCODE_API_MIN,
  1497. .sku = IWL_SKU_A|IWL_SKU_G,
  1498. .ops = &iwl5150_ops,
  1499. .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
  1500. .eeprom_ver = EEPROM_5050_EEPROM_VERSION,
  1501. .eeprom_calib_ver = EEPROM_5050_TX_POWER_VERSION,
  1502. .num_of_queues = IWL50_NUM_QUEUES,
  1503. .num_of_ampdu_queues = IWL50_NUM_AMPDU_QUEUES,
  1504. .mod_params = &iwl50_mod_params,
  1505. .valid_tx_ant = ANT_A,
  1506. .valid_rx_ant = ANT_AB,
  1507. .pll_cfg_val = CSR50_ANA_PLL_CFG_VAL,
  1508. .set_l0s = true,
  1509. .use_bsm = false,
  1510. .led_compensation = 51,
  1511. .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
  1512. .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF,
  1513. .chain_noise_scale = 1000,
  1514. };
  1515. MODULE_FIRMWARE(IWL5000_MODULE_FIRMWARE(IWL5000_UCODE_API_MAX));
  1516. MODULE_FIRMWARE(IWL5150_MODULE_FIRMWARE(IWL5150_UCODE_API_MAX));
  1517. module_param_named(swcrypto50, iwl50_mod_params.sw_crypto, bool, S_IRUGO);
  1518. MODULE_PARM_DESC(swcrypto50,
  1519. "using software crypto engine (default 0 [hardware])\n");
  1520. module_param_named(queues_num50, iwl50_mod_params.num_of_queues, int, S_IRUGO);
  1521. MODULE_PARM_DESC(queues_num50, "number of hw queues in 50xx series");
  1522. module_param_named(11n_disable50, iwl50_mod_params.disable_11n, int, S_IRUGO);
  1523. MODULE_PARM_DESC(11n_disable50, "disable 50XX 11n functionality");
  1524. module_param_named(amsdu_size_8K50, iwl50_mod_params.amsdu_size_8K,
  1525. int, S_IRUGO);
  1526. MODULE_PARM_DESC(amsdu_size_8K50, "enable 8K amsdu size in 50XX series");
  1527. module_param_named(fw_restart50, iwl50_mod_params.restart_fw, int, S_IRUGO);
  1528. MODULE_PARM_DESC(fw_restart50, "restart firmware in case of error");