platform: add support for ring settings using ioctl()

https://bugzilla.redhat.com/show_bug.cgi?id=1614700
This commit is contained in:
Antonio Cardace 2020-05-14 18:27:54 +02:00
parent 126995a4d8
commit 2d2c111304
No known key found for this signature in database
GPG key ID: 6BF80ABD43E377D3
4 changed files with 180 additions and 2 deletions

View file

@ -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

View file

@ -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);

View file

@ -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 *

View file

@ -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,