summaryrefslogtreecommitdiff
path: root/drivers/net/dsa/realtek/rtl8365mb_table.h
blob: 41280eb6f8b0c9b0a60cdd8f498af80cf0d19d84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/* SPDX-License-Identifier: GPL-2.0 */
/* Look-up table query interface for the rtl8365mb switch family
 *
 * Copyright (C) 2022 Alvin Šipraga <alsi@bang-olufsen.dk>
 */

#ifndef _REALTEK_RTL8365MB_TABLE_H
#define _REALTEK_RTL8365MB_TABLE_H

#include <linux/if_ether.h>
#include <linux/types.h>

#include "realtek.h"

#define RTL8365MB_TABLE_ENTRY_MAX_SIZE			10

/*
 * enum rtl8365mb_table - available switch tables
 * @RTL8365MB_TABLE_ACL_RULE: ACL rules
 * @RTL8365MB_TABLE_ACL_ACTION: ACL actions
 * @RTL8365MB_TABLE_CVLAN: VLAN4k configurations
 * @RTL8365MB_TABLE_L2: filtering database (2K hash table)
 * @RTL8365MB_TABLE_IGMP_GROUP: IGMP group database (readonly)
 *
 * NOTE: Don't change the enum values. They must concur with the field
 * described by @RTL8365MB_TABLE_CTRL_TABLE_MASK.
 */
enum rtl8365mb_table {
	RTL8365MB_TABLE_ACL_RULE = 1,
	RTL8365MB_TABLE_ACL_ACTION = 2,
	RTL8365MB_TABLE_CVLAN = 3,
	RTL8365MB_TABLE_L2 = 4,
	RTL8365MB_TABLE_IGMP_GROUP = 5,
};

/*
 * enum rtl8365mb_table_op - table query operation
 * @RTL8365MB_TABLE_OP_READ: read an entry from the target table
 * @RTL8365MB_TABLE_OP_WRITE: write an entry to the target table
 *
 * NOTE: Don't change the enum values. They must concur with the field
 * described by @RTL8365MB_TABLE_CTRL_OP_MASK.
 */
enum rtl8365mb_table_op {
	RTL8365MB_TABLE_OP_READ = 0,
	RTL8365MB_TABLE_OP_WRITE = 1,
};

/*
 * enum rtl8365mb_table_l2_method - look-up method for read queries of L2 table
 * @RTL8365MB_TABLE_L2_METHOD_MAC: look-up by source MAC address and FID (or
 *   VID)
 * @RTL8365MB_TABLE_L2_METHOD_ADDR: look-up by entry address
 * @RTL8365MB_TABLE_L2_METHOD_ADDR_NEXT: look-up next entry starting from the
 *   supplied address
 * @RTL8365MB_TABLE_L2_METHOD_ADDR_NEXT_UC: same as ADDR_NEXT but search only
 *   unicast addresses
 * @RTL8365MB_TABLE_L2_METHOD_ADDR_NEXT_MC: same as ADDR_NEXT but search only
 *   multicast addresses
 * @RTL8365MB_TABLE_L2_METHOD_ADDR_NEXT_UC_PORT: same as ADDR_NEXT_UC but
 *   search only entries with matching source port
 *
 * NOTE: Don't change the enum values. They must concur with the field
 * described by @RTL8365MB_TABLE_CTRL_METHOD_MASK
 */
enum rtl8365mb_table_l2_method {
	RTL8365MB_TABLE_L2_METHOD_MAC = 0,
	RTL8365MB_TABLE_L2_METHOD_ADDR = 1,
	RTL8365MB_TABLE_L2_METHOD_ADDR_NEXT = 2,
	RTL8365MB_TABLE_L2_METHOD_ADDR_NEXT_UC = 3,
	RTL8365MB_TABLE_L2_METHOD_ADDR_NEXT_MC = 4,
	/*
	 * RTL8365MB_TABLE_L2_METHOD_ADDR_NEXT_MC_L3 = 5,
	 * RTL8365MB_TABLE_L2_METHOD_ADDR_NEXT_MC_L2L3 = 6,
	 */
	RTL8365MB_TABLE_L2_METHOD_ADDR_NEXT_UC_PORT = 7,
};

/*
 * rtl8365mb_table_query() - read from or write to a switch table
 * @priv: driver context
 * @table: target table, see &enum rtl8365mb_table
 * @op: read or write operation, see &enum rtl8365mb_table_op
 * @addr: table address. For indexed tables, this selects the entry to access.
 *        For L2 read queries, it is ignored as input for MAC-based lookup
 *        methods and used as input for address-based lookup methods. On
 *        successful L2 queries, it is updated with the matched entry address.
 * @method: L2 table lookup method, see &enum rtl8365mb_table_l2_method.
 *	    Ignored for non-L2 tables.
 * @port: for L2 read queries using method
 *        %RTL8365MB_TABLE_L2_METHOD_ADDR_NEXT_UC_PORT, restrict the search
 *        to entries associated with this source port. Ignored otherwise.
 * @data: data buffer used to read from or write to the table. For L2 MAC
 *        lookups, this buffer provides the lookup key and receives the
 *        matched entry contents on success.
 * @size: size of @data in 16-bit words. The caller must ensure that @size
 *        matches the target table's entry size and does not exceed
 *        RTL8365MB_TABLE_ENTRY_MAX_SIZE.
 *
 * This function provides unified access to the internal tables of the switch.
 * All tables except the L2 table are simple indexed tables, where @addr
 * selects the entry and @op determines whether the access is a read or a
 * write operation.
 *
 * The content of @data is used as input when writing to tables or when
 * specifying the lookup key for L2 MAC searches, and as output for all
 * successful read operations. It remains unchanged during write operations or
 * failed read operations that return %-ENOENT. For other errors during read
 * operations, it is undefined.
 *
 * The L2 table is a hash table and supports multiple lookup methods. For
 * %RTL8365MB_TABLE_L2_METHOD_MAC, an entry is searched based on the MAC
 * address and FID/VID fields provided in @data, using the same format as
 * an L2 table entry. Address-based methods either read a specific entry
 * (%RTL8365MB_TABLE_L2_METHOD_ADDR) or iterate over valid entries starting
 * from @addr (%RTL8365MB_TABLE_L2_METHOD_ADDR_NEXT and variants). When using
 * %RTL8365MB_TABLE_L2_METHOD_ADDR_NEXT_UC_PORT, only entries associated with
 * the specified @port are considered.
 *
 * On successful L2 operations, @addr is updated with the matched table address
 * or allocated entry address. If no matching entry is found, or if an L2 write
 * operation fails (e.g., due to a full table during addition or a missing entry
 * during deletion), %-ENOENT is returned and @addr remains unchanged. It is the
 * caller's responsibility to map the returned error to the appropriate
 * semantic error.
 *
 * @size must match the size of the target table entry, expressed in 16-bit
 * words.
 *
 * Return: 0 on success, or a negative error code on failure.
 */
int rtl8365mb_table_query(struct realtek_priv *priv,
			  enum rtl8365mb_table table,
			  enum rtl8365mb_table_op op, u16 *addr,
			  enum rtl8365mb_table_l2_method method,
			  u16 port, u16 *data, size_t size);

#endif /* _REALTEK_RTL8365MB_TABLE_H */