/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright(c) 2014-2018 Broadcom
+ * Copyright(c) 2014-2021 Broadcom
* All rights reserved.
*/
#include <rte_flow.h>
#include <rte_flow_driver.h>
#include <rte_tailq.h>
+#include <rte_alarm.h>
+#include <rte_cycles.h>
#include "bnxt.h"
#include "bnxt_filter.h"
#include "bnxt_hwrm.h"
#include "bnxt_ring.h"
#include "bnxt_rxq.h"
+#include "bnxt_rxr.h"
#include "bnxt_vnic.h"
#include "hsi_struct_def_dpdk.h"
static int
bnxt_filter_type_check(const struct rte_flow_item pattern[],
- struct rte_flow_error *error __rte_unused)
+ struct rte_flow_error *error)
{
const struct rte_flow_item *item =
bnxt_flow_non_void_item(pattern);
const struct rte_flow_item_tcp *tcp_spec, *tcp_mask;
const struct rte_flow_item_udp *udp_spec, *udp_mask;
const struct rte_flow_item_eth *eth_spec, *eth_mask;
+ const struct rte_ether_addr *dst, *src;
const struct rte_flow_item_nvgre *nvgre_spec;
const struct rte_flow_item_nvgre *nvgre_mask;
const struct rte_flow_item_gre *gre_spec;
return -rte_errno;
}
- if (!item->spec || !item->mask) {
- rte_flow_error_set(error, EINVAL,
- RTE_FLOW_ERROR_TYPE_ITEM,
- item,
- "spec/mask is NULL");
- return -rte_errno;
- }
-
switch (item->type) {
case RTE_FLOW_ITEM_TYPE_ANY:
inner =
PMD_DRV_LOG(DEBUG, "Parse inner header\n");
break;
case RTE_FLOW_ITEM_TYPE_ETH:
- if (!item->spec || !item->mask)
+ if (!item->spec)
break;
eth_spec = item->spec;
- eth_mask = item->mask;
+
+ if (item->mask)
+ eth_mask = item->mask;
+ else
+ eth_mask = &rte_flow_item_eth_mask;
/* Source MAC address mask cannot be partially set.
* Should be All 0's or all 1's.
}
if (rte_is_broadcast_ether_addr(ð_mask->dst)) {
- if (!rte_is_unicast_ether_addr(ð_spec->dst)) {
+ dst = ð_spec->dst;
+ if (!rte_is_valid_assigned_ether_addr(dst)) {
rte_flow_error_set(error,
EINVAL,
RTE_FLOW_ERROR_TYPE_ITEM,
item,
"DMAC is invalid");
+ PMD_DRV_LOG(ERR,
+ "DMAC is invalid!\n");
return -rte_errno;
}
rte_memcpy(filter->dst_macaddr,
PMD_DRV_LOG(DEBUG,
"Creating a priority flow\n");
}
-
if (rte_is_broadcast_ether_addr(ð_mask->src)) {
- if (!rte_is_unicast_ether_addr(ð_spec->src)) {
+ src = ð_spec->src;
+ if (!rte_is_valid_assigned_ether_addr(src)) {
rte_flow_error_set(error,
EINVAL,
RTE_FLOW_ERROR_TYPE_ITEM,
item,
"SMAC is invalid");
+ PMD_DRV_LOG(ERR,
+ "SMAC is invalid!\n");
return -rte_errno;
}
rte_memcpy(filter->src_macaddr,
break;
case RTE_FLOW_ITEM_TYPE_VLAN:
vlan_spec = item->spec;
- vlan_mask = item->mask;
+
+ if (item->mask)
+ vlan_mask = item->mask;
+ else
+ vlan_mask = &rte_flow_item_vlan_mask;
+
if (en & en_ethertype) {
rte_flow_error_set(error, EINVAL,
RTE_FLOW_ERROR_TYPE_ITEM,
case RTE_FLOW_ITEM_TYPE_IPV4:
/* If mask is not involved, we could use EM filters. */
ipv4_spec = item->spec;
- ipv4_mask = item->mask;
- if (!item->spec || !item->mask)
+ if (!item->spec)
break;
+ if (item->mask)
+ ipv4_mask = item->mask;
+ else
+ ipv4_mask = &rte_flow_item_ipv4_mask;
+
/* Only IP DST and SRC fields are maskable. */
if (ipv4_mask->hdr.version_ihl ||
ipv4_mask->hdr.type_of_service ||
break;
case RTE_FLOW_ITEM_TYPE_IPV6:
ipv6_spec = item->spec;
- ipv6_mask = item->mask;
- if (!item->spec || !item->mask)
+ if (!item->spec)
break;
+ if (item->mask)
+ ipv6_mask = item->mask;
+ else
+ ipv6_mask = &rte_flow_item_ipv6_mask;
+
/* Only IP DST and SRC fields are maskable. */
if (ipv6_mask->hdr.vtc_flow ||
ipv6_mask->hdr.payload_len ||
break;
case RTE_FLOW_ITEM_TYPE_TCP:
tcp_spec = item->spec;
- tcp_mask = item->mask;
- if (!item->spec || !item->mask)
+ if (!item->spec)
break;
+ if (item->mask)
+ tcp_mask = item->mask;
+ else
+ tcp_mask = &rte_flow_item_tcp_mask;
+
/* Check TCP mask. Only DST & SRC ports are maskable */
if (tcp_mask->hdr.sent_seq ||
tcp_mask->hdr.recv_ack ||
break;
case RTE_FLOW_ITEM_TYPE_UDP:
udp_spec = item->spec;
- udp_mask = item->mask;
- if (!item->spec || !item->mask)
+ if (!item->spec)
break;
+ if (item->mask)
+ udp_mask = item->mask;
+ else
+ udp_mask = &rte_flow_item_udp_mask;
+
if (udp_mask->hdr.dgram_len ||
udp_mask->hdr.dgram_cksum) {
rte_flow_error_set(error,
}
/* Check if VNI is masked. */
- if (vxlan_spec && vxlan_mask) {
+ if (vxlan_mask != NULL) {
vni_masked =
!!memcmp(vxlan_mask->vni, vni_mask,
RTE_DIM(vni_mask));
filter->enables = en;
filter->valid_flags = valid_flags;
+ /* Items parsed but no filter to create in HW. */
+ if (filter->enables == 0 && filter->valid_flags == 0)
+ filter->filter_type = HWRM_CFA_CONFIG;
+
return 0;
}
{
struct bnxt_filter_info *mf, *f0;
struct bnxt_vnic_info *vnic0;
- struct rte_flow *flow;
int i;
- vnic0 = &bp->vnic_info[0];
+ vnic0 = BNXT_GET_DEFAULT_VNIC(bp);
f0 = STAILQ_FIRST(&vnic0->filter);
/* This flow has same DST MAC as the port/l2 filter. */
if (vnic->fw_vnic_id == INVALID_VNIC_ID)
continue;
- STAILQ_FOREACH(flow, &vnic->flow_list, next) {
- mf = flow->filter;
+ STAILQ_FOREACH(mf, &vnic->filter, next) {
if (mf->matching_l2_fltr_ptr)
continue;
if (filter1 == NULL)
return NULL;
+ memcpy(filter1, nf, sizeof(*filter1));
+
filter1->flags = HWRM_CFA_L2_FILTER_ALLOC_INPUT_FLAGS_XDP_DISABLE;
filter1->flags |= HWRM_CFA_L2_FILTER_ALLOC_INPUT_FLAGS_PATH_RX;
if (nf->valid_flags & BNXT_FLOW_L2_SRC_VALID_FLAG ||
bnxt_free_filter(bp, filter1);
return NULL;
}
- filter1->l2_ref_cnt++;
return filter1;
}
l2_filter = bnxt_find_matching_l2_filter(bp, nf);
if (l2_filter) {
l2_filter->l2_ref_cnt++;
- nf->matching_l2_fltr_ptr = l2_filter;
} else {
l2_filter = bnxt_create_l2_filter(bp, nf, vnic);
- nf->matching_l2_fltr_ptr = NULL;
+ if (l2_filter) {
+ STAILQ_INSERT_TAIL(&vnic->filter, l2_filter, next);
+ l2_filter->vnic = vnic;
+ }
}
+ nf->matching_l2_fltr_ptr = l2_filter;
return l2_filter;
}
-static int bnxt_vnic_prep(struct bnxt *bp, struct bnxt_vnic_info *vnic)
+static void bnxt_vnic_cleanup(struct bnxt *bp, struct bnxt_vnic_info *vnic)
+{
+ if (vnic->rx_queue_cnt > 1)
+ bnxt_hwrm_vnic_ctx_free(bp, vnic);
+
+ bnxt_hwrm_vnic_free(bp, vnic);
+
+ rte_free(vnic->fw_grp_ids);
+ vnic->fw_grp_ids = NULL;
+
+ vnic->rx_queue_cnt = 0;
+}
+
+static int bnxt_vnic_prep(struct bnxt *bp, struct bnxt_vnic_info *vnic,
+ const struct rte_flow_action *act,
+ struct rte_flow_error *error)
{
struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
uint64_t rx_offloads = dev_conf->rxmode.offloads;
int rc;
+ if (bp->nr_vnics > bp->max_vnics - 1)
+ return rte_flow_error_set(error, EINVAL,
+ RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
+ NULL,
+ "Group id is invalid");
+
rc = bnxt_vnic_grp_alloc(bp, vnic);
if (rc)
- goto ret;
+ return rte_flow_error_set(error, -rc,
+ RTE_FLOW_ERROR_TYPE_ACTION,
+ act,
+ "Failed to alloc VNIC group");
rc = bnxt_hwrm_vnic_alloc(bp, vnic);
if (rc) {
- PMD_DRV_LOG(ERR, "HWRM vnic alloc failure rc: %x\n", rc);
+ rte_flow_error_set(error, -rc,
+ RTE_FLOW_ERROR_TYPE_ACTION,
+ act,
+ "Failed to alloc VNIC");
goto ret;
}
- bp->nr_vnics++;
/* RSS context is required only when there is more than one RSS ring */
if (vnic->rx_queue_cnt > 1) {
- rc = bnxt_hwrm_vnic_ctx_alloc(bp, vnic, 0 /* ctx_idx 0 */);
+ rc = bnxt_hwrm_vnic_ctx_alloc(bp, vnic, 0);
if (rc) {
- PMD_DRV_LOG(ERR,
- "HWRM vnic ctx alloc failure: %x\n", rc);
+ rte_flow_error_set(error, -rc,
+ RTE_FLOW_ERROR_TYPE_ACTION,
+ act,
+ "Failed to alloc VNIC context");
goto ret;
}
- } else {
- PMD_DRV_LOG(DEBUG, "No RSS context required\n");
}
- if (rx_offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
+ if (rx_offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
vnic->vlan_strip = true;
else
vnic->vlan_strip = false;
rc = bnxt_hwrm_vnic_cfg(bp, vnic);
- if (rc)
+ if (rc) {
+ rte_flow_error_set(error, -rc,
+ RTE_FLOW_ERROR_TYPE_ACTION,
+ act,
+ "Failed to configure VNIC");
goto ret;
+ }
+
+ rc = bnxt_hwrm_vnic_plcmode_cfg(bp, vnic);
+ if (rc) {
+ rte_flow_error_set(error, -rc,
+ RTE_FLOW_ERROR_TYPE_ACTION,
+ act,
+ "Failed to configure VNIC plcmode");
+ goto ret;
+ }
+
+ bp->nr_vnics++;
- bnxt_hwrm_vnic_plcmode_cfg(bp, vnic);
+ return 0;
ret:
+ bnxt_vnic_cleanup(bp, vnic);
return rc;
}
}
filter->fw_l2_filter_id = filter1->fw_l2_filter_id;
filter->l2_ref_cnt = filter1->l2_ref_cnt;
+ filter->flow_id = filter1->flow_id;
PMD_DRV_LOG(DEBUG,
"l2_filter: %p fw_l2_filter_id %" PRIx64 " l2_ref_cnt %u\n",
filter1, filter->fw_l2_filter_id, filter->l2_ref_cnt);
}
+/* Valid actions supported along with RSS are count and mark. */
+static int
+bnxt_validate_rss_action(const struct rte_flow_action actions[])
+{
+ for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
+ switch (actions->type) {
+ case RTE_FLOW_ACTION_TYPE_VOID:
+ break;
+ case RTE_FLOW_ACTION_TYPE_RSS:
+ break;
+ default:
+ return -ENOTSUP;
+ }
+ }
+
+ return 0;
+}
+
+static int
+bnxt_get_vnic(struct bnxt *bp, uint32_t group)
+{
+ int vnic_id = 0;
+
+ /* For legacy NS3 based implementations,
+ * group_id will be mapped to a VNIC ID.
+ */
+ if (BNXT_STINGRAY(bp))
+ vnic_id = group;
+
+ /* Non NS3 cases, group_id will be ignored.
+ * Setting will be configured on default VNIC.
+ */
+ return vnic_id;
+}
+
+static int
+bnxt_vnic_rss_cfg_update(struct bnxt *bp,
+ struct bnxt_vnic_info *vnic,
+ const struct rte_flow_action *act,
+ struct rte_flow_error *error)
+{
+ const struct rte_flow_action_rss *rss;
+ unsigned int rss_idx, i;
+ uint16_t hash_type;
+ uint64_t types;
+ int rc;
+
+ rss = (const struct rte_flow_action_rss *)act->conf;
+
+ /* Currently only Toeplitz hash is supported. */
+ if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT &&
+ rss->func != RTE_ETH_HASH_FUNCTION_TOEPLITZ) {
+ rte_flow_error_set(error,
+ ENOTSUP,
+ RTE_FLOW_ERROR_TYPE_ACTION,
+ act,
+ "Unsupported RSS hash function");
+ rc = -rte_errno;
+ goto ret;
+ }
+
+ /* key_len should match the hash key supported by hardware */
+ if (rss->key_len != 0 && rss->key_len != HW_HASH_KEY_SIZE) {
+ rte_flow_error_set(error,
+ EINVAL,
+ RTE_FLOW_ERROR_TYPE_ACTION,
+ act,
+ "Incorrect hash key parameters");
+ rc = -rte_errno;
+ goto ret;
+ }
+
+ /* Currently RSS hash on inner and outer headers are supported.
+ * 0 => Default (innermost RSS) setting
+ * 1 => Outermost
+ */
+ if (rss->level > 1) {
+ rte_flow_error_set(error,
+ ENOTSUP,
+ RTE_FLOW_ERROR_TYPE_ACTION,
+ act,
+ "Unsupported hash level");
+ rc = -rte_errno;
+ goto ret;
+ }
+
+ if ((rss->queue_num == 0 && rss->queue != NULL) ||
+ (rss->queue_num != 0 && rss->queue == NULL)) {
+ rte_flow_error_set(error,
+ EINVAL,
+ RTE_FLOW_ERROR_TYPE_ACTION,
+ act,
+ "Invalid queue config specified");
+ rc = -rte_errno;
+ goto ret;
+ }
+
+ /* If RSS types is 0, use a best effort configuration */
+ types = rss->types ? rss->types : RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_IPV6;
+
+ hash_type = bnxt_rte_to_hwrm_hash_types(types);
+
+ /* If requested types can't be supported, leave existing settings */
+ if (hash_type)
+ vnic->hash_type = hash_type;
+
+ vnic->hash_mode =
+ bnxt_rte_to_hwrm_hash_level(bp, rss->types, rss->level);
+
+ /* Update RSS key only if key_len != 0 */
+ if (rss->key_len != 0)
+ memcpy(vnic->rss_hash_key, rss->key, rss->key_len);
+
+ if (rss->queue_num == 0)
+ goto skip_rss_table;
+
+ /* Validate Rx queues */
+ for (i = 0; i < rss->queue_num; i++) {
+ PMD_DRV_LOG(DEBUG, "RSS action Queue %d\n", rss->queue[i]);
+
+ if (rss->queue[i] >= bp->rx_nr_rings ||
+ !bp->rx_queues[rss->queue[i]]) {
+ rte_flow_error_set(error,
+ EINVAL,
+ RTE_FLOW_ERROR_TYPE_ACTION,
+ act,
+ "Invalid queue ID for RSS");
+ rc = -rte_errno;
+ goto ret;
+ }
+ }
+
+ /* Prepare the indirection table */
+ for (rss_idx = 0; rss_idx < HW_HASH_INDEX_SIZE; rss_idx++) {
+ struct bnxt_rx_queue *rxq;
+ uint32_t idx;
+
+ idx = rss->queue[rss_idx % rss->queue_num];
+
+ if (BNXT_CHIP_P5(bp)) {
+ rxq = bp->rx_queues[idx];
+ vnic->rss_table[rss_idx * 2] =
+ rxq->rx_ring->rx_ring_struct->fw_ring_id;
+ vnic->rss_table[rss_idx * 2 + 1] =
+ rxq->cp_ring->cp_ring_struct->fw_ring_id;
+ } else {
+ vnic->rss_table[rss_idx] = vnic->fw_grp_ids[idx];
+ }
+ }
+
+skip_rss_table:
+ rc = bnxt_hwrm_vnic_rss_cfg(bp, vnic);
+ if (rc != 0) {
+ rte_flow_error_set(error,
+ -rc,
+ RTE_FLOW_ERROR_TYPE_ACTION,
+ act,
+ "VNIC RSS configure failed");
+ rc = -rte_errno;
+ goto ret;
+ }
+ret:
+ return rc;
+}
+
static int
bnxt_validate_and_parse_flow(struct rte_eth_dev *dev,
const struct rte_flow_item pattern[],
filter->flags = HWRM_CFA_EM_FLOW_ALLOC_INPUT_FLAGS_PATH_RX;
use_ntuple = bnxt_filter_type_check(pattern, error);
+
+start:
switch (act->type) {
case RTE_FLOW_ACTION_TYPE_QUEUE:
/* Allow this flow. Redirect to a VNIC. */
vnic_id = act_q->index;
}
+ BNXT_VALID_VNIC_OR_RET(bp, vnic_id);
+
vnic = &bp->vnic_info[vnic_id];
- if (vnic == NULL) {
- rte_flow_error_set(error,
- EINVAL,
- RTE_FLOW_ERROR_TYPE_ACTION,
- act,
- "No matching VNIC found.");
- rc = -rte_errno;
- goto ret;
- }
if (vnic->rx_queue_cnt) {
if (vnic->start_grp_id != act_q->index) {
PMD_DRV_LOG(ERR,
rxq = bp->rx_queues[act_q->index];
- if (!(dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS) && rxq &&
+ if (!(dev_conf->rxmode.mq_mode & RTE_ETH_MQ_RX_RSS) && rxq &&
vnic->fw_vnic_id != INVALID_HW_RING_ID)
goto use_vnic;
- if (!rxq ||
- bp->vnic_info[0].fw_grp_ids[act_q->index] !=
- INVALID_HW_RING_ID) {
+ if (!rxq) {
PMD_DRV_LOG(ERR,
"Queue invalid or used with other VNIC\n");
rte_flow_error_set(error,
PMD_DRV_LOG(DEBUG, "VNIC found\n");
- rc = bnxt_vnic_prep(bp, vnic);
- if (rc) {
- rte_flow_error_set(error,
- EINVAL,
- RTE_FLOW_ERROR_TYPE_ACTION,
- act,
- "VNIC prep fail");
- rc = -rte_errno;
+ rc = bnxt_vnic_prep(bp, vnic, act, error);
+ if (rc)
goto ret;
- }
PMD_DRV_LOG(DEBUG,
"vnic[%d] = %p vnic->fw_grp_ids = %p\n",
PMD_DRV_LOG(DEBUG,
"Setting vnic ff_idx %d\n", vnic->ff_pool_idx);
filter->dst_id = vnic->fw_vnic_id;
- filter1 = bnxt_get_l2_filter(bp, filter, vnic);
+
+ /* For ntuple filter, create the L2 filter with default VNIC.
+ * The user specified redirect queue will be set while creating
+ * the ntuple filter in hardware.
+ */
+ vnic0 = BNXT_GET_DEFAULT_VNIC(bp);
+ if (use_ntuple)
+ filter1 = bnxt_get_l2_filter(bp, filter, vnic0);
+ else
+ filter1 = bnxt_get_l2_filter(bp, filter, vnic);
if (filter1 == NULL) {
rte_flow_error_set(error,
ENOSPC,
}
filter->fw_l2_filter_id = filter1->fw_l2_filter_id;
+ filter->flow_id = filter1->flow_id;
filter->flags = HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_FLAGS_METER;
break;
case RTE_FLOW_ACTION_TYPE_VF:
}
filter->fw_l2_filter_id = filter1->fw_l2_filter_id;
+ filter->flow_id = filter1->flow_id;
break;
case RTE_FLOW_ACTION_TYPE_RSS:
- rss = (const struct rte_flow_action_rss *)act->conf;
-
- vnic_id = attr->group;
- if (!vnic_id) {
- PMD_DRV_LOG(ERR, "Group id cannot be 0\n");
+ rc = bnxt_validate_rss_action(actions);
+ if (rc != 0) {
rte_flow_error_set(error,
EINVAL,
- RTE_FLOW_ERROR_TYPE_ATTR,
- NULL,
- "Group id cannot be 0");
+ RTE_FLOW_ERROR_TYPE_ACTION,
+ act,
+ "Invalid actions specified with RSS");
rc = -rte_errno;
goto ret;
}
+ rss = (const struct rte_flow_action_rss *)act->conf;
+
+ vnic_id = bnxt_get_vnic(bp, attr->group);
+
+ BNXT_VALID_VNIC_OR_RET(bp, vnic_id);
vnic = &bp->vnic_info[vnic_id];
- if (vnic == NULL) {
- rte_flow_error_set(error,
- EINVAL,
- RTE_FLOW_ERROR_TYPE_ACTION,
- act,
- "No matching VNIC for RSS group.");
- rc = -rte_errno;
- goto ret;
+
+ /*
+ * For non NS3 cases, rte_flow_items will not be considered
+ * for RSS updates.
+ */
+ if (filter->filter_type == HWRM_CFA_CONFIG) {
+ /* RSS config update requested */
+ rc = bnxt_vnic_rss_cfg_update(bp, vnic, act, error);
+ if (rc != 0)
+ goto ret;
+
+ filter->dst_id = vnic->fw_vnic_id;
+ break;
}
- PMD_DRV_LOG(DEBUG, "VNIC found\n");
/* Check if requested RSS config matches RSS config of VNIC
* only if it is not a fresh VNIC configuration.
vnic->end_grp_id = rss->queue[rss->queue_num - 1];
vnic->func_default = 0; //This is not a default VNIC.
- rc = bnxt_vnic_prep(bp, vnic);
- if (rc) {
- rte_flow_error_set(error,
- EINVAL,
- RTE_FLOW_ERROR_TYPE_ACTION,
- act,
- "VNIC prep fail");
- rc = -rte_errno;
+ rc = bnxt_vnic_prep(bp, vnic, act, error);
+ if (rc)
goto ret;
- }
PMD_DRV_LOG(DEBUG,
"vnic[%d] = %p vnic->fw_grp_ids = %p\n",
if (vnic->rx_queue_cnt > 1) {
vnic->hash_type =
bnxt_rte_to_hwrm_hash_types(rss->types);
+ vnic->hash_mode =
+ bnxt_rte_to_hwrm_hash_level(bp, rss->types, rss->level);
if (!rss->key_len) {
/* If hash key has not been specified,
* use random hash key.
*/
- prandom_bytes(vnic->rss_hash_key,
- HW_HASH_KEY_SIZE);
+ bnxt_prandom_bytes(vnic->rss_hash_key,
+ HW_HASH_KEY_SIZE);
} else {
if (rss->key_len > HW_HASH_KEY_SIZE)
memcpy(vnic->rss_hash_key,
PMD_DRV_LOG(DEBUG, "L2 filter created\n");
bnxt_update_filter_flags_en(filter, filter1, use_ntuple);
break;
+ case RTE_FLOW_ACTION_TYPE_MARK:
+ if (bp->mark_table == NULL) {
+ rte_flow_error_set(error,
+ ENOMEM,
+ RTE_FLOW_ERROR_TYPE_ACTION,
+ act,
+ "Mark table not allocated.");
+ rc = -rte_errno;
+ goto ret;
+ }
+
+ if (bp->flags & BNXT_FLAG_RX_VECTOR_PKT_MODE) {
+ PMD_DRV_LOG(DEBUG,
+ "Disabling vector processing for mark\n");
+ bp->eth_dev->rx_pkt_burst = bnxt_recv_pkts;
+ bp->flags &= ~BNXT_FLAG_RX_VECTOR_PKT_MODE;
+ }
+
+ filter->valid_flags |= BNXT_FLOW_MARK_FLAG;
+ filter->mark = ((const struct rte_flow_action_mark *)
+ act->conf)->id;
+ PMD_DRV_LOG(DEBUG, "Mark the flow %d\n", filter->mark);
+ break;
default:
rte_flow_error_set(error,
EINVAL,
goto ret;
}
- if (filter1 && !filter->matching_l2_fltr_ptr) {
- bnxt_free_filter(bp, filter1);
- filter1->fw_l2_filter_id = -1;
- }
-
done:
act = bnxt_flow_non_void_action(++act);
- if (act->type != RTE_FLOW_ACTION_TYPE_END) {
- rte_flow_error_set(error,
- EINVAL,
- RTE_FLOW_ERROR_TYPE_ACTION,
- act,
- "Invalid action.");
- rc = -rte_errno;
- goto ret;
- }
+ while (act->type != RTE_FLOW_ACTION_TYPE_END)
+ goto start;
return rc;
ret:
- //TODO: Cleanup according to ACTION TYPE.
+ if (filter1) {
+ bnxt_hwrm_clear_l2_filter(bp, filter1);
+ bnxt_free_filter(bp, filter1);
+ }
+
if (rte_errno) {
if (vnic && STAILQ_EMPTY(&vnic->filter))
vnic->rx_queue_cnt = 0;
if (rxq && !vnic->rx_queue_cnt)
rxq->vnic = &bp->vnic_info[0];
}
- return rc;
+ return -rte_errno;
}
static
filter = bnxt_get_unused_filter(bp);
if (filter == NULL) {
- PMD_DRV_LOG(ERR, "Not enough resources for a new flow.\n");
+ rte_flow_error_set(error, ENOSPC,
+ RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
+ "Not enough resources for a new flow");
bnxt_release_flow_lock(bp);
- return -ENOMEM;
+ return -ENOSPC;
}
ret = bnxt_validate_and_parse_flow(dev, pattern, actions, attr,
vnic = find_matching_vnic(bp, filter);
if (vnic) {
if (STAILQ_EMPTY(&vnic->filter)) {
- rte_free(vnic->fw_grp_ids);
- bnxt_hwrm_vnic_ctx_free(bp, vnic);
- bnxt_hwrm_vnic_free(bp, vnic);
- vnic->rx_queue_cnt = 0;
+ bnxt_vnic_cleanup(bp, vnic);
+ bp->nr_vnics--;
PMD_DRV_LOG(DEBUG, "Free VNIC\n");
}
}
exit:
/* No need to hold on to this filter if we are just validating flow */
- filter->fw_l2_filter_id = UINT64_MAX;
bnxt_free_filter(bp, filter);
bnxt_release_flow_lock(bp);
* filter which points to the new destination queue and so we clear
* the previous L2 filter. For ntuple filters, we are going to reuse
* the old L2 filter and create new NTUPLE filter with this new
- * destination queue subsequently during bnxt_flow_create.
+ * destination queue subsequently during bnxt_flow_create. So we
+ * decrement the ref cnt of the L2 filter that would've been bumped
+ * up previously in bnxt_validate_and_parse_flow as the old n-tuple
+ * filter that was referencing it will be deleted now.
*/
+ bnxt_hwrm_clear_l2_filter(bp, old_filter);
if (new_filter->filter_type == HWRM_CFA_L2_FILTER) {
- bnxt_hwrm_clear_l2_filter(bp, old_filter);
bnxt_hwrm_set_l2_filter(bp, new_filter->dst_id, new_filter);
} else {
if (new_filter->filter_type == HWRM_CFA_EM_FILTER)
return 0;
}
+static void
+bnxt_setup_flow_counter(struct bnxt *bp)
+{
+ if (bp->fw_cap & BNXT_FW_CAP_ADV_FLOW_COUNTERS &&
+ !(bp->flags & BNXT_FLAG_FC_THREAD) && BNXT_FLOW_XSTATS_EN(bp)) {
+ rte_eal_alarm_set(US_PER_S * BNXT_FC_TIMER,
+ bnxt_flow_cnt_alarm_cb,
+ (void *)bp);
+ bp->flags |= BNXT_FLAG_FC_THREAD;
+ }
+}
+
+void bnxt_flow_cnt_alarm_cb(void *arg)
+{
+ int rc = 0;
+ struct bnxt *bp = arg;
+
+ if (!bp->flow_stat->rx_fc_out_tbl.va) {
+ PMD_DRV_LOG(ERR, "bp->flow_stat->rx_fc_out_tbl.va is NULL?\n");
+ bnxt_cancel_fc_thread(bp);
+ return;
+ }
+
+ if (!bp->flow_stat->flow_count) {
+ bnxt_cancel_fc_thread(bp);
+ return;
+ }
+
+ if (!bp->eth_dev->data->dev_started) {
+ bnxt_cancel_fc_thread(bp);
+ return;
+ }
+
+ rc = bnxt_flow_stats_req(bp);
+ if (rc) {
+ PMD_DRV_LOG(ERR, "Flow stat alarm not rescheduled.\n");
+ return;
+ }
+
+ rte_eal_alarm_set(US_PER_S * BNXT_FC_TIMER,
+ bnxt_flow_cnt_alarm_cb,
+ (void *)bp);
+}
+
+
static struct rte_flow *
bnxt_flow_create(struct rte_eth_dev *dev,
const struct rte_flow_attr *attr,
bool update_flow = false;
struct rte_flow *flow;
int ret = 0;
- uint32_t tun_type;
+ uint32_t tun_type, flow_id;
if (BNXT_VF(bp) && !BNXT_VF_IS_TRUSTED(bp)) {
rte_flow_error_set(error, EINVAL,
filter = bnxt_get_unused_filter(bp);
if (filter == NULL) {
- PMD_DRV_LOG(ERR, "Not enough resources for a new flow.\n");
+ rte_flow_error_set(error, ENOSPC,
+ RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
+ "Not enough resources for a new flow");
goto free_flow;
}
filter->enables |=
HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_L2_FILTER_ID;
ret = bnxt_hwrm_set_em_filter(bp, filter->dst_id, filter);
+ if (ret != 0) {
+ rte_flow_error_set(error, -ret,
+ RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
+ "Failed to create EM filter");
+ goto free_filter;
+ }
}
if (filter->filter_type == HWRM_CFA_NTUPLE_FILTER) {
filter->enables |=
HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_L2_FILTER_ID;
ret = bnxt_hwrm_set_ntuple_filter(bp, filter->dst_id, filter);
+ if (ret != 0) {
+ rte_flow_error_set(error, -ret,
+ RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
+ "Failed to create ntuple filter");
+ goto free_filter;
+ }
}
vnic = find_matching_vnic(bp, filter);
goto free_flow;
}
+ if (filter->valid_flags & BNXT_FLOW_MARK_FLAG) {
+ PMD_DRV_LOG(DEBUG,
+ "Mark action: mark id 0x%x, flow id 0x%x\n",
+ filter->mark, filter->flow_id);
+
+ /* TCAM and EM should be 16-bit only.
+ * Other modes not supported.
+ */
+ flow_id = filter->flow_id & BNXT_FLOW_ID_MASK;
+ if (bp->mark_table[flow_id].valid) {
+ rte_flow_error_set(error, EEXIST,
+ RTE_FLOW_ERROR_TYPE_HANDLE,
+ NULL,
+ "Flow with mark id exists");
+ bnxt_clear_one_vnic_filter(bp, filter);
+ goto free_filter;
+ }
+ bp->mark_table[flow_id].valid = true;
+ bp->mark_table[flow_id].mark_id = filter->mark;
+ }
+
STAILQ_INSERT_TAIL(&vnic->filter, filter, next);
- PMD_DRV_LOG(ERR, "Successfully created flow.\n");
STAILQ_INSERT_TAIL(&vnic->flow_list, flow, next);
+
+ if (BNXT_FLOW_XSTATS_EN(bp))
+ bp->flow_stat->flow_count++;
bnxt_release_flow_lock(bp);
+ bnxt_setup_flow_counter(bp);
+ PMD_DRV_LOG(DEBUG, "Successfully created flow.\n");
return flow;
}
rte_flow_error_set(error, 0,
RTE_FLOW_ERROR_TYPE_NONE, NULL,
"Flow with pattern exists, updating destination queue");
- else
+ else if (!rte_errno)
rte_flow_error_set(error, -ret,
RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
"Failed to create flow.");
/* Tunnel doesn't belong to this VF, so don't send HWRM
* cmd, just delete the flow from driver
*/
- if (bp->fw_fid != (tun_dst_fid + bp->first_vf_id))
+ if (bp->fw_fid != (tun_dst_fid + bp->first_vf_id)) {
PMD_DRV_LOG(ERR,
"Tunnel does not belong to this VF, skip hwrm_tunnel_redirect_free\n");
- else
+ } else {
ret = bnxt_hwrm_tunnel_redirect_free(bp,
filter->tunnel_type);
+ if (ret) {
+ rte_flow_error_set(error, -ret,
+ RTE_FLOW_ERROR_TYPE_HANDLE,
+ NULL,
+ "Unable to free tunnel redirection");
+ return ret;
+ }
+ }
}
return ret;
}
static int
-bnxt_flow_destroy(struct rte_eth_dev *dev,
- struct rte_flow *flow,
- struct rte_flow_error *error)
+_bnxt_flow_destroy(struct bnxt *bp,
+ struct rte_flow *flow,
+ struct rte_flow_error *error)
{
- struct bnxt *bp = dev->data->dev_private;
struct bnxt_filter_info *filter;
struct bnxt_vnic_info *vnic;
int ret = 0;
-
- bnxt_acquire_flow_lock(bp);
- if (!flow) {
- rte_flow_error_set(error, EINVAL,
- RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
- "Invalid flow: failed to destroy flow.");
- bnxt_release_flow_lock(bp);
- return -EINVAL;
- }
+ uint32_t flow_id;
filter = flow->filter;
vnic = flow->vnic;
- if (!filter) {
- rte_flow_error_set(error, EINVAL,
- RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
- "Invalid flow: failed to destroy flow.");
- bnxt_release_flow_lock(bp);
- return -EINVAL;
- }
-
if (filter->filter_type == HWRM_CFA_TUNNEL_REDIRECT_FILTER &&
filter->enables == filter->tunnel_type) {
- ret = bnxt_handle_tunnel_redirect_destroy(bp,
- filter,
- error);
- if (!ret) {
+ ret = bnxt_handle_tunnel_redirect_destroy(bp, filter, error);
+ if (!ret)
goto done;
- } else {
- bnxt_release_flow_lock(bp);
+ else
return ret;
- }
}
+ /* For config type, there is no filter in HW. Finish cleanup here */
+ if (filter->filter_type == HWRM_CFA_CONFIG)
+ goto done;
+
ret = bnxt_match_filter(bp, filter);
if (ret == 0)
PMD_DRV_LOG(ERR, "Could not find matching flow\n");
- if (filter->filter_type == HWRM_CFA_EM_FILTER)
- ret = bnxt_hwrm_clear_em_filter(bp, filter);
- if (filter->filter_type == HWRM_CFA_NTUPLE_FILTER)
- ret = bnxt_hwrm_clear_ntuple_filter(bp, filter);
- ret = bnxt_hwrm_clear_l2_filter(bp, filter);
+ if (filter->valid_flags & BNXT_FLOW_MARK_FLAG) {
+ flow_id = filter->flow_id & BNXT_FLOW_ID_MASK;
+ memset(&bp->mark_table[flow_id], 0,
+ sizeof(bp->mark_table[flow_id]));
+ filter->flow_id = 0;
+ }
+
+ ret = bnxt_clear_one_vnic_filter(bp, filter);
done:
if (!ret) {
bnxt_free_filter(bp, filter);
STAILQ_REMOVE(&vnic->flow_list, flow, rte_flow, next);
rte_free(flow);
+ if (BNXT_FLOW_XSTATS_EN(bp))
+ bp->flow_stat->flow_count--;
/* If this was the last flow associated with this vnic,
* switch the queue back to RSS pool.
*/
if (vnic && !vnic->func_default &&
STAILQ_EMPTY(&vnic->flow_list)) {
- rte_free(vnic->fw_grp_ids);
- if (vnic->rx_queue_cnt > 1)
- bnxt_hwrm_vnic_ctx_free(bp, vnic);
-
- bnxt_hwrm_vnic_free(bp, vnic);
- vnic->rx_queue_cnt = 0;
+ bnxt_vnic_cleanup(bp, vnic);
+ bp->nr_vnics--;
}
} else {
rte_flow_error_set(error, -ret,
"Failed to destroy flow.");
}
+ return ret;
+}
+
+static int
+bnxt_flow_destroy(struct rte_eth_dev *dev,
+ struct rte_flow *flow,
+ struct rte_flow_error *error)
+{
+ struct bnxt *bp = dev->data->dev_private;
+ int ret = 0;
+
+ bnxt_acquire_flow_lock(bp);
+ if (!flow) {
+ rte_flow_error_set(error, EINVAL,
+ RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
+ "Invalid flow: failed to destroy flow.");
+ bnxt_release_flow_lock(bp);
+ return -EINVAL;
+ }
+
+ if (!flow->filter) {
+ rte_flow_error_set(error, EINVAL,
+ RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
+ "Invalid flow: failed to destroy flow.");
+ bnxt_release_flow_lock(bp);
+ return -EINVAL;
+ }
+ ret = _bnxt_flow_destroy(bp, flow, error);
bnxt_release_flow_lock(bp);
+
return ret;
}
+void bnxt_cancel_fc_thread(struct bnxt *bp)
+{
+ bp->flags &= ~BNXT_FLAG_FC_THREAD;
+ rte_eal_alarm_cancel(bnxt_flow_cnt_alarm_cb, (void *)bp);
+}
+
static int
bnxt_flow_flush(struct rte_eth_dev *dev, struct rte_flow_error *error)
{
struct bnxt *bp = dev->data->dev_private;
- struct bnxt_filter_info *filter = NULL;
struct bnxt_vnic_info *vnic;
struct rte_flow *flow;
unsigned int i;
while (!STAILQ_EMPTY(&vnic->flow_list)) {
flow = STAILQ_FIRST(&vnic->flow_list);
- filter = flow->filter;
-
- if (filter->filter_type ==
- HWRM_CFA_TUNNEL_REDIRECT_FILTER &&
- filter->enables == filter->tunnel_type) {
- ret =
- bnxt_handle_tunnel_redirect_destroy(bp,
- filter,
- error);
- if (!ret) {
- goto done;
- } else {
- bnxt_release_flow_lock(bp);
- return ret;
- }
- }
-
- if (filter->filter_type == HWRM_CFA_EM_FILTER)
- ret = bnxt_hwrm_clear_em_filter(bp, filter);
- if (filter->filter_type == HWRM_CFA_NTUPLE_FILTER)
- ret = bnxt_hwrm_clear_ntuple_filter(bp, filter);
- else if (i)
- ret = bnxt_hwrm_clear_l2_filter(bp, filter);
- if (ret) {
- rte_flow_error_set
- (error,
- -ret,
- RTE_FLOW_ERROR_TYPE_HANDLE,
- NULL,
- "Failed to flush flow in HW.");
- bnxt_release_flow_lock(bp);
- return -rte_errno;
- }
-done:
- STAILQ_REMOVE(&vnic->flow_list, flow,
- rte_flow, next);
-
- STAILQ_REMOVE(&vnic->filter,
- filter,
- bnxt_filter_info,
- next);
- bnxt_free_filter(bp, filter);
-
- rte_free(flow);
+ if (!flow->filter)
+ continue;
- /* If this was the last flow associated with this vnic,
- * switch the queue back to RSS pool.
- */
- if (STAILQ_EMPTY(&vnic->flow_list)) {
- rte_free(vnic->fw_grp_ids);
- if (vnic->rx_queue_cnt > 1)
- bnxt_hwrm_vnic_ctx_free(bp, vnic);
- bnxt_hwrm_vnic_free(bp, vnic);
- vnic->rx_queue_cnt = 0;
- }
+ ret = _bnxt_flow_destroy(bp, flow, error);
+ if (ret)
+ break;
}
}
+ bnxt_cancel_fc_thread(bp);
bnxt_release_flow_lock(bp);
+
return ret;
}