Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp2391754rwb; Fri, 20 Jan 2023 02:14:45 -0800 (PST) X-Google-Smtp-Source: AMrXdXsIUhDQelWGJi9bvFN5VvW1bxhqaCwtd1fstPQravvz5uDgnXoBW8ekro3FyqeAV3Suuuug X-Received: by 2002:a17:902:9a97:b0:194:810a:d6ab with SMTP id w23-20020a1709029a9700b00194810ad6abmr14406258plp.20.1674209684966; Fri, 20 Jan 2023 02:14:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674209684; cv=none; d=google.com; s=arc-20160816; b=RoFBluhP2RuIkGcCubBtJn+D9P+RGkF2cKDqyKYAgIvpn/s/uylyOJD5CqRR2435CN k5vPnxdri3FPQlsUFs5sf2OHUjU9Epv/lp3tgPQKM/L7mBR9xJ10Zfum8tvLCcZEivT6 t3Yq3AruxF+JzUwVXJtHDL7cKpJm1Pd3Vj7ryxXZ9W7UdeDCA38yEHQTPj90W4yu+inQ 4NoDhnpOgPlneMh0pLsP9F3qO+Sf2ECLab/w9oFn4Goae3iShNXEwtzp2NXpMKlJ8aay Bt+4k4t+xkqzEV1yxSHcv7G5cuZCwRF/IvxaBLaB7Sd2RDRjq+PM8SXE/N+aEGz9gWP2 DQyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fFSwDuS1LkHYcGgUemEC6qcR/6WJABm50dvYB41h/2w=; b=dhVcbixOKY1Fvxg3z+nTcCHd+PbG2DAN1rTrOoe/jGVBd9LFRkYb3mLa693zz/K6W7 o9infbcqTE1Ekdn+NGXCEMzbd5Xiod1iAMnuwZmAfCqDW2LSIZnpUHmGW8q8gf2rBMTw mQ1j8M1yTWE/M/EDB45MJhssvDErs3I920Ef2fR3dfbTg1qCH4A37jDScmiJ34IaUxkC xvX3oUYWcfSstqHQnBFckAIbxwLt33fZxR2O+RRQCzPS5jgeoMxYSH/wDTZ9kGUWyne+ +mVXYMw5lh2czUWI3H8723MZrZRZhujhkJ2u9YlYc2efqF3x7diuGcFNC6C6CTV36OTy lKiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=1af+OIO4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z6-20020a170902708600b001842f465c10si39885453plk.438.2023.01.20.02.14.39; Fri, 20 Jan 2023 02:14:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=1af+OIO4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229470AbjATJJm (ORCPT + 48 others); Fri, 20 Jan 2023 04:09:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229862AbjATJJd (ORCPT ); Fri, 20 Jan 2023 04:09:33 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0208F8EFFC; Fri, 20 Jan 2023 01:09:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1674205750; x=1705741750; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9zlLmSDXoYd6qfZxPLgWyALhkhhsOhqKQZMXdD30sgc=; b=1af+OIO4/NK2e/rO6ekqDzsFFaZmbUOgObgL09FtHYHHcY8q+b0IOyg4 xd7q7fXyGsDmaUuVGtfIUktqV7ntU7ZXnr/Y9pHBPpj9vjSWDkThIAtCp k3hXs1HV89Bc/42NqWl0E4ga/GgV7cJy0wwXulkMm8xwUJV39EbiQKmzo lbLAaxl1WJdjmVAwVY+I6F9DIdzw5XH2CIE2mRuNyxHBA0we1t3A4maUa 1gaq7yPvM2zRnEbddOz/+45mGyvbO95eewcWRF1m6AXcNkoqHuhwXKpUS WrE/rb2uE2qaECDJg4lRot/obxsdCFi9qWTOoVBWcnVgt8xHQcj2JlL78 Q==; X-IronPort-AV: E=Sophos;i="5.97,231,1669100400"; d="scan'208";a="193122587" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa4.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 20 Jan 2023 02:09:08 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Fri, 20 Jan 2023 02:09:02 -0700 Received: from den-dk-m31857.microchip.com (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2507.16 via Frontend Transport; Fri, 20 Jan 2023 02:08:59 -0700 From: Steen Hegelund To: "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni CC: Steen Hegelund , , Randy Dunlap , "Casper Andersson" , Russell King , Wan Jiabing , "Nathan Huckleberry" , , , , "Steen Hegelund" , Daniel Machon , Horatiu Vultur , Lars Povlsen , Dan Carpenter , Michael Walle Subject: [PATCH net-next 6/8] net: microchip: sparx5: Add automatic selection of VCAP rule actionset Date: Fri, 20 Jan 2023 10:08:29 +0100 Message-ID: <20230120090831.20032-7-steen.hegelund@microchip.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230120090831.20032-1-steen.hegelund@microchip.com> References: <20230120090831.20032-1-steen.hegelund@microchip.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With more than one possible actionset in a VCAP instance, the VCAP API will now use the actions in a VCAP rule to select the actionset that fits these actions the best possible way. Signed-off-by: Steen Hegelund --- .../microchip/sparx5/sparx5_tc_flower.c | 5 - .../net/ethernet/microchip/vcap/vcap_api.c | 107 +++++++++++++++++- .../net/ethernet/microchip/vcap/vcap_api.h | 7 ++ 3 files changed, 109 insertions(+), 10 deletions(-) diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_tc_flower.c b/drivers/net/ethernet/microchip/sparx5/sparx5_tc_flower.c index 54c79c316dd5..3875b5bc984f 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_tc_flower.c +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_tc_flower.c @@ -991,11 +991,6 @@ static int sparx5_tc_flower_replace(struct net_device *ndev, SPX5_PMM_REPLACE_ALL); if (err) goto out; - /* For now the actionset is hardcoded */ - err = vcap_set_rule_set_actionset(vrule, - VCAP_AFS_BASE_TYPE); - if (err) - goto out; break; case FLOW_ACTION_ACCEPT: err = sparx5_tc_set_actionset(admin, vrule); diff --git a/drivers/net/ethernet/microchip/vcap/vcap_api.c b/drivers/net/ethernet/microchip/vcap/vcap_api.c index e7152cf91680..71da20ff22b7 100644 --- a/drivers/net/ethernet/microchip/vcap/vcap_api.c +++ b/drivers/net/ethernet/microchip/vcap/vcap_api.c @@ -1759,6 +1759,22 @@ bool vcap_keyset_list_add(struct vcap_keyset_list *keysetlist, } EXPORT_SYMBOL_GPL(vcap_keyset_list_add); +/* Add a actionset to a actionset list */ +static bool vcap_actionset_list_add(struct vcap_actionset_list *actionsetlist, + enum vcap_actionfield_set actionset) +{ + int idx; + + if (actionsetlist->cnt < actionsetlist->max) { + /* Avoid duplicates */ + for (idx = 0; idx < actionsetlist->cnt; ++idx) + if (actionsetlist->actionsets[idx] == actionset) + return actionsetlist->cnt < actionsetlist->max; + actionsetlist->actionsets[actionsetlist->cnt++] = actionset; + } + return actionsetlist->cnt < actionsetlist->max; +} + /* map keyset id to a string with the keyset name */ const char *vcap_keyset_name(struct vcap_control *vctrl, enum vcap_keyfield_set keyset) @@ -1867,6 +1883,75 @@ bool vcap_rule_find_keysets(struct vcap_rule *rule, } EXPORT_SYMBOL_GPL(vcap_rule_find_keysets); +/* Return the actionfield that matches a action in a actionset */ +static const struct vcap_field * +vcap_find_actionset_actionfield(struct vcap_control *vctrl, + enum vcap_type vtype, + enum vcap_actionfield_set actionset, + enum vcap_action_field action) +{ + const struct vcap_field *fields; + int idx, count; + + fields = vcap_actionfields(vctrl, vtype, actionset); + if (!fields) + return NULL; + + /* Iterate the actionfields of the actionset */ + count = vcap_actionfield_count(vctrl, vtype, actionset); + for (idx = 0; idx < count; ++idx) { + if (fields[idx].width == 0) + continue; + + if (action == idx) + return &fields[idx]; + } + + return NULL; +} + +/* Match a list of actions against the actionsets available in a vcap type */ +static bool vcap_rule_find_actionsets(struct vcap_rule_internal *ri, + struct vcap_actionset_list *matches) +{ + int actionset, found, actioncount, map_size; + const struct vcap_client_actionfield *ckf; + const struct vcap_field **map; + enum vcap_type vtype; + + vtype = ri->admin->vtype; + map = ri->vctrl->vcaps[vtype].actionfield_set_map; + map_size = ri->vctrl->vcaps[vtype].actionfield_set_size; + + /* Get a count of the actionfields we want to match */ + actioncount = 0; + list_for_each_entry(ckf, &ri->data.actionfields, ctrl.list) + ++actioncount; + + matches->cnt = 0; + /* Iterate the actionsets of the VCAP */ + for (actionset = 0; actionset < map_size; ++actionset) { + if (!map[actionset]) + continue; + + /* Iterate the actions in the rule */ + found = 0; + list_for_each_entry(ckf, &ri->data.actionfields, ctrl.list) + if (vcap_find_actionset_actionfield(ri->vctrl, vtype, + actionset, + ckf->ctrl.action)) + ++found; + + /* Save the actionset if all actionfields were found */ + if (found == actioncount) + if (!vcap_actionset_list_add(matches, actionset)) + /* bail out when the quota is filled */ + break; + } + + return matches->cnt > 0; +} + /* Validate a rule with respect to available port keys */ int vcap_val_rule(struct vcap_rule *rule, u16 l3_proto) { @@ -1918,11 +2003,23 @@ int vcap_val_rule(struct vcap_rule *rule, u16 l3_proto) return ret; } if (ri->data.actionset == VCAP_AFS_NO_VALUE) { - /* Later also actionsets will be matched against actions in - * the rule, and the type will be set accordingly - */ - ri->data.exterr = VCAP_ERR_NO_ACTIONSET_MATCH; - return -EINVAL; + struct vcap_actionset_list matches = {}; + enum vcap_actionfield_set actionsets[10]; + + matches.actionsets = actionsets; + matches.max = ARRAY_SIZE(actionsets); + + /* Find an actionset that fits the rule actions */ + if (!vcap_rule_find_actionsets(ri, &matches)) { + ri->data.exterr = VCAP_ERR_NO_ACTIONSET_MATCH; + return -EINVAL; + } + ret = vcap_set_rule_set_actionset(rule, actionsets[0]); + if (ret < 0) { + pr_err("%s:%d: actionset was not updated: %d\n", + __func__, __LINE__, ret); + return ret; + } } vcap_add_type_keyfield(rule); vcap_add_type_actionfield(rule); diff --git a/drivers/net/ethernet/microchip/vcap/vcap_api.h b/drivers/net/ethernet/microchip/vcap/vcap_api.h index c61f13a65030..40491116b0a9 100644 --- a/drivers/net/ethernet/microchip/vcap/vcap_api.h +++ b/drivers/net/ethernet/microchip/vcap/vcap_api.h @@ -201,6 +201,13 @@ struct vcap_keyset_list { enum vcap_keyfield_set *keysets; /* the list of keysets */ }; +/* List of actionsets */ +struct vcap_actionset_list { + int max; /* size of the actionset list */ + int cnt; /* count of actionsets actually in the list */ + enum vcap_actionfield_set *actionsets; /* the list of actionsets */ +}; + /* Client output printf-like function with destination */ struct vcap_output_print { __printf(2, 3) -- 2.39.1