[PATCH net-next v2 7/8] net: rpmsg-eth: Add support for multicast filtering

MD Danish Anwar
2025-09-02T09:08:50Z

Add support for multicast filtering for RPMSG ETH driver. Implement the
ndo_set_rx_mode callback as icve_set_rx_mode() API. rx_mode_workqueue is
initialized in rpmsg_eth_probe() and queued in rpmsg_eth_set_rx_mode().

Signed-off-by: MD Danish Anwar <danishanwar@ti.com>
---
drivers/net/ethernet/rpmsg_eth.c | 63 ++++++++++++++++++++++++++++++++
drivers/net/ethernet/rpmsg_eth.h | 12 ++++++
2 files changed, 75 insertions(+)

diff --git a/drivers/net/ethernet/rpmsg_eth.c b/drivers/net/ethernet/rpmsg_eth.c
index a2248e21cf22..e26b1d8f1752 100644
--- a/drivers/net/ethernet/rpmsg_eth.c
+++ b/drivers/net/ethernet/rpmsg_eth.c
@@ -67,6 +67,11 @@ static int create_request(struct rpmsg_eth_common *common,
ether_addr_copy(msg->req_msg.mac_addr.addr,
common->port->ndev->dev_addr);
break;
+ case RPMSG_ETH_REQ_ADD_MC_ADDR:
+ case RPMSG_ETH_REQ_DEL_MC_ADDR:
+ ether_addr_copy(msg->req_msg.mac_addr.addr,
+ common->mcast_addr);
+ break;
case RPMSG_ETH_NOTIFY_PORT_UP:
case RPMSG_ETH_NOTIFY_PORT_DOWN:
msg->msg_hdr.msg_type = RPMSG_ETH_NOTIFY_MSG;
@@ -118,6 +123,22 @@ static int rpmsg_eth_create_send_request(struct rpmsg_eth_common *common,
return ret;
}

+static int rpmsg_eth_add_mc_addr(struct net_device *ndev, const u8 *addr)
+{
+ struct rpmsg_eth_common *common = rpmsg_eth_ndev_to_common(ndev);
+
+ ether_addr_copy(common->mcast_addr, addr);
+ return rpmsg_eth_create_send_request(common, RPMSG_ETH_REQ_ADD_MC_ADDR, true);
+}
+
+static int rpmsg_eth_del_mc_addr(struct net_device *ndev, const u8 *addr)
+{
+ struct rpmsg_eth_common *common = rpmsg_eth_ndev_to_common(ndev);
+
+ ether_addr_copy(common->mcast_addr, addr);
+ return rpmsg_eth_create_send_request(common, RPMSG_ETH_REQ_DEL_MC_ADDR, true);
+}
+
static void rpmsg_eth_state_machine(struct work_struct *work)
{
struct delayed_work *dwork = to_delayed_work(work);
@@ -200,6 +221,10 @@ static int rpmsg_eth_rpmsg_cb(struct rpmsg_device *rpdev, void *data, int len,
break;
case RPMSG_ETH_RESP_SET_MAC_ADDR:
break;
+ case RPMSG_ETH_RESP_ADD_MC_ADDR:
+ case RPMSG_ETH_RESP_DEL_MC_ADDR:
+ complete(&common->sync_msg);
+ break;
}
break;
case RPMSG_ETH_NOTIFY_MSG:
@@ -399,10 +424,15 @@ static int rpmsg_eth_ndo_stop(struct net_device *ndev)

netif_carrier_off(port->ndev);

+ __dev_mc_unsync(ndev, rpmsg_eth_del_mc_addr);
+ __hw_addr_init(&common->mc_list);
+
cancel_delayed_work_sync(&common->state_work);
timer_delete_sync(&port->rx_timer);
napi_disable(&port->rx_napi);

+ cancel_work_sync(&common->rx_mode_work);
+
return 0;
}

@@ -459,10 +489,35 @@ static int rpmsg_eth_set_mac_address(struct net_device *ndev, void *addr)
return ret;
}

