aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorCatalin Marinas <catalin.marinas@arm.com>2008-10-20 13:15:37 -0400
committerJeff Garzik <jgarzik@redhat.com>2008-10-22 07:00:41 -0400
commitb891a9023bc4fc639b31c234a705e7e51104cf22 (patch)
tree0f17ecfb53069f6d3ae92f503c40d1dcbf216268 /drivers
parent319edafef64406c971035c56bd68480e5a82b581 (diff)
smc911x: Make the driver safer on SMP
This patch extends the critical regions covered by lp->lock to make it safer on SMP. The main failure point was the smc911x_hard_start_xmit function being called from different CPUs. It was tested on the ARM SMP platforms. Signed-off-by: Catalin Marinas <catalin.marinas@arm.com> Signed-off-by: Jeff Garzik <jgarzik@redhat.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/net/smc911x.c25
1 files changed, 8 insertions, 17 deletions
diff --git a/drivers/net/smc911x.c b/drivers/net/smc911x.c
index 2c78229ad04b..f59c7772f344 100644
--- a/drivers/net/smc911x.c
+++ b/drivers/net/smc911x.c
@@ -155,23 +155,17 @@ static void PRINT_PKT(u_char *buf, int length)
155/* this enables an interrupt in the interrupt mask register */ 155/* this enables an interrupt in the interrupt mask register */
156#define SMC_ENABLE_INT(lp, x) do { \ 156#define SMC_ENABLE_INT(lp, x) do { \
157 unsigned int __mask; \ 157 unsigned int __mask; \
158 unsigned long __flags; \
159 spin_lock_irqsave(&lp->lock, __flags); \
160 __mask = SMC_GET_INT_EN((lp)); \ 158 __mask = SMC_GET_INT_EN((lp)); \
161 __mask |= (x); \ 159 __mask |= (x); \
162 SMC_SET_INT_EN((lp), __mask); \ 160 SMC_SET_INT_EN((lp), __mask); \
163 spin_unlock_irqrestore(&lp->lock, __flags); \
164} while (0) 161} while (0)
165 162
166/* this disables an interrupt from the interrupt mask register */ 163/* this disables an interrupt from the interrupt mask register */
167#define SMC_DISABLE_INT(lp, x) do { \ 164#define SMC_DISABLE_INT(lp, x) do { \
168 unsigned int __mask; \ 165 unsigned int __mask; \
169 unsigned long __flags; \
170 spin_lock_irqsave(&lp->lock, __flags); \
171 __mask = SMC_GET_INT_EN((lp)); \ 166 __mask = SMC_GET_INT_EN((lp)); \
172 __mask &= ~(x); \ 167 __mask &= ~(x); \
173 SMC_SET_INT_EN((lp), __mask); \ 168 SMC_SET_INT_EN((lp), __mask); \
174 spin_unlock_irqrestore(&lp->lock, __flags); \
175} while (0) 169} while (0)
176 170
177/* 171/*
@@ -279,6 +273,8 @@ static void smc911x_enable(struct net_device *dev)
279 273
280 DBG(SMC_DEBUG_FUNC, "%s: --> %s\n", dev->name, __func__); 274 DBG(SMC_DEBUG_FUNC, "%s: --> %s\n", dev->name, __func__);
281 275
276 spin_lock_irqsave(&lp->lock, flags);
277
282 SMC_SET_MAC_ADDR(lp, dev->dev_addr); 278 SMC_SET_MAC_ADDR(lp, dev->dev_addr);
283 279
284 /* Enable TX */ 280 /* Enable TX */
@@ -291,12 +287,10 @@ static void smc911x_enable(struct net_device *dev)
291 SMC_SET_FIFO_TSL(lp, 64); 287 SMC_SET_FIFO_TSL(lp, 64);
292 SMC_SET_GPT_CFG(lp, GPT_CFG_TIMER_EN_ | 10000); 288 SMC_SET_GPT_CFG(lp, GPT_CFG_TIMER_EN_ | 10000);
293 289
294 spin_lock_irqsave(&lp->lock, flags);
295 SMC_GET_MAC_CR(lp, cr); 290 SMC_GET_MAC_CR(lp, cr);
296 cr |= MAC_CR_TXEN_ | MAC_CR_HBDIS_; 291 cr |= MAC_CR_TXEN_ | MAC_CR_HBDIS_;
297 SMC_SET_MAC_CR(lp, cr); 292 SMC_SET_MAC_CR(lp, cr);
298 SMC_SET_TX_CFG(lp, TX_CFG_TX_ON_); 293 SMC_SET_TX_CFG(lp, TX_CFG_TX_ON_);
299 spin_unlock_irqrestore(&lp->lock, flags);
300 294
301 /* Add 2 byte padding to start of packets */ 295 /* Add 2 byte padding to start of packets */
302 SMC_SET_RX_CFG(lp, (2<<8) & RX_CFG_RXDOFF_); 296 SMC_SET_RX_CFG(lp, (2<<8) & RX_CFG_RXDOFF_);
@@ -305,9 +299,7 @@ static void smc911x_enable(struct net_device *dev)
305 if (cr & MAC_CR_RXEN_) 299 if (cr & MAC_CR_RXEN_)
306 DBG(SMC_DEBUG_RX, "%s: Receiver already enabled\n", dev->name); 300 DBG(SMC_DEBUG_RX, "%s: Receiver already enabled\n", dev->name);
307 301
308 spin_lock_irqsave(&lp->lock, flags);
309 SMC_SET_MAC_CR(lp, cr | MAC_CR_RXEN_); 302 SMC_SET_MAC_CR(lp, cr | MAC_CR_RXEN_);
310 spin_unlock_irqrestore(&lp->lock, flags);
311 303
312 /* Interrupt on every received packet */ 304 /* Interrupt on every received packet */
313 SMC_SET_FIFO_RSA(lp, 0x01); 305 SMC_SET_FIFO_RSA(lp, 0x01);
@@ -323,6 +315,8 @@ static void smc911x_enable(struct net_device *dev)
323 mask|=INT_EN_RDFO_EN_; 315 mask|=INT_EN_RDFO_EN_;
324 } 316 }
325 SMC_ENABLE_INT(lp, mask); 317 SMC_ENABLE_INT(lp, mask);
318
319 spin_unlock_irqrestore(&lp->lock, flags);
326} 320}
327 321
328/* 322/*
@@ -463,7 +457,6 @@ static void smc911x_hardware_send_pkt(struct net_device *dev)
463 struct sk_buff *skb; 457 struct sk_buff *skb;
464 unsigned int cmdA, cmdB, len; 458 unsigned int cmdA, cmdB, len;
465 unsigned char *buf; 459 unsigned char *buf;
466 unsigned long flags;
467 460
468 DBG(SMC_DEBUG_FUNC | SMC_DEBUG_TX, "%s: --> %s\n", dev->name, __func__); 461 DBG(SMC_DEBUG_FUNC | SMC_DEBUG_TX, "%s: --> %s\n", dev->name, __func__);
469 BUG_ON(lp->pending_tx_skb == NULL); 462 BUG_ON(lp->pending_tx_skb == NULL);
@@ -508,11 +501,9 @@ static void smc911x_hardware_send_pkt(struct net_device *dev)
508 dev->trans_start = jiffies; 501 dev->trans_start = jiffies;
509 dev_kfree_skb(skb); 502 dev_kfree_skb(skb);
510#endif 503#endif
511 spin_lock_irqsave(&lp->lock, flags);
512 if (!lp->tx_throttle) { 504 if (!lp->tx_throttle) {
513 netif_wake_queue(dev); 505 netif_wake_queue(dev);
514 } 506 }
515 spin_unlock_irqrestore(&lp->lock, flags);
516 SMC_ENABLE_INT(lp, INT_EN_TDFA_EN_ | INT_EN_TSFL_EN_); 507 SMC_ENABLE_INT(lp, INT_EN_TDFA_EN_ | INT_EN_TSFL_EN_);
517} 508}
518 509
@@ -531,6 +522,8 @@ static int smc911x_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
531 DBG(SMC_DEBUG_FUNC | SMC_DEBUG_TX, "%s: --> %s\n", 522 DBG(SMC_DEBUG_FUNC | SMC_DEBUG_TX, "%s: --> %s\n",
532 dev->name, __func__); 523 dev->name, __func__);
533 524
525 spin_lock_irqsave(&lp->lock, flags);
526
534 BUG_ON(lp->pending_tx_skb != NULL); 527 BUG_ON(lp->pending_tx_skb != NULL);
535 528
536 free = SMC_GET_TX_FIFO_INF(lp) & TX_FIFO_INF_TDFREE_; 529 free = SMC_GET_TX_FIFO_INF(lp) & TX_FIFO_INF_TDFREE_;
@@ -540,12 +533,10 @@ static int smc911x_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
540 if (free <= SMC911X_TX_FIFO_LOW_THRESHOLD) { 533 if (free <= SMC911X_TX_FIFO_LOW_THRESHOLD) {
541 DBG(SMC_DEBUG_TX, "%s: Disabling data flow due to low FIFO space (%d)\n", 534 DBG(SMC_DEBUG_TX, "%s: Disabling data flow due to low FIFO space (%d)\n",
542 dev->name, free); 535 dev->name, free);
543 spin_lock_irqsave(&lp->lock, flags);
544 /* Reenable when at least 1 packet of size MTU present */ 536 /* Reenable when at least 1 packet of size MTU present */
545 SMC_SET_FIFO_TDA(lp, (SMC911X_TX_FIFO_LOW_THRESHOLD)/64); 537 SMC_SET_FIFO_TDA(lp, (SMC911X_TX_FIFO_LOW_THRESHOLD)/64);
546 lp->tx_throttle = 1; 538 lp->tx_throttle = 1;
547 netif_stop_queue(dev); 539 netif_stop_queue(dev);
548 spin_unlock_irqrestore(&lp->lock, flags);
549 } 540 }
550 541
551 /* Drop packets when we run out of space in TX FIFO 542 /* Drop packets when we run out of space in TX FIFO
@@ -561,6 +552,7 @@ static int smc911x_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
561 lp->pending_tx_skb = NULL; 552 lp->pending_tx_skb = NULL;
562 dev->stats.tx_errors++; 553 dev->stats.tx_errors++;
563 dev->stats.tx_dropped++; 554 dev->stats.tx_dropped++;
555 spin_unlock_irqrestore(&lp->lock, flags);
564 dev_kfree_skb(skb); 556 dev_kfree_skb(skb);
565 return 0; 557 return 0;
566 } 558 }
@@ -570,7 +562,6 @@ static int smc911x_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
570 /* If the DMA is already running then defer this packet Tx until 562 /* If the DMA is already running then defer this packet Tx until
571 * the DMA IRQ starts it 563 * the DMA IRQ starts it
572 */ 564 */
573 spin_lock_irqsave(&lp->lock, flags);
574 if (lp->txdma_active) { 565 if (lp->txdma_active) {
575 DBG(SMC_DEBUG_TX | SMC_DEBUG_DMA, "%s: Tx DMA running, deferring packet\n", dev->name); 566 DBG(SMC_DEBUG_TX | SMC_DEBUG_DMA, "%s: Tx DMA running, deferring packet\n", dev->name);
576 lp->pending_tx_skb = skb; 567 lp->pending_tx_skb = skb;
@@ -581,11 +572,11 @@ static int smc911x_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
581 DBG(SMC_DEBUG_TX | SMC_DEBUG_DMA, "%s: Activating Tx DMA\n", dev->name); 572 DBG(SMC_DEBUG_TX | SMC_DEBUG_DMA, "%s: Activating Tx DMA\n", dev->name);
582 lp->txdma_active = 1; 573 lp->txdma_active = 1;
583 } 574 }
584 spin_unlock_irqrestore(&lp->lock, flags);
585 } 575 }
586#endif 576#endif
587 lp->pending_tx_skb = skb; 577 lp->pending_tx_skb = skb;
588 smc911x_hardware_send_pkt(dev); 578 smc911x_hardware_send_pkt(dev);
579 spin_unlock_irqrestore(&lp->lock, flags);
589 580
590 return 0; 581 return 0;
591} 582}