Lines Matching +full:mod +full:- +full:12 +full:b
1 // SPDX-License-Identifier: GPL-2.0-only
21 #define HINIC_MBOX_INT_SRC_RESP_AEQN_SHIFT 12
48 * 0 - Tx request is done;
49 * 1 - Tx request is in process.
68 * 0 - send
69 * 1 - receive
110 /* MBOX size is 64B, 8B for mbox_header, 4B reserved */
115 /* mbox write back status is 16B, only first 4B is used */
141 ((hwif)->cfg_regs_bar + HINIC_FUNC_CSR_MAILBOX_DATA_OFF)
146 #define MBOX_MSG_ID(func_to_func) ((func_to_func)->send_msg_id)
156 #define HINIC_QUEUE_MAX_DEPTH 12
192 dev_warn(&hwdev->hwif->pdev->dev, in check_func_id()
201 dev_warn(&hwdev->hwif->pdev->dev, in check_func_id()
218 * hinic_register_pf_mbox_cb - register mbox callback for pf
220 * @mod: specific mod that the callback will handle
222 * Return: 0 - success, negative - failure
225 enum hinic_mod_type mod, in hinic_register_pf_mbox_cb() argument
228 struct hinic_mbox_func_to_func *func_to_func = hwdev->func_to_func; in hinic_register_pf_mbox_cb()
230 if (mod >= HINIC_MOD_MAX) in hinic_register_pf_mbox_cb()
231 return -EFAULT; in hinic_register_pf_mbox_cb()
233 func_to_func->pf_mbox_cb[mod] = callback; in hinic_register_pf_mbox_cb()
235 set_bit(HINIC_PF_MBOX_CB_REG, &func_to_func->pf_mbox_cb_state[mod]); in hinic_register_pf_mbox_cb()
241 * hinic_register_vf_mbox_cb - register mbox callback for vf
243 * @mod: specific mod that the callback will handle
245 * Return: 0 - success, negative - failure
248 enum hinic_mod_type mod, in hinic_register_vf_mbox_cb() argument
251 struct hinic_mbox_func_to_func *func_to_func = hwdev->func_to_func; in hinic_register_vf_mbox_cb()
253 if (mod >= HINIC_MOD_MAX) in hinic_register_vf_mbox_cb()
254 return -EFAULT; in hinic_register_vf_mbox_cb()
256 func_to_func->vf_mbox_cb[mod] = callback; in hinic_register_vf_mbox_cb()
258 set_bit(HINIC_VF_MBOX_CB_REG, &func_to_func->vf_mbox_cb_state[mod]); in hinic_register_vf_mbox_cb()
264 * hinic_unregister_pf_mbox_cb - unregister the mbox callback for pf
266 * @mod: specific mod that the callback will handle
269 enum hinic_mod_type mod) in hinic_unregister_pf_mbox_cb() argument
271 struct hinic_mbox_func_to_func *func_to_func = hwdev->func_to_func; in hinic_unregister_pf_mbox_cb()
273 clear_bit(HINIC_PF_MBOX_CB_REG, &func_to_func->pf_mbox_cb_state[mod]); in hinic_unregister_pf_mbox_cb()
276 &func_to_func->pf_mbox_cb_state[mod])) in hinic_unregister_pf_mbox_cb()
279 func_to_func->pf_mbox_cb[mod] = NULL; in hinic_unregister_pf_mbox_cb()
283 * hinic_unregister_vf_mbox_cb - unregister the mbox callback for vf
285 * @mod: specific mod that the callback will handle
288 enum hinic_mod_type mod) in hinic_unregister_vf_mbox_cb() argument
290 struct hinic_mbox_func_to_func *func_to_func = hwdev->func_to_func; in hinic_unregister_vf_mbox_cb()
292 clear_bit(HINIC_VF_MBOX_CB_REG, &func_to_func->vf_mbox_cb_state[mod]); in hinic_unregister_vf_mbox_cb()
295 &func_to_func->vf_mbox_cb_state[mod])) in hinic_unregister_vf_mbox_cb()
298 func_to_func->vf_mbox_cb[mod] = NULL; in hinic_unregister_vf_mbox_cb()
308 if (recv_mbox->mod >= HINIC_MOD_MAX) { in recv_vf_mbox_handler()
309 dev_err(&func_to_func->hwif->pdev->dev, "Receive illegal mbox message, mod = %d\n", in recv_vf_mbox_handler()
310 recv_mbox->mod); in recv_vf_mbox_handler()
311 return -EINVAL; in recv_vf_mbox_handler()
315 &func_to_func->vf_mbox_cb_state[recv_mbox->mod]); in recv_vf_mbox_handler()
317 cb = func_to_func->vf_mbox_cb[recv_mbox->mod]; in recv_vf_mbox_handler()
319 &func_to_func->vf_mbox_cb_state[recv_mbox->mod])) { in recv_vf_mbox_handler()
320 cb(func_to_func->hwdev, recv_mbox->cmd, recv_mbox->mbox, in recv_vf_mbox_handler()
321 recv_mbox->mbox_len, buf_out, out_size); in recv_vf_mbox_handler()
323 dev_err(&func_to_func->hwif->pdev->dev, "VF mbox cb is not registered\n"); in recv_vf_mbox_handler()
324 ret = -EINVAL; in recv_vf_mbox_handler()
328 &func_to_func->vf_mbox_cb_state[recv_mbox->mod]); in recv_vf_mbox_handler()
343 if (recv_mbox->mod >= HINIC_MOD_MAX) { in recv_pf_from_vf_mbox_handler()
344 dev_err(&func_to_func->hwif->pdev->dev, "Receive illegal mbox message, mod = %d\n", in recv_pf_from_vf_mbox_handler()
345 recv_mbox->mod); in recv_pf_from_vf_mbox_handler()
346 return -EINVAL; in recv_pf_from_vf_mbox_handler()
350 &func_to_func->pf_mbox_cb_state[recv_mbox->mod]); in recv_pf_from_vf_mbox_handler()
352 cb = func_to_func->pf_mbox_cb[recv_mbox->mod]; in recv_pf_from_vf_mbox_handler()
354 &func_to_func->pf_mbox_cb_state[recv_mbox->mod])) { in recv_pf_from_vf_mbox_handler()
355 vf_id = src_func_idx - in recv_pf_from_vf_mbox_handler()
356 hinic_glb_pf_vf_offset(func_to_func->hwif); in recv_pf_from_vf_mbox_handler()
357 ret = cb(func_to_func->hwdev, vf_id, recv_mbox->cmd, in recv_pf_from_vf_mbox_handler()
358 recv_mbox->mbox, recv_mbox->mbox_len, in recv_pf_from_vf_mbox_handler()
361 dev_err(&func_to_func->hwif->pdev->dev, "PF mbox mod(0x%x) cb is not registered\n", in recv_pf_from_vf_mbox_handler()
362 recv_mbox->mod); in recv_pf_from_vf_mbox_handler()
363 ret = -EINVAL; in recv_pf_from_vf_mbox_handler()
367 &func_to_func->pf_mbox_cb_state[recv_mbox->mod]); in recv_pf_from_vf_mbox_handler()
379 recv_mbox->seq_id = seq_id; in check_mbox_seq_id_and_seg_len()
381 if (seq_id != recv_mbox->seq_id + 1) in check_mbox_seq_id_and_seg_len()
384 recv_mbox->seq_id = seq_id; in check_mbox_seq_id_and_seg_len()
393 spin_lock(&func_to_func->mbox_lock); in resp_mbox_handler()
394 if (recv_mbox->msg_info.msg_id == func_to_func->send_msg_id && in resp_mbox_handler()
395 func_to_func->event_flag == EVENT_START) in resp_mbox_handler()
396 complete(&recv_mbox->recv_done); in resp_mbox_handler()
398 dev_err(&func_to_func->hwif->pdev->dev, in resp_mbox_handler()
400 func_to_func->send_msg_id, recv_mbox->msg_info.msg_id, in resp_mbox_handler()
401 recv_mbox->msg_info.status); in resp_mbox_handler()
402 spin_unlock(&func_to_func->mbox_lock); in resp_mbox_handler()
415 recv_func_mbox_handler(mbox_work->func_to_func, mbox_work->recv_mbox, in recv_func_mbox_work_handler()
416 mbox_work->src_func_idx); in recv_func_mbox_work_handler()
419 &mbox_work->func_to_func->mbox_send[mbox_work->src_func_idx]; in recv_func_mbox_work_handler()
421 atomic_dec(&recv_mbox->msg_cnt); in recv_func_mbox_work_handler()
442 dev_err(&func_to_func->hwif->pdev->dev, in recv_mbox_handler()
444 src_func_idx, recv_mbox->seq_id, seq_id, seg_len); in recv_mbox_handler()
445 recv_mbox->seq_id = SEQ_ID_MAX_VAL; in recv_mbox_handler()
450 memcpy((u8 *)recv_mbox->mbox + pos, mbox_body, in recv_mbox_handler()
456 recv_mbox->cmd = HINIC_MBOX_HEADER_GET(mbox_header, CMD); in recv_mbox_handler()
457 recv_mbox->mod = HINIC_MBOX_HEADER_GET(mbox_header, MODULE); in recv_mbox_handler()
458 recv_mbox->mbox_len = HINIC_MBOX_HEADER_GET(mbox_header, MSG_LEN); in recv_mbox_handler()
459 recv_mbox->ack_type = HINIC_MBOX_HEADER_GET(mbox_header, NO_ACK); in recv_mbox_handler()
460 recv_mbox->msg_info.msg_id = HINIC_MBOX_HEADER_GET(mbox_header, MSG_ID); in recv_mbox_handler()
461 recv_mbox->msg_info.status = HINIC_MBOX_HEADER_GET(mbox_header, STATUS); in recv_mbox_handler()
462 recv_mbox->seq_id = SEQ_ID_MAX_VAL; in recv_mbox_handler()
470 if (atomic_read(&recv_mbox->msg_cnt) > HINIC_MAX_MSG_CNT_TO_PROCESS) { in recv_mbox_handler()
471 dev_warn(&func_to_func->hwif->pdev->dev, in recv_mbox_handler()
473 src_func_idx, atomic_read(&recv_mbox->msg_cnt)); in recv_mbox_handler()
481 rcv_mbox_temp->mbox = kmemdup(recv_mbox->mbox, MBOX_MAX_BUF_SZ, in recv_mbox_handler()
483 if (!rcv_mbox_temp->mbox) in recv_mbox_handler()
486 rcv_mbox_temp->buf_out = kzalloc(MBOX_MAX_BUF_SZ, GFP_KERNEL); in recv_mbox_handler()
487 if (!rcv_mbox_temp->buf_out) in recv_mbox_handler()
494 mbox_work->func_to_func = func_to_func; in recv_mbox_handler()
495 mbox_work->recv_mbox = rcv_mbox_temp; in recv_mbox_handler()
496 mbox_work->src_func_idx = src_func_idx; in recv_mbox_handler()
498 atomic_inc(&recv_mbox->msg_cnt); in recv_mbox_handler()
499 INIT_WORK(&mbox_work->work, recv_func_mbox_work_handler); in recv_mbox_handler()
500 queue_work(func_to_func->workq, &mbox_work->work); in recv_mbox_handler()
505 kfree(rcv_mbox_temp->buf_out); in recv_mbox_handler()
508 kfree(rcv_mbox_temp->mbox); in recv_mbox_handler()
516 struct hinic_mbox_func_to_func *func_to_func = hwdev->func_to_func; in set_vf_mbox_random_id()
526 rand_info.vf_in_pf = func_id - hinic_glb_pf_vf_offset(hwdev->hwif); in set_vf_mbox_random_id()
529 func_to_func->vf_mbx_rand_id[func_id] = rand_info.random_id; in set_vf_mbox_random_id()
531 ret = hinic_msg_to_mgmt(&pfhwdev->pf_to_mgmt, HINIC_MOD_COMM, in set_vf_mbox_random_id()
537 …dev_err(&hwdev->hwif->pdev->dev, "Set VF random id failed, err: %d, status: 0x%x, out size: 0x%x\n… in set_vf_mbox_random_id()
539 return -EIO; in set_vf_mbox_random_id()
545 func_to_func->vf_mbx_old_rand_id[func_id] = in set_vf_mbox_random_id()
546 func_to_func->vf_mbx_rand_id[func_id]; in set_vf_mbox_random_id()
556 u16 src = mbox_work->src_func_idx; in update_random_id_work_handler()
558 func_to_func = mbox_work->func_to_func; in update_random_id_work_handler()
560 if (set_vf_mbox_random_id(func_to_func->hwdev, src)) in update_random_id_work_handler()
561 dev_warn(&func_to_func->hwdev->hwif->pdev->dev, "Update VF id: 0x%x random id failed\n", in update_random_id_work_handler()
562 mbox_work->src_func_idx); in update_random_id_work_handler()
570 struct hinic_hwdev *hwdev = func_to_func->hwdev; in check_vf_mbox_random_id()
579 if (IS_PF_OR_PPF_SRC(src) || !func_to_func->support_vf_random) in check_vf_mbox_random_id()
582 if (!HINIC_IS_PPF(hwdev->hwif)) { in check_vf_mbox_random_id()
583 offset = hinic_glb_pf_vf_offset(hwdev->hwif); in check_vf_mbox_random_id()
584 vf_in_pf = src - offset; in check_vf_mbox_random_id()
586 if (vf_in_pf < 1 || vf_in_pf > hwdev->nic_cap.max_vf) { in check_vf_mbox_random_id()
587 dev_warn(&hwdev->hwif->pdev->dev, in check_vf_mbox_random_id()
590 hwdev->nic_cap.max_vf + offset); in check_vf_mbox_random_id()
598 if (random_id == func_to_func->vf_mbx_rand_id[src] || in check_vf_mbox_random_id()
599 random_id == func_to_func->vf_mbx_old_rand_id[src]) in check_vf_mbox_random_id()
602 dev_warn(&hwdev->hwif->pdev->dev, in check_vf_mbox_random_id()
604 random_id, src, func_to_func->vf_mbx_rand_id[src]); in check_vf_mbox_random_id()
610 mbox_work->func_to_func = func_to_func; in check_vf_mbox_random_id()
611 mbox_work->src_func_idx = src; in check_vf_mbox_random_id()
613 INIT_WORK(&mbox_work->work, update_random_id_work_handler); in check_vf_mbox_random_id()
614 queue_work(func_to_func->workq, &mbox_work->work); in check_vf_mbox_random_id()
626 func_to_func = ((struct hinic_hwdev *)handle)->func_to_func; in hinic_mbox_func_aeqe_handler()
632 dev_err(&func_to_func->hwif->pdev->dev, in hinic_mbox_func_aeqe_handler()
641 &func_to_func->mbox_send[src] : in hinic_mbox_func_aeqe_handler()
642 &func_to_func->mbox_resp[src]; in hinic_mbox_func_aeqe_handler()
652 func_to_func = ((struct hinic_hwdev *)handle)->func_to_func; in hinic_mbox_self_aeqe_handler()
653 send_mbox = &func_to_func->send_mbox; in hinic_mbox_self_aeqe_handler()
655 complete(&send_mbox->send_done); in hinic_mbox_self_aeqe_handler()
660 *mbox->wb_status = 0; in clear_mbox_status()
673 __raw_writel(*(data + i), mbox->data + i * sizeof(u32)); in mbox_copy_header()
696 mbox->data + MBOX_HEADER_SZ + i * sizeof(u32)); in mbox_copy_send_data()
716 hinic_hwif_write_reg(func_to_func->hwif, in write_mbox_msg_attr()
727 hinic_hwif_write_reg(func_to_func->hwif, in write_mbox_msg_attr()
735 val = hinic_hwif_read_reg(hwdev->hwif, in dump_mox_reg()
737 dev_err(&hwdev->hwif->pdev->dev, "Mailbox control reg: 0x%x\n", val); in dump_mox_reg()
739 val = hinic_hwif_read_reg(hwdev->hwif, in dump_mox_reg()
741 dev_err(&hwdev->hwif->pdev->dev, "Mailbox interrupt offset: 0x%x\n", in dump_mox_reg()
747 /* write back is 16B, but only use first 4B */ in get_mbox_status()
748 u64 wb_val = be64_to_cpu(*mbox->wb_status); in get_mbox_status()
759 struct hinic_send_mbox *send_mbox = &func_to_func->send_mbox; in wait_for_mbox_seg_completion()
760 struct hinic_hwdev *hwdev = func_to_func->hwdev; in wait_for_mbox_seg_completion()
761 struct completion *done = &send_mbox->send_done; in wait_for_mbox_seg_completion()
776 dev_err(&hwdev->hwif->pdev->dev, "Send mailbox segment timeout, wb status: 0x%x\n", in wait_for_mbox_seg_completion()
779 return -ETIMEDOUT; in wait_for_mbox_seg_completion()
784 dev_err(&hwdev->hwif->pdev->dev, "Send mailbox segment timeout\n"); in wait_for_mbox_seg_completion()
787 return -ETIMEDOUT; in wait_for_mbox_seg_completion()
800 struct hinic_send_mbox *send_mbox = &func_to_func->send_mbox; in send_mbox_seg()
802 struct hinic_hwdev *hwdev = func_to_func->hwdev; in send_mbox_seg()
803 struct completion *done = &send_mbox->send_done; in send_mbox_seg()
804 u8 num_aeqs = hwdev->hwif->attr.num_aeqs; in send_mbox_seg()
827 return -ETIMEDOUT; in send_mbox_seg()
830 dev_err(&hwdev->hwif->pdev->dev, "Send mailbox segment to function %d error, wb status: 0x%x\n", in send_mbox_seg()
833 return errcode ? errcode : -EFAULT; in send_mbox_seg()
840 enum hinic_mod_type mod, u16 cmd, void *msg, in send_mbox_to_func() argument
846 struct hinic_hwdev *hwdev = func_to_func->hwdev; in send_mbox_to_func()
854 down(&func_to_func->msg_send_sem); in send_mbox_to_func()
857 HINIC_MBOX_HEADER_SET(mod, MODULE) | in send_mbox_to_func()
865 HINIC_MBOX_HEADER_SET(msg_info->msg_id, MSG_ID) | in send_mbox_to_func()
866 HINIC_MBOX_HEADER_SET(msg_info->status, STATUS) | in send_mbox_to_func()
867 HINIC_MBOX_HEADER_SET(hinic_global_func_id_hw(hwdev->hwif), in send_mbox_to_func()
882 dev_err(&hwdev->hwif->pdev->dev, "Failed to send mbox seg, seq_id=0x%llx\n", in send_mbox_to_func()
887 left -= HINIC_MBOX_SEG_LEN; in send_mbox_to_func()
897 up(&func_to_func->msg_send_sem); in send_mbox_to_func()
909 if (recv_mbox->ack_type == MBOX_ACK) { in response_for_recv_func_mbox()
910 msg_info.msg_id = recv_mbox->msg_info.msg_id; in response_for_recv_func_mbox()
922 send_mbox_to_func(func_to_func, recv_mbox->mod, recv_mbox->cmd, in response_for_recv_func_mbox()
923 recv_mbox->buf_out, out_size, src_func_idx, in response_for_recv_func_mbox()
933 void *buf_out = recv_mbox->buf_out; in recv_func_mbox_handler()
937 if (HINIC_IS_VF(func_to_func->hwif)) { in recv_func_mbox_handler()
942 dev_warn(&func_to_func->hwif->pdev->dev, in recv_func_mbox_handler()
953 kfree(recv_mbox->buf_out); in recv_func_mbox_handler()
954 kfree(recv_mbox->mbox); in recv_func_mbox_handler()
961 spin_lock(&func_to_func->mbox_lock); in set_mbox_to_func_event()
962 func_to_func->event_flag = event_flag; in set_mbox_to_func_event()
963 spin_unlock(&func_to_func->mbox_lock); in set_mbox_to_func_event()
968 enum hinic_mod_type mod, u16 cmd, in mbox_resp_info_handler() argument
973 if (mbox_for_resp->msg_info.status) { in mbox_resp_info_handler()
974 err = mbox_for_resp->msg_info.status; in mbox_resp_info_handler()
976 dev_err(&func_to_func->hwif->pdev->dev, "Mbox response error(0x%x)\n", in mbox_resp_info_handler()
977 mbox_for_resp->msg_info.status); in mbox_resp_info_handler()
982 if (*out_size < mbox_for_resp->mbox_len) { in mbox_resp_info_handler()
983 dev_err(&func_to_func->hwif->pdev->dev, in mbox_resp_info_handler()
984 "Invalid response mbox message length: %d for mod %d cmd %d, should less than: %d\n", in mbox_resp_info_handler()
985 mbox_for_resp->mbox_len, mod, cmd, *out_size); in mbox_resp_info_handler()
986 return -EFAULT; in mbox_resp_info_handler()
989 if (mbox_for_resp->mbox_len) in mbox_resp_info_handler()
990 memcpy(buf_out, mbox_for_resp->mbox, in mbox_resp_info_handler()
991 mbox_for_resp->mbox_len); in mbox_resp_info_handler()
993 *out_size = mbox_for_resp->mbox_len; in mbox_resp_info_handler()
1000 enum hinic_mod_type mod, u16 cmd, u16 dst_func, in hinic_mbox_to_func() argument
1009 mbox_for_resp = &func_to_func->mbox_resp[dst_func]; in hinic_mbox_to_func()
1011 down(&func_to_func->mbox_send_sem); in hinic_mbox_to_func()
1013 init_completion(&mbox_for_resp->recv_done); in hinic_mbox_to_func()
1019 err = send_mbox_to_func(func_to_func, mod, cmd, buf_in, in_size, in hinic_mbox_to_func()
1023 dev_err(&func_to_func->hwif->pdev->dev, "Send mailbox failed, msg_id: %d\n", in hinic_mbox_to_func()
1030 if (!wait_for_completion_timeout(&mbox_for_resp->recv_done, timeo)) { in hinic_mbox_to_func()
1032 dev_err(&func_to_func->hwif->pdev->dev, in hinic_mbox_to_func()
1034 hinic_dump_aeq_info(func_to_func->hwdev); in hinic_mbox_to_func()
1035 err = -ETIMEDOUT; in hinic_mbox_to_func()
1041 err = mbox_resp_info_handler(func_to_func, mbox_for_resp, mod, cmd, in hinic_mbox_to_func()
1045 up(&func_to_func->mbox_send_sem); in hinic_mbox_to_func()
1054 dev_err(&func_to_func->hwif->pdev->dev, in mbox_func_params_valid()
1057 return -EINVAL; in mbox_func_params_valid()
1064 enum hinic_mod_type mod, u8 cmd, void *buf_in, in hinic_mbox_to_pf() argument
1067 struct hinic_mbox_func_to_func *func_to_func = hwdev->func_to_func; in hinic_mbox_to_pf()
1073 if (!HINIC_IS_VF(hwdev->hwif)) { in hinic_mbox_to_pf()
1074 dev_err(&hwdev->hwif->pdev->dev, "Params error, func_type: %d\n", in hinic_mbox_to_pf()
1075 HINIC_FUNC_TYPE(hwdev->hwif)); in hinic_mbox_to_pf()
1076 return -EINVAL; in hinic_mbox_to_pf()
1079 return hinic_mbox_to_func(func_to_func, mod, cmd, in hinic_mbox_to_pf()
1080 hinic_pf_id_of_vf_hw(hwdev->hwif), buf_in, in hinic_mbox_to_pf()
1085 enum hinic_mod_type mod, u16 vf_id, u8 cmd, void *buf_in, in hinic_mbox_to_vf() argument
1093 return -EINVAL; in hinic_mbox_to_vf()
1095 func_to_func = hwdev->func_to_func; in hinic_mbox_to_vf()
1100 if (HINIC_IS_VF(hwdev->hwif)) { in hinic_mbox_to_vf()
1101 dev_err(&hwdev->hwif->pdev->dev, "Params error, func_type: %d\n", in hinic_mbox_to_vf()
1102 HINIC_FUNC_TYPE(hwdev->hwif)); in hinic_mbox_to_vf()
1103 return -EINVAL; in hinic_mbox_to_vf()
1107 dev_err(&hwdev->hwif->pdev->dev, in hinic_mbox_to_vf()
1109 return -EINVAL; in hinic_mbox_to_vf()
1115 dst_func_idx = hinic_glb_pf_vf_offset(hwdev->hwif) + vf_id; in hinic_mbox_to_vf()
1117 return hinic_mbox_to_func(func_to_func, mod, cmd, dst_func_idx, buf_in, in hinic_mbox_to_vf()
1125 mbox_info->seq_id = SEQ_ID_MAX_VAL; in init_mbox_info()
1127 mbox_info->mbox = kzalloc(MBOX_MAX_BUF_SZ, GFP_KERNEL); in init_mbox_info()
1128 if (!mbox_info->mbox) in init_mbox_info()
1129 return -ENOMEM; in init_mbox_info()
1131 mbox_info->buf_out = kzalloc(MBOX_MAX_BUF_SZ, GFP_KERNEL); in init_mbox_info()
1132 if (!mbox_info->buf_out) { in init_mbox_info()
1133 err = -ENOMEM; in init_mbox_info()
1137 atomic_set(&mbox_info->msg_cnt, 0); in init_mbox_info()
1142 kfree(mbox_info->mbox); in init_mbox_info()
1149 kfree(mbox_info->buf_out); in clean_mbox_info()
1150 kfree(mbox_info->mbox); in clean_mbox_info()
1162 dev_err(&hwdev->hwif->pdev->dev, "Failed to init function %d mbox info\n", in alloc_mbox_info()
1187 struct hinic_send_mbox *send_mbox = &func_to_func->send_mbox; in prepare_send_mbox()
1189 send_mbox->data = MBOX_AREA(func_to_func->hwif); in prepare_send_mbox()
1194 struct hinic_send_mbox *send_mbox = &func_to_func->send_mbox; in alloc_mbox_wb_status()
1195 struct hinic_hwdev *hwdev = func_to_func->hwdev; in alloc_mbox_wb_status()
1198 send_mbox->wb_vaddr = dma_alloc_coherent(&hwdev->hwif->pdev->dev, in alloc_mbox_wb_status()
1200 &send_mbox->wb_paddr, in alloc_mbox_wb_status()
1202 if (!send_mbox->wb_vaddr) in alloc_mbox_wb_status()
1203 return -ENOMEM; in alloc_mbox_wb_status()
1205 send_mbox->wb_status = send_mbox->wb_vaddr; in alloc_mbox_wb_status()
1207 addr_h = upper_32_bits(send_mbox->wb_paddr); in alloc_mbox_wb_status()
1208 addr_l = lower_32_bits(send_mbox->wb_paddr); in alloc_mbox_wb_status()
1210 hinic_hwif_write_reg(hwdev->hwif, HINIC_FUNC_CSR_MAILBOX_RESULT_H_OFF, in alloc_mbox_wb_status()
1212 hinic_hwif_write_reg(hwdev->hwif, HINIC_FUNC_CSR_MAILBOX_RESULT_L_OFF, in alloc_mbox_wb_status()
1220 struct hinic_send_mbox *send_mbox = &func_to_func->send_mbox; in free_mbox_wb_status()
1221 struct hinic_hwdev *hwdev = func_to_func->hwdev; in free_mbox_wb_status()
1223 hinic_hwif_write_reg(hwdev->hwif, HINIC_FUNC_CSR_MAILBOX_RESULT_H_OFF, in free_mbox_wb_status()
1225 hinic_hwif_write_reg(hwdev->hwif, HINIC_FUNC_CSR_MAILBOX_RESULT_L_OFF, in free_mbox_wb_status()
1228 dma_free_coherent(&hwdev->hwif->pdev->dev, MBOX_WB_STATUS_LEN, in free_mbox_wb_status()
1229 send_mbox->wb_vaddr, in free_mbox_wb_status()
1230 send_mbox->wb_paddr); in free_mbox_wb_status()
1238 u16 src_idx = vf_id + hinic_glb_pf_vf_offset(hwdev->hwif); in hinic_mbox_check_cmd_valid()
1251 dev_err(&hwdev->hwif->pdev->dev, in hinic_mbox_check_cmd_valid()
1253 vf_id + hinic_glb_pf_vf_offset(hwdev->hwif), cmd); in hinic_mbox_check_cmd_valid()
1261 struct hinic_cmdq_ctxt_info *ctxt_info = &cmdq_ctxt->ctxt_info; in hinic_cmdq_check_vf_ctxt()
1264 if (cmdq_ctxt->ppf_idx != HINIC_HWIF_PPF_IDX(hwdev->hwif) || in hinic_cmdq_check_vf_ctxt()
1265 cmdq_ctxt->cmdq_type > HINIC_MAX_CMDQ_TYPES) in hinic_cmdq_check_vf_ctxt()
1269 (ctxt_info->curr_wqe_page_pfn, CURR_WQE_PAGE_PFN); in hinic_cmdq_check_vf_ctxt()
1271 (ctxt_info->wq_block_pfn, WQ_BLOCK_PFN); in hinic_cmdq_check_vf_ctxt()
1272 /* VF must use 0-level CLA */ in hinic_cmdq_check_vf_ctxt()
1289 ((hw_ctxt)->rq_depth >= HINIC_QUEUE_MIN_DEPTH && \
1290 (hw_ctxt)->rq_depth <= HINIC_QUEUE_MAX_DEPTH && \
1291 (hw_ctxt)->sq_depth >= HINIC_QUEUE_MIN_DEPTH && \
1292 (hw_ctxt)->sq_depth <= HINIC_QUEUE_MAX_DEPTH && \
1293 (hw_ctxt)->rx_buf_sz_idx <= HINIC_MAX_RX_BUFFER_SIZE)
1300 if (!hw_ctxt->rq_depth && !hw_ctxt->sq_depth && in hw_ctxt_qps_param_valid()
1301 !hw_ctxt->rx_buf_sz_idx) in hw_ctxt_qps_param_valid()
1315 if (hw_ctxt->ppf_idx != HINIC_HWIF_PPF_IDX(hwdev->hwif)) in check_hwctxt()
1318 if (hw_ctxt->set_cmdq_depth) { in check_hwctxt()
1319 if (hw_ctxt->cmdq_depth >= HINIC_QUEUE_MIN_DEPTH && in check_hwctxt()
1320 hw_ctxt->cmdq_depth <= HINIC_QUEUE_MAX_DEPTH) in check_hwctxt()
1337 if (page_size_info->ppf_idx != HINIC_HWIF_PPF_IDX(hwdev->hwif)) in check_set_wq_page_size()
1340 if (((1U << page_size_info->page_size) * SZ_4K) != in check_set_wq_page_size()
1376 dev_err(&hwdev->hwif->pdev->dev, in comm_pf_mbox_handler()
1378 vf_id + hinic_glb_pf_vf_offset(hwdev->hwif), cmd, in comm_pf_mbox_handler()
1386 err = hinic_msg_to_mgmt(&pfhwdev->pf_to_mgmt, HINIC_MOD_COMM, in comm_pf_mbox_handler()
1390 dev_err(&hwdev->hwif->pdev->dev, in comm_pf_mbox_handler()
1407 return -ENOMEM; in hinic_func_to_func_init()
1409 hwdev->func_to_func = func_to_func; in hinic_func_to_func_init()
1410 func_to_func->hwdev = hwdev; in hinic_func_to_func_init()
1411 func_to_func->hwif = hwdev->hwif; in hinic_func_to_func_init()
1412 sema_init(&func_to_func->mbox_send_sem, 1); in hinic_func_to_func_init()
1413 sema_init(&func_to_func->msg_send_sem, 1); in hinic_func_to_func_init()
1414 spin_lock_init(&func_to_func->mbox_lock); in hinic_func_to_func_init()
1415 func_to_func->workq = create_singlethread_workqueue(HINIC_MBOX_WQ_NAME); in hinic_func_to_func_init()
1416 if (!func_to_func->workq) { in hinic_func_to_func_init()
1417 dev_err(&hwdev->hwif->pdev->dev, "Failed to initialize MBOX workqueue\n"); in hinic_func_to_func_init()
1418 err = -ENOMEM; in hinic_func_to_func_init()
1422 err = alloc_mbox_info(hwdev, func_to_func->mbox_send); in hinic_func_to_func_init()
1424 dev_err(&hwdev->hwif->pdev->dev, "Failed to alloc mem for mbox_active\n"); in hinic_func_to_func_init()
1428 err = alloc_mbox_info(hwdev, func_to_func->mbox_resp); in hinic_func_to_func_init()
1430 dev_err(&hwdev->hwif->pdev->dev, "Failed to alloc mem for mbox_passive\n"); in hinic_func_to_func_init()
1436 dev_err(&hwdev->hwif->pdev->dev, "Failed to alloc mbox write back status\n"); in hinic_func_to_func_init()
1442 hinic_aeq_register_hw_cb(&hwdev->aeqs, HINIC_MBX_FROM_FUNC, in hinic_func_to_func_init()
1443 &pfhwdev->hwdev, hinic_mbox_func_aeqe_handler); in hinic_func_to_func_init()
1444 hinic_aeq_register_hw_cb(&hwdev->aeqs, HINIC_MBX_SEND_RSLT, in hinic_func_to_func_init()
1445 &pfhwdev->hwdev, hinic_mbox_self_aeqe_handler); in hinic_func_to_func_init()
1447 if (!HINIC_IS_VF(hwdev->hwif)) in hinic_func_to_func_init()
1454 free_mbox_info(func_to_func->mbox_resp); in hinic_func_to_func_init()
1457 free_mbox_info(func_to_func->mbox_send); in hinic_func_to_func_init()
1460 destroy_workqueue(func_to_func->workq); in hinic_func_to_func_init()
1470 struct hinic_mbox_func_to_func *func_to_func = hwdev->func_to_func; in hinic_func_to_func_free()
1472 hinic_aeq_unregister_hw_cb(&hwdev->aeqs, HINIC_MBX_FROM_FUNC); in hinic_func_to_func_free()
1473 hinic_aeq_unregister_hw_cb(&hwdev->aeqs, HINIC_MBX_SEND_RSLT); in hinic_func_to_func_free()
1479 destroy_workqueue(func_to_func->workq); in hinic_func_to_func_free()
1482 free_mbox_info(func_to_func->mbox_resp); in hinic_func_to_func_free()
1483 free_mbox_info(func_to_func->mbox_send); in hinic_func_to_func_free()
1494 if (HINIC_IS_VF(hwdev->hwif)) in hinic_vf_mbox_random_id_init()
1497 vf_offset = hinic_glb_pf_vf_offset(hwdev->hwif); in hinic_vf_mbox_random_id_init()
1499 for (vf_in_pf = 1; vf_in_pf <= hwdev->nic_cap.max_vf; vf_in_pf++) { in hinic_vf_mbox_random_id_init()
1506 hwdev->func_to_func->support_vf_random = false; in hinic_vf_mbox_random_id_init()
1508 dev_warn(&hwdev->hwif->pdev->dev, "Mgmt is unsupported to set VF%d random id\n", in hinic_vf_mbox_random_id_init()
1509 vf_in_pf - 1); in hinic_vf_mbox_random_id_init()
1511 hwdev->func_to_func->support_vf_random = true; in hinic_vf_mbox_random_id_init()