Received: by 10.223.164.221 with SMTP id h29csp2063259wrb; Thu, 2 Nov 2017 05:24:55 -0700 (PDT) X-Google-Smtp-Source: ABhQp+ToLsvUPHDnBGb5Cw0/VzToqkVz0lNNJCqKIudYn6YKYy9RelNPzQhtXbP84JgKUApIJL5N X-Received: by 10.84.169.1 with SMTP id g1mr3125959plb.349.1509625495659; Thu, 02 Nov 2017 05:24:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509625495; cv=none; d=google.com; s=arc-20160816; b=CPEeU+UcEYqIc3owC+EeTsZZ4arWW7ho32pLgax4s+kb+L4EbS/Hw2S3HyswdDSHff oL8ZTau+rIojzdxiJ++/lxW1NF5q9JKib2N8EXRh9W5Ot6vjaGf3JkgfTrPNYKeIxswt to4QL6mEZoVgLIZfZPCzopgjg2jevxgfKo9vo8kOtkRbCCOTpJU6JKLCl/LCzDepKT1X X+kNqksssZRFS8ncyFsek6yf2cvEMhm2cMjZBFcRaR/Nw6GQfwRwxMwzhiT7Zl2OHr8T 3Ip46TPU74DH+NEHCUiXAZDEo4NBIxm2fxxzd4AFn0VedBohD98T7j4c+cNq5RuKcCmd j0fA== 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=AzO/mOEP0vDNNrjVN6C9asyKfogW0lQcSuDhVFKk6Bs=; b=NuGtLiJIrIUWYJXg6AIBNiPlA/9bBTlmbtQmcpW72fenxHOIV/WBTN0fXI5DjimhI4 DWc8muZf+LGLuJsdiw4fci+jhn9LSlwtFMo1o1tO3fMtE4UZEDO2dzgTpUb0WNUG0BNd nUtdj+6jQIHJzJguGp71RajSe9qKKe/HGIpQDfFnNipCyd/rv7gQQge28a9+v3Dr2Xve vXwlNLw7ZueyhY73LtE+o4OM4QUhTB7DCeZtYtr7HTn68lmcLicTBLtiQK1Nb4Isnmfo vfrvSNe6gB5rXdxrqcw+lvI5gyodn9LTdfnM1R1ou4WKceD1rWmwa34H18amd2AE51Fc 529A== 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 a67si3645339pfe.76.2017.11.02.05.24.41; Thu, 02 Nov 2017 05:24:55 -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 S932788AbdKBMVL (ORCPT + 96 others); Thu, 2 Nov 2017 08:21:11 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:51481 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752139AbdKBMTE (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 939F2FE1A6F10; 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 7/9] net: hns3: Add reset interface implementation in client Date: Thu, 2 Nov 2017 20:45:21 +0800 Message-ID: <1509626723-18619-8-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 implement the interface of reset notification in hns3_enet, it will do resetting business which include shutdown nic device, free and initialize client side resource. Signed-off-by: qumingguang Signed-off-by: Lipeng Signed-off-by: Yunsheng Lin --- .../net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c | 153 +++++++++++++++++++++ 1 file changed, 153 insertions(+) diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c index f0cb88a..39679fd 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c @@ -3009,11 +3009,164 @@ static int hns3_client_setup_tc(struct hnae3_handle *handle, u8 tc) return ret; } +static void hns3_recover_hw_addr(struct net_device *ndev) +{ + struct netdev_hw_addr_list *list; + struct netdev_hw_addr *ha, *tmp; + + /* go through and sync uc_addr entries to the device */ + list = &ndev->uc; + list_for_each_entry_safe(ha, tmp, &list->list, list) + hns3_nic_uc_sync(ndev, ha->addr); + + /* go through and sync mc_addr entries to the device */ + list = &ndev->mc; + list_for_each_entry_safe(ha, tmp, &list->list, list) + hns3_nic_mc_sync(ndev, ha->addr); +} + +static void hns3_drop_skb_data(struct hns3_enet_ring *ring, struct sk_buff *skb) +{ + dev_kfree_skb_any(skb); +} + +static void hns3_clear_all_ring(struct hnae3_handle *h) +{ + struct net_device *ndev = h->kinfo.netdev; + struct hns3_nic_priv *priv = netdev_priv(ndev); + u32 i; + + for (i = 0; i < h->kinfo.num_tqps; i++) { + struct netdev_queue *dev_queue; + struct hns3_enet_ring *ring; + + ring = priv->ring_data[i].ring; + hns3_clean_tx_ring(ring, ring->desc_num); + dev_queue = netdev_get_tx_queue(ndev, + priv->ring_data[i].queue_index); + netdev_tx_reset_queue(dev_queue); + + ring = priv->ring_data[i + h->kinfo.num_tqps].ring; + hns3_clean_rx_ring(ring, ring->desc_num, hns3_drop_skb_data); + } +} + +static int hns3_reset_notify_down_enet(struct hnae3_handle *handle) +{ + struct hnae3_knic_private_info *kinfo = &handle->kinfo; + struct net_device *ndev = kinfo->netdev; + + if (!netif_running(ndev)) + return -EIO; + + return hns3_nic_net_stop(ndev); +} + +static int hns3_reset_notify_up_enet(struct hnae3_handle *handle) +{ + struct hnae3_knic_private_info *kinfo = &handle->kinfo; + struct hns3_nic_priv *priv = netdev_priv(kinfo->netdev); + int ret = 0; + + if (netif_running(kinfo->netdev)) { + ret = hns3_nic_net_up(kinfo->netdev); + if (ret) { + netdev_err(kinfo->netdev, + "hns net up fail, ret=%d!\n", ret); + return ret; + } + + priv->last_reset_time = jiffies; + } + + return ret; +} + +static int hns3_reset_notify_init_enet(struct hnae3_handle *handle) +{ + struct net_device *netdev = handle->kinfo.netdev; + struct hns3_nic_priv *priv = netdev_priv(netdev); + int ret; + + priv->reset_level = 1; + hns3_init_mac_addr(netdev); + hns3_nic_set_rx_mode(netdev); + hns3_recover_hw_addr(netdev); + + /* Carrier off reporting is important to ethtool even BEFORE open */ + netif_carrier_off(netdev); + + ret = hns3_get_ring_config(priv); + if (ret) + return ret; + + ret = hns3_nic_init_vector_data(priv); + if (ret) + return ret; + + ret = hns3_init_all_ring(priv); + if (ret) { + hns3_nic_uninit_vector_data(priv); + priv->ring_data = NULL; + } + + return ret; +} + +static int hns3_reset_notify_uninit_enet(struct hnae3_handle *handle) +{ + struct net_device *netdev = handle->kinfo.netdev; + struct hns3_nic_priv *priv = netdev_priv(netdev); + int ret; + + hns3_clear_all_ring(handle); + + ret = hns3_nic_uninit_vector_data(priv); + if (ret) { + netdev_err(netdev, "uninit vector error\n"); + return ret; + } + + ret = hns3_uninit_all_ring(priv); + if (ret) + netdev_err(netdev, "uninit ring error\n"); + + priv->ring_data = NULL; + + return ret; +} + +static int hns3_reset_notify(struct hnae3_handle *handle, + enum hnae3_reset_notify_type type) +{ + int ret = 0; + + switch (type) { + case HNAE3_UP_CLIENT: + ret = hns3_reset_notify_up_enet(handle); + break; + case HNAE3_DOWN_CLIENT: + ret = hns3_reset_notify_down_enet(handle); + break; + case HNAE3_INIT_CLIENT: + ret = hns3_reset_notify_init_enet(handle); + break; + case HNAE3_UNINIT_CLIENT: + ret = hns3_reset_notify_uninit_enet(handle); + break; + default: + break; + } + + return ret; +} + static const struct hnae3_client_ops client_ops = { .init_instance = hns3_client_init, .uninit_instance = hns3_client_uninit, .link_status_change = hns3_link_status_change, .setup_tc = hns3_client_setup_tc, + .reset_notify = hns3_reset_notify, }; /* hns3_init_module - Driver registration routine -- 1.9.1 From 1583021067275585498@xxx Fri Nov 03 05:22:14 +0000 2017 X-GM-THRID: 1582952273200643934 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread