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_EXTEND_MASK) {
47 octeontx_log_err("Extend offload not supported");
51 if (mask & ETH_VLAN_STRIP_MASK) {
52 octeontx_log_err("VLAN strip offload not supported");
56 if (mask & ETH_VLAN_FILTER_MASK) {
57 if (rxmode->offloads & DEV_RX_OFFLOAD_VLAN_FILTER) {
58 rc = octeontx_vlan_hw_filter(nic, true);
62 nic->rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
63 nic->rx_offload_flags |= OCCTX_RX_VLAN_FLTR_F;
65 rc = octeontx_vlan_hw_filter(nic, false);
69 nic->rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
70 nic->rx_offload_flags &= ~OCCTX_RX_VLAN_FLTR_F;
79 octeontx_dev_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
81 struct octeontx_nic *nic = octeontx_pmd_priv(dev);
82 struct octeontx_vlan_info *vlan = &nic->vlan_info;
83 pki_port_vlan_filter_entry_config_t fltr_entry;
84 struct vlan_entry *entry = NULL;
89 TAILQ_FOREACH(entry, &vlan->fltr_tbl, next)
90 if (entry->vlan_id == vlan_id) {
91 octeontx_log_dbg("Vlan Id is already set");
95 TAILQ_FOREACH(entry, &vlan->fltr_tbl, next)
102 fltr_entry.port_type = OCTTX_PORT_TYPE_NET;
103 fltr_entry.vlan_tpid = RTE_ETHER_TYPE_VLAN;
104 fltr_entry.vlan_id = vlan_id;
105 fltr_entry.entry_conf = on;
108 entry = rte_zmalloc("octeontx_nic_vlan_entry",
109 sizeof(struct vlan_entry), 0);
111 octeontx_log_err("Failed to allocate memory");
116 rc = octeontx_pki_port_vlan_fltr_entry_config(nic->port_id,
119 octeontx_log_err("Fail to configure vlan filter entry "
120 "for port %d", nic->port_id);
128 entry->vlan_id = vlan_id;
129 TAILQ_INSERT_HEAD(&vlan->fltr_tbl, entry, next);
131 TAILQ_FOREACH(entry, &vlan->fltr_tbl, next) {
132 if (entry->vlan_id == vlan_id) {
133 TAILQ_REMOVE(&vlan->fltr_tbl, entry, next);
145 octeontx_dev_vlan_offload_init(struct rte_eth_dev *dev)
147 struct octeontx_nic *nic = octeontx_pmd_priv(dev);
150 TAILQ_INIT(&nic->vlan_info.fltr_tbl);
152 rc = octeontx_dev_vlan_offload_set(dev, ETH_VLAN_FILTER_MASK);
154 octeontx_log_err("Failed to set vlan offload rc=%d", rc);
160 octeontx_dev_vlan_offload_fini(struct rte_eth_dev *dev)
162 struct octeontx_nic *nic = octeontx_pmd_priv(dev);
163 struct octeontx_vlan_info *vlan = &nic->vlan_info;
164 pki_port_vlan_filter_entry_config_t fltr_entry;
165 struct vlan_entry *entry;
168 TAILQ_FOREACH(entry, &vlan->fltr_tbl, next) {
169 fltr_entry.port_type = OCTTX_PORT_TYPE_NET;
170 fltr_entry.vlan_tpid = RTE_ETHER_TYPE_VLAN;
171 fltr_entry.vlan_id = entry->vlan_id;
172 fltr_entry.entry_conf = 0;
174 rc = octeontx_pki_port_vlan_fltr_entry_config(nic->port_id,
177 octeontx_log_err("Fail to configure vlan filter entry "
178 "for port %d", nic->port_id);
187 octeontx_dev_set_link_up(struct rte_eth_dev *eth_dev)
189 struct octeontx_nic *nic = octeontx_pmd_priv(eth_dev);
192 rc = octeontx_bgx_port_set_link_state(nic->port_id, true);
196 /* Start tx queues */
197 for (i = 0; i < eth_dev->data->nb_tx_queues; i++)
198 octeontx_dev_tx_queue_start(eth_dev, i);
205 octeontx_dev_set_link_down(struct rte_eth_dev *eth_dev)
207 struct octeontx_nic *nic = octeontx_pmd_priv(eth_dev);
211 for (i = 0; i < eth_dev->data->nb_tx_queues; i++)
212 octeontx_dev_tx_queue_stop(eth_dev, i);
214 return octeontx_bgx_port_set_link_state(nic->port_id, false);