blob: 0701f0172751a3bb07aa239e8e226f66d630071b [file] [log] [blame]
developer7800b8d2022-06-23 22:15:56 +08001/* SPDX-License-Identifier: ISC */
2/* Copyright (C) 2020 MediaTek Inc. */
3
4#ifndef __BESRA_H
5#define __BESRA_H
6
7#include <linux/interrupt.h>
8#include <linux/ktime.h>
9#include "../mt76_connac.h"
10#include "regs.h"
11
12#define BESRA_MAX_INTERFACES 19
13#define BESRA_MAX_WMM_SETS 4
14#define BESRA_WTBL_SIZE 544
15#define BESRA_WTBL_RESERVED 201
16#define BESRA_WTBL_STA (BESRA_WTBL_RESERVED - \
17 BESRA_MAX_INTERFACES)
18
19#define BESRA_WATCHDOG_TIME (HZ / 10)
20#define BESRA_RESET_TIMEOUT (30 * HZ)
21
22#define BESRA_TX_RING_SIZE 2048
23#define BESRA_TX_MCU_RING_SIZE 256
24#define BESRA_TX_FWDL_RING_SIZE 128
25
26#define BESRA_RX_RING_SIZE 1536
27#define BESRA_RX_MCU_RING_SIZE 512
28
29#define MT7902_FIRMWARE_WA "mediatek/mt7902_wa.bin"
30#define MT7902_FIRMWARE_WM "mediatek/mt7902_wm.bin"
31#define MT7902_ROM_PATCH "mediatek/mt7902_rom_patch.bin"
32#define MT7902_FIRMWARE_ROM "mediatek/mt7902_wf_rom.bin"
33#define MT7902_FIRMWARE_ROM_SRAM "mediatek/mt7902_wf_rom_sram.bin"
34#define MT7902_EEPROM_DEFAULT "mediatek/mt7902_eeprom.bin"
35
36#define BESRA_EEPROM_SIZE 4096
37#define BESRA_EEPROM_BLOCK_SIZE 16
38#define BESRA_TOKEN_SIZE 8192
39
40#define BESRA_CFEND_RATE_DEFAULT 0x49 /* OFDM 24M */
41#define BESRA_CFEND_RATE_11B 0x03 /* 11B LP, 11M */
42
43#define BESRA_THERMAL_THROTTLE_MAX 100
44#define BESRA_CDEV_THROTTLE_MAX 99
45
46#define BESRA_SKU_RATE_NUM 161
47
48#define BESRA_MAX_TWT_AGRT 16
49#define BESRA_MAX_STA_TWT_AGRT 8
50#define BESRA_MAX_QUEUE (__MT_RXQ_MAX + __MT_MCUQ_MAX + 2)
51
52struct besra_vif;
53struct besra_sta;
54struct besra_dfs_pulse;
55struct besra_dfs_pattern;
56
57enum besra_txq_id {
58 BESRA_TXQ_FWDL = 16,
59 BESRA_TXQ_MCU_WM,
60 BESRA_TXQ_BAND0,
61 BESRA_TXQ_BAND1,
62 BESRA_TXQ_MCU_WA,
63 BESRA_TXQ_BAND2,
64};
65
66enum besra_rxq_id {
67 BESRA_RXQ_MCU_WM = 0,
68 BESRA_RXQ_MCU_WA,
69 BESRA_RXQ_MCU_WA_MAIN,
70 BESRA_RXQ_MCU_WA_EXT = 2,
71 BESRA_RXQ_MCU_WA_TRI = 2,
72 BESRA_RXQ_BAND0 = 4,
73 BESRA_RXQ_BAND1,
74 BESRA_RXQ_BAND2 = 8,
75};
76
77struct besra_twt_flow {
78 struct list_head list;
79 u64 start_tsf;
80 u64 tsf;
81 u32 duration;
82 u16 wcid;
83 __le16 mantissa;
84 u8 exp;
85 u8 table_id;
86 u8 id;
87 u8 protection:1;
88 u8 flowtype:1;
89 u8 trigger:1;
90 u8 sched:1;
91};
92
93struct besra_sta {
94 struct mt76_wcid wcid; /* must be first */
95
96 struct besra_vif *vif;
97
98 struct list_head poll_list;
99 struct list_head rc_list;
100 u32 airtime_ac[8];
101
102 unsigned long changed;
103 unsigned long jiffies;
104 unsigned long ampdu_state;
105
106 struct mt76_sta_stats stats;
107
108 struct mt76_connac_sta_key_conf bip;
109
110 struct {
111 u8 flowid_mask;
112 struct besra_twt_flow flow[BESRA_MAX_STA_TWT_AGRT];
113 } twt;
114};
115
116struct besra_vif_cap {
117 bool ht_ldpc:1;
118 bool vht_ldpc:1;
119 bool he_ldpc:1;
120 bool vht_su_ebfer:1;
121 bool vht_su_ebfee:1;
122 bool vht_mu_ebfer:1;
123 bool vht_mu_ebfee:1;
124 bool he_su_ebfer:1;
125 bool he_su_ebfee:1;
126 bool he_mu_ebfer:1;
127};
128
129struct besra_vif {
130 struct mt76_vif mt76; /* must be first */
131
132 struct besra_vif_cap cap;
133 struct besra_sta sta;
134 struct besra_phy *phy;
135
136 struct ieee80211_tx_queue_params queue_params[IEEE80211_NUM_ACS];
137 struct cfg80211_bitrate_mask bitrate_mask;
138};
139
140/* per-phy stats. */
141struct mib_stats {
142 u32 ack_fail_cnt;
143 u32 fcs_err_cnt;
144 u32 rts_cnt;
145 u32 rts_retries_cnt;
146 u32 ba_miss_cnt;
147 u32 tx_bf_cnt;
148 u32 tx_mu_mpdu_cnt;
149 u32 tx_mu_acked_mpdu_cnt;
150 u32 tx_su_acked_mpdu_cnt;
151 u32 tx_bf_ibf_ppdu_cnt;
152 u32 tx_bf_ebf_ppdu_cnt;
153
154 u32 tx_bf_rx_fb_all_cnt;
155 u32 tx_bf_rx_fb_he_cnt;
156 u32 tx_bf_rx_fb_vht_cnt;
157 u32 tx_bf_rx_fb_ht_cnt;
158
159 u32 tx_bf_rx_fb_bw; /* value of last sample, not cumulative */
160 u32 tx_bf_rx_fb_nc_cnt;
161 u32 tx_bf_rx_fb_nr_cnt;
162 u32 tx_bf_fb_cpl_cnt;
163 u32 tx_bf_fb_trig_cnt;
164
165 u32 tx_ampdu_cnt;
166 u32 tx_stop_q_empty_cnt;
167 u32 tx_mpdu_attempts_cnt;
168 u32 tx_mpdu_success_cnt;
169 u32 tx_pkt_ebf_cnt;
170 u32 tx_pkt_ibf_cnt;
171
172 u32 tx_rwp_fail_cnt;
173 u32 tx_rwp_need_cnt;
174
175 /* rx stats */
176 u32 rx_fifo_full_cnt;
177 u32 channel_idle_cnt;
178 u32 rx_vector_mismatch_cnt;
179 u32 rx_delimiter_fail_cnt;
180 u32 rx_len_mismatch_cnt;
181 u32 rx_mpdu_cnt;
182 u32 rx_ampdu_cnt;
183 u32 rx_ampdu_bytes_cnt;
184 u32 rx_ampdu_valid_subframe_cnt;
185 u32 rx_ampdu_valid_subframe_bytes_cnt;
186 u32 rx_pfdrop_cnt;
187 u32 rx_vec_queue_overflow_drop_cnt;
188 u32 rx_ba_cnt;
189
190 u32 tx_amsdu[8];
191 u32 tx_amsdu_cnt;
192};
193
194struct besra_hif {
195 struct list_head list;
196
197 struct device *dev;
198 void __iomem *regs;
199 int irq;
200};
201
202struct besra_phy {
203 struct mt76_phy *mt76;
204 struct besra_dev *dev;
205
206 struct ieee80211_sband_iftype_data iftype[NUM_NL80211_BANDS][NUM_NL80211_IFTYPES];
207
208 struct ieee80211_vif *monitor_vif;
209
210 struct thermal_cooling_device *cdev;
211 u8 cdev_state;
212 u8 throttle_state;
213 u32 throttle_temp[2]; /* 0: critical high, 1: maximum */
214
215 u32 rxfilter;
216 u64 omac_mask;
217 u8 band_idx;
218
219 u16 noise;
220
221 s16 coverage_class;
222 u8 slottime;
223
224 u8 rdd_state;
225
226 u32 rx_ampdu_ts;
227 u32 ampdu_ref;
228
229 struct mib_stats mib;
230 struct mt76_channel_state state_ts;
231
232#ifdef CONFIG_NL80211_TESTMODE
233 struct {
234 u32 *reg_backup;
235
236 s32 last_freq_offset;
237 u8 last_rcpi[4];
238 s8 last_ib_rssi[4];
239 s8 last_wb_rssi[4];
240 u8 last_snr;
241
242 u8 spe_idx;
243 } test;
244#endif
245};
246
247struct besra_dev {
248 union { /* must be first */
249 struct mt76_dev mt76;
250 struct mt76_phy mphy;
251 };
252
253 struct besra_hif *hif2;
254 struct besra_reg_desc reg;
255 u8 q_id[BESRA_MAX_QUEUE];
256 u32 q_int_mask[BESRA_MAX_QUEUE];
257 u32 wfdma_mask;
258
259 const struct mt76_bus_ops *bus_ops;
260 struct tasklet_struct irq_tasklet;
261 struct besra_phy phy;
262
263 /* monitor rx chain configured channel */
264 struct cfg80211_chan_def rdd2_chandef;
265 struct besra_phy *rdd2_phy;
266
267 u32 chainmask;
268 u16 chain_shift_ext;
269 u16 chain_shift_tri;
270 u32 hif_idx;
271
272 struct work_struct init_work;
273 struct work_struct rc_work;
274 struct work_struct reset_work;
275 wait_queue_head_t reset_wait;
276 u32 reset_state;
277
278 struct list_head sta_rc_list;
279 struct list_head sta_poll_list;
280 struct list_head twt_list;
281 spinlock_t sta_poll_lock;
282
283 u32 hw_pattern;
284
285 bool dbdc_support;
286 bool tbtc_support;
287 bool flash_mode;
288 bool muru_debug;
289 bool ibf;
290 u8 fw_debug_wm;
291 u8 fw_debug_wa;
292 u8 fw_debug_bin;
293 u16 fw_debug_seq;
294
295 struct dentry *debugfs_dir;
296 struct rchan *relay_fwlog;
297
298 void *cal;
299
300 struct {
301 u8 table_mask;
302 u8 n_agrt;
303 } twt;
304};
305
306enum {
307 WFDMA0 = 0x0,
308 WFDMA1,
309 WFDMA_EXT,
310 __MT_WFDMA_MAX,
311};
312
313enum {
314 MT_CTX0,
315 MT_HIF0 = 0x0,
316
317 MT_LMAC_AC00 = 0x0,
318 MT_LMAC_AC01,
319 MT_LMAC_AC02,
320 MT_LMAC_AC03,
321 MT_LMAC_ALTX0 = 0x10,
322 MT_LMAC_BMC0,
323 MT_LMAC_BCN0,
324 MT_LMAC_PSMP0,
325};
326
327enum {
328 MT_RX_SEL0,
329 MT_RX_SEL1,
330 MT_RX_SEL2, /* monitor chain */
331};
332
333enum besra_rdd_cmd {
334 RDD_STOP,
335 RDD_START,
336 RDD_DET_MODE,
337 RDD_RADAR_EMULATE,
338 RDD_START_TXQ = 20,
339 RDD_CAC_START = 50,
340 RDD_CAC_END,
341 RDD_NORMAL_START,
342 RDD_DISABLE_DFS_CAL,
343 RDD_PULSE_DBG,
344 RDD_READ_PULSE,
345 RDD_RESUME_BF,
346 RDD_IRQ_OFF,
347};
348
349static inline struct besra_phy *
350besra_hw_phy(struct ieee80211_hw *hw)
351{
352 struct mt76_phy *phy = hw->priv;
353
354 return phy->priv;
355}
356
357static inline struct besra_dev *
358besra_hw_dev(struct ieee80211_hw *hw)
359{
360 struct mt76_phy *phy = hw->priv;
361
362 return container_of(phy->dev, struct besra_dev, mt76);
363}
364
365static inline struct besra_phy *
366besra_ext_phy(struct besra_dev *dev)
367{
368 struct mt76_phy *phy = dev->mt76.phy2;
369
370 if (!phy)
371 return NULL;
372
373 return phy->priv;
374}
375
376static inline struct besra_phy *
377besra_tri_phy(struct besra_dev *dev)
378{
379 struct mt76_phy *phy = dev->mt76.phy3;
380
381 if (!phy)
382 return NULL;
383
384 return phy->priv;
385}
386
387static inline u8
388besra_get_phy_id(struct besra_phy *phy)
389{
390 if (phy->mt76 == &phy->dev->mphy)
391 return MT_MAIN_PHY;
392
393 if (phy->mt76 == phy->dev->mt76.phy2)
394 return MT_EXT_PHY;
395
396 return MT_TRI_PHY;
397}
398
399extern const struct ieee80211_ops besra_ops;
400extern const struct mt76_testmode_ops besra_testmode_ops;
401extern struct pci_driver besra_pci_driver;
402extern struct pci_driver besra_hif_driver;
403
404struct besra_dev *besra_mmio_probe(struct device *pdev,
405 void __iomem *mem_base, u32 device_id);
406void besra_wfsys_reset(struct besra_dev *dev);
407irqreturn_t besra_irq_handler(int irq, void *dev_instance);
408u64 __besra_get_tsf(struct ieee80211_hw *hw, struct besra_vif *mvif);
409int besra_register_device(struct besra_dev *dev);
410void besra_unregister_device(struct besra_dev *dev);
411int besra_eeprom_init(struct besra_dev *dev);
412void besra_eeprom_parse_hw_cap(struct besra_dev *dev,
413 struct besra_phy *phy);
414int besra_eeprom_get_target_power(struct besra_dev *dev,
415 struct ieee80211_channel *chan,
416 u8 chain_idx);
417s8 besra_eeprom_get_power_delta(struct besra_dev *dev, int band);
418int besra_dma_init(struct besra_dev *dev);
419void besra_dma_prefetch(struct besra_dev *dev);
420void besra_dma_cleanup(struct besra_dev *dev);
421int besra_rom_start(struct besra_dev *dev);
422int besra_mcu_init(struct besra_dev *dev);
423int besra_mcu_twt_agrt_update(struct besra_dev *dev,
424 struct besra_vif *mvif,
425 struct besra_twt_flow *flow,
426 int cmd);
427int besra_mcu_add_dev_info(struct besra_phy *phy,
428 struct ieee80211_vif *vif, bool enable);
429int besra_mcu_add_bss_info(struct besra_phy *phy,
430 struct ieee80211_vif *vif, int enable);
431int besra_mcu_add_sta(struct besra_dev *dev, struct ieee80211_vif *vif,
432 struct ieee80211_sta *sta, bool enable);
433int besra_mcu_add_tx_ba(struct besra_dev *dev,
434 struct ieee80211_ampdu_params *params,
435 bool add);
436int besra_mcu_add_rx_ba(struct besra_dev *dev,
437 struct ieee80211_ampdu_params *params,
438 bool add);
439int besra_mcu_update_bss_color(struct besra_dev *dev, struct ieee80211_vif *vif,
440 struct cfg80211_he_bss_color *he_bss_color);
441int besra_mcu_add_beacon(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
442 int enable);
443int besra_mcu_add_obss_spr(struct besra_dev *dev, struct ieee80211_vif *vif,
444 bool enable);
445int besra_mcu_add_rate_ctrl(struct besra_dev *dev, struct ieee80211_vif *vif,
446 struct ieee80211_sta *sta, bool changed);
447int besra_mcu_add_smps(struct besra_dev *dev, struct ieee80211_vif *vif,
448 struct ieee80211_sta *sta);
449int besra_set_channel(struct besra_phy *phy);
450int besra_mcu_set_chan_info(struct besra_phy *phy, int tag);
451int besra_mcu_set_tx(struct besra_dev *dev, struct ieee80211_vif *vif);
452int besra_mcu_update_edca(struct besra_dev *dev, void *req);
453int besra_mcu_set_fixed_rate_ctrl(struct besra_dev *dev,
454 struct ieee80211_vif *vif,
455 struct ieee80211_sta *sta,
456 void *data, u32 field);
457int besra_mcu_set_eeprom(struct besra_dev *dev);
458int besra_mcu_get_eeprom(struct besra_dev *dev, u32 offset);
459int besra_mcu_get_eeprom_free_block(struct besra_dev *dev, u8 *block_num);
460int besra_mcu_set_test_param(struct besra_dev *dev, u8 param, bool test_mode,
461 u8 en);
462int besra_mcu_set_ser(struct besra_dev *dev, u8 action, u8 set, u8 band);
463int besra_mcu_set_sku_en(struct besra_phy *phy, bool enable);
464int besra_mcu_set_txpower_sku(struct besra_phy *phy);
465int besra_mcu_get_txpower_sku(struct besra_phy *phy, s8 *txpower, int len);
466int besra_mcu_set_txbf(struct besra_dev *dev, u8 action);
467int besra_mcu_set_fcc5_lpn(struct besra_dev *dev, int val);
468int besra_mcu_set_pulse_th(struct besra_dev *dev,
469 const struct besra_dfs_pulse *pulse);
470int besra_mcu_set_radar_th(struct besra_dev *dev, int index,
471 const struct besra_dfs_pattern *pattern);
472int besra_mcu_set_radio_en(struct besra_phy *phy, bool enable);
473void besra_mcu_set_pm(void *priv, u8 *mac, struct ieee80211_vif *vif);
474int besra_mcu_set_rts_thresh(struct besra_phy *phy, u32 val);
475int besra_mcu_set_edcca_thresh(struct besra_phy *phy);
476int besra_mcu_set_edcca_en(struct besra_phy *phy, bool enable);
477int besra_mcu_set_muru_ctrl(struct besra_dev *dev, u32 cmd, u32 val);
478int besra_mcu_apply_group_cal(struct besra_dev *dev);
479int besra_mcu_apply_tx_dpd(struct besra_phy *phy);
480int besra_mcu_get_chan_mib_info(struct besra_phy *phy, bool chan_switch);
481int besra_mcu_get_temperature(struct besra_phy *phy);
482int besra_mcu_set_thermal_throttling(struct besra_phy *phy, u8 state);
483int besra_mcu_get_rx_rate(struct besra_phy *phy, struct ieee80211_vif *vif,
484 struct ieee80211_sta *sta, struct rate_info *rate);
485int besra_mcu_rdd_cmd(struct besra_dev *dev, int cmd, u8 index,
486 u8 rx_sel, u8 val);
487int besra_mcu_rdd_background_enable(struct besra_phy *phy,
488 struct cfg80211_chan_def *chandef);
489int besra_mcu_rf_regval(struct besra_dev *dev, u32 regidx, u32 *val, bool set);
490int besra_mcu_wa_cmd(struct besra_dev *dev, int cmd, u32 a1, u32 a2, u32 a3);
491int besra_mcu_fw_log_2_host(struct besra_dev *dev, u8 type, u8 ctrl);
492int besra_mcu_fw_dbg_ctrl(struct besra_dev *dev, u32 module, u8 level);
493void besra_mcu_rx_event(struct besra_dev *dev, struct sk_buff *skb);
494void besra_mcu_exit(struct besra_dev *dev);
495int besra_mcu_set_hdr_trans(struct besra_dev *dev, bool hdr_trans);
496
497void besra_dual_hif_set_irq_mask(struct besra_dev *dev, bool write_reg,
498 u32 clear, u32 set);
499
500static inline void besra_irq_enable(struct besra_dev *dev, u32 mask)
501{
502 if (dev->hif2)
503 besra_dual_hif_set_irq_mask(dev, false, 0, mask);
504 else
505 mt76_set_irq_mask(&dev->mt76, 0, 0, mask);
506
507 tasklet_schedule(&dev->irq_tasklet);
508}
509
510static inline void besra_irq_disable(struct besra_dev *dev, u32 mask)
511{
512 if (dev->hif2)
513 besra_dual_hif_set_irq_mask(dev, true, mask, 0);
514 else
515 mt76_set_irq_mask(&dev->mt76, MT_INT_MASK_CSR, mask, 0);
516}
517
518u32 besra_mac_wtbl_lmac_addr(struct besra_dev *dev, u16 wcid, u8 dw);
519bool besra_mac_wtbl_update(struct besra_dev *dev, int idx, u32 mask);
520void besra_mac_reset_counters(struct besra_phy *phy);
521void besra_mac_cca_stats_reset(struct besra_phy *phy);
522void besra_mac_enable_nf(struct besra_dev *dev, u8 band);
523void besra_mac_write_txwi(struct besra_dev *dev, __le32 *txwi,
524 struct sk_buff *skb, struct mt76_wcid *wcid, int pid,
525 struct ieee80211_key_conf *key, bool beacon);
526void besra_mac_set_timing(struct besra_phy *phy);
527int besra_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
528 struct ieee80211_sta *sta);
529void besra_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif,
530 struct ieee80211_sta *sta);
531void besra_mac_work(struct work_struct *work);
532void besra_mac_reset_work(struct work_struct *work);
533void besra_mac_sta_rc_work(struct work_struct *work);
534void besra_mac_update_stats(struct besra_phy *phy);
535void besra_mac_twt_teardown_flow(struct besra_dev *dev,
536 struct besra_sta *msta,
537 u8 flowid);
538void besra_mac_add_twt_setup(struct ieee80211_hw *hw,
539 struct ieee80211_sta *sta,
540 struct ieee80211_twt_setup *twt);
541int besra_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
542 enum mt76_txq_id qid, struct mt76_wcid *wcid,
543 struct ieee80211_sta *sta,
544 struct mt76_tx_info *tx_info);
545void besra_tx_complete_skb(struct mt76_dev *mdev, struct mt76_queue_entry *e);
546void besra_tx_token_put(struct besra_dev *dev);
547int besra_init_tx_queues(struct besra_phy *phy, int idx, int n_desc, int ring_base);
548void besra_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q,
549 struct sk_buff *skb);
550bool besra_rx_check(struct mt76_dev *mdev, enum mt76_rxq_id q, void *data, int len);
551void besra_sta_ps(struct mt76_dev *mdev, struct ieee80211_sta *sta, bool ps);
552void besra_stats_work(struct work_struct *work);
553int mt76_dfs_start_rdd(struct besra_dev *dev, bool force);
554int besra_dfs_init_radar_detector(struct besra_phy *phy);
555void besra_set_stream_he_caps(struct besra_phy *phy);
556void besra_set_stream_vht_txbf_caps(struct besra_phy *phy);
557void besra_update_channel(struct mt76_phy *mphy);
558int besra_mcu_muru_debug_set(struct besra_dev *dev, bool enable);
559int besra_mcu_muru_debug_get(struct besra_phy *phy, void *ms);
560int besra_init_debugfs(struct besra_phy *phy);
561void besra_debugfs_rx_fw_monitor(struct besra_dev *dev, const void *data, int len);
562bool besra_debugfs_rx_log(struct besra_dev *dev, const void *data, int len);
563int besra_mcu_add_key(struct mt76_dev *dev, struct ieee80211_vif *vif,
564 struct mt76_connac_sta_key_conf *sta_key_conf,
565 struct ieee80211_key_conf *key, int mcu_cmd,
566 struct mt76_wcid *wcid, enum set_key_cmd cmd);
567int besra_mcu_wtbl_update_hdr_trans(struct besra_dev *dev,
568 struct ieee80211_vif *vif, struct ieee80211_sta *sta);
569#ifdef CONFIG_MAC80211_DEBUGFS
570void besra_sta_add_debugfs(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
571 struct ieee80211_sta *sta, struct dentry *dir);
572#endif
573
574#endif