12e522a1f840391fe54af58cd5a813a85d0f18e3
[openwrt.git] / target / linux / kirkwood / patches-3.10 / 0029-net-mv643xx_eth-do-not-use-port-number-as-platform-d.patch
1 From dc4eff91629aa5132f9c0737ef6d9ef013d4f8ce Mon Sep 17 00:00:00 2001
2 From: Jonas Gorski <jogo@openwrt.org>
3 Date: Mon, 8 Jul 2013 00:44:55 +0200
4 Subject: [PATCH 29/29] net: mv643xx_eth: do not use port number as platform
5  device id
6
7 The port number is only local to the ethernet block, not global, so
8 there can be two ethernet blocks both using the same port, like
9 kirkwood with both using port 0.
10
11 Fix this by using the array index offset for the allocated platform
12 devices as the id.
13
14 Signed-off-by: Jonas Gorski <jogo@openwrt.org>
15 Signed-off-by: David S. Miller <davem@davemloft.net>
16 ---
17  drivers/net/ethernet/marvell/mv643xx_eth.c | 13 +++++++++++--
18  1 file changed, 11 insertions(+), 2 deletions(-)
19
20 --- a/drivers/net/ethernet/marvell/mv643xx_eth.c
21 +++ b/drivers/net/ethernet/marvell/mv643xx_eth.c
22 @@ -2482,6 +2482,7 @@ static int mv643xx_eth_shared_of_add_por
23         struct resource res;
24         const char *mac_addr;
25         int ret;
26 +       int dev_num = 0;
27  
28         memset(&ppd, 0, sizeof(ppd));
29         ppd.shared = pdev;
30 @@ -2502,6 +2503,14 @@ static int mv643xx_eth_shared_of_add_por
31                 return -EINVAL;
32         }
33  
34 +       while (dev_num < 3 && port_platdev[dev_num])
35 +               dev_num++;
36 +
37 +       if (dev_num == 3) {
38 +               dev_err(&pdev->dev, "too many ports registered\n");
39 +               return -EINVAL;
40 +       }
41 +
42         mac_addr = of_get_mac_address(pnp);
43         if (mac_addr)
44                 memcpy(ppd.mac_addr, mac_addr, 6);
45 @@ -2520,7 +2529,7 @@ static int mv643xx_eth_shared_of_add_por
46                 of_property_read_u32(pnp, "duplex", &ppd.duplex);
47         }
48  
49 -       ppdev = platform_device_alloc(MV643XX_ETH_NAME, ppd.port_number);
50 +       ppdev = platform_device_alloc(MV643XX_ETH_NAME, dev_num);
51         if (!ppdev)
52                 return -ENOMEM;
53         ppdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
54 @@ -2537,7 +2546,7 @@ static int mv643xx_eth_shared_of_add_por
55         if (ret)
56                 goto port_err;
57  
58 -       port_platdev[ppd.port_number] = ppdev;
59 +       port_platdev[dev_num] = ppdev;
60  
61         return 0;
62