Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp2615943lqz; Wed, 3 Apr 2024 03:40:44 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUgErsKvi+UubTS8JgGI4d7QvWEonVFPqMNXZV96VqizlY7PiLq0KNTSpkAhsh7ngW8td7J1+hr7qZ1Ku+pOn850B+MJV8Y04nn0GsL9A== X-Google-Smtp-Source: AGHT+IE7xEe7XJUcKrjvCZkVAcuXj6SrghwNaPCq20GLIKRxZzisgD4KmKG1IN2cZj2RVx+ImKlq X-Received: by 2002:a17:902:c189:b0:1e0:b2d5:5f46 with SMTP id d9-20020a170902c18900b001e0b2d55f46mr1929036pld.46.1712140844667; Wed, 03 Apr 2024 03:40:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712140844; cv=pass; d=google.com; s=arc-20160816; b=vCYx3SJqunwllQ0uwVrtehr7WnbrnZAf91aFtM6nE5Q1gnWOvM3bdmXshFwnhGA0m2 z420RvjuQe13ND7uLDEuRoYKR9kIMDLZgKAgYlbtK3Q52Us+0Gdnz4SedVeoWN7MaQMy CEWaTJLKvDkFsYGuGN4wLLPknjFtKj3DjR29AVTYlQIjUSXV7KkmnA+MzfKV7u5LNH4j Wl8gwntzxozlkULkeZETRf2sOaR4/6vWKr5T88FI8sr89c5dTTSS6O3svyAx3BvhTGv7 niqKFE7WheJ/qMa5mcUoKjBvIis1MKCTiD/9KFe+OGncFQ7XBYd1/dCZh9PcuNu8xtiz wP/Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=63Sv42NZ4UQ21VsUCZjz4D7LimPpZB9TqWKZW2m0UhA=; fh=cTiZEwfkYNCuUU1WrgQeP4QFaz8CY1iQ3WhbeYVLSkM=; b=vbXYblMS5klT3LsCiTvZ8nEu9SX0wTqaENIjuM/0miBO3ldVMK5F5aQz4w23gq/6gx srdCi0hLR1NzW24+P1PyJzGcJ1LvtTFxZD2bQjVjmSLGBtb1ww2svBDYA62FPUMGHQJp GyiOG1pr7+ptlCpVK0UIpzoW3iwm/SmpZgFVVXYFf91LjXMQXap7Yw8ej0dMORUT2QNX 1DT7LziBebkMb/gyJecyEAozOVW28U0jVXFCHdvaEjxPrDrF1f4wMBqsFZ2LKf6QITnK t2V9DUapP8fYs6PwnUG5I4IJM7IkGFnooILQzVhkONTidtxBGKFYmitsXt75rk+atuj9 H+Dw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Gx4CqlzS; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-129578-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-129578-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id e8-20020a170902ef4800b001e29c47a753si301182plx.555.2024.04.03.03.40.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 03:40:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-129578-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Gx4CqlzS; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-129578-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-129578-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id DA180284C71 for ; Wed, 3 Apr 2024 10:40:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7159B148313; Wed, 3 Apr 2024 10:38:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Gx4CqlzS" Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) (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 6C1B8147C94; Wed, 3 Apr 2024 10:38:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712140701; cv=none; b=udYAEAK+fLUcMx9PzOOjcfBp0cyDzEl8n1l9FA/JKQ5yVKG3ldMbzfucVew824BwP0zGhw8gkTjVv1SXxysDgWrVWBxz01sKP38VpA17IfCXdQPrZbH5XHL6+SkYKfadOoltbh7gerHfK6hGn8AKQrzvQ0JYRBNnui8aKwjswzw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712140701; c=relaxed/simple; bh=/1PYhY8+2O5h3/1dpp5yGpsQ3rsJbn94bpYR2AU12xc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kWfVXVllesnA2g6OS8hSj65l9K6gwiPdrUjy6gJXWnuJQum58qe+0J2ioxbL4svJbKXGj2TZzIP/A/qv3gLfhxdAjlpSzVDWzaqWguIVKvwyiXgGC5aIl0oWjsBCxCX92szmT44diAWApGSj2PPtvkgtAsatzv8u0bpqgmVJYoA= 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=Gx4CqlzS; arc=none smtp.client-ip=209.85.218.53 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 Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-a44ad785a44so710710366b.3; Wed, 03 Apr 2024 03:38:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712140697; x=1712745497; 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=63Sv42NZ4UQ21VsUCZjz4D7LimPpZB9TqWKZW2m0UhA=; b=Gx4CqlzSzxxocRJJG/hRuPNwHWWw/fmxDMTHZrW7QPftAn6Mgli+o2kvesfmXawT4p 3fc7AsBlmL2bwya7ZCQpX2u1eQONPub3mAx61klyEQF4tBi7319zvVWMw2FQZ1XAfv7v SnNMm1lWHHB9eKZi+1ijzPpsorh03TN4vaXRGtSc9Sf0Ra3jaEn1FoSE+F+n4DALInLc mvShlV19oMBM/36BxdhWD9gaA6uDV6dN1ZFlje/MzO7YP03hOU0LBL0uniN0ATHBXSDJ n0MBlC98z2t9DZuN1uL081a6DW2eLqjfPAuib35zAwrNDPBj7+c3rraqNPSvfrEWNFU9 qvpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712140697; x=1712745497; 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=63Sv42NZ4UQ21VsUCZjz4D7LimPpZB9TqWKZW2m0UhA=; b=Bfzxq8//RlhgOTIdjUyB1rWZfKYTo0Cd+9IIxSSP+GjLSK8GnDkJyqa7bQ7TOfQwjd gyVB2SUgDa3SOnhyrNNqAWNeZdrnEYN4sA9sCWL1YwptZowOWrZwM3/BRz80hJaCHxfj z2HS4ZyVbcyHH50UJ4a5jNqpUQh90UhMOIPSinb+aJav68qtFAnOdycn+uomY0Caf7u2 WlX5uBO32Qpvl2OgvRS03y9j1UvSXMEIgq0hkKh7daBXCsRfG5lNSaT4EhYLB+wElWsm T5DgQmMkOLsYiL5aFN4HUmaCLsGLkeCU9GKb+tWOnzANsJ7EM6T7KjmRKz/gkjr7TnS8 3fmQ== X-Forwarded-Encrypted: i=1; AJvYcCWwbVexRiIVj2K7E+5KoPvDrmlDqRsctJEhdLmWoICq/zFDVMr0G5SRGbUnuqGtIeRb3/QsLFvSlX9N6M96Pckp5IcvwILqEL79Rq41 X-Gm-Message-State: AOJu0YzOXf2LvzhM5CmDg7COBvPjpYNiIdfuW8SRdYciKUkg7NbssKZy JQtvQbdZ7lUEccEm4pyqLRGQ9axvy5iM9nBWsOnxnCMKWZ9QFM4hp7znqM21KNU= X-Received: by 2002:a17:906:c109:b0:a4e:3b78:ed1f with SMTP id do9-20020a170906c10900b00a4e3b78ed1fmr11134901ejc.47.1712140697518; Wed, 03 Apr 2024 03:38:17 -0700 (PDT) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id xd2-20020a170907078200b00a4e2e16805bsm6858169ejb.11.2024.04.03.03.38.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 03:38:17 -0700 (PDT) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: Linus Walleij , Simon Horman , Vladimir Oltean , Pawel Dembicki , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Russell King , linux-kernel@vger.kernel.org Subject: [PATCH net-next v8 09/16] net: dsa: tag_sja1105: absorb entire sja1105_vlan_rcv() into dsa_8021q_rcv() Date: Wed, 3 Apr 2024 12:37:25 +0200 Message-Id: <20240403103734.3033398-10-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240403103734.3033398-1-paweldembicki@gmail.com> References: <20240403103734.3033398-1-paweldembicki@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: 8bit From: Vladimir Oltean tag_sja1105 has a wrapper over dsa_8021q_rcv(): sja1105_vlan_rcv(), which determines whether the packet came from a bridge with vlan_filtering=1 (the case resolved via dsa_find_designated_bridge_port_by_vid()), or if it contains a tag_8021q header. Looking at a new tagger implementation for vsc73xx, based also on tag_8021q, it is becoming clear that the logic is needed there as well. So instead of forcing each tagger to wrap around dsa_8021q_rcv(), let's merge the logic into the core. Signed-off-by: Vladimir Oltean Signed-off-by: Pawel Dembicki --- v8, v7, v6: - resend only v5: - add missing SoB v4: - introduced patch net/dsa/tag_8021q.c | 34 ++++++++++++++++++++++++++++------ net/dsa/tag_8021q.h | 2 +- net/dsa/tag_ocelot_8021q.c | 2 +- net/dsa/tag_sja1105.c | 32 ++++---------------------------- 4 files changed, 34 insertions(+), 36 deletions(-) diff --git a/net/dsa/tag_8021q.c b/net/dsa/tag_8021q.c index 3cb0293793a5..332b0ae02645 100644 --- a/net/dsa/tag_8021q.c +++ b/net/dsa/tag_8021q.c @@ -507,27 +507,39 @@ EXPORT_SYMBOL_GPL(dsa_tag_8021q_find_port_by_vbid); * @vbid: pointer to storage for imprecise bridge ID. Must be pre-initialized * with -1. If a positive value is returned, the source_port and switch_id * are invalid. + * @vid: pointer to storage for original VID, in case tag_8021q decoding failed. + * + * If the packet has a tag_8021q header, decode it and set @source_port, + * @switch_id and @vbid, and strip the header. Otherwise set @vid and keep the + * header in the hwaccel area of the packet. */ void dsa_8021q_rcv(struct sk_buff *skb, int *source_port, int *switch_id, - int *vbid) + int *vbid, int *vid) { int tmp_source_port, tmp_switch_id, tmp_vbid; - u16 vid, tci; + __be16 vlan_proto; + u16 tmp_vid, tci; if (skb_vlan_tag_present(skb)) { + vlan_proto = skb->vlan_proto; tci = skb_vlan_tag_get(skb); __vlan_hwaccel_clear_tag(skb); } else { + struct vlan_ethhdr *hdr = vlan_eth_hdr(skb); + + vlan_proto = hdr->h_vlan_proto; skb_push_rcsum(skb, ETH_HLEN); __skb_vlan_pop(skb, &tci); skb_pull_rcsum(skb, ETH_HLEN); } - vid = tci & VLAN_VID_MASK; + tmp_vid = tci & VLAN_VID_MASK; + if (!vid_is_dsa_8021q(tmp_vid)) + goto not_tag_8021q; - tmp_source_port = dsa_8021q_rx_source_port(vid); - tmp_switch_id = dsa_8021q_rx_switch_id(vid); - tmp_vbid = dsa_tag_8021q_rx_vbid(vid); + tmp_source_port = dsa_8021q_rx_source_port(tmp_vid); + tmp_switch_id = dsa_8021q_rx_switch_id(tmp_vid); + tmp_vbid = dsa_tag_8021q_rx_vbid(tmp_vid); /* Precise source port information is unknown when receiving from a * VLAN-unaware bridging domain, and tmp_source_port and tmp_switch_id @@ -546,5 +558,15 @@ void dsa_8021q_rcv(struct sk_buff *skb, int *source_port, int *switch_id, *vbid = tmp_vbid; skb->priority = (tci & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT; + return; + +not_tag_8021q: + if (vid) + *vid = tmp_vid; + if (vbid) + *vbid = -1; + + /* Put the tag back */ + __vlan_hwaccel_put_tag(skb, vlan_proto, tci); } EXPORT_SYMBOL_GPL(dsa_8021q_rcv); diff --git a/net/dsa/tag_8021q.h b/net/dsa/tag_8021q.h index 41f7167ac520..0c6671d7c1c2 100644 --- a/net/dsa/tag_8021q.h +++ b/net/dsa/tag_8021q.h @@ -14,7 +14,7 @@ struct sk_buff *dsa_8021q_xmit(struct sk_buff *skb, struct net_device *netdev, u16 tpid, u16 tci); void dsa_8021q_rcv(struct sk_buff *skb, int *source_port, int *switch_id, - int *vbid); + int *vbid, int *vid); struct net_device *dsa_tag_8021q_find_port_by_vbid(struct net_device *conduit, int vbid); diff --git a/net/dsa/tag_ocelot_8021q.c b/net/dsa/tag_ocelot_8021q.c index b059381310fe..8e8b1bef6af6 100644 --- a/net/dsa/tag_ocelot_8021q.c +++ b/net/dsa/tag_ocelot_8021q.c @@ -81,7 +81,7 @@ static struct sk_buff *ocelot_rcv(struct sk_buff *skb, { int src_port, switch_id; - dsa_8021q_rcv(skb, &src_port, &switch_id, NULL); + dsa_8021q_rcv(skb, &src_port, &switch_id, NULL, NULL); skb->dev = dsa_conduit_find_user(netdev, switch_id, src_port); if (!skb->dev) diff --git a/net/dsa/tag_sja1105.c b/net/dsa/tag_sja1105.c index 48886d4b7e3e..7639ccb94d35 100644 --- a/net/dsa/tag_sja1105.c +++ b/net/dsa/tag_sja1105.c @@ -472,37 +472,14 @@ static bool sja1110_skb_has_inband_control_extension(const struct sk_buff *skb) return ntohs(eth_hdr(skb)->h_proto) == ETH_P_SJA1110; } -/* If the VLAN in the packet is a tag_8021q one, set @source_port and - * @switch_id and strip the header. Otherwise set @vid and keep it in the - * packet. - */ -static void sja1105_vlan_rcv(struct sk_buff *skb, int *source_port, - int *switch_id, int *vbid, u16 *vid) -{ - struct vlan_ethhdr *hdr = vlan_eth_hdr(skb); - u16 vlan_tci; - - if (skb_vlan_tag_present(skb)) - vlan_tci = skb_vlan_tag_get(skb); - else - vlan_tci = ntohs(hdr->h_vlan_TCI); - - if (vid_is_dsa_8021q(vlan_tci & VLAN_VID_MASK)) - return dsa_8021q_rcv(skb, source_port, switch_id, vbid); - - /* Try our best with imprecise RX */ - *vid = vlan_tci & VLAN_VID_MASK; -} - static struct sk_buff *sja1105_rcv(struct sk_buff *skb, struct net_device *netdev) { - int source_port = -1, switch_id = -1, vbid = -1; + int source_port = -1, switch_id = -1, vbid = -1, vid = -1; struct sja1105_meta meta = {0}; struct ethhdr *hdr; bool is_link_local; bool is_meta; - u16 vid; hdr = eth_hdr(skb); is_link_local = sja1105_is_link_local(skb); @@ -525,7 +502,7 @@ static struct sk_buff *sja1105_rcv(struct sk_buff *skb, * a tag_8021q VLAN which we have to strip */ if (sja1105_skb_has_tag_8021q(skb)) - sja1105_vlan_rcv(skb, &source_port, &switch_id, &vbid, &vid); + dsa_8021q_rcv(skb, &source_port, &switch_id, &vbid, &vid); else if (source_port == -1 && switch_id == -1) /* Packets with no source information have no chance of * getting accepted, drop them straight away. @@ -660,9 +637,8 @@ static struct sk_buff *sja1110_rcv_inband_control_extension(struct sk_buff *skb, static struct sk_buff *sja1110_rcv(struct sk_buff *skb, struct net_device *netdev) { - int source_port = -1, switch_id = -1, vbid = -1; + int source_port = -1, switch_id = -1, vbid = -1, vid = -1; bool host_only = false; - u16 vid = 0; if (sja1110_skb_has_inband_control_extension(skb)) { skb = sja1110_rcv_inband_control_extension(skb, &source_port, @@ -674,7 +650,7 @@ static struct sk_buff *sja1110_rcv(struct sk_buff *skb, /* Packets with in-band control extensions might still have RX VLANs */ if (likely(sja1105_skb_has_tag_8021q(skb))) - sja1105_vlan_rcv(skb, &source_port, &switch_id, &vbid, &vid); + dsa_8021q_rcv(skb, &source_port, &switch_id, &vbid, &vid); if (vbid >= 1) skb->dev = dsa_tag_8021q_find_port_by_vbid(netdev, vbid); -- 2.34.1