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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [net/] [bsd_tcpip/] [current/] [include/] [sys/] [mbuf.h] - Blame information for rev 808

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

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      include/sys/mbuf.h
4
//
5
//==========================================================================
6
// ####BSDCOPYRIGHTBEGIN####                                    
7
// -------------------------------------------                  
8
// This file is part of eCos, the Embedded Configurable Operating System.
9
//
10
// Portions of this software may have been derived from FreeBSD 
11
// or other sources, and if so are covered by the appropriate copyright
12
// and license included herein.                                 
13
//
14
// Portions created by the Free Software Foundation are         
15
// Copyright (C) 2002 Free Software Foundation, Inc.            
16
// -------------------------------------------                  
17
// ####BSDCOPYRIGHTEND####                                      
18
//==========================================================================
19
 
20
/*
21
 * Copyright (c) 1982, 1986, 1988, 1993
22
 *      The Regents of the University of California.  All rights reserved.
23
 *
24
 * Redistribution and use in source and binary forms, with or without
25
 * modification, are permitted provided that the following conditions
26
 * are met:
27
 * 1. Redistributions of source code must retain the above copyright
28
 *    notice, this list of conditions and the following disclaimer.
29
 * 2. Redistributions in binary form must reproduce the above copyright
30
 *    notice, this list of conditions and the following disclaimer in the
31
 *    documentation and/or other materials provided with the distribution.
32
 * 3. All advertising materials mentioning features or use of this software
33
 *    must display the following acknowledgement:
34
 *      This product includes software developed by the University of
35
 *      California, Berkeley and its contributors.
36
 * 4. Neither the name of the University nor the names of its contributors
37
 *    may be used to endorse or promote products derived from this software
38
 *    without specific prior written permission.
39
 *
40
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
41
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
44
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50
 * SUCH DAMAGE.
51
 *
52
 *      @(#)mbuf.h      8.5 (Berkeley) 2/19/95
53
 * $FreeBSD: src/sys/sys/mbuf.h,v 1.44.2.10 2001/07/03 11:02:01 ume Exp $
54
 */
55
 
56
#ifndef _SYS_MBUF_H_
57
#define _SYS_MBUF_H_
58
 
59
/*
60
 * Mbufs are of a single size, MSIZE (machine/param.h), which
61
 * includes overhead.  An mbuf may add a single "mbuf cluster" of size
62
 * MCLBYTES (also in machine/param.h), which has no additional overhead
63
 * and is used instead of the internal data area; this is done when
64
 * at least MINCLSIZE of data must be stored.
65
 */
66
 
67
#define MLEN            (MSIZE - sizeof(struct m_hdr))  /* normal data len */
68
#define MHLEN           (MLEN - sizeof(struct pkthdr))  /* data len w/pkthdr */
69
 
70
#define MINCLSIZE       (MHLEN + 1)     /* smallest amount to put in cluster */
71
#define M_MAXCOMPRESS   (MHLEN / 2)     /* max amount to copy for compression */
72
 
73
/*
74
 * Macros for type conversion
75
 * mtod(m, t) - convert mbuf pointer to data pointer of correct type
76
 * dtom(x) -    convert data pointer within mbuf to mbuf pointer (XXX)
77
 * mtocl(x) -   convert pointer within cluster to cluster index #
78
 * cltom(x) -   convert cluster # to ptr to beginning of cluster
79
 */
80
#define mtod(m, t)      ((t)((m)->m_data))
81
#define dtom(x)         ((struct mbuf *)((CYG_ADDRESS)(x) & ~(MSIZE-1)))
82
extern int cyg_mtocl(u_long);
83
extern struct mbuf *cyg_cltom(u_long);
84
#define mtocl(x) cyg_mtocl((u_long)x)
85
#define cltom(x) cyg_cltom((u_long)x)
86
 
