1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Cavium, Inc
7 #include "octeontx_bgx.h"
10 octeontx_bgx_port_open(int port
, octeontx_mbox_bgx_port_conf_t
*conf
)
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
);
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
;
22 res
= octeontx_mbox_send(&hdr
, NULL
, 0, &bgx_conf
, len
);
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);
43 octeontx_bgx_port_close(int port
)
45 struct octeontx_mbox_hdr hdr
;
48 hdr
.coproc
= OCTEONTX_BGX_COPROC
;
49 hdr
.msg
= MBOX_BGX_PORT_CLOSE
;
52 res
= octeontx_mbox_send(&hdr
, NULL
, 0, NULL
, 0);
60 octeontx_bgx_port_start(int port
)
62 struct octeontx_mbox_hdr hdr
;
65 hdr
.coproc
= OCTEONTX_BGX_COPROC
;
66 hdr
.msg
= MBOX_BGX_PORT_START
;
69 res
= octeontx_mbox_send(&hdr
, NULL
, 0, NULL
, 0);
77 octeontx_bgx_port_stop(int port
)
79 struct octeontx_mbox_hdr hdr
;
82 hdr
.coproc
= OCTEONTX_BGX_COPROC
;
83 hdr
.msg
= MBOX_BGX_PORT_STOP
;
86 res
= octeontx_mbox_send(&hdr
, NULL
, 0, NULL
, 0);
94 octeontx_bgx_port_get_config(int port
, octeontx_mbox_bgx_port_conf_t
*conf
)
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
);
101 hdr
.coproc
= OCTEONTX_BGX_COPROC
;
102 hdr
.msg
= MBOX_BGX_PORT_GET_CONFIG
;
105 memset(&bgx_conf
, 0, sizeof(octeontx_mbox_bgx_port_conf_t
));
106 res
= octeontx_mbox_send(&hdr
, NULL
, 0, &bgx_conf
, len
);
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);
127 octeontx_bgx_port_status(int port
, octeontx_mbox_bgx_port_status_t
*stat
)
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
);
134 hdr
.coproc
= OCTEONTX_BGX_COPROC
;
135 hdr
.msg
= MBOX_BGX_PORT_GET_STATUS
;
138 res
= octeontx_mbox_send(&hdr
, NULL
, 0, &bgx_stat
, len
);
142 stat
->link_up
= bgx_stat
.link_up
;
148 octeontx_bgx_port_stats(int port
, octeontx_mbox_bgx_port_stats_t
*stats
)
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
);
155 hdr
.coproc
= OCTEONTX_BGX_COPROC
;
156 hdr
.msg
= MBOX_BGX_PORT_GET_STATS
;
159 res
= octeontx_mbox_send(&hdr
, NULL
, 0, &bgx_stats
, len
);
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
;
175 octeontx_bgx_port_stats_clr(int port
)
177 struct octeontx_mbox_hdr hdr
;
180 hdr
.coproc
= OCTEONTX_BGX_COPROC
;
181 hdr
.msg
= MBOX_BGX_PORT_CLR_STATS
;
184 res
= octeontx_mbox_send(&hdr
, NULL
, 0, NULL
, 0);
192 octeontx_bgx_port_link_status(int port
)
194 struct octeontx_mbox_hdr hdr
;
196 int len
= sizeof(uint8_t);
199 hdr
.coproc
= OCTEONTX_BGX_COPROC
;
200 hdr
.msg
= MBOX_BGX_PORT_GET_LINK_STATUS
;
203 res
= octeontx_mbox_send(&hdr
, NULL
, 0, &link
, len
);
211 octeontx_bgx_port_promisc_set(int port
, int en
)
213 struct octeontx_mbox_hdr hdr
;
217 hdr
.coproc
= OCTEONTX_BGX_COPROC
;
218 hdr
.msg
= MBOX_BGX_PORT_SET_PROMISC
;
222 res
= octeontx_mbox_send(&hdr
, &prom
, sizeof(prom
), NULL
, 0);
230 octeontx_bgx_port_mac_set(int port
, uint8_t *mac_addr
)
232 struct octeontx_mbox_hdr hdr
;
236 hdr
.coproc
= OCTEONTX_BGX_COPROC
;
237 hdr
.msg
= MBOX_BGX_PORT_SET_MACADDR
;
240 res
= octeontx_mbox_send(&hdr
, mac_addr
, len
, NULL
, 0);