src/runtime_src/core/pcie/driver/linux/xocl/userpf/xocl_kds.c
/* Construct PS kernel config command and wait for completion */
Construct PS kernel config command and wait for completion
Construct PS kernel config command and wait for completion
static int xocl_scu_cfg_cmd(struct xocl_dev *xdev, struct kds_client *client,
			    struct ert_packet *pkg)
{
	struct kds_command *xcmd;
	struct ert_configure_sk_cmd *ecmd = to_cfg_sk_pkg(pkg);
	struct kds_sched *kds = &XDEV(xdev)->kds;
	struct ps_kernel_node *ps_kernel = NULL;
	struct config_sk_image *image;
	struct ps_kernel_data *scu_data;
	u32 start_cuidx = 0;
	u32 img_idx = 0;
	int ret = 0;
	int i;
	XOCL_GET_PS_KERNEL(xdev, ps_kernel);
	if (!ps_kernel)
		goto out;
	ecmd->header = 0;
	ecmd->state = ERT_CMD_STATE_NEW;
	ecmd->opcode = ERT_SK_CONFIG;
	ecmd->type = ERT_CTRL;
	ecmd->num_image = ps_kernel->pkn_count;
	ecmd->count = 1 + ecmd->num_image * sizeof(*image) / 4;
	for (i = 0; i < ecmd->num_image; i++) {
		image = &ecmd->image[img_idx];
		scu_data = &ps_kernel->pkn_data[img_idx];
		image->start_cuidx = start_cuidx;
		image->num_cus = scu_data->pkd_num_instances;
		strncpy((char *)image->sk_name, scu_data->pkd_sym_name,
			PS_KERNEL_NAME_LENGTH - 1);
		((char *)image->sk_name)[PS_KERNEL_NAME_LENGTH - 1] = 0;
		start_cuidx += image->num_cus;
		img_idx++;
	}
	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;
	ret = sk_ecmd2xcmd(xdev, (struct ert_packet *)ecmd, xcmd);
	if (ret) {
		xcmd->cb.free(xcmd);
		goto out;
	}
	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, "PS kernel cfg command state %d", ecmd->state);
		ret = -EINVAL;
	} else
		userpf_info(xdev, "PS kernel cfg command completed");
out:
	XOCL_PUT_PS_KERNEL(xdev);
	return ret;
}
static int xocl_scu_cfg_cmd ( struct xocl_dev * xdev , struct kds_client * client , struct ert_packet * pkg ) { struct kds_command * xcmd ; struct ert_configure_sk_cmd * ecmd = to_cfg_sk_pkg ( pkg ) ; struct kds_sched * kds = & XDEV ( xdev ) -> kds ; struct ps_kernel_node * ps_kernel = NULL ; struct config_sk_image * image ; struct ps_kernel_data * scu_data ; u32 start_cuidx = 0 ; u32 img_idx = 0 ; int ret = 0 ; int i ; XOCL_GET_PS_KERNEL ( xdev , ps_kernel ) ; if ( ! ps_kernel ) goto out ; ecmd -> header = 0 ; ecmd -> state = ERT_CMD_STATE_NEW ; ecmd -> opcode = ERT_SK_CONFIG ; ecmd -> type = ERT_CTRL ; ecmd -> num_image = ps_kernel -> pkn_count ; ecmd -> count = 1 + ecmd -> num_image * sizeof ( * image ) / 4 ; for ( i = 0 ; i < ecmd -> num_image ; i ++ ) { image = & ecmd -> image [ img_idx ] ; scu_data = & ps_kernel -> pkn_data [ img_idx ] ; image -> start_cuidx = start_cuidx ; image -> num_cus = scu_data -> pkd_num_instances ; strncpy ( ( char * ) image -> sk_name , scu_data -> pkd_sym_name , PS_KERNEL_NAME_LENGTH - 1 ) ; ( ( char * ) image -> sk_name ) [ PS_KERNEL_NAME_LENGTH - 1 ] = 0 ; start_cuidx += image -> num_cus ; img_idx ++ ; } 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 ; ret = sk_ecmd2xcmd ( xdev , ( struct ert_packet * ) ecmd , xcmd ) ; if ( ret ) { xcmd -> cb . free ( xcmd ) ; goto out ; } 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 ; } else userpf_info ( xdev , " " ) ; out : XOCL_PUT_PS_KERNEL ( xdev ) ; return ret ; }
Construct PS kernel config command and wait for completion
Construct PS kernel config command and wait for completion
/* Clear header */ /* Fill PS kernel config command */