Commit fc411eaa authored by Vladimir Oltean's avatar Vladimir Oltean Committed by David S. Miller

net: dsa: felix: add port policers

This patch is a trivial passthrough towards the ocelot library, which
support port policers since commit 2c1d029a ("net: mscc: ocelot:
Implement port policers via tc command").

Some data structure conversion between the DSA core and the Ocelot
library is necessary, for policer parameters.
Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 34297176
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include <linux/of_net.h> #include <linux/of_net.h>
#include <linux/pci.h> #include <linux/pci.h>
#include <linux/of.h> #include <linux/of.h>
#include <net/pkt_sched.h>
#include <net/dsa.h> #include <net/dsa.h>
#include "felix.h" #include "felix.h"
...@@ -650,6 +651,27 @@ static int felix_cls_flower_stats(struct dsa_switch *ds, int port, ...@@ -650,6 +651,27 @@ static int felix_cls_flower_stats(struct dsa_switch *ds, int port,
return ocelot_cls_flower_stats(ocelot, port, cls, ingress); return ocelot_cls_flower_stats(ocelot, port, cls, ingress);
} }
static int felix_port_policer_add(struct dsa_switch *ds, int port,
struct dsa_mall_policer_tc_entry *policer)
{
struct ocelot *ocelot = ds->priv;
struct ocelot_policer pol = {
.rate = div_u64(policer->rate_bytes_per_sec, 1000) * 8,
.burst = div_u64(policer->rate_bytes_per_sec *
PSCHED_NS2TICKS(policer->burst),
PSCHED_TICKS_PER_SEC),
};
return ocelot_port_policer_add(ocelot, port, &pol);
}
static void felix_port_policer_del(struct dsa_switch *ds, int port)
{
struct ocelot *ocelot = ds->priv;
ocelot_port_policer_del(ocelot, port);
}
static const struct dsa_switch_ops felix_switch_ops = { static const struct dsa_switch_ops felix_switch_ops = {
.get_tag_protocol = felix_get_tag_protocol, .get_tag_protocol = felix_get_tag_protocol,
.setup = felix_setup, .setup = felix_setup,
...@@ -683,6 +705,8 @@ static const struct dsa_switch_ops felix_switch_ops = { ...@@ -683,6 +705,8 @@ static const struct dsa_switch_ops felix_switch_ops = {
.port_txtstamp = felix_txtstamp, .port_txtstamp = felix_txtstamp,
.port_change_mtu = felix_change_mtu, .port_change_mtu = felix_change_mtu,
.port_max_mtu = felix_get_max_mtu, .port_max_mtu = felix_get_max_mtu,
.port_policer_add = felix_port_policer_add,
.port_policer_del = felix_port_policer_del,
.cls_flower_add = felix_cls_flower_add, .cls_flower_add = felix_cls_flower_add,
.cls_flower_del = felix_cls_flower_del, .cls_flower_del = felix_cls_flower_del,
.cls_flower_stats = felix_cls_flower_stats, .cls_flower_stats = felix_cls_flower_stats,
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
* Copyright (c) 2019 Microsemi Corporation * Copyright (c) 2019 Microsemi Corporation
*/ */
#include <soc/mscc/ocelot.h>
#include "ocelot_police.h" #include "ocelot_police.h"
enum mscc_qos_rate_mode { enum mscc_qos_rate_mode {
...@@ -203,6 +204,7 @@ int ocelot_port_policer_add(struct ocelot *ocelot, int port, ...@@ -203,6 +204,7 @@ int ocelot_port_policer_add(struct ocelot *ocelot, int port,
return 0; return 0;
} }
EXPORT_SYMBOL(ocelot_port_policer_add);
int ocelot_port_policer_del(struct ocelot *ocelot, int port) int ocelot_port_policer_del(struct ocelot *ocelot, int port)
{ {
...@@ -225,6 +227,7 @@ int ocelot_port_policer_del(struct ocelot *ocelot, int port) ...@@ -225,6 +227,7 @@ int ocelot_port_policer_del(struct ocelot *ocelot, int port)
return 0; return 0;
} }
EXPORT_SYMBOL(ocelot_port_policer_del);
int ocelot_ace_policer_add(struct ocelot *ocelot, u32 pol_ix, int ocelot_ace_policer_add(struct ocelot *ocelot, u32 pol_ix,
struct ocelot_policer *pol) struct ocelot_policer *pol)
......
...@@ -9,16 +9,6 @@ ...@@ -9,16 +9,6 @@
#include "ocelot.h" #include "ocelot.h"
struct ocelot_policer {
u32 rate; /* kilobit per second */
u32 burst; /* bytes */
};
int ocelot_port_policer_add(struct ocelot *ocelot, int port,
struct ocelot_policer *pol);
int ocelot_port_policer_del(struct ocelot *ocelot, int port);
int ocelot_ace_policer_add(struct ocelot *ocelot, u32 pol_ix, int ocelot_ace_policer_add(struct ocelot *ocelot, u32 pol_ix,
struct ocelot_policer *pol); struct ocelot_policer *pol);
......
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
* Copyright (c) 2019 Microsemi Corporation * Copyright (c) 2019 Microsemi Corporation
*/ */
#include <soc/mscc/ocelot.h>
#include "ocelot_tc.h" #include "ocelot_tc.h"
#include "ocelot_police.h"
#include "ocelot_ace.h" #include "ocelot_ace.h"
#include <net/pkt_cls.h> #include <net/pkt_cls.h>
......
...@@ -549,6 +549,11 @@ struct ocelot { ...@@ -549,6 +549,11 @@ struct ocelot {
spinlock_t ptp_clock_lock; spinlock_t ptp_clock_lock;
}; };
struct ocelot_policer {
u32 rate; /* kilobit per second */
u32 burst; /* bytes */
};
#define ocelot_read_ix(ocelot, reg, gi, ri) __ocelot_read_ix(ocelot, reg, reg##_GSZ * (gi) + reg##_RSZ * (ri)) #define ocelot_read_ix(ocelot, reg, gi, ri) __ocelot_read_ix(ocelot, reg, reg##_GSZ * (gi) + reg##_RSZ * (ri))
#define ocelot_read_gix(ocelot, reg, gi) __ocelot_read_ix(ocelot, reg, reg##_GSZ * (gi)) #define ocelot_read_gix(ocelot, reg, gi) __ocelot_read_ix(ocelot, reg, reg##_GSZ * (gi))
#define ocelot_read_rix(ocelot, reg, ri) __ocelot_read_ix(ocelot, reg, reg##_RSZ * (ri)) #define ocelot_read_rix(ocelot, reg, ri) __ocelot_read_ix(ocelot, reg, reg##_RSZ * (ri))
...@@ -619,6 +624,9 @@ int ocelot_port_add_txtstamp_skb(struct ocelot_port *ocelot_port, ...@@ -619,6 +624,9 @@ int ocelot_port_add_txtstamp_skb(struct ocelot_port *ocelot_port,
void ocelot_get_txtstamp(struct ocelot *ocelot); void ocelot_get_txtstamp(struct ocelot *ocelot);
void ocelot_port_set_maxlen(struct ocelot *ocelot, int port, size_t sdu); void ocelot_port_set_maxlen(struct ocelot *ocelot, int port, size_t sdu);
int ocelot_get_max_mtu(struct ocelot *ocelot, int port); int ocelot_get_max_mtu(struct ocelot *ocelot, int port);
int ocelot_port_policer_add(struct ocelot *ocelot, int port,
struct ocelot_policer *pol);
int ocelot_port_policer_del(struct ocelot *ocelot, int port);
int ocelot_cls_flower_replace(struct ocelot *ocelot, int port, int ocelot_cls_flower_replace(struct ocelot *ocelot, int port,
struct flow_cls_offload *f, bool ingress); struct flow_cls_offload *f, bool ingress);
int ocelot_cls_flower_destroy(struct ocelot *ocelot, int port, int ocelot_cls_flower_destroy(struct ocelot *ocelot, int port,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment