Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 41627cdb authored by David S. Miller's avatar David S. Miller
Browse files

Merge tag 'linux-can-next-for-4.19-20180727' of...

Merge tag 'linux-can-next-for-4.19-20180727' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can-next



Marc Kleine-Budde says:

====================
pull-request: can-next 2018-01-16

this is a pull request for net-next/master consisting of 38 patches.

Dan Murphy's patch fixes the path to a file in the comment of the CAN
Error Message Frame Mask structure.

A patch by Colin Ian King fixes a typo in the cc770 driver.

The next patch is by me an sorts the Kconfigand Makefile entries of the
CAN-USB driver subdir alphabetically.

The patch by Jakob Unterwurzacher adds support for the UCAN USB-CAN
adapter.

YueHaibing's patch replaces a open coded skb_put()+memset() by
skb_put_zero() in the CAN-dev infrastructure.

Zhu Yi provides a patch to enable multi-queue CAN devices.

Three patches by Luc Van Oostenryck fix the return value of several
driver's xmit function, I contribute a patch for the a fourth driver.

Fabio Estevam's patch switches the flexcan driver to SPDX identifier.

Two patches by Jia-Ju Bai replace the mdelay() by a usleep_range() in
the sja1000 drivers.

The next 6 patches are by Anssi Hannula and refactor the xilinx CAN
driver and add support for the xilinx CAN FD core.

A patch by Gustavo A. R. Silva adds fallthrough annotation to the
peak_usb driver.

5 patches by Stephane Grosjean for the peak CANFD driver do some
cleanups and provide more improvements for further firmware releases.

The remaining 13 patches are by Jimmy Assarsson and the first clean up
the kvaser_usb driver, so that the later patches add support for the
Kvaser USB hydra family.
====================

Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 4be90c79 1f6ed42c
Loading
Loading
Loading
Loading
+26 −9
Original line number Diff line number Diff line
@@ -2,20 +2,26 @@ Xilinx Axi CAN/Zynq CANPS controller Device Tree Bindings
---------------------------------------------------------

Required properties:
- compatible		: Should be "xlnx,zynq-can-1.0" for Zynq CAN
			  controllers and "xlnx,axi-can-1.00.a" for Axi CAN
			  controllers.
- reg			: Physical base address and size of the Axi CAN/Zynq
			  CANPS registers map.
- compatible		: Should be:
			  - "xlnx,zynq-can-1.0" for Zynq CAN controllers
			  - "xlnx,axi-can-1.00.a" for Axi CAN controllers
			  - "xlnx,canfd-1.0" for CAN FD controllers
- reg			: Physical base address and size of the controller
			  registers map.
- interrupts		: Property with a value describing the interrupt
			  number.
- interrupt-parent	: Must be core interrupt controller
- clock-names		: List of input clock names - "can_clk", "pclk"
			  (For CANPS), "can_clk" , "s_axi_aclk"(For AXI CAN)
- clock-names		: List of input clock names
			  - "can_clk", "pclk" (For CANPS),
			  - "can_clk", "s_axi_aclk" (For AXI CAN and CAN FD).
			  (See clock bindings for details).
- clocks		: Clock phandles (see clock bindings for details).
- tx-fifo-depth		: Can Tx fifo depth.
- rx-fifo-depth		: Can Rx fifo depth.
- tx-fifo-depth		: Can Tx fifo depth (Zynq, Axi CAN).
- rx-fifo-depth		: Can Rx fifo depth (Zynq, Axi CAN, CAN FD in
                          sequential Rx mode).
- tx-mailbox-count	: Can Tx mailbox buffer count (CAN FD).
- rx-mailbox-count	: Can Rx mailbox buffer count (CAN FD in mailbox Rx
			  mode).


Example:
@@ -42,3 +48,14 @@ For Axi CAN Dts file:
			tx-fifo-depth = <0x40>;
			rx-fifo-depth = <0x40>;
		};
