1 // SPDX-License-Identifier: GPL-2.0
2 /* Marvell OcteonTx2 RVU Ethernet driver
3 *
4 * Copyright (C) 2020 Marvell International Ltd.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11 #include <linux/pci.h>
12 #include <linux/ethtool.h>
13 #include <linux/stddef.h>
14 #include <linux/etherdevice.h>
15 #include <linux/log2.h>
16 #include <linux/net_tstamp.h>
17
18 #include "otx2_common.h"
19 #include "otx2_ptp.h"
20
21 #define DRV_NAME "octeontx2-nicpf"
22 #define DRV_VF_NAME "octeontx2-nicvf"
23
24 struct otx2_stat {
25 char name[ETH_GSTRING_LEN];
26 unsigned int index;
27 };
28
29 /* HW device stats */
30 #define OTX2_DEV_STAT(stat) { \
31 .name = #stat, \
32 .index = offsetof(struct otx2_dev_stats, stat) / sizeof(u64), \
33 }
34
35 static const struct otx2_stat otx2_dev_stats[] = {
36 OTX2_DEV_STAT(rx_ucast_frames),
37 OTX2_DEV_STAT(rx_bcast_frames),
38 OTX2_DEV_STAT(rx_mcast_frames),
39
40 OTX2_DEV_STAT(tx_ucast_frames),
41 OTX2_DEV_STAT(tx_bcast_frames),
42 OTX2_DEV_STAT(tx_mcast_frames),
43 };
44
45 /* Driver level stats */
46 #define OTX2_DRV_STAT(stat) { \
47 .name = #stat, \
48 .index = offsetof(struct otx2_drv_stats, stat) / sizeof(atomic_t), \
49 }
50
51 static const struct otx2_stat otx2_drv_stats[] = {
52 OTX2_DRV_STAT(rx_fcs_errs),
53 OTX2_DRV_STAT(rx_oversize_errs),
54 OTX2_DRV_STAT(rx_undersize_errs),
55 OTX2_DRV_STAT(rx_csum_errs),
56 OTX2_DRV_STAT(rx_len_errs),
57 OTX2_DRV_STAT(rx_other_errs),
58 };
59
60 static const struct otx2_stat otx2_queue_stats[] = {
61 { "bytes", 0 },
62 { "frames", 1 },
63 };
64
65 static const unsigned int otx2_n_dev_stats = ARRAY_SIZE(otx2_dev_stats);
66 static const unsigned int otx2_n_drv_stats = ARRAY_SIZE(otx2_drv_stats);
67 static const unsigned int otx2_n_queue_stats = ARRAY_SIZE(otx2_queue_stats);
68
otx2_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *info)69 static void otx2_get_drvinfo(struct net_device *netdev,
70 struct ethtool_drvinfo *info)
71 {
72 struct otx2_nic *pfvf = netdev_priv(netdev);
73
74 strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
75 strlcpy(info->bus_info, pci_name(pfvf->pdev), sizeof(info->bus_info));
76 }
77
otx2_get_qset_strings(struct otx2_nic *pfvf, u8 **data, int qset)78 static void otx2_get_qset_strings(struct otx2_nic *pfvf, u8 **data, int qset)
79 {
80 int start_qidx = qset * pfvf->hw.rx_queues;
81 int qidx, stats;
82
83 for (qidx = 0; qidx < pfvf->hw.rx_queues; qidx++) {
84 for (stats = 0; stats < otx2_n_queue_stats; stats++) {
85 sprintf(*data, "rxq%d: %s", qidx + start_qidx,
86 otx2_queue_stats[stats].name);
87 *data += ETH_GSTRING_LEN;
88 }
89 }
90 for (qidx = 0; qidx < pfvf->hw.tx_queues; qidx++) {
91 for (stats = 0; stats < otx2_n_queue_stats; stats++) {
92 sprintf(*data, "txq%d: %s", qidx + start_qidx,
93 otx2_queue_stats[stats].name);
94 *data += ETH_GSTRING_LEN;
95 }
96 }
97 }
98
otx2_get_strings(struct net_device *netdev, u32 sset, u8 *data)99 static void otx2_get_strings(struct net_device *netdev, u32 sset, u8 *data)
100 {
101 struct otx2_nic *pfvf = netdev_priv(netdev);
102 int stats;
103
104 if (sset != ETH_SS_STATS)
105 return;
106
107 for (stats = 0; stats < otx2_n_dev_stats; stats++) {
108 memcpy(data, otx2_dev_stats[stats].name, ETH_GSTRING_LEN);
109 data += ETH_GSTRING_LEN;
110 }
111
112 for (stats = 0; stats < otx2_n_drv_stats; stats++) {
113 memcpy(data, otx2_drv_stats[stats].name, ETH_GSTRING_LEN);
114 data += ETH_GSTRING_LEN;
115 }
116
117 otx2_get_qset_strings(pfvf, &data, 0);
118
119 for (stats = 0; stats < CGX_RX_STATS_COUNT; stats++) {
120 sprintf(data, "cgx_rxstat%d: ", stats);
121 data += ETH_GSTRING_LEN;
122 }
123
124 for (stats = 0; stats < CGX_TX_STATS_COUNT; stats++) {
125 sprintf(data, "cgx_txstat%d: ", stats);
126 data += ETH_GSTRING_LEN;
127 }
128
129 strcpy(data, "reset_count");
130 data += ETH_GSTRING_LEN;
131 }
132
otx2_get_qset_stats(struct otx2_nic *pfvf, struct ethtool_stats *stats, u64 **data)133 static void otx2_get_qset_stats(struct otx2_nic *pfvf,
134 struct ethtool_stats *stats, u64 **data)
135 {
136 int stat, qidx;
137
138 if (!pfvf)
139 return;
140 for (qidx = 0; qidx < pfvf->hw.rx_queues; qidx++) {
141 if (!otx2_update_rq_stats(pfvf, qidx)) {
142 for (stat = 0; stat < otx2_n_queue_stats; stat++)
143 *((*data)++) = 0;
144 continue;
145 }
146 for (stat = 0; stat < otx2_n_queue_stats; stat++)
147 *((*data)++) = ((u64 *)&pfvf->qset.rq[qidx].stats)
148 [otx2_queue_stats[stat].index];
149 }
150
151 for (qidx = 0; qidx < pfvf->hw.tx_queues; qidx++) {
152 if (!otx2_update_sq_stats(pfvf, qidx)) {
153 for (stat = 0; stat < otx2_n_queue_stats; stat++)
154 *((*data)++) = 0;
155 continue;
156 }
157 for (stat = 0; stat < otx2_n_queue_stats; stat++)
158 *((*data)++) = ((u64 *)&pfvf->qset.sq[qidx].stats)
159 [otx2_queue_stats[stat].index];
160 }
161 }
162
163 /* Get device and per queue statistics */
otx2_get_ethtool_stats(struct net_device *netdev, struct ethtool_stats *stats, u64 *data)164 static void otx2_get_ethtool_stats(struct net_device *netdev,
165 struct ethtool_stats *stats, u64 *data)
166 {
167 struct otx2_nic *pfvf = netdev_priv(netdev);
168 int stat;
169
170 otx2_get_dev_stats(pfvf);
171 for (stat = 0; stat < otx2_n_dev_stats; stat++)
172 *(data++) = ((u64 *)&pfvf->hw.dev_stats)
173 [otx2_dev_stats[stat].index];
174
175 for (stat = 0; stat < otx2_n_drv_stats; stat++)
176 *(data++) = atomic_read(&((atomic_t *)&pfvf->hw.drv_stats)
177 [otx2_drv_stats[stat].index]);
178
179 otx2_get_qset_stats(pfvf, stats, &data);
180 otx2_update_lmac_stats(pfvf);
181 for (stat = 0; stat < CGX_RX_STATS_COUNT; stat++)
182 *(data++) = pfvf->hw.cgx_rx_stats[stat];
183 for (stat = 0; stat < CGX_TX_STATS_COUNT; stat++)
184 *(data++) = pfvf->hw.cgx_tx_stats[stat];
185 *(data++) = pfvf->reset_count;
186 }
187
otx2_get_sset_count(struct net_device *netdev, int sset)188 static int otx2_get_sset_count(struct net_device *netdev, int sset)
189 {
190 struct otx2_nic *pfvf = netdev_priv(netdev);
191 int qstats_count;
192
193 if (sset != ETH_SS_STATS)
194 return -EINVAL;
195
196 qstats_count = otx2_n_queue_stats *
197 (pfvf->hw.rx_queues + pfvf->hw.tx_queues);
198
199 return otx2_n_dev_stats + otx2_n_drv_stats + qstats_count +
200 CGX_RX_STATS_COUNT + CGX_TX_STATS_COUNT + 1;
201 }
202
203 /* Get no of queues device supports and current queue count */
otx2_get_channels(struct net_device *dev, struct ethtool_channels *channel)204 static void otx2_get_channels(struct net_device *dev,
205 struct ethtool_channels *channel)
206 {
207 struct otx2_nic *pfvf = netdev_priv(dev);
208
209 channel->max_rx = pfvf->hw.max_queues;
210 channel->max_tx = pfvf->hw.max_queues;
211
212 channel->rx_count = pfvf->hw.rx_queues;
213 channel->tx_count = pfvf->hw.tx_queues;
214 }
215
216 /* Set no of Tx, Rx queues to be used */
otx2_set_channels(struct net_device *dev, struct ethtool_channels *channel)217 static int otx2_set_channels(struct net_device *dev,
218 struct ethtool_channels *channel)
219 {
220 struct otx2_nic *pfvf = netdev_priv(dev);
221 bool if_up = netif_running(dev);
222 int err = 0;
223
224 if (!channel->rx_count || !channel->tx_count)
225 return -EINVAL;
226
227 if (if_up)
228 dev->netdev_ops->ndo_stop(dev);
229
230 err = otx2_set_real_num_queues(dev, channel->tx_count,
231 channel->rx_count);
232 if (err)
233 return err;
234
235 pfvf->hw.rx_queues = channel->rx_count;
236 pfvf->hw.tx_queues = channel->tx_count;
237 pfvf->qset.cq_cnt = pfvf->hw.tx_queues + pfvf->hw.rx_queues;
238
239 if (if_up)
240 err = dev->netdev_ops->ndo_open(dev);
241
242 netdev_info(dev, "Setting num Tx rings to %d, Rx rings to %d success\n",
243 pfvf->hw.tx_queues, pfvf->hw.rx_queues);
244
245 return err;
246 }
247
otx2_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause)248 static void otx2_get_pauseparam(struct net_device *netdev,
249 struct ethtool_pauseparam *pause)
250 {
251 struct otx2_nic *pfvf = netdev_priv(netdev);
252 struct cgx_pause_frm_cfg *req, *rsp;
253
254 if (is_otx2_lbkvf(pfvf->pdev))
255 return;
256
257 mutex_lock(&pfvf->mbox.lock);
258 req = otx2_mbox_alloc_msg_cgx_cfg_pause_frm(&pfvf->mbox);
259 if (!req) {
260 mutex_unlock(&pfvf->mbox.lock);
261 return;
262 }
263
264 if (!otx2_sync_mbox_msg(&pfvf->mbox)) {
265 rsp = (struct cgx_pause_frm_cfg *)
266 otx2_mbox_get_rsp(&pfvf->mbox.mbox, 0, &req->hdr);
267 pause->rx_pause = rsp->rx_pause;
268 pause->tx_pause = rsp->tx_pause;
269 }
270 mutex_unlock(&pfvf->mbox.lock);
271 }
272
otx2_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause)273 static int otx2_set_pauseparam(struct net_device *netdev,
274 struct ethtool_pauseparam *pause)
275 {
276 struct otx2_nic *pfvf = netdev_priv(netdev);
277
278 if (pause->autoneg)
279 return -EOPNOTSUPP;
280
281 if (is_otx2_lbkvf(pfvf->pdev))
282 return -EOPNOTSUPP;
283
284 if (pause->rx_pause)
285 pfvf->flags |= OTX2_FLAG_RX_PAUSE_ENABLED;
286 else
287 pfvf->flags &= ~OTX2_FLAG_RX_PAUSE_ENABLED;
288
289 if (pause->tx_pause)
290 pfvf->flags |= OTX2_FLAG_TX_PAUSE_ENABLED;
291 else
292 pfvf->flags &= ~OTX2_FLAG_TX_PAUSE_ENABLED;
293
294 return otx2_config_pause_frm(pfvf);
295 }
296
otx2_get_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)297 static void otx2_get_ringparam(struct net_device *netdev,
298 struct ethtool_ringparam *ring)
299 {
300 struct otx2_nic *pfvf = netdev_priv(netdev);
301 struct otx2_qset *qs = &pfvf->qset;
302
303 ring->rx_max_pending = Q_COUNT(Q_SIZE_MAX);
304 ring->rx_pending = qs->rqe_cnt ? qs->rqe_cnt : Q_COUNT(Q_SIZE_256);
305 ring->tx_max_pending = Q_COUNT(Q_SIZE_MAX);
306 ring->tx_pending = qs->sqe_cnt ? qs->sqe_cnt : Q_COUNT(Q_SIZE_4K);
307 }
308
otx2_set_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)309 static int otx2_set_ringparam(struct net_device *netdev,
310 struct ethtool_ringparam *ring)
311 {
312 struct otx2_nic *pfvf = netdev_priv(netdev);
313 bool if_up = netif_running(netdev);
314 struct otx2_qset *qs = &pfvf->qset;
315 u32 rx_count, tx_count;
316
317 if (ring->rx_mini_pending || ring->rx_jumbo_pending)
318 return -EINVAL;
319
320 /* Permitted lengths are 16 64 256 1K 4K 16K 64K 256K 1M */
321 rx_count = ring->rx_pending;
322 /* On some silicon variants a skid or reserved CQEs are
323 * needed to avoid CQ overflow.
324 */
325 if (rx_count < pfvf->hw.rq_skid)
326 rx_count = pfvf->hw.rq_skid;
327 rx_count = Q_COUNT(Q_SIZE(rx_count, 3));
328
329 /* Due pipelining impact minimum 2000 unused SQ CQE's
330 * need to be maintained to avoid CQ overflow, hence the
331 * minimum 4K size.
332 */
333 tx_count = clamp_t(u32, ring->tx_pending,
334 Q_COUNT(Q_SIZE_4K), Q_COUNT(Q_SIZE_MAX));
335 tx_count = Q_COUNT(Q_SIZE(tx_count, 3));
336
337 if (tx_count == qs->sqe_cnt && rx_count == qs->rqe_cnt)
338 return 0;
339
340 if (if_up)
341 netdev->netdev_ops->ndo_stop(netdev);
342
343 /* Assigned to the nearest possible exponent. */
344 qs->sqe_cnt = tx_count;
345 qs->rqe_cnt = rx_count;
346
347 if (if_up)
348 return netdev->netdev_ops->ndo_open(netdev);
349
350 return 0;
351 }
352
otx2_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *cmd)353 static int otx2_get_coalesce(struct net_device *netdev,
354 struct ethtool_coalesce *cmd)
355 {
356 struct otx2_nic *pfvf = netdev_priv(netdev);
357 struct otx2_hw *hw = &pfvf->hw;
358
359 cmd->rx_coalesce_usecs = hw->cq_time_wait;
360 cmd->rx_max_coalesced_frames = hw->cq_ecount_wait;
361 cmd->tx_coalesce_usecs = hw->cq_time_wait;
362 cmd->tx_max_coalesced_frames = hw->cq_ecount_wait;
363
364 return 0;
365 }
366
otx2_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec)367 static int otx2_set_coalesce(struct net_device *netdev,
368 struct ethtool_coalesce *ec)
369 {
370 struct otx2_nic *pfvf = netdev_priv(netdev);
371 struct otx2_hw *hw = &pfvf->hw;
372 int qidx;
373
374 if (!ec->rx_max_coalesced_frames || !ec->tx_max_coalesced_frames)
375 return 0;
376
377 /* 'cq_time_wait' is 8bit and is in multiple of 100ns,
378 * so clamp the user given value to the range of 1 to 25usec.
379 */
380 ec->rx_coalesce_usecs = clamp_t(u32, ec->rx_coalesce_usecs,
381 1, CQ_TIMER_THRESH_MAX);
382 ec->tx_coalesce_usecs = clamp_t(u32, ec->tx_coalesce_usecs,
383 1, CQ_TIMER_THRESH_MAX);
384
385 /* Rx and Tx are mapped to same CQ, check which one
386 * is changed, if both then choose the min.
387 */
388 if (hw->cq_time_wait == ec->rx_coalesce_usecs)
389 hw->cq_time_wait = ec->tx_coalesce_usecs;
390 else if (hw->cq_time_wait == ec->tx_coalesce_usecs)
391 hw->cq_time_wait = ec->rx_coalesce_usecs;
392 else
393 hw->cq_time_wait = min_t(u8, ec->rx_coalesce_usecs,
394 ec->tx_coalesce_usecs);
395
396 /* Max ecount_wait supported is 16bit,
397 * so clamp the user given value to the range of 1 to 64k.
398 */
399 ec->rx_max_coalesced_frames = clamp_t(u32, ec->rx_max_coalesced_frames,
400 1, U16_MAX);
401 ec->tx_max_coalesced_frames = clamp_t(u32, ec->tx_max_coalesced_frames,
402 1, U16_MAX);
403
404 /* Rx and Tx are mapped to same CQ, check which one
405 * is changed, if both then choose the min.
406 */
407 if (hw->cq_ecount_wait == ec->rx_max_coalesced_frames)
408 hw->cq_ecount_wait = ec->tx_max_coalesced_frames;
409 else if (hw->cq_ecount_wait == ec->tx_max_coalesced_frames)
410 hw->cq_ecount_wait = ec->rx_max_coalesced_frames;
411 else
412 hw->cq_ecount_wait = min_t(u16, ec->rx_max_coalesced_frames,
413 ec->tx_max_coalesced_frames);
414
415 if (netif_running(netdev)) {
416 for (qidx = 0; qidx < pfvf->hw.cint_cnt; qidx++)
417 otx2_config_irq_coalescing(pfvf, qidx);
418 }
419
420 return 0;
421 }
422
otx2_get_rss_hash_opts(struct otx2_nic *pfvf, struct ethtool_rxnfc *nfc)423 static int otx2_get_rss_hash_opts(struct otx2_nic *pfvf,
424 struct ethtool_rxnfc *nfc)
425 {
426 struct otx2_rss_info *rss = &pfvf->hw.rss_info;
427
428 if (!(rss->flowkey_cfg &
429 (NIX_FLOW_KEY_TYPE_IPV4 | NIX_FLOW_KEY_TYPE_IPV6)))
430 return 0;
431
432 /* Mimimum is IPv4 and IPv6, SIP/DIP */
433 nfc->data = RXH_IP_SRC | RXH_IP_DST;
434 if (rss->flowkey_cfg & NIX_FLOW_KEY_TYPE_VLAN)
435 nfc->data |= RXH_VLAN;
436
437 switch (nfc->flow_type) {
438 case TCP_V4_FLOW:
439 case TCP_V6_FLOW:
440 if (rss->flowkey_cfg & NIX_FLOW_KEY_TYPE_TCP)
441 nfc->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
442 break;
443 case UDP_V4_FLOW:
444 case UDP_V6_FLOW:
445 if (rss->flowkey_cfg & NIX_FLOW_KEY_TYPE_UDP)
446 nfc->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
447 break;
448 case SCTP_V4_FLOW:
449 case SCTP_V6_FLOW:
450 if (rss->flowkey_cfg & NIX_FLOW_KEY_TYPE_SCTP)
451 nfc->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
452 break;
453 case AH_ESP_V4_FLOW:
454 case AH_V4_FLOW:
455 case ESP_V4_FLOW:
456 case IPV4_FLOW:
457 case AH_ESP_V6_FLOW:
458 case AH_V6_FLOW:
459 case ESP_V6_FLOW:
460 case IPV6_FLOW:
461 break;
462 default:
463 return -EINVAL;
464 }
465 return 0;
466 }
467
otx2_set_rss_hash_opts(struct otx2_nic *pfvf, struct ethtool_rxnfc *nfc)468 static int otx2_set_rss_hash_opts(struct otx2_nic *pfvf,
469 struct ethtool_rxnfc *nfc)
470 {
471 struct otx2_rss_info *rss = &pfvf->hw.rss_info;
472 u32 rxh_l4 = RXH_L4_B_0_1 | RXH_L4_B_2_3;
473 u32 rss_cfg = rss->flowkey_cfg;
474
475 if (!rss->enable) {
476 netdev_err(pfvf->netdev,
477 "RSS is disabled, cannot change settings\n");
478 return -EIO;
479 }
480
481 /* Mimimum is IPv4 and IPv6, SIP/DIP */
482 if (!(nfc->data & RXH_IP_SRC) || !(nfc->data & RXH_IP_DST))
483 return -EINVAL;
484
485 if (nfc->data & RXH_VLAN)
486 rss_cfg |= NIX_FLOW_KEY_TYPE_VLAN;
487 else
488 rss_cfg &= ~NIX_FLOW_KEY_TYPE_VLAN;
489
490 switch (nfc->flow_type) {
491 case TCP_V4_FLOW:
492 case TCP_V6_FLOW:
493 /* Different config for v4 and v6 is not supported.
494 * Both of them have to be either 4-tuple or 2-tuple.
495 */
496 switch (nfc->data & rxh_l4) {
497 case 0:
498 rss_cfg &= ~NIX_FLOW_KEY_TYPE_TCP;
499 break;
500 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
501 rss_cfg |= NIX_FLOW_KEY_TYPE_TCP;
502 break;
503 default:
504 return -EINVAL;
505 }
506 break;
507 case UDP_V4_FLOW:
508 case UDP_V6_FLOW:
509 switch (nfc->data & rxh_l4) {
510 case 0:
511 rss_cfg &= ~NIX_FLOW_KEY_TYPE_UDP;
512 break;
513 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
514 rss_cfg |= NIX_FLOW_KEY_TYPE_UDP;
515 break;
516 default:
517 return -EINVAL;
518 }
519 break;
520 case SCTP_V4_FLOW:
521 case SCTP_V6_FLOW:
522 switch (nfc->data & rxh_l4) {
523 case 0:
524 rss_cfg &= ~NIX_FLOW_KEY_TYPE_SCTP;
525 break;
526 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
527 rss_cfg |= NIX_FLOW_KEY_TYPE_SCTP;
528 break;
529 default:
530 return -EINVAL;
531 }
532 break;
533 case IPV4_FLOW:
534 case IPV6_FLOW:
535 rss_cfg = NIX_FLOW_KEY_TYPE_IPV4 | NIX_FLOW_KEY_TYPE_IPV6;
536 break;
537 default:
538 return -EINVAL;
539 }
540
541 rss->flowkey_cfg = rss_cfg;
542 otx2_set_flowkey_cfg(pfvf);
543 return 0;
544 }
545
otx2_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *nfc, u32 *rules)546 static int otx2_get_rxnfc(struct net_device *dev,
547 struct ethtool_rxnfc *nfc, u32 *rules)
548 {
549 struct otx2_nic *pfvf = netdev_priv(dev);
550 int ret = -EOPNOTSUPP;
551
552 switch (nfc->cmd) {
553 case ETHTOOL_GRXRINGS:
554 nfc->data = pfvf->hw.rx_queues;
555 ret = 0;
556 break;
557 case ETHTOOL_GRXFH:
558 return otx2_get_rss_hash_opts(pfvf, nfc);
559 default:
560 break;
561 }
562 return ret;
563 }
564
otx2_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *nfc)565 static int otx2_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *nfc)
566 {
567 struct otx2_nic *pfvf = netdev_priv(dev);
568 int ret = -EOPNOTSUPP;
569
570 switch (nfc->cmd) {
571 case ETHTOOL_SRXFH:
572 ret = otx2_set_rss_hash_opts(pfvf, nfc);
573 break;
574 default:
575 break;
576 }
577
578 return ret;
579 }
580
otx2_get_rxfh_key_size(struct net_device *netdev)581 static u32 otx2_get_rxfh_key_size(struct net_device *netdev)
582 {
583 struct otx2_nic *pfvf = netdev_priv(netdev);
584 struct otx2_rss_info *rss;
585
586 rss = &pfvf->hw.rss_info;
587
588 return sizeof(rss->key);
589 }
590
otx2_get_rxfh_indir_size(struct net_device *dev)591 static u32 otx2_get_rxfh_indir_size(struct net_device *dev)
592 {
593 struct otx2_nic *pfvf = netdev_priv(dev);
594
595 return pfvf->hw.rss_info.rss_size;
596 }
597
598 /* Get RSS configuration */
otx2_get_rxfh(struct net_device *dev, u32 *indir, u8 *hkey, u8 *hfunc)599 static int otx2_get_rxfh(struct net_device *dev, u32 *indir,
600 u8 *hkey, u8 *hfunc)
601 {
602 struct otx2_nic *pfvf = netdev_priv(dev);
603 struct otx2_rss_info *rss;
604 int idx;
605
606 rss = &pfvf->hw.rss_info;
607
608 if (indir) {
609 for (idx = 0; idx < rss->rss_size; idx++)
610 indir[idx] = rss->ind_tbl[idx];
611 }
612
613 if (hkey)
614 memcpy(hkey, rss->key, sizeof(rss->key));
615
616 if (hfunc)
617 *hfunc = ETH_RSS_HASH_TOP;
618
619 return 0;
620 }
621
622 /* Configure RSS table and hash key */
otx2_set_rxfh(struct net_device *dev, const u32 *indir, const u8 *hkey, const u8 hfunc)623 static int otx2_set_rxfh(struct net_device *dev, const u32 *indir,
624 const u8 *hkey, const u8 hfunc)
625 {
626 struct otx2_nic *pfvf = netdev_priv(dev);
627 struct otx2_rss_info *rss;
628 int idx;
629
630 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
631 return -EOPNOTSUPP;
632
633 rss = &pfvf->hw.rss_info;
634
635 if (!rss->enable) {
636 netdev_err(dev, "RSS is disabled, cannot change settings\n");
637 return -EIO;
638 }
639
640 if (indir) {
641 for (idx = 0; idx < rss->rss_size; idx++)
642 rss->ind_tbl[idx] = indir[idx];
643 }
644
645 if (hkey) {
646 memcpy(rss->key, hkey, sizeof(rss->key));
647 otx2_set_rss_key(pfvf);
648 }
649
650 otx2_set_rss_table(pfvf);
651 return 0;
652 }
653
otx2_get_msglevel(struct net_device *netdev)654 static u32 otx2_get_msglevel(struct net_device *netdev)
655 {
656 struct otx2_nic *pfvf = netdev_priv(netdev);
657
658 return pfvf->msg_enable;
659 }
660
otx2_set_msglevel(struct net_device *netdev, u32 val)661 static void otx2_set_msglevel(struct net_device *netdev, u32 val)
662 {
663 struct otx2_nic *pfvf = netdev_priv(netdev);
664
665 pfvf->msg_enable = val;
666 }
667
otx2_get_link(struct net_device *netdev)668 static u32 otx2_get_link(struct net_device *netdev)
669 {
670 struct otx2_nic *pfvf = netdev_priv(netdev);
671
672 /* LBK link is internal and always UP */
673 if (is_otx2_lbkvf(pfvf->pdev))
674 return 1;
675 return pfvf->linfo.link_up;
676 }
677
otx2_get_ts_info(struct net_device *netdev, struct ethtool_ts_info *info)678 static int otx2_get_ts_info(struct net_device *netdev,
679 struct ethtool_ts_info *info)
680 {
681 struct otx2_nic *pfvf = netdev_priv(netdev);
682
683 if (!pfvf->ptp)
684 return ethtool_op_get_ts_info(netdev, info);
685
686 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
687 SOF_TIMESTAMPING_RX_SOFTWARE |
688 SOF_TIMESTAMPING_SOFTWARE |
689 SOF_TIMESTAMPING_TX_HARDWARE |
690 SOF_TIMESTAMPING_RX_HARDWARE |
691 SOF_TIMESTAMPING_RAW_HARDWARE;
692
693 info->phc_index = otx2_ptp_clock_index(pfvf);
694
695 info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
696
697 info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
698 (1 << HWTSTAMP_FILTER_ALL);
699
700 return 0;
701 }
702
703 static const struct ethtool_ops otx2_ethtool_ops = {
704 .supported_coalesce_params = ETHTOOL_COALESCE_USECS |
705 ETHTOOL_COALESCE_MAX_FRAMES,
706 .get_link = otx2_get_link,
707 .get_drvinfo = otx2_get_drvinfo,
708 .get_strings = otx2_get_strings,
709 .get_ethtool_stats = otx2_get_ethtool_stats,
710 .get_sset_count = otx2_get_sset_count,
711 .set_channels = otx2_set_channels,
712 .get_channels = otx2_get_channels,
713 .get_ringparam = otx2_get_ringparam,
714 .set_ringparam = otx2_set_ringparam,
715 .get_coalesce = otx2_get_coalesce,
716 .set_coalesce = otx2_set_coalesce,
717 .get_rxnfc = otx2_get_rxnfc,
718 .set_rxnfc = otx2_set_rxnfc,
719 .get_rxfh_key_size = otx2_get_rxfh_key_size,
720 .get_rxfh_indir_size = otx2_get_rxfh_indir_size,
721 .get_rxfh = otx2_get_rxfh,
722 .set_rxfh = otx2_set_rxfh,
723 .get_msglevel = otx2_get_msglevel,
724 .set_msglevel = otx2_set_msglevel,
725 .get_pauseparam = otx2_get_pauseparam,
726 .set_pauseparam = otx2_set_pauseparam,
727 .get_ts_info = otx2_get_ts_info,
728 };
729
otx2_set_ethtool_ops(struct net_device *netdev)730 void otx2_set_ethtool_ops(struct net_device *netdev)
731 {
732 netdev->ethtool_ops = &otx2_ethtool_ops;
733 }
734
735 /* VF's ethtool APIs */
otx2vf_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *info)736 static void otx2vf_get_drvinfo(struct net_device *netdev,
737 struct ethtool_drvinfo *info)
738 {
739 struct otx2_nic *vf = netdev_priv(netdev);
740
741 strlcpy(info->driver, DRV_VF_NAME, sizeof(info->driver));
742 strlcpy(info->bus_info, pci_name(vf->pdev), sizeof(info->bus_info));
743 }
744
otx2vf_get_strings(struct net_device *netdev, u32 sset, u8 *data)745 static void otx2vf_get_strings(struct net_device *netdev, u32 sset, u8 *data)
746 {
747 struct otx2_nic *vf = netdev_priv(netdev);
748 int stats;
749
750 if (sset != ETH_SS_STATS)
751 return;
752
753 for (stats = 0; stats < otx2_n_dev_stats; stats++) {
754 memcpy(data, otx2_dev_stats[stats].name, ETH_GSTRING_LEN);
755 data += ETH_GSTRING_LEN;
756 }
757
758 for (stats = 0; stats < otx2_n_drv_stats; stats++) {
759 memcpy(data, otx2_drv_stats[stats].name, ETH_GSTRING_LEN);
760 data += ETH_GSTRING_LEN;
761 }
762
763 otx2_get_qset_strings(vf, &data, 0);
764
765 strcpy(data, "reset_count");
766 data += ETH_GSTRING_LEN;
767 }
768
otx2vf_get_ethtool_stats(struct net_device *netdev, struct ethtool_stats *stats, u64 *data)769 static void otx2vf_get_ethtool_stats(struct net_device *netdev,
770 struct ethtool_stats *stats, u64 *data)
771 {
772 struct otx2_nic *vf = netdev_priv(netdev);
773 int stat;
774
775 otx2_get_dev_stats(vf);
776 for (stat = 0; stat < otx2_n_dev_stats; stat++)
777 *(data++) = ((u64 *)&vf->hw.dev_stats)
778 [otx2_dev_stats[stat].index];
779
780 for (stat = 0; stat < otx2_n_drv_stats; stat++)
781 *(data++) = atomic_read(&((atomic_t *)&vf->hw.drv_stats)
782 [otx2_drv_stats[stat].index]);
783
784 otx2_get_qset_stats(vf, stats, &data);
785 *(data++) = vf->reset_count;
786 }
787
otx2vf_get_sset_count(struct net_device *netdev, int sset)788 static int otx2vf_get_sset_count(struct net_device *netdev, int sset)
789 {
790 struct otx2_nic *vf = netdev_priv(netdev);
791 int qstats_count;
792
793 if (sset != ETH_SS_STATS)
794 return -EINVAL;
795
796 qstats_count = otx2_n_queue_stats *
797 (vf->hw.rx_queues + vf->hw.tx_queues);
798
799 return otx2_n_dev_stats + otx2_n_drv_stats + qstats_count + 1;
800 }
801
802 static const struct ethtool_ops otx2vf_ethtool_ops = {
803 .supported_coalesce_params = ETHTOOL_COALESCE_USECS |
804 ETHTOOL_COALESCE_MAX_FRAMES,
805 .get_link = otx2_get_link,
806 .get_drvinfo = otx2vf_get_drvinfo,
807 .get_strings = otx2vf_get_strings,
808 .get_ethtool_stats = otx2vf_get_ethtool_stats,
809 .get_sset_count = otx2vf_get_sset_count,
810 .set_channels = otx2_set_channels,
811 .get_channels = otx2_get_channels,
812 .get_rxnfc = otx2_get_rxnfc,
813 .set_rxnfc = otx2_set_rxnfc,
814 .get_rxfh_key_size = otx2_get_rxfh_key_size,
815 .get_rxfh_indir_size = otx2_get_rxfh_indir_size,
816 .get_rxfh = otx2_get_rxfh,
817 .set_rxfh = otx2_set_rxfh,
818 .get_ringparam = otx2_get_ringparam,
819 .set_ringparam = otx2_set_ringparam,
820 .get_coalesce = otx2_get_coalesce,
821 .set_coalesce = otx2_set_coalesce,
822 .get_msglevel = otx2_get_msglevel,
823 .set_msglevel = otx2_set_msglevel,
824 .get_pauseparam = otx2_get_pauseparam,
825 .set_pauseparam = otx2_set_pauseparam,
826 };
827
otx2vf_set_ethtool_ops(struct net_device *netdev)828 void otx2vf_set_ethtool_ops(struct net_device *netdev)
829 {
830 netdev->ethtool_ops = &otx2vf_ethtool_ops;
831 }
832 EXPORT_SYMBOL(otx2vf_set_ethtool_ops);
833