lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ada8f820-ee60-4fac-92cc-91f287e36041@gmx.net>
Date: Thu, 9 May 2024 13:16:11 +0200
From: Hans-Frieder Vogt <hfdevel@....net>
To: FUJITA Tomonori <fujita.tomonori@...il.com>
Cc: andrew@...n.ch, netdev@...r.kernel.org, horms@...nel.org,
 kuba@...nel.org, jiri@...nulli.us, pabeni@...hat.com
Subject: Re: [PATCH net-next v5 5/6] net: tn40xx: add mdio bus support

On 09.05.2024 12.59, FUJITA Tomonori wrote:
> Hi,
>
> On Thu, 9 May 2024 11:52:46 +0200
> Hans-Frieder Vogt <hfdevel@....net> wrote:
>
>> A small addition here:
>> digging through an old Tehuti linux river for the TN30xx (revision
>> 7.33.5.1) I found revealing comments:
>> in bdx_mdio_read:
>>          /* Write read command */
>>          writel(MDIO_CMD_STAT_VAL(1, device, port), regs +
>> regMDIO_CMD_STAT);
>> in bdx_mdio_write:
>>          /* Write write command */
>>          writel(MDIO_CMD_STAT_VAL(0, device, port), regs +
>> regMDIO_CMD_STAT);
>>
>> The CMD register has a different layout in the TN40xx, but the logic
>> is
>> similar.
>> Therefore, I conclude now that the value (1 << 15)  is in fact a read
>> flag. Maybe it could be defined like:
>>
>> #define TN40_MDIO_READ    BIT(15)
> Thanks a lot!
>
> So worth adding MDIO_CMD_STAT_VAL macro and TN40_MDIO_CMD_READ
> definition?
>
>
> diff --git a/drivers/net/ethernet/tehuti/tn40_mdio.c b/drivers/net/ethernet/tehuti/tn40_mdio.c
> index 64ef7f40f25d..d2e4b4d5ee9a 100644
> --- a/drivers/net/ethernet/tehuti/tn40_mdio.c
> +++ b/drivers/net/ethernet/tehuti/tn40_mdio.c
> @@ -7,6 +7,10 @@
>
>   #include "tn40.h"
>
> +#define TN40_MDIO_CMD_STAT_VAL(device, port) \
> +	(((device) & MDIO_PHY_ID_DEVAD) | (((port) << 5) & MDIO_PHY_ID_PRTAD))

As Andrew pointed out, using the definitions from uapi/linux/mdio.h is a
bad idea, because it is just a coincidence that the definitions work in
this case.
So it is better to use specific defines for TN40xx, for example:

#define TN40_MDIO_DEVAD_MASK    0x001f
#define TN40_MDIO_PRTAD_MASK    0x03e0
#define TN40_MDIO_CMD_VAL(device, port) \
         (((device) & TN40_MDIO_DEVAD_MASK( | (((port) << 5) &
TN40_MDIO_PRTAD_MASK))

note that I left out the _STAT_ from the TN40_MDIO_CMD_VAL, because in
TN40xx the CMD and STAT registers are separate (different from the
TN30xx example).

> +#define TN40_MDIO_CMD_READ BIT(15)
> +
>   static void tn40_mdio_set_speed(struct tn40_priv *priv, u32 speed)
>   {
>   	void __iomem *regs = priv->regs;
> @@ -48,13 +52,13 @@ static int tn40_mdio_read(struct tn40_priv *priv, int port, int device,
>   	if (tn40_mdio_get(priv, NULL))
>   		return -EIO;
>
> -	i = ((device & 0x1F) | ((port & 0x1F) << 5));
> +	i = TN40_MDIO_CMD_STAT_VAL(device, port);
>   	writel(i, regs + TN40_REG_MDIO_CMD);
>   	writel((u32)regnum, regs + TN40_REG_MDIO_ADDR);
>   	if (tn40_mdio_get(priv, NULL))
>   		return -EIO;
>
> -	writel(((1 << 15) | i), regs + TN40_REG_MDIO_CMD);
> +	writel(TN40_MDIO_CMD_READ | i, regs + TN40_REG_MDIO_CMD);
>   	/* read CMD_STAT until not busy */
>   	if (tn40_mdio_get(priv, NULL))
>   		return -EIO;
> @@ -73,8 +77,7 @@ static int tn40_mdio_write(struct tn40_priv *priv, int port, int device,
>   	/* wait until MDIO is not busy */
>   	if (tn40_mdio_get(priv, NULL))
>   		return -EIO;
> -	writel(((device & 0x1F) | ((port & 0x1F) << 5)),
> -	       regs + TN40_REG_MDIO_CMD);
> +	writel(TN40_MDIO_CMD_STAT_VAL(device, port), regs + TN40_REG_MDIO_CMD);
>   	writel((u32)regnum, regs + TN40_REG_MDIO_ADDR);
>   	if (tn40_mdio_get(priv, NULL))
>   		return -EIO;

Thanks!
Hans


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