1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#include "pch_gbe.h"
20#include "pch_gbe_api.h"
21
22
23
24
25struct pch_gbe_stats {
26 char string[ETH_GSTRING_LEN];
27 size_t size;
28 size_t offset;
29};
30
31#define PCH_GBE_STAT(m) \
32{ \
33 .string = #m, \
34 .size = FIELD_SIZEOF(struct pch_gbe_hw_stats, m), \
35 .offset = offsetof(struct pch_gbe_hw_stats, m), \
36}
37
38
39
40
41static 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)
67};
68
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)
72
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)
75
76
77
78
79
80
81
82
83static int pch_gbe_get_settings(struct net_device *netdev,
84 struct ethtool_cmd *ecmd)
85{
86 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
87 int ret;
88
89 ret = mii_ethtool_gset(&adapter->mii, ecmd);
90 ecmd->supported &= ~(SUPPORTED_TP | SUPPORTED_1000baseT_Half);
91 ecmd->advertising &= ~(ADVERTISED_TP | ADVERTISED_1000baseT_Half);
92
93 if (!netif_carrier_ok(adapter->netdev))
94 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
95 return ret;
96}
97
98
99
100
101
102
103
104
105
106static int pch_gbe_set_settings(struct net_device *netdev,
107 struct ethtool_cmd *ecmd)
108{
109 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
110 struct pch_gbe_hw *hw = &adapter->hw;
111 u32 speed = ethtool_cmd_speed(ecmd);
112 int ret;
113
114 pch_gbe_hal_write_phy_reg(hw, MII_BMCR, BMCR_RESET);
115
116
117
118 if (speed == UINT_MAX) {
119 speed = SPEED_1000;
120 ethtool_cmd_speed_set(ecmd, speed);
121 ecmd->duplex = DUPLEX_FULL;
122 }
123 ret = mii_ethtool_sset(&adapter->mii, ecmd);
124 if (ret) {
125 netdev_err(netdev, "Error: mii_ethtool_sset\n");
126 return ret;
127 }
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;
132
133
134 if (netif_running(adapter->netdev)) {
135 pch_gbe_down(adapter);
136 ret = pch_gbe_up(adapter);
137 } else {
138 pch_gbe_reset(adapter);
139 }
140 return ret;
141}
142
143
144
145
146
147
148static int pch_gbe_get_regs_len(struct net_device *netdev)
149{
150 return PCH_GBE_REGS_LEN * (int)sizeof(u32);
151}
152
153
154
155
156
157
158static void pch_gbe_get_drvinfo(struct net_device *netdev,
159 struct ethtool_drvinfo *drvinfo)
160{
161 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
162
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}
168
169
170
171
172
173
174
175static void pch_gbe_get_regs(struct net_device *netdev,
176 struct ethtool_regs *regs, void *p)
177{
178 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
179 struct pch_gbe_hw *hw = &adapter->hw;
180 struct pci_dev *pdev = adapter->pdev;
181 u32 *regs_buff = p;
182 u16 i, tmp;
183
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);
187
188 for (i = 0; i < PCH_GBE_PHY_REGS_LEN; i++) {
189 pch_gbe_hal_read_phy_reg(&adapter->hw, i, &tmp);
190 *regs_buff++ = tmp;
191 }
192}
193
194
195
196
197
198
199static void pch_gbe_get_wol(struct net_device *netdev,
200 struct ethtool_wolinfo *wol)
201{
202 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
203
204 wol->supported = WAKE_UCAST | WAKE_MCAST | WAKE_BCAST | WAKE_MAGIC;
205 wol->wolopts = 0;
206
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;
215}
216
217
218
219
220
221
222
223
224
225static int pch_gbe_set_wol(struct net_device *netdev,
226 struct ethtool_wolinfo *wol)
227{
228 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
229
230 if ((wol->wolopts & (WAKE_PHY | WAKE_ARP | WAKE_MAGICSECURE)))
231 return -EOPNOTSUPP;
232
233 adapter->wake_up_evt = 0;
234
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;
243 return 0;
244}
245
246
247
248
249
250
251
252
253static int pch_gbe_nway_reset(struct net_device *netdev)
254{
255 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
256
257 return mii_nway_restart(&adapter->mii);
258}
259
260
261
262
263
264
265static void pch_gbe_get_ringparam(struct net_device *netdev,
266 struct ethtool_ringparam *ring)
267{
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;
271
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;
276}
277
278
279
280
281
282
283
284
285
286static int pch_gbe_set_ringparam(struct net_device *netdev,
287 struct ethtool_ringparam *ring)
288{
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;
293 int err = 0;
294
295 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
296 return -EINVAL;
297 tx_ring_size = (int)sizeof(struct pch_gbe_tx_ring);
298 rx_ring_size = (int)sizeof(struct pch_gbe_rx_ring);
299
300 if ((netif_running(adapter->netdev)))
301 pch_gbe_down(adapter);
302 tx_old = adapter->tx_ring;
303 rx_old = adapter->rx_ring;
304
305 txdr = kzalloc(tx_ring_size, GFP_KERNEL);
306 if (!txdr) {
307 err = -ENOMEM;
308 goto err_alloc_tx;
309 }
310 rxdr = kzalloc(rx_ring_size, GFP_KERNEL);
311 if (!rxdr) {
312 err = -ENOMEM;
313 goto err_alloc_rx;
314 }
315 adapter->tx_ring = txdr;
316 adapter->rx_ring = rxdr;
317
318 rxdr->count =
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);
321
322 txdr->count =
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);
325
326 if ((netif_running(adapter->netdev))) {
327
328 err = pch_gbe_setup_rx_resources(adapter, adapter->rx_ring);
329 if (err)
330 goto err_setup_rx;
331 err = pch_gbe_setup_tx_resources(adapter, adapter->tx_ring);
332 if (err)
333 goto err_setup_tx;
334
335
336#ifdef RINGFREE
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);
341 kfree(tx_old);
342 kfree(rx_old);
343 adapter->rx_ring = rxdr;
344 adapter->tx_ring = txdr;
345#else
346 pch_gbe_free_rx_resources(adapter, rx_old);
347 pch_gbe_free_tx_resources(adapter, tx_old);
348 kfree(tx_old);
349 kfree(rx_old);
350 adapter->rx_ring = rxdr;
351 adapter->tx_ring = txdr;
352#endif
353 err = pch_gbe_up(adapter);
354 }
355 return err;
356
357err_setup_tx:
358 pch_gbe_free_rx_resources(adapter, adapter->rx_ring);
359err_setup_rx:
360 adapter->rx_ring = rx_old;
361 adapter->tx_ring = tx_old;
362 kfree(rxdr);
363err_alloc_rx:
364 kfree(txdr);
365err_alloc_tx:
366 if (netif_running(adapter->netdev))
367 pch_gbe_up(adapter);
368 return err;
369}
370
371
372
373
374
375
376static void pch_gbe_get_pauseparam(struct net_device *netdev,
377 struct ethtool_pauseparam *pause)
378{
379 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
380 struct pch_gbe_hw *hw = &adapter->hw;
381
382 pause->autoneg =
383 ((hw->mac.fc_autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE);
384
385 if (hw->mac.fc == PCH_GBE_FC_RX_PAUSE) {
386 pause->rx_pause = 1;
387 } else if (hw->mac.fc == PCH_GBE_FC_TX_PAUSE) {
388 pause->tx_pause = 1;
389 } else if (hw->mac.fc == PCH_GBE_FC_FULL) {
390 pause->rx_pause = 1;
391 pause->tx_pause = 1;
392 }
393}
394
395
396
397
398
399
400
401
402
403static int pch_gbe_set_pauseparam(struct net_device *netdev,
404 struct ethtool_pauseparam *pause)
405{
406 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
407 struct pch_gbe_hw *hw = &adapter->hw;
408 int ret = 0;
409
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;
419
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);
424 } else {
425 pch_gbe_reset(adapter);
426 }
427 } else {
428 ret = pch_gbe_mac_force_mac_fc(hw);
429 }
430 return ret;
431}
432
433
434
435
436
437
438
439
440static void pch_gbe_get_strings(struct net_device *netdev, u32 stringset,
441 u8 *data)
442{
443 u8 *p = data;
444 int i;
445
446 switch (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,
450 ETH_GSTRING_LEN);
451 p += ETH_GSTRING_LEN;
452 }
453 break;
454 }
455}
456
457
458
459
460
461
462
463static void pch_gbe_get_ethtool_stats(struct net_device *netdev,
464 struct ethtool_stats *stats, u64 *data)
465{
466 struct pch_gbe_adapter *adapter = netdev_priv(netdev);
467 int i;
468 const struct pch_gbe_stats *gstats = pch_gbe_gstrings_stats;
469 char *hw_stats = (char *)&adapter->stats;
470
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);
475 gstats++;
476 }
477}
478
479static int pch_gbe_get_sset_count(struct net_device *netdev, int sset)
480{
481 switch (sset) {
482 case ETH_SS_STATS:
483 return PCH_GBE_STATS_LEN;
484 default:
485 return -EOPNOTSUPP;
486 }
487}
488
489static 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,
506};
507
508void pch_gbe_set_ethtool_ops(struct net_device *netdev)
509{
510 netdev->ethtool_ops = &pch_gbe_ethtool_ops;
511}
512