mbuf: add namespace to offload flags
[dpdk.git] / drivers / net / ionic / ionic_rxtx.c
index 5236cae..9f602de 100644 (file)
@@ -47,8 +47,6 @@
 #include "ionic_lif.h"
 #include "ionic_rxtx.h"
 
-#define IONIC_RX_RING_DOORBELL_STRIDE          (32 - 1)
-
 /*********************************************************************
  *
  *  TX functions
@@ -120,9 +118,9 @@ ionic_tx_flush(struct ionic_tx_qcq *txq)
 }
 
 void __rte_cold
-ionic_dev_tx_queue_release(void *tx_queue)
+ionic_dev_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
 {
-       struct ionic_tx_qcq *txq = tx_queue;
+       struct ionic_tx_qcq *txq = dev->data->tx_queues[qid];
        struct ionic_tx_stats *stats = &txq->stats;
 
        IONIC_PRINT_CALL();
@@ -187,8 +185,7 @@ ionic_dev_tx_queue_setup(struct rte_eth_dev *eth_dev, uint16_t tx_queue_id,
 
        /* Free memory prior to re-allocation if needed... */
        if (eth_dev->data->tx_queues[tx_queue_id] != NULL) {
-               void *tx_queue = eth_dev->data->tx_queues[tx_queue_id];
-               ionic_dev_tx_queue_release(tx_queue);
+               ionic_dev_tx_queue_release(eth_dev, tx_queue_id);
                eth_dev->data->tx_queues[tx_queue_id] = NULL;
        }
 
