2 * Copyright (c) 2007-2014 QLogic Corporation. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS'
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
18 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
24 * THE POSSIBILITY OF SUCH DAMAGE.
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
31 #include "bxe_stats.h"
34 #define BITS_PER_LONG 32
36 #define BITS_PER_LONG 64
41 bxe_hilo(uint32_t *hiref)
43 uint32_t lo = *(hiref + 1);
44 #if (BITS_PER_LONG == 64)
46 return (HILO_U64(hi, lo));
52 static inline uint16_t
53 bxe_get_port_stats_dma_len(struct bxe_softc *sc)
58 /* 'newest' convention - shmem2 contains the size of the port stats */
59 if (SHMEM2_HAS(sc, sizeof_port_stats)) {
60 size = SHMEM2_RD(sc, sizeof_port_stats);
65 /* prevent newer BC from causing buffer overflow */
66 if (res > sizeof(struct host_port_stats)) {
67 res = sizeof(struct host_port_stats);
72 * Older convention - all BCs support the port stats fields up until
73 * the 'not_used' field
76 res = (offsetof(struct host_port_stats, not_used) + 4);
78 /* if PFC stats are supported by the MFW, DMA them as well */
79 if (sc->devinfo.bc_ver >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) {
80 res += (offsetof(struct host_port_stats, pfc_frames_rx_lo) -
81 offsetof(struct host_port_stats, pfc_frames_tx_hi) + 4);
87 DBASSERT(sc, !(res > 2 * DMAE_LEN32_RD_MAX), ("big stats dmae length\n"));
92 * Init service functions
96 bxe_dp_stats(struct bxe_softc *sc)
106 " drv_stats_counter %d\n"
108 " stats_counters_addrs %x %x\n",
109 sc->fw_stats_req->hdr.cmd_num,
110 sc->fw_stats_req->hdr.reserved0,
111 sc->fw_stats_req->hdr.drv_stats_counter,
112 sc->fw_stats_req->hdr.reserved1,
113 sc->fw_stats_req->hdr.stats_counters_addrs.hi,
114 sc->fw_stats_req->hdr.stats_counters_addrs.lo);
116 for (i = 0; i < sc->fw_stats_req->hdr.cmd_num; i++) {
125 sc->fw_stats_req->query[i].kind,
126 sc->fw_stats_req->query[i].index,
127 sc->fw_stats_req->query[i].funcID,
128 sc->fw_stats_req->query[i].reserved,
129 sc->fw_stats_req->query[i].address.hi,
130 sc->fw_stats_req->query[i].address.lo);
135 * Post the next statistics ramrod. Protect it with the lock in
136 * order to ensure the strict order between statistics ramrods
137 * (each ramrod has a sequence number passed in a
138 * sc->fw_stats_req->hdr.drv_stats_counter and ramrods must be
142 bxe_storm_stats_post(struct bxe_softc *sc)
146 if (!sc->stats_pending) {
149 if (sc->stats_pending) {
150 BXE_STATS_UNLOCK(sc);
154 sc->fw_stats_req->hdr.drv_stats_counter =
155 htole16(sc->stats_counter++);
158 "sending statistics ramrod %d\n",
159 le16toh(sc->fw_stats_req->hdr.drv_stats_counter));
161 /* adjust the ramrod to include VF queues statistics */
162 // XXX bxe_iov_adjust_stats_req(sc);
166 /* send FW stats ramrod */
167 rc = bxe_sp_post(sc, RAMROD_CMD_ID_COMMON_STAT_QUERY, 0,
168 U64_HI(sc->fw_stats_req_mapping),
169 U64_LO(sc->fw_stats_req_mapping),
170 NONE_CONNECTION_TYPE);
172 sc->stats_pending = 1;
175 BXE_STATS_UNLOCK(sc);
180 bxe_hw_stats_post(struct bxe_softc *sc)
182 struct dmae_cmd *dmae = &sc->stats_dmae;
183 uint32_t *stats_comp = BXE_SP(sc, stats_comp);
187 *stats_comp = DMAE_COMP_VAL;
188 if (CHIP_REV_IS_SLOW(sc)) {
192 /* Update MCP's statistics if possible */
194 memcpy(BXE_SP(sc, func_stats), &sc->func_stats,
195 sizeof(sc->func_stats));
199 if (sc->executer_idx) {
200 loader_idx = PMF_DMAE_C(sc);
201 opcode = bxe_dmae_opcode(sc, DMAE_SRC_PCI, DMAE_DST_GRC,
202 TRUE, DMAE_COMP_GRC);
203 opcode = bxe_dmae_opcode_clr_src_reset(opcode);
205 memset(dmae, 0, sizeof(struct dmae_cmd));
206 dmae->opcode = opcode;
207 dmae->src_addr_lo = U64_LO(BXE_SP_MAPPING(sc, dmae[0]));
208 dmae->src_addr_hi = U64_HI(BXE_SP_MAPPING(sc, dmae[0]));
209 dmae->dst_addr_lo = ((DMAE_REG_CMD_MEM +
210 sizeof(struct dmae_cmd) *
211 (loader_idx + 1)) >> 2);
212 dmae->dst_addr_hi = 0;
213 dmae->len = sizeof(struct dmae_cmd) >> 2;
214 if (CHIP_IS_E1(sc)) {
217 dmae->comp_addr_lo = (dmae_reg_go_c[loader_idx + 1] >> 2);
218 dmae->comp_addr_hi = 0;
222 bxe_post_dmae(sc, dmae, loader_idx);
223 } else if (sc->func_stx) {
225 bxe_post_dmae(sc, dmae, INIT_DMAE_C(sc));
230 bxe_stats_comp(struct bxe_softc *sc)
232 uint32_t *stats_comp = BXE_SP(sc, stats_comp);
235 while (*stats_comp != DMAE_COMP_VAL) {
237 BLOGE(sc, "Timeout waiting for stats finished\n");
238 BXE_SET_ERROR_BIT(sc, BXE_ERR_STATS_TO);
239 taskqueue_enqueue_timeout(taskqueue_thread,
240 &sc->sp_err_timeout_task, hz/10);
253 * Statistics service functions
257 bxe_stats_pmf_update(struct bxe_softc *sc)
259 struct dmae_cmd *dmae;
261 int loader_idx = PMF_DMAE_C(sc);
262 uint32_t *stats_comp = BXE_SP(sc, stats_comp);
264 if (sc->devinfo.bc_ver <= 0x06001400) {
266 * Bootcode v6.0.21 fixed a GRC timeout that occurs when accessing
267 * BRB registers while the BRB block is in reset. The DMA transfer
268 * below triggers this issue resulting in the DMAE to stop
269 * functioning. Skip this initial stats transfer for old bootcode
270 * versions <= 6.0.20.
276 if (!sc->port.pmf || !sc->port.port_stx) {
281 sc->executer_idx = 0;
283 opcode = bxe_dmae_opcode(sc, DMAE_SRC_GRC, DMAE_DST_PCI, FALSE, 0);
285 dmae = BXE_SP(sc, dmae[sc->executer_idx++]);
286 dmae->opcode = bxe_dmae_opcode_add_comp(opcode, DMAE_COMP_GRC);
287 dmae->src_addr_lo = (sc->port.port_stx >> 2);
288 dmae->src_addr_hi = 0;
289 dmae->dst_addr_lo = U64_LO(BXE_SP_MAPPING(sc, port_stats));
290 dmae->dst_addr_hi = U64_HI(BXE_SP_MAPPING(sc, port_stats));
291 dmae->len = DMAE_LEN32_RD_MAX;
292 dmae->comp_addr_lo = (dmae_reg_go_c[loader_idx] >> 2);
293 dmae->comp_addr_hi = 0;
296 dmae = BXE_SP(sc, dmae[sc->executer_idx++]);
297 dmae->opcode = bxe_dmae_opcode_add_comp(opcode, DMAE_COMP_PCI);
298 dmae->src_addr_lo = ((sc->port.port_stx >> 2) + DMAE_LEN32_RD_MAX);
299 dmae->src_addr_hi = 0;
300 dmae->dst_addr_lo = U64_LO(BXE_SP_MAPPING(sc, port_stats) +
301 DMAE_LEN32_RD_MAX * 4);
302 dmae->dst_addr_hi = U64_HI(BXE_SP_MAPPING(sc, port_stats) +
303 DMAE_LEN32_RD_MAX * 4);
304 dmae->len = (bxe_get_port_stats_dma_len(sc) - DMAE_LEN32_RD_MAX);
306 dmae->comp_addr_lo = U64_LO(BXE_SP_MAPPING(sc, stats_comp));
307 dmae->comp_addr_hi = U64_HI(BXE_SP_MAPPING(sc, stats_comp));
308 dmae->comp_val = DMAE_COMP_VAL;
311 bxe_hw_stats_post(sc);
316 bxe_port_stats_init(struct bxe_softc *sc)
318 struct dmae_cmd *dmae;
319 int port = SC_PORT(sc);
321 int loader_idx = PMF_DMAE_C(sc);
323 uint32_t *stats_comp = BXE_SP(sc, stats_comp);
326 if (!sc->link_vars.link_up || !sc->port.pmf) {
331 sc->executer_idx = 0;
334 opcode = bxe_dmae_opcode(sc, DMAE_SRC_PCI, DMAE_DST_GRC,
335 TRUE, DMAE_COMP_GRC);
337 if (sc->port.port_stx) {
338 dmae = BXE_SP(sc, dmae[sc->executer_idx++]);
339 dmae->opcode = opcode;
340 dmae->src_addr_lo = U64_LO(BXE_SP_MAPPING(sc, port_stats));
341 dmae->src_addr_hi = U64_HI(BXE_SP_MAPPING(sc, port_stats));
342 dmae->dst_addr_lo = sc->port.port_stx >> 2;
343 dmae->dst_addr_hi = 0;
344 dmae->len = bxe_get_port_stats_dma_len(sc);
345 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
346 dmae->comp_addr_hi = 0;
351 dmae = BXE_SP(sc, dmae[sc->executer_idx++]);
352 dmae->opcode = opcode;
353 dmae->src_addr_lo = U64_LO(BXE_SP_MAPPING(sc, func_stats));
354 dmae->src_addr_hi = U64_HI(BXE_SP_MAPPING(sc, func_stats));
355 dmae->dst_addr_lo = (sc->func_stx >> 2);
356 dmae->dst_addr_hi = 0;
357 dmae->len = (sizeof(struct host_func_stats) >> 2);
358 dmae->comp_addr_lo = (dmae_reg_go_c[loader_idx] >> 2);
359 dmae->comp_addr_hi = 0;
364 opcode = bxe_dmae_opcode(sc, DMAE_SRC_GRC, DMAE_DST_PCI,
365 TRUE, DMAE_COMP_GRC);
367 /* EMAC is special */
368 if (sc->link_vars.mac_type == ELINK_MAC_TYPE_EMAC) {
369 mac_addr = (port ? GRCBASE_EMAC1 : GRCBASE_EMAC0);
371 /* EMAC_REG_EMAC_RX_STAT_AC (EMAC_REG_EMAC_RX_STAT_AC_COUNT)*/
372 dmae = BXE_SP(sc, dmae[sc->executer_idx++]);
373 dmae->opcode = opcode;
374 dmae->src_addr_lo = (mac_addr + EMAC_REG_EMAC_RX_STAT_AC) >> 2;
375 dmae->src_addr_hi = 0;
376 dmae->dst_addr_lo = U64_LO(BXE_SP_MAPPING(sc, mac_stats));
377 dmae->dst_addr_hi = U64_HI(BXE_SP_MAPPING(sc, mac_stats));
378 dmae->len = EMAC_REG_EMAC_RX_STAT_AC_COUNT;
379 dmae->comp_addr_lo = (dmae_reg_go_c[loader_idx] >> 2);
380 dmae->comp_addr_hi = 0;
383 /* EMAC_REG_EMAC_RX_STAT_AC_28 */
384 dmae = BXE_SP(sc, dmae[sc->executer_idx++]);
385 dmae->opcode = opcode;
386 dmae->src_addr_lo = ((mac_addr + EMAC_REG_EMAC_RX_STAT_AC_28) >> 2);
387 dmae->src_addr_hi = 0;
388 dmae->dst_addr_lo = U64_LO(BXE_SP_MAPPING(sc, mac_stats) +
389 offsetof(struct emac_stats,
390 rx_stat_falsecarriererrors));
391 dmae->dst_addr_hi = U64_HI(BXE_SP_MAPPING(sc, mac_stats) +
392 offsetof(struct emac_stats,
393 rx_stat_falsecarriererrors));
395 dmae->comp_addr_lo = (dmae_reg_go_c[loader_idx] >> 2);
396 dmae->comp_addr_hi = 0;
399 /* EMAC_REG_EMAC_TX_STAT_AC (EMAC_REG_EMAC_TX_STAT_AC_COUNT)*/
400 dmae = BXE_SP(sc, dmae[sc->executer_idx++]);
401 dmae->opcode = opcode;
402 dmae->src_addr_lo = ((mac_addr + EMAC_REG_EMAC_TX_STAT_AC) >> 2);
403 dmae->src_addr_hi = 0;
404 dmae->dst_addr_lo = U64_LO(BXE_SP_MAPPING(sc, mac_stats) +
405 offsetof(struct emac_stats,
406 tx_stat_ifhcoutoctets));
407 dmae->dst_addr_hi = U64_HI(BXE_SP_MAPPING(sc, mac_stats) +
408 offsetof(struct emac_stats,
409 tx_stat_ifhcoutoctets));
410 dmae->len = EMAC_REG_EMAC_TX_STAT_AC_COUNT;
411 dmae->comp_addr_lo = (dmae_reg_go_c[loader_idx] >> 2);
412 dmae->comp_addr_hi = 0;
415 uint32_t tx_src_addr_lo, rx_src_addr_lo;
416 uint16_t rx_len, tx_len;
418 /* configure the params according to MAC type */
419 switch (sc->link_vars.mac_type) {
420 case ELINK_MAC_TYPE_BMAC:
421 mac_addr = (port) ? NIG_REG_INGRESS_BMAC1_MEM :
422 NIG_REG_INGRESS_BMAC0_MEM;
424 /* BIGMAC_REGISTER_TX_STAT_GTPKT ..
425 BIGMAC_REGISTER_TX_STAT_GTBYT */
426 if (CHIP_IS_E1x(sc)) {
428 ((mac_addr + BIGMAC_REGISTER_TX_STAT_GTPKT) >> 2);
429 tx_len = ((8 + BIGMAC_REGISTER_TX_STAT_GTBYT -
430 BIGMAC_REGISTER_TX_STAT_GTPKT) >> 2);
432 ((mac_addr + BIGMAC_REGISTER_RX_STAT_GR64) >> 2);
433 rx_len = ((8 + BIGMAC_REGISTER_RX_STAT_GRIPJ -
434 BIGMAC_REGISTER_RX_STAT_GR64) >> 2);
437 ((mac_addr + BIGMAC2_REGISTER_TX_STAT_GTPOK) >> 2);
438 tx_len = ((8 + BIGMAC2_REGISTER_TX_STAT_GTBYT -
439 BIGMAC2_REGISTER_TX_STAT_GTPOK) >> 2);
441 ((mac_addr + BIGMAC2_REGISTER_RX_STAT_GR64) >> 2);
442 rx_len = ((8 + BIGMAC2_REGISTER_RX_STAT_GRIPJ -
443 BIGMAC2_REGISTER_RX_STAT_GR64) >> 2);
448 case ELINK_MAC_TYPE_UMAC: /* handled by MSTAT */
449 case ELINK_MAC_TYPE_XMAC: /* handled by MSTAT */
451 mac_addr = (port) ? GRCBASE_MSTAT1 : GRCBASE_MSTAT0;
452 tx_src_addr_lo = ((mac_addr + MSTAT_REG_TX_STAT_GTXPOK_LO) >> 2);
453 rx_src_addr_lo = ((mac_addr + MSTAT_REG_RX_STAT_GR64_LO) >> 2);
455 (sizeof(sc->sp->mac_stats.mstat_stats.stats_tx) >> 2);
457 (sizeof(sc->sp->mac_stats.mstat_stats.stats_rx) >> 2);
462 dmae = BXE_SP(sc, dmae[sc->executer_idx++]);
463 dmae->opcode = opcode;
464 dmae->src_addr_lo = tx_src_addr_lo;
465 dmae->src_addr_hi = 0;
467 dmae->dst_addr_lo = U64_LO(BXE_SP_MAPPING(sc, mac_stats));
468 dmae->dst_addr_hi = U64_HI(BXE_SP_MAPPING(sc, mac_stats));
469 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
470 dmae->comp_addr_hi = 0;
474 dmae = BXE_SP(sc, dmae[sc->executer_idx++]);
475 dmae->opcode = opcode;
476 dmae->src_addr_hi = 0;
477 dmae->src_addr_lo = rx_src_addr_lo;
479 U64_LO(BXE_SP_MAPPING(sc, mac_stats) + (tx_len << 2));
481 U64_HI(BXE_SP_MAPPING(sc, mac_stats) + (tx_len << 2));
483 dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
484 dmae->comp_addr_hi = 0;
489 if (!CHIP_IS_E3(sc)) {
490 dmae = BXE_SP(sc, dmae[sc->executer_idx++]);
491 dmae->opcode = opcode;
493 (port ? NIG_REG_STAT1_EGRESS_MAC_PKT0 :
494 NIG_REG_STAT0_EGRESS_MAC_PKT0) >> 2;
495 dmae->src_addr_hi = 0;
496 dmae->dst_addr_lo = U64_LO(BXE_SP_MAPPING(sc, nig_stats) +
497 offsetof(struct nig_stats,
498 egress_mac_pkt0_lo));
499 dmae->dst_addr_hi = U64_HI(BXE_SP_MAPPING(sc, nig_stats) +
500 offsetof(struct nig_stats,
501 egress_mac_pkt0_lo));
502 dmae->len = ((2 * sizeof(uint32_t)) >> 2);
503 dmae->comp_addr_lo = (dmae_reg_go_c[loader_idx] >> 2);
504 dmae->comp_addr_hi = 0;
507 dmae = BXE_SP(sc, dmae[sc->executer_idx++]);
508 dmae->opcode = opcode;
510 (port ? NIG_REG_STAT1_EGRESS_MAC_PKT1 :
511 NIG_REG_STAT0_EGRESS_MAC_PKT1) >> 2;
512 dmae->src_addr_hi = 0;
513 dmae->dst_addr_lo = U64_LO(BXE_SP_MAPPING(sc, nig_stats) +
514 offsetof(struct nig_stats,
515 egress_mac_pkt1_lo));
516 dmae->dst_addr_hi = U64_HI(BXE_SP_MAPPING(sc, nig_stats) +
517 offsetof(struct nig_stats,
518 egress_mac_pkt1_lo));
519 dmae->len = ((2 * sizeof(uint32_t)) >> 2);
520 dmae->comp_addr_lo = (dmae_reg_go_c[loader_idx] >> 2);
521 dmae->comp_addr_hi = 0;
525 dmae = BXE_SP(sc, dmae[sc->executer_idx++]);
526 dmae->opcode = bxe_dmae_opcode(sc, DMAE_SRC_GRC, DMAE_DST_PCI,
527 TRUE, DMAE_COMP_PCI);
529 (port ? NIG_REG_STAT1_BRB_DISCARD :
530 NIG_REG_STAT0_BRB_DISCARD) >> 2;
531 dmae->src_addr_hi = 0;
532 dmae->dst_addr_lo = U64_LO(BXE_SP_MAPPING(sc, nig_stats));
533 dmae->dst_addr_hi = U64_HI(BXE_SP_MAPPING(sc, nig_stats));
534 dmae->len = (sizeof(struct nig_stats) - 4*sizeof(uint32_t)) >> 2;
536 dmae->comp_addr_lo = U64_LO(BXE_SP_MAPPING(sc, stats_comp));
537 dmae->comp_addr_hi = U64_HI(BXE_SP_MAPPING(sc, stats_comp));
538 dmae->comp_val = DMAE_COMP_VAL;
544 bxe_func_stats_init(struct bxe_softc *sc)
546 struct dmae_cmd *dmae = &sc->stats_dmae;
547 uint32_t *stats_comp = BXE_SP(sc, stats_comp);
555 sc->executer_idx = 0;
556 memset(dmae, 0, sizeof(struct dmae_cmd));
558 dmae->opcode = bxe_dmae_opcode(sc, DMAE_SRC_PCI, DMAE_DST_GRC,
559 TRUE, DMAE_COMP_PCI);
560 dmae->src_addr_lo = U64_LO(BXE_SP_MAPPING(sc, func_stats));
561 dmae->src_addr_hi = U64_HI(BXE_SP_MAPPING(sc, func_stats));
562 dmae->dst_addr_lo = (sc->func_stx >> 2);
563 dmae->dst_addr_hi = 0;
564 dmae->len = (sizeof(struct host_func_stats) >> 2);
565 dmae->comp_addr_lo = U64_LO(BXE_SP_MAPPING(sc, stats_comp));
566 dmae->comp_addr_hi = U64_HI(BXE_SP_MAPPING(sc, stats_comp));
567 dmae->comp_val = DMAE_COMP_VAL;
573 bxe_stats_start(struct bxe_softc *sc)
576 * VFs travel through here as part of the statistics FSM, but no action
584 bxe_port_stats_init(sc);
587 else if (sc->func_stx) {
588 bxe_func_stats_init(sc);
591 bxe_hw_stats_post(sc);
592 bxe_storm_stats_post(sc);
596 bxe_stats_pmf_start(struct bxe_softc *sc)
599 bxe_stats_pmf_update(sc);
604 bxe_stats_restart(struct bxe_softc *sc)
607 * VFs travel through here as part of the statistics FSM, but no action
619 bxe_bmac_stats_update(struct bxe_softc *sc)
621 struct host_port_stats *pstats = BXE_SP(sc, port_stats);
622 struct bxe_eth_stats *estats = &sc->eth_stats;
628 if (CHIP_IS_E1x(sc)) {
629 struct bmac1_stats *new = BXE_SP(sc, mac_stats.bmac1_stats);
631 /* the macros below will use "bmac1_stats" type */
632 UPDATE_STAT64(rx_stat_grerb, rx_stat_ifhcinbadoctets);
633 UPDATE_STAT64(rx_stat_grfcs, rx_stat_dot3statsfcserrors);
634 UPDATE_STAT64(rx_stat_grund, rx_stat_etherstatsundersizepkts);
635 UPDATE_STAT64(rx_stat_grovr, rx_stat_dot3statsframestoolong);
636 UPDATE_STAT64(rx_stat_grfrg, rx_stat_etherstatsfragments);
637 UPDATE_STAT64(rx_stat_grjbr, rx_stat_etherstatsjabbers);
638 UPDATE_STAT64(rx_stat_grxcf, rx_stat_maccontrolframesreceived);
639 UPDATE_STAT64(rx_stat_grxpf, rx_stat_xoffstateentered);
640 UPDATE_STAT64(rx_stat_grxpf, rx_stat_mac_xpf);
642 UPDATE_STAT64(tx_stat_gtxpf, tx_stat_outxoffsent);
643 UPDATE_STAT64(tx_stat_gtxpf, tx_stat_flowcontroldone);
644 UPDATE_STAT64(tx_stat_gt64, tx_stat_etherstatspkts64octets);
645 UPDATE_STAT64(tx_stat_gt127,
646 tx_stat_etherstatspkts65octetsto127octets);
647 UPDATE_STAT64(tx_stat_gt255,
648 tx_stat_etherstatspkts128octetsto255octets);
649 UPDATE_STAT64(tx_stat_gt511,
650 tx_stat_etherstatspkts256octetsto511octets);
651 UPDATE_STAT64(tx_stat_gt1023,
652 tx_stat_etherstatspkts512octetsto1023octets);
653 UPDATE_STAT64(tx_stat_gt1518,
654 tx_stat_etherstatspkts1024octetsto1522octets);
655 UPDATE_STAT64(tx_stat_gt2047, tx_stat_mac_2047);
656 UPDATE_STAT64(tx_stat_gt4095, tx_stat_mac_4095);
657 UPDATE_STAT64(tx_stat_gt9216, tx_stat_mac_9216);
658 UPDATE_STAT64(tx_stat_gt16383, tx_stat_mac_16383);
659 UPDATE_STAT64(tx_stat_gterr,
660 tx_stat_dot3statsinternalmactransmiterrors);
661 UPDATE_STAT64(tx_stat_gtufl, tx_stat_mac_ufl);
663 struct bmac2_stats *new = BXE_SP(sc, mac_stats.bmac2_stats);
664 struct bxe_fw_port_stats_old *fwstats = &sc->fw_stats_old;
666 /* the macros below will use "bmac2_stats" type */
667 UPDATE_STAT64(rx_stat_grerb, rx_stat_ifhcinbadoctets);
668 UPDATE_STAT64(rx_stat_grfcs, rx_stat_dot3statsfcserrors);
669 UPDATE_STAT64(rx_stat_grund, rx_stat_etherstatsundersizepkts);
670 UPDATE_STAT64(rx_stat_grovr, rx_stat_dot3statsframestoolong);
671 UPDATE_STAT64(rx_stat_grfrg, rx_stat_etherstatsfragments);
672 UPDATE_STAT64(rx_stat_grjbr, rx_stat_etherstatsjabbers);
673 UPDATE_STAT64(rx_stat_grxcf, rx_stat_maccontrolframesreceived);
674 UPDATE_STAT64(rx_stat_grxpf, rx_stat_xoffstateentered);
675 UPDATE_STAT64(rx_stat_grxpf, rx_stat_mac_xpf);
676 UPDATE_STAT64(tx_stat_gtxpf, tx_stat_outxoffsent);
677 UPDATE_STAT64(tx_stat_gtxpf, tx_stat_flowcontroldone);
678 UPDATE_STAT64(tx_stat_gt64, tx_stat_etherstatspkts64octets);
679 UPDATE_STAT64(tx_stat_gt127,
680 tx_stat_etherstatspkts65octetsto127octets);
681 UPDATE_STAT64(tx_stat_gt255,
682 tx_stat_etherstatspkts128octetsto255octets);
683 UPDATE_STAT64(tx_stat_gt511,
684 tx_stat_etherstatspkts256octetsto511octets);
685 UPDATE_STAT64(tx_stat_gt1023,
686 tx_stat_etherstatspkts512octetsto1023octets);
687 UPDATE_STAT64(tx_stat_gt1518,
688 tx_stat_etherstatspkts1024octetsto1522octets);
689 UPDATE_STAT64(tx_stat_gt2047, tx_stat_mac_2047);
690 UPDATE_STAT64(tx_stat_gt4095, tx_stat_mac_4095);
691 UPDATE_STAT64(tx_stat_gt9216, tx_stat_mac_9216);
692 UPDATE_STAT64(tx_stat_gt16383, tx_stat_mac_16383);
693 UPDATE_STAT64(tx_stat_gterr,
694 tx_stat_dot3statsinternalmactransmiterrors);
695 UPDATE_STAT64(tx_stat_gtufl, tx_stat_mac_ufl);
697 /* collect PFC stats */
698 pstats->pfc_frames_tx_hi = new->tx_stat_gtpp_hi;
699 pstats->pfc_frames_tx_lo = new->tx_stat_gtpp_lo;
700 ADD_64(pstats->pfc_frames_tx_hi, fwstats->pfc_frames_tx_hi,
701 pstats->pfc_frames_tx_lo, fwstats->pfc_frames_tx_lo);
703 pstats->pfc_frames_rx_hi = new->rx_stat_grpp_hi;
704 pstats->pfc_frames_rx_lo = new->rx_stat_grpp_lo;
705 ADD_64(pstats->pfc_frames_rx_hi, fwstats->pfc_frames_rx_hi,
706 pstats->pfc_frames_rx_lo, fwstats->pfc_frames_rx_lo);
709 estats->pause_frames_received_hi = pstats->mac_stx[1].rx_stat_mac_xpf_hi;
710 estats->pause_frames_received_lo = pstats->mac_stx[1].rx_stat_mac_xpf_lo;
712 estats->pause_frames_sent_hi = pstats->mac_stx[1].tx_stat_outxoffsent_hi;
713 estats->pause_frames_sent_lo = pstats->mac_stx[1].tx_stat_outxoffsent_lo;
715 estats->pfc_frames_received_hi = pstats->pfc_frames_rx_hi;
716 estats->pfc_frames_received_lo = pstats->pfc_frames_rx_lo;
717 estats->pfc_frames_sent_hi = pstats->pfc_frames_tx_hi;
718 estats->pfc_frames_sent_lo = pstats->pfc_frames_tx_lo;
722 bxe_mstat_stats_update(struct bxe_softc *sc)
724 struct host_port_stats *pstats = BXE_SP(sc, port_stats);
725 struct bxe_eth_stats *estats = &sc->eth_stats;
726 struct mstat_stats *new = BXE_SP(sc, mac_stats.mstat_stats);
728 ADD_STAT64(stats_rx.rx_grerb, rx_stat_ifhcinbadoctets);
729 ADD_STAT64(stats_rx.rx_grfcs, rx_stat_dot3statsfcserrors);
730 ADD_STAT64(stats_rx.rx_grund, rx_stat_etherstatsundersizepkts);
731 ADD_STAT64(stats_rx.rx_grovr, rx_stat_dot3statsframestoolong);
732 ADD_STAT64(stats_rx.rx_grfrg, rx_stat_etherstatsfragments);
733 ADD_STAT64(stats_rx.rx_grxcf, rx_stat_maccontrolframesreceived);
734 ADD_STAT64(stats_rx.rx_grxpf, rx_stat_xoffstateentered);
735 ADD_STAT64(stats_rx.rx_grxpf, rx_stat_mac_xpf);
736 ADD_STAT64(stats_tx.tx_gtxpf, tx_stat_outxoffsent);
737 ADD_STAT64(stats_tx.tx_gtxpf, tx_stat_flowcontroldone);
739 /* collect pfc stats */
740 ADD_64(pstats->pfc_frames_tx_hi, new->stats_tx.tx_gtxpp_hi,
741 pstats->pfc_frames_tx_lo, new->stats_tx.tx_gtxpp_lo);
742 ADD_64(pstats->pfc_frames_rx_hi, new->stats_rx.rx_grxpp_hi,
743 pstats->pfc_frames_rx_lo, new->stats_rx.rx_grxpp_lo);
745 ADD_STAT64(stats_tx.tx_gt64, tx_stat_etherstatspkts64octets);
746 ADD_STAT64(stats_tx.tx_gt127, tx_stat_etherstatspkts65octetsto127octets);
747 ADD_STAT64(stats_tx.tx_gt255, tx_stat_etherstatspkts128octetsto255octets);
748 ADD_STAT64(stats_tx.tx_gt511, tx_stat_etherstatspkts256octetsto511octets);
749 ADD_STAT64(stats_tx.tx_gt1023,
750 tx_stat_etherstatspkts512octetsto1023octets);
751 ADD_STAT64(stats_tx.tx_gt1518,
752 tx_stat_etherstatspkts1024octetsto1522octets);
753 ADD_STAT64(stats_tx.tx_gt2047, tx_stat_mac_2047);
755 ADD_STAT64(stats_tx.tx_gt4095, tx_stat_mac_4095);
756 ADD_STAT64(stats_tx.tx_gt9216, tx_stat_mac_9216);
757 ADD_STAT64(stats_tx.tx_gt16383, tx_stat_mac_16383);
759 ADD_STAT64(stats_tx.tx_gterr, tx_stat_dot3statsinternalmactransmiterrors);
760 ADD_STAT64(stats_tx.tx_gtufl, tx_stat_mac_ufl);
762 estats->etherstatspkts1024octetsto1522octets_hi =
763 pstats->mac_stx[1].tx_stat_etherstatspkts1024octetsto1522octets_hi;
764 estats->etherstatspkts1024octetsto1522octets_lo =
765 pstats->mac_stx[1].tx_stat_etherstatspkts1024octetsto1522octets_lo;
767 estats->etherstatspktsover1522octets_hi =
768 pstats->mac_stx[1].tx_stat_mac_2047_hi;
769 estats->etherstatspktsover1522octets_lo =
770 pstats->mac_stx[1].tx_stat_mac_2047_lo;
772 ADD_64(estats->etherstatspktsover1522octets_hi,
773 pstats->mac_stx[1].tx_stat_mac_4095_hi,
774 estats->etherstatspktsover1522octets_lo,
775 pstats->mac_stx[1].tx_stat_mac_4095_lo);
777 ADD_64(estats->etherstatspktsover1522octets_hi,
778 pstats->mac_stx[1].tx_stat_mac_9216_hi,
779 estats->etherstatspktsover1522octets_lo,
780 pstats->mac_stx[1].tx_stat_mac_9216_lo);
782 ADD_64(estats->etherstatspktsover1522octets_hi,
783 pstats->mac_stx[1].tx_stat_mac_16383_hi,
784 estats->etherstatspktsover1522octets_lo,
785 pstats->mac_stx[1].tx_stat_mac_16383_lo);
787 estats->pause_frames_received_hi = pstats->mac_stx[1].rx_stat_mac_xpf_hi;
788 estats->pause_frames_received_lo = pstats->mac_stx[1].rx_stat_mac_xpf_lo;
790 estats->pause_frames_sent_hi = pstats->mac_stx[1].tx_stat_outxoffsent_hi;
791 estats->pause_frames_sent_lo = pstats->mac_stx[1].tx_stat_outxoffsent_lo;
793 estats->pfc_frames_received_hi = pstats->pfc_frames_rx_hi;
794 estats->pfc_frames_received_lo = pstats->pfc_frames_rx_lo;
795 estats->pfc_frames_sent_hi = pstats->pfc_frames_tx_hi;
796 estats->pfc_frames_sent_lo = pstats->pfc_frames_tx_lo;
800 bxe_emac_stats_update(struct bxe_softc *sc)
802 struct emac_stats *new = BXE_SP(sc, mac_stats.emac_stats);
803 struct host_port_stats *pstats = BXE_SP(sc, port_stats);
804 struct bxe_eth_stats *estats = &sc->eth_stats;
806 UPDATE_EXTEND_STAT(rx_stat_ifhcinbadoctets);
807 UPDATE_EXTEND_STAT(tx_stat_ifhcoutbadoctets);
808 UPDATE_EXTEND_STAT(rx_stat_dot3statsfcserrors);
809 UPDATE_EXTEND_STAT(rx_stat_dot3statsalignmenterrors);
810 UPDATE_EXTEND_STAT(rx_stat_dot3statscarriersenseerrors);
811 UPDATE_EXTEND_STAT(rx_stat_falsecarriererrors);
812 UPDATE_EXTEND_STAT(rx_stat_etherstatsundersizepkts);
813 UPDATE_EXTEND_STAT(rx_stat_dot3statsframestoolong);
814 UPDATE_EXTEND_STAT(rx_stat_etherstatsfragments);
815 UPDATE_EXTEND_STAT(rx_stat_etherstatsjabbers);
816 UPDATE_EXTEND_STAT(rx_stat_maccontrolframesreceived);
817 UPDATE_EXTEND_STAT(rx_stat_xoffstateentered);
818 UPDATE_EXTEND_STAT(rx_stat_xonpauseframesreceived);
819 UPDATE_EXTEND_STAT(rx_stat_xoffpauseframesreceived);
820 UPDATE_EXTEND_STAT(tx_stat_outxonsent);
821 UPDATE_EXTEND_STAT(tx_stat_outxoffsent);
822 UPDATE_EXTEND_STAT(tx_stat_flowcontroldone);
823 UPDATE_EXTEND_STAT(tx_stat_etherstatscollisions);
824 UPDATE_EXTEND_STAT(tx_stat_dot3statssinglecollisionframes);
825 UPDATE_EXTEND_STAT(tx_stat_dot3statsmultiplecollisionframes);
826 UPDATE_EXTEND_STAT(tx_stat_dot3statsdeferredtransmissions);
827 UPDATE_EXTEND_STAT(tx_stat_dot3statsexcessivecollisions);
828 UPDATE_EXTEND_STAT(tx_stat_dot3statslatecollisions);
829 UPDATE_EXTEND_STAT(tx_stat_etherstatspkts64octets);
830 UPDATE_EXTEND_STAT(tx_stat_etherstatspkts65octetsto127octets);
831 UPDATE_EXTEND_STAT(tx_stat_etherstatspkts128octetsto255octets);
832 UPDATE_EXTEND_STAT(tx_stat_etherstatspkts256octetsto511octets);
833 UPDATE_EXTEND_STAT(tx_stat_etherstatspkts512octetsto1023octets);
834 UPDATE_EXTEND_STAT(tx_stat_etherstatspkts1024octetsto1522octets);
835 UPDATE_EXTEND_STAT(tx_stat_etherstatspktsover1522octets);
836 UPDATE_EXTEND_STAT(tx_stat_dot3statsinternalmactransmiterrors);
838 estats->pause_frames_received_hi =
839 pstats->mac_stx[1].rx_stat_xonpauseframesreceived_hi;
840 estats->pause_frames_received_lo =
841 pstats->mac_stx[1].rx_stat_xonpauseframesreceived_lo;
842 ADD_64(estats->pause_frames_received_hi,
843 pstats->mac_stx[1].rx_stat_xoffpauseframesreceived_hi,
844 estats->pause_frames_received_lo,
845 pstats->mac_stx[1].rx_stat_xoffpauseframesreceived_lo);
847 estats->pause_frames_sent_hi =
848 pstats->mac_stx[1].tx_stat_outxonsent_hi;
849 estats->pause_frames_sent_lo =
850 pstats->mac_stx[1].tx_stat_outxonsent_lo;
851 ADD_64(estats->pause_frames_sent_hi,
852 pstats->mac_stx[1].tx_stat_outxoffsent_hi,
853 estats->pause_frames_sent_lo,
854 pstats->mac_stx[1].tx_stat_outxoffsent_lo);
858 bxe_hw_stats_update(struct bxe_softc *sc)
860 struct nig_stats *new = BXE_SP(sc, nig_stats);
861 struct nig_stats *old = &(sc->port.old_nig_stats);
862 struct host_port_stats *pstats = BXE_SP(sc, port_stats);
863 struct bxe_eth_stats *estats = &sc->eth_stats;
864 uint32_t lpi_reg, nig_timer_max;
870 switch (sc->link_vars.mac_type) {
871 case ELINK_MAC_TYPE_BMAC:
872 bxe_bmac_stats_update(sc);
875 case ELINK_MAC_TYPE_EMAC:
876 bxe_emac_stats_update(sc);
879 case ELINK_MAC_TYPE_UMAC:
880 case ELINK_MAC_TYPE_XMAC:
881 bxe_mstat_stats_update(sc);
884 case ELINK_MAC_TYPE_NONE: /* unreached */
886 "stats updated by DMAE but no MAC active\n");
889 default: /* unreached */
890 BLOGE(sc, "stats update failed, unknown MAC type\n");
893 ADD_EXTEND_64(pstats->brb_drop_hi, pstats->brb_drop_lo,
894 new->brb_discard - old->brb_discard);
895 ADD_EXTEND_64(estats->brb_truncate_hi, estats->brb_truncate_lo,
896 new->brb_truncate - old->brb_truncate);
898 if (!CHIP_IS_E3(sc)) {
899 UPDATE_STAT64_NIG(egress_mac_pkt0,
900 etherstatspkts1024octetsto1522octets);
901 UPDATE_STAT64_NIG(egress_mac_pkt1,
902 etherstatspktsover1522octets);
905 memcpy(old, new, sizeof(struct nig_stats));
907 memcpy(&(estats->rx_stat_ifhcinbadoctets_hi), &(pstats->mac_stx[1]),
908 sizeof(struct mac_stx));
909 estats->brb_drop_hi = pstats->brb_drop_hi;
910 estats->brb_drop_lo = pstats->brb_drop_lo;
912 pstats->host_port_stats_counter++;
914 if (CHIP_IS_E3(sc)) {
915 lpi_reg = (SC_PORT(sc)) ?
916 MISC_REG_CPMU_LP_SM_ENT_CNT_P1 :
917 MISC_REG_CPMU_LP_SM_ENT_CNT_P0;
918 estats->eee_tx_lpi += REG_RD(sc, lpi_reg);
921 if (!BXE_NOMCP(sc)) {
922 nig_timer_max = SHMEM_RD(sc, port_mb[SC_PORT(sc)].stat_nig_timer);
923 if (nig_timer_max != estats->nig_timer_max) {
924 estats->nig_timer_max = nig_timer_max;
925 /*NOTE: not setting error bit */
926 BLOGE(sc, "invalid NIG timer max (%u)\n",
927 estats->nig_timer_max);
935 bxe_storm_stats_validate_counters(struct bxe_softc *sc)
937 struct stats_counter *counters = &sc->fw_stats_data->storm_counters;
938 uint16_t cur_stats_counter;
941 * Make sure we use the value of the counter
942 * used for sending the last stats ramrod.
945 cur_stats_counter = (sc->stats_counter - 1);
946 BXE_STATS_UNLOCK(sc);
948 /* are storm stats valid? */
949 if (le16toh(counters->xstats_counter) != cur_stats_counter) {
951 "stats not updated by xstorm, "
952 "counter 0x%x != stats_counter 0x%x\n",
953 le16toh(counters->xstats_counter), sc->stats_counter);
957 if (le16toh(counters->ustats_counter) != cur_stats_counter) {
959 "stats not updated by ustorm, "
960 "counter 0x%x != stats_counter 0x%x\n",
961 le16toh(counters->ustats_counter), sc->stats_counter);
965 if (le16toh(counters->cstats_counter) != cur_stats_counter) {
967 "stats not updated by cstorm, "
968 "counter 0x%x != stats_counter 0x%x\n",
969 le16toh(counters->cstats_counter), sc->stats_counter);
973 if (le16toh(counters->tstats_counter) != cur_stats_counter) {
975 "stats not updated by tstorm, "
976 "counter 0x%x != stats_counter 0x%x\n",
977 le16toh(counters->tstats_counter), sc->stats_counter);
985 bxe_storm_stats_update(struct bxe_softc *sc)
987 struct tstorm_per_port_stats *tport =
988 &sc->fw_stats_data->port.tstorm_port_statistics;
989 struct tstorm_per_pf_stats *tfunc =
990 &sc->fw_stats_data->pf.tstorm_pf_statistics;
991 struct host_func_stats *fstats = &sc->func_stats;
992 struct bxe_eth_stats *estats = &sc->eth_stats;
993 struct bxe_eth_stats_old *estats_old = &sc->eth_stats_old;
996 /* vfs stat counter is managed by pf */
997 if (IS_PF(sc) && bxe_storm_stats_validate_counters(sc)) {
1001 estats->error_bytes_received_hi = 0;
1002 estats->error_bytes_received_lo = 0;
1004 for (i = 0; i < sc->num_queues; i++) {
1005 struct bxe_fastpath *fp = &sc->fp[i];
1006 struct tstorm_per_queue_stats *tclient =
1007 &sc->fw_stats_data->queue_stats[i].tstorm_queue_statistics;
1008 struct tstorm_per_queue_stats *old_tclient = &fp->old_tclient;
1009 struct ustorm_per_queue_stats *uclient =
1010 &sc->fw_stats_data->queue_stats[i].ustorm_queue_statistics;
1011 struct ustorm_per_queue_stats *old_uclient = &fp->old_uclient;
1012 struct xstorm_per_queue_stats *xclient =
1013 &sc->fw_stats_data->queue_stats[i].xstorm_queue_statistics;
1014 struct xstorm_per_queue_stats *old_xclient = &fp->old_xclient;
1015 struct bxe_eth_q_stats *qstats = &fp->eth_q_stats;
1016 struct bxe_eth_q_stats_old *qstats_old = &fp->eth_q_stats_old;
1020 BLOGD(sc, DBG_STATS,
1021 "queue[%d]: ucast_sent 0x%x bcast_sent 0x%x mcast_sent 0x%x\n",
1022 i, xclient->ucast_pkts_sent, xclient->bcast_pkts_sent,
1023 xclient->mcast_pkts_sent);
1025 BLOGD(sc, DBG_STATS, "---------------\n");
1027 UPDATE_QSTAT(tclient->rcv_bcast_bytes,
1028 total_broadcast_bytes_received);
1029 UPDATE_QSTAT(tclient->rcv_mcast_bytes,
1030 total_multicast_bytes_received);
1031 UPDATE_QSTAT(tclient->rcv_ucast_bytes,
1032 total_unicast_bytes_received);
1035 * sum to total_bytes_received all
1036 * unicast/multicast/broadcast
1038 qstats->total_bytes_received_hi =
1039 qstats->total_broadcast_bytes_received_hi;
1040 qstats->total_bytes_received_lo =
1041 qstats->total_broadcast_bytes_received_lo;
1043 ADD_64(qstats->total_bytes_received_hi,
1044 qstats->total_multicast_bytes_received_hi,
1045 qstats->total_bytes_received_lo,
1046 qstats->total_multicast_bytes_received_lo);
1048 ADD_64(qstats->total_bytes_received_hi,
1049 qstats->total_unicast_bytes_received_hi,
1050 qstats->total_bytes_received_lo,
1051 qstats->total_unicast_bytes_received_lo);
1053 qstats->valid_bytes_received_hi = qstats->total_bytes_received_hi;
1054 qstats->valid_bytes_received_lo = qstats->total_bytes_received_lo;
1056 UPDATE_EXTEND_TSTAT(rcv_ucast_pkts, total_unicast_packets_received);
1057 UPDATE_EXTEND_TSTAT(rcv_mcast_pkts, total_multicast_packets_received);
1058 UPDATE_EXTEND_TSTAT(rcv_bcast_pkts, total_broadcast_packets_received);
1059 UPDATE_EXTEND_E_TSTAT(pkts_too_big_discard,
1060 etherstatsoverrsizepkts, 32);
1061 UPDATE_EXTEND_E_TSTAT(no_buff_discard, no_buff_discard, 16);
1063 SUB_EXTEND_USTAT(ucast_no_buff_pkts, total_unicast_packets_received);
1064 SUB_EXTEND_USTAT(mcast_no_buff_pkts,
1065 total_multicast_packets_received);
1066 SUB_EXTEND_USTAT(bcast_no_buff_pkts,
1067 total_broadcast_packets_received);
1068 UPDATE_EXTEND_E_USTAT(ucast_no_buff_pkts, no_buff_discard);
1069 UPDATE_EXTEND_E_USTAT(mcast_no_buff_pkts, no_buff_discard);
1070 UPDATE_EXTEND_E_USTAT(bcast_no_buff_pkts, no_buff_discard);
1072 UPDATE_QSTAT(xclient->bcast_bytes_sent,
1073 total_broadcast_bytes_transmitted);
1074 UPDATE_QSTAT(xclient->mcast_bytes_sent,
1075 total_multicast_bytes_transmitted);
1076 UPDATE_QSTAT(xclient->ucast_bytes_sent,
1077 total_unicast_bytes_transmitted);
1080 * sum to total_bytes_transmitted all
1081 * unicast/multicast/broadcast
1083 qstats->total_bytes_transmitted_hi =
1084 qstats->total_unicast_bytes_transmitted_hi;
1085 qstats->total_bytes_transmitted_lo =
1086 qstats->total_unicast_bytes_transmitted_lo;
1088 ADD_64(qstats->total_bytes_transmitted_hi,
1089 qstats->total_broadcast_bytes_transmitted_hi,
1090 qstats->total_bytes_transmitted_lo,
1091 qstats->total_broadcast_bytes_transmitted_lo);
1093 ADD_64(qstats->total_bytes_transmitted_hi,
1094 qstats->total_multicast_bytes_transmitted_hi,
1095 qstats->total_bytes_transmitted_lo,
1096 qstats->total_multicast_bytes_transmitted_lo);
1098 UPDATE_EXTEND_XSTAT(ucast_pkts_sent,
1099 total_unicast_packets_transmitted);
1100 UPDATE_EXTEND_XSTAT(mcast_pkts_sent,
1101 total_multicast_packets_transmitted);
1102 UPDATE_EXTEND_XSTAT(bcast_pkts_sent,
1103 total_broadcast_packets_transmitted);
1105 UPDATE_EXTEND_TSTAT(checksum_discard,
1106 total_packets_received_checksum_discarded);
1107 UPDATE_EXTEND_TSTAT(ttl0_discard,
1108 total_packets_received_ttl0_discarded);
1110 UPDATE_EXTEND_XSTAT(error_drop_pkts,
1111 total_transmitted_dropped_packets_error);
1113 /* TPA aggregations completed */
1114 UPDATE_EXTEND_E_USTAT(coalesced_events, total_tpa_aggregations);
1115 /* Number of network frames aggregated by TPA */
1116 UPDATE_EXTEND_E_USTAT(coalesced_pkts, total_tpa_aggregated_frames);
1117 /* Total number of bytes in completed TPA aggregations */
1118 UPDATE_QSTAT(uclient->coalesced_bytes, total_tpa_bytes);
1120 UPDATE_ESTAT_QSTAT_64(total_tpa_bytes);
1122 UPDATE_FSTAT_QSTAT(total_bytes_received);
1123 UPDATE_FSTAT_QSTAT(total_bytes_transmitted);
1124 UPDATE_FSTAT_QSTAT(total_unicast_packets_received);
1125 UPDATE_FSTAT_QSTAT(total_multicast_packets_received);
1126 UPDATE_FSTAT_QSTAT(total_broadcast_packets_received);
1127 UPDATE_FSTAT_QSTAT(total_unicast_packets_transmitted);
1128 UPDATE_FSTAT_QSTAT(total_multicast_packets_transmitted);
1129 UPDATE_FSTAT_QSTAT(total_broadcast_packets_transmitted);
1130 UPDATE_FSTAT_QSTAT(valid_bytes_received);
1133 ADD_64(estats->total_bytes_received_hi,
1134 estats->rx_stat_ifhcinbadoctets_hi,
1135 estats->total_bytes_received_lo,
1136 estats->rx_stat_ifhcinbadoctets_lo);
1138 ADD_64_LE(estats->total_bytes_received_hi,
1139 tfunc->rcv_error_bytes.hi,
1140 estats->total_bytes_received_lo,
1141 tfunc->rcv_error_bytes.lo);
1143 ADD_64_LE(estats->error_bytes_received_hi,
1144 tfunc->rcv_error_bytes.hi,
1145 estats->error_bytes_received_lo,
1146 tfunc->rcv_error_bytes.lo);
1148 UPDATE_ESTAT(etherstatsoverrsizepkts, rx_stat_dot3statsframestoolong);
1150 ADD_64(estats->error_bytes_received_hi,
1151 estats->rx_stat_ifhcinbadoctets_hi,
1152 estats->error_bytes_received_lo,
1153 estats->rx_stat_ifhcinbadoctets_lo);
1156 struct bxe_fw_port_stats_old *fwstats = &sc->fw_stats_old;
1157 UPDATE_FW_STAT(mac_filter_discard);
1158 UPDATE_FW_STAT(mf_tag_discard);
1159 UPDATE_FW_STAT(brb_truncate_discard);
1160 UPDATE_FW_STAT(mac_discard);
1163 fstats->host_func_stats_start = ++fstats->host_func_stats_end;
1165 sc->stats_pending = 0;
1171 bxe_net_stats_update(struct bxe_softc *sc)
1173 struct bxe_eth_stats *estats = &sc->eth_stats;
1174 struct ifnet *ifnet = sc->ifnet;
1178 ifnet->if_data.ifi_ipackets =
1179 bxe_hilo(&estats->total_unicast_packets_received_hi) +
1180 bxe_hilo(&estats->total_multicast_packets_received_hi) +
1181 bxe_hilo(&estats->total_broadcast_packets_received_hi);
1183 ifnet->if_data.ifi_opackets =
1184 bxe_hilo(&estats->total_unicast_packets_transmitted_hi) +
1185 bxe_hilo(&estats->total_multicast_packets_transmitted_hi) +
1186 bxe_hilo(&estats->total_broadcast_packets_transmitted_hi);
1188 ifnet->if_data.ifi_ibytes = bxe_hilo(&estats->total_bytes_received_hi);
1190 ifnet->if_data.ifi_obytes = bxe_hilo(&estats->total_bytes_transmitted_hi);
1193 for (i = 0; i < sc->num_queues; i++) {
1194 struct tstorm_per_queue_stats *old_tclient =
1195 &sc->fp[i].old_tclient;
1196 tmp += le32toh(old_tclient->checksum_discard);
1199 ifnet->if_data.ifi_iqdrops = tmp;
1201 ifnet->if_data.ifi_ierrors =
1202 bxe_hilo(&estats->rx_stat_etherstatsundersizepkts_hi) +
1203 bxe_hilo(&estats->etherstatsoverrsizepkts_hi) +
1204 bxe_hilo(&estats->brb_drop_hi) +
1205 bxe_hilo(&estats->brb_truncate_hi) +
1206 bxe_hilo(&estats->rx_stat_dot3statsfcserrors_hi) +
1207 bxe_hilo(&estats->rx_stat_dot3statsalignmenterrors_hi) +
1208 bxe_hilo(&estats->no_buff_discard_hi);
1210 ifnet->if_data.ifi_oerrors =
1211 bxe_hilo(&estats->rx_stat_dot3statscarriersenseerrors_hi) +
1212 bxe_hilo(&estats->tx_stat_dot3statsinternalmactransmiterrors_hi);
1214 ifnet->if_data.ifi_imcasts =
1215 bxe_hilo(&estats->total_multicast_packets_received_hi);
1217 ifnet->if_data.ifi_collisions =
1218 bxe_hilo(&estats->tx_stat_etherstatscollisions_hi) +
1219 bxe_hilo(&estats->tx_stat_dot3statslatecollisions_hi) +
1220 bxe_hilo(&estats->tx_stat_dot3statsexcessivecollisions_hi);
1224 bxe_drv_stats_update(struct bxe_softc *sc)
1226 struct bxe_eth_stats *estats = &sc->eth_stats;
1229 for (i = 0; i < sc->num_queues; i++) {
1230 struct bxe_eth_q_stats *qstats = &sc->fp[i].eth_q_stats;
1231 struct bxe_eth_q_stats_old *qstats_old = &sc->fp[i].eth_q_stats_old;
1233 UPDATE_ESTAT_QSTAT(rx_calls);
1234 UPDATE_ESTAT_QSTAT(rx_pkts);
1235 UPDATE_ESTAT_QSTAT(rx_tpa_pkts);
1236 UPDATE_ESTAT_QSTAT(rx_erroneous_jumbo_sge_pkts);
1237 UPDATE_ESTAT_QSTAT(rx_bxe_service_rxsgl);
1238 UPDATE_ESTAT_QSTAT(rx_jumbo_sge_pkts);
1239 UPDATE_ESTAT_QSTAT(rx_soft_errors);
1240 UPDATE_ESTAT_QSTAT(rx_hw_csum_errors);
1241 UPDATE_ESTAT_QSTAT(rx_ofld_frames_csum_ip);
1242 UPDATE_ESTAT_QSTAT(rx_ofld_frames_csum_tcp_udp);
1243 UPDATE_ESTAT_QSTAT(rx_budget_reached);
1244 UPDATE_ESTAT_QSTAT(tx_pkts);
1245 UPDATE_ESTAT_QSTAT(tx_soft_errors);
1246 UPDATE_ESTAT_QSTAT(tx_ofld_frames_csum_ip);
1247 UPDATE_ESTAT_QSTAT(tx_ofld_frames_csum_tcp);
1248 UPDATE_ESTAT_QSTAT(tx_ofld_frames_csum_udp);
1249 UPDATE_ESTAT_QSTAT(tx_ofld_frames_lso);
1250 UPDATE_ESTAT_QSTAT(tx_ofld_frames_lso_hdr_splits);
1251 UPDATE_ESTAT_QSTAT(tx_encap_failures);
1252 UPDATE_ESTAT_QSTAT(tx_hw_queue_full);
1253 UPDATE_ESTAT_QSTAT(tx_hw_max_queue_depth);
1254 UPDATE_ESTAT_QSTAT(tx_dma_mapping_failure);
1255 UPDATE_ESTAT_QSTAT(tx_max_drbr_queue_depth);
1256 UPDATE_ESTAT_QSTAT(tx_window_violation_std);
1257 UPDATE_ESTAT_QSTAT(tx_window_violation_tso);
1258 //UPDATE_ESTAT_QSTAT(tx_unsupported_tso_request_ipv6);
1259 //UPDATE_ESTAT_QSTAT(tx_unsupported_tso_request_not_tcp);
1260 UPDATE_ESTAT_QSTAT(tx_chain_lost_mbuf);
1261 UPDATE_ESTAT_QSTAT(tx_frames_deferred);
1262 UPDATE_ESTAT_QSTAT(tx_queue_xoff);
1264 /* mbuf driver statistics */
1265 UPDATE_ESTAT_QSTAT(mbuf_defrag_attempts);
1266 UPDATE_ESTAT_QSTAT(mbuf_defrag_failures);
1267 UPDATE_ESTAT_QSTAT(mbuf_rx_bd_alloc_failed);
1268 UPDATE_ESTAT_QSTAT(mbuf_rx_bd_mapping_failed);
1269 UPDATE_ESTAT_QSTAT(mbuf_rx_tpa_alloc_failed);
1270 UPDATE_ESTAT_QSTAT(mbuf_rx_tpa_mapping_failed);
1271 UPDATE_ESTAT_QSTAT(mbuf_rx_sge_alloc_failed);
1272 UPDATE_ESTAT_QSTAT(mbuf_rx_sge_mapping_failed);
1274 /* track the number of allocated mbufs */
1275 UPDATE_ESTAT_QSTAT(mbuf_alloc_tx);
1276 UPDATE_ESTAT_QSTAT(mbuf_alloc_rx);
1277 UPDATE_ESTAT_QSTAT(mbuf_alloc_sge);
1278 UPDATE_ESTAT_QSTAT(mbuf_alloc_tpa);
1283 bxe_edebug_stats_stopped(struct bxe_softc *sc)
1287 if (SHMEM2_HAS(sc, edebug_driver_if[1])) {
1288 val = SHMEM2_RD(sc, edebug_driver_if[1]);
1290 if (val == EDEBUG_DRIVER_IF_OP_CODE_DISABLE_STAT) {
1299 bxe_stats_update(struct bxe_softc *sc)
1301 uint32_t *stats_comp = BXE_SP(sc, stats_comp);
1303 if (bxe_edebug_stats_stopped(sc)) {
1308 if (*stats_comp != DMAE_COMP_VAL) {
1313 bxe_hw_stats_update(sc);
1316 if (bxe_storm_stats_update(sc)) {
1317 if (sc->stats_pending++ == 3) {
1318 if (sc->ifnet->if_drv_flags & IFF_DRV_RUNNING) {
1319 BLOGE(sc, "Storm stats not updated for 3 times, resetting\n");
1320 BXE_SET_ERROR_BIT(sc, BXE_ERR_STATS_TO);
1321 taskqueue_enqueue_timeout(taskqueue_thread,
1322 &sc->sp_err_timeout_task, hz/10);
1329 * VF doesn't collect HW statistics, and doesn't get completions,
1330 * performs only update.
1332 bxe_storm_stats_update(sc);
1335 bxe_net_stats_update(sc);
1336 bxe_drv_stats_update(sc);
1343 bxe_hw_stats_post(sc);
1344 bxe_storm_stats_post(sc);
1348 bxe_port_stats_stop(struct bxe_softc *sc)
1350 struct dmae_cmd *dmae;
1352 int loader_idx = PMF_DMAE_C(sc);
1353 uint32_t *stats_comp = BXE_SP(sc, stats_comp);
1355 sc->executer_idx = 0;
1357 opcode = bxe_dmae_opcode(sc, DMAE_SRC_PCI, DMAE_DST_GRC, FALSE, 0);
1359 if (sc->port.port_stx) {
1360 dmae = BXE_SP(sc, dmae[sc->executer_idx++]);
1363 dmae->opcode = bxe_dmae_opcode_add_comp(opcode, DMAE_COMP_GRC);
1365 dmae->opcode = bxe_dmae_opcode_add_comp(opcode, DMAE_COMP_PCI);
1368 dmae->src_addr_lo = U64_LO(BXE_SP_MAPPING(sc, port_stats));
1369 dmae->src_addr_hi = U64_HI(BXE_SP_MAPPING(sc, port_stats));
1370 dmae->dst_addr_lo = sc->port.port_stx >> 2;
1371 dmae->dst_addr_hi = 0;
1372 dmae->len = bxe_get_port_stats_dma_len(sc);
1374 dmae->comp_addr_lo = (dmae_reg_go_c[loader_idx] >> 2);
1375 dmae->comp_addr_hi = 0;
1378 dmae->comp_addr_lo = U64_LO(BXE_SP_MAPPING(sc, stats_comp));
1379 dmae->comp_addr_hi = U64_HI(BXE_SP_MAPPING(sc, stats_comp));
1380 dmae->comp_val = DMAE_COMP_VAL;
1387 dmae = BXE_SP(sc, dmae[sc->executer_idx++]);
1388 dmae->opcode = bxe_dmae_opcode_add_comp(opcode, DMAE_COMP_PCI);
1389 dmae->src_addr_lo = U64_LO(BXE_SP_MAPPING(sc, func_stats));
1390 dmae->src_addr_hi = U64_HI(BXE_SP_MAPPING(sc, func_stats));
1391 dmae->dst_addr_lo = (sc->func_stx >> 2);
1392 dmae->dst_addr_hi = 0;
1393 dmae->len = (sizeof(struct host_func_stats) >> 2);
1394 dmae->comp_addr_lo = U64_LO(BXE_SP_MAPPING(sc, stats_comp));
1395 dmae->comp_addr_hi = U64_HI(BXE_SP_MAPPING(sc, stats_comp));
1396 dmae->comp_val = DMAE_COMP_VAL;
1403 bxe_stats_stop(struct bxe_softc *sc)
1405 uint8_t update = FALSE;
1410 update = bxe_hw_stats_update(sc) == 0;
1413 update |= bxe_storm_stats_update(sc) == 0;
1416 bxe_net_stats_update(sc);
1419 bxe_port_stats_stop(sc);
1422 bxe_hw_stats_post(sc);
1428 bxe_stats_do_nothing(struct bxe_softc *sc)
1433 static const struct {
1434 void (*action)(struct bxe_softc *sc);
1435 enum bxe_stats_state next_state;
1436 } bxe_stats_stm[STATS_STATE_MAX][STATS_EVENT_MAX] = {
1438 /* DISABLED PMF */ { bxe_stats_pmf_update, STATS_STATE_DISABLED },
1439 /* LINK_UP */ { bxe_stats_start, STATS_STATE_ENABLED },
1440 /* UPDATE */ { bxe_stats_do_nothing, STATS_STATE_DISABLED },
1441 /* STOP */ { bxe_stats_do_nothing, STATS_STATE_DISABLED }
1444 /* ENABLED PMF */ { bxe_stats_pmf_start, STATS_STATE_ENABLED },
1445 /* LINK_UP */ { bxe_stats_restart, STATS_STATE_ENABLED },
1446 /* UPDATE */ { bxe_stats_update, STATS_STATE_ENABLED },
1447 /* STOP */ { bxe_stats_stop, STATS_STATE_DISABLED }
1451 void bxe_stats_handle(struct bxe_softc *sc,
1452 enum bxe_stats_event event)
1454 enum bxe_stats_state state;
1456 if (__predict_false(sc->panic)) {
1461 state = sc->stats_state;
1462 sc->stats_state = bxe_stats_stm[state][event].next_state;
1463 BXE_STATS_UNLOCK(sc);
1465 bxe_stats_stm[state][event].action(sc);
1467 if (event != STATS_EVENT_UPDATE) {
1468 BLOGD(sc, DBG_STATS,
1469 "state %d -> event %d -> state %d\n",
1470 state, event, sc->stats_state);
1475 bxe_port_stats_base_init(struct bxe_softc *sc)
1477 struct dmae_cmd *dmae;
1478 uint32_t *stats_comp = BXE_SP(sc, stats_comp);
1481 if (!sc->port.pmf || !sc->port.port_stx) {
1482 BLOGE(sc, "BUG!\n");
1486 sc->executer_idx = 0;
1488 dmae = BXE_SP(sc, dmae[sc->executer_idx++]);
1489 dmae->opcode = bxe_dmae_opcode(sc, DMAE_SRC_PCI, DMAE_DST_GRC,
1490 TRUE, DMAE_COMP_PCI);
1491 dmae->src_addr_lo = U64_LO(BXE_SP_MAPPING(sc, port_stats));
1492 dmae->src_addr_hi = U64_HI(BXE_SP_MAPPING(sc, port_stats));
1493 dmae->dst_addr_lo = (sc->port.port_stx >> 2);
1494 dmae->dst_addr_hi = 0;
1495 dmae->len = bxe_get_port_stats_dma_len(sc);
1496 dmae->comp_addr_lo = U64_LO(BXE_SP_MAPPING(sc, stats_comp));
1497 dmae->comp_addr_hi = U64_HI(BXE_SP_MAPPING(sc, stats_comp));
1498 dmae->comp_val = DMAE_COMP_VAL;
1501 bxe_hw_stats_post(sc);
1506 * This function will prepare the statistics ramrod data the way
1507 * we will only have to increment the statistics counter and
1508 * send the ramrod each time we have to.
1511 bxe_prep_fw_stats_req(struct bxe_softc *sc)
1514 int first_queue_query_index;
1515 struct stats_query_header *stats_hdr = &sc->fw_stats_req->hdr;
1516 bus_addr_t cur_data_offset;
1517 struct stats_query_entry *cur_query_entry;
1519 stats_hdr->cmd_num = sc->fw_stats_num;
1520 stats_hdr->drv_stats_counter = 0;
1523 * The storm_counters struct contains the counters of completed
1524 * statistics requests per storm which are incremented by FW
1525 * each time it completes hadning a statistics ramrod. We will
1526 * check these counters in the timer handler and discard a
1527 * (statistics) ramrod completion.
1529 cur_data_offset = (sc->fw_stats_data_mapping +
1530 offsetof(struct bxe_fw_stats_data, storm_counters));
1532 stats_hdr->stats_counters_addrs.hi = htole32(U64_HI(cur_data_offset));
1533 stats_hdr->stats_counters_addrs.lo = htole32(U64_LO(cur_data_offset));
1536 * Prepare the first stats ramrod (will be completed with
1537 * the counters equal to zero) - init counters to somethig different.
1539 memset(&sc->fw_stats_data->storm_counters, 0xff,
1540 sizeof(struct stats_counter));
1542 /**** Port FW statistics data ****/
1543 cur_data_offset = (sc->fw_stats_data_mapping +
1544 offsetof(struct bxe_fw_stats_data, port));
1546 cur_query_entry = &sc->fw_stats_req->query[BXE_PORT_QUERY_IDX];
1548 cur_query_entry->kind = STATS_TYPE_PORT;
1549 /* For port query index is a DONT CARE */
1550 cur_query_entry->index = SC_PORT(sc);
1551 /* For port query funcID is a DONT CARE */
1552 cur_query_entry->funcID = htole16(SC_FUNC(sc));
1553 cur_query_entry->address.hi = htole32(U64_HI(cur_data_offset));
1554 cur_query_entry->address.lo = htole32(U64_LO(cur_data_offset));
1556 /**** PF FW statistics data ****/
1557 cur_data_offset = (sc->fw_stats_data_mapping +
1558 offsetof(struct bxe_fw_stats_data, pf));
1560 cur_query_entry = &sc->fw_stats_req->query[BXE_PF_QUERY_IDX];
1562 cur_query_entry->kind = STATS_TYPE_PF;
1563 /* For PF query index is a DONT CARE */
1564 cur_query_entry->index = SC_PORT(sc);
1565 cur_query_entry->funcID = htole16(SC_FUNC(sc));
1566 cur_query_entry->address.hi = htole32(U64_HI(cur_data_offset));
1567 cur_query_entry->address.lo = htole32(U64_LO(cur_data_offset));
1569 /**** Clients' queries ****/
1570 cur_data_offset = (sc->fw_stats_data_mapping +
1571 offsetof(struct bxe_fw_stats_data, queue_stats));
1574 * First queue query index depends whether FCoE offloaded request will
1575 * be included in the ramrod
1577 first_queue_query_index = (BXE_FIRST_QUEUE_QUERY_IDX - 1);
1579 for (i = 0; i < sc->num_queues; i++) {
1581 &sc->fw_stats_req->query[first_queue_query_index + i];
1583 cur_query_entry->kind = STATS_TYPE_QUEUE;
1584 cur_query_entry->index = bxe_stats_id(&sc->fp[i]);
1585 cur_query_entry->funcID = htole16(SC_FUNC(sc));
1586 cur_query_entry->address.hi = htole32(U64_HI(cur_data_offset));
1587 cur_query_entry->address.lo = htole32(U64_LO(cur_data_offset));
1589 cur_data_offset += sizeof(struct per_queue_stats);
1594 bxe_stats_init(struct bxe_softc *sc)
1596 int /*abs*/port = SC_PORT(sc);
1597 int mb_idx = SC_FW_MB_IDX(sc);
1600 sc->stats_pending = 0;
1601 sc->executer_idx = 0;
1602 sc->stats_counter = 0;
1604 /* port and func stats for management */
1605 if (!BXE_NOMCP(sc)) {
1606 sc->port.port_stx = SHMEM_RD(sc, port_mb[port].port_stx);
1607 sc->func_stx = SHMEM_RD(sc, func_mb[mb_idx].fw_mb_param);
1609 sc->port.port_stx = 0;
1613 BLOGD(sc, DBG_STATS, "port_stx 0x%x func_stx 0x%x\n",
1614 sc->port.port_stx, sc->func_stx);
1616 /* pmf should retrieve port statistics from SP on a non-init*/
1617 if (!sc->stats_init && sc->port.pmf && sc->port.port_stx) {
1618 bxe_stats_handle(sc, STATS_EVENT_PMF);
1623 memset(&(sc->port.old_nig_stats), 0, sizeof(struct nig_stats));
1624 sc->port.old_nig_stats.brb_discard =
1625 REG_RD(sc, NIG_REG_STAT0_BRB_DISCARD + port*0x38);
1626 sc->port.old_nig_stats.brb_truncate =
1627 REG_RD(sc, NIG_REG_STAT0_BRB_TRUNCATE + port*0x38);
1628 if (!CHIP_IS_E3(sc)) {
1629 REG_RD_DMAE(sc, NIG_REG_STAT0_EGRESS_MAC_PKT0 + port*0x50,
1630 &(sc->port.old_nig_stats.egress_mac_pkt0_lo), 2);
1631 REG_RD_DMAE(sc, NIG_REG_STAT0_EGRESS_MAC_PKT1 + port*0x50,
1632 &(sc->port.old_nig_stats.egress_mac_pkt1_lo), 2);
1635 /* function stats */
1636 for (i = 0; i < sc->num_queues; i++) {
1637 memset(&sc->fp[i].old_tclient, 0, sizeof(sc->fp[i].old_tclient));
1638 memset(&sc->fp[i].old_uclient, 0, sizeof(sc->fp[i].old_uclient));
1639 memset(&sc->fp[i].old_xclient, 0, sizeof(sc->fp[i].old_xclient));
1640 if (sc->stats_init) {
1641 memset(&sc->fp[i].eth_q_stats, 0,
1642 sizeof(sc->fp[i].eth_q_stats));
1643 memset(&sc->fp[i].eth_q_stats_old, 0,
1644 sizeof(sc->fp[i].eth_q_stats_old));
1648 /* prepare statistics ramrod data */
1649 bxe_prep_fw_stats_req(sc);
1651 sc->ifnet->if_data.ifi_ipackets = 0;
1652 sc->ifnet->if_data.ifi_opackets = 0;
1653 sc->ifnet->if_data.ifi_ibytes = 0;
1654 sc->ifnet->if_data.ifi_obytes = 0;
1655 sc->ifnet->if_data.ifi_ierrors = 0;
1656 sc->ifnet->if_data.ifi_oerrors = 0;
1657 sc->ifnet->if_data.ifi_imcasts = 0;
1658 sc->ifnet->if_data.ifi_collisions = 0;
1660 if (sc->stats_init) {
1661 memset(&sc->net_stats_old, 0, sizeof(sc->net_stats_old));
1662 memset(&sc->fw_stats_old, 0, sizeof(sc->fw_stats_old));
1663 memset(&sc->eth_stats_old, 0, sizeof(sc->eth_stats_old));
1664 memset(&sc->eth_stats, 0, sizeof(sc->eth_stats));
1665 memset(&sc->func_stats, 0, sizeof(sc->func_stats));
1667 /* Clean SP from previous statistics */
1669 memset(BXE_SP(sc, func_stats), 0, sizeof(struct host_func_stats));
1670 bxe_func_stats_init(sc);
1671 bxe_hw_stats_post(sc);
1676 sc->stats_state = STATS_STATE_DISABLED;
1678 if (sc->port.pmf && sc->port.port_stx) {
1679 bxe_port_stats_base_init(sc);
1682 /* mark the end of statistics initializiation */
1683 sc->stats_init = FALSE;
1687 bxe_save_statistics(struct bxe_softc *sc)
1691 /* save queue statistics */
1692 for (i = 0; i < sc->num_queues; i++) {
1693 struct bxe_fastpath *fp = &sc->fp[i];
1694 struct bxe_eth_q_stats *qstats = &fp->eth_q_stats;
1695 struct bxe_eth_q_stats_old *qstats_old = &fp->eth_q_stats_old;
1697 UPDATE_QSTAT_OLD(total_unicast_bytes_received_hi);
1698 UPDATE_QSTAT_OLD(total_unicast_bytes_received_lo);
1699 UPDATE_QSTAT_OLD(total_broadcast_bytes_received_hi);
1700 UPDATE_QSTAT_OLD(total_broadcast_bytes_received_lo);
1701 UPDATE_QSTAT_OLD(total_multicast_bytes_received_hi);
1702 UPDATE_QSTAT_OLD(total_multicast_bytes_received_lo);
1703 UPDATE_QSTAT_OLD(total_unicast_bytes_transmitted_hi);
1704 UPDATE_QSTAT_OLD(total_unicast_bytes_transmitted_lo);
1705 UPDATE_QSTAT_OLD(total_broadcast_bytes_transmitted_hi);
1706 UPDATE_QSTAT_OLD(total_broadcast_bytes_transmitted_lo);
1707 UPDATE_QSTAT_OLD(total_multicast_bytes_transmitted_hi);
1708 UPDATE_QSTAT_OLD(total_multicast_bytes_transmitted_lo);
1709 UPDATE_QSTAT_OLD(total_tpa_bytes_hi);
1710 UPDATE_QSTAT_OLD(total_tpa_bytes_lo);
1713 /* save net_device_stats statistics */
1714 sc->net_stats_old.rx_dropped = sc->ifnet->if_data.ifi_iqdrops;
1716 /* store port firmware statistics */
1718 struct bxe_eth_stats *estats = &sc->eth_stats;
1719 struct bxe_fw_port_stats_old *fwstats = &sc->fw_stats_old;
1720 struct host_port_stats *pstats = BXE_SP(sc, port_stats);
1722 fwstats->pfc_frames_rx_hi = pstats->pfc_frames_rx_hi;
1723 fwstats->pfc_frames_rx_lo = pstats->pfc_frames_rx_lo;
1724 fwstats->pfc_frames_tx_hi = pstats->pfc_frames_tx_hi;
1725 fwstats->pfc_frames_tx_lo = pstats->pfc_frames_tx_lo;
1728 UPDATE_FW_STAT_OLD(mac_filter_discard);
1729 UPDATE_FW_STAT_OLD(mf_tag_discard);
1730 UPDATE_FW_STAT_OLD(brb_truncate_discard);
1731 UPDATE_FW_STAT_OLD(mac_discard);
1737 bxe_afex_collect_stats(struct bxe_softc *sc,
1738 void *void_afex_stats,
1739 uint32_t stats_type)
1742 struct afex_stats *afex_stats = (struct afex_stats *)void_afex_stats;
1743 struct bxe_eth_stats *estats = &sc->eth_stats;
1745 memset(afex_stats, 0, sizeof(struct afex_stats));
1747 for (i = 0; i < sc->num_queues; i++) {
1748 struct bxe_eth_q_stats *qstats = &sc->fp[i].eth_q_stats;
1750 ADD_64(afex_stats->rx_unicast_bytes_hi,
1751 qstats->total_unicast_bytes_received_hi,
1752 afex_stats->rx_unicast_bytes_lo,
1753 qstats->total_unicast_bytes_received_lo);
1755 ADD_64(afex_stats->rx_broadcast_bytes_hi,
1756 qstats->total_broadcast_bytes_received_hi,
1757 afex_stats->rx_broadcast_bytes_lo,
1758 qstats->total_broadcast_bytes_received_lo);
1760 ADD_64(afex_stats->rx_multicast_bytes_hi,
1761 qstats->total_multicast_bytes_received_hi,
1762 afex_stats->rx_multicast_bytes_lo,
1763 qstats->total_multicast_bytes_received_lo);
1765 ADD_64(afex_stats->rx_unicast_frames_hi,
1766 qstats->total_unicast_packets_received_hi,
1767 afex_stats->rx_unicast_frames_lo,
1768 qstats->total_unicast_packets_received_lo);
1770 ADD_64(afex_stats->rx_broadcast_frames_hi,
1771 qstats->total_broadcast_packets_received_hi,
1772 afex_stats->rx_broadcast_frames_lo,
1773 qstats->total_broadcast_packets_received_lo);
1775 ADD_64(afex_stats->rx_multicast_frames_hi,
1776 qstats->total_multicast_packets_received_hi,
1777 afex_stats->rx_multicast_frames_lo,
1778 qstats->total_multicast_packets_received_lo);
1781 * sum to rx_frames_discarded all discarded
1782 * packets due to size, ttl0 and checksum
1784 ADD_64(afex_stats->rx_frames_discarded_hi,
1785 qstats->total_packets_received_checksum_discarded_hi,
1786 afex_stats->rx_frames_discarded_lo,
1787 qstats->total_packets_received_checksum_discarded_lo);
1789 ADD_64(afex_stats->rx_frames_discarded_hi,
1790 qstats->total_packets_received_ttl0_discarded_hi,
1791 afex_stats->rx_frames_discarded_lo,
1792 qstats->total_packets_received_ttl0_discarded_lo);
1794 ADD_64(afex_stats->rx_frames_discarded_hi,
1795 qstats->etherstatsoverrsizepkts_hi,
1796 afex_stats->rx_frames_discarded_lo,
1797 qstats->etherstatsoverrsizepkts_lo);
1799 ADD_64(afex_stats->rx_frames_dropped_hi,
1800 qstats->no_buff_discard_hi,
1801 afex_stats->rx_frames_dropped_lo,
1802 qstats->no_buff_discard_lo);
1804 ADD_64(afex_stats->tx_unicast_bytes_hi,
1805 qstats->total_unicast_bytes_transmitted_hi,
1806 afex_stats->tx_unicast_bytes_lo,
1807 qstats->total_unicast_bytes_transmitted_lo);
1809 ADD_64(afex_stats->tx_broadcast_bytes_hi,
1810 qstats->total_broadcast_bytes_transmitted_hi,
1811 afex_stats->tx_broadcast_bytes_lo,
1812 qstats->total_broadcast_bytes_transmitted_lo);
1814 ADD_64(afex_stats->tx_multicast_bytes_hi,
1815 qstats->total_multicast_bytes_transmitted_hi,
1816 afex_stats->tx_multicast_bytes_lo,
1817 qstats->total_multicast_bytes_transmitted_lo);
1819 ADD_64(afex_stats->tx_unicast_frames_hi,
1820 qstats->total_unicast_packets_transmitted_hi,
1821 afex_stats->tx_unicast_frames_lo,
1822 qstats->total_unicast_packets_transmitted_lo);
1824 ADD_64(afex_stats->tx_broadcast_frames_hi,
1825 qstats->total_broadcast_packets_transmitted_hi,
1826 afex_stats->tx_broadcast_frames_lo,
1827 qstats->total_broadcast_packets_transmitted_lo);
1829 ADD_64(afex_stats->tx_multicast_frames_hi,
1830 qstats->total_multicast_packets_transmitted_hi,
1831 afex_stats->tx_multicast_frames_lo,
1832 qstats->total_multicast_packets_transmitted_lo);
1834 ADD_64(afex_stats->tx_frames_dropped_hi,
1835 qstats->total_transmitted_dropped_packets_error_hi,
1836 afex_stats->tx_frames_dropped_lo,
1837 qstats->total_transmitted_dropped_packets_error_lo);
1841 * If port stats are requested, add them to the PMF
1842 * stats, as anyway they will be accumulated by the
1843 * MCP before sent to the switch
1845 if ((sc->port.pmf) && (stats_type == VICSTATST_UIF_INDEX)) {
1846 ADD_64(afex_stats->rx_frames_dropped_hi,
1848 afex_stats->rx_frames_dropped_lo,
1849 estats->mac_filter_discard);
1850 ADD_64(afex_stats->rx_frames_dropped_hi,
1852 afex_stats->rx_frames_dropped_lo,
1853 estats->brb_truncate_discard);
1854 ADD_64(afex_stats->rx_frames_discarded_hi,
1856 afex_stats->rx_frames_discarded_lo,
1857 estats->mac_discard);