blob: 760555d7946e16bd130a11bfe686f0d66edca0e9 [file] [log] [blame]
Bogdan Purcareata203e2de2018-01-17 18:36:44 +02001// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
2/*
3 * Copyright 2013-2016 Freescale Semiconductor Inc.
Ioana Radulescu24999f32017-04-28 04:50:26 -05004 *
Ioana Radulescu24999f32017-04-28 04:50:26 -05005 */
Laurentiu Tudor409acdd2017-06-27 17:41:32 +03006#include <linux/kernel.h>
Bogdan Purcareata6bd067c2018-02-05 08:07:42 -06007#include <linux/fsl/mc.h>
Bogdan Purcareata70ae9cf2018-03-02 04:23:59 -06008#include <linux/fsl/mc.h>
Ioana Radulescu24999f32017-04-28 04:50:26 -05009
Bogdan Purcareata70ae9cf2018-03-02 04:23:59 -060010#include "fsl-mc-private.h"
Ioana Radulescu24999f32017-04-28 04:50:26 -050011
12/**
13 * dpcon_open() - Open a control session for the specified object
14 * @mc_io: Pointer to MC portal's I/O object
15 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
16 * @dpcon_id: DPCON unique ID
17 * @token: Returned token; use in subsequent API calls
18 *
19 * This function can be used to open a control session for an
20 * already created object; an object may have been declared in
21 * the DPL or by calling the dpcon_create() function.
22 * This function returns a unique authentication token,
23 * associated with the specific object ID and the specific MC
24 * portal; this token must be used in all subsequent commands for
25 * this specific object.
26 *
27 * Return: '0' on Success; Error code otherwise.
28 */
29int dpcon_open(struct fsl_mc_io *mc_io,
30 u32 cmd_flags,
31 int dpcon_id,
32 u16 *token)
33{
Ioana Ciornei5b04ced2018-03-15 12:05:31 -050034 struct fsl_mc_command cmd = { 0 };
Ioana Radulescu24999f32017-04-28 04:50:26 -050035 struct dpcon_cmd_open *dpcon_cmd;
36 int err;
37
38 /* prepare command */
39 cmd.header = mc_encode_cmd_header(DPCON_CMDID_OPEN,
40 cmd_flags,
41 0);
42 dpcon_cmd = (struct dpcon_cmd_open *)cmd.params;
43 dpcon_cmd->dpcon_id = cpu_to_le32(dpcon_id);
44
45 /* send command to mc*/
46 err = mc_send_command(mc_io, &cmd);
47 if (err)
48 return err;
49
50 /* retrieve response parameters */
51 *token = mc_cmd_hdr_read_token(&cmd);
52
53 return 0;
54}
Laurentiu Tudorc9d57ea2017-11-17 15:38:29 +020055EXPORT_SYMBOL_GPL(dpcon_open);
Ioana Radulescu24999f32017-04-28 04:50:26 -050056
57/**
58 * dpcon_close() - Close the control session of the object
59 * @mc_io: Pointer to MC portal's I/O object
60 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
61 * @token: Token of DPCON object
62 *
63 * After this function is called, no further operations are
64 * allowed on the object without opening a new control session.
65 *
66 * Return: '0' on Success; Error code otherwise.
67 */
68int dpcon_close(struct fsl_mc_io *mc_io,
69 u32 cmd_flags,
70 u16 token)
71{
Ioana Ciornei5b04ced2018-03-15 12:05:31 -050072 struct fsl_mc_command cmd = { 0 };
Ioana Radulescu24999f32017-04-28 04:50:26 -050073
74 /* prepare command */
75 cmd.header = mc_encode_cmd_header(DPCON_CMDID_CLOSE,
76 cmd_flags,
77 token);
78
79 /* send command to mc*/
80 return mc_send_command(mc_io, &cmd);
81}
Laurentiu Tudorc9d57ea2017-11-17 15:38:29 +020082EXPORT_SYMBOL_GPL(dpcon_close);
Ioana Radulescu24999f32017-04-28 04:50:26 -050083
84/**
85 * dpcon_enable() - Enable the DPCON
86 * @mc_io: Pointer to MC portal's I/O object
87 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
88 * @token: Token of DPCON object
89 *
90 * Return: '0' on Success; Error code otherwise
91 */
92int dpcon_enable(struct fsl_mc_io *mc_io,
93 u32 cmd_flags,
94 u16 token)
95{
Ioana Ciornei5b04ced2018-03-15 12:05:31 -050096 struct fsl_mc_command cmd = { 0 };
Ioana Radulescu24999f32017-04-28 04:50:26 -050097
98 /* prepare command */
99 cmd.header = mc_encode_cmd_header(DPCON_CMDID_ENABLE,
100 cmd_flags,
101 token);
102
103 /* send command to mc*/
104 return mc_send_command(mc_io, &cmd);
105}
Laurentiu Tudorc9d57ea2017-11-17 15:38:29 +0200106EXPORT_SYMBOL_GPL(dpcon_enable);
Ioana Radulescu24999f32017-04-28 04:50:26 -0500107
108/**
109 * dpcon_disable() - Disable the DPCON
110 * @mc_io: Pointer to MC portal's I/O object
111 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
112 * @token: Token of DPCON object
113 *
114 * Return: '0' on Success; Error code otherwise
115 */
116int dpcon_disable(struct fsl_mc_io *mc_io,
117 u32 cmd_flags,
118 u16 token)
119{
Ioana Ciornei5b04ced2018-03-15 12:05:31 -0500120 struct fsl_mc_command cmd = { 0 };
Ioana Radulescu24999f32017-04-28 04:50:26 -0500121
122 /* prepare command */
123 cmd.header = mc_encode_cmd_header(DPCON_CMDID_DISABLE,
124 cmd_flags,
125 token);
126
127 /* send command to mc*/
128 return mc_send_command(mc_io, &cmd);
129}
Laurentiu Tudorc9d57ea2017-11-17 15:38:29 +0200130EXPORT_SYMBOL_GPL(dpcon_disable);
Ioana Radulescu24999f32017-04-28 04:50:26 -0500131
132/**
Ioana Radulescu24999f32017-04-28 04:50:26 -0500133 * dpcon_reset() - Reset the DPCON, returns the object to initial state.
134 * @mc_io: Pointer to MC portal's I/O object
135 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
136 * @token: Token of DPCON object
137 *
138 * Return: '0' on Success; Error code otherwise.
139 */
140int dpcon_reset(struct fsl_mc_io *mc_io,
141 u32 cmd_flags,
142 u16 token)
143{
Ioana Ciornei5b04ced2018-03-15 12:05:31 -0500144 struct fsl_mc_command cmd = { 0 };
Ioana Radulescu24999f32017-04-28 04:50:26 -0500145
146 /* prepare command */
147 cmd.header = mc_encode_cmd_header(DPCON_CMDID_RESET,
148 cmd_flags, token);
149
150 /* send command to mc*/
151 return mc_send_command(mc_io, &cmd);
152}
Laurentiu Tudorc9d57ea2017-11-17 15:38:29 +0200153EXPORT_SYMBOL_GPL(dpcon_reset);
Ioana Radulescu24999f32017-04-28 04:50:26 -0500154
155/**
156 * dpcon_get_attributes() - Retrieve DPCON attributes.
157 * @mc_io: Pointer to MC portal's I/O object
158 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
159 * @token: Token of DPCON object
160 * @attr: Object's attributes
161 *
162 * Return: '0' on Success; Error code otherwise.
163 */
164int dpcon_get_attributes(struct fsl_mc_io *mc_io,
165 u32 cmd_flags,
166 u16 token,
167 struct dpcon_attr *attr)
168{
Ioana Ciornei5b04ced2018-03-15 12:05:31 -0500169 struct fsl_mc_command cmd = { 0 };
Ioana Radulescu24999f32017-04-28 04:50:26 -0500170 struct dpcon_rsp_get_attr *dpcon_rsp;
171 int err;
172
173 /* prepare command */
174 cmd.header = mc_encode_cmd_header(DPCON_CMDID_GET_ATTR,
175 cmd_flags,
176 token);
177
178 /* send command to mc*/
179 err = mc_send_command(mc_io, &cmd);
180 if (err)
181 return err;
182
183 /* retrieve response parameters */
184 dpcon_rsp = (struct dpcon_rsp_get_attr *)cmd.params;
185 attr->id = le32_to_cpu(dpcon_rsp->id);
186 attr->qbman_ch_id = le16_to_cpu(dpcon_rsp->qbman_ch_id);
187 attr->num_priorities = dpcon_rsp->num_priorities;
188
189 return 0;
190}
Laurentiu Tudorc9d57ea2017-11-17 15:38:29 +0200191EXPORT_SYMBOL_GPL(dpcon_get_attributes);
Ioana Radulescu24999f32017-04-28 04:50:26 -0500192
193/**
194 * dpcon_set_notification() - Set DPCON notification destination
195 * @mc_io: Pointer to MC portal's I/O object
196 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
197 * @token: Token of DPCON object
198 * @cfg: Notification parameters
199 *
200 * Return: '0' on Success; Error code otherwise
201 */
202int dpcon_set_notification(struct fsl_mc_io *mc_io,
203 u32 cmd_flags,
204 u16 token,
205 struct dpcon_notification_cfg *cfg)
206{
Ioana Ciornei5b04ced2018-03-15 12:05:31 -0500207 struct fsl_mc_command cmd = { 0 };
Ioana Radulescu24999f32017-04-28 04:50:26 -0500208 struct dpcon_cmd_set_notification *dpcon_cmd;
209
210 /* prepare command */
211 cmd.header = mc_encode_cmd_header(DPCON_CMDID_SET_NOTIFICATION,
212 cmd_flags,
213 token);
214 dpcon_cmd = (struct dpcon_cmd_set_notification *)cmd.params;
215 dpcon_cmd->dpio_id = cpu_to_le32(cfg->dpio_id);
216 dpcon_cmd->priority = cfg->priority;
217 dpcon_cmd->user_ctx = cpu_to_le64(cfg->user_ctx);
218
219 /* send command to mc*/
220 return mc_send_command(mc_io, &cmd);
221}
Laurentiu Tudorc9d57ea2017-11-17 15:38:29 +0200222EXPORT_SYMBOL_GPL(dpcon_set_notification);