2 * Copyright (c) 2013 Johannes Berg <johannes@sipsolutions.net>
4 * This file is free software: you may copy, redistribute and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation, either version 2 of the License, or (at your
7 * option) any later version.
9 * This file is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 * This file incorporates work covered by the following copyright and
20 * Copyright (c) 2012 Qualcomm Atheros, Inc.
22 * Permission to use, copy, modify, and/or distribute this software for any
23 * purpose with or without fee is hereby granted, provided that the above
24 * copyright notice and this permission notice appear in all copies.
26 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
27 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
28 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
29 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
30 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
31 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
32 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
35 #include <linux/pci.h>
37 #include <linux/tcp.h>
38 #include <linux/netdevice.h>
39 #include <linux/etherdevice.h>
40 #include <linux/ethtool.h>
41 #include <linux/mdio.h>
42 #include <linux/interrupt.h>
43 #include <asm/byteorder.h>
50 static int alx_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
52 struct alx_priv *alx = netdev_priv(netdev);
53 struct alx_hw *hw = &alx->hw;
55 ecmd->supported = SUPPORTED_10baseT_Half |
56 SUPPORTED_10baseT_Full |
57 SUPPORTED_100baseT_Half |
58 SUPPORTED_100baseT_Full |
63 ecmd->supported |= SUPPORTED_1000baseT_Full;
65 ecmd->advertising = ADVERTISED_TP;
66 if (hw->adv_cfg & ADVERTISED_Autoneg)
67 ecmd->advertising |= hw->adv_cfg;
70 ecmd->phy_address = 0;
71 if (hw->adv_cfg & ADVERTISED_Autoneg)
72 ecmd->autoneg = AUTONEG_ENABLE;
74 ecmd->autoneg = AUTONEG_DISABLE;
75 ecmd->transceiver = XCVR_INTERNAL;
77 if (hw->flowctrl & ALX_FC_ANEG && hw->adv_cfg & ADVERTISED_Autoneg) {
78 if (hw->flowctrl & ALX_FC_RX) {
79 ecmd->advertising |= ADVERTISED_Pause;
81 if (!(hw->flowctrl & ALX_FC_TX))
82 ecmd->advertising |= ADVERTISED_Asym_Pause;
83 } else if (hw->flowctrl & ALX_FC_TX) {
84 ecmd->advertising |= ADVERTISED_Asym_Pause;
88 if (hw->link_speed != SPEED_UNKNOWN) {
89 ethtool_cmd_speed_set(ecmd,
90 hw->link_speed - hw->link_speed % 10);
91 ecmd->duplex = hw->link_speed % 10;
93 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
94 ecmd->duplex = DUPLEX_UNKNOWN;
100 static int alx_set_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
102 struct alx_priv *alx = netdev_priv(netdev);
103 struct alx_hw *hw = &alx->hw;
108 if (ecmd->autoneg == AUTONEG_ENABLE) {
109 if (ecmd->advertising & ADVERTISED_1000baseT_Half)
111 adv_cfg = ecmd->advertising | ADVERTISED_Autoneg;
113 int speed = ethtool_cmd_speed(ecmd);
115 switch (speed + ecmd->duplex) {
116 case SPEED_10 + DUPLEX_HALF:
117 adv_cfg = ADVERTISED_10baseT_Half;
119 case SPEED_10 + DUPLEX_FULL:
120 adv_cfg = ADVERTISED_10baseT_Full;
122 case SPEED_100 + DUPLEX_HALF:
123 adv_cfg = ADVERTISED_100baseT_Half;
125 case SPEED_100 + DUPLEX_FULL:
126 adv_cfg = ADVERTISED_100baseT_Full;
133 hw->adv_cfg = adv_cfg;
134 return alx_setup_speed_duplex(hw, adv_cfg, hw->flowctrl);
137 static void alx_get_pauseparam(struct net_device *netdev,
138 struct ethtool_pauseparam *pause)
140 struct alx_priv *alx = netdev_priv(netdev);
141 struct alx_hw *hw = &alx->hw;
143 if (hw->flowctrl & ALX_FC_ANEG &&
144 hw->adv_cfg & ADVERTISED_Autoneg)
145 pause->autoneg = AUTONEG_ENABLE;
147 pause->autoneg = AUTONEG_DISABLE;
149 if (hw->flowctrl & ALX_FC_TX)
154 if (hw->flowctrl & ALX_FC_RX)
161 static int alx_set_pauseparam(struct net_device *netdev,
162 struct ethtool_pauseparam *pause)
164 struct alx_priv *alx = netdev_priv(netdev);
165 struct alx_hw *hw = &alx->hw;
167 bool reconfig_phy = false;
179 /* restart auto-neg for auto-mode */
180 if (hw->adv_cfg & ADVERTISED_Autoneg) {
181 if (!((fc ^ hw->flowctrl) & ALX_FC_ANEG))
183 if (fc & hw->flowctrl & ALX_FC_ANEG &&
184 (fc ^ hw->flowctrl) & (ALX_FC_RX | ALX_FC_TX))
189 err = alx_setup_speed_duplex(hw, hw->adv_cfg, fc);
194 /* flow control on mac */
195 if ((fc ^ hw->flowctrl) & (ALX_FC_RX | ALX_FC_TX))
196 alx_cfg_mac_flowcontrol(hw, fc);
203 static u32 alx_get_msglevel(struct net_device *netdev)
205 struct alx_priv *alx = netdev_priv(netdev);
207 return alx->msg_enable;
210 static void alx_set_msglevel(struct net_device *netdev, u32 data)
212 struct alx_priv *alx = netdev_priv(netdev);
214 alx->msg_enable = data;
217 static void alx_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
219 struct alx_priv *alx = netdev_priv(netdev);
220 struct alx_hw *hw = &alx->hw;
222 wol->supported = WAKE_MAGIC | WAKE_PHY;
225 if (hw->sleep_ctrl & ALX_SLEEP_WOL_MAGIC)
226 wol->wolopts |= WAKE_MAGIC;
227 if (hw->sleep_ctrl & ALX_SLEEP_WOL_PHY)
228 wol->wolopts |= WAKE_PHY;
231 static int alx_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
233 struct alx_priv *alx = netdev_priv(netdev);
234 struct alx_hw *hw = &alx->hw;
236 if (wol->wolopts & (WAKE_ARP | WAKE_MAGICSECURE |
237 WAKE_UCAST | WAKE_BCAST | WAKE_MCAST))
242 if (wol->wolopts & WAKE_MAGIC)
243 hw->sleep_ctrl |= ALX_SLEEP_WOL_MAGIC;
244 if (wol->wolopts & WAKE_PHY)
245 hw->sleep_ctrl |= ALX_SLEEP_WOL_PHY;
247 device_set_wakeup_enable(&alx->hw.pdev->dev, hw->sleep_ctrl);
252 static void alx_get_drvinfo(struct net_device *netdev,
253 struct ethtool_drvinfo *drvinfo)
255 struct alx_priv *alx = netdev_priv(netdev);
257 strlcpy(drvinfo->driver, alx_drv_name, sizeof(drvinfo->driver));
258 strlcpy(drvinfo->bus_info, pci_name(alx->hw.pdev),
259 sizeof(drvinfo->bus_info));
262 const struct ethtool_ops alx_ethtool_ops = {
263 .get_settings = alx_get_settings,
264 .set_settings = alx_set_settings,
265 .get_pauseparam = alx_get_pauseparam,
266 .set_pauseparam = alx_set_pauseparam,
267 .get_drvinfo = alx_get_drvinfo,
268 .get_msglevel = alx_get_msglevel,
269 .set_msglevel = alx_set_msglevel,
270 .get_wol = alx_get_wol,
271 .set_wol = alx_set_wol,
272 .get_link = ethtool_op_get_link,