Skip to content

Commit 1fe94f5

Browse files
rarun-mchpPaolo Abeni
authored andcommitted
net: dsa: microchip: move get_phy_flags & mtu to ksz_common
This patch assigns the get_phy_flags & mtu hook of ksz8795 and ksz9477 in dsa_switch_ops to ksz_common. For get_phy_flags hooks,checks whether the chip is ksz8863/kss8793 then it returns error for port1. Signed-off-by: Arun Ramadoss <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent e587be7 commit 1fe94f5

File tree

4 files changed

+52
-18
lines changed

4 files changed

+52
-18
lines changed

drivers/net/dsa/microchip/ksz8795.c

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -898,18 +898,6 @@ static void ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val)
898898
}
899899
}
900900

901-
static u32 ksz8_sw_get_phy_flags(struct dsa_switch *ds, int port)
902-
{
903-
/* Silicon Errata Sheet (DS80000830A):
904-
* Port 1 does not work with LinkMD Cable-Testing.
905-
* Port 1 does not respond to received PAUSE control frames.
906-
*/
907-
if (!port)
908-
return MICREL_KSZ8_P1_ERRATA;
909-
910-
return 0;
911-
}
912-
913901
static void ksz8_cfg_port_member(struct ksz_device *dev, int port, u8 member)
914902
{
915903
u8 data;
@@ -1470,7 +1458,7 @@ static void ksz8_get_caps(struct ksz_device *dev, int port,
14701458

14711459
static const struct dsa_switch_ops ksz8_switch_ops = {
14721460
.get_tag_protocol = ksz_get_tag_protocol,
1473-
.get_phy_flags = ksz8_sw_get_phy_flags,
1461+
.get_phy_flags = ksz_get_phy_flags,
14741462
.setup = ksz8_setup,
14751463
.phy_read = ksz_phy_read16,
14761464
.phy_write = ksz_phy_write16,

drivers/net/dsa/microchip/ksz9477.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@ static void ksz9477_port_cfg32(struct ksz_device *dev, int port, int offset,
4747
bits, set ? bits : 0);
4848
}
4949

50-
static int ksz9477_change_mtu(struct dsa_switch *ds, int port, int mtu)
50+
static int ksz9477_change_mtu(struct ksz_device *dev, int port, int mtu)
5151
{
52-
struct ksz_device *dev = ds->priv;
5352
u16 frame_size, max_frame = 0;
5453
int i;
5554

@@ -65,7 +64,7 @@ static int ksz9477_change_mtu(struct dsa_switch *ds, int port, int mtu)
6564
REG_SW_MTU_MASK, max_frame);
6665
}
6766

68-
static int ksz9477_max_mtu(struct dsa_switch *ds, int port)
67+
static int ksz9477_max_mtu(struct ksz_device *dev, int port)
6968
{
7069
return KSZ9477_MAX_FRAME_SIZE - VLAN_ETH_HLEN - ETH_FCS_LEN;
7170
}
@@ -1315,8 +1314,8 @@ static const struct dsa_switch_ops ksz9477_switch_ops = {
13151314
.port_mirror_add = ksz_port_mirror_add,
13161315
.port_mirror_del = ksz_port_mirror_del,
13171316
.get_stats64 = ksz_get_stats64,
1318-
.port_change_mtu = ksz9477_change_mtu,
1319-
.port_max_mtu = ksz9477_max_mtu,
1317+
.port_change_mtu = ksz_change_mtu,
1318+
.port_max_mtu = ksz_max_mtu,
13201319
};
13211320

13221321
static u32 ksz9477_get_port_addr(int port, int offset)
@@ -1399,6 +1398,8 @@ static const struct ksz_dev_ops ksz9477_dev_ops = {
13991398
.fdb_del = ksz9477_fdb_del,
14001399
.mdb_add = ksz9477_mdb_add,
14011400
.mdb_del = ksz9477_mdb_del,
1401+
.change_mtu = ksz9477_change_mtu,
1402+
.max_mtu = ksz9477_max_mtu,
14021403
.shutdown = ksz9477_reset_switch,
14031404
.init = ksz9477_switch_init,
14041405
.exit = ksz9477_switch_exit,

drivers/net/dsa/microchip/ksz_common.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/if_bridge.h>
1717
#include <linux/of_device.h>
1818
#include <linux/of_net.h>
19+
#include <linux/micrel_phy.h>
1920
#include <net/dsa.h>
2021
#include <net/switchdev.h>
2122

@@ -705,6 +706,23 @@ int ksz_phy_write16(struct dsa_switch *ds, int addr, int reg, u16 val)
705706
}
706707
EXPORT_SYMBOL_GPL(ksz_phy_write16);
707708

709+
u32 ksz_get_phy_flags(struct dsa_switch *ds, int port)
710+
{
711+
struct ksz_device *dev = ds->priv;
712+
713+
if (dev->chip_id == KSZ8830_CHIP_ID) {
714+
/* Silicon Errata Sheet (DS80000830A):
715+
* Port 1 does not work with LinkMD Cable-Testing.
716+
* Port 1 does not respond to received PAUSE control frames.
717+
*/
718+
if (!port)
719+
return MICREL_KSZ8_P1_ERRATA;
720+
}
721+
722+
return 0;
723+
}
724+
EXPORT_SYMBOL_GPL(ksz_get_phy_flags);
725+
708726
void ksz_mac_link_down(struct dsa_switch *ds, int port, unsigned int mode,
709727
phy_interface_t interface)
710728
{
@@ -984,6 +1002,28 @@ void ksz_port_mirror_del(struct dsa_switch *ds, int port,
9841002
}
9851003
EXPORT_SYMBOL_GPL(ksz_port_mirror_del);
9861004

1005+
int ksz_change_mtu(struct dsa_switch *ds, int port, int mtu)
1006+
{
1007+
struct ksz_device *dev = ds->priv;
1008+
1009+
if (!dev->dev_ops->change_mtu)
1010+
return -EOPNOTSUPP;
1011+
1012+
return dev->dev_ops->change_mtu(dev, port, mtu);
1013+
}
1014+
EXPORT_SYMBOL_GPL(ksz_change_mtu);
1015+
1016+
int ksz_max_mtu(struct dsa_switch *ds, int port)
1017+
{
1018+
struct ksz_device *dev = ds->priv;
1019+
1020+
if (!dev->dev_ops->max_mtu)
1021+
return -EOPNOTSUPP;
1022+
1023+
return dev->dev_ops->max_mtu(dev, port);
1024+
}
1025+
EXPORT_SYMBOL_GPL(ksz_max_mtu);
1026+
9871027
static int ksz_switch_detect(struct ksz_device *dev)
9881028
{
9891029
u8 id1, id2;

drivers/net/dsa/microchip/ksz_common.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ struct ksz_dev_ops {
200200
struct dsa_db db);
201201
void (*get_caps)(struct ksz_device *dev, int port,
202202
struct phylink_config *config);
203+
int (*change_mtu)(struct ksz_device *dev, int port, int mtu);
204+
int (*max_mtu)(struct ksz_device *dev, int port);
203205
void (*freeze_mib)(struct ksz_device *dev, int port, bool freeze);
204206
void (*port_init_cnt)(struct ksz_device *dev, int port);
205207
int (*shutdown)(struct ksz_device *dev);
@@ -227,6 +229,7 @@ extern const struct ksz_chip_data ksz_switch_chips[];
227229

228230
int ksz_phy_read16(struct dsa_switch *ds, int addr, int reg);
229231
int ksz_phy_write16(struct dsa_switch *ds, int addr, int reg, u16 val);
232+
u32 ksz_get_phy_flags(struct dsa_switch *ds, int port);
230233
void ksz_mac_link_down(struct dsa_switch *ds, int port, unsigned int mode,
231234
phy_interface_t interface);
232235
int ksz_sset_count(struct dsa_switch *ds, int port, int sset);
@@ -267,6 +270,8 @@ int ksz_port_mirror_add(struct dsa_switch *ds, int port,
267270
bool ingress, struct netlink_ext_ack *extack);
268271
void ksz_port_mirror_del(struct dsa_switch *ds, int port,
269272
struct dsa_mall_mirror_tc_entry *mirror);
273+
int ksz_change_mtu(struct dsa_switch *ds, int port, int mtu);
274+
int ksz_max_mtu(struct dsa_switch *ds, int port);
270275

271276
/* Common register access functions */
272277

0 commit comments

Comments
 (0)