blob: c51e078e8f0de3716791231a5a7f626091a72001 [file] [log] [blame]
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001/*
2 * Linux network driver for Brocade Converged Network Adapter.
3 *
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
7 *
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.
12 */
13/*
14 * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
15 * All rights reserved
16 * www.brocade.com
17 */
18
19#include "cna.h"
20
21#include <linux/netdevice.h>
22#include <linux/skbuff.h>
23#include <linux/ethtool.h>
24#include <linux/rtnetlink.h>
25
26#include "bna.h"
27
28#include "bnad.h"
29
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
35
36#define BNAD_ETHTOOL_STATS_NUM \
Eric Dumazet250e0612010-09-02 12:45:02 -070037 (sizeof(struct rtnl_link_stats64) / sizeof(u64) + \
Rasesh Mody8b230ed2010-08-23 20:24:12 -070038 sizeof(struct bnad_drv_stats) / sizeof(u64) + \
39 offsetof(struct bfi_ll_stats, rxf_stats[0]) / sizeof(u64))
40
41static 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",
52
53 "rx_length_errors",
54 "rx_over_errors",
55 "rx_crc_errors",
56 "rx_frame_errors",
57 "rx_fifo_errors",
58 "rx_missed_errors",
59
60 "tx_aborted_errors",
61 "tx_carrier_errors",
62 "tx_fifo_errors",
63 "tx_heartbeat_errors",
64 "tx_window_errors",
65
66 "rx_compressed",
67 "tx_compressed",
68
69 "netif_queue_stop",
70 "netif_queue_wakeup",
Rasesh Modyf7c0fa42010-12-23 21:45:05 +000071 "netif_queue_stopped",
Rasesh Mody8b230ed2010-08-23 20:24:12 -070072 "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",
83
84 "link_toggle",
85 "cee_up",
86
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",
93
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",
118
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",
139
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",
164
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",
189
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",
203
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",
213
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",
226};
227
228static int
229bnad_get_settings(struct net_device *netdev, struct ethtool_cmd *cmd)
230{
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;
238
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;
245 }
246 cmd->transceiver = XCVR_EXTERNAL;
247 cmd->maxtxpkt = 0;
248 cmd->maxrxpkt = 0;
249
250 return 0;
251}
252
253static int
254bnad_set_settings(struct net_device *netdev, struct ethtool_cmd *cmd)
255{
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;
261 }
262
263 return -EOPNOTSUPP;
264}
265
266static void
267bnad_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
268{
269 struct bnad *bnad = netdev_priv(netdev);
270 struct bfa_ioc_attr *ioc_attr;
271 unsigned long flags;
272
273 strcpy(drvinfo->driver, BNAD_NAME);
274 strcpy(drvinfo->version, BNAD_VERSION);
275
276 ioc_attr = kzalloc(sizeof(*ioc_attr), GFP_KERNEL);
277 if (ioc_attr) {
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700278 spin_lock_irqsave(&bnad->bna_lock, flags);
Rasesh Mody8a891422010-08-25 23:00:27 -0700279 bfa_nw_ioc_get_attr(&bnad->bna.device.ioc, ioc_attr);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700280 spin_unlock_irqrestore(&bnad->bna_lock, flags);
281
282 strncpy(drvinfo->fw_version, ioc_attr->adapter_attr.fw_ver,
283 sizeof(drvinfo->fw_version) - 1);
284 kfree(ioc_attr);
285 }
286
287 strncpy(drvinfo->bus_info, pci_name(bnad->pcidev), ETHTOOL_BUSINFO_LEN);
288}
289
290static int
291get_regs(struct bnad *bnad, u32 * regs)
292{
293 int num = 0, i;
294 u32 reg_addr;
295 unsigned long flags;
296
297#define BNAD_GET_REG(addr) \
298do { \
299 if (regs) \
300 regs[num++] = readl(bnad->bar0 + (addr)); \
301 else \
302 num++; \
303} while (0)
304
305 spin_lock_irqsave(&bnad->bna_lock, flags);
306
307 /* DMA Block Internal Registers */
308 BNAD_GET_REG(DMA_CTRL_REG0);
309 BNAD_GET_REG(DMA_CTRL_REG1);
310 BNAD_GET_REG(DMA_ERR_INT_STATUS);
311 BNAD_GET_REG(DMA_ERR_INT_ENABLE);
312 BNAD_GET_REG(DMA_ERR_INT_STATUS_SET);
313
314 /* APP Block Register Address Offset from BAR0 */
315 BNAD_GET_REG(HOSTFN0_INT_STATUS);
316 BNAD_GET_REG(HOSTFN0_INT_MASK);
317 BNAD_GET_REG(HOST_PAGE_NUM_FN0);
318 BNAD_GET_REG(HOST_MSIX_ERR_INDEX_FN0);
319 BNAD_GET_REG(FN0_PCIE_ERR_REG);
320 BNAD_GET_REG(FN0_ERR_TYPE_STATUS_REG);
321 BNAD_GET_REG(FN0_ERR_TYPE_MSK_STATUS_REG);
322
323 BNAD_GET_REG(HOSTFN1_INT_STATUS);
324 BNAD_GET_REG(HOSTFN1_INT_MASK);
325 BNAD_GET_REG(HOST_PAGE_NUM_FN1);
326 BNAD_GET_REG(HOST_MSIX_ERR_INDEX_FN1);
327 BNAD_GET_REG(FN1_PCIE_ERR_REG);
328 BNAD_GET_REG(FN1_ERR_TYPE_STATUS_REG);
329 BNAD_GET_REG(FN1_ERR_TYPE_MSK_STATUS_REG);
330
331 BNAD_GET_REG(PCIE_MISC_REG);
332
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700333 BNAD_GET_REG(HOST_SEM0_INFO_REG);
334 BNAD_GET_REG(HOST_SEM1_INFO_REG);
335 BNAD_GET_REG(HOST_SEM2_INFO_REG);
336 BNAD_GET_REG(HOST_SEM3_INFO_REG);
337
338 BNAD_GET_REG(TEMPSENSE_CNTL_REG);
339 BNAD_GET_REG(TEMPSENSE_STAT_REG);
340
341 BNAD_GET_REG(APP_LOCAL_ERR_STAT);
342 BNAD_GET_REG(APP_LOCAL_ERR_MSK);
343
344 BNAD_GET_REG(PCIE_LNK_ERR_STAT);
345 BNAD_GET_REG(PCIE_LNK_ERR_MSK);
346
347 BNAD_GET_REG(FCOE_FIP_ETH_TYPE);
348 BNAD_GET_REG(RESV_ETH_TYPE);
349
350 BNAD_GET_REG(HOSTFN2_INT_STATUS);
351 BNAD_GET_REG(HOSTFN2_INT_MASK);
352 BNAD_GET_REG(HOST_PAGE_NUM_FN2);
353 BNAD_GET_REG(HOST_MSIX_ERR_INDEX_FN2);
354 BNAD_GET_REG(FN2_PCIE_ERR_REG);
355 BNAD_GET_REG(FN2_ERR_TYPE_STATUS_REG);
356 BNAD_GET_REG(FN2_ERR_TYPE_MSK_STATUS_REG);
357
358 BNAD_GET_REG(HOSTFN3_INT_STATUS);
359 BNAD_GET_REG(HOSTFN3_INT_MASK);
360 BNAD_GET_REG(HOST_PAGE_NUM_FN3);
361 BNAD_GET_REG(HOST_MSIX_ERR_INDEX_FN3);
362 BNAD_GET_REG(FN3_PCIE_ERR_REG);
363 BNAD_GET_REG(FN3_ERR_TYPE_STATUS_REG);
364 BNAD_GET_REG(FN3_ERR_TYPE_MSK_STATUS_REG);
365
366 /* Host Command Status Registers */
367 reg_addr = HOST_CMDSTS0_CLR_REG;
368 for (i = 0; i < 16; i++) {
369 BNAD_GET_REG(reg_addr);
370 BNAD_GET_REG(reg_addr + 4);
371 BNAD_GET_REG(reg_addr + 8);
372 reg_addr += 0x10;
373 }
374
375 /* Function ID register */
376 BNAD_GET_REG(FNC_ID_REG);
377
378 /* Function personality register */
379 BNAD_GET_REG(FNC_PERS_REG);
380
381 /* Operation mode register */
382 BNAD_GET_REG(OP_MODE);
383
384 /* LPU0 Registers */
385 BNAD_GET_REG(LPU0_MBOX_CTL_REG);
386 BNAD_GET_REG(LPU0_MBOX_CMD_REG);
387 BNAD_GET_REG(LPU0_MBOX_LINK_0REG);
388 BNAD_GET_REG(LPU1_MBOX_LINK_0REG);
389 BNAD_GET_REG(LPU0_MBOX_STATUS_0REG);
390 BNAD_GET_REG(LPU1_MBOX_STATUS_0REG);
391 BNAD_GET_REG(LPU0_ERR_STATUS_REG);
392 BNAD_GET_REG(LPU0_ERR_SET_REG);
393
394 /* LPU1 Registers */
395 BNAD_GET_REG(LPU1_MBOX_CTL_REG);
396 BNAD_GET_REG(LPU1_MBOX_CMD_REG);
397 BNAD_GET_REG(LPU0_MBOX_LINK_1REG);
398 BNAD_GET_REG(LPU1_MBOX_LINK_1REG);
399 BNAD_GET_REG(LPU0_MBOX_STATUS_1REG);
400 BNAD_GET_REG(LPU1_MBOX_STATUS_1REG);
401 BNAD_GET_REG(LPU1_ERR_STATUS_REG);
402 BNAD_GET_REG(LPU1_ERR_SET_REG);
403
404 /* PSS Registers */
405 BNAD_GET_REG(PSS_CTL_REG);
406 BNAD_GET_REG(PSS_ERR_STATUS_REG);
407 BNAD_GET_REG(ERR_STATUS_SET);
408 BNAD_GET_REG(PSS_RAM_ERR_STATUS_REG);
409
410 /* Catapult CPQ Registers */
411 BNAD_GET_REG(HOSTFN0_LPU0_MBOX0_CMD_STAT);
412 BNAD_GET_REG(HOSTFN0_LPU1_MBOX0_CMD_STAT);
413 BNAD_GET_REG(LPU0_HOSTFN0_MBOX0_CMD_STAT);
414 BNAD_GET_REG(LPU1_HOSTFN0_MBOX0_CMD_STAT);
415
416 BNAD_GET_REG(HOSTFN0_LPU0_MBOX1_CMD_STAT);
417 BNAD_GET_REG(HOSTFN0_LPU1_MBOX1_CMD_STAT);
418 BNAD_GET_REG(LPU0_HOSTFN0_MBOX1_CMD_STAT);
419 BNAD_GET_REG(LPU1_HOSTFN0_MBOX1_CMD_STAT);
420
421 BNAD_GET_REG(HOSTFN1_LPU0_MBOX0_CMD_STAT);
422 BNAD_GET_REG(HOSTFN1_LPU1_MBOX0_CMD_STAT);
423 BNAD_GET_REG(LPU0_HOSTFN1_MBOX0_CMD_STAT);
424 BNAD_GET_REG(LPU1_HOSTFN1_MBOX0_CMD_STAT);
425
426 BNAD_GET_REG(HOSTFN1_LPU0_MBOX1_CMD_STAT);
427 BNAD_GET_REG(HOSTFN1_LPU1_MBOX1_CMD_STAT);
428 BNAD_GET_REG(LPU0_HOSTFN1_MBOX1_CMD_STAT);
429 BNAD_GET_REG(LPU1_HOSTFN1_MBOX1_CMD_STAT);
430
431 BNAD_GET_REG(HOSTFN2_LPU0_MBOX0_CMD_STAT);
432 BNAD_GET_REG(HOSTFN2_LPU1_MBOX0_CMD_STAT);
433 BNAD_GET_REG(LPU0_HOSTFN2_MBOX0_CMD_STAT);
434 BNAD_GET_REG(LPU1_HOSTFN2_MBOX0_CMD_STAT);
435
436 BNAD_GET_REG(HOSTFN2_LPU0_MBOX1_CMD_STAT);
437 BNAD_GET_REG(HOSTFN2_LPU1_MBOX1_CMD_STAT);
438 BNAD_GET_REG(LPU0_HOSTFN2_MBOX1_CMD_STAT);
439 BNAD_GET_REG(LPU1_HOSTFN2_MBOX1_CMD_STAT);
440
441 BNAD_GET_REG(HOSTFN3_LPU0_MBOX0_CMD_STAT);
442 BNAD_GET_REG(HOSTFN3_LPU1_MBOX0_CMD_STAT);
443 BNAD_GET_REG(LPU0_HOSTFN3_MBOX0_CMD_STAT);
444 BNAD_GET_REG(LPU1_HOSTFN3_MBOX0_CMD_STAT);
445
446 BNAD_GET_REG(HOSTFN3_LPU0_MBOX1_CMD_STAT);
447 BNAD_GET_REG(HOSTFN3_LPU1_MBOX1_CMD_STAT);
448 BNAD_GET_REG(LPU0_HOSTFN3_MBOX1_CMD_STAT);
449 BNAD_GET_REG(LPU1_HOSTFN3_MBOX1_CMD_STAT);
450
451 /* Host Function Force Parity Error Registers */
452 BNAD_GET_REG(HOSTFN0_LPU_FORCE_PERR);
453 BNAD_GET_REG(HOSTFN1_LPU_FORCE_PERR);
454 BNAD_GET_REG(HOSTFN2_LPU_FORCE_PERR);
455 BNAD_GET_REG(HOSTFN3_LPU_FORCE_PERR);
456
457 /* LL Port[0|1] Halt Mask Registers */
458 BNAD_GET_REG(LL_HALT_MSK_P0);
459 BNAD_GET_REG(LL_HALT_MSK_P1);
460
461 /* LL Port[0|1] Error Mask Registers */
462 BNAD_GET_REG(LL_ERR_MSK_P0);
463 BNAD_GET_REG(LL_ERR_MSK_P1);
464
465 /* EMC FLI Registers */
466 BNAD_GET_REG(FLI_CMD_REG);
467 BNAD_GET_REG(FLI_ADDR_REG);
468 BNAD_GET_REG(FLI_CTL_REG);
469 BNAD_GET_REG(FLI_WRDATA_REG);
470 BNAD_GET_REG(FLI_RDDATA_REG);
471 BNAD_GET_REG(FLI_DEV_STATUS_REG);
472 BNAD_GET_REG(FLI_SIG_WD_REG);
473
474 BNAD_GET_REG(FLI_DEV_VENDOR_REG);
475 BNAD_GET_REG(FLI_ERR_STATUS_REG);
476
477 /* RxAdm 0 Registers */
478 BNAD_GET_REG(RAD0_CTL_REG);
479 BNAD_GET_REG(RAD0_PE_PARM_REG);
480 BNAD_GET_REG(RAD0_BCN_REG);
481 BNAD_GET_REG(RAD0_DEFAULT_REG);
482 BNAD_GET_REG(RAD0_PROMISC_REG);
483 BNAD_GET_REG(RAD0_BCNQ_REG);
484 BNAD_GET_REG(RAD0_DEFAULTQ_REG);
485
486 BNAD_GET_REG(RAD0_ERR_STS);
487 BNAD_GET_REG(RAD0_SET_ERR_STS);
488 BNAD_GET_REG(RAD0_ERR_INT_EN);
489 BNAD_GET_REG(RAD0_FIRST_ERR);
490 BNAD_GET_REG(RAD0_FORCE_ERR);
491
492 BNAD_GET_REG(RAD0_MAC_MAN_1H);
493 BNAD_GET_REG(RAD0_MAC_MAN_1L);
494 BNAD_GET_REG(RAD0_MAC_MAN_2H);
495 BNAD_GET_REG(RAD0_MAC_MAN_2L);
496 BNAD_GET_REG(RAD0_MAC_MAN_3H);
497 BNAD_GET_REG(RAD0_MAC_MAN_3L);
498 BNAD_GET_REG(RAD0_MAC_MAN_4H);
499 BNAD_GET_REG(RAD0_MAC_MAN_4L);
500
501 BNAD_GET_REG(RAD0_LAST4_IP);
502
503 /* RxAdm 1 Registers */
504 BNAD_GET_REG(RAD1_CTL_REG);
505 BNAD_GET_REG(RAD1_PE_PARM_REG);
506 BNAD_GET_REG(RAD1_BCN_REG);
507 BNAD_GET_REG(RAD1_DEFAULT_REG);
508 BNAD_GET_REG(RAD1_PROMISC_REG);
509 BNAD_GET_REG(RAD1_BCNQ_REG);
510 BNAD_GET_REG(RAD1_DEFAULTQ_REG);
511
512 BNAD_GET_REG(RAD1_ERR_STS);
513 BNAD_GET_REG(RAD1_SET_ERR_STS);
514 BNAD_GET_REG(RAD1_ERR_INT_EN);
515
516 /* TxA0 Registers */
517 BNAD_GET_REG(TXA0_CTRL_REG);
518 /* TxA0 TSO Sequence # Registers (RO) */
519 for (i = 0; i < 8; i++) {
520 BNAD_GET_REG(TXA0_TSO_TCP_SEQ_REG(i));
521 BNAD_GET_REG(TXA0_TSO_IP_INFO_REG(i));
522 }
523
524 /* TxA1 Registers */
525 BNAD_GET_REG(TXA1_CTRL_REG);
526 /* TxA1 TSO Sequence # Registers (RO) */
527 for (i = 0; i < 8; i++) {
528 BNAD_GET_REG(TXA1_TSO_TCP_SEQ_REG(i));
529 BNAD_GET_REG(TXA1_TSO_IP_INFO_REG(i));
530 }
531
532 /* RxA Registers */
533 BNAD_GET_REG(RXA0_CTL_REG);
534 BNAD_GET_REG(RXA1_CTL_REG);
535
536 /* PLB0 Registers */
537 BNAD_GET_REG(PLB0_ECM_TIMER_REG);
538 BNAD_GET_REG(PLB0_RL_CTL);
539 for (i = 0; i < 8; i++)
540 BNAD_GET_REG(PLB0_RL_MAX_BC(i));
541 BNAD_GET_REG(PLB0_RL_TU_PRIO);
542 for (i = 0; i < 8; i++)
543 BNAD_GET_REG(PLB0_RL_BYTE_CNT(i));
544 BNAD_GET_REG(PLB0_RL_MIN_REG);
545 BNAD_GET_REG(PLB0_RL_MAX_REG);
546 BNAD_GET_REG(PLB0_EMS_ADD_REG);
547
548 /* PLB1 Registers */
549 BNAD_GET_REG(PLB1_ECM_TIMER_REG);
550 BNAD_GET_REG(PLB1_RL_CTL);
551 for (i = 0; i < 8; i++)
552 BNAD_GET_REG(PLB1_RL_MAX_BC(i));
553 BNAD_GET_REG(PLB1_RL_TU_PRIO);
554 for (i = 0; i < 8; i++)
555 BNAD_GET_REG(PLB1_RL_BYTE_CNT(i));
556 BNAD_GET_REG(PLB1_RL_MIN_REG);
557 BNAD_GET_REG(PLB1_RL_MAX_REG);
558 BNAD_GET_REG(PLB1_EMS_ADD_REG);
559
560 /* HQM Control Register */
561 BNAD_GET_REG(HQM0_CTL_REG);
562 BNAD_GET_REG(HQM0_RXQ_STOP_SEM);
563 BNAD_GET_REG(HQM0_TXQ_STOP_SEM);
564 BNAD_GET_REG(HQM1_CTL_REG);
565 BNAD_GET_REG(HQM1_RXQ_STOP_SEM);
566 BNAD_GET_REG(HQM1_TXQ_STOP_SEM);
567
568 /* LUT Registers */
569 BNAD_GET_REG(LUT0_ERR_STS);
570 BNAD_GET_REG(LUT0_SET_ERR_STS);
571 BNAD_GET_REG(LUT1_ERR_STS);
572 BNAD_GET_REG(LUT1_SET_ERR_STS);
573
574 /* TRC Registers */
575 BNAD_GET_REG(TRC_CTL_REG);
576 BNAD_GET_REG(TRC_MODS_REG);
577 BNAD_GET_REG(TRC_TRGC_REG);
578 BNAD_GET_REG(TRC_CNT1_REG);
579 BNAD_GET_REG(TRC_CNT2_REG);
580 BNAD_GET_REG(TRC_NXTS_REG);
581 BNAD_GET_REG(TRC_DIRR_REG);
582 for (i = 0; i < 10; i++)
583 BNAD_GET_REG(TRC_TRGM_REG(i));
584 for (i = 0; i < 10; i++)
585 BNAD_GET_REG(TRC_NXTM_REG(i));
586 for (i = 0; i < 10; i++)
587 BNAD_GET_REG(TRC_STRM_REG(i));
588
589 spin_unlock_irqrestore(&bnad->bna_lock, flags);
590#undef BNAD_GET_REG
591 return num;
592}
593static int
594bnad_get_regs_len(struct net_device *netdev)
595{
596 int ret = get_regs(netdev_priv(netdev), NULL) * sizeof(u32);
597 return ret;
598}
599
600static void
601bnad_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *buf)
602{
603 memset(buf, 0, bnad_get_regs_len(netdev));
604 get_regs(netdev_priv(netdev), buf);
605}
606
607static void
608bnad_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wolinfo)
609{
610 wolinfo->supported = 0;
611 wolinfo->wolopts = 0;
612}
613
614static int
615bnad_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
616{
617 struct bnad *bnad = netdev_priv(netdev);
618 unsigned long flags;
619
620 /* Lock rqd. to access bnad->bna_lock */
621 spin_lock_irqsave(&bnad->bna_lock, flags);
622 coalesce->use_adaptive_rx_coalesce =
623 (bnad->cfg_flags & BNAD_CF_DIM_ENABLED) ? true : false;
624 spin_unlock_irqrestore(&bnad->bna_lock, flags);
625
626 coalesce->rx_coalesce_usecs = bnad->rx_coalescing_timeo *
627 BFI_COALESCING_TIMER_UNIT;
628 coalesce->tx_coalesce_usecs = bnad->tx_coalescing_timeo *
629 BFI_COALESCING_TIMER_UNIT;
630 coalesce->tx_max_coalesced_frames = BFI_TX_INTERPKT_COUNT;
631
632 return 0;
633}
634
635static int
636bnad_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
637{
638 struct bnad *bnad = netdev_priv(netdev);
639 unsigned long flags;
640 int dim_timer_del = 0;
641
642 if (coalesce->rx_coalesce_usecs == 0 ||
643 coalesce->rx_coalesce_usecs >
644 BFI_MAX_COALESCING_TIMEO * BFI_COALESCING_TIMER_UNIT)
645 return -EINVAL;
646
647 if (coalesce->tx_coalesce_usecs == 0 ||
648 coalesce->tx_coalesce_usecs >
649 BFI_MAX_COALESCING_TIMEO * BFI_COALESCING_TIMER_UNIT)
650 return -EINVAL;
651
652 mutex_lock(&bnad->conf_mutex);
653 /*
654 * Do not need to store rx_coalesce_usecs here
655 * Every time DIM is disabled, we can get it from the
656 * stack.
657 */
658 spin_lock_irqsave(&bnad->bna_lock, flags);
659 if (coalesce->use_adaptive_rx_coalesce) {
660 if (!(bnad->cfg_flags & BNAD_CF_DIM_ENABLED)) {
661 bnad->cfg_flags |= BNAD_CF_DIM_ENABLED;
662 bnad_dim_timer_start(bnad);
663 }
664 } else {
665 if (bnad->cfg_flags & BNAD_CF_DIM_ENABLED) {
666 bnad->cfg_flags &= ~BNAD_CF_DIM_ENABLED;
667 dim_timer_del = bnad_dim_timer_running(bnad);
668 if (dim_timer_del) {
669 clear_bit(BNAD_RF_DIM_TIMER_RUNNING,
670 &bnad->run_flags);
671 spin_unlock_irqrestore(&bnad->bna_lock, flags);
672 del_timer_sync(&bnad->dim_timer);
673 spin_lock_irqsave(&bnad->bna_lock, flags);
674 }
675 bnad_rx_coalescing_timeo_set(bnad);
676 }
677 }
678 if (bnad->tx_coalescing_timeo != coalesce->tx_coalesce_usecs /
679 BFI_COALESCING_TIMER_UNIT) {
680 bnad->tx_coalescing_timeo = coalesce->tx_coalesce_usecs /
681 BFI_COALESCING_TIMER_UNIT;
682 bnad_tx_coalescing_timeo_set(bnad);
683 }
684
685 if (bnad->rx_coalescing_timeo != coalesce->rx_coalesce_usecs /
686 BFI_COALESCING_TIMER_UNIT) {
687 bnad->rx_coalescing_timeo = coalesce->rx_coalesce_usecs /
688 BFI_COALESCING_TIMER_UNIT;
689
690 if (!(bnad->cfg_flags & BNAD_CF_DIM_ENABLED))
691 bnad_rx_coalescing_timeo_set(bnad);
692
693 }
694
695 /* Add Tx Inter-pkt DMA count? */
696
697 spin_unlock_irqrestore(&bnad->bna_lock, flags);
698
699 mutex_unlock(&bnad->conf_mutex);
700 return 0;
701}
702
703static void
704bnad_get_ringparam(struct net_device *netdev,
705 struct ethtool_ringparam *ringparam)
706{
707 struct bnad *bnad = netdev_priv(netdev);
708
709 ringparam->rx_max_pending = BNAD_MAX_Q_DEPTH / bnad_rxqs_per_cq;
710 ringparam->rx_mini_max_pending = 0;
711 ringparam->rx_jumbo_max_pending = 0;
712 ringparam->tx_max_pending = BNAD_MAX_Q_DEPTH;
713
714 ringparam->rx_pending = bnad->rxq_depth;
715 ringparam->rx_mini_max_pending = 0;
716 ringparam->rx_jumbo_max_pending = 0;
717 ringparam->tx_pending = bnad->txq_depth;
718}
719
720static int
721bnad_set_ringparam(struct net_device *netdev,
722 struct ethtool_ringparam *ringparam)
723{
724 int i, current_err, err = 0;
725 struct bnad *bnad = netdev_priv(netdev);
726
727 mutex_lock(&bnad->conf_mutex);
728 if (ringparam->rx_pending == bnad->rxq_depth &&
729 ringparam->tx_pending == bnad->txq_depth) {
730 mutex_unlock(&bnad->conf_mutex);
731 return 0;
732 }
733
734 if (ringparam->rx_pending < BNAD_MIN_Q_DEPTH ||
735 ringparam->rx_pending > BNAD_MAX_Q_DEPTH / bnad_rxqs_per_cq ||
736 !BNA_POWER_OF_2(ringparam->rx_pending)) {
737 mutex_unlock(&bnad->conf_mutex);
738 return -EINVAL;
739 }
740 if (ringparam->tx_pending < BNAD_MIN_Q_DEPTH ||
741 ringparam->tx_pending > BNAD_MAX_Q_DEPTH ||
742 !BNA_POWER_OF_2(ringparam->tx_pending)) {
743 mutex_unlock(&bnad->conf_mutex);
744 return -EINVAL;
745 }
746
747 if (ringparam->rx_pending != bnad->rxq_depth) {
748 bnad->rxq_depth = ringparam->rx_pending;
749 for (i = 0; i < bnad->num_rx; i++) {
750 if (!bnad->rx_info[i].rx)
751 continue;
752 bnad_cleanup_rx(bnad, i);
753 current_err = bnad_setup_rx(bnad, i);
754 if (current_err && !err)
755 err = current_err;
756 }
757 }
758 if (ringparam->tx_pending != bnad->txq_depth) {
759 bnad->txq_depth = ringparam->tx_pending;
760 for (i = 0; i < bnad->num_tx; i++) {
761 if (!bnad->tx_info[i].tx)
762 continue;
763 bnad_cleanup_tx(bnad, i);
764 current_err = bnad_setup_tx(bnad, i);
765 if (current_err && !err)
766 err = current_err;
767 }
768 }
769
770 mutex_unlock(&bnad->conf_mutex);
771 return err;
772}
773
774static void
775bnad_get_pauseparam(struct net_device *netdev,
776 struct ethtool_pauseparam *pauseparam)
777{
778 struct bnad *bnad = netdev_priv(netdev);
779
780 pauseparam->autoneg = 0;
781 pauseparam->rx_pause = bnad->bna.port.pause_config.rx_pause;
782 pauseparam->tx_pause = bnad->bna.port.pause_config.tx_pause;
783}
784
785static int
786bnad_set_pauseparam(struct net_device *netdev,
787 struct ethtool_pauseparam *pauseparam)
788{
789 struct bnad *bnad = netdev_priv(netdev);
790 struct bna_pause_config pause_config;
791 unsigned long flags;
792
793 if (pauseparam->autoneg == AUTONEG_ENABLE)
794 return -EINVAL;
795
796 mutex_lock(&bnad->conf_mutex);
797 if (pauseparam->rx_pause != bnad->bna.port.pause_config.rx_pause ||
798 pauseparam->tx_pause != bnad->bna.port.pause_config.tx_pause) {
799 pause_config.rx_pause = pauseparam->rx_pause;
800 pause_config.tx_pause = pauseparam->tx_pause;
801 spin_lock_irqsave(&bnad->bna_lock, flags);
802 bna_port_pause_config(&bnad->bna.port, &pause_config, NULL);
803 spin_unlock_irqrestore(&bnad->bna_lock, flags);
804 }
805 mutex_unlock(&bnad->conf_mutex);
806 return 0;
807}
808
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700809static void
810bnad_get_strings(struct net_device *netdev, u32 stringset, u8 * string)
811{
812 struct bnad *bnad = netdev_priv(netdev);
813 int i, j, q_num;
814 u64 bmap;
815
816 mutex_lock(&bnad->conf_mutex);
817
818 switch (stringset) {
819 case ETH_SS_STATS:
820 for (i = 0; i < BNAD_ETHTOOL_STATS_NUM; i++) {
821 BUG_ON(!(strlen(bnad_net_stats_strings[i]) <
822 ETH_GSTRING_LEN));
823 memcpy(string, bnad_net_stats_strings[i],
824 ETH_GSTRING_LEN);
825 string += ETH_GSTRING_LEN;
826 }
827 bmap = (u64)bnad->bna.tx_mod.txf_bmap[0] |
828 ((u64)bnad->bna.tx_mod.txf_bmap[1] << 32);
829 for (i = 0; bmap && (i < BFI_LL_TXF_ID_MAX); i++) {
830 if (bmap & 1) {
831 sprintf(string, "txf%d_ucast_octets", i);
832 string += ETH_GSTRING_LEN;
833 sprintf(string, "txf%d_ucast", i);
834 string += ETH_GSTRING_LEN;
835 sprintf(string, "txf%d_ucast_vlan", i);
836 string += ETH_GSTRING_LEN;
837 sprintf(string, "txf%d_mcast_octets", i);
838 string += ETH_GSTRING_LEN;
839 sprintf(string, "txf%d_mcast", i);
840 string += ETH_GSTRING_LEN;
841 sprintf(string, "txf%d_mcast_vlan", i);
842 string += ETH_GSTRING_LEN;
843 sprintf(string, "txf%d_bcast_octets", i);
844 string += ETH_GSTRING_LEN;
845 sprintf(string, "txf%d_bcast", i);
846 string += ETH_GSTRING_LEN;
847 sprintf(string, "txf%d_bcast_vlan", i);
848 string += ETH_GSTRING_LEN;
849 sprintf(string, "txf%d_errors", i);
850 string += ETH_GSTRING_LEN;
851 sprintf(string, "txf%d_filter_vlan", i);
852 string += ETH_GSTRING_LEN;
853 sprintf(string, "txf%d_filter_mac_sa", i);
854 string += ETH_GSTRING_LEN;
855 }
856 bmap >>= 1;
857 }
858
859 bmap = (u64)bnad->bna.rx_mod.rxf_bmap[0] |
860 ((u64)bnad->bna.rx_mod.rxf_bmap[1] << 32);
861 for (i = 0; bmap && (i < BFI_LL_RXF_ID_MAX); i++) {
862 if (bmap & 1) {
863 sprintf(string, "rxf%d_ucast_octets", i);
864 string += ETH_GSTRING_LEN;
865 sprintf(string, "rxf%d_ucast", i);
866 string += ETH_GSTRING_LEN;
867 sprintf(string, "rxf%d_ucast_vlan", i);
868 string += ETH_GSTRING_LEN;
869 sprintf(string, "rxf%d_mcast_octets", i);
870 string += ETH_GSTRING_LEN;
871 sprintf(string, "rxf%d_mcast", i);
872 string += ETH_GSTRING_LEN;
873 sprintf(string, "rxf%d_mcast_vlan", i);
874 string += ETH_GSTRING_LEN;
875 sprintf(string, "rxf%d_bcast_octets", i);
876 string += ETH_GSTRING_LEN;
877 sprintf(string, "rxf%d_bcast", i);
878 string += ETH_GSTRING_LEN;
879 sprintf(string, "rxf%d_bcast_vlan", i);
880 string += ETH_GSTRING_LEN;
881 sprintf(string, "rxf%d_frame_drops", i);
882 string += ETH_GSTRING_LEN;
883 }
884 bmap >>= 1;
885 }
886
887 q_num = 0;
888 for (i = 0; i < bnad->num_rx; i++) {
889 if (!bnad->rx_info[i].rx)
890 continue;
891 for (j = 0; j < bnad->num_rxp_per_rx; j++) {
892 sprintf(string, "cq%d_producer_index", q_num);
893 string += ETH_GSTRING_LEN;
894 sprintf(string, "cq%d_consumer_index", q_num);
895 string += ETH_GSTRING_LEN;
896 sprintf(string, "cq%d_hw_producer_index",
897 q_num);
898 string += ETH_GSTRING_LEN;
899 q_num++;
900 }
901 }
902
903 q_num = 0;
904 for (i = 0; i < bnad->num_rx; i++) {
905 if (!bnad->rx_info[i].rx)
906 continue;
907 for (j = 0; j < bnad->num_rxp_per_rx; j++) {
908 sprintf(string, "rxq%d_packets", q_num);
909 string += ETH_GSTRING_LEN;
910 sprintf(string, "rxq%d_bytes", q_num);
911 string += ETH_GSTRING_LEN;
912 sprintf(string, "rxq%d_packets_with_error",
913 q_num);
914 string += ETH_GSTRING_LEN;
915 sprintf(string, "rxq%d_allocbuf_failed", q_num);
916 string += ETH_GSTRING_LEN;
917 sprintf(string, "rxq%d_producer_index", q_num);
918 string += ETH_GSTRING_LEN;
919 sprintf(string, "rxq%d_consumer_index", q_num);
920 string += ETH_GSTRING_LEN;
921 q_num++;
922 if (bnad->rx_info[i].rx_ctrl[j].ccb &&
923 bnad->rx_info[i].rx_ctrl[j].ccb->
924 rcb[1] &&
925 bnad->rx_info[i].rx_ctrl[j].ccb->
926 rcb[1]->rxq) {
927 sprintf(string, "rxq%d_packets", q_num);
928 string += ETH_GSTRING_LEN;
929 sprintf(string, "rxq%d_bytes", q_num);
930 string += ETH_GSTRING_LEN;
931 sprintf(string,
932 "rxq%d_packets_with_error", q_num);
933 string += ETH_GSTRING_LEN;
934 sprintf(string, "rxq%d_allocbuf_failed",
935 q_num);
936 string += ETH_GSTRING_LEN;
937 sprintf(string, "rxq%d_producer_index",
938 q_num);
939 string += ETH_GSTRING_LEN;
940 sprintf(string, "rxq%d_consumer_index",
941 q_num);
942 string += ETH_GSTRING_LEN;
943 q_num++;
944 }
945 }
946 }
947
948 q_num = 0;
949 for (i = 0; i < bnad->num_tx; i++) {
950 if (!bnad->tx_info[i].tx)
951 continue;
952 for (j = 0; j < bnad->num_txq_per_tx; j++) {
953 sprintf(string, "txq%d_packets", q_num);
954 string += ETH_GSTRING_LEN;
955 sprintf(string, "txq%d_bytes", q_num);
956 string += ETH_GSTRING_LEN;
957 sprintf(string, "txq%d_producer_index", q_num);
958 string += ETH_GSTRING_LEN;
959 sprintf(string, "txq%d_consumer_index", q_num);
960 string += ETH_GSTRING_LEN;
961 sprintf(string, "txq%d_hw_consumer_index",
962 q_num);
963 string += ETH_GSTRING_LEN;
964 q_num++;
965 }
966 }
967
968 break;
969
970 default:
971 break;
972 }
973
974 mutex_unlock(&bnad->conf_mutex);
975}
976
977static int
978bnad_get_stats_count_locked(struct net_device *netdev)
979{
980 struct bnad *bnad = netdev_priv(netdev);
981 int i, j, count, rxf_active_num = 0, txf_active_num = 0;
982 u64 bmap;
983
984 bmap = (u64)bnad->bna.tx_mod.txf_bmap[0] |
985 ((u64)bnad->bna.tx_mod.txf_bmap[1] << 32);
986 for (i = 0; bmap && (i < BFI_LL_TXF_ID_MAX); i++) {
987 if (bmap & 1)
988 txf_active_num++;
989 bmap >>= 1;
990 }
991 bmap = (u64)bnad->bna.rx_mod.rxf_bmap[0] |
992 ((u64)bnad->bna.rx_mod.rxf_bmap[1] << 32);
993 for (i = 0; bmap && (i < BFI_LL_RXF_ID_MAX); i++) {
994 if (bmap & 1)
995 rxf_active_num++;
996 bmap >>= 1;
997 }
998 count = BNAD_ETHTOOL_STATS_NUM +
999 txf_active_num * BNAD_NUM_TXF_COUNTERS +
1000 rxf_active_num * BNAD_NUM_RXF_COUNTERS;
1001
1002 for (i = 0; i < bnad->num_rx; i++) {
1003 if (!bnad->rx_info[i].rx)
1004 continue;
1005 count += bnad->num_rxp_per_rx * BNAD_NUM_CQ_COUNTERS;
1006 count += bnad->num_rxp_per_rx * BNAD_NUM_RXQ_COUNTERS;
1007 for (j = 0; j < bnad->num_rxp_per_rx; j++)
1008 if (bnad->rx_info[i].rx_ctrl[j].ccb &&
1009 bnad->rx_info[i].rx_ctrl[j].ccb->rcb[1] &&
1010 bnad->rx_info[i].rx_ctrl[j].ccb->rcb[1]->rxq)
1011 count += BNAD_NUM_RXQ_COUNTERS;
1012 }
1013
1014 for (i = 0; i < bnad->num_tx; i++) {
1015 if (!bnad->tx_info[i].tx)
1016 continue;
1017 count += bnad->num_txq_per_tx * BNAD_NUM_TXQ_COUNTERS;
1018 }
1019 return count;
1020}
1021
1022static int
1023bnad_per_q_stats_fill(struct bnad *bnad, u64 *buf, int bi)
1024{
1025 int i, j;
1026 struct bna_rcb *rcb = NULL;
1027 struct bna_tcb *tcb = NULL;
1028
1029 for (i = 0; i < bnad->num_rx; i++) {
1030 if (!bnad->rx_info[i].rx)
1031 continue;
1032 for (j = 0; j < bnad->num_rxp_per_rx; j++)
1033 if (bnad->rx_info[i].rx_ctrl[j].ccb &&
1034 bnad->rx_info[i].rx_ctrl[j].ccb->rcb[0] &&
1035 bnad->rx_info[i].rx_ctrl[j].ccb->rcb[0]->rxq) {
1036 buf[bi++] = bnad->rx_info[i].rx_ctrl[j].
1037 ccb->producer_index;
1038 buf[bi++] = 0; /* ccb->consumer_index */
1039 buf[bi++] = *(bnad->rx_info[i].rx_ctrl[j].
1040 ccb->hw_producer_index);
1041 }
1042 }
1043 for (i = 0; i < bnad->num_rx; i++) {
1044 if (!bnad->rx_info[i].rx)
1045 continue;
1046 for (j = 0; j < bnad->num_rxp_per_rx; j++)
1047 if (bnad->rx_info[i].rx_ctrl[j].ccb) {
1048 if (bnad->rx_info[i].rx_ctrl[j].ccb->rcb[0] &&
1049 bnad->rx_info[i].rx_ctrl[j].ccb->
1050 rcb[0]->rxq) {
1051 rcb = bnad->rx_info[i].rx_ctrl[j].
1052 ccb->rcb[0];
1053 buf[bi++] = rcb->rxq->rx_packets;
1054 buf[bi++] = rcb->rxq->rx_bytes;
1055 buf[bi++] = rcb->rxq->
1056 rx_packets_with_error;
1057 buf[bi++] = rcb->rxq->
1058 rxbuf_alloc_failed;
1059 buf[bi++] = rcb->producer_index;
1060 buf[bi++] = rcb->consumer_index;
1061 }
1062 if (bnad->rx_info[i].rx_ctrl[j].ccb->rcb[1] &&
1063 bnad->rx_info[i].rx_ctrl[j].ccb->
1064 rcb[1]->rxq) {
1065 rcb = bnad->rx_info[i].rx_ctrl[j].
1066 ccb->rcb[1];
1067 buf[bi++] = rcb->rxq->rx_packets;
1068 buf[bi++] = rcb->rxq->rx_bytes;
1069 buf[bi++] = rcb->rxq->
1070 rx_packets_with_error;
1071 buf[bi++] = rcb->rxq->
1072 rxbuf_alloc_failed;
1073 buf[bi++] = rcb->producer_index;
1074 buf[bi++] = rcb->consumer_index;
1075 }
1076 }
1077 }
1078
1079 for (i = 0; i < bnad->num_tx; i++) {
1080 if (!bnad->tx_info[i].tx)
1081 continue;
1082 for (j = 0; j < bnad->num_txq_per_tx; j++)
1083 if (bnad->tx_info[i].tcb[j] &&
1084 bnad->tx_info[i].tcb[j]->txq) {
1085 tcb = bnad->tx_info[i].tcb[j];
1086 buf[bi++] = tcb->txq->tx_packets;
1087 buf[bi++] = tcb->txq->tx_bytes;
1088 buf[bi++] = tcb->producer_index;
1089 buf[bi++] = tcb->consumer_index;
1090 buf[bi++] = *(tcb->hw_consumer_index);
1091 }
1092 }
1093
1094 return bi;
1095}
1096
1097static void
1098bnad_get_ethtool_stats(struct net_device *netdev, struct ethtool_stats *stats,
1099 u64 *buf)
1100{
1101 struct bnad *bnad = netdev_priv(netdev);
1102 int i, j, bi;
Eric Dumazet250e0612010-09-02 12:45:02 -07001103 unsigned long flags;
1104 struct rtnl_link_stats64 *net_stats64;
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001105 u64 *stats64;
1106 u64 bmap;
1107
1108 mutex_lock(&bnad->conf_mutex);
1109 if (bnad_get_stats_count_locked(netdev) != stats->n_stats) {
1110 mutex_unlock(&bnad->conf_mutex);
1111 return;
1112 }
1113
1114 /*
1115 * Used bna_lock to sync reads from bna_stats, which is written
1116 * under the same lock
1117 */
1118 spin_lock_irqsave(&bnad->bna_lock, flags);
1119 bi = 0;
1120 memset(buf, 0, stats->n_stats * sizeof(u64));
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001121
Eric Dumazet250e0612010-09-02 12:45:02 -07001122 net_stats64 = (struct rtnl_link_stats64 *)buf;
1123 bnad_netdev_qstats_fill(bnad, net_stats64);
1124 bnad_netdev_hwstats_fill(bnad, net_stats64);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001125
Eric Dumazet250e0612010-09-02 12:45:02 -07001126 bi = sizeof(*net_stats64) / sizeof(u64);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001127
Rasesh Modyf7c0fa42010-12-23 21:45:05 +00001128 /* Get netif_queue_stopped from stack */
1129 bnad->stats.drv_stats.netif_queue_stopped = netif_queue_stopped(netdev);
1130
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001131 /* Fill driver stats into ethtool buffers */
1132 stats64 = (u64 *)&bnad->stats.drv_stats;
1133 for (i = 0; i < sizeof(struct bnad_drv_stats) / sizeof(u64); i++)
1134 buf[bi++] = stats64[i];
1135
1136 /* Fill hardware stats excluding the rxf/txf into ethtool bufs */
1137 stats64 = (u64 *) bnad->stats.bna_stats->hw_stats;
1138 for (i = 0;
1139 i < offsetof(struct bfi_ll_stats, rxf_stats[0]) / sizeof(u64);
1140 i++)
1141 buf[bi++] = stats64[i];
1142
1143 /* Fill txf stats into ethtool buffers */
1144 bmap = (u64)bnad->bna.tx_mod.txf_bmap[0] |
1145 ((u64)bnad->bna.tx_mod.txf_bmap[1] << 32);
1146 for (i = 0; bmap && (i < BFI_LL_TXF_ID_MAX); i++) {
1147 if (bmap & 1) {
1148 stats64 = (u64 *)&bnad->stats.bna_stats->
1149 hw_stats->txf_stats[i];
1150 for (j = 0; j < sizeof(struct bfi_ll_stats_txf) /
1151 sizeof(u64); j++)
1152 buf[bi++] = stats64[j];
1153 }
1154 bmap >>= 1;
1155 }
1156
1157 /* Fill rxf stats into ethtool buffers */
1158 bmap = (u64)bnad->bna.rx_mod.rxf_bmap[0] |
1159 ((u64)bnad->bna.rx_mod.rxf_bmap[1] << 32);
1160 for (i = 0; bmap && (i < BFI_LL_RXF_ID_MAX); i++) {
1161 if (bmap & 1) {
1162 stats64 = (u64 *)&bnad->stats.bna_stats->
1163 hw_stats->rxf_stats[i];
1164 for (j = 0; j < sizeof(struct bfi_ll_stats_rxf) /
1165 sizeof(u64); j++)
1166 buf[bi++] = stats64[j];
1167 }
1168 bmap >>= 1;
1169 }
1170
1171 /* Fill per Q stats into ethtool buffers */
1172 bi = bnad_per_q_stats_fill(bnad, buf, bi);
1173
1174 spin_unlock_irqrestore(&bnad->bna_lock, flags);
1175
1176 mutex_unlock(&bnad->conf_mutex);
1177}
1178
1179static int
1180bnad_get_sset_count(struct net_device *netdev, int sset)
1181{
1182 switch (sset) {
1183 case ETH_SS_STATS:
1184 return bnad_get_stats_count_locked(netdev);
1185 default:
1186 return -EOPNOTSUPP;
1187 }
1188}
1189
1190static struct ethtool_ops bnad_ethtool_ops = {
1191 .get_settings = bnad_get_settings,
1192 .set_settings = bnad_set_settings,
1193 .get_drvinfo = bnad_get_drvinfo,
1194 .get_regs_len = bnad_get_regs_len,
1195 .get_regs = bnad_get_regs,
1196 .get_wol = bnad_get_wol,
1197 .get_link = ethtool_op_get_link,
1198 .get_coalesce = bnad_get_coalesce,
1199 .set_coalesce = bnad_set_coalesce,
1200 .get_ringparam = bnad_get_ringparam,
1201 .set_ringparam = bnad_set_ringparam,
1202 .get_pauseparam = bnad_get_pauseparam,
1203 .set_pauseparam = bnad_set_pauseparam,
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001204 .get_strings = bnad_get_strings,
1205 .get_ethtool_stats = bnad_get_ethtool_stats,
1206 .get_sset_count = bnad_get_sset_count
1207};
1208
1209void
1210bnad_set_ethtool_ops(struct net_device *netdev)
1211{
1212 SET_ETHTOOL_OPS(netdev, &bnad_ethtool_ops);
1213}