net/cxgbe: use firmware API for validating filter spec
[dpdk.git] / drivers / net / cxgbe / cxgbe_filter.c
index 4d3f3eb..27e96c7 100644 (file)
@@ -3,17 +3,19 @@
  * All rights reserved.
  */
 #include <rte_net.h>
-#include "common.h"
-#include "t4_tcb.h"
-#include "t4_regs.h"
+
+#include "base/common.h"
+#include "base/t4_tcb.h"
+#include "base/t4_regs.h"
 #include "cxgbe_filter.h"
 #include "clip_tbl.h"
 #include "l2t.h"
+#include "smt.h"
 
 /**
  * Initialize Hash Filters
  */
-int init_hash_filter(struct adapter *adap)
+int cxgbe_init_hash_filter(struct adapter *adap)
 {
        unsigned int n_user_filters;
        unsigned int user_filter_perc;
@@ -52,21 +54,38 @@ int init_hash_filter(struct adapter *adap)
  * Validate if the requested filter specification can be set by checking
  * if the requested features have been enabled
  */
-int validate_filter(struct adapter *adapter, struct ch_filter_specification *fs)
+int cxgbe_validate_filter(struct adapter *adapter,
+                         struct ch_filter_specification *fs)
 {
-       u32 fconf;
+       u32 fconf, iconf;
 
        /*
         * Check for unconfigured fields being used.
         */
-       fconf = adapter->params.tp.vlan_pri_map;
+       fconf = fs->cap ? adapter->params.tp.filter_mask :
+                         adapter->params.tp.vlan_pri_map;
+
+       iconf = adapter->params.tp.ingress_config;
 
 #define S(_field) \
        (fs->val._field || fs->mask._field)
 #define U(_mask, _field) \
        (!(fconf & (_mask)) && S(_field))
 
-       if (U(F_PORT, iport) || U(F_ETHERTYPE, ethtype) || U(F_PROTOCOL, proto))
+       if (U(F_PORT, iport) || U(F_ETHERTYPE, ethtype) ||
+           U(F_PROTOCOL, proto) || U(F_MACMATCH, macidx) ||
+           U(F_VLAN, ivlan_vld) || U(F_VNIC_ID, ovlan_vld) ||
+           U(F_TOS, tos) || U(F_VNIC_ID, pfvf_vld))
+               return -EOPNOTSUPP;
+
+       /* Either OVLAN or PFVF match is enabled in hardware, but not both */
+       if ((S(pfvf_vld) && !(iconf & F_VNIC)) ||
+           (S(ovlan_vld) && (iconf & F_VNIC)))
+               return -EOPNOTSUPP;
+
+       /* To use OVLAN or PFVF, L4 encapsulation match must not be enabled */
+       if ((S(ovlan_vld) && (iconf & F_USE_ENC_IDX)) ||
+           (S(pfvf_vld) && (iconf & F_USE_ENC_IDX)))
                return -EOPNOTSUPP;
 
 #undef S
@@ -88,6 +107,12 @@ int validate_filter(struct adapter *adapter, struct ch_filter_specification *fs)
        if (fs->val.iport >= adapter->params.nports)
                return -ERANGE;
 
+       if (!fs->cap && fs->nat_mode && !adapter->params.filter2_wr_support)
+               return -EOPNOTSUPP;
+
+       if (!fs->cap && fs->swapmac && !adapter->params.filter2_wr_support)
+               return -EOPNOTSUPP;
+
        return 0;
 }
 
@@ -125,7 +150,7 @@ static unsigned int get_filter_steerq(struct rte_eth_dev *dev,
 }
 
 /* Return an error number if the indicated filter isn't writable ... */
-int writable_filter(struct filter_entry *f)
+static int writable_filter(struct filter_entry *f)
 {
        if (f->locked)
                return -EPERM;
@@ -204,20 +229,32 @@ static inline void mk_set_tcb_field_ulp(struct filter_entry *f,
 }
 
 /**
- * Check if entry already filled.
+ * IPv6 requires 2 slots on T6 and 4 slots for cards below T6.
+ * IPv4 requires only 1 slot on all cards.
  */
-bool is_filter_set(struct tid_info *t, int fidx, int family)
+u8 cxgbe_filter_slots(struct adapter *adap, u8 family)
 {
-       bool result = FALSE;
-       int i, max;
+       if (family == FILTER_TYPE_IPV6) {
+               if (CHELSIO_CHIP_VERSION(adap->params.chip) < CHELSIO_T6)
+                       return 4;
 
-       /* IPv6 requires four slots and IPv4 requires only 1 slot.
-        * Ensure, there's enough slots available.
-        */
-       max = family == FILTER_TYPE_IPV6 ? fidx + 3 : fidx;
+               return 2;
+       }
+
+       return 1;
+}
 
+/**
+ * Check if entries are already filled.
+ */
+bool cxgbe_is_filter_set(struct tid_info *t, u32 fidx, u8 nentries)
+{
+       bool result = FALSE;
+       u32 i;
+
+       /* Ensure there's enough slots available. */
        t4_os_lock(&t->ftid_lock);
-       for (i = fidx; i <= max; i++) {
+       for (i = fidx; i < fidx + nentries; i++) {
                if (rte_bitmap_get(t->ftid_bmap, i)) {
                        result = TRUE;
                        break;
@@ -228,17 +265,18 @@ bool is_filter_set(struct tid_info *t, int fidx, int family)
 }
 
 /**
- * Allocate a available free entry
+ * Allocate available free entries.
  */
-int cxgbe_alloc_ftid(struct adapter *adap, unsigned int family)
+int cxgbe_alloc_ftid(struct adapter *adap, u8 nentries)
 {
        struct tid_info *t = &adap->tids;
        int pos;
        int size = t->nftids;
 
        t4_os_lock(&t->ftid_lock);
-       if (family == FILTER_TYPE_IPV6)
-               pos = cxgbe_bitmap_find_free_region(t->ftid_bmap, size, 4);
+       if (nentries > 1)
+               pos = cxgbe_bitmap_find_free_region(t->ftid_bmap, size,
+                                                   nentries);
        else
                pos = cxgbe_find_first_zero_bit(t->ftid_bmap, size);
        t4_os_unlock(&t->ftid_lock);
@@ -256,8 +294,8 @@ static u64 hash_filter_ntuple(const struct filter_entry *f)
        u64 ntuple = 0;
        u16 tcp_proto = IPPROTO_TCP; /* TCP Protocol Number */
 
-       if (tp->port_shift >= 0)
-               ntuple |= (u64)f->fs.mask.iport << tp->port_shift;
+       if (tp->port_shift >= 0 && f->fs.mask.iport)
+               ntuple |= (u64)f->fs.val.iport << tp->port_shift;
 
        if (tp->protocol_shift >= 0) {
                if (!f->fs.val.proto)
@@ -268,9 +306,24 @@ static u64 hash_filter_ntuple(const struct filter_entry *f)
 
        if (tp->ethertype_shift >= 0 && f->fs.mask.ethtype)
                ntuple |= (u64)(f->fs.val.ethtype) << tp->ethertype_shift;
-
-       if (ntuple != tp->hash_filter_mask)
-               return 0;
+       if (tp->macmatch_shift >= 0 && f->fs.mask.macidx)
+               ntuple |= (u64)(f->fs.val.macidx) << tp->macmatch_shift;
+       if (tp->vlan_shift >= 0 && f->fs.mask.ivlan)
+               ntuple |= (u64)(F_FT_VLAN_VLD | f->fs.val.ivlan) <<
+                         tp->vlan_shift;
+       if (tp->vnic_shift >= 0) {
+               if ((adap->params.tp.ingress_config & F_VNIC) &&
+                   f->fs.mask.pfvf_vld)
+                       ntuple |= (u64)(f->fs.val.pfvf_vld << 16 |
+                                       f->fs.val.pf << 13 | f->fs.val.vf) <<
+                                       tp->vnic_shift;
+               else if (!(adap->params.tp.ingress_config & F_VNIC) &&
+                        f->fs.mask.ovlan_vld)
+                       ntuple |= (u64)(f->fs.val.ovlan_vld << 16 |
+                                       f->fs.val.ovlan) << tp->vnic_shift;
+       }
+       if (tp->tos_shift >= 0 && f->fs.mask.tos)
+               ntuple |= (u64)f->fs.val.tos << tp->tos_shift;
 
        return ntuple;
 }
@@ -450,6 +503,7 @@ static void mk_act_open_req6(struct filter_entry *f, struct rte_mbuf *mbuf,
                            V_RSS_QUEUE(f->fs.iq) |
                            F_T5_OPT_2_VALID |
                            F_RX_CHANNEL |
+                           V_SACK_EN(f->fs.swapmac) |
                            V_CONG_CNTRL((f->fs.action == FILTER_DROP) |
                                         (f->fs.dirsteer << 1)) |
                            V_CCTRL_ECN(f->fs.action == FILTER_SWITCH));
@@ -496,6 +550,7 @@ static void mk_act_open_req(struct filter_entry *f, struct rte_mbuf *mbuf,
                            V_RSS_QUEUE(f->fs.iq) |
                            F_T5_OPT_2_VALID |
                            F_RX_CHANNEL |
+                           V_SACK_EN(f->fs.swapmac) |
                            V_CONG_CNTRL((f->fs.action == FILTER_DROP) |
                                         (f->fs.dirsteer << 1)) |
                            V_CCTRL_ECN(f->fs.action == FILTER_SWITCH));
@@ -518,7 +573,7 @@ static int cxgbe_set_hash_filter(struct rte_eth_dev *dev,
        int atid, size;
        int ret = 0;
 
-       ret = validate_filter(adapter, fs);
+       ret = cxgbe_validate_filter(adapter, fs);
        if (ret)
                return ret;
 
@@ -540,7 +595,7 @@ static int cxgbe_set_hash_filter(struct rte_eth_dev *dev,
         * rewriting then we need to allocate a Layer 2 Table (L2T) entry for
         * the filter.
         */
-       if (f->fs.newvlan == VLAN_INSERT ||
+       if (f->fs.newdmac || f->fs.newvlan == VLAN_INSERT ||
            f->fs.newvlan == VLAN_REWRITE) {
                /* allocate L2T entry for new filter */
                f->l2t = cxgbe_l2t_alloc_switching(dev, f->fs.vlan,
@@ -551,11 +606,22 @@ static int cxgbe_set_hash_filter(struct rte_eth_dev *dev,
                }
        }
 
+       /* If the new filter requires Source MAC rewriting then we need to
+        * allocate a SMT entry for the filter
+        */
+       if (f->fs.newsmac) {
+               f->smt = cxgbe_smt_alloc_switching(f->dev, f->fs.smac);
+               if (!f->smt) {
+                       ret = -EAGAIN;
+                       goto out_err;
+               }
+       }
+
        atid = cxgbe_alloc_atid(t, f);
        if (atid < 0)
                goto out_err;
 
-       if (f->fs.type) {
+       if (f->fs.type == FILTER_TYPE_IPV6) {
                /* IPv6 hash filter */
                f->clipt = cxgbe_clip_alloc(f->dev, (u32 *)&f->fs.val.lip);
                if (!f->clipt)
@@ -609,7 +675,7 @@ out_err:
  * Clear a filter and release any of its resources that we own.  This also
  * clears the filter's "pending" status.
  */
-void clear_filter(struct filter_entry *f)
+static void clear_filter(struct filter_entry *f)
 {
        if (f->clipt)
                cxgbe_clip_release(f->dev, f->clipt);
@@ -624,6 +690,7 @@ void clear_filter(struct filter_entry *f)
 
 /**
  * t4_mk_filtdelwr - create a delete filter WR
+ * @adap: adapter context
  * @ftid: the filter ID
  * @wr: the filter work request to populate
  * @qid: ingress queue to receive the delete notification
@@ -631,10 +698,14 @@ void clear_filter(struct filter_entry *f)
  * Creates a filter work request to delete the supplied filter.  If @qid is
  * negative the delete notification is suppressed.
  */
-static void t4_mk_filtdelwr(unsigned int ftid, struct fw_filter_wr *wr, int qid)
+static void t4_mk_filtdelwr(struct adapter *adap, unsigned int ftid,
+                           struct fw_filter2_wr *wr, int qid)
 {
        memset(wr, 0, sizeof(*wr));
-       wr->op_pkd = cpu_to_be32(V_FW_WR_OP(FW_FILTER_WR));
+       if (adap->params.filter2_wr_support)
+               wr->op_pkd = cpu_to_be32(V_FW_WR_OP(FW_FILTER2_WR));
+       else
+               wr->op_pkd = cpu_to_be32(V_FW_WR_OP(FW_FILTER_WR));
        wr->len16_pkd = cpu_to_be32(V_FW_WR_LEN16(sizeof(*wr) / 16));
        wr->tid_to_iq = cpu_to_be32(V_FW_FILTER_WR_TID(ftid) |
                                    V_FW_FILTER_WR_NOREPLY(qid < 0));
@@ -652,7 +723,7 @@ static int del_filter_wr(struct rte_eth_dev *dev, unsigned int fidx)
        struct adapter *adapter = ethdev2adap(dev);
        struct filter_entry *f = &adapter->tids.ftid_tab[fidx];
        struct rte_mbuf *mbuf;
-       struct fw_filter_wr *fwr;
+       struct fw_filter2_wr *fwr;
        struct sge_ctrl_txq *ctrlq;
        unsigned int port_id = ethdev2pinfo(dev)->port_id;
 
@@ -664,8 +735,8 @@ static int del_filter_wr(struct rte_eth_dev *dev, unsigned int fidx)
        mbuf->data_len = sizeof(*fwr);
        mbuf->pkt_len = mbuf->data_len;
 
-       fwr = rte_pktmbuf_mtod(mbuf, struct fw_filter_wr *);
-       t4_mk_filtdelwr(f->tid, fwr, adapter->sge.fw_evtq.abs_id);
+       fwr = rte_pktmbuf_mtod(mbuf, struct fw_filter2_wr *);
+       t4_mk_filtdelwr(adapter, f->tid, fwr, adapter->sge.fw_evtq.abs_id);
 
        /*
         * Mark the filter as "pending" and ship off the Filter Work Request.
@@ -676,12 +747,12 @@ static int del_filter_wr(struct rte_eth_dev *dev, unsigned int fidx)
        return 0;
 }
 
-int set_filter_wr(struct rte_eth_dev *dev, unsigned int fidx)
+static int set_filter_wr(struct rte_eth_dev *dev, unsigned int fidx)
 {
        struct adapter *adapter = ethdev2adap(dev);
        struct filter_entry *f = &adapter->tids.ftid_tab[fidx];
        struct rte_mbuf *mbuf;
-       struct fw_filter_wr *fwr;
+       struct fw_filter2_wr *fwr;
        struct sge_ctrl_txq *ctrlq;
        unsigned int port_id = ethdev2pinfo(dev)->port_id;
        int ret;
@@ -691,14 +762,29 @@ int set_filter_wr(struct rte_eth_dev *dev, unsigned int fidx)
         * rewriting then we need to allocate a Layer 2 Table (L2T) entry for
         * the filter.
         */
-       if (f->fs.newvlan) {
+       if (f->fs.newvlan || f->fs.newdmac) {
                /* allocate L2T entry for new filter */
                f->l2t = cxgbe_l2t_alloc_switching(f->dev, f->fs.vlan,
                                                   f->fs.eport, f->fs.dmac);
+
                if (!f->l2t)
                        return -ENOMEM;
        }
 
+       /* If the new filter requires Source MAC rewriting then we need to
+        * allocate a SMT entry for the filter
+        */
+       if (f->fs.newsmac) {
+               f->smt = cxgbe_smt_alloc_switching(f->dev, f->fs.smac);
+               if (!f->smt) {
+                       if (f->l2t) {
+                               cxgbe_l2t_release(f->l2t);
+                               f->l2t = NULL;
+                       }
+                       return -ENOMEM;
+               }
+       }
+
        ctrlq = &adapter->sge.ctrlq[port_id];
        mbuf = rte_pktmbuf_alloc(ctrlq->mb_pool);
        if (!mbuf) {
@@ -709,13 +795,16 @@ int set_filter_wr(struct rte_eth_dev *dev, unsigned int fidx)
        mbuf->data_len = sizeof(*fwr);
        mbuf->pkt_len = mbuf->data_len;
 
-       fwr = rte_pktmbuf_mtod(mbuf, struct fw_filter_wr *);
+       fwr = rte_pktmbuf_mtod(mbuf, struct fw_filter2_wr *);
        memset(fwr, 0, sizeof(*fwr));
 
        /*
         * Construct the work request to set the filter.
         */
-       fwr->op_pkd = cpu_to_be32(V_FW_WR_OP(FW_FILTER_WR));
+       if (adapter->params.filter2_wr_support)
+               fwr->op_pkd = cpu_to_be32(V_FW_WR_OP(FW_FILTER2_WR));
+       else
+               fwr->op_pkd = cpu_to_be32(V_FW_WR_OP(FW_FILTER_WR));
        fwr->len16_pkd = cpu_to_be32(V_FW_WR_LEN16(sizeof(*fwr) / 16));
        fwr->tid_to_iq =
                cpu_to_be32(V_FW_FILTER_WR_TID(f->tid) |
@@ -726,6 +815,8 @@ int set_filter_wr(struct rte_eth_dev *dev, unsigned int fidx)
                cpu_to_be32(V_FW_FILTER_WR_DROP(f->fs.action == FILTER_DROP) |
                            V_FW_FILTER_WR_DIRSTEER(f->fs.dirsteer) |
                            V_FW_FILTER_WR_LPBK(f->fs.action == FILTER_SWITCH) |
+                           V_FW_FILTER_WR_SMAC(f->fs.newsmac) |
+                           V_FW_FILTER_WR_DMAC(f->fs.newdmac) |
                            V_FW_FILTER_WR_INSVLAN
                                (f->fs.newvlan == VLAN_INSERT ||
                                 f->fs.newvlan == VLAN_REWRITE) |
@@ -738,16 +829,29 @@ int set_filter_wr(struct rte_eth_dev *dev, unsigned int fidx)
                            V_FW_FILTER_WR_L2TIX(f->l2t ? f->l2t->idx : 0));
        fwr->ethtype = cpu_to_be16(f->fs.val.ethtype);
        fwr->ethtypem = cpu_to_be16(f->fs.mask.ethtype);
-       fwr->smac_sel = 0;
+       fwr->frag_to_ovlan_vldm =
+               (V_FW_FILTER_WR_IVLAN_VLD(f->fs.val.ivlan_vld) |
+                V_FW_FILTER_WR_IVLAN_VLDM(f->fs.mask.ivlan_vld) |
+                V_FW_FILTER_WR_OVLAN_VLD(f->fs.val.ovlan_vld) |
+                V_FW_FILTER_WR_OVLAN_VLDM(f->fs.mask.ovlan_vld));
+       fwr->smac_sel = f->smt ? f->smt->hw_idx : 0;
        fwr->rx_chan_rx_rpl_iq =
                cpu_to_be16(V_FW_FILTER_WR_RX_CHAN(0) |
                            V_FW_FILTER_WR_RX_RPL_IQ(adapter->sge.fw_evtq.abs_id
                                                     ));
        fwr->maci_to_matchtypem =
-               cpu_to_be32(V_FW_FILTER_WR_PORT(f->fs.val.iport) |
+               cpu_to_be32(V_FW_FILTER_WR_MACI(f->fs.val.macidx) |
+                           V_FW_FILTER_WR_MACIM(f->fs.mask.macidx) |
+                           V_FW_FILTER_WR_PORT(f->fs.val.iport) |
                            V_FW_FILTER_WR_PORTM(f->fs.mask.iport));
        fwr->ptcl = f->fs.val.proto;
        fwr->ptclm = f->fs.mask.proto;
+       fwr->ttyp = f->fs.val.tos;
+       fwr->ttypm = f->fs.mask.tos;
+       fwr->ivlan = cpu_to_be16(f->fs.val.ivlan);
+       fwr->ivlanm = cpu_to_be16(f->fs.mask.ivlan);
+       fwr->ovlan = cpu_to_be16(f->fs.val.ovlan);
+       fwr->ovlanm = cpu_to_be16(f->fs.mask.ovlan);
        rte_memcpy(fwr->lip, f->fs.val.lip, sizeof(fwr->lip));
        rte_memcpy(fwr->lipm, f->fs.mask.lip, sizeof(fwr->lipm));
        rte_memcpy(fwr->fip, f->fs.val.fip, sizeof(fwr->fip));
@@ -757,6 +861,20 @@ int set_filter_wr(struct rte_eth_dev *dev, unsigned int fidx)
        fwr->fp = cpu_to_be16(f->fs.val.fport);
        fwr->fpm = cpu_to_be16(f->fs.mask.fport);
 
+       if (adapter->params.filter2_wr_support) {
+               fwr->filter_type_swapmac =
+                        V_FW_FILTER2_WR_SWAPMAC(f->fs.swapmac);
+               fwr->natmode_to_ulp_type =
+                       V_FW_FILTER2_WR_ULP_TYPE(f->fs.nat_mode ?
+                                                ULP_MODE_TCPDDP :
+                                                ULP_MODE_NONE) |
+                       V_FW_FILTER2_WR_NATMODE(f->fs.nat_mode);
+               memcpy(fwr->newlip, f->fs.nat_lip, sizeof(fwr->newlip));
+               memcpy(fwr->newfip, f->fs.nat_fip, sizeof(fwr->newfip));
+               fwr->newlport = cpu_to_be16(f->fs.nat_lport);
+               fwr->newfport = cpu_to_be16(f->fs.nat_fport);
+       }
+
        /*
         * Mark the filter as "pending" and ship off the Filter Work Request.
         * When we get the Work Request Reply we'll clear the pending status.
@@ -770,44 +888,34 @@ out:
 }
 
 /**
- * Set the corresponding entry in the bitmap. 4 slots are
- * marked for IPv6, whereas only 1 slot is marked for IPv4.
+ * Set the corresponding entries in the bitmap.
  */
-static int cxgbe_set_ftid(struct tid_info *t, int fidx, int family)
+static int cxgbe_set_ftid(struct tid_info *t, u32 fidx, u8 nentries)
 {
+       u32 i;
+
        t4_os_lock(&t->ftid_lock);
        if (rte_bitmap_get(t->ftid_bmap, fidx)) {
                t4_os_unlock(&t->ftid_lock);
                return -EBUSY;
        }
 
-       if (family == FILTER_TYPE_IPV4) {
-               rte_bitmap_set(t->ftid_bmap, fidx);
-       } else {
-               rte_bitmap_set(t->ftid_bmap, fidx);
-               rte_bitmap_set(t->ftid_bmap, fidx + 1);
-               rte_bitmap_set(t->ftid_bmap, fidx + 2);
-               rte_bitmap_set(t->ftid_bmap, fidx + 3);
-       }
+       for (i = fidx; i < fidx + nentries; i++)
+               rte_bitmap_set(t->ftid_bmap, i);
        t4_os_unlock(&t->ftid_lock);
        return 0;
 }
 
 /**
- * Clear the corresponding entry in the bitmap. 4 slots are
- * cleared for IPv6, whereas only 1 slot is cleared for IPv4.
+ * Clear the corresponding entries in the bitmap.
  */
-static void cxgbe_clear_ftid(struct tid_info *t, int fidx, int family)
+static void cxgbe_clear_ftid(struct tid_info *t, u32 fidx, u8 nentries)
 {
+       u32 i;
+
        t4_os_lock(&t->ftid_lock);
-       if (family == FILTER_TYPE_IPV4) {
-               rte_bitmap_clear(t->ftid_bmap, fidx);
-       } else {
-               rte_bitmap_clear(t->ftid_bmap, fidx);
-               rte_bitmap_clear(t->ftid_bmap, fidx + 1);
-               rte_bitmap_clear(t->ftid_bmap, fidx + 2);
-               rte_bitmap_clear(t->ftid_bmap, fidx + 3);
-       }
+       for (i = fidx; i < fidx + nentries; i++)
+               rte_bitmap_clear(t->ftid_bmap, i);
        t4_os_unlock(&t->ftid_lock);
 }
 
@@ -821,10 +929,11 @@ int cxgbe_del_filter(struct rte_eth_dev *dev, unsigned int filter_id,
                     struct ch_filter_specification *fs,
                     struct filter_ctx *ctx)
 {
-       struct port_info *pi = (struct port_info *)(dev->data->dev_private);
+       struct port_info *pi = dev->data->dev_private;
        struct adapter *adapter = pi->adapter;
        struct filter_entry *f;
        unsigned int chip_ver;
+       u8 nentries;
        int ret;
 
        if (is_hashfilter(adapter) && fs->cap)
@@ -835,24 +944,25 @@ int cxgbe_del_filter(struct rte_eth_dev *dev, unsigned int filter_id,
 
        chip_ver = CHELSIO_CHIP_VERSION(adapter->params.chip);
 
-       ret = is_filter_set(&adapter->tids, filter_id, fs->type);
-       if (!ret) {
-               dev_warn(adap, "%s: could not find filter entry: %u\n",
-                        __func__, filter_id);
-               return -EINVAL;
-       }
-
        /*
-        * Ensure filter id is aligned on the 2 slot boundary for T6,
+        * Ensure IPv6 filter id is aligned on the 2 slot boundary for T6,
         * and 4 slot boundary for cards below T6.
         */
-       if (fs->type) {
+       if (fs->type == FILTER_TYPE_IPV6) {
                if (chip_ver < CHELSIO_T6)
                        filter_id &= ~(0x3);
                else
                        filter_id &= ~(0x1);
        }
 
+       nentries = cxgbe_filter_slots(adapter, fs->type);
+       ret = cxgbe_is_filter_set(&adapter->tids, filter_id, nentries);
+       if (!ret) {
+               dev_warn(adap, "%s: could not find filter entry: %u\n",
+                        __func__, filter_id);
+               return -EINVAL;
+       }
+
        f = &adapter->tids.ftid_tab[filter_id];
        ret = writable_filter(f);
        if (ret)
@@ -862,8 +972,7 @@ int cxgbe_del_filter(struct rte_eth_dev *dev, unsigned int filter_id,
                f->ctx = ctx;
                cxgbe_clear_ftid(&adapter->tids,
                                 f->tid - adapter->tids.ftid_base,
-                                f->fs.type ? FILTER_TYPE_IPV6 :
-                                             FILTER_TYPE_IPV4);
+                                nentries);
                return del_filter_wr(dev, filter_id);
        }
 
@@ -893,10 +1002,11 @@ int cxgbe_set_filter(struct rte_eth_dev *dev, unsigned int filter_id,
 {
        struct port_info *pi = ethdev2pinfo(dev);
        struct adapter *adapter = pi->adapter;
-       unsigned int fidx, iq, fid_bit = 0;
+       u8 nentries, bitoff[16] = {0};
        struct filter_entry *f;
        unsigned int chip_ver;
-       uint8_t bitoff[16] = {0};
+       unsigned int fidx, iq;
+       u32 iconf;
        int ret;
 
        if (is_hashfilter(adapter) && fs->cap)
@@ -907,84 +1017,35 @@ int cxgbe_set_filter(struct rte_eth_dev *dev, unsigned int filter_id,
 
        chip_ver = CHELSIO_CHIP_VERSION(adapter->params.chip);
 
-       ret = validate_filter(adapter, fs);
+       ret = cxgbe_validate_filter(adapter, fs);
        if (ret)
                return ret;
 
-       /*
-        * Ensure filter id is aligned on the 4 slot boundary for IPv6
-        * maskfull filters.
-        */
-       if (fs->type)
-               filter_id &= ~(0x3);
-
-       ret = is_filter_set(&adapter->tids, filter_id, fs->type);
-       if (ret)
-               return -EBUSY;
-
-       iq = get_filter_steerq(dev, fs);
-
        /*
         * IPv6 filters occupy four slots and must be aligned on four-slot
         * boundaries for T5. On T6, IPv6 filters occupy two-slots and
         * must be aligned on two-slot boundaries.
         *
         * IPv4 filters only occupy a single slot and have no alignment
-        * requirements but writing a new IPv4 filter into the middle
-        * of an existing IPv6 filter requires clearing the old IPv6
-        * filter.
+        * requirements.
         */
-       if (fs->type == FILTER_TYPE_IPV4) { /* IPv4 */
-               /*
-                * For T6, If our IPv4 filter isn't being written to a
-                * multiple of two filter index and there's an IPv6
-                * filter at the multiple of 2 base slot, then we need
-                * to delete that IPv6 filter ...
-                * For adapters below T6, IPv6 filter occupies 4 entries.
-                */
+       fidx = filter_id;
+       if (fs->type == FILTER_TYPE_IPV6) {
                if (chip_ver < CHELSIO_T6)
-                       fidx = filter_id & ~0x3;
+                       fidx &= ~(0x3);
                else
-                       fidx = filter_id & ~0x1;
-
-               if (fidx != filter_id && adapter->tids.ftid_tab[fidx].fs.type) {
-                       f = &adapter->tids.ftid_tab[fidx];
-                       if (f->valid)
-                               return -EBUSY;
-               }
-       } else { /* IPv6 */
-               unsigned int max_filter_id;
-
-               if (chip_ver < CHELSIO_T6) {
-                       /*
-                        * Ensure that the IPv6 filter is aligned on a
-                        * multiple of 4 boundary.
-                        */
-                       if (filter_id & 0x3)
-                               return -EINVAL;
+                       fidx &= ~(0x1);
+       }
 
-                       max_filter_id = filter_id + 4;
-               } else {
-                       /*
-                        * For T6, CLIP being enabled, IPv6 filter would occupy
-                        * 2 entries.
-                        */
-                       if (filter_id & 0x1)
-                               return -EINVAL;
+       if (fidx != filter_id)
+               return -EINVAL;
 
-                       max_filter_id = filter_id + 2;
-               }
+       nentries = cxgbe_filter_slots(adapter, fs->type);
+       ret = cxgbe_is_filter_set(&adapter->tids, filter_id, nentries);
+       if (ret)
+               return -EBUSY;
 
-               /*
-                * Check all except the base overlapping IPv4 filter
-                * slots.
-                */
-               for (fidx = filter_id + 1; fidx < max_filter_id; fidx++) {
-                       f = &adapter->tids.ftid_tab[fidx];
-                       if (f->valid)
-                               return -EBUSY;
-               }
-       }
+       iq = get_filter_steerq(dev, fs);
 
        /*
         * Check to make sure that provided filter index is not
@@ -995,9 +1056,7 @@ int cxgbe_set_filter(struct rte_eth_dev *dev, unsigned int filter_id,
                return -EBUSY;
 
        fidx = adapter->tids.ftid_base + filter_id;
-       fid_bit = filter_id;
-       ret = cxgbe_set_ftid(&adapter->tids, fid_bit,
-                            fs->type ? FILTER_TYPE_IPV6 : FILTER_TYPE_IPV4);
+       ret = cxgbe_set_ftid(&adapter->tids, filter_id, nentries);
        if (ret)
                return ret;
 
@@ -1007,9 +1066,7 @@ int cxgbe_set_filter(struct rte_eth_dev *dev, unsigned int filter_id,
        ret = writable_filter(f);
        if (ret) {
                /* Clear the bits we have set above */
-               cxgbe_clear_ftid(&adapter->tids, fid_bit,
-                                fs->type ? FILTER_TYPE_IPV6 :
-                                           FILTER_TYPE_IPV4);
+               cxgbe_clear_ftid(&adapter->tids, filter_id, nentries);
                return ret;
        }
 
@@ -1018,7 +1075,7 @@ int cxgbe_set_filter(struct rte_eth_dev *dev, unsigned int filter_id,
         */
        if (chip_ver > CHELSIO_T5 && fs->type &&
            memcmp(fs->val.lip, bitoff, sizeof(bitoff))) {
-               f->clipt = cxgbe_clip_alloc(f->dev, (u32 *)&f->fs.val.lip);
+               f->clipt = cxgbe_clip_alloc(dev, (u32 *)&fs->val.lip);
                if (!f->clipt)
                        goto free_tid;
        }
@@ -1033,6 +1090,20 @@ int cxgbe_set_filter(struct rte_eth_dev *dev, unsigned int filter_id,
        f->fs.iq = iq;
        f->dev = dev;
 
+       iconf = adapter->params.tp.ingress_config;
+
+       /* Either PFVF or OVLAN can be active, but not both
+        * So, if PFVF is enabled, then overwrite the OVLAN
+        * fields with PFVF fields before writing the spec
+        * to hardware.
+        */
+       if (iconf & F_VNIC) {
+               f->fs.val.ovlan = fs->val.pf << 13 | fs->val.vf;
+               f->fs.mask.ovlan = fs->mask.pf << 13 | fs->mask.vf;
+               f->fs.val.ovlan_vld = fs->val.pfvf_vld;
+               f->fs.mask.ovlan_vld = fs->mask.pfvf_vld;
+       }
+
        /*
         * Attempt to set the filter.  If we don't succeed, we clear
         * it and return the failure.
@@ -1040,17 +1111,13 @@ int cxgbe_set_filter(struct rte_eth_dev *dev, unsigned int filter_id,
        f->ctx = ctx;
        f->tid = fidx; /* Save the actual tid */
        ret = set_filter_wr(dev, filter_id);
-       if (ret) {
-               fid_bit = f->tid - adapter->tids.ftid_base;
+       if (ret)
                goto free_tid;
-       }
 
        return ret;
 
 free_tid:
-       cxgbe_clear_ftid(&adapter->tids, fid_bit,
-                        fs->type ? FILTER_TYPE_IPV6 :
-                                   FILTER_TYPE_IPV4);
+       cxgbe_clear_ftid(&adapter->tids, filter_id, nentries);
        clear_filter(f);
        return ret;
 }
@@ -1058,7 +1125,8 @@ free_tid:
 /**
  * Handle a Hash filter write reply.
  */
-void hash_filter_rpl(struct adapter *adap, const struct cpl_act_open_rpl *rpl)
+void cxgbe_hash_filter_rpl(struct adapter *adap,
+                          const struct cpl_act_open_rpl *rpl)
 {
        struct tid_info *t = &adap->tids;
        struct filter_entry *f;
@@ -1099,9 +1167,17 @@ void hash_filter_rpl(struct adapter *adap, const struct cpl_act_open_rpl *rpl)
                                      V_TCB_TIMESTAMP(0ULL) |
                                      V_TCB_T_RTT_TS_RECENT_AGE(0ULL),
                                      1);
+               if (f->fs.newdmac)
+                       set_tcb_tflag(adap, tid, S_TF_CCTRL_ECE, 1, 1);
                if (f->fs.newvlan == VLAN_INSERT ||
                    f->fs.newvlan == VLAN_REWRITE)
                        set_tcb_tflag(adap, tid, S_TF_CCTRL_RFR, 1, 1);
+               if (f->fs.newsmac) {
+                       set_tcb_tflag(adap, tid, S_TF_CCTRL_CWR, 1, 1);
+                       set_tcb_field(adap, tid, W_TCB_SMAC_SEL,
+                                     V_TCB_SMAC_SEL(M_TCB_SMAC_SEL),
+                                     V_TCB_SMAC_SEL(f->smt->hw_idx), 1);
+               }
                break;
        }
        default:
@@ -1126,7 +1202,7 @@ void hash_filter_rpl(struct adapter *adap, const struct cpl_act_open_rpl *rpl)
 /**
  * Handle a LE-TCAM filter write/deletion reply.
  */
-void filter_rpl(struct adapter *adap, const struct cpl_set_tcb_rpl *rpl)
+void cxgbe_filter_rpl(struct adapter *adap, const struct cpl_set_tcb_rpl *rpl)
 {
        struct filter_entry *f = NULL;
        unsigned int tid = GET_TID(rpl);
@@ -1272,11 +1348,60 @@ get_count:
        return 0;
 }
 
+/*
+ * Clear the packet count for the specified filter.
+ */
+int cxgbe_clear_filter_count(struct adapter *adapter, unsigned int fidx,
+                            int hash, bool clear_byte)
+{
+       u64 tcb_mask = 0, tcb_val = 0;
+       struct filter_entry *f = NULL;
+       u16 tcb_word = 0;
+
+       if (is_hashfilter(adapter) && hash) {
+               if (fidx >= adapter->tids.ntids)
+                       return -ERANGE;
+
+               /* No hitcounts supported for T5 hashfilters */
+               if (is_t5(adapter->params.chip))
+                       return 0;
+
+               f = adapter->tids.tid_tab[fidx];
+       } else {
+               if (fidx >= adapter->tids.nftids)
+                       return -ERANGE;
+
+               f = &adapter->tids.ftid_tab[fidx];
+       }
+
+       if (!f || !f->valid)
+               return -EINVAL;
+
+       tcb_word = W_TCB_TIMESTAMP;
+       tcb_mask = V_TCB_TIMESTAMP(M_TCB_TIMESTAMP);
+       tcb_val = V_TCB_TIMESTAMP(0ULL);
+
+       set_tcb_field(adapter, f->tid, tcb_word, tcb_mask, tcb_val, 1);
+
+       if (clear_byte) {
+               tcb_word = W_TCB_T_RTT_TS_RECENT_AGE;
+               tcb_mask =
+                       V_TCB_T_RTT_TS_RECENT_AGE(M_TCB_T_RTT_TS_RECENT_AGE) |
+                       V_TCB_T_RTSEQ_RECENT(M_TCB_T_RTSEQ_RECENT);
+               tcb_val = V_TCB_T_RTT_TS_RECENT_AGE(0ULL) |
+                         V_TCB_T_RTSEQ_RECENT(0ULL);
+
+               set_tcb_field(adapter, f->tid, tcb_word, tcb_mask, tcb_val, 1);
+       }
+
+       return 0;
+}
+
 /**
  * Handle a Hash filter delete reply.
  */
-void hash_del_filter_rpl(struct adapter *adap,
-                        const struct cpl_abort_rpl_rss *rpl)
+void cxgbe_hash_del_filter_rpl(struct adapter *adap,
+                              const struct cpl_abort_rpl_rss *rpl)
 {
        struct tid_info *t = &adap->tids;
        struct filter_entry *f;