src/runtime_src/core/pcie/driver/linux/xocl/userpf/xocl_kds.c
/* Construct ERT config command and wait for completion */
Construct ERT config command and wait for completion
Construct ERT config command and wait for completion
static int xocl_cfg_cmd(struct xocl_dev *xdev, struct kds_client *client,
			struct ert_packet *pkg, struct drm_xocl_kds *cfg)
{
	struct kds_command *xcmd;
	struct ert_configure_cmd *ecmd = to_cfg_pkg(pkg);
	struct kds_sched *kds = &XDEV(xdev)->kds;
	int num_cu = kds_get_cu_total(kds);
	int regmap_size;
	u32 base_addr = 0xFFFFFFFF;
	int ret = 0;
	int i;
	if (!kds->ert)
		return 0;
	ecmd->state = ERT_CMD_STATE_NEW;
	ecmd->opcode = ERT_CONFIGURE;
	ecmd->type = ERT_CTRL;
	ecmd->count = 5 + num_cu;
	ecmd->num_cus	= num_cu;
	ecmd->cu_shift	= 16;
	ecmd->ert	= cfg->ert;
	ecmd->polling	= cfg->polling;
	ecmd->cu_dma	= cfg->cu_dma;
	ecmd->cu_isr	= cfg->cu_isr;
	ecmd->cq_int	= cfg->cq_int;
	ecmd->dataflow	= cfg->dataflow;
	ecmd->rw_shared	= cfg->rw_shared;
	kds->cu_mgmt.rw_shared = cfg->rw_shared;
	ecmd->slot_size = MAX_CONFIG_PACKET_SIZE;
	regmap_size = kds_get_max_regmap_size(kds);
	if (ecmd->slot_size < regmap_size + MAX_HEADER_SIZE)
		ecmd->slot_size = regmap_size + MAX_HEADER_SIZE;
	for (i = 0; i < num_cu; i++) {
		u32 cu_addr;
		u32 proto;
		cu_addr = kds_get_cu_addr(kds, i);
		if (base_addr > cu_addr)
			base_addr = cu_addr;
		proto = kds_get_cu_proto(kds, i);
		cu_addr |= proto;
		ecmd->data[i] = cu_addr;
	}
	ecmd->cu_base_addr = base_addr;
	xcmd = kds_alloc_command(client, ecmd->count * sizeof(u32));
	if (!xcmd) {
		userpf_err(xdev, "Failed to alloc xcmd\n");
		ret = -ENOMEM;
		goto out;
	}
	xcmd->cb.free = kds_free_command;
	print_ecmd_info(ecmd);
	xcmd->type = KDS_ERT;
	cfg_ecmd2xcmd(ecmd, xcmd);
	xcmd->cb.notify_host = xocl_cfg_notify;
	xcmd->priv = kds;
	ret = kds_submit_cmd_and_wait(kds, xcmd);
	if (ret)
		goto out;
	if (ecmd->state > ERT_CMD_STATE_COMPLETED) {
		userpf_err(xdev, "Cfg command state %d", ecmd->state);
		ret = -EINVAL;
		goto out;
	}
	WARN_ON(ecmd->state != ERT_CMD_STATE_COMPLETED);
	if (!kds->ini_disable)
		kds->ert_disable = cfg->ert ? false : true;
	userpf_info(xdev, "Cfg command completed");
out:
	return ret;
}
static int xocl_cfg_cmd ( struct xocl_dev * xdev , struct kds_client * client , struct ert_packet * pkg , struct drm_xocl_kds * cfg ) { struct kds_command * xcmd ; struct ert_configure_cmd * ecmd = to_cfg_pkg ( pkg ) ; struct kds_sched * kds = & XDEV ( xdev ) -> kds ; int num_cu = kds_get_cu_total ( kds ) ; int regmap_size ; u32 base_addr = 0xFFFFFFFF ; int ret = 0 ; int i ; if ( ! kds -> ert ) return 0 ; ecmd -> state = ERT_CMD_STATE_NEW ; ecmd -> opcode = ERT_CONFIGURE ; ecmd -> type = ERT_CTRL ; ecmd -> count = 5 + num_cu ; ecmd -> num_cus = num_cu ; ecmd -> cu_shift = 16 ; ecmd -> ert = cfg -> ert ; ecmd -> polling = cfg -> polling ; ecmd -> cu_dma = cfg -> cu_dma ; ecmd -> cu_isr = cfg -> cu_isr ; ecmd -> cq_int = cfg -> cq_int ; ecmd -> dataflow = cfg -> dataflow ; ecmd -> rw_shared = cfg -> rw_shared ; kds -> cu_mgmt . rw_shared = cfg -> rw_shared ; ecmd -> slot_size = MAX_CONFIG_PACKET_SIZE ; regmap_size = kds_get_max_regmap_size ( kds ) ; if ( ecmd -> slot_size < regmap_size + MAX_HEADER_SIZE ) ecmd -> slot_size = regmap_size + MAX_HEADER_SIZE ; for ( i = 0 ; i < num_cu ; i ++ ) { u32 cu_addr ; u32 proto ; cu_addr = kds_get_cu_addr ( kds , i ) ; if ( base_addr > cu_addr ) base_addr = cu_addr ; proto = kds_get_cu_proto ( kds , i ) ; cu_addr |= proto ; ecmd -> data [ i ] = cu_addr ; } ecmd -> cu_base_addr = base_addr ; xcmd = kds_alloc_command ( client , ecmd -> count * sizeof ( u32 ) ) ; if ( ! xcmd ) { userpf_err ( xdev , " \n " ) ; ret = - ENOMEM ; goto out ; } xcmd -> cb . free = kds_free_command ; print_ecmd_info ( ecmd ) ; xcmd -> type = KDS_ERT ; cfg_ecmd2xcmd ( ecmd , xcmd ) ; xcmd -> cb . notify_host = xocl_cfg_notify ; xcmd -> priv = kds ; ret = kds_submit_cmd_and_wait ( kds , xcmd ) ; if ( ret ) goto out ; if ( ecmd -> state > ERT_CMD_STATE_COMPLETED ) { userpf_err ( xdev , " " , ecmd -> state ) ; ret = - EINVAL ; goto out ; } WARN_ON ( ecmd -> state != ERT_CMD_STATE_COMPLETED ) ; if ( ! kds -> ini_disable ) kds -> ert_disable = cfg -> ert ? false : true ; userpf_info ( xdev , " " ) ; out : return ret ; }
Construct ERT config command and wait for completion
Construct ERT config command and wait for completion
/* Don't send config command if ERT doesn't present */ /* Fill header */ /* cfg->slot_size is for debug purpose */ /* ecmd->slot_size	= cfg->slot_size; */ /* Fill CU address */ /* encode handshaking control in lower unused address bits [2-0] */ /* If xrt.ini is not disabled, let it determines ERT enable/disable */