14ad79e13SYuval Mintz /* bnx2x_stats.c: QLogic Everest network driver.
2adfc5217SJeff Kirsher *
3247fa82bSYuval Mintz * Copyright (c) 2007-2013 Broadcom Corporation
44ad79e13SYuval Mintz * Copyright (c) 2014 QLogic Corporation
54ad79e13SYuval Mintz * All rights reserved
6adfc5217SJeff Kirsher *
7adfc5217SJeff Kirsher * This program is free software; you can redistribute it and/or modify
8adfc5217SJeff Kirsher * it under the terms of the GNU General Public License as published by
9adfc5217SJeff Kirsher * the Free Software Foundation.
10adfc5217SJeff Kirsher *
1108f6dd89SAriel Elior * Maintained by: Ariel Elior <ariel.elior@qlogic.com>
12adfc5217SJeff Kirsher * Written by: Eliezer Tamir
13adfc5217SJeff Kirsher * Based on code from Michael Chan's bnx2 driver
14adfc5217SJeff Kirsher * UDP CSUM errata workaround by Arik Gendelman
15adfc5217SJeff Kirsher * Slowpath and fastpath rework by Vladislav Zolotarov
16adfc5217SJeff Kirsher * Statistics and Link management by Yitchak Gertner
17adfc5217SJeff Kirsher *
18adfc5217SJeff Kirsher */
19f1deab50SJoe Perches
20f1deab50SJoe Perches #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
21f1deab50SJoe Perches
22adfc5217SJeff Kirsher #include "bnx2x_stats.h"
23adfc5217SJeff Kirsher #include "bnx2x_cmn.h"
2467c431a5SAriel Elior #include "bnx2x_sriov.h"
25adfc5217SJeff Kirsher
26cdf711f2SSudarsana Reddy Kalluru extern const u32 dmae_reg_go_c[];
27cdf711f2SSudarsana Reddy Kalluru
28adfc5217SJeff Kirsher /* Statistics */
29adfc5217SJeff Kirsher
30adfc5217SJeff Kirsher /*
31adfc5217SJeff Kirsher * General service functions
32adfc5217SJeff Kirsher */
33adfc5217SJeff Kirsher
bnx2x_hilo(u32 * hiref)34adfc5217SJeff Kirsher static inline long bnx2x_hilo(u32 *hiref)
35adfc5217SJeff Kirsher {
36adfc5217SJeff Kirsher u32 lo = *(hiref + 1);
37adfc5217SJeff Kirsher #if (BITS_PER_LONG == 64)
38adfc5217SJeff Kirsher u32 hi = *hiref;
39adfc5217SJeff Kirsher
40adfc5217SJeff Kirsher return HILO_U64(hi, lo);
41adfc5217SJeff Kirsher #else
42adfc5217SJeff Kirsher return lo;
43adfc5217SJeff Kirsher #endif
44adfc5217SJeff Kirsher }
45adfc5217SJeff Kirsher
bnx2x_get_port_stats_dma_len(struct bnx2x * bp)4608e9acc2SYuval Mintz static inline u16 bnx2x_get_port_stats_dma_len(struct bnx2x *bp)
471d187b34SBarak Witkowski {
4808e9acc2SYuval Mintz u16 res = 0;
491d187b34SBarak Witkowski
5008e9acc2SYuval Mintz /* 'newest' convention - shmem2 cotains the size of the port stats */
5108e9acc2SYuval Mintz if (SHMEM2_HAS(bp, sizeof_port_stats)) {
5208e9acc2SYuval Mintz u32 size = SHMEM2_RD(bp, sizeof_port_stats);
5308e9acc2SYuval Mintz if (size)
5408e9acc2SYuval Mintz res = size;
551d187b34SBarak Witkowski
5608e9acc2SYuval Mintz /* prevent newer BC from causing buffer overflow */
5708e9acc2SYuval Mintz if (res > sizeof(struct host_port_stats))
5808e9acc2SYuval Mintz res = sizeof(struct host_port_stats);
5908e9acc2SYuval Mintz }
6008e9acc2SYuval Mintz
6108e9acc2SYuval Mintz /* Older convention - all BCs support the port stats' fields up until
6208e9acc2SYuval Mintz * the 'not_used' field
6308e9acc2SYuval Mintz */
6408e9acc2SYuval Mintz if (!res) {
6508e9acc2SYuval Mintz res = offsetof(struct host_port_stats, not_used) + 4;
6608e9acc2SYuval Mintz
6708e9acc2SYuval Mintz /* if PFC stats are supported by the MFW, DMA them as well */
6808e9acc2SYuval Mintz if (bp->flags & BC_SUPPORTS_PFC_STATS) {
6908e9acc2SYuval Mintz res += offsetof(struct host_port_stats,
7008e9acc2SYuval Mintz pfc_frames_rx_lo) -
7108e9acc2SYuval Mintz offsetof(struct host_port_stats,
7208e9acc2SYuval Mintz pfc_frames_tx_hi) + 4 ;
7308e9acc2SYuval Mintz }
7408e9acc2SYuval Mintz }
7508e9acc2SYuval Mintz
7608e9acc2SYuval Mintz res >>= 2;
7708e9acc2SYuval Mintz
7808e9acc2SYuval Mintz WARN_ON(res > 2 * DMAE_LEN32_RD_MAX);
791d187b34SBarak Witkowski return res;
801d187b34SBarak Witkowski }
811d187b34SBarak Witkowski
82adfc5217SJeff Kirsher /*
83adfc5217SJeff Kirsher * Init service functions
84adfc5217SJeff Kirsher */
85adfc5217SJeff Kirsher
bnx2x_dp_stats(struct bnx2x * bp)8667c431a5SAriel Elior static void bnx2x_dp_stats(struct bnx2x *bp)
8767c431a5SAriel Elior {
8867c431a5SAriel Elior int i;
8967c431a5SAriel Elior
9067c431a5SAriel Elior DP(BNX2X_MSG_STATS, "dumping stats:\n"
9167c431a5SAriel Elior "fw_stats_req\n"
9267c431a5SAriel Elior " hdr\n"
9367c431a5SAriel Elior " cmd_num %d\n"
9467c431a5SAriel Elior " reserved0 %d\n"
9567c431a5SAriel Elior " drv_stats_counter %d\n"
9667c431a5SAriel Elior " reserved1 %d\n"
9767c431a5SAriel Elior " stats_counters_addrs %x %x\n",
9867c431a5SAriel Elior bp->fw_stats_req->hdr.cmd_num,
9967c431a5SAriel Elior bp->fw_stats_req->hdr.reserved0,
10067c431a5SAriel Elior bp->fw_stats_req->hdr.drv_stats_counter,
10167c431a5SAriel Elior bp->fw_stats_req->hdr.reserved1,
10267c431a5SAriel Elior bp->fw_stats_req->hdr.stats_counters_addrs.hi,
10367c431a5SAriel Elior bp->fw_stats_req->hdr.stats_counters_addrs.lo);
10467c431a5SAriel Elior
10567c431a5SAriel Elior for (i = 0; i < bp->fw_stats_req->hdr.cmd_num; i++) {
10667c431a5SAriel Elior DP(BNX2X_MSG_STATS,
10767c431a5SAriel Elior "query[%d]\n"
10867c431a5SAriel Elior " kind %d\n"
10967c431a5SAriel Elior " index %d\n"
11067c431a5SAriel Elior " funcID %d\n"
11167c431a5SAriel Elior " reserved %d\n"
11267c431a5SAriel Elior " address %x %x\n",
11367c431a5SAriel Elior i, bp->fw_stats_req->query[i].kind,
11467c431a5SAriel Elior bp->fw_stats_req->query[i].index,
11567c431a5SAriel Elior bp->fw_stats_req->query[i].funcID,
11667c431a5SAriel Elior bp->fw_stats_req->query[i].reserved,
11767c431a5SAriel Elior bp->fw_stats_req->query[i].address.hi,
11867c431a5SAriel Elior bp->fw_stats_req->query[i].address.lo);
11967c431a5SAriel Elior }
12067c431a5SAriel Elior }
12167c431a5SAriel Elior
122adfc5217SJeff Kirsher /* Post the next statistics ramrod. Protect it with the spin in
123adfc5217SJeff Kirsher * order to ensure the strict order between statistics ramrods
124adfc5217SJeff Kirsher * (each ramrod has a sequence number passed in a
125adfc5217SJeff Kirsher * bp->fw_stats_req->hdr.drv_stats_counter and ramrods must be
126adfc5217SJeff Kirsher * sent in order).
127adfc5217SJeff Kirsher */
bnx2x_storm_stats_post(struct bnx2x * bp)128adfc5217SJeff Kirsher static void bnx2x_storm_stats_post(struct bnx2x *bp)
129adfc5217SJeff Kirsher {
130adfc5217SJeff Kirsher int rc;
131adfc5217SJeff Kirsher
132dff173deSYuval Mintz if (bp->stats_pending)
133adfc5217SJeff Kirsher return;
134adfc5217SJeff Kirsher
135adfc5217SJeff Kirsher bp->fw_stats_req->hdr.drv_stats_counter =
136adfc5217SJeff Kirsher cpu_to_le16(bp->stats_counter++);
137adfc5217SJeff Kirsher
13851c1a580SMerav Sicron DP(BNX2X_MSG_STATS, "Sending statistics ramrod %d\n",
1390c23ad37SYuval Mintz le16_to_cpu(bp->fw_stats_req->hdr.drv_stats_counter));
140adfc5217SJeff Kirsher
14167c431a5SAriel Elior /* adjust the ramrod to include VF queues statistics */
14267c431a5SAriel Elior bnx2x_iov_adjust_stats_req(bp);
14367c431a5SAriel Elior bnx2x_dp_stats(bp);
144adfc5217SJeff Kirsher
145adfc5217SJeff Kirsher /* send FW stats ramrod */
146adfc5217SJeff Kirsher rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_STAT_QUERY, 0,
147adfc5217SJeff Kirsher U64_HI(bp->fw_stats_req_mapping),
148adfc5217SJeff Kirsher U64_LO(bp->fw_stats_req_mapping),
149adfc5217SJeff Kirsher NONE_CONNECTION_TYPE);
150adfc5217SJeff Kirsher if (rc == 0)
151adfc5217SJeff Kirsher bp->stats_pending = 1;
152adfc5217SJeff Kirsher }
153adfc5217SJeff Kirsher
bnx2x_hw_stats_post(struct bnx2x * bp)154adfc5217SJeff Kirsher static void bnx2x_hw_stats_post(struct bnx2x *bp)
155adfc5217SJeff Kirsher {
156adfc5217SJeff Kirsher struct dmae_command *dmae = &bp->stats_dmae;
157adfc5217SJeff Kirsher u32 *stats_comp = bnx2x_sp(bp, stats_comp);
158adfc5217SJeff Kirsher
159adfc5217SJeff Kirsher *stats_comp = DMAE_COMP_VAL;
160adfc5217SJeff Kirsher if (CHIP_REV_IS_SLOW(bp))
161adfc5217SJeff Kirsher return;
162adfc5217SJeff Kirsher
163217aeb89SYuval Mintz /* Update MCP's statistics if possible */
164217aeb89SYuval Mintz if (bp->func_stx)
165217aeb89SYuval Mintz memcpy(bnx2x_sp(bp, func_stats), &bp->func_stats,
166217aeb89SYuval Mintz sizeof(bp->func_stats));
167217aeb89SYuval Mintz
168adfc5217SJeff Kirsher /* loader */
169adfc5217SJeff Kirsher if (bp->executer_idx) {
170adfc5217SJeff Kirsher int loader_idx = PMF_DMAE_C(bp);
171adfc5217SJeff Kirsher u32 opcode = bnx2x_dmae_opcode(bp, DMAE_SRC_PCI, DMAE_DST_GRC,
172adfc5217SJeff Kirsher true, DMAE_COMP_GRC);
173adfc5217SJeff Kirsher opcode = bnx2x_dmae_opcode_clr_src_reset(opcode);
174adfc5217SJeff Kirsher
175adfc5217SJeff Kirsher memset(dmae, 0, sizeof(struct dmae_command));
176adfc5217SJeff Kirsher dmae->opcode = opcode;
177adfc5217SJeff Kirsher dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, dmae[0]));
178adfc5217SJeff Kirsher dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, dmae[0]));
179adfc5217SJeff Kirsher dmae->dst_addr_lo = (DMAE_REG_CMD_MEM +
180adfc5217SJeff Kirsher sizeof(struct dmae_command) *
181adfc5217SJeff Kirsher (loader_idx + 1)) >> 2;
182adfc5217SJeff Kirsher dmae->dst_addr_hi = 0;
183adfc5217SJeff Kirsher dmae->len = sizeof(struct dmae_command) >> 2;
184adfc5217SJeff Kirsher if (CHIP_IS_E1(bp))
185adfc5217SJeff Kirsher dmae->len--;
186adfc5217SJeff Kirsher dmae->comp_addr_lo = dmae_reg_go_c[loader_idx + 1] >> 2;
187adfc5217SJeff Kirsher dmae->comp_addr_hi = 0;
188adfc5217SJeff Kirsher dmae->comp_val = 1;
189adfc5217SJeff Kirsher
190adfc5217SJeff Kirsher *stats_comp = 0;
191adfc5217SJeff Kirsher bnx2x_post_dmae(bp, dmae, loader_idx);
192adfc5217SJeff Kirsher
193adfc5217SJeff Kirsher } else if (bp->func_stx) {
194adfc5217SJeff Kirsher *stats_comp = 0;
19532316a46SAriel Elior bnx2x_issue_dmae_with_comp(bp, dmae, stats_comp);
196adfc5217SJeff Kirsher }
197adfc5217SJeff Kirsher }
198adfc5217SJeff Kirsher
bnx2x_stats_comp(struct bnx2x * bp)1990c23ad37SYuval Mintz static void bnx2x_stats_comp(struct bnx2x *bp)
200adfc5217SJeff Kirsher {
201adfc5217SJeff Kirsher u32 *stats_comp = bnx2x_sp(bp, stats_comp);
202adfc5217SJeff Kirsher int cnt = 10;
203adfc5217SJeff Kirsher
204adfc5217SJeff Kirsher might_sleep();
205adfc5217SJeff Kirsher while (*stats_comp != DMAE_COMP_VAL) {
206adfc5217SJeff Kirsher if (!cnt) {
207adfc5217SJeff Kirsher BNX2X_ERR("timeout waiting for stats finished\n");
208adfc5217SJeff Kirsher break;
209adfc5217SJeff Kirsher }
210adfc5217SJeff Kirsher cnt--;
2110926d499SYuval Mintz usleep_range(1000, 2000);
212adfc5217SJeff Kirsher }
213adfc5217SJeff Kirsher }
214adfc5217SJeff Kirsher
215adfc5217SJeff Kirsher /*
216adfc5217SJeff Kirsher * Statistics service functions
217adfc5217SJeff Kirsher */
218adfc5217SJeff Kirsher
219507393ebSDmitry Kravkov /* should be called under stats_sema */
bnx2x_stats_pmf_update(struct bnx2x * bp)220dff173deSYuval Mintz static void bnx2x_stats_pmf_update(struct bnx2x *bp)
221adfc5217SJeff Kirsher {
222adfc5217SJeff Kirsher struct dmae_command *dmae;
223adfc5217SJeff Kirsher u32 opcode;
224adfc5217SJeff Kirsher int loader_idx = PMF_DMAE_C(bp);
225adfc5217SJeff Kirsher u32 *stats_comp = bnx2x_sp(bp, stats_comp);
226adfc5217SJeff Kirsher
227adfc5217SJeff Kirsher /* sanity */
2281355b704SMintz Yuval if (!bp->port.pmf || !bp->port.port_stx) {
229adfc5217SJeff Kirsher BNX2X_ERR("BUG!\n");
230adfc5217SJeff Kirsher return;
231adfc5217SJeff Kirsher }
232adfc5217SJeff Kirsher
233adfc5217SJeff Kirsher bp->executer_idx = 0;
234adfc5217SJeff Kirsher
235adfc5217SJeff Kirsher opcode = bnx2x_dmae_opcode(bp, DMAE_SRC_GRC, DMAE_DST_PCI, false, 0);
236adfc5217SJeff Kirsher
237adfc5217SJeff Kirsher dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
238adfc5217SJeff Kirsher dmae->opcode = bnx2x_dmae_opcode_add_comp(opcode, DMAE_COMP_GRC);
239adfc5217SJeff Kirsher dmae->src_addr_lo = bp->port.port_stx >> 2;
240adfc5217SJeff Kirsher dmae->src_addr_hi = 0;
241adfc5217SJeff Kirsher dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, port_stats));
242adfc5217SJeff Kirsher dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, port_stats));
243adfc5217SJeff Kirsher dmae->len = DMAE_LEN32_RD_MAX;
244adfc5217SJeff Kirsher dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
245adfc5217SJeff Kirsher dmae->comp_addr_hi = 0;
246adfc5217SJeff Kirsher dmae->comp_val = 1;
247adfc5217SJeff Kirsher
248adfc5217SJeff Kirsher dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
249adfc5217SJeff Kirsher dmae->opcode = bnx2x_dmae_opcode_add_comp(opcode, DMAE_COMP_PCI);
250adfc5217SJeff Kirsher dmae->src_addr_lo = (bp->port.port_stx >> 2) + DMAE_LEN32_RD_MAX;
251adfc5217SJeff Kirsher dmae->src_addr_hi = 0;
252adfc5217SJeff Kirsher dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, port_stats) +
253adfc5217SJeff Kirsher DMAE_LEN32_RD_MAX * 4);
254adfc5217SJeff Kirsher dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, port_stats) +
255adfc5217SJeff Kirsher DMAE_LEN32_RD_MAX * 4);
2561d187b34SBarak Witkowski dmae->len = bnx2x_get_port_stats_dma_len(bp) - DMAE_LEN32_RD_MAX;
2571d187b34SBarak Witkowski
258adfc5217SJeff Kirsher dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, stats_comp));
259adfc5217SJeff Kirsher dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, stats_comp));
260adfc5217SJeff Kirsher dmae->comp_val = DMAE_COMP_VAL;
261adfc5217SJeff Kirsher
262adfc5217SJeff Kirsher *stats_comp = 0;
263adfc5217SJeff Kirsher bnx2x_hw_stats_post(bp);
264adfc5217SJeff Kirsher bnx2x_stats_comp(bp);
265adfc5217SJeff Kirsher }
266adfc5217SJeff Kirsher
bnx2x_port_stats_init(struct bnx2x * bp)267adfc5217SJeff Kirsher static void bnx2x_port_stats_init(struct bnx2x *bp)
268adfc5217SJeff Kirsher {
269adfc5217SJeff Kirsher struct dmae_command *dmae;
270adfc5217SJeff Kirsher int port = BP_PORT(bp);
271adfc5217SJeff Kirsher u32 opcode;
272adfc5217SJeff Kirsher int loader_idx = PMF_DMAE_C(bp);
273adfc5217SJeff Kirsher u32 mac_addr;
274adfc5217SJeff Kirsher u32 *stats_comp = bnx2x_sp(bp, stats_comp);
275adfc5217SJeff Kirsher
276adfc5217SJeff Kirsher /* sanity */
277adfc5217SJeff Kirsher if (!bp->link_vars.link_up || !bp->port.pmf) {
278adfc5217SJeff Kirsher BNX2X_ERR("BUG!\n");
279adfc5217SJeff Kirsher return;
280adfc5217SJeff Kirsher }
281adfc5217SJeff Kirsher
282adfc5217SJeff Kirsher bp->executer_idx = 0;
283adfc5217SJeff Kirsher
284adfc5217SJeff Kirsher /* MCP */
285adfc5217SJeff Kirsher opcode = bnx2x_dmae_opcode(bp, DMAE_SRC_PCI, DMAE_DST_GRC,
286adfc5217SJeff Kirsher true, DMAE_COMP_GRC);
287adfc5217SJeff Kirsher
288adfc5217SJeff Kirsher if (bp->port.port_stx) {
289adfc5217SJeff Kirsher
290adfc5217SJeff Kirsher dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
291adfc5217SJeff Kirsher dmae->opcode = opcode;
292adfc5217SJeff Kirsher dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, port_stats));
293adfc5217SJeff Kirsher dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, port_stats));
294adfc5217SJeff Kirsher dmae->dst_addr_lo = bp->port.port_stx >> 2;
295adfc5217SJeff Kirsher dmae->dst_addr_hi = 0;
2961d187b34SBarak Witkowski dmae->len = bnx2x_get_port_stats_dma_len(bp);
297adfc5217SJeff Kirsher dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
298adfc5217SJeff Kirsher dmae->comp_addr_hi = 0;
299adfc5217SJeff Kirsher dmae->comp_val = 1;
300adfc5217SJeff Kirsher }
301adfc5217SJeff Kirsher
302adfc5217SJeff Kirsher if (bp->func_stx) {
303adfc5217SJeff Kirsher
304adfc5217SJeff Kirsher dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
305adfc5217SJeff Kirsher dmae->opcode = opcode;
306adfc5217SJeff Kirsher dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, func_stats));
307adfc5217SJeff Kirsher dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, func_stats));
308adfc5217SJeff Kirsher dmae->dst_addr_lo = bp->func_stx >> 2;
309adfc5217SJeff Kirsher dmae->dst_addr_hi = 0;
310adfc5217SJeff Kirsher dmae->len = sizeof(struct host_func_stats) >> 2;
311adfc5217SJeff Kirsher dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
312adfc5217SJeff Kirsher dmae->comp_addr_hi = 0;
313adfc5217SJeff Kirsher dmae->comp_val = 1;
314adfc5217SJeff Kirsher }
315adfc5217SJeff Kirsher
316adfc5217SJeff Kirsher /* MAC */
317adfc5217SJeff Kirsher opcode = bnx2x_dmae_opcode(bp, DMAE_SRC_GRC, DMAE_DST_PCI,
318adfc5217SJeff Kirsher true, DMAE_COMP_GRC);
319adfc5217SJeff Kirsher
320adfc5217SJeff Kirsher /* EMAC is special */
321adfc5217SJeff Kirsher if (bp->link_vars.mac_type == MAC_TYPE_EMAC) {
322adfc5217SJeff Kirsher mac_addr = (port ? GRCBASE_EMAC1 : GRCBASE_EMAC0);
323adfc5217SJeff Kirsher
324adfc5217SJeff Kirsher /* EMAC_REG_EMAC_RX_STAT_AC (EMAC_REG_EMAC_RX_STAT_AC_COUNT)*/
325adfc5217SJeff Kirsher dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
326adfc5217SJeff Kirsher dmae->opcode = opcode;
327adfc5217SJeff Kirsher dmae->src_addr_lo = (mac_addr +
328adfc5217SJeff Kirsher EMAC_REG_EMAC_RX_STAT_AC) >> 2;
329adfc5217SJeff Kirsher dmae->src_addr_hi = 0;
330adfc5217SJeff Kirsher dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, mac_stats));
331adfc5217SJeff Kirsher dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, mac_stats));
332adfc5217SJeff Kirsher dmae->len = EMAC_REG_EMAC_RX_STAT_AC_COUNT;
333adfc5217SJeff Kirsher dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
334adfc5217SJeff Kirsher dmae->comp_addr_hi = 0;
335adfc5217SJeff Kirsher dmae->comp_val = 1;
336adfc5217SJeff Kirsher
337adfc5217SJeff Kirsher /* EMAC_REG_EMAC_RX_STAT_AC_28 */
338adfc5217SJeff Kirsher dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
339adfc5217SJeff Kirsher dmae->opcode = opcode;
340adfc5217SJeff Kirsher dmae->src_addr_lo = (mac_addr +
341adfc5217SJeff Kirsher EMAC_REG_EMAC_RX_STAT_AC_28) >> 2;
342adfc5217SJeff Kirsher dmae->src_addr_hi = 0;
343adfc5217SJeff Kirsher dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, mac_stats) +
344adfc5217SJeff Kirsher offsetof(struct emac_stats, rx_stat_falsecarriererrors));
345adfc5217SJeff Kirsher dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, mac_stats) +
346adfc5217SJeff Kirsher offsetof(struct emac_stats, rx_stat_falsecarriererrors));
347adfc5217SJeff Kirsher dmae->len = 1;
348adfc5217SJeff Kirsher dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
349adfc5217SJeff Kirsher dmae->comp_addr_hi = 0;
350adfc5217SJeff Kirsher dmae->comp_val = 1;
351adfc5217SJeff Kirsher
352adfc5217SJeff Kirsher /* EMAC_REG_EMAC_TX_STAT_AC (EMAC_REG_EMAC_TX_STAT_AC_COUNT)*/
353adfc5217SJeff Kirsher dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
354adfc5217SJeff Kirsher dmae->opcode = opcode;
355adfc5217SJeff Kirsher dmae->src_addr_lo = (mac_addr +
356adfc5217SJeff Kirsher EMAC_REG_EMAC_TX_STAT_AC) >> 2;
357adfc5217SJeff Kirsher dmae->src_addr_hi = 0;
358adfc5217SJeff Kirsher dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, mac_stats) +
359adfc5217SJeff Kirsher offsetof(struct emac_stats, tx_stat_ifhcoutoctets));
360adfc5217SJeff Kirsher dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, mac_stats) +
361adfc5217SJeff Kirsher offsetof(struct emac_stats, tx_stat_ifhcoutoctets));
362adfc5217SJeff Kirsher dmae->len = EMAC_REG_EMAC_TX_STAT_AC_COUNT;
363adfc5217SJeff Kirsher dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
364adfc5217SJeff Kirsher dmae->comp_addr_hi = 0;
365adfc5217SJeff Kirsher dmae->comp_val = 1;
366adfc5217SJeff Kirsher } else {
367adfc5217SJeff Kirsher u32 tx_src_addr_lo, rx_src_addr_lo;
368adfc5217SJeff Kirsher u16 rx_len, tx_len;
369adfc5217SJeff Kirsher
370adfc5217SJeff Kirsher /* configure the params according to MAC type */
371adfc5217SJeff Kirsher switch (bp->link_vars.mac_type) {
372adfc5217SJeff Kirsher case MAC_TYPE_BMAC:
373adfc5217SJeff Kirsher mac_addr = (port ? NIG_REG_INGRESS_BMAC1_MEM :
374adfc5217SJeff Kirsher NIG_REG_INGRESS_BMAC0_MEM);
375adfc5217SJeff Kirsher
376adfc5217SJeff Kirsher /* BIGMAC_REGISTER_TX_STAT_GTPKT ..
377adfc5217SJeff Kirsher BIGMAC_REGISTER_TX_STAT_GTBYT */
378adfc5217SJeff Kirsher if (CHIP_IS_E1x(bp)) {
379adfc5217SJeff Kirsher tx_src_addr_lo = (mac_addr +
380adfc5217SJeff Kirsher BIGMAC_REGISTER_TX_STAT_GTPKT) >> 2;
381adfc5217SJeff Kirsher tx_len = (8 + BIGMAC_REGISTER_TX_STAT_GTBYT -
382adfc5217SJeff Kirsher BIGMAC_REGISTER_TX_STAT_GTPKT) >> 2;
383adfc5217SJeff Kirsher rx_src_addr_lo = (mac_addr +
384adfc5217SJeff Kirsher BIGMAC_REGISTER_RX_STAT_GR64) >> 2;
385adfc5217SJeff Kirsher rx_len = (8 + BIGMAC_REGISTER_RX_STAT_GRIPJ -
386adfc5217SJeff Kirsher BIGMAC_REGISTER_RX_STAT_GR64) >> 2;
387adfc5217SJeff Kirsher } else {
388adfc5217SJeff Kirsher tx_src_addr_lo = (mac_addr +
389adfc5217SJeff Kirsher BIGMAC2_REGISTER_TX_STAT_GTPOK) >> 2;
390adfc5217SJeff Kirsher tx_len = (8 + BIGMAC2_REGISTER_TX_STAT_GTBYT -
391adfc5217SJeff Kirsher BIGMAC2_REGISTER_TX_STAT_GTPOK) >> 2;
392adfc5217SJeff Kirsher rx_src_addr_lo = (mac_addr +
393adfc5217SJeff Kirsher BIGMAC2_REGISTER_RX_STAT_GR64) >> 2;
394adfc5217SJeff Kirsher rx_len = (8 + BIGMAC2_REGISTER_RX_STAT_GRIPJ -
395adfc5217SJeff Kirsher BIGMAC2_REGISTER_RX_STAT_GR64) >> 2;
396adfc5217SJeff Kirsher }
397adfc5217SJeff Kirsher break;
398adfc5217SJeff Kirsher
399adfc5217SJeff Kirsher case MAC_TYPE_UMAC: /* handled by MSTAT */
400adfc5217SJeff Kirsher case MAC_TYPE_XMAC: /* handled by MSTAT */
401adfc5217SJeff Kirsher default:
402adfc5217SJeff Kirsher mac_addr = port ? GRCBASE_MSTAT1 : GRCBASE_MSTAT0;
403adfc5217SJeff Kirsher tx_src_addr_lo = (mac_addr +
404adfc5217SJeff Kirsher MSTAT_REG_TX_STAT_GTXPOK_LO) >> 2;
405adfc5217SJeff Kirsher rx_src_addr_lo = (mac_addr +
406adfc5217SJeff Kirsher MSTAT_REG_RX_STAT_GR64_LO) >> 2;
407adfc5217SJeff Kirsher tx_len = sizeof(bp->slowpath->
408adfc5217SJeff Kirsher mac_stats.mstat_stats.stats_tx) >> 2;
409adfc5217SJeff Kirsher rx_len = sizeof(bp->slowpath->
410adfc5217SJeff Kirsher mac_stats.mstat_stats.stats_rx) >> 2;
411adfc5217SJeff Kirsher break;
412adfc5217SJeff Kirsher }
413adfc5217SJeff Kirsher
414adfc5217SJeff Kirsher /* TX stats */
415adfc5217SJeff Kirsher dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
416adfc5217SJeff Kirsher dmae->opcode = opcode;
417adfc5217SJeff Kirsher dmae->src_addr_lo = tx_src_addr_lo;
418adfc5217SJeff Kirsher dmae->src_addr_hi = 0;
419adfc5217SJeff Kirsher dmae->len = tx_len;
420adfc5217SJeff Kirsher dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, mac_stats));
421adfc5217SJeff Kirsher dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, mac_stats));
422adfc5217SJeff Kirsher dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
423adfc5217SJeff Kirsher dmae->comp_addr_hi = 0;
424adfc5217SJeff Kirsher dmae->comp_val = 1;
425adfc5217SJeff Kirsher
426adfc5217SJeff Kirsher /* RX stats */
427adfc5217SJeff Kirsher dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
428adfc5217SJeff Kirsher dmae->opcode = opcode;
429adfc5217SJeff Kirsher dmae->src_addr_hi = 0;
430adfc5217SJeff Kirsher dmae->src_addr_lo = rx_src_addr_lo;
431adfc5217SJeff Kirsher dmae->dst_addr_lo =
432adfc5217SJeff Kirsher U64_LO(bnx2x_sp_mapping(bp, mac_stats) + (tx_len << 2));
433adfc5217SJeff Kirsher dmae->dst_addr_hi =
434adfc5217SJeff Kirsher U64_HI(bnx2x_sp_mapping(bp, mac_stats) + (tx_len << 2));
435adfc5217SJeff Kirsher dmae->len = rx_len;
436adfc5217SJeff Kirsher dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
437adfc5217SJeff Kirsher dmae->comp_addr_hi = 0;
438adfc5217SJeff Kirsher dmae->comp_val = 1;
439adfc5217SJeff Kirsher }
440adfc5217SJeff Kirsher
441adfc5217SJeff Kirsher /* NIG */
442adfc5217SJeff Kirsher if (!CHIP_IS_E3(bp)) {
443adfc5217SJeff Kirsher dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
444adfc5217SJeff Kirsher dmae->opcode = opcode;
445adfc5217SJeff Kirsher dmae->src_addr_lo = (port ? NIG_REG_STAT1_EGRESS_MAC_PKT0 :
446adfc5217SJeff Kirsher NIG_REG_STAT0_EGRESS_MAC_PKT0) >> 2;
447adfc5217SJeff Kirsher dmae->src_addr_hi = 0;
448adfc5217SJeff Kirsher dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, nig_stats) +
449adfc5217SJeff Kirsher offsetof(struct nig_stats, egress_mac_pkt0_lo));
450adfc5217SJeff Kirsher dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, nig_stats) +
451adfc5217SJeff Kirsher offsetof(struct nig_stats, egress_mac_pkt0_lo));
452adfc5217SJeff Kirsher dmae->len = (2*sizeof(u32)) >> 2;
453adfc5217SJeff Kirsher dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
454adfc5217SJeff Kirsher dmae->comp_addr_hi = 0;
455adfc5217SJeff Kirsher dmae->comp_val = 1;
456adfc5217SJeff Kirsher
457adfc5217SJeff Kirsher dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
458adfc5217SJeff Kirsher dmae->opcode = opcode;
459adfc5217SJeff Kirsher dmae->src_addr_lo = (port ? NIG_REG_STAT1_EGRESS_MAC_PKT1 :
460adfc5217SJeff Kirsher NIG_REG_STAT0_EGRESS_MAC_PKT1) >> 2;
461adfc5217SJeff Kirsher dmae->src_addr_hi = 0;
462adfc5217SJeff Kirsher dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, nig_stats) +
463adfc5217SJeff Kirsher offsetof(struct nig_stats, egress_mac_pkt1_lo));
464adfc5217SJeff Kirsher dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, nig_stats) +
465adfc5217SJeff Kirsher offsetof(struct nig_stats, egress_mac_pkt1_lo));
466adfc5217SJeff Kirsher dmae->len = (2*sizeof(u32)) >> 2;
467adfc5217SJeff Kirsher dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
468adfc5217SJeff Kirsher dmae->comp_addr_hi = 0;
469adfc5217SJeff Kirsher dmae->comp_val = 1;
470adfc5217SJeff Kirsher }
471adfc5217SJeff Kirsher
472adfc5217SJeff Kirsher dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
473adfc5217SJeff Kirsher dmae->opcode = bnx2x_dmae_opcode(bp, DMAE_SRC_GRC, DMAE_DST_PCI,
474adfc5217SJeff Kirsher true, DMAE_COMP_PCI);
475adfc5217SJeff Kirsher dmae->src_addr_lo = (port ? NIG_REG_STAT1_BRB_DISCARD :
476adfc5217SJeff Kirsher NIG_REG_STAT0_BRB_DISCARD) >> 2;
477adfc5217SJeff Kirsher dmae->src_addr_hi = 0;
478adfc5217SJeff Kirsher dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, nig_stats));
479adfc5217SJeff Kirsher dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, nig_stats));
480adfc5217SJeff Kirsher dmae->len = (sizeof(struct nig_stats) - 4*sizeof(u32)) >> 2;
481adfc5217SJeff Kirsher
482adfc5217SJeff Kirsher dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, stats_comp));
483adfc5217SJeff Kirsher dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, stats_comp));
484adfc5217SJeff Kirsher dmae->comp_val = DMAE_COMP_VAL;
485adfc5217SJeff Kirsher
486adfc5217SJeff Kirsher *stats_comp = 0;
487adfc5217SJeff Kirsher }
488adfc5217SJeff Kirsher
bnx2x_func_stats_init(struct bnx2x * bp)489adfc5217SJeff Kirsher static void bnx2x_func_stats_init(struct bnx2x *bp)
490adfc5217SJeff Kirsher {
491adfc5217SJeff Kirsher struct dmae_command *dmae = &bp->stats_dmae;
492adfc5217SJeff Kirsher u32 *stats_comp = bnx2x_sp(bp, stats_comp);
493adfc5217SJeff Kirsher
494adfc5217SJeff Kirsher /* sanity */
495adfc5217SJeff Kirsher if (!bp->func_stx) {
496adfc5217SJeff Kirsher BNX2X_ERR("BUG!\n");
497adfc5217SJeff Kirsher return;
498adfc5217SJeff Kirsher }
499adfc5217SJeff Kirsher
500adfc5217SJeff Kirsher bp->executer_idx = 0;
501adfc5217SJeff Kirsher memset(dmae, 0, sizeof(struct dmae_command));
502adfc5217SJeff Kirsher
503adfc5217SJeff Kirsher dmae->opcode = bnx2x_dmae_opcode(bp, DMAE_SRC_PCI, DMAE_DST_GRC,
504adfc5217SJeff Kirsher true, DMAE_COMP_PCI);
505adfc5217SJeff Kirsher dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, func_stats));
506adfc5217SJeff Kirsher dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, func_stats));
507adfc5217SJeff Kirsher dmae->dst_addr_lo = bp->func_stx >> 2;
508adfc5217SJeff Kirsher dmae->dst_addr_hi = 0;
509adfc5217SJeff Kirsher dmae->len = sizeof(struct host_func_stats) >> 2;
510adfc5217SJeff Kirsher dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, stats_comp));
511adfc5217SJeff Kirsher dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, stats_comp));
512adfc5217SJeff Kirsher dmae->comp_val = DMAE_COMP_VAL;
513adfc5217SJeff Kirsher
514adfc5217SJeff Kirsher *stats_comp = 0;
515adfc5217SJeff Kirsher }
516adfc5217SJeff Kirsher
517507393ebSDmitry Kravkov /* should be called under stats_sema */
bnx2x_stats_start(struct bnx2x * bp)518dff173deSYuval Mintz static void bnx2x_stats_start(struct bnx2x *bp)
519adfc5217SJeff Kirsher {
520c730b170SAriel Elior if (IS_PF(bp)) {
521adfc5217SJeff Kirsher if (bp->port.pmf)
522adfc5217SJeff Kirsher bnx2x_port_stats_init(bp);
523adfc5217SJeff Kirsher
524adfc5217SJeff Kirsher else if (bp->func_stx)
525adfc5217SJeff Kirsher bnx2x_func_stats_init(bp);
526adfc5217SJeff Kirsher
527adfc5217SJeff Kirsher bnx2x_hw_stats_post(bp);
528adfc5217SJeff Kirsher bnx2x_storm_stats_post(bp);
529c730b170SAriel Elior }
530adfc5217SJeff Kirsher }
531adfc5217SJeff Kirsher
bnx2x_stats_pmf_start(struct bnx2x * bp)532adfc5217SJeff Kirsher static void bnx2x_stats_pmf_start(struct bnx2x *bp)
533adfc5217SJeff Kirsher {
534adfc5217SJeff Kirsher bnx2x_stats_comp(bp);
535dff173deSYuval Mintz bnx2x_stats_pmf_update(bp);
536dff173deSYuval Mintz bnx2x_stats_start(bp);
537adfc5217SJeff Kirsher }
538adfc5217SJeff Kirsher
bnx2x_stats_restart(struct bnx2x * bp)539adfc5217SJeff Kirsher static void bnx2x_stats_restart(struct bnx2x *bp)
540adfc5217SJeff Kirsher {
54167c431a5SAriel Elior /* vfs travel through here as part of the statistics FSM, but no action
54267c431a5SAriel Elior * is required
54367c431a5SAriel Elior */
54467c431a5SAriel Elior if (IS_VF(bp))
54567c431a5SAriel Elior return;
546dff173deSYuval Mintz
547adfc5217SJeff Kirsher bnx2x_stats_comp(bp);
548dff173deSYuval Mintz bnx2x_stats_start(bp);
549adfc5217SJeff Kirsher }
550adfc5217SJeff Kirsher
bnx2x_bmac_stats_update(struct bnx2x * bp)551adfc5217SJeff Kirsher static void bnx2x_bmac_stats_update(struct bnx2x *bp)
552adfc5217SJeff Kirsher {
553adfc5217SJeff Kirsher struct host_port_stats *pstats = bnx2x_sp(bp, port_stats);
554adfc5217SJeff Kirsher struct bnx2x_eth_stats *estats = &bp->eth_stats;
555adfc5217SJeff Kirsher struct {
556adfc5217SJeff Kirsher u32 lo;
557adfc5217SJeff Kirsher u32 hi;
558adfc5217SJeff Kirsher } diff;
559adfc5217SJeff Kirsher
560adfc5217SJeff Kirsher if (CHIP_IS_E1x(bp)) {
561adfc5217SJeff Kirsher struct bmac1_stats *new = bnx2x_sp(bp, mac_stats.bmac1_stats);
562adfc5217SJeff Kirsher
563adfc5217SJeff Kirsher /* the macros below will use "bmac1_stats" type */
564adfc5217SJeff Kirsher UPDATE_STAT64(rx_stat_grerb, rx_stat_ifhcinbadoctets);
565adfc5217SJeff Kirsher UPDATE_STAT64(rx_stat_grfcs, rx_stat_dot3statsfcserrors);
566adfc5217SJeff Kirsher UPDATE_STAT64(rx_stat_grund, rx_stat_etherstatsundersizepkts);
567adfc5217SJeff Kirsher UPDATE_STAT64(rx_stat_grovr, rx_stat_dot3statsframestoolong);
568adfc5217SJeff Kirsher UPDATE_STAT64(rx_stat_grfrg, rx_stat_etherstatsfragments);
569adfc5217SJeff Kirsher UPDATE_STAT64(rx_stat_grjbr, rx_stat_etherstatsjabbers);
570adfc5217SJeff Kirsher UPDATE_STAT64(rx_stat_grxcf, rx_stat_maccontrolframesreceived);
571adfc5217SJeff Kirsher UPDATE_STAT64(rx_stat_grxpf, rx_stat_xoffstateentered);
572adfc5217SJeff Kirsher UPDATE_STAT64(rx_stat_grxpf, rx_stat_mac_xpf);
573adfc5217SJeff Kirsher
574adfc5217SJeff Kirsher UPDATE_STAT64(tx_stat_gtxpf, tx_stat_outxoffsent);
575adfc5217SJeff Kirsher UPDATE_STAT64(tx_stat_gtxpf, tx_stat_flowcontroldone);
576adfc5217SJeff Kirsher UPDATE_STAT64(tx_stat_gt64, tx_stat_etherstatspkts64octets);
577adfc5217SJeff Kirsher UPDATE_STAT64(tx_stat_gt127,
578adfc5217SJeff Kirsher tx_stat_etherstatspkts65octetsto127octets);
579adfc5217SJeff Kirsher UPDATE_STAT64(tx_stat_gt255,
580adfc5217SJeff Kirsher tx_stat_etherstatspkts128octetsto255octets);
581adfc5217SJeff Kirsher UPDATE_STAT64(tx_stat_gt511,
582adfc5217SJeff Kirsher tx_stat_etherstatspkts256octetsto511octets);
583adfc5217SJeff Kirsher UPDATE_STAT64(tx_stat_gt1023,
584adfc5217SJeff Kirsher tx_stat_etherstatspkts512octetsto1023octets);
585adfc5217SJeff Kirsher UPDATE_STAT64(tx_stat_gt1518,
586adfc5217SJeff Kirsher tx_stat_etherstatspkts1024octetsto1522octets);
587adfc5217SJeff Kirsher UPDATE_STAT64(tx_stat_gt2047, tx_stat_mac_2047);
588adfc5217SJeff Kirsher UPDATE_STAT64(tx_stat_gt4095, tx_stat_mac_4095);
589adfc5217SJeff Kirsher UPDATE_STAT64(tx_stat_gt9216, tx_stat_mac_9216);
590adfc5217SJeff Kirsher UPDATE_STAT64(tx_stat_gt16383, tx_stat_mac_16383);
591adfc5217SJeff Kirsher UPDATE_STAT64(tx_stat_gterr,
592adfc5217SJeff Kirsher tx_stat_dot3statsinternalmactransmiterrors);
593adfc5217SJeff Kirsher UPDATE_STAT64(tx_stat_gtufl, tx_stat_mac_ufl);
594adfc5217SJeff Kirsher
595adfc5217SJeff Kirsher } else {
596adfc5217SJeff Kirsher struct bmac2_stats *new = bnx2x_sp(bp, mac_stats.bmac2_stats);
597adfc5217SJeff Kirsher
598adfc5217SJeff Kirsher /* the macros below will use "bmac2_stats" type */
599adfc5217SJeff Kirsher UPDATE_STAT64(rx_stat_grerb, rx_stat_ifhcinbadoctets);
600adfc5217SJeff Kirsher UPDATE_STAT64(rx_stat_grfcs, rx_stat_dot3statsfcserrors);
601adfc5217SJeff Kirsher UPDATE_STAT64(rx_stat_grund, rx_stat_etherstatsundersizepkts);
602adfc5217SJeff Kirsher UPDATE_STAT64(rx_stat_grovr, rx_stat_dot3statsframestoolong);
603adfc5217SJeff Kirsher UPDATE_STAT64(rx_stat_grfrg, rx_stat_etherstatsfragments);
604adfc5217SJeff Kirsher UPDATE_STAT64(rx_stat_grjbr, rx_stat_etherstatsjabbers);
605adfc5217SJeff Kirsher UPDATE_STAT64(rx_stat_grxcf, rx_stat_maccontrolframesreceived);
606adfc5217SJeff Kirsher UPDATE_STAT64(rx_stat_grxpf, rx_stat_xoffstateentered);
607adfc5217SJeff Kirsher UPDATE_STAT64(rx_stat_grxpf, rx_stat_mac_xpf);
608adfc5217SJeff Kirsher UPDATE_STAT64(tx_stat_gtxpf, tx_stat_outxoffsent);
609adfc5217SJeff Kirsher UPDATE_STAT64(tx_stat_gtxpf, tx_stat_flowcontroldone);
610adfc5217SJeff Kirsher UPDATE_STAT64(tx_stat_gt64, tx_stat_etherstatspkts64octets);
611adfc5217SJeff Kirsher UPDATE_STAT64(tx_stat_gt127,
612adfc5217SJeff Kirsher tx_stat_etherstatspkts65octetsto127octets);
613adfc5217SJeff Kirsher UPDATE_STAT64(tx_stat_gt255,
614adfc5217SJeff Kirsher tx_stat_etherstatspkts128octetsto255octets);
615adfc5217SJeff Kirsher UPDATE_STAT64(tx_stat_gt511,
616adfc5217SJeff Kirsher tx_stat_etherstatspkts256octetsto511octets);
617adfc5217SJeff Kirsher UPDATE_STAT64(tx_stat_gt1023,
618adfc5217SJeff Kirsher tx_stat_etherstatspkts512octetsto1023octets);
619adfc5217SJeff Kirsher UPDATE_STAT64(tx_stat_gt1518,
620adfc5217SJeff Kirsher tx_stat_etherstatspkts1024octetsto1522octets);
621adfc5217SJeff Kirsher UPDATE_STAT64(tx_stat_gt2047, tx_stat_mac_2047);
622adfc5217SJeff Kirsher UPDATE_STAT64(tx_stat_gt4095, tx_stat_mac_4095);
623adfc5217SJeff Kirsher UPDATE_STAT64(tx_stat_gt9216, tx_stat_mac_9216);
624adfc5217SJeff Kirsher UPDATE_STAT64(tx_stat_gt16383, tx_stat_mac_16383);
625adfc5217SJeff Kirsher UPDATE_STAT64(tx_stat_gterr,
626adfc5217SJeff Kirsher tx_stat_dot3statsinternalmactransmiterrors);
627adfc5217SJeff Kirsher UPDATE_STAT64(tx_stat_gtufl, tx_stat_mac_ufl);
6280e898dd7SBarak Witkowski
6290e898dd7SBarak Witkowski /* collect PFC stats */
6300e898dd7SBarak Witkowski pstats->pfc_frames_tx_hi = new->tx_stat_gtpp_hi;
6310e898dd7SBarak Witkowski pstats->pfc_frames_tx_lo = new->tx_stat_gtpp_lo;
6320e898dd7SBarak Witkowski
6330e898dd7SBarak Witkowski pstats->pfc_frames_rx_hi = new->rx_stat_grpp_hi;
6340e898dd7SBarak Witkowski pstats->pfc_frames_rx_lo = new->rx_stat_grpp_lo;
635adfc5217SJeff Kirsher }
636adfc5217SJeff Kirsher
637adfc5217SJeff Kirsher estats->pause_frames_received_hi =
638adfc5217SJeff Kirsher pstats->mac_stx[1].rx_stat_mac_xpf_hi;
639adfc5217SJeff Kirsher estats->pause_frames_received_lo =
640adfc5217SJeff Kirsher pstats->mac_stx[1].rx_stat_mac_xpf_lo;
641adfc5217SJeff Kirsher
642adfc5217SJeff Kirsher estats->pause_frames_sent_hi =
643adfc5217SJeff Kirsher pstats->mac_stx[1].tx_stat_outxoffsent_hi;
644adfc5217SJeff Kirsher estats->pause_frames_sent_lo =
645adfc5217SJeff Kirsher pstats->mac_stx[1].tx_stat_outxoffsent_lo;
6460e898dd7SBarak Witkowski
6470e898dd7SBarak Witkowski estats->pfc_frames_received_hi =
6480e898dd7SBarak Witkowski pstats->pfc_frames_rx_hi;
6490e898dd7SBarak Witkowski estats->pfc_frames_received_lo =
6500e898dd7SBarak Witkowski pstats->pfc_frames_rx_lo;
6510e898dd7SBarak Witkowski estats->pfc_frames_sent_hi =
6520e898dd7SBarak Witkowski pstats->pfc_frames_tx_hi;
6530e898dd7SBarak Witkowski estats->pfc_frames_sent_lo =
6540e898dd7SBarak Witkowski pstats->pfc_frames_tx_lo;
655adfc5217SJeff Kirsher }
656adfc5217SJeff Kirsher
bnx2x_mstat_stats_update(struct bnx2x * bp)657adfc5217SJeff Kirsher static void bnx2x_mstat_stats_update(struct bnx2x *bp)
658adfc5217SJeff Kirsher {
659adfc5217SJeff Kirsher struct host_port_stats *pstats = bnx2x_sp(bp, port_stats);
660adfc5217SJeff Kirsher struct bnx2x_eth_stats *estats = &bp->eth_stats;
661adfc5217SJeff Kirsher
662adfc5217SJeff Kirsher struct mstat_stats *new = bnx2x_sp(bp, mac_stats.mstat_stats);
663adfc5217SJeff Kirsher
664adfc5217SJeff Kirsher ADD_STAT64(stats_rx.rx_grerb, rx_stat_ifhcinbadoctets);
665adfc5217SJeff Kirsher ADD_STAT64(stats_rx.rx_grfcs, rx_stat_dot3statsfcserrors);
666adfc5217SJeff Kirsher ADD_STAT64(stats_rx.rx_grund, rx_stat_etherstatsundersizepkts);
667adfc5217SJeff Kirsher ADD_STAT64(stats_rx.rx_grovr, rx_stat_dot3statsframestoolong);
668adfc5217SJeff Kirsher ADD_STAT64(stats_rx.rx_grfrg, rx_stat_etherstatsfragments);
669adfc5217SJeff Kirsher ADD_STAT64(stats_rx.rx_grxcf, rx_stat_maccontrolframesreceived);
670adfc5217SJeff Kirsher ADD_STAT64(stats_rx.rx_grxpf, rx_stat_xoffstateentered);
671adfc5217SJeff Kirsher ADD_STAT64(stats_rx.rx_grxpf, rx_stat_mac_xpf);
672adfc5217SJeff Kirsher ADD_STAT64(stats_tx.tx_gtxpf, tx_stat_outxoffsent);
673adfc5217SJeff Kirsher ADD_STAT64(stats_tx.tx_gtxpf, tx_stat_flowcontroldone);
674adfc5217SJeff Kirsher
6750e898dd7SBarak Witkowski /* collect pfc stats */
6760e898dd7SBarak Witkowski ADD_64(pstats->pfc_frames_tx_hi, new->stats_tx.tx_gtxpp_hi,
6770e898dd7SBarak Witkowski pstats->pfc_frames_tx_lo, new->stats_tx.tx_gtxpp_lo);
6780e898dd7SBarak Witkowski ADD_64(pstats->pfc_frames_rx_hi, new->stats_rx.rx_grxpp_hi,
6790e898dd7SBarak Witkowski pstats->pfc_frames_rx_lo, new->stats_rx.rx_grxpp_lo);
680adfc5217SJeff Kirsher
681adfc5217SJeff Kirsher ADD_STAT64(stats_tx.tx_gt64, tx_stat_etherstatspkts64octets);
682adfc5217SJeff Kirsher ADD_STAT64(stats_tx.tx_gt127,
683adfc5217SJeff Kirsher tx_stat_etherstatspkts65octetsto127octets);
684adfc5217SJeff Kirsher ADD_STAT64(stats_tx.tx_gt255,
685adfc5217SJeff Kirsher tx_stat_etherstatspkts128octetsto255octets);
686adfc5217SJeff Kirsher ADD_STAT64(stats_tx.tx_gt511,
687adfc5217SJeff Kirsher tx_stat_etherstatspkts256octetsto511octets);
688adfc5217SJeff Kirsher ADD_STAT64(stats_tx.tx_gt1023,
689adfc5217SJeff Kirsher tx_stat_etherstatspkts512octetsto1023octets);
690adfc5217SJeff Kirsher ADD_STAT64(stats_tx.tx_gt1518,
691adfc5217SJeff Kirsher tx_stat_etherstatspkts1024octetsto1522octets);
692adfc5217SJeff Kirsher ADD_STAT64(stats_tx.tx_gt2047, tx_stat_mac_2047);
693adfc5217SJeff Kirsher
694adfc5217SJeff Kirsher ADD_STAT64(stats_tx.tx_gt4095, tx_stat_mac_4095);
695adfc5217SJeff Kirsher ADD_STAT64(stats_tx.tx_gt9216, tx_stat_mac_9216);
696adfc5217SJeff Kirsher ADD_STAT64(stats_tx.tx_gt16383, tx_stat_mac_16383);
697adfc5217SJeff Kirsher
698adfc5217SJeff Kirsher ADD_STAT64(stats_tx.tx_gterr,
699adfc5217SJeff Kirsher tx_stat_dot3statsinternalmactransmiterrors);
700adfc5217SJeff Kirsher ADD_STAT64(stats_tx.tx_gtufl, tx_stat_mac_ufl);
701adfc5217SJeff Kirsher
7021355b704SMintz Yuval estats->etherstatspkts1024octetsto1522octets_hi =
7031355b704SMintz Yuval pstats->mac_stx[1].tx_stat_etherstatspkts1024octetsto1522octets_hi;
7041355b704SMintz Yuval estats->etherstatspkts1024octetsto1522octets_lo =
7051355b704SMintz Yuval pstats->mac_stx[1].tx_stat_etherstatspkts1024octetsto1522octets_lo;
7061355b704SMintz Yuval
7071355b704SMintz Yuval estats->etherstatspktsover1522octets_hi =
7081355b704SMintz Yuval pstats->mac_stx[1].tx_stat_mac_2047_hi;
7091355b704SMintz Yuval estats->etherstatspktsover1522octets_lo =
7101355b704SMintz Yuval pstats->mac_stx[1].tx_stat_mac_2047_lo;
711adfc5217SJeff Kirsher
712adfc5217SJeff Kirsher ADD_64(estats->etherstatspktsover1522octets_hi,
7131355b704SMintz Yuval pstats->mac_stx[1].tx_stat_mac_4095_hi,
714adfc5217SJeff Kirsher estats->etherstatspktsover1522octets_lo,
7151355b704SMintz Yuval pstats->mac_stx[1].tx_stat_mac_4095_lo);
716adfc5217SJeff Kirsher
717adfc5217SJeff Kirsher ADD_64(estats->etherstatspktsover1522octets_hi,
7181355b704SMintz Yuval pstats->mac_stx[1].tx_stat_mac_9216_hi,
719adfc5217SJeff Kirsher estats->etherstatspktsover1522octets_lo,
7201355b704SMintz Yuval pstats->mac_stx[1].tx_stat_mac_9216_lo);
721adfc5217SJeff Kirsher
722adfc5217SJeff Kirsher ADD_64(estats->etherstatspktsover1522octets_hi,
7231355b704SMintz Yuval pstats->mac_stx[1].tx_stat_mac_16383_hi,
724adfc5217SJeff Kirsher estats->etherstatspktsover1522octets_lo,
7251355b704SMintz Yuval pstats->mac_stx[1].tx_stat_mac_16383_lo);
726adfc5217SJeff Kirsher
727adfc5217SJeff Kirsher estats->pause_frames_received_hi =
728adfc5217SJeff Kirsher pstats->mac_stx[1].rx_stat_mac_xpf_hi;
729adfc5217SJeff Kirsher estats->pause_frames_received_lo =
730adfc5217SJeff Kirsher pstats->mac_stx[1].rx_stat_mac_xpf_lo;
731adfc5217SJeff Kirsher
732adfc5217SJeff Kirsher estats->pause_frames_sent_hi =
733adfc5217SJeff Kirsher pstats->mac_stx[1].tx_stat_outxoffsent_hi;
734adfc5217SJeff Kirsher estats->pause_frames_sent_lo =
735adfc5217SJeff Kirsher pstats->mac_stx[1].tx_stat_outxoffsent_lo;
7360e898dd7SBarak Witkowski
7370e898dd7SBarak Witkowski estats->pfc_frames_received_hi =
7380e898dd7SBarak Witkowski pstats->pfc_frames_rx_hi;
7390e898dd7SBarak Witkowski estats->pfc_frames_received_lo =
7400e898dd7SBarak Witkowski pstats->pfc_frames_rx_lo;
7410e898dd7SBarak Witkowski estats->pfc_frames_sent_hi =
7420e898dd7SBarak Witkowski pstats->pfc_frames_tx_hi;
7430e898dd7SBarak Witkowski estats->pfc_frames_sent_lo =
7440e898dd7SBarak Witkowski pstats->pfc_frames_tx_lo;
745adfc5217SJeff Kirsher }
746adfc5217SJeff Kirsher
bnx2x_emac_stats_update(struct bnx2x * bp)747adfc5217SJeff Kirsher static void bnx2x_emac_stats_update(struct bnx2x *bp)
748adfc5217SJeff Kirsher {
749adfc5217SJeff Kirsher struct emac_stats *new = bnx2x_sp(bp, mac_stats.emac_stats);
750adfc5217SJeff Kirsher struct host_port_stats *pstats = bnx2x_sp(bp, port_stats);
751adfc5217SJeff Kirsher struct bnx2x_eth_stats *estats = &bp->eth_stats;
752adfc5217SJeff Kirsher
753adfc5217SJeff Kirsher UPDATE_EXTEND_STAT(rx_stat_ifhcinbadoctets);
754adfc5217SJeff Kirsher UPDATE_EXTEND_STAT(tx_stat_ifhcoutbadoctets);
755adfc5217SJeff Kirsher UPDATE_EXTEND_STAT(rx_stat_dot3statsfcserrors);
756adfc5217SJeff Kirsher UPDATE_EXTEND_STAT(rx_stat_dot3statsalignmenterrors);
757adfc5217SJeff Kirsher UPDATE_EXTEND_STAT(rx_stat_dot3statscarriersenseerrors);
758adfc5217SJeff Kirsher UPDATE_EXTEND_STAT(rx_stat_falsecarriererrors);
759adfc5217SJeff Kirsher UPDATE_EXTEND_STAT(rx_stat_etherstatsundersizepkts);
760adfc5217SJeff Kirsher UPDATE_EXTEND_STAT(rx_stat_dot3statsframestoolong);
761adfc5217SJeff Kirsher UPDATE_EXTEND_STAT(rx_stat_etherstatsfragments);
762adfc5217SJeff Kirsher UPDATE_EXTEND_STAT(rx_stat_etherstatsjabbers);
763adfc5217SJeff Kirsher UPDATE_EXTEND_STAT(rx_stat_maccontrolframesreceived);
764adfc5217SJeff Kirsher UPDATE_EXTEND_STAT(rx_stat_xoffstateentered);
765adfc5217SJeff Kirsher UPDATE_EXTEND_STAT(rx_stat_xonpauseframesreceived);
766adfc5217SJeff Kirsher UPDATE_EXTEND_STAT(rx_stat_xoffpauseframesreceived);
767adfc5217SJeff Kirsher UPDATE_EXTEND_STAT(tx_stat_outxonsent);
768adfc5217SJeff Kirsher UPDATE_EXTEND_STAT(tx_stat_outxoffsent);
769adfc5217SJeff Kirsher UPDATE_EXTEND_STAT(tx_stat_flowcontroldone);
770adfc5217SJeff Kirsher UPDATE_EXTEND_STAT(tx_stat_etherstatscollisions);
771adfc5217SJeff Kirsher UPDATE_EXTEND_STAT(tx_stat_dot3statssinglecollisionframes);
772adfc5217SJeff Kirsher UPDATE_EXTEND_STAT(tx_stat_dot3statsmultiplecollisionframes);
773adfc5217SJeff Kirsher UPDATE_EXTEND_STAT(tx_stat_dot3statsdeferredtransmissions);
774adfc5217SJeff Kirsher UPDATE_EXTEND_STAT(tx_stat_dot3statsexcessivecollisions);
775adfc5217SJeff Kirsher UPDATE_EXTEND_STAT(tx_stat_dot3statslatecollisions);
776adfc5217SJeff Kirsher UPDATE_EXTEND_STAT(tx_stat_etherstatspkts64octets);
777adfc5217SJeff Kirsher UPDATE_EXTEND_STAT(tx_stat_etherstatspkts65octetsto127octets);
778adfc5217SJeff Kirsher UPDATE_EXTEND_STAT(tx_stat_etherstatspkts128octetsto255octets);
779adfc5217SJeff Kirsher UPDATE_EXTEND_STAT(tx_stat_etherstatspkts256octetsto511octets);
780adfc5217SJeff Kirsher UPDATE_EXTEND_STAT(tx_stat_etherstatspkts512octetsto1023octets);
781adfc5217SJeff Kirsher UPDATE_EXTEND_STAT(tx_stat_etherstatspkts1024octetsto1522octets);
782adfc5217SJeff Kirsher UPDATE_EXTEND_STAT(tx_stat_etherstatspktsover1522octets);
783adfc5217SJeff Kirsher UPDATE_EXTEND_STAT(tx_stat_dot3statsinternalmactransmiterrors);
784adfc5217SJeff Kirsher
785adfc5217SJeff Kirsher estats->pause_frames_received_hi =
786adfc5217SJeff Kirsher pstats->mac_stx[1].rx_stat_xonpauseframesreceived_hi;
787adfc5217SJeff Kirsher estats->pause_frames_received_lo =
788adfc5217SJeff Kirsher pstats->mac_stx[1].rx_stat_xonpauseframesreceived_lo;
789adfc5217SJeff Kirsher ADD_64(estats->pause_frames_received_hi,
790adfc5217SJeff Kirsher pstats->mac_stx[1].rx_stat_xoffpauseframesreceived_hi,
791adfc5217SJeff Kirsher estats->pause_frames_received_lo,
792adfc5217SJeff Kirsher pstats->mac_stx[1].rx_stat_xoffpauseframesreceived_lo);
793adfc5217SJeff Kirsher
794adfc5217SJeff Kirsher estats->pause_frames_sent_hi =
795adfc5217SJeff Kirsher pstats->mac_stx[1].tx_stat_outxonsent_hi;
796adfc5217SJeff Kirsher estats->pause_frames_sent_lo =
797adfc5217SJeff Kirsher pstats->mac_stx[1].tx_stat_outxonsent_lo;
798adfc5217SJeff Kirsher ADD_64(estats->pause_frames_sent_hi,
799adfc5217SJeff Kirsher pstats->mac_stx[1].tx_stat_outxoffsent_hi,
800adfc5217SJeff Kirsher estats->pause_frames_sent_lo,
801adfc5217SJeff Kirsher pstats->mac_stx[1].tx_stat_outxoffsent_lo);
802adfc5217SJeff Kirsher }
803adfc5217SJeff Kirsher
bnx2x_hw_stats_update(struct bnx2x * bp)804adfc5217SJeff Kirsher static int bnx2x_hw_stats_update(struct bnx2x *bp)
805adfc5217SJeff Kirsher {
806adfc5217SJeff Kirsher struct nig_stats *new = bnx2x_sp(bp, nig_stats);
807adfc5217SJeff Kirsher struct nig_stats *old = &(bp->port.old_nig_stats);
808adfc5217SJeff Kirsher struct host_port_stats *pstats = bnx2x_sp(bp, port_stats);
809adfc5217SJeff Kirsher struct bnx2x_eth_stats *estats = &bp->eth_stats;
810adfc5217SJeff Kirsher struct {
811adfc5217SJeff Kirsher u32 lo;
812adfc5217SJeff Kirsher u32 hi;
813adfc5217SJeff Kirsher } diff;
814adfc5217SJeff Kirsher
815adfc5217SJeff Kirsher switch (bp->link_vars.mac_type) {
816adfc5217SJeff Kirsher case MAC_TYPE_BMAC:
817adfc5217SJeff Kirsher bnx2x_bmac_stats_update(bp);
818adfc5217SJeff Kirsher break;
819adfc5217SJeff Kirsher
820adfc5217SJeff Kirsher case MAC_TYPE_EMAC:
821adfc5217SJeff Kirsher bnx2x_emac_stats_update(bp);
822adfc5217SJeff Kirsher break;
823adfc5217SJeff Kirsher
824adfc5217SJeff Kirsher case MAC_TYPE_UMAC:
825adfc5217SJeff Kirsher case MAC_TYPE_XMAC:
826adfc5217SJeff Kirsher bnx2x_mstat_stats_update(bp);
827adfc5217SJeff Kirsher break;
828adfc5217SJeff Kirsher
829adfc5217SJeff Kirsher case MAC_TYPE_NONE: /* unreached */
8308decf868SDavid S. Miller DP(BNX2X_MSG_STATS,
8318decf868SDavid S. Miller "stats updated by DMAE but no MAC active\n");
832adfc5217SJeff Kirsher return -1;
833adfc5217SJeff Kirsher
834adfc5217SJeff Kirsher default: /* unreached */
835adfc5217SJeff Kirsher BNX2X_ERR("Unknown MAC type\n");
836adfc5217SJeff Kirsher }
837adfc5217SJeff Kirsher
838adfc5217SJeff Kirsher ADD_EXTEND_64(pstats->brb_drop_hi, pstats->brb_drop_lo,
839adfc5217SJeff Kirsher new->brb_discard - old->brb_discard);
840adfc5217SJeff Kirsher ADD_EXTEND_64(estats->brb_truncate_hi, estats->brb_truncate_lo,
841adfc5217SJeff Kirsher new->brb_truncate - old->brb_truncate);
842adfc5217SJeff Kirsher
843adfc5217SJeff Kirsher if (!CHIP_IS_E3(bp)) {
844adfc5217SJeff Kirsher UPDATE_STAT64_NIG(egress_mac_pkt0,
845adfc5217SJeff Kirsher etherstatspkts1024octetsto1522octets);
846adfc5217SJeff Kirsher UPDATE_STAT64_NIG(egress_mac_pkt1,
847adfc5217SJeff Kirsher etherstatspktsover1522octets);
848adfc5217SJeff Kirsher }
849adfc5217SJeff Kirsher
850adfc5217SJeff Kirsher memcpy(old, new, sizeof(struct nig_stats));
851adfc5217SJeff Kirsher
852*29fd0ec6SKees Cook BUILD_BUG_ON(sizeof(estats->shared) != sizeof(pstats->mac_stx[1]));
853*29fd0ec6SKees Cook memcpy(&(estats->shared), &(pstats->mac_stx[1]),
854adfc5217SJeff Kirsher sizeof(struct mac_stx));
855adfc5217SJeff Kirsher estats->brb_drop_hi = pstats->brb_drop_hi;
856adfc5217SJeff Kirsher estats->brb_drop_lo = pstats->brb_drop_lo;
857adfc5217SJeff Kirsher
8580e898dd7SBarak Witkowski pstats->host_port_stats_counter++;
859adfc5217SJeff Kirsher
860c20cd5d7SYuval Mintz if (CHIP_IS_E3(bp)) {
861c20cd5d7SYuval Mintz u32 lpi_reg = BP_PORT(bp) ? MISC_REG_CPMU_LP_SM_ENT_CNT_P1
862c20cd5d7SYuval Mintz : MISC_REG_CPMU_LP_SM_ENT_CNT_P0;
863c20cd5d7SYuval Mintz estats->eee_tx_lpi += REG_RD(bp, lpi_reg);
864c20cd5d7SYuval Mintz }
865c8c60d88SYuval Mintz
866adfc5217SJeff Kirsher if (!BP_NOMCP(bp)) {
867adfc5217SJeff Kirsher u32 nig_timer_max =
868adfc5217SJeff Kirsher SHMEM_RD(bp, port_mb[BP_PORT(bp)].stat_nig_timer);
869adfc5217SJeff Kirsher if (nig_timer_max != estats->nig_timer_max) {
870adfc5217SJeff Kirsher estats->nig_timer_max = nig_timer_max;
871adfc5217SJeff Kirsher BNX2X_ERR("NIG timer max (%u)\n",
872adfc5217SJeff Kirsher estats->nig_timer_max);
873adfc5217SJeff Kirsher }
874adfc5217SJeff Kirsher }
875adfc5217SJeff Kirsher
876adfc5217SJeff Kirsher return 0;
877adfc5217SJeff Kirsher }
878adfc5217SJeff Kirsher
bnx2x_storm_stats_validate_counters(struct bnx2x * bp)87967c431a5SAriel Elior static int bnx2x_storm_stats_validate_counters(struct bnx2x *bp)
880adfc5217SJeff Kirsher {
881adfc5217SJeff Kirsher struct stats_counter *counters = &bp->fw_stats_data->storm_counters;
882adfc5217SJeff Kirsher u16 cur_stats_counter;
883adfc5217SJeff Kirsher /* Make sure we use the value of the counter
884adfc5217SJeff Kirsher * used for sending the last stats ramrod.
885adfc5217SJeff Kirsher */
886adfc5217SJeff Kirsher cur_stats_counter = bp->stats_counter - 1;
887adfc5217SJeff Kirsher
888adfc5217SJeff Kirsher /* are storm stats valid? */
889adfc5217SJeff Kirsher if (le16_to_cpu(counters->xstats_counter) != cur_stats_counter) {
89051c1a580SMerav Sicron DP(BNX2X_MSG_STATS,
89151c1a580SMerav Sicron "stats not updated by xstorm xstorm counter (0x%x) != stats_counter (0x%x)\n",
892adfc5217SJeff Kirsher le16_to_cpu(counters->xstats_counter), bp->stats_counter);
893adfc5217SJeff Kirsher return -EAGAIN;
894adfc5217SJeff Kirsher }
895adfc5217SJeff Kirsher
896adfc5217SJeff Kirsher if (le16_to_cpu(counters->ustats_counter) != cur_stats_counter) {
89751c1a580SMerav Sicron DP(BNX2X_MSG_STATS,
89851c1a580SMerav Sicron "stats not updated by ustorm ustorm counter (0x%x) != stats_counter (0x%x)\n",
899adfc5217SJeff Kirsher le16_to_cpu(counters->ustats_counter), bp->stats_counter);
900adfc5217SJeff Kirsher return -EAGAIN;
901adfc5217SJeff Kirsher }
902adfc5217SJeff Kirsher
903adfc5217SJeff Kirsher if (le16_to_cpu(counters->cstats_counter) != cur_stats_counter) {
90451c1a580SMerav Sicron DP(BNX2X_MSG_STATS,
90551c1a580SMerav Sicron "stats not updated by cstorm cstorm counter (0x%x) != stats_counter (0x%x)\n",
906adfc5217SJeff Kirsher le16_to_cpu(counters->cstats_counter), bp->stats_counter);
907adfc5217SJeff Kirsher return -EAGAIN;
908adfc5217SJeff Kirsher }
909adfc5217SJeff Kirsher
910adfc5217SJeff Kirsher if (le16_to_cpu(counters->tstats_counter) != cur_stats_counter) {
91151c1a580SMerav Sicron DP(BNX2X_MSG_STATS,
91251c1a580SMerav Sicron "stats not updated by tstorm tstorm counter (0x%x) != stats_counter (0x%x)\n",
913adfc5217SJeff Kirsher le16_to_cpu(counters->tstats_counter), bp->stats_counter);
914adfc5217SJeff Kirsher return -EAGAIN;
915adfc5217SJeff Kirsher }
91667c431a5SAriel Elior return 0;
91767c431a5SAriel Elior }
91867c431a5SAriel Elior
bnx2x_storm_stats_update(struct bnx2x * bp)91967c431a5SAriel Elior static int bnx2x_storm_stats_update(struct bnx2x *bp)
92067c431a5SAriel Elior {
92167c431a5SAriel Elior struct tstorm_per_port_stats *tport =
92267c431a5SAriel Elior &bp->fw_stats_data->port.tstorm_port_statistics;
92367c431a5SAriel Elior struct tstorm_per_pf_stats *tfunc =
92467c431a5SAriel Elior &bp->fw_stats_data->pf.tstorm_pf_statistics;
92567c431a5SAriel Elior struct host_func_stats *fstats = &bp->func_stats;
92667c431a5SAriel Elior struct bnx2x_eth_stats *estats = &bp->eth_stats;
92767c431a5SAriel Elior struct bnx2x_eth_stats_old *estats_old = &bp->eth_stats_old;
92867c431a5SAriel Elior int i;
92967c431a5SAriel Elior
93067c431a5SAriel Elior /* vfs stat counter is managed by pf */
93167c431a5SAriel Elior if (IS_PF(bp) && bnx2x_storm_stats_validate_counters(bp))
93267c431a5SAriel Elior return -EAGAIN;
933adfc5217SJeff Kirsher
934adfc5217SJeff Kirsher estats->error_bytes_received_hi = 0;
935adfc5217SJeff Kirsher estats->error_bytes_received_lo = 0;
936adfc5217SJeff Kirsher
937adfc5217SJeff Kirsher for_each_eth_queue(bp, i) {
938adfc5217SJeff Kirsher struct bnx2x_fastpath *fp = &bp->fp[i];
939adfc5217SJeff Kirsher struct tstorm_per_queue_stats *tclient =
940adfc5217SJeff Kirsher &bp->fw_stats_data->queue_stats[i].
941adfc5217SJeff Kirsher tstorm_queue_statistics;
94215192a8cSBarak Witkowski struct tstorm_per_queue_stats *old_tclient =
94315192a8cSBarak Witkowski &bnx2x_fp_stats(bp, fp)->old_tclient;
944adfc5217SJeff Kirsher struct ustorm_per_queue_stats *uclient =
945adfc5217SJeff Kirsher &bp->fw_stats_data->queue_stats[i].
946adfc5217SJeff Kirsher ustorm_queue_statistics;
94715192a8cSBarak Witkowski struct ustorm_per_queue_stats *old_uclient =
94815192a8cSBarak Witkowski &bnx2x_fp_stats(bp, fp)->old_uclient;
949adfc5217SJeff Kirsher struct xstorm_per_queue_stats *xclient =
950adfc5217SJeff Kirsher &bp->fw_stats_data->queue_stats[i].
951adfc5217SJeff Kirsher xstorm_queue_statistics;
95215192a8cSBarak Witkowski struct xstorm_per_queue_stats *old_xclient =
95315192a8cSBarak Witkowski &bnx2x_fp_stats(bp, fp)->old_xclient;
95415192a8cSBarak Witkowski struct bnx2x_eth_q_stats *qstats =
95515192a8cSBarak Witkowski &bnx2x_fp_stats(bp, fp)->eth_q_stats;
95615192a8cSBarak Witkowski struct bnx2x_eth_q_stats_old *qstats_old =
95715192a8cSBarak Witkowski &bnx2x_fp_stats(bp, fp)->eth_q_stats_old;
9581355b704SMintz Yuval
959adfc5217SJeff Kirsher u32 diff;
960adfc5217SJeff Kirsher
96151c1a580SMerav Sicron DP(BNX2X_MSG_STATS, "queue[%d]: ucast_sent 0x%x, bcast_sent 0x%x mcast_sent 0x%x\n",
962adfc5217SJeff Kirsher i, xclient->ucast_pkts_sent,
963adfc5217SJeff Kirsher xclient->bcast_pkts_sent, xclient->mcast_pkts_sent);
964adfc5217SJeff Kirsher
965adfc5217SJeff Kirsher DP(BNX2X_MSG_STATS, "---------------\n");
966adfc5217SJeff Kirsher
9671355b704SMintz Yuval UPDATE_QSTAT(tclient->rcv_bcast_bytes,
9681355b704SMintz Yuval total_broadcast_bytes_received);
9691355b704SMintz Yuval UPDATE_QSTAT(tclient->rcv_mcast_bytes,
9701355b704SMintz Yuval total_multicast_bytes_received);
9711355b704SMintz Yuval UPDATE_QSTAT(tclient->rcv_ucast_bytes,
9721355b704SMintz Yuval total_unicast_bytes_received);
973adfc5217SJeff Kirsher
974adfc5217SJeff Kirsher /*
975adfc5217SJeff Kirsher * sum to total_bytes_received all
976adfc5217SJeff Kirsher * unicast/multicast/broadcast
977adfc5217SJeff Kirsher */
978adfc5217SJeff Kirsher qstats->total_bytes_received_hi =
979adfc5217SJeff Kirsher qstats->total_broadcast_bytes_received_hi;
980adfc5217SJeff Kirsher qstats->total_bytes_received_lo =
981adfc5217SJeff Kirsher qstats->total_broadcast_bytes_received_lo;
982adfc5217SJeff Kirsher
983adfc5217SJeff Kirsher ADD_64(qstats->total_bytes_received_hi,
984adfc5217SJeff Kirsher qstats->total_multicast_bytes_received_hi,
985adfc5217SJeff Kirsher qstats->total_bytes_received_lo,
986adfc5217SJeff Kirsher qstats->total_multicast_bytes_received_lo);
987adfc5217SJeff Kirsher
988adfc5217SJeff Kirsher ADD_64(qstats->total_bytes_received_hi,
989adfc5217SJeff Kirsher qstats->total_unicast_bytes_received_hi,
990adfc5217SJeff Kirsher qstats->total_bytes_received_lo,
991adfc5217SJeff Kirsher qstats->total_unicast_bytes_received_lo);
992adfc5217SJeff Kirsher
993adfc5217SJeff Kirsher qstats->valid_bytes_received_hi =
994adfc5217SJeff Kirsher qstats->total_bytes_received_hi;
995adfc5217SJeff Kirsher qstats->valid_bytes_received_lo =
996adfc5217SJeff Kirsher qstats->total_bytes_received_lo;
997adfc5217SJeff Kirsher
998adfc5217SJeff Kirsher UPDATE_EXTEND_TSTAT(rcv_ucast_pkts,
999adfc5217SJeff Kirsher total_unicast_packets_received);
1000adfc5217SJeff Kirsher UPDATE_EXTEND_TSTAT(rcv_mcast_pkts,
1001adfc5217SJeff Kirsher total_multicast_packets_received);
1002adfc5217SJeff Kirsher UPDATE_EXTEND_TSTAT(rcv_bcast_pkts,
1003adfc5217SJeff Kirsher total_broadcast_packets_received);
10041355b704SMintz Yuval UPDATE_EXTEND_E_TSTAT(pkts_too_big_discard,
100586564c3fSYuval Mintz etherstatsoverrsizepkts, 32);
100686564c3fSYuval Mintz UPDATE_EXTEND_E_TSTAT(no_buff_discard, no_buff_discard, 16);
1007adfc5217SJeff Kirsher
1008adfc5217SJeff Kirsher SUB_EXTEND_USTAT(ucast_no_buff_pkts,
1009adfc5217SJeff Kirsher total_unicast_packets_received);
1010adfc5217SJeff Kirsher SUB_EXTEND_USTAT(mcast_no_buff_pkts,
1011adfc5217SJeff Kirsher total_multicast_packets_received);
1012adfc5217SJeff Kirsher SUB_EXTEND_USTAT(bcast_no_buff_pkts,
1013adfc5217SJeff Kirsher total_broadcast_packets_received);
10141355b704SMintz Yuval UPDATE_EXTEND_E_USTAT(ucast_no_buff_pkts, no_buff_discard);
10151355b704SMintz Yuval UPDATE_EXTEND_E_USTAT(mcast_no_buff_pkts, no_buff_discard);
10161355b704SMintz Yuval UPDATE_EXTEND_E_USTAT(bcast_no_buff_pkts, no_buff_discard);
1017adfc5217SJeff Kirsher
10181355b704SMintz Yuval UPDATE_QSTAT(xclient->bcast_bytes_sent,
10191355b704SMintz Yuval total_broadcast_bytes_transmitted);
10201355b704SMintz Yuval UPDATE_QSTAT(xclient->mcast_bytes_sent,
10211355b704SMintz Yuval total_multicast_bytes_transmitted);
10221355b704SMintz Yuval UPDATE_QSTAT(xclient->ucast_bytes_sent,
10231355b704SMintz Yuval total_unicast_bytes_transmitted);
1024adfc5217SJeff Kirsher
1025adfc5217SJeff Kirsher /*
1026adfc5217SJeff Kirsher * sum to total_bytes_transmitted all
1027adfc5217SJeff Kirsher * unicast/multicast/broadcast
1028adfc5217SJeff Kirsher */
1029adfc5217SJeff Kirsher qstats->total_bytes_transmitted_hi =
1030adfc5217SJeff Kirsher qstats->total_unicast_bytes_transmitted_hi;
1031adfc5217SJeff Kirsher qstats->total_bytes_transmitted_lo =
1032adfc5217SJeff Kirsher qstats->total_unicast_bytes_transmitted_lo;
1033adfc5217SJeff Kirsher
1034adfc5217SJeff Kirsher ADD_64(qstats->total_bytes_transmitted_hi,
1035adfc5217SJeff Kirsher qstats->total_broadcast_bytes_transmitted_hi,
1036adfc5217SJeff Kirsher qstats->total_bytes_transmitted_lo,
1037adfc5217SJeff Kirsher qstats->total_broadcast_bytes_transmitted_lo);
1038adfc5217SJeff Kirsher
1039adfc5217SJeff Kirsher ADD_64(qstats->total_bytes_transmitted_hi,
1040adfc5217SJeff Kirsher qstats->total_multicast_bytes_transmitted_hi,
1041adfc5217SJeff Kirsher qstats->total_bytes_transmitted_lo,
1042adfc5217SJeff Kirsher qstats->total_multicast_bytes_transmitted_lo);
1043adfc5217SJeff Kirsher
1044adfc5217SJeff Kirsher UPDATE_EXTEND_XSTAT(ucast_pkts_sent,
1045adfc5217SJeff Kirsher total_unicast_packets_transmitted);
1046adfc5217SJeff Kirsher UPDATE_EXTEND_XSTAT(mcast_pkts_sent,
1047adfc5217SJeff Kirsher total_multicast_packets_transmitted);
1048adfc5217SJeff Kirsher UPDATE_EXTEND_XSTAT(bcast_pkts_sent,
1049adfc5217SJeff Kirsher total_broadcast_packets_transmitted);
1050adfc5217SJeff Kirsher
1051adfc5217SJeff Kirsher UPDATE_EXTEND_TSTAT(checksum_discard,
1052adfc5217SJeff Kirsher total_packets_received_checksum_discarded);
1053adfc5217SJeff Kirsher UPDATE_EXTEND_TSTAT(ttl0_discard,
1054adfc5217SJeff Kirsher total_packets_received_ttl0_discarded);
1055adfc5217SJeff Kirsher
1056adfc5217SJeff Kirsher UPDATE_EXTEND_XSTAT(error_drop_pkts,
1057adfc5217SJeff Kirsher total_transmitted_dropped_packets_error);
1058adfc5217SJeff Kirsher
1059adfc5217SJeff Kirsher /* TPA aggregations completed */
10601355b704SMintz Yuval UPDATE_EXTEND_E_USTAT(coalesced_events, total_tpa_aggregations);
1061adfc5217SJeff Kirsher /* Number of network frames aggregated by TPA */
10621355b704SMintz Yuval UPDATE_EXTEND_E_USTAT(coalesced_pkts,
1063adfc5217SJeff Kirsher total_tpa_aggregated_frames);
1064adfc5217SJeff Kirsher /* Total number of bytes in completed TPA aggregations */
10651355b704SMintz Yuval UPDATE_QSTAT(uclient->coalesced_bytes, total_tpa_bytes);
1066adfc5217SJeff Kirsher
10671355b704SMintz Yuval UPDATE_ESTAT_QSTAT_64(total_tpa_bytes);
1068adfc5217SJeff Kirsher
10691355b704SMintz Yuval UPDATE_FSTAT_QSTAT(total_bytes_received);
10701355b704SMintz Yuval UPDATE_FSTAT_QSTAT(total_bytes_transmitted);
10711355b704SMintz Yuval UPDATE_FSTAT_QSTAT(total_unicast_packets_received);
10721355b704SMintz Yuval UPDATE_FSTAT_QSTAT(total_multicast_packets_received);
10731355b704SMintz Yuval UPDATE_FSTAT_QSTAT(total_broadcast_packets_received);
10741355b704SMintz Yuval UPDATE_FSTAT_QSTAT(total_unicast_packets_transmitted);
10751355b704SMintz Yuval UPDATE_FSTAT_QSTAT(total_multicast_packets_transmitted);
10761355b704SMintz Yuval UPDATE_FSTAT_QSTAT(total_broadcast_packets_transmitted);
10771355b704SMintz Yuval UPDATE_FSTAT_QSTAT(valid_bytes_received);
1078adfc5217SJeff Kirsher }
1079adfc5217SJeff Kirsher
10801355b704SMintz Yuval ADD_64(estats->total_bytes_received_hi,
1081adfc5217SJeff Kirsher estats->rx_stat_ifhcinbadoctets_hi,
10821355b704SMintz Yuval estats->total_bytes_received_lo,
1083adfc5217SJeff Kirsher estats->rx_stat_ifhcinbadoctets_lo);
1084adfc5217SJeff Kirsher
108586564c3fSYuval Mintz ADD_64_LE(estats->total_bytes_received_hi,
108686564c3fSYuval Mintz tfunc->rcv_error_bytes.hi,
10871355b704SMintz Yuval estats->total_bytes_received_lo,
108886564c3fSYuval Mintz tfunc->rcv_error_bytes.lo);
1089adfc5217SJeff Kirsher
109086564c3fSYuval Mintz ADD_64_LE(estats->error_bytes_received_hi,
109186564c3fSYuval Mintz tfunc->rcv_error_bytes.hi,
1092adfc5217SJeff Kirsher estats->error_bytes_received_lo,
109386564c3fSYuval Mintz tfunc->rcv_error_bytes.lo);
1094adfc5217SJeff Kirsher
10951355b704SMintz Yuval UPDATE_ESTAT(etherstatsoverrsizepkts, rx_stat_dot3statsframestoolong);
10961355b704SMintz Yuval
1097adfc5217SJeff Kirsher ADD_64(estats->error_bytes_received_hi,
1098adfc5217SJeff Kirsher estats->rx_stat_ifhcinbadoctets_hi,
1099adfc5217SJeff Kirsher estats->error_bytes_received_lo,
1100adfc5217SJeff Kirsher estats->rx_stat_ifhcinbadoctets_lo);
1101adfc5217SJeff Kirsher
1102adfc5217SJeff Kirsher if (bp->port.pmf) {
11031355b704SMintz Yuval struct bnx2x_fw_port_stats_old *fwstats = &bp->fw_stats_old;
11041355b704SMintz Yuval UPDATE_FW_STAT(mac_filter_discard);
11051355b704SMintz Yuval UPDATE_FW_STAT(mf_tag_discard);
11061355b704SMintz Yuval UPDATE_FW_STAT(brb_truncate_discard);
11071355b704SMintz Yuval UPDATE_FW_STAT(mac_discard);
1108adfc5217SJeff Kirsher }
1109adfc5217SJeff Kirsher
1110adfc5217SJeff Kirsher fstats->host_func_stats_start = ++fstats->host_func_stats_end;
1111adfc5217SJeff Kirsher
1112adfc5217SJeff Kirsher bp->stats_pending = 0;
1113adfc5217SJeff Kirsher
1114adfc5217SJeff Kirsher return 0;
1115adfc5217SJeff Kirsher }
1116adfc5217SJeff Kirsher
bnx2x_net_stats_update(struct bnx2x * bp)1117adfc5217SJeff Kirsher static void bnx2x_net_stats_update(struct bnx2x *bp)
1118adfc5217SJeff Kirsher {
1119adfc5217SJeff Kirsher struct bnx2x_eth_stats *estats = &bp->eth_stats;
1120adfc5217SJeff Kirsher struct net_device_stats *nstats = &bp->dev->stats;
1121adfc5217SJeff Kirsher unsigned long tmp;
1122adfc5217SJeff Kirsher int i;
1123adfc5217SJeff Kirsher
1124adfc5217SJeff Kirsher nstats->rx_packets =
1125adfc5217SJeff Kirsher bnx2x_hilo(&estats->total_unicast_packets_received_hi) +
1126adfc5217SJeff Kirsher bnx2x_hilo(&estats->total_multicast_packets_received_hi) +
1127adfc5217SJeff Kirsher bnx2x_hilo(&estats->total_broadcast_packets_received_hi);
1128adfc5217SJeff Kirsher
1129adfc5217SJeff Kirsher nstats->tx_packets =
1130adfc5217SJeff Kirsher bnx2x_hilo(&estats->total_unicast_packets_transmitted_hi) +
1131adfc5217SJeff Kirsher bnx2x_hilo(&estats->total_multicast_packets_transmitted_hi) +
1132adfc5217SJeff Kirsher bnx2x_hilo(&estats->total_broadcast_packets_transmitted_hi);
1133adfc5217SJeff Kirsher
1134adfc5217SJeff Kirsher nstats->rx_bytes = bnx2x_hilo(&estats->total_bytes_received_hi);
1135adfc5217SJeff Kirsher
1136adfc5217SJeff Kirsher nstats->tx_bytes = bnx2x_hilo(&estats->total_bytes_transmitted_hi);
1137adfc5217SJeff Kirsher
1138adfc5217SJeff Kirsher tmp = estats->mac_discard;
113915192a8cSBarak Witkowski for_each_rx_queue(bp, i) {
114015192a8cSBarak Witkowski struct tstorm_per_queue_stats *old_tclient =
114115192a8cSBarak Witkowski &bp->fp_stats[i].old_tclient;
114215192a8cSBarak Witkowski tmp += le32_to_cpu(old_tclient->checksum_discard);
114315192a8cSBarak Witkowski }
11441355b704SMintz Yuval nstats->rx_dropped = tmp + bp->net_stats_old.rx_dropped;
1145adfc5217SJeff Kirsher
1146adfc5217SJeff Kirsher nstats->tx_dropped = 0;
1147adfc5217SJeff Kirsher
1148adfc5217SJeff Kirsher nstats->multicast =
1149adfc5217SJeff Kirsher bnx2x_hilo(&estats->total_multicast_packets_received_hi);
1150adfc5217SJeff Kirsher
1151adfc5217SJeff Kirsher nstats->collisions =
1152adfc5217SJeff Kirsher bnx2x_hilo(&estats->tx_stat_etherstatscollisions_hi);
1153adfc5217SJeff Kirsher
1154adfc5217SJeff Kirsher nstats->rx_length_errors =
1155adfc5217SJeff Kirsher bnx2x_hilo(&estats->rx_stat_etherstatsundersizepkts_hi) +
1156adfc5217SJeff Kirsher bnx2x_hilo(&estats->etherstatsoverrsizepkts_hi);
1157adfc5217SJeff Kirsher nstats->rx_over_errors = bnx2x_hilo(&estats->brb_drop_hi) +
1158adfc5217SJeff Kirsher bnx2x_hilo(&estats->brb_truncate_hi);
1159adfc5217SJeff Kirsher nstats->rx_crc_errors =
1160adfc5217SJeff Kirsher bnx2x_hilo(&estats->rx_stat_dot3statsfcserrors_hi);
1161adfc5217SJeff Kirsher nstats->rx_frame_errors =
1162adfc5217SJeff Kirsher bnx2x_hilo(&estats->rx_stat_dot3statsalignmenterrors_hi);
1163adfc5217SJeff Kirsher nstats->rx_fifo_errors = bnx2x_hilo(&estats->no_buff_discard_hi);
1164adfc5217SJeff Kirsher nstats->rx_missed_errors = 0;
1165adfc5217SJeff Kirsher
1166adfc5217SJeff Kirsher nstats->rx_errors = nstats->rx_length_errors +
1167adfc5217SJeff Kirsher nstats->rx_over_errors +
1168adfc5217SJeff Kirsher nstats->rx_crc_errors +
1169adfc5217SJeff Kirsher nstats->rx_frame_errors +
1170adfc5217SJeff Kirsher nstats->rx_fifo_errors +
1171adfc5217SJeff Kirsher nstats->rx_missed_errors;
1172adfc5217SJeff Kirsher
1173adfc5217SJeff Kirsher nstats->tx_aborted_errors =
1174adfc5217SJeff Kirsher bnx2x_hilo(&estats->tx_stat_dot3statslatecollisions_hi) +
1175adfc5217SJeff Kirsher bnx2x_hilo(&estats->tx_stat_dot3statsexcessivecollisions_hi);
1176adfc5217SJeff Kirsher nstats->tx_carrier_errors =
1177adfc5217SJeff Kirsher bnx2x_hilo(&estats->rx_stat_dot3statscarriersenseerrors_hi);
1178adfc5217SJeff Kirsher nstats->tx_fifo_errors = 0;
1179adfc5217SJeff Kirsher nstats->tx_heartbeat_errors = 0;
1180adfc5217SJeff Kirsher nstats->tx_window_errors = 0;
1181adfc5217SJeff Kirsher
1182adfc5217SJeff Kirsher nstats->tx_errors = nstats->tx_aborted_errors +
1183adfc5217SJeff Kirsher nstats->tx_carrier_errors +
1184adfc5217SJeff Kirsher bnx2x_hilo(&estats->tx_stat_dot3statsinternalmactransmiterrors_hi);
1185adfc5217SJeff Kirsher }
1186adfc5217SJeff Kirsher
bnx2x_drv_stats_update(struct bnx2x * bp)1187adfc5217SJeff Kirsher static void bnx2x_drv_stats_update(struct bnx2x *bp)
1188adfc5217SJeff Kirsher {
1189adfc5217SJeff Kirsher struct bnx2x_eth_stats *estats = &bp->eth_stats;
1190adfc5217SJeff Kirsher int i;
1191adfc5217SJeff Kirsher
1192adfc5217SJeff Kirsher for_each_queue(bp, i) {
119315192a8cSBarak Witkowski struct bnx2x_eth_q_stats *qstats = &bp->fp_stats[i].eth_q_stats;
11941355b704SMintz Yuval struct bnx2x_eth_q_stats_old *qstats_old =
119515192a8cSBarak Witkowski &bp->fp_stats[i].eth_q_stats_old;
1196adfc5217SJeff Kirsher
11971355b704SMintz Yuval UPDATE_ESTAT_QSTAT(driver_xoff);
11981355b704SMintz Yuval UPDATE_ESTAT_QSTAT(rx_err_discard_pkt);
11991355b704SMintz Yuval UPDATE_ESTAT_QSTAT(rx_skb_alloc_failed);
12001355b704SMintz Yuval UPDATE_ESTAT_QSTAT(hw_csum_err);
1201c96bdc0cSDmitry Kravkov UPDATE_ESTAT_QSTAT(driver_filtered_tx_pkt);
1202adfc5217SJeff Kirsher }
1203adfc5217SJeff Kirsher }
1204adfc5217SJeff Kirsher
bnx2x_edebug_stats_stopped(struct bnx2x * bp)1205adfc5217SJeff Kirsher static bool bnx2x_edebug_stats_stopped(struct bnx2x *bp)
1206adfc5217SJeff Kirsher {
1207adfc5217SJeff Kirsher u32 val;
1208adfc5217SJeff Kirsher
1209adfc5217SJeff Kirsher if (SHMEM2_HAS(bp, edebug_driver_if[1])) {
1210adfc5217SJeff Kirsher val = SHMEM2_RD(bp, edebug_driver_if[1]);
1211adfc5217SJeff Kirsher
1212adfc5217SJeff Kirsher if (val == EDEBUG_DRIVER_IF_OP_CODE_DISABLE_STAT)
1213adfc5217SJeff Kirsher return true;
1214adfc5217SJeff Kirsher }
1215adfc5217SJeff Kirsher
1216adfc5217SJeff Kirsher return false;
1217adfc5217SJeff Kirsher }
1218adfc5217SJeff Kirsher
bnx2x_stats_update(struct bnx2x * bp)1219adfc5217SJeff Kirsher static void bnx2x_stats_update(struct bnx2x *bp)
1220adfc5217SJeff Kirsher {
1221adfc5217SJeff Kirsher u32 *stats_comp = bnx2x_sp(bp, stats_comp);
1222adfc5217SJeff Kirsher
1223dff173deSYuval Mintz if (bnx2x_edebug_stats_stopped(bp))
1224adfc5217SJeff Kirsher return;
1225adfc5217SJeff Kirsher
122667c431a5SAriel Elior if (IS_PF(bp)) {
1227adfc5217SJeff Kirsher if (*stats_comp != DMAE_COMP_VAL)
1228dff173deSYuval Mintz return;
1229adfc5217SJeff Kirsher
1230adfc5217SJeff Kirsher if (bp->port.pmf)
1231adfc5217SJeff Kirsher bnx2x_hw_stats_update(bp);
1232adfc5217SJeff Kirsher
1233bef05406SDmitry Kravkov if (bnx2x_storm_stats_update(bp)) {
1234bef05406SDmitry Kravkov if (bp->stats_pending++ == 3) {
1235adfc5217SJeff Kirsher BNX2X_ERR("storm stats were not updated for 3 times\n");
1236adfc5217SJeff Kirsher bnx2x_panic();
1237bef05406SDmitry Kravkov }
1238dff173deSYuval Mintz return;
1239adfc5217SJeff Kirsher }
124067c431a5SAriel Elior } else {
124167c431a5SAriel Elior /* vf doesn't collect HW statistics, and doesn't get completions
124267c431a5SAriel Elior * perform only update
124367c431a5SAriel Elior */
124467c431a5SAriel Elior bnx2x_storm_stats_update(bp);
124567c431a5SAriel Elior }
1246adfc5217SJeff Kirsher
1247adfc5217SJeff Kirsher bnx2x_net_stats_update(bp);
1248adfc5217SJeff Kirsher bnx2x_drv_stats_update(bp);
1249adfc5217SJeff Kirsher
125067c431a5SAriel Elior /* vf is done */
125167c431a5SAriel Elior if (IS_VF(bp))
1252dff173deSYuval Mintz return;
125367c431a5SAriel Elior
1254adfc5217SJeff Kirsher if (netif_msg_timer(bp)) {
1255adfc5217SJeff Kirsher struct bnx2x_eth_stats *estats = &bp->eth_stats;
1256adfc5217SJeff Kirsher
1257adfc5217SJeff Kirsher netdev_dbg(bp->dev, "brb drops %u brb truncate %u\n",
1258adfc5217SJeff Kirsher estats->brb_drop_lo, estats->brb_truncate_lo);
1259adfc5217SJeff Kirsher }
1260adfc5217SJeff Kirsher
1261adfc5217SJeff Kirsher bnx2x_hw_stats_post(bp);
1262adfc5217SJeff Kirsher bnx2x_storm_stats_post(bp);
1263adfc5217SJeff Kirsher }
1264adfc5217SJeff Kirsher
bnx2x_port_stats_stop(struct bnx2x * bp)1265adfc5217SJeff Kirsher static void bnx2x_port_stats_stop(struct bnx2x *bp)
1266adfc5217SJeff Kirsher {
1267adfc5217SJeff Kirsher struct dmae_command *dmae;
1268adfc5217SJeff Kirsher u32 opcode;
1269adfc5217SJeff Kirsher int loader_idx = PMF_DMAE_C(bp);
1270adfc5217SJeff Kirsher u32 *stats_comp = bnx2x_sp(bp, stats_comp);
1271adfc5217SJeff Kirsher
1272adfc5217SJeff Kirsher bp->executer_idx = 0;
1273adfc5217SJeff Kirsher
1274adfc5217SJeff Kirsher opcode = bnx2x_dmae_opcode(bp, DMAE_SRC_PCI, DMAE_DST_GRC, false, 0);
1275adfc5217SJeff Kirsher
1276adfc5217SJeff Kirsher if (bp->port.port_stx) {
1277adfc5217SJeff Kirsher
1278adfc5217SJeff Kirsher dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
1279adfc5217SJeff Kirsher if (bp->func_stx)
1280adfc5217SJeff Kirsher dmae->opcode = bnx2x_dmae_opcode_add_comp(
1281adfc5217SJeff Kirsher opcode, DMAE_COMP_GRC);
1282adfc5217SJeff Kirsher else
1283adfc5217SJeff Kirsher dmae->opcode = bnx2x_dmae_opcode_add_comp(
1284adfc5217SJeff Kirsher opcode, DMAE_COMP_PCI);
1285adfc5217SJeff Kirsher
1286adfc5217SJeff Kirsher dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, port_stats));
1287adfc5217SJeff Kirsher dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, port_stats));
1288adfc5217SJeff Kirsher dmae->dst_addr_lo = bp->port.port_stx >> 2;
1289adfc5217SJeff Kirsher dmae->dst_addr_hi = 0;
12901d187b34SBarak Witkowski dmae->len = bnx2x_get_port_stats_dma_len(bp);
1291adfc5217SJeff Kirsher if (bp->func_stx) {
1292adfc5217SJeff Kirsher dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
1293adfc5217SJeff Kirsher dmae->comp_addr_hi = 0;
1294adfc5217SJeff Kirsher dmae->comp_val = 1;
1295adfc5217SJeff Kirsher } else {
1296adfc5217SJeff Kirsher dmae->comp_addr_lo =
1297adfc5217SJeff Kirsher U64_LO(bnx2x_sp_mapping(bp, stats_comp));
1298adfc5217SJeff Kirsher dmae->comp_addr_hi =
1299adfc5217SJeff Kirsher U64_HI(bnx2x_sp_mapping(bp, stats_comp));
1300adfc5217SJeff Kirsher dmae->comp_val = DMAE_COMP_VAL;
1301adfc5217SJeff Kirsher
1302adfc5217SJeff Kirsher *stats_comp = 0;
1303adfc5217SJeff Kirsher }
1304adfc5217SJeff Kirsher }
1305adfc5217SJeff Kirsher
1306adfc5217SJeff Kirsher if (bp->func_stx) {
1307adfc5217SJeff Kirsher
1308adfc5217SJeff Kirsher dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
1309adfc5217SJeff Kirsher dmae->opcode =
1310adfc5217SJeff Kirsher bnx2x_dmae_opcode_add_comp(opcode, DMAE_COMP_PCI);
1311adfc5217SJeff Kirsher dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, func_stats));
1312adfc5217SJeff Kirsher dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, func_stats));
1313adfc5217SJeff Kirsher dmae->dst_addr_lo = bp->func_stx >> 2;
1314adfc5217SJeff Kirsher dmae->dst_addr_hi = 0;
1315adfc5217SJeff Kirsher dmae->len = sizeof(struct host_func_stats) >> 2;
1316adfc5217SJeff Kirsher dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, stats_comp));
1317adfc5217SJeff Kirsher dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, stats_comp));
1318adfc5217SJeff Kirsher dmae->comp_val = DMAE_COMP_VAL;
1319adfc5217SJeff Kirsher
1320adfc5217SJeff Kirsher *stats_comp = 0;
1321adfc5217SJeff Kirsher }
1322adfc5217SJeff Kirsher }
1323adfc5217SJeff Kirsher
bnx2x_stats_stop(struct bnx2x * bp)1324adfc5217SJeff Kirsher static void bnx2x_stats_stop(struct bnx2x *bp)
1325adfc5217SJeff Kirsher {
1326dff173deSYuval Mintz bool update = false;
1327507393ebSDmitry Kravkov
1328adfc5217SJeff Kirsher bnx2x_stats_comp(bp);
1329adfc5217SJeff Kirsher
1330adfc5217SJeff Kirsher if (bp->port.pmf)
1331adfc5217SJeff Kirsher update = (bnx2x_hw_stats_update(bp) == 0);
1332adfc5217SJeff Kirsher
1333adfc5217SJeff Kirsher update |= (bnx2x_storm_stats_update(bp) == 0);
1334adfc5217SJeff Kirsher
1335adfc5217SJeff Kirsher if (update) {
1336adfc5217SJeff Kirsher bnx2x_net_stats_update(bp);
1337adfc5217SJeff Kirsher
1338adfc5217SJeff Kirsher if (bp->port.pmf)
1339adfc5217SJeff Kirsher bnx2x_port_stats_stop(bp);
1340adfc5217SJeff Kirsher
1341adfc5217SJeff Kirsher bnx2x_hw_stats_post(bp);
1342adfc5217SJeff Kirsher bnx2x_stats_comp(bp);
1343adfc5217SJeff Kirsher }
1344adfc5217SJeff Kirsher }
1345adfc5217SJeff Kirsher
bnx2x_stats_do_nothing(struct bnx2x * bp)1346adfc5217SJeff Kirsher static void bnx2x_stats_do_nothing(struct bnx2x *bp)
1347adfc5217SJeff Kirsher {
1348adfc5217SJeff Kirsher }
1349adfc5217SJeff Kirsher
1350adfc5217SJeff Kirsher static const struct {
1351adfc5217SJeff Kirsher void (*action)(struct bnx2x *bp);
1352adfc5217SJeff Kirsher enum bnx2x_stats_state next_state;
1353adfc5217SJeff Kirsher } bnx2x_stats_stm[STATS_STATE_MAX][STATS_EVENT_MAX] = {
1354adfc5217SJeff Kirsher /* state event */
1355adfc5217SJeff Kirsher {
1356adfc5217SJeff Kirsher /* DISABLED PMF */ {bnx2x_stats_pmf_update, STATS_STATE_DISABLED},
1357adfc5217SJeff Kirsher /* LINK_UP */ {bnx2x_stats_start, STATS_STATE_ENABLED},
1358adfc5217SJeff Kirsher /* UPDATE */ {bnx2x_stats_do_nothing, STATS_STATE_DISABLED},
1359adfc5217SJeff Kirsher /* STOP */ {bnx2x_stats_do_nothing, STATS_STATE_DISABLED}
1360adfc5217SJeff Kirsher },
1361adfc5217SJeff Kirsher {
1362adfc5217SJeff Kirsher /* ENABLED PMF */ {bnx2x_stats_pmf_start, STATS_STATE_ENABLED},
1363adfc5217SJeff Kirsher /* LINK_UP */ {bnx2x_stats_restart, STATS_STATE_ENABLED},
1364adfc5217SJeff Kirsher /* UPDATE */ {bnx2x_stats_update, STATS_STATE_ENABLED},
1365adfc5217SJeff Kirsher /* STOP */ {bnx2x_stats_stop, STATS_STATE_DISABLED}
1366adfc5217SJeff Kirsher }
1367adfc5217SJeff Kirsher };
1368adfc5217SJeff Kirsher
bnx2x_stats_handle(struct bnx2x * bp,enum bnx2x_stats_event event)1369adfc5217SJeff Kirsher void bnx2x_stats_handle(struct bnx2x *bp, enum bnx2x_stats_event event)
1370adfc5217SJeff Kirsher {
1371dff173deSYuval Mintz enum bnx2x_stats_state state = bp->stats_state;
1372dff173deSYuval Mintz
1373adfc5217SJeff Kirsher if (unlikely(bp->panic))
1374adfc5217SJeff Kirsher return;
13754a025f49SDmitry Kravkov
1376dff173deSYuval Mintz /* Statistics update run from timer context, and we don't want to stop
1377dff173deSYuval Mintz * that context in case someone is in the middle of a transition.
1378dff173deSYuval Mintz * For other events, wait a bit until lock is taken.
1379dff173deSYuval Mintz */
1380c6e36d8cSYuval Mintz if (down_trylock(&bp->stats_lock)) {
1381dff173deSYuval Mintz if (event == STATS_EVENT_UPDATE)
1382dff173deSYuval Mintz return;
1383adfc5217SJeff Kirsher
1384dff173deSYuval Mintz DP(BNX2X_MSG_STATS,
1385dff173deSYuval Mintz "Unlikely stats' lock contention [event %d]\n", event);
1386c6e36d8cSYuval Mintz if (unlikely(down_timeout(&bp->stats_lock, HZ / 10))) {
1387c6e36d8cSYuval Mintz BNX2X_ERR("Failed to take stats lock [event %d]\n",
1388c6e36d8cSYuval Mintz event);
1389c6e36d8cSYuval Mintz return;
1390c6e36d8cSYuval Mintz }
1391dff173deSYuval Mintz }
1392dff173deSYuval Mintz
1393dff173deSYuval Mintz bnx2x_stats_stm[state][event].action(bp);
1394dff173deSYuval Mintz bp->stats_state = bnx2x_stats_stm[state][event].next_state;
1395dff173deSYuval Mintz
1396c6e36d8cSYuval Mintz up(&bp->stats_lock);
13974a025f49SDmitry Kravkov
1398adfc5217SJeff Kirsher if ((event != STATS_EVENT_UPDATE) || netif_msg_timer(bp))
1399adfc5217SJeff Kirsher DP(BNX2X_MSG_STATS, "state %d -> event %d -> state %d\n",
1400adfc5217SJeff Kirsher state, event, bp->stats_state);
1401adfc5217SJeff Kirsher }
1402adfc5217SJeff Kirsher
bnx2x_port_stats_base_init(struct bnx2x * bp)1403adfc5217SJeff Kirsher static void bnx2x_port_stats_base_init(struct bnx2x *bp)
1404adfc5217SJeff Kirsher {
1405adfc5217SJeff Kirsher struct dmae_command *dmae;
1406adfc5217SJeff Kirsher u32 *stats_comp = bnx2x_sp(bp, stats_comp);
1407adfc5217SJeff Kirsher
1408adfc5217SJeff Kirsher /* sanity */
1409adfc5217SJeff Kirsher if (!bp->port.pmf || !bp->port.port_stx) {
1410adfc5217SJeff Kirsher BNX2X_ERR("BUG!\n");
1411adfc5217SJeff Kirsher return;
1412adfc5217SJeff Kirsher }
1413adfc5217SJeff Kirsher
1414adfc5217SJeff Kirsher bp->executer_idx = 0;
1415adfc5217SJeff Kirsher
1416adfc5217SJeff Kirsher dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
1417adfc5217SJeff Kirsher dmae->opcode = bnx2x_dmae_opcode(bp, DMAE_SRC_PCI, DMAE_DST_GRC,
1418adfc5217SJeff Kirsher true, DMAE_COMP_PCI);
1419adfc5217SJeff Kirsher dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, port_stats));
1420adfc5217SJeff Kirsher dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, port_stats));
1421adfc5217SJeff Kirsher dmae->dst_addr_lo = bp->port.port_stx >> 2;
1422adfc5217SJeff Kirsher dmae->dst_addr_hi = 0;
14231d187b34SBarak Witkowski dmae->len = bnx2x_get_port_stats_dma_len(bp);
1424adfc5217SJeff Kirsher dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, stats_comp));
1425adfc5217SJeff Kirsher dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, stats_comp));
1426adfc5217SJeff Kirsher dmae->comp_val = DMAE_COMP_VAL;
1427adfc5217SJeff Kirsher
1428adfc5217SJeff Kirsher *stats_comp = 0;
1429adfc5217SJeff Kirsher bnx2x_hw_stats_post(bp);
1430adfc5217SJeff Kirsher bnx2x_stats_comp(bp);
1431adfc5217SJeff Kirsher }
1432adfc5217SJeff Kirsher
14331aa8b471SBen Hutchings /* This function will prepare the statistics ramrod data the way
1434adfc5217SJeff Kirsher * we will only have to increment the statistics counter and
1435adfc5217SJeff Kirsher * send the ramrod each time we have to.
1436adfc5217SJeff Kirsher */
bnx2x_prep_fw_stats_req(struct bnx2x * bp)14371191cb83SEric Dumazet static void bnx2x_prep_fw_stats_req(struct bnx2x *bp)
1438adfc5217SJeff Kirsher {
1439adfc5217SJeff Kirsher int i;
144050f0a562SBarak Witkowski int first_queue_query_index;
1441adfc5217SJeff Kirsher struct stats_query_header *stats_hdr = &bp->fw_stats_req->hdr;
1442adfc5217SJeff Kirsher
1443adfc5217SJeff Kirsher dma_addr_t cur_data_offset;
1444adfc5217SJeff Kirsher struct stats_query_entry *cur_query_entry;
1445adfc5217SJeff Kirsher
1446adfc5217SJeff Kirsher stats_hdr->cmd_num = bp->fw_stats_num;
1447adfc5217SJeff Kirsher stats_hdr->drv_stats_counter = 0;
1448adfc5217SJeff Kirsher
1449adfc5217SJeff Kirsher /* storm_counters struct contains the counters of completed
1450adfc5217SJeff Kirsher * statistics requests per storm which are incremented by FW
1451adfc5217SJeff Kirsher * each time it completes hadning a statistics ramrod. We will
1452adfc5217SJeff Kirsher * check these counters in the timer handler and discard a
1453adfc5217SJeff Kirsher * (statistics) ramrod completion.
1454adfc5217SJeff Kirsher */
1455adfc5217SJeff Kirsher cur_data_offset = bp->fw_stats_data_mapping +
1456adfc5217SJeff Kirsher offsetof(struct bnx2x_fw_stats_data, storm_counters);
1457adfc5217SJeff Kirsher
1458adfc5217SJeff Kirsher stats_hdr->stats_counters_addrs.hi =
1459adfc5217SJeff Kirsher cpu_to_le32(U64_HI(cur_data_offset));
1460adfc5217SJeff Kirsher stats_hdr->stats_counters_addrs.lo =
1461adfc5217SJeff Kirsher cpu_to_le32(U64_LO(cur_data_offset));
1462adfc5217SJeff Kirsher
1463adfc5217SJeff Kirsher /* prepare to the first stats ramrod (will be completed with
1464adfc5217SJeff Kirsher * the counters equal to zero) - init counters to somethig different.
1465adfc5217SJeff Kirsher */
1466adfc5217SJeff Kirsher memset(&bp->fw_stats_data->storm_counters, 0xff,
1467adfc5217SJeff Kirsher sizeof(struct stats_counter));
1468adfc5217SJeff Kirsher
1469adfc5217SJeff Kirsher /**** Port FW statistics data ****/
1470adfc5217SJeff Kirsher cur_data_offset = bp->fw_stats_data_mapping +
1471adfc5217SJeff Kirsher offsetof(struct bnx2x_fw_stats_data, port);
1472adfc5217SJeff Kirsher
1473adfc5217SJeff Kirsher cur_query_entry = &bp->fw_stats_req->query[BNX2X_PORT_QUERY_IDX];
1474adfc5217SJeff Kirsher
1475adfc5217SJeff Kirsher cur_query_entry->kind = STATS_TYPE_PORT;
1476adfc5217SJeff Kirsher /* For port query index is a DONT CARE */
1477adfc5217SJeff Kirsher cur_query_entry->index = BP_PORT(bp);
1478adfc5217SJeff Kirsher /* For port query funcID is a DONT CARE */
1479adfc5217SJeff Kirsher cur_query_entry->funcID = cpu_to_le16(BP_FUNC(bp));
1480adfc5217SJeff Kirsher cur_query_entry->address.hi = cpu_to_le32(U64_HI(cur_data_offset));
1481adfc5217SJeff Kirsher cur_query_entry->address.lo = cpu_to_le32(U64_LO(cur_data_offset));
1482adfc5217SJeff Kirsher
1483adfc5217SJeff Kirsher /**** PF FW statistics data ****/
1484adfc5217SJeff Kirsher cur_data_offset = bp->fw_stats_data_mapping +
1485adfc5217SJeff Kirsher offsetof(struct bnx2x_fw_stats_data, pf);
1486adfc5217SJeff Kirsher
1487adfc5217SJeff Kirsher cur_query_entry = &bp->fw_stats_req->query[BNX2X_PF_QUERY_IDX];
1488adfc5217SJeff Kirsher
1489adfc5217SJeff Kirsher cur_query_entry->kind = STATS_TYPE_PF;
1490adfc5217SJeff Kirsher /* For PF query index is a DONT CARE */
1491adfc5217SJeff Kirsher cur_query_entry->index = BP_PORT(bp);
1492adfc5217SJeff Kirsher cur_query_entry->funcID = cpu_to_le16(BP_FUNC(bp));
1493adfc5217SJeff Kirsher cur_query_entry->address.hi = cpu_to_le32(U64_HI(cur_data_offset));
1494adfc5217SJeff Kirsher cur_query_entry->address.lo = cpu_to_le32(U64_LO(cur_data_offset));
1495adfc5217SJeff Kirsher
149650f0a562SBarak Witkowski /**** FCoE FW statistics data ****/
149750f0a562SBarak Witkowski if (!NO_FCOE(bp)) {
149850f0a562SBarak Witkowski cur_data_offset = bp->fw_stats_data_mapping +
149950f0a562SBarak Witkowski offsetof(struct bnx2x_fw_stats_data, fcoe);
150050f0a562SBarak Witkowski
150150f0a562SBarak Witkowski cur_query_entry =
150250f0a562SBarak Witkowski &bp->fw_stats_req->query[BNX2X_FCOE_QUERY_IDX];
150350f0a562SBarak Witkowski
150450f0a562SBarak Witkowski cur_query_entry->kind = STATS_TYPE_FCOE;
150550f0a562SBarak Witkowski /* For FCoE query index is a DONT CARE */
150650f0a562SBarak Witkowski cur_query_entry->index = BP_PORT(bp);
150750f0a562SBarak Witkowski cur_query_entry->funcID = cpu_to_le16(BP_FUNC(bp));
150850f0a562SBarak Witkowski cur_query_entry->address.hi =
150950f0a562SBarak Witkowski cpu_to_le32(U64_HI(cur_data_offset));
151050f0a562SBarak Witkowski cur_query_entry->address.lo =
151150f0a562SBarak Witkowski cpu_to_le32(U64_LO(cur_data_offset));
151250f0a562SBarak Witkowski }
151350f0a562SBarak Witkowski
1514adfc5217SJeff Kirsher /**** Clients' queries ****/
1515adfc5217SJeff Kirsher cur_data_offset = bp->fw_stats_data_mapping +
1516adfc5217SJeff Kirsher offsetof(struct bnx2x_fw_stats_data, queue_stats);
1517adfc5217SJeff Kirsher
151850f0a562SBarak Witkowski /* first queue query index depends whether FCoE offloaded request will
151950f0a562SBarak Witkowski * be included in the ramrod
152050f0a562SBarak Witkowski */
152150f0a562SBarak Witkowski if (!NO_FCOE(bp))
152250f0a562SBarak Witkowski first_queue_query_index = BNX2X_FIRST_QUEUE_QUERY_IDX;
152350f0a562SBarak Witkowski else
152450f0a562SBarak Witkowski first_queue_query_index = BNX2X_FIRST_QUEUE_QUERY_IDX - 1;
152550f0a562SBarak Witkowski
1526adfc5217SJeff Kirsher for_each_eth_queue(bp, i) {
1527adfc5217SJeff Kirsher cur_query_entry =
1528adfc5217SJeff Kirsher &bp->fw_stats_req->
152950f0a562SBarak Witkowski query[first_queue_query_index + i];
1530adfc5217SJeff Kirsher
1531adfc5217SJeff Kirsher cur_query_entry->kind = STATS_TYPE_QUEUE;
1532adfc5217SJeff Kirsher cur_query_entry->index = bnx2x_stats_id(&bp->fp[i]);
1533adfc5217SJeff Kirsher cur_query_entry->funcID = cpu_to_le16(BP_FUNC(bp));
1534adfc5217SJeff Kirsher cur_query_entry->address.hi =
1535adfc5217SJeff Kirsher cpu_to_le32(U64_HI(cur_data_offset));
1536adfc5217SJeff Kirsher cur_query_entry->address.lo =
1537adfc5217SJeff Kirsher cpu_to_le32(U64_LO(cur_data_offset));
1538adfc5217SJeff Kirsher
1539adfc5217SJeff Kirsher cur_data_offset += sizeof(struct per_queue_stats);
1540adfc5217SJeff Kirsher }
154150f0a562SBarak Witkowski
154250f0a562SBarak Witkowski /* add FCoE queue query if needed */
154350f0a562SBarak Witkowski if (!NO_FCOE(bp)) {
154450f0a562SBarak Witkowski cur_query_entry =
154550f0a562SBarak Witkowski &bp->fw_stats_req->
154650f0a562SBarak Witkowski query[first_queue_query_index + i];
154750f0a562SBarak Witkowski
154850f0a562SBarak Witkowski cur_query_entry->kind = STATS_TYPE_QUEUE;
154965565884SMerav Sicron cur_query_entry->index = bnx2x_stats_id(&bp->fp[FCOE_IDX(bp)]);
155050f0a562SBarak Witkowski cur_query_entry->funcID = cpu_to_le16(BP_FUNC(bp));
155150f0a562SBarak Witkowski cur_query_entry->address.hi =
155250f0a562SBarak Witkowski cpu_to_le32(U64_HI(cur_data_offset));
155350f0a562SBarak Witkowski cur_query_entry->address.lo =
155450f0a562SBarak Witkowski cpu_to_le32(U64_LO(cur_data_offset));
155550f0a562SBarak Witkowski }
1556adfc5217SJeff Kirsher }
1557adfc5217SJeff Kirsher
bnx2x_memset_stats(struct bnx2x * bp)15585b0752c8SAriel Elior void bnx2x_memset_stats(struct bnx2x *bp)
15595b0752c8SAriel Elior {
15605b0752c8SAriel Elior int i;
15615b0752c8SAriel Elior
15625b0752c8SAriel Elior /* function stats */
15635b0752c8SAriel Elior for_each_queue(bp, i) {
15645b0752c8SAriel Elior struct bnx2x_fp_stats *fp_stats = &bp->fp_stats[i];
15655b0752c8SAriel Elior
15665b0752c8SAriel Elior memset(&fp_stats->old_tclient, 0,
15675b0752c8SAriel Elior sizeof(fp_stats->old_tclient));
15685b0752c8SAriel Elior memset(&fp_stats->old_uclient, 0,
15695b0752c8SAriel Elior sizeof(fp_stats->old_uclient));
15705b0752c8SAriel Elior memset(&fp_stats->old_xclient, 0,
15715b0752c8SAriel Elior sizeof(fp_stats->old_xclient));
15725b0752c8SAriel Elior if (bp->stats_init) {
15735b0752c8SAriel Elior memset(&fp_stats->eth_q_stats, 0,
15745b0752c8SAriel Elior sizeof(fp_stats->eth_q_stats));
15755b0752c8SAriel Elior memset(&fp_stats->eth_q_stats_old, 0,
15765b0752c8SAriel Elior sizeof(fp_stats->eth_q_stats_old));
15775b0752c8SAriel Elior }
15785b0752c8SAriel Elior }
15795b0752c8SAriel Elior
15805b0752c8SAriel Elior memset(&bp->dev->stats, 0, sizeof(bp->dev->stats));
15815b0752c8SAriel Elior
15825b0752c8SAriel Elior if (bp->stats_init) {
15835b0752c8SAriel Elior memset(&bp->net_stats_old, 0, sizeof(bp->net_stats_old));
15845b0752c8SAriel Elior memset(&bp->fw_stats_old, 0, sizeof(bp->fw_stats_old));
15855b0752c8SAriel Elior memset(&bp->eth_stats_old, 0, sizeof(bp->eth_stats_old));
15865b0752c8SAriel Elior memset(&bp->eth_stats, 0, sizeof(bp->eth_stats));
15875b0752c8SAriel Elior memset(&bp->func_stats, 0, sizeof(bp->func_stats));
15885b0752c8SAriel Elior }
15895b0752c8SAriel Elior
15905b0752c8SAriel Elior bp->stats_state = STATS_STATE_DISABLED;
15915b0752c8SAriel Elior
15925b0752c8SAriel Elior if (bp->port.pmf && bp->port.port_stx)
15935b0752c8SAriel Elior bnx2x_port_stats_base_init(bp);
15945b0752c8SAriel Elior
1595dbedd44eSJoe Perches /* mark the end of statistics initialization */
15965b0752c8SAriel Elior bp->stats_init = false;
15975b0752c8SAriel Elior }
15985b0752c8SAriel Elior
bnx2x_stats_init(struct bnx2x * bp)1599adfc5217SJeff Kirsher void bnx2x_stats_init(struct bnx2x *bp)
1600adfc5217SJeff Kirsher {
1601adfc5217SJeff Kirsher int /*abs*/port = BP_PORT(bp);
1602adfc5217SJeff Kirsher int mb_idx = BP_FW_MB_IDX(bp);
1603adfc5217SJeff Kirsher
160414f806a0SYuval Mintz if (IS_VF(bp)) {
160514f806a0SYuval Mintz bnx2x_memset_stats(bp);
160614f806a0SYuval Mintz return;
160714f806a0SYuval Mintz }
160814f806a0SYuval Mintz
1609adfc5217SJeff Kirsher bp->stats_pending = 0;
1610adfc5217SJeff Kirsher bp->executer_idx = 0;
1611adfc5217SJeff Kirsher bp->stats_counter = 0;
1612adfc5217SJeff Kirsher
1613adfc5217SJeff Kirsher /* port and func stats for management */
1614adfc5217SJeff Kirsher if (!BP_NOMCP(bp)) {
1615adfc5217SJeff Kirsher bp->port.port_stx = SHMEM_RD(bp, port_mb[port].port_stx);
1616adfc5217SJeff Kirsher bp->func_stx = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_param);
1617adfc5217SJeff Kirsher
1618adfc5217SJeff Kirsher } else {
1619adfc5217SJeff Kirsher bp->port.port_stx = 0;
1620adfc5217SJeff Kirsher bp->func_stx = 0;
1621adfc5217SJeff Kirsher }
1622adfc5217SJeff Kirsher DP(BNX2X_MSG_STATS, "port_stx 0x%x func_stx 0x%x\n",
1623adfc5217SJeff Kirsher bp->port.port_stx, bp->func_stx);
1624adfc5217SJeff Kirsher
16251355b704SMintz Yuval /* pmf should retrieve port statistics from SP on a non-init*/
16261355b704SMintz Yuval if (!bp->stats_init && bp->port.pmf && bp->port.port_stx)
16271355b704SMintz Yuval bnx2x_stats_handle(bp, STATS_EVENT_PMF);
16281355b704SMintz Yuval
1629adfc5217SJeff Kirsher port = BP_PORT(bp);
1630adfc5217SJeff Kirsher /* port stats */
1631adfc5217SJeff Kirsher memset(&(bp->port.old_nig_stats), 0, sizeof(struct nig_stats));
1632adfc5217SJeff Kirsher bp->port.old_nig_stats.brb_discard =
1633adfc5217SJeff Kirsher REG_RD(bp, NIG_REG_STAT0_BRB_DISCARD + port*0x38);
1634adfc5217SJeff Kirsher bp->port.old_nig_stats.brb_truncate =
1635adfc5217SJeff Kirsher REG_RD(bp, NIG_REG_STAT0_BRB_TRUNCATE + port*0x38);
1636adfc5217SJeff Kirsher if (!CHIP_IS_E3(bp)) {
1637adfc5217SJeff Kirsher REG_RD_DMAE(bp, NIG_REG_STAT0_EGRESS_MAC_PKT0 + port*0x50,
1638*29fd0ec6SKees Cook &(bp->port.old_nig_stats.egress_mac_pkt0), 2);
1639adfc5217SJeff Kirsher REG_RD_DMAE(bp, NIG_REG_STAT0_EGRESS_MAC_PKT1 + port*0x50,
1640*29fd0ec6SKees Cook &(bp->port.old_nig_stats.egress_mac_pkt1), 2);
1641adfc5217SJeff Kirsher }
1642adfc5217SJeff Kirsher
1643adfc5217SJeff Kirsher /* Prepare statistics ramrod data */
1644adfc5217SJeff Kirsher bnx2x_prep_fw_stats_req(bp);
1645adfc5217SJeff Kirsher
16461355b704SMintz Yuval /* Clean SP from previous statistics */
16475b0752c8SAriel Elior if (bp->stats_init) {
16481355b704SMintz Yuval if (bp->func_stx) {
16491355b704SMintz Yuval memset(bnx2x_sp(bp, func_stats), 0,
16501355b704SMintz Yuval sizeof(struct host_func_stats));
16511355b704SMintz Yuval bnx2x_func_stats_init(bp);
16521355b704SMintz Yuval bnx2x_hw_stats_post(bp);
16531355b704SMintz Yuval bnx2x_stats_comp(bp);
16541355b704SMintz Yuval }
16551355b704SMintz Yuval }
16561355b704SMintz Yuval
16575b0752c8SAriel Elior bnx2x_memset_stats(bp);
16581355b704SMintz Yuval }
16591355b704SMintz Yuval
bnx2x_save_statistics(struct bnx2x * bp)16601355b704SMintz Yuval void bnx2x_save_statistics(struct bnx2x *bp)
16611355b704SMintz Yuval {
16621355b704SMintz Yuval int i;
16631355b704SMintz Yuval struct net_device_stats *nstats = &bp->dev->stats;
16641355b704SMintz Yuval
16651355b704SMintz Yuval /* save queue statistics */
16661355b704SMintz Yuval for_each_eth_queue(bp, i) {
16671355b704SMintz Yuval struct bnx2x_fastpath *fp = &bp->fp[i];
166815192a8cSBarak Witkowski struct bnx2x_eth_q_stats *qstats =
166915192a8cSBarak Witkowski &bnx2x_fp_stats(bp, fp)->eth_q_stats;
167015192a8cSBarak Witkowski struct bnx2x_eth_q_stats_old *qstats_old =
167115192a8cSBarak Witkowski &bnx2x_fp_stats(bp, fp)->eth_q_stats_old;
16721355b704SMintz Yuval
16731355b704SMintz Yuval UPDATE_QSTAT_OLD(total_unicast_bytes_received_hi);
16741355b704SMintz Yuval UPDATE_QSTAT_OLD(total_unicast_bytes_received_lo);
16751355b704SMintz Yuval UPDATE_QSTAT_OLD(total_broadcast_bytes_received_hi);
16761355b704SMintz Yuval UPDATE_QSTAT_OLD(total_broadcast_bytes_received_lo);
16771355b704SMintz Yuval UPDATE_QSTAT_OLD(total_multicast_bytes_received_hi);
16781355b704SMintz Yuval UPDATE_QSTAT_OLD(total_multicast_bytes_received_lo);
16791355b704SMintz Yuval UPDATE_QSTAT_OLD(total_unicast_bytes_transmitted_hi);
16801355b704SMintz Yuval UPDATE_QSTAT_OLD(total_unicast_bytes_transmitted_lo);
16811355b704SMintz Yuval UPDATE_QSTAT_OLD(total_broadcast_bytes_transmitted_hi);
16821355b704SMintz Yuval UPDATE_QSTAT_OLD(total_broadcast_bytes_transmitted_lo);
16831355b704SMintz Yuval UPDATE_QSTAT_OLD(total_multicast_bytes_transmitted_hi);
16841355b704SMintz Yuval UPDATE_QSTAT_OLD(total_multicast_bytes_transmitted_lo);
16851355b704SMintz Yuval UPDATE_QSTAT_OLD(total_tpa_bytes_hi);
16861355b704SMintz Yuval UPDATE_QSTAT_OLD(total_tpa_bytes_lo);
16871355b704SMintz Yuval }
16881355b704SMintz Yuval
16891355b704SMintz Yuval /* save net_device_stats statistics */
16901355b704SMintz Yuval bp->net_stats_old.rx_dropped = nstats->rx_dropped;
16911355b704SMintz Yuval
16921355b704SMintz Yuval /* store port firmware statistics */
16931355b704SMintz Yuval if (bp->port.pmf && IS_MF(bp)) {
16941355b704SMintz Yuval struct bnx2x_eth_stats *estats = &bp->eth_stats;
16951355b704SMintz Yuval struct bnx2x_fw_port_stats_old *fwstats = &bp->fw_stats_old;
16961355b704SMintz Yuval UPDATE_FW_STAT_OLD(mac_filter_discard);
16971355b704SMintz Yuval UPDATE_FW_STAT_OLD(mf_tag_discard);
16981355b704SMintz Yuval UPDATE_FW_STAT_OLD(brb_truncate_discard);
16991355b704SMintz Yuval UPDATE_FW_STAT_OLD(mac_discard);
17001355b704SMintz Yuval }
1701adfc5217SJeff Kirsher }
1702a3348722SBarak Witkowski
bnx2x_afex_collect_stats(struct bnx2x * bp,void * void_afex_stats,u32 stats_type)1703a3348722SBarak Witkowski void bnx2x_afex_collect_stats(struct bnx2x *bp, void *void_afex_stats,
1704a3348722SBarak Witkowski u32 stats_type)
1705a3348722SBarak Witkowski {
1706a3348722SBarak Witkowski int i;
1707a3348722SBarak Witkowski struct afex_stats *afex_stats = (struct afex_stats *)void_afex_stats;
1708a3348722SBarak Witkowski struct bnx2x_eth_stats *estats = &bp->eth_stats;
1709a3348722SBarak Witkowski struct per_queue_stats *fcoe_q_stats =
171065565884SMerav Sicron &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)];
1711a3348722SBarak Witkowski
1712a3348722SBarak Witkowski struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
1713a3348722SBarak Witkowski &fcoe_q_stats->tstorm_queue_statistics;
1714a3348722SBarak Witkowski
1715a3348722SBarak Witkowski struct ustorm_per_queue_stats *fcoe_q_ustorm_stats =
1716a3348722SBarak Witkowski &fcoe_q_stats->ustorm_queue_statistics;
1717a3348722SBarak Witkowski
1718a3348722SBarak Witkowski struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
1719a3348722SBarak Witkowski &fcoe_q_stats->xstorm_queue_statistics;
1720a3348722SBarak Witkowski
1721a3348722SBarak Witkowski struct fcoe_statistics_params *fw_fcoe_stat =
1722a3348722SBarak Witkowski &bp->fw_stats_data->fcoe;
1723a3348722SBarak Witkowski
1724a3348722SBarak Witkowski memset(afex_stats, 0, sizeof(struct afex_stats));
1725a3348722SBarak Witkowski
1726a3348722SBarak Witkowski for_each_eth_queue(bp, i) {
172715192a8cSBarak Witkowski struct bnx2x_eth_q_stats *qstats = &bp->fp_stats[i].eth_q_stats;
1728a3348722SBarak Witkowski
1729a3348722SBarak Witkowski ADD_64(afex_stats->rx_unicast_bytes_hi,
1730a3348722SBarak Witkowski qstats->total_unicast_bytes_received_hi,
1731a3348722SBarak Witkowski afex_stats->rx_unicast_bytes_lo,
1732a3348722SBarak Witkowski qstats->total_unicast_bytes_received_lo);
1733a3348722SBarak Witkowski
1734a3348722SBarak Witkowski ADD_64(afex_stats->rx_broadcast_bytes_hi,
1735a3348722SBarak Witkowski qstats->total_broadcast_bytes_received_hi,
1736a3348722SBarak Witkowski afex_stats->rx_broadcast_bytes_lo,
1737a3348722SBarak Witkowski qstats->total_broadcast_bytes_received_lo);
1738a3348722SBarak Witkowski
1739a3348722SBarak Witkowski ADD_64(afex_stats->rx_multicast_bytes_hi,
1740a3348722SBarak Witkowski qstats->total_multicast_bytes_received_hi,
1741a3348722SBarak Witkowski afex_stats->rx_multicast_bytes_lo,
1742a3348722SBarak Witkowski qstats->total_multicast_bytes_received_lo);
1743a3348722SBarak Witkowski
1744a3348722SBarak Witkowski ADD_64(afex_stats->rx_unicast_frames_hi,
1745a3348722SBarak Witkowski qstats->total_unicast_packets_received_hi,
1746a3348722SBarak Witkowski afex_stats->rx_unicast_frames_lo,
1747a3348722SBarak Witkowski qstats->total_unicast_packets_received_lo);
1748a3348722SBarak Witkowski
1749a3348722SBarak Witkowski ADD_64(afex_stats->rx_broadcast_frames_hi,
1750a3348722SBarak Witkowski qstats->total_broadcast_packets_received_hi,
1751a3348722SBarak Witkowski afex_stats->rx_broadcast_frames_lo,
1752a3348722SBarak Witkowski qstats->total_broadcast_packets_received_lo);
1753a3348722SBarak Witkowski
1754a3348722SBarak Witkowski ADD_64(afex_stats->rx_multicast_frames_hi,
1755a3348722SBarak Witkowski qstats->total_multicast_packets_received_hi,
1756a3348722SBarak Witkowski afex_stats->rx_multicast_frames_lo,
1757a3348722SBarak Witkowski qstats->total_multicast_packets_received_lo);
1758a3348722SBarak Witkowski
1759a3348722SBarak Witkowski /* sum to rx_frames_discarded all discraded
1760a3348722SBarak Witkowski * packets due to size, ttl0 and checksum
1761a3348722SBarak Witkowski */
1762a3348722SBarak Witkowski ADD_64(afex_stats->rx_frames_discarded_hi,
1763a3348722SBarak Witkowski qstats->total_packets_received_checksum_discarded_hi,
1764a3348722SBarak Witkowski afex_stats->rx_frames_discarded_lo,
1765a3348722SBarak Witkowski qstats->total_packets_received_checksum_discarded_lo);
1766a3348722SBarak Witkowski
1767a3348722SBarak Witkowski ADD_64(afex_stats->rx_frames_discarded_hi,
1768a3348722SBarak Witkowski qstats->total_packets_received_ttl0_discarded_hi,
1769a3348722SBarak Witkowski afex_stats->rx_frames_discarded_lo,
1770a3348722SBarak Witkowski qstats->total_packets_received_ttl0_discarded_lo);
1771a3348722SBarak Witkowski
1772a3348722SBarak Witkowski ADD_64(afex_stats->rx_frames_discarded_hi,
1773a3348722SBarak Witkowski qstats->etherstatsoverrsizepkts_hi,
1774a3348722SBarak Witkowski afex_stats->rx_frames_discarded_lo,
1775a3348722SBarak Witkowski qstats->etherstatsoverrsizepkts_lo);
1776a3348722SBarak Witkowski
1777a3348722SBarak Witkowski ADD_64(afex_stats->rx_frames_dropped_hi,
1778a3348722SBarak Witkowski qstats->no_buff_discard_hi,
1779a3348722SBarak Witkowski afex_stats->rx_frames_dropped_lo,
1780a3348722SBarak Witkowski qstats->no_buff_discard_lo);
1781a3348722SBarak Witkowski
1782a3348722SBarak Witkowski ADD_64(afex_stats->tx_unicast_bytes_hi,
1783a3348722SBarak Witkowski qstats->total_unicast_bytes_transmitted_hi,
1784a3348722SBarak Witkowski afex_stats->tx_unicast_bytes_lo,
1785a3348722SBarak Witkowski qstats->total_unicast_bytes_transmitted_lo);
1786a3348722SBarak Witkowski
1787a3348722SBarak Witkowski ADD_64(afex_stats->tx_broadcast_bytes_hi,
1788a3348722SBarak Witkowski qstats->total_broadcast_bytes_transmitted_hi,
1789a3348722SBarak Witkowski afex_stats->tx_broadcast_bytes_lo,
1790a3348722SBarak Witkowski qstats->total_broadcast_bytes_transmitted_lo);
1791a3348722SBarak Witkowski
1792a3348722SBarak Witkowski ADD_64(afex_stats->tx_multicast_bytes_hi,
1793a3348722SBarak Witkowski qstats->total_multicast_bytes_transmitted_hi,
1794a3348722SBarak Witkowski afex_stats->tx_multicast_bytes_lo,
1795a3348722SBarak Witkowski qstats->total_multicast_bytes_transmitted_lo);
1796a3348722SBarak Witkowski
1797a3348722SBarak Witkowski ADD_64(afex_stats->tx_unicast_frames_hi,
1798a3348722SBarak Witkowski qstats->total_unicast_packets_transmitted_hi,
1799a3348722SBarak Witkowski afex_stats->tx_unicast_frames_lo,
1800a3348722SBarak Witkowski qstats->total_unicast_packets_transmitted_lo);
1801a3348722SBarak Witkowski
1802a3348722SBarak Witkowski ADD_64(afex_stats->tx_broadcast_frames_hi,
1803a3348722SBarak Witkowski qstats->total_broadcast_packets_transmitted_hi,
1804a3348722SBarak Witkowski afex_stats->tx_broadcast_frames_lo,
1805a3348722SBarak Witkowski qstats->total_broadcast_packets_transmitted_lo);
1806a3348722SBarak Witkowski
1807a3348722SBarak Witkowski ADD_64(afex_stats->tx_multicast_frames_hi,
1808a3348722SBarak Witkowski qstats->total_multicast_packets_transmitted_hi,
1809a3348722SBarak Witkowski afex_stats->tx_multicast_frames_lo,
1810a3348722SBarak Witkowski qstats->total_multicast_packets_transmitted_lo);
1811a3348722SBarak Witkowski
1812a3348722SBarak Witkowski ADD_64(afex_stats->tx_frames_dropped_hi,
1813a3348722SBarak Witkowski qstats->total_transmitted_dropped_packets_error_hi,
1814a3348722SBarak Witkowski afex_stats->tx_frames_dropped_lo,
1815a3348722SBarak Witkowski qstats->total_transmitted_dropped_packets_error_lo);
1816a3348722SBarak Witkowski }
1817a3348722SBarak Witkowski
1818a3348722SBarak Witkowski /* now add FCoE statistics which are collected separately
1819a3348722SBarak Witkowski * (both offloaded and non offloaded)
1820a3348722SBarak Witkowski */
1821a3348722SBarak Witkowski if (!NO_FCOE(bp)) {
1822a3348722SBarak Witkowski ADD_64_LE(afex_stats->rx_unicast_bytes_hi,
1823a3348722SBarak Witkowski LE32_0,
1824a3348722SBarak Witkowski afex_stats->rx_unicast_bytes_lo,
1825a3348722SBarak Witkowski fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
1826a3348722SBarak Witkowski
1827a3348722SBarak Witkowski ADD_64_LE(afex_stats->rx_unicast_bytes_hi,
1828a3348722SBarak Witkowski fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
1829a3348722SBarak Witkowski afex_stats->rx_unicast_bytes_lo,
1830a3348722SBarak Witkowski fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
1831a3348722SBarak Witkowski
1832a3348722SBarak Witkowski ADD_64_LE(afex_stats->rx_broadcast_bytes_hi,
1833a3348722SBarak Witkowski fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
1834a3348722SBarak Witkowski afex_stats->rx_broadcast_bytes_lo,
1835a3348722SBarak Witkowski fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
1836a3348722SBarak Witkowski
1837a3348722SBarak Witkowski ADD_64_LE(afex_stats->rx_multicast_bytes_hi,
1838a3348722SBarak Witkowski fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
1839a3348722SBarak Witkowski afex_stats->rx_multicast_bytes_lo,
1840a3348722SBarak Witkowski fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
1841a3348722SBarak Witkowski
1842a3348722SBarak Witkowski ADD_64_LE(afex_stats->rx_unicast_frames_hi,
1843a3348722SBarak Witkowski LE32_0,
1844a3348722SBarak Witkowski afex_stats->rx_unicast_frames_lo,
1845a3348722SBarak Witkowski fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
1846a3348722SBarak Witkowski
1847a3348722SBarak Witkowski ADD_64_LE(afex_stats->rx_unicast_frames_hi,
1848a3348722SBarak Witkowski LE32_0,
1849a3348722SBarak Witkowski afex_stats->rx_unicast_frames_lo,
1850a3348722SBarak Witkowski fcoe_q_tstorm_stats->rcv_ucast_pkts);
1851a3348722SBarak Witkowski
1852a3348722SBarak Witkowski ADD_64_LE(afex_stats->rx_broadcast_frames_hi,
1853a3348722SBarak Witkowski LE32_0,
1854a3348722SBarak Witkowski afex_stats->rx_broadcast_frames_lo,
1855a3348722SBarak Witkowski fcoe_q_tstorm_stats->rcv_bcast_pkts);
1856a3348722SBarak Witkowski
1857a3348722SBarak Witkowski ADD_64_LE(afex_stats->rx_multicast_frames_hi,
1858a3348722SBarak Witkowski LE32_0,
1859a3348722SBarak Witkowski afex_stats->rx_multicast_frames_lo,
1860a3348722SBarak Witkowski fcoe_q_tstorm_stats->rcv_ucast_pkts);
1861a3348722SBarak Witkowski
1862a3348722SBarak Witkowski ADD_64_LE(afex_stats->rx_frames_discarded_hi,
1863a3348722SBarak Witkowski LE32_0,
1864a3348722SBarak Witkowski afex_stats->rx_frames_discarded_lo,
1865a3348722SBarak Witkowski fcoe_q_tstorm_stats->checksum_discard);
1866a3348722SBarak Witkowski
1867a3348722SBarak Witkowski ADD_64_LE(afex_stats->rx_frames_discarded_hi,
1868a3348722SBarak Witkowski LE32_0,
1869a3348722SBarak Witkowski afex_stats->rx_frames_discarded_lo,
1870a3348722SBarak Witkowski fcoe_q_tstorm_stats->pkts_too_big_discard);
1871a3348722SBarak Witkowski
1872a3348722SBarak Witkowski ADD_64_LE(afex_stats->rx_frames_discarded_hi,
1873a3348722SBarak Witkowski LE32_0,
1874a3348722SBarak Witkowski afex_stats->rx_frames_discarded_lo,
1875a3348722SBarak Witkowski fcoe_q_tstorm_stats->ttl0_discard);
1876a3348722SBarak Witkowski
1877a3348722SBarak Witkowski ADD_64_LE16(afex_stats->rx_frames_dropped_hi,
1878a3348722SBarak Witkowski LE16_0,
1879a3348722SBarak Witkowski afex_stats->rx_frames_dropped_lo,
1880a3348722SBarak Witkowski fcoe_q_tstorm_stats->no_buff_discard);
1881a3348722SBarak Witkowski
1882a3348722SBarak Witkowski ADD_64_LE(afex_stats->rx_frames_dropped_hi,
1883a3348722SBarak Witkowski LE32_0,
1884a3348722SBarak Witkowski afex_stats->rx_frames_dropped_lo,
1885a3348722SBarak Witkowski fcoe_q_ustorm_stats->ucast_no_buff_pkts);
1886a3348722SBarak Witkowski
1887a3348722SBarak Witkowski ADD_64_LE(afex_stats->rx_frames_dropped_hi,
1888a3348722SBarak Witkowski LE32_0,
1889a3348722SBarak Witkowski afex_stats->rx_frames_dropped_lo,
1890a3348722SBarak Witkowski fcoe_q_ustorm_stats->mcast_no_buff_pkts);
1891a3348722SBarak Witkowski
1892a3348722SBarak Witkowski ADD_64_LE(afex_stats->rx_frames_dropped_hi,
1893a3348722SBarak Witkowski LE32_0,
1894a3348722SBarak Witkowski afex_stats->rx_frames_dropped_lo,
1895a3348722SBarak Witkowski fcoe_q_ustorm_stats->bcast_no_buff_pkts);
1896a3348722SBarak Witkowski
1897a3348722SBarak Witkowski ADD_64_LE(afex_stats->rx_frames_dropped_hi,
1898a3348722SBarak Witkowski LE32_0,
1899a3348722SBarak Witkowski afex_stats->rx_frames_dropped_lo,
1900a3348722SBarak Witkowski fw_fcoe_stat->rx_stat1.fcoe_rx_drop_pkt_cnt);
1901a3348722SBarak Witkowski
1902a3348722SBarak Witkowski ADD_64_LE(afex_stats->rx_frames_dropped_hi,
1903a3348722SBarak Witkowski LE32_0,
1904a3348722SBarak Witkowski afex_stats->rx_frames_dropped_lo,
1905a3348722SBarak Witkowski fw_fcoe_stat->rx_stat2.fcoe_rx_drop_pkt_cnt);
1906a3348722SBarak Witkowski
1907a3348722SBarak Witkowski ADD_64_LE(afex_stats->tx_unicast_bytes_hi,
1908a3348722SBarak Witkowski LE32_0,
1909a3348722SBarak Witkowski afex_stats->tx_unicast_bytes_lo,
1910a3348722SBarak Witkowski fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
1911a3348722SBarak Witkowski
1912a3348722SBarak Witkowski ADD_64_LE(afex_stats->tx_unicast_bytes_hi,
1913a3348722SBarak Witkowski fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
1914a3348722SBarak Witkowski afex_stats->tx_unicast_bytes_lo,
1915a3348722SBarak Witkowski fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
1916a3348722SBarak Witkowski
1917a3348722SBarak Witkowski ADD_64_LE(afex_stats->tx_broadcast_bytes_hi,
1918a3348722SBarak Witkowski fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
1919a3348722SBarak Witkowski afex_stats->tx_broadcast_bytes_lo,
1920a3348722SBarak Witkowski fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
1921a3348722SBarak Witkowski
1922a3348722SBarak Witkowski ADD_64_LE(afex_stats->tx_multicast_bytes_hi,
1923a3348722SBarak Witkowski fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
1924a3348722SBarak Witkowski afex_stats->tx_multicast_bytes_lo,
1925a3348722SBarak Witkowski fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
1926a3348722SBarak Witkowski
1927a3348722SBarak Witkowski ADD_64_LE(afex_stats->tx_unicast_frames_hi,
1928a3348722SBarak Witkowski LE32_0,
1929a3348722SBarak Witkowski afex_stats->tx_unicast_frames_lo,
1930a3348722SBarak Witkowski fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
1931a3348722SBarak Witkowski
1932a3348722SBarak Witkowski ADD_64_LE(afex_stats->tx_unicast_frames_hi,
1933a3348722SBarak Witkowski LE32_0,
1934a3348722SBarak Witkowski afex_stats->tx_unicast_frames_lo,
1935a3348722SBarak Witkowski fcoe_q_xstorm_stats->ucast_pkts_sent);
1936a3348722SBarak Witkowski
1937a3348722SBarak Witkowski ADD_64_LE(afex_stats->tx_broadcast_frames_hi,
1938a3348722SBarak Witkowski LE32_0,
1939a3348722SBarak Witkowski afex_stats->tx_broadcast_frames_lo,
1940a3348722SBarak Witkowski fcoe_q_xstorm_stats->bcast_pkts_sent);
1941a3348722SBarak Witkowski
1942a3348722SBarak Witkowski ADD_64_LE(afex_stats->tx_multicast_frames_hi,
1943a3348722SBarak Witkowski LE32_0,
1944a3348722SBarak Witkowski afex_stats->tx_multicast_frames_lo,
1945a3348722SBarak Witkowski fcoe_q_xstorm_stats->mcast_pkts_sent);
1946a3348722SBarak Witkowski
1947a3348722SBarak Witkowski ADD_64_LE(afex_stats->tx_frames_dropped_hi,
1948a3348722SBarak Witkowski LE32_0,
1949a3348722SBarak Witkowski afex_stats->tx_frames_dropped_lo,
1950a3348722SBarak Witkowski fcoe_q_xstorm_stats->error_drop_pkts);
1951a3348722SBarak Witkowski }
1952a3348722SBarak Witkowski
1953a3348722SBarak Witkowski /* if port stats are requested, add them to the PMF
1954a3348722SBarak Witkowski * stats, as anyway they will be accumulated by the
1955a3348722SBarak Witkowski * MCP before sent to the switch
1956a3348722SBarak Witkowski */
1957a3348722SBarak Witkowski if ((bp->port.pmf) && (stats_type == VICSTATST_UIF_INDEX)) {
1958a3348722SBarak Witkowski ADD_64(afex_stats->rx_frames_dropped_hi,
1959a3348722SBarak Witkowski 0,
1960a3348722SBarak Witkowski afex_stats->rx_frames_dropped_lo,
1961a3348722SBarak Witkowski estats->mac_filter_discard);
1962a3348722SBarak Witkowski ADD_64(afex_stats->rx_frames_dropped_hi,
1963a3348722SBarak Witkowski 0,
1964a3348722SBarak Witkowski afex_stats->rx_frames_dropped_lo,
1965a3348722SBarak Witkowski estats->brb_truncate_discard);
1966a3348722SBarak Witkowski ADD_64(afex_stats->rx_frames_discarded_hi,
1967a3348722SBarak Witkowski 0,
1968a3348722SBarak Witkowski afex_stats->rx_frames_discarded_lo,
1969a3348722SBarak Witkowski estats->mac_discard);
1970a3348722SBarak Witkowski }
1971a3348722SBarak Witkowski }
1972a3097bdaSAriel Elior
bnx2x_stats_safe_exec(struct bnx2x * bp,void (func_to_exec)(void * cookie),void * cookie)1973dff173deSYuval Mintz int bnx2x_stats_safe_exec(struct bnx2x *bp,
1974a3097bdaSAriel Elior void (func_to_exec)(void *cookie),
1975dff173deSYuval Mintz void *cookie)
1976dff173deSYuval Mintz {
1977dff173deSYuval Mintz int cnt = 10, rc = 0;
1978dff173deSYuval Mintz
1979dff173deSYuval Mintz /* Wait for statistics to end [while blocking further requests],
1980dff173deSYuval Mintz * then run supplied function 'safely'.
1981dff173deSYuval Mintz */
1982c6e36d8cSYuval Mintz rc = down_timeout(&bp->stats_lock, HZ / 10);
1983c6e36d8cSYuval Mintz if (unlikely(rc)) {
1984c6e36d8cSYuval Mintz BNX2X_ERR("Failed to take statistics lock for safe execution\n");
1985c6e36d8cSYuval Mintz goto out_no_lock;
1986c6e36d8cSYuval Mintz }
1987dff173deSYuval Mintz
1988a3097bdaSAriel Elior bnx2x_stats_comp(bp);
1989dff173deSYuval Mintz while (bp->stats_pending && cnt--)
1990dff173deSYuval Mintz if (bnx2x_storm_stats_update(bp))
1991dff173deSYuval Mintz usleep_range(1000, 2000);
1992dff173deSYuval Mintz if (bp->stats_pending) {
1993dff173deSYuval Mintz BNX2X_ERR("Failed to wait for stats pending to clear [possibly FW is stuck]\n");
1994dff173deSYuval Mintz rc = -EBUSY;
1995dff173deSYuval Mintz goto out;
1996dff173deSYuval Mintz }
1997dff173deSYuval Mintz
1998a3097bdaSAriel Elior func_to_exec(cookie);
1999dff173deSYuval Mintz
2000dff173deSYuval Mintz out:
2001dff173deSYuval Mintz /* No need to restart statistics - if they're enabled, the timer
2002dff173deSYuval Mintz * will restart the statistics.
2003dff173deSYuval Mintz */
2004c6e36d8cSYuval Mintz up(&bp->stats_lock);
2005c6e36d8cSYuval Mintz out_no_lock:
2006dff173deSYuval Mintz return rc;
2007a3097bdaSAriel Elior }
2008