xref: /openbmc/u-boot/drivers/net/fsl-mc/dpbp.c (revision 7e8702a0)
1 /*
2  * Freescale Layerscape MC I/O wrapper
3  *
4  * Copyright (C) 2013-2015 Freescale Semiconductor, Inc.
5  * Author: German Rivera <German.Rivera@freescale.com>
6  *
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 
13 int dpbp_open(struct fsl_mc_io *mc_io,
14 	      uint32_t cmd_flags,
15 	      int dpbp_id,
16 	      uint16_t *token)
17 {
18 	struct mc_command cmd = { 0 };
19 	int err;
20 
21 	/* prepare command */
22 	cmd.header = mc_encode_cmd_header(DPBP_CMDID_OPEN,
23 					  cmd_flags,
24 					  0);
25 	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 
38 int dpbp_close(struct fsl_mc_io *mc_io,
39 	       uint32_t cmd_flags,
40 	       uint16_t token)
41 {
42 	struct mc_command cmd = { 0 };
43 
44 	/* prepare command */
45 	cmd.header = mc_encode_cmd_header(DPBP_CMDID_CLOSE, cmd_flags,
46 					  token);
47 
48 	/* send command to mc*/
49 	return mc_send_command(mc_io, &cmd);
50 }
51 
52 int dpbp_create(struct fsl_mc_io *mc_io,
53 		uint32_t cmd_flags,
54 		const struct dpbp_cfg *cfg,
55 		uint16_t *token)
56 {
57 	struct mc_command cmd = { 0 };
58 	int err;
59 
60 	(void)(cfg); /* unused */
61 
62 	/* prepare command */
63 	cmd.header = mc_encode_cmd_header(DPBP_CMDID_CREATE,
64 					  cmd_flags,
65 					  0);
66 
67 	/* send command to mc*/
68 	err = mc_send_command(mc_io, &cmd);
69 	if (err)
70 		return err;
71 
72 	/* retrieve response parameters */
73 	*token = MC_CMD_HDR_READ_TOKEN(cmd.header);
74 
75 	return 0;
76 }
77 
78 int dpbp_destroy(struct fsl_mc_io *mc_io,
79 		 uint32_t cmd_flags,
80 		 uint16_t token)
81 {
82 	struct mc_command cmd = { 0 };
83 
84 	/* prepare command */
85 	cmd.header = mc_encode_cmd_header(DPBP_CMDID_DESTROY,
86 					  cmd_flags,
87 					  token);
88 
89 	/* send command to mc*/
90 	return mc_send_command(mc_io, &cmd);
91 }
92 
93 int dpbp_enable(struct fsl_mc_io *mc_io,
94 		uint32_t cmd_flags,
95 		uint16_t token)
96 {
97 	struct mc_command cmd = { 0 };
98 
99 	/* prepare command */
100 	cmd.header = mc_encode_cmd_header(DPBP_CMDID_ENABLE, cmd_flags,
101 					  token);
102 
103 	/* send command to mc*/
104 	return mc_send_command(mc_io, &cmd);
105 }
106 
107 int dpbp_disable(struct fsl_mc_io *mc_io,
108 		 uint32_t cmd_flags,
109 		 uint16_t token)
110 {
111 	struct mc_command cmd = { 0 };
112 
113 	/* prepare command */
114 	cmd.header = mc_encode_cmd_header(DPBP_CMDID_DISABLE,
115 					  cmd_flags,
116 					  token);
117 
118 	/* send command to mc*/
119 	return mc_send_command(mc_io, &cmd);
120 }
121 
122 int dpbp_reset(struct fsl_mc_io *mc_io,
123 	       uint32_t cmd_flags,
124 	       uint16_t token)
125 {
126 	struct mc_command cmd = { 0 };
127 
128 	/* prepare command */
129 	cmd.header = mc_encode_cmd_header(DPBP_CMDID_RESET,
130 					  cmd_flags,
131 					  token);
132 
133 	/* send command to mc*/
134 	return mc_send_command(mc_io, &cmd);
135 }
136 
137 int dpbp_get_attributes(struct fsl_mc_io *mc_io,
138 			uint32_t cmd_flags,
139 			uint16_t token,
140 			struct dpbp_attr *attr)
141 {
142 	struct mc_command cmd = { 0 };
143 	int err;
144 
145 	/* prepare command */
146 	cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_ATTR,
147 					  cmd_flags,
148 					  token);
149 
150 	/* send command to mc*/
151 	err = mc_send_command(mc_io, &cmd);
152 	if (err)
153 		return err;
154 
155 	/* retrieve response parameters */
156 	DPBP_RSP_GET_ATTRIBUTES(cmd, attr);
157 
158 	return 0;
159 }
160