162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 262306a36Sopenharmony_ci/* Copyright (C) 2021 Marvell. */ 362306a36Sopenharmony_ci 462306a36Sopenharmony_ci#include "otx2_cpt_devlink.h" 562306a36Sopenharmony_ci 662306a36Sopenharmony_cistatic int otx2_cpt_dl_egrp_create(struct devlink *dl, u32 id, 762306a36Sopenharmony_ci struct devlink_param_gset_ctx *ctx) 862306a36Sopenharmony_ci{ 962306a36Sopenharmony_ci struct otx2_cpt_devlink *cpt_dl = devlink_priv(dl); 1062306a36Sopenharmony_ci struct otx2_cptpf_dev *cptpf = cpt_dl->cptpf; 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ci return otx2_cpt_dl_custom_egrp_create(cptpf, ctx); 1362306a36Sopenharmony_ci} 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_cistatic int otx2_cpt_dl_egrp_delete(struct devlink *dl, u32 id, 1662306a36Sopenharmony_ci struct devlink_param_gset_ctx *ctx) 1762306a36Sopenharmony_ci{ 1862306a36Sopenharmony_ci struct otx2_cpt_devlink *cpt_dl = devlink_priv(dl); 1962306a36Sopenharmony_ci struct otx2_cptpf_dev *cptpf = cpt_dl->cptpf; 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ci return otx2_cpt_dl_custom_egrp_delete(cptpf, ctx); 2262306a36Sopenharmony_ci} 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_cistatic int otx2_cpt_dl_uc_info(struct devlink *dl, u32 id, 2562306a36Sopenharmony_ci struct devlink_param_gset_ctx *ctx) 2662306a36Sopenharmony_ci{ 2762306a36Sopenharmony_ci struct otx2_cpt_devlink *cpt_dl = devlink_priv(dl); 2862306a36Sopenharmony_ci struct otx2_cptpf_dev *cptpf = cpt_dl->cptpf; 2962306a36Sopenharmony_ci 3062306a36Sopenharmony_ci otx2_cpt_print_uc_dbg_info(cptpf); 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_ci return 0; 3362306a36Sopenharmony_ci} 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_cienum otx2_cpt_dl_param_id { 3662306a36Sopenharmony_ci OTX2_CPT_DEVLINK_PARAM_ID_BASE = DEVLINK_PARAM_GENERIC_ID_MAX, 3762306a36Sopenharmony_ci OTX2_CPT_DEVLINK_PARAM_ID_EGRP_CREATE, 3862306a36Sopenharmony_ci OTX2_CPT_DEVLINK_PARAM_ID_EGRP_DELETE, 3962306a36Sopenharmony_ci}; 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_cistatic const struct devlink_param otx2_cpt_dl_params[] = { 4262306a36Sopenharmony_ci DEVLINK_PARAM_DRIVER(OTX2_CPT_DEVLINK_PARAM_ID_EGRP_CREATE, 4362306a36Sopenharmony_ci "egrp_create", DEVLINK_PARAM_TYPE_STRING, 4462306a36Sopenharmony_ci BIT(DEVLINK_PARAM_CMODE_RUNTIME), 4562306a36Sopenharmony_ci otx2_cpt_dl_uc_info, otx2_cpt_dl_egrp_create, 4662306a36Sopenharmony_ci NULL), 4762306a36Sopenharmony_ci DEVLINK_PARAM_DRIVER(OTX2_CPT_DEVLINK_PARAM_ID_EGRP_DELETE, 4862306a36Sopenharmony_ci "egrp_delete", DEVLINK_PARAM_TYPE_STRING, 4962306a36Sopenharmony_ci BIT(DEVLINK_PARAM_CMODE_RUNTIME), 5062306a36Sopenharmony_ci otx2_cpt_dl_uc_info, otx2_cpt_dl_egrp_delete, 5162306a36Sopenharmony_ci NULL), 5262306a36Sopenharmony_ci}; 5362306a36Sopenharmony_ci 5462306a36Sopenharmony_cistatic int otx2_cpt_dl_info_firmware_version_put(struct devlink_info_req *req, 5562306a36Sopenharmony_ci struct otx2_cpt_eng_grp_info grp[], 5662306a36Sopenharmony_ci const char *ver_name, int eng_type) 5762306a36Sopenharmony_ci{ 5862306a36Sopenharmony_ci struct otx2_cpt_engs_rsvd *eng; 5962306a36Sopenharmony_ci int i; 6062306a36Sopenharmony_ci 6162306a36Sopenharmony_ci for (i = 0; i < OTX2_CPT_MAX_ENGINE_GROUPS; i++) { 6262306a36Sopenharmony_ci eng = find_engines_by_type(&grp[i], eng_type); 6362306a36Sopenharmony_ci if (eng) 6462306a36Sopenharmony_ci return devlink_info_version_running_put(req, ver_name, 6562306a36Sopenharmony_ci eng->ucode->ver_str); 6662306a36Sopenharmony_ci } 6762306a36Sopenharmony_ci 6862306a36Sopenharmony_ci return 0; 6962306a36Sopenharmony_ci} 7062306a36Sopenharmony_ci 7162306a36Sopenharmony_cistatic int otx2_cpt_devlink_info_get(struct devlink *dl, 7262306a36Sopenharmony_ci struct devlink_info_req *req, 7362306a36Sopenharmony_ci struct netlink_ext_ack *extack) 7462306a36Sopenharmony_ci{ 7562306a36Sopenharmony_ci struct otx2_cpt_devlink *cpt_dl = devlink_priv(dl); 7662306a36Sopenharmony_ci struct otx2_cptpf_dev *cptpf = cpt_dl->cptpf; 7762306a36Sopenharmony_ci int err; 7862306a36Sopenharmony_ci 7962306a36Sopenharmony_ci err = otx2_cpt_dl_info_firmware_version_put(req, cptpf->eng_grps.grp, 8062306a36Sopenharmony_ci "fw.ae", OTX2_CPT_AE_TYPES); 8162306a36Sopenharmony_ci if (err) 8262306a36Sopenharmony_ci return err; 8362306a36Sopenharmony_ci 8462306a36Sopenharmony_ci err = otx2_cpt_dl_info_firmware_version_put(req, cptpf->eng_grps.grp, 8562306a36Sopenharmony_ci "fw.se", OTX2_CPT_SE_TYPES); 8662306a36Sopenharmony_ci if (err) 8762306a36Sopenharmony_ci return err; 8862306a36Sopenharmony_ci 8962306a36Sopenharmony_ci return otx2_cpt_dl_info_firmware_version_put(req, cptpf->eng_grps.grp, 9062306a36Sopenharmony_ci "fw.ie", OTX2_CPT_IE_TYPES); 9162306a36Sopenharmony_ci} 9262306a36Sopenharmony_ci 9362306a36Sopenharmony_cistatic const struct devlink_ops otx2_cpt_devlink_ops = { 9462306a36Sopenharmony_ci .info_get = otx2_cpt_devlink_info_get, 9562306a36Sopenharmony_ci}; 9662306a36Sopenharmony_ci 9762306a36Sopenharmony_ciint otx2_cpt_register_dl(struct otx2_cptpf_dev *cptpf) 9862306a36Sopenharmony_ci{ 9962306a36Sopenharmony_ci struct device *dev = &cptpf->pdev->dev; 10062306a36Sopenharmony_ci struct otx2_cpt_devlink *cpt_dl; 10162306a36Sopenharmony_ci struct devlink *dl; 10262306a36Sopenharmony_ci int ret; 10362306a36Sopenharmony_ci 10462306a36Sopenharmony_ci dl = devlink_alloc(&otx2_cpt_devlink_ops, 10562306a36Sopenharmony_ci sizeof(struct otx2_cpt_devlink), dev); 10662306a36Sopenharmony_ci if (!dl) { 10762306a36Sopenharmony_ci dev_warn(dev, "devlink_alloc failed\n"); 10862306a36Sopenharmony_ci return -ENOMEM; 10962306a36Sopenharmony_ci } 11062306a36Sopenharmony_ci 11162306a36Sopenharmony_ci cpt_dl = devlink_priv(dl); 11262306a36Sopenharmony_ci cpt_dl->dl = dl; 11362306a36Sopenharmony_ci cpt_dl->cptpf = cptpf; 11462306a36Sopenharmony_ci cptpf->dl = dl; 11562306a36Sopenharmony_ci ret = devlink_params_register(dl, otx2_cpt_dl_params, 11662306a36Sopenharmony_ci ARRAY_SIZE(otx2_cpt_dl_params)); 11762306a36Sopenharmony_ci if (ret) { 11862306a36Sopenharmony_ci dev_err(dev, "devlink params register failed with error %d", 11962306a36Sopenharmony_ci ret); 12062306a36Sopenharmony_ci devlink_free(dl); 12162306a36Sopenharmony_ci return ret; 12262306a36Sopenharmony_ci } 12362306a36Sopenharmony_ci 12462306a36Sopenharmony_ci devlink_register(dl); 12562306a36Sopenharmony_ci 12662306a36Sopenharmony_ci return 0; 12762306a36Sopenharmony_ci} 12862306a36Sopenharmony_ci 12962306a36Sopenharmony_civoid otx2_cpt_unregister_dl(struct otx2_cptpf_dev *cptpf) 13062306a36Sopenharmony_ci{ 13162306a36Sopenharmony_ci struct devlink *dl = cptpf->dl; 13262306a36Sopenharmony_ci 13362306a36Sopenharmony_ci if (!dl) 13462306a36Sopenharmony_ci return; 13562306a36Sopenharmony_ci 13662306a36Sopenharmony_ci devlink_unregister(dl); 13762306a36Sopenharmony_ci devlink_params_unregister(dl, otx2_cpt_dl_params, 13862306a36Sopenharmony_ci ARRAY_SIZE(otx2_cpt_dl_params)); 13962306a36Sopenharmony_ci devlink_free(dl); 14062306a36Sopenharmony_ci} 141