87
/* header at beginning of each mbuf: */
88
struct m_hdr {
89
        struct  mbuf *mh_next;          /* next buffer in chain */
90
        struct  mbuf *mh_nextpkt;       /* next chain in queue/record */
91
        caddr_t mh_data;                /* location of data */
92
        int     mh_len;                 /* amount of data in this mbuf */
93
        short   mh_type;                /* type of data in this mbuf */
94
        short   mh_flags;               /* flags; see below */
95
};
96
 
97
/* record/packet header in first mbuf of chain; valid if M_PKTHDR set */
98
struct pkthdr {
99
        struct  ifnet *rcvif;           /* rcv interface */
100
        int     len;                    /* total packet length */
101
        /* variables for ip and tcp reassembly */
102
        void    *header;                /* pointer to packet header */
103
        /* variables for hardware checksum */
104
        int     csum_flags;             /* flags regarding checksum */
105
        int     csum_data;              /* data field used by csum routines */
106
        struct  mbuf *aux;              /* extra data buffer; ipsec/others */
107
};
108
 
109
/* description of external storage mapped into mbuf, valid if M_EXT set */
110
struct m_ext {
111
        caddr_t ext_buf;                /* start of buffer */
112
        void    (*ext_free)             /* free routine if not the usual */
113
                __P((caddr_t, u_int));
114
        u_int   ext_size;               /* size of buffer, for ext_free */
115
        void    (*ext_ref)              /* add a reference to the ext object */
116
                __P((caddr_t, u_int));
117
};
118
 
119
struct mbuf {
120
        struct  m_hdr m_hdr;
121
        union {
122
                struct {
123
                        struct  pkthdr MH_pkthdr;       /* M_PKTHDR set */
124
                        union {
125
                                struct  m_ext MH_ext;   /* M_EXT set */
126
                                char    MH_databuf[MHLEN];
127
                        } MH_dat;
128
                } MH;
129
                char    M_databuf[MLEN];                /* !M_PKTHDR, !M_EXT */
130
        } M_dat;
131
};
132
#define m_next          m_hdr.mh_next
133
#define m_len           m_hdr.mh_len
134
#define m_data          m_hdr.mh_data
135
#define m_type          m_hdr.mh_type
136
#define m_flags         m_hdr.mh_flags
137
#define m_nextpkt       m_hdr.mh_nextpkt
138
#define m_act           m_nextpkt
139
#define m_pkthdr        M_dat.MH.MH_pkthdr
140
#define m_ext           M_dat.MH.MH_dat.MH_ext
141
#define m_pktdat        M_dat.MH.MH_dat.MH_databuf
142
#define m_dat           M_dat.M_databuf
143
 
144
/* mbuf flags */
145
#define M_EXT           0x0001  /* has associated external storage */
146
#define M_PKTHDR        0x0002  /* start of record */
147
#define M_EOR           0x0004  /* end of record */
148
#define M_PROTO1        0x0008  /* protocol-specific */
149
#define M_PROTO2        0x0010  /* protocol-specific */
150
#define M_PROTO3        0x0020  /* protocol-specific */
151
#define M_PROTO4        0x0040  /* protocol-specific */
152
#define M_PROTO5        0x0080  /* protocol-specific */
153
#define M_PROTO6        0x2000  /* protocol-specific */
154
 
155
/* mbuf pkthdr flags, also in m_flags */
156
#define M_BCAST         0x0100  /* send/received as link-level broadcast */
157
#define M_MCAST         0x0200  /* send/received as link-level multicast */
158
#define M_FRAG          0x0400  /* packet is a fragment of a larger packet */
159
#define M_FIRSTFRAG     0x0800  /* packet is first fragment */
160
#define M_LASTFRAG      0x1000  /* packet is last fragment */
161
 
162
#define M_AUX           0x4000  /* mbufs pointed to by m->m_pkthdr.aux */
163
 
