All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH V4 0/7] CAN bus support for QEMU (SJA1000 PCI so far)
@ 2018-01-14 20:14 pisa
  2018-01-14 20:14 ` [Qemu-devel] [PATCH V4 1/7] CAN bus simple messages transport implementation for QEMU pisa
                   ` (7 more replies)
  0 siblings, 8 replies; 45+ messages in thread
From: pisa @ 2018-01-14 20:14 UTC (permalink / raw)
  To: qemu-devel
  Cc: Stefan Hajnoczi, Konrad Frederic, Deniz Eren, Oliver Hartkopp,
	Marek Vasut, Jan Kiszka, Oleksij Rempel, Pavel Pisa

From: Pavel Pisa <pisa@cmp.felk.cvut.cz>

Basic emulation of CAN bus controller and interconnection for QEMU.

Patches version 4:
Resolve comments longer than 80 characters to suppress
all warnings reported by scripts/checkpatch.pl.
Follow all suggestions from Frederic Konrad review.
Replace all printf and perror calls by QEMU equivalents.
Include Deniz Eren signed-off confimation.

Patches version 3:
Support to connect to host SocketCAN interface has been
separated from the core bus implementation. Only simple
statically initialize pointer to the connection function
is used, no QOM concept for now.
SJA1000 message filters redone and code unified where
possible.
Basic documentation added.
QEMU_ALIGNED used in definition of CAN frame structure,
structure and defines are separated from Linux/SocketCAN
API defined ones to allow to keep QEMU message format
independed from host system one. Check for correspondence
to socketcan defines added.

Patches version 2:
The bus emulation and the SJA1000 chip emulation introduced
by individual patches as suggested by Frederic Konrad.
Simple example board to test SJA1000 as single memory-mapped BAR
has been omitted in a new series because emulation of real
existing boards can provide same functions now.
Conditionalized debug printfs changed to be exposed to compiler
syntax check as suggested in review.

The work has been started by Jin Yang in the frame of GSoC 2013 slot
contributed by RTEMS project which has been looking for environment
to allow develop and test CAN drivers for multiple CPU architectures.

I have menthored the project and then done substantial code cleanup
and update to QOM. Deniz Eren then used emulation for SJA1000 base card
driver development for other operating system and contributed
PCM-3680I and MIOe-3680 support.

Some page about the project

  https://gitlab.fel.cvut.cz/canbus/qemu-canbus/wikis/home

FEE CTU GitLab repository with can-pci branch for 2.3, 2.4, 2.7, 2.8, 2.10
and 2.11 QEMU version is available in the repository

  https://gitlab.fel.cvut.cz/canbus/qemu-canbus/tree/can-pci

mirror at GitHub

  https://github.com/CTU-IIG/qemu

There are many areas for improvement and extension of the code still
(for example freeze and migration is not implemented. CAN controllers
use proper QOM model but bus/interconnection emulation uses simple broadcast
connection which is required for CAN, but it is not based on QEMU bus model).
I have tried to look into QEMU VLANs implementation but it
does not map straightforward to CAN and I would need some help/opinion
from more advanced developers to decide what is their right
mapping to CAN.

CAN-FD support would be interesting requires other developers/
companies contributions or setup of some project to allow invite
some students and colleagues from my university into project.

But I believe that (even in its actual state) provided solution
is great help for embedded systems developers when they can connect
SocketCAN from one or more embedded systems running in virtual
environment together or with Linux host SocketCAN virtual
or real bus interfaces.

We have even tested our generic CANopen device configured
for CANopen 401 profile for generic I/O running in the virtual
system which can control GPIO inputs/outputs through virtual
industrial I/O card.

Generally QEMU can be interesting setup which allows
to test complete industrial and automotive applications
in virtual environment even before real hardware is availabe.

Deniz Eren (2):
  CAN bus PCM-3680I PCI (dual SJA1000 channel) emulation added.
  CAN bus MIOe-3680 PCI (dual SJA1000 channel) emulation added.

