18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: ISC 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (c) 2014,2017 Qualcomm Atheros, Inc. 48c2ecf20Sopenharmony_ci * Copyright (c) 2018, The Linux Foundation. All rights reserved. 58c2ecf20Sopenharmony_ci */ 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#include <linux/etherdevice.h> 88c2ecf20Sopenharmony_ci#include <linux/pci.h> 98c2ecf20Sopenharmony_ci#include <linux/rtnetlink.h> 108c2ecf20Sopenharmony_ci#include <net/cfg80211.h> 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#include "wil6210.h" 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_cistatic int wil_ethtoolops_get_coalesce(struct net_device *ndev, 158c2ecf20Sopenharmony_ci struct ethtool_coalesce *cp) 168c2ecf20Sopenharmony_ci{ 178c2ecf20Sopenharmony_ci struct wil6210_priv *wil = ndev_to_wil(ndev); 188c2ecf20Sopenharmony_ci u32 tx_itr_en, tx_itr_val = 0; 198c2ecf20Sopenharmony_ci u32 rx_itr_en, rx_itr_val = 0; 208c2ecf20Sopenharmony_ci int ret; 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci mutex_lock(&wil->mutex); 238c2ecf20Sopenharmony_ci wil_dbg_misc(wil, "ethtoolops_get_coalesce\n"); 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci ret = wil_pm_runtime_get(wil); 268c2ecf20Sopenharmony_ci if (ret < 0) 278c2ecf20Sopenharmony_ci goto out; 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci tx_itr_en = wil_r(wil, RGF_DMA_ITR_TX_CNT_CTL); 308c2ecf20Sopenharmony_ci if (tx_itr_en & BIT_DMA_ITR_TX_CNT_CTL_EN) 318c2ecf20Sopenharmony_ci tx_itr_val = wil_r(wil, RGF_DMA_ITR_TX_CNT_TRSH); 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci rx_itr_en = wil_r(wil, RGF_DMA_ITR_RX_CNT_CTL); 348c2ecf20Sopenharmony_ci if (rx_itr_en & BIT_DMA_ITR_RX_CNT_CTL_EN) 358c2ecf20Sopenharmony_ci rx_itr_val = wil_r(wil, RGF_DMA_ITR_RX_CNT_TRSH); 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci wil_pm_runtime_put(wil); 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci cp->tx_coalesce_usecs = tx_itr_val; 408c2ecf20Sopenharmony_ci cp->rx_coalesce_usecs = rx_itr_val; 418c2ecf20Sopenharmony_ci ret = 0; 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ciout: 448c2ecf20Sopenharmony_ci mutex_unlock(&wil->mutex); 458c2ecf20Sopenharmony_ci return ret; 468c2ecf20Sopenharmony_ci} 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_cistatic int wil_ethtoolops_set_coalesce(struct net_device *ndev, 498c2ecf20Sopenharmony_ci struct ethtool_coalesce *cp) 508c2ecf20Sopenharmony_ci{ 518c2ecf20Sopenharmony_ci struct wil6210_priv *wil = ndev_to_wil(ndev); 528c2ecf20Sopenharmony_ci struct wireless_dev *wdev = ndev->ieee80211_ptr; 538c2ecf20Sopenharmony_ci int ret; 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci mutex_lock(&wil->mutex); 568c2ecf20Sopenharmony_ci wil_dbg_misc(wil, "ethtoolops_set_coalesce: rx %d usec, tx %d usec\n", 578c2ecf20Sopenharmony_ci cp->rx_coalesce_usecs, cp->tx_coalesce_usecs); 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci if (wdev->iftype == NL80211_IFTYPE_MONITOR) { 608c2ecf20Sopenharmony_ci wil_dbg_misc(wil, "No IRQ coalescing in monitor mode\n"); 618c2ecf20Sopenharmony_ci ret = -EINVAL; 628c2ecf20Sopenharmony_ci goto out; 638c2ecf20Sopenharmony_ci } 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci /* only @rx_coalesce_usecs and @tx_coalesce_usecs supported, 668c2ecf20Sopenharmony_ci * ignore other parameters 678c2ecf20Sopenharmony_ci */ 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci if (cp->rx_coalesce_usecs > WIL6210_ITR_TRSH_MAX || 708c2ecf20Sopenharmony_ci cp->tx_coalesce_usecs > WIL6210_ITR_TRSH_MAX) 718c2ecf20Sopenharmony_ci goto out_bad; 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci wil->tx_max_burst_duration = cp->tx_coalesce_usecs; 748c2ecf20Sopenharmony_ci wil->rx_max_burst_duration = cp->rx_coalesce_usecs; 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci ret = wil_pm_runtime_get(wil); 778c2ecf20Sopenharmony_ci if (ret < 0) 788c2ecf20Sopenharmony_ci goto out; 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci wil->txrx_ops.configure_interrupt_moderation(wil); 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci wil_pm_runtime_put(wil); 838c2ecf20Sopenharmony_ci ret = 0; 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ciout: 868c2ecf20Sopenharmony_ci mutex_unlock(&wil->mutex); 878c2ecf20Sopenharmony_ci return ret; 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ciout_bad: 908c2ecf20Sopenharmony_ci wil_dbg_misc(wil, "Unsupported coalescing params. Raw command:\n"); 918c2ecf20Sopenharmony_ci print_hex_dump_debug("DBG[MISC] coal ", DUMP_PREFIX_OFFSET, 16, 4, 928c2ecf20Sopenharmony_ci cp, sizeof(*cp), false); 938c2ecf20Sopenharmony_ci mutex_unlock(&wil->mutex); 948c2ecf20Sopenharmony_ci return -EINVAL; 958c2ecf20Sopenharmony_ci} 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_cistatic const struct ethtool_ops wil_ethtool_ops = { 988c2ecf20Sopenharmony_ci .supported_coalesce_params = ETHTOOL_COALESCE_USECS, 998c2ecf20Sopenharmony_ci .get_drvinfo = cfg80211_get_drvinfo, 1008c2ecf20Sopenharmony_ci .get_coalesce = wil_ethtoolops_get_coalesce, 1018c2ecf20Sopenharmony_ci .set_coalesce = wil_ethtoolops_set_coalesce, 1028c2ecf20Sopenharmony_ci}; 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_civoid wil_set_ethtoolops(struct net_device *ndev) 1058c2ecf20Sopenharmony_ci{ 1068c2ecf20Sopenharmony_ci ndev->ethtool_ops = &wil_ethtool_ops; 1078c2ecf20Sopenharmony_ci} 108