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, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
21 #include "pch_gbe_api.h"
24 * pch_gbe_stats - Stats item information
26 struct pch_gbe_stats
{
27 char string
[ETH_GSTRING_LEN
];
32 #define PCH_GBE_STAT(m) \
35 .size = FIELD_SIZEOF(struct pch_gbe_hw_stats, m), \
36 .offset = offsetof(struct pch_gbe_hw_stats, m), \
40 * pch_gbe_gstrings_stats - ethtool information status name list
42 static const struct pch_gbe_stats pch_gbe_gstrings_stats
[] = {
43 PCH_GBE_STAT(rx_packets
),
44 PCH_GBE_STAT(tx_packets
),
45 PCH_GBE_STAT(rx_bytes
),
46 PCH_GBE_STAT(tx_bytes
),
47 PCH_GBE_STAT(rx_errors
),
48 PCH_GBE_STAT(tx_errors
),
49 PCH_GBE_STAT(rx_dropped
),
50 PCH_GBE_STAT(tx_dropped
),
51 PCH_GBE_STAT(multicast
),
52 PCH_GBE_STAT(collisions
),
53 PCH_GBE_STAT(rx_crc_errors
),
54 PCH_GBE_STAT(rx_frame_errors
),
55 PCH_GBE_STAT(rx_alloc_buff_failed
),
56 PCH_GBE_STAT(tx_length_errors
),
57 PCH_GBE_STAT(tx_aborted_errors
),
58 PCH_GBE_STAT(tx_carrier_errors
),
59 PCH_GBE_STAT(tx_timeout_count
),
60 PCH_GBE_STAT(tx_restart_count
),
61 PCH_GBE_STAT(intr_rx_dsc_empty_count
),
62 PCH_GBE_STAT(intr_rx_frame_err_count
),
63 PCH_GBE_STAT(intr_rx_fifo_err_count
),
64 PCH_GBE_STAT(intr_rx_dma_err_count
),
65 PCH_GBE_STAT(intr_tx_fifo_err_count
),
66 PCH_GBE_STAT(intr_tx_dma_err_count
),
67 PCH_GBE_STAT(intr_tcpip_err_count
)
70 #define PCH_GBE_QUEUE_STATS_LEN 0
71 #define PCH_GBE_GLOBAL_STATS_LEN ARRAY_SIZE(pch_gbe_gstrings_stats)
72 #define PCH_GBE_STATS_LEN (PCH_GBE_GLOBAL_STATS_LEN + PCH_GBE_QUEUE_STATS_LEN)
74 #define PCH_GBE_MAC_REGS_LEN (sizeof(struct pch_gbe_regs) / 4)
75 #define PCH_GBE_REGS_LEN (PCH_GBE_MAC_REGS_LEN + PCH_GBE_PHY_REGS_LEN)
77 * pch_gbe_get_settings - Get device-specific settings
78 * @netdev: Network interface device structure
79 * @ecmd: Ethtool command
82 * Negative value: Failed.
84 static int pch_gbe_get_settings(struct net_device
*netdev
,
85 struct ethtool_cmd
*ecmd
)
87 struct pch_gbe_adapter
*adapter
= netdev_priv(netdev
);
90 ret
= mii_ethtool_gset(&adapter
->mii
, ecmd
);
91 ecmd
->supported
&= ~(SUPPORTED_TP
| SUPPORTED_1000baseT_Half
);
92 ecmd
->advertising
&= ~(ADVERTISED_TP
| ADVERTISED_1000baseT_Half
);
94 if (!netif_carrier_ok(adapter
->netdev
))
95 ethtool_cmd_speed_set(ecmd
, -1);
100 * pch_gbe_set_settings - Set device-specific settings
101 * @netdev: Network interface device structure
102 * @ecmd: Ethtool command
105 * Negative value: Failed.
107 static int pch_gbe_set_settings(struct net_device
*netdev
,
108 struct ethtool_cmd
*ecmd
)
110 struct pch_gbe_adapter
*adapter
= netdev_priv(netdev
);
111 struct pch_gbe_hw
*hw
= &adapter
->hw
;
112 u32 speed
= ethtool_cmd_speed(ecmd
);
115 pch_gbe_hal_write_phy_reg(hw
, MII_BMCR
, BMCR_RESET
);
117 /* when set_settings() is called with a ethtool_cmd previously
118 * filled by get_settings() on a down link, speed is -1: */
119 if (speed
== UINT_MAX
) {
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
));
167 drvinfo
->regdump_len
= pch_gbe_get_regs_len(netdev
);
171 * pch_gbe_get_regs - Get device registers
172 * @netdev: Network interface device structure
173 * @regs: Ethtool register structure
174 * @p: Buffer pointer of read device register date
176 static void pch_gbe_get_regs(struct net_device
*netdev
,
177 struct ethtool_regs
*regs
, void *p
)
179 struct pch_gbe_adapter
*adapter
= netdev_priv(netdev
);
180 struct pch_gbe_hw
*hw
= &adapter
->hw
;
181 struct pci_dev
*pdev
= adapter
->pdev
;
185 regs
->version
= 0x1000000 | (__u32
)pdev
->revision
<< 16 | pdev
->device
;
186 for (i
= 0; i
< PCH_GBE_MAC_REGS_LEN
; i
++)
187 *regs_buff
++ = ioread32(&hw
->reg
->INT_ST
+ i
);
189 for (i
= 0; i
< PCH_GBE_PHY_REGS_LEN
; i
++) {
190 pch_gbe_hal_read_phy_reg(&adapter
->hw
, i
, &tmp
);
196 * pch_gbe_get_wol - Report whether Wake-on-Lan is enabled
197 * @netdev: Network interface device structure
198 * @wol: Wake-on-Lan information
200 static void pch_gbe_get_wol(struct net_device
*netdev
,
201 struct ethtool_wolinfo
*wol
)
203 struct pch_gbe_adapter
*adapter
= netdev_priv(netdev
);
205 wol
->supported
= WAKE_UCAST
| WAKE_MCAST
| WAKE_BCAST
| WAKE_MAGIC
;
208 if ((adapter
->wake_up_evt
& PCH_GBE_WLC_IND
))
209 wol
->wolopts
|= WAKE_UCAST
;
210 if ((adapter
->wake_up_evt
& PCH_GBE_WLC_MLT
))
211 wol
->wolopts
|= WAKE_MCAST
;
212 if ((adapter
->wake_up_evt
& PCH_GBE_WLC_BR
))
213 wol
->wolopts
|= WAKE_BCAST
;
214 if ((adapter
->wake_up_evt
& PCH_GBE_WLC_MP
))
215 wol
->wolopts
|= WAKE_MAGIC
;
219 * pch_gbe_set_wol - Turn Wake-on-Lan on or off
220 * @netdev: Network interface device structure
221 * @wol: Pointer of wake-on-Lan information straucture
224 * Negative value: Failed.
226 static int pch_gbe_set_wol(struct net_device
*netdev
,
227 struct ethtool_wolinfo
*wol
)
229 struct pch_gbe_adapter
*adapter
= netdev_priv(netdev
);
231 if ((wol
->wolopts
& (WAKE_PHY
| WAKE_ARP
| WAKE_MAGICSECURE
)))
233 /* these settings will always override what we currently have */
234 adapter
->wake_up_evt
= 0;
236 if ((wol
->wolopts
& WAKE_UCAST
))
237 adapter
->wake_up_evt
|= PCH_GBE_WLC_IND
;
238 if ((wol
->wolopts
& WAKE_MCAST
))
239 adapter
->wake_up_evt
|= PCH_GBE_WLC_MLT
;
240 if ((wol
->wolopts
& WAKE_BCAST
))
241 adapter
->wake_up_evt
|= PCH_GBE_WLC_BR
;
242 if ((wol
->wolopts
& WAKE_MAGIC
))
243 adapter
->wake_up_evt
|= PCH_GBE_WLC_MP
;
248 * pch_gbe_nway_reset - Restart autonegotiation
249 * @netdev: Network interface device structure
252 * Negative value: Failed.
254 static int pch_gbe_nway_reset(struct net_device
*netdev
)
256 struct pch_gbe_adapter
*adapter
= netdev_priv(netdev
);
258 return mii_nway_restart(&adapter
->mii
);
262 * pch_gbe_get_ringparam - Report ring sizes
263 * @netdev: Network interface device structure
264 * @ring: Ring param structure
266 static void pch_gbe_get_ringparam(struct net_device
*netdev
,
267 struct ethtool_ringparam
*ring
)
269 struct pch_gbe_adapter
*adapter
= netdev_priv(netdev
);
270 struct pch_gbe_tx_ring
*txdr
= adapter
->tx_ring
;
271 struct pch_gbe_rx_ring
*rxdr
= adapter
->rx_ring
;
273 ring
->rx_max_pending
= PCH_GBE_MAX_RXD
;
274 ring
->tx_max_pending
= PCH_GBE_MAX_TXD
;
275 ring
->rx_pending
= rxdr
->count
;
276 ring
->tx_pending
= txdr
->count
;
280 * pch_gbe_set_ringparam - Set ring sizes
281 * @netdev: Network interface device structure
282 * @ring: Ring param structure
285 * Negative value: Failed.
287 static int pch_gbe_set_ringparam(struct net_device
*netdev
,
288 struct ethtool_ringparam
*ring
)
290 struct pch_gbe_adapter
*adapter
= netdev_priv(netdev
);
291 struct pch_gbe_tx_ring
*txdr
, *tx_old
;
292 struct pch_gbe_rx_ring
*rxdr
, *rx_old
;
293 int tx_ring_size
, rx_ring_size
;
296 if ((ring
->rx_mini_pending
) || (ring
->rx_jumbo_pending
))
298 tx_ring_size
= (int)sizeof(struct pch_gbe_tx_ring
);
299 rx_ring_size
= (int)sizeof(struct pch_gbe_rx_ring
);
301 if ((netif_running(adapter
->netdev
)))
302 pch_gbe_down(adapter
);
303 tx_old
= adapter
->tx_ring
;
304 rx_old
= adapter
->rx_ring
;
306 txdr
= kzalloc(tx_ring_size
, GFP_KERNEL
);
311 rxdr
= kzalloc(rx_ring_size
, GFP_KERNEL
);
316 adapter
->tx_ring
= txdr
;
317 adapter
->rx_ring
= rxdr
;
320 clamp_val(ring
->rx_pending
, PCH_GBE_MIN_RXD
, PCH_GBE_MAX_RXD
);
321 rxdr
->count
= roundup(rxdr
->count
, PCH_GBE_RX_DESC_MULTIPLE
);
324 clamp_val(ring
->tx_pending
, PCH_GBE_MIN_RXD
, PCH_GBE_MAX_RXD
);
325 txdr
->count
= roundup(txdr
->count
, PCH_GBE_TX_DESC_MULTIPLE
);
327 if ((netif_running(adapter
->netdev
))) {
328 /* Try to get new resources before deleting old */
329 err
= pch_gbe_setup_rx_resources(adapter
, adapter
->rx_ring
);
332 err
= pch_gbe_setup_tx_resources(adapter
, adapter
->tx_ring
);
335 /* save the new, restore the old in order to free it,
336 * then restore the new back again */
338 adapter
->rx_ring
= rx_old
;
339 adapter
->tx_ring
= tx_old
;
340 pch_gbe_free_rx_resources(adapter
, adapter
->rx_ring
);
341 pch_gbe_free_tx_resources(adapter
, adapter
->tx_ring
);
344 adapter
->rx_ring
= rxdr
;
345 adapter
->tx_ring
= txdr
;
347 pch_gbe_free_rx_resources(adapter
, rx_old
);
348 pch_gbe_free_tx_resources(adapter
, tx_old
);
351 adapter
->rx_ring
= rxdr
;
352 adapter
->tx_ring
= txdr
;
354 err
= pch_gbe_up(adapter
);
359 pch_gbe_free_rx_resources(adapter
, adapter
->rx_ring
);
361 adapter
->rx_ring
= rx_old
;
362 adapter
->tx_ring
= tx_old
;
367 if (netif_running(adapter
->netdev
))
373 * pch_gbe_get_pauseparam - Report pause parameters
374 * @netdev: Network interface device structure
375 * @pause: Pause parameters structure
377 static void pch_gbe_get_pauseparam(struct net_device
*netdev
,
378 struct ethtool_pauseparam
*pause
)
380 struct pch_gbe_adapter
*adapter
= netdev_priv(netdev
);
381 struct pch_gbe_hw
*hw
= &adapter
->hw
;
384 ((hw
->mac
.fc_autoneg
) ? AUTONEG_ENABLE
: AUTONEG_DISABLE
);
386 if (hw
->mac
.fc
== PCH_GBE_FC_RX_PAUSE
) {
388 } else if (hw
->mac
.fc
== PCH_GBE_FC_TX_PAUSE
) {
390 } else if (hw
->mac
.fc
== PCH_GBE_FC_FULL
) {
397 * pch_gbe_set_pauseparam - Set pause paramters
398 * @netdev: Network interface device structure
399 * @pause: Pause parameters structure
402 * Negative value: Failed.
404 static int pch_gbe_set_pauseparam(struct net_device
*netdev
,
405 struct ethtool_pauseparam
*pause
)
407 struct pch_gbe_adapter
*adapter
= netdev_priv(netdev
);
408 struct pch_gbe_hw
*hw
= &adapter
->hw
;
411 hw
->mac
.fc_autoneg
= pause
->autoneg
;
412 if ((pause
->rx_pause
) && (pause
->tx_pause
))
413 hw
->mac
.fc
= PCH_GBE_FC_FULL
;
414 else if ((pause
->rx_pause
) && (!pause
->tx_pause
))
415 hw
->mac
.fc
= PCH_GBE_FC_RX_PAUSE
;
416 else if ((!pause
->rx_pause
) && (pause
->tx_pause
))
417 hw
->mac
.fc
= PCH_GBE_FC_TX_PAUSE
;
418 else if ((!pause
->rx_pause
) && (!pause
->tx_pause
))
419 hw
->mac
.fc
= PCH_GBE_FC_NONE
;
421 if (hw
->mac
.fc_autoneg
== AUTONEG_ENABLE
) {
422 if ((netif_running(adapter
->netdev
))) {
423 pch_gbe_down(adapter
);
424 ret
= pch_gbe_up(adapter
);
426 pch_gbe_reset(adapter
);
429 ret
= pch_gbe_mac_force_mac_fc(hw
);
435 * pch_gbe_get_strings - Return a set of strings that describe the requested
437 * @netdev: Network interface device structure
438 * @stringset: Select the stringset. [ETH_SS_TEST] [ETH_SS_STATS]
439 * @data: Pointer of read string data.
441 static void pch_gbe_get_strings(struct net_device
*netdev
, u32 stringset
,
448 case (u32
) ETH_SS_STATS
:
449 for (i
= 0; i
< PCH_GBE_GLOBAL_STATS_LEN
; i
++) {
450 memcpy(p
, pch_gbe_gstrings_stats
[i
].string
,
452 p
+= ETH_GSTRING_LEN
;
459 * pch_gbe_get_ethtool_stats - Return statistics about the device
460 * @netdev: Network interface device structure
461 * @stats: Ethtool statue structure
462 * @data: Pointer of read status area
464 static void pch_gbe_get_ethtool_stats(struct net_device
*netdev
,
465 struct ethtool_stats
*stats
, u64
*data
)
467 struct pch_gbe_adapter
*adapter
= netdev_priv(netdev
);
469 const struct pch_gbe_stats
*gstats
= pch_gbe_gstrings_stats
;
470 char *hw_stats
= (char *)&adapter
->stats
;
472 pch_gbe_update_stats(adapter
);
473 for (i
= 0; i
< PCH_GBE_GLOBAL_STATS_LEN
; i
++) {
474 char *p
= hw_stats
+ gstats
->offset
;
475 data
[i
] = gstats
->size
== sizeof(u64
) ? *(u64
*)p
:(*(u32
*)p
);
480 static int pch_gbe_get_sset_count(struct net_device
*netdev
, int sset
)
484 return PCH_GBE_STATS_LEN
;
490 static const struct ethtool_ops pch_gbe_ethtool_ops
= {
491 .get_settings
= pch_gbe_get_settings
,
492 .set_settings
= pch_gbe_set_settings
,
493 .get_drvinfo
= pch_gbe_get_drvinfo
,
494 .get_regs_len
= pch_gbe_get_regs_len
,
495 .get_regs
= pch_gbe_get_regs
,
496 .get_wol
= pch_gbe_get_wol
,
497 .set_wol
= pch_gbe_set_wol
,
498 .nway_reset
= pch_gbe_nway_reset
,
499 .get_link
= ethtool_op_get_link
,
500 .get_ringparam
= pch_gbe_get_ringparam
,
501 .set_ringparam
= pch_gbe_set_ringparam
,
502 .get_pauseparam
= pch_gbe_get_pauseparam
,
503 .set_pauseparam
= pch_gbe_set_pauseparam
,
504 .get_strings
= pch_gbe_get_strings
,
505 .get_ethtool_stats
= pch_gbe_get_ethtool_stats
,
506 .get_sset_count
= pch_gbe_get_sset_count
,
509 void pch_gbe_set_ethtool_ops(struct net_device
*netdev
)
511 SET_ETHTOOL_OPS(netdev
, &pch_gbe_ethtool_ops
);