ixgbe: minor rework offloading bits fix
[dpdk.git] / lib / librte_pmd_ixgbe / ixgbe_rxtx.c
index 6f82918..a1c1372 100644 (file)
@@ -1,7 +1,7 @@
 /*-
  *   BSD LICENSE
  * 
- *   Copyright(c) 2010-2013 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
  *   All rights reserved.
  * 
  *   Redistribution and use in source and binary forms, with or without
@@ -33,7 +33,6 @@
 
 #include <sys/queue.h>
 
-#include <endian.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -77,6 +76,7 @@
 #include "ixgbe/ixgbe_vf.h"
 #include "ixgbe_ethdev.h"
 #include "ixgbe/ixgbe_dcb.h"
+#include "ixgbe/ixgbe_common.h"
 
 
 #define RTE_PMD_IXGBE_TX_MAX_BURST 32
@@ -1063,12 +1063,11 @@ ixgbe_rx_scan_hw_ring(struct igb_rx_queue *rxq)
                for (j = LOOK_AHEAD-1; j >= 0; --j)
                        s[j] = rxdp[j].wb.upper.status_error;
 
-               /* Clear everything but the status bits (LSB) */
+               /* Compute how many status bits were set */
+               nb_dd = 0;
                for (j = 0; j < LOOK_AHEAD; ++j)
-                       s[j] &= IXGBE_RXDADV_STAT_DD;
+                       nb_dd += s[j] & IXGBE_RXDADV_STAT_DD;
 
-               /* Compute how many status bits were set */
-               nb_dd = s[0]+s[1]+s[2]+s[3]+s[4]+s[5]+s[6]+s[7];
                nb_rx += nb_dd;
 
                /* Translate descriptor info to mbuf format */
@@ -1758,8 +1757,13 @@ ring_dma_zone_reserve(struct rte_eth_dev *dev, const char *ring_name,
        if (mz)
                return mz;
 
+#ifdef RTE_LIBRTE_XEN_DOM0
+       return rte_memzone_reserve_bounded(z_name, ring_size,
+               socket_id, 0, IXGBE_ALIGN, RTE_PGSIZE_2M);
+#else
        return rte_memzone_reserve_aligned(z_name, ring_size,
-                       socket_id, 0, IXGBE_ALIGN);
+               socket_id, 0, IXGBE_ALIGN);
+#endif
 }
 
 static void
@@ -1813,9 +1817,9 @@ ixgbe_reset_tx_queue(struct igb_tx_queue *txq)
                volatile union ixgbe_adv_tx_desc *txd = &txq->tx_ring[i];
                txd->wb.status = IXGBE_TXD_STAT_DD;
                txe[i].mbuf = NULL;
-               txe[i].last_id = i;
-               txe[prev].next_id = i;
-               prev = i;
+               txe[i].last_id = (uint16_t)i;
+               txe[prev].next_id = (uint16_t)i;
+               prev = (uint16_t)i;
        }
 
        txq->tx_next_dd = (uint16_t)(txq->tx_rs_thresh - 1);
