Skip to content

Commit 1cf3299

Browse files
vladimirolteandavem330
authored andcommitted
net: dsa: felix: Allow unknown unicast traffic towards the CPU port module
Compared to other DSA switches, in the Ocelot cores, the RX filtering is a much more important concern. Firstly, the primary use case for Ocelot is non-DSA, so there isn't any secondary Ethernet MAC [the DSA master's one] to implicitly drop frames having a DMAC we are not interested in. So the switch driver itself needs to install FDB entries towards the CPU port module (PGID_CPU) for the MAC address of each switch port, in each VLAN installed on the port. Every address that is not whitelisted is implicitly dropped. This is in order to achieve a behavior similar to N standalone net devices. Secondly, even in the secondary use case of DSA, such as illustrated by Felix with the NPI port mode, that secondary Ethernet MAC is present, but its RX filter is bypassed. This is because the DSA tags themselves are placed before Ethernet, so the DMAC that the switch ports see is not seen by the DSA master too (since it's shifter to the right). So RX filtering is pretty important. A good RX filter won't bother the CPU in case the switch port receives a frame that it's not interested in, and there exists no other line of defense. Ocelot is pretty strict when it comes to RX filtering: non-IP multicast and broadcast traffic is allowed to go to the CPU port module, but unknown unicast isn't. This means that traffic reception for any other MAC addresses than the ones configured on each switch port net device won't work. This includes use cases such as macvlan or bridging with a non-Ocelot (so-called "foreign") interface. But this seems to be fine for the scenarios that the Linux system embedded inside an Ocelot switch is intended for - it is simply not interested in unknown unicast traffic, as explained in Allan Nielsen's presentation [0]. On the other hand, the Felix DSA switch is integrated in more general-purpose Linux systems, so it can't afford to drop that sort of traffic in hardware, even if it will end up doing so later, in software. Actually, unknown unicast means more for Felix than it does for Ocelot. Felix doesn't attempt to perform the whitelisting of switch port MAC addresses towards PGID_CPU at all, mainly because it is too complicated to be feasible: while the MAC addresses are unique in Ocelot, by default in DSA all ports are equal and inherited from the DSA master. This adds into account the question of reference counting MAC addresses (delayed ocelot_mact_forget), not to mention reference counting for the VLAN IDs that those MAC addresses are installed in. This reference counting should be done in the DSA core, and the fact that it wasn't needed so far is due to the fact that the other DSA switches don't have the DSA tag placed before Ethernet, so the DSA master is able to whitelist the MAC addresses in hardware. So this means that even regular traffic termination on a Felix switch port happens through flooding (because neither Felix nor Ocelot learn source MAC addresses from CPU-injected frames). So far we've explained that whitelisting towards PGID_CPU: - helps to reduce the likelihood of spamming the CPU with frames it won't process very far anyway - is implemented in the ocelot driver - is sufficient for the ocelot use cases - is not feasible in DSA - breaks use cases in DSA, in the current status (whitelisting enabled but no MAC address whitelisted) So the proposed patch allows unknown unicast frames to be sent to the CPU port module. This is done for the Felix DSA driver only, as Ocelot seems to be happy without it. [0]: https://www.youtube.com/watch?v=B1HhxEcU7Jg Suggested-by: Allan W. Nielsen <allan.nielsen@microchip.com> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com> Reviewed-by: Allan W. Nielsen <allan.nielsen@microchip.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 69df578 commit 1cf3299

3 files changed

Lines changed: 69 additions & 10 deletions

File tree

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,15 @@ static int felix_setup(struct dsa_switch *ds)
523523
OCELOT_TAG_PREFIX_LONG);
524524
}
525525

526+
/* Include the CPU port module in the forwarding mask for unknown
527+
* unicast - the hardware default value for ANA_FLOODING_FLD_UNICAST
528+
* excludes BIT(ocelot->num_phys_ports), and so does ocelot_init, since
529+
* Ocelot relies on whitelisting MAC addresses towards PGID_CPU.
530+
*/
531+
ocelot_write_rix(ocelot,
532+
ANA_PGID_PGID_PGID(GENMASK(ocelot->num_phys_ports, 0)),
533+
ANA_PGID_PGID, PGID_UC);
534+
526535
/* It looks like the MAC/PCS interrupt register - PM0_IEVENT (0x8040)
527536
* isn't instantiated for the Felix PF.
528537
* In-band AN may take a few ms to complete, so we need to poll.

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,6 @@
2828
#include "ocelot_tc.h"
2929
#include "ocelot_ptp.h"
3030

31-
#define PGID_AGGR 64
32-
#define PGID_SRC 80
33-
34-
/* Reserved PGIDs */
35-
#define PGID_CPU (PGID_AGGR - 5)
36-
#define PGID_UC (PGID_AGGR - 4)
37-
#define PGID_MC (PGID_AGGR - 3)
38-
#define PGID_MCIPV4 (PGID_AGGR - 2)
39-
#define PGID_MCIPV6 (PGID_AGGR - 1)
40-
4131
#define OCELOT_BUFFER_CELL_SZ 60
4232