Pavel Pisa (5):
  CAN bus simple messages transport implementation for QEMU
  CAN bus support to connect bust to Linux host SocketCAN interface.
  CAN bus SJA1000 chip register level emulation for QEMU
  CAN bus Kvaser PCI CAN-S (single SJA1000 channel) emulation added.
  QEMU CAN bus emulation documentation

 default-configs/pci.mak   |    3 +
 docs/can.txt              |   78 ++++
 hw/Makefile.objs          |    1 +
 hw/can/Makefile.objs      |   14 +
 hw/can/can_core.c         |  136 ++++++
 hw/can/can_host_stub.c    |   36 ++
 hw/can/can_kvaser_pci.c   |  375 +++++++++++++++++
 hw/can/can_mioe3680_pci.c |  336 +++++++++++++++
 hw/can/can_pcm3680_pci.c  |  336 +++++++++++++++
 hw/can/can_sja1000.c      | 1013 +++++++++++++++++++++++++++++++++++++++++++++
 hw/can/can_sja1000.h      |  167 ++++++++
 hw/can/can_socketcan.c    |  314 ++++++++++++++
 include/can/can_emu.h     |  131 ++++++
 13 files changed, 2940 insertions(+)
 create mode 100644 docs/can.txt
 create mode 100644 hw/can/Makefile.objs
 create mode 100644 hw/can/can_core.c
 create mode 100644 hw/can/can_host_stub.c
 create mode 100644 hw/can/can_kvaser_pci.c
 create mode 100644 hw/can/can_mioe3680_pci.c
 create mode 100644 hw/can/can_pcm3680_pci.c
 create mode 100644 hw/can/can_sja1000.c
 create mode 100644 hw/can/can_sja1000.h
 create mode 100644 hw/can/can_socketcan.c
 create mode 100644 include/can/can_emu.h

-- 
2.11.0

^ permalink raw reply	[flat|nested] 45+ messages in thread
* Re: [Qemu-devel] [PATCH V4 0/7] CAN bus support for QEMU (SJA1000 PCI so far)
@ 2018-01-31  4:07 Deniz Eren
  0 siblings, 0 replies; 45+ messages in thread
From: Deniz Eren @ 2018-01-31  4:07 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Pavel Pisa, Marek Vasut, Oliver Hartkopp, Stefan Hajnoczi,
	Philippe Mathieu-Daudé,
	qemu-devel, Oleksij Rempel, Konrad Frederic, Jan Kiszka,
	Marc-André Lureau

Hi Paolo,



Thank you for the correction! Greatly appreciated and it worked.



I tested all combinations of Linux host using virtual Socket-CAN and pcm3680 and mioe3680 client QEmu Linux environments using Linux Socket-CAN drivers, sending and receiving from each-other (all combinations; host-to-client, client-to-client, etc).


All tests passed!



Details:



Setup virtual Socket-CAN from host Linux system:

    $ sudo ip link add dev vcan0 type vcan
    $ sudo ip link set up vcan0
    $ sudo ip link add dev vcan1 type vcan
    $ sudo ip link set up vcan1

    $ sudo ip link set vcan0 txqueuelen 15
    $ sudo ip link set vcan1 txqueuelen 15


Starting 2 x QEmu sessions from host Linux; one for pcm3680 and other for mioe3680:

    $ ./qemu-local/bin/qemu-system-i386 -hda sdd2gb-uno1483-16.04-2.0-dev.img -boot d -k en-us -object can-bus,id=canbus0 -object can-bus,id=canbus1 -object can-host-socketcan,id=canhost0,canbus=canbus0,if=vcan0 -object can-host-socketcan,id=canhost1,canbus=canbus1,if=vcan1 -device mioe3680_pci,canbus0=canbus0,canbus1=canbus1 -m size=2048 -netdev user,id=user.0 -device e1000,netdev=user.0 -redir tcp:5022::22 -enable-kvm &

    $ ./qemu-local/bin/qemu-system-i386 -hda sdd2gb-uno1483-16.04-2.0-dev-copy.img -boot d -k en-us -object can-bus,id=canbus0 -object can-bus,id=canbus1 -object can-host-socketcan,id=canhost0,canbus=canbus0,if=vcan0 -object can-host-socketcan,id=canhost1,canbus=canbus1,if=vcan1 -device pcm3680_pci,canbus0=canbus0,canbus1=canbus1 -m size=2048 -netdev user,id=user.0 -device e1000,netdev=user.0 -redir tcp:6022::22 -enable-kvm &

    
Login to client QEmu instances and setup CAN networks:

    $ ssh -Yp5022 user@localhost

    $ sudo ip link set can0 type can bitrate 250000
    $ sudo ip link set can1 type can bitrate 250000
    $ sudo ip link set up can0
    $ sudo ip link set up can1
    $ sudo ip link set can0 txqueuelen 15
    $ sudo ip link set can1 txqueuelen 15

    $ ssh -Yp6022 user@localhost

    $ ... similarly ...

Then tried all combinations of "candump vcan0/1" from host and "candump can0/1" from clients for transmission and reception to and from host to client and client to client.

user@:~$ candump can1
  can1  123   [8]  11 22 33 44 55 66 77 88
  can1  123   [8]  11 22 33 44 55 66 77 88
  can1  123   [8]  11 22 33 44 55 66 77 88

host:$ candump vcan0
  vcan0  123   [8]  11 22 33 44 55 66 77 88
  vcan0  123   [8]  11 22 33 44 55 66 77 88
  vcan0  123   [8]  11 22 33 44 55 66 77 88
  vcan0  123   [8]  11 22 33 44 55 66 77 88