164
/* flags copied when copying m_pkthdr */
165
#define M_COPYFLAGS     (M_PKTHDR|M_EOR|M_PROTO1|M_PROTO1|M_PROTO2|M_PROTO3| \
166
                            M_PROTO4|M_PROTO5|M_PROTO6|M_BCAST|M_MCAST|M_FRAG| \
167
                            M_AUX)
168
 
169
/* flags indicating hw checksum support and sw checksum requirements */
170
#define CSUM_IP                 0x0001          /* will csum IP */
171
#define CSUM_TCP                0x0002          /* will csum TCP */
172
#define CSUM_UDP                0x0004          /* will csum UDP */
173
#define CSUM_IP_FRAGS           0x0008          /* will csum IP fragments */
174
#define CSUM_FRAGMENT           0x0010          /* will do IP fragmentation */
175
 
176
#define CSUM_IP_CHECKED         0x0100          /* did csum IP */
177
#define CSUM_IP_VALID           0x0200          /*   ... the csum is valid */
178
#define CSUM_DATA_VALID         0x0400          /* csum_data field is valid */
179
#define CSUM_PSEUDO_HDR         0x0800          /* csum_data has pseudo hdr */
180
 
181
#define CSUM_DELAY_DATA         (CSUM_TCP | CSUM_UDP)
182
#define CSUM_DELAY_IP           (CSUM_IP)       /* XXX add ipv6 here too? */
183
 
184
/* mbuf types */
185
#define MT_FREE         0        /* should be on free list */
186
#define MT_DATA         1       /* dynamic (data) allocation */
187
#define MT_HEADER       2       /* packet header */
188
#if 0
189
#define MT_SOCKET       3       /* socket structure */
190
#define MT_PCB          4       /* protocol control block */
191
#define MT_RTABLE       5       /* routing tables */
192
#define MT_HTABLE       6       /* IMP host tables */
193
#define MT_ATABLE       7       /* address resolution tables */
194
#endif
195
#define MT_SONAME       8       /* socket name */
196
#if 0
197
#define MT_SOOPTS       10      /* socket options */
198
#endif
199
#define MT_FTABLE       11      /* fragment reassembly header */
200
#if 0
201
#define MT_RIGHTS       12      /* access rights */
202
#define MT_IFADDR       13      /* interface address */
203
#endif
204
#define MT_CONTROL      14      /* extra-data protocol message */
205
#define MT_OOBDATA      15      /* expedited data  */
206
 
207
#define MT_NTYPES       16      /* number of mbuf types for mbtypes[] */
208
 
209
/*
210
 * mbuf statistics
211
 */
212
struct mbstat {
213
        u_long  m_mbufs;        /* mbufs obtained from page pool */
214
        u_long  m_clusters;     /* clusters obtained from page pool */
215
        u_long  m_spare;        /* spare field */
216
        u_long  m_clfree;       /* free clusters */
217
        u_long  m_drops;        /* times failed to find space */
218
        u_long  m_wait;         /* times waited for space */
219
        u_long  m_drain;        /* times drained protocols for space */
220
        u_long  m_mcfail;       /* times m_copym failed */
221
        u_long  m_mpfail;       /* times m_pullup failed */
222
        u_long  m_msize;        /* length of an mbuf */
223
        u_long  m_mclbytes;     /* length of an mbuf cluster */
224
        u_long  m_minclsize;    /* min length of data to allocate a cluster */
225
        u_long  m_mlen;         /* length of data in an mbuf */
226
        u_long  m_mhlen;        /* length of data in a header mbuf */
227
 
228
        u_quad_t m_exthdrget;   /* # of calls to IP6_EXTHDR_GET */
229
        u_quad_t m_exthdrget0;  /* # of calls to IP6_EXTHDR_GET0 */
230
        u_quad_t m_pulldowns;   /* # of calls to m_pulldown */
231
        u_quad_t m_pulldown_copy; /* # of mbuf copies in m_pulldown */
232
        u_quad_t m_pulldown_alloc; /* # of mbuf allocs in m_pulldown */
233
        u_quad_t m_pullups;     /* # of calls to m_pullup */
234
        u_quad_t m_pullup_copy; /* # of possible m_pullup copies */
235
        u_quad_t m_pullup_alloc; /* # of possible m_pullup mallocs */
236
        u_quad_t m_pullup_fail; /* # of possible m_pullup failures */
237
        u_quad_t m_pullup2;     /* # of calls to m_pullup2 */
238
        u_quad_t m_pullup2_copy; /* # of possible m_pullup2 copies */
239
        u_quad_t m_pullup2_alloc; /* # of possible m_pullup2 mallocs */
240
        u_quad_t m_pullup2_fail; /* # of possible m_pullup2 failures */
241
};
242
 
