Skip to content

Commit 8239d57

Browse files
committed
Merge branch 'dpaa2-eth-add-QBMAN-statistics'
Ioana Ciornei says: ==================== dpaa2-eth: add QBMAN statistics This patch set adds ethtool statistics for pending frames/bytes in Rx/Tx conf FQs and number of buffers in pool. The first patch adds support for the query APIs in the DPIO driver while the latter actually exposes the statistics through ethtool. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 7b98f63 + 610febc commit 8239d57

File tree

5 files changed

+267
-0
lines changed

5 files changed

+267
-0
lines changed

drivers/net/ethernet/freescale/dpaa2/dpaa2-ethtool.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ static char dpaa2_ethtool_extras[][ETH_GSTRING_LEN] = {
4848
"[drv] xdp drop",
4949
"[drv] xdp tx",
5050
"[drv] xdp tx errors",
51+
/* FQ stats */
52+
"[qbman] rx pending frames",
53+
"[qbman] rx pending bytes",
54+
"[qbman] tx conf pending frames",
55+
"[qbman] tx conf pending bytes",
56+
"[qbman] buffer count",
5157
};
5258

5359
#define DPAA2_ETH_NUM_EXTRA_STATS ARRAY_SIZE(dpaa2_ethtool_extras)
@@ -177,6 +183,10 @@ static void dpaa2_eth_get_ethtool_stats(struct net_device *net_dev,
177183
int j, k, err;
178184
int num_cnt;
179185
union dpni_statistics dpni_stats;
186+
u32 fcnt, bcnt;
187+
u32 fcnt_rx_total = 0, fcnt_tx_total = 0;
188+
u32 bcnt_rx_total = 0, bcnt_tx_total = 0;
189+
u32 buf_cnt;
180190
struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
181191
struct dpaa2_eth_drv_stats *extras;
182192
struct dpaa2_eth_ch_stats *ch_stats;
@@ -219,6 +229,37 @@ static void dpaa2_eth_get_ethtool_stats(struct net_device *net_dev,
219229
for (j = 0; j < sizeof(*ch_stats) / sizeof(__u64); j++)
220230
*((__u64 *)data + i + j) += *((__u64 *)ch_stats + j);
221231
}
232+
i += j;
233+
234+
for (j = 0; j < priv->num_fqs; j++) {
235+
/* Print FQ instantaneous counts */
236+
err = dpaa2_io_query_fq_count(NULL, priv->fq[j].fqid,
237+
&fcnt, &bcnt);
238+
if (err) {
239+
netdev_warn(net_dev, "FQ query error %d", err);
240+
return;
241+
}
242+
243+
if (priv->fq[j].type == DPAA2_TX_CONF_FQ) {
244+
fcnt_tx_total += fcnt;
245+
bcnt_tx_total += bcnt;
246+
} else {
247+
fcnt_rx_total += fcnt;
248+
bcnt_rx_total += bcnt;
249+
}
250+
}
251+
252+
*(data + i++) = fcnt_rx_total;
253+
*(data + i++) = bcnt_rx_total;
254+
*(data + i++) = fcnt_tx_total;
255+
*(data + i++) = bcnt_tx_total;
256+
257+
err = dpaa2_io_query_bp_count(NULL, priv->bpid, &buf_cnt);
258+
if (err) {
259+
netdev_warn(net_dev, "Buffer count query error %d\n", err);
260+
return;
261+
}
262+
*(data + i++) = buf_cnt;
222263
}
223264