All successful.







Best regards,
Deniz

On Jan 31, 2018, at 12:10 PM, Paolo Bonzini <pbonzini@redhat.com> wrote:


On 30/01/2018 20:08, Paolo Bonzini wrote:

On 30/01/2018 19:13, Deniz Eren wrote:
Hi Pavel, Paolo,


I tried to rerun my environment to test however it seems the interface has changed a little and my standard program options cause complaints. Unfortunately I don’t have too much time to dig through at the moment.


My standard startup command is:


$ ./qemu-local/bin/qemu-system-i386 -hda sdd2gb-uno1483-16.04-2.0-dev.img -boot d -k en-us -device mioe3680_pci,canbus1=canbus0,host1=vcan0,canbus2=canbus1,host2=vcan1 -m size=2048 -netdev user,id=user.0 -device e1000,netdev=user.0 -redir tcp:5022::22 -enable-kvm &


Yep, it's now like this:


./qemu-local/bin/qemu-system-i386 \
-hda sdd2gb-uno1483-16.04-2.0-dev.img -boot d -k en-us \
-object can-bus,id=canbus0 \
-object can-bus,id=canbus1 \
-object can-host-socketcan,id=canhost0,canbus=canbus0,ifname=vcan0 \
-object can-host-socketcan,id=canhost1,canbus=canbus1,ifname=vcan1 \
-device mioe3680_pci,canbus0=canbus0,canbus1=canbus1 \
-m size=2048 -netdev user,id=user.0 -device e1000,netdev=user.0 \
-redir tcp:5022::22 -enable-kvm

Sorry, all "ifname" are "if".

Paolo


Thanks,


Paolo








Best regards,
Deniz


Sent from my iPhone


Deniz Eren
+61 400 307 762


On 31 Jan 2018, at 9:12 am, Pavel Pisa <pisa@cmp.felk.cvut.cz> wrote:


Hello Paolo,


thanks much for conversion to acceptable QOM model.


On Tuesday 30 of January 2018 15:15:22 Paolo Bonzini wrote:
On 25/01/2018 22:33, Pavel Pisa wrote:
Hello Paolo,


thanks for suggestions. I understand and fully agree with your
request to switch to QOM. I have succeed with that for CAN devices
some time ago. It worth to be done for the rest of the objects
but I fear that I do not find time to complete QOMification
in reasonable future. Contributions/suggestions from other
are welcomed. I can look for students for GSoC at our university
or under other funding.


Please take a look at branch can-pci-qom of github.com/bonzini/qemu.git.
Apart from QOMification of the backend include, I simplified the IRQ
handling in can_kvaser_pci (fixing bugs too I think), and removed an
unnecessary mutex. I also moved the files to net/can and hw/net/can so
that in the future Jason (networking maintainer) can take care of pull
requests.


I might have broken something, and the top commit in particular is
completely untested.


I have run basic test with Linux kernel on both sides
for one kavser_pci card on guest side and vcan (no real interface)
on host side.


Mesages exchange tests passed and looks OK.


I have used next parameters


-object can-bus,id=canbus0 \
-device kvaser_pci,canbus=canbus0 \
-object can-host-socketcan,if=can0,canbus=canbus0,id=canbus0-socketcan


The id parameter is required for "can-host-socketcan" object.
Else next error is printed


qemu-system-x86_64: -object can-host-socketcan,if=can0,canbus=canbus0: Parameter 'id' is missing


If "-object can-bus,id=canbus0" is missing then next error is reported


qemu-system-x86_64: -object can-host-socketcan,if=can0,canbus=canbus0,id=canbus0-socketcan: Device 'canbus0' not found


I have inspected through monitor the state of objects


(qemu) qom-list /objects
canbus0-socketcan (child<can-host-socketcan>)
type (string)
canbus0 (child<can-bus>)


(qemu) info qom-tree
/machine (pc-i440fx-2.12-machine)
...
/peripheral-anon (container)
/device[1] (kvaser_pci)
/bus master[0] (qemu:memory-region)
/kvaser_pci-xilinx[0] (qemu:memory-region)
/kvaser_pci-s5920[0] (qemu:memory-region)
/kvaser_pci-sja[0] (qemu:memory-region)
/bus master container[0] (qemu:memory-region)
...




(qemu) qom-list /objects
canbus0-socketcan (child<can-host-socketcan>)
type (string)
canbus0 (child<can-bus>)


(qemu) qom-list /machine/peripheral-anon/device[1]
bus master container[0] (child<qemu:memory-region>)
canbus (link<can-bus>)
rombar (uint32)
hotpluggable (bool)
x-pcie-lnksta-dllla (bool)
kvaser_pci-sja[0] (child<qemu:memory-region>)
multifunction (bool)
hotplugged (bool)
parent_bus (link<bus>)
romfile (str)
kvaser_pci-s5920[0] (child<qemu:memory-region>)
x-pcie-extcap-init (bool)
command_serr_enable (bool)
addr (int32)
type (string)
legacy-addr (str)
kvaser_pci-xilinx[0] (child<qemu:memory-region>)
realized (bool)
bus master[0] (child<qemu:memory-region>)


