Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright 2013-2016 Freescale Semiconductor Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright 2020 NXP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/fsl/mc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include "fsl-mc-private.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  * cache the DPRC version to reduce the number of commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * towards the mc firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) static u16 dprc_major_ver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) static u16 dprc_minor_ver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  * dprc_open() - Open DPRC object for use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  * @mc_io:	Pointer to MC portal's I/O object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  * @container_id: Container ID to open
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * @token:	Returned token of DPRC object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  * Return:	'0' on Success; Error code otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  * @warning	Required before any operation on the object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) int dprc_open(struct fsl_mc_io *mc_io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	      u32 cmd_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	      int container_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	      u16 *token)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	struct fsl_mc_command cmd = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	struct dprc_cmd_open *cmd_params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	/* prepare command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	cmd.header = mc_encode_cmd_header(DPRC_CMDID_OPEN, cmd_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 					  0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	cmd_params = (struct dprc_cmd_open *)cmd.params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	cmd_params->container_id = cpu_to_le32(container_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	/* send command to mc*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	err = mc_send_command(mc_io, &cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	/* retrieve response parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	*token = mc_cmd_hdr_read_token(&cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) EXPORT_SYMBOL_GPL(dprc_open);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  * dprc_close() - Close the control session of the object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  * @mc_io:	Pointer to MC portal's I/O object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  * @token:	Token of DPRC object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)  * After this function is called, no further operations are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)  * allowed on the object without opening a new control session.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  * Return:	'0' on Success; Error code otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) int dprc_close(struct fsl_mc_io *mc_io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	       u32 cmd_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	       u16 token)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	struct fsl_mc_command cmd = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	/* prepare command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	cmd.header = mc_encode_cmd_header(DPRC_CMDID_CLOSE, cmd_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 					  token);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	/* send command to mc*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	return mc_send_command(mc_io, &cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) EXPORT_SYMBOL_GPL(dprc_close);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84)  * dprc_reset_container - Reset child container.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85)  * @mc_io:	Pointer to MC portal's I/O object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86)  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87)  * @token:	Token of DPRC object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88)  * @child_container_id:	ID of the container to reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89)  * @options: 32 bit options:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90)  *   - 0 (no bits set) - all the objects inside the container are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91)  *     reset. The child containers are entered recursively and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92)  *     objects reset. All the objects (including the child containers)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93)  *     are closed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94)  *   - bit 0 set - all the objects inside the container are reset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95)  *     However the child containers are not entered recursively.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96)  *     This option is supported for API versions >= 6.5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97)  * In case a software context crashes or becomes non-responsive, the parent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98)  * may wish to reset its resources container before the software context is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99)  * restarted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)  * This routine informs all objects assigned to the child container that the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)  * container is being reset, so they may perform any cleanup operations that are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)  * needed. All objects handles that were owned by the child container shall be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)  * closed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)  * Note that such request may be submitted even if the child software context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)  * has not crashed, but the resulting object cleanup operations will not be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)  * aware of that.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)  * Return:	'0' on Success; Error code otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) int dprc_reset_container(struct fsl_mc_io *mc_io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 			 u32 cmd_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 			 u16 token,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 			 int child_container_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 			 u32 options)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	struct fsl_mc_command cmd = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	struct dprc_cmd_reset_container *cmd_params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	u32 cmdid = DPRC_CMDID_RESET_CONT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	 * If the DPRC object version was not yet cached, cache it now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	 * Otherwise use the already cached value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	if (!dprc_major_ver && !dprc_minor_ver) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		err = dprc_get_api_version(mc_io, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 				&dprc_major_ver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 				&dprc_minor_ver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	 * MC API 6.5 introduced a new field in the command used to pass
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	 * some flags.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	 * Bit 0 indicates that the child containers are not recursively reset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	if (dprc_major_ver > 6 || (dprc_major_ver == 6 && dprc_minor_ver >= 5))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		cmdid = DPRC_CMDID_RESET_CONT_V2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	/* prepare command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	cmd.header = mc_encode_cmd_header(cmdid, cmd_flags, token);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	cmd_params = (struct dprc_cmd_reset_container *)cmd.params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	cmd_params->child_container_id = cpu_to_le32(child_container_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	cmd_params->options = cpu_to_le32(options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	/* send command to mc*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	return mc_send_command(mc_io, &cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) EXPORT_SYMBOL_GPL(dprc_reset_container);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)  * dprc_set_irq() - Set IRQ information for the DPRC to trigger an interrupt.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)  * @mc_io:	Pointer to MC portal's I/O object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)  * @token:	Token of DPRC object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)  * @irq_index:	Identifies the interrupt index to configure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)  * @irq_cfg:	IRQ configuration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)  * Return:	'0' on Success; Error code otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) int dprc_set_irq(struct fsl_mc_io *mc_io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		 u32 cmd_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		 u16 token,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		 u8 irq_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		 struct dprc_irq_cfg *irq_cfg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	struct fsl_mc_command cmd = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	struct dprc_cmd_set_irq *cmd_params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	/* prepare command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_IRQ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 					  cmd_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 					  token);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	cmd_params = (struct dprc_cmd_set_irq *)cmd.params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	cmd_params->irq_val = cpu_to_le32(irq_cfg->val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	cmd_params->irq_index = irq_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	cmd_params->irq_addr = cpu_to_le64(irq_cfg->paddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	cmd_params->irq_num = cpu_to_le32(irq_cfg->irq_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	/* send command to mc*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	return mc_send_command(mc_io, &cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)  * dprc_set_irq_enable() - Set overall interrupt state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)  * @mc_io:	Pointer to MC portal's I/O object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)  * @token:	Token of DPRC object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)  * @irq_index:	The interrupt index to configure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)  * @en:		Interrupt state - enable = 1, disable = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)  * Allows GPP software to control when interrupts are generated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)  * Each interrupt can have up to 32 causes.  The enable/disable control's the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)  * overall interrupt state. if the interrupt is disabled no causes will cause
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)  * an interrupt.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)  * Return:	'0' on Success; Error code otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) int dprc_set_irq_enable(struct fsl_mc_io *mc_io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 			u32 cmd_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 			u16 token,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 			u8 irq_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 			u8 en)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	struct fsl_mc_command cmd = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	struct dprc_cmd_set_irq_enable *cmd_params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	/* prepare command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_IRQ_ENABLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 					  cmd_flags, token);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	cmd_params = (struct dprc_cmd_set_irq_enable *)cmd.params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	cmd_params->enable = en & DPRC_ENABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	cmd_params->irq_index = irq_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	/* send command to mc*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	return mc_send_command(mc_io, &cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)  * dprc_set_irq_mask() - Set interrupt mask.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)  * @mc_io:	Pointer to MC portal's I/O object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)  * @token:	Token of DPRC object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)  * @irq_index:	The interrupt index to configure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)  * @mask:	event mask to trigger interrupt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)  *			each bit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)  *				0 = ignore event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)  *				1 = consider event for asserting irq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)  * Every interrupt can have up to 32 causes and the interrupt model supports
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)  * masking/unmasking each cause independently
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)  * Return:	'0' on Success; Error code otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) int dprc_set_irq_mask(struct fsl_mc_io *mc_io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		      u32 cmd_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		      u16 token,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		      u8 irq_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		      u32 mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	struct fsl_mc_command cmd = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	struct dprc_cmd_set_irq_mask *cmd_params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	/* prepare command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_IRQ_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 					  cmd_flags, token);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	cmd_params = (struct dprc_cmd_set_irq_mask *)cmd.params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	cmd_params->mask = cpu_to_le32(mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	cmd_params->irq_index = irq_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	/* send command to mc*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	return mc_send_command(mc_io, &cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)  * dprc_get_irq_status() - Get the current status of any pending interrupts.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)  * @mc_io:	Pointer to MC portal's I/O object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)  * @token:	Token of DPRC object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)  * @irq_index:	The interrupt index to configure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)  * @status:	Returned interrupts status - one bit per cause:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)  *			0 = no interrupt pending
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)  *			1 = interrupt pending
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)  * Return:	'0' on Success; Error code otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) int dprc_get_irq_status(struct fsl_mc_io *mc_io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 			u32 cmd_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 			u16 token,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 			u8 irq_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 			u32 *status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	struct fsl_mc_command cmd = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	struct dprc_cmd_get_irq_status *cmd_params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	struct dprc_rsp_get_irq_status *rsp_params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	/* prepare command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_IRQ_STATUS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 					  cmd_flags, token);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	cmd_params = (struct dprc_cmd_get_irq_status *)cmd.params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	cmd_params->status = cpu_to_le32(*status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	cmd_params->irq_index = irq_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	/* send command to mc*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	err = mc_send_command(mc_io, &cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	/* retrieve response parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	rsp_params = (struct dprc_rsp_get_irq_status *)cmd.params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	*status = le32_to_cpu(rsp_params->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)  * dprc_clear_irq_status() - Clear a pending interrupt's status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)  * @mc_io:	Pointer to MC portal's I/O object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)  * @token:	Token of DPRC object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)  * @irq_index:	The interrupt index to configure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)  * @status:	bits to clear (W1C) - one bit per cause:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)  *					0 = don't change
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)  *					1 = clear status bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)  * Return:	'0' on Success; Error code otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) int dprc_clear_irq_status(struct fsl_mc_io *mc_io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 			  u32 cmd_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 			  u16 token,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 			  u8 irq_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 			  u32 status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	struct fsl_mc_command cmd = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	struct dprc_cmd_clear_irq_status *cmd_params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	/* prepare command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	cmd.header = mc_encode_cmd_header(DPRC_CMDID_CLEAR_IRQ_STATUS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 					  cmd_flags, token);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	cmd_params = (struct dprc_cmd_clear_irq_status *)cmd.params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	cmd_params->status = cpu_to_le32(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	cmd_params->irq_index = irq_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	/* send command to mc*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	return mc_send_command(mc_io, &cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)  * dprc_get_attributes() - Obtains container attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)  * @mc_io:	Pointer to MC portal's I/O object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)  * @token:	Token of DPRC object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)  * @attributes	Returned container attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)  * Return:     '0' on Success; Error code otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) int dprc_get_attributes(struct fsl_mc_io *mc_io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 			u32 cmd_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 			u16 token,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 			struct dprc_attributes *attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	struct fsl_mc_command cmd = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	struct dprc_rsp_get_attributes *rsp_params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	/* prepare command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_ATTR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 					  cmd_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 					  token);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	/* send command to mc*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	err = mc_send_command(mc_io, &cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	/* retrieve response parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	rsp_params = (struct dprc_rsp_get_attributes *)cmd.params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	attr->container_id = le32_to_cpu(rsp_params->container_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	attr->icid = le32_to_cpu(rsp_params->icid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	attr->options = le32_to_cpu(rsp_params->options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	attr->portal_id = le32_to_cpu(rsp_params->portal_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)  * dprc_get_obj_count() - Obtains the number of objects in the DPRC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)  * @mc_io:	Pointer to MC portal's I/O object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)  * @token:	Token of DPRC object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)  * @obj_count:	Number of objects assigned to the DPRC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)  * Return:	'0' on Success; Error code otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) int dprc_get_obj_count(struct fsl_mc_io *mc_io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 		       u32 cmd_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 		       u16 token,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 		       int *obj_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	struct fsl_mc_command cmd = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	struct dprc_rsp_get_obj_count *rsp_params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	/* prepare command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_COUNT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 					  cmd_flags, token);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	/* send command to mc*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	err = mc_send_command(mc_io, &cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	/* retrieve response parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	rsp_params = (struct dprc_rsp_get_obj_count *)cmd.params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	*obj_count = le32_to_cpu(rsp_params->obj_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) EXPORT_SYMBOL_GPL(dprc_get_obj_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)  * dprc_get_obj() - Get general information on an object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)  * @mc_io:	Pointer to MC portal's I/O object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)  * @token:	Token of DPRC object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)  * @obj_index:	Index of the object to be queried (< obj_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)  * @obj_desc:	Returns the requested object descriptor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)  * The object descriptors are retrieved one by one by incrementing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414)  * obj_index up to (not including) the value of obj_count returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)  * from dprc_get_obj_count(). dprc_get_obj_count() must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)  * be called prior to dprc_get_obj().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)  * Return:	'0' on Success; Error code otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) int dprc_get_obj(struct fsl_mc_io *mc_io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 		 u32 cmd_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 		 u16 token,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 		 int obj_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		 struct fsl_mc_obj_desc *obj_desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	struct fsl_mc_command cmd = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	struct dprc_cmd_get_obj *cmd_params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	struct dprc_rsp_get_obj *rsp_params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	/* prepare command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 					  cmd_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 					  token);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	cmd_params = (struct dprc_cmd_get_obj *)cmd.params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	cmd_params->obj_index = cpu_to_le32(obj_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	/* send command to mc*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	err = mc_send_command(mc_io, &cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	/* retrieve response parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	rsp_params = (struct dprc_rsp_get_obj *)cmd.params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	obj_desc->id = le32_to_cpu(rsp_params->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	obj_desc->vendor = le16_to_cpu(rsp_params->vendor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	obj_desc->irq_count = rsp_params->irq_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	obj_desc->region_count = rsp_params->region_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	obj_desc->state = le32_to_cpu(rsp_params->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	obj_desc->ver_major = le16_to_cpu(rsp_params->version_major);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	obj_desc->ver_minor = le16_to_cpu(rsp_params->version_minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	obj_desc->flags = le16_to_cpu(rsp_params->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	strncpy(obj_desc->type, rsp_params->type, 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	obj_desc->type[15] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	strncpy(obj_desc->label, rsp_params->label, 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	obj_desc->label[15] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) EXPORT_SYMBOL_GPL(dprc_get_obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)  * dprc_set_obj_irq() - Set IRQ information for object to trigger an interrupt.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)  * @mc_io:	Pointer to MC portal's I/O object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465)  * @token:	Token of DPRC object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)  * @obj_type:	Type of the object to set its IRQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467)  * @obj_id:	ID of the object to set its IRQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)  * @irq_index:	The interrupt index to configure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469)  * @irq_cfg:	IRQ configuration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)  * Return:	'0' on Success; Error code otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) int dprc_set_obj_irq(struct fsl_mc_io *mc_io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 		     u32 cmd_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 		     u16 token,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 		     char *obj_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 		     int obj_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 		     u8 irq_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 		     struct dprc_irq_cfg *irq_cfg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	struct fsl_mc_command cmd = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	struct dprc_cmd_set_obj_irq *cmd_params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	/* prepare command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_OBJ_IRQ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 					  cmd_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 					  token);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	cmd_params = (struct dprc_cmd_set_obj_irq *)cmd.params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 	cmd_params->irq_val = cpu_to_le32(irq_cfg->val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	cmd_params->irq_index = irq_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	cmd_params->irq_addr = cpu_to_le64(irq_cfg->paddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	cmd_params->irq_num = cpu_to_le32(irq_cfg->irq_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	cmd_params->obj_id = cpu_to_le32(obj_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	strncpy(cmd_params->obj_type, obj_type, 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 	cmd_params->obj_type[15] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 	/* send command to mc*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 	return mc_send_command(mc_io, &cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) EXPORT_SYMBOL_GPL(dprc_set_obj_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)  * dprc_get_obj_region() - Get region information for a specified object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504)  * @mc_io:	Pointer to MC portal's I/O object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505)  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)  * @token:	Token of DPRC object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507)  * @obj_type;	Object type as returned in dprc_get_obj()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508)  * @obj_id:	Unique object instance as returned in dprc_get_obj()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509)  * @region_index: The specific region to query
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510)  * @region_desc:  Returns the requested region descriptor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512)  * Return:	'0' on Success; Error code otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) int dprc_get_obj_region(struct fsl_mc_io *mc_io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 			u32 cmd_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 			u16 token,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 			char *obj_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 			int obj_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 			u8 region_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 			struct dprc_region_desc *region_desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	struct fsl_mc_command cmd = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 	struct dprc_cmd_get_obj_region *cmd_params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	struct dprc_rsp_get_obj_region *rsp_params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)     /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528)      * If the DPRC object version was not yet cached, cache it now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529)      * Otherwise use the already cached value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530)      */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 	if (!dprc_major_ver && !dprc_minor_ver) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 		err = dprc_get_api_version(mc_io, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 				      &dprc_major_ver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 				      &dprc_minor_ver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 	if (dprc_major_ver > 6 || (dprc_major_ver == 6 && dprc_minor_ver >= 6)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 		 * MC API version 6.6 changed the size of the MC portals and software
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 		 * portals to 64K (as implemented by hardware). If older API is in use the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 		 * size reported is less (64 bytes for mc portals and 4K for software
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 		 * portals).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 		cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_REG_V3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 						  cmd_flags, token);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 	} else if (dprc_major_ver == 6 && dprc_minor_ver >= 3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 		 * MC API version 6.3 introduced a new field to the region
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 		 * descriptor: base_address. If the older API is in use then the base
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 		 * address is set to zero to indicate it needs to be obtained elsewhere
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 		 * (typically the device tree).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 		cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_REG_V2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 						  cmd_flags, token);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 		cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_REG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 						  cmd_flags, token);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 	cmd_params = (struct dprc_cmd_get_obj_region *)cmd.params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 	cmd_params->obj_id = cpu_to_le32(obj_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 	cmd_params->region_index = region_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 	strncpy(cmd_params->obj_type, obj_type, 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 	cmd_params->obj_type[15] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 	/* send command to mc*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 	err = mc_send_command(mc_io, &cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 	/* retrieve response parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 	rsp_params = (struct dprc_rsp_get_obj_region *)cmd.params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 	region_desc->base_offset = le64_to_cpu(rsp_params->base_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 	region_desc->size = le32_to_cpu(rsp_params->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 	if (dprc_major_ver > 6 || (dprc_major_ver == 6 && dprc_minor_ver >= 3))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 		region_desc->base_address = le64_to_cpu(rsp_params->base_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 		region_desc->base_address = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) EXPORT_SYMBOL_GPL(dprc_get_obj_region);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589)  * dprc_get_api_version - Get Data Path Resource Container API version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590)  * @mc_io:	Pointer to Mc portal's I/O object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591)  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592)  * @major_ver:	Major version of Data Path Resource Container API
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593)  * @minor_ver:	Minor version of Data Path Resource Container API
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)  * Return:	'0' on Success; Error code otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) int dprc_get_api_version(struct fsl_mc_io *mc_io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 			 u32 cmd_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 			 u16 *major_ver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 			 u16 *minor_ver)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 	struct fsl_mc_command cmd = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 	/* prepare command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 	cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_API_VERSION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 					  cmd_flags, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 	/* send command to mc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 	err = mc_send_command(mc_io, &cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 	/* retrieve response parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 	mc_cmd_read_api_version(&cmd, major_ver, minor_ver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621)  * dprc_get_container_id - Get container ID associated with a given portal.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622)  * @mc_io:		Pointer to Mc portal's I/O object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623)  * @cmd_flags:		Command flags; one or more of 'MC_CMD_FLAG_'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624)  * @container_id:	Requested container id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626)  * Return:	'0' on Success; Error code otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) int dprc_get_container_id(struct fsl_mc_io *mc_io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 			  u32 cmd_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 			  int *container_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 	struct fsl_mc_command cmd = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 	/* prepare command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 	cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_CONT_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 					  cmd_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 					  0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 	/* send command to mc*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 	err = mc_send_command(mc_io, &cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 	/* retrieve response parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 	*container_id = (int)mc_cmd_read_object_id(&cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652)  * dprc_get_connection() - Get connected endpoint and link status if connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653)  *			exists.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654)  * @mc_io:	Pointer to MC portal's I/O object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655)  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656)  * @token:	Token of DPRC object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657)  * @endpoint1:	Endpoint 1 configuration parameters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658)  * @endpoint2:	Returned endpoint 2 configuration parameters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659)  * @state:	Returned link state:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660)  *		1 - link is up;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661)  *		0 - link is down;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662)  *		-1 - no connection (endpoint2 information is irrelevant)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664)  * Return:     '0' on Success; -ENOTCONN if connection does not exist.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) int dprc_get_connection(struct fsl_mc_io *mc_io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 			u32 cmd_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 			u16 token,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 			const struct dprc_endpoint *endpoint1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 			struct dprc_endpoint *endpoint2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 			int *state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 	struct dprc_cmd_get_connection *cmd_params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 	struct dprc_rsp_get_connection *rsp_params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 	struct fsl_mc_command cmd = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 	int err, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 	/* prepare command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 	cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_CONNECTION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 					  cmd_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 					  token);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 	cmd_params = (struct dprc_cmd_get_connection *)cmd.params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 	cmd_params->ep1_id = cpu_to_le32(endpoint1->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 	cmd_params->ep1_interface_id = cpu_to_le16(endpoint1->if_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 	for (i = 0; i < 16; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 		cmd_params->ep1_type[i] = endpoint1->type[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 	/* send command to mc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 	err = mc_send_command(mc_io, &cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 		return -ENOTCONN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 	/* retrieve response parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 	rsp_params = (struct dprc_rsp_get_connection *)cmd.params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 	endpoint2->id = le32_to_cpu(rsp_params->ep2_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 	endpoint2->if_id = le16_to_cpu(rsp_params->ep2_interface_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 	*state = le32_to_cpu(rsp_params->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 	for (i = 0; i < 16; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 		endpoint2->type[i] = rsp_params->ep2_type[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) }