ethtool: allow custom interval for physical identification
Subsystems (3)
RFC PATCH v3 1/1 ethtool: allow custom interval for physical identification
When physical identification of an adapter is done by toggling the mechanism on and off through software utilizing the set_phys_id operation, it is done with a fixed duration for both on and off states. Some drivers may want to set a custom duration for the on/off intervals. This patch changes the API so the return code from the driver's entry point when it is called with ETHTOOL_ID_ACTIVE can specify the frequency at which to cycle the on/off states, and updates the drivers that have already been converted to use the new set_phys_id and use the synchronous method for identifying an adapter.
The physical identification frequency set in the updated drivers is based on how it was done prior to the introduction of set_phys_id.
Compile tested only. Also fixes a compiler warning in sfc.
v2: drivers do not return -EINVAL for ETHOOL_ID_ACTIVE
v3: fold patchset into single patch and cleanup per Ben's feedback
---
drivers/net/benet/be_ethtool.c | 2 +- drivers/net/bnx2.c | 2 +- drivers/net/bnx2x/bnx2x_ethtool.c | 2 +- drivers/net/cxgb3/cxgb3_main.c | 2 +- drivers/net/ewrk3.c | 2 +- drivers/net/niu.c | 2 +- drivers/net/pcnet32.c | 2 +- drivers/net/s2io.c | 2 +- drivers/net/sfc/ethtool.c | 6 +++--- drivers/net/skge.c | 2 +- drivers/net/sky2.c | 2 +- drivers/net/tg3.c | 2 +- include/linux/ethtool.h | 6 ++++-- net/core/ethtool.c | 31 ++++++++++++++++--------------- 14 files changed, 34 insertions(+), 31 deletions(-)
drivers/net/benet/be_ethtool.c +1 -1
@@ -516,7 +516,7 @@ be_set_phys_id(struct net_device *netdev,case ETHTOOL_ID_ACTIVE :be_cmd_get_beacon_state (adapter, adapter->hba_port_num, &adapter->beacon_state); -return -EINVAL ; +return 1 ;/* cycle on/off once per second */ case ETHTOOL_ID_ON : be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
drivers/net/bnx2.c +1 -1
@@ -7473,7 +7473,7 @@ bnx2_set_phys_id(struct net_device *dev, enum ethtool_phys_id_state state) bp->leds_save =REG_RD (bp,BNX2_MISC_CFG );REG_WR (bp,BNX2_MISC_CFG ,BNX2_MISC_CFG_LEDMODE_MAC ); -return -EINVAL ; +return 1 ;/* cycle on/off once per second */ case ETHTOOL_ID_ON : REG_WR(bp, BNX2_EMAC_LED, BNX2_EMAC_LED_OVERRIDE |
drivers/net/bnx2x/bnx2x_ethtool.c +1 -1
@@ -2025,7 +2025,7 @@ static int bnx2x_set_phys_id(struct net_device *dev,switch (state) {case ETHTOOL_ID_ACTIVE : -return -EINVAL ; +return 1 ;/* cycle on/off once per second */ case ETHTOOL_ID_ON : bnx2x_set_led(&bp->link_params, &bp->link_vars,
drivers/net/cxgb3/cxgb3_main.c +1 -1
@@ -1757,7 +1757,7 @@ static int set_phys_id(struct net_device *dev,switch (state) {case ETHTOOL_ID_ACTIVE : -return -EINVAL ; +return 1 ;/* cycle on/off once per second */ case ETHTOOL_ID_OFF :t3_set_reg_field (adapter,A_T3DBG_GPIO_EN ,F_GPIO0_OUT_VAL ,0 );
drivers/net/ewrk3.c +1 -1
@@ -1618,7 +1618,7 @@ static int ewrk3_set_phys_id(struct net_device *dev,/* Prevent ISR from twiddling the LED */ lp->led_mask =0 ;spin_unlock_irq (&lp->hw_lock); -return -EINVAL ; +return 2 ;/* cycle on/off twice per second */ case ETHTOOL_ID_ON : cr =inb (EWRK3_CR );
drivers/net/niu.c +1 -1
@@ -7896,7 +7896,7 @@ static int niu_set_phys_id(struct net_device *dev,switch (state) {case ETHTOOL_ID_ACTIVE : np->orig_led_state =niu_led_state_save (np); -return -EINVAL ; +return 1 ;/* cycle on/off once per second */ case ETHTOOL_ID_ON :niu_force_led (np,1 );
drivers/net/pcnet32.c +1 -1
@@ -1038,7 +1038,7 @@ static int pcnet32_set_phys_id(struct net_device *dev,for (i =4 ; i <8 ; i++) lp->save_regs[i -4 ] = a->read_bcr (ioaddr, i);spin_unlock_irqrestore (&lp->lock, flags); -return -EINVAL ; +return 2 ;/* cycle on/off twice per second */ case ETHTOOL_ID_ON :case ETHTOOL_ID_OFF :
drivers/net/s2io.c +1 -1
@@ -5541,7 +5541,7 @@ static int s2io_ethtool_set_led(struct net_device *dev,switch (state) {case ETHTOOL_ID_ACTIVE : sp->adapt_ctrl_org =readq (&bar0->gpio_control); -return -EINVAL ; +return 1 ;/* cycle on/off once per second */ case ETHTOOL_ID_ON :s2io_set_led (sp, true);
drivers/net/sfc/ethtool.c +3 -3
@@ -182,7 +182,7 @@ static int efx_ethtool_phys_id(struct net_device *net_dev, enum ethtool_phys_id_state state) {struct efx_nic *efx =netdev_priv (net_dev); -enum efx_led_mode mode; +enum efx_led_mode mode =EFX_LED_DEFAULT ;switch (state) {case ETHTOOL_ID_ON :
@@ -194,8 +194,8 @@ static int efx_ethtool_phys_id(struct net_device *net_dev,case ETHTOOL_ID_INACTIVE : mode =EFX_LED_DEFAULT ;break ; -default : -return -EINVAL ; +case ETHTOOL_ID_ACTIVE : +return 1 ;/* cycle on/off once per second */ } efx->type->set_id_led (efx, mode);
drivers/net/skge.c +1 -1
@@ -753,7 +753,7 @@ static int skge_set_phys_id(struct net_device *dev,switch (state) {case ETHTOOL_ID_ACTIVE : -return -EINVAL ; +return 2 ;/* cycle on/off twice per second */ case ETHTOOL_ID_ON :skge_led (skge,LED_MODE_TST );
drivers/net/sky2.c +1 -1
@@ -3813,7 +3813,7 @@ static int sky2_set_phys_id(struct net_device *dev,switch (state) {case ETHTOOL_ID_ACTIVE : -return -EINVAL ; +return 1 ;/* cycle on/off once per second */ case ETHTOOL_ID_INACTIVE :sky2_led (sky2,MO_LED_NORM );break ;
drivers/net/tg3.c +1 -1
@@ -10292,7 +10292,7 @@ static int tg3_set_phys_id(struct net_device *dev,switch (state) {case ETHTOOL_ID_ACTIVE : -return -EINVAL ; +return 1 ;/* cycle on/off once per second */ case ETHTOOL_ID_ON : tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE |
include/linux/ethtool.h +4 -2
@@ -798,8 +798,10 @@ bool ethtool_invalid_flags(struct net_device *dev, u32 data, u32 supported);* attached to it. The implementation may update the indicator * asynchronously or synchronously, but in either case it must return * quickly. It is initially called with the argument %ETHTOOL_ID_ACTIVE, -* and must either activate asynchronous updates or return -%EINVAL. -* If it returns -%EINVAL then it will be called again at intervals with +* and must either activate asynchronous updates and return zero, return +* a negative error or return a positive frequency for synchronous +* indication (e.g. 1 for one on/off cycle per second). If it returns +* a frequency then it will be called again at intervals with the * argument %ETHTOOL_ID_ON or %ETHTOOL_ID_OFF and should set the state of * the indicator accordingly. Finally, it is called with the argument * %ETHTOOL_ID_INACTIVE and must deactivate the indicator. Returns a
net/core/ethtool.c +16 -15
@@ -1669,7 +1669,7 @@ static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)return dev->ethtool_ops->phys_id (dev, id.data); rc = dev->ethtool_ops->set_phys_id (dev,ETHTOOL_ID_ACTIVE ); -if (rc && rc != -EINVAL ) +if (rc <0 )return rc;/* Drop the RTNL lock while waiting, but prevent reentry or
@@ -1684,21 +1684,22 @@ static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)schedule_timeout_interruptible ( id.data ? (id.data *HZ ) :MAX_SCHEDULE_TIMEOUT ); }else { -/* Driver expects to be called periodically */ +/* Driver expects to be called at twice the frequency in rc */ +int n = rc *2 , i, interval =HZ / n; + +/* Count down seconds */ do { -rtnl_lock (); - rc = dev->ethtool_ops->set_phys_id (dev,ETHTOOL_ID_ON ); -rtnl_unlock (); -if (rc) -break ; -schedule_timeout_interruptible (HZ /2 ); - -rtnl_lock (); - rc = dev->ethtool_ops->set_phys_id (dev,ETHTOOL_ID_OFF ); -rtnl_unlock (); -if (rc) -break ; -schedule_timeout_interruptible (HZ /2 ); +/* Count down iterations per second */ + i = n; +do { +rtnl_lock (); + rc = dev->ethtool_ops->set_phys_id (dev, + (i &1 ) ?ETHTOOL_ID_OFF :ETHTOOL_ID_ON ); +rtnl_unlock (); +if (rc) +break ; +schedule_timeout_interruptible (interval); + }while (!signal_pending (current) && --i !=0 ); }while (!signal_pending (current) && (id.data ==0 || --id.data !=0 )); }
Quoted 13 lines · Bruce Allan
When physical identification of an adapter is done by toggling the mechanism on and off through software utilizing the
set_phys_idoperation, it is done with a fixed duration for both on and off states. Some drivers may want to set a custom duration for the on/off intervals. This patch changes the API so the return code from the driver's entry point when it is called withETHTOOL_ID_ACTIVEcan specify the frequency at which to cycle the on/off states, and updates the drivers that have already been converted to use the newset_phys_idand use the synchronous method for identifying an adapter.The physical identification frequency set in the updated drivers is based on how it was done prior to the introduction of
set_phys_id.
Quoted 6 lines
Compile tested only. Also fixes a compiler warning in sfc.
v2: drivers do not return
-EINVALforETHOOL_ID_ACTIVE
v3: fold patchset into single patch and cleanup per Ben's feedbackSigned-off-by Bruce Allan <[email protected]>
Quoted 266 lines
Cc Ben Hutchings <[email protected]>Cc Sathya Perla <[email protected]>Cc Subbu Seetharaman <[email protected]>Cc Ajit Khaparde <[email protected]>Cc Michael Chan <[email protected]>Cc Eilon Greenstein <[email protected]>Cc Divy Le Ray <[email protected]>Cc Don Fry <[email protected]>Cc Jon Mason <[email protected]>Cc Solarflare linux maintainers <[email protected]>Cc Steve Hodgson <[email protected]>Cc Stephen Hemminger <[email protected]>Cc Matt Carlson <[email protected]>---
drivers/net/benet/be_ethtool.c | 2 +- drivers/net/bnx2.c | 2 +- drivers/net/bnx2x/bnx2x_ethtool.c | 2 +- drivers/net/cxgb3/cxgb3_main.c | 2 +- drivers/net/ewrk3.c | 2 +- drivers/net/niu.c | 2 +- drivers/net/pcnet32.c | 2 +- drivers/net/s2io.c | 2 +- drivers/net/sfc/ethtool.c | 6 +++--- drivers/net/skge.c | 2 +- drivers/net/sky2.c | 2 +- drivers/net/tg3.c | 2 +- include/linux/ethtool.h | 6 ++++-- net/core/ethtool.c | 31 ++++++++++++++++--------------- 14 files changed, 34 insertions(+), 31 deletions(-)drivers/net/benet/be_ethtool.c +1
-1@@ -516,7 +516,7 @@ be_set_phys_id(struct net_device *netdev,case ETHTOOL_ID_ACTIVE :be_cmd_get_beacon_state (adapter, adapter->hba_port_num, &adapter->beacon_state); -return -EINVAL ; +return 1 ;/* cycle on/off once per second */ case ETHTOOL_ID_ON : be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,drivers/net/bnx2.c +1
-1@@ -7473,7 +7473,7 @@ bnx2_set_phys_id(struct net_device *dev, enum ethtool_phys_id_state state) bp->leds_save =REG_RD (bp,BNX2_MISC_CFG );REG_WR (bp,BNX2_MISC_CFG ,BNX2_MISC_CFG_LEDMODE_MAC ); -return -EINVAL ; +return 1 ;/* cycle on/off once per second */ case ETHTOOL_ID_ON : REG_WR(bp, BNX2_EMAC_LED, BNX2_EMAC_LED_OVERRIDE |drivers/net/bnx2x/bnx2x_ethtool.c +1
-1@@ -2025,7 +2025,7 @@ static int bnx2x_set_phys_id(struct net_device *dev,switch (state) {case ETHTOOL_ID_ACTIVE : -return -EINVAL ; +return 1 ;/* cycle on/off once per second */ case ETHTOOL_ID_ON : bnx2x_set_led(&bp->link_params, &bp->link_vars,drivers/net/cxgb3/cxgb3_main.c +1
-1@@ -1757,7 +1757,7 @@ static int set_phys_id(struct net_device *dev,switch (state) {case ETHTOOL_ID_ACTIVE : -return -EINVAL ; +return 1 ;/* cycle on/off once per second */ case ETHTOOL_ID_OFF :t3_set_reg_field (adapter,A_T3DBG_GPIO_EN ,F_GPIO0_OUT_VAL ,0 );drivers/net/ewrk3.c +1
-1@@ -1618,7 +1618,7 @@ static int ewrk3_set_phys_id(struct net_device *dev,/* Prevent ISR from twiddling the LED */ lp->led_mask =0 ;spin_unlock_irq (&lp->hw_lock); -return -EINVAL ; +return 2 ;/* cycle on/off twice per second */ case ETHTOOL_ID_ON : cr =inb (EWRK3_CR );drivers/net/niu.c +1
-1@@ -7896,7 +7896,7 @@ static int niu_set_phys_id(struct net_device *dev,switch (state) {case ETHTOOL_ID_ACTIVE : np->orig_led_state =niu_led_state_save (np); -return -EINVAL ; +return 1 ;/* cycle on/off once per second */ case ETHTOOL_ID_ON :niu_force_led (np,1 );drivers/net/pcnet32.c +1
-1@@ -1038,7 +1038,7 @@ static int pcnet32_set_phys_id(struct net_device *dev,for (i =4 ; i <8 ; i++) lp->save_regs[i -4 ] = a->read_bcr (ioaddr, i);spin_unlock_irqrestore (&lp->lock, flags); -return -EINVAL ; +return 2 ;/* cycle on/off twice per second */ case ETHTOOL_ID_ON :case ETHTOOL_ID_OFF :drivers/net/s2io.c +1
-1@@ -5541,7 +5541,7 @@ static int s2io_ethtool_set_led(struct net_device *dev,switch (state) {case ETHTOOL_ID_ACTIVE : sp->adapt_ctrl_org =readq (&bar0->gpio_control); -return -EINVAL ; +return 1 ;/* cycle on/off once per second */ case ETHTOOL_ID_ON :s2io_set_led (sp, true);drivers/net/sfc/ethtool.c +3
-3@@ -182,7 +182,7 @@ static int efx_ethtool_phys_id(struct net_device *net_dev, enum ethtool_phys_id_state state) {struct efx_nic *efx =netdev_priv (net_dev); -enum efx_led_mode mode; +enum efx_led_mode mode =EFX_LED_DEFAULT ;switch (state) {case ETHTOOL_ID_ON :@@ -194,8 +194,8 @@ static int efx_ethtool_phys_id(struct net_device *net_dev,case ETHTOOL_ID_INACTIVE : mode =EFX_LED_DEFAULT ;break ; -default : -return -EINVAL ; +case ETHTOOL_ID_ACTIVE : +return 1 ;/* cycle on/off once per second */ } efx->type->set_id_led (efx, mode);drivers/net/skge.c +1
-1@@ -753,7 +753,7 @@ static int skge_set_phys_id(struct net_device *dev,switch (state) {case ETHTOOL_ID_ACTIVE : -return -EINVAL ; +return 2 ;/* cycle on/off twice per second */ case ETHTOOL_ID_ON :skge_led (skge,LED_MODE_TST );drivers/net/sky2.c +1
-1@@ -3813,7 +3813,7 @@ static int sky2_set_phys_id(struct net_device *dev,switch (state) {case ETHTOOL_ID_ACTIVE : -return -EINVAL ; +return 1 ;/* cycle on/off once per second */ case ETHTOOL_ID_INACTIVE :sky2_led (sky2,MO_LED_NORM );break ;drivers/net/tg3.c +1
-1@@ -10292,7 +10292,7 @@ static int tg3_set_phys_id(struct net_device *dev,switch (state) {case ETHTOOL_ID_ACTIVE : -return -EINVAL ; +return 1 ;/* cycle on/off once per second */ case ETHTOOL_ID_ON : tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE |include/linux/ethtool.h +4
-2@@ -798,8 +798,10 @@ bool ethtool_invalid_flags(struct net_device *dev, u32 data, u32 supported);* attached to it. The implementation may update the indicator * asynchronously or synchronously, but in either case it must return * quickly. It is initially called with the argument %ETHTOOL_ID_ACTIVE, -* and must either activate asynchronous updates or return -%EINVAL. -* If it returns -%EINVAL then it will be called again at intervals with +* and must either activate asynchronous updates and return zero, return +* a negative error or return a positive frequency for synchronous +* indication (e.g. 1 for one on/off cycle per second). If it returns +* a frequency then it will be called again at intervals with the * argument %ETHTOOL_ID_ON or %ETHTOOL_ID_OFF and should set the state of * the indicator accordingly. Finally, it is called with the argument * %ETHTOOL_ID_INACTIVE and must deactivate the indicator. Returns a net/core/ethtool.c +16
-15@@ -1669,7 +1669,7 @@ static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)return dev->ethtool_ops->phys_id (dev, id.data); rc = dev->ethtool_ops->set_phys_id (dev,ETHTOOL_ID_ACTIVE ); -if (rc && rc != -EINVAL ) +if (rc <0 )return rc;/* Drop the RTNL lock while waiting, but prevent reentry or @@ -1684,21 +1684,22 @@ static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)schedule_timeout_interruptible ( id.data ? (id.data *HZ ) :MAX_SCHEDULE_TIMEOUT ); }else { -/* Driver expects to be called periodically */ +/* Driver expects to be called at twice the frequency in rc */ +int n = rc *2 , i, interval =HZ / n; + +/* Count down seconds */ do { -rtnl_lock (); - rc = dev->ethtool_ops->set_phys_id (dev,ETHTOOL_ID_ON ); -rtnl_unlock (); -if (rc) -break ; -schedule_timeout_interruptible (HZ /2 ); - -rtnl_lock (); - rc = dev->ethtool_ops->set_phys_id (dev,ETHTOOL_ID_OFF ); -rtnl_unlock (); -if (rc) -break ; -schedule_timeout_interruptible (HZ /2 ); +/* Count down iterations per second */ + i = n; +do { +rtnl_lock (); + rc = dev->ethtool_ops->set_phys_id (dev, + (i &1 ) ?ETHTOOL_ID_OFF :ETHTOOL_ID_ON ); +rtnl_unlock (); +if (rc) +break ; +schedule_timeout_interruptible (interval); + }while (!signal_pending (current) && --i !=0 ); }while (!signal_pending (current) && (id.data ==0 || --id.data !=0 )); }
Quoted 13 lines · Bruce Allan
When physical identification of an adapter is done by toggling the mechanism on and off through software utilizing the
set_phys_idoperation, it is done with a fixed duration for both on and off states. Some drivers may want to set a custom duration for the on/off intervals. This patch changes the API so the return code from the driver's entry point when it is called withETHTOOL_ID_ACTIVEcan specify the frequency at which to cycle the on/off states, and updates the drivers that have already been converted to use the newset_phys_idand use the synchronous method for identifying an adapter.The physical identification frequency set in the updated drivers is based on how it was done prior to the introduction of
set_phys_id.
Quoted 7 lines
Compile tested only. Also fixes a compiler warning in sfc.
v2: drivers do not return
-EINVALforETHOOL_ID_ACTIVE
v3: fold patchset into single patch and cleanup per Ben's feedbackSigned-off-by Bruce Allan <[email protected]>Cc Ben Hutchings <[email protected]>
Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked.
From: Ben Hutchings <[email protected]>
Date: Fri, 15 Apr 2011 02:26:25 +0100
Quoted 16 lines · Bruce Allan
Quoted 15 lines
When physical identification of an adapter is done by toggling the mechanism on and off through software utilizing the
set_phys_idoperation, it is done with a fixed duration for both on and off states. Some drivers may want to set a custom duration for the on/off intervals. This patch changes the API so the return code from the driver's entry point when it is called withETHTOOL_ID_ACTIVEcan specify the frequency at which to cycle the on/off states, and updates the drivers that have already been converted to use the newset_phys_idand use the synchronous method for identifying an adapter.The physical identification frequency set in the updated drivers is based on how it was done prior to the introduction of
set_phys_id.Compile tested only. Also fixes a compiler warning in sfc.
Quoted 7 lines
Quoted 5 lines
v2: drivers do not return
-EINVALforETHOOL_ID_ACTIVE
v3: fold patchset into single patch and cleanup per Ben's feedbackSigned-off-by Bruce Allan <[email protected]>Cc Ben Hutchings <[email protected]>[...]Acked-by Ben Hutchings <[email protected]>
Applied, thanks everyone.