1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Cavium, Inc
7 #include "otx_cryptodev_hw_access.h"
8 #include "otx_cryptodev_mbox.h"
11 otx_cpt_handle_mbox_intr(struct cpt_vf *cptvf)
13 struct cpt_mbox mbx = {0, 0};
16 * MBOX[0] contains msg
17 * MBOX[1] contains data
19 mbx.msg = CPT_READ_CSR(CPT_CSR_REG_BASE(cptvf),
20 CPTX_VFX_PF_MBOXX(0, 0, 0));
21 mbx.data = CPT_READ_CSR(CPT_CSR_REG_BASE(cptvf),
22 CPTX_VFX_PF_MBOXX(0, 0, 1));
24 CPT_LOG_DP_DEBUG("%s: Mailbox msg 0x%lx from PF",
25 cptvf->dev_name, (unsigned int long)mbx.msg);
27 case OTX_CPT_MSG_VF_UP:
28 cptvf->pf_acked = true;
30 case OTX_CPT_MSG_READY:
32 otx_cpt_chipid_vfid_t cid;
35 cptvf->pf_acked = true;
36 cptvf->vfid = cid.s.vfid;
37 CPT_LOG_DP_DEBUG("%s: Received VFID %d chip_id %d",
39 cptvf->vfid, cid.s.chip_id);
42 case OTX_CPT_MSG_QBIND_GRP:
43 cptvf->pf_acked = true;
44 cptvf->vftype = mbx.data;
45 CPT_LOG_DP_DEBUG("%s: VF %d group %d",
46 cptvf->dev_name, cptvf->vfid,
49 case OTX_CPT_MSG_PF_TYPE:
50 cptvf->pf_acked = true;
51 if (mbx.data == OTX_CPT_PF_TYPE_AE)
52 cptvf->vftype = OTX_CPT_VF_TYPE_AE;
53 else if (mbx.data == OTX_CPT_PF_TYPE_SE)
54 cptvf->vftype = OTX_CPT_VF_TYPE_SE;
56 cptvf->vftype = OTX_CPT_VF_TYPE_INVALID;
58 case OTX_CPT_MBOX_MSG_TYPE_ACK:
59 cptvf->pf_acked = true;
61 case OTX_CPT_MBOX_MSG_TYPE_NACK:
62 cptvf->pf_nacked = true;
65 CPT_LOG_DP_DEBUG("%s: Invalid msg from PF, msg 0x%lx",
66 cptvf->dev_name, (unsigned int long)mbx.msg);
71 /* Send a mailbox message to PF
72 * @vf: vf from which this message to be sent
73 * @mbx: Message to be sent
76 otx_cpt_send_msg_to_pf(struct cpt_vf *cptvf, struct cpt_mbox *mbx)
78 /* Writing mbox(1) causes interrupt */
79 CPT_WRITE_CSR(CPT_CSR_REG_BASE(cptvf),
80 CPTX_VFX_PF_MBOXX(0, 0, 0), mbx->msg);
81 CPT_WRITE_CSR(CPT_CSR_REG_BASE(cptvf),
82 CPTX_VFX_PF_MBOXX(0, 0, 1), mbx->data);
86 otx_cpt_send_msg_to_pf_timeout(struct cpt_vf *cptvf, struct cpt_mbox *mbx)
88 int timeout = OTX_CPT_MBOX_MSG_TIMEOUT;
91 cptvf->pf_acked = false;
92 cptvf->pf_nacked = false;
94 otx_cpt_send_msg_to_pf(cptvf, mbx);
96 /* Wait for previous message to be acked, timeout 2sec */
97 while (!cptvf->pf_acked) {
100 usleep(sleep_ms * 1000);
101 otx_cpt_poll_misc(cptvf);
106 CPT_LOG_ERR("%s: PF didn't ack mbox msg %lx(vfid %u)",
108 (unsigned int long)(mbx->msg & 0xFF),
117 otx_cpt_check_pf_ready(struct cpt_vf *cptvf)
119 struct cpt_mbox mbx = {0, 0};
121 mbx.msg = OTX_CPT_MSG_READY;
122 if (otx_cpt_send_msg_to_pf_timeout(cptvf, &mbx)) {
123 CPT_LOG_ERR("%s: PF didn't respond to READY msg",
131 otx_cpt_get_dev_type(struct cpt_vf *cptvf)
133 struct cpt_mbox mbx = {0, 0};
135 mbx.msg = OTX_CPT_MSG_PF_TYPE;
136 if (otx_cpt_send_msg_to_pf_timeout(cptvf, &mbx)) {
137 CPT_LOG_ERR("%s: PF didn't respond to query msg",
145 otx_cpt_send_vq_size_msg(struct cpt_vf *cptvf)
147 struct cpt_mbox mbx = {0, 0};
149 mbx.msg = OTX_CPT_MSG_QLEN;
151 mbx.data = cptvf->qsize;
152 if (otx_cpt_send_msg_to_pf_timeout(cptvf, &mbx)) {
153 CPT_LOG_ERR("%s: PF didn't respond to vq_size msg",
161 otx_cpt_send_vf_grp_msg(struct cpt_vf *cptvf, uint32_t group)
163 struct cpt_mbox mbx = {0, 0};
165 mbx.msg = OTX_CPT_MSG_QBIND_GRP;
167 /* Convey group of the VF */
169 if (otx_cpt_send_msg_to_pf_timeout(cptvf, &mbx)) {
170 CPT_LOG_ERR("%s: PF didn't respond to vf_type msg",
178 otx_cpt_send_vf_up(struct cpt_vf *cptvf)
180 struct cpt_mbox mbx = {0, 0};
182 mbx.msg = OTX_CPT_MSG_VF_UP;
183 if (otx_cpt_send_msg_to_pf_timeout(cptvf, &mbx)) {
184 CPT_LOG_ERR("%s: PF didn't respond to UP msg",
192 otx_cpt_send_vf_down(struct cpt_vf *cptvf)
194 struct cpt_mbox mbx = {0, 0};
196 mbx.msg = OTX_CPT_MSG_VF_DOWN;
197 if (otx_cpt_send_msg_to_pf_timeout(cptvf, &mbx)) {
198 CPT_LOG_ERR("%s: PF didn't respond to DOWN msg",