xref: /linux/tools/testing/selftests/drivers/net/hw/iou-zcrx.py (revision 85502b2214d50ba0ddf2a5fb454e4d28a160d175)
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, defer, ethtool, rand_port, wait_port_listen
9
10
11def _get_current_settings(cfg):
12    output = ethtool(f"-g {cfg.ifname}", json=True, host=cfg.remote)[0]
13    return (output['rx'], output['hds-thresh'])
14
15
16def _get_combined_channels(cfg):
17    output = ethtool(f"-l {cfg.ifname}", host=cfg.remote).stdout
18    values = re.findall(r'Combined:\s+(\d+)', output)
19    return int(values[1])
20
21
22def _create_rss_ctx(cfg, chan):
23    output = ethtool(f"-X {cfg.ifname} context new start {chan} equal 1", host=cfg.remote).stdout
24    values = re.search(r'New RSS context is (\d+)', output).group(1)
25    ctx_id = int(values)
26    return (ctx_id, defer(ethtool, f"-X {cfg.ifname} delete context {ctx_id}", host=cfg.remote))
27
28
29def _set_flow_rule(cfg, port, chan):
30    output = ethtool(f"-N {cfg.ifname} flow-type tcp6 dst-port {port} action {chan}", host=cfg.remote).stdout
31    values = re.search(r'ID (\d+)', output).group(1)
32    return int(values)
33
34
35def _set_flow_rule_rss(cfg, port, ctx_id):
36    output = ethtool(f"-N {cfg.ifname} flow-type tcp6 dst-port {port} context {ctx_id}", host=cfg.remote).stdout
37    values = re.search(r'ID (\d+)', output).group(1)
38    return int(values)
39
40
41def test_zcrx(cfg) -> None:
42    cfg.require_ipver('6')
43
44    combined_chans = _get_combined_channels(cfg)
45    if combined_chans < 2:
46        raise KsftSkipEx('at least 2 combined channels required')
47    (rx_ring, hds_thresh) = _get_current_settings(cfg)
48    port = rand_port()
49
50    ethtool(f"-G {cfg.ifname} tcp-data-split on", host=cfg.remote)
51    defer(ethtool, f"-G {cfg.ifname} tcp-data-split auto", host=cfg.remote)
52
53    ethtool(f"-G {cfg.ifname} hds-thresh 0", host=cfg.remote)
54    defer(ethtool, f"-G {cfg.ifname} hds-thresh {hds_thresh}", host=cfg.remote)
55
56    ethtool(f"-G {cfg.ifname} rx 64", host=cfg.remote)
57    defer(ethtool, f"-G {cfg.ifname} rx {rx_ring}", host=cfg.remote)
58
59    ethtool(f"-X {cfg.ifname} equal {combined_chans - 1}", host=cfg.remote)
60    defer(ethtool, f"-X {cfg.ifname} default", host=cfg.remote)
61
62    flow_rule_id = _set_flow_rule(cfg, port, combined_chans - 1)
63    defer(ethtool, f"-N {cfg.ifname} delete {flow_rule_id}", host=cfg.remote)
64
65    rx_cmd = f"{cfg.bin_remote} -s -p {port} -i {cfg.ifname} -q {combined_chans - 1}"
66    tx_cmd = f"{cfg.bin_local} -c -h {cfg.remote_addr_v['6']} -p {port} -l 12840"
67    with bkg(rx_cmd, host=cfg.remote, exit_wait=True):
68        wait_port_listen(port, proto="tcp", host=cfg.remote)
69        cmd(tx_cmd)
70
71
72def test_zcrx_oneshot(cfg) -> None:
73    cfg.require_ipver('6')
74
75    combined_chans = _get_combined_channels(cfg)
76    if combined_chans < 2:
77        raise KsftSkipEx('at least 2 combined channels required')
78    (rx_ring, hds_thresh) = _get_current_settings(cfg)
79    port = rand_port()
80
81    ethtool(f"-G {cfg.ifname} tcp-data-split on", host=cfg.remote)
82    defer(ethtool, f"-G {cfg.ifname} tcp-data-split auto", host=cfg.remote)
83
84    ethtool(f"-G {cfg.ifname} hds-thresh 0", host=cfg.remote)
85    defer(ethtool, f"-G {cfg.ifname} hds-thresh {hds_thresh}", host=cfg.remote)
86
87    ethtool(f"-G {cfg.ifname} rx 64", host=cfg.remote)
88    defer(ethtool, f"-G {cfg.ifname} rx {rx_ring}", host=cfg.remote)
89
90    ethtool(f"-X {cfg.ifname} equal {combined_chans - 1}", host=cfg.remote)
91    defer(ethtool, f"-X {cfg.ifname} default", host=cfg.remote)
92
93    flow_rule_id = _set_flow_rule(cfg, port, combined_chans - 1)
94    defer(ethtool, f"-N {cfg.ifname} delete {flow_rule_id}", host=cfg.remote)
95
96    rx_cmd = f"{cfg.bin_remote} -s -p {port} -i {cfg.ifname} -q {combined_chans - 1} -o 4"
97    tx_cmd = f"{cfg.bin_local} -c -h {cfg.remote_addr_v['6']} -p {port} -l 4096 -z 16384"
98    with bkg(rx_cmd, host=cfg.remote, exit_wait=True):
99        wait_port_listen(port, proto="tcp", host=cfg.remote)
100        cmd(tx_cmd)
101
102
103def test_zcrx_rss(cfg) -> None:
104    cfg.require_ipver('6')
105
106    combined_chans = _get_combined_channels(cfg)
107    if combined_chans < 2:
108        raise KsftSkipEx('at least 2 combined channels required')
109    (rx_ring, hds_thresh) = _get_current_settings(cfg)
110    port = rand_port()
111
112    ethtool(f"-G {cfg.ifname} tcp-data-split on", host=cfg.remote)
113    defer(ethtool, f"-G {cfg.ifname} tcp-data-split auto", host=cfg.remote)
114
115    ethtool(f"-G {cfg.ifname} hds-thresh 0", host=cfg.remote)
116    defer(ethtool, f"-G {cfg.ifname} hds-thresh {hds_thresh}", host=cfg.remote)
117
118    ethtool(f"-G {cfg.ifname} rx 64", host=cfg.remote)
119    defer(ethtool, f"-G {cfg.ifname} rx {rx_ring}", host=cfg.remote)
120
121    ethtool(f"-X {cfg.ifname} equal {combined_chans - 1}", host=cfg.remote)
122    defer(ethtool, f"-X {cfg.ifname} default", host=cfg.remote)
123
124    (ctx_id, delete_ctx) = _create_rss_ctx(cfg, combined_chans - 1)
125    flow_rule_id = _set_flow_rule_rss(cfg, port, ctx_id)
126    defer(ethtool, f"-N {cfg.ifname} delete {flow_rule_id}", host=cfg.remote)
127
128    rx_cmd = f"{cfg.bin_remote} -s -p {port} -i {cfg.ifname} -q {combined_chans - 1}"
129    tx_cmd = f"{cfg.bin_local} -c -h {cfg.remote_addr_v['6']} -p {port} -l 12840"
130    with bkg(rx_cmd, host=cfg.remote, exit_wait=True):
131        wait_port_listen(port, proto="tcp", host=cfg.remote)
132        cmd(tx_cmd)
133
134
135def main() -> None:
136    with NetDrvEpEnv(__file__) as cfg:
137        cfg.bin_local = path.abspath(path.dirname(__file__) + "/../../../drivers/net/hw/iou-zcrx")
138        cfg.bin_remote = cfg.remote.deploy(cfg.bin_local)
139
140        ksft_run(globs=globals(), case_pfx={"test_"}, args=(cfg, ))
141    ksft_exit()
142
143
144if __name__ == "__main__":
145    main()
146