Skip to content

Commit 7b05c54

Browse files
committed
Merge branch 'net-ethool-add-support-to-get-set-tx-push-by-ethtool-g-g'
Jie Wang says: ==================== net: ethool: add support to get/set tx push by ethtool -G/g These three patches add tx push in ring params and adapt the set and get APIs of ring params. ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 0a03f3c + 1f702c1 commit 7b05c54

File tree

6 files changed

+80
-22
lines changed

6 files changed

+80
-22
lines changed

Documentation/networking/ethtool-netlink.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,7 @@ Kernel response contents:
862862
``ETHTOOL_A_RINGS_RX_BUF_LEN`` u32 size of buffers on the ring
863863
``ETHTOOL_A_RINGS_TCP_DATA_SPLIT`` u8 TCP header / data split
864864
``ETHTOOL_A_RINGS_CQE_SIZE`` u32 Size of TX/RX CQE
865+
``ETHTOOL_A_RINGS_TX_PUSH`` u8 flag of TX Push mode
865866
==================================== ====== ===========================
866867

867868
``ETHTOOL_A_RINGS_TCP_DATA_SPLIT`` indicates whether the device is usable with
@@ -871,6 +872,12 @@ separate buffers. The device configuration must make it possible to receive
871872
full memory pages of data, for example because MTU is high enough or through
872873
HW-GRO.
873874

875+
``ETHTOOL_A_RINGS_TX_PUSH`` flag is used to enable descriptor fast
876+
path to send packets. In ordinary path, driver fills descriptors in DRAM and
877+
notifies NIC hardware. In fast path, driver pushes descriptors to the device
878+
through MMIO writes, thus reducing the latency. However, enabling this feature
879+
may increase the CPU cost. Drivers may enforce additional per-packet
880+
eligibility checks (e.g. on packet size).
874881

875882
RINGS_SET
876883
=========
@@ -887,6 +894,7 @@ Request contents:
887894
``ETHTOOL_A_RINGS_TX`` u32 size of TX ring
888895
``ETHTOOL_A_RINGS_RX_BUF_LEN`` u32 size of buffers on the ring
889896
``ETHTOOL_A_RINGS_CQE_SIZE`` u32 Size of TX/RX CQE
897+
``ETHTOOL_A_RINGS_TX_PUSH`` u8 flag of TX Push mode
890898
==================================== ====== ===========================
891899

892900
Kernel checks that requested ring sizes do not exceed limits reported by

drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,8 @@ static void hns3_get_ringparam(struct net_device *netdev,
664664
param->tx_pending = priv->ring[0].desc_num;
665665
param->rx_pending = priv->ring[rx_queue_index].desc_num;
666666
kernel_param->rx_buf_len = priv->ring[rx_queue_index].buf_size;
667+
kernel_param->tx_push = test_bit(HNS3_NIC_STATE_TX_PUSH_ENABLE,
668+
&priv->state);
667669
}
668670

669671
static void hns3_get_pauseparam(struct net_device *netdev,
@@ -1120,6 +1122,30 @@ static int hns3_change_rx_buf_len(struct net_device *ndev, u32 rx_buf_len)
11201122
return 0;
11211123
}
11221124

