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