Skip to content

Commit 940754a

Browse files
Geetha sowjanyadavem330
authored andcommitted
octeontx2-pf: Get VF stats via representor
Adds support to export VF port statistics via representor netdev. Defines new mbox "NIX_LF_STATS" to fetch VF hw stats. Signed-off-by: Geetha sowjanya <[email protected]> Reviewed-by: Simon Horman <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 683645a commit 940754a

File tree

7 files changed

+180
-54
lines changed

7 files changed

+180
-54
lines changed

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ M(NIX_MCAST_GRP_DESTROY, 0x802c, nix_mcast_grp_destroy, nix_mcast_grp_destroy_re
321321
M(NIX_MCAST_GRP_UPDATE, 0x802d, nix_mcast_grp_update, \
322322
nix_mcast_grp_update_req, \
323323
nix_mcast_grp_update_rsp) \
324+
M(NIX_LF_STATS, 0x802e, nix_lf_stats, nix_stats_req, nix_stats_rsp) \
324325
/* MCS mbox IDs (range 0xA000 - 0xBFFF) */ \
325326
M(MCS_ALLOC_RESOURCES, 0xa000, mcs_alloc_resources, mcs_alloc_rsrc_req, \
326327
mcs_alloc_rsrc_rsp) \
@@ -1366,6 +1367,37 @@ struct nix_bandprof_get_hwinfo_rsp {
13661367
u32 policer_timeunit;
13671368
};
13681369

1370+
struct nix_stats_req {
1371+
struct mbox_msghdr hdr;
1372+
u8 reset;
1373+
u16 pcifunc;
1374+
u64 rsvd;
1375+
};
1376+
1377+
struct nix_stats_rsp {
1378+
struct mbox_msghdr hdr;
1379+
u16 pcifunc;
1380+
struct {
1381+
u64 octs;
1382+
u64 ucast;
1383+
u64 bcast;
1384+
u64 mcast;
1385+
u64 drop;
1386+
u64 drop_octs;
1387+
u64 drop_mcast;
1388+
u64 drop_bcast;
1389+
u64 err;
1390+
u64 rsvd[5];
1391+
} rx;
1392+
struct {
1393+
u64 ucast;
1394+
u64 bcast;
1395+
u64 mcast;
1396+
u64 drop;
1397+
u64 octs;
1398+
} tx;
1399+
};
1400+
13691401
/* NPC mbox message structs */
13701402

13711403
#define NPC_MCAM_ENTRY_INVALID 0xFFFF

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

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

48-
/* NIX TX stats */
49-
enum nix_stat_lf_tx {
50-
TX_UCAST = 0x0,
51-
TX_BCAST = 0x1,
52-
TX_MCAST = 0x2,
53-
TX_DROP = 0x3,
54-
TX_OCTS = 0x4,
55-
TX_STATS_ENUM_LAST,
56-
};
57-
58-
/* NIX RX stats */
59-
enum nix_stat_lf_rx {
60-
RX_OCTS = 0x0,
61-
RX_UCAST = 0x1,
62-
RX_BCAST = 0x2,
63-
RX_MCAST = 0x3,
64-
RX_DROP = 0x4,
65-
RX_DROP_OCTS = 0x5,
66-
RX_FCS = 0x6,
67-
RX_ERR = 0x7,
68-
RX_DRP_BCAST = 0x8,
69-
RX_DRP_MCAST = 0x9,
70-
RX_DRP_L3BCAST = 0xa,
71-
RX_DRP_L3MCAST = 0xb,
72-
RX_STATS_ENUM_LAST,
73-
};
74-
7548
static char *cgx_rx_stats_fields[] = {
7649
[CGX_STAT0] = "Received packets",
7750
[CGX_STAT1] = "Octets of received packets",

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,49 @@
1414
#include "rvu.h"
1515
#include "rvu_reg.h"
1616

17+
#define RVU_LF_RX_STATS(reg) \
18+
rvu_read64(rvu, blkaddr, NIX_AF_LFX_RX_STATX(nixlf, reg))
19+
20+
#define RVU_LF_TX_STATS(reg) \
21+
rvu_read64(rvu, blkaddr, NIX_AF_LFX_TX_STATX(nixlf, reg))
22+
23+
int rvu_mbox_handler_nix_lf_stats(struct rvu *rvu,
24+
struct nix_stats_req *req,
25+
struct nix_stats_rsp *rsp)
26+
{
27+
u16 pcifunc = req->pcifunc;
28+
int nixlf, blkaddr, err;
29+
struct msg_req rst_req;
30+
struct msg_rsp rst_rsp;
31+
32+
err = nix_get_nixlf(rvu, pcifunc, &nixlf, &blkaddr);
33+
if (err)
34+
return 0;
35+
36+
if (req->reset) {
37+
rst_req.hdr.pcifunc = pcifunc;
38+
return rvu_mbox_handler_nix_stats_rst(rvu, &rst_req, &rst_rsp);
39+
}
40+
rsp->rx.octs = RVU_LF_RX_STATS(RX_OCTS);
41+
rsp->rx.ucast = RVU_LF_RX_STATS(RX_UCAST);
42+
rsp->rx.bcast = RVU_LF_RX_STATS(RX_BCAST);
43+
rsp->rx.mcast = RVU_LF_RX_STATS(RX_MCAST);
44+
rsp->rx.drop = RVU_LF_RX_STATS(RX_DROP);
45+
rsp->rx.err = RVU_LF_RX_STATS(RX_ERR);
46+
rsp->rx.drop_octs = RVU_LF_RX_STATS(RX_DROP_OCTS);
47+
rsp->rx.drop_mcast = RVU_LF_RX_STATS(RX_DRP_MCAST);
48+
rsp->rx.drop_bcast = RVU_LF_RX_STATS(RX_DRP_BCAST);
49+
50+
rsp->tx.octs = RVU_LF_TX_STATS(TX_OCTS);
51+
rsp->tx.ucast = RVU_LF_TX_STATS(TX_UCAST);
52+
rsp->tx.bcast = RVU_LF_TX_STATS(TX_BCAST);
53+
rsp->tx.mcast = RVU_LF_TX_STATS(TX_MCAST);
54+
rsp->tx.drop = RVU_LF_TX_STATS(TX_DROP);
55+
56+
rsp->pcifunc = req->pcifunc;
57+
return 0;
58+
}
59+
1760
static u16 rvu_rep_get_vlan_id(struct rvu *rvu, u16 pcifunc)
1861
{
1962
int id;

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,4 +823,30 @@ enum nix_tx_vtag_op {
823823
#define VTAG_STRIP BIT_ULL(4)
824824
#define VTAG_CAPTURE BIT_ULL(5)
825825

826+
/* NIX TX stats */
827+
enum nix_stat_lf_tx {
828+
TX_UCAST = 0x0,
829+
TX_BCAST = 0x1,
830+
TX_MCAST = 0x2,
831+
TX_DROP = 0x3,
832+
TX_OCTS = 0x4,
833+
TX_STATS_ENUM_LAST,
834+
};
835+
836+
/* NIX RX stats */
837+
enum nix_stat_lf_rx {
838+
RX_OCTS = 0x0,
839+
RX_UCAST = 0x1,
840+
RX_BCAST = 0x2,
841+
RX_MCAST = 0x3,
842+
RX_DROP = 0x4,
843+
RX_DROP_OCTS = 0x5,
844+
RX_FCS = 0x6,
845+
RX_ERR = 0x7,
846+
RX_DRP_BCAST = 0x8,
847+
RX_DRP_MCAST = 0x9,
848+
RX_DRP_L3BCAST = 0xa,
849+
RX_DRP_L3MCAST = 0xb,
850+
RX_STATS_ENUM_LAST,
851+
};
826852
#endif /* RVU_STRUCT_H */

drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -121,33 +121,6 @@ enum otx2_errcodes_re {
121121
ERRCODE_IL4_CSUM = 0x22,
122122
};
123123

124-
/* NIX TX stats */
125-
enum nix_stat_lf_tx {
126-
TX_UCAST = 0x0,
127-
TX_BCAST = 0x1,
128-
TX_MCAST = 0x2,
129-
TX_DROP = 0x3,
130-
TX_OCTS = 0x4,
131-
TX_STATS_ENUM_LAST,
132-
};
133-
134-
/* NIX RX stats */
135-
enum nix_stat_lf_rx {
136-
RX_OCTS = 0x0,
137-
RX_UCAST = 0x1,
138-
RX_BCAST = 0x2,
139-
RX_MCAST = 0x3,
140-
RX_DROP = 0x4,
141-
RX_DROP_OCTS = 0x5,
142-
RX_FCS = 0x6,
143-
RX_ERR = 0x7,
144-
RX_DRP_BCAST = 0x8,
145-
RX_DRP_MCAST = 0x9,
146-
RX_DRP_L3BCAST = 0xa,
147-
RX_DRP_L3MCAST = 0xb,
148-
RX_STATS_ENUM_LAST,
149-
};
150-
151124
struct otx2_dev_stats {
152125
u64 rx_bytes;
153126
u64 rx_frames;

drivers/net/ethernet/marvell/octeontx2/nic/rep.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,68 @@ MODULE_DESCRIPTION(DRV_STRING);
2828
MODULE_LICENSE("GPL");
2929
MODULE_DEVICE_TABLE(pci, rvu_rep_id_table);
3030

31+
static void rvu_rep_get_stats(struct work_struct *work)
32+
{
33+
struct delayed_work *del_work = to_delayed_work(work);
34+
struct nix_stats_req *req;
35+
struct nix_stats_rsp *rsp;
36+
struct rep_stats *stats;
37+
struct otx2_nic *priv;
38+
struct rep_dev *rep;
39+
int err;
40+
41+
rep = container_of(del_work, struct rep_dev, stats_wrk);
42+
priv = rep->mdev;
43+
44+
mutex_lock(&priv->mbox.lock);
45+
req = otx2_mbox_alloc_msg_nix_lf_stats(&priv->mbox);
46+
if (!req) {
47+
mutex_unlock(&priv->mbox.lock);
48+
return;
49+
}
50+
req->pcifunc = rep->pcifunc;
51+
err = otx2_sync_mbox_msg_busy_poll(&priv->mbox);
52+
if (err)
53+
goto exit;
54+
55+
rsp = (struct nix_stats_rsp *)
56+
otx2_mbox_get_rsp(&priv->mbox.mbox, 0, &req->hdr);
57+
58+
if (IS_ERR(rsp)) {
59+
err = PTR_ERR(rsp);
60+
goto exit;
61+
}
62+
63+
stats = &rep->stats;
64+
stats->rx_bytes = rsp->rx.octs;
65+
stats->rx_frames = rsp->rx.ucast + rsp->rx.bcast +
66+
rsp->rx.mcast;
67+
stats->rx_drops = rsp->rx.drop;
68+
stats->rx_mcast_frames = rsp->rx.mcast;
69+
stats->tx_bytes = rsp->tx.octs;
70+
stats->tx_frames = rsp->tx.ucast + rsp->tx.bcast + rsp->tx.mcast;
71+
stats->tx_drops = rsp->tx.drop;
72+
exit:
73+
mutex_unlock(&priv->mbox.lock);
74+
}
75+
76+
static void rvu_rep_get_stats64(struct net_device *dev,
77+
struct rtnl_link_stats64 *stats)
78+
{
79+
struct rep_dev *rep = netdev_priv(dev);
80+
81+
stats->rx_packets = rep->stats.rx_frames;
82+
stats->rx_bytes = rep->stats.rx_bytes;
83+
stats->rx_dropped = rep->stats.rx_drops;
84+
stats->multicast = rep->stats.rx_mcast_frames;
85+
86+
stats->tx_packets = rep->stats.tx_frames;
87+
stats->tx_bytes = rep->stats.tx_bytes;
88+
stats->tx_dropped = rep->stats.tx_drops;
89+
90+
schedule_delayed_work(&rep->stats_wrk, msecs_to_jiffies(100));
91+
}
92+
3193
static int rvu_eswitch_config(struct otx2_nic *priv, u8 ena)
3294
{
3395
struct esw_cfg_req *req;
@@ -87,6 +149,7 @@ static const struct net_device_ops rvu_rep_netdev_ops = {
87149
.ndo_open = rvu_rep_open,
88150
.ndo_stop = rvu_rep_stop,
89151
.ndo_start_xmit = rvu_rep_xmit,
152+
.ndo_get_stats64 = rvu_rep_get_stats64,
90153
};
91154

92155
static int rvu_rep_napi_init(struct otx2_nic *priv,
@@ -290,6 +353,8 @@ int rvu_rep_create(struct otx2_nic *priv, struct netlink_ext_ack *extack)
290353
free_netdev(ndev);
291354
goto exit;
292355
}
356+
357+
INIT_DELAYED_WORK(&rep->stats_wrk, rvu_rep_get_stats);
293358
}
294359
err = rvu_rep_napi_init(priv, extack);
295360
if (err)

drivers/net/ethernet/marvell/octeontx2/nic/rep.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,23 @@
1717
#define PCI_DEVID_RVU_REP 0xA0E0
1818

1919
#define RVU_MAX_REP OTX2_MAX_CQ_CNT
20+
21+
struct rep_stats {
22+
u64 rx_bytes;
23+
u64 rx_frames;
24+
u64 rx_drops;
25+
u64 rx_mcast_frames;
26+
27+
u64 tx_bytes;
28+
u64 tx_frames;
29+
u64 tx_drops;
30+
};
31+
2032
struct rep_dev {
2133
struct otx2_nic *mdev;
2234
struct net_device *netdev;
35+
struct rep_stats stats;
36+
struct delayed_work stats_wrk;
2337
u16 rep_id;
2438
u16 pcifunc;
2539
};

0 commit comments

Comments
 (0)