Skip to content

ioctl: add SIOCETHTOOL#102

Open
julianuziemblo wants to merge 7 commits into
masterfrom
julianuziemblo/implement-siocethtool
Open

ioctl: add SIOCETHTOOL#102
julianuziemblo wants to merge 7 commits into
masterfrom
julianuziemblo/implement-siocethtool

Conversation

@julianuziemblo

@julianuziemblo julianuziemblo commented May 26, 2025

Copy link
Copy Markdown
Contributor

Description

Add ethtool handling by the driver
Add simple ethtool implementations to ethernet drivers

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

Comment thread drivers/imx-enet.c Outdated

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

Copy link
Copy Markdown

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.

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

Copy link
Copy Markdown

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.

Comment thread drivers/imx-enet.c
Comment thread drivers/imx-enet.c
Comment thread drivers/imx-enet.c
Comment thread drivers/imx-enet.c Outdated
Comment thread drivers/imx-enet.c
@julianuziemblo julianuziemblo force-pushed the julianuziemblo/implement-siocethtool branch 2 times, most recently from 83b5c93 to 0eeb14a Compare May 27, 2025 08:46
Comment thread drivers/imx-enet.c Outdated
@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
Comment thread drivers/rtl8139cp.c Outdated
@julianuziemblo julianuziemblo force-pushed the julianuziemblo/implement-siocethtool branch 4 times, most recently from 3bf5a8a to bef66ef Compare July 28, 2025 14:25
Comment thread drivers/ephy.c Outdated
@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 force-pushed the julianuziemblo/fix-ethpad-handling branch 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
@julianuziemblo julianuziemblo force-pushed the julianuziemblo/implement-siocethtool branch from 76a8b6b to f7dffef Compare January 15, 2026 16:54
@julianuziemblo julianuziemblo force-pushed the julianuziemblo/implement-siocethtool branch 9 times, most recently from ecc2d78 to 5306708 Compare January 28, 2026 16:06
@julianuziemblo julianuziemblo changed the base branch from master to julianuziemblo/RTOS-1205 January 28, 2026 16:07
@julianuziemblo julianuziemblo force-pushed the julianuziemblo/RTOS-1205 branch from a01abc2 to 2e1b201 Compare February 18, 2026 11:27
@julianuziemblo julianuziemblo force-pushed the julianuziemblo/RTOS-1205 branch from 2e1b201 to dc47a03 Compare February 27, 2026 15:13
@julianuziemblo julianuziemblo force-pushed the julianuziemblo/RTOS-1205 branch 2 times, most recently from 04711f7 to 57ebfea Compare March 12, 2026 08:42
Base automatically changed from julianuziemblo/RTOS-1205 to master March 12, 2026 10:38
@julianuziemblo julianuziemblo force-pushed the julianuziemblo/implement-siocethtool branch from 5306708 to 93737e4 Compare March 12, 2026 13:59
ethernet driver can now specify a function to handle the ethtool ioctl
add handling for simple ethtool commands in imx-enet

JIRA: RTOS-1014
@julianuziemblo julianuziemblo force-pushed the julianuziemblo/implement-siocethtool branch from 93737e4 to 2e64b2e Compare March 12, 2026 14:07
Selftest is a pretty generic procedure that can be done
inside other drivers too (e.g. rtl8139cp driver).

JIRA: RTOS-508
TODO: For now, selftest on this target is not working.
Examine why or remove this commit for now.

JIRA: RTOS-508
@julianuziemblo julianuziemblo force-pushed the julianuziemblo/implement-siocethtool branch from 2e64b2e to 638873c Compare March 12, 2026 14:13
@github-actions

Copy link
Copy Markdown

Unit Test Results

9 553 tests  ±0   8 961 ✅ ±0   52m 32s ⏱️ -7s
  591 suites ±0     592 💤 ±0 
    1 files   ±0       0 ❌ ±0 

Results for commit 638873c. ± Comparison against base commit 04e2c00.

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.

1 participant