From patchwork Mon Dec 18 09:17:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcin Wojtas X-Patchwork-Id: 849920 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=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=semihalf-com.20150623.gappssmtp.com header.i=@semihalf-com.20150623.gappssmtp.com header.b="gQ+/uSvb"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3z0bCk2zfCz9rxm for ; Mon, 18 Dec 2017 20:22:26 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933382AbdLRJWW (ORCPT ); Mon, 18 Dec 2017 04:22:22 -0500 Received: from mail-lf0-f66.google.com ([209.85.215.66]:46148 "EHLO mail-lf0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933291AbdLRJSO (ORCPT ); Mon, 18 Dec 2017 04:18:14 -0500 Received: by mail-lf0-f66.google.com with SMTP id r143so16911075lfe.13 for ; Mon, 18 Dec 2017 01:18:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=7bX/y12XtUjWPTpHiSGzSv/zRkTHt7m1mJUxszvEoPc=; b=gQ+/uSvbCMXEU5fszAR6771EcyxCuBmwJu462CQZbx4zD9EBwMWxA2aM5M8QsPvJRW vhKfgh+g3MnEDAlSTV55zXpqX0WvK7Yv6pazFuGUAGFzWxwIyBzLBnqD6qqAjCDNiebY p5BNZ6CON2yFB3Odvpq29AhGrkKEWChXDeJ6wejrmc63RE5UuBvEhcbvc5GNwpORA/PK MQTP8lPo5LW538WMC8FqEkN2UIOjCulLSVBqtuyV5iLFdUNlQ8C/XZ9x0kvbb7O8wluC 3aWdNPfrclN1bFBntj61wn4BnOJSZvjK0Bvwps7TGaudWtOTjc277dFScoGr2jdcv6at eT+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=7bX/y12XtUjWPTpHiSGzSv/zRkTHt7m1mJUxszvEoPc=; b=GBab81Lzmb7BHUYDZVKA8+Idxnfmiv/PrsldeVUtuaW6IRiZlbgKJJHiscnUb6Ox+P JWtp87oCTxR3sSeFsf/ZjqON9Mydi9NH++MWd0LLBFRzM2lInQwJPbFMWVqRfCVe6mGG zKbseI5yZxxG7sUy1L05rkSGvhI/0NrAr+VCEno3HFpKXQVdK86zkqgFn0uT47oleVtT dYH3PoWAw8r52MxoE8ULrY1GLicQy+XnoH1kru8uzjpajkJ2QegGCcuxtlW8Ptvrl1tR AiQXQppLb6KJz67bDJl/GDx8ggVxc8mG+7I4pHSCer0pKdIthW0m2RBvioiPH+vAQQZI Jr2w== X-Gm-Message-State: AKGB3mJ+qpn09MxPdGrOxyKaSNYRJat691IkSYjVJtcS1+gsa5uiYMfm nOBnqmuYTcS2qGVvF9LiJP2oRg== X-Google-Smtp-Source: ACJfBou8yo/mQHN4Cvo0iwS18QnoFaM53hphFtnZnrZDepyeURYCbOLnfARNWgKhbuaupzT81jgpzA== X-Received: by 10.25.84.21 with SMTP id i21mr3185729lfb.108.1513588693291; Mon, 18 Dec 2017 01:18:13 -0800 (PST) Received: from gilgamesh.semihalf.com (31-172-191-173.noc.fibertech.net.pl. [31.172.191.173]) by smtp.gmail.com with ESMTPSA id r16sm2407186ljd.18.2017.12.18.01.18.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 18 Dec 2017 01:18:12 -0800 (PST) From: Marcin Wojtas To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org Cc: davem@davemloft.net, linux@arm.linux.org.uk, rafael.j.wysocki@intel.com, andrew@lunn.ch, f.fainelli@gmail.com, antoine.tenart@free-electrons.com, thomas.petazzoni@free-electrons.com, gregory.clement@free-electrons.com, ezequiel.garcia@free-electrons.com, nadavh@marvell.com, neta@marvell.com, ard.biesheuvel@linaro.org, mw@semihalf.com, jaz@semihalf.com, tn@semihalf.com Subject: [net-next: PATCH 1/8] device property: Introduce fwnode_get_mac_address() Date: Mon, 18 Dec 2017 10:17:57 +0100 Message-Id: <1513588684-15647-2-git-send-email-mw@semihalf.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513588684-15647-1-git-send-email-mw@semihalf.com> References: <1513588684-15647-1-git-send-email-mw@semihalf.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Until now there were two almost identical functions for obtaining MAC address - of_get_mac_address() and, more generic, device_get_mac_address(). However it is not uncommon, that the network interface is represented as a child of the actual controller, hence it is not associated directly to any struct device, required by the latter routine. This commit allows for getting the MAC address for children nodes in the ACPI world by introducing a new function - fwnode_get_mac_address(). This commit also changes device_get_mac_address() routine to be its wrapper, in order to prevent unnecessary duplication. Signed-off-by: Marcin Wojtas --- drivers/base/property.c | 28 ++++++++++++++------ include/linux/property.h | 2 ++ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/drivers/base/property.c b/drivers/base/property.c index 851b1b6..f261d1a 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -1153,11 +1153,11 @@ int device_get_phy_mode(struct device *dev) } EXPORT_SYMBOL_GPL(device_get_phy_mode); -static void *device_get_mac_addr(struct device *dev, +static void *fwnode_get_mac_addr(struct fwnode_handle *fwnode, const char *name, char *addr, int alen) { - int ret = device_property_read_u8_array(dev, name, addr, alen); + int ret = fwnode_property_read_u8_array(fwnode, name, addr, alen); if (ret == 0 && alen == ETH_ALEN && is_valid_ether_addr(addr)) return addr; @@ -1165,8 +1165,8 @@ static void *device_get_mac_addr(struct device *dev, } /** - * device_get_mac_address - Get the MAC for a given device - * @dev: Pointer to the device + * fwnode_get_mac_address - Get the MAC from the firmware node + * @fwnode: Pointer to the firmware node * @addr: Address of buffer to store the MAC in * @alen: Length of the buffer pointed to by addr, should be ETH_ALEN * @@ -1187,19 +1187,31 @@ static void *device_get_mac_addr(struct device *dev, * In this case, the real MAC is in 'local-mac-address', and 'mac-address' * exists but is all zeros. */ -void *device_get_mac_address(struct device *dev, char *addr, int alen) +void *fwnode_get_mac_address(struct fwnode_handle *fwnode, char *addr, int alen) { char *res; - res = device_get_mac_addr(dev, "mac-address", addr, alen); + res = fwnode_get_mac_addr(fwnode, "mac-address", addr, alen); if (res) return res; - res = device_get_mac_addr(dev, "local-mac-address", addr, alen); + res = fwnode_get_mac_addr(fwnode, "local-mac-address", addr, alen); if (res) return res; - return device_get_mac_addr(dev, "address", addr, alen); + return fwnode_get_mac_addr(fwnode, "address", addr, alen); +} +EXPORT_SYMBOL(fwnode_get_mac_address); + +/** + * device_get_mac_address - Get the MAC for a given device + * @dev: Pointer to the device + * @addr: Address of buffer to store the MAC in + * @alen: Length of the buffer pointed to by addr, should be ETH_ALEN + */ +void *device_get_mac_address(struct device *dev, char *addr, int alen) +{ + return fwnode_get_mac_address(dev_fwnode(dev), addr, alen); } EXPORT_SYMBOL(device_get_mac_address); diff --git a/include/linux/property.h b/include/linux/property.h index f6189a3..35620e0 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -279,6 +279,8 @@ int device_get_phy_mode(struct device *dev); void *device_get_mac_address(struct device *dev, char *addr, int alen); +void *fwnode_get_mac_address(struct fwnode_handle *fwnode, + char *addr, int alen); struct fwnode_handle *fwnode_graph_get_next_endpoint( const struct fwnode_handle *fwnode, struct fwnode_handle *prev); struct fwnode_handle * From patchwork Mon Dec 18 09:17:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcin Wojtas X-Patchwork-Id: 849919 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=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=semihalf-com.20150623.gappssmtp.com header.i=@semihalf-com.20150623.gappssmtp.com header.b="vEGlVfvI"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3z0bBg03pGz9rxm for ; Mon, 18 Dec 2017 20:21:31 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933359AbdLRJVM (ORCPT ); Mon, 18 Dec 2017 04:21:12 -0500 Received: from mail-lf0-f68.google.com ([209.85.215.68]:36522 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933307AbdLRJSQ (ORCPT ); Mon, 18 Dec 2017 04:18:16 -0500 Received: by mail-lf0-f68.google.com with SMTP id f20so16950592lfe.3 for ; Mon, 18 Dec 2017 01:18:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=bNAT0y0tuLP3KP1q1q4PpjvzgVJR2LG8mUxU6Y+V3J8=; b=vEGlVfvIc8Me8213FBUuOYrBfLWE3dhnd655ix3a1o81O5LADBCyQPAe4Hwz10Q3fl 8VeQ49+xTaabpPpqX4Jsltqo4JZ/cBnY99YroO4AxxUrxcaJmBrfQpdjsTRjCITMrSBj WTc4jqfPj426mjHHB0CMeV7PFb9qUYIHNHQBRFDPi5dMctVhx5lXFSjkj5YwS0GFFGXn 4ppxOlT2Y7Z2LTFee2GCd+PaUrB/2TiA+ryhErgEVnEzNZWfmoQYhOoam8uWf1RulG/O YZ5cO2FNjWVwrFXjXAgmba7uIUaaH1U0tp85nXuPIxIqWo7k0c3YDC3lPnRcFZm5Qkqs RLuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=bNAT0y0tuLP3KP1q1q4PpjvzgVJR2LG8mUxU6Y+V3J8=; b=YtNVoL8OOl6EEbf/+GWT5e5DBUqFWQfCE5ZU/d9hUvZlB8FXALdoWwu7xy/GTj+s4Z C3QFfy9uEtQrRbKvdPXiLpCtEN8LpFytLCLyVb9XrqWRmsJmEdRRVoJh+FPU/AJJpegn dSpWsRJGQXpX3nEEW7N3uFzFj1mRsnzQISg1RWUVCN+pbUSqGxrrdj7+tZOSQpPQ4u0o oVgNGNFe5oBXPKhpqcsvhM/k1qMpK3Tw/naQvlLv/NP77T8w+5lto1qCL/M8M8ODxQeQ 80knMs2Hj2n0TPx82NzqrHkUwIazfgAJYxcXKgJrAmOIFZL/Mb0a99JlBt6OAZnLqGxX +6Fw== X-Gm-Message-State: AKGB3mLJf/4O2034RIeYtvw61XRt7X+FsZjyaVuHvON7L0JjesRaNpYu NDcbTAQMI1nAS1uCUVAyZxqE8Q== X-Google-Smtp-Source: ACJfBosqjVKT7GvsY2a44/ODq9lzaSQzVZTbym9qUIp2tlE78a78s68VGRkZP1Z4cl9JIz9jTKQ7RA== X-Received: by 10.46.4.2 with SMTP id 2mr10762096lje.133.1513588695006; Mon, 18 Dec 2017 01:18:15 -0800 (PST) Received: from gilgamesh.semihalf.com (31-172-191-173.noc.fibertech.net.pl. [31.172.191.173]) by smtp.gmail.com with ESMTPSA id r16sm2407186ljd.18.2017.12.18.01.18.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 18 Dec 2017 01:18:14 -0800 (PST) From: Marcin Wojtas To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org Cc: davem@davemloft.net, linux@arm.linux.org.uk, rafael.j.wysocki@intel.com, andrew@lunn.ch, f.fainelli@gmail.com, antoine.tenart@free-electrons.com, thomas.petazzoni@free-electrons.com, gregory.clement@free-electrons.com, ezequiel.garcia@free-electrons.com, nadavh@marvell.com, neta@marvell.com, ard.biesheuvel@linaro.org, mw@semihalf.com, jaz@semihalf.com, tn@semihalf.com Subject: [net-next: PATCH 2/8] device property: Introduce fwnode_get_phy_mode() Date: Mon, 18 Dec 2017 10:17:58 +0100 Message-Id: <1513588684-15647-3-git-send-email-mw@semihalf.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513588684-15647-1-git-send-email-mw@semihalf.com> References: <1513588684-15647-1-git-send-email-mw@semihalf.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Until now there were two almost identical functions for obtaining network PHY mode - of_get_phy_mode() and, more generic, device_get_phy_mode(). However it is not uncommon, that the network interface is represented as a child of the actual controller, hence it is not associated directly to any struct device, required by the latter routine. This commit allows for getting the PHY mode for children nodes in the ACPI world by introducing a new function - fwnode_get_phy_mode(). This commit also changes device_get_phy_mode() routine to be its wrapper, in order to prevent unnecessary duplication. Signed-off-by: Marcin Wojtas --- drivers/base/property.c | 24 ++++++++++++++++---- include/linux/property.h | 1 + 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/drivers/base/property.c b/drivers/base/property.c index f261d1a..7c4a53d 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -1126,21 +1126,21 @@ enum dev_dma_attr device_get_dma_attr(struct device *dev) EXPORT_SYMBOL_GPL(device_get_dma_attr); /** - * device_get_phy_mode - Get phy mode for given device - * @dev: Pointer to the given device + * fwnode_get_phy_mode - Get phy mode for given firmware node + * @fwnode: Pointer to the given node * * The function gets phy interface string from property 'phy-mode' or * 'phy-connection-type', and return its index in phy_modes table, or errno in * error case. */ -int device_get_phy_mode(struct device *dev) +int fwnode_get_phy_mode(struct fwnode_handle *fwnode) { const char *pm; int err, i; - err = device_property_read_string(dev, "phy-mode", &pm); + err = fwnode_property_read_string(fwnode, "phy-mode", &pm); if (err < 0) - err = device_property_read_string(dev, + err = fwnode_property_read_string(fwnode, "phy-connection-type", &pm); if (err < 0) return err; @@ -1151,6 +1151,20 @@ int device_get_phy_mode(struct device *dev) return -ENODEV; } +EXPORT_SYMBOL_GPL(fwnode_get_phy_mode); + +/** + * device_get_phy_mode - Get phy mode for given device + * @dev: Pointer to the given device + * + * The function gets phy interface string from property 'phy-mode' or + * 'phy-connection-type', and return its index in phy_modes table, or errno in + * error case. + */ +int device_get_phy_mode(struct device *dev) +{ + return fwnode_get_phy_mode(dev_fwnode(dev)); +} EXPORT_SYMBOL_GPL(device_get_phy_mode); static void *fwnode_get_mac_addr(struct fwnode_handle *fwnode, diff --git a/include/linux/property.h b/include/linux/property.h index 35620e0..9b13332 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -279,6 +279,7 @@ int device_get_phy_mode(struct device *dev); void *device_get_mac_address(struct device *dev, char *addr, int alen); +int fwnode_get_phy_mode(struct fwnode_handle *fwnode); void *fwnode_get_mac_address(struct fwnode_handle *fwnode, char *addr, int alen); struct fwnode_handle *fwnode_graph_get_next_endpoint( From patchwork Mon Dec 18 09:17:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcin Wojtas X-Patchwork-Id: 849916 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=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=semihalf-com.20150623.gappssmtp.com header.i=@semihalf-com.20150623.gappssmtp.com header.b="dnNIolbB"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3z0b9y1XQpz9rxm for ; Mon, 18 Dec 2017 20:20:54 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933399AbdLRJUh (ORCPT ); Mon, 18 Dec 2017 04:20:37 -0500 Received: from mail-lf0-f66.google.com ([209.85.215.66]:33432 "EHLO mail-lf0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933250AbdLRJSS (ORCPT ); Mon, 18 Dec 2017 04:18:18 -0500 Received: by mail-lf0-f66.google.com with SMTP id g80so12484306lfg.0 for ; Mon, 18 Dec 2017 01:18:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=nZXLnhvx8/k0Slp956fn6z70v5P0yCSUD84icDu3ebs=; b=dnNIolbBgajQTxkgCBWIWJWNlBvBBBS/uRjHopX4qe3Qap34uhj2Y/v2ktlTlMrC/f fDEMIo2MstvCLu0lIhSf1vSWQY1Mf2tKbrilyf0KQdw14vrvcoH77C3pvkbUTj8HoPNZ EVToi1X8WI5X5eZcEyMDVEjoKZttdEFtexMaLs1zUFC6L5/O53PhhcFa3fnuag522LtD DSHPoqIm3JkQIs5AkRLwkGjHZxi/9Hip3BbNvQsWHfVlZK1ZUzxZ8baMYqdV/ddWbMc/ z49jHaFMzxWknQTw4JPF1fN+ymIsVRJMnNNIXvStktxSDU6uba+Jgom+lkMOprJEx+vs Raug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=nZXLnhvx8/k0Slp956fn6z70v5P0yCSUD84icDu3ebs=; b=QoKZqmGtRQx/o8ySK8z1ahQvCShTzIjudmEkjmSYOiOJe5GlrjNdTjBEa/oZm2LINb ncbUNd/gVR+whW2vy4mQGLNi6dYioxNoHDBBhWBFuQcjGbrbJCW+j6Pv7jZloplWyvCd sLuPQZVKlcVgM9PE7Cel3xvwks9Z91OjH+QIu9zv1Uil+DTDwfoDNfxrov4j2Pbf4lO5 E7+dLJOSj85r+zbCyvjr4+rgzdn1etliv9PSl1ydjHFFeJZYsmXg6V2SVq3+VKmiPvjB k7HD67WjFlGq21k6tGq0ASaF9JkD/zjRNxXmmrvEbf5+4OhrBlOLqvYkh7mE6kL6w2Wf zbeQ== X-Gm-Message-State: AKGB3mJBVyyNHaWPJFyLfh/Xg5x/IJVzKiKLr9MvK2XtpjYQ53/QOCSi OtFaZ4yXej4pbQLrnepO5EFhUQ== X-Google-Smtp-Source: ACJfBosnDihjbFvf6KiqNV+1QmEe0B2xqnim4FBPnJ8L0o+rhKWsB07j5xq7uMX/OGnRKsqOycPaeg== X-Received: by 10.46.84.65 with SMTP id y1mr10870599ljd.74.1513588696489; Mon, 18 Dec 2017 01:18:16 -0800 (PST) Received: from gilgamesh.semihalf.com (31-172-191-173.noc.fibertech.net.pl. [31.172.191.173]) by smtp.gmail.com with ESMTPSA id r16sm2407186ljd.18.2017.12.18.01.18.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 18 Dec 2017 01:18:15 -0800 (PST) From: Marcin Wojtas To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org Cc: davem@davemloft.net, linux@arm.linux.org.uk, rafael.j.wysocki@intel.com, andrew@lunn.ch, f.fainelli@gmail.com, antoine.tenart@free-electrons.com, thomas.petazzoni@free-electrons.com, gregory.clement@free-electrons.com, ezequiel.garcia@free-electrons.com, nadavh@marvell.com, neta@marvell.com, ard.biesheuvel@linaro.org, mw@semihalf.com, jaz@semihalf.com, tn@semihalf.com Subject: [net-next: PATCH 3/8] mdio_bus: Introduce fwnode MDIO helpers Date: Mon, 18 Dec 2017 10:17:59 +0100 Message-Id: <1513588684-15647-4-git-send-email-mw@semihalf.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513588684-15647-1-git-send-email-mw@semihalf.com> References: <1513588684-15647-1-git-send-email-mw@semihalf.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This patch introduces fwnode helper for registering MDIO bus, as well as one for finding the PHY, basing on its firmware node pointer. Comparing to existing OF equivalent, fwnode_mdiobus_register() does not support: * deprecated bindings (device whitelist, nor the PHY ID embedded in the compatible string) * MDIO bus auto scanning Signed-off-by: Marcin Wojtas --- drivers/net/phy/mdio_bus.c | 218 ++++++++++++++++++++ include/linux/mdio.h | 3 + 2 files changed, 221 insertions(+) diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c index a0f34c3..f2b2a94 100644 --- a/drivers/net/phy/mdio_bus.c +++ b/drivers/net/phy/mdio_bus.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -662,6 +663,223 @@ static int mdio_uevent(struct device *dev, struct kobj_uevent_env *env) return 0; } +static int fwnode_mdiobus_register_phy(struct mii_bus *bus, + struct fwnode_handle *child, u32 addr) +{ + struct phy_device *phy; + bool is_c45 = false; + int rc; + + rc = fwnode_property_match_string(child, "compatible", + "ethernet-phy-ieee802.3-c45"); + if (!rc) + is_c45 = true; + + phy = get_phy_device(bus, addr, is_c45); + if (IS_ERR(phy)) + return PTR_ERR(phy); + + phy->irq = bus->irq[addr]; + + if (to_of_node(child)) { + rc = of_irq_get(to_of_node(child), 0); + if (rc == -EPROBE_DEFER) { + phy_device_free(phy); + return rc; + } else if (rc > 0) { + phy->irq = rc; + bus->irq[addr] = rc; + } + } + + if (fwnode_property_read_bool(child, "broken-turn-around")) + bus->phy_ignore_ta_mask |= 1 << addr; + + /* Associate the fwnode with the device structure so it + * can be looked up later. + */ + phy->mdio.dev.fwnode = child; + + /* All data is now stored in the phy struct, so register it */ + rc = phy_device_register(phy); + if (rc) { + phy_device_free(phy); + fwnode_handle_put(child); + return rc; + } + + dev_dbg(&bus->dev, "registered phy at address %i\n", addr); + + return 0; +} + +static int fwnode_mdiobus_register_device(struct mii_bus *bus, + struct fwnode_handle *child, u32 addr) +{ + struct mdio_device *mdiodev; + int rc; + + mdiodev = mdio_device_create(bus, addr); + if (IS_ERR(mdiodev)) + return PTR_ERR(mdiodev); + + /* Associate the fwnode with the device structure so it + * can be looked up later. + */ + mdiodev->dev.fwnode = child; + + /* All data is now stored in the mdiodev struct; register it. */ + rc = mdio_device_register(mdiodev); + if (rc) { + mdio_device_free(mdiodev); + fwnode_handle_put(child); + return rc; + } + + dev_dbg(&bus->dev, "registered mdio device at address %i\n", addr); + + return 0; +} + +static int fwnode_mdio_parse_addr(struct device *dev, + const struct fwnode_handle *fwnode) +{ + u32 addr; + int ret; + + ret = fwnode_property_read_u32(fwnode, "reg", &addr); + if (ret < 0) { + dev_err(dev, "PHY node has no 'reg' property\n"); + return ret; + } + + /* A PHY must have a reg property in the range [0-31] */ + if (addr < 0 || addr >= PHY_MAX_ADDR) { + dev_err(dev, "PHY address %i is invalid\n", addr); + return -EINVAL; + } + + return addr; +} + +/** + * fwnode_mdiobus_child_is_phy - Return true if the child is a PHY node. + * It must either: + * o Compatible string of "ethernet-phy-ieee802.3-c45" + * o Compatible string of "ethernet-phy-ieee802.3-c22" + * Checking "compatible" property is done, in order to follow the DT binding. + */ +static bool fwnode_mdiobus_child_is_phy(struct fwnode_handle *child) +{ + int ret; + + ret = fwnode_property_match_string(child, "compatible", + "ethernet-phy-ieee802.3-c45"); + if (!ret) + return true; + + ret = fwnode_property_match_string(child, "compatible", + "ethernet-phy-ieee802.3-c22"); + if (!ret) + return true; + + if (!fwnode_property_present(child, "compatible")) + return true; + + return false; +} + +/** + * fwnode_mdiobus_register - Register mii_bus and create PHYs from the fwnode + * @bus: pointer to mii_bus structure + * @fwnode: pointer to fwnode_handle of MDIO bus. + * + * This function registers the mii_bus structure and registers a phy_device + * for each child node of @fwnode. + */ +int fwnode_mdiobus_register(struct mii_bus *bus, struct fwnode_handle *fwnode) +{ + struct fwnode_handle *child; + int addr, rc; + int default_gpio_reset_delay_ms = 10; + + /* Do not continue if the node is disabled */ + if (!fwnode_device_is_available(fwnode)) + return -ENODEV; + + /* Mask out all PHYs from auto probing. Instead the PHYs listed in + * the firmware nodes are populated after the bus has been registered. + */ + bus->phy_mask = ~0; + + bus->dev.fwnode = fwnode; + + /* Get bus level PHY reset GPIO details */ + bus->reset_delay_us = default_gpio_reset_delay_ms; + fwnode_property_read_u32(fwnode, "reset-delay-us", + &bus->reset_delay_us); + + /* Register the MDIO bus */ + rc = mdiobus_register(bus); + if (rc) + return rc; + + /* Loop over the child nodes and register a phy_device for each PHY */ + fwnode_for_each_child_node(fwnode, child) { + addr = fwnode_mdio_parse_addr(&bus->dev, child); + if (addr < 0) + continue; + + if (fwnode_mdiobus_child_is_phy(child)) + rc = fwnode_mdiobus_register_phy(bus, child, addr); + else + rc = fwnode_mdiobus_register_device(bus, child, addr); + if (rc) + goto unregister; + } + + return 0; + +unregister: + mdiobus_unregister(bus); + + return rc; +} +EXPORT_SYMBOL(fwnode_mdiobus_register); + +/* Helper function for fwnode_phy_find_device */ +static int fwnode_phy_match(struct device *dev, void *phy_fwnode) +{ + return dev->fwnode == phy_fwnode; +} + +/** + * fwnode_phy_find_device - find the phy_device associated to fwnode + * @phy_fwnode: Pointer to the PHY's fwnode + * + * If successful, returns a pointer to the phy_device with the embedded + * struct device refcount incremented by one, or NULL on failure. + */ +struct phy_device *fwnode_phy_find_device(struct fwnode_handle *phy_fwnode) +{ + struct device *d; + struct mdio_device *mdiodev; + + if (!phy_fwnode) + return NULL; + + d = bus_find_device(&mdio_bus_type, NULL, phy_fwnode, fwnode_phy_match); + if (d) { + mdiodev = to_mdio_device(d); + if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY) + return to_phy_device(d); + put_device(d); + } + + return NULL; +} +EXPORT_SYMBOL(fwnode_phy_find_device); + #ifdef CONFIG_PM static int mdio_bus_suspend(struct device *dev) { diff --git a/include/linux/mdio.h b/include/linux/mdio.h index e37c21d..286ec12 100644 --- a/include/linux/mdio.h +++ b/include/linux/mdio.h @@ -272,6 +272,9 @@ int mdiobus_unregister_device(struct mdio_device *mdiodev); bool mdiobus_is_registered_device(struct mii_bus *bus, int addr); struct phy_device *mdiobus_get_phy(struct mii_bus *bus, int addr); +int fwnode_mdiobus_register(struct mii_bus *bus, struct fwnode_handle *fwnode); +struct phy_device *fwnode_phy_find_device(struct fwnode_handle *phy_fwnode); + /** * mdio_module_driver() - Helper macro for registering mdio drivers * From patchwork Mon Dec 18 09:18:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcin Wojtas X-Patchwork-Id: 849913 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=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=semihalf-com.20150623.gappssmtp.com header.i=@semihalf-com.20150623.gappssmtp.com header.b="pguGqqBr"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3z0b8L1lSVz9rxm for ; Mon, 18 Dec 2017 20:19:30 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933344AbdLRJSY (ORCPT ); Mon, 18 Dec 2017 04:18:24 -0500 Received: from mail-lf0-f65.google.com ([209.85.215.65]:36926 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933324AbdLRJST (ORCPT ); Mon, 18 Dec 2017 04:18:19 -0500 Received: by mail-lf0-f65.google.com with SMTP id a12so16945998lfe.4 for ; Mon, 18 Dec 2017 01:18:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=V6c/fgwy55nbCFI7VAWAtG97lHlAQpLwz6l8MV90oKo=; b=pguGqqBrMYGAZ55g8o/TuL6lQv6Q9u8YztYs847r1RVlBxDzoMHfQzPtrH6sbT9mjm o72UbynDq/6+xeUnWMMM34kh/NkmCDuGEyYW+vdwdJuJccm7Ms7HW1L9tXhY4GVzUX9D TEOriOEifKOx9Y1cpNetTJth4/4vmtj0V24AiTi4CJgpw36rpKwvW9D2lNRv7xkKNMFX H5KDVS1aZUAXOIOexPBZpcVZbBvtQc2gIq9yC5xy4xQkQliCs1Jjsezv63+80RVnpX9V MArm5ZQ083QhdHpNdIdmn8l7SHjVFM/hoUn8J95ZURudl4FTMVRFVlo8WaWgWCCyagaQ +amA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=V6c/fgwy55nbCFI7VAWAtG97lHlAQpLwz6l8MV90oKo=; b=Ak87f4DD6BISaWmbW4Z+Sb6oLwbkqprRH77nqIGOF4gqNr5spXhYhXq07XbhSxsXAP +nym7TP2zbTXSIj1afaOEHzYODx7gteAQbStsP0QE1Ng/nxhdDxrXZMEhUiMy7pj0ZSM RV9NpqKNaBkTxq3kCHKyAp6TfmKbKc/8VSFyP1TSrOYs/ZCo5zxRlOeZurQI1TQKI/F2 3dKAPRzv3hyelWE3XJ3rD6aD01K2zzB+IzpUAuTnN6asXT4iYuYQmzfT6T8Ae0hth26r 6Yv9VLyNs685OMj85hv8cxx6KJoUHLo1ONZJnk9SqmU6GwsrFDNfUAyrZx7ntC36mO2i Uh/g== X-Gm-Message-State: AKGB3mIgrJcHJqt5vfJfZic/1p/tp5mWhWZwl7eKc8W+t/2ravColctp ML+9aZYOTlbvcbZ+h/UQl/xsTg== X-Google-Smtp-Source: ACJfBosHiG/aKLU2LurGkgoBKKbpreCVmSVBQvb0z5+83TA/Vyh+6j8O0p6h9suzG2NH71sYOg7OSw== X-Received: by 10.46.34.134 with SMTP id i128mr10272379lji.11.1513588698230; Mon, 18 Dec 2017 01:18:18 -0800 (PST) Received: from gilgamesh.semihalf.com (31-172-191-173.noc.fibertech.net.pl. [31.172.191.173]) by smtp.gmail.com with ESMTPSA id r16sm2407186ljd.18.2017.12.18.01.18.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 18 Dec 2017 01:18:17 -0800 (PST) From: Marcin Wojtas To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org Cc: davem@davemloft.net, linux@arm.linux.org.uk, rafael.j.wysocki@intel.com, andrew@lunn.ch, f.fainelli@gmail.com, antoine.tenart@free-electrons.com, thomas.petazzoni@free-electrons.com, gregory.clement@free-electrons.com, ezequiel.garcia@free-electrons.com, nadavh@marvell.com, neta@marvell.com, ard.biesheuvel@linaro.org, mw@semihalf.com, jaz@semihalf.com, tn@semihalf.com Subject: [net-next: PATCH 4/8] net: mvmdio: add ACPI support Date: Mon, 18 Dec 2017 10:18:00 +0100 Message-Id: <1513588684-15647-5-git-send-email-mw@semihalf.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513588684-15647-1-git-send-email-mw@semihalf.com> References: <1513588684-15647-1-git-send-email-mw@semihalf.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This patch introducing ACPI support for the mvmdio driver by adding acpi_match_table with two entries: * "MRVL0100" for the SMI operation * "MRVL0101" for the XSMI mode Also clk enabling is skipped, because the tables do not contain such data and clock maintenance relies on the firmware. The MDIO bus is registered using newly introduced fwnode_mdiobus_register(). Memory region used by mvmdio driver is usually placed in the middle of the address space of the network controller (e.g. NETA or PP2). The MDIO base address is obtained without requesting memory region (by devm_ioremap() call), later overlapping resources are requested by the network driver, where care is taken to avoid concurrent access. This way of solving problem occurred to be not sufficient with ACPI, because resources declared in the table and used once, appear as 'in-use' in the OS. This patch also ensures releasing resources by mvmdio driver prior to initializing the network controller driver. Signed-off-by: Marcin Wojtas --- drivers/net/ethernet/marvell/mvmdio.c | 42 +++++++++++++++++++- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/marvell/mvmdio.c b/drivers/net/ethernet/marvell/mvmdio.c index 0495487..31d758a 100644 --- a/drivers/net/ethernet/marvell/mvmdio.c +++ b/drivers/net/ethernet/marvell/mvmdio.c @@ -17,6 +17,7 @@ * warranty of any kind, whether express or implied. */ +#include #include #include #include @@ -279,9 +280,19 @@ static int orion_mdio_probe(struct platform_device *pdev) struct resource *r; struct mii_bus *bus; struct orion_mdio_dev *dev; + const struct acpi_device_id *acpi_id; + bool use_acpi = false; int i, ret; - type = (enum orion_mdio_bus_type)of_device_get_match_data(&pdev->dev); + if (has_acpi_companion(&pdev->dev)) { + acpi_id = acpi_match_device(pdev->dev.driver->acpi_match_table, + &pdev->dev); + type = (enum orion_mdio_bus_type)acpi_id->driver_data; + use_acpi = true; + } else { + type = + (enum orion_mdio_bus_type)of_device_get_match_data(&pdev->dev); + } r = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!r) { @@ -319,7 +330,7 @@ static int orion_mdio_probe(struct platform_device *pdev) init_waitqueue_head(&dev->smi_busy_wait); - for (i = 0; i < ARRAY_SIZE(dev->clk); i++) { + for (i = 0; !use_acpi && i < ARRAY_SIZE(dev->clk); i++) { dev->clk[i] = of_clk_get(pdev->dev.of_node, i); if (IS_ERR(dev->clk[i])) break; @@ -350,6 +361,8 @@ static int orion_mdio_probe(struct platform_device *pdev) if (pdev->dev.of_node) ret = of_mdiobus_register(bus, pdev->dev.of_node); + else if (use_acpi) + ret = fwnode_mdiobus_register(bus, pdev->dev.fwnode); else ret = mdiobus_register(bus); if (ret < 0) { @@ -357,6 +370,15 @@ static int orion_mdio_probe(struct platform_device *pdev) goto out_mdio; } + /* In case of ACPI resources declared in the tables and used + * once, appear as 'in-use' in the OS. Make sure they are released, + * before the network driver possibly requests it again during + * its initialization. The care is taken there to avoid + * concurrent access to this memory region. + */ + if (use_acpi) + release_resource(r); + platform_set_drvdata(pdev, bus); return 0; @@ -365,6 +387,11 @@ static int orion_mdio_probe(struct platform_device *pdev) if (dev->err_interrupt > 0) writel(0, dev->regs + MVMDIO_ERR_INT_MASK); + if (use_acpi) { + release_resource(r); + return ret; + } + for (i = 0; i < ARRAY_SIZE(dev->clk); i++) { if (IS_ERR(dev->clk[i])) break; @@ -385,6 +412,9 @@ static int orion_mdio_remove(struct platform_device *pdev) writel(0, dev->regs + MVMDIO_ERR_INT_MASK); mdiobus_unregister(bus); + if (has_acpi_companion(&pdev->dev)) + return 0; + for (i = 0; i < ARRAY_SIZE(dev->clk); i++) { if (IS_ERR(dev->clk[i])) break; @@ -402,12 +432,20 @@ static const struct of_device_id orion_mdio_match[] = { }; MODULE_DEVICE_TABLE(of, orion_mdio_match); +static const struct acpi_device_id orion_mdio_acpi_match[] = { + { "MRVL0100", BUS_TYPE_SMI }, + { "MRVL0101", BUS_TYPE_XSMI }, + { }, +}; +MODULE_DEVICE_TABLE(acpi, orion_mdio_acpi_match); + static struct platform_driver orion_mdio_driver = { .probe = orion_mdio_probe, .remove = orion_mdio_remove, .driver = { .name = "orion-mdio", .of_match_table = orion_mdio_match, + .acpi_match_table = ACPI_PTR(orion_mdio_acpi_match), }, }; From patchwork Mon Dec 18 09:18:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcin Wojtas X-Patchwork-Id: 849915 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=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=semihalf-com.20150623.gappssmtp.com header.i=@semihalf-com.20150623.gappssmtp.com header.b="Ci4nCMcX"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3z0b9L055Hz9rxm for ; Mon, 18 Dec 2017 20:20:21 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933387AbdLRJUG (ORCPT ); Mon, 18 Dec 2017 04:20:06 -0500 Received: from mail-lf0-f67.google.com ([209.85.215.67]:45248 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932837AbdLRJSV (ORCPT ); Mon, 18 Dec 2017 04:18:21 -0500 Received: by mail-lf0-f67.google.com with SMTP id f13so16909210lff.12 for ; Mon, 18 Dec 2017 01:18:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=oj0JajkqNds/vxCnFWY1cB89VnOimwCruDlOqJl844E=; b=Ci4nCMcXLzTsp9ZzHizkIlmxvOS9pljWCorbjEXCtU5e/cH0tmrmz3FcDchKa/COR5 2cxWqrI6YJ0ThPl887lR417asASQIWc9BtOUK/30TN0jeYv8R4WAM1oudJ3zKKCvOJjQ jY4CzkU0L9pJl045gcSGnzan8b79YbL8X555zPv3cFguN4Eum46BBk0iRUWvFfTq/G7M hk1ynz8kJTWGnp2wP6n2eoUa1eTAHV8XkYnkbsKxcTC72X9YXjRXoyYEXmQig1avS6ej zE/gijUa3ij5J3Ty8728BU3k8/ZSsp7YSFthvzPzl8Y1439+bGmeLolqEsWz2SuZtnOt Zm4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=oj0JajkqNds/vxCnFWY1cB89VnOimwCruDlOqJl844E=; b=BlRwRVqK7TPL+RKlzUcR9KM/kyPpfPpLvRmJZhD0uxy25r91vl6VsMGWZh+ZmRspXf 2ItfN8dXVwOFK5xiFt0pZSMo+JOdYP+o3NfK6NbVMh42nqeZZ2uWmc8j5FzIECkn5DKk 5s/C8bAkK/bGAafHv6iSOXMznx4pzIeu+fi22n+4rZ/aNe4PT//gkst6hdEK9y7unue9 RFM1m1fFoM0PF1tOYgYSKXzvSncBTEXnnTuXsPv1F+p/4TaKABZ1C/lslqewP2F6rjAs 2DxDEv4AXNsbksW94fNg7JsfsM2vOWusZwN9Krz5lfNp0C7gSe0AOL+pbMH2dDc7c7BP QDZg== X-Gm-Message-State: AKGB3mLFn7Jh5XXY5fzA7jDjzskl/cbWbBogrkalcZwSfBjq8H6mkGcy A6CH8PSJtZEfKT0463qj54axeg== X-Google-Smtp-Source: ACJfBouFjAXc4cfPQdyiGoxDyHN4FWLYm53e0LBsF9jkIDi6YH7U9lBlN8OQ/EAFquMZcJflRIQ9TA== X-Received: by 10.25.215.167 with SMTP id q39mr10955423lfi.33.1513588699726; Mon, 18 Dec 2017 01:18:19 -0800 (PST) Received: from gilgamesh.semihalf.com (31-172-191-173.noc.fibertech.net.pl. [31.172.191.173]) by smtp.gmail.com with ESMTPSA id r16sm2407186ljd.18.2017.12.18.01.18.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 18 Dec 2017 01:18:19 -0800 (PST) From: Marcin Wojtas To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org Cc: davem@davemloft.net, linux@arm.linux.org.uk, rafael.j.wysocki@intel.com, andrew@lunn.ch, f.fainelli@gmail.com, antoine.tenart@free-electrons.com, thomas.petazzoni@free-electrons.com, gregory.clement@free-electrons.com, ezequiel.garcia@free-electrons.com, nadavh@marvell.com, neta@marvell.com, ard.biesheuvel@linaro.org, mw@semihalf.com, jaz@semihalf.com, tn@semihalf.com Subject: [net-next: PATCH 5/8] net: mvpp2: simplify maintaining enabled ports' list Date: Mon, 18 Dec 2017 10:18:01 +0100 Message-Id: <1513588684-15647-6-git-send-email-mw@semihalf.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513588684-15647-1-git-send-email-mw@semihalf.com> References: <1513588684-15647-1-git-send-email-mw@semihalf.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 'port_count' field of the mvpp2 structure holds an overall amount of available ports, based on DT nodes status. In order to be prepared to support other HW description, obtain the value by incrementing it upon each successful port initialization. This allowed for simplifying port indexing in the controller's private array, whose size is now not dynamically allocated, but fixed to MVPP2_MAX_PORTS. This patch simplifies creating and filling list of enabled ports and is a part of the preparation for adding ACPI support in the mvpp2 driver. Signed-off-by: Marcin Wojtas --- drivers/net/ethernet/marvell/mvpp2.c | 32 +++++++------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/drivers/net/ethernet/marvell/mvpp2.c b/drivers/net/ethernet/marvell/mvpp2.c index a197607..7f42d90 100644 --- a/drivers/net/ethernet/marvell/mvpp2.c +++ b/drivers/net/ethernet/marvell/mvpp2.c @@ -865,7 +865,7 @@ struct mvpp2 { /* List of pointers to port structures */ int port_count; - struct mvpp2_port **port_list; + struct mvpp2_port *port_list[MVPP2_MAX_PORTS]; /* Aggregated TXQs */ struct mvpp2_tx_queue *aggr_txqs; @@ -7741,7 +7741,7 @@ static void mvpp2_port_copy_mac_addr(struct net_device *dev, struct mvpp2 *priv, /* Ports initialization */ static int mvpp2_port_probe(struct platform_device *pdev, struct device_node *port_node, - struct mvpp2 *priv, int index) + struct mvpp2 *priv) { struct device_node *phy_node; struct phy *comphy; @@ -7934,7 +7934,8 @@ static int mvpp2_port_probe(struct platform_device *pdev, } netdev_info(dev, "Using %s mac address %pM\n", mac_from, dev->dev_addr); - priv->port_list[index] = port; + priv->port_list[priv->port_count++] = port; + return 0; err_free_port_pcpu: @@ -8313,28 +8314,17 @@ static int mvpp2_probe(struct platform_device *pdev) goto err_mg_clk; } - priv->port_count = of_get_available_child_count(dn); - if (priv->port_count == 0) { - dev_err(&pdev->dev, "no ports enabled\n"); - err = -ENODEV; - goto err_mg_clk; - } - - priv->port_list = devm_kcalloc(&pdev->dev, priv->port_count, - sizeof(*priv->port_list), - GFP_KERNEL); - if (!priv->port_list) { - err = -ENOMEM; - goto err_mg_clk; - } - /* Initialize ports */ - i = 0; for_each_available_child_of_node(dn, port_node) { - err = mvpp2_port_probe(pdev, port_node, priv, i); + err = mvpp2_port_probe(pdev, port_node, priv); if (err < 0) goto err_port_probe; - i++; + } + + if (priv->port_count == 0) { + dev_err(&pdev->dev, "no ports enabled\n"); + err = -ENODEV; + goto err_mg_clk; } /* Statistics must be gathered regularly because some of them (like From patchwork Mon Dec 18 09:18:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcin Wojtas X-Patchwork-Id: 849914 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=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=semihalf-com.20150623.gappssmtp.com header.i=@semihalf-com.20150623.gappssmtp.com header.b="gqwlwSwn"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3z0b8Z4QjBz9rxm for ; Mon, 18 Dec 2017 20:19:42 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933279AbdLRJTk (ORCPT ); Mon, 18 Dec 2017 04:19:40 -0500 Received: from mail-lf0-f67.google.com ([209.85.215.67]:44061 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933332AbdLRJSX (ORCPT ); Mon, 18 Dec 2017 04:18:23 -0500 Received: by mail-lf0-f67.google.com with SMTP id x204so16905407lfa.11 for ; Mon, 18 Dec 2017 01:18:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Bqd7nzH4/Tt5heQYNjT+tplFLLUS1UbUGRpcfs0es4k=; b=gqwlwSwnTRoNoSVkp3rUaGl2pHt0z7ZABzmHe/96w74K7ECHRaA2SlLBGNv1XvJPyJ D6Pbsem9t4/wmoS70uG4ZTaIfkp7HXmJI3mneR8a0u6l12izcQ8Vl+vxYWCq++MjonX/ UCaMW46ScABXI7F9UKp3trblkknHXhhXzpLgik4MTRLExz4cQ3EERb+9okG6/Tj26a4J N1umRalS//4xVSgK37H+AIX3+UQPVhR7zAteNnneBnRKePEC98kWnOfD2UP0Ou4Xk78u roVLHllcUN1rfil+9VJdl+RSHr5Dwv1tVH6Hwyheb+wn83r9FJyM8azQ7KxlFJgUJsJk Y4pA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Bqd7nzH4/Tt5heQYNjT+tplFLLUS1UbUGRpcfs0es4k=; b=FthV5yD6xKL0ubz6fnR8arUPQ/diUdGPizDklL+fV0hGFHqR82m5JRvdb+sCoX6l2c PnvSpoeNVT9x8YZArgNLPAZ721xmQruCKrFuUmAD99TtPKT0ZTJXkl3XDH8AC3w6sWCy clViXrScsQ/pDWTuHr9KpP3MzVyKoiRa5JGdQePQhl8Br8fV/QIrwv1RUb2dVw0iUNVo u3djJ3uvvhNLmOQbsS2UkqjT8ZA8CS05q2o0TnbBJMJWnWamOcpz7NV9gJ6e0cXJYhfv FBnEJGsfLgmkdfEJkzgkuCgzZdvrHpYZgtJB8d5JNp3/j0b/AbJES9mAxz4ZYZHdDkEQ HsNg== X-Gm-Message-State: AKGB3mLN1JlQpV1XaNeX9KQqRPS7w5UMs415gLz8JWAA5PuONXIr732H Uzl2ntH4ynS96UYMpuAYDi+xYQ== X-Google-Smtp-Source: ACJfBosyvsiYDwqqmwzT++iHzH5v0WNrHvpdGhYTED1M2Vm3PdKdGLxCw+cP45sJH1kDK4bY9MM0yA== X-Received: by 10.25.213.138 with SMTP id m132mr9379889lfg.107.1513588701448; Mon, 18 Dec 2017 01:18:21 -0800 (PST) Received: from gilgamesh.semihalf.com (31-172-191-173.noc.fibertech.net.pl. [31.172.191.173]) by smtp.gmail.com with ESMTPSA id r16sm2407186ljd.18.2017.12.18.01.18.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 18 Dec 2017 01:18:20 -0800 (PST) From: Marcin Wojtas To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org Cc: davem@davemloft.net, linux@arm.linux.org.uk, rafael.j.wysocki@intel.com, andrew@lunn.ch, f.fainelli@gmail.com, antoine.tenart@free-electrons.com, thomas.petazzoni@free-electrons.com, gregory.clement@free-electrons.com, ezequiel.garcia@free-electrons.com, nadavh@marvell.com, neta@marvell.com, ard.biesheuvel@linaro.org, mw@semihalf.com, jaz@semihalf.com, tn@semihalf.com Subject: [net-next: PATCH 6/8] net: mvpp2: use device_*/fwnode_* APIs instead of of_* Date: Mon, 18 Dec 2017 10:18:02 +0100 Message-Id: <1513588684-15647-7-git-send-email-mw@semihalf.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513588684-15647-1-git-send-email-mw@semihalf.com> References: <1513588684-15647-1-git-send-email-mw@semihalf.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org OF functions can be used only for the driver using DT. As a preparation for introducing ACPI support in mvpp2 driver, use struct fwnode_handle in order to obtain properties from the hardware description. Because there is no equivalent for for_each_available_child_of_node(), use device_for_each_child_node() and check the port availability inside the mvpp2_port_probe() routine. This patch replaces of_* function with device_*/fwnode_* where possible in the mvpp2. Signed-off-by: Marcin Wojtas --- drivers/net/ethernet/marvell/mvpp2.c | 47 +++++++++++--------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/drivers/net/ethernet/marvell/mvpp2.c b/drivers/net/ethernet/marvell/mvpp2.c index 7f42d90..537474f 100644 --- a/drivers/net/ethernet/marvell/mvpp2.c +++ b/drivers/net/ethernet/marvell/mvpp2.c @@ -932,6 +932,9 @@ struct mvpp2_port { struct mvpp2 *priv; + /* Firmware node associated to the port */ + struct fwnode_handle *fwnode; + /* Per-port registers' base address */ void __iomem *base; void __iomem *stats_base; @@ -7711,17 +7714,16 @@ static bool mvpp2_port_has_tx_irqs(struct mvpp2 *priv, } static void mvpp2_port_copy_mac_addr(struct net_device *dev, struct mvpp2 *priv, - struct device_node *port_node, + struct fwnode_handle *fwnode, char **mac_from) { struct mvpp2_port *port = netdev_priv(dev); char hw_mac_addr[ETH_ALEN] = {0}; - const char *dt_mac_addr; + char fw_mac_addr[ETH_ALEN]; - dt_mac_addr = of_get_mac_address(port_node); - if (dt_mac_addr && is_valid_ether_addr(dt_mac_addr)) { - *mac_from = "device tree"; - ether_addr_copy(dev->dev_addr, dt_mac_addr); + if (fwnode_get_mac_address(fwnode, fw_mac_addr, ETH_ALEN)) { + *mac_from = "firmware node"; + ether_addr_copy(dev->dev_addr, fw_mac_addr); return; } @@ -7740,13 +7742,14 @@ static void mvpp2_port_copy_mac_addr(struct net_device *dev, struct mvpp2 *priv, /* Ports initialization */ static int mvpp2_port_probe(struct platform_device *pdev, - struct device_node *port_node, + struct fwnode_handle *port_fwnode, struct mvpp2 *priv) { struct device_node *phy_node; struct phy *comphy; struct mvpp2_port *port; struct mvpp2_port_pcpu *port_pcpu; + struct device_node *port_node = to_of_node(port_fwnode); struct net_device *dev; struct resource *res; char *mac_from = ""; @@ -7757,6 +7760,10 @@ static int mvpp2_port_probe(struct platform_device *pdev, int phy_mode; int err, i, cpu; + /* Silently exit, if the port node turns out to be disabled. */ + if (!fwnode_device_is_available(port_fwnode)) + return 0; + has_tx_irqs = mvpp2_port_has_tx_irqs(priv, port_node); if (!has_tx_irqs) @@ -7773,7 +7780,7 @@ static int mvpp2_port_probe(struct platform_device *pdev, return -ENOMEM; phy_node = of_parse_phandle(port_node, "phy", 0); - phy_mode = of_get_phy_mode(port_node); + phy_mode = fwnode_get_phy_mode(port_fwnode); if (phy_mode < 0) { dev_err(&pdev->dev, "incorrect phy mode\n"); err = phy_mode; @@ -7789,7 +7796,7 @@ static int mvpp2_port_probe(struct platform_device *pdev, comphy = NULL; } - if (of_property_read_u32(port_node, "port-id", &id)) { + if (fwnode_property_read_u32(port_fwnode, "port-id", &id)) { err = -EINVAL; dev_err(&pdev->dev, "missing port-id value\n"); goto err_free_netdev; @@ -7820,7 +7827,7 @@ static int mvpp2_port_probe(struct platform_device *pdev, /* the link irq is optional */ port->link_irq = 0; - if (of_property_read_bool(port_node, "marvell,loopback")) + if (fwnode_property_read_bool(port_fwnode, "marvell,loopback")) port->flags |= MVPP2_F_LOOPBACK; port->id = id; @@ -7845,8 +7852,8 @@ static int mvpp2_port_probe(struct platform_device *pdev, MVPP21_MIB_COUNTERS_OFFSET + port->gop_id * MVPP21_MIB_COUNTERS_PORT_SZ; } else { - if (of_property_read_u32(port_node, "gop-port-id", - &port->gop_id)) { + if (fwnode_property_read_u32(port_fwnode, "gop-port-id", + &port->gop_id)) { err = -EINVAL; dev_err(&pdev->dev, "missing gop-port-id value\n"); goto err_deinit_qvecs; @@ -7876,7 +7883,7 @@ static int mvpp2_port_probe(struct platform_device *pdev, mutex_init(&port->gather_stats_lock); INIT_DELAYED_WORK(&port->stats_work, mvpp2_gather_hw_statistics); - mvpp2_port_copy_mac_addr(dev, priv, port_node, &mac_from); + mvpp2_port_copy_mac_addr(dev, priv, port_fwnode, &mac_from); port->tx_ring_size = MVPP2_MAX_TXD_DFLT; port->rx_ring_size = MVPP2_MAX_RXD_DFLT; @@ -8194,8 +8201,7 @@ static int mvpp2_init(struct platform_device *pdev, struct mvpp2 *priv) static int mvpp2_probe(struct platform_device *pdev) { - struct device_node *dn = pdev->dev.of_node; - struct device_node *port_node; + struct fwnode_handle *port_fwnode; struct mvpp2 *priv; struct resource *res; void __iomem *base; @@ -8315,8 +8321,8 @@ static int mvpp2_probe(struct platform_device *pdev) } /* Initialize ports */ - for_each_available_child_of_node(dn, port_node) { - err = mvpp2_port_probe(pdev, port_node, priv); + device_for_each_child_node(&pdev->dev, port_fwnode) { + err = mvpp2_port_probe(pdev, port_fwnode, priv); if (err < 0) goto err_port_probe; } @@ -8347,7 +8353,7 @@ static int mvpp2_probe(struct platform_device *pdev) err_port_probe: i = 0; - for_each_available_child_of_node(dn, port_node) { + device_for_each_child_node(&pdev->dev, port_fwnode) { if (priv->port_list[i]) mvpp2_port_remove(priv->port_list[i]); i++; @@ -8366,14 +8372,13 @@ static int mvpp2_probe(struct platform_device *pdev) static int mvpp2_remove(struct platform_device *pdev) { struct mvpp2 *priv = platform_get_drvdata(pdev); - struct device_node *dn = pdev->dev.of_node; - struct device_node *port_node; + struct fwnode_handle *port_fwnode; int i = 0; flush_workqueue(priv->stats_queue); destroy_workqueue(priv->stats_queue); - for_each_available_child_of_node(dn, port_node) { + device_for_each_child_node(&pdev->dev, port_fwnode) { if (priv->port_list[i]) { mutex_destroy(&priv->port_list[i]->gather_stats_lock); mvpp2_port_remove(priv->port_list[i]); From patchwork Mon Dec 18 09:18:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcin Wojtas X-Patchwork-Id: 849912 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=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=semihalf-com.20150623.gappssmtp.com header.i=@semihalf-com.20150623.gappssmtp.com header.b="JUPDIbXl"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3z0b8F1DS5z9rxm for ; Mon, 18 Dec 2017 20:19:25 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932843AbdLRJTW (ORCPT ); Mon, 18 Dec 2017 04:19:22 -0500 Received: from mail-lf0-f67.google.com ([209.85.215.67]:44063 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933335AbdLRJSY (ORCPT ); Mon, 18 Dec 2017 04:18:24 -0500 Received: by mail-lf0-f67.google.com with SMTP id x204so16905494lfa.11 for ; Mon, 18 Dec 2017 01:18:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=yFKH4iPXd/4r5YtctdJLRHkSGyeJeMMi1Ybj5jbDS+g=; b=JUPDIbXlni0Dw/OMZG+R96hQ34syUnY/gIdLkTboRQCLPzbir8BCduuvvXy2+Dxx25 0L/TblUUygRB4sXKxS1lN4pJXXU5PNHw8zH507hnpWRc8Pu/b0YoIdRzL+YGYQw9hSGP X2Na0+4i57S+ujL0vAMjzUMPExtud5FiwlIYxjCyg9cPcdZJH8gP+sxOD/iaBiD9m668 k/RFEIN51ClCi6H9rBBsLdmkriFOmnFHWO9I1+quytwqsCMwX5ZrX6/s18HQzGa9gulX EjfPb6L+QA/29rcVF/OhHzZtXvtJbblyEPtmDlPTcHvu3MmzLS+XMW5RgkaqODJBCee+ TN/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=yFKH4iPXd/4r5YtctdJLRHkSGyeJeMMi1Ybj5jbDS+g=; b=cYalK555JE6rqB//3yl1dJ/JpXlJ4fpXBKywAiGNRySuTJjC4jJ3Q/5BKpMa5Y3JkM uvumeEWXEUx/6dN7KhUxND4zeBq8zJfjsxSeKGuhm5TyymifIm/yHdqS7WvSwDsc78jm O/yHKi05RuuCR3yy2/5DajwvlVzXIWdr95gIgA0fkff97KnrW7GGHo7t+XwHJbc92v7R pHBWYvFy2bNUx2b3ukeaT3NoCjWEW2gaQFBFFkvcjjxSjZkwhiXsUzGlq5EsLejuoMjB APUSno0+6NFa2ULBesQVZMQ0cKHsFUdboJcpifUvnTPxptlbZnRx9faNfaJalNUfGfmG 42FA== X-Gm-Message-State: AKGB3mLYfhqhWHRI7jO7OVhwOXkHdru8h6/xoRGWDZL8UkVg6PsUnyW2 xMeqB/5eVzPtBOfg5GTFGIQgDA== X-Google-Smtp-Source: ACJfBov9JYL1Vmvwvg2Z3RvapYhNemVaMw+cnPzfvXcUpKCuLFAVfMOQ7seUhF5LvrIbXjNUmFbL+w== X-Received: by 10.25.21.11 with SMTP id l11mr9296634lfi.142.1513588703151; Mon, 18 Dec 2017 01:18:23 -0800 (PST) Received: from gilgamesh.semihalf.com (31-172-191-173.noc.fibertech.net.pl. [31.172.191.173]) by smtp.gmail.com with ESMTPSA id r16sm2407186ljd.18.2017.12.18.01.18.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 18 Dec 2017 01:18:22 -0800 (PST) From: Marcin Wojtas To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org Cc: davem@davemloft.net, linux@arm.linux.org.uk, rafael.j.wysocki@intel.com, andrew@lunn.ch, f.fainelli@gmail.com, antoine.tenart@free-electrons.com, thomas.petazzoni@free-electrons.com, gregory.clement@free-electrons.com, ezequiel.garcia@free-electrons.com, nadavh@marvell.com, neta@marvell.com, ard.biesheuvel@linaro.org, mw@semihalf.com, jaz@semihalf.com, tn@semihalf.com Subject: [net-next: PATCH 7/8] net: mvpp2: handle PHY with its fwnode Date: Mon, 18 Dec 2017 10:18:03 +0100 Message-Id: <1513588684-15647-8-git-send-email-mw@semihalf.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513588684-15647-1-git-send-email-mw@semihalf.com> References: <1513588684-15647-1-git-send-email-mw@semihalf.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Newly introduced mvmdio driver ACPI support and also fwnode MDIO helpers allow for switching to PHY handling with its fwnode. This patch replaces of_* related PHY handling function with the fwnode_* equivalent and updates mvpp2_port structure accordingly. Signed-off-by: Marcin Wojtas --- drivers/net/ethernet/marvell/mvpp2.c | 41 ++++++++++++++------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/drivers/net/ethernet/marvell/mvpp2.c b/drivers/net/ethernet/marvell/mvpp2.c index 537474f..4e61ce7 100644 --- a/drivers/net/ethernet/marvell/mvpp2.c +++ b/drivers/net/ethernet/marvell/mvpp2.c @@ -963,7 +963,7 @@ struct mvpp2_port { struct delayed_work stats_work; phy_interface_t phy_interface; - struct device_node *phy_node; + struct fwnode_handle *phy_fwnode; struct phy *comphy; unsigned int link; unsigned int duplex; @@ -6890,14 +6890,22 @@ static void mvpp21_get_mac_address(struct mvpp2_port *port, unsigned char *addr) static int mvpp2_phy_connect(struct mvpp2_port *port) { struct phy_device *phy_dev; + int ret; /* No PHY is attached */ - if (!port->phy_node) + if (!port->phy_fwnode) return 0; - phy_dev = of_phy_connect(port->dev, port->phy_node, mvpp2_link_event, 0, + phy_dev = fwnode_phy_find_device(port->phy_fwnode); + phy_dev->dev_flags = 0; + + ret = phy_connect_direct(port->dev, phy_dev, mvpp2_link_event, port->phy_interface); - if (!phy_dev) { + + /* Refcount is held by phy_connect_direct() on success */ + put_device(&phy_dev->mdio.dev); + + if (ret) { netdev_err(port->dev, "cannot connect to phy\n"); return -ENODEV; } @@ -7047,7 +7055,7 @@ static int mvpp2_open(struct net_device *dev) goto err_cleanup_txqs; } - if (priv->hw_version == MVPP22 && !port->phy_node && port->link_irq) { + if (priv->hw_version == MVPP22 && !port->phy_fwnode && port->link_irq) { err = request_irq(port->link_irq, mvpp2_link_status_isr, 0, dev->name, port); if (err) { @@ -7082,7 +7090,7 @@ static int mvpp2_open(struct net_device *dev) return 0; err_free_link_irq: - if (priv->hw_version == MVPP22 && !port->phy_node && port->link_irq) + if (priv->hw_version == MVPP22 && !port->phy_fwnode && port->link_irq) free_irq(port->link_irq, port); err_free_irq: mvpp2_irqs_deinit(port); @@ -7107,7 +7115,7 @@ static int mvpp2_stop(struct net_device *dev) on_each_cpu(mvpp2_interrupts_mask, port, 1); mvpp2_shared_interrupt_mask_unmask(port, true); - if (priv->hw_version == MVPP22 && !port->phy_node && port->link_irq) + if (priv->hw_version == MVPP22 && !port->phy_fwnode && port->link_irq) free_irq(port->link_irq, port); mvpp2_irqs_deinit(port); @@ -7745,11 +7753,11 @@ static int mvpp2_port_probe(struct platform_device *pdev, struct fwnode_handle *port_fwnode, struct mvpp2 *priv) { - struct device_node *phy_node; struct phy *comphy; struct mvpp2_port *port; struct mvpp2_port_pcpu *port_pcpu; struct device_node *port_node = to_of_node(port_fwnode); + struct fwnode_reference_args args; struct net_device *dev; struct resource *res; char *mac_from = ""; @@ -7779,7 +7787,6 @@ static int mvpp2_port_probe(struct platform_device *pdev, if (!dev) return -ENOMEM; - phy_node = of_parse_phandle(port_node, "phy", 0); phy_mode = fwnode_get_phy_mode(port_fwnode); if (phy_mode < 0) { dev_err(&pdev->dev, "incorrect phy mode\n"); @@ -7814,6 +7821,17 @@ static int mvpp2_port_probe(struct platform_device *pdev, port->priv = priv; port->has_tx_irqs = has_tx_irqs; + err = fwnode_property_get_reference_args(port_fwnode, "phy", NULL, + 0, 0, &args); + if (!err) { + port->phy_fwnode = args.fwnode; + } else if (err == -ENOENT) { + port->phy_fwnode = NULL; + } else { + dev_err(&pdev->dev, "unable to parse \"phy\" node\n"); + goto err_free_netdev; + } + err = mvpp2_queue_vectors_init(port, port_node); if (err) goto err_free_netdev; @@ -7836,7 +7854,6 @@ static int mvpp2_port_probe(struct platform_device *pdev, else port->first_rxq = port->id * priv->max_port_rxqs; - port->phy_node = phy_node; port->phy_interface = phy_mode; port->comphy = comphy; @@ -7958,7 +7975,7 @@ static int mvpp2_port_probe(struct platform_device *pdev, err_deinit_qvecs: mvpp2_queue_vectors_deinit(port); err_free_netdev: - of_node_put(phy_node); + fwnode_handle_put(args.fwnode); free_netdev(dev); return err; } @@ -7969,7 +7986,7 @@ static void mvpp2_port_remove(struct mvpp2_port *port) int i; unregister_netdev(port->dev); - of_node_put(port->phy_node); + fwnode_handle_put(port->phy_fwnode); free_percpu(port->pcpu); free_percpu(port->stats); for (i = 0; i < port->ntxqs; i++) From patchwork Mon Dec 18 09:18:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcin Wojtas X-Patchwork-Id: 849911 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=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=semihalf-com.20150623.gappssmtp.com header.i=@semihalf-com.20150623.gappssmtp.com header.b="AsBp/OCe"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3z0b7t5Bvnz9s83 for ; Mon, 18 Dec 2017 20:19:06 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933361AbdLRJS3 (ORCPT ); Mon, 18 Dec 2017 04:18:29 -0500 Received: from mail-lf0-f67.google.com ([209.85.215.67]:36941 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933353AbdLRJS0 (ORCPT ); Mon, 18 Dec 2017 04:18:26 -0500 Received: by mail-lf0-f67.google.com with SMTP id a12so16946343lfe.4 for ; Mon, 18 Dec 2017 01:18:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=pHpyG4WfT/ESTmbwbIkbXBNraX1Zgl2dDx7CU8k6m2U=; b=AsBp/OCemfapvhD38BrFoqQYTZzh1DeN6yFXRNhJvDBt9ywf6XTz4jTZflDKjF0Umz 9e7kpNwTIdufVhXvTw7YuSonjtuAE/LpgcTlaWtb6lA2+WVCgYgdBwvO8dkf1rybC+um /W5Fsn8A270XFbqK8oRVWceuhTnL46Ttb94ZIRfobKLzVbHtXDiniTClz5vCVJxsj8kq N/Lf8S4VikUJimfluy87YjQZPpFTKaw2X7h15KvtJ71DGrkfq7Un3y+UNPwUxf3cvHgO r7jjSu6NJSBVQMkT1KQ/rodKm2ThNPAJ9hB2/Nw2IYEvsy4rg+SShkZVWc4Asai76mrX 4/yA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=pHpyG4WfT/ESTmbwbIkbXBNraX1Zgl2dDx7CU8k6m2U=; b=pzZcG7IwJ8qfymPz9aLRbKjKbg56fsyGnePfIwx4aGFPuK23uTGKSJH9/rlHkJxka1 7ebRnJssI76ItzGNWMOGptR3dn6cUa0T4yY3rkiG5ryS51wV4yqWGGulEhjO7riSTsx4 jTqQMtRXUBUIML+KSTOOgTX8EGppmIaCudhxKbbQsuwFfNZY8imR+L9LSAtOrS4G8lmr kZyyemhIH3LKCrSrakwPXLuj/cqPx3S/vYRkaCV7wszwib1fZp2ao2unqKdxIblR/b7R AxUmp9VOFJzEy71jAQS6XaVRF0fzq7dHxpx4TWycx1WYQzp31hZ8AtjkT27qsz3ES2Wt McDw== X-Gm-Message-State: AKGB3mIFeVKj95rH6VesBw5GSFbvVPDh2VGjsqFzeWKR/BmjpGFbx8l8 Qc5qU4gaWBO1FPl0495HX+OGWQ== X-Google-Smtp-Source: ACJfBouGDrmXswhdqW+5ujtvagkXK22Tx7yolKX77EBRAOBVkUW8zkbKRdgn7vMXSanZaonIZtGQOA== X-Received: by 10.25.219.145 with SMTP id t17mr10180490lfi.73.1513588704623; Mon, 18 Dec 2017 01:18:24 -0800 (PST) Received: from gilgamesh.semihalf.com (31-172-191-173.noc.fibertech.net.pl. [31.172.191.173]) by smtp.gmail.com with ESMTPSA id r16sm2407186ljd.18.2017.12.18.01.18.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 18 Dec 2017 01:18:23 -0800 (PST) From: Marcin Wojtas To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org Cc: davem@davemloft.net, linux@arm.linux.org.uk, rafael.j.wysocki@intel.com, andrew@lunn.ch, f.fainelli@gmail.com, antoine.tenart@free-electrons.com, thomas.petazzoni@free-electrons.com, gregory.clement@free-electrons.com, ezequiel.garcia@free-electrons.com, nadavh@marvell.com, neta@marvell.com, ard.biesheuvel@linaro.org, mw@semihalf.com, jaz@semihalf.com, tn@semihalf.com Subject: [net-next: PATCH 8/8] net: mvpp2: enable ACPI support in the driver Date: Mon, 18 Dec 2017 10:18:04 +0100 Message-Id: <1513588684-15647-9-git-send-email-mw@semihalf.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513588684-15647-1-git-send-email-mw@semihalf.com> References: <1513588684-15647-1-git-send-email-mw@semihalf.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This patch introduces an alternative way of obtaining resources - via ACPI tables provided by firmware. Enabling coexistence with the DT support, in addition to the OF_*->device_*/fwnode_* API replacement, required following steps to be taken: * Add mvpp2_acpi_match table * Omit clock configuration and obtain tclk from the property - in ACPI world, the firmware is responsible for clock maintenance. * Disable comphy and syscon handling as they are not available for ACPI. * Modify way of obtaining interrupts - with ACPI they are resources bound to struct platform_device and it's not possible to obtain them directly from the child node. Hence a formula is used, depending on the port_id and number of possible CPUs. Moreover when booting with ACPI MVPP2_QDIST_MULTI_MODE is picked by default, as there is no need to keep any kind of the backward compatibility. Signed-off-by: Marcin Wojtas --- drivers/net/ethernet/marvell/mvpp2.c | 130 +++++++++++++------- 1 file changed, 87 insertions(+), 43 deletions(-) diff --git a/drivers/net/ethernet/marvell/mvpp2.c b/drivers/net/ethernet/marvell/mvpp2.c index 4e61ce7..762a44e 100644 --- a/drivers/net/ethernet/marvell/mvpp2.c +++ b/drivers/net/ethernet/marvell/mvpp2.c @@ -10,6 +10,7 @@ * warranty of any kind, whether express or implied. */ +#include #include #include #include @@ -7477,7 +7478,8 @@ static int mvpp2_simple_queue_vectors_init(struct mvpp2_port *port, return 0; } -static int mvpp2_multi_queue_vectors_init(struct mvpp2_port *port, +static int mvpp2_multi_queue_vectors_init(struct platform_device *pdev, + struct mvpp2_port *port, struct device_node *port_node) { struct mvpp2_queue_vector *v; @@ -7510,7 +7512,11 @@ static int mvpp2_multi_queue_vectors_init(struct mvpp2_port *port, strncpy(irqname, "rx-shared", sizeof(irqname)); } - v->irq = of_irq_get_byname(port_node, irqname); + if (port_node) + v->irq = of_irq_get_byname(port_node, irqname); + else + v->irq = platform_get_irq(pdev, port->id * + (port->nqvecs + 2) + i); if (v->irq <= 0) { ret = -EINVAL; goto err; @@ -7528,11 +7534,12 @@ static int mvpp2_multi_queue_vectors_init(struct mvpp2_port *port, return ret; } -static int mvpp2_queue_vectors_init(struct mvpp2_port *port, +static int mvpp2_queue_vectors_init(struct platform_device *pdev, + struct mvpp2_port *port, struct device_node *port_node) { if (port->has_tx_irqs) - return mvpp2_multi_queue_vectors_init(port, port_node); + return mvpp2_multi_queue_vectors_init(pdev, port, port_node); else return mvpp2_simple_queue_vectors_init(port, port_node); } @@ -7753,7 +7760,7 @@ static int mvpp2_port_probe(struct platform_device *pdev, struct fwnode_handle *port_fwnode, struct mvpp2 *priv) { - struct phy *comphy; + struct phy *comphy = NULL; struct mvpp2_port *port; struct mvpp2_port_pcpu *port_pcpu; struct device_node *port_node = to_of_node(port_fwnode); @@ -7772,7 +7779,12 @@ static int mvpp2_port_probe(struct platform_device *pdev, if (!fwnode_device_is_available(port_fwnode)) return 0; - has_tx_irqs = mvpp2_port_has_tx_irqs(priv, port_node); + if (port_node) { + has_tx_irqs = mvpp2_port_has_tx_irqs(priv, port_node); + } else { + has_tx_irqs = true; + queue_mode = MVPP2_QDIST_MULTI_MODE; + } if (!has_tx_irqs) queue_mode = MVPP2_QDIST_SINGLE_MODE; @@ -7794,13 +7806,15 @@ static int mvpp2_port_probe(struct platform_device *pdev, goto err_free_netdev; } - comphy = devm_of_phy_get(&pdev->dev, port_node, NULL); - if (IS_ERR(comphy)) { - if (PTR_ERR(comphy) == -EPROBE_DEFER) { - err = -EPROBE_DEFER; - goto err_free_netdev; + if (port_node) { + comphy = devm_of_phy_get(&pdev->dev, port_node, NULL); + if (IS_ERR(comphy)) { + if (PTR_ERR(comphy) == -EPROBE_DEFER) { + err = -EPROBE_DEFER; + goto err_free_netdev; + } + comphy = NULL; } - comphy = NULL; } if (fwnode_property_read_u32(port_fwnode, "port-id", &id)) { @@ -7820,6 +7834,7 @@ static int mvpp2_port_probe(struct platform_device *pdev, port->nrxqs = nrxqs; port->priv = priv; port->has_tx_irqs = has_tx_irqs; + port->id = id; err = fwnode_property_get_reference_args(port_fwnode, "phy", NULL, 0, 0, &args); @@ -7832,11 +7847,16 @@ static int mvpp2_port_probe(struct platform_device *pdev, goto err_free_netdev; } - err = mvpp2_queue_vectors_init(port, port_node); + err = mvpp2_queue_vectors_init(pdev, port, port_node); if (err) goto err_free_netdev; - port->link_irq = of_irq_get_byname(port_node, "link"); + if (port_node) + port->link_irq = of_irq_get_byname(port_node, "link"); + else + port->link_irq = platform_get_irq(pdev, port->id * + (port->nqvecs + 2) + + port->nqvecs + 1); if (port->link_irq == -EPROBE_DEFER) { err = -EPROBE_DEFER; goto err_deinit_qvecs; @@ -7848,7 +7868,6 @@ static int mvpp2_port_probe(struct platform_device *pdev, if (fwnode_property_read_bool(port_fwnode, "marvell,loopback")) port->flags |= MVPP2_F_LOOPBACK; - port->id = id; if (priv->hw_version == MVPP21) port->first_rxq = port->id * port->nrxqs; else @@ -8218,6 +8237,7 @@ static int mvpp2_init(struct platform_device *pdev, struct mvpp2 *priv) static int mvpp2_probe(struct platform_device *pdev) { + const struct acpi_device_id *acpi_id; struct fwnode_handle *port_fwnode; struct mvpp2 *priv; struct resource *res; @@ -8229,8 +8249,14 @@ static int mvpp2_probe(struct platform_device *pdev) if (!priv) return -ENOMEM; - priv->hw_version = - (unsigned long)of_device_get_match_data(&pdev->dev); + if (has_acpi_companion(&pdev->dev)) { + acpi_id = acpi_match_device(pdev->dev.driver->acpi_match_table, + &pdev->dev); + priv->hw_version = (unsigned long)acpi_id->driver_data; + } else { + priv->hw_version = + (unsigned long)of_device_get_match_data(&pdev->dev); + } res = platform_get_resource(pdev, IORESOURCE_MEM, 0); base = devm_ioremap_resource(&pdev->dev, res); @@ -8247,7 +8273,9 @@ static int mvpp2_probe(struct platform_device *pdev) priv->iface_base = devm_ioremap_resource(&pdev->dev, res); if (IS_ERR(priv->iface_base)) return PTR_ERR(priv->iface_base); + } + if (priv->hw_version == MVPP22 && dev_of_node(&pdev->dev)) { priv->sysctrl_base = syscon_regmap_lookup_by_phandle(pdev->dev.of_node, "marvell,system-controller"); @@ -8273,32 +8301,34 @@ static int mvpp2_probe(struct platform_device *pdev) else priv->max_port_rxqs = 32; - priv->pp_clk = devm_clk_get(&pdev->dev, "pp_clk"); - if (IS_ERR(priv->pp_clk)) - return PTR_ERR(priv->pp_clk); - err = clk_prepare_enable(priv->pp_clk); - if (err < 0) - return err; - - priv->gop_clk = devm_clk_get(&pdev->dev, "gop_clk"); - if (IS_ERR(priv->gop_clk)) { - err = PTR_ERR(priv->gop_clk); - goto err_pp_clk; - } - err = clk_prepare_enable(priv->gop_clk); - if (err < 0) - goto err_pp_clk; + if (dev_of_node(&pdev->dev)) { + priv->pp_clk = devm_clk_get(&pdev->dev, "pp_clk"); + if (IS_ERR(priv->pp_clk)) + return PTR_ERR(priv->pp_clk); + err = clk_prepare_enable(priv->pp_clk); + if (err < 0) + return err; - if (priv->hw_version == MVPP22) { - priv->mg_clk = devm_clk_get(&pdev->dev, "mg_clk"); - if (IS_ERR(priv->mg_clk)) { - err = PTR_ERR(priv->mg_clk); - goto err_gop_clk; + priv->gop_clk = devm_clk_get(&pdev->dev, "gop_clk"); + if (IS_ERR(priv->gop_clk)) { + err = PTR_ERR(priv->gop_clk); + goto err_pp_clk; } - - err = clk_prepare_enable(priv->mg_clk); + err = clk_prepare_enable(priv->gop_clk); if (err < 0) - goto err_gop_clk; + goto err_pp_clk; + + if (priv->hw_version == MVPP22) { + priv->mg_clk = devm_clk_get(&pdev->dev, "mg_clk"); + if (IS_ERR(priv->mg_clk)) { + err = PTR_ERR(priv->mg_clk); + goto err_gop_clk; + } + + err = clk_prepare_enable(priv->mg_clk); + if (err < 0) + goto err_gop_clk; + } priv->axi_clk = devm_clk_get(&pdev->dev, "axi_clk"); if (IS_ERR(priv->axi_clk)) { @@ -8311,10 +8341,14 @@ static int mvpp2_probe(struct platform_device *pdev) if (err < 0) goto err_gop_clk; } - } - /* Get system's tclk rate */ - priv->tclk = clk_get_rate(priv->pp_clk); + /* Get system's tclk rate */ + priv->tclk = clk_get_rate(priv->pp_clk); + } else if (device_property_read_u32(&pdev->dev, "clock-frequency", + &priv->tclk)) { + dev_err(&pdev->dev, "missing clock-frequency value\n"); + return -EINVAL; + } if (priv->hw_version == MVPP22) { err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(40)); @@ -8418,6 +8452,9 @@ static int mvpp2_remove(struct platform_device *pdev) aggr_txq->descs_dma); } + if (is_acpi_node(port_fwnode)) + return 0; + clk_disable_unprepare(priv->axi_clk); clk_disable_unprepare(priv->mg_clk); clk_disable_unprepare(priv->pp_clk); @@ -8439,12 +8476,19 @@ static const struct of_device_id mvpp2_match[] = { }; MODULE_DEVICE_TABLE(of, mvpp2_match); +static const struct acpi_device_id mvpp2_acpi_match[] = { + { "MRVL0110", MVPP22 }, + { }, +}; +MODULE_DEVICE_TABLE(acpi, mvpp2_acpi_match); + static struct platform_driver mvpp2_driver = { .probe = mvpp2_probe, .remove = mvpp2_remove, .driver = { .name = MVPP2_DRIVER_NAME, .of_match_table = mvpp2_match, + .acpi_match_table = ACPI_PTR(mvpp2_acpi_match), }, };