The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/dev/cxgb/sys/uipc_mvec.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /**************************************************************************
    2  *
    3  * Copyright (c) 2007-2008, 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  *
   29  ***************************************************************************/
   30 
   31 #include <sys/cdefs.h>
   32 __FBSDID("$FreeBSD: releng/8.0/sys/dev/cxgb/sys/uipc_mvec.c 195006 2009-06-25 21:50:15Z np $");
   33 
   34 #include <sys/param.h>
   35 #include <sys/systm.h>
   36 #include <sys/kernel.h>
   37 #include <sys/lock.h>
   38 #include <sys/malloc.h>
   39 #include <sys/mbuf.h>
   40 #include <sys/ktr.h>
   41 #include <sys/sf_buf.h>
   42 
   43 #include <vm/vm.h>
   44 #include <vm/pmap.h>
   45 
   46 #include <machine/bus.h>
   47 
   48 #include <cxgb_include.h>
   49 #include <sys/mvec.h>
   50 
   51 #include <vm/vm.h>
   52 #include <vm/vm_page.h>
   53 #include <vm/pmap.h>
   54 
   55 #ifdef INVARIANTS
   56 #define M_SANITY m_sanity
   57 #else
   58 #define M_SANITY(a, b)
   59 #endif
   60 
   61 int
   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)
   64 {
   65         struct mbuf *n = *m;
   66         int seg_count, defragged = 0, err = 0;
   67         bus_dma_segment_t *psegs;
   68         
   69         KASSERT(n->m_pkthdr.len, ("packet has zero header len"));
   70         if (n->m_pkthdr.len <= PIO_LEN)
   71                 return (0);
   72 retry:
   73         psegs = segs;
   74         seg_count = 0;
   75         if (n->m_next == NULL) {
   76                 busdma_map_mbuf_fast(tag, map, n, segs);
   77                 *nsegs = 1;
   78                 return (0);
   79         }
   80 #if defined(__i386__) || defined(__amd64__)
   81         while (n && seg_count < TX_MAX_SEGS) {
   82                 /*
   83                  * firmware doesn't like empty segments
   84                  */
   85                 if (__predict_true(n->m_len != 0)) {
   86                         seg_count++;
   87                         busdma_map_mbuf_fast(tag, map, n, psegs);
   88                         psegs++;
   89                 }
   90                 n = n->m_next;
   91         }
   92 #else
   93         err = bus_dmamap_load_mbuf_sg(tag, map, *m, segs, &seg_count, 0);
   94 #endif  
   95         if (seg_count == 0) {
   96                 if (cxgb_debug)
   97                         printf("empty segment chain\n");
   98                 err = EFBIG;
   99                 goto err_out;
  100         }  else if (err == EFBIG || seg_count >= TX_MAX_SEGS) {
  101                 if (cxgb_debug)
  102                         printf("mbuf chain too long: %d max allowed %d\n",
  103                             seg_count, TX_MAX_SEGS);
  104                 if (!defragged) {
  105                         n = m_defrag(*m, M_DONTWAIT);
  106                         if (n == NULL) {
  107                                 err = ENOBUFS;
  108                                 goto err_out;
  109                         }
  110                         *m = n;
  111                         defragged = 1;
  112                         goto retry;
  113                 }
  114                 err = EFBIG;
  115                 goto err_out;
  116         }
  117 
  118         *nsegs = seg_count;
  119 err_out:        
  120         return (err);
  121 }
  122 
  123 void
  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)
  126 {
  127 
  128         for (*nsegs = 0; m != NULL ; segs++, *nsegs += 1, m = m->m_nextpkt)
  129                 busdma_map_mbuf_fast(tag, map, m, segs);
  130 }
  131 

Cache object: 55d92a6c557f3be60daa156ce8258b8a


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.