1. 27 1月, 2015 7 次提交
    • B
      sh_eth: Check for DMA mapping errors on transmit · aa3933b8
      Ben Hutchings 提交于
      dma_map_single() may fail if an IOMMU or swiotlb is in use, so
      we need to check for this.
      Signed-off-by: NBen Hutchings <ben.hutchings@codethink.co.uk>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      aa3933b8
    • B
      sh_eth: Ensure DMA engines are stopped before freeing buffers · 740c7f31
      Ben Hutchings 提交于
      Currently we try to clear EDRRR and EDTRR and immediately continue to
      free buffers.  This is unsafe because:
      
      - In general, register writes are not serialised with DMA, so we still
        have to wait for DMA to complete somehow
      - The R8A7790 (R-Car H2) manual states that the TX running flag cannot
        be cleared by writing to EDTRR
      - The same manual states that clearing the RX running flag only stops
        RX DMA at the next packet boundary
      
      I applied this patch to the driver to detect DMA writes to freed
      buffers:
      
      > --- a/drivers/net/ethernet/renesas/sh_eth.c
      > +++ b/drivers/net/ethernet/renesas/sh_eth.c
      > @@ -1098,7 +1098,14 @@ static void sh_eth_ring_free(struct net_device *ndev)
      >  	/* Free Rx skb ringbuffer */
      >  	if (mdp->rx_skbuff) {
      >  		for (i = 0; i < mdp->num_rx_ring; i++)
      > +			memcpy(mdp->rx_skbuff[i]->data,
      > +			       "Hello, world", 12);
      > +		msleep(100);
      > +		for (i = 0; i < mdp->num_rx_ring; i++) {
      > +			WARN_ON(memcmp(mdp->rx_skbuff[i]->data,
      > +				       "Hello, world", 12));
      >  			dev_kfree_skb(mdp->rx_skbuff[i]);
      > +		}
      >  	}
      >  	kfree(mdp->rx_skbuff);
      >  	mdp->rx_skbuff = NULL;
      
      then ran the loop:
      
          while ethtool -G eth0 rx 128 ; ethtool -G eth0 rx 64; do echo -n .; done
      
      and 'ping -f' toward the sh_eth port from another machine.  The
      warning fired several times a minute.
      
      To fix these issues:
      
      - Deactivate all TX descriptors rather than writing to EDTRR
      - As there seems to be no way of telling when RX DMA is stopped,
        perform a soft reset to ensure that both DMA enginess are stopped
      - To reduce the possibility of the reset truncating a transmitted
        frame, disable egress and wait a reasonable time to reach a
        packet boundary before resetting
      - Update statistics before resetting
      
      (The 'reasonable time' does not allow for CS/CD in half-duplex
      mode, but half-duplex no longer seems reasonable!)
      Signed-off-by: NBen Hutchings <ben.hutchings@codethink.co.uk>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      740c7f31
    • B
      sh_eth: Remove RX overflow log messages · dc1d0e6d
      Ben Hutchings 提交于
      If RX traffic is overflowing the FIFO or DMA ring, logging every time
      this happens just makes things worse.  These errors are visible in the
      statistics anyway.
      Signed-off-by: NBen Hutchings <ben.hutchings@codethink.co.uk>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      dc1d0e6d
    • B
      sh_eth: Fix serialisation of interrupt disable with interrupt & NAPI handlers · 283e38db
      Ben Hutchings 提交于
      In order to stop the RX path accessing the RX ring while it's being
      stopped or resized, we clear the interrupt mask (EESIPR) and then call
      free_irq() or synchronise_irq().  This is insufficient because the
      interrupt handler or NAPI poller may set EESIPR again after we clear
      it.  Also, in sh_eth_set_ringparam() we currently don't disable NAPI
      polling at all.
      
      I could easily trigger a crash by running the loop:
      
         while ethtool -G eth0 rx 128 && ethtool -G eth0 rx 64; do echo -n .; done
      
      and 'ping -f' toward the sh_eth port from another machine.
      
      To fix this:
      - Add a software flag (irq_enabled) to signal whether interrupts
        should be enabled
      - In the interrupt handler, if the flag is clear then clear EESIPR
        and return
      - In the NAPI poller, if the flag is clear then don't set EESIPR
      - Set the flag before enabling interrupts in sh_eth_dev_init() and
        sh_eth_set_ringparam()
      - Clear the flag and serialise with the interrupt and NAPI
        handlers before clearing EESIPR in sh_eth_close() and
        sh_eth_set_ringparam()
      
      After this, I could run the loop for 100,000 iterations successfully.
      Signed-off-by: NBen Hutchings <ben.hutchings@codethink.co.uk>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      283e38db
    • B
      sh_eth: Fix crash or memory leak when resizing rings on device that is down · 084236d8
      Ben Hutchings 提交于
      If the device is down then no packet buffers should be allocated.
      We also must not touch its registers as it may be powered off.
      Signed-off-by: NBen Hutchings <ben.hutchings@codethink.co.uk>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      084236d8
    • B
      sh_eth: Detach net device when stopping queue to resize DMA rings · bd888916
      Ben Hutchings 提交于
      We must only ever stop TX queues when they are full or the net device
      is not 'ready' so far as the net core, and specifically the watchdog,
      is concerned.  Otherwise, the watchdog may fire *immediately* if no
      packets have been added to the queue in the last 5 seconds.
      
      What's more, sh_eth_tx_timeout() will likely crash if called while
      we're resizing the TX ring.
      
      I could easily trigger this by running the loop:
      
         while ethtool -G eth0 rx 128 && ethtool -G eth0 rx 64; do echo -n .; done
      Signed-off-by: NBen Hutchings <ben.hutchings@codethink.co.uk>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      bd888916
    • B
      sh_eth: Fix padding of short frames on TX · eebfb643
      Ben Hutchings 提交于
      If an skb to be transmitted is shorter than the minimum Ethernet frame
      length, we currently set the DMA descriptor length to the minimum but
      do not add zero-padding.  This could result in leaking sensitive
      data.  We also pass different lengths to dma_map_single() and
      dma_unmap_single().
      
      Use skb_padto() to pad properly, before calling dma_map_single().
      Signed-off-by: NBen Hutchings <ben.hutchings@codethink.co.uk>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      eebfb643
  2. 20 1月, 2015 2 次提交
    • B
      sh_eth: Fix ethtool operation crash when net device is down · 4f9dce23
      Ben Hutchings 提交于
      The driver connects and disconnects the PHY device whenever the
      net device is brought up and down.  The ethtool get_settings,
      set_settings and nway_reset operations will dereference a null
      or dangling pointer if called while it is down.
      
      I think it would be preferable to keep the PHY connected, but there
      may be good reasons not to.
      
      As an immediate fix for this bug:
      - Set the phydev pointer to NULL after disconnecting the PHY
      - Change those three operations to return -ENODEV while the PHY is
        not connected
      Signed-off-by: NBen Hutchings <ben.hutchings@codethink.co.uk>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      4f9dce23
    • B
      sh_eth: Fix promiscuous mode on chips without TSU · b37feed7
      Ben Hutchings 提交于
      Currently net_device_ops::set_rx_mode is only implemented for
      chips with a TSU (multiple address table).  However we do need
      to turn the PRM (promiscuous) flag on and off for other chips.
      
      - Remove the unlikely() from the TSU functions that we may safely
        call for chips without a TSU
      - Make setting of the MCT flag conditional on the tsu capability flag
      - Rename sh_eth_set_multicast_list() to sh_eth_set_rx_mode() and plumb
        it into both net_device_ops structures
      - Remove the previously-unreachable branch in sh_eth_rx_mode() that
        would otherwise reset the flags to defaults for non-TSU chips
      Signed-off-by: NBen Hutchings <ben.hutchings@codethink.co.uk>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      b37feed7
  3. 16 1月, 2015 1 次提交
  4. 09 1月, 2015 2 次提交
  5. 10 12月, 2014 2 次提交
  6. 30 11月, 2014 2 次提交
    • M
      sh_eth: Fix sleeping function called from invalid context · 7fa2955f
      Mitsuhiro Kimura 提交于
      This resolves the following bug which can be reproduced by building the
      kernel with CONFIG_DEBUG_ATOMIC_SLEEP=y and reading network statistics
      while the network interface is down.
      
      e.g.:
      
      ifconfig eth0 down
      cat /sys/class/net/eth0/statistics/tx_errors
      
      ----
      [ 1238.161349] BUG: sleeping function called from invalid context at drivers/base/power/runtime.c:952
      [ 1238.188279] in_atomic(): 1, irqs_disabled(): 0, pid: 1388, name: cat
      [ 1238.207425] CPU: 0 PID: 1388 Comm: cat Not tainted 3.10.31-ltsi-00046-gefa0b46 #1087
      [ 1238.230737] Backtrace:
      [ 1238.238123] [<c0012e64>] (dump_backtrace+0x0/0x10c) from [<c0013000>] (show_stack+0x18/0x1c)
      [ 1238.263499]  r6:000003b8 r5:c06160c0 r4:c0669e00 r3:00404000
      [ 1238.280583] [<c0012fe8>] (show_stack+0x0/0x1c) from [<c04515a4>] (dump_stack+0x20/0x28)
      [ 1238.304631] [<c0451584>] (dump_stack+0x0/0x28) from [<c004970c>] (__might_sleep+0xf8/0x118)
      [ 1238.329734] [<c0049614>] (__might_sleep+0x0/0x118) from [<c02465ac>] (__pm_runtime_resume+0x38/0x90)
      [ 1238.357170]  r7:d616f000 r6:c049c458 r5:00000004 r4:d6a17210
      [ 1238.374251] [<c0246574>] (__pm_runtime_resume+0x0/0x90) from [<c029b1c4>] (sh_eth_get_stats+0x44/0x280)
      [ 1238.402468]  r7:d616f000 r6:c049c458 r5:d5c21000 r4:d5c21000
      [ 1238.419552] [<c029b180>] (sh_eth_get_stats+0x0/0x280) from [<c03ae39c>] (dev_get_stats+0x54/0x88)
      [ 1238.446204]  r5:d5c21000 r4:d5ed7e08
      [ 1238.456980] [<c03ae348>] (dev_get_stats+0x0/0x88) from [<c03c677c>] (netstat_show.isra.15+0x54/0x9c)
      [ 1238.484413]  r6:d5c21000 r5:d5c21238 r4:00000028 r3:00000001
      [ 1238.501495] [<c03c6728>] (netstat_show.isra.15+0x0/0x9c) from [<c03c69b8>] (show_tx_errors+0x18/0x1c)
      [ 1238.529196]  r7:d5f945d8 r6:d5f945c0 r5:c049716c r4:c0650e7c
      [ 1238.546279] [<c03c69a0>] (show_tx_errors+0x0/0x1c) from [<c023963c>] (dev_attr_show+0x24/0x50)
      [ 1238.572157] [<c0239618>] (dev_attr_show+0x0/0x50) from [<c010c148>] (sysfs_read_file+0xb0/0x140)
      [ 1238.598554]  r5:c049716c r4:d5c21240
      [ 1238.609326] [<c010c098>] (sysfs_read_file+0x0/0x140) from [<c00b9ee4>] (vfs_read+0xb0/0x13c)
      [ 1238.634679] [<c00b9e34>] (vfs_read+0x0/0x13c) from [<c00ba0ac>] (SyS_read+0x44/0x74)
      [ 1238.657944]  r8:bef45bf0 r7:00000000 r6:d6ac0600 r5:00000000 r4:00000000
      [ 1238.678172] [<c00ba068>] (SyS_read+0x0/0x74) from [<c000eec0>] (ret_fast_syscall+0x0/0x30)
      ----
      Signed-off-by: NMitsuhiro Kimura <mitsuhiro.kimura.kc@renesas.com>
      Signed-off-by: NYoshihiro Kaneko <ykaneko0929@gmail.com>
      Signed-off-by: NSimon Horman <horms+renesas@verge.net.au>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      7fa2955f
    • M
      sh_eth: Fix skb alloc size and alignment adjust rule. · 4d6a949c
      Mitsuhiro Kimura 提交于
      In the current driver, allocation size of skb does not care the alignment
      adjust after allocation.
      And also, in the current implementation, buffer alignment method by
      sh_eth_set_receive_align function has a bug that this function displace
      buffer start address forcedly when the alignment is corrected.
      In the result, tail of the skb will exceed allocated area and kernel panic
      will be occurred.
      This patch fix this issue.
      Signed-off-by: NMitsuhiro Kimura <mitsuhiro.kimura.kc@renesas.com>
      Signed-off-by: NYoshihiro Kaneko <ykaneko0929@gmail.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      4d6a949c
  7. 14 11月, 2014 2 次提交
  8. 28 10月, 2014 1 次提交
  9. 03 8月, 2014 1 次提交
  10. 03 7月, 2014 1 次提交
  11. 12 6月, 2014 2 次提交
  12. 04 6月, 2014 2 次提交
  13. 14 5月, 2014 2 次提交
  14. 29 3月, 2014 1 次提交
    • B
      sh_eth: ensure pm_runtime cannot suspend the device during init · b5893a08
      Ben Dooks 提交于
      The pm_rumtime work queue is causing the device to be suspended during
      initialisation, thus the initialisation may not be able to access registers
      properly. As the code is called from a work queue, it is possible that this
      is not seen from certain configurations/builds due to the asynchronos
      nature of the code.
      
      Another issue has also been found where the network device registration
      calls back into the driver thus causing further pm_runtime calls that
      also caused issues with the MDIO bus code. This has now been checked
      and is the only place the MDIO can be called without the device open.
      
      Use pm_runtime_get_sync() and pm_runtime_put() to ensure that the
      pm system does not suspend it during the probe() call and remove the
      now unnecessary pm_runtime_resume() call. Also add a call in the error
      path to call pm_runtime_disable().
      
      This fixes the external abort that can cause /sbin/init or other such
      init processed to die.
      Signed-off-by: NBen Dooks <ben.dooks@codethink.co.uk>
      Tested-by: NGeert Uytterhoeven <geert@linux-m68k.org>
      Acked-by: NLaurent Pinchart <laurent.pinchart@ideasonboard.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      b5893a08
  15. 21 3月, 2014 5 次提交
  16. 18 3月, 2014 4 次提交
  17. 14 3月, 2014 1 次提交
    • B
      sh_eth: update OF PHY registeration · 702eca02
      Ben Dooks 提交于
      If the sh_eth device is registered using OF, then the driver
      should call of_mdiobus_register() to register the PHYs described
      in the devicetree and then use of_phy_connect() to connect the
      PHYs to the device.
      
      This ensures that any PHYs registered in the device tree are
      appropriately connected to the parent devices nodes so that
      the PHY drivers can access their OF properties.
      Signed-off-by: NBen Dooks <ben.dooks@codethink.co.uk>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      702eca02
  18. 19 2月, 2014 1 次提交
  19. 14 2月, 2014 1 次提交