net: add rte prefix to ether structures
[dpdk.git] / drivers / net / ena / ena_ethdev.c
index 0aeb85f..1d832f9 100644 (file)
@@ -31,6 +31,7 @@
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
+#include <rte_string_fns.h>
 #include <rte_ether.h>
 #include <rte_ethdev_driver.h>
 #include <rte_ethdev_pci.h>
@@ -53,9 +54,9 @@
 #include <ena_admin_defs.h>
 #include <ena_eth_io_defs.h>
 
-#define DRV_MODULE_VER_MAJOR   1
-#define DRV_MODULE_VER_MINOR   1
-#define DRV_MODULE_VER_SUBMINOR        1
+#define DRV_MODULE_VER_MAJOR   2
+#define DRV_MODULE_VER_MINOR   0
+#define DRV_MODULE_VER_SUBMINOR        0
 
 #define ENA_IO_TXQ_IDX(q)      (2 * (q))
 #define ENA_IO_RXQ_IDX(q)      (2 * (q) + 1)
@@ -421,13 +422,11 @@ static void ena_config_host_info(struct ena_com_dev *ena_dev)
 
        host_info->os_type = ENA_ADMIN_OS_DPDK;
        host_info->kernel_ver = RTE_VERSION;
-       snprintf((char *)host_info->kernel_ver_str,
-                sizeof(host_info->kernel_ver_str),
-                "%s", rte_version());
+       strlcpy((char *)host_info->kernel_ver_str, rte_version(),
+               sizeof(host_info->kernel_ver_str));
        host_info->os_dist = RTE_VERSION;
-       snprintf((char *)host_info->os_dist_str,
-                sizeof(host_info->os_dist_str),
-                "%s", rte_version());
+       strlcpy((char *)host_info->os_dist_str, rte_version(),
+               sizeof(host_info->os_dist_str));
        host_info->driver_version =
                (DRV_MODULE_VER_MAJOR) |
                (DRV_MODULE_VER_MINOR << ENA_ADMIN_HOST_INFO_MINOR_SHIFT) |
@@ -1687,8 +1686,7 @@ static int ena_calc_io_queue_num(struct ena_com_dev *ena_dev,
        if (ena_dev->tx_mem_queue_type == ENA_ADMIN_PLACEMENT_POLICY_DEV)
                io_tx_sq_num = get_feat_ctx->llq.max_llq_num;
 
-       io_queue_num = RTE_MIN(rte_lcore_count(), ENA_MAX_NUM_IO_QUEUES);
-       io_queue_num = RTE_MIN(io_queue_num, io_rx_num);
+       io_queue_num = RTE_MIN(ENA_MAX_NUM_IO_QUEUES, io_rx_num);
        io_queue_num = RTE_MIN(io_queue_num, io_tx_sq_num);
        io_queue_num = RTE_MIN(io_queue_num, io_tx_cq_num);
 
@@ -1716,19 +1714,20 @@ static int eth_ena_dev_init(struct rte_eth_dev *eth_dev)
        static int adapters_found;
        bool wd_state;
 
-       memset(adapter, 0, sizeof(struct ena_adapter));
-       ena_dev = &adapter->ena_dev;
-
        eth_dev->dev_ops = &ena_dev_ops;
        eth_dev->rx_pkt_burst = &eth_ena_recv_pkts;
        eth_dev->tx_pkt_burst = &eth_ena_xmit_pkts;
        eth_dev->tx_pkt_prepare = &eth_ena_prep_pkts;
-       adapter->rte_eth_dev_data = eth_dev->data;
-       adapter->rte_dev = eth_dev;
 
        if (rte_eal_process_type() != RTE_PROC_PRIMARY)
                return 0;
 
+       memset(adapter, 0, sizeof(struct ena_adapter));
+       ena_dev = &adapter->ena_dev;
+
+       adapter->rte_eth_dev_data = eth_dev->data;
+       adapter->rte_dev = eth_dev;
+
        pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
        adapter->pdev = pci_dev;
 
@@ -1804,14 +1803,19 @@ static int eth_ena_dev_init(struct rte_eth_dev *eth_dev)
        /* Set max MTU for this device */
        adapter->max_mtu = get_feat_ctx.dev_attr.max_mtu;
 
-       /* set device support for TSO */
-       adapter->tso4_supported = get_feat_ctx.offload.tx &
-                                 ENA_ADMIN_FEATURE_OFFLOAD_DESC_TSO_IPV4_MASK;
+       /* set device support for offloads */
+       adapter->offloads.tso4_supported = (get_feat_ctx.offload.tx &
+               ENA_ADMIN_FEATURE_OFFLOAD_DESC_TSO_IPV4_MASK) != 0;
+       adapter->offloads.tx_csum_supported = (get_feat_ctx.offload.tx &
+               ENA_ADMIN_FEATURE_OFFLOAD_DESC_TX_L4_IPV4_CSUM_PART_MASK) != 0;
+       adapter->offloads.rx_csum_supported =
+               (get_feat_ctx.offload.rx_supported &
+               ENA_ADMIN_FEATURE_OFFLOAD_DESC_RX_L4_IPV4_CSUM_MASK) != 0;
 
        /* Copy MAC address and point DPDK to it */
-       eth_dev->data->mac_addrs = (struct ether_addr *)adapter->mac_addr;
-       ether_addr_copy((struct ether_addr *)get_feat_ctx.dev_attr.mac_addr,
-                       (struct ether_addr *)adapter->mac_addr);
+       eth_dev->data->mac_addrs = (struct rte_ether_addr *)adapter->mac_addr;
+       ether_addr_copy((struct rte_ether_addr *)get_feat_ctx.dev_attr.mac_addr,
+                       (struct rte_ether_addr *)adapter->mac_addr);
 
        /*
         * Pass the information to the rte_eth_dev_close() that it should also
@@ -1939,9 +1943,7 @@ static void ena_infos_get(struct rte_eth_dev *dev,
 {
        struct ena_adapter *adapter;
        struct ena_com_dev *ena_dev;
-       struct ena_com_dev_get_features_ctx feat;
        uint64_t rx_feat = 0, tx_feat = 0;
-       int rc = 0;
 
        ena_assert_msg(dev->data != NULL, "Uninitialized device\n");
        ena_assert_msg(dev->data->dev_private != NULL, "Uninitialized device\n");
@@ -1960,26 +1962,16 @@ static void ena_infos_get(struct rte_eth_dev *dev,
                        ETH_LINK_SPEED_50G  |
                        ETH_LINK_SPEED_100G;
 
-       /* Get supported features from HW */
-       rc = ena_com_get_dev_attr_feat(ena_dev, &feat);
-       if (unlikely(rc)) {
-               RTE_LOG(ERR, PMD,
-                       "Cannot get attribute for ena device rc= %d\n", rc);
-               return;
-       }
-
        /* Set Tx & Rx features available for device */
-       if (feat.offload.tx & ENA_ADMIN_FEATURE_OFFLOAD_DESC_TSO_IPV4_MASK)
+       if (adapter->offloads.tso4_supported)
                tx_feat |= DEV_TX_OFFLOAD_TCP_TSO;
 
-       if (feat.offload.tx &
-           ENA_ADMIN_FEATURE_OFFLOAD_DESC_TX_L4_IPV4_CSUM_PART_MASK)
+       if (adapter->offloads.tx_csum_supported)
                tx_feat |= DEV_TX_OFFLOAD_IPV4_CKSUM |
                        DEV_TX_OFFLOAD_UDP_CKSUM |
                        DEV_TX_OFFLOAD_TCP_CKSUM;
 
-       if (feat.offload.rx_supported &
-           ENA_ADMIN_FEATURE_OFFLOAD_DESC_RX_L4_IPV4_CSUM_MASK)
+       if (adapter->offloads.rx_csum_supported)
                rx_feat |= DEV_RX_OFFLOAD_IPV4_CKSUM |
                        DEV_RX_OFFLOAD_UDP_CKSUM  |
                        DEV_RX_OFFLOAD_TCP_CKSUM;
@@ -2128,8 +2120,10 @@ static uint16_t eth_ena_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
 
        desc_in_use = desc_in_use - completed + 1;
        /* Burst refill to save doorbells, memory barriers, const interval */
-       if (ring_size - desc_in_use > ENA_RING_DESCS_RATIO(ring_size))
+       if (ring_size - desc_in_use > ENA_RING_DESCS_RATIO(ring_size)) {
+               ena_com_update_dev_comp_head(rx_ring->ena_com_io_cq);
                ena_populate_rx_queue(rx_ring, ring_size - desc_in_use);
+       }
 
        return recv_idx;
 }
