X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=drivers%2Fnet%2Fcxgbe%2Fcxgbe_filter.c;h=a77935a657323fc5321569e0c1526514652e4525;hb=1def64c2d79e07eb3ec73f5d1ca797e512a3e4d5;hp=7759b8acf79ea0a532795e96ebf71ba87e9ea819;hpb=41dc98b0827a486b929bbea3dff18771d8bf3414;p=dpdk.git diff --git a/drivers/net/cxgbe/cxgbe_filter.c b/drivers/net/cxgbe/cxgbe_filter.c index 7759b8acf7..a77935a657 100644 --- a/drivers/net/cxgbe/cxgbe_filter.c +++ b/drivers/net/cxgbe/cxgbe_filter.c @@ -3,11 +3,13 @@ * All rights reserved. */ #include -#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" /** * Initialize Hash Filters @@ -65,11 +67,35 @@ int validate_filter(struct adapter *adapter, struct ch_filter_specification *fs) #define U(_mask, _field) \ (!(fconf & (_mask)) && S(_field)) - if (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)) return -EOPNOTSUPP; #undef S #undef U + + /* + * If the user is requesting that the filter action loop + * matching packets back out one of our ports, make sure that + * the egress port is in range. + */ + if (fs->action == FILTER_SWITCH && + fs->eport >= adapter->params.nports) + return -ERANGE; + + /* + * Don't allow various trivially obvious bogus out-of-range + * values ... + */ + 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; } @@ -117,6 +143,46 @@ int writable_filter(struct filter_entry *f) return 0; } +/** + * Send CPL_SET_TCB_FIELD message + */ +static void set_tcb_field(struct adapter *adapter, unsigned int ftid, + u16 word, u64 mask, u64 val, int no_reply) +{ + struct rte_mbuf *mbuf; + struct cpl_set_tcb_field *req; + struct sge_ctrl_txq *ctrlq; + + ctrlq = &adapter->sge.ctrlq[0]; + mbuf = rte_pktmbuf_alloc(ctrlq->mb_pool); + WARN_ON(!mbuf); + + mbuf->data_len = sizeof(*req); + mbuf->pkt_len = mbuf->data_len; + + req = rte_pktmbuf_mtod(mbuf, struct cpl_set_tcb_field *); + memset(req, 0, sizeof(*req)); + INIT_TP_WR_MIT_CPL(req, CPL_SET_TCB_FIELD, ftid); + req->reply_ctrl = cpu_to_be16(V_REPLY_CHAN(0) | + V_QUEUENO(adapter->sge.fw_evtq.abs_id) | + V_NO_REPLY(no_reply)); + req->word_cookie = cpu_to_be16(V_WORD(word) | V_COOKIE(ftid)); + req->mask = cpu_to_be64(mask); + req->val = cpu_to_be64(val); + + t4_mgmt_tx(ctrlq, mbuf); +} + +/** + * Set one of the t_flags bits in the TCB. + */ +static void set_tcb_tflag(struct adapter *adap, unsigned int ftid, + unsigned int bit_pos, unsigned int val, int no_reply) +{ + set_tcb_field(adap, ftid, W_TCB_T_FLAGS, 1ULL << bit_pos, + (unsigned long long)val << bit_pos, no_reply); +} + /** * Build a CPL_SET_TCB_FIELD message as payload of a ULP_TX_PKT command. */ @@ -198,6 +264,9 @@ 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 && f->fs.mask.iport) + ntuple |= (u64)f->fs.val.iport << tp->port_shift; + if (tp->protocol_shift >= 0) { if (!f->fs.val.proto) ntuple |= (u64)tcp_proto << tp->protocol_shift; @@ -207,9 +276,8 @@ 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; return ntuple; } @@ -375,9 +443,13 @@ static void mk_act_open_req6(struct filter_entry *f, struct rte_mbuf *mbuf, req->local_ip_lo = local_lo; req->peer_ip_hi = peer_hi; req->peer_ip_lo = peer_lo; - req->opt0 = cpu_to_be64(V_DELACK(f->fs.hitcnts) | + req->opt0 = cpu_to_be64(V_NAGLE(f->fs.newvlan == VLAN_REMOVE || + f->fs.newvlan == VLAN_REWRITE) | + V_DELACK(f->fs.hitcnts) | + V_L2T_IDX(f->l2t ? f->l2t->idx : 0) | V_SMAC_SEL((cxgbe_port_viid(f->dev) & 0x7F) << 1) | + V_TX_CHAN(f->fs.eport) | V_ULP_MODE(ULP_MODE_NONE) | F_TCAM_BYPASS | F_NON_OFFLOAD); req->params = cpu_to_be64(V_FILTER_TUPLE(hash_filter_ntuple(f))); @@ -385,8 +457,10 @@ 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))); + (f->fs.dirsteer << 1)) | + V_CCTRL_ECN(f->fs.action == FILTER_SWITCH)); } /** @@ -416,9 +490,13 @@ static void mk_act_open_req(struct filter_entry *f, struct rte_mbuf *mbuf, f->fs.val.lip[2] << 16 | f->fs.val.lip[3] << 24; req->peer_ip = f->fs.val.fip[0] | f->fs.val.fip[1] << 8 | f->fs.val.fip[2] << 16 | f->fs.val.fip[3] << 24; - req->opt0 = cpu_to_be64(V_DELACK(f->fs.hitcnts) | + req->opt0 = cpu_to_be64(V_NAGLE(f->fs.newvlan == VLAN_REMOVE || + f->fs.newvlan == VLAN_REWRITE) | + V_DELACK(f->fs.hitcnts) | + V_L2T_IDX(f->l2t ? f->l2t->idx : 0) | V_SMAC_SEL((cxgbe_port_viid(f->dev) & 0x7F) << 1) | + V_TX_CHAN(f->fs.eport) | V_ULP_MODE(ULP_MODE_NONE) | F_TCAM_BYPASS | F_NON_OFFLOAD); req->params = cpu_to_be64(V_FILTER_TUPLE(hash_filter_ntuple(f))); @@ -426,8 +504,10 @@ 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))); + (f->fs.dirsteer << 1)) | + V_CCTRL_ECN(f->fs.action == FILTER_SWITCH)); } /** @@ -464,6 +544,22 @@ static int cxgbe_set_hash_filter(struct rte_eth_dev *dev, f->dev = dev; f->fs.iq = iq; + /* + * If the new filter requires loopback Destination MAC and/or VLAN + * rewriting then we need to allocate a Layer 2 Table (L2T) entry for + * the filter. + */ + if (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, + f->fs.eport, f->fs.dmac); + if (!f->l2t) { + ret = -ENOMEM; + goto out_err; + } + } + atid = cxgbe_alloc_atid(t, f); if (atid < 0) goto out_err; @@ -537,6 +633,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 @@ -544,10 +641,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)); @@ -565,7 +666,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; @@ -577,8 +678,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. @@ -594,11 +695,24 @@ 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; + /* + * If the new filter requires loopback Destination MAC and/or VLAN + * rewriting then we need to allocate a Layer 2 Table (L2T) entry for + * the filter. + */ + if (f->fs.newvlan) { + /* 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; + } + ctrlq = &adapter->sge.ctrlq[port_id]; mbuf = rte_pktmbuf_alloc(ctrlq->mb_pool); if (!mbuf) { @@ -609,13 +723,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) | @@ -625,8 +742,17 @@ int set_filter_wr(struct rte_eth_dev *dev, unsigned int fidx) fwr->del_filter_to_l2tix = 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_INSVLAN + (f->fs.newvlan == VLAN_INSERT || + f->fs.newvlan == VLAN_REWRITE) | + V_FW_FILTER_WR_RMVLAN + (f->fs.newvlan == VLAN_REMOVE || + f->fs.newvlan == VLAN_REWRITE) | V_FW_FILTER_WR_HITCNTS(f->fs.hitcnts) | - V_FW_FILTER_WR_PRIO(f->fs.prio)); + V_FW_FILTER_WR_TXCHAN(f->fs.eport) | + V_FW_FILTER_WR_PRIO(f->fs.prio) | + 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; @@ -634,6 +760,11 @@ int set_filter_wr(struct rte_eth_dev *dev, unsigned int fidx) 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_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; rte_memcpy(fwr->lip, f->fs.val.lip, sizeof(fwr->lip)); @@ -645,6 +776,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. @@ -978,6 +1123,18 @@ void hash_filter_rpl(struct adapter *adap, const struct cpl_act_open_rpl *rpl) ctx->tid = f->tid; ctx->result = 0; } + if (f->fs.hitcnts) + set_tcb_field(adap, tid, + W_TCB_TIMESTAMP, + V_TCB_TIMESTAMP(M_TCB_TIMESTAMP) | + V_TCB_T_RTT_TS_RECENT_AGE + (M_TCB_T_RTT_TS_RECENT_AGE), + V_TCB_TIMESTAMP(0ULL) | + V_TCB_T_RTT_TS_RECENT_AGE(0ULL), + 1); + if (f->fs.newvlan == VLAN_INSERT || + f->fs.newvlan == VLAN_REWRITE) + set_tcb_tflag(adap, tid, S_TF_CCTRL_RFR, 1, 1); break; } default: @@ -1068,22 +1225,44 @@ void filter_rpl(struct adapter *adap, const struct cpl_set_tcb_rpl *rpl) * Retrieve the packet count for the specified filter. */ int cxgbe_get_filter_count(struct adapter *adapter, unsigned int fidx, - u64 *c, bool get_byte) + u64 *c, int hash, bool get_byte) { struct filter_entry *f; unsigned int tcb_base, tcbaddr; int ret; tcb_base = t4_read_reg(adapter, A_TP_CMM_TCB_BASE); - if (fidx >= adapter->tids.nftids) - return -ERANGE; + if (is_hashfilter(adapter) && hash) { + if (fidx < adapter->tids.ntids) { + f = adapter->tids.tid_tab[fidx]; + if (!f) + return -EINVAL; + + if (is_t5(adapter->params.chip)) { + *c = 0; + return 0; + } + tcbaddr = tcb_base + (fidx * TCB_SIZE); + goto get_count; + } else { + return -ERANGE; + } + } else { + if (fidx >= adapter->tids.nftids) + return -ERANGE; + + f = &adapter->tids.ftid_tab[fidx]; + if (!f->valid) + return -EINVAL; + + tcbaddr = tcb_base + f->tid * TCB_SIZE; + } f = &adapter->tids.ftid_tab[fidx]; if (!f->valid) return -EINVAL; - tcbaddr = tcb_base + f->tid * TCB_SIZE; - +get_count: if (is_t5(adapter->params.chip) || is_t6(adapter->params.chip)) { /* * For T5, the Filter Packet Hit Count is maintained as a @@ -1126,6 +1305,55 @@ int cxgbe_get_filter_count(struct adapter *adapter, unsigned int fidx, 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. */