From patchwork Thu Feb 27 15:26:03 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Harvey X-Patchwork-Id: 324841 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 301F22C00A3 for ; Fri, 28 Feb 2014 02:26:15 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751912AbaB0P0N (ORCPT ); Thu, 27 Feb 2014 10:26:13 -0500 Received: from mail-pa0-f43.google.com ([209.85.220.43]:44291 "EHLO mail-pa0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751155AbaB0P0M (ORCPT ); Thu, 27 Feb 2014 10:26:12 -0500 Received: by mail-pa0-f43.google.com with SMTP id rd3so2627092pab.2 for ; Thu, 27 Feb 2014 07:26:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id; bh=RUGt1cRY1pmkbTHEsdGQgoeUlnnOR5zt+ZvOIZOaZls=; b=CEVwED1jtcU97y2qLo+mCFixSazfK1xMczpxLmIQJTtndBII8SRRXKIvKhCC3GYeaI pSXH7V+oGFvjv11CH4HKq4okbPXPPOmefnZH1YRMwwlRTDTnW1ABuG0dkD4KiN/pUN5Y cROaRQCI3r1kCqCUyxUQj47IPwcUX635daRrufTz6T0+X7wcw6D1RGguH0hz4WM0nu0U ho5f/A9WnXOfxKA52W44khfoBwOASAWdq3+t2hBOuzJ67zkarDfIQi1X502DZwmL1AnL skCAur6nub4r0ESYSw0V8uoeHPoawBZZD/VG3G3CzsL6MUoE9cTSRliPucJsSs2jApWh y9DQ== X-Gm-Message-State: ALoCoQmPpVweBAcZIaijWe1n9ALkCp5/Jp52/EmJn2vaSAV65lC4I7cykyLPJyHG7pHMfh6wQYnp X-Received: by 10.68.227.4 with SMTP id rw4mr13909292pbc.3.1393514771994; Thu, 27 Feb 2014 07:26:11 -0800 (PST) Received: from localhost.localdomain (68-189-91-139.static.snlo.ca.charter.com. [68.189.91.139]) by mx.google.com with ESMTPSA id yz5sm33445070pac.9.2014.02.27.07.26.09 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 27 Feb 2014 07:26:10 -0800 (PST) From: Tim Harvey To: linux-pci@vger.kernel.org, devicetree@vger.kernel.org Subject: [RFC PATCH] sky2: allow mac to come from dt Date: Thu, 27 Feb 2014 07:26:03 -0800 Message-Id: <1393514763-8384-1-git-send-email-tharvey@gateworks.com> X-Mailer: git-send-email 1.8.3.2 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org The sky2 driver currently reads the mac address from the device registers which would need to have been programmed by the bootloader. This patch adds the ability to pull the mac from devicetree via the aliases/sky2 node. The RFC is because I'm not clear if there is a better way to reference the devicetree node for a PCI device from both the bootloader perspective and the driver perspective. Using an alias feels a bit like a hack. An example of a dts that describes a marvell,sky2 sitting on bus8 of the PCI bus is: aliases { sky2 = ð1; }; &pcie { eth1: sky2@8 { /* MAC/PHY on bus 8 */ compatible = "marvell,sky2"; }; }; Signed-off-by: Tim Harvey --- drivers/net/ethernet/marvell/sky2.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/marvell/sky2.c b/drivers/net/ethernet/marvell/sky2.c index 55a37ae..4165fc0 100644 --- a/drivers/net/ethernet/marvell/sky2.c +++ b/drivers/net/ethernet/marvell/sky2.c @@ -44,6 +44,8 @@ #include #include #include +#include +#include #include @@ -4748,6 +4750,7 @@ static struct net_device *sky2_init_netdev(struct sky2_hw *hw, unsigned port, { struct sky2_port *sky2; struct net_device *dev = alloc_etherdev(sizeof(*sky2)); + unsigned char *iap, tmpaddr[ETH_ALEN]; if (!dev) return NULL; @@ -4805,8 +4808,36 @@ static struct net_device *sky2_init_netdev(struct sky2_hw *hw, unsigned port, dev->features |= dev->hw_features; + /* + * try to get mac address in the following order: + * 1) from device tree data + * 2) from internal registers set by bootloader + */ + iap = NULL; + if (IS_ENABLED(CONFIG_OF)) { + struct device_node *np; + np = of_find_node_by_path("/aliases"); + if (np) { + const char *path = of_get_property(np, "sky2", NULL); + if (path) + np = of_find_node_by_path(path); + if (np) + path = of_get_mac_address(np); + if (path) + iap = (unsigned char *) path; + } + } + + /* + * 2) mac registers set by bootloader + */ + if (!iap || !is_valid_ether_addr(iap)) { + memcpy_fromio(&tmpaddr, hw->regs + B2_MAC_1 + port * 8, ETH_ALEN); + iap = &tmpaddr[0]; + } + /* read the mac address */ - memcpy_fromio(dev->dev_addr, hw->regs + B2_MAC_1 + port * 8, ETH_ALEN); + memcpy(dev->dev_addr, iap, ETH_ALEN); return dev; }