From nobody Wed Nov 27 23:49:20 2024 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 41C481EA73; Tue, 8 Oct 2024 02:30:28 +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=1728354630; cv=none; b=DlaYsvULoz1yr2p+ZZQY5IcsTlh21zVhgH71ik17KKsiEGtZ3fkwWjb+LjAdHIkuD2LKwsNVP1I72hWioARqYDPqTcIwShsQCFR0/bjJvX4tbmXSDl4+OvLTi+fHzfQfjFaK6utwfvI6d88iCl7Mitft1TyDwhzvZpctCrnNn3k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728354630; c=relaxed/simple; bh=6bzmQWZ50Z4Ptqwi0MxNuTn8rxQ1BZUD81funVcZdgc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Lqdc/dWKF3ca/RwBc7xE+UTSvQNtkunF2ntcXOvqIq3rrPEZd7rzYpI+ED7X4WrhDFNjy+2FkSVPpTu9Kgz7rhTb5CGS7WwVukr/KnKzHhRX+OOk+MU4qAeXDQVNqWHSZzxEEYVD/CDPzrIK5Vvz7YYVRRgRBxCdmKqSqisLDXU= 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 4XN0Mk0tq9z2DdH0; Tue, 8 Oct 2024 10:29:22 +0800 (CST) Received: from kwepemm000007.china.huawei.com (unknown [7.193.23.189]) by mail.maildlp.com (Postfix) with ESMTPS id A1E711401F4; Tue, 8 Oct 2024 10:30:25 +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, 8 Oct 2024 10:30:24 +0800 From: Jijie Shao To: , , , CC: , , , , , , , , , , , , , , , , , , Subject: [PATCH V11 net-next 01/10] net: hibmcge: Add pci table supported in this module Date: Tue, 8 Oct 2024 10:23:49 +0800 Message-ID: <20241008022358.863393-2-shaojijie@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20241008022358.863393-1-shaojijie@huawei.com> References: <20241008022358.863393-1-shaojijie@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemm000007.china.huawei.com (7.193.23.189) 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. =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=90 =E2=94=82 HOST CPU network device =E2=94=82 =E2=94=82 =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=90 =E2=94=82 =E2=94=82 =E2=94=82hibmcge driver=E2=94=82 =E2=94=82 =E2=94=82 =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =AC=E2=94=80=E2=94=AC=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=98 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82HOST =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=B4=E2=94=80=E2= =94=B4=E2=94=80=E2=94=80=E2=94=80=E2=94=90 =E2=94=82 =E2=94=82 =E2=94=82 PCIE RC =E2=94=82 =E2=94=82 =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=B4= =E2=94=80=E2=94=80=E2=94=80=E2=94=AC=E2=94=80=E2=94=AC=E2=94=80=E2=94=80=E2= =94=80=E2=94=B4=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=98 =E2=94=82 =E2=94=82 PCIE =E2=94=82 =E2=94=82 =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=AC= =E2=94=80=E2=94=80=E2=94=80=E2=94=B4=E2=94=80=E2=94=B4=E2=94=80=E2=94=80=E2= =94=80=E2=94=AC=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=90 =E2=94=82 =E2=94=82 PCIE EP =E2=94=82 =E2=94=82 =E2=94=82BMC =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=AC=E2=94=80=E2= =94=AC=E2=94=80=E2=94=80=E2=94=80=E2=94=98 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=B4=E2=94=80=E2=94=B4=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=90 =E2= =94=82 =E2=94=82 =E2=94=82 GE =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=90 =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=90 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 MAC =E2=94=82 =E2=94=82 MAC =E2=94=82 = =E2=94=82 =E2=94=82 =E2=94=94=E2=94=80=E2=94=B4=E2=94=80=E2=94=BC=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=BC=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=BC=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=BC=E2=94=80=E2=94=80=E2=94= =B4=E2=94=80=E2=94=98 =E2=94=82 PHY =E2=94=82 =E2=94=82 PHY =E2=94=82 =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=98 = =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=98 Signed-off-by: Jijie Shao --- ChangeLog: v10 -> v11: - Delete devm_netdev_alloc_pcpu_stats to prevent memory leak, suggested by Jakub. v10: https://lore.kernel.org/all/20240912025127.3912972-1-shaojijie@huawe= i.com/ v7 -> v8: - Set netdev->pcpu_stat_type to NETDEV_PCPU_STAT_TSTATS, suggested by Jak= ub v7: https://lore.kernel.org/all/20240905143120.1583460-1-shaojijie@huawei= .com/ v6 -> v7: - Add devm_netdev_alloc_pcpu_stats() to init netdev->tstats, suggested by Paolo. v6: https://lore.kernel.org/all/20240830121604.2250904-2-shaojijie@huawei= .com/ RFC v1 -> RFC v2: - Add the null pointer check on the return value of pcim_iomap_table(), suggested by Jonathan. RFC v1: https://lore.kernel.org/all/20240731094245.1967834-1-shaojijie@hu= awei.com/ --- .../ethernet/hisilicon/hibmcge/hbg_common.h | 16 ++++ .../net/ethernet/hisilicon/hibmcge/hbg_main.c | 84 +++++++++++++++++++ 2 files changed, 100 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/ne= t/ethernet/hisilicon/hibmcge/hbg_main.c new file mode 100644 index 000000000000..86027434d5e0 --- /dev/null +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c @@ -0,0 +1,84 @@ +// 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 =3D pci_get_drvdata(pdev); + struct hbg_priv *priv =3D netdev_priv(netdev); + struct device *dev =3D &pdev->dev; + int ret; + + ret =3D pcim_enable_device(pdev); + if (ret) + return dev_err_probe(dev, ret, "failed to enable PCI device\n"); + + ret =3D 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 =3D 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 =3D 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 =3D &pdev->dev; + struct net_device *netdev; + struct hbg_priv *priv; + int ret; + + netdev =3D devm_alloc_etherdev(dev, sizeof(struct hbg_priv)); + if (!netdev) + return -ENOMEM; + + pci_set_drvdata(pdev, netdev); + SET_NETDEV_DEV(netdev, dev); + + priv =3D netdev_priv(netdev); + priv->netdev =3D netdev; + priv->pdev =3D pdev; + + ret =3D hbg_pci_init(pdev); + if (ret) + return ret; + + netdev->pcpu_stat_type =3D NETDEV_PCPU_STAT_TSTATS; + + ret =3D devm_register_netdev(dev, netdev); + if (ret) + return dev_err_probe(dev, ret, "failed to register netdev\n"); + + netif_carrier_off(netdev); + return 0; +} + +static const struct pci_device_id hbg_pci_tbl[] =3D { + {PCI_VDEVICE(HUAWEI, 0x3730), 0}, + { } +}; +MODULE_DEVICE_TABLE(pci, hbg_pci_tbl); + +static struct pci_driver hbg_driver =3D { + .name =3D "hibmcge", + .id_table =3D hbg_pci_tbl, + .probe =3D hbg_probe, +}; +module_pci_driver(hbg_driver); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Huawei Tech. Co., Ltd."); +MODULE_DESCRIPTION("hibmcge driver"); +MODULE_VERSION("1.0"); --=20 2.33.0