From patchwork Wed Sep 28 12:42:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Horman X-Patchwork-Id: 676192 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (archives.nicira.com [96.126.127.54]) by ozlabs.org (Postfix) with ESMTP id 3skcnb6t2tz9t0P for ; Wed, 28 Sep 2016 22:43:31 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=netronome-com.20150623.gappssmtp.com header.i=@netronome-com.20150623.gappssmtp.com header.b=NKIyD8X7; dkim-atps=neutral Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id D63D010619; Wed, 28 Sep 2016 05:43:15 -0700 (PDT) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx1e3.cudamail.com (mx1.cudamail.com [69.90.118.67]) by archives.nicira.com (Postfix) with ESMTPS id 257CA103B8 for ; Wed, 28 Sep 2016 05:43:13 -0700 (PDT) Received: from bar5.cudamail.com (localhost [127.0.0.1]) by mx1e3.cudamail.com (Postfix) with ESMTPS id B09DB42046A for ; Wed, 28 Sep 2016 06:43:12 -0600 (MDT) X-ASG-Debug-ID: 1475066592-09eadd519cc0390001-byXFYA Received: from mx1-pf2.cudamail.com ([192.168.24.2]) by bar5.cudamail.com with ESMTP id DmLpBenvmlidrCWh (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 28 Sep 2016 06:43:12 -0600 (MDT) X-Barracuda-Envelope-From: simon.horman@netronome.com X-Barracuda-RBL-Trusted-Forwarder: 192.168.24.2 Received: from unknown (HELO mail-wm0-f50.google.com) (74.125.82.50) by mx1-pf2.cudamail.com with ESMTPS (AES128-SHA encrypted); 28 Sep 2016 12:43:11 -0000 Received-SPF: neutral (mx1-pf2.cudamail.com: 74.125.82.50 is neither permitted nor denied by SPF record at mktomail.com) X-Barracuda-Apparent-Source-IP: 74.125.82.50 X-Barracuda-RBL-IP: 74.125.82.50 Received: by mail-wm0-f50.google.com with SMTP id b130so69639179wmc.0 for ; Wed, 28 Sep 2016 05:43:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netronome-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=LSQkjZzJw3Z09HKw9ocUAALa8Adg7DvBcVZQGl200F4=; b=NKIyD8X70gsX4FJQjzxFhQhUVrzy8F6QW6j8wka/eCSU8f/d7km4puPPOnOVy1OziK EFWdvTreRil+xlrIzFCvfFatw5eY+BTYycyYzfwORohBA5BARgjz70fKFRav6g1h00L0 CfnE3vxACmCH66jB981wESeLun1CXR8IbZbKf1piJT/1Z5SZgIgIZ+3W1vBCEhxhwNNC XOaFTsp4lJRzRmOHASE4t9r3kWyG0M2E4d6h2kqIcsH8bYY1xB7gCk2IBU0/0QNd6obT wEfvEbcFddA6Bp3xuHDM6hqxF4/TyMS4JOOTWZfNnmG4/y5XlxQRjo++taUR+sZxkomv ZVEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=LSQkjZzJw3Z09HKw9ocUAALa8Adg7DvBcVZQGl200F4=; b=ADRlvNQ71QEEys8OKIot4RPVBqJM9XJdEqzXPNJK+Y/jDNpGFC3NyB/7VGUGBuaGqD W+QARhylYoLWajJZfnOaYj+0HpbtCw1hc+KsG372f30dQadxQFS1NGzyb7QzKaK/vdzv AH5ScsagGyBSywY6AazZjMtnimrPhvCaI0VyRwonLXxcPRXM9DSAQRBMspvcUfPW35yn K+eO8t4P//w8i383PfYLuu/zD7jszKuxT8UNNehRIP+BppFb6KclJ9CdJMNN1/bRlQLE VPTA7a6w1wi0gI9do8JXeopDfTrkB4fWUSJRvWNY+x90+333QpPmrXbKT2Nt4bhR1Y0c lC0A== X-Gm-Message-State: AA6/9Rm4t3G/eY3dwTv18hCrI4rkk06F62P4EIUJlPyRboouDA+ezYTog6RKjFWN71sF/88e X-Received: by 10.28.23.18 with SMTP id 18mr7705735wmx.100.1475066589826; Wed, 28 Sep 2016 05:43:09 -0700 (PDT) Received: from penelope.horms.nl (52D9BC73.cm-11-1c.dynamic.ziggo.nl. [82.217.188.115]) by smtp.gmail.com with ESMTPSA id g17sm8661670wme.3.2016.09.28.05.43.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 28 Sep 2016 05:43:08 -0700 (PDT) X-CudaMail-Envelope-Sender: simon.horman@netronome.com From: Simon Horman To: netdev@vger.kernel.org, dev@openvswitch.org X-CudaMail-MID: CM-E2-927012434 X-CudaMail-DTE: 092816 X-CudaMail-Originating-IP: 74.125.82.50 Date: Wed, 28 Sep 2016 14:42:52 +0200 X-ASG-Orig-Subj: [##CM-E2-927012434##][PATCH/RFC 02/12] switchdev: Add Open vSwitch (-like) flow object support Message-Id: <1475066582-1971-3-git-send-email-simon.horman@netronome.com> X-Mailer: git-send-email 2.7.0.rc3.207.g0ac5344 In-Reply-To: <1475066582-1971-1-git-send-email-simon.horman@netronome.com> References: <1475066582-1971-1-git-send-email-simon.horman@netronome.com> X-GBUdb-Analysis: 0, 74.125.82.50, Ugly c=0.436326 p=-0.304348 Source Normal X-MessageSniffer-Rules: 0-0-0-12851-c X-Barracuda-Connect: UNKNOWN[192.168.24.2] X-Barracuda-Start-Time: 1475066592 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://web.cudamail.com:443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at cudamail.com X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.60 X-Barracuda-Spam-Status: No, SCORE=0.60 using global scores of TAG_LEVEL=3.5 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=4.0 tests=BSF_SC0_MISMATCH_TO, BSF_SC5_MJ1963, DKIM_SIGNED, RDNS_NONE X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.33289 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.00 BSF_SC0_MISMATCH_TO Envelope rcpt doesn't match header 0.00 DKIM_SIGNED Domain Keys Identified Mail: message has a signature 0.10 RDNS_NONE Delivered to trusted network by a host with no rDNS 0.50 BSF_SC5_MJ1963 Custom Rule MJ1963 Cc: Simon Horman Subject: [ovs-dev] [PATCH/RFC 02/12] switchdev: Add Open vSwitch (-like) flow object support X-BeenThere: dev@openvswitch.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dev-bounces@openvswitch.org Sender: "dev" The motivation of this patch is to provide objects for Open vSwitch (-like) flows so that they may be programmed into hardware using switchdev. The structures used here may well prove to be too Open vSwitch centric, but the purpose of the prototype of which this patch is part is to explore if switchdev is an appropriate mechanism for programming Open vSwitch (-like) flows into hardware. The data structures can be tweaked/reworked as needed. Signed-off-by: Simon Horman --- include/net/switchdev.h | 39 +++++++++++++++++++++++++++++++ net/switchdev/switchdev.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) diff --git a/include/net/switchdev.h b/include/net/switchdev.h index 729fe1534160..8eda96e46f98 100644 --- a/include/net/switchdev.h +++ b/include/net/switchdev.h @@ -71,6 +71,7 @@ enum switchdev_obj_id { SWITCHDEV_OBJ_ID_IPV4_FIB, SWITCHDEV_OBJ_ID_PORT_FDB, SWITCHDEV_OBJ_ID_PORT_MDB, + SWITCHDEV_OBJ_SW_FLOW, }; struct switchdev_obj { @@ -128,6 +129,19 @@ struct switchdev_obj_port_mdb { #define SWITCHDEV_OBJ_PORT_MDB(obj) \ container_of(obj, struct switchdev_obj_port_mdb, obj) +/* SWITCHDEV_OBJ_ID_PORT_SW_FLOW */ +struct switchdev_obj_sw_flow { + struct switchdev_obj obj; + const struct sw_flow_key *key; + const struct sw_flow_key *mask; + u64 attrs; + const struct nlattr *actions; + u32 actions_len; +}; + +#define SWITCHDEV_OBJ_SW_FLOW(obj) \ + container_of(obj, struct switchdev_obj_sw_flow, obj) + void switchdev_trans_item_enqueue(struct switchdev_trans *trans, void *data, void (*destructor)(void const *), struct switchdev_trans_item *tritem); @@ -223,6 +237,13 @@ int switchdev_port_fdb_del(struct ndmsg *ndm, struct nlattr *tb[], int switchdev_port_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb, struct net_device *dev, struct net_device *filter_dev, int *idx); +int switchdev_sw_flow_add(struct net_device *dev, + const struct sw_flow_key *key, + const struct sw_flow_key *mask, u64 attrs, + const struct nlattr *actions, u32 actions_len); +int switchdev_sw_flow_del(struct net_device *dev, + const struct sw_flow_key *key, + const struct sw_flow_key *mask, u64 attrs); void switchdev_port_fwd_mark_set(struct net_device *dev, struct net_device *group_dev, bool joining); @@ -347,6 +368,24 @@ static inline int switchdev_port_fdb_dump(struct sk_buff *skb, return *idx; } +static inline int switchdev_sw_flow_add(struct net_device *dev, + const struct sw_flow_key *key, + const struct sw_flow_key *mask, + u64 attrs, + const struct nlattr *actions, + u32 actions_len) +{ + return -EOPNOTSUPP; +} + +static inline int switchdev_sw_flow_del(struct net_device *dev, + const struct sw_flow_key *key, + const struct sw_flow_key *mask, + u64 attrs) +{ + return -EOPNOTSUPP; +} + static inline bool switchdev_port_same_parent_id(struct net_device *a, struct net_device *b) { diff --git a/net/switchdev/switchdev.c b/net/switchdev/switchdev.c index 10b819308439..db96c3345129 100644 --- a/net/switchdev/switchdev.c +++ b/net/switchdev/switchdev.c @@ -1286,6 +1286,64 @@ void switchdev_fib_ipv4_abort(struct fib_info *fi) } EXPORT_SYMBOL_GPL(switchdev_fib_ipv4_abort); +/** + * switchdev_sw_flow_add - Program a flow into a switch port + * + * @dev: port device + * @key: flow key + * @mask: flow mask + * @attrs: attributes present in key + * @actions: actions of the flow + * @actions_len: length of @actions + * + * Program a flow into a port device where the flow is expressed as + * an Open vSwitch flow key, mask, attributes, and actions + */ +int switchdev_sw_flow_add(struct net_device *dev, + const struct sw_flow_key *key, + const struct sw_flow_key *mask, + u64 attrs, const struct nlattr *actions, + u32 actions_len) +{ + struct switchdev_obj_sw_flow sw_flow = { + .obj.id = SWITCHDEV_OBJ_SW_FLOW, + .key = key, + .mask = mask, + .attrs = attrs, + .actions = actions, + .actions_len = actions_len, + }; + + return switchdev_port_obj_add(dev, &sw_flow.obj); +} +EXPORT_SYMBOL_GPL(switchdev_sw_flow_add); + +/** + * switchdev_sw_flow_del - Delete flow from switch + * + * @dev: port device + * @key: flow key + * @mask: flow mask + * @attrs: attributes present in key + * + * Delete a flow from a device where the flow is expressed as + * an Open vSwitch flow key, mask and attributes. + */ +int switchdev_sw_flow_del(struct net_device *dev, + const struct sw_flow_key *key, + const struct sw_flow_key *mask, u64 attrs) +{ + struct switchdev_obj_sw_flow sw_flow = { + .obj.id = SWITCHDEV_OBJ_SW_FLOW, + .key = key, + .mask = mask, + .attrs = attrs, + }; + + return switchdev_port_obj_del(dev, &sw_flow.obj); +} +EXPORT_SYMBOL_GPL(switchdev_sw_flow_del); + bool switchdev_port_same_parent_id(struct net_device *a, struct net_device *b) {