xref: /openbmc/linux/drivers/net/wwan/iosm/iosm_ipc_devlink.c (revision 6c71a0574249f5e5a45fe055ab5f837023d5eeca)
14dcd183fSM Chetan Kumar // SPDX-License-Identifier: GPL-2.0-only
24dcd183fSM Chetan Kumar /*
34dcd183fSM Chetan Kumar  * Copyright (C) 2020-2021 Intel Corporation.
44dcd183fSM Chetan Kumar  */
5980ec04aSM Chetan Kumar #include <linux/vmalloc.h>
64dcd183fSM Chetan Kumar 
74dcd183fSM Chetan Kumar #include "iosm_ipc_chnl_cfg.h"
84dcd183fSM Chetan Kumar #include "iosm_ipc_coredump.h"
94dcd183fSM Chetan Kumar #include "iosm_ipc_devlink.h"
104dcd183fSM Chetan Kumar #include "iosm_ipc_flash.h"
114dcd183fSM Chetan Kumar 
124dcd183fSM Chetan Kumar /* Coredump list */
134dcd183fSM Chetan Kumar static struct iosm_coredump_file_info list[IOSM_NOF_CD_REGION] = {
144dcd183fSM Chetan Kumar 	{"report.json", REPORT_JSON_SIZE,},
154dcd183fSM Chetan Kumar 	{"coredump.fcd", COREDUMP_FCD_SIZE,},
164dcd183fSM Chetan Kumar 	{"cdd.log", CDD_LOG_SIZE,},
174dcd183fSM Chetan Kumar 	{"eeprom.bin", EEPROM_BIN_SIZE,},
184dcd183fSM Chetan Kumar 	{"bootcore_trace.bin", BOOTCORE_TRC_BIN_SIZE,},
194dcd183fSM Chetan Kumar 	{"bootcore_prev_trace.bin", BOOTCORE_PREV_TRC_BIN_SIZE,},
204dcd183fSM Chetan Kumar };
214dcd183fSM Chetan Kumar 
224dcd183fSM Chetan Kumar /* Get the param values for the specific param ID's */
ipc_devlink_get_param(struct devlink * dl,u32 id,struct devlink_param_gset_ctx * ctx)234dcd183fSM Chetan Kumar static int ipc_devlink_get_param(struct devlink *dl, u32 id,
244dcd183fSM Chetan Kumar 				 struct devlink_param_gset_ctx *ctx)
254dcd183fSM Chetan Kumar {
264dcd183fSM Chetan Kumar 	struct iosm_devlink *ipc_devlink = devlink_priv(dl);
274dcd183fSM Chetan Kumar 
28b8aa1654SM Chetan Kumar 	if (id == IOSM_DEVLINK_PARAM_ID_ERASE_FULL_FLASH)
294dcd183fSM Chetan Kumar 		ctx->val.vu8 = ipc_devlink->param.erase_full_flash;
304dcd183fSM Chetan Kumar 
31b8aa1654SM Chetan Kumar 	return 0;
324dcd183fSM Chetan Kumar }
334dcd183fSM Chetan Kumar 
344dcd183fSM Chetan Kumar /* Set the param values for the specific param ID's */
ipc_devlink_set_param(struct devlink * dl,u32 id,struct devlink_param_gset_ctx * ctx)354dcd183fSM Chetan Kumar static int ipc_devlink_set_param(struct devlink *dl, u32 id,
364dcd183fSM Chetan Kumar 				 struct devlink_param_gset_ctx *ctx)
374dcd183fSM Chetan Kumar {
384dcd183fSM Chetan Kumar 	struct iosm_devlink *ipc_devlink = devlink_priv(dl);
394dcd183fSM Chetan Kumar 
40b8aa1654SM Chetan Kumar 	if (id == IOSM_DEVLINK_PARAM_ID_ERASE_FULL_FLASH)
414dcd183fSM Chetan Kumar 		ipc_devlink->param.erase_full_flash = ctx->val.vu8;
424dcd183fSM Chetan Kumar 
43b8aa1654SM Chetan Kumar 	return 0;
444dcd183fSM Chetan Kumar }
454dcd183fSM Chetan Kumar 
464dcd183fSM Chetan Kumar /* Devlink param structure array */
474dcd183fSM Chetan Kumar static const struct devlink_param iosm_devlink_params[] = {
484dcd183fSM Chetan Kumar 	DEVLINK_PARAM_DRIVER(IOSM_DEVLINK_PARAM_ID_ERASE_FULL_FLASH,
494dcd183fSM Chetan Kumar 			     "erase_full_flash", DEVLINK_PARAM_TYPE_BOOL,
504dcd183fSM Chetan Kumar 			     BIT(DEVLINK_PARAM_CMODE_RUNTIME),
514dcd183fSM Chetan Kumar 			     ipc_devlink_get_param, ipc_devlink_set_param,
524dcd183fSM Chetan Kumar 			     NULL),
534dcd183fSM Chetan Kumar };
544dcd183fSM Chetan Kumar 
554dcd183fSM Chetan Kumar /* Get devlink flash component type */
564dcd183fSM Chetan Kumar static enum iosm_flash_comp_type
ipc_devlink_get_flash_comp_type(const char comp_str[],u32 len)574dcd183fSM Chetan Kumar ipc_devlink_get_flash_comp_type(const char comp_str[], u32 len)
584dcd183fSM Chetan Kumar {
594dcd183fSM Chetan Kumar 	enum iosm_flash_comp_type fls_type;
604dcd183fSM Chetan Kumar 
614dcd183fSM Chetan Kumar 	if (!strncmp("PSI", comp_str, len))
624dcd183fSM Chetan Kumar 		fls_type = FLASH_COMP_TYPE_PSI;
634dcd183fSM Chetan Kumar 	else if (!strncmp("EBL", comp_str, len))
644dcd183fSM Chetan Kumar 		fls_type = FLASH_COMP_TYPE_EBL;
654dcd183fSM Chetan Kumar 	else if (!strncmp("FLS", comp_str, len))
664dcd183fSM Chetan Kumar 		fls_type = FLASH_COMP_TYPE_FLS;
674dcd183fSM Chetan Kumar 	else
684dcd183fSM Chetan Kumar 		fls_type = FLASH_COMP_TYPE_INVAL;
694dcd183fSM Chetan Kumar 
704dcd183fSM Chetan Kumar 	return fls_type;
714dcd183fSM Chetan Kumar }
724dcd183fSM Chetan Kumar 
734dcd183fSM Chetan Kumar /* Function triggered on devlink flash command
744dcd183fSM Chetan Kumar  * Flash update function which calls multiple functions based on
754dcd183fSM Chetan Kumar  * component type specified in the flash command
764dcd183fSM Chetan Kumar  */
ipc_devlink_flash_update(struct devlink * devlink,struct devlink_flash_update_params * params,struct netlink_ext_ack * extack)774dcd183fSM Chetan Kumar static int ipc_devlink_flash_update(struct devlink *devlink,
784dcd183fSM Chetan Kumar 				    struct devlink_flash_update_params *params,
794dcd183fSM Chetan Kumar 				    struct netlink_ext_ack *extack)
804dcd183fSM Chetan Kumar {
814dcd183fSM Chetan Kumar 	struct iosm_devlink *ipc_devlink = devlink_priv(devlink);
824dcd183fSM Chetan Kumar 	enum iosm_flash_comp_type fls_type;
83b8aa1654SM Chetan Kumar 	struct iosm_devlink_image *header;
848bea96efSM Chetan Kumar 	int rc = -EINVAL;
854dcd183fSM Chetan Kumar 	u8 *mdm_rsp;
864dcd183fSM Chetan Kumar 
87b8aa1654SM Chetan Kumar 	header = (struct iosm_devlink_image *)params->fw->data;
88b8aa1654SM Chetan Kumar 
89b8aa1654SM Chetan Kumar 	if (!header || params->fw->size <= IOSM_DEVLINK_HDR_SIZE ||
90b8aa1654SM Chetan Kumar 	    (memcmp(header->magic_header, IOSM_DEVLINK_MAGIC_HEADER,
91b8aa1654SM Chetan Kumar 	     IOSM_DEVLINK_MAGIC_HEADER_LEN) != 0))
928bea96efSM Chetan Kumar 		return -EINVAL;
934dcd183fSM Chetan Kumar 
944dcd183fSM Chetan Kumar 	mdm_rsp = kzalloc(IOSM_EBL_DW_PACK_SIZE, GFP_KERNEL);
954dcd183fSM Chetan Kumar 	if (!mdm_rsp)
964dcd183fSM Chetan Kumar 		return -ENOMEM;
974dcd183fSM Chetan Kumar 
98b8aa1654SM Chetan Kumar 	fls_type = ipc_devlink_get_flash_comp_type(header->image_type,
99b8aa1654SM Chetan Kumar 						   IOSM_DEVLINK_MAX_IMG_LEN);
1004dcd183fSM Chetan Kumar 
1014dcd183fSM Chetan Kumar 	switch (fls_type) {
1024dcd183fSM Chetan Kumar 	case FLASH_COMP_TYPE_PSI:
1034dcd183fSM Chetan Kumar 		rc = ipc_flash_boot_psi(ipc_devlink, params->fw);
1044dcd183fSM Chetan Kumar 		break;
1054dcd183fSM Chetan Kumar 	case FLASH_COMP_TYPE_EBL:
1064dcd183fSM Chetan Kumar 		rc = ipc_flash_boot_ebl(ipc_devlink, params->fw);
1078bea96efSM Chetan Kumar 		if (rc)
1088bea96efSM Chetan Kumar 			break;
1098bea96efSM Chetan Kumar 		rc = ipc_flash_boot_set_capabilities(ipc_devlink, mdm_rsp);
1108bea96efSM Chetan Kumar 		if (rc)
1118bea96efSM Chetan Kumar 			break;
1124dcd183fSM Chetan Kumar 		rc = ipc_flash_read_swid(ipc_devlink, mdm_rsp);
1134dcd183fSM Chetan Kumar 		break;
1144dcd183fSM Chetan Kumar 	case FLASH_COMP_TYPE_FLS:
1154dcd183fSM Chetan Kumar 		rc = ipc_flash_send_fls(ipc_devlink, params->fw, mdm_rsp);
1164dcd183fSM Chetan Kumar 		break;
1174dcd183fSM Chetan Kumar 	default:
1184dcd183fSM Chetan Kumar 		devlink_flash_update_status_notify(devlink, "Invalid component",
119b8aa1654SM Chetan Kumar 						   NULL, 0, 0);
1204dcd183fSM Chetan Kumar 		break;
1214dcd183fSM Chetan Kumar 	}
1224dcd183fSM Chetan Kumar 
1234dcd183fSM Chetan Kumar 	if (!rc)
1244dcd183fSM Chetan Kumar 		devlink_flash_update_status_notify(devlink, "Flashing success",
125b8aa1654SM Chetan Kumar 						   header->image_type, 0, 0);
1264dcd183fSM Chetan Kumar 	else
1274dcd183fSM Chetan Kumar 		devlink_flash_update_status_notify(devlink, "Flashing failed",
128b8aa1654SM Chetan Kumar 						   header->image_type, 0, 0);
1294dcd183fSM Chetan Kumar 
1304dcd183fSM Chetan Kumar 	kfree(mdm_rsp);
1314dcd183fSM Chetan Kumar 	return rc;
1324dcd183fSM Chetan Kumar }
1334dcd183fSM Chetan Kumar 
1344dcd183fSM Chetan Kumar /* Call back function for devlink ops */
1354dcd183fSM Chetan Kumar static const struct devlink_ops devlink_flash_ops = {
1364dcd183fSM Chetan Kumar 	.flash_update = ipc_devlink_flash_update,
1374dcd183fSM Chetan Kumar };
1384dcd183fSM Chetan Kumar 
1398bea96efSM Chetan Kumar /**
1408bea96efSM Chetan Kumar  * ipc_devlink_send_cmd - Send command to Modem
1418bea96efSM Chetan Kumar  * @ipc_devlink: Pointer to struct iosm_devlink
1428bea96efSM Chetan Kumar  * @cmd:         Command to be sent to modem
1438bea96efSM Chetan Kumar  * @entry:       Command entry number
1448bea96efSM Chetan Kumar  *
1458bea96efSM Chetan Kumar  * Returns:      0 on success and failure value on error
1468bea96efSM Chetan Kumar  */
ipc_devlink_send_cmd(struct iosm_devlink * ipc_devlink,u16 cmd,u32 entry)1474dcd183fSM Chetan Kumar int ipc_devlink_send_cmd(struct iosm_devlink *ipc_devlink, u16 cmd, u32 entry)
1484dcd183fSM Chetan Kumar {
1494dcd183fSM Chetan Kumar 	struct iosm_rpsi_cmd rpsi_cmd;
1504dcd183fSM Chetan Kumar 
1514dcd183fSM Chetan Kumar 	rpsi_cmd.param.dword = cpu_to_le32(entry);
1524dcd183fSM Chetan Kumar 	rpsi_cmd.cmd = cpu_to_le16(cmd);
1534dcd183fSM Chetan Kumar 	rpsi_cmd.crc = rpsi_cmd.param.word[0] ^ rpsi_cmd.param.word[1] ^
1544dcd183fSM Chetan Kumar 		       rpsi_cmd.cmd;
1554dcd183fSM Chetan Kumar 
1564dcd183fSM Chetan Kumar 	return ipc_imem_sys_devlink_write(ipc_devlink, (u8 *)&rpsi_cmd,
1574dcd183fSM Chetan Kumar 					  sizeof(rpsi_cmd));
1584dcd183fSM Chetan Kumar }
1594dcd183fSM Chetan Kumar 
1608bea96efSM Chetan Kumar /* Function to create snapshot */
ipc_devlink_coredump_snapshot(struct devlink * dl,const struct devlink_region_ops * ops,struct netlink_ext_ack * extack,u8 ** data)1614dcd183fSM Chetan Kumar static int ipc_devlink_coredump_snapshot(struct devlink *dl,
1624dcd183fSM Chetan Kumar 					 const struct devlink_region_ops *ops,
1634dcd183fSM Chetan Kumar 					 struct netlink_ext_ack *extack,
1644dcd183fSM Chetan Kumar 					 u8 **data)
1654dcd183fSM Chetan Kumar {
1664dcd183fSM Chetan Kumar 	struct iosm_devlink *ipc_devlink = devlink_priv(dl);
1674dcd183fSM Chetan Kumar 	struct iosm_coredump_file_info *cd_list = ops->priv;
1684dcd183fSM Chetan Kumar 	u32 region_size;
1694dcd183fSM Chetan Kumar 	int rc;
1704dcd183fSM Chetan Kumar 
1714dcd183fSM Chetan Kumar 	dev_dbg(ipc_devlink->dev, "Region:%s, ID:%d", ops->name,
1724dcd183fSM Chetan Kumar 		cd_list->entry);
1734dcd183fSM Chetan Kumar 	region_size = cd_list->default_size;
1744dcd183fSM Chetan Kumar 	rc = ipc_coredump_collect(ipc_devlink, data, cd_list->entry,
1754dcd183fSM Chetan Kumar 				  region_size);
1764dcd183fSM Chetan Kumar 	if (rc) {
1774dcd183fSM Chetan Kumar 		dev_err(ipc_devlink->dev, "Fail to create snapshot,err %d", rc);
1784dcd183fSM Chetan Kumar 		goto coredump_collect_err;
1794dcd183fSM Chetan Kumar 	}
1804dcd183fSM Chetan Kumar 
1814dcd183fSM Chetan Kumar 	/* Send coredump end cmd indicating end of coredump collection */
1824dcd183fSM Chetan Kumar 	if (cd_list->entry == (IOSM_NOF_CD_REGION - 1))
1834dcd183fSM Chetan Kumar 		ipc_coredump_get_list(ipc_devlink, rpsi_cmd_coredump_end);
1844dcd183fSM Chetan Kumar 
1858bea96efSM Chetan Kumar 	return 0;
1868bea96efSM Chetan Kumar 
1874dcd183fSM Chetan Kumar coredump_collect_err:
1884dcd183fSM Chetan Kumar 	ipc_coredump_get_list(ipc_devlink, rpsi_cmd_coredump_end);
1894dcd183fSM Chetan Kumar 	return rc;
1904dcd183fSM Chetan Kumar }
1914dcd183fSM Chetan Kumar 
1924dcd183fSM Chetan Kumar /* To create regions for coredump files */
ipc_devlink_create_region(struct iosm_devlink * devlink)1934dcd183fSM Chetan Kumar static int ipc_devlink_create_region(struct iosm_devlink *devlink)
1944dcd183fSM Chetan Kumar {
1954dcd183fSM Chetan Kumar 	struct devlink_region_ops *mdm_coredump;
1964dcd183fSM Chetan Kumar 	int rc = 0;
1974dcd183fSM Chetan Kumar 	int i;
1984dcd183fSM Chetan Kumar 
1994dcd183fSM Chetan Kumar 	mdm_coredump = devlink->iosm_devlink_mdm_coredump;
2004dcd183fSM Chetan Kumar 	for (i = 0; i < IOSM_NOF_CD_REGION; i++) {
2014dcd183fSM Chetan Kumar 		mdm_coredump[i].name = list[i].filename;
2024dcd183fSM Chetan Kumar 		mdm_coredump[i].snapshot = ipc_devlink_coredump_snapshot;
2034dcd183fSM Chetan Kumar 		mdm_coredump[i].destructor = vfree;
2044dcd183fSM Chetan Kumar 		devlink->cd_regions[i] =
2054dcd183fSM Chetan Kumar 			devlink_region_create(devlink->devlink_ctx,
2064dcd183fSM Chetan Kumar 					      &mdm_coredump[i], MAX_SNAPSHOTS,
2074dcd183fSM Chetan Kumar 					      list[i].default_size);
2084dcd183fSM Chetan Kumar 
2094dcd183fSM Chetan Kumar 		if (IS_ERR(devlink->cd_regions[i])) {
2104dcd183fSM Chetan Kumar 			rc = PTR_ERR(devlink->cd_regions[i]);
2114dcd183fSM Chetan Kumar 			dev_err(devlink->dev, "Devlink region fail,err %d", rc);
2124dcd183fSM Chetan Kumar 			/* Delete previously created regions */
213*040d9384SAleksandr Mishin 			for (i--; i >= 0; i--)
2144dcd183fSM Chetan Kumar 				devlink_region_destroy(devlink->cd_regions[i]);
2154dcd183fSM Chetan Kumar 			goto region_create_fail;
2164dcd183fSM Chetan Kumar 		}
2174dcd183fSM Chetan Kumar 		list[i].entry = i;
2184dcd183fSM Chetan Kumar 		mdm_coredump[i].priv = list + i;
2194dcd183fSM Chetan Kumar 	}
2204dcd183fSM Chetan Kumar region_create_fail:
2214dcd183fSM Chetan Kumar 	return rc;
2224dcd183fSM Chetan Kumar }
2234dcd183fSM Chetan Kumar 
2244dcd183fSM Chetan Kumar /* To Destroy devlink regions */
ipc_devlink_destroy_region(struct iosm_devlink * ipc_devlink)2254dcd183fSM Chetan Kumar static void ipc_devlink_destroy_region(struct iosm_devlink *ipc_devlink)
2264dcd183fSM Chetan Kumar {
2274dcd183fSM Chetan Kumar 	u8 i;
2284dcd183fSM Chetan Kumar 
2294dcd183fSM Chetan Kumar 	for (i = 0; i < IOSM_NOF_CD_REGION; i++)
2304dcd183fSM Chetan Kumar 		devlink_region_destroy(ipc_devlink->cd_regions[i]);
2314dcd183fSM Chetan Kumar }
2324dcd183fSM Chetan Kumar 
2338bea96efSM Chetan Kumar /**
2348bea96efSM Chetan Kumar  * ipc_devlink_init - Initialize/register devlink to IOSM driver
2358bea96efSM Chetan Kumar  * @ipc_imem:   Pointer to struct iosm_imem
2368bea96efSM Chetan Kumar  *
2378bea96efSM Chetan Kumar  * Returns:     Pointer to iosm_devlink on success and NULL on failure
2388bea96efSM Chetan Kumar  */
ipc_devlink_init(struct iosm_imem * ipc_imem)2394dcd183fSM Chetan Kumar struct iosm_devlink *ipc_devlink_init(struct iosm_imem *ipc_imem)
2404dcd183fSM Chetan Kumar {
2414dcd183fSM Chetan Kumar 	struct ipc_chnl_cfg chnl_cfg_flash = { 0 };
2424dcd183fSM Chetan Kumar 	struct iosm_devlink *ipc_devlink;
2434dcd183fSM Chetan Kumar 	struct devlink *devlink_ctx;
2444dcd183fSM Chetan Kumar 	int rc;
2454dcd183fSM Chetan Kumar 
2464dcd183fSM Chetan Kumar 	devlink_ctx = devlink_alloc(&devlink_flash_ops,
2474dcd183fSM Chetan Kumar 				    sizeof(struct iosm_devlink),
2484dcd183fSM Chetan Kumar 				    ipc_imem->dev);
2494dcd183fSM Chetan Kumar 	if (!devlink_ctx) {
2504dcd183fSM Chetan Kumar 		dev_err(ipc_imem->dev, "devlink_alloc failed");
2514dcd183fSM Chetan Kumar 		goto devlink_alloc_fail;
2524dcd183fSM Chetan Kumar 	}
2534dcd183fSM Chetan Kumar 
2544dcd183fSM Chetan Kumar 	ipc_devlink = devlink_priv(devlink_ctx);
2554dcd183fSM Chetan Kumar 	ipc_devlink->devlink_ctx = devlink_ctx;
2564dcd183fSM Chetan Kumar 	ipc_devlink->pcie = ipc_imem->pcie;
2574dcd183fSM Chetan Kumar 	ipc_devlink->dev = ipc_imem->dev;
2584dcd183fSM Chetan Kumar 
2594dcd183fSM Chetan Kumar 	rc = devlink_params_register(devlink_ctx, iosm_devlink_params,
2604dcd183fSM Chetan Kumar 				     ARRAY_SIZE(iosm_devlink_params));
2614dcd183fSM Chetan Kumar 	if (rc) {
2624dcd183fSM Chetan Kumar 		dev_err(ipc_devlink->dev,
2634dcd183fSM Chetan Kumar 			"devlink_params_register failed. rc %d", rc);
2644dcd183fSM Chetan Kumar 		goto param_reg_fail;
2654dcd183fSM Chetan Kumar 	}
2664dcd183fSM Chetan Kumar 
2674dcd183fSM Chetan Kumar 	ipc_devlink->cd_file_info = list;
2684dcd183fSM Chetan Kumar 
2694dcd183fSM Chetan Kumar 	rc = ipc_devlink_create_region(ipc_devlink);
2704dcd183fSM Chetan Kumar 	if (rc) {
2714dcd183fSM Chetan Kumar 		dev_err(ipc_devlink->dev, "Devlink Region create failed, rc %d",
2724dcd183fSM Chetan Kumar 			rc);
2734dcd183fSM Chetan Kumar 		goto region_create_fail;
2744dcd183fSM Chetan Kumar 	}
2754dcd183fSM Chetan Kumar 
2764dcd183fSM Chetan Kumar 	if (ipc_chnl_cfg_get(&chnl_cfg_flash, IPC_MEM_CTRL_CHL_ID_7) < 0)
2774dcd183fSM Chetan Kumar 		goto chnl_get_fail;
2784dcd183fSM Chetan Kumar 
2794dcd183fSM Chetan Kumar 	ipc_imem_channel_init(ipc_imem, IPC_CTYPE_CTRL,
2804dcd183fSM Chetan Kumar 			      chnl_cfg_flash, IRQ_MOD_OFF);
2814dcd183fSM Chetan Kumar 
2824dcd183fSM Chetan Kumar 	init_completion(&ipc_devlink->devlink_sio.read_sem);
2834dcd183fSM Chetan Kumar 	skb_queue_head_init(&ipc_devlink->devlink_sio.rx_list);
2844dcd183fSM Chetan Kumar 
285504627eeSLeon Romanovsky 	devlink_register(devlink_ctx);
2864dcd183fSM Chetan Kumar 	dev_dbg(ipc_devlink->dev, "iosm devlink register success");
2874dcd183fSM Chetan Kumar 
2884dcd183fSM Chetan Kumar 	return ipc_devlink;
2894dcd183fSM Chetan Kumar 
2904dcd183fSM Chetan Kumar chnl_get_fail:
2914dcd183fSM Chetan Kumar 	ipc_devlink_destroy_region(ipc_devlink);
2924dcd183fSM Chetan Kumar region_create_fail:
2934dcd183fSM Chetan Kumar 	devlink_params_unregister(devlink_ctx, iosm_devlink_params,
2944dcd183fSM Chetan Kumar 				  ARRAY_SIZE(iosm_devlink_params));
2954dcd183fSM Chetan Kumar param_reg_fail:
2964dcd183fSM Chetan Kumar 	devlink_free(devlink_ctx);
2974dcd183fSM Chetan Kumar devlink_alloc_fail:
2984dcd183fSM Chetan Kumar 	return NULL;
2994dcd183fSM Chetan Kumar }
3004dcd183fSM Chetan Kumar 
3018bea96efSM Chetan Kumar /**
3028bea96efSM Chetan Kumar  * ipc_devlink_deinit - To unintialize the devlink from IOSM driver.
3038bea96efSM Chetan Kumar  * @ipc_devlink:        Devlink instance
3048bea96efSM Chetan Kumar  */
ipc_devlink_deinit(struct iosm_devlink * ipc_devlink)3054dcd183fSM Chetan Kumar void ipc_devlink_deinit(struct iosm_devlink *ipc_devlink)
3064dcd183fSM Chetan Kumar {
3074dcd183fSM Chetan Kumar 	struct devlink *devlink_ctx = ipc_devlink->devlink_ctx;
3084dcd183fSM Chetan Kumar 
309504627eeSLeon Romanovsky 	devlink_unregister(devlink_ctx);
3104dcd183fSM Chetan Kumar 	ipc_devlink_destroy_region(ipc_devlink);
3114dcd183fSM Chetan Kumar 	devlink_params_unregister(devlink_ctx, iosm_devlink_params,
3124dcd183fSM Chetan Kumar 				  ARRAY_SIZE(iosm_devlink_params));
3134dcd183fSM Chetan Kumar 	if (ipc_devlink->devlink_sio.devlink_read_pend) {
3144dcd183fSM Chetan Kumar 		complete(&ipc_devlink->devlink_sio.read_sem);
3154dcd183fSM Chetan Kumar 		complete(&ipc_devlink->devlink_sio.channel->ul_sem);
3164dcd183fSM Chetan Kumar 	}
3174dcd183fSM Chetan Kumar 	if (!ipc_devlink->devlink_sio.devlink_read_pend)
3184dcd183fSM Chetan Kumar 		skb_queue_purge(&ipc_devlink->devlink_sio.rx_list);
3194dcd183fSM Chetan Kumar 
3204dcd183fSM Chetan Kumar 	ipc_imem_sys_devlink_close(ipc_devlink);
3214dcd183fSM Chetan Kumar 	devlink_free(devlink_ctx);
3224dcd183fSM Chetan Kumar }
323