From patchwork Sat Sep 19 14:43:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 260554 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 444EFC43466 for ; Sat, 19 Sep 2020 14:44:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1978B2220C for ; Sat, 19 Sep 2020 14:44:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726541AbgISOoC (ORCPT ); Sat, 19 Sep 2020 10:44:02 -0400 Received: from vps0.lunn.ch ([185.16.172.187]:45202 "EHLO vps0.lunn.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726312AbgISOn6 (ORCPT ); Sat, 19 Sep 2020 10:43:58 -0400 Received: from andrew by vps0.lunn.ch with local (Exim 4.94) (envelope-from ) id 1kJe5h-00FNaS-4h; Sat, 19 Sep 2020 16:43:53 +0200 From: Andrew Lunn To: netdev Cc: Florian Fainelli , Jakub Kicinski , Jiri Pirko , Vladimir Oltean , Chris Healy , Andrew Lunn Subject: [PATCH net-next RFC v1 2/4] net: dsa: Add devlink port regions support to DSA Date: Sat, 19 Sep 2020 16:43:30 +0200 Message-Id: <20200919144332.3665538-3-andrew@lunn.ch> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200919144332.3665538-1-andrew@lunn.ch> References: <20200919144332.3665538-1-andrew@lunn.ch> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Allow DSA drivers to make use of devlink port regions, via simple wrappers. Signed-off-by: Andrew Lunn --- include/net/dsa.h | 5 +++++ net/core/devlink.c | 3 +-- net/dsa/dsa.c | 14 ++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/include/net/dsa.h b/include/net/dsa.h index d16057c5987a..01da896b2998 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -665,6 +665,11 @@ struct devlink_region * dsa_devlink_region_create(struct dsa_switch *ds, const struct devlink_region_ops *ops, u32 region_max_snapshots, u64 region_size); +struct devlink_region * +dsa_devlink_port_region_create(struct dsa_switch *ds, + int port, + const struct devlink_port_region_ops *ops, + u32 region_max_snapshots, u64 region_size); void dsa_devlink_region_destroy(struct devlink_region *region); struct dsa_port *dsa_port_from_netdev(struct net_device *netdev); diff --git a/net/core/devlink.c b/net/core/devlink.c index 66469cdcdc1e..4701ec17f3da 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -4292,7 +4292,6 @@ static int devlink_nl_cmd_region_get_port_dumpit(struct sk_buff *msg, } out: - mutex_unlock(&devlink_mutex); return err; } @@ -4330,7 +4329,7 @@ static int devlink_nl_cmd_region_get_devlink_dumpit(struct sk_buff *msg, } out: - mutex_unlock(&devlink_mutex); + mutex_unlock(&devlink->lock); return err; } diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c index 5c18c0214aac..97fcabdeccec 100644 --- a/net/dsa/dsa.c +++ b/net/dsa/dsa.c @@ -414,6 +414,20 @@ dsa_devlink_region_create(struct dsa_switch *ds, } EXPORT_SYMBOL_GPL(dsa_devlink_region_create); +struct devlink_region * +dsa_devlink_port_region_create(struct dsa_switch *ds, + int port, + const struct devlink_port_region_ops *ops, + u32 region_max_snapshots, u64 region_size) +{ + struct dsa_port *dp = dsa_to_port(ds, port); + + return devlink_port_region_create(&dp->devlink_port, ops, + region_max_snapshots, + region_size); +} +EXPORT_SYMBOL_GPL(dsa_devlink_port_region_create); + void dsa_devlink_region_destroy(struct devlink_region *region) { devlink_region_destroy(region); From patchwork Sat Sep 19 14:43:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 260553 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E444BC43464 for ; Sat, 19 Sep 2020 14:44:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AC1642220C for ; Sat, 19 Sep 2020 14:44:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726510AbgISOn6 (ORCPT ); Sat, 19 Sep 2020 10:43:58 -0400 Received: from vps0.lunn.ch ([185.16.172.187]:45192 "EHLO vps0.lunn.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726408AbgISOn6 (ORCPT ); Sat, 19 Sep 2020 10:43:58 -0400 Received: from andrew by vps0.lunn.ch with local (Exim 4.94) (envelope-from ) id 1kJe5h-00FNaV-64; Sat, 19 Sep 2020 16:43:53 +0200 From: Andrew Lunn To: netdev Cc: Florian Fainelli , Jakub Kicinski , Jiri Pirko , Vladimir Oltean , Chris Healy , Andrew Lunn Subject: [PATCH net-next RFC v1 3/4] net: dsa: Add helper for converting devlink port to ds and port Date: Sat, 19 Sep 2020 16:43:31 +0200 Message-Id: <20200919144332.3665538-4-andrew@lunn.ch> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200919144332.3665538-1-andrew@lunn.ch> References: <20200919144332.3665538-1-andrew@lunn.ch> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Hide away from DSA drivers how devlink works. Signed-off-by: Andrew Lunn --- include/net/dsa.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/net/dsa.h b/include/net/dsa.h index 01da896b2998..a24d5158ee0c 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -685,6 +685,20 @@ static inline struct dsa_switch *dsa_devlink_to_ds(struct devlink *dl) return dl_priv->ds; } +static inline +struct dsa_switch *dsa_devlink_port_to_ds(struct devlink_port *port) +{ + struct devlink *dl = port->devlink; + struct dsa_devlink_priv *dl_priv = devlink_priv(dl); + + return dl_priv->ds; +} + +static inline int dsa_devlink_port_to_port(struct devlink_port *port) +{ + return port->index; +} + struct dsa_switch_driver { struct list_head list; const struct dsa_switch_ops *ops; From patchwork Sat Sep 19 14:43:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 260555 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 51838C43464 for ; Sat, 19 Sep 2020 14:43:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 166FD2098B for ; Sat, 19 Sep 2020 14:43:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726469AbgISOn5 (ORCPT ); Sat, 19 Sep 2020 10:43:57 -0400 Received: from vps0.lunn.ch ([185.16.172.187]:45184 "EHLO vps0.lunn.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726312AbgISOn5 (ORCPT ); Sat, 19 Sep 2020 10:43:57 -0400 Received: from andrew by vps0.lunn.ch with local (Exim 4.94) (envelope-from ) id 1kJe5h-00FNaY-7N; Sat, 19 Sep 2020 16:43:53 +0200 From: Andrew Lunn To: netdev Cc: Florian Fainelli , Jakub Kicinski , Jiri Pirko , Vladimir Oltean , Chris Healy , Andrew Lunn Subject: [PATCH net-next RFC v1 4/4] net: dsa: mv88e6xxx: Add per port devlink regions Date: Sat, 19 Sep 2020 16:43:32 +0200 Message-Id: <20200919144332.3665538-5-andrew@lunn.ch> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200919144332.3665538-1-andrew@lunn.ch> References: <20200919144332.3665538-1-andrew@lunn.ch> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Add a devlink region to return the per port registers. Signed-off-by: Andrew Lunn --- drivers/net/dsa/mv88e6xxx/chip.c | 8 ++++ drivers/net/dsa/mv88e6xxx/devlink.c | 61 +++++++++++++++++++++++++++++ drivers/net/dsa/mv88e6xxx/devlink.h | 6 ++- 3 files changed, 74 insertions(+), 1 deletion(-) diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c index 9417412e5fce..3d2d813f7a79 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.c +++ b/drivers/net/dsa/mv88e6xxx/chip.c @@ -2741,10 +2741,16 @@ static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port, struct mv88e6xxx_chip *chip = ds->priv; int err; + err = mv88e6xxx_setup_devlink_regions_port(ds, chip, port); + if (err) + return err; + mv88e6xxx_reg_lock(chip); err = mv88e6xxx_serdes_power(chip, port, true); mv88e6xxx_reg_unlock(chip); + if (err) + mv88e6xxx_teardown_devlink_regions_port(chip, port); return err; } @@ -2752,6 +2758,8 @@ static void mv88e6xxx_port_disable(struct dsa_switch *ds, int port) { struct mv88e6xxx_chip *chip = ds->priv; + mv88e6xxx_teardown_devlink_regions_port(chip, port); + mv88e6xxx_reg_lock(chip); if (mv88e6xxx_serdes_power(chip, port, false)) dev_err(chip->dev, "failed to power off SERDES\n"); diff --git a/drivers/net/dsa/mv88e6xxx/devlink.c b/drivers/net/dsa/mv88e6xxx/devlink.c index 81e1560db206..dc8a244aa154 100644 --- a/drivers/net/dsa/mv88e6xxx/devlink.c +++ b/drivers/net/dsa/mv88e6xxx/devlink.c @@ -415,6 +415,36 @@ static int mv88e6xxx_region_atu_snapshot(struct devlink *dl, return err; } +static int mv88e6xxx_region_port_snapshot(struct devlink_port *devlink_port, + const struct devlink_port_region_ops *ops, + struct netlink_ext_ack *extack, + u8 **data) +{ + struct dsa_switch *ds = dsa_devlink_port_to_ds(devlink_port); + int port = dsa_devlink_port_to_port(devlink_port); + struct mv88e6xxx_chip *chip = ds->priv; + u16 *registers; + int i, err; + + registers = kmalloc_array(32, sizeof(u16), GFP_KERNEL); + if (!registers) + return -ENOMEM; + + mv88e6xxx_reg_lock(chip); + for (i = 0; i < 32; i++) { + err = mv88e6xxx_port_read(chip, port, i, ®isters[i]); + if (err) { + kfree(registers); + goto out; + } + } + *data = (u8 *)registers; +out: + mv88e6xxx_reg_unlock(chip); + + return err; +} + static struct mv88e6xxx_region_priv mv88e6xxx_region_global1_priv = { .id = MV88E6XXX_REGION_GLOBAL1, }; @@ -443,6 +473,12 @@ static struct devlink_region_ops mv88e6xxx_region_atu_ops = { .destructor = kfree, }; +static const struct devlink_port_region_ops mv88e6xxx_region_port_ops = { + .name = "port", + .snapshot = mv88e6xxx_region_port_snapshot, + .destructor = kfree, +}; + struct mv88e6xxx_region { struct devlink_region_ops *ops; u64 size; @@ -478,6 +514,31 @@ void mv88e6xxx_teardown_devlink_regions(struct dsa_switch *ds) mv88e6xxx_teardown_devlink_regions_global(chip); } +int mv88e6xxx_setup_devlink_regions_port(struct dsa_switch *ds, + struct mv88e6xxx_chip *chip, + int port) +{ + struct devlink_region *region; + + region = dsa_devlink_port_region_create(ds, + port, + &mv88e6xxx_region_port_ops, 1, + 32 * sizeof(u16)); + if (IS_ERR(region)) + return PTR_ERR(region); + + chip->ports[port].region = region; + + return 0; +} + +void mv88e6xxx_teardown_devlink_regions_port(struct mv88e6xxx_chip *chip, + int port) +{ + if (chip->ports[port].region) + dsa_devlink_region_destroy(chip->ports[port].region); +} + static int mv88e6xxx_setup_devlink_regions_global(struct dsa_switch *ds, struct mv88e6xxx_chip *chip) { diff --git a/drivers/net/dsa/mv88e6xxx/devlink.h b/drivers/net/dsa/mv88e6xxx/devlink.h index 3d72db3dcf95..9302f0ee550d 100644 --- a/drivers/net/dsa/mv88e6xxx/devlink.h +++ b/drivers/net/dsa/mv88e6xxx/devlink.h @@ -14,7 +14,11 @@ int mv88e6xxx_devlink_param_set(struct dsa_switch *ds, u32 id, struct devlink_param_gset_ctx *ctx); int mv88e6xxx_setup_devlink_regions(struct dsa_switch *ds); void mv88e6xxx_teardown_devlink_regions(struct dsa_switch *ds); - +int mv88e6xxx_setup_devlink_regions_port(struct dsa_switch *ds, + struct mv88e6xxx_chip *chip, + int port); +void mv88e6xxx_teardown_devlink_regions_port(struct mv88e6xxx_chip *chip, + int port); int mv88e6xxx_devlink_info_get(struct dsa_switch *ds, struct devlink_info_req *req, struct netlink_ext_ack *extack);