0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef STA_INFO_H
0010 #define STA_INFO_H
0011
0012 #include <linux/list.h>
0013 #include <linux/types.h>
0014 #include <linux/if_ether.h>
0015 #include <linux/workqueue.h>
0016 #include <linux/average.h>
0017 #include <linux/bitfield.h>
0018 #include <linux/etherdevice.h>
0019 #include <linux/rhashtable.h>
0020 #include <linux/u64_stats_sync.h>
0021 #include "key.h"
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078 enum ieee80211_sta_info_flags {
0079 WLAN_STA_AUTH,
0080 WLAN_STA_ASSOC,
0081 WLAN_STA_PS_STA,
0082 WLAN_STA_AUTHORIZED,
0083 WLAN_STA_SHORT_PREAMBLE,
0084 WLAN_STA_WDS,
0085 WLAN_STA_CLEAR_PS_FILT,
0086 WLAN_STA_MFP,
0087 WLAN_STA_BLOCK_BA,
0088 WLAN_STA_PS_DRIVER,
0089 WLAN_STA_PSPOLL,
0090 WLAN_STA_TDLS_PEER,
0091 WLAN_STA_TDLS_PEER_AUTH,
0092 WLAN_STA_TDLS_INITIATOR,
0093 WLAN_STA_TDLS_CHAN_SWITCH,
0094 WLAN_STA_TDLS_OFF_CHANNEL,
0095 WLAN_STA_TDLS_WIDER_BW,
0096 WLAN_STA_UAPSD,
0097 WLAN_STA_SP,
0098 WLAN_STA_4ADDR_EVENT,
0099 WLAN_STA_INSERTED,
0100 WLAN_STA_RATE_CONTROL,
0101 WLAN_STA_TOFFSET_KNOWN,
0102 WLAN_STA_MPSP_OWNER,
0103 WLAN_STA_MPSP_RECIPIENT,
0104 WLAN_STA_PS_DELIVER,
0105 WLAN_STA_USES_ENCRYPTION,
0106 WLAN_STA_DECAP_OFFLOAD,
0107
0108 NUM_WLAN_STA_FLAGS,
0109 };
0110
0111 #define ADDBA_RESP_INTERVAL HZ
0112 #define HT_AGG_MAX_RETRIES 15
0113 #define HT_AGG_BURST_RETRIES 3
0114 #define HT_AGG_RETRIES_PERIOD (15 * HZ)
0115
0116 #define HT_AGG_STATE_DRV_READY 0
0117 #define HT_AGG_STATE_RESPONSE_RECEIVED 1
0118 #define HT_AGG_STATE_OPERATIONAL 2
0119 #define HT_AGG_STATE_STOPPING 3
0120 #define HT_AGG_STATE_WANT_START 4
0121 #define HT_AGG_STATE_WANT_STOP 5
0122 #define HT_AGG_STATE_START_CB 6
0123 #define HT_AGG_STATE_STOP_CB 7
0124 #define HT_AGG_STATE_SENT_ADDBA 8
0125
0126 DECLARE_EWMA(avg_signal, 10, 8)
0127 enum ieee80211_agg_stop_reason {
0128 AGG_STOP_DECLINED,
0129 AGG_STOP_LOCAL_REQUEST,
0130 AGG_STOP_PEER_REQUEST,
0131 AGG_STOP_DESTROY_STA,
0132 };
0133
0134
0135 #define AIRTIME_USE_TX BIT(0)
0136 #define AIRTIME_USE_RX BIT(1)
0137
0138 struct airtime_info {
0139 u64 rx_airtime;
0140 u64 tx_airtime;
0141 u32 last_active;
0142 s32 deficit;
0143 atomic_t aql_tx_pending;
0144 u32 aql_limit_low;
0145 u32 aql_limit_high;
0146 };
0147
0148 void ieee80211_sta_update_pending_airtime(struct ieee80211_local *local,
0149 struct sta_info *sta, u8 ac,
0150 u16 tx_airtime, bool tx_completed);
0151
0152 struct sta_info;
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184 struct tid_ampdu_tx {
0185 struct rcu_head rcu_head;
0186 struct timer_list session_timer;
0187 struct timer_list addba_resp_timer;
0188 struct sk_buff_head pending;
0189 struct sta_info *sta;
0190 unsigned long state;
0191 unsigned long last_tx;
0192 u16 timeout;
0193 u8 dialog_token;
0194 u8 stop_initiator;
0195 bool tx_stop;
0196 u16 buf_size;
0197 u16 ssn;
0198
0199 u16 failed_bar_ssn;
0200 bool bar_pending;
0201 bool amsdu;
0202 u8 tid;
0203 };
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233
0234
0235
0236
0237
0238 struct tid_ampdu_rx {
0239 struct rcu_head rcu_head;
0240 spinlock_t reorder_lock;
0241 u64 reorder_buf_filtered;
0242 struct sk_buff_head *reorder_buf;
0243 unsigned long *reorder_time;
0244 struct sta_info *sta;
0245 struct timer_list session_timer;
0246 struct timer_list reorder_timer;
0247 unsigned long last_rx;
0248 u16 head_seq_num;
0249 u16 stored_mpdu_num;
0250 u16 ssn;
0251 u16 buf_size;
0252 u16 timeout;
0253 u8 tid;
0254 u8 auto_seq:1,
0255 removed:1,
0256 started:1;
0257 };
0258
0259
0260
0261
0262
0263
0264
0265
0266
0267
0268
0269
0270
0271
0272
0273
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283 struct sta_ampdu_mlme {
0284 struct mutex mtx;
0285
0286 struct tid_ampdu_rx __rcu *tid_rx[IEEE80211_NUM_TIDS];
0287 u8 tid_rx_token[IEEE80211_NUM_TIDS];
0288 unsigned long tid_rx_timer_expired[BITS_TO_LONGS(IEEE80211_NUM_TIDS)];
0289 unsigned long tid_rx_stop_requested[BITS_TO_LONGS(IEEE80211_NUM_TIDS)];
0290 unsigned long tid_rx_manage_offl[BITS_TO_LONGS(2 * IEEE80211_NUM_TIDS)];
0291 unsigned long agg_session_valid[BITS_TO_LONGS(IEEE80211_NUM_TIDS)];
0292 unsigned long unexpected_agg[BITS_TO_LONGS(IEEE80211_NUM_TIDS)];
0293
0294 struct work_struct work;
0295 struct tid_ampdu_tx __rcu *tid_tx[IEEE80211_NUM_TIDS];
0296 struct tid_ampdu_tx *tid_start_tx[IEEE80211_NUM_TIDS];
0297 unsigned long last_addba_req_time[IEEE80211_NUM_TIDS];
0298 u8 addba_req_num[IEEE80211_NUM_TIDS];
0299 u8 dialog_token_allocator;
0300 };
0301
0302
0303
0304 #define IEEE80211_TID_UNRESERVED 0xff
0305
0306 #define IEEE80211_FAST_XMIT_MAX_IV 18
0307
0308
0309
0310
0311
0312
0313
0314
0315
0316
0317
0318
0319
0320
0321
0322
0323 struct ieee80211_fast_tx {
0324 struct ieee80211_key *key;
0325 u8 hdr_len;
0326 u8 sa_offs, da_offs, pn_offs;
0327 u8 band;
0328 u8 hdr[30 + 2 + IEEE80211_FAST_XMIT_MAX_IV +
0329 sizeof(rfc1042_header)] __aligned(2);
0330
0331 struct rcu_head rcu_head;
0332 };
0333
0334
0335
0336
0337
0338
0339
0340
0341
0342
0343
0344
0345
0346
0347
0348
0349
0350 struct ieee80211_fast_rx {
0351 struct net_device *dev;
0352 enum nl80211_iftype vif_type;
0353 u8 vif_addr[ETH_ALEN] __aligned(2);
0354 u8 rfc1042_hdr[6] __aligned(2);
0355 __be16 control_port_protocol;
0356 __le16 expected_ds_bits;
0357 u8 icv_len;
0358 u8 key:1,
0359 internal_forward:1,
0360 uses_rss:1;
0361 u8 da_offs, sa_offs;
0362
0363 struct rcu_head rcu_head;
0364 };
0365
0366
0367 DECLARE_EWMA(mesh_fail_avg, 20, 8)
0368 DECLARE_EWMA(mesh_tx_rate_avg, 8, 16)
0369
0370
0371
0372
0373
0374
0375
0376
0377
0378
0379
0380
0381
0382
0383
0384
0385
0386
0387
0388
0389
0390
0391
0392
0393
0394
0395 struct mesh_sta {
0396 struct timer_list plink_timer;
0397 struct sta_info *plink_sta;
0398
0399 s64 t_offset;
0400 s64 t_offset_setpoint;
0401
0402 spinlock_t plink_lock;
0403 u16 llid;
0404 u16 plid;
0405 u16 aid;
0406 u16 reason;
0407 u8 plink_retries;
0408
0409 bool processed_beacon;
0410 bool connected_to_gate;
0411 bool connected_to_as;
0412
0413 enum nl80211_plink_state plink_state;
0414 u32 plink_timeout;
0415
0416
0417 enum nl80211_mesh_power_mode local_pm;
0418 enum nl80211_mesh_power_mode peer_pm;
0419 enum nl80211_mesh_power_mode nonpeer_pm;
0420
0421
0422 struct ewma_mesh_fail_avg fail_avg;
0423
0424 struct ewma_mesh_tx_rate_avg tx_rate_avg;
0425 };
0426
0427 DECLARE_EWMA(signal, 10, 8)
0428
0429 struct ieee80211_sta_rx_stats {
0430 unsigned long packets;
0431 unsigned long last_rx;
0432 unsigned long num_duplicates;
0433 unsigned long fragments;
0434 unsigned long dropped;
0435 int last_signal;
0436 u8 chains;
0437 s8 chain_signal_last[IEEE80211_MAX_CHAINS];
0438 u32 last_rate;
0439 struct u64_stats_sync syncp;
0440 u64 bytes;
0441 u64 msdu[IEEE80211_NUM_TIDS + 1];
0442 };
0443
0444
0445
0446
0447
0448
0449
0450
0451
0452 #define IEEE80211_FRAGMENT_MAX 4
0453
0454 struct ieee80211_fragment_entry {
0455 struct sk_buff_head skb_list;
0456 unsigned long first_frag_time;
0457 u16 seq;
0458 u16 extra_len;
0459 u16 last_frag;
0460 u8 rx_queue;
0461 u8 check_sequential_pn:1,
0462 is_protected:1;
0463 u8 last_pn[6];
0464 unsigned int key_color;
0465 };
0466
0467 struct ieee80211_fragment_cache {
0468 struct ieee80211_fragment_entry entries[IEEE80211_FRAGMENT_MAX];
0469 unsigned int next;
0470 };
0471
0472
0473
0474
0475
0476
0477
0478 #define STA_SLOW_THRESHOLD 6000
0479
0480
0481
0482
0483
0484
0485
0486
0487
0488
0489
0490
0491
0492
0493
0494
0495
0496
0497
0498
0499
0500
0501
0502
0503
0504
0505
0506
0507
0508
0509
0510
0511
0512
0513
0514
0515
0516
0517
0518
0519 struct link_sta_info {
0520 u8 addr[ETH_ALEN];
0521 u8 link_id;
0522
0523 struct rhlist_head link_hash_node;
0524
0525 struct sta_info *sta;
0526 struct ieee80211_key __rcu *gtk[NUM_DEFAULT_KEYS +
0527 NUM_DEFAULT_MGMT_KEYS +
0528 NUM_DEFAULT_BEACON_KEYS];
0529 struct ieee80211_sta_rx_stats __percpu *pcpu_rx_stats;
0530
0531
0532 struct ieee80211_sta_rx_stats rx_stats;
0533 struct {
0534 struct ewma_signal signal;
0535 struct ewma_signal chain_signal[IEEE80211_MAX_CHAINS];
0536 } rx_stats_avg;
0537
0538
0539 struct {
0540 unsigned long filtered;
0541 unsigned long retry_failed, retry_count;
0542 unsigned int lost_packets;
0543 unsigned long last_pkt_time;
0544 u64 msdu_retries[IEEE80211_NUM_TIDS + 1];
0545 u64 msdu_failed[IEEE80211_NUM_TIDS + 1];
0546 unsigned long last_ack;
0547 s8 last_ack_signal;
0548 bool ack_signal_filled;
0549 struct ewma_avg_signal avg_ack_signal;
0550 } status_stats;
0551
0552
0553 struct {
0554 u64 packets[IEEE80211_NUM_ACS];
0555 u64 bytes[IEEE80211_NUM_ACS];
0556 struct ieee80211_tx_rate last_rate;
0557 struct rate_info last_rate_info;
0558 u64 msdu[IEEE80211_NUM_TIDS + 1];
0559 } tx_stats;
0560
0561 enum ieee80211_sta_rx_bandwidth cur_max_bandwidth;
0562
0563 struct ieee80211_link_sta *pub;
0564 };
0565
0566
0567
0568
0569
0570
0571
0572
0573
0574
0575
0576
0577
0578
0579
0580
0581
0582
0583
0584
0585
0586
0587
0588
0589
0590
0591
0592
0593
0594
0595
0596
0597
0598
0599
0600
0601
0602
0603
0604
0605
0606
0607
0608
0609
0610
0611
0612
0613
0614
0615
0616
0617
0618
0619
0620
0621
0622
0623
0624
0625
0626
0627
0628
0629
0630
0631
0632
0633
0634
0635
0636
0637 struct sta_info {
0638
0639 struct list_head list, free_list;
0640 struct rcu_head rcu_head;
0641 struct rhlist_head hash_node;
0642 u8 addr[ETH_ALEN];
0643 struct ieee80211_local *local;
0644 struct ieee80211_sub_if_data *sdata;
0645 struct ieee80211_key __rcu *ptk[NUM_DEFAULT_KEYS];
0646 u8 ptk_idx;
0647 struct rate_control_ref *rate_ctrl;
0648 void *rate_ctrl_priv;
0649 spinlock_t rate_ctrl_lock;
0650 spinlock_t lock;
0651
0652 struct ieee80211_fast_tx __rcu *fast_tx;
0653 struct ieee80211_fast_rx __rcu *fast_rx;
0654
0655 #ifdef CONFIG_MAC80211_MESH
0656 struct mesh_sta *mesh;
0657 #endif
0658
0659 struct work_struct drv_deliver_wk;
0660
0661 u16 listen_interval;
0662
0663 bool dead;
0664 bool removed;
0665
0666 bool uploaded;
0667
0668 enum ieee80211_sta_state sta_state;
0669
0670
0671 unsigned long _flags;
0672
0673
0674 spinlock_t ps_lock;
0675 struct sk_buff_head ps_tx_buf[IEEE80211_NUM_ACS];
0676 struct sk_buff_head tx_filtered[IEEE80211_NUM_ACS];
0677 unsigned long driver_buffered_tids;
0678 unsigned long txq_buffered_tids;
0679
0680 u64 assoc_at;
0681 long last_connected;
0682
0683
0684 __le16 last_seq_ctrl[IEEE80211_NUM_TIDS + 1];
0685
0686 u16 tid_seq[IEEE80211_QOS_CTL_TID_MASK + 1];
0687
0688 struct airtime_info airtime[IEEE80211_NUM_ACS];
0689 u16 airtime_weight;
0690
0691
0692
0693
0694 struct sta_ampdu_mlme ampdu_mlme;
0695
0696 #ifdef CONFIG_MAC80211_DEBUGFS
0697 struct dentry *debugfs_dir;
0698 #endif
0699
0700 struct codel_params cparams;
0701
0702 u8 reserved_tid;
0703
0704 struct cfg80211_chan_def tdls_chandef;
0705
0706 struct ieee80211_fragment_cache frags;
0707
0708 struct link_sta_info deflink;
0709 struct link_sta_info __rcu *link[IEEE80211_MLD_MAX_NUM_LINKS];
0710
0711
0712 struct ieee80211_sta sta;
0713 };
0714
0715 static inline enum nl80211_plink_state sta_plink_state(struct sta_info *sta)
0716 {
0717 #ifdef CONFIG_MAC80211_MESH
0718 return sta->mesh->plink_state;
0719 #endif
0720 return NL80211_PLINK_LISTEN;
0721 }
0722
0723 static inline void set_sta_flag(struct sta_info *sta,
0724 enum ieee80211_sta_info_flags flag)
0725 {
0726 WARN_ON(flag == WLAN_STA_AUTH ||
0727 flag == WLAN_STA_ASSOC ||
0728 flag == WLAN_STA_AUTHORIZED);
0729 set_bit(flag, &sta->_flags);
0730 }
0731
0732 static inline void clear_sta_flag(struct sta_info *sta,
0733 enum ieee80211_sta_info_flags flag)
0734 {
0735 WARN_ON(flag == WLAN_STA_AUTH ||
0736 flag == WLAN_STA_ASSOC ||
0737 flag == WLAN_STA_AUTHORIZED);
0738 clear_bit(flag, &sta->_flags);
0739 }
0740
0741 static inline int test_sta_flag(struct sta_info *sta,
0742 enum ieee80211_sta_info_flags flag)
0743 {
0744 return test_bit(flag, &sta->_flags);
0745 }
0746
0747 static inline int test_and_clear_sta_flag(struct sta_info *sta,
0748 enum ieee80211_sta_info_flags flag)
0749 {
0750 WARN_ON(flag == WLAN_STA_AUTH ||
0751 flag == WLAN_STA_ASSOC ||
0752 flag == WLAN_STA_AUTHORIZED);
0753 return test_and_clear_bit(flag, &sta->_flags);
0754 }
0755
0756 static inline int test_and_set_sta_flag(struct sta_info *sta,
0757 enum ieee80211_sta_info_flags flag)
0758 {
0759 WARN_ON(flag == WLAN_STA_AUTH ||
0760 flag == WLAN_STA_ASSOC ||
0761 flag == WLAN_STA_AUTHORIZED);
0762 return test_and_set_bit(flag, &sta->_flags);
0763 }
0764
0765 int sta_info_move_state(struct sta_info *sta,
0766 enum ieee80211_sta_state new_state);
0767
0768 static inline void sta_info_pre_move_state(struct sta_info *sta,
0769 enum ieee80211_sta_state new_state)
0770 {
0771 int ret;
0772
0773 WARN_ON_ONCE(test_sta_flag(sta, WLAN_STA_INSERTED));
0774
0775 ret = sta_info_move_state(sta, new_state);
0776 WARN_ON_ONCE(ret);
0777 }
0778
0779
0780 void ieee80211_assign_tid_tx(struct sta_info *sta, int tid,
0781 struct tid_ampdu_tx *tid_tx);
0782
0783 static inline struct tid_ampdu_tx *
0784 rcu_dereference_protected_tid_tx(struct sta_info *sta, int tid)
0785 {
0786 return rcu_dereference_protected(sta->ampdu_mlme.tid_tx[tid],
0787 lockdep_is_held(&sta->lock) ||
0788 lockdep_is_held(&sta->ampdu_mlme.mtx));
0789 }
0790
0791
0792 #define STA_MAX_TX_BUFFER 64
0793
0794
0795
0796 #define STA_TX_BUFFER_EXPIRE (10 * HZ)
0797
0798
0799
0800 #define STA_INFO_CLEANUP_INTERVAL (10 * HZ)
0801
0802 struct rhlist_head *sta_info_hash_lookup(struct ieee80211_local *local,
0803 const u8 *addr);
0804
0805
0806
0807
0808 struct sta_info *sta_info_get(struct ieee80211_sub_if_data *sdata,
0809 const u8 *addr);
0810
0811 struct sta_info *sta_info_get_bss(struct ieee80211_sub_if_data *sdata,
0812 const u8 *addr);
0813
0814
0815 struct sta_info *sta_info_get_by_addrs(struct ieee80211_local *local,
0816 const u8 *sta_addr, const u8 *vif_addr);
0817
0818 #define for_each_sta_info(local, _addr, _sta, _tmp) \
0819 rhl_for_each_entry_rcu(_sta, _tmp, \
0820 sta_info_hash_lookup(local, _addr), hash_node)
0821
0822 struct rhlist_head *link_sta_info_hash_lookup(struct ieee80211_local *local,
0823 const u8 *addr);
0824
0825 #define for_each_link_sta_info(local, _addr, _sta, _tmp) \
0826 rhl_for_each_entry_rcu(_sta, _tmp, \
0827 link_sta_info_hash_lookup(local, _addr), \
0828 link_hash_node)
0829
0830 struct link_sta_info *
0831 link_sta_info_get_bss(struct ieee80211_sub_if_data *sdata, const u8 *addr);
0832
0833
0834
0835
0836 struct sta_info *sta_info_get_by_idx(struct ieee80211_sub_if_data *sdata,
0837 int idx);
0838
0839
0840
0841
0842 struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata,
0843 const u8 *addr, gfp_t gfp);
0844 struct sta_info *sta_info_alloc_with_link(struct ieee80211_sub_if_data *sdata,
0845 const u8 *mld_addr,
0846 unsigned int link_id,
0847 const u8 *link_addr,
0848 gfp_t gfp);
0849
0850 void sta_info_free(struct ieee80211_local *local, struct sta_info *sta);
0851
0852
0853
0854
0855
0856
0857
0858
0859
0860 int sta_info_insert(struct sta_info *sta);
0861 int sta_info_insert_rcu(struct sta_info *sta) __acquires(RCU);
0862
0863 int __must_check __sta_info_destroy(struct sta_info *sta);
0864 int sta_info_destroy_addr(struct ieee80211_sub_if_data *sdata,
0865 const u8 *addr);
0866 int sta_info_destroy_addr_bss(struct ieee80211_sub_if_data *sdata,
0867 const u8 *addr);
0868
0869 void sta_info_recalc_tim(struct sta_info *sta);
0870
0871 int sta_info_init(struct ieee80211_local *local);
0872 void sta_info_stop(struct ieee80211_local *local);
0873
0874
0875
0876
0877
0878
0879
0880
0881
0882 int __sta_info_flush(struct ieee80211_sub_if_data *sdata, bool vlans);
0883
0884
0885
0886
0887
0888
0889
0890
0891 static inline int sta_info_flush(struct ieee80211_sub_if_data *sdata)
0892 {
0893 return __sta_info_flush(sdata, false);
0894 }
0895
0896 void sta_set_rate_info_tx(struct sta_info *sta,
0897 const struct ieee80211_tx_rate *rate,
0898 struct rate_info *rinfo);
0899 void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo,
0900 bool tidstats);
0901
0902 u32 sta_get_expected_throughput(struct sta_info *sta);
0903
0904 void ieee80211_sta_expire(struct ieee80211_sub_if_data *sdata,
0905 unsigned long exp_time);
0906
0907 int ieee80211_sta_allocate_link(struct sta_info *sta, unsigned int link_id);
0908 void ieee80211_sta_free_link(struct sta_info *sta, unsigned int link_id);
0909 int ieee80211_sta_activate_link(struct sta_info *sta, unsigned int link_id);
0910 void ieee80211_sta_remove_link(struct sta_info *sta, unsigned int link_id);
0911
0912 void ieee80211_sta_ps_deliver_wakeup(struct sta_info *sta);
0913 void ieee80211_sta_ps_deliver_poll_response(struct sta_info *sta);
0914 void ieee80211_sta_ps_deliver_uapsd(struct sta_info *sta);
0915
0916 unsigned long ieee80211_sta_last_active(struct sta_info *sta);
0917
0918 void ieee80211_sta_set_max_amsdu_subframes(struct sta_info *sta,
0919 const u8 *ext_capab,
0920 unsigned int ext_capab_len);
0921
0922 enum sta_stats_type {
0923 STA_STATS_RATE_TYPE_INVALID = 0,
0924 STA_STATS_RATE_TYPE_LEGACY,
0925 STA_STATS_RATE_TYPE_HT,
0926 STA_STATS_RATE_TYPE_VHT,
0927 STA_STATS_RATE_TYPE_HE,
0928 STA_STATS_RATE_TYPE_S1G,
0929 };
0930
0931 #define STA_STATS_FIELD_HT_MCS GENMASK( 7, 0)
0932 #define STA_STATS_FIELD_LEGACY_IDX GENMASK( 3, 0)
0933 #define STA_STATS_FIELD_LEGACY_BAND GENMASK( 7, 4)
0934 #define STA_STATS_FIELD_VHT_MCS GENMASK( 3, 0)
0935 #define STA_STATS_FIELD_VHT_NSS GENMASK( 7, 4)
0936 #define STA_STATS_FIELD_HE_MCS GENMASK( 3, 0)
0937 #define STA_STATS_FIELD_HE_NSS GENMASK( 7, 4)
0938 #define STA_STATS_FIELD_BW GENMASK(11, 8)
0939 #define STA_STATS_FIELD_SGI GENMASK(12, 12)
0940 #define STA_STATS_FIELD_TYPE GENMASK(15, 13)
0941 #define STA_STATS_FIELD_HE_RU GENMASK(18, 16)
0942 #define STA_STATS_FIELD_HE_GI GENMASK(20, 19)
0943 #define STA_STATS_FIELD_HE_DCM GENMASK(21, 21)
0944
0945 #define STA_STATS_FIELD(_n, _v) FIELD_PREP(STA_STATS_FIELD_ ## _n, _v)
0946 #define STA_STATS_GET(_n, _v) FIELD_GET(STA_STATS_FIELD_ ## _n, _v)
0947
0948 #define STA_STATS_RATE_INVALID 0
0949
0950 static inline u32 sta_stats_encode_rate(struct ieee80211_rx_status *s)
0951 {
0952 u32 r;
0953
0954 r = STA_STATS_FIELD(BW, s->bw);
0955
0956 if (s->enc_flags & RX_ENC_FLAG_SHORT_GI)
0957 r |= STA_STATS_FIELD(SGI, 1);
0958
0959 switch (s->encoding) {
0960 case RX_ENC_VHT:
0961 r |= STA_STATS_FIELD(TYPE, STA_STATS_RATE_TYPE_VHT);
0962 r |= STA_STATS_FIELD(VHT_NSS, s->nss);
0963 r |= STA_STATS_FIELD(VHT_MCS, s->rate_idx);
0964 break;
0965 case RX_ENC_HT:
0966 r |= STA_STATS_FIELD(TYPE, STA_STATS_RATE_TYPE_HT);
0967 r |= STA_STATS_FIELD(HT_MCS, s->rate_idx);
0968 break;
0969 case RX_ENC_LEGACY:
0970 r |= STA_STATS_FIELD(TYPE, STA_STATS_RATE_TYPE_LEGACY);
0971 r |= STA_STATS_FIELD(LEGACY_BAND, s->band);
0972 r |= STA_STATS_FIELD(LEGACY_IDX, s->rate_idx);
0973 break;
0974 case RX_ENC_HE:
0975 r |= STA_STATS_FIELD(TYPE, STA_STATS_RATE_TYPE_HE);
0976 r |= STA_STATS_FIELD(HE_NSS, s->nss);
0977 r |= STA_STATS_FIELD(HE_MCS, s->rate_idx);
0978 r |= STA_STATS_FIELD(HE_GI, s->he_gi);
0979 r |= STA_STATS_FIELD(HE_RU, s->he_ru);
0980 r |= STA_STATS_FIELD(HE_DCM, s->he_dcm);
0981 break;
0982 default:
0983 WARN_ON(1);
0984 return STA_STATS_RATE_INVALID;
0985 }
0986
0987 return r;
0988 }
0989
0990 #endif