Skip to content

Commit caa858b

Browse files
Dimitri Fedraukuba-moo
authored andcommitted
net: phy: marvell-88q2xxx: add interrupt support for link detection
Added .config_intr and .handle_interrupt callbacks. Whenever the link goes up or down an interrupt will be triggered. Interrupts are configured separately for 100/1000BASET1. Reviewed-by: Andrew Lunn <[email protected]> Signed-off-by: Dimitri Fedrau <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent e57e4c7 commit caa858b

File tree

1 file changed

+119
-4
lines changed

1 file changed

+119
-4
lines changed

drivers/net/phy/marvell-88q2xxx.c

Lines changed: 119 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@
2424
#define MDIO_MMD_AN_MV_STAT2_100BT1 0x2000
2525
#define MDIO_MMD_AN_MV_STAT2_1000BT1 0x4000
2626

27+
#define MDIO_MMD_PCS_MV_INT_EN 32784
28+
#define MDIO_MMD_PCS_MV_INT_EN_LINK_UP 0x0040
29+
#define MDIO_MMD_PCS_MV_INT_EN_LINK_DOWN 0x0080
30+
#define MDIO_MMD_PCS_MV_INT_EN_100BT1 0x1000
31+
32+
#define MDIO_MMD_PCS_MV_GPIO_INT_STAT 32785
33+
#define MDIO_MMD_PCS_MV_GPIO_INT_STAT_LINK_UP 0x0040
34+
#define MDIO_MMD_PCS_MV_GPIO_INT_STAT_LINK_DOWN 0x0080
35+
#define MDIO_MMD_PCS_MV_GPIO_INT_STAT_100BT1_GEN 0x1000
36+
37+
#define MDIO_MMD_PCS_MV_GPIO_INT_CTRL 32787
38+
#define MDIO_MMD_PCS_MV_GPIO_INT_CTRL_TRI_DIS 0x0800
39+
2740
#define MDIO_MMD_PCS_MV_100BT1_STAT1 33032
2841
#define MDIO_MMD_PCS_MV_100BT1_STAT1_IDLE_ERROR 0x00ff
2942
#define MDIO_MMD_PCS_MV_100BT1_STAT1_JABBER 0x0100
@@ -38,6 +51,12 @@
3851
#define MDIO_MMD_PCS_MV_100BT1_STAT2_LINK 0x0004
3952
#define MDIO_MMD_PCS_MV_100BT1_STAT2_ANGE 0x0008
4053

54+
#define MDIO_MMD_PCS_MV_100BT1_INT_EN 33042
55+
#define MDIO_MMD_PCS_MV_100BT1_INT_EN_LINKEVENT 0x0400
56+
57+
#define MDIO_MMD_PCS_MV_COPPER_INT_STAT 33043
58+
#define MDIO_MMD_PCS_MV_COPPER_INT_STAT_LINKEVENT 0x0400
59+
4160
#define MDIO_MMD_PCS_MV_RX_STAT 33328
4261

