16a345b3dSKumar Sanghvi /* 26a345b3dSKumar Sanghvi * This file is part of the Chelsio T4/T5/T6 Ethernet driver for Linux. 36a345b3dSKumar Sanghvi * 46a345b3dSKumar Sanghvi * Copyright (c) 2017 Chelsio Communications, Inc. All rights reserved. 56a345b3dSKumar Sanghvi * 66a345b3dSKumar Sanghvi * This software is available to you under a choice of one of two 76a345b3dSKumar Sanghvi * licenses. You may choose to be licensed under the terms of the GNU 86a345b3dSKumar Sanghvi * General Public License (GPL) Version 2, available from the file 96a345b3dSKumar Sanghvi * COPYING in the main directory of this source tree, or the 106a345b3dSKumar Sanghvi * OpenIB.org BSD license below: 116a345b3dSKumar Sanghvi * 126a345b3dSKumar Sanghvi * Redistribution and use in source and binary forms, with or 136a345b3dSKumar Sanghvi * without modification, are permitted provided that the following 146a345b3dSKumar Sanghvi * conditions are met: 156a345b3dSKumar Sanghvi * 166a345b3dSKumar Sanghvi * - Redistributions of source code must retain the above 176a345b3dSKumar Sanghvi * copyright notice, this list of conditions and the following 186a345b3dSKumar Sanghvi * disclaimer. 196a345b3dSKumar Sanghvi * 206a345b3dSKumar Sanghvi * - Redistributions in binary form must reproduce the above 216a345b3dSKumar Sanghvi * copyright notice, this list of conditions and the following 226a345b3dSKumar Sanghvi * disclaimer in the documentation and/or other materials 236a345b3dSKumar Sanghvi * provided with the distribution. 246a345b3dSKumar Sanghvi * 256a345b3dSKumar Sanghvi * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 266a345b3dSKumar Sanghvi * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 276a345b3dSKumar Sanghvi * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 286a345b3dSKumar Sanghvi * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 296a345b3dSKumar Sanghvi * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 306a345b3dSKumar Sanghvi * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 316a345b3dSKumar Sanghvi * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 326a345b3dSKumar Sanghvi * SOFTWARE. 336a345b3dSKumar Sanghvi */ 346a345b3dSKumar Sanghvi 356a345b3dSKumar Sanghvi #ifndef __CXGB4_TC_FLOWER_H 366a345b3dSKumar Sanghvi #define __CXGB4_TC_FLOWER_H 376a345b3dSKumar Sanghvi 386a345b3dSKumar Sanghvi #include <net/pkt_cls.h> 396a345b3dSKumar Sanghvi 4062488e4bSKumar Sanghvi struct ch_tc_flower_stats { 41e0f911c8SKumar Sanghvi u64 prev_packet_count; 4262488e4bSKumar Sanghvi u64 packet_count; 4362488e4bSKumar Sanghvi u64 byte_count; 4462488e4bSKumar Sanghvi u64 last_used; 4562488e4bSKumar Sanghvi }; 4662488e4bSKumar Sanghvi 4762488e4bSKumar Sanghvi struct ch_tc_flower_entry { 4862488e4bSKumar Sanghvi struct ch_filter_specification fs; 4962488e4bSKumar Sanghvi struct ch_tc_flower_stats stats; 5062488e4bSKumar Sanghvi unsigned long tc_flower_cookie; 5179e6d46aSKumar Sanghvi struct rhash_head node; 5262488e4bSKumar Sanghvi struct rcu_head rcu; 53e0f911c8SKumar Sanghvi spinlock_t lock; /* lock for stats */ 5462488e4bSKumar Sanghvi u32 filter_id; 5562488e4bSKumar Sanghvi }; 5662488e4bSKumar Sanghvi 5727ece1f3SKumar Sanghvi enum { 5827ece1f3SKumar Sanghvi ETH_DMAC_31_0, /* dmac bits 0.. 31 */ 5927ece1f3SKumar Sanghvi ETH_DMAC_47_32, /* dmac bits 32..47 */ 60202187c3SKumar Sanghvi ETH_SMAC_15_0, /* smac bits 0.. 15 */ 61202187c3SKumar Sanghvi ETH_SMAC_47_16, /* smac bits 16..47 */ 62557ccbf9SKumar Sanghvi 63557ccbf9SKumar Sanghvi IP4_SRC, /* 32-bit IPv4 src */ 64557ccbf9SKumar Sanghvi IP4_DST, /* 32-bit IPv4 dst */ 65557ccbf9SKumar Sanghvi 66557ccbf9SKumar Sanghvi IP6_SRC_31_0, /* src bits 0.. 31 */ 67557ccbf9SKumar Sanghvi IP6_SRC_63_32, /* src bits 63.. 32 */ 68557ccbf9SKumar Sanghvi IP6_SRC_95_64, /* src bits 95.. 64 */ 69557ccbf9SKumar Sanghvi IP6_SRC_127_96, /* src bits 127..96 */ 70557ccbf9SKumar Sanghvi 71557ccbf9SKumar Sanghvi IP6_DST_31_0, /* dst bits 0.. 31 */ 72557ccbf9SKumar Sanghvi IP6_DST_63_32, /* dst bits 63.. 32 */ 73557ccbf9SKumar Sanghvi IP6_DST_95_64, /* dst bits 95.. 64 */ 74557ccbf9SKumar Sanghvi IP6_DST_127_96, /* dst bits 127..96 */ 75557ccbf9SKumar Sanghvi 76557ccbf9SKumar Sanghvi TCP_SPORT, /* 16-bit TCP sport */ 77557ccbf9SKumar Sanghvi TCP_DPORT, /* 16-bit TCP dport */ 78557ccbf9SKumar Sanghvi 79557ccbf9SKumar Sanghvi UDP_SPORT, /* 16-bit UDP sport */ 80557ccbf9SKumar Sanghvi UDP_DPORT, /* 16-bit UDP dport */ 8127ece1f3SKumar Sanghvi }; 8227ece1f3SKumar Sanghvi 8327ece1f3SKumar Sanghvi struct ch_tc_pedit_fields { 8427ece1f3SKumar Sanghvi u8 field; 8527ece1f3SKumar Sanghvi u8 size; 8627ece1f3SKumar Sanghvi u32 offset; 8727ece1f3SKumar Sanghvi }; 8827ece1f3SKumar Sanghvi 8927ece1f3SKumar Sanghvi #define PEDIT_FIELDS(type, field, size, fs_field, offset) \ 9027ece1f3SKumar Sanghvi { type## field, size, \ 9127ece1f3SKumar Sanghvi offsetof(struct ch_filter_specification, fs_field) + (offset) } 9227ece1f3SKumar Sanghvi 9327ece1f3SKumar Sanghvi #define PEDIT_ETH_DMAC_MASK 0xffff 94557ccbf9SKumar Sanghvi #define PEDIT_TCP_UDP_SPORT_MASK 0xffff 9527ece1f3SKumar Sanghvi #define PEDIT_ETH_DMAC_31_0 0x0 9627ece1f3SKumar Sanghvi #define PEDIT_ETH_DMAC_47_32_SMAC_15_0 0x4 97202187c3SKumar Sanghvi #define PEDIT_ETH_SMAC_47_16 0x8 98557ccbf9SKumar Sanghvi #define PEDIT_IP4_SRC 0xC 99557ccbf9SKumar Sanghvi #define PEDIT_IP4_DST 0x10 100557ccbf9SKumar Sanghvi #define PEDIT_IP6_SRC_31_0 0x8 101557ccbf9SKumar Sanghvi #define PEDIT_IP6_SRC_63_32 0xC 102557ccbf9SKumar Sanghvi #define PEDIT_IP6_SRC_95_64 0x10 103557ccbf9SKumar Sanghvi #define PEDIT_IP6_SRC_127_96 0x14 104557ccbf9SKumar Sanghvi #define PEDIT_IP6_DST_31_0 0x18 105557ccbf9SKumar Sanghvi #define PEDIT_IP6_DST_63_32 0x1C 106557ccbf9SKumar Sanghvi #define PEDIT_IP6_DST_95_64 0x20 107557ccbf9SKumar Sanghvi #define PEDIT_IP6_DST_127_96 0x24 108557ccbf9SKumar Sanghvi #define PEDIT_TCP_SPORT_DPORT 0x0 109557ccbf9SKumar Sanghvi #define PEDIT_UDP_SPORT_DPORT 0x0 11027ece1f3SKumar Sanghvi 111*2ef813b8SHerat Ramani enum cxgb4_action_natmode_flags { 112*2ef813b8SHerat Ramani CXGB4_ACTION_NATMODE_NONE = 0, 113*2ef813b8SHerat Ramani CXGB4_ACTION_NATMODE_DIP = (1 << 0), 114*2ef813b8SHerat Ramani CXGB4_ACTION_NATMODE_SIP = (1 << 1), 115*2ef813b8SHerat Ramani CXGB4_ACTION_NATMODE_DPORT = (1 << 2), 116*2ef813b8SHerat Ramani CXGB4_ACTION_NATMODE_SPORT = (1 << 3), 117*2ef813b8SHerat Ramani }; 118*2ef813b8SHerat Ramani 119*2ef813b8SHerat Ramani /* TC PEDIT action to NATMODE translation entry */ 120*2ef813b8SHerat Ramani struct cxgb4_natmode_config { 121*2ef813b8SHerat Ramani enum chip_type chip; 122*2ef813b8SHerat Ramani u8 flags; 123*2ef813b8SHerat Ramani u8 natmode; 124*2ef813b8SHerat Ramani }; 125*2ef813b8SHerat Ramani 12621c4c60bSRahul Lakkireddy void cxgb4_process_flow_actions(struct net_device *in, 12721c4c60bSRahul Lakkireddy struct flow_action *actions, 12821c4c60bSRahul Lakkireddy struct ch_filter_specification *fs); 12921c4c60bSRahul Lakkireddy int cxgb4_validate_flow_actions(struct net_device *dev, 130319a1d19SJiri Pirko struct flow_action *actions, 131fd2261d8SRahul Lakkireddy struct netlink_ext_ack *extack, 132fd2261d8SRahul Lakkireddy u8 matchall_filter); 13321c4c60bSRahul Lakkireddy 1346a345b3dSKumar Sanghvi int cxgb4_tc_flower_replace(struct net_device *dev, 135f9e30088SPablo Neira Ayuso struct flow_cls_offload *cls); 1366a345b3dSKumar Sanghvi int cxgb4_tc_flower_destroy(struct net_device *dev, 137f9e30088SPablo Neira Ayuso struct flow_cls_offload *cls); 1386a345b3dSKumar Sanghvi int cxgb4_tc_flower_stats(struct net_device *dev, 139f9e30088SPablo Neira Ayuso struct flow_cls_offload *cls); 140c8729cacSVishal Kulkarni int cxgb4_flow_rule_replace(struct net_device *dev, struct flow_rule *rule, 141c8729cacSVishal Kulkarni u32 tc_prio, struct netlink_ext_ack *extack, 142c8729cacSVishal Kulkarni struct ch_filter_specification *fs, u32 *tid); 143db43b30cSVishal Kulkarni int cxgb4_flow_rule_destroy(struct net_device *dev, u32 tc_prio, 144db43b30cSVishal Kulkarni struct ch_filter_specification *fs, int tid); 14562488e4bSKumar Sanghvi 14679e6d46aSKumar Sanghvi int cxgb4_init_tc_flower(struct adapter *adap); 147e0f911c8SKumar Sanghvi void cxgb4_cleanup_tc_flower(struct adapter *adap); 1486a345b3dSKumar Sanghvi #endif /* __CXGB4_TC_FLOWER_H */ 149