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 infomation
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
))
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
;
114 pch_gbe_hal_write_phy_reg(hw
, MII_BMCR
, BMCR_RESET
);
116 if (ecmd
->speed
== -1)
117 ecmd
->speed
= SPEED_1000
;
118 ecmd
->duplex
= DUPLEX_FULL
;
119 ret
= mii_ethtool_sset(&adapter
->mii
, ecmd
);
121 pr_err("Error: mii_ethtool_sset\n");
124 hw
->mac
.link_speed
= ecmd
->speed
;
125 hw
->mac
.link_duplex
= ecmd
->duplex
;
126 hw
->phy
.autoneg_advertised
= ecmd
->advertising
;
127 hw
->mac
.autoneg
= ecmd
->autoneg
;
128 pch_gbe_hal_phy_sw_reset(hw
);
131 if (netif_running(adapter
->netdev
)) {
132 pch_gbe_down(adapter
);
133 ret
= pch_gbe_up(adapter
);
135 pch_gbe_reset(adapter
);
141 * pch_gbe_get_regs_len - Report the size of device registers
142 * @netdev: Network interface device structure
143 * Returns: the size of device registers.
145 static int pch_gbe_get_regs_len(struct net_device
*netdev
)
147 return PCH_GBE_REGS_LEN
* (int)sizeof(u32
);
151 * pch_gbe_get_drvinfo - Report driver information
152 * @netdev: Network interface device structure
153 * @drvinfo: Driver information structure
155 static void pch_gbe_get_drvinfo(struct net_device
*netdev
,
156 struct ethtool_drvinfo
*drvinfo
)
158 struct pch_gbe_adapter
*adapter
= netdev_priv(netdev
);
160 strcpy(drvinfo
->driver
, KBUILD_MODNAME
);
161 strcpy(drvinfo
->version
, pch_driver_version
);
162 strcpy(drvinfo
->fw_version
, "N/A");
163 strcpy(drvinfo
->bus_info
, pci_name(adapter
->pdev
));
164 drvinfo
->regdump_len
= pch_gbe_get_regs_len(netdev
);
168 * pch_gbe_get_regs - Get device registers
169 * @netdev: Network interface device structure
170 * @regs: Ethtool register structure
171 * @p: Buffer pointer of read device register date
173 static void pch_gbe_get_regs(struct net_device
*netdev
,
174 struct ethtool_regs
*regs
, void *p
)
176 struct pch_gbe_adapter
*adapter
= netdev_priv(netdev
);
177 struct pch_gbe_hw
*hw
= &adapter
->hw
;
178 struct pci_dev
*pdev
= adapter
->pdev
;
182 regs
->version
= 0x1000000 | (__u32
)pdev
->revision
<< 16 | pdev
->device
;
183 for (i
= 0; i
< PCH_GBE_MAC_REGS_LEN
; i
++)
184 *regs_buff
++ = ioread32(&hw
->reg
->INT_ST
+ i
);
186 for (i
= 0; i
< PCH_GBE_PHY_REGS_LEN
; i
++) {
187 pch_gbe_hal_read_phy_reg(&adapter
->hw
, i
, &tmp
);
193 * pch_gbe_get_wol - Report whether Wake-on-Lan is enabled
194 * @netdev: Network interface device structure
195 * @wol: Wake-on-Lan information
197 static void pch_gbe_get_wol(struct net_device
*netdev
,
198 struct ethtool_wolinfo
*wol
)
200 struct pch_gbe_adapter
*adapter
= netdev_priv(netdev
);
202 wol
->supported
= WAKE_UCAST
| WAKE_MCAST
| WAKE_BCAST
| WAKE_MAGIC
;
205 if ((adapter
->wake_up_evt
& PCH_GBE_WLC_IND
))
206 wol
->wolopts
|= WAKE_UCAST
;
207 if ((adapter
->wake_up_evt
& PCH_GBE_WLC_MLT
))
208 wol
->wolopts
|= WAKE_MCAST
;
209 if ((adapter
->wake_up_evt
& PCH_GBE_WLC_BR
))
210 wol
->wolopts
|= WAKE_BCAST
;
211 if ((adapter
->wake_up_evt
& PCH_GBE_WLC_MP
))
212 wol
->wolopts
|= WAKE_MAGIC
;
216 * pch_gbe_set_wol - Turn Wake-on-Lan on or off
217 * @netdev: Network interface device structure
218 * @wol: Pointer of wake-on-Lan information straucture
221 * Negative value: Failed.
223 static int pch_gbe_set_wol(struct net_device
*netdev
,
224 struct ethtool_wolinfo
*wol
)
226 struct pch_gbe_adapter
*adapter
= netdev_priv(netdev
);
228 if ((wol
->wolopts
& (WAKE_PHY
| WAKE_ARP
| WAKE_MAGICSECURE
)))
230 /* these settings will always override what we currently have */
231 adapter
->wake_up_evt
= 0;
233 if ((wol
->wolopts
& WAKE_UCAST
))
234 adapter
->wake_up_evt
|= PCH_GBE_WLC_IND
;
235 if ((wol
->wolopts
& WAKE_MCAST
))
236 adapter
->wake_up_evt
|= PCH_GBE_WLC_MLT
;
237 if ((wol
->wolopts
& WAKE_BCAST
))
238 adapter
->wake_up_evt
|= PCH_GBE_WLC_BR
;
239 if ((wol
->wolopts
& WAKE_MAGIC
))
240 adapter
->wake_up_evt
|= PCH_GBE_WLC_MP
;
245 * pch_gbe_nway_reset - Restart autonegotiation
246 * @netdev: Network interface device structure
249 * Negative value: Failed.
251 static int pch_gbe_nway_reset(struct net_device
*netdev
)
253 struct pch_gbe_adapter
*adapter
= netdev_priv(netdev
);
255 return mii_nway_restart(&adapter
->mii
);
259 * pch_gbe_get_ringparam - Report ring sizes
260 * @netdev: Network interface device structure
261 * @ring: Ring param structure
263 static void pch_gbe_get_ringparam(struct net_device
*netdev
,
264 struct ethtool_ringparam
*ring
)
266 struct pch_gbe_adapter
*adapter
= netdev_priv(netdev
);
267 struct pch_gbe_tx_ring
*txdr
= adapter
->tx_ring
;
268 struct pch_gbe_rx_ring
*rxdr
= adapter
->rx_ring
;
270 ring
->rx_max_pending
= PCH_GBE_MAX_RXD
;
271 ring
->tx_max_pending
= PCH_GBE_MAX_TXD
;
272 ring
->rx_mini_max_pending
= 0;
273 ring
->rx_jumbo_max_pending
= 0;
274 ring
->rx_pending
= rxdr
->count
;
275 ring
->tx_pending
= txdr
->count
;
276 ring
->rx_mini_pending
= 0;
277 ring
->rx_jumbo_pending
= 0;
281 * pch_gbe_set_ringparam - Set ring sizes
282 * @netdev: Network interface device structure
283 * @ring: Ring param structure
286 * Negative value: Failed.
288 static int pch_gbe_set_ringparam(struct net_device
*netdev
,
289 struct ethtool_ringparam
*ring
)
291 struct pch_gbe_adapter
*adapter
= netdev_priv(netdev
);
292 struct pch_gbe_tx_ring
*txdr
, *tx_old
;
293 struct pch_gbe_rx_ring
*rxdr
, *rx_old
;
294 int tx_ring_size
, rx_ring_size
;
297 if ((ring
->rx_mini_pending
) || (ring
->rx_jumbo_pending
))
299 tx_ring_size
= (int)sizeof(struct pch_gbe_tx_ring
);
300 rx_ring_size
= (int)sizeof(struct pch_gbe_rx_ring
);
302 if ((netif_running(adapter
->netdev
)))
303 pch_gbe_down(adapter
);
304 tx_old
= adapter
->tx_ring
;
305 rx_old
= adapter
->rx_ring
;
307 txdr
= kzalloc(tx_ring_size
, GFP_KERNEL
);
312 rxdr
= kzalloc(rx_ring_size
, GFP_KERNEL
);
317 adapter
->tx_ring
= txdr
;
318 adapter
->rx_ring
= rxdr
;
321 clamp_val(ring
->rx_pending
, PCH_GBE_MIN_RXD
, PCH_GBE_MAX_RXD
);
322 rxdr
->count
= roundup(rxdr
->count
, PCH_GBE_RX_DESC_MULTIPLE
);
325 clamp_val(ring
->tx_pending
, PCH_GBE_MIN_RXD
, PCH_GBE_MAX_RXD
);
326 txdr
->count
= roundup(txdr
->count
, PCH_GBE_TX_DESC_MULTIPLE
);
328 if ((netif_running(adapter
->netdev
))) {
329 /* Try to get new resources before deleting old */
330 err
= pch_gbe_setup_rx_resources(adapter
, adapter
->rx_ring
);
333 err
= pch_gbe_setup_tx_resources(adapter
, adapter
->tx_ring
);
336 /* save the new, restore the old in order to free it,
337 * then restore the new back again */
339 adapter
->rx_ring
= rx_old
;
340 adapter
->tx_ring
= tx_old
;
341 pch_gbe_free_rx_resources(adapter
, adapter
->rx_ring
);
342 pch_gbe_free_tx_resources(adapter
, adapter
->tx_ring
);
345 adapter
->rx_ring
= rxdr
;
346 adapter
->tx_ring
= txdr
;
348 pch_gbe_free_rx_resources(adapter
, rx_old
);
349 pch_gbe_free_tx_resources(adapter
, tx_old
);
352 adapter
->rx_ring
= rxdr
;
353 adapter
->tx_ring
= txdr
;
355 err
= pch_gbe_up(adapter
);
360 pch_gbe_free_rx_resources(adapter
, adapter
->rx_ring
);
362 adapter
->rx_ring
= rx_old
;
363 adapter
->tx_ring
= tx_old
;
368 if (netif_running(adapter
->netdev
))
374 * pch_gbe_get_pauseparam - Report pause parameters
375 * @netdev: Network interface device structure
376 * @pause: Pause parameters structure
378 static void pch_gbe_get_pauseparam(struct net_device
*netdev
,
379 struct ethtool_pauseparam
*pause
)
381 struct pch_gbe_adapter
*adapter
= netdev_priv(netdev
);
382 struct pch_gbe_hw
*hw
= &adapter
->hw
;
385 ((hw
->mac
.fc_autoneg
) ? AUTONEG_ENABLE
: AUTONEG_DISABLE
);
387 if (hw
->mac
.fc
== PCH_GBE_FC_RX_PAUSE
) {
389 } else if (hw
->mac
.fc
== PCH_GBE_FC_TX_PAUSE
) {
391 } else if (hw
->mac
.fc
== PCH_GBE_FC_FULL
) {
398 * pch_gbe_set_pauseparam - Set pause paramters
399 * @netdev: Network interface device structure
400 * @pause: Pause parameters structure
403 * Negative value: Failed.
405 static int pch_gbe_set_pauseparam(struct net_device
*netdev
,
406 struct ethtool_pauseparam
*pause
)
408 struct pch_gbe_adapter
*adapter
= netdev_priv(netdev
);
409 struct pch_gbe_hw
*hw
= &adapter
->hw
;
412 hw
->mac
.fc_autoneg
= pause
->autoneg
;
413 if ((pause
->rx_pause
) && (pause
->tx_pause
))
414 hw
->mac
.fc
= PCH_GBE_FC_FULL
;
415 else if ((pause
->rx_pause
) && (!pause
->tx_pause
))
416 hw
->mac
.fc
= PCH_GBE_FC_RX_PAUSE
;
417 else if ((!pause
->rx_pause
) && (pause
->tx_pause
))
418 hw
->mac
.fc
= PCH_GBE_FC_TX_PAUSE
;
419 else if ((!pause
->rx_pause
) && (!pause
->tx_pause
))
420 hw
->mac
.fc
= PCH_GBE_FC_NONE
;
422 if (hw
->mac
.fc_autoneg
== AUTONEG_ENABLE
) {
423 if ((netif_running(adapter
->netdev
))) {
424 pch_gbe_down(adapter
);
425 ret
= pch_gbe_up(adapter
);
427 pch_gbe_reset(adapter
);
430 ret
= pch_gbe_mac_force_mac_fc(hw
);
436 * pch_gbe_get_rx_csum - Report whether receive checksums are turned on or off
437 * @netdev: Network interface device structure
439 * true(1): Checksum On
440 * false(0): Checksum Off
442 static u32
pch_gbe_get_rx_csum(struct net_device
*netdev
)
444 struct pch_gbe_adapter
*adapter
= netdev_priv(netdev
);
446 return adapter
->rx_csum
;
450 * pch_gbe_set_rx_csum - Turn receive checksum on or off
451 * @netdev: Network interface device structure
452 * @data: Checksum On[true] or Off[false]
455 * Negative value: Failed.
457 static int pch_gbe_set_rx_csum(struct net_device
*netdev
, u32 data
)
459 struct pch_gbe_adapter
*adapter
= netdev_priv(netdev
);
461 adapter
->rx_csum
= data
;
462 if ((netif_running(netdev
)))
463 pch_gbe_reinit_locked(adapter
);
465 pch_gbe_reset(adapter
);
471 * pch_gbe_get_tx_csum - Report whether transmit checksums are turned on or off
472 * @netdev: Network interface device structure
474 * true(1): Checksum On
475 * false(0): Checksum Off
477 static u32
pch_gbe_get_tx_csum(struct net_device
*netdev
)
479 return (netdev
->features
& NETIF_F_HW_CSUM
) != 0;
483 * pch_gbe_set_tx_csum - Turn transmit checksums on or off
484 * @netdev: Network interface device structure
485 * @data: Checksum on[true] or off[false]
488 * Negative value: Failed.
490 static int pch_gbe_set_tx_csum(struct net_device
*netdev
, u32 data
)
492 struct pch_gbe_adapter
*adapter
= netdev_priv(netdev
);
494 adapter
->tx_csum
= data
;
496 netdev
->features
|= NETIF_F_HW_CSUM
;
498 netdev
->features
&= ~NETIF_F_HW_CSUM
;
503 * pch_gbe_get_strings - Return a set of strings that describe the requested
505 * @netdev: Network interface device structure
506 * @stringset: Select the stringset. [ETH_SS_TEST] [ETH_SS_STATS]
507 * @data: Pointer of read string data.
509 static void pch_gbe_get_strings(struct net_device
*netdev
, u32 stringset
,
516 case (u32
) ETH_SS_STATS
:
517 for (i
= 0; i
< PCH_GBE_GLOBAL_STATS_LEN
; i
++) {
518 memcpy(p
, pch_gbe_gstrings_stats
[i
].string
,
520 p
+= ETH_GSTRING_LEN
;
527 * pch_gbe_get_ethtool_stats - Return statistics about the device
528 * @netdev: Network interface device structure
529 * @stats: Ethtool statue structure
530 * @data: Pointer of read status area
532 static void pch_gbe_get_ethtool_stats(struct net_device
*netdev
,
533 struct ethtool_stats
*stats
, u64
*data
)
535 struct pch_gbe_adapter
*adapter
= netdev_priv(netdev
);
537 const struct pch_gbe_stats
*gstats
= pch_gbe_gstrings_stats
;
538 char *hw_stats
= (char *)&adapter
->stats
;
540 pch_gbe_update_stats(adapter
);
541 for (i
= 0; i
< PCH_GBE_GLOBAL_STATS_LEN
; i
++) {
542 char *p
= hw_stats
+ gstats
->offset
;
543 data
[i
] = gstats
->size
== sizeof(u64
) ? *(u64
*)p
:(*(u32
*)p
);
548 static int pch_gbe_get_sset_count(struct net_device
*netdev
, int sset
)
552 return PCH_GBE_STATS_LEN
;
558 static const struct ethtool_ops pch_gbe_ethtool_ops
= {
559 .get_settings
= pch_gbe_get_settings
,
560 .set_settings
= pch_gbe_set_settings
,
561 .get_drvinfo
= pch_gbe_get_drvinfo
,
562 .get_regs_len
= pch_gbe_get_regs_len
,
563 .get_regs
= pch_gbe_get_regs
,
564 .get_wol
= pch_gbe_get_wol
,
565 .set_wol
= pch_gbe_set_wol
,
566 .nway_reset
= pch_gbe_nway_reset
,
567 .get_link
= ethtool_op_get_link
,
568 .get_ringparam
= pch_gbe_get_ringparam
,
569 .set_ringparam
= pch_gbe_set_ringparam
,
570 .get_pauseparam
= pch_gbe_get_pauseparam
,
571 .set_pauseparam
= pch_gbe_set_pauseparam
,
572 .get_rx_csum
= pch_gbe_get_rx_csum
,
573 .set_rx_csum
= pch_gbe_set_rx_csum
,
574 .get_tx_csum
= pch_gbe_get_tx_csum
,
575 .set_tx_csum
= pch_gbe_set_tx_csum
,
576 .get_strings
= pch_gbe_get_strings
,
577 .get_ethtool_stats
= pch_gbe_get_ethtool_stats
,
578 .get_sset_count
= pch_gbe_get_sset_count
,
581 void pch_gbe_set_ethtool_ops(struct net_device
*netdev
)
583 SET_ETHTOOL_OPS(netdev
, &pch_gbe_ethtool_ops
);