diff mbox series

[net-next,v2] net: ti: icssg-prueth: Add multicast filtering support

Message ID 20240604114402.1835973-1-danishanwar@ti.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [net-next,v2] net: ti: icssg-prueth: Add multicast filtering support | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 8 this patch: 8
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 2 maintainers not CCed: kuba@kernel.org edumazet@google.com
netdev/build_clang success Errors and warnings before: 8 this patch: 8
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 8 this patch: 8
netdev/checkpatch warning WARNING: line length of 83 exceeds 80 columns
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-06-04--18-00 (tests: 1045)

Commit Message

MD Danish Anwar June 4, 2024, 11:44 a.m. UTC
Add multicast filtering support for ICSSG Driver.

The driver will keep a copy of multicast addresses in emac->mcast_list.
This list will be kept in sync with the netdev list and to add / del
multicast address icssg_prueth_mac_add_mcast / icssg_prueth_mac_del_mcast
APIs will be called.

To add a mac_address for a port, driver need to call icssg_fdb_add_del()
and pass the mac_address and BIT(port_id) to the API. The ICSSG firmware
will then configure the rules and allow filtering.

If a mac_address is added to port0 and the same mac_address needs to be
added for port1, driver needs to pass BIT(port0) | BIT(port1) to the
icssg_fdb_add_del() API. If driver just pass BIT(port1) then the entry for
port0 will be overwritten / lost. This is a design constraint on the
firmware side.

To overcome this in the driver, to add any mac_address for let's say portX
driver first checks if the same mac_address is already added for any other
port. If yes driver calls icssg_fdb_add_del() with BIT(portX) |
BIT(other_existing_port). If not, driver calls icssg_fdb_add_del() with
BIT(portX).

The same thing is applicable for deleting mac_addresses as well. This
logic is in icssg_prueth_mac_add_mcast / icssg_prueth_mac_del_mcast APIs.

Signed-off-by: MD Danish Anwar <danishanwar@ti.com>
---
v1 -> v2:
*) Rebased on latest net-next/main.

NOTE: This series can be applied cleanly on the tip of net-next/main. This
series doesn't depend on any other ICSSG driver related series that is
floating around in netdev.

v1 https://lore.kernel.org/all/20240516091752.2969092-1-danishanwar@ti.com/

 drivers/net/ethernet/ti/icssg/icssg_prueth.c | 50 ++++++++++++++++++--
 drivers/net/ethernet/ti/icssg/icssg_prueth.h |  3 ++
 2 files changed, 49 insertions(+), 4 deletions(-)


base-commit: 2589d668e1a6ebe85329f1054cdad13647deac06

Comments

