blob: a0552f44dc23ddabd72636390ff952b25200f161 [file] [log] [blame]
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -07001/*
2 * Freescale Layerscape MC I/O wrapper
3 *
Yogesh Gaur318c32f2017-11-15 11:59:31 +05304 * Copyright (C) 2013-2016 Freescale Semiconductor, Inc.
5 * Copyright 2017 NXP
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -07006 *
7 * SPDX-License-Identifier: GPL-2.0+
8 */
9#include <fsl-mc/fsl_mc_sys.h>
10#include <fsl-mc/fsl_mc_cmd.h>
11#include <fsl-mc/fsl_dpbp.h>
12
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +053013int dpbp_open(struct fsl_mc_io *mc_io,
14 uint32_t cmd_flags,
15 int dpbp_id,
16 uint16_t *token)
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -070017{
18 struct mc_command cmd = { 0 };
19 int err;
20
21 /* prepare command */
22 cmd.header = mc_encode_cmd_header(DPBP_CMDID_OPEN,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +053023 cmd_flags,
24 0);
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -070025 DPBP_CMD_OPEN(cmd, dpbp_id);
26
27 /* send command to mc*/
28 err = mc_send_command(mc_io, &cmd);
29 if (err)
30 return err;
31
32 /* retrieve response parameters */
33 *token = MC_CMD_HDR_READ_TOKEN(cmd.header);
34
35 return err;
36}
37
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +053038int dpbp_close(struct fsl_mc_io *mc_io,
39 uint32_t cmd_flags,
40 uint16_t token)
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -070041{
42 struct mc_command cmd = { 0 };
43
44 /* prepare command */
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +053045 cmd.header = mc_encode_cmd_header(DPBP_CMDID_CLOSE, cmd_flags,
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -070046 token);
47
48 /* send command to mc*/
49 return mc_send_command(mc_io, &cmd);
50}
51
Prabhakar Kushwahacf0c8cf2015-11-04 12:25:53 +053052int dpbp_create(struct fsl_mc_io *mc_io,
Yogesh Gaur318c32f2017-11-15 11:59:31 +053053 uint16_t dprc_token,
Prabhakar Kushwahacf0c8cf2015-11-04 12:25:53 +053054 uint32_t cmd_flags,
55 const struct dpbp_cfg *cfg,
Yogesh Gaur318c32f2017-11-15 11:59:31 +053056 uint32_t *obj_id)
Prabhakar Kushwahacf0c8cf2015-11-04 12:25:53 +053057{
58 struct mc_command cmd = { 0 };
59 int err;
60
61 (void)(cfg); /* unused */
62
63 /* prepare command */
64 cmd.header = mc_encode_cmd_header(DPBP_CMDID_CREATE,
65 cmd_flags,
Yogesh Gaur318c32f2017-11-15 11:59:31 +053066 dprc_token);
Prabhakar Kushwahacf0c8cf2015-11-04 12:25:53 +053067
68 /* send command to mc*/
69 err = mc_send_command(mc_io, &cmd);
70 if (err)
71 return err;
72
73 /* retrieve response parameters */
Yogesh Gaur318c32f2017-11-15 11:59:31 +053074 MC_CMD_READ_OBJ_ID(cmd, *obj_id);
Prabhakar Kushwahacf0c8cf2015-11-04 12:25:53 +053075
76 return 0;
77}
78
79int dpbp_destroy(struct fsl_mc_io *mc_io,
Yogesh Gaur318c32f2017-11-15 11:59:31 +053080 uint16_t dprc_token,
Prabhakar Kushwahacf0c8cf2015-11-04 12:25:53 +053081 uint32_t cmd_flags,
Yogesh Gaur318c32f2017-11-15 11:59:31 +053082 uint32_t obj_id)
Prabhakar Kushwahacf0c8cf2015-11-04 12:25:53 +053083{
84 struct mc_command cmd = { 0 };
85
86 /* prepare command */
87 cmd.header = mc_encode_cmd_header(DPBP_CMDID_DESTROY,
88 cmd_flags,
Yogesh Gaur318c32f2017-11-15 11:59:31 +053089 dprc_token);
90
91 /* set object id to destroy */
92 CMD_DESTROY_SET_OBJ_ID_PARAM0(cmd, obj_id);
Prabhakar Kushwahacf0c8cf2015-11-04 12:25:53 +053093
94 /* send command to mc*/
95 return mc_send_command(mc_io, &cmd);
96}
97
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +053098int dpbp_enable(struct fsl_mc_io *mc_io,
99 uint32_t cmd_flags,
100 uint16_t token)
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700101{
102 struct mc_command cmd = { 0 };
103
104 /* prepare command */
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530105 cmd.header = mc_encode_cmd_header(DPBP_CMDID_ENABLE, cmd_flags,
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700106 token);
107
108 /* send command to mc*/
109 return mc_send_command(mc_io, &cmd);
110}
111
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530112int dpbp_disable(struct fsl_mc_io *mc_io,
113 uint32_t cmd_flags,
114 uint16_t token)
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700115{
116 struct mc_command cmd = { 0 };
117
118 /* prepare command */
119 cmd.header = mc_encode_cmd_header(DPBP_CMDID_DISABLE,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530120 cmd_flags,
121 token);
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700122
123 /* send command to mc*/
124 return mc_send_command(mc_io, &cmd);
125}
126
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530127int dpbp_reset(struct fsl_mc_io *mc_io,
128 uint32_t cmd_flags,
129 uint16_t token)
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700130{
131 struct mc_command cmd = { 0 };
132
133 /* prepare command */
134 cmd.header = mc_encode_cmd_header(DPBP_CMDID_RESET,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530135 cmd_flags,
136 token);
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700137
138 /* send command to mc*/
139 return mc_send_command(mc_io, &cmd);
140}
141
142int dpbp_get_attributes(struct fsl_mc_io *mc_io,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530143 uint32_t cmd_flags,
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700144 uint16_t token,
145 struct dpbp_attr *attr)
146{
147 struct mc_command cmd = { 0 };
148 int err;
149
150 /* prepare command */
151 cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_ATTR,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530152 cmd_flags,
153 token);
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700154
155 /* send command to mc*/
156 err = mc_send_command(mc_io, &cmd);
157 if (err)
158 return err;
159
160 /* retrieve response parameters */
161 DPBP_RSP_GET_ATTRIBUTES(cmd, attr);
162
163 return 0;
164}
Yogesh Gaur318c32f2017-11-15 11:59:31 +0530165
166int dpbp_get_api_version(struct fsl_mc_io *mc_io,
167 u32 cmd_flags,
168 u16 *major_ver,
169 u16 *minor_ver)
170{
171 struct mc_command cmd = { 0 };
172 int err;
173
174 /* prepare command */
175 cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_API_VERSION,
176 cmd_flags, 0);
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 mc_cmd_read_api_version(&cmd, major_ver, minor_ver);
185
186 return 0;
187}