Skip to content

Commit 029ee6b

Browse files
Yufeng Mokuba-moo
authored andcommitted
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>
1 parent 95d1d24 commit 029ee6b

File tree

5 files changed

+45
-4
lines changed

5 files changed

+45
-4
lines changed

Documentation/networking/ethtool-netlink.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,12 +947,25 @@ Kernel response contents:
947947
``ETHTOOL_A_COALESCE_TX_USECS_HIGH`` u32 delay (us), high Tx
948948
``ETHTOOL_A_COALESCE_TX_MAX_FRAMES_HIGH`` u32 max packets, high Tx
949949
``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
950952
=========================================== ====== =======================
951953

952954
Attributes are only included in reply if their value is not zero or the
953955
corresponding bit in ``ethtool_ops::supported_coalesce_params`` is set (i.e.
954956
they are declared as supported by driver).
955957

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.
956969

957970
COALESCE_SET
958971
============
@@ -985,6 +998,8 @@ Request contents:
985998
``ETHTOOL_A_COALESCE_TX_USECS_HIGH`` u32 delay (us), high Tx
986999
``ETHTOOL_A_COALESCE_TX_MAX_FRAMES_HIGH`` u32 max packets, high Tx
9871000
``ETHTOOL_A_COALESCE_RATE_SAMPLE_INTERVAL`` u32 rate sampling interval
1001+
``ETHTOOL_A_COALESCE_USE_CQE_TX`` bool timer reset mode, Tx
1002+
``ETHTOOL_A_COALESCE_USE_CQE_RX`` bool timer reset mode, Rx
9881003
=========================================== ====== =======================
9891004

