1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#include <linux/kernel.h>
28#include <linux/ethtool.h>
29#include <linux/phy.h>
30#include <linux/ratelimit.h>
31
32#include <net/dst.h>
33
34#include <asm/octeon/octeon.h>
35
36#include "ethernet-defines.h"
37#include "octeon-ethernet.h"
38#include "ethernet-mdio.h"
39#include "ethernet-util.h"
40
41#include <asm/octeon/cvmx-helper-board.h>
42
43#include <asm/octeon/cvmx-smix-defs.h>
44
45static void cvm_oct_get_drvinfo(struct net_device *dev,
46 struct ethtool_drvinfo *info)
47{
48 strcpy(info->driver, "cavium-ethernet");
49 strcpy(info->version, OCTEON_ETHERNET_VERSION);
50 strcpy(info->bus_info, "Builtin");
51}
52
53static int cvm_oct_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
54{
55 struct octeon_ethernet *priv = netdev_priv(dev);
56
57 if (priv->phydev)
58 return phy_ethtool_gset(priv->phydev, cmd);
59
60 return -EINVAL;
61}
62
63static int cvm_oct_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
64{
65 struct octeon_ethernet *priv = netdev_priv(dev);
66
67 if (!capable(CAP_NET_ADMIN))
68 return -EPERM;
69
70 if (priv->phydev)
71 return phy_ethtool_sset(priv->phydev, cmd);
72
73 return -EINVAL;
74}
75
76static int cvm_oct_nway_reset(struct net_device *dev)
77{
78 struct octeon_ethernet *priv = netdev_priv(dev);
79
80 if (!capable(CAP_NET_ADMIN))
81 return -EPERM;
82
83 if (priv->phydev)
84 return phy_start_aneg(priv->phydev);
85
86 return -EINVAL;
87}
88
89const struct ethtool_ops cvm_oct_ethtool_ops = {
90 .get_drvinfo = cvm_oct_get_drvinfo,
91 .get_settings = cvm_oct_get_settings,
92 .set_settings = cvm_oct_set_settings,
93 .nway_reset = cvm_oct_nway_reset,
94 .get_link = ethtool_op_get_link,
95};
96
97
98
99
100
101
102
103
104
105int cvm_oct_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
106{
107 struct octeon_ethernet *priv = netdev_priv(dev);
108
109 if (!netif_running(dev))
110 return -EINVAL;
111
112 if (!priv->phydev)
113 return -EINVAL;
114
115 return phy_mii_ioctl(priv->phydev, rq, cmd);
116}
117
118static void cvm_oct_adjust_link(struct net_device *dev)
119{
120 struct octeon_ethernet *priv = netdev_priv(dev);
121 cvmx_helper_link_info_t link_info;
122
123 if (priv->last_link != priv->phydev->link) {
124 priv->last_link = priv->phydev->link;
125 link_info.u64 = 0;
126 link_info.s.link_up = priv->last_link ? 1 : 0;
127 link_info.s.full_duplex = priv->phydev->duplex ? 1 : 0;
128 link_info.s.speed = priv->phydev->speed;
129 cvmx_helper_link_set( priv->port, link_info);
130 if (priv->last_link) {
131 netif_carrier_on(dev);
132 if (priv->queue != -1)
133 printk_ratelimited("%s: %u Mbps %s duplex, "
134 "port %2d, queue %2d\n",
135 dev->name, priv->phydev->speed,
136 priv->phydev->duplex ?
137 "Full" : "Half",
138 priv->port, priv->queue);
139 else
140 printk_ratelimited("%s: %u Mbps %s duplex, "
141 "port %2d, POW\n",
142 dev->name, priv->phydev->speed,
143 priv->phydev->duplex ?
144 "Full" : "Half",
145 priv->port);
146 } else {
147 netif_carrier_off(dev);
148 printk_ratelimited("%s: Link down\n", dev->name);
149 }
150 }
151}
152
153
154
155
156
157
158
159
160
161int cvm_oct_phy_setup_device(struct net_device *dev)
162{
163 struct octeon_ethernet *priv = netdev_priv(dev);
164
165 int phy_addr = cvmx_helper_board_get_mii_address(priv->port);
166 if (phy_addr != -1) {
167 char phy_id[20];
168
169 snprintf(phy_id, sizeof(phy_id), PHY_ID_FMT, "0", phy_addr);
170
171 priv->phydev = phy_connect(dev, phy_id, cvm_oct_adjust_link, 0,
172 PHY_INTERFACE_MODE_GMII);
173
174 if (IS_ERR(priv->phydev)) {
175 priv->phydev = NULL;
176 return -1;
177 }
178 priv->last_link = 0;
179 phy_start_aneg(priv->phydev);
180 }
181 return 0;
182}
183