mvec.h revision 194553
1/**************************************************************************
2 *
3 * Copyright (c) 2007,2009 Kip Macy kmacy@freebsd.org
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright notice,
10 *    this list of conditions and the following disclaimer.
11 *
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.
15 *
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.
27 *
28 * $FreeBSD: head/sys/dev/cxgb/sys/mvec.h 194553 2009-06-20 18:57:14Z kmacy $
29 *
30 ***************************************************************************/
31
32#ifndef _MVEC_H_
33#define _MVEC_H_
34#include <machine/bus.h>
35
36#define	M_DDP		0x200000	/* direct data placement mbuf */
37#define	EXT_PHYS	10		/* physical/bus address  */
38
39#define m_cur_offset	m_ext.ext_size		/* override to provide ddp offset */
40#define m_seq		m_pkthdr.csum_data	/* stored sequence */
41#define m_ddp_gl	m_ext.ext_buf		/* ddp list	*/
42#define m_ddp_flags	m_pkthdr.csum_flags	/* ddp flags	*/
43#define m_ulp_mode	m_pkthdr.tso_segsz	/* upper level protocol	*/
44
45static __inline void
46busdma_map_mbuf_fast(struct sge_txq *txq, bus_dmamap_t map,
47    struct mbuf *m, bus_dma_segment_t *seg)
48{
49#if defined(__i386__) || defined(__amd64__)
50	seg->ds_addr = pmap_kextract(mtod(m, vm_offset_t));
51	seg->ds_len = m->m_len;
52#else
53	int nsegstmp;
54
55	bus_dmamap_load_mbuf_sg(txq->entry_tag, map, m, seg,
56		    &nsegstmp, 0);
57#endif
58}
59
60int busdma_map_sg_collapse(struct sge_txq *txq, bus_dmamap_t map,
61    struct mbuf **m, bus_dma_segment_t *segs, int *nsegs);
62void busdma_map_sg_vec(struct sge_txq *txq, bus_dmamap_t map,
63    struct mbuf *m, bus_dma_segment_t *segs, int *nsegs);
64static __inline int
65busdma_map_sgl(bus_dma_segment_t *vsegs, bus_dma_segment_t *segs, int count)
66{
67	while (count--) {
68		segs->ds_addr = pmap_kextract((vm_offset_t)vsegs->ds_addr);
69		segs->ds_len = vsegs->ds_len;
70		segs++;
71		vsegs++;
72	}
73	return (0);
74}
75
76static __inline void
77m_freem_list(struct mbuf *m)
78{
79	struct mbuf *n;
80
81	while (m != NULL) {
82		n = m->m_nextpkt;
83		if (n != NULL)
84			prefetch(n);
85		m_freem(m);
86		m = n;
87	}
88}
89
90
91#endif /* _MVEC_H_ */
92