developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 1 | From e3dd6804fa642a733b7a6932d60bb83b6363555c Mon Sep 17 00:00:00 2001 |
| 2 | From: Sam Shih <sam.shih@mediatek.com> |
| 3 | Date: Fri, 2 Jun 2023 13:05:59 +0800 |
| 4 | Subject: [PATCH] |
| 5 | [backport-networking-drivers][999-1701-add-default-setting-to-dsa-unused-port.patch] |
| 6 | |
| 7 | --- |
| 8 | drivers/net/dsa/mt7530.c | 62 ++++++++++++++++++++++++++++++++++++++-- |
| 9 | drivers/net/dsa/mt7530.h | 1 + |
| 10 | 2 files changed, 60 insertions(+), 3 deletions(-) |
| 11 | |
| 12 | diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c |
| 13 | index 8ce3d51e8..008432d5c 100644 |
| 14 | --- a/drivers/net/dsa/mt7530.c |
| 15 | +++ b/drivers/net/dsa/mt7530.c |
| 16 | @@ -1022,6 +1022,9 @@ mt7530_stp_state_set(struct dsa_switch *ds, int port, u8 state) |
developer | d8b297a | 2021-06-28 19:15:10 +0800 | [diff] [blame] | 17 | struct mt7530_priv *priv = ds->priv; |
| 18 | u32 stp_state; |
| 19 | |
| 20 | + if (dsa_is_unused_port(ds, port)) |
| 21 | + return; |
| 22 | + |
| 23 | switch (state) { |
| 24 | case BR_STATE_DISABLED: |
| 25 | stp_state = MT7530_STP_DISABLED; |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 26 | @@ -1674,11 +1677,59 @@ mt7530_setup(struct dsa_switch *ds) |
| 27 | return 0; |
developer | d8b297a | 2021-06-28 19:15:10 +0800 | [diff] [blame] | 28 | } |
| 29 | |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 30 | +static int |
developer | d8b297a | 2021-06-28 19:15:10 +0800 | [diff] [blame] | 31 | +setup_unused_ports(struct dsa_switch *ds, u32 pm) |
| 32 | +{ |
| 33 | + struct mt7530_priv *priv = ds->priv; |
| 34 | + u32 egtag_mask = 0; |
| 35 | + u32 egtag_val = 0; |
| 36 | + int i; |
| 37 | + |
| 38 | + if (!pm) |
| 39 | + return 0; |
| 40 | + |
| 41 | + for (i = 0; i < MT7530_NUM_PORTS; i++) { |
| 42 | + if (!dsa_is_unused_port(ds, i)) |
| 43 | + continue; |
| 44 | + |
| 45 | + /* Setup MAC port with maximum capability. */ |
| 46 | + if ((i == 5) || (i == 6)) |
| 47 | + if (priv->info->cpu_port_config) |
| 48 | + priv->info->cpu_port_config(ds, i); |
| 49 | + |
| 50 | + mt7530_rmw(priv, MT7530_PCR_P(i), PCR_MATRIX_MASK | PCR_PORT_VLAN_MASK, |
| 51 | + PCR_MATRIX(pm) | MT7530_PORT_SECURITY_MODE); |
| 52 | + egtag_mask |= ETAG_CTRL_P_MASK(i); |
| 53 | + egtag_val |= ETAG_CTRL_P(i, MT7530_VLAN_EGRESS_UNTAG); |
| 54 | + } |
| 55 | + |
| 56 | + /* Add unused ports to VLAN2 group for using IVL fdb. */ |
| 57 | + mt7530_write(priv, MT7530_VAWD1, |
| 58 | + IVL_MAC | VTAG_EN | PORT_MEM(pm) | VLAN_VALID); |
| 59 | + mt7530_rmw(priv, MT7530_VAWD2, egtag_mask, egtag_val); |
| 60 | + mt7530_vlan_cmd(priv, MT7530_VTCR_WR_VID, MT753X_RESERVED_VLAN); |
| 61 | + |
| 62 | + for (i = 0; i < MT7530_NUM_PORTS; i++) { |
| 63 | + if (!dsa_is_unused_port(ds, i)) |
| 64 | + continue; |
| 65 | + |
| 66 | + mt7530_rmw(priv, MT7530_PPBV1_P(i), G0_PORT_VID_MASK, |
| 67 | + G0_PORT_VID(MT753X_RESERVED_VLAN)); |
| 68 | + mt7530_rmw(priv, MT7530_SSP_P(i), FID_PST_MASK, MT7530_STP_FORWARDING); |
| 69 | + |
| 70 | + dev_dbg(ds->dev, "Add unused port%d to reserved VLAN%d group\n", |
| 71 | + i, MT753X_RESERVED_VLAN); |
| 72 | + } |
| 73 | + |
| 74 | + return 0; |
| 75 | +} |
| 76 | + |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 77 | static int |
developer | d8b297a | 2021-06-28 19:15:10 +0800 | [diff] [blame] | 78 | mt7531_setup(struct dsa_switch *ds) |
| 79 | { |
| 80 | struct mt7530_priv *priv = ds->priv; |
| 81 | struct mt7530_dummy_poll p; |
| 82 | + u32 unused_pm = 0; |
| 83 | u32 val, id; |
| 84 | int ret, i; |
| 85 | |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 86 | @@ -1766,7 +1817,9 @@ mt7531_setup(struct dsa_switch *ds) |
developer | d8b297a | 2021-06-28 19:15:10 +0800 | [diff] [blame] | 87 | |
| 88 | mt7530_set(priv, MT7531_DBG_CNT(i), MT7531_DIS_CLR); |
| 89 | |
| 90 | - if (dsa_is_cpu_port(ds, i)) |
| 91 | + if (dsa_is_unused_port(ds, i)) |
| 92 | + unused_pm |= BIT(i); |
| 93 | + else if (dsa_is_cpu_port(ds, i)) |
| 94 | mt753x_cpu_port_enable(ds, i); |
| 95 | else |
| 96 | mt7530_port_disable(ds, i); |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 97 | @@ -1776,6 +1829,9 @@ mt7531_setup(struct dsa_switch *ds) |
developer | d8b297a | 2021-06-28 19:15:10 +0800 | [diff] [blame] | 98 | PVC_EG_TAG(MT7530_VLAN_EG_CONSISTENT)); |
| 99 | } |
| 100 | |
| 101 | + /* Group and enable unused ports as a standalone dumb switch. */ |
| 102 | + setup_unused_ports(ds, unused_pm); |
| 103 | + |
| 104 | ds->configure_vlan_while_not_filtering = true; |
| 105 | |
| 106 | /* Flush the FDB table */ |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 107 | @@ -2100,7 +2156,7 @@ mt7531_mac_config(struct dsa_switch *ds, int port, unsigned int mode, |
developer | d8b297a | 2021-06-28 19:15:10 +0800 | [diff] [blame] | 108 | case PHY_INTERFACE_MODE_RGMII_RXID: |
| 109 | case PHY_INTERFACE_MODE_RGMII_TXID: |
| 110 | dp = dsa_to_port(ds, port); |
| 111 | - phydev = dp->slave->phydev; |
| 112 | + phydev = (dp->slave) ? dp->slave->phydev : NULL; |
| 113 | return mt7531_rgmii_setup(priv, port, interface, phydev); |
| 114 | case PHY_INTERFACE_MODE_SGMII: |
| 115 | return mt7531_sgmii_setup_mode_an(priv, port, interface); |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 116 | @@ -2640,7 +2696,7 @@ mt7530_probe(struct mdio_device *mdiodev) |
developer | d8b297a | 2021-06-28 19:15:10 +0800 | [diff] [blame] | 117 | if (!priv) |
| 118 | return -ENOMEM; |
| 119 | |
| 120 | - priv->ds = dsa_switch_alloc(&mdiodev->dev, DSA_MAX_PORTS); |
| 121 | + priv->ds = dsa_switch_alloc(&mdiodev->dev, MT7530_NUM_PORTS); |
| 122 | if (!priv->ds) |
| 123 | return -ENOMEM; |
| 124 | |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 125 | diff --git a/drivers/net/dsa/mt7530.h b/drivers/net/dsa/mt7530.h |
| 126 | index 6424bc90e..aa758b2d2 100644 |
| 127 | --- a/drivers/net/dsa/mt7530.h |
| 128 | +++ b/drivers/net/dsa/mt7530.h |
developer | d8b297a | 2021-06-28 19:15:10 +0800 | [diff] [blame] | 129 | @@ -10,6 +10,7 @@ |
| 130 | #define MT7530_CPU_PORT 6 |
| 131 | #define MT7530_NUM_FDB_RECORDS 2048 |
| 132 | #define MT7530_ALL_MEMBERS 0xff |
| 133 | +#define MT753X_RESERVED_VLAN 2 |
| 134 | |
| 135 | enum mt753x_id { |
| 136 | ID_MT7530 = 0, |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 137 | -- |
| 138 | 2.34.1 |
| 139 | |