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_get_settings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
39 struct octeon_ethernet
*priv
= netdev_priv(dev
);
42 return phy_ethtool_gset(priv
->phydev
, cmd
);
47 static int cvm_oct_set_settings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
49 struct octeon_ethernet
*priv
= netdev_priv(dev
);
51 if (!capable(CAP_NET_ADMIN
))
55 return phy_ethtool_sset(priv
->phydev
, cmd
);
60 static int cvm_oct_nway_reset(struct net_device
*dev
)
62 struct octeon_ethernet
*priv
= netdev_priv(dev
);
64 if (!capable(CAP_NET_ADMIN
))
68 return phy_start_aneg(priv
->phydev
);
73 const struct ethtool_ops cvm_oct_ethtool_ops
= {
74 .get_drvinfo
= cvm_oct_get_drvinfo
,
75 .get_settings
= cvm_oct_get_settings
,
76 .set_settings
= cvm_oct_set_settings
,
77 .nway_reset
= cvm_oct_nway_reset
,
78 .get_link
= ethtool_op_get_link
,
82 * cvm_oct_ioctl - IOCTL support for PHY control
83 * @dev: Device to change
87 * Returns Zero on success
89 int cvm_oct_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
91 struct octeon_ethernet
*priv
= netdev_priv(dev
);
93 if (!netif_running(dev
))
99 return phy_mii_ioctl(priv
->phydev
, rq
, cmd
);
102 void cvm_oct_note_carrier(struct octeon_ethernet
*priv
,
103 cvmx_helper_link_info_t li
)
106 pr_notice_ratelimited("%s: %u Mbps %s duplex, port %d, queue %d\n",
107 netdev_name(priv
->netdev
), li
.s
.speed
,
108 (li
.s
.full_duplex
) ? "Full" : "Half",
109 priv
->port
, priv
->queue
);
111 pr_notice_ratelimited("%s: Link down\n",
112 netdev_name(priv
->netdev
));
116 void cvm_oct_adjust_link(struct net_device
*dev
)
118 struct octeon_ethernet
*priv
= netdev_priv(dev
);
119 cvmx_helper_link_info_t link_info
;
121 if (priv
->last_link
!= priv
->phydev
->link
) {
122 priv
->last_link
= priv
->phydev
->link
;
124 link_info
.s
.link_up
= priv
->last_link
? 1 : 0;
125 link_info
.s
.full_duplex
= priv
->phydev
->duplex
? 1 : 0;
126 link_info
.s
.speed
= priv
->phydev
->speed
;
128 cvmx_helper_link_set(priv
->port
, link_info
);
129 cvm_oct_note_carrier(priv
, link_info
);
133 int cvm_oct_common_stop(struct net_device
*dev
)
135 struct octeon_ethernet
*priv
= netdev_priv(dev
);
136 int interface
= INTERFACE(priv
->port
);
137 cvmx_helper_link_info_t link_info
;
138 union cvmx_gmxx_prtx_cfg gmx_cfg
;
139 int index
= INDEX(priv
->port
);
141 gmx_cfg
.u64
= cvmx_read_csr(CVMX_GMXX_PRTX_CFG(index
, interface
));
143 cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index
, interface
), gmx_cfg
.u64
);
148 phy_disconnect(priv
->phydev
);
151 if (priv
->last_link
) {
155 cvmx_helper_link_set(priv
->port
, link_info
);
156 cvm_oct_note_carrier(priv
, link_info
);
162 * cvm_oct_phy_setup_device - setup the PHY
164 * @dev: Device to setup
166 * Returns Zero on success, negative on failure
168 int cvm_oct_phy_setup_device(struct net_device
*dev
)
170 struct octeon_ethernet
*priv
= netdev_priv(dev
);
171 struct device_node
*phy_node
;
176 phy_node
= of_parse_phandle(priv
->of_node
, "phy-handle", 0);
180 priv
->phydev
= of_phy_connect(dev
, phy_node
, cvm_oct_adjust_link
, 0,
181 PHY_INTERFACE_MODE_GMII
);
183 if (priv
->phydev
== NULL
)
187 phy_start_aneg(priv
->phydev
);
191 /* If there is no phy, assume a direct MAC connection and that
194 netif_carrier_on(dev
);