[dpdk-dev] [PATCH v2 09/40] bnxt: add L2 filter alloc/init/free

2016-05-25 Thread Bruce Richardson
On Fri, May 13, 2016 at 03:45:58PM -0700, Stephen Hurd wrote:
> Add the L2 filter structure and the alloc/init/free functions for
> dealing with them.
> 

The DPDK ethdev API has filtering APIs, but this code is not made accessible
via those APIs. If that link is added via later patches, then that should be
documented in the commit message here.


> +/* hwrm_cfa_l2_filter_alloc */
> +/*
> + * Description: An L2 filter is a filter resource that is used to identify a
> + * vnic or ring for a packet based on layer 2 fields. Layer 2 fields for
> + * encapsulated packets include both outer L2 header and/or inner l2 header 
> of
> + * encapsulated packet. The L2 filter resource covers the following OS 
> specific
> + * L2 filters. Linux/FreeBSD (per function): # Broadcast enable/disable # 
> List
> + * of individual multicast filters # All multicast enable/disable filter #
> + * Unicast filters # Promiscuous mode VMware: # Broadcast enable/disable (per
> + * physical function) # All multicast enable/disable (per function) # Unicast
> + * filters per ring or vnic # Promiscuous mode per PF Windows: # Broadcast
> + * enable/disable (per physical function) # List of individual multicast 
> filters
> + * (Driver needs to advertise the maximum number of filters supported) # All
> + * multicast enable/disable per physical function # Unicast filters per vnic 
> #
> + * Promiscuous mode per PF Implementation notes on the use of VNIC in this
> + * command: # By default, these filters belong to default vnic for the 
> function.
> + * # Once these filters are set up, only destination VNIC can be modified. # 
> If
> + * the destination VNIC is not specified in this command, then the HWRM shall
> + * only create an l2 context id. HWRM Implementation notes for multicast
> + * filters: # The hwrm_filter_alloc command can be used to set up multicast
> + * filters (perfect match or partial match). Each individual function driver 
> can
> + * set up multicast filters independently. # The HWRM needs to keep track of
> + * multicast filters set up by function drivers and maintain multicast group
> + * replication records to enable a subset of functions to receive traffic 
> for a
> + * specific multicast address. # When a specific multicast filter cannot be 
> set,
> + * the HWRM shall return an error. In this error case, the driver should fall
> + * back to using one general filter (rather than specific) for all multicast
> + * traffic. # When the SR-IOV is enabled, the HWRM needs to additionally 
> track
> + * source knockout per multicast group record. Examples of setting unicast
> + * filters: For a unicast MAC based filter, one can use a combination of the
> + * fields and masks provided in this command to set up the filter. Below are
> + * some examples: # MAC + no VLAN filter: This filter is used to identify
> + * traffic that does not contain any VLAN tags and matches destination (or
> + * source) MAC address. This filter can be set up by setting only l2_addr 
> field
> + * to be a valid field. All other fields are not valid. The following value 
> is
> + * set for l2_addr. l2_addr = MAC # MAC + Any VLAN filter: This filter is 
> used
> + * to identify traffic that carries single VLAN tag and matches (destination 
> or
> + * source) MAC address. This filter can be set up by setting only l2_addr and
> + * l2_ovlan_mask fields to be valid fields. All other fields are not valid. 
> The
> + * following values are set for those two valid fields. l2_addr = MAC,
> + * l2_ovlan_mask = 0x # MAC + no VLAN or VLAN ID=0: This filter is used 
> to
> + * identify untagged traffic that does not contain any VLAN tags or a VLAN 
> tag
> + * with VLAN ID = 0 and matches destination (or source) MAC address. This 
> filter
> + * can be set up by setting only l2_addr and l2_ovlan fields to be valid 
> fields.
> + * All other fields are not valid. The following value are set for l2_addr 
> and
> + * l2_ovlan. l2_addr = MAC, l2_ovlan = 0x0 # MAC + no VLAN or any VLAN: This
> + * filter is used to identify traffic that contains zero or 1 VLAN tag and
> + * matches destination (or source) MAC address. This filter can be set up by
> + * setting only l2_addr, l2_ovlan, and l2_mask fields to be valid fields. All
> + * other fields are not valid. The following value are set for l2_addr,
> + * l2_ovlan, and l2_mask fields. l2_addr = MAC, l2_ovlan = 0x0, 
> l2_ovlan_mask =
> + * 0x # MAC + VLAN ID filter: This filter can be set up by setting only
> + * l2_addr, l2_ovlan, and l2_ovlan_mask fields to be valid fields. All other
> + * fields are not valid. The following values are set for those three valid
> + * fields. l2_addr = MAC, l2_ovlan = VLAN ID, l2_ovlan_mask = 0xF000
> + */
This comment could do with clean-up to improve formatting and readability. I'm
also not sure that an explanation of this size is best placed as a comment on
a function. However, I'm also not sure where this information is best placed as
these filter functions are all 

