octeontx2-af: Add free rsrc count mbox msg
authorGeorge Cherian <george.cherian@marvell.com>
Wed, 25 Aug 2021 12:18:43 +0000 (17:48 +0530)
committerDavid S. Miller <davem@davemloft.net>
Wed, 25 Aug 2021 12:39:01 +0000 (13:39 +0100)
Upon receiving the MBOX_MSG_FREE_RSRC_CNT, the AF will find out the
current number of free resources and reply it back to the requester. No
guarantee is given on the future state of the free resources yet.
If another requester sends MBOX_MSG_ATTACH_RESOURCES after this call,
the number of available resources might change.

Signed-off-by: George Cherian <george.cherian@marvell.com>
Signed-off-by: Stanislaw Kardach <skardach@marvell.com>
Signed-off-by: Sunil Goutham <sgoutham@marvell.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/marvell/octeontx2/af/mbox.h
drivers/net/ethernet/marvell/octeontx2/af/rvu.c

index 7fbd1e252cd7f8e4204ddbf1053a594966846dc9..bc9cd1de2872ab1ae66a020cefcfd1a5b289610d 100644 (file)
@@ -130,6 +130,7 @@ static inline struct mbox_msghdr *otx2_mbox_alloc_msg(struct otx2_mbox *mbox,
 M(READY,               0x001, ready, msg_req, ready_msg_rsp)           \
 M(ATTACH_RESOURCES,    0x002, attach_resources, rsrc_attach, msg_rsp)  \
 M(DETACH_RESOURCES,    0x003, detach_resources, rsrc_detach, msg_rsp)  \
+M(FREE_RSRC_CNT,       0x004, free_rsrc_cnt, msg_req, free_rsrcs_rsp)  \
 M(MSIX_OFFSET,         0x005, msix_offset, msg_req, msix_offset_rsp)   \
 M(VF_FLR,              0x006, vf_flr, msg_req, msg_rsp)                \
 M(PTP_OP,              0x007, ptp_op, ptp_req, ptp_rsp)                \
@@ -367,6 +368,25 @@ struct rsrc_detach {
        u8 cptlfs:1;
 };
 
+/* Number of resources available to the caller.
+ * In reply to MBOX_MSG_FREE_RSRC_CNT.
+ */
+struct free_rsrcs_rsp {
+       struct mbox_msghdr hdr;
+       u16 schq[NIX_TXSCH_LVL_CNT];
+       u16  sso;
+       u16  tim;
+       u16  ssow;
+       u16  cpt;
+       u8   npa;
+       u8   nix;
+       u16  schq_nix1[NIX_TXSCH_LVL_CNT];
+       u8   nix1;
+       u8   cpt1;
+       u8   ree0;
+       u8   ree1;
+};
+
 #define MSIX_VECTOR_INVALID    0xFFFF
 #define MAX_RVU_BLKLF_CNT      256
 
index 6801cd3dbf98dab693a04d44ec33496f00350bd0..8e3ed57d5b75da49277ca9a99e8636c7deffb11f 100644 (file)
@@ -1796,6 +1796,99 @@ int rvu_mbox_handler_msix_offset(struct rvu *rvu, struct msg_req *req,
        return 0;
 }
 
+int rvu_mbox_handler_free_rsrc_cnt(struct rvu *rvu, struct msg_req *req,
+                                  struct free_rsrcs_rsp *rsp)
+{
+       struct rvu_hwinfo *hw = rvu->hw;
+       struct rvu_block *block;
+       struct nix_txsch *txsch;
+       struct nix_hw *nix_hw;
+
+       mutex_lock(&rvu->rsrc_lock);
+
+       block = &hw->block[BLKADDR_NPA];
+       rsp->npa = rvu_rsrc_free_count(&block->lf);
+
+       block = &hw->block[BLKADDR_NIX0];
+       rsp->nix = rvu_rsrc_free_count(&block->lf);
+
+       block = &hw->block[BLKADDR_NIX1];
+       rsp->nix1 = rvu_rsrc_free_count(&block->lf);
+
+       block = &hw->block[BLKADDR_SSO];
+       rsp->sso = rvu_rsrc_free_count(&block->lf);
+
+       block = &hw->block[BLKADDR_SSOW];
+       rsp->ssow = rvu_rsrc_free_count(&block->lf);
+
+       block = &hw->block[BLKADDR_TIM];
+       rsp->tim = rvu_rsrc_free_count(&block->lf);
+
+       block = &hw->block[BLKADDR_CPT0];
+       rsp->cpt = rvu_rsrc_free_count(&block->lf);
+
+       block = &hw->block[BLKADDR_CPT1];
+       rsp->cpt1 = rvu_rsrc_free_count(&block->lf);
+
+       if (rvu->hw->cap.nix_fixed_txschq_mapping) {
+               rsp->schq[NIX_TXSCH_LVL_SMQ] = 1;
+               rsp->schq[NIX_TXSCH_LVL_TL4] = 1;
+               rsp->schq[NIX_TXSCH_LVL_TL3] = 1;
+               rsp->schq[NIX_TXSCH_LVL_TL2] = 1;
+               /* NIX1 */
+               if (!is_block_implemented(rvu->hw, BLKADDR_NIX1))
+                       goto out;
+               rsp->schq_nix1[NIX_TXSCH_LVL_SMQ] = 1;
+               rsp->schq_nix1[NIX_TXSCH_LVL_TL4] = 1;
+               rsp->schq_nix1[NIX_TXSCH_LVL_TL3] = 1;
+               rsp->schq_nix1[NIX_TXSCH_LVL_TL2] = 1;
+       } else {
+               nix_hw = get_nix_hw(hw, BLKADDR_NIX0);
+               txsch = &nix_hw->txsch[NIX_TXSCH_LVL_SMQ];
+               rsp->schq[NIX_TXSCH_LVL_SMQ] =
+                               rvu_rsrc_free_count(&txsch->schq);
+
+               txsch = &nix_hw->txsch[NIX_TXSCH_LVL_TL4];
+               rsp->schq[NIX_TXSCH_LVL_TL4] =
+                               rvu_rsrc_free_count(&txsch->schq);
+
+               txsch = &nix_hw->txsch[NIX_TXSCH_LVL_TL3];
+               rsp->schq[NIX_TXSCH_LVL_TL3] =
+                               rvu_rsrc_free_count(&txsch->schq);
+
+               txsch = &nix_hw->txsch[NIX_TXSCH_LVL_TL2];
+               rsp->schq[NIX_TXSCH_LVL_TL2] =
+                               rvu_rsrc_free_count(&txsch->schq);
+
+               if (!is_block_implemented(rvu->hw, BLKADDR_NIX1))
+                       goto out;
+
+               nix_hw = get_nix_hw(hw, BLKADDR_NIX1);
+               txsch = &nix_hw->txsch[NIX_TXSCH_LVL_SMQ];
+               rsp->schq_nix1[NIX_TXSCH_LVL_SMQ] =
+                               rvu_rsrc_free_count(&txsch->schq);
+
+               txsch = &nix_hw->txsch[NIX_TXSCH_LVL_TL4];
+               rsp->schq_nix1[NIX_TXSCH_LVL_TL4] =
+                               rvu_rsrc_free_count(&txsch->schq);
+
+               txsch = &nix_hw->txsch[NIX_TXSCH_LVL_TL3];
+               rsp->schq_nix1[NIX_TXSCH_LVL_TL3] =
+                               rvu_rsrc_free_count(&txsch->schq);
+
+               txsch = &nix_hw->txsch[NIX_TXSCH_LVL_TL2];
+               rsp->schq_nix1[NIX_TXSCH_LVL_TL2] =
+                               rvu_rsrc_free_count(&txsch->schq);
+       }
+
+       rsp->schq_nix1[NIX_TXSCH_LVL_TL1] = 1;
+out:
+       rsp->schq[NIX_TXSCH_LVL_TL1] = 1;
+       mutex_unlock(&rvu->rsrc_lock);
+
+       return 0;
+}
+
 int rvu_mbox_handler_vf_flr(struct rvu *rvu, struct msg_req *req,
                            struct msg_rsp *rsp)
 {