Skip to content

Commit 1699437

Browse files
ffainellidavem330
authored andcommitted
net: dsa: b53: Make SRAB driver manage port interrupts
Update the SRAB driver to manage per-port interrupts. Since we cannot sleep during b53_io_ops, schedule a workqueue whenever we get a port specific interrupt. We will later make use of this to call back into PHYLINK when there is e.g: a link state change. Signed-off-by: Florian Fainelli <f.fainelli@gmail.com> Reviewed-by: Andrew Lunn <andrew@lunn.ch> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 8ca7c16 commit 1699437

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed

drivers/net/dsa/b53/b53_srab.c

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/kernel.h>
2020
#include <linux/module.h>
2121
#include <linux/delay.h>
22+
#include <linux/interrupt.h>
2223
#include <linux/platform_device.h>
2324
#include <linux/platform_data/b53.h>
2425
#include <linux/of.h>
@@ -47,6 +48,7 @@
4748

4849
/* command and status register of the SRAB */
4950
#define B53_SRAB_CTRLS 0x40
51+
#define B53_SRAB_CTRLS_HOST_INTR BIT(1)
5052
#define B53_SRAB_CTRLS_RCAREQ BIT(3)
5153
#define B53_SRAB_CTRLS_RCAGNT BIT(4)
5254
#define B53_SRAB_CTRLS_SW_INIT_DONE BIT(6)
@@ -60,8 +62,16 @@
6062
#define B53_SRAB_P7_SLEEP_TIMER BIT(11)
6163
#define B53_SRAB_IMP0_SLEEP_TIMER BIT(12)
6264

65+
struct b53_srab_port_priv {
66+
int irq;
67+
bool irq_enabled;
68+
struct b53_device *dev;
69+
unsigned int num;
70+
};
71+
6372
struct b53_srab_priv {
6473
void __iomem *regs;
74+
struct b53_srab_port_priv port_intrs[B53_N_PORTS];
6575
};
6676

6777
static int b53_srab_request_grant(struct b53_device *dev)
@@ -344,6 +354,49 @@ static int b53_srab_write64(struct b53_device *dev, u8 page, u8 reg,
344354
return ret;
345355
}
346356

357+
static irqreturn_t b53_srab_port_thread(int irq, void *dev_id)
358+
{
359+
return IRQ_HANDLED;
360+
}
361+
362+
static irqreturn_t b53_srab_port_isr(int irq, void *dev_id)
363+
{
364+
struct b53_srab_port_priv *port = dev_id;
365+
struct b53_device *dev = port->dev;
366+
struct b53_srab_priv *priv = dev->priv;
367+
368+
/* Acknowledge the interrupt */
369+
writel(BIT(port->num), priv->regs + B53_SRAB_INTR);
370+
371+
return IRQ_WAKE_THREAD;
372+
}
373+
374+
static int b53_srab_irq_enable(struct b53_device *dev, int port)
375+
{
376+
struct b53_srab_priv *priv = dev->priv;
377+
struct b53_srab_port_priv *p = &priv->port_intrs[port];
378+
int ret;
379+
380+
ret = request_threaded_irq(p->irq, b53_srab_port_isr,
381+
b53_srab_port_thread, 0,
382+
dev_name(dev->dev), p);
383+
if (!ret)
384+
p->irq_enabled = true;
385+
386+
return ret;
387+
}
388+
389+
static void b53_srab_irq_disable(struct b53_device *dev, int port)
390+
{
391+
struct b53_srab_priv *priv = dev->priv;
392+
struct b53_srab_port_priv *p = &priv->port_intrs[port];
393+
394+
if (p->irq_enabled) {
395+
free_irq(p->irq, p);
396+
p->irq_enabled = false;
397+
}
398+
}
399+
347400
static const struct b53_io_ops b53_srab_ops = {
348401
.read8 = b53_srab_read8,
349402
.read16 = b53_srab_read16,
@@ -355,6 +408,8 @@ static const struct b53_io_ops b53_srab_ops = {
355408
.write32 = b53_srab_write32,
356409
.write48 = b53_srab_write48,
357410
.write64 = b53_srab_write64,
411+
.irq_enable = b53_srab_irq_enable,
412+
.irq_disable = b53_srab_irq_disable,
358413
};
359414

360415
static const struct of_device_id b53_srab_of_match[] = {
@@ -379,6 +434,52 @@ static const struct of_device_id b53_srab_of_match[] = {
379434
};
380435
MODULE_DEVICE_TABLE(of, b53_srab_of_match);
381436

437+
static void b53_srab_intr_set(struct b53_srab_priv *priv, bool set)
438+
{
439+
u32 reg;
440+
441+
reg = readl(priv->regs + B53_SRAB_CTRLS);
442+
if (set)
443+
reg |= B53_SRAB_CTRLS_HOST_INTR;
444+
else
445+
reg &= ~B53_SRAB_CTRLS_HOST_INTR;
446+
writel(reg, priv->regs + B53_SRAB_CTRLS);
447+
}
448+
449+
static void b53_srab_prepare_irq(struct platform_device *pdev)
450+
{
451+
struct b53_device *dev = platform_get_drvdata(pdev);
452+
struct b53_srab_priv *priv = dev->priv;
453+
struct b53_srab_port_priv *port;
454+
unsigned int i;
455+
char *name;
456+
457+
/* Clear all pending interrupts */
458+
writel(0xffffffff, priv->regs + B53_SRAB_INTR);
459+
460+
if (dev->pdata && dev->pdata->chip_id != BCM58XX_DEVICE_ID)
461+
return;
462+
463+
for (i = 0; i < B53_N_PORTS; i++) {
464+
port = &priv->port_intrs[i];
465+
466+
/* There is no port 6 */
467+
if (i == 6)
468+
continue;
469+
470+
name = kasprintf(GFP_KERNEL, "link_state_p%d", i);
471+
if (!name)
472+
return;
473+
474+
port->num = i;
475+
port->dev = dev;
476+
port->irq = platform_get_irq_byname(pdev, name);
477+
kfree(name);
478+
}
479+
480+
b53_srab_intr_set(priv, true);
481+
}
482+
382483
static int b53_srab_probe(struct platform_device *pdev)
383484
{
384485
struct b53_platform_data *pdata = pdev->dev.platform_data;
@@ -417,13 +518,17 @@ static int b53_srab_probe(struct platform_device *pdev)
417518

418519
platform_set_drvdata(pdev, dev);
419520

521+
b53_srab_prepare_irq(pdev);
522+
420523
return b53_switch_register(dev);
421524
}
422525

423526
static int b53_srab_remove(struct platform_device *pdev)
424527
{
425528
struct b53_device *dev = platform_get_drvdata(pdev);
529+
struct b53_srab_priv *priv = dev->priv;
426530

531+
b53_srab_intr_set(priv, false);
427532
if (dev)
428533
b53_switch_remove(dev);
429534

0 commit comments

Comments
 (0)