Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1// SPDX-License-Identifier: GPL-2.0
2/* Copyright(c) 2017 - 2019 Pensando Systems, Inc */
3
4#include <linux/module.h>
5#include <linux/netdevice.h>
6#include <linux/sfp.h>
7
8#include "ionic.h"
9#include "ionic_bus.h"
10#include "ionic_lif.h"
11#include "ionic_ethtool.h"
12#include "ionic_stats.h"
13
14static const char ionic_priv_flags_strings[][ETH_GSTRING_LEN] = {
15#define PRIV_F_SW_DBG_STATS BIT(0)
16 "sw-dbg-stats",
17};
18#define PRIV_FLAGS_COUNT ARRAY_SIZE(ionic_priv_flags_strings)
19
20static void ionic_get_stats_strings(struct ionic_lif *lif, u8 *buf)
21{
22 u32 i;
23
24 for (i = 0; i < ionic_num_stats_grps; i++)
25 ionic_stats_groups[i].get_strings(lif, &buf);
26}
27
28static void ionic_get_stats(struct net_device *netdev,
29 struct ethtool_stats *stats, u64 *buf)
30{
31 struct ionic_lif *lif;
32 u32 i;
33
34 lif = netdev_priv(netdev);
35
36 memset(buf, 0, stats->n_stats * sizeof(*buf));
37 for (i = 0; i < ionic_num_stats_grps; i++)
38 ionic_stats_groups[i].get_values(lif, &buf);
39}
40
41static int ionic_get_stats_count(struct ionic_lif *lif)
42{
43 int i, num_stats = 0;
44
45 for (i = 0; i < ionic_num_stats_grps; i++)
46 num_stats += ionic_stats_groups[i].get_count(lif);
47
48 return num_stats;
49}
50
51static int ionic_get_sset_count(struct net_device *netdev, int sset)
52{
53 struct ionic_lif *lif = netdev_priv(netdev);
54 int count = 0;
55
56 switch (sset) {
57 case ETH_SS_STATS:
58 count = ionic_get_stats_count(lif);
59 break;
60 case ETH_SS_PRIV_FLAGS:
61 count = PRIV_FLAGS_COUNT;
62 break;
63 }
64 return count;
65}
66
67static void ionic_get_strings(struct net_device *netdev,
68 u32 sset, u8 *buf)
69{
70 struct ionic_lif *lif = netdev_priv(netdev);
71
72 switch (sset) {
73 case ETH_SS_STATS:
74 ionic_get_stats_strings(lif, buf);
75 break;
76 case ETH_SS_PRIV_FLAGS:
77 memcpy(buf, ionic_priv_flags_strings,
78 PRIV_FLAGS_COUNT * ETH_GSTRING_LEN);
79 break;
80 }
81}
82
83static void ionic_get_drvinfo(struct net_device *netdev,
84 struct ethtool_drvinfo *drvinfo)
85{
86 struct ionic_lif *lif = netdev_priv(netdev);
87 struct ionic *ionic = lif->ionic;
88
89 strlcpy(drvinfo->driver, IONIC_DRV_NAME, sizeof(drvinfo->driver));
90 strlcpy(drvinfo->fw_version, ionic->idev.dev_info.fw_version,
91 sizeof(drvinfo->fw_version));
92 strlcpy(drvinfo->bus_info, ionic_bus_info(ionic),
93 sizeof(drvinfo->bus_info));
94}
95
96static int ionic_get_regs_len(struct net_device *netdev)
97{
98 return (IONIC_DEV_INFO_REG_COUNT + IONIC_DEV_CMD_REG_COUNT) * sizeof(u32);
99}
100
101static void ionic_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
102 void *p)
103{
104 struct ionic_lif *lif = netdev_priv(netdev);
105 unsigned int size;
106
107 regs->version = IONIC_DEV_CMD_REG_VERSION;
108
109 size = IONIC_DEV_INFO_REG_COUNT * sizeof(u32);
110 memcpy_fromio(p, lif->ionic->idev.dev_info_regs->words, size);
111
112 size = IONIC_DEV_CMD_REG_COUNT * sizeof(u32);
113 memcpy_fromio(p, lif->ionic->idev.dev_cmd_regs->words, size);
114}
115
116static int ionic_get_link_ksettings(struct net_device *netdev,
117 struct ethtool_link_ksettings *ks)
118{
119 struct ionic_lif *lif = netdev_priv(netdev);
120 struct ionic_dev *idev = &lif->ionic->idev;
121 int copper_seen = 0;
122
123 ethtool_link_ksettings_zero_link_mode(ks, supported);
124
125 /* The port_info data is found in a DMA space that the NIC keeps
126 * up-to-date, so there's no need to request the data from the
127 * NIC, we already have it in our memory space.
128 */
129
130 switch (le16_to_cpu(idev->port_info->status.xcvr.pid)) {
131 /* Copper */
132 case IONIC_XCVR_PID_QSFP_100G_CR4:
133 ethtool_link_ksettings_add_link_mode(ks, supported,
134 100000baseCR4_Full);
135 copper_seen++;
136 break;
137 case IONIC_XCVR_PID_QSFP_40GBASE_CR4:
138 ethtool_link_ksettings_add_link_mode(ks, supported,
139 40000baseCR4_Full);
140 copper_seen++;
141 break;
142 case IONIC_XCVR_PID_SFP_25GBASE_CR_S:
143 case IONIC_XCVR_PID_SFP_25GBASE_CR_L:
144 case IONIC_XCVR_PID_SFP_25GBASE_CR_N:
145 ethtool_link_ksettings_add_link_mode(ks, supported,
146 25000baseCR_Full);
147 copper_seen++;
148 break;
149 case IONIC_XCVR_PID_SFP_10GBASE_AOC:
150 case IONIC_XCVR_PID_SFP_10GBASE_CU:
151 ethtool_link_ksettings_add_link_mode(ks, supported,
152 10000baseCR_Full);
153 copper_seen++;
154 break;
155
156 /* Fibre */
157 case IONIC_XCVR_PID_QSFP_100G_SR4:
158 case IONIC_XCVR_PID_QSFP_100G_AOC:
159 ethtool_link_ksettings_add_link_mode(ks, supported,
160 100000baseSR4_Full);
161 break;
162 case IONIC_XCVR_PID_QSFP_100G_LR4:
163 ethtool_link_ksettings_add_link_mode(ks, supported,
164 100000baseLR4_ER4_Full);
165 break;
166 case IONIC_XCVR_PID_QSFP_100G_ER4:
167 ethtool_link_ksettings_add_link_mode(ks, supported,
168 100000baseLR4_ER4_Full);
169 break;
170 case IONIC_XCVR_PID_QSFP_40GBASE_SR4:
171 case IONIC_XCVR_PID_QSFP_40GBASE_AOC:
172 ethtool_link_ksettings_add_link_mode(ks, supported,
173 40000baseSR4_Full);
174 break;
175 case IONIC_XCVR_PID_QSFP_40GBASE_LR4:
176 ethtool_link_ksettings_add_link_mode(ks, supported,
177 40000baseLR4_Full);
178 break;
179 case IONIC_XCVR_PID_SFP_25GBASE_SR:
180 case IONIC_XCVR_PID_SFP_25GBASE_AOC:
181 ethtool_link_ksettings_add_link_mode(ks, supported,
182 25000baseSR_Full);
183 break;
184 case IONIC_XCVR_PID_SFP_10GBASE_SR:
185 ethtool_link_ksettings_add_link_mode(ks, supported,
186 10000baseSR_Full);
187 break;
188 case IONIC_XCVR_PID_SFP_10GBASE_LR:
189 ethtool_link_ksettings_add_link_mode(ks, supported,
190 10000baseLR_Full);
191 break;
192 case IONIC_XCVR_PID_SFP_10GBASE_LRM:
193 ethtool_link_ksettings_add_link_mode(ks, supported,
194 10000baseLRM_Full);
195 break;
196 case IONIC_XCVR_PID_SFP_10GBASE_ER:
197 ethtool_link_ksettings_add_link_mode(ks, supported,
198 10000baseER_Full);
199 break;
200 case IONIC_XCVR_PID_UNKNOWN:
201 /* This means there's no module plugged in */
202 break;
203 default:
204 dev_info(lif->ionic->dev, "unknown xcvr type pid=%d / 0x%x\n",
205 idev->port_info->status.xcvr.pid,
206 idev->port_info->status.xcvr.pid);
207 break;
208 }
209
210 bitmap_copy(ks->link_modes.advertising, ks->link_modes.supported,
211 __ETHTOOL_LINK_MODE_MASK_NBITS);
212
213 ethtool_link_ksettings_add_link_mode(ks, supported, FEC_BASER);
214 ethtool_link_ksettings_add_link_mode(ks, supported, FEC_RS);
215 if (idev->port_info->config.fec_type == IONIC_PORT_FEC_TYPE_FC)
216 ethtool_link_ksettings_add_link_mode(ks, advertising, FEC_BASER);
217 else if (idev->port_info->config.fec_type == IONIC_PORT_FEC_TYPE_RS)
218 ethtool_link_ksettings_add_link_mode(ks, advertising, FEC_RS);
219
220 ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE);
221 ethtool_link_ksettings_add_link_mode(ks, supported, Pause);
222
223 if (idev->port_info->status.xcvr.phy == IONIC_PHY_TYPE_COPPER ||
224 copper_seen)
225 ks->base.port = PORT_DA;
226 else if (idev->port_info->status.xcvr.phy == IONIC_PHY_TYPE_FIBER)
227 ks->base.port = PORT_FIBRE;
228 else
229 ks->base.port = PORT_NONE;
230
231 if (ks->base.port != PORT_NONE) {
232 ks->base.speed = le32_to_cpu(lif->info->status.link_speed);
233
234 if (le16_to_cpu(lif->info->status.link_status))
235 ks->base.duplex = DUPLEX_FULL;
236 else
237 ks->base.duplex = DUPLEX_UNKNOWN;
238
239 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
240
241 if (idev->port_info->config.an_enable) {
242 ethtool_link_ksettings_add_link_mode(ks, advertising,
243 Autoneg);
244 ks->base.autoneg = AUTONEG_ENABLE;
245 }
246 }
247
248 return 0;
249}
250
251static int ionic_set_link_ksettings(struct net_device *netdev,
252 const struct ethtool_link_ksettings *ks)
253{
254 struct ionic_lif *lif = netdev_priv(netdev);
255 struct ionic *ionic = lif->ionic;
256 struct ionic_dev *idev;
257 int err = 0;
258
259 idev = &lif->ionic->idev;
260
261 /* set autoneg */
262 if (ks->base.autoneg != idev->port_info->config.an_enable) {
263 mutex_lock(&ionic->dev_cmd_lock);
264 ionic_dev_cmd_port_autoneg(idev, ks->base.autoneg);
265 err = ionic_dev_cmd_wait(ionic, DEVCMD_TIMEOUT);
266 mutex_unlock(&ionic->dev_cmd_lock);
267 if (err)
268 return err;
269 }
270
271 /* set speed */
272 if (ks->base.speed != le32_to_cpu(idev->port_info->config.speed)) {
273 mutex_lock(&ionic->dev_cmd_lock);
274 ionic_dev_cmd_port_speed(idev, ks->base.speed);
275 err = ionic_dev_cmd_wait(ionic, DEVCMD_TIMEOUT);
276 mutex_unlock(&ionic->dev_cmd_lock);
277 if (err)
278 return err;
279 }
280
281 return 0;
282}
283
284static void ionic_get_pauseparam(struct net_device *netdev,
285 struct ethtool_pauseparam *pause)
286{
287 struct ionic_lif *lif = netdev_priv(netdev);
288 u8 pause_type;
289
290 pause->autoneg = 0;
291
292 pause_type = lif->ionic->idev.port_info->config.pause_type;
293 if (pause_type) {
294 pause->rx_pause = pause_type & IONIC_PAUSE_F_RX ? 1 : 0;
295 pause->tx_pause = pause_type & IONIC_PAUSE_F_TX ? 1 : 0;
296 }
297}
298
299static int ionic_set_pauseparam(struct net_device *netdev,
300 struct ethtool_pauseparam *pause)
301{
302 struct ionic_lif *lif = netdev_priv(netdev);
303 struct ionic *ionic = lif->ionic;
304 u32 requested_pause;
305 int err;
306
307 if (pause->autoneg)
308 return -EOPNOTSUPP;
309
310 /* change both at the same time */
311 requested_pause = IONIC_PORT_PAUSE_TYPE_LINK;
312 if (pause->rx_pause)
313 requested_pause |= IONIC_PAUSE_F_RX;
314 if (pause->tx_pause)
315 requested_pause |= IONIC_PAUSE_F_TX;
316
317 if (requested_pause == lif->ionic->idev.port_info->config.pause_type)
318 return 0;
319
320 mutex_lock(&ionic->dev_cmd_lock);
321 ionic_dev_cmd_port_pause(&lif->ionic->idev, requested_pause);
322 err = ionic_dev_cmd_wait(ionic, DEVCMD_TIMEOUT);
323 mutex_unlock(&ionic->dev_cmd_lock);
324 if (err)
325 return err;
326
327 return 0;
328}
329
330static int ionic_get_fecparam(struct net_device *netdev,
331 struct ethtool_fecparam *fec)
332{
333 struct ionic_lif *lif = netdev_priv(netdev);
334
335 switch (lif->ionic->idev.port_info->config.fec_type) {
336 case IONIC_PORT_FEC_TYPE_NONE:
337 fec->active_fec = ETHTOOL_FEC_OFF;
338 break;
339 case IONIC_PORT_FEC_TYPE_RS:
340 fec->active_fec = ETHTOOL_FEC_RS;
341 break;
342 case IONIC_PORT_FEC_TYPE_FC:
343 fec->active_fec = ETHTOOL_FEC_BASER;
344 break;
345 }
346
347 fec->fec = ETHTOOL_FEC_OFF | ETHTOOL_FEC_RS | ETHTOOL_FEC_BASER;
348
349 return 0;
350}
351
352static int ionic_set_fecparam(struct net_device *netdev,
353 struct ethtool_fecparam *fec)
354{
355 struct ionic_lif *lif = netdev_priv(netdev);
356 u8 fec_type;
357 int ret = 0;
358
359 if (lif->ionic->idev.port_info->config.an_enable) {
360 netdev_err(netdev, "FEC request not allowed while autoneg is enabled\n");
361 return -EINVAL;
362 }
363
364 switch (fec->fec) {
365 case ETHTOOL_FEC_NONE:
366 fec_type = IONIC_PORT_FEC_TYPE_NONE;
367 break;
368 case ETHTOOL_FEC_OFF:
369 fec_type = IONIC_PORT_FEC_TYPE_NONE;
370 break;
371 case ETHTOOL_FEC_RS:
372 fec_type = IONIC_PORT_FEC_TYPE_RS;
373 break;
374 case ETHTOOL_FEC_BASER:
375 fec_type = IONIC_PORT_FEC_TYPE_FC;
376 break;
377 case ETHTOOL_FEC_AUTO:
378 default:
379 netdev_err(netdev, "FEC request 0x%04x not supported\n",
380 fec->fec);
381 return -EINVAL;
382 }
383
384 if (fec_type != lif->ionic->idev.port_info->config.fec_type) {
385 mutex_lock(&lif->ionic->dev_cmd_lock);
386 ionic_dev_cmd_port_fec(&lif->ionic->idev, fec_type);
387 ret = ionic_dev_cmd_wait(lif->ionic, DEVCMD_TIMEOUT);
388 mutex_unlock(&lif->ionic->dev_cmd_lock);
389 }
390
391 return ret;
392}
393
394static int ionic_get_coalesce(struct net_device *netdev,
395 struct ethtool_coalesce *coalesce)
396{
397 struct ionic_lif *lif = netdev_priv(netdev);
398
399 /* Tx uses Rx interrupt */
400 coalesce->tx_coalesce_usecs = lif->rx_coalesce_usecs;
401 coalesce->rx_coalesce_usecs = lif->rx_coalesce_usecs;
402
403 return 0;
404}
405
406static int ionic_set_coalesce(struct net_device *netdev,
407 struct ethtool_coalesce *coalesce)
408{
409 struct ionic_lif *lif = netdev_priv(netdev);
410 struct ionic_identity *ident;
411 struct ionic_qcq *qcq;
412 unsigned int i;
413 u32 coal;
414
415 ident = &lif->ionic->ident;
416 if (ident->dev.intr_coal_div == 0) {
417 netdev_warn(netdev, "bad HW value in dev.intr_coal_div = %d\n",
418 ident->dev.intr_coal_div);
419 return -EIO;
420 }
421
422 /* Tx uses Rx interrupt, so only change Rx */
423 if (coalesce->tx_coalesce_usecs != lif->rx_coalesce_usecs) {
424 netdev_warn(netdev, "only the rx-usecs can be changed\n");
425 return -EINVAL;
426 }
427
428 /* Convert the usec request to a HW useable value. If they asked
429 * for non-zero and it resolved to zero, bump it up
430 */
431 coal = ionic_coal_usec_to_hw(lif->ionic, coalesce->rx_coalesce_usecs);
432 if (!coal && coalesce->rx_coalesce_usecs)
433 coal = 1;
434
435 if (coal > IONIC_INTR_CTRL_COAL_MAX)
436 return -ERANGE;
437
438 /* Save the new value */
439 lif->rx_coalesce_usecs = coalesce->rx_coalesce_usecs;
440 if (coal != lif->rx_coalesce_hw) {
441 lif->rx_coalesce_hw = coal;
442
443 if (test_bit(IONIC_LIF_F_UP, lif->state)) {
444 for (i = 0; i < lif->nxqs; i++) {
445 qcq = lif->rxqcqs[i].qcq;
446 ionic_intr_coal_init(lif->ionic->idev.intr_ctrl,
447 qcq->intr.index,
448 lif->rx_coalesce_hw);
449 }
450 }
451 }
452
453 return 0;
454}
455
456static void ionic_get_ringparam(struct net_device *netdev,
457 struct ethtool_ringparam *ring)
458{
459 struct ionic_lif *lif = netdev_priv(netdev);
460
461 ring->tx_max_pending = IONIC_MAX_TXRX_DESC;
462 ring->tx_pending = lif->ntxq_descs;
463 ring->rx_max_pending = IONIC_MAX_TXRX_DESC;
464 ring->rx_pending = lif->nrxq_descs;
465}
466
467static int ionic_set_ringparam(struct net_device *netdev,
468 struct ethtool_ringparam *ring)
469{
470 struct ionic_lif *lif = netdev_priv(netdev);
471 bool running;
472 int err;
473
474 if (ring->rx_mini_pending || ring->rx_jumbo_pending) {
475 netdev_info(netdev, "Changing jumbo or mini descriptors not supported\n");
476 return -EINVAL;
477 }
478
479 if (!is_power_of_2(ring->tx_pending) ||
480 !is_power_of_2(ring->rx_pending)) {
481 netdev_info(netdev, "Descriptor count must be a power of 2\n");
482 return -EINVAL;
483 }
484
485 /* if nothing to do return success */
486 if (ring->tx_pending == lif->ntxq_descs &&
487 ring->rx_pending == lif->nrxq_descs)
488 return 0;
489
490 err = ionic_wait_for_bit(lif, IONIC_LIF_F_QUEUE_RESET);
491 if (err)
492 return err;
493
494 running = test_bit(IONIC_LIF_F_UP, lif->state);
495 if (running)
496 ionic_stop(netdev);
497
498 lif->ntxq_descs = ring->tx_pending;
499 lif->nrxq_descs = ring->rx_pending;
500
501 if (running)
502 ionic_open(netdev);
503 clear_bit(IONIC_LIF_F_QUEUE_RESET, lif->state);
504
505 return 0;
506}
507
508static void ionic_get_channels(struct net_device *netdev,
509 struct ethtool_channels *ch)
510{
511 struct ionic_lif *lif = netdev_priv(netdev);
512
513 /* report maximum channels */
514 ch->max_combined = lif->ionic->ntxqs_per_lif;
515
516 /* report current channels */
517 ch->combined_count = lif->nxqs;
518}
519
520static int ionic_set_channels(struct net_device *netdev,
521 struct ethtool_channels *ch)
522{
523 struct ionic_lif *lif = netdev_priv(netdev);
524 bool running;
525 int err;
526
527 if (!ch->combined_count || ch->other_count ||
528 ch->rx_count || ch->tx_count)
529 return -EINVAL;
530
531 if (ch->combined_count == lif->nxqs)
532 return 0;
533
534 err = ionic_wait_for_bit(lif, IONIC_LIF_F_QUEUE_RESET);
535 if (err)
536 return err;
537
538 running = test_bit(IONIC_LIF_F_UP, lif->state);
539 if (running)
540 ionic_stop(netdev);
541
542 lif->nxqs = ch->combined_count;
543
544 if (running)
545 ionic_open(netdev);
546 clear_bit(IONIC_LIF_F_QUEUE_RESET, lif->state);
547
548 return 0;
549}
550
551static u32 ionic_get_priv_flags(struct net_device *netdev)
552{
553 struct ionic_lif *lif = netdev_priv(netdev);
554 u32 priv_flags = 0;
555
556 if (test_bit(IONIC_LIF_F_SW_DEBUG_STATS, lif->state))
557 priv_flags |= PRIV_F_SW_DBG_STATS;
558
559 return priv_flags;
560}
561
562static int ionic_set_priv_flags(struct net_device *netdev, u32 priv_flags)
563{
564 struct ionic_lif *lif = netdev_priv(netdev);
565
566 clear_bit(IONIC_LIF_F_SW_DEBUG_STATS, lif->state);
567 if (priv_flags & PRIV_F_SW_DBG_STATS)
568 set_bit(IONIC_LIF_F_SW_DEBUG_STATS, lif->state);
569
570 return 0;
571}
572
573static int ionic_get_rxnfc(struct net_device *netdev,
574 struct ethtool_rxnfc *info, u32 *rules)
575{
576 struct ionic_lif *lif = netdev_priv(netdev);
577 int err = 0;
578
579 switch (info->cmd) {
580 case ETHTOOL_GRXRINGS:
581 info->data = lif->nxqs;
582 break;
583 default:
584 netdev_err(netdev, "Command parameter %d is not supported\n",
585 info->cmd);
586 err = -EOPNOTSUPP;
587 }
588
589 return err;
590}
591
592static u32 ionic_get_rxfh_indir_size(struct net_device *netdev)
593{
594 struct ionic_lif *lif = netdev_priv(netdev);
595
596 return le16_to_cpu(lif->ionic->ident.lif.eth.rss_ind_tbl_sz);
597}
598
599static u32 ionic_get_rxfh_key_size(struct net_device *netdev)
600{
601 return IONIC_RSS_HASH_KEY_SIZE;
602}
603
604static int ionic_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
605 u8 *hfunc)
606{
607 struct ionic_lif *lif = netdev_priv(netdev);
608 unsigned int i, tbl_sz;
609
610 if (indir) {
611 tbl_sz = le16_to_cpu(lif->ionic->ident.lif.eth.rss_ind_tbl_sz);
612 for (i = 0; i < tbl_sz; i++)
613 indir[i] = lif->rss_ind_tbl[i];
614 }
615
616 if (key)
617 memcpy(key, lif->rss_hash_key, IONIC_RSS_HASH_KEY_SIZE);
618
619 if (hfunc)
620 *hfunc = ETH_RSS_HASH_TOP;
621
622 return 0;
623}
624
625static int ionic_set_rxfh(struct net_device *netdev, const u32 *indir,
626 const u8 *key, const u8 hfunc)
627{
628 struct ionic_lif *lif = netdev_priv(netdev);
629 int err;
630
631 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
632 return -EOPNOTSUPP;
633
634 err = ionic_lif_rss_config(lif, lif->rss_types, key, indir);
635 if (err)
636 return err;
637
638 return 0;
639}
640
641static int ionic_set_tunable(struct net_device *dev,
642 const struct ethtool_tunable *tuna,
643 const void *data)
644{
645 struct ionic_lif *lif = netdev_priv(dev);
646
647 switch (tuna->id) {
648 case ETHTOOL_RX_COPYBREAK:
649 lif->rx_copybreak = *(u32 *)data;
650 break;
651 default:
652 return -EOPNOTSUPP;
653 }
654
655 return 0;
656}
657
658static int ionic_get_tunable(struct net_device *netdev,
659 const struct ethtool_tunable *tuna, void *data)
660{
661 struct ionic_lif *lif = netdev_priv(netdev);
662
663 switch (tuna->id) {
664 case ETHTOOL_RX_COPYBREAK:
665 *(u32 *)data = lif->rx_copybreak;
666 break;
667 default:
668 return -EOPNOTSUPP;
669 }
670
671 return 0;
672}
673
674static int ionic_get_module_info(struct net_device *netdev,
675 struct ethtool_modinfo *modinfo)
676
677{
678 struct ionic_lif *lif = netdev_priv(netdev);
679 struct ionic_dev *idev = &lif->ionic->idev;
680 struct ionic_xcvr_status *xcvr;
681 struct sfp_eeprom_base *sfp;
682
683 xcvr = &idev->port_info->status.xcvr;
684 sfp = (struct sfp_eeprom_base *) xcvr->sprom;
685
686 /* report the module data type and length */
687 switch (sfp->phys_id) {
688 case SFF8024_ID_SFP:
689 modinfo->type = ETH_MODULE_SFF_8079;
690 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
691 break;
692 case SFF8024_ID_QSFP_8436_8636:
693 case SFF8024_ID_QSFP28_8636:
694 modinfo->type = ETH_MODULE_SFF_8436;
695 modinfo->eeprom_len = ETH_MODULE_SFF_8436_LEN;
696 break;
697 default:
698 netdev_info(netdev, "unknown xcvr type 0x%02x\n",
699 xcvr->sprom[0]);
700 modinfo->type = 0;
701 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
702 break;
703 }
704
705 return 0;
706}
707
708static int ionic_get_module_eeprom(struct net_device *netdev,
709 struct ethtool_eeprom *ee,
710 u8 *data)
711{
712 struct ionic_lif *lif = netdev_priv(netdev);
713 struct ionic_dev *idev = &lif->ionic->idev;
714 struct ionic_xcvr_status *xcvr;
715 char tbuf[sizeof(xcvr->sprom)];
716 int count = 10;
717 u32 len;
718
719 /* The NIC keeps the module prom up-to-date in the DMA space
720 * so we can simply copy the module bytes into the data buffer.
721 */
722 xcvr = &idev->port_info->status.xcvr;
723 len = min_t(u32, sizeof(xcvr->sprom), ee->len);
724
725 do {
726 memcpy(data, xcvr->sprom, len);
727 memcpy(tbuf, xcvr->sprom, len);
728
729 /* Let's make sure we got a consistent copy */
730 if (!memcmp(data, tbuf, len))
731 break;
732
733 } while (--count);
734
735 if (!count)
736 return -ETIMEDOUT;
737
738 return 0;
739}
740
741static int ionic_nway_reset(struct net_device *netdev)
742{
743 struct ionic_lif *lif = netdev_priv(netdev);
744 struct ionic *ionic = lif->ionic;
745 int err = 0;
746
747 /* flap the link to force auto-negotiation */
748
749 mutex_lock(&ionic->dev_cmd_lock);
750
751 ionic_dev_cmd_port_state(&ionic->idev, IONIC_PORT_ADMIN_STATE_DOWN);
752 err = ionic_dev_cmd_wait(ionic, DEVCMD_TIMEOUT);
753
754 if (!err) {
755 ionic_dev_cmd_port_state(&ionic->idev, IONIC_PORT_ADMIN_STATE_UP);
756 err = ionic_dev_cmd_wait(ionic, DEVCMD_TIMEOUT);
757 }
758
759 mutex_unlock(&ionic->dev_cmd_lock);
760
761 return err;
762}
763
764static const struct ethtool_ops ionic_ethtool_ops = {
765 .supported_coalesce_params = ETHTOOL_COALESCE_USECS,
766 .get_drvinfo = ionic_get_drvinfo,
767 .get_regs_len = ionic_get_regs_len,
768 .get_regs = ionic_get_regs,
769 .get_link = ethtool_op_get_link,
770 .get_link_ksettings = ionic_get_link_ksettings,
771 .set_link_ksettings = ionic_set_link_ksettings,
772 .get_coalesce = ionic_get_coalesce,
773 .set_coalesce = ionic_set_coalesce,
774 .get_ringparam = ionic_get_ringparam,
775 .set_ringparam = ionic_set_ringparam,
776 .get_channels = ionic_get_channels,
777 .set_channels = ionic_set_channels,
778 .get_strings = ionic_get_strings,
779 .get_ethtool_stats = ionic_get_stats,
780 .get_sset_count = ionic_get_sset_count,
781 .get_priv_flags = ionic_get_priv_flags,
782 .set_priv_flags = ionic_set_priv_flags,
783 .get_rxnfc = ionic_get_rxnfc,
784 .get_rxfh_indir_size = ionic_get_rxfh_indir_size,
785 .get_rxfh_key_size = ionic_get_rxfh_key_size,
786 .get_rxfh = ionic_get_rxfh,
787 .set_rxfh = ionic_set_rxfh,
788 .get_tunable = ionic_get_tunable,
789 .set_tunable = ionic_set_tunable,
790 .get_module_info = ionic_get_module_info,
791 .get_module_eeprom = ionic_get_module_eeprom,
792 .get_pauseparam = ionic_get_pauseparam,
793 .set_pauseparam = ionic_set_pauseparam,
794 .get_fecparam = ionic_get_fecparam,
795 .set_fecparam = ionic_set_fecparam,
796 .nway_reset = ionic_nway_reset,
797};
798
799void ionic_ethtool_set_ops(struct net_device *netdev)
800{
801 netdev->ethtool_ops = &ionic_ethtool_ops;
802}