Skip to content

Commit f967488

Browse files
Linu Cheriandavem330
authored andcommitted
octeontx2-af: Add per CGX port level NIX Rx/Tx counters
A CGX port is shared by a RVU PF and it's VFs. These per CGX port level NIX Rx/Tx counters are cumilative stats of all NIXLFs sharing this port. These stats when compared to CGX Rx/Tx stats helps in identifying pkts dropped within the system, if any. Signed-off-by: Linu Cherian <lcherian@marvell.com> Signed-off-by: Sunil Goutham <sgoutham@marvell.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent c57211b commit f967488

File tree

5 files changed

+173
-2
lines changed

5 files changed

+173
-2
lines changed

drivers/net/ethernet/marvell/octeontx2/af/cgx.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,16 @@ void *cgx_get_pdata(int cgx_id)
138138
}
139139
EXPORT_SYMBOL(cgx_get_pdata);
140140

141+
int cgx_get_cgxid(void *cgxd)
142+
{
143+
struct cgx *cgx = cgxd;
144+
145+
if (!cgx)
146+
return -EINVAL;
147+
148+
return cgx->cgx_id;
149+
}
150+
141151
/* Ensure the required lock for event queue(where asynchronous events are
142152
* posted) is acquired before calling this API. Else an asynchronous event(with
143153
* latest link status) can reach the destination before this function returns

drivers/net/ethernet/marvell/octeontx2/af/cgx.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@
6363
#define CGX_NVEC 37
6464
#define CGX_LMAC_FWI 0
6565

66+
enum cgx_nix_stat_type {
67+
NIX_STATS_RX,
68+
NIX_STATS_TX,
69+
};
70+
6671
enum LMAC_TYPE {
6772
LMAC_MODE_SGMII = 0,
6873
LMAC_MODE_XAUI = 1,
@@ -96,6 +101,7 @@ struct cgx_event_cb {
96101
extern struct pci_driver cgx_driver;
97102

98103
int cgx_get_cgxcnt_max(void);
104+
int cgx_get_cgxid(void *cgxd);
99105
int cgx_get_lmac_cnt(void *cgxd);
100106
void *cgx_get_pdata(int cgx_id);
101107
int cgx_set_pkind(void *cgxd, u8 lmac_id, int pkind);

drivers/net/ethernet/marvell/octeontx2/af/rvu.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,8 @@ int rvu_cgx_init(struct rvu *rvu);
374374
int rvu_cgx_exit(struct rvu *rvu);
375375
void *rvu_cgx_pdata(u8 cgx_id, struct rvu *rvu);
376376
int rvu_cgx_config_rxtx(struct rvu *rvu, u16 pcifunc, bool start);
377+
int rvu_cgx_nix_cuml_stats(struct rvu *rvu, void *cgxd, int lmac_id, int index,
378+
int rxtxflag, u64 *stat);
377379
int rvu_mbox_handler_cgx_start_rxtx(struct rvu *rvu, struct msg_req *req,
378380
struct msg_rsp *rsp);
379381
int rvu_mbox_handler_cgx_stop_rxtx(struct rvu *rvu, struct msg_req *req,

drivers/net/ethernet/marvell/octeontx2/af/rvu_cgx.c

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "rvu.h"
1616
#include "cgx.h"
17+
#include "rvu_reg.h"
1718

1819
struct cgx_evq_entry {
1920
struct list_head evq_node;
@@ -40,12 +41,25 @@ MBOX_UP_CGX_MESSAGES
4041
#undef M
4142

4243
/* Returns bitmap of mapped PFs */
43-
static inline u16 cgxlmac_to_pfmap(struct rvu *rvu, u8 cgx_id, u8 lmac_id)
44+
static u16 cgxlmac_to_pfmap(struct rvu *rvu, u8 cgx_id, u8 lmac_id)
4445
{
4546
return rvu->cgxlmac2pf_map[CGX_OFFSET(cgx_id) + lmac_id];
4647
}
4748

