From patchwork Wed Jun 19 19:30:23 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Shtylyov X-Patchwork-Id: 2751741 Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D232A9F8E1 for ; Wed, 19 Jun 2013 19:30:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C2D82204BD for ; Wed, 19 Jun 2013 19:30:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7FDE8204C0 for ; Wed, 19 Jun 2013 19:30:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935159Ab3FSTa0 (ORCPT ); Wed, 19 Jun 2013 15:30:26 -0400 Received: from mail-la0-f50.google.com ([209.85.215.50]:54907 "EHLO mail-la0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935155Ab3FSTaX (ORCPT ); Wed, 19 Jun 2013 15:30:23 -0400 Received: by mail-la0-f50.google.com with SMTP id dy20so4849933lab.23 for ; Wed, 19 Jun 2013 12:30:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=to:subject:cc:from:organization:date:mime-version:content-type :content-transfer-encoding:message-id:x-gm-message-state; bh=8gKkBsVGhXxyPXhy+8uGRSETdWVyhKcs0Vv1gc8HIcY=; b=PSv5jni0YW+1KFvkwxUd1NamNFnHmAC7NUiOYfTU/1JWv8bnpN7f9NvEHmQ9DHhobl WQ7SK7lk78PODFrw4FrM6+n99/0zG/3JvtnnELuhbDkh4NxaXurijERunGKCpMYm8F34 CbA/Vzf+IdWHx85beJ4aXWd8qwU8PsOelJjDDr8MGhj49oOO6zV7ptgt/73AUeNtv4ZQ eP5nh+OhMF/g/CDoh92WbhKMzu7uyTVLaiPKedZ2Ht99XR3XqA/2SNlfgAyT7AtcNNEH mOXqFs3f+aVSAn0Oxf+JeXLXVGA+XJVksj5Cu+G3D1KmAtaKAVsDfaenA47PLdA4+gaU jojA== X-Received: by 10.112.89.226 with SMTP id br2mr3929008lbb.12.1371670221010; Wed, 19 Jun 2013 12:30:21 -0700 (PDT) Received: from wasted.dev.rtsoft.ru (ppp91-76-156-235.pppoe.mtu-net.ru. [91.76.156.235]) by mx.google.com with ESMTPSA id m14sm9178518lbl.1.2013.06.19.12.30.19 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 19 Jun 2013 12:30:20 -0700 (PDT) To: netdev@vger.kernel.org Subject: [PATCH v2 2/2] sh_eth: add NAPI support Cc: nobuhiro.iwamatsu.yj@renesas.com, linux-sh@vger.kernel.org From: Sergei Shtylyov Organization: Cogent Embedded Date: Wed, 19 Jun 2013 23:30:23 +0400 MIME-Version: 1.0 Message-Id: <201306192330.23477.sergei.shtylyov@cogentembedded.com> X-Gm-Message-State: ALoCoQl5MF4ACLQcb1GDX/a+3lIuczpM1YrWMaexZw8QZwCpzxB715swLilXAz3/q4ivzflRM4f6 Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Spam-Status: No, score=-8.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The driver hasn't used NAPI so far; implement its support at last... The patch was tested on Renesas R8A77781 BOCK-W board. Signed-off-by: Sergei Shtylyov --- The patch is against the Dave Miller's 'net-next.git' repo. Changes in version 2: - added to the changelog information about testing. drivers/net/ethernet/renesas/sh_eth.c | 85 +++++++++++++++++++++++++++++----- drivers/net/ethernet/renesas/sh_eth.h | 1 2 files changed, 74 insertions(+), 12 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-sh" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Index: net-next/drivers/net/ethernet/renesas/sh_eth.c =================================================================== --- net-next.orig/drivers/net/ethernet/renesas/sh_eth.c +++ net-next/drivers/net/ethernet/renesas/sh_eth.c @@ -1244,7 +1244,7 @@ static int sh_eth_txfree(struct net_devi } /* Packet receive function */ -static int sh_eth_rx(struct net_device *ndev, u32 intr_status) +static int sh_eth_rx(struct net_device *ndev, u32 intr_status, int *quota) { struct sh_eth_private *mdp = netdev_priv(ndev); struct sh_eth_rxdesc *rxdesc; @@ -1252,6 +1252,7 @@ static int sh_eth_rx(struct net_device * int entry = mdp->cur_rx % mdp->num_rx_ring; int boguscnt = (mdp->dirty_rx + mdp->num_rx_ring) - mdp->cur_rx; struct sk_buff *skb; + int exceeded = 0; u16 pkt_len = 0; u32 desc_status; @@ -1267,6 +1268,12 @@ static int sh_eth_rx(struct net_device * if (--boguscnt < 0) break; + if (*quota <= 0) { + exceeded = 1; + break; + } + (*quota)--; + if (!(desc_status & RDFEND)) ndev->stats.rx_length_errors++; @@ -1343,7 +1350,7 @@ static int sh_eth_rx(struct net_device * sh_eth_write(ndev, EDRRR_R, EDRRR); } - return 0; + return exceeded; } static void sh_eth_rcv_snd_disable(struct net_device *ndev) @@ -1484,7 +1491,7 @@ static irqreturn_t sh_eth_interrupt(int struct sh_eth_private *mdp = netdev_priv(ndev); struct sh_eth_cpu_data *cd = mdp->cd; irqreturn_t ret = IRQ_NONE; - unsigned long intr_status; + unsigned long intr_status, intr_enable; spin_lock(&mdp->lock); @@ -1495,25 +1502,41 @@ static irqreturn_t sh_eth_interrupt(int * and we need to fully handle it in sh_eth_error() in order to quench * it as it doesn't get cleared by just writing 1 to the ECI bit... */ - intr_status &= sh_eth_read(ndev, EESIPR) | DMAC_M_ECI; - /* Clear interrupt */ - if (intr_status & (EESR_RX_CHECK | cd->tx_check | cd->eesr_err_check)) { - sh_eth_write(ndev, intr_status, EESR); + intr_enable = sh_eth_read(ndev, EESIPR); + intr_status &= intr_enable | DMAC_M_ECI; + if (intr_status & (EESR_RX_CHECK | cd->tx_check | cd->eesr_err_check)) ret = IRQ_HANDLED; - } else + else goto other_irq; - if (intr_status & EESR_RX_CHECK) - sh_eth_rx(ndev, intr_status); + if (intr_status & EESR_RX_CHECK) { + if (napi_schedule_prep(&mdp->napi)) { + /* Mask Rx interrupts */ + sh_eth_write(ndev, intr_enable & ~EESR_RX_CHECK, + EESIPR); + __napi_schedule(&mdp->napi); + } else { + dev_warn(&ndev->dev, + "ignoring interrupt, status 0x%08lx, mask 0x%08lx.\n", + intr_status, intr_enable); + } + } /* Tx Check */ if (intr_status & cd->tx_check) { + /* Clear Tx interrupts */ + sh_eth_write(ndev, intr_status & cd->tx_check, EESR); + sh_eth_txfree(ndev); netif_wake_queue(ndev); } - if (intr_status & cd->eesr_err_check) + if (intr_status & cd->eesr_err_check) { + /* Clear error interrupts */ + sh_eth_write(ndev, intr_status & cd->eesr_err_check, EESR); + sh_eth_error(ndev, intr_status); + } other_irq: spin_unlock(&mdp->lock); @@ -1521,6 +1544,33 @@ other_irq: return ret; } +static int sh_eth_poll(struct napi_struct *napi, int budget) +{ + struct sh_eth_private *mdp = container_of(napi, struct sh_eth_private, + napi); + struct net_device *ndev = napi->dev; + int quota = budget; + unsigned long intr_status; + + for (;;) { + intr_status = sh_eth_read(ndev, EESR); + if (!(intr_status & EESR_RX_CHECK)) + break; + /* Clear Rx interrupts */ + sh_eth_write(ndev, intr_status & EESR_RX_CHECK, EESR); + + if (sh_eth_rx(ndev, intr_status, "a)) + goto out; + } + + napi_complete(napi); + + /* Reenable Rx interrupts */ + sh_eth_write(ndev, mdp->cd->eesipr_value, EESIPR); +out: + return budget - quota; +} + /* PHY state control function */ static void sh_eth_adjust_link(struct net_device *ndev) { @@ -1832,6 +1882,8 @@ static int sh_eth_open(struct net_device if (ret) goto out_free_irq; + napi_enable(&mdp->napi); + return ret; out_free_irq: @@ -1927,6 +1979,8 @@ static int sh_eth_close(struct net_devic { struct sh_eth_private *mdp = netdev_priv(ndev); + napi_disable(&mdp->napi); + netif_stop_queue(ndev); /* Disable interrupts by clearing the interrupt mask. */ @@ -2616,10 +2670,12 @@ static int sh_eth_drv_probe(struct platf } } + netif_napi_add(ndev, &mdp->napi, sh_eth_poll, 64); + /* network device register */ ret = register_netdev(ndev); if (ret) - goto out_release; + goto out_napi_del; /* mdio bus init */ ret = sh_mdio_init(ndev, pdev->id, pd); @@ -2637,6 +2693,9 @@ static int sh_eth_drv_probe(struct platf out_unregister: unregister_netdev(ndev); +out_napi_del: + netif_napi_del(&mdp->napi); + out_release: /* net_dev free */ if (ndev) @@ -2649,9 +2708,11 @@ out: static int sh_eth_drv_remove(struct platform_device *pdev) { struct net_device *ndev = platform_get_drvdata(pdev); + struct sh_eth_private *mdp = netdev_priv(ndev); sh_mdio_release(ndev); unregister_netdev(ndev); + netif_napi_del(&mdp->napi); pm_runtime_disable(&pdev->dev); free_netdev(ndev); Index: net-next/drivers/net/ethernet/renesas/sh_eth.h =================================================================== --- net-next.orig/drivers/net/ethernet/renesas/sh_eth.h +++ net-next/drivers/net/ethernet/renesas/sh_eth.h @@ -505,6 +505,7 @@ struct sh_eth_private { u32 cur_tx, dirty_tx; u32 rx_buf_sz; /* Based on MTU+slack. */ int edmac_endian; + struct napi_struct napi; /* MII transceiver section. */ u32 phy_id; /* PHY ID */ struct mii_bus *mii_bus; /* MDIO bus control */