#include <inttypes.h>
#include "roc_api.h"
+#include "roc_nix_xstats.h"
#include "roc_priv.h"
#define NIX_RX_STATS(val) plt_read64(nix->base + NIX_LF_RX_STATX(val))
#define NIX_TX_STATS(val) plt_read64(nix->base + NIX_LF_TX_STATX(val))
+int
+roc_nix_num_xstats_get(struct roc_nix *roc_nix)
+{
+ if (roc_nix_is_vf_or_sdp(roc_nix))
+ return CNXK_NIX_NUM_XSTATS_REG;
+ else if (roc_model_is_cn9k())
+ return CNXK_NIX_NUM_XSTATS_CGX;
+
+ return CNXK_NIX_NUM_XSTATS_RPM;
+}
+
int
roc_nix_stats_get(struct roc_nix *roc_nix, struct roc_nix_stats *stats)
{
struct nix_aq_enq_req *aq;
aq = mbox_alloc_msg_nix_aq_enq(mbox);
+ if (!aq)
+ return -ENOSPC;
+
aq->qidx = qid;
aq->ctype = NIX_AQ_CTYPE_RQ;
aq->op = NIX_AQ_INSTOP_WRITE;
struct nix_cn10k_aq_enq_req *aq;
aq = mbox_alloc_msg_nix_cn10k_aq_enq(mbox);
+ if (!aq)
+ return -ENOSPC;
+
aq->qidx = qid;
aq->ctype = NIX_AQ_CTYPE_RQ;
aq->op = NIX_AQ_INSTOP_WRITE;
struct nix_aq_enq_req *aq;
aq = mbox_alloc_msg_nix_aq_enq(mbox);
+ if (!aq)
+ return -ENOSPC;
+
aq->qidx = qid;
aq->ctype = NIX_AQ_CTYPE_SQ;
aq->op = NIX_AQ_INSTOP_WRITE;
struct nix_cn10k_aq_enq_req *aq;
aq = mbox_alloc_msg_nix_cn10k_aq_enq(mbox);
+ if (!aq)
+ return -ENOSPC;
+
aq->qidx = qid;
aq->ctype = NIX_AQ_CTYPE_SQ;
aq->op = NIX_AQ_INSTOP_WRITE;
fail:
return rc;
}
+
+int
+roc_nix_xstats_get(struct roc_nix *roc_nix, struct roc_nix_xstat *xstats,
+ unsigned int n)
+{
+ struct nix *nix = roc_nix_to_nix_priv(roc_nix);
+ struct mbox *mbox = (&nix->dev)->mbox;
+ struct cgx_stats_rsp *cgx_resp;
+ struct rpm_stats_rsp *rpm_resp;
+ uint64_t i, count = 0;
+ struct msg_req *req;
+ uint32_t xstat_cnt;
+ int rc;
+
+ xstat_cnt = roc_nix_num_xstats_get(roc_nix);
+ if (n < xstat_cnt)
+ return xstat_cnt;
+
+ if (xstats == NULL)
+ return -EINVAL;
+
+ memset(xstats, 0, (xstat_cnt * sizeof(*xstats)));
+ for (i = 0; i < CNXK_NIX_NUM_TX_XSTATS; i++) {
+ xstats[count].value = NIX_TX_STATS(nix_tx_xstats[i].offset);
+ xstats[count].id = count;
+ count++;
+ }
+
+ for (i = 0; i < CNXK_NIX_NUM_RX_XSTATS; i++) {
+ xstats[count].value = NIX_RX_STATS(nix_rx_xstats[i].offset);
+ xstats[count].id = count;
+ count++;
+ }
+
+ for (i = 0; i < nix->nb_rx_queues; i++)
+ xstats[count].value +=
+ qstat_read(nix, i, nix_q_xstats[0].offset);
+
+ xstats[count].id = count;
+ count++;
+
+ if (roc_nix_is_vf_or_sdp(roc_nix))
+ return count;
+
+ if (roc_model_is_cn9k()) {
+ req = mbox_alloc_msg_cgx_stats(mbox);
+ if (!req)
+ return -ENOSPC;
+
+ req->hdr.pcifunc = roc_nix_get_pf_func(roc_nix);
+
+ rc = mbox_process_msg(mbox, (void *)&cgx_resp);
+ if (rc)
+ return rc;
+
+ for (i = 0; i < roc_nix_num_rx_xstats(); i++) {
+ xstats[count].value =
+ cgx_resp->rx_stats[nix_rx_xstats_cgx[i].offset];
+ xstats[count].id = count;
+ count++;
+ }
+
+ for (i = 0; i < roc_nix_num_tx_xstats(); i++) {
+ xstats[count].value =
+ cgx_resp->tx_stats[nix_tx_xstats_cgx[i].offset];
+ xstats[count].id = count;
+ count++;
+ }
+ } else {
+ req = mbox_alloc_msg_rpm_stats(mbox);
+ if (!req)
+ return -ENOSPC;
+
+ req->hdr.pcifunc = roc_nix_get_pf_func(roc_nix);
+
+ rc = mbox_process_msg(mbox, (void *)&rpm_resp);
+ if (rc)
+ return rc;
+
+ for (i = 0; i < roc_nix_num_rx_xstats(); i++) {
+ xstats[count].value =
+ rpm_resp->rx_stats[nix_rx_xstats_rpm[i].offset];
+ xstats[count].id = count;
+ count++;
+ }
+
+ for (i = 0; i < roc_nix_num_tx_xstats(); i++) {
+ xstats[count].value =
+ rpm_resp->tx_stats[nix_tx_xstats_rpm[i].offset];
+ xstats[count].id = count;
+ count++;
+ }
+
+ for (i = 0; i < CNXK_NIX_NUM_CN10K_RX_XSTATS; i++) {
+ xstats[count].value =
+ NIX_RX_STATS(nix_cn10k_rx_xstats[i].offset);
+ xstats[count].id = count;
+ count++;
+ }
+ }
+
+ return count;
+}
+
+int
+roc_nix_xstats_names_get(struct roc_nix *roc_nix,
+ struct roc_nix_xstat_name *xstats_names,
+ unsigned int limit)
+{
+ uint64_t i, count = 0;
+ uint32_t xstat_cnt;
+
+ xstat_cnt = roc_nix_num_xstats_get(roc_nix);
+ if (limit < xstat_cnt && xstats_names != NULL)
+ return -ENOMEM;
+
+ if (xstats_names) {
+ for (i = 0; i < CNXK_NIX_NUM_TX_XSTATS; i++) {
+ snprintf(xstats_names[count].name,
+ sizeof(xstats_names[count].name), "%s",
+ nix_tx_xstats[i].name);
+ count++;
+ }
+
+ for (i = 0; i < CNXK_NIX_NUM_RX_XSTATS; i++) {
+ snprintf(xstats_names[count].name,
+ sizeof(xstats_names[count].name), "%s",
+ nix_rx_xstats[i].name);
+ count++;
+ }
+ for (i = 0; i < CNXK_NIX_NUM_QUEUE_XSTATS; i++) {
+ snprintf(xstats_names[count].name,
+ sizeof(xstats_names[count].name), "%s",
+ nix_q_xstats[i].name);
+ count++;
+ }
+
+ if (roc_nix_is_vf_or_sdp(roc_nix))
+ return count;
+
+ if (roc_model_is_cn9k()) {
+ for (i = 0; i < roc_nix_num_rx_xstats(); i++) {
+ snprintf(xstats_names[count].name,
+ sizeof(xstats_names[count].name), "%s",
+ nix_rx_xstats_cgx[i].name);
+ count++;
+ }
+
+ for (i = 0; i < roc_nix_num_tx_xstats(); i++) {
+ snprintf(xstats_names[count].name,
+ sizeof(xstats_names[count].name), "%s",
+ nix_tx_xstats_cgx[i].name);
+ count++;
+ }
+ } else {
+ for (i = 0; i < roc_nix_num_rx_xstats(); i++) {
+ snprintf(xstats_names[count].name,
+ sizeof(xstats_names[count].name), "%s",
+ nix_rx_xstats_rpm[i].name);
+ count++;
+ }
+
+ for (i = 0; i < roc_nix_num_tx_xstats(); i++) {
+ snprintf(xstats_names[count].name,
+ sizeof(xstats_names[count].name), "%s",
+ nix_tx_xstats_rpm[i].name);
+ count++;
+ }
+
+ for (i = 0; i < CNXK_NIX_NUM_CN10K_RX_XSTATS; i++) {
+ snprintf(xstats_names[count].name,
+ sizeof(xstats_names[count].name), "%s",
+ nix_cn10k_rx_xstats[i].name);
+ count++;
+ }
+ }
+ }
+
+ return xstat_cnt;
+}