48-
static inline u8 cgxlmac_id_to_bmap(u8 cgx_id, u8 lmac_id)
49+
static int cgxlmac_to_pf(struct rvu *rvu, int cgx_id, int lmac_id)
50+
{
51+
unsigned long pfmap;
52+
53+
pfmap = cgxlmac_to_pfmap(rvu, cgx_id, lmac_id);
54+
55+
/* Assumes only one pf mapped to a cgx lmac port */
56+
if (!pfmap)
57+
return -ENODEV;
58+
else
59+
return find_first_bit(&pfmap, 16);
60+
}
61+
62+
static u8 cgxlmac_id_to_bmap(u8 cgx_id, u8 lmac_id)
4963
{
5064
return ((cgx_id & 0xF) << 4) | (lmac_id & 0xF);
5165
}
@@ -562,3 +576,47 @@ int rvu_mbox_handler_cgx_intlbk_disable(struct rvu *rvu, struct msg_req *req,
562576
rvu_cgx_config_intlbk(rvu, req->hdr.pcifunc, false);
563577
return 0;
564578
}
579+
580+
/* Finds cumulative status of NIX rx/tx counters from LF of a PF and those
581+
* from its VFs as well. ie. NIX rx/tx counters at the CGX port level
582+
*/
583+
int rvu_cgx_nix_cuml_stats(struct rvu *rvu, void *cgxd, int lmac_id,
584+
int index, int rxtxflag, u64 *stat)
585+
{
586+
struct rvu_block *block;
587+
int blkaddr;
588+
u16 pcifunc;
589+
int pf, lf;
590+
591+
if (!cgxd || !rvu)
592+
return -EINVAL;
593+
594+
pf = cgxlmac_to_pf(rvu, cgx_get_cgxid(cgxd), lmac_id);
595+
if (pf < 0)
596+
return pf;
597+
598+
/* Assumes LF of a PF and all of its VF belongs to the same
599+
* NIX block
600+
*/
601+
pcifunc = pf << RVU_PFVF_PF_SHIFT;
602+
blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NIX, pcifunc);
603+
if (blkaddr < 0)
604+
return 0;
605+
block = &rvu->hw->block[blkaddr];
606+
607+
*stat = 0;
608+
for (lf = 0; lf < block->lf.max; lf++) {
609+
/* Check if a lf is attached to this PF or one of its VFs */
610+
if (!((block->fn_map[lf] & ~RVU_PFVF_FUNC_MASK) == (pcifunc &
611+
~RVU_PFVF_FUNC_MASK)))
612+
continue;
613+
if (rxtxflag == NIX_STATS_RX)
614+
*stat += rvu_read64(rvu, blkaddr,
615+
NIX_AF_LFX_RX_STATX(lf, index));
616+
else
617+
*stat += rvu_read64(rvu, blkaddr,
618+
NIX_AF_LFX_TX_STATX(lf, index));
619+
}
620+
621+
return 0;
622+
}

drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,33 @@ enum {
4444
CGX_STAT18,
4545
};
4646

47+
/* NIX TX stats */
48+
enum nix_stat_lf_tx {
49+
TX_UCAST = 0x0,
50+
TX_BCAST = 0x1,
51+
TX_MCAST = 0x2,
52+
TX_DROP = 0x3,
53+
TX_OCTS = 0x4,
54+
TX_STATS_ENUM_LAST,
55+
};
56+
57+
/* NIX RX stats */
58+
enum nix_stat_lf_rx {
59+
RX_OCTS = 0x0,
60+
RX_UCAST = 0x1,
61+
RX_BCAST = 0x2,
62+
RX_MCAST = 0x3,
63+
RX_DROP = 0x4,
64+
RX_DROP_OCTS = 0x5,
65+
RX_FCS = 0x6,
66+
RX_ERR = 0x7,
67+
RX_DRP_BCAST = 0x8,
68+
RX_DRP_MCAST = 0x9,
69+
RX_DRP_L3BCAST = 0xa,
70+
RX_DRP_L3MCAST = 0xb,
71+
RX_STATS_ENUM_LAST,
72+
};
73+
4774
static char *cgx_rx_stats_fields[] = {
4875
[CGX_STAT0] = "Received packets",
4976
[CGX_STAT1] = "Octets of received packets",
@@ -1329,12 +1356,39 @@ static void rvu_dbg_npa_init(struct rvu *rvu)
13291356
debugfs_remove_recursive(rvu->rvu_dbg.npa);
13301357
}
13311358

