From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01on0063.outbound.protection.outlook.com [104.47.1.63]) by dpdk.org (Postfix) with ESMTP id 115FA1B29D for ; Thu, 11 Jan 2018 18:46:15 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=PNArWucFr9y9OdR/D3FtrwbSO6Rt9PYvDSZHJBsPJbk=; b=NsD9jKiM3j9gFUkKMrj5MB6NzUkJqffshJ6eDRI6kriaEakAbJCFAYI6ZYZxeWBUWsfovUfturtN9rD40TL0I9k9fcs4dT708JZJxhd+/uZEF7KETmG3YzDNtnR/ZL5umpRv+1nqDuOk4zM2vAIFvpPyQGRh5uTIVJLFYfyevmc= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=ophirmu@mellanox.com; Received: from mellanox.com (37.142.13.130) by VI1PR0502MB3885.eurprd05.prod.outlook.com (2603:10a6:803:c::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.386.5; Thu, 11 Jan 2018 17:46:13 +0000 From: Ophir Munk To: dev@dpdk.org, Pascal Mazon Cc: Thomas Monjalon , Olga Shern , Ophir Munk Date: Thu, 11 Jan 2018 17:45:50 +0000 Message-Id: <1515692751-25257-5-git-send-email-ophirmu@mellanox.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1515692751-25257-1-git-send-email-ophirmu@mellanox.com> References: <1515567969-27946-1-git-send-email-ophirmu@mellanox.com> <1515692751-25257-1-git-send-email-ophirmu@mellanox.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [37.142.13.130] X-ClientProxiedBy: HE1PR07CA0002.eurprd07.prod.outlook.com (2603:10a6:7:67::12) To VI1PR0502MB3885.eurprd05.prod.outlook.com (2603:10a6:803:c::10) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 40b81ec1-28d8-4c6a-07a6-08d5591b35e8 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020069)(4652020)(48565401081)(5600026)(4604075)(2017052603307)(7153060)(7193020); SRVR:VI1PR0502MB3885; X-Microsoft-Exchange-Diagnostics: 1; VI1PR0502MB3885; 3:JSuN2+oQMRSmk0mmT/9sj/EML0TsblHb5hyCnQxJ/rx9YEGs7H3heDQm1yeO7vBlKV30zn2qisgZcJuTOR6MKf9ghwDnxnlGkyLuiYyLvX4EVM5MzcLpWCFFm19f+42FkcOugjx6vFGoe39u2CCYjRvuccpS4FgyRA/CiqushwhFEXOkhWE7vOcur0E2Eqr2JptMHMhiYh1kbnejgQaoBFvALI7YrsJ56K49KX3E+RuoJxPxiXaOaueM7QLtrYy0; 25:30PDSk60hp2tmfsYMcrrFx216gG0KZ+s6OOqUFtzOHUu9hmluKIsK7zcALJo0icWX1vNDoA5Ul8OLxJKxm6zFYWT80HrRgysKw707daoYKohNX3bPfevklOSRnLkLmGcVid/NcBqGuJ+HANw02EzCRPzmUVICBUaLFM6Hfh1ZsFdfBDIB5V29w7f6+TD/luzgD/DUvK2o9F9WvmwZ847+95w13XkTRxfURE5mQnyntCmiEPIIlDwfr0UCjNoVK5ivrzXMhuLDpMeldi95zRRWdKtg/EZvqizTxrt+Z+Hcryd4VJClV5tz+AJ/qE1qeJ2t+riiZl2a8hzJOBNxFx2wg==; 31:Fh4/ty3XxjPWufk+d1rZwzhr2sQOI+EFCPq6eI96fwAhnL9rNg5h2j2pFBGKbZb3Lgza1FsLJ7/285cqgCesFYz7t9spMQNnMMLwJItl4DbK9nPNxNrYNA7QpKHe8gdgaTmBHte8W6Au0ceUK+70rjgu6pXn290ntN6q329pcp5nSLNjbAg4nSBg/UQmKTjMp9Rm5qwlP0rb138Oq/Wma0/pQxmG7cjgHYHFmQr11go= X-MS-TrafficTypeDiagnostic: VI1PR0502MB3885: X-LD-Processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtAddr X-Microsoft-Exchange-Diagnostics: 1; VI1PR0502MB3885; 20:N6ciWkWsQbf0W1SEoW6GjCb4w+6ipkWAZrPXrOXu0RFFnF2tef5/QJlxFWD/rpjHlD8O/kE3fEbVdlC5KfRt+OWHvHvRJt3obw4qH34GHtVxAn4q+QBW9grXIpXYNlvrvHa/AjsWdrWExuAcHCfqDDLlq5VTCUr0y+sC8/5IxM1cGjqqteDwCORotGAgoITMWgZAzRT+NBiCLQNDRs780ue8iur+X1rLVV0yiVTJtDer/Eml8joh0MHIiqKZ6TecyKSX9KbRX+QCEV3Mbf5JtyQ7uIdy1l2hkY54b8bJwstdobJmd8WeJ6DIo2BoWzvRZw7QhJGrh5Tnk1oe3eBiLYzPm8fLhpPebGMQR5GhfbcJvsjyZIq9s8vQ9B1f+zwnGe7VXfAQ3GvfpKZJklMODLwHvjlr5d5UGWo57Mt9BXeErTJpIcQEFniexkP594QDbqp2n9d+HW6CsTSRv2xVuGJybsy0A9VeOmD+uVu+qHIJDbHI+x+WXRywAHqa89QL; 4:9QL/RcWeUM5Pac1MsJ8/KPp6RZjQPBvTdoTE+ljXmHQ84yHxHi565YauGP9obnJBNot9+y4vqjwJ42jbr7NppndqGonBuQTv4hG4kBK68N5twL1OGF74XARWd8rJ55bwE09d4AaMsQeViJlr4oQO4b3YbVoIhqhyDt/k/Zzmq8XC+ZDCmDQGZp829UrsukUkM/j/XYo6/9rQkZ9XxShBe54UvLpJg3CHvrPuQoVQJKhWJ7eAJ6KDkRyl+t+sc38/Yepcfp+ayqQTEdVFolgz7A== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040470)(2401047)(5005006)(8121501046)(10201501046)(3002001)(3231023)(944501134)(93006095)(93001095)(6055026)(6041268)(20161123564045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123560045)(6072148)(201708071742011); SRVR:VI1PR0502MB3885; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:VI1PR0502MB3885; X-Forefront-PRVS: 0549E6FD50 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(39860400002)(376002)(366004)(396003)(39380400002)(346002)(199004)(189003)(316002)(68736007)(16526018)(97736004)(69596002)(21086003)(16586007)(8676002)(8936002)(81166006)(81156014)(54906003)(50226002)(2906002)(66066001)(3846002)(6116002)(478600001)(47776003)(86362001)(5660300001)(51416003)(52116002)(50466002)(7736002)(305945005)(25786009)(36756003)(7696005)(106356001)(105586002)(386003)(33026002)(53936002)(2950100002)(55016002)(4326008)(4720700003)(107886003)(6666003)(59450400001)(76176011)(48376002)(6916009); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR0502MB3885; H:mellanox.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR0502MB3885; 23:w2UEb92YvBoUqFk8NvaEPSGPA5LHpFUABlIsPyM?= =?us-ascii?Q?70ioR7Wp1sNZy5nyNEmrMRDzFDWcjTVy3pIatEYAKZHtd2HYpLnAC/+gYNLw?= =?us-ascii?Q?mRQ6z9XjrUMQJj8tLRg3vG1vJ3vEhMyxxbOMKpyDc1eP2G0pxyLNGO2yF94/?= =?us-ascii?Q?+ASOJ8LrOXm5of0/i6YzVVvLNdQfVlr/jzMsgnk5lD5cIfub9moD6Wc5BfzO?= =?us-ascii?Q?YHo0dSVt2BNpexA7ki2y/7nZMWaa6N6LS8DT/ucKHRteiD47+JoAnZ9sAcu3?= =?us-ascii?Q?3Luwt0aU8Y2fBkYlRjgAUub9MpAokgyn14RPHI0KmQH3bIuxtxsR3m3siiRX?= =?us-ascii?Q?NiwdDZxKECo22bCJJlgEX34spQo3JXcBEn+SwDFFq1RETWVyBne3+RrhOUwp?= =?us-ascii?Q?Gr+lBe9luJLmCv8AP+ryS52a5gNw12Q9lkd5CSo7RIC7ugp6bYkaKxvhF9xB?= =?us-ascii?Q?UWiKxy4ZUFz5VmY+yQ7ks+5kXV1XuPZtNFSKurPEYFmXd1HcjDqOal/TsU18?= =?us-ascii?Q?mRRSoEYzEWmg0mUCZJLtsl4idLy+9/H/PQQ9L7AwSJOVlNc6XP2S1XMrO3fa?= =?us-ascii?Q?JfHVi0Uuj4O1pz++ksHJhMZF9Tc31XFmQdUMNhItguVpxWq6qEJTQUpZWw2S?= =?us-ascii?Q?iymYghOdSvAl7cqBOggzn8O7EDTD67aB3Jl2QLT8ruByHtiI3lkeNEgBHpeU?= =?us-ascii?Q?4NoRM48xSgESyOOZC6z7zU7rBCr8ly4B6FOKmZBc9yUU9baXHTafdtGImra6?= =?us-ascii?Q?vfr+0gPhrMTdhyf3nfm7aB2bD0p5cVJwqBPuQjLpwMZ4rcrxqZHIB47H4Ubu?= =?us-ascii?Q?MduSvqzpu1GLFM9FEULusCzXx/K/k38S6ZK6SevU4gB/tqVGl8A3HnwkiN5X?= =?us-ascii?Q?WB1KnDAgcmIVlJuIy54uXWhnfwu+6gPrXxiSwZebIZPlBil1lbbNBaJULCZo?= =?us-ascii?Q?XR5qgmeyW7LmtyLA1WkeRfHpErwT8wcrLU8MfT+EghlkEKSfqK8CzOfthcTt?= =?us-ascii?Q?h7tC9vbasQV1uqOZmQ3RKWtgcvBo+/cwk6c6NXy2Cr+vDKdAOaVTKzbjJVnB?= =?us-ascii?Q?qI2RaqNg3ZoDoVn4RX28utDCLCXHD3k7M0c+ChrTL9F137kpg6lE2as4Teby?= =?us-ascii?Q?i1aoSKc3hzWeBknzFHyRtemk38GQiKaM6qRlCINXKcfWRORaws4hP4WTLSwM?= =?us-ascii?Q?7f/+LCJf/PFp5o2AdoGTEUAOU273vsYMSDxTD?= X-Microsoft-Exchange-Diagnostics: 1; VI1PR0502MB3885; 6:6iKiAs4B9dleYrRu1synxJAWTZ6ovSqO08XWnzBlQyv2Gla4HbEFRd45V9ulVzqa/C4B/ikp8Hh/kxKI7jq166+O92CawmXCy7f1RS2ByF3J8cL8BJdQFPVYlppLcv7mgMwWdPYjorR6uTJH1cHVS+8B97/pYF+zrJBleGax26WDP/ApZL1Z/0rH23n4j2yT8FfsQlKjNQqrp2ZVCXLUlTwO56S74cPrLzL4u/j53cTmm31d4ti89NJwQjycO/0CVgCEglQWIrtUKEVO3kHh6B/JBR5sg6+GzYBMgDiD4K1JLIY1QyYTakif4+663NPTYd5VtfxSk8XP6PBd630E42MppWasjx2vDT53dXGvJ1w=; 5:fKcPyMPVExx/+8DODZnQk5861sVjpeV3JhV/gtdrZdA4kHSaD/J95G6e6CCNkZPSDxW/9viGgOeI42BI5w4L1ppiut0uncur6tQ6fIZ6KE/x0wjAHq0kIJ0WYk0f3aba9zFlGuIk/uv6ju56W/QGYEfUD6GIMCdfeqFDKErbju8=; 24:qcP0joywjlAlzZV8rKQIfnml3ULY7q86QNRaxsbaLLrO4VX2CS99mE6o/Z/weaeV1M1WxxFPYJrlc842qEN2mJ7qN87B4gtYDI4TnQDUdgk=; 7:pRmhwitYSUr8zQ+MMzNxR+au7/E00ab42x9Ir5wwpfQwFEI5cT7ujuxZdXqWjxsRwVj3JrY+7a8FQxOrWw0s4FuLzUXFWOwGVVn2CImf7Qw8mYD+k76IRYZY6jJ3XzhWVMsz6uSmrLJfOJPgCb+jpyIz9NJPZ3ivdDpSlTmuRaQmGU0YttIb+n/vkBR9jQJgSH3NV2voPYHn25KhFxi2s2HzY7JWiE6hm54AaeZSf/q3KThwnr+VsCE3L4+Gjv+i SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jan 2018 17:46:13.5868 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 40b81ec1-28d8-4c6a-07a6-08d5591b35e8 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0502MB3885 Subject: [dpdk-dev] [PATCH v4 4/5] net/tap: add eBPF API X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 11 Jan 2018 17:46:16 -0000 This commit include BPF API to be used by TAP. tap_flow_bpf_cls_q() - download to kernel BPF program that classifies packets to their matching queues tap_flow_bpf_calc_l3_l4_hash() - download to kernel BPF program that calculates per packet layer 3 and layer 4 RSS hash tap_flow_bpf_rss_map_create() - create BPF RSS map for storing RSS parameters per RSS rule tap_flow_bpf_update_rss_elem() - update BPF map entry with RSS rule parameters Signed-off-by: Ophir Munk --- drivers/net/tap/Makefile | 6 ++ drivers/net/tap/tap_bpf.h | 112 +++++++++++++++++++++++++ drivers/net/tap/tap_bpf_api.c | 190 ++++++++++++++++++++++++++++++++++++++++++ drivers/net/tap/tap_flow.h | 6 ++ 4 files changed, 314 insertions(+) create mode 100644 drivers/net/tap/tap_bpf.h create mode 100644 drivers/net/tap/tap_bpf_api.c diff --git a/drivers/net/tap/Makefile b/drivers/net/tap/Makefile index fbf84e1..fad8a94 100644 --- a/drivers/net/tap/Makefile +++ b/drivers/net/tap/Makefile @@ -35,6 +35,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_PMD_TAP) += rte_eth_tap.c SRCS-$(CONFIG_RTE_LIBRTE_PMD_TAP) += tap_flow.c SRCS-$(CONFIG_RTE_LIBRTE_PMD_TAP) += tap_netlink.c SRCS-$(CONFIG_RTE_LIBRTE_PMD_TAP) += tap_tcmsgs.c +SRCS-$(CONFIG_RTE_LIBRTE_PMD_TAP) += tap_bpf_api.c include $(RTE_SDK)/mk/rte.lib.mk @@ -61,6 +62,11 @@ tap_autoconf.h.new: $(RTE_SDK)/buildtools/auto-config-h.sh linux/pkt_cls.h \ enum TCA_FLOWER_KEY_VLAN_PRIO \ $(AUTOCONF_OUTPUT) + $Q sh -- '$<' '$@' \ + HAVE_BPF_PROG_LOAD \ + linux/bpf.h \ + enum BPF_PROG_LOAD \ + $(AUTOCONF_OUTPUT) # Create tap_autoconf.h or update it in case it differs from the new one. diff --git a/drivers/net/tap/tap_bpf.h b/drivers/net/tap/tap_bpf.h new file mode 100644 index 0000000..30eefb3 --- /dev/null +++ b/drivers/net/tap/tap_bpf.h @@ -0,0 +1,112 @@ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 + * Copyright 2017 Mellanox Technologies, Ltd. + */ + +#ifndef __TAP_BPF_H__ +#define __TAP_BPF_H__ + +#include + +#ifdef HAVE_BPF_PROG_LOAD +#include +#else +/* BPF_MAP_UPDATE_ELEM command flags */ +#define BPF_ANY 0 /* create a new element or update an existing */ + +/* BPF architecture instruction struct */ +struct bpf_insn { + __u8 code; + __u8 dst_reg:4; + __u8 src_reg:4; + __s16 off; + __s32 imm; /* immediate value */ +}; + +/* BPF program types */ +enum bpf_prog_type { + BPF_PROG_TYPE_UNSPEC, + BPF_PROG_TYPE_SOCKET_FILTER, + BPF_PROG_TYPE_KPROBE, + BPF_PROG_TYPE_SCHED_CLS, + BPF_PROG_TYPE_SCHED_ACT, +}; + +/* BPF commands types */ +enum bpf_cmd { + BPF_MAP_CREATE, + BPF_MAP_LOOKUP_ELEM, + BPF_MAP_UPDATE_ELEM, + BPF_MAP_DELETE_ELEM, + BPF_MAP_GET_NEXT_KEY, + BPF_PROG_LOAD, +}; + +/* BPF maps types */ +enum bpf_map_type { + BPF_MAP_TYPE_UNSPEC, + BPF_MAP_TYPE_HASH, +}; + +/* union of anonymous structs used with TAP BPF commands */ +union bpf_attr { + /* BPF_MAP_CREATE command */ + struct { + __u32 map_type; + __u32 key_size; + __u32 value_size; + __u32 max_entries; + __u32 map_flags; + __u32 inner_map_fd; + }; + + /* BPF_MAP_UPDATE_ELEM, BPF_MAP_DELETE_ELEM commands */ + struct { + __u32 map_fd; + __aligned_u64 key; + union { + __aligned_u64 value; + __aligned_u64 next_key; + }; + __u64 flags; + }; + + /* BPF_PROG_LOAD command */ + struct { + __u32 prog_type; + __u32 insn_cnt; + __aligned_u64 insns; + __aligned_u64 license; + __u32 log_level; + __u32 log_size; + __aligned_u64 log_buf; + __u32 kern_version; + __u32 prog_flags; + }; +} __attribute__((aligned(8))); +#endif + +#ifndef __NR_bpf +# if defined(__i386__) +# define __NR_bpf 357 +# elif defined(__x86_64__) +# define __NR_bpf 321 +# elif defined(__aarch64__) +# define __NR_bpf 280 +# elif defined(__sparc__) +# define __NR_bpf 349 +# elif defined(__s390__) +# define __NR_bpf 351 +# else +# error __NR_bpf not defined +# endif +#endif + +enum { + BPF_MAP_ID_KEY, + BPF_MAP_ID_SIMPLE, +}; + +static int bpf_load(enum bpf_prog_type type, const struct bpf_insn *insns, + size_t insns_cnt, const char *license); + +#endif /* __TAP_BPF_H__ */ diff --git a/drivers/net/tap/tap_bpf_api.c b/drivers/net/tap/tap_bpf_api.c new file mode 100644 index 0000000..109a681 --- /dev/null +++ b/drivers/net/tap/tap_bpf_api.c @@ -0,0 +1,190 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright 2017 Mellanox Technologies, Ltd. + */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +/** + * Load BPF program (section cls_q) into the kernel and return a bpf fd + * + * @param queue_idx + * Queue index matching packet cb + * + * @return + * -1 if the BPF program couldn't be loaded. An fd (int) otherwise. + */ +int tap_flow_bpf_cls_q(__u32 queue_idx) +{ + cls_q_insns[1].imm = queue_idx; + + return bpf_load(BPF_PROG_TYPE_SCHED_CLS, + (struct bpf_insn *)cls_q_insns, + RTE_DIM(cls_q_insns), + "Dual BSD/GPL"); +} + +/** + * Load BPF program (section l3_l4) into the kernel and return a bpf fd. + * + * @param[in] key_idx + * RSS MAP key index + * + * @param[in] map_fd + * BPF RSS map file descriptor + * + * @return + * -1 if the BPF program couldn't be loaded. An fd (int) otherwise. + */ +int tap_flow_bpf_calc_l3_l4_hash(__u32 key_idx, int map_fd) +{ + l3_l4_hash_insns[4].imm = key_idx; + l3_l4_hash_insns[9].imm = map_fd; + + return bpf_load(BPF_PROG_TYPE_SCHED_ACT, + (struct bpf_insn *)l3_l4_hash_insns, + RTE_DIM(l3_l4_hash_insns), + "Dual BSD/GPL"); +} + +/** + * Helper function to convert a pointer to unsigned 64 bits + * + * @param[in] ptr + * pointer to address + * + * @return + * 64 bit unsigned long type of pointer address + */ +static inline __u64 ptr_to_u64(const void *ptr) +{ + return (__u64)(unsigned long)ptr; +} + +/** + * Call BPF system call + * + * @param[in] cmd + * BPF command for program loading, map creation, map entry update, etc + * + * @param[in] attr + * System call attributes relevant to system call command + * + * @param[in] size + * size of attr parameter + * + * @return + * -1 if BPF system call failed, 0 otherwise + */ +static inline int sys_bpf(enum bpf_cmd cmd, union bpf_attr *attr, + unsigned int size) +{ + return syscall(__NR_bpf, cmd, attr, size); +} + +/** + * Load BPF instructions to kernel + * + * @param[in] type + * BPF program type: classifieir or action + * + * @param[in] insns + * Array of BPF instructions (equivalent to BPF instructions) + * + * @param[in] insns_cnt + * Number of BPF instructions (size of array) + * + * @param[in] lincense + * License string that must be acknowledged by the kernel + * + * @return + * -1 if the BPF program couldn't be loaded, fd (file descriptor) otherwise + */ +static int bpf_load(enum bpf_prog_type type, + const struct bpf_insn *insns, + size_t insns_cnt, + const char *license) +{ + union bpf_attr attr = {}; + + bzero(&attr, sizeof(attr)); + attr.prog_type = type; + attr.insn_cnt = (__u32)insns_cnt; + attr.insns = ptr_to_u64(insns); + attr.license = ptr_to_u64(license); + attr.log_buf = ptr_to_u64(NULL); + attr.log_level = 0; + attr.kern_version = 0; + + return sys_bpf(BPF_PROG_LOAD, &attr, sizeof(attr)); +} + +/** + * Create BPF map for RSS rules + * + * @param[in] key_size + * map RSS key size + * + * @param[in] value_size + * Map RSS value size + * + * @param[in] max_entries + * Map max number of RSS entries (limit on max RSS rules) + * + * @return + * -1 if BPF map couldn't be created, map fd otherwise + */ +int tap_flow_bpf_rss_map_create(unsigned int key_size, + unsigned int value_size, + unsigned int max_entries) +{ + union bpf_attr attr = {}; + + bzero(&attr, sizeof(attr)); + attr.map_type = BPF_MAP_TYPE_HASH; + attr.key_size = key_size; + attr.value_size = value_size; + attr.max_entries = max_entries; + + return sys_bpf(BPF_MAP_CREATE, &attr, sizeof(attr)); +} + +/** + * Update RSS entry in BPF map + * + * @param[in] fd + * RSS map fd + * + * @param[in] key + * Pointer to RSS key whose entry is updated + * + * @param[in] value + * Pointer to RSS new updated value + * + * @return + * -1 if RSS entry failed to be updated, 0 otherwise + */ +int tap_flow_bpf_update_rss_elem(int fd, void *key, void *value) +{ + union bpf_attr attr = {}; + + bzero(&attr, sizeof(attr)); + + attr.map_type = BPF_MAP_TYPE_HASH; + attr.map_fd = fd; + attr.key = ptr_to_u64(key); + attr.value = ptr_to_u64(value); + attr.flags = BPF_ANY; + + return sys_bpf(BPF_MAP_UPDATE_ELEM, &attr, sizeof(attr)); +} diff --git a/drivers/net/tap/tap_flow.h b/drivers/net/tap/tap_flow.h index 9e332b0..894c959 100644 --- a/drivers/net/tap/tap_flow.h +++ b/drivers/net/tap/tap_flow.h @@ -80,4 +80,10 @@ int tap_flow_implicit_destroy(struct pmd_internals *pmd, int tap_flow_implicit_flush(struct pmd_internals *pmd, struct rte_flow_error *error); +int tap_flow_bpf_cls_q(__u32 queue_idx); +int tap_flow_bpf_calc_l3_l4_hash(__u32 key_idx, int map_fd); +int tap_flow_bpf_rss_map_create(unsigned int key_size, unsigned int value_size, + unsigned int max_entries); +int tap_flow_bpf_update_rss_elem(int fd, void *key, void *value); + #endif /* _TAP_FLOW_H_ */ -- 2.7.4