include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[linux-2.6-block.git] / drivers / net / atl1c / atl1c_ethtool.c
CommitLineData
43250ddd
JY
1/*
2 * Copyright(c) 2009 - 2009 Atheros Corporation. All rights reserved.
3 *
4 * Derived from Intel e1000 driver
5 * Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved.
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; either version 2 of the License, or (at your option)
10 * any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc., 59
19 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 *
21 */
22
23#include <linux/netdevice.h>
24#include <linux/ethtool.h>
5a0e3ad6 25#include <linux/slab.h>
43250ddd
JY
26
27#include "atl1c.h"
28
29static int atl1c_get_settings(struct net_device *netdev,
30 struct ethtool_cmd *ecmd)
31{
32 struct atl1c_adapter *adapter = netdev_priv(netdev);
33 struct atl1c_hw *hw = &adapter->hw;
34
35 ecmd->supported = (SUPPORTED_10baseT_Half |
36 SUPPORTED_10baseT_Full |
37 SUPPORTED_100baseT_Half |
38 SUPPORTED_100baseT_Full |
39 SUPPORTED_Autoneg |
40 SUPPORTED_TP);
496c185c 41 if (hw->link_cap_flags & ATL1C_LINK_CAP_1000M)
43250ddd
JY
42 ecmd->supported |= SUPPORTED_1000baseT_Full;
43
44 ecmd->advertising = ADVERTISED_TP;
45
46 ecmd->advertising |= hw->autoneg_advertised;
47
48 ecmd->port = PORT_TP;
49 ecmd->phy_address = 0;
50 ecmd->transceiver = XCVR_INTERNAL;
51
52 if (adapter->link_speed != SPEED_0) {
53 ecmd->speed = adapter->link_speed;
54 if (adapter->link_duplex == FULL_DUPLEX)
55 ecmd->duplex = DUPLEX_FULL;
56 else
57 ecmd->duplex = DUPLEX_HALF;
58 } else {
59 ecmd->speed = -1;
60 ecmd->duplex = -1;
61 }
62
63 ecmd->autoneg = AUTONEG_ENABLE;
64 return 0;
65}
66
67static int atl1c_set_settings(struct net_device *netdev,
68 struct ethtool_cmd *ecmd)
69{
70 struct atl1c_adapter *adapter = netdev_priv(netdev);
71 struct atl1c_hw *hw = &adapter->hw;
72 u16 autoneg_advertised;
73
74 while (test_and_set_bit(__AT_RESETTING, &adapter->flags))
75 msleep(1);
76
77 if (ecmd->autoneg == AUTONEG_ENABLE) {
78 autoneg_advertised = ADVERTISED_Autoneg;
79 } else {
80 if (ecmd->speed == SPEED_1000) {
81 if (ecmd->duplex != DUPLEX_FULL) {
82 if (netif_msg_link(adapter))
83 dev_warn(&adapter->pdev->dev,
84 "1000M half is invalid\n");
85 clear_bit(__AT_RESETTING, &adapter->flags);
86 return -EINVAL;
87 }
88 autoneg_advertised = ADVERTISED_1000baseT_Full;
89 } else if (ecmd->speed == SPEED_100) {
90 if (ecmd->duplex == DUPLEX_FULL)
91 autoneg_advertised = ADVERTISED_100baseT_Full;
92 else
93 autoneg_advertised = ADVERTISED_100baseT_Half;
94 } else {
95 if (ecmd->duplex == DUPLEX_FULL)
96 autoneg_advertised = ADVERTISED_10baseT_Full;
97 else
98 autoneg_advertised = ADVERTISED_10baseT_Half;
99 }
100 }
101
102 if (hw->autoneg_advertised != autoneg_advertised) {
103 hw->autoneg_advertised = autoneg_advertised;
104 if (atl1c_restart_autoneg(hw) != 0) {
105 if (netif_msg_link(adapter))
106 dev_warn(&adapter->pdev->dev,
107 "ethtool speed/duplex setting failed\n");
108 clear_bit(__AT_RESETTING, &adapter->flags);
109 return -EINVAL;
110 }
111 }
112 clear_bit(__AT_RESETTING, &adapter->flags);
113 return 0;
114}
115
116static u32 atl1c_get_tx_csum(struct net_device *netdev)
117{
118 return (netdev->features & NETIF_F_HW_CSUM) != 0;
119}
120
121static u32 atl1c_get_msglevel(struct net_device *netdev)
122{
123 struct atl1c_adapter *adapter = netdev_priv(netdev);
124 return adapter->msg_enable;
125}
126
127static void atl1c_set_msglevel(struct net_device *netdev, u32 data)
128{
129 struct atl1c_adapter *adapter = netdev_priv(netdev);
130 adapter->msg_enable = data;
131}
132
133static int atl1c_get_regs_len(struct net_device *netdev)
134{
135 return AT_REGS_LEN;
136}
137
138static void atl1c_get_regs(struct net_device *netdev,
139 struct ethtool_regs *regs, void *p)
140{
141 struct atl1c_adapter *adapter = netdev_priv(netdev);
142 struct atl1c_hw *hw = &adapter->hw;
143 u32 *regs_buff = p;
144 u16 phy_data;
145
146 memset(p, 0, AT_REGS_LEN);
147
148 regs->version = 0;
149 AT_READ_REG(hw, REG_VPD_CAP, p++);
150 AT_READ_REG(hw, REG_PM_CTRL, p++);
151 AT_READ_REG(hw, REG_MAC_HALF_DUPLX_CTRL, p++);
152 AT_READ_REG(hw, REG_TWSI_CTRL, p++);
153 AT_READ_REG(hw, REG_PCIE_DEV_MISC_CTRL, p++);
154 AT_READ_REG(hw, REG_MASTER_CTRL, p++);
155 AT_READ_REG(hw, REG_MANUAL_TIMER_INIT, p++);
156 AT_READ_REG(hw, REG_IRQ_MODRT_TIMER_INIT, p++);
157 AT_READ_REG(hw, REG_GPHY_CTRL, p++);
158 AT_READ_REG(hw, REG_LINK_CTRL, p++);
159 AT_READ_REG(hw, REG_IDLE_STATUS, p++);
160 AT_READ_REG(hw, REG_MDIO_CTRL, p++);
161 AT_READ_REG(hw, REG_SERDES_LOCK, p++);
162 AT_READ_REG(hw, REG_MAC_CTRL, p++);
163 AT_READ_REG(hw, REG_MAC_IPG_IFG, p++);
164 AT_READ_REG(hw, REG_MAC_STA_ADDR, p++);
165 AT_READ_REG(hw, REG_MAC_STA_ADDR+4, p++);
166 AT_READ_REG(hw, REG_RX_HASH_TABLE, p++);
167 AT_READ_REG(hw, REG_RX_HASH_TABLE+4, p++);
168 AT_READ_REG(hw, REG_RXQ_CTRL, p++);
169 AT_READ_REG(hw, REG_TXQ_CTRL, p++);
170 AT_READ_REG(hw, REG_MTU, p++);
171 AT_READ_REG(hw, REG_WOL_CTRL, p++);
172
173 atl1c_read_phy_reg(hw, MII_BMCR, &phy_data);
174 regs_buff[73] = (u32) phy_data;
175 atl1c_read_phy_reg(hw, MII_BMSR, &phy_data);
176 regs_buff[74] = (u32) phy_data;
177}
178
179static int atl1c_get_eeprom_len(struct net_device *netdev)
180{
181 struct atl1c_adapter *adapter = netdev_priv(netdev);
182
183 if (atl1c_check_eeprom_exist(&adapter->hw))
184 return AT_EEPROM_LEN;
185 else
186 return 0;
187}
188
189static int atl1c_get_eeprom(struct net_device *netdev,
190 struct ethtool_eeprom *eeprom, u8 *bytes)
191{
192 struct atl1c_adapter *adapter = netdev_priv(netdev);
193 struct atl1c_hw *hw = &adapter->hw;
194 u32 *eeprom_buff;
195 int first_dword, last_dword;
196 int ret_val = 0;
197 int i;
198
199 if (eeprom->len == 0)
200 return -EINVAL;
201
202 if (!atl1c_check_eeprom_exist(hw)) /* not exist */
203 return -EINVAL;
204
205 eeprom->magic = adapter->pdev->vendor |
206 (adapter->pdev->device << 16);
207
208 first_dword = eeprom->offset >> 2;
209 last_dword = (eeprom->offset + eeprom->len - 1) >> 2;
210
211 eeprom_buff = kmalloc(sizeof(u32) *
212 (last_dword - first_dword + 1), GFP_KERNEL);
213 if (eeprom_buff == NULL)
214 return -ENOMEM;
215
216 for (i = first_dword; i < last_dword; i++) {
217 if (!atl1c_read_eeprom(hw, i * 4, &(eeprom_buff[i-first_dword]))) {
218 kfree(eeprom_buff);
219 return -EIO;
220 }
221 }
222
223 memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 3),
224 eeprom->len);
225 kfree(eeprom_buff);
226
227 return ret_val;
228 return 0;
229}
230
231static void atl1c_get_drvinfo(struct net_device *netdev,
232 struct ethtool_drvinfo *drvinfo)
233{
234 struct atl1c_adapter *adapter = netdev_priv(netdev);
235
082ba88a
RK
236 strlcpy(drvinfo->driver, atl1c_driver_name, sizeof(drvinfo->driver));
237 strlcpy(drvinfo->version, atl1c_driver_version,
43250ddd 238 sizeof(drvinfo->version));
082ba88a
RK
239 strlcpy(drvinfo->fw_version, "N/A", sizeof(drvinfo->fw_version));
240 strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
43250ddd
JY
241 sizeof(drvinfo->bus_info));
242 drvinfo->n_stats = 0;
243 drvinfo->testinfo_len = 0;
244 drvinfo->regdump_len = atl1c_get_regs_len(netdev);
245 drvinfo->eedump_len = atl1c_get_eeprom_len(netdev);
246}
247
248static void atl1c_get_wol(struct net_device *netdev,
249 struct ethtool_wolinfo *wol)
250{
251 struct atl1c_adapter *adapter = netdev_priv(netdev);
252
253 wol->supported = WAKE_MAGIC | WAKE_PHY;
254 wol->wolopts = 0;
255
256 if (adapter->wol & AT_WUFC_EX)
257 wol->wolopts |= WAKE_UCAST;
258 if (adapter->wol & AT_WUFC_MC)
259 wol->wolopts |= WAKE_MCAST;
260 if (adapter->wol & AT_WUFC_BC)
261 wol->wolopts |= WAKE_BCAST;
262 if (adapter->wol & AT_WUFC_MAG)
263 wol->wolopts |= WAKE_MAGIC;
264 if (adapter->wol & AT_WUFC_LNKC)
265 wol->wolopts |= WAKE_PHY;
266
267 return;
268}
269
270static int atl1c_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
271{
272 struct atl1c_adapter *adapter = netdev_priv(netdev);
273
274 if (wol->wolopts & (WAKE_ARP | WAKE_MAGICSECURE |
0ed586d0 275 WAKE_UCAST | WAKE_BCAST | WAKE_MCAST))
43250ddd
JY
276 return -EOPNOTSUPP;
277 /* these settings will always override what we currently have */
278 adapter->wol = 0;
279
280 if (wol->wolopts & WAKE_MAGIC)
281 adapter->wol |= AT_WUFC_MAG;
282 if (wol->wolopts & WAKE_PHY)
283 adapter->wol |= AT_WUFC_LNKC;
284
d8146bb2
BP
285 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
286
43250ddd
JY
287 return 0;
288}
289
290static int atl1c_nway_reset(struct net_device *netdev)
291{
292 struct atl1c_adapter *adapter = netdev_priv(netdev);
293 if (netif_running(netdev))
294 atl1c_reinit_locked(adapter);
295 return 0;
296}
297
0fc0b732 298static const struct ethtool_ops atl1c_ethtool_ops = {
43250ddd
JY
299 .get_settings = atl1c_get_settings,
300 .set_settings = atl1c_set_settings,
301 .get_drvinfo = atl1c_get_drvinfo,
302 .get_regs_len = atl1c_get_regs_len,
303 .get_regs = atl1c_get_regs,
304 .get_wol = atl1c_get_wol,
305 .set_wol = atl1c_set_wol,
306 .get_msglevel = atl1c_get_msglevel,
307 .set_msglevel = atl1c_set_msglevel,
308 .nway_reset = atl1c_nway_reset,
309 .get_link = ethtool_op_get_link,
310 .get_eeprom_len = atl1c_get_eeprom_len,
311 .get_eeprom = atl1c_get_eeprom,
312 .get_tx_csum = atl1c_get_tx_csum,
313 .get_sg = ethtool_op_get_sg,
314 .set_sg = ethtool_op_set_sg,
315};
316
317void atl1c_set_ethtool_ops(struct net_device *netdev)
318{
319 SET_ETHTOOL_OPS(netdev, &atl1c_ethtool_ops);
320}