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