1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(C) 2020 Marvell International Ltd.
5 #include <rte_malloc.h>
7 #include "octeontx_ethdev.h"
8 #include "octeontx_logs.h"
9 #include "octeontx_rxtx.h"
12 octeontx_vlan_hw_filter(struct octeontx_nic *nic, uint8_t flag)
14 struct octeontx_vlan_info *vlan = &nic->vlan_info;
15 pki_port_vlan_filter_config_t fltr_conf;
18 if (vlan->filter_on == flag)
21 fltr_conf.port_type = OCTTX_PORT_TYPE_NET;
22 fltr_conf.fltr_conf = flag;
24 rc = octeontx_pki_port_vlan_fltr_config(nic->port_id, &fltr_conf);
26 octeontx_log_err("Fail to configure vlan hw filter for port %d",
31 vlan->filter_on = flag;
38 octeontx_dev_vlan_offload_set(struct rte_eth_dev *dev, int mask)
40 struct octeontx_nic *nic = octeontx_pmd_priv(dev);
41 struct rte_eth_rxmode *rxmode;
44 rxmode = &dev->data->dev_conf.rxmode;
46 if (mask & ETH_VLAN_FILTER_MASK) {
47 if (rxmode->offloads & DEV_RX_OFFLOAD_VLAN_FILTER) {
48 rc = octeontx_vlan_hw_filter(nic, true);
52 nic->rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
53 nic->rx_offload_flags |= OCCTX_RX_VLAN_FLTR_F;
55 rc = octeontx_vlan_hw_filter(nic, false);
59 nic->rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
60 nic->rx_offload_flags &= ~OCCTX_RX_VLAN_FLTR_F;
69 octeontx_dev_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
71 struct octeontx_nic *nic = octeontx_pmd_priv(dev);
72 struct octeontx_vlan_info *vlan = &nic->vlan_info;
73 pki_port_vlan_filter_entry_config_t fltr_entry;
74 struct vlan_entry *entry = NULL;
79 TAILQ_FOREACH(entry, &vlan->fltr_tbl, next)
80 if (entry->vlan_id == vlan_id) {
81 octeontx_log_dbg("Vlan Id is already set");
85 TAILQ_FOREACH(entry, &vlan->fltr_tbl, next)
92 fltr_entry.port_type = OCTTX_PORT_TYPE_NET;
93 fltr_entry.vlan_tpid = RTE_ETHER_TYPE_VLAN;
94 fltr_entry.vlan_id = vlan_id;
95 fltr_entry.entry_conf = on;
98 entry = rte_zmalloc("octeontx_nic_vlan_entry",
99 sizeof(struct vlan_entry), 0);
101 octeontx_log_err("Failed to allocate memory");
106 rc = octeontx_pki_port_vlan_fltr_entry_config(nic->port_id,
109 octeontx_log_err("Fail to configure vlan filter entry "
110 "for port %d", nic->port_id);
118 entry->vlan_id = vlan_id;
119 TAILQ_INSERT_HEAD(&vlan->fltr_tbl, entry, next);
121 TAILQ_FOREACH(entry, &vlan->fltr_tbl, next) {
122 if (entry->vlan_id == vlan_id) {
123 TAILQ_REMOVE(&vlan->fltr_tbl, entry, next);
135 octeontx_dev_vlan_offload_init(struct rte_eth_dev *dev)
137 struct octeontx_nic *nic = octeontx_pmd_priv(dev);
140 TAILQ_INIT(&nic->vlan_info.fltr_tbl);
142 rc = octeontx_dev_vlan_offload_set(dev, ETH_VLAN_FILTER_MASK);
144 octeontx_log_err("Failed to set vlan offload rc=%d", rc);
150 octeontx_dev_vlan_offload_fini(struct rte_eth_dev *dev)
152 struct octeontx_nic *nic = octeontx_pmd_priv(dev);
153 struct octeontx_vlan_info *vlan = &nic->vlan_info;
154 pki_port_vlan_filter_entry_config_t fltr_entry;
155 struct vlan_entry *entry;
158 TAILQ_FOREACH(entry, &vlan->fltr_tbl, next) {
159 fltr_entry.port_type = OCTTX_PORT_TYPE_NET;
160 fltr_entry.vlan_tpid = RTE_ETHER_TYPE_VLAN;
161 fltr_entry.vlan_id = entry->vlan_id;
162 fltr_entry.entry_conf = 0;
164 rc = octeontx_pki_port_vlan_fltr_entry_config(nic->port_id,
167 octeontx_log_err("Fail to configure vlan filter entry "
168 "for port %d", nic->port_id);
177 octeontx_dev_set_link_up(struct rte_eth_dev *eth_dev)
179 struct octeontx_nic *nic = octeontx_pmd_priv(eth_dev);
182 rc = octeontx_bgx_port_set_link_state(nic->port_id, true);
186 /* Start tx queues */
187 for (i = 0; i < eth_dev->data->nb_tx_queues; i++)
188 octeontx_dev_tx_queue_start(eth_dev, i);
195 octeontx_dev_set_link_down(struct rte_eth_dev *eth_dev)
197 struct octeontx_nic *nic = octeontx_pmd_priv(eth_dev);
201 for (i = 0; i < eth_dev->data->nb_tx_queues; i++)
202 octeontx_dev_tx_queue_stop(eth_dev, i);
204 return octeontx_bgx_port_set_link_state(nic->port_id, false);
208 octeontx_dev_flow_ctrl_get(struct rte_eth_dev *dev,
209 struct rte_eth_fc_conf *fc_conf)
211 struct octeontx_nic *nic = octeontx_pmd_priv(dev);
212 octeontx_mbox_bgx_port_fc_cfg_t conf;
215 memset(&conf, 0, sizeof(octeontx_mbox_bgx_port_fc_cfg_t));
217 rc = octeontx_bgx_port_flow_ctrl_cfg(nic->port_id, &conf);
221 if (conf.rx_pause && conf.tx_pause)
222 fc_conf->mode = RTE_FC_FULL;
223 else if (conf.rx_pause)
224 fc_conf->mode = RTE_FC_RX_PAUSE;
225 else if (conf.tx_pause)
226 fc_conf->mode = RTE_FC_TX_PAUSE;
228 fc_conf->mode = RTE_FC_NONE;
230 /* low_water & high_water values are in Bytes */
231 fc_conf->low_water = conf.low_water;
232 fc_conf->high_water = conf.high_water;
238 octeontx_dev_flow_ctrl_set(struct rte_eth_dev *dev,
239 struct rte_eth_fc_conf *fc_conf)
241 struct octeontx_nic *nic = octeontx_pmd_priv(dev);
242 struct octeontx_fc_info *fc = &nic->fc;
243 octeontx_mbox_bgx_port_fc_cfg_t conf;
244 uint8_t tx_pause, rx_pause;
245 uint16_t max_high_water;
248 if (fc_conf->pause_time || fc_conf->mac_ctrl_frame_fwd ||
250 octeontx_log_err("Below flowctrl parameters are not supported "
251 "pause_time, mac_ctrl_frame_fwd and autoneg");
255 if (fc_conf->high_water == fc->high_water &&
256 fc_conf->low_water == fc->low_water &&
257 fc_conf->mode == fc->mode)
260 max_high_water = fc->rx_fifosz - OCTEONTX_BGX_RSVD_RX_FIFOBYTES;
262 if (fc_conf->high_water > max_high_water ||
263 fc_conf->high_water < fc_conf->low_water) {
264 octeontx_log_err("Invalid high/low water values "
265 "High_water(in Bytes) must <= 0x%x ",
270 if (fc_conf->high_water % BIT(4) || fc_conf->low_water % BIT(4)) {
271 octeontx_log_err("High/low water value must be multiple of 16");
275 rx_pause = (fc_conf->mode == RTE_FC_FULL) ||
276 (fc_conf->mode == RTE_FC_RX_PAUSE);
277 tx_pause = (fc_conf->mode == RTE_FC_FULL) ||
278 (fc_conf->mode == RTE_FC_TX_PAUSE);
280 conf.high_water = fc_conf->high_water;
281 conf.low_water = fc_conf->low_water;
282 conf.fc_cfg = BGX_PORT_FC_CFG_SET;
283 conf.rx_pause = rx_pause;
284 conf.tx_pause = tx_pause;
286 rc = octeontx_bgx_port_flow_ctrl_cfg(nic->port_id, &conf);
290 fc->high_water = fc_conf->high_water;
291 fc->low_water = fc_conf->low_water;
292 fc->mode = fc_conf->mode;
298 octeontx_dev_flow_ctrl_init(struct rte_eth_dev *dev)
300 struct octeontx_nic *nic = octeontx_pmd_priv(dev);
301 struct octeontx_fc_info *fc = &nic->fc;
302 struct rte_eth_fc_conf fc_conf;
305 rc = octeontx_dev_flow_ctrl_get(dev, &fc_conf);
307 octeontx_log_err("Failed to get flow control info");
311 fc->def_highmark = fc_conf.high_water;
312 fc->def_lowmark = fc_conf.low_water;
313 fc->def_mode = fc_conf.mode;
319 octeontx_dev_flow_ctrl_fini(struct rte_eth_dev *dev)
321 struct octeontx_nic *nic = octeontx_pmd_priv(dev);
322 struct octeontx_fc_info *fc = &nic->fc;
323 struct rte_eth_fc_conf fc_conf;
325 memset(&fc_conf, 0, sizeof(struct rte_eth_fc_conf));
327 /* Restore flow control parameters with default values */
328 fc_conf.high_water = fc->def_highmark;
329 fc_conf.low_water = fc->def_lowmark;
330 fc_conf.mode = fc->def_mode;
332 return octeontx_dev_flow_ctrl_set(dev, &fc_conf);