]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/staging/fsl-mc/bus/dpmcp.c
staging: fsl-mc: move mc-sys.h contents in the public header
[karo-tx-linux.git] / drivers / staging / fsl-mc / bus / dpmcp.c
1 /*
2  * Copyright 2013-2016 Freescale Semiconductor Inc.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  * * Redistributions of source code must retain the above copyright
7  * notice, this list of conditions and the following disclaimer.
8  * * Redistributions in binary form must reproduce the above copyright
9  * notice, this list of conditions and the following disclaimer in the
10  * documentation and/or other materials provided with the distribution.
11  * * Neither the name of the above-listed copyright holders nor the
12  * names of any contributors may be used to endorse or promote products
13  * derived from this software without specific prior written permission.
14  *
15  * ALTERNATIVELY, this software may be distributed under the terms of the
16  * GNU General Public License ("GPL") as published by the Free Software
17  * Foundation, either version 2 of that License or (at your option) any
18  * later version.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 #include <linux/kernel.h>
33 #include "../include/mc.h"
34 #include "../include/mc-cmd.h"
35
36 #include "dpmcp.h"
37 #include "dpmcp-cmd.h"
38
39 /**
40  * dpmcp_open() - Open a control session for the specified object.
41  * @mc_io:      Pointer to MC portal's I/O object
42  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
43  * @dpmcp_id:   DPMCP unique ID
44  * @token:      Returned token; use in subsequent API calls
45  *
46  * This function can be used to open a control session for an
47  * already created object; an object may have been declared in
48  * the DPL or by calling the dpmcp_create function.
49  * This function returns a unique authentication token,
50  * associated with the specific object ID and the specific MC
51  * portal; this token must be used in all subsequent commands for
52  * this specific object
53  *
54  * Return:      '0' on Success; Error code otherwise.
55  */
56 int dpmcp_open(struct fsl_mc_io *mc_io,
57                u32 cmd_flags,
58                int dpmcp_id,
59                u16 *token)
60 {
61         struct mc_command cmd = { 0 };
62         struct dpmcp_cmd_open *cmd_params;
63         int err;
64
65         /* prepare command */
66         cmd.header = mc_encode_cmd_header(DPMCP_CMDID_OPEN,
67                                           cmd_flags, 0);
68         cmd_params = (struct dpmcp_cmd_open *)cmd.params;
69         cmd_params->dpmcp_id = cpu_to_le32(dpmcp_id);
70
71         /* send command to mc*/
72         err = mc_send_command(mc_io, &cmd);
73         if (err)
74                 return err;
75
76         /* retrieve response parameters */
77         *token = mc_cmd_hdr_read_token(&cmd);
78
79         return err;
80 }
81
82 /**
83  * dpmcp_close() - Close the control session of the object
84  * @mc_io:      Pointer to MC portal's I/O object
85  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
86  * @token:      Token of DPMCP object
87  *
88  * After this function is called, no further operations are
89  * allowed on the object without opening a new control session.
90  *
91  * Return:      '0' on Success; Error code otherwise.
92  */
93 int dpmcp_close(struct fsl_mc_io *mc_io,
94                 u32 cmd_flags,
95                 u16 token)
96 {
97         struct mc_command cmd = { 0 };
98
99         /* prepare command */
100         cmd.header = mc_encode_cmd_header(DPMCP_CMDID_CLOSE,
101                                           cmd_flags, token);
102
103         /* send command to mc*/
104         return mc_send_command(mc_io, &cmd);
105 }
106
107 /**
108  * dpmcp_reset() - Reset the DPMCP, returns the object to initial state.
109  * @mc_io:      Pointer to MC portal's I/O object
110  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
111  * @token:      Token of DPMCP object
112  *
113  * Return:      '0' on Success; Error code otherwise.
114  */
115 int dpmcp_reset(struct fsl_mc_io *mc_io,
116                 u32 cmd_flags,
117                 u16 token)
118 {
119         struct mc_command cmd = { 0 };
120
121         /* prepare command */
122         cmd.header = mc_encode_cmd_header(DPMCP_CMDID_RESET,
123                                           cmd_flags, token);
124
125         /* send command to mc*/
126         return mc_send_command(mc_io, &cmd);
127 }
128
129 /**
130  * dpmcp_get_api_version - Get Data Path Management Command Portal API version
131  * @mc_io:      Pointer to Mc portal's I/O object
132  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
133  * @major_ver:  Major version of Data Path Management Command Portal API
134  * @minor_ver:  Minor version of Data Path Management Command Portal API
135  *
136  * Return:      '0' on Success; Error code otherwise.
137  */
138 int dpmcp_get_api_version(struct fsl_mc_io *mc_io,
139                           u32 cmd_flags,
140                           u16 *major_ver,
141                           u16 *minor_ver)
142 {
143         struct mc_command cmd = { 0 };
144         int err;
145
146         /* prepare command */
147         cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_API_VERSION,
148                                           cmd_flags, 0);
149
150         /* send command to mc */
151         err = mc_send_command(mc_io, &cmd);
152         if (err)
153                 return err;
154
155         /* retrieve response parameters */
156         mc_cmd_read_api_version(&cmd, major_ver, minor_ver);
157
158         return 0;
159 }