doc: whitespace changes in licenses
[dpdk.git] / lib / librte_pmd_e1000 / igb_rxtx.c
index b59e1aa..334082d 100644 (file)
@@ -1,35 +1,34 @@
 /*-
  *   BSD LICENSE
  * 
- *   Copyright(c) 2010-2012 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2010-2013 Intel Corporation. All rights reserved.
  *   All rights reserved.
  * 
- *   Redistribution and use in source and binary forms, with or without 
- *   modification, are permitted provided that the following conditions 
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
  *   are met:
  * 
- *     * Redistributions of source code must retain the above copyright 
+ *     * Redistributions of source code must retain the above copyright
  *       notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above copyright 
- *       notice, this list of conditions and the following disclaimer in 
- *       the documentation and/or other materials provided with the 
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
  *       distribution.
- *     * Neither the name of Intel Corporation nor the names of its 
- *       contributors may be used to endorse or promote products derived 
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
  *       from this software without specific prior written permission.
  * 
- *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
- *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
- *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
- *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
- *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
- *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
- *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
- *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
- *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
- *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- * 
  */
 
 #include <sys/queue.h>
@@ -88,7 +87,7 @@ rte_rxmbuf_alloc(struct rte_mempool *mp)
 #define RTE_MBUF_DATA_DMA_ADDR(mb) \
        (uint64_t) ((mb)->buf_physaddr +                   \
                        (uint64_t) ((char *)((mb)->pkt.data) -     \
-                               (char *)(mb)->buf_addr))
+                               (char *)(mb)->buf_addr))
 
 #define RTE_MBUF_DATA_DMA_ADDR_DEFAULT(mb) \
        (uint64_t) ((mb)->buf_physaddr + RTE_PKTMBUF_HEADROOM)
