From patchwork Fri Aug 4 15:26:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory CLEMENT X-Patchwork-Id: 797863 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3xP9l30FF5z9sxR for ; Sat, 5 Aug 2017 01:26:55 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752237AbdHDP0x (ORCPT ); Fri, 4 Aug 2017 11:26:53 -0400 Received: from mail.free-electrons.com ([62.4.15.54]:36130 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752160AbdHDP0w (ORCPT ); Fri, 4 Aug 2017 11:26:52 -0400 Received: by mail.free-electrons.com (Postfix, from userid 110) id B4D1021DB9; Fri, 4 Aug 2017 17:26:49 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.free-electrons.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.4.0 Received: from localhost (83.146.29.93.rev.sfr.net [93.29.146.83]) by mail.free-electrons.com (Postfix) with ESMTPSA id 80F5D21D9F; Fri, 4 Aug 2017 17:26:49 +0200 (CEST) From: Gregory CLEMENT To: Rob Herring Cc: Thomas Petazzoni , netdev , "devicetree\@vger.kernel.org" , Frank Rowand , Marcin Wojtas Subject: Re: [PATCH 1/2] net: mvneta: remove bogus use of References: <20170720142711.12847-1-robh@kernel.org> <8760en5es2.fsf@free-electrons.com> Date: Fri, 04 Aug 2017 17:26:50 +0200 In-Reply-To: (Rob Herring's message of "Thu, 20 Jul 2017 11:02:22 -0500") Message-ID: <87tw1n73r9.fsf@free-electrons.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Hi Rob, On jeu., juil. 20 2017, Rob Herring wrote: > On Thu, Jul 20, 2017 at 10:06 AM, Gregory CLEMENT > wrote: >> Hi Rob, >> >> On jeu., juil. 20 2017, Rob Herring wrote: >> >> (Adding Marcin in CC who wrote this part of code) >> >>> Nothing sets ever sets data, so it is always NULL. Remove it as this is >>> the only user of data ptr in the whole kernel, and it is going to be >>> removed from struct device_node. >> >> Actually the use of device_node.data ptr is not bogus and it is set in >> mvneta_bm_probe: >> http://elixir.free-electrons.com/linux/latest/source/drivers/net/ethernet/marvell/mvneta_bm.c#L433 > > Indeed. Looks like some complicated kconfig logic, so I'd not been > able to trigger a build failure nor did 0-day (so far). > >> Your patch will break the BM support on this driver. So if you need to >> remove this data ptr, then you have to offer an alternative for it. > > How about something like this (WS damaged) patch: I finally took time to test your patch. There was some missing part which prevented it to be build, like including linux/of_platform.h, or providing tub function when CONFIG_MVNETA_BM was not enable. Also the fact that you still call mvneta_bm_port_init() even if bm_priv was NULL was not really nice. So I proposed the following patch, that I tested on a clearfog with and without CONFIG_MVNETA_BM enabled. From 03c4028bc1f52d3d214e8506d9f0f66660d3985d Mon Sep 17 00:00:00 2001 From: Gregory CLEMENT Date: Fri, 4 Aug 2017 17:18:38 +0200 Subject: [PATCH] net: mvneta: remove data pointer usage from device_node structure In order to be able to remove the data pointer from the device_node structure. We have to modify the way the BM resources are shared between the mvneta port. Signed-off-by: Gregory CLEMENT --- drivers/net/ethernet/marvell/mvneta.c | 18 ++++++++++++------ drivers/net/ethernet/marvell/mvneta_bm.c | 13 +++++++++++++ drivers/net/ethernet/marvell/mvneta_bm.h | 8 ++++++-- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/drivers/net/ethernet/marvell/mvneta.c b/drivers/net/ethernet/marvell/mvneta.c index 63b6147753fe..fd84447582f7 100644 --- a/drivers/net/ethernet/marvell/mvneta.c +++ b/drivers/net/ethernet/marvell/mvneta.c @@ -4295,12 +4295,16 @@ static int mvneta_probe(struct platform_device *pdev) /* Obtain access to BM resources if enabled and already initialized */ bm_node = of_parse_phandle(dn, "buffer-manager", 0); - if (bm_node && bm_node->data) { - pp->bm_priv = bm_node->data; - err = mvneta_bm_port_init(pdev, pp); - if (err < 0) { - dev_info(&pdev->dev, "use SW buffer management\n"); - pp->bm_priv = NULL; + if (bm_node) { + pp->bm_priv = mvneta_bm_get(bm_node); + if (pp->bm_priv) { + err = mvneta_bm_port_init(pdev, pp); + if (err < 0) { + dev_info(&pdev->dev, + "use SW buffer management\n"); + mvneta_bm_put(pp->bm_priv); + pp->bm_priv = NULL; + } } } of_node_put(bm_node); @@ -4369,6 +4373,7 @@ static int mvneta_probe(struct platform_device *pdev) mvneta_bm_pool_destroy(pp->bm_priv, pp->pool_long, 1 << pp->id); mvneta_bm_pool_destroy(pp->bm_priv, pp->pool_short, 1 << pp->id); + mvneta_bm_put(pp->bm_priv); } err_free_stats: free_percpu(pp->stats); @@ -4410,6 +4415,7 @@ static int mvneta_remove(struct platform_device *pdev) mvneta_bm_pool_destroy(pp->bm_priv, pp->pool_long, 1 << pp->id); mvneta_bm_pool_destroy(pp->bm_priv, pp->pool_short, 1 << pp->id); + mvneta_bm_put(pp->bm_priv); } return 0; diff --git a/drivers/net/ethernet/marvell/mvneta_bm.c b/drivers/net/ethernet/marvell/mvneta_bm.c index 466939f8f0cf..01e3152e76c8 100644 --- a/drivers/net/ethernet/marvell/mvneta_bm.c +++ b/drivers/net/ethernet/marvell/mvneta_bm.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -392,6 +393,18 @@ static void mvneta_bm_put_sram(struct mvneta_bm *priv) MVNETA_BM_BPPI_SIZE); } +struct mvneta_bm *mvneta_bm_get(struct device_node *node) +{ + struct platform_device *pdev = of_find_device_by_node(node); + + return pdev ? platform_get_drvdata(pdev) : NULL; +} + +void mvneta_bm_put(struct mvneta_bm *priv) +{ + platform_device_put(priv->pdev); +} + static int mvneta_bm_probe(struct platform_device *pdev) { struct device_node *dn = pdev->dev.of_node; diff --git a/drivers/net/ethernet/marvell/mvneta_bm.h b/drivers/net/ethernet/marvell/mvneta_bm.h index a32de432800c..daa9a91d2708 100644 --- a/drivers/net/ethernet/marvell/mvneta_bm.h +++ b/drivers/net/ethernet/marvell/mvneta_bm.h @@ -134,6 +134,9 @@ void *mvneta_frag_alloc(unsigned int frag_size); void mvneta_frag_free(unsigned int frag_size, void *data); #if IS_ENABLED(CONFIG_MVNETA_BM) +struct mvneta_bm *mvneta_bm_get(struct device_node *node); +void mvneta_bm_put(struct mvneta_bm *priv); + void mvneta_bm_pool_destroy(struct mvneta_bm *priv, struct mvneta_bm_pool *bm_pool, u8 port_map); void mvneta_bm_bufs_free(struct mvneta_bm *priv, struct mvneta_bm_pool *bm_pool, @@ -176,7 +179,8 @@ static inline void mvneta_bm_pool_put_bp(struct mvneta_bm *priv, dma_addr_t buf_phys_addr) {} static inline u32 mvneta_bm_pool_get_bp(struct mvneta_bm *priv, - struct mvneta_bm_pool *bm_pool) -{ return 0; } + struct mvneta_bm_pool *bm_pool) { return 0; } +struct mvneta_bm *mvneta_bm_get(struct device_node *node) {return NULL; } +void mvneta_bm_put(struct mvneta_bm *priv) {} #endif /* CONFIG_MVNETA_BM */ #endif