From patchwork Fri Feb 3 18:12:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antoine Tenart X-Patchwork-Id: 9554907 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id ADE71604A7 for ; Fri, 3 Feb 2017 18:16:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 968C3205A8 for ; Fri, 3 Feb 2017 18:16:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8A30626E64; Fri, 3 Feb 2017 18:16:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00 autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1CB81205A8 for ; Fri, 3 Feb 2017 18:16:38 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cZiPV-000547-OD; Fri, 03 Feb 2017 18:16:37 +0000 Received: from mail.free-electrons.com ([62.4.15.54]) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cZiOt-0003wF-IB for linux-arm-kernel@lists.infradead.org; Fri, 03 Feb 2017 18:16:04 +0000 Received: by mail.free-electrons.com (Postfix, from userid 110) id 760ED20DAF; Fri, 3 Feb 2017 19:15:11 +0100 (CET) Received: from localhost (LFbn-1-3856-160.w86-233.abo.wanadoo.fr [86.233.111.160]) by mail.free-electrons.com (Postfix) with ESMTPSA id A6A5820C16; Fri, 3 Feb 2017 19:15:10 +0100 (CET) From: Antoine Tenart To: netdev@vger.kernel.org, davem@davemloft.net, linux-arm-kernel@lists.infradead.org Subject: [PATCH net-next 8/8] net: ethernet: annapurna: add the coalesce helpers to the Alpine driver Date: Fri, 3 Feb 2017 19:12:16 +0100 Message-Id: <20170203181216.30214-9-antoine.tenart@free-electrons.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170203181216.30214-1-antoine.tenart@free-electrons.com> References: <20170203181216.30214-1-antoine.tenart@free-electrons.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170203_101600_544754_23C1B1EF X-CRM114-Status: GOOD ( 13.60 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: thomas.petazzoni@free-electrons.com, saeed@annapurnalabs.com, arnd@arndb.de, Antoine Tenart , talz@annapurnalabs.com, rshitrit@annapurnalabs.com, barak@annapurnalabs.com, tsahee@annapurnalabs.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Add the get_coalesce() and set_coalesce() helpers to the Annapurna Labs Alpine Ethernet driver. --- drivers/net/ethernet/annapurna/al_eth.c | 81 +++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/drivers/net/ethernet/annapurna/al_eth.c b/drivers/net/ethernet/annapurna/al_eth.c index 674dafdb638a..369a5a7d5cc5 100644 --- a/drivers/net/ethernet/annapurna/al_eth.c +++ b/drivers/net/ethernet/annapurna/al_eth.c @@ -2132,6 +2132,9 @@ static void al_eth_config_rx_fwd(struct al_eth_adapter *adapter) al_eth_fsm_table_init(adapter); } +static void al_eth_set_coalesce(struct al_eth_adapter *adapter, + unsigned int tx_usecs, unsigned int rx_usecs); + static void al_eth_restore_ethtool_params(struct al_eth_adapter *adapter) { int i; @@ -2141,6 +2144,8 @@ static void al_eth_restore_ethtool_params(struct al_eth_adapter *adapter) adapter->tx_usecs = 0; adapter->rx_usecs = 0; + al_eth_set_coalesce(adapter, tx_usecs, rx_usecs); + for (i = 0; i < AL_ETH_RX_RSS_TABLE_SIZE; i++) al_eth_thash_table_set(&adapter->hw_adapter, i, 0, adapter->rss_ind_tbl[i]); @@ -2364,6 +2369,80 @@ static int al_eth_set_settings(struct net_device *netdev, return rc; } +static int al_eth_get_coalesce(struct net_device *net_dev, + struct ethtool_coalesce *coalesce) +{ + struct al_eth_adapter *adapter = netdev_priv(net_dev); + + coalesce->tx_coalesce_usecs = adapter->tx_usecs; + coalesce->tx_coalesce_usecs_irq = adapter->tx_usecs; + coalesce->rx_coalesce_usecs = adapter->rx_usecs; + coalesce->rx_coalesce_usecs_irq = adapter->rx_usecs; + coalesce->use_adaptive_rx_coalesce = false; + + return 0; +} + +static void al_eth_set_coalesce(struct al_eth_adapter *adapter, + unsigned int tx_usecs, unsigned int rx_usecs) +{ + struct unit_regs *udma_base = (struct unit_regs *)(adapter->udma_base); + int qid; + + if (adapter->tx_usecs != tx_usecs) { + uint interval = (tx_usecs + 15) / 16; + + WARN_ON(interval > 255); + + adapter->tx_usecs = interval * 16; + for (qid = 0; qid < adapter->num_tx_queues; qid++) + al_iofic_msix_moder_interval_config( + &udma_base->gen.interrupt_regs.main_iofic, + AL_INT_GROUP_C, qid, interval); + } + if (adapter->rx_usecs != rx_usecs) { + uint interval = (rx_usecs + 15) / 16; + + WARN_ON(interval > 255); + + adapter->rx_usecs = interval * 16; + for (qid = 0; qid < adapter->num_rx_queues; qid++) + al_iofic_msix_moder_interval_config( + &udma_base->gen.interrupt_regs.main_iofic, + AL_INT_GROUP_B, qid, interval); + } +} + +static int al_eth_ethtool_set_coalesce(struct net_device *net_dev, + struct ethtool_coalesce *coalesce) +{ + struct al_eth_adapter *adapter = netdev_priv(net_dev); + unsigned int tx_usecs = adapter->tx_usecs; + unsigned int rx_usecs = adapter->rx_usecs; + + if (coalesce->use_adaptive_tx_coalesce) + return -EINVAL; + + if (coalesce->rx_coalesce_usecs != rx_usecs) + rx_usecs = coalesce->rx_coalesce_usecs; + else + rx_usecs = coalesce->rx_coalesce_usecs_irq; + + if (coalesce->tx_coalesce_usecs != tx_usecs) + tx_usecs = coalesce->tx_coalesce_usecs; + else + tx_usecs = coalesce->tx_coalesce_usecs_irq; + + if (tx_usecs > (255 * 16)) + return -EINVAL; + if (rx_usecs > (255 * 16)) + return -EINVAL; + + al_eth_set_coalesce(adapter, tx_usecs, rx_usecs); + + return 0; +} + static int al_eth_nway_reset(struct net_device *netdev) { struct al_eth_adapter *adapter = netdev_priv(netdev); @@ -2613,6 +2692,8 @@ static const struct ethtool_ops al_eth_ethtool_ops = { .nway_reset = al_eth_nway_reset, .get_link = ethtool_op_get_link, + .get_coalesce = al_eth_get_coalesce, + .set_coalesce = al_eth_ethtool_set_coalesce, .get_pauseparam = al_eth_get_pauseparam, .set_pauseparam = al_eth_set_pauseparam, .get_rxnfc = al_eth_get_rxnfc,