Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp65494pxb; Thu, 30 Sep 2021 00:56:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxWpQm+BDFoMMy+CI+cAMoHpJ/81kKAcR4oURtNGn1qNGKfOsrHfI/YCnGpdKsf8tZ6KJZh X-Received: by 2002:a05:6402:1291:: with SMTP id w17mr5344058edv.29.1632988574321; Thu, 30 Sep 2021 00:56:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632988574; cv=none; d=google.com; s=arc-20160816; b=mHRG7gMkP6GFSDvF79pN/9yla10EM5wX0oiuSo+z+rYfyYW99P8/bES1izAE6nrS0Q 3Tie5d5BcINNPhRbkXKne0oONuzTnbpCRd94C159k5bTKL54H8nPO3tlF75lVJmzFbYd 0IblY7H/Yd4iDcbQJacLandZ5L/emG9pmFCYQr47BQKOOEMP6dJ/ENfHEcLqmRad7cMV Gc1nWlZySoPeLRRrw7dlZiz50XyPA4K/ybhpNnuasjLAdCZCfy/wjq5OXZ//1yDUfok/ fgf8+ANa0WbdkwVGwD+B4GE5qq3JNTlrPpIgz32+VwgxkrpWO4BhXNWz3H3P0mxiFrJh 509A== 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=KMMu5X2MTOqKFuiAzYp6zYwceLBKtoVG/ougJ+0A+fc=; b=WCctnc+3crWd1n+exR+JtFs0xl3f6r/NxLZRRn05k9+bQecA+MKzM3uSit16lxBvjo UY3s2evsspfONNHnNhnj2waRXG8sBjgeuaV2h0lo+HAxcxq6gir6i/1GDzu0vwW61JOH LDya77/L04MXHKHYscIo7zSK3Ujcqp74WaAjyTOuuPPjlpASsagCwEaYg88ulWWsoQ+y UAjAE5CuivrKMg7ordp7mS+jgdCUqdJ0If7duqz0BOa30NeQOGdcyvjKhTk8V7XL+Jmi C4kSFqLNeo/1SqcX0uHNZP4WCxVPXUTmVWK7gQIoVxDv5nBl2P8+OhowcTH/tdYDpkue pmvg== 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 w18si2459390edu.157.2021.09.30.00.55.50; Thu, 30 Sep 2021 00:56:14 -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 S1348896AbhI3HwU (ORCPT + 99 others); Thu, 30 Sep 2021 03:52:20 -0400 Received: from inva021.nxp.com ([92.121.34.21]:37504 "EHLO inva021.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348923AbhI3HwM (ORCPT ); Thu, 30 Sep 2021 03:52:12 -0400 Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 920832017C0; Thu, 30 Sep 2021 09:50:29 +0200 (CEST) Received: from aprdc01srsp001v.ap-rdc01.nxp.com (aprdc01srsp001v.ap-rdc01.nxp.com [165.114.16.16]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 20696200408; Thu, 30 Sep 2021 09:50:29 +0200 (CEST) Received: from localhost.localdomain (mega.ap.freescale.net [10.192.208.232]) by aprdc01srsp001v.ap-rdc01.nxp.com (Postfix) with ESMTP id 5D3FC183AC94; Thu, 30 Sep 2021 15:50:26 +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, linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org, matthias.bgg@gmail.com, horatiu.vultur@microchip.com Subject: [PATCH v6 net-next 8/8] net: dsa: felix: use vcap policer to set flow meter for psfp Date: Thu, 30 Sep 2021 15:59:48 +0800 Message-Id: <20210930075948.36981-9-xiaoliang.yang_1@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210930075948.36981-1-xiaoliang.yang_1@nxp.com> References: <20210930075948.36981-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 2856df471cf2..1699d8cd8366 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 @@ -1849,7 +1850,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; @@ -1868,13 +1872,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; } @@ -1911,6 +1935,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; } @@ -1934,6 +1961,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