WS63 SDK 文档 7021f4f@fbb_ws63
ws63 和 ws63e 解决方案的 SDK 文档
载入中...
搜索中...
未找到
oal_skbuff.h
浏览该文件的文档.
1/*
2 * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2022-2023. All rights reserved.
3 * Description: skb function.
4 * Author:
5 * Create: 2022-04-07
6 */
7
8#ifndef LITEOS_SKBUFF_H
9#define LITEOS_SKBUFF_H
10
11/*****************************************************************************
12 1 其他头文件包含
13*****************************************************************************/
14#include <stdlib.h>
15#ifndef FREERTOS_DEFINE
16#include <linux/spinlock.h>
17#endif
18#include "osal_adapt.h"
19#include "td_type.h"
20#include "td_base.h"
21#include "osal_types.h"
22#ifdef _PRE_LWIP_ZERO_COPY_MEM_ALLOC_PKT_BUF
23#include "oal_net_pkt_rom.h"
24#endif
25
26#ifdef __cplusplus
27#if __cplusplus
28extern "C" {
29#endif
30#endif
31
32/*****************************************************************************
33 2 宏定义
34*****************************************************************************/
35/* Don't change this without changing skb_csum_unnecessary! */
36#define CHECKSUM_NONE 0
37#define CHECKSUM_UNNECESSARY 1
38#define CHECKSUM_COMPLETE 2
39#define CHECKSUM_PARTIAL 3
40
41#define L1_CACHE_BYTES (1 << 5)
42#define SMP_CACHE_BYTES L1_CACHE_BYTES
43#define skb_data_align(x) (((x) + (SMP_CACHE_BYTES - 1)) & ~(SMP_CACHE_BYTES - 1))
44
45/* return minimum truesize of one skb containing X bytes of data */
46#define skb_truesize(x) ((x) + skb_data_align(sizeof(struct sk_buff)))
47
48#ifndef NET_SKB_PAD
49#define NET_SKB_PAD 80
50#endif
51
52#define NUMA_NO_NODE (-1)
53
54#define USB_CACHE_ALIGN_SIZE 32
55
56#define SKB_ALLOC_FCLONE 0x01
57#define SKB_ALLOC_RX 0x02
58
59#ifndef OFFSETOF
60#ifdef HAVE_PCLINT_CHECK
61#define oal_offsetof(type, member) 0
62#else
63#define oal_offsetof(type, member) ((long) &((type *) 0)->member)
64#endif
65#endif
66
67typedef td_u32 gfp_t;
69
70/*****************************************************************************
71 3 结构体定义
72*****************************************************************************/
74 /* These two members must be first. */
75 struct sk_buff *next;
76 struct sk_buff *prev;
77
80};
81
82struct sk_buff {
83 /* These two members must be first. */
84 struct sk_buff *next;
85 struct sk_buff *prev;
86#ifdef _PRE_LWIP_ZERO_COPY_MEM_ALLOC_PKT_BUF
87 oal_dmac_netbuf_stru *pkt_buf;
88#endif
89 td_void *dev; /* for hwal_netif_rx */
93
94 /* These elements must be at the end, see alloc_skb() for details. */
97
98 td_s8 cb[48]; /* 48: SIZE(0..48) */
101
105
106 /* use for lwip_pbuf zero_copy:actual start addr of memory space */
109
113#ifdef TIMESTAMP_RECORD_DEBUG
114 td_u32 times[19]; /* timestamp for debug */
115#endif
116};
117
120
121/*****************************************************************************
122 4 函数声明
123*****************************************************************************/
124td_void skb_trim(struct sk_buff *skb, td_u32 len);
125struct sk_buff *skb_unshare(struct sk_buff *skb, td_u32 pri);
126td_s32 pskb_expand_head(struct sk_buff *skb, td_u32 nhead, td_u32 ntail, td_s32 gfp_mask);
128struct sk_buff *skb_dequeue(struct sk_buff_head *list);
129td_void skb_queue_tail(struct sk_buff_head *list, struct sk_buff *newsk);
133#define dev_kfree_skb_any(a) dev_kfree_skb(a)
134
135/*****************************************************************************
136 5 内联函数
137*****************************************************************************/
138static inline td_void _skb_queue_head_init(struct sk_buff_head *list)
139{
140 list->prev = list->next = (struct sk_buff *)(uintptr_t)list;
141 list->qlen = 0;
142}
143
144static inline td_void skb_queue_head_init(struct sk_buff_head *list)
145{
146#ifndef FREERTOS_DEFINE
147 /* liteos list操作不用osal_spin_lock_init, 因为给lock申请的内存 可能没有流程保障释放 */
148 spin_lock_init(&list->lock);
149#else
150 /* 其他系统下 init函数中不会给lock申请内存 */
152#endif
153 _skb_queue_head_init(list);
154}
155
156static inline td_void skb_reset_tail_pointer(struct sk_buff *skb)
157{
158 skb->tail = (sk_buff_data_t)(skb->data - skb->head);
159}
160
161static inline td_u8 *skb_tail_pointer(const struct sk_buff *skb)
162{
163 td_u8 *phead = skb->head;
164 return (phead + skb->tail);
165}
166
167static inline td_s32 skb_queue_empty(const struct sk_buff_head *list)
168{
169 return list->next == (struct sk_buff *)(uintptr_t)list;
170}
171
172static inline td_void skb_reserve(struct sk_buff *skb, td_u32 len)
173{
174 skb->data += len;
175 skb->tail += len;
176}
177
178static inline struct sk_buff *_dev_alloc_skb(td_u32 length)
179{
180 struct sk_buff *skb = alloc_skb(length + NET_SKB_PAD);
181 if (skb != NULL) {
182 skb_reserve(skb, NET_SKB_PAD);
183 }
184 return skb;
185}
186
187static inline td_void skb_unlink(struct sk_buff *skb, struct sk_buff_head *list)
188{
189 struct sk_buff *next = NULL;
190 struct sk_buff *prev = NULL;
191
192 list->qlen--;
193 next = skb->next;
194 prev = skb->prev;
195 skb->next = skb->prev = NULL;
196 next->prev = prev;
197 prev->next = next;
198}
199
200static inline struct sk_buff *skb_get(struct sk_buff *skb)
201{
203 return skb;
204}
205
206static inline struct sk_buff *skb_peek(const struct sk_buff_head *list_)
207{
208 struct sk_buff *list = ((const struct sk_buff *)(uintptr_t)list_)->next;
209 if (list == (struct sk_buff *)(uintptr_t)list_) {
210 list = NULL;
211 }
212 return list;
213}
214
215static inline struct sk_buff *skb_peek_next(const struct sk_buff *skb, const struct sk_buff_head *list_)
216{
217 struct sk_buff *next = skb->next;
218
219 if (next == (struct sk_buff *)(uintptr_t)list_) {
220 next = NULL;
221 }
222 return next;
223}
224
225static inline struct sk_buff *skb_peek_tail(const struct sk_buff_head *list_)
226{
227 struct sk_buff *skb = list_->prev;
228
229 if (skb == (struct sk_buff *)(uintptr_t)list_) {
230 skb = NULL;
231 }
232 return skb;
233}
234
235static inline struct sk_buff *_skb_dequeue(struct sk_buff_head *list)
236{
237 struct sk_buff *skb = skb_peek(list);
238 if (skb) {
239 skb_unlink(skb, list);
240 }
241 return skb;
242}
243
244static inline struct sk_buff *_skb_dequeue_tail(struct sk_buff_head *list)
245{
246 struct sk_buff *skb = skb_peek_tail(list);
247 if (skb) {
248 skb_unlink(skb, list);
249 }
250 return skb;
251}
252
253static inline td_s32 skb_headlen(const struct sk_buff *skb)
254{
255 return (td_s32)(skb->len - skb->data_len);
256}
257
258static inline td_void _skb_insert(struct sk_buff *newsk,
259 struct sk_buff *prev, struct sk_buff *next,
260 struct sk_buff_head *list)
261{
262 newsk->next = next;
263 newsk->prev = prev;
264 next->prev = prev->next = newsk;
265 list->qlen++;
266}
267
268static inline td_void _skb_queue_before(struct sk_buff_head *list, struct sk_buff *next, struct sk_buff *newsk)
269{
270 _skb_insert(newsk, next->prev, next, list);
271}
272
273static inline td_void __skb_queue_tail(struct sk_buff_head *list, struct sk_buff *newsk)
274{
275 _skb_queue_before(list, (struct sk_buff *)(uintptr_t)list, newsk);
276}
277
278static inline td_void _skb_queue_splice(const struct sk_buff_head *list, struct sk_buff *prev, struct sk_buff *next)
279{
280 struct sk_buff *first = list->next;
281 struct sk_buff *last = list->prev;
282
283 first->prev = prev;
284 prev->next = first;
285
286 last->next = next;
287 next->prev = last;
288}
289
290static inline td_void skb_queue_splice(const struct sk_buff_head *list, struct sk_buff_head *head)
291{
292 if (skb_queue_empty(list) == 0) {
293 _skb_queue_splice(list, (struct sk_buff *) head, head->next);
294 head->qlen += list->qlen;
295 }
296}
297
298static inline td_void skb_queue_splice_tail_init(struct sk_buff_head *list, struct sk_buff_head *head)
299{
300 if (skb_queue_empty(list) == 0) {
301 _skb_queue_splice(list, head->prev, (struct sk_buff *) head);
302 head->qlen += list->qlen;
303 _skb_queue_head_init(list);
304 }
305}
306
307static inline td_void skb_queue_splice_init(struct sk_buff_head *list, struct sk_buff_head *head)
308{
309 if (skb_queue_empty(list) == 0) {
310 _skb_queue_splice(list, (struct sk_buff *)(uintptr_t)head, head->next);
311 head->qlen += list->qlen;
312 _skb_queue_head_init(list);
313 }
314}
315
316static inline td_u8 *skb_pull(struct sk_buff *skb, td_u32 len)
317{
318 skb->len -= len;
319 return skb->data += len;
320}
321
322static inline td_s32 skb_headroom(const struct sk_buff *skb)
323{
324 return (td_s32)(skb->data - skb->head);
325}
326
327static inline bool skb_is_nonlinear(const struct sk_buff *skb)
328{
329 return skb->data_len;
330}
331
332static inline td_void skb_set_tail_pointer(struct sk_buff *skb, const td_u32 offset)
333{
334 skb_reset_tail_pointer(skb);
335 skb->tail += offset;
336}
337
338static inline td_void _skb_trim(struct sk_buff *skb, td_u32 len)
339{
340 if (skb_is_nonlinear(skb)) {
341 return;
342 }
343 skb->len = len;
344 skb_set_tail_pointer(skb, len);
345}
346
347static inline td_u8 *skb_push(struct sk_buff *skb, td_u32 len)
348{
349 if (skb->data - len < skb->head) {
350 return NULL;
351 }
352
353 skb->data -= len;
354 skb->len += len;
355 return skb->data;
356}
357
358static inline td_u32 skb_tailroom(const struct sk_buff *skb)
359{
360 return skb_is_nonlinear(skb) ? 0 : skb->end - skb->tail;
361}
362
363static inline bool skb_queue_is_last(const struct sk_buff_head *list, const struct sk_buff *skb)
364{
365 return skb->next == (struct sk_buff *)list;
366}
367
368static inline td_u8 *skb_end_pointer(const struct sk_buff *skb)
369{
370 return skb->head + skb->end;
371}
372
373static inline td_u32 skb_end_offset(const struct sk_buff *skb)
374{
375 return skb->end;
376}
377
378static inline td_void _skb_queue_after(struct sk_buff_head *list, struct sk_buff *prev, struct sk_buff *newsk)
379{
380 _skb_insert(newsk, prev, prev->next, list);
381}
382
383static inline td_void skb_queue_head(struct sk_buff_head *list, struct sk_buff *newsk)
384{
385 _skb_queue_after(list, (struct sk_buff *)(uintptr_t)list, newsk);
386}
387
388static inline td_void skb_set_queue_mapping(struct sk_buff *skb, td_u16 queue_mapping)
389{
390 skb->queue_mapping = queue_mapping;
391}
392
393static inline td_u16 skb_get_queue_mapping(const struct sk_buff *skb)
394{
395 return skb->queue_mapping;
396}
397
398static inline td_void skb_copy_queue_mapping(struct sk_buff *to, const struct sk_buff *from)
399{
400 to->queue_mapping = from->queue_mapping;
401}
402
403static inline td_u32 skb_queue_len(const struct sk_buff_head *list_)
404{
405 return list_->qlen;
406}
407
408#endif /* LITEOS_SKBUFF_H */
void osal_adapt_atomic_inc(osal_atomic *atomic)
Definition osal_adapt_atomic.c:39
#define NULL
Definition common_def.h:21
int osal_spin_lock_init(osal_spinlock *lock)
Initialize a spin lock.
Definition osal_spinlock.c:15
td_u8 * skb_put(struct sk_buff *skb, td_u32 len)
td_u32 sk_buff_data_t
Definition oal_skbuff.h:68
struct sk_buff * alloc_skb(td_u32 size)
struct sk_buff * dev_alloc_skb(td_u32 length)
struct sk_buff * skb_unshare(struct sk_buff *skb, td_u32 pri)
struct sk_buff * skb_dequeue(struct sk_buff_head *list)
td_void dev_kfree_skb(struct sk_buff *skb)
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)
#define NET_SKB_PAD
Definition oal_skbuff.h:49
td_u32 gfp_t
Definition oal_skbuff.h:67
Definition oal_net_pkt_rom.h:83
Definition osal_atomic.h:18
Definition osal_spinlock.h:18
Definition oal_skbuff.h:73
struct sk_buff * next
Definition oal_skbuff.h:75
td_u32 qlen
Definition oal_skbuff.h:78
osal_spinlock lock
Definition oal_skbuff.h:79
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_u8 resv
Definition oal_skbuff.h:112
td_u8 * head
Definition oal_skbuff.h:99
td_s8 cb[48]
Definition oal_skbuff.h:98
td_u8 resv2
Definition oal_skbuff.h:111
td_u8 * mem_head
Definition oal_skbuff.h:107
sk_buff_data_t tail
Definition oal_skbuff.h:95
td_void * dev
Definition oal_skbuff.h:89
sk_buff_data_t end
Definition oal_skbuff.h:96
td_u32 truesize
Definition oal_skbuff.h:102
td_u8 * data
Definition oal_skbuff.h:100
td_u16 queue_mapping
Definition oal_skbuff.h:92
td_u32 data_len
Definition oal_skbuff.h:91
td_u32 priority
Definition oal_skbuff.h:103
osal_atomic users
Definition oal_skbuff.h:104
td_u16 mac_header
Definition oal_skbuff.h:110
td_u32 protocol
Definition oal_skbuff.h:108
unsigned short td_u16
Definition td_type.h:37
unsigned int uintptr_t
Definition td_type.h:65
unsigned char td_u8
Definition td_type.h:36
void td_void
Definition td_type.h:49
signed char td_s8
Definition td_type.h:42
unsigned int td_u32
Definition td_type.h:38
int td_s32
Definition td_type.h:44