From patchwork Thu Feb 9 00:07:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Khoronzhuk X-Patchwork-Id: 9563815 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 2A06B60236 for ; Thu, 9 Feb 2017 00:08:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AC4F528536 for ; Thu, 9 Feb 2017 00:08:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 979662853E; Thu, 9 Feb 2017 00:08:49 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 36C3B28538 for ; Thu, 9 Feb 2017 00:08:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752480AbdBIAIl (ORCPT ); Wed, 8 Feb 2017 19:08:41 -0500 Received: from mail-lf0-f49.google.com ([209.85.215.49]:35885 "EHLO mail-lf0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751925AbdBIAHq (ORCPT ); Wed, 8 Feb 2017 19:07:46 -0500 Received: by mail-lf0-f49.google.com with SMTP id z134so91765984lff.3 for ; Wed, 08 Feb 2017 16:07:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ezIy0E2FXNcZIFBVUsHEuP7dHrlIFvltNa+7lfBPeiM=; b=QcYmydSStq8n7hOOGZoX2VRXZSW+OxdKSjtpydZLUZ23jkBbDLxf2POe5duhQYOQbs VAQ0vKj20WvfIF1pkB+E5Q18SgdPn8a2FRFWPSWb4UzQiif3oFrWZ1QKMGNxgPcNGIfd hsqg0uNARwJc0fE55TrdGRT47BtS9E3qnF9Ak= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ezIy0E2FXNcZIFBVUsHEuP7dHrlIFvltNa+7lfBPeiM=; b=Z5/LiLfNkuv9PVxKSPvJWSXozub7Fy3XMTKBhMZW4FmaQNK2mVkHNjzlLTSYwWRKjb Y05CfqhZwJVaEs3lzTd6GMWA9BFln+/8rNdgLzTO9tkZTZMFHvFkbYxMyyc03PAS/WwN lQt2AxoEBF/tHeZQ+evpnYNcOYu1OMSzw/mZAgs3dFRKlr5mchgdf9isx9WveYT3tbh+ B0xSqg2Vdg7RIJ2VqqthXs0r1RHL+y1LUaohJixjctGIpZP1H+wnzNZefKqDYCIQfUgI /hbtWgQ5eeCsrO3X28tdVLhbIobKSUiHzbKw9VMk6hobB5mB2wF2a7JSGoSm2XKNbuUg usKw== X-Gm-Message-State: AMke39mZT14JXgC+IqmzBjufuX2SDYAdnNYRbrRJOY7X1+5U0MjVsZMGC0H8m7GNfXNwREBB X-Received: by 10.25.219.82 with SMTP id s79mr60542lfg.116.1486598863114; Wed, 08 Feb 2017 16:07:43 -0800 (PST) Received: from localhost.localdomain (183-224-132-95.pool.ukrtel.net. [95.132.224.183]) by smtp.gmail.com with ESMTPSA id 206sm2887040ljf.35.2017.02.08.16.07.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 08 Feb 2017 16:07:42 -0800 (PST) From: Ivan Khoronzhuk To: mugunthanvnm@ti.com Cc: grygorii.strashko@ti.com, netdev@vger.kernel.org, linux-omap@vger.kernel.org, linux-kernel@vger.kernel.org, AStarikovskiy@topcon.com, Ivan Khoronzhuk Subject: [PATCH 2/2] net: ethernet: ti: cpsw: fix resume because of usage count Date: Thu, 9 Feb 2017 02:07:36 +0200 Message-Id: <1486598856-3512-3-git-send-email-ivan.khoronzhuk@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1486598856-3512-1-git-send-email-ivan.khoronzhuk@linaro.org> References: <1486598856-3512-1-git-send-email-ivan.khoronzhuk@linaro.org> Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The usage count function is based on ndev_running flag that is updated before calling ndo_open/close, but if ndo is called in another place, in this case in suspend/resume, the counter is not changed, that breaks sus/resume. For common resource no difference which device is using it, does matter only device count. So, replace usage count function on var and inc and dec it in ndo_open/close. Fixes: 03fd01ad0eead23eb79294b6fb4d71dcac493855 "net: ethernet: ti: cpsw: don't duplicate ndev_running" Signed-off-by: Ivan Khoronzhuk --- drivers/net/ethernet/ti/cpsw.c | 42 ++++++++++++------------------------------ 1 file changed, 12 insertions(+), 30 deletions(-) diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c index 9714fab..1ffaad1 100644 --- a/drivers/net/ethernet/ti/cpsw.c +++ b/drivers/net/ethernet/ti/cpsw.c @@ -399,6 +399,7 @@ struct cpsw_common { struct cpts *cpts; int rx_ch_num, tx_ch_num; int speed; + int usage_count; }; struct cpsw_priv { @@ -671,18 +672,6 @@ static void cpsw_intr_disable(struct cpsw_common *cpsw) return; } -static int cpsw_get_usage_count(struct cpsw_common *cpsw) -{ - u32 i; - u32 usage_count = 0; - - for (i = 0; i < cpsw->data.slaves; i++) - if (cpsw->slaves[i].ndev && netif_running(cpsw->slaves[i].ndev)) - usage_count++; - - return usage_count; -} - static void cpsw_tx_handler(void *token, int len, int status) { struct netdev_queue *txq; @@ -716,8 +705,7 @@ static void cpsw_rx_handler(void *token, int len, int status) if (unlikely(status < 0) || unlikely(!netif_running(ndev))) { /* In dual emac mode check for all interfaces */ - if (cpsw->data.dual_emac && - cpsw_get_usage_count(cpsw) && + if (cpsw->data.dual_emac && cpsw->usage_count && (status >= 0)) { /* The packet received is for the interface which * is already down and the other interface is up @@ -1492,11 +1480,8 @@ static int cpsw_ndo_open(struct net_device *ndev) CPSW_MAJOR_VERSION(reg), CPSW_MINOR_VERSION(reg), CPSW_RTL_VERSION(reg)); - /* Initialize host and slave ports. - * Given ndev is marked as opened already, so init port only if 1 ndev - * is opened - */ - if (cpsw_get_usage_count(cpsw) < 2) + /* Initialize host and slave ports */ + if (!cpsw->usage_count) cpsw_init_host_port(priv); for_each_slave(priv, cpsw_slave_open, priv); @@ -1507,10 +1492,8 @@ static int cpsw_ndo_open(struct net_device *ndev) cpsw_ale_add_vlan(cpsw->ale, cpsw->data.default_vlan, ALE_ALL_PORTS, ALE_ALL_PORTS, 0, 0); - /* Given ndev is marked as opened already, so if more ndev - * are opened - no need to init shared resources. - */ - if (cpsw_get_usage_count(cpsw) < 2) { + /* initialize shared resources for every ndev */ + if (!cpsw->usage_count) { /* disable priority elevation */ __raw_writel(0, &cpsw->regs->ptype); @@ -1552,6 +1535,7 @@ static int cpsw_ndo_open(struct net_device *ndev) cpdma_ctlr_start(cpsw->dma); cpsw_intr_enable(cpsw); + cpsw->usage_count++; return 0; @@ -1572,10 +1556,7 @@ static int cpsw_ndo_stop(struct net_device *ndev) netif_tx_stop_all_queues(priv->ndev); netif_carrier_off(priv->ndev); - /* Given ndev is marked as close already, - * so disable shared resources if no open devices - */ - if (!cpsw_get_usage_count(cpsw)) { + if (cpsw->usage_count <= 1) { napi_disable(&cpsw->napi_rx); napi_disable(&cpsw->napi_tx); cpts_unregister(cpsw->cpts); @@ -1588,6 +1569,7 @@ static int cpsw_ndo_stop(struct net_device *ndev) if (cpsw_need_resplit(cpsw)) cpsw_split_res(ndev); + cpsw->usage_count--; pm_runtime_put_sync(cpsw->dev); return 0; } @@ -2393,7 +2375,7 @@ static int cpsw_resume_data_pass(struct net_device *ndev) netif_dormant_off(slave->ndev); /* After this receive is started */ - if (cpsw_get_usage_count(cpsw)) { + if (cpsw->usage_count) { ret = cpsw_fill_rx_channels(priv); if (ret) return ret; @@ -2447,7 +2429,7 @@ static int cpsw_set_channels(struct net_device *ndev, } } - if (cpsw_get_usage_count(cpsw)) + if (cpsw->usage_count) cpsw_split_res(ndev); ret = cpsw_resume_data_pass(ndev); @@ -2529,7 +2511,7 @@ static int cpsw_set_ringparam(struct net_device *ndev, cpdma_set_num_rx_descs(cpsw->dma, ering->rx_pending); - if (cpsw_get_usage_count(cpsw)) + if (cpsw->usage_count) cpdma_chan_split_pool(cpsw->dma); ret = cpsw_resume_data_pass(ndev);