Skip to content

Conversation

@julianuziemblo
Copy link
Contributor

@julianuziemblo julianuziemblo commented May 26, 2025

Description

  • port/sockets: adjust to special ioctl changes
    Special ioctls (e.g. those with pointer in the input strucutre) are now
    packed in userspace instead of kernel, and we have to unpack those here
    properly.
    Also: fix SIOCGIFCONF fixme note by handling it as described in POSIX.

  • drivers: add ethtool ioctl handling by the driver
    ethernet driver can now specify a function to handle the ethtool ioctl
    add handling for simple ethtool commands in imx-enet

  • drivers/imx-enet: add interface loopback get/set handling

  • drivers/ephy: fix loopback enable on RTL8201FI-VC-CG/RTL8211FDI-CG
    the loopback functionality seems not to be working properly without the wait
    on supported RTL PHYs on target imxrt117x-evkb

  • drivers/rtl8139cp: add interface loopback get/set handling

  • drivers: pull out enet_selftest to separate file
    Selftest is a pretty generic procedure that can be done
    inside other drivers too (e.g. rtl8139cp driver).

  • drivers/rtl8139cp: add selftest

Motivation and Context

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (refactoring, style fixes, git/CI config, submodule management, no code logic changes)

How Has This Been Tested?

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing linter checks and tests passed
    • checks will not be passing due to related PRs
  • My changes generate no new compilation warnings for any of the targets.

Special treatment

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @julianuziemblo, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

Hello! Gemini or gemini-code-assist here, providing a summary of this pull request by @julianuziemblo.

This pull request introduces support for the SIOCETHTOOL ioctl command, allowing userspace applications to query and potentially configure Ethernet device parameters using the standard ethtool interface. This is a significant step towards providing more standard network management capabilities.

The changes involve refactoring how certain ioctls with pointer arguments are handled in the sockets layer, ensuring they are correctly unpacked in userspace. It also includes updates to the network interface driver structure to accommodate a new function pointer for handling ethtool-specific ioctls. Finally, the imx-enet driver is updated to implement this new interface and provide basic ethtool functionality, such as retrieving link settings (speed, duplex, autonegotiation, MDI/MDIX state) and potentially running PHY self-tests.

This PR is marked as a new feature and requires companion changes in the kernel and libphoenix repositories.

Highlights

  • Add SIOCETHTOOL ioctl: Introduces the SIOCETHTOOL ioctl command in the sockets layer, enabling standard ethtool operations for network interfaces.
  • Refactor ioctl handling: Adjusts the sockets implementation to correctly handle ioctls that involve pointer arguments or variable-length data in userspace, specifically fixing the handling of SIOCGIFCONF to comply with POSIX (allowing size queries) and SIOCADDRT/SIOCDELRT to correctly parse the device name.
  • Driver ethtool support: Adds a new do_ethtool_ioctl function pointer to the netif_driver_t structure, allowing individual network drivers to provide their own ethtool command handlers.
  • imx-enet driver implementation: Updates the imx-enet driver to implement the new do_ethtool_ioctl interface, providing support for several ethtool commands (ETHTOOL_GSET, ETHTOOL_GSSET_INFO, ETHTOOL_GSTRINGS, ETHTOOL_TEST, ETHTOOL_GLINKSETTINGS) by querying the PHY state.

Changelog

Click here to see the changelog
  • drivers/ephy.c
    • Renamed full_duplex variable to duplex for clarity.
    • Updated ephy_setLinkState and ephy_linkSpeed to use SPEED_* and DUPLEX_* constants and handle unknown states during auto-negotiation.
    • Added ephy_getAN, ephy_setAN, and ephy_getMdix functions to retrieve/set autonegotiation state and get MDI/MDIX status from the PHY.
  • drivers/ephy.h
    • Included phoenix/ethtool.h.
    • Defined EPHY_SPEEDS macro for ethtool advertising flags.
    • Updated function declarations for ephy_linkSpeed, ephy_getAN, ephy_setAN, and ephy_getMdix.
  • drivers/imx-enet.c
    • Included phoenix/ethtool.h.
    • Changed ENET_SELFTEST define from 0 to 1.
    • Removed the direct call to enet_phySelfTest from enet_netifInit.
    • Updated enet_media to use SPEED_* and DUPLEX_* constants.
    • Implemented enet_ethtoolIoctl to handle various ethtool commands by querying the PHY state.
    • Added enet_ethtoolIoctl to the enet_drv structure.
  • include/netif-driver.h
    • Added do_ethtool_ioctl function pointer to the netif_driver_t structure.
  • port/sockets.c
    • Included netif-driver.h.
    • Refactored SIOCGIFCONF handling to correctly support querying the required buffer size (POSIX compliance).
    • Refactored SIOCADDRT/SIOCDELRT handling to correctly extract the device name from the input buffer.
    • Added handling for the new SIOCETHTOOL ioctl, delegating the call to the specific network driver's handler.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


Network calls take flight,
Ioctl commands, a key,
Driver does the work.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces SIOCETHTOOL support, which is a valuable addition for network interface inspection and control. The changes also include refactoring for SIOCGIFCONF to align better with POSIX standards and adjustments to how routing ioctls handle their data. The introduction of more descriptive enums for speed and duplex in the PHY layer (ephy.c) improves code clarity.

