David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 1 | /********************************************************************** |
| 2 | * Author: Cavium Networks |
| 3 | * |
| 4 | * Contact: support@caviumnetworks.com |
| 5 | * This file is part of the OCTEON SDK |
| 6 | * |
| 7 | * Copyright (c) 2003-2007 Cavium Networks |
| 8 | * |
| 9 | * This file is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License, Version 2, as |
| 11 | * published by the Free Software Foundation. |
| 12 | * |
| 13 | * This file is distributed in the hope that it will be useful, but |
| 14 | * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty |
| 15 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or |
| 16 | * NONINFRINGEMENT. See the GNU General Public License for more |
| 17 | * details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this file; if not, write to the Free Software |
| 21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 22 | * or visit http://www.gnu.org/licenses/. |
| 23 | * |
| 24 | * This file may also be available under a different license from Cavium. |
| 25 | * Contact Cavium Networks for more information |
| 26 | **********************************************************************/ |
| 27 | #include <linux/kernel.h> |
| 28 | #include <linux/ethtool.h> |
David Daney | f6ed1b3 | 2009-10-14 12:04:42 -0700 | [diff] [blame] | 29 | #include <linux/phy.h> |
Christian Dietrich | 7a2eaf9 | 2011-06-04 17:35:58 +0200 | [diff] [blame] | 30 | #include <linux/ratelimit.h> |
David Daney | df9244c | 2012-07-05 18:12:40 +0200 | [diff] [blame] | 31 | #include <linux/of_mdio.h> |
David Daney | f6ed1b3 | 2009-10-14 12:04:42 -0700 | [diff] [blame] | 32 | |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 33 | #include <net/dst.h> |
| 34 | |
| 35 | #include <asm/octeon/octeon.h> |
| 36 | |
| 37 | #include "ethernet-defines.h" |
| 38 | #include "octeon-ethernet.h" |
| 39 | #include "ethernet-mdio.h" |
David Daney | f6ed1b3 | 2009-10-14 12:04:42 -0700 | [diff] [blame] | 40 | #include "ethernet-util.h" |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 41 | |
David Daney | af86649 | 2011-11-22 14:47:00 +0000 | [diff] [blame] | 42 | #include <asm/octeon/cvmx-helper-board.h> |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 43 | |
David Daney | af86649 | 2011-11-22 14:47:00 +0000 | [diff] [blame] | 44 | #include <asm/octeon/cvmx-smix-defs.h> |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 45 | |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 46 | static void cvm_oct_get_drvinfo(struct net_device *dev, |
| 47 | struct ethtool_drvinfo *info) |
| 48 | { |
Jiri Pirko | 7826d43 | 2013-01-06 00:44:26 +0000 | [diff] [blame] | 49 | strlcpy(info->driver, "cavium-ethernet", sizeof(info->driver)); |
| 50 | strlcpy(info->version, OCTEON_ETHERNET_VERSION, sizeof(info->version)); |
| 51 | strlcpy(info->bus_info, "Builtin", sizeof(info->bus_info)); |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | static int cvm_oct_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 55 | { |
| 56 | struct octeon_ethernet *priv = netdev_priv(dev); |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 57 | |
David Daney | f6ed1b3 | 2009-10-14 12:04:42 -0700 | [diff] [blame] | 58 | if (priv->phydev) |
| 59 | return phy_ethtool_gset(priv->phydev, cmd); |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 60 | |
David Daney | f6ed1b3 | 2009-10-14 12:04:42 -0700 | [diff] [blame] | 61 | return -EINVAL; |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | static int cvm_oct_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 65 | { |
| 66 | struct octeon_ethernet *priv = netdev_priv(dev); |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 67 | |
David Daney | f6ed1b3 | 2009-10-14 12:04:42 -0700 | [diff] [blame] | 68 | if (!capable(CAP_NET_ADMIN)) |
| 69 | return -EPERM; |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 70 | |
David Daney | f6ed1b3 | 2009-10-14 12:04:42 -0700 | [diff] [blame] | 71 | if (priv->phydev) |
| 72 | return phy_ethtool_sset(priv->phydev, cmd); |
| 73 | |
| 74 | return -EINVAL; |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | static int cvm_oct_nway_reset(struct net_device *dev) |
| 78 | { |
| 79 | struct octeon_ethernet *priv = netdev_priv(dev); |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 80 | |
David Daney | f6ed1b3 | 2009-10-14 12:04:42 -0700 | [diff] [blame] | 81 | if (!capable(CAP_NET_ADMIN)) |
| 82 | return -EPERM; |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 83 | |
David Daney | f6ed1b3 | 2009-10-14 12:04:42 -0700 | [diff] [blame] | 84 | if (priv->phydev) |
| 85 | return phy_start_aneg(priv->phydev); |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 86 | |
David Daney | f6ed1b3 | 2009-10-14 12:04:42 -0700 | [diff] [blame] | 87 | return -EINVAL; |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 88 | } |
| 89 | |
David Daney | 9326e36 | 2009-10-01 16:47:39 -0700 | [diff] [blame] | 90 | const struct ethtool_ops cvm_oct_ethtool_ops = { |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 91 | .get_drvinfo = cvm_oct_get_drvinfo, |
| 92 | .get_settings = cvm_oct_get_settings, |
| 93 | .set_settings = cvm_oct_set_settings, |
| 94 | .nway_reset = cvm_oct_nway_reset, |
David Daney | f6ed1b3 | 2009-10-14 12:04:42 -0700 | [diff] [blame] | 95 | .get_link = ethtool_op_get_link, |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | /** |
David Daney | ec977c5 | 2010-02-16 17:25:32 -0800 | [diff] [blame] | 99 | * cvm_oct_ioctl - IOCTL support for PHY control |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 100 | * @dev: Device to change |
| 101 | * @rq: the request |
| 102 | * @cmd: the command |
David Daney | ec977c5 | 2010-02-16 17:25:32 -0800 | [diff] [blame] | 103 | * |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 104 | * Returns Zero on success |
| 105 | */ |
| 106 | int cvm_oct_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) |
| 107 | { |
| 108 | struct octeon_ethernet *priv = netdev_priv(dev); |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 109 | |
David Daney | f6ed1b3 | 2009-10-14 12:04:42 -0700 | [diff] [blame] | 110 | if (!netif_running(dev)) |
| 111 | return -EINVAL; |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 112 | |
David Daney | f6ed1b3 | 2009-10-14 12:04:42 -0700 | [diff] [blame] | 113 | if (!priv->phydev) |
| 114 | return -EINVAL; |
| 115 | |
Richard Cochran | 28b0411 | 2010-07-17 08:48:55 +0000 | [diff] [blame] | 116 | return phy_mii_ioctl(priv->phydev, rq, cmd); |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 117 | } |
| 118 | |
David Daney | f6ed1b3 | 2009-10-14 12:04:42 -0700 | [diff] [blame] | 119 | static void cvm_oct_adjust_link(struct net_device *dev) |
| 120 | { |
| 121 | struct octeon_ethernet *priv = netdev_priv(dev); |
| 122 | cvmx_helper_link_info_t link_info; |
| 123 | |
| 124 | if (priv->last_link != priv->phydev->link) { |
| 125 | priv->last_link = priv->phydev->link; |
| 126 | link_info.u64 = 0; |
| 127 | link_info.s.link_up = priv->last_link ? 1 : 0; |
| 128 | link_info.s.full_duplex = priv->phydev->duplex ? 1 : 0; |
| 129 | link_info.s.speed = priv->phydev->speed; |
Himangi Saraogi | 0da50c6 | 2014-03-03 06:30:46 +0530 | [diff] [blame] | 130 | cvmx_helper_link_set(priv->port, link_info); |
David Daney | f6ed1b3 | 2009-10-14 12:04:42 -0700 | [diff] [blame] | 131 | if (priv->last_link) { |
| 132 | netif_carrier_on(dev); |
| 133 | if (priv->queue != -1) |
Christian Dietrich | 7a2eaf9 | 2011-06-04 17:35:58 +0200 | [diff] [blame] | 134 | printk_ratelimited("%s: %u Mbps %s duplex, " |
Aybuke Ozdemir | de82a6d | 2014-03-15 18:54:28 +0200 | [diff] [blame] | 135 | "port %2d, queue %2d\n", dev->name, |
| 136 | priv->phydev->speed, |
| 137 | priv->phydev->duplex ? "Full" : "Half", |
| 138 | priv->port, priv->queue); |
David Daney | f6ed1b3 | 2009-10-14 12:04:42 -0700 | [diff] [blame] | 139 | else |
Christian Dietrich | 7a2eaf9 | 2011-06-04 17:35:58 +0200 | [diff] [blame] | 140 | printk_ratelimited("%s: %u Mbps %s duplex, " |
Aybuke Ozdemir | de82a6d | 2014-03-15 18:54:28 +0200 | [diff] [blame] | 141 | "port %2d, POW\n", dev->name, |
| 142 | priv->phydev->speed, |
| 143 | priv->phydev->duplex ? "Full" : "Half", |
| 144 | priv->port); |
David Daney | f6ed1b3 | 2009-10-14 12:04:42 -0700 | [diff] [blame] | 145 | } else { |
| 146 | netif_carrier_off(dev); |
Christian Dietrich | 7a2eaf9 | 2011-06-04 17:35:58 +0200 | [diff] [blame] | 147 | printk_ratelimited("%s: Link down\n", dev->name); |
David Daney | f6ed1b3 | 2009-10-14 12:04:42 -0700 | [diff] [blame] | 148 | } |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 153 | /** |
David Daney | ec977c5 | 2010-02-16 17:25:32 -0800 | [diff] [blame] | 154 | * cvm_oct_phy_setup_device - setup the PHY |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 155 | * |
| 156 | * @dev: Device to setup |
| 157 | * |
| 158 | * Returns Zero on success, negative on failure |
| 159 | */ |
David Daney | f6ed1b3 | 2009-10-14 12:04:42 -0700 | [diff] [blame] | 160 | int cvm_oct_phy_setup_device(struct net_device *dev) |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 161 | { |
| 162 | struct octeon_ethernet *priv = netdev_priv(dev); |
David Daney | df9244c | 2012-07-05 18:12:40 +0200 | [diff] [blame] | 163 | struct device_node *phy_node; |
David Daney | f6ed1b3 | 2009-10-14 12:04:42 -0700 | [diff] [blame] | 164 | |
David Daney | df9244c | 2012-07-05 18:12:40 +0200 | [diff] [blame] | 165 | if (!priv->of_node) |
| 166 | return 0; |
David Daney | f6ed1b3 | 2009-10-14 12:04:42 -0700 | [diff] [blame] | 167 | |
David Daney | df9244c | 2012-07-05 18:12:40 +0200 | [diff] [blame] | 168 | phy_node = of_parse_phandle(priv->of_node, "phy-handle", 0); |
| 169 | if (!phy_node) |
| 170 | return 0; |
David Daney | f6ed1b3 | 2009-10-14 12:04:42 -0700 | [diff] [blame] | 171 | |
David Daney | df9244c | 2012-07-05 18:12:40 +0200 | [diff] [blame] | 172 | priv->phydev = of_phy_connect(dev, phy_node, cvm_oct_adjust_link, 0, |
| 173 | PHY_INTERFACE_MODE_GMII); |
David Daney | f6ed1b3 | 2009-10-14 12:04:42 -0700 | [diff] [blame] | 174 | |
David Daney | df9244c | 2012-07-05 18:12:40 +0200 | [diff] [blame] | 175 | if (priv->phydev == NULL) |
| 176 | return -ENODEV; |
| 177 | |
| 178 | priv->last_link = 0; |
| 179 | phy_start_aneg(priv->phydev); |
| 180 | |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 181 | return 0; |
| 182 | } |