diff mbox series

[08/16] net-next/yunsilicon: Add ethernet interface

Message ID 20241209071101.3392590-9-tianx@yunsilicon.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series [01/16] net-next/yunsilicon: Add yunsilicon xsc driver basic framework | expand

Checks

Context Check Description
netdev/series_format fail Series does not have a cover letter; Series longer than 15 patches (and no cover letter)
netdev/tree_selection success Guessed tree name to be net-next, async
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 5 maintainers not CCed: andrew+netdev@lunn.ch kuba@kernel.org pabeni@redhat.com edumazet@google.com jacky@yunsilicon.com
netdev/build_clang fail Errors and warnings before: 6 this patch: 12
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn fail Errors and warnings before: 498 this patch: 558
netdev/checkpatch warning WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? WARNING: line length of 100 exceeds 80 columns WARNING: line length of 88 exceeds 80 columns
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

tianx Dec. 9, 2024, 7:10 a.m. UTC
From: Xin Tian <tianx@yunsilicon.com>

Build a basic netdevice driver

Signed-off-by: Xin Tian <tianx@yunsilicon.com>
Signed-off-by: Honggang Wei <weihg@yunsilicon.com>
Signed-off-by: Lei Yan <jacky@yunsilicon.com>
---
 drivers/net/ethernet/yunsilicon/Makefile      |   2 +-
 .../ethernet/yunsilicon/xsc/common/xsc_core.h |   1 +
 .../net/ethernet/yunsilicon/xsc/net/main.c    | 135 ++++++++++++++++++
 .../net/ethernet/yunsilicon/xsc/net/xsc_eth.h |  16 +++
 .../yunsilicon/xsc/net/xsc_eth_common.h       |  15 ++
 5 files changed, 168 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/ethernet/yunsilicon/xsc/net/main.c
 create mode 100644 drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth.h
 create mode 100644 drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth_common.h

Comments