243
/* flags to m_get/MGET */
244
#define M_DONTWAIT      1
245
#define M_WAIT          0
246
 
247
/* Freelists:
248
 *
249
 * Normal mbuf clusters are normally treated as character arrays
250
 * after allocation, but use the first word of the buffer as a free list
251
 * pointer while on the free list.
252
 */
253
union mcluster {
254
        union   mcluster *mcl_next;
255
        char    mcl_buf[MCLBYTES];
256
};
257
 
258
 
259
/*
260
 * These are identifying numbers passed to the m_mballoc_wait function,
261
 * allowing us to determine whether the call came from an MGETHDR or
262
 * an MGET.
263
 */
264
#define MGETHDR_C      1
265
#define MGET_C         2
266
 
267
/*
268
 * Wake up the next instance (if any) of m_mballoc_wait() which is
269
 * waiting for an mbuf to be freed.  This should be called at splimp().
270
 *
271
 * XXX: If there is another free mbuf, this routine will be called [again]
272
 * from the m_mballoc_wait routine in order to wake another sleep instance.
273
 */
274
#define MMBWAKEUP() do {                                                \
275
        if (m_mballoc_wid) {                                            \
276
                m_mballoc_wid--;                                        \
277
                wakeup_one(&m_mballoc_wid);                             \
278
        }                                                               \
279
} while (0)
280
 
281
/*
282
 * Same as above, but for mbuf cluster(s).
283
 */
284
#define MCLWAKEUP() do {                                                \
285
        if (m_clalloc_wid) {                                            \
286
                m_clalloc_wid--;                                        \
287
                wakeup_one(&m_clalloc_wid);                             \
288
        }                                                               \
289
} while (0)
290
 
291
/*
292
 * mbuf utility macros:
293
 *
294
 *      MBUFLOCK(code)
295
 * prevents a section of code from from being interrupted by network
296
 * drivers.
297
 */
298
#define MBUFLOCK(code) do {                                             \
299
        int _ms = splimp();                                             \
300
                                                                        \
301
        { code }                                                        \
302
        splx(_ms);                                                      \
303
} while (0)
304
 
305
/*
306
 * mbuf allocation/deallocation macros:
307
 *
308
 *      MGET(struct mbuf *m, int how, int type)
309
 * allocates an mbuf and initializes it to contain internal data.
310
 *
311
 *      MGETHDR(struct mbuf *m, int how, int type)
312
 * allocates an mbuf and initializes it to contain a packet header
313
 * and internal data.
314
 */
315
#define MGET(m, how, type) do {                                         \
316
        struct mbuf *_mm;                                               \
317
        int _mhow = (how);                                              \
318
        int _mtype = (type);                                            \
319
        int _ms = splimp();                                             \
320
                                                                        \
321
        if (mmbfree == NULL)                                            \
322
                (void)m_mballoc(1, _mhow);                              \
323
        _mm = mmbfree;                                                  \
