blob: 17e3c5d2f22ef3632df9d6af3ccb4fc32f3f4988 [file] [log] [blame]
Bogdan Purcareata203e2de2018-01-17 18:36:44 +02001// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
Stuart Yoder363b0cb2016-10-26 11:20:28 -05002/*
3 * Copyright 2013-2016 Freescale Semiconductor Inc.
Ramiro Oliveiraf86a1802016-09-30 15:01:21 +01004 *
Ramiro Oliveiraf86a1802016-09-30 15:01:21 +01005 */
Laurentiu Tudor409acdd2017-06-27 17:41:32 +03006#include <linux/kernel.h>
Bogdan Purcareata6bd067c482018-02-05 08:07:42 -06007#include <linux/fsl/mc.h>
Bogdan Purcareata9c692d52018-03-02 04:23:58 -06008#include <linux/fsl/mc.h>
Stuart Yoder824ebf12016-10-17 13:42:18 -05009
Bogdan Purcareata9c692d52018-03-02 04:23:58 -060010#include "fsl-mc-private.h"
J. German Rivera197f4d62015-03-05 19:35:25 -060011
J. German Riverae9bf3f22015-09-24 14:26:54 -050012/**
13 * dpbp_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 * @dpbp_id: DPBP 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 dpbp_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 */
J. German Riverac4d887212015-09-23 16:11:00 -050029int dpbp_open(struct fsl_mc_io *mc_io,
J. German Riveraba72f252015-09-25 11:21:01 -050030 u32 cmd_flags,
J. German Riverac4d887212015-09-23 16:11:00 -050031 int dpbp_id,
J. German Riveraba72f252015-09-25 11:21:01 -050032 u16 *token)
J. German Rivera197f4d62015-03-05 19:35:25 -060033{
Ioana Ciornei5b04ced2018-03-15 12:05:31 -050034 struct fsl_mc_command cmd = { 0 };
Ioana Radulescu9989b592016-06-22 16:40:52 -050035 struct dpbp_cmd_open *cmd_params;
J. German Rivera197f4d62015-03-05 19:35:25 -060036 int err;
37
38 /* prepare command */
39 cmd.header = mc_encode_cmd_header(DPBP_CMDID_OPEN,
J. German Riverac4d887212015-09-23 16:11:00 -050040 cmd_flags, 0);
Ioana Radulescu9989b592016-06-22 16:40:52 -050041 cmd_params = (struct dpbp_cmd_open *)cmd.params;
42 cmd_params->dpbp_id = cpu_to_le32(dpbp_id);
J. German Rivera197f4d62015-03-05 19:35:25 -060043
44 /* send command to mc*/
45 err = mc_send_command(mc_io, &cmd);
46 if (err)
47 return err;
48
49 /* retrieve response parameters */
Ioana Radulescu9989b592016-06-22 16:40:52 -050050 *token = mc_cmd_hdr_read_token(&cmd);
J. German Rivera197f4d62015-03-05 19:35:25 -060051
52 return err;
53}
Laurentiu Tudorc9d57ea2017-11-17 15:38:29 +020054EXPORT_SYMBOL_GPL(dpbp_open);
J. German Rivera197f4d62015-03-05 19:35:25 -060055
J. German Riverae9bf3f22015-09-24 14:26:54 -050056/**
57 * dpbp_close() - Close the control session of the object
58 * @mc_io: Pointer to MC portal's I/O object
59 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
60 * @token: Token of DPBP object
61 *
62 * After this function is called, no further operations are
63 * allowed on the object without opening a new control session.
64 *
65 * Return: '0' on Success; Error code otherwise.
66 */
J. German Riverac4d887212015-09-23 16:11:00 -050067int dpbp_close(struct fsl_mc_io *mc_io,
J. German Riveraba72f252015-09-25 11:21:01 -050068 u32 cmd_flags,
69 u16 token)
J. German Rivera197f4d62015-03-05 19:35:25 -060070{
Ioana Ciornei5b04ced2018-03-15 12:05:31 -050071 struct fsl_mc_command cmd = { 0 };
J. German Rivera197f4d62015-03-05 19:35:25 -060072
73 /* prepare command */
J. German Riverac4d887212015-09-23 16:11:00 -050074 cmd.header = mc_encode_cmd_header(DPBP_CMDID_CLOSE, cmd_flags,
J. German Rivera197f4d62015-03-05 19:35:25 -060075 token);
76
77 /* send command to mc*/
78 return mc_send_command(mc_io, &cmd);
79}
Laurentiu Tudorc9d57ea2017-11-17 15:38:29 +020080EXPORT_SYMBOL_GPL(dpbp_close);
J. German Rivera197f4d62015-03-05 19:35:25 -060081
J. German Riverae9bf3f22015-09-24 14:26:54 -050082/**
J. German Riverae9bf3f22015-09-24 14:26:54 -050083 * dpbp_enable() - Enable the DPBP.
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 DPBP object
87 *
88 * Return: '0' on Success; Error code otherwise.
89 */
J. German Riverac4d887212015-09-23 16:11:00 -050090int dpbp_enable(struct fsl_mc_io *mc_io,
J. German Riveraba72f252015-09-25 11:21:01 -050091 u32 cmd_flags,
92 u16 token)
J. German Rivera197f4d62015-03-05 19:35:25 -060093{
Ioana Ciornei5b04ced2018-03-15 12:05:31 -050094 struct fsl_mc_command cmd = { 0 };
J. German Rivera197f4d62015-03-05 19:35:25 -060095
96 /* prepare command */
J. German Riverac4d887212015-09-23 16:11:00 -050097 cmd.header = mc_encode_cmd_header(DPBP_CMDID_ENABLE, cmd_flags,
J. German Rivera197f4d62015-03-05 19:35:25 -060098 token);
99
100 /* send command to mc*/
101 return mc_send_command(mc_io, &cmd);
102}
Laurentiu Tudorc9d57ea2017-11-17 15:38:29 +0200103EXPORT_SYMBOL_GPL(dpbp_enable);
J. German Rivera197f4d62015-03-05 19:35:25 -0600104
J. German Riverae9bf3f22015-09-24 14:26:54 -0500105/**
106 * dpbp_disable() - Disable the DPBP.
107 * @mc_io: Pointer to MC portal's I/O object
108 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
109 * @token: Token of DPBP object
110 *
111 * Return: '0' on Success; Error code otherwise.
112 */
J. German Riverac4d887212015-09-23 16:11:00 -0500113int dpbp_disable(struct fsl_mc_io *mc_io,
J. German Riveraba72f252015-09-25 11:21:01 -0500114 u32 cmd_flags,
115 u16 token)
J. German Rivera197f4d62015-03-05 19:35:25 -0600116{
Ioana Ciornei5b04ced2018-03-15 12:05:31 -0500117 struct fsl_mc_command cmd = { 0 };
J. German Rivera197f4d62015-03-05 19:35:25 -0600118
119 /* prepare command */
120 cmd.header = mc_encode_cmd_header(DPBP_CMDID_DISABLE,
J. German Riverac4d887212015-09-23 16:11:00 -0500121 cmd_flags, token);
J. German Rivera197f4d62015-03-05 19:35:25 -0600122
123 /* send command to mc*/
124 return mc_send_command(mc_io, &cmd);
125}
Laurentiu Tudorc9d57ea2017-11-17 15:38:29 +0200126EXPORT_SYMBOL_GPL(dpbp_disable);
J. German Rivera197f4d62015-03-05 19:35:25 -0600127
J. German Riverae9bf3f22015-09-24 14:26:54 -0500128/**
J. German Riverae9bf3f22015-09-24 14:26:54 -0500129 * dpbp_reset() - Reset the DPBP, returns the object to initial state.
130 * @mc_io: Pointer to MC portal's I/O object
131 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
132 * @token: Token of DPBP object
133 *
134 * Return: '0' on Success; Error code otherwise.
135 */
J. German Riverac4d887212015-09-23 16:11:00 -0500136int dpbp_reset(struct fsl_mc_io *mc_io,
J. German Riveraba72f252015-09-25 11:21:01 -0500137 u32 cmd_flags,
138 u16 token)
J. German Rivera197f4d62015-03-05 19:35:25 -0600139{
Ioana Ciornei5b04ced2018-03-15 12:05:31 -0500140 struct fsl_mc_command cmd = { 0 };
J. German Rivera197f4d62015-03-05 19:35:25 -0600141
142 /* prepare command */
143 cmd.header = mc_encode_cmd_header(DPBP_CMDID_RESET,
J. German Riverac4d887212015-09-23 16:11:00 -0500144 cmd_flags, token);
J. German Rivera197f4d62015-03-05 19:35:25 -0600145
146 /* send command to mc*/
147 return mc_send_command(mc_io, &cmd);
148}
Laurentiu Tudorc9d57ea2017-11-17 15:38:29 +0200149EXPORT_SYMBOL_GPL(dpbp_reset);
J. German Rivera197f4d62015-03-05 19:35:25 -0600150
J. German Riverae9bf3f22015-09-24 14:26:54 -0500151/**
J. German Riverae9bf3f22015-09-24 14:26:54 -0500152 * dpbp_get_attributes - Retrieve DPBP attributes.
153 *
154 * @mc_io: Pointer to MC portal's I/O object
155 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
156 * @token: Token of DPBP object
157 * @attr: Returned object's attributes
158 *
159 * Return: '0' on Success; Error code otherwise.
160 */
J. German Rivera197f4d62015-03-05 19:35:25 -0600161int dpbp_get_attributes(struct fsl_mc_io *mc_io,
J. German Riveraba72f252015-09-25 11:21:01 -0500162 u32 cmd_flags,
163 u16 token,
J. German Rivera197f4d62015-03-05 19:35:25 -0600164 struct dpbp_attr *attr)
165{
Ioana Ciornei5b04ced2018-03-15 12:05:31 -0500166 struct fsl_mc_command cmd = { 0 };
Ioana Radulescu9989b592016-06-22 16:40:52 -0500167 struct dpbp_rsp_get_attributes *rsp_params;
J. German Rivera197f4d62015-03-05 19:35:25 -0600168 int err;
169
170 /* prepare command */
171 cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_ATTR,
J. German Riverac4d887212015-09-23 16:11:00 -0500172 cmd_flags, token);
J. German Rivera197f4d62015-03-05 19:35:25 -0600173
174 /* send command to mc*/
175 err = mc_send_command(mc_io, &cmd);
176 if (err)
177 return err;
178
179 /* retrieve response parameters */
Ioana Radulescu9989b592016-06-22 16:40:52 -0500180 rsp_params = (struct dpbp_rsp_get_attributes *)cmd.params;
181 attr->bpid = le16_to_cpu(rsp_params->bpid);
182 attr->id = le32_to_cpu(rsp_params->id);
Ioana Radulescu9989b592016-06-22 16:40:52 -0500183
J. German Rivera197f4d62015-03-05 19:35:25 -0600184 return 0;
185}
Laurentiu Tudorc9d57ea2017-11-17 15:38:29 +0200186EXPORT_SYMBOL_GPL(dpbp_get_attributes);