Andrew Lunn Dec. 9, 2024, 1:40 p.m. UTC | #1
On Mon, Dec 09, 2024 at 03:10:53PM +0800, Tian Xin wrote:
> From: Xin Tian <tianx@yunsilicon.com>
> 
> Build a basic netdevice driver
> 
> Signed-off-by: Xin Tian <tianx@yunsilicon.com>
> Signed-off-by: Honggang Wei <weihg@yunsilicon.com>
> Signed-off-by: Lei Yan <jacky@yunsilicon.com>
> ---
>  drivers/net/ethernet/yunsilicon/Makefile      |   2 +-
>  .../ethernet/yunsilicon/xsc/common/xsc_core.h |   1 +
>  .../net/ethernet/yunsilicon/xsc/net/main.c    | 135 ++++++++++++++++++
>  .../net/ethernet/yunsilicon/xsc/net/xsc_eth.h |  16 +++
>  .../yunsilicon/xsc/net/xsc_eth_common.h       |  15 ++
>  5 files changed, 168 insertions(+), 1 deletion(-)
>  create mode 100644 drivers/net/ethernet/yunsilicon/xsc/net/main.c
>  create mode 100644 drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth.h
>  create mode 100644 drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth_common.h
> 
> diff --git a/drivers/net/ethernet/yunsilicon/Makefile b/drivers/net/ethernet/yunsilicon/Makefile
> index 950fd2663..c1d3e3398 100644
> --- a/drivers/net/ethernet/yunsilicon/Makefile
> +++ b/drivers/net/ethernet/yunsilicon/Makefile
> @@ -4,5 +4,5 @@
>  # Makefile for the Yunsilicon device drivers.
>  #
>  
> -# obj-$(CONFIG_YUNSILICON_XSC_ETH) += xsc/net/
> +obj-$(CONFIG_YUNSILICON_XSC_ETH) += xsc/net/
>  obj-$(CONFIG_YUNSILICON_XSC_PCI) += xsc/pci/
> \ No newline at end of file
> diff --git a/drivers/net/ethernet/yunsilicon/xsc/common/xsc_core.h b/drivers/net/ethernet/yunsilicon/xsc/common/xsc_core.h
> index 88d4c5654..5d2b28e2e 100644
> --- a/drivers/net/ethernet/yunsilicon/xsc/common/xsc_core.h
> +++ b/drivers/net/ethernet/yunsilicon/xsc/common/xsc_core.h
> @@ -498,6 +498,7 @@ struct xsc_core_device {
>  	struct pci_dev		*pdev;
>  	struct device		*device;
>  	struct xsc_priv		priv;
> +	void			*netdev;
>  	void			*eth_priv;
>  	struct xsc_dev_resource	*dev_res;
>  
> diff --git a/drivers/net/ethernet/yunsilicon/xsc/net/main.c b/drivers/net/ethernet/yunsilicon/xsc/net/main.c
> new file mode 100644
> index 000000000..243ec7ced
> --- /dev/null
> +++ b/drivers/net/ethernet/yunsilicon/xsc/net/main.c
> @@ -0,0 +1,135 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/* Copyright (C) 2021 - 2023, Shanghai Yunsilicon Technology Co., Ltd.
> + * All rights reserved.
> + */
> +
> +#include <linux/reboot.h>

reboot.h in an ethernet driver? 

> +static int xsc_net_reboot_event_handler(struct notifier_block *nb, unsigned long action, void *data)
> +{
> +	pr_info("xsc net driver recv %lu event\n", action);
> +	xsc_remove_eth_driver();
> +
> +	return NOTIFY_OK;
> +}
> +
> +struct notifier_block xsc_net_nb = {
> +	.notifier_call = xsc_net_reboot_event_handler,
> +	.next = NULL,
> +	.priority = 1,
> +};

This needs a comment explanation why this driver needs something
special during reboot.

    Andrew

---
pw-bot: cr
Andrew Lunn Dec. 9, 2024, 1:41 p.m. UTC | #2
> +static void xsc_remove_eth_driver(void)
> +{
> +	pr_info("remove ethernet driver\n");
> +	xsc_unregister_interface(&xsc_interface);
> +}
> +
> +static int xsc_net_reboot_event_handler(struct notifier_block *nb, unsigned long action, void *data)
> +{
> +	pr_info("xsc net driver recv %lu event\n", action);
> +	xsc_remove_eth_driver();
> +
> +	return NOTIFY_OK;
> +}
> +
> +struct notifier_block xsc_net_nb = {
> +	.notifier_call = xsc_net_reboot_event_handler,
> +	.next = NULL,
> +	.priority = 1,
> +};
> +
> +static __init int xsc_net_driver_init(void)
> +{
> +	int ret;
> +
> +	pr_info("add ethernet driver\n");

Please don't spam the kernel log with all the pr_info() calls.

	Andrew
tianx Dec. 18, 2024, 11:21 a.m. UTC | #3
OK, the unecessary log have been removed in v1 patch.

On 2024/12/9 21:41, Andrew Lunn wrote:
>> +static void xsc_remove_eth_driver(void)
>> +{
>> +	pr_info("remove ethernet driver\n");
>> +	xsc_unregister_interface(&xsc_interface);
>> +}
>> +
>> +static int xsc_net_reboot_event_handler(struct notifier_block *nb, unsigned long action, void *data)
>> +{
>> +	pr_info("xsc net driver recv %lu event\n", action);
>> +	xsc_remove_eth_driver();
>> +
>> +	return NOTIFY_OK;
>> +}
>> +
>> +struct notifier_block xsc_net_nb = {
>> +	.notifier_call = xsc_net_reboot_event_handler,
>> +	.next = NULL,
>> +	.priority = 1,
>> +};
>> +
>> +static __init int xsc_net_driver_init(void)
>> +{
>> +	int ret;
>> +
>> +	pr_info("add ethernet driver\n");
> Please don't spam the kernel log with all the pr_info() calls.
>
> 	Andrew
tianx Dec. 18, 2024, 3:35 p.m. UTC | #4
We need to do some cleanup work when the machine shutdown. But it's not 
necessary in current series, so the reboot callback have been removed in 
v1 code

On 2024/12/9 21:40, Andrew Lunn wrote:
> On Mon, Dec 09, 2024 at 03:10:53PM +0800, Tian Xin wrote:
>> From: Xin Tian <tianx@yunsilicon.com>
>>
>> Build a basic netdevice driver
>>
>> Signed-off-by: Xin Tian <tianx@yunsilicon.com>
>> Signed-off-by: Honggang Wei <weihg@yunsilicon.com>
>> Signed-off-by: Lei Yan <jacky@yunsilicon.com>
>> ---
>>   drivers/net/ethernet/yunsilicon/Makefile      |   2 +-
>>   .../ethernet/yunsilicon/xsc/common/xsc_core.h |   1 +
>>   .../net/ethernet/yunsilicon/xsc/net/main.c    | 135 ++++++++++++++++++
>>   .../net/ethernet/yunsilicon/xsc/net/xsc_eth.h |  16 +++
>>   .../yunsilicon/xsc/net/xsc_eth_common.h       |  15 ++
>>   5 files changed, 168 insertions(+), 1 deletion(-)
>>   create mode 100644 drivers/net/ethernet/yunsilicon/xsc/net/main.c
>>   create mode 100644 drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth.h
>>   create mode 100644 drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth_common.h
>>
>> diff --git a/drivers/net/ethernet/yunsilicon/Makefile b/drivers/net/ethernet/yunsilicon/Makefile
>> index 950fd2663..c1d3e3398 100644
>> --- a/drivers/net/ethernet/yunsilicon/Makefile
>> +++ b/drivers/net/ethernet/yunsilicon/Makefile
>> @@ -4,5 +4,5 @@
>>   # Makefile for the Yunsilicon device drivers.
>>   #
>>   
>> -# obj-$(CONFIG_YUNSILICON_XSC_ETH) += xsc/net/
>> +obj-$(CONFIG_YUNSILICON_XSC_ETH) += xsc/net/
>>   obj-$(CONFIG_YUNSILICON_XSC_PCI) += xsc/pci/
>> \ No newline at end of file
>> diff --git a/drivers/net/ethernet/yunsilicon/xsc/common/xsc_core.h b/drivers/net/ethernet/yunsilicon/xsc/common/xsc_core.h
>> index 88d4c5654..5d2b28e2e 100644
>> --- a/drivers/net/ethernet/yunsilicon/xsc/common/xsc_core.h
>> +++ b/drivers/net/ethernet/yunsilicon/xsc/common/xsc_core.h
>> @@ -498,6 +498,7 @@ struct xsc_core_device {
>>   	struct pci_dev		*pdev;
>>   	struct device		*device;
>>   	struct xsc_priv		priv;
>> +	void			*netdev;
>>   	void			*eth_priv;
>>   	struct xsc_dev_resource	*dev_res;
>>   
>> diff --git a/drivers/net/ethernet/yunsilicon/xsc/net/main.c b/drivers/net/ethernet/yunsilicon/xsc/net/main.c
>> new file mode 100644
>> index 000000000..243ec7ced
>> --- /dev/null
>> +++ b/drivers/net/ethernet/yunsilicon/xsc/net/main.c
>> @@ -0,0 +1,135 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/* Copyright (C) 2021 - 2023, Shanghai Yunsilicon Technology Co., Ltd.
>> + * All rights reserved.
>> + */
>> +
>> +#include <linux/reboot.h>
> reboot.h in an ethernet driver?
>
>> +static int xsc_net_reboot_event_handler(struct notifier_block *nb, unsigned long action, void *data)
>> +{
>> +	pr_info("xsc net driver recv %lu event\n", action);
>> +	xsc_remove_eth_driver();
>> +
>> +	return NOTIFY_OK;
>> +}
>> +
>> +struct notifier_block xsc_net_nb = {
>> +	.notifier_call = xsc_net_reboot_event_handler,
>> +	.next = NULL,
>> +	.priority = 1,
>> +};
> This needs a comment explanation why this driver needs something
> special during reboot.
>
>      Andrew
>
> ---
> pw-bot: cr
Andrew Lunn Dec. 18, 2024, 4 p.m. UTC | #5
On Wed, Dec 18, 2024 at 11:35:39PM +0800, tianx wrote:
> We need to do some cleanup work when the machine shutdown.

That is very unusual. When you do add that code, please add a good
comment why it is needed. Anything unusual should be commented,
because you are going to get questions about it.

	Andrew
diff mbox series

Patch

diff --git a/drivers/net/ethernet/yunsilicon/Makefile b/drivers/net/ethernet/yunsilicon/Makefile
index 950fd2663..c1d3e3398 100644
--- a/drivers/net/ethernet/yunsilicon/Makefile
+++ b/drivers/net/ethernet/yunsilicon/Makefile
@@ -4,5 +4,5 @@ 
 # Makefile for the Yunsilicon device drivers.
 #
 
-# obj-$(CONFIG_YUNSILICON_XSC_ETH) += xsc/net/
+obj-$(CONFIG_YUNSILICON_XSC_ETH) += xsc/net/
 obj-$(CONFIG_YUNSILICON_XSC_PCI) += xsc/pci/
\ No newline at end of file
diff --git a/drivers/net/ethernet/yunsilicon/xsc/common/xsc_core.h b/drivers/net/ethernet/yunsilicon/xsc/common/xsc_core.h
index 88d4c5654..5d2b28e2e 100644
--- a/drivers/net/ethernet/yunsilicon/xsc/common/xsc_core.h
+++ b/drivers/net/ethernet/yunsilicon/xsc/common/xsc_core.h
@@ -498,6 +498,7 @@  struct xsc_core_device {
 	struct pci_dev		*pdev;
 	struct device		*device;
 	struct xsc_priv		priv;
+	void			*netdev;
 	void			*eth_priv;
 	struct xsc_dev_resource	*dev_res;
 
diff --git a/drivers/net/ethernet/yunsilicon/xsc/net/main.c b/drivers/net/ethernet/yunsilicon/xsc/net/main.c
new file mode 100644
index 000000000..243ec7ced
--- /dev/null
+++ b/drivers/net/ethernet/yunsilicon/xsc/net/main.c
@@ -0,0 +1,135 @@ 
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (C) 2021 - 2023, Shanghai Yunsilicon Technology Co., Ltd.
+ * All rights reserved.
+ */
+
+#include <linux/reboot.h>
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
+#include "common/xsc_core.h"
+#include "xsc_eth_common.h"
+#include "xsc_eth.h"
+
+static int xsc_get_max_num_channels(struct xsc_core_device *xdev)
+{
+	return min_t(int, xdev->dev_res->eq_table.num_comp_vectors,
+		     XSC_ETH_MAX_NUM_CHANNELS);
+}
+
+static void *xsc_eth_add(struct xsc_core_device *xdev)
+{
+	int err = -1;
+	int num_chl, num_tc;
+	struct net_device *netdev;
+	struct xsc_adapter *adapter = NULL;
+
+	num_chl = xsc_get_max_num_channels(xdev);
+	num_tc = xdev->caps.max_tc;
+
+	netdev = alloc_etherdev_mqs(sizeof(struct xsc_adapter),
+				    num_chl * num_tc, num_chl);
+	if (unlikely(!netdev)) {
+		xsc_core_warn(xdev, "alloc_etherdev_mqs failed, txq=%d, rxq=%d\n",
+			      (num_chl * num_tc), num_chl);
+		return NULL;
+	}
+
+	netdev->dev.parent = &xdev->pdev->dev;
+	adapter = netdev_priv(netdev);
+	adapter->netdev = netdev;
+	adapter->pdev = xdev->pdev;
+	adapter->dev = &adapter->pdev->dev;
+	adapter->xdev = (void *)xdev;
+	xdev->eth_priv = adapter;
+
+	err = register_netdev(netdev);
+	if (err) {
+		xsc_core_warn(xdev, "register_netdev failed, err=%d\n", err);
+		goto err_reg_netdev;
+	}
+
+	xdev->netdev = (void *)netdev;
+
+	return adapter;
+
+err_reg_netdev:
+	free_netdev(netdev);
+
+	return NULL;
+}
+
+static void xsc_eth_remove(struct xsc_core_device *xdev, void *context)
+{
+	struct xsc_adapter *adapter = NULL;
+
+	if (!xdev)
+		return;
+
+	adapter = xdev->eth_priv;
+	if (!adapter) {
+		xsc_core_warn(xdev, "failed! adapter is null\n");
+		return;
+	}
+
+	xsc_core_info(adapter->xdev, "remove netdev %s entry\n", adapter->netdev->name);
+
+	unregister_netdev(adapter->netdev);
+
+	free_netdev(adapter->netdev);
+
+	xdev->netdev = NULL;
+	xdev->eth_priv = NULL;
+}
+
+static struct xsc_interface xsc_interface = {
+	.add       = xsc_eth_add,
+	.remove    = xsc_eth_remove,
+	.event     = NULL,
+	.protocol  = XSC_INTERFACE_PROTOCOL_ETH,
+};
+
+static void xsc_remove_eth_driver(void)
+{
+	pr_info("remove ethernet driver\n");
+	xsc_unregister_interface(&xsc_interface);
+}
+
+static int xsc_net_reboot_event_handler(struct notifier_block *nb, unsigned long action, void *data)
+{
+	pr_info("xsc net driver recv %lu event\n", action);
+	xsc_remove_eth_driver();
+
+	return NOTIFY_OK;
+}
+
+struct notifier_block xsc_net_nb = {
+	.notifier_call = xsc_net_reboot_event_handler,
+	.next = NULL,
+	.priority = 1,
+};
+
+static __init int xsc_net_driver_init(void)
+{
+	int ret;
+
+	pr_info("add ethernet driver\n");
+	ret = xsc_register_interface(&xsc_interface);
+	if (ret != 0) {
+		pr_err("failed to register interface\n");
+		goto out;
+	}
+
+	register_reboot_notifier(&xsc_net_nb);
+	return 0;
+out:
+	return -1;
+}
+
+static __exit void xsc_net_driver_exit(void)
+{
+	unregister_reboot_notifier(&xsc_net_nb);
+	xsc_remove_eth_driver();
+}
+
+module_init(xsc_net_driver_init);
+module_exit(xsc_net_driver_exit);
diff --git a/drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth.h b/drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth.h
new file mode 100644
index 000000000..ba8e52d7f
--- /dev/null
+++ b/drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth.h
@@ -0,0 +1,16 @@ 
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (C) 2021 - 2023, Shanghai Yunsilicon Technology Co., Ltd.
+ * All rights reserved.
+ */
+
+#ifndef XSC_ETH_H
+#define XSC_ETH_H
+
+struct xsc_adapter {
+	struct net_device *netdev;
+	struct pci_dev *pdev;
+	struct device *dev;
+	struct xsc_core_device *xdev;
+};
+
+#endif /* XSC_ETH_H */
diff --git a/drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth_common.h b/drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth_common.h
new file mode 100644
index 000000000..8cc416783
--- /dev/null
+++ b/drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth_common.h
@@ -0,0 +1,15 @@ 
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (C) 2021 - 2023, Shanghai Yunsilicon Technology Co., Ltd.
+ * All rights reserved.
+ */
+
+#ifndef XSC_ETH_COMMON_H
+#define XSC_ETH_COMMON_H
+
+#define XSC_LOG_INDIR_RQT_SIZE		0x8
+
+#define XSC_INDIR_RQT_SIZE			BIT(XSC_LOG_INDIR_RQT_SIZE)
+#define XSC_ETH_MIN_NUM_CHANNELS	2
+#define XSC_ETH_MAX_NUM_CHANNELS	XSC_INDIR_RQT_SIZE
+
+#endif