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