blob: 487f01ed37d109f1834a55bb81065c0186e81b83 [file] [log] [blame]
wdenk7152b1d2003-09-05 23:19:14 +00001/*
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
wdenk149dded2003-09-10 18:20:28 +000026#include <config.h>
wdenk7152b1d2003-09-05 23:19:14 +000027#include <common.h>
28#include "u-boot_compat.h"
29
30#define MAX_SKB 50
31
32static struct sk_buff *sk_table[MAX_SKB];
33
34
35struct sk_buff * alloc_skb(u32 size, int dummy)
36{
37 int i;
38 struct sk_buff * ret = NULL;
39
40 for (i = 0; i < MAX_SKB; i++)
41 {
42 if (sk_table[i])
43 {
44 /* Already allocated.
45 */
46 continue;
47 }
48
49 sk_table[i] = malloc(sizeof(struct sk_buff));
50 if (! sk_table[i])
51 {
52 printf("alloc_skb: malloc failed\n");
53 break;
54 }
55
56 memset(sk_table[i], 0, sizeof(struct sk_buff));
57 sk_table[i]->data = sk_table[i]->data_unaligned =
58 malloc(size + 16);
59 if (! sk_table[i]->data)
60 {
61 printf("alloc_skb: malloc failed\n");
62 free(sk_table[i]);
63 sk_table[i] = NULL;
64 break;
65 }
66
67 sk_table[i]->data += 16 - ((u32)sk_table[i]->data & 15);
68 sk_table[i]->len = size;
wdenk42d1f032003-10-15 23:53:47 +000069
wdenk7152b1d2003-09-05 23:19:14 +000070 break;
71 }
72
73 if (i < MAX_SKB)
74 {
75 ret = sk_table[i];
76 }
77
78 if (! ret)
79 {
80 printf("Unable to allocate skb!\n");
81 }
82
83 return ret;
84}
85
86void dev_kfree_skb_any(struct sk_buff *skb)
87{
88 int i;
89
90 for (i = 0; i < MAX_SKB; i++)
91 {
92 if (sk_table[i] != skb)
93 {
94 continue;
95 }
96
97 free(skb->data_unaligned);
98 free(skb);
99 sk_table[i] = NULL;
100 break;
101 }
102
103 if (i == MAX_SKB)
104 {
105 printf("SKB allocation error!\n");
106 }
107}
108
109void skb_reserve(struct sk_buff *skb, unsigned int len)
110{
111 skb->data+=len;
112}
113
114void skb_put(struct sk_buff *skb, unsigned int len)
115{
116 skb->len+=len;
117}