History

ethtool: Add support for configuring tx_push_buf_len

This attribute, which is part of ethtool's ring param configuration allows the user to specify the maximum number of the packet's payload that can be written directly to the device. Example usage: # ethtool -G [interface] tx-push-buf-len [number of bytes]

Shay Agroskin committed 3 years ago

Commit 233eb4e1 parent 3e4d5ba6 files · +84 −23Browse files

Unified · Split

6 files
  1. Documentation/netlink/specs/ethtool.yaml +8 −0
  2. Documentation/networking/ethtool-netlink.rst +31 −16
  3. include/linux/ethtool.h +10 −4
  4. include/uapi/linux/ethtool_netlink.h +2 −0
  5. net/ethtool/netlink.h +1 −1
  6. net/ethtool/rings.c +32 −2
Documentation/netlink/specs/ethtool.yaml+8−0
@@ -165,6 +165,12 @@ attribute-sets: · 164 unmodified lines
165165 -
166166 name: rx-push
167167 type: u8
168+ -
169+ name: tx-push-buf-len
170+ type: u32
171+ -
172+ name: tx-push-buf-len-max
173+ type: u32
168174
169175 -
170176 name: mm-stat
@@ -311,6 +317,8 @@ operations: · 140 unmodified lines
311317 - cqe-size
312318 - tx-push
313319 - rx-push
320+ - tx-push-buf-len
321+ - tx-push-buf-len-max
314322 dump: *ring-get-op
315323 -
316324 name: rings-set
Documentation/networking/ethtool-netlink.rst+31−16
@@ -860,22 +860,24 @@ Request contents: · 859 unmodified lines
860860
861861 Kernel response contents:
862862
863− ==================================== ====== ===========================
864− ``ETHTOOL_A_RINGS_HEADER`` nested reply header
865− ``ETHTOOL_A_RINGS_RX_MAX`` u32 max size of RX ring
866− ``ETHTOOL_A_RINGS_RX_MINI_MAX`` u32 max size of RX mini ring
867− ``ETHTOOL_A_RINGS_RX_JUMBO_MAX`` u32 max size of RX jumbo ring
868− ``ETHTOOL_A_RINGS_TX_MAX`` u32 max size of TX ring
869− ``ETHTOOL_A_RINGS_RX`` u32 size of RX ring
870− ``ETHTOOL_A_RINGS_RX_MINI`` u32 size of RX mini ring
871− ``ETHTOOL_A_RINGS_RX_JUMBO`` u32 size of RX jumbo ring
872− ``ETHTOOL_A_RINGS_TX`` u32 size of TX ring
873− ``ETHTOOL_A_RINGS_RX_BUF_LEN`` u32 size of buffers on the ring
874− ``ETHTOOL_A_RINGS_TCP_DATA_SPLIT`` u8 TCP header / data split
875− ``ETHTOOL_A_RINGS_CQE_SIZE`` u32 Size of TX/RX CQE
876− ``ETHTOOL_A_RINGS_TX_PUSH`` u8 flag of TX Push mode
877− ``ETHTOOL_A_RINGS_RX_PUSH`` u8 flag of RX Push mode
878− ==================================== ====== ===========================
863+ ======================================= ====== ===========================
864+ ``ETHTOOL_A_RINGS_HEADER`` nested reply header
865+ ``ETHTOOL_A_RINGS_RX_MAX`` u32 max size of RX ring
866+ ``ETHTOOL_A_RINGS_RX_MINI_MAX`` u32 max size of RX mini ring
867+ ``ETHTOOL_A_RINGS_RX_JUMBO_MAX`` u32 max size of RX jumbo ring
868+ ``ETHTOOL_A_RINGS_TX_MAX`` u32 max size of TX ring
869+ ``ETHTOOL_A_RINGS_RX`` u32 size of RX ring
870+ ``ETHTOOL_A_RINGS_RX_MINI`` u32 size of RX mini ring
871+ ``ETHTOOL_A_RINGS_RX_JUMBO`` u32 size of RX jumbo ring
872+ ``ETHTOOL_A_RINGS_TX`` u32 size of TX ring
873+ ``ETHTOOL_A_RINGS_RX_BUF_LEN`` u32 size of buffers on the ring
874+ ``ETHTOOL_A_RINGS_TCP_DATA_SPLIT`` u8 TCP header / data split
875+ ``ETHTOOL_A_RINGS_CQE_SIZE`` u32 Size of TX/RX CQE
876+ ``ETHTOOL_A_RINGS_TX_PUSH`` u8 flag of TX Push mode
877+ ``ETHTOOL_A_RINGS_RX_PUSH`` u8 flag of RX Push mode
878+ ``ETHTOOL_A_RINGS_TX_PUSH_BUF_LEN`` u32 size of TX push buffer
879+ ``ETHTOOL_A_RINGS_TX_PUSH_BUF_LEN_MAX`` u32 max size of TX push buffer
880+ ======================================= ====== ===========================
879881
880882 ``ETHTOOL_A_RINGS_TCP_DATA_SPLIT`` indicates whether the device is usable with
881883 page-flipping TCP zero-copy receive (``getsockopt(TCP_ZEROCOPY_RECEIVE)``).
@@ -891,6 +893,18 @@ through MMIO writes, thus reducing the latency. However, enabling this feature · 9 unmodified lines
891893 may increase the CPU cost. Drivers may enforce additional per-packet
892894 eligibility checks (e.g. on packet size).
893895
896+``ETHTOOL_A_RINGS_TX_PUSH_BUF_LEN`` specifies the maximum number of bytes of a
897+transmitted packet a driver can push directly to the underlying device
898+('push' mode). Pushing some of the payload bytes to the device has the
899+advantages of reducing latency for small packets by avoiding DMA mapping (same
900+as ``ETHTOOL_A_RINGS_TX_PUSH`` parameter) as well as allowing the underlying
901+device to process packet headers ahead of fetching its payload.
902+This can help the device to make fast actions based on the packet's headers.
903+This is similar to the "tx-copybreak" parameter, which copies the packet to a
904+preallocated DMA memory area instead of mapping new memory. However,
905+tx-push-buff parameter copies the packet directly to the device to allow the
906+device to take faster actions on the packet.
907+
894908 RINGS_SET
895909 =========
896910
@@ -908,6 +922,7 @@ Request contents: · 11 unmodified lines
908922 ``ETHTOOL_A_RINGS_CQE_SIZE`` u32 Size of TX/RX CQE
909923 ``ETHTOOL_A_RINGS_TX_PUSH`` u8 flag of TX Push mode
910924 ``ETHTOOL_A_RINGS_RX_PUSH`` u8 flag of RX Push mode
925+ ``ETHTOOL_A_RINGS_TX_PUSH_BUF_LEN`` u32 size of TX push buffer
911926 ==================================== ====== ===========================
912927
913928 Kernel checks that requested ring sizes do not exceed limits reported by
include/linux/ethtool.h+10−4
@@ -75,6 +75,8 @@ enum { · 74 unmodified lines
7575 * @tx_push: The flag of tx push mode
7676 * @rx_push: The flag of rx push mode
7777 * @cqe_size: Size of TX/RX completion queue event
78+ * @tx_push_buf_len: Size of TX push buffer
79+ * @tx_push_buf_max_len: Maximum allowed size of TX push buffer
7880 */
7981 struct kernel_ethtool_ringparam {
8082 u32 rx_buf_len;
@@ -82,6 +84,8 @@ struct kernel_ethtool_ringparam { · 1 unmodified line
8284 u8 tx_push;
8385 u8 rx_push;
8486 u32 cqe_size;
87+ u32 tx_push_buf_len;
88+ u32 tx_push_buf_max_len;
8589 };
8690
8791 /**
@@ -90,12 +94,14 @@ struct kernel_ethtool_ringparam { · 2 unmodified lines
9094 * @ETHTOOL_RING_USE_CQE_SIZE: capture for setting cqe_size
9195 * @ETHTOOL_RING_USE_TX_PUSH: capture for setting tx_push
9296 * @ETHTOOL_RING_USE_RX_PUSH: capture for setting rx_push
97+ * @ETHTOOL_RING_USE_TX_PUSH_BUF_LEN: capture for setting tx_push_buf_len
9398 */
9499 enum ethtool_supported_ring_param {
95− ETHTOOL_RING_USE_RX_BUF_LEN = BIT(0),
96− ETHTOOL_RING_USE_CQE_SIZE = BIT(1),
97− ETHTOOL_RING_USE_TX_PUSH = BIT(2),
98− ETHTOOL_RING_USE_RX_PUSH = BIT(3),
100+ ETHTOOL_RING_USE_RX_BUF_LEN = BIT(0),
101+ ETHTOOL_RING_USE_CQE_SIZE = BIT(1),
102+ ETHTOOL_RING_USE_TX_PUSH = BIT(2),
103+ ETHTOOL_RING_USE_RX_PUSH = BIT(3),
104+ ETHTOOL_RING_USE_TX_PUSH_BUF_LEN = BIT(4),
99105 };
100106
101107 #define __ETH_RSS_HASH_BIT(bit) ((u32)1 << (bit))
include/uapi/linux/ethtool_netlink.h+2−0
@@ -357,6 +357,8 @@ enum { · 356 unmodified lines
357357 ETHTOOL_A_RINGS_CQE_SIZE, /* u32 */
358358 ETHTOOL_A_RINGS_TX_PUSH, /* u8 */
359359 ETHTOOL_A_RINGS_RX_PUSH, /* u8 */
360+ ETHTOOL_A_RINGS_TX_PUSH_BUF_LEN, /* u32 */
361+ ETHTOOL_A_RINGS_TX_PUSH_BUF_LEN_MAX, /* u32 */
360362
361363 /* add new constants above here */
362364 __ETHTOOL_A_RINGS_CNT,
net/ethtool/netlink.h+1−1
@@ -413,7 +413,7 @@ extern const struct nla_policy ethnl_features_set_policy[ETHTOOL_A_FEATURES_WANT · 412 unmodified lines
413413 extern const struct nla_policy ethnl_privflags_get_policy[ETHTOOL_A_PRIVFLAGS_HEADER + 1];
414414 extern const struct nla_policy ethnl_privflags_set_policy[ETHTOOL_A_PRIVFLAGS_FLAGS + 1];
415415 extern const struct nla_policy ethnl_rings_get_policy[ETHTOOL_A_RINGS_HEADER + 1];
416−extern const struct nla_policy ethnl_rings_set_policy[ETHTOOL_A_RINGS_RX_PUSH + 1];
416+extern const struct nla_policy ethnl_rings_set_policy[ETHTOOL_A_RINGS_TX_PUSH_BUF_LEN_MAX + 1];
417417 extern const struct nla_policy ethnl_channels_get_policy[ETHTOOL_A_CHANNELS_HEADER + 1];
418418 extern const struct nla_policy ethnl_channels_set_policy[ETHTOOL_A_CHANNELS_COMBINED_COUNT + 1];
419419 extern const struct nla_policy ethnl_coalesce_get_policy[ETHTOOL_A_COALESCE_HEADER + 1];
net/ethtool/rings.c+32−2
@@ -11,6 +11,7 @@ struct rings_reply_data { · 10 unmodified lines
1111 struct ethnl_reply_data base;
1212 struct ethtool_ringparam ringparam;
1313 struct kernel_ethtool_ringparam kernel_ringparam;
14+ u32 supported_ring_params;
1415 };
1516
1617 #define RINGS_REPDATA(__reply_base) \
@@ -32,6 +33,8 @@ static int rings_prepare_data(const struct ethnl_req_info *req_base, · 15 unmodified lines
3233
3334 if (!dev->ethtool_ops->get_ringparam)
3435 return -EOPNOTSUPP;
36+
37+ data->supported_ring_params = dev->ethtool_ops->supported_ring_params;
3538 ret = ethnl_ops_begin(dev);
3639 if (ret < 0)
3740 return ret;
@@ -57,7 +60,9 @@ static int rings_reply_size(const struct ethnl_req_info *req_base, · 19 unmodified lines
5760 nla_total_size(sizeof(u8)) + /* _RINGS_TCP_DATA_SPLIT */
5861 nla_total_size(sizeof(u32) + /* _RINGS_CQE_SIZE */
5962 nla_total_size(sizeof(u8)) + /* _RINGS_TX_PUSH */
60− nla_total_size(sizeof(u8))); /* _RINGS_RX_PUSH */
63+ nla_total_size(sizeof(u8))) + /* _RINGS_RX_PUSH */
64+ nla_total_size(sizeof(u32)) + /* _RINGS_TX_PUSH_BUF_LEN */
65+ nla_total_size(sizeof(u32)); /* _RINGS_TX_PUSH_BUF_LEN_MAX */
6166 }
6267
6368 static int rings_fill_reply(struct sk_buff *skb,
@@ -67,6 +72,7 @@ static int rings_fill_reply(struct sk_buff *skb, · 3 unmodified lines
6772 const struct rings_reply_data *data = RINGS_REPDATA(reply_base);
6873 const struct kernel_ethtool_ringparam *kr = &data->kernel_ringparam;
6974 const struct ethtool_ringparam *ringparam = &data->ringparam;
75+ u32 supported_ring_params = data->supported_ring_params;
7076
7177 WARN_ON(kr->tcp_data_split > ETHTOOL_TCP_DATA_SPLIT_ENABLED);
7278
@@ -98,7 +104,12 @@ static int rings_fill_reply(struct sk_buff *skb, · 25 unmodified lines
98104 (kr->cqe_size &&
99105 (nla_put_u32(skb, ETHTOOL_A_RINGS_CQE_SIZE, kr->cqe_size))) ||
100106 nla_put_u8(skb, ETHTOOL_A_RINGS_TX_PUSH, !!kr->tx_push) ||
101− nla_put_u8(skb, ETHTOOL_A_RINGS_RX_PUSH, !!kr->rx_push))
107+ nla_put_u8(skb, ETHTOOL_A_RINGS_RX_PUSH, !!kr->rx_push) ||
108+ ((supported_ring_params & ETHTOOL_RING_USE_TX_PUSH_BUF_LEN) &&
109+ (nla_put_u32(skb, ETHTOOL_A_RINGS_TX_PUSH_BUF_LEN_MAX,
110+ kr->tx_push_buf_max_len) ||
111+ nla_put_u32(skb, ETHTOOL_A_RINGS_TX_PUSH_BUF_LEN,
112+ kr->tx_push_buf_len))))
102113 return -EMSGSIZE;
103114
104115 return 0;
@@ -117,6 +128,7 @@ const struct nla_policy ethnl_rings_set_policy[] = { · 12 unmodified lines
117128 [ETHTOOL_A_RINGS_CQE_SIZE] = NLA_POLICY_MIN(NLA_U32, 1),
118129 [ETHTOOL_A_RINGS_TX_PUSH] = NLA_POLICY_MAX(NLA_U8, 1),
119130 [ETHTOOL_A_RINGS_RX_PUSH] = NLA_POLICY_MAX(NLA_U8, 1),
131+ [ETHTOOL_A_RINGS_TX_PUSH_BUF_LEN] = { .type = NLA_U32 },
120132 };
121133
122134 static int
@@ -158,6 +170,14 @@ ethnl_set_rings_validate(struct ethnl_req_info *req_info, · 35 unmodified lines
158170 return -EOPNOTSUPP;
159171 }
160172
173+ if (tb[ETHTOOL_A_RINGS_TX_PUSH_BUF_LEN] &&
174+ !(ops->supported_ring_params & ETHTOOL_RING_USE_TX_PUSH_BUF_LEN)) {
175+ NL_SET_ERR_MSG_ATTR(info->extack,
176+ tb[ETHTOOL_A_RINGS_TX_PUSH_BUF_LEN],
177+ "setting tx push buf len is not supported");
178+ return -EOPNOTSUPP;
179+ }
180+
161181 return ops->get_ringparam && ops->set_ringparam ? 1 : -EOPNOTSUPP;
162182 }
163183
@@ -189,6 +209,8 @@ ethnl_set_rings(struct ethnl_req_info *req_info, struct genl_info *info) · 25 unmodified lines
189209 tb[ETHTOOL_A_RINGS_TX_PUSH], &mod);
190210 ethnl_update_u8(&kernel_ringparam.rx_push,
191211 tb[ETHTOOL_A_RINGS_RX_PUSH], &mod);
212+ ethnl_update_u32(&kernel_ringparam.tx_push_buf_len,
213+ tb[ETHTOOL_A_RINGS_TX_PUSH_BUF_LEN], &mod);
192214 if (!mod)
193215 return 0;
194216
@@ -209,6 +231,14 @@ ethnl_set_rings(struct ethnl_req_info *req_info, struct genl_info *info) · 14 unmodified lines
209231 return -EINVAL;
210232 }
211233
234+ if (kernel_ringparam.tx_push_buf_len > kernel_ringparam.tx_push_buf_max_len) {
235+ NL_SET_ERR_MSG_ATTR_FMT(info->extack, tb[ETHTOOL_A_RINGS_TX_PUSH_BUF_LEN],
236+ "Requested TX push buffer exceeds the maximum of %u",
237+ kernel_ringparam.tx_push_buf_max_len);
238+
239+ return -EINVAL;
240+ }
241+
212242 ret = dev->ethtool_ops->set_ringparam(dev, &ringparam,
213243 &kernel_ringparam, info->extack);
214244 return ret < 0 ? ret : 1;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t