platform: support ethtool channels properties

Support setting the ethtool channels properties in platform via
ETHTOOL_GCHANNELS and ETHTOOL_SCHANNELS ioctls.
This commit is contained in:
Beniamino Galvani 2023-10-11 19:11:14 +02:00 committed by Íñigo Huguet
parent 80dd179ffd
commit c3e538e1cd
5 changed files with 107 additions and 4 deletions

View file

@ -1067,6 +1067,69 @@ nmp_utils_ethtool_set_ring(int ifindex, const NMEthtoolRingState *ring)
return TRUE;
}
gboolean
nmp_utils_ethtool_get_channels(int ifindex, NMEthtoolChannelsState *channels)
{
struct ethtool_channels eth_data;
g_return_val_if_fail(ifindex > 0, FALSE);
g_return_val_if_fail(channels, FALSE);
eth_data.cmd = ETHTOOL_GCHANNELS;
if (_ethtool_call_once(ifindex, &eth_data, sizeof(eth_data)) < 0) {
nm_log_trace(LOGD_PLATFORM,
"ethtool[%d]: %s: failure getting channels settings",
ifindex,
"get-channels");
return FALSE;
}
*channels = (NMEthtoolChannelsState){
.rx = eth_data.rx_count,
.tx = eth_data.tx_count,
.other = eth_data.other_count,
.combined = eth_data.combined_count,
};
nm_log_trace(LOGD_PLATFORM,
"ethtool[%d]: %s: retrieved kernel channels settings",
ifindex,
"get-channels");
return TRUE;
}
gboolean
nmp_utils_ethtool_set_channels(int ifindex, const NMEthtoolChannelsState *channels)
{
struct ethtool_channels eth_data;
g_return_val_if_fail(ifindex > 0, FALSE);
g_return_val_if_fail(channels, FALSE);
eth_data = (struct ethtool_channels){
.cmd = ETHTOOL_SCHANNELS,
.rx_count = channels->rx,
.tx_count = channels->tx,
.other_count = channels->other,
.combined_count = channels->combined,
};
if (_ethtool_call_once(ifindex, &eth_data, sizeof(eth_data)) < 0) {
nm_log_trace(LOGD_PLATFORM,
"ethtool[%d]: %s: failure setting channels settings",
ifindex,
"set-channels");
return FALSE;
}
nm_log_trace(LOGD_PLATFORM,
"ethtool[%d]: %s: set kernel channels settings",
ifindex,
"set-channels");
return TRUE;
}
gboolean
nmp_utils_ethtool_get_pause(int ifindex, NMEthtoolPauseState *pause)
{

View file

@ -54,6 +54,10 @@ gboolean nmp_utils_ethtool_get_ring(int ifindex, NMEthtoolRingState *ring);
gboolean nmp_utils_ethtool_set_ring(int ifindex, const NMEthtoolRingState *ring);
gboolean nmp_utils_ethtool_get_channels(int ifindex, NMEthtoolChannelsState *channels);
gboolean nmp_utils_ethtool_set_channels(int ifindex, const NMEthtoolChannelsState *channels);
gboolean nmp_utils_ethtool_get_pause(int ifindex, NMEthtoolPauseState *pause);
gboolean nmp_utils_ethtool_set_pause(int ifindex, const NMEthtoolPauseState *pause);

View file

@ -3580,6 +3580,31 @@ nm_platform_ethtool_set_ring(NMPlatform *self, int ifindex, const NMEthtoolRingS
return nmp_utils_ethtool_set_ring(ifindex, ring);
}
gboolean
nm_platform_ethtool_get_link_channels(NMPlatform *self,
int ifindex,
NMEthtoolChannelsState *channels)
{
_CHECK_SELF_NETNS(self, klass, netns, FALSE);
g_return_val_if_fail(ifindex > 0, FALSE);
g_return_val_if_fail(channels, FALSE);
return nmp_utils_ethtool_get_channels(ifindex, channels);
}
gboolean
nm_platform_ethtool_set_channels(NMPlatform *self,
int ifindex,
const NMEthtoolChannelsState *channels)
{
_CHECK_SELF_NETNS(self, klass, netns, FALSE);
g_return_val_if_fail(ifindex > 0, FALSE);
return nmp_utils_ethtool_set_channels(ifindex, channels);
}
gboolean
nm_platform_ethtool_get_link_pause(NMPlatform *self, int ifindex, NMEthtoolPauseState *pause)
{

View file

@ -2567,6 +2567,14 @@ gboolean nm_platform_ethtool_get_link_ring(NMPlatform *self, int ifindex, NMEtht
gboolean
nm_platform_ethtool_set_ring(NMPlatform *self, int ifindex, const NMEthtoolRingState *ring);
gboolean nm_platform_ethtool_get_link_channels(NMPlatform *self,
int ifindex,
NMEthtoolChannelsState *channels);
gboolean nm_platform_ethtool_set_channels(NMPlatform *self,
int ifindex,
const NMEthtoolChannelsState *channels);
gboolean
nm_platform_ethtool_get_link_pause(NMPlatform *self, int ifindex, NMEthtoolPauseState *pause);

View file

@ -93,16 +93,12 @@ typedef struct {
const NMEthtoolFeatureState states_list[];
} NMEthtoolFeatureStates;
/*****************************************************************************/
typedef struct {
guint32
s[_NM_ETHTOOL_ID_COALESCE_NUM /* indexed by (NMEthtoolID - _NM_ETHTOOL_ID_COALESCE_FIRST) */
];
} NMEthtoolCoalesceState;
/*****************************************************************************/
typedef struct {
guint32 rx_pending;
guint32 rx_mini_pending;
@ -116,6 +112,13 @@ typedef struct {
bool tx : 1;
} NMEthtoolPauseState;
typedef struct {
guint32 rx;
guint32 tx;
guint32 other;
guint32 combined;
} NMEthtoolChannelsState;
/*****************************************************************************/
typedef struct _NMPNetns NMPNetns;