Commit 9ace2300 authored by David S. Miller's avatar David S. Miller

Merge branch 'prestera-next'

Volodymyr Mytnyk says:

====================
net: prestera: acl: migrate to new vTcam/counter api

This patch series aims to use new vTcam and Counter API
provided by latest fw version. The advantage of using
this API is the following:

- provides a way to have a rule with desired Tcam size (improves
  Tcam memory utilization).
- batch support for acl counters gathering (improves performance)
- gives more control over HW ACL engine (actions/matches/bindings)
  to be able to support more features in the future driver
  versions

Note: the feature set left the same as was before this patch.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 4c897cfc adefefe5
......@@ -3,6 +3,6 @@ obj-$(CONFIG_PRESTERA) += prestera.o
prestera-objs := prestera_main.o prestera_hw.o prestera_dsa.o \
prestera_rxtx.o prestera_devlink.o prestera_ethtool.o \
prestera_switchdev.o prestera_acl.o prestera_flow.o \
prestera_flower.o prestera_span.o
prestera_flower.o prestera_span.o prestera_counter.o
obj-$(CONFIG_PRESTERA_PCI) += prestera_pci.o
......@@ -248,6 +248,7 @@ struct prestera_switch {
u32 mtu_max;
u8 id;
struct prestera_lag *lags;
struct prestera_counter *counter;
u8 lag_member_max;
u8 lag_max;
};
......
/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
/* Copyright (c) 2020 Marvell International Ltd. All rights reserved. */
/* Copyright (c) 2020-2021 Marvell International Ltd. All rights reserved. */
#ifndef _PRESTERA_ACL_H_
#define _PRESTERA_ACL_H_
enum prestera_acl_rule_match_entry_type {
PRESTERA_ACL_RULE_MATCH_ENTRY_TYPE_ETH_TYPE = 1,
PRESTERA_ACL_RULE_MATCH_ENTRY_TYPE_ETH_DMAC,
PRESTERA_ACL_RULE_MATCH_ENTRY_TYPE_ETH_SMAC,
PRESTERA_ACL_RULE_MATCH_ENTRY_TYPE_IP_PROTO,
PRESTERA_ACL_RULE_MATCH_ENTRY_TYPE_PORT,
PRESTERA_ACL_RULE_MATCH_ENTRY_TYPE_IP_SRC,
PRESTERA_ACL_RULE_MATCH_ENTRY_TYPE_IP_DST,
PRESTERA_ACL_RULE_MATCH_ENTRY_TYPE_L4_PORT_SRC,
PRESTERA_ACL_RULE_MATCH_ENTRY_TYPE_L4_PORT_DST,
PRESTERA_ACL_RULE_MATCH_ENTRY_TYPE_L4_PORT_RANGE_SRC,
PRESTERA_ACL_RULE_MATCH_ENTRY_TYPE_L4_PORT_RANGE_DST,
PRESTERA_ACL_RULE_MATCH_ENTRY_TYPE_VLAN_ID,
PRESTERA_ACL_RULE_MATCH_ENTRY_TYPE_VLAN_TPID,
PRESTERA_ACL_RULE_MATCH_ENTRY_TYPE_ICMP_TYPE,
PRESTERA_ACL_RULE_MATCH_ENTRY_TYPE_ICMP_CODE
#include <linux/types.h>
#include "prestera_counter.h"
#define PRESTERA_ACL_KEYMASK_PCL_ID 0x3FF
#define PRESTERA_ACL_KEYMASK_PCL_ID_USER \
(PRESTERA_ACL_KEYMASK_PCL_ID & 0x00FF)
#define rule_match_set_n(match_p, type, val_p, size) \
memcpy(&(match_p)[PRESTERA_ACL_RULE_MATCH_TYPE_##type], \
val_p, size)
#define rule_match_set(match_p, type, val) \
memcpy(&(match_p)[PRESTERA_ACL_RULE_MATCH_TYPE_##type], \
&(val), sizeof(val))
enum prestera_acl_match_type {
PRESTERA_ACL_RULE_MATCH_TYPE_PCL_ID,
PRESTERA_ACL_RULE_MATCH_TYPE_ETH_TYPE,
PRESTERA_ACL_RULE_MATCH_TYPE_ETH_DMAC_0,
PRESTERA_ACL_RULE_MATCH_TYPE_ETH_DMAC_1,
PRESTERA_ACL_RULE_MATCH_TYPE_ETH_SMAC_0,
PRESTERA_ACL_RULE_MATCH_TYPE_ETH_SMAC_1,
PRESTERA_ACL_RULE_MATCH_TYPE_IP_PROTO,
PRESTERA_ACL_RULE_MATCH_TYPE_SYS_PORT,
PRESTERA_ACL_RULE_MATCH_TYPE_SYS_DEV,
PRESTERA_ACL_RULE_MATCH_TYPE_IP_SRC,
PRESTERA_ACL_RULE_MATCH_TYPE_IP_DST,
PRESTERA_ACL_RULE_MATCH_TYPE_L4_PORT_SRC,
PRESTERA_ACL_RULE_MATCH_TYPE_L4_PORT_DST,
PRESTERA_ACL_RULE_MATCH_TYPE_L4_PORT_RANGE_SRC,
PRESTERA_ACL_RULE_MATCH_TYPE_L4_PORT_RANGE_DST,
PRESTERA_ACL_RULE_MATCH_TYPE_VLAN_ID,
PRESTERA_ACL_RULE_MATCH_TYPE_VLAN_TPID,
PRESTERA_ACL_RULE_MATCH_TYPE_ICMP_TYPE,
PRESTERA_ACL_RULE_MATCH_TYPE_ICMP_CODE,
__PRESTERA_ACL_RULE_MATCH_TYPE_MAX
};
enum prestera_acl_rule_action {
PRESTERA_ACL_RULE_ACTION_ACCEPT,
PRESTERA_ACL_RULE_ACTION_DROP,
PRESTERA_ACL_RULE_ACTION_TRAP
PRESTERA_ACL_RULE_ACTION_ACCEPT = 0,
PRESTERA_ACL_RULE_ACTION_DROP = 1,
PRESTERA_ACL_RULE_ACTION_TRAP = 2,
PRESTERA_ACL_RULE_ACTION_COUNT = 7,
PRESTERA_ACL_RULE_ACTION_MAX
};
struct prestera_switch;
struct prestera_port;
struct prestera_acl_rule;
struct prestera_acl_ruleset;
enum {
PRESTERA_ACL_IFACE_TYPE_PORT,
PRESTERA_ACL_IFACE_TYPE_INDEX
};
struct prestera_flow_block_binding {
struct list_head list;
struct prestera_port *port;
int span_id;
struct prestera_acl_match {
__be32 key[__PRESTERA_ACL_RULE_MATCH_TYPE_MAX];
__be32 mask[__PRESTERA_ACL_RULE_MATCH_TYPE_MAX];
};
struct prestera_flow_block {
struct list_head binding_list;
struct prestera_switch *sw;
struct net *net;
struct prestera_acl_ruleset *ruleset;
struct flow_block_cb *block_cb;
struct prestera_acl_action_count {
u32 id;
};
struct prestera_acl_rule_action_entry {
struct list_head list;
enum prestera_acl_rule_action id;
struct prestera_acl_rule_entry_key {
u32 prio;
struct prestera_acl_match match;
};
struct prestera_acl_rule_match_entry {
struct list_head list;
enum prestera_acl_rule_match_entry_type type;
struct prestera_acl_hw_action_info {
enum prestera_acl_rule_action id;
union {
struct prestera_acl_action_count count;
};
};
/* This struct (arg) used only to be passed as parameter for
* acl_rule_entry_create. Must be flat. Can contain object keys, which will be
* resolved to object links, before saving to acl_rule_entry struct
*/
struct prestera_acl_rule_entry_arg {
u32 vtcam_id;
struct {
struct {
u8 key;
u8 mask;
} u8;
struct {
u16 key;
u16 mask;
} u16;
struct {
u32 key;
u32 mask;
} u32;
struct {
u64 key;
u64 mask;
} u64;
u8 valid:1;
} accept, drop, trap;
struct {
u8 key[ETH_ALEN];
u8 mask[ETH_ALEN];
} mac;
} keymask;
u8 valid:1;
u32 client;
} count;
};
};
struct prestera_acl_rule {
struct rhash_head ht_node; /* Member of acl HT */
struct list_head list;
struct prestera_acl_ruleset *ruleset;
unsigned long cookie;
u32 priority;
struct prestera_acl_rule_entry_key re_key;
struct prestera_acl_rule_entry_arg re_arg;
struct prestera_acl_rule_entry *re;
};
struct prestera_acl_iface {
union {
struct prestera_port *port;
u32 index;
};
u8 type;
};
struct prestera_acl;
struct prestera_switch;
struct prestera_flow_block;
int prestera_acl_init(struct prestera_switch *sw);
void prestera_acl_fini(struct prestera_switch *sw);
struct prestera_flow_block *
prestera_acl_block_create(struct prestera_switch *sw, struct net *net);
void prestera_acl_block_destroy(struct prestera_flow_block *block);
struct net *prestera_acl_block_net(struct prestera_flow_block *block);
struct prestera_switch *prestera_acl_block_sw(struct prestera_flow_block *block);
int prestera_acl_block_bind(struct prestera_flow_block *block,
struct prestera_port *port);
int prestera_acl_block_unbind(struct prestera_flow_block *block,
struct prestera_port *port);
struct prestera_acl_ruleset *
prestera_acl_block_ruleset_get(struct prestera_flow_block *block);
struct prestera_acl_rule *
prestera_acl_rule_create(struct prestera_flow_block *block,
prestera_acl_rule_create(struct prestera_acl_ruleset *ruleset,
unsigned long cookie);
u32 prestera_acl_rule_priority_get(struct prestera_acl_rule *rule);
void prestera_acl_rule_priority_set(struct prestera_acl_rule *rule,
u32 priority);
u16 prestera_acl_rule_ruleset_id_get(const struct prestera_acl_rule *rule);
struct list_head *
prestera_acl_rule_action_list_get(struct prestera_acl_rule *rule);
u8 prestera_acl_rule_action_len(struct prestera_acl_rule *rule);
u8 prestera_acl_rule_match_len(struct prestera_acl_rule *rule);
int prestera_acl_rule_action_add(struct prestera_acl_rule *rule,
struct prestera_acl_rule_action_entry *entry);
struct list_head *
prestera_acl_rule_match_list_get(struct prestera_acl_rule *rule);
int prestera_acl_rule_match_add(struct prestera_acl_rule *rule,
struct prestera_acl_rule_match_entry *entry);
void prestera_acl_rule_destroy(struct prestera_acl_rule *rule);
struct prestera_acl_rule *
prestera_acl_rule_lookup(struct prestera_acl_ruleset *ruleset,
......@@ -117,8 +133,37 @@ int prestera_acl_rule_add(struct prestera_switch *sw,
struct prestera_acl_rule *rule);
void prestera_acl_rule_del(struct prestera_switch *sw,
struct prestera_acl_rule *rule);
int prestera_acl_rule_get_stats(struct prestera_switch *sw,
int prestera_acl_rule_get_stats(struct prestera_acl *acl,
struct prestera_acl_rule *rule,
u64 *packets, u64 *bytes, u64 *last_use);
struct prestera_acl_rule_entry *
prestera_acl_rule_entry_find(struct prestera_acl *acl,
struct prestera_acl_rule_entry_key *key);
void prestera_acl_rule_entry_destroy(struct prestera_acl *acl,
struct prestera_acl_rule_entry *e);
struct prestera_acl_rule_entry *
prestera_acl_rule_entry_create(struct prestera_acl *acl,
struct prestera_acl_rule_entry_key *key,
struct prestera_acl_rule_entry_arg *arg);
struct prestera_acl_ruleset *
prestera_acl_ruleset_get(struct prestera_acl *acl,
struct prestera_flow_block *block);
struct prestera_acl_ruleset *
prestera_acl_ruleset_lookup(struct prestera_acl *acl,
struct prestera_flow_block *block);
bool prestera_acl_ruleset_is_offload(struct prestera_acl_ruleset *ruleset);
int prestera_acl_ruleset_offload(struct prestera_acl_ruleset *ruleset);
void prestera_acl_ruleset_put(struct prestera_acl_ruleset *ruleset);
int prestera_acl_ruleset_bind(struct prestera_acl_ruleset *ruleset,
struct prestera_port *port);
int prestera_acl_ruleset_unbind(struct prestera_acl_ruleset *ruleset,
struct prestera_port *port);
void
prestera_acl_rule_keymask_pcl_id_set(struct prestera_acl_rule *rule,
u16 pcl_id);
int prestera_acl_vtcam_id_get(struct prestera_acl *acl, u8 lookup,
void *keymask, u32 *vtcam_id);
int prestera_acl_vtcam_id_put(struct prestera_acl *acl, u32 vtcam_id);
#endif /* _PRESTERA_ACL_H_ */
This diff is collapsed.
/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
/* Copyright (c) 2021 Marvell International Ltd. All rights reserved. */
#ifndef _PRESTERA_COUNTER_H_
#define _PRESTERA_COUNTER_H_
#include <linux/types.h>
struct prestera_counter_stats {
u64 packets;
u64 bytes;
};
struct prestera_switch;
struct prestera_counter;
struct prestera_counter_block;
int prestera_counter_init(struct prestera_switch *sw);
void prestera_counter_fini(struct prestera_switch *sw);
int prestera_counter_get(struct prestera_counter *counter, u32 client,
struct prestera_counter_block **block,
u32 *counter_id);
void prestera_counter_put(struct prestera_counter *counter,
struct prestera_counter_block *block, u32 counter_id);
int prestera_counter_stats_get(struct prestera_counter *counter,
struct prestera_counter_block *block,
u32 counter_id, u64 *packets, u64 *bytes);
#endif /* _PRESTERA_COUNTER_H_ */
......@@ -60,11 +60,100 @@ static int prestera_flow_block_cb(enum tc_setup_type type,
}
}
static void prestera_flow_block_destroy(void *cb_priv)
{
struct prestera_flow_block *block = cb_priv;
WARN_ON(!list_empty(&block->binding_list));
kfree(block);
}
static struct prestera_flow_block *
prestera_flow_block_create(struct prestera_switch *sw, struct net *net)
{
struct prestera_flow_block *block;
block = kzalloc(sizeof(*block), GFP_KERNEL);
if (!block)
return NULL;
INIT_LIST_HEAD(&block->binding_list);
block->net = net;
block->sw = sw;
return block;
}
static void prestera_flow_block_release(void *cb_priv)
{
struct prestera_flow_block *block = cb_priv;
prestera_acl_block_destroy(block);
prestera_flow_block_destroy(block);
}
static bool
prestera_flow_block_is_bound(const struct prestera_flow_block *block)
{
return block->ruleset_zero;
}
static struct prestera_flow_block_binding *
prestera_flow_block_lookup(struct prestera_flow_block *block,
struct prestera_port *port)
{
struct prestera_flow_block_binding *binding;
list_for_each_entry(binding, &block->binding_list, list)
if (binding->port == port)
return binding;
return NULL;
}
static int prestera_flow_block_bind(struct prestera_flow_block *block,
struct prestera_port *port)
{
struct prestera_flow_block_binding *binding;
int err;
binding = kzalloc(sizeof(*binding), GFP_KERNEL);
if (!binding)
return -ENOMEM;
binding->span_id = PRESTERA_SPAN_INVALID_ID;
binding->port = port;
if (prestera_flow_block_is_bound(block)) {
err = prestera_acl_ruleset_bind(block->ruleset_zero, port);
if (err)
goto err_ruleset_bind;
}
list_add(&binding->list, &block->binding_list);
return 0;
err_ruleset_bind:
kfree(binding);
return err;
}
static int prestera_flow_block_unbind(struct prestera_flow_block *block,
struct prestera_port *port)
{
struct prestera_flow_block_binding *binding;
binding = prestera_flow_block_lookup(block, port);
if (!binding)
return -ENOENT;
list_del(&binding->list);
if (prestera_flow_block_is_bound(block))
prestera_acl_ruleset_unbind(block->ruleset_zero, port);
kfree(binding);
return 0;
}
static struct prestera_flow_block *
......@@ -78,7 +167,7 @@ prestera_flow_block_get(struct prestera_switch *sw,
block_cb = flow_block_cb_lookup(f->block,
prestera_flow_block_cb, sw);
if (!block_cb) {
block = prestera_acl_block_create(sw, f->net);
block = prestera_flow_block_create(sw, f->net);
if (!block)
return ERR_PTR(-ENOMEM);
......@@ -86,7 +175,7 @@ prestera_flow_block_get(struct prestera_switch *sw,
sw, block,
prestera_flow_block_release);
if (IS_ERR(block_cb)) {
prestera_acl_block_destroy(block);
prestera_flow_block_destroy(block);
return ERR_CAST(block_cb);
}
......@@ -110,7 +199,7 @@ static void prestera_flow_block_put(struct prestera_flow_block *block)
return;
flow_block_cb_free(block_cb);
prestera_acl_block_destroy(block);
prestera_flow_block_destroy(block);
}
static int prestera_setup_flow_block_bind(struct prestera_port *port,
......@@ -128,7 +217,7 @@ static int prestera_setup_flow_block_bind(struct prestera_port *port,
block_cb = block->block_cb;
err = prestera_acl_block_bind(block, port);
err = prestera_flow_block_bind(block, port);
if (err)
goto err_block_bind;
......@@ -162,7 +251,7 @@ static void prestera_setup_flow_block_unbind(struct prestera_port *port,
prestera_span_destroy(block);
err = prestera_acl_block_unbind(block, port);
err = prestera_flow_block_unbind(block, port);
if (err)
goto error;
......
......@@ -7,6 +7,22 @@
#include <net/flow_offload.h>
struct prestera_port;
struct prestera_switch;
struct prestera_flow_block_binding {
struct list_head list;
struct prestera_port *port;
int span_id;
};
struct prestera_flow_block {
struct list_head binding_list;
struct prestera_switch *sw;
unsigned int rule_count;
struct net *net;
struct prestera_acl_ruleset *ruleset_zero;
struct flow_block_cb *block_cb;
};
int prestera_flow_block_setup(struct prestera_port *port,
struct flow_block_offload *f);
......
/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
/* Copyright (c) 2020 Marvell International Ltd. All rights reserved. */
/* Copyright (c) 2020-2021 Marvell International Ltd. All rights reserved. */
#ifndef _PRESTERA_FLOWER_H_
#define _PRESTERA_FLOWER_H_
#include <net/pkt_cls.h>
struct prestera_switch;
struct prestera_flow_block;
int prestera_flower_replace(struct prestera_flow_block *block,
......
......@@ -5,6 +5,7 @@
#define _PRESTERA_HW_H_
#include <linux/types.h>
#include "prestera_acl.h"
enum prestera_accept_frm_type {
PRESTERA_ACCEPT_FRAME_TYPE_TAGGED,
......@@ -111,18 +112,31 @@ enum prestera_hw_cpu_code_cnt_t {
PRESTERA_HW_CPU_CODE_CNT_TYPE_TRAP = 1,
};
enum prestera_hw_vtcam_direction_t {
PRESTERA_HW_VTCAM_DIR_INGRESS = 0,
PRESTERA_HW_VTCAM_DIR_EGRESS = 1,
};
enum {
PRESTERA_HW_COUNTER_CLIENT_LOOKUP_0 = 0,
PRESTERA_HW_COUNTER_CLIENT_LOOKUP_1 = 1,
PRESTERA_HW_COUNTER_CLIENT_LOOKUP_2 = 2,
};
struct prestera_switch;
struct prestera_port;
struct prestera_port_stats;
struct prestera_port_caps;
enum prestera_event_type;
struct prestera_event;
struct prestera_acl_rule;
typedef void (*prestera_event_cb_t)
(struct prestera_switch *sw, struct prestera_event *evt, void *arg);
struct prestera_rxtx_params;
struct prestera_acl_hw_action_info;
struct prestera_acl_iface;
struct prestera_counter_stats;
/* Switch API */
int prestera_hw_switch_init(struct prestera_switch *sw);
......@@ -186,21 +200,37 @@ int prestera_hw_bridge_delete(struct prestera_switch *sw, u16 bridge_id);
int prestera_hw_bridge_port_add(struct prestera_port *port, u16 bridge_id);
int prestera_hw_bridge_port_delete(struct prestera_port *port, u16 bridge_id);
/* ACL API */
int prestera_hw_acl_ruleset_create(struct prestera_switch *sw,
u16 *ruleset_id);
int prestera_hw_acl_ruleset_del(struct prestera_switch *sw,
u16 ruleset_id);
int prestera_hw_acl_rule_add(struct prestera_switch *sw,
struct prestera_acl_rule *rule,
u32 *rule_id);
int prestera_hw_acl_rule_del(struct prestera_switch *sw, u32 rule_id);
int prestera_hw_acl_rule_stats_get(struct prestera_switch *sw,
u32 rule_id, u64 *packets, u64 *bytes);
int prestera_hw_acl_port_bind(const struct prestera_port *port,
u16 ruleset_id);
int prestera_hw_acl_port_unbind(const struct prestera_port *port,
u16 ruleset_id);
/* vTCAM API */
int prestera_hw_vtcam_create(struct prestera_switch *sw,
u8 lookup, const u32 *keymask, u32 *vtcam_id,
enum prestera_hw_vtcam_direction_t direction);
int prestera_hw_vtcam_rule_add(struct prestera_switch *sw, u32 vtcam_id,
u32 prio, void *key, void *keymask,
struct prestera_acl_hw_action_info *act,
u8 n_act, u32 *rule_id);
int prestera_hw_vtcam_rule_del(struct prestera_switch *sw,
u32 vtcam_id, u32 rule_id);
int prestera_hw_vtcam_destroy(struct prestera_switch *sw, u32 vtcam_id);
int prestera_hw_vtcam_iface_bind(struct prestera_switch *sw,
struct prestera_acl_iface *iface,
u32 vtcam_id, u16 pcl_id);
int prestera_hw_vtcam_iface_unbind(struct prestera_switch *sw,
struct prestera_acl_iface *iface,
u32 vtcam_id);
/* Counter API */
int prestera_hw_counter_trigger(struct prestera_switch *sw, u32 block_id);
int prestera_hw_counter_abort(struct prestera_switch *sw);
int prestera_hw_counters_get(struct prestera_switch *sw, u32 idx,
u32 *len, bool *done,
struct prestera_counter_stats *stats);
int prestera_hw_counter_block_get(struct prestera_switch *sw,
u32 client, u32 *block_id, u32 *offset,
u32 *num_counters);
int prestera_hw_counter_block_release(struct prestera_switch *sw,
u32 block_id);
int prestera_hw_counter_clear(struct prestera_switch *sw, u32 block_id,
u32 counter_id);
/* SPAN API */
int prestera_hw_span_get(const struct prestera_port *port, u8 *span_id);
......
......@@ -18,6 +18,7 @@
#include "prestera_rxtx.h"
#include "prestera_devlink.h"
#include "prestera_ethtool.h"
#include "prestera_counter.h"
#include "prestera_switchdev.h"
#define PRESTERA_MTU_DEFAULT 1536
......@@ -904,6 +905,10 @@ static int prestera_switch_init(struct prestera_switch *sw)
if (err)
goto err_handlers_register;
err = prestera_counter_init(sw);
if (err)
goto err_counter_init;
err = prestera_acl_init(sw);
if (err)
goto err_acl_init;
......@@ -936,6 +941,8 @@ static int prestera_switch_init(struct prestera_switch *sw)
err_span_init:
prestera_acl_fini(sw);
err_acl_init:
prestera_counter_fini(sw);
err_counter_init:
prestera_event_handlers_unregister(sw);
err_handlers_register:
prestera_rxtx_switch_fini(sw);
......@@ -956,6 +963,7 @@ static void prestera_switch_fini(struct prestera_switch *sw)
prestera_devlink_traps_unregister(sw);
prestera_span_fini(sw);
prestera_acl_fini(sw);
prestera_counter_fini(sw);
prestera_event_handlers_unregister(sw);
prestera_rxtx_switch_fini(sw);
prestera_switchdev_fini(sw);
......
......@@ -7,6 +7,7 @@
#include "prestera.h"
#include "prestera_hw.h"
#include "prestera_acl.h"
#include "prestera_flow.h"
#include "prestera_span.h"
struct prestera_span_entry {
......
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