[net-next v9 10/11] net: phy: bcm7xxx: Add EPHY entry for 74165

2023-07-13 Thread Justin Chen
From: Florian Fainelli 

74165 is a 16nm process SoC with a 10/100 integrated Ethernet PHY,
utilize the recently defined 16nm EPHY macro to configure that PHY.

Reviewed-by: Simon Horman 
Reviewed-by: Andrew Lunn 
Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
---
 drivers/net/phy/bcm7xxx.c | 1 +
 include/linux/brcmphy.h   | 1 +
 2 files changed, 2 insertions(+)

diff --git a/drivers/net/phy/bcm7xxx.c b/drivers/net/phy/bcm7xxx.c
index f8c17a253f8b..8478b081c058 100644
--- a/drivers/net/phy/bcm7xxx.c
+++ b/drivers/net/phy/bcm7xxx.c
@@ -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)"),
diff --git a/include/linux/brcmphy.h b/include/linux/brcmphy.h
index 5d732f48f787..c55810a43541 100644
--- a/include/linux/brcmphy.h
+++ b/include/linux/brcmphy.h
@@ -44,6 +44,7 @@
 #define PHY_ID_BCM7366 0x600d8490
 #define PHY_ID_BCM7346 0x600d8650
 #define PHY_ID_BCM7362 0x600d84b0
+#define PHY_ID_BCM741650x359052c0
 #define PHY_ID_BCM7425 0x600d86b0
 #define PHY_ID_BCM7429 0x600d8730
 #define PHY_ID_BCM7435 0x600d8750
-- 
2.7.4



smime.p7s
Description: S/MIME Cryptographic Signature


[net-next v9 11/11] MAINTAINERS: ASP 2.0 Ethernet driver maintainers

2023-07-13 Thread Justin Chen
Add maintainers entry for ASP 2.0 Ethernet driver.

Reviewed-by: Simon Horman 
Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
---
v3
- Change from gmail to broadcom emails

 MAINTAINERS | 9 +
 1 file changed, 9 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 99f18f6e8bc6..da9ab7edd507 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -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 
+M: Florian Fainelli 
+L: bcm-kernel-feedback-l...@broadcom.com
+L: net...@vger.kernel.org
+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 
 M: Scott Branden 
-- 
2.7.4



smime.p7s
Description: S/MIME Cryptographic Signature


[net-next v9 09/11] net: phy: mdio-bcm-unimac: Add asp v2.0 support

2023-07-13 Thread Justin Chen
Add mdio compat string for ASP 2.0 ethernet driver.

Reviewed-by: Simon Horman 
Reviewed-by: Andrew Lunn 
Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
---
 drivers/net/mdio/mdio-bcm-unimac.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/mdio/mdio-bcm-unimac.c 
b/drivers/net/mdio/mdio-bcm-unimac.c
index bfc9be23c973..6b26a0803696 100644
--- a/drivers/net/mdio/mdio-bcm-unimac.c
+++ b/drivers/net/mdio/mdio-bcm-unimac.c
@@ -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", },
-- 
2.7.4



smime.p7s
Description: S/MIME Cryptographic Signature


[net-next v9 07/11] net: bcmasp: Add support for ethtool standard stats

2023-07-13 Thread Justin Chen
Add support for eth_mac_stats, rmon_stats, and eth_ctrl_stats.

Signed-off-by: Justin Chen 
---
 .../net/ethernet/broadcom/asp2/bcmasp_ethtool.c| 77 ++
 .../net/ethernet/broadcom/asp2/bcmasp_intf_defs.h  | 63 +-
 2 files changed, 139 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c 
b/drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c
index 1e96a69043f3..59d853c2293c 100644
--- a/drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c
+++ b/drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c
@@ -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,
 };
diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp_intf_defs.h 
b/drivers/net/ethernet/broadcom/asp2/bcmasp_intf_defs.h
index b259a475207f..ad742612895f 100644
--- a/drivers/net/ethernet/broadcom/asp2/bcmasp_intf

[net-next v9 08/11] net: bcmasp: Add support for ethtool driver stats

2023-07-13 Thread Justin Chen
Add support for ethernet driver specific stats.

Signed-off-by: Justin Chen 
---
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(-)

diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp.c 
b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
index 92dfea961add..a9984efff6d1 100644
--- a/drivers/net/ethernet/broadcom/asp2/bcmasp.c
+++ b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
@@ -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 */
diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp.h 
b/drivers/net/ethernet/broadcom/asp2/bcmasp.h
index 18a44044ad93..6bfcaa7f95a8 100644
--- a/drivers/net/ethernet/broadcom/asp2/bcmasp.h
+++ b/drivers/net/ethernet/broadcom/asp2/bcmasp.h
@@ -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];
diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c 
b/drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c
index 59d853c2293c..c4f1604d5ab3 100644
--- a/drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c
+++ b/drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
 #define pr_fmt(fmt)"bcmasp_ethtool: " fmt
 
+#include 
 #include 
 #include 
 #include 
@@ -8,6 +9,162 @@
 #include "bcmasp.h"
 #include "bcmasp_intf_defs.h"
 
