Skip to contentSkip to conversation

This is a patch series for Ethernet driver of Sunplus SP7021 SoC.

PATCH Superseded Wells Lu 5 participants 10 messages Dec 7, 2021 – Dec 14, 2021

Subsystems (4)

v4 of 11 Superseded Latest is v11 →

lore
Share & tools
lore

Wells Lu

author
#0 lore raw

v4 cover This is a patch series for Ethernet driver of 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       | 282 +++++++++
 drivers/net/ethernet/sunplus/spl2sw_desc.c         | 226 ++++++++
 drivers/net/ethernet/sunplus/spl2sw_desc.h         |  19 +
 drivers/net/ethernet/sunplus/spl2sw_driver.c       | 629 +++++++++++++++++++++
 drivers/net/ethernet/sunplus/spl2sw_driver.h       |  12 +
 drivers/net/ethernet/sunplus/spl2sw_int.c          | 253 +++++++++
 drivers/net/ethernet/sunplus/spl2sw_int.h          |  13 +
 drivers/net/ethernet/sunplus/spl2sw_mac.c          | 353 ++++++++++++
 drivers/net/ethernet/sunplus/spl2sw_mac.h          |  19 +
 drivers/net/ethernet/sunplus/spl2sw_mdio.c         | 126 +++++
 drivers/net/ethernet/sunplus/spl2sw_mdio.h         |  12 +
 drivers/net/ethernet/sunplus/spl2sw_phy.c          |  92 +++
 drivers/net/ethernet/sunplus/spl2sw_phy.h          |  12 +
 drivers/net/ethernet/sunplus/spl2sw_register.h     |  94 +++
 20 files changed, 2366 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
author
#1 lore raw

PATCH v4 1/2 devicetree: bindings: net: Add bindings doc for Sunplus SP7021.

Add bindings documentation for Sunplus SP7021.

---
Changes in v4
- Addressed all comments from Mr. Andrew Lunn.
- Moved properties 'nvmem-cells' and 'nvmem-cell-names' to port of ethernet-ports.
- Changed value of property 'nvmem-cell-names' to "mac-address".

 .../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
new file mode 100644
index 0000000..efc987f
@@ -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
+
+  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
+
+          nvmem-cells:
+            items:
+              - description: nvmem cell address of MAC address
+
+          nvmem-cell-names:
+            description: names corresponding to the nvmem cells
+            items:
+              - const: mac-address
+
+        required:
+          - reg
+          - phy-handle
+          - phy-mode
+          - nvmem-cells
+          - nvmem-cell-names
+
+  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
+  - 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";
+
+        ethernet-ports {
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            port@0 {
+                reg = <0>;
+                phy-handle = <&eth_phy0>;
+                phy-mode = "rmii";
+                nvmem-cells = <&mac_addr0>;
+                nvmem-cell-names = "mac-address";
+            };
+
+            port@1 {
+                reg = <1>;
+                phy-handle = <&eth_phy1>;
+                phy-mode = "rmii";
+                nvmem-cells = <&mac_addr1>;
+                nvmem-cell-names = "mac-address";
+            };
+        };
+
+        mdio {
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            eth_phy0: ethernet-phy@0 {
+                reg = <0>;
+            };
+
+            eth_phy1: ethernet-phy@1 {
+                reg = <1>;
+            };
+        };
+    };
+...
MAINTAINERS +7 -0
index 0dc08cd..5b1ef9d 100644
@@ -18245,6 +18245,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
author
#6 lore raw

PATCH v4 2/2 net: ethernet: Add driver for Sunplus SP7021

In reply to Wells Lu

Add driver for Sunplus SP7021 SoC.

