mt76: mt7615: add dual-phy support for mac80211 ops
[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 "../mt76.h"
10 #include "regs.h"
11
12 #define MT7615_MAX_INTERFACES           4
13 #define MT7615_MAX_WMM_SETS             4
14 #define MT7615_WTBL_SIZE                128
15 #define MT7615_WTBL_RESERVED            (MT7615_WTBL_SIZE - 1)
16 #define MT7615_WTBL_STA                 (MT7615_WTBL_RESERVED - \
17                                          MT7615_MAX_INTERFACES)
18
19 #define MT7615_WATCHDOG_TIME            (HZ / 10)
20 #define MT7615_RATE_RETRY               2
21
22 #define MT7615_TX_RING_SIZE             1024
23 #define MT7615_TX_MCU_RING_SIZE         128
24 #define MT7615_TX_FWDL_RING_SIZE        128
25
26 #define MT7615_RX_RING_SIZE             1024
27 #define MT7615_RX_MCU_RING_SIZE         512
28
29 #define MT7615_FIRMWARE_CR4             "mediatek/mt7615_cr4.bin"
30 #define MT7615_FIRMWARE_N9              "mediatek/mt7615_n9.bin"
31 #define MT7615_ROM_PATCH                "mediatek/mt7615_rom_patch.bin"
32
33 #define MT7615_EEPROM_SIZE              1024
34 #define MT7615_TOKEN_SIZE               4096
35
36 #define MT_FRAC_SCALE           12
37 #define MT_FRAC(val, div)       (((val) << MT_FRAC_SCALE) / (div))
38
39 struct mt7615_vif;
40 struct mt7615_sta;
41
42 enum mt7615_hw_txq_id {
43         MT7615_TXQ_MAIN,
44         MT7615_TXQ_EXT,
45         MT7615_TXQ_MCU,
46         MT7615_TXQ_FWDL,
47 };
48
49 struct mt7615_rate_set {
50         struct ieee80211_tx_rate probe_rate;
51         struct ieee80211_tx_rate rates[4];
52 };
53
54 struct mt7615_sta {
55         struct mt76_wcid wcid; /* must be first */
56
57         struct mt7615_vif *vif;
58
59         struct list_head poll_list;
60         u32 airtime_ac[8];
61
62         struct ieee80211_tx_rate rates[4];
63
64         struct mt7615_rate_set rateset[2];
65         u32 rate_set_tsf;
66
67         u8 rate_count;
68         u8 n_rates;
69
70         u8 rate_probe;
71 };
72
73 struct mt7615_vif {
74         u8 idx;
75         u8 omac_idx;
76         u8 band_idx;
77         u8 wmm_idx;
78
79         struct mt7615_sta sta;
80 };
81
82 struct mt7615_phy {
83         struct mt76_phy *mt76;
84         struct mt7615_dev *dev;
85
86         u32 rxfilter;
87 };
88
89 struct mt7615_dev {
90         union { /* must be first */
91                 struct mt76_dev mt76;
92                 struct mt76_phy mphy;
93         };
94
95         struct mt7615_phy phy;
96         u16 chainmask;
97         u32 vif_mask;
98         u32 omac_mask;
99
100         __le32 rx_ampdu_ts;
101         u32 ampdu_ref;
102
103         struct list_head sta_poll_list;
104         spinlock_t sta_poll_lock;
105
106         struct {
107                 u8 n_pulses;
108                 u32 period;
109                 u16 width;
110                 s16 power;
111         } radar_pattern;
112         u32 hw_pattern;
113         int dfs_state;
114
115         int false_cca_ofdm, false_cca_cck;
116         unsigned long last_cca_adj;
117         u8 mac_work_count;
118         s8 ofdm_sensitivity;
119         s8 cck_sensitivity;
120         bool scs_en;
121
122         spinlock_t token_lock;
123         struct idr token;
124 };
125
126 enum {
127         HW_BSSID_0 = 0x0,
128         HW_BSSID_1,
129         HW_BSSID_2,
130         HW_BSSID_3,
131         HW_BSSID_MAX,
132         EXT_BSSID_START = 0x10,
133         EXT_BSSID_1,
134         EXT_BSSID_2,
135         EXT_BSSID_3,
136         EXT_BSSID_4,
137         EXT_BSSID_5,
138         EXT_BSSID_6,
139         EXT_BSSID_7,
140         EXT_BSSID_8,
141         EXT_BSSID_9,
142         EXT_BSSID_10,
143         EXT_BSSID_11,
144         EXT_BSSID_12,
145         EXT_BSSID_13,
146         EXT_BSSID_14,
147         EXT_BSSID_15,
148         EXT_BSSID_END
149 };
150
151 enum {
152         MT_HW_RDD0,
153         MT_HW_RDD1,
154 };
155
156 enum {
157         MT_RX_SEL0,
158         MT_RX_SEL1,
159 };
160
161 enum mt7615_rdd_cmd {
162         RDD_STOP,
163         RDD_START,
164         RDD_DET_MODE,
165         RDD_DET_STOP,
166         RDD_CAC_START,
167         RDD_CAC_END,
168         RDD_NORMAL_START,
169         RDD_DISABLE_DFS_CAL,
170         RDD_PULSE_DBG,
171         RDD_READ_PULSE,
172         RDD_RESUME_BF,
173 };
174
175 static inline struct mt7615_phy *
176 mt7615_hw_phy(struct ieee80211_hw *hw)
177 {
178         struct mt76_phy *phy = hw->priv;
179
180         return phy->priv;
181 }
182
183 static inline struct mt7615_dev *
184 mt7615_hw_dev(struct ieee80211_hw *hw)
185 {
186         struct mt76_phy *phy = hw->priv;
187
188         return container_of(phy->dev, struct mt7615_dev, mt76);
189 }
190
191 static inline struct mt7615_phy *
192 mt7615_ext_phy(struct mt7615_dev *dev)
193 {
194         struct mt76_phy *phy = dev->mt76.phy2;
195
196         if (!phy)
197                 return NULL;
198
199         return phy->priv;
200 }
201
202 extern const struct ieee80211_ops mt7615_ops;
203 extern struct pci_driver mt7615_pci_driver;
204
205 u32 mt7615_reg_map(struct mt7615_dev *dev, u32 addr);
206
207 int mt7615_register_device(struct mt7615_dev *dev);
208 void mt7615_unregister_device(struct mt7615_dev *dev);
209 int mt7615_eeprom_init(struct mt7615_dev *dev);
210 int mt7615_eeprom_get_power_index(struct mt7615_dev *dev,
211                                   struct ieee80211_channel *chan,
212                                   u8 chain_idx);
213 int mt7615_dma_init(struct mt7615_dev *dev);
214 void mt7615_dma_cleanup(struct mt7615_dev *dev);
215 int mt7615_mcu_init(struct mt7615_dev *dev);
216 int mt7615_mcu_set_dev_info(struct mt7615_dev *dev,
217                             struct ieee80211_vif *vif, bool enable);
218 int mt7615_mcu_set_bss_info(struct mt7615_dev *dev, struct ieee80211_vif *vif,
219                             int en);
220 void mt7615_mac_set_rates(struct mt7615_phy *phy, struct mt7615_sta *sta,
221                           struct ieee80211_tx_rate *probe_rate,
222                           struct ieee80211_tx_rate *rates);
223 int mt7615_mcu_wtbl_bmc(struct mt7615_dev *dev, struct ieee80211_vif *vif,
224                         bool enable);
225 int mt7615_mcu_add_wtbl(struct mt7615_dev *dev, struct ieee80211_vif *vif,
226                         struct ieee80211_sta *sta);
227 int mt7615_mcu_del_wtbl(struct mt7615_dev *dev, struct ieee80211_sta *sta);
228 int mt7615_mcu_del_wtbl_all(struct mt7615_dev *dev);
229 int mt7615_mcu_set_sta_rec_bmc(struct mt7615_dev *dev,
230                                struct ieee80211_vif *vif, bool en);
231 int mt7615_mcu_set_sta_rec(struct mt7615_dev *dev, struct ieee80211_vif *vif,
232                            struct ieee80211_sta *sta, bool en);
233 int mt7615_mcu_set_bcn(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
234                        int en);
235 int mt7615_mcu_set_channel(struct mt7615_phy *phy);
236 int mt7615_mcu_set_wmm(struct mt7615_dev *dev, u8 queue,
237                        const struct ieee80211_tx_queue_params *params);
238 int mt7615_mcu_set_tx_ba(struct mt7615_dev *dev,
239                          struct ieee80211_ampdu_params *params,
240                          bool add);
241 int mt7615_mcu_set_rx_ba(struct mt7615_dev *dev,
242                          struct ieee80211_ampdu_params *params,
243                          bool add);
244 int mt7615_mcu_set_ht_cap(struct mt7615_dev *dev, struct ieee80211_vif *vif,
245                           struct ieee80211_sta *sta);
246 void mt7615_mcu_rx_event(struct mt7615_dev *dev, struct sk_buff *skb);
247 int mt7615_mcu_rdd_cmd(struct mt7615_dev *dev,
248                        enum mt7615_rdd_cmd cmd, u8 index,
249                        u8 rx_sel, u8 val);
250 int mt7615_dfs_start_radar_detector(struct mt7615_dev *dev);
251 int mt7615_dfs_stop_radar_detector(struct mt7615_dev *dev);
252 int mt7615_mcu_rdd_send_pattern(struct mt7615_dev *dev);
253
254 static inline bool is_mt7622(struct mt76_dev *dev)
255 {
256         return mt76_chip(dev) == 0x7622;
257 }
258
259 static inline void mt7615_dfs_check_channel(struct mt7615_dev *dev)
260 {
261         enum nl80211_chan_width width = dev->mphy.chandef.width;
262         u32 freq = dev->mphy.chandef.chan->center_freq;
263         struct ieee80211_hw *hw = mt76_hw(dev);
264
265         if (hw->conf.chandef.chan->center_freq != freq ||
266             hw->conf.chandef.width != width)
267                 dev->dfs_state = -1;
268 }
269
270 static inline void mt7615_irq_enable(struct mt7615_dev *dev, u32 mask)
271 {
272         mt76_set_irq_mask(&dev->mt76, MT_INT_MASK_CSR, 0, mask);
273 }
274
275 static inline void mt7615_irq_disable(struct mt7615_dev *dev, u32 mask)
276 {
277         mt76_set_irq_mask(&dev->mt76, MT_INT_MASK_CSR, mask, 0);
278 }
279
280 void mt7615_update_channel(struct mt76_dev *mdev);
281 bool mt7615_mac_wtbl_update(struct mt7615_dev *dev, int idx, u32 mask);
282 void mt7615_mac_reset_counters(struct mt7615_dev *dev);
283 void mt7615_mac_cca_stats_reset(struct mt7615_dev *dev);
284 void mt7615_mac_set_scs(struct mt7615_dev *dev, bool enable);
285 void mt7615_mac_sta_poll(struct mt7615_dev *dev);
286 int mt7615_mac_write_txwi(struct mt7615_dev *dev, __le32 *txwi,
287                           struct sk_buff *skb, struct mt76_wcid *wcid,
288                           struct ieee80211_sta *sta, int pid,
289                           struct ieee80211_key_conf *key);
290 int mt7615_mac_fill_rx(struct mt7615_dev *dev, struct sk_buff *skb);
291 void mt7615_mac_add_txs(struct mt7615_dev *dev, void *data);
292 void mt7615_mac_tx_free(struct mt7615_dev *dev, struct sk_buff *skb);
293 int mt7615_mac_wtbl_set_key(struct mt7615_dev *dev, struct mt76_wcid *wcid,
294                             struct ieee80211_key_conf *key,
295                             enum set_key_cmd cmd);
296
297 int mt7615_mcu_set_eeprom(struct mt7615_dev *dev);
298 int mt7615_mcu_init_mac(struct mt7615_dev *dev);
299 int mt7615_mcu_set_rts_thresh(struct mt7615_phy *phy, u32 val);
300 int mt7615_mcu_ctrl_pm_state(struct mt7615_dev *dev, int band, int enter);
301 int mt7615_mcu_get_temperature(struct mt7615_dev *dev, int index);
302 int mt7615_mcu_set_tx_power(struct mt7615_phy *phy);
303 void mt7615_mcu_exit(struct mt7615_dev *dev);
304
305 int mt7615_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
306                           enum mt76_txq_id qid, struct mt76_wcid *wcid,
307                           struct ieee80211_sta *sta,
308                           struct mt76_tx_info *tx_info);
309
310 void mt7615_tx_complete_skb(struct mt76_dev *mdev, enum mt76_txq_id qid,
311                             struct mt76_queue_entry *e);
312
313 void mt7615_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q,
314                          struct sk_buff *skb);
315 void mt7615_sta_ps(struct mt76_dev *mdev, struct ieee80211_sta *sta, bool ps);
316 int mt7615_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
317                    struct ieee80211_sta *sta);
318 void mt7615_sta_assoc(struct mt76_dev *mdev, struct ieee80211_vif *vif,
319                       struct ieee80211_sta *sta);
320 void mt7615_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif,
321                        struct ieee80211_sta *sta);
322 void mt7615_mac_work(struct work_struct *work);
323 void mt7615_txp_skb_unmap(struct mt76_dev *dev,
324                           struct mt76_txwi_cache *txwi);
325 int mt76_dfs_start_rdd(struct mt7615_dev *dev, bool force);
326 int mt7615_dfs_init_radar_detector(struct mt7615_dev *dev);
327
328 int mt7615_init_debugfs(struct mt7615_dev *dev);
329
330 #endif