Skip to content

Commit 22a6776

Browse files
jpirkodavem330
authored andcommitted
mlxsw: spectrum: Introduce ACL core with simple TCAM implementation
Add ACL core infrastructure for Spectrum ASIC. This infra provides an abstraction layer over specific HW implementations. There are two basic objects used. One is "rule" and the second is "ruleset" which serves as a container of multiple rules. In general, within one ruleset the rules are allowed to have multiple priorities and masks. Each ruleset is bound to either ingress or egress a of port netdevice. The initial TCAM implementation is very simple and limited. It utilizes parman lsort manager to take care of TCAM region layout. Signed-off-by: Jiri Pirko <[email protected]> Reviewed-by: Ido Schimmel <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 44091d2 commit 22a6776

File tree

6 files changed

+1769
-8
lines changed

6 files changed

+1769
-8
lines changed

drivers/net/ethernet/mellanox/mlxsw/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ config MLXSW_SWITCHX2
7373
config MLXSW_SPECTRUM
7474
tristate "Mellanox Technologies Spectrum support"
7575
depends on MLXSW_CORE && MLXSW_PCI && NET_SWITCHDEV && VLAN_8021Q
76+
select PARMAN
7677
default m
7778
---help---
7879
This driver supports Mellanox Technologies Spectrum Ethernet

drivers/net/ethernet/mellanox/mlxsw/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ mlxsw_switchx2-objs := switchx2.o
1414
obj-$(CONFIG_MLXSW_SPECTRUM) += mlxsw_spectrum.o
1515
mlxsw_spectrum-objs := spectrum.o spectrum_buffers.o \
1616
spectrum_switchdev.o spectrum_router.o \
17-
spectrum_kvdl.o
17+
spectrum_kvdl.o spectrum_acl.o \
18+
spectrum_acl_tcam.o
1819
mlxsw_spectrum-$(CONFIG_MLXSW_SPECTRUM_DCB) += spectrum_dcb.o
1920
obj-$(CONFIG_MLXSW_MINIMAL) += mlxsw_minimal.o
2021
mlxsw_minimal-objs := minimal.o

drivers/net/ethernet/mellanox/mlxsw/spectrum.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* drivers/net/ethernet/mellanox/mlxsw/spectrum.c
3-
* Copyright (c) 2015 Mellanox Technologies. All rights reserved.
4-
* Copyright (c) 2015 Jiri Pirko <[email protected]>
3+
* Copyright (c) 2015-2017 Mellanox Technologies. All rights reserved.
4+
* Copyright (c) 2015-2017 Jiri Pirko <[email protected]>
55
* Copyright (c) 2015 Ido Schimmel <[email protected]>
66
* Copyright (c) 2015 Elad Raz <[email protected]>
77
*
@@ -138,8 +138,6 @@ MLXSW_ITEM32(tx, hdr, fid, 0x08, 0, 16);
138138
*/
139139
MLXSW_ITEM32(tx, hdr, type, 0x0C, 0, 4);
140140

