diff options
author | Jingchang Lu <jingchang.lu@freescale.com> | 2015-03-13 04:52:32 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2015-03-15 19:56:47 -0400 |
commit | 559176415cc663fff9dd99a3862629a4fcdb36ab (patch) | |
tree | 4cb91e90fa4980a4e2853e5cb113402c96380f52 /drivers/net/ethernet/freescale | |
parent | 26eb9374f83d129f26a417fc3cc9b480fb47e5e4 (diff) |
gianfar: Consider dts property endianess on handling
Use of_property_read*() to get arch endian consistent
property values. Do some refactoring in the process.
Signed-off-by: Jingchang Lu <jingchang.lu@freescale.com>
Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/ethernet/freescale')
-rw-r--r-- | drivers/net/ethernet/freescale/gianfar.c | 77 |
1 files changed, 47 insertions, 30 deletions
diff --git a/drivers/net/ethernet/freescale/gianfar.c b/drivers/net/ethernet/freescale/gianfar.c index 5d6883dd01ef..70fa6887f940 100644 --- a/drivers/net/ethernet/freescale/gianfar.c +++ b/drivers/net/ethernet/freescale/gianfar.c | |||
@@ -697,19 +697,28 @@ static int gfar_parse_group(struct device_node *np, | |||
697 | grp->priv = priv; | 697 | grp->priv = priv; |
698 | spin_lock_init(&grp->grplock); | 698 | spin_lock_init(&grp->grplock); |
699 | if (priv->mode == MQ_MG_MODE) { | 699 | if (priv->mode == MQ_MG_MODE) { |
700 | u32 *rxq_mask, *txq_mask; | 700 | u32 rxq_mask, txq_mask; |
701 | rxq_mask = (u32 *)of_get_property(np, "fsl,rx-bit-map", NULL); | 701 | int ret; |
702 | txq_mask = (u32 *)of_get_property(np, "fsl,tx-bit-map", NULL); | 702 | |
703 | grp->rx_bit_map = (DEFAULT_MAPPING >> priv->num_grps); | ||
704 | grp->tx_bit_map = (DEFAULT_MAPPING >> priv->num_grps); | ||
705 | |||
706 | ret = of_property_read_u32(np, "fsl,rx-bit-map", &rxq_mask); | ||
707 | if (!ret) { | ||
708 | grp->rx_bit_map = rxq_mask ? | ||
709 | rxq_mask : (DEFAULT_MAPPING >> priv->num_grps); | ||
710 | } | ||
711 | |||
712 | ret = of_property_read_u32(np, "fsl,tx-bit-map", &txq_mask); | ||
713 | if (!ret) { | ||
714 | grp->tx_bit_map = txq_mask ? | ||
715 | txq_mask : (DEFAULT_MAPPING >> priv->num_grps); | ||
716 | } | ||
703 | 717 | ||
704 | if (priv->poll_mode == GFAR_SQ_POLLING) { | 718 | if (priv->poll_mode == GFAR_SQ_POLLING) { |
705 | /* One Q per interrupt group: Q0 to G0, Q1 to G1 */ | 719 | /* One Q per interrupt group: Q0 to G0, Q1 to G1 */ |
706 | grp->rx_bit_map = (DEFAULT_MAPPING >> priv->num_grps); | 720 | grp->rx_bit_map = (DEFAULT_MAPPING >> priv->num_grps); |
707 | grp->tx_bit_map = (DEFAULT_MAPPING >> priv->num_grps); | 721 | grp->tx_bit_map = (DEFAULT_MAPPING >> priv->num_grps); |
708 | } else { /* GFAR_MQ_POLLING */ | ||
709 | grp->rx_bit_map = rxq_mask ? | ||
710 | *rxq_mask : (DEFAULT_MAPPING >> priv->num_grps); | ||
711 | grp->tx_bit_map = txq_mask ? | ||
712 | *txq_mask : (DEFAULT_MAPPING >> priv->num_grps); | ||
713 | } | 722 | } |
714 | } else { | 723 | } else { |
715 | grp->rx_bit_map = 0xFF; | 724 | grp->rx_bit_map = 0xFF; |
@@ -770,11 +779,10 @@ static int gfar_of_init(struct platform_device *ofdev, struct net_device **pdev) | |||
770 | struct gfar_private *priv = NULL; | 779 | struct gfar_private *priv = NULL; |
771 | struct device_node *np = ofdev->dev.of_node; | 780 | struct device_node *np = ofdev->dev.of_node; |
772 | struct device_node *child = NULL; | 781 | struct device_node *child = NULL; |
773 | const u32 *stash; | 782 | struct property *stash; |
774 | const u32 *stash_len; | 783 | u32 stash_len = 0; |
775 | const u32 *stash_idx; | 784 | u32 stash_idx = 0; |
776 | unsigned int num_tx_qs, num_rx_qs; | 785 | unsigned int num_tx_qs, num_rx_qs; |
777 | u32 *tx_queues, *rx_queues; | ||
778 | unsigned short mode, poll_mode; | 786 | unsigned short mode, poll_mode; |
779 | 787 | ||
780 | if (!np) | 788 | if (!np) |
@@ -788,10 +796,6 @@ static int gfar_of_init(struct platform_device *ofdev, struct net_device **pdev) | |||
788 | poll_mode = GFAR_SQ_POLLING; | 796 | poll_mode = GFAR_SQ_POLLING; |
789 | } | 797 | } |
790 | 798 | ||
791 | /* parse the num of HW tx and rx queues */ | ||
792 | tx_queues = (u32 *)of_get_property(np, "fsl,num_tx_queues", NULL); | ||
793 | rx_queues = (u32 *)of_get_property(np, "fsl,num_rx_queues", NULL); | ||
794 | |||
795 | if (mode == SQ_SG_MODE) { | 799 | if (mode == SQ_SG_MODE) { |
796 | num_tx_qs = 1; | 800 | num_tx_qs = 1; |
797 | num_rx_qs = 1; | 801 | num_rx_qs = 1; |
@@ -810,8 +814,17 @@ static int gfar_of_init(struct platform_device *ofdev, struct net_device **pdev) | |||
810 | num_tx_qs = num_grps; /* one txq per int group */ | 814 | num_tx_qs = num_grps; /* one txq per int group */ |
811 | num_rx_qs = num_grps; /* one rxq per int group */ | 815 | num_rx_qs = num_grps; /* one rxq per int group */ |
812 | } else { /* GFAR_MQ_POLLING */ | 816 | } else { /* GFAR_MQ_POLLING */ |
813 | num_tx_qs = tx_queues ? *tx_queues : 1; | 817 | u32 tx_queues, rx_queues; |
814 | num_rx_qs = rx_queues ? *rx_queues : 1; | 818 | int ret; |
819 | |||
820 | /* parse the num of HW tx and rx queues */ | ||
821 | ret = of_property_read_u32(np, "fsl,num_tx_queues", | ||
822 | &tx_queues); | ||
823 | num_tx_qs = ret ? 1 : tx_queues; | ||
824 | |||
825 | ret = of_property_read_u32(np, "fsl,num_rx_queues", | ||
826 | &rx_queues); | ||
827 | num_rx_qs = ret ? 1 : rx_queues; | ||
815 | } | 828 | } |
816 | } | 829 | } |
817 | 830 | ||
@@ -852,13 +865,17 @@ static int gfar_of_init(struct platform_device *ofdev, struct net_device **pdev) | |||
852 | if (err) | 865 | if (err) |
853 | goto rx_alloc_failed; | 866 | goto rx_alloc_failed; |
854 | 867 | ||
868 | err = of_property_read_string(np, "model", &model); | ||
869 | if (err) { | ||
870 | pr_err("Device model property missing, aborting\n"); | ||
871 | goto rx_alloc_failed; | ||
872 | } | ||
873 | |||
855 | /* Init Rx queue filer rule set linked list */ | 874 | /* Init Rx queue filer rule set linked list */ |
856 | INIT_LIST_HEAD(&priv->rx_list.list); | 875 | INIT_LIST_HEAD(&priv->rx_list.list); |
857 | priv->rx_list.count = 0; | 876 | priv->rx_list.count = 0; |
858 | mutex_init(&priv->rx_queue_access); | 877 | mutex_init(&priv->rx_queue_access); |
859 | 878 | ||
860 | model = of_get_property(np, "model", NULL); | ||
861 | |||
862 | for (i = 0; i < MAXGROUPS; i++) | 879 | for (i = 0; i < MAXGROUPS; i++) |
863 | priv->gfargrp[i].regs = NULL; | 880 | priv->gfargrp[i].regs = NULL; |
864 | 881 | ||
@@ -878,22 +895,22 @@ static int gfar_of_init(struct platform_device *ofdev, struct net_device **pdev) | |||
878 | goto err_grp_init; | 895 | goto err_grp_init; |
879 | } | 896 | } |
880 | 897 | ||
881 | stash = of_get_property(np, "bd-stash", NULL); | 898 | stash = of_find_property(np, "bd-stash", NULL); |
882 | 899 | ||
883 | if (stash) { | 900 | if (stash) { |
884 | priv->device_flags |= FSL_GIANFAR_DEV_HAS_BD_STASHING; | 901 | priv->device_flags |= FSL_GIANFAR_DEV_HAS_BD_STASHING; |
885 | priv->bd_stash_en = 1; | 902 | priv->bd_stash_en = 1; |
886 | } | 903 | } |
887 | 904 | ||
888 | stash_len = of_get_property(np, "rx-stash-len", NULL); | 905 | err = of_property_read_u32(np, "rx-stash-len", &stash_len); |
889 | 906 | ||
890 | if (stash_len) | 907 | if (err == 0) |
891 | priv->rx_stash_size = *stash_len; | 908 | priv->rx_stash_size = stash_len; |
892 | 909 | ||
893 | stash_idx = of_get_property(np, "rx-stash-idx", NULL); | 910 | err = of_property_read_u32(np, "rx-stash-idx", &stash_idx); |
894 | 911 | ||
895 | if (stash_idx) | 912 | if (err == 0) |
896 | priv->rx_stash_index = *stash_idx; | 913 | priv->rx_stash_index = stash_idx; |
897 | 914 | ||
898 | if (stash_len || stash_idx) | 915 | if (stash_len || stash_idx) |
899 | priv->device_flags |= FSL_GIANFAR_DEV_HAS_BUF_STASHING; | 916 | priv->device_flags |= FSL_GIANFAR_DEV_HAS_BUF_STASHING; |
@@ -920,15 +937,15 @@ static int gfar_of_init(struct platform_device *ofdev, struct net_device **pdev) | |||
920 | FSL_GIANFAR_DEV_HAS_EXTENDED_HASH | | 937 | FSL_GIANFAR_DEV_HAS_EXTENDED_HASH | |
921 | FSL_GIANFAR_DEV_HAS_TIMER; | 938 | FSL_GIANFAR_DEV_HAS_TIMER; |
922 | 939 | ||
923 | ctype = of_get_property(np, "phy-connection-type", NULL); | 940 | err = of_property_read_string(np, "phy-connection-type", &ctype); |
924 | 941 | ||
925 | /* We only care about rgmii-id. The rest are autodetected */ | 942 | /* We only care about rgmii-id. The rest are autodetected */ |
926 | if (ctype && !strcmp(ctype, "rgmii-id")) | 943 | if (err == 0 && !strcmp(ctype, "rgmii-id")) |
927 | priv->interface = PHY_INTERFACE_MODE_RGMII_ID; | 944 | priv->interface = PHY_INTERFACE_MODE_RGMII_ID; |
928 | else | 945 | else |
929 | priv->interface = PHY_INTERFACE_MODE_MII; | 946 | priv->interface = PHY_INTERFACE_MODE_MII; |
930 | 947 | ||
931 | if (of_get_property(np, "fsl,magic-packet", NULL)) | 948 | if (of_find_property(np, "fsl,magic-packet", NULL)) |
932 | priv->device_flags |= FSL_GIANFAR_DEV_HAS_MAGIC_PACKET; | 949 | priv->device_flags |= FSL_GIANFAR_DEV_HAS_MAGIC_PACKET; |
933 | 950 | ||
934 | priv->phy_node = of_parse_phandle(np, "phy-handle", 0); | 951 | priv->phy_node = of_parse_phandle(np, "phy-handle", 0); |