This is a patch series for pinctrl driver for Sunplus SP7021 SoC.
Subsystems (4)
v3 cover This is a patch series for pinctrl driver for Sunplus SP7021 SoC.
Sunplus SP7021 is an ARM Cortex A7 (4 cores) based SoC. It integrates many peripherals (ex: UART, I2C, SPI, SDIO, eMMC, USB, SD card and etc.) into a single chip. It is designed for industrial control applications.
Refer to:
https://sunplus-tibbo.atlassian.net/wiki/spaces/doc/overview
https://tibbo.com/store/plus1.html
Wells Lu (2):
devicetree: bindings: net: Add bindings doc for Sunplus SP7021.
net: ethernet: Add driver for Sunplus SP7021
.../bindings/net/sunplus,sp7021-emac.yaml | 172 ++++++ MAINTAINERS | 8 + drivers/net/ethernet/Kconfig | 1 + drivers/net/ethernet/Makefile | 1 + drivers/net/ethernet/sunplus/Kconfig | 36 ++ drivers/net/ethernet/sunplus/Makefile | 6 + drivers/net/ethernet/sunplus/spl2sw_define.h | 301 ++++++++++ drivers/net/ethernet/sunplus/spl2sw_desc.c | 224 ++++++++ drivers/net/ethernet/sunplus/spl2sw_desc.h | 21 + drivers/net/ethernet/sunplus/spl2sw_driver.c | 627 +++++++++++++++++++++ drivers/net/ethernet/sunplus/spl2sw_driver.h | 19 + drivers/net/ethernet/sunplus/spl2sw_int.c | 272 +++++++++ drivers/net/ethernet/sunplus/spl2sw_int.h | 15 + drivers/net/ethernet/sunplus/spl2sw_mac.c | 336 +++++++++++ drivers/net/ethernet/sunplus/spl2sw_mac.h | 23 + drivers/net/ethernet/sunplus/spl2sw_mdio.c | 117 ++++ drivers/net/ethernet/sunplus/spl2sw_mdio.h | 14 + drivers/net/ethernet/sunplus/spl2sw_phy.c | 89 +++ drivers/net/ethernet/sunplus/spl2sw_phy.h | 14 + drivers/net/ethernet/sunplus/spl2sw_register.h | 96 ++++ 20 files changed, 2392 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/sunplus,sp7021-emac.yaml create mode 100644 drivers/net/ethernet/sunplus/Kconfig create mode 100644 drivers/net/ethernet/sunplus/Makefile create mode 100644 drivers/net/ethernet/sunplus/spl2sw_define.h create mode 100644 drivers/net/ethernet/sunplus/spl2sw_desc.c create mode 100644 drivers/net/ethernet/sunplus/spl2sw_desc.h create mode 100644 drivers/net/ethernet/sunplus/spl2sw_driver.c create mode 100644 drivers/net/ethernet/sunplus/spl2sw_driver.h create mode 100644 drivers/net/ethernet/sunplus/spl2sw_int.c create mode 100644 drivers/net/ethernet/sunplus/spl2sw_int.h create mode 100644 drivers/net/ethernet/sunplus/spl2sw_mac.c create mode 100644 drivers/net/ethernet/sunplus/spl2sw_mac.h create mode 100644 drivers/net/ethernet/sunplus/spl2sw_mdio.c create mode 100644 drivers/net/ethernet/sunplus/spl2sw_mdio.h create mode 100644 drivers/net/ethernet/sunplus/spl2sw_phy.c create mode 100644 drivers/net/ethernet/sunplus/spl2sw_phy.h create mode 100644 drivers/net/ethernet/sunplus/spl2sw_register.h
Signature · 1 line
2.7.4
PATCH v3 1/2 devicetree: bindings: net: Add bindings doc for Sunplus SP7021.
Add bindings documentation for Sunplus SP7021.
---
Changes in v3
- Addressed all comments from Mr. Andrew Lunn.
- Added node 'ethernet-ports' and sub-nodes 'port'.
- Moved properties phy-handle and phy-mode to sub-nodes 'port'.
- Limit maximum value of reg of ethernet-phy port to 30.
- Addressed all commetns from Mr. Rob Herring.
- Fixed wrong indentation in dt doc (yaml).
.../bindings/net/sunplus,sp7021-emac.yaml | 172 +++++++++++++++++++++ MAINTAINERS | 7 + 2 files changed, 179 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/sunplus,sp7021-emac.yaml
Documentation/devicetree/bindings/net/sunplus,sp7021-emac.yaml new file +172 -0
@@ -0,0 +1,172 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +# Copyright (C) Sunplus Co., Ltd. 2021 +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/sunplus,sp7021-emac.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Sunplus SP7021 Dual Ethernet MAC Device Tree Bindings + +maintainers: + - Wells Lu <[email protected]> + +description: | + Sunplus SP7021 dual 10M/100M Ethernet MAC controller. + Device node of the controller has following properties. + +properties: + compatible: + const: sunplus,sp7021-emac + + reg: + items: + - description: the EMAC registers + - description: the MOON5 registers + + reg-names: + items: + - const: emac + - const: moon5 + + interrupts: + description: | + Contains number and type of interrupt. Number should be 66. + Type should be high-level trigger. + maxItems: 1 + + clocks: + maxItems: 1 + + resets: + maxItems: 1 + + nvmem-cells: + items: + - description: nvmem cell address of MAC address of 1st MAC + - description: nvmem cell address of MAC address of 2nd MAC + + nvmem-cell-names: + description: names corresponding to the nvmem cells of MAC address + items: + - const: mac_addr0 + - const: mac_addr1 + + ethernet-ports: + type: object + description: Ethernet ports to PHY + + properties: + "#address-cells": + const: 1 + + "#size-cells": + const: 0 + + patternProperties: + "^port@[0-1]$": + type: object + description: Port to PHY + + properties: + reg: + minimum: 0 + maximum: 1 + + phy-handle: + maxItems: 1 + + phy-mode: + maxItems: 1 + + required: + - reg + - phy-handle + - phy-mode + + mdio: + type: object + description: external MDIO Bus + + properties: + "#address-cells": + const: 1 + + "#size-cells": + const: 0 + + patternProperties: + "^ethernet-phy@[0-9a-f]+$": + type: object + description: external PHY node + + properties: + reg: + minimum: 0 + maximum: 30 + + required: + - reg + +additionalProperties: false + +required: + - compatible + - reg + - reg-names + - interrupts + - clocks + - resets + - pinctrl-0 + - pinctrl-names + - nvmem-cells + - nvmem-cell-names + - ethernet-ports + - mdio + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + emac: emac@9c108000 { + compatible = "sunplus,sp7021-emac"; + reg = <0x9c108000 0x400>, <0x9c000280 0x80>; + reg-names = "emac", "moon5"; + interrupt-parent = <&intc>; + interrupts = <66 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&clkc 0xa7>; + resets = <&rstc 0x97>; + pinctrl-0 = <&emac_demo_board_v3_pins>; + pinctrl-names = "default"; + nvmem-cells = <&mac_addr0>, <&mac_addr1>; + nvmem-cell-names = "mac_addr0", "mac_addr1"; + + ethernet-ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + phy-handle = <ð_phy0>; + phy-mode = "rmii"; + }; + + port@1 { + reg = <1>; + phy-handle = <ð_phy1>; + phy-mode = "rmii"; + }; + }; + + mdio { + #address-cells = <1>; + #size-cells = <0>; + + eth_phy0: ethernet-phy@0 { + reg = <0>; + }; + + eth_phy1: ethernet-phy@1 { + reg = <1>; + }; + }; + }; +...
MAINTAINERS +7 -0
@@ -18242,6 +18242,13 @@ L: [email protected] S: Maintained F: drivers/net/ethernet/dlink/sundance.c +SUNPLUS ETHERNET DRIVER +M: Wells Lu <[email protected]> +L: [email protected] +S: Maintained +W: https://sunplus-tibbo.atlassian.net/wiki/spaces/doc/overview +F: Documentation/devicetree/bindings/net/sunplus,sp7021-emac.yaml + SUPERH M: Yoshinori Sato <[email protected]> M: Rich Felker <[email protected]>
Signature · 1 line
2.7.4
Re: [PATCH net-next v3 1/2] devicetree: bindings: net: Add bindings doc for Sunplus SP7021.
Documentation/devicetree/bindings/net/sunplus,sp7021-emac.yaml line 52
Quoted 10 lines
Documentation/devicetree/bindings/net/sunplus,sp7021-emac.yaml new file +10
-0+ nvmem-cells: + items: + - description: nvmem cell address of MAC address of 1st MAC + - description: nvmem cell address of MAC address of 2nd MAC + + nvmem-cell-names: + description: names corresponding to the nvmem cells of MAC address + items: + - const: mac_addr0 + - const: mac_addr1
These are port properties, so put them in the port section.
Also, the name you should use is well defined, "mac-address". See nvmem_get_mac_address(). But you won't be able to use that helper because it take dev, not an of node.
Andrew
RE: [PATCH net-next v3 1/2] devicetree: bindings: net: Add bindings doc for Sunplus SP7021.
Hi Andrew,
Thank you very much for review.
I'll move properties nvmem-cells and nvmem-cell-names to ethernet ports and change value of nvmem-cell-names to "mac-address" next patch.
I'll refer to "nvmem_get_mac_address()" when modifying code.
Best regards,
Wells
Quoted 17 lines
Documentation/devicetree/bindings/net/sunplus,sp7021-emac.yaml line 52
Quoted 10 lines
Documentation/devicetree/bindings/net/sunplus,sp7021-emac.yaml new file +10
-0+ nvmem-cells: + items: + - description: nvmem cell address of MAC address of 1st MAC + - description: nvmem cell address of MAC address of 2nd MAC + + nvmem-cell-names: + description: names corresponding to the nvmem cells of MAC address + items: + - const: mac_addr0 + - const: mac_addr1These are port properties, so put them in the port section.
Also, the name you should use is well defined, "mac-address". See
nvmem_get_mac_address(). But you won't be able to use that helper because it take dev, not an of node.Andrew
PATCH v3 2/2 net: ethernet: Add driver for Sunplus SP7021
In reply to Wells LuAdd driver for Sunplus SP7021.
---
Changes in v3
- Addressed all comments from Mr. Andrew Lunn.
- Modified code to get properties phy-handle and phy-mode from sub-nodes 'port'.
- Removed file 'sp_hal.c'.
- Moved mac relevant functions to 'spl2sw_mac.c'.
- Moved mdio relevant functions to 'spl2sw_mdio.c'.
- Modified some functions' name to be more consistent.
- Added spl2sw_ prefix to all functions.
- Reversed Xmas tree order for local variables in functions.
- Removed port_status_change().
- Use an array of 'pointer to struct net-device' to manage net-devices, instead of linked-list of 'struct spl2sw_mac'.
- Use 'force' mode to invalidate 'auto mii' function.
- Added processes in spl2sw_mii_link_change() function to take care of link-change events.
- Use netdev_err(), netdev_dbg() if ndev is available.
Replaced some dev_info() with dev_dbg() or netdev_dbg().
- others
- Addressed all comments from Mr. Denis Kirjanov.
- Use C-style comments.
- Added error handling when dma_map_single() fails.
- lower case for all labels.
- Added tx_timeout function.
- Defined some constants for control-bits of MAC using BIT() or GENMASK() macros. Use FIELD_GET() and FIELD_PREP() macros to access.
- others.
- Addressed all comments from Mr. Florian Fainelli.
- Fixed scope issues of mdio read and write functions.
- Removed a layer violation settings about PHY.
- Removed member 'phy_dev' from struct sp_mac.
- Addressed all comments from Mr. Pavel Skripkin.
- Removed buggy code that private data is accessed after struct net_device is freed.
- Fixed a warning Reported-by: kernel test robot <[email protected]>
- Changed Linux tree to 'net-next'
MAINTAINERS | 1 + drivers/net/ethernet/Kconfig | 1 + drivers/net/ethernet/Makefile | 1 + drivers/net/ethernet/sunplus/Kconfig | 36 ++ drivers/net/ethernet/sunplus/Makefile | 6 + drivers/net/ethernet/sunplus/spl2sw_define.h | 301 ++++++++++++ drivers/net/ethernet/sunplus/spl2sw_desc.c | 224 +++++++++ drivers/net/ethernet/sunplus/spl2sw_desc.h | 21 + drivers/net/ethernet/sunplus/spl2sw_driver.c | 627 +++++++++++++++++++++++++ drivers/net/ethernet/sunplus/spl2sw_driver.h | 19 + drivers/net/ethernet/sunplus/spl2sw_int.c | 272 +++++++++++ drivers/net/ethernet/sunplus/spl2sw_int.h | 15 + drivers/net/ethernet/sunplus/spl2sw_mac.c | 336 +++++++++++++ drivers/net/ethernet/sunplus/spl2sw_mac.h | 23 + drivers/net/ethernet/sunplus/spl2sw_mdio.c | 117 +++++ drivers/net/ethernet/sunplus/spl2sw_mdio.h | 14 + drivers/net/ethernet/sunplus/spl2sw_phy.c | 89 ++++ drivers/net/ethernet/sunplus/spl2sw_phy.h | 14 + drivers/net/ethernet/sunplus/spl2sw_register.h | 96 ++++ 19 files changed, 2213 insertions(+) create mode 100644 drivers/net/ethernet/sunplus/Kconfig create mode 100644 drivers/net/ethernet/sunplus/Makefile create mode 100644 drivers/net/ethernet/sunplus/spl2sw_define.h create mode 100644 drivers/net/ethernet/sunplus/spl2sw_desc.c create mode 100644 drivers/net/ethernet/sunplus/spl2sw_desc.h create mode 100644 drivers/net/ethernet/sunplus/spl2sw_driver.c create mode 100644 drivers/net/ethernet/sunplus/spl2sw_driver.h create mode 100644 drivers/net/ethernet/sunplus/spl2sw_int.c create mode 100644 drivers/net/ethernet/sunplus/spl2sw_int.h create mode 100644 drivers/net/ethernet/sunplus/spl2sw_mac.c create mode 100644 drivers/net/ethernet/sunplus/spl2sw_mac.h create mode 100644 drivers/net/ethernet/sunplus/spl2sw_mdio.c create mode 100644 drivers/net/ethernet/sunplus/spl2sw_mdio.h create mode 100644 drivers/net/ethernet/sunplus/spl2sw_phy.c create mode 100644 drivers/net/ethernet/sunplus/spl2sw_phy.h create mode 100644 drivers/net/ethernet/sunplus/spl2sw_register.h
MAINTAINERS +1 -0
@@ -18248,6 +18248,7 @@ L: [email protected] S: Maintained W: https://sunplus-tibbo.atlassian.net/wiki/spaces/doc/overview F: Documentation/devicetree/bindings/net/sunplus,sp7021-emac.yaml +F: drivers/net/ethernet/sunplus/ SUPERH M: Yoshinori Sato <[email protected]>
drivers/net/ethernet/Kconfig +1 -0
@@ -178,6 +178,7 @@ source "drivers/net/ethernet/smsc/Kconfig" source "drivers/net/ethernet/socionext/Kconfig" source "drivers/net/ethernet/stmicro/Kconfig" source "drivers/net/ethernet/sun/Kconfig" +source "drivers/net/ethernet/sunplus/Kconfig" source "drivers/net/ethernet/synopsys/Kconfig" source "drivers/net/ethernet/tehuti/Kconfig" source "drivers/net/ethernet/ti/Kconfig"
drivers/net/ethernet/Makefile +1 -0
@@ -89,6 +89,7 @@ obj-$(CONFIG_NET_VENDOR_SMSC) += smsc/ obj-$(CONFIG_NET_VENDOR_SOCIONEXT) += socionext/ obj-$(CONFIG_NET_VENDOR_STMICRO) += stmicro/ obj-$(CONFIG_NET_VENDOR_SUN) += sun/ +obj-$(CONFIG_NET_VENDOR_SUNPLUS) += sunplus/ obj-$(CONFIG_NET_VENDOR_TEHUTI) += tehuti/ obj-$(CONFIG_NET_VENDOR_TI) += ti/ obj-$(CONFIG_NET_VENDOR_TOSHIBA) += toshiba/
drivers/net/ethernet/sunplus/Kconfig new file +36 -0
@@ -0,0 +1,36 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Sunplus network device configuration +# + +config NET_VENDOR_SUNPLUS + bool "Sunplus devices" + default y + depends on ARCH_SUNPLUS || COMPILE_TEST + help + If you have a network (Ethernet) card belonging to this + class, say Y here. + + Note that the answer to this question doesn't directly + affect the kernel: saying N will just cause the configurator + to skip all the questions about Sunplus cards. If you say Y, + you will be asked for your specific card in the following + questions. + +if NET_VENDOR_SUNPLUS + +config SP7021_EMAC + tristate "Sunplus Dual 10M/100M Ethernet devices" + depends on SOC_SP7021 || COMPILE_TEST + select PHYLIB + select PINCTRL_SPPCTL + select COMMON_CLK_SP7021 + select RESET_SUNPLUS + select NVMEM_SUNPLUS_OCOTP + help + If you have Sunplus dual 10M/100M Ethernet devices, say Y. + The network device creates two net-device interfaces. + To compile this driver as a module, choose M here. The + module will be called sp7021_emac. + +endif # NET_VENDOR_SUNPLUS
drivers/net/ethernet/sunplus/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for the Sunplus network device drivers. +# +obj-$(CONFIG_SP7021_EMAC) += sp7021_emac.o +sp7021_emac-objs := spl2sw_driver.o spl2sw_int.o spl2sw_desc.o spl2sw_mac.o spl2sw_mdio.o spl2sw_phy.o
drivers/net/ethernet/sunplus/spl2sw_define.h new file +301 -0
301 lines not on this page · raw message
drivers/net/ethernet/sunplus/spl2sw_desc.c new file +224 -0
224 lines not on this page · raw message
drivers/net/ethernet/sunplus/spl2sw_desc.h new file +21 -0
@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright Sunplus Technology Co., Ltd. +* All rights reserved. +*/ + +#ifndef __SPL2SW_DESC_H__ +#define __SPL2SW_DESC_H__ + +#include "spl2sw_define.h" + +void spl2sw_rx_descs_flush (struct spl2sw_common *comm); +void spl2sw_tx_descs_clean (struct spl2sw_common *comm); +void spl2sw_rx_descs_clean (struct spl2sw_common *comm); +void spl2sw_descs_clean (struct spl2sw_common *comm); +void spl2sw_descs_free (struct spl2sw_common *comm); +void spl2sw_tx_descs_init (struct spl2sw_common *comm); +int spl2sw_rx_descs_init (struct spl2sw_common *comm); +int spl2sw_descs_alloc (struct spl2sw_common *comm); +int spl2sw_descs_init (struct spl2sw_common *comm); + +#endif
drivers/net/ethernet/sunplus/spl2sw_driver.c new file +627 -0
627 lines not on this page · raw message
drivers/net/ethernet/sunplus/spl2sw_driver.h new file +19 -0
@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright Sunplus Technology Co., Ltd. +* All rights reserved. +*/ + +#ifndef __SPL2SW_DRIVER_H__ +#define __SPL2SW_DRIVER_H__ + +#include "spl2sw_register.h" +#include "spl2sw_define.h" +#include "spl2sw_int.h" +#include "spl2sw_mdio.h" +#include "spl2sw_mac.h" +#include "spl2sw_desc.h" + +#define SPL2SW_RX_NAPI_WEIGHT 16 +#define SPL2SW_TX_NAPI_WEIGHT 16 + +#endif
drivers/net/ethernet/sunplus/spl2sw_int.c new file +272 -0
272 lines not on this page · raw message
drivers/net/ethernet/sunplus/spl2sw_int.h new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright Sunplus Technology Co., Ltd. +* All rights reserved. +*/ + +#ifndef __SPL2SW_INT_H__ +#define __SPL2SW_INT_H__ + +#include <linux/netdevice.h> + +int spl2sw_rx_poll (struct napi_struct *napi,int budget); +int spl2sw_tx_poll (struct napi_struct *napi,int budget); +irqreturn_t spl2sw_ethernet_interrupt (int irq,void *dev_id); + +#endif
drivers/net/ethernet/sunplus/spl2sw_mac.c new file +336 -0
336 lines not on this page · raw message
drivers/net/ethernet/sunplus/spl2sw_mac.h new file +23 -0
@@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright Sunplus Technology Co., Ltd. +* All rights reserved. +*/ + +#ifndef __SPL2SW_MAC_H__ +#define __SPL2SW_MAC_H__ + +#include "spl2sw_define.h" +#include "spl2sw_register.h" +#include "spl2sw_desc.h" + +void spl2sw_mac_hw_stop (struct spl2sw_common *comm); +void spl2sw_mac_hw_start (struct spl2sw_common *comm); +void spl2sw_mac_addr_add (struct spl2sw_mac *mac); +void spl2sw_mac_addr_del (struct spl2sw_mac *mac); +void spl2sw_mac_addr_del_all (struct spl2sw_common *comm); +void spl2sw_mac_hw_init (struct spl2sw_common *comm); +void spl2sw_mac_rx_mode_set (struct spl2sw_mac *mac); +void spl2sw_mac_init (struct spl2sw_common *comm); +void spl2sw_mac_soft_reset (struct spl2sw_common *comm); + +#endif
drivers/net/ethernet/sunplus/spl2sw_mdio.c new file +117 -0
117 lines not on this page · raw message
drivers/net/ethernet/sunplus/spl2sw_mdio.h new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright Sunplus Technology Co., Ltd. +* All rights reserved. +*/ + +#ifndef __SPL2SW_MDIO_H__ +#define __SPL2SW_MDIO_H__ + +#include "spl2sw_define.h" + +u32 spl2sw_mdio_init (struct spl2sw_common *comm); +void spl2sw_mdio_remove (struct spl2sw_common *comm); + +#endif
drivers/net/ethernet/sunplus/spl2sw_phy.c new file +89 -0
89 lines not on this page · raw message
drivers/net/ethernet/sunplus/spl2sw_phy.h new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright Sunplus Technology Co., Ltd. +* All rights reserved. +*/ + +#ifndef __SPL2SW_PHY_H__ +#define __SPL2SW_PHY_H__ + +#include "spl2sw_define.h" + +int spl2sw_phy_connect (struct spl2sw_common *comm); +void spl2sw_phy_remove (struct spl2sw_common *comm); + +#endif
drivers/net/ethernet/sunplus/spl2sw_register.h new file +96 -0
96 lines not on this page · raw message
Signature · 1 line
2.7.4
kernel test robot
build botRe: [PATCH net-next v3 2/2] net: ethernet: Add driver for Sunplus SP7021
I love your patch! Perhaps something to improve:
Hi Wells,
I love your patch! Perhaps something to improve:
[auto build test WARNING on net-next/master]
url: https://github.com/0day-ci/linux/commits/Wells-Lu/This-is-a-patch-series-for-pinctrl-driver-for-Sunplus-SP7021-SoC/20211130-180452 base: https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 09ae03e2fc9d04240c21759ce9f1ef63d7651850 config: alpha-allyesconfig (https://download.01.org/0day-ci/archive/20211130/202111302126.kdjsLCiQ-lkp(a)intel.com/config) compiler: alpha-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/c5416cd4312a02ecbd1752129b61392a857a45fb
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Wells-Lu/This-is-a-patch-series-for-pinctrl-driver-for-Sunplus-SP7021-SoC/20211130-180452 git checkout c5416cd4312a02ecbd1752129b61392a857a45fb
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=alpha SHELL=/bin/bash drivers/net/ethernet/sunplus/
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
drivers/net/ethernet/sunplus/spl2sw_int.c: In function 'spl2sw_tx_poll':
>> drivers/net/ethernet/sunplus/spl2sw_int.c:157:28: warning: variable 'mac' set but not used [-Wunused-but-set-variable]
157 | struct spl2sw_mac *mac;
| ^~~vim +/mac +157 drivers/net/ethernet/sunplus/spl2sw_int.c
151
152 int spl2sw_tx_poll(struct napi_struct *napi, int budget)
153 {
154 struct spl2sw_common *comm = container_of(napi, struct spl2sw_common, tx_napi);
155 struct spl2sw_skb_info *skbinfo;
156 struct net_device_stats *stats;
> 157 struct spl2sw_mac *mac;
158 u32 tx_done_pos;
159 u32 mask;
160 u32 cmd;
161 int i;
162
163 spin_lock(&comm->tx_lock);
164
165 tx_done_pos = comm->tx_done_pos;
166 while ((tx_done_pos != comm->tx_pos) || (comm->tx_desc_full == 1)) {
167 cmd = comm->tx_desc[tx_done_pos].cmd1;
168 if (cmd & TXD_OWN)
169 break;
170
171 skbinfo = &comm->tx_temp_skb_info[tx_done_pos];
172 if (unlikely(!skbinfo->skb))
173 goto spl2sw_tx_poll_next;
174
175 i = spl2sw_bit_pos_to_port_num(FIELD_GET(TXD_VLAN, cmd));
176 if (i < MAX_NETDEV_NUM && comm->ndev[i]) {
177 mac = netdev_priv(comm->ndev[i]);
178 stats = &comm->ndev[i]->stats;
179 } else {
180 goto spl2sw_tx_poll_unmap;
181 }
182
183 if (unlikely(cmd & (TXD_ERR_CODE))) {
184 stats->tx_errors++;
185 } else {
186 stats->tx_packets++;
187 stats->tx_bytes += skbinfo->len;
188 }
189
190 spl2sw_tx_poll_unmap:
191 dma_unmap_single(&comm->pdev->dev, skbinfo->mapping, skbinfo->len,
192 DMA_TO_DEVICE);
193 skbinfo->mapping = 0;
194 dev_kfree_skb_irq(skbinfo->skb);
195 skbinfo->skb = NULL;
196
197 spl2sw_tx_poll_next:
198 /* Move tx_done_pos to next position */
199 tx_done_pos = ((tx_done_pos + 1) == TX_DESC_NUM) ? 0 : tx_done_pos + 1;
200
201 if (comm->tx_desc_full == 1)
202 comm->tx_desc_full = 0;
203 }
204
205 comm->tx_done_pos = tx_done_pos;
206 if (!comm->tx_desc_full)
207 for (i = 0; i < MAX_NETDEV_NUM; i++)
208 if (comm->ndev[i])
209 if (netif_queue_stopped(comm->ndev[i]))
210 netif_wake_queue(comm->ndev[i]);
211
212 spin_unlock(&comm->tx_lock);
213
214 wmb(); /* make sure settings are effective. */
215 mask = readl(comm->l2sw_reg_base + L2SW_SW_INT_MASK_0);
216 mask &= ~MAC_INT_TX;
217 writel(mask, comm->l2sw_reg_base + L2SW_SW_INT_MASK_0);
218
219 napi_complete(napi);
220 return 0;
221 }
222
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Re: [PATCH net-next v3 2/2] net: ethernet: Add driver for Sunplus SP7021
In reply to Wells LuQuoted 16 lines
+++
b/drivers/net/ethernet/sunplus/spl2sw_define.hdrivers/net/ethernet/sunplus/spl2sw_define.h new file +14
-0@@ -0,0 +1,301 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright Sunplus Technology Co., Ltd. +* All rights reserved. +*/ + +#ifndef __SPL2SW_DEFINE_H__ +#define __SPL2SW_DEFINE_H__ + +#include <linux/module.h> +#include <linux/errno.h> +#include <linux/types.h> +#include <linux/interrupt.h> +#include <linux/netdevice.h> +#include <linux/etherdevice.h>
drivers/net/ethernet/sunplus/spl2sw_define.h line 24
Quoted 10 lines
drivers/net/ethernet/sunplus/spl2sw_define.h new file +10
-0+#include <linux/skbuff.h> +#include <linux/ethtool.h> +#include <linux/platform_device.h> +#include <linux/phy.h> +#include <linux/mii.h> +#include <linux/io.h> +#include <linux/dma-mapping.h> +#include <linux/of_address.h> +#include <linux/of_mdio.h> +#include <linux/bitfield.h>
Please put these in the .c file, and only include those that are needed in each .c file.
Quoted 7 lines
drivers/net/ethernet/sunplus/spl2sw_desc.c new file +7
-0+int spl2sw_rx_descs_init (struct spl2sw_common *comm) +{ +struct spl2sw_skb_info *rx_skbinfo; +struct spl2sw_mac_desc *rx_desc; +struct sk_buff *skb; +u32 i, j; +
drivers/net/ethernet/sunplus/spl2sw_desc.c line 135
Quoted 10 lines
drivers/net/ethernet/sunplus/spl2sw_desc.c new file +10
-0+for (i =0 ; i <RX_DESC_QUEUE_NUM ; i++) { + comm->rx_skb_info[i] =kcalloc (comm->rx_desc_num[i],sizeof (*rx_skbinfo), +GFP_KERNEL |GFP_DMA ); +if (!comm->rx_skb_info[i]) + goto mem_alloc_fail; + + rx_skbinfo = comm->rx_skb_info[i]; + rx_desc = comm->rx_desc[i]; +for (j =0 ; j < comm->rx_desc_num[i]; j++) { + skb =__dev_alloc_skb (comm->rx_desc_buff_size,GFP_KERNEL |GFP_DMA );
I generally don't look to closely at buffer handling in drivers. But the __ caught my eye. There is a comment:
/* legacy helper around __netdev_alloc_skb() */
Since this is legacy, you probably should not be using it. I don't know what you should be using though.
Quoted 22 lines
drivers/net/ethernet/sunplus/spl2sw_driver.c new file +22
-0+static u32 spl2sw_init_netdev (struct platform_device *pdev,int eth_no, +struct net_device **r_ndev) +{ +struct net_device *ndev; +struct spl2sw_mac *mac; +char *m_addr_name; +ssize_t otp_l =0 ; +char *otp_v; +int ret; + + m_addr_name = (eth_no ==0 ) ?"mac_addr0" :"mac_addr1" ; + +/* Allocate the devices, and also allocate spl2sw_mac, +* we can get it by netdev_priv(). +*/ + ndev =devm_alloc_etherdev (&pdev->dev,sizeof (*mac)); +if (!ndev) { + *r_ndev =NULL ; +return -ENOMEM ; + } +SET_NETDEV_DEV (ndev, &pdev->dev); + ndev->netdev_ops = &netdev_ops;
drivers/net/ethernet/sunplus/spl2sw_driver.c line 287
Quoted 10 lines
drivers/net/ethernet/sunplus/spl2sw_driver.c new file +10
-0+ + mac =netdev_priv (ndev); + mac->ndev = ndev; + +/* Get property 'mac-addr0' or 'mac-addr1' from dts. */ + otp_v =spl2sw_otp_read_mac (&pdev->dev, &otp_l, m_addr_name); +if (otp_l <ETH_ALEN ||IS_ERR_OR_NULL (otp_v)) { +dev_err (&pdev->dev,"OTP mac %s (len = %zd) is invalid, using default!\n" , + m_addr_name, otp_l); + otp_l =0 ;
This is not actually an error, in that you keep going and use the default. So dev_info() would be better, here and the other calls in this function.
Quoted 23 lines
drivers/net/ethernet/sunplus/spl2sw_driver.c new file +23
-0+ }else { +/* Check if MAC address is valid or not. If not, copy from default. */ +ether_addr_copy (mac->mac_addr, otp_v); + +/* Byte order of Some samples are reversed. Convert byte order here. */ +spl2sw_check_mac_vendor_id_and_convert (mac->mac_addr); + +if (!is_valid_ether_addr (mac->mac_addr)) { +dev_err (&pdev->dev,"Invalid mac in OTP[%s] = %pM, use default!\n" , + m_addr_name, mac->mac_addr); + otp_l =0 ; + } + } +if (otp_l !=6 ) { +/* MAC address is invalid. Generate one using random number. */ +ether_addr_copy (mac->mac_addr, spl2sw_def_mac_addr); + mac->mac_addr[3 ] =get_random_int () %256 ; + mac->mac_addr[4 ] =get_random_int () %256 ; + mac->mac_addr[5 ] =get_random_int () %256 ; + } + +eth_hw_addr_set (ndev, mac->mac_addr); +dev_info (&pdev->dev,"HW Addr = %pM\n" , mac->mac_addr);
drivers/net/ethernet/sunplus/spl2sw_driver.c line 320
Quoted 10 lines
drivers/net/ethernet/sunplus/spl2sw_driver.c new file +10
-0+ + ret =register_netdev (ndev); +if (ret) { +dev_err (&pdev->dev,"Failed to register net device \"%s\"!\n" , + ndev->name); +free_netdev (ndev); + *r_ndev =NULL ; +return ret; + } +netdev_info (ndev,"Registered net device \"%s\" successfully.\n" , ndev->name);
netdev_dbg().
Quoted 22 lines
drivers/net/ethernet/sunplus/spl2sw_driver.c new file +21
-0+ *r_ndev = ndev; +return 0 ; +} + +static int spl2sw_probe (struct platform_device *pdev) +{ +struct device_node *eth_ports_np; +struct device_node *port_np; +struct spl2sw_common *comm; +struct device_node *phy_np; +phy_interface_t phy_mode; +struct net_device *ndev; +struct spl2sw_mac *mac; +struct resource *rc; +int irq, i; +int ret; + +if (platform_get_drvdata (pdev)) +return -ENODEV ; + +/* Allocate memory for 'spl2sw_common' area. */
drivers/net/ethernet/sunplus/spl2sw_driver.c line 373
Quoted 10 lines
drivers/net/ethernet/sunplus/spl2sw_driver.c new file +10
-0+ comm =devm_kzalloc (&pdev->dev,sizeof (*comm),GFP_KERNEL ); +if (!comm) +return -ENOMEM ; + comm->pdev = pdev; + +spin_lock_init (&comm->rx_lock); +spin_lock_init (&comm->tx_lock); +spin_lock_init (&comm->mdio_lock); + +/* Get memory resoruce "emac" from dts. */
resource
drivers/net/ethernet/sunplus/spl2sw_driver.c line 438
Quoted 13 lines
drivers/net/ethernet/sunplus/spl2sw_driver.c new file +13
-0+/* Enable clock. */ +clk_prepare_enable (comm->clk); +udelay (1 ); + +reset_control_assert (comm->rstc); +udelay (1 ); +reset_control_deassert (comm->rstc); +udelay (1 ); + +/* Get child node ethernet-ports. */ + eth_ports_np =of_get_child_by_name (pdev->dev.of_node,"ethernet-ports" ); +if (!eth_ports_np) { +dev_err (&pdev->dev,"No ethernet-ports child node found!\n" );
You should disable the clock before returning.
Quoted 16 lines
drivers/net/ethernet/sunplus/spl2sw_driver.c new file +16
-0+return -ENODEV ; + } + +for (i =0 ; i <MAX_NETDEV_NUM ; i++) { +/* Get port@i of node ethernet-ports. */ + port_np =spl2sw_get_eth_child_node (eth_ports_np, i); +if (!port_np) +continue ; + +/* Get phy-mode. */ +if (of_get_phy_mode (port_np, &phy_mode)) { +dev_err (&pdev->dev,"Failed to get phy-mode property of port@%d!\n" , + i); +continue ; + } +
drivers/net/ethernet/sunplus/spl2sw_driver.c line 464
Quoted 10 lines
drivers/net/ethernet/sunplus/spl2sw_driver.c new file +10
-0+/* Get phy-handle. */ + phy_np =of_parse_phandle (port_np,"phy-handle" ,0 ); +if (!phy_np) { +dev_err (&pdev->dev,"Failed to get phy-handle property of port@%d!\n" , + i); +continue ; + } + +/* Get address of phy. */ +if (of_property_read_u32 (phy_np,"reg" , &comm->phy_addr[i])) {
This does not appear to be used.
drivers/net/ethernet/sunplus/spl2sw_driver.c line 473
Quoted 9 lines
drivers/net/ethernet/sunplus/spl2sw_driver.c new file +9
-0+dev_err (&pdev->dev,"Failed to get reg property of phy node!\n" ); +continue ; + } + +if (comm->phy_addr[i] >=PHY_MAX_ADDR -1 ) { +dev_err (&pdev->dev,"Invalid phy address (reg = <%d>)!\n" , + comm->phy_addr[i]); +continue ; + }
phylib should validate this.
drivers/net/ethernet/sunplus/spl2sw_driver.c line 481
Quoted 8 lines
drivers/net/ethernet/sunplus/spl2sw_driver.c new file +8
-0+ +if (!comm->mdio_node) { + comm->mdio_node =of_get_parent (phy_np); +if (!comm->mdio_node) { +dev_err (&pdev->dev,"Failed to get mdio_node!\n" ); +return -ENODATA ; + } + }
This does not look correct. The PHY could be on any MDIO bus. It does not have to be the bus of this device. There should not be any need to follow the pointer.
drivers/net/ethernet/sunplus/spl2sw_int.c line 149
Quoted 10 lines
drivers/net/ethernet/sunplus/spl2sw_int.c new file +10
-0+static int spl2sw_bit_pos_to_port_num (int n) +{ +int i; + +for (i =0 ; i <MAX_NETDEV_NUM ; i++) { +if (n &1 ) +break ; + n >>=1 ; + } +return i;
Look at the ffs() helper. But since MAX_NETDEV_NUM is two, the compiler might be smart enough to unroll the loop and just use simple logic operations which could be faster.
Quoted 13 lines
drivers/net/ethernet/sunplus/spl2sw_mac.c new file +13
-0+void spl2sw_mac_addr_add (struct spl2sw_mac *mac) +{ +struct spl2sw_common *comm = mac->comm; +u32 reg; + +/* Write 6-octet MAC address. */ +writel ((mac->mac_addr[0 ] <<0 ) + (mac->mac_addr[1 ] <<8 ), + comm->l2sw_reg_base +L2SW_W_MAC_15_0 ); +writel ((mac->mac_addr[2 ] <<0 ) + (mac->mac_addr[3 ] <<8 ) + + (mac->mac_addr[4 ] <<16 ) + (mac->mac_addr[5 ] <<24 ), + comm->l2sw_reg_base +L2SW_W_MAC_47_16 ); + +/* Set learn port = cpu_port, aging = 1 */
drivers/net/ethernet/sunplus/spl2sw_mac.c line 67
Quoted 10 lines
drivers/net/ethernet/sunplus/spl2sw_mac.c new file +10
-0+ reg =MAC_W_CPU_PORT_0 |FIELD_PREP (MAC_W_VID , mac->vlan_id) | +FIELD_PREP (MAC_W_AGE ,1 ) |MAC_W_MAC_CMD ; +writel (reg, comm->l2sw_reg_base +L2SW_WT_MAC_AD0 ); + +/* Wait for completing. */ +do { + reg =readl (comm->l2sw_reg_base +L2SW_WT_MAC_AD0 ); +ndelay (10 ); +netdev_dbg (mac->ndev,"wt_mac_ad0 = %08x\n" , reg); + }while (!(reg &MAC_W_MAC_DONE ));
linux/iopoll.h
Quoted 23 lines
drivers/net/ethernet/sunplus/spl2sw_mac.c new file +23
-0+ +netdev_dbg (mac->ndev,"mac_ad0 = %08x, mac_ad = %08x%04x\n" , +readl (comm->l2sw_reg_base +L2SW_WT_MAC_AD0 ), + (u32 )FIELD_GET (MAC_W_MAC_47_16 , +readl (comm->l2sw_reg_base +L2SW_W_MAC_47_16 )), + (u32 )FIELD_GET (MAC_W_MAC_15_0 , +readl (comm->l2sw_reg_base +L2SW_W_MAC_15_0 ))); +} + +void spl2sw_mac_addr_del (struct spl2sw_mac *mac) +{ +struct spl2sw_common *comm = mac->comm; +u32 reg; + +/* Write 6-octet MAC address. */ +writel ((mac->mac_addr[0 ] <<0 ) + (mac->mac_addr[1 ] <<8 ), + comm->l2sw_reg_base +L2SW_W_MAC_15_0 ); +writel ((mac->mac_addr[2 ] <<0 ) + (mac->mac_addr[3 ] <<8 ) + + (mac->mac_addr[4 ] <<16 ) + (mac->mac_addr[5 ] <<24 ), + comm->l2sw_reg_base +L2SW_W_MAC_47_16 ); + +/* Set learn port = lan_port0 and aging = 0 +* to wipe (age) out the entry.
drivers/net/ethernet/sunplus/spl2sw_mac.c line 100
Quoted 10 lines
drivers/net/ethernet/sunplus/spl2sw_mac.c new file +10
-0+*/ + reg =MAC_W_LAN_PORT_0 |FIELD_PREP (MAC_W_VID , mac->vlan_id) |MAC_W_MAC_CMD ; +writel (reg, comm->l2sw_reg_base +L2SW_WT_MAC_AD0 ); + +/* Wait for completing. */ +do { + reg =readl (comm->l2sw_reg_base +L2SW_WT_MAC_AD0 ); +ndelay (10 ); +netdev_dbg (mac->ndev,"wt_mac_ad0 = %08x\n" , reg); + }while (!(reg &MAC_W_MAC_DONE ));
Here as well. Any where you need to wait for some sort of completion, it is best you use these helpers. They will also do a timeout, just in case the hardware dies.
drivers/net/ethernet/sunplus/spl2sw_mdio.c line 65
Quoted 11 lines
drivers/net/ethernet/sunplus/spl2sw_mdio.c new file +11
-0+static int spl2sw_mii_read (struct mii_bus *bus,int addr,int regnum) +{ +struct spl2sw_common *comm = bus->priv; +int ret; + +if (regnum &MII_ADDR_C45 ) +return -EOPNOTSUPP ; + + ret =spl2sw_mdio_access (comm,SPL2SW_MDIO_READ_CMD , addr, regnum,0 ); +if (ret <0 ) +return -EOPNOTSUPP ;
spl2sw_mdio_access() returns an error code, -ETIMEDOUT. So us it.
Quoted 7 lines
drivers/net/ethernet/sunplus/spl2sw_mdio.c new file +7
-0+u32 spl2sw_mdio_init (struct spl2sw_common *comm) +{ +struct mii_bus *mii_bus; +int ret; + + mii_bus =devm_mdiobus_alloc (&comm->pdev->dev); +if (!mii_bus)
drivers/net/ethernet/sunplus/spl2sw_mdio.c line 101
Quoted 10 lines
drivers/net/ethernet/sunplus/spl2sw_mdio.c new file +10
-0+return -ENOMEM ; + + mii_bus->name ="sunplus_mii_bus" ; + mii_bus->parent = &comm->pdev->dev; + mii_bus->priv = comm; + mii_bus->read = spl2sw_mii_read; + mii_bus->write = spl2sw_mii_write; +snprintf (mii_bus->id,MII_BUS_ID_SIZE ,"%s-mii" ,dev_name (&comm->pdev->dev)); + + ret =of_mdiobus_register (mii_bus, comm->mdio_node);
Here you should be looking into the device tree to find the mdio node and passing it.
Quoted 16 lines
drivers/net/ethernet/sunplus/spl2sw_phy.c new file +15
-0+if (ret) { +dev_err (&comm->pdev->dev,"Failed to register mdiobus!\n" ); +return ret; + } + + comm->mii_bus = mii_bus; +return ret; +} +int spl2sw_phy_connect (struct spl2sw_common *comm) +{ +struct phy_device *phydev; +struct net_device *ndev; +struct spl2sw_mac *mac; +int i; +
drivers/net/ethernet/sunplus/spl2sw_phy.c line 67
Quoted 10 lines
drivers/net/ethernet/sunplus/spl2sw_phy.c new file +10
-0+for (i =0 ; i <MAX_NETDEV_NUM ; i++) +if (comm->ndev[i]) { + ndev = comm->ndev[i]; + mac =netdev_priv (ndev); + phydev =of_phy_connect (ndev, mac->phy_node, spl2sw_mii_link_change, +0 , mac->phy_mode); +if (!phydev) +return -ENODEV ; + +linkmode_copy (phydev->advertising, phydev->supported);
There should not be any need to do this.
drivers/net/ethernet/sunplus/spl2sw_phy.c line 70
Quoted 3 lines
drivers/net/ethernet/sunplus/spl2sw_phy.c new file +3
-0+ +/* Enable polling mode */ + phydev->irq =PHY_POLL ;
And that should be the default, so no need to set it.
drivers/net/ethernet/sunplus/spl2sw_desc.c line 163
Quoted 4 lines
drivers/net/ethernet/sunplus/spl2sw_desc.c new file +4
-0+ } + +return 0 ; +}
This is looking a lot better.
Andrew
RE: [PATCH net-next v3 2/2] net: ethernet: Add driver for Sunplus SP7021
Hi Andrew,
Thank you very much for your review.
Quoted 20 lines
Quoted 20 lines
+++
b/drivers/net/ethernet/sunplus/spl2sw_define.hdrivers/net/ethernet/sunplus/spl2sw_define.h new file +18
-0@@ -0,0 +1,301 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright Sunplus Technology Co., Ltd. +* All rights reserved. +*/ + +#ifndef __SPL2SW_DEFINE_H__ +#define __SPL2SW_DEFINE_H__ + +#include <linux/module.h> +#include <linux/errno.h> +#include <linux/types.h> +#include <linux/interrupt.h> +#include <linux/netdevice.h> +#include <linux/etherdevice.h> +#include <linux/skbuff.h> +#include <linux/ethtool.h> +#include <linux/platform_device.h> +#include <linux/phy.h>
Quoted 8 lines
drivers/net/ethernet/sunplus/spl2sw_define.h line 24
Quoted 6 lines
drivers/net/ethernet/sunplus/spl2sw_define.h new file +6
-0+#include <linux/mii.h> +#include <linux/io.h> +#include <linux/dma-mapping.h> +#include <linux/of_address.h> +#include <linux/of_mdio.h> +#include <linux/bitfield.h> Please put these in the .c file, and only include those that are needed in each .c file.
Yes, I'll move all "#include ..." to .c files and
remove unnecessary inclusions next patch.
Quoted 21 lines
Quoted 7 lines
drivers/net/ethernet/sunplus/spl2sw_desc.c new file +7
-0+int spl2sw_rx_descs_init (struct spl2sw_common *comm) { +struct spl2sw_skb_info *rx_skbinfo; +struct spl2sw_mac_desc *rx_desc; +struct sk_buff *skb; +u32 i, j; + +for (i =0 ; i <RX_DESC_QUEUE_NUM ; i++) {drivers/net/ethernet/sunplus/spl2sw_desc.c
Quoted 10 lines
drivers/net/ethernet/sunplus/spl2sw_desc.c new file +10
-0+ comm->rx_skb_info[i] =kcalloc (comm->rx_desc_num[i],sizeof (*rx_skbinfo), +GFP_KERNEL |GFP_DMA ); +if (!comm->rx_skb_info[i]) + goto mem_alloc_fail; + + rx_skbinfo = comm->rx_skb_info[i]; + rx_desc = comm->rx_desc[i]; +for (j =0 ; j < comm->rx_desc_num[i]; j++) { + skb =__dev_alloc_skb (comm->rx_desc_buff_size,GFP_KERNEL | +GFP_DMA );I generally don't look to closely at buffer handling in drivers. But the __ caught my eye. There is a comment:
Quoted 4 lines
/* legacy helper around
__netdev_alloc_skb()*/Since this is legacy, you probably should not be using it. I don't know what you should be using though.
__netdev_alloc_skb() is used to set gfp_flags to GFP_DMA or GFP_ATOMIC.
I'll replace __dev_alloc_skb() with dev_alloc_skb(). I'll replace __napi_schedule() with napi_schedule(). I'll review dev_kfree_skb() and dev_kfree_skb_irq().
I found many drivers still use __skb_put().
Should I replace it with skb_put()?
Quoted 27 lines
Quoted 27 lines
drivers/net/ethernet/sunplus/spl2sw_driver.c new file +27
-0+static u32 spl2sw_init_netdev (struct platform_device *pdev,int eth_no, +struct net_device **r_ndev) +{ +struct net_device *ndev; +struct spl2sw_mac *mac; +char *m_addr_name; +ssize_t otp_l =0 ; +char *otp_v; +int ret; + + m_addr_name = (eth_no ==0 ) ?"mac_addr0" :"mac_addr1" ; + +/* Allocate the devices, and also allocate spl2sw_mac, +* we can get it by netdev_priv(). +*/ + ndev =devm_alloc_etherdev (&pdev->dev,sizeof (*mac)); +if (!ndev) { + *r_ndev =NULL ; +return -ENOMEM ; + } +SET_NETDEV_DEV (ndev, &pdev->dev); + ndev->netdev_ops = &netdev_ops; + + mac =netdev_priv (ndev); + mac->ndev = ndev; + +/* Get property 'mac-addr0' or 'mac-addr1' from dts. */
Quoted 8 lines
drivers/net/ethernet/sunplus/spl2sw_driver.c line 287
Quoted 5 lines
drivers/net/ethernet/sunplus/spl2sw_driver.c new file +5
-0+ otp_v =spl2sw_otp_read_mac (&pdev->dev, &otp_l, m_addr_name); +if (otp_l <ETH_ALEN ||IS_ERR_OR_NULL (otp_v)) { +dev_err (&pdev->dev,"OTP mac %s (len = %zd) is invalid, using default!\n" , + m_addr_name, otp_l); + otp_l =0 ;This is not actually an error, in that you keep going and use the default. So
dev_info()would be better, here and the other calls in this function.
I'll replace the dev_err() with dev_info() in this function next patch.
Quoted 28 lines
Quoted 28 lines
drivers/net/ethernet/sunplus/spl2sw_driver.c new file +28
-0+ }else { +/* Check if MAC address is valid or not. If not, copy from default. */ +ether_addr_copy (mac->mac_addr, otp_v); + +/* Byte order of Some samples are reversed. Convert byte order here. */ +spl2sw_check_mac_vendor_id_and_convert (mac->mac_addr); + +if (!is_valid_ether_addr (mac->mac_addr)) { +dev_err (&pdev->dev,"Invalid mac in OTP[%s] = %pM, use default!\n" , + m_addr_name, mac->mac_addr); + otp_l =0 ; + } + } +if (otp_l !=6 ) { +/* MAC address is invalid. Generate one using random number. */ +ether_addr_copy (mac->mac_addr, spl2sw_def_mac_addr); + mac->mac_addr[3 ] =get_random_int () %256 ; + mac->mac_addr[4 ] =get_random_int () %256 ; + mac->mac_addr[5 ] =get_random_int () %256 ; + } + +eth_hw_addr_set (ndev, mac->mac_addr); +dev_info (&pdev->dev,"HW Addr = %pM\n" , mac->mac_addr); + + ret =register_netdev (ndev); +if (ret) { +dev_err (&pdev->dev,"Failed to register net device \"%s\"!\n" , + ndev->name);
Quoted 8 lines
drivers/net/ethernet/sunplus/spl2sw_driver.c
Quoted 6 lines
drivers/net/ethernet/sunplus/spl2sw_driver.c new file +6
-0+free_netdev (ndev); + *r_ndev =NULL ; +return ret; + } +netdev_info (ndev,"Registered net device \"%s\" successfully.\n" , +ndev->name);
netdev_dbg().
Yes, I'll replace the netdev_info() with netdev_dbg() next patch.
Quoted 25 lines
Quoted 25 lines
drivers/net/ethernet/sunplus/spl2sw_driver.c new file +24
-0+ *r_ndev = ndev; +return 0 ; +} + +static int spl2sw_probe (struct platform_device *pdev) { +struct device_node *eth_ports_np; +struct device_node *port_np; +struct spl2sw_common *comm; +struct device_node *phy_np; +phy_interface_t phy_mode; +struct net_device *ndev; +struct spl2sw_mac *mac; +struct resource *rc; +int irq, i; +int ret; + +if (platform_get_drvdata (pdev)) +return -ENODEV ; + +/* Allocate memory for 'spl2sw_common' area. */ + comm =devm_kzalloc (&pdev->dev,sizeof (*comm),GFP_KERNEL ); +if (!comm) +return -ENOMEM ; + comm->pdev = pdev;
Quoted 8 lines
drivers/net/ethernet/sunplus/spl2sw_driver.c line 373
Quoted 6 lines
drivers/net/ethernet/sunplus/spl2sw_driver.c new file +6
-0+ +spin_lock_init (&comm->rx_lock); +spin_lock_init (&comm->tx_lock); +spin_lock_init (&comm->mdio_lock); + +/* Get memory resoruce "emac" from dts. */ resource
I'll fix the two typo 'resoruce' next patch.
Quoted 7 lines
Quoted 7 lines
drivers/net/ethernet/sunplus/spl2sw_driver.c new file +7
-0+/* Enable clock. */ +clk_prepare_enable (comm->clk); +udelay (1 ); + +reset_control_assert (comm->rstc); +udelay (1 ); +reset_control_deassert (comm->rstc);
Quoted 8 lines
drivers/net/ethernet/sunplus/spl2sw_driver.c line 438
Quoted 6 lines
drivers/net/ethernet/sunplus/spl2sw_driver.c new file +6
-0+udelay (1 ); + +/* Get child node ethernet-ports. */ + eth_ports_np =of_get_child_by_name (pdev->dev.of_node,"ethernet-ports" ); +if (!eth_ports_np) { +dev_err (&pdev->dev,"No ethernet-ports child node found!\n" );You should disable the clock before returning.
I'll add 'disable the clock' at exit of the function next patch.
Quoted 20 lines
Quoted 20 lines
drivers/net/ethernet/sunplus/spl2sw_driver.c new file +20
-0+return -ENODEV ; + } + +for (i =0 ; i <MAX_NETDEV_NUM ; i++) { +/* Get port@i of node ethernet-ports. */ + port_np =spl2sw_get_eth_child_node (eth_ports_np, i); +if (!port_np) +continue ; + +/* Get phy-mode. */ +if (of_get_phy_mode (port_np, &phy_mode)) { +dev_err (&pdev->dev,"Failed to get phy-mode property of port@%d!\n" , + i); +continue ; + } + +/* Get phy-handle. */ + phy_np =of_parse_phandle (port_np,"phy-handle" ,0 ); +if (!phy_np) { + dev_err(&pdev->dev, "Failed to get phy-handle property of port@%d!\n",
Quoted 8 lines
drivers/net/ethernet/sunplus/spl2sw_driver.c line 464
Quoted 6 lines
drivers/net/ethernet/sunplus/spl2sw_driver.c new file +6
-0+ i); +continue ; + } + +/* Get address of phy. */ +if (of_property_read_u32 (phy_np,"reg" , &comm->phy_addr[i])) {This does not appear to be used.
I'll remove "get address of phy" statements and also remove member phy_addr from 'struct spl2sw_commmon' next patch.
Quoted 11 lines
drivers/net/ethernet/sunplus/spl2sw_driver.c line 473
Quoted 9 lines
drivers/net/ethernet/sunplus/spl2sw_driver.c new file +9
-0+dev_err (&pdev->dev,"Failed to get reg property of phy node!\n" ); +continue ; + } + +if (comm->phy_addr[i] >=PHY_MAX_ADDR -1 ) { +dev_err (&pdev->dev,"Invalid phy address (reg = <%d>)!\n" , + comm->phy_addr[i]); +continue ; + }phylib should validate this.
I'll remove the whole if-statement next patch.
Quoted 11 lines
drivers/net/ethernet/sunplus/spl2sw_driver.c line 481
Quoted 8 lines
drivers/net/ethernet/sunplus/spl2sw_driver.c new file +8
-0+ +if (!comm->mdio_node) { + comm->mdio_node =of_get_parent (phy_np); +if (!comm->mdio_node) { +dev_err (&pdev->dev,"Failed to get mdio_node!\n" ); +return -ENODATA ; + } + }This does not look correct. The PHY could be on any MDIO bus. It does not have to be the bus of this device. There should not be any need to follow the pointer.
I'll remove the two 'if (!comm->mdio_node)' statements and also remove member mdio_node from 'struct spl2sw_common' next patch.
Quoted 4 lines
Quoted 4 lines
drivers/net/ethernet/sunplus/spl2sw_int.c new file +4
-0+static int spl2sw_bit_pos_to_port_num (int n) { +int i; + +for (i =0 ; i <MAX_NETDEV_NUM ; i++) {
Quoted 8 lines
drivers/net/ethernet/sunplus/spl2sw_int.c line 149
Quoted 5 lines
drivers/net/ethernet/sunplus/spl2sw_int.c new file +5
-0+if (n &1 ) +break ; + n >>=1 ; + } +return i;Look at the
ffs()helper. But sinceMAX_NETDEV_NUMis two, the compiler might be smart enough to unroll the loop and just use simple logic operations which could be faster.
I'll replace spl2sw_bit_pos_to_num(x) with (ffs(x) - 1) next patch.
Quoted 16 lines
Quoted 16 lines
drivers/net/ethernet/sunplus/spl2sw_mac.c new file +16
-0+void spl2sw_mac_addr_add (struct spl2sw_mac *mac) { +struct spl2sw_common *comm = mac->comm; +u32 reg; + +/* Write 6-octet MAC address. */ +writel ((mac->mac_addr[0 ] <<0 ) + (mac->mac_addr[1 ] <<8 ), + comm->l2sw_reg_base +L2SW_W_MAC_15_0 ); +writel ((mac->mac_addr[2 ] <<0 ) + (mac->mac_addr[3 ] <<8 ) + + (mac->mac_addr[4 ] <<16 ) + (mac->mac_addr[5 ] <<24 ), + comm->l2sw_reg_base +L2SW_W_MAC_47_16 ); + +/* Set learn port = cpu_port, aging = 1 */ + reg =MAC_W_CPU_PORT_0 |FIELD_PREP (MAC_W_VID , mac->vlan_id) | +FIELD_PREP (MAC_W_AGE ,1 ) |MAC_W_MAC_CMD ; +writel (reg, comm->l2sw_reg_base +L2SW_WT_MAC_AD0 ); +
Quoted 8 lines
drivers/net/ethernet/sunplus/spl2sw_mac.c line 67
Quoted 6 lines
drivers/net/ethernet/sunplus/spl2sw_mac.c new file +6
-0+/* Wait for completing. */ +do { + reg =readl (comm->l2sw_reg_base +L2SW_WT_MAC_AD0 ); +ndelay (10 ); +netdev_dbg (mac->ndev,"wt_mac_ad0 = %08x\n" , reg); + }while (!(reg &MAC_W_MAC_DONE ));
linux/iopoll.h
I'll use read_poll_timeout() to replace the while-loops next patch
Quoted 26 lines
Quoted 26 lines
drivers/net/ethernet/sunplus/spl2sw_mac.c new file +26
-0+ +netdev_dbg (mac->ndev,"mac_ad0 = %08x, mac_ad = %08x%04x\n" , +readl (comm->l2sw_reg_base +L2SW_WT_MAC_AD0 ), + (u32 )FIELD_GET (MAC_W_MAC_47_16 , +readl (comm->l2sw_reg_base +L2SW_W_MAC_47_16 )), + (u32 )FIELD_GET (MAC_W_MAC_15_0 , +readl (comm->l2sw_reg_base +L2SW_W_MAC_15_0 ))); } + +void spl2sw_mac_addr_del (struct spl2sw_mac *mac) { +struct spl2sw_common *comm = mac->comm; +u32 reg; + +/* Write 6-octet MAC address. */ +writel ((mac->mac_addr[0 ] <<0 ) + (mac->mac_addr[1 ] <<8 ), + comm->l2sw_reg_base +L2SW_W_MAC_15_0 ); +writel ((mac->mac_addr[2 ] <<0 ) + (mac->mac_addr[3 ] <<8 ) + + (mac->mac_addr[4 ] <<16 ) + (mac->mac_addr[5 ] <<24 ), + comm->l2sw_reg_base +L2SW_W_MAC_47_16 ); + +/* Set learn port = lan_port0 and aging = 0 +* to wipe (age) out the entry. +*/ + reg =MAC_W_LAN_PORT_0 |FIELD_PREP (MAC_W_VID , mac->vlan_id) |MAC_W_MAC_CMD ; +writel (reg, comm->l2sw_reg_base +L2SW_WT_MAC_AD0 ); + +/* Wait for completing. */
Quoted 8 lines
drivers/net/ethernet/sunplus/spl2sw_mac.c line 67
Quoted 5 lines
drivers/net/ethernet/sunplus/spl2sw_mac.c new file +5
-0+do { + reg =readl (comm->l2sw_reg_base +L2SW_WT_MAC_AD0 ); +ndelay (10 ); +netdev_dbg (mac->ndev,"wt_mac_ad0 = %08x\n" , reg); + }while (!(reg &MAC_W_MAC_DONE ));Here as well. Anywhere you need to wait for some sort of completion, it is best you use these helpers. They will also do a timeout, just in case the hardware dies.
I'll use read_poll_timeout() to replace the while-loops next patch. Totally, 5 while-loops will be modified in 'spl2sw_mac.c' next patch.
Quoted 5 lines
Quoted 5 lines
drivers/net/ethernet/sunplus/spl2sw_mdio.c new file +5
-0+static int spl2sw_mii_read (struct mii_bus *bus,int addr,int regnum) +{ +struct spl2sw_common *comm = bus->priv; +int ret; +
Quoted 8 lines
drivers/net/ethernet/sunplus/spl2sw_mdio.c line 65
Quoted 6 lines
drivers/net/ethernet/sunplus/spl2sw_mdio.c new file +6
-0+if (regnum &MII_ADDR_C45 ) +return -EOPNOTSUPP ; + + ret =spl2sw_mdio_access (comm,SPL2SW_MDIO_READ_CMD , addr, regnum,0 ); +if (ret <0 ) +return -EOPNOTSUPP ;
spl2sw_mdio_access()returns an error code,-ETIMEDOUT. So us it.
Yes, I'll use the 'return value' of spl2sw_mdio_access() next patch.
Quoted 11 lines
Quoted 11 lines
drivers/net/ethernet/sunplus/spl2sw_mdio.c new file +11
-0+u32 spl2sw_mdio_init (struct spl2sw_common *comm) { +struct mii_bus *mii_bus; +int ret; + + mii_bus =devm_mdiobus_alloc (&comm->pdev->dev); +if (!mii_bus) +return -ENOMEM ; + + mii_bus->name ="sunplus_mii_bus" ; + mii_bus->parent = &comm->pdev->dev; + mii_bus->priv = comm;
Quoted 8 lines
drivers/net/ethernet/sunplus/spl2sw_mdio.c line 101
Quoted 6 lines
drivers/net/ethernet/sunplus/spl2sw_mdio.c new file +6
-0+ mii_bus->read = spl2sw_mii_read; + mii_bus->write = spl2sw_mii_write; +snprintf (mii_bus->id,MII_BUS_ID_SIZE ,"%s-mii" , +dev_name (&comm->pdev->dev)); + + ret =of_mdiobus_register (mii_bus, comm->mdio_node);Here you should be looking into the device tree to find the mdio node and passing it.
Yes, I'll use of_get_child_by_name() to get mdio child node next patch.
Quoted 19 lines
Quoted 19 lines
drivers/net/ethernet/sunplus/spl2sw_phy.c new file +18
-0+if (ret) { +dev_err (&comm->pdev->dev,"Failed to register mdiobus!\n" ); +return ret; + } + + comm->mii_bus = mii_bus; +return ret; +} +int spl2sw_phy_connect (struct spl2sw_common *comm) { +struct phy_device *phydev; +struct net_device *ndev; +struct spl2sw_mac *mac; +int i; + +for (i =0 ; i <MAX_NETDEV_NUM ; i++) +if (comm->ndev[i]) { + ndev = comm->ndev[i]; + mac =netdev_priv (ndev);
Quoted 8 lines
drivers/net/ethernet/sunplus/spl2sw_phy.c line 67
Quoted 6 lines
drivers/net/ethernet/sunplus/spl2sw_phy.c new file +6
-0+ phydev =of_phy_connect (ndev, mac->phy_node, spl2sw_mii_link_change, +0 , mac->phy_mode); +if (!phydev) +return -ENODEV ; + +linkmode_copy (phydev->advertising, phydev->supported);There should not be any need to do this.
I'll remove the linkmode_copy(...) statement next patch.
I printed out the value of 'supported' and 'advertising'. 'supported' shows PHY device supports Pause and AsymPause (0x62cf). But 'advertising' shows PHY device does not support Pause or AsymPause (0x02cf). Is this correct?
How to let link partner know local node supports
Pause & AsymPause (flow control)?
Quoted 5 lines
drivers/net/ethernet/sunplus/spl2sw_phy.c line 70
Quoted 3 lines
drivers/net/ethernet/sunplus/spl2sw_phy.c new file +3
-0+ +/* Enable polling mode */ + phydev->irq =PHY_POLL ;And that should be the default, so no need to set it.
Yes, I'll remove the statements next patch.
Quoted 8 lines
drivers/net/ethernet/sunplus/spl2sw_desc.c line 163
Quoted 4 lines
drivers/net/ethernet/sunplus/spl2sw_desc.c new file +4
-0+ } + +return 0 ; +}This is looking a lot better.
Andrew
Can I ask a question?
Will mii_read() and mii_write() be called in interrupt context? Should I replace read_poll_timeout() with read_poll_timeout_atomic() in spl2sw_mdio_access()?
Best regards,
Wells
Re: [PATCH net-next v3 2/2] net: ethernet: Add driver for Sunplus SP7021
Quoted 8 lines
I printed out the value of 'supported' and 'advertising'. 'supported' shows PHY device supports Pause and AsymPause (
0x62cf). But 'advertising' shows PHY device does not support Pause or AsymPause (0x02cf). Is this correct?How to let link partner know local node supports
Pause & AsymPause (flow control)?
'supported' indicates that the PHY can do. It has the ability to advertise pause. But we don't automatically copy those bits into 'advertising' because we don't know if the MAC actually supports pause/asym pause.
The MAC driver needs to call phy_support_sym_pause() or phy_support_asym_pause() to let phylib know what it can do. phylib will then add the appropriate bits to 'advertising'.
Quoted 1 line
Will
mii_read()andmii_write()be called in interrupt context?
No. Only thread context, because it uses a mutex to prevent multiple accesses at the same time.
Andrew
RE: [PATCH net-next v3 2/2] net: ethernet: Add driver for Sunplus SP7021
Hi Andrew,
Thank you for explanation.
I'll add phy_support_asym_pause() after PHY connected next patch.
I found some drivers call phy_set_max_speed() to set PHY speed to 100M after PHY connected. Is that necessary? From 'supported', PHY supports 10M/100M already.
I also found some drivers call phy_start_aneg() after PHY started. Is that necessary? From status register of PHY, 'auto-nego' has completed.
Best regards,
Wells
Quoted 23 lines
Quoted 8 lines
I printed out the value of 'supported' and 'advertising'. 'supported' shows PHY device supports Pause and AsymPause (
0x62cf). But 'advertising' shows PHY device does not support Pause or AsymPause (0x02cf). Is this correct?How to let link partner know local node supports Pause & AsymPause (flow control)?
'supported' indicates that the PHY can do. It has the ability to advertise pause. But we don't automatically copy those bits into 'advertising' because we don't know if the MAC actually supports pause/asym pause.
The MAC driver needs to call
phy_support_sym_pause()orphy_support_asym_pause()to let phylib know what it can do. phylib will then add the appropriate bits to 'advertising'.Quoted 1 line
Will
mii_read()andmii_write()be called in interrupt context?No. Only thread context, because it uses a mutex to prevent multiple accesses at the same time.
Andrew
Re: [PATCH net-next v3 2/2] net: ethernet: Add driver for Sunplus SP7021
Quoted 10 lines · Wells Lu 呂芳騰
Hi Andrew,
Thank you for explanation.
I'll add
phy_support_asym_pause()after PHY connected next patch.I found some drivers call
phy_set_max_speed()to set PHY speed to 100M after PHY connected. Is that necessary?From 'supported', PHY supports 10M/100M already.
You need phy_set_max_speed() when it is possible to connect a 10/100 MAC to a 1G PHY. You sometime do this because a 1G PHY is cheaper than a 100M PHY. Unless limited, the PHY will advertise and could negotiate a 1G link, but the MAC could then not support it. If it is not physically possible to connect a 1G PHY to your MAC, you don't need to worry.
Quoted 1 line
I also found some drivers call
phy_start_aneg()after PHY started.
It is not needed.
Andrew
RE: [PATCH net-next v3 2/2] net: ethernet: Add driver for Sunplus SP7021
Hi Andrew,
Thank you for explanation.
Best regards,
Wells Lu
Quoted 21 lines
Quoted 10 lines
Hi Andrew,
Thank you for explanation.
I'll add
phy_support_asym_pause()after PHY connected next patch.I found some drivers call
phy_set_max_speed()to set PHY speed to 100M after PHY connected. Is that necessary?From 'supported', PHY supports 10M/100M already.
You need
phy_set_max_speed()when it is possible to connect a 10/100 MAC to a 1G PHY. You sometime do this because a 1G PHY is cheaper than a 100M PHY. Unless limited, the PHY will advertise and could negotiate a 1G link, but the MAC could then not support it. If it is not physically possible to connect a 1G PHY to your MAC, you don't need to worry.Quoted 1 line
I also found some drivers call
phy_start_aneg()after PHY started.It is not needed.
Andrew
Quoted 4 lines · Wells Lu
Sunplus SP7021 is an ARM Cortex A7 (4 cores) based SoC. It integrates many peripherals (ex: UART, I2C, SPI, SDIO, eMMC, USB, SD card and etc.) into a single chip. It is designed for industrial control applications.
The subject line is wrong again. This has nothing to do with a pin controller.
Andrew
Hi Andrew,
Sorry for wrong subject line. I did a wrong copy.
Best regards,
Wells Lu
Smart Computing Program Home Entertainment Business Unit Sunplus Technology Co., Ltd. 19, Innovation 1st Road, Science-based Industrial Park Hsin-Chu, Taiwan 300 TEL:886-3-5786005 ext. 2580
Quoted 8 lines
Quoted 4 lines
Sunplus SP7021 is an ARM Cortex A7 (4 cores) based SoC. It integrates many peripherals (ex: UART, I2C, SPI, SDIO, eMMC, USB, SD card and etc.) into a single chip. It is designed for industrial control applications.
The subject line is wrong again. This has nothing to do with a pin controller.
Andrew