Lines Matching refs:hwc

8 static int mana_hwc_get_msg_index(struct hw_channel_context *hwc, u16 *msg_id)  in mana_hwc_get_msg_index()  argument
10 struct gdma_resource *r = &hwc->inflight_msg_res; in mana_hwc_get_msg_index()
14 down(&hwc->sema); in mana_hwc_get_msg_index()
18 index = find_first_zero_bit(hwc->inflight_msg_res.map, in mana_hwc_get_msg_index()
19 hwc->inflight_msg_res.size); in mana_hwc_get_msg_index()
21 bitmap_set(hwc->inflight_msg_res.map, index, 1); in mana_hwc_get_msg_index()
30 static void mana_hwc_put_msg_index(struct hw_channel_context *hwc, u16 msg_id) in mana_hwc_put_msg_index() argument
32 struct gdma_resource *r = &hwc->inflight_msg_res; in mana_hwc_put_msg_index()
36 bitmap_clear(hwc->inflight_msg_res.map, msg_id, 1); in mana_hwc_put_msg_index()
39 up(&hwc->sema); in mana_hwc_put_msg_index()
58 struct device *dev = hwc_rxq->hwc->dev; in mana_hwc_post_rx_wqe()
78 static void mana_hwc_handle_resp(struct hw_channel_context *hwc, u32 resp_len, in mana_hwc_handle_resp() argument
86 hwc->inflight_msg_res.map)) { in mana_hwc_handle_resp()
87 dev_err(hwc->dev, "hwc_rx: invalid msg_id = %u\n", in mana_hwc_handle_resp()
89 mana_hwc_post_rx_wqe(hwc->rxq, rx_req); in mana_hwc_handle_resp()
93 ctx = hwc->caller_ctx + resp_msg->response.hwc_msg_id; in mana_hwc_handle_resp()
107 mana_hwc_post_rx_wqe(hwc->rxq, rx_req); in mana_hwc_handle_resp()
116 struct hw_channel_context *hwc = ctx; in mana_hwc_init_event_handler() local
117 struct gdma_dev *gd = hwc->gdma_dev; in mana_hwc_init_event_handler()
126 hwc->cq->gdma_eq->id = eq_db.eq_id; in mana_hwc_init_event_handler()
137 hwc->cq->gdma_cq->id = val; in mana_hwc_init_event_handler()
141 hwc->rxq->gdma_wq->id = val; in mana_hwc_init_event_handler()
145 hwc->txq->gdma_wq->id = val; in mana_hwc_init_event_handler()
149 hwc->hwc_init_q_depth_max = (u16)val; in mana_hwc_init_event_handler()
153 hwc->hwc_init_max_req_msg_size = val; in mana_hwc_init_event_handler()
157 hwc->hwc_init_max_resp_msg_size = val; in mana_hwc_init_event_handler()
165 hwc->gdma_dev->pdid = val; in mana_hwc_init_event_handler()
169 hwc->rxq->msg_buf->gpa_mkey = val; in mana_hwc_init_event_handler()
170 hwc->txq->msg_buf->gpa_mkey = val; in mana_hwc_init_event_handler()
174 hwc->pf_dest_vrq_id = val; in mana_hwc_init_event_handler()
178 hwc->pf_dest_vrcq_id = val; in mana_hwc_init_event_handler()
185 complete(&hwc->hwc_init_eqe_comp); in mana_hwc_init_event_handler()
195 hwc->hwc_timeout = val; in mana_hwc_init_event_handler()
199 dev_warn(hwc->dev, "Received unknown reconfig type %u\n", type); in mana_hwc_init_event_handler()
213 dev_err(hwc->dev, "Failed to schedule adev service event: %d\n", in mana_hwc_init_event_handler()
217 dev_warn(hwc->dev, "Received unknown SOC service type %u\n", type); in mana_hwc_init_event_handler()
223 dev_warn(hwc->dev, "Received unknown gdma event %u\n", event->type); in mana_hwc_init_event_handler()
232 struct hw_channel_context *hwc = ctx; in mana_hwc_rx_event_handler() local
233 struct hwc_wq *hwc_rxq = hwc->rxq; in mana_hwc_rx_event_handler()
254 rx_req_idx = (sge->address - rq_base_addr) / hwc->max_req_msg_size; in mana_hwc_rx_event_handler()
259 if (resp->response.hwc_msg_id >= hwc->num_inflight_msg) { in mana_hwc_rx_event_handler()
260 dev_err(hwc->dev, "HWC RX: wrong msg_id=%u\n", in mana_hwc_rx_event_handler()
265 mana_hwc_handle_resp(hwc, rx_oob->tx_oob_data_size, rx_req); in mana_hwc_rx_event_handler()
276 struct hw_channel_context *hwc = ctx; in mana_hwc_tx_event_handler() local
277 struct hwc_wq *hwc_txq = hwc->txq; in mana_hwc_tx_event_handler()
282 static int mana_hwc_create_gdma_wq(struct hw_channel_context *hwc, in mana_hwc_create_gdma_wq() argument
295 return mana_gd_create_hwc_queue(hwc->gdma_dev, &spec, queue); in mana_hwc_create_gdma_wq()
298 static int mana_hwc_create_gdma_cq(struct hw_channel_context *hwc, in mana_hwc_create_gdma_cq() argument
313 return mana_gd_create_hwc_queue(hwc->gdma_dev, &spec, queue); in mana_hwc_create_gdma_cq()
316 static int mana_hwc_create_gdma_eq(struct hw_channel_context *hwc, in mana_hwc_create_gdma_eq() argument
331 return mana_gd_create_hwc_queue(hwc->gdma_dev, &spec, queue); in mana_hwc_create_gdma_eq()
376 static int mana_hwc_create_cq(struct hw_channel_context *hwc, u16 q_depth, in mana_hwc_create_cq() argument
401 err = mana_hwc_create_gdma_eq(hwc, eq_size, ctx, callback, &eq); in mana_hwc_create_cq()
403 dev_err(hwc->dev, "Failed to create HWC EQ for RQ: %d\n", err); in mana_hwc_create_cq()
408 err = mana_hwc_create_gdma_cq(hwc, cq_size, hwc_cq, mana_hwc_comp_event, in mana_hwc_create_cq()
411 dev_err(hwc->dev, "Failed to create HWC CQ for RQ: %d\n", err); in mana_hwc_create_cq()
422 hwc_cq->hwc = hwc; in mana_hwc_create_cq()
433 mana_hwc_destroy_cq(hwc->gdma_dev->gdma_context, hwc_cq); in mana_hwc_create_cq()
437 static int mana_hwc_alloc_dma_buf(struct hw_channel_context *hwc, u16 q_depth, in mana_hwc_alloc_dma_buf() argument
441 struct gdma_context *gc = hwc->gdma_dev->gdma_context; in mana_hwc_alloc_dma_buf()
462 dev_err(hwc->dev, "Failed to allocate DMA buffer size: %u, err %d\n", in mana_hwc_alloc_dma_buf()
486 static void mana_hwc_dealloc_dma_buf(struct hw_channel_context *hwc, in mana_hwc_dealloc_dma_buf() argument
497 static void mana_hwc_destroy_wq(struct hw_channel_context *hwc, in mana_hwc_destroy_wq() argument
500 mana_hwc_dealloc_dma_buf(hwc, hwc_wq->msg_buf); in mana_hwc_destroy_wq()
503 mana_gd_destroy_queue(hwc->gdma_dev->gdma_context, in mana_hwc_destroy_wq()
509 static int mana_hwc_create_wq(struct hw_channel_context *hwc, in mana_hwc_create_wq() argument
533 err = mana_hwc_create_gdma_wq(hwc, q_type, queue_size, &queue); in mana_hwc_create_wq()
537 hwc_wq->hwc = hwc; in mana_hwc_create_wq()
542 err = mana_hwc_alloc_dma_buf(hwc, q_depth, max_msg_size, in mana_hwc_create_wq()
551 mana_hwc_destroy_wq(hwc, hwc_wq); in mana_hwc_create_wq()
553 dev_err(hwc->dev, "Failed to create HWC queue size= %u type= %d err= %d\n", in mana_hwc_create_wq()
563 struct device *dev = hwc_txq->hwc->dev; in mana_hwc_post_tx_wqe()
603 static int mana_hwc_init_inflight_msg(struct hw_channel_context *hwc, in mana_hwc_init_inflight_msg() argument
608 sema_init(&hwc->sema, num_msg); in mana_hwc_init_inflight_msg()
610 err = mana_gd_alloc_res_map(num_msg, &hwc->inflight_msg_res); in mana_hwc_init_inflight_msg()
612 dev_err(hwc->dev, "Failed to init inflight_msg_res: %d\n", err); in mana_hwc_init_inflight_msg()
616 static int mana_hwc_test_channel(struct hw_channel_context *hwc, u16 q_depth, in mana_hwc_test_channel() argument
619 struct gdma_context *gc = hwc->gdma_dev->gdma_context; in mana_hwc_test_channel()
620 struct hwc_wq *hwc_rxq = hwc->rxq; in mana_hwc_test_channel()
641 hwc->caller_ctx = ctx; in mana_hwc_test_channel()
643 return mana_gd_test_eq(gc, hwc->cq->gdma_eq); in mana_hwc_test_channel()
650 struct hw_channel_context *hwc = gc->hwc.driver_data; in mana_hwc_establish_channel() local
651 struct gdma_queue *rq = hwc->rxq->gdma_wq; in mana_hwc_establish_channel()
652 struct gdma_queue *sq = hwc->txq->gdma_wq; in mana_hwc_establish_channel()
653 struct gdma_queue *eq = hwc->cq->gdma_eq; in mana_hwc_establish_channel()
654 struct gdma_queue *cq = hwc->cq->gdma_cq; in mana_hwc_establish_channel()
657 init_completion(&hwc->hwc_init_eqe_comp); in mana_hwc_establish_channel()
668 if (!wait_for_completion_timeout(&hwc->hwc_init_eqe_comp, 60 * HZ)) in mana_hwc_establish_channel()
671 *q_depth = hwc->hwc_init_q_depth_max; in mana_hwc_establish_channel()
672 *max_req_msg_size = hwc->hwc_init_max_req_msg_size; in mana_hwc_establish_channel()
673 *max_resp_msg_size = hwc->hwc_init_max_resp_msg_size; in mana_hwc_establish_channel()
688 static int mana_hwc_init_queues(struct hw_channel_context *hwc, u16 q_depth, in mana_hwc_init_queues() argument
693 err = mana_hwc_init_inflight_msg(hwc, q_depth); in mana_hwc_init_queues()
700 err = mana_hwc_create_cq(hwc, q_depth * 2, in mana_hwc_init_queues()
701 mana_hwc_init_event_handler, hwc, in mana_hwc_init_queues()
702 mana_hwc_rx_event_handler, hwc, in mana_hwc_init_queues()
703 mana_hwc_tx_event_handler, hwc, &hwc->cq); in mana_hwc_init_queues()
705 dev_err(hwc->dev, "Failed to create HWC CQ: %d\n", err); in mana_hwc_init_queues()
709 err = mana_hwc_create_wq(hwc, GDMA_RQ, q_depth, max_req_msg_size, in mana_hwc_init_queues()
710 hwc->cq, &hwc->rxq); in mana_hwc_init_queues()
712 dev_err(hwc->dev, "Failed to create HWC RQ: %d\n", err); in mana_hwc_init_queues()
716 err = mana_hwc_create_wq(hwc, GDMA_SQ, q_depth, max_resp_msg_size, in mana_hwc_init_queues()
717 hwc->cq, &hwc->txq); in mana_hwc_init_queues()
719 dev_err(hwc->dev, "Failed to create HWC SQ: %d\n", err); in mana_hwc_init_queues()
723 hwc->num_inflight_msg = q_depth; in mana_hwc_init_queues()
724 hwc->max_req_msg_size = max_req_msg_size; in mana_hwc_init_queues()
735 struct gdma_dev *gd = &gc->hwc; in mana_hwc_create_channel()
736 struct hw_channel_context *hwc; in mana_hwc_create_channel() local
740 hwc = kzalloc(sizeof(*hwc), GFP_KERNEL); in mana_hwc_create_channel()
741 if (!hwc) in mana_hwc_create_channel()
745 gd->driver_data = hwc; in mana_hwc_create_channel()
746 hwc->gdma_dev = gd; in mana_hwc_create_channel()
747 hwc->dev = gc->dev; in mana_hwc_create_channel()
748 hwc->hwc_timeout = HW_CHANNEL_WAIT_RESOURCE_TIMEOUT_MS; in mana_hwc_create_channel()
760 err = mana_hwc_init_queues(hwc, HW_CHANNEL_VF_BOOTSTRAP_QUEUE_DEPTH, in mana_hwc_create_channel()
764 dev_err(hwc->dev, "Failed to initialize HWC: %d\n", err); in mana_hwc_create_channel()
771 dev_err(hwc->dev, "Failed to establish HWC: %d\n", err); in mana_hwc_create_channel()
775 err = mana_hwc_test_channel(gc->hwc.driver_data, in mana_hwc_create_channel()
779 dev_err(hwc->dev, "Failed to test HWC: %d\n", err); in mana_hwc_create_channel()
791 struct hw_channel_context *hwc = gc->hwc.driver_data; in mana_hwc_destroy_channel() local
793 if (!hwc) in mana_hwc_destroy_channel()
804 kfree(hwc->caller_ctx); in mana_hwc_destroy_channel()
805 hwc->caller_ctx = NULL; in mana_hwc_destroy_channel()
807 if (hwc->txq) in mana_hwc_destroy_channel()
808 mana_hwc_destroy_wq(hwc, hwc->txq); in mana_hwc_destroy_channel()
810 if (hwc->rxq) in mana_hwc_destroy_channel()
811 mana_hwc_destroy_wq(hwc, hwc->rxq); in mana_hwc_destroy_channel()
813 if (hwc->cq) in mana_hwc_destroy_channel()
814 mana_hwc_destroy_cq(hwc->gdma_dev->gdma_context, hwc->cq); in mana_hwc_destroy_channel()
816 mana_gd_free_res_map(&hwc->inflight_msg_res); in mana_hwc_destroy_channel()
818 hwc->num_inflight_msg = 0; in mana_hwc_destroy_channel()
820 hwc->gdma_dev->doorbell = INVALID_DOORBELL; in mana_hwc_destroy_channel()
821 hwc->gdma_dev->pdid = INVALID_PDID; in mana_hwc_destroy_channel()
823 hwc->hwc_timeout = 0; in mana_hwc_destroy_channel()
825 kfree(hwc); in mana_hwc_destroy_channel()
826 gc->hwc.driver_data = NULL; in mana_hwc_destroy_channel()
827 gc->hwc.gdma_context = NULL; in mana_hwc_destroy_channel()
833 int mana_hwc_send_request(struct hw_channel_context *hwc, u32 req_len, in mana_hwc_send_request() argument
836 struct gdma_context *gc = hwc->gdma_dev->gdma_context; in mana_hwc_send_request()
838 struct hwc_wq *txq = hwc->txq; in mana_hwc_send_request()
846 mana_hwc_get_msg_index(hwc, &msg_id); in mana_hwc_send_request()
851 dev_err(hwc->dev, "HWC: req msg size: %d > %d\n", req_len, in mana_hwc_send_request()
857 ctx = hwc->caller_ctx + msg_id; in mana_hwc_send_request()
870 dest_vrq = hwc->pf_dest_vrq_id; in mana_hwc_send_request()
871 dest_vrcq = hwc->pf_dest_vrcq_id; in mana_hwc_send_request()
876 dev_err(hwc->dev, "HWC: Failed to post send WQE: %d\n", err); in mana_hwc_send_request()
881 (msecs_to_jiffies(hwc->hwc_timeout)))) { in mana_hwc_send_request()
882 dev_err(hwc->dev, "HWC: Request timed out!\n"); in mana_hwc_send_request()
893 dev_err(hwc->dev, "HWC: Failed hw_channel req: 0x%x\n", in mana_hwc_send_request()
899 mana_hwc_put_msg_index(hwc, msg_id); in mana_hwc_send_request()