summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntonio Cardace <acardace@redhat.com>2020-05-14 18:27:54 +0200
committerAntonio Cardace <acardace@redhat.com>2020-05-20 10:55:02 +0200
commit2d2c111304ed34a8d004cfa6e6bdde3fd3c71fa2 (patch)
treedb263b03d4f05c4b556a45e7ec11d89a3213e19a
parent126995a4d854935f1ab9041dfdb39fd04be5e9d9 (diff)
downloadNetworkManager-2d2c111304ed34a8d004cfa6e6bdde3fd3c71fa2.tar.gz
platform: add support for ring settings using ioctl()
https://bugzilla.redhat.com/show_bug.cgi?id=1614700
-rw-r--r--src/platform/nm-platform-utils.c91
-rw-r--r--src/platform/nm-platform-utils.h13
-rw-r--r--src/platform/nm-platform.c63
-rw-r--r--src/platform/nm-platform.h15
4 files changed, 180 insertions, 2 deletions
diff --git a/src/platform/nm-platform-utils.c b/src/platform/nm-platform-utils.c
index b0510c077a..3b799e2f11 100644
--- a/src/platform/nm-platform-utils.c
+++ b/src/platform/nm-platform-utils.c
@@ -269,6 +269,7 @@ NM_UTILS_ENUM2STR_DEFINE (_ethtool_cmd_to_string, guint32,
NM_UTILS_ENUM2STR (ETHTOOL_GFEATURES, "ETHTOOL_GFEATURES"),
NM_UTILS_ENUM2STR (ETHTOOL_GLINK, "ETHTOOL_GLINK"),
NM_UTILS_ENUM2STR (ETHTOOL_GPERMADDR, "ETHTOOL_GPERMADDR"),
+ NM_UTILS_ENUM2STR (ETHTOOL_GRINGPARAM, "ETHTOOL_GRINGPARAM"),
NM_UTILS_ENUM2STR (ETHTOOL_GSET, "ETHTOOL_GSET"),
NM_UTILS_ENUM2STR (ETHTOOL_GSSET_INFO, "ETHTOOL_GSSET_INFO"),
NM_UTILS_ENUM2STR (ETHTOOL_GSTATS, "ETHTOOL_GSTATS"),
@@ -276,6 +277,7 @@ NM_UTILS_ENUM2STR_DEFINE (_ethtool_cmd_to_string, guint32,
NM_UTILS_ENUM2STR (ETHTOOL_GWOL, "ETHTOOL_GWOL"),
NM_UTILS_ENUM2STR (ETHTOOL_SCOALESCE, "ETHTOOL_SCOALESCE"),
NM_UTILS_ENUM2STR (ETHTOOL_SFEATURES, "ETHTOOL_SFEATURES"),
+ NM_UTILS_ENUM2STR (ETHTOOL_SRINGPARAM, "ETHTOOL_SRINGPARAM"),
NM_UTILS_ENUM2STR (ETHTOOL_SSET, "ETHTOOL_SSET"),
NM_UTILS_ENUM2STR (ETHTOOL_SWOL, "ETHTOOL_SWOL"),
);
@@ -931,6 +933,95 @@ nmp_utils_ethtool_set_coalesce (int ifindex,
return TRUE;
}
+static gboolean
+ethtool_get_ring (SocketHandle *shandle,
+ NMEthtoolRingState *ring)
+{
+ struct ethtool_ringparam eth_data;
+
+ eth_data.cmd = ETHTOOL_GRINGPARAM;
+
+ if (_ethtool_call_handle (shandle,
+ &eth_data,
+ sizeof (struct ethtool_ringparam)) != 0)
+ return FALSE;
+
+ ring->rx_pending = eth_data.rx_pending;
+ ring->rx_jumbo_pending = eth_data.rx_jumbo_pending;
+ ring->rx_mini_pending = eth_data.rx_mini_pending;
+ ring->tx_pending = eth_data.tx_pending;
+
+ return TRUE;
+}
+
+gboolean
+nmp_utils_ethtool_get_ring (int ifindex,
+ NMEthtoolRingState *ring)
+{
+ nm_auto_socket_handle SocketHandle shandle = SOCKET_HANDLE_INIT (ifindex);
+
+ g_return_val_if_fail (ifindex > 0, FALSE);
+ g_return_val_if_fail (ring, FALSE);
+
+ if (!ethtool_get_ring (&shandle, ring)) {
+ nm_log_trace (LOGD_PLATFORM, "ethtool[%d]: %s: failure getting ring settings",
+ ifindex,
+ "get-ring");
+ return FALSE;
+ }
+
+ nm_log_trace (LOGD_PLATFORM, "ethtool[%d]: %s: retrieved kernel ring settings",
+ ifindex,
+ "get-ring");
+ return TRUE;
+}
+
+static gboolean
+ethtool_set_ring (SocketHandle *shandle,
+ const NMEthtoolRingState *ring)
+{
+ gboolean success;
+ struct ethtool_ringparam eth_data;
+
+ g_return_val_if_fail (shandle, FALSE);
+ g_return_val_if_fail (ring, FALSE);
+
+ eth_data = (struct ethtool_ringparam) {
+ .cmd = ETHTOOL_SRINGPARAM,
+ .rx_pending = ring->rx_pending,
+ .rx_jumbo_pending = ring->rx_jumbo_pending,
+ .rx_mini_pending = ring->rx_mini_pending,
+ .tx_pending = ring->tx_pending,
+ };
+
+ success = (_ethtool_call_handle (shandle,
+ &eth_data,
+ sizeof (struct ethtool_ringparam)) == 0);
+ return success;
+}
+
+gboolean
+nmp_utils_ethtool_set_ring (int ifindex,
+ const NMEthtoolRingState *ring)
+{
+ nm_auto_socket_handle SocketHandle shandle = SOCKET_HANDLE_INIT (ifindex);
+
+ g_return_val_if_fail (ifindex > 0, FALSE);
+ g_return_val_if_fail (ring, FALSE);
+
+ if (!ethtool_set_ring (&shandle, ring)) {
+ nm_log_trace (LOGD_PLATFORM, "ethtool[%d]: %s: failure setting ring settings",
+ ifindex,
+ "set-ring");
+ return FALSE;
+ }
+
+ nm_log_trace (LOGD_PLATFORM, "ethtool[%d]: %s: set kernel ring settings",
+ ifindex,
+ "set-ring");
+ return TRUE;
+}
+
/*****************************************************************************/
gboolean
diff --git a/src/platform/nm-platform-utils.h b/src/platform/nm-platform-utils.h
index b511c12cc6..242b97f168 100644
--- a/src/platform/nm-platform-utils.h
+++ b/src/platform/nm-platform-utils.h
@@ -123,6 +123,19 @@ gboolean nmp_utils_ethtool_get_coalesce (int ifindex,
gboolean nmp_utils_ethtool_set_coalesce (int ifindex,
const NMEthtoolCoalesceState *coalesce);
+struct _NMEthtoolRingState {
+ guint32 rx_pending;
+ guint32 rx_mini_pending;
+ guint32 rx_jumbo_pending;
+ guint32 tx_pending;
+};
+
+gboolean nmp_utils_ethtool_get_ring (int ifindex,
+ NMEthtoolRingState *ring);
+
+gboolean nmp_utils_ethtool_set_ring (int ifindex,
+ const NMEthtoolRingState *ring);
+
/*****************************************************************************/
gboolean nmp_utils_mii_supports_carrier_detect (int ifindex);
diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c
index 03ca152fa8..596f08542e 100644
--- a/src/platform/nm-platform.c
+++ b/src/platform/nm-platform.c
@@ -3240,8 +3240,7 @@ nm_platform_ethtool_init_coalesce (NMPlatform *self,
ethtool_id = nm_ethtool_id_get_by_name (option_name);
- if (!nm_ethtool_id_is_coalesce (ethtool_id))
- return FALSE;
+ g_return_val_if_fail (nm_ethtool_id_is_coalesce (ethtool_id), FALSE);
switch (ethtool_id) {
case NM_ETHTOOL_ID_COALESCE_ADAPTIVE_RX:
@@ -3329,6 +3328,66 @@ nm_platform_ethtool_set_coalesce (NMPlatform *self,
return nmp_utils_ethtool_set_coalesce (ifindex, coalesce);
}
+gboolean
+nm_platform_ethtool_get_link_ring (NMPlatform *self,
+ int ifindex,
+ NMEthtoolRingState *ring)
+{
+ _CHECK_SELF_NETNS (self, klass, netns, FALSE);
+
+ g_return_val_if_fail (ifindex > 0, FALSE);
+ g_return_val_if_fail (ring, FALSE);
+
+ return nmp_utils_ethtool_get_ring (ifindex, ring);
+}
+
+gboolean
+nm_platform_ethtool_init_ring (NMPlatform *self,
+ NMEthtoolRingState *ring,
+ const char *option_name,
+ guint32 value)
+{
+ NMEthtoolID ethtool_id;
+
+ g_return_val_if_fail (ring, FALSE);
+ g_return_val_if_fail (option_name, FALSE);
+
+ ethtool_id = nm_ethtool_id_get_by_name (option_name);
+
+ g_return_val_if_fail (nm_ethtool_id_is_ring (ethtool_id), FALSE);
+
+ switch (ethtool_id) {
+ case NM_ETHTOOL_ID_RING_RX:
+ ring->rx_pending = value;
+ break;
+ case NM_ETHTOOL_ID_RING_RX_JUMBO:
+ ring->rx_jumbo_pending = value;
+ break;
+ case NM_ETHTOOL_ID_RING_RX_MINI:
+ ring->rx_mini_pending = value;
+ break;
+ case NM_ETHTOOL_ID_RING_TX:
+ ring->tx_pending = value;
+ break;
+ default:
+ g_return_val_if_reached (FALSE);
+ }
+
+ return TRUE;
+}
+
+gboolean
+nm_platform_ethtool_set_ring (NMPlatform *self,
+ int ifindex,
+ const NMEthtoolRingState *ring)
+{
+ _CHECK_SELF_NETNS (self, klass, netns, FALSE);
+
+ g_return_val_if_fail (ifindex > 0, FALSE);
+
+ return nmp_utils_ethtool_set_ring (ifindex, ring);
+}
+
/*****************************************************************************/
const NMDedupMultiHeadEntry *
diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h
index 87571dd180..8957de429c 100644
--- a/src/platform/nm-platform.h
+++ b/src/platform/nm-platform.h
@@ -1969,6 +1969,21 @@ gboolean nm_platform_ethtool_set_coalesce (NMPlatform *self,
int ifindex,
const NMEthtoolCoalesceState *coalesce);
+typedef struct _NMEthtoolRingState NMEthtoolRingState;
+
+gboolean nm_platform_ethtool_get_link_ring (NMPlatform *self,
+ int ifindex,
+ NMEthtoolRingState *ring);
+
+gboolean nm_platform_ethtool_init_ring (NMPlatform *self,
+ NMEthtoolRingState *ring,
+ const char *option_name,
+ guint32 value);
+
+gboolean nm_platform_ethtool_set_ring (NMPlatform *self,
+ int ifindex,
+ const NMEthtoolRingState *ring);
+
const char * nm_platform_link_duplex_type_to_string (NMPlatformLinkDuplexType duplex);
void nm_platform_ip4_dev_route_blacklist_set (NMPlatform *self,