[dpdk-dev] [PATCH v2 09/40] bnxt: add L2 filter alloc/init/free

2016-05-13 Thread Stephen Hurd
Add the L2 filter structure and the alloc/init/free functions for
dealing with them.

Signed-off-by: Stephen Hurd 
Reviewed-by: Ajit Kumar Khaparde 
---
 drivers/net/bnxt/Makefile  |   1 +
 drivers/net/bnxt/bnxt.h|   3 +
 drivers/net/bnxt/bnxt_filter.c | 175 
 drivers/net/bnxt/bnxt_filter.h |  74 +
 drivers/net/bnxt/bnxt_hwrm.c   |  21 ++
 drivers/net/bnxt/bnxt_hwrm.h   |   3 +
 drivers/net/bnxt/hsi_struct_def_dpdk.h | 505 +
 7 files changed, 782 insertions(+)
 create mode 100644 drivers/net/bnxt/bnxt_filter.c
 create mode 100644 drivers/net/bnxt/bnxt_filter.h

diff --git a/drivers/net/bnxt/Makefile b/drivers/net/bnxt/Makefile
index afd1690..b7834b1 100644
--- a/drivers/net/bnxt/Makefile
+++ b/drivers/net/bnxt/Makefile
@@ -50,6 +50,7 @@ EXPORT_MAP := rte_pmd_bnxt_version.map
 #
 SRCS-$(CONFIG_RTE_LIBRTE_BNXT_PMD) += bnxt_cpr.c
 SRCS-$(CONFIG_RTE_LIBRTE_BNXT_PMD) += bnxt_ethdev.c
+SRCS-$(CONFIG_RTE_LIBRTE_BNXT_PMD) += bnxt_filter.c
 SRCS-$(CONFIG_RTE_LIBRTE_BNXT_PMD) += bnxt_hwrm.c
 SRCS-$(CONFIG_RTE_LIBRTE_BNXT_PMD) += bnxt_ring.c
 SRCS-$(CONFIG_RTE_LIBRTE_BNXT_PMD) += bnxt_vnic.c
diff --git a/drivers/net/bnxt/bnxt.h b/drivers/net/bnxt/bnxt.h
index 4e0b514..54ddd24 100644
--- a/drivers/net/bnxt/bnxt.h
+++ b/drivers/net/bnxt/bnxt.h
@@ -146,6 +146,9 @@ struct bnxt {
struct bnxt_vnic_info   *vnic_info;
STAILQ_HEAD(, bnxt_vnic_info)   free_vnic_list;

+   struct bnxt_filter_info *filter_info;
+   STAILQ_HEAD(, bnxt_filter_info) free_filter_list;
+
/* VNIC pointer for flow filter (VMDq) pools */
 #define MAX_FF_POOLS   ETH_64_POOLS
STAILQ_HEAD(, bnxt_vnic_info)   ff_pool[MAX_FF_POOLS];
diff --git a/drivers/net/bnxt/bnxt_filter.c b/drivers/net/bnxt/bnxt_filter.c
new file mode 100644
index 000..f03a1dc
--- /dev/null
+++ b/drivers/net/bnxt/bnxt_filter.c
@@ -0,0 +1,175 @@
+/*-
+ *   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.
+ */
+
+#include 
+
+#include 
+#include 
+
+#include "bnxt.h"
+#include "bnxt_filter.h"
+#include "bnxt_hwrm.h"
+#include "bnxt_vnic.h"
+#include "hsi_struct_def_dpdk.h"
+
+/*
+ * Filter Functions
+ */
+
+struct bnxt_filter_info *bnxt_alloc_filter(struct bnxt *bp)
+{
+   struct bnxt_filter_info *filter;
+
+   /* Find the 1st unused filter from the free_filter_list pool*/
+   filter = STAILQ_FIRST(>free_filter_list);
+   if (!filter) {
+   RTE_LOG(ERR, PMD, "No more free filter resources\n");
+   return NULL;
+   }
+   STAILQ_REMOVE_HEAD(>free_filter_list, next);
+
+   /* Default to L2 MAC Addr filter */
+   filter->flags = HWRM_CFA_L2_FILTER_ALLOC_INPUT_FLAGS_PATH_RX;
+   filter->enables = HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_ADDR |
+   HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_ADDR_MASK;
+   memcpy(filter->l2_addr, bp->eth_dev->data->mac_addrs->addr_bytes,
+  ETHER_ADDR_LEN);
+   memset(filter->l2_addr_mask, 0xff, ETHER_ADDR_LEN);
+   return filter;
+}
+
+void bnxt_init_filters(struct bnxt *bp)
+{
+   struct bnxt_filter_info *filter;
+   int i, max_filters;
+
+   if (BNXT_PF(bp)) {
+   struct bnxt_pf_info *pf = >pf;
+
+   max_filters = pf->max_l2_ctx;
+   } else {
+   struct