treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / net / wireless / mediatek / mt76 / mt7615 / mt7615.h
blob21486831172c6e82cb99beb6d2a407a8b2ca7ea3
1 /* SPDX-License-Identifier: ISC */
2 /* Copyright (C) 2019 MediaTek Inc. */
4 #ifndef __MT7615_H
5 #define __MT7615_H
7 #include <linux/interrupt.h>
8 #include <linux/ktime.h>
9 #include "../mt76.h"
10 #include "regs.h"
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)
19 #define MT7615_WATCHDOG_TIME (HZ / 10)
20 #define MT7615_RATE_RETRY 2
22 #define MT7615_TX_RING_SIZE 1024
23 #define MT7615_TX_MCU_RING_SIZE 128
24 #define MT7615_TX_FWDL_RING_SIZE 128
26 #define MT7615_RX_RING_SIZE 1024
27 #define MT7615_RX_MCU_RING_SIZE 512
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"
33 #define MT7615_EEPROM_SIZE 1024
34 #define MT7615_TOKEN_SIZE 4096
36 #define MT_FRAC_SCALE 12
37 #define MT_FRAC(val, div) (((val) << MT_FRAC_SCALE) / (div))
39 struct mt7615_vif;
40 struct mt7615_sta;
42 enum mt7615_hw_txq_id {
43 MT7615_TXQ_MAIN,
44 MT7615_TXQ_EXT,
45 MT7615_TXQ_MCU,
46 MT7615_TXQ_FWDL,
49 struct mt7615_rate_set {
50 struct ieee80211_tx_rate probe_rate;
51 struct ieee80211_tx_rate rates[4];
54 struct mt7615_sta {
55 struct mt76_wcid wcid; /* must be first */
57 struct mt7615_vif *vif;
59 struct list_head poll_list;
60 u32 airtime_ac[8];
62 struct ieee80211_tx_rate rates[4];
64 struct mt7615_rate_set rateset[2];
65 u32 rate_set_tsf;
67 u8 rate_count;
68 u8 n_rates;
70 u8 rate_probe;
73 struct mt7615_vif {
74 u8 idx;
75 u8 omac_idx;
76 u8 band_idx;
77 u8 wmm_idx;
79 struct mt7615_sta sta;
82 struct mt7615_dev {
83 struct mt76_dev mt76; /* must be first */
84 u32 vif_mask;
85 u32 omac_mask;
87 __le32 rx_ampdu_ts;
89 struct list_head sta_poll_list;
90 spinlock_t sta_poll_lock;
92 struct {
93 u8 n_pulses;
94 u32 period;
95 u16 width;
96 s16 power;
97 } radar_pattern;
98 u32 hw_pattern;
99 int dfs_state;
101 int false_cca_ofdm, false_cca_cck;
102 unsigned long last_cca_adj;
103 u8 mac_work_count;
104 s8 ofdm_sensitivity;
105 s8 cck_sensitivity;
106 bool scs_en;
108 spinlock_t token_lock;
109 struct idr token;
112 enum {
113 HW_BSSID_0 = 0x0,
114 HW_BSSID_1,
115 HW_BSSID_2,
116 HW_BSSID_3,
117 HW_BSSID_MAX,
118 EXT_BSSID_START = 0x10,
119 EXT_BSSID_1,
120 EXT_BSSID_2,
121 EXT_BSSID_3,
122 EXT_BSSID_4,
123 EXT_BSSID_5,
124 EXT_BSSID_6,
125 EXT_BSSID_7,
126 EXT_BSSID_8,
127 EXT_BSSID_9,
128 EXT_BSSID_10,
129 EXT_BSSID_11,
130 EXT_BSSID_12,
131 EXT_BSSID_13,
132 EXT_BSSID_14,
133 EXT_BSSID_15,
134 EXT_BSSID_END
137 enum {
138 MT_HW_RDD0,
139 MT_HW_RDD1,
142 enum {
143 MT_RX_SEL0,
144 MT_RX_SEL1,
147 enum mt7615_rdd_cmd {
148 RDD_STOP,
149 RDD_START,
150 RDD_DET_MODE,
151 RDD_DET_STOP,
152 RDD_CAC_START,
153 RDD_CAC_END,
154 RDD_NORMAL_START,
155 RDD_DISABLE_DFS_CAL,
156 RDD_PULSE_DBG,
157 RDD_READ_PULSE,
158 RDD_RESUME_BF,
161 extern const struct ieee80211_ops mt7615_ops;
162 extern struct pci_driver mt7615_pci_driver;
164 u32 mt7615_reg_map(struct mt7615_dev *dev, u32 addr);
166 int mt7615_register_device(struct mt7615_dev *dev);
167 void mt7615_unregister_device(struct mt7615_dev *dev);
168 int mt7615_eeprom_init(struct mt7615_dev *dev);
169 int mt7615_eeprom_get_power_index(struct mt7615_dev *dev,
170 struct ieee80211_channel *chan,
171 u8 chain_idx);
172 int mt7615_dma_init(struct mt7615_dev *dev);
173 void mt7615_dma_cleanup(struct mt7615_dev *dev);
174 int mt7615_mcu_init(struct mt7615_dev *dev);
175 int mt7615_mcu_set_dev_info(struct mt7615_dev *dev,
176 struct ieee80211_vif *vif, bool enable);
177 int mt7615_mcu_set_bss_info(struct mt7615_dev *dev, struct ieee80211_vif *vif,
178 int en);
179 void mt7615_mac_set_rates(struct mt7615_dev *dev, struct mt7615_sta *sta,
180 struct ieee80211_tx_rate *probe_rate,
181 struct ieee80211_tx_rate *rates);
182 int mt7615_mcu_wtbl_bmc(struct mt7615_dev *dev, struct ieee80211_vif *vif,
183 bool enable);
184 int mt7615_mcu_add_wtbl(struct mt7615_dev *dev, struct ieee80211_vif *vif,
185 struct ieee80211_sta *sta);
186 int mt7615_mcu_del_wtbl(struct mt7615_dev *dev, struct ieee80211_sta *sta);
187 int mt7615_mcu_del_wtbl_all(struct mt7615_dev *dev);
188 int mt7615_mcu_set_sta_rec_bmc(struct mt7615_dev *dev,
189 struct ieee80211_vif *vif, bool en);
190 int mt7615_mcu_set_sta_rec(struct mt7615_dev *dev, struct ieee80211_vif *vif,
191 struct ieee80211_sta *sta, bool en);
192 int mt7615_mcu_set_bcn(struct mt7615_dev *dev, struct ieee80211_vif *vif,
193 int en);
194 int mt7615_mcu_set_channel(struct mt7615_dev *dev);
195 int mt7615_mcu_set_wmm(struct mt7615_dev *dev, u8 queue,
196 const struct ieee80211_tx_queue_params *params);
197 int mt7615_mcu_set_tx_ba(struct mt7615_dev *dev,
198 struct ieee80211_ampdu_params *params,
199 bool add);
200 int mt7615_mcu_set_rx_ba(struct mt7615_dev *dev,
201 struct ieee80211_ampdu_params *params,
202 bool add);
203 int mt7615_mcu_set_ht_cap(struct mt7615_dev *dev, struct ieee80211_vif *vif,
204 struct ieee80211_sta *sta);
205 void mt7615_mcu_rx_event(struct mt7615_dev *dev, struct sk_buff *skb);
206 int mt7615_mcu_rdd_cmd(struct mt7615_dev *dev,
207 enum mt7615_rdd_cmd cmd, u8 index,
208 u8 rx_sel, u8 val);
209 int mt7615_dfs_start_radar_detector(struct mt7615_dev *dev);
210 int mt7615_dfs_stop_radar_detector(struct mt7615_dev *dev);
211 int mt7615_mcu_rdd_send_pattern(struct mt7615_dev *dev);
213 static inline bool is_mt7622(struct mt76_dev *dev)
215 return mt76_chip(dev) == 0x7622;
218 static inline void mt7615_dfs_check_channel(struct mt7615_dev *dev)
220 enum nl80211_chan_width width = dev->mt76.chandef.width;
221 u32 freq = dev->mt76.chandef.chan->center_freq;
222 struct ieee80211_hw *hw = mt76_hw(dev);
224 if (hw->conf.chandef.chan->center_freq != freq ||
225 hw->conf.chandef.width != width)
226 dev->dfs_state = -1;
229 static inline void mt7615_irq_enable(struct mt7615_dev *dev, u32 mask)
231 mt76_set_irq_mask(&dev->mt76, MT_INT_MASK_CSR, 0, mask);
234 static inline void mt7615_irq_disable(struct mt7615_dev *dev, u32 mask)
236 mt76_set_irq_mask(&dev->mt76, MT_INT_MASK_CSR, mask, 0);
239 void mt7615_update_channel(struct mt76_dev *mdev);
240 bool mt7615_mac_wtbl_update(struct mt7615_dev *dev, int idx, u32 mask);
241 void mt7615_mac_reset_counters(struct mt7615_dev *dev);
242 void mt7615_mac_cca_stats_reset(struct mt7615_dev *dev);
243 void mt7615_mac_set_scs(struct mt7615_dev *dev, bool enable);
244 void mt7615_mac_sta_poll(struct mt7615_dev *dev);
245 int mt7615_mac_write_txwi(struct mt7615_dev *dev, __le32 *txwi,
246 struct sk_buff *skb, struct mt76_wcid *wcid,
247 struct ieee80211_sta *sta, int pid,
248 struct ieee80211_key_conf *key);
249 int mt7615_mac_fill_rx(struct mt7615_dev *dev, struct sk_buff *skb);
250 void mt7615_mac_add_txs(struct mt7615_dev *dev, void *data);
251 void mt7615_mac_tx_free(struct mt7615_dev *dev, struct sk_buff *skb);
252 int mt7615_mac_wtbl_set_key(struct mt7615_dev *dev, struct mt76_wcid *wcid,
253 struct ieee80211_key_conf *key,
254 enum set_key_cmd cmd);
256 int mt7615_mcu_set_eeprom(struct mt7615_dev *dev);
257 int mt7615_mcu_init_mac(struct mt7615_dev *dev);
258 int mt7615_mcu_set_rts_thresh(struct mt7615_dev *dev, u32 val);
259 int mt7615_mcu_ctrl_pm_state(struct mt7615_dev *dev, int enter);
260 int mt7615_mcu_get_temperature(struct mt7615_dev *dev, int index);
261 int mt7615_mcu_set_tx_power(struct mt7615_dev *dev);
262 void mt7615_mcu_exit(struct mt7615_dev *dev);
264 int mt7615_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
265 enum mt76_txq_id qid, struct mt76_wcid *wcid,
266 struct ieee80211_sta *sta,
267 struct mt76_tx_info *tx_info);
269 void mt7615_tx_complete_skb(struct mt76_dev *mdev, enum mt76_txq_id qid,
270 struct mt76_queue_entry *e);
272 void mt7615_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q,
273 struct sk_buff *skb);
274 void mt7615_sta_ps(struct mt76_dev *mdev, struct ieee80211_sta *sta, bool ps);
275 int mt7615_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
276 struct ieee80211_sta *sta);
277 void mt7615_sta_assoc(struct mt76_dev *mdev, struct ieee80211_vif *vif,
278 struct ieee80211_sta *sta);
279 void mt7615_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif,
280 struct ieee80211_sta *sta);
281 void mt7615_mac_work(struct work_struct *work);
282 void mt7615_txp_skb_unmap(struct mt76_dev *dev,
283 struct mt76_txwi_cache *txwi);
284 int mt76_dfs_start_rdd(struct mt7615_dev *dev, bool force);
285 int mt7615_dfs_init_radar_detector(struct mt7615_dev *dev);
287 int mt7615_init_debugfs(struct mt7615_dev *dev);
289 #endif