net/mlx4: add loopback Tx from VF
authorMoti Haimovsky <motih@mellanox.com>
Thu, 12 Oct 2017 12:30:00 +0000 (14:30 +0200)
committerFerruh Yigit <ferruh.yigit@intel.com>
Fri, 13 Oct 2017 00:18:48 +0000 (01:18 +0100)
This patch adds loopback functionality used when the chip is a VF in order
to enable packet transmission between VFs and PF.

Signed-off-by: Moti Haimovsky <motih@mellanox.com>
Acked-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
drivers/net/mlx4/mlx4_rxtx.c
drivers/net/mlx4/mlx4_rxtx.h
drivers/net/mlx4/mlx4_txq.c

index 87c5261..36173ad 100644 (file)
@@ -311,10 +311,13 @@ mlx4_post_send(struct txq *txq, struct rte_mbuf *pkt)
        struct mlx4_wqe_data_seg *dseg;
        struct mlx4_sq *sq = &txq->msq;
        struct rte_mbuf *buf;
+       union {
+               uint32_t flags;
+               uint16_t flags16[2];
+       } srcrb;
        uint32_t head_idx = sq->head & sq->txbb_cnt_mask;
        uint32_t lkey;
        uintptr_t addr;
-       uint32_t srcrb_flags;
        uint32_t owner_opcode = MLX4_OPCODE_SEND;
        uint32_t byte_count;
        int wqe_real_size;
@@ -413,12 +416,6 @@ mlx4_post_send(struct txq *txq, struct rte_mbuf *pkt)
        }
        /* Fill the control parameters for this packet. */
        ctrl->fence_size = (wqe_real_size >> 4) & 0x3f;
-       /*
-        * The caller should prepare "imm" in advance in order to support
-        * VF to VF communication (when the device is a virtual-function
-        * device (VF)).
-        */
-       ctrl->imm = 0;
        /*
         * For raw Ethernet, the SOLICIT flag is used to indicate that no ICRC
         * should be calculated.
@@ -426,10 +423,10 @@ mlx4_post_send(struct txq *txq, struct rte_mbuf *pkt)
        txq->elts_comp_cd -= nr_txbbs;
        if (unlikely(txq->elts_comp_cd <= 0)) {
                txq->elts_comp_cd = txq->elts_comp_cd_init;
-               srcrb_flags = RTE_BE32(MLX4_WQE_CTRL_SOLICIT |
+               srcrb.flags = RTE_BE32(MLX4_WQE_CTRL_SOLICIT |
                                       MLX4_WQE_CTRL_CQ_UPDATE);
        } else {
-               srcrb_flags = RTE_BE32(MLX4_WQE_CTRL_SOLICIT);
+               srcrb.flags = RTE_BE32(MLX4_WQE_CTRL_SOLICIT);
        }
        /* Enable HW checksum offload if requested */
        if (txq->csum &&
@@ -443,14 +440,26 @@ mlx4_post_send(struct txq *txq, struct rte_mbuf *pkt)
                        owner_opcode |= MLX4_WQE_CTRL_IIP_HDR_CSUM |
                                        MLX4_WQE_CTRL_IL4_HDR_CSUM;
                        if (pkt->ol_flags & PKT_TX_OUTER_IP_CKSUM)
-                               srcrb_flags |=
+                               srcrb.flags |=
                                        RTE_BE32(MLX4_WQE_CTRL_IP_HDR_CSUM);
                } else {
-                       srcrb_flags |= RTE_BE32(MLX4_WQE_CTRL_IP_HDR_CSUM |
+                       srcrb.flags |= RTE_BE32(MLX4_WQE_CTRL_IP_HDR_CSUM |
                                                MLX4_WQE_CTRL_TCP_UDP_CSUM);
                }
        }
-       ctrl->srcrb_flags = srcrb_flags;
+       if (txq->lb) {
+               /*
+                * Copy destination MAC address to the WQE, this allows
+                * loopback in eSwitch, so that VFs and PF can communicate
+                * with each other.
+                */
+               srcrb.flags16[0] = *(rte_pktmbuf_mtod(pkt, uint16_t *));
+               ctrl->imm = *(rte_pktmbuf_mtod_offset(pkt, uint32_t *,
+                                                     sizeof(uint16_t)));
+       } else {
+               ctrl->imm = 0;
+       }
+       ctrl->srcrb_flags = srcrb.flags;
        /*
         * Make sure descriptor is fully written before
         * setting ownership bit (because HW can start
index 51af69c..e10bbca 100644 (file)
@@ -128,6 +128,7 @@ struct txq {
        uint32_t max_inline; /**< Max inline send size. */
        uint32_t csum:1; /**< Enable checksum offloading. */
        uint32_t csum_l2tun:1; /**< Same for L2 tunnels. */
+       uint32_t lb:1; /**< Whether packets should be looped back by eSwitch. */
        uint8_t *bounce_buf;
        /**< Memory used for storing the first DWORD of data TXBBs. */
        struct {
index 0e27df2..6d3dd78 100644 (file)
@@ -278,6 +278,8 @@ mlx4_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
                        RTE_MIN(MLX4_PMD_TX_PER_COMP_REQ, desc / 4),
                .csum = priv->hw_csum,
                .csum_l2tun = priv->hw_csum_l2tun,
+               /* Enable Tx loopback for VF devices. */
+               .lb = !!priv->vf,
                .bounce_buf = bounce_buf,
        };
        txq->cq = ibv_create_cq(priv->ctx, desc, NULL, NULL, 0);