18e99ea8dSJohannes Berg /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
28e99ea8dSJohannes Berg /*
3*425d66d8SJohannes Berg  * Copyright (C) 2018-2021 Intel Corporation
48e99ea8dSJohannes Berg  */
5e705c121SKalle Valo #ifndef __iwl_io_h__
6e705c121SKalle Valo #define __iwl_io_h__
7e705c121SKalle Valo 
8e705c121SKalle Valo #include "iwl-devtrace.h"
9e705c121SKalle Valo #include "iwl-trans.h"
10e705c121SKalle Valo 
11e705c121SKalle Valo void iwl_write8(struct iwl_trans *trans, u32 ofs, u8 val);
12e705c121SKalle Valo void iwl_write32(struct iwl_trans *trans, u32 ofs, u32 val);
1312a17458SSara Sharon void iwl_write64(struct iwl_trans *trans, u64 ofs, u64 val);
14e705c121SKalle Valo u32 iwl_read32(struct iwl_trans *trans, u32 ofs);
15e705c121SKalle Valo 
iwl_set_bit(struct iwl_trans * trans,u32 reg,u32 mask)16e705c121SKalle Valo static inline void iwl_set_bit(struct iwl_trans *trans, u32 reg, u32 mask)
17e705c121SKalle Valo {
18e705c121SKalle Valo 	iwl_trans_set_bits_mask(trans, reg, mask, mask);
19e705c121SKalle Valo }
20e705c121SKalle Valo 
iwl_clear_bit(struct iwl_trans * trans,u32 reg,u32 mask)21e705c121SKalle Valo static inline void iwl_clear_bit(struct iwl_trans *trans, u32 reg, u32 mask)
22e705c121SKalle Valo {
23e705c121SKalle Valo 	iwl_trans_set_bits_mask(trans, reg, mask, 0);
24e705c121SKalle Valo }
25e705c121SKalle Valo 
26e705c121SKalle Valo int iwl_poll_bit(struct iwl_trans *trans, u32 addr,
27e705c121SKalle Valo 		 u32 bits, u32 mask, int timeout);
28e705c121SKalle Valo int iwl_poll_direct_bit(struct iwl_trans *trans, u32 addr, u32 mask,
29e705c121SKalle Valo 			int timeout);
30e705c121SKalle Valo 
31e705c121SKalle Valo u32 iwl_read_direct32(struct iwl_trans *trans, u32 reg);
32e705c121SKalle Valo void iwl_write_direct32(struct iwl_trans *trans, u32 reg, u32 value);
3312a17458SSara Sharon void iwl_write_direct64(struct iwl_trans *trans, u64 reg, u64 value);
34e705c121SKalle Valo 
35e705c121SKalle Valo 
3614ef1b43SGolan Ben-Ami u32 iwl_read_prph_no_grab(struct iwl_trans *trans, u32 ofs);
37e705c121SKalle Valo u32 iwl_read_prph(struct iwl_trans *trans, u32 ofs);
3814ef1b43SGolan Ben-Ami void iwl_write_prph_no_grab(struct iwl_trans *trans, u32 ofs, u32 val);
3912a17458SSara Sharon void iwl_write_prph64_no_grab(struct iwl_trans *trans, u64 ofs, u64 val);
40a800f958SEmmanuel Grumbach void iwl_write_prph_delay(struct iwl_trans *trans, u32 ofs,
41a800f958SEmmanuel Grumbach 			  u32 val, u32 delay_ms);
iwl_write_prph(struct iwl_trans * trans,u32 ofs,u32 val)42a800f958SEmmanuel Grumbach static inline void iwl_write_prph(struct iwl_trans *trans, u32 ofs, u32 val)
43a800f958SEmmanuel Grumbach {
44a800f958SEmmanuel Grumbach 	iwl_write_prph_delay(trans, ofs, val, 0);
45a800f958SEmmanuel Grumbach }
46a800f958SEmmanuel Grumbach 
47e705c121SKalle Valo int iwl_poll_prph_bit(struct iwl_trans *trans, u32 addr,
48e705c121SKalle Valo 		      u32 bits, u32 mask, int timeout);
49e705c121SKalle Valo void iwl_set_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask);
50e705c121SKalle Valo void iwl_set_bits_mask_prph(struct iwl_trans *trans, u32 ofs,
51e705c121SKalle Valo 			    u32 bits, u32 mask);
52e705c121SKalle Valo void iwl_clear_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask);
53e705c121SKalle Valo void iwl_force_nmi(struct iwl_trans *trans);
54e705c121SKalle Valo 
55*425d66d8SJohannes Berg int iwl_finish_nic_init(struct iwl_trans *trans);
56c96b5eecSJohannes Berg 
57e705c121SKalle Valo /* Error handling */
58e705c121SKalle Valo int iwl_dump_fh(struct iwl_trans *trans, char **buf);
59e705c121SKalle Valo 
60ea695b7cSShaul Triebitz /*
61ea695b7cSShaul Triebitz  * UMAC periphery address space changed from 0xA00000 to 0xD00000 starting from
62ea695b7cSShaul Triebitz  * device family AX200. So peripheries used in families above and below AX200
63ea695b7cSShaul Triebitz  * should go through iwl_..._umac_..._prph.
64ea695b7cSShaul Triebitz  */
iwl_umac_prph(struct iwl_trans * trans,u32 ofs)65ea695b7cSShaul Triebitz static inline u32 iwl_umac_prph(struct iwl_trans *trans, u32 ofs)
66ea695b7cSShaul Triebitz {
671fee35d0SLuca Coelho 	return ofs + trans->trans_cfg->umac_prph_offset;
68ea695b7cSShaul Triebitz }
69ea695b7cSShaul Triebitz 
iwl_read_umac_prph_no_grab(struct iwl_trans * trans,u32 ofs)70ea695b7cSShaul Triebitz static inline u32 iwl_read_umac_prph_no_grab(struct iwl_trans *trans, u32 ofs)
71ea695b7cSShaul Triebitz {
7279b6c8feSLuca Coelho 	return iwl_read_prph_no_grab(trans, ofs +
731fee35d0SLuca Coelho 				     trans->trans_cfg->umac_prph_offset);
74ea695b7cSShaul Triebitz }
75ea695b7cSShaul Triebitz 
iwl_read_umac_prph(struct iwl_trans * trans,u32 ofs)76ea695b7cSShaul Triebitz static inline u32 iwl_read_umac_prph(struct iwl_trans *trans, u32 ofs)
77ea695b7cSShaul Triebitz {
781fee35d0SLuca Coelho 	return iwl_read_prph(trans, ofs + trans->trans_cfg->umac_prph_offset);
79ea695b7cSShaul Triebitz }
80ea695b7cSShaul Triebitz 
iwl_write_umac_prph_no_grab(struct iwl_trans * trans,u32 ofs,u32 val)81ea695b7cSShaul Triebitz static inline void iwl_write_umac_prph_no_grab(struct iwl_trans *trans, u32 ofs,
82ea695b7cSShaul Triebitz 					       u32 val)
83ea695b7cSShaul Triebitz {
841fee35d0SLuca Coelho 	iwl_write_prph_no_grab(trans,  ofs + trans->trans_cfg->umac_prph_offset,
8579b6c8feSLuca Coelho 			       val);
86ea695b7cSShaul Triebitz }
87ea695b7cSShaul Triebitz 
iwl_write_umac_prph(struct iwl_trans * trans,u32 ofs,u32 val)88ea695b7cSShaul Triebitz static inline void iwl_write_umac_prph(struct iwl_trans *trans, u32 ofs,
89ea695b7cSShaul Triebitz 				       u32 val)
90ea695b7cSShaul Triebitz {
911fee35d0SLuca Coelho 	iwl_write_prph(trans,  ofs + trans->trans_cfg->umac_prph_offset, val);
92ea695b7cSShaul Triebitz }
93ea695b7cSShaul Triebitz 
iwl_poll_umac_prph_bit(struct iwl_trans * trans,u32 addr,u32 bits,u32 mask,int timeout)94ea695b7cSShaul Triebitz static inline int iwl_poll_umac_prph_bit(struct iwl_trans *trans, u32 addr,
95ea695b7cSShaul Triebitz 					 u32 bits, u32 mask, int timeout)
96ea695b7cSShaul Triebitz {
9779b6c8feSLuca Coelho 	return iwl_poll_prph_bit(trans, addr +
981fee35d0SLuca Coelho 				 trans->trans_cfg->umac_prph_offset,
99ea695b7cSShaul Triebitz 				 bits, mask, timeout);
100ea695b7cSShaul Triebitz }
101ea695b7cSShaul Triebitz 
102e705c121SKalle Valo #endif
103