net: dsa: microchip: Add KSZ8463 switch support
Subsystems (5)
v6 cover net: dsa: microchip: Add KSZ8463 switch support
From: Tristram Ha <[email protected]>
This series of patches is to add KSZ8463 switch support to the KSZ DSA driver.
v6
- Set use_single_read and use_single_write so that 64-bit access works
- Change register values for big-endian system if necessary
v5
- Use separate SPI read and write functions for KSZ8463
- remove inline keyword inside ksz8.c
v4
- Fix a typo in ksz8_reg.h
- Fix logic in ksz8463_r_phy()
v3
- Replace cpu_to_be16() with swab16() to avoid compiler warning
- Disable PTP function in a separate patch
v2
- Break the KSZ8463 driver code into several patches for easy review
- Replace ntohs with cpu_to_be16
Tristram Ha (6):
dt-bindings: net: dsa: microchip: Add KSZ8463 switch support
net: dsa: microchip: Add KSZ8463 switch support to KSZ DSA driver
net: dsa: microchip: Use different registers for KSZ8463
net: dsa: microchip: Write switch MAC address differently for KSZ8463
net: dsa: microchip: Setup fiber ports for KSZ8463
net: dsa: microchip: Disable PTP function of KSZ8463
.../bindings/net/dsa/microchip,ksz.yaml | 1 + drivers/net/dsa/microchip/ksz8.c | 188 ++++++++++++++++-- drivers/net/dsa/microchip/ksz8.h | 4 + drivers/net/dsa/microchip/ksz8_reg.h | 49 +++++ drivers/net/dsa/microchip/ksz_common.c | 160 ++++++++++++++- drivers/net/dsa/microchip/ksz_common.h | 37 +++- drivers/net/dsa/microchip/ksz_dcb.c | 10 +- drivers/net/dsa/microchip/ksz_spi.c | 104 ++++++++++ include/linux/platform_data/microchip-ksz.h | 1 + 9 files changed, 522 insertions(+), 32 deletions(-)
Signature · 1 line
2.34.1
PATCH v6 1/6 dt-bindings: net: dsa: microchip: Add KSZ8463 switch support
From: Tristram Ha <[email protected]>
KSZ8463 switch is a 3-port switch based from KSZ8863. Its register access is significantly different from the other KSZ SPI switches.
--- Documentation/devicetree/bindings/net/dsa/microchip,ksz.yaml | 1 + 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/net/dsa/microchip,ksz.yaml +1 -0
@@ -18,6 +18,7 @@ properties: # required and optional properties. compatible: enum: + - microchip,ksz8463 - microchip,ksz8765 - microchip,ksz8794 - microchip,ksz8795
Signature · 1 line
2.34.1
PATCH v6 2/6 net: dsa: microchip: Add KSZ8463 switch support to KSZ DSA driver
In reply to [email protected]From: Tristram Ha <[email protected]>
KSZ8463 switch is a 3-port switch based from KSZ8863. Its major difference from other KSZ SPI switches is its register access is not a simple continual 8-bit transfer with automatic address increase but uses a byte-enable mechanism specifying 8-bit, 16-bit, or 32-bit access. Its registers are also defined in 16-bit format because it shares a design with a MAC controller using 16-bit access. As a result some common register accesses need to be re-arranged.
This patch adds the basic structure for using KSZ8463. It cannot use the same regmap table for other KSZ switches as it interprets the 16-bit value as little-endian and its SPI commands are different.
KSZ8463 uses a byte-enable mechanism to specify 8-bit, 16-bit, and 32-bit access. The register is first shifted right by 2 then left by 4. Extra 4 bits are added. If the access is 8-bit one of the 4 bits is set. If the access is 16-bit two of the 4 bits are set. If the access is 32-bit all 4 bits are set. The SPI command for read or write is then added.
Because of this register transformation separate SPI read and write functions are provided for KSZ8463.
KSZ8463's internal PHYs use standard PHY register definitions so there is no need to remap things. However, the hardware has a bug that the high word and low word of the PHY id are swapped. In addition the port registers are arranged differently so KSZ8463 has its own mapping for port registers and PHY registers. Therefore the PORT_CTRL_ADDR macro is replaced with the get_port_addr helper function.
---
v6
- Set use_single_read and use_single_write so that 64-bit access works
- Change register values for big-endian system if necessary
v5
- Use separate SPI read and write functions for KSZ8463
- remove inline keyword inside ksz8.c
v4
- Fix a typo in ksz8_reg.h
- Fix logic in ksz8463_r_phy()
drivers/net/dsa/microchip/ksz8.c | 83 +++++++++++++- drivers/net/dsa/microchip/ksz8.h | 4 + drivers/net/dsa/microchip/ksz8_reg.h | 49 +++++++++ drivers/net/dsa/microchip/ksz_common.c | 114 ++++++++++++++++++++ drivers/net/dsa/microchip/ksz_common.h | 37 ++++++- drivers/net/dsa/microchip/ksz_spi.c | 104 ++++++++++++++++++ include/linux/platform_data/microchip-ksz.h | 1 + 7 files changed, 389 insertions(+), 3 deletions(-)
drivers/net/dsa/microchip/ksz8.c +82 -1
@@ -3,6 +3,7 @@* Microchip KSZ8XXX series switch driver * * It supports the following switches: +* - KSZ8463 * - KSZ8863, KSZ8873 aka KSZ88X3 * - KSZ8895, KSZ8864 aka KSZ8895 family * - KSZ8794, KSZ8795, KSZ8765 aka KSZ87XX
@@ -41,7 +42,8 @@ static void ksz_cfg(struct ksz_device *dev, u32 addr, u8 bits, bool set)static void ksz_port_cfg (struct ksz_device *dev,int port,int offset,u8 bits,bool set) { -regmap_update_bits (ksz_regmap_8 (dev),PORT_CTRL_ADDR (port, offset), +regmap_update_bits (ksz_regmap_8 (dev), + dev->dev_ops->get_port_addr (port, offset), bits, set ? bits :0 ); }
@@ -194,6 +196,7 @@ int ksz8_change_mtu(struct ksz_device *dev, int port, int mtu)case KSZ8794_CHIP_ID :case KSZ8765_CHIP_ID :return ksz8795_change_mtu (dev, frame_size); +case KSZ8463_CHIP_ID :case KSZ88X3_CHIP_ID :case KSZ8864_CHIP_ID :case KSZ8895_CHIP_ID :
@@ -1947,6 +1950,84 @@ u32 ksz8_get_port_addr(int port, int offset)return PORT_CTRL_ADDR (port, offset); } +u32 ksz8463_get_port_addr (int port,int offset) +{ +return offset +0x18 * port; +} + +static u16 ksz8463_get_phy_addr (u16 phy,u16 reg,u16 offset) +{ +return offset + reg *2 + phy * (P2MBCR -P1MBCR ); +} + +int ksz8463_r_phy (struct ksz_device *dev,u16 phy,u16 reg,u16 *val) +{ +u16 sw_reg =0 ; +u16 data =0 ; +int ret; + +if (phy >1 ) +return -ENOSPC ; +switch (reg) { +case MII_PHYSID1 : + sw_reg =ksz8463_get_phy_addr (phy,0 ,PHY1IHR ); +break ; +case MII_PHYSID2 : + sw_reg =ksz8463_get_phy_addr (phy,0 ,PHY1ILR ); +break ; +case MII_BMCR : +case MII_BMSR : +case MII_ADVERTISE : +case MII_LPA : + sw_reg =ksz8463_get_phy_addr (phy, reg,P1MBCR ); +break ; +case MII_TPISTATUS : +/* This register holds the PHY interrupt status for simulated +* Micrel KSZ PHY. +*/ + data =0x0505 ; +break ; +default : +break ; + } +if (sw_reg) { + ret =ksz_read16 (dev, sw_reg, &data); +if (ret) +return ret; + } + *val = data; + +return 0 ; +} + +int ksz8463_w_phy (struct ksz_device *dev,u16 phy,u16 reg,u16 val) +{ +u16 sw_reg =0 ; +int ret; + +if (phy >1 ) +return -ENOSPC ; + +/* No write to fiber port. */ +if (dev->ports[phy].fiber) +return 0 ; +switch (reg) { +case MII_BMCR : +case MII_ADVERTISE : + sw_reg =ksz8463_get_phy_addr (phy, reg,P1MBCR ); +break ; +default : +break ; + } +if (sw_reg) { + ret =ksz_write16 (dev, sw_reg, val); +if (ret) +return ret; + } + +return 0 ; +} +int ksz8_switch_init (struct ksz_device *dev) { dev->cpu_port =fls (dev->info->cpu_ports) -1 ;
drivers/net/dsa/microchip/ksz8.h +4 -0
@@ -63,4 +63,8 @@ void ksz8_phylink_mac_link_up(struct phylink_config *config, bool tx_pause, bool rx_pause);int ksz8_all_queues_split (struct ksz_device *dev,int queues); +u32 ksz8463_get_port_addr (int port,int offset); +int ksz8463_r_phy (struct ksz_device *dev,u16 phy,u16 reg,u16 *val); +int ksz8463_w_phy (struct ksz_device *dev,u16 phy,u16 reg,u16 val); +#endif
drivers/net/dsa/microchip/ksz8_reg.h +49 -0
55 lines not on this page · raw message
drivers/net/dsa/microchip/ksz_common.c +114 -0
150 lines not on this page · raw message
drivers/net/dsa/microchip/ksz_common.h +35 -2
@@ -222,6 +222,7 @@ struct ksz_device {/* List of supported models */ enum ksz_model { +KSZ8463 ,KSZ8563 ,KSZ8567 ,KSZ8795 ,
@@ -484,6 +485,11 @@ static inline struct regmap *ksz_regmap_32(struct ksz_device *dev)return dev->regmap[KSZ_REGMAP_32 ]; } +static inline bool ksz_is_ksz8463 (struct ksz_device *dev) +{ +return dev->chip_id ==KSZ8463_CHIP_ID ; +} +static inline int ksz_read8 (struct ksz_device *dev,u32 reg,u8 *val) {unsigned int value;
@@ -709,12 +715,13 @@ static inline bool ksz_is_8895_family(struct ksz_device *dev)static inline bool is_ksz8 (struct ksz_device *dev) {return ksz_is_ksz87xx (dev) ||ksz_is_ksz88x3 (dev) || -ksz_is_8895_family (dev); +ksz_is_8895_family (dev) ||ksz_is_ksz8463 (dev); }static inline bool is_ksz88xx (struct ksz_device *dev) { -return ksz_is_ksz88x3 (dev) ||ksz_is_8895_family (dev); +return ksz_is_ksz88x3 (dev) ||ksz_is_8895_family (dev) || +ksz_is_ksz8463 (dev); }static inline bool is_ksz9477 (struct ksz_device *dev)
@@ -761,6 +768,7 @@ static inline bool ksz_is_sgmii_port(struct ksz_device *dev, int port)#define REG_CHIP_ID0 0x00#define SW_FAMILY_ID_M GENMASK(15, 8) +#define KSZ84_FAMILY_ID 0x84#define KSZ87_FAMILY_ID 0x87#define KSZ88_FAMILY_ID 0x88#define KSZ8895_FAMILY_ID 0x95
@@ -939,4 +947,29 @@ static inline bool ksz_is_sgmii_port(struct ksz_device *dev, int port) [KSZ_REGMAP_32] = KSZ_REGMAP_ENTRY(32, swp, (regbits), (regpad), (regalign)), \ } +#define KSZ8463_REGMAP_ENTRY(width, regbits, regpad, regalign) \ + { \ + .name = #width, \ + .val_bits = (width), \ + .reg_stride = (width / 8), \ + .reg_bits = (regbits) + (regalign), \ + .pad_bits = (regpad), \ + .read = ksz8463_spi_read, \ + .write = ksz8463_spi_write, \ + .max_register = BIT(regbits) - 1, \ + .cache_type = REGCACHE_NONE, \ + .zero_flag_mask = 1, \ + .use_single_read = 1, \ + .use_single_write = 1, \ + .lock = ksz_regmap_lock, \ + .unlock = ksz_regmap_unlock, \ + } + +#define KSZ8463_REGMAP_TABLE (ksz, regbits, regpad, regalign) \ + static const struct regmap_config ksz##_regmap_config[] = { \ + [KSZ_REGMAP_8] = KSZ8463_REGMAP_ENTRY(8, (regbits), (regpad), (regalign)), \ + [KSZ_REGMAP_16] = KSZ8463_REGMAP_ENTRY(16, (regbits), (regpad), (regalign)), \ + [KSZ_REGMAP_32] = KSZ8463_REGMAP_ENTRY(32, (regbits), (regpad), (regalign)), \ + } +#endif
drivers/net/dsa/microchip/ksz_spi.c +104 -0
134 lines not on this page · raw message
include/linux/platform_data/microchip-ksz.h +1 -0
@@ -23,6 +23,7 @@#include <linux/platform_data/dsa.h> enum ksz_chip_id { +KSZ8463_CHIP_ID =0x8463 ,KSZ8563_CHIP_ID =0x8563 ,KSZ8795_CHIP_ID =0x8795 ,KSZ8794_CHIP_ID =0x8794 ,
Signature · 1 line
2.34.1
Re: [PATCH net-next v6 2/6] net: dsa: microchip: Add KSZ8463 switch support to KSZ DSA driver
Quoted 24 lines · On Thu, Jul 24, 2025 at 05:17:49PM -0700, [email protected] wrote:
From: Tristram Ha <[email protected]>
KSZ8463 switch is a 3-port switch based from KSZ8863. Its major difference from other KSZ SPI switches is its register access is not a simple continual 8-bit transfer with automatic address increase but uses a byte-enable mechanism specifying 8-bit, 16-bit, or 32-bit access. Its registers are also defined in 16-bit format because it shares a design with a MAC controller using 16-bit access. As a result some common register accesses need to be re-arranged.
This patch adds the basic structure for using KSZ8463. It cannot use the same regmap table for other KSZ switches as it interprets the 16-bit value as little-endian and its SPI commands are different.
KSZ8463 uses a byte-enable mechanism to specify 8-bit, 16-bit, and 32-bit access. The register is first shifted right by 2 then left by 4. Extra 4 bits are added. If the access is 8-bit one of the 4 bits is set. If the access is 16-bit two of the 4 bits are set. If the access is 32-bit all 4 bits are set. The SPI command for read or write is then added.
Because of this register transformation separate SPI read and write functions are provided for KSZ8463.
Quoted 8 lines
KSZ8463's internal PHYs use standard PHY register definitions so there is no need to remap things. However, the hardware has a bug that the high word and low word of the PHY id are swapped. In addition the port registers are arranged differently so KSZ8463 has its own mapping for port registers and PHY registers. Therefore the
PORT_CTRL_ADDRmacro is replaced with theget_port_addrhelper function.Signed-off-by Tristram Ha <[email protected]>
Thanks for keeping working on regmap. The end result is a lot better, smaller.
Andrew
PATCH v6 3/6 net: dsa: microchip: Use different registers for KSZ8463
In reply to [email protected]From: Tristram Ha <[email protected]>
KSZ8463 does not use same set of registers as KSZ8863 so it is necessary to change some registers when using KSZ8463.
---
v3
- Replace cpu_to_be16() with swab16() to avoid compiler warning
drivers/net/dsa/microchip/ksz8.c | 78 +++++++++++++++++++------- drivers/net/dsa/microchip/ksz_common.c | 32 +++++++++-- drivers/net/dsa/microchip/ksz_dcb.c | 10 +++- 3 files changed, 92 insertions(+), 28 deletions(-)
drivers/net/dsa/microchip/ksz8.c +57 -21
@@ -142,6 +142,11 @@ int ksz8_reset_switch(struct ksz_device *dev) KSZ8863_GLOBAL_SOFTWARE_RESET | KSZ8863_PCS_RESET, true);ksz_cfg (dev,KSZ8863_REG_SW_RESET ,KSZ8863_GLOBAL_SOFTWARE_RESET |KSZ8863_PCS_RESET , false); + }else if (ksz_is_ksz8463 (dev)) { +ksz_cfg (dev,KSZ8463_REG_SW_RESET , +KSZ8463_GLOBAL_SOFTWARE_RESET , true); +ksz_cfg (dev,KSZ8463_REG_SW_RESET , +KSZ8463_GLOBAL_SOFTWARE_RESET , false); }else {/* reset switch */ ksz_write8(dev, REG_POWER_MANAGEMENT_1,
@@ -230,6 +235,11 @@ static int ksz8_port_queue_split(struct ksz_device *dev, int port, int queues) WEIGHTED_FAIR_QUEUE_ENABLE);if (ret)return ret; + }else if (ksz_is_ksz8463 (dev)) { + mask_4q =KSZ8873_PORT_4QUEUE_SPLIT_EN ; + mask_2q =KSZ8873_PORT_2QUEUE_SPLIT_EN ; + reg_4q =P1CR1 ; + reg_2q =P1CR1 +1 ; }else { mask_4q =KSZ8795_PORT_4QUEUE_SPLIT_EN ; mask_2q =KSZ8795_PORT_2QUEUE_SPLIT_EN ;
@@ -1268,12 +1278,15 @@ int ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val)void ksz8_cfg_port_member (struct ksz_device *dev,int port,u8 member) { +int offset =P_MIRROR_CTRL ;u8 data; -ksz_pread8 (dev, port,P_MIRROR_CTRL , &data); - data &= ~PORT_VLAN_MEMBERSHIP ; +if (ksz_is_ksz8463 (dev)) + offset =P1CR2 ; +ksz_pread8 (dev, port, offset, &data); + data &= ~dev->port_mask; data |= (member & dev->port_mask); -ksz_pwrite8 (dev, port,P_MIRROR_CTRL , data); +ksz_pwrite8 (dev, port, offset, data); }void ksz8_flush_dyn_mac_table (struct ksz_device *dev,int port)
@@ -1281,6 +1294,8 @@ void ksz8_flush_dyn_mac_table(struct ksz_device *dev, int port)u8 learn[DSA_MAX_PORTS ];int first, index, cnt;const u16 *regs; +int reg =S_FLUSH_TABLE_CTRL ; +int mask =SW_FLUSH_DYN_MAC_TABLE ; regs = dev->info->regs;
@@ -1298,7 +1313,11 @@ void ksz8_flush_dyn_mac_table(struct ksz_device *dev, int port)ksz_pwrite8 (dev, index, regs[P_STP_CTRL ], learn[index] |PORT_LEARN_DISABLE ); } -ksz_cfg (dev,S_FLUSH_TABLE_CTRL ,SW_FLUSH_DYN_MAC_TABLE , true); +if (ksz_is_ksz8463 (dev)) { + reg =KSZ8463_FLUSH_TABLE_CTRL ; + mask =KSZ8463_FLUSH_DYN_MAC_TABLE ; + } +ksz_cfg (dev, reg, mask, true);for (index = first; index < cnt; index++) {if (!(learn[index] &PORT_LEARN_DISABLE ))ksz_pwrite8 (dev, index, regs[P_STP_CTRL ], learn[index]);
@@ -1437,7 +1456,7 @@ int ksz8_fdb_del(struct ksz_device *dev, int port, const unsigned char *addr,int ksz8_port_vlan_filtering (struct ksz_device *dev,int port,bool flag,struct netlink_ext_ack *extack) { -if (ksz_is_ksz88x3 (dev)) +if (ksz_is_ksz88x3 (dev) ||ksz_is_ksz8463 (dev))return -ENOTSUPP ;/* Discard packets with VID not enabled on the switch */
@@ -1453,9 +1472,12 @@ int ksz8_port_vlan_filtering(struct ksz_device *dev, int port, bool flag,static void ksz8_port_enable_pvid (struct ksz_device *dev,int port,bool state) { -if (ksz_is_ksz88x3 (dev)) { -ksz_cfg (dev,REG_SW_INSERT_SRC_PVID , -0x03 << (4 -2 * port), state); +if (ksz_is_ksz88x3 (dev) ||ksz_is_ksz8463 (dev)) { +int reg =REG_SW_INSERT_SRC_PVID ; + +if (ksz_is_ksz8463 (dev)) + reg =KSZ8463_REG_SW_CTRL_9 ; +ksz_cfg (dev, reg,0x03 << (4 -2 * port), state); }else {ksz_pwrite8 (dev, port,REG_PORT_CTRL_12 , state ?0x0f :0x00 ); }
@@ -1470,7 +1492,7 @@ int ksz8_port_vlan_add(struct ksz_device *dev, int port,u16 data, new_pvid =0 ;u8 fid, member, valid; -if (ksz_is_ksz88x3 (dev)) +if (ksz_is_ksz88x3 (dev) ||ksz_is_ksz8463 (dev))return -ENOTSUPP ;/* If a VLAN is added with untagged flag different from the
@@ -1539,7 +1561,7 @@ int ksz8_port_vlan_del(struct ksz_device *dev, int port,u16 data, pvid;u8 fid, member, valid; -if (ksz_is_ksz88x3 (dev)) +if (ksz_is_ksz88x3 (dev) ||ksz_is_ksz8463 (dev))return -ENOTSUPP ;ksz_pread16 (dev, port,REG_PORT_CTRL_VID , &pvid);
@@ -1569,19 +1591,23 @@ int ksz8_port_mirror_add(struct ksz_device *dev, int port,struct dsa_mall_mirror_tc_entry *mirror, bool ingress, struct netlink_ext_ack *extack) { + int offset = P_MIRROR_CTRL; + +if (ksz_is_ksz8463 (dev)) + offset =P1CR2 ;if (ingress) { -ksz_port_cfg (dev ,port ,P_MIRROR_CTRL ,PORT_MIRROR_RX ,true ); +ksz_port_cfg (dev, port, offset,PORT_MIRROR_RX , true); dev->mirror_rx |=BIT (port); }else { -ksz_port_cfg (dev, port,P_MIRROR_CTRL ,PORT_MIRROR_TX , true); +ksz_port_cfg (dev, port, offset,PORT_MIRROR_TX , true); dev->mirror_tx |=BIT (port); } -ksz_port_cfg (dev, port,P_MIRROR_CTRL ,PORT_MIRROR_SNIFFER , false); +ksz_port_cfg (dev, port, offset,PORT_MIRROR_SNIFFER , false);/* configure mirror port */ if (dev->mirror_rx || dev->mirror_tx) -ksz_port_cfg (dev, mirror->to_local_port,P_MIRROR_CTRL , +ksz_port_cfg (dev, mirror->to_local_port, offset,PORT_MIRROR_SNIFFER , true);return 0 ;
@@ -1590,20 +1616,23 @@ int ksz8_port_mirror_add(struct ksz_device *dev, int port,void ksz8_port_mirror_del (struct ksz_device *dev,int port,struct dsa_mall_mirror_tc_entry *mirror) { +int offset =P_MIRROR_CTRL ;u8 data; +if (ksz_is_ksz8463 (dev)) + offset =P1CR2 ;if (mirror->ingress) { -ksz_port_cfg (dev, port,P_MIRROR_CTRL ,PORT_MIRROR_RX , false); +ksz_port_cfg (dev, port, offset,PORT_MIRROR_RX , false); dev->mirror_rx &= ~BIT (port); }else { -ksz_port_cfg (dev, port,P_MIRROR_CTRL ,PORT_MIRROR_TX , false); +ksz_port_cfg (dev, port, offset,PORT_MIRROR_TX , false); dev->mirror_tx &= ~BIT (port); } -ksz_pread8 (dev, port,P_MIRROR_CTRL , &data); +ksz_pread8 (dev, port, offset, &data);if (!dev->mirror_rx && !dev->mirror_tx) -ksz_port_cfg (dev, mirror->to_local_port,P_MIRROR_CTRL , +ksz_port_cfg (dev, mirror->to_local_port, offset,PORT_MIRROR_SNIFFER , false); }
@@ -1628,17 +1657,24 @@ void ksz8_port_setup(struct ksz_device *dev, int port, bool cpu_port)const u16 *regs = dev->info->regs;struct dsa_switch *ds = dev->ds;const u32 *masks; +int offset;u8 member; masks = dev->info->masks;/* enable broadcast storm limit */ -ksz_port_cfg (dev, port,P_BCAST_STORM_CTRL ,PORT_BROADCAST_STORM , true); + offset =P_BCAST_STORM_CTRL ; +if (ksz_is_ksz8463 (dev)) + offset =P1CR1 ; +ksz_port_cfg (dev, port, offset,PORT_BROADCAST_STORM , true);ksz8_port_queue_split (dev, port, dev->info->num_tx_queues);/* replace priority */ -ksz_port_cfg (dev, port,P_802_1P_CTRL , + offset =P_802_1P_CTRL ; +if (ksz_is_ksz8463 (dev)) + offset =P1CR2 ; +ksz_port_cfg (dev, port, offset, masks[PORT_802_1P_REMAPPING ], false);if (cpu_port)
@@ -1904,7 +1940,7 @@ int ksz8_setup(struct dsa_switch *ds)ksz_cfg (dev,S_MIRROR_CTRL ,SW_MIRROR_RX_TX , false); -if (!ksz_is_ksz88x3 (dev)) +if (!ksz_is_ksz88x3 (dev) && !ksz_is_ksz8463 (dev))ksz_cfg (dev,REG_SW_CTRL_19 ,SW_INS_TAG_ENABLE , true);for (i =0 ; i < (dev->info->num_vlans /4 ); i++)
drivers/net/dsa/microchip/ksz_common.c +26 -6
@@ -2951,6 +2951,7 @@ static int ksz_parse_drive_strength(struct ksz_device *dev);static int ksz_setup (struct dsa_switch *ds) {struct ksz_device *dev = ds->priv; +u16 storm_mask, storm_rate;struct dsa_port *dp;struct ksz_port *p;const u16 *regs;
@@ -2980,10 +2981,14 @@ static int ksz_setup(struct dsa_switch *ds) }/* set broadcast storm protection 10% rate */ + storm_mask =BROADCAST_STORM_RATE ; + storm_rate = (BROADCAST_STORM_VALUE *BROADCAST_STORM_PROT_RATE ) /100 ; +if (ksz_is_ksz8463 (dev)) { + storm_mask =swab16 (storm_mask); + storm_rate =swab16 (storm_rate); + }regmap_update_bits (ksz_regmap_16 (dev), regs[S_BROADCAST_CTRL ], -BROADCAST_STORM_RATE , - (BROADCAST_STORM_VALUE * -BROADCAST_STORM_PROT_RATE ) /100 ); + storm_mask, storm_rate); dev->dev_ops->config_cpu_port (ds);
@@ -4221,6 +4226,17 @@ static int ksz_ets_band_to_queue(struct tc_ets_qopt_offload_replace_params *p,return p->bands -1 - band; } +static u8 ksz8463_tc_ctrl (int port,int queue) +{ +u8 reg; + + reg =0xC8 + port *4 ; + reg += ((3 - queue) /2 ) *2 ; + reg++; + reg -= (queue &1 ); +return reg; +} +/** * ksz88x3_tc_ets_add - Configure ETS (Enhanced Transmission Selection) * for a port on KSZ88x3 switch
@@ -4256,6 +4272,8 @@ static int ksz88x3_tc_ets_add(struct ksz_device *dev, int port,* port/queue */ reg =KSZ8873_TXQ_SPLIT_CTRL_REG (port, queue); +if (ksz_is_ksz8463 (dev)) + reg =ksz8463_tc_ctrl (port, queue);/* Clear WFQ enable bit to select strict priority scheduling */ ret =ksz_rmw8 (dev, reg,KSZ8873_TXQ_WFQ_ENABLE ,0 );
@@ -4291,6 +4309,8 @@ static int ksz88x3_tc_ets_del(struct ksz_device *dev, int port)* port/queue */ reg =KSZ8873_TXQ_SPLIT_CTRL_REG (port, queue); +if (ksz_is_ksz8463 (dev)) + reg =ksz8463_tc_ctrl (port, queue);/* Set WFQ enable bit to revert back to default scheduling * mode
@@ -4438,7 +4458,7 @@ static int ksz_tc_setup_qdisc_ets(struct dsa_switch *ds, int port,struct ksz_device *dev = ds->priv;int ret; -if (is_ksz8 (dev) && !ksz_is_ksz88x3 (dev)) +if (is_ksz8 (dev) && !(ksz_is_ksz88x3 (dev) ||ksz_is_ksz8463 (dev)))return -EOPNOTSUPP ;if (qopt->parent !=TC_H_ROOT ) {
@@ -4452,13 +4472,13 @@ static int ksz_tc_setup_qdisc_ets(struct dsa_switch *ds, int port,if (ret)return ret; -if (ksz_is_ksz88x3 (dev)) +if (ksz_is_ksz88x3 (dev) ||ksz_is_ksz8463 (dev))return ksz88x3_tc_ets_add (dev, port, &qopt->replace_params);else return ksz_tc_ets_add (dev, port, &qopt->replace_params);case TC_ETS_DESTROY : -if (ksz_is_ksz88x3 (dev)) +if (ksz_is_ksz88x3 (dev) ||ksz_is_ksz8463 (dev))return ksz88x3_tc_ets_del (dev, port);else return ksz_tc_ets_del (dev, port);
drivers/net/dsa/microchip/ksz_dcb.c +9 -1
@@ -16,10 +16,12 @@* Therefore, we define the base offset as 0x00 here to align with that logic. */ #define KSZ8_REG_PORT_1_CTRL_0 0x00 +#define KSZ8463_REG_PORT_1_CTRL_0 0x6C#define KSZ8_PORT_DIFFSERV_ENABLE BIT(6)#define KSZ8_PORT_802_1P_ENABLE BIT(5)#define KSZ8_PORT_BASED_PRIO_M GENMASK(4, 3) +#define KSZ8463_REG_TOS_DSCP_CTRL 0x16#define KSZ88X3_REG_TOS_DSCP_CTRL 0x60#define KSZ8765_REG_TOS_DSCP_CTRL 0x90
@@ -98,6 +100,8 @@ static void ksz_get_default_port_prio_reg(struct ksz_device *dev, int *reg, *reg =KSZ8_REG_PORT_1_CTRL_0 ; *mask =KSZ8_PORT_BASED_PRIO_M ; *shift =__bf_shf (KSZ8_PORT_BASED_PRIO_M ); +if (ksz_is_ksz8463 (dev)) + *reg =KSZ8463_REG_PORT_1_CTRL_0 ; }else { *reg =KSZ9477_REG_PORT_MRI_MAC_CTRL ; *mask =KSZ9477_PORT_BASED_PRIO_M ;
@@ -122,10 +126,12 @@ static void ksz_get_dscp_prio_reg(struct ksz_device *dev, int *reg, *reg =KSZ8765_REG_TOS_DSCP_CTRL ; *per_reg =4 ; *mask =GENMASK (1 ,0 ); - }else if (ksz_is_ksz88x3 (dev)) { + }else if (ksz_is_ksz88x3 (dev) ||ksz_is_ksz8463 (dev)) { *reg =KSZ88X3_REG_TOS_DSCP_CTRL ; *per_reg =4 ; *mask =GENMASK (1 ,0 ); +if (ksz_is_ksz8463 (dev)) + *reg =KSZ8463_REG_TOS_DSCP_CTRL ; }else { *reg =KSZ9477_REG_DIFFSERV_PRIO_MAP ; *per_reg =2 ;
@@ -151,6 +157,8 @@ static void ksz_get_apptrust_map_and_reg(struct ksz_device *dev, *map = ksz8_apptrust_map_to_bit; *reg =KSZ8_REG_PORT_1_CTRL_0 ; *mask =KSZ8_PORT_DIFFSERV_ENABLE |KSZ8_PORT_802_1P_ENABLE ; +if (ksz_is_ksz8463 (dev)) + *reg =KSZ8463_REG_PORT_1_CTRL_0 ; }else { *map = ksz9477_apptrust_map_to_bit; *reg =KSZ9477_REG_PORT_MRI_PRIO_CTRL ;
Signature · 1 line
2.34.1
Re: [PATCH net-next v6 3/6] net: dsa: microchip: Use different registers for KSZ8463
Quoted 6 lines · On Thu, Jul 24, 2025 at 05:17:50PM -0700, [email protected] wrote:
From: Tristram Ha <[email protected]>
KSZ8463 does not use same set of registers as KSZ8863 so it is necessary to change some registers when using KSZ8463.
Signed-off-by Tristram Ha <[email protected]>
Andrew
PATCH v6 4/6 net: dsa: microchip: Write switch MAC address differently for KSZ8463
In reply to [email protected]From: Tristram Ha <[email protected]>
KSZ8463 uses 16-bit register definitions so it writes differently for 8-bit switch MAC address.
--- drivers/net/dsa/microchip/ksz_common.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/net/dsa/microchip/ksz_common.c +10 -1
@@ -4821,7 +4821,16 @@ int ksz_switch_macaddr_get(struct dsa_switch *ds, int port,/* Program the switch MAC address to hardware */ for (i =0 ; i <ETH_ALEN ; i++) { - ret =ksz_write8 (dev, regs[REG_SW_MAC_ADDR ] + i, addr[i]); +if (ksz_is_ksz8463 (dev)) { +u16 addr16 = ((u16 )addr[i] <<8 ) | addr[i +1 ]; + + ret =ksz_write16 (dev, regs[REG_SW_MAC_ADDR ] + i, + addr16); + i++; + }else { + ret =ksz_write8 (dev, regs[REG_SW_MAC_ADDR ] + i, + addr[i]); + }if (ret) goto macaddr_drop; }
Signature · 1 line
2.34.1
PATCH v6 5/6 net: dsa: microchip: Setup fiber ports for KSZ8463
In reply to [email protected]From: Tristram Ha <[email protected]>
The fiber ports in KSZ8463 cannot be detected internally, so it requires specifying that condition in the device tree. Like the one used in Micrel PHY the port link can only be read and there is no write to the PHY. The driver programs registers to operate fiber ports correctly.
---
v3
- Disable PTP function in a separate patch
drivers/net/dsa/microchip/ksz8.c | 16 ++++++++++++++++ drivers/net/dsa/microchip/ksz_common.c | 3 +++ 2 files changed, 19 insertions(+)
drivers/net/dsa/microchip/ksz8.c +16 -0
@@ -1714,6 +1714,7 @@ void ksz8_config_cpu_port(struct dsa_switch *ds)const u32 *masks;const u16 *regs;u8 remote; +u8 fiber_ports =0 ;int i; masks = dev->info->masks;
@@ -1744,6 +1745,21 @@ void ksz8_config_cpu_port(struct dsa_switch *ds)else ksz_port_cfg (dev, i, regs[P_STP_CTRL ],PORT_FORCE_FLOW_CTRL , false); +if (p->fiber) + fiber_ports |= (1 << i); + } +if (ksz_is_ksz8463 (dev)) { +/* Setup fiber ports. */ +if (fiber_ports) { + fiber_ports &=3 ; +regmap_update_bits (ksz_regmap_16 (dev), +KSZ8463_REG_CFG_CTRL , + fiber_ports <<PORT_COPPER_MODE_S , +0 ); +regmap_update_bits (ksz_regmap_16 (dev), +KSZ8463_REG_DSP_CTRL_6 , +COPPER_RECEIVE_ADJUSTMENT ,0 ); + } } }
drivers/net/dsa/microchip/ksz_common.c +3 -0
@@ -5439,6 +5439,9 @@ int ksz_switch_register(struct ksz_device *dev) &dev->ports[port_num].interface);ksz_parse_rgmii_delay (dev, port_num, port); + dev->ports[port_num].fiber = +of_property_read_bool (port, +"micrel,fiber-mode" ); }of_node_put (ports); }
Signature · 1 line
2.34.1
Re: [PATCH net-next v6 5/6] net: dsa: microchip: Setup fiber ports for KSZ8463
On Thu, Jul 24, 2025 at 05:17:52PM -0700, [email protected] wrote:
61;8003;1c> From: Tristram Ha <[email protected]>
Quoted 7 lines
The fiber ports in KSZ8463 cannot be detected internally, so it requires specifying that condition in the device tree. Like the one used in Micrel PHY the port link can only be read and there is no write to the PHY. The driver programs registers to operate fiber ports correctly.
Signed-off-by Tristram Ha <[email protected]>
Andrew
PATCH v6 6/6 net: dsa: microchip: Disable PTP function of KSZ8463
In reply to [email protected]From: Tristram Ha <[email protected]>
The PTP function of KSZ8463 is on by default. However, its proprietary way of storing timestamp directly in a reserved field inside the PTP message header is not suitable for use with the current Linux PTP stack implementation. It is necessary to disable the PTP function to not interfere the normal operation of the MAC.
Note the PTP driver for KSZ switches does not work for KSZ8463 and is not activated for it.
--- drivers/net/dsa/microchip/ksz8.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/net/dsa/microchip/ksz8.c +11 -0
@@ -1760,6 +1760,17 @@ void ksz8_config_cpu_port(struct dsa_switch *ds)KSZ8463_REG_DSP_CTRL_6 , COPPER_RECEIVE_ADJUSTMENT, 0); } + +/* Turn off PTP function as the switch's proprietary way of +* handling timestamp is not supported in current Linux PTP +* stack implementation. +*/ +regmap_update_bits (ksz_regmap_16 (dev), +KSZ8463_PTP_MSG_CONF1 , +PTP_ENABLE ,0 ); +regmap_update_bits (ksz_regmap_16 (dev), +KSZ8463_PTP_CLK_CTRL , +PTP_CLK_ENABLE ,0 ); } }
Signature · 1 line
2.34.1
Re: [PATCH net-next v6 6/6] net: dsa: microchip: Disable PTP function of KSZ8463
Quoted 8 lines · On Thu, Jul 24, 2025 at 05:17:53PM -0700, [email protected] wrote:
From: Tristram Ha <[email protected]>
The PTP function of KSZ8463 is on by default. However, its proprietary way of storing timestamp directly in a reserved field inside the PTP message header is not suitable for use with the current Linux PTP stack implementation. It is necessary to disable the PTP function to not interfere the normal operation of the MAC.
Quoted 4 lines
Note the PTP driver for KSZ switches does not work for KSZ8463 and is not activated for it.
Signed-off-by Tristram Ha <[email protected]>
Andrew
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 10 lines · On Thu, 24 Jul 2025 17:17:47 -0700 you wrote:
From: Tristram Ha <[email protected]>
This series of patches is to add KSZ8463 switch support to the KSZ DSA driver.
v6
- Setuse_single_readanduse_single_writeso that 64-bit access works
- Change register values for big-endian system if necessary[...]
Here is the summary with links:
- [net-next,v6,1/6] dt-bindings: net: dsa: microchip: Add KSZ8463 switch support
https://git.kernel.org/netdev/net-next/c/ba37d556eaf7 - [net-next,v6,2/6] net: dsa: microchip: Add KSZ8463 switch support to KSZ DSA driver https://git.kernel.org/netdev/net-next/c/84c47bfc5b3b - [net-next,v6,3/6] net: dsa: microchip: Use different registers for KSZ8463 https://git.kernel.org/netdev/net-next/c/15b8d3e38607 - [net-next,v6,4/6] net: dsa: microchip: Write switch MAC address differently for KSZ8463 https://git.kernel.org/netdev/net-next/c/5bcdb1373a6c - [net-next,v6,5/6] net: dsa: microchip: Setup fiber ports for KSZ8463 https://git.kernel.org/netdev/net-next/c/006983e59755 - [net-next,v6,6/6] net: dsa: microchip: Disable PTP function of KSZ8463 https://git.kernel.org/netdev/net-next/c/620e2392db23
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html