@@ -206,11 +203,11 @@ ionic_dev_tx_queue_setup(struct rte_eth_dev *eth_dev, uint16_t tx_queue_id,
                txq->flags |= IONIC_QCQ_F_DEFERRED;
 
        /* Convert the offload flags into queue flags */
-       if (offloads & DEV_TX_OFFLOAD_IPV4_CKSUM)
+       if (offloads & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM)
                txq->flags |= IONIC_QCQ_F_CSUM_L3;
-       if (offloads & DEV_TX_OFFLOAD_TCP_CKSUM)
+       if (offloads & RTE_ETH_TX_OFFLOAD_TCP_CKSUM)
                txq->flags |= IONIC_QCQ_F_CSUM_TCP;
-       if (offloads & DEV_TX_OFFLOAD_UDP_CKSUM)
+       if (offloads & RTE_ETH_TX_OFFLOAD_UDP_CKSUM)
                txq->flags |= IONIC_QCQ_F_CSUM_UDP;
 
        eth_dev->data->tx_queues[tx_queue_id] = txq;
@@ -260,7 +257,7 @@ ionic_tx_tcp_pseudo_csum(struct rte_mbuf *txm)
        struct rte_tcp_hdr *tcp_hdr = (struct rte_tcp_hdr *)
                (l3_hdr + txm->l3_len);
 
-       if (txm->ol_flags & PKT_TX_IP_CKSUM) {
+       if (txm->ol_flags & RTE_MBUF_F_TX_IP_CKSUM) {
                struct rte_ipv4_hdr *ipv4_hdr = (struct rte_ipv4_hdr *)l3_hdr;
                ipv4_hdr->hdr_checksum = 0;
                tcp_hdr->cksum = 0;
@@ -281,7 +278,7 @@ ionic_tx_tcp_inner_pseudo_csum(struct rte_mbuf *txm)
        struct rte_tcp_hdr *tcp_hdr = (struct rte_tcp_hdr *)
                (l3_hdr + txm->l3_len);
 
-       if (txm->ol_flags & PKT_TX_IPV4) {
+       if (txm->ol_flags & RTE_MBUF_F_TX_IPV4) {
                struct rte_ipv4_hdr *ipv4_hdr = (struct rte_ipv4_hdr *)l3_hdr;
                ipv4_hdr->hdr_checksum = 0;
                tcp_hdr->cksum = 0;
@@ -322,9 +319,6 @@ ionic_tx_tso_post(struct ionic_queue *q, struct ionic_txq_desc *desc,
        }
 
        q->head_idx = Q_NEXT_TO_POST(q, 1);
-
-       if (done)
-               ionic_q_flush(q);
 }
 
 static struct ionic_txq_desc *
@@ -341,8 +335,7 @@ ionic_tx_tso_next(struct ionic_tx_qcq *txq, struct ionic_txq_sg_elem **elem)
 }
 
 static int
-ionic_tx_tso(struct ionic_tx_qcq *txq, struct rte_mbuf *txm,
-               bool not_xmit_more)
+ionic_tx_tso(struct ionic_tx_qcq *txq, struct rte_mbuf *txm)
 {
        struct ionic_queue *q = &txq->qcq.q;
        struct ionic_tx_stats *stats = &txq->stats;
@@ -362,14 +355,14 @@ ionic_tx_tso(struct ionic_tx_qcq *txq, struct rte_mbuf *txm,
        uint32_t offset = 0;
        bool start, done;
        bool encap;
-       bool has_vlan = !!(txm->ol_flags & PKT_TX_VLAN_PKT);
+       bool has_vlan = !!(txm->ol_flags & RTE_MBUF_F_TX_VLAN);
        uint16_t vlan_tci = txm->vlan_tci;
        uint64_t ol_flags = txm->ol_flags;
 
-       encap = ((ol_flags & PKT_TX_OUTER_IP_CKSUM) ||
-               (ol_flags & PKT_TX_OUTER_UDP_CKSUM)) &&
-               ((ol_flags & PKT_TX_OUTER_IPV4) ||
-               (ol_flags & PKT_TX_OUTER_IPV6));
+       encap = ((ol_flags & RTE_MBUF_F_TX_OUTER_IP_CKSUM) ||
+                (ol_flags & RTE_MBUF_F_TX_OUTER_UDP_CKSUM)) &&
+               ((ol_flags & RTE_MBUF_F_TX_OUTER_IPV4) ||
+                (ol_flags & RTE_MBUF_F_TX_OUTER_IPV6));
 
        /* Preload inner-most TCP csum field with IP pseudo hdr
         * calculated with IP length set to zero.  HW will later
@@ -410,7 +403,7 @@ ionic_tx_tso(struct ionic_tx_qcq *txq, struct rte_mbuf *txm,
                        hdrlen, mss,
                        encap,
                        vlan_tci, has_vlan,
-                       start, done && not_xmit_more);
+                       start, done);
                desc = ionic_tx_tso_next(txq, &elem);
                start = false;
                seglen = mss;
@@ -451,7 +444,7 @@ ionic_tx_tso(struct ionic_tx_qcq *txq, struct rte_mbuf *txm,
                                hdrlen, mss,
                                encap,
                                vlan_tci, has_vlan,
-                               start, done && not_xmit_more);
+                               start, done);
                        desc = ionic_tx_tso_next(txq, &elem);
                        start = false;
                }
@@ -465,8 +458,7 @@ ionic_tx_tso(struct ionic_tx_qcq *txq, struct rte_mbuf *txm,
 }
 
 static __rte_always_inline int
-ionic_tx(struct ionic_tx_qcq *txq, struct rte_mbuf *txm,
-               bool not_xmit_more)
+ionic_tx(struct ionic_tx_qcq *txq, struct rte_mbuf *txm)
 {
        struct ionic_queue *q = &txq->qcq.q;
        struct ionic_txq_desc *desc, *desc_base = q->base;
@@ -485,15 +477,15 @@ ionic_tx(struct ionic_tx_qcq *txq, struct rte_mbuf *txm,
        desc = &desc_base[q->head_idx];
        info = IONIC_INFO_PTR(q, q->head_idx);
 
-       if ((ol_flags & PKT_TX_IP_CKSUM) &&
+       if ((ol_flags & RTE_MBUF_F_TX_IP_CKSUM) &&
            (txq->flags & IONIC_QCQ_F_CSUM_L3)) {
                opcode = IONIC_TXQ_DESC_OPCODE_CSUM_HW;
                flags |= IONIC_TXQ_DESC_FLAG_CSUM_L3;
        }
 
-       if (((ol_flags & PKT_TX_TCP_CKSUM) &&
+       if (((ol_flags & RTE_MBUF_F_TX_TCP_CKSUM) &&
             (txq->flags & IONIC_QCQ_F_CSUM_TCP)) ||
-           ((ol_flags & PKT_TX_UDP_CKSUM) &&
+           ((ol_flags & RTE_MBUF_F_TX_UDP_CKSUM) &&
             (txq->flags & IONIC_QCQ_F_CSUM_UDP))) {
                opcode = IONIC_TXQ_DESC_OPCODE_CSUM_HW;
                flags |= IONIC_TXQ_DESC_FLAG_CSUM_L4;
@@ -502,11 +494,11 @@ ionic_tx(struct ionic_tx_qcq *txq, struct rte_mbuf *txm,
        if (opcode == IONIC_TXQ_DESC_OPCODE_CSUM_NONE)
                stats->no_csum++;
 
-       has_vlan = (ol_flags & PKT_TX_VLAN_PKT);
-       encap = ((ol_flags & PKT_TX_OUTER_IP_CKSUM) ||
-                       (ol_flags & PKT_TX_OUTER_UDP_CKSUM)) &&
-                       ((ol_flags & PKT_TX_OUTER_IPV4) ||
-                       (ol_flags & PKT_TX_OUTER_IPV6));
+       has_vlan = (ol_flags & RTE_MBUF_F_TX_VLAN);
+       encap = ((ol_flags & RTE_MBUF_F_TX_OUTER_IP_CKSUM) ||
+                       (ol_flags & RTE_MBUF_F_TX_OUTER_UDP_CKSUM)) &&
+                       ((ol_flags & RTE_MBUF_F_TX_OUTER_IPV4) ||
+                        (ol_flags & RTE_MBUF_F_TX_OUTER_IPV6));
 
        flags |= has_vlan ? IONIC_TXQ_DESC_FLAG_VLAN : 0;
        flags |= encap ? IONIC_TXQ_DESC_FLAG_ENCAP : 0;
@@ -531,9 +523,6 @@ ionic_tx(struct ionic_tx_qcq *txq, struct rte_mbuf *txm,
 
        q->head_idx = Q_NEXT_TO_POST(q, 1);
 
-       if (not_xmit_more)
-               ionic_q_flush(q);
-
        return 0;
 }
 
@@ -546,21 +535,19 @@ ionic_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
        struct ionic_tx_stats *stats = &txq->stats;
        uint32_t next_q_head_idx;
        uint32_t bytes_tx = 0;
-       uint16_t nb_tx = 0;
+       uint16_t nb_avail, nb_tx = 0;
        int err;
-       bool last;
 
        /* Cleaning old buffers */
        ionic_tx_flush(txq);
 
-       if (unlikely(ionic_q_space_avail(q) < nb_pkts)) {
-               stats->stop += nb_pkts;
-               return 0;
+       nb_avail = ionic_q_space_avail(q);
+       if (unlikely(nb_avail < nb_pkts)) {
+               stats->stop += nb_pkts - nb_avail;
+               nb_pkts = nb_avail;
        }
 
        while (nb_tx < nb_pkts) {
-               last = (nb_tx == (nb_pkts - 1));
-
                next_q_head_idx = Q_NEXT_TO_POST(q, 1);
                if ((next_q_head_idx & 0x3) == 0) {
                        struct ionic_txq_desc *desc_base = q->base;
@@ -568,14 +555,12 @@ ionic_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
                        rte_prefetch0(&q->info[next_q_head_idx]);
                }
 
-               if (tx_pkts[nb_tx]->ol_flags & PKT_TX_TCP_SEG)
-                       err = ionic_tx_tso(txq, tx_pkts[nb_tx], last);
+               if (tx_pkts[nb_tx]->ol_flags & RTE_MBUF_F_TX_TCP_SEG)
+                       err = ionic_tx_tso(txq, tx_pkts[nb_tx]);
                else
-                       err = ionic_tx(txq, tx_pkts[nb_tx], last);
+                       err = ionic_tx(txq, tx_pkts[nb_tx]);
                if (err) {
                        stats->drop += nb_pkts - nb_tx;
-                       if (nb_tx > 0)
-                               ionic_q_flush(q);
                        break;
                }
 
@@ -583,6 +568,11 @@ ionic_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
                nb_tx++;
        }
 
+       if (nb_tx > 0) {
+               rte_wmb();
+               ionic_q_flush(q);
+       }
+
        stats->packets += nb_tx;
        stats->bytes += bytes_tx;
 
@@ -595,21 +585,20 @@ ionic_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
  *
  **********************************************************************/
 
-#define IONIC_TX_OFFLOAD_MASK (        \
-       PKT_TX_IPV4 |           \
-       PKT_TX_IPV6 |           \
-       PKT_TX_VLAN |           \
-       PKT_TX_IP_CKSUM |       \
-       PKT_TX_TCP_SEG |        \
-       PKT_TX_L4_MASK)
+#define IONIC_TX_OFFLOAD_MASK (RTE_MBUF_F_TX_IPV4 |            \
+       RTE_MBUF_F_TX_IPV6 |            \
+       RTE_MBUF_F_TX_VLAN |            \
+       RTE_MBUF_F_TX_IP_CKSUM |        \
+       RTE_MBUF_F_TX_TCP_SEG | \
+       RTE_MBUF_F_TX_L4_MASK)
 
 #define IONIC_TX_OFFLOAD_NOTSUP_MASK \
-       (PKT_TX_OFFLOAD_MASK ^ IONIC_TX_OFFLOAD_MASK)
+       (RTE_MBUF_F_TX_OFFLOAD_MASK ^ IONIC_TX_OFFLOAD_MASK)
 
 uint16_t
-ionic_prep_pkts(void *tx_queue __rte_unused, struct rte_mbuf **tx_pkts,
-               uint16_t nb_pkts)
+ionic_prep_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
 {
+       struct ionic_tx_qcq *txq = tx_queue;
        struct rte_mbuf *txm;
        uint64_t offloads;
        int i = 0;
@@ -617,7 +606,7 @@ ionic_prep_pkts(void *tx_queue __rte_unused, struct rte_mbuf **tx_pkts,
        for (i = 0; i < nb_pkts; i++) {
                txm = tx_pkts[i];
 
-               if (txm->nb_segs > IONIC_TX_MAX_SG_ELEMS_V1 + 1) {
+               if (txm->nb_segs > txq->num_segs_fw) {
                        rte_errno = -EINVAL;
                        break;
                }
@@ -673,9 +662,9 @@ ionic_rx_empty(struct ionic_rx_qcq *rxq)
 }
 
 void __rte_cold
-ionic_dev_rx_queue_release(void *rx_queue)
+ionic_dev_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
 {
-       struct ionic_rx_qcq *rxq = rx_queue;
+       struct ionic_rx_qcq *rxq = dev->data->rx_queues[qid];
        struct ionic_rx_stats *stats;
 
        if (!rxq)
@@ -735,8 +724,7 @@ ionic_dev_rx_queue_setup(struct rte_eth_dev *eth_dev,
 
        /* Free memory prior to re-allocation if needed... */
        if (eth_dev->data->rx_queues[rx_queue_id] != NULL) {
-               void *rx_queue = eth_dev->data->rx_queues[rx_queue_id];
-               ionic_dev_rx_queue_release(rx_queue);
+               ionic_dev_rx_queue_release(eth_dev, rx_queue_id);
                eth_dev->data->rx_queues[rx_queue_id] = NULL;
        }
 
@@ -754,11 +742,11 @@ ionic_dev_rx_queue_setup(struct rte_eth_dev *eth_dev,
 
        /*
         * Note: the interface does not currently support
-        * DEV_RX_OFFLOAD_KEEP_CRC, please also consider ETHER_CRC_LEN
+        * RTE_ETH_RX_OFFLOAD_KEEP_CRC, please also consider ETHER_CRC_LEN
         * when the adapter will be able to keep the CRC and subtract
         * it to the length for all received packets:
         * if (eth_dev->data->dev_conf.rxmode.offloads &
-        *     DEV_RX_OFFLOAD_KEEP_CRC)
+        *     RTE_ETH_RX_OFFLOAD_KEEP_CRC)
         *   rxq->crc_len = ETHER_CRC_LEN;
         */
 
@@ -782,7 +770,7 @@ ionic_rx_clean(struct ionic_rx_qcq *rxq,
        struct ionic_rxq_comp *cq_desc = &cq_desc_base[cq_desc_index];
        struct rte_mbuf *rxm, *rxm_seg;
        uint32_t max_frame_size =
-               rxq->qcq.lif->eth_dev->data->dev_conf.rxmode.max_rx_pkt_len;
+               rxq->qcq.lif->eth_dev->data->mtu + RTE_ETHER_HDR_LEN;
        uint64_t pkt_flags = 0;
        uint32_t pkt_type;
        struct ionic_rx_stats *stats = &rxq->stats;
@@ -851,30 +839,30 @@ ionic_rx_clean(struct ionic_rx_qcq *rxq,
        }
 
        /* RSS */
-       pkt_flags |= PKT_RX_RSS_HASH;
+       pkt_flags |= RTE_MBUF_F_RX_RSS_HASH;
        rxm->hash.rss = cq_desc->rss_hash;
 
        /* Vlan Strip */
        if (cq_desc->csum_flags & IONIC_RXQ_COMP_CSUM_F_VLAN) {
-               pkt_flags |= PKT_RX_VLAN | PKT_RX_VLAN_STRIPPED;
+               pkt_flags |= RTE_MBUF_F_RX_VLAN | RTE_MBUF_F_RX_VLAN_STRIPPED;
                rxm->vlan_tci = cq_desc->vlan_tci;
        }
 
        /* Checksum */
        if (cq_desc->csum_flags & IONIC_RXQ_COMP_CSUM_F_CALC) {
                if (cq_desc->csum_flags & IONIC_RXQ_COMP_CSUM_F_IP_OK)
-                       pkt_flags |= PKT_RX_IP_CKSUM_GOOD;
+                       pkt_flags |= RTE_MBUF_F_RX_IP_CKSUM_GOOD;
                else if (cq_desc->csum_flags & IONIC_RXQ_COMP_CSUM_F_IP_BAD)
-                       pkt_flags |= PKT_RX_IP_CKSUM_BAD;
+                       pkt_flags |= RTE_MBUF_F_RX_IP_CKSUM_BAD;
 
                if ((cq_desc->csum_flags & IONIC_RXQ_COMP_CSUM_F_TCP_OK) ||
                        (cq_desc->csum_flags & IONIC_RXQ_COMP_CSUM_F_UDP_OK))
-                       pkt_flags |= PKT_RX_L4_CKSUM_GOOD;
+                       pkt_flags |= RTE_MBUF_F_RX_L4_CKSUM_GOOD;
                else if ((cq_desc->csum_flags &
                                IONIC_RXQ_COMP_CSUM_F_TCP_BAD) ||
                                (cq_desc->csum_flags &
                                IONIC_RXQ_COMP_CSUM_F_UDP_BAD))
-                       pkt_flags |= PKT_RX_L4_CKSUM_BAD;
+                       pkt_flags |= RTE_MBUF_F_RX_L4_CKSUM_BAD;
        }
 
        rxm->ol_flags = pkt_flags;
@@ -954,7 +942,6 @@ ionic_rx_fill(struct ionic_rx_qcq *rxq, uint32_t len)
        void **info;
        rte_iova_t dma_addr;
        uint32_t i, j, nsegs, buf_size, size;
-       bool ring_doorbell;
 
        buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mb_pool) -
                RTE_PKTMBUF_HEADROOM);
@@ -1010,17 +997,13 @@ ionic_rx_fill(struct ionic_rx_qcq *rxq, uint32_t len)
                        IONIC_PRINT(ERR, "Rx SG size is not sufficient (%d < %d)",
                                size, len);
 
-               ring_doorbell = ((q->head_idx + 1) &
-                       IONIC_RX_RING_DOORBELL_STRIDE) == 0;
-
                info[0] = rxm;
 
                q->head_idx = Q_NEXT_TO_POST(q, 1);
-
-               if (ring_doorbell)
-                       ionic_q_flush(q);
        }
 
+       ionic_q_flush(q);
+
        return 0;
 }
 
@@ -1030,7 +1013,7 @@ ionic_rx_fill(struct ionic_rx_qcq *rxq, uint32_t len)
 int __rte_cold
 ionic_dev_rx_queue_start(struct rte_eth_dev *eth_dev, uint16_t rx_queue_id)
 {
-       uint32_t frame_size = eth_dev->data->dev_conf.rxmode.max_rx_pkt_len;
+       uint32_t frame_size = eth_dev->data->mtu + RTE_ETHER_HDR_LEN;
        uint8_t *rx_queue_state = eth_dev->data->rx_queue_state;
        struct ionic_rx_qcq *rxq;
        int err;
@@ -1144,7 +1127,7 @@ ionic_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
 {
        struct ionic_rx_qcq *rxq = rx_queue;
        uint32_t frame_size =
-               rxq->qcq.lif->eth_dev->data->dev_conf.rxmode.max_rx_pkt_len;
+               rxq->qcq.lif->eth_dev->data->mtu + RTE_ETHER_HDR_LEN;
        struct ionic_rx_service service_cb_arg;
 
        service_cb_arg.rx_pkts = rx_pkts;