4965.h 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004
  1. /******************************************************************************
  2. *
  3. * GPL LICENSE SUMMARY
  4. *
  5. * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of version 2 of the GNU General Public License as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  19. * USA
  20. *
  21. * The full GNU General Public License is included in this distribution
  22. * in the file called LICENSE.GPL.
  23. *
  24. * Contact Information:
  25. * Intel Linux Wireless <ilw@linux.intel.com>
  26. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  27. *
  28. *****************************************************************************/
  29. #ifndef __il_4965_h__
  30. #define __il_4965_h__
  31. #include "iwl-fh.h"
  32. #include "iwl-debug.h"
  33. struct il_rx_queue;
  34. struct il_rx_buf;
  35. struct il_rx_pkt;
  36. struct il_tx_queue;
  37. struct il_rxon_context;
  38. /* configuration for the _4965 devices */
  39. extern struct il_cfg il4965_cfg;
  40. extern struct il_mod_params il4965_mod_params;
  41. extern struct ieee80211_ops il4965_hw_ops;
  42. /* tx queue */
  43. void il4965_free_tfds_in_queue(struct il_priv *il,
  44. int sta_id, int tid, int freed);
  45. /* RXON */
  46. void il4965_set_rxon_chain(struct il_priv *il,
  47. struct il_rxon_context *ctx);
  48. /* uCode */
  49. int il4965_verify_ucode(struct il_priv *il);
  50. /* lib */
  51. void il4965_check_abort_status(struct il_priv *il,
  52. u8 frame_count, u32 status);
  53. void il4965_rx_queue_reset(struct il_priv *il, struct il_rx_queue *rxq);
  54. int il4965_rx_init(struct il_priv *il, struct il_rx_queue *rxq);
  55. int il4965_hw_nic_init(struct il_priv *il);
  56. int il4965_dump_fh(struct il_priv *il, char **buf, bool display);
  57. /* rx */
  58. void il4965_rx_queue_restock(struct il_priv *il);
  59. void il4965_rx_replenish(struct il_priv *il);
  60. void il4965_rx_replenish_now(struct il_priv *il);
  61. void il4965_rx_queue_free(struct il_priv *il, struct il_rx_queue *rxq);
  62. int il4965_rxq_stop(struct il_priv *il);
  63. int il4965_hwrate_to_mac80211_idx(u32 rate_n_flags, enum ieee80211_band band);
  64. void il4965_rx_reply_rx(struct il_priv *il,
  65. struct il_rx_buf *rxb);
  66. void il4965_rx_reply_rx_phy(struct il_priv *il,
  67. struct il_rx_buf *rxb);
  68. void il4965_rx_handle(struct il_priv *il);
  69. /* tx */
  70. void il4965_hw_txq_free_tfd(struct il_priv *il, struct il_tx_queue *txq);
  71. int il4965_hw_txq_attach_buf_to_tfd(struct il_priv *il,
  72. struct il_tx_queue *txq,
  73. dma_addr_t addr, u16 len, u8 reset, u8 pad);
  74. int il4965_hw_tx_queue_init(struct il_priv *il,
  75. struct il_tx_queue *txq);
  76. void il4965_hwrate_to_tx_control(struct il_priv *il, u32 rate_n_flags,
  77. struct ieee80211_tx_info *info);
  78. int il4965_tx_skb(struct il_priv *il, struct sk_buff *skb);
  79. int il4965_tx_agg_start(struct il_priv *il, struct ieee80211_vif *vif,
  80. struct ieee80211_sta *sta, u16 tid, u16 *ssn);
  81. int il4965_tx_agg_stop(struct il_priv *il, struct ieee80211_vif *vif,
  82. struct ieee80211_sta *sta, u16 tid);
  83. int il4965_txq_check_empty(struct il_priv *il,
  84. int sta_id, u8 tid, int txq_id);
  85. void il4965_rx_reply_compressed_ba(struct il_priv *il,
  86. struct il_rx_buf *rxb);
  87. int il4965_tx_queue_reclaim(struct il_priv *il, int txq_id, int idx);
  88. void il4965_hw_txq_ctx_free(struct il_priv *il);
  89. int il4965_txq_ctx_alloc(struct il_priv *il);
  90. void il4965_txq_ctx_reset(struct il_priv *il);
  91. void il4965_txq_ctx_stop(struct il_priv *il);
  92. void il4965_txq_set_sched(struct il_priv *il, u32 mask);
  93. /*
  94. * Acquire il->lock before calling this function !
  95. */
  96. void il4965_set_wr_ptrs(struct il_priv *il, int txq_id, u32 idx);
  97. /**
  98. * il4965_tx_queue_set_status - (optionally) start Tx/Cmd queue
  99. * @tx_fifo_id: Tx DMA/FIFO channel (range 0-7) that the queue will feed
  100. * @scd_retry: (1) Indicates queue will be used in aggregation mode
  101. *
  102. * NOTE: Acquire il->lock before calling this function !
  103. */
  104. void il4965_tx_queue_set_status(struct il_priv *il,
  105. struct il_tx_queue *txq,
  106. int tx_fifo_id, int scd_retry);
  107. u8 il4965_toggle_tx_ant(struct il_priv *il, u8 ant_idx, u8 valid);
  108. /* rx */
  109. void il4965_rx_missed_beacon_notif(struct il_priv *il,
  110. struct il_rx_buf *rxb);
  111. bool il4965_good_plcp_health(struct il_priv *il,
  112. struct il_rx_pkt *pkt);
  113. void il4965_rx_stats(struct il_priv *il,
  114. struct il_rx_buf *rxb);
  115. void il4965_reply_stats(struct il_priv *il,
  116. struct il_rx_buf *rxb);
  117. /* scan */
  118. int il4965_request_scan(struct il_priv *il, struct ieee80211_vif *vif);
  119. /* station mgmt */
  120. int il4965_manage_ibss_station(struct il_priv *il,
  121. struct ieee80211_vif *vif, bool add);
  122. /* hcmd */
  123. int il4965_send_beacon_cmd(struct il_priv *il);
  124. #ifdef CONFIG_IWLEGACY_DEBUG
  125. const char *il4965_get_tx_fail_reason(u32 status);
  126. #else
  127. static inline const char *
  128. il4965_get_tx_fail_reason(u32 status) { return ""; }
  129. #endif
  130. /* station management */
  131. int il4965_alloc_bcast_station(struct il_priv *il,
  132. struct il_rxon_context *ctx);
  133. int il4965_add_bssid_station(struct il_priv *il,
  134. struct il_rxon_context *ctx,
  135. const u8 *addr, u8 *sta_id_r);
  136. int il4965_remove_default_wep_key(struct il_priv *il,
  137. struct il_rxon_context *ctx,
  138. struct ieee80211_key_conf *key);
  139. int il4965_set_default_wep_key(struct il_priv *il,
  140. struct il_rxon_context *ctx,
  141. struct ieee80211_key_conf *key);
  142. int il4965_restore_default_wep_keys(struct il_priv *il,
  143. struct il_rxon_context *ctx);
  144. int il4965_set_dynamic_key(struct il_priv *il,
  145. struct il_rxon_context *ctx,
  146. struct ieee80211_key_conf *key, u8 sta_id);
  147. int il4965_remove_dynamic_key(struct il_priv *il,
  148. struct il_rxon_context *ctx,
  149. struct ieee80211_key_conf *key, u8 sta_id);
  150. void il4965_update_tkip_key(struct il_priv *il,
  151. struct il_rxon_context *ctx,
  152. struct ieee80211_key_conf *keyconf,
  153. struct ieee80211_sta *sta, u32 iv32, u16 *phase1key);
  154. int il4965_sta_tx_modify_enable_tid(struct il_priv *il,
  155. int sta_id, int tid);
  156. int il4965_sta_rx_agg_start(struct il_priv *il, struct ieee80211_sta *sta,
  157. int tid, u16 ssn);
  158. int il4965_sta_rx_agg_stop(struct il_priv *il, struct ieee80211_sta *sta,
  159. int tid);
  160. void il4965_sta_modify_sleep_tx_count(struct il_priv *il,
  161. int sta_id, int cnt);
  162. int il4965_update_bcast_stations(struct il_priv *il);
  163. /* rate */
  164. static inline u8 il4965_hw_get_rate(__le32 rate_n_flags)
  165. {
  166. return le32_to_cpu(rate_n_flags) & 0xFF;
  167. }
  168. static inline __le32 il4965_hw_set_rate_n_flags(u8 rate, u32 flags)
  169. {
  170. return cpu_to_le32(flags|(u32)rate);
  171. }
  172. /* eeprom */
  173. void il4965_eeprom_get_mac(const struct il_priv *il, u8 *mac);
  174. int il4965_eeprom_acquire_semaphore(struct il_priv *il);
  175. void il4965_eeprom_release_semaphore(struct il_priv *il);
  176. int il4965_eeprom_check_version(struct il_priv *il);
  177. /* mac80211 handlers (for 4965) */
  178. void il4965_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb);
  179. int il4965_mac_start(struct ieee80211_hw *hw);
  180. void il4965_mac_stop(struct ieee80211_hw *hw);
  181. void il4965_configure_filter(struct ieee80211_hw *hw,
  182. unsigned int changed_flags,
  183. unsigned int *total_flags,
  184. u64 multicast);
  185. int il4965_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  186. struct ieee80211_vif *vif, struct ieee80211_sta *sta,
  187. struct ieee80211_key_conf *key);
  188. void il4965_mac_update_tkip_key(struct ieee80211_hw *hw,
  189. struct ieee80211_vif *vif,
  190. struct ieee80211_key_conf *keyconf,
  191. struct ieee80211_sta *sta,
  192. u32 iv32, u16 *phase1key);
  193. int il4965_mac_ampdu_action(struct ieee80211_hw *hw,
  194. struct ieee80211_vif *vif,
  195. enum ieee80211_ampdu_mlme_action action,
  196. struct ieee80211_sta *sta, u16 tid, u16 *ssn,
  197. u8 buf_size);
  198. int il4965_mac_sta_add(struct ieee80211_hw *hw,
  199. struct ieee80211_vif *vif,
  200. struct ieee80211_sta *sta);
  201. void il4965_mac_channel_switch(struct ieee80211_hw *hw,
  202. struct ieee80211_channel_switch *ch_switch);
  203. void il4965_led_enable(struct il_priv *il);
  204. /* EEPROM */
  205. #define IL4965_EEPROM_IMG_SIZE 1024
  206. /*
  207. * uCode queue management definitions ...
  208. * The first queue used for block-ack aggregation is #7 (4965 only).
  209. * All block-ack aggregation queues should map to Tx DMA/FIFO channel 7.
  210. */
  211. #define IL49_FIRST_AMPDU_QUEUE 7
  212. /* Sizes and addresses for instruction and data memory (SRAM) in
  213. * 4965's embedded processor. Driver access is via HBUS_TARG_MEM_* regs. */
  214. #define IL49_RTC_INST_LOWER_BOUND (0x000000)
  215. #define IL49_RTC_INST_UPPER_BOUND (0x018000)
  216. #define IL49_RTC_DATA_LOWER_BOUND (0x800000)
  217. #define IL49_RTC_DATA_UPPER_BOUND (0x80A000)
  218. #define IL49_RTC_INST_SIZE (IL49_RTC_INST_UPPER_BOUND - \
  219. IL49_RTC_INST_LOWER_BOUND)
  220. #define IL49_RTC_DATA_SIZE (IL49_RTC_DATA_UPPER_BOUND - \
  221. IL49_RTC_DATA_LOWER_BOUND)
  222. #define IL49_MAX_INST_SIZE IL49_RTC_INST_SIZE
  223. #define IL49_MAX_DATA_SIZE IL49_RTC_DATA_SIZE
  224. /* Size of uCode instruction memory in bootstrap state machine */
  225. #define IL49_MAX_BSM_SIZE BSM_SRAM_SIZE
  226. static inline int il4965_hw_valid_rtc_data_addr(u32 addr)
  227. {
  228. return (addr >= IL49_RTC_DATA_LOWER_BOUND &&
  229. addr < IL49_RTC_DATA_UPPER_BOUND);
  230. }
  231. /********************* START TEMPERATURE *************************************/
  232. /**
  233. * 4965 temperature calculation.
  234. *
  235. * The driver must calculate the device temperature before calculating
  236. * a txpower setting (amplifier gain is temperature dependent). The
  237. * calculation uses 4 measurements, 3 of which (R1, R2, R3) are calibration
  238. * values used for the life of the driver, and one of which (R4) is the
  239. * real-time temperature indicator.
  240. *
  241. * uCode provides all 4 values to the driver via the "initialize alive"
  242. * notification (see struct il4965_init_alive_resp). After the runtime uCode
  243. * image loads, uCode updates the R4 value via stats notifications
  244. * (see STATISTICS_NOTIFICATION), which occur after each received beacon
  245. * when associated, or can be requested via REPLY_STATISTICS_CMD.
  246. *
  247. * NOTE: uCode provides the R4 value as a 23-bit signed value. Driver
  248. * must sign-extend to 32 bits before applying formula below.
  249. *
  250. * Formula:
  251. *
  252. * degrees Kelvin = ((97 * 259 * (R4 - R2) / (R3 - R1)) / 100) + 8
  253. *
  254. * NOTE: The basic formula is 259 * (R4-R2) / (R3-R1). The 97/100 is
  255. * an additional correction, which should be centered around 0 degrees
  256. * Celsius (273 degrees Kelvin). The 8 (3 percent of 273) compensates for
  257. * centering the 97/100 correction around 0 degrees K.
  258. *
  259. * Add 273 to Kelvin value to find degrees Celsius, for comparing current
  260. * temperature with factory-measured temperatures when calculating txpower
  261. * settings.
  262. */
  263. #define TEMPERATURE_CALIB_KELVIN_OFFSET 8
  264. #define TEMPERATURE_CALIB_A_VAL 259
  265. /* Limit range of calculated temperature to be between these Kelvin values */
  266. #define IL_TX_POWER_TEMPERATURE_MIN (263)
  267. #define IL_TX_POWER_TEMPERATURE_MAX (410)
  268. #define IL_TX_POWER_TEMPERATURE_OUT_OF_RANGE(t) \
  269. ((t) < IL_TX_POWER_TEMPERATURE_MIN || \
  270. (t) > IL_TX_POWER_TEMPERATURE_MAX)
  271. /********************* END TEMPERATURE ***************************************/
  272. /********************* START TXPOWER *****************************************/
  273. /**
  274. * 4965 txpower calculations rely on information from three sources:
  275. *
  276. * 1) EEPROM
  277. * 2) "initialize" alive notification
  278. * 3) stats notifications
  279. *
  280. * EEPROM data consists of:
  281. *
  282. * 1) Regulatory information (max txpower and channel usage flags) is provided
  283. * separately for each channel that can possibly supported by 4965.
  284. * 40 MHz wide (.11n HT40) channels are listed separately from 20 MHz
  285. * (legacy) channels.
  286. *
  287. * See struct il4965_eeprom_channel for format, and struct il4965_eeprom
  288. * for locations in EEPROM.
  289. *
  290. * 2) Factory txpower calibration information is provided separately for
  291. * sub-bands of contiguous channels. 2.4GHz has just one sub-band,
  292. * but 5 GHz has several sub-bands.
  293. *
  294. * In addition, per-band (2.4 and 5 Ghz) saturation txpowers are provided.
  295. *
  296. * See struct il4965_eeprom_calib_info (and the tree of structures
  297. * contained within it) for format, and struct il4965_eeprom for
  298. * locations in EEPROM.
  299. *
  300. * "Initialization alive" notification (see struct il4965_init_alive_resp)
  301. * consists of:
  302. *
  303. * 1) Temperature calculation parameters.
  304. *
  305. * 2) Power supply voltage measurement.
  306. *
  307. * 3) Tx gain compensation to balance 2 transmitters for MIMO use.
  308. *
  309. * Statistics notifications deliver:
  310. *
  311. * 1) Current values for temperature param R4.
  312. */
  313. /**
  314. * To calculate a txpower setting for a given desired target txpower, channel,
  315. * modulation bit rate, and transmitter chain (4965 has 2 transmitters to
  316. * support MIMO and transmit diversity), driver must do the following:
  317. *
  318. * 1) Compare desired txpower vs. (EEPROM) regulatory limit for this channel.
  319. * Do not exceed regulatory limit; reduce target txpower if necessary.
  320. *
  321. * If setting up txpowers for MIMO rates (rate idxes 8-15, 24-31),
  322. * 2 transmitters will be used simultaneously; driver must reduce the
  323. * regulatory limit by 3 dB (half-power) for each transmitter, so the
  324. * combined total output of the 2 transmitters is within regulatory limits.
  325. *
  326. *
  327. * 2) Compare target txpower vs. (EEPROM) saturation txpower *reduced by
  328. * backoff for this bit rate*. Do not exceed (saturation - backoff[rate]);
  329. * reduce target txpower if necessary.
  330. *
  331. * Backoff values below are in 1/2 dB units (equivalent to steps in
  332. * txpower gain tables):
  333. *
  334. * OFDM 6 - 36 MBit: 10 steps (5 dB)
  335. * OFDM 48 MBit: 15 steps (7.5 dB)
  336. * OFDM 54 MBit: 17 steps (8.5 dB)
  337. * OFDM 60 MBit: 20 steps (10 dB)
  338. * CCK all rates: 10 steps (5 dB)
  339. *
  340. * Backoff values apply to saturation txpower on a per-transmitter basis;
  341. * when using MIMO (2 transmitters), each transmitter uses the same
  342. * saturation level provided in EEPROM, and the same backoff values;
  343. * no reduction (such as with regulatory txpower limits) is required.
  344. *
  345. * Saturation and Backoff values apply equally to 20 Mhz (legacy) channel
  346. * widths and 40 Mhz (.11n HT40) channel widths; there is no separate
  347. * factory measurement for ht40 channels.
  348. *
  349. * The result of this step is the final target txpower. The rest of
  350. * the steps figure out the proper settings for the device to achieve
  351. * that target txpower.
  352. *
  353. *
  354. * 3) Determine (EEPROM) calibration sub band for the target channel, by
  355. * comparing against first and last channels in each sub band
  356. * (see struct il4965_eeprom_calib_subband_info).
  357. *
  358. *
  359. * 4) Linearly interpolate (EEPROM) factory calibration measurement sets,
  360. * referencing the 2 factory-measured (sample) channels within the sub band.
  361. *
  362. * Interpolation is based on difference between target channel's frequency
  363. * and the sample channels' frequencies. Since channel numbers are based
  364. * on frequency (5 MHz between each channel number), this is equivalent
  365. * to interpolating based on channel number differences.
  366. *
  367. * Note that the sample channels may or may not be the channels at the
  368. * edges of the sub band. The target channel may be "outside" of the
  369. * span of the sampled channels.
  370. *
  371. * Driver may choose the pair (for 2 Tx chains) of measurements (see
  372. * struct il4965_eeprom_calib_ch_info) for which the actual measured
  373. * txpower comes closest to the desired txpower. Usually, though,
  374. * the middle set of measurements is closest to the regulatory limits,
  375. * and is therefore a good choice for all txpower calculations (this
  376. * assumes that high accuracy is needed for maximizing legal txpower,
  377. * while lower txpower configurations do not need as much accuracy).
  378. *
  379. * Driver should interpolate both members of the chosen measurement pair,
  380. * i.e. for both Tx chains (radio transmitters), unless the driver knows
  381. * that only one of the chains will be used (e.g. only one tx antenna
  382. * connected, but this should be unusual). The rate scaling algorithm
  383. * switches antennas to find best performance, so both Tx chains will
  384. * be used (although only one at a time) even for non-MIMO transmissions.
  385. *
  386. * Driver should interpolate factory values for temperature, gain table
  387. * idx, and actual power. The power amplifier detector values are
  388. * not used by the driver.
  389. *
  390. * Sanity check: If the target channel happens to be one of the sample
  391. * channels, the results should agree with the sample channel's
  392. * measurements!
  393. *
  394. *
  395. * 5) Find difference between desired txpower and (interpolated)
  396. * factory-measured txpower. Using (interpolated) factory gain table idx
  397. * (shown elsewhere) as a starting point, adjust this idx lower to
  398. * increase txpower, or higher to decrease txpower, until the target
  399. * txpower is reached. Each step in the gain table is 1/2 dB.
  400. *
  401. * For example, if factory measured txpower is 16 dBm, and target txpower
  402. * is 13 dBm, add 6 steps to the factory gain idx to reduce txpower
  403. * by 3 dB.
  404. *
  405. *
  406. * 6) Find difference between current device temperature and (interpolated)
  407. * factory-measured temperature for sub-band. Factory values are in
  408. * degrees Celsius. To calculate current temperature, see comments for
  409. * "4965 temperature calculation".
  410. *
  411. * If current temperature is higher than factory temperature, driver must
  412. * increase gain (lower gain table idx), and vice verse.
  413. *
  414. * Temperature affects gain differently for different channels:
  415. *
  416. * 2.4 GHz all channels: 3.5 degrees per half-dB step
  417. * 5 GHz channels 34-43: 4.5 degrees per half-dB step
  418. * 5 GHz channels >= 44: 4.0 degrees per half-dB step
  419. *
  420. * NOTE: Temperature can increase rapidly when transmitting, especially
  421. * with heavy traffic at high txpowers. Driver should update
  422. * temperature calculations often under these conditions to
  423. * maintain strong txpower in the face of rising temperature.
  424. *
  425. *
  426. * 7) Find difference between current power supply voltage indicator
  427. * (from "initialize alive") and factory-measured power supply voltage
  428. * indicator (EEPROM).
  429. *
  430. * If the current voltage is higher (indicator is lower) than factory
  431. * voltage, gain should be reduced (gain table idx increased) by:
  432. *
  433. * (eeprom - current) / 7
  434. *
  435. * If the current voltage is lower (indicator is higher) than factory
  436. * voltage, gain should be increased (gain table idx decreased) by:
  437. *
  438. * 2 * (current - eeprom) / 7
  439. *
  440. * If number of idx steps in either direction turns out to be > 2,
  441. * something is wrong ... just use 0.
  442. *
  443. * NOTE: Voltage compensation is independent of band/channel.
  444. *
  445. * NOTE: "Initialize" uCode measures current voltage, which is assumed
  446. * to be constant after this initial measurement. Voltage
  447. * compensation for txpower (number of steps in gain table)
  448. * may be calculated once and used until the next uCode bootload.
  449. *
  450. *
  451. * 8) If setting up txpowers for MIMO rates (rate idxes 8-15, 24-31),
  452. * adjust txpower for each transmitter chain, so txpower is balanced
  453. * between the two chains. There are 5 pairs of tx_atten[group][chain]
  454. * values in "initialize alive", one pair for each of 5 channel ranges:
  455. *
  456. * Group 0: 5 GHz channel 34-43
  457. * Group 1: 5 GHz channel 44-70
  458. * Group 2: 5 GHz channel 71-124
  459. * Group 3: 5 GHz channel 125-200
  460. * Group 4: 2.4 GHz all channels
  461. *
  462. * Add the tx_atten[group][chain] value to the idx for the target chain.
  463. * The values are signed, but are in pairs of 0 and a non-negative number,
  464. * so as to reduce gain (if necessary) of the "hotter" channel. This
  465. * avoids any need to double-check for regulatory compliance after
  466. * this step.
  467. *
  468. *
  469. * 9) If setting up for a CCK rate, lower the gain by adding a CCK compensation
  470. * value to the idx:
  471. *
  472. * Hardware rev B: 9 steps (4.5 dB)
  473. * Hardware rev C: 5 steps (2.5 dB)
  474. *
  475. * Hardware rev for 4965 can be determined by reading CSR_HW_REV_WA_REG,
  476. * bits [3:2], 1 = B, 2 = C.
  477. *
  478. * NOTE: This compensation is in addition to any saturation backoff that
  479. * might have been applied in an earlier step.
  480. *
  481. *
  482. * 10) Select the gain table, based on band (2.4 vs 5 GHz).
  483. *
  484. * Limit the adjusted idx to stay within the table!
  485. *
  486. *
  487. * 11) Read gain table entries for DSP and radio gain, place into appropriate
  488. * location(s) in command (struct il4965_txpowertable_cmd).
  489. */
  490. /**
  491. * When MIMO is used (2 transmitters operating simultaneously), driver should
  492. * limit each transmitter to deliver a max of 3 dB below the regulatory limit
  493. * for the device. That is, use half power for each transmitter, so total
  494. * txpower is within regulatory limits.
  495. *
  496. * The value "6" represents number of steps in gain table to reduce power 3 dB.
  497. * Each step is 1/2 dB.
  498. */
  499. #define IL_TX_POWER_MIMO_REGULATORY_COMPENSATION (6)
  500. /**
  501. * CCK gain compensation.
  502. *
  503. * When calculating txpowers for CCK, after making sure that the target power
  504. * is within regulatory and saturation limits, driver must additionally
  505. * back off gain by adding these values to the gain table idx.
  506. *
  507. * Hardware rev for 4965 can be determined by reading CSR_HW_REV_WA_REG,
  508. * bits [3:2], 1 = B, 2 = C.
  509. */
  510. #define IL_TX_POWER_CCK_COMPENSATION_B_STEP (9)
  511. #define IL_TX_POWER_CCK_COMPENSATION_C_STEP (5)
  512. /*
  513. * 4965 power supply voltage compensation for txpower
  514. */
  515. #define TX_POWER_IL_VOLTAGE_CODES_PER_03V (7)
  516. /**
  517. * Gain tables.
  518. *
  519. * The following tables contain pair of values for setting txpower, i.e.
  520. * gain settings for the output of the device's digital signal processor (DSP),
  521. * and for the analog gain structure of the transmitter.
  522. *
  523. * Each entry in the gain tables represents a step of 1/2 dB. Note that these
  524. * are *relative* steps, not indications of absolute output power. Output
  525. * power varies with temperature, voltage, and channel frequency, and also
  526. * requires consideration of average power (to satisfy regulatory constraints),
  527. * and peak power (to avoid distortion of the output signal).
  528. *
  529. * Each entry contains two values:
  530. * 1) DSP gain (or sometimes called DSP attenuation). This is a fine-grained
  531. * linear value that multiplies the output of the digital signal processor,
  532. * before being sent to the analog radio.
  533. * 2) Radio gain. This sets the analog gain of the radio Tx path.
  534. * It is a coarser setting, and behaves in a logarithmic (dB) fashion.
  535. *
  536. * EEPROM contains factory calibration data for txpower. This maps actual
  537. * measured txpower levels to gain settings in the "well known" tables
  538. * below ("well-known" means here that both factory calibration *and* the
  539. * driver work with the same table).
  540. *
  541. * There are separate tables for 2.4 GHz and 5 GHz bands. The 5 GHz table
  542. * has an extension (into negative idxes), in case the driver needs to
  543. * boost power setting for high device temperatures (higher than would be
  544. * present during factory calibration). A 5 Ghz EEPROM idx of "40"
  545. * corresponds to the 49th entry in the table used by the driver.
  546. */
  547. #define MIN_TX_GAIN_IDX (0) /* highest gain, lowest idx, 2.4 */
  548. #define MIN_TX_GAIN_IDX_52GHZ_EXT (-9) /* highest gain, lowest idx, 5 */
  549. /**
  550. * 2.4 GHz gain table
  551. *
  552. * Index Dsp gain Radio gain
  553. * 0 110 0x3f (highest gain)
  554. * 1 104 0x3f
  555. * 2 98 0x3f
  556. * 3 110 0x3e
  557. * 4 104 0x3e
  558. * 5 98 0x3e
  559. * 6 110 0x3d
  560. * 7 104 0x3d
  561. * 8 98 0x3d
  562. * 9 110 0x3c
  563. * 10 104 0x3c
  564. * 11 98 0x3c
  565. * 12 110 0x3b
  566. * 13 104 0x3b
  567. * 14 98 0x3b
  568. * 15 110 0x3a
  569. * 16 104 0x3a
  570. * 17 98 0x3a
  571. * 18 110 0x39
  572. * 19 104 0x39
  573. * 20 98 0x39
  574. * 21 110 0x38
  575. * 22 104 0x38
  576. * 23 98 0x38
  577. * 24 110 0x37
  578. * 25 104 0x37
  579. * 26 98 0x37
  580. * 27 110 0x36
  581. * 28 104 0x36
  582. * 29 98 0x36
  583. * 30 110 0x35
  584. * 31 104 0x35
  585. * 32 98 0x35
  586. * 33 110 0x34
  587. * 34 104 0x34
  588. * 35 98 0x34
  589. * 36 110 0x33
  590. * 37 104 0x33
  591. * 38 98 0x33
  592. * 39 110 0x32
  593. * 40 104 0x32
  594. * 41 98 0x32
  595. * 42 110 0x31
  596. * 43 104 0x31
  597. * 44 98 0x31
  598. * 45 110 0x30
  599. * 46 104 0x30
  600. * 47 98 0x30
  601. * 48 110 0x6
  602. * 49 104 0x6
  603. * 50 98 0x6
  604. * 51 110 0x5
  605. * 52 104 0x5
  606. * 53 98 0x5
  607. * 54 110 0x4
  608. * 55 104 0x4
  609. * 56 98 0x4
  610. * 57 110 0x3
  611. * 58 104 0x3
  612. * 59 98 0x3
  613. * 60 110 0x2
  614. * 61 104 0x2
  615. * 62 98 0x2
  616. * 63 110 0x1
  617. * 64 104 0x1
  618. * 65 98 0x1
  619. * 66 110 0x0
  620. * 67 104 0x0
  621. * 68 98 0x0
  622. * 69 97 0
  623. * 70 96 0
  624. * 71 95 0
  625. * 72 94 0
  626. * 73 93 0
  627. * 74 92 0
  628. * 75 91 0
  629. * 76 90 0
  630. * 77 89 0
  631. * 78 88 0
  632. * 79 87 0
  633. * 80 86 0
  634. * 81 85 0
  635. * 82 84 0
  636. * 83 83 0
  637. * 84 82 0
  638. * 85 81 0
  639. * 86 80 0
  640. * 87 79 0
  641. * 88 78 0
  642. * 89 77 0
  643. * 90 76 0
  644. * 91 75 0
  645. * 92 74 0
  646. * 93 73 0
  647. * 94 72 0
  648. * 95 71 0
  649. * 96 70 0
  650. * 97 69 0
  651. * 98 68 0
  652. */
  653. /**
  654. * 5 GHz gain table
  655. *
  656. * Index Dsp gain Radio gain
  657. * -9 123 0x3F (highest gain)
  658. * -8 117 0x3F
  659. * -7 110 0x3F
  660. * -6 104 0x3F
  661. * -5 98 0x3F
  662. * -4 110 0x3E
  663. * -3 104 0x3E
  664. * -2 98 0x3E
  665. * -1 110 0x3D
  666. * 0 104 0x3D
  667. * 1 98 0x3D
  668. * 2 110 0x3C
  669. * 3 104 0x3C
  670. * 4 98 0x3C
  671. * 5 110 0x3B
  672. * 6 104 0x3B
  673. * 7 98 0x3B
  674. * 8 110 0x3A
  675. * 9 104 0x3A
  676. * 10 98 0x3A
  677. * 11 110 0x39
  678. * 12 104 0x39
  679. * 13 98 0x39
  680. * 14 110 0x38
  681. * 15 104 0x38
  682. * 16 98 0x38
  683. * 17 110 0x37
  684. * 18 104 0x37
  685. * 19 98 0x37
  686. * 20 110 0x36
  687. * 21 104 0x36
  688. * 22 98 0x36
  689. * 23 110 0x35
  690. * 24 104 0x35
  691. * 25 98 0x35
  692. * 26 110 0x34
  693. * 27 104 0x34
  694. * 28 98 0x34
  695. * 29 110 0x33
  696. * 30 104 0x33
  697. * 31 98 0x33
  698. * 32 110 0x32
  699. * 33 104 0x32
  700. * 34 98 0x32
  701. * 35 110 0x31
  702. * 36 104 0x31
  703. * 37 98 0x31
  704. * 38 110 0x30
  705. * 39 104 0x30
  706. * 40 98 0x30
  707. * 41 110 0x25
  708. * 42 104 0x25
  709. * 43 98 0x25
  710. * 44 110 0x24
  711. * 45 104 0x24
  712. * 46 98 0x24
  713. * 47 110 0x23
  714. * 48 104 0x23
  715. * 49 98 0x23
  716. * 50 110 0x22
  717. * 51 104 0x18
  718. * 52 98 0x18
  719. * 53 110 0x17
  720. * 54 104 0x17
  721. * 55 98 0x17
  722. * 56 110 0x16
  723. * 57 104 0x16
  724. * 58 98 0x16
  725. * 59 110 0x15
  726. * 60 104 0x15
  727. * 61 98 0x15
  728. * 62 110 0x14
  729. * 63 104 0x14
  730. * 64 98 0x14
  731. * 65 110 0x13
  732. * 66 104 0x13
  733. * 67 98 0x13
  734. * 68 110 0x12
  735. * 69 104 0x08
  736. * 70 98 0x08
  737. * 71 110 0x07
  738. * 72 104 0x07
  739. * 73 98 0x07
  740. * 74 110 0x06
  741. * 75 104 0x06
  742. * 76 98 0x06
  743. * 77 110 0x05
  744. * 78 104 0x05
  745. * 79 98 0x05
  746. * 80 110 0x04
  747. * 81 104 0x04
  748. * 82 98 0x04
  749. * 83 110 0x03
  750. * 84 104 0x03
  751. * 85 98 0x03
  752. * 86 110 0x02
  753. * 87 104 0x02
  754. * 88 98 0x02
  755. * 89 110 0x01
  756. * 90 104 0x01
  757. * 91 98 0x01
  758. * 92 110 0x00
  759. * 93 104 0x00
  760. * 94 98 0x00
  761. * 95 93 0x00
  762. * 96 88 0x00
  763. * 97 83 0x00
  764. * 98 78 0x00
  765. */
  766. /**
  767. * Sanity checks and default values for EEPROM regulatory levels.
  768. * If EEPROM values fall outside MIN/MAX range, use default values.
  769. *
  770. * Regulatory limits refer to the maximum average txpower allowed by
  771. * regulatory agencies in the geographies in which the device is meant
  772. * to be operated. These limits are SKU-specific (i.e. geography-specific),
  773. * and channel-specific; each channel has an individual regulatory limit
  774. * listed in the EEPROM.
  775. *
  776. * Units are in half-dBm (i.e. "34" means 17 dBm).
  777. */
  778. #define IL_TX_POWER_DEFAULT_REGULATORY_24 (34)
  779. #define IL_TX_POWER_DEFAULT_REGULATORY_52 (34)
  780. #define IL_TX_POWER_REGULATORY_MIN (0)
  781. #define IL_TX_POWER_REGULATORY_MAX (34)
  782. /**
  783. * Sanity checks and default values for EEPROM saturation levels.
  784. * If EEPROM values fall outside MIN/MAX range, use default values.
  785. *
  786. * Saturation is the highest level that the output power amplifier can produce
  787. * without significant clipping distortion. This is a "peak" power level.
  788. * Different types of modulation (i.e. various "rates", and OFDM vs. CCK)
  789. * require differing amounts of backoff, relative to their average power output,
  790. * in order to avoid clipping distortion.
  791. *
  792. * Driver must make sure that it is violating neither the saturation limit,
  793. * nor the regulatory limit, when calculating Tx power settings for various
  794. * rates.
  795. *
  796. * Units are in half-dBm (i.e. "38" means 19 dBm).
  797. */
  798. #define IL_TX_POWER_DEFAULT_SATURATION_24 (38)
  799. #define IL_TX_POWER_DEFAULT_SATURATION_52 (38)
  800. #define IL_TX_POWER_SATURATION_MIN (20)
  801. #define IL_TX_POWER_SATURATION_MAX (50)
  802. /**
  803. * Channel groups used for Tx Attenuation calibration (MIMO tx channel balance)
  804. * and thermal Txpower calibration.
  805. *
  806. * When calculating txpower, driver must compensate for current device
  807. * temperature; higher temperature requires higher gain. Driver must calculate
  808. * current temperature (see "4965 temperature calculation"), then compare vs.
  809. * factory calibration temperature in EEPROM; if current temperature is higher
  810. * than factory temperature, driver must *increase* gain by proportions shown
  811. * in table below. If current temperature is lower than factory, driver must
  812. * *decrease* gain.
  813. *
  814. * Different frequency ranges require different compensation, as shown below.
  815. */
  816. /* Group 0, 5.2 GHz ch 34-43: 4.5 degrees per 1/2 dB. */
  817. #define CALIB_IL_TX_ATTEN_GR1_FCH 34
  818. #define CALIB_IL_TX_ATTEN_GR1_LCH 43
  819. /* Group 1, 5.3 GHz ch 44-70: 4.0 degrees per 1/2 dB. */
  820. #define CALIB_IL_TX_ATTEN_GR2_FCH 44
  821. #define CALIB_IL_TX_ATTEN_GR2_LCH 70
  822. /* Group 2, 5.5 GHz ch 71-124: 4.0 degrees per 1/2 dB. */
  823. #define CALIB_IL_TX_ATTEN_GR3_FCH 71
  824. #define CALIB_IL_TX_ATTEN_GR3_LCH 124
  825. /* Group 3, 5.7 GHz ch 125-200: 4.0 degrees per 1/2 dB. */
  826. #define CALIB_IL_TX_ATTEN_GR4_FCH 125
  827. #define CALIB_IL_TX_ATTEN_GR4_LCH 200
  828. /* Group 4, 2.4 GHz all channels: 3.5 degrees per 1/2 dB. */
  829. #define CALIB_IL_TX_ATTEN_GR5_FCH 1
  830. #define CALIB_IL_TX_ATTEN_GR5_LCH 20
  831. enum {
  832. CALIB_CH_GROUP_1 = 0,
  833. CALIB_CH_GROUP_2 = 1,
  834. CALIB_CH_GROUP_3 = 2,
  835. CALIB_CH_GROUP_4 = 3,
  836. CALIB_CH_GROUP_5 = 4,
  837. CALIB_CH_GROUP_MAX
  838. };
  839. /********************* END TXPOWER *****************************************/
  840. /**
  841. * Tx/Rx Queues
  842. *
  843. * Most communication between driver and 4965 is via queues of data buffers.
  844. * For example, all commands that the driver issues to device's embedded
  845. * controller (uCode) are via the command queue (one of the Tx queues). All
  846. * uCode command responses/replies/notifications, including Rx frames, are
  847. * conveyed from uCode to driver via the Rx queue.
  848. *
  849. * Most support for these queues, including handshake support, resides in
  850. * structures in host DRAM, shared between the driver and the device. When
  851. * allocating this memory, the driver must make sure that data written by
  852. * the host CPU updates DRAM immediately (and does not get "stuck" in CPU's
  853. * cache memory), so DRAM and cache are consistent, and the device can
  854. * immediately see changes made by the driver.
  855. *
  856. * 4965 supports up to 16 DRAM-based Tx queues, and services these queues via
  857. * up to 7 DMA channels (FIFOs). Each Tx queue is supported by a circular array
  858. * in DRAM containing 256 Transmit Frame Descriptors (TFDs).
  859. */
  860. #define IL49_NUM_FIFOS 7
  861. #define IL49_CMD_FIFO_NUM 4
  862. #define IL49_NUM_QUEUES 16
  863. #define IL49_NUM_AMPDU_QUEUES 8
  864. /**
  865. * struct il4965_schedq_bc_tbl
  866. *
  867. * Byte Count table
  868. *
  869. * Each Tx queue uses a byte-count table containing 320 entries:
  870. * one 16-bit entry for each of 256 TFDs, plus an additional 64 entries that
  871. * duplicate the first 64 entries (to avoid wrap-around within a Tx win;
  872. * max Tx win is 64 TFDs).
  873. *
  874. * When driver sets up a new TFD, it must also enter the total byte count
  875. * of the frame to be transmitted into the corresponding entry in the byte
  876. * count table for the chosen Tx queue. If the TFD idx is 0-63, the driver
  877. * must duplicate the byte count entry in corresponding idx 256-319.
  878. *
  879. * padding puts each byte count table on a 1024-byte boundary;
  880. * 4965 assumes tables are separated by 1024 bytes.
  881. */
  882. struct il4965_scd_bc_tbl {
  883. __le16 tfd_offset[TFD_QUEUE_BC_SIZE];
  884. u8 pad[1024 - (TFD_QUEUE_BC_SIZE) * sizeof(__le16)];
  885. } __packed;
  886. #define IL4965_RTC_INST_LOWER_BOUND (0x000000)
  887. /* RSSI to dBm */
  888. #define IL4965_RSSI_OFFSET 44
  889. /* PCI registers */
  890. #define PCI_CFG_RETRY_TIMEOUT 0x041
  891. /* PCI register values */
  892. #define PCI_CFG_LINK_CTRL_VAL_L0S_EN 0x01
  893. #define PCI_CFG_LINK_CTRL_VAL_L1_EN 0x02
  894. #define IL4965_DEFAULT_TX_RETRY 15
  895. /* EEPROM */
  896. #define IL4965_FIRST_AMPDU_QUEUE 10
  897. /* Calibration */
  898. void il4965_chain_noise_calibration(struct il_priv *il, void *stat_resp);
  899. void il4965_sensitivity_calibration(struct il_priv *il, void *resp);
  900. void il4965_init_sensitivity(struct il_priv *il);
  901. void il4965_reset_run_time_calib(struct il_priv *il);
  902. void il4965_calib_free_results(struct il_priv *il);
  903. /* Debug */
  904. #ifdef CONFIG_IWLEGACY_DEBUGFS
  905. ssize_t il4965_ucode_rx_stats_read(struct file *file, char __user *user_buf,
  906. size_t count, loff_t *ppos);
  907. ssize_t il4965_ucode_tx_stats_read(struct file *file, char __user *user_buf,
  908. size_t count, loff_t *ppos);
  909. ssize_t il4965_ucode_general_stats_read(struct file *file,
  910. char __user *user_buf, size_t count, loff_t *ppos);
  911. #else
  912. static ssize_t
  913. il4965_ucode_rx_stats_read(struct file *file, char __user *user_buf,
  914. size_t count, loff_t *ppos)
  915. {
  916. return 0;
  917. }
  918. static ssize_t
  919. il4965_ucode_tx_stats_read(struct file *file, char __user *user_buf,
  920. size_t count, loff_t *ppos)
  921. {
  922. return 0;
  923. }
  924. static ssize_t
  925. il4965_ucode_general_stats_read(struct file *file, char __user *user_buf,
  926. size_t count, loff_t *ppos)
  927. {
  928. return 0;
  929. }
  930. #endif
  931. #endif /* __il_4965_h__ */