From patchwork Sat Feb 13 22:37:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12087055 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 667FEC433DB for ; Sat, 13 Feb 2021 22:40:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4183864E3F for ; Sat, 13 Feb 2021 22:40:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229862AbhBMWkG (ORCPT ); Sat, 13 Feb 2021 17:40:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229789AbhBMWjm (ORCPT ); Sat, 13 Feb 2021 17:39:42 -0500 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F6C6C061793 for ; Sat, 13 Feb 2021 14:38:28 -0800 (PST) Received: by mail-ed1-x536.google.com with SMTP id o3so1903369edv.4 for ; Sat, 13 Feb 2021 14:38:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CD62OzZ1PxX5rU56KuWkRmROPrc11d6+ChKGcjktbXE=; b=MF6ZmP4Rep4yIwQUoqmw3/7oY8LZC+INs1axqMbtYP6jgPCaUT1fUL9WspX4P9hXpQ f+GiAlwjyPfDmZ00uVDRoXp8pSmS3pJeJ0NK0dyBDX7PDPXqoQR53JJCUnGzV8BnCjj7 zyuL+CU2Bg4ZcK/lkqiNKoIEl7Q6s7laH/Voj5j15vPrrgrs91sG/X6C39sEVjO6tNNG cE7gkU8VG/kPpu/8Inv0dF4lvq9cAZU0VFp5xEteJhpy3Ii7SAOX5hS56M2mi8MERycl PwD1pLWkomA0iO8MP5CdZeV1BJfkXIBb9MXkyWM43I6ZMzAMIGSATI8Lfx0uE8d4OMfw cm7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CD62OzZ1PxX5rU56KuWkRmROPrc11d6+ChKGcjktbXE=; b=lLvpHWOsDaJh7ebjJpSXljWNBFpHMIVELpwggAh5M0hwSL4hZckJfwmEDuckSgMEdV MfBbmBBz61ZbpohqCa0LQ7jnDxYM/d2cyj+Okp5TNJiq9mUB+OyzF7goAn7OWFeN5/Ia pc3EiCERIvBlMomCvVfKYi6CPVCqdF2+/l3TQvkWz5lLszAznOvXVV1fmqQyT/cwfE9R 2zjx7Z8RQulEMuLgHq5fgcgTH8r6qTzD9UB6ZoeBk+BIRD7xMuCuf5Mc0o5j1gQEmxtL p94UReZgXBUyi/7hHArAUXkVflZUzjuHEZ7En/frrexZWWrU6xRMf3eN92tKV7dL07Cx B/Eg== X-Gm-Message-State: AOAM533wR6lNyuGpSIMpbjaLbNdLWTL1+/rTcs8HfsCiwswo33vAL9vs pumbbLhjTvIDtgbNOmzeXxk= X-Google-Smtp-Source: ABdhPJxSRR+QpKuhH08L2fn2HlBxZdE3XbbW72vly/kggOlxb39yyS9dB97LR8ujF8iQpdhSLAH4HQ== X-Received: by 2002:aa7:c247:: with SMTP id y7mr638495edo.350.1613255907256; Sat, 13 Feb 2021 14:38:27 -0800 (PST) Received: from localhost.localdomain (5-12-227-87.residential.rdsnet.ro. [5.12.227.87]) by smtp.gmail.com with ESMTPSA id h3sm7662582edw.18.2021.02.13.14.38.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Feb 2021 14:38:26 -0800 (PST) From: Vladimir Oltean To: "David S . Miller" , Jakub Kicinski , netdev@vger.kernel.org Cc: Andrew Lunn , Florian Fainelli , Vivien Didelot , Richard Cochran , Claudiu Manoil , Alexandre Belloni , Vladimir Oltean , Maxim Kochetkov , UNGLinuxDriver@microchip.com Subject: [PATCH v2 net-next 08/12] net: dsa: tag_ocelot: single out PTP-related transmit tag processing Date: Sun, 14 Feb 2021 00:37:57 +0200 Message-Id: <20210213223801.1334216-9-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210213223801.1334216-1-olteanv@gmail.com> References: <20210213223801.1334216-1-olteanv@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Vladimir Oltean There is one place where we cannot avoid accessing driver data, and that is 2-step PTP TX timestamping, since the switch wants us to provide a timestamp request ID through the injection header, which naturally must come from a sequence number kept by the driver (it is generated by the .port_txtstamp method prior to the tagger's xmit). However, since other drivers like dsa_loop do not claim PTP support anyway, the DSA_SKB_CB(skb)->clone will always be NULL anyway, so if we move all PTP-related dereferences of struct ocelot and struct ocelot_port into a separate function, we can effectively ensure that this is dead code when the ocelot tagger is attached to non-ocelot switches, and the stateful portion of the tagger is more self-contained. Signed-off-by: Vladimir Oltean Reviewed-by: Florian Fainelli --- Changes in v2: None. net/dsa/tag_ocelot.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/net/dsa/tag_ocelot.c b/net/dsa/tag_ocelot.c index 8ce0b26f3520..fe00519229d7 100644 --- a/net/dsa/tag_ocelot.c +++ b/net/dsa/tag_ocelot.c @@ -5,6 +5,25 @@ #include #include "dsa_priv.h" +static void ocelot_xmit_ptp(struct dsa_port *dp, void *injection, + struct sk_buff *clone) +{ + struct ocelot *ocelot = dp->ds->priv; + struct ocelot_port *ocelot_port; + u64 rew_op; + + ocelot_port = ocelot->ports[dp->index]; + rew_op = ocelot_port->ptp_cmd; + + /* Retrieve timestamp ID populated inside skb->cb[0] of the + * clone by ocelot_port_add_txtstamp_skb + */ + if (ocelot_port->ptp_cmd == IFH_REW_OP_TWO_STEP_PTP) + rew_op |= clone->cb[0] << 3; + + ocelot_ifh_set_rew_op(injection, rew_op); +} + static struct sk_buff *ocelot_xmit(struct sk_buff *skb, struct net_device *netdev) { @@ -29,17 +48,8 @@ static struct sk_buff *ocelot_xmit(struct sk_buff *skb, ocelot_ifh_set_qos_class(injection, skb->priority); /* TX timestamping was requested */ - if (clone) { - u64 rew_op = ocelot_port->ptp_cmd; - - /* Retrieve timestamp ID populated inside skb->cb[0] of the - * clone by ocelot_port_add_txtstamp_skb - */ - if (ocelot_port->ptp_cmd == IFH_REW_OP_TWO_STEP_PTP) - rew_op |= clone->cb[0] << 3; - - ocelot_ifh_set_rew_op(injection, rew_op); - } + if (clone) + ocelot_xmit_ptp(dp, injection, clone); return skb; }