1359+
#define PRINT_CGX_CUML_NIXRX_STATUS(idx, name) \
1360+
({ \
1361+
u64 cnt; \
1362+
err = rvu_cgx_nix_cuml_stats(rvu, cgxd, lmac_id, (idx), \
1363+
NIX_STATS_RX, &(cnt)); \
1364+
if (!err) \
1365+
seq_printf(s, "%s: %llu\n", name, cnt); \
1366+
cnt; \
1367+
})
1368+
1369+
#define PRINT_CGX_CUML_NIXTX_STATUS(idx, name) \
1370+
({ \
1371+
u64 cnt; \
1372+
err = rvu_cgx_nix_cuml_stats(rvu, cgxd, lmac_id, (idx), \
1373+
NIX_STATS_TX, &(cnt)); \
1374+
if (!err) \
1375+
seq_printf(s, "%s: %llu\n", name, cnt); \
1376+
cnt; \
1377+
})
1378+
13321379
static int cgx_print_stats(struct seq_file *s, int lmac_id)
13331380
{
13341381
struct cgx_link_user_info linfo;
13351382
void *cgxd = s->private;
1383+
u64 ucast, mcast, bcast;
13361384
int stat = 0, err = 0;
13371385
u64 tx_stat, rx_stat;
1386+
struct rvu *rvu;
1387+
1388+
rvu = pci_get_drvdata(pci_get_device(PCI_VENDOR_ID_CAVIUM,
1389+
PCI_DEVID_OCTEONTX2_RVU_AF, NULL));
1390+
if (!rvu)
1391+
return -ENODEV;
13381392

13391393
/* Link status */
13401394
seq_puts(s, "\n=======Link Status======\n\n");
@@ -1344,6 +1398,47 @@ static int cgx_print_stats(struct seq_file *s, int lmac_id)
13441398
seq_printf(s, "\nLink is %s %d Mbps\n\n",
13451399
linfo.link_up ? "UP" : "DOWN", linfo.speed);
13461400

1401+
/* Rx stats */
1402+
seq_puts(s, "\n=======NIX RX_STATS(CGX port level)======\n\n");
1403+
ucast = PRINT_CGX_CUML_NIXRX_STATUS(RX_UCAST, "rx_ucast_frames");
1404+
if (err)
1405+
return err;
1406+
mcast = PRINT_CGX_CUML_NIXRX_STATUS(RX_MCAST, "rx_mcast_frames");
1407+
if (err)
1408+
return err;
1409+
bcast = PRINT_CGX_CUML_NIXRX_STATUS(RX_BCAST, "rx_bcast_frames");
1410+
if (err)
1411+
return err;
1412+
seq_printf(s, "rx_frames: %llu\n", ucast + mcast + bcast);
1413+
PRINT_CGX_CUML_NIXRX_STATUS(RX_OCTS, "rx_bytes");
1414+
if (err)
1415+
return err;
1416+
PRINT_CGX_CUML_NIXRX_STATUS(RX_DROP, "rx_drops");
1417+
if (err)
1418+
return err;
1419+
PRINT_CGX_CUML_NIXRX_STATUS(RX_ERR, "rx_errors");
1420+
if (err)
1421+
return err;
1422+
1423+
/* Tx stats */
1424+
seq_puts(s, "\n=======NIX TX_STATS(CGX port level)======\n\n");
1425+
ucast = PRINT_CGX_CUML_NIXTX_STATUS(TX_UCAST, "tx_ucast_frames");
1426+
if (err)
1427+
return err;
1428+
mcast = PRINT_CGX_CUML_NIXTX_STATUS(TX_MCAST, "tx_mcast_frames");
1429+
if (err)
1430+
return err;
1431+
bcast = PRINT_CGX_CUML_NIXTX_STATUS(TX_BCAST, "tx_bcast_frames");
1432+
if (err)
1433+
return err;
1434+
seq_printf(s, "tx_frames: %llu\n", ucast + mcast + bcast);
1435+
PRINT_CGX_CUML_NIXTX_STATUS(TX_OCTS, "tx_bytes");
1436+
if (err)
1437+
return err;
1438+
PRINT_CGX_CUML_NIXTX_STATUS(TX_DROP, "tx_drops");
1439+
if (err)
1440+
return err;
1441+
13471442
/* Rx stats */
13481443
seq_puts(s, "\n=======CGX RX_STATS======\n\n");
13491444
while (stat < CGX_RX_STATS_COUNT) {

0 commit comments

Comments
 (0)