18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci	Copyright (C) 2010 Willow Garage <http://www.willowgarage.com>
48c2ecf20Sopenharmony_ci	Copyright (C) 2010 Ivo van Doorn <IvDoorn@gmail.com>
58c2ecf20Sopenharmony_ci	Copyright (C) 2009 Bartlomiej Zolnierkiewicz
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#ifndef RT2800LIB_H
108c2ecf20Sopenharmony_ci#define RT2800LIB_H
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci/*
138c2ecf20Sopenharmony_ci * Hardware has 255 WCID table entries. First 32 entries are reserved for
148c2ecf20Sopenharmony_ci * shared keys. Since parts of the pairwise key table might be shared with
158c2ecf20Sopenharmony_ci * the beacon frame buffers 6 & 7 we could only use the first 222 entries.
168c2ecf20Sopenharmony_ci */
178c2ecf20Sopenharmony_ci#define WCID_START	33
188c2ecf20Sopenharmony_ci#define WCID_END	222
198c2ecf20Sopenharmony_ci#define STA_IDS_SIZE	(WCID_END - WCID_START + 2)
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci/* RT2800 driver data structure */
228c2ecf20Sopenharmony_cistruct rt2800_drv_data {
238c2ecf20Sopenharmony_ci	u8 calibration_bw20;
248c2ecf20Sopenharmony_ci	u8 calibration_bw40;
258c2ecf20Sopenharmony_ci	char rx_calibration_bw20;
268c2ecf20Sopenharmony_ci	char rx_calibration_bw40;
278c2ecf20Sopenharmony_ci	char tx_calibration_bw20;
288c2ecf20Sopenharmony_ci	char tx_calibration_bw40;
298c2ecf20Sopenharmony_ci	u8 bbp25;
308c2ecf20Sopenharmony_ci	u8 bbp26;
318c2ecf20Sopenharmony_ci	u8 txmixer_gain_24g;
328c2ecf20Sopenharmony_ci	u8 txmixer_gain_5g;
338c2ecf20Sopenharmony_ci	u8 max_psdu;
348c2ecf20Sopenharmony_ci	unsigned int tbtt_tick;
358c2ecf20Sopenharmony_ci	unsigned int ampdu_factor_cnt[4];
368c2ecf20Sopenharmony_ci	DECLARE_BITMAP(sta_ids, STA_IDS_SIZE);
378c2ecf20Sopenharmony_ci	struct ieee80211_sta *wcid_to_sta[STA_IDS_SIZE];
388c2ecf20Sopenharmony_ci};
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_cistruct rt2800_ops {
418c2ecf20Sopenharmony_ci	u32 (*register_read)(struct rt2x00_dev *rt2x00dev,
428c2ecf20Sopenharmony_ci			      const unsigned int offset);
438c2ecf20Sopenharmony_ci	u32 (*register_read_lock)(struct rt2x00_dev *rt2x00dev,
448c2ecf20Sopenharmony_ci				   const unsigned int offset);
458c2ecf20Sopenharmony_ci	void (*register_write)(struct rt2x00_dev *rt2x00dev,
468c2ecf20Sopenharmony_ci			       const unsigned int offset, u32 value);
478c2ecf20Sopenharmony_ci	void (*register_write_lock)(struct rt2x00_dev *rt2x00dev,
488c2ecf20Sopenharmony_ci				    const unsigned int offset, u32 value);
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci	void (*register_multiread)(struct rt2x00_dev *rt2x00dev,
518c2ecf20Sopenharmony_ci				   const unsigned int offset,
528c2ecf20Sopenharmony_ci				   void *value, const u32 length);
538c2ecf20Sopenharmony_ci	void (*register_multiwrite)(struct rt2x00_dev *rt2x00dev,
548c2ecf20Sopenharmony_ci				    const unsigned int offset,
558c2ecf20Sopenharmony_ci				    const void *value, const u32 length);
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci	int (*regbusy_read)(struct rt2x00_dev *rt2x00dev,
588c2ecf20Sopenharmony_ci			    const unsigned int offset,
598c2ecf20Sopenharmony_ci			    const struct rt2x00_field32 field, u32 *reg);
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci	int (*read_eeprom)(struct rt2x00_dev *rt2x00dev);
628c2ecf20Sopenharmony_ci	bool (*hwcrypt_disabled)(struct rt2x00_dev *rt2x00dev);
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci	int (*drv_write_firmware)(struct rt2x00_dev *rt2x00dev,
658c2ecf20Sopenharmony_ci				  const u8 *data, const size_t len);
668c2ecf20Sopenharmony_ci	int (*drv_init_registers)(struct rt2x00_dev *rt2x00dev);
678c2ecf20Sopenharmony_ci	__le32 *(*drv_get_txwi)(struct queue_entry *entry);
688c2ecf20Sopenharmony_ci	unsigned int (*drv_get_dma_done)(struct data_queue *queue);
698c2ecf20Sopenharmony_ci};
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_cistatic inline u32 rt2800_register_read(struct rt2x00_dev *rt2x00dev,
728c2ecf20Sopenharmony_ci				       const unsigned int offset)
738c2ecf20Sopenharmony_ci{
748c2ecf20Sopenharmony_ci	const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci	return rt2800ops->register_read(rt2x00dev, offset);
778c2ecf20Sopenharmony_ci}
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_cistatic inline u32 rt2800_register_read_lock(struct rt2x00_dev *rt2x00dev,
808c2ecf20Sopenharmony_ci					    const unsigned int offset)
818c2ecf20Sopenharmony_ci{
828c2ecf20Sopenharmony_ci	const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci	return rt2800ops->register_read_lock(rt2x00dev, offset);
858c2ecf20Sopenharmony_ci}
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_cistatic inline void rt2800_register_write(struct rt2x00_dev *rt2x00dev,
888c2ecf20Sopenharmony_ci					 const unsigned int offset,
898c2ecf20Sopenharmony_ci					 u32 value)
908c2ecf20Sopenharmony_ci{
918c2ecf20Sopenharmony_ci	const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci	rt2800ops->register_write(rt2x00dev, offset, value);
948c2ecf20Sopenharmony_ci}
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_cistatic inline void rt2800_register_write_lock(struct rt2x00_dev *rt2x00dev,
978c2ecf20Sopenharmony_ci					      const unsigned int offset,
988c2ecf20Sopenharmony_ci					      u32 value)
998c2ecf20Sopenharmony_ci{
1008c2ecf20Sopenharmony_ci	const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ci	rt2800ops->register_write_lock(rt2x00dev, offset, value);
1038c2ecf20Sopenharmony_ci}
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_cistatic inline void rt2800_register_multiread(struct rt2x00_dev *rt2x00dev,
1068c2ecf20Sopenharmony_ci					     const unsigned int offset,
1078c2ecf20Sopenharmony_ci					     void *value, const u32 length)
1088c2ecf20Sopenharmony_ci{
1098c2ecf20Sopenharmony_ci	const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_ci	rt2800ops->register_multiread(rt2x00dev, offset, value, length);
1128c2ecf20Sopenharmony_ci}
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_cistatic inline void rt2800_register_multiwrite(struct rt2x00_dev *rt2x00dev,
1158c2ecf20Sopenharmony_ci					      const unsigned int offset,
1168c2ecf20Sopenharmony_ci					      const void *value,
1178c2ecf20Sopenharmony_ci					      const u32 length)
1188c2ecf20Sopenharmony_ci{
1198c2ecf20Sopenharmony_ci	const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_ci	rt2800ops->register_multiwrite(rt2x00dev, offset, value, length);
1228c2ecf20Sopenharmony_ci}
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_cistatic inline int rt2800_regbusy_read(struct rt2x00_dev *rt2x00dev,
1258c2ecf20Sopenharmony_ci				      const unsigned int offset,
1268c2ecf20Sopenharmony_ci				      const struct rt2x00_field32 field,
1278c2ecf20Sopenharmony_ci				      u32 *reg)
1288c2ecf20Sopenharmony_ci{
1298c2ecf20Sopenharmony_ci	const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci	return rt2800ops->regbusy_read(rt2x00dev, offset, field, reg);
1328c2ecf20Sopenharmony_ci}
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_cistatic inline int rt2800_read_eeprom(struct rt2x00_dev *rt2x00dev)
1358c2ecf20Sopenharmony_ci{
1368c2ecf20Sopenharmony_ci	const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci	return rt2800ops->read_eeprom(rt2x00dev);
1398c2ecf20Sopenharmony_ci}
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_cistatic inline bool rt2800_hwcrypt_disabled(struct rt2x00_dev *rt2x00dev)
1428c2ecf20Sopenharmony_ci{
1438c2ecf20Sopenharmony_ci	const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_ci	return rt2800ops->hwcrypt_disabled(rt2x00dev);
1468c2ecf20Sopenharmony_ci}
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_cistatic inline int rt2800_drv_write_firmware(struct rt2x00_dev *rt2x00dev,
1498c2ecf20Sopenharmony_ci					    const u8 *data, const size_t len)
1508c2ecf20Sopenharmony_ci{
1518c2ecf20Sopenharmony_ci	const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_ci	return rt2800ops->drv_write_firmware(rt2x00dev, data, len);
1548c2ecf20Sopenharmony_ci}
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_cistatic inline int rt2800_drv_init_registers(struct rt2x00_dev *rt2x00dev)
1578c2ecf20Sopenharmony_ci{
1588c2ecf20Sopenharmony_ci	const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci	return rt2800ops->drv_init_registers(rt2x00dev);
1618c2ecf20Sopenharmony_ci}
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_cistatic inline __le32 *rt2800_drv_get_txwi(struct queue_entry *entry)
1648c2ecf20Sopenharmony_ci{
1658c2ecf20Sopenharmony_ci	const struct rt2800_ops *rt2800ops = entry->queue->rt2x00dev->ops->drv;
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_ci	return rt2800ops->drv_get_txwi(entry);
1688c2ecf20Sopenharmony_ci}
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_cistatic inline unsigned int rt2800_drv_get_dma_done(struct data_queue *queue)
1718c2ecf20Sopenharmony_ci{
1728c2ecf20Sopenharmony_ci	const struct rt2800_ops *rt2800ops = queue->rt2x00dev->ops->drv;
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_ci	return rt2800ops->drv_get_dma_done(queue);
1758c2ecf20Sopenharmony_ci}
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_civoid rt2800_mcu_request(struct rt2x00_dev *rt2x00dev,
1788c2ecf20Sopenharmony_ci			const u8 command, const u8 token,
1798c2ecf20Sopenharmony_ci			const u8 arg0, const u8 arg1);
1808c2ecf20Sopenharmony_ci
1818c2ecf20Sopenharmony_ciint rt2800_wait_csr_ready(struct rt2x00_dev *rt2x00dev);
1828c2ecf20Sopenharmony_ciint rt2800_wait_wpdma_ready(struct rt2x00_dev *rt2x00dev);
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_ciint rt2800_check_firmware(struct rt2x00_dev *rt2x00dev,
1858c2ecf20Sopenharmony_ci			  const u8 *data, const size_t len);
1868c2ecf20Sopenharmony_ciint rt2800_load_firmware(struct rt2x00_dev *rt2x00dev,
1878c2ecf20Sopenharmony_ci			 const u8 *data, const size_t len);
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_civoid rt2800_write_tx_data(struct queue_entry *entry,
1908c2ecf20Sopenharmony_ci			  struct txentry_desc *txdesc);
1918c2ecf20Sopenharmony_civoid rt2800_process_rxwi(struct queue_entry *entry, struct rxdone_entry_desc *txdesc);
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_civoid rt2800_txdone_entry(struct queue_entry *entry, u32 status, __le32 *txwi,
1948c2ecf20Sopenharmony_ci			 bool match);
1958c2ecf20Sopenharmony_civoid rt2800_txdone(struct rt2x00_dev *rt2x00dev, unsigned int quota);
1968c2ecf20Sopenharmony_civoid rt2800_txdone_nostatus(struct rt2x00_dev *rt2x00dev);
1978c2ecf20Sopenharmony_cibool rt2800_txstatus_timeout(struct rt2x00_dev *rt2x00dev);
1988c2ecf20Sopenharmony_cibool rt2800_txstatus_pending(struct rt2x00_dev *rt2x00dev);
1998c2ecf20Sopenharmony_ci
2008c2ecf20Sopenharmony_civoid rt2800_watchdog(struct rt2x00_dev *rt2x00dev);
2018c2ecf20Sopenharmony_ci
2028c2ecf20Sopenharmony_civoid rt2800_write_beacon(struct queue_entry *entry, struct txentry_desc *txdesc);
2038c2ecf20Sopenharmony_civoid rt2800_clear_beacon(struct queue_entry *entry);
2048c2ecf20Sopenharmony_ci
2058c2ecf20Sopenharmony_ciextern const struct rt2x00debug rt2800_rt2x00debug;
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_ciint rt2800_rfkill_poll(struct rt2x00_dev *rt2x00dev);
2088c2ecf20Sopenharmony_ciint rt2800_config_shared_key(struct rt2x00_dev *rt2x00dev,
2098c2ecf20Sopenharmony_ci			     struct rt2x00lib_crypto *crypto,
2108c2ecf20Sopenharmony_ci			     struct ieee80211_key_conf *key);
2118c2ecf20Sopenharmony_ciint rt2800_config_pairwise_key(struct rt2x00_dev *rt2x00dev,
2128c2ecf20Sopenharmony_ci			       struct rt2x00lib_crypto *crypto,
2138c2ecf20Sopenharmony_ci			       struct ieee80211_key_conf *key);
2148c2ecf20Sopenharmony_ciint rt2800_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2158c2ecf20Sopenharmony_ci		   struct ieee80211_sta *sta);
2168c2ecf20Sopenharmony_ciint rt2800_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2178c2ecf20Sopenharmony_ci		      struct ieee80211_sta *sta);
2188c2ecf20Sopenharmony_civoid rt2800_config_filter(struct rt2x00_dev *rt2x00dev,
2198c2ecf20Sopenharmony_ci			  const unsigned int filter_flags);
2208c2ecf20Sopenharmony_civoid rt2800_config_intf(struct rt2x00_dev *rt2x00dev, struct rt2x00_intf *intf,
2218c2ecf20Sopenharmony_ci			struct rt2x00intf_conf *conf, const unsigned int flags);
2228c2ecf20Sopenharmony_civoid rt2800_config_erp(struct rt2x00_dev *rt2x00dev, struct rt2x00lib_erp *erp,
2238c2ecf20Sopenharmony_ci		       u32 changed);
2248c2ecf20Sopenharmony_civoid rt2800_config_ant(struct rt2x00_dev *rt2x00dev, struct antenna_setup *ant);
2258c2ecf20Sopenharmony_civoid rt2800_config(struct rt2x00_dev *rt2x00dev,
2268c2ecf20Sopenharmony_ci		   struct rt2x00lib_conf *libconf,
2278c2ecf20Sopenharmony_ci		   const unsigned int flags);
2288c2ecf20Sopenharmony_civoid rt2800_link_stats(struct rt2x00_dev *rt2x00dev, struct link_qual *qual);
2298c2ecf20Sopenharmony_civoid rt2800_reset_tuner(struct rt2x00_dev *rt2x00dev, struct link_qual *qual);
2308c2ecf20Sopenharmony_civoid rt2800_link_tuner(struct rt2x00_dev *rt2x00dev, struct link_qual *qual,
2318c2ecf20Sopenharmony_ci		       const u32 count);
2328c2ecf20Sopenharmony_civoid rt2800_gain_calibration(struct rt2x00_dev *rt2x00dev);
2338c2ecf20Sopenharmony_civoid rt2800_vco_calibration(struct rt2x00_dev *rt2x00dev);
2348c2ecf20Sopenharmony_ci
2358c2ecf20Sopenharmony_ciint rt2800_enable_radio(struct rt2x00_dev *rt2x00dev);
2368c2ecf20Sopenharmony_civoid rt2800_disable_radio(struct rt2x00_dev *rt2x00dev);
2378c2ecf20Sopenharmony_ci
2388c2ecf20Sopenharmony_ciint rt2800_efuse_detect(struct rt2x00_dev *rt2x00dev);
2398c2ecf20Sopenharmony_ciint rt2800_read_eeprom_efuse(struct rt2x00_dev *rt2x00dev);
2408c2ecf20Sopenharmony_ci
2418c2ecf20Sopenharmony_ciint rt2800_probe_hw(struct rt2x00_dev *rt2x00dev);
2428c2ecf20Sopenharmony_ci
2438c2ecf20Sopenharmony_civoid rt2800_get_key_seq(struct ieee80211_hw *hw,
2448c2ecf20Sopenharmony_ci			struct ieee80211_key_conf *key,
2458c2ecf20Sopenharmony_ci			struct ieee80211_key_seq *seq);
2468c2ecf20Sopenharmony_ciint rt2800_set_rts_threshold(struct ieee80211_hw *hw, u32 value);
2478c2ecf20Sopenharmony_ciint rt2800_conf_tx(struct ieee80211_hw *hw,
2488c2ecf20Sopenharmony_ci		   struct ieee80211_vif *vif, u16 queue_idx,
2498c2ecf20Sopenharmony_ci		   const struct ieee80211_tx_queue_params *params);
2508c2ecf20Sopenharmony_ciu64 rt2800_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif);
2518c2ecf20Sopenharmony_ciint rt2800_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2528c2ecf20Sopenharmony_ci			struct ieee80211_ampdu_params *params);
2538c2ecf20Sopenharmony_ciint rt2800_get_survey(struct ieee80211_hw *hw, int idx,
2548c2ecf20Sopenharmony_ci		      struct survey_info *survey);
2558c2ecf20Sopenharmony_civoid rt2800_disable_wpdma(struct rt2x00_dev *rt2x00dev);
2568c2ecf20Sopenharmony_ci
2578c2ecf20Sopenharmony_civoid rt2800_get_txwi_rxwi_size(struct rt2x00_dev *rt2x00dev,
2588c2ecf20Sopenharmony_ci			       unsigned short *txwi_size,
2598c2ecf20Sopenharmony_ci			       unsigned short *rxwi_size);
2608c2ecf20Sopenharmony_civoid rt2800_pre_reset_hw(struct rt2x00_dev *rt2x00dev);
2618c2ecf20Sopenharmony_ci
2628c2ecf20Sopenharmony_ci#endif /* RT2800LIB_H */
263