Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / dev / pci / cxgb_mvec.h
blob73545a0b0dd9e6adadea50ef8bfd594cdcd5370d
1 /**************************************************************************
3 * Copyright (c) 2007, Kip Macy kmacy@freebsd.org
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
9 * 1. Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
12 * 2. The name of Kip Macy nor the names of other
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
28 * $FreeBSD: src/sys/dev/cxgb/sys/mvec.h,v 1.5 2007/05/25 16:42:25 kmacy Exp $
30 ***************************************************************************/
32 #ifndef _MVEC_H_
33 #define _MVEC_H_
35 #include <sys/mbuf.h>
37 #define mtomv(m) ((struct mbuf_vec *)((m)->m_pktdat))
39 #define M_IOVEC 0x100000 /* mbuf immediate data area is used for cluster ptrs */
40 #define MBUF_IOV_TYPE_MASK ((1<<3)-1)
41 #define mbuf_vec_set_type(mv, i, type) \
42 (mv)->mv_vec[(i)].mi_flags = (((mv)->mv_vec[(i)].mi_flags \
43 & ~MBUF_IOV_TYPE_MASK) | type)
45 #define mbuf_vec_get_type(mv, i) \
46 ((mv)->mv_vec[(i)].mi_flags & MBUF_IOV_TYPE_MASK)
49 struct mbuf_iovec {
50 uint16_t mi_flags; /* per-cluster flags */
51 uint16_t mi_len; /* length of cluster */
52 uint32_t mi_offset; /* data offsets into cluster */
53 uint8_t *mi_base; /* pointers to cluster */
54 volatile uint32_t *mi_refcnt; /* refcnt for cluster*/
55 #ifdef __i386__
56 void *mi_args; /* for sf_buf */
57 #endif
60 #define MAX_MBUF_IOV ((MHLEN-8)/sizeof(struct mbuf_iovec))
61 struct mbuf_vec {
62 uint16_t mv_first; /* first valid cluster */
63 uint16_t mv_count; /* # of clusters */
64 uint32_t mv_flags; /* flags for iovec */
65 struct mbuf_iovec mv_vec[MAX_MBUF_IOV];
68 int _m_explode(struct mbuf *);
69 int _m_collapse(struct mbuf *, int maxbufs, struct mbuf **);
70 void mb_free_vec(struct mbuf *m);
72 static inline void
73 m_iovinit(struct mbuf *m)
75 struct mbuf_vec *mv = mtomv(m);
77 mv->mv_first = mv->mv_count = 0;
78 m->m_pkthdr.len = m->m_len = 0;
79 m->m_flags |= M_IOVEC;
82 static inline void
83 m_iovappend(struct mbuf *m, uint8_t *cl, int size, int len, int offset)
85 struct mbuf_vec *mv = mtomv(m);
86 struct mbuf_iovec *iov;
87 int idx = mv->mv_first + mv->mv_count;
89 #ifdef __FreeBSD__
90 KASSERT(idx <= MAX_MBUF_IOV, ("tried to append too many clusters to mbuf iovec"));
91 #endif
92 if ((m->m_flags & M_EXT) != 0)
93 panic("invalid flags in %s", __func__);
95 if (mv->mv_count == 0)
96 m->m_data = cl + offset;
98 iov = &mv->mv_vec[idx];
99 #ifdef __FreeBSD__
100 iov->mi_flags = m_gettype(size);
101 #endif
102 iov->mi_base = cl;
103 iov->mi_len = len;
104 iov->mi_offset = offset;
105 m->m_pkthdr.len += len;
106 m->m_len += len;
107 mv->mv_count++;
110 static inline int
111 m_explode(struct mbuf *m)
113 if ((m->m_flags & M_IOVEC) == 0)
114 return (0);
116 return _m_explode(m);
119 static inline int
120 m_collapse(struct mbuf *m, int maxbufs, struct mbuf **mnew)
122 #if (!defined(__sparc64__) && !defined(__sun4v__))
123 if (m->m_next == NULL)
124 #endif
126 *mnew = m;
127 return (0);
129 return _m_collapse(m, maxbufs, mnew);
132 static inline struct mbuf *
133 m_free_vec(struct mbuf *m)
135 #ifdef __FreeBSD__
136 struct mbuf *n = m->m_next;
138 if (m->m_flags & M_IOVEC)
139 mb_free_vec(m);
140 else if (m->m_flags & M_EXT)
141 mb_free_ext(m);
142 else
143 uma_zfree(zone_mbuf, m);
144 #endif
145 #ifdef __NetBSD__
146 struct mbuf *n = NULL;
148 MFREE(m, n);
149 #endif
150 return (n);
153 static inline void
154 m_freem_vec(struct mbuf *m)
156 while (m != NULL)
157 m = m_free_vec(m);
160 #ifdef __FreeBSD__
161 static inline uma_zone_t
162 m_getzonefromtype(int type)
164 uma_zone_t zone;
166 switch (type) {
167 case EXT_MBUF:
168 zone = zone_mbuf;
169 break;
170 case EXT_CLUSTER:
171 zone = zone_clust;
172 break;
173 #if MJUMPAGESIZE != MCLBYTES
174 case EXT_JUMBOP:
175 zone = zone_jumbop;
176 break;
177 #endif
178 case EXT_JUMBO9:
179 zone = zone_jumbo9;
180 break;
181 case EXT_JUMBO16:
182 zone = zone_jumbo16;
183 break;
184 #ifndef PACKET_ZONE_DISABLED
185 case EXT_PACKET:
186 zone = zone_pack;
187 break;
188 #endif
189 default:
190 panic("%s: invalid cluster type %d", __func__, type);
192 return (zone);
194 #endif
196 #if (!defined(__sparc64__) && !defined(__sun4v__))
198 bus_dmamap_load_mvec_sg(bus_dma_tag_t dmat, bus_dmamap_t map, struct mbuf *m0,
199 bus_dma_segment_t *segs, int *nsegs, int flags);
201 #else
202 #define bus_dmamap_load_mvec_sg bus_dmamap_load_mbuf_sg
203 #endif
205 #endif