Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp3606587pxb; Tue, 7 Sep 2021 03:35:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyhl5qNIbFkrgWwXoqHC9g8qqsgmG86Rh0qKrOV0Xy/8crLiTUyeYHMUHJjWLXZKdWLs0fN X-Received: by 2002:a92:190b:: with SMTP id 11mr11142001ilz.303.1631010948744; Tue, 07 Sep 2021 03:35:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631010948; cv=none; d=google.com; s=arc-20160816; b=uGhi7QoKkuPJ6yP/7hZZULO7CP9tiQgC9vLFmQLj6b3dduKnaogpOEbtplBd/PT6LP TmNAANXnEW7yzS7Se3VGbjNHHQrS6R8NCK9q3dzjRGpBb8/7wvNCjfhiZZI04Z3JPdD0 uAjX1oyZ0qYCHAfN/9iwwlRkma5JFvq64etLco9IeI1tYVfsiM0pDmLIZ6S5vRpnnOM0 osQ4weSEh3WJGbu/1lmT378zqa/eM2wMx15Y5OrJF0fH33Z+Hinwnk5wjhvUbrl07l5U rRJxjqc94PO7i3cP/6ZMitZxrNT8O/dkZlSfVe1GDhrNjclxINHse/qu5yJsHUVn0tLs OAVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=LdmIJy9lxllcNOPBh9cp5RRnSXt003/cUddWzui6oG0=; b=fLU60hguglbnm7C72U7FbZEkc4oTflCIqndJWBNlZyrSUUsKlXVJa4bRrn9yAVARsp UdepgSjcTtV/dgxEzff+J/texvy6pOOQVP24prw5qRbZgCPqxnuCKMJ3Ej3f75WTBU+V yeL0ehzU10IvvFaSNlxjAMQEEzwu1mPuY39L7X6QsfEDzOrrKS6C8W2nIfFwHnVnNPLv c20lj+JM9JpBR+Ksal9i2d2T/pJUATNzIU7LilMZvilLvWf63XGyrNOzu4C/ziu5I27B MnkrIWdQihGgKWRiaRFDK8c49kl03NNFeb7E3pTaWeYqNfd0v8YcNmuKLG3TvrlWFnAI pplg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f18si9247334iox.32.2021.09.07.03.35.37; Tue, 07 Sep 2021 03:35:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244880AbhIGJAw (ORCPT + 99 others); Tue, 7 Sep 2021 05:00:52 -0400 Received: from inva020.nxp.com ([92.121.34.13]:59842 "EHLO inva020.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244961AbhIGJAV (ORCPT ); Tue, 7 Sep 2021 05:00:21 -0400 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id B08E31A2AB0; Tue, 7 Sep 2021 10:59:14 +0200 (CEST) Received: from aprdc01srsp001v.ap-rdc01.nxp.com (aprdc01srsp001v.ap-rdc01.nxp.com [165.114.16.16]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 4CC5E1A13F6; Tue, 7 Sep 2021 10:59:14 +0200 (CEST) Received: from localhost.localdomain (mega.ap.freescale.net [10.192.208.232]) by aprdc01srsp001v.ap-rdc01.nxp.com (Postfix) with ESMTP id DD1A4183AC4C; Tue, 7 Sep 2021 16:59:11 +0800 (+08) From: Xiaoliang Yang To: davem@davemloft.net, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Cc: allan.nielsen@microchip.com, joergen.andreasen@microchip.com, UNGLinuxDriver@microchip.com, vinicius.gomes@intel.com, michael.chan@broadcom.com, vishal@chelsio.com, saeedm@mellanox.com, jiri@mellanox.com, idosch@mellanox.com, alexandre.belloni@bootlin.com, kuba@kernel.org, xiaoliang.yang_1@nxp.com, po.liu@nxp.com, vladimir.oltean@nxp.com, leoyang.li@nxp.com, f.fainelli@gmail.com, andrew@lunn.ch, vivien.didelot@gmail.com, claudiu.manoil@nxp.com Subject: [PATCH v4 net-next 8/8] net: dsa: felix: use vcap policer to set flow meter for psfp Date: Tue, 7 Sep 2021 17:09:15 +0800 Message-Id: <20210907090915.17866-9-xiaoliang.yang_1@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210907090915.17866-1-xiaoliang.yang_1@nxp.com> References: <20210907090915.17866-1-xiaoliang.yang_1@nxp.com> X-Virus-Scanned: ClamAV using ClamSMTP Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch add police action to set flow meter table which is defined in IEEE802.1Qci. Flow metering is two rates two buckets and three color marker to policing the frames, we only enable one rate one bucket in this patch. Flow metering shares a same policer pool with VCAP policers, so the PSFP policer calls ocelot_vcap_policer_add() and ocelot_vcap_policer_del() to set flow meter police. Signed-off-by: Xiaoliang Yang --- drivers/net/dsa/ocelot/felix_vsc9959.c | 32 +++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/drivers/net/dsa/ocelot/felix_vsc9959.c b/drivers/net/dsa/ocelot/felix_vsc9959.c index 1418d2a66bd6..1118101d0ee8 100644 --- a/drivers/net/dsa/ocelot/felix_vsc9959.c +++ b/drivers/net/dsa/ocelot/felix_vsc9959.c @@ -1343,6 +1343,7 @@ static int vsc9959_port_setup_tc(struct dsa_switch *ds, int port, #define VSC9959_PSFP_SFID_MAX 175 #define VSC9959_PSFP_GATE_ID_MAX 183 +#define VSC9959_PSFP_POLICER_BASE 63 #define VSC9959_PSFP_POLICER_MAX 383 #define VSC9959_PSFP_GATE_LIST_NUM 4 #define VSC9959_PSFP_GATE_CYCLETIME_MIN 5000 @@ -1854,7 +1855,10 @@ static int vsc9959_psfp_filter_add(struct ocelot *ocelot, struct felix_stream stream = {0}; struct felix_stream_gate *sgi; struct ocelot_psfp_list *psfp; + struct ocelot_policer pol; int ret, i, size; + u64 rate, burst; + u32 index; psfp = &ocelot->psfp; @@ -1873,13 +1877,33 @@ static int vsc9959_psfp_filter_add(struct ocelot *ocelot, ret = vsc9959_psfp_sgi_table_add(ocelot, sgi); if (ret) { kfree(sgi); - return ret; + goto err; } sfi.sg_valid = 1; sfi.sgid = sgi->index; kfree(sgi); break; case FLOW_ACTION_POLICE: + index = a->police.index + VSC9959_PSFP_POLICER_BASE; + if (index > VSC9959_PSFP_POLICER_MAX) { + ret = -EINVAL; + goto err; + } + + rate = a->police.rate_bytes_ps; + burst = rate * PSCHED_NS2TICKS(a->police.burst); + pol = (struct ocelot_policer) { + .burst = div_u64(burst, PSCHED_TICKS_PER_SEC), + .rate = div_u64(rate, 1000) * 8, + }; + ret = ocelot_vcap_policer_add(ocelot, index, &pol); + if (ret) + goto err; + + sfi.fm_valid = 1; + sfi.fmid = index; + sfi.maxsdu = a->police.mtu; + break; default: return -EOPNOTSUPP; } @@ -1916,6 +1940,9 @@ static int vsc9959_psfp_filter_add(struct ocelot *ocelot, if (sfi.sg_valid) vsc9959_psfp_sgi_table_del(ocelot, sfi.sgid); + if (sfi.fm_valid) + ocelot_vcap_policer_del(ocelot, sfi.fmid); + return ret; } @@ -1939,6 +1966,9 @@ static int vsc9959_psfp_filter_del(struct ocelot *ocelot, if (sfi->sg_valid) vsc9959_psfp_sgi_table_del(ocelot, sfi->sgid); + if (sfi->fm_valid) + ocelot_vcap_policer_del(ocelot, sfi->fmid); + vsc9959_psfp_sfi_table_del(ocelot, stream->sfid); stream->sfid_valid = 0; -- 2.17.1