]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/dpdk/drivers/net/octeontx/base/octeontx_bgx.c
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / spdk / dpdk / drivers / net / octeontx / base / octeontx_bgx.c
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
9 int
10 octeontx_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
42 int
43 octeontx_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
59 int
60 octeontx_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
76 int
77 octeontx_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
93 int
94 octeontx_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
126 int
127 octeontx_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
147 int
148 octeontx_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
174 int
175 octeontx_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
191 int
192 octeontx_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
210 int
211 octeontx_bgx_port_promisc_set(int port, int en)
212 {
213 struct octeontx_mbox_hdr hdr;
214 uint8_t prom;
215 int res;
216
217 hdr.coproc = OCTEONTX_BGX_COPROC;
218 hdr.msg = MBOX_BGX_PORT_SET_PROMISC;
219 hdr.vfid = port;
220 prom = en ? 1 : 0;
221
222 res = octeontx_mbox_send(&hdr, &prom, sizeof(prom), NULL, 0);
223 if (res < 0)
224 return -EACCES;
225
226 return res;
227 }
228
229 int
230 octeontx_bgx_port_mac_set(int port, uint8_t *mac_addr)
231 {
232 struct octeontx_mbox_hdr hdr;
233 int len = 6;
234 int res = 0;
235
236 hdr.coproc = OCTEONTX_BGX_COPROC;
237 hdr.msg = MBOX_BGX_PORT_SET_MACADDR;
238 hdr.vfid = port;
239
240 res = octeontx_mbox_send(&hdr, mac_addr, len, NULL, 0);
241 if (res < 0)
242 return -EACCES;
243
244 return res;
245 }