Overall, the changes are well-structured. I've identified a few issues that should be addressed to ensure correctness and robustness.

Summary of Findings

  • Duplicate Header Include: The file drivers/imx-enet.c includes <phoenix/ethtool.h> twice, which is redundant and could lead to issues.
  • Incorrect Media Strings: The enet_media function in drivers/imx-enet.c returns swapped strings for full/half duplex modes across different speeds (10/100/1000 Mbps).
  • Potential Buffer Overflow in ETHTOOL_GLINKSETTINGS: In drivers/imx-enet.c, the ETHTOOL_GLINKSETTINGS handler might write beyond the allocated buffer for link_mode_masks if the caller provides an insufficient link_mode_masks_nwords.

Merge Readiness

The pull request introduces valuable ethtool functionality and improves existing ioctl handling. However, there are a few high and medium severity issues identified (duplicate header, incorrect media strings, potential buffer overflow) that should be addressed before merging to ensure correctness and stability. I am not authorized to approve pull requests, so please ensure these changes are reviewed and approved by the appropriate maintainers after the suggested modifications are made.

@julianuziemblo julianuziemblo force-pushed the julianuziemblo/implement-siocethtool branch 2 times, most recently from 83b5c93 to 0eeb14a Compare May 27, 2025 08:46
@julianuziemblo julianuziemblo force-pushed the julianuziemblo/implement-siocethtool branch from 0eeb14a to 473a4bd Compare May 27, 2025 08:56
@julianuziemblo julianuziemblo force-pushed the julianuziemblo/implement-siocethtool branch 2 times, most recently from a261fd6 to 5f704f6 Compare May 28, 2025 12:02
@julianuziemblo julianuziemblo force-pushed the julianuziemblo/implement-siocethtool branch 2 times, most recently from 77ac270 to d3cbf78 Compare June 6, 2025 09:16
@julianuziemblo julianuziemblo force-pushed the julianuziemblo/implement-siocethtool branch from d3cbf78 to 2fe49ee Compare July 22, 2025 10:08
@julianuziemblo julianuziemblo force-pushed the julianuziemblo/implement-siocethtool branch from 2fe49ee to 269f31d Compare July 24, 2025 09:57
@julianuziemblo julianuziemblo force-pushed the julianuziemblo/implement-siocethtool branch 4 times, most recently from 3bf5a8a to bef66ef Compare July 28, 2025 14:25
@julianuziemblo julianuziemblo force-pushed the julianuziemblo/implement-siocethtool branch 2 times, most recently from 9a99139 to 218f0e9 Compare July 30, 2025 15:11
@julianuziemblo julianuziemblo force-pushed the julianuziemblo/implement-siocethtool branch from 218f0e9 to e5a292a Compare August 27, 2025 10:20
@julianuziemblo julianuziemblo changed the base branch from master to julianuziemblo/fix-ethpad-handling August 29, 2025 16:14
@julianuziemblo julianuziemblo force-pushed the julianuziemblo/implement-siocethtool branch from b73b7e0 to fb0fbb6 Compare August 29, 2025 16:14
@julianuziemblo julianuziemblo force-pushed the julianuziemblo/fix-ethpad-handling branch from 641d0af to b6e9f1a Compare September 2, 2025 11:11
@julianuziemblo julianuziemblo force-pushed the julianuziemblo/implement-siocethtool branch from fb0fbb6 to 802e7ba Compare September 2, 2025 12:45
@julianuziemblo julianuziemblo force-pushed the julianuziemblo/implement-siocethtool branch from 802e7ba to 0f96937 Compare September 26, 2025 14:29
@julianuziemblo julianuziemblo force-pushed the julianuziemblo/fix-ethpad-handling branch from b6e9f1a to de1b5a6 Compare September 26, 2025 14:29
@julianuziemblo julianuziemblo force-pushed the julianuziemblo/implement-siocethtool branch 2 times, most recently from 4017476 to 76a8b6b Compare September 26, 2025 15:34
@julianuziemblo julianuziemblo force-pushed the julianuziemblo/fix-ethpad-handling branch 6 times, most recently from 4333806 to 5e69166 Compare October 30, 2025 11:10
@julianuziemblo julianuziemblo force-pushed the julianuziemblo/fix-ethpad-handling branch 4 times, most recently from 00f4943 to c6e22ce Compare December 18, 2025 09:28
Base automatically changed from julianuziemblo/fix-ethpad-handling to master December 18, 2025 10:29
Special ioctls (e.g. those with pointer in the input strucutre) are now
packed in userspace instead of kernel, and we have to unpack those here
properly.
Also: fix SIOCGIFCONF fixme note by handling it as described in POSIX.

JIRA: RTOS-1014
ethernet driver can now specify a function to handle the ethtool ioctl
add handling for simple ethtool commands in imx-enet

JIRA: RTOS-1014
Selftest is a pretty generic procedure that can be done
inside other drivers too (e.g. rtl8139cp driver).

JIRA: RTOS-508
@julianuziemblo julianuziemblo force-pushed the julianuziemblo/implement-siocethtool branch from 76a8b6b to f7dffef Compare January 15, 2026 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants