diff options
author | Anton Vorontsov <avorontsov@ru.mvista.com> | 2009-10-12 02:00:26 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2009-10-13 02:54:01 -0400 |
commit | ccc05c6e1e4fb672c93c98d92079c89a976e80ba (patch) | |
tree | f687178656c4d0b42f45a5b1648569c650c5617e /drivers/net/gianfar.c | |
parent | a2e2725541fad72416326798c2d7fa4dafb7d337 (diff) |
gianfar: Some cleanups for startup_gfar()
We're going to split the startup_gfar() into 3 separate functions,
so let's cleanup the code a little bit so that cosmetic changes
won't distract attention from logical ones.
- Remove needless casts (e.g. (struct sk_buff **)kmalloc());
- Turn 'unsigned long vaddr;' into 'void *vaddr', to avoid casting;
- Add new 'struct device *dev' variable as a shorthand for
'&priv->ofdev->dev' that is used all over the place, also rename
'struct net_device *dev' to 'struct net_device *ndev';
- Turn printk(KERN_ERR ...) to pr_err(...), which is shorter;
- Don't return bogus -1 (i.e. -EPERM) when request_irq() fails;
- Turn '&priv->regs->' to just '®s->'.
Signed-off-by: Anton Vorontsov <avorontsov@ru.mvista.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/gianfar.c')
-rw-r--r-- | drivers/net/gianfar.c | 143 |
1 files changed, 64 insertions, 79 deletions
diff --git a/drivers/net/gianfar.c b/drivers/net/gianfar.c index 1e5289ffef6f..5d6480c7cc95 100644 --- a/drivers/net/gianfar.c +++ b/drivers/net/gianfar.c | |||
@@ -925,16 +925,17 @@ void gfar_start(struct net_device *dev) | |||
925 | } | 925 | } |
926 | 926 | ||
927 | /* Bring the controller up and running */ | 927 | /* Bring the controller up and running */ |
928 | int startup_gfar(struct net_device *dev) | 928 | int startup_gfar(struct net_device *ndev) |
929 | { | 929 | { |
930 | struct txbd8 *txbdp; | 930 | struct txbd8 *txbdp; |
931 | struct rxbd8 *rxbdp; | 931 | struct rxbd8 *rxbdp; |
932 | dma_addr_t addr = 0; | 932 | dma_addr_t addr = 0; |
933 | unsigned long vaddr; | 933 | void *vaddr; |
934 | int i; | 934 | int i; |
935 | struct gfar_private *priv = netdev_priv(dev); | 935 | struct gfar_private *priv = netdev_priv(ndev); |
936 | struct device *dev = &priv->ofdev->dev; | ||
936 | struct gfar __iomem *regs = priv->regs; | 937 | struct gfar __iomem *regs = priv->regs; |
937 | int err = 0; | 938 | int err; |
938 | u32 rctrl = 0; | 939 | u32 rctrl = 0; |
939 | u32 tctrl = 0; | 940 | u32 tctrl = 0; |
940 | u32 attrs = 0; | 941 | u32 attrs = 0; |
@@ -942,38 +943,34 @@ int startup_gfar(struct net_device *dev) | |||
942 | gfar_write(®s->imask, IMASK_INIT_CLEAR); | 943 | gfar_write(®s->imask, IMASK_INIT_CLEAR); |
943 | 944 | ||
944 | /* Allocate memory for the buffer descriptors */ | 945 | /* Allocate memory for the buffer descriptors */ |
945 | vaddr = (unsigned long) dma_alloc_coherent(&priv->ofdev->dev, | 946 | vaddr = dma_alloc_coherent(dev, sizeof(*txbdp) * priv->tx_ring_size + |
946 | sizeof (struct txbd8) * priv->tx_ring_size + | 947 | sizeof(*rxbdp) * priv->rx_ring_size, |
947 | sizeof (struct rxbd8) * priv->rx_ring_size, | 948 | &addr, GFP_KERNEL); |
948 | &addr, GFP_KERNEL); | 949 | if (!vaddr) { |
949 | |||
950 | if (vaddr == 0) { | ||
951 | if (netif_msg_ifup(priv)) | 950 | if (netif_msg_ifup(priv)) |
952 | printk(KERN_ERR "%s: Could not allocate buffer descriptors!\n", | 951 | pr_err("%s: Could not allocate buffer descriptors!\n", |
953 | dev->name); | 952 | ndev->name); |
954 | return -ENOMEM; | 953 | return -ENOMEM; |
955 | } | 954 | } |
956 | 955 | ||
957 | priv->tx_bd_base = (struct txbd8 *) vaddr; | 956 | priv->tx_bd_base = vaddr; |
958 | 957 | ||
959 | /* enet DMA only understands physical addresses */ | 958 | /* enet DMA only understands physical addresses */ |
960 | gfar_write(®s->tbase0, addr); | 959 | gfar_write(®s->tbase0, addr); |
961 | 960 | ||
962 | /* Start the rx descriptor ring where the tx ring leaves off */ | 961 | /* Start the rx descriptor ring where the tx ring leaves off */ |
963 | addr = addr + sizeof (struct txbd8) * priv->tx_ring_size; | 962 | addr = addr + sizeof(*txbdp) * priv->tx_ring_size; |
964 | vaddr = vaddr + sizeof (struct txbd8) * priv->tx_ring_size; | 963 | vaddr = vaddr + sizeof(*txbdp) * priv->tx_ring_size; |
965 | priv->rx_bd_base = (struct rxbd8 *) vaddr; | 964 | priv->rx_bd_base = vaddr; |
966 | gfar_write(®s->rbase0, addr); | 965 | gfar_write(®s->rbase0, addr); |
967 | 966 | ||
968 | /* Setup the skbuff rings */ | 967 | /* Setup the skbuff rings */ |
969 | priv->tx_skbuff = | 968 | priv->tx_skbuff = kmalloc(sizeof(*priv->tx_skbuff) * |
970 | (struct sk_buff **) kmalloc(sizeof (struct sk_buff *) * | 969 | priv->tx_ring_size, GFP_KERNEL); |
971 | priv->tx_ring_size, GFP_KERNEL); | 970 | if (!priv->tx_skbuff) { |
972 | |||
973 | if (NULL == priv->tx_skbuff) { | ||
974 | if (netif_msg_ifup(priv)) | 971 | if (netif_msg_ifup(priv)) |
975 | printk(KERN_ERR "%s: Could not allocate tx_skbuff\n", | 972 | pr_err("%s: Could not allocate tx_skbuff\n", |
976 | dev->name); | 973 | ndev->name); |
977 | err = -ENOMEM; | 974 | err = -ENOMEM; |
978 | goto tx_skb_fail; | 975 | goto tx_skb_fail; |
979 | } | 976 | } |
@@ -981,14 +978,12 @@ int startup_gfar(struct net_device *dev) | |||
981 | for (i = 0; i < priv->tx_ring_size; i++) | 978 | for (i = 0; i < priv->tx_ring_size; i++) |
982 | priv->tx_skbuff[i] = NULL; | 979 | priv->tx_skbuff[i] = NULL; |
983 | 980 | ||
984 | priv->rx_skbuff = | 981 | priv->rx_skbuff = kmalloc(sizeof(*priv->rx_skbuff) * |
985 | (struct sk_buff **) kmalloc(sizeof (struct sk_buff *) * | 982 | priv->rx_ring_size, GFP_KERNEL); |
986 | priv->rx_ring_size, GFP_KERNEL); | 983 | if (!priv->rx_skbuff) { |
987 | |||
988 | if (NULL == priv->rx_skbuff) { | ||
989 | if (netif_msg_ifup(priv)) | 984 | if (netif_msg_ifup(priv)) |
990 | printk(KERN_ERR "%s: Could not allocate rx_skbuff\n", | 985 | pr_err("%s: Could not allocate rx_skbuff\n", |
991 | dev->name); | 986 | ndev->name); |
992 | err = -ENOMEM; | 987 | err = -ENOMEM; |
993 | goto rx_skb_fail; | 988 | goto rx_skb_fail; |
994 | } | 989 | } |
@@ -1019,18 +1014,16 @@ int startup_gfar(struct net_device *dev) | |||
1019 | for (i = 0; i < priv->rx_ring_size; i++) { | 1014 | for (i = 0; i < priv->rx_ring_size; i++) { |
1020 | struct sk_buff *skb; | 1015 | struct sk_buff *skb; |
1021 | 1016 | ||
1022 | skb = gfar_new_skb(dev); | 1017 | skb = gfar_new_skb(ndev); |
1023 | |||
1024 | if (!skb) { | 1018 | if (!skb) { |
1025 | printk(KERN_ERR "%s: Can't allocate RX buffers\n", | 1019 | pr_err("%s: Can't allocate RX buffers\n", ndev->name); |
1026 | dev->name); | 1020 | err = -ENOMEM; |
1027 | |||
1028 | goto err_rxalloc_fail; | 1021 | goto err_rxalloc_fail; |
1029 | } | 1022 | } |
1030 | 1023 | ||
1031 | priv->rx_skbuff[i] = skb; | 1024 | priv->rx_skbuff[i] = skb; |
1032 | 1025 | ||
1033 | gfar_new_rxbdp(dev, rxbdp, skb); | 1026 | gfar_new_rxbdp(ndev, rxbdp, skb); |
1034 | 1027 | ||
1035 | rxbdp++; | 1028 | rxbdp++; |
1036 | } | 1029 | } |
@@ -1044,44 +1037,39 @@ int startup_gfar(struct net_device *dev) | |||
1044 | if (priv->device_flags & FSL_GIANFAR_DEV_HAS_MULTI_INTR) { | 1037 | if (priv->device_flags & FSL_GIANFAR_DEV_HAS_MULTI_INTR) { |
1045 | /* Install our interrupt handlers for Error, | 1038 | /* Install our interrupt handlers for Error, |
1046 | * Transmit, and Receive */ | 1039 | * Transmit, and Receive */ |
1047 | if (request_irq(priv->interruptError, gfar_error, | 1040 | err = request_irq(priv->interruptError, gfar_error, 0, |
1048 | 0, priv->int_name_er, dev) < 0) { | 1041 | priv->int_name_er, ndev); |
1042 | if (err) { | ||
1049 | if (netif_msg_intr(priv)) | 1043 | if (netif_msg_intr(priv)) |
1050 | printk(KERN_ERR "%s: Can't get IRQ %d\n", | 1044 | pr_err("%s: Can't get IRQ %d\n", ndev->name, |
1051 | dev->name, priv->interruptError); | 1045 | priv->interruptError); |
1052 | |||
1053 | err = -1; | ||
1054 | goto err_irq_fail; | 1046 | goto err_irq_fail; |
1055 | } | 1047 | } |
1056 | 1048 | ||
1057 | if (request_irq(priv->interruptTransmit, gfar_transmit, | 1049 | err = request_irq(priv->interruptTransmit, gfar_transmit, 0, |
1058 | 0, priv->int_name_tx, dev) < 0) { | 1050 | priv->int_name_tx, ndev); |
1051 | if (err) { | ||
1059 | if (netif_msg_intr(priv)) | 1052 | if (netif_msg_intr(priv)) |
1060 | printk(KERN_ERR "%s: Can't get IRQ %d\n", | 1053 | pr_err("%s: Can't get IRQ %d\n", ndev->name, |
1061 | dev->name, priv->interruptTransmit); | 1054 | priv->interruptTransmit); |
1062 | |||
1063 | err = -1; | ||
1064 | |||
1065 | goto tx_irq_fail; | 1055 | goto tx_irq_fail; |
1066 | } | 1056 | } |
1067 | 1057 | ||
1068 | if (request_irq(priv->interruptReceive, gfar_receive, | 1058 | err = request_irq(priv->interruptReceive, gfar_receive, 0, |
1069 | 0, priv->int_name_rx, dev) < 0) { | 1059 | priv->int_name_rx, ndev); |
1060 | if (err) { | ||
1070 | if (netif_msg_intr(priv)) | 1061 | if (netif_msg_intr(priv)) |
1071 | printk(KERN_ERR "%s: Can't get IRQ %d (receive0)\n", | 1062 | pr_err("%s: Can't get IRQ %d (receive0)\n", |
1072 | dev->name, priv->interruptReceive); | 1063 | ndev->name, priv->interruptReceive); |
1073 | |||
1074 | err = -1; | ||
1075 | goto rx_irq_fail; | 1064 | goto rx_irq_fail; |
1076 | } | 1065 | } |
1077 | } else { | 1066 | } else { |
1078 | if (request_irq(priv->interruptTransmit, gfar_interrupt, | 1067 | err = request_irq(priv->interruptTransmit, gfar_interrupt, |
1079 | 0, priv->int_name_tx, dev) < 0) { | 1068 | 0, priv->int_name_tx, ndev); |
1069 | if (err) { | ||
1080 | if (netif_msg_intr(priv)) | 1070 | if (netif_msg_intr(priv)) |
1081 | printk(KERN_ERR "%s: Can't get IRQ %d\n", | 1071 | pr_err("%s: Can't get IRQ %d\n", ndev->name, |
1082 | dev->name, priv->interruptTransmit); | 1072 | priv->interruptTransmit); |
1083 | |||
1084 | err = -1; | ||
1085 | goto err_irq_fail; | 1073 | goto err_irq_fail; |
1086 | } | 1074 | } |
1087 | } | 1075 | } |
@@ -1103,7 +1091,7 @@ int startup_gfar(struct net_device *dev) | |||
1103 | if (priv->extended_hash) { | 1091 | if (priv->extended_hash) { |
1104 | rctrl |= RCTRL_EXTHASH; | 1092 | rctrl |= RCTRL_EXTHASH; |
1105 | 1093 | ||
1106 | gfar_clear_exact_match(dev); | 1094 | gfar_clear_exact_match(ndev); |
1107 | rctrl |= RCTRL_EMEN; | 1095 | rctrl |= RCTRL_EMEN; |
1108 | } | 1096 | } |
1109 | 1097 | ||
@@ -1119,18 +1107,18 @@ int startup_gfar(struct net_device *dev) | |||
1119 | } | 1107 | } |
1120 | 1108 | ||
1121 | /* Init rctrl based on our settings */ | 1109 | /* Init rctrl based on our settings */ |
1122 | gfar_write(&priv->regs->rctrl, rctrl); | 1110 | gfar_write(®s->rctrl, rctrl); |
1123 | 1111 | ||
1124 | if (dev->features & NETIF_F_IP_CSUM) | 1112 | if (ndev->features & NETIF_F_IP_CSUM) |
1125 | tctrl |= TCTRL_INIT_CSUM; | 1113 | tctrl |= TCTRL_INIT_CSUM; |
1126 | 1114 | ||
1127 | gfar_write(&priv->regs->tctrl, tctrl); | 1115 | gfar_write(®s->tctrl, tctrl); |
1128 | 1116 | ||
1129 | /* Set the extraction length and index */ | 1117 | /* Set the extraction length and index */ |
1130 | attrs = ATTRELI_EL(priv->rx_stash_size) | | 1118 | attrs = ATTRELI_EL(priv->rx_stash_size) | |
1131 | ATTRELI_EI(priv->rx_stash_index); | 1119 | ATTRELI_EI(priv->rx_stash_index); |
1132 | 1120 | ||
1133 | gfar_write(&priv->regs->attreli, attrs); | 1121 | gfar_write(®s->attreli, attrs); |
1134 | 1122 | ||
1135 | /* Start with defaults, and add stashing or locking | 1123 | /* Start with defaults, and add stashing or locking |
1136 | * depending on the approprate variables */ | 1124 | * depending on the approprate variables */ |
@@ -1142,32 +1130,29 @@ int startup_gfar(struct net_device *dev) | |||
1142 | if (priv->rx_stash_size != 0) | 1130 | if (priv->rx_stash_size != 0) |
1143 | attrs |= ATTR_BUFSTASH; | 1131 | attrs |= ATTR_BUFSTASH; |
1144 | 1132 | ||
1145 | gfar_write(&priv->regs->attr, attrs); | 1133 | gfar_write(®s->attr, attrs); |
1146 | 1134 | ||
1147 | gfar_write(&priv->regs->fifo_tx_thr, priv->fifo_threshold); | 1135 | gfar_write(®s->fifo_tx_thr, priv->fifo_threshold); |
1148 | gfar_write(&priv->regs->fifo_tx_starve, priv->fifo_starve); | 1136 | gfar_write(®s->fifo_tx_starve, priv->fifo_starve); |
1149 | gfar_write(&priv->regs->fifo_tx_starve_shutoff, priv->fifo_starve_off); | 1137 | gfar_write(®s->fifo_tx_starve_shutoff, priv->fifo_starve_off); |
1150 | 1138 | ||
1151 | /* Start the controller */ | 1139 | /* Start the controller */ |
1152 | gfar_start(dev); | 1140 | gfar_start(ndev); |
1153 | 1141 | ||
1154 | return 0; | 1142 | return 0; |
1155 | 1143 | ||
1156 | rx_irq_fail: | 1144 | rx_irq_fail: |
1157 | free_irq(priv->interruptTransmit, dev); | 1145 | free_irq(priv->interruptTransmit, ndev); |
1158 | tx_irq_fail: | 1146 | tx_irq_fail: |
1159 | free_irq(priv->interruptError, dev); | 1147 | free_irq(priv->interruptError, ndev); |
1160 | err_irq_fail: | 1148 | err_irq_fail: |
1161 | err_rxalloc_fail: | 1149 | err_rxalloc_fail: |
1162 | rx_skb_fail: | 1150 | rx_skb_fail: |
1163 | free_skb_resources(priv); | 1151 | free_skb_resources(priv); |
1164 | tx_skb_fail: | 1152 | tx_skb_fail: |
1165 | dma_free_coherent(&priv->ofdev->dev, | 1153 | dma_free_coherent(dev, sizeof(*txbdp) * priv->tx_ring_size + |
1166 | sizeof(struct txbd8)*priv->tx_ring_size | 1154 | sizeof(*rxbdp) * priv->rx_ring_size, |
1167 | + sizeof(struct rxbd8)*priv->rx_ring_size, | 1155 | priv->tx_bd_base, gfar_read(®s->tbase0)); |
1168 | priv->tx_bd_base, | ||
1169 | gfar_read(®s->tbase0)); | ||
1170 | |||
1171 | return err; | 1156 | return err; |
1172 | } | 1157 | } |
1173 | 1158 | ||