Author: delphij
Date: Mon Jun  1 10:49:08 2009
New Revision: 193220
URL: http://svn.freebsd.org/changeset/base/193220

Log:
  DMA synchronization fixes:
  
   - In bce_rx_intr(), use BUS_DMASYNC_POSTREAD instead of
     BUS_DMASYNC_POSTWRITE, as we want to "read" from the
     rx page chain pages.
   - Document why we need to do PREWRITE after we have updated
     the rx page chain pages.
   - In bce_intr(), use BUS_DMASYNC_POSTREAD and
     BUS_DMASYNC_PREREAD when before and after CPU "reading"
     the status block.
   - Adjust some nearby style mismatches/etc.
  
  Pointed out by:       yongari
  Approved by:  davidch (no objection) but bugs are mine :)

Modified:
  stable/7/sys/   (props changed)
  stable/7/sys/contrib/pf/   (props changed)
  stable/7/sys/dev/ath/ath_hal/   (props changed)
  stable/7/sys/dev/bce/if_bce.c
  stable/7/sys/dev/cxgb/   (props changed)

Modified: stable/7/sys/dev/bce/if_bce.c
==============================================================================
--- stable/7/sys/dev/bce/if_bce.c       Mon Jun  1 10:41:38 2009        
(r193219)
+++ stable/7/sys/dev/bce/if_bce.c       Mon Jun  1 10:49:08 2009        
(r193220)
@@ -4884,7 +4884,7 @@ bce_get_rx_buf(struct bce_softc *sc, str
        KASSERT(nsegs == 1, ("%s(): Too many segments returned (%d)!",
                 __FUNCTION__, nsegs));
 
-       /* ToDo: Do we need bus_dmamap_sync(,,BUS_DMASYNC_PREWRITE) here? */
+       /* ToDo: Do we need bus_dmamap_sync(,,BUS_DMASYNC_PREREAD) here? */
 
        /* Setup the rx_bd for the segment. */
        rxbd = &sc->rx_bd_chain[RX_PAGE(*chain_prod)][RX_IDX(*chain_prod)];
@@ -4993,7 +4993,7 @@ bce_get_pg_buf(struct bce_softc *sc, str
                goto bce_get_pg_buf_exit;
        }
 
-       /* ToDo: Do we need bus_dmamap_sync(,,BUS_DMASYNC_PREWRITE) here? */
+       /* ToDo: Do we need bus_dmamap_sync(,,BUS_DMASYNC_PREREAD) here? */
 
        /*
         * The page chain uses the same rx_bd data structure
@@ -5270,13 +5270,11 @@ bce_init_rx_chain(struct bce_softc *sc)
                rxbd->rx_bd_haddr_lo = 
htole32(BCE_ADDR_LO(sc->rx_bd_chain_paddr[j]));
        }
 
-/* Fill up the RX chain. */
+       /* Fill up the RX chain. */
        bce_fill_rx_chain(sc);
 
        for (i = 0; i < RX_PAGES; i++) {
-               bus_dmamap_sync(
-                       sc->rx_bd_chain_tag,
-               sc->rx_bd_chain_map[i],
+               bus_dmamap_sync(sc->rx_bd_chain_tag, sc->rx_bd_chain_map[i],
                    BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
        }
 
@@ -5447,9 +5445,7 @@ bce_init_pg_chain(struct bce_softc *sc)
        bce_fill_pg_chain(sc);
 
        for (i = 0; i < PG_PAGES; i++) {
-               bus_dmamap_sync(
-                       sc->pg_bd_chain_tag,
-               sc->pg_bd_chain_map[i],
+               bus_dmamap_sync(sc->pg_bd_chain_tag, sc->pg_bd_chain_map[i],
                    BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
        }
 
@@ -5732,13 +5728,13 @@ bce_rx_intr(struct bce_softc *sc)
        /* Prepare the RX chain pages to be accessed by the host CPU. */
        for (int i = 0; i < RX_PAGES; i++)
                bus_dmamap_sync(sc->rx_bd_chain_tag,
-                   sc->rx_bd_chain_map[i], BUS_DMASYNC_POSTWRITE);
+                   sc->rx_bd_chain_map[i], BUS_DMASYNC_POSTREAD);
 
 #ifdef ZERO_COPY_SOCKETS
        /* Prepare the page chain pages to be accessed by the host CPU. */
        for (int i = 0; i < PG_PAGES; i++)
                bus_dmamap_sync(sc->pg_bd_chain_tag,
-                   sc->pg_bd_chain_map[i], BUS_DMASYNC_POSTWRITE);
+                   sc->pg_bd_chain_map[i], BUS_DMASYNC_POSTREAD);
 #endif
 
        /* Get the hardware's view of the RX consumer index. */
@@ -5765,9 +5761,8 @@ bce_rx_intr(struct bce_softc *sc)
                sw_rx_cons_idx = RX_CHAIN_IDX(sw_rx_cons);
 
                /* Unmap the mbuf from DMA space. */
-               bus_dmamap_sync(sc->rx_mbuf_tag,
-                   sc->rx_mbuf_map[sw_rx_cons_idx],
-               BUS_DMASYNC_POSTREAD);
+               bus_dmamap_sync(sc->rx_mbuf_tag, 
sc->rx_mbuf_map[sw_rx_cons_idx],
+                   BUS_DMASYNC_POSTREAD);
                bus_dmamap_unload(sc->rx_mbuf_tag,
                    sc->rx_mbuf_map[sw_rx_cons_idx]);
 
@@ -6011,6 +6006,7 @@ bce_rx_int_next_rx:
        sc->rx_cons = sw_rx_cons;
        bce_fill_rx_chain(sc);
 
+       /* Prepare the page chain pages to be accessed by the NIC. */
        for (int i = 0; i < RX_PAGES; i++)
                bus_dmamap_sync(sc->rx_bd_chain_tag,
                    sc->rx_bd_chain_map[i], BUS_DMASYNC_PREWRITE);
@@ -7023,8 +7019,9 @@ bce_intr(void *xsc)
 
        DBRUN(sc->interrupts_generated++);
 
+       /* Synchnorize before we read from interface's status block */
        bus_dmamap_sync(sc->status_tag, sc->status_map,
-           BUS_DMASYNC_POSTWRITE);
+           BUS_DMASYNC_POSTREAD);
 
        /*
         * If the hardware status block index
@@ -7112,7 +7109,7 @@ bce_intr(void *xsc)
        }
 
        bus_dmamap_sync(sc->status_tag, sc->status_map,
-           BUS_DMASYNC_PREWRITE);
+           BUS_DMASYNC_PREREAD);
 
        /* Re-enable interrupts. */
        bce_enable_intr(sc, 0);
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to