2 * Copyright 2013-2016 Freescale Semiconductor Inc.
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.
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
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.
33 #include <linux/kernel.h>
34 #include "../../include/mc.h"
40 * Data Path I/O Portal API
41 * Contains initialization APIs and runtime control APIs for DPIO
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
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.
59 * Return: '0' on Success; Error code otherwise.
61 int dpio_open(struct fsl_mc_io
*mc_io
,
66 struct mc_command cmd
= { 0 };
67 struct dpio_cmd_open
*dpio_cmd
;
71 cmd
.header
= mc_encode_cmd_header(DPIO_CMDID_OPEN
,
74 dpio_cmd
= (struct dpio_cmd_open
*)cmd
.params
;
75 dpio_cmd
->dpio_id
= cpu_to_le32(dpio_id
);
77 err
= mc_send_command(mc_io
, &cmd
);
81 /* retrieve response parameters */
82 *token
= mc_cmd_hdr_read_token(&cmd
);
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
93 * Return: '0' on Success; Error code otherwise.
95 int dpio_close(struct fsl_mc_io
*mc_io
,
99 struct mc_command cmd
= { 0 };
101 /* prepare command */
102 cmd
.header
= mc_encode_cmd_header(DPIO_CMDID_CLOSE
,
106 return mc_send_command(mc_io
, &cmd
);
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
115 * Return: '0' on Success; Error code otherwise
117 int dpio_enable(struct fsl_mc_io
*mc_io
,
121 struct mc_command cmd
= { 0 };
123 /* prepare command */
124 cmd
.header
= mc_encode_cmd_header(DPIO_CMDID_ENABLE
,
128 return mc_send_command(mc_io
, &cmd
);
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
137 * Return: '0' on Success; Error code otherwise
139 int dpio_disable(struct fsl_mc_io
*mc_io
,
143 struct mc_command cmd
= { 0 };
145 /* prepare command */
146 cmd
.header
= mc_encode_cmd_header(DPIO_CMDID_DISABLE
,
150 return mc_send_command(mc_io
, &cmd
);
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
160 * Return: '0' on Success; Error code otherwise
162 int dpio_get_attributes(struct fsl_mc_io
*mc_io
,
165 struct dpio_attr
*attr
)
167 struct mc_command cmd
= { 0 };
168 struct dpio_rsp_get_attr
*dpio_rsp
;
171 /* prepare command */
172 cmd
.header
= mc_encode_cmd_header(DPIO_CMDID_GET_ATTR
,
176 err
= mc_send_command(mc_io
, &cmd
);
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
);
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
202 * Return: '0' on Success; Error code otherwise
204 int dpio_get_api_version(struct fsl_mc_io
*mc_io
,
209 struct mc_command cmd
= { 0 };
212 /* prepare command */
213 cmd
.header
= mc_encode_cmd_header(DPIO_CMDID_GET_API_VERSION
,
216 err
= mc_send_command(mc_io
, &cmd
);
220 /* retrieve response parameters */
221 mc_cmd_read_api_version(&cmd
, major_ver
, minor_ver
);