Lines Matching refs:rsrc

37 struct irdma_puda_buf *irdma_puda_get_bufpool(struct irdma_puda_rsrc *rsrc)  in irdma_puda_get_bufpool()  argument
40 struct list_head *list = &rsrc->bufpool; in irdma_puda_get_bufpool()
43 spin_lock_irqsave(&rsrc->bufpool_lock, flags); in irdma_puda_get_bufpool()
46 rsrc->avail_buf_count--; in irdma_puda_get_bufpool()
47 buf->vsi = rsrc->vsi; in irdma_puda_get_bufpool()
49 rsrc->stats_buf_alloc_fail++; in irdma_puda_get_bufpool()
51 spin_unlock_irqrestore(&rsrc->bufpool_lock, flags); in irdma_puda_get_bufpool()
61 void irdma_puda_ret_bufpool(struct irdma_puda_rsrc *rsrc, in irdma_puda_ret_bufpool() argument
67 spin_lock_irqsave(&rsrc->bufpool_lock, flags); in irdma_puda_ret_bufpool()
68 list_add(&buf->list, &rsrc->bufpool); in irdma_puda_ret_bufpool()
69 spin_unlock_irqrestore(&rsrc->bufpool_lock, flags); in irdma_puda_ret_bufpool()
70 rsrc->avail_buf_count++; in irdma_puda_ret_bufpool()
80 static void irdma_puda_post_recvbuf(struct irdma_puda_rsrc *rsrc, u32 wqe_idx, in irdma_puda_post_recvbuf() argument
84 struct irdma_sc_qp *qp = &rsrc->qp; in irdma_puda_post_recvbuf()
88 dma_sync_single_for_device(rsrc->dev->hw->device, buf->mem.pa, in irdma_puda_post_recvbuf()
118 irdma_puda_replenish_rq(struct irdma_puda_rsrc *rsrc, bool initial) in irdma_puda_replenish_rq() argument
121 u32 invalid_cnt = rsrc->rxq_invalid_cnt; in irdma_puda_replenish_rq()
125 buf = irdma_puda_get_bufpool(rsrc); in irdma_puda_replenish_rq()
128 irdma_puda_post_recvbuf(rsrc, rsrc->rx_wqe_idx, buf, initial); in irdma_puda_replenish_rq()
129 rsrc->rx_wqe_idx = ((rsrc->rx_wqe_idx + 1) % rsrc->rq_size); in irdma_puda_replenish_rq()
130 rsrc->rxq_invalid_cnt--; in irdma_puda_replenish_rq()
331 struct irdma_puda_rsrc *rsrc; in irdma_puda_poll_cmpl() local
336 rsrc = (cq_type == IRDMA_CQ_TYPE_ILQ) ? cq->vsi->ilq : in irdma_puda_poll_cmpl()
351 if (!qp || !rsrc) { in irdma_puda_poll_cmpl()
356 if (qp->qp_id != rsrc->qp_id) { in irdma_puda_poll_cmpl()
371 rsrc->stats_rcvd_pkt_err++; in irdma_puda_poll_cmpl()
373 irdma_ilq_putback_rcvbuf(&rsrc->qp, buf, in irdma_puda_poll_cmpl()
376 irdma_puda_ret_bufpool(rsrc, buf); in irdma_puda_poll_cmpl()
377 irdma_puda_replenish_rq(rsrc, false); in irdma_puda_poll_cmpl()
382 rsrc->stats_pkt_rcvd++; in irdma_puda_poll_cmpl()
383 rsrc->compl_rxwqe_idx = info.wqe_idx; in irdma_puda_poll_cmpl()
385 rsrc->receive(rsrc->vsi, buf); in irdma_puda_poll_cmpl()
387 irdma_ilq_putback_rcvbuf(&rsrc->qp, buf, info.wqe_idx); in irdma_puda_poll_cmpl()
389 irdma_puda_replenish_rq(rsrc, false); in irdma_puda_poll_cmpl()
400 rsrc->xmit_complete(rsrc->vsi, buf); in irdma_puda_poll_cmpl()
401 spin_lock_irqsave(&rsrc->bufpool_lock, flags); in irdma_puda_poll_cmpl()
402 rsrc->tx_wqe_avail_cnt++; in irdma_puda_poll_cmpl()
403 spin_unlock_irqrestore(&rsrc->bufpool_lock, flags); in irdma_puda_poll_cmpl()
404 if (!list_empty(&rsrc->txpend)) in irdma_puda_poll_cmpl()
405 irdma_puda_send_buf(rsrc, NULL); in irdma_puda_poll_cmpl()
502 void irdma_puda_send_buf(struct irdma_puda_rsrc *rsrc, in irdma_puda_send_buf() argument
509 spin_lock_irqsave(&rsrc->bufpool_lock, flags); in irdma_puda_send_buf()
513 if (!rsrc->tx_wqe_avail_cnt || (buf && !list_empty(&rsrc->txpend))) { in irdma_puda_send_buf()
514 list_add_tail(&buf->list, &rsrc->txpend); in irdma_puda_send_buf()
515 spin_unlock_irqrestore(&rsrc->bufpool_lock, flags); in irdma_puda_send_buf()
516 rsrc->stats_sent_pkt_q++; in irdma_puda_send_buf()
517 if (rsrc->type == IRDMA_PUDA_RSRC_TYPE_ILQ) in irdma_puda_send_buf()
518 ibdev_dbg(to_ibdev(rsrc->dev), in irdma_puda_send_buf()
522 rsrc->tx_wqe_avail_cnt--; in irdma_puda_send_buf()
527 buf = irdma_puda_get_listbuf(&rsrc->txpend); in irdma_puda_send_buf()
538 if (rsrc->dev->hw_attrs.uk_attrs.hw_rev >= IRDMA_GEN_2) { in irdma_puda_send_buf()
546 dma_sync_single_for_cpu(rsrc->dev->hw->device, buf->mem.pa, in irdma_puda_send_buf()
548 ret = irdma_puda_send(&rsrc->qp, &info); in irdma_puda_send_buf()
550 rsrc->tx_wqe_avail_cnt++; in irdma_puda_send_buf()
551 rsrc->stats_sent_pkt_q++; in irdma_puda_send_buf()
552 list_add(&buf->list, &rsrc->txpend); in irdma_puda_send_buf()
553 if (rsrc->type == IRDMA_PUDA_RSRC_TYPE_ILQ) in irdma_puda_send_buf()
554 ibdev_dbg(to_ibdev(rsrc->dev), in irdma_puda_send_buf()
557 rsrc->stats_pkt_sent++; in irdma_puda_send_buf()
560 spin_unlock_irqrestore(&rsrc->bufpool_lock, flags); in irdma_puda_send_buf()
567 static void irdma_puda_qp_setctx(struct irdma_puda_rsrc *rsrc) in irdma_puda_qp_setctx() argument
569 struct irdma_sc_qp *qp = &rsrc->qp; in irdma_puda_qp_setctx()
578 FIELD_PREP(IRDMAQPC_SNDMSS, rsrc->buf_size)); in irdma_puda_qp_setctx()
583 FIELD_PREP(IRDMAQPC_TXCQNUM, rsrc->cq_id) | in irdma_puda_qp_setctx()
584 FIELD_PREP(IRDMAQPC_RXCQNUM, rsrc->cq_id)); in irdma_puda_qp_setctx()
586 FIELD_PREP(IRDMAQPC_STAT_INDEX, rsrc->stats_idx)); in irdma_puda_qp_setctx()
589 FIELD_PREP(IRDMAQPC_USESTATSINSTANCE, rsrc->stats_idx_valid)); in irdma_puda_qp_setctx()
646 static enum irdma_status_code irdma_puda_qp_create(struct irdma_puda_rsrc *rsrc) in irdma_puda_qp_create() argument
648 struct irdma_sc_qp *qp = &rsrc->qp; in irdma_puda_qp_create()
654 sq_size = rsrc->sq_size * IRDMA_QP_WQE_MIN_SIZE; in irdma_puda_qp_create()
655 rq_size = rsrc->rq_size * IRDMA_QP_WQE_MIN_SIZE; in irdma_puda_qp_create()
656 rsrc->qpmem.size = ALIGN((sq_size + rq_size + (IRDMA_SHADOW_AREA_SIZE << 3) + IRDMA_QP_CTX_SIZE), in irdma_puda_qp_create()
658 rsrc->qpmem.va = dma_alloc_coherent(rsrc->dev->hw->device, in irdma_puda_qp_create()
659 rsrc->qpmem.size, &rsrc->qpmem.pa, in irdma_puda_qp_create()
661 if (!rsrc->qpmem.va) in irdma_puda_qp_create()
664 mem = &rsrc->qpmem; in irdma_puda_qp_create()
665 memset(mem->va, 0, rsrc->qpmem.size); in irdma_puda_qp_create()
666 qp->hw_sq_size = irdma_get_encoded_wqe_size(rsrc->sq_size, IRDMA_QUEUE_TYPE_SQ_RQ); in irdma_puda_qp_create()
667 qp->hw_rq_size = irdma_get_encoded_wqe_size(rsrc->rq_size, IRDMA_QUEUE_TYPE_SQ_RQ); in irdma_puda_qp_create()
668 qp->pd = &rsrc->sc_pd; in irdma_puda_qp_create()
670 qp->dev = rsrc->dev; in irdma_puda_qp_create()
671 qp->qp_uk.back_qp = rsrc; in irdma_puda_qp_create()
674 qp->vsi = rsrc->vsi; in irdma_puda_qp_create()
676 ukqp->rq_base = &ukqp->sq_base[rsrc->sq_size]; in irdma_puda_qp_create()
677 ukqp->shadow_area = ukqp->rq_base[rsrc->rq_size].elem; in irdma_puda_qp_create()
683 ukqp->qp_id = rsrc->qp_id; in irdma_puda_qp_create()
684 ukqp->sq_wrtrk_array = rsrc->sq_wrtrk_array; in irdma_puda_qp_create()
685 ukqp->rq_wrid_array = rsrc->rq_wrid_array; in irdma_puda_qp_create()
686 ukqp->sq_size = rsrc->sq_size; in irdma_puda_qp_create()
687 ukqp->rq_size = rsrc->rq_size; in irdma_puda_qp_create()
694 ret = rsrc->dev->ws_add(qp->vsi, qp->user_pri); in irdma_puda_qp_create()
696 dma_free_coherent(rsrc->dev->hw->device, rsrc->qpmem.size, in irdma_puda_qp_create()
697 rsrc->qpmem.va, rsrc->qpmem.pa); in irdma_puda_qp_create()
698 rsrc->qpmem.va = NULL; in irdma_puda_qp_create()
703 irdma_puda_qp_setctx(rsrc); in irdma_puda_qp_create()
705 if (rsrc->dev->ceq_valid) in irdma_puda_qp_create()
706 ret = irdma_cqp_qp_create_cmd(rsrc->dev, qp); in irdma_puda_qp_create()
708 ret = irdma_puda_qp_wqe(rsrc->dev, qp); in irdma_puda_qp_create()
711 rsrc->dev->ws_remove(qp->vsi, qp->user_pri); in irdma_puda_qp_create()
712 dma_free_coherent(rsrc->dev->hw->device, rsrc->qpmem.size, in irdma_puda_qp_create()
713 rsrc->qpmem.va, rsrc->qpmem.pa); in irdma_puda_qp_create()
714 rsrc->qpmem.va = NULL; in irdma_puda_qp_create()
778 static enum irdma_status_code irdma_puda_cq_create(struct irdma_puda_rsrc *rsrc) in irdma_puda_cq_create() argument
780 struct irdma_sc_dev *dev = rsrc->dev; in irdma_puda_cq_create()
781 struct irdma_sc_cq *cq = &rsrc->cq; in irdma_puda_cq_create()
788 cq->vsi = rsrc->vsi; in irdma_puda_cq_create()
789 cqsize = rsrc->cq_size * (sizeof(struct irdma_cqe)); in irdma_puda_cq_create()
790 rsrc->cqmem.size = ALIGN(cqsize + sizeof(struct irdma_cq_shadow_area), in irdma_puda_cq_create()
792 rsrc->cqmem.va = dma_alloc_coherent(dev->hw->device, rsrc->cqmem.size, in irdma_puda_cq_create()
793 &rsrc->cqmem.pa, GFP_KERNEL); in irdma_puda_cq_create()
794 if (!rsrc->cqmem.va) in irdma_puda_cq_create()
797 mem = &rsrc->cqmem; in irdma_puda_cq_create()
799 info.type = (rsrc->type == IRDMA_PUDA_RSRC_TYPE_ILQ) ? in irdma_puda_cq_create()
801 info.shadow_read_threshold = rsrc->cq_size >> 2; in irdma_puda_cq_create()
806 init_info->cq_size = rsrc->cq_size; in irdma_puda_cq_create()
807 init_info->cq_id = rsrc->cq_id; in irdma_puda_cq_create()
810 info.vsi = rsrc->vsi; in irdma_puda_cq_create()
816 if (rsrc->dev->ceq_valid) in irdma_puda_cq_create()
822 dma_free_coherent(dev->hw->device, rsrc->cqmem.size, in irdma_puda_cq_create()
823 rsrc->cqmem.va, rsrc->cqmem.pa); in irdma_puda_cq_create()
824 rsrc->cqmem.va = NULL; in irdma_puda_cq_create()
834 static void irdma_puda_free_qp(struct irdma_puda_rsrc *rsrc) in irdma_puda_free_qp() argument
838 struct irdma_sc_dev *dev = rsrc->dev; in irdma_puda_free_qp()
840 if (rsrc->dev->ceq_valid) { in irdma_puda_free_qp()
841 irdma_cqp_qp_destroy_cmd(dev, &rsrc->qp); in irdma_puda_free_qp()
842 rsrc->dev->ws_remove(rsrc->qp.vsi, rsrc->qp.user_pri); in irdma_puda_free_qp()
846 ret = irdma_sc_qp_destroy(&rsrc->qp, 0, false, true, true); in irdma_puda_free_qp()
859 rsrc->dev->ws_remove(rsrc->qp.vsi, rsrc->qp.user_pri); in irdma_puda_free_qp()
866 static void irdma_puda_free_cq(struct irdma_puda_rsrc *rsrc) in irdma_puda_free_cq() argument
870 struct irdma_sc_dev *dev = rsrc->dev; in irdma_puda_free_cq()
872 if (rsrc->dev->ceq_valid) { in irdma_puda_free_cq()
873 irdma_cqp_cq_destroy_cmd(dev, &rsrc->cq); in irdma_puda_free_cq()
877 ret = irdma_sc_cq_destroy(&rsrc->cq, 0, true); in irdma_puda_free_cq()
899 struct irdma_puda_rsrc *rsrc; in irdma_puda_dele_rsrc() local
908 rsrc = vsi->ilq; in irdma_puda_dele_rsrc()
912 irdma_sc_remove_cq_ctx(ceq, &rsrc->cq); in irdma_puda_dele_rsrc()
915 rsrc = vsi->ieq; in irdma_puda_dele_rsrc()
919 irdma_sc_remove_cq_ctx(ceq, &rsrc->cq); in irdma_puda_dele_rsrc()
927 switch (rsrc->cmpl) { in irdma_puda_dele_rsrc()
929 irdma_free_hash_desc(rsrc->hash_desc); in irdma_puda_dele_rsrc()
932 irdma_qp_rem_qos(&rsrc->qp); in irdma_puda_dele_rsrc()
935 irdma_puda_free_qp(rsrc); in irdma_puda_dele_rsrc()
937 dma_free_coherent(dev->hw->device, rsrc->qpmem.size, in irdma_puda_dele_rsrc()
938 rsrc->qpmem.va, rsrc->qpmem.pa); in irdma_puda_dele_rsrc()
939 rsrc->qpmem.va = NULL; in irdma_puda_dele_rsrc()
943 irdma_puda_free_cq(rsrc); in irdma_puda_dele_rsrc()
945 dma_free_coherent(dev->hw->device, rsrc->cqmem.size, in irdma_puda_dele_rsrc()
946 rsrc->cqmem.va, rsrc->cqmem.pa); in irdma_puda_dele_rsrc()
947 rsrc->cqmem.va = NULL; in irdma_puda_dele_rsrc()
950 ibdev_dbg(to_ibdev(rsrc->dev), "PUDA: error no resources\n"); in irdma_puda_dele_rsrc()
954 buf = rsrc->alloclist; in irdma_puda_dele_rsrc()
959 rsrc->alloc_buf_count--; in irdma_puda_dele_rsrc()
970 static enum irdma_status_code irdma_puda_allocbufs(struct irdma_puda_rsrc *rsrc, in irdma_puda_allocbufs() argument
978 buf = irdma_puda_alloc_buf(rsrc->dev, rsrc->buf_size); in irdma_puda_allocbufs()
980 rsrc->stats_buf_alloc_fail++; in irdma_puda_allocbufs()
983 irdma_puda_ret_bufpool(rsrc, buf); in irdma_puda_allocbufs()
984 rsrc->alloc_buf_count++; in irdma_puda_allocbufs()
985 if (!rsrc->alloclist) { in irdma_puda_allocbufs()
986 rsrc->alloclist = buf; in irdma_puda_allocbufs()
988 nextbuf = rsrc->alloclist; in irdma_puda_allocbufs()
989 rsrc->alloclist = buf; in irdma_puda_allocbufs()
994 rsrc->avail_buf_count = rsrc->alloc_buf_count; in irdma_puda_allocbufs()
1009 struct irdma_puda_rsrc *rsrc; in irdma_puda_create_rsrc() local
1033 rsrc = vmem->va; in irdma_puda_create_rsrc()
1034 spin_lock_init(&rsrc->bufpool_lock); in irdma_puda_create_rsrc()
1039 rsrc->receive = info->receive; in irdma_puda_create_rsrc()
1040 rsrc->xmit_complete = info->xmit_complete; in irdma_puda_create_rsrc()
1045 rsrc->receive = irdma_ieq_receive; in irdma_puda_create_rsrc()
1046 rsrc->xmit_complete = irdma_ieq_tx_compl; in irdma_puda_create_rsrc()
1052 rsrc->type = info->type; in irdma_puda_create_rsrc()
1053 rsrc->sq_wrtrk_array = (struct irdma_sq_uk_wr_trk_info *) in irdma_puda_create_rsrc()
1055 rsrc->rq_wrid_array = (u64 *)((u8 *)vmem->va + pudasize + sqwridsize); in irdma_puda_create_rsrc()
1057 INIT_LIST_HEAD(&rsrc->bufpool); in irdma_puda_create_rsrc()
1058 INIT_LIST_HEAD(&rsrc->txpend); in irdma_puda_create_rsrc()
1060 rsrc->tx_wqe_avail_cnt = info->sq_size - 1; in irdma_puda_create_rsrc()
1061 irdma_sc_pd_init(dev, &rsrc->sc_pd, info->pd_id, info->abi_ver); in irdma_puda_create_rsrc()
1062 rsrc->qp_id = info->qp_id; in irdma_puda_create_rsrc()
1063 rsrc->cq_id = info->cq_id; in irdma_puda_create_rsrc()
1064 rsrc->sq_size = info->sq_size; in irdma_puda_create_rsrc()
1065 rsrc->rq_size = info->rq_size; in irdma_puda_create_rsrc()
1066 rsrc->cq_size = info->rq_size + info->sq_size; in irdma_puda_create_rsrc()
1068 if (rsrc->type == IRDMA_PUDA_RSRC_TYPE_ILQ) in irdma_puda_create_rsrc()
1069 rsrc->cq_size += info->rq_size; in irdma_puda_create_rsrc()
1071 rsrc->buf_size = info->buf_size; in irdma_puda_create_rsrc()
1072 rsrc->dev = dev; in irdma_puda_create_rsrc()
1073 rsrc->vsi = vsi; in irdma_puda_create_rsrc()
1074 rsrc->stats_idx = info->stats_idx; in irdma_puda_create_rsrc()
1075 rsrc->stats_idx_valid = info->stats_idx_valid; in irdma_puda_create_rsrc()
1077 ret = irdma_puda_cq_create(rsrc); in irdma_puda_create_rsrc()
1079 rsrc->cmpl = PUDA_CQ_CREATED; in irdma_puda_create_rsrc()
1080 ret = irdma_puda_qp_create(rsrc); in irdma_puda_create_rsrc()
1085 rsrc->type, ret); in irdma_puda_create_rsrc()
1088 rsrc->cmpl = PUDA_QP_CREATED; in irdma_puda_create_rsrc()
1090 ret = irdma_puda_allocbufs(rsrc, info->tx_buf_cnt + info->rq_size); in irdma_puda_create_rsrc()
1096 rsrc->rxq_invalid_cnt = info->rq_size; in irdma_puda_create_rsrc()
1097 ret = irdma_puda_replenish_rq(rsrc, true); in irdma_puda_create_rsrc()
1102 if (!irdma_init_hash_desc(&rsrc->hash_desc)) { in irdma_puda_create_rsrc()
1103 rsrc->check_crc = true; in irdma_puda_create_rsrc()
1104 rsrc->cmpl = PUDA_HASH_CRC_COMPLETE; in irdma_puda_create_rsrc()
1109 irdma_sc_ccq_arm(&rsrc->cq); in irdma_puda_create_rsrc()