14d027880SJerin Jacob /* 24d027880SJerin Jacob * BSD LICENSE 34d027880SJerin Jacob * 44d027880SJerin Jacob * Copyright (C) Cavium Inc. 2017. All rights reserved. 54d027880SJerin Jacob * 64d027880SJerin Jacob * Redistribution and use in source and binary forms, with or without 74d027880SJerin Jacob * modification, are permitted provided that the following conditions 84d027880SJerin Jacob * are met: 94d027880SJerin Jacob * 104d027880SJerin Jacob * * Redistributions of source code must retain the above copyright 114d027880SJerin Jacob * notice, this list of conditions and the following disclaimer. 124d027880SJerin Jacob * * Redistributions in binary form must reproduce the above copyright 134d027880SJerin Jacob * notice, this list of conditions and the following disclaimer in 144d027880SJerin Jacob * the documentation and/or other materials provided with the 154d027880SJerin Jacob * distribution. 164d027880SJerin Jacob * * Neither the name of Cavium networks nor the names of its 174d027880SJerin Jacob * contributors may be used to endorse or promote products derived 184d027880SJerin Jacob * from this software without specific prior written permission. 194d027880SJerin Jacob * 204d027880SJerin Jacob * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 214d027880SJerin Jacob * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 224d027880SJerin Jacob * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 234d027880SJerin Jacob * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 244d027880SJerin Jacob * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 254d027880SJerin Jacob * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 264d027880SJerin Jacob * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 274d027880SJerin Jacob * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 284d027880SJerin Jacob * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 294d027880SJerin Jacob * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 304d027880SJerin Jacob * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 314d027880SJerin Jacob */ 324d027880SJerin Jacob 334d027880SJerin Jacob #include <string.h> 344d027880SJerin Jacob 354d027880SJerin Jacob #include "octeontx_bgx.h" 364d027880SJerin Jacob 374d027880SJerin Jacob int 384d027880SJerin Jacob octeontx_bgx_port_open(int port, octeontx_mbox_bgx_port_conf_t *conf) 394d027880SJerin Jacob { 404d027880SJerin Jacob struct octeontx_mbox_hdr hdr; 414d027880SJerin Jacob octeontx_mbox_bgx_port_conf_t bgx_conf; 424d027880SJerin Jacob int len = sizeof(octeontx_mbox_bgx_port_conf_t); 434d027880SJerin Jacob int res; 444d027880SJerin Jacob 454d027880SJerin Jacob memset(&bgx_conf, 0, sizeof(octeontx_mbox_bgx_port_conf_t)); 464d027880SJerin Jacob hdr.coproc = OCTEONTX_BGX_COPROC; 474d027880SJerin Jacob hdr.msg = MBOX_BGX_PORT_OPEN; 484d027880SJerin Jacob hdr.vfid = port; 494d027880SJerin Jacob 504d027880SJerin Jacob res = octeontx_ssovf_mbox_send(&hdr, NULL, 0, &bgx_conf, len); 514d027880SJerin Jacob if (res < 0) 524d027880SJerin Jacob return -EACCES; 534d027880SJerin Jacob 544d027880SJerin Jacob conf->enable = bgx_conf.enable; 554d027880SJerin Jacob conf->promisc = bgx_conf.promisc; 564d027880SJerin Jacob conf->bpen = bgx_conf.bpen; 574d027880SJerin Jacob conf->node = bgx_conf.node; 584d027880SJerin Jacob conf->base_chan = bgx_conf.base_chan; 594d027880SJerin Jacob conf->num_chans = bgx_conf.num_chans; 604d027880SJerin Jacob conf->mtu = bgx_conf.mtu; 614d027880SJerin Jacob conf->bgx = bgx_conf.bgx; 624d027880SJerin Jacob conf->lmac = bgx_conf.lmac; 634d027880SJerin Jacob conf->mode = bgx_conf.mode; 644d027880SJerin Jacob conf->pkind = bgx_conf.pkind; 654d027880SJerin Jacob memcpy(conf->macaddr, bgx_conf.macaddr, 6); 664d027880SJerin Jacob 674d027880SJerin Jacob return res; 684d027880SJerin Jacob } 694d027880SJerin Jacob 704d027880SJerin Jacob int 714d027880SJerin Jacob octeontx_bgx_port_close(int port) 724d027880SJerin Jacob { 734d027880SJerin Jacob struct octeontx_mbox_hdr hdr; 744d027880SJerin Jacob int res; 754d027880SJerin Jacob 764d027880SJerin Jacob hdr.coproc = OCTEONTX_BGX_COPROC; 774d027880SJerin Jacob hdr.msg = MBOX_BGX_PORT_CLOSE; 784d027880SJerin Jacob hdr.vfid = port; 794d027880SJerin Jacob 804d027880SJerin Jacob res = octeontx_ssovf_mbox_send(&hdr, NULL, 0, NULL, 0); 814d027880SJerin Jacob if (res < 0) 824d027880SJerin Jacob return -EACCES; 834d027880SJerin Jacob 844d027880SJerin Jacob return res; 854d027880SJerin Jacob } 864d027880SJerin Jacob 874d027880SJerin Jacob int 884d027880SJerin Jacob octeontx_bgx_port_start(int port) 894d027880SJerin Jacob { 904d027880SJerin Jacob struct octeontx_mbox_hdr hdr; 914d027880SJerin Jacob int res; 924d027880SJerin Jacob 934d027880SJerin Jacob hdr.coproc = OCTEONTX_BGX_COPROC; 944d027880SJerin Jacob hdr.msg = MBOX_BGX_PORT_START; 954d027880SJerin Jacob hdr.vfid = port; 964d027880SJerin Jacob 974d027880SJerin Jacob res = octeontx_ssovf_mbox_send(&hdr, NULL, 0, NULL, 0); 984d027880SJerin Jacob if (res < 0) 994d027880SJerin Jacob return -EACCES; 1004d027880SJerin Jacob 1014d027880SJerin Jacob return res; 1024d027880SJerin Jacob } 1034d027880SJerin Jacob 1044d027880SJerin Jacob int 1054d027880SJerin Jacob octeontx_bgx_port_stop(int port) 1064d027880SJerin Jacob { 1074d027880SJerin Jacob struct octeontx_mbox_hdr hdr; 1084d027880SJerin Jacob int res; 1094d027880SJerin Jacob 1104d027880SJerin Jacob hdr.coproc = OCTEONTX_BGX_COPROC; 1114d027880SJerin Jacob hdr.msg = MBOX_BGX_PORT_STOP; 1124d027880SJerin Jacob hdr.vfid = port; 1134d027880SJerin Jacob 1144d027880SJerin Jacob res = octeontx_ssovf_mbox_send(&hdr, NULL, 0, NULL, 0); 1154d027880SJerin Jacob if (res < 0) 1164d027880SJerin Jacob return -EACCES; 1174d027880SJerin Jacob 1184d027880SJerin Jacob return res; 1194d027880SJerin Jacob } 120*e242dd1cSJerin Jacob 121*e242dd1cSJerin Jacob int 122*e242dd1cSJerin Jacob octeontx_bgx_port_get_config(int port, octeontx_mbox_bgx_port_conf_t *conf) 123*e242dd1cSJerin Jacob { 124*e242dd1cSJerin Jacob struct octeontx_mbox_hdr hdr; 125*e242dd1cSJerin Jacob octeontx_mbox_bgx_port_conf_t bgx_conf; 126*e242dd1cSJerin Jacob int len = sizeof(octeontx_mbox_bgx_port_conf_t); 127*e242dd1cSJerin Jacob int res; 128*e242dd1cSJerin Jacob 129*e242dd1cSJerin Jacob hdr.coproc = OCTEONTX_BGX_COPROC; 130*e242dd1cSJerin Jacob hdr.msg = MBOX_BGX_PORT_GET_CONFIG; 131*e242dd1cSJerin Jacob hdr.vfid = port; 132*e242dd1cSJerin Jacob 133*e242dd1cSJerin Jacob memset(&bgx_conf, 0, sizeof(octeontx_mbox_bgx_port_conf_t)); 134*e242dd1cSJerin Jacob res = octeontx_ssovf_mbox_send(&hdr, NULL, 0, &bgx_conf, len); 135*e242dd1cSJerin Jacob if (res < 0) 136*e242dd1cSJerin Jacob return -EACCES; 137*e242dd1cSJerin Jacob 138*e242dd1cSJerin Jacob conf->enable = bgx_conf.enable; 139*e242dd1cSJerin Jacob conf->promisc = bgx_conf.promisc; 140*e242dd1cSJerin Jacob conf->bpen = bgx_conf.bpen; 141*e242dd1cSJerin Jacob conf->node = bgx_conf.node; 142*e242dd1cSJerin Jacob conf->base_chan = bgx_conf.base_chan; 143*e242dd1cSJerin Jacob conf->num_chans = bgx_conf.num_chans; 144*e242dd1cSJerin Jacob conf->mtu = bgx_conf.mtu; 145*e242dd1cSJerin Jacob conf->bgx = bgx_conf.bgx; 146*e242dd1cSJerin Jacob conf->lmac = bgx_conf.lmac; 147*e242dd1cSJerin Jacob conf->mode = bgx_conf.mode; 148*e242dd1cSJerin Jacob conf->pkind = bgx_conf.pkind; 149*e242dd1cSJerin Jacob memcpy(conf->macaddr, bgx_conf.macaddr, 6); 150*e242dd1cSJerin Jacob 151*e242dd1cSJerin Jacob return res; 152*e242dd1cSJerin Jacob } 153*e242dd1cSJerin Jacob 154*e242dd1cSJerin Jacob int 155*e242dd1cSJerin Jacob octeontx_bgx_port_status(int port, octeontx_mbox_bgx_port_status_t *stat) 156*e242dd1cSJerin Jacob { 157*e242dd1cSJerin Jacob struct octeontx_mbox_hdr hdr; 158*e242dd1cSJerin Jacob octeontx_mbox_bgx_port_status_t bgx_stat; 159*e242dd1cSJerin Jacob int len = sizeof(octeontx_mbox_bgx_port_status_t); 160*e242dd1cSJerin Jacob int res; 161*e242dd1cSJerin Jacob 162*e242dd1cSJerin Jacob hdr.coproc = OCTEONTX_BGX_COPROC; 163*e242dd1cSJerin Jacob hdr.msg = MBOX_BGX_PORT_GET_STATUS; 164*e242dd1cSJerin Jacob hdr.vfid = port; 165*e242dd1cSJerin Jacob 166*e242dd1cSJerin Jacob res = octeontx_ssovf_mbox_send(&hdr, NULL, 0, &bgx_stat, len); 167*e242dd1cSJerin Jacob if (res < 0) 168*e242dd1cSJerin Jacob return -EACCES; 169*e242dd1cSJerin Jacob 170*e242dd1cSJerin Jacob stat->link_up = bgx_stat.link_up; 171*e242dd1cSJerin Jacob 172*e242dd1cSJerin Jacob return res; 173*e242dd1cSJerin Jacob } 174*e242dd1cSJerin Jacob 175*e242dd1cSJerin Jacob int 176*e242dd1cSJerin Jacob octeontx_bgx_port_stats(int port, octeontx_mbox_bgx_port_stats_t *stats) 177*e242dd1cSJerin Jacob { 178*e242dd1cSJerin Jacob struct octeontx_mbox_hdr hdr; 179*e242dd1cSJerin Jacob octeontx_mbox_bgx_port_stats_t bgx_stats; 180*e242dd1cSJerin Jacob int len = sizeof(octeontx_mbox_bgx_port_stats_t); 181*e242dd1cSJerin Jacob int res; 182*e242dd1cSJerin Jacob 183*e242dd1cSJerin Jacob hdr.coproc = OCTEONTX_BGX_COPROC; 184*e242dd1cSJerin Jacob hdr.msg = MBOX_BGX_PORT_GET_STATS; 185*e242dd1cSJerin Jacob hdr.vfid = port; 186*e242dd1cSJerin Jacob 187*e242dd1cSJerin Jacob res = octeontx_ssovf_mbox_send(&hdr, NULL, 0, &bgx_stats, len); 188*e242dd1cSJerin Jacob if (res < 0) 189*e242dd1cSJerin Jacob return -EACCES; 190*e242dd1cSJerin Jacob 191*e242dd1cSJerin Jacob stats->rx_packets = bgx_stats.rx_packets; 192*e242dd1cSJerin Jacob stats->rx_bytes = bgx_stats.rx_bytes; 193*e242dd1cSJerin Jacob stats->rx_dropped = bgx_stats.rx_dropped; 194*e242dd1cSJerin Jacob stats->rx_errors = bgx_stats.rx_errors; 195*e242dd1cSJerin Jacob stats->tx_packets = bgx_stats.tx_packets; 196*e242dd1cSJerin Jacob stats->tx_bytes = bgx_stats.tx_bytes; 197*e242dd1cSJerin Jacob stats->tx_dropped = bgx_stats.tx_dropped; 198*e242dd1cSJerin Jacob stats->tx_errors = bgx_stats.tx_errors; 199*e242dd1cSJerin Jacob return res; 200*e242dd1cSJerin Jacob } 201*e242dd1cSJerin Jacob 202*e242dd1cSJerin Jacob int 203*e242dd1cSJerin Jacob octeontx_bgx_port_stats_clr(int port) 204*e242dd1cSJerin Jacob { 205*e242dd1cSJerin Jacob struct octeontx_mbox_hdr hdr; 206*e242dd1cSJerin Jacob int res; 207*e242dd1cSJerin Jacob 208*e242dd1cSJerin Jacob hdr.coproc = OCTEONTX_BGX_COPROC; 209*e242dd1cSJerin Jacob hdr.msg = MBOX_BGX_PORT_CLR_STATS; 210*e242dd1cSJerin Jacob hdr.vfid = port; 211*e242dd1cSJerin Jacob 212*e242dd1cSJerin Jacob res = octeontx_ssovf_mbox_send(&hdr, NULL, 0, NULL, 0); 213*e242dd1cSJerin Jacob if (res < 0) 214*e242dd1cSJerin Jacob return -EACCES; 215*e242dd1cSJerin Jacob 216*e242dd1cSJerin Jacob return res; 217*e242dd1cSJerin Jacob } 218*e242dd1cSJerin Jacob 219*e242dd1cSJerin Jacob int 220*e242dd1cSJerin Jacob octeontx_bgx_port_link_status(int port) 221*e242dd1cSJerin Jacob { 222*e242dd1cSJerin Jacob struct octeontx_mbox_hdr hdr; 223*e242dd1cSJerin Jacob uint8_t link; 224*e242dd1cSJerin Jacob int len = sizeof(uint8_t); 225*e242dd1cSJerin Jacob int res; 226*e242dd1cSJerin Jacob 227*e242dd1cSJerin Jacob hdr.coproc = OCTEONTX_BGX_COPROC; 228*e242dd1cSJerin Jacob hdr.msg = MBOX_BGX_PORT_GET_LINK_STATUS; 229*e242dd1cSJerin Jacob hdr.vfid = port; 230*e242dd1cSJerin Jacob 231*e242dd1cSJerin Jacob res = octeontx_ssovf_mbox_send(&hdr, NULL, 0, &link, len); 232*e242dd1cSJerin Jacob if (res < 0) 233*e242dd1cSJerin Jacob return -EACCES; 234*e242dd1cSJerin Jacob 235*e242dd1cSJerin Jacob return link; 236*e242dd1cSJerin Jacob } 237*e242dd1cSJerin Jacob 238*e242dd1cSJerin Jacob int 239*e242dd1cSJerin Jacob octeontx_bgx_port_promisc_set(int port, int en) 240*e242dd1cSJerin Jacob { 241*e242dd1cSJerin Jacob struct octeontx_mbox_hdr hdr; 242*e242dd1cSJerin Jacob uint8_t prom; 243*e242dd1cSJerin Jacob int res; 244*e242dd1cSJerin Jacob 245*e242dd1cSJerin Jacob hdr.coproc = OCTEONTX_BGX_COPROC; 246*e242dd1cSJerin Jacob hdr.msg = MBOX_BGX_PORT_SET_PROMISC; 247*e242dd1cSJerin Jacob hdr.vfid = port; 248*e242dd1cSJerin Jacob prom = en ? 1 : 0; 249*e242dd1cSJerin Jacob 250*e242dd1cSJerin Jacob res = octeontx_ssovf_mbox_send(&hdr, &prom, sizeof(prom), NULL, 0); 251*e242dd1cSJerin Jacob if (res < 0) 252*e242dd1cSJerin Jacob return -EACCES; 253*e242dd1cSJerin Jacob 254*e242dd1cSJerin Jacob return res; 255*e242dd1cSJerin Jacob } 256*e242dd1cSJerin Jacob 257*e242dd1cSJerin Jacob int 258*e242dd1cSJerin Jacob octeontx_bgx_port_mac_set(int port, uint8_t *mac_addr) 259*e242dd1cSJerin Jacob { 260*e242dd1cSJerin Jacob struct octeontx_mbox_hdr hdr; 261*e242dd1cSJerin Jacob int len = 6; 262*e242dd1cSJerin Jacob int res = 0; 263*e242dd1cSJerin Jacob 264*e242dd1cSJerin Jacob hdr.coproc = OCTEONTX_BGX_COPROC; 265*e242dd1cSJerin Jacob hdr.msg = MBOX_BGX_PORT_SET_MACADDR; 266*e242dd1cSJerin Jacob hdr.vfid = port; 267*e242dd1cSJerin Jacob 268*e242dd1cSJerin Jacob res = octeontx_ssovf_mbox_send(&hdr, mac_addr, len, NULL, 0); 269*e242dd1cSJerin Jacob if (res < 0) 270*e242dd1cSJerin Jacob return -EACCES; 271*e242dd1cSJerin Jacob 272*e242dd1cSJerin Jacob return res; 273*e242dd1cSJerin Jacob } 274