mt76: mt7615: disable hw/sched scan ops for non-offload firmware
[linux-2.6-microblaze.git] / drivers / net / wireless / mediatek / mt76 / mt7615 / mt7615.h
1 /* SPDX-License-Identifier: ISC */
2 /* Copyright (C) 2019 MediaTek Inc. */
3
4 #ifndef __MT7615_H
5 #define __MT7615_H
6
7 #include <linux/interrupt.h>
8 #include <linux/ktime.h>
9 #include <linux/regmap.h>
10 #include "../mt76.h"
11 #include "regs.h"
12
13 #define MT7615_MAX_INTERFACES           4
14 #define MT7615_MAX_WMM_SETS             4
15 #define MT7615_WTBL_SIZE                128
16 #define MT7615_WTBL_RESERVED            (MT7615_WTBL_SIZE - 1)
17 #define MT7615_WTBL_STA                 (MT7615_WTBL_RESERVED - \
18                                          MT7615_MAX_INTERFACES)
19
20 #define MT7615_WATCHDOG_TIME            (HZ / 10)
21 #define MT7615_HW_SCAN_TIMEOUT          (HZ / 10)
22 #define MT7615_RESET_TIMEOUT            (30 * HZ)
23 #define MT7615_RATE_RETRY               2
24
25 #define MT7615_TX_RING_SIZE             1024
26 #define MT7615_TX_MGMT_RING_SIZE        128
27 #define MT7615_TX_MCU_RING_SIZE         128
28 #define MT7615_TX_FWDL_RING_SIZE        128
29
30 #define MT7615_RX_RING_SIZE             1024
31 #define MT7615_RX_MCU_RING_SIZE         512
32
33 #define MT7615_FIRMWARE_CR4             "mediatek/mt7615_cr4.bin"
34 #define MT7615_FIRMWARE_N9              "mediatek/mt7615_n9.bin"
35 #define MT7615_ROM_PATCH                "mediatek/mt7615_rom_patch.bin"
36
37 #define MT7622_FIRMWARE_N9              "mediatek/mt7622_n9.bin"
38 #define MT7622_ROM_PATCH                "mediatek/mt7622_rom_patch.bin"
39
40 #define MT7615_FIRMWARE_V1              1
41 #define MT7615_FIRMWARE_V2              2
42 #define MT7615_FIRMWARE_V3              3
43
44 #define MT7663_ROM_PATCH                "mediatek/mt7663pr2h.bin"
45 #define MT7663_FIRMWARE_N9              "mediatek/mt7663_n9_v3.bin"
46
47 #define MT7615_EEPROM_SIZE              1024
48 #define MT7615_TOKEN_SIZE               4096
49
50 #define MT_FRAC_SCALE           12
51 #define MT_FRAC(val, div)       (((val) << MT_FRAC_SCALE) / (div))
52
53 #define MT_CHFREQ_VALID         BIT(7)
54 #define MT_CHFREQ_DBDC_IDX      BIT(6)
55 #define MT_CHFREQ_SEQ           GENMASK(5, 0)
56
57 #define MT7615_BAR_RATE_DEFAULT         0x4b /* OFDM 6M */
58 #define MT7615_CFEND_RATE_DEFAULT       0x49 /* OFDM 24M */
59 #define MT7615_CFEND_RATE_11B           0x03 /* 11B LP, 11M */
60
61 #define MT7615_SCAN_IE_LEN              600
62 #define MT7615_MAX_SCHED_SCAN_INTERVAL  10
63 #define MT7615_MAX_SCHED_SCAN_SSID      10
64 #define MT7615_MAX_SCAN_MATCH           16
65
66 struct mt7615_vif;
67 struct mt7615_sta;
68 struct mt7615_dfs_pulse;
69 struct mt7615_dfs_pattern;
70 enum mt7615_cipher_type;
71
72 enum mt7615_hw_txq_id {
73         MT7615_TXQ_MAIN,
74         MT7615_TXQ_EXT,
75         MT7615_TXQ_MCU,
76         MT7615_TXQ_FWDL,
77 };
78
79 enum mt7622_hw_txq_id {
80         MT7622_TXQ_AC0,
81         MT7622_TXQ_AC1,
82         MT7622_TXQ_AC2,
83         MT7622_TXQ_FWDL = MT7615_TXQ_FWDL,
84         MT7622_TXQ_AC3,
85         MT7622_TXQ_MGMT,
86         MT7622_TXQ_MCU = 15,
87 };
88
89 struct mt7615_rate_set {
90         struct ieee80211_tx_rate probe_rate;
91         struct ieee80211_tx_rate rates[4];
92 };
93
94 struct mt7615_rate_desc {
95         bool rateset;
96         u16 probe_val;
97         u16 val[4];
98         u8 bw_idx;
99         u8 bw;
100 };
101
102 enum mt7615_wtbl_desc_type {
103         MT7615_WTBL_RATE_DESC,
104         MT7615_WTBL_KEY_DESC
105 };
106
107 struct mt7615_key_desc {
108         enum set_key_cmd cmd;
109         u32 cipher;
110         s8 keyidx;
111         u8 keylen;
112         u8 *key;
113 };
114
115 struct mt7615_wtbl_desc {
116         struct list_head node;
117
118         enum mt7615_wtbl_desc_type type;
119         struct mt7615_sta *sta;
120
121         union {
122                 struct mt7615_rate_desc rate;
123                 struct mt7615_key_desc key;
124         };
125 };
126
127 struct mt7615_sta {
128         struct mt76_wcid wcid; /* must be first */
129
130         struct mt7615_vif *vif;
131
132         struct list_head poll_list;
133         u32 airtime_ac[8];
134
135         struct ieee80211_tx_rate rates[4];
136
137         struct mt7615_rate_set rateset[2];
138         u32 rate_set_tsf;
139
140         u8 rate_count;
141         u8 n_rates;
142
143         u8 rate_probe;
144 };
145
146 struct mt7615_vif {
147         u8 idx;
148         u8 omac_idx;
149         u8 band_idx;
150         u8 wmm_idx;
151         u8 scan_seq_num;
152
153         struct mt7615_sta sta;
154 };
155
156 struct mib_stats {
157         u16 ack_fail_cnt;
158         u16 fcs_err_cnt;
159         u16 rts_cnt;
160         u16 rts_retries_cnt;
161         u16 ba_miss_cnt;
162         unsigned long aggr_per;
163 };
164
165 struct mt7615_phy {
166         struct mt76_phy *mt76;
167         struct mt7615_dev *dev;
168
169         u32 rxfilter;
170         u32 omac_mask;
171
172         u16 noise;
173
174         bool scs_en;
175
176         unsigned long last_cca_adj;
177         int false_cca_ofdm, false_cca_cck;
178         s8 ofdm_sensitivity;
179         s8 cck_sensitivity;
180
181         u16 chainmask;
182
183         s16 coverage_class;
184         u8 slottime;
185
186         u8 chfreq;
187         u8 rdd_state;
188         int dfs_state;
189
190         __le32 rx_ampdu_ts;
191         u32 ampdu_ref;
192
193         struct mib_stats mib;
194
195         struct sk_buff_head scan_event_list;
196         struct delayed_work scan_work;
197 };
198
199 #define mt7615_mcu_add_tx_ba(dev, ...)  (dev)->mcu_ops->add_tx_ba((dev), __VA_ARGS__)
200 #define mt7615_mcu_add_rx_ba(dev, ...)  (dev)->mcu_ops->add_rx_ba((dev), __VA_ARGS__)
201 #define mt7615_mcu_sta_add(dev, ...)    (dev)->mcu_ops->sta_add((dev),  __VA_ARGS__)
202 #define mt7615_mcu_add_dev_info(dev, ...) (dev)->mcu_ops->add_dev_info((dev),  __VA_ARGS__)
203 #define mt7615_mcu_add_bss_info(phy, ...) (phy->dev)->mcu_ops->add_bss_info((phy),  __VA_ARGS__)
204 #define mt7615_mcu_add_beacon(dev, ...) (dev)->mcu_ops->add_beacon_offload((dev),  __VA_ARGS__)
205 #define mt7615_mcu_set_pm(dev, ...)     (dev)->mcu_ops->set_pm_state((dev),  __VA_ARGS__)
206 struct mt7615_mcu_ops {
207         int (*add_tx_ba)(struct mt7615_dev *dev,
208                          struct ieee80211_ampdu_params *params,
209                          bool enable);
210         int (*add_rx_ba)(struct mt7615_dev *dev,
211                          struct ieee80211_ampdu_params *params,
212                          bool enable);
213         int (*sta_add)(struct mt7615_dev *dev,
214                        struct ieee80211_vif *vif,
215                        struct ieee80211_sta *sta, bool enable);
216         int (*add_dev_info)(struct mt7615_dev *dev,
217                             struct ieee80211_vif *vif, bool enable);
218         int (*add_bss_info)(struct mt7615_phy *phy, struct ieee80211_vif *vif,
219                             bool enable);
220         int (*add_beacon_offload)(struct mt7615_dev *dev,
221                                   struct ieee80211_hw *hw,
222                                   struct ieee80211_vif *vif, bool enable);
223         int (*set_pm_state)(struct mt7615_dev *dev, int band, int state);
224 };
225
226 struct mt7615_dev {
227         union { /* must be first */
228                 struct mt76_dev mt76;
229                 struct mt76_phy mphy;
230         };
231
232         struct mt7615_phy phy;
233         u32 vif_mask;
234         u32 omac_mask;
235
236         u16 chainmask;
237
238         struct ieee80211_ops *ops;
239         const struct mt7615_mcu_ops *mcu_ops;
240         struct regmap *infracfg;
241         const u32 *reg_map;
242
243         struct work_struct mcu_work;
244
245         struct work_struct reset_work;
246         wait_queue_head_t reset_wait;
247         u32 reset_state;
248
249         struct list_head sta_poll_list;
250         spinlock_t sta_poll_lock;
251
252         struct {
253                 u8 n_pulses;
254                 u32 period;
255                 u16 width;
256                 s16 power;
257         } radar_pattern;
258         u32 hw_pattern;
259
260         u8 mac_work_count;
261         bool fw_debug;
262         bool flash_eeprom;
263
264         spinlock_t token_lock;
265         struct idr token;
266
267         u8 fw_ver;
268 };
269
270 enum {
271         HW_BSSID_0 = 0x0,
272         HW_BSSID_1,
273         HW_BSSID_2,
274         HW_BSSID_3,
275         HW_BSSID_MAX,
276         EXT_BSSID_START = 0x10,
277         EXT_BSSID_1,
278         EXT_BSSID_2,
279         EXT_BSSID_3,
280         EXT_BSSID_4,
281         EXT_BSSID_5,
282         EXT_BSSID_6,
283         EXT_BSSID_7,
284         EXT_BSSID_8,
285         EXT_BSSID_9,
286         EXT_BSSID_10,
287         EXT_BSSID_11,
288         EXT_BSSID_12,
289         EXT_BSSID_13,
290         EXT_BSSID_14,
291         EXT_BSSID_15,
292         EXT_BSSID_END
293 };
294
295 enum {
296         MT_RX_SEL0,
297         MT_RX_SEL1,
298 };
299
300 enum mt7615_rdd_cmd {
301         RDD_STOP,
302         RDD_START,
303         RDD_DET_MODE,
304         RDD_DET_STOP,
305         RDD_CAC_START,
306         RDD_CAC_END,
307         RDD_NORMAL_START,
308         RDD_DISABLE_DFS_CAL,
309         RDD_PULSE_DBG,
310         RDD_READ_PULSE,
311         RDD_RESUME_BF,
312 };
313
314 static inline struct mt7615_phy *
315 mt7615_hw_phy(struct ieee80211_hw *hw)
316 {
317         struct mt76_phy *phy = hw->priv;
318
319         return phy->priv;
320 }
321
322 static inline struct mt7615_dev *
323 mt7615_hw_dev(struct ieee80211_hw *hw)
324 {
325         struct mt76_phy *phy = hw->priv;
326
327         return container_of(phy->dev, struct mt7615_dev, mt76);
328 }
329
330 static inline struct mt7615_phy *
331 mt7615_ext_phy(struct mt7615_dev *dev)
332 {
333         struct mt76_phy *phy = dev->mt76.phy2;
334
335         if (!phy)
336                 return NULL;
337
338         return phy->priv;
339 }
340
341 extern const struct ieee80211_ops mt7615_ops;
342 extern const u32 mt7615e_reg_map[__MT_BASE_MAX];
343 extern const u32 mt7663e_reg_map[__MT_BASE_MAX];
344 extern struct pci_driver mt7615_pci_driver;
345 extern struct platform_driver mt7622_wmac_driver;
346
347 #ifdef CONFIG_MT7622_WMAC
348 int mt7622_wmac_init(struct mt7615_dev *dev);
349 #else
350 static inline int mt7622_wmac_init(struct mt7615_dev *dev)
351 {
352         return 0;
353 }
354 #endif
355
356 int mt7615_mmio_probe(struct device *pdev, void __iomem *mem_base,
357                       int irq, const u32 *map);
358 u32 mt7615_reg_map(struct mt7615_dev *dev, u32 addr);
359
360 void mt7615_init_device(struct mt7615_dev *dev);
361 int mt7615_register_device(struct mt7615_dev *dev);
362 void mt7615_unregister_device(struct mt7615_dev *dev);
363 int mt7615_register_ext_phy(struct mt7615_dev *dev);
364 void mt7615_unregister_ext_phy(struct mt7615_dev *dev);
365 int mt7615_eeprom_init(struct mt7615_dev *dev, u32 addr);
366 int mt7615_eeprom_get_power_index(struct mt7615_dev *dev,
367                                   struct ieee80211_channel *chan,
368                                   u8 chain_idx);
369 int mt7615_dma_init(struct mt7615_dev *dev);
370 void mt7615_dma_cleanup(struct mt7615_dev *dev);
371 int mt7615_mcu_init(struct mt7615_dev *dev);
372 bool mt7615_wait_for_mcu_init(struct mt7615_dev *dev);
373 void mt7615_mac_set_rates(struct mt7615_phy *phy, struct mt7615_sta *sta,
374                           struct ieee80211_tx_rate *probe_rate,
375                           struct ieee80211_tx_rate *rates);
376 int mt7615_mcu_del_wtbl_all(struct mt7615_dev *dev);
377 int mt7615_mcu_set_chan_info(struct mt7615_phy *phy, int cmd);
378 int mt7615_mcu_set_wmm(struct mt7615_dev *dev, u8 queue,
379                        const struct ieee80211_tx_queue_params *params);
380 void mt7615_mcu_rx_event(struct mt7615_dev *dev, struct sk_buff *skb);
381 int mt7615_mcu_rdd_cmd(struct mt7615_dev *dev,
382                        enum mt7615_rdd_cmd cmd, u8 index,
383                        u8 rx_sel, u8 val);
384 int mt7615_mcu_rdd_send_pattern(struct mt7615_dev *dev);
385 int mt7615_mcu_fw_log_2_host(struct mt7615_dev *dev, u8 ctrl);
386
387 static inline bool is_mt7622(struct mt76_dev *dev)
388 {
389         if (!IS_ENABLED(CONFIG_MT7622_WMAC))
390                 return false;
391
392         return mt76_chip(dev) == 0x7622;
393 }
394
395 static inline bool is_mt7615(struct mt76_dev *dev)
396 {
397         return mt76_chip(dev) == 0x7615;
398 }
399
400 static inline bool is_mt7663(struct mt76_dev *dev)
401 {
402         return mt76_chip(dev) == 0x7663;
403 }
404
405 static inline void mt7615_irq_enable(struct mt7615_dev *dev, u32 mask)
406 {
407         mt76_set_irq_mask(&dev->mt76, MT_INT_MASK_CSR, 0, mask);
408 }
409
410 static inline void mt7615_irq_disable(struct mt7615_dev *dev, u32 mask)
411 {
412         mt76_set_irq_mask(&dev->mt76, MT_INT_MASK_CSR, mask, 0);
413 }
414
415 static inline bool mt7615_firmware_offload(struct mt7615_dev *dev)
416 {
417         return dev->fw_ver > MT7615_FIRMWARE_V2;
418 }
419
420 void mt7615_scan_work(struct work_struct *work);
421 void mt7615_update_channel(struct mt76_dev *mdev);
422 bool mt7615_mac_wtbl_update(struct mt7615_dev *dev, int idx, u32 mask);
423 void mt7615_mac_reset_counters(struct mt7615_dev *dev);
424 void mt7615_mac_cca_stats_reset(struct mt7615_phy *phy);
425 void mt7615_mac_set_scs(struct mt7615_phy *phy, bool enable);
426 void mt7615_mac_enable_nf(struct mt7615_dev *dev, bool ext_phy);
427 void mt7615_mac_sta_poll(struct mt7615_dev *dev);
428 int mt7615_mac_write_txwi(struct mt7615_dev *dev, __le32 *txwi,
429                           struct sk_buff *skb, struct mt76_wcid *wcid,
430                           struct ieee80211_sta *sta, int pid,
431                           struct ieee80211_key_conf *key, bool beacon);
432 void mt7615_mac_set_timing(struct mt7615_phy *phy);
433 int mt7615_mac_fill_rx(struct mt7615_dev *dev, struct sk_buff *skb);
434 void mt7615_mac_add_txs(struct mt7615_dev *dev, void *data);
435 void mt7615_mac_tx_free(struct mt7615_dev *dev, struct sk_buff *skb);
436 int mt7615_mac_wtbl_set_key(struct mt7615_dev *dev, struct mt76_wcid *wcid,
437                             struct ieee80211_key_conf *key,
438                             enum set_key_cmd cmd);
439 int mt7615_mac_wtbl_update_pk(struct mt7615_dev *dev,
440                               struct mt76_wcid *wcid,
441                               enum mt7615_cipher_type cipher,
442                               int keyidx, enum set_key_cmd cmd);
443 void mt7615_mac_wtbl_update_cipher(struct mt7615_dev *dev,
444                                    struct mt76_wcid *wcid,
445                                    enum mt7615_cipher_type cipher,
446                                    enum set_key_cmd cmd);
447 int mt7615_mac_wtbl_update_key(struct mt7615_dev *dev,
448                                struct mt76_wcid *wcid,
449                                u8 *key, u8 keylen,
450                                enum mt7615_cipher_type cipher,
451                                enum set_key_cmd cmd);
452 void mt7615_mac_reset_work(struct work_struct *work);
453
454 int mt7615_mcu_wait_response(struct mt7615_dev *dev, int cmd, int seq);
455 int mt7615_mcu_set_dbdc(struct mt7615_dev *dev);
456 int mt7615_mcu_set_eeprom(struct mt7615_dev *dev);
457 int mt7615_mcu_set_mac_enable(struct mt7615_dev *dev, int band, bool enable);
458 int mt7615_mcu_set_rts_thresh(struct mt7615_phy *phy, u32 val);
459 int mt7615_mcu_get_temperature(struct mt7615_dev *dev, int index);
460 void mt7615_mcu_exit(struct mt7615_dev *dev);
461 void mt7615_mcu_fill_msg(struct mt7615_dev *dev, struct sk_buff *skb,
462                          int cmd, int *wait_seq);
463 int mt7615_mcu_set_channel_domain(struct mt7615_phy *phy);
464 int mt7615_mcu_hw_scan(struct mt7615_phy *phy, struct ieee80211_vif *vif,
465                        struct ieee80211_scan_request *scan_req);
466 int mt7615_mcu_cancel_hw_scan(struct mt7615_phy *phy,
467                               struct ieee80211_vif *vif);
468 int mt7615_mcu_sched_scan_req(struct mt7615_phy *phy,
469                               struct ieee80211_vif *vif,
470                               struct cfg80211_sched_scan_request *sreq);
471 int mt7615_mcu_sched_scan_enable(struct mt7615_phy *phy,
472                                  struct ieee80211_vif *vif,
473                                  bool enable);
474
475 int mt7615_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
476                           enum mt76_txq_id qid, struct mt76_wcid *wcid,
477                           struct ieee80211_sta *sta,
478                           struct mt76_tx_info *tx_info);
479
480 void mt7615_tx_complete_skb(struct mt76_dev *mdev, enum mt76_txq_id qid,
481                             struct mt76_queue_entry *e);
482
483 void mt7615_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q,
484                          struct sk_buff *skb);
485 void mt7615_sta_ps(struct mt76_dev *mdev, struct ieee80211_sta *sta, bool ps);
486 int mt7615_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
487                        struct ieee80211_sta *sta);
488 void mt7615_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif,
489                            struct ieee80211_sta *sta);
490 void mt7615_mac_work(struct work_struct *work);
491 void mt7615_txp_skb_unmap(struct mt76_dev *dev,
492                           struct mt76_txwi_cache *txwi);
493 int mt7615_mcu_set_fcc5_lpn(struct mt7615_dev *dev, int val);
494 int mt7615_mcu_set_pulse_th(struct mt7615_dev *dev,
495                             const struct mt7615_dfs_pulse *pulse);
496 int mt7615_mcu_set_radar_th(struct mt7615_dev *dev, int index,
497                             const struct mt7615_dfs_pattern *pattern);
498 int mt7615_mcu_set_sku_en(struct mt7615_phy *phy, bool enable);
499 int mt7615_mcu_apply_rx_dcoc(struct mt7615_phy *phy);
500 int mt7615_mcu_apply_tx_dpd(struct mt7615_phy *phy);
501 int mt7615_dfs_init_radar_detector(struct mt7615_phy *phy);
502
503 int mt7615_init_debugfs(struct mt7615_dev *dev);
504 int __mt7663_load_firmware(struct mt7615_dev *dev);
505
506 #endif