+enum bcmasp_stat_type {
+   BCMASP_STAT_RX_EDPKT,
+   BCMASP_STAT_RX_CTRL,
+   BCMASP_STAT_RX_CTRL_PER_INTF,
+   BCMASP_STAT_SOFT,
+};
+
+struct bcmasp_stats {
+   char stat_string[ETH_GSTRING_LEN];
+   enum bcmasp_stat_type type;
+   u32 reg_offset;
+};
+
+#define STAT_BCMASP_SOFT_MIB(str) { \
+   .stat_string = str, \
+   .type = BCMASP_STAT_SOFT, \
+}
+
+#define STAT_BCMASP_OFFSET(str, _type, offset) { \
+   .stat_string = str, \
+   .type = _type, \
+   .reg_offset = offset, \
+}
+
+#define STAT_BCMASP_RX_EDPKT(str, offset) \
+   STAT_BCMASP_OFFSET(str, BCMASP_STAT_RX_EDPKT, offset)
+#define STAT_BCMASP_RX_CTRL(str, offset) \
+   STAT_BCMASP_OFFSET(str, BCMASP_STAT_RX_CTRL, offset)
+#define STAT_BCMASP_RX_CTRL_PER_INTF(str, offset) \
+   STAT_BCMASP_OFFSET(str, BCMASP_STAT_RX_CTRL_PER_INTF, offset)
+
+/* Must match the order of struct bcmasp_mib_counters */
+static const struct bcmasp_stats bcmasp_gstrings_stats[] = {
+   /* EDPKT counters */
+   STAT_BCMASP_RX_EDPKT("RX Time Stamp", ASP_EDPKT_RX_TS_COUNTER),
+   STAT_BCMASP_RX_EDPKT("RX PKT Count", ASP_EDPKT_RX_PKT_CNT),
+   STAT_BCMASP_RX_EDPKT("RX PKT Buffered", ASP_EDPKT_HDR_EXTR_CNT),
+   STAT_BCMASP_RX_EDPKT("RX PKT Pushed to DRAM", ASP_EDPKT_HDR_OUT_CNT),
+   /* ASP RX control */
+   STAT_BCMASP_RX_CTRL_PER_INTF("Frames From Unimac",
+ASP_RX_CTRL_UMAC_0_FRAME_COUNT),
+   STAT_BCMASP_RX_CTRL_PER_INTF("Frames From Port",
+ASP_RX_CTRL_FB_0_FRAME_COUNT),
+   STAT_BCMASP_RX_CTRL_PER_INTF("RX Buffer FIFO Depth",
+  

[net-next v9 05/11] net: bcmasp: Add support for wake on net filters

2023-07-13 Thread Justin Chen
Add support for wake on network filters. The max match is 256 bytes.

Signed-off-by: Justin Chen 
---
 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(-)

diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp.c 
b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
index 894c14dca911..92dfea961add 100644
--- a/drivers/net/ethernet/broadcom/asp2/bcmasp.c
+++ b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
@@ -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) 

[net-next v9 06/11] net: bcmasp: Add support for eee mode

2023-07-13 Thread Justin Chen
Add support for eee mode.

Signed-off-by: Justin Chen 
---
 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(+)

diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp.h 
b/drivers/net/ethernet/broadcom/asp2/bcmasp.h
index fbbde04a0eab..18a44044ad93 100644
--- a/drivers/net/ethernet/broadcom/asp2/bcmasp.h
+++ b/drivers/net/ethernet/broadcom/asp2/bcmasp.h
@@ -315,6 +315,8 @@ struct bcmasp_intf {
/* Used if per intf wol irq */
int wol_irq;
unsigned intwol_irq_enabled:1;
+
+   struct ethtool_eee  eee;
 };
 
 #define NUM_NET_FILTERS32
@@ -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
diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c 
b/drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c
index eddd1c43f00e..1e96a69043f3 100644
--- a/drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c
+++ b/drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c
@@ -191,6 +191,65 @@ static int bcmasp_get_rxnfc(struct net_device *dev, struct 
ethtool_rxnfc *cmd,
return err;
 }
 
+void bcmasp_eee_enable_set(struct bcmasp_intf *intf, bool enable)
+{
+   u32 reg;
+
+   reg = umac_rl(intf, UMC_EEE_CTRL);
+   if (enable)
+   reg |= EEE_EN;
+   else
+   reg &= ~EEE_EN;
+   umac_wl(intf, reg, UMC_EEE_CTRL);
+
+   intf->eee.eee_enabled = enable;
+   intf->eee.eee_active = enable;
+}
+
+static int bcmasp_get_eee(struct net_device *dev, struct ethtool_eee *e)
+{
+   struct bcmasp_intf *intf = netdev_priv(dev);
+   struct ethtool_eee *p = >eee;
+
+   if (!dev->phydev)
+   return -ENODEV;
+
+   e->eee_enabled = p->eee_enabled;
+   e->eee_active = p->eee_active;
+   e->tx_lpi_enabled = p->tx_lpi_enabled;
+   e->tx_lpi_timer = umac_rl(intf, UMC_EEE_LPI_TIMER);
+
+   return phy_ethtool_get_eee(dev->phydev, e);
+}
+
+static int bcmasp_set_eee(struct net_device *dev, struct ethtool_eee *e)
+{
+   struct bcmasp_intf *intf = netdev_priv(dev);
+   struct ethtool_eee *p = >eee;
+   int ret;
+
+   if (!dev->phydev)
+   return -ENODEV;
+
+   if (!p->eee_enabled) {
+   bcmasp_eee_enable_set(intf, false);
+   } else {
+   ret = phy_init_eee(dev->phydev, 0);
+   if (ret) {
+   netif_err(intf, hw, dev,
+ "EEE initialization failed: %d\n", ret);
+   return ret;
+   }
+
+   umac_wl(intf, e->tx_lpi_timer, UMC_EEE_LPI_TIMER);
+   intf->eee.eee_active = ret >= 0;
+   intf->eee.tx_lpi_enabled = e->tx_lpi_enabled;
+   bcmasp_eee_enable_set(intf, true);
+   }
+
+   return phy_ethtool_set_eee(dev->phydev, e);
+}
+
 const struct ethtool_ops bcmasp_ethtool_ops = {
.get_drvinfo= bcmasp_get_drvinfo,
.get_link   = ethtool_op_get_link,
@@ -202,4 +261,6 @@ const struct ethtool_ops bcmasp_ethtool_ops = {
.set_wol= bcmasp_set_wol,
.get_rxnfc  = bcmasp_get_rxnfc,
.set_rxnfc  = bcmasp_set_rxnfc,
+   .set_eee= bcmasp_set_eee,
+   .get_eee= bcmasp_get_eee,
 };
diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c 
b/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c
index ad8422334f38..051f882b2766 100644
--- a/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c
+++ b/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c
@@ -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;
-- 
2.7.4



smime.p7s
Description: S/MIME Cryptographic Signature


[net-next v9 03/11] net: bcmasp: Add support for ASP2.0 Ethernet controller

2023-07-13 Thread Justin Chen
Add 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.

Reviewed-by: Simon Horman 
Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
---
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

diff --git a/drivers/net/ethernet/broadcom/Kconfig 
b/drivers/net/ethernet/broadcom/Kconfig
index 948586bf1b5b..d4166141145d 100644
--- a/drivers/net/ethernet/broadcom/Kconfig
+++ b/drivers/net/ethernet/broadcom/Kconfig
@@ -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
diff --git a/drivers/net/ethernet/broadcom/Makefile 
b/drivers/net/ethernet/broadcom/Makefile
index 0ddfb5b5d53c..bac5cb6ad0cd 100644
--- a/drivers/net/ethernet/broadcom/Makefile
+++ b/drivers/net/ethernet/broadcom/Makefile
@@ -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/
diff --git a/drivers/net/ethernet/broadcom/asp2/Makefile 
b/drivers/net/ethernet/broadcom/asp2/Makefile
new file mode 100644
index ..e07550315f83
--- /dev/null
+++ b/drivers/net/ethernet/broadcom/asp2/Makefile
@@ -0,0 +1,2 @@
+obj-$(CONFIG_BCMASP) += bcm-asp.o
+bcm-asp-objs := bcmasp.o bcmasp_intf.o bcmasp_ethtool.o
diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp.c 
b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
new file mode 100644
index ..83494641b545
--- /dev/null
+++ b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
@@ -0,0 +1,696 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Broadcom STB ASP 2.0 Driver
+ *
+ * Copyright (c) 2023 Broadcom
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "bcmasp.h"
+#include "bcmasp_intf_defs.h"
+
+static void _intr2_mask_clear(struct bcmasp_priv *priv, u32 mask)
+{
+   intr2_core_wl(priv, mask, ASP_INTR2_MA

[net-next v9 04/11] net: bcmasp: Add support for WoL magic packet

2023-07-13 Thread Justin Chen
Add support for Wake-On-Lan magic packet and magic packet with password.

Signed-off-by: Justin Chen 
---
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(-)

diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp.c 
b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
index 83494641b545..894c14dca911 100644
--- a/drivers/net/ethernet/broadcom/asp2/bcmasp.c
+++ b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
@@ -436,6 +436,135 @@ void bcmasp_core_clock_set_intf(struct bcmasp_intf *intf, 
bool en)
spin_unlock_irqrestore(>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(>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(>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 = >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(>dev, 1);
+}
+
+static void bcmasp_enable_wol_shared(struct bcmasp_intf *intf, bool en)
+{
+   struct bcmasp_priv *priv = intf->parent;
+   struct device *dev = >pdev->dev;
+
+   if (en) {
+   if (priv->wol_irq_enabled_mask) {
+   set_bit(intf->port, >wol_irq_enabled_mask);
+   return;
+   }
+
+   /* First enable */
+   set_bit(intf->port, >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, >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 = >dev;
+   struct bcmasp_intf *intf;
+   int irq;
+
+   list_for_each_entry(intf, >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(>dev, 1);
+   }
+}
+
+static void bcmasp_enable_wol_per_intf(struct bcmasp_intf *intf, bool en)
+{
+   struct device *dev = >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, >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,

[net-next v9 02/11] dt-bindings: net: Brcm ASP 2.0 Ethernet controller

2023-07-13 Thread Justin Chen
From: Florian Fainelli 

Add a binding document for the Broadcom ASP 2.0 Ethernet
controller.

Reviewed-by: Conor Dooley 
Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
---
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

diff --git a/Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml 
b/Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml
new file mode 100644
index ..aa3162c74833
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml
@@ -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 
+  - Florian Fainelli 
+
+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 
+#include 
+
+ethernet@9c0 {
+compatible = "brcm,bcm72165-asp", "brcm,asp-v2.0";
+reg = <0x9c0 0x1fff14>;
+interrupts = ;
+ranges = <0x0 0x9c0 0x1fff14>;
+clocks = < 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 = <>;
+};
+
+port@1 {
+reg = <1>;
+brcm,channel = <9>;
+phy-mode = "rgmii";
+phy-handle = <>;
+};
+};
+};
-- 
2.7.4



smime.p7s
Description: S/MIME Cryptographic Signature


[net-next v9 01/11] dt-bindings: net: brcm,unimac-mdio: Add asp-v2.0

2023-07-13 Thread Justin Chen
The ASP 2.0 Ethernet controller uses a brcm unimac.

Reviewed-by: Simon Horman 
Acked-by: Conor Dooley 
Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
---
 Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml 
b/Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml
index 0be426ee1e44..6684810fcbf0 100644
--- a/Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml
+++ b/Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml
@@ -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:
-- 
2.7.4



smime.p7s
Description: S/MIME Cryptographic Signature


[net-next v9 00/11] Brcm ASP 2.0 Ethernet Controller

2023-07-13 Thread Justin Chen
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

-- 
2.7.4



smime.p7s
Description: S/MIME Cryptographic Signature


[PATCH net-next v8 11/11] MAINTAINERS: ASP 2.0 Ethernet driver maintainers

2023-06-16 Thread Justin Chen
Add maintainers entry for ASP 2.0 Ethernet driver.

Reviewed-by: Simon Horman 
Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
---
v3
- Change from gmail to broadcom emails

 MAINTAINERS | 9 +
 1 file changed, 9 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 7322963b0670..adbbfe636c0c 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4195,6 +4195,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 
+M: Florian Fainelli 
+L: bcm-kernel-feedback-l...@broadcom.com
+L: net...@vger.kernel.org
+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 
 M: Scott Branden 
-- 
2.7.4



smime.p7s
Description: S/MIME Cryptographic Signature


[PATCH net-next v8 08/11] net: bcmasp: Add support for ethtool driver stats

2023-06-16 Thread Justin Chen
Add support for ethernet driver specific stats.

Signed-off-by: Justin Chen 
---
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   |  17 ++-
 4 files changed, 198 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp.c 
b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
index 51b7aa8365c8..a8905fef4f8a 100644
--- a/drivers/net/ethernet/broadcom/asp2/bcmasp.c
+++ b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
@@ -890,8 +890,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 */
diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp.h 
b/drivers/net/ethernet/broadcom/asp2/bcmasp.h
index d6740077877a..1d5c3be575d7 100644
--- a/drivers/net/ethernet/broadcom/asp2/bcmasp.h
+++ b/drivers/net/ethernet/broadcom/asp2/bcmasp.h
@@ -245,6 +245,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_realloc_offload;
+};
+
 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);
@@ -307,6 +327,7 @@ struct bcmasp_intf {
 
/* Statistics */
struct bcmasp_intf_stats64  stats64;
+   struct bcmasp_mib_counters  mib;
 
u32 wolopts;
u8  sopass[SOPASS_MAX];
diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c 
b/drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c
index 59d853c2293c..81a84ba7a394 100644
--- a/drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c
+++ b/drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
 #define pr_fmt(fmt)"bcmasp_ethtool: " fmt
 
+#include 
 #include 
 #include 
 #include 
@@ -8,6 +9,162 @@
 #include "bcmasp.h"
 #include "bcmasp_intf_defs.h"
 
+enum bcmasp_stat_type {
+   BCMASP_STAT_RX_EDPKT,
+   BCMASP_STAT_RX_CTRL,
+   BCMASP_STAT_RX_CTRL_PER_INTF,
+   BCMASP_STAT_SOFT,
+};
+
+struct bcmasp_stats {
+   char stat_string[ETH_GSTRING_LEN];
+   enum bcmasp_stat_type type;
+   u32 reg_offset;
+};
+
+#define STAT_BCMASP_SOFT_MIB(str) { \
+   .stat_string = str, \
+   .type = BCMASP_STAT_SOFT, \
+}
+
+#define STAT_BCMASP_OFFSET(str, _type, offset) { \
+   .stat_string = str, \
+   .type = _type, \
+   .reg_offset = offset, \
+}
+
+#define STAT_BCMASP_RX_EDPKT(str, offset) \
+   STAT_BCMASP_OFFSET(str, BCMASP_STAT_RX_EDPKT, offset)
+#define STAT_BCMASP_RX_CTRL(str, offset) \
+   STAT_BCMASP_OFFSET(str, BCMASP_STAT_RX_CTRL, offset)
+#define STAT_BCMASP_RX_CTRL_PER_INTF(str, offset) \
+   STAT_BCMASP_OFFSET(str, BCMASP_STAT_RX_CTRL_PER_INTF, offset)
+
+/* Must match the order of struct bcmasp_mib_counters */
+static const struct bcmasp_stats bcmasp_gstrings_stats[] = {
+   /* EDPKT counters */
+   STAT_BCMASP_RX_EDPKT("RX Time Stamp", ASP_EDPKT_RX_TS_COUNTER),
+   STAT_BCMASP_RX_EDPKT("RX PKT Count", ASP_EDPKT_RX_PKT_CNT),
+   STAT_BCMASP_RX_EDPKT("RX PKT Buffered", ASP_EDPKT_HDR_EXTR_CNT),
+   STAT_BCMASP_RX_EDPKT("RX PKT Pushed to DRAM", ASP_EDPKT_HDR_OUT_CNT),
+   /* ASP RX control */
+   STAT_BCMASP_RX_CTRL_PER_INTF("Frames From Unimac",
+ASP_RX_CTRL_UMAC_0_FRAME_COUNT),
+   STAT_BCMASP_RX_CTRL_PER_INTF("Frames From Port",
+ASP_RX_CTRL_FB_0_FRAME_COUNT),
+   STAT_BCMASP_RX_CTRL_PER_INTF("RX Buffer FIFO Depth",
+ASP_RX_CTRL_FB_RX_FIFO_DEPTH),
+   STAT_BCMASP_RX_CTRL("Frames Out(Buffer)",
+   ASP_RX_CTRL_FB_OUT_FRAME_COUNT),
+

[PATCH net-next v8 09/11] net: phy: mdio-bcm-unimac: Add asp v2.0 support

2023-06-16 Thread Justin Chen
Add mdio compat string for ASP 2.0 ethernet driver.

Reviewed-by: Simon Horman 
Reviewed-by: Andrew Lunn 
Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
---
 drivers/net/mdio/mdio-bcm-unimac.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/mdio/mdio-bcm-unimac.c 
b/drivers/net/mdio/mdio-bcm-unimac.c
index bfc9be23c973..6b26a0803696 100644
--- a/drivers/net/mdio/mdio-bcm-unimac.c
+++ b/drivers/net/mdio/mdio-bcm-unimac.c
@@ -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", },
-- 
2.7.4



smime.p7s
Description: S/MIME Cryptographic Signature


[PATCH net-next v8 10/11] net: phy: bcm7xxx: Add EPHY entry for 74165

2023-06-16 Thread Justin Chen
From: Florian Fainelli 

74165 is a 16nm process SoC with a 10/100 integrated Ethernet PHY,
utilize the recently defined 16nm EPHY macro to configure that PHY.

Reviewed-by: Simon Horman 
Reviewed-by: Andrew Lunn 
Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
---
 drivers/net/phy/bcm7xxx.c | 1 +
 include/linux/brcmphy.h   | 1 +
 2 files changed, 2 insertions(+)

diff --git a/drivers/net/phy/bcm7xxx.c b/drivers/net/phy/bcm7xxx.c
index f8c17a253f8b..8478b081c058 100644
--- a/drivers/net/phy/bcm7xxx.c
+++ b/drivers/net/phy/bcm7xxx.c
@@ -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)"),
diff --git a/include/linux/brcmphy.h b/include/linux/brcmphy.h
index 5d732f48f787..c55810a43541 100644
--- a/include/linux/brcmphy.h
+++ b/include/linux/brcmphy.h
@@ -44,6 +44,7 @@
 #define PHY_ID_BCM7366 0x600d8490
 #define PHY_ID_BCM7346 0x600d8650
 #define PHY_ID_BCM7362 0x600d84b0
+#define PHY_ID_BCM741650x359052c0
 #define PHY_ID_BCM7425 0x600d86b0
 #define PHY_ID_BCM7429 0x600d8730
 #define PHY_ID_BCM7435 0x600d8750
-- 
2.7.4



smime.p7s
Description: S/MIME Cryptographic Signature


[PATCH net-next v8 05/11] net: bcmasp: Add support for wake on net filters

2023-06-16 Thread Justin Chen
Add support for wake on network filters. The max match is 256 bytes.

Signed-off-by: Justin Chen 
---
 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(-)

diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp.c 
b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
index 40143bb566ef..51b7aa8365c8 100644
--- a/drivers/net/ethernet/broadcom/asp2/bcmasp.c
+++ b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
@@ -130,6 +130,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) 

[PATCH net-next v8 07/11] net: bcmasp: Add support for ethtool standard stats

2023-06-16 Thread Justin Chen
Add support for eth_mac_stats, rmon_stats, and eth_ctrl_stats.

Signed-off-by: Justin Chen 
---
 .../net/ethernet/broadcom/asp2/bcmasp_ethtool.c| 77 ++
 .../net/ethernet/broadcom/asp2/bcmasp_intf_defs.h  | 63 +-
 2 files changed, 139 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c 
b/drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c
index 1e96a69043f3..59d853c2293c 100644
--- a/drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c
+++ b/drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c
@@ -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,
 };
diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp_intf_defs.h 
b/drivers/net/ethernet/broadcom/asp2/bcmasp_intf_defs.h
index b259a475207f..ad742612895f 100644
--- a/drivers/net/ethernet/broadcom/asp2/bcmasp_intf

[PATCH net-next v8 06/11] net: bcmasp: Add support for eee mode

2023-06-16 Thread Justin Chen
Add support for eee mode.

Signed-off-by: Justin Chen 
---
 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(+)

diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp.h 
b/drivers/net/ethernet/broadcom/asp2/bcmasp.h
index e791b869006e..d6740077877a 100644
--- a/drivers/net/ethernet/broadcom/asp2/bcmasp.h
+++ b/drivers/net/ethernet/broadcom/asp2/bcmasp.h
@@ -313,6 +313,8 @@ struct bcmasp_intf {
/* Used if per intf wol irq */
int wol_irq;
unsigned intwol_irq_enabled:1;
+
+   struct ethtool_eee  eee;
 };
 
 #define NUM_NET_FILTERS32
@@ -559,4 +561,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
diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c 
b/drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c
index eddd1c43f00e..1e96a69043f3 100644
--- a/drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c
+++ b/drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c
@@ -191,6 +191,65 @@ static int bcmasp_get_rxnfc(struct net_device *dev, struct 
ethtool_rxnfc *cmd,
return err;
 }
 
+void bcmasp_eee_enable_set(struct bcmasp_intf *intf, bool enable)
+{
+   u32 reg;
+
+   reg = umac_rl(intf, UMC_EEE_CTRL);
+   if (enable)
+   reg |= EEE_EN;
+   else
+   reg &= ~EEE_EN;
+   umac_wl(intf, reg, UMC_EEE_CTRL);
+
+   intf->eee.eee_enabled = enable;
+   intf->eee.eee_active = enable;
+}
+
+static int bcmasp_get_eee(struct net_device *dev, struct ethtool_eee *e)
+{
+   struct bcmasp_intf *intf = netdev_priv(dev);
+   struct ethtool_eee *p = >eee;
+
+   if (!dev->phydev)
+   return -ENODEV;
+
+   e->eee_enabled = p->eee_enabled;
+   e->eee_active = p->eee_active;
+   e->tx_lpi_enabled = p->tx_lpi_enabled;
+   e->tx_lpi_timer = umac_rl(intf, UMC_EEE_LPI_TIMER);
+
+   return phy_ethtool_get_eee(dev->phydev, e);
+}
+
+static int bcmasp_set_eee(struct net_device *dev, struct ethtool_eee *e)
+{
+   struct bcmasp_intf *intf = netdev_priv(dev);
+   struct ethtool_eee *p = >eee;
+   int ret;
+
+   if (!dev->phydev)
+   return -ENODEV;
+
+   if (!p->eee_enabled) {
+   bcmasp_eee_enable_set(intf, false);
+   } else {
+   ret = phy_init_eee(dev->phydev, 0);
+   if (ret) {
+   netif_err(intf, hw, dev,
+ "EEE initialization failed: %d\n", ret);
+   return ret;
+   }
+
+   umac_wl(intf, e->tx_lpi_timer, UMC_EEE_LPI_TIMER);
+   intf->eee.eee_active = ret >= 0;
+   intf->eee.tx_lpi_enabled = e->tx_lpi_enabled;
+   bcmasp_eee_enable_set(intf, true);
+   }
+
+   return phy_ethtool_set_eee(dev->phydev, e);
+}
+
 const struct ethtool_ops bcmasp_ethtool_ops = {
.get_drvinfo= bcmasp_get_drvinfo,
.get_link   = ethtool_op_get_link,
@@ -202,4 +261,6 @@ const struct ethtool_ops bcmasp_ethtool_ops = {
.set_wol= bcmasp_set_wol,
.get_rxnfc  = bcmasp_get_rxnfc,
.set_rxnfc  = bcmasp_set_rxnfc,
+   .set_eee= bcmasp_set_eee,
+   .get_eee= bcmasp_get_eee,
 };
diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c 
b/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c
index e221f07bf743..2c8a9d5711de 100644
--- a/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c
+++ b/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c
@@ -653,6 +653,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);
@@ -1403,6 +1406,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;
-- 
2.7.4



smime.p7s
Description: S/MIME Cryptographic Signature


[PATCH net-next v8 04/11] net: bcmasp: Add support for WoL magic packet

2023-06-16 Thread Justin Chen
Add support for Wake-On-Lan magic packet and magic packet with password.

Signed-off-by: Justin Chen 
---
 drivers/net/ethernet/broadcom/asp2/bcmasp.c| 148 +
 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, 266 insertions(+), 12 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp.c 
b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
index 34a0c7545ebd..40143bb566ef 100644
--- a/drivers/net/ethernet/broadcom/asp2/bcmasp.c
+++ b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
@@ -440,6 +440,139 @@ static int bcmasp_is_port_valid(struct bcmasp_priv *priv, 
int port)
return port == 0 || port == 1;
 }
 
+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(>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(>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 = >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(>dev, 1);
+}
+
+static void bcmasp_enable_wol_shared(struct bcmasp_intf *intf, bool en)
+{
+   struct bcmasp_priv *priv = intf->parent;
+   struct device *dev = >pdev->dev;
+
+   if (en) {
+   if (priv->wol_irq_enabled_mask) {
+   set_bit(intf->port, >wol_irq_enabled_mask);
+   return;
+   }
+
+   /* First enable */
+   set_bit(intf->port, >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, >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 = >dev;
+   struct bcmasp_intf *intf;
+   int irq, i;
+
+   for (i = 0; i < priv->intf_count; i++) {
+   intf = priv->intfs[i];
+   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(>dev, 1);
+   }
+}
+
+static void bcmasp_enable_wol_per_intf(struct bcmasp_intf *intf, bool en)
+{
+   struct device *dev = >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;
+   int i;
+
+   for (i = 0; i < priv->intf_count; i++) {
+   intf = priv->intfs[i];
+
+   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_

[PATCH net-next v8 03/11] net: bcmasp: Add support for ASP2.0 Ethernet controller

2023-06-16 Thread Justin Chen
Add 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.

Reviewed-by: Simon Horman 
Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
---
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|  726 +++
 drivers/net/ethernet/broadcom/asp2/bcmasp.h|  504 
 .../net/ethernet/broadcom/asp2/bcmasp_ethtool.c|   40 +
 drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c   | 1358 
 .../net/ethernet/broadcom/asp2/bcmasp_intf_defs.h  |  196 +++
 8 files changed, 2838 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

diff --git a/drivers/net/ethernet/broadcom/Kconfig 
b/drivers/net/ethernet/broadcom/Kconfig
index 948586bf1b5b..d4166141145d 100644
--- a/drivers/net/ethernet/broadcom/Kconfig
+++ b/drivers/net/ethernet/broadcom/Kconfig
@@ -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
diff --git a/drivers/net/ethernet/broadcom/Makefile 
b/drivers/net/ethernet/broadcom/Makefile
index 0ddfb5b5d53c..bac5cb6ad0cd 100644
--- a/drivers/net/ethernet/broadcom/Makefile
+++ b/drivers/net/ethernet/broadcom/Makefile
@@ -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/
diff --git a/drivers/net/ethernet/broadcom/asp2/Makefile 
b/drivers/net/ethernet/broadcom/asp2/Makefile
new file mode 100644
index ..e07550315f83
--- /dev/null
+++ b/drivers/net/ethernet/broadcom/asp2/Makefile
@@ -0,0 +1,2 @@
+obj-$(CONFIG_BCMASP) += bcm-asp.o
+bcm-asp-objs := bcmasp.o bcmasp_intf.o bcmasp_ethtool.o
diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp.c 
b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
new file mode 100644
index ..34a0c7545ebd
--- /dev/null
+++ b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
@@ -0,0 +1,726 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Broadcom STB ASP 2.0 Driver
+ *
+ * Copyright (c) 2023 Broadcom
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "bcmasp.h"
+#include "bcmasp_intf_defs.h"
+
+static void _intr2_mask_clear(struct bcmasp_priv *priv, u32 mask)
+{
+   intr2_core_wl(priv, mask, ASP_INTR2_MASK_CLEAR);
+   priv->irq_mask &= ~mask;
+}
+
+static void _intr2_mask_set(struct bcmasp_priv *priv, u32 mask)
+{
+   intr2_core_wl(priv, mask, ASP_INTR2_MASK_SET);
+   priv->irq_mask |= mask;
+}
+
+void bcmasp_enable_tx_irq(struct bcmasp_intf *intf, int en)
+{
+   struct bcmasp_priv *priv = intf->parent;
+
+   if (en)
+   _intr2_mask_clear(priv, ASP_INTR2_TX_DESC(intf->channel));
+   else
+   _intr2_mask_set(priv, ASP_INTR2_TX_DESC(intf->c

[PATCH net-next v8 02/11] dt-bindings: net: Brcm ASP 2.0 Ethernet controller

2023-06-16 Thread Justin Chen
From: Florian Fainelli 

Add a binding document for the Broadcom ASP 2.0 Ethernet
controller.

Reviewed-by: Conor Dooley 
Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
---
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

diff --git a/Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml 
b/Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml
new file mode 100644
index ..aa3162c74833
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml
@@ -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 
+  - Florian Fainelli 
+
+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 
+#include 
+
+ethernet@9c0 {
+compatible = "brcm,bcm72165-asp", "brcm,asp-v2.0";
+reg = <0x9c0 0x1fff14>;
+interrupts = ;
+ranges = <0x0 0x9c0 0x1fff14>;
+clocks = < 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 = <>;
+};
+
+port@1 {
+reg = <1>;
+brcm,channel = <9>;
+phy-mode = "rgmii";
+phy-handle = <>;
+};
+};
+};
-- 
2.7.4



smime.p7s
Description: S/MIME Cryptographic Signature


[PATCH net-next v8 00/11] Brcm ASP 2.0 Ethernet Controller

2023-06-16 Thread Justin Chen
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| 1471 
 drivers/net/ethernet/broadcom/asp2/bcmasp.h|  587 
 .../net/ethernet/broadcom/asp2/bcmasp_ethtool.c|  503 +++
 drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c   | 1430 +++
 .../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, 4432 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

-- 
2.7.4



smime.p7s
Description: S/MIME Cryptographic Signature


[PATCH net-next v8 01/11] dt-bindings: net: brcm, unimac-mdio: Add asp-v2.0

2023-06-16 Thread Justin Chen
The ASP 2.0 Ethernet controller uses a brcm unimac.

Reviewed-by: Simon Horman 
Acked-by: Conor Dooley 
Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
---
 Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml 
b/Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml
index 0be426ee1e44..6684810fcbf0 100644
--- a/Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml
+++ b/Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml
@@ -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:
-- 
2.7.4



smime.p7s
Description: S/MIME Cryptographic Signature


[PATCH net-next v7 10/11] net: phy: bcm7xxx: Add EPHY entry for 74165

2023-06-14 Thread Justin Chen
From: Florian Fainelli 

74165 is a 16nm process SoC with a 10/100 integrated Ethernet PHY,
utilize the recently defined 16nm EPHY macro to configure that PHY.

Reviewed-by: Simon Horman 
Reviewed-by: Andrew Lunn 
Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
---
 drivers/net/phy/bcm7xxx.c | 1 +
 include/linux/brcmphy.h   | 1 +
 2 files changed, 2 insertions(+)

diff --git a/drivers/net/phy/bcm7xxx.c b/drivers/net/phy/bcm7xxx.c
index f8c17a253f8b..8478b081c058 100644
--- a/drivers/net/phy/bcm7xxx.c
+++ b/drivers/net/phy/bcm7xxx.c
@@ -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)"),
diff --git a/include/linux/brcmphy.h b/include/linux/brcmphy.h
index 5d732f48f787..c55810a43541 100644
--- a/include/linux/brcmphy.h
+++ b/include/linux/brcmphy.h
@@ -44,6 +44,7 @@
 #define PHY_ID_BCM7366 0x600d8490
 #define PHY_ID_BCM7346 0x600d8650
 #define PHY_ID_BCM7362 0x600d84b0
+#define PHY_ID_BCM741650x359052c0
 #define PHY_ID_BCM7425 0x600d86b0
 #define PHY_ID_BCM7429 0x600d8730
 #define PHY_ID_BCM7435 0x600d8750
-- 
2.7.4



smime.p7s
Description: S/MIME Cryptographic Signature


[PATCH net-next v7 11/11] MAINTAINERS: ASP 2.0 Ethernet driver maintainers

2023-06-14 Thread Justin Chen
Add maintainers entry for ASP 2.0 Ethernet driver.

Reviewed-by: Simon Horman 
Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
---
v3
- Change from gmail to broadcom emails

 MAINTAINERS | 9 +
 1 file changed, 9 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index cd9752472d77..d6b37b45c7fd 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4195,6 +4195,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 
+M: Florian Fainelli 
+L: bcm-kernel-feedback-l...@broadcom.com
+L: net...@vger.kernel.org
+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 
 M: Scott Branden 
-- 
2.7.4



smime.p7s
Description: S/MIME Cryptographic Signature


[PATCH net-next v7 07/11] net: bcmasp: Add support for ethtool standard stats

2023-06-14 Thread Justin Chen
Add support for eth_mac_stats, rmon_stats, and eth_ctrl_stats.

Signed-off-by: Justin Chen 
---
 .../net/ethernet/broadcom/asp2/bcmasp_ethtool.c| 77 ++
 .../net/ethernet/broadcom/asp2/bcmasp_intf_defs.h  | 63 +-
 2 files changed, 139 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c 
b/drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c
index 1e96a69043f3..59d853c2293c 100644
--- a/drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c
+++ b/drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c
@@ -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,
 };
diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp_intf_defs.h 
b/drivers/net/ethernet/broadcom/asp2/bcmasp_intf_defs.h
index b259a475207f..ad742612895f 100644
--- a/drivers/net/ethernet/broadcom/asp2/bcmasp_intf

[PATCH net-next v7 08/11] net: bcmasp: Add support for ethtool driver stats

2023-06-14 Thread Justin Chen
Add support for ethernet driver specific stats.

Signed-off-by: Justin Chen 
---
 drivers/net/ethernet/broadcom/asp2/bcmasp.c|   1 +
 drivers/net/ethernet/broadcom/asp2/bcmasp.h|  21 +++
 .../net/ethernet/broadcom/asp2/bcmasp_ethtool.c| 158 +
 drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c   |   8 ++
 4 files changed, 188 insertions(+)

diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp.c 
b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
index ba9842c760d5..a8905fef4f8a 100644
--- a/drivers/net/ethernet/broadcom/asp2/bcmasp.c
+++ b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
@@ -891,6 +891,7 @@ 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) {
+   intf->mib.filters_combine_cnt++;
return 0;
}
}
diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp.h 
b/drivers/net/ethernet/broadcom/asp2/bcmasp.h
index 7dc597658ed7..1485c2c3712d 100644
--- a/drivers/net/ethernet/broadcom/asp2/bcmasp.h
+++ b/drivers/net/ethernet/broadcom/asp2/bcmasp.h
@@ -245,6 +245,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_realloc_offload;
+};
+
 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);
@@ -307,6 +327,7 @@ struct bcmasp_intf {
 
/* Statistics */
struct bcmasp_intf_stats64  stats64;
+   struct bcmasp_mib_counters  mib;
 
u32 wolopts;
u8  sopass[SOPASS_MAX];
diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c 
b/drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c
index 59d853c2293c..fc47e27b148d 100644
--- a/drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c
+++ b/drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
 #define pr_fmt(fmt)"bcmasp_ethtool: " fmt
 
+#include 
 #include 
 #include 
 #include 
@@ -8,6 +9,160 @@
 #include "bcmasp.h"
 #include "bcmasp_intf_defs.h"
 
+enum bcmasp_stat_type {
+   BCMASP_STAT_RX_EDPKT,
+   BCMASP_STAT_RX_CTRL,
+   BCMASP_STAT_RX_CTRL_PER_INTF,
+   BCMASP_STAT_SOFT,
+};
+
+struct bcmasp_stats {
+   char stat_string[ETH_GSTRING_LEN];
+   enum bcmasp_stat_type type;
+   u32 reg_offset;
+};
+
+#define STAT_BCMASP_SOFT_MIB(str) { \
+   .stat_string = str, \
+   .type = BCMASP_STAT_SOFT, \
+}
+
+#define STAT_BCMASP_OFFSET(str, _type, offset) { \
+   .stat_string = str, \
+   .type = _type, \
+   .reg_offset = offset, \
+}
+
+#define STAT_BCMASP_RX_EDPKT(str, offset) \
+   STAT_BCMASP_OFFSET(str, BCMASP_STAT_RX_EDPKT, offset)
+#define STAT_BCMASP_RX_CTRL(str, offset) \
+   STAT_BCMASP_OFFSET(str, BCMASP_STAT_RX_CTRL, offset)
+#define STAT_BCMASP_RX_CTRL_PER_INTF(str, offset) \
+   STAT_BCMASP_OFFSET(str, BCMASP_STAT_RX_CTRL_PER_INTF, offset)
+
+/* Must match the order of struct bcmasp_mib_counters */
+static const struct bcmasp_stats bcmasp_gstrings_stats[] = {
+   /* EDPKT counters */
+   STAT_BCMASP_RX_EDPKT("RX Time Stamp", ASP_EDPKT_RX_TS_COUNTER),
+   STAT_BCMASP_RX_EDPKT("RX PKT Count", ASP_EDPKT_RX_PKT_CNT),
+   STAT_BCMASP_RX_EDPKT("RX PKT Buffered", ASP_EDPKT_HDR_EXTR_CNT),
+   STAT_BCMASP_RX_EDPKT("RX PKT Pushed to DRAM", ASP_EDPKT_HDR_OUT_CNT),
+   /* ASP RX control */
+   STAT_BCMASP_RX_CTRL_PER_INTF("Frames From Unimac",
+ASP_RX_CTRL_UMAC_0_FRAME_COUNT),
+   STAT_BCMASP_RX_CTRL_PER_INTF("Frames From Port",
+ASP_RX_CTRL_FB_0_FRAME_COUNT),
+   STAT_BCMASP_RX_CTRL_PER_INTF("RX Buffer FIFO Depth",
+ASP_RX_CTRL_FB_RX_FIFO_DEPTH),
+   STAT_BCMASP_RX_CTRL("Frames Out(Buffer)",
+   ASP_RX_CTRL_FB_OUT_FRAME_COUNT),
+   STAT_BCMASP_RX_CTRL("Frames Out(Filters)",
+   ASP_RX_CTRL_FB_FILT_OUT_FRAME_COUNT),
+   /* Softwar

[PATCH net-next v7 09/11] net: phy: mdio-bcm-unimac: Add asp v2.0 support

2023-06-14 Thread Justin Chen
Add mdio compat string for ASP 2.0 ethernet driver.

Reviewed-by: Simon Horman 
Reviewed-by: Andrew Lunn 
Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
---
 drivers/net/mdio/mdio-bcm-unimac.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/mdio/mdio-bcm-unimac.c 
b/drivers/net/mdio/mdio-bcm-unimac.c
index bfc9be23c973..6b26a0803696 100644
--- a/drivers/net/mdio/mdio-bcm-unimac.c
+++ b/drivers/net/mdio/mdio-bcm-unimac.c
@@ -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", },
-- 
2.7.4



smime.p7s
Description: S/MIME Cryptographic Signature


[PATCH net-next v7 04/11] net: bcmasp: Add support for WoL magic packet

2023-06-14 Thread Justin Chen
Add support for Wake-On-Lan magic packet and magic packet with password.

Signed-off-by: Justin Chen 
---
 drivers/net/ethernet/broadcom/asp2/bcmasp.c| 148 +
 drivers/net/ethernet/broadcom/asp2/bcmasp.h|  18 +++
 .../net/ethernet/broadcom/asp2/bcmasp_ethtool.c|  36 +
 drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c   |  77 +--
 4 files changed, 266 insertions(+), 13 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp.c 
b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
index 5dbd9fcdd23f..9e3977856b71 100644
--- a/drivers/net/ethernet/broadcom/asp2/bcmasp.c
+++ b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
@@ -441,6 +441,139 @@ static int bcmasp_is_port_valid(struct bcmasp_priv *priv, 
int port)
return port == 0 || port == 1;
 }
 
+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(>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(>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 = >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(>dev, 1);
+}
+
+static void bcmasp_enable_wol_shared(struct bcmasp_intf *intf, bool en)
+{
+   struct bcmasp_priv *priv = intf->parent;
+   struct device *dev = >pdev->dev;
+
+   if (en) {
+   if (priv->wol_irq_enabled_mask) {
+   set_bit(intf->port, >wol_irq_enabled_mask);
+   return;
+   }
+
+   /* First enable */
+   set_bit(intf->port, >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, >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 = >dev;
+   struct bcmasp_intf *intf;
+   int irq, i;
+
+   for (i = 0; i < priv->intf_count; i++) {
+   intf = priv->intfs[i];
+   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(>dev, 1);
+   }
+}
+
+static void bcmasp_enable_wol_per_intf(struct bcmasp_intf *intf, bool en)
+{
+   struct device *dev = >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;
+   int i;
+
+   for (i = 0; i < priv->intf_count; i++) {
+   intf = priv->intfs[i];
+
+   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_

[PATCH net-next v7 03/11] net: bcmasp: Add support for ASP2.0 Ethernet controller

2023-06-14 Thread Justin Chen
Add 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.

Reviewed-by: Simon Horman 
Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
---
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|  727 +++
 drivers/net/ethernet/broadcom/asp2/bcmasp.h|  504 
 .../net/ethernet/broadcom/asp2/bcmasp_ethtool.c|   40 +
 drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c   | 1363 
 .../net/ethernet/broadcom/asp2/bcmasp_intf_defs.h  |  196 +++
 8 files changed, 2844 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

diff --git a/drivers/net/ethernet/broadcom/Kconfig 
b/drivers/net/ethernet/broadcom/Kconfig
index 948586bf1b5b..d4166141145d 100644
--- a/drivers/net/ethernet/broadcom/Kconfig
+++ b/drivers/net/ethernet/broadcom/Kconfig
@@ -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
diff --git a/drivers/net/ethernet/broadcom/Makefile 
b/drivers/net/ethernet/broadcom/Makefile
index 0ddfb5b5d53c..bac5cb6ad0cd 100644
--- a/drivers/net/ethernet/broadcom/Makefile
+++ b/drivers/net/ethernet/broadcom/Makefile
@@ -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/
diff --git a/drivers/net/ethernet/broadcom/asp2/Makefile 
b/drivers/net/ethernet/broadcom/asp2/Makefile
new file mode 100644
index ..e07550315f83
--- /dev/null
+++ b/drivers/net/ethernet/broadcom/asp2/Makefile
@@ -0,0 +1,2 @@
+obj-$(CONFIG_BCMASP) += bcm-asp.o
+bcm-asp-objs := bcmasp.o bcmasp_intf.o bcmasp_ethtool.o
diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp.c 
b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
new file mode 100644
index ..5dbd9fcdd23f
--- /dev/null
+++ b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
@@ -0,0 +1,727 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Broadcom STB ASP 2.0 Driver
+ *
+ * Copyright (c) 2023 Broadcom
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "bcmasp.h"
+#include "bcmasp_intf_defs.h"
+
+static void _intr2_mask_clear(struct bcmasp_priv *priv, u32 mask)
+{
+   intr2_core_wl(priv, mask, ASP_INTR2_MASK_CLEAR);
+   priv->irq_mask &= ~mask;
+}
+
+static void _intr2_mask_set(struct bcmasp_priv *priv, u32 mask)
+{
+   intr2_core_wl(priv, mask, ASP_INTR2_MASK_SET);
+   priv->irq_mask |= mask;
+}
+
+void bcmasp_enable_tx_irq(struct bcmasp_intf *intf, int en)
+{
+   struct bcmasp_priv *priv = intf->parent;
+
+   if (en)
+   _intr2_mask_clear(priv, ASP_INTR2_TX_DESC(intf->channel));
+   else
+   _intr2_mask_set(priv, ASP_INTR2_TX_DESC(intf->channel));
+}
+EXPORT_SYMBOL_GPL(bcmasp_enable_tx_i

[PATCH net-next v7 06/11] net: bcmasp: Add support for eee mode

2023-06-14 Thread Justin Chen
Add support for eee mode.

Signed-off-by: Justin Chen 
---
 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(+)

diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp.h 
b/drivers/net/ethernet/broadcom/asp2/bcmasp.h
index 521c9b4b7288..7dc597658ed7 100644
--- a/drivers/net/ethernet/broadcom/asp2/bcmasp.h
+++ b/drivers/net/ethernet/broadcom/asp2/bcmasp.h
@@ -313,6 +313,8 @@ struct bcmasp_intf {
/* Used if per intf wol irq */
int wol_irq;
unsigned intwol_irq_enabled:1;
+
+   struct ethtool_eee  eee;
 };
 
 #define NUM_NET_FILTERS32
@@ -559,4 +561,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
diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c 
b/drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c
index eddd1c43f00e..1e96a69043f3 100644
--- a/drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c
+++ b/drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c
@@ -191,6 +191,65 @@ static int bcmasp_get_rxnfc(struct net_device *dev, struct 
ethtool_rxnfc *cmd,
return err;
 }
 
+void bcmasp_eee_enable_set(struct bcmasp_intf *intf, bool enable)
+{
+   u32 reg;
+
+   reg = umac_rl(intf, UMC_EEE_CTRL);
+   if (enable)
+   reg |= EEE_EN;
+   else
+   reg &= ~EEE_EN;
+   umac_wl(intf, reg, UMC_EEE_CTRL);
+
+   intf->eee.eee_enabled = enable;
+   intf->eee.eee_active = enable;
+}
+
+static int bcmasp_get_eee(struct net_device *dev, struct ethtool_eee *e)
+{
+   struct bcmasp_intf *intf = netdev_priv(dev);
+   struct ethtool_eee *p = >eee;
+
+   if (!dev->phydev)
+   return -ENODEV;
+
+   e->eee_enabled = p->eee_enabled;
+   e->eee_active = p->eee_active;
+   e->tx_lpi_enabled = p->tx_lpi_enabled;
+   e->tx_lpi_timer = umac_rl(intf, UMC_EEE_LPI_TIMER);
+
+   return phy_ethtool_get_eee(dev->phydev, e);
+}
+
+static int bcmasp_set_eee(struct net_device *dev, struct ethtool_eee *e)
+{
+   struct bcmasp_intf *intf = netdev_priv(dev);
+   struct ethtool_eee *p = >eee;
+   int ret;
+
+   if (!dev->phydev)
+   return -ENODEV;
+
+   if (!p->eee_enabled) {
+   bcmasp_eee_enable_set(intf, false);
+   } else {
+   ret = phy_init_eee(dev->phydev, 0);
+   if (ret) {
+   netif_err(intf, hw, dev,
+ "EEE initialization failed: %d\n", ret);
+   return ret;
+   }
+
+   umac_wl(intf, e->tx_lpi_timer, UMC_EEE_LPI_TIMER);
+   intf->eee.eee_active = ret >= 0;
+   intf->eee.tx_lpi_enabled = e->tx_lpi_enabled;
+   bcmasp_eee_enable_set(intf, true);
+   }
+
+   return phy_ethtool_set_eee(dev->phydev, e);
+}
+
 const struct ethtool_ops bcmasp_ethtool_ops = {
.get_drvinfo= bcmasp_get_drvinfo,
.get_link   = ethtool_op_get_link,
@@ -202,4 +261,6 @@ const struct ethtool_ops bcmasp_ethtool_ops = {
.set_wol= bcmasp_set_wol,
.get_rxnfc  = bcmasp_get_rxnfc,
.set_rxnfc  = bcmasp_set_rxnfc,
+   .set_eee= bcmasp_set_eee,
+   .get_eee= bcmasp_get_eee,
 };
diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c 
b/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c
index 0c59f4025965..899cb06a3fde 100644
--- a/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c
+++ b/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c
@@ -656,6 +656,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);
@@ -1407,6 +1410,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;
-- 
2.7.4



smime.p7s
Description: S/MIME Cryptographic Signature


[PATCH net-next v7 05/11] net: bcmasp: Add support for wake on net filters

2023-06-14 Thread Justin Chen
Add support for wake on network filters. The max match is 256 bytes.

Signed-off-by: Justin Chen 
---
 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(-)

diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp.c 
b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
index 9e3977856b71..ba9842c760d5 100644
--- a/drivers/net/ethernet/broadcom/asp2/bcmasp.c
+++ b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
@@ -130,6 +130,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) 

[PATCH net-next v7 01/11] dt-bindings: net: brcm, unimac-mdio: Add asp-v2.0

2023-06-14 Thread Justin Chen
The ASP 2.0 Ethernet controller uses a brcm unimac.

Reviewed-by: Simon Horman 
Acked-by: Conor Dooley 
Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
---
 Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml 
b/Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml
index 0be426ee1e44..6684810fcbf0 100644
--- a/Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml
+++ b/Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml
@@ -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:
-- 
2.7.4



smime.p7s
Description: S/MIME Cryptographic Signature


[PATCH net-next v7 02/11] dt-bindings: net: Brcm ASP 2.0 Ethernet controller

2023-06-14 Thread Justin Chen
From: Florian Fainelli 

Add a binding document for the Broadcom ASP 2.0 Ethernet
controller.

Reviewed-by: Conor Dooley 
Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
---
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

diff --git a/Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml 
b/Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml
new file mode 100644
index ..aa3162c74833
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml
@@ -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 
+  - Florian Fainelli 
+
+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 
+#include 
+
+ethernet@9c0 {
+compatible = "brcm,bcm72165-asp", "brcm,asp-v2.0";
+reg = <0x9c0 0x1fff14>;
+interrupts = ;
+ranges = <0x0 0x9c0 0x1fff14>;
+clocks = < 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 = <>;
+};
+
+port@1 {
+reg = <1>;
+brcm,channel = <9>;
+phy-mode = "rgmii";
+phy-handle = <>;
+};
+};
+};
-- 
2.7.4



smime.p7s
Description: S/MIME Cryptographic Signature


[PATCH net-next v7 00/11] Brcm ASP 2.0 Ethernet Controller

2023-06-14 Thread Justin Chen
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| 1471 
 drivers/net/ethernet/broadcom/asp2/bcmasp.h|  587 
 .../net/ethernet/broadcom/asp2/bcmasp_ethtool.c|  501 +++
 drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c   | 1431 +++
 .../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, 4431 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

-- 
2.7.4



smime.p7s
Description: S/MIME Cryptographic Signature


Re: [PATCH net-next v6 3/6] net: bcmasp: Add support for ASP2.0 Ethernet controller

2023-06-06 Thread Justin Chen



On 6/6/2023 8:45 PM, Jakub Kicinski wrote:

On Tue, 6 Jun 2023 19:33:13 -0700 Justin Chen wrote:

Not netdevs per se, but packets can be redirected to an offload
co-processor.


How is the redirecting configured?


Through filters that can be programmed by the Host cpu or co-processor.


How are the filter programmed by the host (in terms of user API)?


You are stumbling upon my next objective here. This patch set does not 
support this because it wasn't clear how to do it. The plan was to get 
the base driver merged first then introduce a way to specify an offload 
channel.


If you must know, I introduced a rxnfc flow_spec ring cookie to specify 
an offload filter. Not sure if this is the right way to do it or not, 
but figured this would be a future discussion.


smime.p7s
Description: S/MIME Cryptographic Signature


Re: [PATCH net-next v6 3/6] net: bcmasp: Add support for ASP2.0 Ethernet controller

2023-06-06 Thread Justin Chen



On 6/6/2023 6:54 PM, Jakub Kicinski wrote:

On Tue, 6 Jun 2023 18:35:51 -0700 Justin Chen wrote:

Also - can you describe how you can have multiple netdevs for
the same MAC?


Not netdevs per se, but packets can be redirected to an offload
co-processor.


How is the redirecting configured?



Through filters that can be programmed by the Host cpu or co-processor.


Could you split this patch into basic netdev datapath,
and then as separate patches support for ethtool configuration features,
each with its own patch? This will make it easier for area experts to
review.

The base patch can probably include these:

+   .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,

WoL can be a separate patch:

+   .get_wol= bcmasp_get_wol,
+   .set_wol= bcmasp_set_wol,

Stats a separate patch:

+   .get_strings= bcmasp_get_strings,
+   .get_ethtool_stats  = bcmasp_get_ethtool_stats,
+   .get_sset_count = bcmasp_get_sset_count,
+   .nway_reset = phy_ethtool_nway_reset,

Flow steering separate:

+   .get_rxnfc  = bcmasp_get_rxnfc,
+   .set_rxnfc  = bcmasp_set_rxnfc,

EEE separate:

+   .set_eee= bcmasp_set_eee,
+   .get_eee= bcmasp_get_eee,


Will do.


smime.p7s
Description: S/MIME Cryptographic Signature


Re: [PATCH net-next v6 3/6] net: bcmasp: Add support for ASP2.0 Ethernet controller

2023-06-06 Thread Justin Chen



On 6/6/2023 5:16 PM, Jakub Kicinski wrote:

On Tue, 6 Jun 2023 15:58:21 -0700 Justin Chen wrote:

On 6/2/23 11:58 PM, Jakub Kicinski wrote:

On Thu,  1 Jun 2023 15:12:28 -0700 Justin Chen wrote:

+   /* general stats */
+   STAT_NETDEV(rx_packets),
+   STAT_NETDEV(tx_packets),
+   STAT_NETDEV(rx_bytes),
+   STAT_NETDEV(tx_bytes),
+   STAT_NETDEV(rx_errors),
+   STAT_NETDEV(tx_errors),
+   STAT_NETDEV(rx_dropped),
+   STAT_NETDEV(tx_dropped),
+   STAT_NETDEV(multicast),


please don't report standard interface stats in ethtool -S
   


These are not netdev statistics but MAC block counters. Guess it is not
clear with the naming here, will fix this. We have a use case where the
MAC traffic may be redirected from the associated net dev, so the
counters may not be the same.


You seem to be dumping straight from the stats member of struct
net_device:

+   if (s->type == BCMASP_STAT_NETDEV)
+   p = (char *)>stats;

No?



Woops I got it mixed up. Yes these stats are redundant. What I was 
describing is

+   STAT_BCMASP_MIB_RX("rx_pkts", mib.rx.pkt),
and equivalent.


Also - can you describe how you can have multiple netdevs for
the same MAC?


Not netdevs per se, but packets can be redirected to an offload 
co-processor.


smime.p7s
Description: S/MIME Cryptographic Signature


Re: [PATCH net-next v6 3/6] net: bcmasp: Add support for ASP2.0 Ethernet controller

2023-06-06 Thread Justin Chen



On 6/2/23 11:58 PM, Jakub Kicinski wrote:

On Thu,  1 Jun 2023 15:12:28 -0700 Justin Chen wrote:

+   /* general stats */
+   STAT_NETDEV(rx_packets),
+   STAT_NETDEV(tx_packets),
+   STAT_NETDEV(rx_bytes),
+   STAT_NETDEV(tx_bytes),
+   STAT_NETDEV(rx_errors),
+   STAT_NETDEV(tx_errors),
+   STAT_NETDEV(rx_dropped),
+   STAT_NETDEV(tx_dropped),
+   STAT_NETDEV(multicast),


please don't report standard interface stats in ethtool -S



These are not netdev statistics but MAC block counters. Guess it is not 
clear with the naming here, will fix this. We have a use case where the 
MAC traffic may be redirected from the associated net dev, so the 
counters may not be the same.



+   /* UniMAC RSV counters */
+   STAT_BCMASP_MIB_RX("rx_64_octets", mib.rx.pkt_cnt.cnt_64),
+   STAT_BCMASP_MIB_RX("rx_65_127_oct", mib.rx.pkt_cnt.cnt_127),
+   STAT_BCMASP_MIB_RX("rx_128_255_oct", mib.rx.pkt_cnt.cnt_255),
+   STAT_BCMASP_MIB_RX("rx_256_511_oct", mib.rx.pkt_cnt.cnt_511),
+   STAT_BCMASP_MIB_RX("rx_512_1023_oct", mib.rx.pkt_cnt.cnt_1023),
+   STAT_BCMASP_MIB_RX("rx_1024_1518_oct", mib.rx.pkt_cnt.cnt_1518),
+   STAT_BCMASP_MIB_RX("rx_vlan_1519_1522_oct", mib.rx.pkt_cnt.cnt_mgv),
+   STAT_BCMASP_MIB_RX("rx_1522_2047_oct", mib.rx.pkt_cnt.cnt_2047),
+   STAT_BCMASP_MIB_RX("rx_2048_4095_oct", mib.rx.pkt_cnt.cnt_4095),
+   STAT_BCMASP_MIB_RX("rx_4096_9216_oct", mib.rx.pkt_cnt.cnt_9216),


these should also be removed, and you should implement @get_rmon_stats.


+   STAT_BCMASP_MIB_RX("rx_pkts", mib.rx.pkt),
+   STAT_BCMASP_MIB_RX("rx_bytes", mib.rx.bytes),
+   STAT_BCMASP_MIB_RX("rx_multicast", mib.rx.mca),
+   STAT_BCMASP_MIB_RX("rx_broadcast", mib.rx.bca),
+   STAT_BCMASP_MIB_RX("rx_fcs", mib.rx.fcs),


there's a FCS error statistic in the standard stats, no need to
duplicate



Same comment as above


+   STAT_BCMASP_MIB_RX("rx_control", mib.rx.cf),
+   STAT_BCMASP_MIB_RX("rx_pause", mib.rx.pf),


@get_pause_stats


+   STAT_BCMASP_MIB_RX("rx_unknown", mib.rx.uo),
+   STAT_BCMASP_MIB_RX("rx_align", mib.rx.aln),
+   STAT_BCMASP_MIB_RX("rx_outrange", mib.rx.flr),
+   STAT_BCMASP_MIB_RX("rx_code", mib.rx.cde),
+   STAT_BCMASP_MIB_RX("rx_carrier", mib.rx.fcr),
+   STAT_BCMASP_MIB_RX("rx_oversize", mib.rx.ovr),
+   STAT_BCMASP_MIB_RX("rx_jabber", mib.rx.jbr),


these look like candidates from standard stats, too.
Please read thru:

https://docs.kernel.org/next/networking/statistics.html



Looks like the way we are doing stats are a bit outdated. Thanks for 
pointing it out. I got a bit of refactoring to do.



+   STAT_BCMASP_MIB_RX("rx_mtu_err", mib.rx.mtue),
+   STAT_BCMASP_MIB_RX("rx_good_pkts", mib.rx.pok),
+   STAT_BCMASP_MIB_RX("rx_unicast", mib.rx.uc),
+   STAT_BCMASP_MIB_RX("rx_ppp", mib.rx.ppp),
+   STAT_BCMASP_MIB_RX("rx_crc", mib.rx.rcrc),


hm, what's the difference between rx_crc and rx_fcs ?


This looks like some debug feature that really has nothing to do with 
verifying crcs. I will remove it.


Apologies, probably should have done my due diligence with each stats 
instead of blindly including everything.


Thanks,
Justin


smime.p7s
Description: S/MIME Cryptographic Signature


[PATCH net-next v6 6/6] MAINTAINERS: ASP 2.0 Ethernet driver maintainers

2023-06-01 Thread Justin Chen
Add maintainers entry for ASP 2.0 Ethernet driver.

Reviewed-by: Simon Horman 
Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
---
v3
- Change from gmail to broadcom emails

 MAINTAINERS | 9 +
 1 file changed, 9 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index c25172d6471a..986b975b1d67 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4198,6 +4198,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 
+M: Florian Fainelli 
+L: bcm-kernel-feedback-l...@broadcom.com
+L: net...@vger.kernel.org
+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 
 M: Scott Branden 
-- 
2.7.4



smime.p7s
Description: S/MIME Cryptographic Signature


[PATCH net-next v6 5/6] net: phy: bcm7xxx: Add EPHY entry for 74165

2023-06-01 Thread Justin Chen
From: Florian Fainelli 

74165 is a 16nm process SoC with a 10/100 integrated Ethernet PHY,
utilize the recently defined 16nm EPHY macro to configure that PHY.

Reviewed-by: Simon Horman 
Reviewed-by: Andrew Lunn 
Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
---
 drivers/net/phy/bcm7xxx.c | 1 +
 include/linux/brcmphy.h   | 1 +
 2 files changed, 2 insertions(+)

diff --git a/drivers/net/phy/bcm7xxx.c b/drivers/net/phy/bcm7xxx.c
index f8c17a253f8b..8478b081c058 100644
--- a/drivers/net/phy/bcm7xxx.c
+++ b/drivers/net/phy/bcm7xxx.c
@@ -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)"),
diff --git a/include/linux/brcmphy.h b/include/linux/brcmphy.h
index e9afbfb6d7a5..409ec9d35051 100644
--- a/include/linux/brcmphy.h
+++ b/include/linux/brcmphy.h
@@ -44,6 +44,7 @@
 #define PHY_ID_BCM7366 0x600d8490
 #define PHY_ID_BCM7346 0x600d8650
 #define PHY_ID_BCM7362 0x600d84b0