324
        if (_mm != NULL) {                                              \
325
                mmbfree = _mm->m_next;                                  \
326
                mbtypes[MT_FREE]--;                                     \
327
                _mm->m_type = _mtype;                                   \
328
                mbtypes[_mtype]++;                                      \
329
                _mm->m_next = NULL;                                     \
330
                _mm->m_nextpkt = NULL;                                  \
331
                _mm->m_data = _mm->m_dat;                               \
332
                _mm->m_flags = 0;                                        \
333
                (m) = _mm;                                              \
334
                splx(_ms);                                              \
335
        } else {                                                        \
336
                splx(_ms);                                              \
337
                _mm = m_retry(_mhow, _mtype);                           \
338
                if (_mm == NULL && _mhow == M_WAIT)                     \
339
                        (m) = m_mballoc_wait(MGET_C, _mtype);           \
340
                else                                                    \
341
                        (m) = _mm;                                      \
342
        }                                                               \
343
} while (0)
344
 
345
#define MGETHDR(m, how, type) do {                                      \
346
        struct mbuf *_mm;                                               \
347
        int _mhow = (how);                                              \
348
        int _mtype = (type);                                            \
349
        int _ms = splimp();                                             \
350
                                                                        \
351
        if (mmbfree == NULL)                                            \
352
                (void)m_mballoc(1, _mhow);                              \
353
        _mm = mmbfree;                                                  \
354
        if (_mm != NULL) {                                              \
355
                mmbfree = _mm->m_next;                                  \
356
                mbtypes[MT_FREE]--;                                     \
357
                _mm->m_type = _mtype;                                   \
358
                mbtypes[_mtype]++;                                      \
359
                _mm->m_next = NULL;                                     \
360
                _mm->m_nextpkt = NULL;                                  \
361
                _mm->m_data = _mm->m_pktdat;                            \
362
                _mm->m_flags = M_PKTHDR;                                \
363
                bzero(&(_mm)->m_pkthdr, sizeof((_mm)->m_pkthdr));       \
364
                (m) = _mm;                                              \
365
                splx(_ms);                                              \
366
        } else {                                                        \
367
                splx(_ms);                                              \
368
                _mm = m_retryhdr(_mhow, _mtype);                        \
369
                if (_mm == NULL && _mhow == M_WAIT)                     \
370
                        (m) = m_mballoc_wait(MGETHDR_C, _mtype);        \
371
                else                                                    \
372
                        (m) = _mm;                                      \
373
        }                                                               \
374
} while (0)
375
 
376
/*
377
 * Mbuf cluster macros.
378
 * MCLALLOC(caddr_t p, int how) allocates an mbuf cluster.
379
 * MCLGET adds such clusters to a normal mbuf;
380
 * the flag M_EXT is set upon success.
381
 * MCLFREE releases a reference to a cluster allocated by MCLALLOC,
382
 * freeing the cluster if the reference count has reached 0.
383
 */
384
#define MCLALLOC(p, how) do {                                           \
385
        caddr_t _mp;                                                    \
386
        int _mhow = (how);                                              \
387
        int _ms = splimp();                                             \
388
                                                                        \
389
        if (mclfree == NULL)                                            \
390
                (void)m_clalloc(1, _mhow);                              \
391
        _mp = (caddr_t)mclfree;                                         \
392
        if (_mp != NULL) {                                              \
393
                mclrefcnt[mtocl(_mp)]++;                                \
394
                mbstat.m_clfree--;                                      \
395
                mclfree = ((union mcluster *)_mp)->mcl_next;            \
396
                (p) = _mp;                                              \
397
                splx(_ms);                                              \
398
        } else {                                                        \
399
                splx(_ms);                                              \
400
                if (_mhow == M_WAIT)                                    \
401
                        (p) = m_clalloc_wait();                         \
402
                else                                                    \
403
                        (p) = NULL;                                     \
404
        }                                                               \
405
} while (0)
406
 
407
#define MCLGET(m, how) do {                                             \
408
        struct mbuf *_mm = (m);                                         \
409
                                                                        \
