kirkwood: add linux 3.10 support
[openwrt.git] / target / linux / kirkwood / patches-3.10 / 0027-net-mv643xx_eth-do-not-use-port-number-as-platform-d.patch
1 From eac92acae29cfab34785d61cbb3218e88e487b77 Mon Sep 17 00:00:00 2001
2 From: Jonas Gorski <jogo@openwrt.org>
3 Date: Mon, 8 Jul 2013 00:35:12 +0200
4 Subject: [PATCH 27/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 ---
16  drivers/net/ethernet/marvell/mv643xx_eth.c | 13 +++++++++++--
17  1 file changed, 11 insertions(+), 2 deletions(-)
18
19 diff --git a/drivers/net/ethernet/marvell/mv643xx_eth.c b/drivers/net/ethernet/marvell/mv643xx_eth.c
20 index 004a250..e57d292 100644
21 --- a/drivers/net/ethernet/marvell/mv643xx_eth.c
22 +++ b/drivers/net/ethernet/marvell/mv643xx_eth.c
23 @@ -2483,6 +2483,7 @@ static int mv643xx_eth_shared_of_add_port(struct platform_device *pdev,
24         struct resource res;
25         const char *mac_addr;
26         int ret;
27 +       int dev_num = 0;
28  
29         memset(&ppd, 0, sizeof(ppd));
30         ppd.shared = pdev;
31 @@ -2503,6 +2504,14 @@ static int mv643xx_eth_shared_of_add_port(struct platform_device *pdev,
32                 return -EINVAL;
33         }
34  
35 +       while (dev_num < 3 && port_platdev[dev_num])
36 +               dev_num++;
37 +
38 +       if (dev_num == 3) {
39 +               dev_err(&pdev->dev, "too many ports registered\n");
40 +               return -EINVAL;
41 +       }
42 +
43         mac_addr = of_get_mac_address(pnp);
44         if (mac_addr)
45                 memcpy(ppd.mac_addr, mac_addr, 6);
46 @@ -2521,7 +2530,7 @@ static int mv643xx_eth_shared_of_add_port(struct platform_device *pdev,
47                 of_property_read_u32(pnp, "duplex", &ppd.duplex);
48         }
49  
50 -       ppdev = platform_device_alloc(MV643XX_ETH_NAME, ppd.port_number);
51 +       ppdev = platform_device_alloc(MV643XX_ETH_NAME, dev_num);
52         if (!ppdev)
53                 return -ENOMEM;
54         ppdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
55 @@ -2538,7 +2547,7 @@ static int mv643xx_eth_shared_of_add_port(struct platform_device *pdev,
56         if (ret)
57                 goto port_err;
58  
59 -       port_platdev[ppd.port_number] = ppdev;
60 +       port_platdev[dev_num] = ppdev;
61  
62         return 0;
63  
64 -- 
65 1.8.4.rc1
66