@@ -1971,8 +1975,11 @@ ixgbe_dev_tx_queue_setup(struct rte_eth_dev *dev,
                txq->tdt_reg_addr = IXGBE_PCI_REG_ADDR(hw, IXGBE_VFTDT(queue_idx));
        else
                txq->tdt_reg_addr = IXGBE_PCI_REG_ADDR(hw, IXGBE_TDT(txq->reg_idx));
-
+#ifndef        RTE_LIBRTE_XEN_DOM0 
        txq->tx_ring_phys_addr = (uint64_t) tz->phys_addr;
+#else
+       txq->tx_ring_phys_addr = rte_mem_phy2mch(tz->memseg_id, tz->phys_addr);
+#endif
        txq->tx_ring = (union ixgbe_adv_tx_desc *) tz->addr;
 
        /* Allocate software ring */
@@ -2221,8 +2228,11 @@ ixgbe_dev_rx_queue_setup(struct rte_eth_dev *dev,
                rxq->rdh_reg_addr =
                        IXGBE_PCI_REG_ADDR(hw, IXGBE_RDH(rxq->reg_idx));
        }
-
+#ifndef RTE_LIBRTE_XEN_DOM0
        rxq->rx_ring_phys_addr = (uint64_t) rz->phys_addr;
+#else
+       rxq->rx_ring_phys_addr = rte_mem_phy2mch(rz->memseg_id, rz->phys_addr);
+#endif
        rxq->rx_ring = (union ixgbe_adv_rx_desc *) rz->addr;
 
        /*
@@ -3215,10 +3225,7 @@ ixgbe_dev_mq_rx_configure(struct rte_eth_dev *dev)
                 * SRIOV inactive scheme
                 * any DCB/RSS w/o VMDq multi-queue setting
                 */
-               if (dev->data->nb_rx_queues > 1)
-                       switch (dev->data->dev_conf.rxmode.mq_mode) {
-                       case ETH_MQ_RX_NONE:
-                               /* if mq_mode not assign, we use rss mode.*/
+               switch (dev->data->dev_conf.rxmode.mq_mode) {
                        case ETH_MQ_RX_RSS:
                                ixgbe_rss_configure(dev);
                                break;
@@ -3231,10 +3238,10 @@ ixgbe_dev_mq_rx_configure(struct rte_eth_dev *dev)
                                ixgbe_vmdq_rx_hw_configure(dev);
                                break;
                        
+                       case ETH_MQ_RX_NONE:
+                               /* if mq_mode is none, disable rss mode.*/
                        default: ixgbe_rss_disable(dev);
-                       }
-               else
-                       ixgbe_rss_disable(dev);
+               }
        } else {
                switch (RTE_ETH_DEV_SRIOV(dev).active) {
                /*
@@ -3377,6 +3384,15 @@ ixgbe_dev_rx_init(struct rte_eth_dev *dev)
        } else
                hlreg0 &= ~IXGBE_HLREG0_JUMBOEN;
 
+       /*
+        * If loopback mode is configured for 82599, set LPBK bit.
+        */
+       if (hw->mac.type == ixgbe_mac_82599EB &&
+                       dev->data->dev_conf.lpbk_mode == IXGBE_LPBK_82599_TX_RX)
+               hlreg0 |= IXGBE_HLREG0_LPBK;
+       else
+               hlreg0 &= ~IXGBE_HLREG0_LPBK;
+
        IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
 
        /* Setup RX queues */
@@ -3440,8 +3456,7 @@ ixgbe_dev_rx_init(struct rte_eth_dev *dev)
                 * The value is in 1 KB resolution. Valid values can be from
                 * 1 KB to 16 KB.
                 */
-               mbp_priv = (struct rte_pktmbuf_pool_private *)
-                       ((char *)rxq->mb_pool + sizeof(struct rte_mempool));
+               mbp_priv = rte_mempool_get_priv(rxq->mb_pool);
                buf_size = (uint16_t) (mbp_priv->mbuf_data_room_size -
                                       RTE_PKTMBUF_HEADROOM);
                srrctl |= ((buf_size >> IXGBE_SRRCTL_BSIZEPKT_SHIFT) &
@@ -3556,6 +3571,34 @@ ixgbe_dev_tx_init(struct rte_eth_dev *dev)
        ixgbe_dev_mq_tx_configure(dev);
 }
 
+/*
+ * Set up link for 82599 loopback mode Tx->Rx.
+ */
+static inline void
+ixgbe_setup_loopback_link_82599(struct ixgbe_hw *hw)
+{
+       DEBUGFUNC("ixgbe_setup_loopback_link_82599");
+
+       if (ixgbe_verify_lesm_fw_enabled_82599(hw)) {
+               if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_MAC_CSR_SM) !=
+                               IXGBE_SUCCESS) {
+                       PMD_INIT_LOG(ERR, "Could not enable loopback mode\n");
+                       /* ignore error */
+                       return;
+               }
+       }
+
+       /* Restart link */
+       IXGBE_WRITE_REG(hw,
+                       IXGBE_AUTOC,
+                       IXGBE_AUTOC_LMS_10G_LINK_NO_AN | IXGBE_AUTOC_FLU);
+       ixgbe_reset_pipeline_82599(hw);
+
+       hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_MAC_CSR_SM);
+       msec_delay(50);
+}
+
+
 /*
  * Start Transmit and Receive Units.
  */
@@ -3634,6 +3677,12 @@ ixgbe_dev_rxtx_start(struct rte_eth_dev *dev)
                rxctrl |= IXGBE_RXCTRL_DMBYPS;
        rxctrl |= IXGBE_RXCTRL_RXEN;
        hw->mac.ops.enable_rx_dma(hw, rxctrl);
+
+       /* If loopback mode is enabled for 82599, set up the link accordingly */
+       if (hw->mac.type == ixgbe_mac_82599EB &&
+                       dev->data->dev_conf.lpbk_mode == IXGBE_LPBK_82599_TX_RX)
+               ixgbe_setup_loopback_link_82599(hw);
+
 }
 
 
@@ -3712,8 +3761,7 @@ ixgbevf_dev_rx_init(struct rte_eth_dev *dev)
                 * The value is in 1 KB resolution. Valid values can be from
                 * 1 KB to 16 KB.
                 */
-               mbp_priv = (struct rte_pktmbuf_pool_private *)
-                       ((char *)rxq->mb_pool + sizeof(struct rte_mempool));
+               mbp_priv = rte_mempool_get_priv(rxq->mb_pool);
                buf_size = (uint16_t) (mbp_priv->mbuf_data_room_size -
                                       RTE_PKTMBUF_HEADROOM);
                srrctl |= ((buf_size >> IXGBE_SRRCTL_BSIZEPKT_SHIFT) &