4362
struct mmd_val {
@@ -99,13 +118,15 @@ static int mv88q2xxx_read_link_gbit(struct phy_device *phydev)
99118

100119
/* Read vendor specific Auto-Negotiation status register to get local
101120
* and remote receiver status according to software initialization
102-
* guide.
121+
* guide. However, when not in polling mode the local and remote
122+
* receiver status are not evaluated due to the Marvell 88Q2xxx APIs.
103123
*/
104124
ret = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_MMD_AN_MV_STAT);
105125
if (ret < 0) {
106126
return ret;
107-
} else if ((ret & MDIO_MMD_AN_MV_STAT_LOCAL_RX) &&
108-
(ret & MDIO_MMD_AN_MV_STAT_REMOTE_RX)) {
127+
} else if (((ret & MDIO_MMD_AN_MV_STAT_LOCAL_RX) &&
128+
(ret & MDIO_MMD_AN_MV_STAT_REMOTE_RX)) ||
129+
!phy_polling_mode(phydev)) {
109130
/* The link state is latched low so that momentary link
110131
* drops can be detected. Do not double-read the status
111132
* in polling mode to detect such short link drops except
@@ -145,7 +166,18 @@ static int mv88q2xxx_read_link_100m(struct phy_device *phydev)
145166
* the link was already down. In case we are not polling,
146167
* we always read the realtime status.
147168
*/
148-
if (!phy_polling_mode(phydev) || !phydev->link) {
169+
if (!phy_polling_mode(phydev)) {
170+
phydev->link = false;
171+
ret = phy_read_mmd(phydev, MDIO_MMD_PCS,
172+
MDIO_MMD_PCS_MV_100BT1_STAT2);
173+
if (ret < 0)
174+
return ret;
175+
176+
if (ret & MDIO_MMD_PCS_MV_100BT1_STAT2_LINK)
177+
phydev->link = true;
178+
179+
return 0;
180+
} else if (!phydev->link) {
149181
ret = phy_read_mmd(phydev, MDIO_MMD_PCS,
150182
MDIO_MMD_PCS_MV_100BT1_STAT1);
151183
if (ret < 0)
@@ -356,6 +388,79 @@ static int mv88q2xxx_get_sqi_max(struct phy_device *phydev)
356388
return 15;
357389
}
358390

391+
static int mv88q2xxx_config_intr(struct phy_device *phydev)
392+
{
393+
int ret;
394+
395+
if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
396+
/* Enable interrupts for 1000BASE-T1 link up and down events
397+
* and enable general interrupts for 100BASE-T1.
398+
*/
399+
ret = phy_write_mmd(phydev, MDIO_MMD_PCS,
400+
MDIO_MMD_PCS_MV_INT_EN,
401+
MDIO_MMD_PCS_MV_INT_EN_LINK_UP |
402+
MDIO_MMD_PCS_MV_INT_EN_LINK_DOWN |
403+
MDIO_MMD_PCS_MV_INT_EN_100BT1);
404+
if (ret < 0)
405+
return ret;
406+
407+
/* Enable interrupts for 100BASE-T1 link events */
408+
return phy_write_mmd(phydev, MDIO_MMD_PCS,
409+
MDIO_MMD_PCS_MV_100BT1_INT_EN,
410+
MDIO_MMD_PCS_MV_100BT1_INT_EN_LINKEVENT);
411+
} else {
412+
ret = phy_write_mmd(phydev, MDIO_MMD_PCS,
413+
MDIO_MMD_PCS_MV_INT_EN, 0);
414+
if (ret < 0)
415+
return ret;
416+
417+
return phy_write_mmd(phydev, MDIO_MMD_PCS,
418+
MDIO_MMD_PCS_MV_100BT1_INT_EN, 0);
419+
}
420+
}
421+
422+
static irqreturn_t mv88q2xxx_handle_interrupt(struct phy_device *phydev)
423+
{
424+
bool trigger_machine = false;
425+
int irq;
426+
427+
/* Before we can acknowledge the 100BT1 general interrupt, that is in
428+
* the 1000BT1 interrupt status register, we have to acknowledge any
429+
* interrupts that are related to it. Therefore we read first the 100BT1
430+
* interrupt status register, followed by reading the 1000BT1 interrupt
431+
* status register.
432+
*/
433+
434+
irq = phy_read_mmd(phydev, MDIO_MMD_PCS,
435+
MDIO_MMD_PCS_MV_COPPER_INT_STAT);
436+
if (irq < 0) {
437+
phy_error(phydev);
438+
return IRQ_NONE;
439+
}
440+
441+
/* Check link status for 100BT1 */
442+
if (irq & MDIO_MMD_PCS_MV_COPPER_INT_STAT_LINKEVENT)
443+
trigger_machine = true;
444+
445+
irq = phy_read_mmd(phydev, MDIO_MMD_PCS, MDIO_MMD_PCS_MV_GPIO_INT_STAT);
446+
if (irq < 0) {
447+
phy_error(phydev);
448+
return IRQ_NONE;
449+
}
450+
451+
/* Check link status for 1000BT1 */
452+
if ((irq & MDIO_MMD_PCS_MV_GPIO_INT_STAT_LINK_UP) ||
453+
(irq & MDIO_MMD_PCS_MV_GPIO_INT_STAT_LINK_DOWN))
454+
trigger_machine = true;
455+
456+
if (!trigger_machine)
457+
return IRQ_NONE;
458+
459+
phy_trigger_machine(phydev);
460+
461+
return IRQ_HANDLED;
462+
}
463+
359464
static int mv88q222x_soft_reset(struct phy_device *phydev)
360465
{
361466
int ret;
@@ -422,6 +527,14 @@ static int mv88q222x_revb0_config_init(struct phy_device *phydev)
422527
*/
423528
phydev->pma_extable = MDIO_PMA_EXTABLE_BT1;
424529

530+
/* Configure interrupt with default settings, output is driven low for
531+
* active interrupt and high for inactive.
532+
*/
533+
if (phy_interrupt_is_valid(phydev))
534+
return phy_set_bits_mmd(phydev, MDIO_MMD_PCS,
535+
MDIO_MMD_PCS_MV_GPIO_INT_CTRL,
536+
MDIO_MMD_PCS_MV_GPIO_INT_CTRL_TRI_DIS);
537+
425538
return 0;
426539
}
427540

@@ -448,6 +561,8 @@ static struct phy_driver mv88q2xxx_driver[] = {
448561
.config_init = mv88q222x_revb0_config_init,
449562
.read_status = mv88q2xxx_read_status,
450563
.soft_reset = mv88q222x_soft_reset,
564+
.config_intr = mv88q2xxx_config_intr,
565+
.handle_interrupt = mv88q2xxx_handle_interrupt,
451566
.set_loopback = genphy_c45_loopback,
452567
.get_sqi = mv88q2xxx_get_sqi,
453568
.get_sqi_max = mv88q2xxx_get_sqi_max,

0 commit comments

Comments
 (0)