From patchwork Fri Nov 4 17:41:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Chevallier X-Patchwork-Id: 13032455 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4186FC433FE for ; Fri, 4 Nov 2022 17:43:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=35yhBEAOkfRy9kqalj7eqJRKhEqwzyKSRSfRH/mIg+Y=; b=a1KQJz+VyxPFCK KuN/pkcVqIgMsSU2//ZnM0S94v4GcEKMyj8VwZJYb4wwzJ5jAwijmKn13hVf2cq+vCA747AdIlGVE Gr9stzWK/TtgKtr6ABCQfP1gJbO/UXEundgIfa+EOLAbRBqjRbyCNwtRNe48hViuyCUS9ut+QlA3l X8WRszDW6Ez5zjqDx97tO6zDAu9Z7HiMiVJsP3Ro1Zs2u31cayMQMRHJkdOU22Ug9m3FtUaT8i2lq Ignde8TwAUDoWzjzIHpbh3NliX94fj3Ctonclh+0e+6SR424jsufYMJfUQZUT4znr+94iYoLvd2+W b3ypFL1LPSqlhCFv2MXw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1or0hv-004fA5-Q1; Fri, 04 Nov 2022 17:42:19 +0000 Received: from relay9-d.mail.gandi.net ([2001:4b98:dc4:8::229]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1or0hh-004f5g-2C for linux-arm-kernel@lists.infradead.org; Fri, 04 Nov 2022 17:42:07 +0000 Received: (Authenticated sender: maxime.chevallier@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id B1DB1FF80B; Fri, 4 Nov 2022 17:42:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1667583723; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DbNxTyHYW1cIdgfjhvhSwggm97TobHRFI15Lp5bfo6I=; b=HGzW5w0mZDHEbYAWbEDrkB5IaZQyf4qE2MPzaxAL+URQ2h1gw++TIJqiBgO+LTa6HuiuWF +prlUqoZKdZUoJYAfoZFjlTTWV7Nvl13gVpNJGF4amlUhLFmF2sHnTOQ+1u2v3UHde3jsu 3/OfpeU+kYHtjR5h5b/8qHFFEVFZZkinhravxcb8pBa5a3Z9ifigrEzWeyU0v0P5hYwzI1 hxOpfIo1WftzskJUeUYidBdHijnCcPPZALy/hTz958T65tf/tc0B5hErXKux1SSgYC/Apw w4kRBYLAT8UeGbbi9KSIW/OCsKgVGNgV6QqmkN990IrupRPa/9HSJfRbaKTi7w== From: Maxime Chevallier To: davem@davemloft.net, Rob Herring , Krzysztof Kozlowski Cc: Maxime Chevallier , Jakub Kicinski , Eric Dumazet , Paolo Abeni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, thomas.petazzoni@bootlin.com, Andrew Lunn , Florian Fainelli , Heiner Kallweit , Russell King , linux-arm-kernel@lists.infradead.org, Vladimir Oltean , Luka Perkov , Robert Marko , Andy Gross , Bjorn Andersson , Konrad Dybcio Subject: [PATCH net-next v8 4/5] net: ipqess: Add out-of-band DSA tagging support Date: Fri, 4 Nov 2022 18:41:50 +0100 Message-Id: <20221104174151.439008-5-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221104174151.439008-1-maxime.chevallier@bootlin.com> References: <20221104174151.439008-1-maxime.chevallier@bootlin.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221104_104205_427331_DA966027 X-CRM114-Status: GOOD ( 22.49 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On the IPQ4019, there's an 5 ports switch connected to the CPU through the IPQESS Ethernet controller. The way the DSA tag is sent-out to that switch is through the DMA descriptor, due to how tightly it is integrated with the switch. We use the out-of-band tagging protocol by getting the source port from the descriptor, push it into the skb extensions, and have the tagger pull it to infer the destination netdev. The reverse process is done on the TX side, where the driver pulls the tag from the skb and builds the descriptor accordingly. Signed-off-by: Maxime Chevallier --- V7->V8: - No changes V6->V7: - Added proper endianness conversion for descriptor accesses V5->V6: - Fixed the CHANGEUPPER event handling - removed pop/push helpers V4->V5: - Rework the CHANGEUPPER event handling V3->V4: - No changes V2->V3: - No changes V1->V2: - Use the new tagger, and the dsa_oob_tag_* helpers drivers/net/ethernet/qualcomm/Kconfig | 1 + drivers/net/ethernet/qualcomm/ipqess/ipqess.c | 64 ++++++++++++++++++- drivers/net/ethernet/qualcomm/ipqess/ipqess.h | 4 ++ 3 files changed, 68 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/qualcomm/Kconfig b/drivers/net/ethernet/qualcomm/Kconfig index 28861bca5a5b..7eda94131cb1 100644 --- a/drivers/net/ethernet/qualcomm/Kconfig +++ b/drivers/net/ethernet/qualcomm/Kconfig @@ -64,6 +64,7 @@ config QCOM_IPQ4019_ESS_EDMA tristate "Qualcomm Atheros IPQ4019 ESS EDMA support" depends on (OF && ARCH_QCOM) || COMPILE_TEST select PHYLINK + select NET_DSA_TAG_OOB help This driver supports the Qualcomm Atheros IPQ40xx built-in ESS EDMA ethernet controller. diff --git a/drivers/net/ethernet/qualcomm/ipqess/ipqess.c b/drivers/net/ethernet/qualcomm/ipqess/ipqess.c index df3f2ce77065..a2385d6407b3 100644 --- a/drivers/net/ethernet/qualcomm/ipqess/ipqess.c +++ b/drivers/net/ethernet/qualcomm/ipqess/ipqess.c @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -22,6 +23,7 @@ #include #include #include +#include #include #include "ipqess.h" @@ -327,6 +329,7 @@ static int ipqess_rx_poll(struct ipqess_rx_ring *rx_ring, int budget) tail &= IPQESS_RFD_CONS_IDX_MASK; while (done < budget) { + struct dsa_oob_tag_info *tag_info; struct ipqess_rx_desc *rd; struct sk_buff *skb; @@ -406,6 +409,12 @@ static int ipqess_rx_poll(struct ipqess_rx_ring *rx_ring, int budget) __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021AD), le16_to_cpu(rd->rrd4)); + if (likely(rx_ring->ess->dsa_ports)) { + tag_info = skb_ext_add(skb, SKB_EXT_DSA_OOB); + tag_info->port = FIELD_GET(IPQESS_RRD_PORT_ID_MASK, + le16_to_cpu(rd->rrd1)); + } + napi_gro_receive(&rx_ring->napi_rx, skb); rx_ring->ess->stats.rx_packets++; @@ -706,6 +715,23 @@ static void ipqess_rollback_tx(struct ipqess *eth, tx_ring->head = start_index; } +static void ipqess_process_dsa_tag_sh(struct ipqess *ess, struct sk_buff *skb, + u32 *word3) +{ + struct dsa_oob_tag_info *tag_info; + + if (unlikely(!ess->dsa_ports)) + return; + + tag_info = skb_ext_find(skb, SKB_EXT_DSA_OOB); + if (!tag_info) + return; + + *word3 |= tag_info->port << IPQESS_TPD_PORT_BITMAP_SHIFT; + *word3 |= BIT(IPQESS_TPD_FROM_CPU_SHIFT); + *word3 |= 0x3e << IPQESS_TPD_PORT_BITMAP_SHIFT; +} + static int ipqess_tx_map_and_fill(struct ipqess_tx_ring *tx_ring, struct sk_buff *skb) { @@ -716,6 +742,8 @@ static int ipqess_tx_map_and_fill(struct ipqess_tx_ring *tx_ring, u16 len; int i; + ipqess_process_dsa_tag_sh(tx_ring->ess, skb, &word3); + if (skb_is_gso(skb)) { if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4) { lso_word1 |= IPQESS_TPD_IPV4_EN; @@ -917,6 +945,33 @@ static const struct net_device_ops ipqess_axi_netdev_ops = { .ndo_tx_timeout = ipqess_tx_timeout, }; +static int ipqess_netdevice_event(struct notifier_block *nb, + unsigned long event, void *ptr) +{ + struct ipqess *ess = container_of(nb, struct ipqess, netdev_notifier); + struct net_device *dev = netdev_notifier_info_to_dev(ptr); + struct netdev_notifier_changeupper_info *info; + + if (dev != ess->netdev) + return NOTIFY_DONE; + + switch (event) { + case NETDEV_CHANGEUPPER: + info = ptr; + + if (!dsa_slave_dev_check(info->upper_dev)) + return NOTIFY_DONE; + + if (info->linking) + ess->dsa_ports++; + else + ess->dsa_ports--; + + return NOTIFY_DONE; + } + return NOTIFY_OK; +} + static void ipqess_hw_stop(struct ipqess *ess) { int i; @@ -1184,12 +1239,19 @@ static int ipqess_axi_probe(struct platform_device *pdev) netif_napi_add(netdev, &ess->rx_ring[i].napi_rx, ipqess_rx_napi); } - err = register_netdev(netdev); + ess->netdev_notifier.notifier_call = ipqess_netdevice_event; + err = register_netdevice_notifier(&ess->netdev_notifier); if (err) goto err_hw_stop; + err = register_netdev(netdev); + if (err) + goto err_notifier_unregister; + return 0; +err_notifier_unregister: + unregister_netdevice_notifier(&ess->netdev_notifier); err_hw_stop: ipqess_hw_stop(ess); diff --git a/drivers/net/ethernet/qualcomm/ipqess/ipqess.h b/drivers/net/ethernet/qualcomm/ipqess/ipqess.h index dae17f3a23e4..5999a3b26235 100644 --- a/drivers/net/ethernet/qualcomm/ipqess/ipqess.h +++ b/drivers/net/ethernet/qualcomm/ipqess/ipqess.h @@ -171,6 +171,10 @@ struct ipqess { struct platform_device *pdev; struct phylink *phylink; struct phylink_config phylink_config; + + struct notifier_block netdev_notifier; + int dsa_ports; + struct ipqess_tx_ring tx_ring[IPQESS_NETDEV_QUEUES]; struct ipqess_statistics ipqess_stats;