+static void rpmsg_eth_ndo_set_rx_mode_work(struct work_struct *work)
+{
+ struct rpmsg_eth_common *common;
+ struct net_device *ndev;
+
+ common = container_of(work, struct rpmsg_eth_common, rx_mode_work);
+ ndev = common->port->ndev;
+
+ /* make a mc list copy */
+ netif_addr_lock_bh(ndev);
+ __hw_addr_sync(&common->mc_list, &ndev->mc, ndev->addr_len);
+ netif_addr_unlock_bh(ndev);
+
+ __hw_addr_sync_dev(&common->mc_list, ndev, rpmsg_eth_add_mc_addr,
+ rpmsg_eth_del_mc_addr);
+}
+
+static void rpmsg_eth_set_rx_mode(struct net_device *ndev)
+{
+ struct rpmsg_eth_common *common = rpmsg_eth_ndev_to_common(ndev);
+
+ queue_work(common->cmd_wq, &common->rx_mode_work);
+}
+
static const struct net_device_ops rpmsg_eth_netdev_ops = {
.ndo_open = rpmsg_eth_ndo_open,
.ndo_stop = rpmsg_eth_ndo_stop,
.ndo_start_xmit = rpmsg_eth_start_xmit,
+ .ndo_set_rx_mode = rpmsg_eth_set_rx_mode,
.ndo_set_mac_address = rpmsg_eth_set_mac_address,
};

@@ -537,6 +592,13 @@ static int rpmsg_eth_probe(struct rpmsg_device *rpdev)
INIT_DELAYED_WORK(&common->state_work, rpmsg_eth_state_machine);
init_completion(&common->sync_msg);

+ __hw_addr_init(&common->mc_list);
+ INIT_WORK(&common->rx_mode_work, rpmsg_eth_ndo_set_rx_mode_work);
+ common->cmd_wq = create_singlethread_workqueue("rpmsg_eth_rx_work");
+ if (!common->cmd_wq) {
+ dev_err(dev, "Failure requesting workqueue\n");
+ return -ENOMEM;
+ }
/* Register the network device */
ret = rpmsg_eth_init_ndev(common);
if (ret)
@@ -552,6 +614,7 @@ static void rpmsg_eth_remove(struct rpmsg_device *rpdev)

netif_napi_del(&port->rx_napi);
timer_delete_sync(&port->rx_timer);
+ destroy_workqueue(common->cmd_wq);

dev_dbg(&rpdev->dev, "rpmsg-eth client driver is removed\n");
}
diff --git a/drivers/net/ethernet/rpmsg_eth.h b/drivers/net/ethernet/rpmsg_eth.h
index 992d05bd9386..995c5a9c1034 100644
--- a/drivers/net/ethernet/rpmsg_eth.h
+++ b/drivers/net/ethernet/rpmsg_eth.h
@@ -57,10 +57,14 @@ enum rpmsg_eth_rpmsg_type {
/* Request types */
RPMSG_ETH_REQ_SHM_INFO = 0,
RPMSG_ETH_REQ_SET_MAC_ADDR,
+ RPMSG_ETH_REQ_ADD_MC_ADDR,
+ RPMSG_ETH_REQ_DEL_MC_ADDR,

/* Response types */
RPMSG_ETH_RESP_SHM_INFO,
RPMSG_ETH_RESP_SET_MAC_ADDR,
+ RPMSG_ETH_RESP_ADD_MC_ADDR,
+ RPMSG_ETH_RESP_DEL_MC_ADDR,

/* Notification types */
RPMSG_ETH_NOTIFY_PORT_UP,
@@ -210,6 +214,10 @@ enum rpmsg_eth_state {
* @state: Interface state
* @state_work: Delayed work for state machine
* @sync_msg: Completion for synchronous message
+ * @rx_mode_work: Work structure for rx mode
+ * @cmd_wq: Workqueue for commands
+ * @mc_list: List of multicast addresses
+ * @mcast_addr: Multicast address filter
*/
struct rpmsg_eth_common {
struct rpmsg_device *rpdev;
@@ -226,6 +234,10 @@ struct rpmsg_eth_common {
struct mutex state_lock;
struct delayed_work state_work;
struct completion sync_msg;
+ struct work_struct rx_mode_work;
+ struct workqueue_struct *cmd_wq;
+ struct netdev_hw_addr_list mc_list;
+ u8 mcast_addr[ETH_ALEN];
};

/**
--
2.34.1