Re: [PATCH net-next v8 4/4] net: dsa: add basic initial driver for MxL862xx switches

From: Daniel Golle

Date: Tue Jan 27 2026 - 11:12:05 EST


On Tue, Jan 27, 2026 at 04:04:10PM +0100, Andrew Lunn wrote:
> > > int mxl862xx_to_zephyr_errno(u16 reg)
> > so that would then just be
> > return (s16)reg;
> > right?
>
> Yes.

+1

Maybe better to check if bit 16~31 is actually zero as well, so
int mxl862xx_to_zephyr_errno(int reg)
{
if (reg >= 0 && reg <= U16_MAX)
return (s16)reg;

return 0;
}

or

int mxl862xx_to_zephyr_errno(int reg)
{
if (!(reg & GENMASK(31, 16))
return (s16)reg;

return 0;
}

or something like that. Let me know what you prefer.


>
> >
> > Or did you think to include the handling of the error __mdiodev_c45_read()
> > would return, ie.
> > int mxl862xx_to_zephyr_errno(int reg)
> > {
> > if (reg < 0)
> > return reg;
>
> No, that mixes up real linux error codes and Zephyr OS error codes.

I thought of that 'int reg' to be the return value of
__mdiodev_c45_read(), so if that 32-bit signed int < 0 that means what
you get is the error returned from __mdiodev_c45_read().

>
> If the MDIO operation fails, you have a real error code you can
> return. If the firmware fails, you will want to netdev_err() the
> Zephyr error code to aid debug, and then return -EIO.

+1


>
> > Or actually translating the actual errno to a Linux error code?
>
> Is it worth the effort? How many times have you seen the firmware
> fail? During debugging, it might be useful, but in production?

Some of the error values are useful, it *is* good to know whether eg. a
bridge cannot be allocated because (for what ever reason) of resource
exhaustion (-ENOMEM) or because of otherwise invalid settings (-EINVAL).
However, it is true that in production none of that should ever happen.
The driver will be able to predict and manage the resources of the
switch without ever hitting -ENOMEM, and make sure parameters are valid
before passing anything to the firmware. And even during development it
is good enough to see the error number in the netdev_err() output.