From patchwork Tue Aug 2 11:31:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 654683 X-Patchwork-Delegate: joe.hershberger@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 3s3Yw84hTdz9t50 for ; Tue, 2 Aug 2016 21:32:40 +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=jK4V9bCr; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A7963A760A; Tue, 2 Aug 2016 13:32:33 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id IFDd3MkDTjIK; Tue, 2 Aug 2016 13:32:33 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id B4078A75C3; Tue, 2 Aug 2016 13:32:25 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A7D79A74FB for ; Tue, 2 Aug 2016 13:32:17 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id OGiCOr75Mp7f for ; Tue, 2 Aug 2016 13:32:17 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-lf0-f65.google.com (mail-lf0-f65.google.com [209.85.215.65]) by theia.denx.de (Postfix) with ESMTPS id 6F10AA751E for ; Tue, 2 Aug 2016 13:32:13 +0200 (CEST) Received: by mail-lf0-f65.google.com with SMTP id l69so9777119lfg.1 for ; Tue, 02 Aug 2016 04:32:13 -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:in-reply-to:references; bh=Z8VM7x1FXgpWcqt0wF3bkUAadDvlrUuMJlicDAhP+ys=; b=jK4V9bCrInw4GUaZBaZ69FOV29nDY3Fo4VwymYzAfR5yzoBccM5ytxyAQ5I5J1vLi0 wIwEcQ1LqUssiEbvHkMOZW7okazg2GjvEU7qSp2TKKas8+D1P3fkRV3LQPiFLXCA8Rst o3Plj0VFMu6MqX1r5d2d9+YFH7dGqfEs5xFwWmlyjkb6QFuxVfw0Pugf2TmPywt6/QRy oHp0U6xZfkKYk9xAaL2iwK+4W7NZZaEtUztYMj40pSShgzjWahShdHcIyVkwhKtSMHjq Rdoij+9RYMqu0SV9ATXKmKrkbspifwwp7rfwOR/d5cv6Z4QZxBSdvdtA89lpxBCGiCOj K8tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Z8VM7x1FXgpWcqt0wF3bkUAadDvlrUuMJlicDAhP+ys=; b=Ti3Sm6mdkCUEzgC10gZv+yXJPUewYZOhyDCnZ5bio767sXtI106iRgxJHihUCRoLk0 wuVUzCttToAeS8BIAHrmjVPxIZempH6Q7K719n5WnCZe7OwMHU1ZgIPzR99UyieNTSmf ectjWh7W23LLsIW7w67Exw2Y+wcyhStqMfZn8U9K+Yh2WHkmQAeGDysskHvwAa8t3awL lfIK804N9cNr6NkKuQ3Yp0IHdLqFmItRc/wr/m2ys2Fyl3ruD7j6AH4wjuLBIcMTKdwr /EdPQ1QBIW1dW84PDku12TOlxZBxYvplNQN7hT3I+RvEpu5n6LEF93Y+LaZ3Jx05yQTP Qyzg== X-Gm-Message-State: AEkooutt5Z/luXeI3eWH/i7Eqm3wYQihy7Vwfdi4T8WjGMl3ENSKmJrUzs6HPA/ynlsUgw== X-Received: by 10.46.1.162 with SMTP id f34mr17559253lji.22.1470137532493; Tue, 02 Aug 2016 04:32:12 -0700 (PDT) Received: from octofox.metropolis ([5.19.183.212]) by smtp.gmail.com with ESMTPSA id f69sm417906lji.19.2016.08.02.04.32.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 02 Aug 2016 04:32:11 -0700 (PDT) From: Max Filippov To: u-boot@lists.denx.de Date: Tue, 2 Aug 2016 14:31:05 +0300 Message-Id: <1470137470-6051-3-git-send-email-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1470137470-6051-1-git-send-email-jcmvbkbc@gmail.com> References: <1470137470-6051-1-git-send-email-jcmvbkbc@gmail.com> Cc: Joe Hershberger Subject: [U-Boot] [PATCH 2/7] net/ethoc: use priv instead of dev internally X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Don't use physical base address of registers directly, ioremap it first. Save pointer in private struct ethoc and use that struct in all internal functions. Signed-off-by: Max Filippov Acked-by: Joe Hershberger --- drivers/net/ethoc.c | 111 ++++++++++++++++++++++++++-------------------------- 1 file changed, 56 insertions(+), 55 deletions(-) diff --git a/drivers/net/ethoc.c b/drivers/net/ethoc.c index edb3c80..f5bd1ab 100644 --- a/drivers/net/ethoc.c +++ b/drivers/net/ethoc.c @@ -12,11 +12,10 @@ */ #include -#include +#include #include #include #include -#include #include /* register offsets */ @@ -162,6 +161,7 @@ #define ETHOC_BD_BASE 0x400 #define ETHOC_TIMEOUT (HZ / 2) #define ETHOC_MII_TIMEOUT (1 + (HZ / 5)) +#define ETHOC_IOSIZE 0x54 /** * struct ethoc - driver-private device structure @@ -177,6 +177,7 @@ struct ethoc { u32 dty_tx; u32 num_rx; u32 cur_rx; + void __iomem *iobase; }; /** @@ -189,64 +190,64 @@ struct ethoc_bd { u32 addr; }; -static inline u32 ethoc_read(struct eth_device *dev, size_t offset) +static inline u32 ethoc_read(struct ethoc *priv, size_t offset) { - return readl(dev->iobase + offset); + return readl(priv->iobase + offset); } -static inline void ethoc_write(struct eth_device *dev, size_t offset, u32 data) +static inline void ethoc_write(struct ethoc *priv, size_t offset, u32 data) { - writel(data, dev->iobase + offset); + writel(data, priv->iobase + offset); } -static inline void ethoc_read_bd(struct eth_device *dev, int index, +static inline void ethoc_read_bd(struct ethoc *priv, int index, struct ethoc_bd *bd) { size_t offset = ETHOC_BD_BASE + (index * sizeof(struct ethoc_bd)); - bd->stat = ethoc_read(dev, offset + 0); - bd->addr = ethoc_read(dev, offset + 4); + bd->stat = ethoc_read(priv, offset + 0); + bd->addr = ethoc_read(priv, offset + 4); } -static inline void ethoc_write_bd(struct eth_device *dev, int index, +static inline void ethoc_write_bd(struct ethoc *priv, int index, const struct ethoc_bd *bd) { size_t offset = ETHOC_BD_BASE + (index * sizeof(struct ethoc_bd)); - ethoc_write(dev, offset + 0, bd->stat); - ethoc_write(dev, offset + 4, bd->addr); + ethoc_write(priv, offset + 0, bd->stat); + ethoc_write(priv, offset + 4, bd->addr); } static int ethoc_set_mac_address(struct eth_device *dev) { + struct ethoc *priv = (struct ethoc *)dev->priv; u8 *mac = dev->enetaddr; - ethoc_write(dev, MAC_ADDR0, (mac[2] << 24) | (mac[3] << 16) | + ethoc_write(priv, MAC_ADDR0, (mac[2] << 24) | (mac[3] << 16) | (mac[4] << 8) | (mac[5] << 0)); - ethoc_write(dev, MAC_ADDR1, (mac[0] << 8) | (mac[1] << 0)); + ethoc_write(priv, MAC_ADDR1, (mac[0] << 8) | (mac[1] << 0)); return 0; } -static inline void ethoc_ack_irq(struct eth_device *dev, u32 mask) +static inline void ethoc_ack_irq(struct ethoc *priv, u32 mask) { - ethoc_write(dev, INT_SOURCE, mask); + ethoc_write(priv, INT_SOURCE, mask); } -static inline void ethoc_enable_rx_and_tx(struct eth_device *dev) +static inline void ethoc_enable_rx_and_tx(struct ethoc *priv) { - u32 mode = ethoc_read(dev, MODER); + u32 mode = ethoc_read(priv, MODER); mode |= MODER_RXEN | MODER_TXEN; - ethoc_write(dev, MODER, mode); + ethoc_write(priv, MODER, mode); } -static inline void ethoc_disable_rx_and_tx(struct eth_device *dev) +static inline void ethoc_disable_rx_and_tx(struct ethoc *priv) { - u32 mode = ethoc_read(dev, MODER); + u32 mode = ethoc_read(priv, MODER); mode &= ~(MODER_RXEN | MODER_TXEN); - ethoc_write(dev, MODER, mode); + ethoc_write(priv, MODER, mode); } -static int ethoc_init_ring(struct eth_device *dev) +static int ethoc_init_ring(struct ethoc *priv) { - struct ethoc *priv = (struct ethoc *)dev->priv; struct ethoc_bd bd; int i; @@ -261,7 +262,7 @@ static int ethoc_init_ring(struct eth_device *dev) if (i == priv->num_tx - 1) bd.stat |= TX_BD_WRAP; - ethoc_write_bd(dev, i, &bd); + ethoc_write_bd(priv, i, &bd); } bd.stat = RX_BD_EMPTY | RX_BD_IRQ; @@ -272,35 +273,35 @@ static int ethoc_init_ring(struct eth_device *dev) bd.stat |= RX_BD_WRAP; flush_dcache_range(bd.addr, bd.addr + PKTSIZE_ALIGN); - ethoc_write_bd(dev, priv->num_tx + i, &bd); + ethoc_write_bd(priv, priv->num_tx + i, &bd); } return 0; } -static int ethoc_reset(struct eth_device *dev) +static int ethoc_reset(struct ethoc *priv) { u32 mode; /* TODO: reset controller? */ - ethoc_disable_rx_and_tx(dev); + ethoc_disable_rx_and_tx(priv); /* TODO: setup registers */ /* enable FCS generation and automatic padding */ - mode = ethoc_read(dev, MODER); + mode = ethoc_read(priv, MODER); mode |= MODER_CRC | MODER_PAD; - ethoc_write(dev, MODER, mode); + ethoc_write(priv, MODER, mode); /* set full-duplex mode */ - mode = ethoc_read(dev, MODER); + mode = ethoc_read(priv, MODER); mode |= MODER_FULLD; - ethoc_write(dev, MODER, mode); - ethoc_write(dev, IPGT, 0x15); + ethoc_write(priv, MODER, mode); + ethoc_write(priv, IPGT, 0x15); - ethoc_ack_irq(dev, INT_MASK_ALL); - ethoc_enable_rx_and_tx(dev); + ethoc_ack_irq(priv, INT_MASK_ALL); + ethoc_enable_rx_and_tx(priv); return 0; } @@ -311,9 +312,9 @@ static int ethoc_init(struct eth_device *dev, bd_t * bd) priv->num_tx = 1; priv->num_rx = PKTBUFSRX; - ethoc_write(dev, TX_BD_NUM, priv->num_tx); - ethoc_init_ring(dev); - ethoc_reset(dev); + ethoc_write(priv, TX_BD_NUM, priv->num_tx); + ethoc_init_ring(priv); + ethoc_reset(priv); return 0; } @@ -353,9 +354,8 @@ static int ethoc_update_rx_stats(struct ethoc_bd *bd) return ret; } -static int ethoc_rx(struct eth_device *dev, int limit) +static int ethoc_rx(struct ethoc *priv, int limit) { - struct ethoc *priv = (struct ethoc *)dev->priv; int count; for (count = 0; count < limit; ++count) { @@ -363,7 +363,7 @@ static int ethoc_rx(struct eth_device *dev, int limit) struct ethoc_bd bd; entry = priv->num_tx + (priv->cur_rx % priv->num_rx); - ethoc_read_bd(dev, entry, &bd); + ethoc_read_bd(priv, entry, &bd); if (bd.stat & RX_BD_EMPTY) break; @@ -379,7 +379,7 @@ static int ethoc_rx(struct eth_device *dev, int limit) flush_dcache_range(bd.addr, bd.addr + PKTSIZE_ALIGN); bd.stat &= ~RX_BD_STATS; bd.stat |= RX_BD_EMPTY; - ethoc_write_bd(dev, entry, &bd); + ethoc_write_bd(priv, entry, &bd); priv->cur_rx++; } @@ -403,13 +403,12 @@ static int ethoc_update_tx_stats(struct ethoc_bd *bd) return 0; } -static void ethoc_tx(struct eth_device *dev) +static void ethoc_tx(struct ethoc *priv) { - struct ethoc *priv = (struct ethoc *)dev->priv; u32 entry = priv->dty_tx % priv->num_tx; struct ethoc_bd bd; - ethoc_read_bd(dev, entry, &bd); + ethoc_read_bd(priv, entry, &bd); if ((bd.stat & TX_BD_READY) == 0) (void)ethoc_update_tx_stats(&bd); } @@ -423,7 +422,7 @@ static int ethoc_send(struct eth_device *dev, void *packet, int length) int tmo; entry = priv->cur_tx % priv->num_tx; - ethoc_read_bd(dev, entry, &bd); + ethoc_read_bd(priv, entry, &bd); if (unlikely(length < ETHOC_ZLEN)) bd.stat |= TX_BD_PAD; else @@ -433,22 +432,22 @@ static int ethoc_send(struct eth_device *dev, void *packet, int length) flush_dcache_range(bd.addr, bd.addr + length); bd.stat &= ~(TX_BD_STATS | TX_BD_LEN_MASK); bd.stat |= TX_BD_LEN(length); - ethoc_write_bd(dev, entry, &bd); + ethoc_write_bd(priv, entry, &bd); /* start transmit */ bd.stat |= TX_BD_READY; - ethoc_write_bd(dev, entry, &bd); + ethoc_write_bd(priv, entry, &bd); /* wait for transfer to succeed */ tmo = get_timer(0) + 5 * CONFIG_SYS_HZ; while (1) { - pending = ethoc_read(dev, INT_SOURCE); - ethoc_ack_irq(dev, pending & ~INT_MASK_RX); + pending = ethoc_read(priv, INT_SOURCE); + ethoc_ack_irq(priv, pending & ~INT_MASK_RX); if (pending & INT_MASK_BUSY) debug("%s(): packet dropped\n", __func__); if (pending & INT_MASK_TX) { - ethoc_tx(dev); + ethoc_tx(priv); break; } if (get_timer(0) >= tmo) { @@ -463,20 +462,21 @@ static int ethoc_send(struct eth_device *dev, void *packet, int length) static void ethoc_halt(struct eth_device *dev) { - ethoc_disable_rx_and_tx(dev); + ethoc_disable_rx_and_tx(dev->priv); } static int ethoc_recv(struct eth_device *dev) { + struct ethoc *priv = (struct ethoc *)dev->priv; u32 pending; - pending = ethoc_read(dev, INT_SOURCE); - ethoc_ack_irq(dev, pending); + pending = ethoc_read(priv, INT_SOURCE); + ethoc_ack_irq(priv, pending); if (pending & INT_MASK_BUSY) debug("%s(): packet dropped\n", __func__); if (pending & INT_MASK_RX) { debug("%s(): rx irq\n", __func__); - ethoc_rx(dev, PKTBUFSRX); + ethoc_rx(priv, PKTBUFSRX); } return 0; @@ -505,6 +505,7 @@ int ethoc_initialize(u8 dev_num, int base_addr) dev->recv = ethoc_recv; dev->write_hwaddr = ethoc_set_mac_address; sprintf(dev->name, "%s-%hu", "ETHOC", dev_num); + priv->iobase = ioremap(dev->iobase, ETHOC_IOSIZE); eth_register(dev); return 1;