From: Thomas Petazzoni <hidden> Date: 2013-09-06 15:18:17
Hello,
Here is a second version of the patch set that adds a Device Tree
binding and the related code to support fixed PHYs. Marked as RFC,
this patch set is obviously not intended for merging in 3.12.
Since the first version, the changes have been:
* Instead of using a 'fixed-link' property inside the Ethernet device
DT node, with a fairly cryptic succession of integer values, we now
use a PHY subnode under the Ethernet device DT node, with explicit
properties to configure the duplex, speed, pause and other PHY
properties.
* The PHY address is automatically allocated by the kernel and no
longer visible in the Device Tree binding.
* The PHY device is created directly when the network driver calls
of_phy_connect_fixed_link(), and associated to the PHY DT node,
which allows the existing of_phy_connect() function to work,
without the need to use the deprecated of_phy_connect_fixed_link().
The things I am not entirely happy with yet are:
* The PHY ID is hardcoded to 0xdeadbeef. Ideally, it should be a
properly reserved vendor/device identifier, but it isn't clear how
to get one allocated for this purpose.
* The fixed_phy_register() function in drivers/net/phy/fixed.c has
some OF references. So ideally, I would have preferred to put this
code in drivers/of/of_mdio.c, but to call get_phy_device(), we need
a reference to the mii_bus structure that represents the fixed MDIO
bus.
* There is some error management missing in fixed_phy_register(), but
it can certainly be added easily. This RFC is meant to sort out the
general idea.
Thanks,
Thomas
Thomas Petazzoni (4):
net: phy: decouple PHY id and PHY address in fixed PHY driver
net: phy: extend fixed driver with fixed_phy_register()
of: provide a binding for fixed link PHYs
net: mvneta: add support for fixed links
.../devicetree/bindings/net/fixed-link.txt | 34 ++++++++++++
.../bindings/net/marvell-armada-370-neta.txt | 4 +-
drivers/net/ethernet/marvell/mvneta.c | 10 ++--
drivers/net/phy/fixed.c | 63 ++++++++++++++++++----
drivers/of/of_mdio.c | 24 +++++++++
include/linux/of_mdio.h | 15 ++++++
include/linux/phy_fixed.h | 11 ++++
7 files changed, 145 insertions(+), 16 deletions(-)
create mode 100644 Documentation/devicetree/bindings/net/fixed-link.txt
--
1.8.1.2
From: Thomas Petazzoni <hidden> Date: 2013-09-06 15:18:18
Until now, the fixed_phy_add() function was taking as argument
'phy_id', which was used both as the PHY address on the fake fixed
MDIO bus, and as the PHY id, as available in the MII_PHYSID1 and
MII_PHYSID2 registers. However, those two informations are completely
unrelated.
This patch decouples them. The PHY id of fixed PHYs is hardcoded to be
0xdeadbeef. Ideally, a really reserved value would be nicer, but there
doesn't seem to be an easy of making sure a dummy value can be
assigned to the Linux kernel for such usage.
The PHY address remains passed by the caller of phy_fixed_add().
Signed-off-by: Thomas Petazzoni <redacted>
---
drivers/net/phy/fixed.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
@@ -104,8 +104,8 @@ static int fixed_phy_update_regs(struct fixed_phy *fp)if(fp->status.asym_pause)lpa|=LPA_PAUSE_ASYM;-fp->regs[MII_PHYSID1]=fp->id>>16;-fp->regs[MII_PHYSID2]=fp->id;+fp->regs[MII_PHYSID1]=0xdead;+fp->regs[MII_PHYSID2]=0xbeef;fp->regs[MII_BMSR]=bmsr;fp->regs[MII_BMCR]=bmcr;
@@ -115,7 +115,7 @@ static int fixed_phy_update_regs(struct fixed_phy *fp)return0;}-staticintfixed_mdio_read(structmii_bus*bus,intphy_id,intreg_num)+staticintfixed_mdio_read(structmii_bus*bus,intphy_addr,intreg_num){structfixed_mdio_bus*fmb=bus->priv;structfixed_phy*fp;
@@ -124,7 +124,7 @@ static int fixed_mdio_read(struct mii_bus *bus, int phy_id, int reg_num)return-1;list_for_each_entry(fp,&fmb->phys,node){-if(fp->id==phy_id){+if(fp->addr==phy_addr){/* Issue callback if user registered it. */if(fp->link_update){fp->link_update(fp->phydev->attached_dev,
@@ -138,7 +138,7 @@ static int fixed_mdio_read(struct mii_bus *bus, int phy_id, int reg_num)return0xFFFF;}-staticintfixed_mdio_write(structmii_bus*bus,intphy_id,intreg_num,+staticintfixed_mdio_write(structmii_bus*bus,intphy_addr,intreg_num,u16val){return0;
@@ -160,7 +160,7 @@ int fixed_phy_set_link_update(struct phy_device *phydev,return-EINVAL;list_for_each_entry(fp,&fmb->phys,node){-if(fp->id==phydev->phy_id){+if(fp->addr==phydev->addr){fp->link_update=link_update;fp->phydev=phydev;return0;
@@ -171,7 +171,7 @@ int fixed_phy_set_link_update(struct phy_device *phydev,}EXPORT_SYMBOL_GPL(fixed_phy_set_link_update);-intfixed_phy_add(unsignedintirq,intphy_id,+intfixed_phy_add(unsignedintirq,intphy_addr,structfixed_phy_status*status){intret;
@@ -184,9 +184,9 @@ int fixed_phy_add(unsigned int irq, int phy_id,memset(fp->regs,0xFF,sizeof(fp->regs[0])*MII_REGS_NUM);-fmb->irqs[phy_id]=irq;+fmb->irqs[phy_addr]=irq;-fp->id=phy_id;+fp->addr=phy_addr;fp->status=*status;ret=fixed_phy_update_regs(fp);
From: Thomas Petazzoni <hidden> Date: 2013-09-06 15:18:19
The existing fixed_phy_add() function has several drawbacks that
prevents it from being used as is for OF-based declaration of fixed
PHYs:
* The address of the PHY on the fake bus needs to be passed, while a
dynamic allocation is desired.
* Since the phy_device instantiation is post-poned until the next
mdiobus scan, there is no way to associate the fixed PHY with its
OF node, which later prevents of_phy_connect() from finding this
fixed PHY from a given OF node.
To solve this, this commit introduces fixed_phy_register(), which will
allocate an available PHY address, add the PHY using fixed_phy_add()
and instantiate the phy_device structure associated with the provided
OF node.
Signed-off-by: Thomas Petazzoni <redacted>
---
drivers/net/phy/fixed.c | 43 +++++++++++++++++++++++++++++++++++++++++++
include/linux/phy_fixed.h | 11 +++++++++++
2 files changed, 54 insertions(+)
@@ -203,6 +204,48 @@ err_regs:}EXPORT_SYMBOL_GPL(fixed_phy_add);+staticintphy_fixed_addr;+staticDEFINE_SPINLOCK(phy_fixed_addr_lock);++intfixed_phy_register(unsignedintirq,+structfixed_phy_status*status,+structdevice_node*np)+{+structfixed_mdio_bus*fmb=&platform_fmb;+structphy_device*phy;+intphy_addr;+intret;++/* Get the next available PHY address, up to PHY_MAX_ADDR */+spin_lock(&phy_fixed_addr_lock);+if(phy_fixed_addr==PHY_MAX_ADDR){+spin_unlock(&phy_fixed_addr_lock);+return-ENOSPC;+}+phy_addr=phy_fixed_addr++;+spin_unlock(&phy_fixed_addr_lock);++ret=fixed_phy_add(PHY_POLL,phy_addr,status);+if(ret<0)+returnret;++phy=get_phy_device(fmb->mii_bus,phy_addr,false);+if(!phy||IS_ERR(phy))+return-EINVAL;++of_node_get(np);+phy->dev.of_node=np;++ret=phy_device_register(phy);+if(ret){+phy_device_free(phy);+of_node_put(np);+returnret;+}++return0;+}+staticint__initfixed_mdio_bus_init(void){structfixed_mdio_bus*fmb=&platform_fmb;
From: Thomas Petazzoni <hidden> Date: 2013-09-06 15:18:20
Some Ethernet MACs have a "fixed link", and are not connected to a
normal MDIO-managed PHY device. For those situations, a Device Tree
binding allows to describe a "fixed link" using a special PHY node.
This patch adds:
* A documentation for the fixed PHY Device Tree binding.
* An of_phy_is_fixed_link() function that an Ethernet driver can call
on its PHY phandle to find out whether it's a fixed link PHY or
not. It should typically be used to know if
of_phy_register_fixed_link() should be called.
* An of_phy_register_fixed_link() function that instantiates the
fixed PHY into the PHY subsystem, so that when the driver calls
of_phy_connect(), the PHY device associated to the OF node will be
found.
Signed-off-by: Thomas Petazzoni <redacted>
---
.../devicetree/bindings/net/fixed-link.txt | 34 ++++++++++++++++++++++
drivers/of/of_mdio.c | 24 +++++++++++++++
include/linux/of_mdio.h | 15 ++++++++++
3 files changed, 73 insertions(+)
create mode 100644 Documentation/devicetree/bindings/net/fixed-link.txt
@@ -0,0 +1,34 @@+Fixed link Device Tree binding+------------------------------++Some Ethernet MACs have a "fixed link", and are not connected to a+normal MDIO-managed PHY device. For those situations, a Device Tree+binding allows to describe a "fixed link".++Such a fixed link situation is described by creating a PHY node as a+sub-node of an Ethernet device, with the following properties:++* 'fixed-link' (boolean, mandatory), to indicate that this PHY is a+ fixed link PHY.+* 'speed' (integer, mandatory), to indicate the link speed. Accepted+ values are 10, 100 and 1000+* 'full-duplex' (boolean, optional), to indicate that full duplex is+ used. When absent, half duplex is assumed.+* 'pause' (boolean, optional), to indicate that pause should be+ enabled.+* 'asym-pause' (boolean, optional), to indicate that asym_pause should+ be enabled.++Example:++ethernet@0 {+ ...+ phy = <&phy0>;+ phy0: phy@0 {+ fixed-link;+ speed = <1000>;+ full-duplex;+ };+ ...+};+
From: Thomas Petazzoni <hidden> Date: 2013-09-06 15:18:21
Following the introduction of of_phy_register_fixed_link(), this patch
introduces fixed link support in the mvneta driver, for Marvell Armada
370/XP SOCs.
Signed-off-by: Thomas Petazzoni <redacted>
---
.../devicetree/bindings/net/marvell-armada-370-neta.txt | 4 ++--
drivers/net/ethernet/marvell/mvneta.c | 10 ++++++----
2 files changed, 8 insertions(+), 6 deletions(-)
@@ -4,8 +4,8 @@ Required properties: - compatible: should be "marvell,armada-370-neta". - reg: address and length of the register set for the device. - interrupts: interrupt for the device-- phy: A phandle to a phy node defining the PHY address (as the reg- property, a single integer).+- phy: A phandle to the PHY node describing the PHY to which this+ Ethernet controller is connected to. - phy-mode: The interface between the SoC and the PHY (a string that of_get_phy_mode() can understand) - clocks: a pointer to the reference clock for this device.
Hello Thomas,
Le vendredi 6 septembre 2013 17:18:17 Thomas Petazzoni a écrit :
Hello,
Here is a second version of the patch set that adds a Device Tree
binding and the related code to support fixed PHYs. Marked as RFC,
this patch set is obviously not intended for merging in 3.12.
Thanks a lot for continuing on this work, I really like the state of it now.
Since the first version, the changes have been:
* Instead of using a 'fixed-link' property inside the Ethernet device
DT node, with a fairly cryptic succession of integer values, we now
use a PHY subnode under the Ethernet device DT node, with explicit
properties to configure the duplex, speed, pause and other PHY
properties.
* The PHY address is automatically allocated by the kernel and no
longer visible in the Device Tree binding.
* The PHY device is created directly when the network driver calls
of_phy_connect_fixed_link(), and associated to the PHY DT node,
which allows the existing of_phy_connect() function to work,
without the need to use the deprecated of_phy_connect_fixed_link().
The things I am not entirely happy with yet are:
* The PHY ID is hardcoded to 0xdeadbeef. Ideally, it should be a
properly reserved vendor/device identifier, but it isn't clear how
to get one allocated for this purpose.
Right, we should try to get something better, but we obviously cannot use an
already allocated OUI for this. Can we ask the Linux foundation or a Linux-
friendly company to allocate one maybe?
* The fixed_phy_register() function in drivers/net/phy/fixed.c has
some OF references. So ideally, I would have preferred to put this
code in drivers/of/of_mdio.c, but to call get_phy_device(), we need
a reference to the mii_bus structure that represents the fixed MDIO
bus.
This is not a big deal, not everything in drivers/ is consistent with this,
and making the fixed MDIO bus globally accessible does not sound too great.
* There is some error management missing in fixed_phy_register(), but
it can certainly be added easily. This RFC is meant to sort out the
general idea.
Do you think you could add these to got beyond the RFC state? The patchset as
it currently is fine with me if you can address these.
--
Florian
Here is a second version of the patch set that adds a Device Tree
binding and the related code to support fixed PHYs. Marked as RFC,
this patch set is obviously not intended for merging in 3.12.
Thanks a lot for continuing on this work, I really like the state of it now.
Thanks for your feedback.
quoted
Since the first version, the changes have been:
* Instead of using a 'fixed-link' property inside the Ethernet device
DT node, with a fairly cryptic succession of integer values, we now
use a PHY subnode under the Ethernet device DT node, with explicit
properties to configure the duplex, speed, pause and other PHY
properties.
* The PHY address is automatically allocated by the kernel and no
longer visible in the Device Tree binding.
* The PHY device is created directly when the network driver calls
of_phy_connect_fixed_link(), and associated to the PHY DT node,
which allows the existing of_phy_connect() function to work,
without the need to use the deprecated of_phy_connect_fixed_link().
The things I am not entirely happy with yet are:
* The PHY ID is hardcoded to 0xdeadbeef. Ideally, it should be a
properly reserved vendor/device identifier, but it isn't clear how
to get one allocated for this purpose.
Right, we should try to get something better, but we obviously cannot use an
already allocated OUI for this. Can we ask the Linux foundation or a Linux-
friendly company to allocate one maybe?
* The fixed_phy_register() function in drivers/net/phy/fixed.c has
some OF references. So ideally, I would have preferred to put this
code in drivers/of/of_mdio.c, but to call get_phy_device(), we need
a reference to the mii_bus structure that represents the fixed MDIO
bus.
This is not a big deal, not everything in drivers/ is consistent with this,
and making the fixed MDIO bus globally accessible does not sound too great.
Indeed.
quoted
* There is some error management missing in fixed_phy_register(), but
it can certainly be added easily. This RFC is meant to sort out the
general idea.
Do you think you could add these to got beyond the RFC state? The patchset as
it currently is fine with me if you can address these.
Sure, it shouldn't be too difficult.
In the mean time, I'm interested in hearing comments from other people,
especially from the Device Tree bindings maintainers: while the
internal implementation details can always be fixed later on, the DT
binding should obviously get an approval from the DT maintainers.
Thanks,
Thomas
--
Thomas Petazzoni, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com
On Fri, Sep 06, 2013 at 05:18:17PM +0200, Thomas Petazzoni wrote:
Hello,
Here is a second version of the patch set that adds a Device Tree
binding and the related code to support fixed PHYs. Marked as RFC,
this patch set is obviously not intended for merging in 3.12.
Since the first version, the changes have been:
* Instead of using a 'fixed-link' property inside the Ethernet device
DT node, with a fairly cryptic succession of integer values, we now
use a PHY subnode under the Ethernet device DT node, with explicit
properties to configure the duplex, speed, pause and other PHY
properties.
* The PHY address is automatically allocated by the kernel and no
longer visible in the Device Tree binding.
* The PHY device is created directly when the network driver calls
of_phy_connect_fixed_link(), and associated to the PHY DT node,
which allows the existing of_phy_connect() function to work,
without the need to use the deprecated of_phy_connect_fixed_link().
The things I am not entirely happy with yet are:
* The PHY ID is hardcoded to 0xdeadbeef. Ideally, it should be a
properly reserved vendor/device identifier, but it isn't clear how
to get one allocated for this purpose.
* The fixed_phy_register() function in drivers/net/phy/fixed.c has
some OF references. So ideally, I would have preferred to put this
code in drivers/of/of_mdio.c, but to call get_phy_device(), we need
a reference to the mii_bus structure that represents the fixed MDIO
bus.
* There is some error management missing in fixed_phy_register(), but
it can certainly be added easily. This RFC is meant to sort out the
general idea.
+1 for the general idea. This really looks good now. I've not much more
to say. Maybe someone from the devicetree corner has a few words for the
binding?
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Hello Thomas,
2013/9/6 Thomas Petazzoni [off-list ref]:
+Some Ethernet MACs have a "fixed link", and are not connected to a
+normal MDIO-managed PHY device. For those situations, a Device Tree
+binding allows to describe a "fixed link".
+
+Such a fixed link situation is described by creating a PHY node as a
+sub-node of an Ethernet device, with the following properties:
+
+* 'fixed-link' (boolean, mandatory), to indicate that this PHY is a
+ fixed link PHY.
+* 'speed' (integer, mandatory), to indicate the link speed. Accepted
+ values are 10, 100 and 1000
'max-speed' might be better here to match ePAPR v1.1 (if we do care,
'speed') works for me too.
+* 'full-duplex' (boolean, optional), to indicate that full duplex is
+ used. When absent, half duplex is assumed.
+* 'pause' (boolean, optional), to indicate that pause should be
+ enabled.
+* 'asym-pause' (boolean, optional), to indicate that asym_pause should
+ be enabled.
We also need to add a property: 'connection-type' which can be any of
'mii', 'rgmii' etc... When operating Ethernet devices with Ethernet
devices connected back to back, it might be required to configure the
Ethernet MAC with an appropriate connection type.
Note that I picked 'connection-type' here because this the ePAPR v1.1
terminology. Now the good thing is that it is a new "feature" wrt. the
old binding.