• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Freescale Layerscape MC I/O wrapper
4  *
5  * Copyright 2013-2016 Freescale Semiconductor, Inc.
6  * Copyright 2017 NXP
7  */
8 #include <fsl-mc/fsl_mc_sys.h>
9 #include <fsl-mc/fsl_mc_cmd.h>
10 #include <fsl-mc/fsl_dpbp.h>
11 
dpbp_open(struct fsl_mc_io * mc_io,uint32_t cmd_flags,int dpbp_id,uint16_t * token)12 int dpbp_open(struct fsl_mc_io *mc_io,
13 	      uint32_t cmd_flags,
14 	      int dpbp_id,
15 	      uint16_t *token)
16 {
17 	struct mc_command cmd = { 0 };
18 	int err;
19 
20 	/* prepare command */
21 	cmd.header = mc_encode_cmd_header(DPBP_CMDID_OPEN,
22 					  cmd_flags,
23 					  0);
24 	DPBP_CMD_OPEN(cmd, dpbp_id);
25 
26 	/* send command to mc*/
27 	err = mc_send_command(mc_io, &cmd);
28 	if (err)
29 		return err;
30 
31 	/* retrieve response parameters */
32 	*token = MC_CMD_HDR_READ_TOKEN(cmd.header);
33 
34 	return err;
35 }
36 
dpbp_close(struct fsl_mc_io * mc_io,uint32_t cmd_flags,uint16_t token)37 int dpbp_close(struct fsl_mc_io *mc_io,
38 	       uint32_t cmd_flags,
39 	       uint16_t token)
40 {
41 	struct mc_command cmd = { 0 };
42 
43 	/* prepare command */
44 	cmd.header = mc_encode_cmd_header(DPBP_CMDID_CLOSE, cmd_flags,
45 					  token);
46 
47 	/* send command to mc*/
48 	return mc_send_command(mc_io, &cmd);
49 }
50 
dpbp_create(struct fsl_mc_io * mc_io,uint16_t dprc_token,uint32_t cmd_flags,const struct dpbp_cfg * cfg,uint32_t * obj_id)51 int dpbp_create(struct fsl_mc_io *mc_io,
52 		uint16_t dprc_token,
53 		uint32_t cmd_flags,
54 		const struct dpbp_cfg *cfg,
55 		uint32_t *obj_id)
56 {
57 	struct mc_command cmd = { 0 };
58 	int err;
59 
60 	(void)(cfg); /* unused */
61 
62 	/* prepare command */
63 	cmd.header = mc_encode_cmd_header(DPBP_CMDID_CREATE,
64 					  cmd_flags,
65 					  dprc_token);
66 
67 	/* send command to mc*/
68 	err = mc_send_command(mc_io, &cmd);
69 	if (err)
70 		return err;
71 
72 	/* retrieve response parameters */
73 	MC_CMD_READ_OBJ_ID(cmd, *obj_id);
74 
75 	return 0;
76 }
77 
dpbp_destroy(struct fsl_mc_io * mc_io,uint16_t dprc_token,uint32_t cmd_flags,uint32_t obj_id)78 int dpbp_destroy(struct fsl_mc_io *mc_io,
79 		 uint16_t dprc_token,
80 		 uint32_t cmd_flags,
81 		 uint32_t obj_id)
82 {
83 	struct mc_command cmd = { 0 };
84 
85 	/* prepare command */
86 	cmd.header = mc_encode_cmd_header(DPBP_CMDID_DESTROY,
87 					  cmd_flags,
88 					  dprc_token);
89 
90 	/* set object id to destroy */
91 	CMD_DESTROY_SET_OBJ_ID_PARAM0(cmd, obj_id);
92 
93 	/* send command to mc*/
94 	return mc_send_command(mc_io, &cmd);
95 }
96 
dpbp_enable(struct fsl_mc_io * mc_io,uint32_t cmd_flags,uint16_t token)97 int dpbp_enable(struct fsl_mc_io *mc_io,
98 		uint32_t cmd_flags,
99 		uint16_t token)
100 {
101 	struct mc_command cmd = { 0 };
102 
103 	/* prepare command */
104 	cmd.header = mc_encode_cmd_header(DPBP_CMDID_ENABLE, cmd_flags,
105 					  token);
106 
107 	/* send command to mc*/
108 	return mc_send_command(mc_io, &cmd);
109 }
110 
dpbp_disable(struct fsl_mc_io * mc_io,uint32_t cmd_flags,uint16_t token)111 int dpbp_disable(struct fsl_mc_io *mc_io,
112 		 uint32_t cmd_flags,
113 		 uint16_t token)
114 {
115 	struct mc_command cmd = { 0 };
116 
117 	/* prepare command */
118 	cmd.header = mc_encode_cmd_header(DPBP_CMDID_DISABLE,
119 					  cmd_flags,
120 					  token);
121 
122 	/* send command to mc*/
123 	return mc_send_command(mc_io, &cmd);
124 }
125 
dpbp_reset(struct fsl_mc_io * mc_io,uint32_t cmd_flags,uint16_t token)126 int dpbp_reset(struct fsl_mc_io *mc_io,
127 	       uint32_t cmd_flags,
128 	       uint16_t token)
129 {
130 	struct mc_command cmd = { 0 };
131 
132 	/* prepare command */
133 	cmd.header = mc_encode_cmd_header(DPBP_CMDID_RESET,
134 					  cmd_flags,
135 					  token);
136 
137 	/* send command to mc*/
138 	return mc_send_command(mc_io, &cmd);
139 }
140 
dpbp_get_attributes(struct fsl_mc_io * mc_io,uint32_t cmd_flags,uint16_t token,struct dpbp_attr * attr)141 int dpbp_get_attributes(struct fsl_mc_io *mc_io,
142 			uint32_t cmd_flags,
143 			uint16_t token,
144 			struct dpbp_attr *attr)
145 {
146 	struct mc_command cmd = { 0 };
147 	int err;
148 
149 	/* prepare command */
150 	cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_ATTR,
151 					  cmd_flags,
152 					  token);
153 
154 	/* send command to mc*/
155 	err = mc_send_command(mc_io, &cmd);
156 	if (err)
157 		return err;
158 
159 	/* retrieve response parameters */
160 	DPBP_RSP_GET_ATTRIBUTES(cmd, attr);
161 
162 	return 0;
163 }
164 
dpbp_get_api_version(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 * major_ver,u16 * minor_ver)165 int dpbp_get_api_version(struct fsl_mc_io *mc_io,
166 			 u32 cmd_flags,
167 			 u16 *major_ver,
168 			 u16 *minor_ver)
169 {
170 	struct mc_command cmd = { 0 };
171 	int err;
172 
173 	/* prepare command */
174 	cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_API_VERSION,
175 					  cmd_flags, 0);
176 
177 	/* send command to mc */
178 	err = mc_send_command(mc_io, &cmd);
179 	if (err)
180 		return err;
181 
182 	/* retrieve response parameters */
183 	mc_cmd_read_api_version(&cmd, major_ver, minor_ver);
184 
185 	return 0;
186 }
187