add prefix to cache line macros
[dpdk.git] / lib / librte_pmd_e1000 / em_rxtx.c
index eb00b0c..aa0b88c 100644 (file)
@@ -1,40 +1,38 @@
 /*-
  *   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 
- *   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>
 
-#include <endian.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -75,6 +73,7 @@
 #include "e1000_logs.h"
 #include "e1000/e1000_api.h"
 #include "e1000_ethdev.h"
+#include "e1000/e1000_osdep.h"
 
 #define        E1000_TXD_VLAN_SHIFT    16
 
@@ -86,13 +85,12 @@ rte_rxmbuf_alloc(struct rte_mempool *mp)
        struct rte_mbuf *m;
 
        m = __rte_mbuf_raw_alloc(mp);
-       __rte_mbuf_sanity_check_raw(m, RTE_MBUF_PKT, 0);
+       __rte_mbuf_sanity_check_raw(m, 0);
        return (m);
 }
 
 #define RTE_MBUF_DATA_DMA_ADDR(mb)             \
-       (uint64_t) ((mb)->buf_physaddr +       \
-       (uint64_t) ((char *)((mb)->pkt.data) - (char *)(mb)->buf_addr))
+       (uint64_t) ((mb)->buf_physaddr + (mb)->data_off)
 
 #define RTE_MBUF_DATA_DMA_ADDR_DEFAULT(mb) \
        (uint64_t) ((mb)->buf_physaddr + RTE_PKTMBUF_HEADROOM)
@@ -145,13 +143,34 @@ enum {
        EM_CTX_NUM  = 1, /**< CTX NUM */
 };
 
+/** Offload features */
+union em_vlan_macip {
+       uint32_t data;
+       struct {
+               uint16_t l3_len:9; /**< L3 (IP) Header Length. */
+               uint16_t l2_len:7; /**< L2 (MAC) Header Length. */
+               uint16_t vlan_tci;
+               /**< VLAN Tag Control Identifier (CPU order). */
+       } f;
+};
+
+/*
+ * Compare mask for vlan_macip_len.data,
+ * should be in sync with em_vlan_macip.f layout.
+ * */
+#define TX_VLAN_CMP_MASK        0xFFFF0000  /**< VLAN length - 16-bits. */
+#define TX_MAC_LEN_CMP_MASK     0x0000FE00  /**< MAC length - 7-bits. */
+#define TX_IP_LEN_CMP_MASK      0x000001FF  /**< IP  length - 9-bits. */
+/** MAC+IP  length. */
+#define TX_MACIP_LEN_CMP_MASK   (TX_MAC_LEN_CMP_MASK | TX_IP_LEN_CMP_MASK)
+
 /**
  * Structure to check if new context need be built
  */
 struct em_ctx_info {
-       uint16_t flags;               /**< ol_flags related to context build. */
-       uint32_t cmp_mask;            /**< compare mask */
-       union rte_vlan_macip hdrlen;  /**< L2 and L3 header lenghts */
+       uint64_t flags;              /**< ol_flags related to context build. */
+       uint32_t cmp_mask;           /**< compare mask */
+       union em_vlan_macip hdrlen;  /**< L2 and L3 header lenghts */
 };
 
 /**
@@ -219,8 +238,8 @@ struct em_tx_queue {
 static inline void
 em_set_xmit_ctx(struct em_tx_queue* txq,
                volatile struct e1000_context_desc *ctx_txd,
-               uint16_t flags,
-               union rte_vlan_macip hdrlen)
+               uint64_t flags,
+               union em_vlan_macip hdrlen)
 {
        uint32_t cmp_mask, cmd_len;
        uint16_t ipcse, l2len;
@@ -285,8 +304,8 @@ em_set_xmit_ctx(struct em_tx_queue* txq,
  * or create a new context descriptor.
  */
 static inline uint32_t
