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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [net/] [bsd_tcpip/] [v2_0/] [include/] [sys/] [mbuf.h] - Blame information for rev 174

Details | Compare with Previous | View Log

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