Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
0002 /*
0003  * Copyright (C) 2005-2014, 2021 Intel Corporation
0004  */
0005 #ifndef __iwl_agn_h__
0006 #define __iwl_agn_h__
0007 
0008 #include "iwl-config.h"
0009 
0010 #include "dev.h"
0011 
0012 /* The first 11 queues (0-10) are used otherwise */
0013 #define IWLAGN_FIRST_AMPDU_QUEUE    11
0014 
0015 /* AUX (TX during scan dwell) queue */
0016 #define IWL_AUX_QUEUE       10
0017 
0018 #define IWL_INVALID_STATION 255
0019 
0020 /* device operations */
0021 extern const struct iwl_dvm_cfg iwl_dvm_1000_cfg;
0022 extern const struct iwl_dvm_cfg iwl_dvm_2000_cfg;
0023 extern const struct iwl_dvm_cfg iwl_dvm_105_cfg;
0024 extern const struct iwl_dvm_cfg iwl_dvm_2030_cfg;
0025 extern const struct iwl_dvm_cfg iwl_dvm_5000_cfg;
0026 extern const struct iwl_dvm_cfg iwl_dvm_5150_cfg;
0027 extern const struct iwl_dvm_cfg iwl_dvm_6000_cfg;
0028 extern const struct iwl_dvm_cfg iwl_dvm_6005_cfg;
0029 extern const struct iwl_dvm_cfg iwl_dvm_6050_cfg;
0030 extern const struct iwl_dvm_cfg iwl_dvm_6030_cfg;
0031 
0032 
0033 #define TIME_UNIT       1024
0034 
0035 /*****************************************************
0036 * DRIVER STATUS FUNCTIONS
0037 ******************************************************/
0038 #define STATUS_RF_KILL_HW   0
0039 #define STATUS_CT_KILL      1
0040 #define STATUS_ALIVE        2
0041 #define STATUS_READY        3
0042 #define STATUS_EXIT_PENDING 5
0043 #define STATUS_STATISTICS   6
0044 #define STATUS_SCANNING     7
0045 #define STATUS_SCAN_ABORTING    8
0046 #define STATUS_SCAN_HW      9
0047 #define STATUS_FW_ERROR     10
0048 #define STATUS_CHANNEL_SWITCH_PENDING 11
0049 #define STATUS_SCAN_COMPLETE    12
0050 #define STATUS_POWER_PMI    13
0051 
0052 struct iwl_ucode_capabilities;
0053 
0054 extern const struct ieee80211_ops iwlagn_hw_ops;
0055 
0056 static inline void iwl_set_calib_hdr(struct iwl_calib_hdr *hdr, u8 cmd)
0057 {
0058     hdr->op_code = cmd;
0059     hdr->first_group = 0;
0060     hdr->groups_num = 1;
0061     hdr->data_valid = 1;
0062 }
0063 
0064 void iwl_down(struct iwl_priv *priv);
0065 void iwl_cancel_deferred_work(struct iwl_priv *priv);
0066 void iwlagn_prepare_restart(struct iwl_priv *priv);
0067 void iwl_rx_dispatch(struct iwl_op_mode *op_mode, struct napi_struct *napi,
0068              struct iwl_rx_cmd_buffer *rxb);
0069 
0070 bool iwl_check_for_ct_kill(struct iwl_priv *priv);
0071 
0072 void iwlagn_lift_passive_no_rx(struct iwl_priv *priv);
0073 
0074 /* MAC80211 */
0075 struct ieee80211_hw *iwl_alloc_all(void);
0076 int iwlagn_mac_setup_register(struct iwl_priv *priv,
0077                   const struct iwl_ucode_capabilities *capa);
0078 void iwlagn_mac_unregister(struct iwl_priv *priv);
0079 
0080 /* commands */
0081 int iwl_dvm_send_cmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd);
0082 int iwl_dvm_send_cmd_pdu(struct iwl_priv *priv, u8 id,
0083              u32 flags, u16 len, const void *data);
0084 
0085 /* RXON */
0086 void iwl_connection_init_rx_config(struct iwl_priv *priv,
0087                    struct iwl_rxon_context *ctx);
0088 int iwlagn_set_pan_params(struct iwl_priv *priv);
0089 int iwlagn_commit_rxon(struct iwl_priv *priv, struct iwl_rxon_context *ctx);
0090 void iwlagn_set_rxon_chain(struct iwl_priv *priv, struct iwl_rxon_context *ctx);
0091 int iwlagn_mac_config(struct ieee80211_hw *hw, u32 changed);
0092 void iwlagn_bss_info_changed(struct ieee80211_hw *hw,
0093                  struct ieee80211_vif *vif,
0094                  struct ieee80211_bss_conf *bss_conf,
0095                  u64 changes);
0096 void iwlagn_config_ht40(struct ieee80211_conf *conf,
0097             struct iwl_rxon_context *ctx);
0098 void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_config *ht_conf);
0099 void iwl_set_rxon_channel(struct iwl_priv *priv, struct ieee80211_channel *ch,
0100              struct iwl_rxon_context *ctx);
0101 void iwl_set_flags_for_band(struct iwl_priv *priv,
0102                 struct iwl_rxon_context *ctx,
0103                 enum nl80211_band band,
0104                 struct ieee80211_vif *vif);
0105 
0106 /* uCode */
0107 int iwl_send_bt_env(struct iwl_priv *priv, u8 action, u8 type);
0108 void iwl_send_prio_tbl(struct iwl_priv *priv);
0109 int iwl_init_alive_start(struct iwl_priv *priv);
0110 int iwl_run_init_ucode(struct iwl_priv *priv);
0111 int iwl_load_ucode_wait_alive(struct iwl_priv *priv,
0112                   enum iwl_ucode_type ucode_type);
0113 int iwl_send_calib_results(struct iwl_priv *priv);
0114 int iwl_calib_set(struct iwl_priv *priv,
0115           const struct iwl_calib_hdr *cmd, int len);
0116 void iwl_calib_free_results(struct iwl_priv *priv);
0117 int iwl_dump_nic_event_log(struct iwl_priv *priv, bool full_log,
0118                 char **buf);
0119 int iwlagn_hw_valid_rtc_data_addr(u32 addr);
0120 
0121 /* lib */
0122 int iwlagn_send_tx_power(struct iwl_priv *priv);
0123 void iwlagn_temperature(struct iwl_priv *priv);
0124 int iwlagn_txfifo_flush(struct iwl_priv *priv, u32 scd_q_msk);
0125 void iwlagn_dev_txfifo_flush(struct iwl_priv *priv);
0126 int iwlagn_send_beacon_cmd(struct iwl_priv *priv);
0127 int iwl_send_statistics_request(struct iwl_priv *priv,
0128                 u8 flags, bool clear);
0129 
0130 static inline const struct ieee80211_supported_band *iwl_get_hw_mode(
0131             struct iwl_priv *priv, enum nl80211_band band)
0132 {
0133     return priv->hw->wiphy->bands[band];
0134 }
0135 
0136 #ifdef CONFIG_PM_SLEEP
0137 int iwlagn_send_patterns(struct iwl_priv *priv,
0138              struct cfg80211_wowlan *wowlan);
0139 int iwlagn_suspend(struct iwl_priv *priv, struct cfg80211_wowlan *wowlan);
0140 #endif
0141 
0142 /* rx */
0143 int iwlagn_hwrate_to_mac80211_idx(u32 rate_n_flags, enum nl80211_band band);
0144 void iwl_setup_rx_handlers(struct iwl_priv *priv);
0145 void iwl_chswitch_done(struct iwl_priv *priv, bool is_success);
0146 
0147 
0148 /* tx */
0149 int iwlagn_tx_skb(struct iwl_priv *priv,
0150           struct ieee80211_sta *sta,
0151           struct sk_buff *skb);
0152 int iwlagn_tx_agg_start(struct iwl_priv *priv, struct ieee80211_vif *vif,
0153             struct ieee80211_sta *sta, u16 tid, u16 *ssn);
0154 int iwlagn_tx_agg_oper(struct iwl_priv *priv, struct ieee80211_vif *vif,
0155             struct ieee80211_sta *sta, u16 tid, u8 buf_size);
0156 int iwlagn_tx_agg_stop(struct iwl_priv *priv, struct ieee80211_vif *vif,
0157                struct ieee80211_sta *sta, u16 tid);
0158 int iwlagn_tx_agg_flush(struct iwl_priv *priv, struct ieee80211_vif *vif,
0159             struct ieee80211_sta *sta, u16 tid);
0160 void iwlagn_rx_reply_compressed_ba(struct iwl_priv *priv,
0161                    struct iwl_rx_cmd_buffer *rxb);
0162 void iwlagn_rx_reply_tx(struct iwl_priv *priv, struct iwl_rx_cmd_buffer *rxb);
0163 
0164 static inline u32 iwl_tx_status_to_mac80211(u32 status)
0165 {
0166     status &= TX_STATUS_MSK;
0167 
0168     switch (status) {
0169     case TX_STATUS_SUCCESS:
0170     case TX_STATUS_DIRECT_DONE:
0171         return IEEE80211_TX_STAT_ACK;
0172     case TX_STATUS_FAIL_DEST_PS:
0173     case TX_STATUS_FAIL_PASSIVE_NO_RX:
0174         return IEEE80211_TX_STAT_TX_FILTERED;
0175     default:
0176         return 0;
0177     }
0178 }
0179 
0180 static inline bool iwl_is_tx_success(u32 status)
0181 {
0182     status &= TX_STATUS_MSK;
0183     return (status == TX_STATUS_SUCCESS) ||
0184            (status == TX_STATUS_DIRECT_DONE);
0185 }
0186 
0187 u8 iwl_toggle_tx_ant(struct iwl_priv *priv, u8 ant_idx, u8 valid);
0188 
0189 /* scan */
0190 void iwlagn_post_scan(struct iwl_priv *priv);
0191 int iwl_force_rf_reset(struct iwl_priv *priv, bool external);
0192 void iwl_init_scan_params(struct iwl_priv *priv);
0193 int iwl_scan_cancel(struct iwl_priv *priv);
0194 void iwl_scan_cancel_timeout(struct iwl_priv *priv, unsigned long ms);
0195 void iwl_force_scan_end(struct iwl_priv *priv);
0196 void iwl_internal_short_hw_scan(struct iwl_priv *priv);
0197 void iwl_setup_rx_scan_handlers(struct iwl_priv *priv);
0198 void iwl_setup_scan_deferred_work(struct iwl_priv *priv);
0199 void iwl_cancel_scan_deferred_work(struct iwl_priv *priv);
0200 int __must_check iwl_scan_initiate(struct iwl_priv *priv,
0201                    struct ieee80211_vif *vif,
0202                    enum iwl_scan_type scan_type,
0203                    enum nl80211_band band);
0204 
0205 /* For faster active scanning, scan will move to the next channel if fewer than
0206  * PLCP_QUIET_THRESH packets are heard on this channel within
0207  * ACTIVE_QUIET_TIME after sending probe request.  This shortens the dwell
0208  * time if it's a quiet channel (nothing responded to our probe, and there's
0209  * no other traffic).
0210  * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */
0211 #define IWL_ACTIVE_QUIET_TIME       cpu_to_le16(10)  /* msec */
0212 #define IWL_PLCP_QUIET_THRESH       cpu_to_le16(1)  /* packets */
0213 
0214 #define IWL_SCAN_CHECK_WATCHDOG     (HZ * 15)
0215 
0216 
0217 /* bt coex */
0218 void iwlagn_send_advance_bt_config(struct iwl_priv *priv);
0219 void iwlagn_bt_rx_handler_setup(struct iwl_priv *priv);
0220 void iwlagn_bt_setup_deferred_work(struct iwl_priv *priv);
0221 void iwlagn_bt_cancel_deferred_work(struct iwl_priv *priv);
0222 void iwlagn_bt_coex_rssi_monitor(struct iwl_priv *priv);
0223 void iwlagn_bt_adjust_rssi_monitor(struct iwl_priv *priv, bool rssi_ena);
0224 
0225 static inline bool iwl_advanced_bt_coexist(struct iwl_priv *priv)
0226 {
0227     return priv->lib->bt_params &&
0228            priv->lib->bt_params->advanced_bt_coexist;
0229 }
0230 
0231 #ifdef CONFIG_IWLWIFI_DEBUG
0232 const char *iwl_get_tx_fail_reason(u32 status);
0233 const char *iwl_get_agg_tx_fail_reason(u16 status);
0234 #else
0235 static inline const char *iwl_get_tx_fail_reason(u32 status) { return ""; }
0236 static inline const char *iwl_get_agg_tx_fail_reason(u16 status) { return ""; }
0237 #endif
0238 
0239 
0240 /* station management */
0241 int iwlagn_manage_ibss_station(struct iwl_priv *priv,
0242                    struct ieee80211_vif *vif, bool add);
0243 #define IWL_STA_DRIVER_ACTIVE BIT(0) /* driver entry is active */
0244 #define IWL_STA_UCODE_ACTIVE  BIT(1) /* ucode entry is active */
0245 #define IWL_STA_UCODE_INPROGRESS  BIT(2) /* ucode entry is in process of
0246                         being activated */
0247 #define IWL_STA_LOCAL BIT(3) /* station state not directed by mac80211;
0248                 (this is for the IBSS BSSID stations) */
0249 #define IWL_STA_BCAST BIT(4) /* this station is the special bcast station */
0250 
0251 
0252 void iwl_restore_stations(struct iwl_priv *priv, struct iwl_rxon_context *ctx);
0253 void iwl_clear_ucode_stations(struct iwl_priv *priv,
0254                   struct iwl_rxon_context *ctx);
0255 void iwl_dealloc_bcast_stations(struct iwl_priv *priv);
0256 int iwl_get_free_ucode_key_offset(struct iwl_priv *priv);
0257 int iwl_send_add_sta(struct iwl_priv *priv,
0258              struct iwl_addsta_cmd *sta, u8 flags);
0259 int iwl_add_station_common(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
0260                const u8 *addr, bool is_ap,
0261                struct ieee80211_sta *sta, u8 *sta_id_r);
0262 int iwl_remove_station(struct iwl_priv *priv, const u8 sta_id,
0263                const u8 *addr);
0264 void iwl_deactivate_station(struct iwl_priv *priv, const u8 sta_id,
0265                 const u8 *addr);
0266 u8 iwl_prep_station(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
0267             const u8 *addr, bool is_ap, struct ieee80211_sta *sta);
0268 
0269 int iwl_send_lq_cmd(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
0270             struct iwl_link_quality_cmd *lq, u8 flags, bool init);
0271 void iwl_add_sta_callback(struct iwl_priv *priv, struct iwl_rx_cmd_buffer *rxb);
0272 int iwl_sta_update_ht(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
0273               struct ieee80211_sta *sta);
0274 
0275 bool iwl_is_ht40_tx_allowed(struct iwl_priv *priv,
0276                 struct iwl_rxon_context *ctx,
0277                 struct ieee80211_sta *sta);
0278 
0279 static inline int iwl_sta_id(struct ieee80211_sta *sta)
0280 {
0281     if (WARN_ON(!sta))
0282         return IWL_INVALID_STATION;
0283 
0284     return ((struct iwl_station_priv *)sta->drv_priv)->sta_id;
0285 }
0286 
0287 int iwlagn_alloc_bcast_station(struct iwl_priv *priv,
0288                    struct iwl_rxon_context *ctx);
0289 int iwlagn_add_bssid_station(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
0290                  const u8 *addr, u8 *sta_id_r);
0291 int iwl_remove_default_wep_key(struct iwl_priv *priv,
0292                    struct iwl_rxon_context *ctx,
0293                    struct ieee80211_key_conf *key);
0294 int iwl_set_default_wep_key(struct iwl_priv *priv,
0295                 struct iwl_rxon_context *ctx,
0296                 struct ieee80211_key_conf *key);
0297 int iwl_restore_default_wep_keys(struct iwl_priv *priv,
0298                  struct iwl_rxon_context *ctx);
0299 int iwl_set_dynamic_key(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
0300             struct ieee80211_key_conf *key,
0301             struct ieee80211_sta *sta);
0302 int iwl_remove_dynamic_key(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
0303                struct ieee80211_key_conf *key,
0304                struct ieee80211_sta *sta);
0305 void iwl_update_tkip_key(struct iwl_priv *priv,
0306              struct ieee80211_vif *vif,
0307              struct ieee80211_key_conf *keyconf,
0308              struct ieee80211_sta *sta, u32 iv32, u16 *phase1key);
0309 int iwl_sta_tx_modify_enable_tid(struct iwl_priv *priv, int sta_id, int tid);
0310 int iwl_sta_rx_agg_start(struct iwl_priv *priv, struct ieee80211_sta *sta,
0311              int tid, u16 ssn);
0312 int iwl_sta_rx_agg_stop(struct iwl_priv *priv, struct ieee80211_sta *sta,
0313             int tid);
0314 void iwl_sta_modify_sleep_tx_count(struct iwl_priv *priv, int sta_id, int cnt);
0315 int iwl_update_bcast_station(struct iwl_priv *priv,
0316                  struct iwl_rxon_context *ctx);
0317 int iwl_update_bcast_stations(struct iwl_priv *priv);
0318 
0319 /* rate */
0320 static inline u32 iwl_ant_idx_to_flags(u8 ant_idx)
0321 {
0322     return BIT(ant_idx) << RATE_MCS_ANT_POS;
0323 }
0324 
0325 static inline u8 iwl_hw_get_rate(__le32 rate_n_flags)
0326 {
0327     return le32_to_cpu(rate_n_flags) & RATE_MCS_RATE_MSK;
0328 }
0329 
0330 static inline __le32 iwl_hw_set_rate_n_flags(u8 rate, u32 flags)
0331 {
0332     return cpu_to_le32(flags|(u32)rate);
0333 }
0334 
0335 int iwl_alive_start(struct iwl_priv *priv);
0336 
0337 #ifdef CONFIG_IWLWIFI_DEBUG
0338 void iwl_print_rx_config_cmd(struct iwl_priv *priv,
0339                  enum iwl_rxon_context_id ctxid);
0340 #else
0341 static inline void iwl_print_rx_config_cmd(struct iwl_priv *priv,
0342                        enum iwl_rxon_context_id ctxid)
0343 {
0344 }
0345 #endif
0346 
0347 /* status checks */
0348 
0349 static inline int iwl_is_ready(struct iwl_priv *priv)
0350 {
0351     /* The adapter is 'ready' if READY EXIT_PENDING is not set */
0352     return test_bit(STATUS_READY, &priv->status) &&
0353            !test_bit(STATUS_EXIT_PENDING, &priv->status);
0354 }
0355 
0356 static inline int iwl_is_alive(struct iwl_priv *priv)
0357 {
0358     return test_bit(STATUS_ALIVE, &priv->status);
0359 }
0360 
0361 static inline int iwl_is_rfkill(struct iwl_priv *priv)
0362 {
0363     return test_bit(STATUS_RF_KILL_HW, &priv->status);
0364 }
0365 
0366 static inline int iwl_is_ctkill(struct iwl_priv *priv)
0367 {
0368     return test_bit(STATUS_CT_KILL, &priv->status);
0369 }
0370 
0371 static inline int iwl_is_ready_rf(struct iwl_priv *priv)
0372 {
0373     if (iwl_is_rfkill(priv))
0374         return 0;
0375 
0376     return iwl_is_ready(priv);
0377 }
0378 
0379 static inline void iwl_dvm_set_pmi(struct iwl_priv *priv, bool state)
0380 {
0381     if (state)
0382         set_bit(STATUS_POWER_PMI, &priv->status);
0383     else
0384         clear_bit(STATUS_POWER_PMI, &priv->status);
0385     iwl_trans_set_pmi(priv->trans, state);
0386 }
0387 
0388 #ifdef CONFIG_IWLWIFI_DEBUGFS
0389 void iwl_dbgfs_register(struct iwl_priv *priv, struct dentry *dbgfs_dir);
0390 #else
0391 static inline void iwl_dbgfs_register(struct iwl_priv *priv,
0392                       struct dentry *dbgfs_dir) { }
0393 #endif /* CONFIG_IWLWIFI_DEBUGFS */
0394 
0395 #ifdef CONFIG_IWLWIFI_DEBUG
0396 #define IWL_DEBUG_QUIET_RFKILL(m, fmt, args...) \
0397 do {                                    \
0398     if (!iwl_is_rfkill((m)))                    \
0399         IWL_ERR(m, fmt, ##args);                \
0400     else                                \
0401         __iwl_err((m)->dev,                 \
0402               iwl_have_debug_level(IWL_DL_RADIO) ?      \
0403                 IWL_ERR_MODE_RFKILL :           \
0404                 IWL_ERR_MODE_TRACE_ONLY,        \
0405               fmt, ##args);                 \
0406 } while (0)
0407 #else
0408 #define IWL_DEBUG_QUIET_RFKILL(m, fmt, args...) \
0409 do {                                    \
0410     if (!iwl_is_rfkill((m)))                    \
0411         IWL_ERR(m, fmt, ##args);                \
0412     else                                \
0413         __iwl_err((m)->dev, IWL_ERR_MODE_TRACE_ONLY,        \
0414               fmt, ##args);                 \
0415 } while (0)
0416 #endif              /* CONFIG_IWLWIFI_DEBUG */
0417 
0418 #endif /* __iwl_agn_h__ */