1 /* mbuf.h 4.11 82/01/24 */ 2 3 /* 4 * Constants related to memory allocator. 5 */ 6 #define MSIZE 128 /* size of an mbuf */ 7 #define MMINOFF 12 /* mbuf header length */ 8 #define MTAIL 4 9 #define MMAXOFF (MSIZE-MTAIL) /* offset where data ends */ 10 #define MLEN (MSIZE-MMINOFF-MTAIL) /* mbuf data length */ 11 #define NMBCLUSTERS 256 12 13 /* 14 * Macros for type conversion 15 */ 16 17 /* network cluster number to virtual address, and back */ 18 #define cltom(x) ((struct mbuf *)((int)mbutl + ((x) << CLSHIFT))) 19 #define mtocl(x) (((int)x - (int)mbutl) >> CLSHIFT) 20 21 /* address in mbuf to mbuf head */ 22 #define dtom(x) ((struct mbuf *)((int)x & ~(MSIZE-1))) 23 24 /* mbuf head, to typed data */ 25 #define mtod(x,t) ((t)((int)(x) + (x)->m_off)) 26 27 struct mbuf { 28 struct mbuf *m_next; /* next buffer in chain */ 29 u_long m_off; /* offset of data */ 30 short m_len; /* amount of data in this mbuf */ 31 short m_free; /* is mbuf free? (consistency check) */ 32 u_char m_dat[MLEN]; /* data storage */ 33 struct mbuf *m_act; /* link in higher-level mbuf list */ 34 }; 35 36 /* flags to m_get */ 37 #define M_DONTWAIT 0 38 #define M_WAIT 1 39 40 /* flags to m_pgalloc */ 41 #define MPG_MBUFS 0 /* put new mbufs on free list */ 42 #define MPG_CLUSTERS 1 /* put new clusters on free list */ 43 #define MPG_SPACE 2 /* don't free; caller wants space */ 44 45 /* length to m_copy to copy all */ 46 #define M_COPYALL 1000000000 47 48 #define MGET(m, i) \ 49 { int ms = splimp(); \ 50 if ((m)=mfree) \ 51 { if ((m)->m_free == 0) panic("mget"); (m)->m_free = 0; \ 52 mbstat.m_bufs--; mfree = (m)->m_next; (m)->m_next = 0; } \ 53 else \ 54 (m) = m_more(i); \ 55 splx(ms); } 56 #define MCLGET(m, i) \ 57 { int ms = splimp(); \ 58 if ((m)=mclfree) \ 59 { ++mclrefcnt[mtocl(m)]; nmclfree--; mclfree = (m)->m_next; } \ 60 splx(ms); } 61 #define MFREE(m, n) \ 62 { int ms = splimp(); \ 63 if ((m)->m_free) panic("mfree"); (m)->m_free = 1; \ 64 if ((m)->m_off > MSIZE) { \ 65 (n) = (struct mbuf *)(mtod(m, int)&~0x3ff); \ 66 if (--mclrefcnt[mtocl(n)] == 0) \ 67 { (n)->m_next = mclfree; mclfree = (n); nmclfree++; } \ 68 } \ 69 (n) = (m)->m_next; (m)->m_next = mfree; \ 70 (m)->m_off = 0; (m)->m_act = 0; mfree = (m); mbstat.m_bufs++; \ 71 splx(ms); } 72 73 struct mbstat { 74 short m_bufs; /* # free msg buffers */ 75 short m_hiwat; /* # free mbufs allocated */ 76 short m_lowat; /* min. # free mbufs */ 77 short m_clusters; /* # pages owned by network */ 78 short m_drops; /* times failed to find space */ 79 }; 80 81 #ifdef KERNEL 82 extern struct mbuf mbutl[]; /* virtual address of net free mem */ 83 extern struct pte Mbmap[]; /* page tables to map Netutl */ 84 struct mbstat mbstat; 85 int nmbclusters; 86 struct mbuf *mfree, *mclfree; 87 int nmclfree; 88 char mclrefcnt[NMBCLUSTERS]; 89 struct mbuf *m_get(),*m_getclr(),*m_free(),*m_more(),*m_copy(),*m_pullup(); 90 caddr_t m_clalloc(); 91 #endif 92