r8169: Tx timeout rework
Subsystems (2)
PATCH 1/5 r8169: Tx timeout rework
Tx timeout rework:
- the ring descriptors of the chipset and the ring index of the driver are synced during a reset of the device;
- rtl8169_interrupt: rtl8169_hw_reset() replaces the previous stop code. An implicit reset of the device is added but it makes no noticeable difference with the former behavior (i.e.: stop the chipset).
drivers/net/r8169.c renamed from drivers/net/r8169.c~r8169-200 +65 -24
@@ -400,6 +400,7 @@ struct rtl8169_private {void (*phy_reset_enable)(void *);unsigned int (*phy_reset_pending)(void *);unsigned int (*link_ok)(void *); +struct work_struct task; };MODULE_AUTHOR ("Realtek" );
@@ -420,6 +421,8 @@ static int rtl8169_close(struct net_devistatic void rtl8169_set_rx_mode (struct net_device *dev);static void rtl8169_tx_timeout (struct net_device *dev);static struct net_device_stats *rtl8169_get_stats (struct net_device *netdev); +static int rtl8169_rx_interrupt (struct net_device *,struct rtl8169_private *, +void *);#ifdef CONFIG_R8169_NAPI static int rtl8169_poll (struct net_device *dev,int *budget);#endif
@@ -1456,6 +1459,8 @@ rtl8169_open(struct net_device *dev)if (retval <0 ) goto err_free_rx; +INIT_WORK (&tp->task,NULL , dev); +rtl8169_hw_start (dev);rtl8169_request_timer (dev);
@@ -1475,6 +1480,18 @@ err_free_irq: goto out; } +static void rtl8169_hw_reset (void *ioaddr) +{ +/* Disable interrupts */ +RTL_W16 (IntrMask,0x0000 ); + +/* Reset the chipset */ +RTL_W8 (ChipCmd, CmdReset); + +/* PCI commit */ +RTL_R8 (ChipCmd); +} +static void rtl8169_hw_start (struct net_device *dev) {
@@ -1518,8 +1535,6 @@ rtl8169_hw_start(struct net_device *dev)RTL_W16 (CPlusCmd, tp->cp_cmd); } - tp->cur_rx =0 ; -RTL_W32 (TxDescStartAddrLow, ((u64 ) tp->TxPhyAddr &DMA_32BIT_MASK ));RTL_W32 (TxDescStartAddrHigh, ((u64 ) tp->TxPhyAddr >>32 ));RTL_W32 (RxDescAddrLow, ((u64 ) tp->RxPhyAddr &DMA_32BIT_MASK ));
@@ -1634,12 +1649,16 @@ static inline void rtl8169_mark_as_last_ desc->opts1 |=cpu_to_le32 (RingEnd); } +static void rtl8169_init_ring_indexes (struct rtl8169_private *tp) +{ + tp->dirty_tx = tp->dirty_rx = tp->cur_tx = tp->cur_rx =0 ; +} +static int rtl8169_init_ring (struct net_device *dev) {struct rtl8169_private *tp =netdev_priv (dev); - tp->cur_rx = tp->dirty_rx =0 ; - tp->cur_tx = tp->dirty_tx =0 ; +rtl8169_init_ring_indexes (tp);memset (tp->tx_skb,0x0 ,NUM_TX_DESC *sizeof (struct ring_info ));memset (tp->Rx_skbuff,0x0 ,NUM_RX_DESC *sizeof (struct sk_buff *));
@@ -1691,31 +1710,53 @@ static void rtl8169_tx_clear(struct rtl8 tp->cur_tx = tp->dirty_tx =0 ; } -static void -rtl8169_tx_timeout (struct net_device *dev) +static void rtl8169_schedule_work (struct net_device *dev,void (*task)(void *)) {struct rtl8169_private *tp =netdev_priv (dev); -void *ioaddr = tp->mmio_addr; -u8 tmp8; -printk (KERN_INFO "%s: TX Timeout\n" , dev->name); -/* disable Tx, if not already */ - tmp8 =RTL_R8 (ChipCmd); -if (tmp8 & CmdTxEnb) -RTL_W8 (ChipCmd, tmp8 & ~CmdTxEnb); +PREPARE_WORK (&tp->task, task, dev); +schedule_delayed_work (&tp->task,4 ); +} -/* Disable interrupts by clearing the interrupt mask. */ -RTL_W16 (IntrMask,0x0000 ); +static void rtl8169_reset_task (void *_data) +{ +struct net_device *dev = _data; +struct rtl8169_private *tp =netdev_priv (dev); -/* Stop a shared interrupt from scavenging while we are. */ -spin_lock_irq (&tp->lock); +if (!netif_running (dev)) +return ; + +synchronize_irq (dev->irq); + +/* Wait for any pending NAPI task to complete */ +netif_poll_disable (dev); + +rtl8169_rx_interrupt (dev, tp, tp->mmio_addr);rtl8169_tx_clear (tp); -spin_unlock_irq (&tp->lock); -/* ...and finally, reset everything */ -rtl8169_hw_start (dev); +if (tp->dirty_rx == tp->cur_rx) { +rtl8169_init_ring_indexes (tp); +rtl8169_hw_start (dev); +netif_wake_queue (dev); + }else { +if (net_ratelimit ()) { + printk(PFX KERN_EMERG "%s: Rx buffers shortage\n", + dev->name); + } +rtl8169_schedule_work (dev, rtl8169_reset_task); + } +} + +static void rtl8169_tx_timeout (struct net_device *dev) +{ +struct rtl8169_private *tp =netdev_priv (dev); + +printk (KERN_INFO "%s: TX Timeout\n" , dev->name); -netif_wake_queue (dev); +rtl8169_hw_reset (tp->mmio_addr); + +/* Let's wait a bit while any (async) irq lands on */ +rtl8169_schedule_work (dev, rtl8169_reset_task); } static int rtl8169_xmit_frags(struct rtl8169_private *tp, struct sk_buff *skb,
@@ -2057,9 +2098,7 @@ rtl8169_interrupt(int irq, void *dev_insif (unlikely (status & SYSErr)) { printk(KERN_ERR PFX "%s: PCI error (status: 0x%04x)." " Device disabled.\n", dev->name, status); -RTL_W8 (ChipCmd,0x00 ); -RTL_W16 (IntrMask,0x0000 ); -RTL_R16 (IntrMask); +rtl8169_hw_reset (ioaddr);break ; }
@@ -2138,6 +2177,8 @@ rtl8169_close(struct net_device *dev)netif_stop_queue (dev); +flush_scheduled_work (); +rtl8169_delete_timer (dev);spin_lock_irq (&tp->lock);
_
PATCH 2/5 r8169: wrong advertisement of VLAN features
Removal of an advertisement for VLAN features which is redundant with rtl8169_init_one().
drivers/net/r8169.c renamed from drivers/net/r8169.c~r8169-205 +0 -2
@@ -1166,8 +1166,6 @@ rtl8169_init_board(struct pci_dev *pdev, tp->cp_cmd = PCIMulRW | RxChkSum; - dev->features |=NETIF_F_HW_VLAN_TX |NETIF_F_HW_VLAN_RX ; -if ((sizeof (dma_addr_t) >4 ) && !pci_set_dma_mask (pdev,DMA_64BIT_MASK ) && use_dac) { tp->cp_cmd |=PCIDAC ;
_
PATCH 3/5 r8169: automatic pci dac step down
Automatic adjustement of highmem dma feature.
The first interruption encountered on systems where the 8169 does not perform PCI DAC correctly seems to always be a PCI error one. When DAC is enabled, the driver tries to issue a complete down/up sequence as an addition to the usual halt of the device.
drivers/net/r8169.c renamed from drivers/net/r8169.c~r8169-210 +70 -7
@@ -1716,6 +1716,34 @@ static void rtl8169_schedule_work(structschedule_delayed_work (&tp->task,4 ); } +static void rtl8169_wait_for_quiescence (struct net_device *dev) +{ +synchronize_irq (dev->irq); + +/* Wait for any pending NAPI task to complete */ +netif_poll_disable (dev); +} + +static void rtl8169_reinit_task (void *_data) +{ +struct net_device *dev = _data; +int ret; + +if (netif_running (dev)) { +rtl8169_wait_for_quiescence (dev); +rtl8169_close (dev); + } + + ret =rtl8169_open (dev); +if (unlikely (ret <0 )) { +if (net_ratelimit ()) { + printk(PFX KERN_ERR "%s: reinit failure (status = %d)." + " Rescheduling.\n", dev->name, ret); + } +rtl8169_schedule_work (dev, rtl8169_reinit_task); + } +} +static void rtl8169_reset_task (void *_data) {struct net_device *dev = _data;
@@ -1724,10 +1752,7 @@ static void rtl8169_reset_task(void *_daif (!netif_running (dev))return ; -synchronize_irq (dev->irq); - -/* Wait for any pending NAPI task to complete */ -netif_poll_disable (dev); +rtl8169_wait_for_quiescence (dev);rtl8169_rx_interrupt (dev, tp, tp->mmio_addr);rtl8169_tx_clear (tp);
@@ -1893,6 +1918,46 @@ err_update_stats: goto out; } +static void rtl8169_pcierr_interrupt (struct net_device *dev) +{ +struct rtl8169_private *tp =netdev_priv (dev); +struct pci_dev *pdev = tp->pci_dev; +void *ioaddr = tp->mmio_addr; +u16 pci_status, pci_cmd; + +pci_read_config_word (pdev,PCI_COMMAND , &pci_cmd); +pci_read_config_word (pdev,PCI_STATUS , &pci_status); + + printk(KERN_ERR PFX "%s: PCI error (cmd = 0x%04x, status = 0x%04x).\n", + dev->name, pci_cmd, pci_status); + +/* +* The recovery sequence below admits a very elaborated explanation: +* - it seems to work; +* - I did not see what else could be done. +* +* Feel free to adjust to your needs. +*/ +pci_write_config_word (pdev,PCI_COMMAND , + pci_cmd |PCI_COMMAND_SERR |PCI_COMMAND_PARITY ); + +pci_write_config_word (pdev,PCI_STATUS , + pci_status & (PCI_STATUS_DETECTED_PARITY | +PCI_STATUS_SIG_SYSTEM_ERROR |PCI_STATUS_REC_MASTER_ABORT | +PCI_STATUS_REC_TARGET_ABORT |PCI_STATUS_SIG_TARGET_ABORT )); + +/* The infamous DAC f*ckup only happens at boot time */ +if ((tp->cp_cmd &PCIDAC ) && (tp->dirty_rx == tp->cur_rx ==0 )) { + printk(KERN_INFO PFX "%s: disabling PCI DAC.\n", dev->name); + tp->cp_cmd &= ~PCIDAC ; +RTL_W16 (CPlusCmd, tp->cp_cmd); + dev->features &= ~NETIF_F_HIGHDMA ; +rtl8169_schedule_work (dev, rtl8169_reinit_task); + } + +rtl8169_hw_reset (ioaddr); +} +static void rtl8169_tx_interrupt (struct net_device *dev,struct rtl8169_private *tp,void *ioaddr)
@@ -2094,9 +2159,7 @@ rtl8169_interrupt(int irq, void *dev_insbreak ;if (unlikely (status & SYSErr)) { - printk(KERN_ERR PFX "%s: PCI error (status: 0x%04x)." - " Device disabled.\n", dev->name, status); -rtl8169_hw_reset (ioaddr); +rtl8169_pcierr_interrupt (dev);break ; }
_
PATCH 4/5 r8169: rtl8169_close() races
- close the race with rtl8169_interrupt() which appears when rtl8169_close() uses synchronize_irq()/free_irq();
- netif_poll_disable() allows rtl8169_close() to wait for any pending rtl8169_poll() to complete so it can safely clear the rings.
drivers/net/r8169.c renamed from drivers/net/r8169.c~r8169-215 +6 -0
@@ -2142,6 +2142,9 @@ rtl8169_interrupt(int irq, void *dev_insint status =0 ;int handled =0 ; +if (unlikely (!netif_running (dev))) + goto out; + do { status = RTL_R16(IntrStatus);
@@ -2196,6 +2199,7 @@ rtl8169_interrupt(int irq, void *dev_ins/* Clear all interrupt sources. */ RTL_W16 (IntrStatus,0xffff ); } +out:return IRQ_RETVAL (handled); }
@@ -2259,6 +2263,8 @@ rtl8169_close(struct net_device *dev)synchronize_irq (dev->irq);free_irq (dev->irq, dev); +netif_poll_disable (dev); +rtl8169_tx_clear (tp);rtl8169_rx_clear (tp);
_
PATCH 5/5 r8169: cleanup
Cleanup
- timeout message is redundant with net/sched/sch_generic::dev_watchdog;
- anti-bloat in rtl8169_get_rx_csum;
- format fix.
drivers/net/r8169.c renamed from drivers/net/r8169.c~r8169-220 +3 -5
@@ -660,10 +660,10 @@ static u32 rtl8169_get_rx_csum(struct ne {struct rtl8169_private *tp =netdev_priv (dev); -return !!(tp->cp_cmd & RxChkSum); +return tp->cp_cmd & RxChkSum; } -static int rtl8169_set_rx_csum (struct net_device *dev,u32 data) +static int rtl8169_set_rx_csum (struct net_device *dev,u32 data) {struct rtl8169_private *tp =netdev_priv (dev);void *ioaddr = tp->mmio_addr;
@@ -1774,8 +1774,6 @@ static void rtl8169_tx_timeout(struct ne {struct rtl8169_private *tp =netdev_priv (dev); -printk (KERN_INFO "%s: TX Timeout\n" , dev->name); -rtl8169_hw_reset (tp->mmio_addr);/* Let's wait a bit while any (async) irq lands on */
@@ -2176,7 +2174,7 @@ rtl8169_interrupt(int irq, void *dev_insif (likely (netif_rx_schedule_prep (dev)))__netif_rx_schedule (dev);else { -printk (KERN_INFO "%s: interrupt %x taken in poll\n" , +printk (KERN_INFO "%s: interrupt %04x taken in poll\n" , dev->name, status); }break ;
_
applied 1-5