Skip to content

Commit 5591764

Browse files
Jingchang Ludavem330
authored andcommitted
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 <[email protected]> Signed-off-by: Claudiu Manoil <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 26eb937 commit 5591764

File tree

1 file changed

+47
-30
lines changed

1 file changed

+47
-30
lines changed

drivers/net/ethernet/freescale/gianfar.c

Lines changed: 47 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -697,19 +697,28 @@ static int gfar_parse_group(struct device_node *np,
697697
grp->priv = priv;
698698
spin_lock_init(&grp->grplock);
699699
if (priv->mode == MQ_MG_MODE) {
700-
u32 *rxq_mask, *txq_mask;
701-
rxq_mask = (u32 *)of_get_property(np, "fsl,rx-bit-map", NULL);
702-
txq_mask = (u32 *)of_get_property(np, "fsl,tx-bit-map", NULL);
700+
u32 rxq_mask, txq_mask;
701+
int ret;
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+
}
703717

704718
if (priv->poll_mode == GFAR_SQ_POLLING) {
705719
/* One Q per interrupt group: Q0 to G0, Q1 to G1 */
706720
grp->rx_bit_map = (DEFAULT_MAPPING >> priv->num_grps);
707721
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);
713722
}
714723
} else {
715724
grp->rx_bit_map = 0xFF;
@@ -770,11 +779,10 @@ static int gfar_of_init(struct platform_device *ofdev, struct net_device **pdev)
770779
struct gfar_private *priv = NULL;
771780
struct device_node *np = ofdev->dev.of_node;
772781
struct device_node *child = NULL;
773-
const u32 *stash;
774-
const u32 *stash_len;
775-
const u32 *stash_idx;
782+
struct property *stash;
783+
u32 stash_len = 0;
784+
u32 stash_idx = 0;
776785
unsigned int num_tx_qs, num_rx_qs;
777-
u32 *tx_queues, *rx_queues;
778786
unsigned short mode, poll_mode;
779787

780788
if (!np)
@@ -788,10 +796,6 @@ static int gfar_of_init(struct platform_device *ofdev, struct net_device **pdev)
788796
poll_mode = GFAR_SQ_POLLING;
789797
}
790798

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-
795799
if (mode == SQ_SG_MODE) {
796800
num_tx_qs = 1;
797801
num_rx_qs = 1;
@@ -810,8 +814,17 @@ static int gfar_of_init(struct platform_device *ofdev, struct net_device **pdev)
810814
num_tx_qs = num_grps; /* one txq per int group */
811815
num_rx_qs = num_grps; /* one rxq per int group */
812816
} else { /* GFAR_MQ_POLLING */
813-
num_tx_qs = tx_queues ? *tx_queues : 1;
814-
num_rx_qs = rx_queues ? *rx_queues : 1;
817+
u32 tx_queues, rx_queues;
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;
815828
}
816829
}
817830

@@ -852,13 +865,17 @@ static int gfar_of_init(struct platform_device *ofdev, struct net_device **pdev)
852865
if (err)
853866
goto rx_alloc_failed;
854867

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+
855874
/* Init Rx queue filer rule set linked list */
856875
INIT_LIST_HEAD(&priv->rx_list.list);
857876
priv->rx_list.count = 0;
858877
mutex_init(&priv->rx_queue_access);
859878

860-
model = of_get_property(np, "model", NULL);
861-
862879
for (i = 0; i < MAXGROUPS; i++)
863880
priv->gfargrp[i].regs = NULL;
864881

@@ -878,22 +895,22 @@ static int gfar_of_init(struct platform_device *ofdev, struct net_device **pdev)
878895
goto err_grp_init;
879896
}
880897

881-
stash = of_get_property(np, "bd-stash", NULL);
898+
stash = of_find_property(np, "bd-stash", NULL);
882899

883900
if (stash) {
884901
priv->device_flags |= FSL_GIANFAR_DEV_HAS_BD_STASHING;
885902
priv->bd_stash_en = 1;
886903
}
887904

888-
stash_len = of_get_property(np, "rx-stash-len", NULL);
905+
err = of_property_read_u32(np, "rx-stash-len", &stash_len);
889906

890-
if (stash_len)
891-
priv->rx_stash_size = *stash_len;
907+
if (err == 0)
908+
priv->rx_stash_size = stash_len;
892909

893-
stash_idx = of_get_property(np, "rx-stash-idx", NULL);
910+
err = of_property_read_u32(np, "rx-stash-idx", &stash_idx);
894911

895-
if (stash_idx)
896-
priv->rx_stash_index = *stash_idx;
912+
if (err == 0)
913+
priv->rx_stash_index = stash_idx;
897914

898915
if (stash_len || stash_idx)
899916
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)
920937
FSL_GIANFAR_DEV_HAS_EXTENDED_HASH |
921938
FSL_GIANFAR_DEV_HAS_TIMER;
922939

923-
ctype = of_get_property(np, "phy-connection-type", NULL);
940+
err = of_property_read_string(np, "phy-connection-type", &ctype);
924941

925942
/* 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"))
927944
priv->interface = PHY_INTERFACE_MODE_RGMII_ID;
928945
else
929946
priv->interface = PHY_INTERFACE_MODE_MII;
930947

931-
if (of_get_property(np, "fsl,magic-packet", NULL))
948+
if (of_find_property(np, "fsl,magic-packet", NULL))
932949
priv->device_flags |= FSL_GIANFAR_DEV_HAS_MAGIC_PACKET;
933950

934951
priv->phy_node = of_parse_phandle(np, "phy-handle", 0);

0 commit comments

Comments
 (0)