From: linas@austin.ibm.com (Linas Vepstas)
To: utz.bacher@de.ibm.com, Arnd Bergmann <arnd.bergmann@de.ibm.com>
Cc: Maxim Shchetynin <maxim@de.ibm.com>,
linux-kernel@vger.kernel.org, linuxppc-dev@ozlabs.org
Subject: [PATCH 1/2]: Spider ethernet driver spinlocks
Date: Fri, 21 Apr 2006 18:29:42 -0500 [thread overview]
Message-ID: <20060421232942.GG7242@austin.ibm.com> (raw)
Please review/apply/ack/forward upstream.
--linas
The spider network driver currently uses hand-rolled spinlocks
in a few places. Replace these with industry standard spinlocks.
In particular, this should add some safety if multiple threads
are touching the tx and rx chain pointers.
Signed-off-by: Linas Vepstas <linas@austin.ibm.com>
----
drivers/net/spider_net.c | 18 ++++++++----------
drivers/net/spider_net.h | 4 ++--
2 files changed, 10 insertions(+), 12 deletions(-)
Index: linux-2.6.17-rc1/drivers/net/spider_net.c
===================================================================
--- linux-2.6.17-rc1.orig/drivers/net/spider_net.c 2006-04-20 17:22:04.000000000 -0500
+++ linux-2.6.17-rc1/drivers/net/spider_net.c 2006-04-21 11:52:39.000000000 -0500
@@ -335,8 +335,6 @@ spider_net_init_chain(struct spider_net_
struct spider_net_descr *descr;
dma_addr_t buf;
- atomic_set(&card->rx_chain_refill,0);
-
descr = start_descr;
memset(descr, 0, sizeof(*descr) * no);
@@ -509,15 +507,15 @@ spider_net_refill_rx_chain(struct spider
* and omitting it) is ok. If called by NAPI, we'll be called again
* as spider_net_decode_one_descr is called several times. If some
* interrupt calls us, the NAPI is about to clean up anyway. */
- if (atomic_inc_return(&card->rx_chain_refill) == 1)
+ if (spin_trylock(&card->rx_chain_lock)) {
while (spider_net_get_descr_status(chain->head) ==
SPIDER_NET_DESCR_NOT_IN_USE) {
if (spider_net_prepare_rx_descr(card, chain->head))
break;
chain->head = chain->head->next;
}
-
- atomic_dec(&card->rx_chain_refill);
+ spin_unlock(&card->rx_chain_lock);
+ }
}
/**
@@ -596,10 +594,8 @@ spider_net_release_tx_chain(struct spide
struct spider_net_descr_chain *tx_chain = &card->tx_chain;
enum spider_net_descr_status status;
- if (atomic_inc_return(&card->tx_chain_release) != 1) {
- atomic_dec(&card->tx_chain_release);
+ if (!spin_trylock(&card->tx_chain_lock))
return 1;
- }
for (;;) {
status = spider_net_get_descr_status(tx_chain->tail);
@@ -633,7 +629,7 @@ spider_net_release_tx_chain(struct spide
tx_chain->tail = tx_chain->tail->next;
}
out:
- atomic_dec(&card->tx_chain_release);
+ spin_unlock(&card->tx_chain_lock);
netif_wake_queue(card->netdev);
@@ -2072,7 +2068,9 @@ spider_net_setup_netdev(struct spider_ne
pci_set_drvdata(card->pdev, netdev);
- atomic_set(&card->tx_chain_release,0);
+ spin_lock_init(&card->rx_chain_lock);
+ spin_lock_init(&card->tx_chain_lock);
+
card->rxram_full_tl.data = (unsigned long) card;
card->rxram_full_tl.func =
(void (*)(unsigned long)) spider_net_handle_rxram_full;
Index: linux-2.6.17-rc1/drivers/net/spider_net.h
===================================================================
--- linux-2.6.17-rc1.orig/drivers/net/spider_net.h 2006-04-20 17:22:04.000000000 -0500
+++ linux-2.6.17-rc1/drivers/net/spider_net.h 2006-04-21 11:47:17.000000000 -0500
@@ -451,8 +451,8 @@ struct spider_net_card {
struct spider_net_descr_chain tx_chain;
struct spider_net_descr_chain rx_chain;
- atomic_t rx_chain_refill;
- atomic_t tx_chain_release;
+ spinlock_t rx_chain_lock;
+ spinlock_t tx_chain_lock;
struct net_device_stats netdev_stats;
next reply other threads:[~2006-04-21 23:29 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-04-21 23:29 Linas Vepstas [this message]
2006-04-21 23:45 ` [PATCH 2/2]: Spider ethernet driver -- protect chain head Linas Vepstas
2006-04-22 0:11 ` Eugene Surovegin
2006-04-22 1:03 ` Linas Vepstas
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=20060421232942.GG7242@austin.ibm.com \
--to=linas@austin.ibm.com \
--cc=arnd.bergmann@de.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@ozlabs.org \
--cc=maxim@de.ibm.com \
--cc=utz.bacher@de.ibm.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).