cxgb4: add hash-filter support to tc-flower offload
Subsystems (3)
cover cxgb4: add hash-filter support to tc-flower offload
This series of patches add support to create hash-filters; a.k.a exact-match filters, to tc-flower offload. T6 supports creating ~500K hash-filters in hw and can theoretically be expanded up to ~1 million.
Patch 1 fetches and saves the configured hw filter tuple field shifts and filter mask.
Patch 2 initializes the driver to use hash-filter configuration.
Patch 3 adds support to create hash filters in hw.
Patch 4 adds support to delete hash filters in hw.
Patch 5 adds support to retrieve filter stats for hash filters.
Patch 6 converts the flower table to use rhashtable instead of static hlist.
Patch 7 finally adds support to create hash filters via tc-flower offload.
Thanks,
Rahul
Kumar Sanghvi (7):
cxgb4: save additional filter tuple field shifts in tp_params
cxgb4: initialize hash-filter configuration
cxgb4: add support to create hash filters
cxgb4: add support to delete hash filter
cxgb4: add support to retrieve stats for hash filters
cxgb4: convert flower table to use rhashtable
cxgb4: add support to create hash-filters via tc-flower offload
drivers/net/ethernet/chelsio/cxgb4/cxgb4.h | 32 +- drivers/net/ethernet/chelsio/cxgb4/cxgb4_filter.c | 928 +++++++++++++++++++-- drivers/net/ethernet/chelsio/cxgb4/cxgb4_filter.h | 8 + drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c | 26 +- .../net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c | 126 ++- .../net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.h | 4 +- drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_u32.c | 4 +- drivers/net/ethernet/chelsio/cxgb4/cxgb4_uld.h | 6 +- drivers/net/ethernet/chelsio/cxgb4/t4_hw.c | 18 +- drivers/net/ethernet/chelsio/cxgb4/t4_msg.h | 5 + drivers/net/ethernet/chelsio/cxgb4/t4_regs.h | 17 + drivers/net/ethernet/chelsio/cxgb4/t4_tcb.h | 22 + drivers/net/ethernet/chelsio/cxgb4/t4fw_api.h | 1 + 13 files changed, 1082 insertions(+), 115 deletions(-)
Signature · 1 line
2.14.1
PATCH 1/7 cxgb4: save additional filter tuple field shifts in tp_params
From: Kumar Sanghvi <[email protected]>
Save additional filter tuple field shifts in tp_params based on configured filter tuple fields.
Also, save the combined filter tuple mask based on configured filter tuple fields.
--- drivers/net/ethernet/chelsio/cxgb4/cxgb4.h | 12 ++++++++++-- drivers/net/ethernet/chelsio/cxgb4/t4_hw.c | 18 ++++++++++++++++-- drivers/net/ethernet/chelsio/cxgb4/t4_regs.h | 3 +++ 3 files changed, 29 insertions(+), 4 deletions(-)
drivers/net/ethernet/chelsio/cxgb4/cxgb4.h +10 -2
@@ -287,10 +287,18 @@ struct tp_params {* places we store their offsets here, or a -1 if the field isn't * present. */ -int vlan_shift; -int vnic_shift; +int fcoe_shift;int port_shift; +int vnic_shift; +int vlan_shift; +int tos_shift;int protocol_shift; +int ethertype_shift; +int macmatch_shift; +int matchtype_shift; +int frag_shift; + +u64 hash_filter_mask; };struct vpd_params {
drivers/net/ethernet/chelsio/cxgb4/t4_hw.c +16 -2
@@ -8816,11 +8816,21 @@ int t4_init_tp_params(struct adapter *adap, bool sleep_ok)* shift positions of several elements of the Compressed Filter Tuple * for this adapter which we need frequently ... */ - adap->params.tp.vlan_shift =t4_filter_field_shift (adap,VLAN_F ); - adap->params.tp.vnic_shift =t4_filter_field_shift (adap,VNIC_ID_F ); + adap->params.tp.fcoe_shift =t4_filter_field_shift (adap,FCOE_F ); adap->params.tp.port_shift =t4_filter_field_shift (adap,PORT_F ); + adap->params.tp.vnic_shift =t4_filter_field_shift (adap,VNIC_ID_F ); + adap->params.tp.vlan_shift =t4_filter_field_shift (adap,VLAN_F ); + adap->params.tp.tos_shift =t4_filter_field_shift (adap,TOS_F ); adap->params.tp.protocol_shift =t4_filter_field_shift (adap,PROTOCOL_F ); + adap->params.tp.ethertype_shift =t4_filter_field_shift (adap, +ETHERTYPE_F ); + adap->params.tp.macmatch_shift =t4_filter_field_shift (adap, +MACMATCH_F ); + adap->params.tp.matchtype_shift =t4_filter_field_shift (adap, +MPSHITTYPE_F ); + adap->params.tp.frag_shift =t4_filter_field_shift (adap, +FRAGMENTATION_F );/* If TP_INGRESS_CONFIG.VNID == 0, then TP_VLAN_PRI_MAP.VNIC_ID * represents the presence of an Outer VLAN instead of a VNIC ID.
@@ -8828,6 +8838,10 @@ int t4_init_tp_params(struct adapter *adap, bool sleep_ok)if ((adap->params.tp.ingress_config &VNIC_F ) ==0 ) adap->params.tp.vnic_shift =-1 ; + v =t4_read_reg (adap,LE_3_DB_HASH_MASK_GEN_IPV4_T6_A ); + adap->params.tp.hash_filter_mask = v; + v =t4_read_reg (adap,LE_4_DB_HASH_MASK_GEN_IPV4_T6_A ); + adap->params.tp.hash_filter_mask |= ((u64 )v <<32 );return 0 ; }
drivers/net/ethernet/chelsio/cxgb4/t4_regs.h +3 -0
@@ -2933,6 +2933,9 @@#define SSRAMINTPERR_V (x) ((x) << SSRAMINTPERR_S)#define SSRAMINTPERR_F SSRAMINTPERR_V(1U) +#define LE_3_DB_HASH_MASK_GEN_IPV4_T6_A 0x19eac +#define LE_4_DB_HASH_MASK_GEN_IPV4_T6_A 0x19eb0 +#define NCSI_INT_CAUSE_A 0x1a0d8#define CIM_DM_PRTY_ERR_S 8
Signature · 1 line
2.14.1
PATCH 2/7 cxgb4: initialize hash-filter configuration
In reply to Rahul LakkireddyFrom: Kumar Sanghvi <[email protected]>
Add support for hash-filter configuration on T6. Also, do basic checks for the related initialization.
--- drivers/net/ethernet/chelsio/cxgb4/cxgb4.h | 6 ++++++ drivers/net/ethernet/chelsio/cxgb4/cxgb4_filter.c | 22 ++++++++++++++++++++++ drivers/net/ethernet/chelsio/cxgb4/cxgb4_filter.h | 1 + drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c | 14 ++++++++++---- drivers/net/ethernet/chelsio/cxgb4/t4_regs.h | 14 ++++++++++++++ drivers/net/ethernet/chelsio/cxgb4/t4fw_api.h | 1 + 6 files changed, 54 insertions(+), 4 deletions(-)
drivers/net/ethernet/chelsio/cxgb4/cxgb4.h +6 -0
@@ -366,6 +366,7 @@ struct adapter_params {unsigned char crypto;/* HW capability for crypto */ unsigned char bypass; +unsigned char hash_filter;unsigned int ofldq_wr_cred;bool ulptx_memwrite_dsgl;/* use of T5 DSGL allowed */
@@ -1140,6 +1141,11 @@ static inline int is_offload(const struct adapter *adap)return adap->params.offload; } +static inline int is_hashfilter (const struct adapter *adap) +{ +return adap->params.hash_filter; +} +static inline int is_pci_uld (const struct adapter *adap) {return adap->params.crypto;
drivers/net/ethernet/chelsio/cxgb4/cxgb4_filter.c +22 -0
@@ -915,3 +915,25 @@ void filter_rpl(struct adapter *adap, const struct cpl_set_tcb_rpl *rpl)complete (&ctx->completion); } } + +int init_hash_filter (struct adapter *adap) +{ +/* On T6, verify the necessary register configs and warn the user in +* case of improper config +*/ +if (is_t6 (adap->params.chip)) { +if (TCAM_ACTV_HIT_G (t4_read_reg (adap,LE_DB_RSP_CODE_0_A )) !=4 ) + goto err; + +if (HASH_ACTV_HIT_G (t4_read_reg (adap,LE_DB_RSP_CODE_1_A )) !=4 ) + goto err; + }else { +dev_err (adap->pdev_dev,"Hash filter supported only on T6\n" ); +return -EINVAL ; + } + adap->params.hash_filter =1 ; +return 0 ; +err: +dev_warn (adap->pdev_dev,"Invalid hash filter config!\n" ); +return -EINVAL ; +}
drivers/net/ethernet/chelsio/cxgb4/cxgb4_filter.h +1 -0
@@ -45,4 +45,5 @@ int delete_filter(struct adapter *adapter, unsigned int fidx);int writable_filter (struct filter_entry *f);void clear_all_filters (struct adapter *adapter); +int init_hash_filter (struct adapter *adap);#endif /* __CXGB4_FILTER_H */
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c +10 -4
@@ -3963,7 +3963,8 @@ static int adap_init0(struct adapter *adap)if (ret <0 ) goto bye; -if (caps_cmd.ofldcaps) { +if (caps_cmd.ofldcaps || + (caps_cmd.niccaps &htons (FW_CAPS_CONFIG_NIC_HASHFILTER ))) {/* query offload-related parameters */ params[0 ] =FW_PARAM_DEV (NTID ); params[1 ] =FW_PARAM_PFVF (SERVER_START );
@@ -4000,8 +4001,13 @@ static int adap_init0(struct adapter *adap) adap->vres.ddp.size = val[4 ] - val[3 ] +1 ; adap->params.ofldq_wr_cred = val[5 ]; - adap->params.offload =1 ; - adap->num_ofld_uld +=1 ; +if (caps_cmd.niccaps &htons (FW_CAPS_CONFIG_NIC_HASHFILTER )) { +if (init_hash_filter (adap) <0 ) + goto bye; + }else { + adap->params.offload =1 ; + adap->num_ofld_uld +=1 ; + } }if (caps_cmd.rdmacaps) { params[0 ] =FW_PARAM_PFVF (STAG_START );
@@ -5171,7 +5177,7 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)cxgb4_init_tc_flower (adapter); } -if (is_offload (adapter)) { +if (is_offload (adapter) ||is_hashfilter (adapter)) {if (t4_read_reg (adapter,LE_DB_CONFIG_A ) &HASHEN_F ) {u32 hash_base, hash_reg;
drivers/net/ethernet/chelsio/cxgb4/t4_regs.h +14 -0
@@ -2933,6 +2933,20 @@#define SSRAMINTPERR_V (x) ((x) << SSRAMINTPERR_S)#define SSRAMINTPERR_F SSRAMINTPERR_V(1U) +#define LE_DB_RSP_CODE_0_A 0x19c74 + +#define TCAM_ACTV_HIT_S 0 +#define TCAM_ACTV_HIT_M 0x1fU +#define TCAM_ACTV_HIT_V (x) ((x) << TCAM_ACTV_HIT_S) +#define TCAM_ACTV_HIT_G (x) (((x) >> TCAM_ACTV_HIT_S) & TCAM_ACTV_HIT_M) + +#define LE_DB_RSP_CODE_1_A 0x19c78 + +#define HASH_ACTV_HIT_S 25 +#define HASH_ACTV_HIT_M 0x1fU +#define HASH_ACTV_HIT_V (x) ((x) << HASH_ACTV_HIT_S) +#define HASH_ACTV_HIT_G (x) (((x) >> HASH_ACTV_HIT_S) & HASH_ACTV_HIT_M) +#define LE_3_DB_HASH_MASK_GEN_IPV4_T6_A 0x19eac#define LE_4_DB_HASH_MASK_GEN_IPV4_T6_A 0x19eb0
drivers/net/ethernet/chelsio/cxgb4/t4fw_api.h +1 -0
@@ -1092,6 +1092,7 @@ enum fw_caps_config_switch {enum fw_caps_config_nic {FW_CAPS_CONFIG_NIC =0x00000001 ,FW_CAPS_CONFIG_NIC_VM =0x00000002 , +FW_CAPS_CONFIG_NIC_HASHFILTER =0x00000020 , };enum fw_caps_config_ofld {
Signature · 1 line
2.14.1
PATCH 3/7 cxgb4: add support to create hash filters
In reply to Rahul LakkireddyFrom: Kumar Sanghvi <[email protected]>
Add support to create hash (exact-match) filters based on the value of 'hash' field in ch_filter_specification.
Allocate SMT/L2T entries if DMAC-rewrite/SMAC-rewrite is requested.
Allocate CLIP entry in case of IPv6 filter.
Use cpl_act_open_req[6] to send hash filter create request to hw. Also, the filter tuple is calculated as part of sending this request.
Hash-filter reply is processed on getting cpl_act_open_rpl. In case of success, various bits/fields in filter-tcb are set per filter requirement, such as enabling filter hitcnts, and/or various header rewrite operations, such as VLAN-rewrite, NAT or (L3/L4)-rewrite, and SMAC/DMAC-rewrite. In case of failure, clear the filter entry and release any hw resources occupied by it.
The patch also moves the functions set_tcb_field, set_tcb_tflag and configure_filter_smac towards beginning of file.
--- drivers/net/ethernet/chelsio/cxgb4/cxgb4.h | 10 +- drivers/net/ethernet/chelsio/cxgb4/cxgb4_filter.c | 573 ++++++++++++++++++++-- drivers/net/ethernet/chelsio/cxgb4/cxgb4_filter.h | 3 + drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c | 4 + drivers/net/ethernet/chelsio/cxgb4/t4_msg.h | 5 + drivers/net/ethernet/chelsio/cxgb4/t4_tcb.h | 17 + 6 files changed, 562 insertions(+), 50 deletions(-)
drivers/net/ethernet/chelsio/cxgb4/cxgb4.h +9 -1
@@ -1050,6 +1050,7 @@ struct ch_filter_specification {* matching that doesn't exist as a (value, mask) tuple. */ uint32_t type:1; /* 0 => IPv4, 1 => IPv6 */ + u32 hash:1; /* 0 => wild-card, 1 => exact-match *//* Packet dispatch information. Ingress packets which match the * filter rules will be dropped, passed to the host or switched back
@@ -1107,7 +1108,14 @@ enum { };enum { -NAT_MODE_ALL =7 ,/* NAT on entire 4-tuple */ +NAT_MODE_NONE =0 ,/* No NAT performed */ +NAT_MODE_DIP ,/* NAT on Dst IP */ +NAT_MODE_DIP_DP ,/* NAT on Dst IP, Dst Port */ +NAT_MODE_DIP_DP_SIP ,/* NAT on Dst IP, Dst Port and Src IP */ +NAT_MODE_DIP_DP_SP ,/* NAT on Dst IP, Dst Port and Src Port */ +NAT_MODE_SIP_SP ,/* NAT on Src IP and Src Port */ +NAT_MODE_DIP_SIP_SP ,/* NAT on Dst IP, Src IP and Src Port */ +NAT_MODE_ALL /* NAT on entire 4-tuple */ };/* Host shadow copy of ingress filter entry. This is in host native format
drivers/net/ethernet/chelsio/cxgb4/cxgb4_filter.c +524 -49
624 lines not on this page · raw message
drivers/net/ethernet/chelsio/cxgb4/cxgb4_filter.h +3 -0
@@ -37,7 +37,10 @@#include "t4_msg.h" +#define WORD_MASK 0xffffffff +void filter_rpl (struct adapter *adap,const struct cpl_set_tcb_rpl *rpl); +void hash_filter_rpl (struct adapter *adap,const struct cpl_act_open_rpl *rpl);void clear_filter (struct adapter *adap,struct filter_entry *f);int set_filter_wr (struct adapter *adapter,int fidx);
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c +4 -0
@@ -572,6 +572,10 @@ static int fwevtq_handler(struct sge_rspq *q, const __be64 *rsp,const struct cpl_set_tcb_rpl *p = (void *)rsp;filter_rpl (q->adap, p); + }else if (opcode ==CPL_ACT_OPEN_RPL ) { +const struct cpl_act_open_rpl *p = (void *)rsp; + +hash_filter_rpl (q->adap, p); }else dev_err (q->adap->pdev_dev,"unexpected CPL %#x on FW event queue\n" , opcode);
drivers/net/ethernet/chelsio/cxgb4/t4_msg.h +5 -0
@@ -286,6 +286,7 @@ struct work_request_hdr {#define RX_CHANNEL_S 26#define RX_CHANNEL_V (x) ((x) << RX_CHANNEL_S) +#define RX_CHANNEL_F RX_CHANNEL_V(1U)#define WND_SCALE_EN_S 28#define WND_SCALE_EN_V (x) ((x) << WND_SCALE_EN_S)
@@ -315,6 +316,10 @@ struct cpl_pass_open_req {#define DELACK_V (x) ((x) << DELACK_S)#define DELACK_F DELACK_V(1U) +#define NON_OFFLOAD_S 7 +#define NON_OFFLOAD_V (x) ((x) << NON_OFFLOAD_S) +#define NON_OFFLOAD_F NON_OFFLOAD_V(1U) +#define DSCP_S 22#define DSCP_M 0x3F#define DSCP_V (x) ((x) << DSCP_S)
drivers/net/ethernet/chelsio/cxgb4/t4_tcb.h +17 -0
@@ -42,6 +42,23 @@#define TCB_T_FLAGS_W 1 +#define TF_CCTRL_ECE_S 60#define TF_CCTRL_CWR_S 61 +#define TF_CCTRL_RFR_S 62 +#define TCB_TIMESTAMP_W 5 +#define TCB_TIMESTAMP_S 0 +#define TCB_TIMESTAMP_M 0xffffffffULL +#define TCB_TIMESTAMP_V (x) ((x) << TCB_TIMESTAMP_S) + +#define TCB_RTT_TS_RECENT_AGE_W 6 +#define TCB_RTT_TS_RECENT_AGE_S 0 +#define TCB_RTT_TS_RECENT_AGE_M 0xffffffffULL +#define TCB_RTT_TS_RECENT_AGE_V (x) ((x) << TCB_RTT_TS_RECENT_AGE_S) + +#define TCB_SND_UNA_RAW_W 10 +#define TCB_RX_FRAG2_PTR_RAW_W 27 +#define TCB_RX_FRAG3_LEN_RAW_W 29 +#define TCB_RX_FRAG3_START_IDX_OFFSET_RAW_W 30 +#define TCB_PDU_HDR_LEN_W 31#endif /* __T4_TCB_H */
Signature · 1 line
2.14.1
PATCH 4/7 cxgb4: add support to delete hash filter
In reply to Rahul LakkireddyFrom: Kumar Sanghvi <[email protected]>
Use a combined ulptx work-request to send hash filter deletion request to hw. Hash filter deletion reply is processed on getting cpl_abort_rpl_rss.
Release any L2T/SMT/CLIP entries on filter deletion. Also, free up the corresponding filter entry.
--- drivers/net/ethernet/chelsio/cxgb4/cxgb4_filter.c | 159 ++++++++++++++++++++- drivers/net/ethernet/chelsio/cxgb4/cxgb4_filter.h | 2 + drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c | 4 + .../net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c | 2 +- drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_u32.c | 4 +- drivers/net/ethernet/chelsio/cxgb4/cxgb4_uld.h | 4 +- drivers/net/ethernet/chelsio/cxgb4/t4_tcb.h | 5 + 7 files changed, 173 insertions(+), 7 deletions(-)
drivers/net/ethernet/chelsio/cxgb4/cxgb4_filter.c +156 -3
@@ -87,6 +87,59 @@ static int set_tcb_tflag(struct adapter *adap, struct filter_entry *f, (unsigned long long)val << bit_pos, no_reply); } +static void mk_abort_req_ulp (struct cpl_abort_req *abort_req,unsigned int tid) +{ +struct ulp_txpkt *txpkt = (struct ulp_txpkt *)abort_req; +struct ulptx_idata *sc = (struct ulptx_idata *)(txpkt +1 ); + + txpkt->cmd_dest =htonl (ULPTX_CMD_V (ULP_TX_PKT ) |ULP_TXPKT_DEST_V (0 )); + txpkt->len =htonl (DIV_ROUND_UP (sizeof (*abort_req),16 )); + sc->cmd_more =htonl (ULPTX_CMD_V (ULP_TX_SC_IMM )); + sc->len =htonl (sizeof (*abort_req) -sizeof (struct work_request_hdr )); +OPCODE_TID (abort_req) =htonl (MK_OPCODE_TID (CPL_ABORT_REQ , tid)); + abort_req->rsvd0 =htonl (0 ); + abort_req->rsvd1 =0 ; + abort_req->cmd =CPL_ABORT_NO_RST ; +} + +static void mk_abort_rpl_ulp (struct cpl_abort_rpl *abort_rpl,unsigned int tid) +{ +struct ulp_txpkt *txpkt = (struct ulp_txpkt *)abort_rpl; +struct ulptx_idata *sc = (struct ulptx_idata *)(txpkt +1 ); + + txpkt->cmd_dest =htonl (ULPTX_CMD_V (ULP_TX_PKT ) |ULP_TXPKT_DEST_V (0 )); + txpkt->len =htonl (DIV_ROUND_UP (sizeof (*abort_rpl),16 )); + sc->cmd_more =htonl (ULPTX_CMD_V (ULP_TX_SC_IMM )); + sc->len =htonl (sizeof (*abort_rpl) -sizeof (struct work_request_hdr )); +OPCODE_TID (abort_rpl) =htonl (MK_OPCODE_TID (CPL_ABORT_RPL , tid)); + abort_rpl->rsvd0 =htonl (0 ); + abort_rpl->rsvd1 =0 ; + abort_rpl->cmd =CPL_ABORT_NO_RST ; +} + +static void mk_set_tcb_ulp (struct filter_entry *f, +struct cpl_set_tcb_field *req, +unsigned int word,u64 mask,u64 val, +u8 cookie,int no_reply) +{ +struct ulp_txpkt *txpkt = (struct ulp_txpkt *)req; +struct ulptx_idata *sc = (struct ulptx_idata *)(txpkt +1 ); + + txpkt->cmd_dest =htonl (ULPTX_CMD_V (ULP_TX_PKT ) |ULP_TXPKT_DEST_V (0 )); + txpkt->len =htonl (DIV_ROUND_UP (sizeof (*req),16 )); + sc->cmd_more =htonl (ULPTX_CMD_V (ULP_TX_SC_IMM )); + sc->len =htonl (sizeof (*req) -sizeof (struct work_request_hdr )); +OPCODE_TID (req) =htonl (MK_OPCODE_TID (CPL_SET_TCB_FIELD , f->tid)); + req->reply_ctrl =htons (NO_REPLY_V (no_reply) |REPLY_CHAN_V (0 ) | +QUEUENO_V (0 )); + req->word_cookie =htons (TCB_WORD_V (word) |TCB_COOKIE_V (cookie)); + req->mask =cpu_to_be64 (mask); + req->val =cpu_to_be64 (val); + sc = (struct ulptx_idata *)(req +1 ); + sc->cmd_more =htonl (ULPTX_CMD_V (ULP_TX_SC_NOOP )); + sc->len =htonl (0 ); +} +static int configure_filter_smac (struct adapter *adap,struct filter_entry *f) {int err;
@@ -1110,12 +1163,74 @@ int __cxgb4_set_filter(struct net_device *dev, int filter_id,return ret; } +static int cxgb4_del_hash_filter (struct net_device *dev,int filter_id, +struct filter_ctx *ctx) +{ +struct adapter *adapter =netdev2adap (dev); +struct tid_info *t = &adapter->tids; +struct cpl_abort_req *abort_req; +struct cpl_abort_rpl *abort_rpl; +struct cpl_set_tcb_field *req; +struct ulptx_idata *aligner; +struct work_request_hdr *wr; +struct filter_entry *f; +struct sk_buff *skb; +unsigned int wrlen; +int ret; + +netdev_dbg (dev,"%s: filter_id = %d ; nftids = %d\n" , + __func__, filter_id, adapter->tids.nftids); + +if (filter_id > adapter->tids.ntids) +return -E2BIG ; + + f =lookup_tid (t, filter_id); +if (!f) { +netdev_err (dev,"%s: no filter entry for filter_id = %d" , + __func__, filter_id); +return -EINVAL ; + } + + ret =writable_filter (f); +if (ret) +return ret; + +if (!f->valid) +return -EINVAL ; + + f->ctx = ctx; + f->pending =1 ; + wrlen =roundup (sizeof (*wr) + (sizeof (*req) +sizeof (*aligner)) + +sizeof (*abort_req) +sizeof (*abort_rpl),16 ); + skb =alloc_skb (wrlen,GFP_KERNEL ); +if (!skb) { +netdev_err (dev,"%s: could not allocate skb ..\n" , __func__); +return -ENOMEM ; + } +set_wr_txq (skb,CPL_PRIORITY_CONTROL , f->fs.val.iport &0x3 ); + req = (struct cpl_set_tcb_field *)__skb_put (skb, wrlen); +INIT_ULPTX_WR (req, wrlen,0 ,0 ); + wr = (struct work_request_hdr *)req; + wr++; + req = (struct cpl_set_tcb_field *)wr; +mk_set_tcb_ulp (f, req,TCB_RSS_INFO_W ,TCB_RSS_INFO_V (TCB_RSS_INFO_M ), +TCB_RSS_INFO_V (adapter->sge.fw_evtq.abs_id),0 ,1 ); + aligner = (struct ulptx_idata *)(req +1 ); + abort_req = (struct cpl_abort_req *)(aligner +1 ); +mk_abort_req_ulp (abort_req, f->tid); + abort_rpl = (struct cpl_abort_rpl *)(abort_req +1 ); +mk_abort_rpl_ulp (abort_rpl, f->tid); +t4_ofld_send (adapter, skb); +return 0 ; +} +/* Check a delete filter request for validity and send it to the hardware. * Return 0 on success, an error number otherwise. We attach any provided * filter operation context to the internal filter specification in order to * facilitate signaling completion of the operation. */ int __cxgb4_del_filter (struct net_device *dev,int filter_id, +struct ch_filter_specification *fs,struct filter_ctx *ctx) {struct adapter *adapter =netdev2adap (dev);
@@ -1123,6 +1238,14 @@ int __cxgb4_del_filter(struct net_device *dev, int filter_id,unsigned int max_fidx;int ret; +if (fs && fs->hash) { +if (is_hashfilter (adapter)) +return cxgb4_del_hash_filter (dev, filter_id, ctx); +netdev_err (dev,"%s: Exact-match filters only supported with Hash Filter configuration\n" , + __func__); +return -EINVAL ; + } + max_fidx = adapter->tids.nftids;if (filter_id != (max_fidx + adapter->tids.nsftids -1 ) && filter_id >= max_fidx)
@@ -1173,18 +1296,19 @@ int cxgb4_set_filter(struct net_device *dev, int filter_id,return ret; } -int cxgb4_del_filter (struct net_device *dev,int filter_id) +int cxgb4_del_filter (struct net_device *dev,int filter_id, +struct ch_filter_specification *fs) {struct filter_ctx ctx;int ret;/* If we are shutting down the adapter do not wait for completion */ if (netdev2adap (dev)->flags &SHUTTING_DOWN ) -return __cxgb4_del_filter (dev, filter_id,NULL ); +return __cxgb4_del_filter (dev, filter_id, fs,NULL );init_completion (&ctx.completion); - ret =__cxgb4_del_filter (dev, filter_id, &ctx); + ret =__cxgb4_del_filter (dev, filter_id, fs, &ctx);if (ret) goto out;
@@ -1258,6 +1382,35 @@ static int configure_filter_tcb(struct adapter *adap, unsigned int tid,return 0 ; } +void hash_del_filter_rpl (struct adapter *adap, +const struct cpl_abort_rpl_rss *rpl) +{ +unsigned int status = rpl->status; +struct tid_info *t = &adap->tids; +unsigned int tid =GET_TID (rpl); +struct filter_ctx *ctx =NULL ; +struct filter_entry *f; + +dev_dbg (adap->pdev_dev,"%s: status = %u; tid = %u\n" , + __func__, status, tid); + + f =lookup_tid (t, tid); +if (!f) { +dev_err (adap->pdev_dev,"%s:could not find filter entry" , + __func__); +return ; + } + ctx = f->ctx; + f->ctx =NULL ; +clear_filter (adap, f); +cxgb4_remove_tid (t,0 , tid,0 ); +kfree (f); +if (ctx) { + ctx->result =0 ; +complete (&ctx->completion); + } +} +void hash_filter_rpl (struct adapter *adap,const struct cpl_act_open_rpl *rpl) {unsigned int ftid =TID_TID_G (AOPEN_ATID_G (ntohl (rpl->atid_status)));
drivers/net/ethernet/chelsio/cxgb4/cxgb4_filter.h +2 -0
@@ -41,6 +41,8 @@void filter_rpl (struct adapter *adap,const struct cpl_set_tcb_rpl *rpl);void hash_filter_rpl (struct adapter *adap,const struct cpl_act_open_rpl *rpl); +void hash_del_filter_rpl (struct adapter *adap, +const struct cpl_abort_rpl_rss *rpl);void clear_filter (struct adapter *adap,struct filter_entry *f);int set_filter_wr (struct adapter *adapter,int fidx);
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c +4 -0
@@ -576,6 +576,10 @@ static int fwevtq_handler(struct sge_rspq *q, const __be64 *rsp,const struct cpl_act_open_rpl *p = (void *)rsp;hash_filter_rpl (q->adap, p); + }else if (opcode ==CPL_ABORT_RPL_RSS ) { +const struct cpl_abort_rpl_rss *p = (void *)rsp; + +hash_del_filter_rpl (q->adap, p); }else dev_err (q->adap->pdev_dev,"unexpected CPL %#x on FW event queue\n" , opcode);
drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c +1 -1
@@ -730,7 +730,7 @@ int cxgb4_tc_flower_destroy(struct net_device *dev,if (!ch_flower)return -ENOENT ; - ret =cxgb4_del_filter (dev, ch_flower->filter_id); + ret =cxgb4_del_filter (dev, ch_flower->filter_id, &ch_flower->fs);if (ret) goto err;
drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_u32.c +2 -2
@@ -380,7 +380,7 @@ int cxgb4_delete_knode(struct net_device *dev, struct tc_cls_u32_offload *cls)return -EINVAL ; } - ret =cxgb4_del_filter (dev, filter_id); + ret =cxgb4_del_filter (dev, filter_id,NULL );if (ret) goto out;
@@ -399,7 +399,7 @@ int cxgb4_delete_knode(struct net_device *dev, struct tc_cls_u32_offload *cls)if (!test_bit (j, link->tid_map))continue ; - ret =__cxgb4_del_filter (dev, j,NULL ); + ret =__cxgb4_del_filter (dev, j,NULL ,NULL );if (ret) goto out;
drivers/net/ethernet/chelsio/cxgb4/cxgb4_uld.h +3 -1
@@ -217,10 +217,12 @@ int __cxgb4_set_filter(struct net_device *dev, int filter_id,struct ch_filter_specification *fs, struct filter_ctx *ctx);int __cxgb4_del_filter (struct net_device *dev,int filter_id, +struct ch_filter_specification *fs,struct filter_ctx *ctx);int cxgb4_set_filter (struct net_device *dev,int filter_id,struct ch_filter_specification *fs); -int cxgb4_del_filter (struct net_device *dev,int filter_id); +int cxgb4_del_filter (struct net_device *dev,int filter_id, +struct ch_filter_specification *fs);int cxgb4_get_filter_counters (struct net_device *dev,unsigned int fidx,u64 *hitcnt,u64 *bytecnt);
drivers/net/ethernet/chelsio/cxgb4/t4_tcb.h +5 -0
@@ -46,6 +46,11 @@#define TF_CCTRL_CWR_S 61#define TF_CCTRL_RFR_S 62 +#define TCB_RSS_INFO_W 3 +#define TCB_RSS_INFO_S 0 +#define TCB_RSS_INFO_M 0x3ffULL +#define TCB_RSS_INFO_V (x) ((x) << TCB_RSS_INFO_S) +#define TCB_TIMESTAMP_W 5#define TCB_TIMESTAMP_S 0#define TCB_TIMESTAMP_M 0xffffffffULL
Signature · 1 line
2.14.1
PATCH 5/7 cxgb4: add support to retrieve stats for hash filters
In reply to Rahul LakkireddyFrom: Kumar Sanghvi <[email protected]>
Add support to retrieve packet-count and byte-count for hash-filters by retrieving filter-entry appropriately based on whether the request is for hash-filter or not.
--- drivers/net/ethernet/chelsio/cxgb4/cxgb4_filter.c | 30 ++++++++++++++-------- .../net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c | 6 +++-- drivers/net/ethernet/chelsio/cxgb4/cxgb4_uld.h | 2 +- 3 files changed, 25 insertions(+), 13 deletions(-)
drivers/net/ethernet/chelsio/cxgb4/cxgb4_filter.c +20 -10
@@ -341,7 +341,7 @@ static int get_filter_steerq(struct net_device *dev, }static int get_filter_count (struct adapter *adapter,unsigned int fidx, -u64 *pkts,u64 *bytes) +u64 *pkts,u64 *bytes,bool hash) {unsigned int tcb_base, tcbaddr;unsigned int word_offset;
@@ -350,14 +350,24 @@ static int get_filter_count(struct adapter *adapter, unsigned int fidx,int ret; tcb_base =t4_read_reg (adapter,TP_CMM_TCB_BASE_A ); -if ((fidx != (adapter->tids.nftids + adapter->tids.nsftids -1 )) && - fidx >= adapter->tids.nftids) -return -E2BIG ; - - f = &adapter->tids.ftid_tab[fidx]; -if (!f->valid) -return -EINVAL ; +if (is_hashfilter (adapter) && hash) { +if (fidx < adapter->tids.ntids) { + f = adapter->tids.tid_tab[fidx]; +if (!f) +return -EINVAL ; + }else { +return -E2BIG ; + } + }else { +if ((fidx != (adapter->tids.nftids + + adapter->tids.nsftids -1 )) && + fidx >= adapter->tids.nftids) +return -E2BIG ; + f = &adapter->tids.ftid_tab[fidx]; +if (!f->valid) +return -EINVAL ; + } tcbaddr = tcb_base + f->tid *TCB_SIZE ;spin_lock (&adapter->win0_lock);
@@ -409,11 +419,11 @@ static int get_filter_count(struct adapter *adapter, unsigned int fidx, }int cxgb4_get_filter_counters (struct net_device *dev,unsigned int fidx, -u64 *hitcnt,u64 *bytecnt) +u64 *hitcnt,u64 *bytecnt,bool hash) {struct adapter *adapter =netdev2adap (dev); -return get_filter_count (adapter, fidx, hitcnt, bytecnt); +return get_filter_count (adapter, fidx, hitcnt, bytecnt, hash); }int cxgb4_get_free_ftid (struct net_device *dev,int family)
drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c +4 -2
@@ -755,7 +755,8 @@ static void ch_flower_stats_cb(struct timer_list *t)hash_for_each_rcu (adap->flower_anymatch_tbl, i, flower_entry, link) { ret =cxgb4_get_filter_counters (adap->port[0 ], flower_entry->filter_id, - &packets, &bytes); + &packets, &bytes, + flower_entry->fs.hash);if (!ret) {spin_lock (&flower_entry->lock); ofld_stats = &flower_entry->stats;
@@ -788,7 +789,8 @@ int cxgb4_tc_flower_stats(struct net_device *dev, } ret =cxgb4_get_filter_counters (dev, ch_flower->filter_id, - &packets, &bytes); + &packets, &bytes, + ch_flower->fs.hash);if (ret <0 ) goto err;
drivers/net/ethernet/chelsio/cxgb4/cxgb4_uld.h +1 -1
@@ -224,7 +224,7 @@ int cxgb4_set_filter(struct net_device *dev, int filter_id,int cxgb4_del_filter (struct net_device *dev,int filter_id,struct ch_filter_specification *fs);int cxgb4_get_filter_counters (struct net_device *dev,unsigned int fidx, -u64 *hitcnt,u64 *bytecnt); +u64 *hitcnt,u64 *bytecnt,bool hash);static inline void set_wr_txq (struct sk_buff *skb,int prio,int queue) {
Signature · 1 line
2.14.1
PATCH 6/7 cxgb4: convert flower table to use rhashtable
In reply to Rahul LakkireddyFrom: Kumar Sanghvi <[email protected]>
T6 supports ~500K hash filters and can theoretically climb up to ~1 million hash filters. Preallocated hash table is not efficient in terms of memory usage. So, use rhashtable instead which gives the flexibility to grow based on usage.
--- drivers/net/ethernet/chelsio/cxgb4/cxgb4.h | 4 +- drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c | 4 +- .../net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c | 106 ++++++++++++++------- .../net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.h | 4 +- 4 files changed, 82 insertions(+), 36 deletions(-)
drivers/net/ethernet/chelsio/cxgb4/cxgb4.h +3 -1
@@ -918,8 +918,10 @@ struct adapter {struct chcr_stats_debug chcr_stats;/* TC flower offload */ -DECLARE_HASHTABLE (flower_anymatch_tbl,9 ); +struct rhashtable flower_tbl; +struct rhashtable_params flower_ht_params;struct timer_list flower_stats_timer; +struct work_struct flower_stats_work;/* Ethtool Dump */ struct ethtool_dump eth_dump;
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c +3 -1
@@ -5182,7 +5182,9 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)dev_warn (&pdev->dev,"could not offload tc u32, continuing\n" ); -cxgb4_init_tc_flower (adapter); +if (cxgb4_init_tc_flower (adapter)) +dev_warn (&pdev->dev, +"could not offload tc flower, continuing\n" ); }if (is_offload (adapter) ||is_hashfilter (adapter)) {
drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c +74 -32
158 lines not on this page · raw message
drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.h +2 -2
@@ -48,7 +48,7 @@ struct ch_tc_flower_entry {struct ch_filter_specification fs;struct ch_tc_flower_stats stats;unsigned long tc_flower_cookie; -struct hlist_node link; +struct rhash_head node;struct rcu_head rcu;spinlock_t lock;/* lock for stats */ u32 filter_id;
@@ -115,6 +115,6 @@ int cxgb4_tc_flower_destroy(struct net_device *dev,int cxgb4_tc_flower_stats (struct net_device *dev,struct tc_cls_flower_offload *cls); -void cxgb4_init_tc_flower (struct adapter *adap); +int cxgb4_init_tc_flower (struct adapter *adap);void cxgb4_cleanup_tc_flower (struct adapter *adap);#endif /* __CXGB4_TC_FLOWER_H */
Signature · 1 line
2.14.1
PATCH 7/7 cxgb4: add support to create hash-filters via tc-flower offload
In reply to Rahul LakkireddyFrom: Kumar Sanghvi <[email protected]>
Determine whether the flow classifies as exact-match with respect to 4-tuple and configured tuple mask in hw. If successfully classified as exact-match, offload the flow as hash-filter in hw.
--- drivers/net/ethernet/chelsio/cxgb4/cxgb4_filter.c | 148 +++++++++++++++++++++ drivers/net/ethernet/chelsio/cxgb4/cxgb4_filter.h | 2 + .../net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c | 16 ++- 3 files changed, 161 insertions(+), 5 deletions(-)
drivers/net/ethernet/chelsio/cxgb4/cxgb4_filter.c +148 -0
@@ -31,6 +31,7 @@* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ +#include <net/ipv6.h> #include "cxgb4.h" #include "t4_regs.h"
@@ -765,6 +766,153 @@ static void fill_default_mask(struct ch_filter_specification *fs) fs->mask.fport = ~0 ; } +static bool is_addr_all_mask (u8 *ipmask,int family) +{ +if (family ==AF_INET ) { +struct in_addr *addr; + + addr = (struct in_addr *)ipmask; +if (addr->s_addr ==0xffffffff ) +return true; + }else if (family ==AF_INET6 ) { +struct in6_addr *addr6; + + addr6 = (struct in6_addr *)ipmask; +if (addr6->s6_addr32[0 ] ==0xffffffff && + addr6->s6_addr32[1 ] ==0xffffffff && + addr6->s6_addr32[2 ] ==0xffffffff && + addr6->s6_addr32[3 ] ==0xffffffff ) +return true; + } +return false; +} + +static bool is_inaddr_any (u8 *ip,int family) +{ +int addr_type; + +if (family ==AF_INET ) { +struct in_addr *addr; + + addr = (struct in_addr *)ip; +if (addr->s_addr ==htonl (INADDR_ANY )) +return true; + }else if (family ==AF_INET6 ) { +struct in6_addr *addr6; + + addr6 = (struct in6_addr *)ip; + addr_type =ipv6_addr_type ((const struct in6_addr *) + &addr6); +if (addr_type ==IPV6_ADDR_ANY ) +return true; + } +return false; +} + +bool is_filter_exact_match (struct adapter *adap, +struct ch_filter_specification *fs) +{ +struct tp_params *tp = &adap->params.tp; +u64 hash_filter_mask = tp->hash_filter_mask; +u32 mask; + +if (!is_hashfilter (adap)) +return false; + +if (fs->type) { +if (is_inaddr_any (fs->val.fip,AF_INET6 ) || + !is_addr_all_mask (fs->mask.fip,AF_INET6 )) +return false; + +if (is_inaddr_any (fs->val.lip,AF_INET6 ) || + !is_addr_all_mask (fs->mask.lip,AF_INET6 )) +return false; + }else { +if (is_inaddr_any (fs->val.fip,AF_INET ) || + !is_addr_all_mask (fs->mask.fip,AF_INET )) +return false; + +if (is_inaddr_any (fs->val.lip,AF_INET ) || + !is_addr_all_mask (fs->mask.lip,AF_INET )) +return false; + } + +if (!fs->val.lport || fs->mask.lport !=0xffff ) +return false; + +if (!fs->val.fport || fs->mask.fport !=0xffff ) +return false; + +if (tp->fcoe_shift >=0 ) { + mask = (hash_filter_mask >> tp->fcoe_shift) &FT_FCOE_W ; +if (mask && !fs->mask.fcoe) +return false; + } + +if (tp->port_shift >=0 ) { + mask = (hash_filter_mask >> tp->port_shift) &FT_PORT_W ; +if (mask && !fs->mask.iport) +return false; + } + +if (tp->vnic_shift >=0 ) { + mask = (hash_filter_mask >> tp->vnic_shift) &FT_VNIC_ID_W ; + +if ((adap->params.tp.ingress_config &VNIC_F )) { +if (mask && !fs->mask.pfvf_vld) +return false; + }else { +if (mask && !fs->mask.ovlan_vld) +return false; + } + } + +if (tp->vlan_shift >=0 ) { + mask = (hash_filter_mask >> tp->vlan_shift) &FT_VLAN_W ; +if (mask && !fs->mask.ivlan) +return false; + } + +if (tp->tos_shift >=0 ) { + mask = (hash_filter_mask >> tp->tos_shift) &FT_TOS_W ; +if (mask && !fs->mask.tos) +return false; + } + +if (tp->protocol_shift >=0 ) { + mask = (hash_filter_mask >> tp->protocol_shift) &FT_PROTOCOL_W ; +if (mask && !fs->mask.proto) +return false; + } + +if (tp->ethertype_shift >=0 ) { + mask = (hash_filter_mask >> tp->ethertype_shift) & +FT_ETHERTYPE_W ; +if (mask && !fs->mask.ethtype) +return false; + } + +if (tp->macmatch_shift >=0 ) { + mask = (hash_filter_mask >> tp->macmatch_shift) &FT_MACMATCH_W ; +if (mask && !fs->mask.macidx) +return false; + } + +if (tp->matchtype_shift >=0 ) { + mask = (hash_filter_mask >> tp->matchtype_shift) & +FT_MPSHITTYPE_W ; +if (mask && !fs->mask.matchtype) +return false; + } +if (tp->frag_shift >=0 ) { + mask = (hash_filter_mask >> tp->frag_shift) & +FT_FRAGMENTATION_W ; +if (mask && !fs->mask.frag) +return false; + } +return true; +} +static u64 hash_filter_ntuple (struct ch_filter_specification *fs,struct net_device *dev) {
drivers/net/ethernet/chelsio/cxgb4/cxgb4_filter.h +2 -0
@@ -51,4 +51,6 @@ int delete_filter(struct adapter *adapter, unsigned int fidx);int writable_filter (struct filter_entry *f);void clear_all_filters (struct adapter *adapter);int init_hash_filter (struct adapter *adap); +bool is_filter_exact_match (struct adapter *adap, +struct ch_filter_specification *fs);#endif /* __CXGB4_FILTER_H */
drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c +11 -5
@@ -38,6 +38,7 @@#include <net/tc_act/tc_vlan.h> #include "cxgb4.h" +#include "cxgb4_filter.h" #include "cxgb4_tc_flower.h" #define STATS_CHECK_PERIOD (HZ / 2)
@@ -672,11 +673,16 @@ int cxgb4_tc_flower_replace(struct net_device *dev,cxgb4_process_flow_match (dev, cls, fs);cxgb4_process_flow_actions (dev, cls, fs); - fidx =cxgb4_get_free_ftid (dev, fs->type ?PF_INET6 :PF_INET ); -if (fidx <0 ) { -netdev_err (dev,"%s: No fidx for offload.\n" , __func__); - ret = -ENOMEM ; - goto free_entry; + fs->hash =is_filter_exact_match (adap, fs); +if (fs->hash) { + fidx =0 ; + }else { + fidx =cxgb4_get_free_ftid (dev, fs->type ?PF_INET6 :PF_INET ); +if (fidx <0 ) { +netdev_err (dev,"%s: No fidx for offload.\n" , __func__); + ret = -ENOMEM ; + goto free_entry; + } }init_completion (&ctx.completion);
Signature · 1 line
2.14.1
David Miller
maintainerFrom: Rahul Lakkireddy <[email protected]>
Date: Wed, 1 Nov 2017 08:52:58 +0530
Quoted 14 lines
This series of patches add support to create hash-filters; a.k.a exact-match filters, to tc-flower offload. T6 supports creating ~500K hash-filters in hw and can theoretically be expanded up to ~1 million.
Patch 1 fetches and saves the configured hw filter tuple field shifts and filter mask.
Patch 2 initializes the driver to use hash-filter configuration.
Patch 3 adds support to create hash filters in hw.
Patch 4 adds support to delete hash filters in hw.
Quoted 7 lines
Patch 5 adds support to retrieve filter stats for hash filters.
Patch 6 converts the flower table to use rhashtable instead of static hlist.
Patch 7 finally adds support to create hash filters via tc-flower offload.
Series applied, thanks.