Path: blob/master/drivers/crypto/marvell/octeontx/otx_cptpf_mbox.c
26295 views
// SPDX-License-Identifier: GPL-2.01/* Marvell OcteonTX CPT driver2*3* Copyright (C) 2019 Marvell International Ltd.4*5* This program is free software; you can redistribute it and/or modify6* it under the terms of the GNU General Public License version 2 as7* published by the Free Software Foundation.8*/910#include "otx_cpt_common.h"11#include "otx_cptpf.h"1213static char *get_mbox_opcode_str(int msg_opcode)14{15char *str = "Unknown";1617switch (msg_opcode) {18case OTX_CPT_MSG_VF_UP:19str = "UP";20break;2122case OTX_CPT_MSG_VF_DOWN:23str = "DOWN";24break;2526case OTX_CPT_MSG_READY:27str = "READY";28break;2930case OTX_CPT_MSG_QLEN:31str = "QLEN";32break;3334case OTX_CPT_MSG_QBIND_GRP:35str = "QBIND_GRP";36break;3738case OTX_CPT_MSG_VQ_PRIORITY:39str = "VQ_PRIORITY";40break;4142case OTX_CPT_MSG_PF_TYPE:43str = "PF_TYPE";44break;4546case OTX_CPT_MSG_ACK:47str = "ACK";48break;4950case OTX_CPT_MSG_NACK:51str = "NACK";52break;53}5455return str;56}5758static void dump_mbox_msg(struct otx_cpt_mbox *mbox_msg, int vf_id)59{60char raw_data_str[OTX_CPT_MAX_MBOX_DATA_STR_SIZE];6162hex_dump_to_buffer(mbox_msg, sizeof(struct otx_cpt_mbox), 16, 8,63raw_data_str, OTX_CPT_MAX_MBOX_DATA_STR_SIZE, false);64if (vf_id >= 0)65pr_debug("MBOX opcode %s received from VF%d raw_data %s\n",66get_mbox_opcode_str(mbox_msg->msg), vf_id,67raw_data_str);68else69pr_debug("MBOX opcode %s received from PF raw_data %s\n",70get_mbox_opcode_str(mbox_msg->msg), raw_data_str);71}7273static void otx_cpt_send_msg_to_vf(struct otx_cpt_device *cpt, int vf,74struct otx_cpt_mbox *mbx)75{76/* Writing mbox(0) causes interrupt */77writeq(mbx->data, cpt->reg_base + OTX_CPT_PF_VFX_MBOXX(vf, 1));78writeq(mbx->msg, cpt->reg_base + OTX_CPT_PF_VFX_MBOXX(vf, 0));79}8081/*82* ACKs VF's mailbox message83* @vf: VF to which ACK to be sent84*/85static void otx_cpt_mbox_send_ack(struct otx_cpt_device *cpt, int vf,86struct otx_cpt_mbox *mbx)87{88mbx->data = 0ull;89mbx->msg = OTX_CPT_MSG_ACK;90otx_cpt_send_msg_to_vf(cpt, vf, mbx);91}9293/* NACKs VF's mailbox message that PF is not able to complete the action */94static void otx_cptpf_mbox_send_nack(struct otx_cpt_device *cpt, int vf,95struct otx_cpt_mbox *mbx)96{97mbx->data = 0ull;98mbx->msg = OTX_CPT_MSG_NACK;99otx_cpt_send_msg_to_vf(cpt, vf, mbx);100}101102static void otx_cpt_clear_mbox_intr(struct otx_cpt_device *cpt, u32 vf)103{104/* W1C for the VF */105writeq(1ull << vf, cpt->reg_base + OTX_CPT_PF_MBOX_INTX(0));106}107108/*109* Configure QLEN/Chunk sizes for VF110*/111static void otx_cpt_cfg_qlen_for_vf(struct otx_cpt_device *cpt, int vf,112u32 size)113{114union otx_cptx_pf_qx_ctl pf_qx_ctl;115116pf_qx_ctl.u = readq(cpt->reg_base + OTX_CPT_PF_QX_CTL(vf));117pf_qx_ctl.s.size = size;118pf_qx_ctl.s.cont_err = true;119writeq(pf_qx_ctl.u, cpt->reg_base + OTX_CPT_PF_QX_CTL(vf));120}121122/*123* Configure VQ priority124*/125static void otx_cpt_cfg_vq_priority(struct otx_cpt_device *cpt, int vf, u32 pri)126{127union otx_cptx_pf_qx_ctl pf_qx_ctl;128129pf_qx_ctl.u = readq(cpt->reg_base + OTX_CPT_PF_QX_CTL(vf));130pf_qx_ctl.s.pri = pri;131writeq(pf_qx_ctl.u, cpt->reg_base + OTX_CPT_PF_QX_CTL(vf));132}133134static int otx_cpt_bind_vq_to_grp(struct otx_cpt_device *cpt, u8 q, u8 grp)135{136struct device *dev = &cpt->pdev->dev;137struct otx_cpt_eng_grp_info *eng_grp;138union otx_cptx_pf_qx_ctl pf_qx_ctl;139struct otx_cpt_ucode *ucode;140141if (q >= cpt->max_vfs) {142dev_err(dev, "Requested queue %d is > than maximum avail %d\n",143q, cpt->max_vfs);144return -EINVAL;145}146147if (grp >= OTX_CPT_MAX_ENGINE_GROUPS) {148dev_err(dev, "Requested group %d is > than maximum avail %d\n",149grp, OTX_CPT_MAX_ENGINE_GROUPS);150return -EINVAL;151}152153eng_grp = &cpt->eng_grps.grp[grp];154if (!eng_grp->is_enabled) {155dev_err(dev, "Requested engine group %d is disabled\n", grp);156return -EINVAL;157}158159pf_qx_ctl.u = readq(cpt->reg_base + OTX_CPT_PF_QX_CTL(q));160pf_qx_ctl.s.grp = grp;161writeq(pf_qx_ctl.u, cpt->reg_base + OTX_CPT_PF_QX_CTL(q));162163if (eng_grp->mirror.is_ena)164ucode = &eng_grp->g->grp[eng_grp->mirror.idx].ucode[0];165else166ucode = &eng_grp->ucode[0];167168if (otx_cpt_uc_supports_eng_type(ucode, OTX_CPT_SE_TYPES))169return OTX_CPT_SE_TYPES;170else if (otx_cpt_uc_supports_eng_type(ucode, OTX_CPT_AE_TYPES))171return OTX_CPT_AE_TYPES;172else173return BAD_OTX_CPTVF_TYPE;174}175176/* Interrupt handler to handle mailbox messages from VFs */177static void otx_cpt_handle_mbox_intr(struct otx_cpt_device *cpt, int vf)178{179int vftype = 0;180struct otx_cpt_mbox mbx = {};181struct device *dev = &cpt->pdev->dev;182/*183* MBOX[0] contains msg184* MBOX[1] contains data185*/186mbx.msg = readq(cpt->reg_base + OTX_CPT_PF_VFX_MBOXX(vf, 0));187mbx.data = readq(cpt->reg_base + OTX_CPT_PF_VFX_MBOXX(vf, 1));188189dump_mbox_msg(&mbx, vf);190191switch (mbx.msg) {192case OTX_CPT_MSG_VF_UP:193mbx.msg = OTX_CPT_MSG_VF_UP;194mbx.data = cpt->vfs_enabled;195otx_cpt_send_msg_to_vf(cpt, vf, &mbx);196break;197case OTX_CPT_MSG_READY:198mbx.msg = OTX_CPT_MSG_READY;199mbx.data = vf;200otx_cpt_send_msg_to_vf(cpt, vf, &mbx);201break;202case OTX_CPT_MSG_VF_DOWN:203/* First msg in VF teardown sequence */204otx_cpt_mbox_send_ack(cpt, vf, &mbx);205break;206case OTX_CPT_MSG_QLEN:207otx_cpt_cfg_qlen_for_vf(cpt, vf, mbx.data);208otx_cpt_mbox_send_ack(cpt, vf, &mbx);209break;210case OTX_CPT_MSG_QBIND_GRP:211vftype = otx_cpt_bind_vq_to_grp(cpt, vf, (u8)mbx.data);212if ((vftype != OTX_CPT_AE_TYPES) &&213(vftype != OTX_CPT_SE_TYPES)) {214dev_err(dev, "VF%d binding to eng group %llu failed\n",215vf, mbx.data);216otx_cptpf_mbox_send_nack(cpt, vf, &mbx);217} else {218mbx.msg = OTX_CPT_MSG_QBIND_GRP;219mbx.data = vftype;220otx_cpt_send_msg_to_vf(cpt, vf, &mbx);221}222break;223case OTX_CPT_MSG_PF_TYPE:224mbx.msg = OTX_CPT_MSG_PF_TYPE;225mbx.data = cpt->pf_type;226otx_cpt_send_msg_to_vf(cpt, vf, &mbx);227break;228case OTX_CPT_MSG_VQ_PRIORITY:229otx_cpt_cfg_vq_priority(cpt, vf, mbx.data);230otx_cpt_mbox_send_ack(cpt, vf, &mbx);231break;232default:233dev_err(&cpt->pdev->dev, "Invalid msg from VF%d, msg 0x%llx\n",234vf, mbx.msg);235break;236}237}238239void otx_cpt_mbox_intr_handler (struct otx_cpt_device *cpt, int mbx)240{241u64 intr;242u8 vf;243244intr = readq(cpt->reg_base + OTX_CPT_PF_MBOX_INTX(0));245pr_debug("PF interrupt mbox%d mask 0x%llx\n", mbx, intr);246for (vf = 0; vf < cpt->max_vfs; vf++) {247if (intr & (1ULL << vf)) {248otx_cpt_handle_mbox_intr(cpt, vf);249otx_cpt_clear_mbox_intr(cpt, vf);250}251}252}253254255