0001
0002
0003
0004
0005
0006
0007 #include "otx2_common.h"
0008
0009
0010 static int otx2_dl_mcam_count_validate(struct devlink *devlink, u32 id,
0011 union devlink_param_value val,
0012 struct netlink_ext_ack *extack)
0013 {
0014 struct otx2_devlink *otx2_dl = devlink_priv(devlink);
0015 struct otx2_nic *pfvf = otx2_dl->pfvf;
0016 struct otx2_flow_config *flow_cfg;
0017
0018 if (!pfvf->flow_cfg) {
0019 NL_SET_ERR_MSG_MOD(extack,
0020 "pfvf->flow_cfg not initialized");
0021 return -EINVAL;
0022 }
0023
0024 flow_cfg = pfvf->flow_cfg;
0025 if (flow_cfg && flow_cfg->nr_flows) {
0026 NL_SET_ERR_MSG_MOD(extack,
0027 "Cannot modify count when there are active rules");
0028 return -EINVAL;
0029 }
0030
0031 return 0;
0032 }
0033
0034 static int otx2_dl_mcam_count_set(struct devlink *devlink, u32 id,
0035 struct devlink_param_gset_ctx *ctx)
0036 {
0037 struct otx2_devlink *otx2_dl = devlink_priv(devlink);
0038 struct otx2_nic *pfvf = otx2_dl->pfvf;
0039
0040 if (!pfvf->flow_cfg)
0041 return 0;
0042
0043 otx2_alloc_mcam_entries(pfvf, ctx->val.vu16);
0044 otx2_tc_alloc_ent_bitmap(pfvf);
0045
0046 return 0;
0047 }
0048
0049 static int otx2_dl_mcam_count_get(struct devlink *devlink, u32 id,
0050 struct devlink_param_gset_ctx *ctx)
0051 {
0052 struct otx2_devlink *otx2_dl = devlink_priv(devlink);
0053 struct otx2_nic *pfvf = otx2_dl->pfvf;
0054 struct otx2_flow_config *flow_cfg;
0055
0056 if (!pfvf->flow_cfg) {
0057 ctx->val.vu16 = 0;
0058 return 0;
0059 }
0060
0061 flow_cfg = pfvf->flow_cfg;
0062 ctx->val.vu16 = flow_cfg->max_flows;
0063
0064 return 0;
0065 }
0066
0067 enum otx2_dl_param_id {
0068 OTX2_DEVLINK_PARAM_ID_BASE = DEVLINK_PARAM_GENERIC_ID_MAX,
0069 OTX2_DEVLINK_PARAM_ID_MCAM_COUNT,
0070 };
0071
0072 static const struct devlink_param otx2_dl_params[] = {
0073 DEVLINK_PARAM_DRIVER(OTX2_DEVLINK_PARAM_ID_MCAM_COUNT,
0074 "mcam_count", DEVLINK_PARAM_TYPE_U16,
0075 BIT(DEVLINK_PARAM_CMODE_RUNTIME),
0076 otx2_dl_mcam_count_get, otx2_dl_mcam_count_set,
0077 otx2_dl_mcam_count_validate),
0078 };
0079
0080
0081 static int otx2_devlink_info_get(struct devlink *devlink,
0082 struct devlink_info_req *req,
0083 struct netlink_ext_ack *extack)
0084 {
0085 struct otx2_devlink *otx2_dl = devlink_priv(devlink);
0086 struct otx2_nic *pfvf = otx2_dl->pfvf;
0087
0088 if (is_otx2_vf(pfvf->pcifunc))
0089 return devlink_info_driver_name_put(req, "rvu_nicvf");
0090
0091 return devlink_info_driver_name_put(req, "rvu_nicpf");
0092 }
0093
0094 static const struct devlink_ops otx2_devlink_ops = {
0095 .info_get = otx2_devlink_info_get,
0096 };
0097
0098 int otx2_register_dl(struct otx2_nic *pfvf)
0099 {
0100 struct otx2_devlink *otx2_dl;
0101 struct devlink *dl;
0102 int err;
0103
0104 dl = devlink_alloc(&otx2_devlink_ops,
0105 sizeof(struct otx2_devlink), pfvf->dev);
0106 if (!dl) {
0107 dev_warn(pfvf->dev, "devlink_alloc failed\n");
0108 return -ENOMEM;
0109 }
0110
0111 otx2_dl = devlink_priv(dl);
0112 otx2_dl->dl = dl;
0113 otx2_dl->pfvf = pfvf;
0114 pfvf->dl = otx2_dl;
0115
0116 err = devlink_params_register(dl, otx2_dl_params,
0117 ARRAY_SIZE(otx2_dl_params));
0118 if (err) {
0119 dev_err(pfvf->dev,
0120 "devlink params register failed with error %d", err);
0121 goto err_dl;
0122 }
0123
0124 devlink_register(dl);
0125 return 0;
0126
0127 err_dl:
0128 devlink_free(dl);
0129 return err;
0130 }
0131
0132 void otx2_unregister_dl(struct otx2_nic *pfvf)
0133 {
0134 struct otx2_devlink *otx2_dl = pfvf->dl;
0135 struct devlink *dl = otx2_dl->dl;
0136
0137 devlink_unregister(dl);
0138 devlink_params_unregister(dl, otx2_dl_params,
0139 ARRAY_SIZE(otx2_dl_params));
0140 devlink_free(dl);
0141 }