Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp336506ybi; Fri, 24 May 2019 04:42:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqw+gU9nzYa8QpTCfoOvk/pCALIoRR7SSpmofVZGsuuRX99rfJ/lHbn83sYULufsFmIstXpg X-Received: by 2002:a63:24c1:: with SMTP id k184mr18342029pgk.120.1558698152756; Fri, 24 May 2019 04:42:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558698152; cv=none; d=google.com; s=arc-20160816; b=seJzwGkDxUl0H16v0wdV14OA2jEMlt7zpu/HdoUVnrafYtuEj8OuEdIJP4X0iVIdDa LtmGhmBylCkHsfW5OtgByARgOlDwp3oFvFObZ78J/ld41pdtJAnmZ8DMn8uBZe4kyCF0 vDoB7tzzQ1GkZqtjE9hET+GLNe90fifztTM7N4N7waFuSANB5m8nJw2zga/C0pPDr4Vf 3/ShBnifb5QsCucrX8++wfEYmFz949IL96rfauSbocs/EVe2y3P9wf42vDuRkz2bqHLk UsJGjdsAoaj3+XwQ2t1A1b94/tVaXhNUJcsKJ8po8REap88AXtdnDrrCcrU8VOmUgZ/G VlCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=Yi5PaBnf1txc83HouNkzvLxpX5WxrtUj07CerLQA7Us=; b=k9aR4igwbN0gCRTbSjGBdi+cAV/5fCh4kpimNVn3PKtcypGzoBhMV9cTkyOE4Opz/7 f1cJX+FAS/Q461kIvPw0wHP41+FiEzCSzRPdCeaYivRg6IeEUkMTMb0Vbp4hi6cY9JQD dRSC0nVndkBy4bJ8+DkrL8XKYNXgHxTJYEnYxT0qvK3yHgbwVlQJULf8KtmhgHAMnWv2 39iGICRdoGSYw9VSy2JGMCGKgP0UlRqID+RTi9HAGyLoFrrSBqgM5K5TqCKUcfbJYu1V hkoJ07kq3/AZj8QrgnVw/soOcpnwU4lH8w0NsWrPP5A5S5FNQKGQCL/mqRsFhd8EXxTX 2R/A== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=microchip.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j1si3718477pfa.164.2019.05.24.04.42.18; Fri, 24 May 2019 04:42:32 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=microchip.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391216AbfEXLkz (ORCPT + 99 others); Fri, 24 May 2019 07:40:55 -0400 Received: from esa4.microchip.iphmx.com ([68.232.154.123]:53618 "EHLO esa4.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390743AbfEXLky (ORCPT ); Fri, 24 May 2019 07:40:54 -0400 Received-SPF: Pass (esa4.microchip.iphmx.com: domain of Joergen.Andreasen@microchip.com designates 198.175.253.82 as permitted sender) identity=mailfrom; client-ip=198.175.253.82; receiver=esa4.microchip.iphmx.com; envelope-from="Joergen.Andreasen@microchip.com"; x-sender="Joergen.Andreasen@microchip.com"; x-conformance=spf_only; x-record-type="v=spf1"; x-record-text="v=spf1 mx a:ushub1.microchip.com a:smtpout.microchip.com a:mx1.microchip.iphmx.com a:mx2.microchip.iphmx.com include:servers.mcsv.net include:mktomail.com include:spf.protection.outlook.com ~all" Received-SPF: None (esa4.microchip.iphmx.com: no sender authenticity information available from domain of postmaster@email.microchip.com) identity=helo; client-ip=198.175.253.82; receiver=esa4.microchip.iphmx.com; envelope-from="Joergen.Andreasen@microchip.com"; x-sender="postmaster@email.microchip.com"; x-conformance=spf_only Authentication-Results: esa4.microchip.iphmx.com; dkim=none (message not signed) header.i=none; spf=Pass smtp.mailfrom=Joergen.Andreasen@microchip.com; spf=None smtp.helo=postmaster@email.microchip.com; dmarc=pass (p=none dis=none) d=microchip.com X-IronPort-AV: E=Sophos;i="5.60,506,1549954800"; d="scan'208";a="34319525" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa4.microchip.iphmx.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 24 May 2019 04:40:53 -0700 Received: from localhost (10.10.76.4) by chn-sv-exch02.mchp-main.com (10.10.76.38) with Microsoft SMTP Server id 14.3.352.0; Fri, 24 May 2019 04:40:53 -0700 Date: Fri, 24 May 2019 13:40:52 +0200 From: Joergen Andreasen To: Jakub Kicinski CC: , Microchip Linux Driver Support , Alexandre Belloni , "David S. Miller" , Subject: Re: [PATCH net-next v2 1/1] net: mscc: ocelot: Implement port policers via tc command Message-ID: <20190524114050.rznhisqcgdm5c2e6@soft-dev16> References: <20190502094029.22526-1-joergen.andreasen@microchip.com> <20190523104939.2721-1-joergen.andreasen@microchip.com> <20190523104939.2721-2-joergen.andreasen@microchip.com> <20190523115630.7710cc49@cakuba.netronome.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Disposition: inline In-Reply-To: <20190523115630.7710cc49@cakuba.netronome.com> User-Agent: NeoMutt/20171215 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jakub, The 05/23/2019 11:56, Jakub Kicinski wrote: > External E-Mail > > > On Thu, 23 May 2019 12:49:39 +0200, Joergen Andreasen wrote: > > Hardware offload of matchall classifier and police action are now > > supported via the tc command. > > Supported police parameters are: rate and burst. > > > > Example: > > > > Add: > > tc qdisc add dev eth3 handle ffff: ingress > > tc filter add dev eth3 parent ffff: prio 1 handle 2 \ > > matchall skip_sw \ > > action police rate 100Mbit burst 10000 > > > > Show: > > tc -s -d qdisc show dev eth3 > > tc -s -d filter show dev eth3 ingress > > > > Delete: > > tc filter del dev eth3 parent ffff: prio 1 > > tc qdisc del dev eth3 handle ffff: ingress > > > > Signed-off-by: Joergen Andreasen > > > diff --git a/drivers/net/ethernet/mscc/ocelot.c b/drivers/net/ethernet/mscc/ocelot.c > > index d715ef4fc92f..3ec7864d9dc8 100644 > > --- a/drivers/net/ethernet/mscc/ocelot.c > > +++ b/drivers/net/ethernet/mscc/ocelot.c > > @@ -943,6 +943,7 @@ static const struct net_device_ops ocelot_port_netdev_ops = { > > .ndo_vlan_rx_kill_vid = ocelot_vlan_rx_kill_vid, > > .ndo_set_features = ocelot_set_features, > > .ndo_get_port_parent_id = ocelot_get_port_parent_id, > > + .ndo_setup_tc = ocelot_setup_tc, > > }; > > > > static void ocelot_get_strings(struct net_device *netdev, u32 sset, u8 *data) > > @@ -1663,8 +1664,9 @@ int ocelot_probe_port(struct ocelot *ocelot, u8 port, > > dev->netdev_ops = &ocelot_port_netdev_ops; > > dev->ethtool_ops = &ocelot_ethtool_ops; > > > > - dev->hw_features |= NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_RXFCS; > > - dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER; > > + dev->hw_features |= NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_RXFCS | > > + NETIF_F_HW_TC; > > + dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_HW_TC; > > > > memcpy(dev->dev_addr, ocelot->base_mac, ETH_ALEN); > > dev->dev_addr[ETH_ALEN - 1] += port; > > You need to add a check in set_features to make sure nobody clears the > NETIF_F_TC flag while something is offloaded, otherwise you will miss > the REMOVE callback (it will bounce from the > tc_cls_can_offload_and_chain0() check). I will add this check in v3 > > > diff --git a/drivers/net/ethernet/mscc/ocelot_tc.c b/drivers/net/ethernet/mscc/ocelot_tc.c > > new file mode 100644 > > index 000000000000..2412e0dbc267 > > --- /dev/null > > +++ b/drivers/net/ethernet/mscc/ocelot_tc.c > > @@ -0,0 +1,164 @@ > > +// SPDX-License-Identifier: (GPL-2.0 OR MIT) > > +/* Microsemi Ocelot Switch TC driver > > + * > > + * Copyright (c) 2019 Microsemi Corporation > > + */ > > + > > +#include "ocelot_tc.h" > > +#include "ocelot_police.h" > > +#include > > + > > +static int ocelot_setup_tc_cls_matchall(struct ocelot_port *port, > > + struct tc_cls_matchall_offload *f, > > + bool ingress) > > +{ > > + struct netlink_ext_ack *extack = f->common.extack; > > + struct ocelot_policer pol = { 0 }; > > + struct flow_action_entry *action; > > + int err; > > + > > + netdev_dbg(port->dev, "%s: port %u command %d cookie %lu\n", > > + __func__, port->chip_port, f->command, f->cookie); > > + > > + if (!ingress) { > > + NL_SET_ERR_MSG_MOD(extack, "Only ingress is supported"); > > + return -EOPNOTSUPP; > > + } > > + > > + switch (f->command) { > > + case TC_CLSMATCHALL_REPLACE: > > + if (!flow_offload_has_one_action(&f->rule->action)) { > > + NL_SET_ERR_MSG_MOD(extack, > > + "Only one action is supported"); > > + return -EOPNOTSUPP; > > + } > > + > > + action = &f->rule->action.entries[0]; > > + > > + if (action->id != FLOW_ACTION_POLICE) { > > + NL_SET_ERR_MSG_MOD(extack, "Unsupported action"); > > + return -EOPNOTSUPP; > > + } > > Please also reject the offload if block is shared, as HW policer state > cannot be shared between ports, the way it is in SW. You have to save > whether the block is shared or not at bind time, see: > > d6787147e15d ("net/sched: remove block pointer from common offload structure") I will fix this in v3. > > > + if (port->tc.police_id && port->tc.police_id != f->cookie) { > > + NL_SET_ERR_MSG_MOD(extack, > > + "Only one policer per port is supported\n"); > > + return -EEXIST; > > + } > > + > > + pol.rate = (u32)div_u64(action->police.rate_bytes_ps, 1000) * 8; > > + pol.burst = (u32)div_u64(action->police.rate_bytes_ps * > > + PSCHED_NS2TICKS(action->police.burst), > > + PSCHED_TICKS_PER_SEC); > > + > > + err = ocelot_port_policer_add(port, &pol); > > + if (err) { > > + NL_SET_ERR_MSG_MOD(extack, "Could not add policer\n"); > > + return err; > > + } > > + > > + port->tc.police_id = f->cookie; > > + return 0; > > + case TC_CLSMATCHALL_DESTROY: > > + if (port->tc.police_id != f->cookie) > > + return -ENOENT; > > + > > + err = ocelot_port_policer_del(port); > > + if (err) { > > + NL_SET_ERR_MSG_MOD(extack, > > + "Could not delete policer\n"); > > + return err; > > + } > > + port->tc.police_id = 0; > > + return 0; > > + case TC_CLSMATCHALL_STATS: /* fall through */ > > + default: > > + return -EOPNOTSUPP; > > + } > > +} > -- Joergen Andreasen, Microchip