This is an automated email from the ASF dual-hosted git repository.

GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new b2b0bde9d0f net/ethtool: add ethtool-ioctl to get/set hardware channel 
info
b2b0bde9d0f is described below

commit b2b0bde9d0f554c25cf997919172761af7abbf82
Author: gaohedong <[email protected]>
AuthorDate: Sun Oct 19 11:58:33 2025 +0800

    net/ethtool: add ethtool-ioctl to get/set hardware channel info
    
    Add ETHTOOL_GCHANNELS/ETHTOOL_SCHANNELS (count based, Linux compatible)
    and ETHTOOL_GCHANNELS2/ETHTOOL_SCHANNELS2 (bitmask based) support to the
    netdev upper-half driver.
    
    A new optional struct ethtool_ops_s is added to struct netdev_lowerhalf_s
    (eth_ops) so that lower-half drivers can implement these operations.
    netdev_upper_ioctl() dispatches SIOCETHTOOL requests to eth_ops when it is
    provided by the driver. The feature is guarded by the new
    CONFIG_NETDEV_ETHTOOL_IOCTL option.
    
    Signed-off-by: gaohedong <[email protected]>
---
 drivers/net/netdev_upperhalf.c       | 85 ++++++++++++++++++++++++++++++++++++
 include/nuttx/ethtool.h              | 69 +++++++++++++++++++++++++----
 include/nuttx/net/netdev_lowerhalf.h | 34 +++++++++++++++
 net/netdev/Kconfig                   |  8 ++++
 4 files changed, 188 insertions(+), 8 deletions(-)

diff --git a/drivers/net/netdev_upperhalf.c b/drivers/net/netdev_upperhalf.c
index 36c5ebd38cc..82fef7e1f87 100644
--- a/drivers/net/netdev_upperhalf.c
+++ b/drivers/net/netdev_upperhalf.c
@@ -1000,6 +1000,80 @@ static int netdev_upper_txavail(FAR struct net_driver_s 
*dev)
   return OK;
 }
 
+/****************************************************************************
+ * Name: netdev_upper_ethtool_ioctl
+ *
+ * Description:
+ *   Handle upper layer ethtool IOCTL commands for a network device.
+ *   This function processes ethtool-related IOCTL requests that are handled
+ *   at the upper network layer, interacting with the specified network
+ *   device.
+ *
+ * Input Parameters:
+ *   dev - Pointer to the network driver structure (struct net_driver_s)
+ *         representing the network device to operate on.
+ *   arg - IOCTL command argument. The specific type and interpretation
+ *         depend on the ethtool command being processed (e.g., may point to
+ *         an struct ethtool_cmd or other ethtool-related data structure).
+ *
+ * Returned Value:
+ *   On success, returns 0.
+ *   On failure, returns a negative error code.
+ ****************************************************************************/
+
+#ifdef CONFIG_NETDEV_ETHTOOL_IOCTL
+static int netdev_upper_ethtool_ioctl(FAR struct net_driver_s *dev,
+                                      unsigned long arg)
+{
+  FAR struct netdev_upperhalf_s *upper = dev->d_private;
+  FAR struct netdev_lowerhalf_s *lower = upper->lower;
+  uint32_t cmd = *(FAR const uint32_t *)arg;
+  int ret = -EOPNOTSUPP;
+
+  switch (cmd)
+    {
+      case ETHTOOL_GCHANNELS:
+        if (lower->eth_ops->get_channels)
+          {
+            ret = lower->eth_ops->get_channels(lower,
+                                  (FAR struct ethtool_chns *)arg);
+          }
+        break;
+
+      case ETHTOOL_SCHANNELS:
+        if (lower->eth_ops->set_channels)
+          {
+            ret = lower->eth_ops->set_channels(lower,
+                                  (FAR struct ethtool_chns *)arg);
+          }
+        break;
+
+      case ETHTOOL_GCHANNELS2:
+        if (lower->eth_ops->get_channels2)
+          {
+            ret = lower->eth_ops->get_channels2(lower,
+                                  (FAR struct ethtool_chns2 *)arg);
+          }
+        break;
+
+      case ETHTOOL_SCHANNELS2:
+        if (lower->eth_ops->set_channels2)
+          {
+            ret = lower->eth_ops->set_channels2(lower,
+                                  (FAR struct ethtool_chns2 *)arg);
+          }
+        break;
+
+      default:
+        ret = -ENOTTY;
+        nerr("ERROR: No such cmd in ethtool opt!");
+        break;
+    }
+
+  return ret;
+}
+#endif
+
 /****************************************************************************
  * Name: netdev_upper_wireless_ioctl
  *
@@ -1458,6 +1532,17 @@ static int netdev_upper_ioctl(FAR struct net_driver_s 
*dev, int cmd,
     }
 #endif
 
+#ifdef CONFIG_NETDEV_ETHTOOL_IOCTL
+  if (cmd == SIOCETHTOOL && lower->eth_ops)
+    {
+      ret = netdev_upper_ethtool_ioctl(dev, arg);
+      if (ret != -ENOTTY)
+        {
+          return ret;
+        }
+    }
+#endif
+
 #ifdef CONFIG_NETDEV_WIRELESS_HANDLER
   if (lower->iw_ops)
     {
diff --git a/include/nuttx/ethtool.h b/include/nuttx/ethtool.h
index 79da67762cb..981193a1483 100644
--- a/include/nuttx/ethtool.h
+++ b/include/nuttx/ethtool.h
@@ -127,6 +127,11 @@
 #define ETHTOOL_PHY_STUNABLE  0x0000004f /* Set PHY tunable configuration */
 #define ETHTOOL_GFECPARAM     0x00000050 /* Get FEC settings */
 #define ETHTOOL_SFECPARAM     0x00000051 /* Set FEC settings */
