]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
igc: add support for frame preemption verification
authorFaizal Rahim <faizal.abdul.rahim@linux.intel.com>
Tue, 18 Mar 2025 03:07:38 +0000 (23:07 -0400)
committerTony Nguyen <anthony.l.nguyen@intel.com>
Fri, 18 Apr 2025 16:16:58 +0000 (09:16 -0700)
This patch implements the "ethtool --set-mm" callback to trigger the
frame preemption verification handshake.

Uses the MAC Merge Software Verification (mmsv) mechanism in ethtool
to perform the verification handshake for igc.
The structure fpe.mmsv is set by mmsv in ethtool and should remain
read-only for the driver.

Other mmsv callbacks:
a) configure_tx() -> not used yet at this point
   - igc lacks registers to configure FPE in the transmit direction, so
     this API is not utilized for now. When igc supports preemptible queue,
     driver will use this API to manage its configuration.

b) configure_pmac() -> not used
   - this callback dynamically controls pmac_enabled at runtime. For
     example, mmsv calls configure_pmac() and disables pmac_enabled when
     the link partner goes down, even if the user previously enabled it.
     The intention is to save power but it is not feasible in igc
     because it causes an endless adapter reset loop:

   1) Board A and Board B complete the verification handshake. Tx mode
      register for both boards are in TSN mode.
   2) Board B link goes down.

   On Board A:
   3) mmsv calls configure_pmac() with pmac_enabled = false.
   4) configure_pmac() in igc updates a new field based on pmac_enabled.
      Driver uses this field in igc_tsn_new_flags() to indicate that the
      user enabled/disabled FPE.
   5) configure_pmac() in igc calls igc_tsn_offload_apply() to check
      whether an adapter reset is needed. Calls existing logic in
      igc_tsn_will_tx_mode_change() and igc_tsn_new_flags().
   6) Since pmac_enabled is now disabled and no other TSN feature is
      active, igc_tsn_will_tx_mode_change() evaluates to true because Tx
      mode will switch from TSN to Legacy.
   7) Driver resets the adapter.
   8) Registers are set, and Tx mode switches to Legacy.
   9) When link partner is up, steps 3-8 repeat, but this time with
      pmac_enabled = true, reactivating TSN.
      igc_tsn_will_tx_mode_change() evaluates to true again, since Tx
      mode will switch from Legacy to TSN.
  10) Driver resets the adapter.
  11) Adapter reset completes, registers are set, and Tx mode switches to
      TSN.

  On Board B:
  12) Adapter reset on Board A at step 10 causes it to detect its link
      partner as down.
  13) Repeats steps 3-8.
  14) Once reset adapter on Board A is completed at step 11, it detects
      its link partner as up.
  15) Repeats steps 9-11.

   - this cycle repeats indefinitely. To avoid this issue, igc only uses
     mmsv.pmac_enabled to track whether FPE is enabled or disabled.

Co-developed-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
Co-developed-by: Choong Yong Liang <yong.liang.choong@linux.intel.com>
Signed-off-by: Choong Yong Liang <yong.liang.choong@linux.intel.com>
Co-developed-by: Chwee-Lin Choong <chwee.lin.choong@intel.com>
Signed-off-by: Chwee-Lin Choong <chwee.lin.choong@intel.com>
Reviewed-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: Faizal Rahim <faizal.abdul.rahim@linux.intel.com>
Tested-by: Mor Bar-Gabay <morx.bar.gabay@intel.com>
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
drivers/net/ethernet/intel/Kconfig
drivers/net/ethernet/intel/igc/igc.h
drivers/net/ethernet/intel/igc/igc_base.h
drivers/net/ethernet/intel/igc/igc_defines.h
drivers/net/ethernet/intel/igc/igc_ethtool.c
drivers/net/ethernet/intel/igc/igc_main.c
drivers/net/ethernet/intel/igc/igc_tsn.c
drivers/net/ethernet/intel/igc/igc_tsn.h

