add virtual PHY for PHY-less devices
Subsystems (3)
PATCH 1/1 add virtual PHY for PHY-less devices
From: [email protected]
Here is a kernel related part of my work which was helps to develop brand
new PHY device.
It is migth be helpful for developers work with PHY-less lan743x
(7431:0011 in my case). It's just a fake virtual PHY which can change speed of network card processing as a loopback device. Baud rate can be tuned with ethtool from command line or by means of SIOCSMIIREG ioctl. Duplex mode not configurable and it's allways DUPLEX_FULL.
It also provides module parameter mii_regs for setting initial values of
IEEE 802.3 Control Register.
MAINTAINERS +6 -0
@@ -11423,6 +11448,12 @@ L: [email protected] S: Maintained F: drivers/net/ethernet/microchip/lan743x_* +MICROCHIP LAN743X VIRTUAL PHY DRIVER +M: Sergej Bauer <[email protected]> +L: [email protected] +S: Maintained +F: drivers/net/ethernet/microchip/lan743x_virtual_phy.* + MICROCHIP LCDFB DRIVER M: Nicolas Ferre <[email protected]> L: [email protected]
drivers/net/ethernet/microchip/Makefile +2 -1
@@ -7,4 +7,5 @@ obj-$(CONFIG_ENC28J60) += enc28j60.o obj-$(CONFIG_ENCX24J600) += encx24j600.o encx24j600-regmap.o obj-$(CONFIG_LAN743X) += lan743x.o -lan743x-objs := lan743x_main.o lan743x_ethtool.o lan743x_ptp.o +lan743x-objs := lan743x_main.o lan743x_ethtool.o lan743x_ptp.o \ + lan743x_virtual_phy.o
drivers/net/ethernet/microchip/lan743x_ethtool.c +67 -1
80 lines not on this page · raw message
drivers/net/ethernet/microchip/lan743x_ethtool.h +2 -0
@@ -6,6 +6,8 @@#include "linux/ethtool.h" +int lan743x_set_link_ksettings (struct net_device *netdev, +const struct ethtool_link_ksettings *cmd);extern const struct ethtool_ops lan743x_ethtool_ops;#endif /* _LAN743X_ETHTOOL_H */
drivers/net/ethernet/microchip/lan743x_main.c +136 -12
247 lines not on this page · raw message
drivers/net/ethernet/microchip/lan743x_main.h +7 -0
@@ -104,6 +104,8 @@#define FCT_FLOW_CTL_ON_THRESHOLD_SET_ (value) \ ((value << 0) & FCT_FLOW_CTL_ON_THRESHOLD_) +#define FCT_CFG (0x00DC) +#define MAC_CR (0x100)#define MAC_CR_MII_EN_ BIT(19)#define MAC_CR_EEE_EN_ BIT(17)
@@ -726,6 +728,9 @@ struct lan743x_adapter {#define LAN743X_ADAPTER_FLAG_OTP BIT(0)u32 flags; +u8 virtual_phy; +u16 *regs802p3; +char *name; };#define LAN743X_COMPONENT_FLAG_RX (channel) BIT(20 + (channel))
@@ -839,5 +844,7 @@ struct lan743x_rx_buffer_info {u32 lan743x_csr_read (struct lan743x_adapter *adapter,int offset);void lan743x_csr_write (struct lan743x_adapter *adapter,int offset,u32 data); +void lan743x_netdev_set_bit (struct net_device *netdev,int reg,int n, +int state);#endif /* _LAN743X_H */
drivers/net/ethernet/microchip/lan743x_virtual_phy.c new file +215 -0
215 lines not on this page · raw message
drivers/net/ethernet/microchip/lan743x_virtual_phy.h new file +21 -0
@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* Copyright (C) 2020 Sergej Bauer */ + +#ifndef LAN743X_VIRTUAL_PHY_H +#define LAN743X_VIRTUAL_PHY_H + +#include <linux/phy.h> +#include <uapi/linux/if.h> +#include "lan743x_main.h" + +int lan743x_virtual_phy_mii_ioctl (struct phy_device *phydev, +struct ifreq *ifr,int cmd); + +struct phy_device *lan743x_virtual_phy (struct lan743x_adapter *adapter, +char *mii_regs[],int mi_regs_count); + +int lan743x_virtual_phy_connect (struct net_device *netdev, +struct phy_device *phydev, +void (*handler)(struct net_device *), +phy_interface_t interface); +#endif
Quoted 10 lines · Sergej Bauer
From: [email protected]
Here is a kernel related part of my work which was helps to develop brand
new PHY device.It is migth be helpful for developers work with PHY-less lan743x
(7431:0011 in my case). It's just a fake virtual PHY which can change speed of network card processing as a loopback device. Baud rate can be tuned with ethtool from command line or by means of SIOCSMIIREG ioctl. Duplex mode not configurable and it's allwaysDUPLEX_FULL.
Hi Sergej
What is the advantage of this over using driver/net/phy/fixed_phy.c which also emulates a standard PHY?
Andrew
Quoted 5 lines · Sergej Bauer
From: [email protected]
Here is a kernel related part of my work which was helps to develop brand
new PHY device.
Quoted 8 lines
It is migth be helpful for developers work with PHY-less lan743x
(7431:0011 in my case). It's just a fake virtual PHY which can change speed of network card processing as a loopback device. Baud rate can be tuned with ethtool from command line or by means of SIOCSMIIREG ioctl. Duplex mode not configurable and it's allwaysDUPLEX_FULL.It also provides module parameter
mii_regsfor setting initial values of
IEEE 802.3 Control Register.
You appear to have re-implemented the fixed PHY driver, please use that instead of rolling your own.
Signature · 1 line
Florian
Hi Andrew
To tell the truth, I thought that fixed_phy is only for devices with a Device
Trees and I never met DTS on x86 machines...
So it looks like there realy no any significant advantage _except_ of ability to use ethtool and ioctl to set speed and rx-all/fcs flags without removing module. That was most wanted request from HW designers as they are wanted to change registers of virtual PHY on-the-fly with ethtool either custom tool (using SIOCSMIIREG ioctl) for controling PHY registers.
p.s. And that's my bad, the original driver was developed year ago (for linux-5.2.15),
but I had no time before this moment.
p.p.s. sorry for long time to answer but it's far behind the midnight in my region.
Signature · 1 line
Sergej
Quoted 21 lines · MSK Andrew Lunn
Quoted 5 lines · Sergej Bauer
From: [email protected]
Here is a kernel related part of my work which was helps to develop brand
Quoted 8 lines
new PHY device.
It is migth be helpful for developers work with PHY-less lan743x
(7431:0011 in my case). It's just a fake virtual PHY which can change speed of network card processing as a loopback device. Baud rate can be tuned with ethtool from command line or by means of SIOCSMIIREG ioctl. Duplex mode not configurable and it's allways
DUPLEX_FULL.Hi Sergej
What is the advantage of this over using
driver/net/phy/fixed_phy.cwhich also emulates a standard PHY?Andrew
Hi Florian
The fixed-PHY driver looks a little bit hardly tunable, please look at
https://www.lkml.org/lkml/2020/9/17/1424
This is not my idea. This is a request of HW team, and I thnk it will be
useful for someone else. But I'll try to combine fixed-phy with virtual-PHY tomorrow. It just to rearrange some lines in lan743x_phy_open.
Signature · 1 line
Sergej
Quoted 22 lines · MSK Florian Fainelli
Quoted 14 lines · Sergej Bauer
From: [email protected]
Here is a kernel related part of my work which was helps to develop brand
new PHY device.
It is migth be helpful for developers work with PHY-less lan743x
(7431:0011 in my case). It's just a fake virtual PHY which can change speed of network card processing as a loopback device. Baud rate can be tuned with ethtool from command line or by means of SIOCSMIIREG ioctl. Duplex mode not configurable and it's allways
DUPLEX_FULL.Quoted 4 lines
It also provides module parameter
mii_regsfor setting initial values ofIEEE 802.3 Control Register.
You appear to have re-implemented the fixed PHY driver, please use that instead of rolling your own.
(please do not top-post)
Quoted 4 lines · Sergej Bauer
Hi Andrew
To tell the truth, I thought that
fixed_phyis only for devices with a Device
Trees and I never met DTS on x86 machines...
fixed_phy existed long before Device Tree was popular and you can register a fixed PHY device from within your Ethernet MAC driver, see drivers/net/dsa/dsa_loop.c for an example.
Quoted 6 lines
So it looks like there realy no any significant advantage _except_ of ability to use ethtool and ioctl to set speed and rx-all/fcs flags without removing module. That was most wanted request from HW designers as they are wanted to change registers of virtual PHY on-the-fly with ethtool either custom tool (using SIOCSMIIREG ioctl) for controling PHY registers.
NETIF_F_RXALL and NETIF_F_RXFCS are feature flags that are applicable to the Ethernet MAC, so I am not really sure where the virtual PHY, or the fixed PHY plays a role in those?
The key thing with the fixed PHY is that it is an emulation device, therefore from the Ethernet MAC perspective you can tell (phy_is_pseudo_fixed_link) whether this is a real PHY device on a MDIO bus or the emulated fixed PHY but there is really no need for you to make that difference.
Quoted 9 lines
p.s. And that's my bad, the original driver was developed year ago (for linux-5.2.15),
but I had no time before this moment.p.p.s. sorry for long time to answer but it's far behind the midnight in my region.
Signature · 1 line
Florian