linux/drivers/crypto/marvell/octeontx2/otx2_cpt_devlink.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0-only
   2/* Copyright (C) 2021 Marvell. */
   3
   4#include "otx2_cpt_devlink.h"
   5
   6static int otx2_cpt_dl_egrp_create(struct devlink *dl, u32 id,
   7                                   struct devlink_param_gset_ctx *ctx)
   8{
   9        struct otx2_cpt_devlink *cpt_dl = devlink_priv(dl);
  10        struct otx2_cptpf_dev *cptpf = cpt_dl->cptpf;
  11
  12        return otx2_cpt_dl_custom_egrp_create(cptpf, ctx);
  13}
  14
  15static int otx2_cpt_dl_egrp_delete(struct devlink *dl, u32 id,
  16                                   struct devlink_param_gset_ctx *ctx)
  17{
  18        struct otx2_cpt_devlink *cpt_dl = devlink_priv(dl);
  19        struct otx2_cptpf_dev *cptpf = cpt_dl->cptpf;
  20
  21        return otx2_cpt_dl_custom_egrp_delete(cptpf, ctx);
  22}
  23
  24static int otx2_cpt_dl_uc_info(struct devlink *dl, u32 id,
  25                               struct devlink_param_gset_ctx *ctx)
  26{
  27        struct otx2_cpt_devlink *cpt_dl = devlink_priv(dl);
  28        struct otx2_cptpf_dev *cptpf = cpt_dl->cptpf;
  29
  30        otx2_cpt_print_uc_dbg_info(cptpf);
  31
  32        return 0;
  33}
  34
  35enum otx2_cpt_dl_param_id {
  36        OTX2_CPT_DEVLINK_PARAM_ID_BASE = DEVLINK_PARAM_GENERIC_ID_MAX,
  37        OTX2_CPT_DEVLINK_PARAM_ID_EGRP_CREATE,
  38        OTX2_CPT_DEVLINK_PARAM_ID_EGRP_DELETE,
  39};
  40
  41static const struct devlink_param otx2_cpt_dl_params[] = {
  42        DEVLINK_PARAM_DRIVER(OTX2_CPT_DEVLINK_PARAM_ID_EGRP_CREATE,
  43                             "egrp_create", DEVLINK_PARAM_TYPE_STRING,
  44                             BIT(DEVLINK_PARAM_CMODE_RUNTIME),
  45                             otx2_cpt_dl_uc_info, otx2_cpt_dl_egrp_create,
  46                             NULL),
  47        DEVLINK_PARAM_DRIVER(OTX2_CPT_DEVLINK_PARAM_ID_EGRP_DELETE,
  48                             "egrp_delete", DEVLINK_PARAM_TYPE_STRING,
  49                             BIT(DEVLINK_PARAM_CMODE_RUNTIME),
  50                             otx2_cpt_dl_uc_info, otx2_cpt_dl_egrp_delete,
  51                             NULL),
  52};
  53
  54static int otx2_cpt_devlink_info_get(struct devlink *devlink,
  55                                     struct devlink_info_req *req,
  56                                     struct netlink_ext_ack *extack)
  57{
  58        return devlink_info_driver_name_put(req, "rvu_cptpf");
  59}
  60
  61static const struct devlink_ops otx2_cpt_devlink_ops = {
  62        .info_get = otx2_cpt_devlink_info_get,
  63};
  64
  65int otx2_cpt_register_dl(struct otx2_cptpf_dev *cptpf)
  66{
  67        struct device *dev = &cptpf->pdev->dev;
  68        struct otx2_cpt_devlink *cpt_dl;
  69        struct devlink *dl;
  70        int ret;
  71
  72        dl = devlink_alloc(&otx2_cpt_devlink_ops,
  73                           sizeof(struct otx2_cpt_devlink), dev);
  74        if (!dl) {
  75                dev_warn(dev, "devlink_alloc failed\n");
  76                return -ENOMEM;
  77        }
  78
  79        cpt_dl = devlink_priv(dl);
  80        cpt_dl->dl = dl;
  81        cpt_dl->cptpf = cptpf;
  82        cptpf->dl = dl;
  83        ret = devlink_params_register(dl, otx2_cpt_dl_params,
  84                                      ARRAY_SIZE(otx2_cpt_dl_params));
  85        if (ret) {
  86                dev_err(dev, "devlink params register failed with error %d",
  87                        ret);
  88                devlink_free(dl);
  89                return ret;
  90        }
  91
  92        devlink_register(dl);
  93
  94        return 0;
  95}
  96
  97void otx2_cpt_unregister_dl(struct otx2_cptpf_dev *cptpf)
  98{
  99        struct devlink *dl = cptpf->dl;
 100
 101        if (!dl)
 102                return;
 103
 104        devlink_unregister(dl);
 105        devlink_params_unregister(dl, otx2_cpt_dl_params,
 106                                  ARRAY_SIZE(otx2_cpt_dl_params));
 107        devlink_free(dl);
 108}
 109