Wojciech Drewek June 4, 2024, 2:49 p.m. UTC | #1
On 04.06.2024 13:44, MD Danish Anwar wrote:
> Add multicast filtering support for ICSSG Driver.
> 
> The driver will keep a copy of multicast addresses in emac->mcast_list.
> This list will be kept in sync with the netdev list and to add / del
> multicast address icssg_prueth_mac_add_mcast / icssg_prueth_mac_del_mcast
> APIs will be called.
> 
> To add a mac_address for a port, driver need to call icssg_fdb_add_del()
> and pass the mac_address and BIT(port_id) to the API. The ICSSG firmware
> will then configure the rules and allow filtering.
> 
> If a mac_address is added to port0 and the same mac_address needs to be
> added for port1, driver needs to pass BIT(port0) | BIT(port1) to the
> icssg_fdb_add_del() API. If driver just pass BIT(port1) then the entry for
> port0 will be overwritten / lost. This is a design constraint on the
> firmware side.
> 
> To overcome this in the driver, to add any mac_address for let's say portX
> driver first checks if the same mac_address is already added for any other
> port. If yes driver calls icssg_fdb_add_del() with BIT(portX) |
> BIT(other_existing_port). If not, driver calls icssg_fdb_add_del() with
> BIT(portX).
> 
> The same thing is applicable for deleting mac_addresses as well. This
> logic is in icssg_prueth_mac_add_mcast / icssg_prueth_mac_del_mcast APIs.
> 
> Signed-off-by: MD Danish Anwar <danishanwar@ti.com>
> ---
> v1 -> v2:
> *) Rebased on latest net-next/main.
> 
> NOTE: This series can be applied cleanly on the tip of net-next/main. This
> series doesn't depend on any other ICSSG driver related series that is
> floating around in netdev.
> 
> v1 https://lore.kernel.org/all/20240516091752.2969092-1-danishanwar@ti.com/
> 
>  drivers/net/ethernet/ti/icssg/icssg_prueth.c | 50 ++++++++++++++++++--
>  drivers/net/ethernet/ti/icssg/icssg_prueth.h |  3 ++
>  2 files changed, 49 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/net/ethernet/ti/icssg/icssg_prueth.c b/drivers/net/ethernet/ti/icssg/icssg_prueth.c
> index 6e65aa0977d4..03dd49f0afb7 100644
> --- a/drivers/net/ethernet/ti/icssg/icssg_prueth.c
> +++ b/drivers/net/ethernet/ti/icssg/icssg_prueth.c
> @@ -439,6 +439,37 @@ const struct icss_iep_clockops prueth_iep_clockops = {
>  	.perout_enable = prueth_perout_enable,
>  };
>  
> +static int icssg_prueth_mac_add_mcast(struct net_device *ndev, const u8 *addr)
> +{
> +	struct prueth_emac *emac = netdev_priv(ndev);
> +	int port_mask = BIT(emac->port_id);
> +
> +	port_mask |= icssg_fdb_lookup(emac, addr, 0);
> +	icssg_fdb_add_del(emac, addr, 0, port_mask, true);
> +	icssg_vtbl_modify(emac, 0, port_mask, port_mask, true);
> +
> +	return 0;
> +}
> +
> +static int icssg_prueth_mac_del_mcast(struct net_device *ndev, const u8 *addr)
> +{
> +	struct prueth_emac *emac = netdev_priv(ndev);
> +	int port_mask = BIT(emac->port_id);
> +	int other_port_mask;
> +
> +	other_port_mask = port_mask ^ icssg_fdb_lookup(emac, addr, 0);
> +
> +	icssg_fdb_add_del(emac, addr, 0, port_mask, false);
> +	icssg_vtbl_modify(emac, 0, port_mask, port_mask, false);
> +
> +	if (other_port_mask) {
> +		icssg_fdb_add_del(emac, addr, 0, other_port_mask, true);
> +		icssg_vtbl_modify(emac, 0, other_port_mask, other_port_mask, true);
> +	}
> +
> +	return 0;
> +}
> +
>  /**
>   * emac_ndo_open - EMAC device open
>   * @ndev: network adapter device
> @@ -547,6 +578,8 @@ static int emac_ndo_open(struct net_device *ndev)
>  
>  	prueth->emacs_initialized++;
>  
> +	__hw_addr_init(&emac->mcast_list);
> +
>  	queue_work(system_long_wq, &emac->stats_work.work);
>  
>  	return 0;
> @@ -599,6 +632,9 @@ static int emac_ndo_stop(struct net_device *ndev)
>  
>  	icssg_class_disable(prueth->miig_rt, prueth_emac_slice(emac));
>  
> +	__dev_mc_unsync(ndev, icssg_prueth_mac_del_mcast);
> +	__hw_addr_init(&emac->mcast_list);
> +
>  	atomic_set(&emac->tdown_cnt, emac->tx_ch_num);
>  	/* ensure new tdown_cnt value is visible */
>  	smp_mb__after_atomic();
> @@ -675,10 +711,15 @@ static void emac_ndo_set_rx_mode_work(struct work_struct *work)
>  		return;
>  	}
>  
> -	if (!netdev_mc_empty(ndev)) {
> -		emac_set_port_state(emac, ICSSG_EMAC_PORT_MC_FLOODING_ENABLE);
> -		return;
> -	}
> +	/* make a mc list copy */
> +
> +	netif_addr_lock_bh(ndev);
> +	__hw_addr_sync(&emac->mcast_list, &ndev->mc, ndev->addr_len);
> +	netif_addr_unlock_bh(ndev);
> +
> +	__hw_addr_sync_dev(&emac->mcast_list, ndev,
> +			   icssg_prueth_mac_add_mcast,
> +			   icssg_prueth_mac_del_mcast);

Is there a reason __dev_mc_sync can't be used here?
net_device has mc list already, no need to keep your own list
in prueth_emac.

