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