From patchwork Tue Sep 27 11:14:31 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 116582 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 6EAE8B6F69 for ; Tue, 27 Sep 2011 21:14:45 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 2F28E2838C; Tue, 27 Sep 2011 13:14:42 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de 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 MXwV5887xNeh; Tue, 27 Sep 2011 13:14:41 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 4846328371; Tue, 27 Sep 2011 13:14:39 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 9B41428371 for ; Tue, 27 Sep 2011 13:14:37 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de 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 L-Q1icYYRaU1 for ; Tue, 27 Sep 2011 13:14:36 +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-bw0-f44.google.com (mail-bw0-f44.google.com [209.85.214.44]) by theia.denx.de (Postfix) with ESMTPS id 815862836F for ; Tue, 27 Sep 2011 13:14:34 +0200 (CEST) Received: by bkaq10 with SMTP id q10so6319791bka.3 for ; Tue, 27 Sep 2011 04:14:34 -0700 (PDT) Received: by 10.204.136.81 with SMTP id q17mr4967386bkt.105.1317122074330; Tue, 27 Sep 2011 04:14:34 -0700 (PDT) Received: from localhost ([178.23.216.97]) by mx.google.com with ESMTPS id d1sm24181401bku.1.2011.09.27.04.14.32 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 27 Sep 2011 04:14:33 -0700 (PDT) From: Michal Simek To: u-boot@lists.denx.de Date: Tue, 27 Sep 2011 13:14:31 +0200 Message-Id: <1317122071-10149-1-git-send-email-monstr@monstr.eu> X-Mailer: git-send-email 1.5.5.1 Subject: [U-Boot] [PATCH v2] net: emaclite: Use dynamic allocation X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.9 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de Every emaclite instance use own setting. Signed-off-by: Michal Simek Acked-by: Mike Frysinger --- v2: Free allocated space when private data allocation failed Based on git://git.denx.de/u-boot-microblaze.git emaclite branch --- drivers/net/xilinx_emaclite.c | 41 +++++++++++++++++++++++++---------------- 1 files changed, 25 insertions(+), 16 deletions(-) diff --git a/drivers/net/xilinx_emaclite.c b/drivers/net/xilinx_emaclite.c index 805da17..8e574cd 100644 --- a/drivers/net/xilinx_emaclite.c +++ b/drivers/net/xilinx_emaclite.c @@ -63,12 +63,10 @@ /* Recv interrupt enable bit */ #define XEL_RSR_RECV_IE_MASK 0x00000008UL -typedef struct { +struct xemaclite { u32 nexttxbuffertouse; /* Next TX buffer to write to */ u32 nextrxbuffertouse; /* Next RX buffer to read from */ -} xemaclite; - -static xemaclite emaclite; +}; static u32 etherrxbuff[PKTSIZE_ALIGN/4]; /* Receive buffer */ @@ -134,7 +132,6 @@ static void emaclite_halt(struct eth_device *dev) static int emaclite_init(struct eth_device *dev, bd_t *bis) { debug ("EmacLite Initialization Started\n"); - memset (&emaclite, 0, sizeof (xemaclite)); /* * TX - TX_PING & TX_PONG initialization @@ -180,22 +177,24 @@ static int emaclite_init(struct eth_device *dev, bd_t *bis) return 0; } -static int xemaclite_txbufferavailable (xemaclite *instanceptr) +static int xemaclite_txbufferavailable(struct eth_device *dev) { u32 reg; u32 txpingbusy; u32 txpongbusy; + struct xemaclite *emaclite = dev->priv; + /* * Read the other buffer register * and determine if the other buffer is available */ - reg = in_be32 (instanceptr->baseaddress + - instanceptr->nexttxbuffertouse + 0); + reg = in_be32 (dev->iobase + + emaclite->nexttxbuffertouse + 0); txpingbusy = ((reg & XEL_TSR_XMIT_BUSY_MASK) == XEL_TSR_XMIT_BUSY_MASK); - reg = in_be32 (instanceptr->baseaddress + - (instanceptr->nexttxbuffertouse ^ XEL_TSR_OFFSET) + 0); + reg = in_be32 (dev->iobase + + (emaclite->nexttxbuffertouse ^ XEL_TSR_OFFSET) + 0); txpongbusy = ((reg & XEL_TSR_XMIT_BUSY_MASK) == XEL_TSR_XMIT_BUSY_MASK); @@ -206,13 +205,14 @@ static int emaclite_send (struct eth_device *dev, volatile void *ptr, int len) { u32 reg; u32 baseaddress; + struct xemaclite *emaclite = dev->priv; u32 maxtry = 1000; if (len > ENET_MAX_MTU) len = ENET_MAX_MTU; - while (!xemaclite_txbufferavailable (&emaclite) && maxtry) { + while (!xemaclite_txbufferavailable(dev) && maxtry) { udelay (10); maxtry--; } @@ -229,7 +229,7 @@ static int emaclite_send (struct eth_device *dev, volatile void *ptr, int len) } /* Determine the expected TX buffer address */ - baseaddress = (dev->iobase + emaclite.nexttxbuffertouse); + baseaddress = (dev->iobase + emaclite->nexttxbuffertouse); /* Determine if the expected buffer address is empty */ reg = in_be32 (baseaddress + XEL_TSR_OFFSET); @@ -238,7 +238,7 @@ static int emaclite_send (struct eth_device *dev, volatile void *ptr, int len) & XEL_TSR_XMIT_ACTIVE_MASK) == 0)) { #ifdef CONFIG_XILINX_EMACLITE_TX_PING_PONG - emaclite.nexttxbuffertouse ^= XEL_BUFFER_OFFSET; + emaclite->nexttxbuffertouse ^= XEL_BUFFER_OFFSET; #endif debug ("Send packet from 0x%x\n", baseaddress); /* Write the frame to the buffer */ @@ -284,13 +284,14 @@ static int emaclite_recv(struct eth_device *dev) u32 length; u32 reg; u32 baseaddress; + struct xemaclite *emaclite = dev->priv; - baseaddress = dev->iobase + emaclite.nextrxbuffertouse; + baseaddress = dev->iobase + emaclite->nextrxbuffertouse; reg = in_be32 (baseaddress + XEL_RSR_OFFSET); debug ("Testing data at address 0x%x\n", baseaddress); if ((reg & XEL_RSR_RECV_DONE_MASK) == XEL_RSR_RECV_DONE_MASK) { #ifdef CONFIG_XILINX_EMACLITE_RX_PING_PONG - emaclite.nextrxbuffertouse ^= XEL_BUFFER_OFFSET; + emaclite->nextrxbuffertouse ^= XEL_BUFFER_OFFSET; #endif } else { #ifndef CONFIG_XILINX_EMACLITE_RX_PING_PONG @@ -343,15 +344,23 @@ static int emaclite_recv(struct eth_device *dev) int xilinx_emaclite_initialize (bd_t *bis, int base_addr) { struct eth_device *dev; + struct xemaclite *emaclite; dev = calloc(1, sizeof(*dev)); if (dev == NULL) return -1; + emaclite = calloc(1, sizeof(struct xemaclite)); + if (emaclite == NULL) { + free(dev); + return -1; + } + + dev->priv = emaclite; + sprintf(dev->name, "Xelite.%x", base_addr); dev->iobase = base_addr; - dev->priv = 0; dev->init = emaclite_init; dev->halt = emaclite_halt; dev->send = emaclite_send;