Received: by 10.223.164.221 with SMTP id h29csp2061354wrb; Thu, 2 Nov 2017 05:23:07 -0700 (PDT) X-Google-Smtp-Source: ABhQp+SBwqhJSxRZv5ky4T/lB1hnVCVBp/ytvffjhWoEF0RdIq7AzaAxbBYk/R46qJGNSEaTUSQw X-Received: by 10.159.218.142 with SMTP id w14mr3129046plp.310.1509625387045; Thu, 02 Nov 2017 05:23:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509625387; cv=none; d=google.com; s=arc-20160816; b=WjWIVoG5z/N/hEr1JNzIaTT6Y92ZGAPirD05c4Tz/03Eekjd4yM2eDrBNrT1DBYnf8 8LSKdeHFlhuoKgMU8ixIaSB4l+5nY79yDx149u3R+29M4XJ/bq7xysGDAVX36NMojqqA nZhGVS8OdEKr/lPHdhdQkwrY/B4I0pf3Y93D8xVf5Q+jcJhjmQrGR51p/r2cN3c543kW SD3SQO5B/u3qGwmHsldxCY4yAfiwFbbAp1FXDJo1zmF1Nm5FnP7usmWHuB/3vzBhEEqb 8MLiyvMSx37xYAYpBtAubs3k5sYJarkv0mqfu2LohqV+R1eHzSCDkOdurYBfozMkK8Hg /tmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=W9emkj8LlHOmKkb9yW4BsJ/6WD+2y/PHofCoY0rVDWg=; b=LiJMNfEykjjkks5I23Yel6y5gmO5cb2lIjc8r+8/GeJq/8WewINrj7SXfPgDFTgN0M 7tqzkxx0HgllNUjcimJHxWQMZCf9WJVQu/schQNi0IyqAVE6MW6y89qC6a/2XMIyFxTw Vrbp7uJg4KBFVtVtt/liTFj9y91xvwJDyWkPcGgaYXAvzOXoljqqzU1Id3B6tm8tl6Gg iameKpIeq1RuwSiUqTIR1pjNgQgdwJlTmNw+LL9mYDr4HvFzHqBqiGXHffHNRpr3/2Gi 4K8Y+xT5Nfmd8HreYGoDRWtOsJt3uO7w44gzzYcmzB4wBnco9C8sLNu5nS80V2PKTjo9 oW+Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b190si3552912pga.635.2017.11.02.05.22.48; Thu, 02 Nov 2017 05:23:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755535AbdKBMVM (ORCPT + 96 others); Thu, 2 Nov 2017 08:21:12 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:51479 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752408AbdKBMTE (ORCPT ); Thu, 2 Nov 2017 08:19:04 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 76B9BEE8B8BC1; Thu, 2 Nov 2017 20:18:50 +0800 (CST) Received: from linux-ioko.site (10.71.200.31) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.361.1; Thu, 2 Nov 2017 20:17:48 +0800 From: Lipeng To: CC: , , , , Subject: [PATCH V2 net-next 6/9] net: hns3: Add timeout process in hns3_enet Date: Thu, 2 Nov 2017 20:45:20 +0800 Message-ID: <1509626723-18619-7-git-send-email-lipeng321@huawei.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1509626723-18619-1-git-send-email-lipeng321@huawei.com> References: <1509626723-18619-1-git-send-email-lipeng321@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.71.200.31] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch add timeout handler in hns3_enet.c to handle TX side timeout event, when TX timeout event occur, it will triger NIC driver into reset process. Signed-off-by: qumingguang Signed-off-by: Lipeng Signed-off-by: Yunsheng Lin --- .../net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c | 86 ++++++++++++++++++++++ .../net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.h | 2 + 2 files changed, 88 insertions(+) diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c index c6c5b2a..f0cb88a 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c @@ -258,6 +258,7 @@ static int hns3_nic_net_up(struct net_device *netdev) static int hns3_nic_net_open(struct net_device *netdev) { + struct hns3_nic_priv *priv = netdev_priv(netdev); int ret; netif_carrier_off(netdev); @@ -273,6 +274,7 @@ static int hns3_nic_net_open(struct net_device *netdev) return ret; } + priv->last_reset_time = jiffies; return 0; } @@ -1322,10 +1324,91 @@ static int hns3_nic_change_mtu(struct net_device *netdev, int new_mtu) return ret; } +static bool hns3_get_tx_timeo_queue_info(struct net_device *ndev) +{ + struct hns3_nic_priv *priv = netdev_priv(ndev); + struct hns3_enet_ring *tx_ring = NULL; + int timeout_queue = 0; + int hw_head, hw_tail; + int i; + + /* Find the stopped queue the same way the stack does */ + for (i = 0; i < ndev->real_num_tx_queues; i++) { + struct netdev_queue *q; + unsigned long trans_start; + + q = netdev_get_tx_queue(ndev, i); + trans_start = q->trans_start; + if (netif_xmit_stopped(q) && + time_after(jiffies, + (trans_start + ndev->watchdog_timeo))) { + timeout_queue = i; + break; + } + } + + if (i == ndev->num_tx_queues) { + netdev_info(ndev, + "no netdev TX timeout queue found, timeout count: %llu\n", + priv->tx_timeout_count); + return false; + } + + tx_ring = priv->ring_data[timeout_queue].ring; + + hw_head = readl_relaxed(tx_ring->tqp->io_base + + HNS3_RING_TX_RING_HEAD_REG); + hw_tail = readl_relaxed(tx_ring->tqp->io_base + + HNS3_RING_TX_RING_TAIL_REG); + netdev_info(ndev, + "tx_timeout count: %llu, queue id: %d, SW_NTU: 0x%x, SW_NTC: 0x%x, HW_HEAD: 0x%x, HW_TAIL: 0x%x, INT: 0x%x\n", + priv->tx_timeout_count, + timeout_queue, + tx_ring->next_to_use, + tx_ring->next_to_clean, + hw_head, + hw_tail, + readl(tx_ring->tqp_vector->mask_addr)); + + return true; +} + +static void hns3_nic_net_timeout(struct net_device *ndev) +{ + struct hns3_nic_priv *priv = netdev_priv(ndev); + unsigned long last_reset_time = priv->last_reset_time; + struct hnae3_handle *h = priv->ae_handle; + + if (!hns3_get_tx_timeo_queue_info(ndev)) + return; + + priv->tx_timeout_count++; + + /* This timeout is far away enough from last timeout, + * if timeout again,set the reset type to PF reset + */ + if (time_after(jiffies, (last_reset_time + 20 * HZ))) + priv->reset_level = HNAE3_FUNC_RESET; + + /* Don't do any new action before the next timeout */ + else if (time_before(jiffies, (last_reset_time + ndev->watchdog_timeo))) + return; + + priv->last_reset_time = jiffies; + + if (h->ae_algo->ops->reset_event) + h->ae_algo->ops->reset_event(h, priv->reset_level); + + priv->reset_level++; + if (priv->reset_level > HNAE3_GLOBAL_RESET) + priv->reset_level = HNAE3_GLOBAL_RESET; +} + static const struct net_device_ops hns3_nic_netdev_ops = { .ndo_open = hns3_nic_net_open, .ndo_stop = hns3_nic_net_stop, .ndo_start_xmit = hns3_nic_net_xmit, + .ndo_tx_timeout = hns3_nic_net_timeout, .ndo_set_mac_address = hns3_nic_net_set_mac_address, .ndo_change_mtu = hns3_nic_change_mtu, .ndo_set_features = hns3_nic_set_features, @@ -2763,6 +2846,9 @@ static int hns3_client_init(struct hnae3_handle *handle) priv->dev = &pdev->dev; priv->netdev = netdev; priv->ae_handle = handle; + priv->last_reset_time = jiffies; + priv->reset_level = HNAE3_FUNC_RESET; + priv->tx_timeout_count = 0; handle->kinfo.netdev = netdev; handle->priv = (void *)priv; diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.h b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.h index 58dc30b..8a9de75 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.h +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.h @@ -518,6 +518,8 @@ struct hns3_nic_priv { /* The most recently read link state */ int link; u64 tx_timeout_count; + enum hnae3_reset_type reset_level; + unsigned long last_reset_time; unsigned long state; -- 1.9.1 From 1585317370400927968@xxx Tue Nov 28 13:40:59 +0000 2017 X-GM-THRID: 1583337261485569711 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread