WS63 SDK 文档 7021f4f@fbb_ws63
ws63 和 ws63e 解决方案的 SDK 文档
载入中...
搜索中...
未找到
oal_netbuf_ext.h
浏览该文件的文档.
1/*
2 * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2022-2022. All rights reserved.
3 * Description: header file for netbuf adapter.
4 * Create: 2022-04-06
5 */
6
7#ifndef OAL_NETBUFF_EXT_H
8#define OAL_NETBUFF_EXT_H
9
10#include "oal_skbuff.h"
11#include "td_type.h"
12#include "securec.h"
14#include "oal_types.h"
15
16/* oal_netbuf.h */
17#define ETH_P_CONTROL 0x0016 /* Card specific control frames */
18#define OAL_NETBUF_SUCC 0
19#define OAL_NETBUF_FAIL (-1)
20
21
22#define OAL_NETBUF_NEXT(_pst_buf) ((_pst_buf)->next)
23#define OAL_NETBUF_PREV(_pst_buf) ((_pst_buf)->prev)
24#define OAL_NETBUF_HEAD_NEXT(_pst_buf_head) ((_pst_buf_head)->next)
25#define OAL_NETBUF_HEAD_PREV(_pst_buf_head) ((_pst_buf_head)->prev)
26
27#define OAL_NETBUF_PROTOCOL(_pst_buf) ((_pst_buf)->protocol)
28#define OAL_NETBUF_DATA(_pst_buf) ((_pst_buf)->data)
29#define OAL_NETBUF_HEADER(_pst_buf) ((_pst_buf)->data)
30#define OAL_NETBUF_PAYLOAD(_pst_buf) ((_pst_buf)->data)
31
32#define OAL_NETBUF_CB(_pst_buf) ((_pst_buf)->cb)
33#define OAL_NETBUF_CB_SIZE() (sizeof(((oal_netbuf_stru*)0)->cb))
34#define OAL_NETBUF_LEN(_pst_buf) ((_pst_buf)->len)
35#define OAL_NETBUF_PRIORITY(_pst_buf) ((_pst_buf)->priority)
36#define OAL_NETBUF_TAIL skb_tail_pointer
37#define OAL_NETBUF_QUEUE_TAIL skb_queue_tail
38#define OAL_NETBUF_QUEUE_HEAD_INIT skb_queue_head_init
39#define OAL_NETBUF_DEQUEUE skb_dequeue
40
41#define WLAN_MEM_NETBUF_ALIGN 4 /* netbuf对齐 */
42
46
47#define OAL_MEM_NETBUF_ALLOC(subpool_id, len, netbuf_priority) \
48 oal_netbuf_alloc(len, 0, WLAN_MEM_NETBUF_ALIGN)
49
50typedef struct {
51 oal_netbuf_head_stru buff_header; /* netbuf队列头结点 */
52 osal_u32 mpdu_cnt; /* 队列中报文数量 */
54
56{
58}
59
60static inline td_u8* oal_netbuf_payload(const oal_netbuf_stru *netbuf)
61{
62 return netbuf->data;
63}
64
65static inline const td_u8* oal_netbuf_payload_const(const oal_netbuf_stru *netbuf)
66{
67 return netbuf->data;
68}
69
70static inline td_u8* oal_netbuf_cb(const oal_netbuf_stru *netbuf)
71{
72 return (td_u8 *)netbuf->cb;
73}
74
75static inline const td_u8* oal_netbuf_cb_const(const oal_netbuf_stru *netbuf)
76{
77 return (td_u8 *)netbuf->cb;
78}
79
80static inline td_u8* oal_netbuf_data(oal_netbuf_stru *netbuf)
81{
82 return netbuf->data;
83}
84
85static inline td_u8* oal_netbuf_data_offset(oal_netbuf_stru *netbuf, td_u32 offset)
86{
87 return netbuf->data + offset;
88}
89
90static inline td_u8* oal_netbuf_header(const oal_netbuf_stru *netbuf)
91{
92 return netbuf->data;
93}
94
95static inline const td_u8* oal_netbuf_header_const(const oal_netbuf_stru *netbuf)
96{
97 return netbuf->data;
98}
99
100/*****************************************************************************
101功能描述 : 获取将skb的数据长度
102*****************************************************************************/
103static inline td_u32 oal_netbuf_get_len(oal_netbuf_stru *netbuf)
104{
105 return netbuf->len;
106}
107
108static inline td_void oal_netbuf_copy_queue_mapping(oal_netbuf_stru *netbuf_to,
109 const oal_netbuf_stru *netbuf_from)
110{
111 skb_copy_queue_mapping(netbuf_to, netbuf_from);
112}
113
114
115/*****************************************************************************
116功能描述 : 在缓冲区尾部增加数据
117*****************************************************************************/
118static inline td_u8* oal_netbuf_put(oal_netbuf_stru *netbuf, td_u32 len)
119{
120 return skb_put(netbuf, len);
121}
122
123/*****************************************************************************
124功能描述 : 在缓冲区开头增加数据
125*****************************************************************************/
126static inline td_u8* oal_netbuf_push(oal_netbuf_stru *netbuf, td_u32 len)
127{
128 return skb_push(netbuf, len);
129}
130
131static inline td_u8* oal_netbuf_pull(oal_netbuf_stru *netbuf, td_u32 len)
132{
133 if (len > netbuf->len) {
134 return TD_NULL;
135 }
136 return skb_pull(netbuf, len);
137}
138
139/*****************************************************************************
140 功能描述 : 链接skb list前一个成员--DMAC
141*****************************************************************************/
142static inline td_void oal_set_netbuf_prev(oal_netbuf_stru *netbuf, oal_netbuf_stru *prev)
143{
144 netbuf->prev = prev;
145}
146
147/*****************************************************************************
148 功能描述 : 链接skb list下一个成员--DMAC
149*****************************************************************************/
150static inline td_void oal_set_netbuf_next(oal_netbuf_stru *netbuf, oal_netbuf_stru *next)
151{
152 if (netbuf == TD_NULL) {
153 return;
154 } else {
155 netbuf->next = next;
156 }
157}
158
159/*****************************************************************************
160 功能描述 : 取skb list下一个成员--DMAC
161*****************************************************************************/
162static inline oal_netbuf_stru* oal_get_netbuf_next(oal_netbuf_stru *netbuf)
163{
164 return netbuf->next;
165}
166
167/*****************************************************************************
168 功能描述 : 判断skb list是否为空--DMAC
169*****************************************************************************/
170static inline td_s32 oal_netbuf_list_empty(const oal_netbuf_head_stru* list_head)
171{
172 return skb_queue_empty(list_head);
173}
174
175/*****************************************************************************
176 功能描述 : 将报文结构体的data指针和tail指针同时下移
177*****************************************************************************/
178static inline td_void oal_netbuf_reserve(oal_netbuf_stru *netbuf, td_u32 l_len)
179{
180 skb_reserve(netbuf, l_len);
181}
182
183/*****************************************************************************
184 功能描述 : 判断一个skb是否为克隆的,是则copy一份新的skb,否则直接返回传入的skb
185*****************************************************************************/
186static inline oal_netbuf_stru* oal_netbuf_unshare(oal_netbuf_stru *netbuf, td_u32 pri)
187{
188 return skb_unshare(netbuf, pri);
189}
190
191/*****************************************************************************
192 功能描述 : 获取头部空间大小
193*****************************************************************************/
194static inline td_u32 oal_netbuf_headroom(const oal_netbuf_stru *netbuf)
195{
196 return (td_u32)skb_headroom(netbuf);
197}
198
199/*****************************************************************************
200 功能描述 : 获取尾部空间大小
201*****************************************************************************/
202static inline td_u32 oal_netbuf_tailroom(const oal_netbuf_stru *netbuf)
203{
204 return (td_u32)skb_tailroom(netbuf);
205}
206
207/*****************************************************************************
208 功能描述 : 将skb加入skb链表中的尾部--DMAC
209*****************************************************************************/
210static inline td_void oal_netbuf_add_to_list_tail(oal_netbuf_stru *netbuf, oal_netbuf_head_stru* head)
211{
212 skb_queue_tail(head, netbuf);
213}
214
215/*****************************************************************************
216 功能描述 : skb链表出队--DMAC
217*****************************************************************************/
218static inline oal_netbuf_stru* oal_netbuf_delist(oal_netbuf_head_stru *list_head)
219{
220 return skb_dequeue(list_head);
221}
222
223/*****************************************************************************
224 功能描述 : skb链表取出其中skb--DMAC
225*****************************************************************************/
226static inline void oal_netbuf_unlink(oal_netbuf_stru *netbuf, oal_netbuf_head_stru *list_head)
227{
228 skb_unlink(netbuf, list_head);
229}
230
231/*****************************************************************************
232 功能描述 : 初始化skb队列头--DMAC
233*****************************************************************************/
234static inline td_void oal_netbuf_list_head_init(oal_netbuf_head_stru* list_head)
235{
236 skb_queue_head_init(list_head);
237}
238
239/*****************************************************************************
240 功能描述 : 返回链表中指定节点的下一个节点
241
242*****************************************************************************/
243static inline oal_netbuf_stru* oal_netbuf_list_next(const oal_netbuf_stru *netbuf)
244{
245 return netbuf->next;
246}
247/*****************************************************************************
248 功能描述 : add a netbuf to skb list
249
250*****************************************************************************/
251static inline td_void oal_netbuf_list_tail(oal_netbuf_head_stru* list, oal_netbuf_stru *netbuf)
252{
253 skb_queue_tail(list, netbuf);
254}
255
256static inline td_void oal_netbuf_list_tail_nolock(oal_netbuf_head_stru *list, oal_netbuf_stru *newsk)
257{
258 __skb_queue_tail(list, newsk);
259}
260
261/*****************************************************************************
262 功能描述 : join two skb lists and reinitialise the emptied list
263*****************************************************************************/
264static inline td_void oal_netbuf_splice_init(oal_netbuf_head_stru* list, oal_netbuf_head_stru* head)
265{
266 skb_queue_splice_init(list, head);
267}
268
269/*****************************************************************************
270 功能描述 : join two skb lists and reinitialise the emptied list
271*****************************************************************************/
272static inline td_void oal_netbuf_queue_splice_tail_init(oal_netbuf_head_stru* list, oal_netbuf_head_stru* head)
273{
274 skb_queue_splice_tail_init(list, head);
275}
276
277/*****************************************************************************
278功能描述 : init netbuf list
279*****************************************************************************/
280static inline td_void oal_netbuf_head_init(oal_netbuf_head_stru *list)
281{
282 skb_queue_head_init(list);
283}
284
285/*****************************************************************************
286功能描述 : 返回skb链表中的第一个元素--DMAC
287*****************************************************************************/
288static inline oal_netbuf_stru* oal_netbuf_peek(const oal_netbuf_head_stru *head)
289{
290#if defined(_PRE_OS_VERSION_LINUX) && defined(_PRE_OS_VERSION) && (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
291#if defined(LINUX_VERSION_CODE) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3,2,0))
292 return skb_peek(head);
293#else
294 oal_netbuf_stru *skb = head->next;
295 if (skb == (oal_netbuf_stru *)head)
296 skb = NULL;
297 return skb;
298#endif
299#endif
300#if defined(_PRE_OS_VERSION_LITEOS) && defined(_PRE_OS_VERSION) && (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION)
301 return skb_peek(head);
302#endif
303}
304
305/* ****************************************************************************
306功能描述 : 返回skb链表中的第一个元素的下一个元素--HMAC
307**************************************************************************** */
308static inline oal_netbuf_stru* oal_netbuf_peek_next(oal_netbuf_stru* netbuf, oal_netbuf_head_stru *head)
309{
310#if defined(_PRE_OS_VERSION_LINUX) && defined(_PRE_OS_VERSION) && (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
311#if defined(LINUX_VERSION_CODE) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
312 return skb_peek_next(netbuf, head);
313#else
314 oal_netbuf_stru *next = netbuf->next;
315 if (next == (oal_netbuf_stru *)head)
316 next = NULL;
317 return next;
318#endif
319#endif
320#if defined(_PRE_OS_VERSION_LITEOS) && defined(_PRE_OS_VERSION) && (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION)
321 return skb_peek_next(netbuf, head);
322#endif
323}
324
325/*****************************************************************************
326功能描述 : 返回skb链表中的最后一个元素
327*****************************************************************************/
328static inline oal_netbuf_stru* oal_netbuf_tail(const oal_netbuf_head_stru *head)
329{
330#if defined(_PRE_OS_VERSION_LINUX) && defined(_PRE_OS_VERSION) && (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
331#if defined(LINUX_VERSION_CODE) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3,2,0))
332 return skb_peek_tail(head);
333#else
334 oal_netbuf_stru *skb = head->prev;
335 if (skb == (oal_netbuf_stru *)head)
336 skb = NULL;
337 return skb;
338#endif
339#endif
340#if defined(_PRE_OS_VERSION_LITEOS) && defined(_PRE_OS_VERSION) && (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION)
341 return skb_peek_tail(head);
342#endif
343}
344
345/*****************************************************************************
346功能描述 : 获取netbuf双向链表中buf的个数
347*****************************************************************************/
348static inline td_u32 oal_netbuf_get_buf_num(const oal_netbuf_head_stru *netbuf_head)
349{
350 return netbuf_head->qlen;
351}
352
353/*****************************************************************************
354功能描述 : 将skb中的内容先偏移ul_offset后 按指定长度拷贝到指定内存中
355*****************************************************************************/
356static inline td_u32 oal_netbuf_copydata(const oal_netbuf_stru *netbuf, td_u32 offset, td_void *dst,
357 td_u32 dst_len, td_u32 len)
358{
359 const td_void *scr = oal_netbuf_payload_const(netbuf) + offset;
360
361 if (memcpy_s(dst, dst_len, scr, len) != EOK) {
362 return OAL_NETBUF_FAIL;
363 }
364
365 return OAL_NETBUF_SUCC;
366}
367
368/*****************************************************************************
369功能描述 : 剥去skb中尾部的信息
370*****************************************************************************/
371static inline td_void oal_netbuf_trim(oal_netbuf_stru *netbuf, td_u32 len)
372{
373 skb_trim(netbuf, netbuf->len - len);
374}
375
376/*****************************************************************************
377功能描述 : 将skb的数据内容长度设置为指定长度
378*****************************************************************************/
379static inline td_void oal_netbuf_set_len(oal_netbuf_stru *netbuf, td_u32 len)
380{
381 if (netbuf->len > len) {
382 skb_trim(netbuf, len);
383 } else {
384 skb_put(netbuf, (len - netbuf->len));
385 }
386}
387
388/*****************************************************************************
389功能描述 : 初始化netbuf
390*****************************************************************************/
391static inline td_void oal_netbuf_init(oal_netbuf_stru *netbuf, td_u32 len)
392{
393 oal_netbuf_set_len(netbuf, len);
394 netbuf->protocol = ETH_P_CONTROL;
395}
396
397/*****************************************************************************
398功能描述: 获取netbuf 链表长度--DMAC
399*****************************************************************************/
400static inline td_u32 oal_netbuf_list_len(const oal_netbuf_head_stru *head)
401{
402 return skb_queue_len(head);
403}
404
405/*****************************************************************************
406 功能描述 : 删除链表中的skb.(只有链表头有next 和 pre,所以只能依次从头删)
407*****************************************************************************/
408static inline td_void oal_netbuf_delete(oal_netbuf_stru *buf, oal_netbuf_head_stru *list_head)
409{
410 skb_unlink(buf, list_head);
411}
412
413/* oal_netbuf.c */
414/*****************************************************************************
415 功能描述 : 获取当前netbuf元素后的第n个元素
416 输入参数 : (1)起始查找节点
417 (2)向后查找的个数
418 输出参数 : 指向期望的netbuf的指针
419 返 回 值 : 期望的betbuf元素的指针或空指针
420*****************************************************************************/
421static inline td_u32 oal_netbuf_get_appointed_netbuf(oal_netbuf_stru *netbuf, td_u8 num,
422 oal_netbuf_stru** expect_netbuf)
423{
424 td_u8 buf_num;
425
426 if ((netbuf == TD_NULL) || (expect_netbuf == TD_NULL)) {
427 return OAL_NETBUF_FAIL;
428 }
429
430 *expect_netbuf = TD_NULL;
431 for (buf_num = 0; buf_num < num; buf_num++) {
432 *expect_netbuf = oal_get_netbuf_next(netbuf);
433
434 if (*expect_netbuf == TD_NULL) {
435 break;
436 }
437
438 netbuf = *expect_netbuf;
439 }
440
441 return OAL_NETBUF_SUCC;
442}
443
444/*****************************************************************************
445 功能描述 : 向netbu_head的尾部串接netbuf
446*****************************************************************************/
447static inline td_u32 oal_netbuf_concat(oal_netbuf_stru* netbuf_head, oal_netbuf_stru* netbuf)
448{
449 if (skb_is_nonlinear(netbuf_head)) {
450 oal_netbuf_free(netbuf);
451 return OAL_NETBUF_FAIL;
452 }
453
454 if (skb_tailroom(netbuf_head) < netbuf->len) {
455 oal_netbuf_free(netbuf);
456 return OAL_NETBUF_FAIL;
457 }
458
459 if (memcpy_s(skb_tail_pointer(netbuf_head), netbuf->len, netbuf->data, netbuf->len) != EOK) {
460 oal_netbuf_free(netbuf);
461 return OAL_NETBUF_FAIL;
462 }
463
464 skb_put(netbuf_head, netbuf->len);
465 oal_netbuf_free(netbuf);
466 return OAL_NETBUF_SUCC;
467}
468
469/* oal_net_rom.h */
470/*****************************************************************************
471 功能描述 : 将skb加入skb链表(device单向链表)中的头部
472*****************************************************************************/
473static inline td_void oal_netbuf_addlist(oal_netbuf_head_stru *head, oal_netbuf_stru *netbuf)
474{
475 skb_queue_head(head, netbuf);
476}
477
478/* oal_net.h */
479static inline td_s32 oal_netbuf_expand_head(oal_netbuf_stru *netbuf, td_s32 nhead, td_s32 ntail, td_s32 gfp_mask)
480{
481 return pskb_expand_head(netbuf, (td_u32)nhead, (td_u32)ntail, gfp_mask);
482}
483
484/* get the queue index of the input skbuff */
485static inline td_u16 oal_skb_get_queue_mapping(oal_netbuf_stru *netbuf)
486{
487 return skb_get_queue_mapping(netbuf);
488}
489
490static inline td_void oal_skb_set_queue_mapping(oal_netbuf_stru *netbuf, td_u16 queue_mapping)
491{
492 skb_set_queue_mapping(netbuf, queue_mapping);
493}
494
495static inline td_u32 oal_netbuf_reserve_header(oal_netbuf_stru *netbuf)
496{
497 td_u32 header_len = oal_netbuf_headroom(netbuf);
498 if (header_len < (td_u32)OAL_HDR_TOTAL_LEN) {
499 return (td_u32)oal_netbuf_expand_head(netbuf, (osal_s32)(OAL_HDR_TOTAL_LEN - header_len), 0, 0);
500 }
501 return OAL_NETBUF_SUCC;
502}
503#endif
#define NULL
Definition common_def.h:21
td_u8 * skb_put(struct sk_buff *skb, td_u32 len)
struct sk_buff * skb_unshare(struct sk_buff *skb, td_u32 pri)
struct sk_buff * skb_dequeue(struct sk_buff_head *list)
td_s32 pskb_expand_head(struct sk_buff *skb, td_u32 nhead, td_u32 ntail, td_s32 gfp_mask)
td_void skb_queue_tail(struct sk_buff_head *list, struct sk_buff *newsk)
td_void skb_trim(struct sk_buff *skb, td_u32 len)
oal_netbuf_stru * oal_netbuf_alloc_ext(td_u32 size)
#define OAL_HDR_TOTAL_LEN
Definition oal_netbuf_common_rom.h:25
#define OAL_MAX_MAC_HDR_LEN
Definition oal_netbuf_common_rom.h:24
#define WLAN_MEM_NETBUF_ALIGN
Definition oal_netbuf_ext.h:41
#define ETH_P_CONTROL
Definition oal_netbuf_ext.h:17
#define OAL_NETBUF_SUCC
Definition oal_netbuf_ext.h:18
#define OAL_NETBUF_FAIL
Definition oal_netbuf_ext.h:19
td_void oal_netbuf_free_any(oal_netbuf_stru *netbuf)
oal_netbuf_stru * oal_netbuf_alloc(td_u32 size, td_u32 l_reserve, td_u32 align)
td_u32 oal_netbuf_free(oal_netbuf_stru *netbuf)
int osal_s32
Definition osal_types.h:19
unsigned int osal_u32
Definition osal_types.h:13
errno_t memcpy_s(void *dest, size_t destMax, const void *src, size_t count)
#define EOK
Definition securec.h:57
Definition list.h:18
Definition oal_netbuf_ext.h:50
oal_netbuf_head_stru buff_header
Definition oal_netbuf_ext.h:51
osal_u32 mpdu_cnt
Definition oal_netbuf_ext.h:52
Definition oal_skbuff.h:73
struct sk_buff * next
Definition oal_skbuff.h:75
td_u32 qlen
Definition oal_skbuff.h:78
struct sk_buff * prev
Definition oal_skbuff.h:76
Definition oal_skbuff.h:82
struct sk_buff * prev
Definition oal_skbuff.h:85
td_u32 len
Definition oal_skbuff.h:90
struct sk_buff * next
Definition oal_skbuff.h:84
td_s8 cb[48]
Definition oal_skbuff.h:98
td_u8 * data
Definition oal_skbuff.h:100
td_u32 protocol
Definition oal_skbuff.h:108
unsigned short td_u16
Definition td_type.h:37
unsigned char td_u8
Definition td_type.h:36
void td_void
Definition td_type.h:49
unsigned int td_u32
Definition td_type.h:38
#define TD_NULL
Definition td_type.h:30
int td_s32
Definition td_type.h:44