From patchwork Fri Sep 9 08:51:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mattias Forsblad X-Patchwork-Id: 12971248 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 BA797ECAAA1 for ; Fri, 9 Sep 2022 08:51:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229780AbiIIIvx (ORCPT ); Fri, 9 Sep 2022 04:51:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230099AbiIIIvq (ORCPT ); Fri, 9 Sep 2022 04:51:46 -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 D495F12D183 for ; Fri, 9 Sep 2022 01:51:44 -0700 (PDT) Received: by mail-lf1-x130.google.com with SMTP id w8so1520705lft.12 for ; Fri, 09 Sep 2022 01:51:44 -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=zsnHYmYMzmTkLJ6LKB6GxQ39PgXOpuoo34Qk3CJkEHw=; b=Nzx6A3YH07XT6us4Bc3vzP/vQejBdYi7KSZunw7ZO+aofcLRzHgK/Fae8yurkZHccR sLMlsIVWFzXxYUvqfgP9G5jwl7ipDYcHphthnmHgo+sZXvdw9KKkT0754A4k80OErjgU x996gfFE6q8BZ5u2bGt8AYCT5RHlTENx5D+CXgHNLGn5m1xI7KwRCLrcF3GpKKP+Laie kGcTkZHjAKErGbGuXkdZzoHg/uB/L4bgcawJFSu08gC4U3IaHZKIOw7IwQa9AIcZC61Q TJ/mG3zvGTu6k3wIWmoyKQrdVIh11McQY/+vaYxTs5vGncIIuRyJocn41i972WzbEi8f uGfg== 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=zsnHYmYMzmTkLJ6LKB6GxQ39PgXOpuoo34Qk3CJkEHw=; b=r5ccIji13an/zsoYZEe60I/VJVfvqFYlw0k9Z3ynwM6jpOvStLPoqvsnySkuqiGWmb +G1Bx4G7Xr66daKILCaEt28OT9RKX56DpMf7RN2KTxulStttnoytPiAYYlGVYPOgN2pT nPbfxVZ7MujFBtNkAah8OEX4x7O8wo34x3QpCyHPuGwT+ArUd+ZjXFBZXGbJvWGvORNb uERJ+jXaqaHxRH9lQBkiMLRKVaRbmvXXONfYJ6KSy2Q/6xlpiMOXSHCx7IxQ7g7W0xGH CryQ+vx1m+8mKm0bY7P8KU5/OM9up69OJ5EYW+NUc7wFFKeiE1zwk/gx+JWDF56CjQkF n3aQ== X-Gm-Message-State: ACgBeo2ZVUWUwsG0N1KKMnJTu/pxDilVExy/xX7de7iYB8RifZBwmTmT vUyrjin2YXL5q4xuvManj8K7/2rvQrdBMweY X-Google-Smtp-Source: AA6agR6DswflVN4oRL4FlwfZSnoh/XkoBoQd3ddCaYay7Hq6GB2XAHRznemOyZBQx1Aa7vQdEY7YOQ== X-Received: by 2002:ac2:5c52:0:b0:498:ec75:c73c with SMTP id s18-20020ac25c52000000b00498ec75c73cmr2331833lfp.164.1662713502945; Fri, 09 Sep 2022 01:51:42 -0700 (PDT) Received: from wse-c0089.raspi.local (h-98-128-229-160.NA.cust.bahnhof.se. [98.128.229.160]) by smtp.gmail.com with ESMTPSA id q17-20020a05651c055100b00262fae1ffe6sm193956ljp.110.2022.09.09.01.51.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Sep 2022 01:51:42 -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 , Mattias Forsblad Subject: [PATCH net-next v8 1/6] net: dsa: mv88e6xxx: Add RMU enable for select switches. Date: Fri, 9 Sep 2022 10:51:33 +0200 Message-Id: <20220909085138.3539952-2-mattias.forsblad@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220909085138.3539952-1-mattias.forsblad@gmail.com> References: <20220909085138.3539952-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 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..b808009a6098 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 upstream_port) +{ + int val = MV88E6352_G1_CTL2_RMU_MODE_DISABLED; + + switch (upstream_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 upstream_port) +{ + int val = MV88E6352_G1_CTL2_RMU_MODE_DISABLED; + + switch (upstream_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 upstream_port) +{ + int val = MV88E6390_G1_CTL2_RMU_MODE_DISABLED; + + switch (upstream_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..29c0c8acb583 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 upstream_port); int mv88e6352_g1_rmu_disable(struct mv88e6xxx_chip *chip); +int mv88e6352_g1_rmu_enable(struct mv88e6xxx_chip *chip, int upstream_port); int mv88e6390_g1_rmu_disable(struct mv88e6xxx_chip *chip); +int mv88e6390_g1_rmu_enable(struct mv88e6xxx_chip *chip, int upstream_port); int mv88e6xxx_g1_set_device_number(struct mv88e6xxx_chip *chip, int index); From patchwork Fri Sep 9 08:51:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mattias Forsblad X-Patchwork-Id: 12971250 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 B24FDECAAD3 for ; Fri, 9 Sep 2022 08:52:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231680AbiIIIv6 (ORCPT ); Fri, 9 Sep 2022 04:51:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231371AbiIIIvs (ORCPT ); Fri, 9 Sep 2022 04:51:48 -0400 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDF3C110AB2 for ; Fri, 9 Sep 2022 01:51:45 -0700 (PDT) Received: by mail-lf1-x134.google.com with SMTP id f14so584493lfg.5 for ; Fri, 09 Sep 2022 01:51:45 -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=bWmhNNVHl3R8ha6SYx0y73Iir+uSkgTqxcDApePcL38=; b=NIJLiQFRGts7mJdelZ/NjPIljSf/hbBhbl174StI8FasY6sqY342Anwn/xIxwE/f6k TI4wDWZtnRz2Z5Hc5oyS+rLcGPgMr3pLQhWI4BAq9ODLFxMSELO85gAwVA53ZB4Ls78P iSz7TigpvxhWdpjn/OTq9FffIFRLsoDktz3xiT5J7JT22yWFA73ikbI7nA75NtEmwDo7 t/xBPIxSE+WV39EmAjXe8uNihUOnmCcuNESk2lp51h9YD/ubAM/ySzUFCoYZR+aAZ3Zh NTVDXZZMdywHQsLwzwHOP9AFDT0SK7AfhcmgYUThv4gYcvf0+2RCwM0EX6w6o2lFGxo5 YncA== 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=bWmhNNVHl3R8ha6SYx0y73Iir+uSkgTqxcDApePcL38=; b=a1+T711IQ4Bf/+A3CuJDc2NEXBlnH1fgk2l0IMoM+AdwWfD1BOmr9HWQ56MRbp3fjD nzKFW/kxRElBj23P0s5Pjwm9tC+ji5fsU1V7egO7uDLZdQDZ8GCNzjIzyIU2gZQTk9fk 8fwyD6oIxVeYcY3UKL9qLIRBbl1NAjDgR5KEIv2HqOaoBJeNDjowBflUmtUqrBpHimxS PHa1MMBvH5qv8nYbZzcA4KpPJ1fenrRYjg66Jq7HWVJ4YwuFlt2xYydj5f+n2aqud66/ 4gV3U9zY4ygBrsjvUnvwg7978OiG9fAj08RHCQoqnuE97Jy4WZf6ZCMFuZfMQOVtXeXw 4Xng== X-Gm-Message-State: ACgBeo3V9RzwHGgwfMlOnU1QBbas0jyAqXx0mtoEed7ONqsaxaQ9bicZ /ANLAwW5j/1cBlDRcbbwaZOQH5vqW32GeTr1 X-Google-Smtp-Source: AA6agR6Eq8Z1KHoOWSX9niqQDImrohMAcZ4yMX48BdY2RWSk6Awp/Ammyshum8oKrVc+iJb7kGMmHw== X-Received: by 2002:ac2:5d22:0:b0:494:a1c0:b2ed with SMTP id i2-20020ac25d22000000b00494a1c0b2edmr4327880lfb.482.1662713503807; Fri, 09 Sep 2022 01:51:43 -0700 (PDT) Received: from wse-c0089.raspi.local (h-98-128-229-160.NA.cust.bahnhof.se. [98.128.229.160]) by smtp.gmail.com with ESMTPSA id q17-20020a05651c055100b00262fae1ffe6sm193956ljp.110.2022.09.09.01.51.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Sep 2022 01:51:43 -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 , Mattias Forsblad Subject: [PATCH net-next v8 2/6] net: dsa: Add convenience functions for frame handling Date: Fri, 9 Sep 2022 10:51:34 +0200 Message-Id: <20220909085138.3539952-3-mattias.forsblad@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220909085138.3539952-1-mattias.forsblad@gmail.com> References: <20220909085138.3539952-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 | 14 ++++++++++++++ net/dsa/dsa.c | 17 +++++++++++++++++ net/dsa/dsa2.c | 2 ++ 3 files changed, 33 insertions(+) diff --git a/include/net/dsa.h b/include/net/dsa.h index f2ce12860546..0e8a7ef17490 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,18 @@ 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? */ + if (completion) + complete(completion); + else + complete(&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..a1b3ecfdffb8 100644 --- a/net/dsa/dsa2.c +++ b/net/dsa/dsa2.c @@ -1746,6 +1746,8 @@ static int dsa_switch_probe(struct dsa_switch *ds) dsa_tree_put(dst); } + init_completion(&ds->inband_done); + return err; } From patchwork Fri Sep 9 08:51:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mattias Forsblad X-Patchwork-Id: 12971255 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 98B7FECAAD3 for ; Fri, 9 Sep 2022 08:52:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231504AbiIIIwC (ORCPT ); Fri, 9 Sep 2022 04:52:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231578AbiIIIvv (ORCPT ); Fri, 9 Sep 2022 04:51:51 -0400 Received: from mail-lj1-x235.google.com (mail-lj1-x235.google.com [IPv6:2a00:1450:4864:20::235]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F68C12B365 for ; Fri, 9 Sep 2022 01:51:46 -0700 (PDT) Received: by mail-lj1-x235.google.com with SMTP id 9so106076ljr.2 for ; Fri, 09 Sep 2022 01:51:46 -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=ruv5tr93aYjBezDdb5DTBRfAjKu1mzpocvMW/HyVJOc=; b=giOkbYYXtiiHcX7qVPNo3D6u+x84gV+DsFTWwqRGPcylZdKH5G0y8qGvxctczzdpJG hgIGFoBvpzizLj7fraF5Dj//m75iHqhBjiQNaPwtqqC4QODX/q8mBjO+hXcRsbMf5FYB aEtxVa96uwnwS0BXTQtbksGWGFBlm25EuMPvL4Ji+BG7BCoN09n0Fp8Ssl4c8+wFKzcf 0fddcbatKJhEsrhI70OTzvN+itVVFT7GIWFTPbI1/9DEI5VW0nN1ZVb30Et+JqAI5Z1A WIgJ9p6fmgjD9Y/ivz8PpOSKTmu9O6TNaQpCGVZW1buZDnONF+WlBm77fPQWWjeSVElL W0eA== 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=ruv5tr93aYjBezDdb5DTBRfAjKu1mzpocvMW/HyVJOc=; b=tx0gXS52RB55pwMwn7Nsb6cgQEGlaNPY6vyneT+jPMBvR/KNo/TwROPFOAa5dwhRCX GqvUIaWyyjGyVgPIjJXKPTCbxIbaDfoBFkrpVOj9rTBTBUPVMsNA51TT6y8CTJ7ca9ZQ DuPGMuWkO2yPiV+RB69ews9nArp4NIZJr6v8BfOQudfWzvrLIJEWVlFFZm/S8ml8tMpj xEKrzuLCzolz84hPHaCxw5sF91hq39khYZW2hyoZjn5lSDM2FgDhAC+mtIo13yE5X/rd iijDmWIUGGyVY+NTzAK8Q1cZ8QMCaFs/d1+8BibXD3ziCG+pi0Wqbi44F3lIWPqvxorB M4bw== X-Gm-Message-State: ACgBeo3mnwTWM/473kB1IP7M/53dXVwggJYw6kaLq6it4VkQeSdS02rY 11IE38dKZdRvf+QD1lvecOcyOm0vsaStdsUu X-Google-Smtp-Source: AA6agR4c8W+kBAp4RnvfIPYmJXw/zsKOle/df+MbRYSW2hcTzqZK1jd+QP6jlK+xr2kPKZUHrdxgiw== X-Received: by 2002:a05:651c:1941:b0:268:9a35:4a00 with SMTP id bs1-20020a05651c194100b002689a354a00mr3472267ljb.264.1662713504554; Fri, 09 Sep 2022 01:51:44 -0700 (PDT) Received: from wse-c0089.raspi.local (h-98-128-229-160.NA.cust.bahnhof.se. [98.128.229.160]) by smtp.gmail.com with ESMTPSA id q17-20020a05651c055100b00262fae1ffe6sm193956ljp.110.2022.09.09.01.51.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Sep 2022 01:51:44 -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 , Mattias Forsblad Subject: [PATCH net-next v8 3/6] net: dsa: Introduce dsa tagger data operation. Date: Fri, 9 Sep 2022 10:51:35 +0200 Message-Id: <20220909085138.3539952-4-mattias.forsblad@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220909085138.3539952-1-mattias.forsblad@gmail.com> References: <20220909085138.3539952-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 it's associated hookup functions. Reviewed-by: Andrew Lunn Signed-off-by: Mattias Forsblad Reviewed-by: Florian Fainelli --- include/net/dsa.h | 5 +++++ net/dsa/tag_dsa.c | 32 +++++++++++++++++++++++++++++--- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/include/net/dsa.h b/include/net/dsa.h index 0e8a7ef17490..8510267d6188 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -130,6 +130,11 @@ struct dsa_lag { refcount_t refcount; }; +struct dsa_tagger_data { + void (*decode_frame2reg)(struct net_device *netdev, + struct sk_buff *skb); +}; + struct dsa_switch_tree { struct list_head list; diff --git a/net/dsa/tag_dsa.c b/net/dsa/tag_dsa.c index e4b6e3f2a3db..3dd1dcddaf05 100644 --- a/net/dsa/tag_dsa.c +++ b/net/dsa/tag_dsa.c @@ -198,7 +198,10 @@ 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_tagger_data *tagger_data; + struct dsa_port *dp = dev->dsa_ptr; bool trap = false, trunk = false; + struct dsa_switch *ds = dp->ds; int source_device, source_port; enum dsa_code code; enum dsa_cmd cmd; @@ -218,9 +221,9 @@ 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. - */ + tagger_data = ds->tagger_data; + if (likely(tagger_data->decode_frame2reg)) + tagger_data->decode_frame2reg(dev, skb); return NULL; case DSA_CODE_ARP_MIRROR: case DSA_CODE_POLICY_MIRROR: @@ -323,6 +326,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 +365,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 +409,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 Fri Sep 9 08:51:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mattias Forsblad X-Patchwork-Id: 12971256 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 41A14ECAAD3 for ; Fri, 9 Sep 2022 08:52:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231722AbiIIIwD (ORCPT ); Fri, 9 Sep 2022 04:52:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231492AbiIIIvv (ORCPT ); Fri, 9 Sep 2022 04:51:51 -0400 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9152B4BA54 for ; Fri, 9 Sep 2022 01:51:47 -0700 (PDT) Received: by mail-lf1-x12f.google.com with SMTP id bq23so1547978lfb.7 for ; Fri, 09 Sep 2022 01:51:47 -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=+tLunMScdUoAyATdGWlEVONC0nz6+7Pb5ZJhnjqwByY=; b=QNb4B5zQ8qpq16eJHIxEKOS9iZJNaTLb3vIXzE1pRnxQaHuvKIF0NwDKXKjRBemdHr gHCht8IjeYReNakxhe/MHCRXeKdSorP700VvPvM5fOYUHxSHHEpLuKFF/0FwKCe26WSa QJXgMjv2rAd8vrTa7beAMRh1X28Pcn8J5N7CgocJBhVujMYxyvEpWFV3mtWBUKGBbL9D 4d0s1t5jUBFWVoNdCflzsxCEjDzEWRI1aZXz9QCmPjVPDaJ0EuHkFXu9rJltWgA8Erfc giuBC5BKUFyvgkwcNhNbzWkXhaviE08nkHoqIQ/ndpAwxifgMNZy3+bao6rBEmxVntSa cjkg== 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=+tLunMScdUoAyATdGWlEVONC0nz6+7Pb5ZJhnjqwByY=; b=jMgh1zI0GU6miDlf2KPWmy+nqVtpf2JaUugAiIXDaw57KIH7SDM0hXFLcH/YrL9FUd PA5LmcgpdIfkLfBbIsOaNLhlhAisELWCEAJkDCFYJ6xiOiJZIxGNmReUwly8/Vq9Qb4u J+nrt0qV6WC/3Qb8t0jHPHV2TJ6h6J2/ac4Xzyr+hYdevHmer+IyRyvOrctA+Z5ByNpa 4J/EXEGY+OhUbU8mgA+S5v4c2BZYVvqAf7p4P+Fq/u+AO3Bmtof9K3FhZzMfwcFXJaD9 FaX82UaQFoMROqMcX6K94ekqHI2TzHXplB8Vvo1TxZf9W1UEaYWmoj6XxY6o8FV+WAX0 iHOA== X-Gm-Message-State: ACgBeo3nfaM0WrxINRachFcvTCwCpDKRphYlxi31C3rQtbvxD+KYbcpY 9SVgXhYNjXYN/DpPf+r42hRXOvpZGBS0e3q5 X-Google-Smtp-Source: AA6agR4HiLtTdCeCNC1HXbO6tJWYlMsU+sSXjDb/Cdo0SCIRBXj0nxuzVtREn9C8yfApD6hpmshvoA== X-Received: by 2002:a05:6512:22ce:b0:497:499e:c966 with SMTP id g14-20020a05651222ce00b00497499ec966mr3871963lfu.402.1662713505549; Fri, 09 Sep 2022 01:51:45 -0700 (PDT) Received: from wse-c0089.raspi.local (h-98-128-229-160.NA.cust.bahnhof.se. [98.128.229.160]) by smtp.gmail.com with ESMTPSA id q17-20020a05651c055100b00262fae1ffe6sm193956ljp.110.2022.09.09.01.51.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Sep 2022 01:51:45 -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 , Mattias Forsblad Subject: [PATCH net-next v8 4/6] net: dsa: mv88e6xxxx: Add RMU functionality. Date: Fri, 9 Sep 2022 10:51:36 +0200 Message-Id: <20220909085138.3539952-5-mattias.forsblad@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220909085138.3539952-1-mattias.forsblad@gmail.com> References: <20220909085138.3539952-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. Signed-off-by: Mattias Forsblad Reported-by: kernel test robot --- drivers/net/dsa/mv88e6xxx/Makefile | 1 + drivers/net/dsa/mv88e6xxx/chip.c | 28 ++- drivers/net/dsa/mv88e6xxx/chip.h | 19 ++ drivers/net/dsa/mv88e6xxx/rmu.c | 270 +++++++++++++++++++++++++++++ drivers/net/dsa/mv88e6xxx/rmu.h | 76 ++++++++ 5 files changed, 386 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..bbdf229c9e71 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 -EOPNOTSUPP; + } + + 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_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..566d18cf5170 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.h +++ b/drivers/net/dsa/mv88e6xxx/chip.h @@ -282,6 +282,18 @@ struct mv88e6xxx_port { struct devlink_region *region; }; +struct mv88e6xxx_rmu { + /* RMU resources */ + struct net_device *master_netdev; + const struct mv88e6xxx_bus_ops *smi_ops; + struct mv88e6xxx_bus_ops *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 +422,9 @@ struct mv88e6xxx_chip { /* Bridge MST to SID mappings */ struct list_head msts; + + /* RMU resources */ + struct mv88e6xxx_rmu rmu; }; struct mv88e6xxx_bus_ops { @@ -805,4 +820,8 @@ static inline void mv88e6xxx_reg_unlock(struct mv88e6xxx_chip *chip) int mv88e6xxx_fid_map(struct mv88e6xxx_chip *chip, unsigned long *bitmap); +static inline bool mv88e6xxx_rmu_available(struct mv88e6xxx_chip *chip) +{ + return chip->rmu.master_netdev ? 1 : 0; +} #endif /* _MV88E6XXX_CHIP_H */ diff --git a/drivers/net/dsa/mv88e6xxx/rmu.c b/drivers/net/dsa/mv88e6xxx/rmu.c new file mode 100644 index 000000000000..20a91629e72b --- /dev/null +++ b/drivers/net/dsa/mv88e6xxx/rmu.c @@ -0,0 +1,270 @@ +// 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 void mv88e6xxx_rmu_create_l2(struct sk_buff *skb, struct dsa_port *dp) +{ + struct mv88e6xxx_chip *chip = dp->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, dp->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 */ + skb_push(skb, ETH_ALEN * 2 + extra); + eth = (struct ethhdr *)skb->data; + memcpy(eth->h_dest, rmu_dest_addr, ETH_ALEN); + memcpy(eth->h_source, chip->rmu.master_netdev->dev_addr, ETH_ALEN); + + 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, int port, + const void *req, int req_len, + void *resp, unsigned int *resp_len) +{ + struct dsa_port *dp; + struct sk_buff *skb; + unsigned char *data; + int ret = 0; + + dp = dsa_to_port(chip->ds, port); + if (!dp) + return -EINVAL; + + 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(skb, dp); + + mutex_lock(&chip->rmu.mutex); + + ret = dsa_switch_inband_tx(dp->ds, skb, NULL, MV88E6XXX_RMU_WAIT_TIME_MS); + if (ret < 0) { + dev_err(chip->dev, "RMU: timeout waiting for request (%pe) on port %d\n", + ERR_PTR(ret), port); + 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); + } + + /* We're done with the received data copy, discard it */ + kfree_skb(chip->rmu.resp); + chip->rmu.resp = NULL; + +out: + mutex_unlock(&chip->rmu.mutex); + + return ret > 0 ? 0 : ret; +} + +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 rmu_header resp; + int resp_len; + int ret = -1; + u16 format; + u16 code; + + resp_len = sizeof(resp); + ret = mv88e6xxx_rmu_send_wait(chip, port, 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 */ + format = get_unaligned_be16(&resp.format); + code = get_unaligned_be16(&resp.code); + + if (format != MV88E6XXX_RMU_RESP_FORMAT_1 && + format != MV88E6XXX_RMU_RESP_FORMAT_2 && + code != MV88E6XXX_RMU_RESP_CODE_GOT_ID) { + net_dbg_ratelimited("RMU: received unknown format 0x%04x code 0x%04x", + format, code); + return -EIO; + } + + chip->rmu.prodnr = get_unaligned_be16(&resp.prodnr); + + return 0; +} + +static void mv88e6xxx_disable_rmu(struct mv88e6xxx_chip *chip) +{ + chip->smi_ops = chip->rmu.smi_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->smi_ops = chip->rmu.rmu_ops; + + return 0; +} + +void mv88e6xxx_master_change(struct dsa_switch *ds, const struct net_device *master, + bool operational) +{ + struct mv88e6xxx_chip *chip = ds->priv; + struct dsa_port *cpu_dp; + int port; + int ret; + + cpu_dp = master->dsa_ptr; + 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; + } + } + + 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 net_device *dev, struct sk_buff *skb) +{ + struct dsa_port *dp = dev->dsa_ptr; + struct dsa_switch *ds = dp->ds; + struct mv88e6xxx_chip *chip; + int source_device; + u8 *dsa_header; + u8 seqno; + + /* Decode Frame2Reg DSA portion */ + dsa_header = skb->data - 2; + + source_device = FIELD_GET(MV88E6XXX_SOURCE_DEV, dsa_header[0]); + ds = dsa_switch_find(ds->dst->index, source_device); + if (!ds) { + net_err_ratelimited("RMU: Didn't find switch with index %d", source_device); + return; + } + + if (mv88e6xxx_validate_mac(ds, skb)) + return; + + chip = ds->priv; + 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); + + /* Make an copy for further processing in initiator */ + chip->rmu.resp = skb_copy(skb, GFP_ATOMIC); + if (!chip->rmu.resp) + return; + + dsa_switch_inband_complete(ds, NULL); +} + +int mv88e6xxx_rmu_setup(struct mv88e6xxx_chip *chip) +{ + mutex_init(&chip->rmu.mutex); + + 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..1dd533361661 --- /dev/null +++ b/drivers/net/dsa/mv88e6xxx/rmu.h @@ -0,0 +1,76 @@ +/* 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 + +static const u8 rmu_dest_addr[ETH_ALEN] = { 0x01, 0x50, 0x43, 0x00, 0x00, 0x00 }; + +#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_SOURCE_DEV GENMASK(5, 0) +#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 rmu_header { + u16 format; + u16 prodnr; + u16 code; +} __packed; + +struct dump_mib_resp { + struct rmu_header rmu_header; + u8 devnum; + u8 portnum; + u32 timestamp; + u32 mib[MV88E6XXX_RMU_MAX_RMON]; +} __packed; + +int mv88e6xxx_rmu_setup(struct mv88e6xxx_chip *chip); + +void mv88e6xxx_master_change(struct dsa_switch *ds, const struct net_device *master, + bool operational); + +void mv88e6xxx_decode_frame2reg_handler(struct net_device *dev, struct sk_buff *skb); + +#endif /* _MV88E6XXX_RMU_H_ */ From patchwork Fri Sep 9 08:51:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mattias Forsblad X-Patchwork-Id: 12971251 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 418FBECAAA1 for ; Fri, 9 Sep 2022 08:52:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231687AbiIIIv7 (ORCPT ); Fri, 9 Sep 2022 04:51:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231504AbiIIIvv (ORCPT ); Fri, 9 Sep 2022 04:51:51 -0400 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C80C642E9 for ; Fri, 9 Sep 2022 01:51:48 -0700 (PDT) Received: by mail-lf1-x12a.google.com with SMTP id a8so1513419lff.13 for ; Fri, 09 Sep 2022 01:51:48 -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=l1jwyRrgWZk9ydwmIxs0l3qr3oYAbIS7S0+df2N8X0E=; b=gelITtSt4PjZ9Nj1lgX1NrDttSQD5Rqvo2dQChr2IvjlmOkgQEGzGnZTplA87uVbnq rW5Ic9FgLzCIK7zLAhzd/spyCk2CyFMQJPLE80aljP4qWZ7zyFyr8FQLL/3E6LLD9EsE I3Q31pdK9D8qM7cEaUzEGPkyVvr/vVet7/z4MOgDSy2fuDxODTFccdKzWb9P8xv2vjF+ i2DctTDfsGCTbelev5/q+Ntf9H8Z3miJzgdavAcM0u4g+5R54Bv6PVxunacDiV7uYlop Fx0xDJ+7hlshptVO7byoGUrvCGtYDuRQ2Se5owz+8pvG/QqJc3ArVnSz5KjFo1UNewxK bMrA== 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=l1jwyRrgWZk9ydwmIxs0l3qr3oYAbIS7S0+df2N8X0E=; b=7cCOen6Mq7wLY+B+XzPPKI93lcgKgPcqfBfPYzo6jxnD9+iAbjrf3DSeA1RWBdTBA4 qB3UfW6vdAXsJu6PxajN/6qjUE5kjJYIoE/p63QoljCCs/0wDvyXjh12PK3Bg4gbAzRD Sx5CXZoj2kD2exwEvsxF0vsU3aYVkEKP3M4o8peHd3Ae/6gPwZG1vFEuUPV43faLR3pN KHBxkGPqp0ATFdcmBdB8yPW7NkH4kFNpkCZtEDw0olW+sxo4MmJxFnMwFXw6Fe9qwOKz u6hPVJDuAYMD2c7mamzLzmLix8ON2zYuIHdcfsyNoZOOLI//mCXNttOUkkK3PrkyCI+J T8NA== X-Gm-Message-State: ACgBeo0ly/WhTGLAX3/yIcslb9biRgPpzwtn9Rmry7FHrYUndqjEFiq2 URPZ0viYn7mIpiXFdZ15Xum4o5/MQJik6WYf X-Google-Smtp-Source: AA6agR6PKwToIgAY6mVXEMmbsFDQkzNH+6wQDur6wq88XVALyj7/k27RjoE8GsUR5ldHPWpACOvIYw== X-Received: by 2002:a05:6512:3e18:b0:498:fd18:8e12 with SMTP id i24-20020a0565123e1800b00498fd188e12mr381376lfv.249.1662713506283; Fri, 09 Sep 2022 01:51:46 -0700 (PDT) Received: from wse-c0089.raspi.local (h-98-128-229-160.NA.cust.bahnhof.se. [98.128.229.160]) by smtp.gmail.com with ESMTPSA id q17-20020a05651c055100b00262fae1ffe6sm193956ljp.110.2022.09.09.01.51.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Sep 2022 01:51:45 -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 , Mattias Forsblad Subject: [PATCH net-next v8 5/6] net: dsa: mv88e6xxx: rmon: Use RMU for reading RMON data Date: Fri, 9 Sep 2022 10:51:37 +0200 Message-Id: <20220909085138.3539952-6-mattias.forsblad@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220909085138.3539952-1-mattias.forsblad@gmail.com> References: <20220909085138.3539952-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 Remote Management Unit for efficiently accessing the RMON data. Signed-off-by: Mattias Forsblad --- drivers/net/dsa/mv88e6xxx/chip.c | 36 ++++++++++++++---- drivers/net/dsa/mv88e6xxx/chip.h | 4 ++ drivers/net/dsa/mv88e6xxx/rmu.c | 63 ++++++++++++++++++++++++++++++++ drivers/net/dsa/mv88e6xxx/smi.c | 3 ++ 4 files changed, 98 insertions(+), 8 deletions(-) diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c index bbdf229c9e71..bd16afa2e1a5 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.c +++ b/drivers/net/dsa/mv88e6xxx/chip.c @@ -1234,16 +1234,30 @@ static int mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port, u16 bank1_select, u16 histogram) { 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]; if (stat->type & types) { - mv88e6xxx_reg_lock(chip); - data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port, - bank1_select, - histogram); - mv88e6xxx_reg_unlock(chip); + if (mv88e6xxx_rmu_available(chip) && + !(stat->type & STATS_TYPE_PORT)) { + if (stat->type & STATS_TYPE_BANK1) + offset = 32; + + data[j] = chip->ports[port].rmu_raw_stats[stat->reg + offset]; + if (stat->size == 8) { + high = chip->ports[port].rmu_raw_stats[stat->reg + offset + + 1]; + data[j] += (high << 32); + } + } else { + mv88e6xxx_reg_lock(chip); + data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port, + bank1_select, histogram); + mv88e6xxx_reg_unlock(chip); + } j++; } @@ -1312,10 +1326,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); @@ -1327,7 +1340,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 566d18cf5170..5459037067e6 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.h +++ b/drivers/net/dsa/mv88e6xxx/chip.h @@ -266,6 +266,7 @@ struct mv88e6xxx_vlan { struct mv88e6xxx_port { struct mv88e6xxx_chip *chip; int port; + u64 rmu_raw_stats[64]; struct mv88e6xxx_vlan bridge_pvid; u64 serdes_stats[2]; u64 atu_member_violation; @@ -431,6 +432,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 { @@ -807,6 +809,8 @@ int mv88e6xxx_wait_mask(struct mv88e6xxx_chip *chip, int addr, int reg, 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) { diff --git a/drivers/net/dsa/mv88e6xxx/rmu.c b/drivers/net/dsa/mv88e6xxx/rmu.c index 20a91629e72b..2f10844dc61e 100644 --- a/drivers/net/dsa/mv88e6xxx/rmu.c +++ b/drivers/net/dsa/mv88e6xxx/rmu.c @@ -138,6 +138,62 @@ static int mv88e6xxx_rmu_get_id(struct mv88e6xxx_chip *chip, int port) return 0; } +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 dump_mib_resp resp; + struct mv88e6xxx_port *p; + u8 resp_port; + int resp_len; + u16 format; + u16 code; + int ret; + int i; + + /* 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, port, 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 */ + format = get_unaligned_be16(&resp.rmu_header.format); + code = get_unaligned_be16(&resp.rmu_header.code); + + if (format != MV88E6XXX_RMU_RESP_FORMAT_1 && + format != MV88E6XXX_RMU_RESP_FORMAT_2 && + code != MV88E6XXX_RMU_RESP_CODE_DUMP_MIB) { + net_dbg_ratelimited("RMU: received unknown format 0x%04x code 0x%04x", + format, code); + 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; + } + + /* Copy array for further processing according to chip type */ + for (i = 0; i < resp_len - offsetof(struct dump_mib_resp, mib); i++) + p->rmu_raw_stats[i] = get_unaligned_be32(&resp.mib[i]); + + /* Update MIB for port */ + if (chip->info->ops->stats_get_stats) + chip->info->ops->stats_get_stats(chip, port, data); +} + static void mv88e6xxx_disable_rmu(struct mv88e6xxx_chip *chip) { chip->smi_ops = chip->rmu.smi_ops; @@ -263,6 +319,13 @@ 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; + + /* Change rmu ops with our own pointer */ + chip->rmu.rmu_ops = (struct mv88e6xxx_bus_ops *)chip->rmu.smi_ops; + chip->rmu.rmu_ops->get_rmon = mv88e6xxx_rmu_stats_get; + if (chip->info->ops->rmu_disable) return chip->info->ops->rmu_disable(chip); 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 Fri Sep 9 08:51:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mattias Forsblad X-Patchwork-Id: 12971257 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 A6853ECAAA1 for ; Fri, 9 Sep 2022 08:52:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231726AbiIIIwG (ORCPT ); Fri, 9 Sep 2022 04:52:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231608AbiIIIvv (ORCPT ); Fri, 9 Sep 2022 04:51:51 -0400 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1240612D1B8 for ; Fri, 9 Sep 2022 01:51:49 -0700 (PDT) Received: by mail-lf1-x133.google.com with SMTP id x14so1533327lfu.10 for ; Fri, 09 Sep 2022 01:51:48 -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=O651eX+vdQDwumo6UV5G0Dw+0xJjVRxHZkQh9754BII=; b=drfHfC8G6tTWLPM5+sunYSbrtA6Oze+KZfihhdAQUQ7gMfhcJ1pZHfZ+TQrAY3gAtz 9QEQ1zvtNzK+TOPe1Py867LqVk/Kvhx94vuxS14LcEB8rG2jZKC1HQ6Lb99WOazY2/oV Pmlsh6k0SK9aAoOtKMG0euYUyYAObXt2coMc0sXO+61GgZuGd3NxKqGa6JzkhPsTE5vO P8mMwPGOyVtV9rBBZWKKtRzMsJQqkTIeC5w4qFwR1AWBlwmb3LHwDLYYb838AiYR5Sqb ky84npq7RareDkEw1BiTHt6FKiIAAsh9zHMFPkgfoRc6FCfI4pDc+QM8/AHiTdeFKmNo e66A== 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=O651eX+vdQDwumo6UV5G0Dw+0xJjVRxHZkQh9754BII=; b=2Qu8QZYfiKDSwNglwd0lIAId53gjG/UK8RLbiYT0vzd1iD0F4srqfoUAhctHZgDowo /seny3s9pwDPKtB5J1kk88hBVPhzLy/P6CHcVbUYx9CvpCa+O26xOElULamXwm3vPMyQ jLfI6MUC42fkjjcWLTvGFBvomPhOoBZj+JFLibFYbZkUkgTCKgsz2rCbfVlMtBqGusj6 dyGv0ZMLn99fjHThIzy/pVSvRaDl6MUVEyVOm4zGvHs5x46BeNqg6zzeRsTotsaudzdx E+zZbrfRnrBkkwguDn3L0no+BUSh9EW3O2AsoZISE9hjwc9KkL679GgWq4g2YaJWiuTT aUpw== X-Gm-Message-State: ACgBeo06F9IGj7T/zR6q4dysjG1srRjH+wz20wIfhIjHbjNInmLt1chg 0/ENJt4l4gLuC9VuMbx4AMk/tDfbKpgju+aS X-Google-Smtp-Source: AA6agR6B/DKFMRWO8GXTnx9ePceo3mnCR+d4LAZ9ZMxGXUDH848ETLbUi1P14Zqzcz001Blo6z8tOw== X-Received: by 2002:a05:6512:3b09:b0:48b:394e:6b3b with SMTP id f9-20020a0565123b0900b0048b394e6b3bmr3783551lfv.567.1662713507126; Fri, 09 Sep 2022 01:51:47 -0700 (PDT) Received: from wse-c0089.raspi.local (h-98-128-229-160.NA.cust.bahnhof.se. [98.128.229.160]) by smtp.gmail.com with ESMTPSA id q17-20020a05651c055100b00262fae1ffe6sm193956ljp.110.2022.09.09.01.51.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Sep 2022 01:51:46 -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 , Mattias Forsblad Subject: [PATCH net-next v8 6/6] net: dsa: qca8k: Use new convenience functions Date: Fri, 9 Sep 2022 10:51:38 +0200 Message-Id: <20220909085138.3539952-7-mattias.forsblad@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220909085138.3539952-1-mattias.forsblad@gmail.com> References: <20220909085138.3539952-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. Signed-off-by: Mattias Forsblad --- drivers/net/dsa/qca/qca8k-8xxx.c | 61 +++++++++----------------------- 1 file changed, 17 insertions(+), 44 deletions(-) diff --git a/drivers/net/dsa/qca/qca8k-8xxx.c b/drivers/net/dsa/qca/qca8k-8xxx.c index c181346388a4..4e9bc103c0a5 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,12 @@ 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 +276,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 +297,12 @@ 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 +433,21 @@ 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 +469,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 +530,12 @@ 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 +554,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 +562,13 @@ 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 +587,12 @@ 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); + ret = dsa_switch_inband_tx(ds, clear_skb, &mgmt_eth_data->rw_done, QCA8K_ETHERNET_TIMEOUT); mutex_unlock(&mgmt_eth_data->mutex); @@ -1528,7 +1504,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 +1519,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 +1536,7 @@ 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);