diff options
author | Pavel Nakonechny <pavel.nakonechny@skitlab.ru> | 2015-04-04 17:46:21 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2015-04-06 17:31:37 -0400 |
commit | 303038135afbd0520d1e241c02592be6e4ea7204 (patch) | |
tree | 32e77ff115fbc865760912b731db9cb063703a2a | |
parent | 67e04c29ec0daad9ba29341b4dab4b89526994cf (diff) |
net: dsa: fix filling routing table from OF description
According to description in 'include/net/dsa.h', in cascade switches
configurations where there are more than one interconnected devices,
'rtable' array in 'dsa_chip_data' structure is used to indicate which
port on this switch should be used to send packets to that are destined
for corresponding switch.
However, dsa_of_setup_routing_table() fills 'rtable' with port numbers
of the _target_ switch, but not current one.
This commit removes redundant devicetree parsing and adds needed port
number as a function argument. So dsa_of_setup_routing_table() now just
looks for target switch number by parsing parent of 'link' device node.
To remove possible misunderstandings with the way of determining target
switch number, a corresponding comment was added to the source code and
to the DSA device tree bindings documentation file.
This was tested on a custom board with two Marvell 88E6095 switches with
following corresponding routing tables: { -1, 10 } and { 8, -1 }.
Signed-off-by: Pavel Nakonechny <pavel.nakonechny@skitlab.ru>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | Documentation/devicetree/bindings/net/dsa/dsa.txt | 4 | ||||
-rw-r--r-- | net/dsa/dsa.c | 23 |
2 files changed, 10 insertions, 17 deletions
diff --git a/Documentation/devicetree/bindings/net/dsa/dsa.txt b/Documentation/devicetree/bindings/net/dsa/dsa.txt index e124847443f8..f0b4cd72411d 100644 --- a/Documentation/devicetree/bindings/net/dsa/dsa.txt +++ b/Documentation/devicetree/bindings/net/dsa/dsa.txt | |||
@@ -19,7 +19,9 @@ the parent DSA node. The maximum number of allowed child nodes is 4 | |||
19 | (DSA_MAX_SWITCHES). | 19 | (DSA_MAX_SWITCHES). |
20 | Each of these switch child nodes should have the following required properties: | 20 | Each of these switch child nodes should have the following required properties: |
21 | 21 | ||
22 | - reg : Describes the switch address on the MII bus | 22 | - reg : Contains two fields. The first one describes the |
23 | address on the MII bus. The second is the switch | ||
24 | number that must be unique in cascaded configurations | ||
23 | - #address-cells : Must be 1 | 25 | - #address-cells : Must be 1 |
24 | - #size-cells : Must be 0 | 26 | - #size-cells : Must be 0 |
25 | 27 | ||
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c index 2173402d87e0..4dea2e0681d1 100644 --- a/net/dsa/dsa.c +++ b/net/dsa/dsa.c | |||
@@ -501,12 +501,10 @@ static struct net_device *dev_to_net_device(struct device *dev) | |||
501 | #ifdef CONFIG_OF | 501 | #ifdef CONFIG_OF |
502 | static int dsa_of_setup_routing_table(struct dsa_platform_data *pd, | 502 | static int dsa_of_setup_routing_table(struct dsa_platform_data *pd, |
503 | struct dsa_chip_data *cd, | 503 | struct dsa_chip_data *cd, |
504 | int chip_index, | 504 | int chip_index, int port_index, |
505 | struct device_node *link) | 505 | struct device_node *link) |
506 | { | 506 | { |
507 | int ret; | ||
508 | const __be32 *reg; | 507 | const __be32 *reg; |
509 | int link_port_addr; | ||
510 | int link_sw_addr; | 508 | int link_sw_addr; |
511 | struct device_node *parent_sw; | 509 | struct device_node *parent_sw; |
512 | int len; | 510 | int len; |
@@ -519,6 +517,10 @@ static int dsa_of_setup_routing_table(struct dsa_platform_data *pd, | |||
519 | if (!reg || (len != sizeof(*reg) * 2)) | 517 | if (!reg || (len != sizeof(*reg) * 2)) |
520 | return -EINVAL; | 518 | return -EINVAL; |
521 | 519 | ||
520 | /* | ||
521 | * Get the destination switch number from the second field of its 'reg' | ||
522 | * property, i.e. for "reg = <0x19 1>" sw_addr is '1'. | ||
523 | */ | ||
522 | link_sw_addr = be32_to_cpup(reg + 1); | 524 | link_sw_addr = be32_to_cpup(reg + 1); |
523 | 525 | ||
524 | if (link_sw_addr >= pd->nr_chips) | 526 | if (link_sw_addr >= pd->nr_chips) |
@@ -535,20 +537,9 @@ static int dsa_of_setup_routing_table(struct dsa_platform_data *pd, | |||
535 | memset(cd->rtable, -1, pd->nr_chips * sizeof(s8)); | 537 | memset(cd->rtable, -1, pd->nr_chips * sizeof(s8)); |
536 | } | 538 | } |
537 | 539 | ||
538 | reg = of_get_property(link, "reg", NULL); | 540 | cd->rtable[link_sw_addr] = port_index; |
539 | if (!reg) { | ||
540 | ret = -EINVAL; | ||
541 | goto out; | ||
542 | } | ||
543 | |||
544 | link_port_addr = be32_to_cpup(reg); | ||
545 | |||
546 | cd->rtable[link_sw_addr] = link_port_addr; | ||
547 | 541 | ||
548 | return 0; | 542 | return 0; |
549 | out: | ||
550 | kfree(cd->rtable); | ||
551 | return ret; | ||
552 | } | 543 | } |
553 | 544 | ||
554 | static void dsa_of_free_platform_data(struct dsa_platform_data *pd) | 545 | static void dsa_of_free_platform_data(struct dsa_platform_data *pd) |
@@ -658,7 +649,7 @@ static int dsa_of_probe(struct platform_device *pdev) | |||
658 | if (!strcmp(port_name, "dsa") && link && | 649 | if (!strcmp(port_name, "dsa") && link && |
659 | pd->nr_chips > 1) { | 650 | pd->nr_chips > 1) { |
660 | ret = dsa_of_setup_routing_table(pd, cd, | 651 | ret = dsa_of_setup_routing_table(pd, cd, |
661 | chip_index, link); | 652 | chip_index, port_index, link); |
662 | if (ret) | 653 | if (ret) |
663 | goto out_free_chip; | 654 | goto out_free_chip; |
664 | } | 655 | } |