+#define PHY_ID_BCM741650x359052c0
 #define PHY_ID_BCM7425 0x600d86b0
 #define PHY_ID_BCM7429 0x600d8730
 #define PHY_ID_BCM7435 0x600d8750
-- 
2.7.4



smime.p7s
Description: S/MIME Cryptographic Signature


[PATCH net-next v6 4/6] net: phy: mdio-bcm-unimac: Add asp v2.0 support

2023-06-01 Thread Justin Chen
Add mdio compat string for ASP 2.0 ethernet driver.

Reviewed-by: Simon Horman 
Reviewed-by: Andrew Lunn 
Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
---
 drivers/net/mdio/mdio-bcm-unimac.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/mdio/mdio-bcm-unimac.c 
b/drivers/net/mdio/mdio-bcm-unimac.c
index bfc9be23c973..6b26a0803696 100644
--- a/drivers/net/mdio/mdio-bcm-unimac.c
+++ b/drivers/net/mdio/mdio-bcm-unimac.c
@@ -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", },
-- 
2.7.4



smime.p7s
Description: S/MIME Cryptographic Signature


[PATCH net-next v6 3/6] net: bcmasp: Add support for ASP2.0 Ethernet controller

2023-06-01 Thread Justin Chen
Add 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.

This patch supports:

