|
| 1 | +From 8b8282cacc9638522524a05448a5f44d24f00c22 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Aaron Chan <aaron.chun.yew.chan@intel.com> |
| 3 | +Date: Thu, 29 May 2025 11:55:58 +0800 |
| 4 | +Subject: [PATCH 2/5] ethtool: Add support for configuring frame |
| 5 | + preemptionethtool: Add support for configuring frame preemption |
| 6 | + |
| 7 | +The configuration knobs that can be set are: |
| 8 | + - enabling/disabling frame preemption per-device; |
| 9 | + - configuring the minimum fragment size; |
| 10 | + |
| 11 | +The values that can be retrieved from the hardware are: |
| 12 | + - if frame preemption is enabled; |
| 13 | + - the current minimum fragment size; |
| 14 | + |
| 15 | +Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com> |
| 16 | +--- |
| 17 | + Makefile.am | 1 + |
| 18 | + ethtool.8.in | 15 +++++ |
| 19 | + ethtool.c | 12 ++++ |
| 20 | + netlink/desc-ethtool.c | 9 +++ |
| 21 | + netlink/extapi.h | 4 ++ |
| 22 | + netlink/preempt.c | 137 +++++++++++++++++++++++++++++++++++++++++ |
| 23 | + 6 files changed, 178 insertions(+) |
| 24 | + create mode 100644 netlink/preempt.c |
| 25 | + |
| 26 | +diff --git a/Makefile.am b/Makefile.am |
| 27 | +index 3879138..a92181c 100644 |
| 28 | +--- a/Makefile.am |
| 29 | ++++ b/Makefile.am |
| 30 | +@@ -42,6 +42,7 @@ ethtool_SOURCES += \ |
| 31 | + netlink/desc-ethtool.c netlink/desc-genlctrl.c \ |
| 32 | + netlink/module-eeprom.c netlink/module.c netlink/rss.c \ |
| 33 | + netlink/desc-rtnl.c netlink/cable_test.c netlink/tunnels.c \ |
| 34 | ++ netlink/preempt.c \ |
| 35 | + netlink/plca.c \ |
| 36 | + netlink/pse-pd.c \ |
| 37 | + uapi/linux/ethtool_netlink.h \ |
| 38 | +diff --git a/ethtool.8.in b/ethtool.8.in |
| 39 | +index adf8900..0fad822 100644 |
| 40 | +--- a/ethtool.8.in |
| 41 | ++++ b/ethtool.8.in |
| 42 | +@@ -1560,6 +1560,21 @@ shown. Default is to show notifications for all devices. |
| 43 | + Show tunnel-related device capabilities and state. |
| 44 | + List UDP ports kernel has programmed the device to parse as VxLAN, |
| 45 | + or GENEVE tunnels. |
| 46 | ++.TP |
| 47 | ++.B \-\-set\-frame\-preemption |
| 48 | ++Configures frame preemption support for the specified network device. |
| 49 | ++ |
| 50 | ++Frame preemption allows packets from higher priority queues, called |
| 51 | ++express queues, to interrupt (preempt) the transmission of packets |
| 52 | ++from lower priority queues. |
| 53 | ++.RS 4 |
| 54 | ++.TP |
| 55 | ++.B fp\ [ on | off ] |
| 56 | ++Enables or disables frame preemption. |
| 57 | ++.TP |
| 58 | ++.B add\-frag\-size \ N |
| 59 | ++Size, in bytes, of minimum non-final fragments of preempted packets |
| 60 | ++supported by the receiver. |
| 61 | + .RE |
| 62 | + .TP |
| 63 | + .B \-\-show\-module |
| 64 | +diff --git a/ethtool.c b/ethtool.c |
| 65 | +index b7d173b..2324215 100644 |
| 66 | +--- a/ethtool.c |
| 67 | ++++ b/ethtool.c |
| 68 | +@@ -6043,6 +6043,18 @@ static const struct option args[] = { |
| 69 | + .help = "Set FEC settings", |
| 70 | + .xhelp = " [ encoding auto|off|rs|baser|llrs [...] ]\n" |
| 71 | + }, |
| 72 | ++ { |
| 73 | ++ .opts = "--show-frame-preemption", |
| 74 | ++ .nlfunc = nl_get_preempt, |
| 75 | ++ .help = "Show Frame Preemption settings", |
| 76 | ++ }, |
| 77 | ++ { |
| 78 | ++ .opts = "--set-frame-preemption", |
| 79 | ++ .nlfunc = nl_set_preempt, |
| 80 | ++ .help = "Set Frame Preemption settings", |
| 81 | ++ .xhelp = " [ fp on|off ]\n" |
| 82 | ++ " [ add-frag-size %d ]\n", |
| 83 | ++ }, |
| 84 | + { |
| 85 | + .opts = "-Q|--per-queue", |
| 86 | + .func = do_perqueue, |
| 87 | +diff --git a/netlink/desc-ethtool.c b/netlink/desc-ethtool.c |
| 88 | +index 661de26..8e92839 100644 |
| 89 | +--- a/netlink/desc-ethtool.c |
| 90 | ++++ b/netlink/desc-ethtool.c |
| 91 | +@@ -496,6 +496,13 @@ static const struct pretty_nla_desc __mm_desc[] = { |
| 92 | + NLATTR_DESC_NESTED(ETHTOOL_A_MM_STATS, mm_stat), |
| 93 | + }; |
| 94 | + |
| 95 | ++static const struct pretty_nla_desc __preempt_desc[] = { |
| 96 | ++ NLATTR_DESC_INVALID(ETHTOOL_A_PREEMPT_UNSPEC), |
| 97 | ++ NLATTR_DESC_NESTED(ETHTOOL_A_PREEMPT_HEADER, header), |
| 98 | ++ NLATTR_DESC_U8(ETHTOOL_A_PREEMPT_ENABLED), |
| 99 | ++ NLATTR_DESC_U32(ETHTOOL_A_PREEMPT_ADD_FRAG_SIZE), |
| 100 | ++}; |
| 101 | ++ |
| 102 | + const struct pretty_nlmsg_desc ethnl_umsg_desc[] = { |
| 103 | + NLMSG_DESC_INVALID(ETHTOOL_MSG_USER_NONE), |
| 104 | + NLMSG_DESC(ETHTOOL_MSG_STRSET_GET, strset), |
| 105 | +@@ -531,6 +538,8 @@ const struct pretty_nlmsg_desc ethnl_umsg_desc[] = { |
| 106 | + NLMSG_DESC(ETHTOOL_MSG_MODULE_EEPROM_GET, module_eeprom), |
| 107 | + NLMSG_DESC(ETHTOOL_MSG_STATS_GET, stats), |
| 108 | + NLMSG_DESC(ETHTOOL_MSG_PHC_VCLOCKS_GET, phc_vclocks), |
| 109 | ++ NLMSG_DESC(ETHTOOL_MSG_PREEMPT_GET, preempt), |
| 110 | ++ NLMSG_DESC(ETHTOOL_MSG_PREEMPT_SET, preempt), |
| 111 | + NLMSG_DESC(ETHTOOL_MSG_MODULE_GET, module), |
| 112 | + NLMSG_DESC(ETHTOOL_MSG_MODULE_SET, module), |
| 113 | + NLMSG_DESC(ETHTOOL_MSG_PSE_GET, pse), |
| 114 | +diff --git a/netlink/extapi.h b/netlink/extapi.h |
| 115 | +index e2d6b71..c7b3ebe 100644 |
| 116 | +--- a/netlink/extapi.h |
| 117 | ++++ b/netlink/extapi.h |
| 118 | +@@ -47,6 +47,8 @@ int nl_gmodule(struct cmd_context *ctx); |
| 119 | + int nl_smodule(struct cmd_context *ctx); |
| 120 | + int nl_monitor(struct cmd_context *ctx); |
| 121 | + int nl_getmodule(struct cmd_context *ctx); |
| 122 | ++int nl_get_preempt(struct cmd_context *ctx); |
| 123 | ++int nl_set_preempt(struct cmd_context *ctx); |
| 124 | + int nl_grss(struct cmd_context *ctx); |
| 125 | + int nl_plca_get_cfg(struct cmd_context *ctx); |
| 126 | + int nl_plca_set_cfg(struct cmd_context *ctx); |
| 127 | +@@ -120,6 +122,8 @@ nl_get_eeprom_page(struct cmd_context *ctx __maybe_unused, |
| 128 | + #define nl_gstats_chk NULL |
| 129 | + #define nl_gstats NULL |
| 130 | + #define nl_getmodule NULL |
| 131 | ++#define nl_get_preempt NULL |
| 132 | ++#define nl_set_preempt NULL |
| 133 | + #define nl_gmodule NULL |
| 134 | + #define nl_smodule NULL |
| 135 | + #define nl_grss NULL |
| 136 | +diff --git a/netlink/preempt.c b/netlink/preempt.c |
| 137 | +new file mode 100644 |
| 138 | +index 0000000..75d4cfc |
| 139 | +--- /dev/null |
| 140 | ++++ b/netlink/preempt.c |
| 141 | +@@ -0,0 +1,137 @@ |
| 142 | ++/* |
| 143 | ++ * preempt.c - netlink implementation of frame preemption settings |
| 144 | ++ * |
| 145 | ++ * Implementation of "ethtool --{show,set}-frame-preemption <dev>" |
| 146 | ++ */ |
| 147 | ++ |
| 148 | ++#include <errno.h> |
| 149 | ++#include <string.h> |
| 150 | ++#include <stdio.h> |
| 151 | ++#include <linux/rtnetlink.h> |
| 152 | ++#include <linux/if_link.h> |
| 153 | ++ |
| 154 | ++#include "../internal.h" |
| 155 | ++#include "../common.h" |
| 156 | ++#include "netlink.h" |
| 157 | ++#include "parser.h" |
| 158 | ++ |
| 159 | ++/* PREEMPT_GET */ |
| 160 | ++ |
| 161 | ++static int preempt_get_prep_request(struct nl_socket *nlsk) |
| 162 | ++{ |
| 163 | ++ int ret; |
| 164 | ++ |
| 165 | ++ ret = nlsock_prep_get_request(nlsk, ETHTOOL_MSG_PREEMPT_GET, |
| 166 | ++ ETHTOOL_A_PREEMPT_HEADER, 0); |
| 167 | ++ if (ret < 0) |
| 168 | ++ return ret; |
| 169 | ++ |
| 170 | ++ return 0; |
| 171 | ++} |
| 172 | ++ |
| 173 | ++int preempt_get_reply_cb(const struct nlmsghdr *nlhdr, void *data) |
| 174 | ++{ |
| 175 | ++ const struct nlattr *tb[ETHTOOL_A_PREEMPT_MAX + 1] = {}; |
| 176 | ++ DECLARE_ATTR_TB_INFO(tb); |
| 177 | ++ struct nl_context *nlctx = data; |
| 178 | ++ int ret; |
| 179 | ++ |
| 180 | ++ if (nlctx->is_dump || nlctx->is_monitor) |
| 181 | ++ nlctx->no_banner = false; |
| 182 | ++ |
| 183 | ++ ret = mnl_attr_parse(nlhdr, GENL_HDRLEN, attr_cb, &tb_info); |
| 184 | ++ if (ret < 0) |
| 185 | ++ return ret; |
| 186 | ++ |
| 187 | ++ nlctx->devname = get_dev_name(tb[ETHTOOL_A_PREEMPT_HEADER]); |
| 188 | ++ if (!dev_ok(nlctx)) |
| 189 | ++ return MNL_CB_OK; |
| 190 | ++ |
| 191 | ++ printf("Frame preemption settings for %s:\n", nlctx->devname); |
| 192 | ++ |
| 193 | ++ if (tb[ETHTOOL_A_PREEMPT_ENABLED]) { |
| 194 | ++ int enabled = mnl_attr_get_u8(tb[ETHTOOL_A_PREEMPT_ENABLED]); |
| 195 | ++ |
| 196 | ++ printf("\tenabled: %s\n", enabled ? "enabled" : "not enabled"); |
| 197 | ++ } |
| 198 | ++ if (tb[ETHTOOL_A_PREEMPT_ADD_FRAG_SIZE]) { |
| 199 | ++ uint32_t add_frag_size = mnl_attr_get_u32( |
| 200 | ++ tb[ETHTOOL_A_PREEMPT_ADD_FRAG_SIZE]); |
| 201 | ++ |
| 202 | ++ printf("\tadditional fragment size: %d\n", add_frag_size); |
| 203 | ++ } |
| 204 | ++ return MNL_CB_OK; |
| 205 | ++} |
| 206 | ++ |
| 207 | ++int nl_get_preempt(struct cmd_context *ctx) |
| 208 | ++{ |
| 209 | ++ struct nl_context *nlctx = ctx->nlctx; |
| 210 | ++ struct nl_socket *nlsk = nlctx->ethnl_socket; |
| 211 | ++ int ret; |
| 212 | ++ |
| 213 | ++ ret = preempt_get_prep_request(nlsk); |
| 214 | ++ if (ret < 0) |
| 215 | ++ return ret; |
| 216 | ++ return nlsock_send_get_request(nlsk, preempt_get_reply_cb); |
| 217 | ++} |
| 218 | ++ |
| 219 | ++static const struct lookup_entry_u8 fp_values[] = { |
| 220 | ++ { .arg = "off", .val = 0 }, |
| 221 | ++ { .arg = "on", .val = 1 }, |
| 222 | ++ {} |
| 223 | ++}; |
| 224 | ++ |
| 225 | ++static const struct param_parser set_preempt_params[] = { |
| 226 | ++ { |
| 227 | ++ .arg = "fp", |
| 228 | ++ .group = ETHTOOL_MSG_PREEMPT_SET, |
| 229 | ++ .type = ETHTOOL_A_PREEMPT_ENABLED, |
| 230 | ++ .handler = nl_parse_lookup_u8, |
| 231 | ++ .handler_data = fp_values, |
| 232 | ++ .min_argc = 1, |
| 233 | ++ }, |
| 234 | ++ { |
| 235 | ++ .arg = "add-frag-size", |
| 236 | ++ .group = ETHTOOL_MSG_PREEMPT_SET, |
| 237 | ++ .type = ETHTOOL_A_PREEMPT_ADD_FRAG_SIZE, |
| 238 | ++ .handler = nl_parse_direct_u32, |
| 239 | ++ .min_argc = 1, |
| 240 | ++ }, |
| 241 | ++ {} |
| 242 | ++}; |
| 243 | ++ |
| 244 | ++int nl_set_preempt(struct cmd_context *ctx) |
| 245 | ++{ |
| 246 | ++ struct nl_context *nlctx = ctx->nlctx; |
| 247 | ++ struct nl_msg_buff *msgbuff; |
| 248 | ++ struct nl_socket *nlsk; |
| 249 | ++ int ret; |
| 250 | ++ |
| 251 | ++ nlctx->cmd = "--set-frame-preemption"; |
| 252 | ++ nlctx->argp = ctx->argp; |
| 253 | ++ nlctx->argc = ctx->argc; |
| 254 | ++ nlctx->devname = ctx->devname; |
| 255 | ++ nlsk = nlctx->ethnl_socket; |
| 256 | ++ msgbuff = &nlsk->msgbuff; |
| 257 | ++ |
| 258 | ++ ret = msg_init(nlctx, msgbuff, ETHTOOL_MSG_PREEMPT_SET, |
| 259 | ++ NLM_F_REQUEST | NLM_F_ACK); |
| 260 | ++ if (ret < 0) |
| 261 | ++ return 2; |
| 262 | ++ if (ethnla_fill_header(msgbuff, ETHTOOL_A_PREEMPT_HEADER, |
| 263 | ++ ctx->devname, 0)) |
| 264 | ++ return -EMSGSIZE; |
| 265 | ++ |
| 266 | ++ ret = nl_parser(nlctx, set_preempt_params, NULL, PARSER_GROUP_NONE, NULL); |
| 267 | ++ if (ret < 0) |
| 268 | ++ return 1; |
| 269 | ++ |
| 270 | ++ ret = nlsock_sendmsg(nlsk, NULL); |
| 271 | ++ if (ret < 0) |
| 272 | ++ return 81; |
| 273 | ++ ret = nlsock_process_reply(nlsk, nomsg_reply_cb, nlctx); |
| 274 | ++ if (ret == 0) |
| 275 | ++ return 0; |
| 276 | ++ else |
| 277 | ++ return nlctx->exit_code ?: 81; |
| 278 | ++} |
| 279 | +\ No newline at end of file |
| 280 | +-- |
| 281 | +2.34.1 |
| 282 | + |
0 commit comments