Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ethtool: add two coalesce attributes for CQE mode

Currently, there are many drivers who support CQE mode configuration,
some configure it as a fixed when initialized, some provide an
interface to change it by ethtool private flags. In order to make it
more generic, add two new 'ETHTOOL_A_COALESCE_USE_CQE_TX' and
'ETHTOOL_A_COALESCE_USE_CQE_RX' coalesce attributes, then these
parameters can be accessed by ethtool netlink coalesce uAPI.

Also add an new structure kernel_ethtool_coalesce, then the
new parameter can be added into this struct.

Signed-off-by: Yufeng Mo <moyufeng@huawei.com>
Signed-off-by: Huazhong Tan <tanhuazhong@huawei.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Yufeng Mo and committed by
Jakub Kicinski
029ee6b1 95d1d249

+45 -4
+15
Documentation/networking/ethtool-netlink.rst
··· 947 947 ``ETHTOOL_A_COALESCE_TX_USECS_HIGH`` u32 delay (us), high Tx 948 948 ``ETHTOOL_A_COALESCE_TX_MAX_FRAMES_HIGH`` u32 max packets, high Tx 949 949 ``ETHTOOL_A_COALESCE_RATE_SAMPLE_INTERVAL`` u32 rate sampling interval 950 + ``ETHTOOL_A_COALESCE_USE_CQE_TX`` bool timer reset mode, Tx 951 + ``ETHTOOL_A_COALESCE_USE_CQE_RX`` bool timer reset mode, Rx 950 952 =========================================== ====== ======================= 951 953 952 954 Attributes are only included in reply if their value is not zero or the 953 955 corresponding bit in ``ethtool_ops::supported_coalesce_params`` is set (i.e. 954 956 they are declared as supported by driver). 955 957 958 + Timer reset mode (``ETHTOOL_A_COALESCE_USE_CQE_TX`` and 959 + ``ETHTOOL_A_COALESCE_USE_CQE_RX``) controls the interaction between packet 960 + arrival and the various time based delay parameters. By default timers are 961 + expected to limit the max delay between any packet arrival/departure and a 962 + corresponding interrupt. In this mode timer should be started by packet 963 + arrival (sometimes delivery of previous interrupt) and reset when interrupt 964 + is delivered. 965 + Setting the appropriate attribute to 1 will enable ``CQE`` mode, where 966 + each packet event resets the timer. In this mode timer is used to force 967 + the interrupt if queue goes idle, while busy queues depend on the packet 968 + limit to trigger interrupts. 956 969 957 970 COALESCE_SET 958 971 ============ ··· 998 985 ``ETHTOOL_A_COALESCE_TX_USECS_HIGH`` u32 delay (us), high Tx 999 986 ``ETHTOOL_A_COALESCE_TX_MAX_FRAMES_HIGH`` u32 max packets, high Tx 1000 987 ``ETHTOOL_A_COALESCE_RATE_SAMPLE_INTERVAL`` u32 rate sampling interval 988 + ``ETHTOOL_A_COALESCE_USE_CQE_TX`` bool timer reset mode, Tx 989 + ``ETHTOOL_A_COALESCE_USE_CQE_RX`` bool timer reset mode, Rx 1001 990 =========================================== ====== ======================= 1002 991 1003 992 Request is rejected if it attributes declared as unsupported by driver (i.e.
+10 -1
include/linux/ethtool.h
··· 172 172 __ethtool_get_link_ksettings(struct net_device *dev, 173 173 struct ethtool_link_ksettings *link_ksettings); 174 174 175 + struct kernel_ethtool_coalesce { 176 + u8 use_cqe_mode_tx; 177 + u8 use_cqe_mode_rx; 178 + }; 179 + 175 180 /** 176 181 * ethtool_intersect_link_masks - Given two link masks, AND them together 177 182 * @dst: first mask and where result is stored ··· 216 211 #define ETHTOOL_COALESCE_TX_USECS_HIGH BIT(19) 217 212 #define ETHTOOL_COALESCE_TX_MAX_FRAMES_HIGH BIT(20) 218 213 #define ETHTOOL_COALESCE_RATE_SAMPLE_INTERVAL BIT(21) 219 - #define ETHTOOL_COALESCE_ALL_PARAMS GENMASK(21, 0) 214 + #define ETHTOOL_COALESCE_USE_CQE_RX BIT(22) 215 + #define ETHTOOL_COALESCE_USE_CQE_TX BIT(23) 216 + #define ETHTOOL_COALESCE_ALL_PARAMS GENMASK(23, 0) 220 217 221 218 #define ETHTOOL_COALESCE_USECS \ 222 219 (ETHTOOL_COALESCE_RX_USECS | ETHTOOL_COALESCE_TX_USECS) ··· 244 237 ETHTOOL_COALESCE_RX_USECS_LOW | ETHTOOL_COALESCE_RX_USECS_HIGH | \ 245 238 ETHTOOL_COALESCE_PKT_RATE_LOW | ETHTOOL_COALESCE_PKT_RATE_HIGH | \ 246 239 ETHTOOL_COALESCE_RATE_SAMPLE_INTERVAL) 240 + #define ETHTOOL_COALESCE_USE_CQE \ 241 + (ETHTOOL_COALESCE_USE_CQE_RX | ETHTOOL_COALESCE_USE_CQE_TX) 247 242 248 243 #define ETHTOOL_STAT_NOT_SET (~0ULL) 249 244
+2
include/uapi/linux/ethtool_netlink.h
··· 377 377 ETHTOOL_A_COALESCE_TX_USECS_HIGH, /* u32 */ 378 378 ETHTOOL_A_COALESCE_TX_MAX_FRAMES_HIGH, /* u32 */ 379 379 ETHTOOL_A_COALESCE_RATE_SAMPLE_INTERVAL, /* u32 */ 380 + ETHTOOL_A_COALESCE_USE_CQE_MODE_TX, /* u8 */ 381 + ETHTOOL_A_COALESCE_USE_CQE_MODE_RX, /* u8 */ 380 382 381 383 /* add new constants above here */ 382 384 __ETHTOOL_A_COALESCE_CNT,
+17 -2
net/ethtool/coalesce.c
··· 10 10 struct coalesce_reply_data { 11 11 struct ethnl_reply_data base; 12 12 struct ethtool_coalesce coalesce; 13 + struct kernel_ethtool_coalesce kernel_coalesce; 13 14 u32 supported_params; 14 15 }; 15 16 ··· 101 100 nla_total_size(sizeof(u32)) + /* _RX_MAX_FRAMES_HIGH */ 102 101 nla_total_size(sizeof(u32)) + /* _TX_USECS_HIGH */ 103 102 nla_total_size(sizeof(u32)) + /* _TX_MAX_FRAMES_HIGH */ 104 - nla_total_size(sizeof(u32)); /* _RATE_SAMPLE_INTERVAL */ 103 + nla_total_size(sizeof(u32)) + /* _RATE_SAMPLE_INTERVAL */ 104 + nla_total_size(sizeof(u8)) + /* _USE_CQE_MODE_TX */ 105 + nla_total_size(sizeof(u8)); /* _USE_CQE_MODE_RX */ 105 106 } 106 107 107 108 static bool coalesce_put_u32(struct sk_buff *skb, u16 attr_type, u32 val, ··· 127 124 const struct ethnl_reply_data *reply_base) 128 125 { 129 126 const struct coalesce_reply_data *data = COALESCE_REPDATA(reply_base); 127 + const struct kernel_ethtool_coalesce *kcoal = &data->kernel_coalesce; 130 128 const struct ethtool_coalesce *coal = &data->coalesce; 131 129 u32 supported = data->supported_params; 132 130 ··· 174 170 coalesce_put_u32(skb, ETHTOOL_A_COALESCE_TX_MAX_FRAMES_HIGH, 175 171 coal->tx_max_coalesced_frames_high, supported) || 176 172 coalesce_put_u32(skb, ETHTOOL_A_COALESCE_RATE_SAMPLE_INTERVAL, 177 - coal->rate_sample_interval, supported)) 173 + coal->rate_sample_interval, supported) || 174 + coalesce_put_bool(skb, ETHTOOL_A_COALESCE_USE_CQE_MODE_TX, 175 + kcoal->use_cqe_mode_tx, supported) || 176 + coalesce_put_bool(skb, ETHTOOL_A_COALESCE_USE_CQE_MODE_RX, 177 + kcoal->use_cqe_mode_rx, supported)) 178 178 return -EMSGSIZE; 179 179 180 180 return 0; ··· 223 215 [ETHTOOL_A_COALESCE_TX_USECS_HIGH] = { .type = NLA_U32 }, 224 216 [ETHTOOL_A_COALESCE_TX_MAX_FRAMES_HIGH] = { .type = NLA_U32 }, 225 217 [ETHTOOL_A_COALESCE_RATE_SAMPLE_INTERVAL] = { .type = NLA_U32 }, 218 + [ETHTOOL_A_COALESCE_USE_CQE_MODE_TX] = NLA_POLICY_MAX(NLA_U8, 1), 219 + [ETHTOOL_A_COALESCE_USE_CQE_MODE_RX] = NLA_POLICY_MAX(NLA_U8, 1), 226 220 }; 227 221 228 222 int ethnl_set_coalesce(struct sk_buff *skb, struct genl_info *info) 229 223 { 224 + struct kernel_ethtool_coalesce kernel_coalesce = {}; 230 225 struct ethtool_coalesce coalesce = {}; 231 226 struct ethnl_req_info req_info = {}; 232 227 struct nlattr **tb = info->attrs; ··· 314 303 tb[ETHTOOL_A_COALESCE_TX_MAX_FRAMES_HIGH], &mod); 315 304 ethnl_update_u32(&coalesce.rate_sample_interval, 316 305 tb[ETHTOOL_A_COALESCE_RATE_SAMPLE_INTERVAL], &mod); 306 + ethnl_update_u8(&kernel_coalesce.use_cqe_mode_tx, 307 + tb[ETHTOOL_A_COALESCE_USE_CQE_MODE_TX], &mod); 308 + ethnl_update_u8(&kernel_coalesce.use_cqe_mode_rx, 309 + tb[ETHTOOL_A_COALESCE_USE_CQE_MODE_RX], &mod); 317 310 ret = 0; 318 311 if (!mod) 319 312 goto out_ops;
+1 -1
net/ethtool/netlink.h
··· 359 359 extern const struct nla_policy ethnl_channels_get_policy[ETHTOOL_A_CHANNELS_HEADER + 1]; 360 360 extern const struct nla_policy ethnl_channels_set_policy[ETHTOOL_A_CHANNELS_COMBINED_COUNT + 1]; 361 361 extern const struct nla_policy ethnl_coalesce_get_policy[ETHTOOL_A_COALESCE_HEADER + 1]; 362 - extern const struct nla_policy ethnl_coalesce_set_policy[ETHTOOL_A_COALESCE_RATE_SAMPLE_INTERVAL + 1]; 362 + extern const struct nla_policy ethnl_coalesce_set_policy[ETHTOOL_A_COALESCE_MAX + 1]; 363 363 extern const struct nla_policy ethnl_pause_get_policy[ETHTOOL_A_PAUSE_HEADER + 1]; 364 364 extern const struct nla_policy ethnl_pause_set_policy[ETHTOOL_A_PAUSE_TX + 1]; 365 365 extern const struct nla_policy ethnl_eee_get_policy[ETHTOOL_A_EEE_HEADER + 1];