1 /**********************************************************************
2 * Author: Cavium Networks
5 * This file is part of the OCTEON SDK
7 * Copyright (c) 2003-2007 Cavium Networks
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.
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
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/.
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>
29 #include <linux/phy.h>
30 #include <linux/ratelimit.h>
31 #include <linux/of_mdio.h>
35 #include <asm/octeon/octeon.h>
37 #include "ethernet-defines.h"
38 #include "octeon-ethernet.h"
39 #include "ethernet-mdio.h"
40 #include "ethernet-util.h"
42 #include <asm/octeon/cvmx-helper-board.h>
44 #include <asm/octeon/cvmx-smix-defs.h>
46 static void cvm_oct_get_drvinfo(struct net_device *dev,
47 struct ethtool_drvinfo *info)
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));
54 static int cvm_oct_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
56 struct octeon_ethernet *priv = netdev_priv(dev);
59 return phy_ethtool_gset(priv->phydev, cmd);
64 static int cvm_oct_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
66 struct octeon_ethernet *priv = netdev_priv(dev);
68 if (!capable(CAP_NET_ADMIN))
72 return phy_ethtool_sset(priv->phydev, cmd);
77 static int cvm_oct_nway_reset(struct net_device *dev)
79 struct octeon_ethernet *priv = netdev_priv(dev);
81 if (!capable(CAP_NET_ADMIN))
85 return phy_start_aneg(priv->phydev);
90 const struct ethtool_ops cvm_oct_ethtool_ops = {
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,
95 .get_link = ethtool_op_get_link,
99 * cvm_oct_ioctl - IOCTL support for PHY control
100 * @dev: Device to change
104 * Returns Zero on success
106 int cvm_oct_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
108 struct octeon_ethernet *priv = netdev_priv(dev);
110 if (!netif_running(dev))
116 return phy_mii_ioctl(priv->phydev, rq, cmd);
119 static void cvm_oct_note_carrier(struct octeon_ethernet *priv,
120 cvmx_helper_link_info_t li)
123 pr_notice_ratelimited("%s: %u Mbps %s duplex, port %d\n",
124 netdev_name(priv->netdev), li.s.speed,
125 (li.s.full_duplex) ? "Full" : "Half",
128 pr_notice_ratelimited("%s: Link down\n",
129 netdev_name(priv->netdev));
133 void cvm_oct_set_carrier(struct octeon_ethernet *priv,
134 cvmx_helper_link_info_t link_info)
136 cvm_oct_note_carrier(priv, link_info);
137 if (link_info.s.link_up) {
138 if (!netif_carrier_ok(priv->netdev))
139 netif_carrier_on(priv->netdev);
141 if (netif_carrier_ok(priv->netdev))
142 netif_carrier_off(priv->netdev);
146 void cvm_oct_adjust_link(struct net_device *dev)
148 struct octeon_ethernet *priv = netdev_priv(dev);
149 cvmx_helper_link_info_t link_info;
151 if (priv->last_link != priv->phydev->link) {
152 priv->last_link = priv->phydev->link;
154 link_info.s.link_up = priv->last_link ? 1 : 0;
155 link_info.s.full_duplex = priv->phydev->duplex ? 1 : 0;
156 link_info.s.speed = priv->phydev->speed;
158 cvmx_helper_link_set(priv->port, link_info);
159 cvm_oct_note_carrier(priv, link_info);
163 int cvm_oct_common_stop(struct net_device *dev)
165 struct octeon_ethernet *priv = netdev_priv(dev);
166 cvmx_helper_link_info_t link_info;
171 phy_disconnect(priv->phydev);
174 if (priv->last_link) {
178 cvmx_helper_link_set(priv->port, link_info);
179 cvm_oct_note_carrier(priv, link_info);
185 * cvm_oct_phy_setup_device - setup the PHY
187 * @dev: Device to setup
189 * Returns Zero on success, negative on failure
191 int cvm_oct_phy_setup_device(struct net_device *dev)
193 struct octeon_ethernet *priv = netdev_priv(dev);
194 struct device_node *phy_node;
199 phy_node = of_parse_phandle(priv->of_node, "phy-handle", 0);
203 priv->phydev = of_phy_connect(dev, phy_node, cvm_oct_adjust_link, 0,
204 PHY_INTERFACE_MODE_GMII);
206 if (priv->phydev == NULL)
210 phy_start_aneg(priv->phydev);
214 /* If there is no phy, assume a direct MAC connection and that
217 netif_carrier_on(dev);