| 1 |
// SPDX-License-Identifier: GPL-2.0 |
| 2 |
/* Copyright(c) 1999 - 2006 Intel Corporation. */ |
| 3 |
|
| 4 |
/* ethtool support for e1000 */ |
| 5 |
|
| 6 |
#include "e1000.h" |
| 7 |
#include <linux/jiffies.h> |
| 8 |
#include <linux/uaccess.h> |
| 9 |
|
| 10 |
enum {NETDEV_STATS, E1000_STATS}; |
| 11 |
|
| 12 |
struct e1000_stats { |
| 13 |
char stat_string[ETH_GSTRING_LEN]; |
| 14 |
int type; |
| 15 |
int sizeof_stat; |
| 16 |
int stat_offset; |
| 17 |
}; |
| 18 |
|
| 19 |
#define E1000_STAT(m) E1000_STATS, \ |
| 20 |
sizeof(((struct e1000_adapter *)0)->m), \ |
| 21 |
offsetof(struct e1000_adapter, m) |
| 22 |
#define E1000_NETDEV_STAT(m) NETDEV_STATS, \ |
| 23 |
sizeof(((struct net_device *)0)->m), \ |
| 24 |
offsetof(struct net_device, m) |
| 25 |
|
| 26 |
static const struct e1000_stats e1000_gstrings_stats[] = { |
| 27 |
{ "rx_packets", E1000_STAT(stats.gprc) }, |
| 28 |
{ "tx_packets", E1000_STAT(stats.gptc) }, |
| 29 |
{ "rx_bytes", E1000_STAT(stats.gorcl) }, |
| 30 |
{ "tx_bytes", E1000_STAT(stats.gotcl) }, |
| 31 |
{ "rx_broadcast", E1000_STAT(stats.bprc) }, |
| 32 |
{ "tx_broadcast", E1000_STAT(stats.bptc) }, |
| 33 |
{ "rx_multicast", E1000_STAT(stats.mprc) }, |
| 34 |
{ "tx_multicast", E1000_STAT(stats.mptc) }, |
| 35 |
{ "rx_errors", E1000_STAT(stats.rxerrc) }, |
| 36 |
{ "tx_errors", E1000_STAT(stats.txerrc) }, |
| 37 |
{ "tx_dropped", E1000_NETDEV_STAT(stats.tx_dropped) }, |
| 38 |
{ "multicast", E1000_STAT(stats.mprc) }, |
| 39 |
{ "collisions", E1000_STAT(stats.colc) }, |
| 40 |
{ "rx_length_errors", E1000_STAT(stats.rlerrc) }, |
| 41 |
{ "rx_over_errors", E1000_NETDEV_STAT(stats.rx_over_errors) }, |
| 42 |
{ "rx_crc_errors", E1000_STAT(stats.crcerrs) }, |
| 43 |
{ "rx_frame_errors", E1000_NETDEV_STAT(stats.rx_frame_errors) }, |
| 44 |
{ "rx_no_buffer_count", E1000_STAT(stats.rnbc) }, |
| 45 |
{ "rx_missed_errors", E1000_STAT(stats.mpc) }, |
| 46 |
{ "tx_aborted_errors", E1000_STAT(stats.ecol) }, |
| 47 |
{ "tx_carrier_errors", E1000_STAT(stats.tncrs) }, |
| 48 |
{ "tx_fifo_errors", E1000_NETDEV_STAT(stats.tx_fifo_errors) }, |
| 49 |
{ "tx_heartbeat_errors", E1000_NETDEV_STAT(stats.tx_heartbeat_errors) }, |
| 50 |
{ "tx_window_errors", E1000_STAT(stats.latecol) }, |
| 51 |
{ "tx_abort_late_coll", E1000_STAT(stats.latecol) }, |
| 52 |
{ "tx_deferred_ok", E1000_STAT(stats.dc) }, |
| 53 |
{ "tx_single_coll_ok", E1000_STAT(stats.scc) }, |
| 54 |
{ "tx_multi_coll_ok", E1000_STAT(stats.mcc) }, |
| 55 |
{ "tx_timeout_count", E1000_STAT(tx_timeout_count) }, |
| 56 |
{ "tx_restart_queue", E1000_STAT(restart_queue) }, |
| 57 |
{ "rx_long_length_errors", E1000_STAT(stats.roc) }, |
| 58 |
{ "rx_short_length_errors", E1000_STAT(stats.ruc) }, |
| 59 |
{ "rx_align_errors", E1000_STAT(stats.algnerrc) }, |
| 60 |
{ "tx_tcp_seg_good", E1000_STAT(stats.tsctc) }, |
| 61 |
{ "tx_tcp_seg_failed", E1000_STAT(stats.tsctfc) }, |
| 62 |
{ "rx_flow_control_xon", E1000_STAT(stats.xonrxc) }, |
| 63 |
{ "rx_flow_control_xoff", E1000_STAT(stats.xoffrxc) }, |
| 64 |
{ "tx_flow_control_xon", E1000_STAT(stats.xontxc) }, |
| 65 |
{ "tx_flow_control_xoff", E1000_STAT(stats.xofftxc) }, |
| 66 |
{ "rx_long_byte_count", E1000_STAT(stats.gorcl) }, |
| 67 |
{ "rx_csum_offload_good", E1000_STAT(hw_csum_good) }, |
| 68 |
{ "rx_csum_offload_errors", E1000_STAT(hw_csum_err) }, |
| 69 |
{ "alloc_rx_buff_failed", E1000_STAT(alloc_rx_buff_failed) }, |
| 70 |
{ "tx_smbus", E1000_STAT(stats.mgptc) }, |
| 71 |
{ "rx_smbus", E1000_STAT(stats.mgprc) }, |
| 72 |
{ "dropped_smbus", E1000_STAT(stats.mgpdc) }, |
| 73 |
}; |
| 74 |
|
| 75 |
#define E1000_QUEUE_STATS_LEN 0 |
| 76 |
#define E1000_GLOBAL_STATS_LEN ARRAY_SIZE(e1000_gstrings_stats) |
| 77 |
#define E1000_STATS_LEN (E1000_GLOBAL_STATS_LEN + E1000_QUEUE_STATS_LEN) |
| 78 |
static const char e1000_gstrings_test[][ETH_GSTRING_LEN] = { |
| 79 |
"Register test (offline)", "Eeprom test (offline)", |
| 80 |
"Interrupt test (offline)", "Loopback test (offline)", |
| 81 |
"Link test (on/offline)" |
| 82 |
}; |
| 83 |
|
| 84 |
#define E1000_TEST_LEN ARRAY_SIZE(e1000_gstrings_test) |
| 85 |
|
| 86 |
static int e1000_get_link_ksettings(struct net_device *netdev, |
| 87 |
struct ethtool_link_ksettings *cmd) |
| 88 |
{ |
| 89 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
| 90 |
struct e1000_hw *hw = &adapter->hw; |
| 91 |
u32 supported, advertising; |
| 92 |
|
| 93 |
if (hw->media_type == e1000_media_type_copper) { |
| 94 |
supported = (SUPPORTED_10baseT_Half | |
| 95 |
SUPPORTED_10baseT_Full | |
| 96 |
SUPPORTED_100baseT_Half | |
| 97 |
SUPPORTED_100baseT_Full | |
| 98 |
SUPPORTED_1000baseT_Full| |
| 99 |
SUPPORTED_Autoneg | |
| 100 |
SUPPORTED_TP); |
| 101 |
advertising = ADVERTISED_TP; |
| 102 |
|
| 103 |
if (hw->autoneg == 1) { |
| 104 |
advertising |= ADVERTISED_Autoneg; |
| 105 |
/* the e1000 autoneg seems to match ethtool nicely */ |
| 106 |
advertising |= hw->autoneg_advertised; |
| 107 |
} |
| 108 |
|
| 109 |
cmd->base.port = PORT_TP; |
| 110 |
cmd->base.phy_address = hw->phy_addr; |
| 111 |
} else { |
| 112 |
supported = (SUPPORTED_1000baseT_Full | |
| 113 |
SUPPORTED_FIBRE | |
| 114 |
SUPPORTED_Autoneg); |
| 115 |
|
| 116 |
advertising = (ADVERTISED_1000baseT_Full | |
| 117 |
ADVERTISED_FIBRE | |
| 118 |
ADVERTISED_Autoneg); |
| 119 |
|
| 120 |
cmd->base.port = PORT_FIBRE; |
| 121 |
} |
| 122 |
|
| 123 |
if (er32(STATUS) & E1000_STATUS_LU) { |
| 124 |
e1000_get_speed_and_duplex(hw, &adapter->link_speed, |
| 125 |
&adapter->link_duplex); |
| 126 |
cmd->base.speed = adapter->link_speed; |
| 127 |
|
| 128 |
/* unfortunately FULL_DUPLEX != DUPLEX_FULL |
| 129 |
* and HALF_DUPLEX != DUPLEX_HALF |
| 130 |
*/ |
| 131 |
if (adapter->link_duplex == FULL_DUPLEX) |
| 132 |
cmd->base.duplex = DUPLEX_FULL; |
| 133 |
else |
| 134 |
cmd->base.duplex = DUPLEX_HALF; |
| 135 |
} else { |
| 136 |
cmd->base.speed = SPEED_UNKNOWN; |
| 137 |
cmd->base.duplex = DUPLEX_UNKNOWN; |
| 138 |
} |
| 139 |
|
| 140 |
cmd->base.autoneg = ((hw->media_type == e1000_media_type_fiber) || |
| 141 |
hw->autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE; |
| 142 |
|
| 143 |
/* MDI-X => 1; MDI => 0 */ |
| 144 |
if ((hw->media_type == e1000_media_type_copper) && |
| 145 |
netif_carrier_ok(netdev)) |
| 146 |
cmd->base.eth_tp_mdix = (!!adapter->phy_info.mdix_mode ? |
| 147 |
ETH_TP_MDI_X : ETH_TP_MDI); |
| 148 |
else |
| 149 |
cmd->base.eth_tp_mdix = ETH_TP_MDI_INVALID; |
| 150 |
|
| 151 |
if (hw->mdix == AUTO_ALL_MODES) |
| 152 |
cmd->base.eth_tp_mdix_ctrl = ETH_TP_MDI_AUTO; |
| 153 |
else |
| 154 |
cmd->base.eth_tp_mdix_ctrl = hw->mdix; |
| 155 |
|
| 156 |
ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported, |
| 157 |
supported); |
| 158 |
ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising, |
| 159 |
advertising); |
| 160 |
|
| 161 |
return 0; |
| 162 |
} |
| 163 |
|
| 164 |
static int e1000_set_link_ksettings(struct net_device *netdev, |
| 165 |
const struct ethtool_link_ksettings *cmd) |
| 166 |
{ |
| 167 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
| 168 |
struct e1000_hw *hw = &adapter->hw; |
| 169 |
u32 advertising; |
| 170 |
|
| 171 |
ethtool_convert_link_mode_to_legacy_u32(&advertising, |
| 172 |
cmd->link_modes.advertising); |
| 173 |
|
| 174 |
/* MDI setting is only allowed when autoneg enabled because |
| 175 |
* some hardware doesn't allow MDI setting when speed or |
| 176 |
* duplex is forced. |
| 177 |
*/ |
| 178 |
if (cmd->base.eth_tp_mdix_ctrl) { |
| 179 |
if (hw->media_type != e1000_media_type_copper) |
| 180 |
return -EOPNOTSUPP; |
| 181 |
|
| 182 |
if ((cmd->base.eth_tp_mdix_ctrl != ETH_TP_MDI_AUTO) && |
| 183 |
(cmd->base.autoneg != AUTONEG_ENABLE)) { |
| 184 |
e_err(drv, "forcing MDI/MDI-X state is not supported when link speed and/or duplex are forced\n"); |
| 185 |
return -EINVAL; |
| 186 |
} |
| 187 |
} |
| 188 |
|
| 189 |
while (test_and_set_bit(__E1000_RESETTING, &adapter->flags)) |
| 190 |
msleep(1); |
| 191 |
|
| 192 |
if (cmd->base.autoneg == AUTONEG_ENABLE) { |
| 193 |
hw->autoneg = 1; |
| 194 |
if (hw->media_type == e1000_media_type_fiber) |
| 195 |
hw->autoneg_advertised = ADVERTISED_1000baseT_Full | |
| 196 |
ADVERTISED_FIBRE | |
| 197 |
ADVERTISED_Autoneg; |
| 198 |
else |
| 199 |
hw->autoneg_advertised = advertising | |
| 200 |
ADVERTISED_TP | |
| 201 |
ADVERTISED_Autoneg; |
| 202 |
} else { |
| 203 |
u32 speed = cmd->base.speed; |
| 204 |
/* calling this overrides forced MDI setting */ |
| 205 |
if (e1000_set_spd_dplx(adapter, speed, cmd->base.duplex)) { |
| 206 |
clear_bit(__E1000_RESETTING, &adapter->flags); |
| 207 |
return -EINVAL; |
| 208 |
} |
| 209 |
} |
| 210 |
|
| 211 |
/* MDI-X => 2; MDI => 1; Auto => 3 */ |
| 212 |
if (cmd->base.eth_tp_mdix_ctrl) { |
| 213 |
if (cmd->base.eth_tp_mdix_ctrl == ETH_TP_MDI_AUTO) |
| 214 |
hw->mdix = AUTO_ALL_MODES; |
| 215 |
else |
| 216 |
hw->mdix = cmd->base.eth_tp_mdix_ctrl; |
| 217 |
} |
| 218 |
|
| 219 |
/* reset the link */ |
| 220 |
|
| 221 |
if (netif_running(adapter->netdev)) { |
| 222 |
e1000_down(adapter); |
| 223 |
e1000_up(adapter); |
| 224 |
} else { |
| 225 |
e1000_reset(adapter); |
| 226 |
} |
| 227 |
clear_bit(__E1000_RESETTING, &adapter->flags); |
| 228 |
return 0; |
| 229 |
} |
| 230 |
|
| 231 |
static u32 e1000_get_link(struct net_device *netdev) |
| 232 |
{ |
| 233 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
| 234 |
|
| 235 |
/* If the link is not reported up to netdev, interrupts are disabled, |
| 236 |
* and so the physical link state may have changed since we last |
| 237 |
* looked. Set get_link_status to make sure that the true link |
| 238 |
* state is interrogated, rather than pulling a cached and possibly |
| 239 |
* stale link state from the driver. |
| 240 |
*/ |
| 241 |
if (!netif_carrier_ok(netdev)) |
| 242 |
adapter->hw.get_link_status = 1; |
| 243 |
|
| 244 |
return e1000_has_link(adapter); |
| 245 |
} |
| 246 |
|
| 247 |
static void e1000_get_pauseparam(struct net_device *netdev, |
| 248 |
struct ethtool_pauseparam *pause) |
| 249 |
{ |
| 250 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
| 251 |
struct e1000_hw *hw = &adapter->hw; |
| 252 |
|
| 253 |
pause->autoneg = |
| 254 |
(adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE); |
| 255 |
|
| 256 |
if (hw->fc == E1000_FC_RX_PAUSE) { |
| 257 |
pause->rx_pause = 1; |
| 258 |
} else if (hw->fc == E1000_FC_TX_PAUSE) { |
| 259 |
pause->tx_pause = 1; |
| 260 |
} else if (hw->fc == E1000_FC_FULL) { |
| 261 |
pause->rx_pause = 1; |
| 262 |
pause->tx_pause = 1; |
| 263 |
} |
| 264 |
} |
| 265 |
|
| 266 |
static int e1000_set_pauseparam(struct net_device *netdev, |
| 267 |
struct ethtool_pauseparam *pause) |
| 268 |
{ |
| 269 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
| 270 |
struct e1000_hw *hw = &adapter->hw; |
| 271 |
int retval = 0; |
| 272 |
|
| 273 |
adapter->fc_autoneg = pause->autoneg; |
| 274 |
|
| 275 |
while (test_and_set_bit(__E1000_RESETTING, &adapter->flags)) |
| 276 |
msleep(1); |
| 277 |
|
| 278 |
if (pause->rx_pause && pause->tx_pause) |
| 279 |
hw->fc = E1000_FC_FULL; |
| 280 |
else if (pause->rx_pause && !pause->tx_pause) |
| 281 |
hw->fc = E1000_FC_RX_PAUSE; |
| 282 |
else if (!pause->rx_pause && pause->tx_pause) |
| 283 |
hw->fc = E1000_FC_TX_PAUSE; |
| 284 |
else if (!pause->rx_pause && !pause->tx_pause) |
| 285 |
hw->fc = E1000_FC_NONE; |
| 286 |
|
| 287 |
hw->original_fc = hw->fc; |
| 288 |
|
| 289 |
if (adapter->fc_autoneg == AUTONEG_ENABLE) { |
| 290 |
if (netif_running(adapter->netdev)) { |
| 291 |
e1000_down(adapter); |
| 292 |
e1000_up(adapter); |
| 293 |
} else { |
| 294 |
e1000_reset(adapter); |
| 295 |
} |
| 296 |
} else |
| 297 |
retval = ((hw->media_type == e1000_media_type_fiber) ? |
| 298 |
e1000_setup_link(hw) : e1000_force_mac_fc(hw)); |
| 299 |
|
| 300 |
clear_bit(__E1000_RESETTING, &adapter->flags); |
| 301 |
return retval; |
| 302 |
} |
| 303 |
|
| 304 |
static u32 e1000_get_msglevel(struct net_device *netdev) |
| 305 |
{ |
| 306 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
| 307 |
|
| 308 |
return adapter->msg_enable; |
| 309 |
} |
| 310 |
|
| 311 |
static void e1000_set_msglevel(struct net_device *netdev, u32 data) |
| 312 |
{ |
| 313 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
| 314 |
|
| 315 |
adapter->msg_enable = data; |
| 316 |
} |
| 317 |
|
| 318 |
static int e1000_get_regs_len(struct net_device *netdev) |
| 319 |
{ |
| 320 |
#define E1000_REGS_LEN 32 |
| 321 |
return E1000_REGS_LEN * sizeof(u32); |
| 322 |
} |
| 323 |
|
| 324 |
static void e1000_get_regs(struct net_device *netdev, struct ethtool_regs *regs, |
| 325 |
void *p) |
| 326 |
{ |
| 327 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
| 328 |
struct e1000_hw *hw = &adapter->hw; |
| 329 |
u32 *regs_buff = p; |
| 330 |
u16 phy_data; |
| 331 |
|
| 332 |
memset(p, 0, E1000_REGS_LEN * sizeof(u32)); |
| 333 |
|
| 334 |
regs->version = (1 << 24) | (hw->revision_id << 16) | hw->device_id; |
| 335 |
|
| 336 |
regs_buff[0] = er32(CTRL); |
| 337 |
regs_buff[1] = er32(STATUS); |
| 338 |
|
| 339 |
regs_buff[2] = er32(RCTL); |
| 340 |
regs_buff[3] = er32(RDLEN); |
| 341 |
regs_buff[4] = er32(RDH); |
| 342 |
regs_buff[5] = er32(RDT); |
| 343 |
regs_buff[6] = er32(RDTR); |
| 344 |
|
| 345 |
regs_buff[7] = er32(TCTL); |
| 346 |
regs_buff[8] = er32(TDLEN); |
| 347 |
regs_buff[9] = er32(TDH); |
| 348 |
regs_buff[10] = er32(TDT); |
| 349 |
regs_buff[11] = er32(TIDV); |
| 350 |
|
| 351 |
regs_buff[12] = hw->phy_type; /* PHY type (IGP=1, M88=0) */ |
| 352 |
if (hw->phy_type == e1000_phy_igp) { |
| 353 |
e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT, |
| 354 |
IGP01E1000_PHY_AGC_A); |
| 355 |
e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_A & |
| 356 |
IGP01E1000_PHY_PAGE_SELECT, &phy_data); |
| 357 |
regs_buff[13] = (u32)phy_data; /* cable length */ |
| 358 |
e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT, |
| 359 |
IGP01E1000_PHY_AGC_B); |
| 360 |
e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_B & |
| 361 |
IGP01E1000_PHY_PAGE_SELECT, &phy_data); |
| 362 |
regs_buff[14] = (u32)phy_data; /* cable length */ |
| 363 |
e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT, |
| 364 |
IGP01E1000_PHY_AGC_C); |
| 365 |
e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_C & |
| 366 |
IGP01E1000_PHY_PAGE_SELECT, &phy_data); |
| 367 |
regs_buff[15] = (u32)phy_data; /* cable length */ |
| 368 |
e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT, |
| 369 |
IGP01E1000_PHY_AGC_D); |
| 370 |
e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_D & |
| 371 |
IGP01E1000_PHY_PAGE_SELECT, &phy_data); |
| 372 |
regs_buff[16] = (u32)phy_data; /* cable length */ |
| 373 |
regs_buff[17] = 0; /* extended 10bt distance (not needed) */ |
| 374 |
e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT, 0x0); |
| 375 |
e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS & |
| 376 |
IGP01E1000_PHY_PAGE_SELECT, &phy_data); |
| 377 |
regs_buff[18] = (u32)phy_data; /* cable polarity */ |
| 378 |
e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT, |
| 379 |
IGP01E1000_PHY_PCS_INIT_REG); |
| 380 |
e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG & |
| 381 |
IGP01E1000_PHY_PAGE_SELECT, &phy_data); |
| 382 |
regs_buff[19] = (u32)phy_data; /* cable polarity */ |
| 383 |
regs_buff[20] = 0; /* polarity correction enabled (always) */ |
| 384 |
regs_buff[22] = 0; /* phy receive errors (unavailable) */ |
| 385 |
regs_buff[23] = regs_buff[18]; /* mdix mode */ |
| 386 |
e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT, 0x0); |
| 387 |
} else { |
| 388 |
e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data); |
| 389 |
regs_buff[13] = (u32)phy_data; /* cable length */ |
| 390 |
regs_buff[14] = 0; /* Dummy (to align w/ IGP phy reg dump) */ |
| 391 |
regs_buff[15] = 0; /* Dummy (to align w/ IGP phy reg dump) */ |
| 392 |
regs_buff[16] = 0; /* Dummy (to align w/ IGP phy reg dump) */ |
| 393 |
e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); |
| 394 |
regs_buff[17] = (u32)phy_data; /* extended 10bt distance */ |
| 395 |
regs_buff[18] = regs_buff[13]; /* cable polarity */ |
| 396 |
regs_buff[19] = 0; /* Dummy (to align w/ IGP phy reg dump) */ |
| 397 |
regs_buff[20] = regs_buff[17]; /* polarity correction */ |
| 398 |
/* phy receive errors */ |
| 399 |
regs_buff[22] = adapter->phy_stats.receive_errors; |
| 400 |
regs_buff[23] = regs_buff[13]; /* mdix mode */ |
| 401 |
} |
| 402 |
regs_buff[21] = adapter->phy_stats.idle_errors; /* phy idle errors */ |
| 403 |
e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data); |
| 404 |
regs_buff[24] = (u32)phy_data; /* phy local receiver status */ |
| 405 |
regs_buff[25] = regs_buff[24]; /* phy remote receiver status */ |
| 406 |
if (hw->mac_type >= e1000_82540 && |
| 407 |
hw->media_type == e1000_media_type_copper) { |
| 408 |
regs_buff[26] = er32(MANC); |
| 409 |
} |
| 410 |
} |
| 411 |
|
| 412 |
static int e1000_get_eeprom_len(struct net_device *netdev) |
| 413 |
{ |
| 414 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
| 415 |
struct e1000_hw *hw = &adapter->hw; |
| 416 |
|
| 417 |
return hw->eeprom.word_size * 2; |
| 418 |
} |
| 419 |
|
| 420 |
static int e1000_get_eeprom(struct net_device *netdev, |
| 421 |
struct ethtool_eeprom *eeprom, u8 *bytes) |
| 422 |
{ |
| 423 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
| 424 |
struct e1000_hw *hw = &adapter->hw; |
| 425 |
u16 *eeprom_buff; |
| 426 |
int first_word, last_word; |
| 427 |
int ret_val = 0; |
| 428 |
u16 i; |
| 429 |
|
| 430 |
if (eeprom->len == 0) |
| 431 |
return -EINVAL; |
| 432 |
|
| 433 |
eeprom->magic = hw->vendor_id | (hw->device_id << 16); |
| 434 |
|
| 435 |
first_word = eeprom->offset >> 1; |
| 436 |
last_word = (eeprom->offset + eeprom->len - 1) >> 1; |
| 437 |
|
| 438 |
eeprom_buff = kmalloc_array(last_word - first_word + 1, sizeof(u16), |
| 439 |
GFP_KERNEL); |
| 440 |
if (!eeprom_buff) |
| 441 |
return -ENOMEM; |
| 442 |
|
| 443 |
if (hw->eeprom.type == e1000_eeprom_spi) |
| 444 |
ret_val = e1000_read_eeprom(hw, first_word, |
| 445 |
last_word - first_word + 1, |
| 446 |
eeprom_buff); |
| 447 |
else { |
| 448 |
for (i = 0; i < last_word - first_word + 1; i++) { |
| 449 |
ret_val = e1000_read_eeprom(hw, first_word + i, 1, |
| 450 |
&eeprom_buff[i]); |
| 451 |
if (ret_val) |
| 452 |
break; |
| 453 |
} |
| 454 |
} |
| 455 |
|
| 456 |
/* Device's eeprom is always little-endian, word addressable */ |
| 457 |
for (i = 0; i < last_word - first_word + 1; i++) |
| 458 |
le16_to_cpus(&eeprom_buff[i]); |
| 459 |
|
| 460 |
memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1), |
| 461 |
eeprom->len); |
| 462 |
kfree(eeprom_buff); |
| 463 |
|
| 464 |
return ret_val; |
| 465 |
} |
| 466 |
|
| 467 |
static int e1000_set_eeprom(struct net_device *netdev, |
| 468 |
struct ethtool_eeprom *eeprom, u8 *bytes) |
| 469 |
{ |
| 470 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
| 471 |
struct e1000_hw *hw = &adapter->hw; |
| 472 |
u16 *eeprom_buff; |
| 473 |
void *ptr; |
| 474 |
int max_len, first_word, last_word, ret_val = 0; |
| 475 |
u16 i; |
| 476 |
|
| 477 |
if (eeprom->len == 0) |
| 478 |
return -EOPNOTSUPP; |
| 479 |
|
| 480 |
if (eeprom->magic != (hw->vendor_id | (hw->device_id << 16))) |
| 481 |
return -EFAULT; |
| 482 |
|
| 483 |
max_len = hw->eeprom.word_size * 2; |
| 484 |
|
| 485 |
first_word = eeprom->offset >> 1; |
| 486 |
last_word = (eeprom->offset + eeprom->len - 1) >> 1; |
| 487 |
eeprom_buff = kmalloc(max_len, GFP_KERNEL); |
| 488 |
if (!eeprom_buff) |
| 489 |
return -ENOMEM; |
| 490 |
|
| 491 |
ptr = (void *)eeprom_buff; |
| 492 |
|
| 493 |
if (eeprom->offset & 1) { |
| 494 |
/* need read/modify/write of first changed EEPROM word |
| 495 |
* only the second byte of the word is being modified |
| 496 |
*/ |
| 497 |
ret_val = e1000_read_eeprom(hw, first_word, 1, |
| 498 |
&eeprom_buff[0]); |
| 499 |
if (ret_val) |
| 500 |
goto out; |
| 501 |
|
| 502 |
ptr++; |
| 503 |
} |
| 504 |
if ((eeprom->offset + eeprom->len) & 1) { |
| 505 |
/* need read/modify/write of last changed EEPROM word |
| 506 |
* only the first byte of the word is being modified |
| 507 |
*/ |
| 508 |
ret_val = e1000_read_eeprom(hw, last_word, 1, |
| 509 |
&eeprom_buff[last_word - first_word]); |
| 510 |
if (ret_val) |
| 511 |
goto out; |
| 512 |
} |
| 513 |
|
| 514 |
/* Device's eeprom is always little-endian, word addressable */ |
| 515 |
for (i = 0; i < last_word - first_word + 1; i++) |
| 516 |
le16_to_cpus(&eeprom_buff[i]); |
| 517 |
|
| 518 |
memcpy(ptr, bytes, eeprom->len); |
| 519 |
|
| 520 |
for (i = 0; i < last_word - first_word + 1; i++) |
| 521 |
cpu_to_le16s(&eeprom_buff[i]); |
| 522 |
|
| 523 |
ret_val = e1000_write_eeprom(hw, first_word, |
| 524 |
last_word - first_word + 1, eeprom_buff); |
| 525 |
|
| 526 |
/* Update the checksum over the first part of the EEPROM if needed */ |
| 527 |
if ((ret_val == 0) && (first_word <= EEPROM_CHECKSUM_REG)) |
| 528 |
e1000_update_eeprom_checksum(hw); |
| 529 |
|
| 530 |
out: |
| 531 |
kfree(eeprom_buff); |
| 532 |
return ret_val; |
| 533 |
} |
| 534 |
|
| 535 |
static void e1000_get_drvinfo(struct net_device *netdev, |
| 536 |
struct ethtool_drvinfo *drvinfo) |
| 537 |
{ |
| 538 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
| 539 |
|
| 540 |
strscpy(drvinfo->driver, e1000_driver_name, |
| 541 |
sizeof(drvinfo->driver)); |
| 542 |
|
| 543 |
strscpy(drvinfo->bus_info, pci_name(adapter->pdev), |
| 544 |
sizeof(drvinfo->bus_info)); |
| 545 |
} |
| 546 |
|
| 547 |
static void e1000_get_ringparam(struct net_device *netdev, |
| 548 |
struct ethtool_ringparam *ring, |
| 549 |
struct kernel_ethtool_ringparam *kernel_ring, |
| 550 |
struct netlink_ext_ack *extack) |
| 551 |
{ |
| 552 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
| 553 |
struct e1000_hw *hw = &adapter->hw; |
| 554 |
e1000_mac_type mac_type = hw->mac_type; |
| 555 |
struct e1000_tx_ring *txdr = adapter->tx_ring; |
| 556 |
struct e1000_rx_ring *rxdr = adapter->rx_ring; |
| 557 |
|
| 558 |
ring->rx_max_pending = (mac_type < e1000_82544) ? E1000_MAX_RXD : |
| 559 |
E1000_MAX_82544_RXD; |
| 560 |
ring->tx_max_pending = (mac_type < e1000_82544) ? E1000_MAX_TXD : |
| 561 |
E1000_MAX_82544_TXD; |
| 562 |
ring->rx_pending = rxdr->count; |
| 563 |
ring->tx_pending = txdr->count; |
| 564 |
} |
| 565 |
|
| 566 |
static int e1000_set_ringparam(struct net_device *netdev, |
| 567 |
struct ethtool_ringparam *ring, |
| 568 |
struct kernel_ethtool_ringparam *kernel_ring, |
| 569 |
struct netlink_ext_ack *extack) |
| 570 |
{ |
| 571 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
| 572 |
struct e1000_hw *hw = &adapter->hw; |
| 573 |
e1000_mac_type mac_type = hw->mac_type; |
| 574 |
struct e1000_tx_ring *txdr, *tx_old; |
| 575 |
struct e1000_rx_ring *rxdr, *rx_old; |
| 576 |
int i, err; |
| 577 |
|
| 578 |
if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending)) |
| 579 |
return -EINVAL; |
| 580 |
|
| 581 |
while (test_and_set_bit(__E1000_RESETTING, &adapter->flags)) |
| 582 |
msleep(1); |
| 583 |
|
| 584 |
if (netif_running(adapter->netdev)) |
| 585 |
e1000_down(adapter); |
| 586 |
|
| 587 |
tx_old = adapter->tx_ring; |
| 588 |
rx_old = adapter->rx_ring; |
| 589 |
|
| 590 |
err = -ENOMEM; |
| 591 |
txdr = kzalloc_objs(struct e1000_tx_ring, adapter->num_tx_queues); |
| 592 |
if (!txdr) |
| 593 |
goto err_alloc_tx; |
| 594 |
|
| 595 |
rxdr = kzalloc_objs(struct e1000_rx_ring, adapter->num_rx_queues); |
| 596 |
if (!rxdr) |
| 597 |
goto err_alloc_rx; |
| 598 |
|
| 599 |
adapter->tx_ring = txdr; |
| 600 |
adapter->rx_ring = rxdr; |
| 601 |
|
| 602 |
rxdr->count = max(ring->rx_pending, (u32)E1000_MIN_RXD); |
| 603 |
rxdr->count = min(rxdr->count, (u32)(mac_type < e1000_82544 ? |
| 604 |
E1000_MAX_RXD : E1000_MAX_82544_RXD)); |
| 605 |
rxdr->count = ALIGN(rxdr->count, REQ_RX_DESCRIPTOR_MULTIPLE); |
| 606 |
txdr->count = max(ring->tx_pending, (u32)E1000_MIN_TXD); |
| 607 |
txdr->count = min(txdr->count, (u32)(mac_type < e1000_82544 ? |
| 608 |
E1000_MAX_TXD : E1000_MAX_82544_TXD)); |
| 609 |
txdr->count = ALIGN(txdr->count, REQ_TX_DESCRIPTOR_MULTIPLE); |
| 610 |
|
| 611 |
for (i = 0; i < adapter->num_tx_queues; i++) |
| 612 |
txdr[i].count = txdr->count; |
| 613 |
for (i = 0; i < adapter->num_rx_queues; i++) |
| 614 |
rxdr[i].count = rxdr->count; |
| 615 |
|
| 616 |
err = 0; |
| 617 |
if (netif_running(adapter->netdev)) { |
| 618 |
/* Try to get new resources before deleting old */ |
| 619 |
err = e1000_setup_all_rx_resources(adapter); |
| 620 |
if (err) |
| 621 |
goto err_setup_rx; |
| 622 |
err = e1000_setup_all_tx_resources(adapter); |
| 623 |
if (err) |
| 624 |
goto err_setup_tx; |
| 625 |
|
| 626 |
/* save the new, restore the old in order to free it, |
| 627 |
* then restore the new back again |
| 628 |
*/ |
| 629 |
|
| 630 |
adapter->rx_ring = rx_old; |
| 631 |
adapter->tx_ring = tx_old; |
| 632 |
e1000_free_all_rx_resources(adapter); |
| 633 |
e1000_free_all_tx_resources(adapter); |
| 634 |
adapter->rx_ring = rxdr; |
| 635 |
adapter->tx_ring = txdr; |
| 636 |
err = e1000_up(adapter); |
| 637 |
} |
| 638 |
kfree(tx_old); |
| 639 |
kfree(rx_old); |
| 640 |
|
| 641 |
clear_bit(__E1000_RESETTING, &adapter->flags); |
| 642 |
return err; |
| 643 |
|
| 644 |
err_setup_tx: |
| 645 |
e1000_free_all_rx_resources(adapter); |
| 646 |
err_setup_rx: |
| 647 |
adapter->rx_ring = rx_old; |
| 648 |
adapter->tx_ring = tx_old; |
| 649 |
kfree(rxdr); |
| 650 |
err_alloc_rx: |
| 651 |
kfree(txdr); |
| 652 |
err_alloc_tx: |
| 653 |
if (netif_running(adapter->netdev)) |
| 654 |
e1000_up(adapter); |
| 655 |
clear_bit(__E1000_RESETTING, &adapter->flags); |
| 656 |
return err; |
| 657 |
} |
| 658 |
|
| 659 |
static bool reg_pattern_test(struct e1000_adapter *adapter, u64 *data, int reg, |
| 660 |
u32 mask, u32 write) |
| 661 |
{ |
| 662 |
struct e1000_hw *hw = &adapter->hw; |
| 663 |
static const u32 test[] = { |
| 664 |
0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF |
| 665 |
}; |
| 666 |
u8 __iomem *address = hw->hw_addr + reg; |
| 667 |
u32 read; |
| 668 |
int i; |
| 669 |
|
| 670 |
for (i = 0; i < ARRAY_SIZE(test); i++) { |
| 671 |
writel(write & test[i], address); |
| 672 |
read = readl(address); |
| 673 |
if (read != (write & test[i] & mask)) { |
| 674 |
e_err(drv, "pattern test reg %04X failed: " |
| 675 |
"got 0x%08X expected 0x%08X\n", |
| 676 |
reg, read, (write & test[i] & mask)); |
| 677 |
*data = reg; |
| 678 |
return true; |
| 679 |
} |
| 680 |
} |
| 681 |
return false; |
| 682 |
} |
| 683 |
|
| 684 |
static bool reg_set_and_check(struct e1000_adapter *adapter, u64 *data, int reg, |
| 685 |
u32 mask, u32 write) |
| 686 |
{ |
| 687 |
struct e1000_hw *hw = &adapter->hw; |
| 688 |
u8 __iomem *address = hw->hw_addr + reg; |
| 689 |
u32 read; |
| 690 |
|
| 691 |
writel(write & mask, address); |
| 692 |
read = readl(address); |
| 693 |
if ((read & mask) != (write & mask)) { |
| 694 |
e_err(drv, "set/check reg %04X test failed: " |
| 695 |
"got 0x%08X expected 0x%08X\n", |
| 696 |
reg, (read & mask), (write & mask)); |
| 697 |
*data = reg; |
| 698 |
return true; |
| 699 |
} |
| 700 |
return false; |
| 701 |
} |
| 702 |
|
| 703 |
#define REG_PATTERN_TEST(reg, mask, write) \ |
| 704 |
do { \ |
| 705 |
if (reg_pattern_test(adapter, data, \ |
| 706 |
(hw->mac_type >= e1000_82543) \ |
| 707 |
? E1000_##reg : E1000_82542_##reg, \ |
| 708 |
mask, write)) \ |
| 709 |
return 1; \ |
| 710 |
} while (0) |
| 711 |
|
| 712 |
#define REG_SET_AND_CHECK(reg, mask, write) \ |
| 713 |
do { \ |
| 714 |
if (reg_set_and_check(adapter, data, \ |
| 715 |
(hw->mac_type >= e1000_82543) \ |
| 716 |
? E1000_##reg : E1000_82542_##reg, \ |
| 717 |
mask, write)) \ |
| 718 |
return 1; \ |
| 719 |
} while (0) |
| 720 |
|
| 721 |
static int e1000_reg_test(struct e1000_adapter *adapter, u64 *data) |
| 722 |
{ |
| 723 |
u32 value, before, after; |
| 724 |
u32 i, toggle; |
| 725 |
struct e1000_hw *hw = &adapter->hw; |
| 726 |
|
| 727 |
/* The status register is Read Only, so a write should fail. |
| 728 |
* Some bits that get toggled are ignored. |
| 729 |
*/ |
| 730 |
|
| 731 |
/* there are several bits on newer hardware that are r/w */ |
| 732 |
toggle = 0xFFFFF833; |
| 733 |
|
| 734 |
before = er32(STATUS); |
| 735 |
value = (er32(STATUS) & toggle); |
| 736 |
ew32(STATUS, toggle); |
| 737 |
after = er32(STATUS) & toggle; |
| 738 |
if (value != after) { |
| 739 |
e_err(drv, "failed STATUS register test got: " |
| 740 |
"0x%08X expected: 0x%08X\n", after, value); |
| 741 |
*data = 1; |
| 742 |
return 1; |
| 743 |
} |
| 744 |
/* restore previous status */ |
| 745 |
ew32(STATUS, before); |
| 746 |
|
| 747 |
REG_PATTERN_TEST(FCAL, 0xFFFFFFFF, 0xFFFFFFFF); |
| 748 |
REG_PATTERN_TEST(FCAH, 0x0000FFFF, 0xFFFFFFFF); |
| 749 |
REG_PATTERN_TEST(FCT, 0x0000FFFF, 0xFFFFFFFF); |
| 750 |
REG_PATTERN_TEST(VET, 0x0000FFFF, 0xFFFFFFFF); |
| 751 |
|
| 752 |
REG_PATTERN_TEST(RDTR, 0x0000FFFF, 0xFFFFFFFF); |
| 753 |
REG_PATTERN_TEST(RDBAH, 0xFFFFFFFF, 0xFFFFFFFF); |
| 754 |
REG_PATTERN_TEST(RDLEN, 0x000FFF80, 0x000FFFFF); |
| 755 |
REG_PATTERN_TEST(RDH, 0x0000FFFF, 0x0000FFFF); |
| 756 |
REG_PATTERN_TEST(RDT, 0x0000FFFF, 0x0000FFFF); |
| 757 |
REG_PATTERN_TEST(FCRTH, 0x0000FFF8, 0x0000FFF8); |
| 758 |
REG_PATTERN_TEST(FCTTV, 0x0000FFFF, 0x0000FFFF); |
| 759 |
REG_PATTERN_TEST(TIPG, 0x3FFFFFFF, 0x3FFFFFFF); |
| 760 |
REG_PATTERN_TEST(TDBAH, 0xFFFFFFFF, 0xFFFFFFFF); |
| 761 |
REG_PATTERN_TEST(TDLEN, 0x000FFF80, 0x000FFFFF); |
| 762 |
|
| 763 |
REG_SET_AND_CHECK(RCTL, 0xFFFFFFFF, 0x00000000); |
| 764 |
|
| 765 |
before = 0x06DFB3FE; |
| 766 |
REG_SET_AND_CHECK(RCTL, before, 0x003FFFFB); |
| 767 |
REG_SET_AND_CHECK(TCTL, 0xFFFFFFFF, 0x00000000); |
| 768 |
|
| 769 |
if (hw->mac_type >= e1000_82543) { |
| 770 |
REG_SET_AND_CHECK(RCTL, before, 0xFFFFFFFF); |
| 771 |
REG_PATTERN_TEST(RDBAL, 0xFFFFFFF0, 0xFFFFFFFF); |
| 772 |
REG_PATTERN_TEST(TXCW, 0xC000FFFF, 0x0000FFFF); |
| 773 |
REG_PATTERN_TEST(TDBAL, 0xFFFFFFF0, 0xFFFFFFFF); |
| 774 |
REG_PATTERN_TEST(TIDV, 0x0000FFFF, 0x0000FFFF); |
| 775 |
value = E1000_RAR_ENTRIES; |
| 776 |
for (i = 0; i < value; i++) { |
| 777 |
REG_PATTERN_TEST(RA + (((i << 1) + 1) << 2), |
| 778 |
0x8003FFFF, 0xFFFFFFFF); |
| 779 |
} |
| 780 |
} else { |
| 781 |
REG_SET_AND_CHECK(RCTL, 0xFFFFFFFF, 0x01FFFFFF); |
| 782 |
REG_PATTERN_TEST(RDBAL, 0xFFFFF000, 0xFFFFFFFF); |
| 783 |
REG_PATTERN_TEST(TXCW, 0x0000FFFF, 0x0000FFFF); |
| 784 |
REG_PATTERN_TEST(TDBAL, 0xFFFFF000, 0xFFFFFFFF); |
| 785 |
} |
| 786 |
|
| 787 |
value = E1000_MC_TBL_SIZE; |
| 788 |
for (i = 0; i < value; i++) |
| 789 |
REG_PATTERN_TEST(MTA + (i << 2), 0xFFFFFFFF, 0xFFFFFFFF); |
| 790 |
|
| 791 |
*data = 0; |
| 792 |
return 0; |
| 793 |
} |
| 794 |
|
| 795 |
static int e1000_eeprom_test(struct e1000_adapter *adapter, u64 *data) |
| 796 |
{ |
| 797 |
struct e1000_hw *hw = &adapter->hw; |
| 798 |
u16 temp; |
| 799 |
u16 checksum = 0; |
| 800 |
u16 i; |
| 801 |
|
| 802 |
*data = 0; |
| 803 |
/* Read and add up the contents of the EEPROM */ |
| 804 |
for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) { |
| 805 |
if ((e1000_read_eeprom(hw, i, 1, &temp)) < 0) { |
| 806 |
*data = 1; |
| 807 |
break; |
| 808 |
} |
| 809 |
checksum += temp; |
| 810 |
} |
| 811 |
|
| 812 |
/* If Checksum is not Correct return error else test passed */ |
| 813 |
if (checksum != EEPROM_SUM && !(*data)) |
| 814 |
*data = 2; |
| 815 |
|
| 816 |
return *data; |
| 817 |
} |
| 818 |
|
| 819 |
static irqreturn_t e1000_test_intr(int irq, void *data) |
| 820 |
{ |
| 821 |
struct net_device *netdev = (struct net_device *)data; |
| 822 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
| 823 |
struct e1000_hw *hw = &adapter->hw; |
| 824 |
|
| 825 |
adapter->test_icr |= er32(ICR); |
| 826 |
|
| 827 |
return IRQ_HANDLED; |
| 828 |
} |
| 829 |
|
| 830 |
static int e1000_intr_test(struct e1000_adapter *adapter, u64 *data) |
| 831 |
{ |
| 832 |
struct net_device *netdev = adapter->netdev; |
| 833 |
u32 mask, i = 0; |
| 834 |
bool shared_int = true; |
| 835 |
u32 irq = adapter->pdev->irq; |
| 836 |
struct e1000_hw *hw = &adapter->hw; |
| 837 |
|
| 838 |
*data = 0; |
| 839 |
|
| 840 |
/* NOTE: we don't test MSI interrupts here, yet |
| 841 |
* Hook up test interrupt handler just for this test |
| 842 |
*/ |
| 843 |
if (!request_irq(irq, e1000_test_intr, IRQF_PROBE_SHARED, netdev->name, |
| 844 |
netdev)) |
| 845 |
shared_int = false; |
| 846 |
else if (request_irq(irq, e1000_test_intr, IRQF_SHARED, |
| 847 |
netdev->name, netdev)) { |
| 848 |
*data = 1; |
| 849 |
return -1; |
| 850 |
} |
| 851 |
e_info(hw, "testing %s interrupt\n", (shared_int ? |
| 852 |
"shared" : "unshared")); |
| 853 |
|
| 854 |
/* Disable all the interrupts */ |
| 855 |
ew32(IMC, 0xFFFFFFFF); |
| 856 |
E1000_WRITE_FLUSH(); |
| 857 |
msleep(10); |
| 858 |
|
| 859 |
/* Test each interrupt */ |
| 860 |
for (; i < 10; i++) { |
| 861 |
/* Interrupt to test */ |
| 862 |
mask = 1 << i; |
| 863 |
|
| 864 |
if (!shared_int) { |
| 865 |
/* Disable the interrupt to be reported in |
| 866 |
* the cause register and then force the same |
| 867 |
* interrupt and see if one gets posted. If |
| 868 |
* an interrupt was posted to the bus, the |
| 869 |
* test failed. |
| 870 |
*/ |
| 871 |
adapter->test_icr = 0; |
| 872 |
ew32(IMC, mask); |
| 873 |
ew32(ICS, mask); |
| 874 |
E1000_WRITE_FLUSH(); |
| 875 |
msleep(10); |
| 876 |
|
| 877 |
if (adapter->test_icr & mask) { |
| 878 |
*data = 3; |
| 879 |
break; |
| 880 |
} |
| 881 |
} |
| 882 |
|
| 883 |
/* Enable the interrupt to be reported in |
| 884 |
* the cause register and then force the same |
| 885 |
* interrupt and see if one gets posted. If |
| 886 |
* an interrupt was not posted to the bus, the |
| 887 |
* test failed. |
| 888 |
*/ |
| 889 |
adapter->test_icr = 0; |
| 890 |
ew32(IMS, mask); |
| 891 |
ew32(ICS, mask); |
| 892 |
E1000_WRITE_FLUSH(); |
| 893 |
msleep(10); |
| 894 |
|
| 895 |
if (!(adapter->test_icr & mask)) { |
| 896 |
*data = 4; |
| 897 |
break; |
| 898 |
} |
| 899 |
|
| 900 |
if (!shared_int) { |
| 901 |
/* Disable the other interrupts to be reported in |
| 902 |
* the cause register and then force the other |
| 903 |
* interrupts and see if any get posted. If |
| 904 |
* an interrupt was posted to the bus, the |
| 905 |
* test failed. |
| 906 |
*/ |
| 907 |
adapter->test_icr = 0; |
| 908 |
ew32(IMC, ~mask & 0x00007FFF); |
| 909 |
ew32(ICS, ~mask & 0x00007FFF); |
| 910 |
E1000_WRITE_FLUSH(); |
| 911 |
msleep(10); |
| 912 |
|
| 913 |
if (adapter->test_icr) { |
| 914 |
*data = 5; |
| 915 |
break; |
| 916 |
} |
| 917 |
} |
| 918 |
} |
| 919 |
|
| 920 |
/* Disable all the interrupts */ |
| 921 |
ew32(IMC, 0xFFFFFFFF); |
| 922 |
E1000_WRITE_FLUSH(); |
| 923 |
msleep(10); |
| 924 |
|
| 925 |
/* Unhook test interrupt handler */ |
| 926 |
free_irq(irq, netdev); |
| 927 |
|
| 928 |
return *data; |
| 929 |
} |
| 930 |
|
| 931 |
static void e1000_free_desc_rings(struct e1000_adapter *adapter) |
| 932 |
{ |
| 933 |
struct e1000_tx_ring *txdr = &adapter->test_tx_ring; |
| 934 |
struct e1000_rx_ring *rxdr = &adapter->test_rx_ring; |
| 935 |
struct pci_dev *pdev = adapter->pdev; |
| 936 |
int i; |
| 937 |
|
| 938 |
if (txdr->desc && txdr->buffer_info) { |
| 939 |
for (i = 0; i < txdr->count; i++) { |
| 940 |
if (txdr->buffer_info[i].dma) |
| 941 |
dma_unmap_single(&pdev->dev, |
| 942 |
txdr->buffer_info[i].dma, |
| 943 |
txdr->buffer_info[i].length, |
| 944 |
DMA_TO_DEVICE); |
| 945 |
dev_kfree_skb(txdr->buffer_info[i].skb); |
| 946 |
} |
| 947 |
} |
| 948 |
|
| 949 |
if (rxdr->desc && rxdr->buffer_info) { |
| 950 |
for (i = 0; i < rxdr->count; i++) { |
| 951 |
if (rxdr->buffer_info[i].dma) |
| 952 |
dma_unmap_single(&pdev->dev, |
| 953 |
rxdr->buffer_info[i].dma, |
| 954 |
E1000_RXBUFFER_2048, |
| 955 |
DMA_FROM_DEVICE); |
| 956 |
kfree(rxdr->buffer_info[i].rxbuf.data); |
| 957 |
} |
| 958 |
} |
| 959 |
|
| 960 |
if (txdr->desc) { |
| 961 |
dma_free_coherent(&pdev->dev, txdr->size, txdr->desc, |
| 962 |
txdr->dma); |
| 963 |
txdr->desc = NULL; |
| 964 |
} |
| 965 |
if (rxdr->desc) { |
| 966 |
dma_free_coherent(&pdev->dev, rxdr->size, rxdr->desc, |
| 967 |
rxdr->dma); |
| 968 |
rxdr->desc = NULL; |
| 969 |
} |
| 970 |
|
| 971 |
kfree(txdr->buffer_info); |
| 972 |
txdr->buffer_info = NULL; |
| 973 |
kfree(rxdr->buffer_info); |
| 974 |
rxdr->buffer_info = NULL; |
| 975 |
} |
| 976 |
|
| 977 |
static int e1000_setup_desc_rings(struct e1000_adapter *adapter) |
| 978 |
{ |
| 979 |
struct e1000_hw *hw = &adapter->hw; |
| 980 |
struct e1000_tx_ring *txdr = &adapter->test_tx_ring; |
| 981 |
struct e1000_rx_ring *rxdr = &adapter->test_rx_ring; |
| 982 |
struct pci_dev *pdev = adapter->pdev; |
| 983 |
u32 rctl; |
| 984 |
int i, ret_val; |
| 985 |
|
| 986 |
/* Setup Tx descriptor ring and Tx buffers */ |
| 987 |
|
| 988 |
if (!txdr->count) |
| 989 |
txdr->count = E1000_DEFAULT_TXD; |
| 990 |
|
| 991 |
txdr->buffer_info = kzalloc_objs(struct e1000_tx_buffer, txdr->count); |
| 992 |
if (!txdr->buffer_info) { |
| 993 |
ret_val = 1; |
| 994 |
goto err_nomem; |
| 995 |
} |
| 996 |
|
| 997 |
txdr->size = txdr->count * sizeof(struct e1000_tx_desc); |
| 998 |
txdr->size = ALIGN(txdr->size, 4096); |
| 999 |
txdr->desc = dma_alloc_coherent(&pdev->dev, txdr->size, &txdr->dma, |
| 1000 |
GFP_KERNEL); |
| 1001 |
if (!txdr->desc) { |
| 1002 |
ret_val = 2; |
| 1003 |
goto err_nomem; |
| 1004 |
} |
| 1005 |
txdr->next_to_use = txdr->next_to_clean = 0; |
| 1006 |
|
| 1007 |
ew32(TDBAL, ((u64)txdr->dma & 0x00000000FFFFFFFF)); |
| 1008 |
ew32(TDBAH, ((u64)txdr->dma >> 32)); |
| 1009 |
ew32(TDLEN, txdr->count * sizeof(struct e1000_tx_desc)); |
| 1010 |
ew32(TDH, 0); |
| 1011 |
ew32(TDT, 0); |
| 1012 |
ew32(TCTL, E1000_TCTL_PSP | E1000_TCTL_EN | |
| 1013 |
E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT | |
| 1014 |
E1000_FDX_COLLISION_DISTANCE << E1000_COLD_SHIFT); |
| 1015 |
|
| 1016 |
for (i = 0; i < txdr->count; i++) { |
| 1017 |
struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*txdr, i); |
| 1018 |
struct sk_buff *skb; |
| 1019 |
unsigned int size = 1024; |
| 1020 |
|
| 1021 |
skb = alloc_skb(size, GFP_KERNEL); |
| 1022 |
if (!skb) { |
| 1023 |
ret_val = 3; |
| 1024 |
goto err_nomem; |
| 1025 |
} |
| 1026 |
skb_put(skb, size); |
| 1027 |
txdr->buffer_info[i].skb = skb; |
| 1028 |
txdr->buffer_info[i].length = skb->len; |
| 1029 |
txdr->buffer_info[i].dma = |
| 1030 |
dma_map_single(&pdev->dev, skb->data, skb->len, |
| 1031 |
DMA_TO_DEVICE); |
| 1032 |
if (dma_mapping_error(&pdev->dev, txdr->buffer_info[i].dma)) { |
| 1033 |
ret_val = 4; |
| 1034 |
goto err_nomem; |
| 1035 |
} |
| 1036 |
tx_desc->buffer_addr = cpu_to_le64(txdr->buffer_info[i].dma); |
| 1037 |
tx_desc->lower.data = cpu_to_le32(skb->len); |
| 1038 |
tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP | |
| 1039 |
E1000_TXD_CMD_IFCS | |
| 1040 |
E1000_TXD_CMD_RPS); |
| 1041 |
tx_desc->upper.data = 0; |
| 1042 |
} |
| 1043 |
|
| 1044 |
/* Setup Rx descriptor ring and Rx buffers */ |
| 1045 |
|
| 1046 |
if (!rxdr->count) |
| 1047 |
rxdr->count = E1000_DEFAULT_RXD; |
| 1048 |
|
| 1049 |
rxdr->buffer_info = kzalloc_objs(struct e1000_rx_buffer, rxdr->count); |
| 1050 |
if (!rxdr->buffer_info) { |
| 1051 |
ret_val = 5; |
| 1052 |
goto err_nomem; |
| 1053 |
} |
| 1054 |
|
| 1055 |
rxdr->size = rxdr->count * sizeof(struct e1000_rx_desc); |
| 1056 |
rxdr->desc = dma_alloc_coherent(&pdev->dev, rxdr->size, &rxdr->dma, |
| 1057 |
GFP_KERNEL); |
| 1058 |
if (!rxdr->desc) { |
| 1059 |
ret_val = 6; |
| 1060 |
goto err_nomem; |
| 1061 |
} |
| 1062 |
rxdr->next_to_use = rxdr->next_to_clean = 0; |
| 1063 |
|
| 1064 |
rctl = er32(RCTL); |
| 1065 |
ew32(RCTL, rctl & ~E1000_RCTL_EN); |
| 1066 |
ew32(RDBAL, ((u64)rxdr->dma & 0xFFFFFFFF)); |
| 1067 |
ew32(RDBAH, ((u64)rxdr->dma >> 32)); |
| 1068 |
ew32(RDLEN, rxdr->size); |
| 1069 |
ew32(RDH, 0); |
| 1070 |
ew32(RDT, 0); |
| 1071 |
rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 | |
| 1072 |
E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF | |
| 1073 |
(hw->mc_filter_type << E1000_RCTL_MO_SHIFT); |
| 1074 |
ew32(RCTL, rctl); |
| 1075 |
|
| 1076 |
for (i = 0; i < rxdr->count; i++) { |
| 1077 |
struct e1000_rx_desc *rx_desc = E1000_RX_DESC(*rxdr, i); |
| 1078 |
u8 *buf; |
| 1079 |
|
| 1080 |
buf = kzalloc(E1000_RXBUFFER_2048 + NET_SKB_PAD + NET_IP_ALIGN, |
| 1081 |
GFP_KERNEL); |
| 1082 |
if (!buf) { |
| 1083 |
ret_val = 7; |
| 1084 |
goto err_nomem; |
| 1085 |
} |
| 1086 |
rxdr->buffer_info[i].rxbuf.data = buf; |
| 1087 |
|
| 1088 |
rxdr->buffer_info[i].dma = |
| 1089 |
dma_map_single(&pdev->dev, |
| 1090 |
buf + NET_SKB_PAD + NET_IP_ALIGN, |
| 1091 |
E1000_RXBUFFER_2048, DMA_FROM_DEVICE); |
| 1092 |
if (dma_mapping_error(&pdev->dev, rxdr->buffer_info[i].dma)) { |
| 1093 |
ret_val = 8; |
| 1094 |
goto err_nomem; |
| 1095 |
} |
| 1096 |
rx_desc->buffer_addr = cpu_to_le64(rxdr->buffer_info[i].dma); |
| 1097 |
} |
| 1098 |
|
| 1099 |
return 0; |
| 1100 |
|
| 1101 |
err_nomem: |
| 1102 |
e1000_free_desc_rings(adapter); |
| 1103 |
return ret_val; |
| 1104 |
} |
| 1105 |
|
| 1106 |
static void e1000_phy_disable_receiver(struct e1000_adapter *adapter) |
| 1107 |
{ |
| 1108 |
struct e1000_hw *hw = &adapter->hw; |
| 1109 |
|
| 1110 |
/* Write out to PHY registers 29 and 30 to disable the Receiver. */ |
| 1111 |
e1000_write_phy_reg(hw, 29, 0x001F); |
| 1112 |
e1000_write_phy_reg(hw, 30, 0x8FFC); |
| 1113 |
e1000_write_phy_reg(hw, 29, 0x001A); |
| 1114 |
e1000_write_phy_reg(hw, 30, 0x8FF0); |
| 1115 |
} |
| 1116 |
|
| 1117 |
static void e1000_phy_reset_clk_and_crs(struct e1000_adapter *adapter) |
| 1118 |
{ |
| 1119 |
struct e1000_hw *hw = &adapter->hw; |
| 1120 |
u16 phy_reg; |
| 1121 |
|
| 1122 |
/* Because we reset the PHY above, we need to re-force TX_CLK in the |
| 1123 |
* Extended PHY Specific Control Register to 25MHz clock. This |
| 1124 |
* value defaults back to a 2.5MHz clock when the PHY is reset. |
| 1125 |
*/ |
| 1126 |
e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_reg); |
| 1127 |
phy_reg |= M88E1000_EPSCR_TX_CLK_25; |
| 1128 |
e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_reg); |
| 1129 |
|
| 1130 |
/* In addition, because of the s/w reset above, we need to enable |
| 1131 |
* CRS on TX. This must be set for both full and half duplex |
| 1132 |
* operation. |
| 1133 |
*/ |
| 1134 |
e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_reg); |
| 1135 |
phy_reg |= M88E1000_PSCR_ASSERT_CRS_ON_TX; |
| 1136 |
e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_reg); |
| 1137 |
} |
| 1138 |
|
| 1139 |
static int e1000_nonintegrated_phy_loopback(struct e1000_adapter *adapter) |
| 1140 |
{ |
| 1141 |
struct e1000_hw *hw = &adapter->hw; |
| 1142 |
u32 ctrl_reg; |
| 1143 |
u16 phy_reg; |
| 1144 |
|
| 1145 |
/* Setup the Device Control Register for PHY loopback test. */ |
| 1146 |
|
| 1147 |
ctrl_reg = er32(CTRL); |
| 1148 |
ctrl_reg |= (E1000_CTRL_ILOS | /* Invert Loss-Of-Signal */ |
| 1149 |
E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */ |
| 1150 |
E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */ |
| 1151 |
E1000_CTRL_SPD_1000 | /* Force Speed to 1000 */ |
| 1152 |
E1000_CTRL_FD); /* Force Duplex to FULL */ |
| 1153 |
|
| 1154 |
ew32(CTRL, ctrl_reg); |
| 1155 |
|
| 1156 |
/* Read the PHY Specific Control Register (0x10) */ |
| 1157 |
e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_reg); |
| 1158 |
|
| 1159 |
/* Clear Auto-Crossover bits in PHY Specific Control Register |
| 1160 |
* (bits 6:5). |
| 1161 |
*/ |
| 1162 |
phy_reg &= ~M88E1000_PSCR_AUTO_X_MODE; |
| 1163 |
e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_reg); |
| 1164 |
|
| 1165 |
/* Perform software reset on the PHY */ |
| 1166 |
e1000_phy_reset(hw); |
| 1167 |
|
| 1168 |
/* Have to setup TX_CLK and TX_CRS after software reset */ |
| 1169 |
e1000_phy_reset_clk_and_crs(adapter); |
| 1170 |
|
| 1171 |
e1000_write_phy_reg(hw, PHY_CTRL, 0x8100); |
| 1172 |
|
| 1173 |
/* Wait for reset to complete. */ |
| 1174 |
udelay(500); |
| 1175 |
|
| 1176 |
/* Have to setup TX_CLK and TX_CRS after software reset */ |
| 1177 |
e1000_phy_reset_clk_and_crs(adapter); |
| 1178 |
|
| 1179 |
/* Write out to PHY registers 29 and 30 to disable the Receiver. */ |
| 1180 |
e1000_phy_disable_receiver(adapter); |
| 1181 |
|
| 1182 |
/* Set the loopback bit in the PHY control register. */ |
| 1183 |
e1000_read_phy_reg(hw, PHY_CTRL, &phy_reg); |
| 1184 |
phy_reg |= MII_CR_LOOPBACK; |
| 1185 |
e1000_write_phy_reg(hw, PHY_CTRL, phy_reg); |
| 1186 |
|
| 1187 |
/* Setup TX_CLK and TX_CRS one more time. */ |
| 1188 |
e1000_phy_reset_clk_and_crs(adapter); |
| 1189 |
|
| 1190 |
/* Check Phy Configuration */ |
| 1191 |
e1000_read_phy_reg(hw, PHY_CTRL, &phy_reg); |
| 1192 |
if (phy_reg != 0x4100) |
| 1193 |
return 9; |
| 1194 |
|
| 1195 |
e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_reg); |
| 1196 |
if (phy_reg != 0x0070) |
| 1197 |
return 10; |
| 1198 |
|
| 1199 |
e1000_read_phy_reg(hw, 29, &phy_reg); |
| 1200 |
if (phy_reg != 0x001A) |
| 1201 |
return 11; |
| 1202 |
|
| 1203 |
return 0; |
| 1204 |
} |
| 1205 |
|
| 1206 |
static int e1000_integrated_phy_loopback(struct e1000_adapter *adapter) |
| 1207 |
{ |
| 1208 |
struct e1000_hw *hw = &adapter->hw; |
| 1209 |
u32 ctrl_reg = 0; |
| 1210 |
u32 stat_reg = 0; |
| 1211 |
|
| 1212 |
hw->autoneg = false; |
| 1213 |
|
| 1214 |
if (hw->phy_type == e1000_phy_m88) { |
| 1215 |
/* Auto-MDI/MDIX Off */ |
| 1216 |
e1000_write_phy_reg(hw, |
| 1217 |
M88E1000_PHY_SPEC_CTRL, 0x0808); |
| 1218 |
/* reset to update Auto-MDI/MDIX */ |
| 1219 |
e1000_write_phy_reg(hw, PHY_CTRL, 0x9140); |
| 1220 |
/* autoneg off */ |
| 1221 |
e1000_write_phy_reg(hw, PHY_CTRL, 0x8140); |
| 1222 |
} |
| 1223 |
|
| 1224 |
ctrl_reg = er32(CTRL); |
| 1225 |
|
| 1226 |
/* force 1000, set loopback */ |
| 1227 |
e1000_write_phy_reg(hw, PHY_CTRL, 0x4140); |
| 1228 |
|
| 1229 |
/* Now set up the MAC to the same speed/duplex as the PHY. */ |
| 1230 |
ctrl_reg = er32(CTRL); |
| 1231 |
ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */ |
| 1232 |
ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */ |
| 1233 |
E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */ |
| 1234 |
E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */ |
| 1235 |
E1000_CTRL_FD); /* Force Duplex to FULL */ |
| 1236 |
|
| 1237 |
if (hw->media_type == e1000_media_type_copper && |
| 1238 |
hw->phy_type == e1000_phy_m88) |
| 1239 |
ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */ |
| 1240 |
else { |
| 1241 |
/* Set the ILOS bit on the fiber Nic is half |
| 1242 |
* duplex link is detected. |
| 1243 |
*/ |
| 1244 |
stat_reg = er32(STATUS); |
| 1245 |
if ((stat_reg & E1000_STATUS_FD) == 0) |
| 1246 |
ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU); |
| 1247 |
} |
| 1248 |
|
| 1249 |
ew32(CTRL, ctrl_reg); |
| 1250 |
|
| 1251 |
/* Disable the receiver on the PHY so when a cable is plugged in, the |
| 1252 |
* PHY does not begin to autoneg when a cable is reconnected to the NIC. |
| 1253 |
*/ |
| 1254 |
if (hw->phy_type == e1000_phy_m88) |
| 1255 |
e1000_phy_disable_receiver(adapter); |
| 1256 |
|
| 1257 |
udelay(500); |
| 1258 |
|
| 1259 |
return 0; |
| 1260 |
} |
| 1261 |
|
| 1262 |
static int e1000_set_phy_loopback(struct e1000_adapter *adapter) |
| 1263 |
{ |
| 1264 |
struct e1000_hw *hw = &adapter->hw; |
| 1265 |
u16 phy_reg = 0; |
| 1266 |
u16 count = 0; |
| 1267 |
|
| 1268 |
switch (hw->mac_type) { |
| 1269 |
case e1000_82543: |
| 1270 |
if (hw->media_type == e1000_media_type_copper) { |
| 1271 |
/* Attempt to setup Loopback mode on Non-integrated PHY. |
| 1272 |
* Some PHY registers get corrupted at random, so |
| 1273 |
* attempt this 10 times. |
| 1274 |
*/ |
| 1275 |
while (e1000_nonintegrated_phy_loopback(adapter) && |
| 1276 |
count++ < 10); |
| 1277 |
if (count < 11) |
| 1278 |
return 0; |
| 1279 |
} |
| 1280 |
break; |
| 1281 |
|
| 1282 |
case e1000_82544: |
| 1283 |
case e1000_82540: |
| 1284 |
case e1000_82545: |
| 1285 |
case e1000_82545_rev_3: |
| 1286 |
case e1000_82546: |
| 1287 |
case e1000_82546_rev_3: |
| 1288 |
case e1000_82541: |
| 1289 |
case e1000_82541_rev_2: |
| 1290 |
case e1000_82547: |
| 1291 |
case e1000_82547_rev_2: |
| 1292 |
return e1000_integrated_phy_loopback(adapter); |
| 1293 |
default: |
| 1294 |
/* Default PHY loopback work is to read the MII |
| 1295 |
* control register and assert bit 14 (loopback mode). |
| 1296 |
*/ |
| 1297 |
e1000_read_phy_reg(hw, PHY_CTRL, &phy_reg); |
| 1298 |
phy_reg |= MII_CR_LOOPBACK; |
| 1299 |
e1000_write_phy_reg(hw, PHY_CTRL, phy_reg); |
| 1300 |
return 0; |
| 1301 |
} |
| 1302 |
|
| 1303 |
return 8; |
| 1304 |
} |
| 1305 |
|
| 1306 |
static int e1000_setup_loopback_test(struct e1000_adapter *adapter) |
| 1307 |
{ |
| 1308 |
struct e1000_hw *hw = &adapter->hw; |
| 1309 |
u32 rctl; |
| 1310 |
|
| 1311 |
if (hw->media_type == e1000_media_type_fiber || |
| 1312 |
hw->media_type == e1000_media_type_internal_serdes) { |
| 1313 |
switch (hw->mac_type) { |
| 1314 |
case e1000_82545: |
| 1315 |
case e1000_82546: |
| 1316 |
case e1000_82545_rev_3: |
| 1317 |
case e1000_82546_rev_3: |
| 1318 |
return e1000_set_phy_loopback(adapter); |
| 1319 |
default: |
| 1320 |
rctl = er32(RCTL); |
| 1321 |
rctl |= E1000_RCTL_LBM_TCVR; |
| 1322 |
ew32(RCTL, rctl); |
| 1323 |
return 0; |
| 1324 |
} |
| 1325 |
} else if (hw->media_type == e1000_media_type_copper) { |
| 1326 |
return e1000_set_phy_loopback(adapter); |
| 1327 |
} |
| 1328 |
|
| 1329 |
return 7; |
| 1330 |
} |
| 1331 |
|
| 1332 |
static void e1000_loopback_cleanup(struct e1000_adapter *adapter) |
| 1333 |
{ |
| 1334 |
struct e1000_hw *hw = &adapter->hw; |
| 1335 |
u32 rctl; |
| 1336 |
u16 phy_reg; |
| 1337 |
|
| 1338 |
rctl = er32(RCTL); |
| 1339 |
rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC); |
| 1340 |
ew32(RCTL, rctl); |
| 1341 |
|
| 1342 |
switch (hw->mac_type) { |
| 1343 |
case e1000_82545: |
| 1344 |
case e1000_82546: |
| 1345 |
case e1000_82545_rev_3: |
| 1346 |
case e1000_82546_rev_3: |
| 1347 |
default: |
| 1348 |
hw->autoneg = true; |
| 1349 |
e1000_read_phy_reg(hw, PHY_CTRL, &phy_reg); |
| 1350 |
if (phy_reg & MII_CR_LOOPBACK) { |
| 1351 |
phy_reg &= ~MII_CR_LOOPBACK; |
| 1352 |
e1000_write_phy_reg(hw, PHY_CTRL, phy_reg); |
| 1353 |
e1000_phy_reset(hw); |
| 1354 |
} |
| 1355 |
break; |
| 1356 |
} |
| 1357 |
} |
| 1358 |
|
| 1359 |
static void e1000_create_lbtest_frame(struct sk_buff *skb, |
| 1360 |
unsigned int frame_size) |
| 1361 |
{ |
| 1362 |
memset(skb->data, 0xFF, frame_size); |
| 1363 |
frame_size &= ~1; |
| 1364 |
memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1); |
| 1365 |
skb->data[frame_size / 2 + 10] = 0xBE; |
| 1366 |
skb->data[frame_size / 2 + 12] = 0xAF; |
| 1367 |
} |
| 1368 |
|
| 1369 |
static int e1000_check_lbtest_frame(const unsigned char *data, |
| 1370 |
unsigned int frame_size) |
| 1371 |
{ |
| 1372 |
frame_size &= ~1; |
| 1373 |
if (*(data + 3) == 0xFF) { |
| 1374 |
if ((*(data + frame_size / 2 + 10) == 0xBE) && |
| 1375 |
(*(data + frame_size / 2 + 12) == 0xAF)) { |
| 1376 |
return 0; |
| 1377 |
} |
| 1378 |
} |
| 1379 |
return 13; |
| 1380 |
} |
| 1381 |
|
| 1382 |
static int e1000_run_loopback_test(struct e1000_adapter *adapter) |
| 1383 |
{ |
| 1384 |
struct e1000_hw *hw = &adapter->hw; |
| 1385 |
struct e1000_tx_ring *txdr = &adapter->test_tx_ring; |
| 1386 |
struct e1000_rx_ring *rxdr = &adapter->test_rx_ring; |
| 1387 |
struct pci_dev *pdev = adapter->pdev; |
| 1388 |
int i, j, k, l, lc, good_cnt, ret_val = 0; |
| 1389 |
unsigned long time; |
| 1390 |
|
| 1391 |
ew32(RDT, rxdr->count - 1); |
| 1392 |
|
| 1393 |
/* Calculate the loop count based on the largest descriptor ring |
| 1394 |
* The idea is to wrap the largest ring a number of times using 64 |
| 1395 |
* send/receive pairs during each loop |
| 1396 |
*/ |
| 1397 |
|
| 1398 |
if (rxdr->count <= txdr->count) |
| 1399 |
lc = ((txdr->count / 64) * 2) + 1; |
| 1400 |
else |
| 1401 |
lc = ((rxdr->count / 64) * 2) + 1; |
| 1402 |
|
| 1403 |
k = l = 0; |
| 1404 |
for (j = 0; j <= lc; j++) { /* loop count loop */ |
| 1405 |
for (i = 0; i < 64; i++) { /* send the packets */ |
| 1406 |
e1000_create_lbtest_frame(txdr->buffer_info[i].skb, |
| 1407 |
1024); |
| 1408 |
dma_sync_single_for_device(&pdev->dev, |
| 1409 |
txdr->buffer_info[k].dma, |
| 1410 |
txdr->buffer_info[k].length, |
| 1411 |
DMA_TO_DEVICE); |
| 1412 |
if (unlikely(++k == txdr->count)) |
| 1413 |
k = 0; |
| 1414 |
} |
| 1415 |
ew32(TDT, k); |
| 1416 |
E1000_WRITE_FLUSH(); |
| 1417 |
msleep(200); |
| 1418 |
time = jiffies; /* set the start time for the receive */ |
| 1419 |
good_cnt = 0; |
| 1420 |
do { /* receive the sent packets */ |
| 1421 |
dma_sync_single_for_cpu(&pdev->dev, |
| 1422 |
rxdr->buffer_info[l].dma, |
| 1423 |
E1000_RXBUFFER_2048, |
| 1424 |
DMA_FROM_DEVICE); |
| 1425 |
|
| 1426 |
ret_val = e1000_check_lbtest_frame( |
| 1427 |
rxdr->buffer_info[l].rxbuf.data + |
| 1428 |
NET_SKB_PAD + NET_IP_ALIGN, |
| 1429 |
1024); |
| 1430 |
if (!ret_val) |
| 1431 |
good_cnt++; |
| 1432 |
if (unlikely(++l == rxdr->count)) |
| 1433 |
l = 0; |
| 1434 |
/* time + 20 msecs (200 msecs on 2.4) is more than |
| 1435 |
* enough time to complete the receives, if it's |
| 1436 |
* exceeded, break and error off |
| 1437 |
*/ |
| 1438 |
} while (good_cnt < 64 && time_after(time + 20, jiffies)); |
| 1439 |
|
| 1440 |
if (good_cnt != 64) { |
| 1441 |
ret_val = 13; /* ret_val is the same as mis-compare */ |
| 1442 |
break; |
| 1443 |
} |
| 1444 |
if (time_after_eq(jiffies, time + 2)) { |
| 1445 |
ret_val = 14; /* error code for time out error */ |
| 1446 |
break; |
| 1447 |
} |
| 1448 |
} /* end loop count loop */ |
| 1449 |
return ret_val; |
| 1450 |
} |
| 1451 |
|
| 1452 |
static int e1000_loopback_test(struct e1000_adapter *adapter, u64 *data) |
| 1453 |
{ |
| 1454 |
*data = e1000_setup_desc_rings(adapter); |
| 1455 |
if (*data) |
| 1456 |
goto out; |
| 1457 |
*data = e1000_setup_loopback_test(adapter); |
| 1458 |
if (*data) |
| 1459 |
goto err_loopback; |
| 1460 |
*data = e1000_run_loopback_test(adapter); |
| 1461 |
e1000_loopback_cleanup(adapter); |
| 1462 |
|
| 1463 |
err_loopback: |
| 1464 |
e1000_free_desc_rings(adapter); |
| 1465 |
out: |
| 1466 |
return *data; |
| 1467 |
} |
| 1468 |
|
| 1469 |
static int e1000_link_test(struct e1000_adapter *adapter, u64 *data) |
| 1470 |
{ |
| 1471 |
struct e1000_hw *hw = &adapter->hw; |
| 1472 |
*data = 0; |
| 1473 |
if (hw->media_type == e1000_media_type_internal_serdes) { |
| 1474 |
int i = 0; |
| 1475 |
|
| 1476 |
hw->serdes_has_link = false; |
| 1477 |
|
| 1478 |
/* On some blade server designs, link establishment |
| 1479 |
* could take as long as 2-3 minutes |
| 1480 |
*/ |
| 1481 |
do { |
| 1482 |
e1000_check_for_link(hw); |
| 1483 |
if (hw->serdes_has_link) |
| 1484 |
return *data; |
| 1485 |
msleep(20); |
| 1486 |
} while (i++ < 3750); |
| 1487 |
|
| 1488 |
*data = 1; |
| 1489 |
} else { |
| 1490 |
e1000_check_for_link(hw); |
| 1491 |
if (hw->autoneg) /* if auto_neg is set wait for it */ |
| 1492 |
msleep(4000); |
| 1493 |
|
| 1494 |
if (!(er32(STATUS) & E1000_STATUS_LU)) |
| 1495 |
*data = 1; |
| 1496 |
} |
| 1497 |
return *data; |
| 1498 |
} |
| 1499 |
|
| 1500 |
static int e1000_get_sset_count(struct net_device *netdev, int sset) |
| 1501 |
{ |
| 1502 |
switch (sset) { |
| 1503 |
case ETH_SS_TEST: |
| 1504 |
return E1000_TEST_LEN; |
| 1505 |
case ETH_SS_STATS: |
| 1506 |
return E1000_STATS_LEN; |
| 1507 |
default: |
| 1508 |
return -EOPNOTSUPP; |
| 1509 |
} |
| 1510 |
} |
| 1511 |
|
| 1512 |
static void e1000_diag_test(struct net_device *netdev, |
| 1513 |
struct ethtool_test *eth_test, u64 *data) |
| 1514 |
{ |
| 1515 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1516 |
struct e1000_hw *hw = &adapter->hw; |
| 1517 |
bool if_running = netif_running(netdev); |
| 1518 |
|
| 1519 |
set_bit(__E1000_TESTING, &adapter->flags); |
| 1520 |
if (eth_test->flags == ETH_TEST_FL_OFFLINE) { |
| 1521 |
/* Offline tests */ |
| 1522 |
|
| 1523 |
/* save speed, duplex, autoneg settings */ |
| 1524 |
u16 autoneg_advertised = hw->autoneg_advertised; |
| 1525 |
u8 forced_speed_duplex = hw->forced_speed_duplex; |
| 1526 |
u8 autoneg = hw->autoneg; |
| 1527 |
|
| 1528 |
e_info(hw, "offline testing starting\n"); |
| 1529 |
|
| 1530 |
/* Link test performed before hardware reset so autoneg doesn't |
| 1531 |
* interfere with test result |
| 1532 |
*/ |
| 1533 |
if (e1000_link_test(adapter, &data[4])) |
| 1534 |
eth_test->flags |= ETH_TEST_FL_FAILED; |
| 1535 |
|
| 1536 |
if (if_running) |
| 1537 |
/* indicate we're in test mode */ |
| 1538 |
e1000_close(netdev); |
| 1539 |
else |
| 1540 |
e1000_reset(adapter); |
| 1541 |
|
| 1542 |
if (e1000_reg_test(adapter, &data[0])) |
| 1543 |
eth_test->flags |= ETH_TEST_FL_FAILED; |
| 1544 |
|
| 1545 |
e1000_reset(adapter); |
| 1546 |
if (e1000_eeprom_test(adapter, &data[1])) |
| 1547 |
eth_test->flags |= ETH_TEST_FL_FAILED; |
| 1548 |
|
| 1549 |
e1000_reset(adapter); |
| 1550 |
if (e1000_intr_test(adapter, &data[2])) |
| 1551 |
eth_test->flags |= ETH_TEST_FL_FAILED; |
| 1552 |
|
| 1553 |
e1000_reset(adapter); |
| 1554 |
/* make sure the phy is powered up */ |
| 1555 |
e1000_power_up_phy(adapter); |
| 1556 |
if (e1000_loopback_test(adapter, &data[3])) |
| 1557 |
eth_test->flags |= ETH_TEST_FL_FAILED; |
| 1558 |
|
| 1559 |
/* restore speed, duplex, autoneg settings */ |
| 1560 |
hw->autoneg_advertised = autoneg_advertised; |
| 1561 |
hw->forced_speed_duplex = forced_speed_duplex; |
| 1562 |
hw->autoneg = autoneg; |
| 1563 |
|
| 1564 |
e1000_reset(adapter); |
| 1565 |
clear_bit(__E1000_TESTING, &adapter->flags); |
| 1566 |
if (if_running) |
| 1567 |
e1000_open(netdev); |
| 1568 |
} else { |
| 1569 |
e_info(hw, "online testing starting\n"); |
| 1570 |
/* Online tests */ |
| 1571 |
if (e1000_link_test(adapter, &data[4])) |
| 1572 |
eth_test->flags |= ETH_TEST_FL_FAILED; |
| 1573 |
|
| 1574 |
/* Online tests aren't run; pass by default */ |
| 1575 |
data[0] = 0; |
| 1576 |
data[1] = 0; |
| 1577 |
data[2] = 0; |
| 1578 |
data[3] = 0; |
| 1579 |
|
| 1580 |
clear_bit(__E1000_TESTING, &adapter->flags); |
| 1581 |
} |
| 1582 |
msleep_interruptible(4 * 1000); |
| 1583 |
} |
| 1584 |
|
| 1585 |
static int e1000_wol_exclusion(struct e1000_adapter *adapter, |
| 1586 |
struct ethtool_wolinfo *wol) |
| 1587 |
{ |
| 1588 |
struct e1000_hw *hw = &adapter->hw; |
| 1589 |
int retval = 1; /* fail by default */ |
| 1590 |
|
| 1591 |
switch (hw->device_id) { |
| 1592 |
case E1000_DEV_ID_82542: |
| 1593 |
case E1000_DEV_ID_82543GC_FIBER: |
| 1594 |
case E1000_DEV_ID_82543GC_COPPER: |
| 1595 |
case E1000_DEV_ID_82544EI_FIBER: |
| 1596 |
case E1000_DEV_ID_82546EB_QUAD_COPPER: |
| 1597 |
case E1000_DEV_ID_82545EM_FIBER: |
| 1598 |
case E1000_DEV_ID_82545EM_COPPER: |
| 1599 |
case E1000_DEV_ID_82546GB_QUAD_COPPER: |
| 1600 |
case E1000_DEV_ID_82546GB_PCIE: |
| 1601 |
/* these don't support WoL at all */ |
| 1602 |
wol->supported = 0; |
| 1603 |
break; |
| 1604 |
case E1000_DEV_ID_82546EB_FIBER: |
| 1605 |
case E1000_DEV_ID_82546GB_FIBER: |
| 1606 |
/* Wake events not supported on port B */ |
| 1607 |
if (er32(STATUS) & E1000_STATUS_FUNC_1) { |
| 1608 |
wol->supported = 0; |
| 1609 |
break; |
| 1610 |
} |
| 1611 |
/* return success for non excluded adapter ports */ |
| 1612 |
retval = 0; |
| 1613 |
break; |
| 1614 |
case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3: |
| 1615 |
/* quad port adapters only support WoL on port A */ |
| 1616 |
if (!adapter->quad_port_a) { |
| 1617 |
wol->supported = 0; |
| 1618 |
break; |
| 1619 |
} |
| 1620 |
/* return success for non excluded adapter ports */ |
| 1621 |
retval = 0; |
| 1622 |
break; |
| 1623 |
default: |
| 1624 |
/* dual port cards only support WoL on port A from now on |
| 1625 |
* unless it was enabled in the eeprom for port B |
| 1626 |
* so exclude FUNC_1 ports from having WoL enabled |
| 1627 |
*/ |
| 1628 |
if (er32(STATUS) & E1000_STATUS_FUNC_1 && |
| 1629 |
!adapter->eeprom_wol) { |
| 1630 |
wol->supported = 0; |
| 1631 |
break; |
| 1632 |
} |
| 1633 |
|
| 1634 |
retval = 0; |
| 1635 |
} |
| 1636 |
|
| 1637 |
return retval; |
| 1638 |
} |
| 1639 |
|
| 1640 |
static void e1000_get_wol(struct net_device *netdev, |
| 1641 |
struct ethtool_wolinfo *wol) |
| 1642 |
{ |
| 1643 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1644 |
struct e1000_hw *hw = &adapter->hw; |
| 1645 |
|
| 1646 |
wol->supported = WAKE_UCAST | WAKE_MCAST | WAKE_BCAST | WAKE_MAGIC; |
| 1647 |
wol->wolopts = 0; |
| 1648 |
|
| 1649 |
/* this function will set ->supported = 0 and return 1 if wol is not |
| 1650 |
* supported by this hardware |
| 1651 |
*/ |
| 1652 |
if (e1000_wol_exclusion(adapter, wol) || |
| 1653 |
!device_can_wakeup(&adapter->pdev->dev)) |
| 1654 |
return; |
| 1655 |
|
| 1656 |
/* apply any specific unsupported masks here */ |
| 1657 |
switch (hw->device_id) { |
| 1658 |
case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3: |
| 1659 |
/* KSP3 does not support UCAST wake-ups */ |
| 1660 |
wol->supported &= ~WAKE_UCAST; |
| 1661 |
|
| 1662 |
if (adapter->wol & E1000_WUFC_EX) |
| 1663 |
e_err(drv, "Interface does not support directed " |
| 1664 |
"(unicast) frame wake-up packets\n"); |
| 1665 |
break; |
| 1666 |
default: |
| 1667 |
break; |
| 1668 |
} |
| 1669 |
|
| 1670 |
if (adapter->wol & E1000_WUFC_EX) |
| 1671 |
wol->wolopts |= WAKE_UCAST; |
| 1672 |
if (adapter->wol & E1000_WUFC_MC) |
| 1673 |
wol->wolopts |= WAKE_MCAST; |
| 1674 |
if (adapter->wol & E1000_WUFC_BC) |
| 1675 |
wol->wolopts |= WAKE_BCAST; |
| 1676 |
if (adapter->wol & E1000_WUFC_MAG) |
| 1677 |
wol->wolopts |= WAKE_MAGIC; |
| 1678 |
} |
| 1679 |
|
| 1680 |
static int e1000_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) |
| 1681 |
{ |
| 1682 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1683 |
struct e1000_hw *hw = &adapter->hw; |
| 1684 |
|
| 1685 |
if (wol->wolopts & (WAKE_PHY | WAKE_ARP | WAKE_MAGICSECURE)) |
| 1686 |
return -EOPNOTSUPP; |
| 1687 |
|
| 1688 |
if (e1000_wol_exclusion(adapter, wol) || |
| 1689 |
!device_can_wakeup(&adapter->pdev->dev)) |
| 1690 |
return wol->wolopts ? -EOPNOTSUPP : 0; |
| 1691 |
|
| 1692 |
switch (hw->device_id) { |
| 1693 |
case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3: |
| 1694 |
if (wol->wolopts & WAKE_UCAST) { |
| 1695 |
e_err(drv, "Interface does not support directed " |
| 1696 |
"(unicast) frame wake-up packets\n"); |
| 1697 |
return -EOPNOTSUPP; |
| 1698 |
} |
| 1699 |
break; |
| 1700 |
default: |
| 1701 |
break; |
| 1702 |
} |
| 1703 |
|
| 1704 |
/* these settings will always override what we currently have */ |
| 1705 |
adapter->wol = 0; |
| 1706 |
|
| 1707 |
if (wol->wolopts & WAKE_UCAST) |
| 1708 |
adapter->wol |= E1000_WUFC_EX; |
| 1709 |
if (wol->wolopts & WAKE_MCAST) |
| 1710 |
adapter->wol |= E1000_WUFC_MC; |
| 1711 |
if (wol->wolopts & WAKE_BCAST) |
| 1712 |
adapter->wol |= E1000_WUFC_BC; |
| 1713 |
if (wol->wolopts & WAKE_MAGIC) |
| 1714 |
adapter->wol |= E1000_WUFC_MAG; |
| 1715 |
|
| 1716 |
device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); |
| 1717 |
|
| 1718 |
return 0; |
| 1719 |
} |
| 1720 |
|
| 1721 |
static int e1000_set_phys_id(struct net_device *netdev, |
| 1722 |
enum ethtool_phys_id_state state) |
| 1723 |
{ |
| 1724 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1725 |
struct e1000_hw *hw = &adapter->hw; |
| 1726 |
|
| 1727 |
switch (state) { |
| 1728 |
case ETHTOOL_ID_ACTIVE: |
| 1729 |
e1000_setup_led(hw); |
| 1730 |
return 2; |
| 1731 |
|
| 1732 |
case ETHTOOL_ID_ON: |
| 1733 |
e1000_led_on(hw); |
| 1734 |
break; |
| 1735 |
|
| 1736 |
case ETHTOOL_ID_OFF: |
| 1737 |
e1000_led_off(hw); |
| 1738 |
break; |
| 1739 |
|
| 1740 |
case ETHTOOL_ID_INACTIVE: |
| 1741 |
e1000_cleanup_led(hw); |
| 1742 |
} |
| 1743 |
|
| 1744 |
return 0; |
| 1745 |
} |
| 1746 |
|
| 1747 |
static int e1000_get_coalesce(struct net_device *netdev, |
| 1748 |
struct ethtool_coalesce *ec, |
| 1749 |
struct kernel_ethtool_coalesce *kernel_coal, |
| 1750 |
struct netlink_ext_ack *extack) |
| 1751 |
{ |
| 1752 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1753 |
|
| 1754 |
if (adapter->hw.mac_type < e1000_82545) |
| 1755 |
return -EOPNOTSUPP; |
| 1756 |
|
| 1757 |
if (adapter->itr_setting <= 4) |
| 1758 |
ec->rx_coalesce_usecs = adapter->itr_setting; |
| 1759 |
else |
| 1760 |
ec->rx_coalesce_usecs = 1000000 / adapter->itr_setting; |
| 1761 |
|
| 1762 |
return 0; |
| 1763 |
} |
| 1764 |
|
| 1765 |
static int e1000_set_coalesce(struct net_device *netdev, |
| 1766 |
struct ethtool_coalesce *ec, |
| 1767 |
struct kernel_ethtool_coalesce *kernel_coal, |
| 1768 |
struct netlink_ext_ack *extack) |
| 1769 |
{ |
| 1770 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1771 |
struct e1000_hw *hw = &adapter->hw; |
| 1772 |
|
| 1773 |
if (hw->mac_type < e1000_82545) |
| 1774 |
return -EOPNOTSUPP; |
| 1775 |
|
| 1776 |
if ((ec->rx_coalesce_usecs > E1000_MAX_ITR_USECS) || |
| 1777 |
((ec->rx_coalesce_usecs > 4) && |
| 1778 |
(ec->rx_coalesce_usecs < E1000_MIN_ITR_USECS)) || |
| 1779 |
(ec->rx_coalesce_usecs == 2)) |
| 1780 |
return -EINVAL; |
| 1781 |
|
| 1782 |
if (ec->rx_coalesce_usecs == 4) { |
| 1783 |
adapter->itr = adapter->itr_setting = 4; |
| 1784 |
} else if (ec->rx_coalesce_usecs <= 3) { |
| 1785 |
adapter->itr = 20000; |
| 1786 |
adapter->itr_setting = ec->rx_coalesce_usecs; |
| 1787 |
} else { |
| 1788 |
adapter->itr = (1000000 / ec->rx_coalesce_usecs); |
| 1789 |
adapter->itr_setting = adapter->itr & ~3; |
| 1790 |
} |
| 1791 |
|
| 1792 |
if (adapter->itr_setting != 0) |
| 1793 |
ew32(ITR, 1000000000 / (adapter->itr * 256)); |
| 1794 |
else |
| 1795 |
ew32(ITR, 0); |
| 1796 |
|
| 1797 |
return 0; |
| 1798 |
} |
| 1799 |
|
| 1800 |
static int e1000_nway_reset(struct net_device *netdev) |
| 1801 |
{ |
| 1802 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1803 |
|
| 1804 |
if (netif_running(netdev)) |
| 1805 |
e1000_reinit_locked(adapter); |
| 1806 |
return 0; |
| 1807 |
} |
| 1808 |
|
| 1809 |
static void e1000_get_ethtool_stats(struct net_device *netdev, |
| 1810 |
struct ethtool_stats *stats, u64 *data) |
| 1811 |
{ |
| 1812 |
struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1813 |
int i; |
| 1814 |
const struct e1000_stats *stat = e1000_gstrings_stats; |
| 1815 |
|
| 1816 |
e1000_update_stats(adapter); |
| 1817 |
for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++, stat++) { |
| 1818 |
char *p; |
| 1819 |
|
| 1820 |
switch (stat->type) { |
| 1821 |
case NETDEV_STATS: |
| 1822 |
p = (char *)netdev + stat->stat_offset; |
| 1823 |
break; |
| 1824 |
case E1000_STATS: |
| 1825 |
p = (char *)adapter + stat->stat_offset; |
| 1826 |
break; |
| 1827 |
default: |
| 1828 |
netdev_WARN_ONCE(netdev, "Invalid E1000 stat type: %u index %d\n", |
| 1829 |
stat->type, i); |
| 1830 |
continue; |
| 1831 |
} |
| 1832 |
|
| 1833 |
if (stat->sizeof_stat == sizeof(u64)) |
| 1834 |
data[i] = *(u64 *)p; |
| 1835 |
else |
| 1836 |
data[i] = *(u32 *)p; |
| 1837 |
} |
| 1838 |
/* BUG_ON(i != E1000_STATS_LEN); */ |
| 1839 |
} |
| 1840 |
|
| 1841 |
static void e1000_get_strings(struct net_device *netdev, u32 stringset, |
| 1842 |
u8 *data) |
| 1843 |
{ |
| 1844 |
u8 *p = data; |
| 1845 |
int i; |
| 1846 |
|
| 1847 |
switch (stringset) { |
| 1848 |
case ETH_SS_TEST: |
| 1849 |
memcpy(data, e1000_gstrings_test, sizeof(e1000_gstrings_test)); |
| 1850 |
break; |
| 1851 |
case ETH_SS_STATS: |
| 1852 |
for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) { |
| 1853 |
memcpy(p, e1000_gstrings_stats[i].stat_string, |
| 1854 |
ETH_GSTRING_LEN); |
| 1855 |
p += ETH_GSTRING_LEN; |
| 1856 |
} |
| 1857 |
/* BUG_ON(p - data != E1000_STATS_LEN * ETH_GSTRING_LEN); */ |
| 1858 |
break; |
| 1859 |
} |
| 1860 |
} |
| 1861 |
|
| 1862 |
static const struct ethtool_ops e1000_ethtool_ops = { |
| 1863 |
.supported_coalesce_params = ETHTOOL_COALESCE_RX_USECS, |
| 1864 |
.get_drvinfo = e1000_get_drvinfo, |
| 1865 |
.get_regs_len = e1000_get_regs_len, |
| 1866 |
.get_regs = e1000_get_regs, |
| 1867 |
.get_wol = e1000_get_wol, |
| 1868 |
.set_wol = e1000_set_wol, |
| 1869 |
.get_msglevel = e1000_get_msglevel, |
| 1870 |
.set_msglevel = e1000_set_msglevel, |
| 1871 |
.nway_reset = e1000_nway_reset, |
| 1872 |
.get_link = e1000_get_link, |
| 1873 |
.get_eeprom_len = e1000_get_eeprom_len, |
| 1874 |
.get_eeprom = e1000_get_eeprom, |
| 1875 |
.set_eeprom = e1000_set_eeprom, |
| 1876 |
.get_ringparam = e1000_get_ringparam, |
| 1877 |
.set_ringparam = e1000_set_ringparam, |
| 1878 |
.get_pauseparam = e1000_get_pauseparam, |
| 1879 |
.set_pauseparam = e1000_set_pauseparam, |
| 1880 |
.self_test = e1000_diag_test, |
| 1881 |
.get_strings = e1000_get_strings, |
| 1882 |
.set_phys_id = e1000_set_phys_id, |
| 1883 |
.get_ethtool_stats = e1000_get_ethtool_stats, |
| 1884 |
.get_sset_count = e1000_get_sset_count, |
| 1885 |
.get_coalesce = e1000_get_coalesce, |
| 1886 |
.set_coalesce = e1000_set_coalesce, |
| 1887 |
.get_ts_info = ethtool_op_get_ts_info, |
| 1888 |
.get_link_ksettings = e1000_get_link_ksettings, |
| 1889 |
.set_link_ksettings = e1000_set_link_ksettings, |
| 1890 |
}; |
| 1891 |
|
| 1892 |
void e1000_set_ethtool_ops(struct net_device *netdev) |
| 1893 |
{ |
| 1894 |
netdev->ethtool_ops = &e1000_ethtool_ops; |
| 1895 |
} |