For CAN FD Dts file:
	canfd_0: canfd@40000000 {
			compatible = "xlnx,canfd-1.0";
			clocks = <&clkc 0>, <&clkc 1>;
			clock-names = "can_clk", "s_axi_aclk";
			reg = <0x40000000 0x2000>;
			interrupt-parent = <&intc>;
			interrupts = <0 59 1>;
			tx-mailbox-count = <0x20>;
			rx-fifo-depth = <0x20>;
		};
+332 −0
Original line number Diff line number Diff line
=================
The UCAN Protocol
=================

UCAN is the protocol used by the microcontroller-based USB-CAN
adapter that is integrated on System-on-Modules from Theobroma Systems
and that is also available as a standalone USB stick.

The UCAN protocol has been designed to be hardware-independent.
It is modeled closely after how Linux represents CAN devices
internally. All multi-byte integers are encoded as Little Endian.

All structures mentioned in this document are defined in
``drivers/net/can/usb/ucan.c``.

USB Endpoints
=============

UCAN devices use three USB endpoints:

CONTROL endpoint
  The driver sends device management commands on this endpoint

IN endpoint
  The device sends CAN data frames and CAN error frames

OUT endpoint
  The driver sends CAN data frames on the out endpoint


CONTROL Messages
================

UCAN devices are configured using vendor requests on the control pipe.

To support multiple CAN interfaces in a single USB device all
configuration commands target the corresponding interface in the USB
descriptor.

The driver uses ``ucan_ctrl_command_in/out`` and
``ucan_device_request_in`` to deliver commands to the device.

Setup Packet
------------

=================  =====================================================
``bmRequestType``  Direction | Vendor | (Interface or Device)
``bRequest``       Command Number
``wValue``         Subcommand Number (16 Bit) or 0 if not used
``wIndex``         USB Interface Index (0 for device commands)
``wLength``        * Host to Device - Number of bytes to transmit
                   * Device to Host - Maximum Number of bytes to
                     receive. If the device send less. Commom ZLP
                     semantics are used.
=================  =====================================================

Error Handling
--------------

The device indicates failed control commands by stalling the
pipe.

Device Commands
---------------

UCAN_DEVICE_GET_FW_STRING
~~~~~~~~~~~~~~~~~~~~~~~~~

*Dev2Host; optional*

Request the device firmware string.


Interface Commands
------------------

UCAN_COMMAND_START
~~~~~~~~~~~~~~~~~~

*Host2Dev; mandatory*

Bring the CAN interface up.

Payload Format
  ``ucan_ctl_payload_t.cmd_start``

====  ============================
mode  or mask of ``UCAN_MODE_*``
====  ============================

UCAN_COMMAND_STOP
~~~~~~~~~~~~~~~~~~

*Host2Dev; mandatory*

Stop the CAN interface

Payload Format
  *empty*

UCAN_COMMAND_RESET
~~~~~~~~~~~~~~~~~~

*Host2Dev; mandatory*

Reset the CAN controller (including error counters)

Payload Format
  *empty*

UCAN_COMMAND_GET
~~~~~~~~~~~~~~~~

*Host2Dev; mandatory*

Get Information from the Device

Subcommands
^^^^^^^^^^^

UCAN_COMMAND_GET_INFO
  Request the device information structure ``ucan_ctl_payload_t.device_info``.

  See the ``device_info`` field for details, and
  ``uapi/linux/can/netlink.h`` for an explanation of the
  ``can_bittiming fields``.

  Payload Format
    ``ucan_ctl_payload_t.device_info``

UCAN_COMMAND_GET_PROTOCOL_VERSION

  Request the device protocol version
  ``ucan_ctl_payload_t.protocol_version``. The current protocol version is 3.

  Payload Format
    ``ucan_ctl_payload_t.protocol_version``

.. note:: Devices that do not implement this command use the old
          protocol version 1

UCAN_COMMAND_SET_BITTIMING
~~~~~~~~~~~~~~~~~~~~~~~~~~

*Host2Dev; mandatory*

Setup bittiming by sending the the structure
``ucan_ctl_payload_t.cmd_set_bittiming`` (see ``struct bittiming`` for
details)

Payload Format
  ``ucan_ctl_payload_t.cmd_set_bittiming``.