-what_ctx_update(struct em_tx_queue *txq, uint16_t flags,
-               union rte_vlan_macip hdrlen)
+what_ctx_update(struct em_tx_queue *txq, uint64_t flags,
+               union em_vlan_macip hdrlen)
 {
        /* If match with the current context */
        if (likely (txq->ctx_cache.flags == flags &&
@@ -320,8 +339,7 @@ em_xmit_cleanup(struct em_tx_queue *txq)
        {
                PMD_TX_FREE_LOG(DEBUG,
                                "TX descriptor %4u is not done"
-                               "(port=%d queue=%d)",
-                               desc_to_clean_to,
+                               "(port=%d queue=%d)", desc_to_clean_to,
                                txq->port_id, txq->queue_id);
                /* Failed to clean any descriptors, better luck next time */
                return -(1);
@@ -337,9 +355,9 @@ em_xmit_cleanup(struct em_tx_queue *txq)
 
        PMD_TX_FREE_LOG(DEBUG,
                        "Cleaning %4u TX descriptors: %4u to %4u "
-                       "(port=%d queue=%d)",
-                       nb_tx_to_clean, last_desc_cleaned, desc_to_clean_to,
-                       txq->port_id, txq->queue_id);
+                       "(port=%d queue=%d)", nb_tx_to_clean,
+                       last_desc_cleaned, desc_to_clean_to, txq->port_id,
+                       txq->queue_id);
 
        /*
         * The last descriptor to clean is done, so that means all the
@@ -358,7 +376,7 @@ em_xmit_cleanup(struct em_tx_queue *txq)
 }
 
 static inline uint32_t
-tx_desc_cksum_flags_to_upper(uint16_t ol_flags)
+tx_desc_cksum_flags_to_upper(uint64_t ol_flags)
 {
        static const uint32_t l4_olinfo[2] = {0, E1000_TXD_POPTS_TXSM << 8};
        static const uint32_t l3_olinfo[2] = {0, E1000_TXD_POPTS_IXSM << 8};
@@ -384,15 +402,15 @@ eth_em_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
        uint32_t popts_spec;
        uint32_t cmd_type_len;
        uint16_t slen;
-       uint16_t ol_flags;
+       uint64_t ol_flags;
        uint16_t tx_id;
        uint16_t tx_last;
        uint16_t nb_tx;
        uint16_t nb_used;
-       uint16_t tx_ol_req;
+       uint64_t tx_ol_req;
        uint32_t ctx;
        uint32_t new_ctx;
-       union rte_vlan_macip hdrlen;
+       union em_vlan_macip hdrlen;
 
        txq = tx_queue;
        sw_ring = txq->sw_ring;
@@ -419,10 +437,11 @@ eth_em_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
                ol_flags = tx_pkt->ol_flags;
 
                /* If hardware offload required */
-               tx_ol_req = (uint16_t)(ol_flags & (PKT_TX_IP_CKSUM |
-                                                       PKT_TX_L4_MASK));
+               tx_ol_req = (ol_flags & (PKT_TX_IP_CKSUM | PKT_TX_L4_MASK));
                if (tx_ol_req) {
-                       hdrlen = tx_pkt->pkt.vlan_macip;
+                       hdrlen.f.vlan_tci = tx_pkt->vlan_tci;
+                       hdrlen.f.l2_len = tx_pkt->l2_len;
+                       hdrlen.f.l3_len = tx_pkt->l3_len;
                        /* If new context to be built or reuse the exist ctx. */
                        ctx = what_ctx_update(txq, tx_ol_req, hdrlen);
 
@@ -435,7 +454,7 @@ eth_em_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
                 * This will always be the number of segments + the number of
                 * Context descriptors required to transmit the packet
                 */
-               nb_used = (uint16_t)(tx_pkt->pkt.nb_segs + new_ctx);
+               nb_used = (uint16_t)(tx_pkt->nb_segs + new_ctx);
 
                /*
                 * The number of descriptors that must be allocated for a
@@ -452,12 +471,12 @@ eth_em_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
                        tx_last = (uint16_t) (tx_last - txq->nb_tx_desc);
 
                PMD_TX_LOG(DEBUG, "port_id=%u queue_id=%u pktlen=%u"
-                       " tx_first=%u tx_last=%u\n",
-                       (unsigned) txq->port_id,
-                       (unsigned) txq->queue_id,
-                       (unsigned) tx_pkt->pkt.pkt_len,
-                       (unsigned) tx_id,
-                       (unsigned) tx_last);
+                          " tx_first=%u tx_last=%u",
+                          (unsigned) txq->port_id,
+                          (unsigned) txq->queue_id,
+                          (unsigned) tx_pkt->pkt_len,
+                          (unsigned) tx_id,
+                          (unsigned) tx_last);
 
                /*
                 * Make sure there are enough TX descriptors available to
@@ -465,8 +484,7 @@ eth_em_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
                 * nb_used better be less than or equal to txq->tx_rs_thresh
                 */
                while (unlikely (nb_used > txq->nb_tx_free)) {
-                       PMD_TX_FREE_LOG(DEBUG,
-                                       "Not enough free TX descriptors "
+                       PMD_TX_FREE_LOG(DEBUG, "Not enough free TX descriptors "
                                        "nb_used=%4u nb_free=%4u "
                                        "(port=%d queue=%d)",
                                        nb_used, txq->nb_tx_free,
@@ -517,8 +535,7 @@ eth_em_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
                /* Set VLAN Tag offload fields. */
                if (ol_flags & PKT_TX_VLAN_PKT) {
                        cmd_type_len |= E1000_TXD_CMD_VLE;
-                       popts_spec = tx_pkt->pkt.vlan_macip.f.vlan_tci <<
-                               E1000_TXD_VLAN_SHIFT;
+                       popts_spec = tx_pkt->vlan_tci << E1000_TXD_VLAN_SHIFT;
                }
 
                if (tx_ol_req) {
@@ -567,7 +584,7 @@ eth_em_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
                        /*
                         * Set up Transmit Data Descriptor.
                         */
-                       slen = m_seg->pkt.data_len;
+                       slen = m_seg->data_len;
                        buf_dma_addr = RTE_MBUF_DATA_DMA_ADDR(m_seg);
 
                        txd->buffer_addr = rte_cpu_to_le_64(buf_dma_addr);
@@ -577,7 +594,7 @@ eth_em_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
                        txe->last_id = tx_last;
                        tx_id = txe->next_id;
                        txe = txn;
-                       m_seg = m_seg->pkt.next;
+                       m_seg = m_seg->next;
                } while (m_seg != NULL);
 
                /*
@@ -590,8 +607,8 @@ eth_em_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
                /* Set RS bit only on threshold packets' last descriptor */
                if (txq->nb_tx_used >= txq->tx_rs_thresh) {
                        PMD_TX_FREE_LOG(DEBUG,
-                                       "Setting RS bit on TXD id="
-                                       "%4u (port=%d queue=%d)",
+                                       "Setting RS bit on TXD id=%4u "
+                                       "(port=%d queue=%d)",
                                        tx_last, txq->port_id, txq->queue_id);
 
                        cmd_type_len |= E1000_TXD_CMD_RS;
@@ -622,22 +639,21 @@ end_of_tx:
  *
  **********************************************************************/
 
-static inline uint16_t
+static inline uint64_t
 rx_desc_status_to_pkt_flags(uint32_t rx_status)
 {
-       uint16_t pkt_flags;
+       uint64_t pkt_flags;
 
        /* Check if VLAN present */
-       pkt_flags = (uint16_t)((rx_status & E1000_RXD_STAT_VP) ?
-                                               PKT_RX_VLAN_PKT : 0);
+       pkt_flags = ((rx_status & E1000_RXD_STAT_VP) ?  PKT_RX_VLAN_PKT : 0);
 
        return pkt_flags;
 }
 
-static inline uint16_t
+static inline uint64_t
 rx_desc_error_to_pkt_flags(uint32_t rx_error)
 {
-       uint16_t pkt_flags = 0;
+       uint64_t pkt_flags = 0;
 
        if (rx_error & E1000_RXD_ERR_IPE)
                pkt_flags |= PKT_RX_IP_CKSUM_BAD;
@@ -713,18 +729,18 @@ eth_em_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
                 * to happen by sending specific "back-pressure" flow control
                 * frames to its peer(s).
                 */
-               PMD_RX_LOG(DEBUG, "\nport_id=%u queue_id=%u rx_id=%u "
-                       "status=0x%x pkt_len=%u\n",
-                       (unsigned) rxq->port_id, (unsigned) rxq->queue_id,
-                       (unsigned) rx_id, (unsigned) status,
-                       (unsigned) rte_le_to_cpu_16(rxd.length));
+               PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u rx_id=%u "
+                          "status=0x%x pkt_len=%u",
+                          (unsigned) rxq->port_id, (unsigned) rxq->queue_id,
+                          (unsigned) rx_id, (unsigned) status,
+                          (unsigned) rte_le_to_cpu_16(rxd.length));
 
                nmb = rte_rxmbuf_alloc(rxq->mb_pool);
                if (nmb == NULL) {
                        PMD_RX_LOG(DEBUG, "RX mbuf alloc failed port_id=%u "
-                               "queue_id=%u\n",
-                               (unsigned) rxq->port_id,
-                               (unsigned) rxq->queue_id);
+                                  "queue_id=%u",
+                                  (unsigned) rxq->port_id,
+                                  (unsigned) rxq->queue_id);
                        rte_eth_devices[rxq->port_id].data->rx_mbuf_alloc_failed++;
                        break;
                }
@@ -772,20 +788,20 @@ eth_em_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
                 */
                pkt_len = (uint16_t) (rte_le_to_cpu_16(rxd.length) -
                                rxq->crc_len);
-               rxm->pkt.data = (char*) rxm->buf_addr + RTE_PKTMBUF_HEADROOM;
-               rte_packet_prefetch(rxm->pkt.data);
-               rxm->pkt.nb_segs = 1;
-               rxm->pkt.next = NULL;
-               rxm->pkt.pkt_len = pkt_len;
-               rxm->pkt.data_len = pkt_len;
-               rxm->pkt.in_port = rxq->port_id;
+               rxm->data_off = RTE_PKTMBUF_HEADROOM;
+               rte_packet_prefetch((char *)rxm->buf_addr + rxm->data_off);
+               rxm->nb_segs = 1;
+               rxm->next = NULL;
+               rxm->pkt_len = pkt_len;
+               rxm->data_len = pkt_len;
+               rxm->port = rxq->port_id;
 
                rxm->ol_flags = rx_desc_status_to_pkt_flags(status);
-               rxm->ol_flags = (uint16_t)(rxm->ol_flags |
-                               rx_desc_error_to_pkt_flags(rxd.errors));
+               rxm->ol_flags = rxm->ol_flags |
+                               rx_desc_error_to_pkt_flags(rxd.errors);
 
                /* Only valid if PKT_RX_VLAN_PKT set in pkt_flags */
-               rxm->pkt.vlan_macip.f.vlan_tci = rte_le_to_cpu_16(rxd.special);
+               rxm->vlan_tci = rte_le_to_cpu_16(rxd.special);
 
                /*
                 * Store the mbuf address into the next entry of the array
@@ -807,10 +823,10 @@ eth_em_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
        nb_hold = (uint16_t) (nb_hold + rxq->nb_rx_hold);
        if (nb_hold > rxq->rx_free_thresh) {
                PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u rx_tail=%u "
-                       "nb_hold=%u nb_rx=%u\n",
-                       (unsigned) rxq->port_id, (unsigned) rxq->queue_id,
-                       (unsigned) rx_id, (unsigned) nb_hold,
-                       (unsigned) nb_rx);
+                          "nb_hold=%u nb_rx=%u",
+                          (unsigned) rxq->port_id, (unsigned) rxq->queue_id,
+                          (unsigned) rx_id, (unsigned) nb_hold,
+                          (unsigned) nb_rx);
                rx_id = (uint16_t) ((rx_id == 0) ?
                        (rxq->nb_rx_desc - 1) : (rx_id - 1));
                E1000_PCI_REG_WRITE(rxq->rdt_reg_addr, rx_id);
@@ -893,17 +909,17 @@ eth_em_recv_scattered_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
                 * to happen by sending specific "back-pressure" flow control
                 * frames to its peer(s).
                 */
-               PMD_RX_LOG(DEBUG, "\nport_id=%u queue_id=%u rx_id=%u "
-                       "status=0x%x data_len=%u\n",
-                       (unsigned) rxq->port_id, (unsigned) rxq->queue_id,
-                       (unsigned) rx_id, (unsigned) status,
-                       (unsigned) rte_le_to_cpu_16(rxd.length));
+               PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u rx_id=%u "
+                          "status=0x%x data_len=%u",
+                          (unsigned) rxq->port_id, (unsigned) rxq->queue_id,
+                          (unsigned) rx_id, (unsigned) status,
+                          (unsigned) rte_le_to_cpu_16(rxd.length));
 
                nmb = rte_rxmbuf_alloc(rxq->mb_pool);
                if (nmb == NULL) {
                        PMD_RX_LOG(DEBUG, "RX mbuf alloc failed port_id=%u "
-                               "queue_id=%u\n", (unsigned) rxq->port_id,
-                               (unsigned) rxq->queue_id);
+                                  "queue_id=%u", (unsigned) rxq->port_id,
+                                  (unsigned) rxq->queue_id);
                        rte_eth_devices[rxq->port_id].data->rx_mbuf_alloc_failed++;
                        break;
                }
@@ -941,8 +957,8 @@ eth_em_recv_scattered_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
                 * Set data length & data buffer address of mbuf.
                 */
                data_len = rte_le_to_cpu_16(rxd.length);
-               rxm->pkt.data_len = data_len;
-               rxm->pkt.data = (char*) rxm->buf_addr + RTE_PKTMBUF_HEADROOM;
+               rxm->data_len = data_len;
+               rxm->data_off = RTE_PKTMBUF_HEADROOM;
 
                /*
                 * If this is the first buffer of the received packet,
@@ -954,12 +970,12 @@ eth_em_recv_scattered_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
                 */
                if (first_seg == NULL) {
                        first_seg = rxm;
-                       first_seg->pkt.pkt_len = data_len;
-                       first_seg->pkt.nb_segs = 1;
+                       first_seg->pkt_len = data_len;
+                       first_seg->nb_segs = 1;
                } else {
-                       first_seg->pkt.pkt_len += data_len;
-                       first_seg->pkt.nb_segs++;
-                       last_seg->pkt.next = rxm;
+                       first_seg->pkt_len += data_len;
+                       first_seg->nb_segs++;
+                       last_seg->next = rxm;
                }
 
                /*
@@ -982,18 +998,18 @@ eth_em_recv_scattered_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
                 *     mbuf, subtract the length of that CRC part from the
                 *     data length of the previous mbuf.
                 */
-               rxm->pkt.next = NULL;
+               rxm->next = NULL;
                if (unlikely(rxq->crc_len > 0)) {
-                       first_seg->pkt.pkt_len -= ETHER_CRC_LEN;
+                       first_seg->pkt_len -= ETHER_CRC_LEN;
                        if (data_len <= ETHER_CRC_LEN) {
                                rte_pktmbuf_free_seg(rxm);
-                               first_seg->pkt.nb_segs--;
-                               last_seg->pkt.data_len = (uint16_t)
-                                       (last_seg->pkt.data_len -
+                               first_seg->nb_segs--;
+                               last_seg->data_len = (uint16_t)
+                                       (last_seg->data_len -
                                         (ETHER_CRC_LEN - data_len));
-                               last_seg->pkt.next = NULL;
+                               last_seg->next = NULL;
                        } else
-                               rxm->pkt.data_len =
+                               rxm->data_len =
                                        (uint16_t) (data_len - ETHER_CRC_LEN);
                }
 
@@ -1004,17 +1020,18 @@ eth_em_recv_scattered_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
                 *      - IP checksum flag,
                 *      - error flags.
                 */
-               first_seg->pkt.in_port = rxq->port_id;
+               first_seg->port = rxq->port_id;
 
                first_seg->ol_flags = rx_desc_status_to_pkt_flags(status);
-               first_seg->ol_flags = (uint16_t)(first_seg->ol_flags |
-                                       rx_desc_error_to_pkt_flags(rxd.errors));
+               first_seg->ol_flags = first_seg->ol_flags |
+                                       rx_desc_error_to_pkt_flags(rxd.errors);
 
                /* Only valid if PKT_RX_VLAN_PKT set in pkt_flags */
-               rxm->pkt.vlan_macip.f.vlan_tci = rte_le_to_cpu_16(rxd.special);
+               rxm->vlan_tci = rte_le_to_cpu_16(rxd.special);
 
                /* Prefetch data of first segment, if configured to do so. */
-               rte_packet_prefetch(first_seg->pkt.data);
+               rte_packet_prefetch((char *)first_seg->buf_addr +
+                       first_seg->data_off);
 
                /*
                 * Store the mbuf address into the next entry of the array
@@ -1051,10 +1068,10 @@ eth_em_recv_scattered_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
        nb_hold = (uint16_t) (nb_hold + rxq->nb_rx_hold);
        if (nb_hold > rxq->rx_free_thresh) {
                PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u rx_tail=%u "
-                       "nb_hold=%u nb_rx=%u\n",
-                       (unsigned) rxq->port_id, (unsigned) rxq->queue_id,
-                       (unsigned) rx_id, (unsigned) nb_hold,
-                       (unsigned) nb_rx);
+                          "nb_hold=%u nb_rx=%u",
+                          (unsigned) rxq->port_id, (unsigned) rxq->queue_id,
+                          (unsigned) rx_id, (unsigned) nb_hold,
+                          (unsigned) nb_rx);
                rx_id = (uint16_t) ((rx_id == 0) ?
                        (rxq->nb_rx_desc - 1) : (rx_id - 1));
                E1000_PCI_REG_WRITE(rxq->rdt_reg_addr, rx_id);
@@ -1094,14 +1111,19 @@ ring_dma_zone_reserve(struct rte_eth_dev *dev, const char *ring_name,
        const struct rte_memzone *mz;
        char z_name[RTE_MEMZONE_NAMESIZE];
 
-       rte_snprintf(z_name, sizeof(z_name), "%s_%s_%d_%d",
+       snprintf(z_name, sizeof(z_name), "%s_%s_%d_%d",
                dev->driver->pci_drv.name, ring_name, dev->data->port_id,
                queue_id);
 
        if ((mz = rte_memzone_lookup(z_name)) != 0)
                return (mz);
 
+#ifdef RTE_LIBRTE_XEN_DOM0
+       return rte_memzone_reserve_bounded(z_name, ring_size,
+                       socket_id, 0, RTE_CACHE_LINE_SIZE, RTE_PGSIZE_2M);
+#else
        return rte_memzone_reserve(z_name, ring_size, socket_id, 0);
+#endif
 }
 
 static void
@@ -1207,18 +1229,21 @@ eth_em_tx_queue_setup(struct rte_eth_dev *dev,
                                        DEFAULT_TX_RS_THRESH);
 
        if (tx_free_thresh >= (nb_desc - 3)) {
-               RTE_LOG(ERR, PMD, "tx_free_thresh must be less than the "
-                       "number of TX descriptors minus 3. (tx_free_thresh=%u "
-                       "port=%d queue=%d)\n", (unsigned int)tx_free_thresh,
-                               (int)dev->data->port_id, (int)queue_idx);
+               PMD_INIT_LOG(ERR, "tx_free_thresh must be less than the "
+                            "number of TX descriptors minus 3. "
+                            "(tx_free_thresh=%u port=%d queue=%d)",
+                            (unsigned int)tx_free_thresh,
+                            (int)dev->data->port_id, (int)queue_idx);
                return -(EINVAL);
        }
        if (tx_rs_thresh > tx_free_thresh) {
-               RTE_LOG(ERR, PMD, "tx_rs_thresh must be less than or equal to "
-                       "tx_free_thresh. (tx_free_thresh=%u tx_rs_thresh=%u "
-                       "port=%d queue=%d)\n", (unsigned int)tx_free_thresh,
-                       (unsigned int)tx_rs_thresh, (int)dev->data->port_id,
-                                                       (int)queue_idx);
+               PMD_INIT_LOG(ERR, "tx_rs_thresh must be less than or equal to "
+                            "tx_free_thresh. (tx_free_thresh=%u "
+                            "tx_rs_thresh=%u port=%d queue=%d)",
+                            (unsigned int)tx_free_thresh,
+                            (unsigned int)tx_rs_thresh,
+                            (int)dev->data->port_id,
+                            (int)queue_idx);
                return -(EINVAL);
        }
 
@@ -1229,10 +1254,10 @@ eth_em_tx_queue_setup(struct rte_eth_dev *dev,
         * accumulates WTHRESH descriptors.
         */
        if (tx_conf->tx_thresh.wthresh != 0 && tx_rs_thresh != 1) {
-               RTE_LOG(ERR, PMD, "TX WTHRESH must be set to 0 if "
-                       "tx_rs_thresh is greater than 1. (tx_rs_thresh=%u "
-                       "port=%d queue=%d)\n", (unsigned int)tx_rs_thresh,
-                               (int)dev->data->port_id, (int)queue_idx);
+               PMD_INIT_LOG(ERR, "TX WTHRESH must be set to 0 if "
+                            "tx_rs_thresh is greater than 1. (tx_rs_thresh=%u "
+                            "port=%d queue=%d)", (unsigned int)tx_rs_thresh,
+                            (int)dev->data->port_id, (int)queue_idx);
                return -(EINVAL);
        }
 
@@ -1254,13 +1279,13 @@ eth_em_tx_queue_setup(struct rte_eth_dev *dev,
 
        /* Allocate the tx queue data structure. */
        if ((txq = rte_zmalloc("ethdev TX queue", sizeof(*txq),
-                       CACHE_LINE_SIZE)) == NULL)
+                       RTE_CACHE_LINE_SIZE)) == NULL)
                return (-ENOMEM);
 
        /* Allocate software ring */
        if ((txq->sw_ring = rte_zmalloc("txq->sw_ring",
                        sizeof(txq->sw_ring[0]) * nb_desc,
-                       CACHE_LINE_SIZE)) == NULL) {
+                       RTE_CACHE_LINE_SIZE)) == NULL) {
                em_tx_queue_release(txq);
                return (-ENOMEM);
        }
@@ -1271,17 +1296,19 @@ eth_em_tx_queue_setup(struct rte_eth_dev *dev,
        txq->pthresh = tx_conf->tx_thresh.pthresh;
        txq->hthresh = tx_conf->tx_thresh.hthresh;
        txq->wthresh = tx_conf->tx_thresh.wthresh;
-       if (txq->wthresh > 0 && hw->mac.type == e1000_82576)
-               txq->wthresh = 1;
        txq->queue_id = queue_idx;
        txq->port_id = dev->data->port_id;
 
        txq->tdt_reg_addr = E1000_PCI_REG_ADDR(hw, E1000_TDT(queue_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 = (struct e1000_data_desc *) tz->addr;
 
-       PMD_INIT_LOG(DEBUG, "sw_ring=%p hw_ring=%p dma_addr=0x%"PRIx64"\n",
-               txq->sw_ring, txq->tx_ring, txq->tx_ring_phys_addr);
+       PMD_INIT_LOG(DEBUG, "sw_ring=%p hw_ring=%p dma_addr=0x%"PRIx64,
+                    txq->sw_ring, txq->tx_ring, txq->tx_ring_phys_addr);
 
        em_reset_tx_queue(txq);
 
@@ -1360,7 +1387,8 @@ eth_em_rx_queue_setup(struct rte_eth_dev *dev,
         * EM devices don't support drop_en functionality
         */
        if (rx_conf->rx_drop_en) {
-               RTE_LOG(ERR, PMD, "drop_en functionality not supported by device\n");
+               PMD_INIT_LOG(ERR, "drop_en functionality not supported by "
+                            "device");
                return (-EINVAL);
        }
 
@@ -1378,13 +1406,13 @@ eth_em_rx_queue_setup(struct rte_eth_dev *dev,
 
        /* Allocate the RX queue data structure. */
        if ((rxq = rte_zmalloc("ethdev RX queue", sizeof(*rxq),
-                       CACHE_LINE_SIZE)) == NULL)
+                       RTE_CACHE_LINE_SIZE)) == NULL)
                return (-ENOMEM);
 
        /* Allocate software ring. */
        if ((rxq->sw_ring = rte_zmalloc("rxq->sw_ring",
                        sizeof (rxq->sw_ring[0]) * nb_desc,
-                       CACHE_LINE_SIZE)) == NULL) {
+                       RTE_CACHE_LINE_SIZE)) == NULL) {
                em_rx_queue_release(rxq);
                return (-ENOMEM);
        }
@@ -1394,9 +1422,6 @@ eth_em_rx_queue_setup(struct rte_eth_dev *dev,
        rxq->pthresh = rx_conf->rx_thresh.pthresh;
        rxq->hthresh = rx_conf->rx_thresh.hthresh;
        rxq->wthresh = rx_conf->rx_thresh.wthresh;
-       if (rxq->wthresh > 0 && hw->mac.type == e1000_82576)
-               rxq->wthresh = 1;
-
        rxq->rx_free_thresh = rx_conf->rx_free_thresh;
        rxq->queue_id = queue_idx;
        rxq->port_id = dev->data->port_id;
@@ -1404,12 +1429,16 @@ eth_em_rx_queue_setup(struct rte_eth_dev *dev,
                                0 : ETHER_CRC_LEN);
 
        rxq->rdt_reg_addr = E1000_PCI_REG_ADDR(hw, E1000_RDT(queue_idx));
-       rxq->rdh_reg_addr = E1000_PCI_REG_ADDR(hw, E1000_RDH(queue_idx));       
+       rxq->rdh_reg_addr = E1000_PCI_REG_ADDR(hw, E1000_RDH(queue_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 = (struct e1000_rx_desc *) rz->addr;
 
-       PMD_INIT_LOG(DEBUG, "sw_ring=%p hw_ring=%p dma_addr=0x%"PRIx64"\n",
-               rxq->sw_ring, rxq->rx_ring, rxq->rx_ring_phys_addr);
+       PMD_INIT_LOG(DEBUG, "sw_ring=%p hw_ring=%p dma_addr=0x%"PRIx64,
+                    rxq->sw_ring, rxq->rx_ring, rxq->rx_ring_phys_addr);
 
        dev->data->rx_queues[queue_idx] = rxq;
        em_reset_rx_queue(rxq);
@@ -1417,7 +1446,7 @@ eth_em_rx_queue_setup(struct rte_eth_dev *dev,
        return (0);
 }
 
-uint32_t 
+uint32_t
 eth_em_rx_queue_count(struct rte_eth_dev *dev, uint16_t rx_queue_id)
 {
 #define EM_RXQ_SCAN_INTERVAL 4
@@ -1426,7 +1455,7 @@ eth_em_rx_queue_count(struct rte_eth_dev *dev, uint16_t rx_queue_id)
        uint32_t desc = 0;
 
        if (rx_queue_id >= dev->data->nb_rx_queues) {
-               PMD_RX_LOG(DEBUG,"Invalid RX queue_id=%d\n", rx_queue_id);
+               PMD_RX_LOG(DEBUG, "Invalid RX queue_id=%d", rx_queue_id);
                return 0;
        }
 
@@ -1450,7 +1479,7 @@ eth_em_rx_descriptor_done(void *rx_queue, uint16_t offset)
 {
        volatile struct e1000_rx_desc *rxdp;
        struct em_rx_queue *rxq = rx_queue;
-       uint16_t desc;
+       uint32_t desc;
 
        if (unlikely(offset >= rxq->nb_rx_desc))
                return 0;
@@ -1572,8 +1601,7 @@ em_alloc_rx_queue_mbufs(struct em_rx_queue *rxq)
 
                if (mbuf == NULL) {
                        PMD_INIT_LOG(ERR, "RX mbuf alloc failed "
-                               "queue_id=%hu\n", rxq->queue_id);
-                       em_rx_queue_release(rxq);
+                                    "queue_id=%hu", rxq->queue_id);
                        return (-ENOMEM);
                }
 
@@ -1696,18 +1724,27 @@ eth_em_rx_init(struct rte_eth_dev *dev)
                 * limit for packet length, jumbo frame of any size
                 * can be accepted, thus we have to enable scattered
                 * rx if jumbo frames are enabled (or if buffer size
-                * is too small to accomodate non-jumbo packets)
+                * is too small to accommodate non-jumbo packets)
                 * to avoid splitting packets that don't fit into
                 * one buffer.
                 */
                if (dev->data->dev_conf.rxmode.jumbo_frame ||
                                rctl_bsize < ETHER_MAX_LEN) {
+                       if (!dev->data->scattered_rx)
+                               PMD_INIT_LOG(DEBUG, "forcing scatter mode");
                        dev->rx_pkt_burst =
                                (eth_rx_burst_t)eth_em_recv_scattered_pkts;
                        dev->data->scattered_rx = 1;
                }
        }
 
+       if (dev->data->dev_conf.rxmode.enable_scatter) {
+               if (!dev->data->scattered_rx)
+                       PMD_INIT_LOG(DEBUG, "forcing scatter mode");
+               dev->rx_pkt_burst = eth_em_recv_scattered_pkts;
+               dev->data->scattered_rx = 1;
+       }
+
        /*
         * Setup the Checksum Register.
         * Receive Full-Packet Checksum Offload is mutually exclusive with RSS.