1c4d83
From a1661a140c97a9e8fd90ee00f2de6baa214c9076 Mon Sep 17 00:00:00 2001
1c4d83
From: Daan De Meyer <daan.j.demeyer@gmail.com>
1c4d83
Date: Wed, 18 Aug 2021 13:52:00 +0100
1c4d83
Subject: [PATCH] udev: Add support for configuring nic coalescing settings
1c4d83
1c4d83
These are configured via the corresponding ethtool ioctl.
1c4d83
---
1c4d83
 man/systemd.link.xml                       |  71 +++++++
1c4d83
 src/shared/ethtool-util.c                  | 205 +++++++++++++++++++++
1c4d83
 src/shared/ethtool-util.h                  |  29 +++
1c4d83
 src/udev/net/link-config-gperf.gperf       | 124 ++++++++-----
1c4d83
 src/udev/net/link-config.c                 |   4 +
1c4d83
 src/udev/net/link-config.h                 |   1 +
1c4d83
 test/fuzz/fuzz-link-parser/directives.link |  22 +++
1c4d83
 7 files changed, 405 insertions(+), 51 deletions(-)
1c4d83
1c4d83
diff --git a/man/systemd.link.xml b/man/systemd.link.xml
1c4d83
index dfb02073b2..6d8dcb9af7 100644
1c4d83
--- a/man/systemd.link.xml
1c4d83
+++ b/man/systemd.link.xml
1c4d83
@@ -773,6 +773,77 @@
1c4d83
           accept. An unsigned integer in the range 1…65535. Defaults to unset.</para>
1c4d83
         </listitem>
1c4d83
       </varlistentry>
1c4d83
+      <varlistentry>
1c4d83
+        <term><varname>UseAdaptiveRxCoalesce=</varname></term>
1c4d83
+        <term><varname>UseAdaptiveTxCoalesce=</varname></term>
1c4d83
+        <listitem>
1c4d83
+          <para>Boolean properties that, when set, enable/disable adaptive Rx/Tx coalescing if the hardware
1c4d83
+          supports it. When unset, the kernel's default will be used.</para>
1c4d83
+        </listitem>
1c4d83
+      </varlistentry>
1c4d83
+      <varlistentry>
1c4d83
+        <term><varname>RxCoalesceSec=</varname></term>
1c4d83
+        <term><varname>RxCoalesceIrqSec=</varname></term>
1c4d83
+        <term><varname>RxCoalesceLowSec=</varname></term>
1c4d83
+        <term><varname>RxCoalesceHighSec=</varname></term>
1c4d83
+        <term><varname>TxCoalesceSec=</varname></term>
1c4d83
+        <term><varname>TxCoalesceIrqSec=</varname></term>
1c4d83
+        <term><varname>TxCoalesceLowSec=</varname></term>
1c4d83
+        <term><varname>TxCoalesceHighSec=</varname></term>
1c4d83
+        <listitem>
1c4d83
+          <para>These properties configure the delay before Rx/Tx interrupts are generated after a packet is
1c4d83
+          sent/received. The <literal>Irq</literal> properties come into effect when the host is servicing an
1c4d83
+          IRQ. The <literal>Low</literal> and <literal>High</literal> properties come into effect when the
1c4d83
+          packet rate drops below the low packet rate threshold or exceeds the high packet rate threshold
1c4d83
+          respectively if adaptive Rx/Tx coalescing is enabled. When unset, the kernel's defaults will be
1c4d83
+          used.</para>
1c4d83
+        </listitem>
1c4d83
+      </varlistentry>
1c4d83
+        <varlistentry>
1c4d83
+        <term><varname>RxMaxCoalescedFrames=</varname></term>
1c4d83
+        <term><varname>RxMaxCoalescedIrqFrames=</varname></term>
1c4d83
+        <term><varname>RxMaxCoalescedLowFrames=</varname></term>
1c4d83
+        <term><varname>RxMaxCoalescedHighFrames=</varname></term>
1c4d83
+        <term><varname>TxMaxCoalescedFrames=</varname></term>
1c4d83
+        <term><varname>TxMaxCoalescedIrqFrames=</varname></term>
1c4d83
+        <term><varname>TxMaxCoalescedLowFrames=</varname></term>
1c4d83
+        <term><varname>TxMaxCoalescedHighFrames=</varname></term>
1c4d83
+        <listitem>
1c4d83
+          <para>These properties configure the maximum number of frames that are sent/received before a Rx/Tx
1c4d83
+          interrupt is generated. The <literal>Irq</literal> properties come into effect when the host is
1c4d83
+          servicing an IRQ. The <literal>Low</literal> and <literal>High</literal> properties come into
1c4d83
+          effect when the packet rate drops below the low packet rate threshold or exceeds the high packet
1c4d83
+          rate threshold respectively if adaptive Rx/Tx coalescing is enabled. When unset, the kernel's
1c4d83
+          defaults will be used.</para>
1c4d83
+        </listitem>
1c4d83
+      </varlistentry>
1c4d83
+      <varlistentry>
1c4d83
+        <term><varname>CoalescePacketRateLow=</varname></term>
1c4d83
+        <term><varname>CoalescePacketRateHigh=</varname></term>
1c4d83
+        <listitem>
1c4d83
+          <para>These properties configure the low and high packet rate (expressed in packets per second)
1c4d83
+          threshold respectively and are used to determine when the corresponding coalescing settings for low
1c4d83
+          and high packet rates come into effect if adaptive Rx/Tx coalescing is enabled. If unset, the
1c4d83
+          kernel's defaults will be used.</para>
1c4d83
+        </listitem>
1c4d83
+      </varlistentry>
1c4d83
+      <varlistentry>
1c4d83
+        <term><varname>CoalescePacketRateSampleIntervalSec=</varname></term>
1c4d83
+        <listitem>
1c4d83
+          <para>Configures how often to sample the packet rate used for adaptive Rx/Tx coalescing. This
1c4d83
+          property cannot be zero. This lowest time granularity supported by this property is seconds.
1c4d83
+          Partial seconds will be rounded up before being passed to the kernel. If unset, the kernel's
1c4d83
+          default will be used.</para>
1c4d83
+        </listitem>
1c4d83
+      </varlistentry>
1c4d83
+      <varlistentry>
1c4d83
+        <term><varname>StatisticsBlockCoalesceSec=</varname></term>
1c4d83
+        <listitem>
1c4d83
+          <para>How long to delay driver in-memory statistics block updates. If the driver does not have an
1c4d83
+          in-memory statistic block, this property is ignored. This property cannot be zero. If unset, the
1c4d83
+          kernel's default will be used.</para>
1c4d83
+        </listitem>
1c4d83
+      </varlistentry>
1c4d83
 