>  }
>  
>  /**
> @@ -767,6 +808,7 @@ static int prueth_netdev_init(struct prueth *prueth,
>  	SET_NETDEV_DEV(ndev, prueth->dev);
>  	spin_lock_init(&emac->lock);
>  	mutex_init(&emac->cmd_lock);
> +	__hw_addr_init(&emac->mcast_list);
>  
>  	emac->phy_node = of_parse_phandle(eth_node, "phy-handle", 0);
>  	if (!emac->phy_node && !of_phy_is_fixed_link(eth_node)) {
> diff --git a/drivers/net/ethernet/ti/icssg/icssg_prueth.h b/drivers/net/ethernet/ti/icssg/icssg_prueth.h
> index 5eeeccb73665..2bfda26b5901 100644
> --- a/drivers/net/ethernet/ti/icssg/icssg_prueth.h
> +++ b/drivers/net/ethernet/ti/icssg/icssg_prueth.h
> @@ -155,6 +155,9 @@ struct prueth_emac {
>  	unsigned int tx_ts_enabled : 1;
>  	unsigned int half_duplex : 1;
>  
> +	/* List for storing multicast addresses */
> +	struct netdev_hw_addr_list mcast_list;
> +
>  	/* DMA related */
>  	struct prueth_tx_chn tx_chns[PRUETH_MAX_TX_QUEUES];
>  	struct completion tdown_complete;
> 
> base-commit: 2589d668e1a6ebe85329f1054cdad13647deac06
MD Danish Anwar June 5, 2024, 9:20 a.m. UTC | #2
Hi Wojciech,

On 04/06/24 8:19 pm, Wojciech Drewek wrote:
> 
> 
> On 04.06.2024 13:44, MD Danish Anwar wrote:
>> Add multicast filtering support for ICSSG Driver.
>>
>> The driver will keep a copy of multicast addresses in emac->mcast_list.
>> This list will be kept in sync with the netdev list and to add / del
>> multicast address icssg_prueth_mac_add_mcast / icssg_prueth_mac_del_mcast
>> APIs will be called.
>>
>> To add a mac_address for a port, driver need to call icssg_fdb_add_del()
>> and pass the mac_address and BIT(port_id) to the API. The ICSSG firmware
>> will then configure the rules and allow filtering.
>>
>> If a mac_address is added to port0 and the same mac_address needs to be
>> added for port1, driver needs to pass BIT(port0) | BIT(port1) to the
>> icssg_fdb_add_del() API. If driver just pass BIT(port1) then the entry for
>> port0 will be overwritten / lost. This is a design constraint on the
>> firmware side.
>>
>> To overcome this in the driver, to add any mac_address for let's say portX
>> driver first checks if the same mac_address is already added for any other
>> port. If yes driver calls icssg_fdb_add_del() with BIT(portX) |
>> BIT(other_existing_port). If not, driver calls icssg_fdb_add_del() with
>> BIT(portX).
>>
>> The same thing is applicable for deleting mac_addresses as well. This
>> logic is in icssg_prueth_mac_add_mcast / icssg_prueth_mac_del_mcast APIs.
>>
>> Signed-off-by: MD Danish Anwar <danishanwar@ti.com>
>> ---
>> v1 -> v2:
>> *) Rebased on latest net-next/main.
>>
>> NOTE: This series can be applied cleanly on the tip of net-next/main. This
>> series doesn't depend on any other ICSSG driver related series that is
>> floating around in netdev.
>>
>> v1 https://lore.kernel.org/all/20240516091752.2969092-1-danishanwar@ti.com/
>>
>>  drivers/net/ethernet/ti/icssg/icssg_prueth.c | 50 ++++++++++++++++++--
>>  drivers/net/ethernet/ti/icssg/icssg_prueth.h |  3 ++
>>  2 files changed, 49 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/ti/icssg/icssg_prueth.c b/drivers/net/ethernet/ti/icssg/icssg_prueth.c
>> index 6e65aa0977d4..03dd49f0afb7 100644
>> --- a/drivers/net/ethernet/ti/icssg/icssg_prueth.c
>> +++ b/drivers/net/ethernet/ti/icssg/icssg_prueth.c
>> @@ -439,6 +439,37 @@ const struct icss_iep_clockops prueth_iep_clockops = {
>>  	.perout_enable = prueth_perout_enable,
>>  };
>>  
>> +static int icssg_prueth_mac_add_mcast(struct net_device *ndev, const u8 *addr)
>> +{
>> +	struct prueth_emac *emac = netdev_priv(ndev);
>> +	int port_mask = BIT(emac->port_id);
>> +
>> +	port_mask |= icssg_fdb_lookup(emac, addr, 0);
>> +	icssg_fdb_add_del(emac, addr, 0, port_mask, true);
>> +	icssg_vtbl_modify(emac, 0, port_mask, port_mask, true);
>> +
>> +	return 0;
>> +}
>> +
>> +static int icssg_prueth_mac_del_mcast(struct net_device *ndev, const u8 *addr)
>> +{
>> +	struct prueth_emac *emac = netdev_priv(ndev);
>> +	int port_mask = BIT(emac->port_id);
>> +	int other_port_mask;
>> +
>> +	other_port_mask = port_mask ^ icssg_fdb_lookup(emac, addr, 0);
>> +
>> +	icssg_fdb_add_del(emac, addr, 0, port_mask, false);
>> +	icssg_vtbl_modify(emac, 0, port_mask, port_mask, false);
>> +
>> +	if (other_port_mask) {
>> +		icssg_fdb_add_del(emac, addr, 0, other_port_mask, true);
>> +		icssg_vtbl_modify(emac, 0, other_port_mask, other_port_mask, true);
>> +	}
>> +
>> +	return 0;
>> +}
>> +
>>  /**
>>   * emac_ndo_open - EMAC device open
>>   * @ndev: network adapter device
>> @@ -547,6 +578,8 @@ static int emac_ndo_open(struct net_device *ndev)
>>  
>>  	prueth->emacs_initialized++;
>>  
>> +	__hw_addr_init(&emac->mcast_list);
>> +
>>  	queue_work(system_long_wq, &emac->stats_work.work);
>>  
>>  	return 0;
>> @@ -599,6 +632,9 @@ static int emac_ndo_stop(struct net_device *ndev)
>>  
>>  	icssg_class_disable(prueth->miig_rt, prueth_emac_slice(emac));
>>  
>> +	__dev_mc_unsync(ndev, icssg_prueth_mac_del_mcast);
>> +	__hw_addr_init(&emac->mcast_list);
>> +
>>  	atomic_set(&emac->tdown_cnt, emac->tx_ch_num);
>>  	/* ensure new tdown_cnt value is visible */
>>  	smp_mb__after_atomic();
>> @@ -675,10 +711,15 @@ static void emac_ndo_set_rx_mode_work(struct work_struct *work)
>>  		return;
>>  	}
>>  
>> -	if (!netdev_mc_empty(ndev)) {
>> -		emac_set_port_state(emac, ICSSG_EMAC_PORT_MC_FLOODING_ENABLE);
>> -		return;
>> -	}
>> +	/* make a mc list copy */
>> +
>> +	netif_addr_lock_bh(ndev);
>> +	__hw_addr_sync(&emac->mcast_list, &ndev->mc, ndev->addr_len);
>> +	netif_addr_unlock_bh(ndev);
>> +
>> +	__hw_addr_sync_dev(&emac->mcast_list, ndev,
>> +			   icssg_prueth_mac_add_mcast,
>> +			   icssg_prueth_mac_del_mcast);
> 
> Is there a reason __dev_mc_sync can't be used here?
> net_device has mc list already, no need to keep your own list
> in prueth_emac.

