-
Notifications
You must be signed in to change notification settings - Fork 1.5k
net/netdev/netdev_ioctl.c: Add new ioctls for MMD register access #16911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Add SIOCGMMDREG and SIOCSMMDREG ioctl commands with accompanying logic. SIOCGMMDREG: Get MMD register. SIOCGMMDREG: Set MMD register. MMD registers are an extension to the MII management interface, both defined in IEEE 802.3. Signed-off-by: michal matias <mich4l.matias@gmail.com>
|
@matiamic please update https://nuttx.apache.org/docs/latest/components/net/netdev.html to contain this new struct and ioctl. |
| uint8_t mmd; /* MMD number */ | ||
| uint16_t addr; /* Address in the selected MMD */ | ||
| uint16_t data; /* Input / Output data */ | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does the new struct and ioctl number follow Linux definition? @matiamic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think Linux uses SIOCETHTOOL exclusively to access MMD registers. The SIOCxMMDREG op is not present in Linux.
|
The current main purpose for these operations is to allow PLCA 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. 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 include/uapi/linux/if.h includes pointer field ifru_data which points to the structure mii_ioctl_data. NuttX provides this structure in include/net/if.h. In Linux, it seems that MDIO_PHY_ID_C45 bit set in 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 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 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. |
|
Thanks for the detailed explanation.
but the driver which implement SIOCGMIIREG/SIOCSMIIREG suppose to check phy_id and reject the unknown id anyway regardless whether the unknown id is related to MDD, so why do we need do the check before invoke netdev->ioctl.
yes, after we finish the public interface definition, we can add the new callback to netdev driver.
But, it' s always the driver's responsibility to reject the unknown phy id. |
|
Thank you @ppisa for the detailed explanation and for correcting me on this. @xiaoxiang781216 Even though the responsibility is on the driver side, I skimmed through a dozen of net drivers implementing SIOCxMIIREG ioctls and I couldn't find one that actually checks for valid phyid. The most I've seen a driver do is to mask top 11 bits. |
|
@xiaoxiang781216 and @matiamic . I think that some flags or callback into struct net_driver_s should be added which inform if Clause 22 or 45 or both are supported. Linux kernel checks that on base of the list registered PHY per network device, see Only thing to decide is if it should go into some struct net_driver_s field or query function. For flags, d_flags / IFF_xxx is more runtime control, state, not features. d_lltype is not flag based. So some new field or capability query function d_qeury. or it can be internal ioctl to query features which would call d_ioctl and if it is not implemented by driver it would report some default for now... I.e. C22 support. |
|
I have opened a new pull request #16926. I approached the MMD access the way it is approached in Linux using SIOCxMIIREG commands. No new ioctl commands are introduced. |
to support per netdev checksum offload, we add d_features to net_driver_s recently, we can add MDIO_SUPPORTS_C45 to this field. |
|
The Linux kernel style for MMD PHY registers access is proposed in alternative pull request #16926 which superseded this request if approved. Combining of Clause 22 and Clause 45 accesses in the single IOCTL is a little more readable but does not resources for another and NuttX specific IOCTL. There should be followup discussion how to report which MACs are acapable of C45 accesses to PHYs. All controllers with MDIO IOCTLs support should be revised to not attempt interpret incorrect way C45 as C22 and vice versa. Current state is that there are even no checks that classical MDIO addresses and registers are in range. But it should be discussed the first and is mostly another topic than MMD and PLCA for T1S. |
The following is a list of drivers that might need to be revisited. |
|
There is great potential to enhance NuttX networking documentation from @matiamic bachelor thesis. We have already discussed it locally and mentioned on the list. But it would not fit into GSoC time unfortunately. On the other hand, I consider final T1S state as big success myself. But it is still to be reviewed by others) as really very good, including more different chips (thanks to OnSemi provided kits and tools and other lent from VZLU who have tested more manufacturers MAC-PHY underradiation as future potential technology for their space applications. |
|
since #16926 is merged, we can close this pr now. |
|
@matiamic yes, I read Michal's bachelor thesis some weeks ago and it is really good, he explains many things about netdev that the NuttX documentation doesn't explain. |
Summary
This patch adds SIOCGMMDREG and SIOCSMMDREG ioctl commands with accompanying logic.
SIOCGMMDREG: Get MMD register.
SIOCGMMDREG: Set MMD register.
A new structure
mmd_ioctl_data_sis introduced intoinclude/net/if.hin order to accommodate command data.MMD registers are an extension to the MII management interface, both are defined in IEEE 802.3.
Impact
Network drivers may implement these ioctl commands. When implemented, PHY features configurable by
MMD access can now be managed from the user application.
Testing
The testing was performed by a testing application during development of a driver for 10BASE-T1x SPI MAC-PHYs.
This mechanism was used to control PHY behavior, especially to configure 10BASE-T1S PLCA access method.