xref: /linux/drivers/net/wireless/ralink/rt2x00/rt2800lib.h (revision 67f49869106f78882a8a09b736d4884be85aba18)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3 	Copyright (C) 2010 Willow Garage <http://www.willowgarage.com>
4 	Copyright (C) 2010 Ivo van Doorn <IvDoorn@gmail.com>
5 	Copyright (C) 2009 Bartlomiej Zolnierkiewicz
6 
7  */
8 
9 #ifndef RT2800LIB_H
10 #define RT2800LIB_H
11 
12 /*
13  * Hardware has 255 WCID table entries. First 32 entries are reserved for
14  * shared keys. Since parts of the pairwise key table might be shared with
15  * the beacon frame buffers 6 & 7 we could only use the first 222 entries.
16  */
17 #define WCID_START	33
18 #define WCID_END	222
19 #define STA_IDS_SIZE	(WCID_END - WCID_START + 2)
20 #define CHAIN_0		0x0
21 #define CHAIN_1		0x1
22 #define RF_ALC_NUM	6
23 #define CHAIN_NUM	2
24 
25 struct rf_reg_pair {
26 	u8 bank;
27 	u8 reg;
28 	u8 value;
29 };
30 
31 /* RT2800 driver data structure */
32 struct rt2800_drv_data {
33 	u8 calibration_bw20;
34 	u8 calibration_bw40;
35 	s8 rx_calibration_bw20;
36 	s8 rx_calibration_bw40;
37 	s8 tx_calibration_bw20;
38 	s8 tx_calibration_bw40;
39 	u8 bbp25;
40 	u8 bbp26;
41 	u8 txmixer_gain_24g;
42 	u8 txmixer_gain_5g;
43 	u8 max_psdu;
44 	unsigned int tbtt_tick;
45 	unsigned int ampdu_factor_cnt[4];
46 	DECLARE_BITMAP(sta_ids, STA_IDS_SIZE);
47 	struct ieee80211_sta *wcid_to_sta[STA_IDS_SIZE];
48 };
49 
50 struct rt2800_ops {
51 	u32 (*register_read)(struct rt2x00_dev *rt2x00dev,
52 			      const unsigned int offset);
53 	u32 (*register_read_lock)(struct rt2x00_dev *rt2x00dev,
54 				   const unsigned int offset);
55 	void (*register_write)(struct rt2x00_dev *rt2x00dev,
56 			       const unsigned int offset, u32 value);
57 	void (*register_write_lock)(struct rt2x00_dev *rt2x00dev,
58 				    const unsigned int offset, u32 value);
59 
60 	void (*register_multiread)(struct rt2x00_dev *rt2x00dev,
61 				   const unsigned int offset,
62 				   void *value, const u32 length);
63 	void (*register_multiwrite)(struct rt2x00_dev *rt2x00dev,
64 				    const unsigned int offset,
65 				    const void *value, const u32 length);
66 
67 	int (*regbusy_read)(struct rt2x00_dev *rt2x00dev,
68 			    const unsigned int offset,
69 			    const struct rt2x00_field32 field, u32 *reg);
70 
71 	int (*read_eeprom)(struct rt2x00_dev *rt2x00dev);
72 	bool (*hwcrypt_disabled)(struct rt2x00_dev *rt2x00dev);
73 
74 	int (*drv_write_firmware)(struct rt2x00_dev *rt2x00dev,
75 				  const u8 *data, const size_t len);
76 	int (*drv_init_registers)(struct rt2x00_dev *rt2x00dev);
77 	__le32 *(*drv_get_txwi)(struct queue_entry *entry);
78 	unsigned int (*drv_get_dma_done)(struct data_queue *queue);
79 };
80 
81 static inline u32 rt2800_register_read(struct rt2x00_dev *rt2x00dev,
82 				       const unsigned int offset)
83 {
84 	const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
85 
86 	return rt2800ops->register_read(rt2x00dev, offset);
87 }
88 
89 static inline u32 rt2800_register_read_lock(struct rt2x00_dev *rt2x00dev,
90 					    const unsigned int offset)
91 {
92 	const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
93 
94 	return rt2800ops->register_read_lock(rt2x00dev, offset);
95 }
96 
97 static inline void rt2800_register_write(struct rt2x00_dev *rt2x00dev,
98 					 const unsigned int offset,
99 					 u32 value)
100 {
101 	const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
102 
103 	rt2800ops->register_write(rt2x00dev, offset, value);
104 }
105 
106 static inline void rt2800_register_write_lock(struct rt2x00_dev *rt2x00dev,
107 					      const unsigned int offset,
108 					      u32 value)
109 {
110 	const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
111 
112 	rt2800ops->register_write_lock(rt2x00dev, offset, value);
113 }
114 
115 static inline void rt2800_register_multiread(struct rt2x00_dev *rt2x00dev,
116 					     const unsigned int offset,
117 					     void *value, const u32 length)
118 {
119 	const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
120 
121 	rt2800ops->register_multiread(rt2x00dev, offset, value, length);
122 }
123 
124 static inline void rt2800_register_multiwrite(struct rt2x00_dev *rt2x00dev,
125 					      const unsigned int offset,
126 					      const void *value,
127 					      const u32 length)
128 {
129 	const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
130 
131 	rt2800ops->register_multiwrite(rt2x00dev, offset, value, length);
132 }
133 
134 static inline int rt2800_regbusy_read(struct rt2x00_dev *rt2x00dev,
135 				      const unsigned int offset,
136 				      const struct rt2x00_field32 field,
137 				      u32 *reg)
138 {
139 	const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
140 
141 	return rt2800ops->regbusy_read(rt2x00dev, offset, field, reg);
142 }
143 
144 static inline int rt2800_read_eeprom(struct rt2x00_dev *rt2x00dev)
145 {
146 	const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
147 
148 	return rt2800ops->read_eeprom(rt2x00dev);
149 }
150 
151 static inline bool rt2800_hwcrypt_disabled(struct rt2x00_dev *rt2x00dev)
152 {
153 	const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
154 
155 	return rt2800ops->hwcrypt_disabled(rt2x00dev);
156 }
157 
158 static inline int rt2800_drv_write_firmware(struct rt2x00_dev *rt2x00dev,
159 					    const u8 *data, const size_t len)
160 {
161 	const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
162 
163 	return rt2800ops->drv_write_firmware(rt2x00dev, data, len);
164 }
165 
166 static inline int rt2800_drv_init_registers(struct rt2x00_dev *rt2x00dev)
167 {
168 	const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
169 
170 	return rt2800ops->drv_init_registers(rt2x00dev);
171 }
172 
173 static inline __le32 *rt2800_drv_get_txwi(struct queue_entry *entry)
174 {
175 	const struct rt2800_ops *rt2800ops = entry->queue->rt2x00dev->ops->drv;
176 
177 	return rt2800ops->drv_get_txwi(entry);
178 }
179 
180 static inline unsigned int rt2800_drv_get_dma_done(struct data_queue *queue)
181 {
182 	const struct rt2800_ops *rt2800ops = queue->rt2x00dev->ops->drv;
183 
184 	return rt2800ops->drv_get_dma_done(queue);
185 }
186 
187 void rt2800_mcu_request(struct rt2x00_dev *rt2x00dev,
188 			const u8 command, const u8 token,
189 			const u8 arg0, const u8 arg1);
190 
191 int rt2800_wait_csr_ready(struct rt2x00_dev *rt2x00dev);
192 int rt2800_wait_wpdma_ready(struct rt2x00_dev *rt2x00dev);
193 
194 int rt2800_check_firmware(struct rt2x00_dev *rt2x00dev,
195 			  const u8 *data, const size_t len);
196 int rt2800_load_firmware(struct rt2x00_dev *rt2x00dev,
197 			 const u8 *data, const size_t len);
198 
199 void rt2800_write_tx_data(struct queue_entry *entry,
200 			  struct txentry_desc *txdesc);
201 void rt2800_process_rxwi(struct queue_entry *entry, struct rxdone_entry_desc *txdesc);
202 
203 void rt2800_txdone_entry(struct queue_entry *entry, u32 status, __le32 *txwi,
204 			 bool match);
205 void rt2800_txdone(struct rt2x00_dev *rt2x00dev, unsigned int quota);
206 void rt2800_txdone_nostatus(struct rt2x00_dev *rt2x00dev);
207 bool rt2800_txstatus_timeout(struct rt2x00_dev *rt2x00dev);
208 bool rt2800_txstatus_pending(struct rt2x00_dev *rt2x00dev);
209 
210 void rt2800_watchdog(struct rt2x00_dev *rt2x00dev);
211 
212 void rt2800_write_beacon(struct queue_entry *entry, struct txentry_desc *txdesc);
213 void rt2800_clear_beacon(struct queue_entry *entry);
214 
215 extern const struct rt2x00debug rt2800_rt2x00debug;
216 
217 int rt2800_rfkill_poll(struct rt2x00_dev *rt2x00dev);
218 int rt2800_config_shared_key(struct rt2x00_dev *rt2x00dev,
219 			     struct rt2x00lib_crypto *crypto,
220 			     struct ieee80211_key_conf *key);
221 int rt2800_config_pairwise_key(struct rt2x00_dev *rt2x00dev,
222 			       struct rt2x00lib_crypto *crypto,
223 			       struct ieee80211_key_conf *key);
224 int rt2800_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
225 		   struct ieee80211_sta *sta);
226 int rt2800_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
227 		      struct ieee80211_sta *sta);
228 void rt2800_config_filter(struct rt2x00_dev *rt2x00dev,
229 			  const unsigned int filter_flags);
230 void rt2800_config_intf(struct rt2x00_dev *rt2x00dev, struct rt2x00_intf *intf,
231 			struct rt2x00intf_conf *conf, const unsigned int flags);
232 void rt2800_config_erp(struct rt2x00_dev *rt2x00dev, struct rt2x00lib_erp *erp,
233 		       u32 changed);
234 void rt2800_config_ant(struct rt2x00_dev *rt2x00dev, struct antenna_setup *ant);
235 void rt2800_config(struct rt2x00_dev *rt2x00dev,
236 		   struct rt2x00lib_conf *libconf,
237 		   const unsigned int flags);
238 void rt2800_link_stats(struct rt2x00_dev *rt2x00dev, struct link_qual *qual);
239 void rt2800_reset_tuner(struct rt2x00_dev *rt2x00dev, struct link_qual *qual);
240 void rt2800_link_tuner(struct rt2x00_dev *rt2x00dev, struct link_qual *qual,
241 		       const u32 count);
242 void rt2800_gain_calibration(struct rt2x00_dev *rt2x00dev);
243 void rt2800_vco_calibration(struct rt2x00_dev *rt2x00dev);
244 
245 int rt2800_enable_radio(struct rt2x00_dev *rt2x00dev);
246 void rt2800_disable_radio(struct rt2x00_dev *rt2x00dev);
247 
248 int rt2800_efuse_detect(struct rt2x00_dev *rt2x00dev);
249 int rt2800_read_eeprom_efuse(struct rt2x00_dev *rt2x00dev);
250 
251 int rt2800_probe_hw(struct rt2x00_dev *rt2x00dev);
252 
253 void rt2800_get_key_seq(struct ieee80211_hw *hw,
254 			struct ieee80211_key_conf *key,
255 			struct ieee80211_key_seq *seq);
256 int rt2800_set_rts_threshold(struct ieee80211_hw *hw, u32 value);
257 int rt2800_conf_tx(struct ieee80211_hw *hw,
258 		   struct ieee80211_vif *vif,
259 		   unsigned int link_id, u16 queue_idx,
260 		   const struct ieee80211_tx_queue_params *params);
261 u64 rt2800_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif);
262 int rt2800_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
263 			struct ieee80211_ampdu_params *params);
264 int rt2800_get_survey(struct ieee80211_hw *hw, int idx,
265 		      struct survey_info *survey);
266 void rt2800_disable_wpdma(struct rt2x00_dev *rt2x00dev);
267 
268 void rt2800_get_txwi_rxwi_size(struct rt2x00_dev *rt2x00dev,
269 			       unsigned short *txwi_size,
270 			       unsigned short *rxwi_size);
271 void rt2800_pre_reset_hw(struct rt2x00_dev *rt2x00dev);
272 
273 #endif /* RT2800LIB_H */
274