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