Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1306794pxk; Thu, 10 Sep 2020 12:04:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxZ76ut39hIevNL0FiycB4eNPk8NzrfF39VXDeakUDo3cA1OqCU4LSY9/LXNvf9C53U48QU X-Received: by 2002:a17:906:ae8f:: with SMTP id md15mr9923008ejb.131.1599764650336; Thu, 10 Sep 2020 12:04:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599764650; cv=none; d=google.com; s=arc-20160816; b=ID0jt4ImyvyiJPlriqkKVdjqllYrRvIWR4IOEsW9z0zosqfYUZU60N4d9qoe3SWCud 9cDSmmmDd90gERZwIwkg5gPgWT+nl3S56eR39pro76MSL4gTB0nrf8r8kjdM7cW6pQfa OJjKnk8VpIPTPzy0igjVJvPEvxwuuggrkR40tbhGHSPNNYKXpfAI6zoHZrutsazVWiVE ETZycpZdcKtUtL57dTfm1Mq1k2vu0DyOrc+94THaAPi/8BmaUhSzmr57oOHVHL5wI1bR 2rzXCqPp0ihfdSWjWWqs/4tjMnyKZlha94rLVwvlzzFZoR2X8AATQuvUzpcOw3ZrOKmV /wSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=3UPlh3Kyd3Y4TY4RZl2rxdxtBbfraaBRvID8Rle5+Mg=; b=wu5jaIk1cLLNvrIsyJ1/ua15744hjoEjZ6bB/HZfd7OkOzbTmJjbX9mUKDOQ7cWscL PFjraT+N4q2/PFpSGs0Qwd6NLJ/GRWeFgPa94184ffbhxJfMj38/EEhpojWxP4a4Cnoa H33eBefZEWD121iLfw/vVUZMuI4WgSg+qFC4bD1DaDbLLflSBKik1qvzktit9tVBoNZh Y4ccPFJI6GNB4Wq/CU0Rb03YMDLIfizf64/Kdlx1BNITwLbviLc8h6qfyJfj6xma39je HII5W1hx/Jc0SnFg939DwIV3H7i2cMdcR/UBtHJWs3aisV2AJLzfiRTOXOsFfLQGqJSm d+vA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=lO1VWBQF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n2si4015589ejd.578.2020.09.10.12.03.46; Thu, 10 Sep 2020 12:04:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=lO1VWBQF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727044AbgIJStj (ORCPT + 99 others); Thu, 10 Sep 2020 14:49:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726722AbgIJQMn (ORCPT ); Thu, 10 Sep 2020 12:12:43 -0400 Received: from mail-ej1-x643.google.com (mail-ej1-x643.google.com [IPv6:2a00:1450:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4B20C0617B1; Thu, 10 Sep 2020 09:12:23 -0700 (PDT) Received: by mail-ej1-x643.google.com with SMTP id o8so9522442ejb.10; Thu, 10 Sep 2020 09:12:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=3UPlh3Kyd3Y4TY4RZl2rxdxtBbfraaBRvID8Rle5+Mg=; b=lO1VWBQFmH6VbAkxjDb2ACXNSiPX+dHed6wE3ZYfJr4XS+bsNTjLsh1JadXJWQjo97 ezKKVRjyorByCxs0EJR///Z/AG9qHjwHmdxyhDwTrprz1oLzWENWRZQDh6U6hZWjs9gx u7rb+oiIWdynm21MstjSZIRPW5LRXGfbWE6xTV/eeVl94zA0ZsmRUMfRcDmmPGo/UqVc u7X7cT7Y9/zesxbdMBysvW9q2rybKJSn3sIwf0Ejgo2cJQS9tYIv85D8NCXjzEjxOAJ1 zCQkShSr2MtvlOqHGJvPua1AyIYFPb7iDC4QEvpN/KSg95+Xdga1+B+2rZ8qJA1RFbuu oezw== 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=3UPlh3Kyd3Y4TY4RZl2rxdxtBbfraaBRvID8Rle5+Mg=; b=ZiZOKIF5OQc335QVFBTe/HkZCDHqA3brukBup/592tFn0MeWgH1uGD3FO1h4+le55x s8Z6tedvI43m0srCJ7anYiSowtxvZ/TYu2lkUTOSRyiRfulSgt0gekKIm/EOvOYObfUR kTVn7EeLCja6TRFMMPSsb/y6XmILRnGAD6+fMfb8y9PKjK2/Q51BUv0/0EKMWfF2Jt+F umvFCw0m8MM3507kHUEysrumVeSNvQm/o4MEykICOu2ZfqEH3zBB7GyUel9NVvsdH2vx AR9ZUB7Ue/EVMM4Fkr1GXYpdxIz6HZ2665KPfRJ9/RFrqIrjpemcoKj62krSSmK4KvIB At2A== X-Gm-Message-State: AOAM5316/hdlhzHZdtWrZqv+etFdjSHHNZpu0UJqTighPx52VvgdFx0v RMkfKajohNn6I68m8h4o8qFhOagH7AI= X-Received: by 2002:a17:906:cf82:: with SMTP id um2mr9523837ejb.49.1599754341751; Thu, 10 Sep 2020 09:12:21 -0700 (PDT) Received: from ogabbay-VM.habana-labs.com ([213.57.90.10]) by smtp.gmail.com with ESMTPSA id k8sm7282911ejz.60.2020.09.10.09.12.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Sep 2020 09:12:20 -0700 (PDT) From: Oded Gabbay To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org Cc: SW_Drivers@habana.ai, gregkh@linuxfoundation.org, davem@davemloft.net, kuba@kernel.org, Omer Shpigelman Subject: [PATCH 14/15] habanalabs/gaudi: support DCB protocol Date: Thu, 10 Sep 2020 19:11:25 +0300 Message-Id: <20200910161126.30948-15-oded.gabbay@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200910161126.30948-1-oded.gabbay@gmail.com> References: <20200910161126.30948-1-oded.gabbay@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Omer Shpigelman Add DCB support to configure the NIC's Priority Flow Control (PFC). The added support is minimal because a full support is not currently required. A summary of the supported callbacks: - ieee_getpfc: get the current PFC configuration. PFC is enabled by default. - ieee_setpfc: set PFC configuration. Only 0 or all 4 priorities can be enabled, no subset is allowed. - getdcbx: get DCBX capability. - setdcbx: set DCBX capability. Only host LLDP agent and IEEE protocol flavors are supported. Signed-off-by: Omer Shpigelman Reviewed-by: Oded Gabbay Signed-off-by: Oded Gabbay --- drivers/misc/habanalabs/gaudi/Makefile | 2 +- drivers/misc/habanalabs/gaudi/gaudi_nic.c | 3 + .../misc/habanalabs/gaudi/gaudi_nic_dcbnl.c | 108 ++++++++++++++++++ 3 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 drivers/misc/habanalabs/gaudi/gaudi_nic_dcbnl.c diff --git a/drivers/misc/habanalabs/gaudi/Makefile b/drivers/misc/habanalabs/gaudi/Makefile index e3002dc34a74..9757c8ba1cb0 100644 --- a/drivers/misc/habanalabs/gaudi/Makefile +++ b/drivers/misc/habanalabs/gaudi/Makefile @@ -3,5 +3,5 @@ HL_GAUDI_FILES := gaudi/gaudi.o gaudi/gaudi_hwmgr.o gaudi/gaudi_security.o \ gaudi/gaudi_coresight.o HL_GAUDI_FILES += gaudi/gaudi_nic.o gaudi/gaudi_phy.o \ - gaudi/gaudi_nic_ethtool.o \ + gaudi/gaudi_nic_ethtool.o gaudi/gaudi_nic_dcbnl.o \ gaudi/gaudi_nic_debugfs.o diff --git a/drivers/misc/habanalabs/gaudi/gaudi_nic.c b/drivers/misc/habanalabs/gaudi/gaudi_nic.c index 108db990efa8..1ea410cdafdf 100644 --- a/drivers/misc/habanalabs/gaudi/gaudi_nic.c +++ b/drivers/misc/habanalabs/gaudi/gaudi_nic.c @@ -2745,6 +2745,9 @@ static int port_register(struct hl_device *hdev, int port) ndev->netdev_ops = &gaudi_nic_netdev_ops; ndev->ethtool_ops = &gaudi_nic_ethtool_ops; +#ifdef CONFIG_DCB + ndev->dcbnl_ops = &gaudi_nic_dcbnl_ops; +#endif ndev->watchdog_timeo = NIC_TX_TIMEOUT; ndev->min_mtu = ETH_MIN_MTU; ndev->max_mtu = NIC_MAX_MTU; diff --git a/drivers/misc/habanalabs/gaudi/gaudi_nic_dcbnl.c b/drivers/misc/habanalabs/gaudi/gaudi_nic_dcbnl.c new file mode 100644 index 000000000000..b8f37fd0d3cf --- /dev/null +++ b/drivers/misc/habanalabs/gaudi/gaudi_nic_dcbnl.c @@ -0,0 +1,108 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * Copyright 2018-2020 HabanaLabs, Ltd. + * All Rights Reserved. + */ + +#include "gaudi_nic.h" + +#define PFC_PRIO_NUM 4 +#define PFC_PRIO_MASK_ALL GENMASK(PFC_PRIO_NUM - 1, 0) +#define PFC_PRIO_MASK_NONE 0 +#define PFC_STAT_TX_OFFSET 17 +#define PFC_STAT_RX_OFFSET 27 + +#ifdef CONFIG_DCB +static int gaudi_nic_dcbnl_ieee_getpfc(struct net_device *netdev, + struct ieee_pfc *pfc) +{ + struct gaudi_nic_device **ptr = netdev_priv(netdev); + struct gaudi_nic_device *gaudi_nic = *ptr; + struct hl_device *hdev = gaudi_nic->hdev; + u32 port = gaudi_nic->port; + int rc = 0, i, tx_idx, rx_idx; + + if (disabled_or_in_reset(gaudi_nic)) { + dev_info_ratelimited(hdev->dev, + "port %d is in reset, can't get PFC", port); + return -EBUSY; + } + + pfc->pfc_en = gaudi_nic->pfc_enable ? PFC_PRIO_MASK_ALL : + PFC_PRIO_MASK_NONE; + pfc->pfc_cap = PFC_PRIO_NUM; + + for (i = 0 ; i < PFC_PRIO_NUM ; i++) { + tx_idx = PFC_STAT_TX_OFFSET + i; + rx_idx = PFC_STAT_RX_OFFSET + i; + + pfc->requests[i] = gaudi_nic_read_mac_stat_counter(hdev, port, + tx_idx, false); + pfc->indications[i] = gaudi_nic_read_mac_stat_counter(hdev, + port, rx_idx, true); + } + + return rc; +} + +static int gaudi_nic_dcbnl_ieee_setpfc(struct net_device *netdev, + struct ieee_pfc *pfc) +{ + struct gaudi_nic_device **ptr = netdev_priv(netdev); + struct gaudi_nic_device *gaudi_nic = *ptr; + struct hl_device *hdev = gaudi_nic->hdev; + u32 port = gaudi_nic->port; + u8 curr_pfc_en; + + if (pfc->pfc_en & ~PFC_PRIO_MASK_ALL) { + dev_info_ratelimited(hdev->dev, + "PFC supports %d priorities only, port %d\n", + PFC_PRIO_NUM, port); + return -EINVAL; + } + + if ((pfc->pfc_en != PFC_PRIO_MASK_NONE) && + (pfc->pfc_en != PFC_PRIO_MASK_ALL)) { + dev_info_ratelimited(hdev->dev, + "PFC should be enabled/disabled on all priorities, port %d\n", + port); + return -EINVAL; + } + + if (disabled_or_in_reset(gaudi_nic)) { + dev_info_ratelimited(hdev->dev, + "port %d is in reset, can't set PFC", port); + return -EBUSY; + } + + curr_pfc_en = gaudi_nic->pfc_enable ? PFC_PRIO_MASK_ALL : + PFC_PRIO_MASK_NONE; + + if (pfc->pfc_en == curr_pfc_en) + return 0; + + gaudi_nic->pfc_enable = !gaudi_nic->pfc_enable; + + gaudi_nic_set_pfc(gaudi_nic); + + return 0; +} + +static u8 gaudi_nic_dcbnl_getdcbx(struct net_device *netdev) +{ + return DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_IEEE; +} + +static u8 gaudi_nic_dcbnl_setdcbx(struct net_device *netdev, u8 mode) +{ + return !(mode == (DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_IEEE)); +} + +const struct dcbnl_rtnl_ops gaudi_nic_dcbnl_ops = { + .ieee_getpfc = gaudi_nic_dcbnl_ieee_getpfc, + .ieee_setpfc = gaudi_nic_dcbnl_ieee_setpfc, + .getdcbx = gaudi_nic_dcbnl_getdcbx, + .setdcbx = gaudi_nic_dcbnl_setdcbx +}; +#endif -- 2.17.1