^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #include "netlink.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) #include "common.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) struct coalesce_req_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) struct ethnl_req_info base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) struct coalesce_reply_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) struct ethnl_reply_data base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) struct ethtool_coalesce coalesce;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) u32 supported_params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define COALESCE_REPDATA(__reply_base) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) container_of(__reply_base, struct coalesce_reply_data, base)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define __SUPPORTED_OFFSET ETHTOOL_A_COALESCE_RX_USECS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) static u32 attr_to_mask(unsigned int attr_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) return BIT(attr_type - __SUPPORTED_OFFSET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) /* build time check that indices in ethtool_ops::supported_coalesce_params
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * match corresponding attribute types with an offset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define __CHECK_SUPPORTED_OFFSET(x) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) static_assert((ETHTOOL_ ## x) == \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) BIT((ETHTOOL_A_ ## x) - __SUPPORTED_OFFSET))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) __CHECK_SUPPORTED_OFFSET(COALESCE_RX_USECS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) __CHECK_SUPPORTED_OFFSET(COALESCE_RX_MAX_FRAMES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) __CHECK_SUPPORTED_OFFSET(COALESCE_RX_USECS_IRQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) __CHECK_SUPPORTED_OFFSET(COALESCE_RX_MAX_FRAMES_IRQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) __CHECK_SUPPORTED_OFFSET(COALESCE_TX_USECS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) __CHECK_SUPPORTED_OFFSET(COALESCE_TX_MAX_FRAMES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) __CHECK_SUPPORTED_OFFSET(COALESCE_TX_USECS_IRQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) __CHECK_SUPPORTED_OFFSET(COALESCE_TX_MAX_FRAMES_IRQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) __CHECK_SUPPORTED_OFFSET(COALESCE_STATS_BLOCK_USECS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) __CHECK_SUPPORTED_OFFSET(COALESCE_USE_ADAPTIVE_RX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) __CHECK_SUPPORTED_OFFSET(COALESCE_USE_ADAPTIVE_TX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) __CHECK_SUPPORTED_OFFSET(COALESCE_PKT_RATE_LOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) __CHECK_SUPPORTED_OFFSET(COALESCE_RX_USECS_LOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) __CHECK_SUPPORTED_OFFSET(COALESCE_RX_MAX_FRAMES_LOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) __CHECK_SUPPORTED_OFFSET(COALESCE_TX_USECS_LOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) __CHECK_SUPPORTED_OFFSET(COALESCE_TX_MAX_FRAMES_LOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) __CHECK_SUPPORTED_OFFSET(COALESCE_PKT_RATE_HIGH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) __CHECK_SUPPORTED_OFFSET(COALESCE_RX_USECS_HIGH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) __CHECK_SUPPORTED_OFFSET(COALESCE_RX_MAX_FRAMES_HIGH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) __CHECK_SUPPORTED_OFFSET(COALESCE_TX_USECS_HIGH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) __CHECK_SUPPORTED_OFFSET(COALESCE_TX_MAX_FRAMES_HIGH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) __CHECK_SUPPORTED_OFFSET(COALESCE_RATE_SAMPLE_INTERVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) const struct nla_policy ethnl_coalesce_get_policy[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) [ETHTOOL_A_COALESCE_HEADER] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) NLA_POLICY_NESTED(ethnl_header_policy),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) static int coalesce_prepare_data(const struct ethnl_req_info *req_base,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) struct ethnl_reply_data *reply_base,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) struct genl_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) struct coalesce_reply_data *data = COALESCE_REPDATA(reply_base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) struct net_device *dev = reply_base->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) if (!dev->ethtool_ops->get_coalesce)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) data->supported_params = dev->ethtool_ops->supported_coalesce_params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) ret = ethnl_ops_begin(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) ret = dev->ethtool_ops->get_coalesce(dev, &data->coalesce);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) ethnl_ops_complete(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) static int coalesce_reply_size(const struct ethnl_req_info *req_base,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) const struct ethnl_reply_data *reply_base)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) return nla_total_size(sizeof(u32)) + /* _RX_USECS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) nla_total_size(sizeof(u32)) + /* _RX_MAX_FRAMES */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) nla_total_size(sizeof(u32)) + /* _RX_USECS_IRQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) nla_total_size(sizeof(u32)) + /* _RX_MAX_FRAMES_IRQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) nla_total_size(sizeof(u32)) + /* _TX_USECS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) nla_total_size(sizeof(u32)) + /* _TX_MAX_FRAMES */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) nla_total_size(sizeof(u32)) + /* _TX_USECS_IRQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) nla_total_size(sizeof(u32)) + /* _TX_MAX_FRAMES_IRQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) nla_total_size(sizeof(u32)) + /* _STATS_BLOCK_USECS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) nla_total_size(sizeof(u8)) + /* _USE_ADAPTIVE_RX */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) nla_total_size(sizeof(u8)) + /* _USE_ADAPTIVE_TX */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) nla_total_size(sizeof(u32)) + /* _PKT_RATE_LOW */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) nla_total_size(sizeof(u32)) + /* _RX_USECS_LOW */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) nla_total_size(sizeof(u32)) + /* _RX_MAX_FRAMES_LOW */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) nla_total_size(sizeof(u32)) + /* _TX_USECS_LOW */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) nla_total_size(sizeof(u32)) + /* _TX_MAX_FRAMES_LOW */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) nla_total_size(sizeof(u32)) + /* _PKT_RATE_HIGH */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) nla_total_size(sizeof(u32)) + /* _RX_USECS_HIGH */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) nla_total_size(sizeof(u32)) + /* _RX_MAX_FRAMES_HIGH */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) nla_total_size(sizeof(u32)) + /* _TX_USECS_HIGH */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) nla_total_size(sizeof(u32)) + /* _TX_MAX_FRAMES_HIGH */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) nla_total_size(sizeof(u32)); /* _RATE_SAMPLE_INTERVAL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) static bool coalesce_put_u32(struct sk_buff *skb, u16 attr_type, u32 val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) u32 supported_params)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) if (!val && !(supported_params & attr_to_mask(attr_type)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) return nla_put_u32(skb, attr_type, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static bool coalesce_put_bool(struct sk_buff *skb, u16 attr_type, u32 val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) u32 supported_params)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) if (!val && !(supported_params & attr_to_mask(attr_type)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) return nla_put_u8(skb, attr_type, !!val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) static int coalesce_fill_reply(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) const struct ethnl_req_info *req_base,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) const struct ethnl_reply_data *reply_base)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) const struct coalesce_reply_data *data = COALESCE_REPDATA(reply_base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) const struct ethtool_coalesce *coal = &data->coalesce;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) u32 supported = data->supported_params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) if (coalesce_put_u32(skb, ETHTOOL_A_COALESCE_RX_USECS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) coal->rx_coalesce_usecs, supported) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) coalesce_put_u32(skb, ETHTOOL_A_COALESCE_RX_MAX_FRAMES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) coal->rx_max_coalesced_frames, supported) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) coalesce_put_u32(skb, ETHTOOL_A_COALESCE_RX_USECS_IRQ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) coal->rx_coalesce_usecs_irq, supported) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) coalesce_put_u32(skb, ETHTOOL_A_COALESCE_RX_MAX_FRAMES_IRQ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) coal->rx_max_coalesced_frames_irq, supported) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) coalesce_put_u32(skb, ETHTOOL_A_COALESCE_TX_USECS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) coal->tx_coalesce_usecs, supported) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) coalesce_put_u32(skb, ETHTOOL_A_COALESCE_TX_MAX_FRAMES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) coal->tx_max_coalesced_frames, supported) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) coalesce_put_u32(skb, ETHTOOL_A_COALESCE_TX_USECS_IRQ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) coal->tx_coalesce_usecs_irq, supported) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) coalesce_put_u32(skb, ETHTOOL_A_COALESCE_TX_MAX_FRAMES_IRQ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) coal->tx_max_coalesced_frames_irq, supported) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) coalesce_put_u32(skb, ETHTOOL_A_COALESCE_STATS_BLOCK_USECS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) coal->stats_block_coalesce_usecs, supported) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) coalesce_put_bool(skb, ETHTOOL_A_COALESCE_USE_ADAPTIVE_RX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) coal->use_adaptive_rx_coalesce, supported) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) coalesce_put_bool(skb, ETHTOOL_A_COALESCE_USE_ADAPTIVE_TX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) coal->use_adaptive_tx_coalesce, supported) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) coalesce_put_u32(skb, ETHTOOL_A_COALESCE_PKT_RATE_LOW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) coal->pkt_rate_low, supported) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) coalesce_put_u32(skb, ETHTOOL_A_COALESCE_RX_USECS_LOW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) coal->rx_coalesce_usecs_low, supported) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) coalesce_put_u32(skb, ETHTOOL_A_COALESCE_RX_MAX_FRAMES_LOW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) coal->rx_max_coalesced_frames_low, supported) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) coalesce_put_u32(skb, ETHTOOL_A_COALESCE_TX_USECS_LOW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) coal->tx_coalesce_usecs_low, supported) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) coalesce_put_u32(skb, ETHTOOL_A_COALESCE_TX_MAX_FRAMES_LOW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) coal->tx_max_coalesced_frames_low, supported) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) coalesce_put_u32(skb, ETHTOOL_A_COALESCE_PKT_RATE_HIGH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) coal->pkt_rate_high, supported) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) coalesce_put_u32(skb, ETHTOOL_A_COALESCE_RX_USECS_HIGH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) coal->rx_coalesce_usecs_high, supported) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) coalesce_put_u32(skb, ETHTOOL_A_COALESCE_RX_MAX_FRAMES_HIGH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) coal->rx_max_coalesced_frames_high, supported) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) coalesce_put_u32(skb, ETHTOOL_A_COALESCE_TX_USECS_HIGH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) coal->tx_coalesce_usecs_high, supported) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) coalesce_put_u32(skb, ETHTOOL_A_COALESCE_TX_MAX_FRAMES_HIGH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) coal->tx_max_coalesced_frames_high, supported) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) coalesce_put_u32(skb, ETHTOOL_A_COALESCE_RATE_SAMPLE_INTERVAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) coal->rate_sample_interval, supported))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) const struct ethnl_request_ops ethnl_coalesce_request_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) .request_cmd = ETHTOOL_MSG_COALESCE_GET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) .reply_cmd = ETHTOOL_MSG_COALESCE_GET_REPLY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) .hdr_attr = ETHTOOL_A_COALESCE_HEADER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) .req_info_size = sizeof(struct coalesce_req_info),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) .reply_data_size = sizeof(struct coalesce_reply_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) .prepare_data = coalesce_prepare_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) .reply_size = coalesce_reply_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) .fill_reply = coalesce_fill_reply,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) /* COALESCE_SET */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) const struct nla_policy ethnl_coalesce_set_policy[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) [ETHTOOL_A_COALESCE_HEADER] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) NLA_POLICY_NESTED(ethnl_header_policy),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) [ETHTOOL_A_COALESCE_RX_USECS] = { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) [ETHTOOL_A_COALESCE_RX_MAX_FRAMES] = { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) [ETHTOOL_A_COALESCE_RX_USECS_IRQ] = { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) [ETHTOOL_A_COALESCE_RX_MAX_FRAMES_IRQ] = { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) [ETHTOOL_A_COALESCE_TX_USECS] = { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) [ETHTOOL_A_COALESCE_TX_MAX_FRAMES] = { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) [ETHTOOL_A_COALESCE_TX_USECS_IRQ] = { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) [ETHTOOL_A_COALESCE_TX_MAX_FRAMES_IRQ] = { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) [ETHTOOL_A_COALESCE_STATS_BLOCK_USECS] = { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) [ETHTOOL_A_COALESCE_USE_ADAPTIVE_RX] = { .type = NLA_U8 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) [ETHTOOL_A_COALESCE_USE_ADAPTIVE_TX] = { .type = NLA_U8 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) [ETHTOOL_A_COALESCE_PKT_RATE_LOW] = { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) [ETHTOOL_A_COALESCE_RX_USECS_LOW] = { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) [ETHTOOL_A_COALESCE_RX_MAX_FRAMES_LOW] = { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) [ETHTOOL_A_COALESCE_TX_USECS_LOW] = { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) [ETHTOOL_A_COALESCE_TX_MAX_FRAMES_LOW] = { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) [ETHTOOL_A_COALESCE_PKT_RATE_HIGH] = { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) [ETHTOOL_A_COALESCE_RX_USECS_HIGH] = { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) [ETHTOOL_A_COALESCE_RX_MAX_FRAMES_HIGH] = { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) [ETHTOOL_A_COALESCE_TX_USECS_HIGH] = { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) [ETHTOOL_A_COALESCE_TX_MAX_FRAMES_HIGH] = { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) [ETHTOOL_A_COALESCE_RATE_SAMPLE_INTERVAL] = { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) int ethnl_set_coalesce(struct sk_buff *skb, struct genl_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) struct ethtool_coalesce coalesce = {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) struct ethnl_req_info req_info = {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) struct nlattr **tb = info->attrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) const struct ethtool_ops *ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) u32 supported_params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) bool mod = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) u16 a;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) ret = ethnl_parse_header_dev_get(&req_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) tb[ETHTOOL_A_COALESCE_HEADER],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) genl_info_net(info), info->extack,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) dev = req_info.dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) ops = dev->ethtool_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) ret = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) if (!ops->get_coalesce || !ops->set_coalesce)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) goto out_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) /* make sure that only supported parameters are present */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) supported_params = ops->supported_coalesce_params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) for (a = ETHTOOL_A_COALESCE_RX_USECS; a < __ETHTOOL_A_COALESCE_CNT; a++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) if (tb[a] && !(supported_params & attr_to_mask(a))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) NL_SET_ERR_MSG_ATTR(info->extack, tb[a],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) "cannot modify an unsupported parameter");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) goto out_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) rtnl_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) ret = ethnl_ops_begin(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) goto out_rtnl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) ret = ops->get_coalesce(dev, &coalesce);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) goto out_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) ethnl_update_u32(&coalesce.rx_coalesce_usecs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) tb[ETHTOOL_A_COALESCE_RX_USECS], &mod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) ethnl_update_u32(&coalesce.rx_max_coalesced_frames,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) tb[ETHTOOL_A_COALESCE_RX_MAX_FRAMES], &mod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) ethnl_update_u32(&coalesce.rx_coalesce_usecs_irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) tb[ETHTOOL_A_COALESCE_RX_USECS_IRQ], &mod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) ethnl_update_u32(&coalesce.rx_max_coalesced_frames_irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) tb[ETHTOOL_A_COALESCE_RX_MAX_FRAMES_IRQ], &mod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) ethnl_update_u32(&coalesce.tx_coalesce_usecs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) tb[ETHTOOL_A_COALESCE_TX_USECS], &mod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) ethnl_update_u32(&coalesce.tx_max_coalesced_frames,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) tb[ETHTOOL_A_COALESCE_TX_MAX_FRAMES], &mod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) ethnl_update_u32(&coalesce.tx_coalesce_usecs_irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) tb[ETHTOOL_A_COALESCE_TX_USECS_IRQ], &mod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) ethnl_update_u32(&coalesce.tx_max_coalesced_frames_irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) tb[ETHTOOL_A_COALESCE_TX_MAX_FRAMES_IRQ], &mod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) ethnl_update_u32(&coalesce.stats_block_coalesce_usecs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) tb[ETHTOOL_A_COALESCE_STATS_BLOCK_USECS], &mod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) ethnl_update_bool32(&coalesce.use_adaptive_rx_coalesce,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) tb[ETHTOOL_A_COALESCE_USE_ADAPTIVE_RX], &mod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) ethnl_update_bool32(&coalesce.use_adaptive_tx_coalesce,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) tb[ETHTOOL_A_COALESCE_USE_ADAPTIVE_TX], &mod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) ethnl_update_u32(&coalesce.pkt_rate_low,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) tb[ETHTOOL_A_COALESCE_PKT_RATE_LOW], &mod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) ethnl_update_u32(&coalesce.rx_coalesce_usecs_low,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) tb[ETHTOOL_A_COALESCE_RX_USECS_LOW], &mod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) ethnl_update_u32(&coalesce.rx_max_coalesced_frames_low,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) tb[ETHTOOL_A_COALESCE_RX_MAX_FRAMES_LOW], &mod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) ethnl_update_u32(&coalesce.tx_coalesce_usecs_low,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) tb[ETHTOOL_A_COALESCE_TX_USECS_LOW], &mod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) ethnl_update_u32(&coalesce.tx_max_coalesced_frames_low,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) tb[ETHTOOL_A_COALESCE_TX_MAX_FRAMES_LOW], &mod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) ethnl_update_u32(&coalesce.pkt_rate_high,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) tb[ETHTOOL_A_COALESCE_PKT_RATE_HIGH], &mod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) ethnl_update_u32(&coalesce.rx_coalesce_usecs_high,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) tb[ETHTOOL_A_COALESCE_RX_USECS_HIGH], &mod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) ethnl_update_u32(&coalesce.rx_max_coalesced_frames_high,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) tb[ETHTOOL_A_COALESCE_RX_MAX_FRAMES_HIGH], &mod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) ethnl_update_u32(&coalesce.tx_coalesce_usecs_high,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) tb[ETHTOOL_A_COALESCE_TX_USECS_HIGH], &mod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) ethnl_update_u32(&coalesce.tx_max_coalesced_frames_high,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) tb[ETHTOOL_A_COALESCE_TX_MAX_FRAMES_HIGH], &mod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) ethnl_update_u32(&coalesce.rate_sample_interval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) tb[ETHTOOL_A_COALESCE_RATE_SAMPLE_INTERVAL], &mod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) if (!mod)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) goto out_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) ret = dev->ethtool_ops->set_coalesce(dev, &coalesce);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) goto out_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) ethtool_notify(dev, ETHTOOL_MSG_COALESCE_NTF, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) out_ops:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) ethnl_ops_complete(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) out_rtnl:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) out_dev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) dev_put(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) }