9901005
Request is rejected if it attributes declared as unsupported by driver (i.e.

include/linux/ethtool.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@ extern int
172172
__ethtool_get_link_ksettings(struct net_device *dev,
173173
struct ethtool_link_ksettings *link_ksettings);
174174

175+
struct kernel_ethtool_coalesce {
176+
u8 use_cqe_mode_tx;
177+
u8 use_cqe_mode_rx;
178+
};
179+
175180
/**
176181
* ethtool_intersect_link_masks - Given two link masks, AND them together
177182
* @dst: first mask and where result is stored
@@ -211,7 +216,9 @@ bool ethtool_convert_link_mode_to_legacy_u32(u32 *legacy_u32,
211216
#define ETHTOOL_COALESCE_TX_USECS_HIGH BIT(19)
212217
#define ETHTOOL_COALESCE_TX_MAX_FRAMES_HIGH BIT(20)
213218
#define ETHTOOL_COALESCE_RATE_SAMPLE_INTERVAL BIT(21)
214-
#define ETHTOOL_COALESCE_ALL_PARAMS GENMASK(21, 0)
219+
#define ETHTOOL_COALESCE_USE_CQE_RX BIT(22)
220+
#define ETHTOOL_COALESCE_USE_CQE_TX BIT(23)
221+
#define ETHTOOL_COALESCE_ALL_PARAMS GENMASK(23, 0)
215222

216223
#define ETHTOOL_COALESCE_USECS \
217224
(ETHTOOL_COALESCE_RX_USECS | ETHTOOL_COALESCE_TX_USECS)
@@ -237,6 +244,8 @@ bool ethtool_convert_link_mode_to_legacy_u32(u32 *legacy_u32,
237244
ETHTOOL_COALESCE_RX_USECS_LOW | ETHTOOL_COALESCE_RX_USECS_HIGH | \
238245
ETHTOOL_COALESCE_PKT_RATE_LOW | ETHTOOL_COALESCE_PKT_RATE_HIGH | \
239246
ETHTOOL_COALESCE_RATE_SAMPLE_INTERVAL)
247+
#define ETHTOOL_COALESCE_USE_CQE \
248+
(ETHTOOL_COALESCE_USE_CQE_RX | ETHTOOL_COALESCE_USE_CQE_TX)
240249

241250
#define ETHTOOL_STAT_NOT_SET (~0ULL)
242251

include/uapi/linux/ethtool_netlink.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,8 @@ enum {
377377
ETHTOOL_A_COALESCE_TX_USECS_HIGH, /* u32 */
378378
ETHTOOL_A_COALESCE_TX_MAX_FRAMES_HIGH, /* u32 */
379379
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 */
380382

381383
/* add new constants above here */
382384
__ETHTOOL_A_COALESCE_CNT,

net/ethtool/coalesce.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ struct coalesce_req_info {
1010
struct coalesce_reply_data {
1111
struct ethnl_reply_data base;
1212
struct ethtool_coalesce coalesce;
13+
struct kernel_ethtool_coalesce kernel_coalesce;
1314
u32 supported_params;
1415
};
1516

@@ -100,7 +101,9 @@ static int coalesce_reply_size(const struct ethnl_req_info *req_base,
100101
nla_total_size(sizeof(u32)) + /* _RX_MAX_FRAMES_HIGH */
101102
nla_total_size(sizeof(u32)) + /* _TX_USECS_HIGH */
102103
nla_total_size(sizeof(u32)) + /* _TX_MAX_FRAMES_HIGH */
103-
nla_total_size(sizeof(u32)); /* _RATE_SAMPLE_INTERVAL */
104+
nla_total_size(sizeof(u32)) + /* _RATE_SAMPLE_INTERVAL */
105+
nla_total_size(sizeof(u8)) + /* _USE_CQE_MODE_TX */
106+
nla_total_size(sizeof(u8)); /* _USE_CQE_MODE_RX */
104107
}
105108

106109
static bool coalesce_put_u32(struct sk_buff *skb, u16 attr_type, u32 val,
@@ -124,6 +127,7 @@ static int coalesce_fill_reply(struct sk_buff *skb,
124127
const struct ethnl_reply_data *reply_base)
125128
{
126129
const struct coalesce_reply_data *data = COALESCE_REPDATA(reply_base);
130+
const struct kernel_ethtool_coalesce *kcoal = &data->kernel_coalesce;
127131
const struct ethtool_coalesce *coal = &data->coalesce;
128132
u32 supported = data->supported_params;
129133

@@ -170,7 +174,11 @@ static int coalesce_fill_reply(struct sk_buff *skb,
170174
coalesce_put_u32(skb, ETHTOOL_A_COALESCE_TX_MAX_FRAMES_HIGH,
171175
coal->tx_max_coalesced_frames_high, supported) ||
172176
coalesce_put_u32(skb, ETHTOOL_A_COALESCE_RATE_SAMPLE_INTERVAL,
173-
coal->rate_sample_interval, supported))
177+
coal->rate_sample_interval, supported) ||
178+
coalesce_put_bool(skb, ETHTOOL_A_COALESCE_USE_CQE_MODE_TX,
179+
kcoal->use_cqe_mode_tx, supported) ||
180+
coalesce_put_bool(skb, ETHTOOL_A_COALESCE_USE_CQE_MODE_RX,
181+
kcoal->use_cqe_mode_rx, supported))
174182
return -EMSGSIZE;
175183

176184
return 0;
@@ -215,10 +223,13 @@ const struct nla_policy ethnl_coalesce_set_policy[] = {
215223
[ETHTOOL_A_COALESCE_TX_USECS_HIGH] = { .type = NLA_U32 },
216224
[ETHTOOL_A_COALESCE_TX_MAX_FRAMES_HIGH] = { .type = NLA_U32 },
217225
[ETHTOOL_A_COALESCE_RATE_SAMPLE_INTERVAL] = { .type = NLA_U32 },
226+
[ETHTOOL_A_COALESCE_USE_CQE_MODE_TX] = NLA_POLICY_MAX(NLA_U8, 1),
227+
[ETHTOOL_A_COALESCE_USE_CQE_MODE_RX] = NLA_POLICY_MAX(NLA_U8, 1),
218228
};
219229

220230
int ethnl_set_coalesce(struct sk_buff *skb, struct genl_info *info)
221231
{
232+
struct kernel_ethtool_coalesce kernel_coalesce = {};
222233
struct ethtool_coalesce coalesce = {};
223234
struct ethnl_req_info req_info = {};
224235
struct nlattr **tb = info->attrs;
@@ -303,6 +314,10 @@ int ethnl_set_coalesce(struct sk_buff *skb, struct genl_info *info)
303314
tb[ETHTOOL_A_COALESCE_TX_MAX_FRAMES_HIGH], &mod);
304315
ethnl_update_u32(&coalesce.rate_sample_interval,
305316
tb[ETHTOOL_A_COALESCE_RATE_SAMPLE_INTERVAL], &mod);
317+
ethnl_update_u8(&kernel_coalesce.use_cqe_mode_tx,
318+
tb[ETHTOOL_A_COALESCE_USE_CQE_MODE_TX], &mod);
319+
ethnl_update_u8(&kernel_coalesce.use_cqe_mode_rx,
320+
tb[ETHTOOL_A_COALESCE_USE_CQE_MODE_RX], &mod);
306321
ret = 0;
307322
if (!mod)
308323
goto out_ops;

net/ethtool/netlink.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ extern const struct nla_policy ethnl_rings_set_policy[ETHTOOL_A_RINGS_TX + 1];
359359
extern const struct nla_policy ethnl_channels_get_policy[ETHTOOL_A_CHANNELS_HEADER + 1];
360360
extern const struct nla_policy ethnl_channels_set_policy[ETHTOOL_A_CHANNELS_COMBINED_COUNT + 1];
361361
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];
363363
extern const struct nla_policy ethnl_pause_get_policy[ETHTOOL_A_PAUSE_HEADER + 1];
364364
extern const struct nla_policy ethnl_pause_set_policy[ETHTOOL_A_PAUSE_TX + 1];
365365
extern const struct nla_policy ethnl_eee_get_policy[ETHTOOL_A_EEE_HEADER + 1];

0 commit comments

Comments
 (0)