This is a patch series for Ethernet driver of Sunplus SP7021 SoC.
Subsystems (4)
v9 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.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 | 141 +++++ MAINTAINERS | 8 + drivers/net/ethernet/Kconfig | 1 + drivers/net/ethernet/Makefile | 1 + drivers/net/ethernet/sunplus/Kconfig | 35 ++ drivers/net/ethernet/sunplus/Makefile | 6 + drivers/net/ethernet/sunplus/spl2sw_define.h | 270 ++++++++ drivers/net/ethernet/sunplus/spl2sw_desc.c | 228 +++++++ drivers/net/ethernet/sunplus/spl2sw_desc.h | 19 + drivers/net/ethernet/sunplus/spl2sw_driver.c | 577 ++++++++++++++++++ drivers/net/ethernet/sunplus/spl2sw_driver.h | 12 + drivers/net/ethernet/sunplus/spl2sw_int.c | 260 ++++++++ drivers/net/ethernet/sunplus/spl2sw_int.h | 13 + drivers/net/ethernet/sunplus/spl2sw_mac.c | 274 +++++++++ drivers/net/ethernet/sunplus/spl2sw_mac.h | 18 + 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 + .../net/ethernet/sunplus/spl2sw_register.h | 86 +++ 20 files changed, 2191 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.25.1
PATCH v9 1/2 devicetree: bindings: net: Add bindings doc for Sunplus SP7021.
Add bindings documentation for Sunplus SP7021 SoC.
---
Changes in v9
- None
.../bindings/net/sunplus,sp7021-emac.yaml | 141 ++++++++++++++++++ MAINTAINERS | 7 + 2 files changed, 148 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/sunplus,sp7021-emac.yaml
Documentation/devicetree/bindings/net/sunplus,sp7021-emac.yaml new file +141 -0
@@ -0,0 +1,141 @@ +# 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: + maxItems: 1 + + interrupts: + 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: + $ref: mdio.yaml# + unevaluatedProperties: false + +additionalProperties: false + +required: + - compatible + - reg + - interrupts + - clocks + - resets + - pinctrl-0 + - pinctrl-names + - ethernet-ports + - mdio + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + + ethernet@9c108000 { + compatible = "sunplus,sp7021-emac"; + reg = <0x9c108000 0x400>; + 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 = <ð_phy0>; + phy-mode = "rmii"; + nvmem-cells = <&mac_addr0>; + nvmem-cell-names = "mac-address"; + }; + + port@1 { + reg = <1>; + phy-handle = <ð_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
@@ -18888,6 +18888,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.atlassian.net/wiki/spaces/doc/overview +F: Documentation/devicetree/bindings/net/sunplus,sp7021-emac.yaml + SUNPLUS OCOTP DRIVER M: Vincent Shih <[email protected]> S: Maintained
Signature · 1 line
2.25.1
PATCH v9 2/2 net: ethernet: Add driver for Sunplus SP7021
In reply to Wells LuAdd driver for Sunplus SP7021 SoC.
---
Changes in v9
- Addressed comments of Mr. Jakub Kicinski.
- Fixed wrong coding which tries to unmap error map.
- Use "skb_padto()" to pad a skb if its length is less than ETH_ZLEN.
- Added a variable 'mapping' to store result of dma_map_single() so that we don't need
clear skbinfo->mapping on failure.
Moved some statements from before dma_map_single() to after success of dma_mapping_error() to simplify codes.
- Added error-handling for clk_prepare_enable().
- Use "eth_random_addr()" to generate locally administered (random) address on failure of reading it from nvmem.
- Pass "comm" as private data in devm_request_irq() function.
- Moved "register net-devices" to late spl2sw_probe() to avoid from potential crash.
- Removed "rx_lock" for spl2sw_rx_poll(). It is not necessary.
- Removed IP-checksum check when receiving a packet. It is not trusted by upper layer.
- Modified error-handling of allocating skb when receiving a packet.
- Take 'budget' into account in spl2sw_rx_poll() and spl2sw_tx_poll() functions.
- Added handling 'EPROBE_DEFER' error returned by nvmem function, spl2sw_nvmem_get_mac_address(). Adjusted delay time after reset_control_deassert(): udelay(1) --> usleep_range(1000, 2000) Hardware needs more time to stabilize in case of re-probing (after EPROBE_DEFER error).
- Replaced platform driver data 'ndev' with 'comm'.
MAINTAINERS | 1 + drivers/net/ethernet/Kconfig | 1 + drivers/net/ethernet/Makefile | 1 + drivers/net/ethernet/sunplus/Kconfig | 35 ++ drivers/net/ethernet/sunplus/Makefile | 6 + drivers/net/ethernet/sunplus/spl2sw_define.h | 270 ++++++++ drivers/net/ethernet/sunplus/spl2sw_desc.c | 228 +++++++ drivers/net/ethernet/sunplus/spl2sw_desc.h | 19 + drivers/net/ethernet/sunplus/spl2sw_driver.c | 577 ++++++++++++++++++ drivers/net/ethernet/sunplus/spl2sw_driver.h | 12 + drivers/net/ethernet/sunplus/spl2sw_int.c | 260 ++++++++ drivers/net/ethernet/sunplus/spl2sw_int.h | 13 + drivers/net/ethernet/sunplus/spl2sw_mac.c | 274 +++++++++ drivers/net/ethernet/sunplus/spl2sw_mac.h | 18 + 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 + .../net/ethernet/sunplus/spl2sw_register.h | 86 +++ 19 files changed, 2043 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
@@ -18894,6 +18894,7 @@ L: [email protected] S: Maintained W: https://sunplus.atlassian.net/wiki/spaces/doc/overview F: Documentation/devicetree/bindings/net/sunplus,sp7021-emac.yaml +F: drivers/net/ethernet/sunplus/ SUNPLUS OCOTP DRIVER M: Vincent Shih <[email protected]>
drivers/net/ethernet/Kconfig +1 -0
@@ -179,6 +179,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
@@ -90,6 +90,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 +35 -0
@@ -0,0 +1,35 @@ +# 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 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 +270 -0
270 lines not on this page · raw message
drivers/net/ethernet/sunplus/spl2sw_desc.c new file +228 -0
228 lines not on this page · raw message
drivers/net/ethernet/sunplus/spl2sw_desc.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_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 +577 -0
577 lines not on this page · raw message
drivers/net/ethernet/sunplus/spl2sw_driver.h new file +12 -0
@@ -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 +260 -0
260 lines not on this page · raw message
drivers/net/ethernet/sunplus/spl2sw_int.h new file +13 -0
@@ -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 +274 -0
274 lines not on this page · raw message
drivers/net/ethernet/sunplus/spl2sw_mac.h new file +18 -0
@@ -0,0 +1,18 @@ +/* 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); +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
@@ -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
@@ -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 +86 -0
86 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH net-next v9 2/2] net: ethernet: Add driver for Sunplus SP7021
Quoted 6 lines · On Mon, 25 Apr 2022 18:30:40 +0800 Wells Lu <[email protected]> wrote:
drivers/net/ethernet/sunplus/spl2sw_driver.h new file +0
-0
drivers/net/ethernet/sunplus/spl2sw_driver.h line 10
Quoted 10 lines
drivers/net/ethernet/sunplus/spl2sw_driver.h new file +10
-0@@ -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
Why define your own? there is NAPI_POLL_WEIGHT already defined in netdevice.h
Re: [PATCH net-next v9 2/2] net: ethernet: Add driver for Sunplus SP7021
In reply to Wells LuQuoted 178 lines · On Mon, 25 Apr 2022 18:30:40 +0800 Wells Lu <[email protected]> wrote:
drivers/net/ethernet/sunplus/spl2sw_int.c new file +178
-0+ +int spl2sw_rx_poll (struct napi_struct *napi,int budget) +{ + struct spl2sw_common *comm = container_of(napi, struct spl2sw_common, rx_napi); +struct spl2sw_mac_desc *desc, *h_desc; +struct net_device_stats *stats; +struct sk_buff *skb, *new_skb; +struct spl2sw_skb_info *sinfo; +int budget_left = budget; +u32 rx_pos, pkg_len; +u32 num, rx_count; +s32 queue; +u32 mask; +int port; +u32 cmd; + +/* Process high-priority queue and then low-priority queue. */ +for (queue =0 ; queue <RX_DESC_QUEUE_NUM ; queue++) { + rx_pos = comm->rx_pos[queue]; + rx_count = comm->rx_desc_num[queue]; + +for (num =0 ; num < rx_count && budget_left; num++) { + sinfo = comm->rx_skb_info[queue] + rx_pos; + desc = comm->rx_desc[queue] + rx_pos; + cmd = desc->cmd1; + +if (cmd &RXD_OWN ) +break ; + + port =FIELD_GET (RXD_PKT_SP , cmd); +if (port <MAX_NETDEV_NUM && comm->ndev[port]) + stats = &comm->ndev[port]->stats; +else + goto spl2sw_rx_poll_rec_err; + + pkg_len =FIELD_GET (RXD_PKT_LEN , cmd); +if (unlikely ((cmd &RXD_ERR_CODE ) || pkg_len <ETH_ZLEN +4 )) { + stats->rx_length_errors++; + stats->rx_dropped++; + goto spl2sw_rx_poll_rec_err; + } + +dma_unmap_single (&comm->pdev->dev, sinfo->mapping, + comm->rx_desc_buff_size,DMA_FROM_DEVICE ); + + skb = sinfo->skb; +skb_put (skb, pkg_len -4 );/* Minus FCS */ + skb->ip_summed =CHECKSUM_NONE ; + skb->protocol =eth_type_trans (skb, comm->ndev[port]); +netif_receive_skb (skb); + + stats->rx_packets++; + stats->rx_bytes += skb->len; + +/* Allocate a new skb for receiving. */ + new_skb =netdev_alloc_skb (NULL , comm->rx_desc_buff_size); +if (unlikely (!new_skb)) { + desc->cmd2 = (rx_pos == comm->rx_desc_num[queue] -1 ) ? +RXD_EOR :0 ; + sinfo->skb =NULL ; + sinfo->mapping =0 ; + desc->addr1 =0 ; + goto spl2sw_rx_poll_alloc_err; + } + + sinfo->mapping =dma_map_single (&comm->pdev->dev, new_skb->data, + comm->rx_desc_buff_size, +DMA_FROM_DEVICE ); +if (dma_mapping_error (&comm->pdev->dev, sinfo->mapping)) { +dev_kfree_skb_irq (new_skb); + desc->cmd2 = (rx_pos == comm->rx_desc_num[queue] -1 ) ? +RXD_EOR :0 ; + sinfo->skb =NULL ; + sinfo->mapping =0 ; + desc->addr1 =0 ; + goto spl2sw_rx_poll_alloc_err; + } + + sinfo->skb = new_skb; + desc->addr1 = sinfo->mapping; + +spl2sw_rx_poll_rec_err: + desc->cmd2 = (rx_pos == comm->rx_desc_num[queue] -1 ) ? +RXD_EOR | comm->rx_desc_buff_size : + comm->rx_desc_buff_size; + +wmb ();/* Set RXD_OWN after other fields are effective. */ + desc->cmd1 =RXD_OWN ; + +spl2sw_rx_poll_alloc_err: +/* Move rx_pos to next position */ + rx_pos = ((rx_pos +1 ) == comm->rx_desc_num[queue]) ?0 : rx_pos +1 ; + + budget_left--; + +/* If there are packets in high-priority queue, +* stop processing low-priority queue. +*/ +if (queue ==1 && !(h_desc->cmd1 &RXD_OWN )) +break ; + } + + comm->rx_pos[queue] = rx_pos; + +/* Save pointer to last rx descriptor of high-priority queue. */ +if (queue ==0 ) + h_desc = comm->rx_desc[queue] + rx_pos; + } + +wmb ();/* make sure settings are effective. */ + mask =readl (comm->l2sw_reg_base +L2SW_SW_INT_MASK_0 ); + mask &= ~MAC_INT_RX ; +writel (mask, comm->l2sw_reg_base +L2SW_SW_INT_MASK_0 ); + +napi_complete (napi); +return 0 ; +} + +int spl2sw_tx_poll (struct napi_struct *napi,int budget) +{ + struct spl2sw_common *comm = container_of(napi, struct spl2sw_common, tx_napi); +struct spl2sw_skb_info *skbinfo; +struct net_device_stats *stats; +int budget_left = budget; +u32 tx_done_pos; +u32 mask; +u32 cmd; +int i; + +spin_lock (&comm->tx_lock); + + tx_done_pos = comm->tx_done_pos; +while (((tx_done_pos != comm->tx_pos) || (comm->tx_desc_full ==1 )) && budget_left) { + cmd = comm->tx_desc[tx_done_pos].cmd1; +if (cmd &TXD_OWN ) +break ; + + skbinfo = &comm->tx_temp_skb_info[tx_done_pos]; +if (unlikely (!skbinfo->skb)) + goto spl2sw_tx_poll_next; + + i =ffs (FIELD_GET (TXD_VLAN , cmd)) -1 ; +if (i <MAX_NETDEV_NUM && comm->ndev[i]) + stats = &comm->ndev[i]->stats; +else + goto spl2sw_tx_poll_unmap; + +if (unlikely (cmd & (TXD_ERR_CODE ))) { + stats->tx_errors++; + }else { + stats->tx_packets++; + stats->tx_bytes += skbinfo->len; + } + +spl2sw_tx_poll_unmap: +dma_unmap_single (&comm->pdev->dev, skbinfo->mapping, skbinfo->len, +DMA_TO_DEVICE ); + skbinfo->mapping =0 ; +dev_kfree_skb_irq (skbinfo->skb); + skbinfo->skb =NULL ; + +spl2sw_tx_poll_next: +/* Move tx_done_pos to next position */ + tx_done_pos = ((tx_done_pos +1 ) ==TX_DESC_NUM ) ?0 : tx_done_pos +1 ; + +if (comm->tx_desc_full ==1 ) + comm->tx_desc_full =0 ; + + budget_left--; + } + + comm->tx_done_pos = tx_done_pos; +if (!comm->tx_desc_full) +for (i =0 ; i <MAX_NETDEV_NUM ; i++) +if (comm->ndev[i]) +if (netif_queue_stopped (comm->ndev[i])) +netif_wake_queue (comm->ndev[i]); +
drivers/net/ethernet/sunplus/spl2sw_int.c line 202
Quoted 10 lines
drivers/net/ethernet/sunplus/spl2sw_int.c new file +10
-0+spin_unlock (&comm->tx_lock); + +wmb ();/* make sure settings are effective. */ + mask =readl (comm->l2sw_reg_base +L2SW_SW_INT_MASK_0 ); + mask &= ~MAC_INT_TX ; +writel (mask, comm->l2sw_reg_base +L2SW_SW_INT_MASK_0 ); + +napi_complete (napi); +return 0 ; +}
This doesn't look like it is doing NAPI properly.
The driver is supposed to return the amount of packets processed. If budget is used, it should return budget.
RE: [PATCH net-next v9 2/2] net: ethernet: Add driver for Sunplus SP7021
In reply to Stephen HemmingerHi Stephen,
Quoted 11 lines
Quoted 11 lines
drivers/net/ethernet/sunplus/spl2sw_driver.h new file +4
-0@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright Sunplus Technology Co., Ltd. +* All rights reserved. +*/
Quoted 8 lines
drivers/net/ethernet/sunplus/spl2sw_driver.h line 10
Quoted 6 lines
drivers/net/ethernet/sunplus/spl2sw_driver.h new file +6
-0+ +#ifndef __SPL2SW_DRIVER_H__ +#define __SPL2SW_DRIVER_H__ + +#define SPL2SW_RX_NAPI_WEIGHT 16 +#define SPL2SW_TX_NAPI_WEIGHT 16Why define your own? there is
NAPI_POLL_WEIGHTalready defined innetdevice.h
I didn't know there is NAPI_POLL_WEIGHT defined in netdevice.h. I'll remove my own define and use it next patch.
Thank you for your review.
Best regards,
Wells
RE: [PATCH net-next v9 2/2] net: ethernet: Add driver for Sunplus SP7021
In reply to Stephen HemmingerHi Stephen,
Quoted 191 lines
Quoted 121 lines
drivers/net/ethernet/sunplus/spl2sw_int.c new file +121
-0+int spl2sw_rx_poll (struct napi_struct *napi,int budget) { + struct spl2sw_common *comm = container_of(napi, struct spl2sw_common, rx_napi); +struct spl2sw_mac_desc *desc, *h_desc; +struct net_device_stats *stats; +struct sk_buff *skb, *new_skb; +struct spl2sw_skb_info *sinfo; +int budget_left = budget; +u32 rx_pos, pkg_len; +u32 num, rx_count; +s32 queue; +u32 mask; +int port; +u32 cmd; + +/* Process high-priority queue and then low-priority queue. */ +for (queue =0 ; queue <RX_DESC_QUEUE_NUM ; queue++) { + rx_pos = comm->rx_pos[queue]; + rx_count = comm->rx_desc_num[queue]; + +for (num =0 ; num < rx_count && budget_left; num++) { + sinfo = comm->rx_skb_info[queue] + rx_pos; + desc = comm->rx_desc[queue] + rx_pos; + cmd = desc->cmd1; + +if (cmd &RXD_OWN ) +break ; + + port =FIELD_GET (RXD_PKT_SP , cmd); +if (port <MAX_NETDEV_NUM && comm->ndev[port]) + stats = &comm->ndev[port]->stats; +else + goto spl2sw_rx_poll_rec_err; + + pkg_len =FIELD_GET (RXD_PKT_LEN , cmd); +if (unlikely ((cmd &RXD_ERR_CODE ) || pkg_len <ETH_ZLEN +4 )) { + stats->rx_length_errors++; + stats->rx_dropped++; + goto spl2sw_rx_poll_rec_err; + } + +dma_unmap_single (&comm->pdev->dev, sinfo->mapping, + comm->rx_desc_buff_size,DMA_FROM_DEVICE ); + + skb = sinfo->skb; +skb_put (skb, pkg_len -4 );/* Minus FCS */ + skb->ip_summed =CHECKSUM_NONE ; + skb->protocol =eth_type_trans (skb, comm->ndev[port]); +netif_receive_skb (skb); + + stats->rx_packets++; + stats->rx_bytes += skb->len; + +/* Allocate a new skb for receiving. */ + new_skb =netdev_alloc_skb (NULL , comm->rx_desc_buff_size); +if (unlikely (!new_skb)) { + desc->cmd2 = (rx_pos == comm->rx_desc_num[queue] -1 ) ? +RXD_EOR :0 ; + sinfo->skb =NULL ; + sinfo->mapping =0 ; + desc->addr1 =0 ; + goto spl2sw_rx_poll_alloc_err; + } + + sinfo->mapping =dma_map_single (&comm->pdev->dev, new_skb->data, + comm->rx_desc_buff_size, +DMA_FROM_DEVICE ); +if (dma_mapping_error (&comm->pdev->dev, sinfo->mapping)) { +dev_kfree_skb_irq (new_skb); + desc->cmd2 = (rx_pos == comm->rx_desc_num[queue] -1 ) ? +RXD_EOR :0 ; + sinfo->skb =NULL ; + sinfo->mapping =0 ; + desc->addr1 =0 ; + goto spl2sw_rx_poll_alloc_err; + } + + sinfo->skb = new_skb; + desc->addr1 = sinfo->mapping; + +spl2sw_rx_poll_rec_err: + desc->cmd2 = (rx_pos == comm->rx_desc_num[queue] -1 ) ? +RXD_EOR | comm->rx_desc_buff_size : + comm->rx_desc_buff_size; + +wmb ();/* Set RXD_OWN after other fields are effective. */ + desc->cmd1 =RXD_OWN ; + +spl2sw_rx_poll_alloc_err: +/* Move rx_pos to next position */ + rx_pos = ((rx_pos +1 ) == comm->rx_desc_num[queue]) ?0 : rx_pos + +1 ; + + budget_left--; + +/* If there are packets in high-priority queue, +* stop processing low-priority queue. +*/ +if (queue ==1 && !(h_desc->cmd1 &RXD_OWN )) +break ; + } + + comm->rx_pos[queue] = rx_pos; + +/* Save pointer to last rx descriptor of high-priority queue. */ +if (queue ==0 ) + h_desc = comm->rx_desc[queue] + rx_pos; + } + +wmb ();/* make sure settings are effective. */ + mask =readl (comm->l2sw_reg_base +L2SW_SW_INT_MASK_0 ); + mask &= ~MAC_INT_RX ; +writel (mask, comm->l2sw_reg_base +L2SW_SW_INT_MASK_0 ); + +napi_complete (napi); +return 0 ; +} + +int spl2sw_tx_poll (struct napi_struct *napi,int budget) { + struct spl2sw_common *comm = container_of(napi, struct spl2sw_common, tx_napi); +struct spl2sw_skb_info *skbinfo; +struct net_device_stats *stats;drivers/net/ethernet/sunplus/spl2sw_int.c
Quoted 10 lines
drivers/net/ethernet/sunplus/spl2sw_int.c new file +10
-0+int budget_left = budget; +u32 tx_done_pos; +u32 mask; +u32 cmd; +int i; + +spin_lock (&comm->tx_lock); + + tx_done_pos = comm->tx_done_pos; +while (((tx_done_pos != comm->tx_pos) || (comm->tx_desc_full ==1 )) && budget_left){
Quoted 46 lines
drivers/net/ethernet/sunplus/spl2sw_int.c new file +46
-0+ cmd = comm->tx_desc[tx_done_pos].cmd1; +if (cmd &TXD_OWN ) +break ; + + skbinfo = &comm->tx_temp_skb_info[tx_done_pos]; +if (unlikely (!skbinfo->skb)) + goto spl2sw_tx_poll_next; + + i =ffs (FIELD_GET (TXD_VLAN , cmd)) -1 ; +if (i <MAX_NETDEV_NUM && comm->ndev[i]) + stats = &comm->ndev[i]->stats; +else + goto spl2sw_tx_poll_unmap; + +if (unlikely (cmd & (TXD_ERR_CODE ))) { + stats->tx_errors++; + }else { + stats->tx_packets++; + stats->tx_bytes += skbinfo->len; + } + +spl2sw_tx_poll_unmap: +dma_unmap_single (&comm->pdev->dev, skbinfo->mapping, skbinfo->len, +DMA_TO_DEVICE ); + skbinfo->mapping =0 ; +dev_kfree_skb_irq (skbinfo->skb); + skbinfo->skb =NULL ; + +spl2sw_tx_poll_next: +/* Move tx_done_pos to next position */ + tx_done_pos = ((tx_done_pos +1 ) ==TX_DESC_NUM ) ?0 : tx_done_pos ++1 ; + +if (comm->tx_desc_full ==1 ) + comm->tx_desc_full =0 ; + + budget_left--; + } + + comm->tx_done_pos = tx_done_pos; +if (!comm->tx_desc_full) +for (i =0 ; i <MAX_NETDEV_NUM ; i++) +if (comm->ndev[i]) +if (netif_queue_stopped (comm->ndev[i])) +netif_wake_queue (comm->ndev[i]); +drivers/net/ethernet/sunplus/spl2sw_int.c line 202
Quoted 10 lines
drivers/net/ethernet/sunplus/spl2sw_int.c new file +10
-0+spin_unlock (&comm->tx_lock); + +wmb ();/* make sure settings are effective. */ + mask =readl (comm->l2sw_reg_base +L2SW_SW_INT_MASK_0 ); + mask &= ~MAC_INT_TX ; +writel (mask, comm->l2sw_reg_base +L2SW_SW_INT_MASK_0 ); + +napi_complete (napi); +return 0 ; +}This doesn't look like it is doing NAPI properly.
Quoted 2 lines
The driver is supposed to return the amount of packets processed. If budget is used, it should return budget.
I'll modify code to return the amount of processed packets:
return budge - budget_left;
Thank you for your review.
Best regards,
Wells
Re: [PATCH net-next v9 2/2] net: ethernet: Add driver for Sunplus SP7021
In reply to Wells LuWells Lu <[email protected]> :
[...]
Quoted 2 lines
drivers/net/ethernet/sunplus/spl2sw_int.c new file +2
-0+int spl2sw_rx_poll (struct napi_struct *napi,int budget) +{
[...]
Quoted 11 lines
drivers/net/ethernet/sunplus/spl2sw_int.c new file +11
-0+wmb ();/* make sure settings are effective. */ + mask =readl (comm->l2sw_reg_base +L2SW_SW_INT_MASK_0 ); + mask &= ~MAC_INT_RX ; +writel (mask, comm->l2sw_reg_base +L2SW_SW_INT_MASK_0 ); + +napi_complete (napi); +return 0 ; +} + +int spl2sw_tx_poll (struct napi_struct *napi,int budget) +{
[...]
Quoted 11 lines
drivers/net/ethernet/sunplus/spl2sw_int.c new file +11
-0+wmb ();/* make sure settings are effective. */ + mask =readl (comm->l2sw_reg_base +L2SW_SW_INT_MASK_0 ); + mask &= ~MAC_INT_TX ; +writel (mask, comm->l2sw_reg_base +L2SW_SW_INT_MASK_0 ); + +napi_complete (napi); +return 0 ; +} + +irqreturn_t spl2sw_ethernet_interrupt (int irq,void *dev_id) +{
[...]
Quoted 5 lines
drivers/net/ethernet/sunplus/spl2sw_int.c new file +5
-0+if (status &MAC_INT_RX ) { +/* Disable RX interrupts. */ + mask =readl (comm->l2sw_reg_base +L2SW_SW_INT_MASK_0 ); + mask |=MAC_INT_RX ; +writel (mask, comm->l2sw_reg_base +L2SW_SW_INT_MASK_0 );
[...]
Quoted 10 lines
drivers/net/ethernet/sunplus/spl2sw_int.c new file +10
-0+napi_schedule (&comm->rx_napi); + } + +if (status &MAC_INT_TX ) { +/* Disable TX interrupts. */ + mask =readl (comm->l2sw_reg_base +L2SW_SW_INT_MASK_0 ); + mask |=MAC_INT_TX ; +writel (mask, comm->l2sw_reg_base +L2SW_SW_INT_MASK_0 ); + +if (unlikely (status &MAC_INT_TX_DES_ERR )) {
[...]
drivers/net/ethernet/sunplus/spl2sw_int.c line 256
Quoted 4 lines
drivers/net/ethernet/sunplus/spl2sw_int.c new file +4
-0+ }else { +napi_schedule (&comm->tx_napi); + } + }
The readl/writel sequence in rx_poll (or tx_poll) races with the irq handler performing MAC_INT_TX (or MAC_INT_RX) work. If the readl returns the same value to both callers, one of the writel will be overwritten.
Signature · 1 line
Ueimor
RE: [PATCH net-next v9 2/2] net: ethernet: Add driver for Sunplus SP7021
Hi Francois,
Quoted 51 lines
[...]
Quoted 1 line
+int
spl2sw_rx_poll(struct napi_struct *napi, int budget){[...]
Quoted 10 lines
drivers/net/ethernet/sunplus/spl2sw_int.c new file +10
-0+wmb ();/* make sure settings are effective. */ + mask =readl (comm->l2sw_reg_base +L2SW_SW_INT_MASK_0 ); + mask &= ~MAC_INT_RX ; +writel (mask, comm->l2sw_reg_base +L2SW_SW_INT_MASK_0 ); + +napi_complete (napi); +return 0 ; +} + +int spl2sw_tx_poll (struct napi_struct *napi,int budget) {[...]
Quoted 10 lines
drivers/net/ethernet/sunplus/spl2sw_int.c new file +10
-0+wmb ();/* make sure settings are effective. */ + mask =readl (comm->l2sw_reg_base +L2SW_SW_INT_MASK_0 ); + mask &= ~MAC_INT_TX ; +writel (mask, comm->l2sw_reg_base +L2SW_SW_INT_MASK_0 ); + +napi_complete (napi); +return 0 ; +} + +irqreturn_t spl2sw_ethernet_interrupt (int irq,void *dev_id) {[...]
Quoted 5 lines
drivers/net/ethernet/sunplus/spl2sw_int.c new file +5
-0+if (status &MAC_INT_RX ) { +/* Disable RX interrupts. */ + mask =readl (comm->l2sw_reg_base +L2SW_SW_INT_MASK_0 ); + mask |=MAC_INT_RX ; +writel (mask, comm->l2sw_reg_base +L2SW_SW_INT_MASK_0 );[...]
Quoted 10 lines
drivers/net/ethernet/sunplus/spl2sw_int.c new file +10
-0+napi_schedule (&comm->rx_napi); + } + +if (status &MAC_INT_TX ) { +/* Disable TX interrupts. */ + mask =readl (comm->l2sw_reg_base +L2SW_SW_INT_MASK_0 ); + mask |=MAC_INT_TX ; +writel (mask, comm->l2sw_reg_base +L2SW_SW_INT_MASK_0 ); + +if (unlikely (status &MAC_INT_TX_DES_ERR )) {[...]
drivers/net/ethernet/sunplus/spl2sw_int.c line 256
Quoted 4 lines
drivers/net/ethernet/sunplus/spl2sw_int.c new file +4
-0+ }else { +napi_schedule (&comm->tx_napi); + } + }The readl/writel sequence in
rx_poll(ortx_poll) races with the irq handler performingMAC_INT_TX(orMAC_INT_RX) work. If the readl returns the same value to both callers, one of the writel will be overwritten.
Quoted 2 lines
--
Ueimor
I will add disable_irq() and enable_irq() for spl2sw_rx_poll() and spl2sw_tx_poll() as shown below:
spl2sw_rx_poll():
wmb(); /* make sure settings are effective. */ disable_irq(comm->irq); mask = readl(comm->l2sw_reg_base + L2SW_SW_INT_MASK_0); mask &= ~MAC_INT_RX; writel(mask, comm->l2sw_reg_base + L2SW_SW_INT_MASK_0); enable_irq(comm->irq);
spl2sw_tx_poll():
wmb(); /* make sure settings are effective. */ disable_irq(comm->irq); mask = readl(comm->l2sw_reg_base + L2SW_SW_INT_MASK_0); mask &= ~MAC_INT_TX; writel(mask, comm->l2sw_reg_base + L2SW_SW_INT_MASK_0); enable_irq(comm->irq);
Is the modification ok?
Thank you for your review.
Best regards,
Wells
Re: [PATCH net-next v9 2/2] net: ethernet: Add driver for Sunplus SP7021
Wells Lu eh
3i(0 <[email protected]> :
[...]
Quoted 21 lines
I will add
disable_irq()andenable_irq()forspl2sw_rx_poll()andspl2sw_tx_poll()as shown below:
spl2sw_rx_poll():wmb(); /* make sure settings are effective. */ disable_irq(comm->irq); mask = readl(comm->l2sw_reg_base + L2SW_SW_INT_MASK_0); mask &= ~MAC_INT_RX; writel(mask, comm->l2sw_reg_base + L2SW_SW_INT_MASK_0); enable_irq(comm->irq);
spl2sw_tx_poll():wmb(); /* make sure settings are effective. */ disable_irq(comm->irq); mask = readl(comm->l2sw_reg_base + L2SW_SW_INT_MASK_0); mask &= ~MAC_INT_TX; writel(mask, comm->l2sw_reg_base + L2SW_SW_INT_MASK_0); enable_irq(comm->irq);
Quoted 1 line
Is the modification ok?
disable_irq prevents future irq processing but it does not help against irq code currently running on a different cpu.
You may use plain spin_{lock / unlock} in IRQ context and spin_{loq_irqsave / irq_restore} in NAPI context.
Signature · 1 line
Ueimor
RE: [PATCH net-next v9 2/2] net: ethernet: Add driver for Sunplus SP7021
Hi Francois,
Quoted 25 lines
[...]
Quoted 1 line
I will add
disable_irq()andenable_irq()forspl2sw_rx_poll()andspl2sw_tx_poll()as shown below:
Quoted 20 lines
spl2sw_rx_poll():wmb(); /* make sure settings are effective. */ disable_irq(comm->irq); mask = readl(comm->l2sw_reg_base + L2SW_SW_INT_MASK_0); mask &= ~MAC_INT_RX; writel(mask, comm->l2sw_reg_base + L2SW_SW_INT_MASK_0); enable_irq(comm->irq);
spl2sw_tx_poll():wmb(); /* make sure settings are effective. */ disable_irq(comm->irq); mask = readl(comm->l2sw_reg_base + L2SW_SW_INT_MASK_0); mask &= ~MAC_INT_TX; writel(mask, comm->l2sw_reg_base + L2SW_SW_INT_MASK_0); enable_irq(comm->irq);Quoted 1 line
Is the modification ok?
Quoted 8 lines
disable_irqprevents future irq processing but it does not help against irq code currently running on a different cpu.You may use plain spin_{lock / unlock} in IRQ context and spin_{loq_irqsave /
irq_restore} in NAPI context.--
Ueimor
Thank you for teaching me how to fix the issue.
I'll add them next patch.
Best regards,
Wells