UCAN_SLEEP/WAKE
~~~~~~~~~~~~~~~

*Host2Dev; optional*

Configure sleep and wake modes. Not yet supported by the driver.

UCAN_FILTER
~~~~~~~~~~~

*Host2Dev; optional*

Setup hardware CAN filters. Not yet supported by the driver.

Allowed interface commands
--------------------------

==================  ===================  ==================
Legal Device State  Command              New Device State
==================  ===================  ==================
stopped             SET_BITTIMING        stopped
stopped             START                started
started             STOP or RESET        stopped
stopped             STOP or RESET        stopped
started             RESTART              started
any                 GET                  *no change*
==================  ===================  ==================

IN Message Format
=================

A data packet on the USB IN endpoint contains one or more
``ucan_message_in`` values. If multiple messages are batched in a USB
data packet, the ``len`` field can be used to jump to the next
``ucan_message_in`` value (take care to sanity-check the ``len`` value
against the actual data size).

.. _can_ucan_in_message_len:

``len`` field
-------------

Each ``ucan_message_in`` must be aligned to a 4-byte boundary (relative
to the start of the start of the data buffer). That means that there
may be padding bytes between multiple ``ucan_message_in`` values:

.. code::

    +----------------------------+ < 0
    |                            |
    |   struct ucan_message_in   |
    |                            |
    +----------------------------+ < len
              [padding]
    +----------------------------+ < round_up(len, 4)
    |                            |
    |   struct ucan_message_in   |
    |                            |
    +----------------------------+
                [...]

``type`` field
--------------

The ``type`` field specifies the type of the message.

UCAN_IN_RX
~~~~~~~~~~

``subtype``
  zero

Data received from the CAN bus (ID + payload).

UCAN_IN_TX_COMPLETE
~~~~~~~~~~~~~~~~~~~

``subtype``
  zero

The CAN device has sent a message to the CAN bus. It answers with a
list of of tuples <echo-ids, flags>.

The echo-id identifies the frame from (echos the id from a previous
UCAN_OUT_TX message). The flag indicates the result of the
transmission. Whereas a set Bit 0 indicates success. All other bits
are reserved and set to zero.

Flow Control
------------

When receiving CAN messages there is no flow control on the USB
buffer. The driver has to handle inbound message quickly enough to
avoid drops. I case the device buffer overflow the condition is
reported by sending corresponding error frames (see
:ref:`can_ucan_error_handling`)


OUT Message Format
==================

A data packet on the USB OUT endpoint contains one or more ``struct
ucan_message_out`` values. If multiple messages are batched into one
data packet, the device uses the ``len`` field to jump to the next
ucan_message_out value. Each ucan_message_out must be aligned to 4
bytes (relative to the start of the data buffer). The mechanism is
same as described in :ref:`can_ucan_in_message_len`.

.. code::

    +----------------------------+ < 0
    |                            |
    |   struct ucan_message_out  |
    |                            |
    +----------------------------+ < len
              [padding]
    +----------------------------+ < round_up(len, 4)
    |                            |
    |   struct ucan_message_out  |
    |                            |
    +----------------------------+
                [...]

``type`` field
--------------

In protocol version 3 only ``UCAN_OUT_TX`` is defined, others are used
only by legacy devices (protocol version 1).

UCAN_OUT_TX
~~~~~~~~~~~
``subtype``
  echo id to be replied within a CAN_IN_TX_COMPLETE message

Transmit a CAN frame. (parameters: ``id``, ``data``)

Flow Control
------------

When the device outbound buffers are full it starts sending *NAKs* on
the *OUT* pipe until more buffers are available. The driver stops the
queue when a certain threshold of out packets are incomplete.

.. _can_ucan_error_handling:

CAN Error Handling
==================

If error reporting is turned on the device encodes errors into CAN
error frames (see ``uapi/linux/can/error.h``) and sends it using the
IN endpoint. The driver updates its error statistics and forwards
it.

