net: add rte prefix to ether defines
[dpdk.git] / drivers / net / mlx5 / mlx5_rxtx.c
index 24a054d..7174ffc 100644 (file)
@@ -417,20 +417,17 @@ mlx5_tx_descriptor_status(void *tx_queue, uint16_t offset)
 }
 
 /**
- * DPDK callback to check the status of a rx descriptor.
+ * Internal function to compute the number of used descriptors in an RX queue
  *
- * @param rx_queue
- *   The rx queue.
- * @param[in] offset
- *   The index of the descriptor in the ring.
+ * @param rxq
+ *   The Rx queue.
  *
  * @return
- *   The status of the tx descriptor.
+ *   The number of used rx descriptor.
  */
-int
-mlx5_rx_descriptor_status(void *rx_queue, uint16_t offset)
+static uint32_t
+rx_queue_count(struct mlx5_rxq_data *rxq)
 {
-       struct mlx5_rxq_data *rxq = rx_queue;
        struct rxq_zip *zip = &rxq->zip;
        volatile struct mlx5_cqe *cqe;
        const unsigned int cqe_n = (1 << rxq->cqe_n);
@@ -461,11 +458,72 @@ mlx5_rx_descriptor_status(void *rx_queue, uint16_t offset)
                cqe = &(*rxq->cqes)[cq_ci & cqe_cnt];
        }
        used = RTE_MIN(used, (1U << rxq->elts_n) - 1);
-       if (offset < used)
+       return used;
+}
+
+/**
+ * DPDK callback to check the status of a rx descriptor.
+ *
+ * @param rx_queue
+ *   The Rx queue.
+ * @param[in] offset
+ *   The index of the descriptor in the ring.
+ *
+ * @return
+ *   The status of the tx descriptor.
+ */
+int
+mlx5_rx_descriptor_status(void *rx_queue, uint16_t offset)
+{
+       struct mlx5_rxq_data *rxq = rx_queue;
+       struct mlx5_rxq_ctrl *rxq_ctrl =
+                       container_of(rxq, struct mlx5_rxq_ctrl, rxq);
+       struct rte_eth_dev *dev = ETH_DEV(rxq_ctrl->priv);
+
+       if (dev->rx_pkt_burst != mlx5_rx_burst) {
+               rte_errno = ENOTSUP;
+               return -rte_errno;
+       }
+       if (offset >= (1 << rxq->elts_n)) {
+               rte_errno = EINVAL;
+               return -rte_errno;
+       }
+       if (offset < rx_queue_count(rxq))
                return RTE_ETH_RX_DESC_DONE;
        return RTE_ETH_RX_DESC_AVAIL;
 }
 
+/**
+ * DPDK callback to get the number of used descriptors in a RX queue
+ *
+ * @param dev
+ *   Pointer to the device structure.
+ *
+ * @param rx_queue_id
+ *   The Rx queue.
+ *
+ * @return
+ *   The number of used rx descriptor.
+ *   -EINVAL if the queue is invalid
+ */
+uint32_t
+mlx5_rx_queue_count(struct rte_eth_dev *dev, uint16_t rx_queue_id)
+{
+       struct mlx5_priv *priv = dev->data->dev_private;
+       struct mlx5_rxq_data *rxq;
+
+       if (dev->rx_pkt_burst != mlx5_rx_burst) {
+               rte_errno = ENOTSUP;
+               return -rte_errno;
+       }
+       rxq = (*priv->rxqs)[rx_queue_id];
+       if (!rxq) {
+               rte_errno = EINVAL;
+               return -rte_errno;
+       }
+       return rx_queue_count(rxq);
+}
+
 /**
  * DPDK callback for TX.
  *
@@ -574,7 +632,7 @@ mlx5_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n)
                if (buf->ol_flags & PKT_TX_VLAN_PKT) {
                        uint32_t vlan = rte_cpu_to_be_32(0x81000000 |
                                                         buf->vlan_tci);
-                       unsigned int len = 2 * ETHER_ADDR_LEN - 2;
+                       unsigned int len = 2 * RTE_ETHER_ADDR_LEN - 2;
 
                        addr += 2;
                        length -= 2;
@@ -635,7 +693,8 @@ pkt_inline:
                                                   RTE_CACHE_LINE_SIZE);
                        copy_b = (addr_end > addr) ?
                                 RTE_MIN((addr_end - addr), length) : 0;
-                       if (copy_b && ((end - (uintptr_t)raw) > copy_b)) {
+                       if (copy_b && ((end - (uintptr_t)raw) >
+                                      (copy_b + sizeof(inl)))) {
                                /*
                                 * One Dseg remains in the current WQE.  To
                                 * keep the computation positive, it is
@@ -1999,7 +2058,7 @@ mlx5_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
                                                        mcqe->rx_hash_result);
                        rxq_cq_to_mbuf(rxq, pkt, cqe, rss_hash_res);
                        if (rxq->crc_present)
-                               len -= ETHER_CRC_LEN;
+                               len -= RTE_ETHER_CRC_LEN;
                        PKT_LEN(pkt) = len;
                }
                DATA_LEN(rep) = DATA_LEN(seg);
@@ -2205,7 +2264,7 @@ mlx5_rx_burst_mprq(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
                len = (byte_cnt & MLX5_MPRQ_LEN_MASK) >> MLX5_MPRQ_LEN_SHIFT;
                assert((int)len >= (rxq->crc_present << 2));
                if (rxq->crc_present)
-                       len -= ETHER_CRC_LEN;
+                       len -= RTE_ETHER_CRC_LEN;
                offset = strd_idx * strd_sz + strd_shift;
                addr = RTE_PTR_ADD(mlx5_mprq_buf_addr(buf), offset);
                /* Initialize the offload flag. */
@@ -2314,6 +2373,7 @@ removed_tx_burst(void *dpdk_txq __rte_unused,
                 struct rte_mbuf **pkts __rte_unused,
                 uint16_t pkts_n __rte_unused)
 {
+       rte_mb();
        return 0;
 }
 
@@ -2338,6 +2398,7 @@ removed_rx_burst(void *dpdk_txq __rte_unused,
                 struct rte_mbuf **pkts __rte_unused,
                 uint16_t pkts_n __rte_unused)
 {
+       rte_mb();
        return 0;
 }