index b2adb40a5921004ee14f48897c197e1dfd44d168..5a331c1c76cb812d50d4bba671f2f7aa6fa2aef6 100644 (file)
@@ -369,6 +369,7 @@ config IGC
        default n
        depends on PCI
        depends on PTP_1588_CLOCK_OPTIONAL
+       depends on ETHTOOL_NETLINK
        help
          This driver supports Intel(R) Ethernet Controller I225-LM/I225-V
          family of adapters.
index a489e14d8dc479bb6e38a48f45f5c3a58d6c423f..cce537d7dbd34a07de60769e55605f4b93c7c357 100644 (file)
@@ -40,6 +40,10 @@ void igc_ethtool_set_ops(struct net_device *);
 
 #define IGC_MAX_TX_TSTAMP_REGS         4
 
+struct igc_fpe_t {
+       struct ethtool_mmsv mmsv;
+};
+
 enum igc_mac_filter_type {
        IGC_MAC_FILTER_TYPE_DST = 0,
        IGC_MAC_FILTER_TYPE_SRC
@@ -333,6 +337,8 @@ struct igc_adapter {
                struct timespec64 period;
        } perout[IGC_N_PEROUT];
 
+       struct igc_fpe_t fpe;
+
        /* LEDs */
        struct mutex led_mutex;
        struct igc_led_classdev *leds;
@@ -388,10 +394,11 @@ extern char igc_driver_name[];
 #define IGC_FLAG_TSN_QBV_ENABLED       BIT(17)
 #define IGC_FLAG_TSN_QAV_ENABLED       BIT(18)
 #define IGC_FLAG_TSN_LEGACY_ENABLED    BIT(19)
+#define IGC_FLAG_TSN_PREEMPT_ENABLED   BIT(20)
 
 #define IGC_FLAG_TSN_ANY_ENABLED                               \
        (IGC_FLAG_TSN_QBV_ENABLED | IGC_FLAG_TSN_QAV_ENABLED |  \
-        IGC_FLAG_TSN_LEGACY_ENABLED)
+        IGC_FLAG_TSN_LEGACY_ENABLED | IGC_FLAG_TSN_PREEMPT_ENABLED)
 
 #define IGC_FLAG_RSS_FIELD_IPV4_UDP    BIT(6)
 #define IGC_FLAG_RSS_FIELD_IPV6_UDP    BIT(7)
@@ -736,7 +743,10 @@ struct igc_nfc_rule *igc_get_nfc_rule(struct igc_adapter *adapter,
                                      u32 location);
 int igc_add_nfc_rule(struct igc_adapter *adapter, struct igc_nfc_rule *rule);
 void igc_del_nfc_rule(struct igc_adapter *adapter, struct igc_nfc_rule *rule);
+void igc_disable_empty_addr_recv(struct igc_adapter *adapter);
+int igc_enable_empty_addr_recv(struct igc_adapter *adapter);
 struct igc_ring *igc_get_tx_ring(struct igc_adapter *adapter, int cpu);
+void igc_flush_tx_descriptors(struct igc_ring *ring);
 void igc_ptp_init(struct igc_adapter *adapter);
 void igc_ptp_reset(struct igc_adapter *adapter);
 void igc_ptp_suspend(struct igc_adapter *adapter);
