18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci 38c2ecf20Sopenharmony_ci#include "netlink.h" 48c2ecf20Sopenharmony_ci#include "common.h" 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_cistruct coalesce_req_info { 78c2ecf20Sopenharmony_ci struct ethnl_req_info base; 88c2ecf20Sopenharmony_ci}; 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_cistruct coalesce_reply_data { 118c2ecf20Sopenharmony_ci struct ethnl_reply_data base; 128c2ecf20Sopenharmony_ci struct ethtool_coalesce coalesce; 138c2ecf20Sopenharmony_ci u32 supported_params; 148c2ecf20Sopenharmony_ci}; 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci#define COALESCE_REPDATA(__reply_base) \ 178c2ecf20Sopenharmony_ci container_of(__reply_base, struct coalesce_reply_data, base) 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci#define __SUPPORTED_OFFSET ETHTOOL_A_COALESCE_RX_USECS 208c2ecf20Sopenharmony_cistatic u32 attr_to_mask(unsigned int attr_type) 218c2ecf20Sopenharmony_ci{ 228c2ecf20Sopenharmony_ci return BIT(attr_type - __SUPPORTED_OFFSET); 238c2ecf20Sopenharmony_ci} 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci/* build time check that indices in ethtool_ops::supported_coalesce_params 268c2ecf20Sopenharmony_ci * match corresponding attribute types with an offset 278c2ecf20Sopenharmony_ci */ 288c2ecf20Sopenharmony_ci#define __CHECK_SUPPORTED_OFFSET(x) \ 298c2ecf20Sopenharmony_ci static_assert((ETHTOOL_ ## x) == \ 308c2ecf20Sopenharmony_ci BIT((ETHTOOL_A_ ## x) - __SUPPORTED_OFFSET)) 318c2ecf20Sopenharmony_ci__CHECK_SUPPORTED_OFFSET(COALESCE_RX_USECS); 328c2ecf20Sopenharmony_ci__CHECK_SUPPORTED_OFFSET(COALESCE_RX_MAX_FRAMES); 338c2ecf20Sopenharmony_ci__CHECK_SUPPORTED_OFFSET(COALESCE_RX_USECS_IRQ); 348c2ecf20Sopenharmony_ci__CHECK_SUPPORTED_OFFSET(COALESCE_RX_MAX_FRAMES_IRQ); 358c2ecf20Sopenharmony_ci__CHECK_SUPPORTED_OFFSET(COALESCE_TX_USECS); 368c2ecf20Sopenharmony_ci__CHECK_SUPPORTED_OFFSET(COALESCE_TX_MAX_FRAMES); 378c2ecf20Sopenharmony_ci__CHECK_SUPPORTED_OFFSET(COALESCE_TX_USECS_IRQ); 388c2ecf20Sopenharmony_ci__CHECK_SUPPORTED_OFFSET(COALESCE_TX_MAX_FRAMES_IRQ); 398c2ecf20Sopenharmony_ci__CHECK_SUPPORTED_OFFSET(COALESCE_STATS_BLOCK_USECS); 408c2ecf20Sopenharmony_ci__CHECK_SUPPORTED_OFFSET(COALESCE_USE_ADAPTIVE_RX); 418c2ecf20Sopenharmony_ci__CHECK_SUPPORTED_OFFSET(COALESCE_USE_ADAPTIVE_TX); 428c2ecf20Sopenharmony_ci__CHECK_SUPPORTED_OFFSET(COALESCE_PKT_RATE_LOW); 438c2ecf20Sopenharmony_ci__CHECK_SUPPORTED_OFFSET(COALESCE_RX_USECS_LOW); 448c2ecf20Sopenharmony_ci__CHECK_SUPPORTED_OFFSET(COALESCE_RX_MAX_FRAMES_LOW); 458c2ecf20Sopenharmony_ci__CHECK_SUPPORTED_OFFSET(COALESCE_TX_USECS_LOW); 468c2ecf20Sopenharmony_ci__CHECK_SUPPORTED_OFFSET(COALESCE_TX_MAX_FRAMES_LOW); 478c2ecf20Sopenharmony_ci__CHECK_SUPPORTED_OFFSET(COALESCE_PKT_RATE_HIGH); 488c2ecf20Sopenharmony_ci__CHECK_SUPPORTED_OFFSET(COALESCE_RX_USECS_HIGH); 498c2ecf20Sopenharmony_ci__CHECK_SUPPORTED_OFFSET(COALESCE_RX_MAX_FRAMES_HIGH); 508c2ecf20Sopenharmony_ci__CHECK_SUPPORTED_OFFSET(COALESCE_TX_USECS_HIGH); 518c2ecf20Sopenharmony_ci__CHECK_SUPPORTED_OFFSET(COALESCE_TX_MAX_FRAMES_HIGH); 528c2ecf20Sopenharmony_ci__CHECK_SUPPORTED_OFFSET(COALESCE_RATE_SAMPLE_INTERVAL); 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ciconst struct nla_policy ethnl_coalesce_get_policy[] = { 558c2ecf20Sopenharmony_ci [ETHTOOL_A_COALESCE_HEADER] = 568c2ecf20Sopenharmony_ci NLA_POLICY_NESTED(ethnl_header_policy), 578c2ecf20Sopenharmony_ci}; 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_cistatic int coalesce_prepare_data(const struct ethnl_req_info *req_base, 608c2ecf20Sopenharmony_ci struct ethnl_reply_data *reply_base, 618c2ecf20Sopenharmony_ci struct genl_info *info) 628c2ecf20Sopenharmony_ci{ 638c2ecf20Sopenharmony_ci struct coalesce_reply_data *data = COALESCE_REPDATA(reply_base); 648c2ecf20Sopenharmony_ci struct net_device *dev = reply_base->dev; 658c2ecf20Sopenharmony_ci int ret; 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci if (!dev->ethtool_ops->get_coalesce) 688c2ecf20Sopenharmony_ci return -EOPNOTSUPP; 698c2ecf20Sopenharmony_ci data->supported_params = dev->ethtool_ops->supported_coalesce_params; 708c2ecf20Sopenharmony_ci ret = ethnl_ops_begin(dev); 718c2ecf20Sopenharmony_ci if (ret < 0) 728c2ecf20Sopenharmony_ci return ret; 738c2ecf20Sopenharmony_ci ret = dev->ethtool_ops->get_coalesce(dev, &data->coalesce); 748c2ecf20Sopenharmony_ci ethnl_ops_complete(dev); 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci return ret; 778c2ecf20Sopenharmony_ci} 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_cistatic int coalesce_reply_size(const struct ethnl_req_info *req_base, 808c2ecf20Sopenharmony_ci const struct ethnl_reply_data *reply_base) 818c2ecf20Sopenharmony_ci{ 828c2ecf20Sopenharmony_ci return nla_total_size(sizeof(u32)) + /* _RX_USECS */ 838c2ecf20Sopenharmony_ci nla_total_size(sizeof(u32)) + /* _RX_MAX_FRAMES */ 848c2ecf20Sopenharmony_ci nla_total_size(sizeof(u32)) + /* _RX_USECS_IRQ */ 858c2ecf20Sopenharmony_ci nla_total_size(sizeof(u32)) + /* _RX_MAX_FRAMES_IRQ */ 868c2ecf20Sopenharmony_ci nla_total_size(sizeof(u32)) + /* _TX_USECS */ 878c2ecf20Sopenharmony_ci nla_total_size(sizeof(u32)) + /* _TX_MAX_FRAMES */ 888c2ecf20Sopenharmony_ci nla_total_size(sizeof(u32)) + /* _TX_USECS_IRQ */ 898c2ecf20Sopenharmony_ci nla_total_size(sizeof(u32)) + /* _TX_MAX_FRAMES_IRQ */ 908c2ecf20Sopenharmony_ci nla_total_size(sizeof(u32)) + /* _STATS_BLOCK_USECS */ 918c2ecf20Sopenharmony_ci nla_total_size(sizeof(u8)) + /* _USE_ADAPTIVE_RX */ 928c2ecf20Sopenharmony_ci nla_total_size(sizeof(u8)) + /* _USE_ADAPTIVE_TX */ 938c2ecf20Sopenharmony_ci nla_total_size(sizeof(u32)) + /* _PKT_RATE_LOW */ 948c2ecf20Sopenharmony_ci nla_total_size(sizeof(u32)) + /* _RX_USECS_LOW */ 958c2ecf20Sopenharmony_ci nla_total_size(sizeof(u32)) + /* _RX_MAX_FRAMES_LOW */ 968c2ecf20Sopenharmony_ci nla_total_size(sizeof(u32)) + /* _TX_USECS_LOW */ 978c2ecf20Sopenharmony_ci nla_total_size(sizeof(u32)) + /* _TX_MAX_FRAMES_LOW */ 988c2ecf20Sopenharmony_ci nla_total_size(sizeof(u32)) + /* _PKT_RATE_HIGH */ 998c2ecf20Sopenharmony_ci nla_total_size(sizeof(u32)) + /* _RX_USECS_HIGH */ 1008c2ecf20Sopenharmony_ci nla_total_size(sizeof(u32)) + /* _RX_MAX_FRAMES_HIGH */ 1018c2ecf20Sopenharmony_ci nla_total_size(sizeof(u32)) + /* _TX_USECS_HIGH */ 1028c2ecf20Sopenharmony_ci nla_total_size(sizeof(u32)) + /* _TX_MAX_FRAMES_HIGH */ 1038c2ecf20Sopenharmony_ci nla_total_size(sizeof(u32)); /* _RATE_SAMPLE_INTERVAL */ 1048c2ecf20Sopenharmony_ci} 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_cistatic bool coalesce_put_u32(struct sk_buff *skb, u16 attr_type, u32 val, 1078c2ecf20Sopenharmony_ci u32 supported_params) 1088c2ecf20Sopenharmony_ci{ 1098c2ecf20Sopenharmony_ci if (!val && !(supported_params & attr_to_mask(attr_type))) 1108c2ecf20Sopenharmony_ci return false; 1118c2ecf20Sopenharmony_ci return nla_put_u32(skb, attr_type, val); 1128c2ecf20Sopenharmony_ci} 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_cistatic bool coalesce_put_bool(struct sk_buff *skb, u16 attr_type, u32 val, 1158c2ecf20Sopenharmony_ci u32 supported_params) 1168c2ecf20Sopenharmony_ci{ 1178c2ecf20Sopenharmony_ci if (!val && !(supported_params & attr_to_mask(attr_type))) 1188c2ecf20Sopenharmony_ci return false; 1198c2ecf20Sopenharmony_ci return nla_put_u8(skb, attr_type, !!val); 1208c2ecf20Sopenharmony_ci} 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_cistatic int coalesce_fill_reply(struct sk_buff *skb, 1238c2ecf20Sopenharmony_ci const struct ethnl_req_info *req_base, 1248c2ecf20Sopenharmony_ci const struct ethnl_reply_data *reply_base) 1258c2ecf20Sopenharmony_ci{ 1268c2ecf20Sopenharmony_ci const struct coalesce_reply_data *data = COALESCE_REPDATA(reply_base); 1278c2ecf20Sopenharmony_ci const struct ethtool_coalesce *coal = &data->coalesce; 1288c2ecf20Sopenharmony_ci u32 supported = data->supported_params; 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci if (coalesce_put_u32(skb, ETHTOOL_A_COALESCE_RX_USECS, 1318c2ecf20Sopenharmony_ci coal->rx_coalesce_usecs, supported) || 1328c2ecf20Sopenharmony_ci coalesce_put_u32(skb, ETHTOOL_A_COALESCE_RX_MAX_FRAMES, 1338c2ecf20Sopenharmony_ci coal->rx_max_coalesced_frames, supported) || 1348c2ecf20Sopenharmony_ci coalesce_put_u32(skb, ETHTOOL_A_COALESCE_RX_USECS_IRQ, 1358c2ecf20Sopenharmony_ci coal->rx_coalesce_usecs_irq, supported) || 1368c2ecf20Sopenharmony_ci coalesce_put_u32(skb, ETHTOOL_A_COALESCE_RX_MAX_FRAMES_IRQ, 1378c2ecf20Sopenharmony_ci coal->rx_max_coalesced_frames_irq, supported) || 1388c2ecf20Sopenharmony_ci coalesce_put_u32(skb, ETHTOOL_A_COALESCE_TX_USECS, 1398c2ecf20Sopenharmony_ci coal->tx_coalesce_usecs, supported) || 1408c2ecf20Sopenharmony_ci coalesce_put_u32(skb, ETHTOOL_A_COALESCE_TX_MAX_FRAMES, 1418c2ecf20Sopenharmony_ci coal->tx_max_coalesced_frames, supported) || 1428c2ecf20Sopenharmony_ci coalesce_put_u32(skb, ETHTOOL_A_COALESCE_TX_USECS_IRQ, 1438c2ecf20Sopenharmony_ci coal->tx_coalesce_usecs_irq, supported) || 1448c2ecf20Sopenharmony_ci coalesce_put_u32(skb, ETHTOOL_A_COALESCE_TX_MAX_FRAMES_IRQ, 1458c2ecf20Sopenharmony_ci coal->tx_max_coalesced_frames_irq, supported) || 1468c2ecf20Sopenharmony_ci coalesce_put_u32(skb, ETHTOOL_A_COALESCE_STATS_BLOCK_USECS, 1478c2ecf20Sopenharmony_ci coal->stats_block_coalesce_usecs, supported) || 1488c2ecf20Sopenharmony_ci coalesce_put_bool(skb, ETHTOOL_A_COALESCE_USE_ADAPTIVE_RX, 1498c2ecf20Sopenharmony_ci coal->use_adaptive_rx_coalesce, supported) || 1508c2ecf20Sopenharmony_ci coalesce_put_bool(skb, ETHTOOL_A_COALESCE_USE_ADAPTIVE_TX, 1518c2ecf20Sopenharmony_ci coal->use_adaptive_tx_coalesce, supported) || 1528c2ecf20Sopenharmony_ci coalesce_put_u32(skb, ETHTOOL_A_COALESCE_PKT_RATE_LOW, 1538c2ecf20Sopenharmony_ci coal->pkt_rate_low, supported) || 1548c2ecf20Sopenharmony_ci coalesce_put_u32(skb, ETHTOOL_A_COALESCE_RX_USECS_LOW, 1558c2ecf20Sopenharmony_ci coal->rx_coalesce_usecs_low, supported) || 1568c2ecf20Sopenharmony_ci coalesce_put_u32(skb, ETHTOOL_A_COALESCE_RX_MAX_FRAMES_LOW, 1578c2ecf20Sopenharmony_ci coal->rx_max_coalesced_frames_low, supported) || 1588c2ecf20Sopenharmony_ci coalesce_put_u32(skb, ETHTOOL_A_COALESCE_TX_USECS_LOW, 1598c2ecf20Sopenharmony_ci coal->tx_coalesce_usecs_low, supported) || 1608c2ecf20Sopenharmony_ci coalesce_put_u32(skb, ETHTOOL_A_COALESCE_TX_MAX_FRAMES_LOW, 1618c2ecf20Sopenharmony_ci coal->tx_max_coalesced_frames_low, supported) || 1628c2ecf20Sopenharmony_ci coalesce_put_u32(skb, ETHTOOL_A_COALESCE_PKT_RATE_HIGH, 1638c2ecf20Sopenharmony_ci coal->pkt_rate_high, supported) || 1648c2ecf20Sopenharmony_ci coalesce_put_u32(skb, ETHTOOL_A_COALESCE_RX_USECS_HIGH, 1658c2ecf20Sopenharmony_ci coal->rx_coalesce_usecs_high, supported) || 1668c2ecf20Sopenharmony_ci coalesce_put_u32(skb, ETHTOOL_A_COALESCE_RX_MAX_FRAMES_HIGH, 1678c2ecf20Sopenharmony_ci coal->rx_max_coalesced_frames_high, supported) || 1688c2ecf20Sopenharmony_ci coalesce_put_u32(skb, ETHTOOL_A_COALESCE_TX_USECS_HIGH, 1698c2ecf20Sopenharmony_ci coal->tx_coalesce_usecs_high, supported) || 1708c2ecf20Sopenharmony_ci coalesce_put_u32(skb, ETHTOOL_A_COALESCE_TX_MAX_FRAMES_HIGH, 1718c2ecf20Sopenharmony_ci coal->tx_max_coalesced_frames_high, supported) || 1728c2ecf20Sopenharmony_ci coalesce_put_u32(skb, ETHTOOL_A_COALESCE_RATE_SAMPLE_INTERVAL, 1738c2ecf20Sopenharmony_ci coal->rate_sample_interval, supported)) 1748c2ecf20Sopenharmony_ci return -EMSGSIZE; 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ci return 0; 1778c2ecf20Sopenharmony_ci} 1788c2ecf20Sopenharmony_ci 1798c2ecf20Sopenharmony_ciconst struct ethnl_request_ops ethnl_coalesce_request_ops = { 1808c2ecf20Sopenharmony_ci .request_cmd = ETHTOOL_MSG_COALESCE_GET, 1818c2ecf20Sopenharmony_ci .reply_cmd = ETHTOOL_MSG_COALESCE_GET_REPLY, 1828c2ecf20Sopenharmony_ci .hdr_attr = ETHTOOL_A_COALESCE_HEADER, 1838c2ecf20Sopenharmony_ci .req_info_size = sizeof(struct coalesce_req_info), 1848c2ecf20Sopenharmony_ci .reply_data_size = sizeof(struct coalesce_reply_data), 1858c2ecf20Sopenharmony_ci 1868c2ecf20Sopenharmony_ci .prepare_data = coalesce_prepare_data, 1878c2ecf20Sopenharmony_ci .reply_size = coalesce_reply_size, 1888c2ecf20Sopenharmony_ci .fill_reply = coalesce_fill_reply, 1898c2ecf20Sopenharmony_ci}; 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_ci/* COALESCE_SET */ 1928c2ecf20Sopenharmony_ci 1938c2ecf20Sopenharmony_ciconst struct nla_policy ethnl_coalesce_set_policy[] = { 1948c2ecf20Sopenharmony_ci [ETHTOOL_A_COALESCE_HEADER] = 1958c2ecf20Sopenharmony_ci NLA_POLICY_NESTED(ethnl_header_policy), 1968c2ecf20Sopenharmony_ci [ETHTOOL_A_COALESCE_RX_USECS] = { .type = NLA_U32 }, 1978c2ecf20Sopenharmony_ci [ETHTOOL_A_COALESCE_RX_MAX_FRAMES] = { .type = NLA_U32 }, 1988c2ecf20Sopenharmony_ci [ETHTOOL_A_COALESCE_RX_USECS_IRQ] = { .type = NLA_U32 }, 1998c2ecf20Sopenharmony_ci [ETHTOOL_A_COALESCE_RX_MAX_FRAMES_IRQ] = { .type = NLA_U32 }, 2008c2ecf20Sopenharmony_ci [ETHTOOL_A_COALESCE_TX_USECS] = { .type = NLA_U32 }, 2018c2ecf20Sopenharmony_ci [ETHTOOL_A_COALESCE_TX_MAX_FRAMES] = { .type = NLA_U32 }, 2028c2ecf20Sopenharmony_ci [ETHTOOL_A_COALESCE_TX_USECS_IRQ] = { .type = NLA_U32 }, 2038c2ecf20Sopenharmony_ci [ETHTOOL_A_COALESCE_TX_MAX_FRAMES_IRQ] = { .type = NLA_U32 }, 2048c2ecf20Sopenharmony_ci [ETHTOOL_A_COALESCE_STATS_BLOCK_USECS] = { .type = NLA_U32 }, 2058c2ecf20Sopenharmony_ci [ETHTOOL_A_COALESCE_USE_ADAPTIVE_RX] = { .type = NLA_U8 }, 2068c2ecf20Sopenharmony_ci [ETHTOOL_A_COALESCE_USE_ADAPTIVE_TX] = { .type = NLA_U8 }, 2078c2ecf20Sopenharmony_ci [ETHTOOL_A_COALESCE_PKT_RATE_LOW] = { .type = NLA_U32 }, 2088c2ecf20Sopenharmony_ci [ETHTOOL_A_COALESCE_RX_USECS_LOW] = { .type = NLA_U32 }, 2098c2ecf20Sopenharmony_ci [ETHTOOL_A_COALESCE_RX_MAX_FRAMES_LOW] = { .type = NLA_U32 }, 2108c2ecf20Sopenharmony_ci [ETHTOOL_A_COALESCE_TX_USECS_LOW] = { .type = NLA_U32 }, 2118c2ecf20Sopenharmony_ci [ETHTOOL_A_COALESCE_TX_MAX_FRAMES_LOW] = { .type = NLA_U32 }, 2128c2ecf20Sopenharmony_ci [ETHTOOL_A_COALESCE_PKT_RATE_HIGH] = { .type = NLA_U32 }, 2138c2ecf20Sopenharmony_ci [ETHTOOL_A_COALESCE_RX_USECS_HIGH] = { .type = NLA_U32 }, 2148c2ecf20Sopenharmony_ci [ETHTOOL_A_COALESCE_RX_MAX_FRAMES_HIGH] = { .type = NLA_U32 }, 2158c2ecf20Sopenharmony_ci [ETHTOOL_A_COALESCE_TX_USECS_HIGH] = { .type = NLA_U32 }, 2168c2ecf20Sopenharmony_ci [ETHTOOL_A_COALESCE_TX_MAX_FRAMES_HIGH] = { .type = NLA_U32 }, 2178c2ecf20Sopenharmony_ci [ETHTOOL_A_COALESCE_RATE_SAMPLE_INTERVAL] = { .type = NLA_U32 }, 2188c2ecf20Sopenharmony_ci}; 2198c2ecf20Sopenharmony_ci 2208c2ecf20Sopenharmony_ciint ethnl_set_coalesce(struct sk_buff *skb, struct genl_info *info) 2218c2ecf20Sopenharmony_ci{ 2228c2ecf20Sopenharmony_ci struct ethtool_coalesce coalesce = {}; 2238c2ecf20Sopenharmony_ci struct ethnl_req_info req_info = {}; 2248c2ecf20Sopenharmony_ci struct nlattr **tb = info->attrs; 2258c2ecf20Sopenharmony_ci const struct ethtool_ops *ops; 2268c2ecf20Sopenharmony_ci struct net_device *dev; 2278c2ecf20Sopenharmony_ci u32 supported_params; 2288c2ecf20Sopenharmony_ci bool mod = false; 2298c2ecf20Sopenharmony_ci int ret; 2308c2ecf20Sopenharmony_ci u16 a; 2318c2ecf20Sopenharmony_ci 2328c2ecf20Sopenharmony_ci ret = ethnl_parse_header_dev_get(&req_info, 2338c2ecf20Sopenharmony_ci tb[ETHTOOL_A_COALESCE_HEADER], 2348c2ecf20Sopenharmony_ci genl_info_net(info), info->extack, 2358c2ecf20Sopenharmony_ci true); 2368c2ecf20Sopenharmony_ci if (ret < 0) 2378c2ecf20Sopenharmony_ci return ret; 2388c2ecf20Sopenharmony_ci dev = req_info.dev; 2398c2ecf20Sopenharmony_ci ops = dev->ethtool_ops; 2408c2ecf20Sopenharmony_ci ret = -EOPNOTSUPP; 2418c2ecf20Sopenharmony_ci if (!ops->get_coalesce || !ops->set_coalesce) 2428c2ecf20Sopenharmony_ci goto out_dev; 2438c2ecf20Sopenharmony_ci 2448c2ecf20Sopenharmony_ci /* make sure that only supported parameters are present */ 2458c2ecf20Sopenharmony_ci supported_params = ops->supported_coalesce_params; 2468c2ecf20Sopenharmony_ci for (a = ETHTOOL_A_COALESCE_RX_USECS; a < __ETHTOOL_A_COALESCE_CNT; a++) 2478c2ecf20Sopenharmony_ci if (tb[a] && !(supported_params & attr_to_mask(a))) { 2488c2ecf20Sopenharmony_ci ret = -EINVAL; 2498c2ecf20Sopenharmony_ci NL_SET_ERR_MSG_ATTR(info->extack, tb[a], 2508c2ecf20Sopenharmony_ci "cannot modify an unsupported parameter"); 2518c2ecf20Sopenharmony_ci goto out_dev; 2528c2ecf20Sopenharmony_ci } 2538c2ecf20Sopenharmony_ci 2548c2ecf20Sopenharmony_ci rtnl_lock(); 2558c2ecf20Sopenharmony_ci ret = ethnl_ops_begin(dev); 2568c2ecf20Sopenharmony_ci if (ret < 0) 2578c2ecf20Sopenharmony_ci goto out_rtnl; 2588c2ecf20Sopenharmony_ci ret = ops->get_coalesce(dev, &coalesce); 2598c2ecf20Sopenharmony_ci if (ret < 0) 2608c2ecf20Sopenharmony_ci goto out_ops; 2618c2ecf20Sopenharmony_ci 2628c2ecf20Sopenharmony_ci ethnl_update_u32(&coalesce.rx_coalesce_usecs, 2638c2ecf20Sopenharmony_ci tb[ETHTOOL_A_COALESCE_RX_USECS], &mod); 2648c2ecf20Sopenharmony_ci ethnl_update_u32(&coalesce.rx_max_coalesced_frames, 2658c2ecf20Sopenharmony_ci tb[ETHTOOL_A_COALESCE_RX_MAX_FRAMES], &mod); 2668c2ecf20Sopenharmony_ci ethnl_update_u32(&coalesce.rx_coalesce_usecs_irq, 2678c2ecf20Sopenharmony_ci tb[ETHTOOL_A_COALESCE_RX_USECS_IRQ], &mod); 2688c2ecf20Sopenharmony_ci ethnl_update_u32(&coalesce.rx_max_coalesced_frames_irq, 2698c2ecf20Sopenharmony_ci tb[ETHTOOL_A_COALESCE_RX_MAX_FRAMES_IRQ], &mod); 2708c2ecf20Sopenharmony_ci ethnl_update_u32(&coalesce.tx_coalesce_usecs, 2718c2ecf20Sopenharmony_ci tb[ETHTOOL_A_COALESCE_TX_USECS], &mod); 2728c2ecf20Sopenharmony_ci ethnl_update_u32(&coalesce.tx_max_coalesced_frames, 2738c2ecf20Sopenharmony_ci tb[ETHTOOL_A_COALESCE_TX_MAX_FRAMES], &mod); 2748c2ecf20Sopenharmony_ci ethnl_update_u32(&coalesce.tx_coalesce_usecs_irq, 2758c2ecf20Sopenharmony_ci tb[ETHTOOL_A_COALESCE_TX_USECS_IRQ], &mod); 2768c2ecf20Sopenharmony_ci ethnl_update_u32(&coalesce.tx_max_coalesced_frames_irq, 2778c2ecf20Sopenharmony_ci tb[ETHTOOL_A_COALESCE_TX_MAX_FRAMES_IRQ], &mod); 2788c2ecf20Sopenharmony_ci ethnl_update_u32(&coalesce.stats_block_coalesce_usecs, 2798c2ecf20Sopenharmony_ci tb[ETHTOOL_A_COALESCE_STATS_BLOCK_USECS], &mod); 2808c2ecf20Sopenharmony_ci ethnl_update_bool32(&coalesce.use_adaptive_rx_coalesce, 2818c2ecf20Sopenharmony_ci tb[ETHTOOL_A_COALESCE_USE_ADAPTIVE_RX], &mod); 2828c2ecf20Sopenharmony_ci ethnl_update_bool32(&coalesce.use_adaptive_tx_coalesce, 2838c2ecf20Sopenharmony_ci tb[ETHTOOL_A_COALESCE_USE_ADAPTIVE_TX], &mod); 2848c2ecf20Sopenharmony_ci ethnl_update_u32(&coalesce.pkt_rate_low, 2858c2ecf20Sopenharmony_ci tb[ETHTOOL_A_COALESCE_PKT_RATE_LOW], &mod); 2868c2ecf20Sopenharmony_ci ethnl_update_u32(&coalesce.rx_coalesce_usecs_low, 2878c2ecf20Sopenharmony_ci tb[ETHTOOL_A_COALESCE_RX_USECS_LOW], &mod); 2888c2ecf20Sopenharmony_ci ethnl_update_u32(&coalesce.rx_max_coalesced_frames_low, 2898c2ecf20Sopenharmony_ci tb[ETHTOOL_A_COALESCE_RX_MAX_FRAMES_LOW], &mod); 2908c2ecf20Sopenharmony_ci ethnl_update_u32(&coalesce.tx_coalesce_usecs_low, 2918c2ecf20Sopenharmony_ci tb[ETHTOOL_A_COALESCE_TX_USECS_LOW], &mod); 2928c2ecf20Sopenharmony_ci ethnl_update_u32(&coalesce.tx_max_coalesced_frames_low, 2938c2ecf20Sopenharmony_ci tb[ETHTOOL_A_COALESCE_TX_MAX_FRAMES_LOW], &mod); 2948c2ecf20Sopenharmony_ci ethnl_update_u32(&coalesce.pkt_rate_high, 2958c2ecf20Sopenharmony_ci tb[ETHTOOL_A_COALESCE_PKT_RATE_HIGH], &mod); 2968c2ecf20Sopenharmony_ci ethnl_update_u32(&coalesce.rx_coalesce_usecs_high, 2978c2ecf20Sopenharmony_ci tb[ETHTOOL_A_COALESCE_RX_USECS_HIGH], &mod); 2988c2ecf20Sopenharmony_ci ethnl_update_u32(&coalesce.rx_max_coalesced_frames_high, 2998c2ecf20Sopenharmony_ci tb[ETHTOOL_A_COALESCE_RX_MAX_FRAMES_HIGH], &mod); 3008c2ecf20Sopenharmony_ci ethnl_update_u32(&coalesce.tx_coalesce_usecs_high, 3018c2ecf20Sopenharmony_ci tb[ETHTOOL_A_COALESCE_TX_USECS_HIGH], &mod); 3028c2ecf20Sopenharmony_ci ethnl_update_u32(&coalesce.tx_max_coalesced_frames_high, 3038c2ecf20Sopenharmony_ci tb[ETHTOOL_A_COALESCE_TX_MAX_FRAMES_HIGH], &mod); 3048c2ecf20Sopenharmony_ci ethnl_update_u32(&coalesce.rate_sample_interval, 3058c2ecf20Sopenharmony_ci tb[ETHTOOL_A_COALESCE_RATE_SAMPLE_INTERVAL], &mod); 3068c2ecf20Sopenharmony_ci ret = 0; 3078c2ecf20Sopenharmony_ci if (!mod) 3088c2ecf20Sopenharmony_ci goto out_ops; 3098c2ecf20Sopenharmony_ci 3108c2ecf20Sopenharmony_ci ret = dev->ethtool_ops->set_coalesce(dev, &coalesce); 3118c2ecf20Sopenharmony_ci if (ret < 0) 3128c2ecf20Sopenharmony_ci goto out_ops; 3138c2ecf20Sopenharmony_ci ethtool_notify(dev, ETHTOOL_MSG_COALESCE_NTF, NULL); 3148c2ecf20Sopenharmony_ci 3158c2ecf20Sopenharmony_ciout_ops: 3168c2ecf20Sopenharmony_ci ethnl_ops_complete(dev); 3178c2ecf20Sopenharmony_ciout_rtnl: 3188c2ecf20Sopenharmony_ci rtnl_unlock(); 3198c2ecf20Sopenharmony_ciout_dev: 3208c2ecf20Sopenharmony_ci dev_put(dev); 3218c2ecf20Sopenharmony_ci return ret; 3228c2ecf20Sopenharmony_ci} 323