All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marek Vasut <marek.vasut@gmail.com>
To: u-boot@lists.denx.de
Subject: [PATCH 07/10] net: rtl8139: Split out common and non-DM functions
Date: Sat,  9 May 2020 22:34:41 +0200	[thread overview]
Message-ID: <20200509203444.821733-7-marek.vasut+renesas@gmail.com> (raw)
In-Reply-To: <20200509203444.821733-1-marek.vasut+renesas@gmail.com>

Split the driver into common and non-DM functionality, so that the
DM support can later re-use the common code, while we retain the
non-DM code until all the platforms are converted.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
---
 drivers/net/rtl8139.c | 92 ++++++++++++++++++++++++++++++++-----------
 1 file changed, 68 insertions(+), 24 deletions(-)

diff --git a/drivers/net/rtl8139.c b/drivers/net/rtl8139.c
index 679cafc6c8..6b87248094 100644
--- a/drivers/net/rtl8139.c
+++ b/drivers/net/rtl8139.c
@@ -190,6 +190,7 @@
 
 struct rtl8139_priv {
 	struct eth_device	dev;
+	unsigned int		rxstatus;
 	unsigned int		cur_rx;
 	unsigned int		cur_tx;
 	unsigned long		ioaddr;
@@ -357,9 +358,9 @@ static void rtl8139_reset(struct rtl8139_priv *priv)
 	outw(0, priv->ioaddr + RTL_REG_INTRMASK);
 }
 
-static int rtl8139_send(struct eth_device *dev, void *packet, int length)
+static int rtl8139_send_common(struct rtl8139_priv *priv,
+			       void *packet, int length)
 {
-	struct rtl8139_priv *priv = container_of(dev, struct rtl8139_priv, dev);
 	unsigned int len = length;
 	unsigned long txstatus;
 	unsigned int status;
@@ -419,25 +420,24 @@ static int rtl8139_send(struct eth_device *dev, void *packet, int length)
 	return length;
 }
 
-static int rtl8139_recv(struct eth_device *dev)
+static int rtl8139_recv_common(struct rtl8139_priv *priv, unsigned char *rxdata,
+			       uchar **packetp)
 {
-	struct rtl8139_priv *priv = container_of(dev, struct rtl8139_priv, dev);
 	const unsigned int rxstat = RTL_REG_INTRSTATUS_RXFIFOOVER |
 				    RTL_REG_INTRSTATUS_RXOVERFLOW |
 				    RTL_REG_INTRSTATUS_RXOK;
 	unsigned int rx_size, rx_status;
 	unsigned int ring_offs;
-	unsigned int status;
 	int length = 0;
 
 	if (inb(priv->ioaddr + RTL_REG_CHIPCMD) & RTL_REG_CHIPCMD_RXBUFEMPTY)
 		return 0;
 
-	status = inw(priv->ioaddr + RTL_REG_INTRSTATUS);
+	priv->rxstatus = inw(priv->ioaddr + RTL_REG_INTRSTATUS);
 	/* See below for the rest of the interrupt acknowledges.  */
-	outw(status & ~rxstat, priv->ioaddr + RTL_REG_INTRSTATUS);
+	outw(priv->rxstatus & ~rxstat, priv->ioaddr + RTL_REG_INTRSTATUS);
 
-	debug_cond(DEBUG_RX, "%s: int %hX ", __func__, status);
+	debug_cond(DEBUG_RX, "%s: int %hX ", __func__, priv->rxstatus);
 
 	ring_offs = priv->cur_rx % RX_BUF_LEN;
 	/* ring_offs is guaranteed being 4-byte aligned */
@@ -459,20 +459,30 @@ static int rtl8139_recv(struct eth_device *dev)
 	/* Received a good packet */
 	length = rx_size - 4;	/* no one cares about the FCS */
 	if (ring_offs + 4 + rx_size - 4 > RX_BUF_LEN) {
-		unsigned char rxdata[RX_BUF_LEN];
 		int semi_count = RX_BUF_LEN - ring_offs - 4;
 
 		memcpy(rxdata, rx_ring + ring_offs + 4, semi_count);
 		memcpy(&rxdata[semi_count], rx_ring,
 		       rx_size - 4 - semi_count);
 
-		net_process_received_packet(rxdata, length);
+		*packetp = rxdata;
 		debug_cond(DEBUG_RX, "rx packet %d+%d bytes",
 			   semi_count, rx_size - 4 - semi_count);
 	} else {
-		net_process_received_packet(rx_ring + ring_offs + 4, length);
+		*packetp = rx_ring + ring_offs + 4;
 		debug_cond(DEBUG_RX, "rx packet %d bytes", rx_size - 4);
 	}
+
+	return length;
+}
+
+static int rtl8139_free_pkt_common(struct rtl8139_priv *priv, unsigned int len)
+{
+	const unsigned int rxstat = RTL_REG_INTRSTATUS_RXFIFOOVER |
+				    RTL_REG_INTRSTATUS_RXOVERFLOW |
+				    RTL_REG_INTRSTATUS_RXOK;
+	unsigned int rx_size = len + 4;
+
 	flush_cache((unsigned long)rx_ring, RX_BUF_LEN);
 
 	priv->cur_rx = ROUND(priv->cur_rx + rx_size + 4, 4);
@@ -482,14 +492,13 @@ static int rtl8139_recv(struct eth_device *dev)
 	 * Rx overflow situations. The document itself contains basically
 	 * no usable information, except for a few exception handling rules.
 	 */
-	outw(status & rxstat, priv->ioaddr + RTL_REG_INTRSTATUS);
+	outw(priv->rxstatus & rxstat, priv->ioaddr + RTL_REG_INTRSTATUS);
 
-	return length;
+	return 0;
 }
 
