1 /**************************************************************************
3 * Copyright (c) 2007-2008, Kip Macy kmacy@freebsd.org
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.
29 ***************************************************************************/
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/kernel.h>
38 #include <sys/malloc.h>
41 #include <sys/sf_buf.h>
46 #include <machine/bus.h>
48 #include <cxgb_include.h>
52 #include <vm/vm_page.h>
56 #define M_SANITY m_sanity
58 #define M_SANITY(a, b)
62 busdma_map_sg_collapse(bus_dma_tag_t tag, bus_dmamap_t map,
63 struct mbuf **m, bus_dma_segment_t *segs, int *nsegs)
66 int seg_count, defragged = 0, err = 0;
67 bus_dma_segment_t *psegs;
69 KASSERT(n->m_pkthdr.len, ("packet has zero header len"));
70 if (n->m_pkthdr.len <= PIO_LEN)
75 if (n->m_next == NULL) {
76 busdma_map_mbuf_fast(tag, map, n, segs);
80 #if defined(__i386__) || defined(__amd64__)
81 while (n && seg_count < TX_MAX_SEGS) {
83 * firmware doesn't like empty segments
85 if (__predict_true(n->m_len != 0)) {
87 busdma_map_mbuf_fast(tag, map, n, psegs);
93 err = bus_dmamap_load_mbuf_sg(tag, map, *m, segs, &seg_count, 0);
97 printf("empty segment chain\n");
100 } else if (err == EFBIG || seg_count >= TX_MAX_SEGS) {
102 printf("mbuf chain too long: %d max allowed %d\n",
103 seg_count, TX_MAX_SEGS);
105 n = m_defrag(*m, M_DONTWAIT);
124 busdma_map_sg_vec(bus_dma_tag_t tag, bus_dmamap_t map,
125 struct mbuf *m, bus_dma_segment_t *segs, int *nsegs)
128 for (*nsegs = 0; m != NULL ; segs++, *nsegs += 1, m = m->m_nextpkt)
129 busdma_map_mbuf_fast(tag, map, m, segs);