net: dsa: microchip: lan937x: enable interrupt for internal phy link detection
cover net: dsa: microchip: lan937x: enable interrupt for internal phy link detection
This patch series enables the internal phy link detection for lan937x using the interrupt method. lan937x acts as the interrupt controller for the internal ports and phy, the irq_domain is registered for the individual ports and in turn for the individual port interrupts.
RFC v3 -> Patch v1
- Removed the RFC v3 1/3 from the series - changing exit from reset
- Changed the variable name in ksz_port from irq to pirq
- Added the check for return value of irq_find_mapping during phy irq registeration.
- Moved the clearing of POR_READY_INT from girq_thread_fn to lan937x_reset_switch
RFC v2 -> v3
- Used the interrupt controller implementation of phy link
Changes in RFC v2
- fixed the compilation issue
Arun Ramadoss (3):
net: dsa: microchip: add reference to ksz_device inside the ksz_port
net: dsa: microchip: lan937x: clear the POR_READY_INT status bit
net: dsa: microchip: lan937x: add interrupt support for port phy link
drivers/net/dsa/microchip/ksz_common.c | 13 + drivers/net/dsa/microchip/ksz_common.h | 18 ++ drivers/net/dsa/microchip/ksz_spi.c | 2 + drivers/net/dsa/microchip/lan937x.h | 1 + drivers/net/dsa/microchip/lan937x_main.c | 368 ++++++++++++++++++++++- drivers/net/dsa/microchip/lan937x_reg.h | 12 + 6 files changed, 410 insertions(+), 4 deletions(-)
base-commit: aa51b80e1af47b3781abb1fb1666445a7616f0cd
Signature · 1 line
2.36.1
PATCH 1/3 net: dsa: microchip: add reference to ksz_device inside the ksz_port
struct ksz_port doesn't have reference to ksz_device as of now. In order to find out from which port interrupt has triggered, we need to pass the struct ksz_port as a host data. When the interrupt is triggered, we can get the port from which interrupt triggered, but to identify it is phy interrupt we have to read status register. The regmap structure for accessing the device register is present in the ksz_device struct. To access the ksz_device from the ksz_port, the reference is added to it with port number as well.
--- drivers/net/dsa/microchip/ksz_common.c | 3 +++ drivers/net/dsa/microchip/ksz_common.h | 4 ++++ 2 files changed, 7 insertions(+)
drivers/net/dsa/microchip/ksz_common.c +3 -0
@@ -2357,6 +2357,9 @@ int ksz_switch_register(struct ksz_device *dev) GFP_KERNEL);if (!dev->ports[i].mib.counters)return -ENOMEM ; + + dev->ports[i].ksz_dev = dev; + dev->ports[i].num = i; }/* set the real number of ports */
drivers/net/dsa/microchip/ksz_common.h +4 -0
@@ -16,6 +16,8 @@#define KSZ_MAX_NUM_PORTS 8 +struct ksz_device ; +struct vlan_table {u32 table[3 ]; };
@@ -83,6 +85,8 @@ struct ksz_port {u16 max_frame;u32 rgmii_tx_val;u32 rgmii_rx_val; +struct ksz_device *ksz_dev; +u8 num; };struct ksz_device {
Signature · 1 line
2.36.1
Re: [Patch net-next 1/3] net: dsa: microchip: add reference to ksz_device inside the ksz_port
Quoted 11 lines · Arun Ramadoss
struct
ksz_portdoesn't have reference toksz_deviceas of now. In order to find out from which port interrupt has triggered, we need to pass the structksz_portas a host data. When the interrupt is triggered, we can get the port from which interrupt triggered, but to identify it is phy interrupt we have to read status register. The regmap structure for accessing the device register is present in theksz_devicestruct. To access theksz_devicefrom theksz_port, the reference is added to it with port number as well.Signed-off-by Arun Ramadoss <[email protected]>Reviewed-by Andrew Lunn <[email protected]>
Signature · 1 line
Florian
PATCH 2/3 net: dsa: microchip: lan937x: clear the POR_READY_INT status bit
In reply to Arun RamadossIn the lan937x_reset_switch(), it masks all the switch and port registers. In the Global_Int_status register, POR ready bit is write 1 to clear bit and all other bits are read only. So, this patch clear the por_ready_int status bit by writing 1.
--- drivers/net/dsa/microchip/lan937x_main.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/dsa/microchip/lan937x_main.c +4 -0
@@ -225,6 +225,10 @@ int lan937x_reset_switch(struct ksz_device *dev)if (ret <0 )return ret; + ret =ksz_write32 (dev,REG_SW_INT_STATUS__4 ,POR_READY_INT ); +if (ret <0 ) +return ret; + ret =ksz_write32 (dev,REG_SW_PORT_INT_MASK__4 ,0xFF );if (ret <0 )return ret;
Signature · 1 line
2.36.1
Re: [Patch net-next 2/3] net: dsa: microchip: lan937x: clear the POR_READY_INT status bit
Quoted 6 lines · Arun Ramadoss
In the
lan937x_reset_switch(), it masks all the switch and port registers. In theGlobal_Int_statusregister, POR ready bit is write 1 to clear bit and all other bits are read only. So, this patch clear thepor_ready_intstatus bit by writing 1.Signed-off-by Arun Ramadoss <[email protected]>
Signature · 1 line
Florian
PATCH 3/3 net: dsa: microchip: lan937x: add interrupt support for port phy link
In reply to Arun RamadossThis patch enables the interrupts for internal phy link detection for LAN937x. The interrupt enable bits are active low. There is global interrupt mask for each port. And each port has the individual interrupt mask for TAS. QCI, SGMII, PTP, PHY and ACL.
The first level of interrupt domain is registered for global port interrupt and second level of interrupt domain for the individual port interrupts. The phy interrupt is enabled in the lan937x_mdio_register function. Interrupt from which port is raised will be detected based on the interrupt host data.
--- drivers/net/dsa/microchip/ksz_common.c | 10 + drivers/net/dsa/microchip/ksz_common.h | 14 + drivers/net/dsa/microchip/ksz_spi.c | 2 + drivers/net/dsa/microchip/lan937x.h | 1 + drivers/net/dsa/microchip/lan937x_main.c | 364 ++++++++++++++++++++++- drivers/net/dsa/microchip/lan937x_reg.h | 12 + 6 files changed, 399 insertions(+), 4 deletions(-)
drivers/net/dsa/microchip/ksz_common.c +10 -0
@@ -205,6 +205,7 @@ static const struct ksz_dev_ops ksz9477_dev_ops = {static const struct ksz_dev_ops lan937x_dev_ops = { .setup = lan937x_setup, + .teardown = lan937x_teardown, .get_port_addr = ksz9477_get_port_addr, .cfg_port_member = ksz9477_cfg_port_member, .flush_dyn_mac_table = ksz9477_flush_dyn_mac_table,
@@ -1444,6 +1445,14 @@ static int ksz_setup(struct dsa_switch *ds)return 0 ; } +static void ksz_teardown (struct dsa_switch *ds) +{ +struct ksz_device *dev = ds->priv; + +if (dev->dev_ops->teardown) + dev->dev_ops->teardown (ds); +} +static void port_r_cnt (struct ksz_device *dev,int port) {struct ksz_port_mib *mib = &dev->ports[port].mib;
@@ -2193,6 +2202,7 @@ static const struct dsa_switch_ops ksz_switch_ops = { .get_tag_protocol = ksz_get_tag_protocol, .get_phy_flags = ksz_get_phy_flags, .setup = ksz_setup, + .teardown = ksz_teardown, .phy_read = ksz_phy_read16, .phy_write = ksz_phy_write16, .phylink_get_caps = ksz_phylink_get_caps,
drivers/net/dsa/microchip/ksz_common.h +14 -0
@@ -13,6 +13,7 @@#include <linux/phy.h> #include <linux/regmap.h> #include <net/dsa.h> +#include <linux/irq.h> #define KSZ_MAX_NUM_PORTS 8
@@ -68,6 +69,14 @@ struct ksz_chip_data {const struct regmap_access_table *rd_table; }; +struct ksz_irq { +u16 masked; +struct irq_chip chip; +struct irq_domain *domain; +int nirqs; +char name[16 ]; +}; +struct ksz_port {bool remove_tag;/* Remove Tag flag set, for ksz8795 only */ bool learning;
@@ -86,6 +95,7 @@ struct ksz_port {u32 rgmii_tx_val;u32 rgmii_rx_val;struct ksz_device *ksz_dev; +struct ksz_irq pirq;u8 num; };
@@ -104,6 +114,7 @@ struct ksz_device {struct regmap *regmap[3 ];void *priv; +int irq;struct gpio_desc *reset_gpio;/* Optional reset GPIO */
@@ -124,6 +135,8 @@ struct ksz_device {u16 mirror_rx;u16 mirror_tx;u16 port_mask; +struct mutex lock_irq;/* IRQ Access */ +struct ksz_irq girq; };/* List of supported models */
@@ -260,6 +273,7 @@ struct alu_struct {struct ksz_dev_ops {int (*setup)(struct dsa_switch *ds); +void (*teardown)(struct dsa_switch *ds);u32 (*get_port_addr)(int port,int offset);void (*cfg_port_member)(struct ksz_device *dev,int port,u8 member);void (*flush_dyn_mac_table)(struct ksz_device *dev,int port);
drivers/net/dsa/microchip/ksz_spi.c +2 -0
@@ -88,6 +88,8 @@ static int ksz_spi_probe(struct spi_device *spi)if (ret)return ret; + dev->irq = spi->irq; + ret =ksz_switch_register (dev);/* Main DSA driver may not be started yet. */
drivers/net/dsa/microchip/lan937x.h +1 -0
@@ -8,6 +8,7 @@int lan937x_reset_switch (struct ksz_device *dev);int lan937x_setup (struct dsa_switch *ds); +void lan937x_teardown (struct dsa_switch *ds);void lan937x_port_setup (struct ksz_device *dev,int port,bool cpu_port);void lan937x_config_cpu_port (struct dsa_switch *ds);int lan937x_switch_init (struct ksz_device *dev);
drivers/net/dsa/microchip/lan937x_main.c +360 -4
420 lines not on this page · raw message
drivers/net/dsa/microchip/lan937x_reg.h +12 -0
@@ -118,6 +118,18 @@/* Port Registers */ /* 0 - Operation */ +#define REG_PORT_INT_STATUS 0x001B +#define REG_PORT_INT_MASK 0x001F + +#define PORT_TAS_INT BIT(5) +#define PORT_QCI_INT BIT(4) +#define PORT_SGMII_INT BIT(3) +#define PORT_PTP_INT BIT(2) +#define PORT_PHY_INT BIT(1) +#define PORT_ACL_INT BIT(0) + +#define PORT_SRC_PHY_INT 1 +#define REG_PORT_CTRL_0 0x0020#define PORT_MAC_LOOPBACK BIT(7)
Signature · 1 line
2.36.1
This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:
Quoted 13 lines · On Fri, 2 Sep 2022 16:02:07 +0530 you wrote:
This patch series enables the internal phy link detection for lan937x using the interrupt method. lan937x acts as the interrupt controller for the internal ports and phy, the
irq_domainis registered for the individual ports and in turn for the individual port interrupts.RFC v3 -> Patch v1
- Removed the RFC v3 1/3 from the series - changing exit from reset
- Changed the variable name inksz_portfrom irq to pirq
- Added the check for return value ofirq_find_mappingduring phy irq registeration.
- Moved the clearing ofPOR_READY_INTfromgirq_thread_fntolan937x_reset_switch
Quoted 1 line
[...]
Here is the summary with links:
- [net-next,1/3] net: dsa: microchip: add reference to ksz_device inside the ksz_port
https://git.kernel.org/netdev/net-next/c/f3c165459c51 - [net-next,2/3] net: dsa: microchip: lan937x: clear the POR_READY_INT status bit https://git.kernel.org/netdev/net-next/c/f313936261ac - [net-next,3/3] net: dsa: microchip: lan937x: add interrupt support for port phy link https://git.kernel.org/netdev/net-next/c/c9cd961c0d43
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html