From: Jijie Shao <shaojijie@huawei.com>
To: <davem@davemloft.net>, <edumazet@google.com>, <kuba@kernel.org>,
<pabeni@redhat.com>
Cc: <shenjian15@huawei.com>, <wangpeiyang1@huawei.com>,
<liuyonglong@huawei.com>, <chenhao418@huawei.com>,
<sudongming1@huawei.com>, <xujunsheng@huawei.com>,
<shiyongbang@huawei.com>, <libaihan@huawei.com>, <andrew@lunn.ch>,
<jdamato@fastly.com>, <horms@kernel.org>,
<kalesh-anakkur.purayil@broadcom.com>,
<christophe.jaillet@wanadoo.fr>, <jonathan.cameron@huawei.com>,
<shameerali.kolothum.thodi@huawei.com>, <salil.mehta@huawei.com>,
<netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<shaojijie@huawei.com>
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 [thread overview]
Message-ID: <20241008022358.863393-2-shaojijie@huawei.com> (raw)
In-Reply-To: <20241008022358.863393-1-shaojijie@huawei.com>
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 <shaojijie@huawei.com>
---
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@huawei.com/
v7 -> v8:
- Set netdev->pcpu_stat_type to NETDEV_PCPU_STAT_TSTATS, suggested by Jakub
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@huawei.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 <linux/netdevice.h>
+#include <linux/pci.h>
+
+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..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 <linux/etherdevice.h>
+#include <linux/netdevice.h>
+#include <linux/pci.h>
+#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(dev, sizeof(struct hbg_priv));
+ 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;
+
+ netdev->pcpu_stat_type = NETDEV_PCPU_STAT_TSTATS;
+
+ ret = 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[] = {
+ {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");
--
2.33.0
next prev parent reply other threads:[~2024-10-08 2:30 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-08 2:23 [PATCH V11 net-next 00/10] Add support of HIBMCGE Ethernet Driver Jijie Shao
2024-10-08 2:23 ` Jijie Shao [this message]
2024-10-08 2:23 ` [PATCH V11 net-next 02/10] net: hibmcge: Add read/write registers supported through the bar space Jijie Shao
2024-10-08 2:23 ` [PATCH V11 net-next 03/10] net: hibmcge: Add mdio and hardware configuration supported in this module Jijie Shao
2024-10-08 2:23 ` [PATCH V11 net-next 04/10] net: hibmcge: Add interrupt " Jijie Shao
2024-10-10 10:22 ` Simon Horman
2024-10-10 14:24 ` Jijie Shao
2024-10-08 2:23 ` [PATCH V11 net-next 05/10] net: hibmcge: Implement some .ndo functions Jijie Shao
2024-10-08 2:23 ` [PATCH V11 net-next 06/10] net: hibmcge: Implement .ndo_start_xmit function Jijie Shao
2024-10-08 2:23 ` [PATCH V11 net-next 07/10] net: hibmcge: Implement rx_poll function to receive packets Jijie Shao
2024-10-09 21:35 ` Joe Damato
2024-10-09 21:42 ` Joe Damato
2024-10-10 1:04 ` Jijie Shao
2024-10-08 2:23 ` [PATCH V11 net-next 08/10] net: hibmcge: Implement some ethtool_ops functions Jijie Shao
2024-10-08 2:23 ` [PATCH V11 net-next 09/10] net: hibmcge: Add a Makefile and update Kconfig for hibmcge Jijie Shao
2024-10-08 2:23 ` [PATCH V11 net-next 10/10] net: hibmcge: Add maintainer " Jijie Shao
2024-10-10 2:37 ` Jakub Kicinski
2024-10-10 14:26 ` Jijie Shao
2024-10-10 2:36 ` [PATCH V11 net-next 00/10] Add support of HIBMCGE Ethernet Driver Jakub Kicinski
2024-10-10 14:25 ` Jijie Shao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241008022358.863393-2-shaojijie@huawei.com \
--to=shaojijie@huawei.com \
--cc=andrew@lunn.ch \
--cc=chenhao418@huawei.com \
--cc=christophe.jaillet@wanadoo.fr \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=jdamato@fastly.com \
--cc=jonathan.cameron@huawei.com \
--cc=kalesh-anakkur.purayil@broadcom.com \
--cc=kuba@kernel.org \
--cc=libaihan@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=liuyonglong@huawei.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=salil.mehta@huawei.com \
--cc=shameerali.kolothum.thodi@huawei.com \
--cc=shenjian15@huawei.com \
--cc=shiyongbang@huawei.com \
--cc=sudongming1@huawei.com \
--cc=wangpeiyang1@huawei.com \
--cc=xujunsheng@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).