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

ethtool: provide pause parameters with PAUSE_GET request

Implement PAUSE_GET request to get pause parameters of a network device.
These are traditionally available via ETHTOOL_GPAUSEPARAM ioctl request.

Signed-off-by: Michal Kubecek <mkubecek@suse.cz>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Michal Kubecek and committed by
David S. Miller
7f59fb32 0cf3eac8

+146 -2
+39 -1
Documentation/networking/ethtool-netlink.rst
··· 199 199 ``ETHTOOL_MSG_CHANNELS_SET`` set channel counts 200 200 ``ETHTOOL_MSG_COALESCE_GET`` get coalescing parameters 201 201 ``ETHTOOL_MSG_COALESCE_SET`` set coalescing parameters 202 + ``ETHTOOL_MSG_PAUSE_GET`` get pause parameters 202 203 ===================================== ================================ 203 204 204 205 Kernel to userspace: ··· 226 225 ``ETHTOOL_MSG_CHANNELS_NTF`` channel counts 227 226 ``ETHTOOL_MSG_COALESCE_GET_REPLY`` coalescing parameters 228 227 ``ETHTOOL_MSG_COALESCE_NTF`` coalescing parameters 228 + ``ETHTOOL_MSG_PAUSE_GET_REPLY`` pause parameters 229 229 ===================================== ================================= 230 230 231 231 ``GET`` requests are sent by userspace applications to retrieve device ··· 834 832 constraints on coalescing parameters and their values. 835 833 836 834 835 + PAUSE_GET 836 + ============ 837 + 838 + Gets channel counts like ``ETHTOOL_GPAUSE`` ioctl request. 839 + 840 + Request contents: 841 + 842 + ===================================== ====== ========================== 843 + ``ETHTOOL_A_PAUSE_HEADER`` nested request header 844 + ===================================== ====== ========================== 845 + 846 + Kernel response contents: 847 + 848 + ===================================== ====== ========================== 849 + ``ETHTOOL_A_PAUSE_HEADER`` nested request header 850 + ``ETHTOOL_A_PAUSE_AUTONEG`` bool pause autonegotiation 851 + ``ETHTOOL_A_PAUSE_RX`` bool receive pause frames 852 + ``ETHTOOL_A_PAUSE_TX`` bool transmit pause frames 853 + ===================================== ====== ========================== 854 + 855 + 856 + PAUSE_SET 857 + ============ 858 + 859 + Sets pause parameters like ``ETHTOOL_GPAUSEPARAM`` ioctl request. 860 + 861 + Request contents: 862 + 863 + ===================================== ====== ========================== 864 + ``ETHTOOL_A_PAUSE_HEADER`` nested request header 865 + ``ETHTOOL_A_PAUSE_AUTONEG`` bool pause autonegotiation 866 + ``ETHTOOL_A_PAUSE_RX`` bool receive pause frames 867 + ``ETHTOOL_A_PAUSE_TX`` bool transmit pause frames 868 + ===================================== ====== ========================== 869 + 870 + 837 871 Request translation 838 872 =================== 839 873 ··· 898 860 ``ETHTOOL_SCOALESCE`` ``ETHTOOL_MSG_COALESCE_SET`` 899 861 ``ETHTOOL_GRINGPARAM`` ``ETHTOOL_MSG_RINGS_GET`` 900 862 ``ETHTOOL_SRINGPARAM`` ``ETHTOOL_MSG_RINGS_SET`` 901 - ``ETHTOOL_GPAUSEPARAM`` n/a 863 + ``ETHTOOL_GPAUSEPARAM`` ``ETHTOOL_MSG_PAUSE_GET`` 902 864 ``ETHTOOL_SPAUSEPARAM`` n/a 903 865 ``ETHTOOL_GRXCSUM`` ``ETHTOOL_MSG_FEATURES_GET`` 904 866 ``ETHTOOL_SRXCSUM`` ``ETHTOOL_MSG_FEATURES_SET``
+16
include/uapi/linux/ethtool_netlink.h
··· 34 34 ETHTOOL_MSG_CHANNELS_SET, 35 35 ETHTOOL_MSG_COALESCE_GET, 36 36 ETHTOOL_MSG_COALESCE_SET, 37 + ETHTOOL_MSG_PAUSE_GET, 37 38 38 39 /* add new constants above here */ 39 40 __ETHTOOL_MSG_USER_CNT, ··· 65 64 ETHTOOL_MSG_CHANNELS_NTF, 66 65 ETHTOOL_MSG_COALESCE_GET_REPLY, 67 66 ETHTOOL_MSG_COALESCE_NTF, 67 + ETHTOOL_MSG_PAUSE_GET_REPLY, 68 68 69 69 /* add new constants above here */ 70 70 __ETHTOOL_MSG_KERNEL_CNT, ··· 347 345 /* add new constants above here */ 348 346 __ETHTOOL_A_COALESCE_CNT, 349 347 ETHTOOL_A_COALESCE_MAX = (__ETHTOOL_A_COALESCE_CNT - 1) 348 + }; 349 + 350 + /* PAUSE */ 351 + 352 + enum { 353 + ETHTOOL_A_PAUSE_UNSPEC, 354 + ETHTOOL_A_PAUSE_HEADER, /* nest - _A_HEADER_* */ 355 + ETHTOOL_A_PAUSE_AUTONEG, /* u8 */ 356 + ETHTOOL_A_PAUSE_RX, /* u8 */ 357 + ETHTOOL_A_PAUSE_TX, /* u8 */ 358 + 359 + /* add new constants above here */ 360 + __ETHTOOL_A_PAUSE_CNT, 361 + ETHTOOL_A_PAUSE_MAX = (__ETHTOOL_A_PAUSE_CNT - 1) 350 362 }; 351 363 352 364 /* generic netlink info */
+1 -1
net/ethtool/Makefile
··· 6 6 7 7 ethtool_nl-y := netlink.o bitset.o strset.o linkinfo.o linkmodes.o \ 8 8 linkstate.o debug.o wol.o features.o privflags.o rings.o \ 9 - channels.o coalesce.o 9 + channels.o coalesce.o pause.o
+8
net/ethtool/netlink.c
··· 228 228 [ETHTOOL_MSG_RINGS_GET] = &ethnl_rings_request_ops, 229 229 [ETHTOOL_MSG_CHANNELS_GET] = &ethnl_channels_request_ops, 230 230 [ETHTOOL_MSG_COALESCE_GET] = &ethnl_coalesce_request_ops, 231 + [ETHTOOL_MSG_PAUSE_GET] = &ethnl_pause_request_ops, 231 232 }; 232 233 233 234 static struct ethnl_dump_ctx *ethnl_dump_context(struct netlink_callback *cb) ··· 801 800 .cmd = ETHTOOL_MSG_COALESCE_SET, 802 801 .flags = GENL_UNS_ADMIN_PERM, 803 802 .doit = ethnl_set_coalesce, 803 + }, 804 + { 805 + .cmd = ETHTOOL_MSG_PAUSE_GET, 806 + .doit = ethnl_default_doit, 807 + .start = ethnl_default_start, 808 + .dumpit = ethnl_default_dumpit, 809 + .done = ethnl_default_done, 804 810 }, 805 811 }; 806 812
+1
net/ethtool/netlink.h
··· 342 342 extern const struct ethnl_request_ops ethnl_rings_request_ops; 343 343 extern const struct ethnl_request_ops ethnl_channels_request_ops; 344 344 extern const struct ethnl_request_ops ethnl_coalesce_request_ops; 345 + extern const struct ethnl_request_ops ethnl_pause_request_ops; 345 346 346 347 int ethnl_set_linkinfo(struct sk_buff *skb, struct genl_info *info); 347 348 int ethnl_set_linkmodes(struct sk_buff *skb, struct genl_info *info);
+81
net/ethtool/pause.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + 3 + #include "netlink.h" 4 + #include "common.h" 5 + 6 + struct pause_req_info { 7 + struct ethnl_req_info base; 8 + }; 9 + 10 + struct pause_reply_data { 11 + struct ethnl_reply_data base; 12 + struct ethtool_pauseparam pauseparam; 13 + }; 14 + 15 + #define PAUSE_REPDATA(__reply_base) \ 16 + container_of(__reply_base, struct pause_reply_data, base) 17 + 18 + static const struct nla_policy 19 + pause_get_policy[ETHTOOL_A_PAUSE_MAX + 1] = { 20 + [ETHTOOL_A_PAUSE_UNSPEC] = { .type = NLA_REJECT }, 21 + [ETHTOOL_A_PAUSE_HEADER] = { .type = NLA_NESTED }, 22 + [ETHTOOL_A_PAUSE_AUTONEG] = { .type = NLA_REJECT }, 23 + [ETHTOOL_A_PAUSE_RX] = { .type = NLA_REJECT }, 24 + [ETHTOOL_A_PAUSE_TX] = { .type = NLA_REJECT }, 25 + }; 26 + 27 + static int pause_prepare_data(const struct ethnl_req_info *req_base, 28 + struct ethnl_reply_data *reply_base, 29 + struct genl_info *info) 30 + { 31 + struct pause_reply_data *data = PAUSE_REPDATA(reply_base); 32 + struct net_device *dev = reply_base->dev; 33 + int ret; 34 + 35 + if (!dev->ethtool_ops->get_pauseparam) 36 + return -EOPNOTSUPP; 37 + ret = ethnl_ops_begin(dev); 38 + if (ret < 0) 39 + return ret; 40 + dev->ethtool_ops->get_pauseparam(dev, &data->pauseparam); 41 + ethnl_ops_complete(dev); 42 + 43 + return 0; 44 + } 45 + 46 + static int pause_reply_size(const struct ethnl_req_info *req_base, 47 + const struct ethnl_reply_data *reply_base) 48 + { 49 + return nla_total_size(sizeof(u8)) + /* _PAUSE_AUTONEG */ 50 + nla_total_size(sizeof(u8)) + /* _PAUSE_RX */ 51 + nla_total_size(sizeof(u8)); /* _PAUSE_TX */ 52 + } 53 + 54 + static int pause_fill_reply(struct sk_buff *skb, 55 + const struct ethnl_req_info *req_base, 56 + const struct ethnl_reply_data *reply_base) 57 + { 58 + const struct pause_reply_data *data = PAUSE_REPDATA(reply_base); 59 + const struct ethtool_pauseparam *pauseparam = &data->pauseparam; 60 + 61 + if (nla_put_u8(skb, ETHTOOL_A_PAUSE_AUTONEG, !!pauseparam->autoneg) || 62 + nla_put_u8(skb, ETHTOOL_A_PAUSE_RX, !!pauseparam->rx_pause) || 63 + nla_put_u8(skb, ETHTOOL_A_PAUSE_TX, !!pauseparam->tx_pause)) 64 + return -EMSGSIZE; 65 + 66 + return 0; 67 + } 68 + 69 + const struct ethnl_request_ops ethnl_pause_request_ops = { 70 + .request_cmd = ETHTOOL_MSG_PAUSE_GET, 71 + .reply_cmd = ETHTOOL_MSG_PAUSE_GET_REPLY, 72 + .hdr_attr = ETHTOOL_A_PAUSE_HEADER, 73 + .max_attr = ETHTOOL_A_PAUSE_MAX, 74 + .req_info_size = sizeof(struct pause_req_info), 75 + .reply_data_size = sizeof(struct pause_reply_data), 76 + .request_policy = pause_get_policy, 77 + 78 + .prepare_data = pause_prepare_data, 79 + .reply_size = pause_reply_size, 80 + .fill_reply = pause_fill_reply, 81 + };