index bf8cdfbba9ffb2b04e980d320963d567b4a3f218..6320eabb72fe0d8334992e493b4c7dd1e81d5e64 100644 (file)
@@ -49,6 +49,7 @@ struct igc_adv_tx_context_desc {
 #define IGC_ADVTXD_DCMD_DEXT   0x20000000 /* Descriptor extension (1=Adv) */
 #define IGC_ADVTXD_DCMD_VLE    0x40000000 /* VLAN pkt enable */
 #define IGC_ADVTXD_DCMD_TSE    0x80000000 /* TCP Seg enable */
+#define IGC_ADVTXD_PAYLEN_MASK 0XFFFFC000 /* Adv desc PAYLEN mask */
 #define IGC_ADVTXD_PAYLEN_SHIFT        14 /* Adv desc PAYLEN shift */
 
 #define IGC_RAR_ENTRIES                16
index 86abd3bafb37cd923916ef5b195856cc728d86da..66061b0d6cbf4e709114242876e5e9ea40f5bea8 100644 (file)
 #define IGC_TXD_DTYP_C         0x00000000 /* Context Descriptor */
 #define IGC_TXD_POPTS_IXSM     0x01       /* Insert IP checksum */
 #define IGC_TXD_POPTS_TXSM     0x02       /* Insert TCP/UDP checksum */
+#define IGC_TXD_POPTS_SMD_MASK 0x3000     /* Indicates whether it's SMD-V or SMD-R */
+
 #define IGC_TXD_CMD_EOP                0x01000000 /* End of Packet */
 #define IGC_TXD_CMD_IC         0x04000000 /* Insert Checksum */
 #define IGC_TXD_CMD_DEXT       0x20000000 /* Desc extension (0 = legacy) */
 #define IGC_SRRCTL_TIMER0SEL(timer)    (((timer) & 0x3) << 17)
 
 /* Receive Descriptor bit definitions */
+#define IGC_RXD_STAT_SMD_TYPE_V        0x01    /* SMD-V Packet */
+#define IGC_RXD_STAT_SMD_TYPE_R        0x02    /* SMD-R Packet */
 #define IGC_RXD_STAT_EOP       0x02    /* End of Packet */
 #define IGC_RXD_STAT_IXSM      0x04    /* Ignore checksum */
 #define IGC_RXD_STAT_UDPCS     0x10    /* UDP xsum calculated */
 #define IGC_RXDEXT_STATERR_LB  0x00040000
 
 /* Advanced Receive Descriptor bit definitions */
-#define IGC_RXDADV_STAT_TSIP   0x08000 /* timestamp in packet */
+#define IGC_RXDADV_STAT_SMD_TYPE_MASK  0x06000
+#define IGC_RXDADV_STAT_TSIP           0x08000 /* timestamp in packet */
 
 #define IGC_RXDEXT_STATERR_L4E         0x20000000
 #define IGC_RXDEXT_STATERR_IPE         0x40000000
 
 /* Transmit Scheduling */
 #define IGC_TQAVCTRL_TRANSMIT_MODE_TSN 0x00000001
+#define IGC_TQAVCTRL_PREEMPT_ENA       0x00000002
 #define IGC_TQAVCTRL_ENHANCED_QAV      0x00000008
 #define IGC_TQAVCTRL_FUTSCDDIS         0x00000080
 
index 8178386778176f42efa9d67c65f3740ec95c0994..b64d5c6c1d20c58c0e6b603b923eec1a7ce9d963 100644 (file)
@@ -8,6 +8,7 @@
 
 #include "igc.h"
 #include "igc_diag.h"
+#include "igc_tsn.h"
 
 /* forward declaration */
 struct igc_stats {
@@ -1781,6 +1782,25 @@ static int igc_ethtool_set_eee(struct net_device *netdev,
        return 0;
 }
 
+static int igc_ethtool_set_mm(struct net_device *netdev,
+                             struct ethtool_mm_cfg *cmd,
+                             struct netlink_ext_ack *extack)
+{
+       struct igc_adapter *adapter = netdev_priv(netdev);
+       struct igc_fpe_t *fpe = &adapter->fpe;
+
+       if (fpe->mmsv.pmac_enabled != cmd->pmac_enabled) {
+               if (cmd->pmac_enabled)
+                       static_branch_inc(&igc_fpe_enabled);
+               else
+                       static_branch_dec(&igc_fpe_enabled);
+       }
+
+       ethtool_mmsv_set_mm(&fpe->mmsv, cmd);
+
+       return igc_tsn_offload_apply(adapter);
+}
+
 static int igc_ethtool_get_link_ksettings(struct net_device *netdev,
                                          struct ethtool_link_ksettings *cmd)
 {
@@ -2076,6 +2096,7 @@ static const struct ethtool_ops igc_ethtool_ops = {
        .get_link_ksettings     = igc_ethtool_get_link_ksettings,
        .set_link_ksettings     = igc_ethtool_set_link_ksettings,
        .self_test              = igc_ethtool_diag_test,
+       .set_mm                 = igc_ethtool_set_mm,
 };
 
 void igc_ethtool_set_ops(struct net_device *netdev)
index 9d9661632ae79de0f6d7504b808d8a28e386eff5..d160da49b0d28b02a40eab70ad6978b38187505b 100644 (file)
@@ -2548,7 +2548,7 @@ out:
 }
 
 /* This function assumes __netif_tx_lock is held by the caller. */
-static void igc_flush_tx_descriptors(struct igc_ring *ring)
+void igc_flush_tx_descriptors(struct igc_ring *ring)
 {
        /* Once tail pointer is updated, hardware can fetch the descriptors
         * any time so we issue a write membar here to ensure all memory
@@ -2637,6 +2637,14 @@ static int igc_clean_rx_irq(struct igc_q_vector *q_vector, const int budget)
                        size -= IGC_TS_HDR_LEN;
                }
 
+               if (igc_fpe_is_pmac_enabled(adapter) &&
+                   igc_fpe_handle_mpacket(adapter, rx_desc, size, pktbuf)) {
+                       /* Advance the ring next-to-clean */
+                       igc_is_non_eop(rx_ring, rx_desc);
+                       cleaned_count++;
+                       continue;
+               }
+
                if (!skb) {
                        xdp_init_buff(&ctx.xdp, truesize, &rx_ring->xdp_rxq);
                        xdp_prepare_buff(&ctx.xdp, pktbuf - igc_rx_offset(rx_ring),
@@ -3144,6 +3152,11 @@ static bool igc_clean_tx_irq(struct igc_q_vector *q_vector, int napi_budget)
                if (!(eop_desc->wb.status & cpu_to_le32(IGC_TXD_STAT_DD)))
                        break;
 
+               if (igc_fpe_is_pmac_enabled(adapter) &&
+                   igc_fpe_transmitted_smd_v(tx_desc))
+                       ethtool_mmsv_event_handle(&adapter->fpe.mmsv,
+                                                 ETHTOOL_MMSV_LD_SENT_VERIFY_MPACKET);
+
                /* Hold the completions while there's a pending tx hardware
                 * timestamp request from XDP Tx metadata.
                 */
@@ -4035,6 +4048,30 @@ static int igc_uc_unsync(struct net_device *netdev, const unsigned char *addr)
        return 0;
 }
 
+/**
+ * igc_enable_empty_addr_recv - Enable Rx of packets with all-zeroes MAC address
+ * @adapter: Pointer to the igc_adapter structure.
+ *
+ * Frame preemption verification requires that packets with the all-zeroes
+ * MAC address are allowed to be received by the driver. This function adds the
+ * all-zeroes destination address to the list of acceptable addresses.
+ *
+ * Return: 0 on success, negative value otherwise.
+ */
+int igc_enable_empty_addr_recv(struct igc_adapter *adapter)
+{
+       u8 empty[ETH_ALEN] = {};
+
+       return igc_add_mac_filter(adapter, IGC_MAC_FILTER_TYPE_DST, empty, -1);
+}
+
+void igc_disable_empty_addr_recv(struct igc_adapter *adapter)
+{
+       u8 empty[ETH_ALEN] = {};
+
+       igc_del_mac_filter(adapter, IGC_MAC_FILTER_TYPE_DST, empty);
+}
+
 /**
  * igc_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set
  * @netdev: network interface device structure
@@ -5310,6 +5347,9 @@ void igc_down(struct igc_adapter *adapter)
        igc_disable_all_tx_rings_hw(adapter);
        igc_clean_all_tx_rings(adapter);
        igc_clean_all_rx_rings(adapter);
+
+       if (adapter->fpe.mmsv.pmac_enabled)
+               ethtool_mmsv_stop(&adapter->fpe.mmsv);
 }
 
 void igc_reinit_locked(struct igc_adapter *adapter)
@@ -5834,6 +5874,10 @@ static void igc_watchdog_task(struct work_struct *work)
                         */
                        igc_tsn_adjust_txtime_offset(adapter);
 
+                       if (adapter->fpe.mmsv.pmac_enabled)
+                               ethtool_mmsv_link_state_handle(&adapter->fpe.mmsv,
+                                                              true);
+
                        if (adapter->link_speed != SPEED_1000)
                                goto no_wait;
 
@@ -5869,6 +5913,10 @@ no_wait:
                        netdev_info(netdev, "NIC Link is Down\n");
                        netif_carrier_off(netdev);
 
+                       if (adapter->fpe.mmsv.pmac_enabled)
+                               ethtool_mmsv_link_state_handle(&adapter->fpe.mmsv,
+                                                              false);
+
                        /* link state has changed, schedule phy info update */
                        if (!test_bit(__IGC_DOWN, &adapter->state))
                                mod_timer(&adapter->phy_info_timer,
@@ -7192,6 +7240,8 @@ static int igc_probe(struct pci_dev *pdev,
 
        igc_tsn_clear_schedule(adapter);
 
+       igc_fpe_init(adapter);
+
        /* reset the hardware with the new settings */
        igc_reset(adapter);
 
index 2254f255cc3b92d91b3414d70ee1fcefaec53585..a3f32cb94469dab52c4cd22fae2b2694e4cb41aa 100644 (file)
@@ -2,9 +2,135 @@
 /* Copyright (c)  2019 Intel Corporation */
 
 #include "igc.h"
+#include "igc_base.h"
 #include "igc_hw.h"
 #include "igc_tsn.h"
 
+DEFINE_STATIC_KEY_FALSE(igc_fpe_enabled);
+
+static int igc_fpe_init_smd_frame(struct igc_ring *ring,
+                                 struct igc_tx_buffer *buffer,
+                                 struct sk_buff *skb)
+{
+       dma_addr_t dma = dma_map_single(ring->dev, skb->data, skb->len,
+                                       DMA_TO_DEVICE);
+
+       if (dma_mapping_error(ring->dev, dma)) {
+               netdev_err_once(ring->netdev, "Failed to map DMA for TX\n");
+               return -ENOMEM;
+       }
+
+       buffer->skb = skb;
+       buffer->protocol = 0;
+       buffer->bytecount = skb->len;
+       buffer->gso_segs = 1;
+       buffer->time_stamp = jiffies;
+       dma_unmap_len_set(buffer, len, skb->len);
+       dma_unmap_addr_set(buffer, dma, dma);
+
+       return 0;
+}
+
+static int igc_fpe_init_tx_descriptor(struct igc_ring *ring,
+                                     struct sk_buff *skb,
+                                     enum igc_txd_popts_type type)
+{
+       u32 cmd_type, olinfo_status = 0;
+       struct igc_tx_buffer *buffer;
+       union igc_adv_tx_desc *desc;
+       int err;
+
+       if (!igc_desc_unused(ring))
+               return -EBUSY;
+
+       buffer = &ring->tx_buffer_info[ring->next_to_use];
+       err = igc_fpe_init_smd_frame(ring, buffer, skb);
+       if (err)
+               return err;
+
+       cmd_type = IGC_ADVTXD_DTYP_DATA | IGC_ADVTXD_DCMD_DEXT |
+                  IGC_ADVTXD_DCMD_IFCS | IGC_TXD_DCMD |
+                  buffer->bytecount;
+
+       olinfo_status |= FIELD_PREP(IGC_ADVTXD_PAYLEN_MASK, buffer->bytecount);
+
+       switch (type) {
+       case SMD_V:
+       case SMD_R:
+               olinfo_status |= FIELD_PREP(IGC_TXD_POPTS_SMD_MASK, type);
+               break;
+       }
+
+       desc = IGC_TX_DESC(ring, ring->next_to_use);
+       desc->read.cmd_type_len = cpu_to_le32(cmd_type);
+       desc->read.olinfo_status = cpu_to_le32(olinfo_status);
+       desc->read.buffer_addr = cpu_to_le64(dma_unmap_addr(buffer, dma));
+
+       netdev_tx_sent_queue(txring_txq(ring), skb->len);
+
+       buffer->next_to_watch = desc;
+       ring->next_to_use = (ring->next_to_use + 1) % ring->count;
+
+       return 0;
+}
+
+static int igc_fpe_xmit_smd_frame(struct igc_adapter *adapter,
+                                 enum igc_txd_popts_type type)
+{
+       int cpu = smp_processor_id();
+       struct netdev_queue *nq;
+       struct igc_ring *ring;
+       struct sk_buff *skb;
+       int err;
+
+       ring = igc_get_tx_ring(adapter, cpu);
+       nq = txring_txq(ring);
+
+       skb = alloc_skb(SMD_FRAME_SIZE, GFP_ATOMIC);
+       if (!skb)
+               return -ENOMEM;
+
+       skb_put_zero(skb, SMD_FRAME_SIZE);
+
+       __netif_tx_lock(nq, cpu);
+
+       err = igc_fpe_init_tx_descriptor(ring, skb, type);
+       igc_flush_tx_descriptors(ring);
+
+       __netif_tx_unlock(nq);
+
+       return err;
+}
+
+static void igc_fpe_send_mpacket(struct ethtool_mmsv *mmsv,
+                                enum ethtool_mpacket type)
+{
+       struct igc_fpe_t *fpe = container_of(mmsv, struct igc_fpe_t, mmsv);
+       struct igc_adapter *adapter;
+       int err;
+
+       adapter = container_of(fpe, struct igc_adapter, fpe);
+
+       if (type == ETHTOOL_MPACKET_VERIFY) {
+               err = igc_fpe_xmit_smd_frame(adapter, SMD_V);
+               if (err && net_ratelimit())
+                       netdev_err(adapter->netdev, "Error sending SMD-V\n");
+       } else if (type == ETHTOOL_MPACKET_RESPONSE) {
+               err = igc_fpe_xmit_smd_frame(adapter, SMD_R);
+               if (err && net_ratelimit())
+                       netdev_err(adapter->netdev, "Error sending SMD-R frame\n");
+       }
+}
+
+static const struct ethtool_mmsv_ops igc_mmsv_ops = {
+       .send_mpacket = igc_fpe_send_mpacket,
+};
+
+void igc_fpe_init(struct igc_adapter *adapter)
+{
+       ethtool_mmsv_init(&adapter->fpe.mmsv, adapter->netdev, &igc_mmsv_ops);
+}
+
 static bool is_any_launchtime(struct igc_adapter *adapter)
 {
        int i;
@@ -49,6 +175,9 @@ static unsigned int igc_tsn_new_flags(struct igc_adapter *adapter)
        if (adapter->strict_priority_enable)
                new_flags |= IGC_FLAG_TSN_LEGACY_ENABLED;
 
+       if (adapter->fpe.mmsv.pmac_enabled)
+               new_flags |= IGC_FLAG_TSN_PREEMPT_ENABLED;
+
        return new_flags;
 }
 
@@ -169,7 +298,8 @@ static int igc_tsn_disable_offload(struct igc_adapter *adapter)
 
        tqavctrl = rd32(IGC_TQAVCTRL);
        tqavctrl &= ~(IGC_TQAVCTRL_TRANSMIT_MODE_TSN |
-                     IGC_TQAVCTRL_ENHANCED_QAV | IGC_TQAVCTRL_FUTSCDDIS);
+                     IGC_TQAVCTRL_ENHANCED_QAV | IGC_TQAVCTRL_FUTSCDDIS |
+                     IGC_TQAVCTRL_PREEMPT_ENA);
 
        wr32(IGC_TQAVCTRL, tqavctrl);
 
@@ -388,10 +518,14 @@ skip_cbs:
                wr32(IGC_TXQCTL(i), txqctl);
        }
 
-       tqavctrl = rd32(IGC_TQAVCTRL) & ~IGC_TQAVCTRL_FUTSCDDIS;
+       tqavctrl = rd32(IGC_TQAVCTRL) & ~(IGC_TQAVCTRL_FUTSCDDIS |
+                  IGC_TQAVCTRL_PREEMPT_ENA);
 
        tqavctrl |= IGC_TQAVCTRL_TRANSMIT_MODE_TSN | IGC_TQAVCTRL_ENHANCED_QAV;
 
+       if (adapter->fpe.mmsv.pmac_enabled)
+               tqavctrl |= IGC_TQAVCTRL_PREEMPT_ENA;
+
        adapter->qbv_count++;
 
        cycle = adapter->cycle_time;
@@ -452,6 +586,14 @@ int igc_tsn_reset(struct igc_adapter *adapter)
        unsigned int new_flags;
        int err = 0;
 
+       if (adapter->fpe.mmsv.pmac_enabled) {
+               err = igc_enable_empty_addr_recv(adapter);
+               if (err && net_ratelimit())
+                       netdev_err(adapter->netdev, "Error adding empty address to MAC filter\n");
+       } else {
+               igc_disable_empty_addr_recv(adapter);
+       }
+
        new_flags = igc_tsn_new_flags(adapter);
 
        if (!(new_flags & IGC_FLAG_TSN_ANY_ENABLED))
index 98ec845a86bf00935089bd7c5c7a3a7422facf05..bb30d15cec76db3e05e1edbb4e0fc609d1be439e 100644 (file)
@@ -4,9 +4,59 @@
 #ifndef _IGC_TSN_H_
 #define _IGC_TSN_H_
 
+#define SMD_FRAME_SIZE                 60
+
+enum igc_txd_popts_type {
+       SMD_V = 0x01,
+       SMD_R = 0x02,
+};
+
+DECLARE_STATIC_KEY_FALSE(igc_fpe_enabled);
+
+void igc_fpe_init(struct igc_adapter *adapter);
 int igc_tsn_offload_apply(struct igc_adapter *adapter);
 int igc_tsn_reset(struct igc_adapter *adapter);
 void igc_tsn_adjust_txtime_offset(struct igc_adapter *adapter);
 bool igc_tsn_is_taprio_activated_by_user(struct igc_adapter *adapter);
 
+static inline bool igc_fpe_is_pmac_enabled(struct igc_adapter *adapter)
+{
+       return static_branch_unlikely(&igc_fpe_enabled) &&
+              adapter->fpe.mmsv.pmac_enabled;
+}
+
+static inline bool igc_fpe_handle_mpacket(struct igc_adapter *adapter,
+                                         union igc_adv_rx_desc *rx_desc,
+                                         unsigned int size, void *pktbuf)
+{
+       u32 status_error = le32_to_cpu(rx_desc->wb.upper.status_error);
+       int smd;
+
+       smd = FIELD_GET(IGC_RXDADV_STAT_SMD_TYPE_MASK, status_error);
+       if (smd != IGC_RXD_STAT_SMD_TYPE_V && smd != IGC_RXD_STAT_SMD_TYPE_R)
+               return false;
+
+       if (size == SMD_FRAME_SIZE && mem_is_zero(pktbuf, SMD_FRAME_SIZE)) {
+               struct ethtool_mmsv *mmsv = &adapter->fpe.mmsv;
+               enum ethtool_mmsv_event event;
+
+               if (smd == IGC_RXD_STAT_SMD_TYPE_V)
+                       event = ETHTOOL_MMSV_LP_SENT_VERIFY_MPACKET;
+               else
+                       event = ETHTOOL_MMSV_LP_SENT_RESPONSE_MPACKET;
+
+               ethtool_mmsv_event_handle(mmsv, event);
+       }
+
+       return true;
+}
+
+static inline bool igc_fpe_transmitted_smd_v(union igc_adv_tx_desc *tx_desc)
+{
+       u32 olinfo_status = le32_to_cpu(tx_desc->read.olinfo_status);
+       u8 smd = FIELD_GET(IGC_TXD_POPTS_SMD_MASK, olinfo_status);
+
+       return smd == SMD_V;
+}
+
 #endif /* _IGC_BASE_H */