From patchwork Sun Dec 31 11:58:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcin Wojtas X-Patchwork-Id: 854211 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="cTgMmBI8"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3z8f4W2fSBz9s84 for ; Sun, 31 Dec 2017 22:59:07 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751208AbdLaL64 (ORCPT ); Sun, 31 Dec 2017 06:58:56 -0500 Received: from mail-lf0-f66.google.com ([209.85.215.66]:38173 "EHLO mail-lf0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751027AbdLaL6y (ORCPT ); Sun, 31 Dec 2017 06:58:54 -0500 Received: by mail-lf0-f66.google.com with SMTP id w196so33886502lff.5 for ; Sun, 31 Dec 2017 03:58:53 -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=cTgMmBI8LZ4EMA75usO5nCl5aesSBfmhlyT0MBObXZJEgfSLCuDOMsa1PlT6l3kuae F3BYd3ClKAjS6QJVZWnfttj/s/0W0EMC19u2HywKd53+/2sZ5rL8tBsnqEErY01FG3vx vdc8Dx9ZMua5yyOZNRp7/sdRfRVLB7RascL5JOpESD8/RoFIspcaHZim+7+MKn+zL/37 Cq4/2uR+EwJuUeb53jHSra/VB+IB7JztUB5XVN1mzvmq5gaFO/Rr6oCaY0OCG+LrQAUJ DRAF7v/BD1OaePuL4RHuX1akLHU4uFpXJQpUd7AZGSWA31id4iAd3jZIrvXX5MXgfvWW ECqw== 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=YK4qck7QrhToHTpBugl7cdsb1DvLgI/+qM+ulz1ru5nhRir0Drx8msbp3SWKN7yyqj O8OEDEwaC9oT0WOJJIkHqy++73n00L60lSSKcrz4a6Lrz7zO0iV1ASCWzr+Bh/qbFovZ WjWgg9kcAu6VwbiRf5Y6Lxl8YW9qv+xGE/YDvS76H7WkgR49iXP6r+hJCXtvLgwNmhR+ dFa+qHe0JZRXUv5hm1kMhvBEBZvC1WCans90vXmEj4t0fN0Rhyga+q2+P0LCgnH8mOmI qcbF1viPEGMIZrr2PibfWLfM+zJW00hDes6GUPVvjKXJDB7OhKdAcs9JY0xGPxLVoy3F zFdQ== X-Gm-Message-State: AKGB3mLgaogCdYJ6Ns65YkIx3SnljqXzJrqcn77lQ0VEcjygG8ZhlvC5 TS+9RDW0hzFMbY9wFnh3jGTMdg== X-Google-Smtp-Source: ACJfBovaFnnJdKcRha90Fzkpnsslfljj8lTrq20m45DY4Li177M7Vu5ktW9YiDDYMLdpJNWCVYjPSQ== X-Received: by 10.46.42.130 with SMTP id q124mr23625247ljq.59.1514721532413; Sun, 31 Dec 2017 03:58:52 -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 f10sm8646298lff.56.2017.12.31.03.58.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 31 Dec 2017 03:58:51 -0800 (PST) From: Marcin Wojtas To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org, linux-acpi@vger.kernel.org Cc: graeme.gregory@linaro.org, davem@davemloft.net, linux@armlinux.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 v2 1/5] device property: Introduce fwnode_get_mac_address() Date: Sun, 31 Dec 2017 12:58:36 +0100 Message-Id: <1514721520-18964-2-git-send-email-mw@semihalf.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1514721520-18964-1-git-send-email-mw@semihalf.com> References: <1514721520-18964-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 Acked-by: Rafael J. Wysocki --- 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 Sun Dec 31 11:58:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcin Wojtas X-Patchwork-Id: 854216 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="Oswlm4Q7"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3z8f5n0Pwcz9s84 for ; Sun, 31 Dec 2017 23:00:13 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751348AbdLaMAK (ORCPT ); Sun, 31 Dec 2017 07:00:10 -0500 Received: from mail-lf0-f67.google.com ([209.85.215.67]:39354 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751029AbdLaL6z (ORCPT ); Sun, 31 Dec 2017 06:58:55 -0500 Received: by mail-lf0-f67.google.com with SMTP id m20so38718908lfi.6 for ; Sun, 31 Dec 2017 03:58:54 -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=Oswlm4Q7+hpomGDeCJRhxbhtS0gPidP5zdk3/HB/RWG8Y6Gm29igmyjx6fylRZQJTZ srSFZohdsz2148FuzJzmxH+k0dg0np4lb3Tr2FjMSwfNXeYcPKMvClZ+7LXRMTOvA4tI wh/OuQPWoB5yZQdWa2mIWW8PVM8ckr3No3Gbz1CNSVuf0eWqUBjcuRGUiWcj/6+hpAGY agPqno+JvODvM7g7SPN3IoubIlcPGAx4bWdDtYEBgcbWMDNfv8GjdHjF9Uvd3kJdN+o4 Nzq/kexuab1aAkULKQ3kcXOUh4wr95B+tos+hpAkpD3b5Ilygx5FelReDCL3FtNL73xC Hayg== 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=hwNtg4tOHNWZe+PueRZu1QFw0TWaa16bAzwLo58cO9gx8sRuOPnHazSm7s9mmm9jUf PL/BwVojF2iZi9D42VIrxS7JPf3y9Bs1yiKLDSy8mkQIBZyhScVbTtq31YKWKVdYq/xE KiEKIsCVwl1p1/gSAQju7sOHmnz1RWojE0s+8SPbPewsxjRkq2YP25C6MlQUUFTOknFj ZTdNzr325B6xz/y2zrVoUMSlm4kHcgQ+vL0oV9IX5QKZypqKAFJpfiG1my6leFoppahu A3DCBxpRFVnzJJUlt8ZW4YkcIi0hkjep5lrlG/OKRbKe9HAnwa5cn01AGgLKbVVM1Mli DMfQ== X-Gm-Message-State: AKGB3mLHBNd7ikKiKVPh+mP4cE6HRi/lAI2+JDJfWxgEtXOzMQYOK9e+ 6VBKq/froTlX3YMcQ5Z4ouffEg== X-Google-Smtp-Source: ACJfBoup7ovxMEtg8pxT9Oq62RjUTLmq0D2ixli9oupXGnQSxP0HkNZnW8aNGQbxnZjII4cdICn9zw== X-Received: by 10.46.46.3 with SMTP id u3mr1582856lju.117.1514721534220; Sun, 31 Dec 2017 03:58:54 -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 f10sm8646298lff.56.2017.12.31.03.58.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 31 Dec 2017 03:58:53 -0800 (PST) From: Marcin Wojtas To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org, linux-acpi@vger.kernel.org Cc: graeme.gregory@linaro.org, davem@davemloft.net, linux@armlinux.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 v2 2/5] device property: Introduce fwnode_get_phy_mode() Date: Sun, 31 Dec 2017 12:58:37 +0100 Message-Id: <1514721520-18964-3-git-send-email-mw@semihalf.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1514721520-18964-1-git-send-email-mw@semihalf.com> References: <1514721520-18964-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 Acked-by: Rafael J. Wysocki --- 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 Sun Dec 31 11:58:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcin Wojtas X-Patchwork-Id: 854215 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="VAkoICC9"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3z8f5b0YzBz9s84 for ; Sun, 31 Dec 2017 23:00:03 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751319AbdLaL7u (ORCPT ); Sun, 31 Dec 2017 06:59:50 -0500 Received: from mail-lf0-f65.google.com ([209.85.215.65]:42554 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751211AbdLaL65 (ORCPT ); Sun, 31 Dec 2017 06:58:57 -0500 Received: by mail-lf0-f65.google.com with SMTP id e27so17000660lfb.9 for ; Sun, 31 Dec 2017 03:58:56 -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=VAkoICC90FJF9qQGyglNRrmGJrBPLe7DQGEIa5kjRt2H7h7OK5w6Oavs0Y+II9JzOA N6YpOegY3udbDVfeyHZCdq3/hEZQDWLLzxOjfujlAfeAVbUAtJAx5aPIjtW17jAmvtMy PBowIAWSNIwmNE98bh0tpNt1VOjRtVY82kNprFOPJSnPctPwd2agd50MnAu77hyi6/LW p4DsGRIsemPiY9P21sqTG7KDtY04CKWn0exRwUbbMbdg7ucObs7HJ5JVdytqx6dljGES xaFs/Y5kPrf0rDYz1JeJvQo0q35ciSSUrX4Bjt33SQl/w49Le0/kUs0JYzHvKfCFvrhk xxzg== 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=IX2SST1rg9iJcPrz7AnUecbYe3cU6BxMv/QRshnqLu0NzHSK8L4Q5XGlE1Skwi97xE iB9CZiZINH5sa5W3Ir/qKM7J8EvnEbYEqJNNejtmpFz0/w8z4CfRW0I5aurPifoOwY/d XVlMQOgOolfCvvyqiIVD22UeXNrPPomyST1VGEfhxNZXM0V0ddC3EqsVpL88x6K7O5gg ThQ3kLCyPOyX7poiu7w/CzTvufZ9OQ7zK5lQql5YyP9HNpyBtTAfMoNLzwEGKfbinf6E AIfD8oBgxDTKjCc3ejhoRlA2hCDvdurGnNAHS6KdTm8HOmdnvxzJbzjw2HZtcP4NESIx edPw== X-Gm-Message-State: AKGB3mLWJExnKKC1GAsX5ErKVMiLIHxpbyEl4fseLQ7d0z9xSYZ89ppV HVjI1XtahY0lyANdp77cKFJZNA== X-Google-Smtp-Source: ACJfBouN5s5A5VwUFxumBWQbquurB+WyQ+7nIEA0qBZA1ptQoDwxrAn4/E25EnMFxbd6+FXAd6Ekgw== X-Received: by 10.46.14.9 with SMTP id 9mr25023108ljo.148.1514721535770; Sun, 31 Dec 2017 03:58:55 -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 f10sm8646298lff.56.2017.12.31.03.58.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 31 Dec 2017 03:58:55 -0800 (PST) From: Marcin Wojtas To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org, linux-acpi@vger.kernel.org Cc: graeme.gregory@linaro.org, davem@davemloft.net, linux@armlinux.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 v2 3/5] net: mvpp2: simplify maintaining enabled ports' list Date: Sun, 31 Dec 2017 12:58:38 +0100 Message-Id: <1514721520-18964-4-git-send-email-mw@semihalf.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1514721520-18964-1-git-send-email-mw@semihalf.com> References: <1514721520-18964-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 Sun Dec 31 11:58:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcin Wojtas X-Patchwork-Id: 854214 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="tCm2hlwc"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3z8f5D2pW0z9s84 for ; Sun, 31 Dec 2017 22:59:44 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751316AbdLaL7l (ORCPT ); Sun, 31 Dec 2017 06:59:41 -0500 Received: from mail-lf0-f68.google.com ([209.85.215.68]:44306 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751040AbdLaL66 (ORCPT ); Sun, 31 Dec 2017 06:58:58 -0500 Received: by mail-lf0-f68.google.com with SMTP id g63so29781663lfl.11 for ; Sun, 31 Dec 2017 03:58:58 -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=tCm2hlwcU69FIQnaPK67K7ljfleRDk94OtY09iSA2qWoReaVP3w1oOMO9QsyTMMFaY KfTMM9n0D02aDkyk2UwqvH+Ma1CKIeol+jh7K2ZIz206SORopwCR1dfFQlgBpgDMaY0u 3rHrhUPp58CecL1zyN4IXGGfeRj/GqsxoidMG9R54B4oAKBXw5UHPLJVdgmkx8IhDmc6 /YWrSFP/7BkjdyUWV7vUGIm5vYp2IbtoBy6aIHBHIfUeUaAYJPIkIeWtUUBpVXs6cuaL +md4yw8MTmuVY8LttiK0DLZDA2ESmrocNDh3ezl4sXzkKbDi91GHTdZG+59dj5RssUNj iKqw== 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=UuSL2wSq6njPRITwGl3yh6YdbmywZsuBJ2ZZ3HoXsr6KdGWiQDEuq86+gHNJdTbpQi BuZLOCiCSFqylfQVvs+I9sv73YU0f/vLPpaOkeJw0BpicW9m/wkjIfrn0M4H3nDpLMeL PyrLCBmXGnDl/mPdRsie0raBsVmoUUkDpJFVPrk2rYctib//gUZhM8Tg09G+JLTzl3IR +ryBRvRys4P5HK/XWUXzBR8oJ0ND6rIAh3K+gkhQRc7g2JCZghI1IzJk6KoiCGVwEqoS 4+BUXNey7UI6/Aa1/54Jt8vpCtxf0ltV4EnwDd60vzh9/7wCeiOEMnzj63lFPx/pBjAJ Xlkg== X-Gm-Message-State: AKGB3mK4zpHD+Mcbxr3Jms55GNvmoLEbGTVeVVPnlgVwI8L3ZUb5pxyp VSg6D65eBM7iIxkXF9x1FEaavQ== X-Google-Smtp-Source: ACJfBotBLKhe9M6ScI6nPs4EG2VZOWyq6l/x594KvsVtGDvoED03JWAig4TvXmT8VHBHX64KpMzhWw== X-Received: by 10.25.115.194 with SMTP id h63mr20847698lfk.79.1514721537293; Sun, 31 Dec 2017 03:58:57 -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 f10sm8646298lff.56.2017.12.31.03.58.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 31 Dec 2017 03:58:56 -0800 (PST) From: Marcin Wojtas To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org, linux-acpi@vger.kernel.org Cc: graeme.gregory@linaro.org, davem@davemloft.net, linux@armlinux.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 v2 4/5] net: mvpp2: use device_*/fwnode_* APIs instead of of_* Date: Sun, 31 Dec 2017 12:58:39 +0100 Message-Id: <1514721520-18964-5-git-send-email-mw@semihalf.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1514721520-18964-1-git-send-email-mw@semihalf.com> References: <1514721520-18964-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 Sun Dec 31 11:58:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcin Wojtas X-Patchwork-Id: 854212 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="vo/VUkZX"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3z8f4s66ZCz9s84 for ; Sun, 31 Dec 2017 22:59:25 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751305AbdLaL7V (ORCPT ); Sun, 31 Dec 2017 06:59:21 -0500 Received: from mail-lf0-f68.google.com ([209.85.215.68]:42561 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751257AbdLaL7A (ORCPT ); Sun, 31 Dec 2017 06:59:00 -0500 Received: by mail-lf0-f68.google.com with SMTP id e27so17000719lfb.9 for ; Sun, 31 Dec 2017 03:58:59 -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=s750rsCdY1tkV0gmkScDPbtZWFQw4g7zBXXk8/Uywew=; b=vo/VUkZXE9bfyJ/0k1sz7akDApyH7vrHGBgSA70Alf/27LgSGub8lG5CrAMabI0KR2 wPNw6D3Tg/FPqqenLmcUzU88rd1YL6cCwroqgeJtvw/hbLhERh3VWHru2OZ6mS0WN0WL A+dzDotIB8Xm+Af1dYemHMQzx4hq7p+LavqYhlHf15nj0bryUxvSn8ZRowZbiV19+1F4 XIFHCpn4WbLtdHi2UoatvwYKeAU6d4f0DJ1gcmweCr08B4VvUjYHA/+oQ1DkskvRArWw 92fWFKC52FrgDwLRj6Sy+pgPVCy9O0gPDRN2mEPcXOF++CoV1N1JTN9uQn6bNCoxIdWc EMVQ== 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=s750rsCdY1tkV0gmkScDPbtZWFQw4g7zBXXk8/Uywew=; b=GYKfadQA6yza5mg2FbHx6VNnjUaHeN4GPyhDo8Jm2yKNFR9dOESpZhh0C+tAYtxRV8 fJxfzRDqdrKk/FUHxvOpOh8HfCtqQw/9n8IMW19mnjVK84Aef6idMTW0B7pUYMErsapD BADCgXShUWPbrQyB+1A+e+S+CCXgEpH9Tn3lsVuv+KIFqD+8QLv5g5h5QSonGZV+N1VV 6EJXfoxz16okIWR6oa4HGfhbvU3SEIMmSlu1khpiQPgYdHJE207WoQHRyP6xCDVOggIA iQrNZLqPhZbQF0h13y02x2ArRkOX6MtNsPA2bAOQ6W+SpT62jC///5aSPrqg/AGOCc3t X7jw== X-Gm-Message-State: AKGB3mLgJrmpVhuMH0jRm1yc8+bw/tNT0ftOTFbcXH5BmhMo4palenc2 FSAz/JNbghflrcuyVGsP9Wuv/Q== X-Google-Smtp-Source: ACJfBovTO6LaVRURQb7/tlUomd651UB8SAH3e6hC2aaT59Na3pLsKG7YHY6OTG6veerSyrMHpSQRsQ== X-Received: by 10.25.56.68 with SMTP id d4mr16227282lfj.31.1514721538848; Sun, 31 Dec 2017 03:58:58 -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 f10sm8646298lff.56.2017.12.31.03.58.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 31 Dec 2017 03:58:58 -0800 (PST) From: Marcin Wojtas To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org, linux-acpi@vger.kernel.org Cc: graeme.gregory@linaro.org, davem@davemloft.net, linux@armlinux.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 v2 5/5] net: mvpp2: enable ACPI support in the driver Date: Sun, 31 Dec 2017 12:58:40 +0100 Message-Id: <1514721520-18964-6-git-send-email-mw@semihalf.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1514721520-18964-1-git-send-email-mw@semihalf.com> References: <1514721520-18964-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. * Until proper MDIO bus and PHY handling with ACPI is established in the kernel, use only link interrupts feature in the driver. * 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. Moreover, a memory region used by mvmdio driver is usually placed in the middle of the address space of the PP2 network controller. The MDIO base address is obtained without requesting memory region (by devm_ioremap() call) in mvmdio.c, later overlapping resources are requested by the network driver, which is responsible for avoiding a concurrent access. In case the MDIO memory region is declared in the ACPI, it can already appear as 'in-use' in the OS. Because it is overlapped by second region of the network controller, make sure it is released, before requesting it again. The care is taken by mvpp2 driver to avoid concurrent access to this memory region. Signed-off-by: Marcin Wojtas --- drivers/net/ethernet/marvell/mvpp2.c | 147 ++++++++++++++------ 1 file changed, 103 insertions(+), 44 deletions(-) diff --git a/drivers/net/ethernet/marvell/mvpp2.c b/drivers/net/ethernet/marvell/mvpp2.c index 537474f..8b1c9a3 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 @@ -7469,7 +7470,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; @@ -7502,7 +7504,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; @@ -7520,11 +7526,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); } @@ -7746,7 +7753,7 @@ static int mvpp2_port_probe(struct platform_device *pdev, struct mvpp2 *priv) { struct device_node *phy_node; - 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); @@ -7764,7 +7771,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; @@ -7779,7 +7791,11 @@ static int mvpp2_port_probe(struct platform_device *pdev, if (!dev) return -ENOMEM; - phy_node = of_parse_phandle(port_node, "phy", 0); + if (port_node) + phy_node = of_parse_phandle(port_node, "phy", 0); + else + phy_node = NULL; + phy_mode = fwnode_get_phy_mode(port_fwnode); if (phy_mode < 0) { dev_err(&pdev->dev, "incorrect phy mode\n"); @@ -7787,13 +7803,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)) { @@ -7813,12 +7831,18 @@ 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 = 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; @@ -7830,7 +7854,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 @@ -8201,6 +8224,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; @@ -8212,8 +8236,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); @@ -8227,10 +8257,23 @@ static int mvpp2_probe(struct platform_device *pdev) return PTR_ERR(priv->lms_base); } else { res = platform_get_resource(pdev, IORESOURCE_MEM, 1); + if (has_acpi_companion(&pdev->dev)) { + /* In case the MDIO memory region is declared in + * the ACPI, it can already appear as 'in-use' + * in the OS. Because it is overlapped by second + * region of the network controller, make + * sure it is released, before requesting it again. + * The care is taken by mvpp2 driver to avoid + * concurrent access to this memory region. + */ + release_resource(res); + } 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"); @@ -8256,32 +8299,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)) { @@ -8294,10 +8339,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)); @@ -8401,6 +8450,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); @@ -8422,12 +8474,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), }, };