aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVivien Didelot <vivien.didelot@savoirfairelinux.com>2016-09-29 12:21:57 -0400
committerDavid S. Miller <davem@davemloft.net>2016-09-30 01:25:59 -0400
commit370b4ffbd8dda2b1a61dc63a5ac3088d8e715d53 (patch)
tree94e29e0aa13072f2d581f6423c90054300a50714
parentde33376b39b6ea939d53ea44c8c6595b80826501 (diff)
net: dsa: mv88e6xxx: add mv88e6xxx_num_ports helper
Add an mv88e6xxx_num_ports helper instead of digging in the chip info structure. Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/dsa/mv88e6xxx/chip.c30
-rw-r--r--drivers/net/dsa/mv88e6xxx/global2.c8
-rw-r--r--drivers/net/dsa/mv88e6xxx/mv88e6xxx.h5
3 files changed, 24 insertions, 19 deletions
diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c
index 6a55bba943c3..9056d9eb3c13 100644
--- a/drivers/net/dsa/mv88e6xxx/chip.c
+++ b/drivers/net/dsa/mv88e6xxx/chip.c
@@ -613,7 +613,7 @@ static void mv88e6xxx_adjust_link(struct dsa_switch *ds, int port,
613 reg |= PORT_PCS_CTRL_DUPLEX_FULL; 613 reg |= PORT_PCS_CTRL_DUPLEX_FULL;
614 614
615 if ((mv88e6xxx_6352_family(chip) || mv88e6xxx_6351_family(chip)) && 615 if ((mv88e6xxx_6352_family(chip) || mv88e6xxx_6351_family(chip)) &&
616 (port >= chip->info->num_ports - 2)) { 616 (port >= mv88e6xxx_num_ports(chip) - 2)) {
617 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) 617 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID)
618 reg |= PORT_PCS_CTRL_RGMII_DELAY_RXCLK; 618 reg |= PORT_PCS_CTRL_RGMII_DELAY_RXCLK;
619 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) 619 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID)
@@ -1112,7 +1112,7 @@ static int _mv88e6xxx_port_state(struct mv88e6xxx_chip *chip, int port,
1112static int _mv88e6xxx_port_based_vlan_map(struct mv88e6xxx_chip *chip, int port) 1112static int _mv88e6xxx_port_based_vlan_map(struct mv88e6xxx_chip *chip, int port)
1113{ 1113{
1114 struct net_device *bridge = chip->ports[port].bridge_dev; 1114 struct net_device *bridge = chip->ports[port].bridge_dev;
1115 const u16 mask = (1 << chip->info->num_ports) - 1; 1115 const u16 mask = (1 << mv88e6xxx_num_ports(chip)) - 1;
1116 struct dsa_switch *ds = chip->ds; 1116 struct dsa_switch *ds = chip->ds;
1117 u16 output_ports = 0; 1117 u16 output_ports = 0;
1118 u16 reg; 1118 u16 reg;
@@ -1123,7 +1123,7 @@ static int _mv88e6xxx_port_based_vlan_map(struct mv88e6xxx_chip *chip, int port)
1123 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)) { 1123 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)) {
1124 output_ports = mask; 1124 output_ports = mask;
1125 } else { 1125 } else {
1126 for (i = 0; i < chip->info->num_ports; ++i) { 1126 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1127 /* allow sending frames to every group member */ 1127 /* allow sending frames to every group member */
1128 if (bridge && chip->ports[i].bridge_dev == bridge) 1128 if (bridge && chip->ports[i].bridge_dev == bridge)
1129 output_ports |= BIT(i); 1129 output_ports |= BIT(i);
@@ -1279,7 +1279,7 @@ static int _mv88e6xxx_vtu_stu_data_read(struct mv88e6xxx_chip *chip,
1279 return err; 1279 return err;
1280 } 1280 }
1281 1281
1282 for (i = 0; i < chip->info->num_ports; ++i) { 1282 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1283 unsigned int shift = (i % 4) * 4 + nibble_offset; 1283 unsigned int shift = (i % 4) * 4 + nibble_offset;
1284 u16 reg = regs[i / 4]; 1284 u16 reg = regs[i / 4];
1285 1285
@@ -1308,7 +1308,7 @@ static int _mv88e6xxx_vtu_stu_data_write(struct mv88e6xxx_chip *chip,
1308 u16 regs[3] = { 0 }; 1308 u16 regs[3] = { 0 };
1309 int i, err; 1309 int i, err;
1310 1310
1311 for (i = 0; i < chip->info->num_ports; ++i) { 1311 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1312 unsigned int shift = (i % 4) * 4 + nibble_offset; 1312 unsigned int shift = (i % 4) * 4 + nibble_offset;
1313 u8 data = entry->data[i]; 1313 u8 data = entry->data[i];
1314 1314
@@ -1658,7 +1658,7 @@ static int _mv88e6xxx_fid_new(struct mv88e6xxx_chip *chip, u16 *fid)
1658 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID); 1658 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1659 1659
1660 /* Set every FID bit used by the (un)bridged ports */ 1660 /* Set every FID bit used by the (un)bridged ports */
1661 for (i = 0; i < chip->info->num_ports; ++i) { 1661 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1662 err = _mv88e6xxx_port_fid_get(chip, i, fid); 1662 err = _mv88e6xxx_port_fid_get(chip, i, fid);
1663 if (err) 1663 if (err)
1664 return err; 1664 return err;
@@ -1708,7 +1708,7 @@ static int _mv88e6xxx_vtu_new(struct mv88e6xxx_chip *chip, u16 vid,
1708 return err; 1708 return err;
1709 1709
1710 /* exclude all ports except the CPU and DSA ports */ 1710 /* exclude all ports except the CPU and DSA ports */
1711 for (i = 0; i < chip->info->num_ports; ++i) 1711 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
1712 vlan.data[i] = dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i) 1712 vlan.data[i] = dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i)
1713 ? GLOBAL_VTU_DATA_MEMBER_TAG_UNMODIFIED 1713 ? GLOBAL_VTU_DATA_MEMBER_TAG_UNMODIFIED
1714 : GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER; 1714 : GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
@@ -1797,7 +1797,7 @@ static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
1797 if (vlan.vid > vid_end) 1797 if (vlan.vid > vid_end)
1798 break; 1798 break;
1799 1799
1800 for (i = 0; i < chip->info->num_ports; ++i) { 1800 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1801 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i)) 1801 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1802 continue; 1802 continue;
1803 1803
@@ -1959,7 +1959,7 @@ static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
1959 1959
1960 /* keep the VLAN unless all ports are excluded */ 1960 /* keep the VLAN unless all ports are excluded */
1961 vlan.valid = false; 1961 vlan.valid = false;
1962 for (i = 0; i < chip->info->num_ports; ++i) { 1962 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1963 if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i)) 1963 if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i))
1964 continue; 1964 continue;
1965 1965
@@ -2340,7 +2340,7 @@ static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
2340 /* Assign the bridge and remap each port's VLANTable */ 2340 /* Assign the bridge and remap each port's VLANTable */
2341 chip->ports[port].bridge_dev = bridge; 2341 chip->ports[port].bridge_dev = bridge;
2342 2342
2343 for (i = 0; i < chip->info->num_ports; ++i) { 2343 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
2344 if (chip->ports[i].bridge_dev == bridge) { 2344 if (chip->ports[i].bridge_dev == bridge) {
2345 err = _mv88e6xxx_port_based_vlan_map(chip, i); 2345 err = _mv88e6xxx_port_based_vlan_map(chip, i);
2346 if (err) 2346 if (err)
@@ -2364,7 +2364,7 @@ static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port)
2364 /* Unassign the bridge and remap each port's VLANTable */ 2364 /* Unassign the bridge and remap each port's VLANTable */
2365 chip->ports[port].bridge_dev = NULL; 2365 chip->ports[port].bridge_dev = NULL;
2366 2366
2367 for (i = 0; i < chip->info->num_ports; ++i) 2367 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
2368 if (i == port || chip->ports[i].bridge_dev == bridge) 2368 if (i == port || chip->ports[i].bridge_dev == bridge)
2369 if (_mv88e6xxx_port_based_vlan_map(chip, i)) 2369 if (_mv88e6xxx_port_based_vlan_map(chip, i))
2370 netdev_warn(ds->ports[i].netdev, 2370 netdev_warn(ds->ports[i].netdev,
@@ -2384,7 +2384,7 @@ static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
2384 int i; 2384 int i;
2385 2385
2386 /* Set all ports to the disabled state. */ 2386 /* Set all ports to the disabled state. */
2387 for (i = 0; i < chip->info->num_ports; i++) { 2387 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2388 err = mv88e6xxx_port_read(chip, i, PORT_CONTROL, &reg); 2388 err = mv88e6xxx_port_read(chip, i, PORT_CONTROL, &reg);
2389 if (err) 2389 if (err)
2390 return err; 2390 return err;
@@ -2885,7 +2885,7 @@ static int mv88e6xxx_setup(struct dsa_switch *ds)
2885 goto unlock; 2885 goto unlock;
2886 2886
2887 /* Setup Switch Port Registers */ 2887 /* Setup Switch Port Registers */
2888 for (i = 0; i < chip->info->num_ports; i++) { 2888 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2889 err = mv88e6xxx_setup_port(chip, i); 2889 err = mv88e6xxx_setup_port(chip, i);
2890 if (err) 2890 if (err)
2891 goto unlock; 2891 goto unlock;
@@ -2933,7 +2933,7 @@ static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
2933 u16 val; 2933 u16 val;
2934 int err; 2934 int err;
2935 2935
2936 if (phy >= chip->info->num_ports) 2936 if (phy >= mv88e6xxx_num_ports(chip))
2937 return 0xffff; 2937 return 0xffff;
2938 2938
2939 mutex_lock(&chip->reg_lock); 2939 mutex_lock(&chip->reg_lock);
@@ -2948,7 +2948,7 @@ static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
2948 struct mv88e6xxx_chip *chip = bus->priv; 2948 struct mv88e6xxx_chip *chip = bus->priv;
2949 int err; 2949 int err;
2950 2950
2951 if (phy >= chip->info->num_ports) 2951 if (phy >= mv88e6xxx_num_ports(chip))
2952 return 0xffff; 2952 return 0xffff;
2953 2953
2954 mutex_lock(&chip->reg_lock); 2954 mutex_lock(&chip->reg_lock);
diff --git a/drivers/net/dsa/mv88e6xxx/global2.c b/drivers/net/dsa/mv88e6xxx/global2.c
index f31d553c7448..cf686e7506a9 100644
--- a/drivers/net/dsa/mv88e6xxx/global2.c
+++ b/drivers/net/dsa/mv88e6xxx/global2.c
@@ -74,7 +74,7 @@ static int mv88e6xxx_g2_set_device_mapping(struct mv88e6xxx_chip *chip)
74static int mv88e6xxx_g2_trunk_mask_write(struct mv88e6xxx_chip *chip, int num, 74static int mv88e6xxx_g2_trunk_mask_write(struct mv88e6xxx_chip *chip, int num,
75 bool hask, u16 mask) 75 bool hask, u16 mask)
76{ 76{
77 const u16 port_mask = BIT(chip->info->num_ports) - 1; 77 const u16 port_mask = BIT(mv88e6xxx_num_ports(chip)) - 1;
78 u16 val = (num << 12) | (mask & port_mask); 78 u16 val = (num << 12) | (mask & port_mask);
79 79
80 if (hask) 80 if (hask)
@@ -88,7 +88,7 @@ static int mv88e6xxx_g2_trunk_mask_write(struct mv88e6xxx_chip *chip, int num,
88static int mv88e6xxx_g2_trunk_mapping_write(struct mv88e6xxx_chip *chip, int id, 88static int mv88e6xxx_g2_trunk_mapping_write(struct mv88e6xxx_chip *chip, int id,
89 u16 map) 89 u16 map)
90{ 90{
91 const u16 port_mask = BIT(chip->info->num_ports) - 1; 91 const u16 port_mask = BIT(mv88e6xxx_num_ports(chip)) - 1;
92 u16 val = (id << 11) | (map & port_mask); 92 u16 val = (id << 11) | (map & port_mask);
93 93
94 return mv88e6xxx_g2_update(chip, GLOBAL2_TRUNK_MAPPING, val); 94 return mv88e6xxx_g2_update(chip, GLOBAL2_TRUNK_MAPPING, val);
@@ -96,7 +96,7 @@ static int mv88e6xxx_g2_trunk_mapping_write(struct mv88e6xxx_chip *chip, int id,
96 96
97static int mv88e6xxx_g2_clear_trunk(struct mv88e6xxx_chip *chip) 97static int mv88e6xxx_g2_clear_trunk(struct mv88e6xxx_chip *chip)
98{ 98{
99 const u16 port_mask = BIT(chip->info->num_ports) - 1; 99 const u16 port_mask = BIT(mv88e6xxx_num_ports(chip)) - 1;
100 int i, err; 100 int i, err;
101 101
102 /* Clear all eight possible Trunk Mask vectors */ 102 /* Clear all eight possible Trunk Mask vectors */
@@ -125,7 +125,7 @@ static int mv88e6xxx_g2_clear_irl(struct mv88e6xxx_chip *chip)
125 int port, err; 125 int port, err;
126 126
127 /* Init all Ingress Rate Limit resources of all ports */ 127 /* Init all Ingress Rate Limit resources of all ports */
128 for (port = 0; port < chip->info->num_ports; ++port) { 128 for (port = 0; port < mv88e6xxx_num_ports(chip); ++port) {
129 /* XXX newer chips (like 88E6390) have different 2-bit ops */ 129 /* XXX newer chips (like 88E6390) have different 2-bit ops */
130 err = mv88e6xxx_g2_write(chip, GLOBAL2_IRL_CMD, 130 err = mv88e6xxx_g2_write(chip, GLOBAL2_IRL_CMD,
131 GLOBAL2_IRL_CMD_OP_INIT_ALL | 131 GLOBAL2_IRL_CMD_OP_INIT_ALL |
diff --git a/drivers/net/dsa/mv88e6xxx/mv88e6xxx.h b/drivers/net/dsa/mv88e6xxx/mv88e6xxx.h
index 20fe6c61d5a7..cf639ed91d03 100644
--- a/drivers/net/dsa/mv88e6xxx/mv88e6xxx.h
+++ b/drivers/net/dsa/mv88e6xxx/mv88e6xxx.h
@@ -737,6 +737,11 @@ static inline unsigned int mv88e6xxx_num_databases(struct mv88e6xxx_chip *chip)
737 return chip->info->num_databases; 737 return chip->info->num_databases;
738} 738}
739 739
740static inline unsigned int mv88e6xxx_num_ports(struct mv88e6xxx_chip *chip)
741{
742 return chip->info->num_ports;
743}
744
740int mv88e6xxx_read(struct mv88e6xxx_chip *chip, int addr, int reg, u16 *val); 745int mv88e6xxx_read(struct mv88e6xxx_chip *chip, int addr, int reg, u16 *val);
741int mv88e6xxx_write(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val); 746int mv88e6xxx_write(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val);
742int mv88e6xxx_update(struct mv88e6xxx_chip *chip, int addr, int reg, 747int mv88e6xxx_update(struct mv88e6xxx_chip *chip, int addr, int reg,