- Wake-on-LAN using magic packets
- basic ethtool operations (link, counters, message level)
- MAC destination address filtering (promiscuous, ALL_MULTI, etc.)

Reviewed-by: Simon Horman 
Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
---
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| 1467 
 drivers/net/ethernet/broadcom/asp2/bcmasp.h|  638 +
 .../net/ethernet/broadcom/asp2/bcmasp_ethtool.c|  568 
 drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c   | 1393 +++
 .../net/ethernet/broadcom/asp2/bcmasp_intf_defs.h  |  238 
 8 files changed, 4318 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

diff --git a/drivers/net/ethernet/broadcom/Kconfig 
b/drivers/net/ethernet/broadcom/Kconfig
index 948586bf1b5b..d4166141145d 100644
--- a/drivers/net/ethernet/broadcom/Kconfig
+++ b/drivers/net/ethernet/broadcom/Kconfig
@@ -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
diff --git a/drivers/net/ethernet/broadcom/Makefile 
b/drivers/net/ethernet/broadcom/Makefile
index 0ddfb5b5d53c..bac5cb6ad0cd 100644
--- a/drivers/net/ethernet/broadcom/Makefile
+++ b/drivers/net/ethernet/broadcom/Makefile
@@ -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/
diff --git a/drivers/net/ethernet/broadcom/asp2/Makefile 
b/drivers/net/ethernet/broadcom/asp2/Makefile
new file mode 100644
index ..e07550315f83
--- /dev/null
+++ b/drivers/net/ethernet/broadcom/asp2/Makefile
@@ -0,0 +1,2 @@
+obj-$(CONFIG_BCMASP) += bcm-asp.o
+bcm-asp-objs := bcmasp.o bcmasp_intf.o bcmasp_ethtool.o
diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp.c 
b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
new file mode 100644
index ..f4d0d20824a3
--- /dev/null
+++ b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
@@ -0,0 +1,1467 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Broadcom STB ASP 2.0 Driver
+ *
+ * Copyright (c) 2023 Broadcom
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "bcmasp.h"
+#include "bcmasp_intf_defs.h"
+
+static void _intr2_mask_clear(struct bcmasp_priv *priv, u32 mask)
+{
+   intr2_core_wl(priv, mask, ASP_INTR2_MASK_CLEAR);
+   priv->irq_mask &= ~mask;
+}
+
+static void _intr2_mask_set(struct bcmasp_priv *priv, u32 mask)
+{
+   intr2_core_wl(priv, mask, ASP_INTR2_MASK_SET);
+   priv->irq_mask |= mask;
+}
+
+void bcmasp_enable_tx_irq(struct bcmasp_intf *intf, int en)
+{
+   struct bcmasp_priv *priv = intf->parent;
+
+   if (en)
+   _intr2_mask_clear(priv, ASP_INTR2_TX_DESC(intf->channel));
+   else
+ 

[PATCH net-next v6 2/6] dt-bindings: net: Brcm ASP 2.0 Ethernet controller

2023-06-01 Thread Justin Chen
From: Florian Fainelli 

Add a binding document for the Broadcom ASP 2.0 Ethernet
controller.

Reviewed-by: Conor Dooley 
Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
---
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 | 153 +
 1 file changed, 153 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml

diff --git a/Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml 
b/Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml
new file mode 100644
index ..3f2bf64b65c0
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml
@@ -0,0 +1,153 @@
+# 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 
+  - Florian Fainelli 
+
+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#
+
+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 
+#include 
+
+ethernet@9c0 {
+compatible = "brcm,bcm72165-asp", "brcm,asp-v2.0";
+reg = <0x9c0 0x1fff14>;
+interrupts = ;
+ranges = <0x0 0x9c0 0x1fff14>;
+clocks = < 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 = <>;
+};
+
+port@1 {
+reg = <1>;
+brcm,channel = <9>;
+phy-mode = "rgmii";
+phy-handle = <>;
+};
+};
+};
-- 
2.7.4



smime.p7s
Description: S/MIME Cryptographic Signature


[PATCH net-next v6 1/6] dt-bindings: net: brcm, unimac-mdio: Add asp-v2.0

2023-06-01 Thread Justin Chen
The ASP 2.0 Ethernet controller uses a brcm unimac.

Reviewed-by: Simon Horman 
Acked-by: Conor Dooley 
Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
---
 Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml 
b/Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml
index 0be426ee1e44..6684810fcbf0 100644
--- a/Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml
+++ b/Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml
@@ -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:
-- 
2.7.4



smime.p7s
Description: S/MIME Cryptographic Signature


[PATCH net-next v6 0/6] Brcm ASP 2.0 Ethernet Controller

2023-06-01 Thread Justin Chen
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 (4):
  dt-bindings: net: brcm,unimac-mdio: Add asp-v2.0
  net: bcmasp: Add support for ASP2.0 Ethernet controller
  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 |  153 ++
 .../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| 1467 
 drivers/net/ethernet/broadcom/asp2/bcmasp.h|  638 +
 .../net/ethernet/broadcom/asp2/bcmasp_ethtool.c|  568 
 drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c   | 1393 +++
 .../net/ethernet/broadcom/asp2/bcmasp_intf_defs.h  |  238 
 drivers/net/mdio/mdio-bcm-unimac.c |2 +
 drivers/net/phy/bcm7xxx.c  |1 +
 include/linux/brcmphy.h|1 +
 14 files changed, 4486 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

-- 
2.7.4



smime.p7s
Description: S/MIME Cryptographic Signature


Re: [PATCH net-next v5 2/6] dt-bindings: net: Brcm ASP 2.0 Ethernet controller

2023-05-31 Thread Justin Chen



On 5/31/23 12:18 PM, Krzysztof Kozlowski wrote:

On 25/05/2023 01:01, Justin Chen wrote:

From: Florian Fainelli 

Add a binding document for the Broadcom ASP 2.0 Ethernet
controller.

Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
---
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 | 149 +
  1 file changed, 149 insertions(+)
  create mode 100644 Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml

diff --git a/Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml 
b/Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml
new file mode 100644
index ..c4cd24492bfd
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml
@@ -0,0 +1,149 @@
+# 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 
+  - Florian Fainelli 
+
+description: Broadcom Ethernet controller first introduced with 72165
+
+properties:
+  '#address-cells':


Judging by more comments, there will be a v6, thus please also use
consistent quotes - either ' or ".


+const: 1
+  '#size-cells':
+const: 1
+
+  compatible:


As Conor pointed out, compatible is always first.


+oneOf:
+  - items:
+  - enum:
+  - brcm,bcm74165-asp
+  - const: brcm,asp-v2.1
+  - items:
+  - enum:
+  - brcm,bcm72165-asp
+  - const: brcm,asp-v2.0
+
+  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#
+
+properties:
+  reg:
+maxItems: 1
+description: Port number
+
+  brcm,channel:
+$ref: /schemas/types.yaml#/definitions/uint32
+description: ASP channel number


Why do you need it? reg defines it. Your description does not explain
here much, except copying property name. Can we please avoid
descriptions which just copy name?


Will add a better description. The values may be different.

Thanks,
Justin


smime.p7s
Description: S/MIME Cryptographic Signature


Re: [PATCH net-next v5 3/6] net: bcmasp: Add support for ASP2.0 Ethernet controller

2023-05-26 Thread Justin Chen



On 5/25/23 8:54 PM, Jakub Kicinski wrote:

On Wed, 24 May 2023 16:01:50 -0700 Justin Chen wrote:

Add 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.

This patch supports:

- Wake-on-LAN using magic packets
- basic ethtool operations (link, counters, message level)
- MAC destination address filtering (promiscuous, ALL_MULTI, etc.)



+static netdev_tx_t bcmasp_xmit(struct sk_buff *skb, struct net_device *dev)
+{
+   struct bcmasp_intf *intf = netdev_priv(dev);
+   int spb_index, nr_frags, ret, i, j;
+   unsigned int total_bytes, size;
+   struct bcmasp_tx_cb *txcb;
+   dma_addr_t mapping, valid;
+   struct bcmasp_desc *desc;
+   bool csum_hw = false;
+   struct device *kdev;
+   skb_frag_t *frag;
+
+   kdev = >parent->pdev->dev;
+
+   spin_lock(>tx_lock);


What is the tx_lock for? netdevs already have a tx lock, unless you
declare the device as lockless.



Will remove.


+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");
+
+   netif_trans_update(dev);
+   dev->stats.tx_errors++;
+
+   netif_wake_queue(dev);


If the queue is full xmit will just put it back to sleep.
You want to try to reap completions if anything, no?



I can remove the wake. As you mentioned it won't do anything here. There 
isn't anything to reap if we are in the timeout condition. If it is some 
HW stall, we could flush and restart the ring, but if that is the case I 
rather figure out why the HW is stalling. I think we can leave it as a 
"tell the user we are stalled" and leave it as that.



+static struct net_device_stats *bcmasp_get_stats(struct net_device *dev)
+{
+   return >stats;
+}


you don't have to do this, core will use device stats if there's no ndo


+   ndev = alloc_etherdev(sizeof(struct bcmasp_intf));
+   if (!dev) {


*blink* condition is typo'ed



Oops. Good catch.

Thanks,
Justin


+   dev_warn(dev, "%s: unable to alloc ndev\n", ndev_dn->name);
+   goto err;
+   }




smime.p7s
Description: S/MIME Cryptographic Signature


[PATCH net-next v5 6/6] MAINTAINERS: ASP 2.0 Ethernet driver maintainers

2023-05-24 Thread Justin Chen
Add maintainers entry for ASP 2.0 Ethernet driver.

Reviewed-by: Simon Horman 
Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
---
v3
- Change from gmail to broadcom emails

 MAINTAINERS | 9 +
 1 file changed, 9 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index e2fd64c2ebdc..732a099f4a10 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4198,6 +4198,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 
+M: Florian Fainelli 
+L: bcm-kernel-feedback-l...@broadcom.com
+L: net...@vger.kernel.org
+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 
 M: Scott Branden 
-- 
2.7.4



smime.p7s
Description: S/MIME Cryptographic Signature


[PATCH net-next v5 5/6] net: phy: bcm7xxx: Add EPHY entry for 74165

2023-05-24 Thread Justin Chen
From: Florian Fainelli 

74165 is a 16nm process SoC with a 10/100 integrated Ethernet PHY,
utilize the recently defined 16nm EPHY macro to configure that PHY.

Reviewed-by: Simon Horman 
Reviewed-by: Andrew Lunn 
Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
---
 drivers/net/phy/bcm7xxx.c | 1 +
 include/linux/brcmphy.h   | 1 +
 2 files changed, 2 insertions(+)

diff --git a/drivers/net/phy/bcm7xxx.c b/drivers/net/phy/bcm7xxx.c
index f8c17a253f8b..8478b081c058 100644
--- a/drivers/net/phy/bcm7xxx.c
+++ b/drivers/net/phy/bcm7xxx.c
@@ -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)"),
diff --git a/include/linux/brcmphy.h b/include/linux/brcmphy.h
index e9afbfb6d7a5..409ec9d35051 100644
--- a/include/linux/brcmphy.h
+++ b/include/linux/brcmphy.h
@@ -44,6 +44,7 @@
 #define PHY_ID_BCM7366 0x600d8490
 #define PHY_ID_BCM7346 0x600d8650
 #define PHY_ID_BCM7362 0x600d84b0
+#define PHY_ID_BCM741650x359052c0
 #define PHY_ID_BCM7425 0x600d86b0
 #define PHY_ID_BCM7429 0x600d8730
 #define PHY_ID_BCM7435 0x600d8750
-- 
2.7.4



smime.p7s
Description: S/MIME Cryptographic Signature


[PATCH net-next v5 2/6] dt-bindings: net: Brcm ASP 2.0 Ethernet controller

2023-05-24 Thread Justin Chen
From: Florian Fainelli 

Add a binding document for the Broadcom ASP 2.0 Ethernet
controller.

Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
---
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 | 149 +
 1 file changed, 149 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml

diff --git a/Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml 
b/Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml
new file mode 100644
index ..c4cd24492bfd
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml
@@ -0,0 +1,149 @@
+# 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 
+  - Florian Fainelli 
+
+description: Broadcom Ethernet controller first introduced with 72165
+
+properties:
+  '#address-cells':
+const: 1
+  '#size-cells':
+const: 1
+
+  compatible:
+oneOf:
+  - items:
+  - enum:
+  - brcm,bcm74165-asp
+  - const: brcm,asp-v2.1
+  - items:
+  - enum:
+  - brcm,bcm72165-asp
+  - const: brcm,asp-v2.0
+
+  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#
+
+properties:
+  reg:
+maxItems: 1
+description: Port number
+
+  brcm,channel:
+$ref: /schemas/types.yaml#/definitions/uint32
+description: ASP channel number
+
+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 
+#include 
+
+ethernet@9c0 {
+compatible = "brcm,bcm72165-asp", "brcm,asp-v2.0";
+reg = <0x9c0 0x1fff14>;
+interrupts = ;
+ranges = <0x0 0x9c0 0x1fff14>;
+clocks = < 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 = <>;
+};
+
+port@1 {
+reg = <1>;
+brcm,channel = <9>;
+phy-mode = "rgmii";
+phy-handle = <>;
+};
+};
+};
-- 
2.7.4



smime.p7s
Description: S/MIME Cryptographic Signature


[PATCH net-next v5 3/6] net: bcmasp: Add support for ASP2.0 Ethernet controller

2023-05-24 Thread Justin Chen
Add 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.

This patch supports:

- Wake-on-LAN using magic packets
- basic ethtool operations (link, counters, message level)
- MAC destination address filtering (promiscuous, ALL_MULTI, etc.)