Although UCAN devices can suppress error frames completely, in Linux
the driver is always interested. Hence, the device is always started with
the ``UCAN_MODE_BERR_REPORT`` set. Filtering those messages for the
user space is done by the driver.

Bus OFF
-------

- The device does not recover from bus of automatically.
- Bus OFF is indicated by an error frame (see ``uapi/linux/can/error.h``)
- Bus OFF recovery is started by ``UCAN_COMMAND_RESTART``
- Once Bus OFF recover is completed the device sends an error frame
  indicating that it is on ERROR-ACTIVE state.
- During Bus OFF no frames are sent by the device.
- During Bus OFF transmission requests from the host are completed
  immediately with the success bit left unset.

Example Conversation
====================

#) Device is connected to USB
#) Host sends command ``UCAN_COMMAND_RESET``, subcmd 0
#) Host sends command ``UCAN_COMMAND_GET``, subcmd ``UCAN_COMMAND_GET_INFO``
#) Device sends ``UCAN_IN_DEVICE_INFO``
#) Host sends command ``UCAN_OUT_SET_BITTIMING``
#) Host sends command ``UCAN_COMMAND_START``, subcmd 0, mode ``UCAN_MODE_BERR_REPORT``
+1 −0
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ Contents:
   af_xdp
   batman-adv
   can
   can_ucan_protocol
   dpaa2/index
   e100
   e1000
+1 −1
Original line number Diff line number Diff line
@@ -73,7 +73,7 @@ MODULE_PARM_DESC(msgobj15_eff, "Extended 29-bit frames for message object 15 "

static int i82527_compat;
module_param(i82527_compat, int, 0444);
MODULE_PARM_DESC(i82527_compat, "Strict Intel 82527 comptibility mode "
MODULE_PARM_DESC(i82527_compat, "Strict Intel 82527 compatibility mode "
		 "without using additional functions");

/*
+7 −7
Original line number Diff line number Diff line
@@ -649,8 +649,7 @@ struct sk_buff *alloc_can_skb(struct net_device *dev, struct can_frame **cf)
	can_skb_prv(skb)->ifindex = dev->ifindex;
	can_skb_prv(skb)->skbcnt = 0;

	*cf = skb_put(skb, sizeof(struct can_frame));
	memset(*cf, 0, sizeof(struct can_frame));
	*cf = skb_put_zero(skb, sizeof(struct can_frame));

	return skb;
}
@@ -678,8 +677,7 @@ struct sk_buff *alloc_canfd_skb(struct net_device *dev,
	can_skb_prv(skb)->ifindex = dev->ifindex;
	can_skb_prv(skb)->skbcnt = 0;

	*cfd = skb_put(skb, sizeof(struct canfd_frame));
	memset(*cfd, 0, sizeof(struct canfd_frame));
	*cfd = skb_put_zero(skb, sizeof(struct canfd_frame));

	return skb;
}
@@ -703,7 +701,8 @@ EXPORT_SYMBOL_GPL(alloc_can_err_skb);
/*
 * Allocate and setup space for the CAN network device
 */
struct net_device *alloc_candev(int sizeof_priv, unsigned int echo_skb_max)
struct net_device *alloc_candev_mqs(int sizeof_priv, unsigned int echo_skb_max,
				    unsigned int txqs, unsigned int rxqs)
{
	struct net_device *dev;
	struct can_priv *priv;
@@ -715,7 +714,8 @@ struct net_device *alloc_candev(int sizeof_priv, unsigned int echo_skb_max)
	else
		size = sizeof_priv;

	dev = alloc_netdev(size, "can%d", NET_NAME_UNKNOWN, can_setup);
	dev = alloc_netdev_mqs(size, "can%d", NET_NAME_UNKNOWN, can_setup,
			       txqs, rxqs);
	if (!dev)
		return NULL;

@@ -734,7 +734,7 @@ struct net_device *alloc_candev(int sizeof_priv, unsigned int echo_skb_max)

	return dev;
}
EXPORT_SYMBOL_GPL(alloc_candev);
EXPORT_SYMBOL_GPL(alloc_candev_mqs);

/*
 * Free space of the CAN network device
Loading