X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=drivers%2Fnet%2Fbnxt%2Fbnxt_filter.c;h=9351460c25117b1841170f164ce7d6c0031dd1d5;hb=b22cd7b3c679118ccf817697c4a6839a601d1655;hp=65d30fb38f622d7fbcc5eb4eb85ee65cdc559205;hpb=90cdc91c12563019340c10f32dc0b35b39e5821f;p=dpdk.git diff --git a/drivers/net/bnxt/bnxt_filter.c b/drivers/net/bnxt/bnxt_filter.c index 65d30fb38f..9351460c25 100644 --- a/drivers/net/bnxt/bnxt_filter.c +++ b/drivers/net/bnxt/bnxt_filter.c @@ -1,34 +1,6 @@ -/*- - * BSD LICENSE - * - * Copyright(c) Broadcom Limited. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Broadcom Corporation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2014-2018 Broadcom + * All rights reserved. */ #include @@ -56,7 +28,7 @@ struct bnxt_filter_info *bnxt_alloc_filter(struct bnxt *bp) /* Find the 1st unused filter from the free_filter_list pool*/ filter = STAILQ_FIRST(&bp->free_filter_list); if (!filter) { - RTE_LOG(ERR, PMD, "No more free filter resources\n"); + PMD_DRV_LOG(ERR, "No more free filter resources\n"); return NULL; } STAILQ_REMOVE_HEAD(&bp->free_filter_list, next); @@ -77,7 +49,7 @@ struct bnxt_filter_info *bnxt_alloc_vf_filter(struct bnxt *bp, uint16_t vf) filter = rte_zmalloc("bnxt_vf_filter_info", sizeof(*filter), 0); if (!filter) { - RTE_LOG(ERR, PMD, "Failed to alloc memory for VF %hu filters\n", + PMD_DRV_LOG(ERR, "Failed to alloc memory for VF %hu filters\n", vf); return NULL; } @@ -96,9 +68,9 @@ void bnxt_init_filters(struct bnxt *bp) STAILQ_INIT(&bp->free_filter_list); for (i = 0; i < max_filters; i++) { filter = &bp->filter_info[i]; - filter->fw_l2_filter_id = -1; - filter->fw_em_filter_id = -1; - filter->fw_ntuple_filter_id = -1; + filter->fw_l2_filter_id = UINT64_MAX; + filter->fw_em_filter_id = UINT64_MAX; + filter->fw_ntuple_filter_id = UINT64_MAX; STAILQ_INSERT_TAIL(&bp->free_filter_list, filter, next); } } @@ -145,11 +117,11 @@ void bnxt_free_filter_mem(struct bnxt *bp) for (i = 0; i < max_filters; i++) { filter = &bp->filter_info[i]; if (filter->fw_l2_filter_id != ((uint64_t)-1)) { - RTE_LOG(ERR, PMD, "HWRM filter is not freed??\n"); + PMD_DRV_LOG(ERR, "HWRM filter is not freed??\n"); /* Call HWRM to try to free filter again */ rc = bnxt_hwrm_clear_l2_filter(bp, filter); if (rc) - RTE_LOG(ERR, PMD, + PMD_DRV_LOG(ERR, "HWRM filter cannot be freed rc = %d\n", rc); } @@ -159,6 +131,14 @@ void bnxt_free_filter_mem(struct bnxt *bp) rte_free(bp->filter_info); bp->filter_info = NULL; + + for (i = 0; i < bp->pf.max_vfs; i++) { + STAILQ_FOREACH(filter, &bp->pf.vf_info[i].filter, next) { + rte_free(filter); + STAILQ_REMOVE(&bp->pf.vf_info[i].filter, filter, + bnxt_filter_info, next); + } + } } int bnxt_alloc_filter_mem(struct bnxt *bp) @@ -172,7 +152,7 @@ int bnxt_alloc_filter_mem(struct bnxt *bp) max_filters * sizeof(struct bnxt_filter_info), 0); if (filter_mem == NULL) { - RTE_LOG(ERR, PMD, "Failed to alloc memory for %d filters", + PMD_DRV_LOG(ERR, "Failed to alloc memory for %d filters", max_filters); return -ENOMEM; } @@ -187,7 +167,7 @@ struct bnxt_filter_info *bnxt_get_unused_filter(struct bnxt *bp) /* Find the 1st unused filter from the free_filter_list pool*/ filter = STAILQ_FIRST(&bp->free_filter_list); if (!filter) { - RTE_LOG(ERR, PMD, "No more free filter resources\n"); + PMD_DRV_LOG(ERR, "No more free filter resources\n"); return NULL; } STAILQ_REMOVE_HEAD(&bp->free_filter_list, next); @@ -250,7 +230,7 @@ nxt_non_void_action(const struct rte_flow_action *cur) } } -static inline int check_zero_bytes(const uint8_t *bytes, int len) +int check_zero_bytes(const uint8_t *bytes, int len) { int i; for (i = 0; i < len; i++) @@ -281,7 +261,7 @@ bnxt_filter_type_check(const struct rte_flow_item pattern[], /* FALLTHROUGH */ /* need ntuple match, reset exact match */ if (!use_ntuple) { - RTE_LOG(ERR, PMD, + PMD_DRV_LOG(ERR, "VLAN flow cannot use NTUPLE filter\n"); rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM, @@ -292,7 +272,7 @@ bnxt_filter_type_check(const struct rte_flow_item pattern[], use_ntuple |= 1; break; default: - RTE_LOG(ERR, PMD, "Unknown Flow type"); + PMD_DRV_LOG(ERR, "Unknown Flow type"); use_ntuple |= 1; } item++; @@ -329,7 +309,7 @@ bnxt_validate_and_parse_flow_type(struct bnxt *bp, int dflt_vnic; use_ntuple = bnxt_filter_type_check(pattern, error); - RTE_LOG(DEBUG, PMD, "Use NTUPLE %d\n", use_ntuple); + PMD_DRV_LOG(DEBUG, "Use NTUPLE %d\n", use_ntuple); if (use_ntuple < 0) return use_ntuple; @@ -354,8 +334,8 @@ bnxt_validate_and_parse_flow_type(struct bnxt *bp, } switch (item->type) { case RTE_FLOW_ITEM_TYPE_ETH: - eth_spec = (const struct rte_flow_item_eth *)item->spec; - eth_mask = (const struct rte_flow_item_eth *)item->mask; + eth_spec = item->spec; + eth_mask = item->mask; /* Source MAC address mask cannot be partially set. * Should be All 0's or all 1's. @@ -410,10 +390,8 @@ bnxt_validate_and_parse_flow_type(struct bnxt *bp, break; case RTE_FLOW_ITEM_TYPE_VLAN: - vlan_spec = - (const struct rte_flow_item_vlan *)item->spec; - vlan_mask = - (const struct rte_flow_item_vlan *)item->mask; + vlan_spec = item->spec; + vlan_mask = item->mask; if (vlan_mask->tci & 0xFFFF && !vlan_mask->tpid) { /* Only the VLAN ID can be matched. */ filter->l2_ovlan = @@ -431,10 +409,8 @@ bnxt_validate_and_parse_flow_type(struct bnxt *bp, break; case RTE_FLOW_ITEM_TYPE_IPV4: /* If mask is not involved, we could use EM filters. */ - ipv4_spec = - (const struct rte_flow_item_ipv4 *)item->spec; - ipv4_mask = - (const struct rte_flow_item_ipv4 *)item->mask; + ipv4_spec = item->spec; + ipv4_mask = item->mask; /* Only IP DST and SRC fields are maskable. */ if (ipv4_mask->hdr.version_ihl || ipv4_mask->hdr.type_of_service || @@ -483,10 +459,8 @@ bnxt_validate_and_parse_flow_type(struct bnxt *bp, } break; case RTE_FLOW_ITEM_TYPE_IPV6: - ipv6_spec = - (const struct rte_flow_item_ipv6 *)item->spec; - ipv6_mask = - (const struct rte_flow_item_ipv6 *)item->mask; + ipv6_spec = item->spec; + ipv6_mask = item->mask; /* Only IP DST and SRC fields are maskable. */ if (ipv6_mask->hdr.vtc_flow || @@ -527,8 +501,8 @@ bnxt_validate_and_parse_flow_type(struct bnxt *bp, EM_FLOW_ALLOC_INPUT_IP_ADDR_TYPE_IPV6; break; case RTE_FLOW_ITEM_TYPE_TCP: - tcp_spec = (const struct rte_flow_item_tcp *)item->spec; - tcp_mask = (const struct rte_flow_item_tcp *)item->mask; + tcp_spec = item->spec; + tcp_mask = item->mask; /* Check TCP mask. Only DST & SRC ports are maskable */ if (tcp_mask->hdr.sent_seq || @@ -564,8 +538,8 @@ bnxt_validate_and_parse_flow_type(struct bnxt *bp, } break; case RTE_FLOW_ITEM_TYPE_UDP: - udp_spec = (const struct rte_flow_item_udp *)item->spec; - udp_mask = (const struct rte_flow_item_udp *)item->mask; + udp_spec = item->spec; + udp_mask = item->mask; if (udp_mask->hdr.dgram_len || udp_mask->hdr.dgram_cksum) { @@ -597,10 +571,8 @@ bnxt_validate_and_parse_flow_type(struct bnxt *bp, } break; case RTE_FLOW_ITEM_TYPE_VXLAN: - vxlan_spec = - (const struct rte_flow_item_vxlan *)item->spec; - vxlan_mask = - (const struct rte_flow_item_vxlan *)item->mask; + vxlan_spec = item->spec; + vxlan_mask = item->mask; /* Check if VXLAN item is used to describe protocol. * If yes, both spec and mask should be NULL. * If no, both spec and mask shouldn't be NULL. @@ -646,10 +618,8 @@ bnxt_validate_and_parse_flow_type(struct bnxt *bp, } break; case RTE_FLOW_ITEM_TYPE_NVGRE: - nvgre_spec = - (const struct rte_flow_item_nvgre *)item->spec; - nvgre_mask = - (const struct rte_flow_item_nvgre *)item->mask; + nvgre_spec = item->spec; + nvgre_mask = item->mask; /* Check if NVGRE item is used to describe protocol. * If yes, both spec and mask should be NULL. * If no, both spec and mask shouldn't be NULL. @@ -692,7 +662,7 @@ bnxt_validate_and_parse_flow_type(struct bnxt *bp, } break; case RTE_FLOW_ITEM_TYPE_VF: - vf_spec = (const struct rte_flow_item_vf *)item->spec; + vf_spec = item->spec; vf = vf_spec->id; if (!BNXT_PF(bp)) { rte_flow_error_set(error, EINVAL, @@ -791,7 +761,7 @@ bnxt_get_l2_filter(struct bnxt *bp, struct bnxt_filter_info *nf, return f0; //This flow needs DST MAC which is not same as port/l2 - RTE_LOG(DEBUG, PMD, "Create L2 filter for DST MAC\n"); + PMD_DRV_LOG(DEBUG, "Create L2 filter for DST MAC\n"); filter1 = bnxt_get_unused_filter(bp); if (filter1 == NULL) return NULL; @@ -806,7 +776,6 @@ bnxt_get_l2_filter(struct bnxt *bp, struct bnxt_filter_info *nf, bnxt_free_filter(bp, filter1); return NULL; } - STAILQ_INSERT_TAIL(&vnic->filter, filter1, next); return filter1; } @@ -829,7 +798,7 @@ bnxt_validate_and_parse_flow(struct rte_eth_dev *dev, int rc; if (bp->eth_dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS) { - RTE_LOG(ERR, PMD, "Cannot create flow on RSS queues\n"); + PMD_DRV_LOG(ERR, "Cannot create flow on RSS queues\n"); rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, "Cannot create flow on RSS queues"); @@ -845,7 +814,8 @@ bnxt_validate_and_parse_flow(struct rte_eth_dev *dev, if (rc != 0) goto ret; //Since we support ingress attribute only - right now. - filter->flags = HWRM_CFA_EM_FLOW_ALLOC_INPUT_FLAGS_PATH_RX; + if (filter->filter_type == HWRM_CFA_EM_FILTER) + filter->flags = HWRM_CFA_EM_FLOW_ALLOC_INPUT_FLAGS_PATH_RX; switch (act->type) { case RTE_FLOW_ACTION_TYPE_QUEUE: @@ -858,7 +828,7 @@ bnxt_validate_and_parse_flow(struct rte_eth_dev *dev, rc = -rte_errno; goto ret; } - RTE_LOG(DEBUG, PMD, "Queue index %d\n", act_q->index); + PMD_DRV_LOG(DEBUG, "Queue index %d\n", act_q->index); vnic0 = STAILQ_FIRST(&bp->ff_pool[0]); vnic = STAILQ_FIRST(&bp->ff_pool[act_q->index]); @@ -876,7 +846,7 @@ bnxt_validate_and_parse_flow(struct rte_eth_dev *dev, goto ret; } filter->fw_l2_filter_id = filter1->fw_l2_filter_id; - RTE_LOG(DEBUG, PMD, "VNIC found\n"); + PMD_DRV_LOG(DEBUG, "VNIC found\n"); break; case RTE_FLOW_ACTION_TYPE_DROP: vnic0 = STAILQ_FIRST(&bp->ff_pool[0]); @@ -957,7 +927,6 @@ bnxt_validate_and_parse_flow(struct rte_eth_dev *dev, goto ret; } -//done: act = nxt_non_void_action(++act); if (act->type != RTE_FLOW_ACTION_TYPE_END) { rte_flow_error_set(error, EINVAL, @@ -987,14 +956,14 @@ bnxt_flow_validate(struct rte_eth_dev *dev, filter = bnxt_get_unused_filter(bp); if (filter == NULL) { - RTE_LOG(ERR, PMD, "Not enough resources for a new flow.\n"); + PMD_DRV_LOG(ERR, "Not enough resources for a new flow.\n"); return -ENOMEM; } ret = bnxt_validate_and_parse_flow(dev, pattern, actions, attr, error, filter); /* No need to hold on to this filter if we are just validating flow */ - filter->fw_l2_filter_id = -1; + filter->fw_l2_filter_id = UINT64_MAX; bnxt_free_filter(bp, filter); return ret; @@ -1042,8 +1011,23 @@ bnxt_match_filter(struct bnxt *bp, struct bnxt_filter_info *nf) !memcmp(mf->dst_ipaddr, nf->dst_ipaddr, sizeof(nf->dst_ipaddr)) && !memcmp(mf->dst_ipaddr_mask, nf->dst_ipaddr_mask, - sizeof(nf->dst_ipaddr_mask))) - return -EEXIST; + sizeof(nf->dst_ipaddr_mask))) { + if (mf->dst_id == nf->dst_id) + return -EEXIST; + /* Same Flow, Different queue + * Clear the old ntuple filter + */ + if (nf->filter_type == HWRM_CFA_EM_FILTER) + bnxt_hwrm_clear_em_filter(bp, mf); + if (nf->filter_type == HWRM_CFA_NTUPLE_FILTER) + bnxt_hwrm_clear_ntuple_filter(bp, mf); + /* Free the old filter, update flow + * with new filter + */ + bnxt_free_filter(bp, mf); + flow->filter = nf; + return -EXDEV; + } } } return 0; @@ -1059,6 +1043,7 @@ bnxt_flow_create(struct rte_eth_dev *dev, struct bnxt *bp = (struct bnxt *)dev->data->dev_private; struct bnxt_filter_info *filter; struct bnxt_vnic_info *vnic = NULL; + bool update_flow = false; struct rte_flow *flow; unsigned int i; int ret = 0; @@ -1073,13 +1058,13 @@ bnxt_flow_create(struct rte_eth_dev *dev, ret = bnxt_flow_agrs_validate(attr, pattern, actions, error); if (ret != 0) { - RTE_LOG(ERR, PMD, "Not a validate flow.\n"); + PMD_DRV_LOG(ERR, "Not a validate flow.\n"); goto free_flow; } filter = bnxt_get_unused_filter(bp); if (filter == NULL) { - RTE_LOG(ERR, PMD, "Not enough resources for a new flow.\n"); + PMD_DRV_LOG(ERR, "Not enough resources for a new flow.\n"); goto free_flow; } @@ -1089,9 +1074,17 @@ bnxt_flow_create(struct rte_eth_dev *dev, goto free_filter; ret = bnxt_match_filter(bp, filter); - if (ret != 0) { - RTE_LOG(DEBUG, PMD, "Flow already exists.\n"); + if (ret == -EEXIST) { + PMD_DRV_LOG(DEBUG, "Flow already exists.\n"); + /* Clear the filter that was created as part of + * validate_and_parse_flow() above + */ + bnxt_hwrm_clear_l2_filter(bp, filter); goto free_filter; + } else if (ret == -EXDEV) { + PMD_DRV_LOG(DEBUG, "Flow with same pattern exists"); + PMD_DRV_LOG(DEBUG, "Updating with different destination\n"); + update_flow = true; } if (filter->filter_type == HWRM_CFA_EM_FILTER) { @@ -1114,22 +1107,29 @@ bnxt_flow_create(struct rte_eth_dev *dev, if (!ret) { flow->filter = filter; flow->vnic = vnic; - RTE_LOG(ERR, PMD, "Successfully created flow.\n"); + if (update_flow) { + ret = -EXDEV; + goto free_flow; + } + PMD_DRV_LOG(ERR, "Successfully created flow.\n"); STAILQ_INSERT_TAIL(&vnic->flow_list, flow, next); return flow; } free_filter: - filter->fw_l2_filter_id = -1; bnxt_free_filter(bp, filter); free_flow: if (ret == -EEXIST) rte_flow_error_set(error, ret, RTE_FLOW_ERROR_TYPE_HANDLE, NULL, "Matching Flow exists."); + else if (ret == -EXDEV) + rte_flow_error_set(error, ret, + RTE_FLOW_ERROR_TYPE_HANDLE, NULL, + "Flow with pattern exists, updating destination queue"); else rte_flow_error_set(error, -ret, RTE_FLOW_ERROR_TYPE_HANDLE, NULL, - "Failed to create flow."); + "Failed to create flow."); rte_free(flow); flow = NULL; return flow; @@ -1147,12 +1147,13 @@ bnxt_flow_destroy(struct rte_eth_dev *dev, ret = bnxt_match_filter(bp, filter); if (ret == 0) - RTE_LOG(ERR, PMD, "Could not find matching flow\n"); + 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); - + else + ret = bnxt_hwrm_clear_l2_filter(bp, filter); if (!ret) { STAILQ_REMOVE(&vnic->flow_list, flow, rte_flow, next); rte_free(flow);