Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2938957lqp; Mon, 25 Mar 2024 13:48:21 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWwnseIs97D4pSBBo1QUItIE8c3IB9KKaoYAVeea1BZXFM8yCI94hl9hduiHilm5s4oTrHvQFw6YE3nPK1aAKECxUla6L6Pq/aYOuTunw== X-Google-Smtp-Source: AGHT+IHB9vXp8/MJG+o1nZ6JbnnmRqUnihpbJdPHH+mhEA8rif5SI6GxE52wrCiY7RE8UElhRtw1 X-Received: by 2002:a17:907:944f:b0:a49:452d:e722 with SMTP id dl15-20020a170907944f00b00a49452de722mr3701379ejc.29.1711399701357; Mon, 25 Mar 2024 13:48:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711399701; cv=pass; d=google.com; s=arc-20160816; b=R4EQrotT5mAMVfTw4xkuMmvaCnJjK7G8R5W9OuRl/QnpdKwPqD5/YWhqkPE3sUuRkv Jg/n9p9M6BjTZO8r1SxykVhkQN7CZsCCObhA1mXVG96fHzyECXTU0+ikoHZzTDLBgH+U KXqYmn7dsXgPmQeq7kNGAngCq7/U+N1uJj5VHZLzXP/vrJtTCS1atKAXK6Fcn4M0TYTv m7SLbeF+vMDKKhraF8+KVWNmgLSdrqCb8IOmaSPMYQnnxD1s63rLAeSjAkEVbkGaApoy 1UPhtXftN0lvWOLU3ycnilCokqP9Rqf0pZTZY3dTf8Z/8eesNYcfjvvMjpsJiK+amsoa aJPQ== 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=6tG75z9PFe35m2y550RzYH/uskT5uLKYmRA0ol34i+U=; fh=KTAYG+Y3pLrixTbVGjO7WR6G3A7Ko1TXRj15CxKlaxk=; b=oEvd6geNjFFfGA41yQHAiiHxzwqKoMu6SV6TbAcriQ2zrTugggdh61zLCObJeMskv9 gyz7vA/OZEoWad07bQ1S0pRdvNmb4K7gac7rERm+8hcpgFKjAoqgN702aJSYk2a83CPO cFxzwoKDsT2XlTY0FT/yZ6LJSIsz8OuzOtF4FYho44BpvbPlSbKhEmgqtRBlXQiaOSvC +6BInu5a65toh0Q8497STk7wuxkP6B3vhxhbFfoVvAMLPtDNMxT3RKtrQNPzCEdtKwWk Ilsb24NG/zo+24q0+gd4fAFlX0feJv7uECZL0OdVa3ww6354Qv1xG+LCdpM8BSLA9zb9 HoNw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=LTkne9bF; 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-117971-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-117971-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id qk19-20020a1709077f9300b00a4748ca721csi2349087ejc.439.2024.03.25.13.48.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 13:48:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-117971-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=LTkne9bF; 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-117971-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-117971-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 4A1911F2C689 for ; Mon, 25 Mar 2024 20:48:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1069082877; Mon, 25 Mar 2024 20:45:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LTkne9bF" Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.46]) (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 0386F80033; Mon, 25 Mar 2024 20:45:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711399512; cv=none; b=XV7r/AvY2qTuPi49DfE1Kg1/mVPwz6kKWxE6kR8YKxdpWaZFZBoE5DgbYQNOqi35S4vtLNkZAMiNp6yZPabnrvNR9gl7KXUUc9rqatsByTmzKNUGVj0o0pu08LVptbZAWBjO07iOEX2fVsV5QFmERnK6a+OiFDTWLaPua/smIDM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711399512; c=relaxed/simple; bh=EWKoIDVF8fm0QYl3FNRQ3+x62OTfQHW818wFLTOSGtc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=B8ug2JhdJuy1iQ4iXIv9Eu31ZbCnWk2ag3KodllAVXVGG2LtfbuhFbimJJu0rw8VK5ZcXqja9/I0vNqEEQRCqTbaNwKbqA/dkUqPyIUyEf+dCOWERM5HPFvOGFtab58l5l9vd+y9+rMLn6s8Uq0Oa7ZwR8ZUlVPfY8EREfB2l68= 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=LTkne9bF; arc=none smtp.client-ip=209.85.208.46 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-ed1-f46.google.com with SMTP id 4fb4d7f45d1cf-56899d9bf52so6072581a12.2; Mon, 25 Mar 2024 13:45:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711399509; x=1712004309; 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=6tG75z9PFe35m2y550RzYH/uskT5uLKYmRA0ol34i+U=; b=LTkne9bFzs6Mxdpmm+FpKwjFaPfnZSsydogFLtlNeZ2n9GSmPNAKkGIXh4H7ScrbNq FWfshaxffIXFieKF0JDmyKiXryxVmj8KWUWi+VlLbxSS50Cyp2G9Os8txcA4DphRRwy9 F8f96bbzcE+Vz5Re/kIkB/rSJWun7Zjwpdji8bLbKBUWPsoed47h6+bH0XiTUNXskmwE PF1MwQPj3yCKElnzYtj4JPrCL5vFNmsqzkkM0HPwkDwLGQ60JYa/pytJswHsenm9QaCT dPyoSkMpIUAAVfmhkBbpytmTEnCVt019jdNQqoU3j2z0a4sg8hCvchxjRqLRFpfvmMUA QS1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711399509; x=1712004309; 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=6tG75z9PFe35m2y550RzYH/uskT5uLKYmRA0ol34i+U=; b=rAt/RZ1vcjb2C66J0qZ9VZFFMB7kkuQbZU6LW/f5TrL9GWEQchMCSV6lGm0zHOfI9Q TrSwchF8fjy3SBfp6uFRxju4Zhm2Z7rbJT2Rd6mts50DSmIMAHnAnjRukCPLKWX9Afiu jfFo6Nsp2blq9SuCwIqE4jRnH1j/nfHIqjJD/muNqRJjTepEhBYPwgZr70k70W0HJ2sc RkTaDz1/iw9Km9M72n5Ms73r0MDMl7iGiZV7QJG662e+QuSFbA4OOgE3MAjRHrt+BTyM M4P2ULpG7aNWslInr+5/pCCG9TOGenKeJIbp8G3Az46rIVQN6ojSktFxRDvP4KudvXYr v/Yg== X-Forwarded-Encrypted: i=1; AJvYcCXJX+5XWm6GFiLxQ2jSCidGKY7/H9qukfnJbjW8jKCIgt9BsTFdVMomMnP/sFmEwJaQHO8MNp42xPO8HIOg3O94FAhMHI/x45UmwWQp X-Gm-Message-State: AOJu0Yxfimw9dzRX6Y1LY6oFfXYkf3Iqj2pEhVkW4XB4gUbf3zYZtU82 8a+YaKhv+bZZqQdyg7KbEMEKoaXikg54T68pmI7sPWQyZ92cKaENKvhPcG/O3lA= X-Received: by 2002:a50:ab4d:0:b0:56b:cf40:f6fb with SMTP id t13-20020a50ab4d000000b0056bcf40f6fbmr6015029edc.6.1711399508899; Mon, 25 Mar 2024 13:45:08 -0700 (PDT) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id k18-20020a056402049200b0056c1cba8480sm591751edv.25.2024.03.25.13.45.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 13:45:08 -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 v7 09/16] net: dsa: tag_sja1105: absorb entire sja1105_vlan_rcv() into dsa_8021q_rcv() Date: Mon, 25 Mar 2024 21:43:34 +0100 Message-Id: <20240325204344.2298241-10-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240325204344.2298241-1-paweldembicki@gmail.com> References: <20240325204344.2298241-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 --- 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