1*4d027880SJerin Jacob /* 2*4d027880SJerin Jacob * BSD LICENSE 3*4d027880SJerin Jacob * 4*4d027880SJerin Jacob * Copyright (C) Cavium Inc. 2017. All rights reserved. 5*4d027880SJerin Jacob * 6*4d027880SJerin Jacob * Redistribution and use in source and binary forms, with or without 7*4d027880SJerin Jacob * modification, are permitted provided that the following conditions 8*4d027880SJerin Jacob * are met: 9*4d027880SJerin Jacob * 10*4d027880SJerin Jacob * * Redistributions of source code must retain the above copyright 11*4d027880SJerin Jacob * notice, this list of conditions and the following disclaimer. 12*4d027880SJerin Jacob * * Redistributions in binary form must reproduce the above copyright 13*4d027880SJerin Jacob * notice, this list of conditions and the following disclaimer in 14*4d027880SJerin Jacob * the documentation and/or other materials provided with the 15*4d027880SJerin Jacob * distribution. 16*4d027880SJerin Jacob * * Neither the name of Cavium networks nor the names of its 17*4d027880SJerin Jacob * contributors may be used to endorse or promote products derived 18*4d027880SJerin Jacob * from this software without specific prior written permission. 19*4d027880SJerin Jacob * 20*4d027880SJerin Jacob * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21*4d027880SJerin Jacob * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22*4d027880SJerin Jacob * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23*4d027880SJerin Jacob * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24*4d027880SJerin Jacob * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25*4d027880SJerin Jacob * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26*4d027880SJerin Jacob * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27*4d027880SJerin Jacob * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28*4d027880SJerin Jacob * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29*4d027880SJerin Jacob * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30*4d027880SJerin Jacob * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31*4d027880SJerin Jacob */ 32*4d027880SJerin Jacob 33*4d027880SJerin Jacob #include <string.h> 34*4d027880SJerin Jacob 35*4d027880SJerin Jacob #include "octeontx_bgx.h" 36*4d027880SJerin Jacob 37*4d027880SJerin Jacob int 38*4d027880SJerin Jacob octeontx_bgx_port_open(int port, octeontx_mbox_bgx_port_conf_t *conf) 39*4d027880SJerin Jacob { 40*4d027880SJerin Jacob struct octeontx_mbox_hdr hdr; 41*4d027880SJerin Jacob octeontx_mbox_bgx_port_conf_t bgx_conf; 42*4d027880SJerin Jacob int len = sizeof(octeontx_mbox_bgx_port_conf_t); 43*4d027880SJerin Jacob int res; 44*4d027880SJerin Jacob 45*4d027880SJerin Jacob memset(&bgx_conf, 0, sizeof(octeontx_mbox_bgx_port_conf_t)); 46*4d027880SJerin Jacob hdr.coproc = OCTEONTX_BGX_COPROC; 47*4d027880SJerin Jacob hdr.msg = MBOX_BGX_PORT_OPEN; 48*4d027880SJerin Jacob hdr.vfid = port; 49*4d027880SJerin Jacob 50*4d027880SJerin Jacob res = octeontx_ssovf_mbox_send(&hdr, NULL, 0, &bgx_conf, len); 51*4d027880SJerin Jacob if (res < 0) 52*4d027880SJerin Jacob return -EACCES; 53*4d027880SJerin Jacob 54*4d027880SJerin Jacob conf->enable = bgx_conf.enable; 55*4d027880SJerin Jacob conf->promisc = bgx_conf.promisc; 56*4d027880SJerin Jacob conf->bpen = bgx_conf.bpen; 57*4d027880SJerin Jacob conf->node = bgx_conf.node; 58*4d027880SJerin Jacob conf->base_chan = bgx_conf.base_chan; 59*4d027880SJerin Jacob conf->num_chans = bgx_conf.num_chans; 60*4d027880SJerin Jacob conf->mtu = bgx_conf.mtu; 61*4d027880SJerin Jacob conf->bgx = bgx_conf.bgx; 62*4d027880SJerin Jacob conf->lmac = bgx_conf.lmac; 63*4d027880SJerin Jacob conf->mode = bgx_conf.mode; 64*4d027880SJerin Jacob conf->pkind = bgx_conf.pkind; 65*4d027880SJerin Jacob memcpy(conf->macaddr, bgx_conf.macaddr, 6); 66*4d027880SJerin Jacob 67*4d027880SJerin Jacob return res; 68*4d027880SJerin Jacob } 69*4d027880SJerin Jacob 70*4d027880SJerin Jacob int 71*4d027880SJerin Jacob octeontx_bgx_port_close(int port) 72*4d027880SJerin Jacob { 73*4d027880SJerin Jacob struct octeontx_mbox_hdr hdr; 74*4d027880SJerin Jacob int res; 75*4d027880SJerin Jacob 76*4d027880SJerin Jacob hdr.coproc = OCTEONTX_BGX_COPROC; 77*4d027880SJerin Jacob hdr.msg = MBOX_BGX_PORT_CLOSE; 78*4d027880SJerin Jacob hdr.vfid = port; 79*4d027880SJerin Jacob 80*4d027880SJerin Jacob res = octeontx_ssovf_mbox_send(&hdr, NULL, 0, NULL, 0); 81*4d027880SJerin Jacob if (res < 0) 82*4d027880SJerin Jacob return -EACCES; 83*4d027880SJerin Jacob 84*4d027880SJerin Jacob return res; 85*4d027880SJerin Jacob } 86*4d027880SJerin Jacob 87*4d027880SJerin Jacob int 88*4d027880SJerin Jacob octeontx_bgx_port_start(int port) 89*4d027880SJerin Jacob { 90*4d027880SJerin Jacob struct octeontx_mbox_hdr hdr; 91*4d027880SJerin Jacob int res; 92*4d027880SJerin Jacob 93*4d027880SJerin Jacob hdr.coproc = OCTEONTX_BGX_COPROC; 94*4d027880SJerin Jacob hdr.msg = MBOX_BGX_PORT_START; 95*4d027880SJerin Jacob hdr.vfid = port; 96*4d027880SJerin Jacob 97*4d027880SJerin Jacob res = octeontx_ssovf_mbox_send(&hdr, NULL, 0, NULL, 0); 98*4d027880SJerin Jacob if (res < 0) 99*4d027880SJerin Jacob return -EACCES; 100*4d027880SJerin Jacob 101*4d027880SJerin Jacob return res; 102*4d027880SJerin Jacob } 103*4d027880SJerin Jacob 104*4d027880SJerin Jacob int 105*4d027880SJerin Jacob octeontx_bgx_port_stop(int port) 106*4d027880SJerin Jacob { 107*4d027880SJerin Jacob struct octeontx_mbox_hdr hdr; 108*4d027880SJerin Jacob int res; 109*4d027880SJerin Jacob 110*4d027880SJerin Jacob hdr.coproc = OCTEONTX_BGX_COPROC; 111*4d027880SJerin Jacob hdr.msg = MBOX_BGX_PORT_STOP; 112*4d027880SJerin Jacob hdr.vfid = port; 113*4d027880SJerin Jacob 114*4d027880SJerin Jacob res = octeontx_ssovf_mbox_send(&hdr, NULL, 0, NULL, 0); 115*4d027880SJerin Jacob if (res < 0) 116*4d027880SJerin Jacob return -EACCES; 117*4d027880SJerin Jacob 118*4d027880SJerin Jacob return res; 119*4d027880SJerin Jacob } 120