1eec2cd657ffce8b8d184df807300cf302f5c511
[deliverable/linux.git] / drivers / net / ethernet / cavium / thunder / nicvf_ethtool.c
1 /*
2 * Copyright (C) 2015 Cavium, Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License
6 * as published by the Free Software Foundation.
7 */
8
9 /* ETHTOOL Support for VNIC_VF Device*/
10
11 #include <linux/pci.h>
12
13 #include "nic_reg.h"
14 #include "nic.h"
15 #include "nicvf_queues.h"
16 #include "q_struct.h"
17 #include "thunder_bgx.h"
18
19 #define DRV_NAME "thunder-nicvf"
20 #define DRV_VERSION "1.0"
21
22 struct nicvf_stat {
23 char name[ETH_GSTRING_LEN];
24 unsigned int index;
25 };
26
27 #define NICVF_HW_STAT(stat) { \
28 .name = #stat, \
29 .index = offsetof(struct nicvf_hw_stats, stat) / sizeof(u64), \
30 }
31
32 #define NICVF_DRV_STAT(stat) { \
33 .name = #stat, \
34 .index = offsetof(struct nicvf_drv_stats, stat) / sizeof(u64), \
35 }
36
37 static const struct nicvf_stat nicvf_hw_stats[] = {
38 NICVF_HW_STAT(rx_bytes),
39 NICVF_HW_STAT(rx_ucast_frames),
40 NICVF_HW_STAT(rx_bcast_frames),
41 NICVF_HW_STAT(rx_mcast_frames),
42 NICVF_HW_STAT(rx_fcs_errors),
43 NICVF_HW_STAT(rx_l2_errors),
44 NICVF_HW_STAT(rx_drop_red),
45 NICVF_HW_STAT(rx_drop_red_bytes),
46 NICVF_HW_STAT(rx_drop_overrun),
47 NICVF_HW_STAT(rx_drop_overrun_bytes),
48 NICVF_HW_STAT(rx_drop_bcast),
49 NICVF_HW_STAT(rx_drop_mcast),
50 NICVF_HW_STAT(rx_drop_l3_bcast),
51 NICVF_HW_STAT(rx_drop_l3_mcast),
52 NICVF_HW_STAT(rx_bgx_truncated_pkts),
53 NICVF_HW_STAT(rx_jabber_errs),
54 NICVF_HW_STAT(rx_fcs_errs),
55 NICVF_HW_STAT(rx_bgx_errs),
56 NICVF_HW_STAT(rx_prel2_errs),
57 NICVF_HW_STAT(rx_l2_hdr_malformed),
58 NICVF_HW_STAT(rx_oversize),
59 NICVF_HW_STAT(rx_undersize),
60 NICVF_HW_STAT(rx_l2_len_mismatch),
61 NICVF_HW_STAT(rx_l2_pclp),
62 NICVF_HW_STAT(rx_ip_ver_errs),
63 NICVF_HW_STAT(rx_ip_csum_errs),
64 NICVF_HW_STAT(rx_ip_hdr_malformed),
65 NICVF_HW_STAT(rx_ip_payload_malformed),
66 NICVF_HW_STAT(rx_ip_ttl_errs),
67 NICVF_HW_STAT(rx_l3_pclp),
68 NICVF_HW_STAT(rx_l4_malformed),
69 NICVF_HW_STAT(rx_l4_csum_errs),
70 NICVF_HW_STAT(rx_udp_len_errs),
71 NICVF_HW_STAT(rx_l4_port_errs),
72 NICVF_HW_STAT(rx_tcp_flag_errs),
73 NICVF_HW_STAT(rx_tcp_offset_errs),
74 NICVF_HW_STAT(rx_l4_pclp),
75 NICVF_HW_STAT(rx_truncated_pkts),
76 NICVF_HW_STAT(tx_bytes_ok),
77 NICVF_HW_STAT(tx_ucast_frames_ok),
78 NICVF_HW_STAT(tx_bcast_frames_ok),
79 NICVF_HW_STAT(tx_mcast_frames_ok),
80 };
81
82 static const struct nicvf_stat nicvf_drv_stats[] = {
83 NICVF_DRV_STAT(rx_frames_ok),
84 NICVF_DRV_STAT(rx_frames_64),
85 NICVF_DRV_STAT(rx_frames_127),
86 NICVF_DRV_STAT(rx_frames_255),
87 NICVF_DRV_STAT(rx_frames_511),
88 NICVF_DRV_STAT(rx_frames_1023),
89 NICVF_DRV_STAT(rx_frames_1518),
90 NICVF_DRV_STAT(rx_frames_jumbo),
91 NICVF_DRV_STAT(rx_drops),
92 NICVF_DRV_STAT(tx_frames_ok),
93 NICVF_DRV_STAT(tx_tso),
94 NICVF_DRV_STAT(tx_drops),
95 NICVF_DRV_STAT(txq_stop),
96 NICVF_DRV_STAT(txq_wake),
97 };
98
99 static const struct nicvf_stat nicvf_queue_stats[] = {
100 { "bytes", 0 },
101 { "frames", 1 },
102 };
103
104 static const unsigned int nicvf_n_hw_stats = ARRAY_SIZE(nicvf_hw_stats);
105 static const unsigned int nicvf_n_drv_stats = ARRAY_SIZE(nicvf_drv_stats);
106 static const unsigned int nicvf_n_queue_stats = ARRAY_SIZE(nicvf_queue_stats);
107
108 static int nicvf_get_settings(struct net_device *netdev,
109 struct ethtool_cmd *cmd)
110 {
111 struct nicvf *nic = netdev_priv(netdev);
112
113 cmd->supported = 0;
114 cmd->transceiver = XCVR_EXTERNAL;
115 if (nic->speed <= 1000) {
116 cmd->port = PORT_MII;
117 cmd->autoneg = AUTONEG_ENABLE;
118 } else {
119 cmd->port = PORT_FIBRE;
120 cmd->autoneg = AUTONEG_DISABLE;
121 }
122 cmd->duplex = nic->duplex;
123 ethtool_cmd_speed_set(cmd, nic->speed);
124
125 return 0;
126 }
127
128 static void nicvf_get_drvinfo(struct net_device *netdev,
129 struct ethtool_drvinfo *info)
130 {
131 struct nicvf *nic = netdev_priv(netdev);
132
133 strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
134 strlcpy(info->version, DRV_VERSION, sizeof(info->version));
135 strlcpy(info->bus_info, pci_name(nic->pdev), sizeof(info->bus_info));
136 }
137
138 static u32 nicvf_get_msglevel(struct net_device *netdev)
139 {
140 struct nicvf *nic = netdev_priv(netdev);
141
142 return nic->msg_enable;
143 }
144
145 static void nicvf_set_msglevel(struct net_device *netdev, u32 lvl)
146 {
147 struct nicvf *nic = netdev_priv(netdev);
148
149 nic->msg_enable = lvl;
150 }
151
152 static void nicvf_get_strings(struct net_device *netdev, u32 sset, u8 *data)
153 {
154 struct nicvf *nic = netdev_priv(netdev);
155 int stats, qidx;
156
157 if (sset != ETH_SS_STATS)
158 return;
159
160 for (stats = 0; stats < nicvf_n_hw_stats; stats++) {
161 memcpy(data, nicvf_hw_stats[stats].name, ETH_GSTRING_LEN);
162 data += ETH_GSTRING_LEN;
163 }
164
165 for (stats = 0; stats < nicvf_n_drv_stats; stats++) {
166 memcpy(data, nicvf_drv_stats[stats].name, ETH_GSTRING_LEN);
167 data += ETH_GSTRING_LEN;
168 }
169
170 for (qidx = 0; qidx < nic->qs->rq_cnt; qidx++) {
171 for (stats = 0; stats < nicvf_n_queue_stats; stats++) {
172 sprintf(data, "rxq%d: %s", qidx,
173 nicvf_queue_stats[stats].name);
174 data += ETH_GSTRING_LEN;
175 }
176 }
177
178 for (qidx = 0; qidx < nic->qs->sq_cnt; qidx++) {
179 for (stats = 0; stats < nicvf_n_queue_stats; stats++) {
180 sprintf(data, "txq%d: %s", qidx,
181 nicvf_queue_stats[stats].name);
182 data += ETH_GSTRING_LEN;
183 }
184 }
185
186 for (stats = 0; stats < BGX_RX_STATS_COUNT; stats++) {
187 sprintf(data, "bgx_rxstat%d: ", stats);
188 data += ETH_GSTRING_LEN;
189 }
190
191 for (stats = 0; stats < BGX_TX_STATS_COUNT; stats++) {
192 sprintf(data, "bgx_txstat%d: ", stats);
193 data += ETH_GSTRING_LEN;
194 }
195 }
196
197 static int nicvf_get_sset_count(struct net_device *netdev, int sset)
198 {
199 struct nicvf *nic = netdev_priv(netdev);
200
201 if (sset != ETH_SS_STATS)
202 return -EINVAL;
203
204 return nicvf_n_hw_stats + nicvf_n_drv_stats +
205 (nicvf_n_queue_stats *
206 (nic->qs->rq_cnt + nic->qs->sq_cnt)) +
207 BGX_RX_STATS_COUNT + BGX_TX_STATS_COUNT;
208 }
209
210 static void nicvf_get_ethtool_stats(struct net_device *netdev,
211 struct ethtool_stats *stats, u64 *data)
212 {
213 struct nicvf *nic = netdev_priv(netdev);
214 int stat, qidx;
215
216 nicvf_update_stats(nic);
217
218 /* Update LMAC stats */
219 nicvf_update_lmac_stats(nic);
220
221 for (stat = 0; stat < nicvf_n_hw_stats; stat++)
222 *(data++) = ((u64 *)&nic->hw_stats)
223 [nicvf_hw_stats[stat].index];
224 for (stat = 0; stat < nicvf_n_drv_stats; stat++)
225 *(data++) = ((u64 *)&nic->drv_stats)
226 [nicvf_drv_stats[stat].index];
227
228 for (qidx = 0; qidx < nic->qs->rq_cnt; qidx++) {
229 for (stat = 0; stat < nicvf_n_queue_stats; stat++)
230 *(data++) = ((u64 *)&nic->qs->rq[qidx].stats)
231 [nicvf_queue_stats[stat].index];
232 }
233
234 for (qidx = 0; qidx < nic->qs->sq_cnt; qidx++) {
235 for (stat = 0; stat < nicvf_n_queue_stats; stat++)
236 *(data++) = ((u64 *)&nic->qs->sq[qidx].stats)
237 [nicvf_queue_stats[stat].index];
238 }
239
240 for (stat = 0; stat < BGX_RX_STATS_COUNT; stat++)
241 *(data++) = nic->bgx_stats.rx_stats[stat];
242 for (stat = 0; stat < BGX_TX_STATS_COUNT; stat++)
243 *(data++) = nic->bgx_stats.tx_stats[stat];
244 }
245
246 static int nicvf_get_regs_len(struct net_device *dev)
247 {
248 return sizeof(u64) * NIC_VF_REG_COUNT;
249 }
250
251 static void nicvf_get_regs(struct net_device *dev,
252 struct ethtool_regs *regs, void *reg)
253 {
254 struct nicvf *nic = netdev_priv(dev);
255 u64 *p = (u64 *)reg;
256 u64 reg_offset;
257 int mbox, key, stat, q;
258 int i = 0;
259
260 regs->version = 0;
261 memset(p, 0, NIC_VF_REG_COUNT);
262
263 p[i++] = nicvf_reg_read(nic, NIC_VNIC_CFG);
264 /* Mailbox registers */
265 for (mbox = 0; mbox < NIC_PF_VF_MAILBOX_SIZE; mbox++)
266 p[i++] = nicvf_reg_read(nic,
267 NIC_VF_PF_MAILBOX_0_1 | (mbox << 3));
268
269 p[i++] = nicvf_reg_read(nic, NIC_VF_INT);
270 p[i++] = nicvf_reg_read(nic, NIC_VF_INT_W1S);
271 p[i++] = nicvf_reg_read(nic, NIC_VF_ENA_W1C);
272 p[i++] = nicvf_reg_read(nic, NIC_VF_ENA_W1S);
273 p[i++] = nicvf_reg_read(nic, NIC_VNIC_RSS_CFG);
274
275 for (key = 0; key < RSS_HASH_KEY_SIZE; key++)
276 p[i++] = nicvf_reg_read(nic, NIC_VNIC_RSS_KEY_0_4 | (key << 3));
277
278 /* Tx/Rx statistics */
279 for (stat = 0; stat < TX_STATS_ENUM_LAST; stat++)
280 p[i++] = nicvf_reg_read(nic,
281 NIC_VNIC_TX_STAT_0_4 | (stat << 3));
282
283 for (i = 0; i < RX_STATS_ENUM_LAST; i++)
284 p[i++] = nicvf_reg_read(nic,
285 NIC_VNIC_RX_STAT_0_13 | (stat << 3));
286
287 p[i++] = nicvf_reg_read(nic, NIC_QSET_RQ_GEN_CFG);
288
289 /* All completion queue's registers */
290 for (q = 0; q < MAX_CMP_QUEUES_PER_QS; q++) {
291 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_CFG, q);
292 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_CFG2, q);
293 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_THRESH, q);
294 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_BASE, q);
295 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_HEAD, q);
296 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_TAIL, q);
297 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_DOOR, q);
298 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_STATUS, q);
299 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_STATUS2, q);
300 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_DEBUG, q);
301 }
302
303 /* All receive queue's registers */
304 for (q = 0; q < MAX_RCV_QUEUES_PER_QS; q++) {
305 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_RQ_0_7_CFG, q);
306 p[i++] = nicvf_queue_reg_read(nic,
307 NIC_QSET_RQ_0_7_STAT_0_1, q);
308 reg_offset = NIC_QSET_RQ_0_7_STAT_0_1 | (1 << 3);
309 p[i++] = nicvf_queue_reg_read(nic, reg_offset, q);
310 }
311
312 for (q = 0; q < MAX_SND_QUEUES_PER_QS; q++) {
313 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_CFG, q);
314 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_THRESH, q);
315 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_BASE, q);
316 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_HEAD, q);
317 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_TAIL, q);
318 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_DOOR, q);
319 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_STATUS, q);
320 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_DEBUG, q);
321 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_CNM_CHG, q);
322 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_STAT_0_1, q);
323 reg_offset = NIC_QSET_SQ_0_7_STAT_0_1 | (1 << 3);
324 p[i++] = nicvf_queue_reg_read(nic, reg_offset, q);
325 }
326
327 for (q = 0; q < MAX_RCV_BUF_DESC_RINGS_PER_QS; q++) {
328 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_RBDR_0_1_CFG, q);
329 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_RBDR_0_1_THRESH, q);
330 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_RBDR_0_1_BASE, q);
331 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_RBDR_0_1_HEAD, q);
332 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_RBDR_0_1_TAIL, q);
333 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_RBDR_0_1_DOOR, q);
334 p[i++] = nicvf_queue_reg_read(nic,
335 NIC_QSET_RBDR_0_1_STATUS0, q);
336 p[i++] = nicvf_queue_reg_read(nic,
337 NIC_QSET_RBDR_0_1_STATUS1, q);
338 reg_offset = NIC_QSET_RBDR_0_1_PREFETCH_STATUS;
339 p[i++] = nicvf_queue_reg_read(nic, reg_offset, q);
340 }
341 }
342
343 static int nicvf_get_coalesce(struct net_device *netdev,
344 struct ethtool_coalesce *cmd)
345 {
346 struct nicvf *nic = netdev_priv(netdev);
347
348 cmd->rx_coalesce_usecs = nic->cq_coalesce_usecs;
349 return 0;
350 }
351
352 static void nicvf_get_ringparam(struct net_device *netdev,
353 struct ethtool_ringparam *ring)
354 {
355 struct nicvf *nic = netdev_priv(netdev);
356 struct queue_set *qs = nic->qs;
357
358 ring->rx_max_pending = MAX_RCV_BUF_COUNT;
359 ring->rx_pending = qs->rbdr_len;
360 ring->tx_max_pending = MAX_SND_QUEUE_LEN;
361 ring->tx_pending = qs->sq_len;
362 }
363
364 static int nicvf_get_rss_hash_opts(struct nicvf *nic,
365 struct ethtool_rxnfc *info)
366 {
367 info->data = 0;
368
369 switch (info->flow_type) {
370 case TCP_V4_FLOW:
371 case TCP_V6_FLOW:
372 case UDP_V4_FLOW:
373 case UDP_V6_FLOW:
374 case SCTP_V4_FLOW:
375 case SCTP_V6_FLOW:
376 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
377 case IPV4_FLOW:
378 case IPV6_FLOW:
379 info->data |= RXH_IP_SRC | RXH_IP_DST;
380 break;
381 default:
382 return -EINVAL;
383 }
384
385 return 0;
386 }
387
388 static int nicvf_get_rxnfc(struct net_device *dev,
389 struct ethtool_rxnfc *info, u32 *rules)
390 {
391 struct nicvf *nic = netdev_priv(dev);
392 int ret = -EOPNOTSUPP;
393
394 switch (info->cmd) {
395 case ETHTOOL_GRXRINGS:
396 info->data = nic->qs->rq_cnt;
397 ret = 0;
398 break;
399 case ETHTOOL_GRXFH:
400 return nicvf_get_rss_hash_opts(nic, info);
401 default:
402 break;
403 }
404 return ret;
405 }
406
407 static int nicvf_set_rss_hash_opts(struct nicvf *nic,
408 struct ethtool_rxnfc *info)
409 {
410 struct nicvf_rss_info *rss = &nic->rss_info;
411 u64 rss_cfg = nicvf_reg_read(nic, NIC_VNIC_RSS_CFG);
412
413 if (!rss->enable)
414 netdev_err(nic->netdev,
415 "RSS is disabled, hash cannot be set\n");
416
417 netdev_info(nic->netdev, "Set RSS flow type = %d, data = %lld\n",
418 info->flow_type, info->data);
419
420 if (!(info->data & RXH_IP_SRC) || !(info->data & RXH_IP_DST))
421 return -EINVAL;
422
423 switch (info->flow_type) {
424 case TCP_V4_FLOW:
425 case TCP_V6_FLOW:
426 switch (info->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
427 case 0:
428 rss_cfg &= ~(1ULL << RSS_HASH_TCP);
429 break;
430 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
431 rss_cfg |= (1ULL << RSS_HASH_TCP);
432 break;
433 default:
434 return -EINVAL;
435 }
436 break;
437 case UDP_V4_FLOW:
438 case UDP_V6_FLOW:
439 switch (info->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
440 case 0:
441 rss_cfg &= ~(1ULL << RSS_HASH_UDP);
442 break;
443 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
444 rss_cfg |= (1ULL << RSS_HASH_UDP);
445 break;
446 default:
447 return -EINVAL;
448 }
449 break;
450 case SCTP_V4_FLOW:
451 case SCTP_V6_FLOW:
452 switch (info->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
453 case 0:
454 rss_cfg &= ~(1ULL << RSS_HASH_L4ETC);
455 break;
456 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
457 rss_cfg |= (1ULL << RSS_HASH_L4ETC);
458 break;
459 default:
460 return -EINVAL;
461 }
462 break;
463 case IPV4_FLOW:
464 case IPV6_FLOW:
465 rss_cfg = RSS_HASH_IP;
466 break;
467 default:
468 return -EINVAL;
469 }
470
471 nicvf_reg_write(nic, NIC_VNIC_RSS_CFG, rss_cfg);
472 return 0;
473 }
474
475 static int nicvf_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info)
476 {
477 struct nicvf *nic = netdev_priv(dev);
478
479 switch (info->cmd) {
480 case ETHTOOL_SRXFH:
481 return nicvf_set_rss_hash_opts(nic, info);
482 default:
483 break;
484 }
485 return -EOPNOTSUPP;
486 }
487
488 static u32 nicvf_get_rxfh_key_size(struct net_device *netdev)
489 {
490 return RSS_HASH_KEY_SIZE * sizeof(u64);
491 }
492
493 static u32 nicvf_get_rxfh_indir_size(struct net_device *dev)
494 {
495 struct nicvf *nic = netdev_priv(dev);
496
497 return nic->rss_info.rss_size;
498 }
499
500 static int nicvf_get_rxfh(struct net_device *dev, u32 *indir, u8 *hkey,
501 u8 *hfunc)
502 {
503 struct nicvf *nic = netdev_priv(dev);
504 struct nicvf_rss_info *rss = &nic->rss_info;
505 int idx;
506
507 if (indir) {
508 for (idx = 0; idx < rss->rss_size; idx++)
509 indir[idx] = rss->ind_tbl[idx];
510 }
511
512 if (hkey)
513 memcpy(hkey, rss->key, RSS_HASH_KEY_SIZE * sizeof(u64));
514
515 if (hfunc)
516 *hfunc = ETH_RSS_HASH_TOP;
517
518 return 0;
519 }
520
521 static int nicvf_set_rxfh(struct net_device *dev, const u32 *indir,
522 const u8 *hkey, u8 hfunc)
523 {
524 struct nicvf *nic = netdev_priv(dev);
525 struct nicvf_rss_info *rss = &nic->rss_info;
526 int idx;
527
528 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
529 return -EOPNOTSUPP;
530
531 if (!rss->enable) {
532 netdev_err(nic->netdev,
533 "RSS is disabled, cannot change settings\n");
534 return -EIO;
535 }
536
537 if (indir) {
538 for (idx = 0; idx < rss->rss_size; idx++)
539 rss->ind_tbl[idx] = indir[idx];
540 }
541
542 if (hkey) {
543 memcpy(rss->key, hkey, RSS_HASH_KEY_SIZE * sizeof(u64));
544 nicvf_set_rss_key(nic);
545 }
546
547 nicvf_config_rss(nic);
548 return 0;
549 }
550
551 /* Get no of queues device supports and current queue count */
552 static void nicvf_get_channels(struct net_device *dev,
553 struct ethtool_channels *channel)
554 {
555 struct nicvf *nic = netdev_priv(dev);
556
557 memset(channel, 0, sizeof(*channel));
558
559 channel->max_rx = MAX_RCV_QUEUES_PER_QS;
560 channel->max_tx = MAX_SND_QUEUES_PER_QS;
561
562 channel->rx_count = nic->qs->rq_cnt;
563 channel->tx_count = nic->qs->sq_cnt;
564 }
565
566 /* Set no of Tx, Rx queues to be used */
567 static int nicvf_set_channels(struct net_device *dev,
568 struct ethtool_channels *channel)
569 {
570 struct nicvf *nic = netdev_priv(dev);
571 int err = 0;
572 bool if_up = netif_running(dev);
573
574 if (!channel->rx_count || !channel->tx_count)
575 return -EINVAL;
576 if (channel->rx_count > MAX_RCV_QUEUES_PER_QS)
577 return -EINVAL;
578 if (channel->tx_count > MAX_SND_QUEUES_PER_QS)
579 return -EINVAL;
580
581 if (if_up)
582 nicvf_stop(dev);
583
584 nic->qs->rq_cnt = channel->rx_count;
585 nic->qs->sq_cnt = channel->tx_count;
586 nic->qs->cq_cnt = max(nic->qs->rq_cnt, nic->qs->sq_cnt);
587
588 err = nicvf_set_real_num_queues(dev, nic->qs->sq_cnt, nic->qs->rq_cnt);
589 if (err)
590 return err;
591
592 if (if_up)
593 nicvf_open(dev);
594
595 netdev_info(dev, "Setting num Tx rings to %d, Rx rings to %d success\n",
596 nic->qs->sq_cnt, nic->qs->rq_cnt);
597
598 return err;
599 }
600
601 static const struct ethtool_ops nicvf_ethtool_ops = {
602 .get_settings = nicvf_get_settings,
603 .get_link = ethtool_op_get_link,
604 .get_drvinfo = nicvf_get_drvinfo,
605 .get_msglevel = nicvf_get_msglevel,
606 .set_msglevel = nicvf_set_msglevel,
607 .get_strings = nicvf_get_strings,
608 .get_sset_count = nicvf_get_sset_count,
609 .get_ethtool_stats = nicvf_get_ethtool_stats,
610 .get_regs_len = nicvf_get_regs_len,
611 .get_regs = nicvf_get_regs,
612 .get_coalesce = nicvf_get_coalesce,
613 .get_ringparam = nicvf_get_ringparam,
614 .get_rxnfc = nicvf_get_rxnfc,
615 .set_rxnfc = nicvf_set_rxnfc,
616 .get_rxfh_key_size = nicvf_get_rxfh_key_size,
617 .get_rxfh_indir_size = nicvf_get_rxfh_indir_size,
618 .get_rxfh = nicvf_get_rxfh,
619 .set_rxfh = nicvf_set_rxfh,
620 .get_channels = nicvf_get_channels,
621 .set_channels = nicvf_set_channels,
622 .get_ts_info = ethtool_op_get_ts_info,
623 };
624
625 void nicvf_set_ethtool_ops(struct net_device *netdev)
626 {
627 netdev->ethtool_ops = &nicvf_ethtool_ops;
628 }
This page took 0.04317 seconds and 4 git commands to generate.