2 * Copyright(c) 2007 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>
25 #include <linux/slab.h>
29 static int atl1e_get_link_ksettings(struct net_device
*netdev
,
30 struct ethtool_link_ksettings
*cmd
)
32 struct atl1e_adapter
*adapter
= netdev_priv(netdev
);
33 struct atl1e_hw
*hw
= &adapter
->hw
;
34 u32 supported
, advertising
;
36 supported
= (SUPPORTED_10baseT_Half
|
37 SUPPORTED_10baseT_Full
|
38 SUPPORTED_100baseT_Half
|
39 SUPPORTED_100baseT_Full
|
42 if (hw
->nic_type
== athr_l1e
)
43 supported
|= SUPPORTED_1000baseT_Full
;
45 advertising
= ADVERTISED_TP
;
47 advertising
|= ADVERTISED_Autoneg
;
48 advertising
|= hw
->autoneg_advertised
;
50 cmd
->base
.port
= PORT_TP
;
51 cmd
->base
.phy_address
= 0;
53 if (adapter
->link_speed
!= SPEED_0
) {
54 cmd
->base
.speed
= adapter
->link_speed
;
55 if (adapter
->link_duplex
== FULL_DUPLEX
)
56 cmd
->base
.duplex
= DUPLEX_FULL
;
58 cmd
->base
.duplex
= DUPLEX_HALF
;
60 cmd
->base
.speed
= SPEED_UNKNOWN
;
61 cmd
->base
.duplex
= DUPLEX_UNKNOWN
;
64 cmd
->base
.autoneg
= AUTONEG_ENABLE
;
66 ethtool_convert_legacy_u32_to_link_mode(cmd
->link_modes
.supported
,
68 ethtool_convert_legacy_u32_to_link_mode(cmd
->link_modes
.advertising
,
74 static int atl1e_set_link_ksettings(struct net_device
*netdev
,
75 const struct ethtool_link_ksettings
*cmd
)
77 struct atl1e_adapter
*adapter
= netdev_priv(netdev
);
78 struct atl1e_hw
*hw
= &adapter
->hw
;
81 ethtool_convert_link_mode_to_legacy_u32(&advertising
,
82 cmd
->link_modes
.advertising
);
84 while (test_and_set_bit(__AT_RESETTING
, &adapter
->flags
))
87 if (cmd
->base
.autoneg
== AUTONEG_ENABLE
) {
90 if (advertising
& ADVERTISE_1000_FULL
) {
91 if (hw
->nic_type
== athr_l1e
) {
92 hw
->autoneg_advertised
=
93 advertising
& AT_ADV_MASK
;
95 clear_bit(__AT_RESETTING
, &adapter
->flags
);
98 } else if (advertising
& ADVERTISE_1000_HALF
) {
99 clear_bit(__AT_RESETTING
, &adapter
->flags
);
102 hw
->autoneg_advertised
=
103 advertising
& AT_ADV_MASK
;
105 advertising
= hw
->autoneg_advertised
|
106 ADVERTISED_TP
| ADVERTISED_Autoneg
;
108 adv4
= hw
->mii_autoneg_adv_reg
& ~ADVERTISE_ALL
;
109 adv9
= hw
->mii_1000t_ctrl_reg
& ~MII_AT001_CR_1000T_SPEED_MASK
;
110 if (hw
->autoneg_advertised
& ADVERTISE_10_HALF
)
111 adv4
|= ADVERTISE_10HALF
;
112 if (hw
->autoneg_advertised
& ADVERTISE_10_FULL
)
113 adv4
|= ADVERTISE_10FULL
;
114 if (hw
->autoneg_advertised
& ADVERTISE_100_HALF
)
115 adv4
|= ADVERTISE_100HALF
;
116 if (hw
->autoneg_advertised
& ADVERTISE_100_FULL
)
117 adv4
|= ADVERTISE_100FULL
;
118 if (hw
->autoneg_advertised
& ADVERTISE_1000_FULL
)
119 adv9
|= ADVERTISE_1000FULL
;
121 if (adv4
!= hw
->mii_autoneg_adv_reg
||
122 adv9
!= hw
->mii_1000t_ctrl_reg
) {
123 hw
->mii_autoneg_adv_reg
= adv4
;
124 hw
->mii_1000t_ctrl_reg
= adv9
;
125 hw
->re_autoneg
= true;
129 clear_bit(__AT_RESETTING
, &adapter
->flags
);
135 if (netif_running(adapter
->netdev
)) {
139 atl1e_reset_hw(&adapter
->hw
);
141 clear_bit(__AT_RESETTING
, &adapter
->flags
);
145 static u32
atl1e_get_msglevel(struct net_device
*netdev
)
154 static int atl1e_get_regs_len(struct net_device
*netdev
)
156 return AT_REGS_LEN
* sizeof(u32
);
159 static void atl1e_get_regs(struct net_device
*netdev
,
160 struct ethtool_regs
*regs
, void *p
)
162 struct atl1e_adapter
*adapter
= netdev_priv(netdev
);
163 struct atl1e_hw
*hw
= &adapter
->hw
;
167 memset(p
, 0, AT_REGS_LEN
* sizeof(u32
));
169 regs
->version
= (1 << 24) | (hw
->revision_id
<< 16) | hw
->device_id
;
171 regs_buff
[0] = AT_READ_REG(hw
, REG_VPD_CAP
);
172 regs_buff
[1] = AT_READ_REG(hw
, REG_SPI_FLASH_CTRL
);
173 regs_buff
[2] = AT_READ_REG(hw
, REG_SPI_FLASH_CONFIG
);
174 regs_buff
[3] = AT_READ_REG(hw
, REG_TWSI_CTRL
);
175 regs_buff
[4] = AT_READ_REG(hw
, REG_PCIE_DEV_MISC_CTRL
);
176 regs_buff
[5] = AT_READ_REG(hw
, REG_MASTER_CTRL
);
177 regs_buff
[6] = AT_READ_REG(hw
, REG_MANUAL_TIMER_INIT
);
178 regs_buff
[7] = AT_READ_REG(hw
, REG_IRQ_MODU_TIMER_INIT
);
179 regs_buff
[8] = AT_READ_REG(hw
, REG_GPHY_CTRL
);
180 regs_buff
[9] = AT_READ_REG(hw
, REG_CMBDISDMA_TIMER
);
181 regs_buff
[10] = AT_READ_REG(hw
, REG_IDLE_STATUS
);
182 regs_buff
[11] = AT_READ_REG(hw
, REG_MDIO_CTRL
);
183 regs_buff
[12] = AT_READ_REG(hw
, REG_SERDES_LOCK
);
184 regs_buff
[13] = AT_READ_REG(hw
, REG_MAC_CTRL
);
185 regs_buff
[14] = AT_READ_REG(hw
, REG_MAC_IPG_IFG
);
186 regs_buff
[15] = AT_READ_REG(hw
, REG_MAC_STA_ADDR
);
187 regs_buff
[16] = AT_READ_REG(hw
, REG_MAC_STA_ADDR
+4);
188 regs_buff
[17] = AT_READ_REG(hw
, REG_RX_HASH_TABLE
);
189 regs_buff
[18] = AT_READ_REG(hw
, REG_RX_HASH_TABLE
+4);
190 regs_buff
[19] = AT_READ_REG(hw
, REG_MAC_HALF_DUPLX_CTRL
);
191 regs_buff
[20] = AT_READ_REG(hw
, REG_MTU
);
192 regs_buff
[21] = AT_READ_REG(hw
, REG_WOL_CTRL
);
193 regs_buff
[22] = AT_READ_REG(hw
, REG_SRAM_TRD_ADDR
);
194 regs_buff
[23] = AT_READ_REG(hw
, REG_SRAM_TRD_LEN
);
195 regs_buff
[24] = AT_READ_REG(hw
, REG_SRAM_RXF_ADDR
);
196 regs_buff
[25] = AT_READ_REG(hw
, REG_SRAM_RXF_LEN
);
197 regs_buff
[26] = AT_READ_REG(hw
, REG_SRAM_TXF_ADDR
);
198 regs_buff
[27] = AT_READ_REG(hw
, REG_SRAM_TXF_LEN
);
199 regs_buff
[28] = AT_READ_REG(hw
, REG_SRAM_TCPH_ADDR
);
200 regs_buff
[29] = AT_READ_REG(hw
, REG_SRAM_PKTH_ADDR
);
202 atl1e_read_phy_reg(hw
, MII_BMCR
, &phy_data
);
203 regs_buff
[73] = (u32
)phy_data
;
204 atl1e_read_phy_reg(hw
, MII_BMSR
, &phy_data
);
205 regs_buff
[74] = (u32
)phy_data
;
208 static int atl1e_get_eeprom_len(struct net_device
*netdev
)
210 struct atl1e_adapter
*adapter
= netdev_priv(netdev
);
212 if (!atl1e_check_eeprom_exist(&adapter
->hw
))
213 return AT_EEPROM_LEN
;
218 static int atl1e_get_eeprom(struct net_device
*netdev
,
219 struct ethtool_eeprom
*eeprom
, u8
*bytes
)
221 struct atl1e_adapter
*adapter
= netdev_priv(netdev
);
222 struct atl1e_hw
*hw
= &adapter
->hw
;
224 int first_dword
, last_dword
;
228 if (eeprom
->len
== 0)
231 if (atl1e_check_eeprom_exist(hw
)) /* not exist */
234 eeprom
->magic
= hw
->vendor_id
| (hw
->device_id
<< 16);
236 first_dword
= eeprom
->offset
>> 2;
237 last_dword
= (eeprom
->offset
+ eeprom
->len
- 1) >> 2;
239 eeprom_buff
= kmalloc(sizeof(u32
) *
240 (last_dword
- first_dword
+ 1), GFP_KERNEL
);
241 if (eeprom_buff
== NULL
)
244 for (i
= first_dword
; i
< last_dword
; i
++) {
245 if (!atl1e_read_eeprom(hw
, i
* 4, &(eeprom_buff
[i
-first_dword
]))) {
251 memcpy(bytes
, (u8
*)eeprom_buff
+ (eeprom
->offset
& 3),
258 static int atl1e_set_eeprom(struct net_device
*netdev
,
259 struct ethtool_eeprom
*eeprom
, u8
*bytes
)
261 struct atl1e_adapter
*adapter
= netdev_priv(netdev
);
262 struct atl1e_hw
*hw
= &adapter
->hw
;
265 int first_dword
, last_dword
;
269 if (eeprom
->len
== 0)
272 if (eeprom
->magic
!= (hw
->vendor_id
| (hw
->device_id
<< 16)))
275 first_dword
= eeprom
->offset
>> 2;
276 last_dword
= (eeprom
->offset
+ eeprom
->len
- 1) >> 2;
277 eeprom_buff
= kmalloc(AT_EEPROM_LEN
, GFP_KERNEL
);
278 if (eeprom_buff
== NULL
)
283 if (eeprom
->offset
& 3) {
284 /* need read/modify/write of first changed EEPROM word */
285 /* only the second byte of the word is being modified */
286 if (!atl1e_read_eeprom(hw
, first_dword
* 4, &(eeprom_buff
[0]))) {
292 if (((eeprom
->offset
+ eeprom
->len
) & 3)) {
293 /* need read/modify/write of last changed EEPROM word */
294 /* only the first byte of the word is being modified */
296 if (!atl1e_read_eeprom(hw
, last_dword
* 4,
297 &(eeprom_buff
[last_dword
- first_dword
]))) {
303 /* Device's eeprom is always little-endian, word addressable */
304 memcpy(ptr
, bytes
, eeprom
->len
);
306 for (i
= 0; i
< last_dword
- first_dword
+ 1; i
++) {
307 if (!atl1e_write_eeprom(hw
, ((first_dword
+ i
) * 4),
318 static void atl1e_get_drvinfo(struct net_device
*netdev
,
319 struct ethtool_drvinfo
*drvinfo
)
321 struct atl1e_adapter
*adapter
= netdev_priv(netdev
);
323 strlcpy(drvinfo
->driver
, atl1e_driver_name
, sizeof(drvinfo
->driver
));
324 strlcpy(drvinfo
->version
, atl1e_driver_version
,
325 sizeof(drvinfo
->version
));
326 strlcpy(drvinfo
->fw_version
, "L1e", sizeof(drvinfo
->fw_version
));
327 strlcpy(drvinfo
->bus_info
, pci_name(adapter
->pdev
),
328 sizeof(drvinfo
->bus_info
));
331 static void atl1e_get_wol(struct net_device
*netdev
,
332 struct ethtool_wolinfo
*wol
)
334 struct atl1e_adapter
*adapter
= netdev_priv(netdev
);
336 wol
->supported
= WAKE_MAGIC
| WAKE_PHY
;
339 if (adapter
->wol
& AT_WUFC_EX
)
340 wol
->wolopts
|= WAKE_UCAST
;
341 if (adapter
->wol
& AT_WUFC_MC
)
342 wol
->wolopts
|= WAKE_MCAST
;
343 if (adapter
->wol
& AT_WUFC_BC
)
344 wol
->wolopts
|= WAKE_BCAST
;
345 if (adapter
->wol
& AT_WUFC_MAG
)
346 wol
->wolopts
|= WAKE_MAGIC
;
347 if (adapter
->wol
& AT_WUFC_LNKC
)
348 wol
->wolopts
|= WAKE_PHY
;
351 static int atl1e_set_wol(struct net_device
*netdev
, struct ethtool_wolinfo
*wol
)
353 struct atl1e_adapter
*adapter
= netdev_priv(netdev
);
355 if (wol
->wolopts
& (WAKE_ARP
| WAKE_MAGICSECURE
|
356 WAKE_UCAST
| WAKE_MCAST
| WAKE_BCAST
))
358 /* these settings will always override what we currently have */
361 if (wol
->wolopts
& WAKE_MAGIC
)
362 adapter
->wol
|= AT_WUFC_MAG
;
363 if (wol
->wolopts
& WAKE_PHY
)
364 adapter
->wol
|= AT_WUFC_LNKC
;
366 device_set_wakeup_enable(&adapter
->pdev
->dev
, adapter
->wol
);
371 static int atl1e_nway_reset(struct net_device
*netdev
)
373 struct atl1e_adapter
*adapter
= netdev_priv(netdev
);
374 if (netif_running(netdev
))
375 atl1e_reinit_locked(adapter
);
379 static const struct ethtool_ops atl1e_ethtool_ops
= {
380 .get_drvinfo
= atl1e_get_drvinfo
,
381 .get_regs_len
= atl1e_get_regs_len
,
382 .get_regs
= atl1e_get_regs
,
383 .get_wol
= atl1e_get_wol
,
384 .set_wol
= atl1e_set_wol
,
385 .get_msglevel
= atl1e_get_msglevel
,
386 .nway_reset
= atl1e_nway_reset
,
387 .get_link
= ethtool_op_get_link
,
388 .get_eeprom_len
= atl1e_get_eeprom_len
,
389 .get_eeprom
= atl1e_get_eeprom
,
390 .set_eeprom
= atl1e_set_eeprom
,
391 .get_link_ksettings
= atl1e_get_link_ksettings
,
392 .set_link_ksettings
= atl1e_set_link_ksettings
,
395 void atl1e_set_ethtool_ops(struct net_device
*netdev
)
397 netdev
->ethtool_ops
= &atl1e_ethtool_ops
;