xref: /linux/drivers/net/wireless/ralink/rt2x00/rt2800lib.h (revision ebf68996de0ab250c5d520eb2291ab65643e9a1e)
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 
21 /* RT2800 driver data structure */
22 struct rt2800_drv_data {
23 	u8 calibration_bw20;
24 	u8 calibration_bw40;
25 	char rx_calibration_bw20;
26 	char rx_calibration_bw40;
27 	char tx_calibration_bw20;
28 	char tx_calibration_bw40;
29 	u8 bbp25;
30 	u8 bbp26;
31 	u8 txmixer_gain_24g;
32 	u8 txmixer_gain_5g;
33 	u8 max_psdu;
34 	unsigned int tbtt_tick;
35 	unsigned int ampdu_factor_cnt[4];
36 	DECLARE_BITMAP(sta_ids, STA_IDS_SIZE);
37 	struct ieee80211_sta *wcid_to_sta[STA_IDS_SIZE];
38 };
39 
40 struct rt2800_ops {
41 	u32 (*register_read)(struct rt2x00_dev *rt2x00dev,
42 			      const unsigned int offset);
43 	u32 (*register_read_lock)(struct rt2x00_dev *rt2x00dev,
44 				   const unsigned int offset);
45 	void (*register_write)(struct rt2x00_dev *rt2x00dev,
46 			       const unsigned int offset, u32 value);
47 	void (*register_write_lock)(struct rt2x00_dev *rt2x00dev,
48 				    const unsigned int offset, u32 value);
49 
50 	void (*register_multiread)(struct rt2x00_dev *rt2x00dev,
51 				   const unsigned int offset,
52 				   void *value, const u32 length);
53 	void (*register_multiwrite)(struct rt2x00_dev *rt2x00dev,
54 				    const unsigned int offset,
55 				    const void *value, const u32 length);
56 
57 	int (*regbusy_read)(struct rt2x00_dev *rt2x00dev,
58 			    const unsigned int offset,
59 			    const struct rt2x00_field32 field, u32 *reg);
60 
61 	int (*read_eeprom)(struct rt2x00_dev *rt2x00dev);
62 	bool (*hwcrypt_disabled)(struct rt2x00_dev *rt2x00dev);
63 
64 	int (*drv_write_firmware)(struct rt2x00_dev *rt2x00dev,
65 				  const u8 *data, const size_t len);
66 	int (*drv_init_registers)(struct rt2x00_dev *rt2x00dev);
67 	__le32 *(*drv_get_txwi)(struct queue_entry *entry);
68 };
69 
70 static inline u32 rt2800_register_read(struct rt2x00_dev *rt2x00dev,
71 				       const unsigned int offset)
72 {
73 	const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
74 
75 	return rt2800ops->register_read(rt2x00dev, offset);
76 }
77 
78 static inline u32 rt2800_register_read_lock(struct rt2x00_dev *rt2x00dev,
79 					    const unsigned int offset)
80 {
81 	const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
82 
83 	return rt2800ops->register_read_lock(rt2x00dev, offset);
84 }
85 
86 static inline void rt2800_register_write(struct rt2x00_dev *rt2x00dev,
87 					 const unsigned int offset,
88 					 u32 value)
89 {
90 	const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
91 
92 	rt2800ops->register_write(rt2x00dev, offset, value);
93 }
94 
95 static inline void rt2800_register_write_lock(struct rt2x00_dev *rt2x00dev,
96 					      const unsigned int offset,
97 					      u32 value)
98 {
99 	const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
100 
101 	rt2800ops->register_write_lock(rt2x00dev, offset, value);
102 }
103 
104 static inline void rt2800_register_multiread(struct rt2x00_dev *rt2x00dev,
105 					     const unsigned int offset,
106 					     void *value, const u32 length)
107 {
108 	const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
109 
110 	rt2800ops->register_multiread(rt2x00dev, offset, value, length);
111 }
112 
113 static inline void rt2800_register_multiwrite(struct rt2x00_dev *rt2x00dev,
114 					      const unsigned int offset,
115 					      const void *value,
116 					      const u32 length)
117 {
118 	const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
119 
120 	rt2800ops->register_multiwrite(rt2x00dev, offset, value, length);
121 }
122 
123 static inline int rt2800_regbusy_read(struct rt2x00_dev *rt2x00dev,
124 				      const unsigned int offset,
125 				      const struct rt2x00_field32 field,
126 				      u32 *reg)
127 {
128 	const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
129 
130 	return rt2800ops->regbusy_read(rt2x00dev, offset, field, reg);
131 }
132 
133 static inline int rt2800_read_eeprom(struct rt2x00_dev *rt2x00dev)
134 {
135 	const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
136 
137 	return rt2800ops->read_eeprom(rt2x00dev);
138 }
139 
140 static inline bool rt2800_hwcrypt_disabled(struct rt2x00_dev *rt2x00dev)
141 {
142 	const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
143 
144 	return rt2800ops->hwcrypt_disabled(rt2x00dev);
145 }
146 
147 static inline int rt2800_drv_write_firmware(struct rt2x00_dev *rt2x00dev,
148 					    const u8 *data, const size_t len)
149 {
150 	const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
151 
152 	return rt2800ops->drv_write_firmware(rt2x00dev, data, len);
153 }
154 
155 static inline int rt2800_drv_init_registers(struct rt2x00_dev *rt2x00dev)
156 {
157 	const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
158 
159 	return rt2800ops->drv_init_registers(rt2x00dev);
160 }
161 
162 static inline __le32 *rt2800_drv_get_txwi(struct queue_entry *entry)
163 {
164 	const struct rt2800_ops *rt2800ops = entry->queue->rt2x00dev->ops->drv;
165 
166 	return rt2800ops->drv_get_txwi(entry);
167 }
168 
169 void rt2800_mcu_request(struct rt2x00_dev *rt2x00dev,
170 			const u8 command, const u8 token,
171 			const u8 arg0, const u8 arg1);
172 
173 int rt2800_wait_csr_ready(struct rt2x00_dev *rt2x00dev);
174 int rt2800_wait_wpdma_ready(struct rt2x00_dev *rt2x00dev);
175 
176 int rt2800_check_firmware(struct rt2x00_dev *rt2x00dev,
177 			  const u8 *data, const size_t len);
178 int rt2800_load_firmware(struct rt2x00_dev *rt2x00dev,
179 			 const u8 *data, const size_t len);
180 
181 void rt2800_write_tx_data(struct queue_entry *entry,
182 			  struct txentry_desc *txdesc);
183 void rt2800_process_rxwi(struct queue_entry *entry, struct rxdone_entry_desc *txdesc);
184 
185 void rt2800_txdone_entry(struct queue_entry *entry, u32 status, __le32 *txwi,
186 			 bool match);
187 void rt2800_txdone(struct rt2x00_dev *rt2x00dev, unsigned int quota);
188 void rt2800_txdone_nostatus(struct rt2x00_dev *rt2x00dev);
189 bool rt2800_txstatus_timeout(struct rt2x00_dev *rt2x00dev);
190 bool rt2800_txstatus_pending(struct rt2x00_dev *rt2x00dev);
191 
192 void rt2800_write_beacon(struct queue_entry *entry, struct txentry_desc *txdesc);
193 void rt2800_clear_beacon(struct queue_entry *entry);
194 
195 extern const struct rt2x00debug rt2800_rt2x00debug;
196 
197 int rt2800_rfkill_poll(struct rt2x00_dev *rt2x00dev);
198 int rt2800_config_shared_key(struct rt2x00_dev *rt2x00dev,
199 			     struct rt2x00lib_crypto *crypto,
200 			     struct ieee80211_key_conf *key);
201 int rt2800_config_pairwise_key(struct rt2x00_dev *rt2x00dev,
202 			       struct rt2x00lib_crypto *crypto,
203 			       struct ieee80211_key_conf *key);
204 int rt2800_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
205 		   struct ieee80211_sta *sta);
206 int rt2800_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
207 		      struct ieee80211_sta *sta);
208 void rt2800_config_filter(struct rt2x00_dev *rt2x00dev,
209 			  const unsigned int filter_flags);
210 void rt2800_config_intf(struct rt2x00_dev *rt2x00dev, struct rt2x00_intf *intf,
211 			struct rt2x00intf_conf *conf, const unsigned int flags);
212 void rt2800_config_erp(struct rt2x00_dev *rt2x00dev, struct rt2x00lib_erp *erp,
213 		       u32 changed);
214 void rt2800_config_ant(struct rt2x00_dev *rt2x00dev, struct antenna_setup *ant);
215 void rt2800_config(struct rt2x00_dev *rt2x00dev,
216 		   struct rt2x00lib_conf *libconf,
217 		   const unsigned int flags);
218 void rt2800_link_stats(struct rt2x00_dev *rt2x00dev, struct link_qual *qual);
219 void rt2800_reset_tuner(struct rt2x00_dev *rt2x00dev, struct link_qual *qual);
220 void rt2800_link_tuner(struct rt2x00_dev *rt2x00dev, struct link_qual *qual,
221 		       const u32 count);
222 void rt2800_gain_calibration(struct rt2x00_dev *rt2x00dev);
223 void rt2800_vco_calibration(struct rt2x00_dev *rt2x00dev);
224 
225 int rt2800_enable_radio(struct rt2x00_dev *rt2x00dev);
226 void rt2800_disable_radio(struct rt2x00_dev *rt2x00dev);
227 
228 int rt2800_efuse_detect(struct rt2x00_dev *rt2x00dev);
229 int rt2800_read_eeprom_efuse(struct rt2x00_dev *rt2x00dev);
230 
231 int rt2800_probe_hw(struct rt2x00_dev *rt2x00dev);
232 
233 void rt2800_get_key_seq(struct ieee80211_hw *hw,
234 			struct ieee80211_key_conf *key,
235 			struct ieee80211_key_seq *seq);
236 int rt2800_set_rts_threshold(struct ieee80211_hw *hw, u32 value);
237 int rt2800_conf_tx(struct ieee80211_hw *hw,
238 		   struct ieee80211_vif *vif, u16 queue_idx,
239 		   const struct ieee80211_tx_queue_params *params);
240 u64 rt2800_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif);
241 int rt2800_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
242 			struct ieee80211_ampdu_params *params);
243 int rt2800_get_survey(struct ieee80211_hw *hw, int idx,
244 		      struct survey_info *survey);
245 void rt2800_disable_wpdma(struct rt2x00_dev *rt2x00dev);
246 
247 void rt2800_get_txwi_rxwi_size(struct rt2x00_dev *rt2x00dev,
248 			       unsigned short *txwi_size,
249 			       unsigned short *rxwi_size);
250 
251 #endif /* RT2800LIB_H */
252