Clamp l2_filter_count to 1 to `HW_ATL2_MAC_MAX - l2_filters_base_index`. One slot is required for the MAC address. The validation of the firmware supplied l2_filters_base_index ensures that at least 1 slot is avialable. The upper bound ensures that only valid L2 filter slots are programmed. Fixes: 6c1ca112a6e4 ("net: atlantic: fix AQC113 HW init: ART, L2 filter slot, MAC address") Cc: stable@vger.kernel.org Signed-off-by: Janne Grunau --- drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_utils_fw.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_utils_fw.c b/drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_utils_fw.c index dc9b2ef4640b..38e9dd0477ed 100644 --- a/drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_utils_fw.c +++ b/drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_utils_fw.c @@ -4,6 +4,7 @@ */ #include +#include #include "aq_hw.h" #include "aq_hw_utils.h" @@ -628,7 +629,8 @@ int hw_atl2_utils_get_filter_caps(struct aq_hw_s *self) priv->l2_filters_base_index = filter_caps.l2_filters_base_index; if (priv->l2_filters_base_index >= HW_ATL2_MAC_MAX) priv->l2_filters_base_index = HW_ATL2_MAC_UC; - priv->l2_filter_count = filter_caps.l2_filter_count; + priv->l2_filter_count = clamp(filter_caps.l2_filter_count, 1U, + HW_ATL2_MAC_MAX - priv->l2_filters_base_index); priv->etype_filter_base_index = filter_caps.ethertype_filter_base_index; priv->etype_filter_count = filter_caps.ethertype_filter_count; priv->etype_filter_tag_top = -- 2.56.1 Since commit 6c1ca112a6e4 ("net: atlantic: fix AQC113 HW init: ART, L2 filter slot, MAC address") hw_atl2_hw_multicast_list_set() uses L2 filter slots based on the firmware-assigned L2 filter base index. On Apple silicon systems with AQC113 the firmware returns `l2_filters_base_index = 9` and `l2_filter_count = 29` which is less than AQ_HW_MULTICAST_ADDRESS_MAX (32). Add a new `struct aq_hw_ops` function pointer hw_get_multicast_address_max to query the number of available L2 filter slots. hw_atl_a0 and hw_atl_b0 will return AQ_HW_MULTICAST_ADDRESS_MAX and hw_atl2 may return a smaller value based on l2_filter_count.. aq_nic_set_multicast_list() uses the number of available L2 filter slots to configure the packet filter to IFF_PROMISC and/or IFF_ALLMULTI based on the number of unicast and multicast addresses. Fixes: 6c1ca112a6e4 ("net: atlantic: fix AQC113 HW init: ART, L2 filter slot, MAC address") Cc: stable@vger.kernel.org Signed-off-by: Janne Grunau --- drivers/net/ethernet/aquantia/atlantic/aq_hw.h | 2 ++ drivers/net/ethernet/aquantia/atlantic/aq_nic.c | 9 ++++++--- drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_a0.c | 7 +++++++ drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_b0.c | 7 +++++++ drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c | 11 ++++++++++- 5 files changed, 32 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/aquantia/atlantic/aq_hw.h b/drivers/net/ethernet/aquantia/atlantic/aq_hw.h index 338c956ad1f7..98b37d025e67 100644 --- a/drivers/net/ethernet/aquantia/atlantic/aq_hw.h +++ b/drivers/net/ethernet/aquantia/atlantic/aq_hw.h @@ -374,6 +374,8 @@ struct aq_hw_ops { int (*hw_read_module_eeprom)(struct aq_hw_s *self, u8 dev_addr, u8 reg_start_addr, int len, u8 *data); + + unsigned int (*hw_get_multicast_address_max)(struct aq_hw_s *self); }; struct aq_fw_ops { diff --git a/drivers/net/ethernet/aquantia/atlantic/aq_nic.c b/drivers/net/ethernet/aquantia/atlantic/aq_nic.c index 42e0fe9248f2..8ef54be36037 100644 --- a/drivers/net/ethernet/aquantia/atlantic/aq_nic.c +++ b/drivers/net/ethernet/aquantia/atlantic/aq_nic.c @@ -976,11 +976,14 @@ int aq_nic_set_multicast_list(struct aq_nic_s *self, struct net_device *ndev) struct aq_nic_cfg_s *cfg = &self->aq_nic_cfg; unsigned int packet_filter = ndev->flags; struct netdev_hw_addr *ha = NULL; + unsigned int mc_address_max; unsigned int i = 0U; int err = 0; + mc_address_max = hw_ops->hw_get_multicast_address_max(self->aq_hw); + self->mc_list.count = 0; - if (netdev_uc_count(ndev) > AQ_HW_MULTICAST_ADDRESS_MAX) { + if (netdev_uc_count(ndev) > mc_address_max) { packet_filter |= IFF_PROMISC; } else { netdev_for_each_uc_addr(ha, ndev) { @@ -990,7 +993,7 @@ int aq_nic_set_multicast_list(struct aq_nic_s *self, struct net_device *ndev) cfg->is_mc_list_enabled = !!(packet_filter & IFF_MULTICAST); if (cfg->is_mc_list_enabled) { - if (i + netdev_mc_count(ndev) > AQ_HW_MULTICAST_ADDRESS_MAX) { + if (i + netdev_mc_count(ndev) > mc_address_max) { packet_filter |= IFF_ALLMULTI; } else { netdev_for_each_mc_addr(ha, ndev) { @@ -1000,7 +1003,7 @@ int aq_nic_set_multicast_list(struct aq_nic_s *self, struct net_device *ndev) } } - if (i > 0 && i <= AQ_HW_MULTICAST_ADDRESS_MAX) { + if (i > 0 && i <= mc_address_max) { self->mc_list.count = i; err = hw_ops->hw_multicast_list_set(self->aq_hw, self->mc_list.ar, diff --git a/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_a0.c b/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_a0.c index 8de2cdd09213..6bc187153a9c 100644 --- a/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_a0.c +++ b/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_a0.c @@ -944,6 +944,11 @@ static int hw_atl_a0_hw_fl3l4_set(struct aq_hw_s *self, return aq_hw_err_from_flags(self); } +static unsigned int hw_atl_a0_get_multicast_address_max(struct aq_hw_s *self) +{ + return AQ_HW_MULTICAST_ADDRESS_MAX; +} + const struct aq_hw_ops hw_atl_ops_a0 = { .hw_soft_reset = hw_atl_utils_soft_reset, .hw_prepare = hw_atl_utils_initfw, @@ -978,4 +983,6 @@ const struct aq_hw_ops hw_atl_ops_a0 = { .hw_get_regs = hw_atl_utils_hw_get_regs, .hw_get_hw_stats = hw_atl_utils_get_hw_stats, .hw_get_fw_version = hw_atl_utils_get_fw_version, + + .hw_get_multicast_address_max = hw_atl_a0_get_multicast_address_max, }; diff --git a/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_b0.c b/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_b0.c index 6c25ad264b19..639ec472aa0d 100644 --- a/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_b0.c +++ b/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_b0.c @@ -1777,6 +1777,11 @@ static int hw_atl_b0_read_module_eeprom(struct aq_hw_s *self, u8 dev_addr, return err; } +static unsigned int hw_atl_b0_get_multicast_address_max(struct aq_hw_s *self) +{ + return AQ_HW_MULTICAST_ADDRESS_MAX; +} + const struct aq_hw_ops hw_atl_ops_b0 = { .hw_soft_reset = hw_atl_utils_soft_reset, .hw_prepare = hw_atl_utils_initfw, @@ -1836,4 +1841,6 @@ const struct aq_hw_ops hw_atl_ops_b0 = { .hw_get_mac_temp = hw_atl_b0_get_mac_temp, .hw_read_module_eeprom = hw_atl_b0_read_module_eeprom, + + .hw_get_multicast_address_max = hw_atl_b0_get_multicast_address_max, }; diff --git a/drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c b/drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c index 25dd7150aaaf..b6d16ea1e670 100644 --- a/drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c +++ b/drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c @@ -777,7 +777,7 @@ static int hw_atl2_hw_multicast_list_set(struct aq_hw_s *self, struct aq_nic_cfg_s *cfg = self->aq_nic_cfg; int err = 0; - if (count > (HW_ATL2_MAC_MAX - HW_ATL2_MAC_MIN)) { + if (count > (priv->l2_filter_count - 1)) { err = -EBADRQC; goto err_exit; } @@ -1602,6 +1602,13 @@ static int hw_atl2_hw_vlan_ctrl(struct aq_hw_s *self, bool enable) return aq_hw_err_from_flags(self); } +static unsigned int hw_atl2_get_multicast_address_max(struct aq_hw_s *self) +{ + struct hw_atl2_priv *priv = self->priv; + + return min(priv->l2_filter_count - 1, AQ_HW_MULTICAST_ADDRESS_MAX); +} + const struct aq_hw_ops hw_atl2_ops = { .hw_soft_reset = hw_atl2_utils_soft_reset, .hw_prepare = hw_atl2_utils_initfw, @@ -1661,4 +1668,6 @@ const struct aq_hw_ops hw_atl2_ops = { .hw_get_clk_sel = hw_atl2_hw_get_clk_sel, .extract_hwts = NULL, .hw_extts_gpio_enable = NULL, + + .hw_get_multicast_address_max = hw_atl2_get_multicast_address_max, }; -- 2.56.1 hw_atl2_hw_packet_filter_set() wraps hw_atl_b0_hw_packet_filter_set() which has no concept of `l2_filters_base_index` and enables/disables filters from `HW_ATL_B0_MAC_MIN` (1) to `HW_ATL_B0_MAC_MAX` (33). After commit 6c1ca112a6e4 ("net: atlantic: fix AQC113 HW init: ART, L2 filter slot, MAC address") this may result in disabling filters set in hw_atl2.c including the l2 filter for the MAC address. This results in broken networking on Apple silicon systems with AQC113. The firmware in this systems report `l2_filters_base_index = 9`. Copy the formerly wrapped `hw_atl_b0_hw_packet_filter_set()` and modify it to handle this additional complexity on atl2 hardware. Fixes: 6c1ca112a6e4 ("net: atlantic: fix AQC113 HW init: ART, L2 filter slot, MAC address") Cc: stable@vger.kernel.org Signed-off-by: Janne Grunau --- .../ethernet/aquantia/atlantic/hw_atl/hw_atl_b0.c | 4 +-- .../ethernet/aquantia/atlantic/hw_atl/hw_atl_b0.h | 3 -- .../ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c | 36 +++++++++++++++++++++- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_b0.c b/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_b0.c index 639ec472aa0d..608ebad669c5 100644 --- a/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_b0.c +++ b/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_b0.c @@ -1038,8 +1038,8 @@ int hw_atl_b0_hw_irq_read(struct aq_hw_s *self, u64 *mask) #define IS_FILTER_ENABLED(_F_) ((packet_filter & (_F_)) ? 1U : 0U) -int hw_atl_b0_hw_packet_filter_set(struct aq_hw_s *self, - unsigned int packet_filter) +static int hw_atl_b0_hw_packet_filter_set(struct aq_hw_s *self, + unsigned int packet_filter) { struct aq_nic_cfg_s *cfg = self->aq_nic_cfg; unsigned int i = 0U; diff --git a/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_b0.h b/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_b0.h index 5298846dd9f7..35c43762c35a 100644 --- a/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_b0.h +++ b/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_b0.h @@ -69,7 +69,4 @@ int hw_atl_b0_hw_irq_enable(struct aq_hw_s *self, u64 mask); int hw_atl_b0_hw_irq_disable(struct aq_hw_s *self, u64 mask); int hw_atl_b0_hw_irq_read(struct aq_hw_s *self, u64 *mask); -int hw_atl_b0_hw_packet_filter_set(struct aq_hw_s *self, - unsigned int packet_filter); - #endif /* HW_ATL_B0_H */ diff --git a/drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c b/drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c index b6d16ea1e670..ddfec0fc9306 100644 --- a/drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c +++ b/drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c @@ -759,9 +759,43 @@ static int hw_atl2_hw_ring_tx_init(struct aq_hw_s *self, static int hw_atl2_hw_packet_filter_set(struct aq_hw_s *self, unsigned int packet_filter) { + struct aq_nic_cfg_s *cfg = self->aq_nic_cfg; + struct hw_atl2_priv *priv = self->priv; + u32 base_location = priv->l2_filters_base_index + 1; + unsigned int num_l2_filters = min_t(unsigned int, + HW_ATL2_MAC_MAX - base_location, + priv->l2_filter_count - 1); + unsigned int i = 0U; + u32 vlan_promisc; + u32 l2_promisc; + hw_atl2_hw_new_rx_filter_promisc(self, IS_FILTER_ENABLED(IFF_PROMISC)); - return hw_atl_b0_hw_packet_filter_set(self, packet_filter); + l2_promisc = IS_FILTER_ENABLED(IFF_PROMISC) || + !!(cfg->priv_flags & BIT(AQ_HW_LOOPBACK_DMA_NET)); + vlan_promisc = l2_promisc || cfg->is_vlan_force_promisc; + + hw_atl_rpfl2promiscuous_mode_en_set(self, l2_promisc); + + hw_atl_rpf_vlan_prom_mode_en_set(self, vlan_promisc); + + hw_atl_rpfl2multicast_flr_en_set(self, + IS_FILTER_ENABLED(IFF_ALLMULTI) && + IS_FILTER_ENABLED(IFF_MULTICAST), 0); + + hw_atl_rpfl2_accept_all_mc_packets_set(self, + IS_FILTER_ENABLED(IFF_ALLMULTI) && + IS_FILTER_ENABLED(IFF_MULTICAST)); + + hw_atl_rpfl2broadcast_en_set(self, IS_FILTER_ENABLED(IFF_BROADCAST)); + + for (i = 0; i < num_l2_filters; ++i) + hw_atl_rpfl2_uc_flr_en_set(self, + (cfg->is_mc_list_enabled && + (i < cfg->mc_list_count)) ? + 1U : 0U, base_location + i); + + return aq_hw_err_from_flags(self); } #undef IS_FILTER_ENABLED -- 2.56.1