1 // SPDX-License-Identifier: GPL-2.0
2 /* Marvell RVU PF/VF Netdev Devlink
4 * Copyright (C) 2021 Marvell.
7 #include "otx2_common.h"
9 /* Devlink Params APIs */
10 static int otx2_dl_mcam_count_validate(struct devlink *devlink, u32 id,
11 union devlink_param_value val,
12 struct netlink_ext_ack *extack)
14 struct otx2_devlink *otx2_dl = devlink_priv(devlink);
15 struct otx2_nic *pfvf = otx2_dl->pfvf;
16 struct otx2_flow_config *flow_cfg;
18 if (!pfvf->flow_cfg) {
19 NL_SET_ERR_MSG_MOD(extack,
20 "pfvf->flow_cfg not initialized");
24 flow_cfg = pfvf->flow_cfg;
25 if (flow_cfg && flow_cfg->nr_flows) {
26 NL_SET_ERR_MSG_MOD(extack,
27 "Cannot modify count when there are active rules");
34 static int otx2_dl_mcam_count_set(struct devlink *devlink, u32 id,
35 struct devlink_param_gset_ctx *ctx)
37 struct otx2_devlink *otx2_dl = devlink_priv(devlink);
38 struct otx2_nic *pfvf = otx2_dl->pfvf;
43 otx2_alloc_mcam_entries(pfvf, ctx->val.vu16);
48 static int otx2_dl_mcam_count_get(struct devlink *devlink, u32 id,
49 struct devlink_param_gset_ctx *ctx)
51 struct otx2_devlink *otx2_dl = devlink_priv(devlink);
52 struct otx2_nic *pfvf = otx2_dl->pfvf;
53 struct otx2_flow_config *flow_cfg;
55 if (!pfvf->flow_cfg) {
60 flow_cfg = pfvf->flow_cfg;
61 ctx->val.vu16 = flow_cfg->max_flows;
66 enum otx2_dl_param_id {
67 OTX2_DEVLINK_PARAM_ID_BASE = DEVLINK_PARAM_GENERIC_ID_MAX,
68 OTX2_DEVLINK_PARAM_ID_MCAM_COUNT,
71 static const struct devlink_param otx2_dl_params[] = {
72 DEVLINK_PARAM_DRIVER(OTX2_DEVLINK_PARAM_ID_MCAM_COUNT,
73 "mcam_count", DEVLINK_PARAM_TYPE_U16,
74 BIT(DEVLINK_PARAM_CMODE_RUNTIME),
75 otx2_dl_mcam_count_get, otx2_dl_mcam_count_set,
76 otx2_dl_mcam_count_validate),
79 static const struct devlink_ops otx2_devlink_ops = {
82 int otx2_register_dl(struct otx2_nic *pfvf)
84 struct otx2_devlink *otx2_dl;
88 dl = devlink_alloc(&otx2_devlink_ops,
89 sizeof(struct otx2_devlink), pfvf->dev);
91 dev_warn(pfvf->dev, "devlink_alloc failed\n");
95 otx2_dl = devlink_priv(dl);
100 err = devlink_params_register(dl, otx2_dl_params,
101 ARRAY_SIZE(otx2_dl_params));
104 "devlink params register failed with error %d", err);
108 devlink_register(dl);
116 void otx2_unregister_dl(struct otx2_nic *pfvf)
118 struct otx2_devlink *otx2_dl = pfvf->dl;
119 struct devlink *dl = otx2_dl->dl;
121 devlink_unregister(dl);
122 devlink_params_unregister(dl, otx2_dl_params,
123 ARRAY_SIZE(otx2_dl_params));