xref: /linux/tools/testing/selftests/drivers/net/hds.py (revision e814f3fd16acfb7f9966773953de8f740a1e3202)
1#!/usr/bin/env python3
2# SPDX-License-Identifier: GPL-2.0
3
4import errno
5from lib.py import ksft_run, ksft_exit, ksft_eq, ksft_raises, KsftSkipEx
6from lib.py import EthtoolFamily, NlError
7from lib.py import NetDrvEnv
8
9def get_hds(cfg, netnl) -> None:
10    try:
11        rings = netnl.rings_get({'header': {'dev-index': cfg.ifindex}})
12    except NlError as e:
13        raise KsftSkipEx('ring-get not supported by device')
14    if 'tcp-data-split' not in rings:
15        raise KsftSkipEx('tcp-data-split not supported by device')
16
17def get_hds_thresh(cfg, netnl) -> None:
18    try:
19        rings = netnl.rings_get({'header': {'dev-index': cfg.ifindex}})
20    except NlError as e:
21        raise KsftSkipEx('ring-get not supported by device')
22    if 'hds-thresh' not in rings:
23        raise KsftSkipEx('hds-thresh not supported by device')
24
25def set_hds_enable(cfg, netnl) -> None:
26    try:
27        netnl.rings_set({'header': {'dev-index': cfg.ifindex}, 'tcp-data-split': 'enabled'})
28    except NlError as e:
29        if e.error == errno.EINVAL:
30            raise KsftSkipEx("disabling of HDS not supported by the device")
31        elif e.error == errno.EOPNOTSUPP:
32            raise KsftSkipEx("ring-set not supported by the device")
33    try:
34        rings = netnl.rings_get({'header': {'dev-index': cfg.ifindex}})
35    except NlError as e:
36        raise KsftSkipEx('ring-get not supported by device')
37    if 'tcp-data-split' not in rings:
38        raise KsftSkipEx('tcp-data-split not supported by device')
39
40    ksft_eq('enabled', rings['tcp-data-split'])
41
42def set_hds_disable(cfg, netnl) -> None:
43    try:
44        netnl.rings_set({'header': {'dev-index': cfg.ifindex}, 'tcp-data-split': 'disabled'})
45    except NlError as e:
46        if e.error == errno.EINVAL:
47            raise KsftSkipEx("disabling of HDS not supported by the device")
48        elif e.error == errno.EOPNOTSUPP:
49            raise KsftSkipEx("ring-set not supported by the device")
50    try:
51        rings = netnl.rings_get({'header': {'dev-index': cfg.ifindex}})
52    except NlError as e:
53        raise KsftSkipEx('ring-get not supported by device')
54    if 'tcp-data-split' not in rings:
55        raise KsftSkipEx('tcp-data-split not supported by device')
56
57    ksft_eq('disabled', rings['tcp-data-split'])
58
59def set_hds_thresh_zero(cfg, netnl) -> None:
60    try:
61        netnl.rings_set({'header': {'dev-index': cfg.ifindex}, 'hds-thresh': 0})
62    except NlError as e:
63        if e.error == errno.EINVAL:
64            raise KsftSkipEx("hds-thresh-set not supported by the device")
65        elif e.error == errno.EOPNOTSUPP:
66            raise KsftSkipEx("ring-set not supported by the device")
67    try:
68        rings = netnl.rings_get({'header': {'dev-index': cfg.ifindex}})
69    except NlError as e:
70        raise KsftSkipEx('ring-get not supported by device')
71    if 'hds-thresh' not in rings:
72        raise KsftSkipEx('hds-thresh not supported by device')
73
74    ksft_eq(0, rings['hds-thresh'])
75
76def set_hds_thresh_max(cfg, netnl) -> None:
77    try:
78        rings = netnl.rings_get({'header': {'dev-index': cfg.ifindex}})
79    except NlError as e:
80        raise KsftSkipEx('ring-get not supported by device')
81    if 'hds-thresh' not in rings:
82        raise KsftSkipEx('hds-thresh not supported by device')
83    try:
84        netnl.rings_set({'header': {'dev-index': cfg.ifindex}, 'hds-thresh': rings['hds-thresh-max']})
85    except NlError as e:
86        if e.error == errno.EINVAL:
87            raise KsftSkipEx("hds-thresh-set not supported by the device")
88        elif e.error == errno.EOPNOTSUPP:
89            raise KsftSkipEx("ring-set not supported by the device")
90    rings = netnl.rings_get({'header': {'dev-index': cfg.ifindex}})
91    ksft_eq(rings['hds-thresh'], rings['hds-thresh-max'])
92
93def set_hds_thresh_gt(cfg, netnl) -> None:
94    try:
95        rings = netnl.rings_get({'header': {'dev-index': cfg.ifindex}})
96    except NlError as e:
97        raise KsftSkipEx('ring-get not supported by device')
98    if 'hds-thresh' not in rings:
99        raise KsftSkipEx('hds-thresh not supported by device')
100    if 'hds-thresh-max' not in rings:
101        raise KsftSkipEx('hds-thresh-max not defined by device')
102    hds_gt = rings['hds-thresh-max'] + 1
103    with ksft_raises(NlError) as e:
104        netnl.rings_set({'header': {'dev-index': cfg.ifindex}, 'hds-thresh': hds_gt})
105    ksft_eq(e.exception.nl_msg.error, -errno.EINVAL)
106
107def main() -> None:
108    with NetDrvEnv(__file__, queue_count=3) as cfg:
109        ksft_run([get_hds,
110                  get_hds_thresh,
111                  set_hds_disable,
112                  set_hds_enable,
113                  set_hds_thresh_zero,
114                  set_hds_thresh_max,
115                  set_hds_thresh_gt],
116                 args=(cfg, EthtoolFamily()))
117    ksft_exit()
118
119if __name__ == "__main__":
120    main()
121