From 8fc63aaa107cbf04cba87104902f50766a836dab Mon Sep 17 00:00:00 2001 From: michal matias Date: Wed, 27 Aug 2025 21:42:05 +0200 Subject: [PATCH] include/net/if.h: Add mechanism for MMD access with SIOCxMIIREG ioctls Add mdio_phy_id_c45 macro. This macro allows encoding of additional information needed for MMD access into the phy_id field of the mii_ioctl_data_s structure. This macro is intended for use by user applications. Add macros for decoding the phy_id encoded with the mdio_phy_id_c45 macro. These macros are intended for use by network drivers implementing SIOCxMIIREG commands. Signed-off-by: michal matias --- include/net/if.h | 11 +++++++++++ include/nuttx/net/netdev.h | 14 +++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/include/net/if.h b/include/net/if.h index 7afcc2d15a..2e869d6b24 100644 --- a/include/net/if.h +++ b/include/net/if.h @@ -127,6 +127,17 @@ # define IFF_IS_IPv4(f) (1) #endif +/* MDIO Manageable Device (MMD) support with SIOCxMIIREG ioctl commands */ + +#define MDIO_PHY_ID_C45 0x8000 +#define MDIO_PHY_ID_PRTAD 0x03E0 +#define MDIO_PHY_ID_DEVAD 0x001F +#define MDIO_PHY_ID_C45_MASK \ + (MDIO_PHY_ID_C45 | MDIO_PHY_ID_PRTAD | MDIO_PHY_ID_DEVAD) + +#define mdio_phy_id_c45(prtad, devad) \ + ((uint16_t)(MDIO_PHY_ID_C45 | ((prtad) << 5) | (devad))) + /* RFC 2863 operational status */ enum diff --git a/include/nuttx/net/netdev.h b/include/nuttx/net/netdev.h index c31ce180d7..460420b74c 100644 --- a/include/nuttx/net/netdev.h +++ b/include/nuttx/net/netdev.h @@ -2,7 +2,8 @@ * include/nuttx/net/netdev.h * * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2007, 2009, 2011-2018 Gregory Nutt. All rights reserved. + * SPDX-FileCopyrightText: 2007,2009 Gregory Nutt. All rights reserved. + * SPDX-FileCopyrightText: 2011-2018 Gregory Nutt. All rights reserved. * SPDX-FileCopyrightText: 2001-2003, Adam Dunkels. All rights reserved. * SPDX-FileContributor: Gregory Nutt * @@ -216,6 +217,17 @@ (netdev_ipv6_lookup(dev, addr, true) != NULL) #endif +/* MDIO Manageable Device (MMD) support with SIOCxMIIREG ioctl commands */ + +#define mdio_phy_id_is_c45(phy_id) \ + (((phy_id) & MDIO_PHY_ID_C45) && !((phy_id) & ~MDIO_PHY_ID_C45_MASK)) + +#define mdio_phy_id_prtad(phy_id) \ + ((uint16_t)(((phy_id) & MDIO_PHY_ID_PRTAD) >> 5)) + +#define mdio_phy_id_devad(phy_id) \ + ((uint16_t)((phy_id) & MDIO_PHY_ID_DEVAD)) + /**************************************************************************** * Public Types ****************************************************************************/