2 * Copyright (C) 1999 - 2010 Intel Corporation.
3 * Copyright (C) 2010 OKI SEMICONDUCTOR Co., LTD.
5 * This code was derived from the Intel e1000e Linux driver.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20 #include "pch_gbe_api.h"
23 * pch_gbe_stats - Stats item information
25 struct pch_gbe_stats {
26 char string[ETH_GSTRING_LEN];
31 #define PCH_GBE_STAT(m) \
34 .size = FIELD_SIZEOF(struct pch_gbe_hw_stats, m), \
35 .offset = offsetof(struct pch_gbe_hw_stats, m), \
39 * pch_gbe_gstrings_stats - ethtool information status name list
41 static const struct pch_gbe_stats pch_gbe_gstrings_stats[] = {
42 PCH_GBE_STAT(rx_packets),
43 PCH_GBE_STAT(tx_packets),
44 PCH_GBE_STAT(rx_bytes),
45 PCH_GBE_STAT(tx_bytes),
46 PCH_GBE_STAT(rx_errors),
47 PCH_GBE_STAT(tx_errors),
48 PCH_GBE_STAT(rx_dropped),
49 PCH_GBE_STAT(tx_dropped),
50 PCH_GBE_STAT(multicast),
51 PCH_GBE_STAT(collisions),
52 PCH_GBE_STAT(rx_crc_errors),
53 PCH_GBE_STAT(rx_frame_errors),
54 PCH_GBE_STAT(rx_alloc_buff_failed),
55 PCH_GBE_STAT(tx_length_errors),
56 PCH_GBE_STAT(tx_aborted_errors),
57 PCH_GBE_STAT(tx_carrier_errors),
58 PCH_GBE_STAT(tx_timeout_count),
59 PCH_GBE_STAT(tx_restart_count),
60 PCH_GBE_STAT(intr_rx_dsc_empty_count),
61 PCH_GBE_STAT(intr_rx_frame_err_count),
62 PCH_GBE_STAT(intr_rx_fifo_err_count),
63 PCH_GBE_STAT(intr_rx_dma_err_count),
64 PCH_GBE_STAT(intr_tx_fifo_err_count),
65 PCH_GBE_STAT(intr_tx_dma_err_count),
66 PCH_GBE_STAT(intr_tcpip_err_count)
69 #define PCH_GBE_QUEUE_STATS_LEN 0
70 #define PCH_GBE_GLOBAL_STATS_LEN ARRAY_SIZE(pch_gbe_gstrings_stats)
71 #define PCH_GBE_STATS_LEN (PCH_GBE_GLOBAL_STATS_LEN + PCH_GBE_QUEUE_STATS_LEN)
73 #define PCH_GBE_MAC_REGS_LEN (sizeof(struct pch_gbe_regs) / 4)
74 #define PCH_GBE_REGS_LEN (PCH_GBE_MAC_REGS_LEN + PCH_GBE_PHY_REGS_LEN)
76 * pch_gbe_get_settings - Get device-specific settings
77 * @netdev: Network interface device structure
78 * @ecmd: Ethtool command
81 * Negative value: Failed.
83 static int pch_gbe_get_settings(struct net_device *netdev,
84 struct ethtool_cmd *ecmd)
86 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
89 ret = mii_ethtool_gset(&adapter->mii, ecmd);
90 ecmd->supported &= ~(SUPPORTED_TP | SUPPORTED_1000baseT_Half);
91 ecmd->advertising &= ~(ADVERTISED_TP | ADVERTISED_1000baseT_Half);
93 if (!netif_carrier_ok(adapter->netdev))
94 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
99 * pch_gbe_set_settings - Set device-specific settings
100 * @netdev: Network interface device structure
101 * @ecmd: Ethtool command
104 * Negative value: Failed.
106 static int pch_gbe_set_settings(struct net_device *netdev,
107 struct ethtool_cmd *ecmd)
109 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
110 struct pch_gbe_hw *hw = &adapter->hw;
111 u32 speed = ethtool_cmd_speed(ecmd);
114 pch_gbe_hal_write_phy_reg(hw, MII_BMCR, BMCR_RESET);
116 /* when set_settings() is called with a ethtool_cmd previously
117 * filled by get_settings() on a down link, speed is -1: */
118 if (speed == UINT_MAX) {
120 ethtool_cmd_speed_set(ecmd, speed);
121 ecmd->duplex = DUPLEX_FULL;
123 ret = mii_ethtool_sset(&adapter->mii, ecmd);
125 netdev_err(netdev, "Error: mii_ethtool_sset\n");
128 hw->mac.link_speed = speed;
129 hw->mac.link_duplex = ecmd->duplex;
130 hw->phy.autoneg_advertised = ecmd->advertising;
131 hw->mac.autoneg = ecmd->autoneg;
134 if (netif_running(adapter->netdev)) {
135 pch_gbe_down(adapter);
136 ret = pch_gbe_up(adapter);
138 pch_gbe_reset(adapter);
144 * pch_gbe_get_regs_len - Report the size of device registers
145 * @netdev: Network interface device structure
146 * Returns: the size of device registers.
148 static int pch_gbe_get_regs_len(struct net_device *netdev)
150 return PCH_GBE_REGS_LEN * (int)sizeof(u32);
154 * pch_gbe_get_drvinfo - Report driver information
155 * @netdev: Network interface device structure
156 * @drvinfo: Driver information structure
158 static void pch_gbe_get_drvinfo(struct net_device *netdev,
159 struct ethtool_drvinfo *drvinfo)
161 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
163 strlcpy(drvinfo->driver, KBUILD_MODNAME, sizeof(drvinfo->driver));
164 strlcpy(drvinfo->version, pch_driver_version, sizeof(drvinfo->version));
165 strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
166 sizeof(drvinfo->bus_info));
170 * pch_gbe_get_regs - Get device registers
171 * @netdev: Network interface device structure
172 * @regs: Ethtool register structure
173 * @p: Buffer pointer of read device register date
175 static void pch_gbe_get_regs(struct net_device *netdev,
176 struct ethtool_regs *regs, void *p)
178 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
179 struct pch_gbe_hw *hw = &adapter->hw;
180 struct pci_dev *pdev = adapter->pdev;
184 regs->version = 0x1000000 | (__u32)pdev->revision << 16 | pdev->device;
185 for (i = 0; i < PCH_GBE_MAC_REGS_LEN; i++)
186 *regs_buff++ = ioread32(&hw->reg->INT_ST + i);
188 for (i = 0; i < PCH_GBE_PHY_REGS_LEN; i++) {
189 pch_gbe_hal_read_phy_reg(&adapter->hw, i, &tmp);
195 * pch_gbe_get_wol - Report whether Wake-on-Lan is enabled
196 * @netdev: Network interface device structure
197 * @wol: Wake-on-Lan information
199 static void pch_gbe_get_wol(struct net_device *netdev,
200 struct ethtool_wolinfo *wol)
202 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
204 wol->supported = WAKE_UCAST | WAKE_MCAST | WAKE_BCAST | WAKE_MAGIC;
207 if ((adapter->wake_up_evt & PCH_GBE_WLC_IND))
208 wol->wolopts |= WAKE_UCAST;
209 if ((adapter->wake_up_evt & PCH_GBE_WLC_MLT))
210 wol->wolopts |= WAKE_MCAST;
211 if ((adapter->wake_up_evt & PCH_GBE_WLC_BR))
212 wol->wolopts |= WAKE_BCAST;
213 if ((adapter->wake_up_evt & PCH_GBE_WLC_MP))
214 wol->wolopts |= WAKE_MAGIC;
218 * pch_gbe_set_wol - Turn Wake-on-Lan on or off
219 * @netdev: Network interface device structure
220 * @wol: Pointer of wake-on-Lan information straucture
223 * Negative value: Failed.
225 static int pch_gbe_set_wol(struct net_device *netdev,
226 struct ethtool_wolinfo *wol)
228 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
230 if ((wol->wolopts & (WAKE_PHY | WAKE_ARP | WAKE_MAGICSECURE)))
232 /* these settings will always override what we currently have */
233 adapter->wake_up_evt = 0;
235 if ((wol->wolopts & WAKE_UCAST))
236 adapter->wake_up_evt |= PCH_GBE_WLC_IND;
237 if ((wol->wolopts & WAKE_MCAST))
238 adapter->wake_up_evt |= PCH_GBE_WLC_MLT;
239 if ((wol->wolopts & WAKE_BCAST))
240 adapter->wake_up_evt |= PCH_GBE_WLC_BR;
241 if ((wol->wolopts & WAKE_MAGIC))
242 adapter->wake_up_evt |= PCH_GBE_WLC_MP;
247 * pch_gbe_nway_reset - Restart autonegotiation
248 * @netdev: Network interface device structure
251 * Negative value: Failed.
253 static int pch_gbe_nway_reset(struct net_device *netdev)
255 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
257 return mii_nway_restart(&adapter->mii);
261 * pch_gbe_get_ringparam - Report ring sizes
262 * @netdev: Network interface device structure
263 * @ring: Ring param structure
265 static void pch_gbe_get_ringparam(struct net_device *netdev,
266 struct ethtool_ringparam *ring)
268 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
269 struct pch_gbe_tx_ring *txdr = adapter->tx_ring;
270 struct pch_gbe_rx_ring *rxdr = adapter->rx_ring;
272 ring->rx_max_pending = PCH_GBE_MAX_RXD;
273 ring->tx_max_pending = PCH_GBE_MAX_TXD;
274 ring->rx_pending = rxdr->count;
275 ring->tx_pending = txdr->count;
279 * pch_gbe_set_ringparam - Set ring sizes
280 * @netdev: Network interface device structure
281 * @ring: Ring param structure
284 * Negative value: Failed.
286 static int pch_gbe_set_ringparam(struct net_device *netdev,
287 struct ethtool_ringparam *ring)
289 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
290 struct pch_gbe_tx_ring *txdr, *tx_old;
291 struct pch_gbe_rx_ring *rxdr, *rx_old;
292 int tx_ring_size, rx_ring_size;
295 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
297 tx_ring_size = (int)sizeof(struct pch_gbe_tx_ring);
298 rx_ring_size = (int)sizeof(struct pch_gbe_rx_ring);
300 if ((netif_running(adapter->netdev)))
301 pch_gbe_down(adapter);
302 tx_old = adapter->tx_ring;
303 rx_old = adapter->rx_ring;
305 txdr = kzalloc(tx_ring_size, GFP_KERNEL);
310 rxdr = kzalloc(rx_ring_size, GFP_KERNEL);
315 adapter->tx_ring = txdr;
316 adapter->rx_ring = rxdr;
319 clamp_val(ring->rx_pending, PCH_GBE_MIN_RXD, PCH_GBE_MAX_RXD);
320 rxdr->count = roundup(rxdr->count, PCH_GBE_RX_DESC_MULTIPLE);
323 clamp_val(ring->tx_pending, PCH_GBE_MIN_RXD, PCH_GBE_MAX_RXD);
324 txdr->count = roundup(txdr->count, PCH_GBE_TX_DESC_MULTIPLE);
326 if ((netif_running(adapter->netdev))) {
327 /* Try to get new resources before deleting old */
328 err = pch_gbe_setup_rx_resources(adapter, adapter->rx_ring);
331 err = pch_gbe_setup_tx_resources(adapter, adapter->tx_ring);
334 /* save the new, restore the old in order to free it,
335 * then restore the new back again */
337 adapter->rx_ring = rx_old;
338 adapter->tx_ring = tx_old;
339 pch_gbe_free_rx_resources(adapter, adapter->rx_ring);
340 pch_gbe_free_tx_resources(adapter, adapter->tx_ring);
343 adapter->rx_ring = rxdr;
344 adapter->tx_ring = txdr;
346 pch_gbe_free_rx_resources(adapter, rx_old);
347 pch_gbe_free_tx_resources(adapter, tx_old);
350 adapter->rx_ring = rxdr;
351 adapter->tx_ring = txdr;
353 err = pch_gbe_up(adapter);
358 pch_gbe_free_rx_resources(adapter, adapter->rx_ring);
360 adapter->rx_ring = rx_old;
361 adapter->tx_ring = tx_old;
366 if (netif_running(adapter->netdev))
372 * pch_gbe_get_pauseparam - Report pause parameters
373 * @netdev: Network interface device structure
374 * @pause: Pause parameters structure
376 static void pch_gbe_get_pauseparam(struct net_device *netdev,
377 struct ethtool_pauseparam *pause)
379 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
380 struct pch_gbe_hw *hw = &adapter->hw;
383 ((hw->mac.fc_autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE);
385 if (hw->mac.fc == PCH_GBE_FC_RX_PAUSE) {
387 } else if (hw->mac.fc == PCH_GBE_FC_TX_PAUSE) {
389 } else if (hw->mac.fc == PCH_GBE_FC_FULL) {
396 * pch_gbe_set_pauseparam - Set pause parameters
397 * @netdev: Network interface device structure
398 * @pause: Pause parameters structure
401 * Negative value: Failed.
403 static int pch_gbe_set_pauseparam(struct net_device *netdev,
404 struct ethtool_pauseparam *pause)
406 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
407 struct pch_gbe_hw *hw = &adapter->hw;
410 hw->mac.fc_autoneg = pause->autoneg;
411 if ((pause->rx_pause) && (pause->tx_pause))
412 hw->mac.fc = PCH_GBE_FC_FULL;
413 else if ((pause->rx_pause) && (!pause->tx_pause))
414 hw->mac.fc = PCH_GBE_FC_RX_PAUSE;
415 else if ((!pause->rx_pause) && (pause->tx_pause))
416 hw->mac.fc = PCH_GBE_FC_TX_PAUSE;
417 else if ((!pause->rx_pause) && (!pause->tx_pause))
418 hw->mac.fc = PCH_GBE_FC_NONE;
420 if (hw->mac.fc_autoneg == AUTONEG_ENABLE) {
421 if ((netif_running(adapter->netdev))) {
422 pch_gbe_down(adapter);
423 ret = pch_gbe_up(adapter);
425 pch_gbe_reset(adapter);
428 ret = pch_gbe_mac_force_mac_fc(hw);
434 * pch_gbe_get_strings - Return a set of strings that describe the requested
436 * @netdev: Network interface device structure
437 * @stringset: Select the stringset. [ETH_SS_TEST] [ETH_SS_STATS]
438 * @data: Pointer of read string data.
440 static void pch_gbe_get_strings(struct net_device *netdev, u32 stringset,
447 case (u32) ETH_SS_STATS:
448 for (i = 0; i < PCH_GBE_GLOBAL_STATS_LEN; i++) {
449 memcpy(p, pch_gbe_gstrings_stats[i].string,
451 p += ETH_GSTRING_LEN;
458 * pch_gbe_get_ethtool_stats - Return statistics about the device
459 * @netdev: Network interface device structure
460 * @stats: Ethtool statue structure
461 * @data: Pointer of read status area
463 static void pch_gbe_get_ethtool_stats(struct net_device *netdev,
464 struct ethtool_stats *stats, u64 *data)
466 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
468 const struct pch_gbe_stats *gstats = pch_gbe_gstrings_stats;
469 char *hw_stats = (char *)&adapter->stats;
471 pch_gbe_update_stats(adapter);
472 for (i = 0; i < PCH_GBE_GLOBAL_STATS_LEN; i++) {
473 char *p = hw_stats + gstats->offset;
474 data[i] = gstats->size == sizeof(u64) ? *(u64 *)p:(*(u32 *)p);
479 static int pch_gbe_get_sset_count(struct net_device *netdev, int sset)
483 return PCH_GBE_STATS_LEN;
489 static const struct ethtool_ops pch_gbe_ethtool_ops = {
490 .get_settings = pch_gbe_get_settings,
491 .set_settings = pch_gbe_set_settings,
492 .get_drvinfo = pch_gbe_get_drvinfo,
493 .get_regs_len = pch_gbe_get_regs_len,
494 .get_regs = pch_gbe_get_regs,
495 .get_wol = pch_gbe_get_wol,
496 .set_wol = pch_gbe_set_wol,
497 .nway_reset = pch_gbe_nway_reset,
498 .get_link = ethtool_op_get_link,
499 .get_ringparam = pch_gbe_get_ringparam,
500 .set_ringparam = pch_gbe_set_ringparam,
501 .get_pauseparam = pch_gbe_get_pauseparam,
502 .set_pauseparam = pch_gbe_set_pauseparam,
503 .get_strings = pch_gbe_get_strings,
504 .get_ethtool_stats = pch_gbe_get_ethtool_stats,
505 .get_sset_count = pch_gbe_get_sset_count,
508 void pch_gbe_set_ethtool_ops(struct net_device *netdev)
510 netdev->ethtool_ops = &pch_gbe_ethtool_ops;