2025-02-14 16:09:46 -08:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
|
|
|
|
|
|
import re
|
|
|
|
from os import path
|
2025-07-10 09:53:37 -07:00
|
|
|
from lib.py import ksft_run, ksft_exit, KsftSkipEx
|
2025-02-14 16:09:46 -08:00
|
|
|
from lib.py import NetDrvEpEnv
|
2025-04-26 12:55:24 -07:00
|
|
|
from lib.py import bkg, cmd, defer, ethtool, rand_port, wait_port_listen
|
2025-02-14 16:09:46 -08:00
|
|
|
|
|
|
|
|
2025-04-24 19:20:48 -07:00
|
|
|
def _get_current_settings(cfg):
|
2025-07-10 09:53:37 -07:00
|
|
|
output = ethtool(f"-g {cfg.ifname}", json=True)[0]
|
2025-04-26 12:55:25 -07:00
|
|
|
return (output['rx'], output['hds-thresh'])
|
2025-02-14 16:09:46 -08:00
|
|
|
|
|
|
|
|
|
|
|
def _get_combined_channels(cfg):
|
2025-07-10 09:53:37 -07:00
|
|
|
output = ethtool(f"-l {cfg.ifname}").stdout
|
2025-02-14 16:09:46 -08:00
|
|
|
values = re.findall(r'Combined:\s+(\d+)', output)
|
|
|
|
return int(values[1])
|
|
|
|
|
|
|
|
|
2025-05-02 21:30:07 -07:00
|
|
|
def _create_rss_ctx(cfg, chan):
|
2025-07-10 09:53:37 -07:00
|
|
|
output = ethtool(f"-X {cfg.ifname} context new start {chan} equal 1").stdout
|
2025-04-24 19:20:49 -07:00
|
|
|
values = re.search(r'New RSS context is (\d+)', output).group(1)
|
|
|
|
ctx_id = int(values)
|
2025-07-10 09:53:37 -07:00
|
|
|
return (ctx_id, defer(ethtool, f"-X {cfg.ifname} delete context {ctx_id}"))
|
2025-04-24 19:20:49 -07:00
|
|
|
|
|
|
|
|
2025-04-26 12:55:24 -07:00
|
|
|
def _set_flow_rule(cfg, port, chan):
|
2025-07-10 09:53:37 -07:00
|
|
|
output = ethtool(f"-N {cfg.ifname} flow-type tcp6 dst-port {port} action {chan}").stdout
|
2025-02-14 16:09:46 -08:00
|
|
|
values = re.search(r'ID (\d+)', output).group(1)
|
|
|
|
return int(values)
|
|
|
|
|
|
|
|
|
2025-05-02 21:30:07 -07:00
|
|
|
def _set_flow_rule_rss(cfg, port, ctx_id):
|
2025-07-10 09:53:37 -07:00
|
|
|
output = ethtool(f"-N {cfg.ifname} flow-type tcp6 dst-port {port} context {ctx_id}").stdout
|
2025-04-24 19:20:49 -07:00
|
|
|
values = re.search(r'ID (\d+)', output).group(1)
|
|
|
|
return int(values)
|
|
|
|
|
|
|
|
|
2025-02-14 16:09:46 -08:00
|
|
|
def test_zcrx(cfg) -> None:
|
2025-04-02 10:24:14 -07:00
|
|
|
cfg.require_ipver('6')
|
2025-02-14 16:09:46 -08:00
|
|
|
|
|
|
|
combined_chans = _get_combined_channels(cfg)
|
|
|
|
if combined_chans < 2:
|
|
|
|
raise KsftSkipEx('at least 2 combined channels required')
|
2025-04-24 19:20:48 -07:00
|
|
|
(rx_ring, hds_thresh) = _get_current_settings(cfg)
|
2025-04-26 12:55:24 -07:00
|
|
|
port = rand_port()
|
2025-02-23 20:13:19 -08:00
|
|
|
|
2025-07-10 09:53:37 -07:00
|
|
|
ethtool(f"-G {cfg.ifname} tcp-data-split on")
|
|
|
|
defer(ethtool, f"-G {cfg.ifname} tcp-data-split auto")
|
2025-04-26 12:55:24 -07:00
|
|
|
|
2025-07-10 09:53:37 -07:00
|
|
|
ethtool(f"-G {cfg.ifname} hds-thresh 0")
|
|
|
|
defer(ethtool, f"-G {cfg.ifname} hds-thresh {hds_thresh}")
|
2025-04-26 12:55:24 -07:00
|
|
|
|
2025-07-10 09:53:37 -07:00
|
|
|
ethtool(f"-G {cfg.ifname} rx 64")
|
|
|
|
defer(ethtool, f"-G {cfg.ifname} rx {rx_ring}")
|
2025-04-26 12:55:24 -07:00
|
|
|
|
2025-07-10 09:53:37 -07:00
|
|
|
ethtool(f"-X {cfg.ifname} equal {combined_chans - 1}")
|
|
|
|
defer(ethtool, f"-X {cfg.ifname} default")
|
2025-04-26 12:55:24 -07:00
|
|
|
|
|
|
|
flow_rule_id = _set_flow_rule(cfg, port, combined_chans - 1)
|
2025-07-10 09:53:37 -07:00
|
|
|
defer(ethtool, f"-N {cfg.ifname} delete {flow_rule_id}")
|
2025-04-24 19:20:47 -07:00
|
|
|
|
2025-07-10 09:53:37 -07:00
|
|
|
rx_cmd = f"{cfg.bin_local} -s -p {port} -i {cfg.ifname} -q {combined_chans - 1}"
|
|
|
|
tx_cmd = f"{cfg.bin_remote} -c -h {cfg.addr_v['6']} -p {port} -l 12840"
|
|
|
|
with bkg(rx_cmd, exit_wait=True):
|
|
|
|
wait_port_listen(port, proto="tcp")
|
|
|
|
cmd(tx_cmd, host=cfg.remote)
|
2025-02-23 20:13:19 -08:00
|
|
|
|
|
|
|
|
|
|
|
def test_zcrx_oneshot(cfg) -> None:
|
2025-04-02 10:24:14 -07:00
|
|
|
cfg.require_ipver('6')
|
2025-02-23 20:13:19 -08:00
|
|
|
|
|
|
|
combined_chans = _get_combined_channels(cfg)
|
|
|
|
if combined_chans < 2:
|
|
|
|
raise KsftSkipEx('at least 2 combined channels required')
|
2025-04-24 19:20:48 -07:00
|
|
|
(rx_ring, hds_thresh) = _get_current_settings(cfg)
|
2025-04-26 12:55:24 -07:00
|
|
|
port = rand_port()
|
2025-02-14 16:09:46 -08:00
|
|
|
|
2025-07-10 09:53:37 -07:00
|
|
|
ethtool(f"-G {cfg.ifname} tcp-data-split on")
|
|
|
|
defer(ethtool, f"-G {cfg.ifname} tcp-data-split auto")
|
2025-04-26 12:55:24 -07:00
|
|
|
|
2025-07-10 09:53:37 -07:00
|
|
|
ethtool(f"-G {cfg.ifname} hds-thresh 0")
|
|
|
|
defer(ethtool, f"-G {cfg.ifname} hds-thresh {hds_thresh}")
|
2025-04-26 12:55:24 -07:00
|
|
|
|
2025-07-10 09:53:37 -07:00
|
|
|
ethtool(f"-G {cfg.ifname} rx 64")
|
|
|
|
defer(ethtool, f"-G {cfg.ifname} rx {rx_ring}")
|
2025-04-26 12:55:24 -07:00
|
|
|
|
2025-07-10 09:53:37 -07:00
|
|
|
ethtool(f"-X {cfg.ifname} equal {combined_chans - 1}")
|
|
|
|
defer(ethtool, f"-X {cfg.ifname} default")
|
2025-04-26 12:55:24 -07:00
|
|
|
|
|
|
|
flow_rule_id = _set_flow_rule(cfg, port, combined_chans - 1)
|
2025-07-10 09:53:37 -07:00
|
|
|
defer(ethtool, f"-N {cfg.ifname} delete {flow_rule_id}")
|
2025-04-24 19:20:47 -07:00
|
|
|
|
2025-07-10 09:53:37 -07:00
|
|
|
rx_cmd = f"{cfg.bin_local} -s -p {port} -i {cfg.ifname} -q {combined_chans - 1} -o 4"
|
|
|
|
tx_cmd = f"{cfg.bin_remote} -c -h {cfg.addr_v['6']} -p {port} -l 4096 -z 16384"
|
|
|
|
with bkg(rx_cmd, exit_wait=True):
|
|
|
|
wait_port_listen(port, proto="tcp")
|
|
|
|
cmd(tx_cmd, host=cfg.remote)
|
2025-02-14 16:09:46 -08:00
|
|
|
|
|
|
|
|
2025-04-24 19:20:49 -07:00
|
|
|
def test_zcrx_rss(cfg) -> None:
|
|
|
|
cfg.require_ipver('6')
|
|
|
|
|
|
|
|
combined_chans = _get_combined_channels(cfg)
|
|
|
|
if combined_chans < 2:
|
|
|
|
raise KsftSkipEx('at least 2 combined channels required')
|
|
|
|
(rx_ring, hds_thresh) = _get_current_settings(cfg)
|
2025-04-26 12:55:24 -07:00
|
|
|
port = rand_port()
|
2025-04-24 19:20:49 -07:00
|
|
|
|
2025-07-10 09:53:37 -07:00
|
|
|
ethtool(f"-G {cfg.ifname} tcp-data-split on")
|
|
|
|
defer(ethtool, f"-G {cfg.ifname} tcp-data-split auto")
|
2025-04-26 12:55:24 -07:00
|
|
|
|
2025-07-10 09:53:37 -07:00
|
|
|
ethtool(f"-G {cfg.ifname} hds-thresh 0")
|
|
|
|
defer(ethtool, f"-G {cfg.ifname} hds-thresh {hds_thresh}")
|
2025-04-26 12:55:24 -07:00
|
|
|
|
2025-07-10 09:53:37 -07:00
|
|
|
ethtool(f"-G {cfg.ifname} rx 64")
|
|
|
|
defer(ethtool, f"-G {cfg.ifname} rx {rx_ring}")
|
2025-04-26 12:55:24 -07:00
|
|
|
|
2025-07-10 09:53:37 -07:00
|
|
|
ethtool(f"-X {cfg.ifname} equal {combined_chans - 1}")
|
|
|
|
defer(ethtool, f"-X {cfg.ifname} default")
|
2025-04-24 19:20:49 -07:00
|
|
|
|
2025-05-02 21:30:07 -07:00
|
|
|
(ctx_id, delete_ctx) = _create_rss_ctx(cfg, combined_chans - 1)
|
2025-04-26 12:55:24 -07:00
|
|
|
flow_rule_id = _set_flow_rule_rss(cfg, port, ctx_id)
|
2025-07-10 09:53:37 -07:00
|
|
|
defer(ethtool, f"-N {cfg.ifname} delete {flow_rule_id}")
|
2025-04-24 19:20:49 -07:00
|
|
|
|
2025-07-10 09:53:37 -07:00
|
|
|
rx_cmd = f"{cfg.bin_local} -s -p {port} -i {cfg.ifname} -q {combined_chans - 1}"
|
|
|
|
tx_cmd = f"{cfg.bin_remote} -c -h {cfg.addr_v['6']} -p {port} -l 12840"
|
|
|
|
with bkg(rx_cmd, exit_wait=True):
|
|
|
|
wait_port_listen(port, proto="tcp")
|
|
|
|
cmd(tx_cmd, host=cfg.remote)
|
2025-04-24 19:20:49 -07:00
|
|
|
|
|
|
|
|
2025-02-14 16:09:46 -08:00
|
|
|
def main() -> None:
|
|
|
|
with NetDrvEpEnv(__file__) as cfg:
|
|
|
|
cfg.bin_local = path.abspath(path.dirname(__file__) + "/../../../drivers/net/hw/iou-zcrx")
|
|
|
|
cfg.bin_remote = cfg.remote.deploy(cfg.bin_local)
|
|
|
|
|
|
|
|
ksft_run(globs=globals(), case_pfx={"test_"}, args=(cfg, ))
|
|
|
|
ksft_exit()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|