GNU Linux-libre 5.19-rc6-gnu
[releases.git] / drivers / net / ethernet / marvell / prestera / prestera_router_hw.h
1 /* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
2 /* Copyright (c) 2019-2021 Marvell International Ltd. All rights reserved. */
3
4 #ifndef _PRESTERA_ROUTER_HW_H_
5 #define _PRESTERA_ROUTER_HW_H_
6
7 struct prestera_vr {
8         struct list_head router_node;
9         refcount_t refcount;
10         u32 tb_id;                      /* key (kernel fib table id) */
11         u16 hw_vr_id;                   /* virtual router ID */
12         u8 __pad[2];
13 };
14
15 struct prestera_rif_entry {
16         struct prestera_rif_entry_key {
17                 struct prestera_iface iface;
18         } key;
19         struct prestera_vr *vr;
20         unsigned char addr[ETH_ALEN];
21         u16 hw_id; /* rif_id */
22         struct list_head router_node; /* ht */
23 };
24
25 struct prestera_ip_addr {
26         union {
27                 __be32 ipv4;
28                 struct in6_addr ipv6;
29         } u;
30         enum {
31                 PRESTERA_IPV4 = 0,
32                 PRESTERA_IPV6
33         } v;
34 };
35
36 struct prestera_fib_key {
37         struct prestera_ip_addr addr;
38         u32 prefix_len;
39         u32 tb_id;
40 };
41
42 struct prestera_fib_info {
43         struct prestera_vr *vr;
44         struct list_head vr_node;
45         enum prestera_fib_type {
46                 PRESTERA_FIB_TYPE_INVALID = 0,
47                 /* It can be connected route
48                  * and will be overlapped with neighbours
49                  */
50                 PRESTERA_FIB_TYPE_TRAP,
51                 PRESTERA_FIB_TYPE_DROP
52         } type;
53 };
54
55 struct prestera_fib_node {
56         struct rhash_head ht_node; /* node of prestera_vr */
57         struct prestera_fib_key key;
58         struct prestera_fib_info info; /* action related info */
59 };
60
61 struct prestera_rif_entry *
62 prestera_rif_entry_find(const struct prestera_switch *sw,
63                         const struct prestera_rif_entry_key *k);
64 void prestera_rif_entry_destroy(struct prestera_switch *sw,
65                                 struct prestera_rif_entry *e);
66 struct prestera_rif_entry *
67 prestera_rif_entry_create(struct prestera_switch *sw,
68                           struct prestera_rif_entry_key *k,
69                           u32 tb_id, const unsigned char *addr);
70 struct prestera_fib_node *prestera_fib_node_find(struct prestera_switch *sw,
71                                                  struct prestera_fib_key *key);
72 void prestera_fib_node_destroy(struct prestera_switch *sw,
73                                struct prestera_fib_node *fib_node);
74 struct prestera_fib_node *
75 prestera_fib_node_create(struct prestera_switch *sw,
76                          struct prestera_fib_key *key,
77                          enum prestera_fib_type fib_type);
78 int prestera_router_hw_init(struct prestera_switch *sw);
79 void prestera_router_hw_fini(struct prestera_switch *sw);
80
81 #endif /* _PRESTERA_ROUTER_HW_H_ */