410
        MCLALLOC(_mm->m_ext.ext_buf, (how));                            \
411
        if (_mm->m_ext.ext_buf != NULL) {                               \
412
                _mm->m_data = _mm->m_ext.ext_buf;                       \
413
                _mm->m_flags |= M_EXT;                                  \
414
                _mm->m_ext.ext_free = NULL;                             \
415
                _mm->m_ext.ext_ref = NULL;                              \
416
                _mm->m_ext.ext_size = MCLBYTES;                         \
417
        }                                                               \
418
} while (0)
419
 
420
#define MCLFREE1(p) do {                                                \
421
        union mcluster *_mp = (union mcluster *)(p);                    \
422
                                                                        \
423
        /* KASSERT(mclrefcnt[mtocl(_mp)] > 0, ("freeing free cluster")); */     \
424
        if (--mclrefcnt[mtocl(_mp)] == 0) {                              \
425
                _mp->mcl_next = mclfree;                                \
426
                mclfree = _mp;                                          \
427
                mbstat.m_clfree++;                                      \
428
                MCLWAKEUP();                                            \
429
        }                                                               \
430
} while (0)
431
 
432
#define MCLFREE(p) MBUFLOCK(                                            \
433
        MCLFREE1(p);                                                    \
434
)
435
 
436
#define MEXTFREE1(m) do {                                               \
437
                struct mbuf *_mm = (m);                                 \
438
                                                                        \
439
                if (_mm->m_ext.ext_free != NULL)                        \
440
                        (*_mm->m_ext.ext_free)(_mm->m_ext.ext_buf,      \
441
                            _mm->m_ext.ext_size);                       \
442
                else                                                    \
443
                        MCLFREE1(_mm->m_ext.ext_buf);                   \
444
} while (0)
445
 
446
#define MEXTFREE(m) MBUFLOCK(                                           \
447
        MEXTFREE1(m);                                                   \
448
)
449
 
450
/*
451
 * MFREE(struct mbuf *m, struct mbuf *n)
452
 * Free a single mbuf and associated external storage.
453
 * Place the successor, if any, in n.
454
 *
455
 * we do need to check non-first mbuf for m_aux, since some of existing
456
 * code does not call M_PREPEND properly.
457
 * (example: call to bpf_mtap from drivers)
458
 */
459
#define MFREE(m, n) MBUFLOCK(                                           \
460
        struct mbuf *_mm = (m);                                         \
461
                                                                        \
462
        /* KASSERT(_mm->m_type != MT_FREE, ("freeing free mbuf")); */           \
463
        mbtypes[_mm->m_type]--;                                         \
464
        if ((_mm->m_flags & M_PKTHDR) != 0 && _mm->m_pkthdr.aux) {       \
465
                m_freem(_mm->m_pkthdr.aux);                             \
466
                _mm->m_pkthdr.aux = NULL;                               \
467
        }                                                               \
468
        if (_mm->m_flags & M_EXT)                                       \
469
                MEXTFREE1(m);                                           \
470
        (n) = _mm->m_next;                                              \
471
        _mm->m_type = MT_FREE;                                          \
472
        mbtypes[MT_FREE]++;                                             \
473
        _mm->m_next = mmbfree;                                          \
474
        mmbfree = _mm;                                                  \
475
        MMBWAKEUP();                                                    \
476
)
477
 
478
/*
479
 * Copy mbuf pkthdr from "from" to "to".
480
 * from must have M_PKTHDR set, and to must be empty.
481
 * aux pointer will be moved to `to'.
482
 */
483
#define M_COPY_PKTHDR(to, from) do {                                    \
484
        struct mbuf *_mfrom = (from);                                   \
485
        struct mbuf *_mto = (to);                                       \
486
                                                                        \
487
        _mto->m_data = _mto->m_pktdat;                                  \
488
        _mto->m_flags = _mfrom->m_flags & M_COPYFLAGS;                  \
