Skip to content

Commit fc411ea

Browse files
vladimirolteandavem330
authored andcommitted
net: dsa: felix: add port policers
This patch is a trivial passthrough towards the ocelot library, which support port policers since commit 2c1d029 ("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: Vladimir Oltean <vladimir.oltean@nxp.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 3429717 commit fc411ea

5 files changed

Lines changed: 36 additions & 11 deletions

File tree

‎drivers/net/dsa/ocelot/felix.c‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/of_net.h>
1414
#include <linux/pci.h>
1515
#include <linux/of.h>
16+
#include <net/pkt_sched.h>
1617
#include <net/dsa.h>
1718
#include "felix.h"
1819

@@ -650,6 +651,27 @@ static int felix_cls_flower_stats(struct dsa_switch *ds, int port,
650651
return ocelot_cls_flower_stats(ocelot, port, cls, ingress);
651652
}
652653

654+
static int felix_port_policer_add(struct dsa_switch *ds, int port,
655+
struct dsa_mall_policer_tc_entry *policer)
656+
{
657+
struct ocelot *ocelot = ds->priv;
658+
struct ocelot_policer pol = {
659+
.rate = div_u64(policer->rate_bytes_per_sec, 1000) * 8,
660+
.burst = div_u64(policer->rate_bytes_per_sec *
661+
PSCHED_NS2TICKS(policer->burst),
662+
PSCHED_TICKS_PER_SEC),
663+
};
664+
665+
return ocelot_port_policer_add(ocelot, port, &pol);
666+
}
667+
668+
static void felix_port_policer_del(struct dsa_switch *ds, int port)
669+
{
670+
struct ocelot *ocelot = ds->priv;
671+
672+
ocelot_port_policer_del(ocelot, port);
673+
}
674+
653675
static const struct dsa_switch_ops felix_switch_ops = {
654676
.get_tag_protocol = felix_get_tag_protocol,
655677
.setup = felix_setup,
@@ -683,6 +705,8 @@ static const struct dsa_switch_ops felix_switch_ops = {
683705
.port_txtstamp = felix_txtstamp,
684706
.port_change_mtu = felix_change_mtu,
685707
.port_max_mtu = felix_get_max_mtu,
708+
.port_policer_add = felix_port_policer_add,
709+
.port_policer_del = felix_port_policer_del,
686710
.cls_flower_add = felix_cls_flower_add,
687711
.cls_flower_del = felix_cls_flower_del,
688712
.cls_flower_stats = felix_cls_flower_stats,

‎drivers/net/ethernet/mscc/ocelot_police.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Copyright (c) 2019 Microsemi Corporation
55
*/
66

7+
#include <soc/mscc/ocelot.h>
78
#include "ocelot_police.h"
89

910
enum mscc_qos_rate_mode {
@@ -203,6 +204,7 @@ int ocelot_port_policer_add(struct ocelot *ocelot, int port,
203204

204205
return 0;
205206
}
207+
EXPORT_SYMBOL(ocelot_port_policer_add);
206208

207209
int ocelot_port_policer_del(struct ocelot *ocelot, int port)
208210
{
@@ -225,6 +227,7 @@ int ocelot_port_policer_del(struct ocelot *ocelot, int port)
225227

226228
return 0;
227229
}
230+
EXPORT_SYMBOL(ocelot_port_policer_del);
228231

229232
int ocelot_ace_policer_add(struct ocelot *ocelot, u32 pol_ix,
230233
struct ocelot_policer *pol)

‎drivers/net/ethernet/mscc/ocelot_police.h‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,6 @@
99

1010
#include "ocelot.h"
1111

12-
struct ocelot_policer {
13-
u32 rate; /* kilobit per second */
14-
u32 burst; /* bytes */
15-
};
16-
17-
int ocelot_port_policer_add(struct ocelot *ocelot, int port,
18-
struct ocelot_policer *pol);
19-
20-
int ocelot_port_policer_del(struct ocelot *ocelot, int port);
21-
2212
int ocelot_ace_policer_add(struct ocelot *ocelot, u32 pol_ix,
2313
struct ocelot_policer *pol);
2414

‎drivers/net/ethernet/mscc/ocelot_tc.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
* Copyright (c) 2019 Microsemi Corporation
55
*/
66

7+
#include <soc/mscc/ocelot.h>
78
#include "ocelot_tc.h"
8-
#include "ocelot_police.h"
99
#include "ocelot_ace.h"
1010
#include <net/pkt_cls.h>
1111

‎include/soc/mscc/ocelot.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,11 @@ struct ocelot {
549549
spinlock_t ptp_clock_lock;
550550
};
551551

552+
struct ocelot_policer {
553+
u32 rate; /* kilobit per second */
554+
u32 burst; /* bytes */
555+
};
556+
552557
#define ocelot_read_ix(ocelot, reg, gi, ri) __ocelot_read_ix(ocelot, reg, reg##_GSZ * (gi) + reg##_RSZ * (ri))
553558
#define ocelot_read_gix(ocelot, reg, gi) __ocelot_read_ix(ocelot, reg, reg##_GSZ * (gi))
554559
#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,
619624
void ocelot_get_txtstamp(struct ocelot *ocelot);
620625
void ocelot_port_set_maxlen(struct ocelot *ocelot, int port, size_t sdu);
621626
int ocelot_get_max_mtu(struct ocelot *ocelot, int port);
627+
int ocelot_port_policer_add(struct ocelot *ocelot, int port,
628+
struct ocelot_policer *pol);
629+
int ocelot_port_policer_del(struct ocelot *ocelot, int port);
622630
int ocelot_cls_flower_replace(struct ocelot *ocelot, int port,
623631
struct flow_cls_offload *f, bool ingress);
624632
int ocelot_cls_flower_destroy(struct ocelot *ocelot, int port,

0 commit comments

Comments
 (0)