Path: blob/master/drivers/crypto/marvell/octeontx2/otx2_cpt_devlink.c
53511 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,27struct netlink_ext_ack *extack)28{29ctx->val.vstr[0] = '\0';3031return 0;32}3334static int otx2_cpt_dl_t106_mode_get(struct devlink *dl, u32 id,35struct devlink_param_gset_ctx *ctx,36struct netlink_ext_ack *extack)37{38struct otx2_cpt_devlink *cpt_dl = devlink_priv(dl);39struct otx2_cptpf_dev *cptpf = cpt_dl->cptpf;40struct pci_dev *pdev = cptpf->pdev;41u64 reg_val = 0;4243otx2_cpt_read_af_reg(&cptpf->afpf_mbox, pdev, CPT_AF_CTL, ®_val,44BLKADDR_CPT0);45ctx->val.vu8 = (reg_val >> 18) & 0x1;4647return 0;48}4950static int otx2_cpt_dl_t106_mode_set(struct devlink *dl, u32 id,51struct devlink_param_gset_ctx *ctx,52struct netlink_ext_ack *extack)53{54struct otx2_cpt_devlink *cpt_dl = devlink_priv(dl);55struct otx2_cptpf_dev *cptpf = cpt_dl->cptpf;56struct pci_dev *pdev = cptpf->pdev;57u64 reg_val = 0;5859if (cptpf->enabled_vfs != 0 || cptpf->eng_grps.is_grps_created)60return -EPERM;6162if (cpt_feature_sgv2(pdev)) {63otx2_cpt_read_af_reg(&cptpf->afpf_mbox, pdev, CPT_AF_CTL,64®_val, BLKADDR_CPT0);65reg_val &= ~(0x1ULL << 18);66reg_val |= ((u64)ctx->val.vu8 & 0x1) << 18;67return otx2_cpt_write_af_reg(&cptpf->afpf_mbox, pdev,68CPT_AF_CTL, reg_val, BLKADDR_CPT0);69}7071return 0;72}7374enum otx2_cpt_dl_param_id {75OTX2_CPT_DEVLINK_PARAM_ID_BASE = DEVLINK_PARAM_GENERIC_ID_MAX,76OTX2_CPT_DEVLINK_PARAM_ID_EGRP_CREATE,77OTX2_CPT_DEVLINK_PARAM_ID_EGRP_DELETE,78OTX2_CPT_DEVLINK_PARAM_ID_T106_MODE,79};8081static const struct devlink_param otx2_cpt_dl_params[] = {82DEVLINK_PARAM_DRIVER(OTX2_CPT_DEVLINK_PARAM_ID_EGRP_CREATE,83"egrp_create", DEVLINK_PARAM_TYPE_STRING,84BIT(DEVLINK_PARAM_CMODE_RUNTIME),85otx2_cpt_dl_uc_info, otx2_cpt_dl_egrp_create,86NULL),87DEVLINK_PARAM_DRIVER(OTX2_CPT_DEVLINK_PARAM_ID_EGRP_DELETE,88"egrp_delete", DEVLINK_PARAM_TYPE_STRING,89BIT(DEVLINK_PARAM_CMODE_RUNTIME),90otx2_cpt_dl_uc_info, otx2_cpt_dl_egrp_delete,91NULL),92DEVLINK_PARAM_DRIVER(OTX2_CPT_DEVLINK_PARAM_ID_T106_MODE,93"t106_mode", DEVLINK_PARAM_TYPE_U8,94BIT(DEVLINK_PARAM_CMODE_RUNTIME),95otx2_cpt_dl_t106_mode_get, otx2_cpt_dl_t106_mode_set,96NULL),97};9899static int otx2_cpt_dl_info_firmware_version_put(struct devlink_info_req *req,100struct otx2_cpt_eng_grp_info grp[],101const char *ver_name, int eng_type)102{103struct otx2_cpt_engs_rsvd *eng;104int i;105106for (i = 0; i < OTX2_CPT_MAX_ENGINE_GROUPS; i++) {107eng = find_engines_by_type(&grp[i], eng_type);108if (eng)109return devlink_info_version_running_put(req, ver_name,110eng->ucode->ver_str);111}112113return 0;114}115116static int otx2_cpt_devlink_info_get(struct devlink *dl,117struct devlink_info_req *req,118struct netlink_ext_ack *extack)119{120struct otx2_cpt_devlink *cpt_dl = devlink_priv(dl);121struct otx2_cptpf_dev *cptpf = cpt_dl->cptpf;122int err;123124err = otx2_cpt_dl_info_firmware_version_put(req, cptpf->eng_grps.grp,125"fw.ae", OTX2_CPT_AE_TYPES);126if (err)127return err;128129err = otx2_cpt_dl_info_firmware_version_put(req, cptpf->eng_grps.grp,130"fw.se", OTX2_CPT_SE_TYPES);131if (err)132return err;133134return otx2_cpt_dl_info_firmware_version_put(req, cptpf->eng_grps.grp,135"fw.ie", OTX2_CPT_IE_TYPES);136}137138static const struct devlink_ops otx2_cpt_devlink_ops = {139.info_get = otx2_cpt_devlink_info_get,140};141142int otx2_cpt_register_dl(struct otx2_cptpf_dev *cptpf)143{144struct device *dev = &cptpf->pdev->dev;145struct otx2_cpt_devlink *cpt_dl;146struct devlink *dl;147int ret;148149dl = devlink_alloc(&otx2_cpt_devlink_ops,150sizeof(struct otx2_cpt_devlink), dev);151if (!dl) {152dev_warn(dev, "devlink_alloc failed\n");153return -ENOMEM;154}155156cpt_dl = devlink_priv(dl);157cpt_dl->dl = dl;158cpt_dl->cptpf = cptpf;159cptpf->dl = dl;160ret = devlink_params_register(dl, otx2_cpt_dl_params,161ARRAY_SIZE(otx2_cpt_dl_params));162if (ret) {163dev_err(dev, "devlink params register failed with error %d",164ret);165devlink_free(dl);166return ret;167}168devlink_register(dl);169170return 0;171}172173void otx2_cpt_unregister_dl(struct otx2_cptpf_dev *cptpf)174{175struct devlink *dl = cptpf->dl;176177if (!dl)178return;179180devlink_unregister(dl);181devlink_params_unregister(dl, otx2_cpt_dl_params,182ARRAY_SIZE(otx2_cpt_dl_params));183devlink_free(dl);184}185186187