489
        _mto->m_pkthdr = _mfrom->m_pkthdr;                              \
490
        _mfrom->m_pkthdr.aux = (struct mbuf *)NULL;                     \
491
} while (0)
492
 
493
/*
494
 * Set the m_data pointer of a newly-allocated mbuf (m_get/MGET) to place
495
 * an object of the specified size at the end of the mbuf, longword aligned.
496
 */
497
#define M_ALIGN(m, len) do {                                            \
498
        (m)->m_data += (MLEN - (len)) & ~(sizeof(long) - 1);            \
499
} while (0)
500
 
501
/*
502
 * As above, for mbufs allocated with m_gethdr/MGETHDR
503
 * or initialized by M_COPY_PKTHDR.
504
 */
505
#define MH_ALIGN(m, len) do {                                           \
506
        (m)->m_data += (MHLEN - (len)) & ~(sizeof(long) - 1);           \
507
} while (0)
508
 
509
/*
510
 * Check if we can write to an mbuf.
511
 */
512
#define M_WRITABLE(m) (!((m)->m_flags & M_EXT) || \
513
    ((m)->m_ext.ext_free == NULL && mclrefcnt[mtocl((m)->m_ext.ext_buf)] == 1))
514
 
515
/*
516
 * Compute the amount of space available
517
 * before the current start of data in an mbuf.
518
 */
519
#define M_LEADINGSPACE(m)                                               \
520
        ((m)->m_flags & M_EXT ?                                         \
521
            /* (m)->m_data - (m)->m_ext.ext_buf */ 0 :                   \
522
            (m)->m_flags & M_PKTHDR ? (m)->m_data - (m)->m_pktdat :     \
523
            (m)->m_data - (m)->m_dat)
524
 
525
/*
526
 * Compute the amount of space available
527
 * after the end of data in an mbuf.
528
 */
529
#define M_TRAILINGSPACE(m)                                              \
530
        ((m)->m_flags & M_EXT ? (m)->m_ext.ext_buf +                    \
531
            (m)->m_ext.ext_size - ((m)->m_data + (m)->m_len) :          \
532
            &(m)->m_dat[MLEN] - ((m)->m_data + (m)->m_len))
533
 
534
/*
535
 * Arrange to prepend space of size plen to mbuf m.
536
 * If a new mbuf must be allocated, how specifies whether to wait.
537
 * If how is M_DONTWAIT and allocation fails, the original mbuf chain
538
 * is freed and m is set to NULL.
539
 */
540
#define M_PREPEND(m, plen, how) do {                                    \
541
        struct mbuf **_mmp = &(m);                                      \
542
        struct mbuf *_mm = *_mmp;                                       \
543
        int _mplen = (plen);                                            \
544
        int __mhow = (how);                                             \
545
                                                                        \
546
        if (M_LEADINGSPACE(_mm) >= _mplen) {                            \
547
                _mm->m_data -= _mplen;                                  \
548
                _mm->m_len += _mplen;                                   \
549
        } else                                                          \
550
                _mm = m_prepend(_mm, _mplen, __mhow);                   \
551
        if (_mm != NULL && _mm->m_flags & M_PKTHDR)                     \
552
                _mm->m_pkthdr.len += _mplen;                            \
553
        *_mmp = _mm;                                                    \
554
} while (0)
555
 
556
/* change mbuf to new type */
557
#define MCHTYPE(m, t) do {                                              \
558
        struct mbuf *_mm = (m);                                         \
559
        int _mt = (t);                                                  \
560
        int _ms = splimp();                                             \
561
                                                                        \
562
        mbtypes[_mm->m_type]--;                                         \
563
        mbtypes[_mt]++;                                                 \
564
        splx(_ms);                                                      \
565
        _mm->m_type = (_mt);                                            \
566
} while (0)
567
 
568
/* length to m_copy to copy all */
569
#define M_COPYALL       1000000000
570
 
