linux/drivers/net/can
Ahmed S. Darwish 889b77f7fd can: kvaser_usb: Reset all URB tx contexts upon channel close
Flooding the Kvaser CAN to USB dongle with multiple reads and
writes in very high frequency (*), closing the CAN channel while
all the transmissions are on (#), opening the device again (@),
then sending a small number of packets would make the driver
enter an almost infinite loop of:

[....]
[15959.853988] kvaser_usb 4-3:1.0 can0: cannot find free context
[15959.853990] kvaser_usb 4-3:1.0 can0: cannot find free context
[15959.853991] kvaser_usb 4-3:1.0 can0: cannot find free context
[15959.853993] kvaser_usb 4-3:1.0 can0: cannot find free context
[15959.853994] kvaser_usb 4-3:1.0 can0: cannot find free context
[15959.853995] kvaser_usb 4-3:1.0 can0: cannot find free context
[....]

_dragging the whole system down_ in the process due to the
excessive logging output.

Initially, this has caused random panics in the kernel due to a
buggy error recovery path.  That got fixed in an earlier commit.(%)
This patch aims at solving the root cause. -->

16 tx URBs and contexts are allocated per CAN channel per USB
device. Such URBs are protected by:

a) A simple atomic counter, up to a value of MAX_TX_URBS (16)
b) A flag in each URB context, stating if it's free
c) The fact that ndo_start_xmit calls are themselves protected
   by the networking layers higher above

After grabbing one of the tx URBs, if the driver noticed that all
of them are now taken, it stops the netif transmission queue.
Such queue is worken up again only if an acknowedgment was received
from the firmware on one of our earlier-sent frames.

Meanwhile, upon channel close (#), the driver sends a CMD_STOP_CHIP
to the firmware, effectively closing all further communication.  In
the high traffic case, the atomic counter remains at MAX_TX_URBS,
and all the URB contexts remain marked as active.  While opening
the channel again (@), it cannot send any further frames since no
more free tx URB contexts are available.

Reset all tx URB contexts upon CAN channel close.

(*) 50 parallel instances of `cangen0 -g 0 -ix`
(#) `ifconfig can0 down`
(@) `ifconfig can0 up`
(%) "can: kvaser_usb: Don't free packets when tight on URBs"

Signed-off-by: Ahmed S. Darwish <ahmed.darwish@valeo.com>
Cc: linux-stable <stable@vger.kernel.org>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2015-01-15 16:58:01 +01:00
..
c_can can: c_can: use regmap_update_bits() to modify RAMINIT register 2015-01-15 16:58:00 +01:00
cc770 Driver core patches for 3.19-rc1 2014-12-14 16:10:09 -08:00
m_can can: m_can: tag current CAN FD controllers as non-ISO 2015-01-15 16:57:59 +01:00
mscan Driver core patches for 3.19-rc1 2014-12-14 16:10:09 -08:00
sja1000 Driver core patches for 3.19-rc1 2014-12-14 16:10:09 -08:00
softing net: can: softing: drop owner assignment from platform_drivers 2014-10-20 16:21:01 +02:00
spi can: mcp251x: Use dmam_alloc_coherent 2014-08-18 01:03:43 +02:00
usb can: kvaser_usb: Reset all URB tx contexts upon channel close 2015-01-15 16:58:01 +01:00
at91_can.c net: can: drop owner assignment from platform_drivers 2014-10-20 16:20:59 +02:00
bfin_can.c net: can: drop owner assignment from platform_drivers 2014-10-20 16:20:59 +02:00
dev.c can: dev: fix crtlmode_supported check 2015-01-15 16:57:59 +01:00
flexcan.c Driver core patches for 3.19-rc1 2014-12-14 16:10:09 -08:00
grcan.c net: can: drop owner assignment from platform_drivers 2014-10-20 16:20:59 +02:00
janz-ican3.c net: can: drop owner assignment from platform_drivers 2014-10-20 16:20:59 +02:00
Kconfig drivers/net/can/Kconfig: Let CAN_AT91 depend on HAS_IOMEM 2014-10-03 15:52:03 -07:00
led.c can: only rename enabled led triggers when changing the netdev name 2014-05-27 15:05:41 +02:00
Makefile can: Enable -D__CHECK_ENDIAN__ for sparse by default 2014-12-07 21:22:06 +01:00
pch_can.c PCI: Remove DEFINE_PCI_DEVICE_TABLE macro use 2014-08-12 12:15:14 -06:00
rcar_can.c Driver core patches for 3.19-rc1 2014-12-14 16:10:09 -08:00
slcan.c can: slcan/vcan: eliminate banner[] variable, switch to pr_info() 2014-12-07 21:22:05 +01:00
ti_hecc.c net: can: drop owner assignment from platform_drivers 2014-10-20 16:20:59 +02:00
vcan.c can: slcan/vcan: eliminate banner[] variable, switch to pr_info() 2014-12-07 21:22:05 +01:00
xilinx_can.c Driver core patches for 3.19-rc1 2014-12-14 16:10:09 -08:00