OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [redboot/] [current/] [src/] [net/] [pktbuf.c] - Blame information for rev 856

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      net/pktbuf.c
4
//
5
//      Stand-alone network packet support for RedBoot
6
//
7
//==========================================================================
8
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
9
// -------------------------------------------                              
10
// This file is part of eCos, the Embedded Configurable Operating System.   
11
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
12
//
13
// eCos is free software; you can redistribute it and/or modify it under    
14
// the terms of the GNU General Public License as published by the Free     
15
// Software Foundation; either version 2 or (at your option) any later      
16
// version.                                                                 
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT      
19
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
21
// for more details.                                                        
22
//
23
// You should have received a copy of the GNU General Public License        
24
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
25
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
26
//
27
// As a special exception, if other files instantiate templates or use      
28
// macros or inline functions from this file, or you compile this file      
29
// and link it with other works to produce a work based on this file,       
30
// this file does not by itself cause the resulting work to be covered by   
31
// the GNU General Public License. However the source code for this file    
32
// must still be made available in accordance with section (3) of the GNU   
33
// General Public License v2.                                               
34
//
35
// This exception does not invalidate any other reasons why a work based    
36
// on this file might be covered by the GNU General Public License.         
37
// -------------------------------------------                              
38
// ####ECOSGPLCOPYRIGHTEND####                                              
39
//==========================================================================
40
//#####DESCRIPTIONBEGIN####
41
//
42
// Author(s):    gthomas
43
// Contributors: gthomas
44
// Date:         2000-07-14
45
// Purpose:      
46
// Description:  
47
//              
48
// This code is part of RedBoot (tm).
49
//
50
//####DESCRIPTIONEND####
51
//
52
//==========================================================================
53
 
54
#include <redboot.h>
55
#include <net/net.h>
56
 
57
#define MAX_PKTBUF CYGNUM_REDBOOT_NETWORKING_MAX_PKTBUF
58
 
59
#define BUFF_STATS 1
60
 
61
#if BUFF_STATS
62
int max_alloc = 0;
63
int num_alloc = 0;
64
int num_free  = 0;
65
#endif
66
 
67
static pktbuf_t  pktbuf_list[MAX_PKTBUF];
68
static word      bufdata[MAX_PKTBUF][ETH_MAX_PKTLEN/2 + 1];
69
static pktbuf_t *free_list;
70
 
71
 
72
/*
73
 * Initialize the free list.
74
 */
75
void
76
__pktbuf_init(void)
77
{
78
    int  i;
79
    word *p;
80
    static int init = 0;
81
 
82
    if (init) return;
83
    init = 1;
84
 
85
    for (i = 0; i < MAX_PKTBUF; i++) {
86
        p = bufdata[i];
87
        if ((((unsigned long)p) & 2) != 0)
88
            ++p;
89
        pktbuf_list[i].buf = p;
90
        pktbuf_list[i].bufsize = ETH_MAX_PKTLEN;
91
        pktbuf_list[i].next = free_list;
92
        free_list = &pktbuf_list[i];
93
    }
94
}
95
 
96
void
97
__pktbuf_dump(void)
98
{
99
    int i;
100
    for (i = 0; i < MAX_PKTBUF; i++) {
101
        diag_printf("Buf[%d]/%p: buf: %p, len: %d/%d, next: %p\n",
102
                    i,
103
                    (void*)&pktbuf_list[i],
104
                    (void*)pktbuf_list[i].buf,
105
                    pktbuf_list[i].bufsize,
106
                    pktbuf_list[i].pkt_bytes,
107
                    (void*)pktbuf_list[i].next);
108
    }
109
    diag_printf("Free list = %p\n", (void*)free_list);
110
}
111
 
112
/*
113
 * simple pktbuf allocation
114
 */
115
pktbuf_t *
116
__pktbuf_alloc(int nbytes)
117
{
118
    pktbuf_t *p = free_list;
119
 
120
    if (p) {
121
        free_list = p->next;
122
        p->ip_hdr  = (ip_header_t *)p->buf;
123
        p->tcp_hdr = (tcp_header_t *)(p->ip_hdr + 1);
124
        p->pkt_bytes = 0;
125
#if BUFF_STATS
126
        ++num_alloc;
127
        if ((num_alloc - num_free) > max_alloc)
128
            max_alloc = num_alloc - num_free;
129
#endif
130
    }
131
    return p;
132
}
133
 
134
 
135
/*
136
 * free a pktbuf.
137
 */
138
void
139
__pktbuf_free(pktbuf_t *pkt)
140
{
141
#if BUFF_STATS
142
    --num_alloc;
143
#endif
144
#ifdef BSP_LOG
145
    {
146
        int i;
147
        word *p;
148
 
149
        for (i = 0; i < MAX_PKTBUF; i++) {
150
            p = bufdata[i];
151
            if ((((unsigned long)p) & 2) == 0)
152
                ++p;
153
            if (p == (word *)pkt)
154
                break;
155
        }
156
        if (i < MAX_PKTBUF) {
157
            BSPLOG(bsp_log("__pktbuf_free: bad pkt[%x].\n", pkt));
158
            BSPLOG(while(1));
159
        }
160
    }
161
#endif
162
    pkt->next = free_list;
163
    free_list = pkt;
164
}
165
 
166
 

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.