@@ -2157,7 +2151,7 @@ eth_ena_prep_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
                 * length of the ethernet header.
                 */
                if (unlikely(m->l2_len == 0))
-                       m->l2_len = sizeof(struct ether_hdr);
+                       m->l2_len = sizeof(struct rte_ether_hdr);
 
                ip_hdr = rte_pktmbuf_mtod_offset(m, struct ipv4_hdr *,
                                                 m->l2_len);
@@ -2169,21 +2163,21 @@ eth_ena_prep_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
                        /* If IPv4 header has DF flag enabled and TSO support is
                         * disabled, partial chcecksum should not be calculated.
                         */
-                       if (!tx_ring->adapter->tso4_supported)
+                       if (!tx_ring->adapter->offloads.tso4_supported)
                                continue;
                }
 
                if ((ol_flags & ENA_TX_OFFLOAD_NOTSUP_MASK) != 0 ||
                                (ol_flags & PKT_TX_L4_MASK) ==
                                PKT_TX_SCTP_CKSUM) {
-                       rte_errno = -ENOTSUP;
+                       rte_errno = ENOTSUP;
                        return i;
                }
 
 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
                ret = rte_validate_tx_offload(m);
                if (ret != 0) {
-                       rte_errno = ret;
+                       rte_errno = -ret;
                        return i;
                }
 #endif
@@ -2196,7 +2190,7 @@ eth_ena_prep_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
                ret = rte_net_intel_cksum_flags_prepare(m,
                        ol_flags & ~PKT_TX_TCP_SEG);
                if (ret != 0) {
-                       rte_errno = ret;
+                       rte_errno = -ret;
                        return i;
                }
        }
@@ -2440,8 +2434,9 @@ static uint16_t eth_ena_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
 
        if (total_tx_descs > 0) {
                /* acknowledge completion of sent packets */
-               ena_com_comp_ack(tx_ring->ena_com_io_sq, total_tx_descs);
                tx_ring->next_to_clean = next_to_clean;
+               ena_com_comp_ack(tx_ring->ena_com_io_sq, total_tx_descs);
+               ena_com_update_dev_comp_head(tx_ring->ena_com_io_cq);
        }
 
        tx_ring->tx_stats.tx_poll++;