From: "Russell King (Oracle)" <linux@armlinux.org.uk>
To: Arun Ramadoss <arun.ramadoss@microchip.com>
Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
woojung.huh@microchip.com, UNGLinuxDriver@microchip.com,
andrew@lunn.ch, vivien.didelot@gmail.com, f.fainelli@gmail.com,
olteanv@gmail.com, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com, Tristram.Ha@microchip.com,
prasanna.vengateshan@microchip.com, hkallweit1@gmail.com
Subject: Re: [Patch net-next v2 4/5] net: dsa: microchip: move interrupt handling logic from lan937x to ksz_common
Date: Wed, 14 Sep 2022 12:27:39 +0100 [thread overview]
Message-ID: <YyG6q6SPURSAtz7C@shell.armlinux.org.uk> (raw)
In-Reply-To: <20220914035223.31702-5-arun.ramadoss@microchip.com>
Hi,
Some suggestions for a few improvements in a future patch:
On Wed, Sep 14, 2022 at 09:22:22AM +0530, Arun Ramadoss wrote:
> +static int ksz_irq_phy_setup(struct ksz_device *dev)
> +{
> + struct dsa_switch *ds = dev->ds;
> + int phy, err_phy;
> + int irq;
> + int ret;
> +
> + for (phy = 0; phy < KSZ_MAX_NUM_PORTS; phy++) {
> + if (BIT(phy) & ds->phys_mii_mask) {
> + irq = irq_find_mapping(dev->ports[phy].pirq.domain,
> + PORT_SRC_PHY_INT);
> + if (irq < 0) {
> + ret = irq;
> + goto out;
> + }
> + ds->slave_mii_bus->irq[phy] = irq;
> + }
> + }
> + return 0;
> +out:
> + err_phy = phy;
> +
> + for (phy = 0; phy < err_phy; phy++)
> + if (BIT(phy) & ds->phys_mii_mask)
> + irq_dispose_mapping(ds->slave_mii_bus->irq[phy]);
while (phy--)
if (BIT(phy) & ds->phys_mii_mask)
irq_dispose_mapping(ds->slave_mii_bus->irq[phy]);
?
> +static void ksz_girq_mask(struct irq_data *d)
> +{
> + struct ksz_device *dev = irq_data_get_irq_chip_data(d);
> + unsigned int n = d->hwirq;
> +
> + dev->girq.masked |= (1 << n);
dev->girq.masked |= BIT(d->hwirq);
?
> +}
> +
> +static void ksz_girq_unmask(struct irq_data *d)
> +{
> + struct ksz_device *dev = irq_data_get_irq_chip_data(d);
> + unsigned int n = d->hwirq;
> +
> + dev->girq.masked &= ~(1 << n);
dev->girq.masked &= ~BIT(d->hw_irq);
?
> +}
> +
> +static void ksz_girq_bus_lock(struct irq_data *d)
> +{
> + struct ksz_device *dev = irq_data_get_irq_chip_data(d);
> +
> + mutex_lock(&dev->lock_irq);
> +}
> +
> +static void ksz_girq_bus_sync_unlock(struct irq_data *d)
> +{
> + struct ksz_device *dev = irq_data_get_irq_chip_data(d);
> + int ret;
> +
> + ret = ksz_write32(dev, REG_SW_PORT_INT_MASK__4, dev->girq.masked);
> + if (ret)
> + dev_err(dev->dev, "failed to change IRQ mask\n");
> +
> + mutex_unlock(&dev->lock_irq);
> +}
> +
> +static const struct irq_chip ksz_girq_chip = {
> + .name = "ksz-global",
> + .irq_mask = ksz_girq_mask,
> + .irq_unmask = ksz_girq_unmask,
> + .irq_bus_lock = ksz_girq_bus_lock,
> + .irq_bus_sync_unlock = ksz_girq_bus_sync_unlock,
> +};
As the pirq code is almost identical to the girq code, how about putting
a "reg_mask", "reg_status" and a pointer to ksz_device into ksz_irq, and
using the ksz_irq as the chip data?
These would then become:
static void ksz_irq_mask(struct irq_data *d)
{
struct ksz_irq *ki = irq_data_get_irq_chip_data(d);
ki->masked |= BIT(d->hwirq);
}
static void ksz_irq_unmask(struct irq_data *d)
{
struct ksz_irq *ki = irq_data_get_irq_chip_data(d);
ki->masked &= ~BIT(d->hwirq);
}
static void ksz_irq_bus_lock(struct irq_data *d)
{
struct ksz_irq *ki = irq_data_get_irq_chip_data(d);
mutex_lock(&ki->dev->lock_irq);
}
static void ksz_irq_bus_sync_unlock(struct irq_data *d)
{
struct ksz_irq *ki = irq_data_get_irq_chip_data(d);
struct ksz_device *dev = ki->dev;
int ret;
ret = ksz_write32(dev, ki->reg_masked, ki->masked);
if (ret)
dev_err(dev->dev, "failed to change IRQ mask\n");
mutex_unlock(&dev->lock_irq);
}
and thus this code could be shared between both pirq and girq.
I'm pretty sure the thead_fn could be shared as well, and I'm
sure that the setup and tear down could be improved in a similar
way.
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
next prev parent reply other threads:[~2022-09-14 11:27 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-14 3:52 [Patch net-next v2 0/5] net: dsa: microchip: ksz9477: enable interrupt for internal phy link detection Arun Ramadoss
2022-09-14 3:52 ` [Patch net-next v2 1/5] net: dsa: microchip: determine number of port irq based on switch type Arun Ramadoss
2022-09-14 3:52 ` [Patch net-next v2 2/5] net: dsa: microchip: enable phy interrupts only if interrupt enabled in dts Arun Ramadoss
2022-09-14 3:52 ` [Patch net-next v2 3/5] net: dsa: microchip: lan937x: return zero if mdio node not present Arun Ramadoss
2022-09-14 3:52 ` [Patch net-next v2 4/5] net: dsa: microchip: move interrupt handling logic from lan937x to ksz_common Arun Ramadoss
2022-09-14 11:27 ` Russell King (Oracle) [this message]
2022-09-15 4:43 ` Arun.Ramadoss
2022-09-14 3:52 ` [Patch net-next v2 5/5] net: phy: micrel: enable interrupt for ksz9477 phy Arun Ramadoss
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YyG6q6SPURSAtz7C@shell.armlinux.org.uk \
--to=linux@armlinux.org.uk \
--cc=Tristram.Ha@microchip.com \
--cc=UNGLinuxDriver@microchip.com \
--cc=andrew@lunn.ch \
--cc=arun.ramadoss@microchip.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=f.fainelli@gmail.com \
--cc=hkallweit1@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=pabeni@redhat.com \
--cc=prasanna.vengateshan@microchip.com \
--cc=vivien.didelot@gmail.com \
--cc=woojung.huh@microchip.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).