proc: use seq_puts()/seq_putc() where possible
[linux-2.6/next.git] / drivers / net / bna / bnad_ethtool.c
blob99be5ae91991f84554faf98d682f31c75cbf3b0e
1 /*
2 * Linux network driver for Brocade Converged Network Adapter.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License (GPL) Version 2 as
6 * published by the Free Software Foundation
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
14 * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
15 * All rights reserved
16 * www.brocade.com
19 #include "cna.h"
21 #include <linux/netdevice.h>
22 #include <linux/skbuff.h>
23 #include <linux/ethtool.h>
24 #include <linux/rtnetlink.h>
26 #include "bna.h"
28 #include "bnad.h"
30 #define BNAD_NUM_TXF_COUNTERS 12
31 #define BNAD_NUM_RXF_COUNTERS 10
32 #define BNAD_NUM_CQ_COUNTERS 3
33 #define BNAD_NUM_RXQ_COUNTERS 6
34 #define BNAD_NUM_TXQ_COUNTERS 5
36 #define BNAD_ETHTOOL_STATS_NUM \
37 (sizeof(struct rtnl_link_stats64) / sizeof(u64) + \
38 sizeof(struct bnad_drv_stats) / sizeof(u64) + \
39 offsetof(struct bfi_ll_stats, rxf_stats[0]) / sizeof(u64))
41 static char *bnad_net_stats_strings[BNAD_ETHTOOL_STATS_NUM] = {
42 "rx_packets",
43 "tx_packets",
44 "rx_bytes",
45 "tx_bytes",
46 "rx_errors",
47 "tx_errors",
48 "rx_dropped",
49 "tx_dropped",
50 "multicast",
51 "collisions",
53 "rx_length_errors",
54 "rx_over_errors",
55 "rx_crc_errors",
56 "rx_frame_errors",
57 "rx_fifo_errors",
58 "rx_missed_errors",
60 "tx_aborted_errors",
61 "tx_carrier_errors",
62 "tx_fifo_errors",
63 "tx_heartbeat_errors",
64 "tx_window_errors",
66 "rx_compressed",
67 "tx_compressed",
69 "netif_queue_stop",
70 "netif_queue_wakeup",
71 "netif_queue_stopped",
72 "tso4",
73 "tso6",
74 "tso_err",
75 "tcpcsum_offload",
76 "udpcsum_offload",
77 "csum_help",
78 "csum_help_err",
79 "hw_stats_updates",
80 "netif_rx_schedule",
81 "netif_rx_complete",
82 "netif_rx_dropped",
84 "link_toggle",
85 "cee_up",
87 "rxp_info_alloc_failed",
88 "mbox_intr_disabled",
89 "mbox_intr_enabled",
90 "tx_unmap_q_alloc_failed",
91 "rx_unmap_q_alloc_failed",
92 "rxbuf_alloc_failed",
94 "mac_frame_64",
95 "mac_frame_65_127",
96 "mac_frame_128_255",
97 "mac_frame_256_511",
98 "mac_frame_512_1023",
99 "mac_frame_1024_1518",
100 "mac_frame_1518_1522",
101 "mac_rx_bytes",
102 "mac_rx_packets",
103 "mac_rx_fcs_error",
104 "mac_rx_multicast",
105 "mac_rx_broadcast",
106 "mac_rx_control_frames",
107 "mac_rx_pause",
108 "mac_rx_unknown_opcode",
109 "mac_rx_alignment_error",
110 "mac_rx_frame_length_error",
111 "mac_rx_code_error",
112 "mac_rx_carrier_sense_error",
113 "mac_rx_undersize",
114 "mac_rx_oversize",
115 "mac_rx_fragments",
116 "mac_rx_jabber",
117 "mac_rx_drop",
119 "mac_tx_bytes",
120 "mac_tx_packets",
121 "mac_tx_multicast",
122 "mac_tx_broadcast",
123 "mac_tx_pause",
124 "mac_tx_deferral",
125 "mac_tx_excessive_deferral",
126 "mac_tx_single_collision",
127 "mac_tx_muliple_collision",
128 "mac_tx_late_collision",
129 "mac_tx_excessive_collision",
130 "mac_tx_total_collision",
131 "mac_tx_pause_honored",
132 "mac_tx_drop",
133 "mac_tx_jabber",
134 "mac_tx_fcs_error",
135 "mac_tx_control_frame",
136 "mac_tx_oversize",
137 "mac_tx_undersize",
138 "mac_tx_fragments",
140 "bpc_tx_pause_0",
141 "bpc_tx_pause_1",
142 "bpc_tx_pause_2",
143 "bpc_tx_pause_3",
144 "bpc_tx_pause_4",
145 "bpc_tx_pause_5",
146 "bpc_tx_pause_6",
147 "bpc_tx_pause_7",
148 "bpc_tx_zero_pause_0",
149 "bpc_tx_zero_pause_1",
150 "bpc_tx_zero_pause_2",
151 "bpc_tx_zero_pause_3",
152 "bpc_tx_zero_pause_4",
153 "bpc_tx_zero_pause_5",
154 "bpc_tx_zero_pause_6",
155 "bpc_tx_zero_pause_7",
156 "bpc_tx_first_pause_0",
157 "bpc_tx_first_pause_1",
158 "bpc_tx_first_pause_2",
159 "bpc_tx_first_pause_3",
160 "bpc_tx_first_pause_4",
161 "bpc_tx_first_pause_5",
162 "bpc_tx_first_pause_6",
163 "bpc_tx_first_pause_7",
165 "bpc_rx_pause_0",
166 "bpc_rx_pause_1",
167 "bpc_rx_pause_2",
168 "bpc_rx_pause_3",
169 "bpc_rx_pause_4",
170 "bpc_rx_pause_5",
171 "bpc_rx_pause_6",
172 "bpc_rx_pause_7",
173 "bpc_rx_zero_pause_0",
174 "bpc_rx_zero_pause_1",
175 "bpc_rx_zero_pause_2",
176 "bpc_rx_zero_pause_3",
177 "bpc_rx_zero_pause_4",
178 "bpc_rx_zero_pause_5",
179 "bpc_rx_zero_pause_6",
180 "bpc_rx_zero_pause_7",
181 "bpc_rx_first_pause_0",
182 "bpc_rx_first_pause_1",
183 "bpc_rx_first_pause_2",
184 "bpc_rx_first_pause_3",
185 "bpc_rx_first_pause_4",
186 "bpc_rx_first_pause_5",
187 "bpc_rx_first_pause_6",
188 "bpc_rx_first_pause_7",
190 "rad_rx_frames",
191 "rad_rx_octets",
192 "rad_rx_vlan_frames",
193 "rad_rx_ucast",
194 "rad_rx_ucast_octets",
195 "rad_rx_ucast_vlan",
196 "rad_rx_mcast",
197 "rad_rx_mcast_octets",
198 "rad_rx_mcast_vlan",
199 "rad_rx_bcast",
200 "rad_rx_bcast_octets",
201 "rad_rx_bcast_vlan",
202 "rad_rx_drops",
204 "fc_rx_ucast_octets",
205 "fc_rx_ucast",
206 "fc_rx_ucast_vlan",
207 "fc_rx_mcast_octets",
208 "fc_rx_mcast",
209 "fc_rx_mcast_vlan",
210 "fc_rx_bcast_octets",
211 "fc_rx_bcast",
212 "fc_rx_bcast_vlan",
214 "fc_tx_ucast_octets",
215 "fc_tx_ucast",
216 "fc_tx_ucast_vlan",
217 "fc_tx_mcast_octets",
218 "fc_tx_mcast",
219 "fc_tx_mcast_vlan",
220 "fc_tx_bcast_octets",
221 "fc_tx_bcast",
222 "fc_tx_bcast_vlan",
223 "fc_tx_parity_errors",
224 "fc_tx_timeout",
225 "fc_tx_fid_parity_errors",
228 static int
229 bnad_get_settings(struct net_device *netdev, struct ethtool_cmd *cmd)
231 cmd->supported = SUPPORTED_10000baseT_Full;
232 cmd->advertising = ADVERTISED_10000baseT_Full;
233 cmd->autoneg = AUTONEG_DISABLE;
234 cmd->supported |= SUPPORTED_FIBRE;
235 cmd->advertising |= ADVERTISED_FIBRE;
236 cmd->port = PORT_FIBRE;
237 cmd->phy_address = 0;
239 if (netif_carrier_ok(netdev)) {
240 cmd->speed = SPEED_10000;
241 cmd->duplex = DUPLEX_FULL;
242 } else {
243 cmd->speed = -1;
244 cmd->duplex = -1;
246 cmd->transceiver = XCVR_EXTERNAL;
247 cmd->maxtxpkt = 0;
248 cmd->maxrxpkt = 0;
250 return 0;
253 static int
254 bnad_set_settings(struct net_device *netdev, struct ethtool_cmd *cmd)
256 /* 10G full duplex setting supported only */
257 if (cmd->autoneg == AUTONEG_ENABLE)
258 return -EOPNOTSUPP; else {
259 if ((cmd->speed == SPEED_10000) && (cmd->duplex == DUPLEX_FULL))
260 return 0;
263 return -EOPNOTSUPP;
266 static void
267 bnad_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
269 struct bnad *bnad = netdev_priv(netdev);
270 struct bfa_ioc_attr *ioc_attr;
271 unsigned long flags;
273 strcpy(drvinfo->driver, BNAD_NAME);
274 strcpy(drvinfo->version, BNAD_VERSION);
276 ioc_attr = kzalloc(sizeof(*ioc_attr), GFP_KERNEL);
277 if (ioc_attr) {
278 memset(ioc_attr, 0, sizeof(*ioc_attr));
279 spin_lock_irqsave(&bnad->bna_lock, flags);
280 bfa_nw_ioc_get_attr(&bnad->bna.device.ioc, ioc_attr);
281 spin_unlock_irqrestore(&bnad->bna_lock, flags);
283 strncpy(drvinfo->fw_version, ioc_attr->adapter_attr.fw_ver,
284 sizeof(drvinfo->fw_version) - 1);
285 kfree(ioc_attr);
288 strncpy(drvinfo->bus_info, pci_name(bnad->pcidev), ETHTOOL_BUSINFO_LEN);
291 static int
292 get_regs(struct bnad *bnad, u32 * regs)
294 int num = 0, i;
295 u32 reg_addr;
296 unsigned long flags;
298 #define BNAD_GET_REG(addr) \
299 do { \
300 if (regs) \
301 regs[num++] = readl(bnad->bar0 + (addr)); \
302 else \
303 num++; \
304 } while (0)
306 spin_lock_irqsave(&bnad->bna_lock, flags);
308 /* DMA Block Internal Registers */
309 BNAD_GET_REG(DMA_CTRL_REG0);
310 BNAD_GET_REG(DMA_CTRL_REG1);
311 BNAD_GET_REG(DMA_ERR_INT_STATUS);
312 BNAD_GET_REG(DMA_ERR_INT_ENABLE);
313 BNAD_GET_REG(DMA_ERR_INT_STATUS_SET);
315 /* APP Block Register Address Offset from BAR0 */
316 BNAD_GET_REG(HOSTFN0_INT_STATUS);
317 BNAD_GET_REG(HOSTFN0_INT_MASK);
318 BNAD_GET_REG(HOST_PAGE_NUM_FN0);
319 BNAD_GET_REG(HOST_MSIX_ERR_INDEX_FN0);
320 BNAD_GET_REG(FN0_PCIE_ERR_REG);
321 BNAD_GET_REG(FN0_ERR_TYPE_STATUS_REG);
322 BNAD_GET_REG(FN0_ERR_TYPE_MSK_STATUS_REG);
324 BNAD_GET_REG(HOSTFN1_INT_STATUS);
325 BNAD_GET_REG(HOSTFN1_INT_MASK);
326 BNAD_GET_REG(HOST_PAGE_NUM_FN1);
327 BNAD_GET_REG(HOST_MSIX_ERR_INDEX_FN1);
328 BNAD_GET_REG(FN1_PCIE_ERR_REG);
329 BNAD_GET_REG(FN1_ERR_TYPE_STATUS_REG);
330 BNAD_GET_REG(FN1_ERR_TYPE_MSK_STATUS_REG);
332 BNAD_GET_REG(PCIE_MISC_REG);
334 BNAD_GET_REG(HOST_SEM0_INFO_REG);
335 BNAD_GET_REG(HOST_SEM1_INFO_REG);
336 BNAD_GET_REG(HOST_SEM2_INFO_REG);
337 BNAD_GET_REG(HOST_SEM3_INFO_REG);
339 BNAD_GET_REG(TEMPSENSE_CNTL_REG);
340 BNAD_GET_REG(TEMPSENSE_STAT_REG);
342 BNAD_GET_REG(APP_LOCAL_ERR_STAT);
343 BNAD_GET_REG(APP_LOCAL_ERR_MSK);
345 BNAD_GET_REG(PCIE_LNK_ERR_STAT);
346 BNAD_GET_REG(PCIE_LNK_ERR_MSK);
348 BNAD_GET_REG(FCOE_FIP_ETH_TYPE);
349 BNAD_GET_REG(RESV_ETH_TYPE);
351 BNAD_GET_REG(HOSTFN2_INT_STATUS);
352 BNAD_GET_REG(HOSTFN2_INT_MASK);
353 BNAD_GET_REG(HOST_PAGE_NUM_FN2);
354 BNAD_GET_REG(HOST_MSIX_ERR_INDEX_FN2);
355 BNAD_GET_REG(FN2_PCIE_ERR_REG);
356 BNAD_GET_REG(FN2_ERR_TYPE_STATUS_REG);
357 BNAD_GET_REG(FN2_ERR_TYPE_MSK_STATUS_REG);
359 BNAD_GET_REG(HOSTFN3_INT_STATUS);
360 BNAD_GET_REG(HOSTFN3_INT_MASK);
361 BNAD_GET_REG(HOST_PAGE_NUM_FN3);
362 BNAD_GET_REG(HOST_MSIX_ERR_INDEX_FN3);
363 BNAD_GET_REG(FN3_PCIE_ERR_REG);
364 BNAD_GET_REG(FN3_ERR_TYPE_STATUS_REG);
365 BNAD_GET_REG(FN3_ERR_TYPE_MSK_STATUS_REG);
367 /* Host Command Status Registers */
368 reg_addr = HOST_CMDSTS0_CLR_REG;
369 for (i = 0; i < 16; i++) {
370 BNAD_GET_REG(reg_addr);
371 BNAD_GET_REG(reg_addr + 4);
372 BNAD_GET_REG(reg_addr + 8);
373 reg_addr += 0x10;
376 /* Function ID register */
377 BNAD_GET_REG(FNC_ID_REG);
379 /* Function personality register */
380 BNAD_GET_REG(FNC_PERS_REG);
382 /* Operation mode register */
383 BNAD_GET_REG(OP_MODE);
385 /* LPU0 Registers */
386 BNAD_GET_REG(LPU0_MBOX_CTL_REG);
387 BNAD_GET_REG(LPU0_MBOX_CMD_REG);
388 BNAD_GET_REG(LPU0_MBOX_LINK_0REG);
389 BNAD_GET_REG(LPU1_MBOX_LINK_0REG);
390 BNAD_GET_REG(LPU0_MBOX_STATUS_0REG);
391 BNAD_GET_REG(LPU1_MBOX_STATUS_0REG);
392 BNAD_GET_REG(LPU0_ERR_STATUS_REG);
393 BNAD_GET_REG(LPU0_ERR_SET_REG);
395 /* LPU1 Registers */
396 BNAD_GET_REG(LPU1_MBOX_CTL_REG);
397 BNAD_GET_REG(LPU1_MBOX_CMD_REG);
398 BNAD_GET_REG(LPU0_MBOX_LINK_1REG);
399 BNAD_GET_REG(LPU1_MBOX_LINK_1REG);
400 BNAD_GET_REG(LPU0_MBOX_STATUS_1REG);
401 BNAD_GET_REG(LPU1_MBOX_STATUS_1REG);
402 BNAD_GET_REG(LPU1_ERR_STATUS_REG);
403 BNAD_GET_REG(LPU1_ERR_SET_REG);
405 /* PSS Registers */
406 BNAD_GET_REG(PSS_CTL_REG);
407 BNAD_GET_REG(PSS_ERR_STATUS_REG);
408 BNAD_GET_REG(ERR_STATUS_SET);
409 BNAD_GET_REG(PSS_RAM_ERR_STATUS_REG);
411 /* Catapult CPQ Registers */
412 BNAD_GET_REG(HOSTFN0_LPU0_MBOX0_CMD_STAT);
413 BNAD_GET_REG(HOSTFN0_LPU1_MBOX0_CMD_STAT);
414 BNAD_GET_REG(LPU0_HOSTFN0_MBOX0_CMD_STAT);
415 BNAD_GET_REG(LPU1_HOSTFN0_MBOX0_CMD_STAT);
417 BNAD_GET_REG(HOSTFN0_LPU0_MBOX1_CMD_STAT);
418 BNAD_GET_REG(HOSTFN0_LPU1_MBOX1_CMD_STAT);
419 BNAD_GET_REG(LPU0_HOSTFN0_MBOX1_CMD_STAT);
420 BNAD_GET_REG(LPU1_HOSTFN0_MBOX1_CMD_STAT);
422 BNAD_GET_REG(HOSTFN1_LPU0_MBOX0_CMD_STAT);
423 BNAD_GET_REG(HOSTFN1_LPU1_MBOX0_CMD_STAT);
424 BNAD_GET_REG(LPU0_HOSTFN1_MBOX0_CMD_STAT);
425 BNAD_GET_REG(LPU1_HOSTFN1_MBOX0_CMD_STAT);
427 BNAD_GET_REG(HOSTFN1_LPU0_MBOX1_CMD_STAT);
428 BNAD_GET_REG(HOSTFN1_LPU1_MBOX1_CMD_STAT);
429 BNAD_GET_REG(LPU0_HOSTFN1_MBOX1_CMD_STAT);
430 BNAD_GET_REG(LPU1_HOSTFN1_MBOX1_CMD_STAT);
432 BNAD_GET_REG(HOSTFN2_LPU0_MBOX0_CMD_STAT);
433 BNAD_GET_REG(HOSTFN2_LPU1_MBOX0_CMD_STAT);
434 BNAD_GET_REG(LPU0_HOSTFN2_MBOX0_CMD_STAT);
435 BNAD_GET_REG(LPU1_HOSTFN2_MBOX0_CMD_STAT);
437 BNAD_GET_REG(HOSTFN2_LPU0_MBOX1_CMD_STAT);
438 BNAD_GET_REG(HOSTFN2_LPU1_MBOX1_CMD_STAT);
439 BNAD_GET_REG(LPU0_HOSTFN2_MBOX1_CMD_STAT);
440 BNAD_GET_REG(LPU1_HOSTFN2_MBOX1_CMD_STAT);
442 BNAD_GET_REG(HOSTFN3_LPU0_MBOX0_CMD_STAT);
443 BNAD_GET_REG(HOSTFN3_LPU1_MBOX0_CMD_STAT);
444 BNAD_GET_REG(LPU0_HOSTFN3_MBOX0_CMD_STAT);
445 BNAD_GET_REG(LPU1_HOSTFN3_MBOX0_CMD_STAT);
447 BNAD_GET_REG(HOSTFN3_LPU0_MBOX1_CMD_STAT);
448 BNAD_GET_REG(HOSTFN3_LPU1_MBOX1_CMD_STAT);
449 BNAD_GET_REG(LPU0_HOSTFN3_MBOX1_CMD_STAT);
450 BNAD_GET_REG(LPU1_HOSTFN3_MBOX1_CMD_STAT);
452 /* Host Function Force Parity Error Registers */
453 BNAD_GET_REG(HOSTFN0_LPU_FORCE_PERR);
454 BNAD_GET_REG(HOSTFN1_LPU_FORCE_PERR);
455 BNAD_GET_REG(HOSTFN2_LPU_FORCE_PERR);
456 BNAD_GET_REG(HOSTFN3_LPU_FORCE_PERR);
458 /* LL Port[0|1] Halt Mask Registers */
459 BNAD_GET_REG(LL_HALT_MSK_P0);
460 BNAD_GET_REG(LL_HALT_MSK_P1);
462 /* LL Port[0|1] Error Mask Registers */
463 BNAD_GET_REG(LL_ERR_MSK_P0);
464 BNAD_GET_REG(LL_ERR_MSK_P1);
466 /* EMC FLI Registers */
467 BNAD_GET_REG(FLI_CMD_REG);
468 BNAD_GET_REG(FLI_ADDR_REG);
469 BNAD_GET_REG(FLI_CTL_REG);
470 BNAD_GET_REG(FLI_WRDATA_REG);
471 BNAD_GET_REG(FLI_RDDATA_REG);
472 BNAD_GET_REG(FLI_DEV_STATUS_REG);
473 BNAD_GET_REG(FLI_SIG_WD_REG);
475 BNAD_GET_REG(FLI_DEV_VENDOR_REG);
476 BNAD_GET_REG(FLI_ERR_STATUS_REG);
478 /* RxAdm 0 Registers */
479 BNAD_GET_REG(RAD0_CTL_REG);
480 BNAD_GET_REG(RAD0_PE_PARM_REG);
481 BNAD_GET_REG(RAD0_BCN_REG);
482 BNAD_GET_REG(RAD0_DEFAULT_REG);
483 BNAD_GET_REG(RAD0_PROMISC_REG);
484 BNAD_GET_REG(RAD0_BCNQ_REG);
485 BNAD_GET_REG(RAD0_DEFAULTQ_REG);
487 BNAD_GET_REG(RAD0_ERR_STS);
488 BNAD_GET_REG(RAD0_SET_ERR_STS);
489 BNAD_GET_REG(RAD0_ERR_INT_EN);
490 BNAD_GET_REG(RAD0_FIRST_ERR);
491 BNAD_GET_REG(RAD0_FORCE_ERR);
493 BNAD_GET_REG(RAD0_MAC_MAN_1H);
494 BNAD_GET_REG(RAD0_MAC_MAN_1L);
495 BNAD_GET_REG(RAD0_MAC_MAN_2H);
496 BNAD_GET_REG(RAD0_MAC_MAN_2L);
497 BNAD_GET_REG(RAD0_MAC_MAN_3H);
498 BNAD_GET_REG(RAD0_MAC_MAN_3L);
499 BNAD_GET_REG(RAD0_MAC_MAN_4H);
500 BNAD_GET_REG(RAD0_MAC_MAN_4L);
502 BNAD_GET_REG(RAD0_LAST4_IP);
504 /* RxAdm 1 Registers */
505 BNAD_GET_REG(RAD1_CTL_REG);
506 BNAD_GET_REG(RAD1_PE_PARM_REG);
507 BNAD_GET_REG(RAD1_BCN_REG);
508 BNAD_GET_REG(RAD1_DEFAULT_REG);
509 BNAD_GET_REG(RAD1_PROMISC_REG);
510 BNAD_GET_REG(RAD1_BCNQ_REG);
511 BNAD_GET_REG(RAD1_DEFAULTQ_REG);
513 BNAD_GET_REG(RAD1_ERR_STS);
514 BNAD_GET_REG(RAD1_SET_ERR_STS);
515 BNAD_GET_REG(RAD1_ERR_INT_EN);
517 /* TxA0 Registers */
518 BNAD_GET_REG(TXA0_CTRL_REG);
519 /* TxA0 TSO Sequence # Registers (RO) */
520 for (i = 0; i < 8; i++) {
521 BNAD_GET_REG(TXA0_TSO_TCP_SEQ_REG(i));
522 BNAD_GET_REG(TXA0_TSO_IP_INFO_REG(i));
525 /* TxA1 Registers */
526 BNAD_GET_REG(TXA1_CTRL_REG);
527 /* TxA1 TSO Sequence # Registers (RO) */
528 for (i = 0; i < 8; i++) {
529 BNAD_GET_REG(TXA1_TSO_TCP_SEQ_REG(i));
530 BNAD_GET_REG(TXA1_TSO_IP_INFO_REG(i));
533 /* RxA Registers */
534 BNAD_GET_REG(RXA0_CTL_REG);
535 BNAD_GET_REG(RXA1_CTL_REG);
537 /* PLB0 Registers */
538 BNAD_GET_REG(PLB0_ECM_TIMER_REG);
539 BNAD_GET_REG(PLB0_RL_CTL);
540 for (i = 0; i < 8; i++)
541 BNAD_GET_REG(PLB0_RL_MAX_BC(i));
542 BNAD_GET_REG(PLB0_RL_TU_PRIO);
543 for (i = 0; i < 8; i++)
544 BNAD_GET_REG(PLB0_RL_BYTE_CNT(i));
545 BNAD_GET_REG(PLB0_RL_MIN_REG);
546 BNAD_GET_REG(PLB0_RL_MAX_REG);
547 BNAD_GET_REG(PLB0_EMS_ADD_REG);
549 /* PLB1 Registers */
550 BNAD_GET_REG(PLB1_ECM_TIMER_REG);
551 BNAD_GET_REG(PLB1_RL_CTL);
552 for (i = 0; i < 8; i++)
553 BNAD_GET_REG(PLB1_RL_MAX_BC(i));
554 BNAD_GET_REG(PLB1_RL_TU_PRIO);
555 for (i = 0; i < 8; i++)
556 BNAD_GET_REG(PLB1_RL_BYTE_CNT(i));
557 BNAD_GET_REG(PLB1_RL_MIN_REG);
558 BNAD_GET_REG(PLB1_RL_MAX_REG);
559 BNAD_GET_REG(PLB1_EMS_ADD_REG);
561 /* HQM Control Register */
562 BNAD_GET_REG(HQM0_CTL_REG);
563 BNAD_GET_REG(HQM0_RXQ_STOP_SEM);
564 BNAD_GET_REG(HQM0_TXQ_STOP_SEM);
565 BNAD_GET_REG(HQM1_CTL_REG);
566 BNAD_GET_REG(HQM1_RXQ_STOP_SEM);
567 BNAD_GET_REG(HQM1_TXQ_STOP_SEM);
569 /* LUT Registers */
570 BNAD_GET_REG(LUT0_ERR_STS);
571 BNAD_GET_REG(LUT0_SET_ERR_STS);
572 BNAD_GET_REG(LUT1_ERR_STS);
573 BNAD_GET_REG(LUT1_SET_ERR_STS);
575 /* TRC Registers */
576 BNAD_GET_REG(TRC_CTL_REG);
577 BNAD_GET_REG(TRC_MODS_REG);
578 BNAD_GET_REG(TRC_TRGC_REG);
579 BNAD_GET_REG(TRC_CNT1_REG);
580 BNAD_GET_REG(TRC_CNT2_REG);
581 BNAD_GET_REG(TRC_NXTS_REG);
582 BNAD_GET_REG(TRC_DIRR_REG);
583 for (i = 0; i < 10; i++)
584 BNAD_GET_REG(TRC_TRGM_REG(i));
585 for (i = 0; i < 10; i++)
586 BNAD_GET_REG(TRC_NXTM_REG(i));
587 for (i = 0; i < 10; i++)
588 BNAD_GET_REG(TRC_STRM_REG(i));
590 spin_unlock_irqrestore(&bnad->bna_lock, flags);
591 #undef BNAD_GET_REG
592 return num;
594 static int
595 bnad_get_regs_len(struct net_device *netdev)
597 int ret = get_regs(netdev_priv(netdev), NULL) * sizeof(u32);
598 return ret;
601 static void
602 bnad_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *buf)
604 memset(buf, 0, bnad_get_regs_len(netdev));
605 get_regs(netdev_priv(netdev), buf);
608 static void
609 bnad_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wolinfo)
611 wolinfo->supported = 0;
612 wolinfo->wolopts = 0;
615 static int
616 bnad_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
618 struct bnad *bnad = netdev_priv(netdev);
619 unsigned long flags;
621 /* Lock rqd. to access bnad->bna_lock */
622 spin_lock_irqsave(&bnad->bna_lock, flags);
623 coalesce->use_adaptive_rx_coalesce =
624 (bnad->cfg_flags & BNAD_CF_DIM_ENABLED) ? true : false;
625 spin_unlock_irqrestore(&bnad->bna_lock, flags);
627 coalesce->rx_coalesce_usecs = bnad->rx_coalescing_timeo *
628 BFI_COALESCING_TIMER_UNIT;
629 coalesce->tx_coalesce_usecs = bnad->tx_coalescing_timeo *
630 BFI_COALESCING_TIMER_UNIT;
631 coalesce->tx_max_coalesced_frames = BFI_TX_INTERPKT_COUNT;
633 return 0;
636 static int
637 bnad_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
639 struct bnad *bnad = netdev_priv(netdev);
640 unsigned long flags;
641 int dim_timer_del = 0;
643 if (coalesce->rx_coalesce_usecs == 0 ||
644 coalesce->rx_coalesce_usecs >
645 BFI_MAX_COALESCING_TIMEO * BFI_COALESCING_TIMER_UNIT)
646 return -EINVAL;
648 if (coalesce->tx_coalesce_usecs == 0 ||
649 coalesce->tx_coalesce_usecs >
650 BFI_MAX_COALESCING_TIMEO * BFI_COALESCING_TIMER_UNIT)
651 return -EINVAL;
653 mutex_lock(&bnad->conf_mutex);
655 * Do not need to store rx_coalesce_usecs here
656 * Every time DIM is disabled, we can get it from the
657 * stack.
659 spin_lock_irqsave(&bnad->bna_lock, flags);
660 if (coalesce->use_adaptive_rx_coalesce) {
661 if (!(bnad->cfg_flags & BNAD_CF_DIM_ENABLED)) {
662 bnad->cfg_flags |= BNAD_CF_DIM_ENABLED;
663 bnad_dim_timer_start(bnad);
665 } else {
666 if (bnad->cfg_flags & BNAD_CF_DIM_ENABLED) {
667 bnad->cfg_flags &= ~BNAD_CF_DIM_ENABLED;
668 dim_timer_del = bnad_dim_timer_running(bnad);
669 if (dim_timer_del) {
670 clear_bit(BNAD_RF_DIM_TIMER_RUNNING,
671 &bnad->run_flags);
672 spin_unlock_irqrestore(&bnad->bna_lock, flags);
673 del_timer_sync(&bnad->dim_timer);
674 spin_lock_irqsave(&bnad->bna_lock, flags);
676 bnad_rx_coalescing_timeo_set(bnad);
679 if (bnad->tx_coalescing_timeo != coalesce->tx_coalesce_usecs /
680 BFI_COALESCING_TIMER_UNIT) {
681 bnad->tx_coalescing_timeo = coalesce->tx_coalesce_usecs /
682 BFI_COALESCING_TIMER_UNIT;
683 bnad_tx_coalescing_timeo_set(bnad);
686 if (bnad->rx_coalescing_timeo != coalesce->rx_coalesce_usecs /
687 BFI_COALESCING_TIMER_UNIT) {
688 bnad->rx_coalescing_timeo = coalesce->rx_coalesce_usecs /
689 BFI_COALESCING_TIMER_UNIT;
691 if (!(bnad->cfg_flags & BNAD_CF_DIM_ENABLED))
692 bnad_rx_coalescing_timeo_set(bnad);
696 /* Add Tx Inter-pkt DMA count? */
698 spin_unlock_irqrestore(&bnad->bna_lock, flags);
700 mutex_unlock(&bnad->conf_mutex);
701 return 0;
704 static void
705 bnad_get_ringparam(struct net_device *netdev,
706 struct ethtool_ringparam *ringparam)
708 struct bnad *bnad = netdev_priv(netdev);
710 ringparam->rx_max_pending = BNAD_MAX_Q_DEPTH / bnad_rxqs_per_cq;
711 ringparam->rx_mini_max_pending = 0;
712 ringparam->rx_jumbo_max_pending = 0;
713 ringparam->tx_max_pending = BNAD_MAX_Q_DEPTH;
715 ringparam->rx_pending = bnad->rxq_depth;
716 ringparam->rx_mini_max_pending = 0;
717 ringparam->rx_jumbo_max_pending = 0;
718 ringparam->tx_pending = bnad->txq_depth;
721 static int
722 bnad_set_ringparam(struct net_device *netdev,
723 struct ethtool_ringparam *ringparam)
725 int i, current_err, err = 0;
726 struct bnad *bnad = netdev_priv(netdev);
728 mutex_lock(&bnad->conf_mutex);
729 if (ringparam->rx_pending == bnad->rxq_depth &&
730 ringparam->tx_pending == bnad->txq_depth) {
731 mutex_unlock(&bnad->conf_mutex);
732 return 0;
735 if (ringparam->rx_pending < BNAD_MIN_Q_DEPTH ||
736 ringparam->rx_pending > BNAD_MAX_Q_DEPTH / bnad_rxqs_per_cq ||
737 !BNA_POWER_OF_2(ringparam->rx_pending)) {
738 mutex_unlock(&bnad->conf_mutex);
739 return -EINVAL;
741 if (ringparam->tx_pending < BNAD_MIN_Q_DEPTH ||
742 ringparam->tx_pending > BNAD_MAX_Q_DEPTH ||
743 !BNA_POWER_OF_2(ringparam->tx_pending)) {
744 mutex_unlock(&bnad->conf_mutex);
745 return -EINVAL;
748 if (ringparam->rx_pending != bnad->rxq_depth) {
749 bnad->rxq_depth = ringparam->rx_pending;
750 for (i = 0; i < bnad->num_rx; i++) {
751 if (!bnad->rx_info[i].rx)
752 continue;
753 bnad_cleanup_rx(bnad, i);
754 current_err = bnad_setup_rx(bnad, i);
755 if (current_err && !err)
756 err = current_err;
759 if (ringparam->tx_pending != bnad->txq_depth) {
760 bnad->txq_depth = ringparam->tx_pending;
761 for (i = 0; i < bnad->num_tx; i++) {
762 if (!bnad->tx_info[i].tx)
763 continue;
764 bnad_cleanup_tx(bnad, i);
765 current_err = bnad_setup_tx(bnad, i);
766 if (current_err && !err)
767 err = current_err;
771 mutex_unlock(&bnad->conf_mutex);
772 return err;
775 static void
776 bnad_get_pauseparam(struct net_device *netdev,
777 struct ethtool_pauseparam *pauseparam)
779 struct bnad *bnad = netdev_priv(netdev);
781 pauseparam->autoneg = 0;
782 pauseparam->rx_pause = bnad->bna.port.pause_config.rx_pause;
783 pauseparam->tx_pause = bnad->bna.port.pause_config.tx_pause;
786 static int
787 bnad_set_pauseparam(struct net_device *netdev,
788 struct ethtool_pauseparam *pauseparam)
790 struct bnad *bnad = netdev_priv(netdev);
791 struct bna_pause_config pause_config;
792 unsigned long flags;
794 if (pauseparam->autoneg == AUTONEG_ENABLE)
795 return -EINVAL;
797 mutex_lock(&bnad->conf_mutex);
798 if (pauseparam->rx_pause != bnad->bna.port.pause_config.rx_pause ||
799 pauseparam->tx_pause != bnad->bna.port.pause_config.tx_pause) {
800 pause_config.rx_pause = pauseparam->rx_pause;
801 pause_config.tx_pause = pauseparam->tx_pause;
802 spin_lock_irqsave(&bnad->bna_lock, flags);
803 bna_port_pause_config(&bnad->bna.port, &pause_config, NULL);
804 spin_unlock_irqrestore(&bnad->bna_lock, flags);
806 mutex_unlock(&bnad->conf_mutex);
807 return 0;
810 static u32
811 bnad_get_rx_csum(struct net_device *netdev)
813 u32 rx_csum;
814 struct bnad *bnad = netdev_priv(netdev);
816 rx_csum = bnad->rx_csum;
817 return rx_csum;
820 static int
821 bnad_set_rx_csum(struct net_device *netdev, u32 rx_csum)
823 struct bnad *bnad = netdev_priv(netdev);
825 mutex_lock(&bnad->conf_mutex);
826 bnad->rx_csum = rx_csum;
827 mutex_unlock(&bnad->conf_mutex);
828 return 0;
831 static int
832 bnad_set_tx_csum(struct net_device *netdev, u32 tx_csum)
834 struct bnad *bnad = netdev_priv(netdev);
836 mutex_lock(&bnad->conf_mutex);
837 if (tx_csum) {
838 netdev->features |= NETIF_F_IP_CSUM;
839 netdev->features |= NETIF_F_IPV6_CSUM;
840 } else {
841 netdev->features &= ~NETIF_F_IP_CSUM;
842 netdev->features &= ~NETIF_F_IPV6_CSUM;
844 mutex_unlock(&bnad->conf_mutex);
845 return 0;
848 static int
849 bnad_set_tso(struct net_device *netdev, u32 tso)
851 struct bnad *bnad = netdev_priv(netdev);
853 mutex_lock(&bnad->conf_mutex);
854 if (tso) {
855 netdev->features |= NETIF_F_TSO;
856 netdev->features |= NETIF_F_TSO6;
857 } else {
858 netdev->features &= ~NETIF_F_TSO;
859 netdev->features &= ~NETIF_F_TSO6;
861 mutex_unlock(&bnad->conf_mutex);
862 return 0;
865 static void
866 bnad_get_strings(struct net_device *netdev, u32 stringset, u8 * string)
868 struct bnad *bnad = netdev_priv(netdev);
869 int i, j, q_num;
870 u64 bmap;
872 mutex_lock(&bnad->conf_mutex);
874 switch (stringset) {
875 case ETH_SS_STATS:
876 for (i = 0; i < BNAD_ETHTOOL_STATS_NUM; i++) {
877 BUG_ON(!(strlen(bnad_net_stats_strings[i]) <
878 ETH_GSTRING_LEN));
879 memcpy(string, bnad_net_stats_strings[i],
880 ETH_GSTRING_LEN);
881 string += ETH_GSTRING_LEN;
883 bmap = (u64)bnad->bna.tx_mod.txf_bmap[0] |
884 ((u64)bnad->bna.tx_mod.txf_bmap[1] << 32);
885 for (i = 0; bmap && (i < BFI_LL_TXF_ID_MAX); i++) {
886 if (bmap & 1) {
887 sprintf(string, "txf%d_ucast_octets", i);
888 string += ETH_GSTRING_LEN;
889 sprintf(string, "txf%d_ucast", i);
890 string += ETH_GSTRING_LEN;
891 sprintf(string, "txf%d_ucast_vlan", i);
892 string += ETH_GSTRING_LEN;
893 sprintf(string, "txf%d_mcast_octets", i);
894 string += ETH_GSTRING_LEN;
895 sprintf(string, "txf%d_mcast", i);
896 string += ETH_GSTRING_LEN;
897 sprintf(string, "txf%d_mcast_vlan", i);
898 string += ETH_GSTRING_LEN;
899 sprintf(string, "txf%d_bcast_octets", i);
900 string += ETH_GSTRING_LEN;
901 sprintf(string, "txf%d_bcast", i);
902 string += ETH_GSTRING_LEN;
903 sprintf(string, "txf%d_bcast_vlan", i);
904 string += ETH_GSTRING_LEN;
905 sprintf(string, "txf%d_errors", i);
906 string += ETH_GSTRING_LEN;
907 sprintf(string, "txf%d_filter_vlan", i);
908 string += ETH_GSTRING_LEN;
909 sprintf(string, "txf%d_filter_mac_sa", i);
910 string += ETH_GSTRING_LEN;
912 bmap >>= 1;
915 bmap = (u64)bnad->bna.rx_mod.rxf_bmap[0] |
916 ((u64)bnad->bna.rx_mod.rxf_bmap[1] << 32);
917 for (i = 0; bmap && (i < BFI_LL_RXF_ID_MAX); i++) {
918 if (bmap & 1) {
919 sprintf(string, "rxf%d_ucast_octets", i);
920 string += ETH_GSTRING_LEN;
921 sprintf(string, "rxf%d_ucast", i);
922 string += ETH_GSTRING_LEN;
923 sprintf(string, "rxf%d_ucast_vlan", i);
924 string += ETH_GSTRING_LEN;
925 sprintf(string, "rxf%d_mcast_octets", i);
926 string += ETH_GSTRING_LEN;
927 sprintf(string, "rxf%d_mcast", i);
928 string += ETH_GSTRING_LEN;
929 sprintf(string, "rxf%d_mcast_vlan", i);
930 string += ETH_GSTRING_LEN;
931 sprintf(string, "rxf%d_bcast_octets", i);
932 string += ETH_GSTRING_LEN;
933 sprintf(string, "rxf%d_bcast", i);
934 string += ETH_GSTRING_LEN;
935 sprintf(string, "rxf%d_bcast_vlan", i);
936 string += ETH_GSTRING_LEN;
937 sprintf(string, "rxf%d_frame_drops", i);
938 string += ETH_GSTRING_LEN;
940 bmap >>= 1;
943 q_num = 0;
944 for (i = 0; i < bnad->num_rx; i++) {
945 if (!bnad->rx_info[i].rx)
946 continue;
947 for (j = 0; j < bnad->num_rxp_per_rx; j++) {
948 sprintf(string, "cq%d_producer_index", q_num);
949 string += ETH_GSTRING_LEN;
950 sprintf(string, "cq%d_consumer_index", q_num);
951 string += ETH_GSTRING_LEN;
952 sprintf(string, "cq%d_hw_producer_index",
953 q_num);
954 string += ETH_GSTRING_LEN;
955 q_num++;
959 q_num = 0;
960 for (i = 0; i < bnad->num_rx; i++) {
961 if (!bnad->rx_info[i].rx)
962 continue;
963 for (j = 0; j < bnad->num_rxp_per_rx; j++) {
964 sprintf(string, "rxq%d_packets", q_num);
965 string += ETH_GSTRING_LEN;
966 sprintf(string, "rxq%d_bytes", q_num);
967 string += ETH_GSTRING_LEN;
968 sprintf(string, "rxq%d_packets_with_error",
969 q_num);
970 string += ETH_GSTRING_LEN;
971 sprintf(string, "rxq%d_allocbuf_failed", q_num);
972 string += ETH_GSTRING_LEN;
973 sprintf(string, "rxq%d_producer_index", q_num);
974 string += ETH_GSTRING_LEN;
975 sprintf(string, "rxq%d_consumer_index", q_num);
976 string += ETH_GSTRING_LEN;
977 q_num++;
978 if (bnad->rx_info[i].rx_ctrl[j].ccb &&
979 bnad->rx_info[i].rx_ctrl[j].ccb->
980 rcb[1] &&
981 bnad->rx_info[i].rx_ctrl[j].ccb->
982 rcb[1]->rxq) {
983 sprintf(string, "rxq%d_packets", q_num);
984 string += ETH_GSTRING_LEN;
985 sprintf(string, "rxq%d_bytes", q_num);
986 string += ETH_GSTRING_LEN;
987 sprintf(string,
988 "rxq%d_packets_with_error", q_num);
989 string += ETH_GSTRING_LEN;
990 sprintf(string, "rxq%d_allocbuf_failed",
991 q_num);
992 string += ETH_GSTRING_LEN;
993 sprintf(string, "rxq%d_producer_index",
994 q_num);
995 string += ETH_GSTRING_LEN;
996 sprintf(string, "rxq%d_consumer_index",
997 q_num);
998 string += ETH_GSTRING_LEN;
999 q_num++;
1004 q_num = 0;
1005 for (i = 0; i < bnad->num_tx; i++) {
1006 if (!bnad->tx_info[i].tx)
1007 continue;
1008 for (j = 0; j < bnad->num_txq_per_tx; j++) {
1009 sprintf(string, "txq%d_packets", q_num);
1010 string += ETH_GSTRING_LEN;
1011 sprintf(string, "txq%d_bytes", q_num);
1012 string += ETH_GSTRING_LEN;
1013 sprintf(string, "txq%d_producer_index", q_num);
1014 string += ETH_GSTRING_LEN;
1015 sprintf(string, "txq%d_consumer_index", q_num);
1016 string += ETH_GSTRING_LEN;
1017 sprintf(string, "txq%d_hw_consumer_index",
1018 q_num);
1019 string += ETH_GSTRING_LEN;
1020 q_num++;
1024 break;
1026 default:
1027 break;
1030 mutex_unlock(&bnad->conf_mutex);
1033 static int
1034 bnad_get_stats_count_locked(struct net_device *netdev)
1036 struct bnad *bnad = netdev_priv(netdev);
1037 int i, j, count, rxf_active_num = 0, txf_active_num = 0;
1038 u64 bmap;
1040 bmap = (u64)bnad->bna.tx_mod.txf_bmap[0] |
1041 ((u64)bnad->bna.tx_mod.txf_bmap[1] << 32);
1042 for (i = 0; bmap && (i < BFI_LL_TXF_ID_MAX); i++) {
1043 if (bmap & 1)
1044 txf_active_num++;
1045 bmap >>= 1;
1047 bmap = (u64)bnad->bna.rx_mod.rxf_bmap[0] |
1048 ((u64)bnad->bna.rx_mod.rxf_bmap[1] << 32);
1049 for (i = 0; bmap && (i < BFI_LL_RXF_ID_MAX); i++) {
1050 if (bmap & 1)
1051 rxf_active_num++;
1052 bmap >>= 1;
1054 count = BNAD_ETHTOOL_STATS_NUM +
1055 txf_active_num * BNAD_NUM_TXF_COUNTERS +
1056 rxf_active_num * BNAD_NUM_RXF_COUNTERS;
1058 for (i = 0; i < bnad->num_rx; i++) {
1059 if (!bnad->rx_info[i].rx)
1060 continue;
1061 count += bnad->num_rxp_per_rx * BNAD_NUM_CQ_COUNTERS;
1062 count += bnad->num_rxp_per_rx * BNAD_NUM_RXQ_COUNTERS;
1063 for (j = 0; j < bnad->num_rxp_per_rx; j++)
1064 if (bnad->rx_info[i].rx_ctrl[j].ccb &&
1065 bnad->rx_info[i].rx_ctrl[j].ccb->rcb[1] &&
1066 bnad->rx_info[i].rx_ctrl[j].ccb->rcb[1]->rxq)
1067 count += BNAD_NUM_RXQ_COUNTERS;
1070 for (i = 0; i < bnad->num_tx; i++) {
1071 if (!bnad->tx_info[i].tx)
1072 continue;
1073 count += bnad->num_txq_per_tx * BNAD_NUM_TXQ_COUNTERS;
1075 return count;
1078 static int
1079 bnad_per_q_stats_fill(struct bnad *bnad, u64 *buf, int bi)
1081 int i, j;
1082 struct bna_rcb *rcb = NULL;
1083 struct bna_tcb *tcb = NULL;
1085 for (i = 0; i < bnad->num_rx; i++) {
1086 if (!bnad->rx_info[i].rx)
1087 continue;
1088 for (j = 0; j < bnad->num_rxp_per_rx; j++)
1089 if (bnad->rx_info[i].rx_ctrl[j].ccb &&
1090 bnad->rx_info[i].rx_ctrl[j].ccb->rcb[0] &&
1091 bnad->rx_info[i].rx_ctrl[j].ccb->rcb[0]->rxq) {
1092 buf[bi++] = bnad->rx_info[i].rx_ctrl[j].
1093 ccb->producer_index;
1094 buf[bi++] = 0; /* ccb->consumer_index */
1095 buf[bi++] = *(bnad->rx_info[i].rx_ctrl[j].
1096 ccb->hw_producer_index);
1099 for (i = 0; i < bnad->num_rx; i++) {
1100 if (!bnad->rx_info[i].rx)
1101 continue;
1102 for (j = 0; j < bnad->num_rxp_per_rx; j++)
1103 if (bnad->rx_info[i].rx_ctrl[j].ccb) {
1104 if (bnad->rx_info[i].rx_ctrl[j].ccb->rcb[0] &&
1105 bnad->rx_info[i].rx_ctrl[j].ccb->
1106 rcb[0]->rxq) {
1107 rcb = bnad->rx_info[i].rx_ctrl[j].
1108 ccb->rcb[0];
1109 buf[bi++] = rcb->rxq->rx_packets;
1110 buf[bi++] = rcb->rxq->rx_bytes;
1111 buf[bi++] = rcb->rxq->
1112 rx_packets_with_error;
1113 buf[bi++] = rcb->rxq->
1114 rxbuf_alloc_failed;
1115 buf[bi++] = rcb->producer_index;
1116 buf[bi++] = rcb->consumer_index;
1118 if (bnad->rx_info[i].rx_ctrl[j].ccb->rcb[1] &&
1119 bnad->rx_info[i].rx_ctrl[j].ccb->
1120 rcb[1]->rxq) {
1121 rcb = bnad->rx_info[i].rx_ctrl[j].
1122 ccb->rcb[1];
1123 buf[bi++] = rcb->rxq->rx_packets;
1124 buf[bi++] = rcb->rxq->rx_bytes;
1125 buf[bi++] = rcb->rxq->
1126 rx_packets_with_error;
1127 buf[bi++] = rcb->rxq->
1128 rxbuf_alloc_failed;
1129 buf[bi++] = rcb->producer_index;
1130 buf[bi++] = rcb->consumer_index;
1135 for (i = 0; i < bnad->num_tx; i++) {
1136 if (!bnad->tx_info[i].tx)
1137 continue;
1138 for (j = 0; j < bnad->num_txq_per_tx; j++)
1139 if (bnad->tx_info[i].tcb[j] &&
1140 bnad->tx_info[i].tcb[j]->txq) {
1141 tcb = bnad->tx_info[i].tcb[j];
1142 buf[bi++] = tcb->txq->tx_packets;
1143 buf[bi++] = tcb->txq->tx_bytes;
1144 buf[bi++] = tcb->producer_index;
1145 buf[bi++] = tcb->consumer_index;
1146 buf[bi++] = *(tcb->hw_consumer_index);
1150 return bi;
1153 static void
1154 bnad_get_ethtool_stats(struct net_device *netdev, struct ethtool_stats *stats,
1155 u64 *buf)
1157 struct bnad *bnad = netdev_priv(netdev);
1158 int i, j, bi;
1159 unsigned long flags;
1160 struct rtnl_link_stats64 *net_stats64;
1161 u64 *stats64;
1162 u64 bmap;
1164 mutex_lock(&bnad->conf_mutex);
1165 if (bnad_get_stats_count_locked(netdev) != stats->n_stats) {
1166 mutex_unlock(&bnad->conf_mutex);
1167 return;
1171 * Used bna_lock to sync reads from bna_stats, which is written
1172 * under the same lock
1174 spin_lock_irqsave(&bnad->bna_lock, flags);
1175 bi = 0;
1176 memset(buf, 0, stats->n_stats * sizeof(u64));
1178 net_stats64 = (struct rtnl_link_stats64 *)buf;
1179 bnad_netdev_qstats_fill(bnad, net_stats64);
1180 bnad_netdev_hwstats_fill(bnad, net_stats64);
1182 bi = sizeof(*net_stats64) / sizeof(u64);
1184 /* Get netif_queue_stopped from stack */
1185 bnad->stats.drv_stats.netif_queue_stopped = netif_queue_stopped(netdev);
1187 /* Fill driver stats into ethtool buffers */
1188 stats64 = (u64 *)&bnad->stats.drv_stats;
1189 for (i = 0; i < sizeof(struct bnad_drv_stats) / sizeof(u64); i++)
1190 buf[bi++] = stats64[i];
1192 /* Fill hardware stats excluding the rxf/txf into ethtool bufs */
1193 stats64 = (u64 *) bnad->stats.bna_stats->hw_stats;
1194 for (i = 0;
1195 i < offsetof(struct bfi_ll_stats, rxf_stats[0]) / sizeof(u64);
1196 i++)
1197 buf[bi++] = stats64[i];
1199 /* Fill txf stats into ethtool buffers */
1200 bmap = (u64)bnad->bna.tx_mod.txf_bmap[0] |
1201 ((u64)bnad->bna.tx_mod.txf_bmap[1] << 32);
1202 for (i = 0; bmap && (i < BFI_LL_TXF_ID_MAX); i++) {
1203 if (bmap & 1) {
1204 stats64 = (u64 *)&bnad->stats.bna_stats->
1205 hw_stats->txf_stats[i];
1206 for (j = 0; j < sizeof(struct bfi_ll_stats_txf) /
1207 sizeof(u64); j++)
1208 buf[bi++] = stats64[j];
1210 bmap >>= 1;
1213 /* Fill rxf stats into ethtool buffers */
1214 bmap = (u64)bnad->bna.rx_mod.rxf_bmap[0] |
1215 ((u64)bnad->bna.rx_mod.rxf_bmap[1] << 32);
1216 for (i = 0; bmap && (i < BFI_LL_RXF_ID_MAX); i++) {
1217 if (bmap & 1) {
1218 stats64 = (u64 *)&bnad->stats.bna_stats->
1219 hw_stats->rxf_stats[i];
1220 for (j = 0; j < sizeof(struct bfi_ll_stats_rxf) /
1221 sizeof(u64); j++)
1222 buf[bi++] = stats64[j];
1224 bmap >>= 1;
1227 /* Fill per Q stats into ethtool buffers */
1228 bi = bnad_per_q_stats_fill(bnad, buf, bi);
1230 spin_unlock_irqrestore(&bnad->bna_lock, flags);
1232 mutex_unlock(&bnad->conf_mutex);
1235 static int
1236 bnad_get_sset_count(struct net_device *netdev, int sset)
1238 switch (sset) {
1239 case ETH_SS_STATS:
1240 return bnad_get_stats_count_locked(netdev);
1241 default:
1242 return -EOPNOTSUPP;
1246 static struct ethtool_ops bnad_ethtool_ops = {
1247 .get_settings = bnad_get_settings,
1248 .set_settings = bnad_set_settings,
1249 .get_drvinfo = bnad_get_drvinfo,
1250 .get_regs_len = bnad_get_regs_len,
1251 .get_regs = bnad_get_regs,
1252 .get_wol = bnad_get_wol,
1253 .get_link = ethtool_op_get_link,
1254 .get_coalesce = bnad_get_coalesce,
1255 .set_coalesce = bnad_set_coalesce,
1256 .get_ringparam = bnad_get_ringparam,
1257 .set_ringparam = bnad_set_ringparam,
1258 .get_pauseparam = bnad_get_pauseparam,
1259 .set_pauseparam = bnad_set_pauseparam,
1260 .get_rx_csum = bnad_get_rx_csum,
1261 .set_rx_csum = bnad_set_rx_csum,
1262 .get_tx_csum = ethtool_op_get_tx_csum,
1263 .set_tx_csum = bnad_set_tx_csum,
1264 .get_sg = ethtool_op_get_sg,
1265 .set_sg = ethtool_op_set_sg,
1266 .get_tso = ethtool_op_get_tso,
1267 .set_tso = bnad_set_tso,
1268 .get_strings = bnad_get_strings,
1269 .get_ethtool_stats = bnad_get_ethtool_stats,
1270 .get_sset_count = bnad_get_sset_count
1273 void
1274 bnad_set_ethtool_ops(struct net_device *netdev)
1276 SET_ETHTOOL_OPS(netdev, &bnad_ethtool_ops);