Skip to content

Commit

Permalink
net: dsa: b53: Make SRAB driver manage port interrupts
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Florian Fainelli authored and David S. Miller committed Sep 6, 2018
1 parent 8ca7c16 commit 1699437
Showing 1 changed file with 105 additions and 0 deletions.
105 changes: 105 additions & 0 deletions drivers/net/dsa/b53/b53_srab.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/delay.h>
#include <linux/interrupt.h>
#include <linux/platform_device.h>
#include <linux/platform_data/b53.h>
#include <linux/of.h>
Expand Down Expand Up @@ -47,6 +48,7 @@

/* command and status register of the SRAB */
#define B53_SRAB_CTRLS 0x40
#define B53_SRAB_CTRLS_HOST_INTR BIT(1)
#define B53_SRAB_CTRLS_RCAREQ BIT(3)
#define B53_SRAB_CTRLS_RCAGNT BIT(4)
#define B53_SRAB_CTRLS_SW_INIT_DONE BIT(6)
Expand All @@ -60,8 +62,16 @@
#define B53_SRAB_P7_SLEEP_TIMER BIT(11)
#define B53_SRAB_IMP0_SLEEP_TIMER BIT(12)

struct b53_srab_port_priv {
int irq;
bool irq_enabled;
struct b53_device *dev;
unsigned int num;
};

struct b53_srab_priv {
void __iomem *regs;
struct b53_srab_port_priv port_intrs[B53_N_PORTS];
};

static int b53_srab_request_grant(struct b53_device *dev)
Expand Down Expand Up @@ -344,6 +354,49 @@ static int b53_srab_write64(struct b53_device *dev, u8 page, u8 reg,
return ret;
}

static irqreturn_t b53_srab_port_thread(int irq, void *dev_id)
{
return IRQ_HANDLED;
}

static irqreturn_t b53_srab_port_isr(int irq, void *dev_id)
{
struct b53_srab_port_priv *port = dev_id;
struct b53_device *dev = port->dev;
struct b53_srab_priv *priv = dev->priv;

/* Acknowledge the interrupt */
writel(BIT(port->num), priv->regs + B53_SRAB_INTR);

return IRQ_WAKE_THREAD;
}

static int b53_srab_irq_enable(struct b53_device *dev, int port)
{
struct b53_srab_priv *priv = dev->priv;
struct b53_srab_port_priv *p = &priv->port_intrs[port];
int ret;

ret = request_threaded_irq(p->irq, b53_srab_port_isr,
b53_srab_port_thread, 0,
dev_name(dev->dev), p);
if (!ret)
p->irq_enabled = true;

return ret;
}

static void b53_srab_irq_disable(struct b53_device *dev, int port)
{
struct b53_srab_priv *priv = dev->priv;
struct b53_srab_port_priv *p = &priv->port_intrs[port];

if (p->irq_enabled) {
free_irq(p->irq, p);
p->irq_enabled = false;
}
}

static const struct b53_io_ops b53_srab_ops = {
.read8 = b53_srab_read8,
.read16 = b53_srab_read16,
Expand All @@ -355,6 +408,8 @@ static const struct b53_io_ops b53_srab_ops = {
.write32 = b53_srab_write32,
.write48 = b53_srab_write48,
.write64 = b53_srab_write64,
.irq_enable = b53_srab_irq_enable,
.irq_disable = b53_srab_irq_disable,
};

static const struct of_device_id b53_srab_of_match[] = {
Expand All @@ -379,6 +434,52 @@ static const struct of_device_id b53_srab_of_match[] = {
};
MODULE_DEVICE_TABLE(of, b53_srab_of_match);

static void b53_srab_intr_set(struct b53_srab_priv *priv, bool set)
{
u32 reg;

reg = readl(priv->regs + B53_SRAB_CTRLS);
if (set)
reg |= B53_SRAB_CTRLS_HOST_INTR;
else
reg &= ~B53_SRAB_CTRLS_HOST_INTR;
writel(reg, priv->regs + B53_SRAB_CTRLS);
}

static void b53_srab_prepare_irq(struct platform_device *pdev)
{
struct b53_device *dev = platform_get_drvdata(pdev);
struct b53_srab_priv *priv = dev->priv;
struct b53_srab_port_priv *port;
unsigned int i;
char *name;

/* Clear all pending interrupts */
writel(0xffffffff, priv->regs + B53_SRAB_INTR);

if (dev->pdata && dev->pdata->chip_id != BCM58XX_DEVICE_ID)
return;

for (i = 0; i < B53_N_PORTS; i++) {
port = &priv->port_intrs[i];

/* There is no port 6 */
if (i == 6)
continue;

name = kasprintf(GFP_KERNEL, "link_state_p%d", i);
if (!name)
return;

port->num = i;
port->dev = dev;
port->irq = platform_get_irq_byname(pdev, name);
kfree(name);
}

b53_srab_intr_set(priv, true);
}

static int b53_srab_probe(struct platform_device *pdev)
{
struct b53_platform_data *pdata = pdev->dev.platform_data;
Expand Down Expand Up @@ -417,13 +518,17 @@ static int b53_srab_probe(struct platform_device *pdev)

platform_set_drvdata(pdev, dev);

b53_srab_prepare_irq(pdev);

return b53_switch_register(dev);
}

static int b53_srab_remove(struct platform_device *pdev)
{
struct b53_device *dev = platform_get_drvdata(pdev);
struct b53_srab_priv *priv = dev->priv;

b53_srab_intr_set(priv, false);
if (dev)
b53_switch_remove(dev);

Expand Down

0 comments on commit 1699437

Please sign in to comment.