141-
static bool mlxsw_sp_port_dev_check(const struct net_device *dev);
142-
143141
static void mlxsw_sp_txhdr_construct(struct sk_buff *skb,
144142
const struct mlxsw_tx_info *tx_info)
145143
{
@@ -3203,6 +3201,12 @@ static int mlxsw_sp_init(struct mlxsw_core *mlxsw_core,
32033201
goto err_span_init;
32043202
}
32053203

3204+
err = mlxsw_sp_acl_init(mlxsw_sp);
3205+
if (err) {
3206+
dev_err(mlxsw_sp->bus_info->dev, "Failed to initialize ACL\n");
3207+
goto err_acl_init;
3208+
}
3209+
32063210
err = mlxsw_sp_ports_create(mlxsw_sp);
32073211
if (err) {
32083212
dev_err(mlxsw_sp->bus_info->dev, "Failed to create ports\n");
@@ -3212,6 +3216,8 @@ static int mlxsw_sp_init(struct mlxsw_core *mlxsw_core,
32123216
return 0;
32133217

32143218
err_ports_create:
3219+
mlxsw_sp_acl_fini(mlxsw_sp);
3220+
err_acl_init:
32153221
mlxsw_sp_span_fini(mlxsw_sp);
32163222
err_span_init:
32173223
mlxsw_sp_router_fini(mlxsw_sp);
@@ -3232,6 +3238,7 @@ static void mlxsw_sp_fini(struct mlxsw_core *mlxsw_core)
32323238
struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core);
32333239

32343240
mlxsw_sp_ports_remove(mlxsw_sp);
3241+
mlxsw_sp_acl_fini(mlxsw_sp);
32353242
mlxsw_sp_span_fini(mlxsw_sp);
32363243
mlxsw_sp_router_fini(mlxsw_sp);
32373244
mlxsw_sp_switchdev_fini(mlxsw_sp);
@@ -3297,7 +3304,7 @@ static struct mlxsw_driver mlxsw_sp_driver = {
32973304
.profile = &mlxsw_sp_config_profile,
32983305
};
32993306

3300-
static bool mlxsw_sp_port_dev_check(const struct net_device *dev)
3307+
bool mlxsw_sp_port_dev_check(const struct net_device *dev)
33013308
{
33023309
return dev->netdev_ops == &mlxsw_sp_port_netdev_ops;
33033310
}

drivers/net/ethernet/mellanox/mlxsw/spectrum.h

Lines changed: 98 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* drivers/net/ethernet/mellanox/mlxsw/spectrum.h
3-
* Copyright (c) 2015 Mellanox Technologies. All rights reserved.
4-
* Copyright (c) 2015 Jiri Pirko <[email protected]>
3+
* Copyright (c) 2015-2017 Mellanox Technologies. All rights reserved.
4+
* Copyright (c) 2015-2017 Jiri Pirko <[email protected]>
55
* Copyright (c) 2015 Ido Schimmel <[email protected]>
66
* Copyright (c) 2015 Elad Raz <[email protected]>
77
*
@@ -50,6 +50,8 @@
5050

5151
#include "port.h"
5252
#include "core.h"
53+
#include "core_acl_flex_keys.h"
54+
#include "core_acl_flex_actions.h"
5355

5456
#define MLXSW_SP_VFID_BASE VLAN_N_VID
5557
#define MLXSW_SP_VFID_MAX 6656 /* Bridged VLAN interfaces */
@@ -262,6 +264,8 @@ struct mlxsw_sp_router {
262264
bool aborted;
263265
};
264266

267+
struct mlxsw_sp_acl;
268+
265269
struct mlxsw_sp {
266270
struct {
267271
struct list_head list;
@@ -291,6 +295,7 @@ struct mlxsw_sp {
291295
u8 port_to_module[MLXSW_PORT_MAX_PORTS];
292296
struct mlxsw_sp_sb sb;
293297
struct mlxsw_sp_router router;
298+
struct mlxsw_sp_acl *acl;
294299
struct {
295300
DECLARE_BITMAP(usage, MLXSW_SP_KVD_LINEAR_SIZE);
296301
} kvdl;
@@ -373,6 +378,7 @@ struct mlxsw_sp_port {
373378
struct mlxsw_sp_port_sample *sample;
374379
};
375380

381+
bool mlxsw_sp_port_dev_check(const struct net_device *dev);
376382
struct mlxsw_sp_port *mlxsw_sp_port_lower_dev_hold(struct net_device *dev);
377383
void mlxsw_sp_port_dev_put(struct mlxsw_sp_port *mlxsw_sp_port);
378384

@@ -602,4 +608,94 @@ int mlxsw_sp_router_netevent_event(struct notifier_block *unused,
602608
int mlxsw_sp_kvdl_alloc(struct mlxsw_sp *mlxsw_sp, unsigned int entry_count);
603609
void mlxsw_sp_kvdl_free(struct mlxsw_sp *mlxsw_sp, int entry_index);
604610

611+
struct mlxsw_afk *mlxsw_sp_acl_afk(struct mlxsw_sp_acl *acl);
612+
613+
struct mlxsw_sp_acl_rule_info {
614+
unsigned int priority;
615+
struct mlxsw_afk_element_values values;
616+
struct mlxsw_afa_block *act_block;
617+
};
618+
619+
enum mlxsw_sp_acl_profile {
620+
MLXSW_SP_ACL_PROFILE_FLOWER,
621+
};
622+
623+
struct mlxsw_sp_acl_profile_ops {
624+
size_t ruleset_priv_size;
625+
int (*ruleset_add)(struct mlxsw_sp *mlxsw_sp,
626+
void *priv, void *ruleset_priv);
627+
void (*ruleset_del)(struct mlxsw_sp *mlxsw_sp, void *ruleset_priv);
628+
int (*ruleset_bind)(struct mlxsw_sp *mlxsw_sp, void *ruleset_priv,
629+
struct net_device *dev, bool ingress);
630+
void (*ruleset_unbind)(struct mlxsw_sp *mlxsw_sp, void *ruleset_priv);
631+
size_t rule_priv_size;
632+
int (*rule_add)(struct mlxsw_sp *mlxsw_sp,
633+
void *ruleset_priv, void *rule_priv,
634+
struct mlxsw_sp_acl_rule_info *rulei);
635+
void (*rule_del)(struct mlxsw_sp *mlxsw_sp, void *rule_priv);
636+
};
637+
638+
struct mlxsw_sp_acl_ops {
639+
size_t priv_size;
640+
int (*init)(struct mlxsw_sp *mlxsw_sp, void *priv);
641+
void (*fini)(struct mlxsw_sp *mlxsw_sp, void *priv);
642+
const struct mlxsw_sp_acl_profile_ops *
643+
(*profile_ops)(struct mlxsw_sp *mlxsw_sp,
644+
enum mlxsw_sp_acl_profile profile);
645+
};
646+
647+
struct mlxsw_sp_acl_ruleset;
648+
649+
struct mlxsw_sp_acl_ruleset *
650+
mlxsw_sp_acl_ruleset_get(struct mlxsw_sp *mlxsw_sp,
651+
struct net_device *dev, bool ingress,
652+
enum mlxsw_sp_acl_profile profile);
653+
void mlxsw_sp_acl_ruleset_put(struct mlxsw_sp *mlxsw_sp,
654+
struct mlxsw_sp_acl_ruleset *ruleset);
655+
656+
struct mlxsw_sp_acl_rule_info *
657+
mlxsw_sp_acl_rulei_create(struct mlxsw_sp_acl *acl);
658+
void mlxsw_sp_acl_rulei_destroy(struct mlxsw_sp_acl_rule_info *rulei);
659+
int mlxsw_sp_acl_rulei_commit(struct mlxsw_sp_acl_rule_info *rulei);
660+
void mlxsw_sp_acl_rulei_priority(struct mlxsw_sp_acl_rule_info *rulei,
661+
unsigned int priority);
662+
void mlxsw_sp_acl_rulei_keymask_u32(struct mlxsw_sp_acl_rule_info *rulei,
663+
enum mlxsw_afk_element element,
664+
u32 key_value, u32 mask_value);
665+
void mlxsw_sp_acl_rulei_keymask_buf(struct mlxsw_sp_acl_rule_info *rulei,
666+
enum mlxsw_afk_element element,
667+
const char *key_value,
668+
const char *mask_value, unsigned int len);
669+
void mlxsw_sp_acl_rulei_act_continue(struct mlxsw_sp_acl_rule_info *rulei);
670+
void mlxsw_sp_acl_rulei_act_jump(struct mlxsw_sp_acl_rule_info *rulei,
671+
u16 group_id);
672+
int mlxsw_sp_acl_rulei_act_drop(struct mlxsw_sp_acl_rule_info *rulei);
673+
int mlxsw_sp_acl_rulei_act_fwd(struct mlxsw_sp *mlxsw_sp,
674+
struct mlxsw_sp_acl_rule_info *rulei,
675+
struct net_device *out_dev);
676+
677+
struct mlxsw_sp_acl_rule;
678+
679+
struct mlxsw_sp_acl_rule *
680+
mlxsw_sp_acl_rule_create(struct mlxsw_sp *mlxsw_sp,
681+
struct mlxsw_sp_acl_ruleset *ruleset,
682+
unsigned long cookie);
683+
void mlxsw_sp_acl_rule_destroy(struct mlxsw_sp *mlxsw_sp,
684+
struct mlxsw_sp_acl_rule *rule);
685+
int mlxsw_sp_acl_rule_add(struct mlxsw_sp *mlxsw_sp,
686+
struct mlxsw_sp_acl_rule *rule);
687+
void mlxsw_sp_acl_rule_del(struct mlxsw_sp *mlxsw_sp,
688+
struct mlxsw_sp_acl_rule *rule);
689+
struct mlxsw_sp_acl_rule *
690+
mlxsw_sp_acl_rule_lookup(struct mlxsw_sp *mlxsw_sp,
691+
struct mlxsw_sp_acl_ruleset *ruleset,
692+
unsigned long cookie);
693+
struct mlxsw_sp_acl_rule_info *
694+
mlxsw_sp_acl_rule_rulei(struct mlxsw_sp_acl_rule *rule);
695+
696+
int mlxsw_sp_acl_init(struct mlxsw_sp *mlxsw_sp);
697+
void mlxsw_sp_acl_fini(struct mlxsw_sp *mlxsw_sp);
698+
699+
extern const struct mlxsw_sp_acl_ops mlxsw_sp_acl_tcam_ops;
700+
605701
#endif

0 commit comments

Comments
 (0)