From nobody Mon Feb 9 12:01:56 2026 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (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 DA8AD261B9B for ; Mon, 26 Jan 2026 06:15:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769408124; cv=none; b=CpDq8H04JyUDhI1WirrqNfW6A2EGtWORvJTw6b6Vaoc81TdMTaueziF+jg6OKMmp9ir3yTn3R8bIReiktllEez4WaP+Lxf2iqpFFmtHB4xlauGP7ujxy0G5Zpy1O2xtRaajsjeoX+jG7evFXv1R1+6QDB7ZvJfIf06nHe4LxiAg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769408124; c=relaxed/simple; bh=2wpssjHxjFftU46L2ct0nhACoK/GI1O4qsjjvjba/KM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XM2eTKQolkEuzOwIOmGi3Tas7ejjnbATO30j0NvnxzC5pOptxSmTQz6SP4w82inhIiBzLThR2MRUizVq9RRDhu1vCD0aoibkg/g53gggqkY8mLIPnagwnRJfxiK4pxyBVpOdGrWkxSzN6ZWFWQl72lBLy4NXC82PHTi3Agb9Cxk= 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=IgNkYHeC; arc=none smtp.client-ip=209.85.214.174 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="IgNkYHeC" Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-2a7786d7895so26745515ad.1 for ; Sun, 25 Jan 2026 22:15:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769408122; x=1770012922; 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=8JJjobB6PNdLChVyacJVt2J6BgkT8/TCPgnTIdLgQN0=; b=IgNkYHeC7XSUQptfx+B5q/3ant5jB30Mx8nJKeX8vtoytk0ThFLADBTRGj2eJJzIMk aonVtzLX0x0kurRn4T+POU5WmWvhcQL350TyOmlDYRY871NboXfVQSaDOZneoS50ItXz Kt9qtUqi4dmBXsPA5j/pCK5+jlXNyVNgtJdXDJ7IHoqm0AwDDtXdQ6DHnujICzc9Vaba AUE2RrkUGyiQb2FHfVFEsV5+mV7OPfQ1oqV/gyyIJUZwLAqekzWE1sL64tKs+qgwHviX E1jsxCs4dJgJrEAfVG2Sd5B+4NaSdSSiH1sNwyPJzBeTW53IPzmiwTcD8b87cEe5SU81 Vyyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769408122; x=1770012922; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=8JJjobB6PNdLChVyacJVt2J6BgkT8/TCPgnTIdLgQN0=; b=t8t5IML+y2x6PvW4EtFTbGvQ4p4YHtciFPYtQENPKYWK1dE8xtXm7EAWWVActMHmPn 9DOldCYUfrmx11sIfN9TKEJ55C3Jdm4e6ah48NMsuJOUi0MVN02pd/MHl5dB2nkVpuSj rPO4rFuW1m+Q0IJBzjRnV24lAhfDR+63OYtRe29sm4OZxIk6RItO9vLs9eWfp4UL2e6Y /gP469RHYjZP4BoUlnjLIU9C+jJXnNG4b+5UTeu5nY7kmOe31elYMpZk54gvEpaIU//e y1aaKj9xkqIh679PoG3JU7FL0tyKamLAD6kOx8VlLB3VvT0mI3WWFsjIvVGiK/j4m2u6 UhjA== X-Forwarded-Encrypted: i=1; AJvYcCWATNvSpHBW3A83vMwEwNIssVhLAyObu4TjrJ79+S5EqMGwOzpov4Rg+g66JXizNxPlKRfk/n5fLBLRhbo=@vger.kernel.org X-Gm-Message-State: AOJu0YzqygvJitMSS2OjAgGQYle5Z+DPEnWvEkESPb99MDCIeUpzTrsz JhALxH4SlQlbRYFXBeQmXXnfY5qqIQWJd9Ov7WGLoYiNtZ6M9yJj7+Zo X-Gm-Gg: AZuq6aLVNTdLTcoP0Jg9tOWrUbvvnqkXgYeIA1oIdLdbFDyHPuBa7ciT5v+vBXggMSR nxqUgyvVsdupKhZb6wOUcQfJCbZxnTN//3e2UlVVr1xONXQjKeRCv9xYtPAk1+OJltPYFLVogbr jFlylncvipse1RkNLu6z/gjeIAtYYGtpCDWZ4lzOqGv8HTBxeJyNh5CJzvYydNhm/8KKhhjo4gM +WK5RRO9y3cym1wjJ8OZN5cN7xNGgs1V9h650mIFXVl96NcLNpJWssOYym3QGS1bZhvtm9o1HhQ /lvfgAonX4rqW0ocKAzzC6irWS0c/YGUVhN64i6BEl/0slO6cKnaS/oeXO2QfCAosgloABWjBvW q0+2sBua6JqLpjUinbCtQMGlcB4idvF9soMnttg82HZEo9bunt4FQU4qMbGBUKG1dPXkECdHswL iITcqw3yGWjNc0aNw8AAqH3qY7N5ar+Xi1mkAEQXGfkEwUS7vq7gg1xg== X-Received: by 2002:a17:902:daca:b0:2a7:d7b8:7661 with SMTP id d9443c01a7336-2a84520a932mr27459565ad.4.1769408122098; Sun, 25 Jan 2026 22:15:22 -0800 (PST) Received: from d.home.mmyangfl.tk ([2001:19f0:8001:1644:5400:5ff:fe3e:12b1]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2a802ede745sm79477325ad.44.2026.01.25.22.15.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Jan 2026 22:15:21 -0800 (PST) From: David Yang To: netdev@vger.kernel.org Cc: David Yang , Vladimir Oltean , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Russell King , linux-kernel@vger.kernel.org Subject: [PATCH net-next 2/3] net: dsa: add dsa_mall_policer_tc_entry_type() helper Date: Mon, 26 Jan 2026 14:13:30 +0800 Message-ID: <20260126061340.757543-3-mmyangfl@gmail.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260126061340.757543-1-mmyangfl@gmail.com> References: <20260126061340.757543-1-mmyangfl@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" It has shown FLOW_ACTION_POLICE is not stable, and it's very likely that options were added at drivers' request. However, that also means .port_policer_add() would have to check the parameters themselves. Giving that struct dsa_mall_policer_tc_entry is not stable, adjusting the interface between the framework and drivers would be a pain. Introduce a helper to maximize forward compatibility. Drivers may use it to recognize the pattern of tc entry reliably, and ensure all newly-added options are set to 0 / their default values and do not break the semantics. Signed-off-by: David Yang --- include/net/dsa.h | 14 ++++++++++++++ net/dsa/dsa.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/include/net/dsa.h b/include/net/dsa.h index 4c177b168ec8..957439846fe5 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -1410,4 +1410,18 @@ netdev_tx_t dsa_enqueue_skb(struct sk_buff *skb, str= uct net_device *dev); void dsa_port_phylink_mac_change(struct dsa_switch *ds, int port, bool up); bool dsa_supports_eee(struct dsa_switch *ds, int port); =20 +enum dsa_mall_policer_tc_type { + /* Pattern recognized, no surprising fields exist */ + DSA_MALL_POLICER_TC_KNOWN =3D BIT(0), + /* Unset: .burst and .rate_bytes_per_sec valid + * Set: .burst_pkt and .rate_pkt_ps valid + */ + DSA_MALL_POLICER_TC_PKT_MODE =3D BIT(1), + /* .mtu valid */ + DSA_MALL_POLICER_TC_MTU =3D BIT(2), +}; + +unsigned long +dsa_mall_policer_tc_entry_type(struct dsa_mall_policer_tc_entry *entry); + #endif diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c index 35ce3941fae3..c8102cea5ab3 100644 --- a/net/dsa/dsa.c +++ b/net/dsa/dsa.c @@ -1834,6 +1834,39 @@ int dsa_port_simple_hsr_leave(struct dsa_switch *ds,= int port, } EXPORT_SYMBOL_GPL(dsa_port_simple_hsr_leave); =20 +/* dsa_mall_policer_tc_entry_type - map tc_entry to some "known" types + * @entry: the tc entry + * + * A helper to check dsa_mall_policer_tc_entry against some known patterns, + * without having to know the exact struct layout. + * + * Returns: ORs of enum dsa_mall_policer_tc_type with DSA_MALL_POLICER_TC_= KNOWN + * set if recognized, otherwise 0 + */ +unsigned long +dsa_mall_policer_tc_entry_type(struct dsa_mall_policer_tc_entry *entry) +{ + bool byte_mode =3D (entry->burst || entry->rate_bytes_per_sec); + bool pkt_mode =3D (entry->burst_pkt || entry->rate_pkt_ps); + unsigned long flags =3D DSA_MALL_POLICER_TC_KNOWN; + + if (byte_mode =3D=3D pkt_mode) + return 0; + if (entry->peakrate_bytes_ps || entry->avrate || entry->overhead) + return 0; + if (entry->exceed.act_id !=3D FLOW_ACTION_DROP || + entry->notexceed.act_id !=3D FLOW_ACTION_ACCEPT) + return 0; + + if (pkt_mode) + flags |=3D DSA_MALL_POLICER_TC_PKT_MODE; + if (entry->mtu) + flags |=3D DSA_MALL_POLICER_TC_MTU; + + return flags; +} +EXPORT_SYMBOL_GPL(dsa_mall_policer_tc_entry_type); + static const struct dsa_stubs __dsa_stubs =3D { .conduit_hwtstamp_validate =3D __dsa_conduit_hwtstamp_validate, }; --=20 2.51.0