1 /* SPDX-License-Identifier: ISC */
2 /* Copyright (C) 2019 MediaTek Inc. */
7 #include <linux/interrupt.h>
8 #include <linux/ktime.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))
42 enum mt7615_hw_txq_id
{
49 struct mt7615_rate_set
{
50 struct ieee80211_tx_rate probe_rate
;
51 struct ieee80211_tx_rate rates
[4];
55 struct mt76_wcid wcid
; /* must be first */
57 struct mt7615_vif
*vif
;
59 struct list_head poll_list
;
62 struct ieee80211_tx_rate rates
[4];
64 struct mt7615_rate_set rateset
[2];
79 struct mt7615_sta sta
;
83 struct mt76_dev mt76
; /* must be first */
89 struct list_head sta_poll_list
;
90 spinlock_t sta_poll_lock
;
101 int false_cca_ofdm
, false_cca_cck
;
102 unsigned long last_cca_adj
;
108 spinlock_t token_lock
;
118 EXT_BSSID_START
= 0x10,
147 enum mt7615_rdd_cmd
{
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
,
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
,
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
,
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
,
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
,
200 int mt7615_mcu_set_rx_ba(struct mt7615_dev
*dev
,
201 struct ieee80211_ampdu_params
*params
,
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
,
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
)
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
);