]> git.baikalelectronics.ru Git - kernel.git/commitdiff
net: dsa: mv88e6xxx: factorize MAC address setting
authorVivien Didelot <vivien.didelot@savoirfairelinux.com>
Mon, 9 May 2016 17:22:43 +0000 (13:22 -0400)
committerDavid S. Miller <davem@davemloft.net>
Mon, 9 May 2016 18:26:09 +0000 (14:26 -0400)
Some switch models have a dedicated register for Switch MAC/WoF/WoL.
This register, when present, is used to indirectly set the switch MAC
address, instead of a direct write to 3 global registers.

Identify this feature and share a common mv88e6xxx_set_addr function.

Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/dsa/mv88e6123.c
drivers/net/dsa/mv88e6131.c
drivers/net/dsa/mv88e6171.c
drivers/net/dsa/mv88e6352.c
drivers/net/dsa/mv88e6xxx.c
drivers/net/dsa/mv88e6xxx.h

index e234bdbd9b423f01bc65fd9c4741f8dc6ef93090..c349fb7ec3f292ee28471bdec475988f16070104 100644 (file)
@@ -114,7 +114,7 @@ struct dsa_switch_driver mv88e6123_switch_driver = {
        .tag_protocol           = DSA_TAG_PROTO_EDSA,
        .probe                  = mv88e6123_drv_probe,
        .setup                  = mv88e6123_setup,
-       .set_addr               = mv88e6xxx_set_addr_indirect,
+       .set_addr               = mv88e6xxx_set_addr,
        .phy_read               = mv88e6xxx_phy_read,
        .phy_write              = mv88e6xxx_phy_write,
        .get_strings            = mv88e6xxx_get_strings,
index 089f9c05ea381dca59257f73b80970e2124ab194..1e040c6d663a1bf330984e02a36224b5efb652d7 100644 (file)
@@ -147,7 +147,7 @@ struct dsa_switch_driver mv88e6131_switch_driver = {
        .tag_protocol           = DSA_TAG_PROTO_DSA,
        .probe                  = mv88e6131_drv_probe,
        .setup                  = mv88e6131_setup,
-       .set_addr               = mv88e6xxx_set_addr_direct,
+       .set_addr               = mv88e6xxx_set_addr,
        .phy_read               = mv88e6xxx_phy_read,
        .phy_write              = mv88e6xxx_phy_write,
        .get_strings            = mv88e6xxx_get_strings,
index 588b48625af757d1792afcfc90f384586ff34186..f9b20e05b895abbe3e45d2015965f36d6a3bcb81 100644 (file)
@@ -123,7 +123,7 @@ struct dsa_switch_driver mv88e6171_switch_driver = {
        .tag_protocol           = DSA_TAG_PROTO_EDSA,
        .probe                  = mv88e6171_drv_probe,
        .setup                  = mv88e6171_setup,
-       .set_addr               = mv88e6xxx_set_addr_indirect,
+       .set_addr               = mv88e6xxx_set_addr,
        .phy_read               = mv88e6xxx_phy_read,
        .phy_write              = mv88e6xxx_phy_write,
        .get_strings            = mv88e6xxx_get_strings,
index 3bb271e16035ca8a41e2532fc3f96ddf424d1f03..d03c14a7ad1f1a14d1d5289c2dbce688c77ac29f 100644 (file)
@@ -140,7 +140,7 @@ struct dsa_switch_driver mv88e6352_switch_driver = {
        .tag_protocol           = DSA_TAG_PROTO_EDSA,
        .probe                  = mv88e6352_drv_probe,
        .setup                  = mv88e6352_setup,
-       .set_addr               = mv88e6xxx_set_addr_indirect,
+       .set_addr               = mv88e6xxx_set_addr,
        .phy_read               = mv88e6xxx_phy_read,
        .phy_write              = mv88e6xxx_phy_write,
        .get_strings            = mv88e6xxx_get_strings,
index 24aea900af35ec6613e57276fa102feedc3195fe..4f0e047538d2e23da535a3cbdf8be45d9a880157 100644 (file)
@@ -173,7 +173,7 @@ int mv88e6xxx_reg_write(struct mv88e6xxx_priv_state *ps, int addr,
        return ret;
 }
 
-int mv88e6xxx_set_addr_direct(struct dsa_switch *ds, u8 *addr)
+static int mv88e6xxx_set_addr_direct(struct dsa_switch *ds, u8 *addr)
 {
        struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
        int err;
@@ -192,7 +192,7 @@ int mv88e6xxx_set_addr_direct(struct dsa_switch *ds, u8 *addr)
                                   (addr[4] << 8) | addr[5]);
 }
 
-int mv88e6xxx_set_addr_indirect(struct dsa_switch *ds, u8 *addr)
+static int mv88e6xxx_set_addr_indirect(struct dsa_switch *ds, u8 *addr)
 {
        struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
        int ret;
@@ -225,6 +225,16 @@ int mv88e6xxx_set_addr_indirect(struct dsa_switch *ds, u8 *addr)
        return 0;
 }
 
+int mv88e6xxx_set_addr(struct dsa_switch *ds, u8 *addr)
+{
+       struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
+
+       if (mv88e6xxx_has(ps, MV88E6XXX_FLAG_SWITCH_MAC))
+               return mv88e6xxx_set_addr_indirect(ds, addr);
+       else
+               return mv88e6xxx_set_addr_direct(ds, addr);
+}
+
 static int _mv88e6xxx_phy_read(struct mv88e6xxx_priv_state *ps, int addr,
                               int regnum)
 {
index 9ddb6d04389ef85776c79236af8498a70fcfe706..517e95fbd10e6d3e112f307e210be91e359141ea 100644 (file)
@@ -367,6 +367,13 @@ enum mv88e6xxx_cap {
         */
        MV88E6XXX_CAP_SMI_PHY,
 
+       /* Switch MAC/WoL/WoF register.
+        * This requires an indirect access to set the switch MAC address
+        * through GLOBAL2_SWITCH_MAC, otherwise GLOBAL_MAC_01, GLOBAL_MAC_23,
+        * and GLOBAL_MAC_45 are used with a direct access.
+        */
+       MV88E6XXX_CAP_SWITCH_MAC_WOL_WOF,
+
        /* Internal temperature sensor.
         * Available from any enabled port's PHY register 26, page 6.
         */
@@ -378,6 +385,7 @@ enum mv88e6xxx_cap {
 #define MV88E6XXX_FLAG_EEPROM          BIT(MV88E6XXX_CAP_EEPROM)
 #define MV88E6XXX_FLAG_PPU             BIT(MV88E6XXX_CAP_PPU)
 #define MV88E6XXX_FLAG_SMI_PHY         BIT(MV88E6XXX_CAP_SMI_PHY)
+#define MV88E6XXX_FLAG_SWITCH_MAC      BIT(MV88E6XXX_CAP_SWITCH_MAC_WOL_WOF)
 #define MV88E6XXX_FLAG_TEMP            BIT(MV88E6XXX_CAP_TEMP)
 #define MV88E6XXX_FLAG_TEMP_LIMIT      BIT(MV88E6XXX_CAP_TEMP_LIMIT)
 
@@ -388,7 +396,8 @@ enum mv88e6xxx_cap {
        MV88E6XXX_FLAG_PPU
 
 #define MV88E6XXX_FLAGS_FAMILY_6165    \
-       MV88E6XXX_FLAG_TEMP
+       (MV88E6XXX_FLAG_SWITCH_MAC |    \
+        MV88E6XXX_FLAG_TEMP)
 
 #define MV88E6XXX_FLAGS_FAMILY_6185    \
        MV88E6XXX_FLAG_PPU
@@ -396,16 +405,19 @@ enum mv88e6xxx_cap {
 #define MV88E6XXX_FLAGS_FAMILY_6320    \
        (MV88E6XXX_FLAG_EEPROM |        \
         MV88E6XXX_FLAG_SMI_PHY |       \
+        MV88E6XXX_FLAG_SWITCH_MAC |    \
         MV88E6XXX_FLAG_TEMP |          \
         MV88E6XXX_FLAG_TEMP_LIMIT)
 
 #define MV88E6XXX_FLAGS_FAMILY_6351    \
        (MV88E6XXX_FLAG_SMI_PHY |       \
+        MV88E6XXX_FLAG_SWITCH_MAC |    \
         MV88E6XXX_FLAG_TEMP)
 
 #define MV88E6XXX_FLAGS_FAMILY_6352    \
        (MV88E6XXX_FLAG_EEPROM |        \
         MV88E6XXX_FLAG_SMI_PHY |       \
+        MV88E6XXX_FLAG_SWITCH_MAC |    \
         MV88E6XXX_FLAG_TEMP |          \
         MV88E6XXX_FLAG_TEMP_LIMIT)
 
@@ -525,8 +537,7 @@ int mv88e6xxx_setup_global(struct dsa_switch *ds);
 int mv88e6xxx_reg_read(struct mv88e6xxx_priv_state *ps, int addr, int reg);
 int mv88e6xxx_reg_write(struct mv88e6xxx_priv_state *ps, int addr,
                        int reg, u16 val);
-int mv88e6xxx_set_addr_direct(struct dsa_switch *ds, u8 *addr);
-int mv88e6xxx_set_addr_indirect(struct dsa_switch *ds, u8 *addr);
+int mv88e6xxx_set_addr(struct dsa_switch *ds, u8 *addr);
 int mv88e6xxx_phy_read(struct dsa_switch *ds, int port, int regnum);
 int mv88e6xxx_phy_write(struct dsa_switch *ds, int port, int regnum, u16 val);
 void mv88e6xxx_get_strings(struct dsa_switch *ds, int port, uint8_t *data);