1 /*
2  * Copyright (c) 2024 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 /**
8  * @brief File containing OPs declarations for the
9  * OSAL Layer of the Wi-Fi driver.
10  */
11 
12 #ifndef __OSAL_OPS_H__
13 #define __OSAL_OPS_H__
14 
15 #include "osal_structs.h"
16 
17 
18 /**
19  * @brief struct nrf_wifi_osal_ops - Ops to be provided by a specific OS implementation.
20  *
21  * This structure exposes Ops which need to be implemented by the underlying OS
22  * in order for the WLAN driver to work. The Ops can be directly mapped to OS
23  * primitives where a one-to-one mapping is available. In case a mapping is not
24  * available, an equivalent function will need to be implemented and that
25  * function will then need to be mapped to the corresponding Op.
26  */
27 struct nrf_wifi_osal_ops {
28 	/**
29 	 * @brief Allocate memory.
30 	 *
31 	 * @param size The size of the memory to allocate.
32 	 * @return A pointer to the start of the allocated memory.
33 	 */
34 	void *(*mem_alloc)(size_t size);
35 
36 	/**
37 	 * @brief Allocate zero-initialized memory.
38 	 *
39 	 * @param size The size of the memory to allocate.
40 	 * @return A pointer to the start of the allocated memory.
41 	 */
42 	void *(*mem_zalloc)(size_t size);
43 
44 	/**
45 	 * @brief Free allocated memory.
46 	 *
47 	 * @param buf A pointer to the memory to free.
48 	 */
49 	void (*mem_free)(void *buf);
50 
51 	/**
52 	 * @brief Copy memory.
53 	 *
54 	 * @param dest A pointer to the destination memory.
55 	 * @param src A pointer to the source memory.
56 	 * @param count The number of bytes to copy.
57 	 * @return A pointer to the destination memory.
58 	 */
59 	void *(*mem_cpy)(void *dest, const void *src, size_t count);
60 
61 	/**
62 	 * @brief Set memory.
63 	 *
64 	 * @param start A pointer to the start of the memory block.
65 	 * @param val The value to set.
66 	 * @param size The size of the memory block.
67 	 * @return A pointer to the start of the memory block.
68 	 */
69 	void *(*mem_set)(void *start, int val, size_t size);
70 
71 	/**
72 	 * @brief Compare memory.
73 	 *
74 	 * @param addr1 A pointer to the first memory block.
75 	 * @param addr2 A pointer to the second memory block.
76 	 * @param size The size of the memory blocks.
77 	 * @return 0 if the memory blocks are equal, a negative value if addr1 is less
78 	 *		than addr2, a positive value if addr1 is greater than addr2.
79 	 */
80 	int (*mem_cmp)(const void *addr1, const void *addr2, size_t size);
81 
82 	/**
83 	 * @brief Map IO memory into CPU space.
84 	 *
85 	 * @param addr The address of the IO memory.
86 	 * @param size The size of the IO memory.
87 	 * @return A pointer to the mapped IO memory.
88 	 */
89 	void *(*iomem_mmap)(unsigned long addr, unsigned long size);
90 
91 	/**
92 	 * @brief Unmap IO memory from CPU space.
93 	 *
94 	 * @param addr A pointer to the mapped IO memory.
95 	 */
96 	void (*iomem_unmap)(volatile void *addr);
97 
98 	/**
99 	 * @brief Read a 32-bit value from a device register using a memory mapped address.
100 	 *
101 	 * @param addr A pointer to the memory mapped address.
102 	 * @return The value read from the device register.
103 	 */
104 	unsigned int (*iomem_read_reg32)(const volatile void *addr);
105 
106 	/**
107 	 * @brief Write a 32-bit value to a device register using a memory mapped address.
108 	 *
109 	 * @param addr A pointer to the memory mapped address.
110 	 * @param val The value to write to the device register.
111 	 */
112 	void (*iomem_write_reg32)(volatile void *addr, unsigned int val);
113 
114 	/**
115 	 * @brief Copy data from memory mapped device memory to host memory.
116 	 *
117 	 * @param dest A pointer to the destination memory.
118 	 * @param src A pointer to the source memory.
119 	 * @param count The number of bytes to copy.
120 	 */
121 	void (*iomem_cpy_from)(void *dest, const volatile void *src, size_t count);
122 
123 	/**
124 	 * @brief Copy data from host memory to memory mapped device memory.
125 	 *
126 	 * @param dest A pointer to the destination memory.
127 	 * @param src A pointer to the source memory.
128 	 * @param count The number of bytes to copy.
129 	 */
130 	void (*iomem_cpy_to)(volatile void *dest, const void *src, size_t count);
131 
132 	/**
133 	 * @brief Read a 32-bit value from a QSPI device register.
134 	 *
135 	 * @param priv A pointer to the QSPI device private data.
136 	 * @param addr The address of the device register.
137 	 * @return The value read from the device register.
138 	 */
139 	unsigned int (*qspi_read_reg32)(void *priv, unsigned long addr);
140 
141 	/**
142 	 * @brief Write a 32-bit value to a QSPI device register.
143 	 *
144 	 * @param priv A pointer to the QSPI device private data.
145 	 * @param addr The address of the device register.
146 	 * @param val The value to write to the device register.
147 	 */
148 	void (*qspi_write_reg32)(void *priv, unsigned long addr, unsigned int val);
149 
150 	/**
151 	 * @brief Copy data from QSPI device memory to host memory.
152 	 *
153 	 * @param priv A pointer to the QSPI device private data.
154 	 * @param dest A pointer to the destination memory.
155 	 * @param addr The address of the device memory.
156 	 * @param count The number of bytes to copy.
157 	 */
158 	void (*qspi_cpy_from)(void *priv, void *dest, unsigned long addr, size_t count);
159 
160 	/**
161 	 * @brief Copy data from host memory to QSPI device memory.
162 	 *
163 	 * @param priv A pointer to the QSPI device private data.
164 	 * @param addr The address of the device memory.
165 	 * @param src A pointer to the source memory.
166 	 * @param count The number of bytes to copy.
167 	 */
168 	void (*qspi_cpy_to)(void *priv, unsigned long addr, const void *src, size_t count);
169 
170 	/**
171 	 * @brief Read a 32-bit value from a SPI device register.
172 	 *
173 	 * @param priv A pointer to the SPI device private data.
174 	 * @param addr The address of the device register.
175 	 * @return The value read from the device register.
176 	 */
177 	unsigned int (*spi_read_reg32)(void *priv, unsigned long addr);
178 
179 	/**
180 	 * @brief Write a 32-bit value to a SPI device register.
181 	 *
182 	 * @param priv A pointer to the SPI device private data.
183 	 * @param addr The address of the device register.
184 	 * @param val The value to write to the device register.
185 	 */
186 	void (*spi_write_reg32)(void *priv, unsigned long addr, unsigned int val);
187 
188 	/**
189 	 * @brief Copy data from SPI device memory to host memory.
190 	 *
191 	 * @param priv A pointer to the SPI device private data.
192 	 * @param dest A pointer to the destination memory.
193 	 * @param addr The address of the device memory.
194 	 * @param count The number of bytes to copy.
195 	 */
196 	void (*spi_cpy_from)(void *priv, void *dest, unsigned long addr, size_t count);
197 
198 	/**
199 	 * @brief Copy data from host memory to SPI device memory.
200 	 *
201 	 * @param priv A pointer to the SPI device private data.
202 	 * @param addr The address of the device memory.
203 	 * @param src A pointer to the source memory.
204 	 * @param count The number of bytes to copy.
205 	 */
206 	void (*spi_cpy_to)(void *priv, unsigned long addr, const void *src, size_t count);
207 
208 	/**
209 	 * @brief Allocate a spinlock.
210 	 *
211 	 * @return A pointer to the allocated spinlock.
212 	 */
213 	void *(*spinlock_alloc)(void);
214 
215 	/**
216 	 * @brief Free a spinlock.
217 	 *
218 	 * @param lock A pointer to the spinlock to free.
219 	 */
220 	void (*spinlock_free)(void *lock);
221 
222 	/**
223 	 * @brief Initialize a spinlock.
224 	 *
225 	 * @param lock A pointer to the spinlock to initialize.
226 	 */
227 	void (*spinlock_init)(void *lock);
228 
229 	/**
230 	 * @brief Acquire a spinlock.
231 	 *
232 	 * @param lock A pointer to the spinlock to acquire.
233 	 */
234 	void (*spinlock_take)(void *lock);
235 
236 	/**
237 	 * @brief Release a spinlock.
238 	 *
239 	 * @param lock A pointer to the spinlock to release.
240 	 */
241 	void (*spinlock_rel)(void *lock);
242 
243 	/**
244 	 * @brief Save interrupt states, disable interrupts, and acquire a spinlock.
245 	 *
246 	 * @param lock A pointer to the spinlock to acquire.
247 	 * @param flags A pointer to store the saved interrupt states.
248 	 */
249 	void (*spinlock_irq_take)(void *lock, unsigned long *flags);
250 
251 	/**
252 	 * @brief Restore interrupt states and release a spinlock.
253 	 *
254 	 * @param lock A pointer to the spinlock to release.
255 	 * @param flags A pointer to the saved interrupt states.
256 	 */
257 	void (*spinlock_irq_rel)(void *lock, unsigned long *flags);
258 
259 	/**
260 	 * @brief Log a debug message.
261 	 *
262 	 * @param fmt The format string of the message.
263 	 * @param args The arguments for the format string.
264 	 * @return The number of characters written.
265 	 */
266 	int (*log_dbg)(const char *fmt, va_list args);
267 
268 	/**
269 	 * @brief Log an informational message.
270 	 *
271 	 * @param fmt The format string of the message.
272 	 * @param args The arguments for the format string.
273 	 * @return The number of characters written.
274 	 */
275 	int (*log_info)(const char *fmt, va_list args);
276 
277 	/**
278 	 * @brief Log an error message.
279 	 *
280 	 * @param fmt The format string of the message.
281 	 * @param args The arguments for the format string.
282 	 * @return The number of characters written.
283 	 */
284 	int (*log_err)(const char *fmt, va_list args);
285 
286 	/**
287 	 * @brief Allocate a linked list node.
288 	 *
289 	 * @return A pointer to the allocated linked list node.
290 	 */
291 	void *(*llist_node_alloc)(void);
292 
293 	/**
294 	 * @brief Free a linked list node.
295 	 *
296 	 * @param node A pointer to the linked list node to free.
297 	 */
298 	void (*llist_node_free)(void *node);
299 
300 	/**
301 	 * @brief Get the pointer to the data which the linked list node points to.
302 	 *
303 	 * @param node A pointer to the linked list node.
304 	 * @return A pointer to the data.
305 	 */
306 	void *(*llist_node_data_get)(void *node);
307 
308 	/**
309 	 * @brief Store the pointer to the data in the linked list node.
310 	 *
311 	 * @param node A pointer to the linked list node.
312 	 * @param data A pointer to the data.
313 	 */
314 	void (*llist_node_data_set)(void *node, void *data);
315 
316 	/**
317 	 * @brief Allocate a linked list.
318 	 *
319 	 * @return A pointer to the allocated linked list.
320 	 */
321 	void *(*llist_alloc)(void);
322 
323 	/**
324 	 * @brief Free a linked list.
325 	 *
326 	 * @param llist A pointer to the linked list to free.
327 	 */
328 	void (*llist_free)(void *llist);
329 
330 	/**
331 	 * @brief Initialize a linked list.
332 	 *
333 	 * @param llist A pointer to the linked list to initialize.
334 	 */
335 	void (*llist_init)(void *llist);
336 
337 	/**
338 	 * @brief Add a linked list node to the tail of a linked list.
339 	 *
340 	 * @param llist A pointer to the linked list.
341 	 * @param llist_node A pointer to the linked list node to add.
342 	 */
343 	void (*llist_add_node_tail)(void *llist, void *llist_node);
344 
345 	/**
346 	 * @brief Add a linked list node to the head of a linked list.
347 	 *
348 	 * @param llist A pointer to the linked list.
349 	 * @param llist_node A pointer to the linked list node to add.
350 	 */
351 	void (*llist_add_node_head)(void *llist, void *llist_node);
352 
353 	/**
354 	 * @brief Return the head node from a linked list.
355 	 *
356 	 * @param llist A pointer to the linked list.
357 	 * @return A pointer to the head node, or NULL if the linked list is empty.
358 	 */
359 	void *(*llist_get_node_head)(void *llist);
360 
361 	/**
362 	 * @brief Return the node next to the given node in the linked list.
363 	 *
364 	 * @param llist A pointer to the linked list.
365 	 * @param llist_node A pointer to the current node.
366 	 * @return A pointer to the next node.
367 	 */
368 	void *(*llist_get_node_nxt)(void *llist, void *llist_node);
369 
370 	/**
371 	 * @brief Remove a node from the linked list.
372 	 *
373 	 * @param llist A pointer to the linked list.
374 	 * @param llist_node A pointer to the node to remove.
375 	 */
376 	void (*llist_del_node)(void *llist, void *llist_node);
377 
378 	/**
379 	 * @brief Return the length of the linked list.
380 	 *
381 	 * @param llist A pointer to the linked list.
382 	 * @return The length of the linked list.
383 	 */
384 	unsigned int (*llist_len)(void *llist);
385 
386 	/**
387 	 * @brief Allocate a network buffer.
388 	 *
389 	 * @param size The size of the network buffer.
390 	 * @return A pointer to the allocated network buffer.
391 	 */
392 	void *(*nbuf_alloc)(unsigned int size);
393 
394 	/**
395 	 * @brief Free a network buffer.
396 	 *
397 	 * @param nbuf A pointer to the network buffer to free.
398 	 */
399 	void (*nbuf_free)(void *nbuf);
400 
401 	/**
402 	 * @brief Reserve headroom at the beginning of the data area of a network buffer.
403 	 *
404 	 * @param nbuf A pointer to the network buffer.
405 	 * @param size The size of the headroom to reserve.
406 	 */
407 	void (*nbuf_headroom_res)(void *nbuf, unsigned int size);
408 
409 	/**
410 	 * @brief Get the size of the reserved headroom at the beginning of the
411 	 * data area of a network buffer.
412 	 *
413 	 * @param nbuf A pointer to the network buffer.
414 	 * @return The size of the reserved headroom.
415 	 */
416 	unsigned int (*nbuf_headroom_get)(void *nbuf);
417 
418 	/**
419 	 * @brief Get the size of the data area of a network buffer.
420 	 *
421 	 * @param nbuf A pointer to the network buffer.
422 	 * @return The size of the data area.
423 	 */
424 	unsigned int (*nbuf_data_size)(void *nbuf);
425 
426 	/**
427 	 * @brief Get the pointer to the data area of a network buffer.
428 	 *
429 	 * @param nbuf A pointer to the network buffer.
430 	 * @return A pointer to the data area.
431 	 */
432 	void *(*nbuf_data_get)(void *nbuf);
433 
434 	/**
435 	 * @brief Increase the data area of a network buffer at the end of the area.
436 	 *
437 	 * @param nbuf A pointer to the network buffer.
438 	 * @param size The size to increase the data area by.
439 	 * @return A pointer to the beginning of the data area.
440 	 */
441 	void *(*nbuf_data_put)(void *nbuf, unsigned int size);
442 
443 	/**
444 	 * @brief Increase the data area of a network buffer at the start of the area.
445 	 *
446 	 * @param nbuf A pointer to the network buffer.
447 	 * @param size The size to increase the data area by.
448 	 * @return A pointer to the beginning of the data area.
449 	 */
450 	void *(*nbuf_data_push)(void *nbuf, unsigned int size);
451 
452 	/**
453 	 * @brief Decrease the data area of a network buffer at the start of the area.
454 	 *
455 	 * @param nbuf A pointer to the network buffer.
456 	 * @param size The size to decrease the data area by.
457 	 * @return A pointer to the beginning of the data area.
458 	 */
459 	void *(*nbuf_data_pull)(void *nbuf, unsigned int size);
460 
461 	/**
462 	 * @brief Get the priority of a network buffer.
463 	 *
464 	 * @param nbuf A pointer to the network buffer.
465 	 * @return The priority of the network buffer.
466 	 */
467 	unsigned char (*nbuf_get_priority)(void *nbuf);
468 
469 	/**
470 	 * @brief Get the checksum status of a network buffer.
471 	 *
472 	 * @param nbuf A pointer to the network buffer.
473 	 * @return The checksum status of the network buffer.
474 	 */
475 	unsigned char (*nbuf_get_chksum_done)(void *nbuf);
476 
477 	/**
478 	 * @brief Set the checksum status of a network buffer.
479 	 *
480 	 * @param nbuf A pointer to the network buffer.
481 	 * @param chksum_done The checksum status to set.
482 	 */
483 	void (*nbuf_set_chksum_done)(void *nbuf, unsigned char chksum_done);
484 
485 	/**
486 	 * @brief Allocate a tasklet structure.
487 	 *
488 	 * @param type The type of the tasklet.
489 	 * @return A pointer to the allocated tasklet structure.
490 	 */
491 	void *(*tasklet_alloc)(int type);
492 
493 	/**
494 	 * @brief Free a tasklet structure.
495 	 *
496 	 * @param tasklet A pointer to the tasklet structure to free.
497 	 */
498 	void (*tasklet_free)(void *tasklet);
499 
500 	/**
501 	 * @brief Initialize a tasklet structure.
502 	 *
503 	 * @param tasklet A pointer to the tasklet structure to initialize.
504 	 * @param callback The callback function to be invoked when the tasklet is scheduled.
505 	 * @param data The data to be passed to the callback function.
506 	 */
507 	void (*tasklet_init)(void *tasklet, void (*callback)(unsigned long), unsigned long data);
508 
509 	/**
510 	 * @brief Schedule a tasklet.
511 	 *
512 	 * @param tasklet A pointer to the tasklet to schedule.
513 	 */
514 	void (*tasklet_schedule)(void *tasklet);
515 
516 	/**
517 	 * @brief Terminate a tasklet.
518 	 *
519 	 * @param tasklet A pointer to the tasklet to terminate.
520 	 */
521 	void (*tasklet_kill)(void *tasklet);
522 
523 	/**
524 	 * @brief Sleep for a specified number of milliseconds.
525 	 *
526 	 * @param msecs The number of milliseconds to sleep.
527 	 * @return 0 on success, a negative value on failure.
528 	 */
529 	int (*sleep_ms)(int msecs);
530 
531 	/**
532 	 * @brief Delay for a specified number of microseconds.
533 	 *
534 	 * @param usecs The number of microseconds to delay.
535 	 * @return 0 on success, a negative value on failure.
536 	 */
537 	int (*delay_us)(int usecs);
538 
539 	/**
540 	 * @brief Get the current time of the day in microseconds.
541 	 *
542 	 * @return The current time of the day in microseconds.
543 	 */
544 	unsigned long (*time_get_curr_us)(void);
545 
546 	/**
547 	 * @brief Return the time elapsed in microseconds since a specified time instant.
548 	 *
549 	 * @param start_time The time instant to measure the elapsed time from.
550 	 * @return The time elapsed in microseconds.
551 	 */
552 	unsigned int (*time_elapsed_us)(unsigned long start_time);
553 
554 	/** @brief Get the current time of the day in milliseconds.
555 	 *
556 	 * @return The current time of the day in milliseconds.
557 	 */
558 	unsigned long (*time_get_curr_ms)(void);
559 
560 	/**
561 	 * @brief Return the time elapsed in milliseconds since a specified time instant.
562 	 *
563 	 * @param start_time The time instant to measure the elapsed time from.
564 	 * @return The time elapsed in milliseconds.
565 	 */
566 	unsigned int (*time_elapsed_ms)(unsigned long start_time_us);
567 
568 	/**
569 	 * @brief Initialize the PCIe bus.
570 	 *
571 	 * @param dev_name The name of the PCIe device.
572 	 * @param vendor_id The vendor ID of the PCIe device.
573 	 * @param sub_vendor_id The sub-vendor ID of the PCIe device.
574 	 * @param device_id The device ID of the PCIe device.
575 	 * @param sub_device_id The sub-device ID of the PCIe device.
576 	 * @return A pointer to the initialized PCIe bus.
577 	 */
578 	void *(*bus_pcie_init)(const char *dev_name,
579 						   unsigned int vendor_id,
580 						   unsigned int sub_vendor_id,
581 						   unsigned int device_id,
582 						   unsigned int sub_device_id);
583 
584 	/**
585 	 * @brief Deinitialize the PCIe bus.
586 	 *
587 	 * @param os_pcie_priv A pointer to the PCIe bus.
588 	 */
589 	void (*bus_pcie_deinit)(void *os_pcie_priv);
590 
591 	/**
592 	 * @brief Add a PCIe device to the bus.
593 	 *
594 	 * @param pcie_priv A pointer to the PCIe bus.
595 	 * @param osal_pcie_dev_ctx A pointer to the PCIe device context.
596 	 * @return A pointer to the added PCIe device.
597 	 */
598 	void *(*bus_pcie_dev_add)(void *pcie_priv,
599 							  void *osal_pcie_dev_ctx);
600 
601 	/**
602 	 * @brief Remove a PCIe device from the bus.
603 	 *
604 	 * @param os_pcie_dev_ctx A pointer to the PCIe device.
605 	 */
606 	void (*bus_pcie_dev_rem)(void *os_pcie_dev_ctx);
607 
608 	/**
609 	 * @brief Initialize a PCIe device.
610 	 *
611 	 * @param os_pcie_dev_ctx A pointer to the PCIe device.
612 	 * @return The status of the initialization.
613 	 */
614 	enum nrf_wifi_status (*bus_pcie_dev_init)(void *os_pcie_dev_ctx);
615 
616 	/**
617 	 * @brief Deinitialize a PCIe device.
618 	 *
619 	 * @param os_pcie_dev_ctx A pointer to the PCIe device.
620 	 */
621 	void (*bus_pcie_dev_deinit)(void *os_pcie_dev_ctx);
622 
623 	/**
624 	 * @brief Register an interrupt handler for a PCIe device.
625 	 *
626 	 * @param os_pcie_dev_ctx A pointer to the PCIe device.
627 	 * @param callbk_data The data to be passed to the callback function.
628 	 * @param callback_fn The callback function to be invoked when an interrupt occurs.
629 	 * @return The status of the registration.
630 	 */
631 	enum nrf_wifi_status (*bus_pcie_dev_intr_reg)(void *os_pcie_dev_ctx,
632 			void *callbk_data,
633 			int (*callback_fn)(void *callbk_data));
634 
635 	/**
636 	 * @brief Unregister the interrupt handler for a PCIe device.
637 	 *
638 	 * @param os_pcie_dev_ctx A pointer to the PCIe device.
639 	 */
640 	void (*bus_pcie_dev_intr_unreg)(void *os_pcie_dev_ctx);
641 
642 	/**
643 	 * @brief Map a DMA buffer for a PCIe device.
644 	 *
645 	 * @param os_pcie_dev_ctx A pointer to the PCIe device.
646 	 * @param virt_addr The virtual address of the buffer.
647 	 * @param size The size of the buffer.
648 	 * @param dir The direction of the DMA transfer.
649 	 * @return A pointer to the mapped DMA buffer.
650 	 */
651 	void *(*bus_pcie_dev_dma_map)(void *os_pcie_dev_ctx,
652 								  void *virt_addr,
653 								  size_t size,
654 								  enum nrf_wifi_osal_dma_dir dir);
655 
656 	/**
657 	 * @brief Unmap a DMA buffer for a PCIe device.
658 	 *
659 	 * @param os_pcie_dev_ctx A pointer to the PCIe device.
660 	 * @param dma_addr The DMA address of the buffer.
661 	 * @param size The size of the buffer.
662 	 * @param dir The direction of the DMA transfer.
663 	 */
664 	void (*bus_pcie_dev_dma_unmap)(void *os_pcie_dev_ctx,
665 								   void *dma_addr,
666 								   size_t size,
667 								   enum nrf_wifi_osal_dma_dir dir);
668 
669 	/**
670 	 * @brief Get the host mapping of a PCIe device.
671 	 *
672 	 * @param os_pcie_dev_ctx A pointer to the PCIe device.
673 	 * @param host_map A pointer to the host mapping structure.
674 	 */
675 	void (*bus_pcie_dev_host_map_get)(void *os_pcie_dev_ctx,
676 			struct nrf_wifi_osal_host_map *host_map);
677 
678 	/**
679 	 * @brief Initialize the QSPI bus.
680 	 *
681 	 * @return A pointer to the initialized QSPI bus.
682 	 */
683 	void *(*bus_qspi_init)(void);
684 
685 	/**
686 	 * @brief Deinitialize the QSPI bus.
687 	 *
688 	 * @param os_qspi_priv A pointer to the QSPI bus.
689 	 */
690 	void (*bus_qspi_deinit)(void *os_qspi_priv);
691 
692 	/**
693 	 * @brief Add a QSPI device to the bus.
694 	 *
695 	 * @param qspi_priv A pointer to the QSPI bus.
696 	 * @param osal_qspi_dev_ctx A pointer to the QSPI device context.
697 	 * @return A pointer to the added QSPI device.
698 	 */
699 	void *(*bus_qspi_dev_add)(void *qspi_priv,
700 							  void *osal_qspi_dev_ctx);
701 
702 	/**
703 	 * @brief Remove a QSPI device from the bus.
704 	 *
705 	 * @param os_qspi_dev_ctx A pointer to the QSPI device.
706 	 */
707 	void (*bus_qspi_dev_rem)(void *os_qspi_dev_ctx);
708 
709 	/**
710 	 * @brief Initialize a QSPI device.
711 	 *
712 	 * @param os_qspi_dev_ctx A pointer to the QSPI device.
713 	 * @return The status of the initialization.
714 	 */
715 	enum nrf_wifi_status (*bus_qspi_dev_init)(void *os_qspi_dev_ctx);
716 
717 	/**
718 	 * @brief Deinitialize a QSPI device.
719 	 *
720 	 * @param os_qspi_dev_ctx A pointer to the QSPI device.
721 	 */
722 	void (*bus_qspi_dev_deinit)(void *os_qspi_dev_ctx);
723 
724 	/**
725 	 * @brief Register an interrupt handler for a QSPI device.
726 	 *
727 	 * @param os_qspi_dev_ctx A pointer to the QSPI device.
728 	 * @param callbk_data The data to be passed to the callback function.
729 	 * @param callback_fn The callback function to be invoked when an interrupt occurs.
730 	 * @return The status of the registration.
731 	 */
732 	enum nrf_wifi_status (*bus_qspi_dev_intr_reg)(void *os_qspi_dev_ctx,
733 			void *callbk_data,
734 			int (*callback_fn)(void *callbk_data));
735 
736 	/**
737 	 * @brief Unregister the interrupt handler for a QSPI device.
738 	 *
739 	 * @param os_qspi_dev_ctx A pointer to the QSPI device.
740 	 */
741 	void (*bus_qspi_dev_intr_unreg)(void *os_qspi_dev_ctx);
742 
743 	/**
744 	 * @brief Get the host mapping of a QSPI device.
745 	 *
746 	 * @param os_qspi_dev_ctx A pointer to the QSPI device.
747 	 * @param host_map A pointer to the host mapping structure.
748 	 */
749 	void (*bus_qspi_dev_host_map_get)(void *os_qspi_dev_ctx,
750 			struct nrf_wifi_osal_host_map *host_map);
751 
752 	/**
753 	 * @brief Initialize the SPI bus.
754 	 *
755 	 * @return A pointer to the initialized SPI bus.
756 	 */
757 	void *(*bus_spi_init)(void);
758 
759 	/**
760 	 * @brief Deinitialize the SPI bus.
761 	 *
762 	 * @param os_spi_priv A pointer to the SPI bus.
763 	 */
764 	void (*bus_spi_deinit)(void *os_spi_priv);
765 
766 	/**
767 	 * @brief Add a SPI device to the bus.
768 	 *
769 	 * @param spi_priv A pointer to the SPI bus.
770 	 * @param osal_spi_dev_ctx A pointer to the SPI device context.
771 	 * @return A pointer to the added SPI device.
772 	 */
773 	void *(*bus_spi_dev_add)(void *spi_priv,
774 							 void *osal_spi_dev_ctx);
775 
776 	/**
777 	 * @brief Remove a SPI device from the bus.
778 	 *
779 	 * @param os_spi_dev_ctx A pointer to the SPI device.
780 	 */
781 	void (*bus_spi_dev_rem)(void *os_spi_dev_ctx);
782 
783 	/**
784 	 * @brief Initialize a SPI device.
785 	 *
786 	 * @param os_spi_dev_ctx A pointer to the SPI device.
787 	 * @return The status of the initialization.
788 	 */
789 	enum nrf_wifi_status (*bus_spi_dev_init)(void *os_spi_dev_ctx);
790 
791 	/**
792 	 * @brief Deinitialize a SPI device.
793 	 *
794 	 * @param os_spi_dev_ctx A pointer to the SPI device.
795 	 */
796 	void (*bus_spi_dev_deinit)(void *os_spi_dev_ctx);
797 
798 	/**
799 	 * @brief Register an interrupt handler for a SPI device.
800 	 *
801 	 * @param os_spi_dev_ctx A pointer to the SPI device.
802 	 * @param callbk_data The data to be passed to the callback function.
803 	 * @param callback_fn The callback function to be invoked when an interrupt occurs.
804 	 * @return The status of the registration.
805 	 */
806 	enum nrf_wifi_status (*bus_spi_dev_intr_reg)(void *os_spi_dev_ctx,
807 			void *callbk_data,
808 			int (*callback_fn)(void *callbk_data));
809 
810 	/**
811 	 * @brief Unregister the interrupt handler for a SPI device.
812 	 *
813 	 * @param os_spi_dev_ctx A pointer to the SPI device.
814 	 */
815 	void (*bus_spi_dev_intr_unreg)(void *os_spi_dev_ctx);
816 
817 	/**
818 	 * @brief Get the host mapping of a SPI device.
819 	 *
820 	 * @param os_spi_dev_ctx A pointer to the SPI device.
821 	 * @param host_map A pointer to the host mapping structure.
822 	 */
823 	void (*bus_spi_dev_host_map_get)(void *os_spi_dev_ctx,
824 			struct nrf_wifi_osal_host_map *host_map);
825 
826 	#if defined(NRF_WIFI_LOW_POWER) || defined(__DOXYGEN__)
827 	/**
828 	 * @brief Allocate a timer.
829 	 *
830 	 * @return A pointer to the allocated timer.
831 	 */
832 	void *(*timer_alloc)(void);
833 
834 	/**
835 	 * @brief Free a timer.
836 	 *
837 	 * @param timer A pointer to the timer to free.
838 	 */
839 	void (*timer_free)(void *timer);
840 
841 	/**
842 	 * @brief Initialize a timer.
843 	 *
844 	 * @param timer A pointer to the timer to initialize.
845 	 * @param callback The callback function to be invoked when the timer expires.
846 	 * @param data The data to be passed to the callback function.
847 	 */
848 	void (*timer_init)(void *timer,
849 					   void (*callback)(unsigned long),
850 					   unsigned long data);
851 
852 	/**
853 	 * @brief Schedule a timer.
854 	 *
855 	 * @param timer A pointer to the timer to schedule.
856 	 * @param duration The duration of the timer in milliseconds.
857 	 */
858 	void (*timer_schedule)(void *timer, unsigned long duration);
859 
860 	/**
861 	 * @brief Terminate a timer.
862 	 *
863 	 * @param timer A pointer to the timer to terminate.
864 	 */
865 	void (*timer_kill)(void *timer);
866 
867 	/**
868 	 * @brief Put the QSPI bus to sleep.
869 	 *
870 	 * @param os_qspi_priv A pointer to the QSPI bus.
871 	 * @return 0 on success, a negative value on failure.
872 	 */
873 	int (*bus_qspi_ps_sleep)(void *os_qspi_priv);
874 
875 	/**
876 	 * @brief Wake up the QSPI bus from sleep.
877 	 *
878 	 * @param os_qspi_priv A pointer to the QSPI bus.
879 	 * @return 0 on success, a negative value on failure.
880 	 */
881 	int (*bus_qspi_ps_wake)(void *os_qspi_priv);
882 
883 	/**
884 	 * @brief Get the power state of the QSPI bus.
885 	 *
886 	 * @param os_qspi_priv A pointer to the QSPI bus.
887 	 * @return The power state of the QSPI bus.
888 	 */
889 	int (*bus_qspi_ps_status)(void *os_qspi_priv);
890 	#endif /* NRF_WIFI_LOW_POWER */
891 
892 	/**
893 	 * @brief Assert a condition and display an error message if the condition is false.
894 	 *
895 	 * @param test_val The value to test.
896 	 * @param val The value to compare against.
897 	 * @param op The comparison operator.
898 	 * @param assert_msg The error message to display.
899 	 */
900 	void (*assert)(int test_val,
901 				   int val,
902 				   enum nrf_wifi_assert_op_type op,
903 				   char *assert_msg);
904 
905 	/**
906 	 * @brief Get the length of a string.
907 	 *
908 	 * @param str A pointer to the string.
909 	 * @return The length of the string.
910 	 */
911 	unsigned int (*strlen)(const void *str);
912 
913 	/**
914 	 * @brief Get a random 8-bit value.
915 	 *
916 	 * @return A random 8-bit value.
917 	 */
918 	unsigned char (*rand8_get)(void);
919 };
920 #endif /* __OSAL_OPS_H__ */
921