@@ -117,6 +116,7 @@ struct igb_rx_queue {
        volatile union e1000_adv_rx_desc *rx_ring; /**< RX ring virtual address. */
        uint64_t            rx_ring_phys_addr; /**< RX ring DMA address. */
        volatile uint32_t   *rdt_reg_addr; /**< RDT register address. */
+       volatile uint32_t   *rdh_reg_addr; /**< RDH register address. */
        struct igb_rx_entry *sw_ring;   /**< address of RX software ring. */
        struct rte_mbuf *pkt_first_seg; /**< First segment of current packet. */
        struct rte_mbuf *pkt_last_seg;  /**< Last segment of current packet. */
@@ -125,6 +125,7 @@ struct igb_rx_queue {
        uint16_t            nb_rx_hold; /**< number of held free RX desc. */
        uint16_t            rx_free_thresh; /**< max free RX desc to hold. */
        uint16_t            queue_id;   /**< RX queue index. */
+       uint16_t            reg_idx;    /**< RX queue register index. */
        uint8_t             port_id;    /**< Device port identifier. */
        uint8_t             pthresh;    /**< Prefetch threshold register. */
        uint8_t             hthresh;    /**< Host threshold register. */
@@ -161,10 +162,11 @@ struct igb_tx_queue {
        volatile uint32_t      *tdt_reg_addr; /**< Address of TDT register. */
        uint32_t               txd_type;      /**< Device-specific TXD type */
        uint16_t               nb_tx_desc;    /**< number of TX descriptors. */
-       uint16_t               tx_tail;  /**< Current value of TDT register. */
+       uint16_t               tx_tail; /**< Current value of TDT register. */
        uint16_t               tx_head;
        /**< Index of first used TX descriptor. */
        uint16_t               queue_id; /**< TX queue index. */
+       uint16_t               reg_idx;  /**< TX queue register index. */
        uint8_t                port_id;  /**< Device port identifier. */
        uint8_t                pthresh;  /**< Prefetch threshold register. */
        uint8_t                hthresh;  /**< Host threshold register. */
@@ -315,9 +317,10 @@ tx_desc_vlan_flags_to_cmdtype(uint16_t ol_flags)
 }
 
 uint16_t
-eth_igb_xmit_pkts(struct igb_tx_queue *txq, struct rte_mbuf **tx_pkts,
+eth_igb_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
               uint16_t nb_pkts)
 {
+       struct igb_tx_queue *txq;
        struct igb_tx_entry *sw_ring;
        struct igb_tx_entry *txe, *txn;
        volatile union e1000_adv_tx_desc *txr;
@@ -335,10 +338,11 @@ eth_igb_xmit_pkts(struct igb_tx_queue *txq, struct rte_mbuf **tx_pkts,
        uint16_t tx_last;
        uint16_t nb_tx;
        uint16_t tx_ol_req;
-       uint32_t new_ctx;
-       uint32_t ctx;
+       uint32_t new_ctx = 0;
+       uint32_t ctx = 0;
        uint32_t vlan_macip_lens;
 
+       txq = tx_queue;
        sw_ring = txq->sw_ring;
        txr     = txq->tx_ring;
        tx_id   = txq->tx_tail;
@@ -362,7 +366,7 @@ eth_igb_xmit_pkts(struct igb_tx_queue *txq, struct rte_mbuf **tx_pkts,
 
                ol_flags = tx_pkt->ol_flags;
                vlan_macip_lens = tx_pkt->pkt.vlan_macip.data;
-               tx_ol_req = (ol_flags & PKT_TX_OFFLOAD_MASK);
+               tx_ol_req = (uint16_t)(ol_flags & PKT_TX_OFFLOAD_MASK);
 
                /* If a Context Descriptor need be built . */
                if (tx_ol_req) {
@@ -567,15 +571,15 @@ rx_desc_hlen_type_rss_to_pkt_flags(uint32_t hl_tp_rs)
                0, 0, 0, 0,
        };
 
-       pkt_flags = (uint16_t) (hl_tp_rs & E1000_RXDADV_PKTTYPE_ETQF) ?
+       pkt_flags = (uint16_t)((hl_tp_rs & E1000_RXDADV_PKTTYPE_ETQF) ?
                                ip_pkt_etqf_map[(hl_tp_rs >> 4) & 0x07] :
-                               ip_pkt_types_map[(hl_tp_rs >> 4) & 0x0F];
+                               ip_pkt_types_map[(hl_tp_rs >> 4) & 0x0F]);
 #else
-       pkt_flags = (uint16_t) (hl_tp_rs & E1000_RXDADV_PKTTYPE_ETQF) ? 0 :
-                               ip_pkt_types_map[(hl_tp_rs >> 4) & 0x0F];
+       pkt_flags = (uint16_t)((hl_tp_rs & E1000_RXDADV_PKTTYPE_ETQF) ? 0 :
+                               ip_pkt_types_map[(hl_tp_rs >> 4) & 0x0F]);
 #endif
-       return pkt_flags | (uint16_t) (((hl_tp_rs & 0x0F) == 0) ? 0 :
-                                       PKT_RX_RSS_HASH);
+       return (uint16_t)(pkt_flags | (((hl_tp_rs & 0x0F) == 0) ?
+                                               0 : PKT_RX_RSS_HASH));
 }
 
 static inline uint16_t
@@ -584,11 +588,12 @@ rx_desc_status_to_pkt_flags(uint32_t rx_status)
        uint16_t pkt_flags;
 
        /* Check if VLAN present */
-       pkt_flags = (uint16_t) (rx_status & E1000_RXD_STAT_VP) ? PKT_RX_VLAN_PKT : 0;
+       pkt_flags = (uint16_t)((rx_status & E1000_RXD_STAT_VP) ?
+                                               PKT_RX_VLAN_PKT : 0);
 
 #if defined(RTE_LIBRTE_IEEE1588)
        if (rx_status & E1000_RXD_STAT_TMST)
-               pkt_flags = pkt_flags | PKT_RX_IEEE1588_TMST;
+               pkt_flags = (uint16_t)(pkt_flags | PKT_RX_IEEE1588_TMST);
 #endif
        return pkt_flags;
 }
@@ -610,9 +615,10 @@ rx_desc_error_to_pkt_flags(uint32_t rx_status)
 }
 
 uint16_t
-eth_igb_recv_pkts(struct igb_rx_queue *rxq, struct rte_mbuf **rx_pkts,
+eth_igb_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
               uint16_t nb_pkts)
 {
+       struct igb_rx_queue *rxq;
        volatile union e1000_adv_rx_desc *rx_ring;
        volatile union e1000_adv_rx_desc *rxdp;
        struct igb_rx_entry *sw_ring;
@@ -631,6 +637,7 @@ eth_igb_recv_pkts(struct igb_rx_queue *rxq, struct rte_mbuf **rx_pkts,
 
        nb_rx = 0;
        nb_hold = 0;
+       rxq = rx_queue;
        rx_id = rxq->rx_tail;
        rx_ring = rxq->rx_ring;
        sw_ring = rxq->sw_ring;
@@ -746,10 +753,10 @@ eth_igb_recv_pkts(struct igb_rx_queue *rxq, struct rte_mbuf **rx_pkts,
                        rte_le_to_cpu_16(rxd.wb.upper.vlan);
 
                pkt_flags = rx_desc_hlen_type_rss_to_pkt_flags(hlen_type_rss);
-               pkt_flags = (pkt_flags |
-                                       rx_desc_status_to_pkt_flags(staterr));
-               pkt_flags = (pkt_flags |
-                                       rx_desc_error_to_pkt_flags(staterr));
+               pkt_flags = (uint16_t)(pkt_flags |
+                               rx_desc_status_to_pkt_flags(staterr));
+               pkt_flags = (uint16_t)(pkt_flags |
+                               rx_desc_error_to_pkt_flags(staterr));
                rxm->ol_flags = pkt_flags;
 
                /*
@@ -786,9 +793,10 @@ eth_igb_recv_pkts(struct igb_rx_queue *rxq, struct rte_mbuf **rx_pkts,
 }
 
 uint16_t
-eth_igb_recv_scattered_pkts(struct igb_rx_queue *rxq, struct rte_mbuf **rx_pkts,
+eth_igb_recv_scattered_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
                         uint16_t nb_pkts)
 {
+       struct igb_rx_queue *rxq;
        volatile union e1000_adv_rx_desc *rx_ring;
        volatile union e1000_adv_rx_desc *rxdp;
        struct igb_rx_entry *sw_ring;
@@ -809,6 +817,7 @@ eth_igb_recv_scattered_pkts(struct igb_rx_queue *rxq, struct rte_mbuf **rx_pkts,
 
        nb_rx = 0;
        nb_hold = 0;
+       rxq = rx_queue;
        rx_id = rxq->rx_tail;
        rx_ring = rxq->rx_ring;
        sw_ring = rxq->sw_ring;
@@ -981,8 +990,10 @@ eth_igb_recv_scattered_pkts(struct igb_rx_queue *rxq, struct rte_mbuf **rx_pkts,
                        rte_le_to_cpu_16(rxd.wb.upper.vlan);
                hlen_type_rss = rte_le_to_cpu_32(rxd.wb.lower.lo_dword.data);
                pkt_flags = rx_desc_hlen_type_rss_to_pkt_flags(hlen_type_rss);
-               pkt_flags = (pkt_flags | rx_desc_status_to_pkt_flags(staterr));
-               pkt_flags = (pkt_flags | rx_desc_error_to_pkt_flags(staterr));
+               pkt_flags = (uint16_t)(pkt_flags |
+                               rx_desc_status_to_pkt_flags(staterr));
+               pkt_flags = (uint16_t)(pkt_flags |
+                               rx_desc_error_to_pkt_flags(staterr));
                first_seg->ol_flags = pkt_flags;
 
                /* Prefetch data of first segment, if configured to do so. */
@@ -1070,7 +1081,7 @@ ring_dma_zone_reserve(struct rte_eth_dev *dev, const char *ring_name,
        if (mz)
                return mz;
 
-       return rte_memzone_reserve_aligned(z_name, (uint64_t)ring_size,
+       return rte_memzone_reserve_aligned(z_name, ring_size,
                        socket_id, 0, IGB_ALIGN);
 }
 
@@ -1092,47 +1103,17 @@ igb_tx_queue_release_mbufs(struct igb_tx_queue *txq)
 static void
 igb_tx_queue_release(struct igb_tx_queue *txq)
 {
-       igb_tx_queue_release_mbufs(txq);
-        rte_free(txq->sw_ring);
-        rte_free(txq);
+       if (txq != NULL) {
+               igb_tx_queue_release_mbufs(txq);
+               rte_free(txq->sw_ring);
+               rte_free(txq);
+       }
 }
 
-int
-igb_dev_tx_queue_alloc(struct rte_eth_dev *dev, uint16_t nb_queues)
+void
+eth_igb_tx_queue_release(void *txq)
 {
-       uint16_t i, old_nb_queues = dev->data->nb_tx_queues;
-       struct igb_tx_queue **txq;
-
-       if (dev->data->tx_queues == NULL) {
-               dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues",
-                               sizeof(struct igb_tx_queue *) * nb_queues,
-                                                       CACHE_LINE_SIZE);
-               if (dev->data->tx_queues == NULL) {
-                       dev->data->nb_tx_queues = 0;
-                       return -ENOMEM;
-               }
-       } else {
-               if (nb_queues < old_nb_queues)
-                       for (i = nb_queues; i < old_nb_queues; i++)
-                               igb_tx_queue_release(dev->data->tx_queues[i]);
-
-               if (nb_queues != old_nb_queues) {
-                       txq = rte_realloc(dev->data->tx_queues,
-                               sizeof(struct igb_tx_queue *) * nb_queues,
-                                                       CACHE_LINE_SIZE);
-                       if (txq == NULL)
-                               return -ENOMEM;
-                       else
-                               dev->data->tx_queues = txq;
-                       if (nb_queues > old_nb_queues)
-                               memset(&(txq[old_nb_queues]), 0,
-                                       sizeof(struct igb_tx_queue *) *
-                                       (nb_queues - old_nb_queues));
-               }
-       }
-       dev->data->nb_tx_queues = nb_queues;
-
-       return 0;
+       igb_tx_queue_release(txq);
 }
 
 static void
@@ -1161,7 +1142,7 @@ igb_reset_tx_queue(struct igb_tx_queue *txq, struct rte_eth_dev *dev)
        }
 
        /* Initialize ring entries */
-       prev = txq->nb_tx_desc - 1;
+       prev = (uint16_t)(txq->nb_tx_desc - 1);
        for (i = 0; i < txq->nb_tx_desc; i++) {
                volatile union e1000_adv_tx_desc *txd = &(txq->tx_ring[i]);
 
@@ -1249,14 +1230,14 @@ eth_igb_tx_queue_setup(struct rte_eth_dev *dev,
        txq->hthresh = tx_conf->tx_thresh.hthresh;
        txq->wthresh = tx_conf->tx_thresh.wthresh;
        txq->queue_id = queue_idx;
+       txq->reg_idx = (uint16_t)((RTE_ETH_DEV_SRIOV(dev).active == 0) ?
+               queue_idx : RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx + queue_idx);
        txq->port_id = dev->data->port_id;
 
-       txq->tdt_reg_addr = E1000_PCI_REG_ADDR(hw, E1000_TDT(queue_idx));
+       txq->tdt_reg_addr = E1000_PCI_REG_ADDR(hw, E1000_TDT(txq->reg_idx));
        txq->tx_ring_phys_addr = (uint64_t) tz->phys_addr;
        txq->tx_ring = (union e1000_adv_tx_desc *) tz->addr;
 
-       size = sizeof(union e1000_adv_tx_desc) * nb_desc;
-
        /* Allocate software ring */
        txq->sw_ring = rte_zmalloc("txq->sw_ring",
                                   sizeof(struct igb_tx_entry) * nb_desc,
@@ -1293,47 +1274,17 @@ igb_rx_queue_release_mbufs(struct igb_rx_queue *rxq)
 static void
 igb_rx_queue_release(struct igb_rx_queue *rxq)
 {
-       igb_rx_queue_release_mbufs(rxq);
-       rte_free(rxq->sw_ring);
-       rte_free(rxq);
+       if (rxq != NULL) {
+               igb_rx_queue_release_mbufs(rxq);
+               rte_free(rxq->sw_ring);
+               rte_free(rxq);
+       }
 }
 
-int
-igb_dev_rx_queue_alloc(struct rte_eth_dev *dev, uint16_t nb_queues)
+void
+eth_igb_rx_queue_release(void *rxq)
 {
-       uint16_t i, old_nb_queues = dev->data->nb_rx_queues;
-       struct igb_rx_queue **rxq;
-
-       if (dev->data->rx_queues == NULL) {
-               dev->data->rx_queues = rte_zmalloc("ethdev->rx_queues",
-                               sizeof(struct igb_rx_queue *) * nb_queues,
-                                                       CACHE_LINE_SIZE);
-               if (dev->data->rx_queues == NULL) {
-                       dev->data->nb_rx_queues = 0;
-                       return -ENOMEM;
-               }
-       } else {
-               for (i = nb_queues; i < old_nb_queues; i++) {
-                       igb_rx_queue_release(dev->data->rx_queues[i]);
-                       dev->data->rx_queues[i] = NULL;
-               }
-               if (nb_queues != old_nb_queues) {
-                       rxq = rte_realloc(dev->data->rx_queues,
-                               sizeof(struct igb_rx_queue *) * nb_queues,
-                                                       CACHE_LINE_SIZE);
-                       if (rxq == NULL)
-                               return -ENOMEM;
-                       else
-                               dev->data->rx_queues = rxq;
-                       if (nb_queues > old_nb_queues)
-                               memset(&(rxq[old_nb_queues]), 0,
-                                       sizeof(struct igb_rx_queue *) *
-                                       (nb_queues - old_nb_queues));
-               }
-       }
-       dev->data->nb_rx_queues = nb_queues;
-
-       return 0;
+       igb_rx_queue_release(rxq);
 }
 
 static void
@@ -1397,6 +1348,8 @@ eth_igb_rx_queue_setup(struct rte_eth_dev *dev,
        rxq->drop_en = rx_conf->rx_drop_en;
        rxq->rx_free_thresh = rx_conf->rx_free_thresh;
        rxq->queue_id = queue_idx;
+       rxq->reg_idx = (uint16_t)((RTE_ETH_DEV_SRIOV(dev).active == 0) ?
+               queue_idx : RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx + queue_idx);
        rxq->port_id = dev->data->port_id;
        rxq->crc_len = (uint8_t) ((dev->data->dev_conf.rxmode.hw_strip_crc) ? 0 :
                                  ETHER_CRC_LEN);
@@ -1412,7 +1365,8 @@ eth_igb_rx_queue_setup(struct rte_eth_dev *dev,
                igb_rx_queue_release(rxq);
                return (-ENOMEM);
        }
-       rxq->rdt_reg_addr = E1000_PCI_REG_ADDR(hw, E1000_RDT(queue_idx));
+       rxq->rdt_reg_addr = E1000_PCI_REG_ADDR(hw, E1000_RDT(rxq->reg_idx));
+       rxq->rdh_reg_addr = E1000_PCI_REG_ADDR(hw, E1000_RDH(rxq->reg_idx));
        rxq->rx_ring_phys_addr = (uint64_t) rz->phys_addr;
        rxq->rx_ring = (union e1000_adv_rx_desc *) rz->addr;
 
@@ -1433,6 +1387,51 @@ eth_igb_rx_queue_setup(struct rte_eth_dev *dev,
        return 0;
 }
 
+uint32_t 
+eth_igb_rx_queue_count(struct rte_eth_dev *dev, uint16_t rx_queue_id)
+{
+#define IGB_RXQ_SCAN_INTERVAL 4
+       volatile union e1000_adv_rx_desc *rxdp;
+       struct igb_rx_queue *rxq;
+       uint32_t desc = 0;
+
+       if (rx_queue_id >= dev->data->nb_rx_queues) {
+               PMD_RX_LOG(ERR, "Invalid RX queue id=%d\n", rx_queue_id);
+               return 0;
+       }
+
+       rxq = dev->data->rx_queues[rx_queue_id];
+       rxdp = &(rxq->rx_ring[rxq->rx_tail]);
+
+       while ((desc < rxq->nb_rx_desc) &&
+               (rxdp->wb.upper.status_error & E1000_RXD_STAT_DD)) {
+               desc += IGB_RXQ_SCAN_INTERVAL;
+               rxdp += IGB_RXQ_SCAN_INTERVAL;
+               if (rxq->rx_tail + desc >= rxq->nb_rx_desc)
+                       rxdp = &(rxq->rx_ring[rxq->rx_tail +
+                               desc - rxq->nb_rx_desc]);
+       }
+
+       return 0;
+}
+
+int
+eth_igb_rx_descriptor_done(void *rx_queue, uint16_t offset)
+{
+       volatile union e1000_adv_rx_desc *rxdp;
+       struct igb_rx_queue *rxq = rx_queue;
+       uint32_t desc;
+
+       if (unlikely(offset >= rxq->nb_rx_desc))
+               return 0;
+       desc = rxq->rx_tail + offset;
+       if (desc >= rxq->nb_rx_desc)
+               desc -= rxq->nb_rx_desc;
+
+       rxdp = &rxq->rx_ring[desc];
+       return !!(rxdp->wb.upper.status_error & E1000_RXD_STAT_DD);
+}
+
 void
 igb_dev_clear_queues(struct rte_eth_dev *dev)
 {
@@ -1442,14 +1441,18 @@ igb_dev_clear_queues(struct rte_eth_dev *dev)
 
        for (i = 0; i < dev->data->nb_tx_queues; i++) {
                txq = dev->data->tx_queues[i];
-               igb_tx_queue_release_mbufs(txq);
-               igb_reset_tx_queue(txq, dev);
+               if (txq != NULL) {
+                       igb_tx_queue_release_mbufs(txq);
+                       igb_reset_tx_queue(txq, dev);
+               }
        }
 
        for (i = 0; i < dev->data->nb_rx_queues; i++) {
                rxq = dev->data->rx_queues[i];
-               igb_rx_queue_release_mbufs(rxq);
-               igb_reset_rx_queue(rxq);
+               if (rxq != NULL) {
+                       igb_rx_queue_release_mbufs(rxq);
+                       igb_reset_rx_queue(rxq);
+               }
        }
 }
 
@@ -1600,6 +1603,36 @@ igb_alloc_rx_queue_mbufs(struct igb_rx_queue *rxq)
        return 0;
 }
 
+#define E1000_MRQC_DEF_Q_SHIFT               (3)
+static int
+igb_dev_mq_rx_configure(struct rte_eth_dev *dev)
+{
+       struct e1000_hw *hw =
+               E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+       uint32_t mrqc;
+       if (RTE_ETH_DEV_SRIOV(dev).active == ETH_8_POOLS) {
+               /*
+               * SRIOV active scheme
+               * FIXME if support RSS together with VMDq & SRIOV
+               */
+               mrqc = E1000_MRQC_ENABLE_VMDQ;
+               /* 011b Def_Q ignore, according to VT_CTL.DEF_PL */
+               mrqc |= 0x3 << E1000_MRQC_DEF_Q_SHIFT;
+               E1000_WRITE_REG(hw, E1000_MRQC, mrqc);
+       } else if(RTE_ETH_DEV_SRIOV(dev).active == 0) { 
+               /*
+               * SRIOV inactive scheme
+               */
+               if (dev->data->nb_rx_queues > 1)
+                       igb_rss_configure(dev);
+               else
+                       igb_rss_disable(dev);
+       }
+       return 0;
+}
 int
 eth_igb_rx_init(struct rte_eth_dev *dev)
 {
@@ -1630,9 +1663,13 @@ eth_igb_rx_init(struct rte_eth_dev *dev)
        if (dev->data->dev_conf.rxmode.jumbo_frame == 1) {
                rctl |= E1000_RCTL_LPE;
 
-               /* Set maximum packet length. */
+               /*
+                * Set maximum packet length by default, and might be updated
+                * together with enabling/disabling dual VLAN.
+                */
                E1000_WRITE_REG(hw, E1000_RLPML,
-                               dev->data->dev_conf.rxmode.max_rx_pkt_len);
+                       dev->data->dev_conf.rxmode.max_rx_pkt_len +
+                                               VLAN_TAG_SIZE);
        } else
                rctl &= ~E1000_RCTL_LPE;
 
@@ -1647,10 +1684,8 @@ eth_igb_rx_init(struct rte_eth_dev *dev)
 
                /* Allocate buffers for descriptor rings and set up queue */
                ret = igb_alloc_rx_queue_mbufs(rxq);
-               if (ret) {
-                       igb_dev_clear_queues(dev);
+               if (ret)
                        return ret;
-               }
 
                /*
                 * Reset crc_len in case it was changed after queue setup by a
@@ -1661,12 +1696,12 @@ eth_igb_rx_init(struct rte_eth_dev *dev)
                                                        0 : ETHER_CRC_LEN);
 
                bus_addr = rxq->rx_ring_phys_addr;
-               E1000_WRITE_REG(hw, E1000_RDLEN(i),
+               E1000_WRITE_REG(hw, E1000_RDLEN(rxq->reg_idx),
                                rxq->nb_rx_desc *
                                sizeof(union e1000_adv_rx_desc));
-               E1000_WRITE_REG(hw, E1000_RDBAH(i),
+               E1000_WRITE_REG(hw, E1000_RDBAH(rxq->reg_idx),
                                (uint32_t)(bus_addr >> 32));
-               E1000_WRITE_REG(hw, E1000_RDBAL(i), (uint32_t)bus_addr);
+               E1000_WRITE_REG(hw, E1000_RDBAL(rxq->reg_idx), (uint32_t)bus_addr);
 
                srrctl = E1000_SRRCTL_DESCTYPE_ADV_ONEBUF;
 
@@ -1691,8 +1726,9 @@ eth_igb_rx_init(struct rte_eth_dev *dev)
                                                E1000_SRRCTL_BSIZEPKT_MASK) <<
                                               E1000_SRRCTL_BSIZEPKT_SHIFT);
 
-                       if (dev->data->dev_conf.rxmode.max_rx_pkt_len + VLAN_TAG_SIZE
-                                       > buf_size){
+                       /* It adds dual VLAN length for supporting dual VLAN */
+                       if ((dev->data->dev_conf.rxmode.max_rx_pkt_len +
+                                               2 * VLAN_TAG_SIZE) > buf_size){
                                dev->rx_pkt_burst = eth_igb_recv_scattered_pkts;
                                dev->data->scattered_rx = 1;
                        }
@@ -1710,16 +1746,16 @@ eth_igb_rx_init(struct rte_eth_dev *dev)
                if (rxq->drop_en)
                        srrctl |= E1000_SRRCTL_DROP_EN;
 
-               E1000_WRITE_REG(hw, E1000_SRRCTL(i), srrctl);
+               E1000_WRITE_REG(hw, E1000_SRRCTL(rxq->reg_idx), srrctl);
 
                /* Enable this RX queue. */
-               rxdctl = E1000_READ_REG(hw, E1000_RXDCTL(i));
+               rxdctl = E1000_READ_REG(hw, E1000_RXDCTL(rxq->reg_idx));
                rxdctl |= E1000_RXDCTL_QUEUE_ENABLE;
                rxdctl &= 0xFFF00000;
                rxdctl |= (rxq->pthresh & 0x1F);
                rxdctl |= ((rxq->hthresh & 0x1F) << 8);
                rxdctl |= ((rxq->wthresh & 0x1F) << 16);
-               E1000_WRITE_REG(hw, E1000_RXDCTL(i), rxdctl);
+               E1000_WRITE_REG(hw, E1000_RXDCTL(rxq->reg_idx), rxdctl);
        }
 
        /*
@@ -1746,10 +1782,7 @@ eth_igb_rx_init(struct rte_eth_dev *dev)
        /*
         * Configure RSS if device configured with multiple RX queues.
         */
-       if (dev->data->nb_rx_queues > 1)
-               igb_rss_configure(dev);
-       else
-               igb_rss_disable(dev);
+       igb_dev_mq_rx_configure(dev);
 
        /*
         * Setup the Checksum Register.
@@ -1769,25 +1802,27 @@ eth_igb_rx_init(struct rte_eth_dev *dev)
        if (dev->data->dev_conf.rxmode.hw_strip_crc) {
                rctl |= E1000_RCTL_SECRC; /* Strip Ethernet CRC. */
 
-               /* set STRCRC bit in all queues for Powerville */
-               if (hw->mac.type == e1000_i350) {
+               /* set STRCRC bit in all queues for Powerville/Springville */
+               if (hw->mac.type == e1000_i350 || hw->mac.type == e1000_i210) {
                        for (i = 0; i < dev->data->nb_rx_queues; i++) {
+                               rxq = dev->data->rx_queues[i];
                                uint32_t dvmolr = E1000_READ_REG(hw,
-                                       E1000_DVMOLR(i));
+                                       E1000_DVMOLR(rxq->reg_idx));
                                dvmolr |= E1000_DVMOLR_STRCRC;
-                               E1000_WRITE_REG(hw, E1000_DVMOLR(i), dvmolr);
+                               E1000_WRITE_REG(hw, E1000_DVMOLR(rxq->reg_idx), dvmolr);
                        }
                }
        } else {
                rctl &= ~E1000_RCTL_SECRC; /* Do not Strip Ethernet CRC. */
 
-               /* clear STRCRC bit in all queues for Powerville */
-               if (hw->mac.type == e1000_i350) {
+               /* clear STRCRC bit in all queues for Powerville/Springville */
+               if (hw->mac.type == e1000_i350 || hw->mac.type == e1000_i210) {
                        for (i = 0; i < dev->data->nb_rx_queues; i++) {
+                               rxq = dev->data->rx_queues[i];
                                uint32_t dvmolr = E1000_READ_REG(hw,
-                                       E1000_DVMOLR(i));
+                                       E1000_DVMOLR(rxq->reg_idx));
                                dvmolr &= ~E1000_DVMOLR_STRCRC;
-                               E1000_WRITE_REG(hw, E1000_DVMOLR(i), dvmolr);
+                               E1000_WRITE_REG(hw, E1000_DVMOLR(rxq->reg_idx), dvmolr);
                        }
                }
        }
@@ -1811,8 +1846,8 @@ eth_igb_rx_init(struct rte_eth_dev *dev)
         */
        for (i = 0; i < dev->data->nb_rx_queues; i++) {
                rxq = dev->data->rx_queues[i];
-               E1000_WRITE_REG(hw, E1000_RDH(i), 0);
-               E1000_WRITE_REG(hw, E1000_RDT(i), rxq->nb_rx_desc - 1);
+               E1000_WRITE_REG(hw, E1000_RDH(rxq->reg_idx), 0);
+               E1000_WRITE_REG(hw, E1000_RDT(rxq->reg_idx), rxq->nb_rx_desc - 1);
        }
 
        return 0;
@@ -1840,24 +1875,24 @@ eth_igb_tx_init(struct rte_eth_dev *dev)
                txq = dev->data->tx_queues[i];
                bus_addr = txq->tx_ring_phys_addr;
 
-               E1000_WRITE_REG(hw, E1000_TDLEN(i),
+               E1000_WRITE_REG(hw, E1000_TDLEN(txq->reg_idx),
                                txq->nb_tx_desc *
                                sizeof(union e1000_adv_tx_desc));
-               E1000_WRITE_REG(hw, E1000_TDBAH(i),
+               E1000_WRITE_REG(hw, E1000_TDBAH(txq->reg_idx),
                                (uint32_t)(bus_addr >> 32));
-               E1000_WRITE_REG(hw, E1000_TDBAL(i), (uint32_t)bus_addr);
+               E1000_WRITE_REG(hw, E1000_TDBAL(txq->reg_idx), (uint32_t)bus_addr);
 
                /* Setup the HW Tx Head and Tail descriptor pointers. */
-               E1000_WRITE_REG(hw, E1000_TDT(i), 0);
-               E1000_WRITE_REG(hw, E1000_TDH(i), 0);
+               E1000_WRITE_REG(hw, E1000_TDT(txq->reg_idx), 0);
+               E1000_WRITE_REG(hw, E1000_TDH(txq->reg_idx), 0);
 
                /* Setup Transmit threshold registers. */
-               txdctl = E1000_READ_REG(hw, E1000_TXDCTL(i));
+               txdctl = E1000_READ_REG(hw, E1000_TXDCTL(txq->reg_idx));
                txdctl |= txq->pthresh & 0x1F;
                txdctl |= ((txq->hthresh & 0x1F) << 8);
                txdctl |= ((txq->wthresh & 0x1F) << 16);
                txdctl |= E1000_TXDCTL_QUEUE_ENABLE;
-               E1000_WRITE_REG(hw, E1000_TXDCTL(i), txdctl);
+               E1000_WRITE_REG(hw, E1000_TXDCTL(txq->reg_idx), txdctl);
        }
 
        /* Program the Transmit Control Register. */
@@ -1936,7 +1971,9 @@ eth_igbvf_rx_init(struct rte_eth_dev *dev)
                                                E1000_SRRCTL_BSIZEPKT_MASK) <<
                                               E1000_SRRCTL_BSIZEPKT_SHIFT);
 
-                       if (dev->data->dev_conf.rxmode.max_rx_pkt_len > buf_size){
+                       /* It adds dual VLAN length for supporting dual VLAN */
+                       if ((dev->data->dev_conf.rxmode.max_rx_pkt_len +
+                                               2 * VLAN_TAG_SIZE) > buf_size){
                                dev->rx_pkt_burst = eth_igb_recv_scattered_pkts;
                                dev->data->scattered_rx = 1;
                        }