Reviewed-by: Simon Horman 
Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
---
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| 1462 
 drivers/net/ethernet/broadcom/asp2/bcmasp.h|  637 +
 .../net/ethernet/broadcom/asp2/bcmasp_ethtool.c|  568 
 drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c   | 1425 +++
 .../net/ethernet/broadcom/asp2/bcmasp_intf_defs.h  |  238 
 8 files changed, 4344 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

diff --git a/drivers/net/ethernet/broadcom/Kconfig 
b/drivers/net/ethernet/broadcom/Kconfig
index 948586bf1b5b..d4166141145d 100644
--- a/drivers/net/ethernet/broadcom/Kconfig
+++ b/drivers/net/ethernet/broadcom/Kconfig
@@ -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
diff --git a/drivers/net/ethernet/broadcom/Makefile 
b/drivers/net/ethernet/broadcom/Makefile
index 0ddfb5b5d53c..bac5cb6ad0cd 100644
--- a/drivers/net/ethernet/broadcom/Makefile
+++ b/drivers/net/ethernet/broadcom/Makefile
@@ -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/
diff --git a/drivers/net/ethernet/broadcom/asp2/Makefile 
b/drivers/net/ethernet/broadcom/asp2/Makefile
new file mode 100644
index ..e07550315f83
--- /dev/null
+++ b/drivers/net/ethernet/broadcom/asp2/Makefile
@@ -0,0 +1,2 @@
+obj-$(CONFIG_BCMASP) += bcm-asp.o
+bcm-asp-objs := bcmasp.o bcmasp_intf.o bcmasp_ethtool.o
diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp.c 
b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
new file mode 100644
index ..cb0d4f2de890
--- /dev/null
+++ b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
@@ -0,0 +1,1462 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Broadcom STB ASP 2.0 Driver
+ *
+ * Copyright (c) 2023 Broadcom
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "bcmasp.h"
+#include "bcmasp_intf_defs.h"
+
+static void _intr2_mask_clear(struct bcmasp_priv *priv, u32 mask)
+{
+   intr2_core_wl(priv, mask, ASP_INTR2_MASK_CLEAR);
+   priv->irq_mask &= ~mask;
+}
+
+static void _intr2_mask_set(struct bcmasp_priv *priv, u32 mask)
+{
+   intr2_core_wl(priv, mask, ASP_INTR2_MASK_SET);
+   priv->irq_mask |= mask;
+}
+
+void bcmasp_enable_tx_irq(struct bcmasp_intf *intf, int en)
+{
+   struct bcmasp_priv *priv = intf->parent;
+
+   if (en)
+   _intr2_mask_clear(priv, ASP_INTR2_TX_DESC(intf->channel));
+   else
+   _intr2_mask_set(priv, ASP_INTR2_TX_DESC(intf->channel));
+}
+EXPORT_SYMBOL_GPL(bcmasp_enable_tx_irq);
+
+void bcmasp_enable_rx_irq(struct bcmasp_intf *intf, int en)
+{
+   struct bcmasp_priv *priv = intf->parent;
+
+ 

[PATCH net-next v5 4/6] net: phy: mdio-bcm-unimac: Add asp v2.0 support

2023-05-24 Thread Justin Chen
Add mdio compat string for ASP 2.0 ethernet driver.

Reviewed-by: Simon Horman 
Reviewed-by: Andrew Lunn 
Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
---
 drivers/net/mdio/mdio-bcm-unimac.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/mdio/mdio-bcm-unimac.c 
b/drivers/net/mdio/mdio-bcm-unimac.c
index bfc9be23c973..6b26a0803696 100644
--- a/drivers/net/mdio/mdio-bcm-unimac.c
+++ b/drivers/net/mdio/mdio-bcm-unimac.c
@@ -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", },
-- 
2.7.4



smime.p7s
Description: S/MIME Cryptographic Signature


[PATCH net-next v5 1/6] dt-bindings: net: brcm, unimac-mdio: Add asp-v2.0

2023-05-24 Thread Justin Chen
The ASP 2.0 Ethernet controller uses a brcm unimac.

Reviewed-by: Simon Horman 
Acked-by: Conor Dooley 
Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
---
 Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml 
b/Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml
index 0be426ee1e44..6684810fcbf0 100644
--- a/Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml
+++ b/Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml
@@ -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:
-- 
2.7.4



smime.p7s
Description: S/MIME Cryptographic Signature


[PATCH net-next v5 0/6] Brcm ASP 2.0 Ethernet Controller

2023-05-24 Thread Justin Chen
Add support for the Broadcom ASP 2.0 Ethernet controller which is first
introduced with 72165.

Add support for 74165 10/100 integrated Ethernet PHY which also uses
the ASP 2.0 Ethernet controller.

Florian Fainelli (2):
  dt-bindings: net: Brcm ASP 2.0 Ethernet controller
  net: phy: bcm7xxx: Add EPHY entry for 74165

Justin Chen (4):
  dt-bindings: net: brcm,unimac-mdio: Add asp-v2.0
  net: bcmasp: Add support for ASP2.0 Ethernet controller
  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 |  149 ++
 .../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| 1462 
 drivers/net/ethernet/broadcom/asp2/bcmasp.h|  637 +
 .../net/ethernet/broadcom/asp2/bcmasp_ethtool.c|  568 
 drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c   | 1425 +++
 .../net/ethernet/broadcom/asp2/bcmasp_intf_defs.h  |  238 
 drivers/net/mdio/mdio-bcm-unimac.c |2 +
 drivers/net/phy/bcm7xxx.c  |1 +
 include/linux/brcmphy.h|1 +
 14 files changed, 4508 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

-- 
2.7.4



smime.p7s
Description: S/MIME Cryptographic Signature


Re: [PATCH net-next v4 2/6] dt-bindings: net: Brcm ASP 2.0 Ethernet controller

2023-05-24 Thread Justin Chen
On Tue, May 23, 2023 at 11:56 PM Conor Dooley
 wrote:
>
> On Wed, May 24, 2023 at 07:51:07AM +0100, Conor Dooley wrote:
> > Hey Justin,
> > On Tue, May 23, 2023 at 04:27:12PM -0700, Justin Chen wrote:
> > > On Tue, May 23, 2023 at 3:55 PM Conor Dooley  wrote:
> > > > On Tue, May 23, 2023 at 02:53:43PM -0700, Justin Chen wrote:
> > > >
> > > > > +  compatible:
> > > > > +enum:
> > > > > +  - brcm,asp-v2.0
> > > > > +  - brcm,bcm72165-asp
> > > > > +  - brcm,asp-v2.1
> > > > > +  - brcm,bcm74165-asp
> > > >
> > > > > +compatible = "brcm,bcm72165-asp", "brcm,asp-v2.0";
> > > >
> > > > You can't do this, as Rob's bot has pointed out. Please test the
> > > > bindings :( You need one of these type of constructs:
> > > >
> > > > compatible:
> > > >   oneOf:
> > > > - items:
> > > > - const: brcm,bcm72165-asp
> > > > - const: brcm,asp-v2.0
> > > > - items:
> > > > - const: brcm,bcm74165-asp
> > > > - const: brcm,asp-v2.1
> > > >
> > > > Although, given either you or Florian said there are likely to be
> > > > multiple parts, going for an enum, rather than const for the brcm,bcm..
> > > > entry will prevent some churn. Up to you.
> > > >
> > > Urg so close. Thought it was a trivial change, so didn't bother
> > > retesting the binding. I think I have it right now...
> > >
> > >   compatible:
> > > oneOf:
> > >   - items:
> > >   - enum:
> > >   - brcm,bcm72165-asp
> > >   - brcm,bcm74165-asp
> > >   - enum:
> > >   - brcm,asp-v2.0
> > >   - brcm,asp-v2.1
> > >
> > > Something like this look good?
> >
> > I am still caffeine-less, but this implies that both of
> > "brcm,bcm72165-asp", "brcm,asp-v2.0"
> > _and_
> > "brcm,bcm72165-asp", "brcm,asp-v2.1"
> > are. I suspect that that is not the case, unless "brcm,asp-v2.0" is a
>
> I a word. s/are/are valid/
>
Gotcha. I got something like this now.

  compatible:
oneOf:
  - items:
  - enum:
  - brcm,bcm74165-asp
  - const: brcm,asp-v2.1
  - items:
  - enum:
  - brcm,bcm72165-asp
  - const: brcm,asp-v2.0

Apologies, still getting used to this yaml stuff. Starting to make a
bit more sense to me now.

> > valid fallback for "brcm,asp-v2.1"?
> > The oneOf: also becomes redundant since you only have one items:.
> >
> > > Will submit a v5 tomorrow.
> >
> > BTW, when you do, could you use the address listed in MAINTAINERS rather
> > than the one you used for this version?
> >
I changed the address listed in MAINTAINERS from the previous versions
of this patchset. The current version should match the address that
this patch set was sent from. Looks like I forgot to add a changelog
for that in v4.

Thanks,
Justin

> > Cheers,
> > Conor.


smime.p7s
Description: S/MIME Cryptographic Signature


Re: [PATCH net-next v4 2/6] dt-bindings: net: Brcm ASP 2.0 Ethernet controller

2023-05-23 Thread Justin Chen
On Tue, May 23, 2023 at 3:55 PM Conor Dooley  wrote:
>
> Hey Justin,
>
> On Tue, May 23, 2023 at 02:53:43PM -0700, Justin Chen wrote:
>
> > +  compatible:
> > +enum:
> > +  - brcm,asp-v2.0
> > +  - brcm,bcm72165-asp
> > +  - brcm,asp-v2.1
> > +  - brcm,bcm74165-asp
>
> > +compatible = "brcm,bcm72165-asp", "brcm,asp-v2.0";
>
> You can't do this, as Rob's bot has pointed out. Please test the
> bindings :( You need one of these type of constructs:
>
> compatible:
>   oneOf:
> - items:
> - const: brcm,bcm72165-asp
> - const: brcm,asp-v2.0
> - items:
> - const: brcm,bcm74165-asp
> - const: brcm,asp-v2.1
>
> Although, given either you or Florian said there are likely to be
> multiple parts, going for an enum, rather than const for the brcm,bcm..
> entry will prevent some churn. Up to you.
>
Urg so close. Thought it was a trivial change, so didn't bother
retesting the binding. I think I have it right now...

  compatible:
oneOf:
  - items:
  - enum:
  - brcm,bcm72165-asp
  - brcm,bcm74165-asp
  - enum:
  - brcm,asp-v2.0
  - brcm,asp-v2.1

Something like this look good? Will submit a v5 tomorrow.

Thanks,
Justin

> Cheers,
> Conor.


smime.p7s
Description: S/MIME Cryptographic Signature


[PATCH net-next v4 5/6] net: phy: bcm7xxx: Add EPHY entry for 74165

2023-05-23 Thread Justin Chen
From: Florian Fainelli 

74165 is a 16nm process SoC with a 10/100 integrated Ethernet PHY,
utilize the recently defined 16nm EPHY macro to configure that PHY.

Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
Reviewed-by: Andrew Lunn 
---
 drivers/net/phy/bcm7xxx.c | 1 +
 include/linux/brcmphy.h   | 1 +
 2 files changed, 2 insertions(+)

diff --git a/drivers/net/phy/bcm7xxx.c b/drivers/net/phy/bcm7xxx.c
index f8c17a253f8b..8478b081c058 100644
--- a/drivers/net/phy/bcm7xxx.c
+++ b/drivers/net/phy/bcm7xxx.c
@@ -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)"),
diff --git a/include/linux/brcmphy.h b/include/linux/brcmphy.h
index e9afbfb6d7a5..409ec9d35051 100644
--- a/include/linux/brcmphy.h
+++ b/include/linux/brcmphy.h
@@ -44,6 +44,7 @@
 #define PHY_ID_BCM7366 0x600d8490
 #define PHY_ID_BCM7346 0x600d8650
 #define PHY_ID_BCM7362 0x600d84b0
+#define PHY_ID_BCM741650x359052c0
 #define PHY_ID_BCM7425 0x600d86b0
 #define PHY_ID_BCM7429 0x600d8730
 #define PHY_ID_BCM7435 0x600d8750
-- 
2.7.4



smime.p7s
Description: S/MIME Cryptographic Signature


[PATCH net-next v4 6/6] MAINTAINERS: ASP 2.0 Ethernet driver maintainers

2023-05-23 Thread Justin Chen
Add maintainers entry for ASP 2.0 Ethernet driver.

Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
---
 MAINTAINERS | 9 +
 1 file changed, 9 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index e2fd64c2ebdc..732a099f4a10 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4198,6 +4198,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 
+M: Florian Fainelli 
+L: bcm-kernel-feedback-l...@broadcom.com
+L: net...@vger.kernel.org
+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 
 M: Scott Branden 
-- 
2.7.4



smime.p7s
Description: S/MIME Cryptographic Signature


[PATCH net-next v4 1/6] dt-bindings: net: brcm, unimac-mdio: Add asp-v2.0

2023-05-23 Thread Justin Chen
The ASP 2.0 Ethernet controller uses a brcm unimac.

Acked-by: Conor Dooley 
Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
---
 Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml 
b/Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml
index 0be426ee1e44..6684810fcbf0 100644
--- a/Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml
+++ b/Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml
@@ -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:
-- 
2.7.4



smime.p7s
Description: S/MIME Cryptographic Signature


[PATCH net-next v4 3/6] net: bcmasp: Add support for ASP2.0 Ethernet controller

2023-05-23 Thread Justin Chen
Add 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.

This patch supports:

- Wake-on-LAN using magic packets
- basic ethtool operations (link, counters, message level)
- MAC destination address filtering (promiscuous, ALL_MULTI, etc.)

Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
---
v4
- Address sparse warnings
- Fix one more reverse xmas tree violation
- Improve error logic for bcmasp_netfilt_get_reg_offset()

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| 1462 
 drivers/net/ethernet/broadcom/asp2/bcmasp.h|  637 +
 .../net/ethernet/broadcom/asp2/bcmasp_ethtool.c|  568 
 drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c   | 1425 +++
 .../net/ethernet/broadcom/asp2/bcmasp_intf_defs.h  |  238 
 8 files changed, 4344 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

diff --git a/drivers/net/ethernet/broadcom/Kconfig 
b/drivers/net/ethernet/broadcom/Kconfig
index 948586bf1b5b..d4166141145d 100644
--- a/drivers/net/ethernet/broadcom/Kconfig
+++ b/drivers/net/ethernet/broadcom/Kconfig
@@ -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
diff --git a/drivers/net/ethernet/broadcom/Makefile 
b/drivers/net/ethernet/broadcom/Makefile
index 0ddfb5b5d53c..bac5cb6ad0cd 100644
--- a/drivers/net/ethernet/broadcom/Makefile
+++ b/drivers/net/ethernet/broadcom/Makefile
@@ -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/
diff --git a/drivers/net/ethernet/broadcom/asp2/Makefile 
b/drivers/net/ethernet/broadcom/asp2/Makefile
new file mode 100644
index ..e07550315f83
--- /dev/null
+++ b/drivers/net/ethernet/broadcom/asp2/Makefile
@@ -0,0 +1,2 @@
+obj-$(CONFIG_BCMASP) += bcm-asp.o
+bcm-asp-objs := bcmasp.o bcmasp_intf.o bcmasp_ethtool.o
diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp.c 
b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
new file mode 100644
index ..b89392bc5495
--- /dev/null
+++ b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
@@ -0,0 +1,1462 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Broadcom STB ASP 2.0 Driver
+ *
+ * Copyright (c) 2023 Broadcom
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "bcmasp.h"
+#include "bcmasp_intf_defs.h"
+
+static void _intr2_mask_clear(struct bcmasp_priv *priv, u32 mask)
+{
+   intr2_core_wl(priv, mask, ASP_INTR2_MASK_CLEAR);
+   priv->irq_mask &= ~mask;
+}
+
+static void _intr2_mask_set(struct bcmasp_priv *priv, u32 mask)
+{
+   intr2_core_wl(priv, mask, ASP_INTR2_MASK_SET);
+   priv->irq_mask |= mask;
+}
+
+void bcmasp_enable_tx_irq(struct bcmasp_intf *intf, int en)
+{
+   struct bcmasp_priv *priv = intf->parent;
+
+   if (en)
+   _intr2_mask_clear(priv, ASP_INTR2_TX_DESC(intf->channel));
+   else
+   _intr2_mask_set(priv, ASP_INTR2_TX_DESC(intf->channel));
+}
+EXPORT_SYMBOL_GPL(bcmasp_enable_tx_irq);
+
+void bcmasp_enable_rx_irq(struct bcmasp_intf *intf, int en)
+{
+   struct bcmasp_priv *priv = intf->parent;
+
+   if (en)
+   _intr2_mask_clear(priv, ASP_INTR2_RX_ECH(intf->channel));
+   else
+   _intr2_mask_set(priv, ASP_INTR2_RX_ECH(intf

[PATCH net-next v4 4/6] net: phy: mdio-bcm-unimac: Add asp v2.0 support

2023-05-23 Thread Justin Chen
Add mdio compat string for ASP 2.0 ethernet driver.

Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
Reviewed-by: Andrew Lunn 
---
 drivers/net/mdio/mdio-bcm-unimac.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/mdio/mdio-bcm-unimac.c 
b/drivers/net/mdio/mdio-bcm-unimac.c
index bfc9be23c973..6b26a0803696 100644
--- a/drivers/net/mdio/mdio-bcm-unimac.c
+++ b/drivers/net/mdio/mdio-bcm-unimac.c
@@ -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", },
-- 
2.7.4



smime.p7s
Description: S/MIME Cryptographic Signature


[PATCH net-next v4 2/6] dt-bindings: net: Brcm ASP 2.0 Ethernet controller

2023-05-23 Thread Justin Chen
From: Florian Fainelli 

Add a binding document for the Broadcom ASP 2.0 Ethernet
controller.

Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
---
v3
- 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 | 145 +
 1 file changed, 145 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml

diff --git a/Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml 
b/Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml
new file mode 100644
index ..07f7373b9d64
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml
@@ -0,0 +1,145 @@
+# 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 
+  - Florian Fainelli 
+
+description: Broadcom Ethernet controller first introduced with 72165
+
+properties:
+  '#address-cells':
+const: 1
+  '#size-cells':
+const: 1
+
+  compatible:
+enum:
+  - brcm,asp-v2.0
+  - brcm,bcm72165-asp
+  - brcm,asp-v2.1
+  - brcm,bcm74165-asp
+
+  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#
+
+properties:
+  reg:
+maxItems: 1
+description: Port number
+
+  brcm,channel:
+$ref: /schemas/types.yaml#/definitions/uint32
+description: ASP channel number
+
+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 
+#include 
+
+ethernet@9c0 {
+compatible = "brcm,bcm72165-asp", "brcm,asp-v2.0";
+reg = <0x9c0 0x1fff14>;
+interrupts = ;
+ranges = <0x0 0x9c0 0x1fff14>;
+clocks = < 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 = <>;
+};
+
+port@1 {
+reg = <1>;
+brcm,channel = <9>;
+phy-mode = "rgmii";
+phy-handle = <>;
+};
+};
+};
-- 
2.7.4



smime.p7s
Description: S/MIME Cryptographic Signature


[PATCH net-next v4 0/6] Brcm ASP 2.0 Ethernet Controller

2023-05-23 Thread Justin Chen
Add support for the Broadcom ASP 2.0 Ethernet controller which is first
introduced with 72165.

Add support for 74165 10/100 integrated Ethernet PHY which also uses
the ASP 2.0 Ethernet controller.

Florian Fainelli (2):
  dt-bindings: net: Brcm ASP 2.0 Ethernet controller
  net: phy: bcm7xxx: Add EPHY entry for 74165

Justin Chen (4):
  dt-bindings: net: brcm,unimac-mdio: Add asp-v2.0
  net: bcmasp: Add support for ASP2.0 Ethernet controller
  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 |  145 ++
 .../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| 1462 
 drivers/net/ethernet/broadcom/asp2/bcmasp.h|  637 +
 .../net/ethernet/broadcom/asp2/bcmasp_ethtool.c|  568 
 drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c   | 1425 +++
 .../net/ethernet/broadcom/asp2/bcmasp_intf_defs.h  |  238 
 drivers/net/mdio/mdio-bcm-unimac.c |2 +
 drivers/net/phy/bcm7xxx.c  |1 +
 include/linux/brcmphy.h|1 +
 14 files changed, 4504 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

-- 
2.7.4



smime.p7s
Description: S/MIME Cryptographic Signature


Re: [PATCH net-next v3 2/6] dt-bindings: net: Brcm ASP 2.0 Ethernet controller

2023-05-23 Thread Justin Chen
On Mon, May 22, 2023 at 11:27 AM Conor Dooley  wrote:
>
> On Fri, May 19, 2023 at 02:19:40PM -0700, Justin Chen wrote:
>  > From: Florian Fainelli 
>  >
>  > Add a binding document for the Broadcom ASP 2.0 Ethernet controller.
>  >
>  > Signed-off-by: Florian Fainelli 
>  > Signed-off-by: Justin Chen 
>  > ---
>
> Same deal here, usual mailer is refusing to reply cos of:
> Problem signature from:
> 1.2.840.113549.1.9.1=#6A757374696E2E6368656E4062726F6164636F6D2E636F6D,CN=Justin
> Chen,O=Broadcom Inc.,L=Bangalore,ST=Karnataka,C=IN
> aka: 
> created: Fri 19 May 2023 10:19:57 PM IST
> expires: Wed 10 Sep 2025 01:39:50 PM IST
>
>  > 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 | 145
> +
>  >  1 file changed, 145 insertions(+)
>  >  create mode 100644
> Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml
>  >
>  > diff --git a/Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml
> b/Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml
>  > new file mode 100644
>  > index ..a9fed957e1d6
>  > --- /dev/null
>  > +++ b/Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml
>  > @@ -0,0 +1,145 @@
>  > +# 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 
>  > +  - Florian Fainelli 
>  > +
>  > +description: Broadcom Ethernet controller first introduced with 72165
>  > +
>  > +properties:
>  > +  '#address-cells':
>  > +const: 1
>  > +  '#size-cells':
>  > +const: 1
>  > +
>  > +  compatible:
>  > +enum:
>  > +  - brcm,asp-v2.0
>  > +  - brcm,bcm72165-asp
>  > +  - brcm,asp-v2.1
>  > +  - brcm,bcm74165-asp
>
> One of Rob's questions on V(N-1) that seems to have been ignored/only
> partly implemented:
>  > You have 1 SoC per version, so what's the point of versions? If you have
>  > more coming, then fine, but I'd expect it to be something like this:
>  >
>  > compatible = "brcm,bcm74165-asp-v2.1", "brcm,asp-v2.1";
>
> You did drop the -v2.1 that he requested from the SoC compatible, but I
> amn't sure why the above was not implemented (at least there's no
> explanation in the previous thread's version, nor in the changelog
> here...)

Will fix it. Didn't realize he was talking about the compat string in
the example below.

Thanks,
Justin

>
> Cheers,
> Conor


smime.p7s
Description: S/MIME Cryptographic Signature


[PATCH net-next v3 1/6] dt-bindings: net: brcm, unimac-mdio: Add asp-v2.0

2023-05-20 Thread Justin Chen
The ASP 2.0 Ethernet controller uses a brcm unimac.

Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
---
 Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml 
b/Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml
index 0be426ee1e44..6684810fcbf0 100644
--- a/Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml
+++ b/Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml
@@ -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:
-- 
2.7.4



smime.p7s
Description: S/MIME Cryptographic Signature


[PATCH net-next v3 5/6] net: phy: bcm7xxx: Add EPHY entry for 74165

2023-05-20 Thread Justin Chen
From: Florian Fainelli 

74165 is a 16nm process SoC with a 10/100 integrated Ethernet PHY,
utilize the recently defined 16nm EPHY macro to configure that PHY.

Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
Reviewed-by: Andrew Lunn 
---
 drivers/net/phy/bcm7xxx.c | 1 +
 include/linux/brcmphy.h   | 1 +
 2 files changed, 2 insertions(+)

diff --git a/drivers/net/phy/bcm7xxx.c b/drivers/net/phy/bcm7xxx.c
index f8c17a253f8b..8478b081c058 100644
--- a/drivers/net/phy/bcm7xxx.c
+++ b/drivers/net/phy/bcm7xxx.c
@@ -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)"),
diff --git a/include/linux/brcmphy.h b/include/linux/brcmphy.h
index e9afbfb6d7a5..409ec9d35051 100644
--- a/include/linux/brcmphy.h
+++ b/include/linux/brcmphy.h
@@ -44,6 +44,7 @@
 #define PHY_ID_BCM7366 0x600d8490
 #define PHY_ID_BCM7346 0x600d8650
 #define PHY_ID_BCM7362 0x600d84b0
+#define PHY_ID_BCM741650x359052c0
 #define PHY_ID_BCM7425 0x600d86b0
 #define PHY_ID_BCM7429 0x600d8730
 #define PHY_ID_BCM7435 0x600d8750
-- 
2.7.4



smime.p7s
Description: S/MIME Cryptographic Signature


[PATCH net-next v3 4/6] net: phy: mdio-bcm-unimac: Add asp v2.0 support

2023-05-20 Thread Justin Chen
Add mdio compat string for ASP 2.0 ethernet driver.

Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
Reviewed-by: Andrew Lunn 
---
 drivers/net/mdio/mdio-bcm-unimac.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/mdio/mdio-bcm-unimac.c 
b/drivers/net/mdio/mdio-bcm-unimac.c
index bfc9be23c973..6b26a0803696 100644
--- a/drivers/net/mdio/mdio-bcm-unimac.c
+++ b/drivers/net/mdio/mdio-bcm-unimac.c
@@ -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", },
-- 
2.7.4



smime.p7s
Description: S/MIME Cryptographic Signature


[PATCH net-next v3 0/6] Brcm ASP 2.0 Ethernet Controller

2023-05-20 Thread Justin Chen
Add support for the Broadcom ASP 2.0 Ethernet controller which is first
introduced with 72165.

Add support for 74165 10/100 integrated Ethernet PHY which also uses
the ASP 2.0 Ethernet controller.

Florian Fainelli (2):
  dt-bindings: net: Brcm ASP 2.0 Ethernet controller
  net: phy: bcm7xxx: Add EPHY entry for 74165

Justin Chen (4):
  dt-bindings: net: brcm,unimac-mdio: Add asp-v2.0
  net: bcmasp: Add support for ASP2.0 Ethernet controller
  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 |  145 ++
 .../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| 1460 
 drivers/net/ethernet/broadcom/asp2/bcmasp.h|  636 +
 .../net/ethernet/broadcom/asp2/bcmasp_ethtool.c|  568 
 drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c   | 1429 +++
 .../net/ethernet/broadcom/asp2/bcmasp_intf_defs.h  |  238 
 drivers/net/mdio/mdio-bcm-unimac.c |2 +
 drivers/net/phy/bcm7xxx.c  |1 +
 include/linux/brcmphy.h|1 +
 14 files changed, 4505 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

-- 
2.7.4



smime.p7s
Description: S/MIME Cryptographic Signature


[PATCH net-next v3 3/6] net: bcmasp: Add support for ASP2.0 Ethernet controller

2023-05-20 Thread Justin Chen
Add 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.

This patch supports:

- Wake-on-LAN using magic packets
- basic ethtool operations (link, counters, message level)
- MAC destination address filtering (promiscuous, ALL_MULTI, etc.)

Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
---
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| 1460 
 drivers/net/ethernet/broadcom/asp2/bcmasp.h|  636 +
 .../net/ethernet/broadcom/asp2/bcmasp_ethtool.c|  568 
 drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c   | 1429 +++
 .../net/ethernet/broadcom/asp2/bcmasp_intf_defs.h  |  238 
 8 files changed, 4345 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

diff --git a/drivers/net/ethernet/broadcom/Kconfig 
b/drivers/net/ethernet/broadcom/Kconfig
index 948586bf1b5b..d4166141145d 100644
--- a/drivers/net/ethernet/broadcom/Kconfig
+++ b/drivers/net/ethernet/broadcom/Kconfig
@@ -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
diff --git a/drivers/net/ethernet/broadcom/Makefile 
b/drivers/net/ethernet/broadcom/Makefile
index 0ddfb5b5d53c..bac5cb6ad0cd 100644
--- a/drivers/net/ethernet/broadcom/Makefile
+++ b/drivers/net/ethernet/broadcom/Makefile
@@ -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/
diff --git a/drivers/net/ethernet/broadcom/asp2/Makefile 
b/drivers/net/ethernet/broadcom/asp2/Makefile
new file mode 100644
index ..e07550315f83
--- /dev/null
+++ b/drivers/net/ethernet/broadcom/asp2/Makefile
@@ -0,0 +1,2 @@
+obj-$(CONFIG_BCMASP) += bcm-asp.o
+bcm-asp-objs := bcmasp.o bcmasp_intf.o bcmasp_ethtool.o
diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp.c 
b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
new file mode 100644
index ..6e0c7df62c1e
--- /dev/null
+++ b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
@@ -0,0 +1,1460 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Broadcom STB ASP 2.0 Driver
+ *
+ * Copyright (c) 2020 Broadcom
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "bcmasp.h"
+#include "bcmasp_intf_defs.h"
+
+static void _intr2_mask_clear(struct bcmasp_priv *priv, u32 mask)
+{
+   intr2_core_wl(priv, mask, ASP_INTR2_MASK_CLEAR);
+   priv->irq_mask &= ~mask;
+}
+
+static void _intr2_mask_set(struct bcmasp_priv *priv, u32 mask)
+{
+   intr2_core_wl(priv, mask, ASP_INTR2_MASK_SET);
+   priv->irq_mask |= mask;
+}
+
+void bcmasp_enable_tx_irq(struct bcmasp_intf *intf, int en)
+{
+   struct bcmasp_priv *priv = intf->parent;
+
+   if (en)
+   _intr2_mask_clear(priv, ASP_INTR2_TX_DESC(intf->channel));
+   else
+   _intr2_mask_set(priv, ASP_INTR2_TX_DESC(intf->channel));
+}
+EXPORT_SYMBOL_GPL(bcmasp_enable_tx_irq);
+
+void bcmasp_enable_rx_irq(struct bcmasp_intf *intf, int en)
+{
+   struct bcmasp_priv *priv = intf->parent;
+
+   if (en)
+   _intr2_mask_clear(priv, ASP_INTR2_RX_ECH(intf->channel));
+   else
+   _intr2_mask_set(priv, ASP_INTR2_RX_ECH(intf->channel));
+}
+EXPORT_SYMBOL_GPL(bcmasp_enable_rx_irq);
+
+static void bcmasp_intr2_mask_set_all(struct bcmasp_priv *priv)
+{
+   _intr2_mask_

[PATCH net-next v3 6/6] MAINTAINERS: ASP 2.0 Ethernet driver maintainers

2023-05-20 Thread Justin Chen
Add maintainers entry for ASP 2.0 Ethernet driver.

Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
---
v3
Change from gmail to broadcom emails

 MAINTAINERS | 9 +
 1 file changed, 9 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index e2fd64c2ebdc..732a099f4a10 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4198,6 +4198,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 
+M: Florian Fainelli 
+L: bcm-kernel-feedback-l...@broadcom.com
+L: net...@vger.kernel.org
+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 
 M: Scott Branden 
-- 
2.7.4



smime.p7s
Description: S/MIME Cryptographic Signature


[PATCH net-next v3 2/6] dt-bindings: net: Brcm ASP 2.0 Ethernet controller

2023-05-20 Thread Justin Chen
From: Florian Fainelli 

Add a binding document for the Broadcom ASP 2.0 Ethernet controller.

Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
---
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 | 145 +
 1 file changed, 145 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml

diff --git a/Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml 
b/Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml
new file mode 100644
index ..a9fed957e1d6
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml
@@ -0,0 +1,145 @@
+# 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 
+  - Florian Fainelli 
+
+description: Broadcom Ethernet controller first introduced with 72165
+
+properties:
+  '#address-cells':
+const: 1
+  '#size-cells':
+const: 1
+
+  compatible:
+enum:
+  - brcm,asp-v2.0
+  - brcm,bcm72165-asp
+  - brcm,asp-v2.1
+  - brcm,bcm74165-asp
+
+  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#
+
+properties:
+  reg:
+maxItems: 1
+description: Port number
+
+  brcm,channel:
+$ref: /schemas/types.yaml#/definitions/uint32
+description: ASP channel number
+
+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 
+#include 
+
+ethernet@9c0 {
+compatible = "brcm,asp-v2.0";
+reg = <0x9c0 0x1fff14>;
+interrupts = ;
+ranges = <0x0 0x9c0 0x1fff14>;
+clocks = < 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 = <>;
+};
+
+port@1 {
+reg = <1>;
+brcm,channel = <9>;
+phy-mode = "rgmii";
+phy-handle = <>;
+};
+};
+};
-- 
2.7.4