1125+
static int hns3_set_tx_push(struct net_device *netdev, u32 tx_push)
1126+
{
1127+
struct hns3_nic_priv *priv = netdev_priv(netdev);
1128+
struct hnae3_handle *h = hns3_get_handle(netdev);
1129+
struct hnae3_ae_dev *ae_dev = pci_get_drvdata(h->pdev);
1130+
u32 old_state = test_bit(HNS3_NIC_STATE_TX_PUSH_ENABLE, &priv->state);
1131+
1132+
if (!test_bit(HNAE3_DEV_SUPPORT_TX_PUSH_B, ae_dev->caps) && tx_push)
1133+
return -EOPNOTSUPP;
1134+
1135+
if (tx_push == old_state)
1136+
return 0;
1137+
1138+
netdev_dbg(netdev, "Changing tx push from %s to %s\n",
1139+
old_state ? "on" : "off", tx_push ? "on" : "off");
1140+
1141+
if (tx_push)
1142+
set_bit(HNS3_NIC_STATE_TX_PUSH_ENABLE, &priv->state);
1143+
else
1144+
clear_bit(HNS3_NIC_STATE_TX_PUSH_ENABLE, &priv->state);
1145+
1146+
return 0;
1147+
}
1148+
11231149
static int hns3_set_ringparam(struct net_device *ndev,
11241150
struct ethtool_ringparam *param,
11251151
struct kernel_ethtool_ringparam *kernel_param,
@@ -1139,6 +1165,10 @@ static int hns3_set_ringparam(struct net_device *ndev,
11391165
if (ret)
11401166
return ret;
11411167

1168+
ret = hns3_set_tx_push(ndev, kernel_param->tx_push);
1169+
if (ret)
1170+
return ret;
1171+
11421172
/* Hardware requires that its descriptors must be multiple of eight */
11431173
new_tx_desc_num = ALIGN(param->tx_pending, HNS3_RING_BD_MULTIPLE);
11441174
new_rx_desc_num = ALIGN(param->rx_pending, HNS3_RING_BD_MULTIPLE);
@@ -1858,7 +1888,8 @@ static int hns3_set_tunable(struct net_device *netdev,
18581888
ETHTOOL_COALESCE_MAX_FRAMES | \
18591889
ETHTOOL_COALESCE_USE_CQE)
18601890

1861-
#define HNS3_ETHTOOL_RING ETHTOOL_RING_USE_RX_BUF_LEN
1891+
#define HNS3_ETHTOOL_RING (ETHTOOL_RING_USE_RX_BUF_LEN | \
1892+
ETHTOOL_RING_USE_TX_PUSH)
18621893

18631894
static int hns3_get_ts_info(struct net_device *netdev,
18641895
struct ethtool_ts_info *info)

include/linux/ethtool.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,22 +71,26 @@ enum {
7171
* struct kernel_ethtool_ringparam - RX/TX ring configuration
7272
* @rx_buf_len: Current length of buffers on the rx ring.
7373
* @tcp_data_split: Scatter packet headers and data to separate buffers
74+
* @tx_push: The flag of tx push mode
7475
* @cqe_size: Size of TX/RX completion queue event
7576
*/
7677
struct kernel_ethtool_ringparam {
7778
u32 rx_buf_len;
7879
u8 tcp_data_split;
80+
u8 tx_push;
7981
u32 cqe_size;
8082
};
8183

8284
/**
8385
* enum ethtool_supported_ring_param - indicator caps for setting ring params
8486
* @ETHTOOL_RING_USE_RX_BUF_LEN: capture for setting rx_buf_len
8587
* @ETHTOOL_RING_USE_CQE_SIZE: capture for setting cqe_size
88+
* @ETHTOOL_RING_USE_TX_PUSH: capture for setting tx_push
8689
*/
8790
enum ethtool_supported_ring_param {
8891
ETHTOOL_RING_USE_RX_BUF_LEN = BIT(0),
8992
ETHTOOL_RING_USE_CQE_SIZE = BIT(1),
93+
ETHTOOL_RING_USE_TX_PUSH = BIT(2),
9094
};
9195

9296
#define __ETH_RSS_HASH_BIT(bit) ((u32)1 << (bit))

include/uapi/linux/ethtool_netlink.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ enum {
338338
ETHTOOL_A_RINGS_RX_BUF_LEN, /* u32 */
339339
ETHTOOL_A_RINGS_TCP_DATA_SPLIT, /* u8 */
340340
ETHTOOL_A_RINGS_CQE_SIZE, /* u32 */
341+
ETHTOOL_A_RINGS_TX_PUSH, /* u8 */
341342

342343
/* add new constants above here */
343344
__ETHTOOL_A_RINGS_CNT,

net/ethtool/netlink.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ extern const struct nla_policy ethnl_features_set_policy[ETHTOOL_A_FEATURES_WANT
363363
extern const struct nla_policy ethnl_privflags_get_policy[ETHTOOL_A_PRIVFLAGS_HEADER + 1];
364364
extern const struct nla_policy ethnl_privflags_set_policy[ETHTOOL_A_PRIVFLAGS_FLAGS + 1];
365365
extern const struct nla_policy ethnl_rings_get_policy[ETHTOOL_A_RINGS_HEADER + 1];
366-
extern const struct nla_policy ethnl_rings_set_policy[ETHTOOL_A_RINGS_CQE_SIZE + 1];
366+
extern const struct nla_policy ethnl_rings_set_policy[ETHTOOL_A_RINGS_TX_PUSH + 1];
367367
extern const struct nla_policy ethnl_channels_get_policy[ETHTOOL_A_CHANNELS_HEADER + 1];
368368
extern const struct nla_policy ethnl_channels_set_policy[ETHTOOL_A_CHANNELS_COMBINED_COUNT + 1];
369369
extern const struct nla_policy ethnl_coalesce_get_policy[ETHTOOL_A_COALESCE_HEADER + 1];

net/ethtool/rings.c

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ static int rings_reply_size(const struct ethnl_req_info *req_base,
5555
nla_total_size(sizeof(u32)) + /* _RINGS_TX */
5656
nla_total_size(sizeof(u32)) + /* _RINGS_RX_BUF_LEN */
5757
nla_total_size(sizeof(u8)) + /* _RINGS_TCP_DATA_SPLIT */
58-
nla_total_size(sizeof(u32)); /* _RINGS_CQE_SIZE */
58+
nla_total_size(sizeof(u32) + /* _RINGS_CQE_SIZE */
59+
nla_total_size(sizeof(u8))); /* _RINGS_TX_PUSH */
5960
}
6061

6162
static int rings_fill_reply(struct sk_buff *skb,
@@ -94,7 +95,8 @@ static int rings_fill_reply(struct sk_buff *skb,
9495
(nla_put_u8(skb, ETHTOOL_A_RINGS_TCP_DATA_SPLIT,
9596
kr->tcp_data_split))) ||
9697
(kr->cqe_size &&
97-
(nla_put_u32(skb, ETHTOOL_A_RINGS_CQE_SIZE, kr->cqe_size))))
98+
(nla_put_u32(skb, ETHTOOL_A_RINGS_CQE_SIZE, kr->cqe_size))) ||
99+
nla_put_u8(skb, ETHTOOL_A_RINGS_TX_PUSH, !!kr->tx_push))
98100
return -EMSGSIZE;
99101

100102
return 0;
@@ -123,6 +125,7 @@ const struct nla_policy ethnl_rings_set_policy[] = {
123125
[ETHTOOL_A_RINGS_TX] = { .type = NLA_U32 },
124126
[ETHTOOL_A_RINGS_RX_BUF_LEN] = NLA_POLICY_MIN(NLA_U32, 1),
125127
[ETHTOOL_A_RINGS_CQE_SIZE] = NLA_POLICY_MIN(NLA_U32, 1),
128+
[ETHTOOL_A_RINGS_TX_PUSH] = NLA_POLICY_MAX(NLA_U8, 1),
126129
};
127130

128131
int ethnl_set_rings(struct sk_buff *skb, struct genl_info *info)
@@ -149,6 +152,33 @@ int ethnl_set_rings(struct sk_buff *skb, struct genl_info *info)
149152
if (!ops->get_ringparam || !ops->set_ringparam)
150153
goto out_dev;
151154

155+
if (tb[ETHTOOL_A_RINGS_RX_BUF_LEN] &&
156+
!(ops->supported_ring_params & ETHTOOL_RING_USE_RX_BUF_LEN)) {
157+
ret = -EOPNOTSUPP;
158+
NL_SET_ERR_MSG_ATTR(info->extack,
159+
tb[ETHTOOL_A_RINGS_RX_BUF_LEN],
160+
"setting rx buf len not supported");
161+
goto out_dev;
162+
}
163+
164+
if (tb[ETHTOOL_A_RINGS_CQE_SIZE] &&
165+
!(ops->supported_ring_params & ETHTOOL_RING_USE_CQE_SIZE)) {
166+
ret = -EOPNOTSUPP;
167+
NL_SET_ERR_MSG_ATTR(info->extack,
168+
tb[ETHTOOL_A_RINGS_CQE_SIZE],
169+
"setting cqe size not supported");
170+
goto out_dev;
171+
}
172+
173+
if (tb[ETHTOOL_A_RINGS_TX_PUSH] &&
174+
!(ops->supported_ring_params & ETHTOOL_RING_USE_TX_PUSH)) {
175+
ret = -EOPNOTSUPP;
176+
NL_SET_ERR_MSG_ATTR(info->extack,
177+
tb[ETHTOOL_A_RINGS_TX_PUSH],
178+
"setting tx push not supported");
179+
goto out_dev;
180+
}
181+
152182
rtnl_lock();
153183
ret = ethnl_ops_begin(dev);
154184
if (ret < 0)
@@ -165,6 +195,8 @@ int ethnl_set_rings(struct sk_buff *skb, struct genl_info *info)
165195
tb[ETHTOOL_A_RINGS_RX_BUF_LEN], &mod);
166196
ethnl_update_u32(&kernel_ringparam.cqe_size,
167197
tb[ETHTOOL_A_RINGS_CQE_SIZE], &mod);
198+
ethnl_update_u8(&kernel_ringparam.tx_push,
199+
tb[ETHTOOL_A_RINGS_TX_PUSH], &mod);
168200
ret = 0;
169201
if (!mod)
170202
goto out_ops;
@@ -187,24 +219,6 @@ int ethnl_set_rings(struct sk_buff *skb, struct genl_info *info)
187219
goto out_ops;
188220
}
189221

190-
if (kernel_ringparam.rx_buf_len != 0 &&
191-
!(ops->supported_ring_params & ETHTOOL_RING_USE_RX_BUF_LEN)) {
192-
ret = -EOPNOTSUPP;
193-
NL_SET_ERR_MSG_ATTR(info->extack,
194-
tb[ETHTOOL_A_RINGS_RX_BUF_LEN],
195-
"setting rx buf len not supported");
196-
goto out_ops;
197-
}
198-
199-
if (kernel_ringparam.cqe_size &&
200-
!(ops->supported_ring_params & ETHTOOL_RING_USE_CQE_SIZE)) {
201-
ret = -EOPNOTSUPP;
202-
NL_SET_ERR_MSG_ATTR(info->extack,
203-
tb[ETHTOOL_A_RINGS_CQE_SIZE],
204-
"setting cqe size not supported");
205-
goto out_ops;
206-
}
207-
208222
ret = dev->ethtool_ops->set_ringparam(dev, &ringparam,
209223
&kernel_ringparam, info->extack);
210224
if (ret < 0)

0 commit comments

Comments
 (0)