diff mbox series

[net-next,v4,08/10] net: phylink: Adjust advertisement based on rate adaptation

Message ID 20220818164616.2064242-9-sean.anderson@seco.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series net: phy: Add support for rate adaptation | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit fail Errors and warnings before: 21338 this patch: 15478
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang fail Errors and warnings before: 17 this patch: 20
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn fail Errors and warnings before: 21338 this patch: 15478
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 98 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Sean Anderson Aug. 18, 2022, 4:46 p.m. UTC
This adds support for adjusting the advertisement for pause-based rate
adaptation. This may result in a lossy link, since the final link settings
are not adjusted. Asymmetric pause support is necessary. It would be
possible for a MAC supporting only symmetric pause to use pause-based rate
adaptation, but only if pause reception was enabled as well.

Signed-off-by: Sean Anderson <sean.anderson@seco.com>
---

(no changes since v3)

Changes in v3:
- Add phylink_cap_from_speed_duplex to look up the mac capability
  corresponding to the interface's speed.
- Include RATE_ADAPT_CRS; it's a few lines and it doesn't hurt.

Changes in v2:
- Determine the interface speed and max mac speed directly instead of
  guessing based on the caps.

 drivers/net/phy/phylink.c | 58 +++++++++++++++++++++++++++++++++++++--
 include/linux/phylink.h   |  3 +-
 2 files changed, 57 insertions(+), 4 deletions(-)

Comments

kernel test robot Aug. 18, 2022, 7 p.m. UTC | #1
Hi Sean,

I love your patch! Yet something to improve:

[auto build test ERROR on net-next/master]

