From patchwork Thu Dec 31 10:49:43 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike McCormack X-Patchwork-Id: 41963 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 972821007D1 for ; Thu, 31 Dec 2009 21:53:23 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752364AbZLaKxS (ORCPT ); Thu, 31 Dec 2009 05:53:18 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752356AbZLaKxS (ORCPT ); Thu, 31 Dec 2009 05:53:18 -0500 Received: from mail-px0-f189.google.com ([209.85.216.189]:44203 "EHLO mail-px0-f189.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752134AbZLaKxR (ORCPT ); Thu, 31 Dec 2009 05:53:17 -0500 Received: by pxi27 with SMTP id 27so7422088pxi.4 for ; Thu, 31 Dec 2009 02:53:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:sender:message-id:date:from :user-agent:mime-version:to:cc:subject:content-type :content-transfer-encoding; bh=n4TtNiKamVwWFJmg1LhtHcuCgV/YSE5KREGspD6o+Fk=; b=gHp2XWpWAP3xNxwM3HMQqaWpKiehEdxdE1z27LeWJsJpFKQ+0f16TXrV8rj7dBtQoJ eq7lw04oJYDPIEUJBK9ifzd1S6yXHW6iTI4LR6/5fBBolihSF3kG23L04d/xRt07S8jO GD8tAQ6oW+wkIsB4k4FlOj0tTp1t2PhbQo50M= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:message-id:date:from:user-agent:mime-version:to:cc:subject :content-type:content-transfer-encoding; b=uG8OU/y8nAFT8JO2GJEcjd19qGMqwO4H4C9aJ15t3Jag2Mk9sJXUtQ7opfCrqJ5D28 jEuTKCASuhOssAdYNxooR6nJ9B9ti4UTL4A0c3d2IycYaZRiwueXYlshBC2EoUICDQPt UpmIOgR8aQvHAQb5lpZFI913KzXAleeZ1zEC8= Received: by 10.142.67.32 with SMTP id p32mr13213563wfa.285.1262256795646; Thu, 31 Dec 2009 02:53:15 -0800 (PST) Received: from ?192.168.0.100? ([121.168.21.96]) by mx.google.com with ESMTPS id 20sm14258606pzk.5.2009.12.31.02.53.13 (version=SSLv3 cipher=RC4-MD5); Thu, 31 Dec 2009 02:53:14 -0800 (PST) Message-ID: <4B3C81C7.9040108@ring3k.org> Date: Thu, 31 Dec 2009 19:49:43 +0900 From: Mike McCormack User-Agent: Mozilla-Thunderbird 2.0.0.22 (X11/20090706) MIME-Version: 1.0 To: Stephen Hemminger , davem@davemloft.net CC: netdev@vger.kernel.org Subject: [PATCH] sky2: Refactor sky2_get_regs into two functions Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Hi Stephen, Dave, Apologies for the delay in resubmitting this with the sign-off (over a month). It still applies to the latest net-2.6 branch, so let me know if there's any objections.. thanks, Mike Subject: [PATCH] sky2: Refactor sky2_get_regs into two functions Separate code deciding which registers can be accessed out of sky2_get_regs in preparation for adding more conditions into it. Signed-off-by: Mike McCormack Signed-off-by: Stephen Hemminger --- drivers/net/sky2.c | 94 ++++++++++++++++++++++++++------------------------- 1 files changed, 48 insertions(+), 46 deletions(-) diff --git a/drivers/net/sky2.c b/drivers/net/sky2.c index 1c01b96..faa4841 100644 --- a/drivers/net/sky2.c +++ b/drivers/net/sky2.c @@ -3837,6 +3837,50 @@ static int sky2_get_regs_len(struct net_device *dev) return 0x4000; } +static int sky2_reg_access_ok(struct sky2_hw *hw, unsigned int b) +{ + /* This complicated switch statement is to make sure and + * only access regions that are unreserved. + * Some blocks are only valid on dual port cards. + */ + switch (b) { + /* second port */ + case 5: /* Tx Arbiter 2 */ + case 9: /* RX2 */ + case 14 ... 15: /* TX2 */ + case 17: case 19: /* Ram Buffer 2 */ + case 22 ... 23: /* Tx Ram Buffer 2 */ + case 25: /* Rx MAC Fifo 1 */ + case 27: /* Tx MAC Fifo 2 */ + case 31: /* GPHY 2 */ + case 40 ... 47: /* Pattern Ram 2 */ + case 52: case 54: /* TCP Segmentation 2 */ + case 112 ... 116: /* GMAC 2 */ + return hw->ports > 1; + + case 0: /* Control */ + case 2: /* Mac address */ + case 4: /* Tx Arbiter 1 */ + case 7: /* PCI express reg */ + case 8: /* RX1 */ + case 12 ... 13: /* TX1 */ + case 16: case 18:/* Rx Ram Buffer 1 */ + case 20 ... 21: /* Tx Ram Buffer 1 */ + case 24: /* Rx MAC Fifo 1 */ + case 26: /* Tx MAC Fifo 1 */ + case 28 ... 29: /* Descriptor and status unit */ + case 30: /* GPHY 1*/ + case 32 ... 39: /* Pattern Ram 1 */ + case 48: case 50: /* TCP Segmentation 1 */ + case 56 ... 60: /* PCI space */ + case 80 ... 84: /* GMAC 1 */ + return 1; + + default: + return 0; + } +} + /* * Returns copy of control register region * Note: ethtool_get_regs always provides full size (16k) buffer @@ -3851,55 +3895,13 @@ static void sky2_get_regs(struct net_device *dev, struct ethtool_regs *regs, regs->version = 1; for (b = 0; b < 128; b++) { - /* This complicated switch statement is to make sure and - * only access regions that are unreserved. - * Some blocks are only valid on dual port cards. - * and block 3 has some special diagnostic registers that - * are poison. - */ - switch (b) { - case 3: - /* skip diagnostic ram region */ + /* skip poisonous diagnostic ram region in block 3 */ + if (b == 3) memcpy_fromio(p + 0x10, io + 0x10, 128 - 0x10); - break; - - /* dual port cards only */ - case 5: /* Tx Arbiter 2 */ - case 9: /* RX2 */ - case 14 ... 15: /* TX2 */ - case 17: case 19: /* Ram Buffer 2 */ - case 22 ... 23: /* Tx Ram Buffer 2 */ - case 25: /* Rx MAC Fifo 1 */ - case 27: /* Tx MAC Fifo 2 */ - case 31: /* GPHY 2 */ - case 40 ... 47: /* Pattern Ram 2 */ - case 52: case 54: /* TCP Segmentation 2 */ - case 112 ... 116: /* GMAC 2 */ - if (sky2->hw->ports == 1) - goto reserved; - /* fall through */ - case 0: /* Control */ - case 2: /* Mac address */ - case 4: /* Tx Arbiter 1 */ - case 7: /* PCI express reg */ - case 8: /* RX1 */ - case 12 ... 13: /* TX1 */ - case 16: case 18:/* Rx Ram Buffer 1 */ - case 20 ... 21: /* Tx Ram Buffer 1 */ - case 24: /* Rx MAC Fifo 1 */ - case 26: /* Tx MAC Fifo 1 */ - case 28 ... 29: /* Descriptor and status unit */ - case 30: /* GPHY 1*/ - case 32 ... 39: /* Pattern Ram 1 */ - case 48: case 50: /* TCP Segmentation 1 */ - case 56 ... 60: /* PCI space */ - case 80 ... 84: /* GMAC 1 */ + else if (sky2_reg_access_ok(sky2->hw, b)) memcpy_fromio(p, io, 128); - break; - default: -reserved: + else memset(p, 0, 128); - } p += 128; io += 128;