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