]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - drivers/staging/fsl-mc/bus/dpio/dpio.c
Merge tag 'iio-for-4.13b' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23...
[mirror_ubuntu-artful-kernel.git] / drivers / staging / fsl-mc / bus / dpio / dpio.c
1 /*
2 * Copyright 2013-2016 Freescale Semiconductor Inc.
3 * Copyright 2016 NXP
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the above-listed copyright holders nor the
13 * names of any contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * ALTERNATIVELY, this software may be distributed under the terms of the
17 * GNU General Public License ("GPL") as published by the Free Software
18 * Foundation, either version 2 of that License or (at your option) any
19 * later version.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */
33 #include <linux/kernel.h>
34 #include "../../include/mc.h"
35
36 #include "dpio.h"
37 #include "dpio-cmd.h"
38
39 /*
40 * Data Path I/O Portal API
41 * Contains initialization APIs and runtime control APIs for DPIO
42 */
43
44 /**
45 * dpio_open() - Open a control session for the specified object
46 * @mc_io: Pointer to MC portal's I/O object
47 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
48 * @dpio_id: DPIO unique ID
49 * @token: Returned token; use in subsequent API calls
50 *
51 * This function can be used to open a control session for an
52 * already created object; an object may have been declared in
53 * the DPL or by calling the dpio_create() function.
54 * This function returns a unique authentication token,
55 * associated with the specific object ID and the specific MC
56 * portal; this token must be used in all subsequent commands for
57 * this specific object.
58 *
59 * Return: '0' on Success; Error code otherwise.
60 */
61 int dpio_open(struct fsl_mc_io *mc_io,
62 u32 cmd_flags,
63 int dpio_id,
64 u16 *token)
65 {
66 struct mc_command cmd = { 0 };
67 struct dpio_cmd_open *dpio_cmd;
68 int err;
69
70 /* prepare command */
71 cmd.header = mc_encode_cmd_header(DPIO_CMDID_OPEN,
72 cmd_flags,
73 0);
74 dpio_cmd = (struct dpio_cmd_open *)cmd.params;
75 dpio_cmd->dpio_id = cpu_to_le32(dpio_id);
76
77 err = mc_send_command(mc_io, &cmd);
78 if (err)
79 return err;
80
81 /* retrieve response parameters */
82 *token = mc_cmd_hdr_read_token(&cmd);
83
84 return 0;
85 }
86
87 /**
88 * dpio_close() - Close the control session of the object
89 * @mc_io: Pointer to MC portal's I/O object
90 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
91 * @token: Token of DPIO object
92 *
93 * Return: '0' on Success; Error code otherwise.
94 */
95 int dpio_close(struct fsl_mc_io *mc_io,
96 u32 cmd_flags,
97 u16 token)
98 {
99 struct mc_command cmd = { 0 };
100
101 /* prepare command */
102 cmd.header = mc_encode_cmd_header(DPIO_CMDID_CLOSE,
103 cmd_flags,
104 token);
105
106 return mc_send_command(mc_io, &cmd);
107 }
108
109 /**
110 * dpio_enable() - Enable the DPIO, allow I/O portal operations.
111 * @mc_io: Pointer to MC portal's I/O object
112 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
113 * @token: Token of DPIO object
114 *
115 * Return: '0' on Success; Error code otherwise
116 */
117 int dpio_enable(struct fsl_mc_io *mc_io,
118 u32 cmd_flags,
119 u16 token)
120 {
121 struct mc_command cmd = { 0 };
122
123 /* prepare command */
124 cmd.header = mc_encode_cmd_header(DPIO_CMDID_ENABLE,
125 cmd_flags,
126 token);
127
128 return mc_send_command(mc_io, &cmd);
129 }
130
131 /**
132 * dpio_disable() - Disable the DPIO, stop any I/O portal operation.
133 * @mc_io: Pointer to MC portal's I/O object
134 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
135 * @token: Token of DPIO object
136 *
137 * Return: '0' on Success; Error code otherwise
138 */
139 int dpio_disable(struct fsl_mc_io *mc_io,
140 u32 cmd_flags,
141 u16 token)
142 {
143 struct mc_command cmd = { 0 };
144
145 /* prepare command */
146 cmd.header = mc_encode_cmd_header(DPIO_CMDID_DISABLE,
147 cmd_flags,
148 token);
149
150 return mc_send_command(mc_io, &cmd);
151 }
152
153 /**
154 * dpio_get_attributes() - Retrieve DPIO attributes
155 * @mc_io: Pointer to MC portal's I/O object
156 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
157 * @token: Token of DPIO object
158 * @attr: Returned object's attributes
159 *
160 * Return: '0' on Success; Error code otherwise
161 */
162 int dpio_get_attributes(struct fsl_mc_io *mc_io,
163 u32 cmd_flags,
164 u16 token,
165 struct dpio_attr *attr)
166 {
167 struct mc_command cmd = { 0 };
168 struct dpio_rsp_get_attr *dpio_rsp;
169 int err;
170
171 /* prepare command */
172 cmd.header = mc_encode_cmd_header(DPIO_CMDID_GET_ATTR,
173 cmd_flags,
174 token);
175
176 err = mc_send_command(mc_io, &cmd);
177 if (err)
178 return err;
179
180 /* retrieve response parameters */
181 dpio_rsp = (struct dpio_rsp_get_attr *)cmd.params;
182 attr->id = le32_to_cpu(dpio_rsp->id);
183 attr->qbman_portal_id = le16_to_cpu(dpio_rsp->qbman_portal_id);
184 attr->num_priorities = dpio_rsp->num_priorities;
185 attr->channel_mode = dpio_rsp->channel_mode & DPIO_CHANNEL_MODE_MASK;
186 attr->qbman_portal_ce_offset =
187 le64_to_cpu(dpio_rsp->qbman_portal_ce_addr);
188 attr->qbman_portal_ci_offset =
189 le64_to_cpu(dpio_rsp->qbman_portal_ci_addr);
190 attr->qbman_version = le32_to_cpu(dpio_rsp->qbman_version);
191
192 return 0;
193 }
194
195 /**
196 * dpio_get_api_version - Get Data Path I/O API version
197 * @mc_io: Pointer to MC portal's DPIO object
198 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
199 * @major_ver: Major version of DPIO API
200 * @minor_ver: Minor version of DPIO API
201 *
202 * Return: '0' on Success; Error code otherwise
203 */
204 int dpio_get_api_version(struct fsl_mc_io *mc_io,
205 u32 cmd_flags,
206 u16 *major_ver,
207 u16 *minor_ver)
208 {
209 struct mc_command cmd = { 0 };
210 int err;
211
212 /* prepare command */
213 cmd.header = mc_encode_cmd_header(DPIO_CMDID_GET_API_VERSION,
214 cmd_flags, 0);
215
216 err = mc_send_command(mc_io, &cmd);
217 if (err)
218 return err;
219
220 /* retrieve response parameters */
221 mc_cmd_read_api_version(&cmd, major_ver, minor_ver);
222
223 return 0;
224 }