net/ice/base: resend some AQ commands when EBUSY
[dpdk.git] / drivers / net / ice / ice_dcf_ethdev.c
index d0219a7..b0b2ecb 100644 (file)
@@ -230,7 +230,7 @@ ice_dcf_config_rx_queues_irqs(struct rte_eth_dev *dev,
 static int
 alloc_rxq_mbufs(struct ice_rx_queue *rxq)
 {
-       volatile union ice_32b_rx_flex_desc *rxd;
+       volatile union ice_rx_flex_desc *rxd;
        struct rte_mbuf *mbuf = NULL;
        uint64_t dma_addr;
        uint16_t i;
@@ -254,8 +254,10 @@ alloc_rxq_mbufs(struct ice_rx_queue *rxq)
                rxd = &rxq->rx_ring[i];
                rxd->read.pkt_addr = dma_addr;
                rxd->read.hdr_addr = 0;
+#ifndef RTE_LIBRTE_ICE_16BYTE_RX_DESC
                rxd->read.rsvd1 = 0;
                rxd->read.rsvd2 = 0;
+#endif
 
                rxq->sw_ring[i].mbuf = (void *)mbuf;
        }
@@ -544,6 +546,12 @@ ice_dcf_dev_start(struct rte_eth_dev *dev)
                return ret;
        }
 
+       ret = ice_dcf_add_del_all_mac_addr(hw, true);
+       if (ret) {
+               PMD_DRV_LOG(ERR, "Failed to add mac addr");
+               return ret;
+       }
+
        dev->data->dev_link.link_status = ETH_LINK_UP;
 
        return 0;
@@ -581,7 +589,7 @@ ice_dcf_stop_queues(struct rte_eth_dev *dev)
        }
 }
 
-static void
+static int
 ice_dcf_dev_stop(struct rte_eth_dev *dev)
 {
        struct ice_dcf_adapter *dcf_ad = dev->data->dev_private;
@@ -590,7 +598,7 @@ ice_dcf_dev_stop(struct rte_eth_dev *dev)
 
        if (ad->pf.adapter_stopped == 1) {
                PMD_DRV_LOG(DEBUG, "Port is already stopped");
-               return;
+               return 0;
        }
 
        ice_dcf_stop_queues(dev);
@@ -601,8 +609,11 @@ ice_dcf_dev_stop(struct rte_eth_dev *dev)
                intr_handle->intr_vec = NULL;
        }
 
+       ice_dcf_add_del_all_mac_addr(&dcf_ad->real_hw, false);
        dev->data->dev_link.link_status = ETH_LINK_DOWN;
        ad->pf.adapter_stopped = 1;
+
+       return 0;
 }
 
 static int
@@ -697,19 +708,6 @@ ice_dcf_dev_info_get(struct rte_eth_dev *dev,
        return 0;
 }
 
