1 /*
2  * Copyright (c) 2024 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 /**
8  * @brief Header containing the OPs declarations for the Bus Abstraction Layer
9  * (BAL) of the Wi-Fi driver.
10  */
11 
12 #ifndef __BAL_OPS_H__
13 #define __BAL_OPS_H__
14 
15 /**
16  * @brief Ops to be provided by a particular bus implementation.
17  *
18  * This structure defines the operations that need to be implemented
19  * by a specific bus implementation.
20  */
21 struct nrf_wifi_bal_ops {
22 	/**
23 	 * @brief Initialize the bus.
24 	 *
25 	 * @param cfg_params Pointer to the configuration parameters.
26 	 * @param intr_callbk_fn Pointer to the interrupt callback function.
27 	 * @return Pointer to the initialized instance of the bus.
28 	 */
29 	void * (*init)(void *cfg_params,
30 		       enum nrf_wifi_status (*intr_callbk_fn)(void *hal_ctx));
31 
32 	/**
33 	 * @brief Deinitialize the bus.
34 	 *
35 	 * @param bus_priv Pointer to the bus private data.
36 	 */
37 	void (*deinit)(void *bus_priv);
38 
39 	/**
40 	 * @brief Add a device to the bus.
41 	 *
42 	 * @param bus_priv Pointer to the bus private data.
43 	 * @param bal_dev_ctx Pointer to the BAL device context.
44 	 * @return Pointer to the added device context.
45 	 */
46 	void * (*dev_add)(void *bus_priv,
47 			  void *bal_dev_ctx);
48 
49 	/**
50 	 * @brief Remove a device from the bus.
51 	 *
52 	 * @param bus_dev_ctx Pointer to the bus device context.
53 	 */
54 	void (*dev_rem)(void *bus_dev_ctx);
55 
56 	/**
57 	 * @brief Initialize a device on the bus.
58 	 *
59 	 * @param bus_dev_ctx Pointer to the bus device context.
60 	 * @return Status of the device initialization.
61 	 */
62 	enum nrf_wifi_status (*dev_init)(void *bus_dev_ctx);
63 
64 	/**
65 	 * @brief Deinitialize a device on the bus.
66 	 *
67 	 * @param bus_dev_ctx Pointer to the bus device context.
68 	 */
69 	void (*dev_deinit)(void *bus_dev_ctx);
70 
71 	/**
72 	 * @brief Read a word from the bus.
73 	 *
74 	 * @param bus_dev_ctx Pointer to the bus device context.
75 	 * @param addr_offset Address offset.
76 	 * @return The read word.
77 	 */
78 	unsigned int (*read_word)(void *bus_dev_ctx,
79 				  unsigned long addr_offset);
80 
81 	/**
82 	 * @brief Write a word to the bus.
83 	 *
84 	 * @param bus_dev_ctx Pointer to the bus device context.
85 	 * @param addr_offset Address offset.
86 	 * @param val Value to write.
87 	 */
88 	void (*write_word)(void *bus_dev_ctx,
89 			   unsigned long addr_offset,
90 			   unsigned int val);
91 
92 	/**
93 	 * @brief Read a block of data from the bus.
94 	 *
95 	 * @param bus_dev_ctx Pointer to the bus device context.
96 	 * @param dest_addr Destination address.
97 	 * @param src_addr_offset Source address offset.
98 	 * @param len Length of the block to read.
99 	 */
100 	void (*read_block)(void *bus_dev_ctx,
101 			   void *dest_addr,
102 			   unsigned long src_addr_offset,
103 			   size_t len);
104 
105 	/**
106 	 * @brief Write a block of data to the bus.
107 	 *
108 	 * @param bus_dev_ctx Pointer to the bus device context.
109 	 * @param dest_addr_offset Destination address offset.
110 	 * @param src_addr Pointer to the source address.
111 	 * @param len Length of the block to write.
112 	 */
113 	void (*write_block)(void *bus_dev_ctx,
114 				unsigned long dest_addr_offset,
115 				const void *src_addr,
116 				size_t len);
117 
118 	/**
119 	 * @brief Map a DMA buffer.
120 	 *
121 	 * @param bus_dev_ctx Pointer to the bus device context.
122 	 * @param virt_addr Virtual address of the buffer.
123 	 * @param len Length of the buffer.
124 	 * @param dma_dir DMA direction.
125 	 * @return Physical address of the mapped buffer.
126 	 */
127 	unsigned long (*dma_map)(void *bus_dev_ctx,
128 				 unsigned long virt_addr,
129 				 size_t len,
130 				 enum nrf_wifi_osal_dma_dir dma_dir);
131 
132 	/**
133 	 * @brief Unmap a DMA buffer.
134 	 *
135 	 * @param bus_dev_ctx Pointer to the bus device context.
136 	 * @param phy_addr Physical address of the buffer.
137 	 * @param len Length of the buffer.
138 	 * @param dma_dir DMA direction.
139 	 * @return Physical address of the unmapped buffer.
140 	 */
141 	unsigned long (*dma_unmap)(void *bus_dev_ctx,
142 				   unsigned long phy_addr,
143 				   size_t len,
144 				   enum nrf_wifi_osal_dma_dir dma_dir);
145 
146 #if defined(NRF_WIFI_LOW_POWER) || defined(__DOXYGEN__)
147 	/**
148 	 * @brief Put the device into power-saving sleep mode.
149 	 *
150 	 * @param bus_dev_ctx Pointer to the bus device context.
151 	 */
152 	void (*rpu_ps_sleep)(void *bus_dev_ctx);
153 
154 	/**
155 	 * @brief Wake the device from power-saving sleep mode.
156 	 *
157 	 * @param bus_dev_ctx Pointer to the bus device context.
158 	 */
159 	void (*rpu_ps_wake)(void *bus_dev_ctx);
160 
161 	/**
162 	 * @brief Get the power-saving status of the device.
163 	 *
164 	 * @param bus_dev_ctx Pointer to the bus device context.
165 	 * @return Power-saving status of the device.
166 	 */
167 	int (*rpu_ps_status)(void *bus_dev_ctx);
168 #endif /* NRF_WIFI_LOW_POWER */
169 };
170 
171 /**
172  * @brief Get the bus operations.
173  *
174  * @return Pointer to the bus operations.
175  */
176 struct nrf_wifi_bal_ops *get_bus_ops(void);
177 #endif /* __BAL_OPS_H__ */
178