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 	u32 (*register_read)(struct rt2x00_dev *rt2x00dev,
53 			      const unsigned int offset);
54 	u32 (*register_read_lock)(struct rt2x00_dev *rt2x00dev,
55 				   const unsigned int offset);
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 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 void rt2800_mcu_request(struct rt2x00_dev *rt2x00dev,
181 			const u8 command, const u8 token,
182 			const u8 arg0, const u8 arg1);
183 
184 int rt2800_wait_csr_ready(struct rt2x00_dev *rt2x00dev);
185 int rt2800_wait_wpdma_ready(struct rt2x00_dev *rt2x00dev);
186 
187 int rt2800_check_firmware(struct rt2x00_dev *rt2x00dev,
188 			  const u8 *data, const size_t len);
189 int rt2800_load_firmware(struct rt2x00_dev *rt2x00dev,
190 			 const u8 *data, const size_t len);
191 
192 void rt2800_write_tx_data(struct queue_entry *entry,
193 			  struct txentry_desc *txdesc);
194 void rt2800_process_rxwi(struct queue_entry *entry, struct rxdone_entry_desc *txdesc);
195 
196 void rt2800_txdone_entry(struct queue_entry *entry, u32 status, __le32 *txwi,
197 			 bool match);
198 
199 void rt2800_write_beacon(struct queue_entry *entry, struct txentry_desc *txdesc);
200 void rt2800_clear_beacon(struct queue_entry *entry);
201 
202 extern const struct rt2x00debug rt2800_rt2x00debug;
203 
204 int rt2800_rfkill_poll(struct rt2x00_dev *rt2x00dev);
205 int rt2800_config_shared_key(struct rt2x00_dev *rt2x00dev,
206 			     struct rt2x00lib_crypto *crypto,
207 			     struct ieee80211_key_conf *key);
208 int rt2800_config_pairwise_key(struct rt2x00_dev *rt2x00dev,
209 			       struct rt2x00lib_crypto *crypto,
210 			       struct ieee80211_key_conf *key);
211 int rt2800_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
212 		   struct ieee80211_sta *sta);
213 int rt2800_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
214 		      struct ieee80211_sta *sta);
215 void rt2800_config_filter(struct rt2x00_dev *rt2x00dev,
216 			  const unsigned int filter_flags);
217 void rt2800_config_intf(struct rt2x00_dev *rt2x00dev, struct rt2x00_intf *intf,
218 			struct rt2x00intf_conf *conf, const unsigned int flags);
219 void rt2800_config_erp(struct rt2x00_dev *rt2x00dev, struct rt2x00lib_erp *erp,
220 		       u32 changed);
221 void rt2800_config_ant(struct rt2x00_dev *rt2x00dev, struct antenna_setup *ant);
222 void rt2800_config(struct rt2x00_dev *rt2x00dev,
223 		   struct rt2x00lib_conf *libconf,
224 		   const unsigned int flags);
225 void rt2800_link_stats(struct rt2x00_dev *rt2x00dev, struct link_qual *qual);
226 void rt2800_reset_tuner(struct rt2x00_dev *rt2x00dev, struct link_qual *qual);
227 void rt2800_link_tuner(struct rt2x00_dev *rt2x00dev, struct link_qual *qual,
228 		       const u32 count);
229 void rt2800_gain_calibration(struct rt2x00_dev *rt2x00dev);
230 void rt2800_vco_calibration(struct rt2x00_dev *rt2x00dev);
231 
232 int rt2800_enable_radio(struct rt2x00_dev *rt2x00dev);
233 void rt2800_disable_radio(struct rt2x00_dev *rt2x00dev);
234 
235 int rt2800_efuse_detect(struct rt2x00_dev *rt2x00dev);
236 int rt2800_read_eeprom_efuse(struct rt2x00_dev *rt2x00dev);
237 
238 int rt2800_probe_hw(struct rt2x00_dev *rt2x00dev);
239 
240 void rt2800_get_key_seq(struct ieee80211_hw *hw,
241 			struct ieee80211_key_conf *key,
242 			struct ieee80211_key_seq *seq);
243 int rt2800_set_rts_threshold(struct ieee80211_hw *hw, u32 value);
244 int rt2800_conf_tx(struct ieee80211_hw *hw,
245 		   struct ieee80211_vif *vif, u16 queue_idx,
246 		   const struct ieee80211_tx_queue_params *params);
247 u64 rt2800_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif);
248 int rt2800_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
249 			struct ieee80211_ampdu_params *params);
250 int rt2800_get_survey(struct ieee80211_hw *hw, int idx,
251 		      struct survey_info *survey);
252 void rt2800_disable_wpdma(struct rt2x00_dev *rt2x00dev);
253 
254 void rt2800_get_txwi_rxwi_size(struct rt2x00_dev *rt2x00dev,
255 			       unsigned short *txwi_size,
256 			       unsigned short *rxwi_size);
257 
258 #endif /* RT2800LIB_H */
259