]>
Commit | Line | Data |
---|---|---|
7152b1d0 WD |
1 | /* |
2 | * Definitions for the 'struct sk_buff' memory handlers in U-Boot. | |
3 | * | |
4 | * (C) Copyright 2003 | |
5 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. | |
6 | * | |
7 | * See file CREDITS for list of people who contributed to this | |
8 | * project. | |
9 | * | |
10 | * This program is free software; you can redistribute it and/or | |
11 | * modify it under the terms of the GNU General Public License as | |
12 | * published by the Free Software Foundation; either version 2 of | |
13 | * the License, or (at your option) any later version. | |
14 | * | |
15 | * This program is distributed in the hope that it will be useful, | |
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | * GNU General Public License for more details. | |
19 | * | |
20 | * You should have received a copy of the GNU General Public License | |
21 | * along with this program; if not, write to the Free Software | |
22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, | |
23 | * MA 02111-1307 USA | |
24 | */ | |
25 | ||
149dded2 WD |
26 | #include <config.h> |
27 | ||
28 | #ifdef CONFIG_SK98 | |
29 | ||
7152b1d0 WD |
30 | #include <common.h> |
31 | #include "u-boot_compat.h" | |
32 | ||
33 | #define MAX_SKB 50 | |
34 | ||
35 | static struct sk_buff *sk_table[MAX_SKB]; | |
36 | ||
37 | ||
38 | struct sk_buff * alloc_skb(u32 size, int dummy) | |
39 | { | |
40 | int i; | |
41 | struct sk_buff * ret = NULL; | |
42 | ||
43 | for (i = 0; i < MAX_SKB; i++) | |
44 | { | |
45 | if (sk_table[i]) | |
46 | { | |
47 | /* Already allocated. | |
48 | */ | |
49 | continue; | |
50 | } | |
51 | ||
52 | sk_table[i] = malloc(sizeof(struct sk_buff)); | |
53 | if (! sk_table[i]) | |
54 | { | |
55 | printf("alloc_skb: malloc failed\n"); | |
56 | break; | |
57 | } | |
58 | ||
59 | memset(sk_table[i], 0, sizeof(struct sk_buff)); | |
60 | sk_table[i]->data = sk_table[i]->data_unaligned = | |
61 | malloc(size + 16); | |
62 | if (! sk_table[i]->data) | |
63 | { | |
64 | printf("alloc_skb: malloc failed\n"); | |
65 | free(sk_table[i]); | |
66 | sk_table[i] = NULL; | |
67 | break; | |
68 | } | |
69 | ||
70 | sk_table[i]->data += 16 - ((u32)sk_table[i]->data & 15); | |
71 | sk_table[i]->len = size; | |
42d1f039 | 72 | |
7152b1d0 WD |
73 | break; |
74 | } | |
75 | ||
76 | if (i < MAX_SKB) | |
77 | { | |
78 | ret = sk_table[i]; | |
79 | } | |
80 | ||
81 | if (! ret) | |
82 | { | |
83 | printf("Unable to allocate skb!\n"); | |
84 | } | |
85 | ||
86 | return ret; | |
87 | } | |
88 | ||
89 | void dev_kfree_skb_any(struct sk_buff *skb) | |
90 | { | |
91 | int i; | |
92 | ||
93 | for (i = 0; i < MAX_SKB; i++) | |
94 | { | |
95 | if (sk_table[i] != skb) | |
96 | { | |
97 | continue; | |
98 | } | |
99 | ||
100 | free(skb->data_unaligned); | |
101 | free(skb); | |
102 | sk_table[i] = NULL; | |
103 | break; | |
104 | } | |
105 | ||
106 | if (i == MAX_SKB) | |
107 | { | |
108 | printf("SKB allocation error!\n"); | |
109 | } | |
110 | } | |
111 | ||
112 | void skb_reserve(struct sk_buff *skb, unsigned int len) | |
113 | { | |
114 | skb->data+=len; | |
115 | } | |
116 | ||
117 | void skb_put(struct sk_buff *skb, unsigned int len) | |
118 | { | |
119 | skb->len+=len; | |
120 | } | |
149dded2 WD |
121 | |
122 | #endif /* CONFIG_SK98 */ |