common/cnxk: add new PCI IDs to supported devices
[dpdk.git] / drivers / common / cnxk / roc_sso.c
index f4c4e5b..bdf973f 100644 (file)
@@ -6,11 +6,10 @@
 #include "roc_priv.h"
 
 /* Private functions. */
-static int
-sso_lf_alloc(struct roc_sso *roc_sso, enum sso_lf_type lf_type, uint16_t nb_lf,
+int
+sso_lf_alloc(struct dev *dev, enum sso_lf_type lf_type, uint16_t nb_lf,
             void **rsp)
 {
-       struct dev *dev = &roc_sso_to_sso_priv(roc_sso)->dev;
        int rc = -ENOSPC;
 
        switch (lf_type) {
@@ -41,10 +40,9 @@ sso_lf_alloc(struct roc_sso *roc_sso, enum sso_lf_type lf_type, uint16_t nb_lf,
        return 0;
 }
 
-static int
-sso_lf_free(struct roc_sso *roc_sso, enum sso_lf_type lf_type, uint16_t nb_lf)
+int
+sso_lf_free(struct dev *dev, enum sso_lf_type lf_type, uint16_t nb_lf)
 {
-       struct dev *dev = &roc_sso_to_sso_priv(roc_sso)->dev;
        int rc = -ENOSPC;
 
        switch (lf_type) {
@@ -152,7 +150,7 @@ sso_rsrc_get(struct roc_sso *roc_sso)
        return 0;
 }
 
-static void
+void
 sso_hws_link_modify(uint8_t hws, uintptr_t base, struct plt_bitmap *bmp,
                    uint16_t hwgrp[], uint16_t n, uint16_t enable)
 {
@@ -172,8 +170,10 @@ sso_hws_link_modify(uint8_t hws, uintptr_t base, struct plt_bitmap *bmp,
                k = k ? k : 4;
                for (j = 0; j < k; j++) {
                        mask[j] = hwgrp[i + j] | enable << 14;
-                       enable ? plt_bitmap_set(bmp, hwgrp[i + j]) :
-                                plt_bitmap_clear(bmp, hwgrp[i + j]);
+                       if (bmp) {
+                               enable ? plt_bitmap_set(bmp, hwgrp[i + j]) :
+                                        plt_bitmap_clear(bmp, hwgrp[i + j]);
+                       }
                        plt_sso_dbg("HWS %d Linked to HWGRP %d", hws,
                                    hwgrp[i + j]);
                }
@@ -185,6 +185,27 @@ sso_hws_link_modify(uint8_t hws, uintptr_t base, struct plt_bitmap *bmp,
        }
 }
 
+static int
+sso_msix_fill(struct roc_sso *roc_sso, uint16_t nb_hws, uint16_t nb_hwgrp)
+{
+       struct sso *sso = roc_sso_to_sso_priv(roc_sso);
+       struct msix_offset_rsp *rsp;
+       struct dev *dev = &sso->dev;
+       int i, rc;
+
+       mbox_alloc_msg_msix_offset(dev->mbox);
+       rc = mbox_process_msg(dev->mbox, (void **)&rsp);
+       if (rc < 0)
+               return rc;
+
+       for (i = 0; i < nb_hws; i++)
+               sso->hws_msix_offset[i] = rsp->ssow_msixoff[i];
+       for (i = 0; i < nb_hwgrp; i++)
+               sso->hwgrp_msix_offset[i] = rsp->sso_msixoff[i];
+
+       return 0;
+}
+
 /* Public Functions. */
 uintptr_t
 roc_sso_hws_base_get(struct roc_sso *roc_sso, uint8_t hws)
@@ -258,6 +279,69 @@ roc_sso_hws_unlink(struct roc_sso *roc_sso, uint8_t hws, uint16_t hwgrp[],
        return nb_hwgrp;
 }
 
+int
+roc_sso_hws_stats_get(struct roc_sso *roc_sso, uint8_t hws,
+                     struct roc_sso_hws_stats *stats)
+{
+       struct dev *dev = &roc_sso_to_sso_priv(roc_sso)->dev;
+       struct sso_hws_stats *req_rsp;
+       int rc;
+
+       req_rsp = (struct sso_hws_stats *)mbox_alloc_msg_sso_hws_get_stats(
+               dev->mbox);
+       if (req_rsp == NULL) {
+               rc = mbox_process(dev->mbox);
+               if (rc < 0)
+                       return rc;
+               req_rsp = (struct sso_hws_stats *)
+                       mbox_alloc_msg_sso_hws_get_stats(dev->mbox);
+               if (req_rsp == NULL)
+                       return -ENOSPC;
+       }
+       req_rsp->hws = hws;
+       rc = mbox_process_msg(dev->mbox, (void **)&req_rsp);
+       if (rc)
+               return rc;
+
+       stats->arbitration = req_rsp->arbitration;
+       return 0;
+}
+
+int
+roc_sso_hwgrp_stats_get(struct roc_sso *roc_sso, uint8_t hwgrp,
+                       struct roc_sso_hwgrp_stats *stats)
+{
+       struct dev *dev = &roc_sso_to_sso_priv(roc_sso)->dev;
+       struct sso_grp_stats *req_rsp;
+       int rc;
+
+       req_rsp = (struct sso_grp_stats *)mbox_alloc_msg_sso_grp_get_stats(
+               dev->mbox);
+       if (req_rsp == NULL) {
+               rc = mbox_process(dev->mbox);
+               if (rc < 0)
+                       return rc;
+               req_rsp = (struct sso_grp_stats *)
+                       mbox_alloc_msg_sso_grp_get_stats(dev->mbox);
+               if (req_rsp == NULL)
+                       return -ENOSPC;
+       }
+       req_rsp->grp = hwgrp;
+       rc = mbox_process_msg(dev->mbox, (void **)&req_rsp);
+       if (rc)
+               return rc;
+
+       stats->aw_status = req_rsp->aw_status;
+       stats->dq_pc = req_rsp->dq_pc;
+       stats->ds_pc = req_rsp->ds_pc;
+       stats->ext_pc = req_rsp->ext_pc;
+       stats->page_cnt = req_rsp->page_cnt;
+       stats->ts_pc = req_rsp->ts_pc;
+       stats->wa_pc = req_rsp->wa_pc;
+       stats->ws_pc = req_rsp->ws_pc;
+       return 0;
+}
+
 int
 roc_sso_hwgrp_hws_link_status(struct roc_sso *roc_sso, uint8_t hws,
                              uint16_t hwgrp)
@@ -304,10 +388,8 @@ roc_sso_hwgrp_qos_config(struct roc_sso *roc_sso, struct roc_sso_hwgrp_qos *qos,
 }
 
 int
-roc_sso_hwgrp_alloc_xaq(struct roc_sso *roc_sso, uint32_t npa_aura_id,
-                       uint16_t hwgrps)
+sso_hwgrp_alloc_xaq(struct dev *dev, uint32_t npa_aura_id, uint16_t hwgrps)
 {
-       struct dev *dev = &roc_sso_to_sso_priv(roc_sso)->dev;
        struct sso_hw_setconfig *req;
        int rc = -ENOSPC;
 
@@ -322,9 +404,17 @@ roc_sso_hwgrp_alloc_xaq(struct roc_sso *roc_sso, uint32_t npa_aura_id,
 }
 
 int
-roc_sso_hwgrp_release_xaq(struct roc_sso *roc_sso, uint16_t hwgrps)
+roc_sso_hwgrp_alloc_xaq(struct roc_sso *roc_sso, uint32_t npa_aura_id,
+                       uint16_t hwgrps)
 {
        struct dev *dev = &roc_sso_to_sso_priv(roc_sso)->dev;
+
+       return sso_hwgrp_alloc_xaq(dev, npa_aura_id, hwgrps);
+}
+
+int
+sso_hwgrp_release_xaq(struct dev *dev, uint16_t hwgrps)
+{
        struct sso_hw_xaq_release *req;
 
        req = mbox_alloc_msg_sso_hw_release_xaq_aura(dev->mbox);
@@ -335,6 +425,14 @@ roc_sso_hwgrp_release_xaq(struct roc_sso *roc_sso, uint16_t hwgrps)
        return mbox_process(dev->mbox);
 }
 
+int
+roc_sso_hwgrp_release_xaq(struct roc_sso *roc_sso, uint16_t hwgrps)
+{
+       struct dev *dev = &roc_sso_to_sso_priv(roc_sso)->dev;
+
+       return sso_hwgrp_release_xaq(dev, hwgrps);
+}
+
 int
 roc_sso_hwgrp_set_priority(struct roc_sso *roc_sso, uint16_t hwgrp,
                           uint8_t weight, uint8_t affinity, uint8_t priority)
@@ -363,6 +461,7 @@ roc_sso_hwgrp_set_priority(struct roc_sso *roc_sso, uint16_t hwgrp,
 int
 roc_sso_rsrc_init(struct roc_sso *roc_sso, uint8_t nb_hws, uint16_t nb_hwgrp)
 {
+       struct sso *sso = roc_sso_to_sso_priv(roc_sso);
        struct sso_lf_alloc_rsp *rsp_hwgrp;
        int rc;
 
@@ -383,13 +482,13 @@ roc_sso_rsrc_init(struct roc_sso *roc_sso, uint8_t nb_hws, uint16_t nb_hwgrp)
                goto hwgrp_atch_fail;
        }
 
-       rc = sso_lf_alloc(roc_sso, SSO_LF_TYPE_HWS, nb_hws, NULL);
+       rc = sso_lf_alloc(&sso->dev, SSO_LF_TYPE_HWS, nb_hws, NULL);
        if (rc < 0) {
                plt_err("Unable to alloc SSO HWS LFs");
                goto hws_alloc_fail;
        }
 
-       rc = sso_lf_alloc(roc_sso, SSO_LF_TYPE_HWGRP, nb_hwgrp,
+       rc = sso_lf_alloc(&sso->dev, SSO_LF_TYPE_HWGRP, nb_hwgrp,
                          (void **)&rsp_hwgrp);
        if (rc < 0) {
                plt_err("Unable to alloc SSO HWGRP Lfs");
@@ -400,12 +499,27 @@ roc_sso_rsrc_init(struct roc_sso *roc_sso, uint8_t nb_hws, uint16_t nb_hwgrp)
        roc_sso->xae_waes = rsp_hwgrp->xaq_wq_entries;
        roc_sso->iue = rsp_hwgrp->in_unit_entries;
 
+       rc = sso_msix_fill(roc_sso, nb_hws, nb_hwgrp);
+       if (rc < 0) {
+               plt_err("Unable to get MSIX offsets for SSO LFs");
+               goto sso_msix_fail;
+       }
+
+       rc = sso_register_irqs_priv(roc_sso, &sso->pci_dev->intr_handle, nb_hws,
+                                   nb_hwgrp);
+       if (rc < 0) {
+               plt_err("Failed to register SSO LF IRQs");
+               goto sso_msix_fail;
+       }
+
        roc_sso->nb_hwgrp = nb_hwgrp;
        roc_sso->nb_hws = nb_hws;
 
        return 0;
+sso_msix_fail:
+       sso_lf_free(&sso->dev, SSO_LF_TYPE_HWGRP, nb_hwgrp);
 hwgrp_alloc_fail:
-       sso_lf_free(roc_sso, SSO_LF_TYPE_HWS, nb_hws);
+       sso_lf_free(&sso->dev, SSO_LF_TYPE_HWS, nb_hws);
 hws_alloc_fail:
        sso_rsrc_detach(roc_sso, SSO_LF_TYPE_HWGRP);
 hwgrp_atch_fail:
@@ -416,11 +530,15 @@ hwgrp_atch_fail:
 void
 roc_sso_rsrc_fini(struct roc_sso *roc_sso)
 {
+       struct sso *sso = roc_sso_to_sso_priv(roc_sso);
+
        if (!roc_sso->nb_hws && !roc_sso->nb_hwgrp)
                return;
 
-       sso_lf_free(roc_sso, SSO_LF_TYPE_HWS, roc_sso->nb_hws);
-       sso_lf_free(roc_sso, SSO_LF_TYPE_HWGRP, roc_sso->nb_hwgrp);
+       sso_unregister_irqs_priv(roc_sso, &sso->pci_dev->intr_handle,
+                                roc_sso->nb_hws, roc_sso->nb_hwgrp);
+       sso_lf_free(&sso->dev, SSO_LF_TYPE_HWS, roc_sso->nb_hws);
+       sso_lf_free(&sso->dev, SSO_LF_TYPE_HWGRP, roc_sso->nb_hwgrp);
 
        sso_rsrc_detach(roc_sso, SSO_LF_TYPE_HWS);
        sso_rsrc_detach(roc_sso, SSO_LF_TYPE_HWGRP);