]> git.proxmox.com Git - ceph.git/blame - ceph/src/spdk/dpdk/drivers/net/octeontx/base/octeontx_bgx.c
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / spdk / dpdk / drivers / net / octeontx / base / octeontx_bgx.c
CommitLineData
11fdf7f2
TL
1/* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Cavium, Inc
3 */
4
5#include <string.h>
6
7#include "octeontx_bgx.h"
8
9int
10octeontx_bgx_port_open(int port, octeontx_mbox_bgx_port_conf_t *conf)
11{
12 struct octeontx_mbox_hdr hdr;
13 octeontx_mbox_bgx_port_conf_t bgx_conf;
14 int len = sizeof(octeontx_mbox_bgx_port_conf_t);
15 int res;
16
17 memset(&bgx_conf, 0, sizeof(octeontx_mbox_bgx_port_conf_t));
18 hdr.coproc = OCTEONTX_BGX_COPROC;
19 hdr.msg = MBOX_BGX_PORT_OPEN;
20 hdr.vfid = port;
21
22 res = octeontx_mbox_send(&hdr, NULL, 0, &bgx_conf, len);
23 if (res < 0)
24 return -EACCES;
25
26 conf->enable = bgx_conf.enable;
27 conf->promisc = bgx_conf.promisc;
28 conf->bpen = bgx_conf.bpen;
29 conf->node = bgx_conf.node;
30 conf->base_chan = bgx_conf.base_chan;
31 conf->num_chans = bgx_conf.num_chans;
32 conf->mtu = bgx_conf.mtu;
33 conf->bgx = bgx_conf.bgx;
34 conf->lmac = bgx_conf.lmac;
35 conf->mode = bgx_conf.mode;
36 conf->pkind = bgx_conf.pkind;
37 memcpy(conf->macaddr, bgx_conf.macaddr, 6);
38
39 return res;
40}
41
42int
43octeontx_bgx_port_close(int port)
44{
45 struct octeontx_mbox_hdr hdr;
46 int res;
47
48 hdr.coproc = OCTEONTX_BGX_COPROC;
49 hdr.msg = MBOX_BGX_PORT_CLOSE;
50 hdr.vfid = port;
51
52 res = octeontx_mbox_send(&hdr, NULL, 0, NULL, 0);
53 if (res < 0)
54 return -EACCES;
55
56 return res;
57}
58
59int
60octeontx_bgx_port_start(int port)
61{
62 struct octeontx_mbox_hdr hdr;
63 int res;
64
65 hdr.coproc = OCTEONTX_BGX_COPROC;
66 hdr.msg = MBOX_BGX_PORT_START;
67 hdr.vfid = port;
68
69 res = octeontx_mbox_send(&hdr, NULL, 0, NULL, 0);
70 if (res < 0)
71 return -EACCES;
72
73 return res;
74}
75
76int
77octeontx_bgx_port_stop(int port)
78{
79 struct octeontx_mbox_hdr hdr;
80 int res;
81
82 hdr.coproc = OCTEONTX_BGX_COPROC;
83 hdr.msg = MBOX_BGX_PORT_STOP;
84 hdr.vfid = port;
85
86 res = octeontx_mbox_send(&hdr, NULL, 0, NULL, 0);
87 if (res < 0)
88 return -EACCES;
89
90 return res;
91}
92
93int
94octeontx_bgx_port_get_config(int port, octeontx_mbox_bgx_port_conf_t *conf)
95{
96 struct octeontx_mbox_hdr hdr;
97 octeontx_mbox_bgx_port_conf_t bgx_conf;
98 int len = sizeof(octeontx_mbox_bgx_port_conf_t);
99 int res;
100
101 hdr.coproc = OCTEONTX_BGX_COPROC;
102 hdr.msg = MBOX_BGX_PORT_GET_CONFIG;
103 hdr.vfid = port;
104
105 memset(&bgx_conf, 0, sizeof(octeontx_mbox_bgx_port_conf_t));
106 res = octeontx_mbox_send(&hdr, NULL, 0, &bgx_conf, len);
107 if (res < 0)
108 return -EACCES;
109
110 conf->enable = bgx_conf.enable;
111 conf->promisc = bgx_conf.promisc;
112 conf->bpen = bgx_conf.bpen;
113 conf->node = bgx_conf.node;
114 conf->base_chan = bgx_conf.base_chan;
115 conf->num_chans = bgx_conf.num_chans;
116 conf->mtu = bgx_conf.mtu;
117 conf->bgx = bgx_conf.bgx;
118 conf->lmac = bgx_conf.lmac;
119 conf->mode = bgx_conf.mode;
120 conf->pkind = bgx_conf.pkind;
121 memcpy(conf->macaddr, bgx_conf.macaddr, 6);
122
123 return res;
124}
125
126int
127octeontx_bgx_port_status(int port, octeontx_mbox_bgx_port_status_t *stat)
128{
129 struct octeontx_mbox_hdr hdr;
130 octeontx_mbox_bgx_port_status_t bgx_stat;
131 int len = sizeof(octeontx_mbox_bgx_port_status_t);
132 int res;
133
134 hdr.coproc = OCTEONTX_BGX_COPROC;
135 hdr.msg = MBOX_BGX_PORT_GET_STATUS;
136 hdr.vfid = port;
137
138 res = octeontx_mbox_send(&hdr, NULL, 0, &bgx_stat, len);
139 if (res < 0)
140 return -EACCES;
141
142 stat->link_up = bgx_stat.link_up;
143
144 return res;
145}
146
147int
148octeontx_bgx_port_stats(int port, octeontx_mbox_bgx_port_stats_t *stats)
149{
150 struct octeontx_mbox_hdr hdr;
151 octeontx_mbox_bgx_port_stats_t bgx_stats;
152 int len = sizeof(octeontx_mbox_bgx_port_stats_t);
153 int res;
154
155 hdr.coproc = OCTEONTX_BGX_COPROC;
156 hdr.msg = MBOX_BGX_PORT_GET_STATS;
157 hdr.vfid = port;
158
159 res = octeontx_mbox_send(&hdr, NULL, 0, &bgx_stats, len);
160 if (res < 0)
161 return -EACCES;
162
163 stats->rx_packets = bgx_stats.rx_packets;
164 stats->rx_bytes = bgx_stats.rx_bytes;
165 stats->rx_dropped = bgx_stats.rx_dropped;
166 stats->rx_errors = bgx_stats.rx_errors;
167 stats->tx_packets = bgx_stats.tx_packets;
168 stats->tx_bytes = bgx_stats.tx_bytes;
169 stats->tx_dropped = bgx_stats.tx_dropped;
170 stats->tx_errors = bgx_stats.tx_errors;
171 return res;
172}
173
174int
175octeontx_bgx_port_stats_clr(int port)
176{
177 struct octeontx_mbox_hdr hdr;
178 int res;
179
180 hdr.coproc = OCTEONTX_BGX_COPROC;
181 hdr.msg = MBOX_BGX_PORT_CLR_STATS;
182 hdr.vfid = port;
183
184 res = octeontx_mbox_send(&hdr, NULL, 0, NULL, 0);
185 if (res < 0)
186 return -EACCES;
187
188 return res;
189}
190
191int
192octeontx_bgx_port_link_status(int port)
193{
194 struct octeontx_mbox_hdr hdr;
195 uint8_t link;
196 int len = sizeof(uint8_t);
197 int res;
198
199 hdr.coproc = OCTEONTX_BGX_COPROC;
200 hdr.msg = MBOX_BGX_PORT_GET_LINK_STATUS;
201 hdr.vfid = port;
202
203 res = octeontx_mbox_send(&hdr, NULL, 0, &link, len);
204 if (res < 0)
205 return -EACCES;
206
207 return link;
208}
209
f67539c2
TL
210int
211octeontx_bgx_port_set_link_state(int port, bool enable)
212{
213 struct octeontx_mbox_hdr hdr;
214
215 hdr.coproc = OCTEONTX_BGX_COPROC;
216 hdr.msg = MBOX_BGX_PORT_SET_LINK_STATE;
217 hdr.vfid = port;
218
219 return octeontx_mbox_send(&hdr, &enable, sizeof(bool), NULL, 0);
220}
221
11fdf7f2
TL
222int
223octeontx_bgx_port_promisc_set(int port, int en)
224{
225 struct octeontx_mbox_hdr hdr;
226 uint8_t prom;
227 int res;
228
229 hdr.coproc = OCTEONTX_BGX_COPROC;
230 hdr.msg = MBOX_BGX_PORT_SET_PROMISC;
231 hdr.vfid = port;
232 prom = en ? 1 : 0;
233
234 res = octeontx_mbox_send(&hdr, &prom, sizeof(prom), NULL, 0);
235 if (res < 0)
236 return -EACCES;
237
238 return res;
239}
240
f67539c2
TL
241int
242octeontx_bgx_port_mtu_set(int port, int mtu)
243{
244 struct octeontx_mbox_hdr hdr;
245 int res;
246
247 hdr.coproc = OCTEONTX_BGX_COPROC;
248 hdr.msg = MBOX_BGX_PORT_SET_MTU;
249 hdr.vfid = port;
250
251 res = octeontx_mbox_send(&hdr, &mtu, sizeof(mtu), NULL, 0);
252 if (res < 0)
253 return -EACCES;
254
255 return res;
256}
257
11fdf7f2
TL
258int
259octeontx_bgx_port_mac_set(int port, uint8_t *mac_addr)
260{
261 struct octeontx_mbox_hdr hdr;
262 int len = 6;
263 int res = 0;
264
265 hdr.coproc = OCTEONTX_BGX_COPROC;
266 hdr.msg = MBOX_BGX_PORT_SET_MACADDR;
267 hdr.vfid = port;
268
269 res = octeontx_mbox_send(&hdr, mac_addr, len, NULL, 0);
270 if (res < 0)
271 return -EACCES;
272
273 return res;
274}
f67539c2
TL
275
276int
277octeontx_bgx_port_mac_add(int port, uint8_t *mac_addr, int index)
278{
279 struct octeontx_mbox_bgx_port_mac_filter filter;
280 struct octeontx_mbox_hdr hdr;
281 int len = 6;
282
283 hdr.coproc = OCTEONTX_BGX_COPROC;
284 hdr.msg = MBOX_BGX_PORT_ADD_MACADDR;
285 hdr.vfid = port;
286
287 memcpy(filter.mac_addr, mac_addr, len);
288 filter.index = index;
289 len = sizeof(struct octeontx_mbox_bgx_port_mac_filter);
290
291 return octeontx_mbox_send(&hdr, &filter, len, NULL, 0);
292}
293
294int
295octeontx_bgx_port_mac_del(int port, uint32_t index)
296{
297 struct octeontx_mbox_hdr hdr;
298 int len = sizeof(uint32_t);
299 int res = 0;
300
301 hdr.coproc = OCTEONTX_BGX_COPROC;
302 hdr.msg = MBOX_BGX_PORT_DEL_MACADDR;
303 hdr.vfid = port;
304
305 res = octeontx_mbox_send(&hdr, &index, len, NULL, 0);
306 if (res < 0)
307 return -EACCES;
308
309 return res;
310}
311
312int
313octeontx_bgx_port_mac_entries_get(int port)
314{
315 struct octeontx_mbox_hdr hdr;
316 int resp = 6;
317 int res = 0;
318
319 hdr.coproc = OCTEONTX_BGX_COPROC;
320 hdr.msg = MBOX_BGX_PORT_GET_MACADDR_ENTRIES;
321 hdr.vfid = port;
322
323 res = octeontx_mbox_send(&hdr, NULL, 0, &resp, sizeof(int));
324 if (res < 0)
325 return -EACCES;
326
327 return resp;
328}
329
330int octeontx_bgx_port_get_fifo_cfg(int port,
331 octeontx_mbox_bgx_port_fifo_cfg_t *cfg)
332{
333 int len = sizeof(octeontx_mbox_bgx_port_fifo_cfg_t);
334 octeontx_mbox_bgx_port_fifo_cfg_t conf;
335 struct octeontx_mbox_hdr hdr;
336
337 hdr.coproc = OCTEONTX_BGX_COPROC;
338 hdr.msg = MBOX_BGX_PORT_GET_FIFO_CFG;
339 hdr.vfid = port;
340
341 if (octeontx_mbox_send(&hdr, NULL, 0, &conf, len) < 0)
342 return -EACCES;
343
344 cfg->rx_fifosz = conf.rx_fifosz;
345
346 return 0;
347}
348
349int octeontx_bgx_port_flow_ctrl_cfg(int port,
350 octeontx_mbox_bgx_port_fc_cfg_t *cfg)
351{
352 int len = sizeof(octeontx_mbox_bgx_port_fc_cfg_t);
353 octeontx_mbox_bgx_port_fc_cfg_t conf;
354 struct octeontx_mbox_hdr hdr;
355
356 hdr.coproc = OCTEONTX_BGX_COPROC;
357 hdr.msg = MBOX_BGX_PORT_FLOW_CTRL_CFG;
358 hdr.vfid = port;
359
360 if (cfg->fc_cfg == BGX_PORT_FC_CFG_SET)
361 memcpy(&conf, cfg, len);
362 else
363 memset(&conf, 0, len);
364
365 if (octeontx_mbox_send(&hdr, &conf, len, &conf, len) < 0)
366 return -EACCES;
367
368 if (cfg->fc_cfg == BGX_PORT_FC_CFG_SET)
369 goto done;
370
371 cfg->rx_pause = conf.rx_pause;
372 cfg->tx_pause = conf.tx_pause;
373 cfg->low_water = conf.low_water;
374 cfg->high_water = conf.high_water;
375
376done:
377 return 0;
378}