+#define ETHTOOL_GCHANNELS2    0x00000052 /* Get status information of \
+                                          * channels and return it in the \
+                                          * form of bitmap
+                                          **/
+#define ETHTOOL_SCHANNELS2    0x00000053 /* Turn on/off channels */
 
 /* Duplex, half or full. */
 
@@ -262,17 +267,17 @@ struct ethtool_cmd
   uint32_t supported;
   uint32_t advertising;
   uint16_t speed;
-  uint8_t duplex;
-  uint8_t port;
-  uint8_t phy_address;
-  uint8_t transceiver;
-  uint8_t autoneg;
-  uint8_t mdio_support;
+  uint8_t  duplex;
+  uint8_t  port;
+  uint8_t  phy_address;
+  uint8_t  transceiver;
+  uint8_t  autoneg;
+  uint8_t  mdio_support;
   uint32_t maxtxpkt;
   uint32_t maxrxpkt;
   uint16_t speed_hi;
-  uint8_t eth_tp_mdix;
-  uint8_t eth_tp_mdix_ctrl;
+  uint8_t  eth_tp_mdix;
+  uint8_t  eth_tp_mdix_ctrl;
   uint32_t lp_advertising;
   uint32_t reserved[2];
 };
@@ -352,4 +357,52 @@ struct ethtool_value
   uint32_t data;
 };
 
+/* struct ethtool_chns - configuring number of network channel
+ * cmd: ETHTOOL_{G,S}CHANNELS
+ * max_rx: Read only. Maximum number of receive channel the driver support.
+ * max_tx: Read only. Maximum number of transmit channel the driver support.
+ * max_other: Read only. Maximum number of other channel the driver support.
+ * max_combined: Read only. Maximum number of combined channel the driver
+ *    support. Set of queues RX, TX or other.
+ * rx_count: Valid values are in the range 1 to the max_rx.
+ * tx_count: Valid values are in the range 1 to the max_tx.
+ * other_count: Valid values are in the range 1 to the max_other.
+ * combined_count: Valid values are in the range 1 to the max_combined.
+ *
+ * This can be used to configure RX, TX and other channels.
+ */
+
+struct ethtool_chns
+{
+  uint32_t cmd;
+  uint32_t max_rx;
+  uint32_t max_tx;
+  uint32_t max_other;
+  uint32_t max_combined;
+  uint32_t rx_count;
+  uint32_t tx_count;
+  uint32_t other_count;
+  uint32_t combined_count;
+};
+
+/* struct ethtool_chns2 - Configure the network channels in the form of
+ *      bitmask.
+ * cmd: ETHTOOL_{G,S}CHANNELS2
+ * rx_chns_map: Bitmask of receive channels. For example: 0x05 means channel
+ *      0 and channel 2 is enabled for receiving, other channels are disabled
+ *      for receiving.
+ * tx_chns_map: Bitmask of transmit channels.
+ * combined_chns_map: Bitmask of combined channels.
+ *
+ * This can be used to configure RX, TX and other channels.
+ */
+
+struct ethtool_chns2
+{
+  uint32_t cmd;
+  uint32_t rx_chns_map;
+  uint32_t tx_chns_map;
+  uint32_t combined_chns_map;
+};
+
 #endif /* __INCLUDE_NUTTX_ETHTOOL_H */