I checked the code and __dev_mc_sync() can be used here. No need for
keeping local list as you pointed out. I will drop this and re post the
patch.

Thanks for the review.

> 
>>  }
>>  
>>  /**
>> @@ -767,6 +808,7 @@ static int prueth_netdev_init(struct prueth *prueth,
>>  	SET_NETDEV_DEV(ndev, prueth->dev);
>>  	spin_lock_init(&emac->lock);
>>  	mutex_init(&emac->cmd_lock);
>> +	__hw_addr_init(&emac->mcast_list);
>>  
>>  	emac->phy_node = of_parse_phandle(eth_node, "phy-handle", 0);
>>  	if (!emac->phy_node && !of_phy_is_fixed_link(eth_node)) {
>> diff --git a/drivers/net/ethernet/ti/icssg/icssg_prueth.h b/drivers/net/ethernet/ti/icssg/icssg_prueth.h
>> index 5eeeccb73665..2bfda26b5901 100644
>> --- a/drivers/net/ethernet/ti/icssg/icssg_prueth.h
>> +++ b/drivers/net/ethernet/ti/icssg/icssg_prueth.h
>> @@ -155,6 +155,9 @@ struct prueth_emac {
>>  	unsigned int tx_ts_enabled : 1;
>>  	unsigned int half_duplex : 1;
>>  
>> +	/* List for storing multicast addresses */
>> +	struct netdev_hw_addr_list mcast_list;
>> +
>>  	/* DMA related */
>>  	struct prueth_tx_chn tx_chns[PRUETH_MAX_TX_QUEUES];
>>  	struct completion tdown_complete;
>>
>> base-commit: 2589d668e1a6ebe85329f1054cdad13647deac06
diff mbox series

Patch

