From patchwork Wed Sep 23 06:35:44 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 521594 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 5DAF8140187 for ; Wed, 23 Sep 2015 16:36:19 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=BiSYt0sE; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752273AbbIWGgA (ORCPT ); Wed, 23 Sep 2015 02:36:00 -0400 Received: from mail-la0-f41.google.com ([209.85.215.41]:33786 "EHLO mail-la0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752119AbbIWGf7 (ORCPT ); Wed, 23 Sep 2015 02:35:59 -0400 Received: by lahh2 with SMTP id h2so14483614lah.0; Tue, 22 Sep 2015 23:35:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=4azjl/FbjA/UtakJC9BOHQSWwCETtJYhu0cBS6TsPt4=; b=BiSYt0sEXfRyzCR+eH1lkDmALxJ7qvZdQocn/0jkyipW6ebRvFDSb1tv+ff7DB6xQ9 IcmQnIzyLOZlbBny04pDr/ktuWjS9ZolOSx4R1GT0E8GA9XLADkndknLtyXuTGoavx+I 98c/4A5gZv3wjrjWUA/4h2wRfjKO80lBiFwnIumLZKoFcOVBcf3IKFVQLV2F8TicUFT9 rlPbuD3R9CHv/ivbOBMXiqxFu3tRxe3FRKxqIqnllw0yv+THx+8oKqrKw86I58iUiY2l vCDq71RRnILw0F8UhGnL20JGw9U+ZzVEZbnvMU+tlBKIxmge/TLN/2ieQz2U4rZ3X/1g SQ8w== X-Received: by 10.152.27.9 with SMTP id p9mr1903142lag.118.1442990157090; Tue, 22 Sep 2015 23:35:57 -0700 (PDT) Received: from octofox.metropolis ([5.19.183.212]) by smtp.gmail.com with ESMTPSA id ql6sm239868lbb.0.2015.09.22.23.35.56 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 Sep 2015 23:35:56 -0700 (PDT) From: Max Filippov To: netdev@vger.kernel.org Cc: "David S. Miller" , linux-kernel@vger.kernel.org, Max Filippov Subject: [PATCH v2] net/ethoc: support big-endian register layout Date: Wed, 23 Sep 2015 09:35:44 +0300 Message-Id: <1442990144-13499-1-git-send-email-jcmvbkbc@gmail.com> X-Mailer: git-send-email 1.8.1.4 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This allows using OpenCores ethernet controller attached to its host in native-endian mode with bi-endian CPUs. Example of such system is Xtensa XTFPGA platform. Signed-off-by: Max Filippov --- Changes v1->v2: - expand changelog with motivation for the change. drivers/net/ethernet/ethoc.c | 14 ++++++++++++-- include/net/ethoc.h | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/ethoc.c b/drivers/net/ethernet/ethoc.c index 442410c..17ff9a4 100644 --- a/drivers/net/ethernet/ethoc.c +++ b/drivers/net/ethernet/ethoc.c @@ -201,6 +201,7 @@ struct ethoc { void __iomem *membase; int dma_alloc; resource_size_t io_region_size; + bool big_endian; unsigned int num_bd; unsigned int num_tx; @@ -236,12 +237,18 @@ struct ethoc_bd { static inline u32 ethoc_read(struct ethoc *dev, loff_t offset) { - return ioread32(dev->iobase + offset); + if (dev->big_endian) + return ioread32be(dev->iobase + offset); + else + return ioread32(dev->iobase + offset); } static inline void ethoc_write(struct ethoc *dev, loff_t offset, u32 data) { - iowrite32(data, dev->iobase + offset); + if (dev->big_endian) + iowrite32be(data, dev->iobase + offset); + else + iowrite32(data, dev->iobase + offset); } static inline void ethoc_read_bd(struct ethoc *dev, int index, @@ -1106,6 +1113,9 @@ static int ethoc_probe(struct platform_device *pdev) priv->dma_alloc = buffer_size; } + priv->big_endian = pdata ? pdata->big_endian : + of_device_is_big_endian(pdev->dev.of_node); + /* calculate the number of TX/RX buffers, maximum 128 supported */ num_bd = min_t(unsigned int, 128, (netdev->mem_end - netdev->mem_start + 1) / ETHOC_BUFSIZ); diff --git a/include/net/ethoc.h b/include/net/ethoc.h index 2a2d6bb..bb7f467 100644 --- a/include/net/ethoc.h +++ b/include/net/ethoc.h @@ -17,6 +17,7 @@ struct ethoc_platform_data { u8 hwaddr[IFHWADDRLEN]; s8 phy_id; u32 eth_clkfreq; + bool big_endian; }; #endif /* !LINUX_NET_ETHOC_H */