diff --git a/include/nuttx/net/netdev_lowerhalf.h 
b/include/nuttx/net/netdev_lowerhalf.h
index c471eee2f01..9bbc241cb62 100644
--- a/include/nuttx/net/netdev_lowerhalf.h
+++ b/include/nuttx/net/netdev_lowerhalf.h
@@ -40,6 +40,7 @@
 #include <nuttx/net/net.h>
 #include <nuttx/net/netdev.h>
 #include <nuttx/wireless/wireless.h>
+#include <nuttx/ethtool.h>
 
 /****************************************************************************
  * Pre-processor Definitions
@@ -111,6 +112,7 @@ enum netdev_rx_e
 
 struct netdev_ops_s;
 struct wireless_ops_s;
+struct ethtool_ops_s;
 struct phy_device_s;
 
 struct netdev_lowerhalf_s
@@ -119,6 +121,10 @@ struct netdev_lowerhalf_s
 
   /* Extended operations. */
 
+#ifdef CONFIG_NETDEV_ETHTOOL_IOCTL
+  FAR const struct ethtool_ops_s *eth_ops;
+#endif
+
 #ifdef CONFIG_NETDEV_WIRELESS_HANDLER
   FAR const struct wireless_ops_s *iw_ops;
 #endif
@@ -245,6 +251,34 @@ struct wireless_ops_s
 };
 #endif
 
+#ifdef CONFIG_NETDEV_ETHTOOL_IOCTL
+
+/* This structure is a set of callback functions used to call from the lower-
+ * half, support ethtool tools. Driver can get/set parameter of hardware
+ * through these api. At present, only some apis are supported in the
+ * framework layer, and others need to be improved.
+ *
+ * get_channels: Get number of channels.
+ * set_channels: Set number of channels.  Returns a negative error code or
+ *               zero.
+ * get_channels2: Get channels status, and return in form of bitmap.
+ * set_channels2: Turn on/off channels, and input parameter in the form of
+ *                bitmap.
+ */
+
+struct ethtool_ops_s
+{
+  CODE int (*get_channels)(FAR struct netdev_lowerhalf_s *dev,
+                           FAR struct ethtool_chns *chns);
+  CODE int (*set_channels)(FAR struct netdev_lowerhalf_s *dev,
+                           FAR struct ethtool_chns *chns);
+  CODE int (*get_channels2)(FAR struct netdev_lowerhalf_s *dev,
+                            FAR struct ethtool_chns2 *chns);
+  CODE int (*set_channels2)(FAR struct netdev_lowerhalf_s *dev,
+                            FAR struct ethtool_chns2 *chns);
+};
+#endif
+
 /****************************************************************************
  * Public Function Prototypes
  ****************************************************************************/
diff --git a/net/netdev/Kconfig b/net/netdev/Kconfig
index 2d69731bc2d..c159f7d03ef 100644
--- a/net/netdev/Kconfig
+++ b/net/netdev/Kconfig
@@ -30,6 +30,14 @@ config NETDEV_IOCTL
        bool
        default n
 
+config NETDEV_ETHTOOL_IOCTL
+       bool "Enable ETHTOOL ioctl()"
+       depends on NET_ETHERNET
+       default n
+       select NETDEV_IOCTL
+       ---help---
+               Enable support for ioctl() commands to config eth device
+
 config NETDEV_PHY_IOCTL
        bool "Enable PHY ioctl()"
        default n

Reply via email to