162306a36Sopenharmony_ci/* 262306a36Sopenharmony_ci * Broadcom NetXtreme-E RoCE driver. 362306a36Sopenharmony_ci * 462306a36Sopenharmony_ci * Copyright (c) 2016 - 2017, Broadcom. All rights reserved. The term 562306a36Sopenharmony_ci * Broadcom refers to Broadcom Limited and/or its subsidiaries. 662306a36Sopenharmony_ci * 762306a36Sopenharmony_ci * This software is available to you under a choice of one of two 862306a36Sopenharmony_ci * licenses. You may choose to be licensed under the terms of the GNU 962306a36Sopenharmony_ci * General Public License (GPL) Version 2, available from the file 1062306a36Sopenharmony_ci * COPYING in the main directory of this source tree, or the 1162306a36Sopenharmony_ci * BSD license below: 1262306a36Sopenharmony_ci * 1362306a36Sopenharmony_ci * Redistribution and use in source and binary forms, with or without 1462306a36Sopenharmony_ci * modification, are permitted provided that the following conditions 1562306a36Sopenharmony_ci * are met: 1662306a36Sopenharmony_ci * 1762306a36Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright 1862306a36Sopenharmony_ci * notice, this list of conditions and the following disclaimer. 1962306a36Sopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright 2062306a36Sopenharmony_ci * notice, this list of conditions and the following disclaimer in 2162306a36Sopenharmony_ci * the documentation and/or other materials provided with the 2262306a36Sopenharmony_ci * distribution. 2362306a36Sopenharmony_ci * 2462306a36Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' 2562306a36Sopenharmony_ci * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 2662306a36Sopenharmony_ci * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 2762306a36Sopenharmony_ci * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS 2862306a36Sopenharmony_ci * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2962306a36Sopenharmony_ci * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 3062306a36Sopenharmony_ci * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 3162306a36Sopenharmony_ci * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 3262306a36Sopenharmony_ci * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 3362306a36Sopenharmony_ci * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 3462306a36Sopenharmony_ci * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3562306a36Sopenharmony_ci * 3662306a36Sopenharmony_ci * Description: Statistics 3762306a36Sopenharmony_ci * 3862306a36Sopenharmony_ci */ 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_ci#include <linux/interrupt.h> 4162306a36Sopenharmony_ci#include <linux/types.h> 4262306a36Sopenharmony_ci#include <linux/spinlock.h> 4362306a36Sopenharmony_ci#include <linux/sched.h> 4462306a36Sopenharmony_ci#include <linux/slab.h> 4562306a36Sopenharmony_ci#include <linux/pci.h> 4662306a36Sopenharmony_ci#include <linux/prefetch.h> 4762306a36Sopenharmony_ci#include <linux/delay.h> 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_ci#include <rdma/ib_addr.h> 5062306a36Sopenharmony_ci 5162306a36Sopenharmony_ci#include "bnxt_ulp.h" 5262306a36Sopenharmony_ci#include "roce_hsi.h" 5362306a36Sopenharmony_ci#include "qplib_res.h" 5462306a36Sopenharmony_ci#include "qplib_sp.h" 5562306a36Sopenharmony_ci#include "qplib_fp.h" 5662306a36Sopenharmony_ci#include "qplib_rcfw.h" 5762306a36Sopenharmony_ci#include "bnxt_re.h" 5862306a36Sopenharmony_ci#include "hw_counters.h" 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_cistatic const struct rdma_stat_desc bnxt_re_stat_descs[] = { 6162306a36Sopenharmony_ci [BNXT_RE_ACTIVE_PD].name = "active_pds", 6262306a36Sopenharmony_ci [BNXT_RE_ACTIVE_AH].name = "active_ahs", 6362306a36Sopenharmony_ci [BNXT_RE_ACTIVE_QP].name = "active_qps", 6462306a36Sopenharmony_ci [BNXT_RE_ACTIVE_RC_QP].name = "active_rc_qps", 6562306a36Sopenharmony_ci [BNXT_RE_ACTIVE_UD_QP].name = "active_ud_qps", 6662306a36Sopenharmony_ci [BNXT_RE_ACTIVE_SRQ].name = "active_srqs", 6762306a36Sopenharmony_ci [BNXT_RE_ACTIVE_CQ].name = "active_cqs", 6862306a36Sopenharmony_ci [BNXT_RE_ACTIVE_MR].name = "active_mrs", 6962306a36Sopenharmony_ci [BNXT_RE_ACTIVE_MW].name = "active_mws", 7062306a36Sopenharmony_ci [BNXT_RE_WATERMARK_PD].name = "watermark_pds", 7162306a36Sopenharmony_ci [BNXT_RE_WATERMARK_AH].name = "watermark_ahs", 7262306a36Sopenharmony_ci [BNXT_RE_WATERMARK_QP].name = "watermark_qps", 7362306a36Sopenharmony_ci [BNXT_RE_WATERMARK_RC_QP].name = "watermark_rc_qps", 7462306a36Sopenharmony_ci [BNXT_RE_WATERMARK_UD_QP].name = "watermark_ud_qps", 7562306a36Sopenharmony_ci [BNXT_RE_WATERMARK_SRQ].name = "watermark_srqs", 7662306a36Sopenharmony_ci [BNXT_RE_WATERMARK_CQ].name = "watermark_cqs", 7762306a36Sopenharmony_ci [BNXT_RE_WATERMARK_MR].name = "watermark_mrs", 7862306a36Sopenharmony_ci [BNXT_RE_WATERMARK_MW].name = "watermark_mws", 7962306a36Sopenharmony_ci [BNXT_RE_RESIZE_CQ_CNT].name = "resize_cq_cnt", 8062306a36Sopenharmony_ci [BNXT_RE_RX_PKTS].name = "rx_pkts", 8162306a36Sopenharmony_ci [BNXT_RE_RX_BYTES].name = "rx_bytes", 8262306a36Sopenharmony_ci [BNXT_RE_TX_PKTS].name = "tx_pkts", 8362306a36Sopenharmony_ci [BNXT_RE_TX_BYTES].name = "tx_bytes", 8462306a36Sopenharmony_ci [BNXT_RE_RECOVERABLE_ERRORS].name = "recoverable_errors", 8562306a36Sopenharmony_ci [BNXT_RE_TX_ERRORS].name = "tx_roce_errors", 8662306a36Sopenharmony_ci [BNXT_RE_TX_DISCARDS].name = "tx_roce_discards", 8762306a36Sopenharmony_ci [BNXT_RE_RX_ERRORS].name = "rx_roce_errors", 8862306a36Sopenharmony_ci [BNXT_RE_RX_DISCARDS].name = "rx_roce_discards", 8962306a36Sopenharmony_ci [BNXT_RE_TO_RETRANSMITS].name = "to_retransmits", 9062306a36Sopenharmony_ci [BNXT_RE_SEQ_ERR_NAKS_RCVD].name = "seq_err_naks_rcvd", 9162306a36Sopenharmony_ci [BNXT_RE_MAX_RETRY_EXCEEDED].name = "max_retry_exceeded", 9262306a36Sopenharmony_ci [BNXT_RE_RNR_NAKS_RCVD].name = "rnr_naks_rcvd", 9362306a36Sopenharmony_ci [BNXT_RE_MISSING_RESP].name = "missing_resp", 9462306a36Sopenharmony_ci [BNXT_RE_UNRECOVERABLE_ERR].name = "unrecoverable_err", 9562306a36Sopenharmony_ci [BNXT_RE_BAD_RESP_ERR].name = "bad_resp_err", 9662306a36Sopenharmony_ci [BNXT_RE_LOCAL_QP_OP_ERR].name = "local_qp_op_err", 9762306a36Sopenharmony_ci [BNXT_RE_LOCAL_PROTECTION_ERR].name = "local_protection_err", 9862306a36Sopenharmony_ci [BNXT_RE_MEM_MGMT_OP_ERR].name = "mem_mgmt_op_err", 9962306a36Sopenharmony_ci [BNXT_RE_REMOTE_INVALID_REQ_ERR].name = "remote_invalid_req_err", 10062306a36Sopenharmony_ci [BNXT_RE_REMOTE_ACCESS_ERR].name = "remote_access_err", 10162306a36Sopenharmony_ci [BNXT_RE_REMOTE_OP_ERR].name = "remote_op_err", 10262306a36Sopenharmony_ci [BNXT_RE_DUP_REQ].name = "dup_req", 10362306a36Sopenharmony_ci [BNXT_RE_RES_EXCEED_MAX].name = "res_exceed_max", 10462306a36Sopenharmony_ci [BNXT_RE_RES_LENGTH_MISMATCH].name = "res_length_mismatch", 10562306a36Sopenharmony_ci [BNXT_RE_RES_EXCEEDS_WQE].name = "res_exceeds_wqe", 10662306a36Sopenharmony_ci [BNXT_RE_RES_OPCODE_ERR].name = "res_opcode_err", 10762306a36Sopenharmony_ci [BNXT_RE_RES_RX_INVALID_RKEY].name = "res_rx_invalid_rkey", 10862306a36Sopenharmony_ci [BNXT_RE_RES_RX_DOMAIN_ERR].name = "res_rx_domain_err", 10962306a36Sopenharmony_ci [BNXT_RE_RES_RX_NO_PERM].name = "res_rx_no_perm", 11062306a36Sopenharmony_ci [BNXT_RE_RES_RX_RANGE_ERR].name = "res_rx_range_err", 11162306a36Sopenharmony_ci [BNXT_RE_RES_TX_INVALID_RKEY].name = "res_tx_invalid_rkey", 11262306a36Sopenharmony_ci [BNXT_RE_RES_TX_DOMAIN_ERR].name = "res_tx_domain_err", 11362306a36Sopenharmony_ci [BNXT_RE_RES_TX_NO_PERM].name = "res_tx_no_perm", 11462306a36Sopenharmony_ci [BNXT_RE_RES_TX_RANGE_ERR].name = "res_tx_range_err", 11562306a36Sopenharmony_ci [BNXT_RE_RES_IRRQ_OFLOW].name = "res_irrq_oflow", 11662306a36Sopenharmony_ci [BNXT_RE_RES_UNSUP_OPCODE].name = "res_unsup_opcode", 11762306a36Sopenharmony_ci [BNXT_RE_RES_UNALIGNED_ATOMIC].name = "res_unaligned_atomic", 11862306a36Sopenharmony_ci [BNXT_RE_RES_REM_INV_ERR].name = "res_rem_inv_err", 11962306a36Sopenharmony_ci [BNXT_RE_RES_MEM_ERROR].name = "res_mem_err", 12062306a36Sopenharmony_ci [BNXT_RE_RES_SRQ_ERR].name = "res_srq_err", 12162306a36Sopenharmony_ci [BNXT_RE_RES_CMP_ERR].name = "res_cmp_err", 12262306a36Sopenharmony_ci [BNXT_RE_RES_INVALID_DUP_RKEY].name = "res_invalid_dup_rkey", 12362306a36Sopenharmony_ci [BNXT_RE_RES_WQE_FORMAT_ERR].name = "res_wqe_format_err", 12462306a36Sopenharmony_ci [BNXT_RE_RES_CQ_LOAD_ERR].name = "res_cq_load_err", 12562306a36Sopenharmony_ci [BNXT_RE_RES_SRQ_LOAD_ERR].name = "res_srq_load_err", 12662306a36Sopenharmony_ci [BNXT_RE_RES_TX_PCI_ERR].name = "res_tx_pci_err", 12762306a36Sopenharmony_ci [BNXT_RE_RES_RX_PCI_ERR].name = "res_rx_pci_err", 12862306a36Sopenharmony_ci [BNXT_RE_OUT_OF_SEQ_ERR].name = "oos_drop_count", 12962306a36Sopenharmony_ci [BNXT_RE_TX_ATOMIC_REQ].name = "tx_atomic_req", 13062306a36Sopenharmony_ci [BNXT_RE_TX_READ_REQ].name = "tx_read_req", 13162306a36Sopenharmony_ci [BNXT_RE_TX_READ_RES].name = "tx_read_resp", 13262306a36Sopenharmony_ci [BNXT_RE_TX_WRITE_REQ].name = "tx_write_req", 13362306a36Sopenharmony_ci [BNXT_RE_TX_SEND_REQ].name = "tx_send_req", 13462306a36Sopenharmony_ci [BNXT_RE_TX_ROCE_PKTS].name = "tx_roce_only_pkts", 13562306a36Sopenharmony_ci [BNXT_RE_TX_ROCE_BYTES].name = "tx_roce_only_bytes", 13662306a36Sopenharmony_ci [BNXT_RE_RX_ATOMIC_REQ].name = "rx_atomic_req", 13762306a36Sopenharmony_ci [BNXT_RE_RX_READ_REQ].name = "rx_read_req", 13862306a36Sopenharmony_ci [BNXT_RE_RX_READ_RESP].name = "rx_read_resp", 13962306a36Sopenharmony_ci [BNXT_RE_RX_WRITE_REQ].name = "rx_write_req", 14062306a36Sopenharmony_ci [BNXT_RE_RX_SEND_REQ].name = "rx_send_req", 14162306a36Sopenharmony_ci [BNXT_RE_RX_ROCE_PKTS].name = "rx_roce_only_pkts", 14262306a36Sopenharmony_ci [BNXT_RE_RX_ROCE_BYTES].name = "rx_roce_only_bytes", 14362306a36Sopenharmony_ci [BNXT_RE_RX_ROCE_GOOD_PKTS].name = "rx_roce_good_pkts", 14462306a36Sopenharmony_ci [BNXT_RE_RX_ROCE_GOOD_BYTES].name = "rx_roce_good_bytes", 14562306a36Sopenharmony_ci [BNXT_RE_OOB].name = "rx_out_of_buffer", 14662306a36Sopenharmony_ci [BNXT_RE_TX_CNP].name = "tx_cnp_pkts", 14762306a36Sopenharmony_ci [BNXT_RE_RX_CNP].name = "rx_cnp_pkts", 14862306a36Sopenharmony_ci [BNXT_RE_RX_ECN].name = "rx_ecn_marked_pkts", 14962306a36Sopenharmony_ci [BNXT_RE_PACING_RESCHED].name = "pacing_reschedule", 15062306a36Sopenharmony_ci [BNXT_RE_PACING_CMPL].name = "pacing_complete", 15162306a36Sopenharmony_ci [BNXT_RE_PACING_ALERT].name = "pacing_alerts", 15262306a36Sopenharmony_ci [BNXT_RE_DB_FIFO_REG].name = "db_fifo_register", 15362306a36Sopenharmony_ci}; 15462306a36Sopenharmony_ci 15562306a36Sopenharmony_cistatic void bnxt_re_copy_ext_stats(struct bnxt_re_dev *rdev, 15662306a36Sopenharmony_ci struct rdma_hw_stats *stats, 15762306a36Sopenharmony_ci struct bnxt_qplib_ext_stat *s) 15862306a36Sopenharmony_ci{ 15962306a36Sopenharmony_ci stats->value[BNXT_RE_TX_ATOMIC_REQ] = s->tx_atomic_req; 16062306a36Sopenharmony_ci stats->value[BNXT_RE_TX_READ_REQ] = s->tx_read_req; 16162306a36Sopenharmony_ci stats->value[BNXT_RE_TX_READ_RES] = s->tx_read_res; 16262306a36Sopenharmony_ci stats->value[BNXT_RE_TX_WRITE_REQ] = s->tx_write_req; 16362306a36Sopenharmony_ci stats->value[BNXT_RE_TX_SEND_REQ] = s->tx_send_req; 16462306a36Sopenharmony_ci stats->value[BNXT_RE_TX_ROCE_PKTS] = s->tx_roce_pkts; 16562306a36Sopenharmony_ci stats->value[BNXT_RE_TX_ROCE_BYTES] = s->tx_roce_bytes; 16662306a36Sopenharmony_ci stats->value[BNXT_RE_RX_ATOMIC_REQ] = s->rx_atomic_req; 16762306a36Sopenharmony_ci stats->value[BNXT_RE_RX_READ_REQ] = s->rx_read_req; 16862306a36Sopenharmony_ci stats->value[BNXT_RE_RX_READ_RESP] = s->rx_read_res; 16962306a36Sopenharmony_ci stats->value[BNXT_RE_RX_WRITE_REQ] = s->rx_write_req; 17062306a36Sopenharmony_ci stats->value[BNXT_RE_RX_SEND_REQ] = s->rx_send_req; 17162306a36Sopenharmony_ci stats->value[BNXT_RE_RX_ROCE_PKTS] = s->rx_roce_pkts; 17262306a36Sopenharmony_ci stats->value[BNXT_RE_RX_ROCE_BYTES] = s->rx_roce_bytes; 17362306a36Sopenharmony_ci stats->value[BNXT_RE_RX_ROCE_GOOD_PKTS] = s->rx_roce_good_pkts; 17462306a36Sopenharmony_ci stats->value[BNXT_RE_RX_ROCE_GOOD_BYTES] = s->rx_roce_good_bytes; 17562306a36Sopenharmony_ci stats->value[BNXT_RE_OOB] = s->rx_out_of_buffer; 17662306a36Sopenharmony_ci stats->value[BNXT_RE_TX_CNP] = s->tx_cnp; 17762306a36Sopenharmony_ci stats->value[BNXT_RE_RX_CNP] = s->rx_cnp; 17862306a36Sopenharmony_ci stats->value[BNXT_RE_RX_ECN] = s->rx_ecn_marked; 17962306a36Sopenharmony_ci stats->value[BNXT_RE_OUT_OF_SEQ_ERR] = s->rx_out_of_sequence; 18062306a36Sopenharmony_ci} 18162306a36Sopenharmony_ci 18262306a36Sopenharmony_cistatic int bnxt_re_get_ext_stat(struct bnxt_re_dev *rdev, 18362306a36Sopenharmony_ci struct rdma_hw_stats *stats) 18462306a36Sopenharmony_ci{ 18562306a36Sopenharmony_ci struct bnxt_qplib_ext_stat *estat = &rdev->stats.rstat.ext_stat; 18662306a36Sopenharmony_ci u32 fid; 18762306a36Sopenharmony_ci int rc; 18862306a36Sopenharmony_ci 18962306a36Sopenharmony_ci fid = PCI_FUNC(rdev->en_dev->pdev->devfn); 19062306a36Sopenharmony_ci rc = bnxt_qplib_qext_stat(&rdev->rcfw, fid, estat); 19162306a36Sopenharmony_ci if (rc) 19262306a36Sopenharmony_ci goto done; 19362306a36Sopenharmony_ci bnxt_re_copy_ext_stats(rdev, stats, estat); 19462306a36Sopenharmony_ci 19562306a36Sopenharmony_cidone: 19662306a36Sopenharmony_ci return rc; 19762306a36Sopenharmony_ci} 19862306a36Sopenharmony_ci 19962306a36Sopenharmony_cistatic void bnxt_re_copy_err_stats(struct bnxt_re_dev *rdev, 20062306a36Sopenharmony_ci struct rdma_hw_stats *stats, 20162306a36Sopenharmony_ci struct bnxt_qplib_roce_stats *err_s) 20262306a36Sopenharmony_ci{ 20362306a36Sopenharmony_ci stats->value[BNXT_RE_TO_RETRANSMITS] = 20462306a36Sopenharmony_ci err_s->to_retransmits; 20562306a36Sopenharmony_ci stats->value[BNXT_RE_SEQ_ERR_NAKS_RCVD] = 20662306a36Sopenharmony_ci err_s->seq_err_naks_rcvd; 20762306a36Sopenharmony_ci stats->value[BNXT_RE_MAX_RETRY_EXCEEDED] = 20862306a36Sopenharmony_ci err_s->max_retry_exceeded; 20962306a36Sopenharmony_ci stats->value[BNXT_RE_RNR_NAKS_RCVD] = 21062306a36Sopenharmony_ci err_s->rnr_naks_rcvd; 21162306a36Sopenharmony_ci stats->value[BNXT_RE_MISSING_RESP] = 21262306a36Sopenharmony_ci err_s->missing_resp; 21362306a36Sopenharmony_ci stats->value[BNXT_RE_UNRECOVERABLE_ERR] = 21462306a36Sopenharmony_ci err_s->unrecoverable_err; 21562306a36Sopenharmony_ci stats->value[BNXT_RE_BAD_RESP_ERR] = 21662306a36Sopenharmony_ci err_s->bad_resp_err; 21762306a36Sopenharmony_ci stats->value[BNXT_RE_LOCAL_QP_OP_ERR] = 21862306a36Sopenharmony_ci err_s->local_qp_op_err; 21962306a36Sopenharmony_ci stats->value[BNXT_RE_LOCAL_PROTECTION_ERR] = 22062306a36Sopenharmony_ci err_s->local_protection_err; 22162306a36Sopenharmony_ci stats->value[BNXT_RE_MEM_MGMT_OP_ERR] = 22262306a36Sopenharmony_ci err_s->mem_mgmt_op_err; 22362306a36Sopenharmony_ci stats->value[BNXT_RE_REMOTE_INVALID_REQ_ERR] = 22462306a36Sopenharmony_ci err_s->remote_invalid_req_err; 22562306a36Sopenharmony_ci stats->value[BNXT_RE_REMOTE_ACCESS_ERR] = 22662306a36Sopenharmony_ci err_s->remote_access_err; 22762306a36Sopenharmony_ci stats->value[BNXT_RE_REMOTE_OP_ERR] = 22862306a36Sopenharmony_ci err_s->remote_op_err; 22962306a36Sopenharmony_ci stats->value[BNXT_RE_DUP_REQ] = 23062306a36Sopenharmony_ci err_s->dup_req; 23162306a36Sopenharmony_ci stats->value[BNXT_RE_RES_EXCEED_MAX] = 23262306a36Sopenharmony_ci err_s->res_exceed_max; 23362306a36Sopenharmony_ci stats->value[BNXT_RE_RES_LENGTH_MISMATCH] = 23462306a36Sopenharmony_ci err_s->res_length_mismatch; 23562306a36Sopenharmony_ci stats->value[BNXT_RE_RES_EXCEEDS_WQE] = 23662306a36Sopenharmony_ci err_s->res_exceeds_wqe; 23762306a36Sopenharmony_ci stats->value[BNXT_RE_RES_OPCODE_ERR] = 23862306a36Sopenharmony_ci err_s->res_opcode_err; 23962306a36Sopenharmony_ci stats->value[BNXT_RE_RES_RX_INVALID_RKEY] = 24062306a36Sopenharmony_ci err_s->res_rx_invalid_rkey; 24162306a36Sopenharmony_ci stats->value[BNXT_RE_RES_RX_DOMAIN_ERR] = 24262306a36Sopenharmony_ci err_s->res_rx_domain_err; 24362306a36Sopenharmony_ci stats->value[BNXT_RE_RES_RX_NO_PERM] = 24462306a36Sopenharmony_ci err_s->res_rx_no_perm; 24562306a36Sopenharmony_ci stats->value[BNXT_RE_RES_RX_RANGE_ERR] = 24662306a36Sopenharmony_ci err_s->res_rx_range_err; 24762306a36Sopenharmony_ci stats->value[BNXT_RE_RES_TX_INVALID_RKEY] = 24862306a36Sopenharmony_ci err_s->res_tx_invalid_rkey; 24962306a36Sopenharmony_ci stats->value[BNXT_RE_RES_TX_DOMAIN_ERR] = 25062306a36Sopenharmony_ci err_s->res_tx_domain_err; 25162306a36Sopenharmony_ci stats->value[BNXT_RE_RES_TX_NO_PERM] = 25262306a36Sopenharmony_ci err_s->res_tx_no_perm; 25362306a36Sopenharmony_ci stats->value[BNXT_RE_RES_TX_RANGE_ERR] = 25462306a36Sopenharmony_ci err_s->res_tx_range_err; 25562306a36Sopenharmony_ci stats->value[BNXT_RE_RES_IRRQ_OFLOW] = 25662306a36Sopenharmony_ci err_s->res_irrq_oflow; 25762306a36Sopenharmony_ci stats->value[BNXT_RE_RES_UNSUP_OPCODE] = 25862306a36Sopenharmony_ci err_s->res_unsup_opcode; 25962306a36Sopenharmony_ci stats->value[BNXT_RE_RES_UNALIGNED_ATOMIC] = 26062306a36Sopenharmony_ci err_s->res_unaligned_atomic; 26162306a36Sopenharmony_ci stats->value[BNXT_RE_RES_REM_INV_ERR] = 26262306a36Sopenharmony_ci err_s->res_rem_inv_err; 26362306a36Sopenharmony_ci stats->value[BNXT_RE_RES_MEM_ERROR] = 26462306a36Sopenharmony_ci err_s->res_mem_error; 26562306a36Sopenharmony_ci stats->value[BNXT_RE_RES_SRQ_ERR] = 26662306a36Sopenharmony_ci err_s->res_srq_err; 26762306a36Sopenharmony_ci stats->value[BNXT_RE_RES_CMP_ERR] = 26862306a36Sopenharmony_ci err_s->res_cmp_err; 26962306a36Sopenharmony_ci stats->value[BNXT_RE_RES_INVALID_DUP_RKEY] = 27062306a36Sopenharmony_ci err_s->res_invalid_dup_rkey; 27162306a36Sopenharmony_ci stats->value[BNXT_RE_RES_WQE_FORMAT_ERR] = 27262306a36Sopenharmony_ci err_s->res_wqe_format_err; 27362306a36Sopenharmony_ci stats->value[BNXT_RE_RES_CQ_LOAD_ERR] = 27462306a36Sopenharmony_ci err_s->res_cq_load_err; 27562306a36Sopenharmony_ci stats->value[BNXT_RE_RES_SRQ_LOAD_ERR] = 27662306a36Sopenharmony_ci err_s->res_srq_load_err; 27762306a36Sopenharmony_ci stats->value[BNXT_RE_RES_TX_PCI_ERR] = 27862306a36Sopenharmony_ci err_s->res_tx_pci_err; 27962306a36Sopenharmony_ci stats->value[BNXT_RE_RES_RX_PCI_ERR] = 28062306a36Sopenharmony_ci err_s->res_rx_pci_err; 28162306a36Sopenharmony_ci stats->value[BNXT_RE_OUT_OF_SEQ_ERR] = 28262306a36Sopenharmony_ci err_s->res_oos_drop_count; 28362306a36Sopenharmony_ci} 28462306a36Sopenharmony_ci 28562306a36Sopenharmony_cistatic void bnxt_re_copy_db_pacing_stats(struct bnxt_re_dev *rdev, 28662306a36Sopenharmony_ci struct rdma_hw_stats *stats) 28762306a36Sopenharmony_ci{ 28862306a36Sopenharmony_ci struct bnxt_re_db_pacing_stats *pacing_s = &rdev->stats.pacing; 28962306a36Sopenharmony_ci 29062306a36Sopenharmony_ci stats->value[BNXT_RE_PACING_RESCHED] = pacing_s->resched; 29162306a36Sopenharmony_ci stats->value[BNXT_RE_PACING_CMPL] = pacing_s->complete; 29262306a36Sopenharmony_ci stats->value[BNXT_RE_PACING_ALERT] = pacing_s->alerts; 29362306a36Sopenharmony_ci stats->value[BNXT_RE_DB_FIFO_REG] = 29462306a36Sopenharmony_ci readl(rdev->en_dev->bar0 + rdev->pacing.dbr_db_fifo_reg_off); 29562306a36Sopenharmony_ci} 29662306a36Sopenharmony_ci 29762306a36Sopenharmony_ciint bnxt_re_ib_get_hw_stats(struct ib_device *ibdev, 29862306a36Sopenharmony_ci struct rdma_hw_stats *stats, 29962306a36Sopenharmony_ci u32 port, int index) 30062306a36Sopenharmony_ci{ 30162306a36Sopenharmony_ci struct bnxt_re_dev *rdev = to_bnxt_re_dev(ibdev, ibdev); 30262306a36Sopenharmony_ci struct bnxt_re_res_cntrs *res_s = &rdev->stats.res; 30362306a36Sopenharmony_ci struct bnxt_qplib_roce_stats *err_s = NULL; 30462306a36Sopenharmony_ci struct ctx_hw_stats *hw_stats = NULL; 30562306a36Sopenharmony_ci int rc = 0; 30662306a36Sopenharmony_ci 30762306a36Sopenharmony_ci hw_stats = rdev->qplib_ctx.stats.dma; 30862306a36Sopenharmony_ci if (!port || !stats) 30962306a36Sopenharmony_ci return -EINVAL; 31062306a36Sopenharmony_ci 31162306a36Sopenharmony_ci stats->value[BNXT_RE_ACTIVE_QP] = atomic_read(&res_s->qp_count); 31262306a36Sopenharmony_ci stats->value[BNXT_RE_ACTIVE_RC_QP] = atomic_read(&res_s->rc_qp_count); 31362306a36Sopenharmony_ci stats->value[BNXT_RE_ACTIVE_UD_QP] = atomic_read(&res_s->ud_qp_count); 31462306a36Sopenharmony_ci stats->value[BNXT_RE_ACTIVE_SRQ] = atomic_read(&res_s->srq_count); 31562306a36Sopenharmony_ci stats->value[BNXT_RE_ACTIVE_CQ] = atomic_read(&res_s->cq_count); 31662306a36Sopenharmony_ci stats->value[BNXT_RE_ACTIVE_MR] = atomic_read(&res_s->mr_count); 31762306a36Sopenharmony_ci stats->value[BNXT_RE_ACTIVE_MW] = atomic_read(&res_s->mw_count); 31862306a36Sopenharmony_ci stats->value[BNXT_RE_ACTIVE_PD] = atomic_read(&res_s->pd_count); 31962306a36Sopenharmony_ci stats->value[BNXT_RE_ACTIVE_AH] = atomic_read(&res_s->ah_count); 32062306a36Sopenharmony_ci stats->value[BNXT_RE_WATERMARK_QP] = res_s->qp_watermark; 32162306a36Sopenharmony_ci stats->value[BNXT_RE_WATERMARK_RC_QP] = res_s->rc_qp_watermark; 32262306a36Sopenharmony_ci stats->value[BNXT_RE_WATERMARK_UD_QP] = res_s->ud_qp_watermark; 32362306a36Sopenharmony_ci stats->value[BNXT_RE_WATERMARK_SRQ] = res_s->srq_watermark; 32462306a36Sopenharmony_ci stats->value[BNXT_RE_WATERMARK_CQ] = res_s->cq_watermark; 32562306a36Sopenharmony_ci stats->value[BNXT_RE_WATERMARK_MR] = res_s->mr_watermark; 32662306a36Sopenharmony_ci stats->value[BNXT_RE_WATERMARK_MW] = res_s->mw_watermark; 32762306a36Sopenharmony_ci stats->value[BNXT_RE_WATERMARK_PD] = res_s->pd_watermark; 32862306a36Sopenharmony_ci stats->value[BNXT_RE_WATERMARK_AH] = res_s->ah_watermark; 32962306a36Sopenharmony_ci stats->value[BNXT_RE_RESIZE_CQ_CNT] = atomic_read(&res_s->resize_count); 33062306a36Sopenharmony_ci 33162306a36Sopenharmony_ci if (hw_stats) { 33262306a36Sopenharmony_ci stats->value[BNXT_RE_RECOVERABLE_ERRORS] = 33362306a36Sopenharmony_ci le64_to_cpu(hw_stats->tx_bcast_pkts); 33462306a36Sopenharmony_ci stats->value[BNXT_RE_TX_DISCARDS] = 33562306a36Sopenharmony_ci le64_to_cpu(hw_stats->tx_discard_pkts); 33662306a36Sopenharmony_ci stats->value[BNXT_RE_TX_ERRORS] = 33762306a36Sopenharmony_ci le64_to_cpu(hw_stats->tx_error_pkts); 33862306a36Sopenharmony_ci stats->value[BNXT_RE_RX_ERRORS] = 33962306a36Sopenharmony_ci le64_to_cpu(hw_stats->rx_error_pkts); 34062306a36Sopenharmony_ci stats->value[BNXT_RE_RX_DISCARDS] = 34162306a36Sopenharmony_ci le64_to_cpu(hw_stats->rx_discard_pkts); 34262306a36Sopenharmony_ci stats->value[BNXT_RE_RX_PKTS] = 34362306a36Sopenharmony_ci le64_to_cpu(hw_stats->rx_ucast_pkts); 34462306a36Sopenharmony_ci stats->value[BNXT_RE_RX_BYTES] = 34562306a36Sopenharmony_ci le64_to_cpu(hw_stats->rx_ucast_bytes); 34662306a36Sopenharmony_ci stats->value[BNXT_RE_TX_PKTS] = 34762306a36Sopenharmony_ci le64_to_cpu(hw_stats->tx_ucast_pkts); 34862306a36Sopenharmony_ci stats->value[BNXT_RE_TX_BYTES] = 34962306a36Sopenharmony_ci le64_to_cpu(hw_stats->tx_ucast_bytes); 35062306a36Sopenharmony_ci } 35162306a36Sopenharmony_ci err_s = &rdev->stats.rstat.errs; 35262306a36Sopenharmony_ci if (test_bit(BNXT_RE_FLAG_ISSUE_ROCE_STATS, &rdev->flags)) { 35362306a36Sopenharmony_ci rc = bnxt_qplib_get_roce_stats(&rdev->rcfw, err_s); 35462306a36Sopenharmony_ci if (rc) { 35562306a36Sopenharmony_ci clear_bit(BNXT_RE_FLAG_ISSUE_ROCE_STATS, 35662306a36Sopenharmony_ci &rdev->flags); 35762306a36Sopenharmony_ci goto done; 35862306a36Sopenharmony_ci } 35962306a36Sopenharmony_ci bnxt_re_copy_err_stats(rdev, stats, err_s); 36062306a36Sopenharmony_ci if (_is_ext_stats_supported(rdev->dev_attr.dev_cap_flags) && 36162306a36Sopenharmony_ci !rdev->is_virtfn) { 36262306a36Sopenharmony_ci rc = bnxt_re_get_ext_stat(rdev, stats); 36362306a36Sopenharmony_ci if (rc) { 36462306a36Sopenharmony_ci clear_bit(BNXT_RE_FLAG_ISSUE_ROCE_STATS, 36562306a36Sopenharmony_ci &rdev->flags); 36662306a36Sopenharmony_ci goto done; 36762306a36Sopenharmony_ci } 36862306a36Sopenharmony_ci } 36962306a36Sopenharmony_ci if (rdev->pacing.dbr_pacing) 37062306a36Sopenharmony_ci bnxt_re_copy_db_pacing_stats(rdev, stats); 37162306a36Sopenharmony_ci } 37262306a36Sopenharmony_ci 37362306a36Sopenharmony_cidone: 37462306a36Sopenharmony_ci return bnxt_qplib_is_chip_gen_p5(rdev->chip_ctx) ? 37562306a36Sopenharmony_ci BNXT_RE_NUM_EXT_COUNTERS : BNXT_RE_NUM_STD_COUNTERS; 37662306a36Sopenharmony_ci} 37762306a36Sopenharmony_ci 37862306a36Sopenharmony_cistruct rdma_hw_stats *bnxt_re_ib_alloc_hw_port_stats(struct ib_device *ibdev, 37962306a36Sopenharmony_ci u32 port_num) 38062306a36Sopenharmony_ci{ 38162306a36Sopenharmony_ci struct bnxt_re_dev *rdev = to_bnxt_re_dev(ibdev, ibdev); 38262306a36Sopenharmony_ci int num_counters = 0; 38362306a36Sopenharmony_ci 38462306a36Sopenharmony_ci if (bnxt_qplib_is_chip_gen_p5(rdev->chip_ctx)) 38562306a36Sopenharmony_ci num_counters = BNXT_RE_NUM_EXT_COUNTERS; 38662306a36Sopenharmony_ci else 38762306a36Sopenharmony_ci num_counters = BNXT_RE_NUM_STD_COUNTERS; 38862306a36Sopenharmony_ci 38962306a36Sopenharmony_ci return rdma_alloc_hw_stats_struct(bnxt_re_stat_descs, num_counters, 39062306a36Sopenharmony_ci RDMA_HW_STATS_DEFAULT_LIFESPAN); 39162306a36Sopenharmony_ci} 392