smime.p7s
Description: S/MIME Cryptographic Signature


Re: [PATCH v2 net-next 3/6] net: bcmasp: Add support for ASP2.0 Ethernet controller

2023-05-02 Thread Justin Chen
On Tue, May 2, 2023 at 12:44 PM Simon Horman  wrote:
>
> On Wed, Apr 26, 2023 at 11:54:29AM -0700, Justin Chen wrote:
> > Add 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.
> >
> > This patch supports:
> >
> > - Wake-on-LAN using magic packets
> > - basic ethtool operations (link, counters, message level)
> > - MAC destination address filtering (promiscuous, ALL_MULTI, etc.)
> >
> > Signed-off-by: Florian Fainelli 
> > Signed-off-by: Justin Chen 
>
> ...
>
> > diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp.c 
> > b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
>
> ...
>
> > +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;
> > + }
>
> block_index and filter_sel are uninitialised if offset doesn't match any
> of the conditions above. Can that happen?
>

Nope. This is a helper function for netfilter read and write reg, we
check offset sizes in those functions.

> > +
> > + 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_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 = 0x;
>
> mask_17 is __be16, but 0x is host byte order.
>
> Please make sure there are no new warnings when building with W=1 C=1.
>
> ...
>
> > +/* 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_priv *priv = intf->parent;
> > + struct bcmasp_net_filter *nfilter = NULL;
> > + int i, open_index = -1;
>
> Please use reverse xmas tree - longest line to shortest - for local
> variable declarations in networking code.
>
> You can check for this using https://github.com/ecree-solarflare/xmastree
>
> ...
>
> > +static int bcmasp_combine_set_filter(struct bcmasp_intf *intf,
> > +  unsigned char *addr, unsigned char *mask,
> > +  int i)
> > +{
> >

Re: [PATCH v2 net-next 2/6] dt-bindings: net: Brcm ASP 2.0 Ethernet controller

2023-04-27 Thread Justin Chen
On Thu, Apr 27, 2023 at 10:16 AM Rob Herring  wrote:
>
> On Wed, Apr 26, 2023 at 11:54:28AM -0700, Justin Chen wrote:
> > From: Florian Fainelli 
> >
> > Add a binding document for the Broadcom ASP 2.0 Ethernet
> > controller.
> >
> > Signed-off-by: Florian Fainelli 
> > Signed-off-by: Justin Chen 
> > ---
> >  .../devicetree/bindings/net/brcm,asp-v2.0.yaml | 145 
> > +
> >  1 file changed, 145 insertions(+)
> >  create mode 100644 Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml
> >
> > diff --git a/Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml 
> > b/Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml
> > new file mode 100644
> > index ..818d91692e6e
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml
> > @@ -0,0 +1,145 @@
> > +# 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 
> > +  - Florian Fainelli 
> > +
> > +description: Broadcom Ethernet controller first introduced with 72165
> > +
> > +properties:
> > +  '#address-cells':
> > +const: 1
> > +  '#size-cells':
> > +const: 1
> > +
> > +  compatible:
> > +enum:
> > +  - brcm,asp-v2.0
> > +  - brcm,bcm72165-asp-v2.0
> > +  - brcm,asp-v2.1
> > +  - brcm,bcm74165-asp-v2.1
>
> You have 1 SoC per version, so what's the point of versions? If you have
> more coming, then fine, but I'd expect it to be something like this:
>
> compatible = "brcm,bcm74165-asp-v2.1", "brcm,asp-v2.1";
>
> Also, the version in the SoC specific compatible is redundant. Just
> "brcm,bcm74165-asp" is enough.
>
> v2.1 is not compatible with v2.0? What that means is would a client/OS
> that only understands what v2.0 is work with v2.1 h/w? If so, you should
> have fallback compatible.
>
v2.1 is not compatible with v2.0 unfortunately. So no, a client/OS
that only understands v2.0 will not work with v2.1 h/w.

> > +
> > +  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:
>
> The ethernet-switch.yaml schema doesn't work for you?
>
Technically it is not a switch. But it might work... If we use port to
reference the unimac and reg to reference the ethernet channel. I
rather not though, just cause it is not a switch, so calling it an
ethernet-switch is confusing.

> > +type: object
> > +properties:
> > +  '#address-cells':
> > +const: 1
> > +  '#size-cells':
> > +const: 0
> > +
> > +patternProperties:
> > +  "^port@[0-9]+$":
> > +type: object
> > +
> > +$ref: ethernet-controller.yaml#
> > +
> > +properties:
> > +  reg:
> > +maxItems: 1
> > +description: Port number
> > +
> > +  channel:
> > +maxItems: 1
> > +description: ASP channel number
>
> Not a standard property, so it needs a type and vendor prefix. However,
> what's the difference between channel and port? Can the port numbers
> correspond to the channels?
>
Port refers to the unimac. In our case we currently have a maximum of
2. Channel refers to the ethernet hardware channel proper, in which we
have many. So yes, you can have a port correlate to any channel.

> > +
> > +required:
> > +  - reg
> > +  - channel
> > +
> > +additionalProperties: false
> > +
> > +patternProperties:
> > +  "^mdio@[0-9a-f]+$":
> > +type: object
> > +$ref: "brcm,unimac-mdio.yaml"
>
> Drop quotes.
>
> > +
> > +description:
> > +  ASP internal UniMAC MDIO bus
> > +
> > +required:
> > +  - compatible
> > +  - reg
> > +  - interrupts
> > +  - clocks
> > +  - ranges
> > +
> > +additionalProperties: false
> > +
> > +examples:
> > +  - |
> > +#include 

[PATCH v2 net-next 6/6] MAINTAINERS: ASP 2.0 Ethernet driver maintainers

2023-04-26 Thread Justin Chen
Add maintainers entry for ASP 2.0 Ethernet driver.

Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
---
 MAINTAINERS | 9 +
 1 file changed, 9 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 4fc57dfd5fd0..24cbe1c0fc06 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4189,6 +4189,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 
+M: Florian Fainelli 
+L: bcm-kernel-feedback-l...@broadcom.com
+L: net...@vger.kernel.org
+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 
 M: Scott Branden 
-- 
2.7.4



[PATCH v2 net-next 3/6] net: bcmasp: Add support for ASP2.0 Ethernet controller

2023-04-26 Thread Justin Chen
Add 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.

This patch supports:

- Wake-on-LAN using magic packets
- basic ethtool operations (link, counters, message level)
- MAC destination address filtering (promiscuous, ALL_MULTI, etc.)

Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
---
 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| 1476 
 drivers/net/ethernet/broadcom/asp2/bcmasp.h|  636 +
 .../net/ethernet/broadcom/asp2/bcmasp_ethtool.c|  585 
 drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c   | 1435 +++
 .../net/ethernet/broadcom/asp2/bcmasp_intf_defs.h  |  238 
 8 files changed, 4384 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

diff --git a/drivers/net/ethernet/broadcom/Kconfig 
b/drivers/net/ethernet/broadcom/Kconfig
index 948586bf1b5b..d4166141145d 100644
--- a/drivers/net/ethernet/broadcom/Kconfig
+++ b/drivers/net/ethernet/broadcom/Kconfig
@@ -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
diff --git a/drivers/net/ethernet/broadcom/Makefile 
b/drivers/net/ethernet/broadcom/Makefile
index 0ddfb5b5d53c..bac5cb6ad0cd 100644
--- a/drivers/net/ethernet/broadcom/Makefile
+++ b/drivers/net/ethernet/broadcom/Makefile
@@ -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/
diff --git a/drivers/net/ethernet/broadcom/asp2/Makefile 
b/drivers/net/ethernet/broadcom/asp2/Makefile
new file mode 100644
index ..e07550315f83
--- /dev/null
+++ b/drivers/net/ethernet/broadcom/asp2/Makefile
@@ -0,0 +1,2 @@
+obj-$(CONFIG_BCMASP) += bcm-asp.o
+bcm-asp-objs := bcmasp.o bcmasp_intf.o bcmasp_ethtool.o
diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp.c 
b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
new file mode 100644
index ..c253bda9ff66
--- /dev/null
+++ b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
@@ -0,0 +1,1476 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Broadcom STB ASP 2.0 Driver
+ *
+ * Copyright (c) 2020 Broadcom
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "bcmasp.h"
+#include "bcmasp_intf_defs.h"
+
+static void _intr2_mask_clear(struct bcmasp_priv *priv, u32 mask)
+{
+   intr2_core_wl(priv, mask, ASP_INTR2_MASK_CLEAR);
+   priv->irq_mask &= ~mask;
+}
+
+static void _intr2_mask_set(struct bcmasp_priv *priv, u32 mask)
+{
+   intr2_core_wl(priv, mask, ASP_INTR2_MASK_SET);
+   priv->irq_mask |= mask;
+}
+
+void bcmasp_enable_tx_irq(struct bcmasp_intf *intf, int en)
+{
+   struct bcmasp_priv *priv = intf->parent;
+
+   if (en)
+   _intr2_mask_clear(priv, ASP_INTR2_TX_DESC(intf->channel));
+   else
+   _intr2_mask_set(priv, ASP_INTR2_TX_DESC(intf->channel));
+}
+EXPORT_SYMBOL_GPL(bcmasp_enable_tx_irq);
+
+void bcmasp_enable_rx_irq(struct bcmasp_intf *intf, int en)
+{
+   struct bcmasp_priv *priv = intf->parent;
+
+   if (en)
+   _intr2_mask_clear(priv, ASP_INTR2_RX_ECH(intf->channel));
+   else
+   _intr2_mask_set(priv, ASP_INTR2_RX_ECH(intf->channel));
+}
+EXPORT_SYMBOL_GPL(bcmasp_enable_rx_irq);
+
+static void bcmasp_intr2_mask_set_all(struct bcmasp_priv *priv)
+{
+   _intr2_mask_set(priv, 0x);
+   priv->irq_mask = 0x;
+}
+
+static void bcmasp_intr2_clear_all(struct bcmasp_priv *priv)
+{
+   intr2_core_wl(priv, 0x, ASP_INTR2_CLEAR);
+}
+
+static void bcmasp_intr2_handling(struct bcmasp_intf *intf, u32 status)
+{
+   if (status & ASP_INTR2_RX_ECH(intf-&g

[PATCH v2 net-next 4/6] net: phy: mdio-bcm-unimac: Add asp v2.0 support

2023-04-26 Thread Justin Chen
Add mdio compat string for ASP 2.0 ethernet driver.

Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
Reviewed-by: Andrew Lunn 
---
 drivers/net/mdio/mdio-bcm-unimac.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/mdio/mdio-bcm-unimac.c 
b/drivers/net/mdio/mdio-bcm-unimac.c
index bfc9be23c973..6b26a0803696 100644
--- a/drivers/net/mdio/mdio-bcm-unimac.c
+++ b/drivers/net/mdio/mdio-bcm-unimac.c
@@ -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", },
-- 
2.7.4



[PATCH v2 net-next 5/6] net: phy: bcm7xxx: Add EPHY entry for 74165

2023-04-26 Thread Justin Chen
From: Florian Fainelli 

74165 is a 16nm process SoC with a 10/100 integrated Ethernet PHY,
utilize the recently defined 16nm EPHY macro to configure that PHY.

Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
Reviewed-by: Andrew Lunn 
---
 drivers/net/phy/bcm7xxx.c | 1 +
 include/linux/brcmphy.h   | 1 +
 2 files changed, 2 insertions(+)

diff --git a/drivers/net/phy/bcm7xxx.c b/drivers/net/phy/bcm7xxx.c
index 06be71ecd2f8..5c03c379cb5e 100644
--- a/drivers/net/phy/bcm7xxx.c
+++ b/drivers/net/phy/bcm7xxx.c
@@ -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)"),
diff --git a/include/linux/brcmphy.h b/include/linux/brcmphy.h
index 9e77165f3ef6..e11c2e9a5398 100644
--- a/include/linux/brcmphy.h
+++ b/include/linux/brcmphy.h
@@ -44,6 +44,7 @@
 #define PHY_ID_BCM7366 0x600d8490
 #define PHY_ID_BCM7346 0x600d8650
 #define PHY_ID_BCM7362 0x600d84b0
+#define PHY_ID_BCM741650x359052c0
 #define PHY_ID_BCM7425 0x600d86b0
 #define PHY_ID_BCM7429 0x600d8730
 #define PHY_ID_BCM7435 0x600d8750
-- 
2.7.4



[PATCH v2 net-next 2/6] dt-bindings: net: Brcm ASP 2.0 Ethernet controller

2023-04-26 Thread Justin Chen
From: Florian Fainelli 

Add a binding document for the Broadcom ASP 2.0 Ethernet
controller.

Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
---
 .../devicetree/bindings/net/brcm,asp-v2.0.yaml | 145 +
 1 file changed, 145 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml

diff --git a/Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml 
b/Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml
new file mode 100644
index ..818d91692e6e
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml
@@ -0,0 +1,145 @@
+# 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 
+  - Florian Fainelli 
+
+description: Broadcom Ethernet controller first introduced with 72165
+
+properties:
+  '#address-cells':
+const: 1
+  '#size-cells':
+const: 1
+
+  compatible:
+enum:
+  - brcm,asp-v2.0
+  - brcm,bcm72165-asp-v2.0
+  - brcm,asp-v2.1
+  - brcm,bcm74165-asp-v2.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#
+
+properties:
+  reg:
+maxItems: 1
+description: Port number
+
+  channel:
+maxItems: 1
+description: ASP channel number
+
+required:
+  - reg
+  - 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 
+#include 
+
+ethernet@9c0 {
+compatible = "brcm,asp-v2.0";
+reg = <0x9c0 0x1fff14>;
+interrupts = ;
+ranges;
+clocks = < 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>;
+channel = <8>;
+phy-mode = "rgmii";
+phy-handle = <>;
+};
+
+port@1 {
+reg = <1>;
+channel = <9>;
+phy-mode = "rgmii";
+phy-handle = <>;
+};
+};
+};
-- 
2.7.4



[PATCH v2 net-next 1/6] dt-bindings: net: brcm, unimac-mdio: Add asp-v2.0

2023-04-26 Thread Justin Chen
The ASP 2.0 Ethernet controller uses a brcm unimac.

Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
---
 Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml 
b/Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml
index 0be426ee1e44..6684810fcbf0 100644
--- a/Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml
+++ b/Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml
@@ -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:
-- 
2.7.4



[PATCH v2 net-next 0/6] Brcm ASP 2.0 Ethernet controller

2023-04-26 Thread Justin Chen
v2
- Updates to yaml dt documentation
- Replace a couple functions with helper functions
- Minor formatting fixes
- Fix a few WoL issues

Add support for the Broadcom ASP 2.0 Ethernet controller which is first
introduced with 72165.

Add support for 74165 10/100 integrated Ethernet PHY which also uses
the ASP 2.0 Ethernet controller.

Florian Fainelli (2):
  dt-bindings: net: Brcm ASP 2.0 Ethernet controller
  net: phy: bcm7xxx: Add EPHY entry for 74165

Justin Chen (4):
  dt-bindings: net: brcm,unimac-mdio: Add asp-v2.0
  net: bcmasp: Add support for ASP2.0 Ethernet controller
  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 |  145 ++
 .../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| 1476 
 drivers/net/ethernet/broadcom/asp2/bcmasp.h|  636 +
 .../net/ethernet/broadcom/asp2/bcmasp_ethtool.c|  585 
 drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c   | 1435 +++
 .../net/ethernet/broadcom/asp2/bcmasp_intf_defs.h  |  238 
 drivers/net/mdio/mdio-bcm-unimac.c |2 +
 drivers/net/phy/bcm7xxx.c  |1 +
 include/linux/brcmphy.h|1 +
 14 files changed, 4544 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

-- 
2.7.4



Re: [PATCH net-next 3/6] net: bcmasp: Add support for ASP2.0 Ethernet controller

2023-04-24 Thread Justin Chen
On Wed, Apr 19, 2023 at 9:33 AM Florian Fainelli  wrote:
>
> On 4/18/23 23:35, Heiner Kallweit wrote:
> > On 19.04.2023 02:10, Justin Chen wrote:
> >> Add 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.
> >>
> >> This patch supports:
> [snip]
> >> +intf->tx_spb_index = spb_index;
> >> +intf->tx_spb_dma_valid = valid;
> >> +bcmasp_intf_tx_write(intf, intf->tx_spb_dma_valid);
> >> +
> >> +if (tx_spb_ring_full(intf, MAX_SKB_FRAGS + 1))
> >> +netif_stop_queue(dev);
> >> +
> >
> > Here it may be better to use the new macros from 
> > include/net/netdev_queues.h.
> > It seems your code (together with the related part in tx_poll) doesn't 
> > consider
> > the queue restart case.
> > In addition you should check whether using READ_ONCE()/WRITE_ONCE() is 
> > needed,
> > e.g. in ring_full().
>
> Thanks Heiner. Can you trim the parts you are not quoting otherwise one
> has to scroll all the way down to where you responded. Thanks!
> --
> Florian
>

Hello Heiner,

The implementation is a locked single queue xmit. Not sure how
netdev_queues.h fits into the picture here. I believe I am handling
the queue restart here.
+static int bcmasp_tx_poll(struct napi_struct *napi, int budget)
+{
[snip]
+ if (released)
+ netif_wake_queue(intf->ndev);
+
+ return 0;
+}
Let me know if I am misunderstanding the feedback here.

Thanks,
Justin


Re: [PATCH net-next 1/6] dt-bindings: net: Brcm ASP 2.0 Ethernet controller

2023-04-24 Thread Justin Chen
On Fri, Apr 21, 2023 at 12:29 AM Krzysztof Kozlowski
 wrote:
>
> On 19/04/2023 02:10, Justin Chen wrote:
> > From: Florian Fainelli 
> >
> > Add a binding document for the Broadcom ASP 2.0 Ethernet
> > controller.
> >
> > Signed-off-by: Florian Fainelli 
> > Signed-off-by: Justin Chen 
> > ---
> >  .../devicetree/bindings/net/brcm,asp-v2.0.yaml | 146 
> > +
> >  1 file changed, 146 insertions(+)
> >  create mode 100644 Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml
> >
> > diff --git a/Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml 
> > b/Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml
> > new file mode 100644
> > index ..3817d722244f
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml
> > @@ -0,0 +1,146 @@
> > +# 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#;
>
> Drop quotes.
>
> > +
> > +title: Broadcom ASP 2.0 Ethernet controller
> > +
> > +maintainers:
> > +  - Justin Chen 
> > +  - Florian Fainelli 
> > +
> > +description: Broadcom Ethernet controller first introduced with 72165
> > +
> > +properties:
> > +  '#address-cells':
> > +const: 1
> > +  '#size-cells':
> > +const: 1
> > +
> > +  compatible:
> > +enum:
> > +  - brcm,bcm72165-asp-v2.0
> > +  - brcm,asp-v2.0
> > +  - brcm,asp-v2.1
>
> Is this part of SoC? If so, then SoC compatibles are preferred, not IP
> block versions.
We have the same IP on different chips. So no, it isn't tied to a specific SoC.

>
> > +
> > +  reg:
> > +maxItems: 1
> > +description: ASP registers
>
> Drop description.
>
> > +
> > +  ranges: true
> > +
> > +  interrupts:
> > +minItems: 1
> > +items:
> > +  - description: RX/TX interrupt
> > +  - description: Port 0 Wake-on-LAN
> > +  - description: Port 1 Wake-on-LAN
> > +
> > +  clocks:
> > +$ref: /schemas/types.yaml#/definitions/phandle-array
>
> Drop.
>
> > +description: Phandle to clock controller
>
> Drop.
>
> Instead maxItems.
>
> > +
> > +  clock-names:
> > +const: sw_asp
>
> Drop entire property.
>
> > +
> > +  ethernet-ports:
> > +type: object
> > +properties:
> > +  '#address-cells':
> > +const: 1
> > +  '#size-cells':
> > +const: 0
>
> Missing additionalProperties:false. Look at existing bindings how it is
> done.
>
> > +
> > +patternProperties:
> > +  "^port@[0-9]+$":
> > +type: object
> > +
> > +$ref: ethernet-controller.yaml#
> > +
> > +properties:
> > +  reg:
> > +maxItems: 1
> > +description: Port number
> > +
> > +  channel:
> > +maxItems: 1
> > +description: ASP channel number
> > +
> > +required:
> > +  - reg
> > +  - channel
> > +
> > +patternProperties:
> > +  "^mdio@[0-9a-f]+$":
> > +type: object
> > +$ref: "brcm,unimac-mdio.yaml"
> > +
> > +description:
> > +  ASP internal UniMAC MDIO bus
> > +
> > +required:
> > +  - compatible
> > +  - reg
> > +  - interrupts
> > +  - clocks
> > +  - clock-names
> > +  - ranges
> > +
> > +additionalProperties: false
> > +
> > +examples:
> > +  - |
> > +asp@9c0 {
>
> Node names should be generic.
> https://devicetree-specification.readthedocs.io/en/latest/chapter2-devicetree-basics.html#generic-names-recommendation
>
> > +compatible = "brcm,asp-v2.0";
> > +reg = <0x9c0 0x1fff14>;
> > +interrupts = <0x0 0x33 0x4>;
>
> Use proper defines for flags.
Not understanding this comment. Can you elaborate?

Thanks,
Justin
>
> > +ranges;
> > +clocks = < 14>;
> > +clock-names = "sw_asp";
> > +#address-cells = <1>;
> > +#size-cells = <1>;
>
>
> Best regards,
> Krzysztof
>


Re: [PATCH net-next 0/6] Brcm ASP 2.0 Ethernet controller

2023-04-18 Thread Justin Chen
On Tue, Apr 18, 2023 at 5:10 PM Justin Chen  wrote:
>
> From: Justin Chen 
Woops, looks like I screwed up on some of my email addresses in the
patch set. Will fix in v2 after first round of reviews.

Justin
>
> Add support for the Broadcom ASP 2.0 Ethernet controller which is first
> introduced with 72165.
>
> Add support for 74165 10/100 integrated Ethernet PHY which also uses
> the ASP 2.0 Ethernet controller.
>
> Florian Fainelli (2):
>   dt-bindings: net: Brcm ASP 2.0 Ethernet controller
>   net: phy: bcm7xxx: Add EPHY entry for 74165
>
> Justin Chen (4):
>   dt-bindings: net: brcm,unimac-mdio: Add asp-v2.0
>   net: bcmasp: Add support for ASP2.0 Ethernet controller
>   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 |  146 ++
>  .../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| 1527 
> 
>  drivers/net/ethernet/broadcom/asp2/bcmasp.h|  636 
>  .../net/ethernet/broadcom/asp2/bcmasp_ethtool.c|  620 
>  drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c   | 1425 ++
>  .../net/ethernet/broadcom/asp2/bcmasp_intf_defs.h  |  238 +++
>  drivers/net/mdio/mdio-bcm-unimac.c |2 +
>  drivers/net/phy/bcm7xxx.c  |1 +
>  include/linux/brcmphy.h|1 +
>  14 files changed, 4621 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
>
> --
> 2.7.4
>


[PATCH net-next 5/6] net: phy: bcm7xxx: Add EPHY entry for 74165

2023-04-18 Thread Justin Chen
From: Florian Fainelli 

74165 is a 16nm process SoC with a 10/100 integrated Ethernet PHY,
utilize the recently defined 16nm EPHY macro to configure that PHY.

Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
---
 drivers/net/phy/bcm7xxx.c | 1 +
 include/linux/brcmphy.h   | 1 +
 2 files changed, 2 insertions(+)

diff --git a/drivers/net/phy/bcm7xxx.c b/drivers/net/phy/bcm7xxx.c
index 06be71ecd2f8..5c03c379cb5e 100644
--- a/drivers/net/phy/bcm7xxx.c
+++ b/drivers/net/phy/bcm7xxx.c
@@ -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)"),
diff --git a/include/linux/brcmphy.h b/include/linux/brcmphy.h
index 9e77165f3ef6..e11c2e9a5398 100644
--- a/include/linux/brcmphy.h
+++ b/include/linux/brcmphy.h
@@ -44,6 +44,7 @@
 #define PHY_ID_BCM7366 0x600d8490
 #define PHY_ID_BCM7346 0x600d8650
 #define PHY_ID_BCM7362 0x600d84b0
+#define PHY_ID_BCM741650x359052c0
 #define PHY_ID_BCM7425 0x600d86b0
 #define PHY_ID_BCM7429 0x600d8730
 #define PHY_ID_BCM7435 0x600d8750
-- 
2.7.4



[PATCH net-next 3/6] net: bcmasp: Add support for ASP2.0 Ethernet controller

2023-04-18 Thread Justin Chen
Add 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.

This patch supports:

- Wake-on-LAN using magic packets
- basic ethtool operations (link, counters, message level)
- MAC destination address filtering (promiscuous, ALL_MULTI, etc.)

Signed-off-by: Justin Chen 
Signed-off-by: Florian Fainelli 
---
 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| 1527 
 drivers/net/ethernet/broadcom/asp2/bcmasp.h|  636 
 .../net/ethernet/broadcom/asp2/bcmasp_ethtool.c|  620 
 drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c   | 1425 ++
 .../net/ethernet/broadcom/asp2/bcmasp_intf_defs.h  |  238 +++
 8 files changed, 4460 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

diff --git a/drivers/net/ethernet/broadcom/Kconfig 
b/drivers/net/ethernet/broadcom/Kconfig
index 948586bf1b5b..d4166141145d 100644
--- a/drivers/net/ethernet/broadcom/Kconfig
+++ b/drivers/net/ethernet/broadcom/Kconfig
@@ -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
diff --git a/drivers/net/ethernet/broadcom/Makefile 
b/drivers/net/ethernet/broadcom/Makefile
index 0ddfb5b5d53c..bac5cb6ad0cd 100644
--- a/drivers/net/ethernet/broadcom/Makefile
+++ b/drivers/net/ethernet/broadcom/Makefile
@@ -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/
diff --git a/drivers/net/ethernet/broadcom/asp2/Makefile 
b/drivers/net/ethernet/broadcom/asp2/Makefile
new file mode 100644
index ..e07550315f83
--- /dev/null
+++ b/drivers/net/ethernet/broadcom/asp2/Makefile
@@ -0,0 +1,2 @@
+obj-$(CONFIG_BCMASP) += bcm-asp.o
+bcm-asp-objs := bcmasp.o bcmasp_intf.o bcmasp_ethtool.o
diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp.c 
b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
new file mode 100644
index ..9cf5f4d6dd0d
--- /dev/null
+++ b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
@@ -0,0 +1,1527 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Broadcom STB ASP 2.0 Driver
+ *
+ * Copyright (c) 2020 Broadcom
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "bcmasp.h"
+#include "bcmasp_intf_defs.h"
+
+static inline void _intr2_mask_clear(struct bcmasp_priv *priv, u32 mask)
+{
+   intr2_core_wl(priv, mask, ASP_INTR2_MASK_CLEAR);
+   priv->irq_mask &= ~mask;
+}
+
+static inline void _intr2_mask_set(struct bcmasp_priv *priv, u32 mask)
+{
+   intr2_core_wl(priv, mask, ASP_INTR2_MASK_SET);
+   priv->irq_mask |= mask;
+}
+
+void bcmasp_enable_tx_irq(struct bcmasp_intf *intf, int en)
+{
+   struct bcmasp_priv *priv = intf->parent;
+
+   if (en)
+   _intr2_mask_clear(priv, ASP_INTR2_TX_DESC(intf->channel));
+   else
+   _intr2_mask_set(priv, ASP_INTR2_TX_DESC(intf->channel));
+}
+EXPORT_SYMBOL_GPL(bcmasp_enable_tx_irq);
+
+void bcmasp_enable_rx_irq(struct bcmasp_intf *intf, int en)
+{
+   struct bcmasp_priv *priv = intf->parent;
+
+   if (en)
+   _intr2_mask_clear(priv, ASP_INTR2_RX_ECH(intf->channel));
+   else
+   _intr2_mask_set(priv, ASP_INTR2_RX_ECH(intf->channel));
+}
+EXPORT_SYMBOL_GPL(bcmasp_enable_rx_irq);
+
+static void bcmasp_intr2_mask_set_all(struct bcmasp_priv *priv)
+{
+   _intr2_mask_set(priv, 0x);
+   priv->irq_mask = 0x;
+}
+
+static void bcmasp_intr2_clear_all(struct bcmasp_priv *priv)
+{
+   intr2_core_wl(priv, 0x, ASP_INTR2_CLEAR);
+}
+
+static inline void bcmasp_intr2_handling(struct bcmasp_intf *intf, u32 status)
+{
+   if (unlikely(!intf))
+   

[PATCH net-next 6/6] MAINTAINERS: ASP 2.0 Ethernet driver maintainers

2023-04-18 Thread Justin Chen
Add maintainers entry for ASP 2.0 Ethernet driver.

Signed-off-by: Justin Chen 
Signed-off-by: Florian Fainelli 
---
 MAINTAINERS | 9 +
 1 file changed, 9 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 4fc57dfd5fd0..24cbe1c0fc06 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4189,6 +4189,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 
+M: Florian Fainelli 
+L: bcm-kernel-feedback-l...@broadcom.com
+L: net...@vger.kernel.org
+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 
 M: Scott Branden 
-- 
2.7.4



[PATCH net-next 4/6] net: phy: mdio-bcm-unimac: Add asp v2.0 support

2023-04-18 Thread Justin Chen
Add mdio compat string for ASP 2.0 ethernet driver.

Signed-off-by: Justin Chen 
Signed-off-by: Florian Fainelli 
---
 drivers/net/mdio/mdio-bcm-unimac.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/mdio/mdio-bcm-unimac.c 
b/drivers/net/mdio/mdio-bcm-unimac.c
index bfc9be23c973..6b26a0803696 100644
--- a/drivers/net/mdio/mdio-bcm-unimac.c
+++ b/drivers/net/mdio/mdio-bcm-unimac.c
@@ -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", },
-- 
2.7.4



[PATCH net-next 2/6] dt-bindings: net: brcm, unimac-mdio: Add asp-v2.0

2023-04-18 Thread Justin Chen
From: Justin Chen 

The ASP 2.0 Ethernet controller uses a brcm unimac.

Signed-off-by: Justin Chen 
Signed-off-by: Florian Fainelli 
---
 Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml 
b/Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml
index 0be426ee1e44..6684810fcbf0 100644
--- a/Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml
+++ b/Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml
@@ -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:
-- 
2.7.4



[PATCH net-next 1/6] dt-bindings: net: Brcm ASP 2.0 Ethernet controller

2023-04-18 Thread Justin Chen
From: Florian Fainelli 

Add a binding document for the Broadcom ASP 2.0 Ethernet
controller.

Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
---
 .../devicetree/bindings/net/brcm,asp-v2.0.yaml | 146 +
 1 file changed, 146 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml

diff --git a/Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml 
b/Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml
new file mode 100644
index ..3817d722244f
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml
@@ -0,0 +1,146 @@
+# 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 
+  - Florian Fainelli 
+
+description: Broadcom Ethernet controller first introduced with 72165
+
+properties:
+  '#address-cells':
+const: 1
+  '#size-cells':
+const: 1
+
+  compatible:
+enum:
+  - brcm,bcm72165-asp-v2.0
+  - brcm,asp-v2.0
+  - brcm,asp-v2.1
+
+  reg:
+maxItems: 1
+description: ASP registers
+
+  ranges: true
+
+  interrupts:
+minItems: 1
+items:
+  - description: RX/TX interrupt
+  - description: Port 0 Wake-on-LAN
+  - description: Port 1 Wake-on-LAN
+
+  clocks:
+$ref: /schemas/types.yaml#/definitions/phandle-array
+description: Phandle to clock controller
+
+  clock-names:
+const: sw_asp
+
+  ethernet-ports:
+type: object
+properties:
+  '#address-cells':
+const: 1
+  '#size-cells':
+const: 0
+
+patternProperties:
+  "^port@[0-9]+$":
+type: object
+
+$ref: ethernet-controller.yaml#
+
+properties:
+  reg:
+maxItems: 1
+description: Port number
+
+  channel:
+maxItems: 1
+description: ASP channel number
+
+required:
+  - reg
+  - channel
+
+patternProperties:
+  "^mdio@[0-9a-f]+$":
+type: object
+$ref: "brcm,unimac-mdio.yaml"
+
+description:
+  ASP internal UniMAC MDIO bus
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+  - clock-names
+  - ranges
+
+additionalProperties: false
+
+examples:
+  - |
+asp@9c0 {
+compatible = "brcm,asp-v2.0";
+reg = <0x9c0 0x1fff14>;
+interrupts = <0x0 0x33 0x4>;
+ranges;
+clocks = < 14>;
+clock-names = "sw_asp";
+#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>;
+channel = <8>;
+phy-mode = "rgmii";
+phy-handle = <>;
+};
+
+port@1 {
+reg = <1>;
+channel = <9>;
+phy-mode = "rgmii";
+phy-handle = <>;
+};
+};
+};
-- 
2.7.4



[PATCH net-next 0/6] Brcm ASP 2.0 Ethernet controller

2023-04-18 Thread Justin Chen
From: Justin Chen 

Add support for the Broadcom ASP 2.0 Ethernet controller which is first
introduced with 72165.

Add support for 74165 10/100 integrated Ethernet PHY which also uses
the ASP 2.0 Ethernet controller.

Florian Fainelli (2):
  dt-bindings: net: Brcm ASP 2.0 Ethernet controller
  net: phy: bcm7xxx: Add EPHY entry for 74165

Justin Chen (4):
  dt-bindings: net: brcm,unimac-mdio: Add asp-v2.0
  net: bcmasp: Add support for ASP2.0 Ethernet controller
  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 |  146 ++
 .../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| 1527 
 drivers/net/ethernet/broadcom/asp2/bcmasp.h|  636 
 .../net/ethernet/broadcom/asp2/bcmasp_ethtool.c|  620 
 drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c   | 1425 ++
 .../net/ethernet/broadcom/asp2/bcmasp_intf_defs.h  |  238 +++
 drivers/net/mdio/mdio-bcm-unimac.c |2 +
 drivers/net/phy/bcm7xxx.c  |1 +
 include/linux/brcmphy.h|1 +
 14 files changed, 4621 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

-- 
2.7.4



Re: [PATCH net-next 3/5] net: bcmasp: Add support for ASP2.0 Ethernet controller

2021-09-30 Thread Justin Chen
On Sun, Sep 26, 2021 at 6:58 AM Andrew Lunn  wrote:
>
> > > > +static int bcmasp_set_priv_flags(struct net_device *dev, u32 flags)
> > > > +{
> > > > + struct bcmasp_intf *intf = netdev_priv(dev);
> > > > +
> > > > + intf->wol_keep_rx_en = flags & BCMASP_WOL_KEEP_RX_EN ? 1 : 0;
> > > > +
> > > > + return 0;
> > >
> > > Please could you explain this some more. How can you disable RX and
> > > still have WoL working?
> >
> > Wake-on-LAN using Magic Packets and network filters requires keeping the
> > UniMAC's receiver turned on, and then the packets feed into the Magic Packet
> > Detector (MPD) block or the network filter block. In that mode DRAM is in
> > self refresh and there is local matching of frames into a tiny FIFO however
> > in the case of magic packets the packets leading to a wake-up are dropped as
> > there is nowhere to store them. In the case of a network filter match (e.g.:
> > matching a multicast IP address plus protocol, plus source/destination
> > ports) the packets are also discarded because the receive DMA was shut down.
> >
> > When the wol_keep_rx_en flag is set, the above happens but we also allow the
> > packets that did match a network filter to reach the small FIFO (Justin
> > would know how many entries are there) that is used to push the packets to
> > DRAM. The packet contents are held in there until the system wakes up which
> > is usually just a few hundreds of micro seconds after we received a packet
> > that triggered a wake-up. Once we overflow the receive DMA FIFO capacity
> > subsequent packets get dropped which is fine since we are usually talking
> > about very low bit rates, and we only try to push to DRAM the packets of
> > interest, that is those for which we have a network filter.
> >
> > This is convenient in scenarios where you want to wake-up from multicast DNS
> > (e.g.: wake on Googlecast, Bonjour etc.) because then the packet that
> > resulted in the system wake-up is not discarded but is then delivered to the
> > network stack.
>
> Thanks for the explanation. It would be easier for the user if you
> automate this. Enable is by default for WoL types which have user
> content?
>
Yup that can work. We can enable it for WAKE_FILTER type wol and leave
it disabled otherwise.

> > > > + /* Per ch */
> > > > + intf->tx_spb_dma = priv->base + TX_SPB_DMA_OFFSET(intf);
> > > > + intf->res.tx_spb_ctrl = priv->base + TX_SPB_CTRL_OFFSET(intf);
> > > > + /*
> > > > +  * Stop gap solution. This should be removed when 72165a0 is
> > > > +  * deprecated
> > > > +  */
> > >
> > > Is that an internal commit?
> >
> > Yes this is a revision of the silicon that is not meant to see the light of
> > day.
>
> So this can all be removed?
>
Yup. That can be removed

