From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf0-f67.google.com (mail-lf0-f67.google.com [209.85.215.67]) by dpdk.org (Postfix) with ESMTP id E8A761B16F for ; Thu, 7 Jun 2018 11:43:35 +0200 (CEST) Received: by mail-lf0-f67.google.com with SMTP id i83-v6so13654280lfh.5 for ; Thu, 07 Jun 2018 02:43:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=kSfrk1ixmmU0rmSZiEsXPVSn0SlN73jJpENv2FPlmN4=; b=higXkTF0ndmccJWwG4oN00S0Uev6O8nLwHiQBzXo7M5r1duHGCkvdojk5dyQHmVbb+ Q0qYRssqv6sLYdpZNP6q8pXN2hJVgj7GVsmZUR0Nt2Koo7VvN7QJJl377CNdFQ2ufj0u aZbGB4MA9zCRrmaZOnSK90hNFaZB3iLaFCBimfJiedV9HjRkr+eQuNmMYcC5XG4bx8O8 Q/cUGsrcLOBveRy9+GfEMtH+0u1BnjAj4wto7wX8WUBoAzRQIcxXCqGkxeXGmQuv/mtB wHenFEIpsfiVflnEl7KmxgGyzNhBVzWCEl58PwuvsTE1fVff92fhkezyutTGx+1Y6ClU rTSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=kSfrk1ixmmU0rmSZiEsXPVSn0SlN73jJpENv2FPlmN4=; b=a/aYrste0k9BfOashVdxELexX7ljbXy2dQGYpnF5A15HaRPTq0IYjTQ24fJ74g+6u8 TIdgMMqdDX6DvpAry8L5O3cMci30Z0vwATWlzoruzcPmHmyjQNqOEWrVQC3prWfF0Mor broGcFRcfqUulRxiH1a1YytVRIYp6EKFYkzXSKfNWaL1lVASXBJpL0BiNxY4D0HpyT4s fpD9qvRqwFwU/+3KBBllc1MP5752UVUXgnHB5jX4pUFm9zOMgrReQHmq9hgaWYAN+ZtV 2I9u8WKAuSir9VuAc1eUv8iFHKLfEdr0INUnoX7pJxO+0mftqOKPHn+oeQcBw5vOUsBR rJDA== X-Gm-Message-State: APt69E2acu4DvEmTh0UKTAmnNdTvxz8pLFB61O5NNB90dgFBAI6oWep8 ke9baRmmJt9daXeEQyt92GJwEQ== X-Google-Smtp-Source: ADUXVKKvzzow+juENix90m6frkbrXcr3k9+c3GCK1ygQVjh7xW+gc6RjCXT1iqPOzFeFQtV8ppQHJg== X-Received: by 2002:a2e:575c:: with SMTP id r28-v6mr941335ljd.51.1528364615350; Thu, 07 Jun 2018 02:43:35 -0700 (PDT) Received: from mkPC.semihalf.local (31-172-191-173.noc.fibertech.net.pl. [31.172.191.173]) by smtp.gmail.com with ESMTPSA id p28-v6sm3612368lfh.24.2018.06.07.02.43.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Jun 2018 02:43:34 -0700 (PDT) From: Michal Krawczyk To: Marcin Wojtas , Michal Krawczyk , Guy Tzalik , Evgeny Schemeilin , Anatoly Burakov Cc: dev@dpdk.org, matua@amazon.com Date: Thu, 7 Jun 2018 11:43:00 +0200 Message-Id: <20180607094322.14312-5-mk@semihalf.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180607094322.14312-1-mk@semihalf.com> References: <20180607094322.14312-1-mk@semihalf.com> Subject: [dpdk-dev] [PATCH v3 05/27] net/ena: add stop and uninit routines X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Jun 2018 09:43:36 -0000 Lack of uninit routine could lead to memory leak. Stop was added to fulfill allowed PMD operations. Checks for the PMD states in the start and configure routine were removed, as the upper layer is already checking for them. The interrupt setup was moved from start to init function. Signed-off-by: Michal Krawczyk --- drivers/net/ena/ena_ethdev.c | 95 +++++++++++++++++++++++++------------------- drivers/net/ena/ena_ethdev.h | 3 +- 2 files changed, 56 insertions(+), 42 deletions(-) diff --git a/drivers/net/ena/ena_ethdev.c b/drivers/net/ena/ena_ethdev.c index 515d17fee..4ca19c57c 100644 --- a/drivers/net/ena/ena_ethdev.c +++ b/drivers/net/ena/ena_ethdev.c @@ -223,6 +223,7 @@ static int ena_populate_rx_queue(struct ena_ring *rxq, unsigned int count); static void ena_init_rings(struct ena_adapter *adapter); static int ena_mtu_set(struct rte_eth_dev *dev, uint16_t mtu); static int ena_start(struct rte_eth_dev *dev); +static void ena_stop(struct rte_eth_dev *dev); static void ena_close(struct rte_eth_dev *dev); static int ena_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats); static void ena_rx_queue_release_all(struct rte_eth_dev *dev); @@ -254,6 +255,7 @@ static const struct eth_dev_ops ena_dev_ops = { .rx_queue_setup = ena_rx_queue_setup, .tx_queue_setup = ena_tx_queue_setup, .dev_start = ena_start, + .dev_stop = ena_stop, .link_update = ena_link_update, .stats_get = ena_stats_get, .mtu_set = ena_mtu_set, @@ -460,15 +462,9 @@ static void ena_close(struct rte_eth_dev *dev) { struct ena_adapter *adapter = (struct ena_adapter *)(dev->data->dev_private); - struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev); - struct rte_intr_handle *intr_handle = &pci_dev->intr_handle; - - adapter->state = ENA_ADAPTER_STATE_STOPPED; - rte_intr_disable(intr_handle); - rte_intr_callback_unregister(intr_handle, - ena_interrupt_handler_rte, - adapter); + ena_stop(dev); + adapter->state = ENA_ADAPTER_STATE_CLOSED; ena_rx_queue_release_all(dev); ena_tx_queue_release_all(dev); @@ -916,16 +912,8 @@ static int ena_start(struct rte_eth_dev *dev) { struct ena_adapter *adapter = (struct ena_adapter *)(dev->data->dev_private); - struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev); - struct rte_intr_handle *intr_handle = &pci_dev->intr_handle; int rc = 0; - if (!(adapter->state == ENA_ADAPTER_STATE_CONFIG || - adapter->state == ENA_ADAPTER_STATE_STOPPED)) { - PMD_INIT_LOG(ERR, "API violation"); - return -1; - } - rc = ena_check_valid_conf(adapter); if (rc) return rc; @@ -947,16 +935,19 @@ static int ena_start(struct rte_eth_dev *dev) ena_stats_restart(dev); - rte_intr_callback_register(intr_handle, - ena_interrupt_handler_rte, - adapter); - rte_intr_enable(intr_handle); - adapter->state = ENA_ADAPTER_STATE_RUNNING; return 0; } +static void ena_stop(struct rte_eth_dev *dev) +{ + struct ena_adapter *adapter = + (struct ena_adapter *)(dev->data->dev_private); + + adapter->state = ENA_ADAPTER_STATE_STOPPED; +} + static int ena_queue_restart(struct ena_ring *ring) { int rc, bufs_num; @@ -1317,6 +1308,7 @@ static void ena_interrupt_handler_rte(__rte_unused void *cb_arg) static int eth_ena_dev_init(struct rte_eth_dev *eth_dev) { struct rte_pci_device *pci_dev; + struct rte_intr_handle *intr_handle; struct ena_adapter *adapter = (struct ena_adapter *)(eth_dev->data->dev_private); struct ena_com_dev *ena_dev = &adapter->ena_dev; @@ -1347,6 +1339,8 @@ static int eth_ena_dev_init(struct rte_eth_dev *eth_dev) pci_dev->addr.devid, pci_dev->addr.function); + intr_handle = &pci_dev->intr_handle; + adapter->regs = pci_dev->mem_resource[ENA_REGS_BAR].addr; adapter->dev_mem_base = pci_dev->mem_resource[ENA_MEM_BAR].addr; @@ -1406,36 +1400,55 @@ static int eth_ena_dev_init(struct rte_eth_dev *eth_dev) return -ENOMEM; } + rte_intr_callback_register(intr_handle, + ena_interrupt_handler_rte, + adapter); + rte_intr_enable(intr_handle); + ena_com_set_admin_polling_mode(ena_dev, false); + adapters_found++; adapter->state = ENA_ADAPTER_STATE_INIT; return 0; } +static int eth_ena_dev_uninit(struct rte_eth_dev *eth_dev) +{ + struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev); + struct rte_intr_handle *intr_handle = &pci_dev->intr_handle; + struct ena_adapter *adapter = + (struct ena_adapter *)(eth_dev->data->dev_private); + + if (rte_eal_process_type() != RTE_PROC_PRIMARY) + return -EPERM; + + if (adapter->state != ENA_ADAPTER_STATE_CLOSED) + ena_close(eth_dev); + + eth_dev->dev_ops = NULL; + eth_dev->rx_pkt_burst = NULL; + eth_dev->tx_pkt_burst = NULL; + eth_dev->tx_pkt_prepare = NULL; + + rte_free(adapter->drv_stats); + adapter->drv_stats = NULL; + + rte_intr_disable(intr_handle); + rte_intr_callback_unregister(intr_handle, + ena_interrupt_handler_rte, + adapter); + + adapter->state = ENA_ADAPTER_STATE_FREE; + + return 0; +} + static int ena_dev_configure(struct rte_eth_dev *dev) { struct ena_adapter *adapter = (struct ena_adapter *)(dev->data->dev_private); - if (!(adapter->state == ENA_ADAPTER_STATE_INIT || - adapter->state == ENA_ADAPTER_STATE_STOPPED)) { - PMD_INIT_LOG(ERR, "Illegal adapter state: %d", - adapter->state); - return -1; - } - - switch (adapter->state) { - case ENA_ADAPTER_STATE_INIT: - case ENA_ADAPTER_STATE_STOPPED: - adapter->state = ENA_ADAPTER_STATE_CONFIG; - break; - case ENA_ADAPTER_STATE_CONFIG: - RTE_LOG(WARNING, PMD, - "Ivalid driver state while trying to configure device\n"); - break; - default: - break; - } + adapter->state = ENA_ADAPTER_STATE_CONFIG; adapter->tx_selected_offloads = dev->data->dev_conf.txmode.offloads; adapter->rx_selected_offloads = dev->data->dev_conf.rxmode.offloads; @@ -1838,7 +1851,7 @@ static int eth_ena_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, static int eth_ena_pci_remove(struct rte_pci_device *pci_dev) { - return rte_eth_dev_pci_generic_remove(pci_dev, NULL); + return rte_eth_dev_pci_generic_remove(pci_dev, eth_ena_dev_uninit); } static struct rte_pci_driver rte_ena_pmd = { diff --git a/drivers/net/ena/ena_ethdev.h b/drivers/net/ena/ena_ethdev.h index 394d05e02..79fb14aeb 100644 --- a/drivers/net/ena/ena_ethdev.h +++ b/drivers/net/ena/ena_ethdev.h @@ -97,9 +97,10 @@ struct ena_ring { enum ena_adapter_state { ENA_ADAPTER_STATE_FREE = 0, ENA_ADAPTER_STATE_INIT = 1, - ENA_ADAPTER_STATE_RUNNING = 2, + ENA_ADAPTER_STATE_RUNNING = 2, ENA_ADAPTER_STATE_STOPPED = 3, ENA_ADAPTER_STATE_CONFIG = 4, + ENA_ADAPTER_STATE_CLOSED = 5, }; struct ena_driver_stats { -- 2.14.1