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 12D6CC433F5 for ; Wed, 13 Apr 2022 02:17:24 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1DE3283E14; Wed, 13 Apr 2022 04:16:27 +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=1649816187; bh=mggso1ccoXzZTonKffJiUP7ZgGZZaMF23dnhqo2ogKE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=pm5UB8C/QrpZSDyazXLKNVwrEdx/SWz+tDge0I5hnFfXhb9XJ+C0M4k0EGzLvTmVp UMfxTYLYVdFh+s/0RcVTaF0iXA8g0HQxy8VUltLQqSQ0TtCEw7ncmXglaTsZndJjLH hXsACy79fE3GLR8n4gdUqd/+aL5Nj3Mxaj28A8ToD2fRxnxm9dUyU6GJ9ixC0uhZqD Tm4oG/+0DDiY/dzRyFmFOmNQulpKDxTHzyvniRNubZa0pXrON8r/m9oiPJKxn5Qofi 74O3W2oBMpGdL3Lzkuw0HlZZhf7a+ZnRnS5Ji4Uq0w2sb8qXprwnuMJGIjMSg6crmn Yqchbq59K0QlA== 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 C430E83D81; Wed, 13 Apr 2022 04:16:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1649816162; bh=mggso1ccoXzZTonKffJiUP7ZgGZZaMF23dnhqo2ogKE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DqRM+p8s50LrP5oUiTirowUGiKozP8jpov09ufsF0d2WQ0nePvpLWAqfOPMJbfy92 Jt27zaWSIve7RfrOG5MfuHq5rdr1IoXBKQ3UqXrFBj2UsNr9sbymefFqc4vqD+yxDt 2tuYUnsoP1UD3Th60iy9MD/GUlDdper0v9ULbJJTNxsu9Y/X0E0Jo+8UG5SG3d6NzD hCA81eaAF6kQEtRfpR4DWSZFK2KqUyY3LcIBXv6623Y6BD1+qIaC1Y/qUSZjsZ+QhM jFyRQjvtPVAF5yf2Gv9xj1BCrdHMYv+F4jb58wc078mGx2rs0UIekj7BhYWCv30y7+ XQA0hitN2LLUw== From: Marek Vasut To: u-boot@lists.denx.de Cc: Marek Vasut , Ramon Fried , Joe Hershberger Subject: [PATCH v2 10/17] net: dm9000: Drop static device private data Date: Wed, 13 Apr 2022 04:15:32 +0200 Message-Id: <20220413021539.454331-10-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 Allocate driver private data dynamically in its init function and drop the static driver private data variable. Pass the dynamic private data throughout the driver. This is done in preparation for DM conversion. Reviewed-by: Ramon Fried Signed-off-by: Marek Vasut Cc: Joe Hershberger Cc: Ramon Fried --- V2: - Add RB from Ramon - Rename struct eth_device netdev to struct eth_device dev in struct dm9000_priv{}, so that it actually matches the use of container_of(). Also, dev is shorter than netdev and that makes those container_of() calls fit on one line. - Add local struct eth_device *dev; and dev = &priv->dev; to dm9000_initialize() to fix the missing variable in non-DM case - Replace kcalloc() with calloc() and include malloc.h --- drivers/net/dm9000x.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c index 7e1368a1be9..36411bd8ebd 100644 --- a/drivers/net/dm9000x.c +++ b/drivers/net/dm9000x.c @@ -51,6 +51,7 @@ #include #include +#include #include #include #include @@ -74,11 +75,9 @@ struct dm9000_priv { void (*outblk)(void *data_ptr, int count); void (*inblk)(void *data_ptr, int count); void (*rx_status)(u16 *rxstatus, u16 *rxlen); - struct eth_device netdev; + struct eth_device dev; }; -static struct dm9000_priv dm9000_info; - /* DM9000 network board routine ---------------------------- */ #ifndef CONFIG_DM9000_BYTE_SWAPPED #define dm9000_outb(d, r) writeb((d), (r)) @@ -313,9 +312,9 @@ dm9000_reset(void) /* Initialize dm9000 board */ static int dm9000_init(struct eth_device *dev, struct bd_info *bd) { + struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev); int i, oft, lnk; u8 io_mode; - struct dm9000_priv *db = &dm9000_info; /* RESET device */ dm9000_reset(); @@ -430,10 +429,10 @@ 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 *netdev, void *packet, int length) +static int dm9000_send(struct eth_device *dev, void *packet, int length) { + struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev); int tmo; - struct dm9000_priv *db = &dm9000_info; dm9000_dump_packet(__func__, packet, length); @@ -483,12 +482,12 @@ static void dm9000_halt(struct eth_device *netdev) /* * Received a packet and pass to upper layer */ -static int dm9000_rx(struct eth_device *netdev) +static int dm9000_rx(struct eth_device *dev) { + struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev); u8 rxbyte; u8 *rdptr = (u8 *)net_rx_packets[0]; u16 rxstatus, rxlen = 0; - struct dm9000_priv *db = &dm9000_info; /* * Check packet ready or not, we must check @@ -591,10 +590,17 @@ static void dm9000_get_enetaddr(struct eth_device *dev) {} int dm9000_initialize(struct bd_info *bis) { - struct eth_device *dev = &dm9000_info.netdev; + struct dm9000_priv *priv; + struct eth_device *dev; + + priv = calloc(1, sizeof(*priv)); + if (!priv) + return -ENOMEM; + + dev = &priv->dev; /* Load MAC address from EEPROM */ - dm9000_get_enetaddr(dev); + dm9000_get_enetaddr(&priv->dev); dev->init = dm9000_init; dev->halt = dm9000_halt; @@ -602,7 +608,7 @@ int dm9000_initialize(struct bd_info *bis) dev->recv = dm9000_rx; strcpy(dev->name, "dm9000"); - eth_register(dev); + eth_register(&priv->dev); return 0; } -- 2.35.1