Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp415462yba; Fri, 3 May 2019 04:25:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqx0jQ5UZsieGT6Iy+vt5eh4YkLecCdx0HTZvIsHEdb04ZnrtRnaMiSgyjmG+M2xRNtHfUNZ X-Received: by 2002:aa7:9285:: with SMTP id j5mr9999402pfa.129.1556882731407; Fri, 03 May 2019 04:25:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556882731; cv=none; d=google.com; s=arc-20160816; b=pg3W4tAMJjRHDuHPg8Kl81u4e860BlNW9IqHGvfvzIRXYAA29wfqm6hNkk41bKmaXi P/T6VynQ6yESGS53k9h/ocdZ/BYhWiLX3lJAZsqS1kxufbGFTY+HdhJEQkcSjadtEvRa zhlpxx0SCg/pjjy5aOjRT95DYDtYxpLveJp0GqO/oZ738A8U7/NOEf7pnu/778UWzI1n W36s2quwu72TEmDmPU5MwbQfx02pUE9x1gGgzxNu7ULJX9aiPnXuW+/QCeGF25VOaIMX tX+D88OJjZZA+b1ESKj03jfZULqxMtnyudsonlJBVnzKaxJMW2PTJAfnvqi3lFF/iJ4o Wxvw== 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=EcJVjQK40r4QfDuCruz4ZdX2Nv0JkVO+ZEMz90RrtYo=; b=l+FDackr20s0LdBFp9QNHaEHaKF2dy0xH/xW68TrF8w13yw4T+3dXR2so29bM4CiXw O3EK+lNU45Powp8+H1HCHC/pPxSTEDT8Vd3C1TklsgMwmunbCUVaeXi69BYJOkOcGlk5 nDLHicAkPmmwuxtMZEVuLjkKR++0/LH/OoYCwJRTrgxnytOALHAr0vBbKBZ8CuPnhYs6 HgTzCGp6w9zutV28gWRvahQZOz3clOqw9GCxcNjoC5CxN7smoFgN7NAPDBKzgk2KGmwN RdKAkehX0HHBkHSKUbkrzvy9UyMqKy4crnOarNf2h32CH0KM3R/9ylIn+RowJC1ai4r/ UJHg== 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 w67si2017057pfb.20.2019.05.03.04.25.16; Fri, 03 May 2019 04:25:31 -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 S1727508AbfECLXv (ORCPT + 99 others); Fri, 3 May 2019 07:23:51 -0400 Received: from esa5.microchip.iphmx.com ([216.71.150.166]:6979 "EHLO esa5.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726396AbfECLXu (ORCPT ); Fri, 3 May 2019 07:23:50 -0400 Received-SPF: Pass (esa5.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=esa5.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 (esa5.microchip.iphmx.com: no sender authenticity information available from domain of postmaster@email.microchip.com) identity=helo; client-ip=198.175.253.82; receiver=esa5.microchip.iphmx.com; envelope-from="Joergen.Andreasen@microchip.com"; x-sender="postmaster@email.microchip.com"; x-conformance=spf_only Authentication-Results: esa5.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,425,1549954800"; d="scan'208";a="29952556" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa5.microchip.iphmx.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 03 May 2019 04:23:50 -0700 Received: from localhost (10.10.76.4) by chn-sv-exch07.mchp-main.com (10.10.76.108) with Microsoft SMTP Server id 14.3.352.0; Fri, 3 May 2019 04:23:29 -0700 Date: Fri, 3 May 2019 13:23:28 +0200 From: Joergen Andreasen To: Andrew Lunn CC: , Jamal Hadi Salim , Cong Wang , Jiri Pirko , Alexandre Belloni , Microchip Linux Driver Support , "David S. Miller" , "Ralf Baechle" , Paul Burton , "James Hogan" , , , Joergen Andreasen Subject: Re: [PATCH net-next 2/3] net: mscc: ocelot: Implement port policers via tc command Message-ID: <20190503112327.he2unkak7rhm6ajk@soft-dev16> References: <20190502094029.22526-1-joergen.andreasen@microchip.com> <20190502094029.22526-3-joergen.andreasen@microchip.com> <20190502123245.GB9844@lunn.ch> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Disposition: inline In-Reply-To: <20190502123245.GB9844@lunn.ch> User-Agent: NeoMutt/20171215 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Andrew, The 05/02/2019 14:32, Andrew Lunn wrote: > External E-Mail > > > Hi Joergen > > > + > > +#define MSCC_RC(expr) \ > > + do { \ > > + int __rc__ = (expr); \ > > + if (__rc__ < 0) \ > > + return __rc__; \ > > + } \ > > + while (0) > > I'm sure checkpatch warned about this. A return inside a macros is a > bad idea. I inherited code doing this, and broke it when adding > locking, because it was not obvious there was a return. > I saw the warning but I assumed that it wasn't a problem in this small context. The macro will be removed in v2. > > + > > +/* The following two functions do the same as in iproute2 */ > > +#define TIME_UNITS_PER_SEC 1000000 > > +static unsigned int tc_core_tick2time(unsigned int tick) > > +{ > > + return (tick * (u32)PSCHED_TICKS2NS(1)) / 1000; > > +} > > + > > +static unsigned int tc_calc_xmitsize(u64 rate, unsigned int ticks) > > +{ > > + return div_u64(rate * tc_core_tick2time(ticks), TIME_UNITS_PER_SEC); > > +} > > Should these but put somewhere others can use them? > It would be nice to put them in a more public place, but I am in doubt where to put them and what to call them. Maybe they belong in the new file: include/net/tc_act/tc_police.h. Would that be ok? > > + > > +enum mscc_qos_rate_mode { > > + MSCC_QOS_RATE_MODE_DISABLED, /* Policer/shaper disabled */ > > + MSCC_QOS_RATE_MODE_LINE, /* Measure line rate in kbps incl. IPG */ > > + MSCC_QOS_RATE_MODE_DATA, /* Measures data rate in kbps excl. IPG */ > > + MSCC_QOS_RATE_MODE_FRAME, /* Measures frame rate in fps */ > > + __MSCC_QOS_RATE_MODE_END, > > + NUM_MSCC_QOS_RATE_MODE = __MSCC_QOS_RATE_MODE_END, > > + MSCC_QOS_RATE_MODE_MAX = __MSCC_QOS_RATE_MODE_END - 1, > > +}; > > + > > +/* Round x divided by y to nearest integer. x and y are integers */ > > +#define MSCC_ROUNDING_DIVISION(x, y) (((x) + ((y) / 2)) / (y)) > > linux/kernel.h defines DIV_ROUND_UP(). Maybe add DIV_ROUND_DOWN()? > This macro is currently not used and I will remove it in v2. > > + > > +/* Round x divided by y to nearest higher integer. x and y are integers */ > > +#define MSCC_DIV_ROUND_UP(x, y) (((x) + (y) - 1) / (y)) > > DIV_ROUND_UP() ? > I will use DIV_ROUND_UP() in v2. > > + /* Limit to maximum values */ > > + pir = min_t(u32, GENMASK(15, 0), pir); > > + cir = min_t(u32, GENMASK(15, 0), cir); > > + pbs = min_t(u32, pbs_max, pbs); > > + cbs = min_t(u32, cbs_max, cbs); > > If it does need to limit, maybe return -EOPNOTSUPP? > It seems fine to return -EOPBITSUPP here. I will do that in v2. > > +int ocelot_port_policer_add(struct ocelot_port *port, > > + struct tcf_police *p) > > +{ > > + struct ocelot *ocelot = port->ocelot; > > + struct qos_policer_conf pp; > > + > > + if (!p) > > + return -EINVAL; > > + > > + netdev_dbg(port->dev, > > + "result %d ewma_rate %u burst %lld mtu %u mtu_pktoks %lld\n", > > + p->params->tcfp_result, > > + p->params->tcfp_ewma_rate, > > + p->params->tcfp_burst, > > + p->params->tcfp_mtu, > > + p->params->tcfp_mtu_ptoks); > > + > > + if (p->params->rate_present) > > + netdev_dbg(port->dev, > > + "rate: rate %llu mult %u over %u link %u shift %u\n", > > + p->params->rate.rate_bytes_ps, > > + p->params->rate.mult, > > + p->params->rate.overhead, > > + p->params->rate.linklayer, > > + p->params->rate.shift); > > + > > + if (p->params->peak_present) > > + netdev_dbg(port->dev, > > + "peak: rate %llu mult %u over %u link %u shift %u\n", > > + p->params->peak.rate_bytes_ps, > > + p->params->peak.mult, > > + p->params->peak.overhead, > > + p->params->peak.linklayer, > > + p->params->peak.shift); > > + > > + memset(&pp, 0, sizeof(pp)); > > Rather than memset, you can do: > > struct qos_policer_conf pp = { 0 }; > I will do as you suggest in v2. > Andrew > -- Joergen Andreasen, Microchip