224265
static int prep_eth_rule(struct ethhdr *eth_value, struct ethhdr *eth_mask,

drivers/soc/fsl/dpio/dpio-service.c

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,3 +601,71 @@ struct dpaa2_dq *dpaa2_io_store_next(struct dpaa2_io_store *s, int *is_last)
601601
return ret;
602602
}
603603
EXPORT_SYMBOL_GPL(dpaa2_io_store_next);
604+
605+
/**
606+
* dpaa2_io_query_fq_count() - Get the frame and byte count for a given fq.
607+
* @d: the given DPIO object.
608+
* @fqid: the id of frame queue to be queried.
609+
* @fcnt: the queried frame count.
610+
* @bcnt: the queried byte count.
611+
*
612+
* Knowing the FQ count at run-time can be useful in debugging situations.
613+
* The instantaneous frame- and byte-count are hereby returned.
614+
*
615+
* Return 0 for a successful query, and negative error code if query fails.
616+
*/
617+
int dpaa2_io_query_fq_count(struct dpaa2_io *d, u32 fqid,
618+
u32 *fcnt, u32 *bcnt)
619+
{
620+
struct qbman_fq_query_np_rslt state;
621+
struct qbman_swp *swp;
622+
unsigned long irqflags;
623+
int ret;
624+
625+
d = service_select(d);
626+
if (!d)
627+
return -ENODEV;
628+
629+
swp = d->swp;
630+
spin_lock_irqsave(&d->lock_mgmt_cmd, irqflags);
631+
ret = qbman_fq_query_state(swp, fqid, &state);
632+
spin_unlock_irqrestore(&d->lock_mgmt_cmd, irqflags);
633+
if (ret)
634+
return ret;
635+
*fcnt = qbman_fq_state_frame_count(&state);
636+
*bcnt = qbman_fq_state_byte_count(&state);
637+
638+
return 0;
639+
}
640+
EXPORT_SYMBOL_GPL(dpaa2_io_query_fq_count);
641+
642+
/**
643+
* dpaa2_io_query_bp_count() - Query the number of buffers currently in a
644+
* buffer pool.
645+
* @d: the given DPIO object.
646+
* @bpid: the index of buffer pool to be queried.
647+
* @num: the queried number of buffers in the buffer pool.
648+
*
649+
* Return 0 for a successful query, and negative error code if query fails.
650+
*/
651+
int dpaa2_io_query_bp_count(struct dpaa2_io *d, u16 bpid, u32 *num)
652+
{
653+
struct qbman_bp_query_rslt state;
654+
struct qbman_swp *swp;
655+
unsigned long irqflags;
656+
int ret;
657+
658+
d = service_select(d);
659+
if (!d)
660+
return -ENODEV;
661+
662+
swp = d->swp;
663+
spin_lock_irqsave(&d->lock_mgmt_cmd, irqflags);
664+
ret = qbman_bp_query(swp, bpid, &state);
665+
spin_unlock_irqrestore(&d->lock_mgmt_cmd, irqflags);
666+
if (ret)
667+
return ret;
668+
*num = qbman_bp_info_num_free_bufs(&state);
669+
return 0;
670+
}
671+
EXPORT_SYMBOL_GPL(dpaa2_io_query_bp_count);

drivers/soc/fsl/dpio/qbman-portal.c

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,3 +1003,99 @@ int qbman_swp_CDAN_set(struct qbman_swp *s, u16 channelid,
10031003

10041004
return 0;
10051005
}
1006+
1007+
#define QBMAN_RESPONSE_VERB_MASK 0x7f
1008+
#define QBMAN_FQ_QUERY_NP 0x45
1009+
#define QBMAN_BP_QUERY 0x32
1010+
1011+
struct qbman_fq_query_desc {
1012+
u8 verb;
1013+
u8 reserved[3];
1014+
__le32 fqid;
1015+
u8 reserved2[56];
1016+
};
1017+
1018+
int qbman_fq_query_state(struct qbman_swp *s, u32 fqid,
1019+
struct qbman_fq_query_np_rslt *r)
1020+
{
1021+
struct qbman_fq_query_desc *p;
1022+
void *resp;
1023+
1024+
p = (struct qbman_fq_query_desc *)qbman_swp_mc_start(s);
1025+
if (!p)
1026+
return -EBUSY;
1027+
1028+
/* FQID is a 24 bit value */
1029+
p->fqid = cpu_to_le32(fqid & 0x00FFFFFF);
1030+
resp = qbman_swp_mc_complete(s, p, QBMAN_FQ_QUERY_NP);
1031+
if (!resp) {
1032+
pr_err("qbman: Query FQID %d NP fields failed, no response\n",
1033+
fqid);
1034+
return -EIO;
1035+
}
1036+
*r = *(struct qbman_fq_query_np_rslt *)resp;
1037+
/* Decode the outcome */
1038+
WARN_ON((r->verb & QBMAN_RESPONSE_VERB_MASK) != QBMAN_FQ_QUERY_NP);
1039+
1040+
/* Determine success or failure */
1041+
if (r->rslt != QBMAN_MC_RSLT_OK) {
1042+
pr_err("Query NP fields of FQID 0x%x failed, code=0x%02x\n",
1043+
p->fqid, r->rslt);
1044+
return -EIO;
1045+
}
1046+
1047+
return 0;
1048+
}
1049+
1050+
u32 qbman_fq_state_frame_count(const struct qbman_fq_query_np_rslt *r)
1051+
{
1052+
return (le32_to_cpu(r->frm_cnt) & 0x00FFFFFF);
1053+
}
1054+
1055+
u32 qbman_fq_state_byte_count(const struct qbman_fq_query_np_rslt *r)
1056+
{
1057+
return le32_to_cpu(r->byte_cnt);
1058+
}
1059+
1060+
struct qbman_bp_query_desc {
1061+
u8 verb;
1062+
u8 reserved;
1063+
__le16 bpid;
1064+
u8 reserved2[60];
1065+
};
1066+
1067+
int qbman_bp_query(struct qbman_swp *s, u16 bpid,
1068+
struct qbman_bp_query_rslt *r)
1069+
{
1070+
struct qbman_bp_query_desc *p;
1071+
void *resp;
1072+
1073+
p = (struct qbman_bp_query_desc *)qbman_swp_mc_start(s);
1074+
if (!p)
1075+
return -EBUSY;
1076+
1077+
p->bpid = cpu_to_le16(bpid);
1078+
resp = qbman_swp_mc_complete(s, p, QBMAN_BP_QUERY);
1079+
if (!resp) {
1080+
pr_err("qbman: Query BPID %d fields failed, no response\n",
1081+
bpid);
1082+
return -EIO;
1083+
}
1084+
*r = *(struct qbman_bp_query_rslt *)resp;
1085+
/* Decode the outcome */
1086+
WARN_ON((r->verb & QBMAN_RESPONSE_VERB_MASK) != QBMAN_BP_QUERY);
1087+
1088+
/* Determine success or failure */
1089+
if (r->rslt != QBMAN_MC_RSLT_OK) {
1090+
pr_err("Query fields of BPID 0x%x failed, code=0x%02x\n",
1091+
bpid, r->rslt);
1092+
return -EIO;
1093+
}
1094+
1095+
return 0;
1096+
}
1097+
1098+
u32 qbman_bp_info_num_free_bufs(struct qbman_bp_query_rslt *a)
1099+
{
1100+
return le32_to_cpu(a->fill);
1101+
}

