hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/net/dsa/b53/b53_common.c
....@@ -17,8 +17,6 @@
1717 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1818 */
1919
20
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
21
-
2220 #include <linux/delay.h>
2321 #include <linux/export.h>
2422 #include <linux/gpio.h>
....@@ -26,6 +24,7 @@
2624 #include <linux/module.h>
2725 #include <linux/platform_data/b53.h>
2826 #include <linux/phy.h>
27
+#include <linux/phylink.h>
2928 #include <linux/etherdevice.h>
3029 #include <linux/if_bridge.h>
3130 #include <net/dsa.h>
....@@ -341,6 +340,13 @@
341340 b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_CTRL, &mgmt);
342341 mgmt |= B53_MII_DUMB_FWDG_EN;
343342 b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_CTRL, mgmt);
343
+
344
+ /* Look at B53_UC_FWD_EN and B53_MC_FWD_EN to decide whether
345
+ * frames should be flooded or not.
346
+ */
347
+ b53_read8(dev, B53_CTRL_PAGE, B53_IP_MULTICAST_CTRL, &mgmt);
348
+ mgmt |= B53_UC_FWD_EN | B53_MC_FWD_EN | B53_IPMC_FWD_EN;
349
+ b53_write8(dev, B53_CTRL_PAGE, B53_IP_MULTICAST_CTRL, mgmt);
344350 }
345351
346352 static void b53_enable_vlan(struct b53_device *dev, bool enable,
....@@ -362,8 +368,6 @@
362368 b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4, &vc4);
363369 b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5, &vc5);
364370 }
365
-
366
- mgmt &= ~SM_SW_FWD_MODE;
367371
368372 if (enable) {
369373 vc0 |= VC0_VLAN_EN | VC0_VID_CHK_EN | VC0_VID_HASH_VID;
....@@ -427,7 +431,6 @@
427431 b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, mgmt);
428432
429433 dev->vlan_enabled = enable;
430
- dev->vlan_filtering_enabled = enable_filtering;
431434 }
432435
433436 static int b53_set_jumbo(struct b53_device *dev, bool enable, bool allow_10_100)
....@@ -523,10 +526,22 @@
523526 int b53_enable_port(struct dsa_switch *ds, int port, struct phy_device *phy)
524527 {
525528 struct b53_device *dev = ds->priv;
526
- unsigned int cpu_port = ds->ports[port].cpu_dp->index;
529
+ unsigned int cpu_port;
530
+ int ret = 0;
527531 u16 pvlan;
528532
533
+ if (!dsa_is_user_port(ds, port))
534
+ return 0;
535
+
536
+ cpu_port = dsa_to_port(ds, port)->cpu_dp->index;
537
+
538
+ b53_br_egress_floods(ds, port, true, true);
529539 b53_port_set_learning(dev, port, false);
540
+
541
+ if (dev->ops->irq_enable)
542
+ ret = dev->ops->irq_enable(dev, port);
543
+ if (ret)
544
+ return ret;
530545
531546 /* Clear the Rx and Tx disable bits and set to no spanning tree */
532547 b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), 0);
....@@ -551,7 +566,7 @@
551566 }
552567 EXPORT_SYMBOL(b53_enable_port);
553568
554
-void b53_disable_port(struct dsa_switch *ds, int port, struct phy_device *phy)
569
+void b53_disable_port(struct dsa_switch *ds, int port)
555570 {
556571 struct b53_device *dev = ds->priv;
557572 u8 reg;
....@@ -560,14 +575,16 @@
560575 b53_read8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), &reg);
561576 reg |= PORT_CTRL_RX_DISABLE | PORT_CTRL_TX_DISABLE;
562577 b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), reg);
578
+
579
+ if (dev->ops->irq_disable)
580
+ dev->ops->irq_disable(dev, port);
563581 }
564582 EXPORT_SYMBOL(b53_disable_port);
565583
566584 void b53_brcm_hdr_setup(struct dsa_switch *ds, int port)
567585 {
568
- bool tag_en = !(ds->ops->get_tag_protocol(ds, port) ==
569
- DSA_TAG_PROTO_NONE);
570586 struct b53_device *dev = ds->priv;
587
+ bool tag_en = !(dev->tag_protocol == DSA_TAG_PROTO_NONE);
571588 u8 hdr_ctl, val;
572589 u16 reg;
573590
....@@ -586,6 +603,22 @@
586603 val = 0;
587604 break;
588605 }
606
+
607
+ /* Enable management mode if tagging is requested */
608
+ b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &hdr_ctl);
609
+ if (tag_en)
610
+ hdr_ctl |= SM_SW_FWD_MODE;
611
+ else
612
+ hdr_ctl &= ~SM_SW_FWD_MODE;
613
+ b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, hdr_ctl);
614
+
615
+ /* Configure the appropriate IMP port */
616
+ b53_read8(dev, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, &hdr_ctl);
617
+ if (port == 8)
618
+ hdr_ctl |= GC_FRM_MGMT_PORT_MII;
619
+ else if (port == 5)
620
+ hdr_ctl |= GC_FRM_MGMT_PORT_M;
621
+ b53_write8(dev, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, hdr_ctl);
589622
590623 /* Enable Broadcom tags for IMP port */
591624 b53_read8(dev, B53_MGMT_PAGE, B53_BRCM_HDR, &hdr_ctl);
....@@ -635,6 +668,8 @@
635668 b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), port_ctrl);
636669
637670 b53_brcm_hdr_setup(dev->ds, port);
671
+
672
+ b53_br_egress_floods(dev->ds, port, true, true);
638673 b53_port_set_learning(dev, port, false);
639674 }
640675
....@@ -659,7 +694,9 @@
659694 {
660695 struct b53_device *dev = ds->priv;
661696 struct b53_vlan vl = { 0 };
697
+ struct b53_vlan *v;
662698 int i, def_vid;
699
+ u16 vid;
663700
664701 def_vid = b53_default_pvid(dev);
665702
....@@ -671,14 +708,24 @@
671708 b53_do_vlan_op(dev, VTA_CMD_CLEAR);
672709 }
673710
674
- b53_enable_vlan(dev, dev->vlan_enabled, dev->vlan_filtering_enabled);
711
+ b53_enable_vlan(dev, dev->vlan_enabled, ds->vlan_filtering);
675712
676713 b53_for_each_port(dev, i)
677714 b53_write16(dev, B53_VLAN_PAGE,
678715 B53_VLAN_PORT_DEF_TAG(i), def_vid);
679716
680
- if (!is5325(dev) && !is5365(dev))
681
- b53_set_jumbo(dev, dev->enable_jumbo, false);
717
+ /* Upon initial call we have not set-up any VLANs, but upon
718
+ * system resume, we need to restore all VLAN entries.
719
+ */
720
+ for (vid = def_vid; vid < dev->num_vlans; vid++) {
721
+ v = &dev->vlans[vid];
722
+
723
+ if (!v->members)
724
+ continue;
725
+
726
+ b53_set_vlan_entry(dev, vid, v);
727
+ b53_fast_age_vlan(dev, vid);
728
+ }
682729
683730 return 0;
684731 }
....@@ -733,8 +780,11 @@
733780 usleep_range(1000, 2000);
734781 } while (timeout-- > 0);
735782
736
- if (timeout == 0)
783
+ if (timeout == 0) {
784
+ dev_err(dev->dev,
785
+ "Timeout waiting for SW_RST to clear!\n");
737786 return -ETIMEDOUT;
787
+ }
738788 }
739789
740790 b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &mgmt);
....@@ -785,10 +835,10 @@
785835 static int b53_reset_switch(struct b53_device *priv)
786836 {
787837 /* reset vlans */
788
- priv->enable_jumbo = false;
789
-
790838 memset(priv->vlans, 0, sizeof(*priv->vlans) * priv->num_vlans);
791839 memset(priv->ports, 0, sizeof(*priv->ports) * priv->num_ports);
840
+
841
+ priv->serdes_lane = B53_INVALID_LANE;
792842
793843 return b53_switch_reset(priv);
794844 }
....@@ -942,6 +992,54 @@
942992 }
943993 EXPORT_SYMBOL(b53_get_sset_count);
944994
995
+enum b53_devlink_resource_id {
996
+ B53_DEVLINK_PARAM_ID_VLAN_TABLE,
997
+};
998
+
999
+static u64 b53_devlink_vlan_table_get(void *priv)
1000
+{
1001
+ struct b53_device *dev = priv;
1002
+ struct b53_vlan *vl;
1003
+ unsigned int i;
1004
+ u64 count = 0;
1005
+
1006
+ for (i = 0; i < dev->num_vlans; i++) {
1007
+ vl = &dev->vlans[i];
1008
+ if (vl->members)
1009
+ count++;
1010
+ }
1011
+
1012
+ return count;
1013
+}
1014
+
1015
+int b53_setup_devlink_resources(struct dsa_switch *ds)
1016
+{
1017
+ struct devlink_resource_size_params size_params;
1018
+ struct b53_device *dev = ds->priv;
1019
+ int err;
1020
+
1021
+ devlink_resource_size_params_init(&size_params, dev->num_vlans,
1022
+ dev->num_vlans,
1023
+ 1, DEVLINK_RESOURCE_UNIT_ENTRY);
1024
+
1025
+ err = dsa_devlink_resource_register(ds, "VLAN", dev->num_vlans,
1026
+ B53_DEVLINK_PARAM_ID_VLAN_TABLE,
1027
+ DEVLINK_RESOURCE_ID_PARENT_TOP,
1028
+ &size_params);
1029
+ if (err)
1030
+ goto out;
1031
+
1032
+ dsa_devlink_resource_occ_get_register(ds,
1033
+ B53_DEVLINK_PARAM_ID_VLAN_TABLE,
1034
+ b53_devlink_vlan_table_get, dev);
1035
+
1036
+ return 0;
1037
+out:
1038
+ dsa_devlink_resources_unregister(ds);
1039
+ return err;
1040
+}
1041
+EXPORT_SYMBOL(b53_setup_devlink_resources);
1042
+
9451043 static int b53_setup(struct dsa_switch *ds)
9461044 {
9471045 struct b53_device *dev = ds->priv;
....@@ -957,52 +1055,77 @@
9571055 b53_reset_mib(dev);
9581056
9591057 ret = b53_apply_config(dev);
960
- if (ret)
1058
+ if (ret) {
9611059 dev_err(ds->dev, "failed to apply configuration\n");
1060
+ return ret;
1061
+ }
9621062
963
- /* Configure IMP/CPU port, disable unused ports. Enabled
1063
+ /* Configure IMP/CPU port, disable all other ports. Enabled
9641064 * ports will be configured with .port_enable
9651065 */
9661066 for (port = 0; port < dev->num_ports; port++) {
9671067 if (dsa_is_cpu_port(ds, port))
9681068 b53_enable_cpu_port(dev, port);
969
- else if (dsa_is_unused_port(ds, port))
970
- b53_disable_port(ds, port, NULL);
1069
+ else
1070
+ b53_disable_port(ds, port);
9711071 }
9721072
973
- return ret;
1073
+ return b53_setup_devlink_resources(ds);
9741074 }
9751075
976
-static void b53_adjust_link(struct dsa_switch *ds, int port,
977
- struct phy_device *phydev)
1076
+static void b53_teardown(struct dsa_switch *ds)
9781077 {
979
- struct b53_device *dev = ds->priv;
980
- struct ethtool_eee *p = &dev->ports[port].eee;
981
- u8 rgmii_ctrl = 0, reg = 0, off;
1078
+ dsa_devlink_resources_unregister(ds);
1079
+}
9821080
983
- if (!phy_is_pseudo_fixed_link(phydev))
984
- return;
1081
+static void b53_force_link(struct b53_device *dev, int port, int link)
1082
+{
1083
+ u8 reg, val, off;
9851084
9861085 /* Override the port settings */
987
- if (port == dev->cpu_port) {
1086
+ if (port == dev->imp_port) {
9881087 off = B53_PORT_OVERRIDE_CTRL;
989
- reg = PORT_OVERRIDE_EN;
1088
+ val = PORT_OVERRIDE_EN;
9901089 } else {
9911090 off = B53_GMII_PORT_OVERRIDE_CTRL(port);
992
- reg = GMII_PO_EN;
1091
+ val = GMII_PO_EN;
9931092 }
9941093
995
- /* Set the link UP */
996
- if (phydev->link)
1094
+ b53_read8(dev, B53_CTRL_PAGE, off, &reg);
1095
+ reg |= val;
1096
+ if (link)
9971097 reg |= PORT_OVERRIDE_LINK;
1098
+ else
1099
+ reg &= ~PORT_OVERRIDE_LINK;
1100
+ b53_write8(dev, B53_CTRL_PAGE, off, reg);
1101
+}
9981102
999
- if (phydev->duplex == DUPLEX_FULL)
1103
+static void b53_force_port_config(struct b53_device *dev, int port,
1104
+ int speed, int duplex,
1105
+ bool tx_pause, bool rx_pause)
1106
+{
1107
+ u8 reg, val, off;
1108
+
1109
+ /* Override the port settings */
1110
+ if (port == dev->imp_port) {
1111
+ off = B53_PORT_OVERRIDE_CTRL;
1112
+ val = PORT_OVERRIDE_EN;
1113
+ } else {
1114
+ off = B53_GMII_PORT_OVERRIDE_CTRL(port);
1115
+ val = GMII_PO_EN;
1116
+ }
1117
+
1118
+ b53_read8(dev, B53_CTRL_PAGE, off, &reg);
1119
+ reg |= val;
1120
+ if (duplex == DUPLEX_FULL)
10001121 reg |= PORT_OVERRIDE_FULL_DUPLEX;
1122
+ else
1123
+ reg &= ~PORT_OVERRIDE_FULL_DUPLEX;
10011124
1002
- switch (phydev->speed) {
1125
+ switch (speed) {
10031126 case 2000:
10041127 reg |= PORT_OVERRIDE_SPEED_2000M;
1005
- /* fallthrough */
1128
+ fallthrough;
10061129 case SPEED_1000:
10071130 reg |= PORT_OVERRIDE_SPEED_1000M;
10081131 break;
....@@ -1013,24 +1136,46 @@
10131136 reg |= PORT_OVERRIDE_SPEED_10M;
10141137 break;
10151138 default:
1016
- dev_err(ds->dev, "unknown speed: %d\n", phydev->speed);
1139
+ dev_err(dev->dev, "unknown speed: %d\n", speed);
10171140 return;
10181141 }
10191142
1143
+ if (rx_pause)
1144
+ reg |= PORT_OVERRIDE_RX_FLOW;
1145
+ if (tx_pause)
1146
+ reg |= PORT_OVERRIDE_TX_FLOW;
1147
+
1148
+ b53_write8(dev, B53_CTRL_PAGE, off, reg);
1149
+}
1150
+
1151
+static void b53_adjust_link(struct dsa_switch *ds, int port,
1152
+ struct phy_device *phydev)
1153
+{
1154
+ struct b53_device *dev = ds->priv;
1155
+ struct ethtool_eee *p = &dev->ports[port].eee;
1156
+ u8 rgmii_ctrl = 0, reg = 0, off;
1157
+ bool tx_pause = false;
1158
+ bool rx_pause = false;
1159
+
1160
+ if (!phy_is_pseudo_fixed_link(phydev))
1161
+ return;
1162
+
10201163 /* Enable flow control on BCM5301x's CPU port */
10211164 if (is5301x(dev) && port == dev->cpu_port)
1022
- reg |= PORT_OVERRIDE_RX_FLOW | PORT_OVERRIDE_TX_FLOW;
1165
+ tx_pause = rx_pause = true;
10231166
10241167 if (phydev->pause) {
10251168 if (phydev->asym_pause)
1026
- reg |= PORT_OVERRIDE_TX_FLOW;
1027
- reg |= PORT_OVERRIDE_RX_FLOW;
1169
+ tx_pause = true;
1170
+ rx_pause = true;
10281171 }
10291172
1030
- b53_write8(dev, B53_CTRL_PAGE, off, reg);
1173
+ b53_force_port_config(dev, port, phydev->speed, phydev->duplex,
1174
+ tx_pause, rx_pause);
1175
+ b53_force_link(dev, port, phydev->link);
10311176
10321177 if (is531x5(dev) && phy_interface_is_rgmii(phydev)) {
1033
- if (port == 8)
1178
+ if (port == dev->imp_port)
10341179 off = B53_RGMII_CTRL_IMP;
10351180 else
10361181 off = B53_RGMII_CTRL_P(port);
....@@ -1087,16 +1232,9 @@
10871232 }
10881233 } else if (is5301x(dev)) {
10891234 if (port != dev->cpu_port) {
1090
- u8 po_reg = B53_GMII_PORT_OVERRIDE_CTRL(dev->cpu_port);
1091
- u8 gmii_po;
1092
-
1093
- b53_read8(dev, B53_CTRL_PAGE, po_reg, &gmii_po);
1094
- gmii_po |= GMII_PO_LINK |
1095
- GMII_PO_RX_FLOW |
1096
- GMII_PO_TX_FLOW |
1097
- GMII_PO_EN |
1098
- GMII_PO_SPEED_2000M;
1099
- b53_write8(dev, B53_CTRL_PAGE, po_reg, gmii_po);
1235
+ b53_force_port_config(dev, dev->cpu_port, 2000,
1236
+ DUPLEX_FULL, true, true);
1237
+ b53_force_link(dev, dev->cpu_port, 1);
11001238 }
11011239 }
11021240
....@@ -1104,45 +1242,153 @@
11041242 p->eee_enabled = b53_eee_init(ds, port, phydev);
11051243 }
11061244
1107
-int b53_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering)
1245
+void b53_port_event(struct dsa_switch *ds, int port)
11081246 {
11091247 struct b53_device *dev = ds->priv;
1110
- struct net_device *bridge_dev;
1111
- unsigned int i;
1112
- u16 pvid, new_pvid;
1248
+ bool link;
1249
+ u16 sts;
11131250
1114
- /* Handle the case were multiple bridges span the same switch device
1115
- * and one of them has a different setting than what is being requested
1116
- * which would be breaking filtering semantics for any of the other
1117
- * bridge devices.
1251
+ b53_read16(dev, B53_STAT_PAGE, B53_LINK_STAT, &sts);
1252
+ link = !!(sts & BIT(port));
1253
+ dsa_port_phylink_mac_change(ds, port, link);
1254
+}
1255
+EXPORT_SYMBOL(b53_port_event);
1256
+
1257
+void b53_phylink_validate(struct dsa_switch *ds, int port,
1258
+ unsigned long *supported,
1259
+ struct phylink_link_state *state)
1260
+{
1261
+ struct b53_device *dev = ds->priv;
1262
+ __ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
1263
+
1264
+ if (dev->ops->serdes_phylink_validate)
1265
+ dev->ops->serdes_phylink_validate(dev, port, mask, state);
1266
+
1267
+ /* Allow all the expected bits */
1268
+ phylink_set(mask, Autoneg);
1269
+ phylink_set_port_modes(mask);
1270
+ phylink_set(mask, Pause);
1271
+ phylink_set(mask, Asym_Pause);
1272
+
1273
+ /* With the exclusion of 5325/5365, MII, Reverse MII and 802.3z, we
1274
+ * support Gigabit, including Half duplex.
11181275 */
1119
- b53_for_each_port(dev, i) {
1120
- bridge_dev = dsa_to_port(ds, i)->bridge_dev;
1121
- if (bridge_dev &&
1122
- bridge_dev != dsa_to_port(ds, port)->bridge_dev &&
1123
- br_vlan_enabled(bridge_dev) != vlan_filtering) {
1124
- netdev_err(bridge_dev,
1125
- "VLAN filtering is global to the switch!\n");
1126
- return -EINVAL;
1127
- }
1276
+ if (state->interface != PHY_INTERFACE_MODE_MII &&
1277
+ state->interface != PHY_INTERFACE_MODE_REVMII &&
1278
+ !phy_interface_mode_is_8023z(state->interface) &&
1279
+ !(is5325(dev) || is5365(dev))) {
1280
+ phylink_set(mask, 1000baseT_Full);
1281
+ phylink_set(mask, 1000baseT_Half);
11281282 }
11291283
1130
- b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), &pvid);
1131
- new_pvid = pvid;
1132
- if (dev->vlan_filtering_enabled && !vlan_filtering) {
1133
- /* Filtering is currently enabled, use the default PVID since
1134
- * the bridge does not expect tagging anymore
1135
- */
1136
- dev->ports[port].pvid = pvid;
1137
- new_pvid = b53_default_pvid(dev);
1138
- } else if (!dev->vlan_filtering_enabled && vlan_filtering) {
1139
- /* Filtering is currently disabled, restore the previous PVID */
1140
- new_pvid = dev->ports[port].pvid;
1284
+ if (!phy_interface_mode_is_8023z(state->interface)) {
1285
+ phylink_set(mask, 10baseT_Half);
1286
+ phylink_set(mask, 10baseT_Full);
1287
+ phylink_set(mask, 100baseT_Half);
1288
+ phylink_set(mask, 100baseT_Full);
11411289 }
11421290
1143
- if (pvid != new_pvid)
1144
- b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port),
1145
- new_pvid);
1291
+ bitmap_and(supported, supported, mask,
1292
+ __ETHTOOL_LINK_MODE_MASK_NBITS);
1293
+ bitmap_and(state->advertising, state->advertising, mask,
1294
+ __ETHTOOL_LINK_MODE_MASK_NBITS);
1295
+
1296
+ phylink_helper_basex_speed(state);
1297
+}
1298
+EXPORT_SYMBOL(b53_phylink_validate);
1299
+
1300
+int b53_phylink_mac_link_state(struct dsa_switch *ds, int port,
1301
+ struct phylink_link_state *state)
1302
+{
1303
+ struct b53_device *dev = ds->priv;
1304
+ int ret = -EOPNOTSUPP;
1305
+
1306
+ if ((phy_interface_mode_is_8023z(state->interface) ||
1307
+ state->interface == PHY_INTERFACE_MODE_SGMII) &&
1308
+ dev->ops->serdes_link_state)
1309
+ ret = dev->ops->serdes_link_state(dev, port, state);
1310
+
1311
+ return ret;
1312
+}
1313
+EXPORT_SYMBOL(b53_phylink_mac_link_state);
1314
+
1315
+void b53_phylink_mac_config(struct dsa_switch *ds, int port,
1316
+ unsigned int mode,
1317
+ const struct phylink_link_state *state)
1318
+{
1319
+ struct b53_device *dev = ds->priv;
1320
+
1321
+ if (mode == MLO_AN_PHY || mode == MLO_AN_FIXED)
1322
+ return;
1323
+
1324
+ if ((phy_interface_mode_is_8023z(state->interface) ||
1325
+ state->interface == PHY_INTERFACE_MODE_SGMII) &&
1326
+ dev->ops->serdes_config)
1327
+ dev->ops->serdes_config(dev, port, mode, state);
1328
+}
1329
+EXPORT_SYMBOL(b53_phylink_mac_config);
1330
+
1331
+void b53_phylink_mac_an_restart(struct dsa_switch *ds, int port)
1332
+{
1333
+ struct b53_device *dev = ds->priv;
1334
+
1335
+ if (dev->ops->serdes_an_restart)
1336
+ dev->ops->serdes_an_restart(dev, port);
1337
+}
1338
+EXPORT_SYMBOL(b53_phylink_mac_an_restart);
1339
+
1340
+void b53_phylink_mac_link_down(struct dsa_switch *ds, int port,
1341
+ unsigned int mode,
1342
+ phy_interface_t interface)
1343
+{
1344
+ struct b53_device *dev = ds->priv;
1345
+
1346
+ if (mode == MLO_AN_PHY)
1347
+ return;
1348
+
1349
+ if (mode == MLO_AN_FIXED) {
1350
+ b53_force_link(dev, port, false);
1351
+ return;
1352
+ }
1353
+
1354
+ if (phy_interface_mode_is_8023z(interface) &&
1355
+ dev->ops->serdes_link_set)
1356
+ dev->ops->serdes_link_set(dev, port, mode, interface, false);
1357
+}
1358
+EXPORT_SYMBOL(b53_phylink_mac_link_down);
1359
+
1360
+void b53_phylink_mac_link_up(struct dsa_switch *ds, int port,
1361
+ unsigned int mode,
1362
+ phy_interface_t interface,
1363
+ struct phy_device *phydev,
1364
+ int speed, int duplex,
1365
+ bool tx_pause, bool rx_pause)
1366
+{
1367
+ struct b53_device *dev = ds->priv;
1368
+
1369
+ if (mode == MLO_AN_PHY)
1370
+ return;
1371
+
1372
+ if (mode == MLO_AN_FIXED) {
1373
+ b53_force_port_config(dev, port, speed, duplex,
1374
+ tx_pause, rx_pause);
1375
+ b53_force_link(dev, port, true);
1376
+ return;
1377
+ }
1378
+
1379
+ if (phy_interface_mode_is_8023z(interface) &&
1380
+ dev->ops->serdes_link_set)
1381
+ dev->ops->serdes_link_set(dev, port, mode, interface, true);
1382
+}
1383
+EXPORT_SYMBOL(b53_phylink_mac_link_up);
1384
+
1385
+int b53_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering,
1386
+ struct switchdev_trans *trans)
1387
+{
1388
+ struct b53_device *dev = ds->priv;
1389
+
1390
+ if (switchdev_trans_ph_prepare(trans))
1391
+ return 0;
11461392
11471393 b53_enable_vlan(dev, dev->vlan_enabled, vlan_filtering);
11481394
....@@ -1158,10 +1404,18 @@
11581404 if ((is5325(dev) || is5365(dev)) && vlan->vid_begin == 0)
11591405 return -EOPNOTSUPP;
11601406
1407
+ /* Port 7 on 7278 connects to the ASP's UniMAC which is not capable of
1408
+ * receiving VLAN tagged frames at all, we can still allow the port to
1409
+ * be configured for egress untagged.
1410
+ */
1411
+ if (dev->chip_id == BCM7278_DEVICE_ID && port == 7 &&
1412
+ !(vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED))
1413
+ return -EINVAL;
1414
+
11611415 if (vlan->vid_end >= dev->num_vlans)
11621416 return -ERANGE;
11631417
1164
- b53_enable_vlan(dev, true, dev->vlan_filtering_enabled);
1418
+ b53_enable_vlan(dev, true, ds->vlan_filtering);
11651419
11661420 return 0;
11671421 }
....@@ -1279,8 +1533,7 @@
12791533 }
12801534
12811535 static int b53_arl_read(struct b53_device *dev, u64 mac,
1282
- u16 vid, struct b53_arl_entry *ent, u8 *idx,
1283
- bool is_valid)
1536
+ u16 vid, struct b53_arl_entry *ent, u8 *idx)
12841537 {
12851538 DECLARE_BITMAP(free_bins, B53_ARLTBL_MAX_BIN_ENTRIES);
12861539 unsigned int i;
....@@ -1290,10 +1543,10 @@
12901543 if (ret)
12911544 return ret;
12921545
1293
- bitmap_zero(free_bins, dev->num_arl_entries);
1546
+ bitmap_zero(free_bins, dev->num_arl_bins);
12941547
12951548 /* Read the bins */
1296
- for (i = 0; i < dev->num_arl_entries; i++) {
1549
+ for (i = 0; i < dev->num_arl_bins; i++) {
12971550 u64 mac_vid;
12981551 u32 fwd_entry;
12991552
....@@ -1316,10 +1569,10 @@
13161569 return 0;
13171570 }
13181571
1319
- if (bitmap_weight(free_bins, dev->num_arl_entries) == 0)
1572
+ if (bitmap_weight(free_bins, dev->num_arl_bins) == 0)
13201573 return -ENOSPC;
13211574
1322
- *idx = find_first_bit(free_bins, dev->num_arl_entries);
1575
+ *idx = find_first_bit(free_bins, dev->num_arl_bins);
13231576
13241577 return -ENOENT;
13251578 }
....@@ -1345,7 +1598,8 @@
13451598 if (ret)
13461599 return ret;
13471600
1348
- ret = b53_arl_read(dev, mac, vid, &ent, &idx, is_valid);
1601
+ ret = b53_arl_read(dev, mac, vid, &ent, &idx);
1602
+
13491603 /* If this is a read, just finish now */
13501604 if (op)
13511605 return ret;
....@@ -1369,11 +1623,24 @@
13691623 break;
13701624 }
13711625
1372
- memset(&ent, 0, sizeof(ent));
1373
- ent.port = port;
1374
- ent.is_valid = is_valid;
1626
+ /* For multicast address, the port is a bitmask and the validity
1627
+ * is determined by having at least one port being still active
1628
+ */
1629
+ if (!is_multicast_ether_addr(addr)) {
1630
+ ent.port = port;
1631
+ ent.is_valid = is_valid;
1632
+ } else {
1633
+ if (is_valid)
1634
+ ent.port |= BIT(port);
1635
+ else
1636
+ ent.port &= ~BIT(port);
1637
+
1638
+ ent.is_valid = !!(ent.port);
1639
+ }
1640
+
13751641 ent.vid = vid;
13761642 ent.is_static = true;
1643
+ ent.is_age = false;
13771644 memcpy(ent.mac, addr, ETH_ALEN);
13781645 b53_arl_from_entry(&mac_vid, &fwd_entry, &ent);
13791646
....@@ -1476,7 +1743,7 @@
14761743 if (ret)
14771744 return ret;
14781745
1479
- if (priv->num_arl_entries > 2) {
1746
+ if (priv->num_arl_bins > 2) {
14801747 b53_arl_search_rd(priv, 1, &results[1]);
14811748 ret = b53_fdb_copy(port, &results[1], cb, data);
14821749 if (ret)
....@@ -1486,18 +1753,65 @@
14861753 break;
14871754 }
14881755
1489
- } while (count++ < 1024);
1756
+ } while (count++ < b53_max_arl_entries(priv) / 2);
14901757
14911758 return 0;
14921759 }
14931760 EXPORT_SYMBOL(b53_fdb_dump);
14941761
1762
+int b53_mdb_prepare(struct dsa_switch *ds, int port,
1763
+ const struct switchdev_obj_port_mdb *mdb)
1764
+{
1765
+ struct b53_device *priv = ds->priv;
1766
+
1767
+ /* 5325 and 5365 require some more massaging, but could
1768
+ * be supported eventually
1769
+ */
1770
+ if (is5325(priv) || is5365(priv))
1771
+ return -EOPNOTSUPP;
1772
+
1773
+ return 0;
1774
+}
1775
+EXPORT_SYMBOL(b53_mdb_prepare);
1776
+
1777
+void b53_mdb_add(struct dsa_switch *ds, int port,
1778
+ const struct switchdev_obj_port_mdb *mdb)
1779
+{
1780
+ struct b53_device *priv = ds->priv;
1781
+ int ret;
1782
+
1783
+ ret = b53_arl_op(priv, 0, port, mdb->addr, mdb->vid, true);
1784
+ if (ret)
1785
+ dev_err(ds->dev, "failed to add MDB entry\n");
1786
+}
1787
+EXPORT_SYMBOL(b53_mdb_add);
1788
+
1789
+int b53_mdb_del(struct dsa_switch *ds, int port,
1790
+ const struct switchdev_obj_port_mdb *mdb)
1791
+{
1792
+ struct b53_device *priv = ds->priv;
1793
+ int ret;
1794
+
1795
+ ret = b53_arl_op(priv, 0, port, mdb->addr, mdb->vid, false);
1796
+ if (ret)
1797
+ dev_err(ds->dev, "failed to delete MDB entry\n");
1798
+
1799
+ return ret;
1800
+}
1801
+EXPORT_SYMBOL(b53_mdb_del);
1802
+
14951803 int b53_br_join(struct dsa_switch *ds, int port, struct net_device *br)
14961804 {
14971805 struct b53_device *dev = ds->priv;
1498
- s8 cpu_port = ds->ports[port].cpu_dp->index;
1806
+ s8 cpu_port = dsa_to_port(ds, port)->cpu_dp->index;
14991807 u16 pvlan, reg;
15001808 unsigned int i;
1809
+
1810
+ /* On 7278, port 7 which connects to the ASP should only receive
1811
+ * traffic from matching CFP rules.
1812
+ */
1813
+ if (dev->chip_id == BCM7278_DEVICE_ID && port == 7)
1814
+ return -EINVAL;
15011815
15021816 /* Make this port leave the all VLANs join since we will have proper
15031817 * VLAN entries from now on
....@@ -1543,7 +1857,7 @@
15431857 {
15441858 struct b53_device *dev = ds->priv;
15451859 struct b53_vlan *vl = &dev->vlans[0];
1546
- s8 cpu_port = ds->ports[port].cpu_dp->index;
1860
+ s8 cpu_port = dsa_to_port(ds, port)->cpu_dp->index;
15471861 unsigned int i;
15481862 u16 pvlan, reg, pvid;
15491863
....@@ -1629,6 +1943,38 @@
16291943 }
16301944 EXPORT_SYMBOL(b53_br_fast_age);
16311945
1946
+int b53_br_egress_floods(struct dsa_switch *ds, int port,
1947
+ bool unicast, bool multicast)
1948
+{
1949
+ struct b53_device *dev = ds->priv;
1950
+ u16 uc, mc;
1951
+
1952
+ b53_read16(dev, B53_CTRL_PAGE, B53_UC_FLOOD_MASK, &uc);
1953
+ if (unicast)
1954
+ uc |= BIT(port);
1955
+ else
1956
+ uc &= ~BIT(port);
1957
+ b53_write16(dev, B53_CTRL_PAGE, B53_UC_FLOOD_MASK, uc);
1958
+
1959
+ b53_read16(dev, B53_CTRL_PAGE, B53_MC_FLOOD_MASK, &mc);
1960
+ if (multicast)
1961
+ mc |= BIT(port);
1962
+ else
1963
+ mc &= ~BIT(port);
1964
+ b53_write16(dev, B53_CTRL_PAGE, B53_MC_FLOOD_MASK, mc);
1965
+
1966
+ b53_read16(dev, B53_CTRL_PAGE, B53_IPMC_FLOOD_MASK, &mc);
1967
+ if (multicast)
1968
+ mc |= BIT(port);
1969
+ else
1970
+ mc &= ~BIT(port);
1971
+ b53_write16(dev, B53_CTRL_PAGE, B53_IPMC_FLOOD_MASK, mc);
1972
+
1973
+ return 0;
1974
+
1975
+}
1976
+EXPORT_SYMBOL(b53_br_egress_floods);
1977
+
16321978 static bool b53_possible_cpu_port(struct dsa_switch *ds, int port)
16331979 {
16341980 /* Broadcom switches will accept enabling Broadcom tags on the
....@@ -1644,36 +1990,57 @@
16441990 return false;
16451991 }
16461992
1647
-static bool b53_can_enable_brcm_tags(struct dsa_switch *ds, int port)
1993
+static bool b53_can_enable_brcm_tags(struct dsa_switch *ds, int port,
1994
+ enum dsa_tag_protocol tag_protocol)
16481995 {
16491996 bool ret = b53_possible_cpu_port(ds, port);
16501997
1651
- if (!ret)
1998
+ if (!ret) {
16521999 dev_warn(ds->dev, "Port %d is not Broadcom tag capable\n",
16532000 port);
2001
+ return ret;
2002
+ }
2003
+
2004
+ switch (tag_protocol) {
2005
+ case DSA_TAG_PROTO_BRCM:
2006
+ case DSA_TAG_PROTO_BRCM_PREPEND:
2007
+ dev_warn(ds->dev,
2008
+ "Port %d is stacked to Broadcom tag switch\n", port);
2009
+ ret = false;
2010
+ break;
2011
+ default:
2012
+ ret = true;
2013
+ break;
2014
+ }
2015
+
16542016 return ret;
16552017 }
16562018
1657
-enum dsa_tag_protocol b53_get_tag_protocol(struct dsa_switch *ds, int port)
2019
+enum dsa_tag_protocol b53_get_tag_protocol(struct dsa_switch *ds, int port,
2020
+ enum dsa_tag_protocol mprot)
16582021 {
16592022 struct b53_device *dev = ds->priv;
16602023
16612024 /* Older models (5325, 5365) support a different tag format that we do
1662
- * not support in net/dsa/tag_brcm.c yet. 539x and 531x5 require managed
1663
- * mode to be turned on which means we need to specifically manage ARL
1664
- * misses on multicast addresses (TBD).
2025
+ * not support in net/dsa/tag_brcm.c yet.
16652026 */
1666
- if (is5325(dev) || is5365(dev) || is539x(dev) || is531x5(dev) ||
1667
- !b53_can_enable_brcm_tags(ds, port))
1668
- return DSA_TAG_PROTO_NONE;
2027
+ if (is5325(dev) || is5365(dev) ||
2028
+ !b53_can_enable_brcm_tags(ds, port, mprot)) {
2029
+ dev->tag_protocol = DSA_TAG_PROTO_NONE;
2030
+ goto out;
2031
+ }
16692032
16702033 /* Broadcom BCM58xx chips have a flow accelerator on Port 8
16712034 * which requires us to use the prepended Broadcom tag type
16722035 */
1673
- if (dev->chip_id == BCM58XX_DEVICE_ID && port == B53_CPU_PORT)
1674
- return DSA_TAG_PROTO_BRCM_PREPEND;
2036
+ if (dev->chip_id == BCM58XX_DEVICE_ID && port == B53_CPU_PORT) {
2037
+ dev->tag_protocol = DSA_TAG_PROTO_BRCM_PREPEND;
2038
+ goto out;
2039
+ }
16752040
1676
- return DSA_TAG_PROTO_BRCM;
2041
+ dev->tag_protocol = DSA_TAG_PROTO_BRCM;
2042
+out:
2043
+ return dev->tag_protocol;
16772044 }
16782045 EXPORT_SYMBOL(b53_get_tag_protocol);
16792046
....@@ -1804,9 +2171,30 @@
18042171 }
18052172 EXPORT_SYMBOL(b53_set_mac_eee);
18062173
2174
+static int b53_change_mtu(struct dsa_switch *ds, int port, int mtu)
2175
+{
2176
+ struct b53_device *dev = ds->priv;
2177
+ bool enable_jumbo;
2178
+ bool allow_10_100;
2179
+
2180
+ if (is5325(dev) || is5365(dev))
2181
+ return -EOPNOTSUPP;
2182
+
2183
+ enable_jumbo = (mtu >= JMS_MIN_SIZE);
2184
+ allow_10_100 = (dev->chip_id == BCM583XX_DEVICE_ID);
2185
+
2186
+ return b53_set_jumbo(dev, enable_jumbo, allow_10_100);
2187
+}
2188
+
2189
+static int b53_get_max_mtu(struct dsa_switch *ds, int port)
2190
+{
2191
+ return JMS_MAX_SIZE;
2192
+}
2193
+
18072194 static const struct dsa_switch_ops b53_switch_ops = {
18082195 .get_tag_protocol = b53_get_tag_protocol,
18092196 .setup = b53_setup,
2197
+ .teardown = b53_teardown,
18102198 .get_strings = b53_get_strings,
18112199 .get_ethtool_stats = b53_get_ethtool_stats,
18122200 .get_sset_count = b53_get_sset_count,
....@@ -1814,6 +2202,12 @@
18142202 .phy_read = b53_phy_read16,
18152203 .phy_write = b53_phy_write16,
18162204 .adjust_link = b53_adjust_link,
2205
+ .phylink_validate = b53_phylink_validate,
2206
+ .phylink_mac_link_state = b53_phylink_mac_link_state,
2207
+ .phylink_mac_config = b53_phylink_mac_config,
2208
+ .phylink_mac_an_restart = b53_phylink_mac_an_restart,
2209
+ .phylink_mac_link_down = b53_phylink_mac_link_down,
2210
+ .phylink_mac_link_up = b53_phylink_mac_link_up,
18172211 .port_enable = b53_enable_port,
18182212 .port_disable = b53_disable_port,
18192213 .get_mac_eee = b53_get_mac_eee,
....@@ -1822,6 +2216,7 @@
18222216 .port_bridge_leave = b53_br_leave,
18232217 .port_stp_state_set = b53_br_set_stp_state,
18242218 .port_fast_age = b53_br_fast_age,
2219
+ .port_egress_floods = b53_br_egress_floods,
18252220 .port_vlan_filtering = b53_vlan_filtering,
18262221 .port_vlan_prepare = b53_vlan_prepare,
18272222 .port_vlan_add = b53_vlan_add,
....@@ -1831,6 +2226,11 @@
18312226 .port_fdb_del = b53_fdb_del,
18322227 .port_mirror_add = b53_mirror_add,
18332228 .port_mirror_del = b53_mirror_del,
2229
+ .port_mdb_prepare = b53_mdb_prepare,
2230
+ .port_mdb_add = b53_mdb_add,
2231
+ .port_mdb_del = b53_mdb_del,
2232
+ .port_max_mtu = b53_get_max_mtu,
2233
+ .port_change_mtu = b53_change_mtu,
18342234 };
18352235
18362236 struct b53_chip_data {
....@@ -1838,9 +2238,11 @@
18382238 const char *dev_name;
18392239 u16 vlans;
18402240 u16 enabled_ports;
2241
+ u8 imp_port;
18412242 u8 cpu_port;
18422243 u8 vta_regs[3];
1843
- u8 arl_entries;
2244
+ u8 arl_bins;
2245
+ u16 arl_buckets;
18442246 u8 duplex_reg;
18452247 u8 jumbo_pm_reg;
18462248 u8 jumbo_size_reg;
....@@ -1859,7 +2261,9 @@
18592261 .dev_name = "BCM5325",
18602262 .vlans = 16,
18612263 .enabled_ports = 0x1f,
1862
- .arl_entries = 2,
2264
+ .arl_bins = 2,
2265
+ .arl_buckets = 1024,
2266
+ .imp_port = 5,
18632267 .cpu_port = B53_CPU_PORT_25,
18642268 .duplex_reg = B53_DUPLEX_STAT_FE,
18652269 },
....@@ -1868,7 +2272,9 @@
18682272 .dev_name = "BCM5365",
18692273 .vlans = 256,
18702274 .enabled_ports = 0x1f,
1871
- .arl_entries = 2,
2275
+ .arl_bins = 2,
2276
+ .arl_buckets = 1024,
2277
+ .imp_port = 5,
18722278 .cpu_port = B53_CPU_PORT_25,
18732279 .duplex_reg = B53_DUPLEX_STAT_FE,
18742280 },
....@@ -1877,7 +2283,9 @@
18772283 .dev_name = "BCM5389",
18782284 .vlans = 4096,
18792285 .enabled_ports = 0x1f,
1880
- .arl_entries = 4,
2286
+ .arl_bins = 4,
2287
+ .arl_buckets = 1024,
2288
+ .imp_port = 8,
18812289 .cpu_port = B53_CPU_PORT,
18822290 .vta_regs = B53_VTA_REGS,
18832291 .duplex_reg = B53_DUPLEX_STAT_GE,
....@@ -1889,7 +2297,9 @@
18892297 .dev_name = "BCM5395",
18902298 .vlans = 4096,
18912299 .enabled_ports = 0x1f,
1892
- .arl_entries = 4,
2300
+ .arl_bins = 4,
2301
+ .arl_buckets = 1024,
2302
+ .imp_port = 8,
18932303 .cpu_port = B53_CPU_PORT,
18942304 .vta_regs = B53_VTA_REGS,
18952305 .duplex_reg = B53_DUPLEX_STAT_GE,
....@@ -1901,7 +2311,9 @@
19012311 .dev_name = "BCM5397",
19022312 .vlans = 4096,
19032313 .enabled_ports = 0x1f,
1904
- .arl_entries = 4,
2314
+ .arl_bins = 4,
2315
+ .arl_buckets = 1024,
2316
+ .imp_port = 8,
19052317 .cpu_port = B53_CPU_PORT,
19062318 .vta_regs = B53_VTA_REGS_9798,
19072319 .duplex_reg = B53_DUPLEX_STAT_GE,
....@@ -1913,7 +2325,9 @@
19132325 .dev_name = "BCM5398",
19142326 .vlans = 4096,
19152327 .enabled_ports = 0x7f,
1916
- .arl_entries = 4,
2328
+ .arl_bins = 4,
2329
+ .arl_buckets = 1024,
2330
+ .imp_port = 8,
19172331 .cpu_port = B53_CPU_PORT,
19182332 .vta_regs = B53_VTA_REGS_9798,
19192333 .duplex_reg = B53_DUPLEX_STAT_GE,
....@@ -1925,8 +2339,10 @@
19252339 .dev_name = "BCM53115",
19262340 .vlans = 4096,
19272341 .enabled_ports = 0x1f,
1928
- .arl_entries = 4,
2342
+ .arl_bins = 4,
2343
+ .arl_buckets = 1024,
19292344 .vta_regs = B53_VTA_REGS,
2345
+ .imp_port = 8,
19302346 .cpu_port = B53_CPU_PORT,
19312347 .duplex_reg = B53_DUPLEX_STAT_GE,
19322348 .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
....@@ -1937,7 +2353,9 @@
19372353 .dev_name = "BCM53125",
19382354 .vlans = 4096,
19392355 .enabled_ports = 0xff,
1940
- .arl_entries = 4,
2356
+ .arl_bins = 4,
2357
+ .arl_buckets = 1024,
2358
+ .imp_port = 8,
19412359 .cpu_port = B53_CPU_PORT,
19422360 .vta_regs = B53_VTA_REGS,
19432361 .duplex_reg = B53_DUPLEX_STAT_GE,
....@@ -1949,7 +2367,9 @@
19492367 .dev_name = "BCM53128",
19502368 .vlans = 4096,
19512369 .enabled_ports = 0x1ff,
1952
- .arl_entries = 4,
2370
+ .arl_bins = 4,
2371
+ .arl_buckets = 1024,
2372
+ .imp_port = 8,
19532373 .cpu_port = B53_CPU_PORT,
19542374 .vta_regs = B53_VTA_REGS,
19552375 .duplex_reg = B53_DUPLEX_STAT_GE,
....@@ -1961,7 +2381,9 @@
19612381 .dev_name = "BCM63xx",
19622382 .vlans = 4096,
19632383 .enabled_ports = 0, /* pdata must provide them */
1964
- .arl_entries = 4,
2384
+ .arl_bins = 4,
2385
+ .arl_buckets = 1024,
2386
+ .imp_port = 8,
19652387 .cpu_port = B53_CPU_PORT,
19662388 .vta_regs = B53_VTA_REGS_63XX,
19672389 .duplex_reg = B53_DUPLEX_STAT_63XX,
....@@ -1973,7 +2395,9 @@
19732395 .dev_name = "BCM53010",
19742396 .vlans = 4096,
19752397 .enabled_ports = 0x1f,
1976
- .arl_entries = 4,
2398
+ .arl_bins = 4,
2399
+ .arl_buckets = 1024,
2400
+ .imp_port = 8,
19772401 .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */
19782402 .vta_regs = B53_VTA_REGS,
19792403 .duplex_reg = B53_DUPLEX_STAT_GE,
....@@ -1985,7 +2409,9 @@
19852409 .dev_name = "BCM53011",
19862410 .vlans = 4096,
19872411 .enabled_ports = 0x1bf,
1988
- .arl_entries = 4,
2412
+ .arl_bins = 4,
2413
+ .arl_buckets = 1024,
2414
+ .imp_port = 8,
19892415 .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */
19902416 .vta_regs = B53_VTA_REGS,
19912417 .duplex_reg = B53_DUPLEX_STAT_GE,
....@@ -1997,7 +2423,9 @@
19972423 .dev_name = "BCM53012",
19982424 .vlans = 4096,
19992425 .enabled_ports = 0x1bf,
2000
- .arl_entries = 4,
2426
+ .arl_bins = 4,
2427
+ .arl_buckets = 1024,
2428
+ .imp_port = 8,
20012429 .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */
20022430 .vta_regs = B53_VTA_REGS,
20032431 .duplex_reg = B53_DUPLEX_STAT_GE,
....@@ -2009,7 +2437,9 @@
20092437 .dev_name = "BCM53018",
20102438 .vlans = 4096,
20112439 .enabled_ports = 0x1f,
2012
- .arl_entries = 4,
2440
+ .arl_bins = 4,
2441
+ .arl_buckets = 1024,
2442
+ .imp_port = 8,
20132443 .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */
20142444 .vta_regs = B53_VTA_REGS,
20152445 .duplex_reg = B53_DUPLEX_STAT_GE,
....@@ -2021,7 +2451,9 @@
20212451 .dev_name = "BCM53019",
20222452 .vlans = 4096,
20232453 .enabled_ports = 0x1f,
2024
- .arl_entries = 4,
2454
+ .arl_bins = 4,
2455
+ .arl_buckets = 1024,
2456
+ .imp_port = 8,
20252457 .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */
20262458 .vta_regs = B53_VTA_REGS,
20272459 .duplex_reg = B53_DUPLEX_STAT_GE,
....@@ -2033,7 +2465,9 @@
20332465 .dev_name = "BCM585xx/586xx/88312",
20342466 .vlans = 4096,
20352467 .enabled_ports = 0x1ff,
2036
- .arl_entries = 4,
2468
+ .arl_bins = 4,
2469
+ .arl_buckets = 1024,
2470
+ .imp_port = 8,
20372471 .cpu_port = B53_CPU_PORT,
20382472 .vta_regs = B53_VTA_REGS,
20392473 .duplex_reg = B53_DUPLEX_STAT_GE,
....@@ -2045,7 +2479,9 @@
20452479 .dev_name = "BCM583xx/11360",
20462480 .vlans = 4096,
20472481 .enabled_ports = 0x103,
2048
- .arl_entries = 4,
2482
+ .arl_bins = 4,
2483
+ .arl_buckets = 1024,
2484
+ .imp_port = 8,
20492485 .cpu_port = B53_CPU_PORT,
20502486 .vta_regs = B53_VTA_REGS,
20512487 .duplex_reg = B53_DUPLEX_STAT_GE,
....@@ -2057,7 +2493,9 @@
20572493 .dev_name = "BCM7445",
20582494 .vlans = 4096,
20592495 .enabled_ports = 0x1ff,
2060
- .arl_entries = 4,
2496
+ .arl_bins = 4,
2497
+ .arl_buckets = 1024,
2498
+ .imp_port = 8,
20612499 .cpu_port = B53_CPU_PORT,
20622500 .vta_regs = B53_VTA_REGS,
20632501 .duplex_reg = B53_DUPLEX_STAT_GE,
....@@ -2069,7 +2507,9 @@
20692507 .dev_name = "BCM7278",
20702508 .vlans = 4096,
20712509 .enabled_ports = 0x1ff,
2072
- .arl_entries= 4,
2510
+ .arl_bins = 4,
2511
+ .arl_buckets = 256,
2512
+ .imp_port = 8,
20732513 .cpu_port = B53_CPU_PORT,
20742514 .vta_regs = B53_VTA_REGS,
20752515 .duplex_reg = B53_DUPLEX_STAT_GE,
....@@ -2095,9 +2535,11 @@
20952535 dev->vta_regs[1] = chip->vta_regs[1];
20962536 dev->vta_regs[2] = chip->vta_regs[2];
20972537 dev->jumbo_pm_reg = chip->jumbo_pm_reg;
2538
+ dev->imp_port = chip->imp_port;
20982539 dev->cpu_port = chip->cpu_port;
20992540 dev->num_vlans = chip->vlans;
2100
- dev->num_arl_entries = chip->arl_entries;
2541
+ dev->num_arl_bins = chip->arl_bins;
2542
+ dev->num_arl_buckets = chip->arl_buckets;
21012543 break;
21022544 }
21032545 }
....@@ -2138,6 +2580,8 @@
21382580 dev->enabled_ports |= BIT(dev->cpu_port);
21392581 dev->num_ports = fls(dev->enabled_ports);
21402582
2583
+ dev->ds->num_ports = min_t(unsigned int, dev->num_ports, DSA_MAX_PORTS);
2584
+
21412585 /* Include non standard CPU port built-in PHYs to be probed */
21422586 if (is539x(dev) || is531x5(dev)) {
21432587 for (i = 0; i < dev->num_ports; i++) {
....@@ -2177,9 +2621,11 @@
21772621 struct dsa_switch *ds;
21782622 struct b53_device *dev;
21792623
2180
- ds = dsa_switch_alloc(base, DSA_MAX_PORTS);
2624
+ ds = devm_kzalloc(base, sizeof(*ds), GFP_KERNEL);
21812625 if (!ds)
21822626 return NULL;
2627
+
2628
+ ds->dev = base;
21832629
21842630 dev = devm_kzalloc(base, sizeof(*dev), GFP_KERNEL);
21852631 if (!dev)
....@@ -2192,6 +2638,16 @@
21922638 dev->priv = priv;
21932639 dev->ops = ops;
21942640 ds->ops = &b53_switch_ops;
2641
+ ds->configure_vlan_while_not_filtering = true;
2642
+ ds->untag_bridge_pvid = true;
2643
+ dev->vlan_enabled = ds->configure_vlan_while_not_filtering;
2644
+ /* Let DSA handle the case were multiple bridges span the same switch
2645
+ * device and different VLAN awareness settings are requested, which
2646
+ * would be breaking filtering semantics for any of the other bridge
2647
+ * devices. (not hardware supported)
2648
+ */
2649
+ ds->vlan_filtering_is_global = true;
2650
+
21952651 mutex_init(&dev->reg_mutex);
21962652 mutex_init(&dev->stats_mutex);
21972653
....@@ -2250,8 +2706,9 @@
22502706 dev->chip_id = id32;
22512707 break;
22522708 default:
2253
- pr_err("unsupported switch detected (BCM53%02x/BCM%x)\n",
2254
- id8, id32);
2709
+ dev_err(dev->dev,
2710
+ "unsupported switch detected (BCM53%02x/BCM%x)\n",
2711
+ id8, id32);
22552712 return -ENODEV;
22562713 }
22572714 }
....@@ -2281,7 +2738,8 @@
22812738 if (ret)
22822739 return ret;
22832740
2284
- pr_info("found switch: %s, rev %i\n", dev->name, dev->core_rev);
2741
+ dev_info(dev->dev, "found switch: %s, rev %i\n",
2742
+ dev->name, dev->core_rev);
22852743
22862744 return dsa_register_switch(dev->ds);
22872745 }