Re: [PATCH net-next v3 10/47] net: phylink: Adjust link settings based on rate adaptation

From: Sean Anderson
Date: Mon Jul 18 2022 - 12:30:01 EST




On 7/16/22 9:39 PM, Andrew Lunn wrote:
>> > I would not do this. If the requirements for rate adaptation are not
>> > fulfilled, you should turn off rate adaptation.
>> >
>> > A MAC which knows rate adaptation is going on can help out, by not
>> > advertising 10Half, 100Half etc. Autoneg will then fail for modes
>> > where rate adaptation does not work.
>>
>> OK, so maybe it is better to phylink_warn here. Something along the
>> lines of "phy using pause-based rate adaptation, but duplex is %s".
>
> You say 1/2 duplex simply does not work with rate adaptation.

It doesn't work with pause-based rate adaptation. This is because we can't
enable pause frames in half duplex (see phy_get_pause). I don't know if this
is a technical limitation (or something else), but presumably there exists a
MAC out there which can't enable pause frames unless it's in full-duplex mode.

> So i
> would actually return -EINVAL at the point the MAC indicates what
> modes it supports if there is a 1/2 duplex mode in the list.

Well, half duplex is still valid if we are at the full line rate. This is more
of a sanity check on what we get back from the phy. That is, we should never
get anything but full duplex if the phy indicates that pause-based rate
adaptation is being performed. So maybe this should live in phy_read_status?

And of course, CRS-based adaptation requires half-duplex (or a MAC which
respects CRS in full-duplex mode).

>>
>> > The MAC should also be declaring what sort of pause it supports, so
>> > disable rate adaptation if it does not have async pause.
>>
>> That's what we do in the previous patch.
>>
>> The problem is that rx_pause and tx_pause are resolved based on our
>> advertisement and the link partner's advertisement. However, the link
>> partner may not support pause frames at all. In that case, we will get
>> rx_pause and tx_pause as false. However, we still want to enable rx_pause,
>> because we know that the phy will be emitting pause frames. And of course
>> the user can always force disable pause frames anyway through ethtool.
>
> Right, so we need a table somewhere in the documentation listing the
> different combinations and what should happen.

OK, so first here's table 28B-3 (e.g. linkmode_resolve_pause):

Local device Link partner Local resolution Partner resolution
============= ============= ================ ==================
PAUSE ASM_DIR PAUSE ASM_DIR Transmit Receive Transmit Receive
===== ======= ===== ======= ======== ======= ======== =======
0 0 X X N N N N
0 1 0 X N N N N
0 1 1 0 N N N N
0 1 1 1 Y N N Y
1 0 0 X N N N N
1 X 1 X Y Y Y Y
1 1 0 0 N N N N
1 1 0 1 N Y Y N

And now here's the same table, but assuming that we have a local phy
performing rate adaptation

Local device Link partner Local resolution Partner resolution
============= ============= ================ ==================
PAUSE ASM_DIR PAUSE ASM_DIR Transmit Receive Transmit Receive
===== ======= ===== ======= ======== ======= ======== =======
0 0 X X N N N N # Broken
0 1 0 X N N N N # Broken
0 1 1 0 N N N N # Broken
0 1 1 1 Y N N Y # Broken
1 0 0 X ? ? N N # Semi-broken
1 X 1 X Y Y Y Y
1 1 0 0 N Y N N
1 1 0 1 N Y Y N

The rows marked as "Broken" don't have local receive pause enabled.
These should never occur, since we can detect that the local MAC doesn't
support pause reception and disable advertisement of pause-based
rate-adapted modes.

On the row marked as "Semi-broken", the local MAC supports only
symmetric pause, and the link partner doesn't support pause. We're not
supposed to send pause frames, so we disable pause, but this breaks rate
adaptation. In this case, we could renegotiate with rate-adapted modes
disabled. Alternatively, we could just decline to advertise rate-adapted
modes for symmetric-pause MACs. This avoids the semi-broken line above,
but also prevents the line below from using rate adaptation.

> If the MAC does not support rx_pause, rate adaptation is turned off.
>> If the negotiation results in no rx_pause, force it on anyway with
> Pause based adaptation. If ethtool turns pause off, turn off rate
> adaptation.
>
> Does 802.3 say anything about this?

Only IPG-based and CRS-based rate adaptation are defined in 802.3.

> We might also want to add an additional state to the ethtool get for
> pause, to indicate rx_pause is enabled because of rate adaptation, not
> because of autoneg.

Probably a good idea.

--Sean