From the user point of view, it would be nice if "can-bus"
can be populated when required automatically.


I am not sure, but may it be that it would worth to
push can-bus objects under some category/specific
container. The path /objects is quite wide.
Into something like /object/can-bus or /net/can.


But generally thanks much, the progress you have made
in one day is really great. I hope that others check
your branch. I have pushed your unmodified version into
"can-pci-qom" branch of my repo


https://gitlab.fel.cvut.cz/canbus/qemu-canbus/tree/can-pci-qom



It would be great if others can check that everything
works in their setup. I think that then it can be pushed
into mainline and some usability improvements can be
done/experiment with later.


Thanks much,




Pavel Pisa





^ permalink raw reply	[flat|nested] 45+ messages in thread

end of thread, other threads:[~2018-03-07 11:40 UTC | newest]

Thread overview: 45+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-14 20:14 [Qemu-devel] [PATCH V4 0/7] CAN bus support for QEMU (SJA1000 PCI so far) pisa
2018-01-14 20:14 ` [Qemu-devel] [PATCH V4 1/7] CAN bus simple messages transport implementation for QEMU pisa
2018-01-19 12:38   ` Philippe Mathieu-Daudé
2018-01-19 13:28     ` Pavel Pisa
2018-01-19 17:04     ` Pavel Pisa
2018-01-14 20:14 ` [Qemu-devel] [PATCH V4 2/7] CAN bus support to connect bust to Linux host SocketCAN interface pisa
2018-01-15  2:55   ` Philippe Mathieu-Daudé
2018-01-15 21:29     ` Pavel Pisa
2018-01-16  0:12       ` Philippe Mathieu-Daudé
2018-01-19  8:51         ` Pavel Pisa
2018-01-19 13:37           ` Philippe Mathieu-Daudé
2018-01-22 10:28             ` Stefan Hajnoczi
2018-01-19 13:37         ` Daniel P. Berrange
2018-01-19 12:57   ` Philippe Mathieu-Daudé
2018-01-19 13:01     ` Philippe Mathieu-Daudé
2018-01-14 20:14 ` [Qemu-devel] [PATCH V4 3/7] CAN bus SJA1000 chip register level emulation for QEMU pisa
2018-01-15  3:03   ` Philippe Mathieu-Daudé
2018-01-14 20:14 ` [Qemu-devel] [PATCH V4 4/7] CAN bus Kvaser PCI CAN-S (single SJA1000 channel) emulation added pisa
2018-01-15  3:09   ` Philippe Mathieu-Daudé
2018-03-06 15:29   ` Thomas Huth
2018-03-06 20:52     ` Pavel Pisa
2018-03-07 11:40       ` Paolo Bonzini
2018-01-14 20:14 ` [Qemu-devel] [PATCH V4 5/7] QEMU CAN bus emulation documentation pisa
2018-01-14 20:14 ` [Qemu-devel] [PATCH V4 6/7] CAN bus PCM-3680I PCI (dual SJA1000 channel) emulation added pisa
2018-01-15  3:12   ` Philippe Mathieu-Daudé
2018-01-19 13:15   ` Philippe Mathieu-Daudé
2018-01-14 20:14 ` [Qemu-devel] [PATCH V4 7/7] CAN bus MIOe-3680 " pisa
2018-01-19 13:13   ` Philippe Mathieu-Daudé
2018-01-22 11:35 ` [Qemu-devel] [PATCH V4 0/7] CAN bus support for QEMU (SJA1000 PCI so far) Philippe Mathieu-Daudé
2018-01-23 21:42   ` Pavel Pisa
2018-01-24 20:22     ` Pavel Pisa
2018-01-24 21:41       ` Philippe Mathieu-Daudé
2018-01-25  8:24         ` Pavel Pisa
2018-01-25 13:50           ` Deniz Eren
2018-01-25 13:58     ` Paolo Bonzini
2018-01-25 21:33       ` Pavel Pisa
2018-01-26 11:12         ` Paolo Bonzini
2018-01-28  9:02           ` Pavel Pisa
2018-01-29  7:43             ` Oleksij Rempel
2018-01-30 14:15         ` Paolo Bonzini
2018-01-30 22:12           ` Pavel Pisa
2018-01-31  0:13             ` Deniz Eren
2018-01-31  1:08               ` Paolo Bonzini
2018-01-31  1:10                 ` Paolo Bonzini
2018-01-31  4:07 Deniz Eren

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.