Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /******************************************************************************
0003  *
0004  * Copyright(c) 2003 - 2014, 2020 Intel Corporation. All rights reserved.
0005  *****************************************************************************/
0006 /*
0007  * Please use this file (dev.h) for driver implementation definitions.
0008  * Please use commands.h for uCode API definitions.
0009  */
0010 
0011 #ifndef __iwl_dev_h__
0012 #define __iwl_dev_h__
0013 
0014 #include <linux/interrupt.h>
0015 #include <linux/kernel.h>
0016 #include <linux/wait.h>
0017 #include <linux/leds.h>
0018 #include <linux/slab.h>
0019 #include <linux/mutex.h>
0020 
0021 #include "fw/img.h"
0022 #include "iwl-eeprom-parse.h"
0023 #include "iwl-csr.h"
0024 #include "iwl-debug.h"
0025 #include "iwl-agn-hw.h"
0026 #include "iwl-op-mode.h"
0027 #include "fw/notif-wait.h"
0028 #include "iwl-trans.h"
0029 
0030 #include "led.h"
0031 #include "power.h"
0032 #include "rs.h"
0033 #include "tt.h"
0034 
0035 /* CT-KILL constants */
0036 #define CT_KILL_THRESHOLD_LEGACY   110 /* in Celsius */
0037 #define CT_KILL_THRESHOLD      114 /* in Celsius */
0038 #define CT_KILL_EXIT_THRESHOLD     95  /* in Celsius */
0039 
0040 /* Default noise level to report when noise measurement is not available.
0041  *   This may be because we're:
0042  *   1)  Not associated  no beacon statistics being sent to driver)
0043  *   2)  Scanning (noise measurement does not apply to associated channel)
0044  * Use default noise value of -127 ... this is below the range of measurable
0045  *   Rx dBm for all agn devices, so it can indicate "unmeasurable" to user.
0046  *   Also, -127 works better than 0 when averaging frames with/without
0047  *   noise info (e.g. averaging might be done in app); measured dBm values are
0048  *   always negative ... using a negative value as the default keeps all
0049  *   averages within an s8's (used in some apps) range of negative values. */
0050 #define IWL_NOISE_MEAS_NOT_AVAILABLE (-127)
0051 
0052 /*
0053  * RTS threshold here is total size [2347] minus 4 FCS bytes
0054  * Per spec:
0055  *   a value of 0 means RTS on all data/management packets
0056  *   a value > max MSDU size means no RTS
0057  * else RTS for data/management frames where MPDU is larger
0058  *   than RTS value.
0059  */
0060 #define DEFAULT_RTS_THRESHOLD     2347U
0061 #define MIN_RTS_THRESHOLD         0U
0062 #define MAX_RTS_THRESHOLD         2347U
0063 #define MAX_MSDU_SIZE         2304U
0064 #define MAX_MPDU_SIZE         2346U
0065 #define DEFAULT_BEACON_INTERVAL   200U
0066 #define DEFAULT_SHORT_RETRY_LIMIT 7U
0067 #define DEFAULT_LONG_RETRY_LIMIT  4U
0068 
0069 #define IWL_NUM_SCAN_RATES         (2)
0070 
0071 
0072 #define IEEE80211_DATA_LEN              2304
0073 #define IEEE80211_4ADDR_LEN             30
0074 #define IEEE80211_HLEN                  (IEEE80211_4ADDR_LEN)
0075 #define IEEE80211_FRAME_LEN             (IEEE80211_DATA_LEN + IEEE80211_HLEN)
0076 
0077 #define SUP_RATE_11A_MAX_NUM_CHANNELS  8
0078 #define SUP_RATE_11B_MAX_NUM_CHANNELS  4
0079 #define SUP_RATE_11G_MAX_NUM_CHANNELS  12
0080 
0081 #define IWL_SUPPORTED_RATES_IE_LEN         8
0082 
0083 #define IWL_INVALID_RATE     0xFF
0084 #define IWL_INVALID_VALUE    -1
0085 
0086 union iwl_ht_rate_supp {
0087     u16 rates;
0088     struct {
0089         u8 siso_rate;
0090         u8 mimo_rate;
0091     };
0092 };
0093 
0094 struct iwl_ht_config {
0095     bool single_chain_sufficient;
0096     enum ieee80211_smps_mode smps; /* current smps mode */
0097 };
0098 
0099 /* QoS structures */
0100 struct iwl_qos_info {
0101     int qos_active;
0102     struct iwl_qosparam_cmd def_qos_parm;
0103 };
0104 
0105 /**
0106  * enum iwl_agg_state
0107  *
0108  * The state machine of the BA agreement establishment / tear down.
0109  * These states relate to a specific RA / TID.
0110  *
0111  * @IWL_AGG_OFF: aggregation is not used
0112  * @IWL_AGG_STARTING: aggregation are starting (between start and oper)
0113  * @IWL_AGG_ON: aggregation session is up
0114  * @IWL_EMPTYING_HW_QUEUE_ADDBA: establishing a BA session - waiting for the
0115  *  HW queue to be empty from packets for this RA /TID.
0116  * @IWL_EMPTYING_HW_QUEUE_DELBA: tearing down a BA session - waiting for the
0117  *  HW queue to be empty from packets for this RA /TID.
0118  */
0119 enum iwl_agg_state {
0120     IWL_AGG_OFF = 0,
0121     IWL_AGG_STARTING,
0122     IWL_AGG_ON,
0123     IWL_EMPTYING_HW_QUEUE_ADDBA,
0124     IWL_EMPTYING_HW_QUEUE_DELBA,
0125 };
0126 
0127 /**
0128  * struct iwl_ht_agg - aggregation state machine
0129 
0130  * This structs holds the states for the BA agreement establishment and tear
0131  * down. It also holds the state during the BA session itself. This struct is
0132  * duplicated for each RA / TID.
0133 
0134  * @rate_n_flags: Rate at which Tx was attempted. Holds the data between the
0135  *  Tx response (REPLY_TX), and the block ack notification
0136  *  (REPLY_COMPRESSED_BA).
0137  * @state: state of the BA agreement establishment / tear down.
0138  * @txq_id: Tx queue used by the BA session
0139  * @ssn: the first packet to be sent in AGG HW queue in Tx AGG start flow, or
0140  *  the first packet to be sent in legacy HW queue in Tx AGG stop flow.
0141  *  Basically when next_reclaimed reaches ssn, we can tell mac80211 that
0142  *  we are ready to finish the Tx AGG stop / start flow.
0143  * @wait_for_ba: Expect block-ack before next Tx reply
0144  */
0145 struct iwl_ht_agg {
0146     u32 rate_n_flags;
0147     enum iwl_agg_state state;
0148     u16 txq_id;
0149     u16 ssn;
0150     bool wait_for_ba;
0151 };
0152 
0153 /**
0154  * struct iwl_tid_data - one for each RA / TID
0155 
0156  * This structs holds the states for each RA / TID.
0157 
0158  * @seq_number: the next WiFi sequence number to use
0159  * @next_reclaimed: the WiFi sequence number of the next packet to be acked.
0160  *  This is basically (last acked packet++).
0161  * @agg: aggregation state machine
0162  */
0163 struct iwl_tid_data {
0164     u16 seq_number;
0165     u16 next_reclaimed;
0166     struct iwl_ht_agg agg;
0167 };
0168 
0169 /*
0170  * Structure should be accessed with sta_lock held. When station addition
0171  * is in progress (IWL_STA_UCODE_INPROGRESS) it is possible to access only
0172  * the commands (iwl_addsta_cmd and iwl_link_quality_cmd) without sta_lock
0173  * held.
0174  */
0175 struct iwl_station_entry {
0176     struct iwl_addsta_cmd sta;
0177     u8 used, ctxid;
0178     struct iwl_link_quality_cmd *lq;
0179 };
0180 
0181 /*
0182  * iwl_station_priv: Driver's private station information
0183  *
0184  * When mac80211 creates a station it reserves some space (hw->sta_data_size)
0185  * in the structure for use by driver. This structure is places in that
0186  * space.
0187  */
0188 struct iwl_station_priv {
0189     struct iwl_rxon_context *ctx;
0190     struct iwl_lq_sta lq_sta;
0191     atomic_t pending_frames;
0192     bool client;
0193     bool asleep;
0194     u8 max_agg_bufsize;
0195     u8 sta_id;
0196 };
0197 
0198 /**
0199  * struct iwl_vif_priv - driver's private per-interface information
0200  *
0201  * When mac80211 allocates a virtual interface, it can allocate
0202  * space for us to put data into.
0203  */
0204 struct iwl_vif_priv {
0205     struct iwl_rxon_context *ctx;
0206     u8 ibss_bssid_sta_id;
0207 };
0208 
0209 struct iwl_sensitivity_ranges {
0210     u16 min_nrg_cck;
0211 
0212     u16 nrg_th_cck;
0213     u16 nrg_th_ofdm;
0214 
0215     u16 auto_corr_min_ofdm;
0216     u16 auto_corr_min_ofdm_mrc;
0217     u16 auto_corr_min_ofdm_x1;
0218     u16 auto_corr_min_ofdm_mrc_x1;
0219 
0220     u16 auto_corr_max_ofdm;
0221     u16 auto_corr_max_ofdm_mrc;
0222     u16 auto_corr_max_ofdm_x1;
0223     u16 auto_corr_max_ofdm_mrc_x1;
0224 
0225     u16 auto_corr_max_cck;
0226     u16 auto_corr_max_cck_mrc;
0227     u16 auto_corr_min_cck;
0228     u16 auto_corr_min_cck_mrc;
0229 
0230     u16 barker_corr_th_min;
0231     u16 barker_corr_th_min_mrc;
0232     u16 nrg_th_cca;
0233 };
0234 
0235 /******************************************************************************
0236  *
0237  * Functions implemented in core module which are forward declared here
0238  * for use by iwl-[4-5].c
0239  *
0240  * NOTE:  The implementation of these functions are not hardware specific
0241  * which is why they are in the core module files.
0242  *
0243  * Naming convention --
0244  * iwl_         <-- Is part of iwlwifi
0245  * iwlXXXX_     <-- Hardware specific (implemented in iwl-XXXX.c for XXXX)
0246  *
0247  ****************************************************************************/
0248 void iwl_update_chain_flags(struct iwl_priv *priv);
0249 extern const u8 iwl_bcast_addr[ETH_ALEN];
0250 
0251 #define IWL_OPERATION_MODE_AUTO     0
0252 #define IWL_OPERATION_MODE_HT_ONLY  1
0253 #define IWL_OPERATION_MODE_MIXED    2
0254 #define IWL_OPERATION_MODE_20MHZ    3
0255 
0256 #define TX_POWER_IWL_ILLEGAL_VOLTAGE -10000
0257 
0258 /* Sensitivity and chain noise calibration */
0259 #define INITIALIZATION_VALUE        0xFFFF
0260 #define IWL_CAL_NUM_BEACONS     16
0261 #define MAXIMUM_ALLOWED_PATHLOSS    15
0262 
0263 #define CHAIN_NOISE_MAX_DELTA_GAIN_CODE 3
0264 
0265 #define MAX_FA_OFDM  50
0266 #define MIN_FA_OFDM  5
0267 #define MAX_FA_CCK   50
0268 #define MIN_FA_CCK   5
0269 
0270 #define AUTO_CORR_STEP_OFDM       1
0271 
0272 #define AUTO_CORR_STEP_CCK     3
0273 #define AUTO_CORR_MAX_TH_CCK   160
0274 
0275 #define NRG_DIFF               2
0276 #define NRG_STEP_CCK           2
0277 #define NRG_MARGIN             8
0278 #define MAX_NUMBER_CCK_NO_FA 100
0279 
0280 #define AUTO_CORR_CCK_MIN_VAL_DEF    (125)
0281 
0282 #define CHAIN_A             0
0283 #define CHAIN_B             1
0284 #define CHAIN_C             2
0285 #define CHAIN_NOISE_DELTA_GAIN_INIT_VAL 4
0286 #define ALL_BAND_FILTER         0xFF00
0287 #define IN_BAND_FILTER          0xFF
0288 #define MIN_AVERAGE_NOISE_MAX_VALUE 0xFFFFFFFF
0289 
0290 #define NRG_NUM_PREV_STAT_L     20
0291 #define NUM_RX_CHAINS           3
0292 
0293 enum iwlagn_false_alarm_state {
0294     IWL_FA_TOO_MANY = 0,
0295     IWL_FA_TOO_FEW = 1,
0296     IWL_FA_GOOD_RANGE = 2,
0297 };
0298 
0299 enum iwlagn_chain_noise_state {
0300     IWL_CHAIN_NOISE_ALIVE = 0,  /* must be 0 */
0301     IWL_CHAIN_NOISE_ACCUMULATE,
0302     IWL_CHAIN_NOISE_CALIBRATED,
0303     IWL_CHAIN_NOISE_DONE,
0304 };
0305 
0306 /* Sensitivity calib data */
0307 struct iwl_sensitivity_data {
0308     u32 auto_corr_ofdm;
0309     u32 auto_corr_ofdm_mrc;
0310     u32 auto_corr_ofdm_x1;
0311     u32 auto_corr_ofdm_mrc_x1;
0312     u32 auto_corr_cck;
0313     u32 auto_corr_cck_mrc;
0314 
0315     u32 last_bad_plcp_cnt_ofdm;
0316     u32 last_fa_cnt_ofdm;
0317     u32 last_bad_plcp_cnt_cck;
0318     u32 last_fa_cnt_cck;
0319 
0320     u32 nrg_curr_state;
0321     u32 nrg_prev_state;
0322     u32 nrg_value[10];
0323     u8  nrg_silence_rssi[NRG_NUM_PREV_STAT_L];
0324     u32 nrg_silence_ref;
0325     u32 nrg_energy_idx;
0326     u32 nrg_silence_idx;
0327     u32 nrg_th_cck;
0328     s32 nrg_auto_corr_silence_diff;
0329     u32 num_in_cck_no_fa;
0330     u32 nrg_th_ofdm;
0331 
0332     u16 barker_corr_th_min;
0333     u16 barker_corr_th_min_mrc;
0334     u16 nrg_th_cca;
0335 };
0336 
0337 /* Chain noise (differential Rx gain) calib data */
0338 struct iwl_chain_noise_data {
0339     u32 active_chains;
0340     u32 chain_noise_a;
0341     u32 chain_noise_b;
0342     u32 chain_noise_c;
0343     u32 chain_signal_a;
0344     u32 chain_signal_b;
0345     u32 chain_signal_c;
0346     u16 beacon_count;
0347     u8 disconn_array[NUM_RX_CHAINS];
0348     u8 delta_gain_code[NUM_RX_CHAINS];
0349     u8 radio_write;
0350     u8 state;
0351 };
0352 
0353 enum {
0354     MEASUREMENT_READY = (1 << 0),
0355     MEASUREMENT_ACTIVE = (1 << 1),
0356 };
0357 
0358 /* reply_tx_statistics (for _agn devices) */
0359 struct reply_tx_error_statistics {
0360     u32 pp_delay;
0361     u32 pp_few_bytes;
0362     u32 pp_bt_prio;
0363     u32 pp_quiet_period;
0364     u32 pp_calc_ttak;
0365     u32 int_crossed_retry;
0366     u32 short_limit;
0367     u32 long_limit;
0368     u32 fifo_underrun;
0369     u32 drain_flow;
0370     u32 rfkill_flush;
0371     u32 life_expire;
0372     u32 dest_ps;
0373     u32 host_abort;
0374     u32 bt_retry;
0375     u32 sta_invalid;
0376     u32 frag_drop;
0377     u32 tid_disable;
0378     u32 fifo_flush;
0379     u32 insuff_cf_poll;
0380     u32 fail_hw_drop;
0381     u32 sta_color_mismatch;
0382     u32 unknown;
0383 };
0384 
0385 /* reply_agg_tx_statistics (for _agn devices) */
0386 struct reply_agg_tx_error_statistics {
0387     u32 underrun;
0388     u32 bt_prio;
0389     u32 few_bytes;
0390     u32 abort;
0391     u32 last_sent_ttl;
0392     u32 last_sent_try;
0393     u32 last_sent_bt_kill;
0394     u32 scd_query;
0395     u32 bad_crc32;
0396     u32 response;
0397     u32 dump_tx;
0398     u32 delay_tx;
0399     u32 unknown;
0400 };
0401 
0402 /*
0403  * schedule the timer to wake up every UCODE_TRACE_PERIOD milliseconds
0404  * to perform continuous uCode event logging operation if enabled
0405  */
0406 #define UCODE_TRACE_PERIOD (10)
0407 
0408 /*
0409  * iwl_event_log: current uCode event log position
0410  *
0411  * @ucode_trace: enable/disable ucode continuous trace timer
0412  * @num_wraps: how many times the event buffer wraps
0413  * @next_entry:  the entry just before the next one that uCode would fill
0414  * @non_wraps_count: counter for no wrap detected when dump ucode events
0415  * @wraps_once_count: counter for wrap once detected when dump ucode events
0416  * @wraps_more_count: counter for wrap more than once detected
0417  *            when dump ucode events
0418  */
0419 struct iwl_event_log {
0420     bool ucode_trace;
0421     u32 num_wraps;
0422     u32 next_entry;
0423     int non_wraps_count;
0424     int wraps_once_count;
0425     int wraps_more_count;
0426 };
0427 
0428 #define IWL_DELAY_NEXT_FORCE_RF_RESET  (HZ*3)
0429 
0430 /* BT Antenna Coupling Threshold (dB) */
0431 #define IWL_BT_ANTENNA_COUPLING_THRESHOLD   (35)
0432 
0433 /* Firmware reload counter and Timestamp */
0434 #define IWL_MIN_RELOAD_DURATION     1000 /* 1000 ms */
0435 #define IWL_MAX_CONTINUE_RELOAD_CNT 4
0436 
0437 
0438 struct iwl_rf_reset {
0439     int reset_request_count;
0440     int reset_success_count;
0441     int reset_reject_count;
0442     unsigned long last_reset_jiffies;
0443 };
0444 
0445 enum iwl_rxon_context_id {
0446     IWL_RXON_CTX_BSS,
0447     IWL_RXON_CTX_PAN,
0448 
0449     NUM_IWL_RXON_CTX
0450 };
0451 
0452 /* extend beacon time format bit shifting  */
0453 /*
0454  * for _agn devices
0455  * bits 31:22 - extended
0456  * bits 21:0  - interval
0457  */
0458 #define IWLAGN_EXT_BEACON_TIME_POS  22
0459 
0460 struct iwl_rxon_context {
0461     struct ieee80211_vif *vif;
0462 
0463     u8 mcast_queue;
0464     u8 ac_to_queue[IEEE80211_NUM_ACS];
0465     u8 ac_to_fifo[IEEE80211_NUM_ACS];
0466 
0467     /*
0468      * We could use the vif to indicate active, but we
0469      * also need it to be active during disabling when
0470      * we already removed the vif for type setting.
0471      */
0472     bool always_active, is_active;
0473 
0474     bool ht_need_multiple_chains;
0475 
0476     enum iwl_rxon_context_id ctxid;
0477 
0478     u32 interface_modes, exclusive_interface_modes;
0479     u8 unused_devtype, ap_devtype, ibss_devtype, station_devtype;
0480 
0481     /*
0482      * We declare this const so it can only be
0483      * changed via explicit cast within the
0484      * routines that actually update the physical
0485      * hardware.
0486      */
0487     const struct iwl_rxon_cmd active;
0488     struct iwl_rxon_cmd staging;
0489 
0490     struct iwl_rxon_time_cmd timing;
0491 
0492     struct iwl_qos_info qos_data;
0493 
0494     u8 bcast_sta_id, ap_sta_id;
0495 
0496     u8 rxon_cmd, rxon_assoc_cmd, rxon_timing_cmd;
0497     u8 qos_cmd;
0498     u8 wep_key_cmd;
0499 
0500     struct iwl_wep_key wep_keys[WEP_KEYS_MAX];
0501     u8 key_mapping_keys;
0502 
0503     __le32 station_flags;
0504 
0505     int beacon_int;
0506 
0507     struct {
0508         bool non_gf_sta_present;
0509         u8 protection;
0510         bool enabled, is_40mhz;
0511         u8 extension_chan_offset;
0512     } ht;
0513 };
0514 
0515 enum iwl_scan_type {
0516     IWL_SCAN_NORMAL,
0517     IWL_SCAN_RADIO_RESET,
0518 };
0519 
0520 /**
0521  * struct iwl_hw_params
0522  *
0523  * Holds the module parameters
0524  *
0525  * @tx_chains_num: Number of TX chains
0526  * @rx_chains_num: Number of RX chains
0527  * @ct_kill_threshold: temperature threshold - in hw dependent unit
0528  * @ct_kill_exit_threshold: when to reeable the device - in hw dependent unit
0529  *  relevant for 1000, 6000 and up
0530  * @struct iwl_sensitivity_ranges: range of sensitivity values
0531  * @use_rts_for_aggregation: use rts/cts protection for HT traffic
0532  */
0533 struct iwl_hw_params {
0534     u8  tx_chains_num;
0535     u8  rx_chains_num;
0536     bool use_rts_for_aggregation;
0537     u32 ct_kill_threshold;
0538     u32 ct_kill_exit_threshold;
0539 
0540     const struct iwl_sensitivity_ranges *sens;
0541 };
0542 
0543 /**
0544  * struct iwl_dvm_bt_params - DVM specific BT (coex) parameters
0545  * @advanced_bt_coexist: support advanced bt coexist
0546  * @bt_init_traffic_load: specify initial bt traffic load
0547  * @bt_prio_boost: default bt priority boost value
0548  * @agg_time_limit: maximum number of uSec in aggregation
0549  * @bt_sco_disable: uCode should not response to BT in SCO/ESCO mode
0550  */
0551 struct iwl_dvm_bt_params {
0552     bool advanced_bt_coexist;
0553     u8 bt_init_traffic_load;
0554     u32 bt_prio_boost;
0555     u16 agg_time_limit;
0556     bool bt_sco_disable;
0557     bool bt_session_2;
0558 };
0559 
0560 /**
0561  * struct iwl_dvm_cfg - DVM firmware specific device configuration
0562  * @set_hw_params: set hardware parameters
0563  * @set_channel_switch: send channel switch command
0564  * @nic_config: apply device specific configuration
0565  * @temperature: read temperature
0566  * @adv_thermal_throttle: support advance thermal throttle
0567  * @support_ct_kill_exit: support ct kill exit condition
0568  * @plcp_delta_threshold: plcp error rate threshold used to trigger
0569  *  radio tuning when there is a high receiving plcp error rate
0570  * @chain_noise_scale: default chain noise scale used for gain computation
0571  * @hd_v2: v2 of enhanced sensitivity value, used for 2000 series and up
0572  * @no_idle_support: do not support idle mode
0573  * @bt_params: pointer to BT parameters
0574  * @need_temp_offset_calib: need to perform temperature offset calibration
0575  * @no_xtal_calib: some devices do not need crystal calibration data,
0576  *  don't send it to those
0577  * @temp_offset_v2: support v2 of temperature offset calibration
0578  * @adv_pm: advanced power management
0579  */
0580 struct iwl_dvm_cfg {
0581     void (*set_hw_params)(struct iwl_priv *priv);
0582     int (*set_channel_switch)(struct iwl_priv *priv,
0583                   struct ieee80211_channel_switch *ch_switch);
0584     void (*nic_config)(struct iwl_priv *priv);
0585     void (*temperature)(struct iwl_priv *priv);
0586 
0587     const struct iwl_dvm_bt_params *bt_params;
0588     s32 chain_noise_scale;
0589     u8 plcp_delta_threshold;
0590     bool adv_thermal_throttle;
0591     bool support_ct_kill_exit;
0592     bool hd_v2;
0593     bool no_idle_support;
0594     bool need_temp_offset_calib;
0595     bool no_xtal_calib;
0596     bool temp_offset_v2;
0597     bool adv_pm;
0598 };
0599 
0600 struct iwl_wipan_noa_data {
0601     struct rcu_head rcu_head;
0602     u32 length;
0603     u8 data[];
0604 };
0605 
0606 /* Calibration disabling bit mask */
0607 enum {
0608     IWL_CALIB_ENABLE_ALL            = 0,
0609 
0610     IWL_SENSITIVITY_CALIB_DISABLED      = BIT(0),
0611     IWL_CHAIN_NOISE_CALIB_DISABLED      = BIT(1),
0612     IWL_TX_POWER_CALIB_DISABLED     = BIT(2),
0613 
0614     IWL_CALIB_DISABLE_ALL           = 0xFFFFFFFF,
0615 };
0616 
0617 #define IWL_OP_MODE_GET_DVM(_iwl_op_mode) \
0618     ((struct iwl_priv *) ((_iwl_op_mode)->op_mode_specific))
0619 
0620 #define IWL_MAC80211_GET_DVM(_hw) \
0621     ((struct iwl_priv *) ((struct iwl_op_mode *) \
0622     (_hw)->priv)->op_mode_specific)
0623 
0624 struct iwl_priv {
0625 
0626     struct iwl_trans *trans;
0627     struct device *dev;     /* for debug prints only */
0628     const struct iwl_cfg *cfg;
0629     const struct iwl_fw *fw;
0630     const struct iwl_dvm_cfg *lib;
0631     unsigned long status;
0632 
0633     spinlock_t sta_lock;
0634     struct mutex mutex;
0635 
0636     unsigned long transport_queue_stop;
0637     bool passive_no_rx;
0638 #define IWL_INVALID_MAC80211_QUEUE  0xff
0639     u8 queue_to_mac80211[IWL_MAX_HW_QUEUES];
0640     atomic_t queue_stop_count[IWL_MAX_HW_QUEUES];
0641 
0642     unsigned long agg_q_alloc[BITS_TO_LONGS(IWL_MAX_HW_QUEUES)];
0643 
0644     /* ieee device used by generic ieee processing code */
0645     struct ieee80211_hw *hw;
0646 
0647     struct napi_struct *napi;
0648 
0649     struct list_head calib_results;
0650 
0651     struct workqueue_struct *workqueue;
0652 
0653     struct iwl_hw_params hw_params;
0654 
0655     enum nl80211_band band;
0656     u8 valid_contexts;
0657 
0658     void (*rx_handlers[REPLY_MAX])(struct iwl_priv *priv,
0659                        struct iwl_rx_cmd_buffer *rxb);
0660 
0661     struct iwl_notif_wait_data notif_wait;
0662 
0663     /* spectrum measurement report caching */
0664     struct iwl_spectrum_notification measure_report;
0665     u8 measurement_status;
0666 
0667     /* ucode beacon time */
0668     u32 ucode_beacon_time;
0669     int missed_beacon_threshold;
0670 
0671     /* track IBSS manager (last beacon) status */
0672     u32 ibss_manager;
0673 
0674     /* jiffies when last recovery from statistics was performed */
0675     unsigned long rx_statistics_jiffies;
0676 
0677     /*counters */
0678     u32 rx_handlers_stats[REPLY_MAX];
0679 
0680     /* rf reset */
0681     struct iwl_rf_reset rf_reset;
0682 
0683     /* firmware reload counter and timestamp */
0684     unsigned long reload_jiffies;
0685     int reload_count;
0686     bool ucode_loaded;
0687 
0688     u8 plcp_delta_threshold;
0689 
0690     /* thermal calibration */
0691     s32 temperature;    /* Celsius */
0692     s32 last_temperature;
0693 
0694     struct iwl_wipan_noa_data __rcu *noa_data;
0695 
0696     /* Scan related variables */
0697     unsigned long scan_start;
0698     unsigned long scan_start_tsf;
0699     void *scan_cmd;
0700     enum nl80211_band scan_band;
0701     struct cfg80211_scan_request *scan_request;
0702     struct ieee80211_vif *scan_vif;
0703     enum iwl_scan_type scan_type;
0704     u8 scan_tx_ant[NUM_NL80211_BANDS];
0705     u8 mgmt_tx_ant;
0706 
0707     /* max number of station keys */
0708     u8 sta_key_max_num;
0709 
0710     bool new_scan_threshold_behaviour;
0711 
0712     bool wowlan;
0713 
0714     /* EEPROM MAC addresses */
0715     struct mac_address addresses[2];
0716 
0717     struct iwl_rxon_context contexts[NUM_IWL_RXON_CTX];
0718 
0719     __le16 switch_channel;
0720 
0721     u8 start_calib;
0722     struct iwl_sensitivity_data sensitivity_data;
0723     struct iwl_chain_noise_data chain_noise_data;
0724     __le16 sensitivity_tbl[HD_TABLE_SIZE];
0725     __le16 enhance_sensitivity_tbl[ENHANCE_HD_TABLE_ENTRIES];
0726 
0727     struct iwl_ht_config current_ht_config;
0728 
0729     /* Rate scaling data */
0730     u8 retry_rate;
0731 
0732     int activity_timer_active;
0733 
0734     struct iwl_power_mgr power_data;
0735     struct iwl_tt_mgmt thermal_throttle;
0736 
0737     /* station table variables */
0738     int num_stations;
0739     struct iwl_station_entry stations[IWLAGN_STATION_COUNT];
0740     unsigned long ucode_key_table;
0741     struct iwl_tid_data tid_data[IWLAGN_STATION_COUNT][IWL_MAX_TID_COUNT];
0742     atomic_t num_aux_in_flight;
0743 
0744     u8 mac80211_registered;
0745 
0746     /* Indication if ieee80211_ops->open has been called */
0747     u8 is_open;
0748 
0749     enum nl80211_iftype iw_mode;
0750 
0751     /* Last Rx'd beacon timestamp */
0752     u64 timestamp;
0753 
0754     struct {
0755         __le32 flag;
0756         struct statistics_general_common common;
0757         struct statistics_rx_non_phy rx_non_phy;
0758         struct statistics_rx_phy rx_ofdm;
0759         struct statistics_rx_ht_phy rx_ofdm_ht;
0760         struct statistics_rx_phy rx_cck;
0761         struct statistics_tx tx;
0762 #ifdef CONFIG_IWLWIFI_DEBUGFS
0763         struct statistics_bt_activity bt_activity;
0764         __le32 num_bt_kills, accum_num_bt_kills;
0765 #endif
0766         spinlock_t lock;
0767     } statistics;
0768 #ifdef CONFIG_IWLWIFI_DEBUGFS
0769     struct {
0770         struct statistics_general_common common;
0771         struct statistics_rx_non_phy rx_non_phy;
0772         struct statistics_rx_phy rx_ofdm;
0773         struct statistics_rx_ht_phy rx_ofdm_ht;
0774         struct statistics_rx_phy rx_cck;
0775         struct statistics_tx tx;
0776         struct statistics_bt_activity bt_activity;
0777     } accum_stats, delta_stats, max_delta_stats;
0778 #endif
0779 
0780     /*
0781      * reporting the number of tids has AGG on. 0 means
0782      * no AGGREGATION
0783      */
0784     u8 agg_tids_count;
0785 
0786     struct iwl_rx_phy_res last_phy_res;
0787     u32 ampdu_ref;
0788     bool last_phy_res_valid;
0789 
0790     /*
0791      * chain noise reset and gain commands are the
0792      * two extra calibration commands follows the standard
0793      * phy calibration commands
0794      */
0795     u8 phy_calib_chain_noise_reset_cmd;
0796     u8 phy_calib_chain_noise_gain_cmd;
0797 
0798     /* counts reply_tx error */
0799     struct reply_tx_error_statistics reply_tx_stats;
0800     struct reply_agg_tx_error_statistics reply_agg_tx_stats;
0801 
0802     /* bt coex */
0803     u8 bt_enable_flag;
0804     u8 bt_status;
0805     u8 bt_traffic_load, last_bt_traffic_load;
0806     bool bt_ch_announce;
0807     bool bt_full_concurrent;
0808     __le32 kill_ack_mask;
0809     __le32 kill_cts_mask;
0810     __le16 bt_valid;
0811     bool reduced_txpower;
0812     u16 bt_on_thresh;
0813     u16 bt_duration;
0814     u16 dynamic_frag_thresh;
0815     u8 bt_ci_compliance;
0816     struct work_struct bt_traffic_change_work;
0817     bool bt_enable_pspoll;
0818     struct iwl_rxon_context *cur_rssi_ctx;
0819     bool bt_is_sco;
0820 
0821     struct work_struct restart;
0822     struct work_struct scan_completed;
0823     struct work_struct abort_scan;
0824 
0825     struct work_struct beacon_update;
0826     struct iwl_rxon_context *beacon_ctx;
0827     struct sk_buff *beacon_skb;
0828     void *beacon_cmd;
0829 
0830     struct work_struct tt_work;
0831     struct work_struct ct_enter;
0832     struct work_struct ct_exit;
0833     struct work_struct start_internal_scan;
0834     struct work_struct tx_flush;
0835     struct work_struct bt_full_concurrency;
0836     struct work_struct bt_runtime_config;
0837 
0838     struct delayed_work scan_check;
0839 
0840     /* TX Power settings */
0841     s8 tx_power_user_lmt;
0842     s8 tx_power_next;
0843 
0844 #ifdef CONFIG_IWLWIFI_DEBUGFS
0845     /* debugfs */
0846     struct dentry *debugfs_dir;
0847     u32 dbgfs_sram_offset, dbgfs_sram_len;
0848     bool disable_ht40;
0849     void *wowlan_sram;
0850 #endif /* CONFIG_IWLWIFI_DEBUGFS */
0851 
0852     struct iwl_nvm_data *nvm_data;
0853     /* eeprom blob for debugfs */
0854     u8 *eeprom_blob;
0855     size_t eeprom_blob_size;
0856 
0857     struct work_struct txpower_work;
0858     u32 calib_disabled;
0859     struct work_struct run_time_calib_work;
0860     struct timer_list statistics_periodic;
0861     struct timer_list ucode_trace;
0862 
0863     struct iwl_event_log event_log;
0864 
0865 #ifdef CONFIG_IWLWIFI_LEDS
0866     struct led_classdev led;
0867     unsigned long blink_on, blink_off;
0868     bool led_registered;
0869 #endif
0870 
0871     /* WoWLAN GTK rekey data */
0872     u8 kck[NL80211_KCK_LEN], kek[NL80211_KEK_LEN];
0873     __le64 replay_ctr;
0874     __le16 last_seq_ctl;
0875     bool have_rekey_data;
0876 #ifdef CONFIG_PM_SLEEP
0877     struct wiphy_wowlan_support wowlan_support;
0878 #endif
0879 
0880     /* device_pointers: pointers to ucode event tables */
0881     struct {
0882         u32 error_event_table;
0883         u32 log_event_table;
0884     } device_pointers;
0885 
0886     /* indicator of loaded ucode image */
0887     enum iwl_ucode_type cur_ucode;
0888 }; /*iwl_priv */
0889 
0890 static inline struct iwl_rxon_context *
0891 iwl_rxon_ctx_from_vif(struct ieee80211_vif *vif)
0892 {
0893     struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
0894 
0895     return vif_priv->ctx;
0896 }
0897 
0898 #define for_each_context(priv, ctx)             \
0899     for (ctx = &priv->contexts[IWL_RXON_CTX_BSS];       \
0900          ctx < &priv->contexts[NUM_IWL_RXON_CTX]; ctx++)    \
0901         if (priv->valid_contexts & BIT(ctx->ctxid))
0902 
0903 static inline int iwl_is_associated_ctx(struct iwl_rxon_context *ctx)
0904 {
0905     return (ctx->active.filter_flags & RXON_FILTER_ASSOC_MSK) ? 1 : 0;
0906 }
0907 
0908 static inline int iwl_is_associated(struct iwl_priv *priv,
0909                     enum iwl_rxon_context_id ctxid)
0910 {
0911     return iwl_is_associated_ctx(&priv->contexts[ctxid]);
0912 }
0913 
0914 static inline int iwl_is_any_associated(struct iwl_priv *priv)
0915 {
0916     struct iwl_rxon_context *ctx;
0917     for_each_context(priv, ctx)
0918         if (iwl_is_associated_ctx(ctx))
0919             return true;
0920     return false;
0921 }
0922 
0923 #endif              /* __iwl_dev_h__ */