From: Marek Vasut <marek.vasut@gmail.com>
To: u-boot@lists.denx.de
Subject: [PATCH 13/15] net: pcnet: Split common and non-DM functions
Date: Sun, 17 May 2020 18:24:23 +0200 [thread overview]
Message-ID: <20200517162425.76584-13-marek.vasut+renesas@gmail.com> (raw)
In-Reply-To: <20200517162425.76584-1-marek.vasut+renesas@gmail.com>
Pull the common parts of functions out so they can be reused by both
DM and non-DM code paths. The recv() function had to be reworked to
fit into this scheme and this means it now only receives one packet
at a time instead of spinning in an endless loop.
Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
---
drivers/net/pcnet.c | 149 ++++++++++++++++++++++++++++----------------
1 file changed, 94 insertions(+), 55 deletions(-)
diff --git a/drivers/net/pcnet.c b/drivers/net/pcnet.c
index 8e99e41863..8292b0bacb 100644
--- a/drivers/net/pcnet.c
+++ b/drivers/net/pcnet.c
@@ -83,6 +83,7 @@ struct pcnet_priv {
void __iomem *iobase;
char *name;
u8 *enetaddr;
+ u16 status;
int cur_rx;
int cur_tx;
};
@@ -140,9 +141,8 @@ static struct pci_device_id supported[] = {
{}
};
-static int pcnet_probe(struct eth_device *dev, bd_t *bis, int dev_nr)
+static int pcnet_probe_common(struct pcnet_priv *lp)
{
- struct pcnet_priv *lp = dev->priv;
int chip_version;
char *chipname;
int i;
@@ -196,9 +196,8 @@ static int pcnet_probe(struct eth_device *dev, bd_t *bis, int dev_nr)
return 0;
}
-static int pcnet_init(struct eth_device *dev, bd_t *bis)
+static int pcnet_init_common(struct pcnet_priv *lp)
{
- struct pcnet_priv *lp = dev->priv;
struct pcnet_uncached_priv *uc;
int i, val;
unsigned long addr;
@@ -316,9 +315,8 @@ static int pcnet_init(struct eth_device *dev, bd_t *bis)
return 0;
}
-static int pcnet_send(struct eth_device *dev, void *packet, int pkt_len)
+static int pcnet_send_common(struct pcnet_priv *lp, void *packet, int pkt_len)
{
- struct pcnet_priv *lp = dev->priv;
int i, status;
u32 addr;
struct pcnet_tx_head *entry = &lp->uc->tx_ring[lp->cur_tx];
@@ -365,65 +363,70 @@ static int pcnet_send(struct eth_device *dev, void *packet, int pkt_len)
return pkt_len;
}
-static int pcnet_recv (struct eth_device *dev)
+static int pcnet_recv_common(struct pcnet_priv *lp, unsigned char **bufp)
{
- struct pcnet_priv *lp = dev->priv;
struct pcnet_rx_head *entry;
unsigned char *buf;
int pkt_len = 0;
- u16 status, err_status;
+ u16 err_status;
- while (1) {
- entry = &lp->uc->rx_ring[lp->cur_rx];
- /*
- * If we own the next entry, it's a new packet. Send it up.
- */
- status = readw(&entry->status);
- if ((status & 0x8000) != 0)
- break;
- err_status = status >> 8;
-
- if (err_status != 0x03) { /* There was an error. */
- printf("%s: Rx%d", lp->name, lp->cur_rx);
- PCNET_DEBUG1(" (status=0x%x)", err_status);
- if (err_status & 0x20)
- printf(" Frame");
- if (err_status & 0x10)
- printf(" Overflow");
- if (err_status & 0x08)
- printf(" CRC");
- if (err_status & 0x04)
- printf(" Fifo");
- printf(" Error\n");
- status &= 0x03ff;
-
- } else {
- pkt_len = (readl(&entry->msg_length) & 0xfff) - 4;
- if (pkt_len < 60) {
- printf("%s: Rx%d: invalid packet length %d\n",
- lp->name, lp->cur_rx, pkt_len);
- } else {
- buf = lp->rx_buf[lp->cur_rx];
- invalidate_dcache_range((unsigned long)buf,
- (unsigned long)buf + pkt_len);
- net_process_received_packet(buf, pkt_len);
- PCNET_DEBUG2("Rx%d: %d bytes from 0x%p\n",
- lp->cur_rx, pkt_len, buf);
- }
- }
-
- status |= 0x8000;
- writew(status, &entry->status);
+ entry = &lp->uc->rx_ring[lp->cur_rx];
+ /*
+ * If we own the next entry, it's a new packet. Send it up.
+ */
+ lp->status = readw(&entry->status);
+ if ((lp->status & 0x8000) != 0)
+ return 0;
+ err_status = lp->status >> 8;
+
+ if (err_status != 0x03) { /* There was an error. */
+ printf("%s: Rx%d", lp->name, lp->cur_rx);
+ PCNET_DEBUG1(" (status=0x%x)", err_status);
+ if (err_status & 0x20)
+ printf(" Frame");
+ if (err_status & 0x10)
+ printf(" Overflow");
+ if (err_status & 0x08)
+ printf(" CRC");
+ if (err_status & 0x04)
+ printf(" Fifo");
+ printf(" Error\n");
+ lp->status &= 0x03ff;
+ return 0;
+ }
- if (++lp->cur_rx >= RX_RING_SIZE)
- lp->cur_rx = 0;
+ pkt_len = (readl(&entry->msg_length) & 0xfff) - 4;
+ if (pkt_len < 60) {
+ printf("%s: Rx%d: invalid packet length %d\n",
+ lp->name, lp->cur_rx, pkt_len);
+ return 0;
}
+
+ *bufp = lp->rx_buf[lp->cur_rx];
+ invalidate_dcache_range((unsigned long)*bufp,
+ (unsigned long)*bufp + pkt_len);
+
+ PCNET_DEBUG2("Rx%d: %d bytes from 0x%p\n",
+ lp->cur_rx, pkt_len, buf);
+
return pkt_len;
}
-static void pcnet_halt(struct eth_device *dev)
+static void pcnet_free_pkt_common(struct pcnet_priv *lp, unsigned int len)
+{
+ struct pcnet_rx_head *entry;
+
+ entry = &lp->uc->rx_ring[lp->cur_rx];
+
+ lp->status |= 0x8000;
+ writew(lp->status, &entry->status);
+
+ if (++lp->cur_rx >= RX_RING_SIZE)
+ lp->cur_rx = 0;
+}
+
+static void pcnet_halt_common(struct pcnet_priv *lp)
{
- struct pcnet_priv *lp = dev->priv;
int i;
PCNET_DEBUG1("%s: %s...\n", lp->name, __func__);
@@ -441,6 +444,42 @@ static void pcnet_halt(struct eth_device *dev)
printf("%s: TIMEOUT: controller reset failed\n", lp->name);
}
+static int pcnet_init(struct eth_device *dev, bd_t *bis)
+{
+ struct pcnet_priv *lp = dev->priv;
+
+ return pcnet_init_common(lp);
+}
+
+static int pcnet_send(struct eth_device *dev, void *packet, int pkt_len)
+{
+ struct pcnet_priv *lp = dev->priv;
+
+ return pcnet_send_common(lp, packet, pkt_len);
+}
+
+static int pcnet_recv(struct eth_device *dev)
+{
+ struct pcnet_priv *lp = dev->priv;
+ uchar *packet;
+ int ret;
+
+ ret = pcnet_recv_common(lp, &packet);
+ if (ret > 0)
+ net_process_received_packet(packet, ret);
+ if (ret)
+ pcnet_free_pkt_common(lp, ret);
+
+ return ret;
+}
+
+static void pcnet_halt(struct eth_device *dev)
+{
+ struct pcnet_priv *lp = dev->priv;
+
+ pcnet_halt_common(lp);
+}
+
int pcnet_initialize(bd_t *bis)
{
pci_dev_t devbusfn;
@@ -509,7 +548,7 @@ int pcnet_initialize(bd_t *bis)
/*
* Probe the PCnet chip.
*/
- if (pcnet_probe(dev, bis, dev_nr) < 0) {
+ if (pcnet_probe_common(lp) < 0) {
free(dev);
continue;
}
--
2.25.1
next prev parent reply other threads:[~2020-05-17 16:24 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-17 16:24 [PATCH 01/15] net: pcnet: Drop typedef struct pcnet_priv_t Marek Vasut
2020-05-17 16:24 ` [PATCH 02/15] net: pcnet: Drop PCNET_HAS_PROM Marek Vasut
2020-05-17 16:24 ` [PATCH 03/15] net: pcnet: Use PCI_DEVICE() to define PCI device compat list Marek Vasut
2020-05-17 16:24 ` [PATCH 04/15] net: pcnet: Simplify private data allocation Marek Vasut
2020-05-17 16:24 ` [PATCH 05/15] net: pcnet: Replace memset+malloc with calloc Marek Vasut
2020-05-17 16:24 ` [PATCH 06/15] net: pcnet: Move private data allocation to initialize Marek Vasut
2020-05-17 16:24 ` [PATCH 07/15] net: pcnet: Move initialize function at the end Marek Vasut
2020-05-17 16:24 ` [PATCH 08/15] net: pcnet: Drop useless forward declarations Marek Vasut
2020-05-17 16:24 ` [PATCH 09/15] net: pcnet: Wrap devbusfn into private data Marek Vasut
2020-05-17 16:24 ` [PATCH 10/15] net: pcnet: Pass private data through dev->priv Marek Vasut
2020-05-17 16:24 ` [PATCH 11/15] net: pcnet: Wrap iobase into private data Marek Vasut
2020-05-17 16:24 ` [PATCH 12/15] net: pcnet: Wrap name and enetaddr " Marek Vasut
2020-05-17 16:24 ` Marek Vasut [this message]
2020-05-17 16:24 ` [PATCH 14/15] net: pcnet: Add DM support Marek Vasut
2020-05-17 16:24 ` [PATCH 15/15] net: pcnet: Add Kconfig entries Marek Vasut
2020-05-18 9:18 ` Daniel Schwierzeck
2020-05-18 9:54 ` Marek Vasut
2020-05-18 16:03 ` Daniel Schwierzeck
2020-06-05 15:28 ` [PATCH 01/15] net: pcnet: Drop typedef struct pcnet_priv_t Daniel Schwierzeck
2020-06-05 16:22 ` Marek Vasut
2020-06-05 16:38 ` Daniel Schwierzeck
2020-06-05 17:50 ` Marek Vasut
2020-06-05 23:56 ` Daniel Schwierzeck
2020-06-06 12:00 ` Marek Vasut
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=20200517162425.76584-13-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.