url:    https://github.com/intel-lab-lkp/linux/commits/Sean-Anderson/net-phy-Add-support-for-rate-adaptation/20220819-005121
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git e34cfee65ec891a319ce79797dda18083af33a76
config: i386-randconfig-a005 (https://download.01.org/0day-ci/archive/20220819/202208190223.zfo3KG9D-lkp@intel.com/config)
compiler: gcc-11 (Debian 11.3.0-5) 11.3.0
reproduce (this is a W=1 build):
        # https://github.com/intel-lab-lkp/linux/commit/f4857d8d4f852b1cc3ae278785c209a7a0da0f67
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Sean-Anderson/net-phy-Add-support-for-rate-adaptation/20220819-005121
        git checkout f4857d8d4f852b1cc3ae278785c209a7a0da0f67
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash drivers/net/phy/

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   drivers/net/phy/phylink.c: In function 'phylink_get_capabilities':
>> drivers/net/phy/phylink.c:543:21: error: implicit declaration of function 'phylink_cap_from_speed_duplex' [-Werror=implicit-function-declaration]
     543 |                     phylink_cap_from_speed_duplex(max_speed, DUPLEX_FULL)) {
         |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   cc1: some warnings being treated as errors


vim +/phylink_cap_from_speed_duplex +543 drivers/net/phy/phylink.c

   431	
   432	/**
   433	 * phylink_get_capabilities() - get capabilities for a given MAC
   434	 * @interface: phy interface mode defined by &typedef phy_interface_t
   435	 * @mac_capabilities: bitmask of MAC capabilities
   436	 * @rate_adaptation: type of rate adaptation being performed
   437	 *
   438	 * Get the MAC capabilities that are supported by the @interface mode and
   439	 * @mac_capabilities.
   440	 */
   441	unsigned long phylink_get_capabilities(phy_interface_t interface,
   442					       unsigned long mac_capabilities,
   443					       int rate_adaptation)
   444	{
   445		int max_speed = phylink_interface_max_speed(interface);
   446		unsigned long caps = MAC_SYM_PAUSE | MAC_ASYM_PAUSE;
   447		unsigned long adapted_caps = 0;
   448	
   449		switch (interface) {
   450		case PHY_INTERFACE_MODE_USXGMII:
   451			caps |= MAC_10000FD | MAC_5000FD | MAC_2500FD;
   452			fallthrough;
   453	
   454		case PHY_INTERFACE_MODE_RGMII_TXID:
   455		case PHY_INTERFACE_MODE_RGMII_RXID:
   456		case PHY_INTERFACE_MODE_RGMII_ID:
   457		case PHY_INTERFACE_MODE_RGMII:
   458		case PHY_INTERFACE_MODE_QSGMII:
   459		case PHY_INTERFACE_MODE_SGMII:
   460		case PHY_INTERFACE_MODE_GMII:
   461			caps |= MAC_1000HD | MAC_1000FD;
   462			fallthrough;
   463	
   464		case PHY_INTERFACE_MODE_REVRMII:
   465		case PHY_INTERFACE_MODE_RMII:
   466		case PHY_INTERFACE_MODE_SMII:
   467		case PHY_INTERFACE_MODE_REVMII:
   468		case PHY_INTERFACE_MODE_MII:
   469			caps |= MAC_10HD | MAC_10FD;
   470			fallthrough;
   471	
   472		case PHY_INTERFACE_MODE_100BASEX:
   473			caps |= MAC_100HD | MAC_100FD;
   474			break;
   475	
   476		case PHY_INTERFACE_MODE_TBI:
   477		case PHY_INTERFACE_MODE_MOCA:
   478		case PHY_INTERFACE_MODE_RTBI:
   479		case PHY_INTERFACE_MODE_1000BASEX:
   480			caps |= MAC_1000HD;
   481			fallthrough;
   482		case PHY_INTERFACE_MODE_1000BASEKX:
   483		case PHY_INTERFACE_MODE_TRGMII:
   484			caps |= MAC_1000FD;
   485			break;
   486	
   487		case PHY_INTERFACE_MODE_2500BASEX:
   488			caps |= MAC_2500FD;
   489			break;
   490	
   491		case PHY_INTERFACE_MODE_5GBASER:
   492			caps |= MAC_5000FD;
   493			break;
   494	
   495		case PHY_INTERFACE_MODE_XGMII:
   496		case PHY_INTERFACE_MODE_RXAUI:
   497		case PHY_INTERFACE_MODE_XAUI:
   498		case PHY_INTERFACE_MODE_10GBASER:
   499		case PHY_INTERFACE_MODE_10GKR:
   500			caps |= MAC_10000FD;
   501			break;
   502	
   503		case PHY_INTERFACE_MODE_25GBASER:
   504			caps |= MAC_25000FD;
   505			break;
   506	
   507		case PHY_INTERFACE_MODE_XLGMII:
   508			caps |= MAC_40000FD;
   509			break;
   510	
   511		case PHY_INTERFACE_MODE_INTERNAL:
   512			caps |= ~0;
   513			break;
   514	
   515		case PHY_INTERFACE_MODE_NA:
   516		case PHY_INTERFACE_MODE_MAX:
   517			break;
   518		}
   519	
   520		switch (rate_adaptation) {
   521		case RATE_ADAPT_OPEN_LOOP:
   522			/* TODO */
   523			fallthrough;
   524		case RATE_ADAPT_NONE:
   525			adapted_caps = 0;
   526			break;
   527		case RATE_ADAPT_PAUSE: {
   528			/* The MAC must support asymmetric pause towards the local
   529			 * device for this. We could allow just symmetric pause, but
   530			 * then we might have to renegotiate if the link partner
   531			 * doesn't support pause. This is because there's no way to
   532			 * accept pause frames without transmitting them if we only
   533			 * support symmetric pause.
   534			 */
   535			if (!(mac_capabilities & MAC_SYM_PAUSE) ||
   536			    !(mac_capabilities & MAC_ASYM_PAUSE))
   537				break;
   538	
   539			/* We can't adapt if the MAC doesn't support the interface's
   540			 * max speed at full duplex.
   541			 */
   542			if (mac_capabilities &
 > 543			    phylink_cap_from_speed_duplex(max_speed, DUPLEX_FULL)) {
   544				/* Although a duplex-adapting phy might exist, we
   545				 * conservatively remove these modes because the MAC
   546				 * will not be aware of the half-duplex nature of the
   547				 * link.
   548				 */
   549				adapted_caps = GENMASK(__fls(caps), __fls(MAC_10HD));
   550				adapted_caps &= ~(MAC_1000HD | MAC_100HD | MAC_10HD);
   551			}
   552			break;
   553		}
   554		case RATE_ADAPT_CRS:
   555			/* The MAC must support half duplex at the interface's max
   556			 * speed.
   557			 */
   558			if (mac_capabilities &
   559			    phylink_cap_from_speed_duplex(max_speed, DUPLEX_HALF)) {
   560				adapted_caps = GENMASK(__fls(caps), __fls(MAC_10HD));
   561				adapted_caps &= mac_capabilities;
   562			}
   563			break;
   564		}
   565	
   566		return (caps & mac_capabilities) | adapted_caps;
   567	}
   568	EXPORT_SYMBOL_GPL(phylink_get_capabilities);
   569
kernel test robot Aug. 18, 2022, 7:31 p.m. UTC | #2
Hi Sean,

I love your patch! Yet something to improve:

[auto build test ERROR on net-next/master]

url:    https://github.com/intel-lab-lkp/linux/commits/Sean-Anderson/net-phy-Add-support-for-rate-adaptation/20220819-005121
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git e34cfee65ec891a319ce79797dda18083af33a76
config: arm-randconfig-r026-20220818 (https://download.01.org/0day-ci/archive/20220819/202208190347.I3rrGqW3-lkp@intel.com/config)
compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project aed5e3bea138ce581d682158eb61c27b3cfdd6ec)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install arm cross compiling tool for clang build
        # apt-get install binutils-arm-linux-gnueabi
        # https://github.com/intel-lab-lkp/linux/commit/f4857d8d4f852b1cc3ae278785c209a7a0da0f67
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Sean-Anderson/net-phy-Add-support-for-rate-adaptation/20220819-005121
        git checkout f4857d8d4f852b1cc3ae278785c209a7a0da0f67
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=arm SHELL=/bin/bash drivers/net/phy/

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

>> drivers/net/phy/phylink.c:543:7: error: call to undeclared function 'phylink_cap_from_speed_duplex'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
                       phylink_cap_from_speed_duplex(max_speed, DUPLEX_FULL)) {
                       ^
   drivers/net/phy/phylink.c:559:7: error: call to undeclared function 'phylink_cap_from_speed_duplex'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
                       phylink_cap_from_speed_duplex(max_speed, DUPLEX_HALF)) {
                       ^
   2 errors generated.


vim +/phylink_cap_from_speed_duplex +543 drivers/net/phy/phylink.c

   431	
   432	/**
   433	 * phylink_get_capabilities() - get capabilities for a given MAC
   434	 * @interface: phy interface mode defined by &typedef phy_interface_t
   435	 * @mac_capabilities: bitmask of MAC capabilities
   436	 * @rate_adaptation: type of rate adaptation being performed
   437	 *
   438	 * Get the MAC capabilities that are supported by the @interface mode and
   439	 * @mac_capabilities.
   440	 */
   441	unsigned long phylink_get_capabilities(phy_interface_t interface,
   442					       unsigned long mac_capabilities,
   443					       int rate_adaptation)
   444	{
   445		int max_speed = phylink_interface_max_speed(interface);
   446		unsigned long caps = MAC_SYM_PAUSE | MAC_ASYM_PAUSE;
   447		unsigned long adapted_caps = 0;
   448	
   449		switch (interface) {
   450		case PHY_INTERFACE_MODE_USXGMII:
   451			caps |= MAC_10000FD | MAC_5000FD | MAC_2500FD;
   452			fallthrough;
   453	
   454		case PHY_INTERFACE_MODE_RGMII_TXID:
   455		case PHY_INTERFACE_MODE_RGMII_RXID:
   456		case PHY_INTERFACE_MODE_RGMII_ID:
   457		case PHY_INTERFACE_MODE_RGMII:
   458		case PHY_INTERFACE_MODE_QSGMII:
   459		case PHY_INTERFACE_MODE_SGMII:
   460		case PHY_INTERFACE_MODE_GMII:
   461			caps |= MAC_1000HD | MAC_1000FD;
   462			fallthrough;
   463	
   464		case PHY_INTERFACE_MODE_REVRMII:
   465		case PHY_INTERFACE_MODE_RMII:
   466		case PHY_INTERFACE_MODE_SMII:
   467		case PHY_INTERFACE_MODE_REVMII:
   468		case PHY_INTERFACE_MODE_MII:
   469			caps |= MAC_10HD | MAC_10FD;
   470			fallthrough;
   471	
   472		case PHY_INTERFACE_MODE_100BASEX:
   473			caps |= MAC_100HD | MAC_100FD;
   474			break;
   475	
   476		case PHY_INTERFACE_MODE_TBI:
   477		case PHY_INTERFACE_MODE_MOCA:
   478		case PHY_INTERFACE_MODE_RTBI:
   479		case PHY_INTERFACE_MODE_1000BASEX:
   480			caps |= MAC_1000HD;
   481			fallthrough;
   482		case PHY_INTERFACE_MODE_1000BASEKX:
   483		case PHY_INTERFACE_MODE_TRGMII:
   484			caps |= MAC_1000FD;
   485			break;
   486	
   487		case PHY_INTERFACE_MODE_2500BASEX:
   488			caps |= MAC_2500FD;
   489			break;
   490	
   491		case PHY_INTERFACE_MODE_5GBASER:
   492			caps |= MAC_5000FD;
   493			break;
   494	
   495		case PHY_INTERFACE_MODE_XGMII:
   496		case PHY_INTERFACE_MODE_RXAUI:
   497		case PHY_INTERFACE_MODE_XAUI:
   498		case PHY_INTERFACE_MODE_10GBASER:
   499		case PHY_INTERFACE_MODE_10GKR:
   500			caps |= MAC_10000FD;
   501			break;
   502	
   503		case PHY_INTERFACE_MODE_25GBASER:
   504			caps |= MAC_25000FD;
   505			break;
   506	
   507		case PHY_INTERFACE_MODE_XLGMII:
   508			caps |= MAC_40000FD;
   509			break;
   510	
   511		case PHY_INTERFACE_MODE_INTERNAL:
   512			caps |= ~0;
   513			break;
   514	
   515		case PHY_INTERFACE_MODE_NA:
   516		case PHY_INTERFACE_MODE_MAX:
   517			break;
   518		}
   519	
   520		switch (rate_adaptation) {
   521		case RATE_ADAPT_OPEN_LOOP:
   522			/* TODO */
   523			fallthrough;
   524		case RATE_ADAPT_NONE:
   525			adapted_caps = 0;
   526			break;
   527		case RATE_ADAPT_PAUSE: {
   528			/* The MAC must support asymmetric pause towards the local
   529			 * device for this. We could allow just symmetric pause, but
   530			 * then we might have to renegotiate if the link partner
   531			 * doesn't support pause. This is because there's no way to
   532			 * accept pause frames without transmitting them if we only
   533			 * support symmetric pause.
   534			 */
   535			if (!(mac_capabilities & MAC_SYM_PAUSE) ||
   536			    !(mac_capabilities & MAC_ASYM_PAUSE))
   537				break;
   538	
   539			/* We can't adapt if the MAC doesn't support the interface's
   540			 * max speed at full duplex.
   541			 */
   542			if (mac_capabilities &
 > 543			    phylink_cap_from_speed_duplex(max_speed, DUPLEX_FULL)) {
   544				/* Although a duplex-adapting phy might exist, we
   545				 * conservatively remove these modes because the MAC
   546				 * will not be aware of the half-duplex nature of the
   547				 * link.
   548				 */
   549				adapted_caps = GENMASK(__fls(caps), __fls(MAC_10HD));
   550				adapted_caps &= ~(MAC_1000HD | MAC_100HD | MAC_10HD);
   551			}
   552			break;
   553		}
   554		case RATE_ADAPT_CRS:
   555			/* The MAC must support half duplex at the interface's max
   556			 * speed.
   557			 */
   558			if (mac_capabilities &
   559			    phylink_cap_from_speed_duplex(max_speed, DUPLEX_HALF)) {
   560				adapted_caps = GENMASK(__fls(caps), __fls(MAC_10HD));
   561				adapted_caps &= mac_capabilities;
   562			}
   563			break;
   564		}
   565	
   566		return (caps & mac_capabilities) | adapted_caps;
   567	}
   568	EXPORT_SYMBOL_GPL(phylink_get_capabilities);
   569
diff mbox series

Patch

diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
index 3e4bbeb1fab2..6cc033148ebf 100644
--- a/drivers/net/phy/phylink.c
+++ b/drivers/net/phy/phylink.c
@@ -433,14 +433,18 @@  EXPORT_SYMBOL_GPL(phylink_caps_find_max_speed);
  * phylink_get_capabilities() - get capabilities for a given MAC
  * @interface: phy interface mode defined by &typedef phy_interface_t
  * @mac_capabilities: bitmask of MAC capabilities
+ * @rate_adaptation: type of rate adaptation being performed
  *
  * Get the MAC capabilities that are supported by the @interface mode and
  * @mac_capabilities.
  */
 unsigned long phylink_get_capabilities(phy_interface_t interface,
-				       unsigned long mac_capabilities)
+				       unsigned long mac_capabilities,
+				       int rate_adaptation)
 {
+	int max_speed = phylink_interface_max_speed(interface);
 	unsigned long caps = MAC_SYM_PAUSE | MAC_ASYM_PAUSE;
+	unsigned long adapted_caps = 0;
 
 	switch (interface) {
 	case PHY_INTERFACE_MODE_USXGMII:
@@ -513,7 +517,53 @@  unsigned long phylink_get_capabilities(phy_interface_t interface,
 		break;
 	}
 
-	return caps & mac_capabilities;
+	switch (rate_adaptation) {
+	case RATE_ADAPT_OPEN_LOOP:
+		/* TODO */
+		fallthrough;
+	case RATE_ADAPT_NONE:
+		adapted_caps = 0;
+		break;
+	case RATE_ADAPT_PAUSE: {
+		/* The MAC must support asymmetric pause towards the local
+		 * device for this. We could allow just symmetric pause, but
+		 * then we might have to renegotiate if the link partner
+		 * doesn't support pause. This is because there's no way to
+		 * accept pause frames without transmitting them if we only
+		 * support symmetric pause.
+		 */
+		if (!(mac_capabilities & MAC_SYM_PAUSE) ||
+		    !(mac_capabilities & MAC_ASYM_PAUSE))
+			break;
+
+		/* We can't adapt if the MAC doesn't support the interface's
+		 * max speed at full duplex.
+		 */
+		if (mac_capabilities &
+		    phylink_cap_from_speed_duplex(max_speed, DUPLEX_FULL)) {
+			/* Although a duplex-adapting phy might exist, we
+			 * conservatively remove these modes because the MAC
+			 * will not be aware of the half-duplex nature of the
+			 * link.
+			 */
+			adapted_caps = GENMASK(__fls(caps), __fls(MAC_10HD));
+			adapted_caps &= ~(MAC_1000HD | MAC_100HD | MAC_10HD);
+		}
+		break;
+	}
+	case RATE_ADAPT_CRS:
+		/* The MAC must support half duplex at the interface's max
+		 * speed.
+		 */
+		if (mac_capabilities &
+		    phylink_cap_from_speed_duplex(max_speed, DUPLEX_HALF)) {
+			adapted_caps = GENMASK(__fls(caps), __fls(MAC_10HD));
+			adapted_caps &= mac_capabilities;
+		}
+		break;
+	}
+
+	return (caps & mac_capabilities) | adapted_caps;
 }
 EXPORT_SYMBOL_GPL(phylink_get_capabilities);
 
@@ -537,7 +587,8 @@  void phylink_generic_validate(struct phylink_config *config,
 	phylink_set_port_modes(mask);
 	phylink_set(mask, Autoneg);
 	caps = phylink_get_capabilities(state->interface,
-					config->mac_capabilities);
+					config->mac_capabilities,
+					state->rate_adaptation);
 	phylink_caps_to_linkmodes(mask, caps);
 
 	linkmode_and(supported, supported, mask);
@@ -1563,6 +1614,7 @@  static int phylink_bringup_phy(struct phylink *pl, struct phy_device *phy,
 		config.interface = PHY_INTERFACE_MODE_NA;
 	else
 		config.interface = interface;
+	config.rate_adaptation = phy_get_rate_adaptation(phy, config.interface);
 
 	ret = phylink_validate(pl, supported, &config);
 	if (ret) {
diff --git a/include/linux/phylink.h b/include/linux/phylink.h
index 192a18a8674a..265a344e1039 100644
--- a/include/linux/phylink.h
+++ b/include/linux/phylink.h
@@ -543,7 +543,8 @@  void phylink_caps_to_linkmodes(unsigned long *linkmodes, unsigned long caps);
 int phylink_caps_find_max_speed(unsigned long caps, int *speed,
 				unsigned int *duplex);
 unsigned long phylink_get_capabilities(phy_interface_t interface,
-				       unsigned long mac_capabilities);
+				       unsigned long mac_capabilities,
+				       int rate_adaptation);
 void phylink_generic_validate(struct phylink_config *config,
 			      unsigned long *supported,
 			      struct phylink_link_state *state);