Skip to content

Commit cf2f608

Browse files
HoratiuVulturdavem330
authored andcommitted
net: lan966x: Add support to offload the forwarding.
This patch adds basic support to offload in the HW the forwarding of the frames. The driver registers to the switchdev callbacks and implements the callbacks for attributes SWITCHDEV_ATTR_ID_PORT_STP_STATE and SWITCHDEV_ATTR_ID_BRIDGE_AGEING_TIME. It is not allowed to add a lan966x port to a bridge that contains a different interface than lan966x. Signed-off-by: Horatiu Vultur <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 571bb51 commit cf2f608

File tree

5 files changed

+354
-2
lines changed

5 files changed

+354
-2
lines changed

drivers/net/ethernet/microchip/lan966x/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ config LAN966X_SWITCH
22
tristate "Lan966x switch driver"
33
depends on HAS_IOMEM
44
depends on OF
5+
depends on NET_SWITCHDEV
56
select PHYLINK
67
select PACKING
78
help

drivers/net/ethernet/microchip/lan966x/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
obj-$(CONFIG_LAN966X_SWITCH) += lan966x-switch.o
77

88
lan966x-switch-objs := lan966x_main.o lan966x_phylink.o lan966x_port.o \
9-
lan966x_mac.o lan966x_ethtool.o
9+
lan966x_mac.o lan966x_ethtool.o lan966x_switchdev.o

drivers/net/ethernet/microchip/lan966x/lan966x_main.c

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,11 @@ static const struct net_device_ops lan966x_port_netdev_ops = {
355355
.ndo_get_port_parent_id = lan966x_port_get_parent_id,
356356
};
357357

358+
bool lan966x_netdevice_check(const struct net_device *dev)
359+
{
360+
return dev->netdev_ops == &lan966x_port_netdev_ops;
361+
}
362+
358363
static int lan966x_port_xtr_status(struct lan966x *lan966x, u8 grp)
359364
{
360365
return lan_rd(lan966x, QS_XTR_RD(grp));
@@ -491,6 +496,9 @@ static irqreturn_t lan966x_xtr_irq_handler(int irq, void *args)
491496

492497
skb->protocol = eth_type_trans(skb, dev);
493498

499+
if (lan966x->bridge_mask & BIT(src_port))
500+
skb->offload_fwd_mark = 1;
501+
494502
netif_rx_ni(skb);
495503
dev->stats.rx_bytes += len;
496504
dev->stats.rx_packets++;
@@ -934,7 +942,32 @@ static struct platform_driver lan966x_driver = {
934942
.of_match_table = lan966x_match,
935943
},
936944
};
937-
module_platform_driver(lan966x_driver);
945+
946+
static int __init lan966x_switch_driver_init(void)
947+
{
948+
int ret;
949+
950+
lan966x_register_notifier_blocks();
951+
952+
ret = platform_driver_register(&lan966x_driver);
953+
if (ret)
954+
goto err;
955+
956+
return 0;
957+
958+
err:
959+
lan966x_unregister_notifier_blocks();
960+
return ret;
961+
}
962+
963+
static void __exit lan966x_switch_driver_exit(void)
964+
{
965+
platform_driver_unregister(&lan966x_driver);
966+
lan966x_unregister_notifier_blocks();
967+
}
968+
969+
module_init(lan966x_switch_driver_init);
970+
module_exit(lan966x_switch_driver_exit);
938971

939972
MODULE_DESCRIPTION("Microchip LAN966X switch driver");
940973
MODULE_AUTHOR("Horatiu Vultur <[email protected]>");

drivers/net/ethernet/microchip/lan966x/lan966x_main.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ struct lan966x {
7575

7676
u8 base_mac[ETH_ALEN];
7777

78+
struct net_device *bridge;
79+
u16 bridge_mask;
80+
u16 bridge_fwd_mask;
81+
7882
struct list_head mac_entries;
7983
spinlock_t mac_lock; /* lock for mac_entries list */
8084

@@ -122,6 +126,11 @@ extern const struct phylink_mac_ops lan966x_phylink_mac_ops;
122126
extern const struct phylink_pcs_ops lan966x_phylink_pcs_ops;
123127
extern const struct ethtool_ops lan966x_ethtool_ops;
124128

129+
bool lan966x_netdevice_check(const struct net_device *dev);
130+
131+
void lan966x_register_notifier_blocks(void);
132+
void lan966x_unregister_notifier_blocks(void);
133+
125134
void lan966x_stats_get(struct net_device *dev,
126135
struct rtnl_link_stats64 *stats);
127136
int lan966x_stats_init(struct lan966x *lan966x);

0 commit comments

Comments
 (0)