---
Changes in v4
- Addressed all comments from Mr. Andrew Lunn.
- Get nvmem-cell of mac-address from port of ethernet-ports.
- Moved all '#include ..." from .h files to .c files.
Removed unnecessary '#include <linux/...>'.
- Reviewed usage of functions with prefix '__'.
- Replaced __dev_alloc_skb() with netdev_alloc_skb().
- Repalced __skb_put() with skb_put().
- Replaced __napi_schedule() with napi_schedule().
- Removed __skb_reserve().
- Replaced dev_kfree_skb() with dev_kfree_skb_any().
- Removed 'get PHY address' in probe function.
- Removed 'get mdio node' in probe function.
Use of_get_child_by_name to get mdio node in spl2sw_mdio_init().
- Use read-poll-timeout() to replace 5 while-loops in 'spl2sw_mac.c'
- Others
- Fixed an 'auto build test' warning Reported-by: kernel test robot <[email protected]>
- Removed unnecessary variable 'mac' in functions spl2sw_rx_poll() and spl2sw_tx_poll().

 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   | 282 +++++++++++
 drivers/net/ethernet/sunplus/spl2sw_desc.c     | 226 +++++++++
 drivers/net/ethernet/sunplus/spl2sw_desc.h     |  19 +
 drivers/net/ethernet/sunplus/spl2sw_driver.c   | 629 +++++++++++++++++++++++++
 drivers/net/ethernet/sunplus/spl2sw_driver.h   |  12 +
 drivers/net/ethernet/sunplus/spl2sw_int.c      | 253 ++++++++++
 drivers/net/ethernet/sunplus/spl2sw_int.h      |  13 +
 drivers/net/ethernet/sunplus/spl2sw_mac.c      | 353 ++++++++++++++
 drivers/net/ethernet/sunplus/spl2sw_mac.h      |  19 +
 drivers/net/ethernet/sunplus/spl2sw_mdio.c     | 126 +++++
 drivers/net/ethernet/sunplus/spl2sw_mdio.h     |  12 +
 drivers/net/ethernet/sunplus/spl2sw_phy.c      |  92 ++++
 drivers/net/ethernet/sunplus/spl2sw_phy.h      |  12 +
 drivers/net/ethernet/sunplus/spl2sw_register.h |  94 ++++
 19 files changed, 2187 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
index 5b1ef9d..49950b2 100644
@@ -18251,6 +18251,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
index 027cbac..909e854 100644
@@ -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
index 33d30b6..b5350c8 100644
@@ -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
new file mode 100644
index 0000000..5af2c5b
@@ -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
new file mode 100644
index 0000000..ef7d7d0
@@ -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 +282 -0

282 lines not on this page · raw message

drivers/net/ethernet/sunplus/spl2sw_desc.c new file +226 -0

226 lines not on this page · raw message

drivers/net/ethernet/sunplus/spl2sw_desc.h new file +19 -0
new file mode 100644
index 0000000..f04e2d8
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright Sunplus Technology Co., Ltd.
+ *       All rights reserved.
+ */
+
+#ifndef __SPL2SW_DESC_H__
+#define __SPL2SW_DESC_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 +629 -0

629 lines not on this page · raw message

drivers/net/ethernet/sunplus/spl2sw_driver.h new file +12 -0
new file mode 100644
index 0000000..5f177b3
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright Sunplus Technology Co., Ltd.
+ *       All rights reserved.
+ */
+
+#ifndef __SPL2SW_DRIVER_H__
+#define __SPL2SW_DRIVER_H__
+
+#define SPL2SW_RX_NAPI_WEIGHT	16
+#define SPL2SW_TX_NAPI_WEIGHT	16
+
+#endif
drivers/net/ethernet/sunplus/spl2sw_int.c new file +253 -0

253 lines not on this page · raw message

drivers/net/ethernet/sunplus/spl2sw_int.h new file +13 -0
new file mode 100644
index 0000000..64f6f25
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright Sunplus Technology Co., Ltd.
+ *       All rights reserved.
+ */
+
+#ifndef __SPL2SW_INT_H__
+#define __SPL2SW_INT_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 +353 -0

353 lines not on this page · raw message

drivers/net/ethernet/sunplus/spl2sw_mac.h new file +19 -0
new file mode 100644
index 0000000..04b6296
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright Sunplus Technology Co., Ltd.
+ *       All rights reserved.
+ */
+
+#ifndef __SPL2SW_MAC_H__
+#define __SPL2SW_MAC_H__
+
+void spl2sw_mac_hw_stop(struct spl2sw_common *comm);
+void spl2sw_mac_hw_start(struct spl2sw_common *comm);
+int  spl2sw_mac_addr_add(struct spl2sw_mac *mac);
+int  spl2sw_mac_addr_del(struct spl2sw_mac *mac);
+int  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 +126 -0

126 lines not on this page · raw message

drivers/net/ethernet/sunplus/spl2sw_mdio.h new file +12 -0
new file mode 100644
index 0000000..8a24c9c
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright Sunplus Technology Co., Ltd.
+ *       All rights reserved.
+ */
+
+#ifndef __SPL2SW_MDIO_H__
+#define __SPL2SW_MDIO_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 +92 -0

92 lines not on this page · raw message

