1
2
3
4
5
6
7
8#include "pch_gbe.h"
9#include "pch_gbe_phy.h"
10
11
12
13
14struct pch_gbe_stats {
15 char string[ETH_GSTRING_LEN];
16 size_t size;
17 size_t offset;
18};
19
20#define PCH_GBE_STAT(m) \
21{ \
22 .string = #m, \
23 .size = sizeof_field(struct pch_gbe_hw_stats, m), \
24 .offset = offsetof(struct pch_gbe_hw_stats, m), \
25}
26
27
28
29
30static const struct pch_gbe_stats pch_gbe_gstrings_stats[] = {
31 PCH_GBE_STAT(rx_packets),
32 PCH_GBE_STAT(tx_packets),
33 PCH_GBE_STAT(rx_bytes),
34 PCH_GBE_STAT(tx_bytes),
35 PCH_GBE_STAT(rx_errors),
36 PCH_GBE_STAT(tx_errors),
37 PCH_GBE_STAT(rx_dropped),
38 PCH_GBE_STAT(tx_dropped),
39 PCH_GBE_STAT(multicast),
40 PCH_GBE_STAT(collisions),
41 PCH_GBE_STAT(rx_crc_errors),
42 PCH_GBE_STAT(rx_frame_errors),
43 PCH_GBE_STAT(rx_alloc_buff_failed),
44 PCH_GBE_STAT(tx_length_errors),
45 PCH_GBE_STAT(tx_aborted_errors),
46 PCH_GBE_STAT(tx_carrier_errors),
47 PCH_GBE_STAT(tx_timeout_count),
48 PCH_GBE_STAT(tx_restart_count),
49 PCH_GBE_STAT(intr_rx_dsc_empty_count),
50 PCH_GBE_STAT(intr_rx_frame_err_count),
51 PCH_GBE_STAT(intr_rx_fifo_err_count),
52 PCH_GBE_STAT(intr_rx_dma_err_count),
53 PCH_GBE_STAT(intr_tx_fifo_err_count),
54 PCH_GBE_STAT(intr_tx_dma_err_count),
55 PCH_GBE_STAT(intr_tcpip_err_count)
56};
57
58#define PCH_GBE_QUEUE_STATS_LEN 0
59#define PCH_GBE_GLOBAL_STATS_LEN ARRAY_SIZE(pch_gbe_gstrings_stats)
60#define PCH_GBE_STATS_LEN (PCH_GBE_GLOBAL_STATS_LEN + PCH_GBE_QUEUE_STATS_LEN)
61
62#define PCH_GBE_MAC_REGS_LEN (sizeof(struct pch_gbe_regs) / 4)
63#define PCH_GBE_REGS_LEN (PCH_GBE_MAC_REGS_LEN + PCH_GBE_PHY_REGS_LEN)
64
65
66
67
68
69
70
71
72static int pch_gbe_get_link_ksettings(struct net_device *netdev,
73 struct ethtool_link_ksettings *ecmd)
74{
75 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
76 u32 supported, advertising;
77
78 mii_ethtool_get_link_ksettings(&adapter->mii, ecmd);
79
80 ethtool_convert_link_mode_to_legacy_u32(&supported,
81 ecmd->link_modes.supported);
82 ethtool_convert_link_mode_to_legacy_u32(&advertising,
83 ecmd->link_modes.advertising);
84
85 supported &= ~(SUPPORTED_TP | SUPPORTED_1000baseT_Half);
86 advertising &= ~(ADVERTISED_TP | ADVERTISED_1000baseT_Half);
87
88 ethtool_convert_legacy_u32_to_link_mode(ecmd->link_modes.supported,
89 supported);
90 ethtool_convert_legacy_u32_to_link_mode(ecmd->link_modes.advertising,
91 advertising);
92
93 if (!netif_carrier_ok(adapter->netdev))
94 ecmd->base.speed = SPEED_UNKNOWN;
95
96 return 0;
97}
98
99
100
101
102
103
104
105
106
107static int pch_gbe_set_link_ksettings(struct net_device *netdev,
108 const struct ethtool_link_ksettings *ecmd)
109{
110 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
111 struct pch_gbe_hw *hw = &adapter->hw;
112 struct ethtool_link_ksettings copy_ecmd;
113 u32 speed = ecmd->base.speed;
114 u32 advertising;
115 int ret;
116
117 pch_gbe_phy_write_reg_miic(hw, MII_BMCR, BMCR_RESET);
118
119 memcpy(©_ecmd, ecmd, sizeof(*ecmd));
120
121
122
123 if (speed == UINT_MAX) {
124 speed = SPEED_1000;
125 copy_ecmd.base.speed = speed;
126 copy_ecmd.base.duplex = DUPLEX_FULL;
127 }
128 ret = mii_ethtool_set_link_ksettings(&adapter->mii, ©_ecmd);
129 if (ret) {
130 netdev_err(netdev, "Error: mii_ethtool_set_link_ksettings\n");
131 return ret;
132 }
133 hw->mac.link_speed = speed;
134 hw->mac.link_duplex = copy_ecmd.base.duplex;
135 ethtool_convert_link_mode_to_legacy_u32(
136 &advertising, copy_ecmd.link_modes.advertising);
137 hw->phy.autoneg_advertised = advertising;
138 hw->mac.autoneg = copy_ecmd.base.autoneg;
139
140
141 if (netif_running(adapter->netdev)) {
142 pch_gbe_down(adapter);
143 ret = pch_gbe_up(adapter);
144 } else {
145 pch_gbe_reset(adapter);
146 }
147 return ret;
148}
149
150
151
152
153
154
155static int pch_gbe_get_regs_len(struct net_device *netdev)
156{
157 return PCH_GBE_REGS_LEN * (int)sizeof(u32);
158}
159
160
161
162
163
164
165static void pch_gbe_get_drvinfo(struct net_device *netdev,
166 struct ethtool_drvinfo *drvinfo)
167{
168 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
169
170 strlcpy(drvinfo->driver, KBUILD_MODNAME, sizeof(drvinfo->driver));
171 strlcpy(drvinfo->version, pch_driver_version, sizeof(drvinfo->version));
172 strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
173 sizeof(drvinfo->bus_info));
174}
175
176
177
178
179
180
181
182static void pch_gbe_get_regs(struct net_device *netdev,
183 struct ethtool_regs *regs, void *p)
184{
185 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
186 struct pch_gbe_hw *hw = &adapter->hw;
187 struct pci_dev *pdev = adapter->pdev;
188 u32 *regs_buff = p;
189 u16 i, tmp;
190
191 regs->version = 0x1000000 | (__u32)pdev->revision << 16 | pdev->device;
192 for (i = 0; i < PCH_GBE_MAC_REGS_LEN; i++)
193 *regs_buff++ = ioread32(&hw->reg->INT_ST + i);
194
195 for (i = 0; i < PCH_GBE_PHY_REGS_LEN; i++) {
196 pch_gbe_phy_read_reg_miic(&adapter->hw, i, &tmp);
197 *regs_buff++ = tmp;
198 }
199}
200
201
202
203
204
205
206static void pch_gbe_get_wol(struct net_device *netdev,
207 struct ethtool_wolinfo *wol)
208{
209 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
210
211 wol->supported = WAKE_UCAST | WAKE_MCAST | WAKE_BCAST | WAKE_MAGIC;
212 wol->wolopts = 0;
213
214 if ((adapter->wake_up_evt & PCH_GBE_WLC_IND))
215 wol->wolopts |= WAKE_UCAST;
216 if ((adapter->wake_up_evt & PCH_GBE_WLC_MLT))
217 wol->wolopts |= WAKE_MCAST;
218 if ((adapter->wake_up_evt & PCH_GBE_WLC_BR))
219 wol->wolopts |= WAKE_BCAST;
220 if ((adapter->wake_up_evt & PCH_GBE_WLC_MP))
221 wol->wolopts |= WAKE_MAGIC;
222}
223
224
225
226
227
228
229
230
231
232static int pch_gbe_set_wol(struct net_device *netdev,
233 struct ethtool_wolinfo *wol)
234{
235 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
236
237 if ((wol->wolopts & (WAKE_PHY | WAKE_ARP | WAKE_MAGICSECURE)))
238 return -EOPNOTSUPP;
239
240 adapter->wake_up_evt = 0;
241
242 if ((wol->wolopts & WAKE_UCAST))
243 adapter->wake_up_evt |= PCH_GBE_WLC_IND;
244 if ((wol->wolopts & WAKE_MCAST))
245 adapter->wake_up_evt |= PCH_GBE_WLC_MLT;
246 if ((wol->wolopts & WAKE_BCAST))
247 adapter->wake_up_evt |= PCH_GBE_WLC_BR;
248 if ((wol->wolopts & WAKE_MAGIC))
249 adapter->wake_up_evt |= PCH_GBE_WLC_MP;
250 return 0;
251}
252
253
254
255
256
257
258
259
260static int pch_gbe_nway_reset(struct net_device *netdev)
261{
262 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
263
264 return mii_nway_restart(&adapter->mii);
265}
266
267
268
269
270
271
272static void pch_gbe_get_ringparam(struct net_device *netdev,
273 struct ethtool_ringparam *ring)
274{
275 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
276 struct pch_gbe_tx_ring *txdr = adapter->tx_ring;
277 struct pch_gbe_rx_ring *rxdr = adapter->rx_ring;
278
279 ring->rx_max_pending = PCH_GBE_MAX_RXD;
280 ring->tx_max_pending = PCH_GBE_MAX_TXD;
281 ring->rx_pending = rxdr->count;
282 ring->tx_pending = txdr->count;
283}
284
285
286
287
288
289
290
291
292
293static int pch_gbe_set_ringparam(struct net_device *netdev,
294 struct ethtool_ringparam *ring)
295{
296 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
297 struct pch_gbe_tx_ring *txdr, *tx_old;
298 struct pch_gbe_rx_ring *rxdr, *rx_old;
299 int tx_ring_size, rx_ring_size;
300 int err = 0;
301
302 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
303 return -EINVAL;
304 tx_ring_size = (int)sizeof(struct pch_gbe_tx_ring);
305 rx_ring_size = (int)sizeof(struct pch_gbe_rx_ring);
306
307 if ((netif_running(adapter->netdev)))
308 pch_gbe_down(adapter);
309 tx_old = adapter->tx_ring;
310 rx_old = adapter->rx_ring;
311
312 txdr = kzalloc(tx_ring_size, GFP_KERNEL);
313 if (!txdr) {
314 err = -ENOMEM;
315 goto err_alloc_tx;
316 }
317 rxdr = kzalloc(rx_ring_size, GFP_KERNEL);
318 if (!rxdr) {
319 err = -ENOMEM;
320 goto err_alloc_rx;
321 }
322 adapter->tx_ring = txdr;
323 adapter->rx_ring = rxdr;
324
325 rxdr->count =
326 clamp_val(ring->rx_pending, PCH_GBE_MIN_RXD, PCH_GBE_MAX_RXD);
327 rxdr->count = roundup(rxdr->count, PCH_GBE_RX_DESC_MULTIPLE);
328
329 txdr->count =
330 clamp_val(ring->tx_pending, PCH_GBE_MIN_RXD, PCH_GBE_MAX_RXD);
331 txdr->count = roundup(txdr->count, PCH_GBE_TX_DESC_MULTIPLE);
332
333 if ((netif_running(adapter->netdev))) {
334
335 err = pch_gbe_setup_rx_resources(adapter, adapter->rx_ring);
336 if (err)
337 goto err_setup_rx;
338 err = pch_gbe_setup_tx_resources(adapter, adapter->tx_ring);
339 if (err)
340 goto err_setup_tx;
341 pch_gbe_free_rx_resources(adapter, rx_old);
342 pch_gbe_free_tx_resources(adapter, tx_old);
343 kfree(tx_old);
344 kfree(rx_old);
345 adapter->rx_ring = rxdr;
346 adapter->tx_ring = txdr;
347 err = pch_gbe_up(adapter);
348 }
349 return err;
350
351err_setup_tx:
352 pch_gbe_free_rx_resources(adapter, adapter->rx_ring);
353err_setup_rx:
354 adapter->rx_ring = rx_old;
355 adapter->tx_ring = tx_old;
356 kfree(rxdr);
357err_alloc_rx:
358 kfree(txdr);
359err_alloc_tx:
360 if (netif_running(adapter->netdev))
361 pch_gbe_up(adapter);
362 return err;
363}
364
365
366
367
368
369
370static void pch_gbe_get_pauseparam(struct net_device *netdev,
371 struct ethtool_pauseparam *pause)
372{
373 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
374 struct pch_gbe_hw *hw = &adapter->hw;
375
376 pause->autoneg =
377 ((hw->mac.fc_autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE);
378
379 if (hw->mac.fc == PCH_GBE_FC_RX_PAUSE) {
380 pause->rx_pause = 1;
381 } else if (hw->mac.fc == PCH_GBE_FC_TX_PAUSE) {
382 pause->tx_pause = 1;
383 } else if (hw->mac.fc == PCH_GBE_FC_FULL) {
384 pause->rx_pause = 1;
385 pause->tx_pause = 1;
386 }
387}
388
389
390
391
392
393
394
395
396
397static int pch_gbe_set_pauseparam(struct net_device *netdev,
398 struct ethtool_pauseparam *pause)
399{
400 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
401 struct pch_gbe_hw *hw = &adapter->hw;
402 int ret = 0;
403
404 hw->mac.fc_autoneg = pause->autoneg;
405 if ((pause->rx_pause) && (pause->tx_pause))
406 hw->mac.fc = PCH_GBE_FC_FULL;
407 else if ((pause->rx_pause) && (!pause->tx_pause))
408 hw->mac.fc = PCH_GBE_FC_RX_PAUSE;
409 else if ((!pause->rx_pause) && (pause->tx_pause))
410 hw->mac.fc = PCH_GBE_FC_TX_PAUSE;
411 else if ((!pause->rx_pause) && (!pause->tx_pause))
412 hw->mac.fc = PCH_GBE_FC_NONE;
413
414 if (hw->mac.fc_autoneg == AUTONEG_ENABLE) {
415 if ((netif_running(adapter->netdev))) {
416 pch_gbe_down(adapter);
417 ret = pch_gbe_up(adapter);
418 } else {
419 pch_gbe_reset(adapter);
420 }
421 } else {
422 ret = pch_gbe_mac_force_mac_fc(hw);
423 }
424 return ret;
425}
426
427
428
429
430
431
432
433
434static void pch_gbe_get_strings(struct net_device *netdev, u32 stringset,
435 u8 *data)
436{
437 u8 *p = data;
438 int i;
439
440 switch (stringset) {
441 case (u32) ETH_SS_STATS:
442 for (i = 0; i < PCH_GBE_GLOBAL_STATS_LEN; i++) {
443 memcpy(p, pch_gbe_gstrings_stats[i].string,
444 ETH_GSTRING_LEN);
445 p += ETH_GSTRING_LEN;
446 }
447 break;
448 }
449}
450
451
452
453
454
455
456
457static void pch_gbe_get_ethtool_stats(struct net_device *netdev,
458 struct ethtool_stats *stats, u64 *data)
459{
460 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
461 int i;
462 const struct pch_gbe_stats *gstats = pch_gbe_gstrings_stats;
463 char *hw_stats = (char *)&adapter->stats;
464
465 pch_gbe_update_stats(adapter);
466 for (i = 0; i < PCH_GBE_GLOBAL_STATS_LEN; i++) {
467 char *p = hw_stats + gstats->offset;
468 data[i] = gstats->size == sizeof(u64) ? *(u64 *)p:(*(u32 *)p);
469 gstats++;
470 }
471}
472
473static int pch_gbe_get_sset_count(struct net_device *netdev, int sset)
474{
475 switch (sset) {
476 case ETH_SS_STATS:
477 return PCH_GBE_STATS_LEN;
478 default:
479 return -EOPNOTSUPP;
480 }
481}
482
483static const struct ethtool_ops pch_gbe_ethtool_ops = {
484 .get_drvinfo = pch_gbe_get_drvinfo,
485 .get_regs_len = pch_gbe_get_regs_len,
486 .get_regs = pch_gbe_get_regs,
487 .get_wol = pch_gbe_get_wol,
488 .set_wol = pch_gbe_set_wol,
489 .nway_reset = pch_gbe_nway_reset,
490 .get_link = ethtool_op_get_link,
491 .get_ringparam = pch_gbe_get_ringparam,
492 .set_ringparam = pch_gbe_set_ringparam,
493 .get_pauseparam = pch_gbe_get_pauseparam,
494 .set_pauseparam = pch_gbe_set_pauseparam,
495 .get_strings = pch_gbe_get_strings,
496 .get_ethtool_stats = pch_gbe_get_ethtool_stats,
497 .get_sset_count = pch_gbe_get_sset_count,
498 .get_link_ksettings = pch_gbe_get_link_ksettings,
499 .set_link_ksettings = pch_gbe_set_link_ksettings,
500};
501
502void pch_gbe_set_ethtool_ops(struct net_device *netdev)
503{
504 netdev->ethtool_ops = &pch_gbe_ethtool_ops;
505}
506