drivers/soc/fsl/dpio/qbman-portal.h

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,4 +441,62 @@ static inline void *qbman_swp_mc_complete(struct qbman_swp *swp, void *cmd,
441441
return cmd;
442442
}
443443

444+
/* Query APIs */
445+
struct qbman_fq_query_np_rslt {
446+
u8 verb;
447+
u8 rslt;
448+
u8 st1;
449+
u8 st2;
450+
u8 reserved[2];
451+
__le16 od1_sfdr;
452+
__le16 od2_sfdr;
453+
__le16 od3_sfdr;
454+
__le16 ra1_sfdr;
455+
__le16 ra2_sfdr;
456+
__le32 pfdr_hptr;
457+
__le32 pfdr_tptr;
458+
__le32 frm_cnt;
459+
__le32 byte_cnt;
460+
__le16 ics_surp;
461+
u8 is;
462+
u8 reserved2[29];
463+
};
464+
465+
int qbman_fq_query_state(struct qbman_swp *s, u32 fqid,
466+
struct qbman_fq_query_np_rslt *r);
467+
u32 qbman_fq_state_frame_count(const struct qbman_fq_query_np_rslt *r);
468+
u32 qbman_fq_state_byte_count(const struct qbman_fq_query_np_rslt *r);
469+
470+
struct qbman_bp_query_rslt {
471+
u8 verb;
472+
u8 rslt;
473+
u8 reserved[4];
474+
u8 bdi;
475+
u8 state;
476+
__le32 fill;
477+
__le32 hdotr;
478+
__le16 swdet;
479+
__le16 swdxt;
480+
__le16 hwdet;
481+
__le16 hwdxt;
482+
__le16 swset;
483+
__le16 swsxt;
484+
__le16 vbpid;
485+
__le16 icid;
486+
__le64 bpscn_addr;
487+
__le64 bpscn_ctx;
488+
__le16 hw_targ;
489+
u8 dbe;
490+
u8 reserved2;
491+
u8 sdcnt;
492+
u8 hdcnt;
493+
u8 sscnt;
494+
u8 reserved3[9];
495+
};
496+
497+
int qbman_bp_query(struct qbman_swp *s, u16 bpid,
498+
struct qbman_bp_query_rslt *r);
499+
500+
u32 qbman_bp_info_num_free_bufs(struct qbman_bp_query_rslt *a);
501+
444502
#endif /* __FSL_QBMAN_PORTAL_H */

include/soc/fsl/dpaa2-io.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,8 @@ struct dpaa2_io_store *dpaa2_io_store_create(unsigned int max_frames,
116116
void dpaa2_io_store_destroy(struct dpaa2_io_store *s);
117117
struct dpaa2_dq *dpaa2_io_store_next(struct dpaa2_io_store *s, int *is_last);
118118

119+
int dpaa2_io_query_fq_count(struct dpaa2_io *d, u32 fqid,
120+
u32 *fcnt, u32 *bcnt);
121+
int dpaa2_io_query_bp_count(struct dpaa2_io *d, u16 bpid,
122+
u32 *num);
119123
#endif /* __FSL_DPAA2_IO_H */

0 commit comments

Comments
 (0)