xref: /dpdk/drivers/net/octeontx/base/octeontx_bgx.c (revision eb6d5a0af9a05bf940ba19ec1ddbe575b5e7540b)
1 /*
2  *   BSD LICENSE
3  *
4  *   Copyright (C) Cavium Inc. 2017. All rights reserved.
5  *
6  *   Redistribution and use in source and binary forms, with or without
7  *   modification, are permitted provided that the following conditions
8  *   are met:
9  *
10  *     * Redistributions of source code must retain the above copyright
11  *       notice, this list of conditions and the following disclaimer.
12  *     * Redistributions in binary form must reproduce the above copyright
13  *       notice, this list of conditions and the following disclaimer in
14  *       the documentation and/or other materials provided with the
15  *       distribution.
16  *     * Neither the name of Cavium networks nor the names of its
17  *       contributors may be used to endorse or promote products derived
18  *       from this software without specific prior written permission.
19  *
20  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #include <string.h>
34 
35 #include "octeontx_bgx.h"
36 
37 int
38 octeontx_bgx_port_open(int port, octeontx_mbox_bgx_port_conf_t *conf)
39 {
40 	struct octeontx_mbox_hdr hdr;
41 	octeontx_mbox_bgx_port_conf_t bgx_conf;
42 	int len = sizeof(octeontx_mbox_bgx_port_conf_t);
43 	int res;
44 
45 	memset(&bgx_conf, 0, sizeof(octeontx_mbox_bgx_port_conf_t));
46 	hdr.coproc = OCTEONTX_BGX_COPROC;
47 	hdr.msg = MBOX_BGX_PORT_OPEN;
48 	hdr.vfid = port;
49 
50 	res = octeontx_ssovf_mbox_send(&hdr, NULL, 0, &bgx_conf, len);
51 	if (res < 0)
52 		return -EACCES;
53 
54 	conf->enable = bgx_conf.enable;
55 	conf->promisc = bgx_conf.promisc;
56 	conf->bpen = bgx_conf.bpen;
57 	conf->node = bgx_conf.node;
58 	conf->base_chan = bgx_conf.base_chan;
59 	conf->num_chans = bgx_conf.num_chans;
60 	conf->mtu = bgx_conf.mtu;
61 	conf->bgx = bgx_conf.bgx;
62 	conf->lmac = bgx_conf.lmac;
63 	conf->mode = bgx_conf.mode;
64 	conf->pkind = bgx_conf.pkind;
65 	memcpy(conf->macaddr, bgx_conf.macaddr, 6);
66 
67 	return res;
68 }
69 
70 int
71 octeontx_bgx_port_close(int port)
72 {
73 	struct octeontx_mbox_hdr hdr;
74 	int res;
75 
76 	hdr.coproc = OCTEONTX_BGX_COPROC;
77 	hdr.msg = MBOX_BGX_PORT_CLOSE;
78 	hdr.vfid = port;
79 
80 	res = octeontx_ssovf_mbox_send(&hdr, NULL, 0, NULL, 0);
81 	if (res < 0)
82 		return -EACCES;
83 
84 	return res;
85 }
86 
87 int
88 octeontx_bgx_port_start(int port)
89 {
90 	struct octeontx_mbox_hdr hdr;
91 	int res;
92 
93 	hdr.coproc = OCTEONTX_BGX_COPROC;
94 	hdr.msg = MBOX_BGX_PORT_START;
95 	hdr.vfid = port;
96 
97 	res = octeontx_ssovf_mbox_send(&hdr, NULL, 0, NULL, 0);
98 	if (res < 0)
99 		return -EACCES;
100 
101 	return res;
102 }
103 
104 int
105 octeontx_bgx_port_stop(int port)
106 {
107 	struct octeontx_mbox_hdr hdr;
108 	int res;
109 
110 	hdr.coproc = OCTEONTX_BGX_COPROC;
111 	hdr.msg = MBOX_BGX_PORT_STOP;
112 	hdr.vfid = port;
113 
114 	res = octeontx_ssovf_mbox_send(&hdr, NULL, 0, NULL, 0);
115 	if (res < 0)
116 		return -EACCES;
117 
118 	return res;
119 }
120 
121 int
122 octeontx_bgx_port_get_config(int port, octeontx_mbox_bgx_port_conf_t *conf)
123 {
124 	struct octeontx_mbox_hdr hdr;
125 	octeontx_mbox_bgx_port_conf_t bgx_conf;
126 	int len = sizeof(octeontx_mbox_bgx_port_conf_t);
127 	int res;
128 
129 	hdr.coproc = OCTEONTX_BGX_COPROC;
130 	hdr.msg = MBOX_BGX_PORT_GET_CONFIG;
131 	hdr.vfid = port;
132 
133 	memset(&bgx_conf, 0, sizeof(octeontx_mbox_bgx_port_conf_t));
134 	res = octeontx_ssovf_mbox_send(&hdr, NULL, 0, &bgx_conf, len);
135 	if (res < 0)
136 		return -EACCES;
137 
138 	conf->enable = bgx_conf.enable;
139 	conf->promisc = bgx_conf.promisc;
140 	conf->bpen = bgx_conf.bpen;
141 	conf->node = bgx_conf.node;
142 	conf->base_chan = bgx_conf.base_chan;
143 	conf->num_chans = bgx_conf.num_chans;
144 	conf->mtu = bgx_conf.mtu;
145 	conf->bgx = bgx_conf.bgx;
146 	conf->lmac = bgx_conf.lmac;
147 	conf->mode = bgx_conf.mode;
148 	conf->pkind = bgx_conf.pkind;
149 	memcpy(conf->macaddr, bgx_conf.macaddr, 6);
150 
151 	return res;
152 }
153 
154 int
155 octeontx_bgx_port_status(int port, octeontx_mbox_bgx_port_status_t *stat)
156 {
157 	struct octeontx_mbox_hdr hdr;
158 	octeontx_mbox_bgx_port_status_t bgx_stat;
159 	int len = sizeof(octeontx_mbox_bgx_port_status_t);
160 	int res;
161 
162 	hdr.coproc = OCTEONTX_BGX_COPROC;
163 	hdr.msg = MBOX_BGX_PORT_GET_STATUS;
164 	hdr.vfid = port;
165 
166 	res = octeontx_ssovf_mbox_send(&hdr, NULL, 0, &bgx_stat, len);
167 	if (res < 0)
168 		return -EACCES;
169 
170 	stat->link_up = bgx_stat.link_up;
171 
172 	return res;
173 }
174 
175 int
176 octeontx_bgx_port_stats(int port, octeontx_mbox_bgx_port_stats_t *stats)
177 {
178 	struct octeontx_mbox_hdr hdr;
179 	octeontx_mbox_bgx_port_stats_t bgx_stats;
180 	int len = sizeof(octeontx_mbox_bgx_port_stats_t);
181 	int res;
182 
183 	hdr.coproc = OCTEONTX_BGX_COPROC;
184 	hdr.msg = MBOX_BGX_PORT_GET_STATS;
185 	hdr.vfid = port;
186 
187 	res = octeontx_ssovf_mbox_send(&hdr, NULL, 0, &bgx_stats, len);
188 	if (res < 0)
189 		return -EACCES;
190 
191 	stats->rx_packets = bgx_stats.rx_packets;
192 	stats->rx_bytes = bgx_stats.rx_bytes;
193 	stats->rx_dropped = bgx_stats.rx_dropped;
194 	stats->rx_errors = bgx_stats.rx_errors;
195 	stats->tx_packets = bgx_stats.tx_packets;
196 	stats->tx_bytes = bgx_stats.tx_bytes;
197 	stats->tx_dropped = bgx_stats.tx_dropped;
198 	stats->tx_errors = bgx_stats.tx_errors;
199 	return res;
200 }
201 
202 int
203 octeontx_bgx_port_stats_clr(int port)
204 {
205 	struct octeontx_mbox_hdr hdr;
206 	int res;
207 
208 	hdr.coproc = OCTEONTX_BGX_COPROC;
209 	hdr.msg = MBOX_BGX_PORT_CLR_STATS;
210 	hdr.vfid = port;
211 
212 	res = octeontx_ssovf_mbox_send(&hdr, NULL, 0, NULL, 0);
213 	if (res < 0)
214 		return -EACCES;
215 
216 	return res;
217 }
218 
219 int
220 octeontx_bgx_port_link_status(int port)
221 {
222 	struct octeontx_mbox_hdr hdr;
223 	uint8_t link;
224 	int len = sizeof(uint8_t);
225 	int res;
226 
227 	hdr.coproc = OCTEONTX_BGX_COPROC;
228 	hdr.msg = MBOX_BGX_PORT_GET_LINK_STATUS;
229 	hdr.vfid = port;
230 
231 	res = octeontx_ssovf_mbox_send(&hdr, NULL, 0, &link, len);
232 	if (res < 0)
233 		return -EACCES;
234 
235 	return link;
236 }
237 
238 int
239 octeontx_bgx_port_promisc_set(int port, int en)
240 {
241 	struct octeontx_mbox_hdr hdr;
242 	uint8_t	prom;
243 	int res;
244 
245 	hdr.coproc = OCTEONTX_BGX_COPROC;
246 	hdr.msg = MBOX_BGX_PORT_SET_PROMISC;
247 	hdr.vfid = port;
248 	prom = en ? 1 : 0;
249 
250 	res = octeontx_ssovf_mbox_send(&hdr, &prom, sizeof(prom), NULL, 0);
251 	if (res < 0)
252 		return -EACCES;
253 
254 	return res;
255 }
256 
257 int
258 octeontx_bgx_port_mac_set(int port, uint8_t *mac_addr)
259 {
260 	struct octeontx_mbox_hdr hdr;
261 	int len = 6;
262 	int res = 0;
263 
264 	hdr.coproc = OCTEONTX_BGX_COPROC;
265 	hdr.msg = MBOX_BGX_PORT_SET_MACADDR;
266 	hdr.vfid = port;
267 
268 	res = octeontx_ssovf_mbox_send(&hdr, mac_addr, len, NULL, 0);
269 	if (res < 0)
270 		return -EACCES;
271 
272 	return res;
273 }
274