ppisa commented on PR #16911:
URL: https://github.com/apache/nuttx/pull/16911#issuecomment-3225180816

   The current main purpose for these operations is to allow 
[PLCA](https://en.wikipedia.org/wiki/PHY-Level_Collision_Avoidance)  
configuration in PHY devices (802.3cg 10BASE-T1S).
   
   Linux kernel uses NetLink for this configuration and command added into 
ethtool, see 
[ethtool.git/tree/netlink/plca.c](https://git.kernel.org/pub/scm/network/ethtool/ethtool.git/tree/netlink/plca.c).
 We have looked into NuttX ethtool and it would be quite lot of rework to 
implement that.
   
   The PLCA configuration operations are provided as methods of PHY
   
   https://elixir.bootlin.com/linux/v6.16.3/source/include/linux/ethtool.h#L1289
   
   For direct MDIO and MDD registers access, Linux kernel provides SIOCGMIIPHY, 
SIOCGMIIREG, SIOCSMIIREG similar as these provided by NuttX.
   
   In Linux kernel, the SIOCGMIIREG, SIOCSMIIREG accepts structure [struct 
ifreq](https://elixir.bootlin.com/linux/v6.16.3/C/ident/ifreq)](https://elixir.bootlin.com/linux/v6.16.3/source/include/uapi/linux/if.h#L234)
 includes pointer field ifru_data which points to the structure  
[mii_ioctl_data](https://elixir.bootlin.com/linux/v6.16.3/source/include/uapi/linux/mii.h#L178).
   
   NuttX does not provide this structure in 
[include/net/if.h](https://github.com/apache/nuttx/blob/master/include/net/if.h#L167).
   
   In Linux, it seems that 
[MDIO_PHY_ID_C45](https://elixir.bootlin.com/linux/v6.16.3/source/include/uapi/linux/mdio.h#L456)
 bit set in `phy_id` field specifies that the `mii_ioctl_data` are in fact MMD 
data. Then the bits 5 to 9 specify PRTAD and bits 0 to 4 DEVAD.
   
   It is possible to define the same mapping in NuttX and reuse 
SIOCGMIIREG/SIOCSMIIREG. Problem is that then all device drivers has to be 
visited to check if they correctly report than   IEEE Std 802.3 Clause 45 MDIO 
Managed Devices (MMD) access is not supported.
   
   Another option is to define some field of other mechanism in NuttX [struct 
net_driver_s](https://github.com/apache/nuttx/blob/f4142626b9b4a161fc67791a9c09965da6fc6ab2/include/nuttx/net/netdev.h#L308)
 which provides information if the Clause 45 is supported.
   
   Actual solution has advantage that devices which do not support MMD report 
by unsupported IOCTL.
   
   In a long term, it would be better to switch to phy register access routines 
which do not pass the pointer to userspace into network drivers and define MDIO 
access inside kernel similar to the Linux solution 
[see](https://elixir.bootlin.com/linux/v6.16.3/source/include/linux/mdio.h#L139)
   
   ```
   int (*mdio_read)(struct net_device *dev, int prtad, int devad, u16 addr);
   int (*mdio_write)(struct net_device *dev, int prtad, int devad, u16 addr, 
u16 val);
   ```
   
   So actual proposal is the least intrusive on the other hand defines new 
IOCTLs, They can be ued only as internal one and external ones can be 
translated to them according to Linux kernel MMD encoding rules.
   
   It is possible to switch to Linux kernel encoding alone, but then we need to 
add some flags to network devices to announce Clause 22 and Clause 45 support.
   
   If even that is not wanted then all network drivers with SIOCGMIIREG, 
SIOCSMIIREG implemented needs to be revised and ensure fail on unsupported 
Clause 45 access.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to