Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp1076126ybb; Sat, 28 Mar 2020 17:54:18 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuLu2MRHdK7725XA3kmxsxVVtLywUyeeaLEJ7IePfqK8cNnL6cm9+cbm1EIfrm1IdhOM4Ig X-Received: by 2002:aca:b756:: with SMTP id h83mr3776995oif.4.1585443258746; Sat, 28 Mar 2020 17:54:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585443258; cv=none; d=google.com; s=arc-20160816; b=dJ3O/1LL6BWQlRmoa5tEWLlQEPMCDZ5awA/lBJ9SRtmqox8hgSKdj8gHzi/sQOHbbE 37q/SV147/TQq424xGuWU+rrZhxwMuM7AJM1JAfEifqs73kTqX+WZGUjLqs89/AeI2hH WDh3iomB6+ezbLbryjl/UGBLxCzH7pryUaOQqGTXjP1aCe7fbl3GcvMo7TrYAipKG5PG Y6Nc+OSa0tHpBZPkI2O6w5EobUW3Zhvi4j5lxcLQqgSvc2vGEbrhm+WXm/7o5hOSrWLz YrQyYp5ZqlsC9N7ccv7suwAwOLtg5s2WS7vK2H85lE6L9xG7kzV3ItcymAu3OCb18teH E3FA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=37kWlgap5I+gvi/hMEL+pJlJvYSPzGhSsylXd5Sbnow=; b=jDqDIkc9qwdQuR5Lub0gXOXhLrwO6vFfIvgji6TvG0Bt5n+HRFvzAzaouuysTO89rx Rq3C9zbfy7wDIfIPRnE+BJ14F5c14FMf9CH/2n8GmZQSPG1T1UlMlRPYmOD7eGiOP+Zc nGsP6RxIT4Zow2+j1/y8Oh8rq7D0D3rbDrwtmXO9QqCGnFOqUWe+CeddmP6G7JODXhoC D5AvCxUocuS50QavxnygqHq2YVbwAJjyZbzGbYkoTCn1nhMKlG/iXOFVN89qKXz0pX2D d+H3hF6HkBXYz86eHuZeG9p3nH/nXqyPlHxbqexMBGxmzMPIy5wox9eHk+4G+g3tC1tn WEuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ErqSZhBA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r17si4498834otp.254.2020.03.28.17.54.05; Sat, 28 Mar 2020 17:54:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ErqSZhBA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727932AbgC2AxM (ORCPT + 99 others); Sat, 28 Mar 2020 20:53:12 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:55144 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727880AbgC2AxK (ORCPT ); Sat, 28 Mar 2020 20:53:10 -0400 Received: by mail-wm1-f67.google.com with SMTP id c81so15833958wmd.4; Sat, 28 Mar 2020 17:53:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=37kWlgap5I+gvi/hMEL+pJlJvYSPzGhSsylXd5Sbnow=; b=ErqSZhBA9K0vDbpaeVxrEPLHEq7sqtm6ewxAw+OqCkstKt6k0rjgGQDbmMSTvocHC/ CseDP+hCyFKp+1yWbrtzygUGZ9zJQ4ME/ig2J8spIdzfwKjJ7IBAsKWJFXSUskMjgfRN iP02jT9f25ifFdq3pJFjKA1LXclqGFBMqGjcVEQV5XDKrQCBwrsosPo0qPYO3Jz0rL0V puFU9hNSdKDjGBJalPLjVWDJH7Kd33IWez81wP54F+xPKZJXtky/tM+lJHEyxM2zOXp+ pQD2zCQgOA8O4zFZpWcne9fObNY5vyvML1tU7QK5mn4atDMaJS/e/M66/0TmNgvNsCTI WcVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=37kWlgap5I+gvi/hMEL+pJlJvYSPzGhSsylXd5Sbnow=; b=W0JdVGhooZ1PIU8tMu5vRMNocPa0k9h3tKF8+l0VD5IDYhYQOAmDa5EyqZWfXcFLf7 8j4fe8C29bkddXc4mbEyfhgrMirRtsBIdATcJuOatWfdv4QaUA0XlgR2/ugRQrjzs+MA aVg0+b97oeKS7M/IySwsCmsLww0jHscQsaBGvmP8xk1zb/aAyxPd9pWzlpLDXZOgQPID mMHew/BFXYvyLT2C+DAhNZPSBAOoFMEiYWv0mYuewaYay/WPDeyqQk/mkWScV4HaLd63 q9KuingQxpBl6CLo/K+0DDf8JX/IPB24u6ygeH6YNJXp0OgCWZXcNsD4l7CBIWRapxd3 zMkQ== X-Gm-Message-State: ANhLgQ2Pmk2CRCZlKs3jOeh07QLrWV+pcKAOW2ba8MplP/48PWcmzTky CH3oMyfDkcIStujQAWWk1c4= X-Received: by 2002:a1c:4c1a:: with SMTP id z26mr5933920wmf.94.1585443188397; Sat, 28 Mar 2020 17:53:08 -0700 (PDT) Received: from localhost.localdomain (5-12-96-237.residential.rdsnet.ro. [5.12.96.237]) by smtp.gmail.com with ESMTPSA id l1sm8292652wme.14.2020.03.28.17.53.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Mar 2020 17:53:07 -0700 (PDT) From: Vladimir Oltean To: andrew@lunn.ch, f.fainelli@gmail.com, vivien.didelot@gmail.com, davem@davemloft.net Cc: jiri@resnulli.us, idosch@idosch.org, kuba@kernel.org, netdev@vger.kernel.org, xiaoliang.yang_1@nxp.com, linux-kernel@vger.kernel.org, horatiu.vultur@microchip.com, alexandre.belloni@bootlin.com, allan.nielsen@microchip.com, joergen.andreasen@microchip.com, UNGLinuxDriver@microchip.com, yangbo.lu@nxp.com, alexandru.marginean@nxp.com, po.liu@nxp.com, claudiu.manoil@nxp.com, leoyang.li@nxp.com Subject: [PATCH net-next 5/6] net: dsa: sja1105: add configuration of port policers Date: Sun, 29 Mar 2020 02:52:01 +0200 Message-Id: <20200329005202.17926-6-olteanv@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200329005202.17926-1-olteanv@gmail.com> References: <20200329005202.17926-1-olteanv@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vladimir Oltean This adds partial configuration support for the L2 Policing Table. Out of the 45 policing entries, only 5 are used (one for each port), in a shared manner. All 8 traffic classes, and the broadcast policer, are redirected to a common instance which belongs to the ingress port. Signed-off-by: Vladimir Oltean --- drivers/net/dsa/sja1105/sja1105_main.c | 132 +++++++++++++++++++------ 1 file changed, 100 insertions(+), 32 deletions(-) diff --git a/drivers/net/dsa/sja1105/sja1105_main.c b/drivers/net/dsa/sja1105/sja1105_main.c index 763ae1d3bca8..81d2e5e5ce96 100644 --- a/drivers/net/dsa/sja1105/sja1105_main.c +++ b/drivers/net/dsa/sja1105/sja1105_main.c @@ -516,23 +516,56 @@ static int sja1105_init_avb_params(struct sja1105_private *priv) return 0; } +/* The L2 policing table is 2-stage. The table is looked up for each frame + * according to the ingress port, whether it was broadcast or not, and the + * classified traffic class (given by VLAN PCP). This portion of the lookup is + * fixed, and gives access to the SHARINDX, an indirection register pointing + * within the policing table itself, which is used to resolve the policer that + * will be used for this frame. + * + * Stage 1 Stage 2 + * +------------+--------+ +---------------------------------+ + * |Port 0 TC 0 |SHARINDX| | Policer 0: Rate, Burst, MTU | + * +------------+--------+ +---------------------------------+ + * |Port 0 TC 1 |SHARINDX| | Policer 1: Rate, Burst, MTU | + * +------------+--------+ +---------------------------------+ + * ... | Policer 2: Rate, Burst, MTU | + * +------------+--------+ +---------------------------------+ + * |Port 0 TC 7 |SHARINDX| | Policer 3: Rate, Burst, MTU | + * +------------+--------+ +---------------------------------+ + * |Port 1 TC 0 |SHARINDX| | Policer 4: Rate, Burst, MTU | + * +------------+--------+ +---------------------------------+ + * ... | Policer 5: Rate, Burst, MTU | + * +------------+--------+ +---------------------------------+ + * |Port 1 TC 7 |SHARINDX| | Policer 6: Rate, Burst, MTU | + * +------------+--------+ +---------------------------------+ + * ... | Policer 7: Rate, Burst, MTU | + * +------------+--------+ +---------------------------------+ + * |Port 4 TC 7 |SHARINDX| ... + * +------------+--------+ + * |Port 0 BCAST|SHARINDX| ... + * +------------+--------+ + * |Port 1 BCAST|SHARINDX| ... + * +------------+--------+ + * ... ... + * +------------+--------+ +---------------------------------+ + * |Port 4 BCAST|SHARINDX| | Policer 44: Rate, Burst, MTU | + * +------------+--------+ +---------------------------------+ + * + * In this driver, we shall use policers 0-4 as statically alocated port + * (matchall) policers. So we need to make the SHARINDX for all lookups + * corresponding to this ingress port (8 VLAN PCP lookups and 1 broadcast + * lookup) equal. + * The remaining policers (40) shall be dynamically allocated for flower + * policers, where the key is either vlan_prio or dst_mac ff:ff:ff:ff:ff:ff. + */ #define SJA1105_RATE_MBPS(speed) (((speed) * 64000) / 1000) -static void sja1105_setup_policer(struct sja1105_l2_policing_entry *policing, - int index, int mtu) -{ - policing[index].sharindx = index; - policing[index].smax = 65535; /* Burst size in bytes */ - policing[index].rate = SJA1105_RATE_MBPS(1000); - policing[index].maxlen = mtu; - policing[index].partition = 0; -} - static int sja1105_init_l2_policing(struct sja1105_private *priv) { struct sja1105_l2_policing_entry *policing; struct sja1105_table *table; - int i, j, k; + int port, tc; table = &priv->static_config.tables[BLK_IDX_L2_POLICING]; @@ -551,22 +584,29 @@ static int sja1105_init_l2_policing(struct sja1105_private *priv) policing = table->entries; - /* k sweeps through all unicast policers (0-39). - * bcast sweeps through policers 40-44. - */ - for (i = 0, k = 0; i < SJA1105_NUM_PORTS; i++) { - int bcast = (SJA1105_NUM_PORTS * SJA1105_NUM_TC) + i; + /* Setup shared indices for the matchall policers */ + for (port = 0; port < SJA1105_NUM_PORTS; port++) { + int bcast = (SJA1105_NUM_PORTS * SJA1105_NUM_TC) + port; + + for (tc = 0; tc < SJA1105_NUM_TC; tc++) + policing[port * SJA1105_NUM_TC + tc].sharindx = port; + + policing[bcast].sharindx = port; + } + + /* Setup the matchall policer parameters */ + for (port = 0; port < SJA1105_NUM_PORTS; port++) { int mtu = VLAN_ETH_FRAME_LEN + ETH_FCS_LEN; - if (dsa_is_cpu_port(priv->ds, i)) + if (dsa_is_cpu_port(priv->ds, port)) mtu += VLAN_HLEN; - for (j = 0; j < SJA1105_NUM_TC; j++, k++) - sja1105_setup_policer(policing, k, mtu); - - /* Set up this port's policer for broadcast traffic */ - sja1105_setup_policer(policing, bcast, mtu); + policing[port].smax = 65535; /* Burst size in bytes */ + policing[port].rate = SJA1105_RATE_MBPS(1000); + policing[port].maxlen = mtu; + policing[port].partition = 0; } + return 0; } @@ -2129,10 +2169,8 @@ static int sja1105_set_ageing_time(struct dsa_switch *ds, static int sja1105_change_mtu(struct dsa_switch *ds, int port, int new_mtu) { - int bcast = (SJA1105_NUM_PORTS * SJA1105_NUM_TC) + port; struct sja1105_l2_policing_entry *policing; struct sja1105_private *priv = ds->priv; - int tc; new_mtu += VLAN_ETH_HLEN + ETH_FCS_LEN; @@ -2141,16 +2179,10 @@ static int sja1105_change_mtu(struct dsa_switch *ds, int port, int new_mtu) policing = priv->static_config.tables[BLK_IDX_L2_POLICING].entries; - /* We set all 9 port policers to the same value, so just checking the - * broadcast one is fine. - */ - if (policing[bcast].maxlen == new_mtu) + if (policing[port].maxlen == new_mtu) return 0; - for (tc = 0; tc < SJA1105_NUM_TC; tc++) - policing[port * SJA1105_NUM_TC + tc].maxlen = new_mtu; - - policing[bcast].maxlen = new_mtu; + policing[port].maxlen = new_mtu; return sja1105_static_config_reload(priv, SJA1105_BEST_EFFORT_POLICING); } @@ -2250,6 +2282,40 @@ static void sja1105_mirror_del(struct dsa_switch *ds, int port, mirror->ingress, false); } +static int sja1105_port_policer_add(struct dsa_switch *ds, int port, + struct dsa_mall_policer_tc_entry *policer) +{ + struct sja1105_l2_policing_entry *policing; + struct sja1105_private *priv = ds->priv; + + policing = priv->static_config.tables[BLK_IDX_L2_POLICING].entries; + + /* In hardware, every 8 microseconds the credit level is incremented by + * the value of RATE bytes divided by 64, up to a maximum of SMAX + * bytes. + */ + policing[port].rate = div_u64(512 * policer->rate_bytes_per_sec, + 1000000); + policing[port].smax = div_u64(policer->rate_bytes_per_sec * + PSCHED_NS2TICKS(policer->burst), + PSCHED_TICKS_PER_SEC); + + return sja1105_static_config_reload(priv, SJA1105_BEST_EFFORT_POLICING); +} + +static void sja1105_port_policer_del(struct dsa_switch *ds, int port) +{ + struct sja1105_l2_policing_entry *policing; + struct sja1105_private *priv = ds->priv; + + policing = priv->static_config.tables[BLK_IDX_L2_POLICING].entries; + + policing[port].rate = SJA1105_RATE_MBPS(1000); + policing[port].smax = 65535; + + sja1105_static_config_reload(priv, SJA1105_BEST_EFFORT_POLICING); +} + static const struct dsa_switch_ops sja1105_switch_ops = { .get_tag_protocol = sja1105_get_tag_protocol, .setup = sja1105_setup, @@ -2288,6 +2354,8 @@ static const struct dsa_switch_ops sja1105_switch_ops = { .port_setup_tc = sja1105_port_setup_tc, .port_mirror_add = sja1105_mirror_add, .port_mirror_del = sja1105_mirror_del, + .port_policer_add = sja1105_port_policer_add, + .port_policer_del = sja1105_port_policer_del, }; static int sja1105_check_device_id(struct sja1105_private *priv) -- 2.17.1