From patchwork Mon Dec 31 15:25:41 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Mohr X-Patchwork-Id: 208871 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 973DB2C00A9 for ; Tue, 1 Jan 2013 02:35:03 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751476Ab2LaPe6 (ORCPT ); Mon, 31 Dec 2012 10:34:58 -0500 Received: from rhlx01.hs-esslingen.de ([129.143.116.10]:54116 "EHLO rhlx01.hs-esslingen.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751327Ab2LaPeo (ORCPT ); Mon, 31 Dec 2012 10:34:44 -0500 Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by rhlx01.hs-esslingen.de (Postfix) with ESMTPS id EB18FA11AF; Mon, 31 Dec 2012 16:25:52 +0100 (CET) From: Andreas Mohr To: andim2@users.sf.net Cc: Roger Luethi , netdev@vger.kernel.org, Francois Romieu Subject: [PATCH RFC 07/15] via-rhine: MMIO: move register verify into helper function. Date: Mon, 31 Dec 2012 16:25:41 +0100 Message-Id: <1356967549-5056-8-git-send-email-andi@lisas.de> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1356967549-5056-1-git-send-email-andi@lisas.de> References: <1356967549-5056-1-git-send-email-andi@lisas.de> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Andreas Mohr Add mmio_verify_registers() function. Gets rid of a useless USE_MMIO define section, too. Reverse logging of MMIO vs. PIO values since the description suggests different order. Signed-off-by: Andreas Mohr --- drivers/net/ethernet/via/via-rhine.c | 49 +++++++++++++++++++-------------- 1 files changed, 28 insertions(+), 21 deletions(-) diff --git a/drivers/net/ethernet/via/via-rhine.c b/drivers/net/ethernet/via/via-rhine.c index 053375b..a16e227 100644 --- a/drivers/net/ethernet/via/via-rhine.c +++ b/drivers/net/ethernet/via/via-rhine.c @@ -338,14 +338,6 @@ enum bcr1_bits { BCR1_MED1=0x80, /* for VT6102 */ }; -#ifdef USE_MMIO -/* Registers we check that mmio and reg are the same. */ -static const int mmio_verify_registers[] = { - RxConfig, TxConfig, IntrEnable, ConfigA, ConfigB, ConfigC, ConfigD, - 0 -}; -#endif - /* Bits in the interrupt status/mask registers. */ enum intr_status_bits { IntrRxDone = 0x0001, @@ -659,6 +651,31 @@ static void enable_mmio(long pioaddr, u32 quirks) outb(n, pioaddr + ConfigD); } } +/* Check that selected MMIO registers match the PIO ones */ +static inline bool +mmio_verify_registers(struct pci_dev *pdev, long pioaddr, void __iomem *ioaddr) +{ + /* Registers we check to verify that mmio and reg are the same. */ + static const int registers_to_verify[] = { + RxConfig, TxConfig, IntrEnable, + ConfigA, ConfigB, ConfigC, ConfigD, + 0 + }; + + int i = 0; + while (registers_to_verify[i]) { + int reg = registers_to_verify[i++]; + unsigned char pio = inb(pioaddr+reg); + unsigned char mmio = readb(ioaddr+reg); + if (pio != mmio) { + dev_err(&pdev->dev, + "MMIO do not match PIO [%02x] (%02x != %02x)\n", + reg, mmio, pio); + return false; + } + } + return true; +} #endif /* @@ -969,19 +986,9 @@ static int rhine_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) #ifdef USE_MMIO enable_mmio(rp->pioaddr, rp->quirks); - /* Check that selected MMIO registers match the PIO ones */ - i = 0; - while (mmio_verify_registers[i]) { - int reg = mmio_verify_registers[i++]; - unsigned char a = inb(pioaddr+reg); - unsigned char b = readb(ioaddr+reg); - if (a != b) { - rc = -EIO; - dev_err(&pdev->dev, - "MMIO do not match PIO [%02x] (%02x != %02x)\n", - reg, a, b); - goto err_out_unmap; - } + if (!mmio_verify_registers(pdev, pioaddr, ioaddr)) { + rc = -EIO; + goto err_out_unmap; } #endif /* USE_MMIO */