staging: octeon-ethernet: add queue information to carrier note
[deliverable/linux.git] / drivers / staging / octeon / ethernet-mdio.c
CommitLineData
80ff0fd3
DD
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>
f6ed1b3b 29#include <linux/phy.h>
7a2eaf93 30#include <linux/ratelimit.h>
df9244c5 31#include <linux/of_mdio.h>
f6ed1b3b 32
80ff0fd3
DD
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"
f6ed1b3b 40#include "ethernet-util.h"
80ff0fd3 41
af866496 42#include <asm/octeon/cvmx-helper-board.h>
96217ebf 43#include <asm/octeon/cvmx-gmxx-defs.h>
af866496 44#include <asm/octeon/cvmx-smix-defs.h>
80ff0fd3 45
80ff0fd3
DD
46static void cvm_oct_get_drvinfo(struct net_device *dev,
47 struct ethtool_drvinfo *info)
48{
7826d43f
JP
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));
80ff0fd3
DD
52}
53
54static int cvm_oct_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
55{
56 struct octeon_ethernet *priv = netdev_priv(dev);
80ff0fd3 57
f6ed1b3b
DD
58 if (priv->phydev)
59 return phy_ethtool_gset(priv->phydev, cmd);
80ff0fd3 60
f6ed1b3b 61 return -EINVAL;
80ff0fd3
DD
62}
63
64static int cvm_oct_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
65{
66 struct octeon_ethernet *priv = netdev_priv(dev);
80ff0fd3 67
f6ed1b3b
DD
68 if (!capable(CAP_NET_ADMIN))
69 return -EPERM;
70
71 if (priv->phydev)
72 return phy_ethtool_sset(priv->phydev, cmd);
80ff0fd3 73
f6ed1b3b 74 return -EINVAL;
80ff0fd3
DD
75}
76
77static int cvm_oct_nway_reset(struct net_device *dev)
78{
79 struct octeon_ethernet *priv = netdev_priv(dev);
80ff0fd3 80
f6ed1b3b
DD
81 if (!capable(CAP_NET_ADMIN))
82 return -EPERM;
80ff0fd3 83
f6ed1b3b
DD
84 if (priv->phydev)
85 return phy_start_aneg(priv->phydev);
80ff0fd3 86
f6ed1b3b 87 return -EINVAL;
80ff0fd3
DD
88}
89
9326e361 90const struct ethtool_ops cvm_oct_ethtool_ops = {
80ff0fd3
DD
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,
f6ed1b3b 95 .get_link = ethtool_op_get_link,
80ff0fd3
DD
96};
97
98/**
ec977c5b 99 * cvm_oct_ioctl - IOCTL support for PHY control
80ff0fd3
DD
100 * @dev: Device to change
101 * @rq: the request
102 * @cmd: the command
ec977c5b 103 *
80ff0fd3
DD
104 * Returns Zero on success
105 */
106int cvm_oct_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
107{
108 struct octeon_ethernet *priv = netdev_priv(dev);
80ff0fd3 109
f6ed1b3b
DD
110 if (!netif_running(dev))
111 return -EINVAL;
112
113 if (!priv->phydev)
114 return -EINVAL;
115
28b04113 116 return phy_mii_ioctl(priv->phydev, rq, cmd);
f6ed1b3b 117}
80ff0fd3 118
ec3a2207
DD
119static void cvm_oct_note_carrier(struct octeon_ethernet *priv,
120 cvmx_helper_link_info_t li)
121{
122 if (li.s.link_up) {
36a14572 123 pr_notice_ratelimited("%s: %u Mbps %s duplex, port %d, queue %d\n",
ec3a2207
DD
124 netdev_name(priv->netdev), li.s.speed,
125 (li.s.full_duplex) ? "Full" : "Half",
36a14572 126 priv->port, priv->queue);
ec3a2207
DD
127 } else {
128 pr_notice_ratelimited("%s: Link down\n",
129 netdev_name(priv->netdev));
130 }
131}
132
ec3a2207 133void cvm_oct_adjust_link(struct net_device *dev)
f6ed1b3b
DD
134{
135 struct octeon_ethernet *priv = netdev_priv(dev);
136 cvmx_helper_link_info_t link_info;
137
138 if (priv->last_link != priv->phydev->link) {
139 priv->last_link = priv->phydev->link;
140 link_info.u64 = 0;
141 link_info.s.link_up = priv->last_link ? 1 : 0;
142 link_info.s.full_duplex = priv->phydev->duplex ? 1 : 0;
143 link_info.s.speed = priv->phydev->speed;
ec3a2207 144
0da50c69 145 cvmx_helper_link_set(priv->port, link_info);
ec3a2207 146 cvm_oct_note_carrier(priv, link_info);
f6ed1b3b 147 }
80ff0fd3
DD
148}
149
ec3a2207
DD
150int cvm_oct_common_stop(struct net_device *dev)
151{
152 struct octeon_ethernet *priv = netdev_priv(dev);
96217ebf 153 int interface = INTERFACE(priv->port);
ec3a2207 154 cvmx_helper_link_info_t link_info;
96217ebf
AK
155 union cvmx_gmxx_prtx_cfg gmx_cfg;
156 int index = INDEX(priv->port);
157
158 gmx_cfg.u64 = cvmx_read_csr(CVMX_GMXX_PRTX_CFG(index, interface));
159 gmx_cfg.s.en = 0;
160 cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index, interface), gmx_cfg.u64);
ec3a2207
DD
161
162 priv->poll = NULL;
163
164 if (priv->phydev)
165 phy_disconnect(priv->phydev);
166 priv->phydev = NULL;
167
168 if (priv->last_link) {
169 link_info.u64 = 0;
170 priv->last_link = 0;
171
172 cvmx_helper_link_set(priv->port, link_info);
173 cvm_oct_note_carrier(priv, link_info);
174 }
175 return 0;
176}
f6ed1b3b 177
80ff0fd3 178/**
ec977c5b 179 * cvm_oct_phy_setup_device - setup the PHY
80ff0fd3
DD
180 *
181 * @dev: Device to setup
182 *
183 * Returns Zero on success, negative on failure
184 */
f6ed1b3b 185int cvm_oct_phy_setup_device(struct net_device *dev)
80ff0fd3
DD
186{
187 struct octeon_ethernet *priv = netdev_priv(dev);
df9244c5 188 struct device_node *phy_node;
f6ed1b3b 189
df9244c5 190 if (!priv->of_node)
ec3a2207 191 goto no_phy;
f6ed1b3b 192
df9244c5
DD
193 phy_node = of_parse_phandle(priv->of_node, "phy-handle", 0);
194 if (!phy_node)
ec3a2207 195 goto no_phy;
f6ed1b3b 196
df9244c5
DD
197 priv->phydev = of_phy_connect(dev, phy_node, cvm_oct_adjust_link, 0,
198 PHY_INTERFACE_MODE_GMII);
199
200 if (priv->phydev == NULL)
201 return -ENODEV;
202
203 priv->last_link = 0;
204 phy_start_aneg(priv->phydev);
f6ed1b3b 205
ec3a2207
DD
206 return 0;
207no_phy:
208 /* If there is no phy, assume a direct MAC connection and that
209 * the link is up.
210 */
211 netif_carrier_on(dev);
80ff0fd3
DD
212 return 0;
213}
This page took 0.514181 seconds and 5 git commands to generate.