mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2026-04-08 12:02:33 +02:00
[ Upstream commit1cbddbddee] Some drivers, like tg3, do not set combined-count: $ ethtool -l enp4s0f1 Channel parameters for enp4s0f1: Pre-set maximums: RX: 4 TX: 4 Other: n/a Combined: n/a Current hardware settings: RX: 4 TX: 1 Other: n/a Combined: n/a In the case where combined-count is not set, the ethtool netlink code in the kernel elides the value and the code in the test: netnl.channels_get(...) With a tg3 device, the returned dictionary looks like: {'header': {'dev-index': 3, 'dev-name': 'enp4s0f1'}, 'rx-max': 4, 'rx-count': 4, 'tx-max': 4, 'tx-count': 1} Note that the key 'combined-count' is missing. As a result of this missing key the test raises an exception: # Exception| if channels['combined-count'] == 0: # Exception| ~~~~~~~~^^^^^^^^^^^^^^^^^^ # Exception| KeyError: 'combined-count' Change the test to check if 'combined-count' is a key in the dictionary first and if not assume that this means the driver has separate RX and TX queues. With this change, the test now passes successfully on tg3 and mlx5 (which does have a 'combined-count'). Fixes:1cf2704242("net: selftest: add test for netdev netlink queue-get API") Signed-off-by: Joe Damato <jdamato@fastly.com> Reviewed-by: David Wei <dw@davidwei.uk> Link: https://patch.msgid.link/20250226181957.212189-1-jdamato@fastly.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
66 lines
1.8 KiB
Python
Executable File
66 lines
1.8 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
|
|
from lib.py import ksft_run, ksft_exit, ksft_eq, KsftSkipEx
|
|
from lib.py import EthtoolFamily, NetdevFamily
|
|
from lib.py import NetDrvEnv
|
|
from lib.py import cmd
|
|
import glob
|
|
|
|
|
|
def sys_get_queues(ifname) -> int:
|
|
folders = glob.glob(f'/sys/class/net/{ifname}/queues/rx-*')
|
|
return len(folders)
|
|
|
|
|
|
def nl_get_queues(cfg, nl):
|
|
queues = nl.queue_get({'ifindex': cfg.ifindex}, dump=True)
|
|
if queues:
|
|
return len([q for q in queues if q['type'] == 'rx'])
|
|
return None
|
|
|
|
|
|
def get_queues(cfg, nl) -> None:
|
|
queues = nl_get_queues(cfg, nl)
|
|
if not queues:
|
|
raise KsftSkipEx('queue-get not supported by device')
|
|
|
|
expected = sys_get_queues(cfg.dev['ifname'])
|
|
ksft_eq(queues, expected)
|
|
|
|
|
|
def addremove_queues(cfg, nl) -> None:
|
|
queues = nl_get_queues(cfg, nl)
|
|
if not queues:
|
|
raise KsftSkipEx('queue-get not supported by device')
|
|
|
|
curr_queues = sys_get_queues(cfg.dev['ifname'])
|
|
if curr_queues == 1:
|
|
raise KsftSkipEx('cannot decrement queue: already at 1')
|
|
|
|
netnl = EthtoolFamily()
|
|
channels = netnl.channels_get({'header': {'dev-index': cfg.ifindex}})
|
|
rx_type = 'rx'
|
|
if channels.get('combined-count', 0) > 0:
|
|
rx_type = 'combined'
|
|
|
|
expected = curr_queues - 1
|
|
cmd(f"ethtool -L {cfg.dev['ifname']} {rx_type} {expected}", timeout=10)
|
|
queues = nl_get_queues(cfg, nl)
|
|
ksft_eq(queues, expected)
|
|
|
|
expected = curr_queues
|
|
cmd(f"ethtool -L {cfg.dev['ifname']} {rx_type} {expected}", timeout=10)
|
|
queues = nl_get_queues(cfg, nl)
|
|
ksft_eq(queues, expected)
|
|
|
|
|
|
def main() -> None:
|
|
with NetDrvEnv(__file__, queue_count=3) as cfg:
|
|
ksft_run([get_queues, addremove_queues], args=(cfg, NetdevFamily()))
|
|
ksft_exit()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|