From patchwork Tue Aug 13 13:56:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jijie Shao X-Patchwork-Id: 13762084 X-Patchwork-Delegate: kuba@kernel.org Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5540C17A583; Tue, 13 Aug 2024 14:02:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.190 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723557761; cv=none; b=lloxwTm1Oh9wzLlFK9v80zO9k8HeQ4lM/pqXFVl6cLU3Y90RvzuJnfUtOtFyhZvbBdJnhXLLygDVG/+PbXs9J/bJm11jWSJMxWMg6yQ1bTTq3FABMpuidFzLmEMPkGqwWaKDX8DXxIR4nQ2w1Jv9Rb4sjEBr2cpAqSikSR8BYyA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723557761; c=relaxed/simple; bh=/8BGoUo8Sjz033UAyN1qINsC3lnaQ5EhzkhogdwdH4c=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ddhJ76Zinhlo51aYIPpuiilLPRcwMI7ZCnasXja2vJJT2YSRcLAGCBTRaFRafYSrqYPiJgTnnbrM/AVWdb1WYL3iKBlVzkqtLEN2WE5en6rji7wChfn3G4PfEezNxT5HRLF42Hjm/jxG4am44VuJzuJD7c6aTPB8amDT4mL8oyI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.190 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.234]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4WjtJC2GkMz20lTf; Tue, 13 Aug 2024 21:58:03 +0800 (CST) Received: from kwepemm000007.china.huawei.com (unknown [7.193.23.189]) by mail.maildlp.com (Postfix) with ESMTPS id 50690140134; Tue, 13 Aug 2024 22:02:36 +0800 (CST) Received: from localhost.localdomain (10.90.30.45) by kwepemm000007.china.huawei.com (7.193.23.189) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Tue, 13 Aug 2024 22:02:35 +0800 From: Jijie Shao To: , , , , , , CC: , , , , , , , , , , , , Subject: [RFC PATCH V2 net-next 01/11] net: hibmcge: Add pci table supported in this module Date: Tue, 13 Aug 2024 21:56:30 +0800 Message-ID: <20240813135640.1694993-2-shaojijie@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20240813135640.1694993-1-shaojijie@huawei.com> References: <20240813135640.1694993-1-shaojijie@huawei.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm000007.china.huawei.com (7.193.23.189) X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Add pci table supported in this module, and implement pci_driver function to initialize this driver. hibmcge is a passthrough network device. Its software runs on the host side, and the MAC hardware runs on the BMC side to reduce the host CPU area. The software interacts with the MAC hardware through the PCIe. ┌─────────────────────────┐ │ HOST CPU network device │ │ ┌──────────────┐ │ │ │hibmcge driver│ │ │ └─────┬─┬──────┘ │ │ │ │ │ │HOST ┌───┴─┴───┐ │ │ │ PCIE RC │ │ └──────┴───┬─┬───┴────────┘ │ │ PCIE │ │ ┌──────┬───┴─┴───┬────────┐ │ │ PCIE EP │ │ │BMC └───┬─┬───┘ │ │ │ │ │ │ ┌────────┴─┴──────────┐ │ │ │ GE │ │ │ │ ┌─────┐ ┌─────┐ │ │ │ │ │ MAC │ │ MAC │ │ │ └─┴─┼─────┼────┼─────┼──┴─┘ │ PHY │ │ PHY │ └─────┘ └─────┘ Signed-off-by: Jijie Shao --- .../ethernet/hisilicon/hibmcge/hbg_common.h | 16 ++++ .../net/ethernet/hisilicon/hibmcge/hbg_main.c | 82 +++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 drivers/net/ethernet/hisilicon/hibmcge/hbg_common.h create mode 100644 drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_common.h b/drivers/net/ethernet/hisilicon/hibmcge/hbg_common.h new file mode 100644 index 000000000000..614650e9a71f --- /dev/null +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_common.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* Copyright (c) 2024 Hisilicon Limited. */ + +#ifndef __HBG_COMMON_H +#define __HBG_COMMON_H + +#include +#include + +struct hbg_priv { + struct net_device *netdev; + struct pci_dev *pdev; + u8 __iomem *io_base; +}; + +#endif diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c b/drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c new file mode 100644 index 000000000000..9195c7fb13e3 --- /dev/null +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c @@ -0,0 +1,82 @@ +// SPDX-License-Identifier: GPL-2.0+ +// Copyright (c) 2024 Hisilicon Limited. + +#include +#include +#include +#include "hbg_common.h" + +static int hbg_pci_init(struct pci_dev *pdev) +{ + struct net_device *netdev = pci_get_drvdata(pdev); + struct hbg_priv *priv = netdev_priv(netdev); + struct device *dev = &pdev->dev; + int ret; + + ret = pcim_enable_device(pdev); + if (ret) + return dev_err_probe(dev, ret, "failed to enable PCI device\n"); + + ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32)); + if (ret) + return dev_err_probe(dev, ret, "failed to set PCI DMA mask\n"); + + ret = pcim_iomap_regions(pdev, BIT(0), dev_driver_string(dev)); + if (ret) + return dev_err_probe(dev, ret, "failed to map PCI bar space\n"); + + priv->io_base = pcim_iomap_table(pdev)[0]; + if (!priv->io_base) + return dev_err_probe(dev, -ENOMEM, "failed to get io base\n"); + + pci_set_master(pdev); + return 0; +} + +static int hbg_probe(struct pci_dev *pdev, const struct pci_device_id *ent) +{ + struct device *dev = &pdev->dev; + struct net_device *netdev; + struct hbg_priv *priv; + int ret; + + netdev = devm_alloc_etherdev_mqs(dev, sizeof(struct hbg_priv), 1, 1); + if (!netdev) + return -ENOMEM; + + pci_set_drvdata(pdev, netdev); + + SET_NETDEV_DEV(netdev, dev); + + priv = netdev_priv(netdev); + priv->netdev = netdev; + priv->pdev = pdev; + + ret = hbg_pci_init(pdev); + if (ret) + return ret; + + ret = devm_register_netdev(dev, netdev); + if (ret) + return dev_err_probe(dev, ret, "failed to register netdev\n"); + + return 0; +} + +static const struct pci_device_id hbg_pci_tbl[] = { + {PCI_VDEVICE(HUAWEI, 0x3730), 0}, + { } +}; +MODULE_DEVICE_TABLE(pci, hbg_pci_tbl); + +static struct pci_driver hbg_driver = { + .name = "hibmcge", + .id_table = hbg_pci_tbl, + .probe = hbg_probe, +}; +module_pci_driver(hbg_driver); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Huawei Tech. Co., Ltd."); +MODULE_DESCRIPTION("hibmcge driver"); +MODULE_VERSION("1.0"); From patchwork Tue Aug 13 13:56:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jijie Shao X-Patchwork-Id: 13762087 X-Patchwork-Delegate: kuba@kernel.org Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5546719306B; Tue, 13 Aug 2024 14:02:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.190 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723557764; cv=none; b=rhSM1ELXzclMLsUU9X3Bgjyj8riy4f/3SycGAUlpa7sjsK9GJqeNidU8wQJp7bir46sRFDV8OKn18Ell6Mrj2efxdCW1U4eVpo0ikzagILiZxxrr2vef3tPfaye/rzdgCZs1PBMNEK50rD3BUIVK0qx5UyY2rUbtvmMbI3w7cZo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723557764; c=relaxed/simple; bh=c0w6xi2XFLIWh+oe9OllzcOGbsi88/66YS+StIWRMg4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Bufxvo/swGzJFJaHAxTbPm8xvSpBwl/TC2tmKAlmbSOP4e/bd/TBGWtrDcgkGFSck8zHskg/SDS63AjThlp6UHbZr/315rMAgozAJGvFPlaXL0PwB2WAmWCbeIS155qg5/3QJVW/keHOwJEdBBGgonQqK0FaMYrbAYsrIgUKgEA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.190 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.44]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4WjtHt0jm0z2CmGw; Tue, 13 Aug 2024 21:57:46 +0800 (CST) Received: from kwepemm000007.china.huawei.com (unknown [7.193.23.189]) by mail.maildlp.com (Postfix) with ESMTPS id F1B1D140361; Tue, 13 Aug 2024 22:02:36 +0800 (CST) Received: from localhost.localdomain (10.90.30.45) by kwepemm000007.china.huawei.com (7.193.23.189) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Tue, 13 Aug 2024 22:02:36 +0800 From: Jijie Shao To: , , , , , , CC: , , , , , , , , , , , , Subject: [RFC PATCH V2 net-next 02/11] net: hibmcge: Add read/write registers supported through the bar space Date: Tue, 13 Aug 2024 21:56:31 +0800 Message-ID: <20240813135640.1694993-3-shaojijie@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20240813135640.1694993-1-shaojijie@huawei.com> References: <20240813135640.1694993-1-shaojijie@huawei.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm000007.china.huawei.com (7.193.23.189) X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Add support for to read and write registers through the pic bar space. Some driver parameters, such as mac_id, are determined by the board form. Therefore, these parameters are initialized from the register as device specifications. the device specifications register are initialized and writed by bmc. driver will read these registers when loading. Signed-off-by: Jijie Shao --- .../ethernet/hisilicon/hibmcge/hbg_common.h | 28 ++++++++ .../net/ethernet/hisilicon/hibmcge/hbg_hw.c | 70 +++++++++++++++++++ .../net/ethernet/hisilicon/hibmcge/hbg_hw.h | 32 +++++++++ .../net/ethernet/hisilicon/hibmcge/hbg_main.c | 32 +++++++++ .../net/ethernet/hisilicon/hibmcge/hbg_reg.h | 20 ++++++ 5 files changed, 182 insertions(+) create mode 100644 drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.c create mode 100644 drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.h create mode 100644 drivers/net/ethernet/hisilicon/hibmcge/hbg_reg.h diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_common.h b/drivers/net/ethernet/hisilicon/hibmcge/hbg_common.h index 614650e9a71f..d1f05484f246 100644 --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_common.h +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_common.h @@ -7,10 +7,38 @@ #include #include +enum hbg_nic_state { + HBG_NIC_STATE_INITED = 0, + HBG_NIC_STATE_EVENT_HANDLING, +}; + +enum hbg_hw_event_type { + HBG_HW_EVENT_NONE = 0, + HBG_HW_EVENT_INIT, /* driver is loading */ +}; + +struct hbg_dev_specs { + u32 mac_id; + struct sockaddr mac_addr; + u32 phy_addr; + u32 mdio_frequency; + u32 rx_fifo_num; + u32 tx_fifo_num; + u32 vlan_layers; + u32 max_mtu; + u32 min_mtu; + + u32 max_frame_len; + u32 rx_buf_size; +}; + struct hbg_priv { struct net_device *netdev; struct pci_dev *pdev; u8 __iomem *io_base; + struct regmap *regmap; + struct hbg_dev_specs dev_specs; + unsigned long state; }; #endif diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.c b/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.c new file mode 100644 index 000000000000..978f680ad089 --- /dev/null +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.c @@ -0,0 +1,70 @@ +// SPDX-License-Identifier: GPL-2.0+ +// Copyright (c) 2024 Hisilicon Limited. + +#include +#include +#include +#include +#include "hbg_common.h" +#include "hbg_hw.h" +#include "hbg_reg.h" + +static bool hbg_hw_spec_is_valid(struct hbg_priv *priv) +{ + return hbg_reg_read(priv, HBG_REG_SPEC_VALID_ADDR) && + !hbg_reg_read(priv, HBG_REG_EVENT_REQ_ADDR); +} + +int hbg_hw_event_notify(struct hbg_priv *priv, enum hbg_hw_event_type event_type) +{ +#define HBG_HW_EVENT_WAIT_TIMEOUT_US (2 * 1000 * 1000) +#define HBG_HW_EVENT_WAIT_INTERVAL_US (10 * 1000) + + bool is_valid; + int ret; + + if (test_and_set_bit(HBG_NIC_STATE_EVENT_HANDLING, &priv->state)) + return -EBUSY; + + /* notify */ + hbg_reg_write(priv, HBG_REG_EVENT_REQ_ADDR, event_type); + + ret = read_poll_timeout(hbg_hw_spec_is_valid, is_valid, is_valid, + HBG_HW_EVENT_WAIT_INTERVAL_US, + HBG_HW_EVENT_WAIT_TIMEOUT_US, + HBG_HW_EVENT_WAIT_INTERVAL_US, priv); + + clear_bit(HBG_NIC_STATE_EVENT_HANDLING, &priv->state); + + if (ret) + dev_err(&priv->pdev->dev, "event %d wait timeout\n", event_type); + + return ret; +} + +int hbg_hw_dev_specs_init(struct hbg_priv *priv) +{ + struct hbg_dev_specs *dev_specs = &priv->dev_specs; + u64 mac_addr; + + if (!hbg_hw_spec_is_valid(priv)) { + dev_err(&priv->pdev->dev, "dev_specs not init\n"); + return -EINVAL; + } + + dev_specs->mac_id = hbg_reg_read(priv, HBG_REG_MAC_ID_ADDR); + dev_specs->phy_addr = hbg_reg_read(priv, HBG_REG_PHY_ID_ADDR); + dev_specs->mdio_frequency = hbg_reg_read(priv, HBG_REG_MDIO_FREQ_ADDR); + dev_specs->max_mtu = hbg_reg_read(priv, HBG_REG_MAX_MTU_ADDR); + dev_specs->min_mtu = hbg_reg_read(priv, HBG_REG_MIN_MTU_ADDR); + dev_specs->vlan_layers = hbg_reg_read(priv, HBG_REG_VLAN_LAYERS_ADDR); + dev_specs->rx_fifo_num = hbg_reg_read(priv, HBG_REG_RX_FIFO_NUM_ADDR); + dev_specs->tx_fifo_num = hbg_reg_read(priv, HBG_REG_TX_FIFO_NUM_ADDR); + mac_addr = hbg_reg_read64(priv, HBG_REG_MAC_ADDR_ADDR); + u64_to_ether_addr(mac_addr, (u8 *)dev_specs->mac_addr.sa_data); + + if (!is_valid_ether_addr((u8 *)dev_specs->mac_addr.sa_data)) + return -EADDRNOTAVAIL; + + return 0; +} diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.h b/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.h new file mode 100644 index 000000000000..e977132915e1 --- /dev/null +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.h @@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* Copyright (c) 2024 Hisilicon Limited. */ + +#ifndef __HBG_HW_H +#define __HBG_HW_H + +#include +#include + +#define hbg_reg_read(priv, reg_addr) ({ \ + u32 _value = U32_MAX; \ + (void)regmap_read((priv)->regmap, reg_addr, &_value); \ + _value; }) + +#define hbg_reg_write(priv, reg_addr, value) \ + regmap_write((priv)->regmap, reg_addr, value) + +#define hbg_reg_read64(priv, reg_addr) lo_hi_readq((priv)->io_base + (reg_addr)) + +#define hbg_reg_write64(priv, reg_addr, value) \ + lo_hi_writeq(value, (priv)->io_base + (reg_addr)) + +#define hbg_reg_read_field(priv, reg_addr, mask) \ + FIELD_GET(mask, hbg_reg_read(priv, reg_addr)) + +#define hbg_reg_write_field(priv, reg_addr, mask, val) \ + regmap_write_bits((priv)->regmap, reg_addr, mask, FIELD_PREP(mask, val)) + +int hbg_hw_event_notify(struct hbg_priv *priv, enum hbg_hw_event_type event_type); +int hbg_hw_dev_specs_init(struct hbg_priv *priv); + +#endif diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c b/drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c index 9195c7fb13e3..5ab3f1df3d21 100644 --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c @@ -5,6 +5,33 @@ #include #include #include "hbg_common.h" +#include "hbg_hw.h" + +static const struct regmap_config hbg_regmap_config = { + .reg_bits = 32, + .reg_stride = 4, + .val_bits = 32, + .max_register = 0x20000, + .fast_io = true, +}; + +static int hbg_init(struct hbg_priv *priv) +{ + struct device *dev = &priv->pdev->dev; + struct regmap *regmap; + int ret; + + regmap = devm_regmap_init_mmio(dev, priv->io_base, &hbg_regmap_config); + if (IS_ERR(regmap)) + return dev_err_probe(dev, PTR_ERR(regmap), "failed to init regmap\n"); + + priv->regmap = regmap; + ret = hbg_hw_event_notify(priv, HBG_HW_EVENT_INIT); + if (ret) + return ret; + + return hbg_hw_dev_specs_init(priv); +} static int hbg_pci_init(struct pci_dev *pdev) { @@ -56,10 +83,15 @@ static int hbg_probe(struct pci_dev *pdev, const struct pci_device_id *ent) if (ret) return ret; + ret = hbg_init(priv); + if (ret) + return ret; + ret = devm_register_netdev(dev, netdev); if (ret) return dev_err_probe(dev, ret, "failed to register netdev\n"); + set_bit(HBG_NIC_STATE_INITED, &priv->state); return 0; } diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_reg.h b/drivers/net/ethernet/hisilicon/hibmcge/hbg_reg.h new file mode 100644 index 000000000000..77153f1132fd --- /dev/null +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_reg.h @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* Copyright (c) 2024 Hisilicon Limited. */ + +#ifndef __HBG_REG_H +#define __HBG_REG_H + +/* DEV SPEC */ +#define HBG_REG_SPEC_VALID_ADDR 0x0000 +#define HBG_REG_EVENT_REQ_ADDR 0x0004 +#define HBG_REG_MAC_ID_ADDR 0x0008 +#define HBG_REG_PHY_ID_ADDR 0x000C +#define HBG_REG_MAC_ADDR_ADDR 0x0010 +#define HBG_REG_MDIO_FREQ_ADDR 0x0024 +#define HBG_REG_MAX_MTU_ADDR 0x0028 +#define HBG_REG_MIN_MTU_ADDR 0x002C +#define HBG_REG_TX_FIFO_NUM_ADDR 0x0030 +#define HBG_REG_RX_FIFO_NUM_ADDR 0x0034 +#define HBG_REG_VLAN_LAYERS_ADDR 0x0038 + +#endif From patchwork Tue Aug 13 13:56:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jijie Shao X-Patchwork-Id: 13762085 X-Patchwork-Delegate: kuba@kernel.org Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 713271DFF8; Tue, 13 Aug 2024 14:02:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.189 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723557763; cv=none; b=XagT8VfOnd3SFbJ7AAzAhMgxnIK3aYpr5WaCc9aU6Bui1r1cIFdsKtra4qw72L8Vyuhfzi2chpEnypbcAeA0S7SkZHvsYS3jXROHDBL8aRGZM1BMOBr1VBNEYEP9EVJTP3S+YYErrIFKXc1maNWTfS7XPXi7En9zUr9OwIvfxKQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723557763; c=relaxed/simple; bh=ovTeCG11jzaqF/J+RBLpusdamo+cHPfsv9sr2km7TqA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=AlDOGgVED6QrQD5PDgDYXVoY2BC7K2hDzTrbIJ/t7IsphqOCBK3d7gcUYmD07UEwKdwgglbV4gTN4zKzlMUOPw2TctPNYaGiv95HXEOIaGyI7jqCfDAl+AtzdZxecOhOyTgEdDTpmZKJLbKdldw8jpeOAbUFbHOxl6E5nrxElIg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.189 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.194]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4WjtJD1hK9zQpjN; Tue, 13 Aug 2024 21:58:04 +0800 (CST) Received: from kwepemm000007.china.huawei.com (unknown [7.193.23.189]) by mail.maildlp.com (Postfix) with ESMTPS id A4A1E1400FD; Tue, 13 Aug 2024 22:02:37 +0800 (CST) Received: from localhost.localdomain (10.90.30.45) by kwepemm000007.china.huawei.com (7.193.23.189) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Tue, 13 Aug 2024 22:02:36 +0800 From: Jijie Shao To: , , , , , , CC: , , , , , , , , , , , , Subject: [RFC PATCH V2 net-next 03/11] net: hibmcge: Add mdio and hardware configuration supported in this module Date: Tue, 13 Aug 2024 21:56:32 +0800 Message-ID: <20240813135640.1694993-4-shaojijie@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20240813135640.1694993-1-shaojijie@huawei.com> References: <20240813135640.1694993-1-shaojijie@huawei.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm000007.china.huawei.com (7.193.23.189) X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC this driver using phy through genphy device. Implements the C22 read and write PHY registers interfaces. Some hardware interfaces related to the PHY are also implemented in this patch. Signed-off-by: Jijie Shao --- .../ethernet/hisilicon/hibmcge/hbg_common.h | 19 ++ .../net/ethernet/hisilicon/hibmcge/hbg_hw.c | 107 ++++++++ .../net/ethernet/hisilicon/hibmcge/hbg_hw.h | 2 + .../net/ethernet/hisilicon/hibmcge/hbg_main.c | 5 +- .../net/ethernet/hisilicon/hibmcge/hbg_mdio.c | 253 ++++++++++++++++++ .../net/ethernet/hisilicon/hibmcge/hbg_mdio.h | 13 + .../net/ethernet/hisilicon/hibmcge/hbg_reg.h | 38 +++ .../hisilicon/hibmcge/hbg_reg_union.h | 112 ++++++++ 8 files changed, 547 insertions(+), 2 deletions(-) create mode 100644 drivers/net/ethernet/hisilicon/hibmcge/hbg_mdio.c create mode 100644 drivers/net/ethernet/hisilicon/hibmcge/hbg_mdio.h create mode 100644 drivers/net/ethernet/hisilicon/hibmcge/hbg_reg_union.h diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_common.h b/drivers/net/ethernet/hisilicon/hibmcge/hbg_common.h index d1f05484f246..f796287c0868 100644 --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_common.h +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_common.h @@ -6,6 +6,13 @@ #include #include +#include "hbg_reg.h" + +#define HBG_STATUS_DISABLE 0x0 +#define HBG_STATUS_ENABLE 0x1 +#define HBG_DEFAULT_MTU_SIZE 1500 +#define HBG_RX_SKIP1 0x00 +#define HBG_RX_SKIP2 0x01 enum hbg_nic_state { HBG_NIC_STATE_INITED = 0, @@ -32,6 +39,17 @@ struct hbg_dev_specs { u32 rx_buf_size; }; +struct hbg_mac { + struct mii_bus *mdio_bus; + struct phy_device *phydev; + u8 phy_addr; + + u32 speed; + u32 duplex; + u32 autoneg; + u32 link_status; +}; + struct hbg_priv { struct net_device *netdev; struct pci_dev *pdev; @@ -39,6 +57,7 @@ struct hbg_priv { struct regmap *regmap; struct hbg_dev_specs dev_specs; unsigned long state; + struct hbg_mac mac; }; #endif diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.c b/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.c index 978f680ad089..e1294c60cd2d 100644 --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.c +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.c @@ -68,3 +68,110 @@ int hbg_hw_dev_specs_init(struct hbg_priv *priv) return 0; } + +int hbg_hw_adjust_link(struct hbg_priv *priv, u32 speed, u32 duplex) +{ + if (speed != HBG_PORT_MODE_SGMII_10M && + speed != HBG_PORT_MODE_SGMII_100M && + speed != HBG_PORT_MODE_SGMII_1000M) + return -EOPNOTSUPP; + + if (duplex != DUPLEX_FULL && duplex != DUPLEX_HALF) + return -EOPNOTSUPP; + + hbg_reg_write_field(priv, HBG_REG_PORT_MODE_ADDR, + HBG_REG_PORT_MODE_M, speed); + hbg_reg_write_field(priv, HBG_REG_DUPLEX_TYPE_ADDR, + HBG_REG_DUPLEX_B, duplex); + + priv->mac.speed = speed; + priv->mac.duplex = duplex; + + return 0; +} + +static void hbg_hw_init_transmit_control(struct hbg_priv *priv) +{ + struct hbg_transmit_control control = { + .bits = 0, + .pad_enalbe = HBG_STATUS_ENABLE, + .crc_add = HBG_STATUS_ENABLE, + .an_enable = HBG_STATUS_ENABLE, + }; + + hbg_reg_write(priv, HBG_REG_TRANSMIT_CONTROL_ADDR, control.bits); +} + +static void hbg_hw_init_rx_ctrl(struct hbg_priv *priv) +{ + struct hbg_rx_ctrl ctrl = { + .bits = 0, + .rx_get_addr_mode = HBG_STATUS_ENABLE, + .time_inf_en = HBG_STATUS_DISABLE, + .rx_align_num = NET_IP_ALIGN, + .rxbuf_1st_skip_size = HBG_RX_SKIP1, + .rxbuf_1st_skip_size2 = HBG_RX_SKIP2, + .port_num = priv->dev_specs.mac_id, + }; + + hbg_reg_write(priv, HBG_REG_RX_CTRL_ADDR, ctrl.bits); +} + +static void hbg_hw_init_rx_pkt_mode(struct hbg_priv *priv) +{ + struct hbg_rx_pkt_mode mode = { + .bits = 0, + .parse_mode = 0x1, /* parse from L2 layer */ + }; + + hbg_reg_write(priv, HBG_REG_RX_PKT_MODE_ADDR, mode.bits); +} + +static void hbg_hw_init_recv_ctrl(struct hbg_priv *priv) +{ + struct hbg_recv_control ctrl = { + .bits = 0, + .strip_pad_en = HBG_STATUS_ENABLE, + }; + + hbg_reg_write(priv, HBG_REG_RECV_CONTROL_ADDR, ctrl.bits); +} + +static void hbg_hw_init_rx_control(struct hbg_priv *priv) +{ + hbg_reg_write_field(priv, HBG_REG_RX_BUF_SIZE_ADDR, + HBG_REG_RX_BUF_SIZE_M, priv->dev_specs.rx_buf_size); + hbg_hw_init_rx_ctrl(priv); + hbg_hw_init_rx_pkt_mode(priv); + hbg_hw_init_recv_ctrl(priv); + hbg_reg_write_field(priv, HBG_REG_CF_CRC_STRIP_ADDR, + HBG_REG_CF_CRC_STRIP_B, HBG_STATUS_DISABLE); +} + +int hbg_hw_init(struct hbg_priv *priv) +{ +/* little endian or big endian. + * ctrl means packet description, data means skb packet data + */ +#define HBG_ENDIAN_CTRL_LE_DATA_BE 0x0 + + int ret; + + ret = hbg_hw_event_notify(priv, HBG_HW_EVENT_INIT); + if (ret) + return ret; + + ret = hbg_hw_dev_specs_init(priv); + if (ret) + return ret; + + hbg_reg_write_field(priv, HBG_REG_BUS_CTRL_ADDR, + HBG_REG_BUS_CTRL_ENDIAN_M, + HBG_ENDIAN_CTRL_LE_DATA_BE); + hbg_reg_write_field(priv, HBG_REG_MODE_CHANGE_EN_ADDR, + HBG_REG_MODE_CHANGE_EN_B, HBG_STATUS_ENABLE); + + hbg_hw_init_rx_control(priv); + hbg_hw_init_transmit_control(priv); + return 0; +} diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.h b/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.h index e977132915e1..c5a2dd49399b 100644 --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.h +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.h @@ -28,5 +28,7 @@ int hbg_hw_event_notify(struct hbg_priv *priv, enum hbg_hw_event_type event_type); int hbg_hw_dev_specs_init(struct hbg_priv *priv); +int hbg_hw_adjust_link(struct hbg_priv *priv, u32 speed, u32 duplex); +int hbg_hw_init(struct hbg_priv *pri); #endif diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c b/drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c index 5ab3f1df3d21..cba301e49b8e 100644 --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c @@ -6,6 +6,7 @@ #include #include "hbg_common.h" #include "hbg_hw.h" +#include "hbg_mdio.h" static const struct regmap_config hbg_regmap_config = { .reg_bits = 32, @@ -26,11 +27,11 @@ static int hbg_init(struct hbg_priv *priv) return dev_err_probe(dev, PTR_ERR(regmap), "failed to init regmap\n"); priv->regmap = regmap; - ret = hbg_hw_event_notify(priv, HBG_HW_EVENT_INIT); + ret = hbg_hw_init(priv); if (ret) return ret; - return hbg_hw_dev_specs_init(priv); + return hbg_mdio_init(priv); } static int hbg_pci_init(struct pci_dev *pdev) diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_mdio.c b/drivers/net/ethernet/hisilicon/hibmcge/hbg_mdio.c new file mode 100644 index 000000000000..00c03865c0ba --- /dev/null +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_mdio.c @@ -0,0 +1,253 @@ +// SPDX-License-Identifier: GPL-2.0+ +// Copyright (c) 2024 Hisilicon Limited. + +#include +#include "hbg_common.h" +#include "hbg_hw.h" +#include "hbg_mdio.h" +#include "hbg_reg.h" + +#define HBG_MAC_GET_PRIV(mac) ((struct hbg_priv *)(mac)->mdio_bus->priv) +#define HBG_MII_BUS_GET_MAC(bus) (&((struct hbg_priv *)(bus)->priv)->mac) + +#define HBG_MDIO_C22_MODE 0x1 +#define HBG_MDIO_C22_REG_WRITE 0x1 +#define HBG_MDIO_C22_REG_READ 0x2 + +static void hbg_mdio_set_command(struct hbg_mac *mac, + struct hbg_mdio_command *command) +{ + hbg_reg_write(HBG_MAC_GET_PRIV(mac), HBG_REG_MDIO_COMMAND_ADDR, + command->bits); +} + +static void hbg_mdio_get_command(struct hbg_mac *mac, + struct hbg_mdio_command *command) +{ + command->bits = hbg_reg_read(HBG_MAC_GET_PRIV(mac), + HBG_REG_MDIO_COMMAND_ADDR); +} + +static void hbg_mdio_set_wdata_reg(struct hbg_mac *mac, u16 wdata_value) +{ + hbg_reg_write_field(HBG_MAC_GET_PRIV(mac), HBG_REG_MDIO_WDATA_ADDR, + HBG_REG_MDIO_WDATA_M, wdata_value); +} + +static u32 hbg_mdio_get_rdata_reg(struct hbg_mac *mac) +{ + return hbg_reg_read_field(HBG_MAC_GET_PRIV(mac), + HBG_REG_MDIO_RDATA_ADDR, + HBG_REG_MDIO_WDATA_M); +} + +static int hbg_mdio_wait_ready(struct hbg_mac *mac) +{ +#define HBG_MDIO_OP_TIMEOUT_US (1 * 1000 * 1000) +#define HBG_MDIO_OP_INTERVAL_US (5 * 1000) + + struct hbg_priv *priv = HBG_MAC_GET_PRIV(mac); + struct hbg_mdio_command command; + + return readl_poll_timeout(priv->io_base + HBG_REG_MDIO_COMMAND_ADDR, + command.bits, !command.mdio_start, + HBG_MDIO_OP_INTERVAL_US, + HBG_MDIO_OP_TIMEOUT_US); +} + +static int hbg_mdio_check_op_status(struct hbg_mac *mac) +{ + if (hbg_reg_read(HBG_MAC_GET_PRIV(mac), HBG_REG_MDIO_STA_ADDR)) + return -EBUSY; + + return 0; +} + +static int hbg_mdio_check_send_result(struct hbg_mac *mac) +{ + int ret; + + ret = hbg_mdio_wait_ready(mac); + if (ret) + return ret; + + return hbg_mdio_check_op_status(mac); +} + +static int hbg_mdio_cmd_send(struct hbg_mac *mac, u32 prt_addr, u32 dev_addr, + u32 type, u32 op_code) +{ + struct hbg_mdio_command mdio_cmd; + + hbg_mdio_get_command(mac, &mdio_cmd); + mdio_cmd.mdio_st = type; + /* if auto scan enabled, this value need fix to 0 */ + mdio_cmd.mdio_start = 0x1; + mdio_cmd.mdio_op = op_code; + mdio_cmd.mdio_prtad = prt_addr; + mdio_cmd.mdio_devad = dev_addr; + hbg_mdio_set_command(mac, &mdio_cmd); + + /* wait operation complete and check the result */ + return hbg_mdio_check_send_result(mac); +} + +static int hbg_mdio_read22(struct mii_bus *bus, int phy_addr, int regnum) +{ + struct hbg_mac *mac = HBG_MII_BUS_GET_MAC(bus); + int ret; + + ret = hbg_mdio_check_op_status(mac); + if (ret) + return ret; + + ret = hbg_mdio_cmd_send(mac, phy_addr, regnum, HBG_MDIO_C22_MODE, + HBG_MDIO_C22_REG_READ); + if (ret) + return ret; + + return hbg_mdio_get_rdata_reg(mac); +} + +static int hbg_mdio_write22(struct mii_bus *bus, int phy_addr, int regnum, + u16 val) +{ + struct hbg_mac *mac = HBG_MII_BUS_GET_MAC(bus); + int ret; + + ret = hbg_mdio_check_op_status(mac); + if (ret) + return ret; + + hbg_mdio_set_wdata_reg(mac, val); + return hbg_mdio_cmd_send(mac, phy_addr, regnum, HBG_MDIO_C22_MODE, + HBG_MDIO_C22_REG_WRITE); +} + +static int hbg_mdio_init_hw(struct hbg_priv *priv) +{ + u32 freq = priv->dev_specs.mdio_frequency; + struct hbg_mac *mac = &priv->mac; + struct hbg_mdio_command cmd; + + cmd.bits = 0; + cmd.mdio_auto_scan = HBG_STATUS_DISABLE; + cmd.mdio_st = HBG_MDIO_C22_MODE; + + /* freq use two bits, which are stored in clk_sel and clk_sel_exp */ + cmd.mdio_clk_sel = freq & 0x1; + cmd.mdio_clk_sel_exp = (((u32)freq) >> 1) & 0x1; + + hbg_mdio_set_command(mac, &cmd); + return 0; +} + +static void hbg_phy_adjust_link(struct net_device *netdev) +{ + struct hbg_priv *priv = netdev_priv(netdev); + struct phy_device *phydev = priv->mac.phydev; + u32 speed; + + if (phydev->link != priv->mac.link_status) { + if (phydev->link) { + switch (phydev->speed) { + case SPEED_10: + speed = HBG_PORT_MODE_SGMII_10M; + break; + case SPEED_100: + speed = HBG_PORT_MODE_SGMII_100M; + break; + case SPEED_1000: + speed = HBG_PORT_MODE_SGMII_1000M; + break; + default: + return; + } + + priv->mac.autoneg = phydev->autoneg; + hbg_hw_adjust_link(priv, speed, phydev->duplex); + } + + priv->mac.link_status = phydev->link; + phy_print_status(phydev); + } +} + +static void hbg_phy_disconnect(void *data) +{ + phy_disconnect((struct phy_device *)data); +} + +static int hbg_phy_connect(struct hbg_priv *priv) +{ + struct phy_device *phydev = priv->mac.phydev; + struct device *dev = &priv->pdev->dev; + struct hbg_mac *mac = &priv->mac; + int ret; + + ret = phy_connect_direct(priv->netdev, mac->phydev, hbg_phy_adjust_link, + PHY_INTERFACE_MODE_SGMII); + if (ret) + return dev_err_probe(dev, -ENOMEM, "failed to connect phy\n"); + + ret = devm_add_action_or_reset(dev, hbg_phy_disconnect, mac->phydev); + if (ret) + return ret; + + phy_remove_link_mode(phydev, ETHTOOL_LINK_MODE_1000baseT_Half_BIT); + phy_attached_info(phydev); + + return 0; +} + +void hbg_phy_start(struct hbg_priv *priv) +{ + if (!priv->mac.phydev) + return; + + phy_start(priv->mac.phydev); +} + +void hbg_phy_stop(struct hbg_priv *priv) +{ + if (!priv->mac.phydev) + return; + + phy_stop(priv->mac.phydev); +} + +int hbg_mdio_init(struct hbg_priv *priv) +{ + struct device *dev = &priv->pdev->dev; + struct hbg_mac *mac = &priv->mac; + struct phy_device *phydev; + struct mii_bus *mdio_bus; + int ret; + + mac->phy_addr = priv->dev_specs.phy_addr; + mdio_bus = devm_mdiobus_alloc(dev); + if (!mdio_bus) + return dev_err_probe(dev, -ENOMEM, "failed to alloc MDIO bus\n"); + + mdio_bus->parent = dev; + mdio_bus->priv = priv; + mdio_bus->phy_mask = ~(1 << mac->phy_addr); + mdio_bus->name = "hibmcge mii bus"; + mac->mdio_bus = mdio_bus; + + mdio_bus->read = hbg_mdio_read22; + mdio_bus->write = hbg_mdio_write22; + snprintf(mdio_bus->id, MII_BUS_ID_SIZE, "%s-%s", "mii", dev_name(dev)); + + ret = devm_mdiobus_register(dev, mdio_bus); + if (ret) + return dev_err_probe(dev, ret, "failed to register MDIO bus\n"); + + phydev = mdiobus_get_phy(mdio_bus, mac->phy_addr); + if (!phydev) + return dev_err_probe(dev, -EIO, "failed to get phy device\n"); + + mac->phydev = phydev; + hbg_mdio_init_hw(priv); + return hbg_phy_connect(priv); +} diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_mdio.h b/drivers/net/ethernet/hisilicon/hibmcge/hbg_mdio.h new file mode 100644 index 000000000000..bca38c7fe14b --- /dev/null +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_mdio.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* Copyright (c) 2024 Hisilicon Limited. */ + +#ifndef __HBG_MDIO_H +#define __HBG_MDIO_H + +#include "hbg_common.h" + +int hbg_mdio_init(struct hbg_priv *priv); +u32 hbg_get_link_status(struct hbg_priv *priv); +void hbg_phy_start(struct hbg_priv *priv); +void hbg_phy_stop(struct hbg_priv *priv); +#endif diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_reg.h b/drivers/net/ethernet/hisilicon/hibmcge/hbg_reg.h index 77153f1132fd..a9885d705cc7 100644 --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_reg.h +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_reg.h @@ -4,6 +4,8 @@ #ifndef __HBG_REG_H #define __HBG_REG_H +#include "hbg_reg_union.h" + /* DEV SPEC */ #define HBG_REG_SPEC_VALID_ADDR 0x0000 #define HBG_REG_EVENT_REQ_ADDR 0x0004 @@ -17,4 +19,40 @@ #define HBG_REG_RX_FIFO_NUM_ADDR 0x0034 #define HBG_REG_VLAN_LAYERS_ADDR 0x0038 +/* MDIO */ +#define HBG_REG_MDIO_BASE 0x8000 +#define HBG_REG_MDIO_COMMAND_ADDR (HBG_REG_MDIO_BASE + 0x0000) +#define HBG_REG_MDIO_WDATA_ADDR (HBG_REG_MDIO_BASE + 0x0008) +#define HBG_REG_MDIO_WDATA_M GENMASK(15, 0) +#define HBG_REG_MDIO_RDATA_ADDR (HBG_REG_MDIO_BASE + 0x000C) +#define HBG_REG_MDIO_STA_ADDR (HBG_REG_MDIO_BASE + 0x0010) + +/* GMAC */ +#define HBG_REG_SGMII_BASE 0x10000 +#define HBG_REG_DUPLEX_TYPE_ADDR (HBG_REG_SGMII_BASE + 0x0008) +#define HBG_REG_DUPLEX_B BIT(0) +#define HBG_REG_PORT_MODE_ADDR (HBG_REG_SGMII_BASE + 0x0040) +#define HBG_REG_PORT_MODE_M GENMASK(3, 0) +#define HBG_REG_TRANSMIT_CONTROL_ADDR (HBG_REG_SGMII_BASE + 0x0060) +#define HBG_REG_CF_CRC_STRIP_ADDR (HBG_REG_SGMII_BASE + 0x01B0) +#define HBG_REG_CF_CRC_STRIP_B BIT(1) +#define HBG_REG_MODE_CHANGE_EN_ADDR (HBG_REG_SGMII_BASE + 0x01B4) +#define HBG_REG_MODE_CHANGE_EN_B BIT(0) +#define HBG_REG_RECV_CONTROL_ADDR (HBG_REG_SGMII_BASE + 0x01E0) + +/* PCU */ +#define HBG_REG_RX_BUF_SIZE_ADDR (HBG_REG_SGMII_BASE + 0x04E4) +#define HBG_REG_RX_BUF_SIZE_M GENMASK(15, 0) +#define HBG_REG_BUS_CTRL_ADDR (HBG_REG_SGMII_BASE + 0x04E8) +#define HBG_REG_BUS_CTRL_ENDIAN_M GENMASK(2, 1) +#define HBG_REG_RX_CTRL_ADDR (HBG_REG_SGMII_BASE + 0x04F0) +#define HBG_REG_RX_PKT_MODE_ADDR (HBG_REG_SGMII_BASE + 0x04F4) + +enum hbg_port_mode { + /* 0x0 ~ 0x5 are reserved */ + HBG_PORT_MODE_SGMII_10M = 0x6, + HBG_PORT_MODE_SGMII_100M = 0x7, + HBG_PORT_MODE_SGMII_1000M = 0x8, +}; + #endif diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_reg_union.h b/drivers/net/ethernet/hisilicon/hibmcge/hbg_reg_union.h new file mode 100644 index 000000000000..fc6cad15438d --- /dev/null +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_reg_union.h @@ -0,0 +1,112 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* Copyright (c) 2024 Hisilicon Limited. */ + +#ifndef __HBG_REG_UNION_H +#define __HBG_REG_UNION_H + +struct hbg_rx_ctrl { + union { + struct { + u32 rxbuf_1st_skip_size2 : 4; + u32 cache_line_l : 3; + u32 rx_cfg_req_en : 1; + u32 cache_line_h : 2; + u32 addr_mode : 2; + u32 rx_get_addr_mode : 1; + u32 port_num : 4; + u32 rx_align_num : 2; + u32 pool_num : 4; + u32 time_inf_en : 1; + u32 rxbuf_no_1st_skip_size : 4; + u32 rxbuf_1st_skip_size : 4; + }; + u32 bits; + }; +}; + +struct hbg_rx_pkt_mode { + union { + struct { + u32 gen_id : 8; + u32 rsv_0 : 4; + u32 match_offset : 9; + u32 parse_mode : 2; + u32 skip_len : 7; + u32 rsv_1 : 1; + u32 instr_head_mode : 1; + }; + u32 bits; + }; +}; + +struct hbg_transmit_control { + union { + struct { + u32 rsv_0 : 5; + u32 an_enable : 1; + u32 crc_add : 1; + u32 pad_enalbe : 1; + u32 rsv_1 : 24; + }; + u32 bits; + }; +}; + +struct hbg_mdio_command { + union { + struct { + u32 mdio_devad : 5; + u32 mdio_prtad :5; + u32 mdio_op : 2; + u32 mdio_st : 2; + u32 mdio_start : 1; + u32 mdio_clk_sel : 1; + u32 mdio_auto_scan : 1; + u32 mdio_clk_sel_exp : 1; + u32 rev : 14; + }; + u32 bits; + }; +}; + +struct hbg_an_state { + union { + struct { + u32 reserved_0 : 5; + /* SerDes autoneg */ + u32 half_duplex : 1; + /* SerDes autoneg */ + u32 full_duplex : 1; + /* SerDes autoneg */ + u32 support_pause_frame : 2; + u32 reserved_1 : 1; + /* SerDes autoneg, b10: 1000M; b01: 100M; b00: 10M */ + u32 speed : 2; + /* SGMII autoneg, 0: half duplex; 1: full duplex */ + u32 duplex : 1; + u32 rf2 : 1; + u32 reserved_2 : 1; + u32 link_ok : 1; + u32 reserved_3 : 4; + u32 rx_sync_ok : 1; + u32 an_done : 1; + u32 reserved_4 : 10; + }; + u32 bits; + }; +}; + +struct hbg_recv_control { + union { + struct { + u32 reserved_0 : 3; + u32 strip_pad_en : 1; + /* short frame transparent transmission enable */ + u32 runt_pkt_en : 1; + u32 reserved_1 : 27; + }; + u32 bits; + }; +}; + +#endif From patchwork Tue Aug 13 13:56:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jijie Shao X-Patchwork-Id: 13762086 X-Patchwork-Delegate: kuba@kernel.org Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AA30613CFBC; Tue, 13 Aug 2024 14:02:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.190 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723557763; cv=none; b=iwej9pQssL2b7+XxxGZ0lH94glgX7ch1f8Kh7KR63GcETaJj5y0Ww7MARJf0CR1IrHtpjDq2yYVa0GSSiCmjW5tlP3Gt0ycinnB1f7K0HTxQARIMe+MTeVX0/M4kO1I8Z9yx3zcLfKeb6NLBhNRrsQjk0EoLINJRiAI9e7q7V1E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723557763; c=relaxed/simple; bh=gcSjZLpuKEq4oPtEg5E0dwyU9Dy5DgUmJFvGbqguzj4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Rx/h75PEufc0+MbFlVF+53KBGD9BLqIyYvnNAzzs9L8w/ERBFIXS8C7nCrrLapg9TYxbK6G5DysE9svkrSaMw+7XGJqX/SgXjg8g1hIXB4+690eDCNWA5zD2+G2QAHqUf57lEGi7kxg/WVFu3Xr8F11VUe4HsKDaLm0tpV4tF1s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.190 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.162.112]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4WjtHv2vsFz2CmNF; Tue, 13 Aug 2024 21:57:47 +0800 (CST) Received: from kwepemm000007.china.huawei.com (unknown [7.193.23.189]) by mail.maildlp.com (Postfix) with ESMTPS id 4877A140337; Tue, 13 Aug 2024 22:02:38 +0800 (CST) Received: from localhost.localdomain (10.90.30.45) by kwepemm000007.china.huawei.com (7.193.23.189) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Tue, 13 Aug 2024 22:02:37 +0800 From: Jijie Shao To: , , , , , , CC: , , , , , , , , , , , , Subject: [RFC PATCH V2 net-next 04/11] net: hibmcge: Add interrupt supported in this module Date: Tue, 13 Aug 2024 21:56:33 +0800 Message-ID: <20240813135640.1694993-5-shaojijie@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20240813135640.1694993-1-shaojijie@huawei.com> References: <20240813135640.1694993-1-shaojijie@huawei.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm000007.china.huawei.com (7.193.23.189) X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC The driver supports four interrupts: TX interrupt, RX interrupt, mdio interrupt, and error interrupt. Actually, the driver does not use the mdio interrupt. Therefore, the driver does not request the mdio interrupt. The error interrupt distinguishes different error information by using different masks. To distinguish different errors, the statistics count is added for each error. To ensure the consistency of the code process, masks are added for the TX interrupt and RX interrupt. This patch implements interrupt request and free, and provides a unified entry for the interrupt handler function. However, the specific interrupt handler function of each interrupt is not implemented currently. Signed-off-by: Jijie Shao --- .../ethernet/hisilicon/hibmcge/hbg_common.h | 27 +++ .../net/ethernet/hisilicon/hibmcge/hbg_hw.c | 54 ++++++ .../net/ethernet/hisilicon/hibmcge/hbg_hw.h | 8 + .../net/ethernet/hisilicon/hibmcge/hbg_irq.c | 168 ++++++++++++++++++ .../net/ethernet/hisilicon/hibmcge/hbg_irq.h | 13 ++ .../net/ethernet/hisilicon/hibmcge/hbg_main.c | 5 + .../net/ethernet/hisilicon/hibmcge/hbg_reg.h | 34 ++++ .../hisilicon/hibmcge/hbg_reg_union.h | 60 +++++++ 8 files changed, 369 insertions(+) create mode 100644 drivers/net/ethernet/hisilicon/hibmcge/hbg_irq.c create mode 100644 drivers/net/ethernet/hisilicon/hibmcge/hbg_irq.h diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_common.h b/drivers/net/ethernet/hisilicon/hibmcge/hbg_common.h index f796287c0868..f95080359f35 100644 --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_common.h +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_common.h @@ -13,6 +13,16 @@ #define HBG_DEFAULT_MTU_SIZE 1500 #define HBG_RX_SKIP1 0x00 #define HBG_RX_SKIP2 0x01 +#define HBG_VECTOR_NUM 4 + +enum hbg_dir { + HBG_DIR_TX = 1 << 0, + HBG_DIR_RX = 1 << 1, + HBG_DIR_TX_RX = HBG_DIR_TX | HBG_DIR_RX, +}; + +#define hbg_dir_has_tx(dir) ((dir) & HBG_DIR_TX) +#define hbg_dir_has_rx(dir) ((dir) & HBG_DIR_RX) enum hbg_nic_state { HBG_NIC_STATE_INITED = 0, @@ -39,6 +49,22 @@ struct hbg_dev_specs { u32 rx_buf_size; }; +struct hbg_irq_info { + const char *name; + enum hbg_irq_mask mask; + bool reenable; + bool need_print; + u64 count; + + void (*irq_handle)(struct hbg_priv *priv, struct hbg_irq_info *irq_info); +}; + +struct hbg_vector { + char name[HBG_VECTOR_NUM][32]; + struct hbg_irq_info *info_array; + u32 info_array_len; +}; + struct hbg_mac { struct mii_bus *mdio_bus; struct phy_device *phydev; @@ -58,6 +84,7 @@ struct hbg_priv { struct hbg_dev_specs dev_specs; unsigned long state; struct hbg_mac mac; + struct hbg_vector vectors; }; #endif diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.c b/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.c index e1294c60cd2d..170aa57ca790 100644 --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.c +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.c @@ -69,6 +69,60 @@ int hbg_hw_dev_specs_init(struct hbg_priv *priv) return 0; } +void hbg_hw_get_err_intr_status(struct hbg_priv *priv, struct hbg_intr_status *status) +{ + status->bits = hbg_reg_read(priv, HBG_REG_CF_INTRPT_STAT_ADDR); +} + +void hbg_hw_set_err_intr_clear(struct hbg_priv *priv, struct hbg_intr_status *status) +{ + hbg_reg_write(priv, HBG_REG_CF_INTRPT_CLR_ADDR, status->bits); +} + +void hbg_hw_set_err_intr_mask(struct hbg_priv *priv, const struct hbg_intr_mask *msk) +{ + hbg_reg_write(priv, HBG_REG_CF_INTRPT_MSK_ADDR, msk->bits); +} + +void hbg_hw_get_err_intr_mask(struct hbg_priv *priv, struct hbg_intr_mask *msk) +{ + msk->bits = hbg_reg_read(priv, HBG_REG_CF_INTRPT_MSK_ADDR); +} + +void hbg_hw_set_txrx_intr_enable(struct hbg_priv *priv, + enum hbg_dir dir, bool enabld) +{ + u32 addr = hbg_dir_has_tx(dir) ? HBG_REG_CF_IND_TXINT_MSK_ADDR : + HBG_REG_CF_IND_RXINT_MSK_ADDR; + + hbg_reg_write_field(priv, addr, HBG_REG_IND_INTR_MASK_B, enabld); +} + +bool hbg_hw_txrx_intr_is_enabled(struct hbg_priv *priv, enum hbg_dir dir) +{ + u32 addr = hbg_dir_has_tx(dir) ? HBG_REG_CF_IND_TXINT_MSK_ADDR : + HBG_REG_CF_IND_RXINT_MSK_ADDR; + + return hbg_reg_read_field(priv, addr, HBG_REG_IND_INTR_MASK_B); +} + +void hbg_hw_set_txrx_intr_clear(struct hbg_priv *priv, enum hbg_dir dir) +{ + u32 addr = hbg_dir_has_tx(dir) ? HBG_REG_CF_IND_TXINT_CLR_ADDR : + HBG_REG_CF_IND_RXINT_CLR_ADDR; + + hbg_reg_write_field(priv, addr, HBG_REG_IND_INTR_MASK_B, 0x1); +} + +void hbg_hw_get_txrx_intr_status(struct hbg_priv *priv, struct hbg_intr_status *status) +{ + status->tx = hbg_reg_read_field(priv, HBG_REG_CF_IND_TXINT_STAT_ADDR, + HBG_REG_IND_INTR_MASK_B); + + status->rx = hbg_reg_read_field(priv, HBG_REG_CF_IND_RXINT_STAT_ADDR, + HBG_REG_IND_INTR_MASK_B); +} + int hbg_hw_adjust_link(struct hbg_priv *priv, u32 speed, u32 duplex) { if (speed != HBG_PORT_MODE_SGMII_10M && diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.h b/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.h index c5a2dd49399b..06561c39c688 100644 --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.h +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.h @@ -28,6 +28,14 @@ int hbg_hw_event_notify(struct hbg_priv *priv, enum hbg_hw_event_type event_type); int hbg_hw_dev_specs_init(struct hbg_priv *priv); +void hbg_hw_get_err_intr_status(struct hbg_priv *priv, struct hbg_intr_status *status); +void hbg_hw_get_err_intr_mask(struct hbg_priv *priv, struct hbg_intr_mask *msk); +void hbg_hw_set_err_intr_mask(struct hbg_priv *priv, const struct hbg_intr_mask *msk); +void hbg_hw_set_err_intr_clear(struct hbg_priv *priv, struct hbg_intr_status *status); +void hbg_hw_set_txrx_intr_enable(struct hbg_priv *priv, enum hbg_dir dir, bool enabld); +bool hbg_hw_txrx_intr_is_enabled(struct hbg_priv *priv, enum hbg_dir dir); +void hbg_hw_set_txrx_intr_clear(struct hbg_priv *priv, enum hbg_dir dir); +void hbg_hw_get_txrx_intr_status(struct hbg_priv *priv, struct hbg_intr_status *status); int hbg_hw_adjust_link(struct hbg_priv *priv, u32 speed, u32 duplex); int hbg_hw_init(struct hbg_priv *pri); diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_irq.c b/drivers/net/ethernet/hisilicon/hibmcge/hbg_irq.c new file mode 100644 index 000000000000..0c28e9c3fbc3 --- /dev/null +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_irq.c @@ -0,0 +1,168 @@ +// SPDX-License-Identifier: GPL-2.0+ +// Copyright (c) 2024 Hisilicon Limited. + +#include +#include "hbg_irq.h" +#include "hbg_hw.h" + +static void hbg_irq_handle_err(struct hbg_priv *priv, + struct hbg_irq_info *irq_info) +{ + if (irq_info->need_print) + dev_err(&priv->pdev->dev, + "receive abnormal interrupt: %s\n", irq_info->name); +} + +static struct hbg_irq_info hbg_irqs[] = { + { "TX", HBG_IRQ_TX, false, false, 0, NULL }, + { "RX", HBG_IRQ_RX, false, false, 0, NULL }, + { "RX_BUF_AVL", HBG_IRQ_BUF_AVL, true, false, 0, hbg_irq_handle_err }, + { "MAC_MII_FIFO_ERR", HBG_IRQ_MAC_MII_FIFO_ERR, + true, true, 0, hbg_irq_handle_err }, + { "MAC_PCS_RX_FIFO_ERR", HBG_IRQ_MAC_PCS_RX_FIFO_ERR, + true, true, 0, hbg_irq_handle_err }, + { "MAC_PCS_TX_FIFO_ERR", HBG_IRQ_MAC_PCS_TX_FIFO_ERR, + true, true, 0, hbg_irq_handle_err }, + { "MAC_APP_RX_FIFO_ERR", HBG_IRQ_MAC_APP_RX_FIFO_ERR, + true, true, 0, hbg_irq_handle_err }, + { "MAC_APP_TX_FIFO_ERR", HBG_IRQ_MAC_APP_TX_FIFO_ERR, + true, true, 0, hbg_irq_handle_err }, + { "SRAM_PARITY_ERR", HBG_IRQ_SRAM_PARITY_ERR, + true, true, 0, hbg_irq_handle_err }, + { "TX_AHB_ERR", HBG_IRQ_TX_AHB_ERR, true, true, 0, hbg_irq_handle_err }, + { "REL_BUF_ERR", HBG_IRQ_REL_BUF_ERR, true, true, 0, hbg_irq_handle_err }, + { "TXCFG_AVL", HBG_IRQ_TXCFG_AVL, true, false, 0, hbg_irq_handle_err }, + { "TX_DROP", HBG_IRQ_TX_DROP, true, false, 0, hbg_irq_handle_err }, + { "RX_DROP", HBG_IRQ_RX_DROP, true, false, 0, hbg_irq_handle_err }, + { "RX_AHB_ERR", HBG_IRQ_RX_AHB_ERR, true, true, 0, hbg_irq_handle_err }, + { "MAC_FIFO_ERR", HBG_IRQ_MAC_FIFO_ERR, + true, true, 0, hbg_irq_handle_err }, + { "RBREQ_ERR", HBG_IRQ_RBREQ_ERR, true, true, 0, hbg_irq_handle_err }, + { "WE_ERR", HBG_IRQ_WE_ERR, true, true, 0, hbg_irq_handle_err }, +}; + +void hbg_irq_enable(struct hbg_priv *priv, enum hbg_irq_mask mask, bool enable) +{ + struct hbg_intr_mask intr_mask; + + if (mask == HBG_IRQ_TX) + return hbg_hw_set_txrx_intr_enable(priv, HBG_DIR_TX, enable); + + if (mask == HBG_IRQ_RX) + return hbg_hw_set_txrx_intr_enable(priv, HBG_DIR_RX, enable); + + hbg_hw_get_err_intr_mask(priv, &intr_mask); + if (enable) + intr_mask.bits = intr_mask.bits | mask; + else + intr_mask.bits = intr_mask.bits & (~mask); + + hbg_hw_set_err_intr_mask(priv, &intr_mask); +} + +bool hbg_irq_is_enabled(struct hbg_priv *priv, enum hbg_irq_mask mask) +{ + struct hbg_intr_mask intr_mask; + + if (mask == HBG_IRQ_TX) + return hbg_hw_txrx_intr_is_enabled(priv, HBG_DIR_TX); + + if (mask == HBG_IRQ_RX) + return hbg_hw_txrx_intr_is_enabled(priv, HBG_DIR_RX); + + hbg_hw_get_err_intr_mask(priv, &intr_mask); + return intr_mask.bits & mask; +} + +static void hbg_irq_clear_src(struct hbg_priv *priv, enum hbg_irq_mask mask) +{ + struct hbg_intr_status intr_clear; + + if (mask == HBG_IRQ_TX) + return hbg_hw_set_txrx_intr_clear(priv, HBG_DIR_TX); + + if (mask == HBG_IRQ_RX) + return hbg_hw_set_txrx_intr_clear(priv, HBG_DIR_RX); + + intr_clear.bits = mask; + hbg_hw_set_err_intr_clear(priv, &intr_clear); +} + +static void hbg_irq_info_handle(struct hbg_priv *priv, + struct hbg_irq_info *irq_info) +{ + if (!hbg_irq_is_enabled(priv, irq_info->mask)) + return; + + hbg_irq_enable(priv, irq_info->mask, false); + hbg_irq_clear_src(priv, irq_info->mask); + + irq_info->count++; + if (irq_info->irq_handle) + irq_info->irq_handle(priv, irq_info); + + if (irq_info->reenable) + hbg_irq_enable(priv, irq_info->mask, true); +} + +static irqreturn_t hbg_irq_handle(int irq_num, void *p) +{ + struct hbg_intr_status intr_status; + struct hbg_irq_info *irq_info; + struct hbg_priv *priv = p; + u32 i; + + hbg_hw_get_err_intr_status(priv, &intr_status); + hbg_hw_get_txrx_intr_status(priv, &intr_status); + + for (i = 0; i < priv->vectors.info_array_len; i++) { + irq_info = &priv->vectors.info_array[i]; + if (intr_status.bits & irq_info->mask) + hbg_irq_info_handle(priv, irq_info); + } + + return IRQ_HANDLED; +} + +static const char *irq_names_map[HBG_VECTOR_NUM] = { "tx", "rx", "err", "mdio" }; + +int hbg_irq_init(struct hbg_priv *priv) +{ + struct hbg_vector *vectors = &priv->vectors; + struct device *dev = &priv->pdev->dev; + int ret, id; + u32 i; + + ret = pci_alloc_irq_vectors(priv->pdev, HBG_VECTOR_NUM, HBG_VECTOR_NUM, + PCI_IRQ_MSI | PCI_IRQ_MSIX); + if (ret < 0) + return dev_err_probe(dev, ret, "failed to allocate MSI vectors\n"); + + if (ret != HBG_VECTOR_NUM) + return dev_err_probe(dev, -EINVAL, + "requested %u MSI, but allocated %d MSI\n", + HBG_VECTOR_NUM, ret); + + /* mdio irq not request, so the number of requested interrupts + * is HBG_VECTOR_NUM - 1. + */ + for (i = 0; i < HBG_VECTOR_NUM - 1; i++) { + id = pci_irq_vector(priv->pdev, i); + if (id < 0) + return dev_err_probe(dev, id, "failed to get irq number\n"); + + snprintf(vectors->name[i], sizeof(vectors->name[i]), "%s-%s-%s", + dev_driver_string(dev), pci_name(priv->pdev), + irq_names_map[i]); + + ret = devm_request_irq(dev, id, hbg_irq_handle, 0, + vectors->name[i], priv); + if (ret) + return dev_err_probe(dev, ret, + "failed to requset irq(%d)\n", id); + } + + vectors->info_array = hbg_irqs; + vectors->info_array_len = ARRAY_SIZE(hbg_irqs); + return 0; +} diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_irq.h b/drivers/net/ethernet/hisilicon/hibmcge/hbg_irq.h new file mode 100644 index 000000000000..f332e7a958c1 --- /dev/null +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_irq.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* Copyright (c) 2024 Hisilicon Limited. */ + +#ifndef __HBG_IRQ_H +#define __HBG_IRQ_H + +#include "hbg_common.h" + +void hbg_irq_enable(struct hbg_priv *priv, enum hbg_irq_mask mask, bool enable); +bool hbg_irq_is_enabled(struct hbg_priv *priv, enum hbg_irq_mask mask); +int hbg_irq_init(struct hbg_priv *priv); + +#endif diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c b/drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c index cba301e49b8e..f1663417d01f 100644 --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c @@ -6,6 +6,7 @@ #include #include "hbg_common.h" #include "hbg_hw.h" +#include "hbg_irq.h" #include "hbg_mdio.h" static const struct regmap_config hbg_regmap_config = { @@ -31,6 +32,10 @@ static int hbg_init(struct hbg_priv *priv) if (ret) return ret; + ret = hbg_irq_init(priv); + if (ret) + return ret; + return hbg_mdio_init(priv); } diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_reg.h b/drivers/net/ethernet/hisilicon/hibmcge/hbg_reg.h index a9885d705cc7..603bfc612fde 100644 --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_reg.h +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_reg.h @@ -41,12 +41,21 @@ #define HBG_REG_RECV_CONTROL_ADDR (HBG_REG_SGMII_BASE + 0x01E0) /* PCU */ +#define HBG_REG_CF_INTRPT_MSK_ADDR (HBG_REG_SGMII_BASE + 0x042C) +#define HBG_REG_CF_INTRPT_STAT_ADDR (HBG_REG_SGMII_BASE + 0x0434) +#define HBG_REG_CF_INTRPT_CLR_ADDR (HBG_REG_SGMII_BASE + 0x0438) #define HBG_REG_RX_BUF_SIZE_ADDR (HBG_REG_SGMII_BASE + 0x04E4) #define HBG_REG_RX_BUF_SIZE_M GENMASK(15, 0) #define HBG_REG_BUS_CTRL_ADDR (HBG_REG_SGMII_BASE + 0x04E8) #define HBG_REG_BUS_CTRL_ENDIAN_M GENMASK(2, 1) #define HBG_REG_RX_CTRL_ADDR (HBG_REG_SGMII_BASE + 0x04F0) #define HBG_REG_RX_PKT_MODE_ADDR (HBG_REG_SGMII_BASE + 0x04F4) +#define HBG_REG_CF_IND_TXINT_MSK_ADDR (HBG_REG_SGMII_BASE + 0x0694) +#define HBG_REG_CF_IND_TXINT_STAT_ADDR (HBG_REG_SGMII_BASE + 0x0698) +#define HBG_REG_CF_IND_TXINT_CLR_ADDR (HBG_REG_SGMII_BASE + 0x069C) +#define HBG_REG_CF_IND_RXINT_MSK_ADDR (HBG_REG_SGMII_BASE + 0x06a0) +#define HBG_REG_CF_IND_RXINT_STAT_ADDR (HBG_REG_SGMII_BASE + 0x06a4) +#define HBG_REG_CF_IND_RXINT_CLR_ADDR (HBG_REG_SGMII_BASE + 0x06a8) enum hbg_port_mode { /* 0x0 ~ 0x5 are reserved */ @@ -55,4 +64,29 @@ enum hbg_port_mode { HBG_PORT_MODE_SGMII_1000M = 0x8, }; +enum hbg_irq_mask { + HBG_IRQ_TX = BIT(0), + HBG_IRQ_RX = BIT(1), + + /* others in err irq */ + HBG_IRQ_TX_PKG = BIT(14), + HBG_IRQ_MAC_MII_FIFO_ERR = BIT(15), + HBG_IRQ_MAC_PCS_RX_FIFO_ERR = BIT(16), + HBG_IRQ_MAC_PCS_TX_FIFO_ERR = BIT(17), + HBG_IRQ_MAC_APP_RX_FIFO_ERR = BIT(18), + HBG_IRQ_MAC_APP_TX_FIFO_ERR = BIT(19), + HBG_IRQ_SRAM_PARITY_ERR = BIT(20), + HBG_IRQ_TX_AHB_ERR = BIT(21), + HBG_IRQ_BUF_AVL = BIT(22), + HBG_IRQ_REL_BUF_ERR = BIT(23), + HBG_IRQ_TXCFG_AVL = BIT(24), + HBG_IRQ_TX_DROP = BIT(25), + HBG_IRQ_RX_DROP = BIT(26), + HBG_IRQ_RX_PKG = BIT(27), + HBG_IRQ_RX_AHB_ERR = BIT(28), + HBG_IRQ_MAC_FIFO_ERR = BIT(29), + HBG_IRQ_RBREQ_ERR = BIT(30), + HBG_IRQ_WE_ERR = BIT(31), +}; + #endif diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_reg_union.h b/drivers/net/ethernet/hisilicon/hibmcge/hbg_reg_union.h index fc6cad15438d..406eac051c10 100644 --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_reg_union.h +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_reg_union.h @@ -109,4 +109,64 @@ struct hbg_recv_control { }; }; +struct hbg_intr_status { + union { + struct { + u32 tx : 1; + u32 rx : 1; + + /* others in err irq */ + u32 rsv_0 : 12; + u32 tx_pkt_cpl : 1; + u32 mac_mii_ff_err : 1; + u32 mac_pcs_rxff_err : 1; + u32 mac_pcs_txff_err : 1; + u32 mac_app_rxff_err : 1; + u32 mac_app_txff_err : 1; + u32 sram_parity_err : 1; + u32 tx_ahb_err : 1; + u32 buf_avl : 1; + u32 rel_err : 1; + u32 txcfg_avl : 1; + u32 tx_drop : 1; + u32 rx_drop : 1; + u32 rx_frm : 1; + u32 ahb_err : 1; + u32 mac_fifo_err : 1; + u32 rbreq_err : 1; + u32 we_err : 1; + }; + u32 bits; + }; +}; + +struct hbg_intr_mask { + union { + struct { + u32 intr_time : 6; + u32 intr_pkt : 6; + u32 rsv0 : 2; + u32 tx_pkg_intr_msk : 1; + u32 mac_mii_ff_err_msk : 1; + u32 mac_pcs_rxff_err_msk : 1; + u32 mac_pcs_txff_err_msk : 1; + u32 mac_app_rxff_err_msk : 1; + u32 mac_app_txff_err_msk : 1; + u32 sram_parity_err_int_msk : 1; + u32 tx_ahb_err_int_msk : 1; + u32 buf_avl_msk : 1; + u32 rel_buf_msk : 1; + u32 txcfg_avl_msk : 1; + u32 tx_drop_int_msk : 1; + u32 rx_drop_int_msk : 1; + u32 rx_pkg_intr_msk : 1; + u32 ahb_err_int_msk : 1; + u32 mac_ff_err_int_msk : 1; + u32 rbreq_err_int_msk : 1; + u32 we_err_int_msk : 1; + }; + u32 bits; + }; +}; + #endif From patchwork Tue Aug 13 13:56:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jijie Shao X-Patchwork-Id: 13762088 X-Patchwork-Delegate: kuba@kernel.org Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9E1C2194C73; Tue, 13 Aug 2024 14:02:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.191 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723557764; cv=none; b=N61IfFXgza/P+FTn/bMdEHFfWOYtOw9lgBM+pKHZ5pTqG63CZio3gwVU9PoMsdJ9xiEHRLbBTM6cXCmrBqDdBP41XRD79GzroK9ozkUR8IHS8VfNrjkYQbT5Eb7QFvXCEMZm1rfETgY56vTY5OTgno1C4y78erFZkA2ihbLhB1k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723557764; c=relaxed/simple; bh=B1bQBU+f0MIunlOo4+lnoMsG1FIMEwl/8iP1k5JlJsk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ex+7J5xy8ep6y08LetSPvYE7gwGEPTXUAbl98Uc0/Cm0jNyS8YTl39jsDs25x8rCclI2Q14BBpKz7RD+tWop0ZQGH++E1qIUylW2T9PI+rBgsjboQea0rHRfE05F8Ys5k1tmsfbY9j8VxOUPUAQqOCsPo3mZG8/xoPBNlccWOFU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.191 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.162.112]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4WjtHw1mmpz1j6Py; Tue, 13 Aug 2024 21:57:48 +0800 (CST) Received: from kwepemm000007.china.huawei.com (unknown [7.193.23.189]) by mail.maildlp.com (Postfix) with ESMTPS id E9A2A140337; Tue, 13 Aug 2024 22:02:38 +0800 (CST) Received: from localhost.localdomain (10.90.30.45) by kwepemm000007.china.huawei.com (7.193.23.189) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Tue, 13 Aug 2024 22:02:38 +0800 From: Jijie Shao To: , , , , , , CC: , , , , , , , , , , , , Subject: [RFC PATCH V2 net-next 05/11] net: hibmcge: Implement some .ndo functions Date: Tue, 13 Aug 2024 21:56:34 +0800 Message-ID: <20240813135640.1694993-6-shaojijie@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20240813135640.1694993-1-shaojijie@huawei.com> References: <20240813135640.1694993-1-shaojijie@huawei.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm000007.china.huawei.com (7.193.23.189) X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Implement the .ndo_open .ndo_stop .ndo_set_mac_address and .ndo_change_mtu functions. And .ndo_validate_addr calls the eth_validate_addr function directly Signed-off-by: Jijie Shao --- .../ethernet/hisilicon/hibmcge/hbg_common.h | 4 + .../net/ethernet/hisilicon/hibmcge/hbg_hw.c | 40 +++++++++ .../net/ethernet/hisilicon/hibmcge/hbg_hw.h | 3 + .../net/ethernet/hisilicon/hibmcge/hbg_main.c | 88 +++++++++++++++++++ .../net/ethernet/hisilicon/hibmcge/hbg_reg.h | 9 ++ 5 files changed, 144 insertions(+) diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_common.h b/drivers/net/ethernet/hisilicon/hibmcge/hbg_common.h index f95080359f35..14aea265b71e 100644 --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_common.h +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_common.h @@ -27,8 +27,12 @@ enum hbg_dir { enum hbg_nic_state { HBG_NIC_STATE_INITED = 0, HBG_NIC_STATE_EVENT_HANDLING, + HBG_NIC_STATE_OPEN, }; +#define hbg_nic_is_open(priv) test_bit(HBG_NIC_STATE_OPEN, &(priv)->state) +#define hbg_nic_is_inited(priv) test_bit(HBG_NIC_STATE_INITED, &(priv)->state) + enum hbg_hw_event_type { HBG_HW_EVENT_NONE = 0, HBG_HW_EVENT_INIT, /* driver is loading */ diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.c b/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.c index 170aa57ca790..89a7b8aafbf7 100644 --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.c +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.c @@ -69,6 +69,46 @@ int hbg_hw_dev_specs_init(struct hbg_priv *priv) return 0; } +void hbg_hw_set_uc_addr(struct hbg_priv *priv, u64 mac_addr) +{ + hbg_reg_write64(priv, HBG_REG_STATION_ADDR_LOW_2_ADDR, mac_addr); +} + +static void hbg_hw_set_pcu_max_frame_len(struct hbg_priv *priv, + u16 max_frame_len) +{ +#define HBG_PCU_FRAME_LEN_PLUS 4 + + max_frame_len = max_t(u32, max_frame_len, HBG_DEFAULT_MTU_SIZE); + + /* lower two bits of value must be set to 0. Otherwise, the value is ignored */ + max_frame_len = round_up(max_frame_len, HBG_PCU_FRAME_LEN_PLUS); + + hbg_reg_write_field(priv, HBG_REG_MAX_FRAME_LEN_ADDR, + HBG_REG_MAX_FRAME_LEN_M, max_frame_len); +} + +static void hbg_hw_set_mac_max_frame_len(struct hbg_priv *priv, + u16 max_frame_size) +{ + hbg_reg_write_field(priv, HBG_REG_MAX_FRAME_SIZE_ADDR, + HBG_REG_MAX_FRAME_LEN_M, max_frame_size); +} + +void hbg_hw_set_mtu(struct hbg_priv *priv, u16 mtu) +{ + hbg_hw_set_pcu_max_frame_len(priv, mtu); + hbg_hw_set_mac_max_frame_len(priv, mtu); +} + +void hbg_hw_mac_enable(struct hbg_priv *priv, u32 enable) +{ + hbg_reg_write_field(priv, HBG_REG_PORT_ENABLE_ADDR, + HBG_REG_PORT_ENABLE_TX_B, enable); + hbg_reg_write_field(priv, HBG_REG_PORT_ENABLE_ADDR, + HBG_REG_PORT_ENABLE_RX_B, enable); +} + void hbg_hw_get_err_intr_status(struct hbg_priv *priv, struct hbg_intr_status *status) { status->bits = hbg_reg_read(priv, HBG_REG_CF_INTRPT_STAT_ADDR); diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.h b/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.h index 06561c39c688..d481aa2d605c 100644 --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.h +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.h @@ -28,6 +28,8 @@ int hbg_hw_event_notify(struct hbg_priv *priv, enum hbg_hw_event_type event_type); int hbg_hw_dev_specs_init(struct hbg_priv *priv); +void hbg_hw_mac_enable(struct hbg_priv *priv, u32 enable); +void hbg_hw_set_uc_addr(struct hbg_priv *priv, u64 mac_addr); void hbg_hw_get_err_intr_status(struct hbg_priv *priv, struct hbg_intr_status *status); void hbg_hw_get_err_intr_mask(struct hbg_priv *priv, struct hbg_intr_mask *msk); void hbg_hw_set_err_intr_mask(struct hbg_priv *priv, const struct hbg_intr_mask *msk); @@ -37,6 +39,7 @@ bool hbg_hw_txrx_intr_is_enabled(struct hbg_priv *priv, enum hbg_dir dir); void hbg_hw_set_txrx_intr_clear(struct hbg_priv *priv, enum hbg_dir dir); void hbg_hw_get_txrx_intr_status(struct hbg_priv *priv, struct hbg_intr_status *status); int hbg_hw_adjust_link(struct hbg_priv *priv, u32 speed, u32 duplex); +void hbg_hw_set_mtu(struct hbg_priv *priv, u16 mtu); int hbg_hw_init(struct hbg_priv *pri); #endif diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c b/drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c index f1663417d01f..d330ec1af711 100644 --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c @@ -2,6 +2,7 @@ // Copyright (c) 2024 Hisilicon Limited. #include +#include #include #include #include "hbg_common.h" @@ -17,6 +18,88 @@ static const struct regmap_config hbg_regmap_config = { .fast_io = true, }; +static void hbg_all_irq_enable(struct hbg_priv *priv, bool enabled) +{ + u32 i; + + for (i = 0; i < priv->vectors.info_array_len; i++) + hbg_irq_enable(priv, priv->vectors.info_array[i].mask, + enabled); +} + +static int hbg_net_open(struct net_device *dev) +{ + struct hbg_priv *priv = netdev_priv(dev); + + if (test_and_set_bit(HBG_NIC_STATE_OPEN, &priv->state)) + return 0; + + netif_carrier_off(dev); + hbg_all_irq_enable(priv, true); + hbg_hw_mac_enable(priv, HBG_STATUS_ENABLE); + netif_start_queue(dev); + hbg_phy_start(priv); + + return 0; +} + +static int hbg_net_stop(struct net_device *dev) +{ + struct hbg_priv *priv = netdev_priv(dev); + + if (!hbg_nic_is_open(priv)) + return 0; + + clear_bit(HBG_NIC_STATE_OPEN, &priv->state); + netif_carrier_off(dev); + hbg_phy_stop(priv); + netif_stop_queue(dev); + hbg_hw_mac_enable(priv, HBG_STATUS_DISABLE); + hbg_all_irq_enable(priv, false); + + return 0; +} + +static int hbg_net_set_mac_address(struct net_device *dev, void *addr) +{ + struct hbg_priv *priv = netdev_priv(dev); + u8 *mac_addr; + + mac_addr = ((struct sockaddr *)addr)->sa_data; + hbg_hw_set_uc_addr(priv, ether_addr_to_u64(mac_addr)); + dev_addr_set(dev, mac_addr); + + return 0; +} + +static int hbg_net_change_mtu(struct net_device *dev, int new_mtu) +{ + struct hbg_priv *priv = netdev_priv(dev); + bool is_opened = hbg_nic_is_open(priv); + u32 frame_len; + + hbg_net_stop(dev); + + frame_len = new_mtu + VLAN_HLEN * priv->dev_specs.vlan_layers + + ETH_HLEN + ETH_FCS_LEN; + hbg_hw_set_mtu(priv, frame_len); + WRITE_ONCE(dev->mtu, new_mtu); + + dev_dbg(&priv->pdev->dev, + "change mtu from %u to %u\n", dev->mtu, new_mtu); + if (is_opened) + hbg_net_open(dev); + return 0; +} + +static const struct net_device_ops hbg_netdev_ops = { + .ndo_open = hbg_net_open, + .ndo_stop = hbg_net_stop, + .ndo_validate_addr = eth_validate_addr, + .ndo_set_mac_address = hbg_net_set_mac_address, + .ndo_change_mtu = hbg_net_change_mtu, +}; + static int hbg_init(struct hbg_priv *priv) { struct device *dev = &priv->pdev->dev; @@ -84,6 +167,7 @@ static int hbg_probe(struct pci_dev *pdev, const struct pci_device_id *ent) priv = netdev_priv(netdev); priv->netdev = netdev; priv->pdev = pdev; + netdev->netdev_ops = &hbg_netdev_ops; ret = hbg_pci_init(pdev); if (ret) @@ -93,6 +177,10 @@ static int hbg_probe(struct pci_dev *pdev, const struct pci_device_id *ent) if (ret) return ret; + netdev->max_mtu = priv->dev_specs.max_mtu; + netdev->min_mtu = priv->dev_specs.min_mtu; + hbg_net_change_mtu(netdev, HBG_DEFAULT_MTU_SIZE); + hbg_net_set_mac_address(priv->netdev, &priv->dev_specs.mac_addr); ret = devm_register_netdev(dev, netdev); if (ret) return dev_err_probe(dev, ret, "failed to register netdev\n"); diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_reg.h b/drivers/net/ethernet/hisilicon/hibmcge/hbg_reg.h index 603bfc612fde..ffbb0998a221 100644 --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_reg.h +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_reg.h @@ -31,19 +31,27 @@ #define HBG_REG_SGMII_BASE 0x10000 #define HBG_REG_DUPLEX_TYPE_ADDR (HBG_REG_SGMII_BASE + 0x0008) #define HBG_REG_DUPLEX_B BIT(0) +#define HBG_REG_MAX_FRAME_SIZE_ADDR (HBG_REG_SGMII_BASE + 0x003C) #define HBG_REG_PORT_MODE_ADDR (HBG_REG_SGMII_BASE + 0x0040) #define HBG_REG_PORT_MODE_M GENMASK(3, 0) +#define HBG_REG_PORT_ENABLE_ADDR (HBG_REG_SGMII_BASE + 0x0044) +#define HBG_REG_PORT_ENABLE_RX_B BIT(1) +#define HBG_REG_PORT_ENABLE_TX_B BIT(2) #define HBG_REG_TRANSMIT_CONTROL_ADDR (HBG_REG_SGMII_BASE + 0x0060) #define HBG_REG_CF_CRC_STRIP_ADDR (HBG_REG_SGMII_BASE + 0x01B0) #define HBG_REG_CF_CRC_STRIP_B BIT(1) #define HBG_REG_MODE_CHANGE_EN_ADDR (HBG_REG_SGMII_BASE + 0x01B4) #define HBG_REG_MODE_CHANGE_EN_B BIT(0) #define HBG_REG_RECV_CONTROL_ADDR (HBG_REG_SGMII_BASE + 0x01E0) +#define HBG_REG_STATION_ADDR_LOW_2_ADDR (HBG_REG_SGMII_BASE + 0x0210) +#define HBG_REG_STATION_ADDR_HIGH_2_ADDR (HBG_REG_SGMII_BASE + 0x0214) /* PCU */ #define HBG_REG_CF_INTRPT_MSK_ADDR (HBG_REG_SGMII_BASE + 0x042C) #define HBG_REG_CF_INTRPT_STAT_ADDR (HBG_REG_SGMII_BASE + 0x0434) #define HBG_REG_CF_INTRPT_CLR_ADDR (HBG_REG_SGMII_BASE + 0x0438) +#define HBG_REG_MAX_FRAME_LEN_ADDR (HBG_REG_SGMII_BASE + 0x0444) +#define HBG_REG_MAX_FRAME_LEN_M GENMASK(15, 0) #define HBG_REG_RX_BUF_SIZE_ADDR (HBG_REG_SGMII_BASE + 0x04E4) #define HBG_REG_RX_BUF_SIZE_M GENMASK(15, 0) #define HBG_REG_BUS_CTRL_ADDR (HBG_REG_SGMII_BASE + 0x04E8) @@ -51,6 +59,7 @@ #define HBG_REG_RX_CTRL_ADDR (HBG_REG_SGMII_BASE + 0x04F0) #define HBG_REG_RX_PKT_MODE_ADDR (HBG_REG_SGMII_BASE + 0x04F4) #define HBG_REG_CF_IND_TXINT_MSK_ADDR (HBG_REG_SGMII_BASE + 0x0694) +#define HBG_REG_IND_INTR_MASK_B BIT(0) #define HBG_REG_CF_IND_TXINT_STAT_ADDR (HBG_REG_SGMII_BASE + 0x0698) #define HBG_REG_CF_IND_TXINT_CLR_ADDR (HBG_REG_SGMII_BASE + 0x069C) #define HBG_REG_CF_IND_RXINT_MSK_ADDR (HBG_REG_SGMII_BASE + 0x06a0) From patchwork Tue Aug 13 13:56:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jijie Shao X-Patchwork-Id: 13762091 X-Patchwork-Delegate: kuba@kernel.org Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DC2AB19D8AD; Tue, 13 Aug 2024 14:02:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.189 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723557767; cv=none; b=OFDHBT58M7zjnfVwR3UXMvLKOy8NtvOOylYkUjRasxnaMllmxqy9ZQlwtbWo4axcaxNrr6X4QPAIqYGRYo17lS8Dc+BTAkaWQGES3cBUVfvIXPXJ26zwKZYBSgMXQumQXdyQ/z/3gCGBDhYopPUHqanM/p8tGA11LnJLgn1TZnM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723557767; c=relaxed/simple; bh=KRlM/AFTcOuUSaB+s5irvXcpCkT3vwo6QMqiV6cVtWs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=XPjnofXVxk2gyLlD1qnv63KTb+IqjPuHcFb2aalyEZBkWv0dPW7oyRsY0G7/tyJuLpZVhdRxAqrEq0OJacpSpKbv7RuIVmX5+0uEXMk014M47bRUkg1MAH7fFUPnhXmyQ79NPY/6XqqQ1gwuEyuXEHd5Mohle0vjIUKiG39Z55I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.189 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.162.254]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4WjtJG12MnzQpds; Tue, 13 Aug 2024 21:58:06 +0800 (CST) Received: from kwepemm000007.china.huawei.com (unknown [7.193.23.189]) by mail.maildlp.com (Postfix) with ESMTPS id 8D06E1800CD; Tue, 13 Aug 2024 22:02:39 +0800 (CST) Received: from localhost.localdomain (10.90.30.45) by kwepemm000007.china.huawei.com (7.193.23.189) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Tue, 13 Aug 2024 22:02:38 +0800 From: Jijie Shao To: , , , , , , CC: , , , , , , , , , , , , Subject: [RFC PATCH V2 net-next 06/11] net: hibmcge: Implement .ndo_start_xmit function Date: Tue, 13 Aug 2024 21:56:35 +0800 Message-ID: <20240813135640.1694993-7-shaojijie@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20240813135640.1694993-1-shaojijie@huawei.com> References: <20240813135640.1694993-1-shaojijie@huawei.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm000007.china.huawei.com (7.193.23.189) X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Implement .ndo_start_xmit function to fill the information of the packet to be transmitted into the tx descriptor, and then the hardware will transmit the packet using the information in the tx descriptor. In addition, we also implemented the tx_handler function to enable the tx descriptor to be reused, and .ndo_tx_timeout function to print some information when the hardware is busy. Signed-off-by: Jijie Shao --- .../ethernet/hisilicon/hibmcge/hbg_common.h | 43 +++ .../net/ethernet/hisilicon/hibmcge/hbg_hw.c | 18 ++ .../net/ethernet/hisilicon/hibmcge/hbg_hw.h | 2 + .../net/ethernet/hisilicon/hibmcge/hbg_irq.c | 8 +- .../net/ethernet/hisilicon/hibmcge/hbg_main.c | 33 +++ .../net/ethernet/hisilicon/hibmcge/hbg_reg.h | 6 + .../hisilicon/hibmcge/hbg_reg_union.h | 29 ++ .../net/ethernet/hisilicon/hibmcge/hbg_txrx.c | 260 ++++++++++++++++++ .../net/ethernet/hisilicon/hibmcge/hbg_txrx.h | 37 +++ 9 files changed, 435 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/hisilicon/hibmcge/hbg_txrx.c create mode 100644 drivers/net/ethernet/hisilicon/hibmcge/hbg_txrx.h diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_common.h b/drivers/net/ethernet/hisilicon/hibmcge/hbg_common.h index 14aea265b71e..f63a5be936ed 100644 --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_common.h +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_common.h @@ -14,6 +14,13 @@ #define HBG_RX_SKIP1 0x00 #define HBG_RX_SKIP2 0x01 #define HBG_VECTOR_NUM 4 +#define HBG_PCU_CACHE_LINE_SIZE 32 +#define HBG_TX_TIMEOUT_BUF_LEN 1024 + +enum hbg_tx_state { + HBG_TX_STATE_COMPLETE = 0, /* clear state, must fix to 0 */ + HBG_TX_STATE_START, +}; enum hbg_dir { HBG_DIR_TX = 1 << 0, @@ -33,6 +40,41 @@ enum hbg_nic_state { #define hbg_nic_is_open(priv) test_bit(HBG_NIC_STATE_OPEN, &(priv)->state) #define hbg_nic_is_inited(priv) test_bit(HBG_NIC_STATE_INITED, &(priv)->state) +struct hbg_priv; +struct hbg_ring; +struct hbg_buffer { + u32 state; + dma_addr_t state_dma; + + struct sk_buff *skb; + dma_addr_t skb_dma; + u32 skb_len; + + enum hbg_dir dir; + struct hbg_ring *ring; + struct hbg_priv *priv; +}; + +struct hbg_ring { + struct hbg_buffer *queue; + dma_addr_t queue_dma; + + union { + u32 head; + u32 ntc; + }; + union { + u32 tail; + u32 ntu; + }; + u32 len; + + enum hbg_dir dir; + struct hbg_priv *priv; + struct napi_struct napi; + char *tout_log_buf; /* tx timeout log buffer */ +}; + enum hbg_hw_event_type { HBG_HW_EVENT_NONE = 0, HBG_HW_EVENT_INIT, /* driver is loading */ @@ -89,6 +131,7 @@ struct hbg_priv { unsigned long state; struct hbg_mac mac; struct hbg_vector vectors; + struct hbg_ring tx_ring; }; #endif diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.c b/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.c index 89a7b8aafbf7..9a8f18cece1a 100644 --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.c +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.c @@ -66,6 +66,7 @@ int hbg_hw_dev_specs_init(struct hbg_priv *priv) if (!is_valid_ether_addr((u8 *)dev_specs->mac_addr.sa_data)) return -EADDRNOTAVAIL; + dev_specs->max_frame_len = HBG_PCU_CACHE_LINE_SIZE + dev_specs->max_mtu; return 0; } @@ -109,6 +110,23 @@ void hbg_hw_mac_enable(struct hbg_priv *priv, u32 enable) HBG_REG_PORT_ENABLE_RX_B, enable); } +u32 hbg_hw_get_fifo_used_num(struct hbg_priv *priv, enum hbg_dir dir) +{ + if (hbg_dir_has_tx(dir)) + return hbg_reg_read_field(priv, HBG_REG_CF_CFF_DATA_NUM_ADDR, + HBG_REG_CF_CFF_DATA_NUM_ADDR_TX_M); + + return 0; +} + +void hbg_hw_set_tx_desc(struct hbg_priv *priv, struct hbg_tx_desc *tx_desc) +{ + hbg_reg_write(priv, HBG_REG_TX_CFF_ADDR_0_ADDR, tx_desc->word0); + hbg_reg_write(priv, HBG_REG_TX_CFF_ADDR_1_ADDR, tx_desc->word1); + hbg_reg_write(priv, HBG_REG_TX_CFF_ADDR_2_ADDR, tx_desc->pkt_addr); + hbg_reg_write(priv, HBG_REG_TX_CFF_ADDR_3_ADDR, tx_desc->clear_addr); +} + void hbg_hw_get_err_intr_status(struct hbg_priv *priv, struct hbg_intr_status *status) { status->bits = hbg_reg_read(priv, HBG_REG_CF_INTRPT_STAT_ADDR); diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.h b/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.h index d481aa2d605c..012845dd95bb 100644 --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.h +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.h @@ -41,5 +41,7 @@ void hbg_hw_get_txrx_intr_status(struct hbg_priv *priv, struct hbg_intr_status * int hbg_hw_adjust_link(struct hbg_priv *priv, u32 speed, u32 duplex); void hbg_hw_set_mtu(struct hbg_priv *priv, u16 mtu); int hbg_hw_init(struct hbg_priv *pri); +u32 hbg_hw_get_fifo_used_num(struct hbg_priv *priv, enum hbg_dir dir); +void hbg_hw_set_tx_desc(struct hbg_priv *priv, struct hbg_tx_desc *tx_desc); #endif diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_irq.c b/drivers/net/ethernet/hisilicon/hibmcge/hbg_irq.c index 0c28e9c3fbc3..134c59a7986c 100644 --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_irq.c +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_irq.c @@ -13,8 +13,14 @@ static void hbg_irq_handle_err(struct hbg_priv *priv, "receive abnormal interrupt: %s\n", irq_info->name); } +static void hbg_irq_handle_tx(struct hbg_priv *priv, + struct hbg_irq_info *irq_info) +{ + napi_schedule(&priv->tx_ring.napi); +} + static struct hbg_irq_info hbg_irqs[] = { - { "TX", HBG_IRQ_TX, false, false, 0, NULL }, + { "TX", HBG_IRQ_TX, false, false, 0, hbg_irq_handle_tx }, { "RX", HBG_IRQ_RX, false, false, 0, NULL }, { "RX_BUF_AVL", HBG_IRQ_BUF_AVL, true, false, 0, hbg_irq_handle_err }, { "MAC_MII_FIFO_ERR", HBG_IRQ_MAC_MII_FIFO_ERR, diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c b/drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c index d330ec1af711..e08e3a477cea 100644 --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c @@ -9,6 +9,7 @@ #include "hbg_hw.h" #include "hbg_irq.h" #include "hbg_mdio.h" +#include "hbg_txrx.h" static const struct regmap_config hbg_regmap_config = { .reg_bits = 32, @@ -35,6 +36,7 @@ static int hbg_net_open(struct net_device *dev) return 0; netif_carrier_off(dev); + napi_enable(&priv->tx_ring.napi); hbg_all_irq_enable(priv, true); hbg_hw_mac_enable(priv, HBG_STATUS_ENABLE); netif_start_queue(dev); @@ -56,6 +58,7 @@ static int hbg_net_stop(struct net_device *dev) netif_stop_queue(dev); hbg_hw_mac_enable(priv, HBG_STATUS_DISABLE); hbg_all_irq_enable(priv, false); + napi_disable(&priv->tx_ring.napi); return 0; } @@ -92,12 +95,33 @@ static int hbg_net_change_mtu(struct net_device *dev, int new_mtu) return 0; } +static void hbg_net_tx_timeout(struct net_device *dev, unsigned int txqueue) +{ + struct hbg_priv *priv = netdev_priv(dev); + struct hbg_ring *ring = &priv->tx_ring; + char *buf = ring->tout_log_buf; + u32 pos = 0; + + pos += scnprintf(buf + pos, HBG_TX_TIMEOUT_BUF_LEN - pos, + "ring used num: %u, fifo used num: %u\n", + hbg_get_queue_used_num(ring), + hbg_hw_get_fifo_used_num(priv, HBG_DIR_TX)); + pos += scnprintf(buf + pos, HBG_TX_TIMEOUT_BUF_LEN - pos, + "ntc: %u, ntu: %u, irq enabled: %u\n", + ring->ntc, ring->ntu, + hbg_irq_is_enabled(priv, HBG_IRQ_TX)); + + netdev_info(dev, "%s", buf); +} + static const struct net_device_ops hbg_netdev_ops = { .ndo_open = hbg_net_open, .ndo_stop = hbg_net_stop, + .ndo_start_xmit = hbg_net_start_xmit, .ndo_validate_addr = eth_validate_addr, .ndo_set_mac_address = hbg_net_set_mac_address, .ndo_change_mtu = hbg_net_change_mtu, + .ndo_tx_timeout = hbg_net_tx_timeout, }; static int hbg_init(struct hbg_priv *priv) @@ -115,6 +139,14 @@ static int hbg_init(struct hbg_priv *priv) if (ret) return ret; + ret = hbg_txrx_init(priv); + if (ret) + return ret; + + ret = devm_add_action_or_reset(&priv->pdev->dev, hbg_txrx_uninit, priv); + if (ret) + return ret; + ret = hbg_irq_init(priv); if (ret) return ret; @@ -177,6 +209,7 @@ static int hbg_probe(struct pci_dev *pdev, const struct pci_device_id *ent) if (ret) return ret; + netdev->watchdog_timeo = 5 * HZ; netdev->max_mtu = priv->dev_specs.max_mtu; netdev->min_mtu = priv->dev_specs.min_mtu; hbg_net_change_mtu(netdev, HBG_DEFAULT_MTU_SIZE); diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_reg.h b/drivers/net/ethernet/hisilicon/hibmcge/hbg_reg.h index ffbb0998a221..0feb3cd24937 100644 --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_reg.h +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_reg.h @@ -52,6 +52,12 @@ #define HBG_REG_CF_INTRPT_CLR_ADDR (HBG_REG_SGMII_BASE + 0x0438) #define HBG_REG_MAX_FRAME_LEN_ADDR (HBG_REG_SGMII_BASE + 0x0444) #define HBG_REG_MAX_FRAME_LEN_M GENMASK(15, 0) +#define HBG_REG_CF_CFF_DATA_NUM_ADDR (HBG_REG_SGMII_BASE + 0x045C) +#define HBG_REG_CF_CFF_DATA_NUM_ADDR_TX_M GENMASK(8, 0) +#define HBG_REG_TX_CFF_ADDR_0_ADDR (HBG_REG_SGMII_BASE + 0x0488) +#define HBG_REG_TX_CFF_ADDR_1_ADDR (HBG_REG_SGMII_BASE + 0x048C) +#define HBG_REG_TX_CFF_ADDR_2_ADDR (HBG_REG_SGMII_BASE + 0x0490) +#define HBG_REG_TX_CFF_ADDR_3_ADDR (HBG_REG_SGMII_BASE + 0x0494) #define HBG_REG_RX_BUF_SIZE_ADDR (HBG_REG_SGMII_BASE + 0x04E4) #define HBG_REG_RX_BUF_SIZE_M GENMASK(15, 0) #define HBG_REG_BUS_CTRL_ADDR (HBG_REG_SGMII_BASE + 0x04E8) diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_reg_union.h b/drivers/net/ethernet/hisilicon/hibmcge/hbg_reg_union.h index 406eac051c10..6a2a585451d7 100644 --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_reg_union.h +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_reg_union.h @@ -169,4 +169,33 @@ struct hbg_intr_mask { }; }; +struct hbg_tx_desc { + union { + struct { + u32 l4_cs : 1; + u32 wb : 1; + u32 l3_cs : 1; + u32 rsv0 : 16; + u32 ds : 6; + u32 sd : 1; + u32 ipoff : 5; + u32 rsv1 : 1; + }; + u32 word0; + }; + union { + struct { + u32 rsv2 : 4; + u32 len : 16; + u32 back : 6; + u32 fm : 1; + u32 l2cache : 1; + u32 rsv3 : 4; + }; + u32 word1; + }; + u32 pkt_addr; /* word2 */ + u32 clear_addr; /* word3 */ +}; + #endif diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_txrx.c b/drivers/net/ethernet/hisilicon/hibmcge/hbg_txrx.c new file mode 100644 index 000000000000..bd16f5df3b5f --- /dev/null +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_txrx.c @@ -0,0 +1,260 @@ +// SPDX-License-Identifier: GPL-2.0+ +// Copyright (c) 2024 Hisilicon Limited. + +#include "hbg_common.h" +#include "hbg_irq.h" +#include "hbg_reg.h" +#include "hbg_txrx.h" + +#define netdev_get_tx_ring(netdev) (&(((struct hbg_priv *)netdev_priv(netdev))->tx_ring)) + +#define buffer_to_dma_dir(buffer) (((buffer)->dir == HBG_DIR_RX) ? \ + DMA_FROM_DEVICE : DMA_TO_DEVICE) + +#define hbg_queue_is_full(head, tail, ring) ((head) == ((tail) + 1) % (ring)->len) +#define hbg_queue_is_empty(head, tail) ((head) == (tail)) +#define hbg_queue_next_prt(p, ring) (((p) + 1) % (ring)->len) + +static int hbg_dma_map(struct hbg_buffer *buffer) +{ + struct hbg_priv *priv = buffer->priv; + + buffer->skb_dma = dma_map_single(&priv->pdev->dev, + buffer->skb->data, buffer->skb_len, + buffer_to_dma_dir(buffer)); + if (unlikely(dma_mapping_error(&priv->pdev->dev, buffer->skb_dma))) + return -ENOMEM; + + return 0; +} + +static void hbg_dma_unmap(struct hbg_buffer *buffer) +{ + struct hbg_priv *priv = buffer->priv; + + if (unlikely(!buffer->skb_dma)) + return; + + dma_unmap_single(&priv->pdev->dev, buffer->skb_dma, buffer->skb_len, + buffer_to_dma_dir(buffer)); + buffer->skb_dma = 0; +} + +static void hbg_init_tx_desc(struct hbg_buffer *buffer, + struct hbg_tx_desc *tx_desc) +{ + tx_desc->word0 = 0; + tx_desc->word1 = 0; + + tx_desc->wb = HBG_STATUS_ENABLE; + tx_desc->len = buffer->skb->len; + tx_desc->clear_addr = buffer->state_dma; + tx_desc->pkt_addr = buffer->skb_dma; + tx_desc->ipoff = buffer->skb->network_header - buffer->skb->mac_header; + + if (likely(buffer->skb->ip_summed == CHECKSUM_PARTIAL)) { + tx_desc->l3_cs = 1; + tx_desc->l4_cs = 1; + } +} + +netdev_tx_t hbg_net_start_xmit(struct sk_buff *skb, struct net_device *net_dev) +{ + struct hbg_ring *ring = netdev_get_tx_ring(net_dev); + struct hbg_priv *priv = netdev_priv(net_dev); + /* This smp_load_acquire() pairs with smp_store_release() in + * hbg_tx_buffer_recycle() called in tx interrupt handle process. + */ + u32 ntc = smp_load_acquire(&ring->ntc); + struct hbg_buffer *buffer; + struct hbg_tx_desc tx_desc; + u32 ntu = ring->ntu; + + if (unlikely(!hbg_nic_is_open(priv))) { + dev_kfree_skb_any(skb); + return NETDEV_TX_OK; + } + + if (unlikely(!skb->len || skb->len > hbg_spec_max_frame_len(priv, HBG_DIR_TX))) { + dev_kfree_skb_any(skb); + net_dev->stats.tx_errors++; + return NETDEV_TX_OK; + } + + if (unlikely(hbg_queue_is_full(ntc, ntu, ring) || + hbg_fifo_is_full(ring->priv, ring->dir))) { + netif_stop_queue(net_dev); + return NETDEV_TX_BUSY; + } + + buffer = &ring->queue[ntu]; + buffer->skb = skb; + buffer->skb_len = skb->len; + if (unlikely(hbg_dma_map(buffer))) { + dev_kfree_skb_any(skb); + return NETDEV_TX_OK; + } + + buffer->state = HBG_TX_STATE_START; + hbg_init_tx_desc(buffer, &tx_desc); + hbg_hw_set_tx_desc(priv, &tx_desc); + + /* This smp_store_release() pairs with smp_load_acquire() in + * hbg_tx_buffer_recycle() called in tx interrupt handle process. + */ + smp_store_release(&ring->ntu, hbg_queue_next_prt(ntu, ring)); + net_dev->stats.tx_bytes += skb->len; + net_dev->stats.tx_packets++; + return NETDEV_TX_OK; +} + +static void hbg_buffer_free_skb(struct hbg_buffer *buffer) +{ + if (unlikely(!buffer->skb)) + return; + + dev_kfree_skb_any(buffer->skb); + buffer->skb = NULL; +} + +static void hbg_buffer_free(struct hbg_buffer *buffer) +{ + hbg_dma_unmap(buffer); + hbg_buffer_free_skb(buffer); +} + +static int hbg_napi_tx_recycle(struct napi_struct *napi, int budget) +{ + struct hbg_ring *ring = container_of(napi, struct hbg_ring, napi); + struct hbg_priv *priv = ring->priv; + /* This smp_load_acquire() pairs with smp_store_release() in + * hbg_start_xmit() called in xmit process. + */ + u32 ntu = smp_load_acquire(&ring->ntu); + struct hbg_buffer *buffer; + u32 ntc = ring->ntc; + int packet_done = 0; + + while (packet_done < budget) { + if (unlikely(hbg_queue_is_empty(ntc, ntu))) + break; + + /* make sure HW write desc complete */ + dma_rmb(); + + buffer = &ring->queue[ntc]; + if (buffer->state != HBG_TX_STATE_COMPLETE) + break; + + hbg_buffer_free(buffer); + ntc = hbg_queue_next_prt(ntc, ring); + packet_done++; + }; + + /* This smp_store_release() pairs with smp_load_acquire() in + * hbg_start_xmit() called in xmit process. + */ + smp_store_release(&ring->ntc, ntc); + netif_wake_queue(priv->netdev); + + if (likely(napi_complete_done(napi, packet_done))) + hbg_irq_enable(priv, HBG_IRQ_TX, true); + + return packet_done; +} + +static void hbg_ring_uninit(struct hbg_ring *ring) +{ + struct hbg_buffer *buffer; + u32 i; + + if (!ring->queue) + return; + + netif_napi_del(&ring->napi); + + for (i = 0; i < ring->len; i++) { + buffer = &ring->queue[i]; + hbg_buffer_free(buffer); + buffer->ring = NULL; + buffer->priv = NULL; + } + + dma_free_coherent(&ring->priv->pdev->dev, + ring->len * sizeof(*ring->queue), + ring->queue, ring->queue_dma); + ring->queue = NULL; + ring->queue_dma = 0; + ring->len = 0; + ring->priv = NULL; +} + +static int hbg_ring_init(struct hbg_priv *priv, struct hbg_ring *ring, + enum hbg_dir dir) +{ + struct hbg_buffer *buffer; + u32 i, len; + + len = hbg_get_spec_fifo_max_num(priv, dir) + 1; + ring->queue = dma_alloc_coherent(&priv->pdev->dev, + len * sizeof(*ring->queue), + &ring->queue_dma, GFP_KERNEL); + if (!ring->queue) + return -ENOMEM; + + for (i = 0; i < len; i++) { + buffer = &ring->queue[i]; + buffer->skb_len = 0; + buffer->dir = dir; + buffer->ring = ring; + buffer->priv = priv; + buffer->state_dma = ring->queue_dma + (i * sizeof(*buffer)); + } + + ring->dir = dir; + ring->priv = priv; + ring->ntc = 0; + ring->ntu = 0; + ring->len = len; + return 0; +} + +static int hbg_tx_ring_init(struct hbg_priv *priv) +{ + struct hbg_ring *tx_ring = &priv->tx_ring; + int ret; + + if (!tx_ring->tout_log_buf) + tx_ring->tout_log_buf = devm_kzalloc(&priv->pdev->dev, + HBG_TX_TIMEOUT_BUF_LEN, + GFP_KERNEL); + + if (!tx_ring->tout_log_buf) + return -ENOMEM; + + ret = hbg_ring_init(priv, tx_ring, HBG_DIR_TX); + if (ret) + return ret; + + netif_napi_add_tx(priv->netdev, &tx_ring->napi, hbg_napi_tx_recycle); + return 0; +} + +int hbg_txrx_init(struct hbg_priv *priv) +{ + int ret; + + ret = hbg_tx_ring_init(priv); + if (ret) + dev_err(&priv->pdev->dev, + "failed to init tx ring, ret = %d\n", ret); + + return ret; +} + +void hbg_txrx_uninit(void *data) +{ + struct hbg_priv *priv = data; + + hbg_ring_uninit(&priv->tx_ring); +} diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_txrx.h b/drivers/net/ethernet/hisilicon/hibmcge/hbg_txrx.h new file mode 100644 index 000000000000..fa00a74a451a --- /dev/null +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_txrx.h @@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* Copyright (c) 2024 Hisilicon Limited. */ + +#ifndef __HBG_TXRX_H +#define __HBG_TXRX_H + +#include +#include "hbg_hw.h" + +static inline u32 hbg_spec_max_frame_len(struct hbg_priv *priv, enum hbg_dir dir) +{ + return (dir == HBG_DIR_TX) ? priv->dev_specs.max_frame_len : + priv->dev_specs.rx_buf_size; +} + +static inline u32 hbg_get_spec_fifo_max_num(struct hbg_priv *priv, enum hbg_dir dir) +{ + return (dir == HBG_DIR_TX) ? priv->dev_specs.tx_fifo_num : + priv->dev_specs.rx_fifo_num; +} + +static inline bool hbg_fifo_is_full(struct hbg_priv *priv, enum hbg_dir dir) +{ + return hbg_hw_get_fifo_used_num(priv, dir) >= + hbg_get_spec_fifo_max_num(priv, dir); +} + +static inline u32 hbg_get_queue_used_num(struct hbg_ring *ring) +{ + return (ring->ntu + ring->len - ring->ntc) % ring->len; +} + +netdev_tx_t hbg_net_start_xmit(struct sk_buff *skb, struct net_device *net_dev); +int hbg_txrx_init(struct hbg_priv *priv); +void hbg_txrx_uninit(void *data); + +#endif From patchwork Tue Aug 13 13:56:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jijie Shao X-Patchwork-Id: 13762089 X-Patchwork-Delegate: kuba@kernel.org Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A087F19D086; Tue, 13 Aug 2024 14:02:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.191 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723557765; cv=none; b=teRLaL+E8l/HyLtIagXXhrmuxBIixzSeZjjP2Z0UnmUJVBx5lGgkoZ/EgWOCjT0stK26XzhAK6oyTkean3nmyIYLic6SsfTsIc11JCnDJco2T/MgihwJLynmV4Ht5Vbh6zu4ta0t4lneRbRE2ypmjq89gjUxGKXaSna9QkmN1FM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723557765; c=relaxed/simple; bh=wW7f0HLb0D4DI9iVhaBYxLqLnPX0Yay8Xm2agjrHXEo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IWu0AMzcOzLwok2U0ioPtNdlq/PiNFkoCg+Gnwcn/+BVqlytj6C8gIpR12vrvAkE3bRTl3Qw+jivQz4Jkl3TWCLYCRTJ29WXQsnNqcTyvPCYpEcvzCClvnAwyfFfk9Zdx02CHuvCHckVAqP7bZ8QVhJVat5k6OWy46ioL2vQoTU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.191 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.234]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4WjtL05h3Vz1HGF8; Tue, 13 Aug 2024 21:59:36 +0800 (CST) Received: from kwepemm000007.china.huawei.com (unknown [7.193.23.189]) by mail.maildlp.com (Postfix) with ESMTPS id 32CC4140134; Tue, 13 Aug 2024 22:02:40 +0800 (CST) Received: from localhost.localdomain (10.90.30.45) by kwepemm000007.china.huawei.com (7.193.23.189) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Tue, 13 Aug 2024 22:02:39 +0800 From: Jijie Shao To: , , , , , , CC: , , , , , , , , , , , , Subject: [RFC PATCH V2 net-next 07/11] net: hibmcge: Implement rx_poll function to receive packets Date: Tue, 13 Aug 2024 21:56:36 +0800 Message-ID: <20240813135640.1694993-8-shaojijie@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20240813135640.1694993-1-shaojijie@huawei.com> References: <20240813135640.1694993-1-shaojijie@huawei.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm000007.china.huawei.com (7.193.23.189) X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Implement rx_poll function to read the rx descriptor after receiving the rx interrupt. Adjust the skb based on the descriptor to complete the reception of the packet. Signed-off-by: Jijie Shao --- .../ethernet/hisilicon/hibmcge/hbg_common.h | 5 + .../net/ethernet/hisilicon/hibmcge/hbg_hw.c | 10 ++ .../net/ethernet/hisilicon/hibmcge/hbg_hw.h | 1 + .../net/ethernet/hisilicon/hibmcge/hbg_irq.c | 8 +- .../net/ethernet/hisilicon/hibmcge/hbg_main.c | 2 + .../net/ethernet/hisilicon/hibmcge/hbg_reg.h | 2 + .../hisilicon/hibmcge/hbg_reg_union.h | 65 ++++++++ .../net/ethernet/hisilicon/hibmcge/hbg_txrx.c | 156 +++++++++++++++++- 8 files changed, 247 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_common.h b/drivers/net/ethernet/hisilicon/hibmcge/hbg_common.h index f63a5be936ed..84d386e31749 100644 --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_common.h +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_common.h @@ -16,6 +16,10 @@ #define HBG_VECTOR_NUM 4 #define HBG_PCU_CACHE_LINE_SIZE 32 #define HBG_TX_TIMEOUT_BUF_LEN 1024 +#define HBG_RX_DESCR 0x01 + +#define HBG_PACKET_HEAD_SIZE ((HBG_RX_SKIP1 + HBG_RX_SKIP2 + HBG_RX_DESCR) * \ + HBG_PCU_CACHE_LINE_SIZE) enum hbg_tx_state { HBG_TX_STATE_COMPLETE = 0, /* clear state, must fix to 0 */ @@ -132,6 +136,7 @@ struct hbg_priv { struct hbg_mac mac; struct hbg_vector vectors; struct hbg_ring tx_ring; + struct hbg_ring rx_ring; }; #endif diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.c b/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.c index 9a8f18cece1a..d6e1600988e4 100644 --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.c +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.c @@ -67,6 +67,7 @@ int hbg_hw_dev_specs_init(struct hbg_priv *priv) return -EADDRNOTAVAIL; dev_specs->max_frame_len = HBG_PCU_CACHE_LINE_SIZE + dev_specs->max_mtu; + dev_specs->rx_buf_size = HBG_PACKET_HEAD_SIZE + dev_specs->max_frame_len; return 0; } @@ -116,6 +117,10 @@ u32 hbg_hw_get_fifo_used_num(struct hbg_priv *priv, enum hbg_dir dir) return hbg_reg_read_field(priv, HBG_REG_CF_CFF_DATA_NUM_ADDR, HBG_REG_CF_CFF_DATA_NUM_ADDR_TX_M); + if (hbg_dir_has_rx(dir)) + return hbg_reg_read_field(priv, HBG_REG_CF_CFF_DATA_NUM_ADDR, + HBG_REG_CF_CFF_DATA_NUM_ADDR_RX_M); + return 0; } @@ -127,6 +132,11 @@ void hbg_hw_set_tx_desc(struct hbg_priv *priv, struct hbg_tx_desc *tx_desc) hbg_reg_write(priv, HBG_REG_TX_CFF_ADDR_3_ADDR, tx_desc->clear_addr); } +void hbg_hw_fill_buffer(struct hbg_priv *priv, u32 buffer_dma_addr) +{ + hbg_reg_write(priv, HBG_REG_RX_CFF_ADDR_ADDR, buffer_dma_addr); +} + void hbg_hw_get_err_intr_status(struct hbg_priv *priv, struct hbg_intr_status *status) { status->bits = hbg_reg_read(priv, HBG_REG_CF_INTRPT_STAT_ADDR); diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.h b/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.h index 012845dd95bb..d056d31c58ae 100644 --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.h +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.h @@ -43,5 +43,6 @@ void hbg_hw_set_mtu(struct hbg_priv *priv, u16 mtu); int hbg_hw_init(struct hbg_priv *pri); u32 hbg_hw_get_fifo_used_num(struct hbg_priv *priv, enum hbg_dir dir); void hbg_hw_set_tx_desc(struct hbg_priv *priv, struct hbg_tx_desc *tx_desc); +void hbg_hw_fill_buffer(struct hbg_priv *priv, u32 buffer_dma_addr); #endif diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_irq.c b/drivers/net/ethernet/hisilicon/hibmcge/hbg_irq.c index 134c59a7986c..3e1c80315ea6 100644 --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_irq.c +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_irq.c @@ -19,9 +19,15 @@ static void hbg_irq_handle_tx(struct hbg_priv *priv, napi_schedule(&priv->tx_ring.napi); } +static void hbg_irq_handle_rx(struct hbg_priv *priv, + struct hbg_irq_info *irq_info) +{ + napi_schedule(&priv->rx_ring.napi); +} + static struct hbg_irq_info hbg_irqs[] = { { "TX", HBG_IRQ_TX, false, false, 0, hbg_irq_handle_tx }, - { "RX", HBG_IRQ_RX, false, false, 0, NULL }, + { "RX", HBG_IRQ_RX, false, false, 0, hbg_irq_handle_rx }, { "RX_BUF_AVL", HBG_IRQ_BUF_AVL, true, false, 0, hbg_irq_handle_err }, { "MAC_MII_FIFO_ERR", HBG_IRQ_MAC_MII_FIFO_ERR, true, true, 0, hbg_irq_handle_err }, diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c b/drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c index e08e3a477cea..0024af404762 100644 --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c @@ -36,6 +36,7 @@ static int hbg_net_open(struct net_device *dev) return 0; netif_carrier_off(dev); + napi_enable(&priv->rx_ring.napi); napi_enable(&priv->tx_ring.napi); hbg_all_irq_enable(priv, true); hbg_hw_mac_enable(priv, HBG_STATUS_ENABLE); @@ -59,6 +60,7 @@ static int hbg_net_stop(struct net_device *dev) hbg_hw_mac_enable(priv, HBG_STATUS_DISABLE); hbg_all_irq_enable(priv, false); napi_disable(&priv->tx_ring.napi); + napi_disable(&priv->rx_ring.napi); return 0; } diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_reg.h b/drivers/net/ethernet/hisilicon/hibmcge/hbg_reg.h index 0feb3cd24937..99432c9d052d 100644 --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_reg.h +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_reg.h @@ -54,10 +54,12 @@ #define HBG_REG_MAX_FRAME_LEN_M GENMASK(15, 0) #define HBG_REG_CF_CFF_DATA_NUM_ADDR (HBG_REG_SGMII_BASE + 0x045C) #define HBG_REG_CF_CFF_DATA_NUM_ADDR_TX_M GENMASK(8, 0) +#define HBG_REG_CF_CFF_DATA_NUM_ADDR_RX_M GENMASK(24, 16) #define HBG_REG_TX_CFF_ADDR_0_ADDR (HBG_REG_SGMII_BASE + 0x0488) #define HBG_REG_TX_CFF_ADDR_1_ADDR (HBG_REG_SGMII_BASE + 0x048C) #define HBG_REG_TX_CFF_ADDR_2_ADDR (HBG_REG_SGMII_BASE + 0x0490) #define HBG_REG_TX_CFF_ADDR_3_ADDR (HBG_REG_SGMII_BASE + 0x0494) +#define HBG_REG_RX_CFF_ADDR_ADDR (HBG_REG_SGMII_BASE + 0x04A0) #define HBG_REG_RX_BUF_SIZE_ADDR (HBG_REG_SGMII_BASE + 0x04E4) #define HBG_REG_RX_BUF_SIZE_M GENMASK(15, 0) #define HBG_REG_BUS_CTRL_ADDR (HBG_REG_SGMII_BASE + 0x04E8) diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_reg_union.h b/drivers/net/ethernet/hisilicon/hibmcge/hbg_reg_union.h index 6a2a585451d7..d6d511f836b4 100644 --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_reg_union.h +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_reg_union.h @@ -198,4 +198,69 @@ struct hbg_tx_desc { u32 clear_addr; /* word3 */ }; +struct hbg_rx_desc { + union { + struct { + u32 rsv : 3; + u32 tt : 2; + u32 group : 4; + u32 qos : 3; + u32 gen_id : 8; + u32 rsv1 : 12; + }; + u32 word0; + }; + u32 tag; /* word1 */ + union { + struct { + u32 all_skip_len : 9; + u32 rsv2 : 3; + u32 port_num : 4; + u32 len : 16; + }; + u32 word2; + }; + union { + struct { + u16 vlan; + u8 ip_offset; + u8 buf_num; + }; + u32 word3; + }; + union { + struct { + u32 rsv3 : 5; + u32 pm : 2; + u32 index_match : 1; + u32 l2_error : 1; + u32 l3_error_code : 4; + u32 drop : 1; + u32 vlan_flag : 1; + u32 icmp : 1; + u32 rarp : 1; + u32 arp : 1; + u32 mul_cst : 1; + u32 brd_cst : 1; + u32 ip_version_err : 1; + u32 opt : 1; + u32 frag : 1; + u32 l4_error_code : 4; + u32 rsv4 : 1; + u32 ip_version : 1; + u32 ipsec : 1; + u32 ip_tcp_udp : 2; + }; + u32 word4; + }; + union { + struct { + u16 size; + u8 rsv5; + u8 back; + }; + u32 word5; + }; +}; + #endif diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_txrx.c b/drivers/net/ethernet/hisilicon/hibmcge/hbg_txrx.c index bd16f5df3b5f..7c2aee4f95c9 100644 --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_txrx.c +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_txrx.c @@ -14,6 +14,9 @@ #define hbg_queue_is_full(head, tail, ring) ((head) == ((tail) + 1) % (ring)->len) #define hbg_queue_is_empty(head, tail) ((head) == (tail)) #define hbg_queue_next_prt(p, ring) (((p) + 1) % (ring)->len) +#define hbg_queue_move_next(p, ring) ({ \ + typeof(ring) _ring = (ring); \ + _ring->p = hbg_queue_next_prt(_ring->p, _ring); }) static int hbg_dma_map(struct hbg_buffer *buffer) { @@ -117,6 +120,20 @@ static void hbg_buffer_free_skb(struct hbg_buffer *buffer) buffer->skb = NULL; } +static int hbg_buffer_alloc_skb(struct hbg_buffer *buffer) +{ + u32 len = hbg_spec_max_frame_len(buffer->priv, buffer->dir); + struct hbg_priv *priv = buffer->priv; + + buffer->skb = netdev_alloc_skb(priv->netdev, len); + if (unlikely(!buffer->skb)) + return -ENOMEM; + + buffer->skb_len = len; + memset(buffer->skb->data, 0, HBG_PACKET_HEAD_SIZE); + return 0; +} + static void hbg_buffer_free(struct hbg_buffer *buffer) { hbg_dma_unmap(buffer); @@ -163,6 +180,107 @@ static int hbg_napi_tx_recycle(struct napi_struct *napi, int budget) return packet_done; } +static int hbg_rx_fill_one_buffer(struct hbg_priv *priv) +{ + struct hbg_ring *ring = &priv->rx_ring; + struct hbg_buffer *buffer; + int ret; + + buffer = &ring->queue[ring->ntu]; + ret = hbg_buffer_alloc_skb(buffer); + if (unlikely(ret)) + return ret; + + ret = hbg_dma_map(buffer); + if (unlikely(ret)) { + hbg_buffer_free_skb(buffer); + return ret; + } + + hbg_hw_fill_buffer(priv, buffer->skb_dma); + hbg_queue_move_next(ntu, ring); + return 0; +} + +static int hbg_rx_fill_buffers(struct hbg_priv *priv) +{ + struct hbg_ring *ring = &priv->rx_ring; + int ret; + + while (!(hbg_fifo_is_full(priv, ring->dir) || + hbg_queue_is_full(ring->ntc, ring->ntu, ring))) { + ret = hbg_rx_fill_one_buffer(priv); + if (ret) + return ret; + } + + return 0; +} + +static bool hbg_sync_data_from_hw(struct hbg_priv *priv, + struct hbg_buffer *buffer) +{ + struct hbg_rx_desc *rx_desc; + + /* make sure HW write desc complete */ + dma_rmb(); + + dma_sync_single_for_cpu(&priv->pdev->dev, buffer->skb_dma, + buffer->skb_len, DMA_FROM_DEVICE); + + rx_desc = (struct hbg_rx_desc *)buffer->skb->data; + return rx_desc->len != 0; +} + +static int hbg_napi_rx_poll(struct napi_struct *napi, int budget) +{ + struct hbg_ring *ring = container_of(napi, struct hbg_ring, napi); + struct hbg_priv *priv = ring->priv; + struct hbg_rx_desc *rx_desc; + struct hbg_buffer *buffer; + u32 packet_done = 0; + + if (unlikely(!hbg_nic_is_open(priv))) { + napi_complete(napi); + return 0; + } + + while (packet_done < budget) { + if (unlikely(hbg_queue_is_empty(ring->ntc, ring->ntu))) + break; + + buffer = &ring->queue[ring->ntc]; + if (unlikely(!buffer->skb)) + goto next_buffer; + + if (unlikely(!hbg_sync_data_from_hw(priv, buffer))) + break; + + hbg_dma_unmap(buffer); + + rx_desc = (struct hbg_rx_desc *)buffer->skb->data; + skb_reserve(buffer->skb, HBG_PACKET_HEAD_SIZE + NET_IP_ALIGN); + skb_put(buffer->skb, rx_desc->len); + buffer->skb->protocol = eth_type_trans(buffer->skb, priv->netdev); + + priv->netdev->stats.rx_bytes += rx_desc->len; + priv->netdev->stats.rx_packets++; + netif_receive_skb(buffer->skb); + buffer->skb = NULL; + hbg_rx_fill_one_buffer(priv); + +next_buffer: + hbg_queue_move_next(ntc, ring); + packet_done++; + } + + hbg_rx_fill_buffers(priv); + if (likely(napi_complete_done(napi, packet_done))) + hbg_irq_enable(priv, HBG_IRQ_RX, true); + + return packet_done; +} + static void hbg_ring_uninit(struct hbg_ring *ring) { struct hbg_buffer *buffer; @@ -240,15 +358,50 @@ static int hbg_tx_ring_init(struct hbg_priv *priv) return 0; } +static int hbg_rx_ring_init(struct hbg_priv *priv) +{ + struct hbg_ring *rx_ring = &priv->rx_ring; + int ret; + + ret = hbg_ring_init(priv, rx_ring, HBG_DIR_RX); + if (ret) + return ret; + + netif_napi_add(priv->netdev, &priv->rx_ring.napi, hbg_napi_rx_poll); + return 0; +} + int hbg_txrx_init(struct hbg_priv *priv) { int ret; ret = hbg_tx_ring_init(priv); - if (ret) + if (ret) { dev_err(&priv->pdev->dev, "failed to init tx ring, ret = %d\n", ret); + return ret; + } + + ret = hbg_rx_ring_init(priv); + if (ret) { + dev_err(&priv->pdev->dev, + "failed to init rx ring, ret = %d\n", ret); + goto err_uninit_tx; + } + + ret = hbg_rx_fill_buffers(priv); + if (ret) { + dev_err(&priv->pdev->dev, + "failed to fill rx buffers, ret = %d\n", ret); + goto err_uninit_rx; + } + return 0; + +err_uninit_rx: + hbg_ring_uninit(&priv->rx_ring); +err_uninit_tx: + hbg_ring_uninit(&priv->tx_ring); return ret; } @@ -257,4 +410,5 @@ void hbg_txrx_uninit(void *data) struct hbg_priv *priv = data; hbg_ring_uninit(&priv->tx_ring); + hbg_ring_uninit(&priv->rx_ring); } From patchwork Tue Aug 13 13:56:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jijie Shao X-Patchwork-Id: 13762090 X-Patchwork-Delegate: kuba@kernel.org Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F4F819D899; Tue, 13 Aug 2024 14:02:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723557766; cv=none; b=Ap2oUnNPWXKqj+Mkt+pZMQ9d2FKEx5aiFwDNEzBzteRESWreXOTWUQ8j81Y1oDUX4Xj1o/yYpKjPJcG4/ogcyB2CmCwwiYIVzSVjZQbZ4xVhfl5SEa4QFrHm+mlZZQkWPCpxDAH0Qz+qjGbbkRlgiWC/SfuQaTRXZ+WdMvHQcfo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723557766; c=relaxed/simple; bh=8AewkJjGbzywTCxdh/HtGILLsEMGnf1OPqxOOMILjNo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FJecQ8GB03lGUvNgl/VJzsiweHpqZY7QJsKU3rPWSOtkPE6s4inn1EzWMLtrDFyZURC9Qjx9NiiAI3629mcqmgFiJLu+LCvIXBbNDe3FMgxgT9fH4l9EiWn995za1cDgimc3vRVp186SNrYO2CjinltoTiilW18gvddr+wrDQYg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.48]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4WjtMJ0P1Nzfb7s; Tue, 13 Aug 2024 22:00:44 +0800 (CST) Received: from kwepemm000007.china.huawei.com (unknown [7.193.23.189]) by mail.maildlp.com (Postfix) with ESMTPS id CE9CC18006C; Tue, 13 Aug 2024 22:02:40 +0800 (CST) Received: from localhost.localdomain (10.90.30.45) by kwepemm000007.china.huawei.com (7.193.23.189) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Tue, 13 Aug 2024 22:02:40 +0800 From: Jijie Shao To: , , , , , , CC: , , , , , , , , , , , , Subject: [RFC PATCH V2 net-next 08/11] net: hibmcge: Implement some ethtool_ops functions Date: Tue, 13 Aug 2024 21:56:37 +0800 Message-ID: <20240813135640.1694993-9-shaojijie@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20240813135640.1694993-1-shaojijie@huawei.com> References: <20240813135640.1694993-1-shaojijie@huawei.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm000007.china.huawei.com (7.193.23.189) X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Implement the .get_drvinfo .get_link .get_link_ksettings to get the basic information and working status of the driver. Implement the .set_link_ksettings to modify the rate, duplex, and auto-negotiation status. Signed-off-by: Jijie Shao --- .../ethernet/hisilicon/hibmcge/hbg_ethtool.c | 17 +++++++++++++++++ .../ethernet/hisilicon/hibmcge/hbg_ethtool.h | 11 +++++++++++ .../net/ethernet/hisilicon/hibmcge/hbg_main.c | 2 ++ 3 files changed, 30 insertions(+) create mode 100644 drivers/net/ethernet/hisilicon/hibmcge/hbg_ethtool.c create mode 100644 drivers/net/ethernet/hisilicon/hibmcge/hbg_ethtool.h diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_ethtool.c b/drivers/net/ethernet/hisilicon/hibmcge/hbg_ethtool.c new file mode 100644 index 000000000000..c3370114aef3 --- /dev/null +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_ethtool.c @@ -0,0 +1,17 @@ +// SPDX-License-Identifier: GPL-2.0+ +// Copyright (c) 2024 Hisilicon Limited. + +#include +#include +#include "hbg_ethtool.h" + +static const struct ethtool_ops hbg_ethtool_ops = { + .get_link = ethtool_op_get_link, + .get_link_ksettings = phy_ethtool_get_link_ksettings, + .set_link_ksettings = phy_ethtool_set_link_ksettings, +}; + +void hbg_ethtool_set_ops(struct net_device *netdev) +{ + netdev->ethtool_ops = &hbg_ethtool_ops; +} diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_ethtool.h b/drivers/net/ethernet/hisilicon/hibmcge/hbg_ethtool.h new file mode 100644 index 000000000000..628707ec2686 --- /dev/null +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_ethtool.h @@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* Copyright (c) 2024 Hisilicon Limited. */ + +#ifndef __HBG_ETHTOOL_H +#define __HBG_ETHTOOL_H + +#include + +void hbg_ethtool_set_ops(struct net_device *netdev); + +#endif diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c b/drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c index 0024af404762..ccbced1a7a1c 100644 --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c @@ -6,6 +6,7 @@ #include #include #include "hbg_common.h" +#include "hbg_ethtool.h" #include "hbg_hw.h" #include "hbg_irq.h" #include "hbg_mdio.h" @@ -220,6 +221,7 @@ static int hbg_probe(struct pci_dev *pdev, const struct pci_device_id *ent) if (ret) return dev_err_probe(dev, ret, "failed to register netdev\n"); + hbg_ethtool_set_ops(netdev); set_bit(HBG_NIC_STATE_INITED, &priv->state); return 0; } From patchwork Tue Aug 13 13:56:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jijie Shao X-Patchwork-Id: 13762095 X-Patchwork-Delegate: kuba@kernel.org Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CCA0719DF5B; Tue, 13 Aug 2024 14:02:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.191 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723557768; cv=none; b=OKdH4Ac0DfhQz+oHEaKyBDxulDHmyNtl3pTQg08tjs8hqkCwZvlCDccJ6ZWsG5bJIebfG4gwvMPE/JedNZlo8B7GZyyspkTMLBcogDbkLWxhCb0qQgmtyyOhwlmwDt9A0uoNSx6hqIA/iu9Wi9inRY35yicLb9OsurvugizPRok= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723557768; c=relaxed/simple; bh=WlL/XgDj2EhnTAXypujoE45aLexwaaITsEqB8lV6M/Y=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KIWUxbyxPWbSLX3y5EgoK9s1uSS1Jyh9P0BsE6TxMYkCj/M4fd3GA8P4gEdZDaqMjiOlPEq5BKjn+D66gFWJgo+zlBsW3EjV5SPAFiqdcnwuiCL3PQ6WD0RA6sgC1KAEdaWMjTBmdfPgQeyQ/+zpPa4C7NKwp0t/CO+QJjd8XBE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.191 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.44]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4WjtHy5P4Yz1j6SH; Tue, 13 Aug 2024 21:57:50 +0800 (CST) Received: from kwepemm000007.china.huawei.com (unknown [7.193.23.189]) by mail.maildlp.com (Postfix) with ESMTPS id 72595140361; Tue, 13 Aug 2024 22:02:41 +0800 (CST) Received: from localhost.localdomain (10.90.30.45) by kwepemm000007.china.huawei.com (7.193.23.189) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Tue, 13 Aug 2024 22:02:40 +0800 From: Jijie Shao To: , , , , , , CC: , , , , , , , , , , , , Subject: [RFC PATCH V2 net-next 09/11] net: hibmcge: Add a Makefile and update Kconfig for hibmcge Date: Tue, 13 Aug 2024 21:56:38 +0800 Message-ID: <20240813135640.1694993-10-shaojijie@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20240813135640.1694993-1-shaojijie@huawei.com> References: <20240813135640.1694993-1-shaojijie@huawei.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm000007.china.huawei.com (7.193.23.189) X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Add a Makefile and update Kconfig to build hibmcge driver. Signed-off-by: Jijie Shao --- drivers/net/ethernet/hisilicon/Kconfig | 16 +++++++++++++++- drivers/net/ethernet/hisilicon/Makefile | 1 + drivers/net/ethernet/hisilicon/hibmcge/Makefile | 10 ++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/hisilicon/hibmcge/Makefile diff --git a/drivers/net/ethernet/hisilicon/Kconfig b/drivers/net/ethernet/hisilicon/Kconfig index 3312e1d93c3b..0ed9b22b65df 100644 --- a/drivers/net/ethernet/hisilicon/Kconfig +++ b/drivers/net/ethernet/hisilicon/Kconfig @@ -7,7 +7,6 @@ config NET_VENDOR_HISILICON bool "Hisilicon devices" default y depends on OF || ACPI - depends on ARM || ARM64 || COMPILE_TEST help If you have a network (Ethernet) card belonging to this class, say Y. @@ -18,6 +17,8 @@ config NET_VENDOR_HISILICON if NET_VENDOR_HISILICON +if ARM || ARM64 || COMPILE_TEST + config HIX5HD2_GMAC tristate "Hisilicon HIX5HD2 Family Network Device Support" select PHYLIB @@ -141,4 +142,17 @@ config HNS3_ENET endif #HNS3 +endif # ARM || ARM64 || COMPILE_TEST + +config HIBMCGE + tristate "Hisilicon BMC Gigabit Ethernet Device Support" + default m + depends on PCI && PCI_MSI + help + If you wish to compile a kernel for a BMC with HIBMC-xx_gmac + then you should answer Y to this. This makes this driver suitable for use + on certain boards such as the HIBMC-210. + + If you are unsure, say N. + endif # NET_VENDOR_HISILICON diff --git a/drivers/net/ethernet/hisilicon/Makefile b/drivers/net/ethernet/hisilicon/Makefile index 7f76d412047a..0e2cadfea8ff 100644 --- a/drivers/net/ethernet/hisilicon/Makefile +++ b/drivers/net/ethernet/hisilicon/Makefile @@ -9,3 +9,4 @@ obj-$(CONFIG_HNS_MDIO) += hns_mdio.o obj-$(CONFIG_HNS) += hns/ obj-$(CONFIG_HNS3) += hns3/ obj-$(CONFIG_HISI_FEMAC) += hisi_femac.o +obj-$(CONFIG_HIBMCGE) += hibmcge/ diff --git a/drivers/net/ethernet/hisilicon/hibmcge/Makefile b/drivers/net/ethernet/hisilicon/hibmcge/Makefile new file mode 100644 index 000000000000..ea223b7207af --- /dev/null +++ b/drivers/net/ethernet/hisilicon/hibmcge/Makefile @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# Makefile for the HISILICON BMC GE network device drivers. +# + +ccflags-y += -I$(src) + +obj-$(CONFIG_HIBMCGE) += hibmcge.o + +hibmcge-objs = hbg_main.o hbg_hw.o hbg_mdio.o hbg_irq.o hbg_txrx.o hbg_ethtool.o From patchwork Tue Aug 13 13:56:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jijie Shao X-Patchwork-Id: 13762094 X-Patchwork-Delegate: kuba@kernel.org Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8C3A019DF87; Tue, 13 Aug 2024 14:02:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723557768; cv=none; b=W3pz6w/JPi8MMlLQ3Nkbv+4rhzw0pA9wh62tY8CJWp90y6S8OWIT9vtcruSvs5MjoIfS2BvweY0sXvbCheluT5ft0Ys3FFSfnI1td0pzyCnnM9dDwfNuHCxlRq5T2QnqNUUS9WVEY9h3O8n9YHmVaNPZNiXcN3sypZEimL1kYpc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723557768; c=relaxed/simple; bh=FUNzXNrbapU3n6e0WZbt99HmwGqTa790/oN7vqUdLBk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rA5CGP062A6tugpayqXPl1oFA4qBIyCwUkzYJvC2bZ7H+AHwBft32Vm2ceLs3ckK/9XAb427Jp6Etmc+6RcIZnRpZS1vk7Cep47HW4WIHUAX/bm3IgFSTh3Sb+z0cE6RaC2g2GUjKprvXPdMkr2NDtqyVWIbNibHBalv8fETHqc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.194]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4WjtP11RxYzyPpf; Tue, 13 Aug 2024 22:02:13 +0800 (CST) Received: from kwepemm000007.china.huawei.com (unknown [7.193.23.189]) by mail.maildlp.com (Postfix) with ESMTPS id 16DE01400FD; Tue, 13 Aug 2024 22:02:42 +0800 (CST) Received: from localhost.localdomain (10.90.30.45) by kwepemm000007.china.huawei.com (7.193.23.189) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Tue, 13 Aug 2024 22:02:41 +0800 From: Jijie Shao To: , , , , , , CC: , , , , , , , , , , , , Subject: [RFC PATCH V2 net-next 10/11] net: hibmcge: Add maintainer for hibmcge Date: Tue, 13 Aug 2024 21:56:39 +0800 Message-ID: <20240813135640.1694993-11-shaojijie@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20240813135640.1694993-1-shaojijie@huawei.com> References: <20240813135640.1694993-1-shaojijie@huawei.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm000007.china.huawei.com (7.193.23.189) X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Add myself as the maintainer for the hibmcge ethernet driver. Signed-off-by: Jijie Shao --- MAINTAINERS | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 7b291c3a9aa4..d53608f348e7 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -10123,6 +10123,13 @@ S: Maintained W: http://www.hisilicon.com F: drivers/net/ethernet/hisilicon/hns3/ +HISILICON NETWORK HIBMCGE DRIVER +M: Jijie Shao +L: netdev@vger.kernel.org +S: Maintained +W: http://www.hisilicon.com +F: drivers/net/ethernet/hisilicon/hibmcge/ + HISILICON NETWORK SUBSYSTEM DRIVER M: Yisen Zhuang M: Salil Mehta From patchwork Tue Aug 13 13:56:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jijie Shao X-Patchwork-Id: 13762092 X-Patchwork-Delegate: kuba@kernel.org Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 32D0719DF76; Tue, 13 Aug 2024 14:02:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.191 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723557767; cv=none; b=l8D3bs/hu6X+oiRlHf2DOg/aOANT3BjQmRE9YFno++VrM+rHX19e/djXQ6Z9xmo7JsFcj8osuVYUDEmHpNdFvQSAeVSet5HOxmDxdU4giKNHlpxsXrWOkmg9J7PGJ0aqwsdjEUm50aZYo/2s+vuhtm9VxgPxx9wM6Lz2jn6Ao/A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723557767; c=relaxed/simple; bh=BVoF6xKSHJyIe3qsWJNAKz/mPt6vgQCUQQFOTncLDlQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lpqSFjy5lm4W/g7AFElPEewlfYp2c/OQ8clwGkA3Jm5HCUtrPBAbHUCbIvogIiUflNvloMc/SFhtMuaAHMqOFADl9PPBn7R0H/QbyWSQwQFe+ELQc8eK+u/Qodgzzfhc4ExW+AjUHHpoKapN9eDWftj47sLXoK/TC/c/QszNcn8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.191 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.17]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4WjtJ00Jgxz1j6SL; Tue, 13 Aug 2024 21:57:52 +0800 (CST) Received: from kwepemm000007.china.huawei.com (unknown [7.193.23.189]) by mail.maildlp.com (Postfix) with ESMTPS id B81C31A0188; Tue, 13 Aug 2024 22:02:42 +0800 (CST) Received: from localhost.localdomain (10.90.30.45) by kwepemm000007.china.huawei.com (7.193.23.189) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Tue, 13 Aug 2024 22:02:41 +0800 From: Jijie Shao To: , , , , , , CC: , , , , , , , , , , , , Subject: [RFC PATCH V2 net-next 11/11] net: add is_valid_ether_addr check in dev_set_mac_address Date: Tue, 13 Aug 2024 21:56:40 +0800 Message-ID: <20240813135640.1694993-12-shaojijie@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20240813135640.1694993-1-shaojijie@huawei.com> References: <20240813135640.1694993-1-shaojijie@huawei.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm000007.china.huawei.com (7.193.23.189) X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC core need test the mac_addr not every driver need to do. Signed-off-by: Jijie Shao --- net/core/dev.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/core/dev.c b/net/core/dev.c index 751d9b70e6ad..ad86b8c939c1 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -9087,6 +9087,8 @@ int dev_set_mac_address(struct net_device *dev, struct sockaddr *sa, return -EOPNOTSUPP; if (sa->sa_family != dev->type) return -EINVAL; + if (!is_valid_ether_addr(sa->sa_data)) + return -EADDRNOTAVAIL; if (!netif_device_present(dev)) return -ENODEV; err = dev_pre_changeaddr_notify(dev, sa->sa_data, extack);