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_WTBL_SIZE		128
14 #define MT7615_WTBL_RESERVED		(MT7615_WTBL_SIZE - 1)
15 #define MT7615_WTBL_STA			(MT7615_WTBL_RESERVED - \
16 					 MT7615_MAX_INTERFACES)
17 
18 #define MT7615_WATCHDOG_TIME		100 /* ms */
19 #define MT7615_RATE_RETRY		2
20 
21 #define MT7615_TX_RING_SIZE		1024
22 #define MT7615_TX_MCU_RING_SIZE		128
23 #define MT7615_TX_FWDL_RING_SIZE	128
24 
25 #define MT7615_RX_RING_SIZE		1024
26 #define MT7615_RX_MCU_RING_SIZE		512
27 
28 #define MT7615_FIRMWARE_CR4		"mt7615_cr4.bin"
29 #define MT7615_FIRMWARE_N9		"mt7615_n9.bin"
30 #define MT7615_ROM_PATCH		"mt7615_rom_patch.bin"
31 
32 #define MT7615_EEPROM_SIZE		1024
33 #define MT7615_TOKEN_SIZE		4096
34 
35 struct mt7615_vif;
36 struct mt7615_sta;
37 
38 enum mt7615_hw_txq_id {
39 	MT7615_TXQ_MAIN,
40 	MT7615_TXQ_EXT,
41 	MT7615_TXQ_MCU,
42 	MT7615_TXQ_FWDL,
43 };
44 
45 struct mt7615_sta {
46 	struct mt76_wcid wcid; /* must be first */
47 
48 	struct mt7615_vif *vif;
49 
50 	struct ieee80211_tx_rate rates[8];
51 	u8 rate_count;
52 	u8 n_rates;
53 
54 	u8 rate_probe;
55 };
56 
57 struct mt7615_vif {
58 	u8 idx;
59 	u8 omac_idx;
60 	u8 band_idx;
61 	u8 wmm_idx;
62 
63 	struct mt7615_sta sta;
64 };
65 
66 struct mt7615_dev {
67 	struct mt76_dev mt76; /* must be first */
68 	u32 vif_mask;
69 	u32 omac_mask;
70 
71 	spinlock_t token_lock;
72 	struct idr token;
73 };
74 
75 enum {
76 	HW_BSSID_0 = 0x0,
77 	HW_BSSID_1,
78 	HW_BSSID_2,
79 	HW_BSSID_3,
80 	HW_BSSID_MAX,
81 	EXT_BSSID_START = 0x10,
82 	EXT_BSSID_1,
83 	EXT_BSSID_2,
84 	EXT_BSSID_3,
85 	EXT_BSSID_4,
86 	EXT_BSSID_5,
87 	EXT_BSSID_6,
88 	EXT_BSSID_7,
89 	EXT_BSSID_8,
90 	EXT_BSSID_9,
91 	EXT_BSSID_10,
92 	EXT_BSSID_11,
93 	EXT_BSSID_12,
94 	EXT_BSSID_13,
95 	EXT_BSSID_14,
96 	EXT_BSSID_15,
97 	EXT_BSSID_END
98 };
99 
100 extern const struct ieee80211_ops mt7615_ops;
101 extern struct pci_driver mt7615_pci_driver;
102 
103 u32 mt7615_reg_map(struct mt7615_dev *dev, u32 addr);
104 
105 int mt7615_register_device(struct mt7615_dev *dev);
106 void mt7615_unregister_device(struct mt7615_dev *dev);
107 int mt7615_eeprom_init(struct mt7615_dev *dev);
108 int mt7615_dma_init(struct mt7615_dev *dev);
109 void mt7615_dma_cleanup(struct mt7615_dev *dev);
110 int mt7615_mcu_init(struct mt7615_dev *dev);
111 int mt7615_mcu_set_dev_info(struct mt7615_dev *dev, struct ieee80211_vif *vif,
112 			    int en);
113 int mt7615_mcu_set_bss_info(struct mt7615_dev *dev, struct ieee80211_vif *vif,
114 			    int en);
115 int mt7615_mcu_set_wtbl_key(struct mt7615_dev *dev, int wcid,
116 			    struct ieee80211_key_conf *key,
117 			    enum set_key_cmd cmd);
118 void mt7615_mcu_set_rates(struct mt7615_dev *dev, struct mt7615_sta *sta,
119 			  struct ieee80211_tx_rate *probe_rate,
120 			  struct ieee80211_tx_rate *rates);
121 int mt7615_mcu_add_wtbl_bmc(struct mt7615_dev *dev, struct ieee80211_vif *vif);
122 int mt7615_mcu_del_wtbl_bmc(struct mt7615_dev *dev, struct ieee80211_vif *vif);
123 int mt7615_mcu_add_wtbl(struct mt7615_dev *dev, struct ieee80211_vif *vif,
124 			struct ieee80211_sta *sta);
125 int mt7615_mcu_del_wtbl(struct mt7615_dev *dev, struct ieee80211_vif *vif,
126 			struct ieee80211_sta *sta);
127 int mt7615_mcu_del_wtbl_all(struct mt7615_dev *dev);
128 int mt7615_mcu_set_sta_rec_bmc(struct mt7615_dev *dev,
129 			       struct ieee80211_vif *vif, bool en);
130 int mt7615_mcu_set_sta_rec(struct mt7615_dev *dev, struct ieee80211_vif *vif,
131 			   struct ieee80211_sta *sta, bool en);
132 int mt7615_mcu_set_bcn(struct mt7615_dev *dev, struct ieee80211_vif *vif,
133 		       int en);
134 int mt7615_mcu_set_channel(struct mt7615_dev *dev);
135 int mt7615_mcu_set_wmm(struct mt7615_dev *dev, u8 queue,
136 		       const struct ieee80211_tx_queue_params *params);
137 int mt7615_mcu_set_tx_ba(struct mt7615_dev *dev,
138 			 struct ieee80211_ampdu_params *params,
139 			 bool add);
140 int mt7615_mcu_set_rx_ba(struct mt7615_dev *dev,
141 			 struct ieee80211_ampdu_params *params,
142 			 bool add);
143 int mt7615_mcu_set_ht_cap(struct mt7615_dev *dev, struct ieee80211_vif *vif,
144 			  struct ieee80211_sta *sta);
145 
146 static inline void mt7615_irq_enable(struct mt7615_dev *dev, u32 mask)
147 {
148 	mt76_set_irq_mask(&dev->mt76, MT_INT_MASK_CSR, 0, mask);
149 }
150 
151 static inline void mt7615_irq_disable(struct mt7615_dev *dev, u32 mask)
152 {
153 	mt76_set_irq_mask(&dev->mt76, MT_INT_MASK_CSR, mask, 0);
154 }
155 
156 u16 mt7615_mac_tx_rate_val(struct mt7615_dev *dev,
157 			   const struct ieee80211_tx_rate *rate,
158 			   bool stbc, u8 *bw);
159 int mt7615_mac_write_txwi(struct mt7615_dev *dev, __le32 *txwi,
160 			  struct sk_buff *skb, struct mt76_wcid *wcid,
161 			  struct ieee80211_sta *sta, int pid,
162 			  struct ieee80211_key_conf *key);
163 int mt7615_mac_fill_rx(struct mt7615_dev *dev, struct sk_buff *skb);
164 void mt7615_mac_add_txs(struct mt7615_dev *dev, void *data);
165 void mt7615_mac_tx_free(struct mt7615_dev *dev, struct sk_buff *skb);
166 
167 int mt7615_mcu_set_eeprom(struct mt7615_dev *dev);
168 int mt7615_mcu_init_mac(struct mt7615_dev *dev);
169 int mt7615_mcu_set_rts_thresh(struct mt7615_dev *dev, u32 val);
170 int mt7615_mcu_ctrl_pm_state(struct mt7615_dev *dev, int enter);
171 void mt7615_mcu_exit(struct mt7615_dev *dev);
172 
173 int mt7615_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
174 			  enum mt76_txq_id qid, struct mt76_wcid *wcid,
175 			  struct ieee80211_sta *sta,
176 			  struct mt76_tx_info *tx_info);
177 
178 void mt7615_tx_complete_skb(struct mt76_dev *mdev, enum mt76_txq_id qid,
179 			    struct mt76_queue_entry *e);
180 
181 void mt7615_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q,
182 			 struct sk_buff *skb);
183 void mt7615_rx_poll_complete(struct mt76_dev *mdev, enum mt76_rxq_id q);
184 void mt7615_sta_ps(struct mt76_dev *mdev, struct ieee80211_sta *sta, bool ps);
185 int mt7615_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
186 		   struct ieee80211_sta *sta);
187 void mt7615_sta_assoc(struct mt76_dev *mdev, struct ieee80211_vif *vif,
188 		      struct ieee80211_sta *sta);
189 void mt7615_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif,
190 		       struct ieee80211_sta *sta);
191 void mt7615_mac_work(struct work_struct *work);
192 void mt7615_txp_skb_unmap(struct mt76_dev *dev,
193 			  struct mt76_txwi_cache *txwi);
194 
195 #endif
196