xref: /linux/drivers/bus/fsl-mc/dpbp.c (revision 680e6ffa15103ab610c0fc1241d2f98c801b13e2)
1 // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
2 /*
3  * Copyright 2013-2016 Freescale Semiconductor Inc.
4  *
5  */
6 #include <linux/kernel.h>
7 #include <linux/fsl/mc.h>
8 
9 #include "fsl-mc-private.h"
10 
11 /**
12  * dpbp_open() - Open a control session for the specified object.
13  * @mc_io:	Pointer to MC portal's I/O object
14  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
15  * @dpbp_id:	DPBP unique ID
16  * @token:	Returned token; use in subsequent API calls
17  *
18  * This function can be used to open a control session for an
19  * already created object; an object may have been declared in
20  * the DPL or by calling the dpbp_create function.
21  * This function returns a unique authentication token,
22  * associated with the specific object ID and the specific MC
23  * portal; this token must be used in all subsequent commands for
24  * this specific object
25  *
26  * Return:	'0' on Success; Error code otherwise.
27  */
28 int dpbp_open(struct fsl_mc_io *mc_io,
29 	      u32 cmd_flags,
30 	      int dpbp_id,
31 	      u16 *token)
32 {
33 	struct fsl_mc_command cmd = { 0 };
34 	struct dpbp_cmd_open *cmd_params;
35 	int err;
36 
37 	/* prepare command */
38 	cmd.header = mc_encode_cmd_header(DPBP_CMDID_OPEN,
39 					  cmd_flags, 0);
40 	cmd_params = (struct dpbp_cmd_open *)cmd.params;
41 	cmd_params->dpbp_id = cpu_to_le32(dpbp_id);
42 
43 	/* send command to mc*/
44 	err = mc_send_command(mc_io, &cmd);
45 	if (err)
46 		return err;
47 
48 	/* retrieve response parameters */
49 	*token = mc_cmd_hdr_read_token(&cmd);
50 
51 	return err;
52 }
53 EXPORT_SYMBOL_GPL(dpbp_open);
54 
55 /**
56  * dpbp_close() - Close the control session of the object
57  * @mc_io:	Pointer to MC portal's I/O object
58  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
59  * @token:	Token of DPBP object
60  *
61  * After this function is called, no further operations are
62  * allowed on the object without opening a new control session.
63  *
64  * Return:	'0' on Success; Error code otherwise.
65  */
66 int dpbp_close(struct fsl_mc_io *mc_io,
67 	       u32 cmd_flags,
68 	       u16 token)
69 {
70 	struct fsl_mc_command cmd = { 0 };
71 
72 	/* prepare command */
73 	cmd.header = mc_encode_cmd_header(DPBP_CMDID_CLOSE, cmd_flags,
74 					  token);
75 
76 	/* send command to mc*/
77 	return mc_send_command(mc_io, &cmd);
78 }
79 EXPORT_SYMBOL_GPL(dpbp_close);
80 
81 /**
82  * dpbp_enable() - Enable the DPBP.
83  * @mc_io:	Pointer to MC portal's I/O object
84  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
85  * @token:	Token of DPBP object
86  *
87  * Return:	'0' on Success; Error code otherwise.
88  */
89 int dpbp_enable(struct fsl_mc_io *mc_io,
90 		u32 cmd_flags,
91 		u16 token)
92 {
93 	struct fsl_mc_command cmd = { 0 };
94 
95 	/* prepare command */
96 	cmd.header = mc_encode_cmd_header(DPBP_CMDID_ENABLE, cmd_flags,
97 					  token);
98 
99 	/* send command to mc*/
100 	return mc_send_command(mc_io, &cmd);
101 }
102 EXPORT_SYMBOL_GPL(dpbp_enable);
103 
104 /**
105  * dpbp_disable() - Disable the DPBP.
106  * @mc_io:	Pointer to MC portal's I/O object
107  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
108  * @token:	Token of DPBP object
109  *
110  * Return:	'0' on Success; Error code otherwise.
111  */
112 int dpbp_disable(struct fsl_mc_io *mc_io,
113 		 u32 cmd_flags,
114 		 u16 token)
115 {
116 	struct fsl_mc_command cmd = { 0 };
117 
118 	/* prepare command */
119 	cmd.header = mc_encode_cmd_header(DPBP_CMDID_DISABLE,
120 					  cmd_flags, token);
121 
122 	/* send command to mc*/
123 	return mc_send_command(mc_io, &cmd);
124 }
125 EXPORT_SYMBOL_GPL(dpbp_disable);
126 
127 /**
128  * dpbp_reset() - Reset the DPBP, returns the object to initial state.
129  * @mc_io:	Pointer to MC portal's I/O object
130  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
131  * @token:	Token of DPBP object
132  *
133  * Return:	'0' on Success; Error code otherwise.
134  */
135 int dpbp_reset(struct fsl_mc_io *mc_io,
136 	       u32 cmd_flags,
137 	       u16 token)
138 {
139 	struct fsl_mc_command cmd = { 0 };
140 
141 	/* prepare command */
142 	cmd.header = mc_encode_cmd_header(DPBP_CMDID_RESET,
143 					  cmd_flags, token);
144 
145 	/* send command to mc*/
146 	return mc_send_command(mc_io, &cmd);
147 }
148 EXPORT_SYMBOL_GPL(dpbp_reset);
149 
150 /**
151  * dpbp_get_attributes - Retrieve DPBP attributes.
152  *
153  * @mc_io:	Pointer to MC portal's I/O object
154  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
155  * @token:	Token of DPBP object
156  * @attr:	Returned object's attributes
157  *
158  * Return:	'0' on Success; Error code otherwise.
159  */
160 int dpbp_get_attributes(struct fsl_mc_io *mc_io,
161 			u32 cmd_flags,
162 			u16 token,
163 			struct dpbp_attr *attr)
164 {
165 	struct fsl_mc_command cmd = { 0 };
166 	struct dpbp_rsp_get_attributes *rsp_params;
167 	int err;
168 
169 	/* prepare command */
170 	cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_ATTR,
171 					  cmd_flags, token);
172 
173 	/* send command to mc*/
174 	err = mc_send_command(mc_io, &cmd);
175 	if (err)
176 		return err;
177 
178 	/* retrieve response parameters */
179 	rsp_params = (struct dpbp_rsp_get_attributes *)cmd.params;
180 	attr->bpid = le16_to_cpu(rsp_params->bpid);
181 	attr->id = le32_to_cpu(rsp_params->id);
182 
183 	return 0;
184 }
185 EXPORT_SYMBOL_GPL(dpbp_get_attributes);
186