571
/* compatibility with 4.3 */
572
#define m_copy(m, o, l) m_copym((m), (o), (l), M_DONTWAIT)
573
 
574
/*
575
 * pkthdr.aux type tags.
576
 */
577
struct mauxtag {
578
        int     af;
579
        int     type;
580
        void*   p;
581
};
582
 
583
#ifdef _KERNEL
584
extern  u_int            m_clalloc_wid; /* mbuf cluster wait count */
585
extern  u_int            m_mballoc_wid; /* mbuf wait count */
586
extern  int              max_linkhdr;   /* largest link-level header */
587
extern  int              max_protohdr;  /* largest protocol header */
588
extern  int              max_hdr;       /* largest link+protocol header */
589
extern  int              max_datalen;   /* MHLEN - max_hdr */
590
extern  struct mbstat    mbstat;
591
extern  u_long           mbtypes[MT_NTYPES]; /* per-type mbuf allocations */
592
extern  int              mbuf_wait;     /* mbuf sleep time */
593
extern  struct mbuf     *mbutl;         /* virtual address of mclusters */
594
extern  char            *mclrefcnt;     /* cluster reference counts */
595
extern  union mcluster  *mclfree;
596
extern  struct mbuf     *mmbfree;
597
extern  int              nmbclusters;
598
extern  int              nmbufs;
599
extern  int              nsfbufs;
600
 
601
void    m_adj __P((struct mbuf *, int));
602
void    m_cat __P((struct mbuf *,struct mbuf *));
603
int     m_clalloc __P((int, int));
604
caddr_t m_clalloc_wait __P((void));
605
void    m_copyback __P((struct mbuf *, int, int, caddr_t));
606
void    m_copydata __P((struct mbuf *,int,int,caddr_t));
607
struct  mbuf *m_copym __P((struct mbuf *, int, int, int));
608
struct  mbuf *m_copypacket __P((struct mbuf *, int));
609
struct  mbuf *m_devget __P((char *, int, int, struct ifnet *,
610
    void (*copy)(char *, caddr_t, u_int)));
611
struct  mbuf *m_dup __P((struct mbuf *, int));
612
struct  mbuf *m_free __P((struct mbuf *));
613
void    m_freem __P((struct mbuf *));
614
struct  mbuf *m_get __P((int, int));
615
struct  mbuf *m_getclr __P((int, int));
616
struct  mbuf *m_gethdr __P((int, int));
617
struct  mbuf *m_getm __P((struct mbuf *, int, int, int));
618
int     m_mballoc __P((int, int));
619
struct  mbuf *m_mballoc_wait __P((int, int));
620
struct  mbuf *m_prepend __P((struct mbuf *,int,int));
621
struct  mbuf *m_pulldown __P((struct mbuf *, int, int, int *));
622
void    m_print __P((const struct mbuf *m));
623
struct  mbuf *m_pullup __P((struct mbuf *, int));
624
struct  mbuf *m_retry __P((int, int));
625
struct  mbuf *m_retryhdr __P((int, int));
626
struct  mbuf *m_split __P((struct mbuf *,int,int));
627
struct  mbuf *m_aux_add2 __P((struct mbuf *, int, int, void *));
628
struct  mbuf *m_aux_find2 __P((struct mbuf *, int, int, void *));
629
struct  mbuf *m_aux_add __P((struct mbuf *, int, int));
630
struct  mbuf *m_aux_find __P((struct mbuf *, int, int));
631
void    m_aux_delete __P((struct mbuf *, struct mbuf *));
632
extern void *cyg_net_mbuf_alloc(void);
633
extern void *cyg_net_cluster_alloc(void );
634
#ifdef CYGDBG_NET_SHOW_MBUFS                
635
extern void cyg_net_show_mbufs(void);
636
#endif
637
#endif /* _KERNEL */
638
 
639
#endif /* !_SYS_MBUF_H_ */

powered by: WebSVN 2.1.0

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