1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117#include <linux/spinlock.h>
118#include <linux/phy.h>
119#include <linux/net_tstamp.h>
120
121#include "xgbe.h"
122#include "xgbe-common.h"
123
124struct xgbe_stats {
125 char stat_string[ETH_GSTRING_LEN];
126 int stat_size;
127 int stat_offset;
128};
129
130#define XGMAC_MMC_STAT(_string, _var) \
131 { _string, \
132 sizeof_field(struct xgbe_mmc_stats, _var), \
133 offsetof(struct xgbe_prv_data, mmc_stats._var), \
134 }
135
136#define XGMAC_EXT_STAT(_string, _var) \
137 { _string, \
138 sizeof_field(struct xgbe_ext_stats, _var), \
139 offsetof(struct xgbe_prv_data, ext_stats._var), \
140 }
141
142static const struct xgbe_stats xgbe_gstring_stats[] = {
143 XGMAC_MMC_STAT("tx_bytes", txoctetcount_gb),
144 XGMAC_MMC_STAT("tx_packets", txframecount_gb),
145 XGMAC_MMC_STAT("tx_unicast_packets", txunicastframes_gb),
146 XGMAC_MMC_STAT("tx_broadcast_packets", txbroadcastframes_gb),
147 XGMAC_MMC_STAT("tx_multicast_packets", txmulticastframes_gb),
148 XGMAC_MMC_STAT("tx_vlan_packets", txvlanframes_g),
149 XGMAC_EXT_STAT("tx_vxlan_packets", tx_vxlan_packets),
150 XGMAC_EXT_STAT("tx_tso_packets", tx_tso_packets),
151 XGMAC_MMC_STAT("tx_64_byte_packets", tx64octets_gb),
152 XGMAC_MMC_STAT("tx_65_to_127_byte_packets", tx65to127octets_gb),
153 XGMAC_MMC_STAT("tx_128_to_255_byte_packets", tx128to255octets_gb),
154 XGMAC_MMC_STAT("tx_256_to_511_byte_packets", tx256to511octets_gb),
155 XGMAC_MMC_STAT("tx_512_to_1023_byte_packets", tx512to1023octets_gb),
156 XGMAC_MMC_STAT("tx_1024_to_max_byte_packets", tx1024tomaxoctets_gb),
157 XGMAC_MMC_STAT("tx_underflow_errors", txunderflowerror),
158 XGMAC_MMC_STAT("tx_pause_frames", txpauseframes),
159
160 XGMAC_MMC_STAT("rx_bytes", rxoctetcount_gb),
161 XGMAC_MMC_STAT("rx_packets", rxframecount_gb),
162 XGMAC_MMC_STAT("rx_unicast_packets", rxunicastframes_g),
163 XGMAC_MMC_STAT("rx_broadcast_packets", rxbroadcastframes_g),
164 XGMAC_MMC_STAT("rx_multicast_packets", rxmulticastframes_g),
165 XGMAC_MMC_STAT("rx_vlan_packets", rxvlanframes_gb),
166 XGMAC_EXT_STAT("rx_vxlan_packets", rx_vxlan_packets),
167 XGMAC_MMC_STAT("rx_64_byte_packets", rx64octets_gb),
168 XGMAC_MMC_STAT("rx_65_to_127_byte_packets", rx65to127octets_gb),
169 XGMAC_MMC_STAT("rx_128_to_255_byte_packets", rx128to255octets_gb),
170 XGMAC_MMC_STAT("rx_256_to_511_byte_packets", rx256to511octets_gb),
171 XGMAC_MMC_STAT("rx_512_to_1023_byte_packets", rx512to1023octets_gb),
172 XGMAC_MMC_STAT("rx_1024_to_max_byte_packets", rx1024tomaxoctets_gb),
173 XGMAC_MMC_STAT("rx_undersize_packets", rxundersize_g),
174 XGMAC_MMC_STAT("rx_oversize_packets", rxoversize_g),
175 XGMAC_MMC_STAT("rx_crc_errors", rxcrcerror),
176 XGMAC_MMC_STAT("rx_crc_errors_small_packets", rxrunterror),
177 XGMAC_MMC_STAT("rx_crc_errors_giant_packets", rxjabbererror),
178 XGMAC_MMC_STAT("rx_length_errors", rxlengtherror),
179 XGMAC_MMC_STAT("rx_out_of_range_errors", rxoutofrangetype),
180 XGMAC_MMC_STAT("rx_fifo_overflow_errors", rxfifooverflow),
181 XGMAC_MMC_STAT("rx_watchdog_errors", rxwatchdogerror),
182 XGMAC_EXT_STAT("rx_csum_errors", rx_csum_errors),
183 XGMAC_EXT_STAT("rx_vxlan_csum_errors", rx_vxlan_csum_errors),
184 XGMAC_MMC_STAT("rx_pause_frames", rxpauseframes),
185 XGMAC_EXT_STAT("rx_split_header_packets", rx_split_header_packets),
186 XGMAC_EXT_STAT("rx_buffer_unavailable", rx_buffer_unavailable),
187};
188
189#define XGBE_STATS_COUNT ARRAY_SIZE(xgbe_gstring_stats)
190
191static void xgbe_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
192{
193 struct xgbe_prv_data *pdata = netdev_priv(netdev);
194 int i;
195
196 switch (stringset) {
197 case ETH_SS_STATS:
198 for (i = 0; i < XGBE_STATS_COUNT; i++) {
199 memcpy(data, xgbe_gstring_stats[i].stat_string,
200 ETH_GSTRING_LEN);
201 data += ETH_GSTRING_LEN;
202 }
203 for (i = 0; i < pdata->tx_ring_count; i++) {
204 sprintf(data, "txq_%u_packets", i);
205 data += ETH_GSTRING_LEN;
206 sprintf(data, "txq_%u_bytes", i);
207 data += ETH_GSTRING_LEN;
208 }
209 for (i = 0; i < pdata->rx_ring_count; i++) {
210 sprintf(data, "rxq_%u_packets", i);
211 data += ETH_GSTRING_LEN;
212 sprintf(data, "rxq_%u_bytes", i);
213 data += ETH_GSTRING_LEN;
214 }
215 break;
216 }
217}
218
219static void xgbe_get_ethtool_stats(struct net_device *netdev,
220 struct ethtool_stats *stats, u64 *data)
221{
222 struct xgbe_prv_data *pdata = netdev_priv(netdev);
223 u8 *stat;
224 int i;
225
226 pdata->hw_if.read_mmc_stats(pdata);
227 for (i = 0; i < XGBE_STATS_COUNT; i++) {
228 stat = (u8 *)pdata + xgbe_gstring_stats[i].stat_offset;
229 *data++ = *(u64 *)stat;
230 }
231 for (i = 0; i < pdata->tx_ring_count; i++) {
232 *data++ = pdata->ext_stats.txq_packets[i];
233 *data++ = pdata->ext_stats.txq_bytes[i];
234 }
235 for (i = 0; i < pdata->rx_ring_count; i++) {
236 *data++ = pdata->ext_stats.rxq_packets[i];
237 *data++ = pdata->ext_stats.rxq_bytes[i];
238 }
239}
240
241static int xgbe_get_sset_count(struct net_device *netdev, int stringset)
242{
243 struct xgbe_prv_data *pdata = netdev_priv(netdev);
244 int ret;
245
246 switch (stringset) {
247 case ETH_SS_STATS:
248 ret = XGBE_STATS_COUNT +
249 (pdata->tx_ring_count * 2) +
250 (pdata->rx_ring_count * 2);
251 break;
252
253 default:
254 ret = -EOPNOTSUPP;
255 }
256
257 return ret;
258}
259
260static void xgbe_get_pauseparam(struct net_device *netdev,
261 struct ethtool_pauseparam *pause)
262{
263 struct xgbe_prv_data *pdata = netdev_priv(netdev);
264
265 pause->autoneg = pdata->phy.pause_autoneg;
266 pause->tx_pause = pdata->phy.tx_pause;
267 pause->rx_pause = pdata->phy.rx_pause;
268}
269
270static int xgbe_set_pauseparam(struct net_device *netdev,
271 struct ethtool_pauseparam *pause)
272{
273 struct xgbe_prv_data *pdata = netdev_priv(netdev);
274 struct ethtool_link_ksettings *lks = &pdata->phy.lks;
275 int ret = 0;
276
277 if (pause->autoneg && (pdata->phy.autoneg != AUTONEG_ENABLE)) {
278 netdev_err(netdev,
279 "autoneg disabled, pause autoneg not available\n");
280 return -EINVAL;
281 }
282
283 pdata->phy.pause_autoneg = pause->autoneg;
284 pdata->phy.tx_pause = pause->tx_pause;
285 pdata->phy.rx_pause = pause->rx_pause;
286
287 XGBE_CLR_ADV(lks, Pause);
288 XGBE_CLR_ADV(lks, Asym_Pause);
289
290 if (pause->rx_pause) {
291 XGBE_SET_ADV(lks, Pause);
292 XGBE_SET_ADV(lks, Asym_Pause);
293 }
294
295 if (pause->tx_pause) {
296
297 if (XGBE_ADV(lks, Asym_Pause))
298 XGBE_CLR_ADV(lks, Asym_Pause);
299 else
300 XGBE_SET_ADV(lks, Asym_Pause);
301 }
302
303 if (netif_running(netdev))
304 ret = pdata->phy_if.phy_config_aneg(pdata);
305
306 return ret;
307}
308
309static int xgbe_get_link_ksettings(struct net_device *netdev,
310 struct ethtool_link_ksettings *cmd)
311{
312 struct xgbe_prv_data *pdata = netdev_priv(netdev);
313 struct ethtool_link_ksettings *lks = &pdata->phy.lks;
314
315 cmd->base.phy_address = pdata->phy.address;
316
317 cmd->base.autoneg = pdata->phy.autoneg;
318 cmd->base.speed = pdata->phy.speed;
319 cmd->base.duplex = pdata->phy.duplex;
320
321 cmd->base.port = PORT_NONE;
322
323 XGBE_LM_COPY(cmd, supported, lks, supported);
324 XGBE_LM_COPY(cmd, advertising, lks, advertising);
325 XGBE_LM_COPY(cmd, lp_advertising, lks, lp_advertising);
326
327 return 0;
328}
329
330static int xgbe_set_link_ksettings(struct net_device *netdev,
331 const struct ethtool_link_ksettings *cmd)
332{
333 struct xgbe_prv_data *pdata = netdev_priv(netdev);
334 struct ethtool_link_ksettings *lks = &pdata->phy.lks;
335 __ETHTOOL_DECLARE_LINK_MODE_MASK(advertising);
336 u32 speed;
337 int ret;
338
339 speed = cmd->base.speed;
340
341 if (cmd->base.phy_address != pdata->phy.address) {
342 netdev_err(netdev, "invalid phy address %hhu\n",
343 cmd->base.phy_address);
344 return -EINVAL;
345 }
346
347 if ((cmd->base.autoneg != AUTONEG_ENABLE) &&
348 (cmd->base.autoneg != AUTONEG_DISABLE)) {
349 netdev_err(netdev, "unsupported autoneg %hhu\n",
350 cmd->base.autoneg);
351 return -EINVAL;
352 }
353
354 if (cmd->base.autoneg == AUTONEG_DISABLE) {
355 if (!pdata->phy_if.phy_valid_speed(pdata, speed)) {
356 netdev_err(netdev, "unsupported speed %u\n", speed);
357 return -EINVAL;
358 }
359
360 if (cmd->base.duplex != DUPLEX_FULL) {
361 netdev_err(netdev, "unsupported duplex %hhu\n",
362 cmd->base.duplex);
363 return -EINVAL;
364 }
365 }
366
367 netif_dbg(pdata, link, netdev,
368 "requested advertisement 0x%*pb, phy supported 0x%*pb\n",
369 __ETHTOOL_LINK_MODE_MASK_NBITS, cmd->link_modes.advertising,
370 __ETHTOOL_LINK_MODE_MASK_NBITS, lks->link_modes.supported);
371
372 bitmap_and(advertising,
373 cmd->link_modes.advertising, lks->link_modes.supported,
374 __ETHTOOL_LINK_MODE_MASK_NBITS);
375
376 if ((cmd->base.autoneg == AUTONEG_ENABLE) &&
377 bitmap_empty(advertising, __ETHTOOL_LINK_MODE_MASK_NBITS)) {
378 netdev_err(netdev,
379 "unsupported requested advertisement\n");
380 return -EINVAL;
381 }
382
383 ret = 0;
384 pdata->phy.autoneg = cmd->base.autoneg;
385 pdata->phy.speed = speed;
386 pdata->phy.duplex = cmd->base.duplex;
387 bitmap_copy(lks->link_modes.advertising, advertising,
388 __ETHTOOL_LINK_MODE_MASK_NBITS);
389
390 if (cmd->base.autoneg == AUTONEG_ENABLE)
391 XGBE_SET_ADV(lks, Autoneg);
392 else
393 XGBE_CLR_ADV(lks, Autoneg);
394
395 if (netif_running(netdev))
396 ret = pdata->phy_if.phy_config_aneg(pdata);
397
398 return ret;
399}
400
401static void xgbe_get_drvinfo(struct net_device *netdev,
402 struct ethtool_drvinfo *drvinfo)
403{
404 struct xgbe_prv_data *pdata = netdev_priv(netdev);
405 struct xgbe_hw_features *hw_feat = &pdata->hw_feat;
406
407 strlcpy(drvinfo->driver, XGBE_DRV_NAME, sizeof(drvinfo->driver));
408 strlcpy(drvinfo->bus_info, dev_name(pdata->dev),
409 sizeof(drvinfo->bus_info));
410 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version), "%d.%d.%d",
411 XGMAC_GET_BITS(hw_feat->version, MAC_VR, USERVER),
412 XGMAC_GET_BITS(hw_feat->version, MAC_VR, DEVID),
413 XGMAC_GET_BITS(hw_feat->version, MAC_VR, SNPSVER));
414}
415
416static u32 xgbe_get_msglevel(struct net_device *netdev)
417{
418 struct xgbe_prv_data *pdata = netdev_priv(netdev);
419
420 return pdata->msg_enable;
421}
422
423static void xgbe_set_msglevel(struct net_device *netdev, u32 msglevel)
424{
425 struct xgbe_prv_data *pdata = netdev_priv(netdev);
426
427 pdata->msg_enable = msglevel;
428}
429
430static int xgbe_get_coalesce(struct net_device *netdev,
431 struct ethtool_coalesce *ec,
432 struct kernel_ethtool_coalesce *kernel_coal,
433 struct netlink_ext_ack *extack)
434{
435 struct xgbe_prv_data *pdata = netdev_priv(netdev);
436
437 memset(ec, 0, sizeof(struct ethtool_coalesce));
438
439 ec->rx_coalesce_usecs = pdata->rx_usecs;
440 ec->rx_max_coalesced_frames = pdata->rx_frames;
441
442 ec->tx_max_coalesced_frames = pdata->tx_frames;
443
444 return 0;
445}
446
447static int xgbe_set_coalesce(struct net_device *netdev,
448 struct ethtool_coalesce *ec,
449 struct kernel_ethtool_coalesce *kernel_coal,
450 struct netlink_ext_ack *extack)
451{
452 struct xgbe_prv_data *pdata = netdev_priv(netdev);
453 struct xgbe_hw_if *hw_if = &pdata->hw_if;
454 unsigned int rx_frames, rx_riwt, rx_usecs;
455 unsigned int tx_frames;
456
457 rx_riwt = hw_if->usec_to_riwt(pdata, ec->rx_coalesce_usecs);
458 rx_usecs = ec->rx_coalesce_usecs;
459 rx_frames = ec->rx_max_coalesced_frames;
460
461
462 if (rx_usecs && !rx_riwt)
463 rx_riwt = 1;
464
465
466 if (rx_riwt > XGMAC_MAX_DMA_RIWT) {
467 netdev_err(netdev, "rx-usec is limited to %d usecs\n",
468 hw_if->riwt_to_usec(pdata, XGMAC_MAX_DMA_RIWT));
469 return -EINVAL;
470 }
471 if (rx_frames > pdata->rx_desc_count) {
472 netdev_err(netdev, "rx-frames is limited to %d frames\n",
473 pdata->rx_desc_count);
474 return -EINVAL;
475 }
476
477 tx_frames = ec->tx_max_coalesced_frames;
478
479
480 if (tx_frames > pdata->tx_desc_count) {
481 netdev_err(netdev, "tx-frames is limited to %d frames\n",
482 pdata->tx_desc_count);
483 return -EINVAL;
484 }
485
486 pdata->rx_riwt = rx_riwt;
487 pdata->rx_usecs = rx_usecs;
488 pdata->rx_frames = rx_frames;
489 hw_if->config_rx_coalesce(pdata);
490
491 pdata->tx_frames = tx_frames;
492 hw_if->config_tx_coalesce(pdata);
493
494 return 0;
495}
496
497static int xgbe_get_rxnfc(struct net_device *netdev,
498 struct ethtool_rxnfc *rxnfc, u32 *rule_locs)
499{
500 struct xgbe_prv_data *pdata = netdev_priv(netdev);
501
502 switch (rxnfc->cmd) {
503 case ETHTOOL_GRXRINGS:
504 rxnfc->data = pdata->rx_ring_count;
505 break;
506 default:
507 return -EOPNOTSUPP;
508 }
509
510 return 0;
511}
512
513static u32 xgbe_get_rxfh_key_size(struct net_device *netdev)
514{
515 struct xgbe_prv_data *pdata = netdev_priv(netdev);
516
517 return sizeof(pdata->rss_key);
518}
519
520static u32 xgbe_get_rxfh_indir_size(struct net_device *netdev)
521{
522 struct xgbe_prv_data *pdata = netdev_priv(netdev);
523
524 return ARRAY_SIZE(pdata->rss_table);
525}
526
527static int xgbe_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
528 u8 *hfunc)
529{
530 struct xgbe_prv_data *pdata = netdev_priv(netdev);
531 unsigned int i;
532
533 if (indir) {
534 for (i = 0; i < ARRAY_SIZE(pdata->rss_table); i++)
535 indir[i] = XGMAC_GET_BITS(pdata->rss_table[i],
536 MAC_RSSDR, DMCH);
537 }
538
539 if (key)
540 memcpy(key, pdata->rss_key, sizeof(pdata->rss_key));
541
542 if (hfunc)
543 *hfunc = ETH_RSS_HASH_TOP;
544
545 return 0;
546}
547
548static int xgbe_set_rxfh(struct net_device *netdev, const u32 *indir,
549 const u8 *key, const u8 hfunc)
550{
551 struct xgbe_prv_data *pdata = netdev_priv(netdev);
552 struct xgbe_hw_if *hw_if = &pdata->hw_if;
553 unsigned int ret;
554
555 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP) {
556 netdev_err(netdev, "unsupported hash function\n");
557 return -EOPNOTSUPP;
558 }
559
560 if (indir) {
561 ret = hw_if->set_rss_lookup_table(pdata, indir);
562 if (ret)
563 return ret;
564 }
565
566 if (key) {
567 ret = hw_if->set_rss_hash_key(pdata, key);
568 if (ret)
569 return ret;
570 }
571
572 return 0;
573}
574
575static int xgbe_get_ts_info(struct net_device *netdev,
576 struct ethtool_ts_info *ts_info)
577{
578 struct xgbe_prv_data *pdata = netdev_priv(netdev);
579
580 ts_info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
581 SOF_TIMESTAMPING_RX_SOFTWARE |
582 SOF_TIMESTAMPING_SOFTWARE |
583 SOF_TIMESTAMPING_TX_HARDWARE |
584 SOF_TIMESTAMPING_RX_HARDWARE |
585 SOF_TIMESTAMPING_RAW_HARDWARE;
586
587 if (pdata->ptp_clock)
588 ts_info->phc_index = ptp_clock_index(pdata->ptp_clock);
589 else
590 ts_info->phc_index = -1;
591
592 ts_info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
593 ts_info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
594 (1 << HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
595 (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
596 (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
597 (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
598 (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
599 (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ) |
600 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
601 (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
602 (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
603 (1 << HWTSTAMP_FILTER_ALL);
604
605 return 0;
606}
607
608static int xgbe_get_module_info(struct net_device *netdev,
609 struct ethtool_modinfo *modinfo)
610{
611 struct xgbe_prv_data *pdata = netdev_priv(netdev);
612
613 return pdata->phy_if.module_info(pdata, modinfo);
614}
615
616static int xgbe_get_module_eeprom(struct net_device *netdev,
617 struct ethtool_eeprom *eeprom, u8 *data)
618{
619 struct xgbe_prv_data *pdata = netdev_priv(netdev);
620
621 return pdata->phy_if.module_eeprom(pdata, eeprom, data);
622}
623
624static void xgbe_get_ringparam(struct net_device *netdev,
625 struct ethtool_ringparam *ringparam)
626{
627 struct xgbe_prv_data *pdata = netdev_priv(netdev);
628
629 ringparam->rx_max_pending = XGBE_RX_DESC_CNT_MAX;
630 ringparam->tx_max_pending = XGBE_TX_DESC_CNT_MAX;
631 ringparam->rx_pending = pdata->rx_desc_count;
632 ringparam->tx_pending = pdata->tx_desc_count;
633}
634
635static int xgbe_set_ringparam(struct net_device *netdev,
636 struct ethtool_ringparam *ringparam)
637{
638 struct xgbe_prv_data *pdata = netdev_priv(netdev);
639 unsigned int rx, tx;
640
641 if (ringparam->rx_mini_pending || ringparam->rx_jumbo_pending) {
642 netdev_err(netdev, "unsupported ring parameter\n");
643 return -EINVAL;
644 }
645
646 if ((ringparam->rx_pending < XGBE_RX_DESC_CNT_MIN) ||
647 (ringparam->rx_pending > XGBE_RX_DESC_CNT_MAX)) {
648 netdev_err(netdev,
649 "rx ring parameter must be between %u and %u\n",
650 XGBE_RX_DESC_CNT_MIN, XGBE_RX_DESC_CNT_MAX);
651 return -EINVAL;
652 }
653
654 if ((ringparam->tx_pending < XGBE_TX_DESC_CNT_MIN) ||
655 (ringparam->tx_pending > XGBE_TX_DESC_CNT_MAX)) {
656 netdev_err(netdev,
657 "tx ring parameter must be between %u and %u\n",
658 XGBE_TX_DESC_CNT_MIN, XGBE_TX_DESC_CNT_MAX);
659 return -EINVAL;
660 }
661
662 rx = __rounddown_pow_of_two(ringparam->rx_pending);
663 if (rx != ringparam->rx_pending)
664 netdev_notice(netdev,
665 "rx ring parameter rounded to power of two: %u\n",
666 rx);
667
668 tx = __rounddown_pow_of_two(ringparam->tx_pending);
669 if (tx != ringparam->tx_pending)
670 netdev_notice(netdev,
671 "tx ring parameter rounded to power of two: %u\n",
672 tx);
673
674 if ((rx == pdata->rx_desc_count) &&
675 (tx == pdata->tx_desc_count))
676 goto out;
677
678 pdata->rx_desc_count = rx;
679 pdata->tx_desc_count = tx;
680
681 xgbe_restart_dev(pdata);
682
683out:
684 return 0;
685}
686
687static void xgbe_get_channels(struct net_device *netdev,
688 struct ethtool_channels *channels)
689{
690 struct xgbe_prv_data *pdata = netdev_priv(netdev);
691 unsigned int rx, tx, combined;
692
693
694
695
696
697
698
699 rx = min(pdata->hw_feat.rx_ch_cnt, pdata->rx_max_channel_count);
700 rx = min(rx, pdata->channel_irq_count);
701 tx = min(pdata->hw_feat.tx_ch_cnt, pdata->tx_max_channel_count);
702 tx = min(tx, pdata->channel_irq_count);
703 tx = min(tx, pdata->tx_max_q_count);
704
705 combined = min(rx, tx);
706
707 channels->max_combined = combined;
708 channels->max_rx = rx ? rx - 1 : 0;
709 channels->max_tx = tx ? tx - 1 : 0;
710
711
712 rx = pdata->new_rx_ring_count ? : pdata->rx_ring_count;
713 tx = pdata->new_tx_ring_count ? : pdata->tx_ring_count;
714
715 combined = min(rx, tx);
716 rx -= combined;
717 tx -= combined;
718
719 channels->combined_count = combined;
720 channels->rx_count = rx;
721 channels->tx_count = tx;
722}
723
724static void xgbe_print_set_channels_input(struct net_device *netdev,
725 struct ethtool_channels *channels)
726{
727 netdev_err(netdev, "channel inputs: combined=%u, rx-only=%u, tx-only=%u\n",
728 channels->combined_count, channels->rx_count,
729 channels->tx_count);
730}
731
732static int xgbe_set_channels(struct net_device *netdev,
733 struct ethtool_channels *channels)
734{
735 struct xgbe_prv_data *pdata = netdev_priv(netdev);
736 unsigned int rx, rx_curr, tx, tx_curr, combined;
737
738
739
740
741
742
743
744 rx = min(pdata->hw_feat.rx_ch_cnt, pdata->rx_max_channel_count);
745 rx = min(rx, pdata->channel_irq_count);
746 tx = min(pdata->hw_feat.tx_ch_cnt, pdata->tx_max_channel_count);
747 tx = min(tx, pdata->tx_max_q_count);
748 tx = min(tx, pdata->channel_irq_count);
749
750 combined = min(rx, tx);
751
752
753 if (channels->other_count) {
754 netdev_err(netdev,
755 "other channel count must be zero\n");
756 return -EINVAL;
757 }
758
759
760 if (!channels->combined_count) {
761 netdev_err(netdev,
762 "at least one combined Rx/Tx channel is required\n");
763 xgbe_print_set_channels_input(netdev, channels);
764 return -EINVAL;
765 }
766
767
768 if (channels->combined_count > combined) {
769 netdev_err(netdev,
770 "combined channel count cannot exceed %u\n",
771 combined);
772 xgbe_print_set_channels_input(netdev, channels);
773 return -EINVAL;
774 }
775
776
777 if (channels->rx_count && channels->tx_count) {
778 netdev_err(netdev,
779 "cannot specify both Rx-only and Tx-only channels\n");
780 xgbe_print_set_channels_input(netdev, channels);
781 return -EINVAL;
782 }
783
784
785 if ((channels->combined_count + channels->rx_count) > rx) {
786 netdev_err(netdev,
787 "total Rx channels (%u) requested exceeds maximum available (%u)\n",
788 channels->combined_count + channels->rx_count, rx);
789 xgbe_print_set_channels_input(netdev, channels);
790 return -EINVAL;
791 }
792
793 if ((channels->combined_count + channels->tx_count) > tx) {
794 netdev_err(netdev,
795 "total Tx channels (%u) requested exceeds maximum available (%u)\n",
796 channels->combined_count + channels->tx_count, tx);
797 xgbe_print_set_channels_input(netdev, channels);
798 return -EINVAL;
799 }
800
801 rx = channels->combined_count + channels->rx_count;
802 tx = channels->combined_count + channels->tx_count;
803
804 rx_curr = pdata->new_rx_ring_count ? : pdata->rx_ring_count;
805 tx_curr = pdata->new_tx_ring_count ? : pdata->tx_ring_count;
806
807 if ((rx == rx_curr) && (tx == tx_curr))
808 goto out;
809
810 pdata->new_rx_ring_count = rx;
811 pdata->new_tx_ring_count = tx;
812
813 xgbe_full_restart_dev(pdata);
814
815out:
816 return 0;
817}
818
819static const struct ethtool_ops xgbe_ethtool_ops = {
820 .supported_coalesce_params = ETHTOOL_COALESCE_RX_USECS |
821 ETHTOOL_COALESCE_MAX_FRAMES,
822 .get_drvinfo = xgbe_get_drvinfo,
823 .get_msglevel = xgbe_get_msglevel,
824 .set_msglevel = xgbe_set_msglevel,
825 .get_link = ethtool_op_get_link,
826 .get_coalesce = xgbe_get_coalesce,
827 .set_coalesce = xgbe_set_coalesce,
828 .get_pauseparam = xgbe_get_pauseparam,
829 .set_pauseparam = xgbe_set_pauseparam,
830 .get_strings = xgbe_get_strings,
831 .get_ethtool_stats = xgbe_get_ethtool_stats,
832 .get_sset_count = xgbe_get_sset_count,
833 .get_rxnfc = xgbe_get_rxnfc,
834 .get_rxfh_key_size = xgbe_get_rxfh_key_size,
835 .get_rxfh_indir_size = xgbe_get_rxfh_indir_size,
836 .get_rxfh = xgbe_get_rxfh,
837 .set_rxfh = xgbe_set_rxfh,
838 .get_ts_info = xgbe_get_ts_info,
839 .get_link_ksettings = xgbe_get_link_ksettings,
840 .set_link_ksettings = xgbe_set_link_ksettings,
841 .get_module_info = xgbe_get_module_info,
842 .get_module_eeprom = xgbe_get_module_eeprom,
843 .get_ringparam = xgbe_get_ringparam,
844 .set_ringparam = xgbe_set_ringparam,
845 .get_channels = xgbe_get_channels,
846 .set_channels = xgbe_set_channels,
847};
848
849const struct ethtool_ops *xgbe_get_ethtool_ops(void)
850{
851 return &xgbe_ethtool_ops;
852}
853