2022-08-18 17:03:47

by Sean Anderson

[permalink] [raw]
Subject: [PATCH net-next v4 08/10] net: phylink: Adjust advertisement based on rate adaptation

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 <[email protected]>
---

(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(-)

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);
--
2.35.1.1320.gc452695387.dirty


2022-08-18 20:06:05

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH net-next v4 08/10] net: phylink: Adjust advertisement based on rate adaptation

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/[email protected]/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 <[email protected]>

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

--
0-DAY CI Kernel Test Service
https://01.org/lkp

2022-08-18 20:13:59

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH net-next v4 08/10] net: phylink: Adjust advertisement based on rate adaptation

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/[email protected]/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 <[email protected]>

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

--
0-DAY CI Kernel Test Service
https://01.org/lkp