From patchwork Tue Sep 8 00:51:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 1359327 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=lunn.ch Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BlmpF51Q8z9sTM for ; Tue, 8 Sep 2020 10:52:37 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728250AbgIHAwZ (ORCPT ); Mon, 7 Sep 2020 20:52:25 -0400 Received: from vps0.lunn.ch ([185.16.172.187]:48786 "EHLO vps0.lunn.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728229AbgIHAwX (ORCPT ); Mon, 7 Sep 2020 20:52:23 -0400 Received: from andrew by vps0.lunn.ch with local (Exim 4.94) (envelope-from ) id 1kFRro-00Di6B-90; Tue, 08 Sep 2020 02:52:12 +0200 From: Andrew Lunn To: David Miller Cc: netdev , Chris Healy , Andrew Lunn , Florian Fainelli Subject: [PATCH net-next v2 1/7] net: dsa: Add helper to convert from devlink to ds Date: Tue, 8 Sep 2020 02:51:49 +0200 Message-Id: <20200908005155.3267736-2-andrew@lunn.ch> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908005155.3267736-1-andrew@lunn.ch> References: <20200908005155.3267736-1-andrew@lunn.ch> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Given a devlink instance, return the dsa switch it is associated to. Reviewed-by: Florian Fainelli Signed-off-by: Andrew Lunn --- include/net/dsa.h | 2 ++ net/dsa/dsa.c | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/include/net/dsa.h b/include/net/dsa.h index 75c8fac82017..63ff6f717307 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -629,6 +629,8 @@ struct dsa_switch_ops { int (*port_max_mtu)(struct dsa_switch *ds, int port); }; +struct dsa_switch *dsa_devlink_to_ds(struct devlink *dl); + #define DSA_DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes) \ DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes, \ dsa_devlink_param_get, dsa_devlink_param_set, NULL) diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c index 1ce9ba8cf545..86351da4e202 100644 --- a/net/dsa/dsa.c +++ b/net/dsa/dsa.c @@ -327,14 +327,18 @@ int call_dsa_notifiers(unsigned long val, struct net_device *dev, } EXPORT_SYMBOL_GPL(call_dsa_notifiers); +struct dsa_switch *dsa_devlink_to_ds(struct devlink *dl) +{ + struct dsa_devlink_priv *dl_priv = devlink_priv(dl); + + return dl_priv->ds; +} +EXPORT_SYMBOL_GPL(dsa_devlink_to_ds); + int dsa_devlink_param_get(struct devlink *dl, u32 id, struct devlink_param_gset_ctx *ctx) { - struct dsa_devlink_priv *dl_priv; - struct dsa_switch *ds; - - dl_priv = devlink_priv(dl); - ds = dl_priv->ds; + struct dsa_switch *ds = dsa_devlink_to_ds(dl); if (!ds->ops->devlink_param_get) return -EOPNOTSUPP; @@ -346,11 +350,7 @@ EXPORT_SYMBOL_GPL(dsa_devlink_param_get); int dsa_devlink_param_set(struct devlink *dl, u32 id, struct devlink_param_gset_ctx *ctx) { - struct dsa_devlink_priv *dl_priv; - struct dsa_switch *ds; - - dl_priv = devlink_priv(dl); - ds = dl_priv->ds; + struct dsa_switch *ds = dsa_devlink_to_ds(dl); if (!ds->ops->devlink_param_set) return -EOPNOTSUPP;