drivers/net/ethernet/sunplus/spl2sw_phy.h new file +12 -0
new file mode 100644
index 0000000..3d051a2
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright Sunplus Technology Co., Ltd.
+ *       All rights reserved.
+ */
+
+#ifndef __SPL2SW_PHY_H__
+#define __SPL2SW_PHY_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 +94 -0

94 lines not on this page · raw message

Signature · 1 line
2.7.4
maintainer
#7 lore raw

Re: [PATCH net-next v4 2/2] net: ethernet: Add driver for Sunplus SP7021

Quoted 3 lines · On Tue, 7 Dec 2021 16:06:59 +0800 Wells Lu wrote:

Add driver for Sunplus SP7021 SoC.

clang points out:

drivers/net/ethernet/sunplus/spl2sw_driver.c:223:65: warning: result of comparison of constant 188 with expression of type 'char' is always true [-Wtautological-constant-out-of-range-compare]

            (mac_addr[0] != 0xFC || mac_addr[1] != 0x4B || mac_addr[2] != 0xBC)) {
                                                           ~~~~~~~~~~~ ^  ~~~~
drivers/net/ethernet/sunplus/spl2sw_driver.c:223:19: warning: result of comparison of constant 252 with expression of type 'char' is always true [-Wtautological-constant-out-of-range-compare]
            (mac_addr[0] != 0xFC || mac_addr[1] != 0x4B || mac_addr[2] != 0xBC)) {
             ~~~~~~~~~~~ ^  ~~~~
drivers/net/ethernet/sunplus/spl2sw_driver.c:222:64: warning: result of comparison of constant 188 with expression of type 'char' is always false [-Wtautological-constant-out-of-range-compare]
        if (mac_addr[5] == 0xFC && mac_addr[4] == 0x4B && mac_addr[3] == 0xBC &&
                                                          ~~~~~~~~~~~ ^  ~~~~
drivers/net/ethernet/sunplus/spl2sw_driver.c:222:18: warning: result of comparison of constant 252 with expression of type 'char' is always false [-Wtautological-constant-out-of-range-compare]
        if (mac_addr[5] == 0xFC && mac_addr[4] == 0x4B && mac_addr[3] == 0xBC &&
            ~~~~~~~~~~~ ^  ~~~~
#8 lore raw

RE: [PATCH net-next v4 2/2] net: ethernet: Add driver for Sunplus SP7021

Hi Jakub,

Thank you for review.

I'll fix the warnings reported from clang next patch.

Best regards,
Wells Lu

Quoted 27 lines · On Tue, 7 Dec 2021 16:06:59 +0800 Wells Lu wrote:
Quoted 3 lines

Add driver for Sunplus SP7021 SoC.

clang points out:

drivers/net/ethernet/sunplus/spl2sw_driver.c:223:65: warning: result of comparison of constant 188 with expression of type 'char' is always true [-Wtautological-constant-out-of-range-compare]

            (mac_addr[0] != 0xFC || mac_addr[1] != 0x4B || mac_addr[2] != 0xBC)) {
                                                           ~~~~~~~~~~~ ^  ~~~~
drivers/net/ethernet/sunplus/spl2sw_driver.c:223:19: warning: result of comparison of
constant 252 with expression of type 'char' is always true
[-Wtautological-constant-out-of-range-compare]
            (mac_addr[0] != 0xFC || mac_addr[1] != 0x4B || mac_addr[2] != 0xBC)) {
             ~~~~~~~~~~~ ^  ~~~~
drivers/net/ethernet/sunplus/spl2sw_driver.c:222:64: warning: result of comparison of
constant 188 with expression of type 'char' is always false
[-Wtautological-constant-out-of-range-compare]
        if (mac_addr[5] == 0xFC && mac_addr[4] == 0x4B && mac_addr[3] == 0xBC &&
                                                          ~~~~~~~~~~~ ^  ~~~~
drivers/net/ethernet/sunplus/spl2sw_driver.c:222:18: warning: result of comparison of
constant 252 with expression of type 'char' is always false
[-Wtautological-constant-out-of-range-compare]
        if (mac_addr[5] == 0xFC && mac_addr[4] == 0x4B && mac_addr[3] == 0xBC &&
            ~~~~~~~~~~~ ^  ~~~~
Reviewed-by on v4 2/2
#9 lore raw

Re: [PATCH net-next v4 2/2] net: ethernet: Add driver for Sunplus SP7021

In reply to Wells Lu
Quoted 1 line · Wells Lu

Add driver for Sunplus SP7021 SoC.

I reviewed phy, mdio, ethtool. That all looks good.

I did not look at any of the packet transfer etc.

Andrew

maintainer
#2 lore raw

Re: [PATCH net-next v4 1/2] devicetree: bindings: net: Add bindings doc for Sunplus SP7021.

In reply to Wells Lu
Quoted 43 lines · Wells Lu

Add bindings documentation for Sunplus SP7021.

---
Changes in v4
- Addressed all comments from Mr. Andrew Lunn.
- Moved properties 'nvmem-cells' and 'nvmem-cell-names' to port of ethernet-ports.
- Changed value of property 'nvmem-cell-names' to "mac-address".

 .../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 +23 -0
new file mode 100644
index 0000000..efc987f
@@ -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

Documentation/devicetree/bindings/net/sunplus,sp7021-emac.yaml line 33

Quoted 10 lines
Documentation/devicetree/bindings/net/sunplus,sp7021-emac.yaml new file +10 -0
+      - description: the MOON5 registers
+
+  reg-names:
+    items:
+      - const: emac
+      - const: moon5
+
+  interrupts:
+    description: |
+      Contains number and type of interrupt. Number should be 66.

Drop. That's every 'interrupts' and the exact number is outside the scope of the binding.

Quoted 43 lines
Documentation/devicetree/bindings/net/sunplus,sp7021-emac.yaml new file +43 -0
+      Type should be high-level trigger.
+    maxItems: 1
+
+  clocks:
+    maxItems: 1
+
+  resets:
+    maxItems: 1
+
+  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
+
+          nvmem-cells:
+            items:
+              - description: nvmem cell address of MAC address
+
+          nvmem-cell-names:
+            description: names corresponding to the nvmem cells
+            items:

Documentation/devicetree/bindings/net/sunplus,sp7021-emac.yaml line 86

Quoted 10 lines
Documentation/devicetree/bindings/net/sunplus,sp7021-emac.yaml new file +10 -0
+              - const: mac-address
+
+        required:
+          - reg
+          - phy-handle
+          - phy-mode
+          - nvmem-cells
+          - nvmem-cell-names
+
+  mdio:

Just need:

$ref: mdio.yaml#
unevaluatedProperties: false

and drop the rest.

Quoted 31 lines
Documentation/devicetree/bindings/net/sunplus,sp7021-emac.yaml new file +31 -0
+    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

Documentation/devicetree/bindings/net/sunplus,sp7021-emac.yaml line 127

Quoted 10 lines
Documentation/devicetree/bindings/net/sunplus,sp7021-emac.yaml new file +10 -0
+  - resets
+  - pinctrl-0
+  - pinctrl-names
+  - ethernet-ports
+  - mdio
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+    emac: emac@9c108000 {

ethernet@9c108000 {

Quoted 67 lines
Documentation/devicetree/bindings/net/sunplus,sp7021-emac.yaml new file +45 -0
+        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";
+
+        ethernet-ports {
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            port@0 {
+                reg = <0>;
+                phy-handle = <&eth_phy0>;
+                phy-mode = "rmii";
+                nvmem-cells = <&mac_addr0>;
+                nvmem-cell-names = "mac-address";
+            };
+
+            port@1 {
+                reg = <1>;
+                phy-handle = <&eth_phy1>;
+                phy-mode = "rmii";
+                nvmem-cells = <&mac_addr1>;
+                nvmem-cell-names = "mac-address";
+            };
+        };
+
+        mdio {
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            eth_phy0: ethernet-phy@0 {
+                reg = <0>;
+            };
+
+            eth_phy1: ethernet-phy@1 {
+                reg = <1>;
+            };
+        };
+    };
+...
MAINTAINERS +7 -0
index 0dc08cd..5b1ef9d 100644
@@ -18245,6 +18245,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
author
#3 lore raw

Re: [PATCH net-next v4 1/2] devicetree: bindings: net: Add bindings doc for Sunplus SP7021.

Hi Rob,

Thank you very much for your review.
Please see my replies below:

Quoted 2 lines

Add bindings documentation for Sunplus SP7021.

[...]

Quoted 7 lines

Documentation/devicetree/bindings/net/sunplus,sp7021-emac.yaml line 33

Quoted 4 lines
Documentation/devicetree/bindings/net/sunplus,sp7021-emac.yaml new file +4 -0
+
+  interrupts:
+    description: |
+      Contains number and type of interrupt. Number should be 66.

Drop. That's every 'interrupts' and the exact number is outside the scope of the binding.

Yes, I'll drop the descriptions next patch.
interrupts property will be:

interrupts:
maxItems: 1

[...]

Quoted 9 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+  mdio:

Just need:

$ref: mdio.yaml#
unevaluatedProperties: false

and drop the rest.

Yes, I'll modify mdio node next patch.
mdio node will be:

mdio:
$ref: mdio.yaml#
unevaluatedProperties: false

Quoted 11 lines
Quoted 11 lines
Documentation/devicetree/bindings/net/sunplus,sp7021-emac.yaml new file +11 -0
+    type: object
+    description: external MDIO Bus
+
+    properties:
+      "#address-cells":
+        const: 1
+
+      "#size-cells":
+        const: 0
+
+    patternProperties:
Quoted 8 lines

Documentation/devicetree/bindings/net/sunplus,sp7021-emac.yaml line 105

Quoted 8 lines
Documentation/devicetree/bindings/net/sunplus,sp7021-emac.yaml new file +8 -0
+      "^ethernet-phy@[0-9a-f]+$":
+        type: object
+        description: external PHY node
+
+        properties:
+          reg:
+            minimum: 0
+            maximum: 30

Can I limit value of 'reg' to no more than 30?

Quoted 6 lines
Quoted 6 lines
Documentation/devicetree/bindings/net/sunplus,sp7021-emac.yaml new file +6 -0
+
+        required:
+          - reg
+
+additionalProperties: false
+

[...]

Quoted 6 lines

Documentation/devicetree/bindings/net/sunplus,sp7021-emac.yaml line 127

Quoted 4 lines
Documentation/devicetree/bindings/net/sunplus,sp7021-emac.yaml new file +4 -0
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+    emac: emac@9c108000 {

ethernet@9c108000 {

I'll modify it next patch.

[...]

Quoted 2 lines
Quoted 2 lines

2.7.4

Best regards,
Wells

maintainer
#4 lore raw

Re: [PATCH net-next v4 1/2] devicetree: bindings: net: Add bindings doc for Sunplus SP7021.

Quoted 56 lines · 呂芳騰

Hi Rob,

Thank you very much for your review.
Please see my replies below:

Quoted 2 lines

Add bindings documentation for Sunplus SP7021.

[...]

Quoted 7 lines

Documentation/devicetree/bindings/net/sunplus,sp7021-emac.yaml line 33

Quoted 4 lines
Documentation/devicetree/bindings/net/sunplus,sp7021-emac.yaml new file +4 -0
+
+  interrupts:
+    description: |
+      Contains number and type of interrupt. Number should be 66.

Drop. That's every 'interrupts' and the exact number is outside the scope of the binding.

Yes, I'll drop the descriptions next patch.
interrupts property will be:

interrupts:
maxItems: 1

[...]

Quoted 9 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+  mdio:

Just need:

$ref: mdio.yaml#
unevaluatedProperties: false

and drop the rest.

Yes, I'll modify mdio node next patch.
mdio node will be:

mdio:
$ref: mdio.yaml#
unevaluatedProperties: false

Quoted 13 lines
Quoted 13 lines
Documentation/devicetree/bindings/net/sunplus,sp7021-emac.yaml new file +13 -0
+    type: object
+    description: external MDIO Bus
+
+    properties:
+      "#address-cells":
+        const: 1
+
+      "#size-cells":
+        const: 0
+
+    patternProperties:
+      "^ethernet-phy@[0-9a-f]+$":
+        type: object
Quoted 8 lines
Quoted 6 lines

Documentation/devicetree/bindings/net/sunplus,sp7021-emac.yaml line 105

Quoted 6 lines
Documentation/devicetree/bindings/net/sunplus,sp7021-emac.yaml new file +6 -0
+        description: external PHY node
+
+        properties:
+          reg:
+            minimum: 0
+            maximum: 30

Can I limit value of 'reg' to no more than 30?

Isn't that the limit for any MDIO bus? I guess normally 31 is also valid? I'm not really sure it is worth adding just for that 1 possible value. Within the range of valid addresses, we can't ever validate that a DT has the correct address.

Rob

author
#5 lore raw

Re: [PATCH net-next v4 1/2] devicetree: bindings: net: Add bindings doc for Sunplus SP7021.

Hi Rob,

Thanks a lot for explanation.
I'll use default mdio node.

best regards,
Wells