otx2_devlink.c (3295B)
1// SPDX-License-Identifier: GPL-2.0 2/* Marvell RVU PF/VF Netdev Devlink 3 * 4 * Copyright (C) 2021 Marvell. 5 */ 6 7#include "otx2_common.h" 8 9/* Devlink Params APIs */ 10static int otx2_dl_mcam_count_validate(struct devlink *devlink, u32 id, 11 union devlink_param_value val, 12 struct netlink_ext_ack *extack) 13{ 14 struct otx2_devlink *otx2_dl = devlink_priv(devlink); 15 struct otx2_nic *pfvf = otx2_dl->pfvf; 16 struct otx2_flow_config *flow_cfg; 17 18 if (!pfvf->flow_cfg) { 19 NL_SET_ERR_MSG_MOD(extack, 20 "pfvf->flow_cfg not initialized"); 21 return -EINVAL; 22 } 23 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"); 28 return -EINVAL; 29 } 30 31 return 0; 32} 33 34static int otx2_dl_mcam_count_set(struct devlink *devlink, u32 id, 35 struct devlink_param_gset_ctx *ctx) 36{ 37 struct otx2_devlink *otx2_dl = devlink_priv(devlink); 38 struct otx2_nic *pfvf = otx2_dl->pfvf; 39 40 if (!pfvf->flow_cfg) 41 return 0; 42 43 otx2_alloc_mcam_entries(pfvf, ctx->val.vu16); 44 otx2_tc_alloc_ent_bitmap(pfvf); 45 46 return 0; 47} 48 49static int otx2_dl_mcam_count_get(struct devlink *devlink, u32 id, 50 struct devlink_param_gset_ctx *ctx) 51{ 52 struct otx2_devlink *otx2_dl = devlink_priv(devlink); 53 struct otx2_nic *pfvf = otx2_dl->pfvf; 54 struct otx2_flow_config *flow_cfg; 55 56 if (!pfvf->flow_cfg) { 57 ctx->val.vu16 = 0; 58 return 0; 59 } 60 61 flow_cfg = pfvf->flow_cfg; 62 ctx->val.vu16 = flow_cfg->max_flows; 63 64 return 0; 65} 66 67enum otx2_dl_param_id { 68 OTX2_DEVLINK_PARAM_ID_BASE = DEVLINK_PARAM_GENERIC_ID_MAX, 69 OTX2_DEVLINK_PARAM_ID_MCAM_COUNT, 70}; 71 72static const struct devlink_param otx2_dl_params[] = { 73 DEVLINK_PARAM_DRIVER(OTX2_DEVLINK_PARAM_ID_MCAM_COUNT, 74 "mcam_count", DEVLINK_PARAM_TYPE_U16, 75 BIT(DEVLINK_PARAM_CMODE_RUNTIME), 76 otx2_dl_mcam_count_get, otx2_dl_mcam_count_set, 77 otx2_dl_mcam_count_validate), 78}; 79 80/* Devlink OPs */ 81static int otx2_devlink_info_get(struct devlink *devlink, 82 struct devlink_info_req *req, 83 struct netlink_ext_ack *extack) 84{ 85 struct otx2_devlink *otx2_dl = devlink_priv(devlink); 86 struct otx2_nic *pfvf = otx2_dl->pfvf; 87 88 if (is_otx2_vf(pfvf->pcifunc)) 89 return devlink_info_driver_name_put(req, "rvu_nicvf"); 90 91 return devlink_info_driver_name_put(req, "rvu_nicpf"); 92} 93 94static const struct devlink_ops otx2_devlink_ops = { 95 .info_get = otx2_devlink_info_get, 96}; 97 98int otx2_register_dl(struct otx2_nic *pfvf) 99{ 100 struct otx2_devlink *otx2_dl; 101 struct devlink *dl; 102 int err; 103 104 dl = devlink_alloc(&otx2_devlink_ops, 105 sizeof(struct otx2_devlink), pfvf->dev); 106 if (!dl) { 107 dev_warn(pfvf->dev, "devlink_alloc failed\n"); 108 return -ENOMEM; 109 } 110 111 otx2_dl = devlink_priv(dl); 112 otx2_dl->dl = dl; 113 otx2_dl->pfvf = pfvf; 114 pfvf->dl = otx2_dl; 115 116 err = devlink_params_register(dl, otx2_dl_params, 117 ARRAY_SIZE(otx2_dl_params)); 118 if (err) { 119 dev_err(pfvf->dev, 120 "devlink params register failed with error %d", err); 121 goto err_dl; 122 } 123 124 devlink_register(dl); 125 return 0; 126 127err_dl: 128 devlink_free(dl); 129 return err; 130} 131 132void otx2_unregister_dl(struct otx2_nic *pfvf) 133{ 134 struct otx2_devlink *otx2_dl = pfvf->dl; 135 struct devlink *dl = otx2_dl->dl; 136 137 devlink_unregister(dl); 138 devlink_params_unregister(dl, otx2_dl_params, 139 ARRAY_SIZE(otx2_dl_params)); 140 devlink_free(dl); 141}