1#!/usr/bin/env python3 2# SPDX-License-Identifier: GPL-2.0 3 4import re 5from os import path 6from lib.py import ksft_run, ksft_exit 7from lib.py import NetDrvEpEnv 8from lib.py import bkg, cmd, ethtool, wait_port_listen 9 10 11def _get_rx_ring_entries(cfg): 12 output = ethtool(f"-g {cfg.ifname}", host=cfg.remote).stdout 13 values = re.findall(r'RX:\s+(\d+)', output) 14 return int(values[1]) 15 16 17def _get_combined_channels(cfg): 18 output = ethtool(f"-l {cfg.ifname}", host=cfg.remote).stdout 19 values = re.findall(r'Combined:\s+(\d+)', output) 20 return int(values[1]) 21 22 23def _set_flow_rule(cfg, chan): 24 output = ethtool(f"-N {cfg.ifname} flow-type tcp6 dst-port 9999 action {chan}", host=cfg.remote).stdout 25 values = re.search(r'ID (\d+)', output).group(1) 26 return int(values) 27 28 29def test_zcrx(cfg) -> None: 30 cfg.require_ipver('6') 31 32 combined_chans = _get_combined_channels(cfg) 33 if combined_chans < 2: 34 raise KsftSkipEx('at least 2 combined channels required') 35 rx_ring = _get_rx_ring_entries(cfg) 36 37 try: 38 ethtool(f"-G {cfg.ifname} rx 64", host=cfg.remote) 39 ethtool(f"-X {cfg.ifname} equal {combined_chans - 1}", host=cfg.remote) 40 flow_rule_id = _set_flow_rule(cfg, combined_chans - 1) 41 42 rx_cmd = f"{cfg.bin_remote} -s -p 9999 -i {cfg.ifname} -q {combined_chans - 1}" 43 tx_cmd = f"{cfg.bin_local} -c -h {cfg.remote_addr_v['6']} -p 9999 -l 12840" 44 with bkg(rx_cmd, host=cfg.remote, exit_wait=True): 45 wait_port_listen(9999, proto="tcp", host=cfg.remote) 46 cmd(tx_cmd) 47 finally: 48 ethtool(f"-N {cfg.ifname} delete {flow_rule_id}", host=cfg.remote) 49 ethtool(f"-X {cfg.ifname} default", host=cfg.remote) 50 ethtool(f"-G {cfg.ifname} rx {rx_ring}", host=cfg.remote) 51 52 53def test_zcrx_oneshot(cfg) -> None: 54 cfg.require_ipver('6') 55 56 combined_chans = _get_combined_channels(cfg) 57 if combined_chans < 2: 58 raise KsftSkipEx('at least 2 combined channels required') 59 rx_ring = _get_rx_ring_entries(cfg) 60 61 try: 62 ethtool(f"-G {cfg.ifname} rx 64", host=cfg.remote) 63 ethtool(f"-X {cfg.ifname} equal {combined_chans - 1}", host=cfg.remote) 64 flow_rule_id = _set_flow_rule(cfg, combined_chans - 1) 65 66 rx_cmd = f"{cfg.bin_remote} -s -p 9999 -i {cfg.ifname} -q {combined_chans - 1} -o 4" 67 tx_cmd = f"{cfg.bin_local} -c -h {cfg.remote_addr_v['6']} -p 9999 -l 4096 -z 16384" 68 with bkg(rx_cmd, host=cfg.remote, exit_wait=True): 69 wait_port_listen(9999, proto="tcp", host=cfg.remote) 70 cmd(tx_cmd) 71 finally: 72 ethtool(f"-N {cfg.ifname} delete {flow_rule_id}", host=cfg.remote) 73 ethtool(f"-X {cfg.ifname} default", host=cfg.remote) 74 ethtool(f"-G {cfg.ifname} rx {rx_ring}", host=cfg.remote) 75 76 77def main() -> None: 78 with NetDrvEpEnv(__file__) as cfg: 79 cfg.bin_local = path.abspath(path.dirname(__file__) + "/../../../drivers/net/hw/iou-zcrx") 80 cfg.bin_remote = cfg.remote.deploy(cfg.bin_local) 81 82 ksft_run(globs=globals(), case_pfx={"test_"}, args=(cfg, )) 83 ksft_exit() 84 85 86if __name__ == "__main__": 87 main() 88