1c4d83
     </variablelist>
1c4d83
   </refsect1>
1c4d83
diff --git a/src/shared/ethtool-util.c b/src/shared/ethtool-util.c
1c4d83
index 2d41d861ba..f7f553dd29 100644
1c4d83
--- a/src/shared/ethtool-util.c
1c4d83
+++ b/src/shared/ethtool-util.c
1c4d83
@@ -14,6 +14,7 @@
1c4d83
 #include "memory-util.h"
1c4d83
 #include "socket-util.h"
1c4d83
 #include "string-table.h"
1c4d83
+#include "strv.h"
1c4d83
 #include "strxcpyx.h"
1c4d83
 
1c4d83
 static const char* const duplex_table[_DUP_MAX] = {
1c4d83
@@ -1091,3 +1092,207 @@ int config_parse_wol(
1c4d83
 
1c4d83
         return 0;
1c4d83
 }
1c4d83
+
1c4d83
+int config_parse_coalesce_u32(
1c4d83
+                const char *unit,
1c4d83
+                const char *filename,
1c4d83
+                unsigned line,
1c4d83
+                const char *section,
1c4d83
+                unsigned section_line,
1c4d83
+                const char *lvalue,
1c4d83
+                int ltype,
1c4d83
+                const char *rvalue,
1c4d83
+                void *data,
1c4d83
+                void *userdata) {
1c4d83
+        u32_opt *dst = data;
1c4d83
+        uint32_t k;
1c4d83
+        int r;
1c4d83
+
1c4d83
+        if (isempty(rvalue)) {
1c4d83
+                dst->value = 0;
1c4d83
+                dst->set = false;
1c4d83
+                return 0;
1c4d83
+        }
1c4d83
+
1c4d83
+        r = safe_atou32(rvalue, &k);
1c4d83
+        if (r < 0) {
1c4d83
+                log_syntax(unit, LOG_WARNING, filename, line, r,
1c4d83
+                           "Failed to parse %s=, ignoring: %s", lvalue, rvalue);
1c4d83
+                return 0;
1c4d83
+        }
1c4d83
+
1c4d83
+        dst->value = k;
1c4d83
+        dst->set = true;
1c4d83
+        return 0;
1c4d83
+}
1c4d83
+
1c4d83
+int config_parse_coalesce_sec(
1c4d83
+                const char *unit,
1c4d83
+                const char *filename,
1c4d83
+                unsigned line,
1c4d83
+                const char *section,
1c4d83
+                unsigned section_line,
1c4d83
+                const char *lvalue,
1c4d83
+                int ltype,
1c4d83
+                const char *rvalue,
1c4d83
+                void *data,
1c4d83
+                void *userdata) {
1c4d83
+        u32_opt *dst = data;
1c4d83
+        usec_t usec;
1c4d83
+        int r;
1c4d83
+
1c4d83
+        if (isempty(rvalue)) {
1c4d83
+                dst->value = 0;
1c4d83
+                dst->set = false;
1c4d83
+                return 0;
1c4d83
+        }
1c4d83
+
1c4d83
+        r = parse_sec(rvalue, &usec);
1c4d83
+        if (r < 0) {
1c4d83
+                log_syntax(unit, LOG_WARNING, filename, line, r,
1c4d83
+                           "Failed to parse coalesce setting value, ignoring: %s", rvalue);
1c4d83
+                return 0;
1c4d83
+        }
1c4d83
+
1c4d83
+        if (usec > UINT32_MAX) {
1c4d83
+                log_syntax(unit, LOG_WARNING, filename, line, 0,
1c4d83
+                           "Too large %s= value, ignoring: %s", lvalue, rvalue);
1c4d83
+                return 0;
1c4d83
+        }
1c4d83
+
1c4d83
+        if (STR_IN_SET(lvalue, "StatisticsBlockCoalesceSec", "CoalescePacketRateSampleIntervalSec") && usec < 1) {
1c4d83
+                log_syntax(unit, LOG_WARNING, filename, line, 0,
1c4d83
+                           "Invalid %s= value, ignoring: %s", lvalue, rvalue);
1c4d83
+                return 0;
1c4d83
+        }
1c4d83
+
1c4d83
+        dst->value = (uint32_t) usec;
1c4d83
+        dst->set = true;
1c4d83
+
1c4d83
+        return 0;
1c4d83
+}
1c4d83
+
1c4d83
+int ethtool_set_nic_coalesce_settings(int *ethtool_fd, const char *ifname, const netdev_coalesce_param *coalesce) {
1c4d83
+        struct ethtool_coalesce ecmd = {
1c4d83
+                .cmd = ETHTOOL_GCOALESCE,
1c4d83
+        };
1c4d83
+        struct ifreq ifr = {
1c4d83
+                .ifr_data = (void*) &ecmd,
1c4d83
+        };
1c4d83
+        bool need_update = false;
1c4d83
+        int r;
1c4d83
+
1c4d83
+        assert(ethtool_fd);
1c4d83
+        assert(ifname);
1c4d83
+        assert(coalesce);
1c4d83
+
1c4d83
+        if (coalesce->use_adaptive_rx_coalesce < 0 &&
1c4d83
+            coalesce->use_adaptive_tx_coalesce < 0 &&
1c4d83
+            !coalesce->rx_coalesce_usecs.set &&
1c4d83
+            !coalesce->rx_max_coalesced_frames.set &&
1c4d83
+            !coalesce->rx_coalesce_usecs_irq.set &&
1c4d83
+            !coalesce->rx_max_coalesced_frames_irq.set &&
1c4d83
+            !coalesce->tx_coalesce_usecs.set &&
1c4d83
+            !coalesce->tx_max_coalesced_frames.set &&
1c4d83
+            !coalesce->tx_coalesce_usecs_irq.set &&
1c4d83
+            !coalesce->tx_max_coalesced_frames_irq.set &&
1c4d83
+            !coalesce->stats_block_coalesce_usecs.set &&
1c4d83
+            !coalesce->pkt_rate_low.set &&
1c4d83
+            !coalesce->rx_coalesce_usecs_low.set &&
1c4d83
+            !coalesce->rx_max_coalesced_frames_low.set &&
1c4d83
+            !coalesce->tx_coalesce_usecs_low.set &&
1c4d83
+            !coalesce->tx_max_coalesced_frames_low.set &&
1c4d83
+            !coalesce->pkt_rate_high.set &&
1c4d83
+            !coalesce->rx_coalesce_usecs_high.set &&
1c4d83
+            !coalesce->rx_max_coalesced_frames_high.set &&
1c4d83
+            !coalesce->tx_coalesce_usecs_high.set &&
1c4d83
+            !coalesce->tx_max_coalesced_frames_high.set &&
1c4d83
+            !coalesce->rate_sample_interval.set)
1c4d83
+                return 0;
1c4d83
+
1c4d83
+        r = ethtool_connect(ethtool_fd);
1c4d83
+        if (r < 0)
1c4d83
+                return r;
1c4d83
+
1c4d83
+        strscpy(ifr.ifr_name, IFNAMSIZ, ifname);
1c4d83
+
1c4d83
+        r = ioctl(*ethtool_fd, SIOCETHTOOL, &ifr);
1c4d83
+        if (r < 0)
1c4d83
+                return -errno;
1c4d83
+
1c4d83
+        if (coalesce->use_adaptive_rx_coalesce >= 0)
1c4d83
+                UPDATE(ecmd.use_adaptive_rx_coalesce, (uint32_t) coalesce->use_adaptive_rx_coalesce, need_update);
1c4d83
+
1c4d83
+        if (coalesce->use_adaptive_tx_coalesce >= 0)
1c4d83
+                UPDATE(ecmd.use_adaptive_tx_coalesce, (uint32_t) coalesce->use_adaptive_tx_coalesce, need_update);
1c4d83
+
1c4d83
+        if (coalesce->rx_coalesce_usecs.set)
1c4d83
+                UPDATE(ecmd.rx_coalesce_usecs, coalesce->rx_coalesce_usecs.value, need_update);
1c4d83
+
1c4d83
+        if (coalesce->rx_max_coalesced_frames.set)
1c4d83
+                UPDATE(ecmd.rx_max_coalesced_frames, coalesce->rx_max_coalesced_frames.value, need_update);
1c4d83
+
1c4d83
+        if (coalesce->rx_coalesce_usecs_irq.set)
1c4d83
+                UPDATE(ecmd.rx_coalesce_usecs_irq, coalesce->rx_coalesce_usecs_irq.value, need_update);
1c4d83
+
1c4d83
+        if (coalesce->rx_max_coalesced_frames_irq.set)
1c4d83
+                UPDATE(ecmd.rx_max_coalesced_frames_irq, coalesce->rx_max_coalesced_frames_irq.value, need_update);
1c4d83
+
1c4d83
+        if (coalesce->tx_coalesce_usecs.set)
1c4d83
+                UPDATE(ecmd.tx_coalesce_usecs, coalesce->tx_coalesce_usecs.value, need_update);
1c4d83
+
1c4d83
+        if (coalesce->tx_max_coalesced_frames.set)
1c4d83
+                UPDATE(ecmd.tx_max_coalesced_frames, coalesce->tx_max_coalesced_frames.value, need_update);
1c4d83
+
1c4d83
+        if (coalesce->tx_coalesce_usecs_irq.set)
1c4d83
+                UPDATE(ecmd.tx_coalesce_usecs_irq, coalesce->tx_coalesce_usecs_irq.value, need_update);
1c4d83
+
1c4d83
+        if (coalesce->tx_max_coalesced_frames_irq.set)
1c4d83
+                UPDATE(ecmd.tx_max_coalesced_frames_irq, coalesce->tx_max_coalesced_frames_irq.value, need_update);
1c4d83
+
1c4d83
+        if (coalesce->stats_block_coalesce_usecs.set)
1c4d83
+                UPDATE(ecmd.stats_block_coalesce_usecs, coalesce->stats_block_coalesce_usecs.value, need_update);
1c4d83
+
1c4d83
+        if (coalesce->pkt_rate_low.set)
1c4d83
+                UPDATE(ecmd.pkt_rate_low, coalesce->pkt_rate_low.value, need_update);
1c4d83
+
1c4d83
+        if (coalesce->rx_coalesce_usecs_low.set)
1c4d83
+                UPDATE(ecmd.rx_coalesce_usecs_low, coalesce->rx_coalesce_usecs_low.value, need_update);
1c4d83
+
1c4d83
+        if (coalesce->rx_max_coalesced_frames_low.set)
1c4d83
+                UPDATE(ecmd.rx_max_coalesced_frames_low, coalesce->rx_max_coalesced_frames_low.value, need_update);
1c4d83
+
1c4d83
+        if (coalesce->tx_coalesce_usecs_low.set)
1c4d83
+                UPDATE(ecmd.tx_coalesce_usecs_low, coalesce->tx_coalesce_usecs_low.value, need_update);
1c4d83
+
1c4d83
+        if (coalesce->tx_max_coalesced_frames_low.set)
1c4d83
+                UPDATE(ecmd.tx_max_coalesced_frames_low, coalesce->tx_max_coalesced_frames_low.value, need_update);
1c4d83
+
1c4d83
+        if (coalesce->pkt_rate_high.set)
1c4d83
+                UPDATE(ecmd.pkt_rate_high, coalesce->pkt_rate_high.value, need_update);
1c4d83
+
1c4d83
+        if (coalesce->rx_coalesce_usecs_high.set)
1c4d83
+                UPDATE(ecmd.rx_coalesce_usecs_high, coalesce->rx_coalesce_usecs_high.value, need_update);
1c4d83
+
1c4d83
+        if (coalesce->rx_max_coalesced_frames_high.set)
1c4d83
+                UPDATE(ecmd.rx_max_coalesced_frames_high, coalesce->rx_max_coalesced_frames_high.value, need_update);
1c4d83
+
1c4d83
+        if (coalesce->tx_coalesce_usecs_high.set)
1c4d83
+                UPDATE(ecmd.tx_coalesce_usecs_high, coalesce->tx_coalesce_usecs_high.value, need_update);
1c4d83
+
1c4d83
+        if (coalesce->tx_max_coalesced_frames_high.set)
1c4d83
+                UPDATE(ecmd.tx_max_coalesced_frames_high, coalesce->tx_max_coalesced_frames_high.value, need_update);
1c4d83
+
1c4d83
+        if (coalesce->rate_sample_interval.set)
1c4d83
+                UPDATE(ecmd.rate_sample_interval, DIV_ROUND_UP(coalesce->rate_sample_interval.value, USEC_PER_SEC), need_update);
1c4d83
+
1c4d83
+        if (!need_update)
1c4d83
+                return 0;
1c4d83
+
1c4d83
+        ecmd.cmd = ETHTOOL_SCOALESCE;
1c4d83
+        r = ioctl(*ethtool_fd, SIOCETHTOOL, &ifr);
1c4d83
+        if (r < 0)
1c4d83
+                return -errno;
1c4d83
+
1c4d83
+        return 0;
1c4d83
+}
1c4d83
diff --git a/src/shared/ethtool-util.h b/src/shared/ethtool-util.h
1c4d83
index 8fdbdec39a..bb0333775c 100644
1c4d83
--- a/src/shared/ethtool-util.h
1c4d83
+++ b/src/shared/ethtool-util.h
1c4d83
@@ -76,6 +76,31 @@ typedef struct netdev_ring_param {
1c4d83
         u32_opt tx;
1c4d83
 } netdev_ring_param;
1c4d83
 
1c4d83
+typedef struct netdev_coalesce_param {
1c4d83
+        u32_opt rx_coalesce_usecs;
1c4d83
+        u32_opt rx_max_coalesced_frames;
1c4d83
+        u32_opt rx_coalesce_usecs_irq;
1c4d83
+        u32_opt rx_max_coalesced_frames_irq;
1c4d83
+        u32_opt tx_coalesce_usecs;
1c4d83
+        u32_opt tx_max_coalesced_frames;
1c4d83
+        u32_opt tx_coalesce_usecs_irq;
1c4d83
+        u32_opt tx_max_coalesced_frames_irq;
1c4d83
+        u32_opt stats_block_coalesce_usecs;
1c4d83
+        int use_adaptive_rx_coalesce;
1c4d83
+        int use_adaptive_tx_coalesce;
1c4d83
+        u32_opt pkt_rate_low;
1c4d83
+        u32_opt rx_coalesce_usecs_low;
1c4d83
+        u32_opt rx_max_coalesced_frames_low;
1c4d83
+        u32_opt tx_coalesce_usecs_low;
1c4d83
+        u32_opt tx_max_coalesced_frames_low;
1c4d83
+        u32_opt pkt_rate_high;
1c4d83
+        u32_opt rx_coalesce_usecs_high;
1c4d83
+        u32_opt rx_max_coalesced_frames_high;
1c4d83
+        u32_opt tx_coalesce_usecs_high;
1c4d83
+        u32_opt tx_max_coalesced_frames_high;
1c4d83
+        u32_opt rate_sample_interval;
1c4d83
+} netdev_coalesce_param;
1c4d83
+
1c4d83
 int ethtool_get_driver(int *ethtool_fd, const char *ifname, char **ret);
1c4d83
 int ethtool_get_link_info(int *ethtool_fd, const char *ifname,
1c4d83
                           int *ret_autonegotiation, uint64_t *ret_speed,
1c4d83
@@ -89,6 +114,7 @@ int ethtool_set_glinksettings(int *ethtool_fd, const char *ifname,
1c4d83
                               uint64_t speed, Duplex duplex, NetDevPort port);
1c4d83
 int ethtool_set_channels(int *ethtool_fd, const char *ifname, const netdev_channels *channels);
1c4d83
 int ethtool_set_flow_control(int *fd, const char *ifname, int rx, int tx, int autoneg);
1c4d83
+int ethtool_set_nic_coalesce_settings(int *ethtool_fd, const char *ifname, const netdev_coalesce_param *coalesce);
1c4d83
 
1c4d83
 const char *duplex_to_string(Duplex d) _const_;
1c4d83
 Duplex duplex_from_string(const char *d) _pure_;
1c4d83
@@ -106,3 +132,6 @@ CONFIG_PARSER_PROTOTYPE(config_parse_wol);
1c4d83
 CONFIG_PARSER_PROTOTYPE(config_parse_port);
1c4d83
 CONFIG_PARSER_PROTOTYPE(config_parse_advertise);
1c4d83
 CONFIG_PARSER_PROTOTYPE(config_parse_ring_buffer_or_channel);
1c4d83
+CONFIG_PARSER_PROTOTYPE(config_parse_coalesce_u32);
1c4d83
+CONFIG_PARSER_PROTOTYPE(config_parse_coalesce_sec);
1c4d83
+CONFIG_PARSER_PROTOTYPE(config_parse_nic_coalesce_setting);
1c4d83
diff --git a/src/udev/net/link-config-gperf.gperf b/src/udev/net/link-config-gperf.gperf
1c4d83
index d0190da5cb..f800de8386 100644
1c4d83
--- a/src/udev/net/link-config-gperf.gperf
1c4d83
+++ b/src/udev/net/link-config-gperf.gperf
1c4d83
@@ -21,54 +21,76 @@ struct ConfigPerfItem;
1c4d83
 %struct-type
1c4d83
 %includes
1c4d83
 %%
1c4d83
-Match.MACAddress,                      config_parse_hwaddrs,                  0,                             offsetof(LinkConfig, match.mac)
1c4d83
-Match.PermanentMACAddress,             config_parse_hwaddrs,                  0,                             offsetof(LinkConfig, match.permanent_mac)
1c4d83
-Match.OriginalName,                    config_parse_match_ifnames,            0,                             offsetof(LinkConfig, match.ifname)
1c4d83
-Match.Path,                            config_parse_match_strv,               0,                             offsetof(LinkConfig, match.path)
1c4d83
-Match.Driver,                          config_parse_match_strv,               0,                             offsetof(LinkConfig, match.driver)
1c4d83
-Match.Type,                            config_parse_match_strv,               0,                             offsetof(LinkConfig, match.iftype)
1c4d83
-Match.Property,                        config_parse_match_property,           0,                             offsetof(LinkConfig, match.property)
1c4d83
-Match.Host,                            config_parse_net_condition,            CONDITION_HOST,                offsetof(LinkConfig, conditions)
1c4d83
-Match.Virtualization,                  config_parse_net_condition,            CONDITION_VIRTUALIZATION,      offsetof(LinkConfig, conditions)
1c4d83
-Match.KernelCommandLine,               config_parse_net_condition,            CONDITION_KERNEL_COMMAND_LINE, offsetof(LinkConfig, conditions)
1c4d83
-Match.KernelVersion,                   config_parse_net_condition,            CONDITION_KERNEL_VERSION,      offsetof(LinkConfig, conditions)
1c4d83
-Match.Architecture,                    config_parse_net_condition,            CONDITION_ARCHITECTURE,        offsetof(LinkConfig, conditions)
1c4d83
-Link.Description,                      config_parse_string,                   0,                             offsetof(LinkConfig, description)
1c4d83
-Link.MACAddressPolicy,                 config_parse_mac_address_policy,       0,                             offsetof(LinkConfig, mac_address_policy)
1c4d83
-Link.MACAddress,                       config_parse_hwaddr,                   0,                             offsetof(LinkConfig, mac)
1c4d83
-Link.NamePolicy,                       config_parse_name_policy,              0,                             offsetof(LinkConfig, name_policy)
1c4d83
-Link.Name,                             config_parse_ifname,                   0,                             offsetof(LinkConfig, name)
1c4d83
-Link.AlternativeName,                  config_parse_ifnames,                  IFNAME_VALID_ALTERNATIVE,      offsetof(LinkConfig, alternative_names)
1c4d83
-Link.AlternativeNamesPolicy,           config_parse_alternative_names_policy, 0,                             offsetof(LinkConfig, alternative_names_policy)
1c4d83
-Link.Alias,                            config_parse_ifalias,                  0,                             offsetof(LinkConfig, alias)
1c4d83
-Link.TransmitQueues,                   config_parse_rx_tx_queues,             0,                             offsetof(LinkConfig, txqueues)
1c4d83
-Link.ReceiveQueues,                    config_parse_rx_tx_queues,             0,                             offsetof(LinkConfig, rxqueues)
1c4d83
-Link.TransmitQueueLength,              config_parse_txqueuelen,               0,                             offsetof(LinkConfig, txqueuelen)
1c4d83
-Link.MTUBytes,                         config_parse_mtu,                      AF_UNSPEC,                     offsetof(LinkConfig, mtu)
1c4d83
-Link.BitsPerSecond,                    config_parse_si_uint64,                0,                             offsetof(LinkConfig, speed)
1c4d83
-Link.Duplex,                           config_parse_duplex,                   0,                             offsetof(LinkConfig, duplex)
1c4d83
-Link.AutoNegotiation,                  config_parse_tristate,                 0,                             offsetof(LinkConfig, autonegotiation)
1c4d83
-Link.WakeOnLan,                        config_parse_wol,                      0,                             offsetof(LinkConfig, wol)
1c4d83
-Link.Port,                             config_parse_port,                     0,                             offsetof(LinkConfig, port)
1c4d83
-Link.ReceiveChecksumOffload,           config_parse_tristate,                 0,                             offsetof(LinkConfig, features[NET_DEV_FEAT_RX])
1c4d83
-Link.TransmitChecksumOffload,          config_parse_tristate,                 0,                             offsetof(LinkConfig, features[NET_DEV_FEAT_TX])
1c4d83
-Link.GenericSegmentationOffload,       config_parse_tristate,                 0,                             offsetof(LinkConfig, features[NET_DEV_FEAT_GSO])
1c4d83
-Link.TCPSegmentationOffload,           config_parse_tristate,                 0,                             offsetof(LinkConfig, features[NET_DEV_FEAT_TSO])
1c4d83
-Link.TCP6SegmentationOffload,          config_parse_tristate,                 0,                             offsetof(LinkConfig, features[NET_DEV_FEAT_TSO6])
1c4d83
-Link.UDPSegmentationOffload,           config_parse_warn_compat,              DISABLED_LEGACY,               0
1c4d83
-Link.GenericReceiveOffload,            config_parse_tristate,                 0,                             offsetof(LinkConfig, features[NET_DEV_FEAT_GRO])
1c4d83
-Link.LargeReceiveOffload,              config_parse_tristate,                 0,                             offsetof(LinkConfig, features[NET_DEV_FEAT_LRO])
1c4d83
-Link.RxChannels,                       config_parse_ring_buffer_or_channel,   0,                             offsetof(LinkConfig, channels.rx)
1c4d83
-Link.TxChannels,                       config_parse_ring_buffer_or_channel,   0,                             offsetof(LinkConfig, channels.tx)
1c4d83
-Link.OtherChannels,                    config_parse_ring_buffer_or_channel,   0,                             offsetof(LinkConfig, channels.other)
1c4d83
-Link.CombinedChannels,                 config_parse_ring_buffer_or_channel,   0,                             offsetof(LinkConfig, channels.combined)
1c4d83
-Link.Advertise,                        config_parse_advertise,                0,                             offsetof(LinkConfig, advertise)
1c4d83
-Link.RxBufferSize,                     config_parse_ring_buffer_or_channel,   0,                             offsetof(LinkConfig, ring.rx)
1c4d83
-Link.RxMiniBufferSize,                 config_parse_ring_buffer_or_channel,   0,                             offsetof(LinkConfig, ring.rx_mini)
1c4d83
-Link.RxJumboBufferSize,                config_parse_ring_buffer_or_channel,   0,                             offsetof(LinkConfig, ring.rx_jumbo)
1c4d83
-Link.TxBufferSize,                     config_parse_ring_buffer_or_channel,   0,                             offsetof(LinkConfig, ring.tx)
1c4d83
-Link.RxFlowControl,                    config_parse_tristate,                 0,                             offsetof(LinkConfig, rx_flow_control)
1c4d83
-Link.TxFlowControl,                    config_parse_tristate,                 0,                             offsetof(LinkConfig, tx_flow_control)
1c4d83
-Link.AutoNegotiationFlowControl,       config_parse_tristate,                 0,                             offsetof(LinkConfig, autoneg_flow_control)
1c4d83
-Link.GenericSegmentOffloadMaxBytes,    config_parse_iec_size,                 0,                             offsetof(LinkConfig, gso_max_size)
1c4d83
-Link.GenericSegmentOffloadMaxSegments, config_parse_uint32,                   0,                             offsetof(LinkConfig, gso_max_segments)
1c4d83
+Match.MACAddress,                         config_parse_hwaddrs,                  0,                             offsetof(LinkConfig, match.mac)
1c4d83
+Match.PermanentMACAddress,                config_parse_hwaddrs,                  0,                             offsetof(LinkConfig, match.permanent_mac)
1c4d83
+Match.OriginalName,                       config_parse_match_ifnames,            0,                             offsetof(LinkConfig, match.ifname)
1c4d83
+Match.Path,                               config_parse_match_strv,               0,                             offsetof(LinkConfig, match.path)
1c4d83
+Match.Driver,                             config_parse_match_strv,               0,                             offsetof(LinkConfig, match.driver)
1c4d83
+Match.Type,                               config_parse_match_strv,               0,                             offsetof(LinkConfig, match.iftype)
1c4d83
+Match.Property,                           config_parse_match_property,           0,                             offsetof(LinkConfig, match.property)
1c4d83
+Match.Host,                               config_parse_net_condition,            CONDITION_HOST,                offsetof(LinkConfig, conditions)
1c4d83
+Match.Virtualization,                     config_parse_net_condition,            CONDITION_VIRTUALIZATION,      offsetof(LinkConfig, conditions)
1c4d83
+Match.KernelCommandLine,                  config_parse_net_condition,            CONDITION_KERNEL_COMMAND_LINE, offsetof(LinkConfig, conditions)
1c4d83
+Match.KernelVersion,                      config_parse_net_condition,            CONDITION_KERNEL_VERSION,      offsetof(LinkConfig, conditions)
1c4d83
+Match.Architecture,                       config_parse_net_condition,            CONDITION_ARCHITECTURE,        offsetof(LinkConfig, conditions)
1c4d83
+Link.Description,                         config_parse_string,                   0,                             offsetof(LinkConfig, description)
1c4d83
+Link.MACAddressPolicy,                    config_parse_mac_address_policy,       0,                             offsetof(LinkConfig, mac_address_policy)
1c4d83
+Link.MACAddress,                          config_parse_hwaddr,                   0,                             offsetof(LinkConfig, mac)
1c4d83
+Link.NamePolicy,                          config_parse_name_policy,              0,                             offsetof(LinkConfig, name_policy)
1c4d83
+Link.Name,                                config_parse_ifname,                   0,                             offsetof(LinkConfig, name)
1c4d83
+Link.AlternativeName,                     config_parse_ifnames,                  IFNAME_VALID_ALTERNATIVE,      offsetof(LinkConfig, alternative_names)
1c4d83
+Link.AlternativeNamesPolicy,              config_parse_alternative_names_policy, 0,                             offsetof(LinkConfig, alternative_names_policy)
1c4d83
+Link.Alias,                               config_parse_ifalias,                  0,                             offsetof(LinkConfig, alias)
1c4d83
+Link.TransmitQueues,                      config_parse_rx_tx_queues,             0,                             offsetof(LinkConfig, txqueues)
1c4d83
+Link.ReceiveQueues,                       config_parse_rx_tx_queues,             0,                             offsetof(LinkConfig, rxqueues)
1c4d83
+Link.TransmitQueueLength,                 config_parse_txqueuelen,               0,                             offsetof(LinkConfig, txqueuelen)
1c4d83
+Link.MTUBytes,                            config_parse_mtu,                      AF_UNSPEC,                     offsetof(LinkConfig, mtu)
1c4d83
+Link.BitsPerSecond,                       config_parse_si_uint64,                0,                             offsetof(LinkConfig, speed)
1c4d83
+Link.Duplex,                              config_parse_duplex,                   0,                             offsetof(LinkConfig, duplex)
1c4d83
+Link.AutoNegotiation,                     config_parse_tristate,                 0,                             offsetof(LinkConfig, autonegotiation)
1c4d83
+Link.WakeOnLan,                           config_parse_wol,                      0,                             offsetof(LinkConfig, wol)
1c4d83
+Link.Port,                                config_parse_port,                     0,                             offsetof(LinkConfig, port)
1c4d83
+Link.ReceiveChecksumOffload,              config_parse_tristate,                 0,                             offsetof(LinkConfig, features[NET_DEV_FEAT_RX])
1c4d83
+Link.TransmitChecksumOffload,             config_parse_tristate,                 0,                             offsetof(LinkConfig, features[NET_DEV_FEAT_TX])
1c4d83
+Link.GenericSegmentationOffload,          config_parse_tristate,                 0,                             offsetof(LinkConfig, features[NET_DEV_FEAT_GSO])
1c4d83
+Link.TCPSegmentationOffload,              config_parse_tristate,                 0,                             offsetof(LinkConfig, features[NET_DEV_FEAT_TSO])
1c4d83
+Link.TCP6SegmentationOffload,             config_parse_tristate,                 0,                             offsetof(LinkConfig, features[NET_DEV_FEAT_TSO6])
1c4d83
+Link.UDPSegmentationOffload,              config_parse_warn_compat,              DISABLED_LEGACY,               0
1c4d83
+Link.GenericReceiveOffload,               config_parse_tristate,                 0,                             offsetof(LinkConfig, features[NET_DEV_FEAT_GRO])
1c4d83
+Link.LargeReceiveOffload,                 config_parse_tristate,                 0,                             offsetof(LinkConfig, features[NET_DEV_FEAT_LRO])
1c4d83
+Link.RxChannels,                          config_parse_ring_buffer_or_channel,   0,                             offsetof(LinkConfig, channels.rx)
1c4d83
+Link.TxChannels,                          config_parse_ring_buffer_or_channel,   0,                             offsetof(LinkConfig, channels.tx)
1c4d83
+Link.OtherChannels,                       config_parse_ring_buffer_or_channel,   0,                             offsetof(LinkConfig, channels.other)
1c4d83
+Link.CombinedChannels,                    config_parse_ring_buffer_or_channel,   0,                             offsetof(LinkConfig, channels.combined)
1c4d83
+Link.Advertise,                           config_parse_advertise,                0,                             offsetof(LinkConfig, advertise)
1c4d83
+Link.RxBufferSize,                        config_parse_ring_buffer_or_channel,   0,                             offsetof(LinkConfig, ring.rx)
1c4d83
+Link.RxMiniBufferSize,                    config_parse_ring_buffer_or_channel,   0,                             offsetof(LinkConfig, ring.rx_mini)
1c4d83
+Link.RxJumboBufferSize,                   config_parse_ring_buffer_or_channel,   0,                             offsetof(LinkConfig, ring.rx_jumbo)
1c4d83
+Link.TxBufferSize,                        config_parse_ring_buffer_or_channel,   0,                             offsetof(LinkConfig, ring.tx)
1c4d83
+Link.RxFlowControl,                       config_parse_tristate,                 0,                             offsetof(LinkConfig, rx_flow_control)
1c4d83
+Link.TxFlowControl,                       config_parse_tristate,                 0,                             offsetof(LinkConfig, tx_flow_control)
1c4d83
+Link.AutoNegotiationFlowControl,          config_parse_tristate,                 0,                             offsetof(LinkConfig, autoneg_flow_control)
1c4d83
+Link.GenericSegmentOffloadMaxBytes,       config_parse_iec_size,                 0,                             offsetof(LinkConfig, gso_max_size)
1c4d83
+Link.GenericSegmentOffloadMaxSegments,    config_parse_uint32,                   0,                             offsetof(LinkConfig, gso_max_segments)
1c4d83
+Link.RxCoalesceSec,                       config_parse_coalesce_sec,             0,                             offsetof(LinkConfig, coalesce.rx_coalesce_usecs)
1c4d83
+Link.RxMaxCoalescedFrames,                config_parse_coalesce_u32,             0,                             offsetof(LinkConfig, coalesce.rx_max_coalesced_frames)
1c4d83
+Link.RxCoalesceIrqSec,                    config_parse_coalesce_sec,             0,                             offsetof(LinkConfig, coalesce.rx_coalesce_usecs_irq)
1c4d83
+Link.RxMaxCoalescedIrqFrames,             config_parse_coalesce_u32,             0,                             offsetof(LinkConfig, coalesce.rx_max_coalesced_frames_irq)
1c4d83
+Link.TxCoalesceSec,                       config_parse_coalesce_sec,             0,                             offsetof(LinkConfig, coalesce.tx_coalesce_usecs)
1c4d83
+Link.TxMaxCoalescedFrames,                config_parse_coalesce_u32,             0,                             offsetof(LinkConfig, coalesce.tx_max_coalesced_frames)
1c4d83
+Link.TxCoalesceIrqSec,                    config_parse_coalesce_sec,             0,                             offsetof(LinkConfig, coalesce.tx_coalesce_usecs_irq)
1c4d83
+Link.TxMaxCoalescedIrqFrames,             config_parse_coalesce_u32,             0,                             offsetof(LinkConfig, coalesce.tx_max_coalesced_frames_irq)
1c4d83
+Link.StatisticsBlockCoalesceSec,          config_parse_coalesce_sec,             0,                             offsetof(LinkConfig, coalesce.stats_block_coalesce_usecs)
1c4d83
+Link.UseAdaptiveRxCoalesce,               config_parse_tristate,                 0,                             offsetof(LinkConfig, coalesce.use_adaptive_rx_coalesce)
1c4d83
+Link.UseAdaptiveTxCoalesce,               config_parse_tristate,                 0,                             offsetof(LinkConfig, coalesce.use_adaptive_tx_coalesce)
1c4d83
+Link.CoalescePacketRateLow,               config_parse_coalesce_u32,             0,                             offsetof(LinkConfig, coalesce.pkt_rate_low)
1c4d83
+Link.RxCoalesceLowSec,                    config_parse_coalesce_sec,             0,                             offsetof(LinkConfig, coalesce.rx_coalesce_usecs_low)
1c4d83
+Link.RxMaxCoalescedLowFrames,             config_parse_coalesce_u32,             0,                             offsetof(LinkConfig, coalesce.rx_max_coalesced_frames_low)
1c4d83
+Link.TxCoalesceLowSec,                    config_parse_coalesce_sec,             0,                             offsetof(LinkConfig, coalesce.tx_coalesce_usecs_low)
1c4d83
+Link.TxMaxCoalescedLowFrames,             config_parse_coalesce_u32,             0,                             offsetof(LinkConfig, coalesce.tx_max_coalesced_frames_low)
1c4d83
+Link.CoalescePacketRateHigh,              config_parse_coalesce_u32,             0,                             offsetof(LinkConfig, coalesce.pkt_rate_high)
1c4d83
+Link.RxCoalesceHighSec,                   config_parse_coalesce_sec,             0,                             offsetof(LinkConfig, coalesce.rx_coalesce_usecs_high)
1c4d83
+Link.RxMaxCoalescedHighFrames,            config_parse_coalesce_u32,             0,                             offsetof(LinkConfig, coalesce.rx_max_coalesced_frames_high)
1c4d83
+Link.TxCoalesceHighSec,                   config_parse_coalesce_sec,             0,                             offsetof(LinkConfig, coalesce.tx_coalesce_usecs_high)
1c4d83
+Link.TxMaxCoalescedHighFrames,            config_parse_coalesce_u32,             0,                             offsetof(LinkConfig, coalesce.tx_max_coalesced_frames_high)
1c4d83
+Link.CoalescePacketRateSampleIntervalSec, config_parse_coalesce_sec,             0,                             offsetof(LinkConfig, coalesce.rate_sample_interval)
1c4d83
diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c
1c4d83
index 8dfe23691b..9451bd8b66 100644
1c4d83
--- a/src/udev/net/link-config.c
1c4d83
+++ b/src/udev/net/link-config.c
1c4d83
@@ -353,6 +353,10 @@ static int link_config_apply_ethtool_settings(int *ethtool_fd, const LinkConfig
1c4d83
         if (r < 0)
1c4d83
                 log_device_warning_errno(device, r, "Could not set flow control, ignoring: %m");
1c4d83
 
1c4d83
+        r = ethtool_set_nic_coalesce_settings(ethtool_fd, name, &config->coalesce);
1c4d83
+        if (r < 0)
1c4d83
+                log_device_warning_errno(device, r, "Could not set coalesce settings, ignoring: %m");
1c4d83
+
1c4d83
         return 0;
1c4d83
 }
1c4d83
 
1c4d83
diff --git a/src/udev/net/link-config.h b/src/udev/net/link-config.h
1c4d83
index b505c94f95..8a29a92822 100644
1c4d83
--- a/src/udev/net/link-config.h
1c4d83
+++ b/src/udev/net/link-config.h
1c4d83
@@ -64,6 +64,7 @@ struct LinkConfig {
1c4d83
         int rx_flow_control;
1c4d83
         int tx_flow_control;
1c4d83
         int autoneg_flow_control;
1c4d83
+        netdev_coalesce_param coalesce;
1c4d83
 
1c4d83
         LIST_FIELDS(LinkConfig, links);
1c4d83
 };
1c4d83
diff --git a/test/fuzz/fuzz-link-parser/directives.link b/test/fuzz/fuzz-link-parser/directives.link
1c4d83
index 112a81930f..5f232ce698 100644
1c4d83
--- a/test/fuzz/fuzz-link-parser/directives.link
1c4d83
+++ b/test/fuzz/fuzz-link-parser/directives.link
1c4d83
@@ -51,3 +51,25 @@ TxFlowControl=
1c4d83
 AutoNegotiationFlowControl=
1c4d83
 GenericSegmentOffloadMaxBytes=
1c4d83
 GenericSegmentOffloadMaxSegments=
1c4d83
+RxCoalesceSec=
1c4d83
+RxMaxCoalescedFrames=
1c4d83
+RxCoalesceIrqSec=
1c4d83
+RxMaxCoalescedIrqFrames=
1c4d83
+TxCoalesceSec=
1c4d83
+TxMaxCoalescedFrames=
1c4d83
+TxCoalesceIrqSec=
1c4d83
+TxMaxCoalescedIrqFrames=
1c4d83
+StatisticsBlockCoalesceSec=
1c4d83
+UseAdaptiveRxCoalesce=
1c4d83
+UseAdaptiveTxCoalesce=
1c4d83
+CoalescePacketRateLow=
1c4d83
+RxCoalesceLowSec=
1c4d83
+RxMaxCoalescedLowFrames=
1c4d83
+TxCoalesceLowSec=
1c4d83
+TxMaxCoalescedLowFrames=
1c4d83
+CoalescePacketRateHigh=
1c4d83
+RxCoalesceHighSec=
1c4d83
+RxMaxCoalescedHighFrames=
1c4d83
+TxCoalesceHighSec=
1c4d83
+TxMaxCoalescedHighFrames=
1c4d83
+CoalescePacketRateSampleIntervalSec=
1c4d83
-- 
1c4d83
2.31.1
1c4d83