xref: /wlan-driver/qca-wifi-host-cmn/qdf/linux/src/i_qdf_nbuf_w.h (revision 5113495b16420b49004c444715d2daae2066e7dc)
1 /*
2  * Copyright (c) 2014-2021 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2021-2023 Qualcomm Innovation Center, Inc. All rights reserved.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for
6  * any purpose with or without fee is hereby granted, provided that the
7  * above copyright notice and this permission notice appear in all
8  * copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 /**
21  * DOC: i_qdf_nbuf_w.h
22  *
23  * This file provides platform specific nbuf API's.
24  * Included by i_qdf_nbuf.h and should not be included
25  * directly from other files.
26  */
27 
28 #ifndef _I_QDF_NBUF_W_H
29 #define _I_QDF_NBUF_W_H
30 
31 /**
32  * struct qdf_nbuf_cb - network buffer control block contents (skb->cb)
33  *                    - data passed between layers of the driver.
34  *
35  * Notes:
36  *   1. Hard limited to 48 bytes. Please count your bytes
37  *   2. The size of this structure has to be easily calculable and
38  *      consistently so: do not use any conditional compile flags
39  *   3. Split into a common part followed by a tx/rx overlay
40  *   4. There is only one extra frag, which represents the HTC/HTT header
41  *   5. "ext_cb_pt" must be the first member in both TX and RX unions
42  *      for the priv_cb_w since it must be at same offset for both
43  *      TX and RX union
44  *   6. "ipa.owned" bit must be first member in both TX and RX unions
45  *      for the priv_cb_m since it must be at same offset for both
46  *      TX and RX union.
47  *
48  * @paddr   : physical addressed retrieved by dma_map of nbuf->data
49  * @u: union of TX and RX member elements
50  * @u.rx.ext_cb_ptr: extended cb pointer
51  * @u.rx.fctx: ctx to handle special pkts defined by ftype
52  * @u.rx.rx_ctx_id: RX ring id
53  * @u.rx.fcs_err: fcs error in RX packet
54  * @u.rx.ipa_smmu_map: do IPA smmu map
55  * @u.rx.flow_idx_valid: is flow_idx_valid flag
56  * @u.rx.flow_idx_timeout: is flow_idx_timeout flag
57  * @u.rx.rsvd8: reserved bits
58  * @u.rx.num_elements_in_list: num of elements (nbufs) in the list
59  * @u.rx.trace: combined structure for DP and protocol trace
60  * @u.rx.trace.packet_stat: {NBUF_TX_PKT_[(HDD)|(TXRX_ENQUEUE)|(TXRX_DEQUEUE)|
61  *                       +          (TXRX)|(HTT)|(HTC)|(HIF)|(CE)|(FREE)]
62  * @u.rx.trace.dp_trace: flag (Datapath trace)
63  * @u.rx.trace.packet_track: RX_DATA packet
64  * @u.rx.trace.rsrvd: enable packet logging
65  *
66  * @u.rx.protocol_tag: protocol tag set by app for rcvd packet type
67  * @u.rx.flow_tag: flow tag set by application for 5 tuples rcvd
68  *
69  * @u.rx.hw_info: combined structure for HW info fields
70  * @u.rx.hw_info.desc_tlv_members.msdu_count: num of msdus
71  * @u.rx.hw_info.desc_tlv_members.fragment_flag: is this fragment mpdu
72  * @u.rx.hw_info.desc_tlv_members.flag_retry: is mpdu retry flag set
73  * @u.rx.hw_info.desc_tlv_members.flag_is_ampdu: is ampdu flag set
74  * @u.rx.hw_info.desc_tlv_members.bar_frame: is this bar frame
75  * @u.rx.hw_info.desc_tlv_members.pn_fields_contain_valid_info: pn valid
76  * @u.rx.hw_info.desc_tlv_members.is_raw_frame: is this raw frame
77  * @u.rx.hw_info.desc_tlv_members.more_fragment_flag: more fragment flag
78  * @u.rx.hw_info.desc_tlv_members.src_info: PPE VP number
79  * @u.rx.hw_info.desc_tlv_members.mpdu_qos_control_valid: is qos ctrl valid
80  * @u.rx.hw_info.desc_tlv_members.tid_val: tid value
81  *
82  * @u.rx.hw_info.desc_tlv_members.peer_id: peer id
83  * @u.rx.hw_info.desc_tlv_members.ml_peer_valid: is ml peer valid
84  * @u.rx.hw_info.desc_tlv_members.vdev_id: vdev id
85  * @u.rx.hw_info.desc_tlv_members.hw_link_id: link id of RX packet
86  * @u.rx.hw_info.desc_tlv_members.chip_id: chip id
87  * @u.rx.hw_info.desc_tlv_members.reserved2: reserved
88  *
89  * @u.rx.hw_info.desc_tlv_members.flag_chfrag_start: first fragment of msdu
90  * @u.rx.hw_info.desc_tlv_members.flag_chfrag_end: last fragment of msdu
91  * @u.rx.hw_info.desc_tlv_members.flag_chfrag_cont: msdu frag is continued
92  * @u.rx.hw_info.desc_tlv_members.msdu_len: msdu length
93  * @u.rx.hw_info.desc_tlv_members.flag_is_frag: msdu is frag
94  * @u.rx.hw_info.desc_tlv_members.flag_sa_valid: source address is valid
95  * @u.rx.hw_info.desc_tlv_members.flag_da_valid: dest address is valid
96  * @u.rx.hw_info.desc_tlv_members.flag_da_mcbc: is mcast/bcast msdu
97  * @u.rx.hw_info.desc_tlv_members.l3_hdr_pad_msb: l3 pad bytes
98  * @u.rx.hw_info.desc_tlv_members.tcp_udp_chksum_fail: tcp/udp checksum failed
99  * @u.rx.hw_info.desc_tlv_members.ip_chksum_fail: ip checksum failed
100  * @u.rx.hw_info.desc_tlv_members.fr_ds: FROM DS bit is set
101  * @u.rx.hw_info.desc_tlv_members.to_ds: TO DS bit is set
102  * @u.rx.hw_info.desc_tlv_members.intra_bss: this is intra-bss msdu
103  * @u.rx.hw_info.desc_tlv_members.rsvd4: reserved
104  *
105  * @u.rx.hw_info.desc_tlv_members.release_source_module: release source
106  * @u.rx.hw_info.desc_tlv_members.bm_action: bm action
107  * @u.rx.hw_info.desc_tlv_members.buffer_or_desc_type: buffer or desc
108  * @u.rx.hw_info.desc_tlv_members.return_buffer_manager: rbm value
109  * @u.rx.hw_info.desc_tlv_members.reserved_2a: reserved
110  * @u.rx.hw_info.desc_tlv_members.cache_id: cache_id
111  * @u.rx.hw_info.desc_tlv_members.cookie_conversion_status: cc status
112  * @u.rx.hw_info.desc_tlv_members.rxdma_push_reason: rxdma push reason
113  * @u.rx.hw_info.desc_tlv_members.rxdma_error_code: rxdma error code
114  * @u.rx.hw_info.desc_tlv_members.reo_push_reason: reo push reason
115  * @u.rx.hw_info.desc_tlv_members.reo_error_code: reo error code
116  * @u.rx.hw_info.desc_tlv_members.wbm_internal_error: wbm internal error
117  *
118  * @u.rx.hw_info.desc_info.mpdu_desc_info[2]: reo destination mpdu desc info
119  * @u.rx.hw_info.desc_info.msdu_desc_info: reo destination msdu desc info
120  * @u.rx.hw_info.desc_info.rx_error_code: wbm error codes
121  *
122  *
123  * @u.tx.ext_cb_ptr: extended cb pointer
124  * @u.tx.fctx: ctx to handle special pkts defined by ftype
125  * @u.tx.ftype: ftype
126  * @u.tx.xmit_type: xmit type of packet (MLD/Legacy)
127  * @u.tx.reserved: unused
128  * @u.tx.vdev_id: vdev_id
129  * @u.tx.len: len
130  * @u.tx.flags:
131  * @u.tx.flags.bits.flag_efrag:
132  * @u.tx.flags.bits.flag_nbuf:
133  * @u.tx.flags.bits.num:
134  * @u.tx.flags.bits.flag_chfrag_start:
135  * @u.tx.flags.bits.flag_chfrag_cont:
136  * @u.tx.flags.bits.flag_chfrag_end:
137  * @u.tx.flags.bits.flag_ext_header:
138  * @u.tx.flags.bits.is_critical:
139  * @u.tx.flags.u8:
140  * @u.tx.trace.packet_state:  {NBUF_TX_PKT_[(HDD)|(TXRX_ENQUEUE)|(TXRX_DEQUEUE)|
141  *			+          (TXRX)|(HTT)|(HTC)|(HIF)|(CE)|(FREE)]
142  * @u.tx.trace.is_packet_priv:
143  * @u.tx.trace.packet_track: {NBUF_TX_PKT_[(DATA)|(MGMT)]_TRACK}
144  * @u.tx.trace.to_fw: Flag to indicate send this packet to FW
145  * @u.tx.trace.htt2_frm: flag (high-latency path only)
146  * @u.tx.trace.proto_type: bitmap of NBUF_PKT_TRAC_TYPE[(EAPOL)|(DHCP)|
147  *			+ (MGMT_ACTION)] - 4 bits
148  * @u.tx.trace.dp_trace: flag (Datapath trace)
149  * @u.tx.trace.is_bcast: flag (Broadcast packet)
150  * @u.tx.trace.is_mcast: flag (Multicast packet)
151  * @u.tx.trace.packet_type: flag (Packet type)
152  * @u.tx.trace.print: enable packet logging
153  *
154  * @u.tx.vaddr: virtual address of ~
155  * @u.tx.paddr: physical/DMA address of ~
156  */
157 
158 struct qdf_nbuf_cb {
159 	/* common */
160 	qdf_paddr_t paddr; /* of skb->data */
161 	/* valid only in one direction */
162 	union {
163 		/* Note: MAX: 40 bytes */
164 		struct {
165 			void *ext_cb_ptr;
166 			void *fctx;
167 			uint16_t ftype:4,
168 				 rx_ctx_id:4,
169 				 fcs_err:1,
170 				 ipa_smmu_map:1,
171 				 flow_idx_valid:1,
172 				 flow_idx_timeout:1,
173 				 rsvd8:4;
174 			uint8_t num_elements_in_list;
175 			union {
176 				uint8_t packet_state;
177 				uint8_t dp_trace:1,
178 					packet_track:3,
179 					rsrvd:4;
180 			} trace;
181 			uint16_t protocol_tag;
182 			uint16_t flow_tag;
183 			union {
184 				struct {
185 					/* do not re-arrange the fields in
186 					 * the below 3 uint32_t words as
187 					 * they map exactly to the desc info
188 					 */
189 #ifndef BIG_ENDIAN_HOST
190 					/* 1st word rx_mpdu_desc_info */
191 					uint32_t msdu_count:8,
192 						 fragment_flag:1,
193 						 flag_retry:1,
194 						 flag_is_ampdu:1,
195 						 bar_frame:1,
196 						 pn_fields_contain_valid_info:1,
197 						 is_raw_frame:1,
198 						 more_fragment_flag:1,
199 						 src_info:12,
200 						 mpdu_qos_control_valid:1,
201 						 tid_val:4;
202 #else
203 					uint32_t tid_val:4,
204 						 mpdu_qos_control_valid:1,
205 						 src_info:12,
206 						 more_fragment_flag:1,
207 						 is_raw_frame:1,
208 						 pn_fields_contain_valid_info:1,
209 						 bar_frame:1,
210 						 flag_is_ampdu:1,
211 						 flag_retry:1,
212 						 fragment_flag:1,
213 						 msdu_count:8;
214 #endif
215 					/* 2nd word rx_mpdu_desc_info */
216 					uint32_t peer_id:14,
217 						 vdev_id:8,
218 						 hw_link_id:4,
219 						 chip_id:3,
220 						 reserved2:3;
221 #ifndef BIG_ENDIAN_HOST
222 					/* 1st word of rx_msdu_desc_info */
223 					uint32_t flag_chfrag_start:1,
224 						 flag_chfrag_end:1,
225 						 flag_chfrag_cont:1,
226 						 msdu_len:14,
227 						 flag_is_frag:1,
228 						 flag_sa_valid:1,
229 						 flag_da_valid:1,
230 						 flag_da_mcbc:1,
231 						 l3_hdr_pad_msb:1,
232 						 tcp_udp_chksum_fail:1,
233 						 ip_chksum_fail:1,
234 						 fr_ds:1,
235 						 to_ds:1,
236 						 intra_bss:1,
237 						 rsvd4:5;
238 					uint32_t release_source_module:3,
239 						 bm_action:3,
240 						 buffer_or_desc_type:3,
241 						 return_buffer_manager:4,
242 						 reserved_2a:2,
243 						 cache_id:1,
244 						 cookie_conversion_status:1,
245 						 rxdma_push_reason:2,
246 						 rxdma_error_code:5,
247 						 reo_push_reason:2,
248 						 reo_error_code:5,
249 						 wbm_internal_error:1;
250 #else
251 					uint32_t rsvd4:5,
252 						 intra_bss:1,
253 						 to_ds:1,
254 						 fr_ds:1,
255 						 ip_chksum_fail:1,
256 						 tcp_udp_chksum_fail:1,
257 						 l3_hdr_pad_msb:1,
258 						 flag_da_mcbc:1,
259 						 flag_da_valid:1,
260 						 flag_sa_valid:1,
261 						 flag_is_frag:1,
262 						 msdu_len:14,
263 						 flag_chfrag_cont:1,
264 						 flag_chfrag_end:1,
265 						 flag_chfrag_start:1;
266 					uint32_t wbm_internal_error:1,
267 						 reo_error_code:5,
268 						 reo_push_reason:2,
269 						 rxdma_error_code:5,
270 						 rxdma_push_reason:2,
271 						 cookie_conversion_status:1,
272 						 cache_id:1,
273 						 reserved_2a:2,
274 						 return_buffer_manager:4,
275 						 buffer_or_desc_type:3,
276 						 bm_action:3,
277 						 release_source_module:3;
278 #endif
279 				} desc_tlv_members;
280 				struct {
281 					uint32_t mpdu_desc_info[2];
282 					uint32_t msdu_desc_info;
283 					uint32_t rx_error_codes;
284 				} desc_info;
285 			} hw_info;
286 		} rx;
287 
288 		/* Note: MAX: 40 bytes */
289 		struct {
290 			void *ext_cb_ptr;
291 			void *fctx;
292 			uint8_t ftype:4,
293 				xmit_type:1,
294 				reserved:3;
295 			uint8_t vdev_id;
296 			uint16_t len;
297 			union {
298 				struct {
299 					uint8_t flag_efrag:1,
300 						flag_nbuf:1,
301 						num:1,
302 						flag_chfrag_start:1,
303 						flag_chfrag_cont:1,
304 						flag_chfrag_end:1,
305 						flag_ext_header:1,
306 						is_critical:1;
307 				} bits;
308 				uint8_t u8;
309 			} flags;
310 			struct {
311 				uint8_t packet_state:7,
312 					is_packet_priv:1;
313 				uint8_t packet_track:3,
314 					to_fw:1,
315 					/* used only for hl */
316 					htt2_frm:1,
317 					proto_type:3;
318 				uint8_t dp_trace:1,
319 					is_bcast:1,
320 					is_mcast:1,
321 					packet_type:4,
322 					print:1;
323 			} trace;
324 			unsigned char *vaddr;
325 			qdf_paddr_t paddr;
326 		} tx;
327 	} u;
328 }; /* struct qdf_nbuf_cb: MAX 48 bytes */
329 
330 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0))
331 QDF_COMPILE_TIME_ASSERT(qdf_nbuf_cb_size,
332 			(sizeof(struct qdf_nbuf_cb)) <=
333 			sizeof_field(struct sk_buff, cb));
334 #else
335 QDF_COMPILE_TIME_ASSERT(qdf_nbuf_cb_size,
336 			(sizeof(struct qdf_nbuf_cb)) <=
337 			FIELD_SIZEOF(struct sk_buff, cb));
338 #endif
339 
340 /*
341  *  access macros to qdf_nbuf_cb
342  *  Note: These macros can be used as L-values as well as R-values.
343  *        When used as R-values, they effectively function as "get" macros
344  *        When used as L_values, they effectively function as "set" macros
345  */
346 
347 #define QDF_NBUF_CB_PADDR(skb) \
348 	(((struct qdf_nbuf_cb *)((skb)->cb))->paddr.dma_addr)
349 
350 #define QDF_NBUF_CB_RX_CTX_ID(skb) \
351 	(((struct qdf_nbuf_cb *)((skb)->cb))->u.rx.rx_ctx_id)
352 #define QDF_NBUF_CB_RX_NUM_ELEMENTS_IN_LIST(skb) \
353 		(((struct qdf_nbuf_cb *)((skb)->cb))->u.rx.num_elements_in_list)
354 
355 #define QDF_NBUF_CB_RX_PACKET_STATE(skb)\
356 	(((struct qdf_nbuf_cb *)((skb)->cb))->u.rx.trace.packet_state)
357 #define QDF_NBUF_CB_RX_DP_TRACE(skb) \
358 	(((struct qdf_nbuf_cb *)((skb)->cb))->u.rx.trace.dp_trace)
359 
360 #define QDF_NBUF_CB_RX_FTYPE(skb) \
361 	(((struct qdf_nbuf_cb *)((skb)->cb))->u.rx.ftype)
362 
363 #define QDF_NBUF_CB_PKT_XMIT_TYPE(skb) \
364 	(((struct qdf_nbuf_cb *)((skb)->cb))->u.tx.xmit_type)
365 
366 #define QDF_NBUF_CB_RX_CHFRAG_START(skb) \
367 	(((struct qdf_nbuf_cb *) \
368 	((skb)->cb))->u.rx.hw_info.desc_tlv_members.flag_chfrag_start)
369 #define QDF_NBUF_CB_RX_CHFRAG_CONT(skb) \
370 	(((struct qdf_nbuf_cb *) \
371 	((skb)->cb))->u.rx.hw_info.desc_tlv_members.flag_chfrag_cont)
372 #define QDF_NBUF_CB_RX_CHFRAG_END(skb) \
373 		(((struct qdf_nbuf_cb *) \
374 		((skb)->cb))->u.rx.hw_info.desc_tlv_members.flag_chfrag_end)
375 
376 #define QDF_NBUF_CB_RX_DA_MCBC(skb) \
377 	(((struct qdf_nbuf_cb *) \
378 	((skb)->cb))->u.rx.hw_info.desc_tlv_members.flag_da_mcbc)
379 
380 #define QDF_NBUF_CB_RX_L3_PAD_MSB(skb) \
381 	(((struct qdf_nbuf_cb *) \
382 	((skb)->cb))->u.rx.hw_info.desc_tlv_members.l3_hdr_pad_msb)
383 
384 #define QDF_NBUF_CB_RX_DA_VALID(skb) \
385 	(((struct qdf_nbuf_cb *) \
386 	((skb)->cb))->u.rx.hw_info.desc_tlv_members.flag_da_valid)
387 
388 #define QDF_NBUF_CB_RX_SA_VALID(skb) \
389 	(((struct qdf_nbuf_cb *) \
390 	((skb)->cb))->u.rx.hw_info.desc_tlv_members.flag_sa_valid)
391 
392 #define QDF_NBUF_CB_RX_RETRY_FLAG(skb) \
393 	(((struct qdf_nbuf_cb *) \
394 	((skb)->cb))->u.rx.hw_info.desc_tlv_members.flag_retry)
395 
396 #define QDF_NBUF_CB_RX_RAW_FRAME(skb) \
397 	(((struct qdf_nbuf_cb *) \
398 	((skb)->cb))->u.rx.hw_info.desc_tlv_members.is_raw_frame)
399 
400 #define QDF_NBUF_CB_RX_FROM_DS(skb) \
401 	(((struct qdf_nbuf_cb *) \
402 	  ((skb)->cb))->u.rx.hw_info.desc_tlv_members.fr_ds)
403 
404 #define QDF_NBUF_CB_RX_TO_DS(skb) \
405 	(((struct qdf_nbuf_cb *) \
406 	  ((skb)->cb))->u.rx.hw_info.desc_tlv_members.to_ds)
407 
408 #define QDF_NBUF_CB_RX_IS_FRAG(skb) \
409 	(((struct qdf_nbuf_cb *) \
410 	((skb)->cb))->u.rx.hw_info.desc_tlv_members.flag_is_frag)
411 
412 #define QDF_NBUF_CB_RX_FCS_ERR(skb) \
413 	(((struct qdf_nbuf_cb *) \
414 	  ((skb)->cb))->u.rx.fcs_err)
415 
416 #define QDF_NBUF_CB_RX_MSDU_DESC_INFO(skb) \
417 	(((struct qdf_nbuf_cb *) \
418 	  ((skb)->cb))->u.rx.hw_info.desc_info.msdu_desc_info)
419 
420 #define QDF_NBUF_CB_RX_MPDU_DESC_INFO(skb) \
421 	(((struct qdf_nbuf_cb *) \
422 	  ((skb)->cb))->u.rx.hw_info.desc_info.mpdu_desc_info)
423 
424 #define QDF_NBUF_CB_RX_MPDU_DESC_INFO_1(skb) \
425 	(((struct qdf_nbuf_cb *) \
426 	  ((skb)->cb))->u.rx.hw_info.desc_info.mpdu_desc_info[0])
427 
428 #define QDF_NBUF_CB_RX_MPDU_DESC_INFO_2(skb) \
429 	(((struct qdf_nbuf_cb *) \
430 	  ((skb)->cb))->u.rx.hw_info.desc_info.mpdu_desc_info[1])
431 
432 #define QDF_NBUF_CB_RX_ERROR_CODE_INFO(skb) \
433 	(((struct qdf_nbuf_cb *) \
434 	  ((skb)->cb))->u.rx.hw_info.desc_info.rx_error_codes)
435 
436 #define QDF_NBUF_CB_RX_PEER_ID(skb) \
437 	(((struct qdf_nbuf_cb *) \
438 	  ((skb)->cb))->u.rx.hw_info.desc_tlv_members.peer_id)
439 
440 #define QDF_NBUF_CB_RX_VDEV_ID(skb) \
441 	(((struct qdf_nbuf_cb *) \
442 	  ((skb)->cb))->u.rx.hw_info.desc_tlv_members.vdev_id)
443 
444 #define QDF_NBUF_CB_RX_PKT_LEN(skb) \
445 	(((struct qdf_nbuf_cb *) \
446 	  ((skb)->cb))->u.rx.hw_info.desc_tlv_members.msdu_len)
447 
448 #define QDF_NBUF_CB_RX_TID_VAL(skb) \
449 	(((struct qdf_nbuf_cb *) \
450 	  ((skb)->cb))->u.rx.hw_info.desc_tlv_members.tid_val)
451 
452 #define QDF_NBUF_CB_RX_NUM_ELEMENTS_IN_LIST(skb) \
453 	(((struct qdf_nbuf_cb *)((skb)->cb))->u.rx.num_elements_in_list)
454 
455 #define QDF_NBUF_UPDATE_TX_PKT_COUNT(skb, PACKET_STATE) \
456 	qdf_nbuf_set_state(skb, PACKET_STATE)
457 
458 #define QDF_NBUF_CB_TX_FTYPE(skb) \
459 	(((struct qdf_nbuf_cb *)((skb)->cb))->u.tx.ftype)
460 
461 #define QDF_NBUF_CB_TX_EXTRA_FRAG_LEN(skb) \
462 	(((struct qdf_nbuf_cb *)((skb)->cb))->u.tx.len)
463 #define QDF_NBUF_CB_TX_VDEV_CTX(skb) \
464 		(((struct qdf_nbuf_cb *)((skb)->cb))->u.tx.vdev_id)
465 
466 /* Tx Flags Accessor Macros*/
467 #define QDF_NBUF_CB_TX_EXTRA_FRAG_WORDSTR_EFRAG(skb) \
468 	(((struct qdf_nbuf_cb *) \
469 		((skb)->cb))->u.tx.flags.bits.flag_efrag)
470 #define QDF_NBUF_CB_TX_EXTRA_FRAG_WORDSTR_NBUF(skb) \
471 	(((struct qdf_nbuf_cb *) \
472 		((skb)->cb))->u.tx.flags.bits.flag_nbuf)
473 #define QDF_NBUF_CB_TX_NUM_EXTRA_FRAGS(skb) \
474 	(((struct qdf_nbuf_cb *)((skb)->cb))->u.tx.flags.bits.num)
475 #define QDF_NBUF_CB_TX_EXTRA_FRAG_FLAGS_CHFRAG_START(skb) \
476 	(((struct qdf_nbuf_cb *) \
477 	((skb)->cb))->u.tx.flags.bits.flag_chfrag_start)
478 #define QDF_NBUF_CB_TX_EXTRA_FRAG_FLAGS_CHFRAG_CONT(skb) \
479 	(((struct qdf_nbuf_cb *) \
480 	((skb)->cb))->u.tx.flags.bits.flag_chfrag_cont)
481 #define QDF_NBUF_CB_TX_EXTRA_FRAG_FLAGS_CHFRAG_END(skb) \
482 		(((struct qdf_nbuf_cb *) \
483 		((skb)->cb))->u.tx.flags.bits.flag_chfrag_end)
484 #define QDF_NBUF_CB_TX_EXTRA_FRAG_FLAGS_EXT_HEADER(skb) \
485 		(((struct qdf_nbuf_cb *) \
486 		((skb)->cb))->u.tx.flags.bits.flag_ext_header)
487 #define QDF_NBUF_CB_TX_EXTRA_FRAG_WORDSTR_FLAGS(skb) \
488 	(((struct qdf_nbuf_cb *)((skb)->cb))->u.tx.flags.u8)
489 
490 #define QDF_NBUF_CB_TX_EXTRA_IS_CRITICAL(skb) \
491 	(((struct qdf_nbuf_cb *)((skb)->cb))->u.tx.flags.bits.is_critical)
492 /* End of Tx Flags Accessor Macros */
493 
494 /* Tx trace accessor macros */
495 #define QDF_NBUF_CB_TX_PACKET_STATE(skb)\
496 	(((struct qdf_nbuf_cb *) \
497 		((skb)->cb))->u.tx.trace.packet_state)
498 
499 #define QDF_NBUF_CB_TX_IS_PACKET_PRIV(skb) \
500 	(((struct qdf_nbuf_cb *) \
501 		((skb)->cb))->u.tx.trace.is_packet_priv)
502 
503 #define QDF_NBUF_CB_TX_PACKET_TRACK(skb)\
504 	(((struct qdf_nbuf_cb *) \
505 		((skb)->cb))->u.tx.trace.packet_track)
506 
507 #define QDF_NBUF_CB_TX_PACKET_TO_FW(skb)\
508 	(((struct qdf_nbuf_cb *) \
509 		((skb)->cb))->u.tx.trace.to_fw)
510 
511 #define QDF_NBUF_CB_RX_PACKET_TRACK(skb)\
512 		(((struct qdf_nbuf_cb *) \
513 			((skb)->cb))->u.rx.trace.packet_track)
514 
515 #define QDF_NBUF_CB_TX_PROTO_TYPE(skb)\
516 	(((struct qdf_nbuf_cb *) \
517 		((skb)->cb))->u.tx.trace.proto_type)
518 
519 #define QDF_NBUF_CB_TX_DP_TRACE(skb)\
520 	(((struct qdf_nbuf_cb *)((skb)->cb))->u.tx.trace.dp_trace)
521 
522 #define QDF_NBUF_CB_DP_TRACE_PRINT(skb)	\
523 	(((struct qdf_nbuf_cb *)((skb)->cb))->u.tx.trace.print)
524 
525 #define QDF_NBUF_CB_TX_HL_HTT2_FRM(skb)	\
526 	(((struct qdf_nbuf_cb *)((skb)->cb))->u.tx.trace.htt2_frm)
527 
528 #define QDF_NBUF_CB_GET_IS_BCAST(skb)\
529 	(((struct qdf_nbuf_cb *)((skb)->cb))->u.tx.trace.is_bcast)
530 
531 #define QDF_NBUF_CB_GET_IS_MCAST(skb)\
532 	(((struct qdf_nbuf_cb *)((skb)->cb))->u.tx.trace.is_mcast)
533 
534 #define QDF_NBUF_CB_GET_PACKET_TYPE(skb)\
535 	(((struct qdf_nbuf_cb *)((skb)->cb))->u.tx.trace.packet_type)
536 
537 #define QDF_NBUF_CB_SET_BCAST(skb) \
538 	(((struct qdf_nbuf_cb *) \
539 		((skb)->cb))->u.tx.trace.is_bcast = true)
540 
541 #define QDF_NBUF_CB_SET_MCAST(skb) \
542 	(((struct qdf_nbuf_cb *) \
543 		((skb)->cb))->u.tx.trace.is_mcast = true)
544 /* End of Tx trace accessor macros */
545 
546 #define QDF_NBUF_CB_TX_EXTRA_FRAG_VADDR(skb) \
547 	(((struct qdf_nbuf_cb *)((skb)->cb))->u.tx.vaddr)
548 #define QDF_NBUF_CB_TX_EXTRA_FRAG_PADDR(skb) \
549 	(((struct qdf_nbuf_cb *)((skb)->cb))->u.tx.paddr.dma_addr)
550 
551 /* assume the OS provides a single fragment */
552 #define __qdf_nbuf_get_num_frags(skb)		   \
553 	(QDF_NBUF_CB_TX_NUM_EXTRA_FRAGS(skb) + 1)
554 
555 #define __qdf_nbuf_reset_num_frags(skb) \
556 	(QDF_NBUF_CB_TX_NUM_EXTRA_FRAGS(skb) = 0)
557 
558 /* ext_cb accessor macros and internal API's */
559 #define QDF_NBUF_CB_EXT_CB(skb) \
560 	(((struct qdf_nbuf_cb *)((skb)->cb))->u.tx.ext_cb_ptr)
561 
562 #define __qdf_nbuf_set_ext_cb(skb, ref) \
563 	do { \
564 		QDF_NBUF_CB_EXT_CB((skb)) = (ref); \
565 	} while (0)
566 
567 #define __qdf_nbuf_get_ext_cb(skb) \
568 	QDF_NBUF_CB_EXT_CB((skb))
569 
570 /* fctx accessor macros and internal API's*/
571 #define QDF_NBUF_CB_RX_FCTX(skb) \
572 	(((struct qdf_nbuf_cb *)((skb)->cb))->u.rx.fctx)
573 
574 #define QDF_NBUF_CB_TX_FCTX(skb) \
575 	(((struct qdf_nbuf_cb *)((skb)->cb))->u.tx.fctx)
576 
577 #define QDF_NBUF_CB_RX_INTRA_BSS(skb) \
578 	(((struct qdf_nbuf_cb *) \
579 	  ((skb)->cb))->u.rx.hw_info.desc_tlv_members.intra_bss)
580 
581 #define __qdf_nbuf_set_rx_fctx_type(skb, ctx, type) \
582 	do { \
583 		QDF_NBUF_CB_RX_FCTX((skb)) = (ctx); \
584 		QDF_NBUF_CB_RX_FTYPE((skb)) = (type); \
585 	} while (0)
586 
587 #define __qdf_nbuf_get_rx_fctx(skb) \
588 		 QDF_NBUF_CB_RX_FCTX((skb))
589 
590 #define __qdf_nbuf_set_intra_bss(skb, val) \
591 	((QDF_NBUF_CB_RX_INTRA_BSS((skb))) = val)
592 
593 #define __qdf_nbuf_is_intra_bss(skb) \
594 	(QDF_NBUF_CB_RX_INTRA_BSS((skb)))
595 
596 #define __qdf_nbuf_set_tx_fctx_type(skb, ctx, type) \
597 	do { \
598 		QDF_NBUF_CB_TX_FCTX((skb)) = (ctx); \
599 		QDF_NBUF_CB_TX_FTYPE((skb)) = (type); \
600 	} while (0)
601 
602 #define __qdf_nbuf_get_tx_fctx(skb) \
603 		 QDF_NBUF_CB_TX_FCTX((skb))
604 
605 #define QDF_NBUF_CB_RX_PROTOCOL_TAG(skb) \
606 		(((struct qdf_nbuf_cb *)((skb)->cb))->u.rx.protocol_tag)
607 
608 #define __qdf_nbuf_set_rx_protocol_tag(skb, val) \
609 		((QDF_NBUF_CB_RX_PROTOCOL_TAG((skb))) = val)
610 
611 #define __qdf_nbuf_get_rx_protocol_tag(skb) \
612 		(QDF_NBUF_CB_RX_PROTOCOL_TAG((skb)))
613 
614 #define QDF_NBUF_CB_RX_FLOW_TAG(skb) \
615 		(((struct qdf_nbuf_cb *)((skb)->cb))->u.rx.flow_tag)
616 
617 #define __qdf_nbuf_set_rx_flow_tag(skb, val) \
618 		((QDF_NBUF_CB_RX_FLOW_TAG((skb))) = val)
619 
620 #define __qdf_nbuf_get_rx_flow_tag(skb) \
621 		(QDF_NBUF_CB_RX_FLOW_TAG((skb)))
622 
623 #define QDF_NBUF_CB_RX_FLOW_IDX_VALID(skb) \
624 		(((struct qdf_nbuf_cb *) \
625 		((skb)->cb))->u.rx.flow_idx_valid)
626 
627 #define __qdf_nbuf_set_rx_flow_idx_valid(skb, val) \
628 		((QDF_NBUF_CB_RX_FLOW_IDX_VALID((skb))) = val)
629 
630 #define __qdf_nbuf_get_rx_flow_idx_valid(skb) \
631 		(QDF_NBUF_CB_RX_FLOW_IDX_VALID((skb)))
632 
633 #define QDF_NBUF_CB_RX_FLOW_IDX_TIMEOUT(skb) \
634 		(((struct qdf_nbuf_cb *) \
635 		((skb)->cb))->u.rx.flow_idx_timeout)
636 
637 #define QDF_NBUF_CB_RX_HW_LINK_ID(skb) \
638 		(((struct qdf_nbuf_cb *) \
639 		((skb)->cb))->u.rx.hw_info.desc_tlv_members.hw_link_id)
640 
641 #define __qdf_nbuf_set_rx_flow_idx_timeout(skb, val) \
642 		((QDF_NBUF_CB_RX_FLOW_IDX_TIMEOUT((skb))) = val)
643 
644 #define __qdf_nbuf_get_rx_flow_idx_timeout(skb) \
645 		(QDF_NBUF_CB_RX_FLOW_IDX_TIMEOUT((skb)))
646 
647 #define  QDF_NBUF_CB_RX_PACKET_IPA_SMMU_MAP(skb) \
648 	 (((struct qdf_nbuf_cb *)((skb)->cb))->u.rx.ipa_smmu_map)
649 
650 #define __qdf_nbuf_data_attr_get(skb) (0)
651 #define __qdf_nbuf_data_attr_set(skb, data_attr)
652 
653 /**
654  * __qdf_nbuf_map_nbytes_single() - map nbytes
655  * @osdev: os device
656  * @buf: buffer
657  * @dir: direction
658  * @nbytes: number of bytes
659  *
660  * Return: QDF_STATUS
661  */
662 #ifdef A_SIMOS_DEVHOST
__qdf_nbuf_map_nbytes_single(qdf_device_t osdev,struct sk_buff * buf,qdf_dma_dir_t dir,int nbytes)663 static inline QDF_STATUS __qdf_nbuf_map_nbytes_single(
664 		qdf_device_t osdev, struct sk_buff *buf,
665 		qdf_dma_dir_t dir, int nbytes)
666 {
667 	qdf_dma_addr_t paddr;
668 
669 	QDF_NBUF_CB_PADDR(buf) = paddr = buf->data;
670 	return QDF_STATUS_SUCCESS;
671 }
672 #else
__qdf_nbuf_map_nbytes_single(qdf_device_t osdev,struct sk_buff * buf,qdf_dma_dir_t dir,int nbytes)673 static inline QDF_STATUS __qdf_nbuf_map_nbytes_single(
674 		qdf_device_t osdev, struct sk_buff *buf,
675 		qdf_dma_dir_t dir, int nbytes)
676 {
677 	qdf_dma_addr_t paddr;
678 	QDF_STATUS ret;
679 
680 	/* assume that the OS only provides a single fragment */
681 	QDF_NBUF_CB_PADDR(buf) = paddr =
682 		dma_map_single(osdev->dev, buf->data,
683 			       nbytes, __qdf_dma_dir_to_os(dir));
684 	ret =  dma_mapping_error(osdev->dev, paddr) ?
685 		QDF_STATUS_E_FAULT : QDF_STATUS_SUCCESS;
686 	if (QDF_IS_STATUS_SUCCESS(ret))
687 		__qdf_record_nbuf_nbytes(__qdf_nbuf_get_end_offset(buf),
688 					 dir, true);
689 	return ret;
690 }
691 #endif
692 /**
693  * __qdf_nbuf_unmap_nbytes_single() - unmap nbytes
694  * @osdev: os device
695  * @buf: buffer
696  * @dir: direction
697  * @nbytes: number of bytes
698  *
699  * Return: none
700  */
701 #if defined(A_SIMOS_DEVHOST)
702 static inline void
__qdf_nbuf_unmap_nbytes_single(qdf_device_t osdev,struct sk_buff * buf,qdf_dma_dir_t dir,int nbytes)703 __qdf_nbuf_unmap_nbytes_single(qdf_device_t osdev, struct sk_buff *buf,
704 			       qdf_dma_dir_t dir, int nbytes)
705 {
706 }
707 #else
708 static inline void
__qdf_nbuf_unmap_nbytes_single(qdf_device_t osdev,struct sk_buff * buf,qdf_dma_dir_t dir,int nbytes)709 __qdf_nbuf_unmap_nbytes_single(qdf_device_t osdev, struct sk_buff *buf,
710 			       qdf_dma_dir_t dir, int nbytes)
711 {
712 	qdf_dma_addr_t paddr = QDF_NBUF_CB_PADDR(buf);
713 
714 	if (qdf_likely(paddr)) {
715 		__qdf_record_nbuf_nbytes(
716 			__qdf_nbuf_get_end_offset(buf), dir, false);
717 		dma_unmap_single(osdev->dev, paddr, nbytes,
718 				 __qdf_dma_dir_to_os(dir));
719 		return;
720 	}
721 }
722 #endif
723 
724 /**
725  * __qdf_nbuf_reset() - reset the buffer data and pointer
726  * @skb: Network buf instance
727  * @reserve: reserve
728  * @align: align
729  *
730  * Return: none
731  */
732 static inline void
__qdf_nbuf_reset(struct sk_buff * skb,int reserve,int align)733 __qdf_nbuf_reset(struct sk_buff *skb, int reserve, int align)
734 {
735 	int offset;
736 
737 	skb_push(skb, skb_headroom(skb));
738 	skb_put(skb, skb_tailroom(skb));
739 	memset(skb->data, 0x0, skb->len);
740 	skb_trim(skb, 0);
741 	skb_reserve(skb, NET_SKB_PAD);
742 	memset(skb->cb, 0x0, sizeof(skb->cb));
743 
744 	/*
745 	 * The default is for netbuf fragments to be interpreted
746 	 * as wordstreams rather than bytestreams.
747 	 */
748 	QDF_NBUF_CB_TX_EXTRA_FRAG_WORDSTR_EFRAG(skb) = 1;
749 	QDF_NBUF_CB_TX_EXTRA_FRAG_WORDSTR_NBUF(skb) = 1;
750 
751 	/*
752 	 * Align & make sure that the tail & data are adjusted properly
753 	 */
754 
755 	if (align) {
756 		offset = ((unsigned long)skb->data) % align;
757 		if (offset)
758 			skb_reserve(skb, align - offset);
759 	}
760 
761 	skb_reserve(skb, reserve);
762 }
763 
764 /**
765  * __qdf_nbuf_len() - return the amount of valid data in the skb
766  * @skb: Pointer to network buffer
767  *
768  * This API returns the amount of valid data in the skb, If there are frags
769  * then it returns total length.
770  *
771  * Return: network buffer length
772  */
__qdf_nbuf_len(struct sk_buff * skb)773 static inline size_t __qdf_nbuf_len(struct sk_buff *skb)
774 {
775 	int i, extra_frag_len = 0;
776 
777 	i = QDF_NBUF_CB_TX_NUM_EXTRA_FRAGS(skb);
778 	if (i > 0)
779 		extra_frag_len = QDF_NBUF_CB_TX_EXTRA_FRAG_LEN(skb);
780 
781 	return extra_frag_len + skb->len;
782 }
783 
784 /**
785  * __qdf_nbuf_num_frags_init() - init extra frags
786  * @skb: sk buffer
787  *
788  * Return: none
789  */
790 static inline
__qdf_nbuf_num_frags_init(struct sk_buff * skb)791 void __qdf_nbuf_num_frags_init(struct sk_buff *skb)
792 {
793 	QDF_NBUF_CB_TX_NUM_EXTRA_FRAGS(skb) = 0;
794 }
795 
796 /**
797  * qdf_nbuf_cb_update_vdev_id() - update vdev id in skb cb
798  * @skb: skb pointer whose cb is updated with vdev id information
799  * @vdev_id: vdev id to be updated in cb
800  *
801  * Return: void
802  */
803 static inline void
qdf_nbuf_cb_update_vdev_id(struct sk_buff * skb,uint8_t vdev_id)804 qdf_nbuf_cb_update_vdev_id(struct sk_buff *skb, uint8_t vdev_id)
805 {
806 	/* Does not apply to WIN */
807 }
808 
809 /**
810  * __qdf_nbuf_push_head() - Push data in the front
811  * @skb: Pointer to network buffer
812  * @size: size to be pushed
813  *
814  * Return: New data pointer of this buf after data has been pushed,
815  *         or NULL if there is not enough room in this buf.
816  */
__qdf_nbuf_push_head(struct sk_buff * skb,size_t size)817 static inline uint8_t *__qdf_nbuf_push_head(struct sk_buff *skb, size_t size)
818 {
819 	return skb_push(skb, size);
820 }
821 
822 /**
823  * __qdf_nbuf_pull_head() - pull data out from the front
824  * @skb: Pointer to network buffer
825  * @size: size to be popped
826  *
827  * Return: New data pointer of this buf after data has been popped,
828  * or NULL if there is not sufficient data to pull.
829  */
__qdf_nbuf_pull_head(struct sk_buff * skb,size_t size)830 static inline uint8_t *__qdf_nbuf_pull_head(struct sk_buff *skb, size_t size)
831 {
832 	return skb_pull(skb, size);
833 }
834 
qdf_nbuf_init_replenish_timer(void)835 static inline void qdf_nbuf_init_replenish_timer(void) {}
qdf_nbuf_deinit_replenish_timer(void)836 static inline void qdf_nbuf_deinit_replenish_timer(void) {}
837 
838 /**
839  * __qdf_nbuf_dma_inv_range() - nbuf invalidate
840  * @buf_start: from
841  * @buf_end: to address to invalidate
842  *
843  * Return: none
844  */
845 #if (defined(__LINUX_ARM_ARCH__) && !defined(DP_NO_CACHE_DESC_SUPPORT))
846 static inline void
__qdf_nbuf_dma_inv_range(const void * buf_start,const void * buf_end)847 __qdf_nbuf_dma_inv_range(const void *buf_start, const void *buf_end)
848 {
849 	dmac_inv_range(buf_start, buf_end);
850 }
851 
852 static inline void
__qdf_nbuf_dma_inv_range_no_dsb(const void * buf_start,const void * buf_end)853 __qdf_nbuf_dma_inv_range_no_dsb(const void *buf_start, const void *buf_end)
854 {
855 #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 89)
856 	dmac_inv_range_no_dsb(buf_start, buf_end);
857 #else
858 	dmac_inv_range(buf_start, buf_end);
859 #endif
860 }
861 
862 static inline void
__qdf_nbuf_dma_clean_range_no_dsb(const void * buf_start,const void * buf_end)863 __qdf_nbuf_dma_clean_range_no_dsb(const void *buf_start, const void *buf_end)
864 {
865 #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 89)
866 	dmac_clean_range_no_dsb(buf_start, buf_end);
867 #else
868 	dmac_clean_range(buf_start, buf_end);
869 #endif
870 }
871 
872 static inline void
__qdf_dsb(void)873 __qdf_dsb(void)
874 {
875 #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 89)
876 	dsb(st);
877 #endif
878 }
879 
880 static inline void
__qdf_nbuf_dma_clean_range(const void * buf_start,const void * buf_end)881 __qdf_nbuf_dma_clean_range(const void *buf_start, const void *buf_end)
882 {
883 	dmac_clean_range(buf_start, buf_end);
884 }
885 #elif defined(__LINUX_MIPS32_ARCH__) || defined(__LINUX_MIPS64_ARCH__)
886 static inline void
__qdf_nbuf_dma_inv_range(const void * buf_start,const void * buf_end)887 __qdf_nbuf_dma_inv_range(const void *buf_start, const void *buf_end)
888 {
889 	dma_cache_inv((unsigned long)buf_start,
890 		      (unsigned long)(buf_end - buf_start));
891 }
892 
893 static inline void
__qdf_nbuf_dma_inv_range_no_dsb(const void * buf_start,const void * buf_end)894 __qdf_nbuf_dma_inv_range_no_dsb(const void *buf_start, const void *buf_end)
895 {
896 	dma_cache_inv((unsigned long)buf_start,
897 		      (unsigned long)(buf_end - buf_start));
898 }
899 
900 static inline void
__qdf_nbuf_dma_clean_range_no_dsb(const void * buf_start,const void * buf_end)901 __qdf_nbuf_dma_clean_range_no_dsb(const void *buf_start, const void *buf_end)
902 {
903 	dmac_cache_wback((unsigned long)buf_start,
904 			 (unsigned long)(buf_end - buf_start));
905 }
906 
907 static inline void
__qdf_dsb(void)908 __qdf_dsb(void)
909 {
910 }
911 
912 static inline void
__qdf_nbuf_dma_clean_range(const void * buf_start,const void * buf_end)913 __qdf_nbuf_dma_clean_range(const void *buf_start, const void *buf_end)
914 {
915 	dma_cache_wback((unsigned long)buf_start,
916 			(unsigned long)(buf_end - buf_start));
917 }
918 #else
919 static inline void
__qdf_nbuf_dma_inv_range(const void * buf_start,const void * buf_end)920 __qdf_nbuf_dma_inv_range(const void *buf_start, const void *buf_end)
921 {
922 }
923 
924 static inline void
__qdf_nbuf_dma_inv_range_no_dsb(const void * buf_start,const void * buf_end)925 __qdf_nbuf_dma_inv_range_no_dsb(const void *buf_start, const void *buf_end)
926 {
927 }
928 
929 static inline void
__qdf_nbuf_dma_clean_range_no_dsb(const void * buf_start,const void * buf_end)930 __qdf_nbuf_dma_clean_range_no_dsb(const void *buf_start, const void *buf_end)
931 {
932 }
933 
934 static inline void
__qdf_dsb(void)935 __qdf_dsb(void)
936 {
937 }
938 
939 static inline void
__qdf_nbuf_dma_clean_range(const void * buf_start,const void * buf_end)940 __qdf_nbuf_dma_clean_range(const void *buf_start, const void *buf_end)
941 {
942 }
943 #endif
944 #endif /*_I_QDF_NBUF_W_H */
945