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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [redboot/] [v2_0/] [src/] [net/] [pktbuf.c] - Blame information for rev 27

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

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

powered by: WebSVN 2.1.0

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