2 * Copyright(c) 2009 - 2009 Atheros Corporation. All rights reserved.
4 * Derived from Intel e1000 driver
5 * Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved.
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)
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
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.
23 #include <linux/netdevice.h>
24 #include <linux/ethtool.h>
28 static int atl1c_get_settings(struct net_device
*netdev
,
29 struct ethtool_cmd
*ecmd
)
31 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
32 struct atl1c_hw
*hw
= &adapter
->hw
;
34 ecmd
->supported
= (SUPPORTED_10baseT_Half
|
35 SUPPORTED_10baseT_Full
|
36 SUPPORTED_100baseT_Half
|
37 SUPPORTED_100baseT_Full
|
40 if (hw
->ctrl_flags
& ATL1C_LINK_CAP_1000M
)
41 ecmd
->supported
|= SUPPORTED_1000baseT_Full
;
43 ecmd
->advertising
= ADVERTISED_TP
;
45 ecmd
->advertising
|= hw
->autoneg_advertised
;
48 ecmd
->phy_address
= 0;
49 ecmd
->transceiver
= XCVR_INTERNAL
;
51 if (adapter
->link_speed
!= SPEED_0
) {
52 ecmd
->speed
= adapter
->link_speed
;
53 if (adapter
->link_duplex
== FULL_DUPLEX
)
54 ecmd
->duplex
= DUPLEX_FULL
;
56 ecmd
->duplex
= DUPLEX_HALF
;
62 ecmd
->autoneg
= AUTONEG_ENABLE
;
66 static int atl1c_set_settings(struct net_device
*netdev
,
67 struct ethtool_cmd
*ecmd
)
69 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
70 struct atl1c_hw
*hw
= &adapter
->hw
;
71 u16 autoneg_advertised
;
73 while (test_and_set_bit(__AT_RESETTING
, &adapter
->flags
))
76 if (ecmd
->autoneg
== AUTONEG_ENABLE
) {
77 autoneg_advertised
= ADVERTISED_Autoneg
;
79 if (ecmd
->speed
== SPEED_1000
) {
80 if (ecmd
->duplex
!= DUPLEX_FULL
) {
81 if (netif_msg_link(adapter
))
82 dev_warn(&adapter
->pdev
->dev
,
83 "1000M half is invalid\n");
84 clear_bit(__AT_RESETTING
, &adapter
->flags
);
87 autoneg_advertised
= ADVERTISED_1000baseT_Full
;
88 } else if (ecmd
->speed
== SPEED_100
) {
89 if (ecmd
->duplex
== DUPLEX_FULL
)
90 autoneg_advertised
= ADVERTISED_100baseT_Full
;
92 autoneg_advertised
= ADVERTISED_100baseT_Half
;
94 if (ecmd
->duplex
== DUPLEX_FULL
)
95 autoneg_advertised
= ADVERTISED_10baseT_Full
;
97 autoneg_advertised
= ADVERTISED_10baseT_Half
;
101 if (hw
->autoneg_advertised
!= autoneg_advertised
) {
102 hw
->autoneg_advertised
= autoneg_advertised
;
103 if (atl1c_restart_autoneg(hw
) != 0) {
104 if (netif_msg_link(adapter
))
105 dev_warn(&adapter
->pdev
->dev
,
106 "ethtool speed/duplex setting failed\n");
107 clear_bit(__AT_RESETTING
, &adapter
->flags
);
111 clear_bit(__AT_RESETTING
, &adapter
->flags
);
115 static u32
atl1c_get_tx_csum(struct net_device
*netdev
)
117 return (netdev
->features
& NETIF_F_HW_CSUM
) != 0;
120 static u32
atl1c_get_msglevel(struct net_device
*netdev
)
122 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
123 return adapter
->msg_enable
;
126 static void atl1c_set_msglevel(struct net_device
*netdev
, u32 data
)
128 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
129 adapter
->msg_enable
= data
;
132 static int atl1c_get_regs_len(struct net_device
*netdev
)
137 static void atl1c_get_regs(struct net_device
*netdev
,
138 struct ethtool_regs
*regs
, void *p
)
140 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
141 struct atl1c_hw
*hw
= &adapter
->hw
;
145 memset(p
, 0, AT_REGS_LEN
);
148 AT_READ_REG(hw
, REG_VPD_CAP
, p
++);
149 AT_READ_REG(hw
, REG_PM_CTRL
, p
++);
150 AT_READ_REG(hw
, REG_MAC_HALF_DUPLX_CTRL
, p
++);
151 AT_READ_REG(hw
, REG_TWSI_CTRL
, p
++);
152 AT_READ_REG(hw
, REG_PCIE_DEV_MISC_CTRL
, p
++);
153 AT_READ_REG(hw
, REG_MASTER_CTRL
, p
++);
154 AT_READ_REG(hw
, REG_MANUAL_TIMER_INIT
, p
++);
155 AT_READ_REG(hw
, REG_IRQ_MODRT_TIMER_INIT
, p
++);
156 AT_READ_REG(hw
, REG_GPHY_CTRL
, p
++);
157 AT_READ_REG(hw
, REG_LINK_CTRL
, p
++);
158 AT_READ_REG(hw
, REG_IDLE_STATUS
, p
++);
159 AT_READ_REG(hw
, REG_MDIO_CTRL
, p
++);
160 AT_READ_REG(hw
, REG_SERDES_LOCK
, p
++);
161 AT_READ_REG(hw
, REG_MAC_CTRL
, p
++);
162 AT_READ_REG(hw
, REG_MAC_IPG_IFG
, p
++);
163 AT_READ_REG(hw
, REG_MAC_STA_ADDR
, p
++);
164 AT_READ_REG(hw
, REG_MAC_STA_ADDR
+4, p
++);
165 AT_READ_REG(hw
, REG_RX_HASH_TABLE
, p
++);
166 AT_READ_REG(hw
, REG_RX_HASH_TABLE
+4, p
++);
167 AT_READ_REG(hw
, REG_RXQ_CTRL
, p
++);
168 AT_READ_REG(hw
, REG_TXQ_CTRL
, p
++);
169 AT_READ_REG(hw
, REG_MTU
, p
++);
170 AT_READ_REG(hw
, REG_WOL_CTRL
, p
++);
172 atl1c_read_phy_reg(hw
, MII_BMCR
, &phy_data
);
173 regs_buff
[73] = (u32
) phy_data
;
174 atl1c_read_phy_reg(hw
, MII_BMSR
, &phy_data
);
175 regs_buff
[74] = (u32
) phy_data
;
178 static int atl1c_get_eeprom_len(struct net_device
*netdev
)
180 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
182 if (atl1c_check_eeprom_exist(&adapter
->hw
))
183 return AT_EEPROM_LEN
;
188 static int atl1c_get_eeprom(struct net_device
*netdev
,
189 struct ethtool_eeprom
*eeprom
, u8
*bytes
)
191 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
192 struct atl1c_hw
*hw
= &adapter
->hw
;
194 int first_dword
, last_dword
;
198 if (eeprom
->len
== 0)
201 if (!atl1c_check_eeprom_exist(hw
)) /* not exist */
204 eeprom
->magic
= adapter
->pdev
->vendor
|
205 (adapter
->pdev
->device
<< 16);
207 first_dword
= eeprom
->offset
>> 2;
208 last_dword
= (eeprom
->offset
+ eeprom
->len
- 1) >> 2;
210 eeprom_buff
= kmalloc(sizeof(u32
) *
211 (last_dword
- first_dword
+ 1), GFP_KERNEL
);
212 if (eeprom_buff
== NULL
)
215 for (i
= first_dword
; i
< last_dword
; i
++) {
216 if (!atl1c_read_eeprom(hw
, i
* 4, &(eeprom_buff
[i
-first_dword
]))) {
222 memcpy(bytes
, (u8
*)eeprom_buff
+ (eeprom
->offset
& 3),
230 static void atl1c_get_drvinfo(struct net_device
*netdev
,
231 struct ethtool_drvinfo
*drvinfo
)
233 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
235 strncpy(drvinfo
->driver
, atl1c_driver_name
, sizeof(drvinfo
->driver
));
236 strncpy(drvinfo
->version
, atl1c_driver_version
,
237 sizeof(drvinfo
->version
));
238 strncpy(drvinfo
->fw_version
, "N/A", sizeof(drvinfo
->fw_version
));
239 strncpy(drvinfo
->bus_info
, pci_name(adapter
->pdev
),
240 sizeof(drvinfo
->bus_info
));
241 drvinfo
->n_stats
= 0;
242 drvinfo
->testinfo_len
= 0;
243 drvinfo
->regdump_len
= atl1c_get_regs_len(netdev
);
244 drvinfo
->eedump_len
= atl1c_get_eeprom_len(netdev
);
247 static void atl1c_get_wol(struct net_device
*netdev
,
248 struct ethtool_wolinfo
*wol
)
250 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
252 wol
->supported
= WAKE_MAGIC
| WAKE_PHY
;
255 if (adapter
->wol
& AT_WUFC_EX
)
256 wol
->wolopts
|= WAKE_UCAST
;
257 if (adapter
->wol
& AT_WUFC_MC
)
258 wol
->wolopts
|= WAKE_MCAST
;
259 if (adapter
->wol
& AT_WUFC_BC
)
260 wol
->wolopts
|= WAKE_BCAST
;
261 if (adapter
->wol
& AT_WUFC_MAG
)
262 wol
->wolopts
|= WAKE_MAGIC
;
263 if (adapter
->wol
& AT_WUFC_LNKC
)
264 wol
->wolopts
|= WAKE_PHY
;
269 static int atl1c_set_wol(struct net_device
*netdev
, struct ethtool_wolinfo
*wol
)
271 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
273 if (wol
->wolopts
& (WAKE_ARP
| WAKE_MAGICSECURE
|
274 WAKE_UCAST
| WAKE_BCAST
| WAKE_MCAST
))
276 /* these settings will always override what we currently have */
279 if (wol
->wolopts
& WAKE_MAGIC
)
280 adapter
->wol
|= AT_WUFC_MAG
;
281 if (wol
->wolopts
& WAKE_PHY
)
282 adapter
->wol
|= AT_WUFC_LNKC
;
287 static int atl1c_nway_reset(struct net_device
*netdev
)
289 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
290 if (netif_running(netdev
))
291 atl1c_reinit_locked(adapter
);
295 static struct ethtool_ops atl1c_ethtool_ops
= {
296 .get_settings
= atl1c_get_settings
,
297 .set_settings
= atl1c_set_settings
,
298 .get_drvinfo
= atl1c_get_drvinfo
,
299 .get_regs_len
= atl1c_get_regs_len
,
300 .get_regs
= atl1c_get_regs
,
301 .get_wol
= atl1c_get_wol
,
302 .set_wol
= atl1c_set_wol
,
303 .get_msglevel
= atl1c_get_msglevel
,
304 .set_msglevel
= atl1c_set_msglevel
,
305 .nway_reset
= atl1c_nway_reset
,
306 .get_link
= ethtool_op_get_link
,
307 .get_eeprom_len
= atl1c_get_eeprom_len
,
308 .get_eeprom
= atl1c_get_eeprom
,
309 .get_tx_csum
= atl1c_get_tx_csum
,
310 .get_sg
= ethtool_op_get_sg
,
311 .set_sg
= ethtool_op_set_sg
,
314 void atl1c_set_ethtool_ops(struct net_device
*netdev
)
316 SET_ETHTOOL_OPS(netdev
, &atl1c_ethtool_ops
);