ixgbe: Rework ixgbe_xmit()
authorFrançois Tigeot <ftigeot@wolfpond.org>
Tue, 21 Aug 2012 19:42:33 +0000 (21:42 +0200)
committerFrançois Tigeot <ftigeot@wolfpond.org>
Tue, 21 Aug 2012 20:34:58 +0000 (22:34 +0200)
* Use bus_dmamap_load_mbuf_segment()

* Clean up error handling code, following the example of the igb(4)
  driver

sys/dev/netif/ixgbe/ixgbe.c
sys/dev/netif/ixgbe/ixgbe.h

index 3a3c4dc..94aad20 100644 (file)
@@ -1744,10 +1744,10 @@ ixgbe_xmit(struct tx_ring *txr, struct mbuf **m_headp)
        struct adapter  *adapter = txr->adapter;
        u32             olinfo_status = 0, cmd_type_len;
        u32             paylen = 0;
        struct adapter  *adapter = txr->adapter;
        u32             olinfo_status = 0, cmd_type_len;
        u32             paylen = 0;
-       int             i, j, error, nsegs;
+       int             i, j, error, nsegs, maxsegs;
        int             first, last = 0;
        struct mbuf     *m_head;
        int             first, last = 0;
        struct mbuf     *m_head;
-       bus_dma_segment_t segs[1];
+       bus_dma_segment_t segs[adapter->num_segs];
        bus_dmamap_t    map;
        struct ixgbe_tx_buf *txbuf;
        union ixgbe_adv_tx_desc *txd = NULL;
        bus_dmamap_t    map;
        struct ixgbe_tx_buf *txbuf;
        union ixgbe_adv_tx_desc *txd = NULL;
@@ -1773,39 +1773,18 @@ ixgbe_xmit(struct tx_ring *txr, struct mbuf **m_headp)
        /*
         * Map the packet for DMA.
         */
        /*
         * Map the packet for DMA.
         */
-       error = bus_dmamap_load_mbuf_segment(txr->txtag, map,
-           *m_headp, segs, 1, &nsegs, BUS_DMA_NOWAIT);
+       maxsegs = txr->tx_avail - IXGBE_TX_RESERVED;
+       if (maxsegs > adapter->num_segs)
+               maxsegs = adapter->num_segs;
 
 
-       if (error == EFBIG) {
-               struct mbuf *m;
-
-               m = m_defrag(*m_headp, MB_DONTWAIT);
-               if (m == NULL) {
+       error = bus_dmamap_load_mbuf_defrag(txr->txtag, map, m_headp,
+           segs, maxsegs, &nsegs, BUS_DMA_NOWAIT);
+       if (error) {
+               if (error == ENOBUFS)
                        adapter->mbuf_defrag_failed++;
                        adapter->mbuf_defrag_failed++;
-                       m_freem(*m_headp);
-                       *m_headp = NULL;
-                       return (ENOBUFS);
-               }
-               *m_headp = m;
-
-               /* Try it again */
-               error = bus_dmamap_load_mbuf_segment(txr->txtag, map,
-                   *m_headp, segs, 1, &nsegs, BUS_DMA_NOWAIT);
-
-               if (error == ENOMEM) {
-                       adapter->no_tx_dma_setup++;
-                       return (error);
-               } else if (error != 0) {
+               else
                        adapter->no_tx_dma_setup++;
                        adapter->no_tx_dma_setup++;
-                       m_freem(*m_headp);
-                       *m_headp = NULL;
-                       return (error);
-               }
-       } else if (error == ENOMEM) {
-               adapter->no_tx_dma_setup++;
-               return (error);
-       } else if (error != 0) {
-               adapter->no_tx_dma_setup++;
+
                m_freem(*m_headp);
                *m_headp = NULL;
                return (error);
                m_freem(*m_headp);
                *m_headp = NULL;
                return (error);
index 1acee05..4cdbbec 100644 (file)
 /* Offload bits in mbuf flag */
 #define CSUM_OFFLOAD           (CSUM_IP|CSUM_TCP|CSUM_UDP)
 
 /* Offload bits in mbuf flag */
 #define CSUM_OFFLOAD           (CSUM_IP|CSUM_TCP|CSUM_UDP)
 
+/* One for TX csum offloading desc, the other 2 are reserved */
+#define IXGBE_TX_RESERVED              3
+
 /*
  * Interrupt Moderation parameters 
  */
 /*
  * Interrupt Moderation parameters 
  */