diff --git a/drivers/net/ethernet/ti/icssg/icssg_prueth.c b/drivers/net/ethernet/ti/icssg/icssg_prueth.c
index 6e65aa0977d4..03dd49f0afb7 100644
--- a/drivers/net/ethernet/ti/icssg/icssg_prueth.c
+++ b/drivers/net/ethernet/ti/icssg/icssg_prueth.c
@@ -439,6 +439,37 @@  const struct icss_iep_clockops prueth_iep_clockops = {
 	.perout_enable = prueth_perout_enable,
 };
 
+static int icssg_prueth_mac_add_mcast(struct net_device *ndev, const u8 *addr)
+{
+	struct prueth_emac *emac = netdev_priv(ndev);
+	int port_mask = BIT(emac->port_id);
+
+	port_mask |= icssg_fdb_lookup(emac, addr, 0);
+	icssg_fdb_add_del(emac, addr, 0, port_mask, true);
+	icssg_vtbl_modify(emac, 0, port_mask, port_mask, true);
+
+	return 0;
+}
+
+static int icssg_prueth_mac_del_mcast(struct net_device *ndev, const u8 *addr)
+{
+	struct prueth_emac *emac = netdev_priv(ndev);
+	int port_mask = BIT(emac->port_id);
+	int other_port_mask;
+
+	other_port_mask = port_mask ^ icssg_fdb_lookup(emac, addr, 0);
+
+	icssg_fdb_add_del(emac, addr, 0, port_mask, false);
+	icssg_vtbl_modify(emac, 0, port_mask, port_mask, false);
+
+	if (other_port_mask) {
+		icssg_fdb_add_del(emac, addr, 0, other_port_mask, true);
+		icssg_vtbl_modify(emac, 0, other_port_mask, other_port_mask, true);
+	}
+
+	return 0;
+}
+
 /**
  * emac_ndo_open - EMAC device open
  * @ndev: network adapter device
@@ -547,6 +578,8 @@  static int emac_ndo_open(struct net_device *ndev)
 
 	prueth->emacs_initialized++;
 
+	__hw_addr_init(&emac->mcast_list);
+
 	queue_work(system_long_wq, &emac->stats_work.work);
 
 	return 0;
@@ -599,6 +632,9 @@  static int emac_ndo_stop(struct net_device *ndev)
 
 	icssg_class_disable(prueth->miig_rt, prueth_emac_slice(emac));
 
+	__dev_mc_unsync(ndev, icssg_prueth_mac_del_mcast);
+	__hw_addr_init(&emac->mcast_list);
+
 	atomic_set(&emac->tdown_cnt, emac->tx_ch_num);
 	/* ensure new tdown_cnt value is visible */
 	smp_mb__after_atomic();
@@ -675,10 +711,15 @@  static void emac_ndo_set_rx_mode_work(struct work_struct *work)
 		return;
 	}
 
-	if (!netdev_mc_empty(ndev)) {
-		emac_set_port_state(emac, ICSSG_EMAC_PORT_MC_FLOODING_ENABLE);
-		return;
-	}
+	/* make a mc list copy */
+
+	netif_addr_lock_bh(ndev);
+	__hw_addr_sync(&emac->mcast_list, &ndev->mc, ndev->addr_len);
+	netif_addr_unlock_bh(ndev);
+
+	__hw_addr_sync_dev(&emac->mcast_list, ndev,
+			   icssg_prueth_mac_add_mcast,
+			   icssg_prueth_mac_del_mcast);
 }
 
 /**
@@ -767,6 +808,7 @@  static int prueth_netdev_init(struct prueth *prueth,
 	SET_NETDEV_DEV(ndev, prueth->dev);
 	spin_lock_init(&emac->lock);
 	mutex_init(&emac->cmd_lock);
+	__hw_addr_init(&emac->mcast_list);
 
 	emac->phy_node = of_parse_phandle(eth_node, "phy-handle", 0);
 	if (!emac->phy_node && !of_phy_is_fixed_link(eth_node)) {
diff --git a/drivers/net/ethernet/ti/icssg/icssg_prueth.h b/drivers/net/ethernet/ti/icssg/icssg_prueth.h
index 5eeeccb73665..2bfda26b5901 100644
--- a/drivers/net/ethernet/ti/icssg/icssg_prueth.h
+++ b/drivers/net/ethernet/ti/icssg/icssg_prueth.h
@@ -155,6 +155,9 @@  struct prueth_emac {
 	unsigned int tx_ts_enabled : 1;
 	unsigned int half_duplex : 1;
 
+	/* List for storing multicast addresses */
+	struct netdev_hw_addr_list mcast_list;
+
 	/* DMA related */
 	struct prueth_tx_chn tx_chns[PRUETH_MAX_TX_QUEUES];
 	struct completion tdown_complete;