2424#define CPT_LF_MAX_NB_DESC 128000
2525#define CPT_LF_DEFAULT_NB_DESC 1024
2626#define CPT_LF_FC_MIN_THRESHOLD 32
27+ #define CQ_ENTRY_SIZE_UNIT 32
2728
2829static struct cpt_int_cb {
2930 roc_cpt_int_misc_cb_t cb ;
@@ -687,6 +688,37 @@ cpt_get_blkaddr(struct dev *dev)
687688 return reg & 0x1FFULL ? RVU_BLOCK_ADDR_CPT1 : RVU_BLOCK_ADDR_CPT0 ;
688689}
689690
691+ int
692+ cpt_lf_cq_init (struct roc_cpt_lf * lf )
693+ {
694+ union cpt_lf_cq_size lf_cq_size = {.u = 0x0 };
695+ union cpt_lf_cq_base lf_cq_base = {.u = 0x0 };
696+ uint8_t max_cq_entry_size = 0x3 ;
697+ uintptr_t addr ;
698+ uint32_t len ;
699+
700+ if (!lf -> cq_size || lf -> cq_entry_size > max_cq_entry_size )
701+ return - EINVAL ;
702+
703+ /* Disable CPT completion queue */
704+ roc_cpt_cq_disable (lf );
705+
706+ /* Set command queue base address */
707+ len = PLT_ALIGN (lf -> cq_size * (CQ_ENTRY_SIZE_UNIT << lf -> cq_entry_size ), ROC_ALIGN );
708+ lf -> cq_vaddr = plt_zmalloc (len , ROC_ALIGN );
709+ if (lf -> cq_vaddr == NULL )
710+ return - ENOMEM ;
711+
712+ addr = (uintptr_t )lf -> cq_vaddr ;
713+
714+ lf_cq_base .s .addr = addr >> 7 ;
715+ plt_write64 (lf_cq_base .u , lf -> rbase + CPT_LF_CQ_BASE );
716+ lf_cq_size .s .size = PLT_ALIGN (len , ROC_ALIGN );
717+ plt_write64 (lf_cq_size .u , lf -> rbase + CPT_LF_CQ_SIZE );
718+
719+ return 0 ;
720+ }
721+
690722int
691723cpt_lf_init (struct roc_cpt_lf * lf , bool skip_register_irq )
692724{
@@ -713,14 +745,22 @@ cpt_lf_init(struct roc_cpt_lf *lf, bool skip_register_irq)
713745 /* Initialize instruction queue */
714746 cpt_iq_init (lf );
715747
748+ if (lf -> cpt_cq_ena ) {
749+ rc = cpt_lf_cq_init (lf );
750+ if (rc )
751+ goto disable_iq ;
752+ }
753+
716754 if (!skip_register_irq ) {
717755 rc = cpt_lf_register_irqs (lf , cpt_lf_misc_irq , cpt_lf_done_irq );
718756 if (rc )
719- goto disable_iq ;
757+ goto disable_cq ;
720758 }
721759
722760 return 0 ;
723761
762+ disable_cq :
763+ cpt_lf_cq_fini (lf );
724764disable_iq :
725765 roc_cpt_iq_disable (lf );
726766 plt_free (iq_mem );
@@ -954,6 +994,7 @@ cpt_lf_fini(struct roc_cpt_lf *lf, bool skip_register_irq)
954994 if (!skip_register_irq )
955995 cpt_lf_unregister_irqs (lf , cpt_lf_misc_irq , cpt_lf_done_irq );
956996
997+ cpt_lf_cq_fini (lf );
957998 /* Disable IQ */
958999 roc_cpt_iq_disable (lf );
9591000 roc_cpt_iq_reset (lf );
@@ -963,6 +1004,17 @@ cpt_lf_fini(struct roc_cpt_lf *lf, bool skip_register_irq)
9631004 lf -> iq_vaddr = NULL ;
9641005}
9651006
1007+ void
1008+ cpt_lf_cq_fini (struct roc_cpt_lf * lf )
1009+ {
1010+ if (!lf -> cpt_cq_ena )
1011+ return ;
1012+
1013+ roc_cpt_cq_disable (lf );
1014+ plt_free (lf -> cq_vaddr );
1015+ lf -> cq_vaddr = NULL ;
1016+ }
1017+
9661018void
9671019roc_cpt_lf_reset (struct roc_cpt_lf * lf )
9681020{
@@ -1074,6 +1126,26 @@ roc_cpt_eng_grp_add(struct roc_cpt *roc_cpt, enum cpt_eng_type eng_type)
10741126 return ret ;
10751127}
10761128
1129+ void
1130+ roc_cpt_cq_enable (struct roc_cpt_lf * lf )
1131+ {
1132+ union cpt_lf_cq_ctl lf_cq_ctl = {.u = 0x0 };
1133+
1134+ lf_cq_ctl .s .ena = 1 ;
1135+ lf_cq_ctl .s .dq_ack_ena = lf -> dq_ack_ena ;
1136+ lf_cq_ctl .s .entry_size = lf -> cq_entry_size ;
1137+ lf_cq_ctl .s .cq_all = lf -> cq_all ;
1138+ plt_write64 (lf_cq_ctl .u , lf -> rbase + CPT_LF_CQ_CTL );
1139+ }
1140+
1141+ void
1142+ roc_cpt_cq_disable (struct roc_cpt_lf * lf )
1143+ {
1144+ union cpt_lf_cq_ctl lf_cq_ctl = {.u = 0x0 };
1145+
1146+ plt_write64 (lf_cq_ctl .u , lf -> rbase + CPT_LF_CQ_CTL );
1147+ }
1148+
10771149void
10781150roc_cpt_iq_disable (struct roc_cpt_lf * lf )
10791151{
0 commit comments