net/axgbe: support device reset
authorSelwin Sebastian <selwin.sebastian@amd.com>
Thu, 19 Nov 2020 13:21:58 +0000 (18:51 +0530)
committerFerruh Yigit <ferruh.yigit@intel.com>
Fri, 8 Jan 2021 15:03:04 +0000 (16:03 +0100)
Added support for device reset

Signed-off-by: Selwin Sebastian <selwin.sebastian@amd.com>
Acked-by: Amaranath Somalapuram <asomalap@amd.com>
drivers/net/axgbe/axgbe_ethdev.c

index cfe6aba..4c6366d 100644 (file)
@@ -16,6 +16,7 @@ static int  axgbe_dev_start(struct rte_eth_dev *dev);
 static int  axgbe_dev_stop(struct rte_eth_dev *dev);
 static void axgbe_dev_interrupt_handler(void *param);
 static int axgbe_dev_close(struct rte_eth_dev *dev);
+static int axgbe_dev_reset(struct rte_eth_dev *dev);
 static int axgbe_dev_promiscuous_enable(struct rte_eth_dev *dev);
 static int axgbe_dev_promiscuous_disable(struct rte_eth_dev *dev);
 static int axgbe_dev_allmulticast_enable(struct rte_eth_dev *dev);
@@ -215,6 +216,7 @@ static const struct eth_dev_ops axgbe_eth_dev_ops = {
        .dev_start            = axgbe_dev_start,
        .dev_stop             = axgbe_dev_stop,
        .dev_close            = axgbe_dev_close,
+       .dev_reset            = axgbe_dev_reset,
        .promiscuous_enable   = axgbe_dev_promiscuous_enable,
        .promiscuous_disable  = axgbe_dev_promiscuous_disable,
        .allmulticast_enable  = axgbe_dev_allmulticast_enable,
@@ -618,6 +620,20 @@ axgbe_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
        return 0;
 }
 
+static int
+axgbe_dev_reset(struct rte_eth_dev *dev)
+{
+       int ret = 0;
+
+       ret = axgbe_dev_close(dev);
+       if (ret)
+               return ret;
+
+       ret = eth_axgbe_dev_init(dev);
+
+       return ret;
+}
+
 static void
 axgbe_dev_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
 {
@@ -1104,22 +1120,33 @@ axgbe_dev_stats_get(struct rte_eth_dev *dev,
 
        for (i = 0; i < dev->data->nb_rx_queues; i++) {
                rxq = dev->data->rx_queues[i];
-               stats->q_ipackets[i] = rxq->pkts;
-               stats->ipackets += rxq->pkts;
-               stats->q_ibytes[i] = rxq->bytes;
-               stats->ibytes += rxq->bytes;
-               stats->rx_nombuf += rxq->rx_mbuf_alloc_failed;
-               stats->q_errors[i] = rxq->errors + rxq->rx_mbuf_alloc_failed;
-               stats->ierrors += rxq->errors;
+               if (rxq) {
+                       stats->q_ipackets[i] = rxq->pkts;
+                       stats->ipackets += rxq->pkts;
+                       stats->q_ibytes[i] = rxq->bytes;
+                       stats->ibytes += rxq->bytes;
+                       stats->rx_nombuf += rxq->rx_mbuf_alloc_failed;
+                       stats->q_errors[i] = rxq->errors
+                               + rxq->rx_mbuf_alloc_failed;
+                       stats->ierrors += rxq->errors;
+               } else {
+                       PMD_DRV_LOG(DEBUG, "Rx queue not setup for port %d\n",
+                                       dev->data->port_id);
+               }
        }
 
        for (i = 0; i < dev->data->nb_tx_queues; i++) {
                txq = dev->data->tx_queues[i];
-               stats->q_opackets[i] = txq->pkts;
-               stats->opackets += txq->pkts;
-               stats->q_obytes[i] = txq->bytes;
-               stats->obytes += txq->bytes;
-               stats->oerrors += txq->errors;
+               if (txq) {
+                       stats->q_opackets[i] = txq->pkts;
+                       stats->opackets += txq->pkts;
+                       stats->q_obytes[i] = txq->bytes;
+                       stats->obytes += txq->bytes;
+                       stats->oerrors += txq->errors;
+               } else {
+                       PMD_DRV_LOG(DEBUG, "Tx queue not setup for port %d\n",
+                                       dev->data->port_id);
+               }
        }
 
        return 0;
@@ -1134,16 +1161,26 @@ axgbe_dev_stats_reset(struct rte_eth_dev *dev)
 
        for (i = 0; i < dev->data->nb_rx_queues; i++) {
                rxq = dev->data->rx_queues[i];
-               rxq->pkts = 0;
-               rxq->bytes = 0;
-               rxq->errors = 0;
-               rxq->rx_mbuf_alloc_failed = 0;
+               if (rxq) {
+                       rxq->pkts = 0;
+                       rxq->bytes = 0;
+                       rxq->errors = 0;
+                       rxq->rx_mbuf_alloc_failed = 0;
+               } else {
+                       PMD_DRV_LOG(DEBUG, "Rx queue not setup for port %d\n",
+                                       dev->data->port_id);
+               }
        }
        for (i = 0; i < dev->data->nb_tx_queues; i++) {
                txq = dev->data->tx_queues[i];
-               txq->pkts = 0;
-               txq->bytes = 0;
-               txq->errors = 0;
+               if (txq) {
+                       txq->pkts = 0;
+                       txq->bytes = 0;
+                       txq->errors = 0;
+               } else {
+                       PMD_DRV_LOG(DEBUG, "Tx queue not setup for port %d\n",
+                                       dev->data->port_id);
+               }
        }
 
        return 0;