2 * This file is based on code from OCTEON SDK by Cavium Networks.
4 * Copyright (c) 2003-2007 Cavium Networks
6 * This file is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License, Version 2, as
8 * published by the Free Software Foundation.
11 #include <linux/kernel.h>
12 #include <linux/ethtool.h>
13 #include <linux/phy.h>
14 #include <linux/ratelimit.h>
15 #include <linux/of_mdio.h>
16 #include <generated/utsrelease.h>
19 #include <asm/octeon/octeon.h>
21 #include "ethernet-defines.h"
22 #include "octeon-ethernet.h"
23 #include "ethernet-mdio.h"
24 #include "ethernet-util.h"
26 #include <asm/octeon/cvmx-gmxx-defs.h>
27 #include <asm/octeon/cvmx-smix-defs.h>
29 static void cvm_oct_get_drvinfo(struct net_device
*dev
,
30 struct ethtool_drvinfo
*info
)
32 strlcpy(info
->driver
, KBUILD_MODNAME
, sizeof(info
->driver
));
33 strlcpy(info
->version
, UTS_RELEASE
, sizeof(info
->version
));
34 strlcpy(info
->bus_info
, "Builtin", sizeof(info
->bus_info
));
37 static int cvm_oct_nway_reset(struct net_device
*dev
)
39 if (!capable(CAP_NET_ADMIN
))
43 return phy_start_aneg(dev
->phydev
);
48 const struct ethtool_ops cvm_oct_ethtool_ops
= {
49 .get_drvinfo
= cvm_oct_get_drvinfo
,
50 .nway_reset
= cvm_oct_nway_reset
,
51 .get_link
= ethtool_op_get_link
,
52 .get_link_ksettings
= phy_ethtool_get_link_ksettings
,
53 .set_link_ksettings
= phy_ethtool_set_link_ksettings
,
57 * cvm_oct_ioctl - IOCTL support for PHY control
58 * @dev: Device to change
62 * Returns Zero on success
64 int cvm_oct_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
66 if (!netif_running(dev
))
72 return phy_mii_ioctl(dev
->phydev
, rq
, cmd
);
75 void cvm_oct_note_carrier(struct octeon_ethernet
*priv
,
76 cvmx_helper_link_info_t li
)
79 pr_notice_ratelimited("%s: %u Mbps %s duplex, port %d, queue %d\n",
80 netdev_name(priv
->netdev
), li
.s
.speed
,
81 (li
.s
.full_duplex
) ? "Full" : "Half",
82 priv
->port
, priv
->queue
);
84 pr_notice_ratelimited("%s: Link down\n",
85 netdev_name(priv
->netdev
));
89 void cvm_oct_adjust_link(struct net_device
*dev
)
91 struct octeon_ethernet
*priv
= netdev_priv(dev
);
92 cvmx_helper_link_info_t link_info
;
95 link_info
.s
.link_up
= dev
->phydev
->link
? 1 : 0;
96 link_info
.s
.full_duplex
= dev
->phydev
->duplex
? 1 : 0;
97 link_info
.s
.speed
= dev
->phydev
->speed
;
98 priv
->link_info
= link_info
.u64
;
101 * The polling task need to know about link status changes.
106 if (priv
->last_link
!= dev
->phydev
->link
) {
107 priv
->last_link
= dev
->phydev
->link
;
108 cvmx_helper_link_set(priv
->port
, link_info
);
109 cvm_oct_note_carrier(priv
, link_info
);
113 int cvm_oct_common_stop(struct net_device
*dev
)
115 struct octeon_ethernet
*priv
= netdev_priv(dev
);
116 int interface
= INTERFACE(priv
->port
);
117 cvmx_helper_link_info_t link_info
;
118 union cvmx_gmxx_prtx_cfg gmx_cfg
;
119 int index
= INDEX(priv
->port
);
121 gmx_cfg
.u64
= cvmx_read_csr(CVMX_GMXX_PRTX_CFG(index
, interface
));
123 cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index
, interface
), gmx_cfg
.u64
);
128 phy_disconnect(dev
->phydev
);
130 if (priv
->last_link
) {
134 cvmx_helper_link_set(priv
->port
, link_info
);
135 cvm_oct_note_carrier(priv
, link_info
);
141 * cvm_oct_phy_setup_device - setup the PHY
143 * @dev: Device to setup
145 * Returns Zero on success, negative on failure
147 int cvm_oct_phy_setup_device(struct net_device
*dev
)
149 struct octeon_ethernet
*priv
= netdev_priv(dev
);
150 struct device_node
*phy_node
;
151 struct phy_device
*phydev
= NULL
;
156 phy_node
= of_parse_phandle(priv
->of_node
, "phy-handle", 0);
157 if (!phy_node
&& of_phy_is_fixed_link(priv
->of_node
)) {
160 rc
= of_phy_register_fixed_link(priv
->of_node
);
164 phy_node
= of_node_get(priv
->of_node
);
169 phydev
= of_phy_connect(dev
, phy_node
, cvm_oct_adjust_link
, 0,
170 PHY_INTERFACE_MODE_GMII
);
171 of_node_put(phy_node
);
177 phy_start_aneg(phydev
);
181 /* If there is no phy, assume a direct MAC connection and that
184 netif_carrier_on(dev
);