4333
#define OCELOT_STATS_CHECK_DELAY (2 * HZ)

‎include/soc/mscc/ocelot.h‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,66 @@
1111
#include <linux/regmap.h>
1212
#include <net/dsa.h>
1313

14+
/* Port Group IDs (PGID) are masks of destination ports.
15+
*
16+
* For L2 forwarding, the switch performs 3 lookups in the PGID table for each
17+
* frame, and forwards the frame to the ports that are present in the logical
18+
* AND of all 3 PGIDs.
19+
*
20+
* These PGID lookups are:
21+
* - In one of PGID[0-63]: for the destination masks. There are 2 paths by
22+
* which the switch selects a destination PGID:
23+
* - The {DMAC, VID} is present in the MAC table. In that case, the
24+
* destination PGID is given by the DEST_IDX field of the MAC table entry
25+
* that matched.
26+
* - The {DMAC, VID} is not present in the MAC table (it is unknown). The
27+
* frame is disseminated as being either unicast, multicast or broadcast,
28+
* and according to that, the destination PGID is chosen as being the
29+
* value contained by ANA_FLOODING_FLD_UNICAST,
30+
* ANA_FLOODING_FLD_MULTICAST or ANA_FLOODING_FLD_BROADCAST.
31+
* The destination PGID can be an unicast set: the first PGIDs, 0 to
32+
* ocelot->num_phys_ports - 1, or a multicast set: the PGIDs from
33+
* ocelot->num_phys_ports to 63. By convention, a unicast PGID corresponds to
34+
* a physical port and has a single bit set in the destination ports mask:
35+
* that corresponding to the port number itself. In contrast, a multicast
36+
* PGID will have potentially more than one single bit set in the destination
37+
* ports mask.
38+
* - In one of PGID[64-79]: for the aggregation mask. The switch classifier
39+
* dissects each frame and generates a 4-bit Link Aggregation Code which is
40+
* used for this second PGID table lookup. The goal of link aggregation is to
41+
* hash multiple flows within the same LAG on to different destination ports.
42+
* The first lookup will result in a PGID with all the LAG members present in
43+
* the destination ports mask, and the second lookup, by Link Aggregation
44+
* Code, will ensure that each flow gets forwarded only to a single port out
45+
* of that mask (there are no duplicates).
46+
* - In one of PGID[80-90]: for the source mask. The third time, the PGID table
47+
* is indexed with the ingress port (plus 80). These PGIDs answer the
48+
* question "is port i allowed to forward traffic to port j?" If yes, then
49+
* BIT(j) of PGID 80+i will be found set. The third PGID lookup can be used
50+
* to enforce the L2 forwarding matrix imposed by e.g. a Linux bridge.
51+
*/
52+
53+
/* Reserve some destination PGIDs at the end of the range:
54+
* PGID_CPU: used for whitelisting certain MAC addresses, such as the addresses
55+
* of the switch port net devices, towards the CPU port module.
56+
* PGID_UC: the flooding destinations for unknown unicast traffic.
57+
* PGID_MC: the flooding destinations for broadcast and non-IP multicast
58+
* traffic.
59+
* PGID_MCIPV4: the flooding destinations for IPv4 multicast traffic.
60+
* PGID_MCIPV6: the flooding destinations for IPv6 multicast traffic.
61+
*/
62+
#define PGID_CPU 59
63+
#define PGID_UC 60
64+
#define PGID_MC 61
65+
#define PGID_MCIPV4 62
66+
#define PGID_MCIPV6 63
67+
68+
/* Aggregation PGIDs, one per Link Aggregation Code */
69+
#define PGID_AGGR 64
70+
71+
/* Source PGIDs, one per physical port */
72+
#define PGID_SRC 80
73+
1474
#define IFH_INJ_BYPASS BIT(31)
1575
#define IFH_INJ_POP_CNT_DISABLE (3 << 28)
1676

0 commit comments

Comments
 (0)