162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci	Copyright (C) 2010 Willow Garage <http://www.willowgarage.com>
462306a36Sopenharmony_ci	Copyright (C) 2010 Ivo van Doorn <IvDoorn@gmail.com>
562306a36Sopenharmony_ci	Copyright (C) 2009 Bartlomiej Zolnierkiewicz
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci */
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#ifndef RT2800LIB_H
1062306a36Sopenharmony_ci#define RT2800LIB_H
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci/*
1362306a36Sopenharmony_ci * Hardware has 255 WCID table entries. First 32 entries are reserved for
1462306a36Sopenharmony_ci * shared keys. Since parts of the pairwise key table might be shared with
1562306a36Sopenharmony_ci * the beacon frame buffers 6 & 7 we could only use the first 222 entries.
1662306a36Sopenharmony_ci */
1762306a36Sopenharmony_ci#define WCID_START	33
1862306a36Sopenharmony_ci#define WCID_END	222
1962306a36Sopenharmony_ci#define STA_IDS_SIZE	(WCID_END - WCID_START + 2)
2062306a36Sopenharmony_ci#define CHAIN_0		0x0
2162306a36Sopenharmony_ci#define CHAIN_1		0x1
2262306a36Sopenharmony_ci#define RF_ALC_NUM	6
2362306a36Sopenharmony_ci#define CHAIN_NUM	2
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_cistruct rf_reg_pair {
2662306a36Sopenharmony_ci	u8 bank;
2762306a36Sopenharmony_ci	u8 reg;
2862306a36Sopenharmony_ci	u8 value;
2962306a36Sopenharmony_ci};
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ci/* RT2800 driver data structure */
3262306a36Sopenharmony_cistruct rt2800_drv_data {
3362306a36Sopenharmony_ci	u8 calibration_bw20;
3462306a36Sopenharmony_ci	u8 calibration_bw40;
3562306a36Sopenharmony_ci	s8 rx_calibration_bw20;
3662306a36Sopenharmony_ci	s8 rx_calibration_bw40;
3762306a36Sopenharmony_ci	s8 tx_calibration_bw20;
3862306a36Sopenharmony_ci	s8 tx_calibration_bw40;
3962306a36Sopenharmony_ci	u8 bbp25;
4062306a36Sopenharmony_ci	u8 bbp26;
4162306a36Sopenharmony_ci	u8 txmixer_gain_24g;
4262306a36Sopenharmony_ci	u8 txmixer_gain_5g;
4362306a36Sopenharmony_ci	u8 max_psdu;
4462306a36Sopenharmony_ci	unsigned int tbtt_tick;
4562306a36Sopenharmony_ci	unsigned int ampdu_factor_cnt[4];
4662306a36Sopenharmony_ci	DECLARE_BITMAP(sta_ids, STA_IDS_SIZE);
4762306a36Sopenharmony_ci	struct ieee80211_sta *wcid_to_sta[STA_IDS_SIZE];
4862306a36Sopenharmony_ci};
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_cistruct rt2800_ops {
5162306a36Sopenharmony_ci	u32 (*register_read)(struct rt2x00_dev *rt2x00dev,
5262306a36Sopenharmony_ci			      const unsigned int offset);
5362306a36Sopenharmony_ci	u32 (*register_read_lock)(struct rt2x00_dev *rt2x00dev,
5462306a36Sopenharmony_ci				   const unsigned int offset);
5562306a36Sopenharmony_ci	void (*register_write)(struct rt2x00_dev *rt2x00dev,
5662306a36Sopenharmony_ci			       const unsigned int offset, u32 value);
5762306a36Sopenharmony_ci	void (*register_write_lock)(struct rt2x00_dev *rt2x00dev,
5862306a36Sopenharmony_ci				    const unsigned int offset, u32 value);
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ci	void (*register_multiread)(struct rt2x00_dev *rt2x00dev,
6162306a36Sopenharmony_ci				   const unsigned int offset,
6262306a36Sopenharmony_ci				   void *value, const u32 length);
6362306a36Sopenharmony_ci	void (*register_multiwrite)(struct rt2x00_dev *rt2x00dev,
6462306a36Sopenharmony_ci				    const unsigned int offset,
6562306a36Sopenharmony_ci				    const void *value, const u32 length);
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_ci	int (*regbusy_read)(struct rt2x00_dev *rt2x00dev,
6862306a36Sopenharmony_ci			    const unsigned int offset,
6962306a36Sopenharmony_ci			    const struct rt2x00_field32 field, u32 *reg);
7062306a36Sopenharmony_ci
7162306a36Sopenharmony_ci	int (*read_eeprom)(struct rt2x00_dev *rt2x00dev);
7262306a36Sopenharmony_ci	bool (*hwcrypt_disabled)(struct rt2x00_dev *rt2x00dev);
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_ci	int (*drv_write_firmware)(struct rt2x00_dev *rt2x00dev,
7562306a36Sopenharmony_ci				  const u8 *data, const size_t len);
7662306a36Sopenharmony_ci	int (*drv_init_registers)(struct rt2x00_dev *rt2x00dev);
7762306a36Sopenharmony_ci	__le32 *(*drv_get_txwi)(struct queue_entry *entry);
7862306a36Sopenharmony_ci	unsigned int (*drv_get_dma_done)(struct data_queue *queue);
7962306a36Sopenharmony_ci};
8062306a36Sopenharmony_ci
8162306a36Sopenharmony_cistatic inline u32 rt2800_register_read(struct rt2x00_dev *rt2x00dev,
8262306a36Sopenharmony_ci				       const unsigned int offset)
8362306a36Sopenharmony_ci{
8462306a36Sopenharmony_ci	const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
8562306a36Sopenharmony_ci
8662306a36Sopenharmony_ci	return rt2800ops->register_read(rt2x00dev, offset);
8762306a36Sopenharmony_ci}
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_cistatic inline u32 rt2800_register_read_lock(struct rt2x00_dev *rt2x00dev,
9062306a36Sopenharmony_ci					    const unsigned int offset)
9162306a36Sopenharmony_ci{
9262306a36Sopenharmony_ci	const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
9362306a36Sopenharmony_ci
9462306a36Sopenharmony_ci	return rt2800ops->register_read_lock(rt2x00dev, offset);
9562306a36Sopenharmony_ci}
9662306a36Sopenharmony_ci
9762306a36Sopenharmony_cistatic inline void rt2800_register_write(struct rt2x00_dev *rt2x00dev,
9862306a36Sopenharmony_ci					 const unsigned int offset,
9962306a36Sopenharmony_ci					 u32 value)
10062306a36Sopenharmony_ci{
10162306a36Sopenharmony_ci	const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
10262306a36Sopenharmony_ci
10362306a36Sopenharmony_ci	rt2800ops->register_write(rt2x00dev, offset, value);
10462306a36Sopenharmony_ci}
10562306a36Sopenharmony_ci
10662306a36Sopenharmony_cistatic inline void rt2800_register_write_lock(struct rt2x00_dev *rt2x00dev,
10762306a36Sopenharmony_ci					      const unsigned int offset,
10862306a36Sopenharmony_ci					      u32 value)
10962306a36Sopenharmony_ci{
11062306a36Sopenharmony_ci	const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
11162306a36Sopenharmony_ci
11262306a36Sopenharmony_ci	rt2800ops->register_write_lock(rt2x00dev, offset, value);
11362306a36Sopenharmony_ci}
11462306a36Sopenharmony_ci
11562306a36Sopenharmony_cistatic inline void rt2800_register_multiread(struct rt2x00_dev *rt2x00dev,
11662306a36Sopenharmony_ci					     const unsigned int offset,
11762306a36Sopenharmony_ci					     void *value, const u32 length)
11862306a36Sopenharmony_ci{
11962306a36Sopenharmony_ci	const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
12062306a36Sopenharmony_ci
12162306a36Sopenharmony_ci	rt2800ops->register_multiread(rt2x00dev, offset, value, length);
12262306a36Sopenharmony_ci}
12362306a36Sopenharmony_ci
12462306a36Sopenharmony_cistatic inline void rt2800_register_multiwrite(struct rt2x00_dev *rt2x00dev,
12562306a36Sopenharmony_ci					      const unsigned int offset,
12662306a36Sopenharmony_ci					      const void *value,
12762306a36Sopenharmony_ci					      const u32 length)
12862306a36Sopenharmony_ci{
12962306a36Sopenharmony_ci	const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
13062306a36Sopenharmony_ci
13162306a36Sopenharmony_ci	rt2800ops->register_multiwrite(rt2x00dev, offset, value, length);
13262306a36Sopenharmony_ci}
13362306a36Sopenharmony_ci
13462306a36Sopenharmony_cistatic inline int rt2800_regbusy_read(struct rt2x00_dev *rt2x00dev,
13562306a36Sopenharmony_ci				      const unsigned int offset,
13662306a36Sopenharmony_ci				      const struct rt2x00_field32 field,
13762306a36Sopenharmony_ci				      u32 *reg)
13862306a36Sopenharmony_ci{
13962306a36Sopenharmony_ci	const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
14062306a36Sopenharmony_ci
14162306a36Sopenharmony_ci	return rt2800ops->regbusy_read(rt2x00dev, offset, field, reg);
14262306a36Sopenharmony_ci}
14362306a36Sopenharmony_ci
14462306a36Sopenharmony_cistatic inline int rt2800_read_eeprom(struct rt2x00_dev *rt2x00dev)
14562306a36Sopenharmony_ci{
14662306a36Sopenharmony_ci	const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
14762306a36Sopenharmony_ci
14862306a36Sopenharmony_ci	return rt2800ops->read_eeprom(rt2x00dev);
14962306a36Sopenharmony_ci}
15062306a36Sopenharmony_ci
15162306a36Sopenharmony_cistatic inline bool rt2800_hwcrypt_disabled(struct rt2x00_dev *rt2x00dev)
15262306a36Sopenharmony_ci{
15362306a36Sopenharmony_ci	const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
15462306a36Sopenharmony_ci
15562306a36Sopenharmony_ci	return rt2800ops->hwcrypt_disabled(rt2x00dev);
15662306a36Sopenharmony_ci}
15762306a36Sopenharmony_ci
15862306a36Sopenharmony_cistatic inline int rt2800_drv_write_firmware(struct rt2x00_dev *rt2x00dev,
15962306a36Sopenharmony_ci					    const u8 *data, const size_t len)
16062306a36Sopenharmony_ci{
16162306a36Sopenharmony_ci	const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
16262306a36Sopenharmony_ci
16362306a36Sopenharmony_ci	return rt2800ops->drv_write_firmware(rt2x00dev, data, len);
16462306a36Sopenharmony_ci}
16562306a36Sopenharmony_ci
16662306a36Sopenharmony_cistatic inline int rt2800_drv_init_registers(struct rt2x00_dev *rt2x00dev)
16762306a36Sopenharmony_ci{
16862306a36Sopenharmony_ci	const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
16962306a36Sopenharmony_ci
17062306a36Sopenharmony_ci	return rt2800ops->drv_init_registers(rt2x00dev);
17162306a36Sopenharmony_ci}
17262306a36Sopenharmony_ci
17362306a36Sopenharmony_cistatic inline __le32 *rt2800_drv_get_txwi(struct queue_entry *entry)
17462306a36Sopenharmony_ci{
17562306a36Sopenharmony_ci	const struct rt2800_ops *rt2800ops = entry->queue->rt2x00dev->ops->drv;
17662306a36Sopenharmony_ci
17762306a36Sopenharmony_ci	return rt2800ops->drv_get_txwi(entry);
17862306a36Sopenharmony_ci}
17962306a36Sopenharmony_ci
18062306a36Sopenharmony_cistatic inline unsigned int rt2800_drv_get_dma_done(struct data_queue *queue)
18162306a36Sopenharmony_ci{
18262306a36Sopenharmony_ci	const struct rt2800_ops *rt2800ops = queue->rt2x00dev->ops->drv;
18362306a36Sopenharmony_ci
18462306a36Sopenharmony_ci	return rt2800ops->drv_get_dma_done(queue);
18562306a36Sopenharmony_ci}
18662306a36Sopenharmony_ci
18762306a36Sopenharmony_civoid rt2800_mcu_request(struct rt2x00_dev *rt2x00dev,
18862306a36Sopenharmony_ci			const u8 command, const u8 token,
18962306a36Sopenharmony_ci			const u8 arg0, const u8 arg1);
19062306a36Sopenharmony_ci
19162306a36Sopenharmony_ciint rt2800_wait_csr_ready(struct rt2x00_dev *rt2x00dev);
19262306a36Sopenharmony_ciint rt2800_wait_wpdma_ready(struct rt2x00_dev *rt2x00dev);
19362306a36Sopenharmony_ci
19462306a36Sopenharmony_ciint rt2800_check_firmware(struct rt2x00_dev *rt2x00dev,
19562306a36Sopenharmony_ci			  const u8 *data, const size_t len);
19662306a36Sopenharmony_ciint rt2800_load_firmware(struct rt2x00_dev *rt2x00dev,
19762306a36Sopenharmony_ci			 const u8 *data, const size_t len);
19862306a36Sopenharmony_ci
19962306a36Sopenharmony_civoid rt2800_write_tx_data(struct queue_entry *entry,
20062306a36Sopenharmony_ci			  struct txentry_desc *txdesc);
20162306a36Sopenharmony_civoid rt2800_process_rxwi(struct queue_entry *entry, struct rxdone_entry_desc *txdesc);
20262306a36Sopenharmony_ci
20362306a36Sopenharmony_civoid rt2800_txdone_entry(struct queue_entry *entry, u32 status, __le32 *txwi,
20462306a36Sopenharmony_ci			 bool match);
20562306a36Sopenharmony_civoid rt2800_txdone(struct rt2x00_dev *rt2x00dev, unsigned int quota);
20662306a36Sopenharmony_civoid rt2800_txdone_nostatus(struct rt2x00_dev *rt2x00dev);
20762306a36Sopenharmony_cibool rt2800_txstatus_timeout(struct rt2x00_dev *rt2x00dev);
20862306a36Sopenharmony_cibool rt2800_txstatus_pending(struct rt2x00_dev *rt2x00dev);
20962306a36Sopenharmony_ci
21062306a36Sopenharmony_civoid rt2800_watchdog(struct rt2x00_dev *rt2x00dev);
21162306a36Sopenharmony_ci
21262306a36Sopenharmony_civoid rt2800_write_beacon(struct queue_entry *entry, struct txentry_desc *txdesc);
21362306a36Sopenharmony_civoid rt2800_clear_beacon(struct queue_entry *entry);
21462306a36Sopenharmony_ci
21562306a36Sopenharmony_ciextern const struct rt2x00debug rt2800_rt2x00debug;
21662306a36Sopenharmony_ci
21762306a36Sopenharmony_ciint rt2800_rfkill_poll(struct rt2x00_dev *rt2x00dev);
21862306a36Sopenharmony_ciint rt2800_config_shared_key(struct rt2x00_dev *rt2x00dev,
21962306a36Sopenharmony_ci			     struct rt2x00lib_crypto *crypto,
22062306a36Sopenharmony_ci			     struct ieee80211_key_conf *key);
22162306a36Sopenharmony_ciint rt2800_config_pairwise_key(struct rt2x00_dev *rt2x00dev,
22262306a36Sopenharmony_ci			       struct rt2x00lib_crypto *crypto,
22362306a36Sopenharmony_ci			       struct ieee80211_key_conf *key);
22462306a36Sopenharmony_ciint rt2800_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
22562306a36Sopenharmony_ci		   struct ieee80211_sta *sta);
22662306a36Sopenharmony_ciint rt2800_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
22762306a36Sopenharmony_ci		      struct ieee80211_sta *sta);
22862306a36Sopenharmony_civoid rt2800_config_filter(struct rt2x00_dev *rt2x00dev,
22962306a36Sopenharmony_ci			  const unsigned int filter_flags);
23062306a36Sopenharmony_civoid rt2800_config_intf(struct rt2x00_dev *rt2x00dev, struct rt2x00_intf *intf,
23162306a36Sopenharmony_ci			struct rt2x00intf_conf *conf, const unsigned int flags);
23262306a36Sopenharmony_civoid rt2800_config_erp(struct rt2x00_dev *rt2x00dev, struct rt2x00lib_erp *erp,
23362306a36Sopenharmony_ci		       u32 changed);
23462306a36Sopenharmony_civoid rt2800_config_ant(struct rt2x00_dev *rt2x00dev, struct antenna_setup *ant);
23562306a36Sopenharmony_civoid rt2800_config(struct rt2x00_dev *rt2x00dev,
23662306a36Sopenharmony_ci		   struct rt2x00lib_conf *libconf,
23762306a36Sopenharmony_ci		   const unsigned int flags);
23862306a36Sopenharmony_civoid rt2800_link_stats(struct rt2x00_dev *rt2x00dev, struct link_qual *qual);
23962306a36Sopenharmony_civoid rt2800_reset_tuner(struct rt2x00_dev *rt2x00dev, struct link_qual *qual);
24062306a36Sopenharmony_civoid rt2800_link_tuner(struct rt2x00_dev *rt2x00dev, struct link_qual *qual,
24162306a36Sopenharmony_ci		       const u32 count);
24262306a36Sopenharmony_civoid rt2800_gain_calibration(struct rt2x00_dev *rt2x00dev);
24362306a36Sopenharmony_civoid rt2800_vco_calibration(struct rt2x00_dev *rt2x00dev);
24462306a36Sopenharmony_ci
24562306a36Sopenharmony_ciint rt2800_enable_radio(struct rt2x00_dev *rt2x00dev);
24662306a36Sopenharmony_civoid rt2800_disable_radio(struct rt2x00_dev *rt2x00dev);
24762306a36Sopenharmony_ci
24862306a36Sopenharmony_ciint rt2800_efuse_detect(struct rt2x00_dev *rt2x00dev);
24962306a36Sopenharmony_ciint rt2800_read_eeprom_efuse(struct rt2x00_dev *rt2x00dev);
25062306a36Sopenharmony_ci
25162306a36Sopenharmony_ciint rt2800_probe_hw(struct rt2x00_dev *rt2x00dev);
25262306a36Sopenharmony_ci
25362306a36Sopenharmony_civoid rt2800_get_key_seq(struct ieee80211_hw *hw,
25462306a36Sopenharmony_ci			struct ieee80211_key_conf *key,
25562306a36Sopenharmony_ci			struct ieee80211_key_seq *seq);
25662306a36Sopenharmony_ciint rt2800_set_rts_threshold(struct ieee80211_hw *hw, u32 value);
25762306a36Sopenharmony_ciint rt2800_conf_tx(struct ieee80211_hw *hw,
25862306a36Sopenharmony_ci		   struct ieee80211_vif *vif,
25962306a36Sopenharmony_ci		   unsigned int link_id, u16 queue_idx,
26062306a36Sopenharmony_ci		   const struct ieee80211_tx_queue_params *params);
26162306a36Sopenharmony_ciu64 rt2800_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif);
26262306a36Sopenharmony_ciint rt2800_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
26362306a36Sopenharmony_ci			struct ieee80211_ampdu_params *params);
26462306a36Sopenharmony_ciint rt2800_get_survey(struct ieee80211_hw *hw, int idx,
26562306a36Sopenharmony_ci		      struct survey_info *survey);
26662306a36Sopenharmony_civoid rt2800_disable_wpdma(struct rt2x00_dev *rt2x00dev);
26762306a36Sopenharmony_ci
26862306a36Sopenharmony_civoid rt2800_get_txwi_rxwi_size(struct rt2x00_dev *rt2x00dev,
26962306a36Sopenharmony_ci			       unsigned short *txwi_size,
27062306a36Sopenharmony_ci			       unsigned short *rxwi_size);
27162306a36Sopenharmony_civoid rt2800_pre_reset_hw(struct rt2x00_dev *rt2x00dev);
27262306a36Sopenharmony_ci
27362306a36Sopenharmony_ci#endif /* RT2800LIB_H */
274