summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-05-14 09:16:31 +0200
committerThomas Haller <thaller@redhat.com>2020-05-22 15:58:08 +0200
commit1f4b190934bed6aa0b5b46d0308d260b245af9a6 (patch)
treed1ab3edcdea6d86e9b65474bc5e7449d549af2bf
parent1f5f84081874d53bd12188c0843b5619478b3ea5 (diff)
downloadNetworkManager-1f4b190934bed6aa0b5b46d0308d260b245af9a6.tar.gz
platform: make states of NMEthtoolCoalesceState indexed by ethtool_id
We already have NMEthtoolID to handle coalesce options in a way that is convenient programmatically. That is, we can iterate over all valid coalesce options (it's just an integer) and use that in a more generic way. If NMEthtoolCoalesceState names all fields explicitly, we need explicit code that names each coalesce option. Especially since NMEthtoolCoalesceState is an internal and intermediate data structure, this is cumbersome and unnecessary. Thereby it also fixes the issue that nm_platform_ethtool_init_coalesce() has a NMPlatform argument without actually needing it. nm_platform_ethtool_init_coalesce() does not operate on a NMPlatform instance, and should not have the appearance of being a method of NMPlatform.
-rw-r--r--shared/nm-libnm-core-intern/nm-ethtool-utils.h2
-rw-r--r--src/devices/nm-device.c6
-rw-r--r--src/platform/nm-platform-utils.c100
-rw-r--r--src/platform/nm-platform-utils.h23
-rw-r--r--src/platform/nm-platform.c80
-rw-r--r--src/platform/nm-platform.h5
6 files changed, 56 insertions, 160 deletions
diff --git a/shared/nm-libnm-core-intern/nm-ethtool-utils.h b/shared/nm-libnm-core-intern/nm-ethtool-utils.h
index 0df3d3d00c..c33c3cb14a 100644
--- a/shared/nm-libnm-core-intern/nm-ethtool-utils.h
+++ b/shared/nm-libnm-core-intern/nm-ethtool-utils.h
@@ -108,6 +108,8 @@ typedef enum {
_NM_ETHTOOL_ID_NUM = (_NM_ETHTOOL_ID_LAST - _NM_ETHTOOL_ID_FIRST + 1),
} NMEthtoolID;
+#define _NM_ETHTOOL_ID_COALESCE_AS_IDX(ethtool_id) ((ethtool_id) - _NM_ETHTOOL_ID_COALESCE_FIRST)
+
typedef enum {
NM_ETHTOOL_TYPE_UNKNOWN,
NM_ETHTOOL_TYPE_COALESCE,
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index ab87f4646c..a1d83c26c2 100644
--- a/src/devices/nm-device.c
+++ b/src/devices/nm-device.c
@@ -932,11 +932,7 @@ _ethtool_coalesce_set (NMDevice *self,
}
nm_assert (g_variant_is_of_type (variant, G_VARIANT_TYPE_UINT32));
-
- nm_platform_ethtool_init_coalesce (platform,
- &coalesce_new,
- ethtool_id,
- g_variant_get_uint32 (variant));
+ coalesce_new.s[_NM_ETHTOOL_ID_COALESCE_AS_IDX (ethtool_id)] = g_variant_get_uint32 (variant);
}
if (!has_old)
diff --git a/src/platform/nm-platform-utils.c b/src/platform/nm-platform-utils.c
index 34c8238cb4..79529f539e 100644
--- a/src/platform/nm-platform-utils.c
+++ b/src/platform/nm-platform-utils.c
@@ -821,32 +821,36 @@ ethtool_get_coalesce (SocketHandle *shandle,
sizeof (struct ethtool_coalesce)) != 0)
return FALSE;
- coalesce->rx_coalesce_usecs = eth_data.rx_coalesce_usecs;
- coalesce->rx_max_coalesced_frames = eth_data.rx_max_coalesced_frames;
- coalesce->rx_coalesce_usecs_irq = eth_data.rx_coalesce_usecs_irq;
- coalesce->rx_max_coalesced_frames_irq = eth_data.rx_max_coalesced_frames_irq;
- coalesce->tx_coalesce_usecs = eth_data.tx_coalesce_usecs;
- coalesce->tx_max_coalesced_frames = eth_data.tx_max_coalesced_frames;
- coalesce->tx_coalesce_usecs_irq = eth_data.tx_coalesce_usecs_irq;
- coalesce->tx_max_coalesced_frames_irq = eth_data.tx_max_coalesced_frames_irq;
- coalesce->stats_block_coalesce_usecs = eth_data.stats_block_coalesce_usecs;
- coalesce->use_adaptive_rx_coalesce = eth_data.use_adaptive_rx_coalesce;
- coalesce->use_adaptive_tx_coalesce = eth_data.use_adaptive_tx_coalesce;
- coalesce->pkt_rate_low = eth_data.pkt_rate_low;
- coalesce->rx_coalesce_usecs_low = eth_data.rx_coalesce_usecs_low;
- coalesce->rx_max_coalesced_frames_low = eth_data.rx_max_coalesced_frames_low;
- coalesce->tx_coalesce_usecs_low = eth_data.tx_coalesce_usecs_low;
- coalesce->tx_max_coalesced_frames_low = eth_data.tx_max_coalesced_frames_low;
- coalesce->pkt_rate_high = eth_data.pkt_rate_high;
- coalesce->rx_coalesce_usecs_high = eth_data.rx_coalesce_usecs_high;
- coalesce->rx_max_coalesced_frames_high = eth_data.rx_max_coalesced_frames_high;
- coalesce->tx_coalesce_usecs_high = eth_data.tx_coalesce_usecs_high;
- coalesce->tx_max_coalesced_frames_high = eth_data.tx_max_coalesced_frames_high;
- coalesce->rate_sample_interval = eth_data.rate_sample_interval;
-
+ *coalesce = (NMEthtoolCoalesceState) {
+ .s = {
+ [_NM_ETHTOOL_ID_COALESCE_AS_IDX (NM_ETHTOOL_ID_COALESCE_RX_USECS)] = eth_data.rx_coalesce_usecs,
+ [_NM_ETHTOOL_ID_COALESCE_AS_IDX (NM_ETHTOOL_ID_COALESCE_RX_FRAMES)] = eth_data.rx_max_coalesced_frames,
+ [_NM_ETHTOOL_ID_COALESCE_AS_IDX (NM_ETHTOOL_ID_COALESCE_RX_USECS_IRQ)] = eth_data.rx_coalesce_usecs_irq,
+ [_NM_ETHTOOL_ID_COALESCE_AS_IDX (NM_ETHTOOL_ID_COALESCE_RX_FRAMES_IRQ)] = eth_data.rx_max_coalesced_frames_irq,
+ [_NM_ETHTOOL_ID_COALESCE_AS_IDX (NM_ETHTOOL_ID_COALESCE_TX_USECS)] = eth_data.tx_coalesce_usecs,
+ [_NM_ETHTOOL_ID_COALESCE_AS_IDX (NM_ETHTOOL_ID_COALESCE_TX_FRAMES)] = eth_data.tx_max_coalesced_frames,
+ [_NM_ETHTOOL_ID_COALESCE_AS_IDX (NM_ETHTOOL_ID_COALESCE_TX_USECS_IRQ)] = eth_data.tx_coalesce_usecs_irq,
+ [_NM_ETHTOOL_ID_COALESCE_AS_IDX (NM_ETHTOOL_ID_COALESCE_TX_FRAMES_IRQ)] = eth_data.tx_max_coalesced_frames_irq,
+ [_NM_ETHTOOL_ID_COALESCE_AS_IDX (NM_ETHTOOL_ID_COALESCE_STATS_BLOCK_USECS)] = eth_data.stats_block_coalesce_usecs,
+ [_NM_ETHTOOL_ID_COALESCE_AS_IDX (NM_ETHTOOL_ID_COALESCE_ADAPTIVE_RX)] = eth_data.use_adaptive_rx_coalesce,
+ [_NM_ETHTOOL_ID_COALESCE_AS_IDX (NM_ETHTOOL_ID_COALESCE_ADAPTIVE_TX)] = eth_data.use_adaptive_tx_coalesce,
+ [_NM_ETHTOOL_ID_COALESCE_AS_IDX (NM_ETHTOOL_ID_COALESCE_PKT_RATE_LOW)] = eth_data.pkt_rate_low,
+ [_NM_ETHTOOL_ID_COALESCE_AS_IDX (NM_ETHTOOL_ID_COALESCE_RX_USECS_LOW)] = eth_data.rx_coalesce_usecs_low,
+ [_NM_ETHTOOL_ID_COALESCE_AS_IDX (NM_ETHTOOL_ID_COALESCE_RX_FRAMES_LOW)] = eth_data.rx_max_coalesced_frames_low,
+ [_NM_ETHTOOL_ID_COALESCE_AS_IDX (NM_ETHTOOL_ID_COALESCE_TX_USECS_LOW)] = eth_data.tx_coalesce_usecs_low,
+ [_NM_ETHTOOL_ID_COALESCE_AS_IDX (NM_ETHTOOL_ID_COALESCE_TX_FRAMES_LOW)] = eth_data.tx_max_coalesced_frames_low,
+ [_NM_ETHTOOL_ID_COALESCE_AS_IDX (NM_ETHTOOL_ID_COALESCE_PKT_RATE_HIGH)] = eth_data.pkt_rate_high,
+ [_NM_ETHTOOL_ID_COALESCE_AS_IDX (NM_ETHTOOL_ID_COALESCE_RX_USECS_HIGH)] = eth_data.rx_coalesce_usecs_high,
+ [_NM_ETHTOOL_ID_COALESCE_AS_IDX (NM_ETHTOOL_ID_COALESCE_RX_FRAMES_HIGH)] = eth_data.rx_max_coalesced_frames_high,
+ [_NM_ETHTOOL_ID_COALESCE_AS_IDX (NM_ETHTOOL_ID_COALESCE_TX_USECS_HIGH)] = eth_data.tx_coalesce_usecs_high,
+ [_NM_ETHTOOL_ID_COALESCE_AS_IDX (NM_ETHTOOL_ID_COALESCE_TX_FRAMES_HIGH)] = eth_data.tx_max_coalesced_frames_high,
+ [_NM_ETHTOOL_ID_COALESCE_AS_IDX (NM_ETHTOOL_ID_COALESCE_SAMPLE_INTERVAL)] = eth_data.rate_sample_interval,
+ }
+ };
return TRUE;
}
+
gboolean
nmp_utils_ethtool_get_coalesce (int ifindex,
NMEthtoolCoalesceState *coalesce)
@@ -873,36 +877,36 @@ static gboolean
ethtool_set_coalesce (SocketHandle *shandle,
const NMEthtoolCoalesceState *coalesce)
{
- gboolean success;
struct ethtool_coalesce eth_data;
+ gboolean success;
- g_return_val_if_fail (shandle, FALSE);
- g_return_val_if_fail (coalesce, FALSE);
+ nm_assert (shandle);
+ nm_assert (coalesce);
eth_data = (struct ethtool_coalesce) {
.cmd = ETHTOOL_SCOALESCE,
- .rx_coalesce_usecs = coalesce->rx_coalesce_usecs,
- .rx_max_coalesced_frames = coalesce->rx_max_coalesced_frames,
- .rx_coalesce_usecs_irq = coalesce->rx_coalesce_usecs_irq,
- .rx_max_coalesced_frames_irq = coalesce->rx_max_coalesced_frames_irq,
- .tx_coalesce_usecs = coalesce->tx_coalesce_usecs,
- .tx_max_coalesced_frames = coalesce->tx_max_coalesced_frames,
- .tx_coalesce_usecs_irq = coalesce->tx_coalesce_usecs_irq,
- .tx_max_coalesced_frames_irq = coalesce->tx_max_coalesced_frames_irq,
- .stats_block_coalesce_usecs = coalesce->stats_block_coalesce_usecs,
- .use_adaptive_rx_coalesce = coalesce->use_adaptive_rx_coalesce,
- .use_adaptive_tx_coalesce = coalesce->use_adaptive_tx_coalesce,
- .pkt_rate_low = coalesce->pkt_rate_low,
- .rx_coalesce_usecs_low = coalesce->rx_coalesce_usecs_low,
- .rx_max_coalesced_frames_low = coalesce->rx_max_coalesced_frames_low,
- .tx_coalesce_usecs_low = coalesce->tx_coalesce_usecs_low,
- .tx_max_coalesced_frames_low = coalesce->tx_max_coalesced_frames_low,
- .pkt_rate_high = coalesce->pkt_rate_high,
- .rx_coalesce_usecs_high = coalesce->rx_coalesce_usecs_high,
- .rx_max_coalesced_frames_high = coalesce->rx_max_coalesced_frames_high,
- .tx_coalesce_usecs_high = coalesce->tx_coalesce_usecs_high,
- .tx_max_coalesced_frames_high = coalesce->tx_max_coalesced_frames_high,
- .rate_sample_interval = coalesce->rate_sample_interval,
+ .rx_coalesce_usecs = coalesce->s[_NM_ETHTOOL_ID_COALESCE_AS_IDX (NM_ETHTOOL_ID_COALESCE_RX_USECS)],
+ .rx_max_coalesced_frames = coalesce->s[_NM_ETHTOOL_ID_COALESCE_AS_IDX (NM_ETHTOOL_ID_COALESCE_RX_FRAMES)],
+ .rx_coalesce_usecs_irq = coalesce->s[_NM_ETHTOOL_ID_COALESCE_AS_IDX (NM_ETHTOOL_ID_COALESCE_RX_USECS_IRQ)],
+ .rx_max_coalesced_frames_irq = coalesce->s[_NM_ETHTOOL_ID_COALESCE_AS_IDX (NM_ETHTOOL_ID_COALESCE_RX_FRAMES_IRQ)],
+ .tx_coalesce_usecs = coalesce->s[_NM_ETHTOOL_ID_COALESCE_AS_IDX (NM_ETHTOOL_ID_COALESCE_TX_USECS)],
+ .tx_max_coalesced_frames = coalesce->s[_NM_ETHTOOL_ID_COALESCE_AS_IDX (NM_ETHTOOL_ID_COALESCE_TX_FRAMES)],
+ .tx_coalesce_usecs_irq = coalesce->s[_NM_ETHTOOL_ID_COALESCE_AS_IDX (NM_ETHTOOL_ID_COALESCE_TX_USECS_IRQ)],
+ .tx_max_coalesced_frames_irq = coalesce->s[_NM_ETHTOOL_ID_COALESCE_AS_IDX (NM_ETHTOOL_ID_COALESCE_TX_FRAMES_IRQ)],
+ .stats_block_coalesce_usecs = coalesce->s[_NM_ETHTOOL_ID_COALESCE_AS_IDX (NM_ETHTOOL_ID_COALESCE_STATS_BLOCK_USECS)],
+ .use_adaptive_rx_coalesce = coalesce->s[_NM_ETHTOOL_ID_COALESCE_AS_IDX (NM_ETHTOOL_ID_COALESCE_ADAPTIVE_RX)],
+ .use_adaptive_tx_coalesce = coalesce->s[_NM_ETHTOOL_ID_COALESCE_AS_IDX (NM_ETHTOOL_ID_COALESCE_ADAPTIVE_TX)],
+ .pkt_rate_low = coalesce->s[_NM_ETHTOOL_ID_COALESCE_AS_IDX (NM_ETHTOOL_ID_COALESCE_PKT_RATE_LOW)],
+ .rx_coalesce_usecs_low = coalesce->s[_NM_ETHTOOL_ID_COALESCE_AS_IDX (NM_ETHTOOL_ID_COALESCE_RX_USECS_LOW)],
+ .rx_max_coalesced_frames_low = coalesce->s[_NM_ETHTOOL_ID_COALESCE_AS_IDX (NM_ETHTOOL_ID_COALESCE_RX_FRAMES_LOW)],
+ .tx_coalesce_usecs_low = coalesce->s[_NM_ETHTOOL_ID_COALESCE_AS_IDX (NM_ETHTOOL_ID_COALESCE_TX_USECS_LOW)],
+ .tx_max_coalesced_frames_low = coalesce->s[_NM_ETHTOOL_ID_COALESCE_AS_IDX (NM_ETHTOOL_ID_COALESCE_TX_FRAMES_LOW)],
+ .pkt_rate_high = coalesce->s[_NM_ETHTOOL_ID_COALESCE_AS_IDX (NM_ETHTOOL_ID_COALESCE_PKT_RATE_HIGH)],
+ .rx_coalesce_usecs_high = coalesce->s[_NM_ETHTOOL_ID_COALESCE_AS_IDX (NM_ETHTOOL_ID_COALESCE_RX_USECS_HIGH)],
+ .rx_max_coalesced_frames_high = coalesce->s[_NM_ETHTOOL_ID_COALESCE_AS_IDX (NM_ETHTOOL_ID_COALESCE_RX_FRAMES_HIGH)],
+ .tx_coalesce_usecs_high = coalesce->s[_NM_ETHTOOL_ID_COALESCE_AS_IDX (NM_ETHTOOL_ID_COALESCE_TX_USECS_HIGH)],
+ .tx_max_coalesced_frames_high = coalesce->s[_NM_ETHTOOL_ID_COALESCE_AS_IDX (NM_ETHTOOL_ID_COALESCE_TX_FRAMES_HIGH)],
+ .rate_sample_interval = coalesce->s[_NM_ETHTOOL_ID_COALESCE_AS_IDX (NM_ETHTOOL_ID_COALESCE_SAMPLE_INTERVAL)],
};
success = (_ethtool_call_handle (shandle,
diff --git a/src/platform/nm-platform-utils.h b/src/platform/nm-platform-utils.h
index 242b97f168..062c859756 100644
--- a/src/platform/nm-platform-utils.h
+++ b/src/platform/nm-platform-utils.h
@@ -93,28 +93,7 @@ gboolean nmp_utils_ethtool_set_features (int ifindex,
gboolean do_set /* or reset */);
struct _NMEthtoolCoalesceState {
- guint32 rx_coalesce_usecs;
- guint32 rx_max_coalesced_frames;
- guint32 rx_coalesce_usecs_irq;
- guint32 rx_max_coalesced_frames_irq;
- guint32 tx_coalesce_usecs;
- guint32 tx_max_coalesced_frames;
- guint32 tx_coalesce_usecs_irq;
- guint32 tx_max_coalesced_frames_irq;
- guint32 stats_block_coalesce_usecs;
- guint32 use_adaptive_rx_coalesce;
- guint32 use_adaptive_tx_coalesce;
- guint32 pkt_rate_low;
- guint32 rx_coalesce_usecs_low;
- guint32 rx_max_coalesced_frames_low;
- guint32 tx_coalesce_usecs_low;
- guint32 tx_max_coalesced_frames_low;
- guint32 pkt_rate_high;
- guint32 rx_coalesce_usecs_high;
- guint32 rx_max_coalesced_frames_high;
- guint32 tx_coalesce_usecs_high;
- guint32 tx_max_coalesced_frames_high;
- guint32 rate_sample_interval;
+ guint32 s[_NM_ETHTOOL_ID_COALESCE_NUM /* indexed by (NMEthtoolID - _NM_ETHTOOL_ID_COALESCE_FIRST) */];
};
gboolean nmp_utils_ethtool_get_coalesce (int ifindex,
diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c
index 7b9457f7a5..8d826a109f 100644
--- a/src/platform/nm-platform.c
+++ b/src/platform/nm-platform.c
@@ -3227,86 +3227,6 @@ nm_platform_ethtool_get_link_coalesce (NMPlatform *self,
return nmp_utils_ethtool_get_coalesce (ifindex, coalesce);
}
-void
-nm_platform_ethtool_init_coalesce (NMPlatform *self,
- NMEthtoolCoalesceState *coalesce,
- int ethtool_id,
- guint32 value)
-{
- nm_assert (coalesce);
-
- switch (ethtool_id) {
- case NM_ETHTOOL_ID_COALESCE_ADAPTIVE_RX:
- coalesce->use_adaptive_rx_coalesce = value;
- break;
- case NM_ETHTOOL_ID_COALESCE_ADAPTIVE_TX:
- coalesce->use_adaptive_tx_coalesce = value;
- break;
- case NM_ETHTOOL_ID_COALESCE_PKT_RATE_HIGH:
- coalesce->pkt_rate_high = value;
- break;
- case NM_ETHTOOL_ID_COALESCE_PKT_RATE_LOW:
- coalesce->pkt_rate_low = value;
- break;
- case NM_ETHTOOL_ID_COALESCE_RX_FRAMES:
- coalesce->rx_max_coalesced_frames = value;
- break;
- case NM_ETHTOOL_ID_COALESCE_RX_FRAMES_HIGH:
- coalesce->rx_max_coalesced_frames_high = value;
- break;
- case NM_ETHTOOL_ID_COALESCE_RX_FRAMES_IRQ:
- coalesce->rx_max_coalesced_frames_irq = value;
- break;
- case NM_ETHTOOL_ID_COALESCE_RX_FRAMES_LOW:
- coalesce->rx_max_coalesced_frames_low = value;
- break;
- case NM_ETHTOOL_ID_COALESCE_RX_USECS:
- coalesce->rx_coalesce_usecs = value;
- break;
- case NM_ETHTOOL_ID_COALESCE_RX_USECS_HIGH:
- coalesce->rx_coalesce_usecs_high = value;
- break;
- case NM_ETHTOOL_ID_COALESCE_RX_USECS_IRQ:
- coalesce->rx_coalesce_usecs_irq = value;
- break;
- case NM_ETHTOOL_ID_COALESCE_RX_USECS_LOW:
- coalesce->rx_coalesce_usecs_low = value;
- break;
- case NM_ETHTOOL_ID_COALESCE_SAMPLE_INTERVAL:
- coalesce->rate_sample_interval = value;
- break;
- case NM_ETHTOOL_ID_COALESCE_STATS_BLOCK_USECS:
- coalesce->stats_block_coalesce_usecs = value;
- break;
- case NM_ETHTOOL_ID_COALESCE_TX_FRAMES:
- coalesce->tx_max_coalesced_frames = value;
- break;
- case NM_ETHTOOL_ID_COALESCE_TX_FRAMES_HIGH:
- coalesce->tx_max_coalesced_frames_high = value;
- break;
- case NM_ETHTOOL_ID_COALESCE_TX_FRAMES_IRQ:
- coalesce->tx_max_coalesced_frames_irq = value;
- break;
- case NM_ETHTOOL_ID_COALESCE_TX_FRAMES_LOW:
- coalesce->tx_max_coalesced_frames_low = value;
- break;
- case NM_ETHTOOL_ID_COALESCE_TX_USECS:
- coalesce->tx_coalesce_usecs = value;
- break;
- case NM_ETHTOOL_ID_COALESCE_TX_USECS_HIGH:
- coalesce->tx_coalesce_usecs_high = value;
- break;
- case NM_ETHTOOL_ID_COALESCE_TX_USECS_IRQ:
- coalesce->tx_coalesce_usecs_irq = value;
- break;
- case NM_ETHTOOL_ID_COALESCE_TX_USECS_LOW:
- coalesce->tx_coalesce_usecs_low = value;
- break;
- default:
- g_return_if_reached ();
- }
-}
-
gboolean
nm_platform_ethtool_set_coalesce (NMPlatform *self,
int ifindex,
diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h
index 041bc87448..c21190e803 100644
--- a/src/platform/nm-platform.h
+++ b/src/platform/nm-platform.h
@@ -1960,11 +1960,6 @@ gboolean nm_platform_ethtool_get_link_coalesce (NMPlatform *self,
int ifindex,
NMEthtoolCoalesceState *coalesce);
-void nm_platform_ethtool_init_coalesce (NMPlatform *self,
- NMEthtoolCoalesceState *coalesce,
- int ethtool_id,
- guint32 value);
-
gboolean nm_platform_ethtool_set_coalesce (NMPlatform *self,
int ifindex,
const NMEthtoolCoalesceState *coalesce);