netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: <Arun.Ramadoss@microchip.com>
To: <andrew@lunn.ch>
Cc: <olteanv@gmail.com>, <linux-kernel@vger.kernel.org>,
	<UNGLinuxDriver@microchip.com>, <vivien.didelot@gmail.com>,
	<linux@armlinux.org.uk>, <Tristram.Ha@microchip.com>,
	<f.fainelli@gmail.com>, <kuba@kernel.org>, <edumazet@google.com>,
	<pabeni@redhat.com>, <netdev@vger.kernel.org>,
	<Woojung.Huh@microchip.com>, <davem@davemloft.net>
Subject: Re: [RFC Patch net-next v3 3/3] net: dsa: microchip: lan937x: add interrupt support for port phy link
Date: Thu, 1 Sep 2022 09:02:51 +0000	[thread overview]
Message-ID: <bd7fcde507f47b22f9a4140bb26b91d9bb7e1662.camel@microchip.com> (raw)
In-Reply-To: <Yw4P3OJgtTtmgBHN@lunn.ch>


On Tue, 2022-08-30 at 15:25 +0200, Andrew Lunn wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you
> know the content is safe
> 
> > @@ -85,6 +94,7 @@ struct ksz_port {
> >       u32 rgmii_tx_val;
> >       u32 rgmii_rx_val;
> >       struct ksz_device *ksz_dev;
> > +     struct ksz_irq irq;
> 
> Here irq is of type ksz_irq.
> 
> >       u8 num;
> >  };
> > 
> > @@ -103,6 +113,7 @@ struct ksz_device {
> >       struct regmap *regmap[3];
> > 
> >       void *priv;
> > +     int irq;
> 
> Here it is of type int.
> 
> > 
> >       struct gpio_desc *reset_gpio;   /* Optional reset GPIO */
> > 
> > @@ -124,6 +135,8 @@ struct ksz_device {
> >       u16 mirror_tx;
> >       u32 features;                   /* chip specific features */
> >       u16 port_mask;
> > +     struct mutex lock_irq;          /* IRQ Access */
> > +     struct ksz_irq girq;
> 
> And here you have the type ksz_irq called qirq. This is going to be
> confusing.
> 
> I suggest you make the first one called pirq, for port, and then we
> have girq for global, and irq is just a number.

Ok. I will update variable names as per the context it is used.

> 
> >  static int lan937x_cfg(struct ksz_device *dev, u32 addr, u8 bits,
> > bool set)
> >  {
> >       return regmap_update_bits(dev->regmap[0], addr, bits, set ?
> > bits : 0);
> > @@ -171,6 +175,7 @@ static int lan937x_mdio_register(struct
> > ksz_device *dev)
> >       struct device_node *mdio_np;
> >       struct mii_bus *bus;
> >       int ret;
> > +     int p;
> > 
> >       mdio_np = of_get_child_by_name(dev->dev->of_node, "mdio");
> >       if (!mdio_np) {
> > @@ -194,6 +199,16 @@ static int lan937x_mdio_register(struct
> > ksz_device *dev)
> > 
> >       ds->slave_mii_bus = bus;
> > 
> > +     for (p = 0; p < KSZ_MAX_NUM_PORTS; p++) {
> > +             if (BIT(p) & ds->phys_mii_mask) {
> > +                     unsigned int irq;
> > +
> > +                     irq = irq_find_mapping(dev-
> > >ports[p].irq.domain,
> > +                                            PORT_SRC_PHY_INT);
> 
> This could return an error code. You really should check for it, the
> irq subsystem is not going to be happy with a negative irq number.

Ok. I will check the return value for irq_find_mapping.

> 
> > +                     ds->slave_mii_bus->irq[p] = irq;
> > +             }
> > +     }
> > +
> >       ret = devm_of_mdiobus_register(ds->dev, bus, mdio_np);
> >       if (ret) {
> >               dev_err(ds->dev, "unable to register MDIO bus %s\n",
> 
> I don't see anywhere you destroy the mappings you created above when
> the MDIO bus is unregistered. The equivalent of
> mv88e6xxx_g2_irq_mdio_free().

I missed to destroy it. I will add.

> 
> 
> > +static irqreturn_t lan937x_girq_thread_fn(int irq, void *dev_id)
> > +{
> > +     struct ksz_device *dev = dev_id;
> > +     unsigned int nhandled = 0;
> > +     unsigned int sub_irq;
> > +     unsigned int n;
> > +     u32 data;
> > +     int ret;
> > +
> > +     ret = ksz_read32(dev, REG_SW_INT_STATUS__4, &data);
> > +     if (ret)
> > +             goto out;
> > +
> > +     if (data & POR_READY_INT) {
> > +             ret = ksz_write32(dev, REG_SW_INT_STATUS__4,
> > POR_READY_INT);
> > +             if (ret)
> > +                     goto out;
> > +     }
> 
> What do these two read/writes do? It seems like you are discarding an
> interrupt?

This interrupt in Power on reset interrupt. It is enabled by default in
the chip. I am not performing any operation based on POR. So I just
cleared the interrupt. Do I need to disable the POR interrupt in the
setup function, since no operation is performed based on it?

> 
> 
> > +
> > +     /* Read global interrupt status register */
> > +     ret = ksz_read32(dev, REG_SW_PORT_INT_STATUS__4, &data);
> > +     if (ret)
> > +             goto out;
> > +
> > +     for (n = 0; n < dev->girq.nirqs; ++n) {
> > +             if (data & (1 << n)) {
> > +                     sub_irq = irq_find_mapping(dev->girq.domain,
> > n);
> > +                     handle_nested_irq(sub_irq);
> > +                     ++nhandled;
> > +             }
> > +     }
> > +out:
> > +     return (nhandled > 0 ? IRQ_HANDLED : IRQ_NONE);
> > +}
> > +
> > +static irqreturn_t lan937x_pirq_thread_fn(int irq, void *dev_id)
> > +{
> > +     struct ksz_port *port = dev_id;
> > +     unsigned int nhandled = 0;
> > +     struct ksz_device *dev;
> > +     unsigned int sub_irq;
> > +     unsigned int n;
> > +     u8 data;
> > +
> > +     dev = port->ksz_dev;
> > +
> > +     /* Read global interrupt status register */
> > +     ksz_pread8(dev, port->num, REG_PORT_INT_STATUS, &data);
> 
> I think global here should be port?

Yes. Copy paste problem. I will update it.

> 
> > +
> > +     for (n = 0; n < port->irq.nirqs; ++n) {
> > +             if (data & (1 << n)) {
> > +                     sub_irq = irq_find_mapping(port->irq.domain,
> > n);
> > +                     handle_nested_irq(sub_irq);
> > +                     ++nhandled;
> > +             }
> > +     }
> > +
> > +     return (nhandled > 0 ? IRQ_HANDLED : IRQ_NONE);
> > +}
> > +
> > 
> >  void lan937x_switch_exit(struct ksz_device *dev)
> >  {
> > +     struct dsa_port *dp;
> > +
> >       lan937x_reset_switch(dev);
> > +
> > +     if (dev->irq > 0) {
> > +             dsa_switch_for_each_user_port(dp, dev->ds) {
> > +                     lan937x_pirq_free(&dev->ports[dp->index], dp-
> > >index);
> > +             }
> > +
> > +             lan937x_girq_free(dev);
> 
> This is where your problem with exit vs reset is coming from. You
> setup all the interrupt code in setup(). But currently there is no
> function which is the opposite of setup(). Generally, it is called
> tairdown. Add such a function.

Yes I was looking for opposite function for setup(). Thanks for
suggestion, I will update the code accordingly and remove the patch 1/3
from the series which replaces the exit with reset.

> 
>           Andrew

  reply	other threads:[~2022-09-01  9:04 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-30 10:53 [RFC Patch net-next v3 0/3] net: dsa: microchip: lan937x: enable interrupt for internal phy link detection Arun Ramadoss
2022-08-30 10:53 ` [RFC Patch net-next v3 1/3] net: dsa: microchip: use dev_ops->reset instead of exit in ksz_switch_register Arun Ramadoss
2022-08-30 12:44   ` Andrew Lunn
2022-08-30 10:53 ` [RFC Patch net-next v3 2/3] net: dsa: microchip: add reference to ksz_device inside the ksz_port Arun Ramadoss
2022-08-30 12:47   ` Andrew Lunn
2022-08-30 10:53 ` [RFC Patch net-next v3 3/3] net: dsa: microchip: lan937x: add interrupt support for port phy link Arun Ramadoss
2022-08-30 13:25   ` Andrew Lunn
2022-09-01  9:02     ` Arun.Ramadoss [this message]
2022-09-01 12:32       ` Andrew Lunn

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=bd7fcde507f47b22f9a4140bb26b91d9bb7e1662.camel@microchip.com \
    --to=arun.ramadoss@microchip.com \
    --cc=Tristram.Ha@microchip.com \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=Woojung.Huh@microchip.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=f.fainelli@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=vivien.didelot@gmail.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).