iwl-5000.c 53 KB

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