-static int rtl8139_init(struct eth_device *dev, bd_t *bis)
+static int rtl8139_init_common(struct rtl8139_priv *priv)
 {
-	struct rtl8139_priv *priv = container_of(dev, struct rtl8139_priv, dev);
 	unsigned short *ap = (unsigned short *)priv->enetaddr;
 	int addr_len, i;
 	u8 reg;
@@ -515,19 +524,11 @@ static int rtl8139_init(struct eth_device *dev, bd_t *bis)
 	return 0;
 }
 
-static void rtl8139_stop(struct eth_device *dev)
+static void rtl8139_stop_common(struct rtl8139_priv *priv)
 {
-	struct rtl8139_priv *priv = container_of(dev, struct rtl8139_priv, dev);
-
 	rtl8139_hw_reset(priv);
 }
 
-static int rtl8139_bcast_addr(struct eth_device *dev, const u8 *bcast_mac,
-			      int join)
-{
-	return 0;
-}
-
 static void rtl8139_name(char *str, int card_number)
 {
 	sprintf(str, "RTL8139#%u", card_number);
@@ -539,6 +540,49 @@ static struct pci_device_id supported[] = {
 	{ }
 };
 
+static int rtl8139_bcast_addr(struct eth_device *dev, const u8 *bcast_mac,
+			      int join)
+{
+	return 0;
+}
+
+static int rtl8139_init(struct eth_device *dev, bd_t *bis)
+{
+	struct rtl8139_priv *priv = container_of(dev, struct rtl8139_priv, dev);
+
+	return rtl8139_init_common(priv);
+}
+
+static void rtl8139_stop(struct eth_device *dev)
+{
+	struct rtl8139_priv *priv = container_of(dev, struct rtl8139_priv, dev);
+
+	return rtl8139_stop_common(priv);
+}
+
+static int rtl8139_send(struct eth_device *dev, void *packet, int length)
+{
+	struct rtl8139_priv *priv = container_of(dev, struct rtl8139_priv, dev);
+
+	return rtl8139_send_common(priv, packet, length);
+}
+
+static int rtl8139_recv(struct eth_device *dev)
+{
+	struct rtl8139_priv *priv = container_of(dev, struct rtl8139_priv, dev);
+	unsigned char rxdata[RX_BUF_LEN];
+	uchar *packet;
+	int ret;
+
+	ret = rtl8139_recv_common(priv, rxdata, &packet);
+	if (ret) {
+		net_process_received_packet(packet, ret);
+		rtl8139_free_pkt_common(priv, ret);
+	}
+
+	return ret;
+}
+
 int rtl8139_initialize(bd_t *bis)
 {
 	struct rtl8139_priv *priv;
-- 
2.25.1

  parent reply	other threads:[~2020-05-09 20:34 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-09 20:34 [PATCH 01/10] net: rtl8139: Factor out device name assignment Marek Vasut
2020-05-09 20:34 ` [PATCH 02/10] net: rtl8139: Switch from malloc()+memset() to calloc() Marek Vasut
2020-06-12 21:16   ` Tom Rini
2020-05-09 20:34 ` [PATCH 03/10] net: rtl8139: Use dev->iobase instead of custom ioaddr Marek Vasut
2020-06-12 21:16   ` Tom Rini
2020-05-09 20:34 ` [PATCH 04/10] net: rtl8139: Clean up bus_to_phys()/phys_to_bus() macros Marek Vasut
2020-06-12 21:16   ` Tom Rini
2020-05-09 20:34 ` [PATCH 05/10] net: rtl8139: Introduce device private data Marek Vasut
2020-06-12 21:16   ` Tom Rini
2020-05-09 20:34 ` [PATCH 06/10] net: rtl8139: Pass private data into rtl8139_eeprom_delay() Marek Vasut
2020-06-12 21:17   ` Tom Rini
2020-05-09 20:34 ` Marek Vasut [this message]
2020-06-12 21:17   ` [PATCH 07/10] net: rtl8139: Split out common and non-DM functions Tom Rini
2020-05-09 20:34 ` [PATCH 08/10] net: rtl8139: Use PCI_DEVICE() to define PCI device compat list Marek Vasut
2020-06-12 21:17   ` Tom Rini
2020-05-09 20:34 ` [PATCH 09/10] net: rtl8139: Read HW address from EEPROM only on probe Marek Vasut
2020-06-12 21:17   ` Tom Rini
2020-05-09 20:34 ` [PATCH 10/10] net: rtl8139: Add DM support Marek Vasut
2020-06-12 21:17   ` Tom Rini
2020-06-12 21:16 ` [PATCH 01/10] net: rtl8139: Factor out device name assignment Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200509203444.821733-7-marek.vasut+renesas@gmail.com \
    --to=marek.vasut@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.