From patchwork Mon Sep 19 11:08:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mattias Forsblad X-Patchwork-Id: 12980258 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 27A62ECAAD3 for ; Mon, 19 Sep 2022 11:09:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230035AbiISLI7 (ORCPT ); Mon, 19 Sep 2022 07:08:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229951AbiISLIz (ORCPT ); Mon, 19 Sep 2022 07:08:55 -0400 Received: from mail-lj1-x22c.google.com (mail-lj1-x22c.google.com [IPv6:2a00:1450:4864:20::22c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1423FE033 for ; Mon, 19 Sep 2022 04:08:54 -0700 (PDT) Received: by mail-lj1-x22c.google.com with SMTP id x29so1174487ljq.2 for ; Mon, 19 Sep 2022 04:08:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=rHijr2ch72XoPSWjRPVH55t6Rl/DFMQFaFbzLh8hqxw=; b=h2YEtFOLru5mfqjJ7h66zipCLipS3zIMqh5UmgAOO32aJAbgah6NAVCiXuVtDpo1a8 4JjyZO4a3j1Aig5AW+0SmFZ1BN8T0Y6TX9IX0Ta3OTb5fEsvnn3ODrlo6iUur5aJlT04 Sen6zB5XS5bTYKdCHUDo4VLF0VNxQbIepSiWPOdLt5vf0LyxkIuzS/g8tkp/D7x+teQu 1ptp4YjZMA/ucCxJdIW/KFIjlRqor9PFma43qpIDBqMoYuSnMw4pHV8qixrZ98WEre7X 6W05lLsK3IbJH1WyQeWRWiLq+tr2UC/eZ/qkJ5NF5V94T8tzVaY4hhmWxpOXIMlaBjto pNsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=rHijr2ch72XoPSWjRPVH55t6Rl/DFMQFaFbzLh8hqxw=; b=XTbkDTWl5mc/6+SItZK218IQhOuwICVwvRmN3gRM9aGiIKyLDlaVFk8vYBxqYkeQzc ace9NR45uwiQTsyY4OLDeq1Wq23f8khmGlR6UwWvi0beflpCpm9tT+E+ovFlzqck6rZ3 iRDdFc5nLia3TLuF+kZHJLPR+7slkXNl7cIdkGMYOEP4L4DuC4DdhtHa6aLOM7A/W0Uw 8WX2jVoamqjHe7G0zodGJP54lfRm7Bh+XYc1rlL21NQyieugcNQYFdJu+x0hxpKXhO9+ TpMI3BvShqqvTYBVQSn1Q1Z8ahDtlvhvZzZ4utQ6tqElW9Ic8u9yif5bvDIzgtaFF73L SAfg== X-Gm-Message-State: ACrzQf3WnC3G4zakSTnzmtDECdMnPTyP8XlUyuxu3cU/FwfpbdgJnIw0 bmjZef0UqhAzZLTghqHfBD8GqMQkgNdF4A== X-Google-Smtp-Source: AMsMyM7YlfTaHjfvjRwhdzrWs8t6a8Mu9ZrRG4iyB8Ut1pzUGBLRDxSuILSF3YvbX2e8+ISZsILAPw== X-Received: by 2002:a2e:9005:0:b0:26c:14d9:cea0 with SMTP id h5-20020a2e9005000000b0026c14d9cea0mr4651331ljg.300.1663585732132; Mon, 19 Sep 2022 04:08:52 -0700 (PDT) Received: from wse-c0089.westermo.com (h-98-128-229-160.NA.cust.bahnhof.se. [98.128.229.160]) by smtp.gmail.com with ESMTPSA id t13-20020a05651c204d00b00266d3f689e1sm4879261ljo.43.2022.09.19.04.08.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Sep 2022 04:08:51 -0700 (PDT) From: Mattias Forsblad To: netdev@vger.kernel.org Cc: Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux@armlinux.org.uk, ansuelsmth@gmail.com, Mattias Forsblad Subject: [PATCH net-next v14 1/7] net: dsa: mv88e6xxx: Add RMU enable for select switches. Date: Mon, 19 Sep 2022 13:08:41 +0200 Message-Id: <20220919110847.744712-2-mattias.forsblad@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220919110847.744712-1-mattias.forsblad@gmail.com> References: <20220919110847.744712-1-mattias.forsblad@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Add RMU enable functionality for some Marvell SOHO switches. Reviewed-by: Andrew Lunn Reviewed-by: Florian Fainelli Signed-off-by: Mattias Forsblad --- drivers/net/dsa/mv88e6xxx/chip.c | 6 +++ drivers/net/dsa/mv88e6xxx/chip.h | 1 + drivers/net/dsa/mv88e6xxx/global1.c | 64 +++++++++++++++++++++++++++++ drivers/net/dsa/mv88e6xxx/global1.h | 3 ++ 4 files changed, 74 insertions(+) diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c index 6f4ea39ab466..46e12b53a9e4 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.c +++ b/drivers/net/dsa/mv88e6xxx/chip.c @@ -4098,6 +4098,7 @@ static const struct mv88e6xxx_ops mv88e6085_ops = { .ppu_disable = mv88e6185_g1_ppu_disable, .reset = mv88e6185_g1_reset, .rmu_disable = mv88e6085_g1_rmu_disable, + .rmu_enable = mv88e6085_g1_rmu_enable, .vtu_getnext = mv88e6352_g1_vtu_getnext, .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge, .stu_getnext = mv88e6352_g1_stu_getnext, @@ -4181,6 +4182,7 @@ static const struct mv88e6xxx_ops mv88e6097_ops = { .pot_clear = mv88e6xxx_g2_pot_clear, .reset = mv88e6352_g1_reset, .rmu_disable = mv88e6085_g1_rmu_disable, + .rmu_enable = mv88e6085_g1_rmu_enable, .vtu_getnext = mv88e6352_g1_vtu_getnext, .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge, .phylink_get_caps = mv88e6095_phylink_get_caps, @@ -5300,6 +5302,7 @@ static const struct mv88e6xxx_ops mv88e6352_ops = { .pot_clear = mv88e6xxx_g2_pot_clear, .reset = mv88e6352_g1_reset, .rmu_disable = mv88e6352_g1_rmu_disable, + .rmu_enable = mv88e6352_g1_rmu_enable, .atu_get_hash = mv88e6165_g1_atu_get_hash, .atu_set_hash = mv88e6165_g1_atu_set_hash, .vtu_getnext = mv88e6352_g1_vtu_getnext, @@ -5367,6 +5370,7 @@ static const struct mv88e6xxx_ops mv88e6390_ops = { .pot_clear = mv88e6xxx_g2_pot_clear, .reset = mv88e6352_g1_reset, .rmu_disable = mv88e6390_g1_rmu_disable, + .rmu_enable = mv88e6390_g1_rmu_enable, .atu_get_hash = mv88e6165_g1_atu_get_hash, .atu_set_hash = mv88e6165_g1_atu_set_hash, .vtu_getnext = mv88e6390_g1_vtu_getnext, @@ -5434,6 +5438,7 @@ static const struct mv88e6xxx_ops mv88e6390x_ops = { .pot_clear = mv88e6xxx_g2_pot_clear, .reset = mv88e6352_g1_reset, .rmu_disable = mv88e6390_g1_rmu_disable, + .rmu_enable = mv88e6390_g1_rmu_enable, .atu_get_hash = mv88e6165_g1_atu_get_hash, .atu_set_hash = mv88e6165_g1_atu_set_hash, .vtu_getnext = mv88e6390_g1_vtu_getnext, @@ -5504,6 +5509,7 @@ static const struct mv88e6xxx_ops mv88e6393x_ops = { .pot_clear = mv88e6xxx_g2_pot_clear, .reset = mv88e6352_g1_reset, .rmu_disable = mv88e6390_g1_rmu_disable, + .rmu_enable = mv88e6390_g1_rmu_enable, .atu_get_hash = mv88e6165_g1_atu_get_hash, .atu_set_hash = mv88e6165_g1_atu_set_hash, .vtu_getnext = mv88e6390_g1_vtu_getnext, diff --git a/drivers/net/dsa/mv88e6xxx/chip.h b/drivers/net/dsa/mv88e6xxx/chip.h index e693154cf803..7ce3c41f6caf 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.h +++ b/drivers/net/dsa/mv88e6xxx/chip.h @@ -637,6 +637,7 @@ struct mv88e6xxx_ops { /* Remote Management Unit operations */ int (*rmu_disable)(struct mv88e6xxx_chip *chip); + int (*rmu_enable)(struct mv88e6xxx_chip *chip, int port); /* Precision Time Protocol operations */ const struct mv88e6xxx_ptp_ops *ptp_ops; diff --git a/drivers/net/dsa/mv88e6xxx/global1.c b/drivers/net/dsa/mv88e6xxx/global1.c index 5848112036b0..1b3a3218c0b5 100644 --- a/drivers/net/dsa/mv88e6xxx/global1.c +++ b/drivers/net/dsa/mv88e6xxx/global1.c @@ -466,18 +466,82 @@ int mv88e6085_g1_rmu_disable(struct mv88e6xxx_chip *chip) MV88E6085_G1_CTL2_RM_ENABLE, 0); } +int mv88e6085_g1_rmu_enable(struct mv88e6xxx_chip *chip, int port) +{ + int val = MV88E6352_G1_CTL2_RMU_MODE_DISABLED; + + switch (port) { + case 9: + val = MV88E6085_G1_CTL2_RM_ENABLE; + break; + case 10: + val = MV88E6085_G1_CTL2_RM_ENABLE | MV88E6085_G1_CTL2_P10RM; + break; + default: + return -EOPNOTSUPP; + } + + return mv88e6xxx_g1_ctl2_mask(chip, MV88E6085_G1_CTL2_P10RM | + MV88E6085_G1_CTL2_RM_ENABLE, val); +} + int mv88e6352_g1_rmu_disable(struct mv88e6xxx_chip *chip) { return mv88e6xxx_g1_ctl2_mask(chip, MV88E6352_G1_CTL2_RMU_MODE_MASK, MV88E6352_G1_CTL2_RMU_MODE_DISABLED); } +int mv88e6352_g1_rmu_enable(struct mv88e6xxx_chip *chip, int port) +{ + int val = MV88E6352_G1_CTL2_RMU_MODE_DISABLED; + + switch (port) { + case 4: + val = MV88E6352_G1_CTL2_RMU_MODE_PORT_4; + break; + case 5: + val = MV88E6352_G1_CTL2_RMU_MODE_PORT_5; + break; + case 6: + val = MV88E6352_G1_CTL2_RMU_MODE_PORT_6; + break; + default: + return -EOPNOTSUPP; + } + + return mv88e6xxx_g1_ctl2_mask(chip, MV88E6352_G1_CTL2_RMU_MODE_MASK, val); +} + int mv88e6390_g1_rmu_disable(struct mv88e6xxx_chip *chip) { return mv88e6xxx_g1_ctl2_mask(chip, MV88E6390_G1_CTL2_RMU_MODE_MASK, MV88E6390_G1_CTL2_RMU_MODE_DISABLED); } +int mv88e6390_g1_rmu_enable(struct mv88e6xxx_chip *chip, int port) +{ + int val = MV88E6390_G1_CTL2_RMU_MODE_DISABLED; + + switch (port) { + case 0: + val = MV88E6390_G1_CTL2_RMU_MODE_PORT_0; + break; + case 1: + val = MV88E6390_G1_CTL2_RMU_MODE_PORT_1; + break; + case 9: + val = MV88E6390_G1_CTL2_RMU_MODE_PORT_9; + break; + case 10: + val = MV88E6390_G1_CTL2_RMU_MODE_PORT_10; + break; + default: + return -EOPNOTSUPP; + } + + return mv88e6xxx_g1_ctl2_mask(chip, MV88E6390_G1_CTL2_RMU_MODE_MASK, val); +} + int mv88e6390_g1_stats_set_histogram(struct mv88e6xxx_chip *chip) { return mv88e6xxx_g1_ctl2_mask(chip, MV88E6390_G1_CTL2_HIST_MODE_MASK, diff --git a/drivers/net/dsa/mv88e6xxx/global1.h b/drivers/net/dsa/mv88e6xxx/global1.h index 65958b2a0d3a..b9aa66712037 100644 --- a/drivers/net/dsa/mv88e6xxx/global1.h +++ b/drivers/net/dsa/mv88e6xxx/global1.h @@ -313,8 +313,11 @@ int mv88e6250_g1_ieee_pri_map(struct mv88e6xxx_chip *chip); int mv88e6185_g1_set_cascade_port(struct mv88e6xxx_chip *chip, int port); int mv88e6085_g1_rmu_disable(struct mv88e6xxx_chip *chip); +int mv88e6085_g1_rmu_enable(struct mv88e6xxx_chip *chip, int port); int mv88e6352_g1_rmu_disable(struct mv88e6xxx_chip *chip); +int mv88e6352_g1_rmu_enable(struct mv88e6xxx_chip *chip, int port); int mv88e6390_g1_rmu_disable(struct mv88e6xxx_chip *chip); +int mv88e6390_g1_rmu_enable(struct mv88e6xxx_chip *chip, int port); int mv88e6xxx_g1_set_device_number(struct mv88e6xxx_chip *chip, int index); From patchwork Mon Sep 19 11:08:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mattias Forsblad X-Patchwork-Id: 12980257 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A78CEC54EE9 for ; Mon, 19 Sep 2022 11:08:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229992AbiISLI6 (ORCPT ); Mon, 19 Sep 2022 07:08:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229960AbiISLIz (ORCPT ); Mon, 19 Sep 2022 07:08:55 -0400 Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [IPv6:2a00:1450:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5ED5E03C for ; Mon, 19 Sep 2022 04:08:54 -0700 (PDT) Received: by mail-lf1-x12e.google.com with SMTP id s6so35121009lfo.7 for ; Mon, 19 Sep 2022 04:08:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=ygTxP1R89jRodLSMaZ5umXgwdbn+zdw9an2P2JOV6+Q=; b=pc0+QCAGiVNaE23IqtysKPw8Ch3HDcsW5KXzRut7Iv1uboBD9eHlOE7I/PK8pSNmHi cXSLASLBlyovycETtkl1GNCWkG0kY0Ji4WPyY0DO9oAxDjSYeAc+L4BCn4SUYJKTHF1+ TFwN+leTLrUbqUjcwY7FvHMEXQEmhFPWxcReV0gCkeEukcUwlTq14nIyQxPydpwgVX21 3ACZi2JXHomPibr4STw+rDxEfrkMyQkSjAqrNcv55OQv+yz/1aL332Q3aWlvz3xordmJ MAZ4U/seBYZo4ZC6fMM7f+vh63np1XRPIMH0Rx5u4dAionklqVrcziJvZ+RDoD65vNOI c9SA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=ygTxP1R89jRodLSMaZ5umXgwdbn+zdw9an2P2JOV6+Q=; b=6zCXnOMz1fQw+7L+RW+HREt0Z1GiYlAvKqhL6esGTD5eBE8fgC4s92Sjf2SvP5uw81 3b58WsPtoi34q/1tpJbLf52kmanV3lWEGxGVXxr5f/4s+A5DtnJnyfqe8+zFPSL8U0np 8k4p6331VPYIfs1diSqGMrMzvlDOaJPF4q75QAaqbhOvTvBnluDHSRky5C+11A4Y6EYx 9S1Nhlu5XeeBpftGGUxWAAGlmHUnL9jN2vseTVr2e7lf9VdfVzyXqGupJKu6K+o1Zp/h mb1XRPtA5MCQdSHSQC3Sa67I3InjfyIZ5oHSTW1v7W0mGYmDe5o8UwYj4ELZXxA2EOMy VZwQ== X-Gm-Message-State: ACrzQf1GWPXI3eZq6B/3vaRc3nhGXZ9oFbeMFbW+K65R8IjNUS29WCbM 0H0TU2d+Unt+MK8iEv8N6JBhge1g2iWnhQ== X-Google-Smtp-Source: AMsMyM4SYa8h2DpwjbsnvWoqnQlLegJ6jRxJqE+Ci2JrZ9r0T2mrPMg27fBiM3mHa8NYeHvtaI7ZkA== X-Received: by 2002:a05:6512:a89:b0:49d:b866:6330 with SMTP id m9-20020a0565120a8900b0049db8666330mr5696115lfu.346.1663585732912; Mon, 19 Sep 2022 04:08:52 -0700 (PDT) Received: from wse-c0089.westermo.com (h-98-128-229-160.NA.cust.bahnhof.se. [98.128.229.160]) by smtp.gmail.com with ESMTPSA id t13-20020a05651c204d00b00266d3f689e1sm4879261ljo.43.2022.09.19.04.08.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Sep 2022 04:08:52 -0700 (PDT) From: Mattias Forsblad To: netdev@vger.kernel.org Cc: Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux@armlinux.org.uk, ansuelsmth@gmail.com, Mattias Forsblad Subject: [PATCH net-next v14 2/7] net: dsa: Add convenience functions for frame handling Date: Mon, 19 Sep 2022 13:08:42 +0200 Message-Id: <20220919110847.744712-3-mattias.forsblad@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220919110847.744712-1-mattias.forsblad@gmail.com> References: <20220919110847.744712-1-mattias.forsblad@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Add common control functions for drivers that need to send and wait for control frames. Reviewed-by: Florian Fainelli Signed-off-by: Mattias Forsblad --- include/net/dsa.h | 11 +++++++++++ net/dsa/dsa.c | 17 +++++++++++++++++ net/dsa/dsa2.c | 2 ++ 3 files changed, 30 insertions(+) diff --git a/include/net/dsa.h b/include/net/dsa.h index f2ce12860546..08f3fff5f4df 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -495,6 +495,8 @@ struct dsa_switch { unsigned int max_num_bridges; unsigned int num_ports; + + struct completion inband_done; }; static inline struct dsa_port *dsa_to_port(struct dsa_switch *ds, int p) @@ -1390,6 +1392,15 @@ void dsa_tag_drivers_register(struct dsa_tag_driver *dsa_tag_driver_array[], void dsa_tag_drivers_unregister(struct dsa_tag_driver *dsa_tag_driver_array[], unsigned int count); +int dsa_switch_inband_tx(struct dsa_switch *ds, struct sk_buff *skb, + struct completion *completion, unsigned long timeout); + +static inline void dsa_switch_inband_complete(struct dsa_switch *ds, struct completion *completion) +{ + /* Custom completion? */ + complete(completion ?: &ds->inband_done); +} + #define dsa_tag_driver_module_drivers(__dsa_tag_drivers_array, __count) \ static int __init dsa_tag_driver_module_init(void) \ { \ diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c index be7b320cda76..ad870494d68b 100644 --- a/net/dsa/dsa.c +++ b/net/dsa/dsa.c @@ -324,6 +324,23 @@ int dsa_switch_resume(struct dsa_switch *ds) EXPORT_SYMBOL_GPL(dsa_switch_resume); #endif +int dsa_switch_inband_tx(struct dsa_switch *ds, struct sk_buff *skb, + struct completion *completion, unsigned long timeout) +{ + struct completion *com; + + /* Custom completion? */ + com = completion ? : &ds->inband_done; + + reinit_completion(com); + + if (skb) + dev_queue_xmit(skb); + + return wait_for_completion_timeout(com, msecs_to_jiffies(timeout)); +} +EXPORT_SYMBOL_GPL(dsa_switch_inband_tx); + static struct packet_type dsa_pack_type __read_mostly = { .type = cpu_to_be16(ETH_P_XDSA), .func = dsa_switch_rcv, diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c index ed56c7a554b8..a048a6200789 100644 --- a/net/dsa/dsa2.c +++ b/net/dsa/dsa2.c @@ -874,6 +874,8 @@ static int dsa_switch_setup(struct dsa_switch *ds) if (ds->setup) return 0; + init_completion(&ds->inband_done); + /* Initialize ds->phys_mii_mask before registering the slave MDIO bus * driver and before ops->setup() has run, since the switch drivers and * the slave MDIO bus driver rely on these values for probing PHY From patchwork Mon Sep 19 11:08:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mattias Forsblad X-Patchwork-Id: 12980260 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 028DAECAAD3 for ; Mon, 19 Sep 2022 11:09:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229945AbiISLJD (ORCPT ); Mon, 19 Sep 2022 07:09:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229996AbiISLI5 (ORCPT ); Mon, 19 Sep 2022 07:08:57 -0400 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B72C5E088 for ; Mon, 19 Sep 2022 04:08:55 -0700 (PDT) Received: by mail-lf1-x12b.google.com with SMTP id a3so34323825lfk.9 for ; Mon, 19 Sep 2022 04:08:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=gYr4/+/VXuVJL9MDBujFWj6YWYU745SughITazFnTEI=; b=Y8I4mbXIzsn0l93tl5ba1q88Af1XXtTYqOFrFwxkUAFfsXuoTd0+IU1NRBVlnXJLV+ bp8XrYshpcxfDdGx+axGq0SslOIMHoOP+TtX6chgfBvQqsG7Z4/pDF4plYBfLwjnpNlo tQXtFLZtLK1tiX353qF1gCKUPlkRwaBlM8iejiDfm3XCPLhj12o7fXp53XOjSPbGpwC3 r5igJ+XCb3LKamQ3RtFf9/tRTPjD5+wMLhd2bHpDWMAomW1qjw4Y7G7TX9bsa74N7y26 GQCaCqnTyyCObPZXeMg9I+wm4EGe9xWEbUYUxM3zAUG9Nhfxaku69pWJAUSl1PxsYsDN aV/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=gYr4/+/VXuVJL9MDBujFWj6YWYU745SughITazFnTEI=; b=HRiZqhST3toNqLnXv4Cjj7JdnOLOjgWDaa/hbxDQIMG1wDJ69mf9bWDOdpyJvKnhRC uLUFt95bGHBCmu8yeZzQqMLJfTw7+PzJYFSLEHbFUCQOvljvrZK0RD8WbGh2KotoN3D5 EhqOZnvJgJe7BzWi4+Yce1x3D1IF/ADpeA76KWQJS7sh1hS8auM+DbMgnAMZXOLa852s dPRYsEAYVBe3cQIvIF+ac0wAwgk/vPC9jjjD8cjdPigac5RtiAzG67y24vFALLkiPWcP CXxU0fE284Ww/81bpUfBBBNvmGi+q3tF7O3KzJXdAl3KEPpHzSecsQ6ps85qfDHl/iHp Apdg== X-Gm-Message-State: ACrzQf04XG941jK9h5zoGPkam3E0uOZPPrPKgNA8ppADEuuB87KCGVRY 857ycZuSVJdrYMYg/1cLMn9Z0+R3jB4P9g== X-Google-Smtp-Source: AMsMyM4feLZqTxkLFeJyNxX7QJtfNMwPg0kAQEB3sU61SovwiPOggHdY0/9N8oCr9Uazk/oVVozajA== X-Received: by 2002:a05:6512:2396:b0:499:159d:ac6a with SMTP id c22-20020a056512239600b00499159dac6amr5667622lfv.185.1663585733776; Mon, 19 Sep 2022 04:08:53 -0700 (PDT) Received: from wse-c0089.westermo.com (h-98-128-229-160.NA.cust.bahnhof.se. [98.128.229.160]) by smtp.gmail.com with ESMTPSA id t13-20020a05651c204d00b00266d3f689e1sm4879261ljo.43.2022.09.19.04.08.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Sep 2022 04:08:53 -0700 (PDT) From: Mattias Forsblad To: netdev@vger.kernel.org Cc: Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux@armlinux.org.uk, ansuelsmth@gmail.com, Mattias Forsblad Subject: [PATCH net-next v14 3/7] net: dsa: Introduce dsa tagger data operation. Date: Mon, 19 Sep 2022 13:08:43 +0200 Message-Id: <20220919110847.744712-4-mattias.forsblad@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220919110847.744712-1-mattias.forsblad@gmail.com> References: <20220919110847.744712-1-mattias.forsblad@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Support connecting dsa tagger for frame2reg decoding with its associated hookup functions. Reviewed-by: Andrew Lunn Reviewed-by: Florian Fainelli Signed-off-by: Mattias Forsblad --- include/linux/dsa/mv88e6xxx.h | 6 ++++++ net/dsa/dsa_priv.h | 2 ++ net/dsa/tag_dsa.c | 40 +++++++++++++++++++++++++++++++---- 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/include/linux/dsa/mv88e6xxx.h b/include/linux/dsa/mv88e6xxx.h index 8c3d45eca46b..a8b6f3c110e5 100644 --- a/include/linux/dsa/mv88e6xxx.h +++ b/include/linux/dsa/mv88e6xxx.h @@ -5,9 +5,15 @@ #ifndef _NET_DSA_TAG_MV88E6XXX_H #define _NET_DSA_TAG_MV88E6XXX_H +#include #include #define MV88E6XXX_VID_STANDALONE 0 #define MV88E6XXX_VID_BRIDGED (VLAN_N_VID - 1) +struct dsa_tagger_data { + void (*decode_frame2reg)(struct dsa_switch *ds, + struct sk_buff *skb); +}; + #endif diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h index 614fbba8fe39..3b23b37eb0f4 100644 --- a/net/dsa/dsa_priv.h +++ b/net/dsa/dsa_priv.h @@ -17,6 +17,8 @@ #define DSA_MAX_NUM_OFFLOADING_BRIDGES BITS_PER_LONG +#define DSA_FRAME2REG_SOURCE_DEV GENMASK(5, 0) + enum { DSA_NOTIFIER_AGEING_TIME, DSA_NOTIFIER_BRIDGE_JOIN, diff --git a/net/dsa/tag_dsa.c b/net/dsa/tag_dsa.c index e4b6e3f2a3db..e7fdf3b5cb4a 100644 --- a/net/dsa/tag_dsa.c +++ b/net/dsa/tag_dsa.c @@ -198,8 +198,11 @@ static struct sk_buff *dsa_xmit_ll(struct sk_buff *skb, struct net_device *dev, static struct sk_buff *dsa_rcv_ll(struct sk_buff *skb, struct net_device *dev, u8 extra) { + struct dsa_port *cpu_dp = dev->dsa_ptr; + struct dsa_tagger_data *tagger_data; bool trap = false, trunk = false; int source_device, source_port; + struct dsa_switch *ds; enum dsa_code code; enum dsa_cmd cmd; u8 *dsa_header; @@ -218,9 +221,16 @@ static struct sk_buff *dsa_rcv_ll(struct sk_buff *skb, struct net_device *dev, switch (code) { case DSA_CODE_FRAME2REG: - /* Remote management is not implemented yet, - * drop. - */ + source_device = FIELD_GET(DSA_FRAME2REG_SOURCE_DEV, dsa_header[0]); + ds = dsa_switch_find(cpu_dp->dst->index, source_device); + if (ds) { + tagger_data = ds->tagger_data; + if (likely(tagger_data->decode_frame2reg)) + tagger_data->decode_frame2reg(ds, skb); + } else { + net_err_ratelimited("RMU: Didn't find switch with index %d", + source_device); + } return NULL; case DSA_CODE_ARP_MIRROR: case DSA_CODE_POLICY_MIRROR: @@ -254,7 +264,6 @@ static struct sk_buff *dsa_rcv_ll(struct sk_buff *skb, struct net_device *dev, source_port = (dsa_header[1] >> 3) & 0x1f; if (trunk) { - struct dsa_port *cpu_dp = dev->dsa_ptr; struct dsa_lag *lag; /* The exact source port is not available in the tag, @@ -323,6 +332,25 @@ static struct sk_buff *dsa_rcv_ll(struct sk_buff *skb, struct net_device *dev, return skb; } +static int dsa_tag_connect(struct dsa_switch *ds) +{ + struct dsa_tagger_data *tagger_data; + + tagger_data = kzalloc(sizeof(*tagger_data), GFP_KERNEL); + if (!tagger_data) + return -ENOMEM; + + ds->tagger_data = tagger_data; + + return 0; +} + +static void dsa_tag_disconnect(struct dsa_switch *ds) +{ + kfree(ds->tagger_data); + ds->tagger_data = NULL; +} + #if IS_ENABLED(CONFIG_NET_DSA_TAG_DSA) static struct sk_buff *dsa_xmit(struct sk_buff *skb, struct net_device *dev) @@ -343,6 +371,8 @@ static const struct dsa_device_ops dsa_netdev_ops = { .proto = DSA_TAG_PROTO_DSA, .xmit = dsa_xmit, .rcv = dsa_rcv, + .connect = dsa_tag_connect, + .disconnect = dsa_tag_disconnect, .needed_headroom = DSA_HLEN, }; @@ -385,6 +415,8 @@ static const struct dsa_device_ops edsa_netdev_ops = { .proto = DSA_TAG_PROTO_EDSA, .xmit = edsa_xmit, .rcv = edsa_rcv, + .connect = dsa_tag_connect, + .disconnect = dsa_tag_disconnect, .needed_headroom = EDSA_HLEN, }; From patchwork Mon Sep 19 11:08:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mattias Forsblad X-Patchwork-Id: 12980261 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A1DBEC6FA82 for ; Mon, 19 Sep 2022 11:09:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230078AbiISLJF (ORCPT ); Mon, 19 Sep 2022 07:09:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229960AbiISLI6 (ORCPT ); Mon, 19 Sep 2022 07:08:58 -0400 Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [IPv6:2a00:1450:4864:20::22a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 900B2E08D for ; Mon, 19 Sep 2022 04:08:56 -0700 (PDT) Received: by mail-lj1-x22a.google.com with SMTP id l12so33409670ljg.9 for ; Mon, 19 Sep 2022 04:08:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=rtLHqEJE/EJOVJrLfCowIdcQz0yHcOW6d+IDvBkC47U=; b=oSWV4JnE1tbC+71nee4PNey37Pb3Q8XQY2sUoxgHN3XymuQ9y7uGWAsAWymFuMUJhO +PL4p4+tqWf3L8pEMRe+OyYITJdSWP8UwRk1CHQsUmUiTRcv13utXEUS6EK/cLmyCpgc K+R9jdOqjyIif7NEi+Io7hbS2qd5Bxec06XurHkg/9wVZ3h9Y2LLazH+nQxsHbYvaGb5 SbhR4L4emQx3uKqnmvVXIZ2lNKkfIH6PXhutmHpbTczatq6yPh2C60HiXQOkpKMweG8f Ag2Av+rZeQsnqU2g6rpCzYwwcNAmf9IiAp+7V/wyWcHh4L0/x+3M9HeQTVJYQtOquhL4 Hm1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=rtLHqEJE/EJOVJrLfCowIdcQz0yHcOW6d+IDvBkC47U=; b=BinEn2wbJGjyePnuMCziNpMjddyYVcarsmL7QcPXInrTxAmx7GS2X3TCcLLyjTWLFh CH5rFF30ctzsby2IydjkooGDfGH5pcc3uijR9NyARg5ECSVh2165/5LdXz6EMA1N2XrT No81MKpfZNV2I9q6ZHYynPrzDE25m8NnLOAEftc4cKw9grjlrWHbyPXqLRvWA+rXvsph XoYQGkbS86Bd7cWjTQizvWvUf12w+fAh/3pPkYp0Rna2KZWmbvsSQTuBIpRDIldyrnck VAW0uOKsfTv8YO/SnvbqDaxewt+wmhhgR4tkIrWS7WjYKQy+KDygOZ2fQ7/3a9bJb1yl WE6g== X-Gm-Message-State: ACrzQf1sXljyVPhyhg/iE1WfLTfIiVCkKsc7Z0U8p2vTFLh2JGt+NUnM O7bkkQohm1vm+gtnlIp0DjA8p/Q9jPOshA== X-Google-Smtp-Source: AMsMyM4COFkl8GIHc9pYDB8t0q7cuO5w0tyJz+UxReDnNd8Dcyd8O+0tDfhMZ3GKpt1rXP98KXELDQ== X-Received: by 2002:a2e:a549:0:b0:26c:4988:2742 with SMTP id e9-20020a2ea549000000b0026c49882742mr2119861ljn.11.1663585734593; Mon, 19 Sep 2022 04:08:54 -0700 (PDT) Received: from wse-c0089.westermo.com (h-98-128-229-160.NA.cust.bahnhof.se. [98.128.229.160]) by smtp.gmail.com with ESMTPSA id t13-20020a05651c204d00b00266d3f689e1sm4879261ljo.43.2022.09.19.04.08.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Sep 2022 04:08:54 -0700 (PDT) From: Mattias Forsblad To: netdev@vger.kernel.org Cc: Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux@armlinux.org.uk, ansuelsmth@gmail.com, Mattias Forsblad Subject: [PATCH net-next v14 4/7] net: dsa: mv88e6xxxx: Add RMU functionality. Date: Mon, 19 Sep 2022 13:08:44 +0200 Message-Id: <20220919110847.744712-5-mattias.forsblad@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220919110847.744712-1-mattias.forsblad@gmail.com> References: <20220919110847.744712-1-mattias.forsblad@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The Marvell SOHO switches supports a secondary control channel for accessing data in the switch. Special crafted ethernet frames can access functions in the switch. These frames is handled by the Remote Management Unit (RMU) in the switch. Accessing data structures is specially efficient and lessens the access contention on the MDIO bus. Reviewed-by: Florian Fainelli Signed-off-by: Mattias Forsblad --- drivers/net/dsa/mv88e6xxx/Makefile | 1 + drivers/net/dsa/mv88e6xxx/chip.c | 28 ++- drivers/net/dsa/mv88e6xxx/chip.h | 17 ++ drivers/net/dsa/mv88e6xxx/rmu.c | 263 +++++++++++++++++++++++++++++ drivers/net/dsa/mv88e6xxx/rmu.h | 73 ++++++++ 5 files changed, 374 insertions(+), 8 deletions(-) create mode 100644 drivers/net/dsa/mv88e6xxx/rmu.c create mode 100644 drivers/net/dsa/mv88e6xxx/rmu.h diff --git a/drivers/net/dsa/mv88e6xxx/Makefile b/drivers/net/dsa/mv88e6xxx/Makefile index c8eca2b6f959..105d7bd832c9 100644 --- a/drivers/net/dsa/mv88e6xxx/Makefile +++ b/drivers/net/dsa/mv88e6xxx/Makefile @@ -15,3 +15,4 @@ mv88e6xxx-objs += port_hidden.o mv88e6xxx-$(CONFIG_NET_DSA_MV88E6XXX_PTP) += ptp.o mv88e6xxx-objs += serdes.o mv88e6xxx-objs += smi.o +mv88e6xxx-objs += rmu.o diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c index 46e12b53a9e4..294bf9bbaf3f 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.c +++ b/drivers/net/dsa/mv88e6xxx/chip.c @@ -42,6 +42,7 @@ #include "ptp.h" #include "serdes.h" #include "smi.h" +#include "rmu.h" static void assert_reg_lock(struct mv88e6xxx_chip *chip) { @@ -1535,14 +1536,6 @@ static int mv88e6xxx_trunk_setup(struct mv88e6xxx_chip *chip) return 0; } -static int mv88e6xxx_rmu_setup(struct mv88e6xxx_chip *chip) -{ - if (chip->info->ops->rmu_disable) - return chip->info->ops->rmu_disable(chip); - - return 0; -} - static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip) { if (chip->info->ops->pot_clear) @@ -6867,6 +6860,23 @@ static int mv88e6xxx_crosschip_lag_leave(struct dsa_switch *ds, int sw_index, return err_sync ? : err_pvt; } +static int mv88e6xxx_connect_tag_protocol(struct dsa_switch *ds, + enum dsa_tag_protocol proto) +{ + struct dsa_tagger_data *tagger_data = ds->tagger_data; + + switch (proto) { + case DSA_TAG_PROTO_DSA: + case DSA_TAG_PROTO_EDSA: + tagger_data->decode_frame2reg = mv88e6xxx_decode_frame2reg_handler; + break; + default: + return -EPROTONOSUPPORT; + } + + return 0; +} + static const struct dsa_switch_ops mv88e6xxx_switch_ops = { .get_tag_protocol = mv88e6xxx_get_tag_protocol, .change_tag_protocol = mv88e6xxx_change_tag_protocol, @@ -6932,6 +6942,8 @@ static const struct dsa_switch_ops mv88e6xxx_switch_ops = { .crosschip_lag_change = mv88e6xxx_crosschip_lag_change, .crosschip_lag_join = mv88e6xxx_crosschip_lag_join, .crosschip_lag_leave = mv88e6xxx_crosschip_lag_leave, + .master_state_change = mv88e6xxx_master_state_change, + .connect_tag_protocol = mv88e6xxx_connect_tag_protocol, }; static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip) diff --git a/drivers/net/dsa/mv88e6xxx/chip.h b/drivers/net/dsa/mv88e6xxx/chip.h index 7ce3c41f6caf..440e9b274df4 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.h +++ b/drivers/net/dsa/mv88e6xxx/chip.h @@ -282,6 +282,20 @@ struct mv88e6xxx_port { struct devlink_region *region; }; +struct mv88e6xxx_rmu { + /* RMU resources */ + struct net_device *master_netdev; + const struct mv88e6xxx_bus_ops *smi_ops; + const struct dsa_switch_ops *ds_ops; + struct dsa_switch_ops *ds_rmu_ops; + struct mv88e6xxx_bus_ops *smi_rmu_ops; + /* Mutex for RMU operations */ + struct mutex mutex; + u16 prodnr; + struct sk_buff *resp; + int seqno; +}; + enum mv88e6xxx_region_id { MV88E6XXX_REGION_GLOBAL1 = 0, MV88E6XXX_REGION_GLOBAL2, @@ -410,6 +424,9 @@ struct mv88e6xxx_chip { /* Bridge MST to SID mappings */ struct list_head msts; + + /* RMU resources */ + struct mv88e6xxx_rmu rmu; }; struct mv88e6xxx_bus_ops { diff --git a/drivers/net/dsa/mv88e6xxx/rmu.c b/drivers/net/dsa/mv88e6xxx/rmu.c new file mode 100644 index 000000000000..c5b3c156de40 --- /dev/null +++ b/drivers/net/dsa/mv88e6xxx/rmu.c @@ -0,0 +1,263 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Marvell 88E6xxx Switch Remote Management Unit Support + * + * Copyright (c) 2022 Mattias Forsblad + * + */ + +#include +#include "rmu.h" +#include "global1.h" + +static const u8 mv88e6xxx_rmu_dest_addr[ETH_ALEN] = { 0x01, 0x50, 0x43, 0x00, 0x00, 0x00 }; + +static void mv88e6xxx_rmu_create_l2(struct dsa_switch *ds, struct sk_buff *skb) +{ + struct mv88e6xxx_chip *chip = ds->priv; + struct ethhdr *eth; + u8 *edsa_header; + u8 *dsa_header; + u8 extra = 0; + + if (chip->tag_protocol == DSA_TAG_PROTO_EDSA) + extra = 4; + + /* Create RMU L2 header */ + dsa_header = skb_push(skb, 6); + dsa_header[0] = FIELD_PREP(MV88E6XXX_CPU_CODE_MASK, MV88E6XXX_RMU); + dsa_header[0] |= FIELD_PREP(MV88E6XXX_TRG_DEV_MASK, ds->index); + dsa_header[1] = FIELD_PREP(MV88E6XXX_RMU_CODE_MASK, 1); + dsa_header[1] |= FIELD_PREP(MV88E6XXX_RMU_L2_BYTE1_RESV, MV88E6XXX_RMU_L2_BYTE1_RESV_VAL); + dsa_header[2] = FIELD_PREP(MV88E6XXX_RMU_PRIO_MASK, MV88E6XXX_RMU_PRIO); + dsa_header[2] |= MV88E6XXX_RMU_L2_BYTE2_RESV; + dsa_header[3] = ++chip->rmu.seqno; + dsa_header[4] = 0; + dsa_header[5] = 0; + + /* Insert RMU MAC destination address /w extra if needed */ + eth = skb_push(skb, ETH_ALEN * 2 + extra); + memcpy(eth->h_dest, mv88e6xxx_rmu_dest_addr, ETH_ALEN); + ether_addr_copy(eth->h_source, chip->rmu.master_netdev->dev_addr); + + if (extra) { + edsa_header = (u8 *)ð->h_proto; + edsa_header[0] = (ETH_P_EDSA >> 8) & 0xff; + edsa_header[1] = ETH_P_EDSA & 0xff; + edsa_header[2] = 0x00; + edsa_header[3] = 0x00; + } +} + +static int mv88e6xxx_rmu_send_wait(struct mv88e6xxx_chip *chip, + const void *req, int req_len, + void *resp, unsigned int *resp_len) +{ + struct sk_buff *skb; + unsigned char *data; + int ret = 0; + + skb = netdev_alloc_skb(chip->rmu.master_netdev, 64); + if (!skb) + return -ENOMEM; + + /* Take height for an eventual EDSA header */ + skb_reserve(skb, 2 * ETH_HLEN + 4); + skb_reset_network_header(skb); + + /* Insert RMU request message */ + data = skb_put(skb, req_len); + memcpy(data, req, req_len); + + mv88e6xxx_rmu_create_l2(chip->ds, skb); + + mutex_lock(&chip->rmu.mutex); + + ret = dsa_switch_inband_tx(chip->ds, skb, NULL, MV88E6XXX_RMU_WAIT_TIME_MS); + if (!ret) { + dev_err(chip->dev, "RMU: error waiting for request (%pe)\n", + ERR_PTR(ret)); + goto out; + } + + if (chip->rmu.resp->len > *resp_len) { + ret = -EMSGSIZE; + } else { + *resp_len = chip->rmu.resp->len; + memcpy(resp, chip->rmu.resp->data, chip->rmu.resp->len); + } + + kfree_skb(chip->rmu.resp); + chip->rmu.resp = NULL; + +out: + mutex_unlock(&chip->rmu.mutex); + + return ret > 0 ? 0 : ret; +} + +static int mv88e6xxx_rmu_validate_response(struct mv88e6xxx_rmu_header *resp, int code) +{ + if (be16_to_cpu(resp->format) != MV88E6XXX_RMU_RESP_FORMAT_1 && + be16_to_cpu(resp->format) != MV88E6XXX_RMU_RESP_FORMAT_2 && + be16_to_cpu(resp->code) != code) { + net_dbg_ratelimited("RMU: received unknown format 0x%04x code 0x%04x", + resp->format, resp->code); + return -EIO; + } + + return 0; +} + +static int mv88e6xxx_rmu_get_id(struct mv88e6xxx_chip *chip, int port) +{ + const u16 req[4] = { MV88E6XXX_RMU_REQ_FORMAT_GET_ID, + MV88E6XXX_RMU_REQ_PAD, + MV88E6XXX_RMU_REQ_CODE_GET_ID, + MV88E6XXX_RMU_REQ_DATA}; + struct mv88e6xxx_rmu_header resp; + int resp_len; + int ret = -1; + + resp_len = sizeof(resp); + ret = mv88e6xxx_rmu_send_wait(chip, req, sizeof(req), + &resp, &resp_len); + if (ret) { + dev_dbg(chip->dev, "RMU: error for command GET_ID %pe\n", ERR_PTR(ret)); + return ret; + } + + /* Got response */ + ret = mv88e6xxx_rmu_validate_response(&resp, MV88E6XXX_RMU_RESP_CODE_GOT_ID); + if (ret) + return ret; + + chip->rmu.prodnr = be16_to_cpu(resp.prodnr); + + return ret; +} + +static void mv88e6xxx_disable_rmu(struct mv88e6xxx_chip *chip) +{ + chip->smi_ops = chip->rmu.smi_ops; + chip->ds->ops = chip->rmu.ds_rmu_ops; + chip->rmu.master_netdev = NULL; + + if (chip->info->ops->rmu_disable) + chip->info->ops->rmu_disable(chip); +} + +static int mv88e6xxx_enable_check_rmu(const struct net_device *master, + struct mv88e6xxx_chip *chip, int port) +{ + int ret; + + chip->rmu.master_netdev = (struct net_device *)master; + + /* Check if chip is alive */ + ret = mv88e6xxx_rmu_get_id(chip, port); + if (!ret) + return ret; + + chip->ds->ops = chip->rmu.ds_rmu_ops; + chip->smi_ops = chip->rmu.smi_rmu_ops; + + return 0; +} + +void mv88e6xxx_master_state_change(struct dsa_switch *ds, const struct net_device *master, + bool operational) +{ + struct dsa_port *cpu_dp = master->dsa_ptr; + struct mv88e6xxx_chip *chip = ds->priv; + int port; + int ret; + + port = dsa_towards_port(ds, cpu_dp->ds->index, cpu_dp->index); + + mv88e6xxx_reg_lock(chip); + + if (operational && chip->info->ops->rmu_enable) { + ret = chip->info->ops->rmu_enable(chip, port); + + if (ret == -EOPNOTSUPP) + goto out; + + if (!ret) { + dev_dbg(chip->dev, "RMU: Enabled on port %d", port); + + ret = mv88e6xxx_enable_check_rmu(master, chip, port); + if (!ret) + goto out; + + } else { + dev_err(chip->dev, "RMU: Unable to enable on port %d %pe", + port, ERR_PTR(ret)); + goto out; + } + } else { + mv88e6xxx_disable_rmu(chip); + } + +out: + mv88e6xxx_reg_unlock(chip); +} + +static int mv88e6xxx_validate_mac(struct dsa_switch *ds, struct sk_buff *skb) +{ + struct mv88e6xxx_chip *chip = ds->priv; + unsigned char *ethhdr; + + /* Check matching MAC */ + ethhdr = skb_mac_header(skb); + if (!ether_addr_equal(chip->rmu.master_netdev->dev_addr, ethhdr)) { + dev_dbg_ratelimited(ds->dev, "RMU: mismatching MAC address for request. Rx %pM expecting %pM\n", + ethhdr, chip->rmu.master_netdev->dev_addr); + return -EINVAL; + } + + return 0; +} + +void mv88e6xxx_decode_frame2reg_handler(struct dsa_switch *ds, struct sk_buff *skb) +{ + struct mv88e6xxx_chip *chip = ds->priv; + u8 *dsa_header; + u8 seqno; + + /* Decode Frame2Reg DSA portion */ + dsa_header = skb->data - 2; + + if (mv88e6xxx_validate_mac(ds, skb)) + return; + + seqno = dsa_header[3]; + if (seqno != chip->rmu.seqno) { + net_err_ratelimited("RMU: wrong seqno received. Was %d, expected %d", + seqno, chip->rmu.seqno); + return; + } + + /* Pull DSA L2 data */ + skb_pull(skb, MV88E6XXX_DSA_HLEN); + + /* Get an reference for further processing in initiator */ + chip->rmu.resp = skb_get(skb); + + dsa_switch_inband_complete(ds, NULL); +} + +int mv88e6xxx_rmu_setup(struct mv88e6xxx_chip *chip) +{ + mutex_init(&chip->rmu.mutex); + + /* Remember original ops for restore */ + chip->rmu.smi_ops = chip->smi_ops; + chip->rmu.ds_ops = chip->ds->ops; + + /* Start disabled, we'll enable RMU in master_state_change */ + if (chip->info->ops->rmu_disable) + return chip->info->ops->rmu_disable(chip); + + return 0; +} diff --git a/drivers/net/dsa/mv88e6xxx/rmu.h b/drivers/net/dsa/mv88e6xxx/rmu.h new file mode 100644 index 000000000000..67757a3c2f29 --- /dev/null +++ b/drivers/net/dsa/mv88e6xxx/rmu.h @@ -0,0 +1,73 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Marvell 88E6xxx Switch Remote Management Unit Support + * + * Copyright (c) 2022 Mattias Forsblad + * + */ + +#ifndef _MV88E6XXX_RMU_H_ +#define _MV88E6XXX_RMU_H_ + +#include "chip.h" + +#define MV88E6XXX_DSA_HLEN 4 + +#define MV88E6XXX_RMU_MAX_RMON 64 + +#define MV88E6XXX_RMU_WAIT_TIME_MS 20 + +#define MV88E6XXX_RMU_L2_BYTE1_RESV_VAL 0x3e +#define MV88E6XXX_RMU 1 +#define MV88E6XXX_RMU_PRIO 6 +#define MV88E6XXX_RMU_RESV2 0xf + +#define MV88E6XXX_SOURCE_PORT GENMASK(6, 3) +#define MV88E6XXX_CPU_CODE_MASK GENMASK(7, 6) +#define MV88E6XXX_TRG_DEV_MASK GENMASK(4, 0) +#define MV88E6XXX_RMU_CODE_MASK GENMASK(1, 1) +#define MV88E6XXX_RMU_PRIO_MASK GENMASK(7, 5) +#define MV88E6XXX_RMU_L2_BYTE1_RESV GENMASK(7, 2) +#define MV88E6XXX_RMU_L2_BYTE2_RESV GENMASK(3, 0) + +#define MV88E6XXX_RMU_REQ_GET_ID 1 +#define MV88E6XXX_RMU_REQ_DUMP_MIB 2 + +#define MV88E6XXX_RMU_REQ_FORMAT_GET_ID 0x0000 +#define MV88E6XXX_RMU_REQ_FORMAT_SOHO 0x0001 +#define MV88E6XXX_RMU_REQ_PAD 0x0000 +#define MV88E6XXX_RMU_REQ_CODE_GET_ID 0x0000 +#define MV88E6XXX_RMU_REQ_CODE_DUMP_MIB 0x1020 +#define MV88E6XXX_RMU_REQ_DATA 0x0000 + +#define MV88E6XXX_RMU_REQ_DUMP_MIB_PORT_MASK GENMASK(4, 0) + +#define MV88E6XXX_RMU_RESP_FORMAT_1 0x0001 +#define MV88E6XXX_RMU_RESP_FORMAT_2 0x0002 +#define MV88E6XXX_RMU_RESP_ERROR 0xffff + +#define MV88E6XXX_RMU_RESP_CODE_GOT_ID 0x0000 +#define MV88E6XXX_RMU_RESP_CODE_DUMP_MIB 0x1020 + +struct mv88e6xxx_rmu_header { + __be16 format; + __be16 prodnr; + __be16 code; +} __packed; + +struct mv88e6xxx_dump_mib_resp { + struct mv88e6xxx_rmu_header rmu_header; + u8 devnum; + u8 portnum; + __be32 timestamp; + __be32 mib[MV88E6XXX_RMU_MAX_RMON]; +} __packed; + +int mv88e6xxx_rmu_setup(struct mv88e6xxx_chip *chip); + +void mv88e6xxx_master_state_change(struct dsa_switch *ds, const struct net_device *master, + bool operational); + +void mv88e6xxx_decode_frame2reg_handler(struct dsa_switch *ds, struct sk_buff *skb); + +#endif /* _MV88E6XXX_RMU_H_ */ From patchwork Mon Sep 19 11:08:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mattias Forsblad X-Patchwork-Id: 12980262 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 84A9FC54EE9 for ; Mon, 19 Sep 2022 11:09:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230099AbiISLJH (ORCPT ); Mon, 19 Sep 2022 07:09:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229613AbiISLI7 (ORCPT ); Mon, 19 Sep 2022 07:08:59 -0400 Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4265795A3 for ; Mon, 19 Sep 2022 04:08:57 -0700 (PDT) Received: by mail-lf1-x130.google.com with SMTP id i26so46325975lfp.11 for ; Mon, 19 Sep 2022 04:08:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=MiAiqg8kMnnPs+t9JdAwgbU7eMmuujYZlpVgCm5v3Xs=; b=N3x955CmOTaECh2nCFFSBxUF8BARAdJAj826m3n2PCM5iKVbK9DuC8MBcGiu0awxy3 Zv4wC+yaiJdEPy1GBPHlVmNjZJJunz/Cq7jWjMhHDojBesQLxW4e8fZ0zrvQbndylj6B rdXJuDhx4wHny/+zQsrrhV0UGGLmWThYlx858rgG+wqC5DkcggQFWW2RO/tCY2L0Vb/y lmfGBsiwR1QuvIMRFGSDJRJ4M+u67x+/1iL+uFk/yXWiPexOOsnsypPYZPCpIF8dZy7c 6Dgp/T0FiOtmD2Y8Ee4Gj0ifMspBHtY/Fg73Wq2z+DOZnHTZnlWwiXzDQzLn+bqHLGF9 Itzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=MiAiqg8kMnnPs+t9JdAwgbU7eMmuujYZlpVgCm5v3Xs=; b=5r0xOlN3q71gqJtatOcPh5eLhoaeVKi0KLZ7LowE/1O3XYvw3GVr9xssx7PkdUfDQL fS37UFSCssVcaVx6k2XYzGfdcIYhT9IoPMN3pPDFZTkD5zV3IMgJGv7HVdMqYkArbrKn dFeyx8q+Ra7mKuF4C63ZGdNETbMcxAoAf2JETAUXnJ6x9I406r2DrGYRBUQYGv5YKlOC GuMNeNTqsmcatUoTArysnV0xqsBf3tyT0jr+0XAv8uAMnursgqlWiA5AIgQqlMf/r5UZ ISHLx+mFJCluVEiBCKAUdi2QkVo2yEg8zZy/C+5yEHlqRn2UVbjsJYtSUjd6tT+qwTvL 6drw== X-Gm-Message-State: ACrzQf1MMDlTqhgJ0VrzzsLF4ohx6RdiJVKjxdnZ5odYLtoVBIhLDlAT njlJ/wX9PkgJVoWp3gBlDcYNTxYzzxwoRg== X-Google-Smtp-Source: AMsMyM5GGEczc3W2cRbLeQcmrSAPo8tEOaKfG75qS+jV/nl2DGahORu0G5pouH6CzQamWLZn4JEviA== X-Received: by 2002:a05:6512:3c88:b0:499:c78:5bb1 with SMTP id h8-20020a0565123c8800b004990c785bb1mr5857472lfv.503.1663585735294; Mon, 19 Sep 2022 04:08:55 -0700 (PDT) Received: from wse-c0089.westermo.com (h-98-128-229-160.NA.cust.bahnhof.se. [98.128.229.160]) by smtp.gmail.com with ESMTPSA id t13-20020a05651c204d00b00266d3f689e1sm4879261ljo.43.2022.09.19.04.08.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Sep 2022 04:08:55 -0700 (PDT) From: Mattias Forsblad To: netdev@vger.kernel.org Cc: Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux@armlinux.org.uk, ansuelsmth@gmail.com, Mattias Forsblad Subject: [PATCH net-next v14 5/7] net: dsa: mv88e6xxx: rmu: Add functionality to get RMON Date: Mon, 19 Sep 2022 13:08:45 +0200 Message-Id: <20220919110847.744712-6-mattias.forsblad@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220919110847.744712-1-mattias.forsblad@gmail.com> References: <20220919110847.744712-1-mattias.forsblad@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org It's possible to access the RMON counters via RMU. Add functionality to send DUMP_MIB frames. Signed-off-by: Mattias Forsblad --- drivers/net/dsa/mv88e6xxx/chip.c | 74 ++++++++++++++++++++++++++++++++ drivers/net/dsa/mv88e6xxx/chip.h | 6 +++ drivers/net/dsa/mv88e6xxx/rmu.c | 53 +++++++++++++++++++++++ 3 files changed, 133 insertions(+) diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c index 294bf9bbaf3f..5b22fe4b3284 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.c +++ b/drivers/net/dsa/mv88e6xxx/chip.c @@ -1229,6 +1229,80 @@ static int mv88e6xxx_get_sset_count(struct dsa_switch *ds, int port, int sset) return count; } +int mv88e6xxx_stats_get_sset_count_rmu(struct dsa_switch *ds, int port, int sset) +{ + if (sset != ETH_SS_STATS) + return 0; + + return ARRAY_SIZE(mv88e6xxx_hw_stats); +} + +void mv88e6xxx_stats_get_strings_rmu(struct dsa_switch *ds, int port, + u32 stringset, uint8_t *data) +{ + struct mv88e6xxx_hw_stat *stat; + int i; + + if (stringset != ETH_SS_STATS) + return; + + for (i = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) { + stat = &mv88e6xxx_hw_stats[i]; + memcpy(data + i * ETH_GSTRING_LEN, stat->string, ETH_GSTRING_LEN); + } +} + +int mv88e6xxx_state_get_stats_rmu(struct mv88e6xxx_chip *chip, int port, + __be32 *raw_cnt, int num_cnt, uint64_t *data) +{ + struct mv88e6xxx_hw_stat *stat; + int offset = 0; + u64 high; + int i, j; + + for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) { + stat = &mv88e6xxx_hw_stats[i]; + offset = stat->reg; + + if (stat->type & STATS_TYPE_PORT) { + /* The offsets for the port counters below + * are different in the RMU packet. + */ + switch (stat->reg) { + case 0x10: /* sw_in_discards */ + offset = 0x81; + break; + case 0x12: /* sw_in_filtered */ + offset = 0x85; + break; + case 0x13: /* sw_out_filtered */ + offset = 0x89; + break; + default: + dev_err(chip->dev, + "RMU: port %d wrong offset requested: %d\n", + port, stat->reg); + return j; + } + } else if (stat->type & STATS_TYPE_BANK1) { + offset += 32; + } + + if (offset >= num_cnt) + continue; + + data[j] = be32_to_cpu(raw_cnt[offset]); + + if (stat->size == 8) { + high = be32_to_cpu(raw_cnt[offset + 1]); + data[j] += (high << 32); + } + + j++; + } + return j; +} + static int mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port, uint64_t *data, int types, u16 bank1_select, u16 histogram) diff --git a/drivers/net/dsa/mv88e6xxx/chip.h b/drivers/net/dsa/mv88e6xxx/chip.h index 440e9b274df4..aca7cfef196e 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.h +++ b/drivers/net/dsa/mv88e6xxx/chip.h @@ -433,6 +433,7 @@ struct mv88e6xxx_bus_ops { int (*read)(struct mv88e6xxx_chip *chip, int addr, int reg, u16 *val); int (*write)(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val); int (*init)(struct mv88e6xxx_chip *chip); + void (*get_rmon)(struct mv88e6xxx_chip *chip, int port, uint64_t *data); }; struct mv88e6xxx_mdio_bus { @@ -822,4 +823,9 @@ static inline void mv88e6xxx_reg_unlock(struct mv88e6xxx_chip *chip) int mv88e6xxx_fid_map(struct mv88e6xxx_chip *chip, unsigned long *bitmap); +int mv88e6xxx_state_get_stats_rmu(struct mv88e6xxx_chip *chip, int port, + __be32 *raw_cnt, int num_cnt, uint64_t *data); +int mv88e6xxx_stats_get_sset_count_rmu(struct dsa_switch *ds, int port, int sset); +void mv88e6xxx_stats_get_strings_rmu(struct dsa_switch *ds, int port, + u32 stringset, uint8_t *data); #endif /* _MV88E6XXX_CHIP_H */ diff --git a/drivers/net/dsa/mv88e6xxx/rmu.c b/drivers/net/dsa/mv88e6xxx/rmu.c index c5b3c156de40..129535777c4b 100644 --- a/drivers/net/dsa/mv88e6xxx/rmu.c +++ b/drivers/net/dsa/mv88e6xxx/rmu.c @@ -137,6 +137,50 @@ static int mv88e6xxx_rmu_get_id(struct mv88e6xxx_chip *chip, int port) return ret; } +static void mv88e6xxx_rmu_stats_get(struct mv88e6xxx_chip *chip, int port, uint64_t *data) +{ + u16 req[4] = { MV88E6XXX_RMU_REQ_FORMAT_SOHO, + MV88E6XXX_RMU_REQ_PAD, + MV88E6XXX_RMU_REQ_CODE_DUMP_MIB, + MV88E6XXX_RMU_REQ_DATA}; + struct mv88e6xxx_dump_mib_resp resp; + struct mv88e6xxx_port *p; + u8 resp_port; + int resp_len; + int num_mibs; + int ret; + + /* Populate port number in request */ + req[3] = FIELD_PREP(MV88E6XXX_RMU_REQ_DUMP_MIB_PORT_MASK, port); + + resp_len = sizeof(resp); + ret = mv88e6xxx_rmu_send_wait(chip, req, sizeof(req), + &resp, &resp_len); + if (ret) { + dev_dbg(chip->dev, "RMU: error for command DUMP_MIB %pe port %d\n", + ERR_PTR(ret), port); + return; + } + + /* Got response */ + ret = mv88e6xxx_rmu_validate_response(&resp.rmu_header, MV88E6XXX_RMU_RESP_CODE_DUMP_MIB); + if (ret) + return; + + resp_port = FIELD_GET(MV88E6XXX_SOURCE_PORT, resp.portnum); + p = &chip->ports[resp_port]; + if (!p) { + dev_err_ratelimited(chip->dev, "RMU: illegal port number in response: %d\n", + resp_port); + return; + } + + /* Update MIB for port */ + num_mibs = (resp_len - offsetof(struct mv88e6xxx_dump_mib_resp, mib)) / sizeof(__be32); + + mv88e6xxx_state_get_stats_rmu(chip, port, resp.mib, num_mibs, data); +} + static void mv88e6xxx_disable_rmu(struct mv88e6xxx_chip *chip) { chip->smi_ops = chip->rmu.smi_ops; @@ -255,6 +299,15 @@ int mv88e6xxx_rmu_setup(struct mv88e6xxx_chip *chip) chip->rmu.smi_ops = chip->smi_ops; chip->rmu.ds_ops = chip->ds->ops; + /* Change rmu ops with our own pointer */ + chip->rmu.smi_rmu_ops = (struct mv88e6xxx_bus_ops *)chip->rmu.smi_ops; + chip->rmu.smi_rmu_ops->get_rmon = mv88e6xxx_rmu_stats_get; + + /* Also change get stats strings for our own */ + chip->rmu.ds_rmu_ops = (struct dsa_switch_ops *)chip->ds->ops; + chip->rmu.ds_rmu_ops->get_sset_count = mv88e6xxx_stats_get_sset_count_rmu; + chip->rmu.ds_rmu_ops->get_strings = mv88e6xxx_stats_get_strings_rmu; + /* Start disabled, we'll enable RMU in master_state_change */ if (chip->info->ops->rmu_disable) return chip->info->ops->rmu_disable(chip); From patchwork Mon Sep 19 11:08:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mattias Forsblad X-Patchwork-Id: 12980264 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7AB5C6FA82 for ; Mon, 19 Sep 2022 11:09:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230111AbiISLJK (ORCPT ); Mon, 19 Sep 2022 07:09:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230033AbiISLI7 (ORCPT ); Mon, 19 Sep 2022 07:08:59 -0400 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA570E01B for ; Mon, 19 Sep 2022 04:08:57 -0700 (PDT) Received: by mail-lf1-x12b.google.com with SMTP id a2so22321197lfb.6 for ; Mon, 19 Sep 2022 04:08:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=xMPI3N4HEitsK3nKmRgxAWSFwBXRQJHlzN+CdBb5P4k=; b=XXAp1P4QBMZWYMBCo9RWJ7wsfwYpRXrAGG6IKnF7wdOydKUn8VbpgJfRapAf/cYiLA 7jSKJyRBIppnj6/DAa5q63KnHfV1FhNcEpjgeGve34R6933/kyYgUE6GyUIcjzvhTbbI URZSbX+/05Go/rB8BgBtlXtVAwU5+01zoEycKvlkcO/DlLVrNuSlQ5iilv95UKidvppj uL6dev03ZK8+tGOPydeS9dBl0EKZVI5jIceV2twOrVdCfdTAi155Ea6HdeeFFiTMUgwQ gJxghHG2LoLIuwua7V9//EAXaAL7RLsSxv28fFu+UwILYelELVfVjeAgdoj27+ZQsnoZ JezQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=xMPI3N4HEitsK3nKmRgxAWSFwBXRQJHlzN+CdBb5P4k=; b=lnOfm62pKKfBzHYC1NlTIQPlXdIXrI4mXjoDmp6REGuDs/FarK2F4+M8pDNoUhVGut VGIfBFDRDjUoigvN1E29ztPAIby4Tf+/MSHkZmz1AuXhYxinMw4jwijv5JugvuKeXSuU F9UqN7DK0w+oqfmGzRp43RsNN/vQ7PBU/yZEqLXPRCN9DjbjZimFxTo6m6dcn2Q015RB hRHbyXAVj00qoiqsRK9aUCsHshmzOgyLtA+/7BsRplm+XPgEmUX/TgSBjlb+j3ADvVQw S14IVzmPNGmphcizntCfjA0FkgJE7ebPPm3s6DH4pWTd9yLXbaGRbkXaqME9HA/71lYe DzZA== X-Gm-Message-State: ACrzQf2ma2z8o4vWtF3iQ0wdM5cY9uhl/XickGRUxkEHhRH2EskE5TMQ M9P9+NZm28EKLG8cWgjDkzUruOBwhtRVmg== X-Google-Smtp-Source: AMsMyM6GaDKiyUTjEWrMKOGrxkjOmZgrMtbPeNA7Ffwhb8gQ4c9CBNAtGswETFmPVerUU3M/RWXMQA== X-Received: by 2002:a05:6512:31d5:b0:498:f3dc:dd2 with SMTP id j21-20020a05651231d500b00498f3dc0dd2mr5628331lfe.101.1663585736017; Mon, 19 Sep 2022 04:08:56 -0700 (PDT) Received: from wse-c0089.westermo.com (h-98-128-229-160.NA.cust.bahnhof.se. [98.128.229.160]) by smtp.gmail.com with ESMTPSA id t13-20020a05651c204d00b00266d3f689e1sm4879261ljo.43.2022.09.19.04.08.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Sep 2022 04:08:55 -0700 (PDT) From: Mattias Forsblad To: netdev@vger.kernel.org Cc: Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux@armlinux.org.uk, ansuelsmth@gmail.com, Mattias Forsblad Subject: [PATCH net-next v14 6/7] net: dsa: mv88e6xxx: rmon: Use RMU for reading RMON data Date: Mon, 19 Sep 2022 13:08:46 +0200 Message-Id: <20220919110847.744712-7-mattias.forsblad@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220919110847.744712-1-mattias.forsblad@gmail.com> References: <20220919110847.744712-1-mattias.forsblad@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Redirect calls for collecting the RMON counters to RMU instead of over legacy MDIO. Signed-off-by: Mattias Forsblad --- drivers/net/dsa/mv88e6xxx/chip.c | 12 +++++++++--- drivers/net/dsa/mv88e6xxx/chip.h | 2 ++ drivers/net/dsa/mv88e6xxx/smi.c | 3 +++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c index 5b22fe4b3284..860896849785 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.c +++ b/drivers/net/dsa/mv88e6xxx/chip.c @@ -1386,10 +1386,9 @@ static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port, mv88e6xxx_reg_unlock(chip); } -static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port, - uint64_t *data) +void mv88e6xxx_get_ethtool_stats_mdio(struct mv88e6xxx_chip *chip, int port, + uint64_t *data) { - struct mv88e6xxx_chip *chip = ds->priv; int ret; mv88e6xxx_reg_lock(chip); @@ -1401,7 +1400,14 @@ static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port, return; mv88e6xxx_get_stats(chip, port, data); +} + +static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port, + uint64_t *data) +{ + struct mv88e6xxx_chip *chip = ds->priv; + chip->smi_ops->get_rmon(chip, port, data); } static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port) diff --git a/drivers/net/dsa/mv88e6xxx/chip.h b/drivers/net/dsa/mv88e6xxx/chip.h index aca7cfef196e..7b692ba688f7 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.h +++ b/drivers/net/dsa/mv88e6xxx/chip.h @@ -811,6 +811,8 @@ int mv88e6xxx_wait_bit(struct mv88e6xxx_chip *chip, int addr, int reg, int bit, int val); struct mii_bus *mv88e6xxx_default_mdio_bus(struct mv88e6xxx_chip *chip); +void mv88e6xxx_get_ethtool_stats_mdio(struct mv88e6xxx_chip *chip, int port, + uint64_t *data); static inline void mv88e6xxx_reg_lock(struct mv88e6xxx_chip *chip) { mutex_lock(&chip->reg_lock); diff --git a/drivers/net/dsa/mv88e6xxx/smi.c b/drivers/net/dsa/mv88e6xxx/smi.c index a990271b7482..ae805c449b85 100644 --- a/drivers/net/dsa/mv88e6xxx/smi.c +++ b/drivers/net/dsa/mv88e6xxx/smi.c @@ -83,6 +83,7 @@ static int mv88e6xxx_smi_direct_wait(struct mv88e6xxx_chip *chip, static const struct mv88e6xxx_bus_ops mv88e6xxx_smi_direct_ops = { .read = mv88e6xxx_smi_direct_read, .write = mv88e6xxx_smi_direct_write, + .get_rmon = mv88e6xxx_get_ethtool_stats_mdio, }; static int mv88e6xxx_smi_dual_direct_read(struct mv88e6xxx_chip *chip, @@ -100,6 +101,7 @@ static int mv88e6xxx_smi_dual_direct_write(struct mv88e6xxx_chip *chip, static const struct mv88e6xxx_bus_ops mv88e6xxx_smi_dual_direct_ops = { .read = mv88e6xxx_smi_dual_direct_read, .write = mv88e6xxx_smi_dual_direct_write, + .get_rmon = mv88e6xxx_get_ethtool_stats_mdio, }; /* Offset 0x00: SMI Command Register @@ -166,6 +168,7 @@ static const struct mv88e6xxx_bus_ops mv88e6xxx_smi_indirect_ops = { .read = mv88e6xxx_smi_indirect_read, .write = mv88e6xxx_smi_indirect_write, .init = mv88e6xxx_smi_indirect_init, + .get_rmon = mv88e6xxx_get_ethtool_stats_mdio, }; int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip, From patchwork Mon Sep 19 11:08:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mattias Forsblad X-Patchwork-Id: 12980263 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 14CE1ECAAD3 for ; Mon, 19 Sep 2022 11:09:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230110AbiISLJJ (ORCPT ); Mon, 19 Sep 2022 07:09:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230022AbiISLI7 (ORCPT ); Mon, 19 Sep 2022 07:08:59 -0400 Received: from mail-lj1-x22c.google.com (mail-lj1-x22c.google.com [IPv6:2a00:1450:4864:20::22c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82FA9BC89 for ; Mon, 19 Sep 2022 04:08:57 -0700 (PDT) Received: by mail-lj1-x22c.google.com with SMTP id x29so1174736ljq.2 for ; Mon, 19 Sep 2022 04:08:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=0XZ1fIAbu/Bo6mejWkFqmWH4riBY+wNGlvz0P7VQtb0=; b=JjmQgasq68yuvds/f/LD54+pb+BlpbsAUOxwGrmctAjvzPq55QrDfd8UNphwyD5CKp i4AH3jy7KW+B0sZXXqiLv5s5m/WSeLfrqPDHayXJbR33ev4UgBihAi1C+avD9OJscKDD xhPTY4jkFw+psnTmDYDQj5dkrQZJ8g1tzVCLoRLgnkudiJyb9HUOBpsZVnkD3UrrYXsq y8B+RRZQC1eYbNy363PqKZyJTuFFAPt0kn4pBP2B6sPkPRaOgRz06mPv5Hs1xj11qWhx 1dGYS3fbxhoUBhTDiuAeIifdMGU5QPSdxGRmmiS/r03u0EvtQd2ZHNw1PMOj3LVnd+h8 gyHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=0XZ1fIAbu/Bo6mejWkFqmWH4riBY+wNGlvz0P7VQtb0=; b=5sDriTtqmrpYVbGArg9HM+y/ikffusaiN+bHBoz+2ZZobJZhm8kexDSFIhG4/2sqdt Whh9qei0yL0D2c46ciSgIM8LhIbt/MaOgsi4qNL8XQGQ8dj7NL17UIJjXWXXhqvlNjja paRcxwyoYprMW7emS56rP2DIiB4O9Q+pfo9V6EAWM0/K4tezrvmjcMV80Tn0lmcPuW0q egYAbLgZLRD+xbhtoZE5a/Mh9VeFhD4CCcmHDlYnhIhnz1dDdZJOFa8zjBDTZ5+WtxY5 UUi941pvArS5qd2kMqY+35+J/dvWjcMQi1haKPMLOZE4JRFVX1szZynVLZuMYAqgSoT7 rigg== X-Gm-Message-State: ACrzQf1+GbfkgWTZtxYuPNfv9P1MxeV/d5uWk1wsVoqot5V6b2ngkkTi qADLJJIcE2RAbC1K9pGYekstxwwAcH+6hw== X-Google-Smtp-Source: AMsMyM63m23EKZJWSNjcDVRwOthG79RouA+qEue1BNI5fq4/Rn1HsABNKeXYahlGekb0zrt7ofQ+ig== X-Received: by 2002:a2e:b8c3:0:b0:26c:2fa9:338a with SMTP id s3-20020a2eb8c3000000b0026c2fa9338amr4769418ljp.331.1663585736805; Mon, 19 Sep 2022 04:08:56 -0700 (PDT) Received: from wse-c0089.westermo.com (h-98-128-229-160.NA.cust.bahnhof.se. [98.128.229.160]) by smtp.gmail.com with ESMTPSA id t13-20020a05651c204d00b00266d3f689e1sm4879261ljo.43.2022.09.19.04.08.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Sep 2022 04:08:56 -0700 (PDT) From: Mattias Forsblad To: netdev@vger.kernel.org Cc: Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux@armlinux.org.uk, ansuelsmth@gmail.com, Mattias Forsblad Subject: [PATCH net-next v14 7/7] net: dsa: qca8k: Use new convenience functions Date: Mon, 19 Sep 2022 13:08:47 +0200 Message-Id: <20220919110847.744712-8-mattias.forsblad@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220919110847.744712-1-mattias.forsblad@gmail.com> References: <20220919110847.744712-1-mattias.forsblad@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Use the new common convenience functions for sending and waiting for frames. Reviewed-by: Florian Fainelli Signed-off-by: Mattias Forsblad Tested-by: Christian Marangi --- drivers/net/dsa/qca/qca8k-8xxx.c | 68 +++++++++++--------------------- 1 file changed, 24 insertions(+), 44 deletions(-) diff --git a/drivers/net/dsa/qca/qca8k-8xxx.c b/drivers/net/dsa/qca/qca8k-8xxx.c index c181346388a4..a4ec0d0e608d 100644 --- a/drivers/net/dsa/qca/qca8k-8xxx.c +++ b/drivers/net/dsa/qca/qca8k-8xxx.c @@ -160,7 +160,7 @@ static void qca8k_rw_reg_ack_handler(struct dsa_switch *ds, struct sk_buff *skb) QCA_HDR_MGMT_DATA2_LEN); } - complete(&mgmt_eth_data->rw_done); + dsa_switch_inband_complete(ds, &mgmt_eth_data->rw_done); } static struct sk_buff *qca8k_alloc_mdio_header(enum mdio_cmd cmd, u32 reg, u32 *val, @@ -228,6 +228,7 @@ static void qca8k_mdio_header_fill_seq_num(struct sk_buff *skb, u32 seq_num) static int qca8k_read_eth(struct qca8k_priv *priv, u32 reg, u32 *val, int len) { struct qca8k_mgmt_eth_data *mgmt_eth_data = &priv->mgmt_eth_data; + struct dsa_switch *ds = priv->ds; struct sk_buff *skb; bool ack; int ret; @@ -248,17 +249,13 @@ static int qca8k_read_eth(struct qca8k_priv *priv, u32 reg, u32 *val, int len) skb->dev = priv->mgmt_master; - reinit_completion(&mgmt_eth_data->rw_done); - /* Increment seq_num and set it in the mdio pkt */ mgmt_eth_data->seq++; qca8k_mdio_header_fill_seq_num(skb, mgmt_eth_data->seq); mgmt_eth_data->ack = false; - dev_queue_xmit(skb); - - ret = wait_for_completion_timeout(&mgmt_eth_data->rw_done, - msecs_to_jiffies(QCA8K_ETHERNET_TIMEOUT)); + ret = dsa_switch_inband_tx(ds, skb, &mgmt_eth_data->rw_done, + QCA8K_ETHERNET_TIMEOUT); *val = mgmt_eth_data->data[0]; if (len > QCA_HDR_MGMT_DATA1_LEN) @@ -280,6 +277,7 @@ static int qca8k_read_eth(struct qca8k_priv *priv, u32 reg, u32 *val, int len) static int qca8k_write_eth(struct qca8k_priv *priv, u32 reg, u32 *val, int len) { struct qca8k_mgmt_eth_data *mgmt_eth_data = &priv->mgmt_eth_data; + struct dsa_switch *ds = priv->ds; struct sk_buff *skb; bool ack; int ret; @@ -300,17 +298,13 @@ static int qca8k_write_eth(struct qca8k_priv *priv, u32 reg, u32 *val, int len) skb->dev = priv->mgmt_master; - reinit_completion(&mgmt_eth_data->rw_done); - /* Increment seq_num and set it in the mdio pkt */ mgmt_eth_data->seq++; qca8k_mdio_header_fill_seq_num(skb, mgmt_eth_data->seq); mgmt_eth_data->ack = false; - dev_queue_xmit(skb); - - ret = wait_for_completion_timeout(&mgmt_eth_data->rw_done, - msecs_to_jiffies(QCA8K_ETHERNET_TIMEOUT)); + ret = dsa_switch_inband_tx(ds, skb, &mgmt_eth_data->rw_done, + QCA8K_ETHERNET_TIMEOUT); ack = mgmt_eth_data->ack; @@ -441,24 +435,22 @@ static struct regmap_config qca8k_regmap_config = { }; static int -qca8k_phy_eth_busy_wait(struct qca8k_mgmt_eth_data *mgmt_eth_data, +qca8k_phy_eth_busy_wait(struct qca8k_priv *priv, struct sk_buff *read_skb, u32 *val) { + struct qca8k_mgmt_eth_data *mgmt_eth_data = &priv->mgmt_eth_data; struct sk_buff *skb = skb_copy(read_skb, GFP_KERNEL); + struct dsa_switch *ds = priv->ds; bool ack; int ret; - reinit_completion(&mgmt_eth_data->rw_done); - /* Increment seq_num and set it in the copy pkt */ mgmt_eth_data->seq++; qca8k_mdio_header_fill_seq_num(skb, mgmt_eth_data->seq); mgmt_eth_data->ack = false; - dev_queue_xmit(skb); - - ret = wait_for_completion_timeout(&mgmt_eth_data->rw_done, - QCA8K_ETHERNET_TIMEOUT); + ret = dsa_switch_inband_tx(ds, skb, &mgmt_eth_data->rw_done, + QCA8K_ETHERNET_TIMEOUT); ack = mgmt_eth_data->ack; @@ -480,6 +472,7 @@ qca8k_phy_eth_command(struct qca8k_priv *priv, bool read, int phy, struct sk_buff *write_skb, *clear_skb, *read_skb; struct qca8k_mgmt_eth_data *mgmt_eth_data; u32 write_val, clear_val = 0, val; + struct dsa_switch *ds = priv->ds; struct net_device *mgmt_master; int ret, ret1; bool ack; @@ -540,17 +533,13 @@ qca8k_phy_eth_command(struct qca8k_priv *priv, bool read, int phy, clear_skb->dev = mgmt_master; write_skb->dev = mgmt_master; - reinit_completion(&mgmt_eth_data->rw_done); - /* Increment seq_num and set it in the write pkt */ mgmt_eth_data->seq++; qca8k_mdio_header_fill_seq_num(write_skb, mgmt_eth_data->seq); mgmt_eth_data->ack = false; - dev_queue_xmit(write_skb); - - ret = wait_for_completion_timeout(&mgmt_eth_data->rw_done, - QCA8K_ETHERNET_TIMEOUT); + ret = dsa_switch_inband_tx(ds, write_skb, &mgmt_eth_data->rw_done, + QCA8K_ETHERNET_TIMEOUT); ack = mgmt_eth_data->ack; @@ -569,7 +558,7 @@ qca8k_phy_eth_command(struct qca8k_priv *priv, bool read, int phy, ret = read_poll_timeout(qca8k_phy_eth_busy_wait, ret1, !(val & QCA8K_MDIO_MASTER_BUSY), 0, QCA8K_BUSY_WAIT_TIMEOUT * USEC_PER_MSEC, false, - mgmt_eth_data, read_skb, &val); + priv, read_skb, &val); if (ret < 0 && ret1 < 0) { ret = ret1; @@ -577,17 +566,14 @@ qca8k_phy_eth_command(struct qca8k_priv *priv, bool read, int phy, } if (read) { - reinit_completion(&mgmt_eth_data->rw_done); - /* Increment seq_num and set it in the read pkt */ mgmt_eth_data->seq++; qca8k_mdio_header_fill_seq_num(read_skb, mgmt_eth_data->seq); mgmt_eth_data->ack = false; - dev_queue_xmit(read_skb); - - ret = wait_for_completion_timeout(&mgmt_eth_data->rw_done, - QCA8K_ETHERNET_TIMEOUT); + ret = dsa_switch_inband_tx(ds, read_skb, + &mgmt_eth_data->rw_done, + QCA8K_ETHERNET_TIMEOUT); ack = mgmt_eth_data->ack; @@ -606,17 +592,13 @@ qca8k_phy_eth_command(struct qca8k_priv *priv, bool read, int phy, kfree_skb(read_skb); } exit: - reinit_completion(&mgmt_eth_data->rw_done); - /* Increment seq_num and set it in the clear pkt */ mgmt_eth_data->seq++; qca8k_mdio_header_fill_seq_num(clear_skb, mgmt_eth_data->seq); mgmt_eth_data->ack = false; - dev_queue_xmit(clear_skb); - - wait_for_completion_timeout(&mgmt_eth_data->rw_done, - QCA8K_ETHERNET_TIMEOUT); + dsa_switch_inband_tx(ds, clear_skb, &mgmt_eth_data->rw_done, + QCA8K_ETHERNET_TIMEOUT); mutex_unlock(&mgmt_eth_data->mutex); @@ -1528,7 +1510,7 @@ static void qca8k_mib_autocast_handler(struct dsa_switch *ds, struct sk_buff *sk exit: /* Complete on receiving all the mib packet */ if (refcount_dec_and_test(&mib_eth_data->port_parsed)) - complete(&mib_eth_data->rw_done); + dsa_switch_inband_complete(ds, &mib_eth_data->rw_done); } static int @@ -1543,8 +1525,6 @@ qca8k_get_ethtool_stats_eth(struct dsa_switch *ds, int port, u64 *data) mutex_lock(&mib_eth_data->mutex); - reinit_completion(&mib_eth_data->rw_done); - mib_eth_data->req_port = dp->index; mib_eth_data->data = data; refcount_set(&mib_eth_data->port_parsed, QCA8K_NUM_PORTS); @@ -1562,8 +1542,8 @@ qca8k_get_ethtool_stats_eth(struct dsa_switch *ds, int port, u64 *data) if (ret) goto exit; - ret = wait_for_completion_timeout(&mib_eth_data->rw_done, QCA8K_ETHERNET_TIMEOUT); - + ret = dsa_switch_inband_tx(ds, NULL, &mib_eth_data->rw_done, + QCA8K_ETHERNET_TIMEOUT); exit: mutex_unlock(&mib_eth_data->mutex); From patchwork Mon Sep 19 22:18:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 12981050 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E1CC9ECAAA1 for ; Mon, 19 Sep 2022 22:19:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229666AbiISWTF (ORCPT ); Mon, 19 Sep 2022 18:19:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229453AbiISWTD (ORCPT ); Mon, 19 Sep 2022 18:19:03 -0400 Received: from vps0.lunn.ch (vps0.lunn.ch [185.16.172.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C8C53AB06 for ; Mon, 19 Sep 2022 15:19:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:From:Sender:Reply-To:Subject:Date: Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Content-Disposition:In-Reply-To:References; bh=UgQImkQHJE4O46BAEidJTBzO/tkp+xEr43bbZJ25hs0=; b=aSxCdxIqcPSYnhrOW/Ay8GMoPt ZjpGX8T62XuW9ggdMkJ5NwWyJ3tYp6tN4BHslcUymeTK/qhy6yQOMlZCuYSJbQ5dOhJL0tlCtzJX8 96wpDNGw15HiBhn86jozDH2/SveNXkigCBwu//geTWZFjnEbeBZdXIKOtRc2jnsjLnf0=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1oaP6R-00HBRR-8m; Tue, 20 Sep 2022 00:18:59 +0200 From: Andrew Lunn To: mattias.forsblad@gmail.com Cc: netdev , Florian Fainelli , Vladimir Oltean , Christian Marangi , Andrew Lunn Subject: [PATCH rfc v0 8/9] net: dsa: qca8k: Pass response buffer via dsa_rmu_request Date: Tue, 20 Sep 2022 00:18:52 +0200 Message-Id: <20220919221853.4095491-9-andrew@lunn.ch> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220919221853.4095491-1-andrew@lunn.ch> References: <20220919110847.744712-3-mattias.forsblad@gmail.com> <20220919221853.4095491-1-andrew@lunn.ch> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Make the calling of operations on the switch more like a request response API by passing the address of the response buffer, rather than making use of global state. To avoid race conditions with the completion timeout, and late arriving responses, protect the resp members via a mutex. The qca8k response frame has an odd layout, the reply is not contiguous. Use a small intermediary buffer to convert the reply into something which can be memcpy'ed. Signed-off-by: Andrew Lunn --- drivers/net/dsa/qca/qca8k-8xxx.c | 31 ++++++++++++++++++++----------- drivers/net/dsa/qca/qca8k.h | 1 - include/net/dsa.h | 7 ++++++- net/dsa/dsa.c | 24 +++++++++++++++++++++++- 4 files changed, 49 insertions(+), 14 deletions(-) diff --git a/drivers/net/dsa/qca/qca8k-8xxx.c b/drivers/net/dsa/qca/qca8k-8xxx.c index 55a781851e28..234d79a09e78 100644 --- a/drivers/net/dsa/qca/qca8k-8xxx.c +++ b/drivers/net/dsa/qca/qca8k-8xxx.c @@ -138,6 +138,7 @@ static void qca8k_rw_reg_ack_handler(struct dsa_switch *ds, struct sk_buff *skb) struct qca8k_priv *priv = ds->priv; struct qca_mgmt_ethhdr *mgmt_ethhdr; u8 len, cmd; + u32 data[4]; int err = 0; mgmt_ethhdr = (struct qca_mgmt_ethhdr *)skb_mac_header(skb); @@ -151,17 +152,16 @@ static void qca8k_rw_reg_ack_handler(struct dsa_switch *ds, struct sk_buff *skb) err = -EPROTO; if (cmd == MDIO_READ) { - mgmt_eth_data->data[0] = mgmt_ethhdr->mdio_data; + data[0] = mgmt_ethhdr->mdio_data; /* Get the rest of the 12 byte of data. * The read/write function will extract the requested data. */ if (len > QCA_HDR_MGMT_DATA1_LEN) - memcpy(mgmt_eth_data->data + 1, skb->data, - QCA_HDR_MGMT_DATA2_LEN); + memcpy(&data[1], skb->data, QCA_HDR_MGMT_DATA2_LEN); } - dsa_inband_complete(&mgmt_eth_data->inband, err); + dsa_inband_complete(&mgmt_eth_data->inband, &data, sizeof(data), err); } static struct sk_buff *qca8k_alloc_mdio_header(enum mdio_cmd cmd, u32 reg, u32 *val, @@ -230,6 +230,7 @@ static int qca8k_read_eth(struct qca8k_priv *priv, u32 reg, u32 *val, int len) { struct qca8k_mgmt_eth_data *mgmt_eth_data = &priv->mgmt_eth_data; struct sk_buff *skb; + u32 data[4]; int ret; skb = qca8k_alloc_mdio_header(MDIO_READ, reg, NULL, @@ -249,12 +250,13 @@ static int qca8k_read_eth(struct qca8k_priv *priv, u32 reg, u32 *val, int len) skb->dev = priv->mgmt_master; ret = dsa_inband_request(&mgmt_eth_data->inband, skb, - qca8k_mdio_header_fill_seq_num, - QCA8K_ETHERNET_TIMEOUT); + qca8k_mdio_header_fill_seq_num, + &data, sizeof(data), + QCA8K_ETHERNET_TIMEOUT); - *val = mgmt_eth_data->data[0]; + *val = data[0]; if (len > QCA_HDR_MGMT_DATA1_LEN) - memcpy(val + 1, mgmt_eth_data->data + 1, len - QCA_HDR_MGMT_DATA1_LEN); + memcpy(val + 1, &data[1], len - QCA_HDR_MGMT_DATA1_LEN); mutex_unlock(&mgmt_eth_data->mutex); @@ -285,6 +287,7 @@ static int qca8k_write_eth(struct qca8k_priv *priv, u32 reg, u32 *val, int len) ret = dsa_inband_request(&mgmt_eth_data->inband, skb, qca8k_mdio_header_fill_seq_num, + NULL, 0, QCA8K_ETHERNET_TIMEOUT); mutex_unlock(&mgmt_eth_data->mutex); @@ -412,16 +415,18 @@ qca8k_phy_eth_busy_wait(struct qca8k_mgmt_eth_data *mgmt_eth_data, struct sk_buff *read_skb, u32 *val) { struct sk_buff *skb = skb_copy(read_skb, GFP_KERNEL); + u32 data[4]; int ret; ret = dsa_inband_request(&mgmt_eth_data->inband, skb, qca8k_mdio_header_fill_seq_num, + &data, sizeof(data), QCA8K_ETHERNET_TIMEOUT); if (ret) return ret; - *val = mgmt_eth_data->data[0]; + *val = data[0]; return 0; } @@ -434,6 +439,7 @@ qca8k_phy_eth_command(struct qca8k_priv *priv, bool read, int phy, struct qca8k_mgmt_eth_data *mgmt_eth_data; u32 write_val, clear_val = 0, val; struct net_device *mgmt_master; + u32 resp_data[4]; int ret, ret1; if (regnum >= QCA8K_MDIO_MASTER_MAX_REG) @@ -494,6 +500,7 @@ qca8k_phy_eth_command(struct qca8k_priv *priv, bool read, int phy, ret = dsa_inband_request(&mgmt_eth_data->inband, write_skb, qca8k_mdio_header_fill_seq_num, + NULL, 0, QCA8K_ETHERNET_TIMEOUT); if (ret) { @@ -514,12 +521,13 @@ qca8k_phy_eth_command(struct qca8k_priv *priv, bool read, int phy, if (read) { ret = dsa_inband_request(&mgmt_eth_data->inband, read_skb, qca8k_mdio_header_fill_seq_num, + &resp_data, sizeof(resp_data), QCA8K_ETHERNET_TIMEOUT); if (ret) goto exit; - ret = mgmt_eth_data->data[0] & QCA8K_MDIO_MASTER_DATA_MASK; + ret = resp_data[0] & QCA8K_MDIO_MASTER_DATA_MASK; } else { kfree_skb(read_skb); } @@ -527,6 +535,7 @@ qca8k_phy_eth_command(struct qca8k_priv *priv, bool read, int phy, ret = dsa_inband_request(&mgmt_eth_data->inband, clear_skb, qca8k_mdio_header_fill_seq_num, + NULL, 0, QCA8K_ETHERNET_TIMEOUT); mutex_unlock(&mgmt_eth_data->mutex); @@ -1442,7 +1451,7 @@ static void qca8k_mib_autocast_handler(struct dsa_switch *ds, struct sk_buff *sk exit: /* Complete on receiving all the mib packet */ if (refcount_dec_and_test(&mib_eth_data->port_parsed)) - dsa_inband_complete(&mib_eth_data->inband, err); + dsa_inband_complete(&mib_eth_data->inband, NULL, 0, err); } static int diff --git a/drivers/net/dsa/qca/qca8k.h b/drivers/net/dsa/qca/qca8k.h index 682106206282..70494096e251 100644 --- a/drivers/net/dsa/qca/qca8k.h +++ b/drivers/net/dsa/qca/qca8k.h @@ -348,7 +348,6 @@ enum { struct qca8k_mgmt_eth_data { struct dsa_inband inband; struct mutex mutex; /* Enforce one mdio read/write at time */ - u32 data[4]; }; struct qca8k_mib_eth_data { diff --git a/include/net/dsa.h b/include/net/dsa.h index 1a920f89b667..dad9e31d36ce 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -1285,12 +1285,17 @@ struct dsa_inband { u32 seqno; u32 seqno_mask; int err; + struct mutex resp_lock; /* Protects resp* members */ + void *resp; + unsigned int resp_len; }; void dsa_inband_init(struct dsa_inband *inband, u32 seqno_mask); -void dsa_inband_complete(struct dsa_inband *inband, int err); +void dsa_inband_complete(struct dsa_inband *inband, + void *resp, unsigned int resp_len, int err); int dsa_inband_request(struct dsa_inband *inband, struct sk_buff *skb, void (* insert_seqno)(struct sk_buff *skb, u32 seqno), + void *resp, unsigned int resp_len, int timeout_ms); int dsa_inband_wait_for_completion(struct dsa_inband *inband, int timeout_ms); u32 dsa_inband_seqno(struct dsa_inband *inband); diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c index 0de283ac0bfc..4fa0ab4ae58e 100644 --- a/net/dsa/dsa.c +++ b/net/dsa/dsa.c @@ -521,14 +521,24 @@ EXPORT_SYMBOL_GPL(dsa_mdb_present_in_other_db); void dsa_inband_init(struct dsa_inband *inband, u32 seqno_mask) { init_completion(&inband->completion); + mutex_init(&inband->resp_lock); inband->seqno_mask = seqno_mask; inband->seqno = 0; } EXPORT_SYMBOL_GPL(dsa_inband_init); -void dsa_inband_complete(struct dsa_inband *inband, int err) +void dsa_inband_complete(struct dsa_inband *inband, + void *resp, unsigned int resp_len, + int err) { inband->err = err; + + mutex_lock(&inband->resp_lock); + resp_len = min(inband->resp_len, resp_len); + if (inband->resp && resp) + memcpy(inband->resp, resp, resp_len); + mutex_unlock(&inband->resp_lock); + complete(&inband->completion); } EXPORT_SYMBOL_GPL(dsa_inband_complete); @@ -548,6 +558,7 @@ EXPORT_SYMBOL_GPL(dsa_inband_wait_for_completion); */ int dsa_inband_request(struct dsa_inband *inband, struct sk_buff *skb, void (* insert_seqno)(struct sk_buff *skb, u32 seqno), + void *resp, unsigned int resp_len, int timeout_ms) { unsigned long jiffies = msecs_to_jiffies(timeout_ms); @@ -556,6 +567,11 @@ int dsa_inband_request(struct dsa_inband *inband, struct sk_buff *skb, reinit_completion(&inband->completion); inband->err = 0; + mutex_lock(&inband->resp_lock); + inband->resp = resp; + inband->resp_len = resp_len; + mutex_unlock(&inband->resp_lock); + if (insert_seqno) { inband->seqno++; insert_seqno(skb, inband->seqno & inband->seqno_mask); @@ -564,6 +580,12 @@ int dsa_inband_request(struct dsa_inband *inband, struct sk_buff *skb, dev_queue_xmit(skb); ret = wait_for_completion_timeout(&inband->completion, jiffies); + + mutex_lock(&inband->resp_lock); + inband->resp = NULL; + inband->resp_len = 0; + mutex_unlock(&inband->resp_lock); + if (ret < 0) return ret; if (ret == 0)