staging: hv: make HYPERV_UTILS depend on NLS to prevent a build error
[linux-2.6/next.git] / drivers / staging / octeon / ethernet-mdio.c
blob8a11ffcd7de89188252cda18d3841174e6802c59
1 /**********************************************************************
2 * Author: Cavium Networks
4 * Contact: support@caviumnetworks.com
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
17 * details.
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>
31 #include <net/dst.h>
33 #include <asm/octeon/octeon.h>
35 #include "ethernet-defines.h"
36 #include "octeon-ethernet.h"
37 #include "ethernet-mdio.h"
38 #include "ethernet-util.h"
40 #include "cvmx-helper-board.h"
42 #include "cvmx-smix-defs.h"
44 static void cvm_oct_get_drvinfo(struct net_device *dev,
45 struct ethtool_drvinfo *info)
47 strcpy(info->driver, "cavium-ethernet");
48 strcpy(info->version, OCTEON_ETHERNET_VERSION);
49 strcpy(info->bus_info, "Builtin");
52 static int cvm_oct_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
54 struct octeon_ethernet *priv = netdev_priv(dev);
56 if (priv->phydev)
57 return phy_ethtool_gset(priv->phydev, cmd);
59 return -EINVAL;
62 static int cvm_oct_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
64 struct octeon_ethernet *priv = netdev_priv(dev);
66 if (!capable(CAP_NET_ADMIN))
67 return -EPERM;
69 if (priv->phydev)
70 return phy_ethtool_sset(priv->phydev, cmd);
72 return -EINVAL;
75 static int cvm_oct_nway_reset(struct net_device *dev)
77 struct octeon_ethernet *priv = netdev_priv(dev);
79 if (!capable(CAP_NET_ADMIN))
80 return -EPERM;
82 if (priv->phydev)
83 return phy_start_aneg(priv->phydev);
85 return -EINVAL;
88 const struct ethtool_ops cvm_oct_ethtool_ops = {
89 .get_drvinfo = cvm_oct_get_drvinfo,
90 .get_settings = cvm_oct_get_settings,
91 .set_settings = cvm_oct_set_settings,
92 .nway_reset = cvm_oct_nway_reset,
93 .get_link = ethtool_op_get_link,
96 /**
97 * cvm_oct_ioctl - IOCTL support for PHY control
98 * @dev: Device to change
99 * @rq: the request
100 * @cmd: the command
102 * Returns Zero on success
104 int cvm_oct_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
106 struct octeon_ethernet *priv = netdev_priv(dev);
108 if (!netif_running(dev))
109 return -EINVAL;
111 if (!priv->phydev)
112 return -EINVAL;
114 return phy_mii_ioctl(priv->phydev, rq, cmd);
117 static void cvm_oct_adjust_link(struct net_device *dev)
119 struct octeon_ethernet *priv = netdev_priv(dev);
120 cvmx_helper_link_info_t link_info;
122 if (priv->last_link != priv->phydev->link) {
123 priv->last_link = priv->phydev->link;
124 link_info.u64 = 0;
125 link_info.s.link_up = priv->last_link ? 1 : 0;
126 link_info.s.full_duplex = priv->phydev->duplex ? 1 : 0;
127 link_info.s.speed = priv->phydev->speed;
128 cvmx_helper_link_set( priv->port, link_info);
129 if (priv->last_link) {
130 netif_carrier_on(dev);
131 if (priv->queue != -1)
132 DEBUGPRINT("%s: %u Mbps %s duplex, "
133 "port %2d, queue %2d\n",
134 dev->name, priv->phydev->speed,
135 priv->phydev->duplex ?
136 "Full" : "Half",
137 priv->port, priv->queue);
138 else
139 DEBUGPRINT("%s: %u Mbps %s duplex, "
140 "port %2d, POW\n",
141 dev->name, priv->phydev->speed,
142 priv->phydev->duplex ?
143 "Full" : "Half",
144 priv->port);
145 } else {
146 netif_carrier_off(dev);
147 DEBUGPRINT("%s: Link down\n", dev->name);
154 * cvm_oct_phy_setup_device - setup the PHY
156 * @dev: Device to setup
158 * Returns Zero on success, negative on failure
160 int cvm_oct_phy_setup_device(struct net_device *dev)
162 struct octeon_ethernet *priv = netdev_priv(dev);
164 int phy_addr = cvmx_helper_board_get_mii_address(priv->port);
165 if (phy_addr != -1) {
166 char phy_id[20];
168 snprintf(phy_id, sizeof(phy_id), PHY_ID_FMT, "0", phy_addr);
170 priv->phydev = phy_connect(dev, phy_id, cvm_oct_adjust_link, 0,
171 PHY_INTERFACE_MODE_GMII);
173 if (IS_ERR(priv->phydev)) {
174 priv->phydev = NULL;
175 return -1;
177 priv->last_link = 0;
178 phy_start_aneg(priv->phydev);
180 return 0;