1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright(c) 2009 - 2009 Atheros Corporation. All rights reserved.
5 * Derived from Intel e1000 driver
6 * Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved.
9 #include <linux/netdevice.h>
10 #include <linux/ethtool.h>
11 #include <linux/slab.h>
15 static int atl1c_get_link_ksettings(struct net_device
*netdev
,
16 struct ethtool_link_ksettings
*cmd
)
18 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
19 struct atl1c_hw
*hw
= &adapter
->hw
;
20 u32 supported
, advertising
;
22 supported
= (SUPPORTED_10baseT_Half
|
23 SUPPORTED_10baseT_Full
|
24 SUPPORTED_100baseT_Half
|
25 SUPPORTED_100baseT_Full
|
28 if (hw
->link_cap_flags
& ATL1C_LINK_CAP_1000M
)
29 supported
|= SUPPORTED_1000baseT_Full
;
31 advertising
= ADVERTISED_TP
;
33 advertising
|= hw
->autoneg_advertised
;
35 cmd
->base
.port
= PORT_TP
;
36 cmd
->base
.phy_address
= 0;
38 if (adapter
->link_speed
!= SPEED_0
) {
39 cmd
->base
.speed
= adapter
->link_speed
;
40 if (adapter
->link_duplex
== FULL_DUPLEX
)
41 cmd
->base
.duplex
= DUPLEX_FULL
;
43 cmd
->base
.duplex
= DUPLEX_HALF
;
45 cmd
->base
.speed
= SPEED_UNKNOWN
;
46 cmd
->base
.duplex
= DUPLEX_UNKNOWN
;
49 cmd
->base
.autoneg
= AUTONEG_ENABLE
;
51 ethtool_convert_legacy_u32_to_link_mode(cmd
->link_modes
.supported
,
53 ethtool_convert_legacy_u32_to_link_mode(cmd
->link_modes
.advertising
,
59 static int atl1c_set_link_ksettings(struct net_device
*netdev
,
60 const struct ethtool_link_ksettings
*cmd
)
62 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
63 struct atl1c_hw
*hw
= &adapter
->hw
;
64 u16 autoneg_advertised
;
66 while (test_and_set_bit(__AT_RESETTING
, &adapter
->flags
))
69 if (cmd
->base
.autoneg
== AUTONEG_ENABLE
) {
70 autoneg_advertised
= ADVERTISED_Autoneg
;
72 u32 speed
= cmd
->base
.speed
;
73 if (speed
== SPEED_1000
) {
74 if (cmd
->base
.duplex
!= DUPLEX_FULL
) {
75 if (netif_msg_link(adapter
))
76 dev_warn(&adapter
->pdev
->dev
,
77 "1000M half is invalid\n");
78 clear_bit(__AT_RESETTING
, &adapter
->flags
);
81 autoneg_advertised
= ADVERTISED_1000baseT_Full
;
82 } else if (speed
== SPEED_100
) {
83 if (cmd
->base
.duplex
== DUPLEX_FULL
)
84 autoneg_advertised
= ADVERTISED_100baseT_Full
;
86 autoneg_advertised
= ADVERTISED_100baseT_Half
;
88 if (cmd
->base
.duplex
== DUPLEX_FULL
)
89 autoneg_advertised
= ADVERTISED_10baseT_Full
;
91 autoneg_advertised
= ADVERTISED_10baseT_Half
;
95 if (hw
->autoneg_advertised
!= autoneg_advertised
) {
96 hw
->autoneg_advertised
= autoneg_advertised
;
97 if (atl1c_restart_autoneg(hw
) != 0) {
98 if (netif_msg_link(adapter
))
99 dev_warn(&adapter
->pdev
->dev
,
100 "ethtool speed/duplex setting failed\n");
101 clear_bit(__AT_RESETTING
, &adapter
->flags
);
105 clear_bit(__AT_RESETTING
, &adapter
->flags
);
109 static u32
atl1c_get_msglevel(struct net_device
*netdev
)
111 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
112 return adapter
->msg_enable
;
115 static void atl1c_set_msglevel(struct net_device
*netdev
, u32 data
)
117 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
118 adapter
->msg_enable
= data
;
121 static int atl1c_get_regs_len(struct net_device
*netdev
)
126 static void atl1c_get_regs(struct net_device
*netdev
,
127 struct ethtool_regs
*regs
, void *p
)
129 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
130 struct atl1c_hw
*hw
= &adapter
->hw
;
134 memset(p
, 0, AT_REGS_LEN
);
137 AT_READ_REG(hw
, REG_PM_CTRL
, p
++);
138 AT_READ_REG(hw
, REG_MAC_HALF_DUPLX_CTRL
, p
++);
139 AT_READ_REG(hw
, REG_TWSI_CTRL
, p
++);
140 AT_READ_REG(hw
, REG_PCIE_DEV_MISC_CTRL
, p
++);
141 AT_READ_REG(hw
, REG_MASTER_CTRL
, p
++);
142 AT_READ_REG(hw
, REG_MANUAL_TIMER_INIT
, p
++);
143 AT_READ_REG(hw
, REG_IRQ_MODRT_TIMER_INIT
, p
++);
144 AT_READ_REG(hw
, REG_GPHY_CTRL
, p
++);
145 AT_READ_REG(hw
, REG_LINK_CTRL
, p
++);
146 AT_READ_REG(hw
, REG_IDLE_STATUS
, p
++);
147 AT_READ_REG(hw
, REG_MDIO_CTRL
, p
++);
148 AT_READ_REG(hw
, REG_SERDES
, p
++);
149 AT_READ_REG(hw
, REG_MAC_CTRL
, p
++);
150 AT_READ_REG(hw
, REG_MAC_IPG_IFG
, p
++);
151 AT_READ_REG(hw
, REG_MAC_STA_ADDR
, p
++);
152 AT_READ_REG(hw
, REG_MAC_STA_ADDR
+4, p
++);
153 AT_READ_REG(hw
, REG_RX_HASH_TABLE
, p
++);
154 AT_READ_REG(hw
, REG_RX_HASH_TABLE
+4, p
++);
155 AT_READ_REG(hw
, REG_RXQ_CTRL
, p
++);
156 AT_READ_REG(hw
, REG_TXQ_CTRL
, p
++);
157 AT_READ_REG(hw
, REG_MTU
, p
++);
158 AT_READ_REG(hw
, REG_WOL_CTRL
, p
++);
160 atl1c_read_phy_reg(hw
, MII_BMCR
, &phy_data
);
161 regs_buff
[AT_REGS_LEN
/sizeof(u32
) - 2] = (u32
) phy_data
;
162 atl1c_read_phy_reg(hw
, MII_BMSR
, &phy_data
);
163 regs_buff
[AT_REGS_LEN
/sizeof(u32
) - 1] = (u32
) phy_data
;
166 static int atl1c_get_eeprom_len(struct net_device
*netdev
)
168 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
170 if (atl1c_check_eeprom_exist(&adapter
->hw
))
171 return AT_EEPROM_LEN
;
176 static int atl1c_get_eeprom(struct net_device
*netdev
,
177 struct ethtool_eeprom
*eeprom
, u8
*bytes
)
179 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
180 struct atl1c_hw
*hw
= &adapter
->hw
;
182 int first_dword
, last_dword
;
186 if (eeprom
->len
== 0)
189 if (!atl1c_check_eeprom_exist(hw
)) /* not exist */
192 eeprom
->magic
= adapter
->pdev
->vendor
|
193 (adapter
->pdev
->device
<< 16);
195 first_dword
= eeprom
->offset
>> 2;
196 last_dword
= (eeprom
->offset
+ eeprom
->len
- 1) >> 2;
198 eeprom_buff
= kmalloc_array(last_dword
- first_dword
+ 1, sizeof(u32
),
200 if (eeprom_buff
== NULL
)
203 for (i
= first_dword
; i
< last_dword
; i
++) {
204 if (!atl1c_read_eeprom(hw
, i
* 4, &(eeprom_buff
[i
-first_dword
]))) {
210 memcpy(bytes
, (u8
*)eeprom_buff
+ (eeprom
->offset
& 3),
218 static void atl1c_get_drvinfo(struct net_device
*netdev
,
219 struct ethtool_drvinfo
*drvinfo
)
221 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
223 strscpy(drvinfo
->driver
, atl1c_driver_name
, sizeof(drvinfo
->driver
));
224 strscpy(drvinfo
->bus_info
, pci_name(adapter
->pdev
),
225 sizeof(drvinfo
->bus_info
));
228 static void atl1c_get_wol(struct net_device
*netdev
,
229 struct ethtool_wolinfo
*wol
)
231 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
233 wol
->supported
= WAKE_MAGIC
| WAKE_PHY
;
236 if (adapter
->wol
& AT_WUFC_EX
)
237 wol
->wolopts
|= WAKE_UCAST
;
238 if (adapter
->wol
& AT_WUFC_MC
)
239 wol
->wolopts
|= WAKE_MCAST
;
240 if (adapter
->wol
& AT_WUFC_BC
)
241 wol
->wolopts
|= WAKE_BCAST
;
242 if (adapter
->wol
& AT_WUFC_MAG
)
243 wol
->wolopts
|= WAKE_MAGIC
;
244 if (adapter
->wol
& AT_WUFC_LNKC
)
245 wol
->wolopts
|= WAKE_PHY
;
248 static int atl1c_set_wol(struct net_device
*netdev
, struct ethtool_wolinfo
*wol
)
250 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
252 if (wol
->wolopts
& (WAKE_ARP
| WAKE_MAGICSECURE
|
253 WAKE_UCAST
| WAKE_BCAST
| WAKE_MCAST
))
255 /* these settings will always override what we currently have */
258 if (wol
->wolopts
& WAKE_MAGIC
)
259 adapter
->wol
|= AT_WUFC_MAG
;
260 if (wol
->wolopts
& WAKE_PHY
)
261 adapter
->wol
|= AT_WUFC_LNKC
;
263 device_set_wakeup_enable(&adapter
->pdev
->dev
, adapter
->wol
);
268 static int atl1c_nway_reset(struct net_device
*netdev
)
270 struct atl1c_adapter
*adapter
= netdev_priv(netdev
);
271 if (netif_running(netdev
))
272 atl1c_reinit_locked(adapter
);
276 static const struct ethtool_ops atl1c_ethtool_ops
= {
277 .get_drvinfo
= atl1c_get_drvinfo
,
278 .get_regs_len
= atl1c_get_regs_len
,
279 .get_regs
= atl1c_get_regs
,
280 .get_wol
= atl1c_get_wol
,
281 .set_wol
= atl1c_set_wol
,
282 .get_msglevel
= atl1c_get_msglevel
,
283 .set_msglevel
= atl1c_set_msglevel
,
284 .nway_reset
= atl1c_nway_reset
,
285 .get_link
= ethtool_op_get_link
,
286 .get_eeprom_len
= atl1c_get_eeprom_len
,
287 .get_eeprom
= atl1c_get_eeprom
,
288 .get_link_ksettings
= atl1c_get_link_ksettings
,
289 .set_link_ksettings
= atl1c_set_link_ksettings
,
292 void atl1c_set_ethtool_ops(struct net_device
*netdev
)
294 netdev
->ethtool_ops
= &atl1c_ethtool_ops
;