Merge branch 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-2.6-block.git] / drivers / bus / fsl-mc / dpbp.c
CommitLineData
203e2de3 1// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
363b0cbf
SY
2/*
3 * Copyright 2013-2016 Freescale Semiconductor Inc.
f86a1808 4 *
f86a1808 5 */
409acdd0 6#include <linux/kernel.h>
6bd067c4 7#include <linux/fsl/mc.h>
824ebf18 8
9c692d5a 9#include "fsl-mc-private.h"
197f4d6a 10
e9bf3f20
GR
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 */
c4d88721 28int dpbp_open(struct fsl_mc_io *mc_io,
ba72f25b 29 u32 cmd_flags,
c4d88721 30 int dpbp_id,
ba72f25b 31 u16 *token)
197f4d6a 32{
5b04cede 33 struct fsl_mc_command cmd = { 0 };
9989b599 34 struct dpbp_cmd_open *cmd_params;
197f4d6a
GR
35 int err;
36
37 /* prepare command */
38 cmd.header = mc_encode_cmd_header(DPBP_CMDID_OPEN,
c4d88721 39 cmd_flags, 0);
9989b599
IR
40 cmd_params = (struct dpbp_cmd_open *)cmd.params;
41 cmd_params->dpbp_id = cpu_to_le32(dpbp_id);
197f4d6a
GR
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 */
9989b599 49 *token = mc_cmd_hdr_read_token(&cmd);
197f4d6a
GR
50
51 return err;
52}
c9d57ea0 53EXPORT_SYMBOL_GPL(dpbp_open);
197f4d6a 54
e9bf3f20
GR
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 */
c4d88721 66int dpbp_close(struct fsl_mc_io *mc_io,
ba72f25b
GR
67 u32 cmd_flags,
68 u16 token)
197f4d6a 69{
5b04cede 70 struct fsl_mc_command cmd = { 0 };
197f4d6a
GR
71
72 /* prepare command */
c4d88721 73 cmd.header = mc_encode_cmd_header(DPBP_CMDID_CLOSE, cmd_flags,
197f4d6a
GR
74 token);
75
76 /* send command to mc*/
77 return mc_send_command(mc_io, &cmd);
78}
c9d57ea0 79EXPORT_SYMBOL_GPL(dpbp_close);
197f4d6a 80
e9bf3f20
GR
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 */
c4d88721 89int dpbp_enable(struct fsl_mc_io *mc_io,
ba72f25b
GR
90 u32 cmd_flags,
91 u16 token)
197f4d6a 92{
5b04cede 93 struct fsl_mc_command cmd = { 0 };
197f4d6a
GR
94
95 /* prepare command */
c4d88721 96 cmd.header = mc_encode_cmd_header(DPBP_CMDID_ENABLE, cmd_flags,
197f4d6a
GR
97 token);
98
99 /* send command to mc*/
100 return mc_send_command(mc_io, &cmd);
101}
c9d57ea0 102EXPORT_SYMBOL_GPL(dpbp_enable);
197f4d6a 103
e9bf3f20
GR
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 */
c4d88721 112int dpbp_disable(struct fsl_mc_io *mc_io,
ba72f25b
GR
113 u32 cmd_flags,
114 u16 token)
197f4d6a 115{
5b04cede 116 struct fsl_mc_command cmd = { 0 };
197f4d6a
GR
117
118 /* prepare command */
119 cmd.header = mc_encode_cmd_header(DPBP_CMDID_DISABLE,
c4d88721 120 cmd_flags, token);
197f4d6a
GR
121
122 /* send command to mc*/
123 return mc_send_command(mc_io, &cmd);
124}
c9d57ea0 125EXPORT_SYMBOL_GPL(dpbp_disable);
197f4d6a 126
e9bf3f20
GR
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 */
c4d88721 135int dpbp_reset(struct fsl_mc_io *mc_io,
ba72f25b
GR
136 u32 cmd_flags,
137 u16 token)
197f4d6a 138{
5b04cede 139 struct fsl_mc_command cmd = { 0 };
197f4d6a
GR
140
141 /* prepare command */
142 cmd.header = mc_encode_cmd_header(DPBP_CMDID_RESET,
c4d88721 143 cmd_flags, token);
197f4d6a
GR
144
145 /* send command to mc*/
146 return mc_send_command(mc_io, &cmd);
147}
c9d57ea0 148EXPORT_SYMBOL_GPL(dpbp_reset);
197f4d6a 149
e9bf3f20
GR
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 */
197f4d6a 160int dpbp_get_attributes(struct fsl_mc_io *mc_io,
ba72f25b
GR
161 u32 cmd_flags,
162 u16 token,
197f4d6a
GR
163 struct dpbp_attr *attr)
164{
5b04cede 165 struct fsl_mc_command cmd = { 0 };
9989b599 166 struct dpbp_rsp_get_attributes *rsp_params;
197f4d6a
GR
167 int err;
168
169 /* prepare command */
170 cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_ATTR,
c4d88721 171 cmd_flags, token);
197f4d6a
GR
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 */
9989b599
IR
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);
9989b599 182
197f4d6a
GR
183 return 0;
184}
c9d57ea0 185EXPORT_SYMBOL_GPL(dpbp_get_attributes);