Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 908B9C433F5 for ; Wed, 13 Apr 2022 02:17:56 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8359283E55; Wed, 13 Apr 2022 04:16:33 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1649816193; bh=4oyGip8+AgDOFSFj8sqS2M40PAhgDB0rgh81lagxORA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=KbOUERslHNXNVSjh35+8ha6mo4s0S1Pd/BnrrZL5VWqoEHyOrNBoI9XjgbnTMv+jr cZAzxre/mhlJz4GXw8F0AEUPOWipxEIU0ml9NrA/zrrJAk2kmrWBvs/S96V9koWfD6 KKM7TjxqGeDwflyNFWNLYDSdkE9uYB0zr1vmxLSF9O3GTYVvLp2BkVT4xITfjt+nTr jdJTpaMi9ZvxTfM5vKMjwtz+OxRXZNelF+/iD1Smrwx5FMR214b1dxN550kQSTNWlp vLkMuVCM/VOSWfOX1rQiHUzpCevrkM7IMTWb3f158XkYQAwXtuhyWWBrkKiEXJwuxx W9RgOb5Jk/YMQ== Received: from tr.lan (ip-86-49-12-201.net.upcbroadband.cz [86.49.12.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 8623E83D05; Wed, 13 Apr 2022 04:16:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1649816163; bh=4oyGip8+AgDOFSFj8sqS2M40PAhgDB0rgh81lagxORA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JkyIHDRJzwoSxJ5ihnduxhlM6Q0u3OnyzKGWpxTfgRqv4K8/vduAC0nOr4CyR7FMy oow3qmz2MPEhUm6mMGvQWp8o+VA21BsFFmNPrkoXVj8Ze1rRdoJp147b4f+/itkp4q /MKjFEgu+p9ei1zZ79Gs3/iko+puSk5JwdMHHEbshTHFeAxk+UD5qMIdZWknEV11uY n/7WsE2lOze710Zd0ebDem3lQyeRuB28OSfRggHrP2hNE9feai83F6xwQ5/NAQsm+i oxEk9dqoZjUNlaABNRnOe45ahUinT2A9MCs4dXspZW6WnXV/cmXNC/7wpifPRgquST Br8aSqaeuo5KQ== From: Marek Vasut To: u-boot@lists.denx.de Cc: Marek Vasut , Ramon Fried , Joe Hershberger Subject: [PATCH v2 13/17] net: dm9000: Split non-DM specific bits from common code Date: Wed, 13 Apr 2022 04:15:35 +0200 Message-Id: <20220413021539.454331-13-marex@denx.de> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220413021539.454331-1-marex@denx.de> References: <20220413021539.454331-1-marex@denx.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean Split network handling functions into non-DM specific parts and common code in preparation for conversion to DM. Reviewed-by: Ramon Fried Signed-off-by: Marek Vasut Cc: Joe Hershberger Cc: Ramon Fried --- V2: - Add RB from Ramon - Ignore return value of dm9000_halt_common(), the function is static void dm9000_halt_common(struct dm9000_priv *db) so it returns nothing. Fix dm9000_halt() function prototype. --- drivers/net/dm9000x.c | 58 +++++++++++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 18 deletions(-) diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c index a40e60bbe61..639977ad6e6 100644 --- a/drivers/net/dm9000x.c +++ b/drivers/net/dm9000x.c @@ -311,9 +311,8 @@ static void dm9000_reset(struct dm9000_priv *db) } /* Initialize dm9000 board */ -static int dm9000_init(struct eth_device *dev, struct bd_info *bd) +static int dm9000_init_common(struct dm9000_priv *db, u8 enetaddr[6]) { - struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev); int i, oft, lnk; u8 io_mode; @@ -371,13 +370,13 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd) /* Clear interrupt status */ dm9000_iow(db, DM9000_ISR, ISR_ROOS | ISR_ROS | ISR_PTS | ISR_PRS); - printf("MAC: %pM\n", dev->enetaddr); - if (!is_valid_ethaddr(dev->enetaddr)) + printf("MAC: %pM\n", enetaddr); + if (!is_valid_ethaddr(enetaddr)) printf("WARNING: Bad MAC address (uninitialized EEPROM?)\n"); /* fill device MAC address registers */ for (i = 0, oft = DM9000_PAR; i < 6; i++, oft++) - dm9000_iow(db, oft, dev->enetaddr[i]); + dm9000_iow(db, oft, enetaddr[i]); for (i = 0, oft = 0x16; i < 8; i++, oft++) dm9000_iow(db, oft, 0xff); @@ -430,9 +429,8 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd) * Hardware start transmission. * Send a packet to media from the upper layer. */ -static int dm9000_send(struct eth_device *dev, void *packet, int length) +static int dm9000_send_common(struct dm9000_priv *db, void *packet, int length) { - struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev); int tmo; dm9000_dump_packet(__func__, packet, length); @@ -471,10 +469,8 @@ static int dm9000_send(struct eth_device *dev, void *packet, int length) * Stop the interface. * The interface is stopped when it is brought. */ -static void dm9000_halt(struct eth_device *netdev) +static void dm9000_halt_common(struct dm9000_priv *db) { - struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev); - /* RESET device */ dm9000_phy_write(db, 0, 0x8000); /* PHY RESET */ dm9000_iow(db, DM9000_GPR, 0x01); /* Power-Down PHY */ @@ -485,9 +481,8 @@ static void dm9000_halt(struct eth_device *netdev) /* * Received a packet and pass to upper layer */ -static int dm9000_rx(struct eth_device *dev) +static int dm9000_recv_common(struct dm9000_priv *db) { - struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev); u8 rxbyte; u8 *rdptr = (u8 *)net_rx_packets[0]; u16 rxstatus, rxlen = 0; @@ -570,18 +565,45 @@ static void dm9000_read_srom_word(struct dm9000_priv *db, int offset, u8 *to) to[1] = dm9000_ior(db, DM9000_EPDRH); } -static void dm9000_get_enetaddr(struct eth_device *dev) +static void dm9000_get_enetaddr(struct dm9000_priv *db, u8 *enetaddr) { - struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev); int i; for (i = 0; i < 3; i++) - dm9000_read_srom_word(db, i, dev->enetaddr + (2 * i)); + dm9000_read_srom_word(db, i, enetaddr + (2 * i)); } #else -static void dm9000_get_enetaddr(struct eth_device *dev) {} +static void dm9000_get_enetaddr(struct dm9000_priv *db, u8 *enetaddr) {} #endif +static int dm9000_init(struct eth_device *dev, struct bd_info *bd) +{ + struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev); + + return dm9000_init_common(db, dev->enetaddr); +} + +static void dm9000_halt(struct eth_device *dev) +{ + struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev); + + dm9000_halt_common(db); +} + +static int dm9000_send(struct eth_device *dev, void *packet, int length) +{ + struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev); + + return dm9000_send_common(db, packet, length); +} + +static int dm9000_recv(struct eth_device *dev) +{ + struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev); + + return dm9000_recv_common(db); +} + int dm9000_initialize(struct bd_info *bis) { struct dm9000_priv *priv; @@ -597,12 +619,12 @@ int dm9000_initialize(struct bd_info *bis) priv->base_data = (void __iomem *)DM9000_DATA; /* Load MAC address from EEPROM */ - dm9000_get_enetaddr(&priv->dev); + dm9000_get_enetaddr(priv, dev->enetaddr); dev->init = dm9000_init; dev->halt = dm9000_halt; dev->send = dm9000_send; - dev->recv = dm9000_rx; + dev->recv = dm9000_recv; strcpy(dev->name, "dm9000"); eth_register(&priv->dev); -- 2.35.1