Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'mv88e6xxx-vlan-filtering'

Vivien Didelot says:

====================
net: dsa: mv88e6xxx: implement VLAN filtering

This patchset fixes hardware bridging for non 802.1Q aware systems.

The mv88e6xxx DSA driver currently depends on CONFIG_VLAN_8021Q and
CONFIG_BRIDGE_VLAN_FILTERING enabled for correct bridging between switch ports.

Patch 1/9 adds support for the VLAN filtering switchdev attribute in DSA.

Patchs 2/9 and 3/9 add helper functions for the following patches.

Patchs 4/9 to 6/9 assign dynamic address databases to VLANs, ports, and
bridge groups (the lowest available FID is cleared and assigned), and thus
restore support for per-port FDB operations.

Patchs 7/9 to 9/9 refine ports isolation and setup 802.1Q on user demand.

With this patchset, ports get correctly bridged and the driver behaves as
expected, with or without 802.1Q support.

With CONFIG_VLAN_8021Q enabled, setting a default PVID to the bridge correctly
propagates the corresponding VLAN, in addition to the hardware bridging:

# echo 42 > /sys/class/net/<bridge>/bridge/default_pvid

But considering CONFIG_BRIDGE_VLAN_FILTERING enabled, the hardware VLAN
filtering is enabled on all bridge members only when the user requests it:

# echo 1 > /sys/class/net/<bridge>/bridge/vlan_filtering
====================

Signed-off-by: David S. Miller <davem@davemloft.net>

