|
| 1 | +/* |
| 2 | + * DPVS is a software load balancer (Virtual Server) based on DPDK. |
| 3 | + * |
| 4 | + * Copyright (C) 2020 ByteDance (www.bytedance.com). |
| 5 | + * All Rights Reserved. |
| 6 | + * |
| 7 | + * This program is free software; you can redistribute it and/or |
| 8 | + * modify it under the terms of the GNU General Public License |
| 9 | + * as published by the Free Software Foundation; either version 2 |
| 10 | + * of the License, or (at your option) any later version. |
| 11 | + * |
| 12 | + * This program is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU General Public License for more details. |
| 16 | + * |
| 17 | + * Copyright (C) 2020 ByteDance (www.bytedance.com). |
| 18 | + * All Rights Reserved. |
| 19 | + * |
| 20 | + |
| 21 | + */ |
| 22 | +#ifndef __NETDEV_FLOW_H__ |
| 23 | +#define __NETDEV_FLOW_H__ |
| 24 | + |
| 25 | +#include <assert.h> |
| 26 | +#include <rte_flow.h> |
| 27 | + |
| 28 | +#include "conf/common.h" |
| 29 | +#include "netif.h" |
| 30 | + |
| 31 | +#ifndef NETDEV |
| 32 | +#define NETDEV |
| 33 | +#define RTE_LOGTYPE_NETDEV RTE_LOGTYPE_USER1 |
| 34 | +#endif |
| 35 | + |
| 36 | +#define DEFAULT_MAX_PATTERNS 6 |
| 37 | +#define DEFAULT_MAX_ACTIONS 6 |
| 38 | + |
| 39 | +#define NETDEV_FLOW_DEFAULT_MARK_ID 1 |
| 40 | +#define NETDEV_FLOW_DEFAULT_RSS_LEVEL 0 |
| 41 | + |
| 42 | +/* fuzzy match level with signature mode */ |
| 43 | +#define DEFAULT_FUZZY_SPEC 2 |
| 44 | +#define DEFAULT_FUZZY_LAST 0xfffffff0 |
| 45 | +#define DEFAULT_FUZZY_MASK 0xffffffff |
| 46 | + |
| 47 | +#define NETDEV_IXGBE_DRIVER_NAME "ixgbe" |
| 48 | +#define NETDEV_I40E_DRIVER_NAME "i40e" |
| 49 | +#define NETDEV_MLNX_DRIVER_NAME "net_mlx5" |
| 50 | + |
| 51 | +/* flags for netdev flow */ |
| 52 | +#define NETDEV_FLOW_F_SIP_FIELD (1 << 0) |
| 53 | +#define NETDEV_FLOW_F_DIP_FIELD (1 << 1) |
| 54 | +#define NETDEV_FLOW_F_SPORT_FIELD (1 << 2) |
| 55 | +#define NETDEV_FLOW_F_DPORT_FIELD (1 << 3) |
| 56 | +#define NETDEV_FLOW_F_L3_PROTO_FIELD (1 << 4) |
| 57 | +#define NETDEV_FLOW_F_L4_PROTO_FIELD (1 << 5) |
| 58 | + |
| 59 | +/* |
| 60 | + * assign static priority on various flow |
| 61 | + * the smaller the priority higher on mellanox nic. |
| 62 | + */ |
| 63 | +enum netdev_flow_priority { |
| 64 | + NETDEV_FLOW_PRIORITY_NONE = 0, |
| 65 | + NETDEV_FLOW_PRIORITY_FILTER, |
| 66 | + NETDEV_FLOW_PRIORITY_VXLAN, |
| 67 | + NETDEV_FLOW_PRIORITY_RSS, |
| 68 | +}; |
| 69 | + |
| 70 | +/* move to next acts index, abort on failure */ |
| 71 | +#define get_next_acts_index(index) do { \ |
| 72 | + assert((index) < DEFAULT_MAX_ACTIONS - 1); \ |
| 73 | + (index)++; \ |
| 74 | + } while(0) |
| 75 | + |
| 76 | +/* move to next patts index, abort on failure */ |
| 77 | +#define get_next_patts_index(index) do { \ |
| 78 | + assert((index) < DEFAULT_MAX_PATTERNS - 1); \ |
| 79 | + (index)++; \ |
| 80 | + } while(0) |
| 81 | + |
| 82 | +/* netdev rss flow init */ |
| 83 | +#define NETDEV_RSS_FLOW_INIT(flow, port) do { \ |
| 84 | + flow->type = NETDEV_FLOW_TYPE_RSS; \ |
| 85 | + flow->port_id = port->id; \ |
| 86 | + flow->flow_handle = NULL; \ |
| 87 | + flow->hw_offloaded = false; \ |
| 88 | + flow->flow_id = netdev_flow_hash(flow); \ |
| 89 | + } while(0) |
| 90 | + |
| 91 | +enum netdev_flow_type { |
| 92 | + NETDEV_FLOW_TYPE_RSS, |
| 93 | + NETDEV_FLOW_TYPE_FILTER, |
| 94 | + NETDEV_FLOW_TYPE_MAX |
| 95 | +}; |
| 96 | + |
| 97 | +union netdev_flow_query { |
| 98 | + struct rte_flow_query_count count; |
| 99 | + struct rte_flow_action_queue queue; |
| 100 | + struct rte_flow_action_rss rss_conf; |
| 101 | +}; |
| 102 | + |
| 103 | +struct netdev_flow_stats { |
| 104 | + uint64_t n_pkts; |
| 105 | + uint64_t n_bytes; |
| 106 | +}; |
| 107 | + |
| 108 | +struct netdev_flow { |
| 109 | + enum netdev_flow_type type; |
| 110 | + portid_t port_id; |
| 111 | + |
| 112 | + /* flow meta data */ |
| 113 | + union { |
| 114 | + struct { |
| 115 | + queueid_t rss_queues[NETIF_MAX_QUEUES]; |
| 116 | + uint32_t rss_queue_num; |
| 117 | + } rss_info; |
| 118 | + struct { |
| 119 | + queueid_t queue_id; |
| 120 | + uint16_t sport; |
| 121 | + uint16_t dport; |
| 122 | + uint8_t l3_proto; |
| 123 | + uint8_t l4_proto; |
| 124 | + union inet_addr saddr; |
| 125 | + union inet_addr daddr; |
| 126 | + } filter_info; |
| 127 | + } data; |
| 128 | + |
| 129 | + uint32_t flags; |
| 130 | + /* unique flow id */ |
| 131 | + uint32_t flow_id; |
| 132 | + |
| 133 | + /* pointer to rte flow in hardware */ |
| 134 | + struct rte_flow *flow_handle; |
| 135 | + bool hw_offloaded; |
| 136 | + struct list_head list; |
| 137 | + struct netdev_flow_stats stats; |
| 138 | +}; |
| 139 | + |
| 140 | +/* l4_proto used by i40e only */ |
| 141 | +int netdev_flow_add_kni_filter(struct netif_port *port, |
| 142 | + const union inet_addr *kni_ip, |
| 143 | + queueid_t kni_queue_id, |
| 144 | + uint8_t l3_proto, |
| 145 | + uint8_t l4_proto); |
| 146 | +/* called on ttgw initial */ |
| 147 | +int netdev_flow_add_rss_filter(struct netif_port *port); |
| 148 | + |
| 149 | +/* |
| 150 | + * NOTE: netdev flow api, operate flow on initial or terminal, |
| 151 | + * need to use lock on rte_flow_* in case of concurrent. |
| 152 | + */ |
| 153 | +int netdev_flow_init(struct netif_port *port); |
| 154 | +int netdev_flow_add(struct netif_port *port, |
| 155 | + struct netdev_flow *netdev_flow); |
| 156 | +int netdev_flow_del(struct netif_port *port, |
| 157 | + struct netdev_flow *netdev_flow); |
| 158 | +int netdev_flow_query(struct netif_port *port, |
| 159 | + struct netdev_flow *netdev_flow, |
| 160 | + union netdev_flow_query *query); |
| 161 | +int netdev_flow_flush(struct netif_port *port); |
| 162 | + |
| 163 | +#endif /* __NETDEV_FLOW_H__ */ |
0 commit comments