diff options
author | Linus Walleij <linus.walleij@linaro.org> | 2014-03-14 05:26:45 -0400 |
---|---|---|
committer | Linus Walleij <linus.walleij@linaro.org> | 2014-03-14 05:26:45 -0400 |
commit | 9e294427f6e427dbaf46140303acded06365f53c (patch) | |
tree | 0669100cbd79fe8612463900171c98873d8dc454 /drivers/net/ethernet/ethoc.c | |
parent | 23600969ff137cf4c3bc9098f77e381de334e3f7 (diff) | |
parent | fa389e220254c69ffae0d403eac4146171062d08 (diff) |
Merge tag 'v3.14-rc6' into devel
Linux 3.14-rc6
Diffstat (limited to 'drivers/net/ethernet/ethoc.c')
-rw-r--r-- | drivers/net/ethernet/ethoc.c | 138 |
1 files changed, 136 insertions, 2 deletions
diff --git a/drivers/net/ethernet/ethoc.c b/drivers/net/ethernet/ethoc.c index 4de8cfd149cf..55e0fa03dc90 100644 --- a/drivers/net/ethernet/ethoc.c +++ b/drivers/net/ethernet/ethoc.c | |||
@@ -13,6 +13,7 @@ | |||
13 | 13 | ||
14 | #include <linux/dma-mapping.h> | 14 | #include <linux/dma-mapping.h> |
15 | #include <linux/etherdevice.h> | 15 | #include <linux/etherdevice.h> |
16 | #include <linux/clk.h> | ||
16 | #include <linux/crc32.h> | 17 | #include <linux/crc32.h> |
17 | #include <linux/interrupt.h> | 18 | #include <linux/interrupt.h> |
18 | #include <linux/io.h> | 19 | #include <linux/io.h> |
@@ -51,6 +52,7 @@ MODULE_PARM_DESC(buffer_size, "DMA buffer allocation size"); | |||
51 | #define ETH_HASH0 0x48 | 52 | #define ETH_HASH0 0x48 |
52 | #define ETH_HASH1 0x4c | 53 | #define ETH_HASH1 0x4c |
53 | #define ETH_TXCTRL 0x50 | 54 | #define ETH_TXCTRL 0x50 |
55 | #define ETH_END 0x54 | ||
54 | 56 | ||
55 | /* mode register */ | 57 | /* mode register */ |
56 | #define MODER_RXEN (1 << 0) /* receive enable */ | 58 | #define MODER_RXEN (1 << 0) /* receive enable */ |
@@ -179,6 +181,7 @@ MODULE_PARM_DESC(buffer_size, "DMA buffer allocation size"); | |||
179 | * @membase: pointer to buffer memory region | 181 | * @membase: pointer to buffer memory region |
180 | * @dma_alloc: dma allocated buffer size | 182 | * @dma_alloc: dma allocated buffer size |
181 | * @io_region_size: I/O memory region size | 183 | * @io_region_size: I/O memory region size |
184 | * @num_bd: number of buffer descriptors | ||
182 | * @num_tx: number of send buffers | 185 | * @num_tx: number of send buffers |
183 | * @cur_tx: last send buffer written | 186 | * @cur_tx: last send buffer written |
184 | * @dty_tx: last buffer actually sent | 187 | * @dty_tx: last buffer actually sent |
@@ -199,6 +202,7 @@ struct ethoc { | |||
199 | int dma_alloc; | 202 | int dma_alloc; |
200 | resource_size_t io_region_size; | 203 | resource_size_t io_region_size; |
201 | 204 | ||
205 | unsigned int num_bd; | ||
202 | unsigned int num_tx; | 206 | unsigned int num_tx; |
203 | unsigned int cur_tx; | 207 | unsigned int cur_tx; |
204 | unsigned int dty_tx; | 208 | unsigned int dty_tx; |
@@ -216,6 +220,7 @@ struct ethoc { | |||
216 | 220 | ||
217 | struct phy_device *phy; | 221 | struct phy_device *phy; |
218 | struct mii_bus *mdio; | 222 | struct mii_bus *mdio; |
223 | struct clk *clk; | ||
219 | s8 phy_id; | 224 | s8 phy_id; |
220 | }; | 225 | }; |
221 | 226 | ||
@@ -688,6 +693,11 @@ static int ethoc_mdio_probe(struct net_device *dev) | |||
688 | } | 693 | } |
689 | 694 | ||
690 | priv->phy = phy; | 695 | priv->phy = phy; |
696 | phy->advertising &= ~(ADVERTISED_1000baseT_Full | | ||
697 | ADVERTISED_1000baseT_Half); | ||
698 | phy->supported &= ~(SUPPORTED_1000baseT_Full | | ||
699 | SUPPORTED_1000baseT_Half); | ||
700 | |||
691 | return 0; | 701 | return 0; |
692 | } | 702 | } |
693 | 703 | ||
@@ -890,6 +900,102 @@ out: | |||
890 | return NETDEV_TX_OK; | 900 | return NETDEV_TX_OK; |
891 | } | 901 | } |
892 | 902 | ||
903 | static int ethoc_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) | ||
904 | { | ||
905 | struct ethoc *priv = netdev_priv(dev); | ||
906 | struct phy_device *phydev = priv->phy; | ||
907 | |||
908 | if (!phydev) | ||
909 | return -EOPNOTSUPP; | ||
910 | |||
911 | return phy_ethtool_gset(phydev, cmd); | ||
912 | } | ||
913 | |||
914 | static int ethoc_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) | ||
915 | { | ||
916 | struct ethoc *priv = netdev_priv(dev); | ||
917 | struct phy_device *phydev = priv->phy; | ||
918 | |||
919 | if (!phydev) | ||
920 | return -EOPNOTSUPP; | ||
921 | |||
922 | return phy_ethtool_sset(phydev, cmd); | ||
923 | } | ||
924 | |||
925 | static int ethoc_get_regs_len(struct net_device *netdev) | ||
926 | { | ||
927 | return ETH_END; | ||
928 | } | ||
929 | |||
930 | static void ethoc_get_regs(struct net_device *dev, struct ethtool_regs *regs, | ||
931 | void *p) | ||
932 | { | ||
933 | struct ethoc *priv = netdev_priv(dev); | ||
934 | u32 *regs_buff = p; | ||
935 | unsigned i; | ||
936 | |||
937 | regs->version = 0; | ||
938 | for (i = 0; i < ETH_END / sizeof(u32); ++i) | ||
939 | regs_buff[i] = ethoc_read(priv, i * sizeof(u32)); | ||
940 | } | ||
941 | |||
942 | static void ethoc_get_ringparam(struct net_device *dev, | ||
943 | struct ethtool_ringparam *ring) | ||
944 | { | ||
945 | struct ethoc *priv = netdev_priv(dev); | ||
946 | |||
947 | ring->rx_max_pending = priv->num_bd - 1; | ||
948 | ring->rx_mini_max_pending = 0; | ||
949 | ring->rx_jumbo_max_pending = 0; | ||
950 | ring->tx_max_pending = priv->num_bd - 1; | ||
951 | |||
952 | ring->rx_pending = priv->num_rx; | ||
953 | ring->rx_mini_pending = 0; | ||
954 | ring->rx_jumbo_pending = 0; | ||
955 | ring->tx_pending = priv->num_tx; | ||
956 | } | ||
957 | |||
958 | static int ethoc_set_ringparam(struct net_device *dev, | ||
959 | struct ethtool_ringparam *ring) | ||
960 | { | ||
961 | struct ethoc *priv = netdev_priv(dev); | ||
962 | |||
963 | if (ring->tx_pending < 1 || ring->rx_pending < 1 || | ||
964 | ring->tx_pending + ring->rx_pending > priv->num_bd) | ||
965 | return -EINVAL; | ||
966 | if (ring->rx_mini_pending || ring->rx_jumbo_pending) | ||
967 | return -EINVAL; | ||
968 | |||
969 | if (netif_running(dev)) { | ||
970 | netif_tx_disable(dev); | ||
971 | ethoc_disable_rx_and_tx(priv); | ||
972 | ethoc_disable_irq(priv, INT_MASK_TX | INT_MASK_RX); | ||
973 | synchronize_irq(dev->irq); | ||
974 | } | ||
975 | |||
976 | priv->num_tx = rounddown_pow_of_two(ring->tx_pending); | ||
977 | priv->num_rx = ring->rx_pending; | ||
978 | ethoc_init_ring(priv, dev->mem_start); | ||
979 | |||
980 | if (netif_running(dev)) { | ||
981 | ethoc_enable_irq(priv, INT_MASK_TX | INT_MASK_RX); | ||
982 | ethoc_enable_rx_and_tx(priv); | ||
983 | netif_wake_queue(dev); | ||
984 | } | ||
985 | return 0; | ||
986 | } | ||
987 | |||
988 | const struct ethtool_ops ethoc_ethtool_ops = { | ||
989 | .get_settings = ethoc_get_settings, | ||
990 | .set_settings = ethoc_set_settings, | ||
991 | .get_regs_len = ethoc_get_regs_len, | ||
992 | .get_regs = ethoc_get_regs, | ||
993 | .get_link = ethtool_op_get_link, | ||
994 | .get_ringparam = ethoc_get_ringparam, | ||
995 | .set_ringparam = ethoc_set_ringparam, | ||
996 | .get_ts_info = ethtool_op_get_ts_info, | ||
997 | }; | ||
998 | |||
893 | static const struct net_device_ops ethoc_netdev_ops = { | 999 | static const struct net_device_ops ethoc_netdev_ops = { |
894 | .ndo_open = ethoc_open, | 1000 | .ndo_open = ethoc_open, |
895 | .ndo_stop = ethoc_stop, | 1001 | .ndo_stop = ethoc_stop, |
@@ -917,6 +1023,8 @@ static int ethoc_probe(struct platform_device *pdev) | |||
917 | int num_bd; | 1023 | int num_bd; |
918 | int ret = 0; | 1024 | int ret = 0; |
919 | bool random_mac = false; | 1025 | bool random_mac = false; |
1026 | struct ethoc_platform_data *pdata = dev_get_platdata(&pdev->dev); | ||
1027 | u32 eth_clkfreq = pdata ? pdata->eth_clkfreq : 0; | ||
920 | 1028 | ||
921 | /* allocate networking device */ | 1029 | /* allocate networking device */ |
922 | netdev = alloc_etherdev(sizeof(struct ethoc)); | 1030 | netdev = alloc_etherdev(sizeof(struct ethoc)); |
@@ -1016,6 +1124,7 @@ static int ethoc_probe(struct platform_device *pdev) | |||
1016 | ret = -ENODEV; | 1124 | ret = -ENODEV; |
1017 | goto error; | 1125 | goto error; |
1018 | } | 1126 | } |
1127 | priv->num_bd = num_bd; | ||
1019 | /* num_tx must be a power of two */ | 1128 | /* num_tx must be a power of two */ |
1020 | priv->num_tx = rounddown_pow_of_two(num_bd >> 1); | 1129 | priv->num_tx = rounddown_pow_of_two(num_bd >> 1); |
1021 | priv->num_rx = num_bd - priv->num_tx; | 1130 | priv->num_rx = num_bd - priv->num_tx; |
@@ -1030,8 +1139,7 @@ static int ethoc_probe(struct platform_device *pdev) | |||
1030 | } | 1139 | } |
1031 | 1140 | ||
1032 | /* Allow the platform setup code to pass in a MAC address. */ | 1141 | /* Allow the platform setup code to pass in a MAC address. */ |
1033 | if (dev_get_platdata(&pdev->dev)) { | 1142 | if (pdata) { |
1034 | struct ethoc_platform_data *pdata = dev_get_platdata(&pdev->dev); | ||
1035 | memcpy(netdev->dev_addr, pdata->hwaddr, IFHWADDRLEN); | 1143 | memcpy(netdev->dev_addr, pdata->hwaddr, IFHWADDRLEN); |
1036 | priv->phy_id = pdata->phy_id; | 1144 | priv->phy_id = pdata->phy_id; |
1037 | } else { | 1145 | } else { |
@@ -1069,6 +1177,27 @@ static int ethoc_probe(struct platform_device *pdev) | |||
1069 | if (random_mac) | 1177 | if (random_mac) |
1070 | netdev->addr_assign_type = NET_ADDR_RANDOM; | 1178 | netdev->addr_assign_type = NET_ADDR_RANDOM; |
1071 | 1179 | ||
1180 | /* Allow the platform setup code to adjust MII management bus clock. */ | ||
1181 | if (!eth_clkfreq) { | ||
1182 | struct clk *clk = devm_clk_get(&pdev->dev, NULL); | ||
1183 | |||
1184 | if (!IS_ERR(clk)) { | ||
1185 | priv->clk = clk; | ||
1186 | clk_prepare_enable(clk); | ||
1187 | eth_clkfreq = clk_get_rate(clk); | ||
1188 | } | ||
1189 | } | ||
1190 | if (eth_clkfreq) { | ||
1191 | u32 clkdiv = MIIMODER_CLKDIV(eth_clkfreq / 2500000 + 1); | ||
1192 | |||
1193 | if (!clkdiv) | ||
1194 | clkdiv = 2; | ||
1195 | dev_dbg(&pdev->dev, "setting MII clkdiv to %u\n", clkdiv); | ||
1196 | ethoc_write(priv, MIIMODER, | ||
1197 | (ethoc_read(priv, MIIMODER) & MIIMODER_NOPRE) | | ||
1198 | clkdiv); | ||
1199 | } | ||
1200 | |||
1072 | /* register MII bus */ | 1201 | /* register MII bus */ |
1073 | priv->mdio = mdiobus_alloc(); | 1202 | priv->mdio = mdiobus_alloc(); |
1074 | if (!priv->mdio) { | 1203 | if (!priv->mdio) { |
@@ -1111,6 +1240,7 @@ static int ethoc_probe(struct platform_device *pdev) | |||
1111 | netdev->netdev_ops = ðoc_netdev_ops; | 1240 | netdev->netdev_ops = ðoc_netdev_ops; |
1112 | netdev->watchdog_timeo = ETHOC_TIMEOUT; | 1241 | netdev->watchdog_timeo = ETHOC_TIMEOUT; |
1113 | netdev->features |= 0; | 1242 | netdev->features |= 0; |
1243 | netdev->ethtool_ops = ðoc_ethtool_ops; | ||
1114 | 1244 | ||
1115 | /* setup NAPI */ | 1245 | /* setup NAPI */ |
1116 | netif_napi_add(netdev, &priv->napi, ethoc_poll, 64); | 1246 | netif_napi_add(netdev, &priv->napi, ethoc_poll, 64); |
@@ -1133,6 +1263,8 @@ free_mdio: | |||
1133 | kfree(priv->mdio->irq); | 1263 | kfree(priv->mdio->irq); |
1134 | mdiobus_free(priv->mdio); | 1264 | mdiobus_free(priv->mdio); |
1135 | free: | 1265 | free: |
1266 | if (priv->clk) | ||
1267 | clk_disable_unprepare(priv->clk); | ||
1136 | free_netdev(netdev); | 1268 | free_netdev(netdev); |
1137 | out: | 1269 | out: |
1138 | return ret; | 1270 | return ret; |
@@ -1157,6 +1289,8 @@ static int ethoc_remove(struct platform_device *pdev) | |||
1157 | kfree(priv->mdio->irq); | 1289 | kfree(priv->mdio->irq); |
1158 | mdiobus_free(priv->mdio); | 1290 | mdiobus_free(priv->mdio); |
1159 | } | 1291 | } |
1292 | if (priv->clk) | ||
1293 | clk_disable_unprepare(priv->clk); | ||
1160 | unregister_netdev(netdev); | 1294 | unregister_netdev(netdev); |
1161 | free_netdev(netdev); | 1295 | free_netdev(netdev); |
1162 | } | 1296 | } |