>Andrew

Thanks for the review.

Justin


[PATCH net-next 1/5] dt-bindings: net: Brcm ASP 2.0 Ethernet controller

2021-09-25 Thread Justin Chen
From: Florian Fainelli 

Add a binding document for the Broadcom ASP 2.0 Ethernet controller.

Signed-off-by: Florian Fainelli 
Signed-off-by: Justin Chen 
---
 .../devicetree/bindings/net/brcm,asp-v2.0.yaml | 147 +
 1 file changed, 147 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml

diff --git a/Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml 
b/Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml
new file mode 100644
index 000..bab31d9
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml
@@ -0,0 +1,147 @@
+# SPDX-License-Identifier: GPL-2.0
+%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 
+  - Florian Fainelli 
+
+description: Broadcom Ethernet controller first introduced with 72165
+
+properties:
+  '#address-cells':
+const: 1
+  '#size-cells':
+const: 1
+
+  compatible:
+enum:
+  - brcm,bcm72165-asp-v2.0
+  - brcm,asp-v2.0
+
+  reg:
+maxItems: 1
+description: ASP registers
+
+  ranges: true
+
+  interrupts:
+minItems: 1
+maxItems: 3
+items:
+  - description: RX/TX interrupt
+  - description: Port 0 Wake-on-LAN
+  - description: Port 1 Wake-on-LAN
+
+  clocks:
+$ref: /schemas/types.yaml#/definitions/phandle-array
+description: Phandle to clock controller
+
+  clock-names:
+const: sw_asp
+
+  brcm,reserved-net-filters-mask:
+$ref: /schemas/types.yaml#/definitions/uint32
+description: bitmap of reserved network filters that the driver will not 
use.
+
+  mdio:
+type: object
+$ref: brcm,unimac-mdio.yaml#
+
+  ethernet-ports:
+type: object
+properties:
+  '#address-cells':
+const: 1
+  '#size-cells':
+const: 0
+
+patternProperties:
+  "^port@[0-9]+$":
+type: object
+
+$ref: ethernet-controller.yaml#
+
+properties:
+  reg:
+maxItems: 1
+description: Port number
+
+  channel:
+maxItems: 1
+description: ASP channel number
+
+required:
+ - reg
+ - channel
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+  - clock-names
+  - ranges
+
+additionalProperties: false
+
+examples:
+  - |
+asp@9c0 {
+compatible = "brcm,asp-v2.0";
+reg = <0x9c0 0x1fff14>;
+interrupts = <0x0 0x33 0x4>;
+ranges;
+clocks = < 14>;
+clock-names = "sw_asp";
+brcm,reserved-net-filters-mask = <0xff>;
+#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>;
+channel = <8>;
+phy-mode = "rgmii";
+phy-handle = <>;
+};
+
+port@1 {
+reg = <1>;
+channel = <9>;
+phy-mode = "rgmii";
+phy-handle = <>;
+};
+};
+};
-- 
2.7.4



