net/cnxk: add SoC specific PTP timestamp read
[dpdk.git] / drivers / net / cnxk / cn9k_ethdev.c
index 01e3850..6b049b2 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright(C) 2021 Marvell.
  */
 #include "cn9k_ethdev.h"
-#include "cn9k_rte_flow.h"
+#include "cn9k_flow.h"
 #include "cn9k_rx.h"
 #include "cn9k_tx.h"
 
@@ -39,6 +39,9 @@ nix_rx_offload_flags(struct rte_eth_dev *eth_dev)
        if (dev->rx_offloads & RTE_ETH_RX_OFFLOAD_SECURITY)
                flags |= NIX_RX_OFFLOAD_SECURITY_F;
 
+       if (dev->rx_mark_update)
+               flags |= NIX_RX_OFFLOAD_MARK_UPDATE_F;
+
        return flags;
 }
 
@@ -447,6 +450,46 @@ cn9k_nix_dev_start(struct rte_eth_dev *eth_dev)
        return 0;
 }
 
+static int
+cn9k_nix_timesync_read_tx_timestamp(struct rte_eth_dev *eth_dev,
+                                   struct timespec *timestamp)
+{
+       struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+       struct cnxk_timesync_info *tstamp = &dev->tstamp;
+       uint64_t ns;
+
+       if (*tstamp->tx_tstamp == 0)
+               return -EINVAL;
+
+       ns = rte_timecounter_update(&dev->tx_tstamp_tc, *tstamp->tx_tstamp);
+       *timestamp = rte_ns_to_timespec(ns);
+       *tstamp->tx_tstamp = 0;
+       rte_wmb();
+
+       return 0;
+}
+
+static int
+cn9k_nix_rx_metadata_negotiate(struct rte_eth_dev *eth_dev, uint64_t *features)
+{
+       struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+
+       *features &=
+               (RTE_ETH_RX_METADATA_USER_FLAG | RTE_ETH_RX_METADATA_USER_MARK);
+
+       if (*features) {
+               dev->rx_offload_flags |= NIX_RX_OFFLOAD_MARK_UPDATE_F;
+               dev->rx_mark_update = true;
+       } else {
+               dev->rx_offload_flags &= ~NIX_RX_OFFLOAD_MARK_UPDATE_F;
+               dev->rx_mark_update = false;
+       }
+
+       cn9k_eth_set_rx_function(eth_dev);
+
+       return 0;
+}
+
 /* Update platform specific eth dev ops */
 static void
 nix_eth_dev_ops_override(void)
@@ -467,6 +510,9 @@ nix_eth_dev_ops_override(void)
        cnxk_eth_dev_ops.timesync_enable = cn9k_nix_timesync_enable;
        cnxk_eth_dev_ops.timesync_disable = cn9k_nix_timesync_disable;
        cnxk_eth_dev_ops.mtr_ops_get = NULL;
+       cnxk_eth_dev_ops.rx_metadata_negotiate = cn9k_nix_rx_metadata_negotiate;
+       cnxk_eth_dev_ops.timesync_read_tx_timestamp =
+               cn9k_nix_timesync_read_tx_timestamp;
 }
 
 static void