2024-05-07 09:32:28 -07:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
|
|
|
2024-12-18 19:28:33 -08:00
|
|
|
from lib.py import ksft_disruptive, ksft_exit, ksft_run
|
2025-02-19 15:49:55 -08:00
|
|
|
from lib.py import ksft_eq, ksft_not_in, ksft_raises, KsftSkipEx, KsftFailEx
|
2024-12-18 19:28:33 -08:00
|
|
|
from lib.py import EthtoolFamily, NetdevFamily, NlError
|
2024-05-07 09:32:28 -07:00
|
|
|
from lib.py import NetDrvEnv
|
2025-02-19 15:49:54 -08:00
|
|
|
from lib.py import bkg, cmd, defer, ip
|
2024-12-18 19:28:33 -08:00
|
|
|
import errno
|
2024-05-07 09:32:28 -07:00
|
|
|
import glob
|
2025-02-14 21:12:31 +00:00
|
|
|
import os
|
|
|
|
import socket
|
|
|
|
import struct
|
2024-05-07 09:32:28 -07:00
|
|
|
|
2024-12-13 07:22:43 -08:00
|
|
|
def sys_get_queues(ifname, qtype='rx') -> int:
|
|
|
|
folders = glob.glob(f'/sys/class/net/{ifname}/queues/{qtype}-*')
|
2024-05-07 09:32:28 -07:00
|
|
|
return len(folders)
|
|
|
|
|
|
|
|
|
2024-12-13 07:22:43 -08:00
|
|
|
def nl_get_queues(cfg, nl, qtype='rx'):
|
2024-05-07 09:32:28 -07:00
|
|
|
queues = nl.queue_get({'ifindex': cfg.ifindex}, dump=True)
|
|
|
|
if queues:
|
2024-12-13 07:22:43 -08:00
|
|
|
return len([q for q in queues if q['type'] == qtype])
|
2024-05-07 09:32:28 -07:00
|
|
|
return None
|
|
|
|
|
2025-02-19 15:49:56 -08:00
|
|
|
|
|
|
|
def check_xsk(cfg, nl, xdp_queue_id=0) -> None:
|
2025-02-19 15:49:53 -08:00
|
|
|
# Probe for support
|
2025-04-25 14:10:15 +07:00
|
|
|
xdp = cmd(f'{cfg.net_lib_dir / "xdp_helper"} - -', fail=False)
|
2025-02-19 15:49:53 -08:00
|
|
|
if xdp.ret == 255:
|
|
|
|
raise KsftSkipEx('AF_XDP unsupported')
|
|
|
|
elif xdp.ret > 0:
|
|
|
|
raise KsftFailEx('unable to create AF_XDP socket')
|
|
|
|
|
2025-04-25 14:10:15 +07:00
|
|
|
with bkg(f'{cfg.net_lib_dir / "xdp_helper"} {cfg.ifindex} {xdp_queue_id}',
|
2025-02-19 15:49:54 -08:00
|
|
|
ksft_wait=3):
|
2025-02-14 21:12:31 +00:00
|
|
|
|
2025-02-19 15:49:54 -08:00
|
|
|
rx = tx = False
|
|
|
|
|
|
|
|
queues = nl.queue_get({'ifindex': cfg.ifindex}, dump=True)
|
|
|
|
if not queues:
|
|
|
|
raise KsftSkipEx("Netlink reports no queues")
|
|
|
|
|
|
|
|
for q in queues:
|
|
|
|
if q['id'] == 0:
|
|
|
|
if q['type'] == 'rx':
|
|
|
|
rx = True
|
|
|
|
if q['type'] == 'tx':
|
|
|
|
tx = True
|
|
|
|
|
2025-02-19 15:49:55 -08:00
|
|
|
ksft_eq(q.get('xsk', None), {},
|
|
|
|
comment="xsk attr on queue we configured")
|
2025-02-19 15:49:54 -08:00
|
|
|
else:
|
2025-02-19 15:49:55 -08:00
|
|
|
ksft_not_in('xsk', q,
|
|
|
|
comment="xsk attr on queue we didn't configure")
|
2025-02-19 15:49:54 -08:00
|
|
|
|
|
|
|
ksft_eq(rx, True)
|
|
|
|
ksft_eq(tx, True)
|
2025-02-14 21:12:31 +00:00
|
|
|
|
2024-05-07 09:32:28 -07:00
|
|
|
|
|
|
|
def get_queues(cfg, nl) -> None:
|
2024-12-13 07:22:43 -08:00
|
|
|
snl = NetdevFamily(recv_size=4096)
|
2024-05-07 09:32:28 -07:00
|
|
|
|
2024-12-13 07:22:43 -08:00
|
|
|
for qtype in ['rx', 'tx']:
|
|
|
|
queues = nl_get_queues(cfg, snl, qtype)
|
|
|
|
if not queues:
|
|
|
|
raise KsftSkipEx('queue-get not supported by device')
|
|
|
|
|
|
|
|
expected = sys_get_queues(cfg.dev['ifname'], qtype)
|
|
|
|
ksft_eq(queues, expected)
|
2024-05-07 09:32:28 -07:00
|
|
|
|
|
|
|
|
|
|
|
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}})
|
selftests: drv-net: Check if combined-count exists
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: 1cf270424218 ("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>
2025-02-26 18:19:57 +00:00
|
|
|
rx_type = 'rx'
|
|
|
|
if channels.get('combined-count', 0) > 0:
|
|
|
|
rx_type = 'combined'
|
2024-05-07 09:32:28 -07:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
2024-12-18 19:28:33 -08:00
|
|
|
@ksft_disruptive
|
|
|
|
def check_down(cfg, nl) -> None:
|
|
|
|
# Check the NAPI IDs before interface goes down and hides them
|
|
|
|
napis = nl.napi_get({'ifindex': cfg.ifindex}, dump=True)
|
|
|
|
|
|
|
|
ip(f"link set dev {cfg.dev['ifname']} down")
|
|
|
|
defer(ip, f"link set dev {cfg.dev['ifname']} up")
|
|
|
|
|
|
|
|
with ksft_raises(NlError) as cm:
|
|
|
|
nl.queue_get({'ifindex': cfg.ifindex, 'id': 0, 'type': 'rx'})
|
|
|
|
ksft_eq(cm.exception.nl_msg.error, -errno.ENOENT)
|
|
|
|
|
|
|
|
if napis:
|
|
|
|
with ksft_raises(NlError) as cm:
|
|
|
|
nl.napi_get({'id': napis[0]['id']})
|
|
|
|
ksft_eq(cm.exception.nl_msg.error, -errno.ENOENT)
|
|
|
|
|
|
|
|
|
2024-05-07 09:32:28 -07:00
|
|
|
def main() -> None:
|
2024-12-13 07:22:43 -08:00
|
|
|
with NetDrvEnv(__file__, queue_count=100) as cfg:
|
2025-02-19 15:49:56 -08:00
|
|
|
ksft_run([get_queues, addremove_queues, check_down, check_xsk],
|
|
|
|
args=(cfg, NetdevFamily()))
|
2024-05-07 09:32:28 -07:00
|
|
|
ksft_exit()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|