public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Horatiu Vultur <horatiu.vultur@microchip.com>
To: Philipp Zabel <p.zabel@pengutronix.de>
Cc: <davem@davemloft.net>, <kuba@kernel.org>, <robh+dt@kernel.org>,
	<linux@armlinux.org.uk>, <netdev@vger.kernel.org>,
	<devicetree@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH net-next 2/5] net: lan966x: add the basic lan966x driver
Date: Wed, 17 Nov 2021 22:42:31 +0100	[thread overview]
Message-ID: <20211117214231.yiv2s6nxl6yx4klq@soft-dev3-1.localhost> (raw)
In-Reply-To: <9ab98fba364f736b267dbd5e1d305d3e8426e877.camel@pengutronix.de>

The 11/17/2021 10:52, Philipp Zabel wrote:
> 
> Hi Horatio,

Hi Phillip,

> 
> On Wed, 2021-11-17 at 10:18 +0100, Horatiu Vultur wrote:
> > +static int lan966x_reset_switch(struct lan966x *lan966x)
> > +{
> > +     struct reset_control *reset;
> > +     int val = 0;
> > +     int ret;
> > +
> > +     reset = devm_reset_control_get_shared(lan966x->dev, "switch");
> > +     if (IS_ERR(reset))
> > +             dev_warn(lan966x->dev, "Could not obtain switch reset: %ld\n",
> > +                      PTR_ERR(reset));
> > +     else
> > +             reset_control_reset(reset);
> 
> According to the device tree bindings, both resets are required.
> I'd expect this to return on error.
> Is there any chance of the device working with out the switch reset
> being triggered?

The only case that I see is if the bootloader triggers this switch
reset and then when bootloader starts the kernel and doesn't set back
the switch in reset. Is this a valid scenario or is a bug in the
bootloader?

> 
> > +
> > +     reset = devm_reset_control_get_shared(lan966x->dev, "phy");
> > +     if (IS_ERR(reset)) {
> > +             dev_warn(lan966x->dev, "Could not obtain phy reset: %ld\n",
> > +                      PTR_ERR(reset));
> > +     } else {
> > +             reset_control_reset(reset);
> > +     }
> 
> Same as above.
> Consider printing errors with %pe or dev_err_probe().
> 
> > +     lan_wr(SYS_RESET_CFG_CORE_ENA_SET(0), lan966x, SYS_RESET_CFG);
> > +     lan_wr(SYS_RAM_INIT_RAM_INIT_SET(1), lan966x, SYS_RAM_INIT);
> > +     ret = readx_poll_timeout(lan966x_ram_init, lan966x,
> > +                              val, (val & BIT(1)) == 0, READL_SLEEP_US,
> > +                              READL_TIMEOUT_US);
> > +     if (ret)
> > +             return ret;
> > +
> > +     lan_wr(SYS_RESET_CFG_CORE_ENA_SET(1), lan966x, SYS_RESET_CFG);
> > +
> > +     return 0;
> > +}
> > +
> > +static int lan966x_probe(struct platform_device *pdev)
> > +{
> > +     struct fwnode_handle *ports, *portnp;
> > +     struct lan966x *lan966x;
> > +     int err, i;
> > +
> > +     lan966x = devm_kzalloc(&pdev->dev, sizeof(*lan966x), GFP_KERNEL);
> > +     if (!lan966x)
> > +             return -ENOMEM;
> > +
> > +     platform_set_drvdata(pdev, lan966x);
> > +     lan966x->dev = &pdev->dev;
> > +
> > +     ports = device_get_named_child_node(&pdev->dev, "ethernet-ports");
> > +     if (!ports) {
> > +             dev_err(&pdev->dev, "no ethernet-ports child not found\n");
> > +             err = -ENODEV;
> > +             goto out;
> 
> No need to goto as long as there's just a "return err;" after the out:
> label.

True, I will udate this.

> 
> > +     }
> > +
> > +     err = lan966x_create_targets(pdev, lan966x);
> > +     if (err)
> > +             goto out;
> > +
> > +     if (lan966x_reset_switch(lan966x)) {
> > +             err = -EINVAL;
> 
> This should propagate the error returned from lan966x_reset_switch()
> instead.

I will fix it in the next version.

> 
> > +             goto out;
> > +     }
> > +
> > +     i = 0;
> > +     fwnode_for_each_available_child_node(ports, portnp)
> > +             ++i;
> > +
> > +     lan966x->num_phys_ports = i;
> > +     lan966x->ports = devm_kcalloc(&pdev->dev, lan966x->num_phys_ports,
> > +                                   sizeof(struct lan966x_port *),
> > +                                   GFP_KERNEL);
> 
>         if (!lan966x->ports)
>                 return -ENOMEM;

Good catch.

> 
> regards
> Philipp

-- 
/Horatiu

  reply	other threads:[~2021-11-17 21:41 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-17  9:18 [PATCH net-next 0/5] net: lan966x: Add lan966x switch driver Horatiu Vultur
2021-11-17  9:18 ` [PATCH net-next 1/5] dt-bindings: net: lan966x: Add lan966x-switch bindings Horatiu Vultur
2021-11-17  9:18 ` [PATCH net-next 2/5] net: lan966x: add the basic lan966x driver Horatiu Vultur
2021-11-17  9:52   ` Philipp Zabel
2021-11-17 21:42     ` Horatiu Vultur [this message]
2021-11-18 10:19       ` Philipp Zabel
2021-11-18 12:49         ` Horatiu Vultur
2021-11-17  9:18 ` [PATCH net-next 3/5] net: lan966x: add port module support Horatiu Vultur
2021-11-17  9:54   ` Russell King (Oracle)
2021-11-18  9:57     ` Horatiu Vultur
2021-11-18  9:59       ` Russell King (Oracle)
2021-11-18 12:59         ` Horatiu Vultur
2021-11-18 13:31           ` Russell King (Oracle)
2021-11-18 15:36             ` Sean Anderson
2021-11-18 16:11               ` Russell King (Oracle)
2021-11-18 16:18                 ` Sean Anderson
2021-11-19  8:49                   ` Horatiu Vultur
2021-11-17 11:41   ` Russell King (Oracle)
2021-11-17  9:18 ` [PATCH net-next 4/5] net: lan966x: add mactable support Horatiu Vultur
2021-11-17  9:18 ` [PATCH net-next 5/5] net: lan966x: add ethtool configuration and statistics Horatiu Vultur

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=20211117214231.yiv2s6nxl6yx4klq@soft-dev3-1.localhost \
    --to=horatiu.vultur@microchip.com \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    --cc=p.zabel@pengutronix.de \
    --cc=robh+dt@kernel.org \
    /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