Brcm ASP 2.0 Ethernet Controller
Subsystems (7)
Justin Chen
maintainerv9 cover Brcm ASP 2.0 Ethernet Controller
Add support for the Broadcom ASP 2.0 Ethernet controller which is first introduced with 72165.
Florian Fainelli (2):
dt-bindings: net: Brcm ASP 2.0 Ethernet controller
net: phy: bcm7xxx: Add EPHY entry for 74165
Justin Chen (9):
dt-bindings: net: brcm,unimac-mdio: Add asp-v2.0
net: bcmasp: Add support for ASP2.0 Ethernet controller
net: bcmasp: Add support for WoL magic packet
net: bcmasp: Add support for wake on net filters
net: bcmasp: Add support for eee mode
net: bcmasp: Add support for ethtool standard stats
net: bcmasp: Add support for ethtool driver stats
net: phy: mdio-bcm-unimac: Add asp v2.0 support
MAINTAINERS: ASP 2.0 Ethernet driver maintainers
.../devicetree/bindings/net/brcm,asp-v2.0.yaml | 155 +++ .../devicetree/bindings/net/brcm,unimac-mdio.yaml | 2 + MAINTAINERS | 9 + drivers/net/ethernet/broadcom/Kconfig | 11 + drivers/net/ethernet/broadcom/Makefile | 1 + drivers/net/ethernet/broadcom/asp2/Makefile | 2 + drivers/net/ethernet/broadcom/asp2/bcmasp.c | 1437 ++++++++++++++++++++ drivers/net/ethernet/broadcom/asp2/bcmasp.h | 586 ++++++++ .../net/ethernet/broadcom/asp2/bcmasp_ethtool.c | 503 +++++++ drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c | 1415 +++++++++++++++++++ .../net/ethernet/broadcom/asp2/bcmasp_intf_defs.h | 257 ++++ drivers/net/mdio/mdio-bcm-unimac.c | 2 + drivers/net/phy/bcm7xxx.c | 1 + include/linux/brcmphy.h | 1 + 14 files changed, 4382 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml create mode 100644 drivers/net/ethernet/broadcom/asp2/Makefile create mode 100644 drivers/net/ethernet/broadcom/asp2/bcmasp.c create mode 100644 drivers/net/ethernet/broadcom/asp2/bcmasp.h create mode 100644 drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c create mode 100644 drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c create mode 100644 drivers/net/ethernet/broadcom/asp2/bcmasp_intf_defs.h
Signature · 1 line
2.7.4
Justin Chen
maintainerPATCH v9 1/11 dt-bindings: net: brcm,unimac-mdio: Add asp-v2.0
The ASP 2.0 Ethernet controller uses a brcm unimac.
--- Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml | 2 ++ 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml +2 -0
@@ -22,6 +22,8 @@ properties: - brcm,genet-mdio-v3 - brcm,genet-mdio-v4 - brcm,genet-mdio-v5 + - brcm,asp-v2.0-mdio + - brcm,asp-v2.1-mdio - brcm,unimac-mdio reg:
Signature · 1 line
2.7.4
Justin Chen
maintainerPATCH v9 2/11 dt-bindings: net: Brcm ASP 2.0 Ethernet controller
In reply to Justin ChenFrom: Florian Fainelli <[email protected]>
Add a binding document for the Broadcom ASP 2.0 Ethernet controller.
---
v7
- Added "unevaluatedProperties: False"
v6
- Moved compatible to the top
- Changed quotes to be consistent
- Elaborated on brcm,channel description
v5
- Fix compatible string yaml format to properly capture what we want
v4
- Adjust compatible string example to reference SoC and HW ver
v3
- Minor formatting issues
- Change channel prop to brcm,channel for vendor specific format
- Removed redundant v2.0 from compat string
- Fix ranges field
v2
- Minor formatting issues
.../devicetree/bindings/net/brcm,asp-v2.0.yaml | 155 +++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml
Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml new file +155 -0
@@ -0,0 +1,155 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/brcm,asp-v2.0.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Broadcom ASP 2.0 Ethernet controller + +maintainers: + - Justin Chen <[email protected]> + - Florian Fainelli <[email protected]> + +description: Broadcom Ethernet controller first introduced with 72165 + +properties: + compatible: + oneOf: + - items: + - enum: + - brcm,bcm74165-asp + - const: brcm,asp-v2.1 + - items: + - enum: + - brcm,bcm72165-asp + - const: brcm,asp-v2.0 + + "#address-cells": + const: 1 + "#size-cells": + const: 1 + + reg: + maxItems: 1 + + ranges: true + + interrupts: + minItems: 1 + items: + - description: RX/TX interrupt + - description: Port 0 Wake-on-LAN + - description: Port 1 Wake-on-LAN + + clocks: + maxItems: 1 + + ethernet-ports: + type: object + properties: + "#address-cells": + const: 1 + "#size-cells": + const: 0 + + patternProperties: + "^port@[0-9]+$": + type: object + + $ref: ethernet-controller.yaml# + + unevaluatedProperties: false + + properties: + reg: + maxItems: 1 + description: Port number + + brcm,channel: + $ref: /schemas/types.yaml#/definitions/uint32 + description: | + ASP Channel Number + + The depacketizer channel that consumes packets from + the unimac/port. + + required: + - reg + - brcm,channel + + additionalProperties: false + +patternProperties: + "^mdio@[0-9a-f]+$": + type: object + $ref: brcm,unimac-mdio.yaml + + description: + ASP internal UniMAC MDIO bus + +required: + - compatible + - reg + - interrupts + - clocks + - ranges + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + #include <dt-bindings/interrupt-controller/arm-gic.h> + + ethernet@9c00000 { + compatible = "brcm,bcm72165-asp", "brcm,asp-v2.0"; + reg = <0x9c00000 0x1fff14>; + interrupts = <GIC_SPI 51 IRQ_TYPE_LEVEL_HIGH>; + ranges = <0x0 0x9c00000 0x1fff14>; + clocks = <&scmi 14>; + #address-cells = <1>; + #size-cells = <1>; + + mdio@c614 { + compatible = "brcm,asp-v2.0-mdio"; + reg = <0xc614 0x8>; + reg-names = "mdio"; + #address-cells = <1>; + #size-cells = <0>; + + phy0: ethernet-phy@1 { + reg = <1>; + }; + }; + + mdio@ce14 { + compatible = "brcm,asp-v2.0-mdio"; + reg = <0xce14 0x8>; + reg-names = "mdio"; + #address-cells = <1>; + #size-cells = <0>; + + phy1: ethernet-phy@1 { + reg = <1>; + }; + }; + + ethernet-ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + brcm,channel = <8>; + phy-mode = "rgmii"; + phy-handle = <&phy0>; + }; + + port@1 { + reg = <1>; + brcm,channel = <9>; + phy-mode = "rgmii"; + phy-handle = <&phy1>; + }; + }; + };
Signature · 1 line
2.7.4
Justin Chen
maintainerPATCH v9 3/11 net: bcmasp: Add support for ASP2.0 Ethernet controller
In reply to Justin ChenAdd support for the Broadcom ASP 2.0 Ethernet controller which is first introduced with 72165. This controller features two distinct Ethernet ports that can be independently operated.
---
v9
- Reworked logic where a port fails to register during probe
- Switch from array to linked list for interfaces. This simplifies the logic and makes it a bit cleaner to follow.
- Check for case where remove and shutdown hook both get called.
- Use skb_cow_head instead of skb_realloc_headroom
- Add ratelimit for some err prints.
- Use napi_alloc_skb instead of __netdev_alloc_skb().
- Reworked some rtnl_link_stats64 according to documentation.
v8
- Address some checkpatch warnings
v7
- Fixed leaking ports_node device node.
- Split out to smaller commits
v6
- Fixed a reserved mac filter indexing error
- Removed tx_lock
- Simplified tx_timeout hook
- Removed get_stats
- Fixed phy ioctl
- Fixed dev -> ndev typo
- Fixed set_wol double disable
v5
- Remove unnecessary parenthesis
- Use bool for bcmasp_netfilt_check_dup()
v4
- Address sparse warnings
- Fix one more reverse xmas tree violation
- Improve error logic for bcmasp_netfilt_get_reg_offset()
- Remove inlines
v3
- Fix logic error with net stats where some stats were missing
- General clean up addressing formatting/spelling/consistency
- Use dev_err_probe to save a few LoCs
- Use put_unaligned when updating net stats
v2
- Replace a couple functions with helper functions
- Fix a few WoL issues
drivers/net/ethernet/broadcom/Kconfig | 11 + drivers/net/ethernet/broadcom/Makefile | 1 + drivers/net/ethernet/broadcom/asp2/Makefile | 2 + drivers/net/ethernet/broadcom/asp2/bcmasp.c | 696 ++++++++++ drivers/net/ethernet/broadcom/asp2/bcmasp.h | 503 ++++++++ .../net/ethernet/broadcom/asp2/bcmasp_ethtool.c | 40 + drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c | 1342 ++++++++++++++++++++ .../net/ethernet/broadcom/asp2/bcmasp_intf_defs.h | 196 +++ 8 files changed, 2791 insertions(+) create mode 100644 drivers/net/ethernet/broadcom/asp2/Makefile create mode 100644 drivers/net/ethernet/broadcom/asp2/bcmasp.c create mode 100644 drivers/net/ethernet/broadcom/asp2/bcmasp.h create mode 100644 drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c create mode 100644 drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c create mode 100644 drivers/net/ethernet/broadcom/asp2/bcmasp_intf_defs.h
drivers/net/ethernet/broadcom/Kconfig +11 -0
@@ -255,4 +255,15 @@ config BNXT_HWMON Say Y if you want to expose the thermal sensor data on NetXtreme-C/E devices, via the hwmon sysfs interface. +config BCMASP + tristate "Broadcom ASP 2.0 Ethernet support" + default ARCH_BRCMSTB + depends on OF + select MII + select PHYLIB + select MDIO_BCM_UNIMAC + help + This configuration enables the Broadcom ASP 2.0 Ethernet controller + driver which is present in Broadcom STB SoCs such as 72165. + endif # NET_VENDOR_BROADCOM
drivers/net/ethernet/broadcom/Makefile +1 -0
@@ -17,3 +17,4 @@ obj-$(CONFIG_BGMAC_BCMA) += bgmac-bcma.o bgmac-bcma-mdio.o obj-$(CONFIG_BGMAC_PLATFORM) += bgmac-platform.o obj-$(CONFIG_SYSTEMPORT) += bcmsysport.o obj-$(CONFIG_BNXT) += bnxt/ +obj-$(CONFIG_BCMASP) += asp2/
drivers/net/ethernet/broadcom/asp2/Makefile new file +2 -0
@@ -0,0 +1,2 @@ +obj-$(CONFIG_BCMASP) += bcm-asp.o +bcm-asp-objs := bcmasp.o bcmasp_intf.o bcmasp_ethtool.o
drivers/net/ethernet/broadcom/asp2/bcmasp.c new file +696 -0
696 lines not on this page · raw message
drivers/net/ethernet/broadcom/asp2/bcmasp.h new file +503 -0
503 lines not on this page · raw message
drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c new file +40 -0
@@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-2.0 +#define pr_fmt (fmt) "bcmasp_ethtool: " fmt + +#include <linux/ethtool.h> +#include <linux/netdevice.h> +#include <linux/platform_device.h> + +#include "bcmasp.h" +#include "bcmasp_intf_defs.h" + +static void bcmasp_get_drvinfo (struct net_device *dev, +struct ethtool_drvinfo *info) +{ +strscpy (info->driver,"bcmasp" ,sizeof (info->driver)); +strscpy (info->bus_info,dev_name (dev->dev.parent), +sizeof (info->bus_info)); +} + +static u32 bcmasp_get_msglevel (struct net_device *dev) +{ +struct bcmasp_intf *intf =netdev_priv (dev); + +return intf->msg_enable; +} + +static void bcmasp_set_msglevel (struct net_device *dev,u32 level) +{ +struct bcmasp_intf *intf =netdev_priv (dev); + + intf->msg_enable = level; +} + +const struct ethtool_ops bcmasp_ethtool_ops = { + .get_drvinfo = bcmasp_get_drvinfo, + .get_link = ethtool_op_get_link, + .get_link_ksettings = phy_ethtool_get_link_ksettings, + .set_link_ksettings = phy_ethtool_set_link_ksettings, + .get_msglevel = bcmasp_get_msglevel, + .set_msglevel = bcmasp_set_msglevel, +};
drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c new file +1342 -0
1,342 lines not on this page · raw message
drivers/net/ethernet/broadcom/asp2/bcmasp_intf_defs.h new file +196 -0
196 lines not on this page · raw message
Signature · 1 line
2.7.4
Justin Chen
maintainerPATCH v9 4/11 net: bcmasp: Add support for WoL magic packet
In reply to Justin ChenAdd support for Wake-On-Lan magic packet and magic packet with password.
---
v9
- Fixed some spacing issues
drivers/net/ethernet/broadcom/asp2/bcmasp.c | 144 +++++++++++++++++++++ drivers/net/ethernet/broadcom/asp2/bcmasp.h | 18 +++ .../net/ethernet/broadcom/asp2/bcmasp_ethtool.c | 36 ++++++ drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c | 76 +++++++++-- 4 files changed, 262 insertions(+), 12 deletions(-)
drivers/net/ethernet/broadcom/asp2/bcmasp.c +144 -0
@@ -436,6 +436,135 @@ void bcmasp_core_clock_set_intf(struct bcmasp_intf *intf, bool en)spin_unlock_irqrestore (&priv->clk_lock, flags); } +static irqreturn_t bcmasp_isr_wol (int irq,void *data) +{ +struct bcmasp_priv *priv = data; +u32 status; + +/* No L3 IRQ, so we good */ +if (priv->wol_irq <=0 ) + goto irq_handled; + + status =wakeup_intr2_core_rl (priv,ASP_WAKEUP_INTR2_STATUS ) & + ~wakeup_intr2_core_rl (priv,ASP_WAKEUP_INTR2_MASK_STATUS ); +wakeup_intr2_core_wl (priv, status,ASP_WAKEUP_INTR2_CLEAR ); + +irq_handled: +pm_wakeup_event (&priv->pdev->dev,0 ); +return IRQ_HANDLED ; +} + +static int bcmasp_get_and_request_irq (struct bcmasp_priv *priv,int i) +{ +struct platform_device *pdev = priv->pdev; +int irq, ret; + + irq =platform_get_irq_optional (pdev, i); +if (irq <0 ) +return irq; + + ret =devm_request_irq (&pdev->dev, irq, bcmasp_isr_wol,0 , + pdev->name, priv); +if (ret) +return ret; + +return irq; +} + +static void bcmasp_init_wol_shared (struct bcmasp_priv *priv) +{ +struct platform_device *pdev = priv->pdev; +struct device *dev = &pdev->dev; +int irq; + + irq =bcmasp_get_and_request_irq (priv,1 ); +if (irq <0 ) { +dev_warn (dev,"Failed to init WoL irq: %d\n" , irq); +return ; + } + + priv->wol_irq = irq; + priv->wol_irq_enabled_mask =0 ; +device_set_wakeup_capable (&pdev->dev,1 ); +} + +static void bcmasp_enable_wol_shared (struct bcmasp_intf *intf,bool en) +{ +struct bcmasp_priv *priv = intf->parent; +struct device *dev = &priv->pdev->dev; + +if (en) { +if (priv->wol_irq_enabled_mask) { +set_bit (intf->port, &priv->wol_irq_enabled_mask); +return ; + } + +/* First enable */ +set_bit (intf->port, &priv->wol_irq_enabled_mask); +enable_irq_wake (priv->wol_irq); +device_set_wakeup_enable (dev,1 ); + }else { +if (!priv->wol_irq_enabled_mask) +return ; + +clear_bit (intf->port, &priv->wol_irq_enabled_mask); +if (priv->wol_irq_enabled_mask) +return ; + +/* Last disable */ +disable_irq_wake (priv->wol_irq); +device_set_wakeup_enable (dev,0 ); + } +} + +static void bcmasp_wol_irq_destroy_shared (struct bcmasp_priv *priv) +{ +if (priv->wol_irq >0 ) +free_irq (priv->wol_irq, priv); +} + +static void bcmasp_init_wol_per_intf (struct bcmasp_priv *priv) +{ +struct platform_device *pdev = priv->pdev; +struct device *dev = &pdev->dev; +struct bcmasp_intf *intf; +int irq; + +list_for_each_entry (intf, &priv->intfs, list) { + irq =bcmasp_get_and_request_irq (priv, intf->port +1 ); +if (irq <0 ) { +dev_warn (dev,"Failed to init WoL irq(port %d): %d\n" , + intf->port, irq); +continue ; + } + + intf->wol_irq = irq; + intf->wol_irq_enabled = false; +device_set_wakeup_capable (&pdev->dev,1 ); + } +} + +static void bcmasp_enable_wol_per_intf (struct bcmasp_intf *intf,bool en) +{ +struct device *dev = &intf->parent->pdev->dev; + +if (en ^ intf->wol_irq_enabled) +irq_set_irq_wake (intf->wol_irq, en); + + intf->wol_irq_enabled = en; +device_set_wakeup_enable (dev, en); +} + +static void bcmasp_wol_irq_destroy_per_intf (struct bcmasp_priv *priv) +{ +struct bcmasp_intf *intf; + +list_for_each_entry (intf, &priv->intfs, list) { +if (intf->wol_irq >0 ) +free_irq (intf->wol_irq, priv); + } +} +static struct bcmasp_hw_info v20_hw_info = { .rx_ctrl_flush =ASP_RX_CTRL_FLUSH , .umac2fb =UMAC2FB_OFFSET ,
@@ -445,6 +574,9 @@ static struct bcmasp_hw_info v20_hw_info = { };static const struct bcmasp_plat_data v20_plat_data = { + .init_wol = bcmasp_init_wol_per_intf, + .enable_wol = bcmasp_enable_wol_per_intf, + .destroy_wol = bcmasp_wol_irq_destroy_per_intf, .hw_info = &v20_hw_info, };
@@ -458,6 +590,9 @@ static struct bcmasp_hw_info v21_hw_info = { };static const struct bcmasp_plat_data v21_plat_data = { + .init_wol = bcmasp_init_wol_shared, + .enable_wol = bcmasp_enable_wol_shared, + .destroy_wol = bcmasp_wol_irq_destroy_shared, .hw_info = &v21_hw_info, };
@@ -521,12 +656,16 @@ static int bcmasp_probe(struct platform_device *pdev) priv->pdev = pdev;spin_lock_init (&priv->mda_lock);spin_lock_init (&priv->clk_lock); +mutex_init (&priv->wol_lock);INIT_LIST_HEAD (&priv->intfs); pdata =device_get_match_data (&pdev->dev);if (!pdata)return dev_err_probe (dev, -EINVAL ,"unable to find platform data\n" ); + priv->init_wol = pdata->init_wol; + priv->enable_wol = pdata->enable_wol; + priv->destroy_wol = pdata->destroy_wol; priv->hw_info = pdata->hw_info;/* Enable all clocks to ensure successful probing */
@@ -570,6 +709,9 @@ static int bcmasp_probe(struct platform_device *pdev) i++; } +/* Check and enable WoL */ + priv->init_wol (priv); +/* Drop the clock reference count now and let ndo_open()/ndo_close() * manage it for us from now on. */
@@ -585,6 +727,7 @@ static int bcmasp_probe(struct platform_device *pdev)if (ret) {netdev_err (intf->ndev,"failed to register net_device: %d\n" , ret); + priv->destroy_wol (priv);bcmasp_remove_intfs (priv); goto of_put_exit; }
@@ -605,6 +748,7 @@ static int bcmasp_remove(struct platform_device *pdev)if (!priv)return 0 ; + priv->destroy_wol (priv);bcmasp_remove_intfs (priv);return 0 ;
drivers/net/ethernet/broadcom/asp2/bcmasp.h +18 -0
@@ -301,6 +301,12 @@ struct bcmasp_intf {/* Statistics */ struct bcmasp_intf_stats64 stats64; + +u32 wolopts; +u8 sopass[SOPASS_MAX ]; +/* Used if per intf wol irq */ +int wol_irq; + unsigned int wol_irq_enabled:1; };#define NUM_MDA_FILTERS 32
@@ -321,6 +327,9 @@ struct bcmasp_hw_info { };struct bcmasp_plat_data { +void (*init_wol)(struct bcmasp_priv *priv); +void (*enable_wol)(struct bcmasp_intf *intf,bool en); +void (*destroy_wol)(struct bcmasp_priv *priv);struct bcmasp_hw_info *hw_info; };
@@ -331,6 +340,15 @@ struct bcmasp_priv {int irq;u32 irq_mask; +/* Used if shared wol irq */ +struct mutex wol_lock; +int wol_irq; +unsigned long wol_irq_enabled_mask; + +void (*init_wol)(struct bcmasp_priv *priv); +void (*enable_wol)(struct bcmasp_intf *intf,bool en); +void (*destroy_wol)(struct bcmasp_priv *priv); +void __iomem *base;struct bcmasp_hw_info *hw_info;
drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c +36 -0
@@ -30,6 +30,40 @@ static void bcmasp_set_msglevel(struct net_device *dev, u32 level) intf->msg_enable = level; } +#define BCMASP_SUPPORTED_WAKE (WAKE_MAGIC | WAKE_MAGICSECURE) +static void bcmasp_get_wol (struct net_device *dev,struct ethtool_wolinfo *wol) +{ +struct bcmasp_intf *intf =netdev_priv (dev); + + wol->supported =BCMASP_SUPPORTED_WAKE ; + wol->wolopts = intf->wolopts; +memset (wol->sopass,0 ,sizeof (wol->sopass)); + +if (wol->wolopts &WAKE_MAGICSECURE ) +memcpy (wol->sopass, intf->sopass,sizeof (intf->sopass)); +} + +static int bcmasp_set_wol (struct net_device *dev,struct ethtool_wolinfo *wol) +{ +struct bcmasp_intf *intf =netdev_priv (dev); +struct bcmasp_priv *priv = intf->parent; +struct device *kdev = &priv->pdev->dev; + +if (!device_can_wakeup (kdev)) +return -EOPNOTSUPP ; + +/* Interface Specific */ + intf->wolopts = wol->wolopts; +if (intf->wolopts &WAKE_MAGICSECURE ) +memcpy (intf->sopass, wol->sopass,sizeof (wol->sopass)); + +mutex_lock (&priv->wol_lock); + priv->enable_wol (intf, !!intf->wolopts); +mutex_unlock (&priv->wol_lock); + +return 0 ; +} +const struct ethtool_ops bcmasp_ethtool_ops = { .get_drvinfo = bcmasp_get_drvinfo, .get_link = ethtool_op_get_link,
@@ -37,4 +71,6 @@ const struct ethtool_ops bcmasp_ethtool_ops = { .set_link_ksettings = phy_ethtool_set_link_ksettings, .get_msglevel = bcmasp_get_msglevel, .set_msglevel = bcmasp_set_msglevel, + .get_wol = bcmasp_get_wol, + .set_wol = bcmasp_set_wol, };
drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c +64 -12
110 lines not on this page · raw message
Signature · 1 line
2.7.4
Justin Chen
maintainerPATCH v9 5/11 net: bcmasp: Add support for wake on net filters
In reply to Justin ChenAdd support for wake on network filters. The max match is 256 bytes.
--- drivers/net/ethernet/broadcom/asp2/bcmasp.c | 595 +++++++++++++++++++++ drivers/net/ethernet/broadcom/asp2/bcmasp.h | 40 ++ .../net/ethernet/broadcom/asp2/bcmasp_ethtool.c | 131 ++++- drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c | 3 + 4 files changed, 768 insertions(+), 1 deletion(-)
drivers/net/ethernet/broadcom/asp2/bcmasp.c +595 -0
@@ -127,6 +127,597 @@ void bcmasp_flush_rx_port(struct bcmasp_intf *intf)rx_ctrl_core_wl (priv, mask, priv->hw_info->rx_ctrl_flush); } +static void bcmasp_netfilt_hw_en_wake (struct bcmasp_priv *priv, +struct bcmasp_net_filter *nfilt) +{ +rx_filter_core_wl (priv,ASP_RX_FILTER_NET_OFFSET_L3_1 (64 ), +ASP_RX_FILTER_NET_OFFSET (nfilt->hw_index)); + +rx_filter_core_wl (priv,ASP_RX_FILTER_NET_OFFSET_L2 (32 ) | +ASP_RX_FILTER_NET_OFFSET_L3_0 (32 ) | +ASP_RX_FILTER_NET_OFFSET_L3_1 (96 ) | +ASP_RX_FILTER_NET_OFFSET_L4 (32 ), +ASP_RX_FILTER_NET_OFFSET (nfilt->hw_index +1 )); + +rx_filter_core_wl (priv,ASP_RX_FILTER_NET_CFG_CH (nfilt->port +8 ) | +ASP_RX_FILTER_NET_CFG_EN | +ASP_RX_FILTER_NET_CFG_L2_EN | +ASP_RX_FILTER_NET_CFG_L3_EN | +ASP_RX_FILTER_NET_CFG_L4_EN | +ASP_RX_FILTER_NET_CFG_L3_FRM (2 ) | +ASP_RX_FILTER_NET_CFG_L4_FRM (2 ) | +ASP_RX_FILTER_NET_CFG_UMC (nfilt->port), +ASP_RX_FILTER_NET_CFG (nfilt->hw_index)); + +rx_filter_core_wl (priv,ASP_RX_FILTER_NET_CFG_CH (nfilt->port +8 ) | +ASP_RX_FILTER_NET_CFG_EN | +ASP_RX_FILTER_NET_CFG_L2_EN | +ASP_RX_FILTER_NET_CFG_L3_EN | +ASP_RX_FILTER_NET_CFG_L4_EN | +ASP_RX_FILTER_NET_CFG_L3_FRM (2 ) | +ASP_RX_FILTER_NET_CFG_L4_FRM (2 ) | +ASP_RX_FILTER_NET_CFG_UMC (nfilt->port), +ASP_RX_FILTER_NET_CFG (nfilt->hw_index +1 )); +} + +#define MAX_WAKE_FILTER_SIZE 256 +enum asp_netfilt_reg_type { +ASP_NETFILT_MATCH =0 , +ASP_NETFILT_MASK , +ASP_NETFILT_MAX +}; + +static int bcmasp_netfilt_get_reg_offset (struct bcmasp_priv *priv, +struct bcmasp_net_filter *nfilt, +enum asp_netfilt_reg_type reg_type, +u32 offset) +{ +u32 block_index, filter_sel; + +if (offset <32 ) { + block_index =ASP_RX_FILTER_NET_L2 ; + filter_sel = nfilt->hw_index; + }else if (offset <64 ) { + block_index =ASP_RX_FILTER_NET_L2 ; + filter_sel = nfilt->hw_index +1 ; + }else if (offset <96 ) { + block_index =ASP_RX_FILTER_NET_L3_0 ; + filter_sel = nfilt->hw_index; + }else if (offset <128 ) { + block_index =ASP_RX_FILTER_NET_L3_0 ; + filter_sel = nfilt->hw_index +1 ; + }else if (offset <160 ) { + block_index =ASP_RX_FILTER_NET_L3_1 ; + filter_sel = nfilt->hw_index; + }else if (offset <192 ) { + block_index =ASP_RX_FILTER_NET_L3_1 ; + filter_sel = nfilt->hw_index +1 ; + }else if (offset <224 ) { + block_index =ASP_RX_FILTER_NET_L4 ; + filter_sel = nfilt->hw_index; + }else if (offset <256 ) { + block_index =ASP_RX_FILTER_NET_L4 ; + filter_sel = nfilt->hw_index +1 ; + }else { +return -EINVAL ; + } + +switch (reg_type) { +case ASP_NETFILT_MATCH : +return ASP_RX_FILTER_NET_PAT (filter_sel, block_index, + (offset %32 )); +case ASP_NETFILT_MASK : +return ASP_RX_FILTER_NET_MASK (filter_sel, block_index, + (offset %32 )); +default : +return -EINVAL ; + } +} + +static void bcmasp_netfilt_wr (struct bcmasp_priv *priv, +struct bcmasp_net_filter *nfilt, +enum asp_netfilt_reg_type reg_type, +u32 val,u32 offset) +{ +int reg_offset; + +/* HW only accepts 4 byte aligned writes */ +if (!IS_ALIGNED (offset,4 ) || offset >MAX_WAKE_FILTER_SIZE ) +return ; + + reg_offset =bcmasp_netfilt_get_reg_offset (priv, nfilt, reg_type, + offset); + +rx_filter_core_wl (priv, val, reg_offset); +} + +static u32 bcmasp_netfilt_rd (struct bcmasp_priv *priv, +struct bcmasp_net_filter *nfilt, +enum asp_netfilt_reg_type reg_type, +u32 offset) +{ +int reg_offset; + +/* HW only accepts 4 byte aligned writes */ +if (!IS_ALIGNED (offset,4 ) || offset >MAX_WAKE_FILTER_SIZE ) +return 0 ; + + reg_offset =bcmasp_netfilt_get_reg_offset (priv, nfilt, reg_type, + offset); + +return rx_filter_core_rl (priv, reg_offset); +} + +static int bcmasp_netfilt_wr_m_wake (struct bcmasp_priv *priv, +struct bcmasp_net_filter *nfilt, +u32 offset,void *match,void *mask, +size_t size) +{ +u32 shift, mask_val =0 , match_val =0 ; +bool first_byte = true; + +if ((offset + size) >MAX_WAKE_FILTER_SIZE ) +return -EINVAL ; + +while (size--) { +/* The HW only accepts 4 byte aligned writes, so if we +* begin unaligned or if remaining bytes less than 4, +* we need to read then write to avoid losing current +* register state +*/ +if (first_byte && (!IS_ALIGNED (offset,4 ) || size <3 )) { + match_val =bcmasp_netfilt_rd (priv, nfilt, +ASP_NETFILT_MATCH , +ALIGN_DOWN (offset,4 )); + mask_val =bcmasp_netfilt_rd (priv, nfilt, +ASP_NETFILT_MASK , +ALIGN_DOWN (offset,4 )); + } + + shift = (3 - (offset %4 )) *8 ; + match_val &= ~GENMASK (shift +7 , shift); + mask_val &= ~GENMASK (shift +7 , shift); + match_val |= (u32)(*((u8 *)match) << shift); + mask_val |= (u32)(*((u8 *)mask) << shift); + +/* If last byte or last byte of word, write to reg */ +if (!size || ((offset %4 ) ==3 )) { +bcmasp_netfilt_wr (priv, nfilt,ASP_NETFILT_MATCH , + match_val,ALIGN_DOWN (offset,4 )); +bcmasp_netfilt_wr (priv, nfilt,ASP_NETFILT_MASK , + mask_val,ALIGN_DOWN (offset,4 )); + first_byte = true; + }else { + first_byte = false; + } + + offset++; + match++; + mask++; + } + +return 0 ; +} + +static void bcmasp_netfilt_reset_hw (struct bcmasp_priv *priv, +struct bcmasp_net_filter *nfilt) +{ +int i; + +for (i =0 ; i <MAX_WAKE_FILTER_SIZE ; i +=4 ) { +bcmasp_netfilt_wr (priv, nfilt,ASP_NETFILT_MATCH ,0 , i); +bcmasp_netfilt_wr (priv, nfilt,ASP_NETFILT_MASK ,0 , i); + } +} + +static void bcmasp_netfilt_tcpip4_wr (struct bcmasp_priv *priv, +struct bcmasp_net_filter *nfilt, +struct ethtool_tcpip4_spec *match, +struct ethtool_tcpip4_spec *mask, +u32 offset) +{ +__be16 val_16, mask_16; + + val_16 =htons (ETH_P_IP ); + mask_16 =htons (0xFFFF ); +bcmasp_netfilt_wr_m_wake (priv, nfilt, (ETH_ALEN *2 ) + offset, + &val_16, &mask_16,sizeof (val_16)); +bcmasp_netfilt_wr_m_wake (priv, nfilt,ETH_HLEN + offset +1 , + &match->tos, &mask->tos, +sizeof (match->tos)); +bcmasp_netfilt_wr_m_wake (priv, nfilt,ETH_HLEN + offset +12 , + &match->ip4src, &mask->ip4src, +sizeof (match->ip4src)); +bcmasp_netfilt_wr_m_wake (priv, nfilt,ETH_HLEN + offset +16 , + &match->ip4dst, &mask->ip4dst, +sizeof (match->ip4dst)); +bcmasp_netfilt_wr_m_wake (priv, nfilt,ETH_HLEN + offset +20 , + &match->psrc, &mask->psrc, +sizeof (match->psrc)); +bcmasp_netfilt_wr_m_wake (priv, nfilt,ETH_HLEN + offset +22 , + &match->pdst, &mask->pdst, +sizeof (match->pdst)); +} + +static void bcmasp_netfilt_tcpip6_wr (struct bcmasp_priv *priv, +struct bcmasp_net_filter *nfilt, +struct ethtool_tcpip6_spec *match, +struct ethtool_tcpip6_spec *mask, +u32 offset) +{ +__be16 val_16, mask_16; + + val_16 =htons (ETH_P_IPV6 ); + mask_16 =htons (0xFFFF ); +bcmasp_netfilt_wr_m_wake (priv, nfilt, (ETH_ALEN *2 ) + offset, + &val_16, &mask_16,sizeof (val_16)); + val_16 =htons (match->tclass <<4 ); + mask_16 =htons (mask->tclass <<4 ); +bcmasp_netfilt_wr_m_wake (priv, nfilt,ETH_HLEN + offset, + &val_16, &mask_16,sizeof (val_16)); +bcmasp_netfilt_wr_m_wake (priv, nfilt,ETH_HLEN + offset +8 , + &match->ip6src, &mask->ip6src, +sizeof (match->ip6src)); +bcmasp_netfilt_wr_m_wake (priv, nfilt,ETH_HLEN + offset +24 , + &match->ip6dst, &mask->ip6dst, +sizeof (match->ip6dst)); +bcmasp_netfilt_wr_m_wake (priv, nfilt,ETH_HLEN + offset +40 , + &match->psrc, &mask->psrc, +sizeof (match->psrc)); +bcmasp_netfilt_wr_m_wake (priv, nfilt,ETH_HLEN + offset +42 , + &match->pdst, &mask->pdst, +sizeof (match->pdst)); +} + +static int bcmasp_netfilt_wr_to_hw (struct bcmasp_priv *priv, +struct bcmasp_net_filter *nfilt) +{ +struct ethtool_rx_flow_spec *fs = &nfilt->fs; +unsigned int offset =0 ; +__be16 val_16, mask_16; +u8 val_8, mask_8; + +/* Currently only supports wake filters */ +if (!nfilt->wake_filter) +return -EINVAL ; + +bcmasp_netfilt_reset_hw (priv, nfilt); + +if (fs->flow_type &FLOW_MAC_EXT ) { +bcmasp_netfilt_wr_m_wake (priv, nfilt,0 , &fs->h_ext.h_dest, + &fs->m_ext.h_dest, +sizeof (fs->h_ext.h_dest)); + } + +if ((fs->flow_type &FLOW_EXT ) && + (fs->m_ext.vlan_etype || fs->m_ext.vlan_tci)) { +bcmasp_netfilt_wr_m_wake (priv, nfilt, (ETH_ALEN *2 ), + &fs->h_ext.vlan_etype, + &fs->m_ext.vlan_etype, +sizeof (fs->h_ext.vlan_etype)); +bcmasp_netfilt_wr_m_wake (priv, nfilt, ((ETH_ALEN *2 ) +2 ), + &fs->h_ext.vlan_tci, + &fs->m_ext.vlan_tci, +sizeof (fs->h_ext.vlan_tci)); + offset +=VLAN_HLEN ; + } + +switch (fs->flow_type & ~(FLOW_EXT |FLOW_MAC_EXT )) { +case ETHER_FLOW : +bcmasp_netfilt_wr_m_wake (priv, nfilt,0 , + &fs->h_u.ether_spec.h_dest, + &fs->m_u.ether_spec.h_dest, +sizeof (fs->h_u.ether_spec.h_dest)); +bcmasp_netfilt_wr_m_wake (priv, nfilt,ETH_ALEN , + &fs->h_u.ether_spec.h_source, + &fs->m_u.ether_spec.h_source, +sizeof (fs->h_u.ether_spec.h_source)); +bcmasp_netfilt_wr_m_wake (priv, nfilt, (ETH_ALEN *2 ) + offset, + &fs->h_u.ether_spec.h_proto, + &fs->m_u.ether_spec.h_proto, +sizeof (fs->h_u.ether_spec.h_proto)); + +break ; +case IP_USER_FLOW : + val_16 =htons (ETH_P_IP ); + mask_16 =htons (0xFFFF ); +bcmasp_netfilt_wr_m_wake (priv, nfilt, (ETH_ALEN *2 ) + offset, + &val_16, &mask_16,sizeof (val_16)); +bcmasp_netfilt_wr_m_wake (priv, nfilt,ETH_HLEN + offset +1 , + &fs->h_u.usr_ip4_spec.tos, + &fs->m_u.usr_ip4_spec.tos, +sizeof (fs->h_u.usr_ip4_spec.tos)); +bcmasp_netfilt_wr_m_wake (priv, nfilt,ETH_HLEN + offset +9 , + &fs->h_u.usr_ip4_spec.proto, + &fs->m_u.usr_ip4_spec.proto, +sizeof (fs->h_u.usr_ip4_spec.proto)); +bcmasp_netfilt_wr_m_wake (priv, nfilt,ETH_HLEN + offset +12 , + &fs->h_u.usr_ip4_spec.ip4src, + &fs->m_u.usr_ip4_spec.ip4src, +sizeof (fs->h_u.usr_ip4_spec.ip4src)); +bcmasp_netfilt_wr_m_wake (priv, nfilt,ETH_HLEN + offset +16 , + &fs->h_u.usr_ip4_spec.ip4dst, + &fs->m_u.usr_ip4_spec.ip4dst, +sizeof (fs->h_u.usr_ip4_spec.ip4dst)); +if (!fs->m_u.usr_ip4_spec.l4_4_bytes) +break ; + +/* Only supports 20 byte IPv4 header */ + val_8 =0x45 ; + mask_8 =0xFF ; +bcmasp_netfilt_wr_m_wake (priv, nfilt,ETH_HLEN + offset, + &val_8, &mask_8,sizeof (val_8)); +bcmasp_netfilt_wr_m_wake (priv, nfilt, +ETH_HLEN +20 + offset, + &fs->h_u.usr_ip4_spec.l4_4_bytes, + &fs->m_u.usr_ip4_spec.l4_4_bytes, +sizeof (fs->h_u.usr_ip4_spec.l4_4_bytes) + ); +break ; +case TCP_V4_FLOW : + val_8 =IPPROTO_TCP ; + mask_8 =0xFF ; +bcmasp_netfilt_tcpip4_wr (priv, nfilt, &fs->h_u.tcp_ip4_spec, + &fs->m_u.tcp_ip4_spec, offset); +bcmasp_netfilt_wr_m_wake (priv, nfilt,ETH_HLEN + offset +9 , + &val_8, &mask_8,sizeof (val_8)); +break ; +case UDP_V4_FLOW : + val_8 =IPPROTO_UDP ; + mask_8 =0xFF ; +bcmasp_netfilt_tcpip4_wr (priv, nfilt, &fs->h_u.udp_ip4_spec, + &fs->m_u.udp_ip4_spec, offset); + +bcmasp_netfilt_wr_m_wake (priv, nfilt,ETH_HLEN + offset +9 , + &val_8, &mask_8,sizeof (val_8)); +break ; +case TCP_V6_FLOW : + val_8 =IPPROTO_TCP ; + mask_8 =0xFF ; +bcmasp_netfilt_tcpip6_wr (priv, nfilt, &fs->h_u.tcp_ip6_spec, + &fs->m_u.tcp_ip6_spec, offset); +bcmasp_netfilt_wr_m_wake (priv, nfilt,ETH_HLEN + offset +6 , + &val_8, &mask_8,sizeof (val_8)); +break ; +case UDP_V6_FLOW : + val_8 =IPPROTO_UDP ; + mask_8 =0xFF ; +bcmasp_netfilt_tcpip6_wr (priv, nfilt, &fs->h_u.udp_ip6_spec, + &fs->m_u.udp_ip6_spec, offset); +bcmasp_netfilt_wr_m_wake (priv, nfilt,ETH_HLEN + offset +6 , + &val_8, &mask_8,sizeof (val_8)); +break ; + } + +bcmasp_netfilt_hw_en_wake (priv, nfilt); + +return 0 ; +} + +void bcmasp_netfilt_suspend (struct bcmasp_intf *intf) +{ +struct bcmasp_priv *priv = intf->parent; +bool write = false; +int ret, i; + +/* Write all filters to HW */ +for (i =0 ; i <NUM_NET_FILTERS ; i++) { +/* If the filter does not match the port, skip programming. */ +if (!priv->net_filters[i].claimed || + priv->net_filters[i].port != intf->port) +continue ; + +if (i >0 && (i %2 ) && + priv->net_filters[i].wake_filter && + priv->net_filters[i -1 ].wake_filter) +continue ; + + ret =bcmasp_netfilt_wr_to_hw (priv, &priv->net_filters[i]); +if (!ret) + write = true; + } + +/* Successfully programmed at least one wake filter +* so enable top level wake config +*/ +if (write) +rx_filter_core_wl (priv, (ASP_RX_FILTER_OPUT_EN | +ASP_RX_FILTER_LNR_MD | +ASP_RX_FILTER_GEN_WK_EN | +ASP_RX_FILTER_NT_FLT_EN ), +ASP_RX_FILTER_BLK_CTRL ); +} + +void bcmasp_netfilt_get_all_active (struct bcmasp_intf *intf,u32 *rule_locs, +u32 *rule_cnt) +{ +struct bcmasp_priv *priv = intf->parent; +int j =0 , i; + +for (i =0 ; i <NUM_NET_FILTERS ; i++) { +if (!priv->net_filters[i].claimed || + priv->net_filters[i].port != intf->port) +continue ; + +if (i >0 && (i %2 ) && + priv->net_filters[i].wake_filter && + priv->net_filters[i -1 ].wake_filter) +continue ; + + rule_locs[j++] = priv->net_filters[i].fs.location; + } + + *rule_cnt = j; +} + +int bcmasp_netfilt_get_active (struct bcmasp_intf *intf) +{ +struct bcmasp_priv *priv = intf->parent; +int cnt =0 , i; + +for (i =0 ; i <NUM_NET_FILTERS ; i++) { +if (!priv->net_filters[i].claimed || + priv->net_filters[i].port != intf->port) +continue ; + +/* Skip over a wake filter pair */ +if (i >0 && (i %2 ) && + priv->net_filters[i].wake_filter && + priv->net_filters[i -1 ].wake_filter) +continue ; + + cnt++; + } + +return cnt; +} + +bool bcmasp_netfilt_check_dup (struct bcmasp_intf *intf, +struct ethtool_rx_flow_spec *fs) +{ +struct bcmasp_priv *priv = intf->parent; +struct ethtool_rx_flow_spec *cur; +size_t fs_size =0 ; +int i; + +for (i =0 ; i <NUM_NET_FILTERS ; i++) { +if (!priv->net_filters[i].claimed || + priv->net_filters[i].port != intf->port) +continue ; + + cur = &priv->net_filters[i].fs; + +if (cur->flow_type != fs->flow_type || + cur->ring_cookie != fs->ring_cookie) +continue ; + +switch (fs->flow_type & ~(FLOW_EXT |FLOW_MAC_EXT )) { +case ETHER_FLOW : + fs_size =sizeof (struct ethhdr ); +break ; +case IP_USER_FLOW : + fs_size =sizeof (struct ethtool_usrip4_spec ); +break ; +case TCP_V6_FLOW : +case UDP_V6_FLOW : + fs_size =sizeof (struct ethtool_tcpip6_spec ); +break ; +case TCP_V4_FLOW : +case UDP_V4_FLOW : + fs_size =sizeof (struct ethtool_tcpip4_spec ); +break ; +default : +continue ; + } + +if (memcmp (&cur->h_u, &fs->h_u, fs_size) || +memcmp (&cur->m_u, &fs->m_u, fs_size)) +continue ; + +if (cur->flow_type &FLOW_EXT ) { +if (cur->h_ext.vlan_etype != fs->h_ext.vlan_etype || + cur->m_ext.vlan_etype != fs->m_ext.vlan_etype || + cur->h_ext.vlan_tci != fs->h_ext.vlan_tci || + cur->m_ext.vlan_tci != fs->m_ext.vlan_tci || + cur->h_ext.data[0 ] != fs->h_ext.data[0 ]) +continue ; + } +if (cur->flow_type &FLOW_MAC_EXT ) { +if (memcmp (&cur->h_ext.h_dest, + &fs->h_ext.h_dest,ETH_ALEN ) || +memcmp (&cur->m_ext.h_dest, + &fs->m_ext.h_dest,ETH_ALEN )) +continue ; + } + +return true; + } + +return false; +} + +/* If no network filter found, return open filter. +* If no more open filters return NULL +*/ +struct bcmasp_net_filter *bcmasp_netfilt_get_init (struct bcmasp_intf *intf, +int loc,bool wake_filter, +bool init) +{ +struct bcmasp_net_filter *nfilter =NULL ; +struct bcmasp_priv *priv = intf->parent; +int i, open_index =-1 ; + +/* Check whether we exceed the filter table capacity */ +if (loc !=RX_CLS_LOC_ANY && loc >=NUM_NET_FILTERS ) +return ERR_PTR (-EINVAL ); + +/* If the filter location is busy (already claimed) and we are initializing +* the filter (insertion), return a busy error code. +*/ +if (loc !=RX_CLS_LOC_ANY && init && priv->net_filters[loc].claimed) +return ERR_PTR (-EBUSY ); + +/* We need two filters for wake-up, so we cannot use an odd filter */ +if (wake_filter && loc !=RX_CLS_LOC_ANY && (loc %2 )) +return ERR_PTR (-EINVAL ); + +/* Initialize the loop index based on the desired location or from 0 */ + i = loc ==RX_CLS_LOC_ANY ?0 : loc; + +for ( ; i <NUM_NET_FILTERS ; i++) { +/* Found matching network filter */ +if (!init && + priv->net_filters[i].claimed && + priv->net_filters[i].hw_index == i && + priv->net_filters[i].port == intf->port) +return &priv->net_filters[i]; + +/* If we don't need a new filter or new filter already found */ +if (!init || open_index >=0 ) +continue ; + +/* Wake filter conslidates two filters to cover more bytes +* Wake filter is open if... +* 1. It is an even filter +* 2. The current and next filter is not claimed +*/ +if (wake_filter && !(i %2 ) && !priv->net_filters[i].claimed && + !priv->net_filters[i +1 ].claimed) + open_index = i; +else if (!priv->net_filters[i].claimed) + open_index = i; + } + +if (open_index >=0 ) { + nfilter = &priv->net_filters[open_index]; + nfilter->claimed = true; + nfilter->port = intf->port; + nfilter->hw_index = open_index; + } + +if (wake_filter && open_index >=0 ) { +/* Claim next filter */ + priv->net_filters[open_index +1 ].claimed = true; + priv->net_filters[open_index +1 ].wake_filter = true; + nfilter->wake_filter = true; + } + +return nfilter ? nfilter :ERR_PTR (-EINVAL ); +} + +void bcmasp_netfilt_release (struct bcmasp_intf *intf, +struct bcmasp_net_filter *nfilt) +{ +struct bcmasp_priv *priv = intf->parent; + +if (nfilt->wake_filter) { +memset (&priv->net_filters[nfilt->hw_index +1 ],0 , +sizeof (struct bcmasp_net_filter )); + } + +memset (nfilt,0 ,sizeof (struct bcmasp_net_filter )); +} +static void bcmasp_addr_to_uint (unsigned char *addr,u32 *high,u32 *low) { *high = (u32)(addr[0 ] <<8 | addr[1 ]);
@@ -334,6 +925,9 @@ static void bcmasp_core_init_filters(struct bcmasp_priv *priv) priv->mda_filters[i].en =0 ; } +for (i =0 ; i <NUM_NET_FILTERS ; i++) +rx_filter_core_wl (priv,0x0 ,ASP_RX_FILTER_NET_CFG (i)); +/* Top level filter enable bit should be enabled at all times, set * GEN_WAKE_CLEAR to clear the network filter wake-up which would * otherwise be sticky
@@ -657,6 +1251,7 @@ static int bcmasp_probe(struct platform_device *pdev)spin_lock_init (&priv->mda_lock);spin_lock_init (&priv->clk_lock);mutex_init (&priv->wol_lock); +mutex_init (&priv->net_lock);INIT_LIST_HEAD (&priv->intfs); pdata =device_get_match_data (&pdev->dev);
drivers/net/ethernet/broadcom/asp2/bcmasp.h +40 -0
@@ -106,6 +106,14 @@#define ASP_RX_FILTER_NET_OFFSET_L3_1 (val) ((val) << 16)#define ASP_RX_FILTER_NET_OFFSET_L4 (val) ((val) << 24) +enum asp_rx_net_filter_block { +ASP_RX_FILTER_NET_L2 =0 , +ASP_RX_FILTER_NET_L3_0 , +ASP_RX_FILTER_NET_L3_1 , +ASP_RX_FILTER_NET_L4 , +ASP_RX_FILTER_NET_BLOCK_MAX +}; +#define ASP_EDPKT_OFFSET 0x9c000#define ASP_EDPKT_ENABLE 0x4#define ASP_EDPKT_ENABLE_EN BIT(0)
@@ -309,6 +317,17 @@ struct bcmasp_intf { unsigned int wol_irq_enabled:1; }; +#define NUM_NET_FILTERS 32 +struct bcmasp_net_filter { +struct ethtool_rx_flow_spec fs; + +bool claimed; +bool wake_filter; + +int port; +unsigned int hw_index; +}; +#define NUM_MDA_FILTERS 32struct bcmasp_mda_filter {/* Current owner of this filter */
@@ -361,6 +380,11 @@ struct bcmasp_priv {/* Protects accesses to ASP_CTRL_CLOCK_CTRL */ spinlock_t clk_lock; + +struct bcmasp_net_filter net_filters[NUM_NET_FILTERS ]; + +/* Network filter lock */ +struct mutex net_lock; };static inline unsigned long bcmasp_intf_rx_desc_read (struct bcmasp_intf *intf)
@@ -518,4 +542,20 @@ void bcmasp_disable_all_filters(struct bcmasp_intf *intf);void bcmasp_core_clock_set_intf (struct bcmasp_intf *intf,bool en); +struct bcmasp_net_filter *bcmasp_netfilt_get_init (struct bcmasp_intf *intf, +int loc,bool wake_filter, +bool init); + +bool bcmasp_netfilt_check_dup (struct bcmasp_intf *intf, +struct ethtool_rx_flow_spec *fs); + +void bcmasp_netfilt_release (struct bcmasp_intf *intf, +struct bcmasp_net_filter *nfilt); + +int bcmasp_netfilt_get_active (struct bcmasp_intf *intf); + +void bcmasp_netfilt_get_all_active (struct bcmasp_intf *intf,u32 *rule_locs, +u32 *rule_cnt); + +void bcmasp_netfilt_suspend (struct bcmasp_intf *intf);#endif
drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c +130 -1
147 lines not on this page · raw message
drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c +3 -0
@@ -1300,6 +1300,9 @@ static void bcmasp_suspend_to_wol(struct bcmasp_intf *intf) }umac_wl (intf, reg,UMC_MPD_CTRL ); +if (intf->wolopts &WAKE_FILTER ) +bcmasp_netfilt_suspend (intf); +/* UniMAC receive needs to be turned on */ umac_enable_set (intf,UMC_CMD_RX_EN ,1 );
Signature · 1 line
2.7.4
Justin Chen
maintainerPATCH v9 6/11 net: bcmasp: Add support for eee mode
In reply to Justin ChenAdd support for eee mode.
--- drivers/net/ethernet/broadcom/asp2/bcmasp.h | 4 ++ .../net/ethernet/broadcom/asp2/bcmasp_ethtool.c | 61 ++++++++++++++++++++++ drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c | 6 +++ 3 files changed, 71 insertions(+)
drivers/net/ethernet/broadcom/asp2/bcmasp.h +4 -0
@@ -315,6 +315,8 @@ struct bcmasp_intf {/* Used if per intf wol irq */ int wol_irq; unsigned int wol_irq_enabled:1; + +struct ethtool_eee eee; };#define NUM_NET_FILTERS 32
@@ -558,4 +560,6 @@ void bcmasp_netfilt_get_all_active(struct bcmasp_intf *intf, u32 *rule_locs, u32 *rule_cnt);void bcmasp_netfilt_suspend (struct bcmasp_intf *intf); + +void bcmasp_eee_enable_set (struct bcmasp_intf *intf,bool enable);#endif
drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c +61 -0
71 lines not on this page · raw message
drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c +6 -0
@@ -646,6 +646,9 @@ static void bcmasp_adj_link(struct net_device *dev) UMC_CMD_TX_PAUSE_IGNORE); reg |= cmd_bits;umac_wl (intf, reg,UMC_CMD ); + + intf->eee.eee_active =phy_init_eee (phydev,0 ) >=0 ; +bcmasp_eee_enable_set (intf, intf->eee.eee_active); } reg =rgmii_rl (intf,RGMII_OOB_CNTRL );
@@ -1387,6 +1390,9 @@ int bcmasp_interface_resume(struct bcmasp_intf *intf)bcmasp_resume_from_wol (intf); +if (intf->eee.eee_enabled) +bcmasp_eee_enable_set (intf, true); +netif_device_attach (dev);return 0 ;
Signature · 1 line
2.7.4
Justin Chen
maintainerPATCH v9 7/11 net: bcmasp: Add support for ethtool standard stats
In reply to Justin ChenAdd support for eth_mac_stats, rmon_stats, and eth_ctrl_stats.
--- .../net/ethernet/broadcom/asp2/bcmasp_ethtool.c | 77 ++++++++++++++++++++++ .../net/ethernet/broadcom/asp2/bcmasp_intf_defs.h | 63 +++++++++++++++++- 2 files changed, 139 insertions(+), 1 deletion(-)
drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c +77 -0
@@ -250,6 +250,80 @@ static int bcmasp_set_eee(struct net_device *dev, struct ethtool_eee *e)return phy_ethtool_set_eee (dev->phydev, e); } +static void bcmasp_get_eth_mac_stats (struct net_device *dev, +struct ethtool_eth_mac_stats *mac_stats) +{ +struct bcmasp_intf *intf =netdev_priv (dev); + + mac_stats->FramesTransmittedOK =umac_rl (intf,UMC_GTPOK ); + mac_stats->SingleCollisionFrames =umac_rl (intf,UMC_GTSCL ); + mac_stats->MultipleCollisionFrames =umac_rl (intf,UMC_GTMCL ); + mac_stats->FramesReceivedOK =umac_rl (intf,UMC_GRPOK ); + mac_stats->FrameCheckSequenceErrors =umac_rl (intf,UMC_GRFCS ); + mac_stats->AlignmentErrors =umac_rl (intf,UMC_GRALN ); + mac_stats->OctetsTransmittedOK =umac_rl (intf,UMC_GTBYT ); + mac_stats->FramesWithDeferredXmissions =umac_rl (intf,UMC_GTDRF ); + mac_stats->LateCollisions =umac_rl (intf,UMC_GTLCL ); + mac_stats->FramesAbortedDueToXSColls =umac_rl (intf,UMC_GTXCL ); + mac_stats->OctetsReceivedOK =umac_rl (intf,UMC_GRBYT ); + mac_stats->MulticastFramesXmittedOK =umac_rl (intf,UMC_GTMCA ); + mac_stats->BroadcastFramesXmittedOK =umac_rl (intf,UMC_GTBCA ); + mac_stats->FramesWithExcessiveDeferral =umac_rl (intf,UMC_GTEDF ); + mac_stats->MulticastFramesReceivedOK =umac_rl (intf,UMC_GRMCA ); + mac_stats->BroadcastFramesReceivedOK =umac_rl (intf,UMC_GRBCA ); +} + +static const struct ethtool_rmon_hist_range bcmasp_rmon_ranges[] = { + {0 ,64 }, + {65 ,127 }, + {128 ,255 }, + {256 ,511 }, + {512 ,1023 }, + {1024 ,1518 }, + {1519 ,1522 }, + {} +}; + +static void bcmasp_get_rmon_stats (struct net_device *dev, +struct ethtool_rmon_stats *rmon_stats, +const struct ethtool_rmon_hist_range **ranges) +{ +struct bcmasp_intf *intf =netdev_priv (dev); + + *ranges = bcmasp_rmon_ranges; + + rmon_stats->undersize_pkts =umac_rl (intf,UMC_RRUND ); + rmon_stats->oversize_pkts =umac_rl (intf,UMC_GROVR ); + rmon_stats->fragments =umac_rl (intf,UMC_RRFRG ); + rmon_stats->jabbers =umac_rl (intf,UMC_GRJBR ); + + rmon_stats->hist[0 ] =umac_rl (intf,UMC_GR64 ); + rmon_stats->hist[1 ] =umac_rl (intf,UMC_GR127 ); + rmon_stats->hist[2 ] =umac_rl (intf,UMC_GR255 ); + rmon_stats->hist[3 ] =umac_rl (intf,UMC_GR511 ); + rmon_stats->hist[4 ] =umac_rl (intf,UMC_GR1023 ); + rmon_stats->hist[5 ] =umac_rl (intf,UMC_GR1518 ); + rmon_stats->hist[6 ] =umac_rl (intf,UMC_GRMGV ); + + rmon_stats->hist_tx[0 ] =umac_rl (intf,UMC_TR64 ); + rmon_stats->hist_tx[1 ] =umac_rl (intf,UMC_TR127 ); + rmon_stats->hist_tx[2 ] =umac_rl (intf,UMC_TR255 ); + rmon_stats->hist_tx[3 ] =umac_rl (intf,UMC_TR511 ); + rmon_stats->hist_tx[4 ] =umac_rl (intf,UMC_TR1023 ); + rmon_stats->hist_tx[5 ] =umac_rl (intf,UMC_TR1518 ); + rmon_stats->hist_tx[6 ] =umac_rl (intf,UMC_TRMGV ); +} + +static void bcmasp_get_eth_ctrl_stats (struct net_device *dev, +struct ethtool_eth_ctrl_stats *ctrl_stats) +{ +struct bcmasp_intf *intf =netdev_priv (dev); + + ctrl_stats->MACControlFramesTransmitted =umac_rl (intf,UMC_GTXCF ); + ctrl_stats->MACControlFramesReceived =umac_rl (intf,UMC_GRXCF ); + ctrl_stats->UnsupportedOpcodesReceived =umac_rl (intf,UMC_GRXUO ); +} +const struct ethtool_ops bcmasp_ethtool_ops = { .get_drvinfo = bcmasp_get_drvinfo, .get_link = ethtool_op_get_link,
@@ -263,4 +337,7 @@ const struct ethtool_ops bcmasp_ethtool_ops = { .set_rxnfc = bcmasp_set_rxnfc, .set_eee = bcmasp_set_eee, .get_eee = bcmasp_get_eee, + .get_eth_mac_stats = bcmasp_get_eth_mac_stats, + .get_rmon_stats = bcmasp_get_rmon_stats, + .get_eth_ctrl_stats = bcmasp_get_eth_ctrl_stats, };
drivers/net/ethernet/broadcom/asp2/bcmasp_intf_defs.h +62 -1
69 lines not on this page · raw message
Signature · 1 line
2.7.4
Justin Chen
maintainerPATCH v9 8/11 net: bcmasp: Add support for ethtool driver stats
In reply to Justin ChenAdd support for ethernet driver specific stats.
---
v9
- Removed tx_realloc_offload, this stat is no longer relevant with skb_cow_head().
- Added tx_timeout_cnt
v8
- Address maybe uninit variable warning
drivers/net/ethernet/broadcom/asp2/bcmasp.c | 4 +- drivers/net/ethernet/broadcom/asp2/bcmasp.h | 21 +++ .../net/ethernet/broadcom/asp2/bcmasp_ethtool.c | 160 +++++++++++++++++++++ drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c | 18 ++- 4 files changed, 199 insertions(+), 4 deletions(-)
drivers/net/ethernet/broadcom/asp2/bcmasp.c +3 -1
@@ -895,8 +895,10 @@ int bcmasp_set_en_mda_filter(struct bcmasp_intf *intf, unsigned char *addr,/* Attempt to combine filters */ ret =bcmasp_combine_set_filter (intf, addr, mask, i); -if (!ret) +if (!ret) { + intf->mib.filters_combine_cnt++;return 0 ; + } }/* Create new filter if possible */
drivers/net/ethernet/broadcom/asp2/bcmasp.h +21 -0
@@ -244,6 +244,26 @@ struct bcmasp_intf_stats64 {struct u64_stats_sync syncp; }; +struct bcmasp_mib_counters { +u32 edpkt_ts; +u32 edpkt_rx_pkt_cnt; +u32 edpkt_hdr_ext_cnt; +u32 edpkt_hdr_out_cnt; +u32 umac_frm_cnt; +u32 fb_frm_cnt; +u32 fb_rx_fifo_depth; +u32 fb_out_frm_cnt; +u32 fb_filt_out_frm_cnt; +u32 alloc_rx_skb_failed; +u32 tx_dma_failed; +u32 mc_filters_full_cnt; +u32 uc_filters_full_cnt; +u32 filters_combine_cnt; +u32 promisc_filters_cnt; +u32 tx_realloc_offload_failed; +u32 tx_timeout_cnt; +}; +struct bcmasp_intf_ops {unsigned long (*rx_desc_read)(struct bcmasp_intf *intf);void (*rx_buffer_write)(struct bcmasp_intf *intf,dma_addr_t addr);
@@ -309,6 +329,7 @@ struct bcmasp_intf {/* Statistics */ struct bcmasp_intf_stats64 stats64; +struct bcmasp_mib_counters mib;u32 wolopts;u8 sopass[SOPASS_MAX ];
drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c +160 -0
176 lines not on this page · raw message
drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c +15 -3
@@ -104,15 +104,19 @@ static void bcmasp_set_rx_mode(struct net_device *dev)netdev_for_each_mc_addr (ha, dev) { ret =bcmasp_set_en_mda_filter (intf, ha->addr, mask); -if (ret) +if (ret) { + intf->mib.mc_filters_full_cnt++; goto set_promisc; + } } }netdev_for_each_uc_addr (ha, dev) { ret =bcmasp_set_en_mda_filter (intf, ha->addr, mask); -if (ret) +if (ret) { + intf->mib.uc_filters_full_cnt++; goto set_promisc; + } }spin_unlock_bh (&intf->parent->mda_lock);
@@ -120,6 +124,7 @@ static void bcmasp_set_rx_mode(struct net_device *dev) set_promisc:bcmasp_set_promisc (intf,1 ); + intf->mib.promisc_filters_cnt++;/* disable all filters used by this port */ bcmasp_disable_all_filters (intf);
@@ -155,6 +160,7 @@ static struct sk_buff *bcmasp_csum_offload(struct net_device *dev,struct sk_buff *skb, bool *csum_hw) { + struct bcmasp_intf *intf = netdev_priv(dev);u32 header =0 , header2 =0 , epkt =0 ;struct bcmasp_pkt_offload *offload;unsigned int header_cnt =0 ;
@@ -165,8 +171,10 @@ static struct sk_buff *bcmasp_csum_offload(struct net_device *dev,return skb; ret =skb_cow_head (skb,sizeof (*offload)); -if (ret <0 ) +if (ret <0 ) { + intf->mib.tx_realloc_offload_failed++; goto help; + }switch (skb->protocol) {case htons (ETH_P_IP ):
@@ -305,6 +313,7 @@ static netdev_tx_t bcmasp_xmit(struct sk_buff *skb, struct net_device *dev) }if (dma_mapping_error (kdev, mapping)) { + intf->mib.tx_dma_failed++; spb_index = intf->tx_spb_index;for (j =0 ; j < i; j++) {bcmasp_clean_txcb (intf, spb_index);
@@ -541,6 +550,8 @@ static int bcmasp_rx_poll(struct napi_struct *napi, int budget)u64_stats_update_begin (&stats->syncp);u64_stats_inc (&stats->rx_dropped);u64_stats_update_end (&stats->syncp); + intf->mib.alloc_rx_skb_failed++; + goto next; }
@@ -1116,6 +1127,7 @@ static void bcmasp_tx_timeout(struct net_device *dev, unsigned int txqueue)struct bcmasp_intf *intf =netdev_priv (dev);netif_dbg (intf, tx_err, dev,"transmit timeout!\n" ); + intf->mib.tx_timeout_cnt++; } static int bcmasp_get_phys_port_name(struct net_device *dev,
Signature · 1 line
2.7.4
Justin Chen
maintainerPATCH v9 9/11 net: phy: mdio-bcm-unimac: Add asp v2.0 support
In reply to Justin ChenAdd mdio compat string for ASP 2.0 ethernet driver.
--- drivers/net/mdio/mdio-bcm-unimac.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/mdio/mdio-bcm-unimac.c +2 -0
@@ -334,6 +334,8 @@ static SIMPLE_DEV_PM_OPS(unimac_mdio_pm_ops, unimac_mdio_suspend, unimac_mdio_resume);static const struct of_device_id unimac_mdio_ids[] = { + { .compatible ="brcm,asp-v2.1-mdio" , }, + { .compatible ="brcm,asp-v2.0-mdio" , }, { .compatible ="brcm,genet-mdio-v5" , }, { .compatible ="brcm,genet-mdio-v4" , }, { .compatible ="brcm,genet-mdio-v3" , },
Signature · 1 line
2.7.4
Justin Chen
maintainerPATCH v9 10/11 net: phy: bcm7xxx: Add EPHY entry for 74165
In reply to Justin ChenFrom: Florian Fainelli <[email protected]>
74165 is a 16nm process SoC with a 10/100 integrated Ethernet PHY, utilize the recently defined 16nm EPHY macro to configure that PHY.
--- drivers/net/phy/bcm7xxx.c | 1 + include/linux/brcmphy.h | 1 + 2 files changed, 2 insertions(+)
drivers/net/phy/bcm7xxx.c +1 -0
@@ -913,6 +913,7 @@ static struct phy_driver bcm7xxx_driver[] = {BCM7XXX_28NM_GPHY (PHY_ID_BCM7278 ,"Broadcom BCM7278" ),BCM7XXX_28NM_GPHY (PHY_ID_BCM7364 ,"Broadcom BCM7364" ),BCM7XXX_28NM_GPHY (PHY_ID_BCM7366 ,"Broadcom BCM7366" ), +BCM7XXX_16NM_EPHY (PHY_ID_BCM74165 ,"Broadcom BCM74165" ),BCM7XXX_28NM_GPHY (PHY_ID_BCM74371 ,"Broadcom BCM74371" ),BCM7XXX_28NM_GPHY (PHY_ID_BCM7439 ,"Broadcom BCM7439" ), BCM7XXX_28NM_GPHY(PHY_ID_BCM7439_2, "Broadcom BCM7439 (2)"),
include/linux/brcmphy.h +1 -0
@@ -44,6 +44,7 @@#define PHY_ID_BCM7366 0x600d8490#define PHY_ID_BCM7346 0x600d8650#define PHY_ID_BCM7362 0x600d84b0 +#define PHY_ID_BCM74165 0x359052c0#define PHY_ID_BCM7425 0x600d86b0#define PHY_ID_BCM7429 0x600d8730#define PHY_ID_BCM7435 0x600d8750
Signature · 1 line
2.7.4
Justin Chen
maintainerPATCH v9 11/11 MAINTAINERS: ASP 2.0 Ethernet driver maintainers
In reply to Justin ChenAdd maintainers entry for ASP 2.0 Ethernet driver.
---
v3
- Change from gmail to broadcom emails
MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+)
MAINTAINERS +9 -0
@@ -4215,6 +4215,15 @@ F: drivers/net/mdio/mdio-bcm-unimac.c F: include/linux/platform_data/bcmgenet.h F: include/linux/platform_data/mdio-bcm-unimac.h +BROADCOM ASP 2.0 ETHERNET DRIVER +M: Justin Chen <[email protected]> +M: Florian Fainelli <[email protected]> +L: [email protected] +L: [email protected] +S: Supported +F: Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml +F: drivers/net/ethernet/broadcom/asp2/ + BROADCOM IPROC ARM ARCHITECTURE M: Ray Jui <[email protected]> M: Scott Branden <[email protected]>
Signature · 1 line
2.7.4
This series was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:
Quoted 8 lines · On Thu, 13 Jul 2023 15:18:55 -0700 you wrote:
Add support for the Broadcom ASP 2.0 Ethernet controller which is first introduced with 72165.
Florian Fainelli (2):
dt-bindings: net: Brcm ASP 2.0 Ethernet controller
net: phy: bcm7xxx: Add EPHY entry for 74165[...]
Here is the summary with links:
- [net-next,v9,01/11] dt-bindings: net: brcm,unimac-mdio: Add asp-v2.0
https://git.kernel.org/netdev/net-next/c/27312c43472b - [net-next,v9,02/11] dt-bindings: net: Brcm ASP 2.0 Ethernet controller https://git.kernel.org/netdev/net-next/c/a29401be8c69 - [net-next,v9,03/11] net: bcmasp: Add support for ASP2.0 Ethernet controller https://git.kernel.org/netdev/net-next/c/490cb412007d - [net-next,v9,04/11] net: bcmasp: Add support for WoL magic packet https://git.kernel.org/netdev/net-next/c/a2f0751206b0 - [net-next,v9,05/11] net: bcmasp: Add support for wake on net filters https://git.kernel.org/netdev/net-next/c/c5d511c49587 - [net-next,v9,06/11] net: bcmasp: Add support for eee mode https://git.kernel.org/netdev/net-next/c/550e6f345687 - [net-next,v9,07/11] net: bcmasp: Add support for ethtool standard stats https://git.kernel.org/netdev/net-next/c/649315346729 - [net-next,v9,08/11] net: bcmasp: Add support for ethtool driver stats https://git.kernel.org/netdev/net-next/c/7c10691e1f5e - [net-next,v9,09/11] net: phy: mdio-bcm-unimac: Add asp v2.0 support https://git.kernel.org/netdev/net-next/c/9de2b402d818 - [net-next,v9,10/11] net: phy: bcm7xxx: Add EPHY entry for 74165 https://git.kernel.org/netdev/net-next/c/9fa0bba012c2 - [net-next,v9,11/11] MAINTAINERS: ASP 2.0 Ethernet driver maintainers https://git.kernel.org/netdev/net-next/c/3abf3d15ffff
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html