-static int
-ice_dcf_stats_get(__rte_unused struct rte_eth_dev *dev,
-                 __rte_unused struct rte_eth_stats *igb_stats)
-{
-       return 0;
-}
-
-static int
-ice_dcf_stats_reset(__rte_unused struct rte_eth_dev *dev)
-{
-       return 0;
-}
-
 static int
 ice_dcf_dev_promiscuous_enable(__rte_unused struct rte_eth_dev *dev)
 {
@@ -762,20 +760,107 @@ ice_dcf_dev_filter_ctrl(struct rte_eth_dev *dev,
        return ret;
 }
 
+#define ICE_DCF_32_BIT_WIDTH (CHAR_BIT * 4)
+#define ICE_DCF_48_BIT_WIDTH (CHAR_BIT * 6)
+#define ICE_DCF_48_BIT_MASK  RTE_LEN2MASK(ICE_DCF_48_BIT_WIDTH, uint64_t)
+
+static void
+ice_dcf_stat_update_48(uint64_t *offset, uint64_t *stat)
+{
+       if (*stat >= *offset)
+               *stat = *stat - *offset;
+       else
+               *stat = (uint64_t)((*stat +
+                       ((uint64_t)1 << ICE_DCF_48_BIT_WIDTH)) - *offset);
+
+       *stat &= ICE_DCF_48_BIT_MASK;
+}
+
+static void
+ice_dcf_stat_update_32(uint64_t *offset, uint64_t *stat)
+{
+       if (*stat >= *offset)
+               *stat = (uint64_t)(*stat - *offset);
+       else
+               *stat = (uint64_t)((*stat +
+                       ((uint64_t)1 << ICE_DCF_32_BIT_WIDTH)) - *offset);
+}
+
 static void
+ice_dcf_update_stats(struct virtchnl_eth_stats *oes,
+                    struct virtchnl_eth_stats *nes)
+{
+       ice_dcf_stat_update_48(&oes->rx_bytes, &nes->rx_bytes);
+       ice_dcf_stat_update_48(&oes->rx_unicast, &nes->rx_unicast);
+       ice_dcf_stat_update_48(&oes->rx_multicast, &nes->rx_multicast);
+       ice_dcf_stat_update_48(&oes->rx_broadcast, &nes->rx_broadcast);
+       ice_dcf_stat_update_32(&oes->rx_discards, &nes->rx_discards);
+       ice_dcf_stat_update_48(&oes->tx_bytes, &nes->tx_bytes);
+       ice_dcf_stat_update_48(&oes->tx_unicast, &nes->tx_unicast);
+       ice_dcf_stat_update_48(&oes->tx_multicast, &nes->tx_multicast);
+       ice_dcf_stat_update_48(&oes->tx_broadcast, &nes->tx_broadcast);
+       ice_dcf_stat_update_32(&oes->tx_errors, &nes->tx_errors);
+       ice_dcf_stat_update_32(&oes->tx_discards, &nes->tx_discards);
+}
+
+
+static int
+ice_dcf_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
+{
+       struct ice_dcf_adapter *ad = dev->data->dev_private;
+       struct ice_dcf_hw *hw = &ad->real_hw;
+       struct virtchnl_eth_stats pstats;
+       int ret;
+
+       ret = ice_dcf_query_stats(hw, &pstats);
+       if (ret == 0) {
+               ice_dcf_update_stats(&hw->eth_stats_offset, &pstats);
+               stats->ipackets = pstats.rx_unicast + pstats.rx_multicast +
+                               pstats.rx_broadcast - pstats.rx_discards;
+               stats->opackets = pstats.tx_broadcast + pstats.tx_multicast +
+                                               pstats.tx_unicast;
+               stats->imissed = pstats.rx_discards;
+               stats->oerrors = pstats.tx_errors + pstats.tx_discards;
+               stats->ibytes = pstats.rx_bytes;
+               stats->ibytes -= stats->ipackets * RTE_ETHER_CRC_LEN;
+               stats->obytes = pstats.tx_bytes;
+       } else {
+               PMD_DRV_LOG(ERR, "Get statistics failed");
+       }
+       return ret;
+}
+
+static int
+ice_dcf_stats_reset(struct rte_eth_dev *dev)
+{
+       struct ice_dcf_adapter *ad = dev->data->dev_private;
+       struct ice_dcf_hw *hw = &ad->real_hw;
+       struct virtchnl_eth_stats pstats;
+       int ret;
+
+       /* read stat values to clear hardware registers */
+       ret = ice_dcf_query_stats(hw, &pstats);
+       if (ret != 0)
+               return ret;
+
+       /* set stats offset base on current values */
+       hw->eth_stats_offset = pstats;
+
+       return 0;
+}
+
+static int
 ice_dcf_dev_close(struct rte_eth_dev *dev)
 {
        struct ice_dcf_adapter *adapter = dev->data->dev_private;
 
        if (rte_eal_process_type() != RTE_PROC_PRIMARY)
-               return;
-
-       dev->dev_ops = NULL;
-       dev->rx_pkt_burst = NULL;
-       dev->tx_pkt_burst = NULL;
+               return 0;
 
        ice_dcf_uninit_parent_adapter(dev);
        ice_dcf_uninit_hw(dev, &adapter->real_hw);
+
+       return 0;
 }
 
 static int
@@ -821,7 +906,7 @@ ice_dcf_dev_init(struct rte_eth_dev *eth_dev)
        if (rte_eal_process_type() != RTE_PROC_PRIMARY)
                return 0;
 
-       eth_dev->data->dev_flags |= RTE_ETH_DEV_CLOSE_REMOVE;
+       eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
 
        adapter->real_hw.vc_event_msg_cb = ice_dcf_handle_pf_event_msg;
        if (ice_dcf_init_hw(eth_dev, &adapter->real_hw) != 0) {