net: mvneta: properly disable HW PHY polling and ensure adjust_link() works
net: mvneta: properly disable HW PHY polling and ensure adjust_link() works

This commit fixes a long-standing bug that has been reported by many
users: on some Armada 370 platforms, only the network interface that
has been used in U-Boot to tftp the kernel works properly in
Linux. The other network interfaces can see a 'link up', but are
unable to transmit data. The reports were generally made on the Armada
370-based Mirabox, but have also been given on the Armada 370-RD
board.

The network MAC in the Armada 370/XP (supported by the mvneta driver
in Linux) has a functionality that allows it to continuously poll the
PHY and directly update the MAC configuration accordingly (speed,
duplex, etc.). The very first versions of the driver submitted for
review were using this hardware mechanism, but due to this, the driver
was not integrated with the kernel phylib. Following reviews, the
driver was changed to use the phylib, and therefore a software based
polling. In software based polling, Linux regularly talks to the PHY
over the MDIO bus, and sees if the link status has changed. If it's
the case then the adjust_link() callback of the driver is called to
update the MAC configuration accordingly.

However, it turns out that the adjust_link() callback was not
configuring the hardware in a completely correct way: while it was
setting the speed and duplex bits correctly, it wasn't telling the
hardware to actually take into account those bits rather than what the
hardware-based PHY polling mechanism has concluded. So, in fact the
adjust_link() callback was basically a no-op.

However, the network happened to be working because on the network
interfaces used by U-Boot for tftp on Armada 370 platforms because the
hardware PHY polling was enabled by the bootloader, and left enabled
by Linux. However, the second network interface not used for tftp (or
both network interfaces if the kernel is loaded from USB, NAND or SD
card) didn't had the hardware PHY polling enabled.

This patch fixes this situation by:

 (1) Making sure that the hardware PHY polling is disabled by clearing
     the MVNETA_PHY_POLLING_ENABLE bit in the MVNETA_UNIT_CONTROL
     register in the driver ->probe() function.

 (2) Making sure that the duplex and speed selections made by the
     adjust_link() callback are taken into account by clearing the
     MVNETA_GMAC_AN_SPEED_EN and MVNETA_GMAC_AN_DUPLEX_EN bits in the
     MVNETA_GMAC_AUTONEG_CONFIG register.

This patch has been tested on Armada 370 Mirabox, and now both network
interfaces are usable after boot.

[ Problem introduced by commit c5aff18 ("net: mvneta: driver for
  Marvell Armada 370/XP network unit") ]

Signed-off-by: Thomas Petazzoni <a5d87d2bd7c424ee5cbdb4e978635bf653d5a005@free-electrons.com>
Cc: Willy Tarreau <aff024fe4ab0fece4091de044c58c9ae4233383a@1wt.eu>
Cc: Jochen De Smet <9dd4d434e80e43ff4e16bd7822e1cf5fb3adb75a@leahnim.org>
Cc: Peter Sanford <7afc8b94bd27fa234d96f707a9ec2259aec8c201@nearbuy.io>
Cc: Ethan Tuttle <0a27e12d062ad71673d57f9c2799b207af316885@ethantuttle.com>
Cc: Chény Yves-Gael <3b1fe340dba76bf37270abad774f327f50b5e1d8@cheny.fr>
Cc: Ryan Press <ea3cd978650417470535f3a4725b6b5042a6ab59@presslab.us>
Cc: Simon Guinot <3ab4e30ada880520f74922b979fc5ca34d9375bb@sequanux.org>
Cc: cfb877cc55bc8fd3927edda486d7ee2c9774fd8d@lacie.com
Cc: 4fbacc2fa0ffdbb11bf1ad6925b886ebd08dd15f@vger.kernel.org
Acked-by: Jason Cooper <68c46a606457643eab92053c1c05574abb26f861@lakedaemon.net>
Tested-by: Vincent Donnefort <cfb877cc55bc8fd3927edda486d7ee2c9774fd8d@gmail.com>
Tested-by: Yves-Gael Cheny <3b1fe340dba76bf37270abad774f327f50b5e1d8@cheny.fr>
Tested-by: Gregory CLEMENT <cd8db494d8ed74d7c3f56ec5c769dff3d51dd397@free-electrons.com>
Signed-off-by: David S. Miller <fe08d3c717adf2ae63592e4c9aec6e3e404d8e3e@davemloft.net>

KristFoundation/Programs,KristFoundation/Programs,KristFoundation/Programs,KristFoundation/Programs,KristFoundation/Programs,KristFoundation/Programs