+372 -104
+1
drivers/net/dsa/mv88e6171.c
··· 106 106 .port_join_bridge = mv88e6xxx_port_bridge_join, 107 107 .port_leave_bridge = mv88e6xxx_port_bridge_leave, 108 108 .port_stp_update = mv88e6xxx_port_stp_update, 109 + .port_vlan_filtering = mv88e6xxx_port_vlan_filtering, 109 110 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare, 110 111 .port_vlan_add = mv88e6xxx_port_vlan_add, 111 112 .port_vlan_del = mv88e6xxx_port_vlan_del,
+1
drivers/net/dsa/mv88e6352.c
··· 327 327 .port_join_bridge = mv88e6xxx_port_bridge_join, 328 328 .port_leave_bridge = mv88e6xxx_port_bridge_leave, 329 329 .port_stp_update = mv88e6xxx_port_stp_update, 330 + .port_vlan_filtering = mv88e6xxx_port_vlan_filtering, 330 331 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare, 331 332 .port_vlan_add = mv88e6xxx_port_vlan_add, 332 333 .port_vlan_del = mv88e6xxx_port_vlan_del,
+341 -104
drivers/net/dsa/mv88e6xxx.c
··· 1087 1087 return ret; 1088 1088 } 1089 1089 1090 - static int _mv88e6xxx_port_vlan_map_set(struct dsa_switch *ds, int port, 1091 - u16 output_ports) 1090 + static int _mv88e6xxx_port_based_vlan_map(struct dsa_switch *ds, int port) 1092 1091 { 1093 1092 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); 1093 + struct net_device *bridge = ps->ports[port].bridge_dev; 1094 1094 const u16 mask = (1 << ps->num_ports) - 1; 1095 + u16 output_ports = 0; 1095 1096 int reg; 1097 + int i; 1098 + 1099 + /* allow CPU port or DSA link(s) to send frames to every port */ 1100 + if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)) { 1101 + output_ports = mask; 1102 + } else { 1103 + for (i = 0; i < ps->num_ports; ++i) { 1104 + /* allow sending frames to every group member */ 1105 + if (bridge && ps->ports[i].bridge_dev == bridge) 1106 + output_ports |= BIT(i); 1107 + 1108 + /* allow sending frames to CPU port and DSA link(s) */ 1109 + if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i)) 1110 + output_ports |= BIT(i); 1111 + } 1112 + } 1113 + 1114 + /* prevent frames from going back out of the port they came in on */ 1115 + output_ports &= ~BIT(port); 1096 1116 1097 1117 reg = _mv88e6xxx_reg_read(ds, REG_PORT(port), PORT_BASE_VLAN); 1098 1118 if (reg < 0) ··· 1478 1458 return _mv88e6xxx_vtu_cmd(ds, GLOBAL_VTU_OP_STU_LOAD_PURGE); 1479 1459 } 1480 1460 1481 - static int _mv88e6xxx_vlan_init(struct dsa_switch *ds, u16 vid, 1482 - struct mv88e6xxx_vtu_stu_entry *entry) 1461 + static int _mv88e6xxx_port_fid(struct dsa_switch *ds, int port, u16 *new, 1462 + u16 *old) 1463 + { 1464 + u16 fid; 1465 + int ret; 1466 + 1467 + /* Port's default FID bits 3:0 are located in reg 0x06, offset 12 */ 1468 + ret = _mv88e6xxx_reg_read(ds, REG_PORT(port), PORT_BASE_VLAN); 1469 + if (ret < 0) 1470 + return ret; 1471 + 1472 + fid = (ret & PORT_BASE_VLAN_FID_3_0_MASK) >> 12; 1473 + 1474 + if (new) { 1475 + ret &= ~PORT_BASE_VLAN_FID_3_0_MASK; 1476 + ret |= (*new << 12) & PORT_BASE_VLAN_FID_3_0_MASK; 1477 + 1478 + ret = _mv88e6xxx_reg_write(ds, REG_PORT(port), PORT_BASE_VLAN, 1479 + ret); 1480 + if (ret < 0) 1481 + return ret; 1482 + } 1483 + 1484 + /* Port's default FID bits 11:4 are located in reg 0x05, offset 0 */ 1485 + ret = _mv88e6xxx_reg_read(ds, REG_PORT(port), PORT_CONTROL_1); 1486 + if (ret < 0) 1487 + return ret; 1488 + 1489 + fid |= (ret & PORT_CONTROL_1_FID_11_4_MASK) << 4; 1490 + 1491 + if (new) { 1492 + ret &= ~PORT_CONTROL_1_FID_11_4_MASK; 1493 + ret |= (*new >> 4) & PORT_CONTROL_1_FID_11_4_MASK; 1494 + 1495 + ret = _mv88e6xxx_reg_write(ds, REG_PORT(port), PORT_CONTROL_1, 1496 + ret); 1497 + if (ret < 0) 1498 + return ret; 1499 + 1500 + netdev_dbg(ds->ports[port], "FID %d (was %d)\n", *new, fid); 1501 + } 1502 + 1503 + if (old) 1504 + *old = fid; 1505 + 1506 + return 0; 1507 + } 1508 + 1509 + static int _mv88e6xxx_port_fid_get(struct dsa_switch *ds, int port, u16 *fid) 1510 + { 1511 + return _mv88e6xxx_port_fid(ds, port, NULL, fid); 1512 + } 1513 + 1514 + static int _mv88e6xxx_port_fid_set(struct dsa_switch *ds, int port, u16 fid) 1515 + { 1516 + return _mv88e6xxx_port_fid(ds, port, &fid, NULL); 1517 + } 1518 + 1519 + static int _mv88e6xxx_fid_new(struct dsa_switch *ds, u16 *fid) 1520 + { 1521 + struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); 1522 + DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID); 1523 + struct mv88e6xxx_vtu_stu_entry vlan; 1524 + int i, err; 1525 + 1526 + bitmap_zero(fid_bitmap, MV88E6XXX_N_FID); 1527 + 1528 + /* Set every FID bit used by the (un)bridged ports */ 1529 + for (i = 0; i < ps->num_ports; ++i) { 1530 + err = _mv88e6xxx_port_fid_get(ds, i, fid); 1531 + if (err) 1532 + return err; 1533 + 1534 + set_bit(*fid, fid_bitmap); 1535 + } 1536 + 1537 + /* Set every FID bit used by the VLAN entries */ 1538 + err = _mv88e6xxx_vtu_vid_write(ds, GLOBAL_VTU_VID_MASK); 1539 + if (err) 1540 + return err; 1541 + 1542 + do { 1543 + err = _mv88e6xxx_vtu_getnext(ds, &vlan); 1544 + if (err) 1545 + return err; 1546 + 1547 + if (!vlan.valid) 1548 + break; 1549 + 1550 + set_bit(vlan.fid, fid_bitmap); 1551 + } while (vlan.vid < GLOBAL_VTU_VID_MASK); 1552 + 1553 + /* The reset value 0x000 is used to indicate that multiple address 1554 + * databases are not needed. Return the next positive available. 1555 + */ 1556 + *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1); 1557 + if (unlikely(*fid == MV88E6XXX_N_FID)) 1558 + return -ENOSPC; 1559 + 1560 + /* Clear the database */ 1561 + return _mv88e6xxx_atu_flush(ds, *fid, true); 1562 + } 1563 + 1564 + static int _mv88e6xxx_vtu_new(struct dsa_switch *ds, u16 vid, 1565 + struct mv88e6xxx_vtu_stu_entry *entry) 1483 1566 { 1484 1567 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); 1485 1568 struct mv88e6xxx_vtu_stu_entry vlan = { 1486 1569 .valid = true, 1487 1570 .vid = vid, 1488 - .fid = vid, /* We use one FID per VLAN */ 1489 1571 }; 1490 - int i; 1572 + int i, err; 1573 + 1574 + err = _mv88e6xxx_fid_new(ds, &vlan.fid); 1575 + if (err) 1576 + return err; 1491 1577 1492 1578 /* exclude all ports except the CPU and DSA ports */ 1493 1579 for (i = 0; i < ps->num_ports; ++i) ··· 1604 1478 if (mv88e6xxx_6097_family(ds) || mv88e6xxx_6165_family(ds) || 1605 1479 mv88e6xxx_6351_family(ds) || mv88e6xxx_6352_family(ds)) { 1606 1480 struct mv88e6xxx_vtu_stu_entry vstp; 1607 - int err; 1608 1481 1609 1482 /* Adding a VTU entry requires a valid STU entry. As VSTP is not 1610 1483 * implemented, only one STU entry is needed to cover all VTU ··· 1623 1498 if (err) 1624 1499 return err; 1625 1500 } 1626 - 1627 - /* Clear all MAC addresses from the new database */ 1628 - err = _mv88e6xxx_atu_flush(ds, vlan.fid, true); 1629 - if (err) 1630 - return err; 1631 1501 } 1632 1502 1633 1503 *entry = vlan; 1634 1504 return 0; 1505 + } 1506 + 1507 + static int _mv88e6xxx_vtu_get(struct dsa_switch *ds, u16 vid, 1508 + struct mv88e6xxx_vtu_stu_entry *entry, bool creat) 1509 + { 1510 + int err; 1511 + 1512 + if (!vid) 1513 + return -EINVAL; 1514 + 1515 + err = _mv88e6xxx_vtu_vid_write(ds, vid - 1); 1516 + if (err) 1517 + return err; 1518 + 1519 + err = _mv88e6xxx_vtu_getnext(ds, entry); 1520 + if (err) 1521 + return err; 1522 + 1523 + if (entry->vid != vid || !entry->valid) { 1524 + if (!creat) 1525 + return -EOPNOTSUPP; 1526 + /* -ENOENT would've been more appropriate, but switchdev expects 1527 + * -EOPNOTSUPP to inform bridge about an eventual software VLAN. 1528 + */ 1529 + 1530 + err = _mv88e6xxx_vtu_new(ds, vid, entry); 1531 + } 1532 + 1533 + return err; 1635 1534 } 1636 1535 1637 1536 static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port, ··· 1712 1563 return err; 1713 1564 } 1714 1565 1566 + static const char * const mv88e6xxx_port_8021q_mode_names[] = { 1567 + [PORT_CONTROL_2_8021Q_DISABLED] = "Disabled", 1568 + [PORT_CONTROL_2_8021Q_FALLBACK] = "Fallback", 1569 + [PORT_CONTROL_2_8021Q_CHECK] = "Check", 1570 + [PORT_CONTROL_2_8021Q_SECURE] = "Secure", 1571 + }; 1572 + 1573 + int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port, 1574 + bool vlan_filtering) 1575 + { 1576 + struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); 1577 + u16 old, new = vlan_filtering ? PORT_CONTROL_2_8021Q_SECURE : 1578 + PORT_CONTROL_2_8021Q_DISABLED; 1579 + int ret; 1580 + 1581 + mutex_lock(&ps->smi_mutex); 1582 + 1583 + ret = _mv88e6xxx_reg_read(ds, REG_PORT(port), PORT_CONTROL_2); 1584 + if (ret < 0) 1585 + goto unlock; 1586 + 1587 + old = ret & PORT_CONTROL_2_8021Q_MASK; 1588 + 1589 + ret &= ~PORT_CONTROL_2_8021Q_MASK; 1590 + ret |= new & PORT_CONTROL_2_8021Q_MASK; 1591 + 1592 + ret = _mv88e6xxx_reg_write(ds, REG_PORT(port), PORT_CONTROL_2, ret); 1593 + if (ret < 0) 1594 + goto unlock; 1595 + 1596 + netdev_dbg(ds->ports[port], "802.1Q Mode: %s (was %s)\n", 1597 + mv88e6xxx_port_8021q_mode_names[new], 1598 + mv88e6xxx_port_8021q_mode_names[old]); 1599 + unlock: 1600 + mutex_unlock(&ps->smi_mutex); 1601 + 1602 + return ret; 1603 + } 1604 + 1715 1605 int mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port, 1716 1606 const struct switchdev_obj_port_vlan *vlan, 1717 1607 struct switchdev_trans *trans) 1718 1608 { 1719 1609 int err; 1720 - 1721 - /* We reserve a few VLANs to isolate unbridged ports */ 1722 - if (vlan->vid_end >= 4000) 1723 - return -EOPNOTSUPP; 1724 1610 1725 1611 /* If the requested port doesn't belong to the same bridge as the VLAN 1726 1612 * members, do not support it (yet) and fallback to software VLAN. ··· 1777 1593 struct mv88e6xxx_vtu_stu_entry vlan; 1778 1594 int err; 1779 1595 1780 - err = _mv88e6xxx_vtu_vid_write(ds, vid - 1); 1596 + err = _mv88e6xxx_vtu_get(ds, vid, &vlan, true); 1781 1597 if (err) 1782 1598 return err; 1783 - 1784 - err = _mv88e6xxx_vtu_getnext(ds, &vlan); 1785 - if (err) 1786 - return err; 1787 - 1788 - if (vlan.vid != vid || !vlan.valid) { 1789 - err = _mv88e6xxx_vlan_init(ds, vid, &vlan); 1790 - if (err) 1791 - return err; 1792 - } 1793 1599 1794 1600 vlan.data[port] = untagged ? 1795 1601 GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED : ··· 1821 1647 struct mv88e6xxx_vtu_stu_entry vlan; 1822 1648 int i, err; 1823 1649 1824 - err = _mv88e6xxx_vtu_vid_write(ds, vid - 1); 1650 + err = _mv88e6xxx_vtu_get(ds, vid, &vlan, false); 1825 1651 if (err) 1826 1652 return err; 1827 1653 1828 - err = _mv88e6xxx_vtu_getnext(ds, &vlan); 1829 - if (err) 1830 - return err; 1831 - 1832 - if (vlan.vid != vid || !vlan.valid || 1833 - vlan.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER) 1654 + /* Tell switchdev if this VLAN is handled in software */ 1655 + if (vlan.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER) 1834 1656 return -EOPNOTSUPP; 1835 1657 1836 1658 vlan.data[port] = GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER; ··· 1854 1684 const struct switchdev_obj_port_vlan *vlan) 1855 1685 { 1856 1686 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); 1857 - const u16 defpvid = 4000 + ds->index * DSA_MAX_PORTS + port; 1858 1687 u16 pvid, vid; 1859 1688 int err = 0; 1860 1689 ··· 1869 1700 goto unlock; 1870 1701 1871 1702 if (vid == pvid) { 1872 - /* restore reserved VLAN ID */ 1873 - err = _mv88e6xxx_port_pvid_set(ds, port, defpvid); 1703 + err = _mv88e6xxx_port_pvid_set(ds, port, 0); 1874 1704 if (err) 1875 1705 goto unlock; 1876 1706 } ··· 1942 1774 u8 state) 1943 1775 { 1944 1776 struct mv88e6xxx_atu_entry entry = { 0 }; 1777 + struct mv88e6xxx_vtu_stu_entry vlan; 1778 + int err; 1945 1779 1946 - entry.fid = vid; /* We use one FID per VLAN */ 1780 + /* Null VLAN ID corresponds to the port private database */ 1781 + if (vid == 0) 1782 + err = _mv88e6xxx_port_fid_get(ds, port, &vlan.fid); 1783 + else 1784 + err = _mv88e6xxx_vtu_get(ds, vid, &vlan, false); 1785 + if (err) 1786 + return err; 1787 + 1788 + entry.fid = vlan.fid; 1947 1789 entry.state = state; 1948 1790 ether_addr_copy(entry.mac, addr); 1949 1791 if (state != GLOBAL_ATU_DATA_STATE_UNUSED) { ··· 1968 1790 const struct switchdev_obj_port_fdb *fdb, 1969 1791 struct switchdev_trans *trans) 1970 1792 { 1971 - /* We don't use per-port FDB */ 1972 - if (fdb->vid == 0) 1973 - return -EOPNOTSUPP; 1974 - 1975 1793 /* We don't need any dynamic resource from the kernel (yet), 1976 1794 * so skip the prepare phase. 1977 1795 */ ··· 2054 1880 return 0; 2055 1881 } 2056 1882 1883 + static int _mv88e6xxx_port_fdb_dump_one(struct dsa_switch *ds, u16 fid, u16 vid, 1884 + int port, 1885 + struct switchdev_obj_port_fdb *fdb, 1886 + int (*cb)(struct switchdev_obj *obj)) 1887 + { 1888 + struct mv88e6xxx_atu_entry addr = { 1889 + .mac = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, 1890 + }; 1891 + int err; 1892 + 1893 + err = _mv88e6xxx_atu_mac_write(ds, addr.mac); 1894 + if (err) 1895 + return err; 1896 + 1897 + do { 1898 + err = _mv88e6xxx_atu_getnext(ds, fid, &addr); 1899 + if (err) 1900 + break; 1901 + 1902 + if (addr.state == GLOBAL_ATU_DATA_STATE_UNUSED) 1903 + break; 1904 + 1905 + if (!addr.trunk && addr.portv_trunkid & BIT(port)) { 1906 + bool is_static = addr.state == 1907 + (is_multicast_ether_addr(addr.mac) ? 1908 + GLOBAL_ATU_DATA_STATE_MC_STATIC : 1909 + GLOBAL_ATU_DATA_STATE_UC_STATIC); 1910 + 1911 + fdb->vid = vid; 1912 + ether_addr_copy(fdb->addr, addr.mac); 1913 + fdb->ndm_state = is_static ? NUD_NOARP : NUD_REACHABLE; 1914 + 1915 + err = cb(&fdb->obj); 1916 + if (err) 1917 + break; 1918 + } 1919 + } while (!is_broadcast_ether_addr(addr.mac)); 1920 + 1921 + return err; 1922 + } 1923 + 2057 1924 int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port, 2058 1925 struct switchdev_obj_port_fdb *fdb, 2059 1926 int (*cb)(struct switchdev_obj *obj)) ··· 2103 1888 struct mv88e6xxx_vtu_stu_entry vlan = { 2104 1889 .vid = GLOBAL_VTU_VID_MASK, /* all ones */ 2105 1890 }; 1891 + u16 fid; 2106 1892 int err; 2107 1893 2108 1894 mutex_lock(&ps->smi_mutex); 2109 1895 1896 + /* Dump port's default Filtering Information Database (VLAN ID 0) */ 1897 + err = _mv88e6xxx_port_fid_get(ds, port, &fid); 1898 + if (err) 1899 + goto unlock; 1900 + 1901 + err = _mv88e6xxx_port_fdb_dump_one(ds, fid, 0, port, fdb, cb); 1902 + if (err) 1903 + goto unlock; 1904 + 1905 + /* Dump VLANs' Filtering Information Databases */ 2110 1906 err = _mv88e6xxx_vtu_vid_write(ds, vlan.vid); 2111 1907 if (err) 2112 1908 goto unlock; 2113 1909 2114 1910 do { 2115 - struct mv88e6xxx_atu_entry addr = { 2116 - .mac = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, 2117 - }; 2118 - 2119 1911 err = _mv88e6xxx_vtu_getnext(ds, &vlan); 2120 1912 if (err) 2121 - goto unlock; 1913 + break; 2122 1914 2123 1915 if (!vlan.valid) 2124 1916 break; 2125 1917 2126 - err = _mv88e6xxx_atu_mac_write(ds, addr.mac); 1918 + err = _mv88e6xxx_port_fdb_dump_one(ds, vlan.fid, vlan.vid, port, 1919 + fdb, cb); 2127 1920 if (err) 2128 - goto unlock; 2129 - 2130 - do { 2131 - err = _mv88e6xxx_atu_getnext(ds, vlan.fid, &addr); 2132 - if (err) 2133 - goto unlock; 2134 - 2135 - if (addr.state == GLOBAL_ATU_DATA_STATE_UNUSED) 2136 - break; 2137 - 2138 - if (!addr.trunk && addr.portv_trunkid & BIT(port)) { 2139 - bool is_static = addr.state == 2140 - (is_multicast_ether_addr(addr.mac) ? 2141 - GLOBAL_ATU_DATA_STATE_MC_STATIC : 2142 - GLOBAL_ATU_DATA_STATE_UC_STATIC); 2143 - 2144 - fdb->vid = vlan.vid; 2145 - ether_addr_copy(fdb->addr, addr.mac); 2146 - fdb->ndm_state = is_static ? NUD_NOARP : 2147 - NUD_REACHABLE; 2148 - 2149 - err = cb(&fdb->obj); 2150 - if (err) 2151 - goto unlock; 2152 - } 2153 - } while (!is_broadcast_ether_addr(addr.mac)); 2154 - 1921 + break; 2155 1922 } while (vlan.vid < GLOBAL_VTU_VID_MASK); 2156 1923 2157 1924 unlock: ··· 2146 1949 struct net_device *bridge) 2147 1950 { 2148 1951 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); 1952 + u16 fid; 1953 + int i, err; 2149 1954 1955 + mutex_lock(&ps->smi_mutex); 1956 + 1957 + /* Get or create the bridge FID and assign it to the port */ 1958 + for (i = 0; i < ps->num_ports; ++i) 1959 + if (ps->ports[i].bridge_dev == bridge) 1960 + break; 1961 + 1962 + if (i < ps->num_ports) 1963 + err = _mv88e6xxx_port_fid_get(ds, i, &fid); 1964 + else 1965 + err = _mv88e6xxx_fid_new(ds, &fid); 1966 + if (err) 1967 + goto unlock; 1968 + 1969 + err = _mv88e6xxx_port_fid_set(ds, port, fid); 1970 + if (err) 1971 + goto unlock; 1972 + 1973 + /* Assign the bridge and remap each port's VLANTable */ 2150 1974 ps->ports[port].bridge_dev = bridge; 2151 1975 2152 - return 0; 1976 + for (i = 0; i < ps->num_ports; ++i) { 1977 + if (ps->ports[i].bridge_dev == bridge) { 1978 + err = _mv88e6xxx_port_based_vlan_map(ds, i); 1979 + if (err) 1980 + break; 1981 + } 1982 + } 1983 + 1984 + unlock: 1985 + mutex_unlock(&ps->smi_mutex); 1986 + 1987 + return err; 2153 1988 } 2154 1989 2155 1990 int mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port) 2156 1991 { 2157 1992 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); 2158 - 2159 - ps->ports[port].bridge_dev = NULL; 2160 - 2161 - return 0; 2162 - } 2163 - 2164 - static int mv88e6xxx_setup_port_default_vlan(struct dsa_switch *ds, int port) 2165 - { 2166 - struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); 2167 - const u16 pvid = 4000 + ds->index * DSA_MAX_PORTS + port; 2168 - int err; 1993 + struct net_device *bridge = ps->ports[port].bridge_dev; 1994 + u16 fid; 1995 + int i, err; 2169 1996 2170 1997 mutex_lock(&ps->smi_mutex); 2171 - err = _mv88e6xxx_port_vlan_add(ds, port, pvid, true); 2172 - if (!err) 2173 - err = _mv88e6xxx_port_pvid_set(ds, port, pvid); 1998 + 1999 + /* Give the port a fresh Filtering Information Database */ 2000 + err = _mv88e6xxx_fid_new(ds, &fid); 2001 + if (err) 2002 + goto unlock; 2003 + 2004 + err = _mv88e6xxx_port_fid_set(ds, port, fid); 2005 + if (err) 2006 + goto unlock; 2007 + 2008 + /* Unassign the bridge and remap each port's VLANTable */ 2009 + ps->ports[port].bridge_dev = NULL; 2010 + 2011 + for (i = 0; i < ps->num_ports; ++i) { 2012 + if (i == port || ps->ports[i].bridge_dev == bridge) { 2013 + err = _mv88e6xxx_port_based_vlan_map(ds, i); 2014 + if (err) 2015 + break; 2016 + } 2017 + } 2018 + 2019 + unlock: 2174 2020 mutex_unlock(&ps->smi_mutex); 2021 + 2175 2022 return err; 2176 2023 } 2177 2024 ··· 2339 2098 } 2340 2099 2341 2100 /* Port Control 2: don't force a good FCS, set the maximum frame size to 2342 - * 10240 bytes, enable secure 802.1q tags, don't discard tagged or 2101 + * 10240 bytes, disable 802.1q tags checking, don't discard tagged or 2343 2102 * untagged frames on this port, do a destination address lookup on all 2344 2103 * received packets as usual, disable ARP mirroring and don't send a 2345 2104 * copy of all transmitted/received frames on this port to the CPU. ··· 2364 2123 reg |= PORT_CONTROL_2_FORWARD_UNKNOWN; 2365 2124 } 2366 2125 2367 - reg |= PORT_CONTROL_2_8021Q_SECURE; 2126 + reg |= PORT_CONTROL_2_8021Q_DISABLED; 2368 2127 2369 2128 if (reg) { 2370 2129 ret = _mv88e6xxx_reg_write(ds, REG_PORT(port), ··· 2461 2220 if (ret) 2462 2221 goto abort; 2463 2222 2464 - /* Port based VLAN map: do not give each port its own address 2465 - * database, and allow every port to egress frames on all other ports. 2223 + /* Port based VLAN map: give each port its own address 2224 + * database, and allow bidirectional communication between the 2225 + * CPU and DSA port(s), and the other ports. 2466 2226 */ 2467 - reg = BIT(ps->num_ports) - 1; /* all ports */ 2468 - reg &= ~BIT(port); /* except itself */ 2469 - ret = _mv88e6xxx_port_vlan_map_set(ds, port, reg); 2227 + ret = _mv88e6xxx_port_fid_set(ds, port, port + 1); 2228 + if (ret) 2229 + goto abort; 2230 + 2231 + ret = _mv88e6xxx_port_based_vlan_map(ds, port); 2470 2232 if (ret) 2471 2233 goto abort; 2472 2234 ··· 2491 2247 2492 2248 for (i = 0; i < ps->num_ports; i++) { 2493 2249 ret = mv88e6xxx_setup_port(ds, i); 2494 - if (ret < 0) 2495 - return ret; 2496 - 2497 - if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i)) 2498 - continue; 2499 - 2500 - ret = mv88e6xxx_setup_port_default_vlan(ds, i); 2501 2250 if (ret < 0) 2502 2251 return ret; 2503 2252 }
+6
drivers/net/dsa/mv88e6xxx.h
··· 133 133 #define PORT_CONTROL_STATE_LEARNING 0x02 134 134 #define PORT_CONTROL_STATE_FORWARDING 0x03 135 135 #define PORT_CONTROL_1 0x05 136 + #define PORT_CONTROL_1_FID_11_4_MASK (0xff << 0) 136 137 #define PORT_BASE_VLAN 0x06 138 + #define PORT_BASE_VLAN_FID_3_0_MASK (0xf << 12) 137 139 #define PORT_DEFAULT_VLAN 0x07 138 140 #define PORT_DEFAULT_VLAN_MASK 0xfff 139 141 #define PORT_CONTROL_2 0x08 ··· 357 355 #define GLOBAL2_QOS_WEIGHT 0x1c 358 356 #define GLOBAL2_MISC 0x1d 359 357 358 + #define MV88E6XXX_N_FID 4096 359 + 360 360 struct mv88e6xxx_switch_id { 361 361 u16 id; 362 362 char *name; ··· 490 486 struct net_device *bridge); 491 487 int mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port); 492 488 int mv88e6xxx_port_stp_update(struct dsa_switch *ds, int port, u8 state); 489 + int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port, 490 + bool vlan_filtering); 493 491 int mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port, 494 492 const struct switchdev_obj_port_vlan *vlan, 495 493 struct switchdev_trans *trans);
+2
include/net/dsa.h
··· 305 305 /* 306 306 * VLAN support 307 307 */ 308 + int (*port_vlan_filtering)(struct dsa_switch *ds, int port, 309 + bool vlan_filtering); 308 310 int (*port_vlan_prepare)(struct dsa_switch *ds, int port, 309 311 const struct switchdev_obj_port_vlan *vlan, 310 312 struct switchdev_trans *trans);
+21
net/dsa/slave.c
··· 317 317 return ret; 318 318 } 319 319 320 + static int dsa_slave_vlan_filtering(struct net_device *dev, 321 + const struct switchdev_attr *attr, 322 + struct switchdev_trans *trans) 323 + { 324 + struct dsa_slave_priv *p = netdev_priv(dev); 325 + struct dsa_switch *ds = p->parent; 326 + 327 + /* bridge skips -EOPNOTSUPP, so skip the prepare phase */ 328 + if (switchdev_trans_ph_prepare(trans)) 329 + return 0; 330 + 331 + if (ds->drv->port_vlan_filtering) 332 + return ds->drv->port_vlan_filtering(ds, p->port, 333 + attr->u.vlan_filtering); 334 + 335 + return 0; 336 + } 337 + 320 338 static int dsa_slave_port_attr_set(struct net_device *dev, 321 339 const struct switchdev_attr *attr, 322 340 struct switchdev_trans *trans) ··· 350 332 else 351 333 ret = ds->drv->port_stp_update(ds, p->port, 352 334 attr->u.stp_state); 335 + break; 336 + case SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING: 337 + ret = dsa_slave_vlan_filtering(dev, attr, trans); 353 338 break; 354 339 default: 355 340 ret = -EOPNOTSUPP;