net: mv643xx_eth: fix DT port device name
Subsystems (3)
Sebastian Hesselbarth
maintainerPATCH 1/1 net: mv643xx_eth: fix DT port device name
Device tree support added to Marvell MV643xx ethernet driver registers port devices from port device nodes found on the corresponding controller node. The current port device name will cause the second controller to fail on registration because of two identical device names. This fixes the issue by taking the device node's name also as port device name.
---
Cc: Lennert Buytenhek <[email protected]>
Cc: Jonas Gorski <[email protected]>
Cc: netdev at vger.kernel.org
Cc: linux-arm-kernel at lists.infradead.org
Cc: linux-kernel at vger.kernel.org
--- drivers/net/ethernet/marvell/mv643xx_eth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/marvell/mv643xx_eth.c +1 -1
@@ -2521,7 +2521,7 @@ static int mv643xx_eth_shared_of_add_port(struct platform_device *pdev,of_property_read_u32 (pnp,"duplex" , &ppd.duplex); } - ppdev =platform_device_alloc (MV643XX_ETH_NAME , ppd.port_number); + ppdev =platform_device_alloc (pnp->name, ppd.port_number);if (!ppdev)return -ENOMEM ; ppdev->dev.coherent_dma_mask =DMA_BIT_MASK (32 );
Signature · 1 line
1.7.10.4
Quoted 23 lines · On Sun, 7 Jul 2013 22:33:51 +0200 Sebastian Hesselbarth…
Device tree support added to Marvell MV643xx ethernet driver registers port devices from port device nodes found on the corresponding controller node. The current port device name will cause the second controller to fail on registration because of two identical device names. This fixes the issue by taking the device node's name also as port device name.
Signed-off-by Sebastian Hesselbarth <[email protected]>Reported-by Jonas Gorski <[email protected]>---
Cc: Lennert Buytenhek <[email protected]>
Cc: Jonas Gorski <[email protected]>
Cc: netdev at vger.kernel.org
Cc: linux-arm-kernel at lists.infradead.org
Cc: linux-kernel at vger.kernel.org--- drivers/net/ethernet/marvell/mv643xx_eth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/ethernet/marvell/mv643xx_eth.c +0
-0
drivers/net/ethernet/marvell/mv643xx_eth.c static int mv643xx_eth_shared_of_add_port(struct platform_device *pdev, · line 2527
Quoted 8 lines
drivers/net/ethernet/marvell/mv643xx_eth.c +1
-1@@ -2521,7 +2521,7 @@ static int mv643xx_eth_shared_of_add_port(struct platform_device *pdev,of_property_read_u32 (pnp,"duplex" , &ppd.duplex); } - ppdev =platform_device_alloc (MV643XX_ETH_NAME , ppd.port_number); + ppdev =platform_device_alloc (pnp->name, ppd.port_number);if (!ppdev)return -ENOMEM ; ppdev->dev.coherent_dma_mask =DMA_BIT_MASK (32 );
This breaks ethernet completely, as there is no platform driver registered for pnp->name ("ethernetX-port"), only for MV643XX_ETH_NAME.
Also since I didn't see a patch for it and no mentioning of it:
There's still one further issue from having two ethernet-ports with port_number 0, it causes a device leak:
static struct platform_device *port_platdev[3];
mv643xx_eth_shared_of_add_port()
{
...
port_platdev[ppd.port_number] = ppdev;
...
}The second port at 0 will overwrite the first and thus will never be deleted in
mv643xx_eth_shared_of_remove()
{
...
for (n = 0; n < 3; n++) {
platform_device_del(port_platdev[n]);
port_platdev[n] = NULL;
}
}I doubt a insmod-rmmod-insmod will go well in that case ;-)
Regards
Jonas
Sebastian Hesselbarth
maintainerQuoted 29 lines · Jonas Gorski
Quoted 26 lines · On Sun, 7 Jul 2013 22:33:51 +0200 Sebastian…
Device tree support added to Marvell MV643xx ethernet driver registers port devices from port device nodes found on the corresponding controller node. The current port device name will cause the second controller to fail on registration because of two identical device names. This fixes the issue by taking the device node's name also as port device name.
Signed-off-by Sebastian Hesselbarth<[email protected]>Reported-by Jonas Gorski<[email protected]>---
Cc: Lennert Buytenhek<[email protected]>
Cc: Jonas Gorski<[email protected]>
Cc: netdev at vger.kernel.org
Cc: linux-arm-kernel at lists.infradead.org
Cc: linux-kernel at vger.kernel.org--- drivers/net/ethernet/marvell/mv643xx_eth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/ethernet/marvell/mv643xx_eth.c +0
-0@@ -2521,7 +2521,7 @@ static int mv643xx_eth_shared_of_add_port(struct platform_device *pdev,of_property_read_u32 (pnp,"duplex" ,&ppd.duplex); }
Quoted 8 lines
drivers/net/ethernet/marvell/mv643xx_eth.c static int mv643xx_eth_shared_of_add_port(struct platform_device *pdev, · line 2527
Quoted 5 lines
drivers/net/ethernet/marvell/mv643xx_eth.c +1
-1- ppdev =platform_device_alloc (MV643XX_ETH_NAME , ppd.port_number); + ppdev =platform_device_alloc (pnp->name, ppd.port_number);if (!ppdev)return -ENOMEM ; ppdev->dev.coherent_dma_mask =DMA_BIT_MASK (32 );This breaks ethernet completely, as there is no platform driver registered for
pnp->name("ethernetX-port"), only forMV643XX_ETH_NAME.
Jonas,
I asked you to test the above earlier today. You said this would fix the issue. I have no Kirkwood board with two ethernet's available, so I really needed on your help here.
Please prepare a patch yourself, that fixes the issue.
Sebastian
Quoted 31 lines
Also since I didn't see a patch for it and no mentioning of it:
There's still one further issue from having two ethernet-ports with
port_number0, it causes a device leak:static struct
platform_device*port_platdev[3];
mv643xx_eth_shared_of_add_port(){ ... port_platdev[ppd.port_number] = ppdev; ... }The second port at 0 will overwrite the first and thus will never be deleted in
mv643xx_eth_shared_of_remove(){ ... for (n = 0; n< 3; n++) { platform_device_del(port_platdev[n]); port_platdev[n] = NULL; } }I doubt a insmod-rmmod-insmod will go well in that case ;-)
Regards
Jonas
PATCH 1/1 net: mv643xx_eth: do not use port number as platform device id
The port number is only local to the ethernet block, not global, so there can be two ethernet blocks both using the same port, like kirkwood with both using port 0.
Fix this by using the array index offset for the allocated platform devices as the id.
--- drivers/net/ethernet/marvell/mv643xx_eth.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/net/ethernet/marvell/mv643xx_eth.c +11 -2
@@ -2483,6 +2483,7 @@ static int mv643xx_eth_shared_of_add_port(struct platform_device *pdev,struct resource res;const char *mac_addr;int ret; +int dev_num =0 ;memset (&ppd,0 ,sizeof (ppd)); ppd.shared = pdev;
@@ -2503,6 +2504,14 @@ static int mv643xx_eth_shared_of_add_port(struct platform_device *pdev,return -EINVAL ; } +while (dev_num <3 && port_platdev[dev_num]) + dev_num++; + +if (dev_num ==3 ) { +dev_err (&pdev->dev,"too many ports registered\n" ); +return -EINVAL ; + } + mac_addr =of_get_mac_address (pnp);if (mac_addr)memcpy (ppd.mac_addr, mac_addr,6 );
@@ -2521,7 +2530,7 @@ static int mv643xx_eth_shared_of_add_port(struct platform_device *pdev,of_property_read_u32 (pnp,"duplex" , &ppd.duplex); } - ppdev =platform_device_alloc (MV643XX_ETH_NAME , ppd.port_number); + ppdev =platform_device_alloc (MV643XX_ETH_NAME , dev_num);if (!ppdev)return -ENOMEM ; ppdev->dev.coherent_dma_mask =DMA_BIT_MASK (32 );
@@ -2538,7 +2547,7 @@ static int mv643xx_eth_shared_of_add_port(struct platform_device *pdev,if (ret) goto port_err; - port_platdev[ppd.port_number] = ppdev; + port_platdev[dev_num] = ppdev;return 0 ;
Signature · 1 line
1.8.3.2
Quoted 29 lines · On Sun, 7 Jul 2013 23:43:41 +0200 Jonas Gorski <[email protected]> wrote:
Quoted 26 lines · On Sun, 7 Jul 2013 22:33:51 +0200 Sebastian Hesselbarth…
Device tree support added to Marvell MV643xx ethernet driver registers port devices from port device nodes found on the corresponding controller node. The current port device name will cause the second controller to fail on registration because of two identical device names. This fixes the issue by taking the device node's name also as port device name.
Signed-off-by Sebastian Hesselbarth <[email protected]>Reported-by Jonas Gorski <[email protected]>---
Cc: Lennert Buytenhek <[email protected]>
Cc: Jonas Gorski <[email protected]>
Cc: netdev at vger.kernel.org
Cc: linux-arm-kernel at lists.infradead.org
Cc: linux-kernel at vger.kernel.org--- drivers/net/ethernet/marvell/mv643xx_eth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/ethernet/marvell/mv643xx_eth.c +0
-0@@ -2521,7 +2521,7 @@ static int mv643xx_eth_shared_of_add_port(struct platform_device *pdev,of_property_read_u32 (pnp,"duplex" , &ppd.duplex); }
Quoted 8 lines
drivers/net/ethernet/marvell/mv643xx_eth.c static int mv643xx_eth_shared_of_add_port(struct platform_device *pdev, · line 2527
Quoted 5 lines
drivers/net/ethernet/marvell/mv643xx_eth.c +1
-1- ppdev =platform_device_alloc (MV643XX_ETH_NAME , ppd.port_number); + ppdev =platform_device_alloc (pnp->name, ppd.port_number);if (!ppdev)return -ENOMEM ; ppdev->dev.coherent_dma_mask =DMA_BIT_MASK (32 );This breaks ethernet completely, as there is no platform driver registered for
pnp->name("ethernetX-port"), only forMV643XX_ETH_NAME.
Looking back at our conversation, this is my fault.
I actually did not change this part as you asked, but I saw the alloc/del issue with port 0, then added the counter and also only replaced the ppd.port_number in the alloc with it. I had completely forgotten at that time to replace the device name; else I would have caught it back then.
I only caught it now because I tried your patch and wondered why there wasn't anything registered, not because I saw the problem by review.
Sorry for that.
Regards
Jonas
Hi Sebastian, Jonas,
first of all thank you for your HUGE efforts in this area.
Quoted 48 lines · Jonas Gorski
Quoted 29 lines · On Sun, 7 Jul 2013 23:43:41 +0200 Jonas Gorski <[email protected]> wrote:
Quoted 26 lines · On Sun, 7 Jul 2013 22:33:51 +0200 Sebastian Hesselbarth…
Device tree support added to Marvell MV643xx ethernet driver registers port devices from port device nodes found on the corresponding controller node. The current port device name will cause the second controller to fail on registration because of two identical device names. This fixes the issue by taking the device node's name also as port device name.
Signed-off-by Sebastian Hesselbarth <[email protected]>Reported-by Jonas Gorski <[email protected]>---
Cc: Lennert Buytenhek <[email protected]>
Cc: Jonas Gorski <[email protected]>
Cc: netdev at vger.kernel.org
Cc: linux-arm-kernel at lists.infradead.org
Cc: linux-kernel at vger.kernel.org--- drivers/net/ethernet/marvell/mv643xx_eth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/ethernet/marvell/mv643xx_eth.c +0
-0@@ -2521,7 +2521,7 @@ static int mv643xx_eth_shared_of_add_port(struct platform_device *pdev,of_property_read_u32 (pnp,"duplex" , &ppd.duplex); }Quoted 8 lines
drivers/net/ethernet/marvell/mv643xx_eth.c static int mv643xx_eth_shared_of_add_port(struct platform_device *pdev, · line 2527
Quoted 5 lines
drivers/net/ethernet/marvell/mv643xx_eth.c +1
-1- ppdev =platform_device_alloc (MV643XX_ETH_NAME , ppd.port_number); + ppdev =platform_device_alloc (pnp->name, ppd.port_number);if (!ppdev)return -ENOMEM ; ppdev->dev.coherent_dma_mask =DMA_BIT_MASK (32 );This breaks ethernet completely, as there is no platform driver registered for
pnp->name("ethernetX-port"), only forMV643XX_ETH_NAME.Looking back at our conversation, this is my fault.
I actually did not change this part as you asked, but I saw the alloc/del issue with port 0, then added the counter and also only replaced the ppd.port_number in the alloc with it. I had completely forgotten at that time to replace the device name; else I would have caught it back then.
Quoted 3 lines
I only caught it now because I tried your patch and wondered why there wasn't anything registered, not because I saw the problem by review.
The way I understand it, you are "manually" creating platform devices off the port subnodes (which, incidentally, have a compatible = "marvell,kirkwood-eth-port" property), but matching with the driver is indeed performed by device name.
Hence Sebastian's first patch breaks everything and Jonas' latest one fixes it. Is that correct? Is there any more work ongoing in this area?
One more question: if my understanding above is correct, what's the reason for NOT having an of_device_id[] table, which looks like was present in Florian Fainelli's first proposal [1]?
I'm also willing to help testing your present/future kirkwood patches if you like. Please just put me on Cc:
Thank you,
Gerlando
[1] http://lists.openwall.net/netdev/2013/04/04/42
Quoted 5 lines
Sorry for that.
Regards
Jonas
Sebastian Hesselbarth
maintainerQuoted 67 lines · Gerlando Falauto
Hi Sebastian, Jonas,
first of all thank you for your HUGE efforts in this area.
Quoted 51 lines · Jonas Gorski
Quoted 32 lines · On Sun, 7 Jul 2013 23:43:41 +0200 Jonas Gorski <[email protected]> wrote:
Quoted 29 lines · On Sun, 7 Jul 2013 22:33:51 +0200 Sebastian Hesselbarth…
Device tree support added to Marvell MV643xx ethernet driver registers port devices from port device nodes found on the corresponding controller
node. The current port device name will cause the second controller to fail on registration because of two identical device names. This fixes the issue by taking the device node's name also as port device name.Signed-off-by Sebastian Hesselbarth <[email protected]>Reported-by Jonas Gorski <[email protected]>---
Cc: Lennert Buytenhek <[email protected]>
Cc: Jonas Gorski <[email protected]>
Cc: netdev at vger.kernel.org
Cc: linux-arm-kernel at lists.infradead.org
Cc: linux-kernel at vger.kernel.org--- drivers/net/ethernet/marvell/mv643xx_eth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/ethernet/marvell/mv643xx_eth.c +0
-0@@ -2521,7 +2521,7 @@ static int mv643xx_eth_shared_of_add_port(struct platform_device *pdev, of_property_read_u32(pnp, "duplex", &ppd.duplex); }Quoted 8 lines
Quoted 5 lines
drivers/net/ethernet/marvell/mv643xx_eth.c +1
-1- ppdev =platform_device_alloc (MV643XX_ETH_NAME , ppd.port_number); + ppdev =platform_device_alloc (pnp->name, ppd.port_number);if (!ppdev)return -ENOMEM ;ppdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);This breaks ethernet completely, as there is no platform driver registered for
pnp->name("ethernetX-port"), only forMV643XX_ETH_NAME.Looking back at our conversation, this is my fault.
I actually did not change this part as you asked, but I saw the alloc/del issue with port 0, then added the counter and also only replaced the ppd.port_number in the alloc with it. I had completely forgotten at that time to replace the device name; else I would have caught it back then.Quoted 3 lines
I only caught it now because I tried your patch and wondered why there wasn't anything registered, not because I saw the problem by review.
The way I understand it, you are "manually" creating platform devices off the port subnodes (which, incidentally, have a compatible = "marvell,kirkwood-eth-port" property), but matching with the driver is indeed performed by device name.
Hence Sebastian's first patch breaks everything and Jonas' latest one fixes it. Is that correct? Is there any more work ongoing in this area?
Quoted 3 lines
One more question: if my understanding above is correct, what's the reason for NOT having an of_device_id[] table, which looks like was present in Florian Fainelli's first proposal [1]?
Gerlando,
for the long run, I plan to break with controller/port device separation. I haven't looked into netdev internals, but I guess you can have more than one netdev per platform_device.
Using one device per controller will remove some temporal dependencies of when which driver gets loaded (there will be only one) and also the root cause of the issue fixed by Jonas.
But it is not on my top priority list, but after fixing MAC address obliviousness, suspend/resume and initial port setup.
Quoted 2 lines
I'm also willing to help testing your present/future kirkwood patches if you like. Please just put me on Cc:
I once put too many people on Cc and that caused ML rejects, but if I remember it I will keep you posted.
Sebastian