drivers: rename register macro prefix
[dpdk.git] / drivers / net / ena / ena_ethdev.c
index 11e7d8e..737ae87 100644 (file)
@@ -38,6 +38,7 @@
 #include <rte_dev.h>
 #include <rte_errno.h>
 #include <rte_version.h>
+#include <rte_eal_memconfig.h>
 
 #include "ena_ethdev.h"
 #include "ena_logs.h"
@@ -168,10 +169,9 @@ static const struct ena_stats ena_stats_ena_com_strings[] = {
 #define PCI_DEVICE_ID_ENA_LLQ_VF       0xEC21
 
 static struct rte_pci_id pci_id_ena_map[] = {
-#define RTE_PCI_DEV_ID_DECL_ENA(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
-       RTE_PCI_DEV_ID_DECL_ENA(PCI_VENDOR_ID_AMAZON, PCI_DEVICE_ID_ENA_VF)
-       RTE_PCI_DEV_ID_DECL_ENA(PCI_VENDOR_ID_AMAZON, PCI_DEVICE_ID_ENA_LLQ_VF)
-       {.device_id = 0},
+       { RTE_PCI_DEVICE(PCI_VENDOR_ID_AMAZON, PCI_DEVICE_ID_ENA_VF) },
+       { RTE_PCI_DEVICE(PCI_VENDOR_ID_AMAZON, PCI_DEVICE_ID_ENA_LLQ_VF) },
+       { .device_id = 0 },
 };
 
 static int ena_device_init(struct ena_com_dev *ena_dev,
@@ -232,6 +232,18 @@ static struct eth_dev_ops ena_dev_ops = {
        .reta_query           = ena_rss_reta_query,
 };
 
+#define NUMA_NO_NODE   SOCKET_ID_ANY
+
+static inline int ena_cpu_to_node(int cpu)
+{
+       struct rte_config *config = rte_eal_get_configuration();
+
+       if (likely(cpu < RTE_MAX_MEMZONE))
+               return config->mem_config->memzone[cpu].socket_id;
+
+       return NUMA_NO_NODE;
+}
+
 static inline void ena_rx_mbuf_prepare(struct rte_mbuf *mbuf,
                                       struct ena_com_rx_ctx *ena_rx_ctx)
 {
@@ -330,11 +342,13 @@ 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;
-       strncpy((char *)host_info->kernel_ver_str, rte_version(),
-               strlen(rte_version()));
+       snprintf((char *)host_info->kernel_ver_str,
+                sizeof(host_info->kernel_ver_str),
+                "%s", rte_version());
        host_info->os_dist = RTE_VERSION;
-       strncpy((char *)host_info->os_dist_str, rte_version(),
-               strlen(rte_version()));
+       snprintf((char *)host_info->os_dist_str,
+                sizeof(host_info->os_dist_str),
+                "%s", rte_version());
        host_info->driver_version =
                (DRV_MODULE_VER_MAJOR) |
                (DRV_MODULE_VER_MINOR << ENA_ADMIN_HOST_INFO_MINOR_SHIFT) |
@@ -962,6 +976,7 @@ static int ena_tx_queue_setup(struct rte_eth_dev *dev,
        ctx.msix_vector = -1; /* admin interrupts not used */
        ctx.mem_queue_type = ena_dev->tx_mem_queue_type;
        ctx.queue_size = adapter->tx_ring_size;
+       ctx.numa_node = ena_cpu_to_node(queue_idx);
 
        rc = ena_com_create_io_queue(ena_dev, &ctx);
        if (rc) {
@@ -1055,6 +1070,7 @@ static int ena_rx_queue_setup(struct rte_eth_dev *dev,
        ctx.mem_queue_type = ENA_ADMIN_PLACEMENT_POLICY_HOST;
        ctx.msix_vector = -1; /* admin interrupts not used */
        ctx.queue_size = adapter->rx_ring_size;
+       ctx.numa_node = ena_cpu_to_node(queue_idx);
 
        rc = ena_com_create_io_queue(ena_dev, &ctx);
        if (rc)
@@ -1140,10 +1156,14 @@ static int ena_populate_rx_queue(struct ena_ring *rxq, unsigned int count)
                next_to_use = ENA_RX_RING_IDX_NEXT(next_to_use, ring_size);
        }
 
-       rte_wmb();
-       rxq->next_to_use = next_to_use;
-       /* let HW know that it can fill buffers with data */
-       ena_com_write_sq_doorbell(rxq->ena_com_io_sq);
+       /* When we submitted free recources to device... */
+       if (i > 0) {
+               /* ...let HW know that it can fill buffers with data */
+               rte_wmb();
+               ena_com_write_sq_doorbell(rxq->ena_com_io_sq);
+
+               rxq->next_to_use = next_to_use;
+       }
 
        return i;
 }
@@ -1549,7 +1569,7 @@ static uint16_t eth_ena_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
        struct ena_tx_buffer *tx_info;
        struct ena_com_buf *ebuf;
        uint16_t rc, req_id, total_tx_descs = 0;
-       int sent_idx = 0;
+       uint16_t sent_idx = 0;
        int nb_hw_desc;
 
        /* Check adapter state */
@@ -1628,9 +1648,14 @@ static uint16_t eth_ena_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
                next_to_use = ENA_TX_RING_IDX_NEXT(next_to_use, ring_size);
        }
 
-       /* Let HW do it's best :-) */
-       rte_wmb();
-       ena_com_write_sq_doorbell(tx_ring->ena_com_io_sq);
+       /* If there are ready packets to be xmitted... */
+       if (sent_idx > 0) {
+               /* ...let HW do its best :-) */
+               rte_wmb();
+               ena_com_write_sq_doorbell(tx_ring->ena_com_io_sq);
+
+               tx_ring->next_to_use = next_to_use;
+       }
 
        /* Clear complete packets  */
        while (ena_com_tx_comp_req_id_get(tx_ring->ena_com_io_cq, &req_id) >= 0) {
@@ -1653,34 +1678,24 @@ static uint16_t eth_ena_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
                        break;
        }
 
-       /* acknowledge completion of sent packets */
-       ena_com_comp_ack(tx_ring->ena_com_io_sq, total_tx_descs);
-       tx_ring->next_to_use = next_to_use;
+       if (total_tx_descs > 0) {
+               /* acknowledge completion of sent packets */
+               ena_com_comp_ack(tx_ring->ena_com_io_sq, total_tx_descs);
+       }
+
        return sent_idx;
 }
 
 static struct eth_driver rte_ena_pmd = {
-       {
-               .name = "rte_ena_pmd",
+       .pci_drv = {
                .id_table = pci_id_ena_map,
                .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
+               .probe = rte_eth_dev_pci_probe,
+               .remove = rte_eth_dev_pci_remove,
        },
        .eth_dev_init = eth_ena_dev_init,
        .dev_private_size = sizeof(struct ena_adapter),
 };
 
-static int
-rte_ena_pmd_init(const char *name __rte_unused,
-                const char *params __rte_unused)
-{
-       rte_eth_driver_register(&rte_ena_pmd);
-       return 0;
-};
-
-struct rte_driver ena_pmd_drv = {
-       .type = PMD_PDEV,
-       .init = rte_ena_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(ena_pmd_drv, ena);
-DRIVER_REGISTER_PCI_TABLE(ena, pci_id_ena_map);
+RTE_PMD_REGISTER_PCI(net_ena, rte_ena_pmd.pci_drv);
+RTE_PMD_REGISTER_PCI_TABLE(net_ena, pci_id_ena_map);