From: Andrew Lunn <andrew@lunn.ch>
To: Joergen Andreasen <joergen.andreasen@microchip.com>
Cc: netdev@vger.kernel.org, Jamal Hadi Salim <jhs@mojatatu.com>,
Cong Wang <xiyou.wangcong@gmail.com>,
Jiri Pirko <jiri@resnulli.us>,
Alexandre Belloni <alexandre.belloni@bootlin.com>,
Microchip Linux Driver Support <UNGLinuxDriver@microchip.com>,
"David S. Miller" <davem@davemloft.net>,
Ralf Baechle <ralf@linux-mips.org>,
Paul Burton <paul.burton@mips.com>,
James Hogan <jhogan@kernel.org>,
linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next 2/3] net: mscc: ocelot: Implement port policers via tc command
Date: Thu, 2 May 2019 14:32:45 +0200 [thread overview]
Message-ID: <20190502123245.GB9844@lunn.ch> (raw)
In-Reply-To: <20190502094029.22526-3-joergen.andreasen@microchip.com>
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.
> +
> +/* 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?
> +
> +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()?
> +
> +/* 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() ?
> + /* 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?
> +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 };
Andrew
next prev parent reply other threads:[~2019-05-02 12:33 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-02 9:40 [PATCH net-next 0/3] Add hw offload of TC police on MSCC ocelot Joergen Andreasen
2019-05-02 9:40 ` [PATCH net-next 1/3] net/sched: act_police: move police parameters into separate header file Joergen Andreasen
2019-05-02 20:38 ` Jiri Pirko
2019-05-02 9:40 ` [PATCH net-next 2/3] net: mscc: ocelot: Implement port policers via tc command Joergen Andreasen
2019-05-02 12:32 ` Andrew Lunn [this message]
2019-05-03 11:23 ` Joergen Andreasen
2019-05-02 20:36 ` Jiri Pirko
2019-05-03 11:38 ` Joergen Andreasen
2019-05-04 13:07 ` Jiri Pirko
2019-05-07 8:30 ` Joergen Andreasen
2019-05-02 9:40 ` [PATCH net-next 3/3] MIPS: generic: Add police related options to ocelot_defconfig Joergen Andreasen
2019-05-02 16:27 ` Alexandre Belloni
2019-05-03 10:47 ` Joergen Andreasen
2019-05-23 10:49 ` [PATCH net-next v2 0/1] Add hw offload of TC police on MSCC ocelot Joergen Andreasen
2019-05-23 10:49 ` [PATCH net-next v2 1/1] net: mscc: ocelot: Implement port policers via tc command Joergen Andreasen
2019-05-23 18:56 ` Jakub Kicinski
2019-05-24 11:40 ` Joergen Andreasen
2019-05-28 12:49 ` [PATCH net-next v3 0/1] Add hw offload of TC police on MSCC ocelot Joergen Andreasen
2019-05-28 12:49 ` [PATCH net-next v3 1/1] net: mscc: ocelot: Implement port policers via tc command Joergen Andreasen
2019-05-30 4:38 ` David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190502123245.GB9844@lunn.ch \
--to=andrew@lunn.ch \
--cc=UNGLinuxDriver@microchip.com \
--cc=alexandre.belloni@bootlin.com \
--cc=davem@davemloft.net \
--cc=jhogan@kernel.org \
--cc=jhs@mojatatu.com \
--cc=jiri@resnulli.us \
--cc=joergen.andreasen@microchip.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=paul.burton@mips.com \
--cc=ralf@linux-mips.org \
--cc=xiyou.wangcong@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).