Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

soc: fsl: dpio: Add BP and FQ query APIs

Add FQ (Frame Queue) and BP (Buffer Pool) query APIs that
users of QBMan can invoke to see the status of the queues
and pools that they are using.

Signed-off-by: Roy Pledge <roy.pledge@nxp.com>
Signed-off-by: Ioana Radulescu <ruxandra.radulescu@nxp.com>
Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Roy Pledge and committed by
David S. Miller
e80081c3 7b98f63e

+226
+68
drivers/soc/fsl/dpio/dpio-service.c
··· 601 601 return ret; 602 602 } 603 603 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);
+96
drivers/soc/fsl/dpio/qbman-portal.c
··· 1003 1003 1004 1004 return 0; 1005 1005 } 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 + }
+58
drivers/soc/fsl/dpio/qbman-portal.h
··· 441 441 return cmd; 442 442 } 443 443 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 + 444 502 #endif /* __FSL_QBMAN_PORTAL_H */
+4
include/soc/fsl/dpaa2-io.h
··· 116 116 void dpaa2_io_store_destroy(struct dpaa2_io_store *s); 117 117 struct dpaa2_dq *dpaa2_io_store_next(struct dpaa2_io_store *s, int *is_last); 118 118 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); 119 123 #endif /* __FSL_DPAA2_IO_H */