@@ -271,7 +271,7 @@ static void i40e_phy_type_to_ethtool(struct i40e_pf *pf, u32 *supported,
271271 * advertising |= ADVERTISED_Autoneg ;
272272 if (hw_link_info -> requested_speeds & I40E_LINK_SPEED_1GB )
273273 * advertising |= ADVERTISED_1000baseT_Full ;
274- if (pf -> flags & I40E_FLAG_100M_SGMII_CAPABLE ) {
274+ if (pf -> hw_features & I40E_HW_100M_SGMII_CAPABLE ) {
275275 * supported |= SUPPORTED_100baseT_Full ;
276276 * advertising |= ADVERTISED_100baseT_Full ;
277277 }
@@ -340,12 +340,12 @@ static void i40e_phy_type_to_ethtool(struct i40e_pf *pf, u32 *supported,
340340 * advertising |= ADVERTISED_20000baseKR2_Full ;
341341 }
342342 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR ) {
343- if (!(pf -> flags & I40E_FLAG_HAVE_CRT_RETIMER ))
343+ if (!(pf -> hw_features & I40E_HW_HAVE_CRT_RETIMER ))
344344 * supported |= SUPPORTED_10000baseKR_Full |
345345 SUPPORTED_Autoneg ;
346346 * advertising |= ADVERTISED_Autoneg ;
347347 if (hw_link_info -> requested_speeds & I40E_LINK_SPEED_10GB )
348- if (!(pf -> flags & I40E_FLAG_HAVE_CRT_RETIMER ))
348+ if (!(pf -> hw_features & I40E_HW_HAVE_CRT_RETIMER ))
349349 * advertising |= ADVERTISED_10000baseKR_Full ;
350350 }
351351 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4 ) {
@@ -356,12 +356,12 @@ static void i40e_phy_type_to_ethtool(struct i40e_pf *pf, u32 *supported,
356356 * advertising |= ADVERTISED_10000baseKX4_Full ;
357357 }
358358 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX ) {
359- if (!(pf -> flags & I40E_FLAG_HAVE_CRT_RETIMER ))
359+ if (!(pf -> hw_features & I40E_HW_HAVE_CRT_RETIMER ))
360360 * supported |= SUPPORTED_1000baseKX_Full |
361361 SUPPORTED_Autoneg ;
362362 * advertising |= ADVERTISED_Autoneg ;
363363 if (hw_link_info -> requested_speeds & I40E_LINK_SPEED_1GB )
364- if (!(pf -> flags & I40E_FLAG_HAVE_CRT_RETIMER ))
364+ if (!(pf -> hw_features & I40E_HW_HAVE_CRT_RETIMER ))
365365 * advertising |= ADVERTISED_1000baseKX_Full ;
366366 }
367367 if (phy_types & I40E_CAP_PHY_TYPE_25GBASE_KR ||
@@ -474,7 +474,7 @@ static void i40e_get_settings_link_up(struct i40e_hw *hw,
474474 SUPPORTED_1000baseT_Full ;
475475 if (hw_link_info -> requested_speeds & I40E_LINK_SPEED_1GB )
476476 advertising |= ADVERTISED_1000baseT_Full ;
477- if (pf -> flags & I40E_FLAG_100M_SGMII_CAPABLE ) {
477+ if (pf -> hw_features & I40E_HW_100M_SGMII_CAPABLE ) {
478478 supported |= SUPPORTED_100baseT_Full ;
479479 if (hw_link_info -> requested_speeds &
480480 I40E_LINK_SPEED_100MB )
@@ -1765,7 +1765,7 @@ static int i40e_get_ts_info(struct net_device *dev,
17651765 BIT (HWTSTAMP_FILTER_PTP_V2_L2_SYNC ) |
17661766 BIT (HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ );
17671767
1768- if (pf -> flags & I40E_FLAG_PTP_L4_CAPABLE )
1768+ if (pf -> hw_features & I40E_HW_PTP_L4_CAPABLE )
17691769 info -> rx_filters |= BIT (HWTSTAMP_FILTER_PTP_V1_L4_SYNC ) |
17701770 BIT (HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ ) |
17711771 BIT (HWTSTAMP_FILTER_PTP_V2_EVENT ) |
@@ -2005,7 +2005,7 @@ static int i40e_set_phys_id(struct net_device *netdev,
20052005
20062006 switch (state ) {
20072007 case ETHTOOL_ID_ACTIVE :
2008- if (!(pf -> flags & I40E_FLAG_PHY_CONTROLS_LEDS )) {
2008+ if (!(pf -> hw_features & I40E_HW_PHY_CONTROLS_LEDS )) {
20092009 pf -> led_status = i40e_led_get (hw );
20102010 } else {
20112011 i40e_aq_set_phy_debug (hw , I40E_PHY_DEBUG_ALL , NULL );
@@ -2015,19 +2015,19 @@ static int i40e_set_phys_id(struct net_device *netdev,
20152015 }
20162016 return blink_freq ;
20172017 case ETHTOOL_ID_ON :
2018- if (!(pf -> flags & I40E_FLAG_PHY_CONTROLS_LEDS ))
2018+ if (!(pf -> hw_features & I40E_HW_PHY_CONTROLS_LEDS ))
20192019 i40e_led_set (hw , 0xf , false);
20202020 else
20212021 ret = i40e_led_set_phy (hw , true, pf -> led_status , 0 );
20222022 break ;
20232023 case ETHTOOL_ID_OFF :
2024- if (!(pf -> flags & I40E_FLAG_PHY_CONTROLS_LEDS ))
2024+ if (!(pf -> hw_features & I40E_HW_PHY_CONTROLS_LEDS ))
20252025 i40e_led_set (hw , 0x0 , false);
20262026 else
20272027 ret = i40e_led_set_phy (hw , false, pf -> led_status , 0 );
20282028 break ;
20292029 case ETHTOOL_ID_INACTIVE :
2030- if (!(pf -> flags & I40E_FLAG_PHY_CONTROLS_LEDS )) {
2030+ if (!(pf -> hw_features & I40E_HW_PHY_CONTROLS_LEDS )) {
20312031 i40e_led_set (hw , pf -> led_status , false);
20322032 } else {
20332033 ret = i40e_led_set_phy (hw , false, pf -> led_status ,
@@ -2194,14 +2194,29 @@ static int __i40e_set_coalesce(struct net_device *netdev,
21942194 int queue )
21952195{
21962196 struct i40e_netdev_priv * np = netdev_priv (netdev );
2197+ u16 intrl_reg , cur_rx_itr , cur_tx_itr ;
21972198 struct i40e_vsi * vsi = np -> vsi ;
21982199 struct i40e_pf * pf = vsi -> back ;
2199- u16 intrl_reg ;
22002200 int i ;
22012201
22022202 if (ec -> tx_max_coalesced_frames_irq || ec -> rx_max_coalesced_frames_irq )
22032203 vsi -> work_limit = ec -> tx_max_coalesced_frames_irq ;
22042204
2205+ if (queue < 0 ) {
2206+ cur_rx_itr = vsi -> rx_rings [0 ]-> rx_itr_setting ;
2207+ cur_tx_itr = vsi -> tx_rings [0 ]-> tx_itr_setting ;
2208+ } else if (queue < vsi -> num_queue_pairs ) {
2209+ cur_rx_itr = vsi -> rx_rings [queue ]-> rx_itr_setting ;
2210+ cur_tx_itr = vsi -> tx_rings [queue ]-> tx_itr_setting ;
2211+ } else {
2212+ netif_info (pf , drv , netdev , "Invalid queue value, queue range is 0 - %d\n" ,
2213+ vsi -> num_queue_pairs - 1 );
2214+ return - EINVAL ;
2215+ }
2216+
2217+ cur_tx_itr &= ~I40E_ITR_DYNAMIC ;
2218+ cur_rx_itr &= ~I40E_ITR_DYNAMIC ;
2219+
22052220 /* tx_coalesce_usecs_high is ignored, use rx-usecs-high instead */
22062221 if (ec -> tx_coalesce_usecs_high != vsi -> int_rate_limit ) {
22072222 netif_info (pf , drv , netdev , "tx-usecs-high is not used, please program rx-usecs-high\n" );
@@ -2214,43 +2229,49 @@ static int __i40e_set_coalesce(struct net_device *netdev,
22142229 return - EINVAL ;
22152230 }
22162231
2217- if (ec -> rx_coalesce_usecs == 0 ) {
2218- if (ec -> use_adaptive_rx_coalesce )
2219- netif_info (pf , drv , netdev , "rx-usecs=0, need to disable adaptive-rx for a complete disable\n" );
2220- } else if ((ec -> rx_coalesce_usecs < (I40E_MIN_ITR << 1 )) ||
2221- (ec -> rx_coalesce_usecs > (I40E_MAX_ITR << 1 ))) {
2222- netif_info (pf , drv , netdev , "Invalid value, rx-usecs range is 0-8160\n" );
2223- return - EINVAL ;
2232+ if (ec -> rx_coalesce_usecs != cur_rx_itr &&
2233+ ec -> use_adaptive_rx_coalesce ) {
2234+ netif_info (pf , drv , netdev , "RX interrupt moderation cannot be changed if adaptive-rx is enabled.\n" );
2235+ return - EINVAL ;
2236+ }
2237+
2238+ if (ec -> rx_coalesce_usecs > (I40E_MAX_ITR << 1 )) {
2239+ netif_info (pf , drv , netdev , "Invalid value, rx-usecs range is 0-8160\n" );
2240+ return - EINVAL ;
2241+ }
2242+
2243+ if (ec -> tx_coalesce_usecs != cur_tx_itr &&
2244+ ec -> use_adaptive_tx_coalesce ) {
2245+ netif_info (pf , drv , netdev , "TX interrupt moderation cannot be changed if adaptive-tx is enabled.\n" );
2246+ return - EINVAL ;
2247+ }
2248+
2249+ if (ec -> tx_coalesce_usecs > (I40E_MAX_ITR << 1 )) {
2250+ netif_info (pf , drv , netdev , "Invalid value, tx-usecs range is 0-8160\n" );
2251+ return - EINVAL ;
22242252 }
22252253
2254+ if (ec -> use_adaptive_rx_coalesce && !cur_rx_itr )
2255+ ec -> rx_coalesce_usecs = I40E_MIN_ITR << 1 ;
2256+
2257+ if (ec -> use_adaptive_tx_coalesce && !cur_tx_itr )
2258+ ec -> tx_coalesce_usecs = I40E_MIN_ITR << 1 ;
2259+
22262260 intrl_reg = i40e_intrl_usec_to_reg (ec -> rx_coalesce_usecs_high );
22272261 vsi -> int_rate_limit = INTRL_REG_TO_USEC (intrl_reg );
22282262 if (vsi -> int_rate_limit != ec -> rx_coalesce_usecs_high ) {
22292263 netif_info (pf , drv , netdev , "Interrupt rate limit rounded down to %d\n" ,
22302264 vsi -> int_rate_limit );
22312265 }
22322266
2233- if (ec -> tx_coalesce_usecs == 0 ) {
2234- if (ec -> use_adaptive_tx_coalesce )
2235- netif_info (pf , drv , netdev , "tx-usecs=0, need to disable adaptive-tx for a complete disable\n" );
2236- } else if ((ec -> tx_coalesce_usecs < (I40E_MIN_ITR << 1 )) ||
2237- (ec -> tx_coalesce_usecs > (I40E_MAX_ITR << 1 ))) {
2238- netif_info (pf , drv , netdev , "Invalid value, tx-usecs range is 0-8160\n" );
2239- return - EINVAL ;
2240- }
2241-
22422267 /* rx and tx usecs has per queue value. If user doesn't specify the queue,
22432268 * apply to all queues.
22442269 */
22452270 if (queue < 0 ) {
22462271 for (i = 0 ; i < vsi -> num_queue_pairs ; i ++ )
22472272 i40e_set_itr_per_queue (vsi , ec , i );
2248- } else if (queue < vsi -> num_queue_pairs ) {
2249- i40e_set_itr_per_queue (vsi , ec , queue );
22502273 } else {
2251- netif_info (pf , drv , netdev , "Invalid queue value, queue range is 0 - %d\n" ,
2252- vsi -> num_queue_pairs - 1 );
2253- return - EINVAL ;
2274+ i40e_set_itr_per_queue (vsi , ec , queue );
22542275 }
22552276
22562277 return 0 ;
@@ -2727,22 +2748,22 @@ static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
27272748 switch (nfc -> flow_type ) {
27282749 case TCP_V4_FLOW :
27292750 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP ;
2730- if (pf -> flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE )
2751+ if (pf -> hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE )
27312752 hena |=
27322753 BIT_ULL (I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK );
27332754 break ;
27342755 case TCP_V6_FLOW :
27352756 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP ;
2736- if (pf -> flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE )
2757+ if (pf -> hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE )
27372758 hena |=
27382759 BIT_ULL (I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK );
2739- if (pf -> flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE )
2760+ if (pf -> hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE )
27402761 hena |=
27412762 BIT_ULL (I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK );
27422763 break ;
27432764 case UDP_V4_FLOW :
27442765 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP ;
2745- if (pf -> flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE )
2766+ if (pf -> hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE )
27462767 hena |=
27472768 BIT_ULL (I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP ) |
27482769 BIT_ULL (I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP );
@@ -2751,7 +2772,7 @@ static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
27512772 break ;
27522773 case UDP_V6_FLOW :
27532774 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP ;
2754- if (pf -> flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE )
2775+ if (pf -> hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE )
27552776 hena |=
27562777 BIT_ULL (I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP ) |
27572778 BIT_ULL (I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP );
@@ -4069,23 +4090,26 @@ static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
40694090 struct i40e_netdev_priv * np = netdev_priv (dev );
40704091 struct i40e_vsi * vsi = np -> vsi ;
40714092 struct i40e_pf * pf = vsi -> back ;
4072- u64 changed_flags ;
4093+ u64 orig_flags , new_flags , changed_flags ;
40734094 u32 i , j ;
40744095
4075- changed_flags = pf -> flags ;
4096+ orig_flags = READ_ONCE (pf -> flags );
4097+ new_flags = orig_flags ;
40764098
40774099 for (i = 0 ; i < I40E_PRIV_FLAGS_STR_LEN ; i ++ ) {
40784100 const struct i40e_priv_flags * priv_flags ;
40794101
40804102 priv_flags = & i40e_gstrings_priv_flags [i ];
40814103
4082- if (priv_flags -> read_only )
4083- continue ;
4084-
40854104 if (flags & BIT (i ))
4086- pf -> flags |= priv_flags -> flag ;
4105+ new_flags |= priv_flags -> flag ;
40874106 else
4088- pf -> flags &= ~(priv_flags -> flag );
4107+ new_flags &= ~(priv_flags -> flag );
4108+
4109+ /* If this is a read-only flag, it can't be changed */
4110+ if (priv_flags -> read_only &&
4111+ ((orig_flags ^ new_flags ) & ~BIT (i )))
4112+ return - EOPNOTSUPP ;
40894113 }
40904114
40914115 if (pf -> hw .pf_id != 0 )
@@ -4096,18 +4120,40 @@ static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
40964120
40974121 priv_flags = & i40e_gl_gstrings_priv_flags [j ];
40984122
4099- if (priv_flags -> read_only )
4100- continue ;
4101-
41024123 if (flags & BIT (i + j ))
4103- pf -> flags |= priv_flags -> flag ;
4124+ new_flags |= priv_flags -> flag ;
41044125 else
4105- pf -> flags &= ~(priv_flags -> flag );
4126+ new_flags &= ~(priv_flags -> flag );
4127+
4128+ /* If this is a read-only flag, it can't be changed */
4129+ if (priv_flags -> read_only &&
4130+ ((orig_flags ^ new_flags ) & ~BIT (i )))
4131+ return - EOPNOTSUPP ;
41064132 }
41074133
41084134flags_complete :
4109- /* check for flags that changed */
4110- changed_flags ^= pf -> flags ;
4135+ /* Before we finalize any flag changes, we need to perform some
4136+ * checks to ensure that the changes are supported and safe.
4137+ */
4138+
4139+ /* ATR eviction is not supported on all devices */
4140+ if ((new_flags & I40E_FLAG_HW_ATR_EVICT_ENABLED ) &&
4141+ !(pf -> hw_features & I40E_HW_ATR_EVICT_CAPABLE ))
4142+ return - EOPNOTSUPP ;
4143+
4144+ /* Compare and exchange the new flags into place. If we failed, that
4145+ * is if cmpxchg64 returns anything but the old value, this means that
4146+ * something else has modified the flags variable since we copied it
4147+ * originally. We'll just punt with an error and log something in the
4148+ * message buffer.
4149+ */
4150+ if (cmpxchg64 (& pf -> flags , orig_flags , new_flags ) != orig_flags ) {
4151+ dev_warn (& pf -> pdev -> dev ,
4152+ "Unable to update pf->flags as it was modified by another thread...\n" );
4153+ return - EAGAIN ;
4154+ }
4155+
4156+ changed_flags = orig_flags ^ new_flags ;
41114157
41124158 /* Process any additional changes needed as a result of flag changes.
41134159 * The changed_flags value reflects the list of bits that were
@@ -4121,10 +4167,6 @@ static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
41214167 set_bit (__I40E_FD_FLUSH_REQUESTED , pf -> state );
41224168 }
41234169
4124- /* Only allow ATR evict on hardware that is capable of handling it */
4125- if (pf -> flags & I40E_FLAG_HW_ATR_EVICT_CAPABLE )
4126- pf -> flags &= ~I40E_FLAG_HW_ATR_EVICT_ENABLED ;
4127-
41284170 if (changed_flags & I40E_FLAG_TRUE_PROMISC_SUPPORT ) {
41294171 u16 sw_flags = 0 , valid_flags = 0 ;
41304172 int ret ;
0 commit comments