[PATCH net-next 5/5] MAINTAINERS: ASP 2.0 Ethernet driver maintainers

2021-09-25 Thread Justin Chen
Signed-off-by: Justin Chen 
Signed-off-by: Florian Fainelli 
---
 MAINTAINERS | 9 +
 1 file changed, 9 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 7f46153..3ba3ca8 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -3762,6 +3762,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 
+M: Florian Fainelli 
+L: bcm-kernel-feedback-l...@broadcom.com
+L: net...@vger.kernel.org
+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 
 M: Scott Branden 
-- 
2.7.4



Re: [PATCH net-next 3/5] net: bcmasp: Add support for ASP2.0 Ethernet controller

2021-09-25 Thread Justin Chen
On Fri, Sep 24, 2021 at 5:05 PM Jakub Kicinski  wrote:
>
> On Fri, 24 Sep 2021 14:44:49 -0700 Justin Chen wrote:
> > Add 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.
> >
> > This patch supports:
> >
> > - Wake-on-LAN using magic packets
> > - basic ethtool operations (link, counters, message level)
> > - MAC destination address filtering (promiscuous, ALL_MULTI, etc.)
> >
> > Signed-off-by: Justin Chen 
> > Signed-off-by: Florian Fainelli 
>
> Please clean up checkpatch --strict and make W=1 C=1 build
> of the new driver.

Apologies, Will fix checkpatch errors in v2


[PATCH net-next 2/5] dt-bindings: net: brcm, unimac-mdio: Add asp-v2.0

2021-09-25 Thread Justin Chen
The ASP 2.0 Ethernet controller uses a brcm unimac.

Signed-off-by: Justin Chen 
Signed-off-by: Florian Fainelli 
---
 Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml 
b/Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml
index f4f4c37..02e1890 100644
--- a/Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml
+++ b/Documentation/devicetree/bindings/net/brcm,unimac-mdio.yaml
@@ -20,6 +20,7 @@ properties:
   - brcm,genet-mdio-v3
   - brcm,genet-mdio-v4
   - brcm,genet-mdio-v5
+  - brcm,asp-v2.0-mdio
   - brcm,unimac-mdio
 
   reg:
-- 
2.7.4



[PATCH net-next 4/5] net: phy: mdio-bcm-unimac: Add asp v2.0 support

2021-09-25 Thread Justin Chen
Signed-off-by: Justin Chen 
Signed-off-by: Florian Fainelli 
---
 drivers/net/mdio/mdio-bcm-unimac.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/mdio/mdio-bcm-unimac.c 
b/drivers/net/mdio/mdio-bcm-unimac.c
index bfc9be2..14202a1 100644
--- a/drivers/net/mdio/mdio-bcm-unimac.c
+++ b/drivers/net/mdio/mdio-bcm-unimac.c
@@ -334,6 +334,7 @@ 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.0-mdio", },
{ .compatible = "brcm,genet-mdio-v5", },
{ .compatible = "brcm,genet-mdio-v4", },
{ .compatible = "brcm,genet-mdio-v3", },
-- 
2.7.4



[PATCH net-next 3/5] net: bcmasp: Add support for ASP2.0 Ethernet controller

2021-09-25 Thread Justin Chen
Add 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.

This patch supports:

- Wake-on-LAN using magic packets
- basic ethtool operations (link, counters, message level)
- MAC destination address filtering (promiscuous, ALL_MULTI, etc.)

Signed-off-by: Justin Chen 
Signed-off-by: Florian Fainelli 
---
 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| 1351 +++
 drivers/net/ethernet/broadcom/asp2/bcmasp.h|  565 
 .../net/ethernet/broadcom/asp2/bcmasp_ethtool.c|  628 +
 drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c   | 1414 
 .../net/ethernet/broadcom/asp2/bcmasp_intf_defs.h  |  187 +++
 8 files changed, 4159 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

diff --git a/drivers/net/ethernet/broadcom/Kconfig 
b/drivers/net/ethernet/broadcom/Kconfig
index 56e0fb0..244b389 100644
--- a/drivers/net/ethernet/broadcom/Kconfig
+++ b/drivers/net/ethernet/broadcom/Kconfig
@@ -253,4 +253,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
diff --git a/drivers/net/ethernet/broadcom/Makefile 
b/drivers/net/ethernet/broadcom/Makefile
index 0ddfb5b..bac5cb6 100644
--- a/drivers/net/ethernet/broadcom/Makefile
+++ b/drivers/net/ethernet/broadcom/Makefile
@@ -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/
diff --git a/drivers/net/ethernet/broadcom/asp2/Makefile 
b/drivers/net/ethernet/broadcom/asp2/Makefile
new file mode 100644
index 000..e075503
--- /dev/null
+++ b/drivers/net/ethernet/broadcom/asp2/Makefile
@@ -0,0 +1,2 @@
+obj-$(CONFIG_BCMASP) += bcm-asp.o
+bcm-asp-objs := bcmasp.o bcmasp_intf.o bcmasp_ethtool.o
diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp.c 
b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
new file mode 100644
index 000..72effa8
--- /dev/null
+++ b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
@@ -0,0 +1,1351 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Broadcom STB ASP 2.0 Driver
+ *
+ * Copyright (c) 2020 Broadcom
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "bcmasp.h"
+
+static const struct of_device_id bcmasp_of_match[] = {
+   { .compatible = "brcm,asp-v2.0", },
+   { /* sentinel */ },
+};
+MODULE_DEVICE_TABLE(of, bcmasp_of_match);
+
+static const struct of_device_id bcmasp_mdio_of_match[] = {
+   { .compatible = "brcm,asp-v2.0-mdio", },
+   { /* sentinel */ },
+};
+MODULE_DEVICE_TABLE(of, bcmasp_of_match);
+
+static inline void _intr2_mask_clear(struct bcmasp_priv *priv, u32 mask)
+{
+   priv->irq_mask &= ~mask;
+   intr2_core_wl(priv, mask, ASP_INTR2_MASK_CLEAR);
+}
+
+static inline void _intr2_mask_set(struct bcmasp_priv *priv, u32 mask)
+{
+   intr2_core_wl(priv, mask, ASP_INTR2_MASK_SET);
+   priv->irq_mask |= mask;
+}
+
+void bcmasp_enable_tx_irq(struct bcmasp_intf *intf, int en)
+{
+   struct bcmasp_priv *priv = intf->parent;
+   int ch = intf->channel;
+
+   if (en)
+   _intr2_mask_clear(priv, ASP_INTR2_TX_DESC(ch));
+   else
+   _intr2_mask_set(priv, ASP_INTR2_TX_DESC(ch));
+}
+
+void bcmasp_enable_rx_irq(struct bcmasp_intf *intf, int en)
+{
+   struct bcmasp_priv *priv = intf->parent;
+   int ch = intf->channel;
+
+   if (en)
+   _intr2_mask_clear(priv, ASP_INTR2_RX_ECH(ch));
+   else
+   _intr2_mask_set(priv, ASP_INTR2_RX_ECH(ch));
+}
+
+static irqreturn_t bcmasp_isr(int irq, void *data)
+{
+   struct bcmasp_priv *priv = data;
+   struct bcmasp_intf *intf;
+   u32 status, i;
+
+   status = intr2_co

[PATCH net-next 0/5] brcm ASP 2.0 Ethernet controller

2021-09-25 Thread Justin Chen
This patch set adds support for Broadcom's ASP 2.0 Ethernet controller.

Florian Fainelli (1):
  dt-bindings: net: Brcm ASP 2.0 Ethernet controller

Justin Chen (4):
  dt-bindings: net: brcm,unimac-mdio: Add asp-v2.0
  net: bcmasp: Add support for ASP2.0 Ethernet controller
  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 |  147 ++
 .../devicetree/bindings/net/brcm,unimac-mdio.yaml  |1 +
 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| 1351 +++
 drivers/net/ethernet/broadcom/asp2/bcmasp.h|  565 
 .../net/ethernet/broadcom/asp2/bcmasp_ethtool.c|  628 +
 drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c   | 1414 
 .../net/ethernet/broadcom/asp2/bcmasp_intf_defs.h  |  187 +++
 drivers/net/mdio/mdio-bcm-unimac.c |1 +
 12 files changed, 4317 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

-- 
2.7.4



  1   2   >