1 /*
2  * Copyright (c) 2024 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 /**
8  * @file fmac_tx.h
9  *
10  * @brief Header containing TX data path specific declarations for the
11  * FMAC IF Layer of the Wi-Fi driver.
12  */
13 
14 #ifndef __FMAC_TX_H__
15 #define __FMAC_TX_H__
16 
17 #include "host_rpu_data_if.h"
18 #include "system/fmac_structs.h"
19 
20 /**
21  * @defgroup fmac_tx FMAC TX
22  * @{
23  */
24 
25 /**
26  * @brief The maximum number of descriptors in a TX descriptor bucket.
27  */
28 #define TX_DESC_BUCKET_BOUND 32
29 
30 /**
31  * @brief The length of the WMM parameters.
32  */
33 #define DOT11_WMM_PARAMS_LEN 2
34 
35 /**
36  * @brief The size of the spare descriptor queue map.
37  *
38  * Four bits represent four access categories: VO, VI, BE, and BK.
39  */
40 #define SPARE_DESC_Q_MAP_SIZE 4
41 
42 /**
43  * @brief The status of a TX operation performed by the RPU driver.
44  */
45 /**
46  * @brief The status of a TX operation performed by the RPU driver.
47  */
48 enum nrf_wifi_fmac_tx_status {
49 	/** The TX operation was successful (sent packet to RPU). */
50 	NRF_WIFI_FMAC_TX_STATUS_SUCCESS,
51 	/** The TX operation was successful (packet queued in driver). */
52 	NRF_WIFI_FMAC_TX_STATUS_QUEUED = 1,
53 	/** The TX operation failed. */
54 	NRF_WIFI_FMAC_TX_STATUS_FAIL = -1
55 };
56 
57 /**
58  * @brief Structure containing information about a TX packet.
59  */
60 struct tx_pkt_info {
61 	/** Pointer to the TX packet. */
62 	void *pkt;
63 	/** Peer ID. */
64 	unsigned int peer_id;
65 };
66 
67 #ifdef NRF70_RAW_DATA_TX
68 /**
69  * @brief Structure containing information for preparing a raw TX command.
70  */
71 struct tx_cmd_prep_raw_info {
72 	/** Pointer to the FMAC device context. */
73 	struct nrf_wifi_fmac_dev_ctx *fmac_dev_ctx;
74 	/** Pointer to the raw TX configuration. */
75 	struct nrf_wifi_cmd_raw_tx *raw_config;
76 	/** Number of TX packets. */
77 	unsigned char num_tx_pkts;
78 };
79 #endif /* NRF70_RAW_DATA_TX */
80 
81 /**
82  * @brief Structure containing information for preparing a TX command.
83  */
84 struct tx_cmd_prep_info {
85 	/** Pointer to the FMAC device context. */
86 	struct nrf_wifi_fmac_dev_ctx *fmac_dev_ctx;
87 	/** Pointer to the TX configuration. */
88 	struct nrf_wifi_tx_buff *config;
89 };
90 
91 /**
92  * @brief Initialize the TX module.
93  *
94  * @param fmac_dev_ctx Pointer to the FMAC device context.
95  * @return The status of the initialization.
96  */
97 enum nrf_wifi_status tx_init(struct nrf_wifi_fmac_dev_ctx *fmac_dev_ctx);
98 
99 /**
100  * @brief Deinitialize the TX module.
101  *
102  * @param fmac_dev_ctx Pointer to the FMAC device context.
103  */
104 void tx_deinit(struct nrf_wifi_fmac_dev_ctx *fmac_dev_ctx);
105 
106 /**
107  * @brief Process the TX done event.
108  *
109  * @param fmac_dev_ctx Pointer to the FMAC device context.
110  * @param config Pointer to the TX buffer done configuration.
111  * @return The status of the event processing.
112  */
113 enum nrf_wifi_status nrf_wifi_fmac_tx_done_event_process(struct nrf_wifi_fmac_dev_ctx *fmac_dev_ctx,
114 		struct nrf_wifi_tx_buff_done *config);
115 
116 #ifdef NRF70_RAW_DATA_TX
117 /**
118  * @brief Process the raw TX done event.
119  *
120  * @param fmac_dev_ctx Pointer to the FMAC device context.
121  * @param config Pointer to the raw TX done configuration.
122  * @return The status of the event processing.
123  */
124 enum nrf_wifi_status
125 nrf_wifi_fmac_rawtx_done_event_process(struct nrf_wifi_fmac_dev_ctx *fmac_dev_ctx,
126 		struct nrf_wifi_event_raw_tx_done *config);
127 #endif /* CONFIG_NRF70_RAW_DATA_TX */
128 
129 /**
130  * @brief Get a TX descriptor from the specified queue.
131  *
132  * @param fmac_dev_ctx Pointer to the FMAC device context.
133  * @param queue The queue index.
134  * @return The TX descriptor.
135  */
136 unsigned int tx_desc_get(struct nrf_wifi_fmac_dev_ctx *fmac_dev_ctx,
137 		int queue);
138 
139 /**
140  * @brief Process the pending TX descriptors.
141  *
142  * @param fmac_dev_ctx Pointer to the FMAC device context.
143  * @param desc The descriptor index.
144  * @param ac The access category.
145  * @return The status of the pending process.
146  */
147 enum nrf_wifi_status tx_pending_process(struct nrf_wifi_fmac_dev_ctx *fmac_dev_ctx,
148 		unsigned int desc,
149 		unsigned int ac);
150 
151 /**
152  * @brief Initialize a TX command.
153  *
154  * @param fmac_dev_ctx Pointer to the FMAC device context.
155  * @param txq Pointer to the TX queue.
156  * @param desc The descriptor index.
157  * @param peer_id The peer ID.
158  * @return The status of the command initialization.
159  */
160 enum nrf_wifi_status tx_cmd_init(struct nrf_wifi_fmac_dev_ctx *fmac_dev_ctx,
161 		void *txq,
162 		int desc,
163 		int peer_id);
164 
165 /**
166  * @brief Request free TX buffers.
167  *
168  * @param fmac_ctx Pointer to the FMAC context.
169  * @param desc The descriptor index.
170  * @param ac Pointer to the access category.
171  * @return The number of free TX buffers.
172  */
173 unsigned int tx_buff_req_free(struct nrf_wifi_fmac_dev_ctx *fmac_ctx,
174 		unsigned int desc,
175 		unsigned char *ac);
176 
177 /** @} */
178 
179 #endif /* __FMAC_TX_H__ */
180