From nobody Sun Feb 8 10:43:43 2026 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CBF7034C99D for ; Tue, 28 Oct 2025 17:42:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761673373; cv=none; b=gFIFldvgR5jsbEtDy3O67vI6oau3CnCFN0xfxFfo/H076acSvtuvluNdnHpqPihuJOrqFp0fGF0DzM0t1ISAug+gQhA/icwnRA/UGZDXB14XQH8fFKWd1D/D6AGynxk5qLaSCJrHE+5pViSV6/MV1isvfxMVXDOfFTaDikoUdQI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761673373; c=relaxed/simple; bh=6v4wjgebPozLKUgfPJH5/qazZjK7CJHOf35355Wnrh8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZiqhAe81Pv27Y6ZBSgr1Zgyx13r3VL7K773P5FvpirBz5HNYXipwQz9P/ImBMD6bKTWBeyRiDcEs5CoaOB/8orGbOsAdXqyLdHx8o6jNnPtC/k4/bC6gD4OMl5MIAM/17wBJaFiGaaZe6n6GQybMhnbpn56MJXKyNWdvNQJ3OMs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=eddZkTuW; arc=none smtp.client-ip=209.85.210.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eddZkTuW" Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-76e2ea933b7so124576b3a.1 for ; Tue, 28 Oct 2025 10:42:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1761673371; x=1762278171; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3CmgKRjxqZ78TC/moM+aLGRRq1ZpH43SB88rhbo0/Vo=; b=eddZkTuWFeKasSR8uxsAbOvFKMc6xw0XfVaLl1yMyYW4rqkjJQB0H6Nw2NU5VSa83/ qxlu+6sQ3ohVdkVH9AwI9y54F6orD10wlFyS5qcURMfZlmVuloJ6B0Jf9SI+Gb5uRv7A B8O+ywkfeNMWPw3QTWROX8SmGjkZ+jBqcmW5Sf054AlWKXHxYYv4bLQrSfEvWV9dY4uJ pAF2iPppu275yzGg7R/8lAfExfKm77HxYykEcyngvwiyO4BJp53Mz+VKD+oUU5ZjISWr CniwzGhbQDwOegWM3ido0wmhpt69Rzx7dGyoxKoKNVRsD+gfsYMGnT1lLPiWeuCWuOlE 40Bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761673371; x=1762278171; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3CmgKRjxqZ78TC/moM+aLGRRq1ZpH43SB88rhbo0/Vo=; b=cnESLGP55PbAzLPoiAdzEsEZIa44fly17i1fqGdIokS79B7TrouIxuoFifIxOPyqDW zRR8wEu0Xw0npolqif6XNsRZe5pQ02axPS4RGgoCf+HFBf5derA+q6HKmLidt6+1B/k6 kwTtDCNOcegdrIAgAo0mhxfC9Z7Peed6xVdYQgpXGlntXRvMBMUaMhGOE+OrNv6sHwzG +MD7pxZZUzADwnBI45LE0SHUJgcui0/qT09nQQHqGobBqtP1pVD4Qrtz4zrGgI9D/gtX orzeNcKSykLi3aOypR1NdXhoW0wQK1ARLdaGX9wSBJkL35e3yESwS3K/W/yKPgIAqRPT YbMA== X-Forwarded-Encrypted: i=1; AJvYcCWSO2kmP5jlPw7uHrRY6zT33hCsauy/oG/aOWkhm0xtxUcAJx2QTbfx7Krq6rKqB204QqoSJLfYfDnxAV8=@vger.kernel.org X-Gm-Message-State: AOJu0YzIRxgq9L1FlKMEXYU/SbpiG9oRThyrZzWQMFNNat7vlP8UmAR/ cIT6AZBqpIGQEVUUkIlZ9HXcgUeIfaqbebqIUDmzUPmqGgZNCh30ryMi X-Gm-Gg: ASbGncuTYTA5kAPUtJIFzSdVIsmy01tsoajiA+j1DPMP/VT8dwDBTAo8K/yiySQCzFD zB+rQOfOYe5U7xQvh6divj4+6aaq9keQqcsA9Kde94zdvtvfruBnQ1Z3+q2Tw23N/aQDD9u8NVJ MkV7iEqfHeP12peV5fVjH+y7MTG/eOwoOVN7RfB2tp1HAAm64428CfyZkxLdFZJIJPkVBtlCM8n fXhYKpupXk/bJPgvGYAeXm87Ebe4d4Dv+V9wXqQm/RhWbpsZXFo/Iwr2d6LRifDmX2BFuXxmbHd SRXfJwHvbvqh8uqxr6nr+jkwRomBxR8mwR1aikzkh+tWi+TMz2ZN+3VXebqzmumceHOLRyrQ6lm r8cB0kjVkNMld+GWjPx5pTcC8QLCUINEDPD+2TnPs28Vn71NvvaguT8r/LPw/0ZOYx+hOb5NroT LDb+lDJWPpQnryciH9TZES+IdhCWvQHJULajDMm9sBZKDYrJdQ0j1SRS+XPzSWzHsPqViwLjjZi DU5OQ== X-Google-Smtp-Source: AGHT+IF7n2P9v4I116Y5WIJSgeGFxuUTJM6UJ4Tic/BqkwkkiA9qVF8XSZ650kwCzK0xRThK/PyTsQ== X-Received: by 2002:a05:6a21:ad16:b0:345:483a:48ae with SMTP id adf61e73a8af0-345483a4a8amr3360888637.12.1761673370932; Tue, 28 Oct 2025 10:42:50 -0700 (PDT) Received: from debian.domain.name ([223.181.113.110]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b71268bde68sm11086746a12.1.2025.10.28.10.42.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Oct 2025 10:42:50 -0700 (PDT) From: I Viswanath To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, sdf@fomichev.me, kuniyu@google.com, ahmed.zaki@intel.com, aleksander.lobakin@intel.com, jacob.e.keller@intel.com Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, skhan@linuxfoundation.org, linux-kernel-mentees@lists.linux.dev, david.hunter.linux@gmail.com, khalid@kernel.org, I Viswanath Subject: [RFC/RFT PATCH net-next v3 1/2] net: Add ndo_write_rx_config and helper structs and functions: Date: Tue, 28 Oct 2025 23:12:21 +0530 Message-ID: <20251028174222.1739954-2-viswanathiyyappan@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251028174222.1739954-1-viswanathiyyappan@gmail.com> References: <20251028174222.1739954-1-viswanathiyyappan@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add ndo_write_rx_config callback and helper structs/functions: rx_config_work - To schedule the callback and handle synchronization read_snapshot/update_snapshot - Helper functions to read/update the rx_config snapshot set_and_schedule_rx_config - Helper function to call ndo_set_rx_mode and schedule ndo_write_rx_config execute_write_rx_config - Helper function that will be scheduled by rx_work->config_write Signed-off-by: I Viswanath --- include/linux/netdevice.h | 38 +++++++++++++++++++++++++++- net/core/dev.c | 53 +++++++++++++++++++++++++++++++++++---- 2 files changed, 85 insertions(+), 6 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 7f5aad5cc9a1..9f188229443c 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -1100,7 +1100,12 @@ struct netdev_net_notifier { * void (*ndo_set_rx_mode)(struct net_device *dev); * This function is called device changes address list filtering. * If driver handles unicast address filtering, it should set - * IFF_UNICAST_FLT in its priv_flags. + * IFF_UNICAST_FLT in its priv_flags. This sets up the snapshot of + * rx_config that will be written to the device. + * + * void (*ndo_write_rx_config)(struct net_device *dev); + * This function is scheduled immediately after ndo_set_rx_mode to + * write rx_config to the device. * * int (*ndo_set_mac_address)(struct net_device *dev, void *addr); * This function is called when the Media Access Control address @@ -1421,6 +1426,7 @@ struct net_device_ops { void (*ndo_change_rx_flags)(struct net_device *dev, int flags); void (*ndo_set_rx_mode)(struct net_device *dev); + void (*ndo_write_rx_config)(struct net_device *dev); int (*ndo_set_mac_address)(struct net_device *dev, void *addr); int (*ndo_validate_addr)(struct net_device *dev); @@ -1767,6 +1773,12 @@ enum netdev_reg_state { NETREG_DUMMY, /* dummy device for NAPI poll */ }; =20 +struct rx_config_work { + struct work_struct config_write; + struct net_device *dev; + spinlock_t config_lock; +}; + /** * struct net_device - The DEVICE structure. * @@ -2082,6 +2094,8 @@ enum netdev_reg_state { * dev_list, one per address-family. * @hwprov: Tracks which PTP performs hardware packet time stamping. * + * @rx_work: helper struct to schedule rx config write to the hardware. + * * FIXME: cleanup struct net_device such that network protocol info * moves out. */ @@ -2559,6 +2573,8 @@ struct net_device { =20 struct hwtstamp_provider __rcu *hwprov; =20 + struct rx_config_work *rx_work; + u8 priv[] ____cacheline_aligned __counted_by(priv_len); } ____cacheline_aligned; @@ -2734,6 +2750,26 @@ void dev_net_set(struct net_device *dev, struct net = *net) write_pnet(&dev->nd_net, net); } =20 +#define update_snapshot(config_ptr, type) \ + do { \ + typeof((config_ptr)) rx_config =3D ((type *)(dev->priv))->rx_config; \ + unsigned long flags; \ + spin_lock_irqsave(&((dev)->rx_work->config_lock), flags); \ + *rx_config =3D *(config_ptr); \ + spin_unlock_irqrestore(&((dev)->rx_work->config_lock), flags); \ + } while (0) + +#define read_snapshot(config_ptr, type) \ + do { \ + typeof((config_ptr)) rx_config =3D ((type *)(dev->priv))->rx_config; \ + unsigned long flags; \ + spin_lock_irqsave(&((dev)->rx_work->config_lock), flags); \ + *(config_ptr) =3D *rx_config; \ + spin_unlock_irqrestore(&((dev)->rx_work->config_lock), flags); \ + } while (0) + +void set_and_schedule_rx_config(struct net_device *dev, bool flush); + /** * netdev_priv - access network device private data * @dev: network device diff --git a/net/core/dev.c b/net/core/dev.c index 378c2d010faf..69b8bfc0edeb 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -9571,6 +9571,37 @@ int netif_set_allmulti(struct net_device *dev, int i= nc, bool notify) return 0; } =20 +static void execute_write_rx_config(struct work_struct *param) +{ + struct rx_config_work *rx_work =3D container_of(param, + struct rx_config_work, + config_write); + struct net_device *dev =3D rx_work->dev; + + // This path should not be hit outside the work item + WARN_ON(!dev->netdev_ops->ndo_write_rx_config); + dev->netdev_ops->ndo_write_rx_config(dev); +} + +/* Sets up the rx_config snapshot and schedules write_rx_config. If + * it's necessary to wait for completion of write_rx_config, set + * flush to true. + */ +void set_and_schedule_rx_config(struct net_device *dev, bool flush) +{ + const struct net_device_ops *ops =3D dev->netdev_ops; + + if (ops->ndo_set_rx_mode) + ops->ndo_set_rx_mode(dev); + + if (ops->ndo_write_rx_config) { + schedule_work(&dev->rx_work->config_write); + if (flush) + flush_work(&dev->rx_work->config_write); + } +} +EXPORT_SYMBOL(set_and_schedule_rx_config); + /* * Upload unicast and multicast address lists to device and * configure RX filtering. When the device doesn't support unicast @@ -9579,8 +9610,6 @@ int netif_set_allmulti(struct net_device *dev, int in= c, bool notify) */ void __dev_set_rx_mode(struct net_device *dev) { - const struct net_device_ops *ops =3D dev->netdev_ops; - /* dev_open will call this function so the list will stay sane. */ if (!(dev->flags&IFF_UP)) return; @@ -9601,8 +9630,7 @@ void __dev_set_rx_mode(struct net_device *dev) } } =20 - if (ops->ndo_set_rx_mode) - ops->ndo_set_rx_mode(dev); + set_and_schedule_rx_config(dev, false); } =20 void dev_set_rx_mode(struct net_device *dev) @@ -11961,9 +11989,17 @@ struct net_device *alloc_netdev_mqs(int sizeof_pri= v, const char *name, refcount_set(&dev->dev_refcnt, 1); #endif =20 - if (dev_addr_init(dev)) + dev->rx_work =3D kmalloc(sizeof(*dev->rx_work), GFP_KERNEL); + if (!dev->rx_work) goto free_pcpu; =20 + dev->rx_work->dev =3D dev; + spin_lock_init(&dev->rx_work->config_lock); + INIT_WORK(&dev->rx_work->config_write, execute_write_rx_config); + + if (dev_addr_init(dev)) + goto free_rx_work; + dev_mc_init(dev); dev_uc_init(dev); =20 @@ -12045,6 +12081,10 @@ struct net_device *alloc_netdev_mqs(int sizeof_pri= v, const char *name, free_netdev(dev); return NULL; =20 +free_rx_work: + cancel_work_sync(&dev->rx_work->config_write); + kfree(dev->rx_work); + free_pcpu: #ifdef CONFIG_PCPU_DEV_REFCNT free_percpu(dev->pcpu_refcnt); @@ -12130,6 +12170,9 @@ void free_netdev(struct net_device *dev) return; } =20 + cancel_work_sync(&dev->rx_work->config_write); + kfree(dev->rx_work); + BUG_ON(dev->reg_state !=3D NETREG_UNREGISTERED); WRITE_ONCE(dev->reg_state, NETREG_RELEASED); =20 --=20 2.34.1 From nobody Sun Feb 8 10:43:43 2026 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 271D534C991 for ; Tue, 28 Oct 2025 17:42:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761673381; cv=none; b=lIfFrvx+spyKBsipBv0Uu6yZn9TTyVT+UAYp5HcTSaoj0QdlTet8XD0jq2o6vCkyEAXFGkhZYpHSJt1FKuRq6RUVa64MHxoIVYcwOEa9+6n6Y4mamiOSmR2cJLbdNkPyUYxocnqiqon6OuQS5tBCivkGlYu/8XaDDJt+C6c/73M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761673381; c=relaxed/simple; bh=sMkDe6QuWZJg6QPZquqAd7/AomdUD6bzML0q+sBe7bg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iMrVg4WlIwWAxmDcoaAOrH0VFHhAhKgL5oHJucrMExh94ziMYGLIaOnujpgcv9JDfoswz2K+TKLv56yrbQQma8O2WXvpPwbXJEjoCMfSoDBRby63P8lM6AcCal7XQkchiu8XfbtDuR2DfJulSh8KNh5q8Xu/Rr0CjRN+1Bu9tGo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=FGQOBvxY; arc=none smtp.client-ip=209.85.210.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FGQOBvxY" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-7a27ab05a2dso5453587b3a.2 for ; Tue, 28 Oct 2025 10:42:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1761673378; x=1762278178; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2wUcQZk4DZbR7xSABHIWAnc7HQf0QktM3XmDK4PsaFA=; b=FGQOBvxYvU48N98+mcTfffb/wm/ukphYceP4s35xWvXZ74ETuydF7SCiCNZLUI1/8L yInsej8B5MYhN0z6RYaj0D+IqsQnSo6I7Rtr4jTwZdw5P1kTFk2IAua4zM5XUHL+2AZV P25n2xw6ibsNoSFCMFMkfwgpVjJswnfyL9K59FHJEE/BFZDX2QYgOvhyVxkBJnkPzSIs s0xW3Ra3tPWj+iit/OeWRiPHY0K6POkdMuV020AV/QHIrKIethA8EF5VEgxJ2Yw6zCXV DLffA+8hn1ZskqwOvEdZnOOQnCJ6cMFvJOKZqd/Pmmd/8F71E3F776FYBp/EVzcFtA51 GNfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761673378; x=1762278178; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2wUcQZk4DZbR7xSABHIWAnc7HQf0QktM3XmDK4PsaFA=; b=nl320nOOjNetAhPsjqi/9zmGTpC4lDxTTO2bnA2mf0b76zLxE3nm5q9vwwiX9Itsyy YJ0Jgp8FzR8yDc87DQ9XpKcZOIlb+RZTjEI3Ut/D6d1JS3CKS4w5xBJJOzDXeGqakWRw kR7KDrkZMGLpDXIFRbAWo+yJxgXUhuSdN8X72l0G5nnf16spJ05YHGfei2xgNbLs7qEc F7318YeFsBYTNWTc44QwDELaH0KE6eLhqE2ygOqGoiA3v/Nslzgebj69Bv5zUxFa1KAk qjP38VDhQbhkG66na5GAIQqD6BOEwePQNhtck5uCDJQM74BrrbXZFpR9857YXXHqS0xE 5Y+g== X-Forwarded-Encrypted: i=1; AJvYcCW/Umkz+FsFksSri6t5EDqG2VMixUQVXsQWk6hEAYNwp+WWCemSbQFWY5yg43ifvzGuZBBgec1MgO0IGFI=@vger.kernel.org X-Gm-Message-State: AOJu0Yz3B/IjOtGgeB0n9kEyqW96PRlFtfIBMJUo6FhYMPrw27taP4P4 jcZX2c9ZPVEbPsEpdd/QMwwnMAZBksFzU4C8/cHW6/vFug7K7qjMYSaL X-Gm-Gg: ASbGnctM3ku8vQX4fRrZhH7JWn22MnxhnllmSDmr4YOiAI34ERXv3m3Y2up9q4bPKxy HkVSJsT/B9JFQ0wiPr/PvWVJXD3442UNBjQjxXkIzaTDDmYfUQ69v4lN7LUObHxGn2X/veuqma6 rYdqv4BKEKkgmZyBq9vhXldO4wMFx4S9OYVG2H5qu+dNHLNZFnIaEOrApB5W8K7WnOS/VQIDpId /365CWsRkjdO64D3s6bfu2i59t10+tTcRUJrf2kzFCZh2zBRVMtwCk2TYmqrx3/Hl998NSgaY05 2vLttCDgsP5AOfkM6RY3GETaYcVJH4o9ambPF5RwfYNw7AuKHDz+EEmZOMCMeOsFvBuxWS2v9ID 4IX+F1f3fDhK2VVLdPwdrHPORfTmzhVBWnHEvBV/18Rzb6+5OZN1LTIcMRdw4ar8m3XsIkArYAR W2HY/QwqiI61XRAX4Wz7wv+I5ftc0pefQUt+9a1acoJtEedjG6XWiZ/8XunDTgx8wrZq8= X-Google-Smtp-Source: AGHT+IFmoA4oUM0hYelxgK8TfKfROtqNw2wglYnqCeCLNgjKiJFLlA1p5RH5+ee4oIgzehf3QEOHoQ== X-Received: by 2002:a05:6a20:9188:b0:2fd:a3b:933d with SMTP id adf61e73a8af0-3461ecf3596mr669372637.58.1761673378402; Tue, 28 Oct 2025 10:42:58 -0700 (PDT) Received: from debian.domain.name ([223.181.113.110]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b71268bde68sm11086746a12.1.2025.10.28.10.42.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Oct 2025 10:42:57 -0700 (PDT) From: I Viswanath To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, sdf@fomichev.me, kuniyu@google.com, ahmed.zaki@intel.com, aleksander.lobakin@intel.com, jacob.e.keller@intel.com Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, skhan@linuxfoundation.org, linux-kernel-mentees@lists.linux.dev, david.hunter.linux@gmail.com, khalid@kernel.org, I Viswanath Subject: [RFC/RFT PATCH net-next v3 2/2] net: ethernet: Implement ndo_write_rx_config callback for the 8139cp driver Date: Tue, 28 Oct 2025 23:12:22 +0530 Message-ID: <20251028174222.1739954-3-viswanathiyyappan@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251028174222.1739954-1-viswanathiyyappan@gmail.com> References: <20251028174222.1739954-1-viswanathiyyappan@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Implement ndo_write_rx_config for the 8139cp driver Signed-off-by: I Viswanath --- drivers/net/ethernet/realtek/8139cp.c | 78 ++++++++++++++++----------- 1 file changed, 46 insertions(+), 32 deletions(-) diff --git a/drivers/net/ethernet/realtek/8139cp.c b/drivers/net/ethernet/r= ealtek/8139cp.c index 5652da8a178c..ae3dca4f9b73 100644 --- a/drivers/net/ethernet/realtek/8139cp.c +++ b/drivers/net/ethernet/realtek/8139cp.c @@ -319,6 +319,11 @@ struct cp_extra_stats { unsigned long rx_frags; }; =20 +struct cp_rx_config { + int rx_mode; + u32 mc_filter[2]; /* Multicast hash filter */ +}; + struct cp_private { void __iomem *regs; struct net_device *dev; @@ -328,7 +333,7 @@ struct cp_private { struct napi_struct napi; =20 struct pci_dev *pdev; - u32 rx_config; + struct cp_rx_config *rx_config; u16 cpcmd; =20 struct cp_extra_stats cp_stats; @@ -372,7 +377,6 @@ struct cp_private { } while (0) =20 =20 -static void __cp_set_rx_mode (struct net_device *dev); static void cp_tx (struct cp_private *cp); static void cp_clean_rings (struct cp_private *cp); #ifdef CONFIG_NET_POLL_CONTROLLER @@ -882,55 +886,53 @@ static netdev_tx_t cp_start_xmit (struct sk_buff *skb, goto out_unlock; } =20 +static void cp_write_rx_config(struct net_device *dev) +{ + struct cp_private *cp =3D netdev_priv(dev); + struct cp_rx_config snapshot; + + read_snapshot(&snapshot, struct cp_private); + + /* We can safely update without stopping the chip. */ + cpw32_f(RxConfig, snapshot.rx_mode); + + cpw32_f(MAR0 + 0, snapshot.mc_filter[0]); + cpw32_f(MAR0 + 4, snapshot.mc_filter[1]); +} + /* Set or clear the multicast filter for this adaptor. This routine is not state sensitive and need not be SMP locked. */ =20 -static void __cp_set_rx_mode (struct net_device *dev) +static void cp_set_rx_mode (struct net_device *dev) { - struct cp_private *cp =3D netdev_priv(dev); - u32 mc_filter[2]; /* Multicast hash filter */ - int rx_mode; + struct cp_rx_config new_config; =20 /* Note: do not reorder, GCC is clever about common statements. */ if (dev->flags & IFF_PROMISC) { /* Unconditionally log net taps. */ - rx_mode =3D + new_config.rx_mode =3D AcceptBroadcast | AcceptMulticast | AcceptMyPhys | AcceptAllPhys; - mc_filter[1] =3D mc_filter[0] =3D 0xffffffff; + new_config.mc_filter[1] =3D new_config.mc_filter[0] =3D 0xffffffff; } else if ((netdev_mc_count(dev) > multicast_filter_limit) || (dev->flags & IFF_ALLMULTI)) { /* Too many to filter perfectly -- accept all multicasts. */ - rx_mode =3D AcceptBroadcast | AcceptMulticast | AcceptMyPhys; - mc_filter[1] =3D mc_filter[0] =3D 0xffffffff; + new_config.rx_mode =3D AcceptBroadcast | AcceptMulticast | AcceptMyPhys; + new_config.mc_filter[1] =3D new_config.mc_filter[0] =3D 0xffffffff; } else { struct netdev_hw_addr *ha; - rx_mode =3D AcceptBroadcast | AcceptMyPhys; - mc_filter[1] =3D mc_filter[0] =3D 0; + new_config.rx_mode =3D AcceptBroadcast | AcceptMyPhys; + new_config.mc_filter[1] =3D new_config.mc_filter[0] =3D 0; netdev_for_each_mc_addr(ha, dev) { int bit_nr =3D ether_crc(ETH_ALEN, ha->addr) >> 26; =20 - mc_filter[bit_nr >> 5] |=3D 1 << (bit_nr & 31); - rx_mode |=3D AcceptMulticast; + new_config.mc_filter[bit_nr >> 5] |=3D 1 << (bit_nr & 31); + new_config.rx_mode |=3D AcceptMulticast; } } =20 - /* We can safely update without stopping the chip. */ - cp->rx_config =3D cp_rx_config | rx_mode; - cpw32_f(RxConfig, cp->rx_config); - - cpw32_f (MAR0 + 0, mc_filter[0]); - cpw32_f (MAR0 + 4, mc_filter[1]); -} - -static void cp_set_rx_mode (struct net_device *dev) -{ - unsigned long flags; - struct cp_private *cp =3D netdev_priv(dev); - - spin_lock_irqsave (&cp->lock, flags); - __cp_set_rx_mode(dev); - spin_unlock_irqrestore (&cp->lock, flags); + new_config.rx_mode =3D cp_rx_config | new_config.rx_mode; + update_snapshot(&new_config, struct cp_private); } =20 static void __cp_get_stats(struct cp_private *cp) @@ -1040,7 +1042,7 @@ static void cp_init_hw (struct cp_private *cp) cp_start_hw(cp); cpw8(TxThresh, 0x06); /* XXX convert magic num to a constant */ =20 - __cp_set_rx_mode(dev); + set_and_schedule_rx_config(dev, true); cpw32_f (TxConfig, IFG | (TX_DMA_BURST << TxDMAShift)); =20 cpw8(Config1, cpr8(Config1) | DriverLoaded | PMEnable); @@ -1188,6 +1190,12 @@ static int cp_open (struct net_device *dev) if (rc) return rc; =20 + cp->rx_config =3D kmalloc(sizeof(*cp->rx_config), GFP_KERNEL); + if (!cp->rx_config) { + rc =3D -ENOMEM; + goto err_out_rx_config; + } + napi_enable(&cp->napi); =20 cp_init_hw(cp); @@ -1207,6 +1215,9 @@ static int cp_open (struct net_device *dev) err_out_hw: napi_disable(&cp->napi); cp_stop_hw(cp); + kfree(cp->rx_config); + +err_out_rx_config: cp_free_rings(cp); return rc; } @@ -1227,6 +1238,8 @@ static int cp_close (struct net_device *dev) =20 cp_stop_hw(cp); =20 + kfree(cp->rx_config); + spin_unlock_irqrestore(&cp->lock, flags); =20 free_irq(cp->pdev->irq, dev); @@ -1262,7 +1275,7 @@ static void cp_tx_timeout(struct net_device *dev, uns= igned int txqueue) cp_clean_rings(cp); cp_init_rings(cp); cp_start_hw(cp); - __cp_set_rx_mode(dev); + set_and_schedule_rx_config(dev, false); cpw16_f(IntrMask, cp_norx_intr_mask); =20 netif_wake_queue(dev); @@ -1870,6 +1883,7 @@ static const struct net_device_ops cp_netdev_ops =3D { .ndo_validate_addr =3D eth_validate_addr, .ndo_set_mac_address =3D cp_set_mac_address, .ndo_set_rx_mode =3D cp_set_rx_mode, + .ndo_write_rx_config =3D cp_write_rx_config, .ndo_get_stats =3D cp_get_stats, .ndo_eth_ioctl =3D cp_ioctl, .ndo_start_xmit =3D cp_start_xmit, --=20 2.34.1