Path: blob/master/drivers/crypto/marvell/octeontx2/otx2_cpt_devlink.c
26285 views
// SPDX-License-Identifier: GPL-2.0-only1/* Copyright (C) 2021 Marvell. */23#include "otx2_cpt_devlink.h"45static int otx2_cpt_dl_egrp_create(struct devlink *dl, u32 id,6struct devlink_param_gset_ctx *ctx,7struct netlink_ext_ack *extack)8{9struct otx2_cpt_devlink *cpt_dl = devlink_priv(dl);10struct otx2_cptpf_dev *cptpf = cpt_dl->cptpf;1112return otx2_cpt_dl_custom_egrp_create(cptpf, ctx);13}1415static int otx2_cpt_dl_egrp_delete(struct devlink *dl, u32 id,16struct devlink_param_gset_ctx *ctx,17struct netlink_ext_ack *extack)18{19struct otx2_cpt_devlink *cpt_dl = devlink_priv(dl);20struct otx2_cptpf_dev *cptpf = cpt_dl->cptpf;2122return otx2_cpt_dl_custom_egrp_delete(cptpf, ctx);23}2425static int otx2_cpt_dl_uc_info(struct devlink *dl, u32 id,26struct devlink_param_gset_ctx *ctx)27{28ctx->val.vstr[0] = '\0';2930return 0;31}3233static int otx2_cpt_dl_t106_mode_get(struct devlink *dl, u32 id,34struct devlink_param_gset_ctx *ctx)35{36struct otx2_cpt_devlink *cpt_dl = devlink_priv(dl);37struct otx2_cptpf_dev *cptpf = cpt_dl->cptpf;38struct pci_dev *pdev = cptpf->pdev;39u64 reg_val = 0;4041otx2_cpt_read_af_reg(&cptpf->afpf_mbox, pdev, CPT_AF_CTL, ®_val,42BLKADDR_CPT0);43ctx->val.vu8 = (reg_val >> 18) & 0x1;4445return 0;46}4748static int otx2_cpt_dl_t106_mode_set(struct devlink *dl, u32 id,49struct devlink_param_gset_ctx *ctx,50struct netlink_ext_ack *extack)51{52struct otx2_cpt_devlink *cpt_dl = devlink_priv(dl);53struct otx2_cptpf_dev *cptpf = cpt_dl->cptpf;54struct pci_dev *pdev = cptpf->pdev;55u64 reg_val = 0;5657if (cptpf->enabled_vfs != 0 || cptpf->eng_grps.is_grps_created)58return -EPERM;5960if (cpt_feature_sgv2(pdev)) {61otx2_cpt_read_af_reg(&cptpf->afpf_mbox, pdev, CPT_AF_CTL,62®_val, BLKADDR_CPT0);63reg_val &= ~(0x1ULL << 18);64reg_val |= ((u64)ctx->val.vu8 & 0x1) << 18;65return otx2_cpt_write_af_reg(&cptpf->afpf_mbox, pdev,66CPT_AF_CTL, reg_val, BLKADDR_CPT0);67}6869return 0;70}7172enum otx2_cpt_dl_param_id {73OTX2_CPT_DEVLINK_PARAM_ID_BASE = DEVLINK_PARAM_GENERIC_ID_MAX,74OTX2_CPT_DEVLINK_PARAM_ID_EGRP_CREATE,75OTX2_CPT_DEVLINK_PARAM_ID_EGRP_DELETE,76OTX2_CPT_DEVLINK_PARAM_ID_T106_MODE,77};7879static const struct devlink_param otx2_cpt_dl_params[] = {80DEVLINK_PARAM_DRIVER(OTX2_CPT_DEVLINK_PARAM_ID_EGRP_CREATE,81"egrp_create", DEVLINK_PARAM_TYPE_STRING,82BIT(DEVLINK_PARAM_CMODE_RUNTIME),83otx2_cpt_dl_uc_info, otx2_cpt_dl_egrp_create,84NULL),85DEVLINK_PARAM_DRIVER(OTX2_CPT_DEVLINK_PARAM_ID_EGRP_DELETE,86"egrp_delete", DEVLINK_PARAM_TYPE_STRING,87BIT(DEVLINK_PARAM_CMODE_RUNTIME),88otx2_cpt_dl_uc_info, otx2_cpt_dl_egrp_delete,89NULL),90DEVLINK_PARAM_DRIVER(OTX2_CPT_DEVLINK_PARAM_ID_T106_MODE,91"t106_mode", DEVLINK_PARAM_TYPE_U8,92BIT(DEVLINK_PARAM_CMODE_RUNTIME),93otx2_cpt_dl_t106_mode_get, otx2_cpt_dl_t106_mode_set,94NULL),95};9697static int otx2_cpt_dl_info_firmware_version_put(struct devlink_info_req *req,98struct otx2_cpt_eng_grp_info grp[],99const char *ver_name, int eng_type)100{101struct otx2_cpt_engs_rsvd *eng;102int i;103104for (i = 0; i < OTX2_CPT_MAX_ENGINE_GROUPS; i++) {105eng = find_engines_by_type(&grp[i], eng_type);106if (eng)107return devlink_info_version_running_put(req, ver_name,108eng->ucode->ver_str);109}110111return 0;112}113114static int otx2_cpt_devlink_info_get(struct devlink *dl,115struct devlink_info_req *req,116struct netlink_ext_ack *extack)117{118struct otx2_cpt_devlink *cpt_dl = devlink_priv(dl);119struct otx2_cptpf_dev *cptpf = cpt_dl->cptpf;120int err;121122err = otx2_cpt_dl_info_firmware_version_put(req, cptpf->eng_grps.grp,123"fw.ae", OTX2_CPT_AE_TYPES);124if (err)125return err;126127err = otx2_cpt_dl_info_firmware_version_put(req, cptpf->eng_grps.grp,128"fw.se", OTX2_CPT_SE_TYPES);129if (err)130return err;131132return otx2_cpt_dl_info_firmware_version_put(req, cptpf->eng_grps.grp,133"fw.ie", OTX2_CPT_IE_TYPES);134}135136static const struct devlink_ops otx2_cpt_devlink_ops = {137.info_get = otx2_cpt_devlink_info_get,138};139140int otx2_cpt_register_dl(struct otx2_cptpf_dev *cptpf)141{142struct device *dev = &cptpf->pdev->dev;143struct otx2_cpt_devlink *cpt_dl;144struct devlink *dl;145int ret;146147dl = devlink_alloc(&otx2_cpt_devlink_ops,148sizeof(struct otx2_cpt_devlink), dev);149if (!dl) {150dev_warn(dev, "devlink_alloc failed\n");151return -ENOMEM;152}153154cpt_dl = devlink_priv(dl);155cpt_dl->dl = dl;156cpt_dl->cptpf = cptpf;157cptpf->dl = dl;158ret = devlink_params_register(dl, otx2_cpt_dl_params,159ARRAY_SIZE(otx2_cpt_dl_params));160if (ret) {161dev_err(dev, "devlink params register failed with error %d",162ret);163devlink_free(dl);164return ret;165}166devlink_register(dl);167168return 0;169}170171void otx2_cpt_unregister_dl(struct otx2_cptpf_dev *cptpf)172{173struct devlink *dl = cptpf->dl;174175if (!dl)176return;177178devlink_unregister(dl);179devlink_params_unregister(dl, otx2_cpt_dl_params,180ARRAY_SIZE(otx2_cpt_dl_params));181devlink_free(dl);182}183184185