Page 1 of 2

PCAN-USB FD Linux Driver Issues on Yocto Linux PowerPC

Posted: Wed 2. Aug 2017, 18:05
by austinsteamboat
Hello,
So I'm having some trouble getting the Peak Linux Driver working correctly on an embedded yocto-based linux image running on a PowerPC architecture. So to begin here are some details on my setup:

1. I'm using the PCAN-USB FD adapter.

2. I'm using a P2020RDB as my processor. It is a PowerPC architecture and defaults to big-endian.

3. I'm using the NXP provided SDK to generate a yocto based Linux Image. I've modified the default image to include popt.h, kernel headers, and support for native gcc compilation.

4. I'm using the Peak Linux Driver 8.4.0. I'm only installing char dev support and USB adapter support. My example instillation is:

Code: Select all

make KERNEL_LOCATION=/usr/src/kernel NET=NO PCI=NO PAR=NO PCC=NO DNG=NO PCIEC=NO ISA=NO
make KERNEL_LOCATION=/usr/src/kernel install
So the driver installs correctly. I've compared it to the same install process on an x86 Ubuntu 16.04 system and the logs all appear to be the same. I plug in the USB and the module loads correctly.

I've written basic code to interface to the USB adapter to transmit CAN FD messages with extended headers using the PCANFD API. I've tested the code on x86 Ubuntu 16.04 and it works correctly. The issue is that on the embedded P2020 board, the messages all default to CAN 2.0B using standard header.

The basic structure of my custom code is:

Code: Select all

fd = pcanfd_open(<the USB adapter with CAN FD settings>)
struct pcanfd_msg tx_msg;
// Then I populate tx_msg with extended header, bit rate shift, data length, and the payload
pcanfd_send_msg(fd,tx_msg);
I've confirmed by adding checks that the device opens and the messages send with no error reports. I've confirmed that the device does support CAN FD and that the device's clock, nominal rate, and data rate are set properly by the pcanfd_open call. It seems like the error comes in the tx_msg. In my message construction I'm setting extended headers, CAN-FD bit rate shift, and 64-byte payload. The device defaults to CAN 2.0B (no bit rate shift, confirmed with an o-scope), with std header length and 8-byte payload. To be clear this code works perfectly on x86 so I don't think it's a function of my code. This assertion is further validated because I see the exact same behavior when using the built-in CAN-FD test (pcanfdtst). Using that built-in test and configuring for the same options, the device always defaults to no bit rate shift, standard headers, and 8-byte payload (actually the max of that test anyways). The test printout on transmit shows that it's trying to send extended headers, but on the receive side (using an x86 laptop) the headers are in fact truncated to standard length.

So I need the adapter to support full CAN FD features. My questions:

1. Does anyone have an idea of what might be causing this behavior? My first guess is that it has to do with the endian-ness of the P2020 (big as opposed to x86's little). I only assume this because I observed an error caused by its endian-ness using different software on the P2020 that is unrelated to this effort.

2. What error could be occurring in either the message construction or the send message call to cause the device to default to these settings?

3. Is there a straightforward way to sniff the raw USB commands going to the adapter to confirm the error is occurring in the message send commands?

Any help would be greatly appreciated and I'm happy to clarify my setup or procedure.

Thanks,
-Austin

Re: PCAN-USB FD Linux Driver Issues on Yocto Linux PowerPC

Posted: Thu 3. Aug 2017, 09:04
by M.Maidhof
Hi,

as a first step, please build the driver with DBG=DEBUG, and check the relevant dmsg output.

Please also post the output of cat /proc/pcan

regards

Michael

Re: PCAN-USB FD Linux Driver Issues on Yocto Linux PowerPC

Posted: Thu 3. Aug 2017, 20:31
by austinsteamboat
Hi Michael,

Thanks for the help, I've re-installed with debug mode enabled. I'll post the results I got from dmsg and the cat call. The executive summary is that it seems like I am seeing an error reported by the kernel when I try to send 1 message (1 Mb Nominal rate, 2 Mb Data rate, 16 bytes: 00-0F with extended header and bit rate shift enabled). The error seems to be:

Code: Select all

pcan: ucan_encode_msgs_buffer(): err -61 while encoding msg *buffer_size=512 msg_len=36 msg_count=1
I'm going to try and install the debug driver on an x86 machine to see if I can duplicate the test and see what results I get there.

From cat /proc/pcan after I plugin the USB device:

Code: Select all

*------------- PEAK-System CAN interfaces (www.peak-system.com) -------------
*------------- Release_20170613_n (8.4.0) Jul 22 2017 11:42:32 --------------
*---------------------------- [dbg] [mod] [usb] -----------------------------
*--------------------- 1 interfaces @ major 250 found -----------------------
*n -type- -ndev- --base-- irq --btr- --read-- --write- --irqs-- -errors- status
32  usbfd   -NA-        0 001 0x001c 00000000 00000000 00000000 00000000 0x0000
From cat /proc/pcan after I transmit one message:

Code: Select all

*------------- PEAK-System CAN interfaces (www.peak-system.com) -------------
*------------- Release_20170613_n (8.4.0) Jul 22 2017 11:42:32 --------------
*---------------------------- [dbg] [mod] [usb] -----------------------------
*--------------------- 1 interfaces @ major 250 found -----------------------
*n -type- -ndev- --base-- irq --btr- --read-- --write- --irqs-- -errors- status
32  usbfd   -NA-        0 001 0x0014 00000001 00000001 00000002 00000000 0x0000
The dmesg output after I transmit one message:

Code: Select all

[  930.047245] pcan: pcan_bitrate_to_bittiming(2000000): tq=12 brp=1 tseg1=29 tseg2=10 sp=7500 sjw=1
[  930.054830] pcan: pcan_bittiming_normalize(clk=80000000): OUT=[brp=1 bitrate/real=2000000/2000000 bps tseg1=29 tseg2=10 sp=7500]
[  930.065109] pcan[32]: time=1500725110.254170s: opening CANFD1 with clock=80000000 Hz bitrate=1000000 bps dbitrate=2000000 bps (flags=00000004h)
[  930.076692] pcan[32]: nominal [brp=1 tseg1=59 tseg2=20 sjw=1]
[  930.081143] pcan[32]: data [brp=1 tseg1=29 tseg2=10 sjw=1]
[  930.085331] pcan: pcan_usb_device_open_fd(), minor = 32. (nOpenPaths=1)
[  930.085337] pcan: ucan_set_bus_off()
[  930.087603] pcan: pcan_usbfd_send_ucan_cmd(CAN1): ->EP#01
[  930.087606] pcan: Dumping sent cmd (16 bytes):
[  930.087608] pcan: 01 00 00 00 00 00 00 00 FF 03 00 00 00 00 00 00 
[  930.087769] pcan: pcan_usbfd_submit_cmd_end(CAN1) = 0
[  930.087778] pcan: pcan_usbfd_open_fd(CAN1, clk=80000000 Hz)
[  930.092070] pcan: ucan_usb_set_clck_domain(CAN1, 0x0)
[  930.092074] pcan: pcan_usbfd_send_ucan_cmd(CAN1): ->EP#01
[  930.092077] pcan: Dumping sent cmd (16 bytes):
[  930.092079] pcan: 80 00 00 00 00 00 00 00 FF 03 00 00 00 00 00 00 
[  930.092142] pcan: pcan_usbfd_submit_cmd_end(CAN1) = 0
[  930.092746] pcan: ucan_clr_err_counters()
[  930.095447] pcan: pcan_usbfd_send_ucan_cmd(CAN1): ->EP#01
[  930.095450] pcan: Dumping sent cmd (16 bytes):
[  930.095452] pcan: 0A 00 00 C0 00 00 00 00 FF 03 00 00 00 00 00 00 
[  930.095514] pcan: pcan_usbfd_submit_cmd_end(CAN1) = 0
[  930.095520] pcan: ucan_set_iso_mode(CAN1)
[  930.098236] pcan: ucan_set_options(CAN1, mask=0004h)
[  930.101903] pcan: pcan_usbfd_send_ucan_cmd(CAN1): ->EP#01
[  930.101910] pcan: Dumping sent cmd (16 bytes):
[  930.101913] pcan: 0B 00 04 00 00 00 00 00 FF 03 00 00 00 00 00 00 
[  930.102016] pcan: pcan_usbfd_submit_cmd_end(CAN1) = 0
[  930.102025] pcan: ucan_set_timing_fast(CAN1, btr=2000000 brp=1 tseg1=29 tseg2=10 sjw=1 tsam=0)
[  930.109349] pcan: pcan_usbfd_send_ucan_cmd(CAN1): ->EP#01
[  930.109357] pcan: Dumping sent cmd (16 bytes):
[  930.109361] pcan: 05 00 00 00 09 1C 00 00 FF 03 00 00 00 00 00 00 
[  930.109516] pcan: pcan_usbfd_submit_cmd_end(CAN1) = 0
[  930.109524] pcan: ucan_set_timing_slow(CAN1, btr=1000000 brp=1 tseg1=59 tseg2=20 sjw=1 tsam=0)
[  930.116848] pcan: pcan_usbfd_send_ucan_cmd(CAN1): ->EP#01
[  930.116856] pcan: Dumping sent cmd (16 bytes):
[  930.116859] pcan: 04 00 60 00 13 3A 00 00 FF 03 00 00 00 00 00 00 
[  930.117017] pcan: pcan_usbfd_submit_cmd_end(CAN1) = 0
[  930.117023] pcan: ucan_set_all_acceptance_filter()
[  930.120506] pcan: pcan_usbfd_send_ucan_cmd(CAN1): ->EP#01
[  930.120509] pcan: Dumping sent cmd (64/512 bytes):
[  930.120511] pcan: 06 00 00 00 FF FF FF FF 06 00 00 01 FF FF FF FF 
[  930.120530] pcan: 06 00 00 02 FF FF FF FF 06 00 00 03 FF FF FF FF 
[  930.120549] pcan: ...
[  930.120551] pcan: 00 00 00 00 C7 37 ED E0 C7 0E C6 A0 EF 00 7A 80 
[  930.120570] pcan: EF 24 FC 14 C7 2C 88 00 EF 00 7A 80 C0 83 57 60 
[  930.120640] pcan: pcan_usbfd_submit_cmd_end(CAN1) = 0
[  930.120646] pcan: pcan_usbfd_send_ucan_cmd(CAN1): ->EP#01
[  930.120649] pcan: Dumping sent cmd (16 bytes):
[  930.120651] pcan: 0C 00 00 00 00 00 00 20 FF 03 00 00 00 00 00 00 
[  930.120767] pcan: pcan_usbfd_submit_cmd_end(CAN1) = 0
[  930.120773] pcan: pcan_usbfd_send_ucan_cmd(CAN1): ->EP#01
[  930.120780] pcan: Dumping sent cmd (16 bytes):
[  930.120784] pcan: 0C 00 02 00 00 00 00 00 FF 03 00 00 00 00 00 00 
[  930.120890] pcan: pcan_usbfd_submit_cmd_end(CAN1) = 0
[  930.120895] pcan: pcan_usbfd_send_ucan_cmd(CAN1): ->EP#01
[  930.120898] pcan: Dumping sent cmd (16 bytes):
[  930.120900] pcan: 0B 00 01 00 00 00 00 80 FF 03 00 00 00 00 00 00 
[  930.121015] pcan: pcan_usbfd_submit_cmd_end(CAN1) = 0
[  930.121020] pcan: ucan_set_bus_on(PCAN-USB FD CAN1): NORMAL
[  930.125290] pcan: got 512 bytes URB, decoding it by packets of 4096 bytes:
[  930.130857] pcan: decoding @offset 0:
[  930.133214] pcan: pcan_sync_times() sync=897492428 (0.897492428) tv_ts=1500725126.074771
[  930.140032] pcan: pcan_usbfd_send_ucan_cmd(CAN1): ->EP#01
[  930.140039] pcan: Dumping sent cmd (16 bytes):
[  930.140042] pcan: 02 00 00 00 00 00 00 00 FF 03 00 00 00 00 00 00 
[  930.140143] pcan: pcan_usbfd_submit_cmd_end(CAN1) = 0
[  930.141274] pcan: got 512 bytes URB, decoding it by packets of 4096 bytes:
[  930.146842] pcan: decoding @offset 0:
[  930.149194] pcan: Dumping received msg (16 bytes):
[  930.149196] pcan: 10 00 03 00 EF EC 7E 35 00 00 00 00 00 00 00 00 
[  930.149218] pcan: got status msg: ts=0x357eecef-00000000 EP=0 EW=0 BO=0
[  930.149227] pcan: pcan_sync_decode(ts=897510639) sync=897492428 => diff=18211 1500725126.074771 + 18211 = 1500725126.092982 (now=1500725126.090782)
[  930.161143] pcan: ucan_post_status_msg(CAN1): bus_state=0 ts32=0x357eecef EP=0 EW=0 BO=0]
[  930.161147] pcan: pcan_handle_error_status(PCAN-USB FD CAN1, EW=0, EP=0): bus=0
[  930.167151] pcan: pcan_handle_error_active(PCAN-USB FD CAN1): bus=0 pf=effe5d00
[  930.173153] pcan: pcan32 enters ERROR_ACTIVE
[  930.176114] pcan: pcan_chardev_rx(CAN1): nOpenPaths=1 bExtended=1 pf[type=3 id=1 flags=3000080h]
[  930.183596] pcan: pcan_chardev_rx(): tv=1500725126.090782 s
[  930.187862] pcan: pcan_status_error_rx(PCAN-USB FD CAN1, pf[id=1]) bus=1 rx=0/1 tx=0/1
[  930.194474] pcan: pcan_fifo_foreach_back() 0 c7340000 c7340000
[  930.194478] pcan: pcan_fifo_put() 0 c7340000 c7340000
[  930.194528] pcan: pcanfd_dev_open(l=540): CAN1 TX engine goes to 3
[  930.199424] pcan: __pcan_ioctl(CAN1, cmd=2152757904): returns 0
[  930.204185] pcan: __pcan_ioctl(CAN1, cmd=3221519002)
[  930.207878] pcan: pcan_is_device_in_list(ef5121f0)
[  930.211376] pcan: __pcan_ioctl(CAN1, cmd=3221519002): returns 0
[  930.216047] pcan: __pcan_ioctl(CAN1, cmd=1079016081)
[  930.219731] pcan: pcan_is_device_in_list(ef5121f0)
[  930.223225] pcan: pcanfd_ioctl_get_init()
[  930.225935] pcan: __pcan_ioctl(CAN1, cmd=1079016081): returns 0
[  931.122099] pcan: got 512 bytes URB, decoding it by packets of 4096 bytes:
[  931.127669] pcan: decoding @offset 0:
[  931.130028] pcan: now=1500725127.071582 sync #1 =898492420 (1500725127.074763) dtv=996811 dts=999992 ttv_us=996811 tts_us=999992 => clk_drift=0
[  931.231761] pcan: __pcan_ioctl(CAN1, cmd=2153282197)
[  931.235432] pcan: pcan_is_device_in_list(ef5121f0)
[  931.238925] pcan: pcanfd_send_msg()
[  931.241110] pcan: pcan_fifo_put() 0 c7100000 c7100000
[  931.241114] pcan: pcanfd_send_msg(856): still 499 free items in Tx queue
[  931.246515] pcan: __pcan_dev_start_writing()
[  931.249476] pcan: ucan_encode_msgs_buffer()
[  931.249479] pcan: pcan_fifo_peek()) 1 c7100000 c7100058
[  931.249483] Encoding msg {type=2 id=badbeefh dlen=16 flg=10000ah}
[  931.249486] pcan: pcan_fifo_get() 1 c7100000 c7100058
[  931.249490] pcan: pcan_fifo_peek()) 0 c7100058 c7100058
[  931.249495] pcan: ucan_encode_msgs_buffer(): err -61 while encoding msg *buffer_size=512 msg_len=36 msg_count=1
[  931.249498] pcan: Dumping encoded buffer (40 bytes):
[  931.249500] pcan: 24 00 00 10 00 00 00 00 00 00 00 00 A0 00 00 32 
[  931.249519] pcan: EF BE AD 0B 00 01 02 03 04 05 06 07 08 09 0A 0B 
[  931.249538] pcan: 0C 0D 0E 0F 00 00 00 00 
[  931.249550] pcan: err=-61: total=0/512
[  931.251988] pcan: Dumping message sent to device (40 bytes):
[  931.251990] pcan: 24 00 00 10 00 00 00 00 00 00 00 00 A0 00 00 32 
[  931.252008] pcan: EF BE AD 0B 00 01 02 03 04 05 06 07 08 09 0A 0B 
[  931.252027] pcan: 0C 0D 0E 0F 00 00 00 00 
[  931.252038] pcan: submitting 40 bytes buffer to usb EP#2
[  931.256042] pcan: pcan_usb_write(l=428): CAN1 TX engine goes to 2
[  931.260844] pcan: __pcan_ioctl(CAN1, cmd=2153282197): returns 0
[  931.260975] pcan_usb_write_notify(): status=0 actual_length=40
[  931.260978] pcan: ucan_encode_msgs_buffer()
[  931.260980] pcan: pcan_fifo_peek()) 0 c7100058 c7100058
[  931.260983] pcan: ucan_encode_msgs_buffer(): err -61 while encoding msg *buffer_size=512 msg_len=0 msg_count=0
[  931.260985] pcan: err=-61: total=0/512
[  931.260988] pcan: pcan_usb_write(l=449): CAN1 TX engine goes to 3
[  931.277932] pcan: pcan_release()
[  931.277938] pcan: pcan_release_path(): minor=32, path=1
[  931.281901] pcan: preparing to wait: ucPhysicallyInstalled=1 fifo_empty=1 tx_engine_state=3 to=1000
[  931.289663] pcan: finished waiting: ucPhysicallyInstalled=1 fifo_empty=1 tx_engine_state=3 err=250
[  931.297333] pcan: pcan_release_path(l=430): CAN1 TX engine goes to 0
[  931.302394] pcan: pcan_usb_device_release(), minor=32 (nOpenPaths=0).
[  931.302398] pcan: pcan_usb_stop(CAN1), minor=32
[  931.302405] pcan: pcan_usbfd_close(CAN1): opened_count=1
[  931.302411] pcan: pcan_usbfd_send_ucan_cmd(CAN1): ->EP#01
[  931.302414] pcan: Dumping sent cmd (16 bytes):
[  931.302417] pcan: 0C 00 03 00 00 00 00 80 FF 03 00 00 00 00 00 00 
[  931.302483] pcan: pcan_usbfd_submit_cmd_end(CAN1) = 0
[  931.302489] pcan: have still 1 active URBs on interface
[  931.302492] pcan: ucan_set_bus_off()
[  931.354775] pcan: pcan_usbfd_send_ucan_cmd(CAN1): ->EP#01
[  931.354779] pcan: Dumping sent cmd (16 bytes):
[  931.354781] pcan: 01 00 00 00 00 00 00 00 FF 03 00 00 00 00 00 00 
[  931.354859] pcan: pcan_usbfd_submit_cmd_end(CAN1) = 0
[  931.354870] pcan: pcan32 back to UNKNWON
[  931.357501] pcan: pcan_usb_release(), minor = 32.
[  931.357505] pcan: pcan_usb_free_irq()
[  931.357513] pcanPCAN-USB FD CAN1: Tx FIFO released
[  931.361017] pcanPCAN-USB FD CAN1: Rx FIFO released

Re: PCAN-USB FD Linux Driver Issues on Yocto Linux PowerPC

Posted: Thu 3. Aug 2017, 20:59
by austinsteamboat
The dmesg output was being overwhelmed by bit timing correction reports so I pulled the messages log, here's the full report with the timing spam removed:

Code: Select all

Jul 22 11:50:27 cpuslicen kernel: usb 1-1: USB disconnect, device number 2
Jul 22 11:50:28 cpuslicen kernel: usb 1-1: new high-speed USB device number 3 using fsl-ehci
Jul 22 11:50:28 cpuslicen kernel: hub 1-1:1.0: USB hub found
Jul 22 11:50:28 cpuslicen kernel: hub 1-1:1.0: 4 ports detected
Jul 22 11:50:28 cpuslicen kernel: usb 1-1.4: new high-speed USB device number 4 using fsl-ehci
Jul 22 11:50:28 cpuslicen kernel: pcan: Release_20170613_n (be)
Jul 22 11:50:28 cpuslicen kernel: pcan: driver config [dbg] [mod] [usb] 
Jul 22 11:50:28 cpuslicen kernel: pcan: driver start time=1500724228.853397 s.
Jul 22 11:50:28 cpuslicen kernel: pcan: DEBUG is switched on
Jul 22 11:50:28 cpuslicen kernel: pcan: new high speed usb adapter with 1 CAN controller(s) detected
Jul 22 11:50:28 cpuslicen kernel: pcan: pcan_usbfd_init(bus=1 port=4 parent_port=1)
Jul 22 11:50:28 cpuslicen kernel: pcan: PCAN-USB FD (01h PCB01h) fw v2.1.0
Jul 22 11:50:28 cpuslicen kernel: pcan: ucan_soft_init(usbfd, 12h)
Jul 22 11:50:28 cpuslicen kernel: pcan: pcan_btr0btr1_to_bittiming(BTR0BTR1=001ch)

Jul 22 11:50:40 cpuslicen kernel: pcan: pcan_bitrate_to_bittiming(2000000): tq=12 brp=1 tseg1=29 tseg2=10 sp=7500 sjw=1
Jul 22 11:50:40 cpuslicen kernel: pcan: pcan_bittiming_normalize(clk=80000000): OUT=[brp=1 bitrate/real=2000000/2000000 bps tseg1=29 tseg2=10 sp=7500]
Jul 22 11:50:40 cpuslicen kernel: pcan: pcan_add_device_in_list_ex(ef5121f0)
Jul 22 11:50:40 cpuslicen kernel: pcanpcan_usb_create_dev(): CAN0 devid=1h (1)
Jul 22 11:50:40 cpuslicen kernel: pcan: pcan_find_free_minor(from=32, until=-1)
Jul 22 11:50:40 cpuslicen kernel: pcan: pcan_sysfs_add_attrs(ef789a00="pcanusbfd32")
Jul 22 11:50:40 cpuslicen last message repeated 2 times
Jul 22 11:50:40 cpuslicen kernel: pcan: ucan_set_bus_off()
Jul 22 11:50:40 cpuslicen kernel: pcan: PCAN-USB FD channel 4 device number=1
Jul 22 11:50:40 cpuslicen kernel: pcan: pcan_usbfd_ctrl_init(l=961): CAN1 TX engine goes to 1
Jul 22 11:50:40 cpuslicen kernel: pcan: usb device minor 32 found
Jul 22 11:50:40 cpuslicen kernel: usbcore: registered new interface driver pcan
Jul 22 11:50:40 cpuslicen kernel: pcan: major 250.

Jul 22 11:54:36 cpuslicen kernel: pcan: pcan_bitrate_to_bittiming(500000): tq=125 brp=1 tseg1=13 tseg2=2 sp=8750 sjw=1
Jul 22 12:03:01 cpuslicen kernel: pcan: pcan_search_dev(): major,minor=250,32
Jul 22 12:03:01 cpuslicen kernel: pcan: pcan_open_path(): minor=32, opened path=0
Jul 22 12:03:01 cpuslicen kernel: pcanPCAN-USB FD CAN1: 500 items Rx FIFO allocated
Jul 22 12:03:01 cpuslicen kernel: pcanPCAN-USB FD CAN1: 500 items Tx FIFO allocated
Jul 22 12:03:01 cpuslicen kernel: pcan: pcanfd_dev_reset(l=323): CAN1 TX engine goes to 0
Jul 22 12:03:01 cpuslicen kernel: pcan: PCAN-USB FD CAN1 rx=0 tx=0

Jul 22 12:03:01 cpuslicen kernel: pcan[32]: time=0.000000s: opening CANFD1 with clock=80000000 Hz bitrate=500000 bps dbitrate=2000000 bps (flags=00000004h)
Jul 22 12:03:01 cpuslicen kernel: pcan[32]: nominal [brp=1 tseg1=139 tseg2=20 sjw=1]
Jul 22 12:03:01 cpuslicen kernel: pcan[32]: data [brp=1 tseg1=29 tseg2=10 sjw=1]
Jul 22 12:03:01 cpuslicen kernel: pcan: ucan_set_bus_off()
Jul 22 12:03:01 cpuslicen kernel: pcan: pcan_usbfd_open_fd(CAN1, clk=80000000 Hz)
Jul 22 12:03:01 cpuslicen kernel: pcan: ucan_clr_err_counters()
Jul 22 12:03:01 cpuslicen kernel: pcan: ucan_set_iso_mode(CAN1)
Jul 22 12:03:01 cpuslicen kernel: pcan: ucan_set_options(CAN1, mask=0004h)
Jul 22 12:03:01 cpuslicen kernel: pcan: ucan_set_timing_fast(CAN1, btr=2000000 brp=1 tseg1=29 tseg2=10 sjw=1 tsam=0)
Jul 22 12:03:01 cpuslicen kernel: pcan: ucan_set_timing_slow(CAN1, btr=500000 brp=1 tseg1=139 tseg2=20 sjw=1 tsam=0)
Jul 22 12:03:01 cpuslicen kernel: pcan: ucan_set_all_acceptance_filter()
Jul 22 12:03:01 cpuslicen kernel: pcan: ucan_set_bus_on(PCAN-USB FD CAN1): NORMAL
Jul 22 12:03:01 cpuslicen kernel: pcan: got 512 bytes URB, decoding it by packets of 4096 bytes:
Jul 22 12:03:01 cpuslicen kernel: pcan: decoding @offset 0:
Jul 22 12:03:01 cpuslicen kernel: pcan: got 512 bytes URB, decoding it by packets of 4096 bytes:
Jul 22 12:03:01 cpuslicen kernel: pcan: decoding @offset 0:
Jul 22 12:03:01 cpuslicen kernel: pcan: pcan_handle_error_status(PCAN-USB FD CAN1, EW=0, EP=0): bus=0
Jul 22 12:03:01 cpuslicen kernel: pcan: pcan_handle_error_active(PCAN-USB FD CAN1): bus=0 pf=effe5d00
Jul 22 12:03:01 cpuslicen kernel: pcan: pcan32 enters ERROR_ACTIVE
Jul 22 12:03:01 cpuslicen kernel: pcan: pcan_chardev_rx(CAN1): nOpenPaths=1 bExtended=1 pf[type=3 id=1 flags=80h]
Jul 22 12:03:01 cpuslicen kernel: pcan: pcan_chardev_rx(): tv=1500724981.333495 s
Jul 22 12:03:01 cpuslicen kernel: pcan: pcan_status_error_rx(PCAN-USB FD CAN1, pf[id=1]) bus=1 rx=0/1 tx=0/1
Jul 22 12:03:01 cpuslicen kernel: pcan: pcanfd_dev_open(l=540): CAN1 TX engine goes to 3
Jul 22 12:03:01 cpuslicen kernel: pcan: __pcan_ioctl(CAN1, cmd=2152757904)
Jul 22 12:03:01 cpuslicen kernel: pcan: pcan_is_device_in_list(ef5121f0)
Jul 22 12:03:01 cpuslicen kernel: pcan: pcanfd_ioctl_set_init()
Jul 22 12:03:01 cpuslicen kernel: pcan: pcanfd_dev_reset(l=323): CAN1 TX engine goes to 0
Jul 22 12:03:01 cpuslicen kernel: pcan: ucan_set_bus_off()
Jul 22 12:03:01 cpuslicen kernel: pcan: pcan32 back to UNKNWON
Jul 22 12:03:01 cpuslicen kernel: pcan: PCAN-USB FD CAN1 rx=0 tx=0

Jul 22 12:03:17 cpuslicen kernel: pcan: pcan_bittiming_normalize(clk=80000000): OUT=[brp=1 bitrate/real=2000000/2000000 bps tseg1=29 tseg2=10 sp=7500]
Jul 22 12:03:17 cpuslicen kernel: pcan[32]: time=1500724981.344423s: opening CANFD1 with clock=80000000 Hz bitrate=1000000 bps dbitrate=2000000 bps (flags=00000004h)
Jul 22 12:03:17 cpuslicen kernel: pcan[32]: nominal [brp=1 tseg1=59 tseg2=20 sjw=1]
Jul 22 12:03:17 cpuslicen kernel: pcan[32]: data [brp=1 tseg1=29 tseg2=10 sjw=1]
Jul 22 12:03:17 cpuslicen kernel: pcan: ucan_set_bus_off()
Jul 22 12:03:17 cpuslicen kernel: pcan: pcan_usbfd_open_fd(CAN1, clk=80000000 Hz)
Jul 22 12:03:17 cpuslicen kernel: pcan: ucan_clr_err_counters()
Jul 22 12:03:17 cpuslicen kernel: pcan: ucan_set_iso_mode(CAN1)
Jul 22 12:03:17 cpuslicen kernel: pcan: ucan_set_options(CAN1, mask=0004h)
Jul 22 12:03:17 cpuslicen kernel: pcan: ucan_set_timing_fast(CAN1, btr=2000000 brp=1 tseg1=29 tseg2=10 sjw=1 tsam=0)
Jul 22 12:03:17 cpuslicen kernel: pcan: ucan_set_timing_slow(CAN1, btr=1000000 brp=1 tseg1=59 tseg2=20 sjw=1 tsam=0)
Jul 22 12:03:17 cpuslicen kernel: pcan: ucan_set_all_acceptance_filter()
Jul 22 12:03:17 cpuslicen kernel: pcan: ucan_set_bus_on(PCAN-USB FD CAN1): NORMAL
Jul 22 12:03:17 cpuslicen kernel: pcan: got 512 bytes URB, decoding it by packets of 4096 bytes:
Jul 22 12:03:17 cpuslicen kernel: pcan: decoding @offset 0:
Jul 22 12:03:17 cpuslicen kernel: pcan: pcan_sync_times() sync=768581698 (0.768581698) tv_ts=1500724997.164491
Jul 22 12:03:17 cpuslicen kernel: pcan: got 512 bytes URB, decoding it by packets of 4096 bytes:
Jul 22 12:03:17 cpuslicen kernel: pcan: decoding @offset 0:
Jul 22 12:03:17 cpuslicen kernel: pcan: pcan_sync_decode(ts=768599922) sync=768581698 => diff=18224 1500724997.164491 + 18224 = 1500724997.182715 (now=1500724997.180507)
Jul 22 12:03:17 cpuslicen kernel: pcan: pcan_handle_error_status(PCAN-USB FD CAN1, EW=0, EP=0): bus=0
Jul 22 12:03:17 cpuslicen kernel: pcan: pcan_handle_error_active(PCAN-USB FD CAN1): bus=0 pf=effe5d00
Jul 22 12:03:17 cpuslicen kernel: pcan: pcan32 enters ERROR_ACTIVE
Jul 22 12:03:17 cpuslicen kernel: pcan: pcan_chardev_rx(CAN1): nOpenPaths=1 bExtended=1 pf[type=3 id=1 flags=3000080h]
Jul 22 12:03:17 cpuslicen kernel: pcan: pcan_chardev_rx(): tv=1500724997.180507 s
Jul 22 12:03:17 cpuslicen kernel: pcan: pcan_status_error_rx(PCAN-USB FD CAN1, pf[id=1]) bus=1 rx=0/1 tx=0/1
Jul 22 12:03:17 cpuslicen kernel: pcan: pcanfd_dev_open(l=540): CAN1 TX engine goes to 3
Jul 22 12:03:17 cpuslicen kernel: pcan: __pcan_ioctl(CAN1, cmd=2152757904): returns 0
Jul 22 12:03:17 cpuslicen kernel: pcan: __pcan_ioctl(CAN1, cmd=3221519002)
Jul 22 12:03:17 cpuslicen kernel: pcan: pcan_is_device_in_list(ef5121f0)
Jul 22 12:03:17 cpuslicen kernel: pcan: __pcan_ioctl(CAN1, cmd=3221519002): returns 0
Jul 22 12:03:17 cpuslicen kernel: pcan: __pcan_ioctl(CAN1, cmd=1079016081)
Jul 22 12:03:17 cpuslicen kernel: pcan: pcan_is_device_in_list(ef5121f0)
Jul 22 12:03:17 cpuslicen kernel: pcan: pcanfd_ioctl_get_init()
Jul 22 12:03:17 cpuslicen kernel: pcan: __pcan_ioctl(CAN1, cmd=1079016081): returns 0
Jul 22 12:03:18 cpuslicen kernel: pcan: got 512 bytes URB, decoding it by packets of 4096 bytes:
Jul 22 12:03:18 cpuslicen kernel: pcan: decoding @offset 0:
Jul 22 12:03:18 cpuslicen kernel: pcan: now=1500724998.161306 sync #1 =769581690 (1500724998.164483) dtv=996815 dts=999992 ttv_us=996815 tts_us=999992 => clk_drift=0
Jul 22 12:03:18 cpuslicen kernel: pcan: __pcan_ioctl(CAN1, cmd=2153282197)
Jul 22 12:03:18 cpuslicen kernel: pcan: pcan_is_device_in_list(ef5121f0)
Jul 22 12:03:18 cpuslicen kernel: pcan: pcanfd_send_msg()
Jul 22 12:03:18 cpuslicen kernel: pcan: pcanfd_send_msg(856): still 499 free items in Tx queue
Jul 22 12:03:18 cpuslicen kernel: pcan: __pcan_dev_start_writing()
Jul 22 12:03:18 cpuslicen kernel: pcan: err=-61: total=0/512
Jul 22 12:03:18 cpuslicen kernel: pcan: submitting 40 bytes buffer to usb EP#2
Jul 22 12:03:18 cpuslicen kernel: pcan: pcan_usb_write(l=428): CAN1 TX engine goes to 2
Jul 22 12:03:18 cpuslicen kernel: pcan: __pcan_ioctl(CAN1, cmd=2153282197): returns 0
Jul 22 12:03:18 cpuslicen kernel: pcan_usb_write_notify(): status=0 actual_length=40
Jul 22 12:03:18 cpuslicen kernel: pcan: err=-61: total=0/512
Jul 22 12:03:18 cpuslicen kernel: pcan: pcan_usb_write(l=449): CAN1 TX engine goes to 3
Jul 22 12:03:19 cpuslicen kernel: pcan: got 512 bytes URB, decoding it by packets of 4096 bytes:
Jul 22 12:03:19 cpuslicen kernel: pcan: decoding @offset 0:
Jul 22 12:03:19 cpuslicen kernel: pcan: now=1500724999.161255 sync #2 =770581692 (1500724999.164485) dtv=999949 dts=1000002 ttv_us=1996764 tts_us=1999994 => clk_drift=0
Jul 22 12:03:19 cpuslicen kernel: pcan: __pcan_ioctl(CAN1, cmd=2153282197)
Jul 22 12:03:19 cpuslicen kernel: pcan: pcan_is_device_in_list(ef5121f0)
Jul 22 12:03:19 cpuslicen kernel: pcan: pcanfd_send_msg()
Jul 22 12:03:19 cpuslicen kernel: pcan: pcanfd_send_msg(856): still 499 free items in Tx queue
Jul 22 12:03:19 cpuslicen kernel: pcan: __pcan_dev_start_writing()
Jul 22 12:03:19 cpuslicen kernel: pcan: err=-61: total=0/512
Jul 22 12:03:19 cpuslicen kernel: pcan: submitting 40 bytes buffer to usb EP#2
Jul 22 12:03:19 cpuslicen kernel: pcan: pcan_usb_write(l=428): CAN1 TX engine goes to 2
Jul 22 12:03:19 cpuslicen kernel: pcan: __pcan_ioctl(CAN1, cmd=2153282197): returns 0
Jul 22 12:03:19 cpuslicen kernel: pcan_usb_write_notify(): status=0 actual_length=40
Jul 22 12:03:19 cpuslicen kernel: pcan: err=-61: total=0/512
Jul 22 12:03:19 cpuslicen kernel: pcan: pcan_usb_write(l=449): CAN1 TX engine goes to 3
Jul 22 12:03:20 cpuslicen kernel: pcan: got 512 bytes URB, decoding it by packets of 4096 bytes:
Jul 22 12:03:20 cpuslicen kernel: pcan: decoding @offset 0:
Jul 22 12:03:20 cpuslicen kernel: pcan: now=1500725000.161323 sync #3 =771581695 (1500725000.164488) dtv=1000068 dts=1000003 ttv_us=2996832 tts_us=2999997 => clk_drift=0
Jul 22 12:03:20 cpuslicen kernel: pcan: __pcan_ioctl(CAN1, cmd=2153282197)
Jul 22 12:03:20 cpuslicen kernel: pcan: pcan_is_device_in_list(ef5121f0)
Jul 22 12:03:20 cpuslicen kernel: pcan: pcanfd_send_msg()
Jul 22 12:03:20 cpuslicen kernel: pcan: pcanfd_send_msg(856): still 499 free items in Tx queue
Jul 22 12:03:20 cpuslicen kernel: pcan: __pcan_dev_start_writing()
Jul 22 12:03:20 cpuslicen kernel: pcan: err=-61: total=0/512
Jul 22 12:03:20 cpuslicen kernel: pcan: submitting 40 bytes buffer to usb EP#2
Jul 22 12:03:20 cpuslicen kernel: pcan: pcan_usb_write(l=428): CAN1 TX engine goes to 2
Jul 22 12:03:20 cpuslicen kernel: pcan: __pcan_ioctl(CAN1, cmd=2153282197): returns 0
Jul 22 12:03:20 cpuslicen kernel: pcan_usb_write_notify(): status=0 actual_length=40
Jul 22 12:03:20 cpuslicen kernel: pcan: err=-61: total=0/512
Jul 22 12:03:20 cpuslicen kernel: pcan: pcan_usb_write(l=449): CAN1 TX engine goes to 3
Jul 22 12:03:21 cpuslicen kernel: pcan: got 512 bytes URB, decoding it by packets of 4096 bytes:
Jul 22 12:03:21 cpuslicen kernel: pcan: decoding @offset 0:
Jul 22 12:03:21 cpuslicen kernel: pcan: now=1500725001.161273 sync #4 =772581691 (1500725001.164484) dtv=999950 dts=999996 ttv_us=3996782 tts_us=3999993 => clk_drift=0
Jul 22 12:03:21 cpuslicen kernel: pcan: __pcan_ioctl(CAN1, cmd=2153282197)
Jul 22 12:03:21 cpuslicen kernel: pcan: pcan_is_device_in_list(ef5121f0)
Jul 22 12:03:21 cpuslicen kernel: pcan: pcanfd_send_msg()
Jul 22 12:03:21 cpuslicen kernel: pcan: pcanfd_send_msg(856): still 499 free items in Tx queue
Jul 22 12:03:21 cpuslicen kernel: pcan: __pcan_dev_start_writing()
Jul 22 12:03:21 cpuslicen kernel: pcan: err=-61: total=0/512
Jul 22 12:03:21 cpuslicen kernel: pcan: submitting 40 bytes buffer to usb EP#2
Jul 22 12:03:21 cpuslicen kernel: pcan: pcan_usb_write(l=428): CAN1 TX engine goes to 2
Jul 22 12:03:21 cpuslicen kernel: pcan: __pcan_ioctl(CAN1, cmd=2153282197): returns 0
Jul 22 12:03:21 cpuslicen kernel: pcan_usb_write_notify(): status=0 actual_length=40
Jul 22 12:03:21 cpuslicen kernel: pcan: err=-61: total=0/512
Jul 22 12:03:21 cpuslicen kernel: pcan: pcan_usb_write(l=449): CAN1 TX engine goes to 3
Jul 22 12:03:22 cpuslicen kernel: pcan: got 512 bytes URB, decoding it by packets of 4096 bytes:
Jul 22 12:03:22 cpuslicen kernel: pcan: decoding @offset 0:
Jul 22 12:03:22 cpuslicen kernel: pcan: now=1500725002.161223 sync #5 =773581694 (1500725002.164487) dtv=999950 dts=1000003 ttv_us=4996732 tts_us=4999996 => clk_drift=0
Jul 22 12:03:22 cpuslicen kernel: pcan: __pcan_ioctl(CAN1, cmd=2153282197)
Jul 22 12:03:22 cpuslicen kernel: pcan: pcan_is_device_in_list(ef5121f0)
Jul 22 12:03:22 cpuslicen kernel: pcan: pcanfd_send_msg()
Jul 22 12:03:22 cpuslicen kernel: pcan: pcanfd_send_msg(856): still 499 free items in Tx queue
Jul 22 12:03:22 cpuslicen kernel: pcan: __pcan_dev_start_writing()
Jul 22 12:03:22 cpuslicen kernel: pcan: err=-61: total=0/512
Jul 22 12:03:22 cpuslicen kernel: pcan: submitting 40 bytes buffer to usb EP#2
Jul 22 12:03:22 cpuslicen kernel: pcan: pcan_usb_write(l=428): CAN1 TX engine goes to 2
Jul 22 12:03:22 cpuslicen kernel: pcan: __pcan_ioctl(CAN1, cmd=2153282197): returns 0
Jul 22 12:03:22 cpuslicen kernel: pcan_usb_write_notify(): status=0 actual_length=40
Jul 22 12:03:22 cpuslicen kernel: pcan: err=-61: total=0/512
Jul 22 12:03:22 cpuslicen kernel: pcan: pcan_usb_write(l=449): CAN1 TX engine goes to 3
Jul 22 12:03:23 cpuslicen kernel: pcan: got 512 bytes URB, decoding it by packets of 4096 bytes:
Jul 22 12:03:23 cpuslicen kernel: pcan: decoding @offset 0:
Jul 22 12:03:23 cpuslicen kernel: pcan: now=1500725003.161294 sync #6 =774581689 (1500725003.164482) dtv=1000071 dts=999995 ttv_us=5996803 tts_us=5999991 => clk_drift=0
Jul 22 12:03:23 cpuslicen kernel: pcan: __pcan_ioctl(CAN1, cmd=2153282197)
Jul 22 12:03:23 cpuslicen kernel: pcan: pcan_is_device_in_list(ef5121f0)
Jul 22 12:03:23 cpuslicen kernel: pcan: pcanfd_send_msg()
Jul 22 12:03:23 cpuslicen kernel: pcan: pcanfd_send_msg(856): still 499 free items in Tx queue
Jul 22 12:03:23 cpuslicen kernel: pcan: __pcan_dev_start_writing()
Jul 22 12:03:23 cpuslicen kernel: pcan: err=-61: total=0/512
Jul 22 12:03:23 cpuslicen kernel: pcan: submitting 40 bytes buffer to usb EP#2
Jul 22 12:03:23 cpuslicen kernel: pcan: pcan_usb_write(l=428): CAN1 TX engine goes to 2
Jul 22 12:03:23 cpuslicen kernel: pcan: __pcan_ioctl(CAN1, cmd=2153282197): returns 0
Jul 22 12:03:23 cpuslicen kernel: pcan_usb_write_notify(): status=0 actual_length=40
Jul 22 12:03:23 cpuslicen kernel: pcan: err=-61: total=0/512
Jul 22 12:03:23 cpuslicen kernel: pcan: pcan_usb_write(l=449): CAN1 TX engine goes to 3
Jul 22 12:03:24 cpuslicen kernel: pcan: got 512 bytes URB, decoding it by packets of 4096 bytes:
Jul 22 12:03:24 cpuslicen kernel: pcan: decoding @offset 0:
Jul 22 12:03:24 cpuslicen kernel: pcan: now=1500725004.161239 sync #7 =775581691 (1500725004.164484) dtv=999945 dts=1000002 ttv_us=6996748 tts_us=6999993 => clk_drift=0
Jul 22 12:03:24 cpuslicen kernel: pcan: __pcan_ioctl(CAN1, cmd=2153282197)
Jul 22 12:03:24 cpuslicen kernel: pcan: pcan_is_device_in_list(ef5121f0)
Jul 22 12:03:24 cpuslicen kernel: pcan: pcanfd_send_msg()
Jul 22 12:03:24 cpuslicen kernel: pcan: pcanfd_send_msg(856): still 499 free items in Tx queue
Jul 22 12:03:24 cpuslicen kernel: pcan: __pcan_dev_start_writing()
Jul 22 12:03:24 cpuslicen kernel: pcan: err=-61: total=0/512
Jul 22 12:03:24 cpuslicen kernel: pcan: submitting 40 bytes buffer to usb EP#2
Jul 22 12:03:24 cpuslicen kernel: pcan: pcan_usb_write(l=428): CAN1 TX engine goes to 2
Jul 22 12:03:24 cpuslicen kernel: pcan: __pcan_ioctl(CAN1, cmd=2153282197): returns 0
Jul 22 12:03:24 cpuslicen kernel: pcan_usb_write_notify(): status=0 actual_length=40
Jul 22 12:03:24 cpuslicen kernel: pcan: err=-61: total=0/512
Jul 22 12:03:24 cpuslicen kernel: pcan: pcan_usb_write(l=449): CAN1 TX engine goes to 3
Jul 22 12:03:25 cpuslicen kernel: pcan: got 512 bytes URB, decoding it by packets of 4096 bytes:
Jul 22 12:03:25 cpuslicen kernel: pcan: decoding @offset 0:
Jul 22 12:03:25 cpuslicen kernel: pcan: now=1500725005.161316 sync #8 =776581695 (1500725005.164488) dtv=1000077 dts=1000004 ttv_us=7996825 tts_us=7999997 => clk_drift=0
Jul 22 12:03:25 cpuslicen kernel: pcan: __pcan_ioctl(CAN1, cmd=2153282197)
Jul 22 12:03:25 cpuslicen kernel: pcan: pcan_is_device_in_list(ef5121f0)
Jul 22 12:03:25 cpuslicen kernel: pcan: pcanfd_send_msg()
Jul 22 12:03:25 cpuslicen kernel: pcan: pcanfd_send_msg(856): still 499 free items in Tx queue
Jul 22 12:03:25 cpuslicen kernel: pcan: __pcan_dev_start_writing()
Jul 22 12:03:25 cpuslicen kernel: pcan: err=-61: total=0/512
Jul 22 12:03:25 cpuslicen kernel: pcan: submitting 40 bytes buffer to usb EP#2
Jul 22 12:03:25 cpuslicen kernel: pcan: pcan_usb_write(l=428): CAN1 TX engine goes to 2
Jul 22 12:03:25 cpuslicen kernel: pcan: __pcan_ioctl(CAN1, cmd=2153282197): returns 0
Jul 22 12:03:25 cpuslicen kernel: pcan_usb_write_notify(): status=0 actual_length=40
Jul 22 12:03:25 cpuslicen kernel: pcan: err=-61: total=0/512
Jul 22 12:03:25 cpuslicen kernel: pcan: pcan_usb_write(l=449): CAN1 TX engine goes to 3
Jul 22 12:03:26 cpuslicen kernel: pcan: got 512 bytes URB, decoding it by packets of 4096 bytes:
Jul 22 12:03:26 cpuslicen kernel: pcan: decoding @offset 0:
Jul 22 12:03:26 cpuslicen kernel: pcan: now=1500725006.161259 sync #9 =777581694 (1500725006.164487) dtv=999943 dts=999999 ttv_us=8996768 tts_us=8999996 => clk_drift=0
Jul 22 12:03:26 cpuslicen kernel: pcan: __pcan_ioctl(CAN1, cmd=2153282197)
Jul 22 12:03:26 cpuslicen kernel: pcan: pcan_is_device_in_list(ef5121f0)
Jul 22 12:03:26 cpuslicen kernel: pcan: pcanfd_send_msg()
Jul 22 12:03:26 cpuslicen kernel: pcan: pcanfd_send_msg(856): still 499 free items in Tx queue
Jul 22 12:03:26 cpuslicen kernel: pcan: __pcan_dev_start_writing()
Jul 22 12:03:26 cpuslicen kernel: pcan: err=-61: total=0/512
Jul 22 12:03:26 cpuslicen kernel: pcan: submitting 40 bytes buffer to usb EP#2
Jul 22 12:03:26 cpuslicen kernel: pcan: pcan_usb_write(l=428): CAN1 TX engine goes to 2
Jul 22 12:03:26 cpuslicen kernel: pcan: __pcan_ioctl(CAN1, cmd=2153282197): returns 0
Jul 22 12:03:26 cpuslicen kernel: pcan_usb_write_notify(): status=0 actual_length=40
Jul 22 12:03:26 cpuslicen kernel: pcan: err=-61: total=0/512
Jul 22 12:03:26 cpuslicen kernel: pcan: pcan_usb_write(l=449): CAN1 TX engine goes to 3
Jul 22 12:03:27 cpuslicen kernel: pcan: got 512 bytes URB, decoding it by packets of 4096 bytes:
Jul 22 12:03:27 cpuslicen kernel: pcan: decoding @offset 0:
Jul 22 12:03:27 cpuslicen kernel: pcan: now=1500725007.161205 sync #10 =778581694 (1500725007.164487) dtv=999946 dts=1000000 ttv_us=9996714 tts_us=9999996 => clk_drift=0
Jul 22 12:03:27 cpuslicen kernel: pcan: __pcan_ioctl(CAN1, cmd=2153282197)
Jul 22 12:03:27 cpuslicen kernel: pcan: pcan_is_device_in_list(ef5121f0)
Jul 22 12:03:27 cpuslicen kernel: pcan: pcanfd_send_msg()
Jul 22 12:03:27 cpuslicen kernel: pcan: pcanfd_send_msg(856): still 499 free items in Tx queue
Jul 22 12:03:27 cpuslicen kernel: pcan: __pcan_dev_start_writing()
Jul 22 12:03:27 cpuslicen kernel: pcan: err=-61: total=0/512
Jul 22 12:03:27 cpuslicen kernel: pcan: submitting 40 bytes buffer to usb EP#2
Jul 22 12:03:27 cpuslicen kernel: pcan: pcan_usb_write(l=428): CAN1 TX engine goes to 2
Jul 22 12:03:27 cpuslicen kernel: pcan: __pcan_ioctl(CAN1, cmd=2153282197): returns 0
Jul 22 12:03:27 cpuslicen kernel: pcan_usb_write_notify(): status=0 actual_length=40
Jul 22 12:03:27 cpuslicen kernel: pcan: err=-61: total=0/512
Jul 22 12:03:27 cpuslicen kernel: pcan: pcan_usb_write(l=449): CAN1 TX engine goes to 3
Jul 22 12:03:27 cpuslicen kernel: pcan: pcan_release_path(): minor=32, path=1
Jul 22 12:03:27 cpuslicen kernel: pcan: preparing to wait: ucPhysicallyInstalled=1 fifo_empty=1 tx_engine_state=3 to=1000
Jul 22 12:03:27 cpuslicen kernel: pcan: finished waiting: ucPhysicallyInstalled=1 fifo_empty=1 tx_engine_state=3 err=250
Jul 22 12:03:27 cpuslicen kernel: pcan: pcan_release_path(l=430): CAN1 TX engine goes to 0
Jul 22 12:03:27 cpuslicen kernel: pcan: ucan_set_bus_off()
Jul 22 12:03:27 cpuslicen kernel: pcan: pcan32 back to UNKNWON
Jul 22 12:03:27 cpuslicen kernel: pcanPCAN-USB FD CAN1: Tx FIFO released
Jul 22 12:03:27 cpuslicen kernel: pcanPCAN-USB FD CAN1: Rx FIFO released
Jul 22 12:05:10 cpuslicen kernel: pcan: pcan_search_dev(): major,minor=250,32
Jul 22 12:05:10 cpuslicen kernel: pcan: pcan_open_path(): minor=32, opened path=0
Jul 22 12:05:10 cpuslicen kernel: pcanPCAN-USB FD CAN1: 500 items Rx FIFO allocated
Jul 22 12:05:10 cpuslicen kernel: pcanPCAN-USB FD CAN1: 500 items Tx FIFO allocated
Jul 22 12:05:10 cpuslicen kernel: pcan: PCAN-USB FD CAN1 rx=0 tx=10

Jul 22 12:05:10 cpuslicen kernel: pcan: pcan_bittiming_normalize(clk=80000000): OUT=[brp=1 bitrate/real=2000000/2000000 bps tseg1=29 tseg2=10 sp=7500]
Jul 22 12:05:10 cpuslicen kernel: pcan[32]: time=1500724997.225811s: opening CANFD1 with clock=80000000 Hz bitrate=1000000 bps dbitrate=2000000 bps (flags=00000004h)
Jul 22 12:05:10 cpuslicen kernel: pcan[32]: nominal [brp=1 tseg1=59 tseg2=20 sjw=1]
Jul 22 12:05:10 cpuslicen kernel: pcan[32]: data [brp=1 tseg1=29 tseg2=10 sjw=1]
Jul 22 12:05:10 cpuslicen kernel: pcan: ucan_set_bus_off()
Jul 22 12:05:10 cpuslicen kernel: pcan: pcan_usbfd_open_fd(CAN1, clk=80000000 Hz)
Jul 22 12:05:10 cpuslicen kernel: pcan: ucan_clr_err_counters()
Jul 22 12:05:10 cpuslicen kernel: pcan: ucan_set_iso_mode(CAN1)
Jul 22 12:05:10 cpuslicen kernel: pcan: ucan_set_options(CAN1, mask=0004h)
Jul 22 12:05:10 cpuslicen kernel: pcan: ucan_set_timing_fast(CAN1, btr=2000000 brp=1 tseg1=29 tseg2=10 sjw=1 tsam=0)
Jul 22 12:05:10 cpuslicen kernel: pcan: ucan_set_timing_slow(CAN1, btr=1000000 brp=1 tseg1=59 tseg2=20 sjw=1 tsam=0)
Jul 22 12:05:10 cpuslicen kernel: pcan: ucan_set_all_acceptance_filter()
Jul 22 12:05:10 cpuslicen kernel: pcan: ucan_set_bus_on(PCAN-USB FD CAN1): NORMAL
Jul 22 12:05:10 cpuslicen kernel: pcan: got 512 bytes URB, decoding it by packets of 4096 bytes:
Jul 22 12:05:10 cpuslicen kernel: pcan: decoding @offset 0:
Jul 22 12:05:10 cpuslicen kernel: pcan: pcan_sync_times() sync=881610465 (0.881610465) tv_ts=1500725110.192860
Jul 22 12:05:10 cpuslicen kernel: pcan: got 512 bytes URB, decoding it by packets of 4096 bytes:
Jul 22 12:05:10 cpuslicen kernel: pcan: decoding @offset 0:
Jul 22 12:05:10 cpuslicen kernel: pcan: pcan_sync_decode(ts=881628675) sync=881610465 => diff=18210 1500725110.192860 + 18210 = 1500725110.211070 (now=1500725110.208874)
Jul 22 12:05:10 cpuslicen kernel: pcan: pcan_handle_error_status(PCAN-USB FD CAN1, EW=0, EP=0): bus=0
Jul 22 12:05:10 cpuslicen kernel: pcan: pcan_handle_error_active(PCAN-USB FD CAN1): bus=0 pf=effe5d00
Jul 22 12:05:10 cpuslicen kernel: pcan: pcan32 enters ERROR_ACTIVE
Jul 22 12:05:10 cpuslicen kernel: pcan: pcan_chardev_rx(CAN1): nOpenPaths=1 bExtended=1 pf[type=3 id=1 flags=3000080h]
Jul 22 12:05:10 cpuslicen kernel: pcan: pcan_chardev_rx(): tv=1500725110.208874 s
Jul 22 12:05:10 cpuslicen kernel: pcan: pcan_status_error_rx(PCAN-USB FD CAN1, pf[id=1]) bus=1 rx=0/1 tx=0/1
Jul 22 12:05:10 cpuslicen kernel: pcan: pcanfd_dev_open(l=540): CAN1 TX engine goes to 3
Jul 22 12:05:10 cpuslicen kernel: pcan: __pcan_ioctl(CAN1, cmd=2152757904)
Jul 22 12:05:10 cpuslicen kernel: pcan: pcan_is_device_in_list(ef5121f0)
Jul 22 12:05:10 cpuslicen kernel: pcan: pcanfd_ioctl_set_init()
Jul 22 12:05:10 cpuslicen kernel: pcan: pcanfd_dev_reset(l=323): CAN1 TX engine goes to 0
Jul 22 12:05:10 cpuslicen kernel: pcan: ucan_set_bus_off()
Jul 22 12:05:10 cpuslicen kernel: pcan: pcan32 back to UNKNWON
Jul 22 12:05:10 cpuslicen kernel: pcan: PCAN-USB FD CAN1 rx=0 tx=0

Jul 22 12:05:26 cpuslicen kernel: pcan[32]: time=1500725110.254170s: opening CANFD1 with clock=80000000 Hz bitrate=1000000 bps dbitrate=2000000 bps (flags=00000004h)
Jul 22 12:05:26 cpuslicen kernel: pcan[32]: nominal [brp=1 tseg1=59 tseg2=20 sjw=1]
Jul 22 12:05:26 cpuslicen kernel: pcan[32]: data [brp=1 tseg1=29 tseg2=10 sjw=1]
Jul 22 12:05:26 cpuslicen kernel: pcan: ucan_set_bus_off()
Jul 22 12:05:26 cpuslicen kernel: pcan: pcan_usbfd_open_fd(CAN1, clk=80000000 Hz)
Jul 22 12:05:26 cpuslicen kernel: pcan: ucan_clr_err_counters()
Jul 22 12:05:26 cpuslicen kernel: pcan: ucan_set_iso_mode(CAN1)
Jul 22 12:05:26 cpuslicen kernel: pcan: ucan_set_options(CAN1, mask=0004h)
Jul 22 12:05:26 cpuslicen kernel: pcan: ucan_set_timing_fast(CAN1, btr=2000000 brp=1 tseg1=29 tseg2=10 sjw=1 tsam=0)
Jul 22 12:05:26 cpuslicen kernel: pcan: ucan_set_timing_slow(CAN1, btr=1000000 brp=1 tseg1=59 tseg2=20 sjw=1 tsam=0)
Jul 22 12:05:26 cpuslicen kernel: pcan: ucan_set_all_acceptance_filter()
Jul 22 12:05:26 cpuslicen kernel: pcan: ucan_set_bus_on(PCAN-USB FD CAN1): NORMAL
Jul 22 12:05:26 cpuslicen kernel: pcan: got 512 bytes URB, decoding it by packets of 4096 bytes:
Jul 22 12:05:26 cpuslicen kernel: pcan: decoding @offset 0:
Jul 22 12:05:26 cpuslicen kernel: pcan: pcan_sync_times() sync=897492428 (0.897492428) tv_ts=1500725126.074771
Jul 22 12:05:26 cpuslicen kernel: pcan: got 512 bytes URB, decoding it by packets of 4096 bytes:
Jul 22 12:05:26 cpuslicen kernel: pcan: decoding @offset 0:
Jul 22 12:05:26 cpuslicen kernel: pcan: pcan_sync_decode(ts=897510639) sync=897492428 => diff=18211 1500725126.074771 + 18211 = 1500725126.092982 (now=1500725126.090782)
Jul 22 12:05:26 cpuslicen kernel: pcan: pcan_handle_error_status(PCAN-USB FD CAN1, EW=0, EP=0): bus=0
Jul 22 12:05:26 cpuslicen kernel: pcan: pcan_handle_error_active(PCAN-USB FD CAN1): bus=0 pf=effe5d00
Jul 22 12:05:26 cpuslicen kernel: pcan: pcan32 enters ERROR_ACTIVE
Jul 22 12:05:26 cpuslicen kernel: pcan: pcan_chardev_rx(CAN1): nOpenPaths=1 bExtended=1 pf[type=3 id=1 flags=3000080h]
Jul 22 12:05:26 cpuslicen kernel: pcan: pcan_chardev_rx(): tv=1500725126.090782 s
Jul 22 12:05:26 cpuslicen kernel: pcan: pcan_status_error_rx(PCAN-USB FD CAN1, pf[id=1]) bus=1 rx=0/1 tx=0/1
Jul 22 12:05:26 cpuslicen kernel: pcan: pcanfd_dev_open(l=540): CAN1 TX engine goes to 3
Jul 22 12:05:26 cpuslicen kernel: pcan: __pcan_ioctl(CAN1, cmd=2152757904): returns 0
Jul 22 12:05:26 cpuslicen kernel: pcan: __pcan_ioctl(CAN1, cmd=3221519002)
Jul 22 12:05:26 cpuslicen kernel: pcan: pcan_is_device_in_list(ef5121f0)
Jul 22 12:05:26 cpuslicen kernel: pcan: __pcan_ioctl(CAN1, cmd=3221519002): returns 0
Jul 22 12:05:26 cpuslicen kernel: pcan: __pcan_ioctl(CAN1, cmd=1079016081)
Jul 22 12:05:26 cpuslicen kernel: pcan: pcan_is_device_in_list(ef5121f0)
Jul 22 12:05:26 cpuslicen kernel: pcan: pcanfd_ioctl_get_init()
Jul 22 12:05:26 cpuslicen kernel: pcan: __pcan_ioctl(CAN1, cmd=1079016081): returns 0
Jul 22 12:05:27 cpuslicen kernel: pcan: got 512 bytes URB, decoding it by packets of 4096 bytes:
Jul 22 12:05:27 cpuslicen kernel: pcan: decoding @offset 0:
Jul 22 12:05:27 cpuslicen kernel: pcan: now=1500725127.071582 sync #1 =898492420 (1500725127.074763) dtv=996811 dts=999992 ttv_us=996811 tts_us=999992 => clk_drift=0
Jul 22 12:05:27 cpuslicen kernel: pcan: __pcan_ioctl(CAN1, cmd=2153282197)
Jul 22 12:05:27 cpuslicen kernel: pcan: pcan_is_device_in_list(ef5121f0)
Jul 22 12:05:27 cpuslicen kernel: pcan: pcanfd_send_msg()
Jul 22 12:05:27 cpuslicen kernel: pcan: pcanfd_send_msg(856): still 499 free items in Tx queue
Jul 22 12:05:27 cpuslicen kernel: pcan: __pcan_dev_start_writing()
Jul 22 12:05:27 cpuslicen kernel: pcan: err=-61: total=0/512
Jul 22 12:05:27 cpuslicen kernel: pcan: submitting 40 bytes buffer to usb EP#2
Jul 22 12:05:27 cpuslicen kernel: pcan: pcan_usb_write(l=428): CAN1 TX engine goes to 2
Jul 22 12:05:27 cpuslicen kernel: pcan: __pcan_ioctl(CAN1, cmd=2153282197): returns 0
Jul 22 12:05:27 cpuslicen kernel: pcan_usb_write_notify(): status=0 actual_length=40
Jul 22 12:05:27 cpuslicen kernel: pcan: err=-61: total=0/512
Jul 22 12:05:27 cpuslicen kernel: pcan: pcan_usb_write(l=449): CAN1 TX engine goes to 3
Jul 22 12:05:27 cpuslicen kernel: pcan: pcan_release_path(): minor=32, path=1
Jul 22 12:05:27 cpuslicen kernel: pcan: preparing to wait: ucPhysicallyInstalled=1 fifo_empty=1 tx_engine_state=3 to=1000
Jul 22 12:05:27 cpuslicen kernel: pcan: finished waiting: ucPhysicallyInstalled=1 fifo_empty=1 tx_engine_state=3 err=250
Jul 22 12:05:27 cpuslicen kernel: pcan: pcan_release_path(l=430): CAN1 TX engine goes to 0
Jul 22 12:05:27 cpuslicen kernel: pcan: ucan_set_bus_off()
Jul 22 12:05:27 cpuslicen kernel: pcan: pcan32 back to UNKNWON
Jul 22 12:05:27 cpuslicen kernel: pcanPCAN-USB FD CAN1: Tx FIFO released
Jul 22 12:05:27 cpuslicen kernel: pcanPCAN-USB FD CAN1: Rx FIFO released

Jul 22 12:25:12 cpuslicen kernel: pcan: pcan_search_dev(): major,minor=250,32
Jul 22 12:25:12 cpuslicen kernel: pcan: pcan_open_path(): minor=32, opened path=0
Jul 22 12:25:12 cpuslicen kernel: pcanPCAN-USB FD CAN1: 500 items Rx FIFO allocated
Jul 22 12:25:12 cpuslicen kernel: pcanPCAN-USB FD CAN1: 500 items Tx FIFO allocated
Jul 22 12:25:12 cpuslicen kernel: pcan: PCAN-USB FD CAN1 rx=0 tx=1

Jul 22 12:25:12 cpuslicen kernel: pcan[32]: nominal [brp=1 tseg1=59 tseg2=20 sjw=1]
Jul 22 12:25:12 cpuslicen kernel: pcan[32]: data [brp=1 tseg1=29 tseg2=10 sjw=1]
Jul 22 12:25:12 cpuslicen kernel: pcan: ucan_set_bus_off()
Jul 22 12:25:12 cpuslicen kernel: pcan: pcan_usbfd_open_fd(CAN1, clk=80000000 Hz)
Jul 22 12:25:12 cpuslicen kernel: pcan: ucan_clr_err_counters()
Jul 22 12:25:12 cpuslicen kernel: pcan: ucan_set_iso_mode(CAN1)
Jul 22 12:25:12 cpuslicen kernel: pcan: ucan_set_options(CAN1, mask=0004h)
Jul 22 12:25:12 cpuslicen kernel: pcan: ucan_set_timing_fast(CAN1, btr=2000000 brp=1 tseg1=29 tseg2=10 sjw=1 tsam=0)
Jul 22 12:25:12 cpuslicen kernel: pcan: ucan_set_timing_slow(CAN1, btr=1000000 brp=1 tseg1=59 tseg2=20 sjw=1 tsam=0)
Jul 22 12:25:12 cpuslicen kernel: pcan: ucan_set_all_acceptance_filter()
Jul 22 12:25:12 cpuslicen kernel: pcan: ucan_set_bus_on(PCAN-USB FD CAN1): NORMAL
Jul 22 12:25:12 cpuslicen kernel: pcan: got 512 bytes URB, decoding it by packets of 4096 bytes:
Jul 22 12:25:12 cpuslicen kernel: pcan: decoding @offset 0:
Jul 22 12:25:12 cpuslicen kernel: pcan: pcan_sync_times() sync=2084021983 (0.2084021983) tv_ts=1500726312.589421
Jul 22 12:25:12 cpuslicen kernel: pcan: got 512 bytes URB, decoding it by packets of 4096 bytes:
Jul 22 12:25:12 cpuslicen kernel: pcan: decoding @offset 0:
Jul 22 12:25:12 cpuslicen kernel: pcan: pcan_sync_decode(ts=2084040334) sync=2084021983 => diff=18351 1500726312.589421 + 18351 = 1500726312.607772 (now=1500726312.616737)
Jul 22 12:25:12 cpuslicen kernel: pcan: pcanfd_dev_open(l=540): CAN1 TX engine goes to 3
Jul 22 12:25:12 cpuslicen kernel: pcan: __pcan_ioctl(CAN1, cmd=2152757904)
Jul 22 12:25:12 cpuslicen kernel: pcan: pcan_is_device_in_list(ef5121f0)
Jul 22 12:25:12 cpuslicen kernel: pcan: pcanfd_ioctl_set_init()
Jul 22 12:25:12 cpuslicen kernel: pcan: pcanfd_dev_reset(l=323): CAN1 TX engine goes to 0
Jul 22 12:25:12 cpuslicen kernel: pcan: pcan_handle_error_status(PCAN-USB FD CAN1, EW=0, EP=0): bus=0
Jul 22 12:25:12 cpuslicen kernel: pcan: pcan_handle_error_active(PCAN-USB FD CAN1): bus=0 pf=effe5d00
Jul 22 12:25:12 cpuslicen kernel: pcan: pcan32 enters ERROR_ACTIVE
Jul 22 12:25:12 cpuslicen kernel: pcan: pcan_chardev_rx(CAN1): nOpenPaths=1 bExtended=1 pf[type=3 id=1 flags=3000080h]
Jul 22 12:25:12 cpuslicen kernel: pcan: pcan_chardev_rx(): tv=1500726312.607772 s
Jul 22 12:25:12 cpuslicen kernel: pcan: pcan_status_error_rx(PCAN-USB FD CAN1, pf[id=1]) bus=1 rx=0/1 tx=0/1
Jul 22 12:25:12 cpuslicen kernel: pcan: ucan_set_bus_off()
Jul 22 12:25:12 cpuslicen kernel: pcan: pcan32 back to UNKNWON
Jul 22 12:25:12 cpuslicen kernel: pcan: PCAN-USB FD CAN1 rx=0 tx=0

Jul 22 12:25:28 cpuslicen kernel: pcan: pcan_bittiming_normalize(clk=80000000): OUT=[brp=1 bitrate/real=2000000/2000000 bps tseg1=29 tseg2=10 sp=7500]
Jul 22 12:25:28 cpuslicen kernel: pcan[32]: time=1500726312.618287s: opening CANFD1 with clock=80000000 Hz bitrate=1000000 bps dbitrate=2000000 bps (flags=00000004h)
Jul 22 12:25:28 cpuslicen kernel: pcan[32]: nominal [brp=1 tseg1=59 tseg2=20 sjw=1]
Jul 22 12:25:28 cpuslicen kernel: pcan[32]: data [brp=1 tseg1=29 tseg2=10 sjw=1]
Jul 22 12:25:28 cpuslicen kernel: pcan: ucan_set_bus_off()
Jul 22 12:25:28 cpuslicen kernel: pcan: pcan_usbfd_open_fd(CAN1, clk=80000000 Hz)
Jul 22 12:25:28 cpuslicen kernel: pcan: ucan_clr_err_counters()
Jul 22 12:25:28 cpuslicen kernel: pcan: ucan_set_iso_mode(CAN1)
Jul 22 12:25:28 cpuslicen kernel: pcan: ucan_set_options(CAN1, mask=0004h)
Jul 22 12:25:28 cpuslicen kernel: pcan: ucan_set_timing_fast(CAN1, btr=2000000 brp=1 tseg1=29 tseg2=10 sjw=1 tsam=0)
Jul 22 12:25:28 cpuslicen kernel: pcan: ucan_set_timing_slow(CAN1, btr=1000000 brp=1 tseg1=59 tseg2=20 sjw=1 tsam=0)
Jul 22 12:25:28 cpuslicen kernel: pcan: ucan_set_all_acceptance_filter()
Jul 22 12:25:28 cpuslicen kernel: pcan: ucan_set_bus_on(PCAN-USB FD CAN1): NORMAL
Jul 22 12:25:28 cpuslicen kernel: pcan: got 512 bytes URB, decoding it by packets of 4096 bytes:
Jul 22 12:25:28 cpuslicen kernel: pcan: decoding @offset 0:
Jul 22 12:25:28 cpuslicen kernel: pcan: pcan_sync_times() sync=2099904569 (0.2099904569) tv_ts=1500726328.483151
Jul 22 12:25:28 cpuslicen kernel: pcan: got 512 bytes URB, decoding it by packets of 4096 bytes:
Jul 22 12:25:28 cpuslicen kernel: pcan: decoding @offset 0:
Jul 22 12:25:28 cpuslicen kernel: pcan: pcan_sync_decode(ts=2099922943) sync=2099904569 => diff=18374 1500726328.483151 + 18374 = 1500726328.501525 (now=1500726328.499413)
Jul 22 12:25:28 cpuslicen kernel: pcan: pcan_handle_error_status(PCAN-USB FD CAN1, EW=0, EP=0): bus=0
Jul 22 12:25:28 cpuslicen kernel: pcan: pcan_handle_error_active(PCAN-USB FD CAN1): bus=0 pf=effe5d00
Jul 22 12:25:28 cpuslicen kernel: pcan: pcan32 enters ERROR_ACTIVE
Jul 22 12:25:28 cpuslicen kernel: pcan: pcan_chardev_rx(CAN1): nOpenPaths=1 bExtended=1 pf[type=3 id=1 flags=3000080h]
Jul 22 12:25:28 cpuslicen kernel: pcan: pcan_chardev_rx(): tv=1500726328.499413 s
Jul 22 12:25:28 cpuslicen kernel: pcan: pcan_status_error_rx(PCAN-USB FD CAN1, pf[id=1]) bus=1 rx=0/1 tx=0/1
Jul 22 12:25:28 cpuslicen kernel: pcan: pcanfd_dev_open(l=540): CAN1 TX engine goes to 3
Jul 22 12:25:28 cpuslicen kernel: pcan: __pcan_ioctl(CAN1, cmd=2152757904): returns 0
Jul 22 12:25:28 cpuslicen kernel: pcan: __pcan_ioctl(CAN1, cmd=3221519002)
Jul 22 12:25:28 cpuslicen kernel: pcan: pcan_is_device_in_list(ef5121f0)
Jul 22 12:25:28 cpuslicen kernel: pcan: __pcan_ioctl(CAN1, cmd=3221519002): returns 0
Jul 22 12:25:28 cpuslicen kernel: pcan: __pcan_ioctl(CAN1, cmd=1079016081)
Jul 22 12:25:28 cpuslicen kernel: pcan: pcan_is_device_in_list(ef5121f0)
Jul 22 12:25:28 cpuslicen kernel: pcan: pcanfd_ioctl_get_init()
Jul 22 12:25:28 cpuslicen kernel: pcan: __pcan_ioctl(CAN1, cmd=1079016081): returns 0
Jul 22 12:25:29 cpuslicen kernel: pcan: got 512 bytes URB, decoding it by packets of 4096 bytes:
Jul 22 12:25:29 cpuslicen kernel: pcan: decoding @offset 0:
Jul 22 12:25:29 cpuslicen kernel: pcan: now=1500726329.479974 sync #1 =2100904561 (1500726329.483143) dtv=996823 dts=999992 ttv_us=996823 tts_us=999992 => clk_drift=0
Jul 22 12:25:29 cpuslicen kernel: pcan: __pcan_ioctl(CAN1, cmd=2153282197)
Jul 22 12:25:29 cpuslicen kernel: pcan: pcan_is_device_in_list(ef5121f0)
Jul 22 12:25:29 cpuslicen kernel: pcan: pcanfd_send_msg()
Jul 22 12:25:29 cpuslicen kernel: pcan: pcanfd_send_msg(856): still 499 free items in Tx queue
Jul 22 12:25:29 cpuslicen kernel: pcan: __pcan_dev_start_writing()
Jul 22 12:25:29 cpuslicen kernel: pcan: err=-61: total=0/512
Jul 22 12:25:29 cpuslicen kernel: pcan: submitting 40 bytes buffer to usb EP#2
Jul 22 12:25:29 cpuslicen kernel: pcan: pcan_usb_write(l=428): CAN1 TX engine goes to 2
Jul 22 12:25:29 cpuslicen kernel: pcan: __pcan_ioctl(CAN1, cmd=2153282197): returns 0
Jul 22 12:25:29 cpuslicen kernel: pcan_usb_write_notify(): status=0 actual_length=40
Jul 22 12:25:29 cpuslicen kernel: pcan: err=-61: total=0/512
Jul 22 12:25:29 cpuslicen kernel: pcan: pcan_usb_write(l=449): CAN1 TX engine goes to 3
Jul 22 12:25:29 cpuslicen kernel: pcan: pcan_release_path(): minor=32, path=1
Jul 22 12:25:29 cpuslicen kernel: pcan: preparing to wait: ucPhysicallyInstalled=1 fifo_empty=1 tx_engine_state=3 to=1000
Jul 22 12:25:29 cpuslicen kernel: pcan: finished waiting: ucPhysicallyInstalled=1 fifo_empty=1 tx_engine_state=3 err=250
Jul 22 12:25:29 cpuslicen kernel: pcan: pcan_release_path(l=430): CAN1 TX engine goes to 0
Jul 22 12:25:29 cpuslicen kernel: pcan: ucan_set_bus_off()
Jul 22 12:25:29 cpuslicen kernel: pcan: pcan32 back to UNKNWON
Jul 22 12:25:29 cpuslicen kernel: pcanPCAN-USB FD CAN1: Tx FIFO released
Jul 22 12:25:29 cpuslicen kernel: pcanPCAN-USB FD CAN1: Rx FIFO released
Jul 22 12:46:05 cpuslicen kernel: usb 1-1.4: USB disconnect, device number 4
Jul 22 12:46:05 cpuslicen kernel: pcan: pcan_sysfs_del_attrs(ef789a00="pcanusbfd32")
Jul 22 12:46:05 cpuslicen last message repeated 2 times
Jul 22 12:46:05 cpuslicen kernel: pcan: pcan_dev_remove_from_list(ef5121f0)

Re: PCAN-USB FD Linux Driver Issues on Yocto Linux PowerPC

Posted: Fri 4. Aug 2017, 00:45
by austinsteamboat
As an update, I've got the debug flag loaded on both the P2020 embedded PowerPC device and a 64-bit x86 server running Ubuntu 16.10. I've run identical transmit code on both and I've found the following:

1. The error I mentioned earlier shows up on both:

Code: Select all

ucan_encode_msgs_buffer(): err -61 while encoding msg *buffer_size=512 msg_len=0 msg_count=0
The P2020 does not transmit the message correctly while the x86 server does.

2. Running the exact same code on both I did find this interesting difference in the log outputs:

Code: Select all

x86 (good transmission):
 pcan: Dumping message sent to device (28 bytes):
 pcan: 18 00 00 10 00 00 00 00 00 00 00 00 10 00 32 00 
 pcan: EF BE AD 0B 39 00 00 00 00 00 00 00 

P2020 (bad transmission):
 pcan: Dumping message sent to device (28 bytes):
 pcan: 18 00 00 10 00 00 00 00 00 00 00 00 10 00 00 32 
 pcan: EF BE AD 0B 39 00 00 00 00 00 00 00 
Theres a value 0x32 that seems to be offset between the two.

Similarly, the pcan_usbfd_send_ucan_cmd calls seem to end up with wildly different messages:

Code: Select all

Good:
 pcan: pcan_usbfd_send_ucan_cmd(CAN1): ->EP#01
 pcan: Dumping sent cmd (64/512 bytes):
 pcan: 06 00 00 00 FF FF FF FF 06 00 00 01 FF FF FF FF 
 pcan: 06 00 00 02 FF FF FF FF 06 00 00 03 FF FF FF FF 
 pcan: ...
 pcan: 00 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
 pcan: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 

Bad:
 pcan: pcan_usbfd_send_ucan_cmd(CAN1): ->EP#01
 pcan: Dumping sent cmd (64/512 bytes):
 pcan: 06 00 00 00 FF FF FF FF 06 00 00 01 FF FF FF FF 
 pcan: 06 00 00 02 FF FF FF FF 06 00 00 03 FF FF FF FF 
 pcan: ...
 pcan: 00 00 00 00 C7 37 E0 00 C7 0E C8 40 EF 71 64 14 
 pcan: EF 24 FC 14 EF 18 A6 80 EF 00 7A 80 C0 83 57 60 
I will also note that I've looked at the /proc/pcan output of the x86 server:

Code: Select all

*------------- PEAK-System CAN interfaces (www.peak-system.com) -------------
*------------- Release_20170613_n (8.4.0) Aug  3 2017 12:39:00 --------------
*---------------------------- [dbg] [mod] [usb] -----------------------------
*--------------------- 1 interfaces @ major 244 found -----------------------
*n -type- -ndev- --base-- irq --btr- --read-- --write- --irqs-- -errors- status
32  usbfd   -NA-        0 001 0x0014 00000001 00000001 00000002 00000000 0x0000
Of note is that major is 244 for the x86 machine as opposed to 250 for the P2020 device. I'm not immediately sure what the significance of that is. Again, any help would be appreciated.
Thanks,
-Austin

Re: PCAN-USB FD Linux Driver Issues on Yocto Linux PowerPC

Posted: Fri 4. Aug 2017, 12:42
by M.Maidhof
Hello Austin,

thanks for the detailed information. Yes, it looks like an endianess issue on a PowerPc based system. Unfortunately we don“t have a PowerPC based system here for testing. Can you tell us where to buy such a board and what are the costs? Will it be possible for you to let our developers on your system by ssh?

It will be helpfull to contact us by email (please use our support email address), to discuss more details and arrange a ssh session next week with our driver developers.

regards

Michael

Re: PCAN-USB FD Linux Driver Issues on Yocto Linux PowerPC

Posted: Fri 4. Aug 2017, 18:03
by austinsteamboat
Hey Michael,

I'll follow up with you via the support e-mail address. In the meantime I'm going to keep try to track this down on my end. I have two follow up questions:

1. Does the netdev driver support CAN FD? From briefly looking into it, it seems like it just uses SocketCAN which sounds like it does support CAN FD, is that correct? I'm thinking I might try going down the netdev path and keeping my fingers crossed that I get around the PowerPC issues that way.

2. Again, it looks like the issue is caused at least in part by this 1-byte shift I observed:

Code: Select all

x86 (good transmission):
pcan: Dumping message sent to device (28 bytes):
pcan: 18 00 00 10 00 00 00 00 00 00 00 00 10 00 32 00
pcan: EF BE AD 0B 39 00 00 00 00 00 00 00

P2020 (bad transmission):
pcan: Dumping message sent to device (28 bytes):
pcan: 18 00 00 10 00 00 00 00 00 00 00 00 10 00 00 32
pcan: EF BE AD 0B 39 00 00 00 00 00 00 00 
In that transmission I was sending 1 CAN FD message with:

Code: Select all

    tx_msg.type = PCANFD_TYPE_CANFD_MSG;
    uint32_t msg_ID = 0x0BADBEEF;
    tx_msg.flags = PCANFD_MSG_EXT|
                           PCANFD_MSG_BRS|
                           PCANFD_MSG_SNG;
    tx_msg.data_len = 1;
    // While this isn't the exact syntax:
    tx_msg.data = 0x39;
So that 28 byte message I observed in the debug printout seemed to be the message including flags and payload. To re-iterate, the behavior I observe is that the message goes through, but defaults to CAN 2.0B with STD header so I see an ID of 0x6EF and if I send more than 8 bytes of data it just grabs the first 8 I tried to send and there's no bitrate shift in the data phase. That indicates to me that the issue is caused by either the message type not being picked up as CANFD or more likely the message flags not getting through properly.

So my question is: does anyone recognize that 28-byte message, is the ordering/format of that documented somewhere, and does anyone know where in the driver that message gets generated?

Thanks,
-Austin

Re: PCAN-USB FD Linux Driver Issues on Yocto Linux PowerPC

Posted: Fri 4. Aug 2017, 20:40
by austinsteamboat
As an update I've tracked down the issue just a bit more. By varying my flags and data size on my x86 ubuntu server with the debug module enabled, I found:

Code: Select all

pcan: Dumping message sent to device (28 bytes):
pcan: 18 00 00 10 00 00 00 00 00 00 00 00 10 00 32 00 
pcan: EF BE AD 0B 01 00 00 00 00 00 00 00 
This message was produced for:

Code: Select all

msg.type = CAN FD
msg.ID = 0xBADBEEF
msg.flags = Extended Headers, Bitrate shift
msg.data length = 1
msg.data = 0x01
The first byte 0x18 seems to indicate the data size to transmit in bytes - 4 (28 bytes-4 = 24 bytes = 0x18).
I haven't figured out the 4th byte. It always seems to be 0x10.
The 13th byte's MSB is the DLC.
The 15th byte handles both flags and msg type. 0x32 indicates CAN FD msg type, ext. header, and BRS. 0x00 indicates CAN 2.0B, std. header, and no BRS. So that seems to explain what I've been seeing because that 15th byte shows up in the 16th position on the PowerPC board. The 15th byte on the PowerPC always defaults to 0x00 which seems to cause the device to default to the state I've been seeing. I'll work to track down where that ordering gets set. To be clear I'm sending CAN FD transmit commands using the pcanfd_send_msg() function.

Re: PCAN-USB FD Linux Driver Issues on Yocto Linux PowerPC

Posted: Fri 4. Aug 2017, 23:44
by austinsteamboat
So I've tracked the issue down, wrote a temporary patch, and got it working. It did turn out to be an endian issue.

I found that the driver formats those receive and transmit packets I'd been observing in pcanfd_ucan.h:

Code: Select all

Lines 205 to 217
struct __packed ucan_rx_msg {
	__le16	size;
	__le16	type;
	__le32	ts_low;
	__le32	ts_high;
	__le32	tag_low;
	__le32	tag_high;
	u8	channel_dlc;
	u8	client;
	__le16	flags;
	__le32	can_id;
	u8	d[0];
};

...

Lines 274 to 284
struct __packed ucan_tx_msg {
	__le16	size;
	__le16	type;
	__le32	tag_low;
	__le32	tag_high;
	u8	channel_dlc;
	u8	client;
	u16	flags;
	__le32	can_id;
	u8	d[0];
};
To the developers credit, I'd say 99% of this code explicitly casts values as little endian. HOWEVER you'll notice in the ucan_tx_msg structure it still uses u16 for flags which on my big endian P2020 end up getting sent over backwards. So the first fix was to cast that u16 flag to __le16 like it is in the rx msgs. Then I also needed to run some fixes in pcanfd_ucan.c:

Code: Select all

// in the function ucan_encode_msg this chunk of code configures the ucan_tx_msg named tx_msg for sending out:
		memset(tx_msg, '\0', tx_msg_size);

		tx_msg->type = cpu_to_le16(UCAN_MSG_CAN_TX);
		tx_msg->size = cpu_to_le16(tx_msg_size);

		//tx_msg->flags = 0;
		if (can_msg.flags & PCANFD_MSG_EXT) {
			tx_msg->flags |= UCAN_MSG_EXT_ID;
			tx_msg->can_id = cpu_to_le32(can_msg.id & CAN_EFF_MASK);
		} else {
			tx_msg->can_id = cpu_to_le32(can_msg.id & CAN_SFF_MASK);
		}

		switch (can_msg.type) {

		case PCANFD_TYPE_CANFD_MSG:
			/* CAN-FD frames */
			tx_msg->flags |= UCAN_MSG_EXT_DATA_LEN;

			if (can_msg.flags & PCANFD_MSG_BRS)
				tx_msg->flags |= UCAN_MSG_BITRATE_SWITCH;

			if (can_msg.flags & PCANFD_MSG_ESI)
				tx_msg->flags |= UCAN_MSG_ERROR_STATE_IND;

		case PCANFD_TYPE_CAN20_MSG:
			/* CAN 2.0 frames */
			if (can_msg.flags & PCANFD_MSG_RTR)
				tx_msg->flags |= UCAN_MSG_RTR;

			if (can_msg.flags & PCANFD_MSG_SLF)
				tx_msg->flags |= UCAN_MSG_HW_SRR;

			break;
		}

		tx_msg->channel_dlc = UCAN_MSG_CHANNEL_DLC(dev->nChannel, dlc);

		memcpy(tx_msg->d, can_msg.data, can_msg.data_len);
So just like in the header, the developers were careful to cast most values to little endian explicitly, but again, the flags fall through the crack. My first kludgey fix was to simply define an extra variable u16 tmp_flag, update that internally through those case and if statements as opposed to the tx_msgs->flags calls and then bit shift the tmp_flag before assigning it tot he tx_msgs-> flags. This isn't a generic fix, but I think I can make it generic shortly. I'll experiment and report back.

With this being the issue, can someone at PEAK take this on as an official bug or bug fix for the next revision of the driver? For now I can just make patches and patch the necessary files as part of my yocto build when I install it on my deployed hardware.

Thanks,
-Austin

Re: PCAN-USB FD Linux Driver Issues on Yocto Linux PowerPC

Posted: Sat 5. Aug 2017, 00:45
by austinsteamboat
Here are my bug fixed files which SHOULD be generic:

driver/src/pcanfd_ucan.c:

Code: Select all

/*****************************************************************************
 * Copyright (C) 2014 PEAK System-Technik GmbH
 *
 * linux@peak-system.com
 * www.peak-system.com
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * Maintainer(s): Stephane Grosjean (s.grosjean@peak-system.com)
 *
 *****************************************************************************/

/*****************************************************************************
 *
 * pcan_ucan.c - the uCAN firmware global interface
 *
 * $Id: pcan_ucan.c 615 2015-01-26 22:38:55Z stephane $
 *
 *****************************************************************************/
/*#define DEBUG*/
/*#undef DEBUG*/

//#define DEBUG_SLOW_BITTIMINGS
//#define DEBUG_FAST_BITTIMINGS

/*
 * INCLUDES
 */
#include "src/pcan_common.h"
#include "src/pcan_main.h"

#include "src/pcanfd_core.h"		/* uCAN base common messages */
#include "src/pcanfd_ucan.h"		/* uCAN base common messages */

#ifdef USB_SUPPORT
#include "src/pcanfd_usb_fw.h"		/* uCAN USB devices specific messages */
#endif

#ifdef NETDEV_SUPPORT
#include "src/pcan_netdev.h"            /* for hotplug pcan_netdev_register() */
#else
#include <linux/can/dev.h>
#endif

#ifdef DEBUG
//#define DEBUG_BUS_LOAD	/* very (VERY) verbose */
#define DEBUG_BUS_MODE
#define DEBUG_RX
#else
//#define DEBUG_BUS_LOAD	/* very (VERY) verbose */
//#define DEBUG_RX
#endif

/* if defined, set the number of times an outgoing CAN message is repeated
 * in the outgoing stream. This enables to do some internal tests only!
 * This MUST not be defined in a production version! */
/* #define UCAN_TEST_TX_BURST		5 */

#ifndef get_can_dlc
/* some (very) old Kernels don't #define get_can_dlc() */
#define get_can_dlc(i)			(min_t(__u8, (i), 8))

#endif

/* Adapter timinig capabilities */
static const struct pcanfd_bittiming_range ucan_slow_capabilities = {

	.brp_min = 1,
	.brp_max = (1 << UCAN_TSLOW_BRP_BITS),
	.brp_inc = 1,

	.tseg1_min = 1,
	.tseg1_max = (1 << UCAN_TSLOW_TSGEG1_BITS),	// 64 or 256
	.tseg2_min = 1,
	.tseg2_max = (1 << UCAN_TSLOW_TSGEG2_BITS),	// 16 or 128
	.sjw_min = 1,
	.sjw_max = (1 << UCAN_TSLOW_SJW_BITS)		// 16 or 128
};

static const struct pcanfd_bittiming_range ucan_fast_capabilities = {

	.brp_min = 1,
	.brp_max = (1 << UCAN_TFAST_BRP_BITS),
	.brp_inc = 1,
	.tseg1_min = 1,
	.tseg1_max = (1 << UCAN_TFAST_TSGEG1_BITS),	// 16 or 32
	.tseg2_min = 1,
	.tseg2_max = (1 << UCAN_TFAST_TSGEG2_BITS),	// 8 or 16
	.sjw_min = 1,
	.sjw_max = (1 << UCAN_TFAST_SJW_BITS)		// 4 or 16
};

typedef struct __array_of_struct(pcanfd_available_clock, 6)
	pcanfd_6_clocks_device;

static const pcanfd_6_clocks_device ucan_clocks = {
	.count = 6,
	.list = {
		[0] = { .clock_Hz = 80*MHz, .clock_src = 80*MHz, },
		[1] = { .clock_Hz = 20*MHz, .clock_src = 240*MHz, },
		[2] = { .clock_Hz = 24*MHz, .clock_src = 240*MHz, },
		[3] = { .clock_Hz = 30*MHz, .clock_src = 240*MHz, },
		[4] = { .clock_Hz = 40*MHz, .clock_src = 240*MHz, },
		[5] = { .clock_Hz = 60*MHz, .clock_src = 240*MHz, },
	}
};

static const u8 pcan_fd_dlc2len[] = {
	0, 1, 2, 3, 4, 5, 6, 7,
	8, 12, 16, 20, 24, 32, 48, 64
};

/* get data length from can_dlc with sanitized can_dlc */
static u8 pcan_dlc2len(u8 can_dlc)
{
	return pcan_fd_dlc2len[can_dlc & 0x0F];
}

static const u8 pcan_fd_len2dlc[] = {
	0, 1, 2, 3, 4, 5, 6, 7, 8,	/* 0 - 8 */
	9, 9, 9, 9,			/* 9 - 12 */
	10, 10, 10, 10,			/* 13 - 16 */
	11, 11, 11, 11,			/* 17 - 20 */
	12, 12, 12, 12,			/* 21 - 24 */
	13, 13, 13, 13, 13, 13, 13, 13,	/* 25 - 32 */
	14, 14, 14, 14, 14, 14, 14, 14,	/* 33 - 40 */
	14, 14, 14, 14, 14, 14, 14, 14,	/* 41 - 48 */
	15, 15, 15, 15, 15, 15, 15, 15,	/* 49 - 56 */
	15, 15, 15, 15, 15, 15, 15, 15	/* 57 - 64 */
};

/* map the sanitized data length to an appropriate data length code */
static u8 pcan_len2dlc(u8 len)
{
	if (len > 64)
		return 0xF;

	return pcan_fd_len2dlc[len];
}

struct pcandev *ucan_init_cmd(struct pcandev *dev)
{
	dev->ucan.cmd_len = 0;
	return dev;
}

void *ucan_add_cmd(struct pcandev *dev, int cmd_op)
{
	const int cmd_size = sizeof(u64);
	struct ucan_command *cmd;

	if (dev->ucan.cmd_len + cmd_size > dev->ucan.cmd_size) {
#ifdef DEBUG_ALL
		pr_err("%s: %s(): failed to add cmd %03xh: "
		       "device cmd buffer not large enough (%u+%u > %u)\n",
		       DEVICE_NAME, __func__, cmd_op,
		       dev->ucan.cmd_len, cmd_size, dev->ucan.cmd_size);
#endif
		return NULL;
	}

	cmd = dev->ucan.cmd_head + dev->ucan.cmd_len;

	/* unused bits should be 0 */
	*(u64 *)cmd = 0;

	cmd->opcode_channel = UCAN_CMD_OPCODE_CHANNEL(dev->nChannel, cmd_op);
	dev->ucan.cmd_len += cmd_size;

	return cmd;
}

/* uCAN commands interface functions */

void *ucan_add_cmd_nop(struct pcandev *dev)
{
	return ucan_add_cmd(dev, UCAN_CMD_NOP);
}

static void *ucan_add_cmd_reset_mode(struct pcandev *dev)
{
	return ucan_add_cmd(dev, UCAN_CMD_RESET_MODE);
}

static void *ucan_add_cmd_normal_mode(struct pcandev *dev)
{
	return ucan_add_cmd(dev, UCAN_CMD_NORMAL_MODE);
}

static void *ucan_add_cmd_listen_only_mode(struct pcandev *dev)
{
	return ucan_add_cmd(dev, UCAN_CMD_LISTEN_ONLY_MODE);
}

static void *ucan_add_cmd_timing_slow(struct pcandev *dev,
					struct pcan_bittiming *pbr)
{
	struct ucan_timing_slow *cmd = ucan_add_cmd(dev, UCAN_CMD_TIMING_SLOW);
	if (cmd) {
#if 0
		pbr->brp = 10;
		pbr->tseg1 = 5;
		pbr->tseg2 = 2;
#endif
#ifdef DEBUG_SLOW_BITTIMINGS
		pr_info(DEVICE_NAME ": %s CAN%u = SLOW"
			"[brp=%u tseg1=%u tseg2=%u sjw=%u ts=%u]\n",
			dev->adapter->name, dev->nChannel+1,
			pbr->brp, pbr->tseg1, pbr->tseg2, pbr->sjw, pbr->tsam);
#endif
		cmd->sjw_t = UCAN_TSLOW_SJW_T(pbr->sjw - 1, pbr->tsam);
		cmd->tseg1 = UCAN_TSLOW_TSEG1(pbr->tseg1 - 1);
		cmd->tseg2 = UCAN_TSLOW_TSEG2(pbr->tseg2 - 1);
		cmd->brp = UCAN_TSLOW_BRP(pbr->brp - 1);

		cmd->ewl = 96;	/* default */
	}

	return cmd;
}

static void *ucan_add_cmd_timing_fast(struct pcandev *dev,
					struct pcan_bittiming *pbr)
{
	struct ucan_timing_fast *cmd = ucan_add_cmd(dev, UCAN_CMD_TIMING_FAST);
	if (cmd) {
#ifdef DEBUG_FAST_BITTIMINGS
		pr_info(DEVICE_NAME ": %s CAN%u = FAST"
			"[brp=%u tseg1=%u tseg2=%u sjw=%u]\n",
			dev->adapter->name, dev->nChannel+1,
			pbr->brp, pbr->tseg1, pbr->tseg2, pbr->sjw);
#endif
		cmd->sjw = UCAN_TFAST_SJW(pbr->sjw - 1);
		cmd->tseg1 = UCAN_TFAST_TSEG1(pbr->tseg1 - 1);
		cmd->tseg2 = UCAN_TFAST_TSEG2(pbr->tseg2 - 1);
		cmd->brp = UCAN_TFAST_BRP(pbr->brp - 1);
	}

	return cmd;
}

static void *ucan_add_cmd_tx_abort(struct pcandev *dev, u16 flags)
{
	struct ucan_tx_abort *cmd = ucan_add_cmd(dev, UCAN_CMD_TX_ABORT);
	if (cmd)
		cmd->flags = cpu_to_le16(flags);

	return cmd;
}

static void *ucan_add_cmd_rx_barrier(struct pcandev *dev)
{
	return ucan_add_cmd(dev, UCAN_CMD_RX_BARRIER);
}

static void *ucan_add_cmd_wr_err_cnt(struct pcandev *dev, u16 sel_mask,
			      u8 tx_counter, u8 rx_counter)
{
	struct ucan_wr_err_cnt *cmd = ucan_add_cmd(dev, UCAN_CMD_WR_ERR_CNT);
	if (cmd) {
		cmd->sel_mask = cpu_to_le16(sel_mask);
		cmd->tx_counter = tx_counter;
		cmd->rx_counter = rx_counter;
	}

	return cmd;
}

void *ucan_add_cmd_set_en_option(struct pcandev *dev, u16 mask)
{
	struct ucan_option *cmd = ucan_add_cmd(dev, UCAN_CMD_SET_EN_OPTION);
	if (cmd)
		cmd->mask = cpu_to_le16(mask);

	return cmd;
}

void *ucan_add_cmd_clr_dis_option(struct pcandev *dev, u16 mask)
{
	struct ucan_option *cmd = ucan_add_cmd(dev, UCAN_CMD_CLR_DIS_OPTION);
	if (cmd)
		cmd->mask = cpu_to_le16(mask);

	return cmd;
}

/* pcan interface functions */

int ucan_clr_err_counters(struct pcandev *dev)
{
#ifdef DEBUG
	pr_info("%s: %s()\n", DEVICE_NAME, __func__);
#endif
	if (!ucan_add_cmd_wr_err_cnt(ucan_init_cmd(dev),
				     UCAN_WRERRCNT_TE|UCAN_WRERRCNT_RE, 0, 0))
		return -EINVAL;

	dev->tx_error_counter = 0;
	dev->rx_error_counter = 0;

	/* send the command */
	return dev->ucan.ops->send_cmd(dev);
}

/* int ucan_set_all_acceptance_filter(struct pcandev *dev)
 */
int ucan_set_all_acceptance_filter(struct pcandev *dev)
{
	struct ucan_std_filter *cmd = NULL;
	const int n = 1 << UCAN_FLTSTD_ROW_IDX_BITS;
	int i, err;

#ifdef DEBUG
	pr_info("%s: %s()\n", DEVICE_NAME, __func__);
#endif

	/* build (and send) a command for each row */
	ucan_init_cmd(dev);
	for (i = 0; i < n; i++) {

		while (1) {
			cmd =  ucan_add_cmd(dev, UCAN_CMD_SET_STD_FILTER);
			if (cmd)
				break;

			/* not enough room? 1st, send the cmds */
			err = dev->ucan.ops->send_cmd(dev);
			if (err)
				return err;

			/* next, reset the cmd buffer and retry */
			ucan_init_cmd(dev);
		}

		cmd->idx = i;
		cmd->mask = cpu_to_le32(0xffffffff);
	}

	/* send the commands */
	return dev->ucan.ops->send_cmd(dev);
}

/* int ucan_set_msg_filters(struct pcandev *dev, u16 mask)
 */
int ucan_set_msg_filters(struct pcandev *dev, u16 mask)
{
#ifdef DEBUG
	pr_info("%s: %s()\n", DEVICE_NAME, __func__);
#endif
	if (!ucan_add_cmd_set_en_option(ucan_init_cmd(dev), mask))
		return -EINVAL;

	/* send the command */
	return dev->ucan.ops->send_cmd(dev);
}

/* int ucan_clr_msg_filters(struct pcandev *dev, u16 mask)
 */
int ucan_clr_msg_filters(struct pcandev *dev, u16 mask)
{
#ifdef DEBUG
	pr_info("%s: %s()\n", DEVICE_NAME, __func__);
#endif
	if (!ucan_add_cmd_clr_dis_option(ucan_init_cmd(dev), mask))
		return -EINVAL;

	/* send the command */
	return dev->ucan.ops->send_cmd(dev);
}

/* int ucan_tx_abort(struct pcandev *dev, u16 flags)
 */
int ucan_tx_abort(struct pcandev *dev, u16 flags)
{
#ifdef DEBUG
	pr_info("%s: %s(CAN%u, flags=%04xh)\n",
			DEVICE_NAME, __func__, dev->nChannel+1, flags);
#endif
	if (!ucan_add_cmd_tx_abort(ucan_init_cmd(dev), flags))
		return -EINVAL;

	/* send the command */
	return dev->ucan.ops->send_cmd(dev);
}

/* int ucan_rx_barrier(struct pcandev *dev)
 */
int ucan_rx_barrier(struct pcandev *dev)
{
#ifdef DEBUG
	pr_info("%s: %s(CAN%u)\n", DEVICE_NAME, __func__, dev->nChannel+1);
#endif
	if (!ucan_add_cmd_rx_barrier(ucan_init_cmd(dev)))
		return -EINVAL;

	/* send the command */
	return dev->ucan.ops->send_cmd(dev);
}

static int ucan_convert_BTR0BTR1(u16 btr0btr1,
				 const struct pcanfd_bittiming_range *pcap,
				 struct pcan_bittiming *pbr)
{
	struct pcan_bittiming_abs at_original, at_convert;
	const u32 sysclock = 80*MHz;

	pcan_btr0btr1_to_abstract(&at_original, btr0btr1);

	if (!pcan_convert_abstract(&at_convert, &at_original, pcap, sysclock))
		return -EINVAL;

	return pcan_abstract_to_bittiming(pbr, &at_convert, pcap, sysclock);
}

/* int ucan_set_bus_on(struct pcandev *dev)
 *
 * Set uCAN device bus controller to ON.
 */
int ucan_set_bus_on(struct pcandev *dev)
{
	int err;
	void *cmd = (dev->flags & PCAN_DEV_LISTEN_ONLY) ?
			ucan_add_cmd_listen_only_mode(ucan_init_cmd(dev)) :
			ucan_add_cmd_normal_mode(ucan_init_cmd(dev));

#ifdef DEBUG_BUS_MODE
	pr_info(DEVICE_NAME ": %s(%s CAN%u): %s\n",
			__func__, dev->adapter->name, dev->nChannel+1,
			(dev->flags & PCAN_DEV_LISTEN_ONLY) ?
				"LISTEN_ONLY" : "NORMAL");
#endif

	if (!cmd)
		return -EINVAL;

	/* send the command */
	err = dev->ucan.ops->send_cmd(dev);
	if (!err)
		dev->flags |= PCAN_DEV_BUS_ON;

	return err;
}

/* int ucan_set_bus_off(struct pcandev *dev)
 *
 * Set uCAN device bus controller to OFF.
 */
int ucan_set_bus_off(struct pcandev *dev)
{
	int err;

#ifdef DEBUG
	pr_info("%s: %s()\n", DEVICE_NAME, __func__);
#endif
	if (!ucan_add_cmd_reset_mode(ucan_init_cmd(dev)))
		return -EINVAL;

	/* wait a bit for last data to be written on CAN bus
	 * (5 ms is not enough if any data buffer was almost filled)
	 * This delay is mandatory when going to BUS_OFF with uCAN devices.
	 * (10 ms is enough for USB devices but not for PCI devices) */
	if (dev->tx_frames_counter > 0)
		mdelay(50);

	/* send the command */
	err = dev->ucan.ops->send_cmd(dev);
	if (!err)
		dev->flags &= ~PCAN_DEV_BUS_ON;

	return err;
}

int ucan_set_options(struct pcandev *dev, u16 opt_mask)
{
#ifdef DEBUG
	pr_info("%s: %s(CAN%u, mask=%04xh)\n",
			DEVICE_NAME, __func__, dev->nChannel+1, opt_mask);
#endif
	if (!ucan_add_cmd_set_en_option(ucan_init_cmd(dev), opt_mask))
		return -EINVAL;

	/* send the command */
	return dev->ucan.ops->send_cmd(dev);
}

int ucan_clr_options(struct pcandev *dev, u16 opt_mask)
{
#ifdef DEBUG
	pr_info("%s: %s(CAN%u, mask=%04xh)\n",
			DEVICE_NAME, __func__, dev->nChannel+1, opt_mask);
#endif
	if (!ucan_add_cmd_clr_dis_option(ucan_init_cmd(dev), opt_mask))
		return -EINVAL;

	/* send the command */
	return dev->ucan.ops->send_cmd(dev);
}

/* int ucan_set_timing_slow(struct pcandev *dev,
 *			     struct pcan_bittiming *pbr)
 */
static int ucan_set_timing_slow(struct pcandev *dev,
				struct pcan_bittiming *pbr)
{
#ifdef DEBUG
	pr_info("%s: %s(CAN%u, btr=%d brp=%d tseg1=%d tseg2=%d "
		"sjw=%d tsam=%d)\n", DEVICE_NAME, __func__, dev->nChannel+1,
		pbr->bitrate, pbr->brp, pbr->tseg1, pbr->tseg2, pbr->sjw,
		pbr->tsam);
#endif
	if (!ucan_add_cmd_timing_slow(ucan_init_cmd(dev), pbr))
		return -EINVAL;

	/* send the command */
	return dev->ucan.ops->send_cmd(dev);
}

/* int ucan_set_timing_fast(struct pcandev *dev,
 *			     struct pcan_bittiming *pbr)
 */
static int ucan_set_timing_fast(struct pcandev *dev,
				struct pcan_bittiming *pbr)
{
#ifdef DEBUG
	pr_info("%s: %s(CAN%u, btr=%d brp=%d tseg1=%d tseg2=%d "
		"sjw=%d tsam=%d)\n", DEVICE_NAME, __func__, dev->nChannel+1,
		pbr->bitrate, pbr->brp, pbr->tseg1, pbr->tseg2, pbr->sjw,
		pbr->tsam);
#endif
	if (!ucan_add_cmd_timing_fast(ucan_init_cmd(dev), pbr))
		return -EINVAL;

	/* send the command */
	return dev->ucan.ops->send_cmd(dev);
}

static inline int ucan_set_iso_mode(struct pcandev *dev)
{
#ifdef DEBUG
	pr_info("%s: %s(CAN%u)\n", DEVICE_NAME, __func__, dev->nChannel+1);
#endif
	return ucan_set_options(dev, UCAN_OPTION_ISO_MODE);
}

static inline int ucan_clr_iso_mode(struct pcandev *dev)
{
#ifdef DEBUG
	pr_info("%s: %s(CAN%u)\n", DEVICE_NAME, __func__, dev->nChannel+1);
#endif
	return ucan_clr_options(dev, UCAN_OPTION_ISO_MODE);
}

#if 0
#define BTR0BTR1_1MBPS		0x0014
#define BTR0BTR1_500KBPS	0x001c
#define BTR0BTR1_250KBPS	0x011c
#endif

/* int ucan_set_BTR0BTR1(struct pcandev *dev, u16 btr0btr1)
 */
int ucan_set_BTR0BTR1(struct pcandev *dev, u16 btr0btr1)
{
	struct pcan_bittiming bitrate;

#ifdef DEBUG
	pr_info("%s: %s()\n", DEVICE_NAME, __func__);
#endif
	switch (btr0btr1) {

#ifdef BTR0BTR1_1MBPS
	case BTR0BTR1_1MBPS:
		bitrate.tsam = 0;
		bitrate.sjw = 1;
		bitrate.tseg1 = 29;
		bitrate.tseg2 = 10;
		bitrate.brp = 2;
		break;
#endif
#ifdef BTR0BTR1_500KBPS
	case BTR0BTR1_500KBPS:
		bitrate.tsam = 0;
		bitrate.sjw = 1;
		bitrate.tseg1 = 34;
		bitrate.tseg2 = 5;
		bitrate.brp = 4;
		break;
#endif
	default:

		/* Need to convert this value for PCAN-USB (Pro) FD */
		if (!ucan_convert_BTR0BTR1(btr0btr1,
					&ucan_slow_capabilities, &bitrate)) {
			pr_err("%s: unable to convert BTR0BTR1 0x%04x\n",
				DEVICE_NAME, btr0btr1);
			pr_err("%s: won't be able to transfer data on CAN#%d\n",
				DEVICE_NAME, dev->nChannel);

			return -EINVAL;
		}
	}

	return ucan_set_timing_slow(dev, &bitrate);
}

int ucan_soft_init(struct pcandev *dev, char *szType, u16 wType)
{
#ifdef DEBUG
	pr_info("%s: %s(%s, %02Xh)\n", DEVICE_NAME, __func__, szType, wType);
#endif

	pcan_soft_init_ex(dev, szType, wType,
			(const struct pcanfd_available_clocks *)&ucan_clocks,
			&ucan_slow_capabilities,
			PCAN_DEV_BUSLOAD_RDY|PCAN_DEV_ERRCNT_RDY);

	dev->def_init_settings.flags |= PCANFD_INIT_FD;
	dev->dbittiming_caps = &ucan_fast_capabilities;

	pcan_bittiming_normalize(&dev->def_init_settings.data,
					dev->sysclock_Hz,
					&ucan_fast_capabilities);

	/* reset default init settings with new data bitrate specs */
	dev->init_settings = dev->def_init_settings;

	return 0;
}

/* pcan (chardev) interface */
int ucan_device_open(struct pcandev *dev, u16 btr0btr1, u8 ext, u8 listen_only)
{
	int err;

	/* reset error counters */
	err = ucan_clr_err_counters(dev);
	if (err)
		goto fail;

	err = ucan_set_BTR0BTR1(dev, btr0btr1);
	if (err)
		goto fail;

	/* Set filter mode: accept all */
	err = ucan_set_all_acceptance_filter(dev);
	if (err)
		goto fail;

	/* keep in memory listen only mode (set when bus goes on) */
	if (listen_only)
		dev->flags |= PCAN_DEV_LISTEN_ONLY;
	else
		dev->flags &= ~PCAN_DEV_LISTEN_ONLY;
fail:
	return err;
}

static int ucan_set_clock_domain(struct pcandev *dev, struct pcanfd_init *pfdi)
{
	int err = 0;

	/* set the uCAN clock domain */
	if (dev->ucan.ops->set_clk_domain) {

		err = dev->ucan.ops->set_clk_domain(dev, pfdi);

		/* looks like pfdi->clock_Hz was wrong: it must be
		 * reset to its default value and the bittimings must be
		 * computed accordingly and the clock domain reset as well. */
		if (err == -EINVAL) {

			/* uCAN device default clock value */
			pfdi->clock_Hz = ucan_clocks.list[0].clock_Hz;

			/* use bitrate bps value as reference to rebuild BRP,
			 * TSEGx and SJW accroding to the de fault clock */
			pcan_bitrate_to_bittiming(&pfdi->nominal,
							dev->bittiming_caps,
							pfdi->clock_Hz);
			if (pfdi->flags & PCANFD_INIT_FD)
				pcan_bitrate_to_bittiming(&pfdi->data,
							dev->dbittiming_caps,
							pfdi->clock_Hz);

			/* finaly, reset to default clock domain */
			err = dev->ucan.ops->set_clk_domain(dev, pfdi);
		}
	}

	return err;
}

/* pcanfd (chardev) interface */
int ucan_device_open_fd(struct pcandev *dev, struct pcanfd_init *pfdi)
{
	int err;

	err = ucan_set_clock_domain(dev, pfdi);
	if (err)
		goto fail;

	/* reset error counters */
	err = ucan_clr_err_counters(dev);
	if (err)
		goto fail;

	if (pfdi->flags & PCANFD_INIT_FD) {

		if (pfdi->flags & PCANFD_INIT_FD_NON_ISO) {
			err = ucan_clr_iso_mode(dev);
		} else {
			err = ucan_set_iso_mode(dev);
		}

		if (err)
			goto fail;

		err = ucan_set_timing_fast(dev, &pfdi->data);
		if (err)
			goto fail;
	}

	err = ucan_set_timing_slow(dev, &pfdi->nominal);
	if (err)
		goto fail;

	/* Set filter mode: accept all */
	err = ucan_set_all_acceptance_filter(dev);
	if (err)
		goto fail;

	/* keep in memory listen only mode (set when bus goes on) */
	if (pfdi->flags & PCANFD_INIT_LISTEN_ONLY)
		dev->flags |= PCAN_DEV_LISTEN_ONLY;
	else
		dev->flags &= ~PCAN_DEV_LISTEN_ONLY;

fail:
	return err;
}

/* int ucan_reset_path(struct pcandev *dev)
 *
 * After reset, the CAN core stays active.
 */
int ucan_reset_path(struct pcandev *dev)
{
	int err;

	/* reset the Tx path first */
	err = ucan_tx_abort(dev, UCAN_TX_ABORT_FLUSH);
	if (err)
		goto fail;

	/* reset the Rx path next */
	err = ucan_rx_barrier(dev);
fail:
	return err;
}

/* int ucan_post_canrx_msg(struct pcandev *dev,
 *				struct ucan_rx_msg *rm, struct timeval *ptv)
 *
 *	Default handler of incoming CAN messages
 */
int ucan_post_canrx_msg(struct pcandev *dev,
				struct ucan_rx_msg *rm, struct timeval *ptv)
{
	struct pcanfd_msg f;
	const u16 msg_flags = le16_to_cpu(rm->flags);
	int err;

#ifdef DEBUG_RX
	printk(KERN_DEBUG "%s: %s(CAN%u): wCANStatus=%xh "
		"rx=[flags=0x%02x len=0x%02x ts32=0x%08x id=0x%08x]\n",
			DEVICE_NAME, __func__, dev->nChannel+1,
			dev->wCANStatus, msg_flags, UCAN_MSG_DLC(rm),
		 le32_to_cpu(rm->ts_low), le32_to_cpu(rm->can_id));
#endif

	/* sure we are no more in that sate */
	//dev->wCANStatus &= ~CAN_ERR_QOVERRUN;
	pcan_clear_status_bit(dev, CAN_ERR_QOVERRUN);

#if 1
	/* such test is now made by pcan_chardev_rx() func */
#else
	/* Don't send any message when device not opened */
	if (dev->nOpenPaths <= 0) {
		pr_info("%s: incoming message 0x%x (flags=%x) discarded: "
		        "CAN#%d not yet opened\n",
			DEVICE_NAME, le32_to_cpu(rm->can_id), rm->flags,
			UCAN_MSG_CHANNEL(rm));
		return 0;
	}
#endif

	/* ignore any CAN data while we're in BUSOFF */
	//if (dev->wCANStatus & CAN_ERR_BUSOFF)
	switch (dev->bus_state) {
	case PCANFD_UNKNOWN:
	case PCANFD_ERROR_BUSOFF:
#ifdef DEBUG_RX
		pr_info(DEVICE_NAME
			": %s(CAN%u): rx CAN msg discarded (bus_state=%u)\n",
			__func__, dev->nChannel+1, dev->bus_state);
#endif
		return 0;
	default:
		break;
	}

	memset(&f, '\0', sizeof(f));

	if (msg_flags & UCAN_MSG_EXT_DATA_LEN) {
		/* CAN FD frame */
		f.type = PCANFD_TYPE_CANFD_MSG;
		if (msg_flags & UCAN_MSG_BITRATE_SWITCH)
			f.flags |= PCANFD_MSG_BRS;

		if (msg_flags & UCAN_MSG_ERROR_STATE_IND)
			f.flags |= PCANFD_MSG_ESI;

		f.data_len = pcan_dlc2len(UCAN_MSG_DLC(rm));
	} else {
		/* CAN 2.0 frame */
		f.type = PCANFD_TYPE_CAN20_MSG;
		f.data_len = get_can_dlc(UCAN_MSG_DLC(rm));
	}

	f.id = le32_to_cpu(rm->can_id);
	if (ptv) {
		f.flags |= PCANFD_TIMESTAMP|PCANFD_HWTIMESTAMP;
		f.timestamp = *ptv;
	}

#ifdef PCANFD_RAWTIMESTAMP
	f.flags |= PCANFD_RAWTIMESTAMP;
	f.raw_timestamp = ((u64 )le32_to_cpu(rm->ts_high) << 32) |
							le32_to_cpu(rm->ts_low);
#endif
	if (msg_flags & UCAN_MSG_EXT_ID)
		f.flags |= PCANFD_MSG_EXT;

	if (msg_flags & UCAN_MSG_RTR)
		f.flags |= PCANFD_MSG_RTR;
	else
		memcpy(f.data, rm->d, f.data_len);

	if (msg_flags & UCAN_MSG_HW_SRR)
		f.flags |= PCANFD_MSG_SLF;

#ifdef DEBUG_RX
	dump_mem("posted pcanfd_msg", &f, sizeof(struct pcanfd_msg));
#endif
	err = pcan_xxxdev_rx(dev, &f);
	if (err < 0)
		pr_err(DEVICE_NAME
			": %s CAN%u: CAN msg %xh (l=%u) lost (err %d)\n",
			dev->adapter->name, dev->nChannel+1,
			f.id, f.data_len, err);

	return err;
}

/* int ucan_handle_error(struct ucan_engine *ucan,
 *			 struct ucan_msg *rx_msg, void *arg)
 *				
 *
 *	Default handler of incoming error messages
 */
int ucan_handle_error(struct ucan_engine *ucan,
		      struct ucan_msg *rx_msg, void *arg)
{
	/* WARNING: ucan pointer can be NULL! */
	struct ucan_error_msg *er = (struct ucan_error_msg *)rx_msg;
	struct pcandev *dev = (struct pcandev *)arg;

#ifdef DEBUG
	printk(KERN_DEBUG "%s: %s(): "
		"rx=[type=0x%02x ts32=0x%08x d=%u g=%u code=0x%02x "
		"err_cnt[rx=%u tx=%u]]\n",
		DEVICE_NAME, __func__,
		UCAN_ERMSG_ERRTYPE(er), le32_to_cpu(er->ts_low),
		UCAN_ERMSG_D(er)?1:0,
		UCAN_ERMSG_G(er)?1:0,
		UCAN_ERMSG_ERRCODE(er),
		er->rx_err_cnt, er->tx_err_cnt);
#endif

	/* keep a trace of tx and rx error counters for later use */
	dev->rx_error_counter = er->rx_err_cnt;
	dev->tx_error_counter = er->tx_err_cnt;

#ifdef DEBUG
	if (dev->rx_error_counter || dev->tx_error_counter)
		printk(KERN_ERR
			"%s: %s CAN%u: errors: rx=%u tx=%u\n",
			DEVICE_NAME, dev->adapter->name, dev->nChannel,
			dev->rx_error_counter, dev->tx_error_counter);
#endif
	return 0;
}

int ucan_post_error_msg(struct pcandev *dev,
		      struct ucan_error_msg *er, struct timeval *ptv)
{
	struct pcanfd_msg f;

#ifdef DEBUG
	printk(KERN_DEBUG "%s: %s(): "
		"rx=[type=0x%02x ts32=0x%08x d=%u g=%u code=0x%02x "
		"err_cnt[rx=%u tx=%u]]\n",
		DEVICE_NAME, __func__,
		UCAN_ERMSG_ERRTYPE(er), le32_to_cpu(er->ts_low),
		UCAN_ERMSG_D(er)?1:0,
		UCAN_ERMSG_G(er)?1:0,
		UCAN_ERMSG_ERRCODE(er),
		er->rx_err_cnt, er->tx_err_cnt);
#endif

	/* call default handler first */
	ucan_handle_error(NULL, (struct ucan_msg *)er, dev);
#if 0
	/* don't bother user with messages having the same status */
	if ((dev->tx_error_counter == er->tx_err_cnt) &&
				(dev->rx_error_counter == er->rx_err_cnt))
		return 0;
#endif

	memset(&f, '\0', sizeof(f));

	f.type = PCANFD_TYPE_STATUS;
	f.flags = PCANFD_ERROR_BUS;
	f.id = dev->bus_state;

	if (ptv) {
		f.flags |= PCANFD_TIMESTAMP|PCANFD_HWTIMESTAMP;
		f.timestamp = *ptv;
	}

	return pcan_xxxdev_rx(dev, &f);
}

int ucan_post_status_msg(struct pcandev *dev,
		       struct ucan_status_msg *st, struct timeval *ptv)
{
	struct pcanfd_msg f;

#ifdef DEBUG
	printk(KERN_DEBUG "%s: %s(CAN%u): bus_state=%u "
		"ts32=0x%08x EP=%u EW=%u BO=%u]\n",
		DEVICE_NAME,__func__, dev->nChannel+1, dev->bus_state,
		le32_to_cpu(st->ts_low), !!UCAN_STMSG_PASSIVE(st),
		!!UCAN_STMSG_WARNING(st), !!UCAN_STMSG_BUSOFF(st));
#endif
	memset(&f, '\0', sizeof(f));

	if (UCAN_STMSG_BUSOFF(st)) {
		pcan_handle_busoff(dev, &f);
	} else if (!pcan_handle_error_status(dev, &f, UCAN_STMSG_WARNING(st),
						      UCAN_STMSG_PASSIVE(st))) {
		/* no error bit (so, no error, back to active state) */
		pcan_handle_error_active(dev, &f);
	}

	if (f.type == PCANFD_TYPE_NOP) {
#ifdef DEBUG
		pr_info(DEVICE_NAME ": %s(CAN%u): status msg discarded (NOP)\n",
			__func__, dev->nChannel+1);
#endif
		return 0;
	}

	if (ptv) {
		f.flags |= PCANFD_TIMESTAMP|PCANFD_HWTIMESTAMP;
		f.timestamp = *ptv;
	}

	return pcan_xxxdev_rx(dev, &f);
}

/*
 * int ucan_handle_bus_load(struct ucan_engine *ucan,
 *			 struct ucan_msg *rx_msg, void *arg)
 *
 * Default handler for bus_load notification messages.
 */
int ucan_handle_bus_load(struct ucan_engine *ucan,
			 struct ucan_msg *rx_msg, void *arg)
{
	struct ucan_bus_load_msg *bl = (struct ucan_bus_load_msg *)rx_msg;
	struct pcandev *dev = (struct pcandev *)arg;

#ifdef DEBUG_BUS_LOAD
	printk(KERN_DEBUG "%s: %s(CAN%u): bus_state=%u "
		"ts32=0x%08x bus_load=%u\n",
		DEVICE_NAME,__func__, dev->nChannel+1, dev->bus_state,
		le32_to_cpu(bl->ts_low), le16_to_cpu(bl->bus_load));
#endif

	//dev->bus_load = (100 * le16_to_cpu(bl->bus_load)) / 4095;
	dev->bus_load = (10000 * le16_to_cpu(bl->bus_load)) / 4095;

	return 0;
}

int ucan_post_bus_load_msg(struct pcandev *dev,
		       struct ucan_bus_load_msg *bl, struct timeval *ptv)
{
	struct pcanfd_msg f;

#if 0//def DEBUG
	printk(KERN_DEBUG "%s: %s(%s CAN%d)\n", DEVICE_NAME, __func__,
		dev->adapter->name, dev->nChannel+1);
#endif

	/* call default handler */
	ucan_handle_bus_load(NULL, (struct ucan_msg *)bl, dev);

	memset(&f, '\0', sizeof(f));

	f.type = PCANFD_TYPE_STATUS;
	f.id = PCANFD_BUS_LOAD;
	if (ptv) {
		f.flags |= PCANFD_TIMESTAMP|PCANFD_HWTIMESTAMP;
		f.timestamp = *ptv;
	}

	return pcan_xxxdev_rx(dev, &f);
}

int ucan_post_overflow_msg(struct pcandev *dev, struct timeval *ptv)
{
	struct pcanfd_msg f;

#ifdef DEBUG
	printk(KERN_DEBUG "%s: %s()\n", DEVICE_NAME, __func__);
#endif

	dev->dwErrorCounter++;

	/* do some filter to avoid overflowing rx queue with the same STATUS
	 * messages */
	if (dev->wCANStatus & CAN_ERR_QOVERRUN)
		return 0;

	dev->wCANStatus |= CAN_ERR_QOVERRUN;

	memset(&f, '\0', sizeof(f));

	f.type = PCANFD_TYPE_STATUS;
	f.flags = PCANFD_ERROR_CTRLR;
	f.id = PCANFD_RX_OVERFLOW;
	if (ptv) {
		f.flags |= PCANFD_TIMESTAMP|PCANFD_HWTIMESTAMP;
		f.timestamp = *ptv;
	}

	return pcan_xxxdev_rx(dev, &f);
}

int ucan_handle_msg(struct ucan_engine *ucan, void *msg_addr)
{
	struct ucan_msg *msg;
	void *arg = NULL;
	int msg_size;
	u16 msg_type;
	int ci = -1, err;
	int (*msg_cb)(struct ucan_engine *, struct ucan_msg *, void *);

	msg = (struct ucan_msg *)msg_addr;
	msg_size = le16_to_cpu(msg->size);
	if (!msg->size || !msg->type) {
		/* null packet found: end of list */
		goto lbl_return;
	}

	msg_type = le16_to_cpu(msg->type);

#ifdef DEBUG_RX
	switch (msg_type) {
#ifdef USB_SUPPORT
	case UCAN_USB_MSG_CALIBRATION:
#endif
#ifndef DEBUG_BUS_LOAD
	case UCAN_MSG_BUSLOAD:
#endif
	case UCAN_MSG_ERROR:
		break;
	default:
		dump_mem("received msg", msg, msg_size);
	}
#endif

	/* theses msgs carry a channel index */
	switch (msg_type) {

	case UCAN_MSG_CAN_RX:
		ci = UCAN_MSG_CHANNEL((struct ucan_rx_msg *)msg);
		break;

	case UCAN_MSG_ERROR:
		ci = UCAN_ERMSG_CHANNEL((struct ucan_error_msg *)msg);
		break;

	case UCAN_MSG_STATUS:
		ci = UCAN_STMSG_CHANNEL((struct ucan_status_msg *)msg);
		break;

	case UCAN_MSG_BUSLOAD:
		ci = UCAN_BLMSG_CHANNEL((struct ucan_bus_load_msg *)msg);
		break;

#ifdef USB_SUPPORT
	case UCAN_USB_MSG_CALIBRATION:
		arg = pcan_usb_get_if(&ucan->devs[0]);
		break;

	case UCAN_USB_MSG_OVERRUN:
		ci = UCAN_USB_OVMSG_CHANNEL((struct ucan_usb_ovr_msg *)msg);
		break;
#endif
	}

	if (msg_type < ucan->ops->handle_msg_size) {
		if (!ucan->ops->handle_msg_table[msg_type]) {
			pr_info(DEVICE_NAME ": unhandled rx uCAN msg %03xh: "
				"it is ignored\n", msg_type);
			dump_mem("unhandled msg", msg, msg_size);
			goto lbl_return;
		}

		msg_cb = ucan->ops->handle_msg_table[msg_type];

	} else {
		if (!ucan->ops->handle_private_msg) {
			pr_err(DEVICE_NAME ": out of range rx uCAN msg "
				"%03xh >= %u: it is ignored\n", msg_type,
				ucan->ops->handle_msg_size);
			dump_mem("out of range msg", msg, msg_size);
			goto lbl_return;
		}

		/* note: in that case, ci is always -1... */
		msg_cb = ucan->ops->handle_private_msg;
	}

	if (ci != -1) {

		/* be sure of the index read... */
		if ((ci < 0) || (ci >= ucan->devs_count)) {
#ifdef DEBUG
			pr_info(DEVICE_NAME ": invalid channel %d in uCAN "
				"msg %03xh: it is ignored\n", ci, msg_type);
#endif
			goto lbl_return;
		}

		arg = ucan->devs + ci;
	}

	//err = ucan->ops->handle_msg_table[msg_type](ucan, msg, arg);
	err = msg_cb(ucan, msg, arg);
	if (err < 0)
		return err;

lbl_return:
	return msg_size;
}

/* int ucan_handle_msgs_buffer(struct ucan_engine *ucan, void *msg_addr,
 *				int msg_len)
 */
int ucan_handle_msgs_buffer(struct ucan_engine *ucan, void *msg_addr,
			    int msg_len)
{
	u8 *msg_end = msg_addr + msg_len;
	int msg_size = 0;
	u8 *msg_ptr;

#if 0//def DEBUG

	pr_info("%s: %s(%d)\n", DEVICE_NAME, __func__, msg_len);
	//dump_mem("received msg", msg_addr, msg_len);
#endif

	/* loop reading all the records from the incoming message */
	for (msg_ptr = msg_addr; msg_ptr < msg_end; msg_ptr += msg_size) {
		msg_size = ucan_handle_msg(ucan, msg_ptr);

		/* a null packet can be found at the end of a list */
		if (msg_size <= 0)
			break;
	}

#if 0
	pr_info("%s: %s(): found %u msgs in %u bytes buffer\n",
			DEVICE_NAME, __func__, msg_nb, msg_len);
#endif
	/* check if the record goes out of current packet */
	if (msg_ptr > msg_end) {
		/* yes, it does: donot handle fragmentation => increase usb rx
		 * message size */
		printk(KERN_ERR
		       "%s: got frag rec: should inc rx buffer size\n",
		       DEVICE_NAME);
		msg_size = -EBADMSG;
	}

	/* in case of error, dump the whole messages (list) */
	if (msg_size < 0) {
		if (msg_size != -ENOSPC)
			dump_mem("received err msg", msg_addr, msg_len);
		return msg_size;
	}

	return 0;
}

/*
 * int ucan_handle_msgs_list(struct ucan_engine *ucan, void *msg_addr,
 *				int *msg_count)
 */
int ucan_handle_msgs_list(struct ucan_engine *ucan, void *msg_addr,
			  int *msg_count)
{
	u8 *msg_ptr = msg_addr;
	int msg_len = 0;
	int msg_size = 0;
	int i;

#if 0//def DEBUG
	pr_info("%s: %s(%d)\n", DEVICE_NAME, __func__, *msg_count);
	//dump_mem("received msg", msg_addr, msg_len);
#endif

	/* loop reading all the records from the incoming message */
	for (i = 0; i < *msg_count; i++) {
		msg_size = ucan_handle_msg(ucan, msg_ptr);

		/* a null packet can be found at the end of a list */
		if (msg_size <= 0)
			break;
		msg_len += msg_size;
		msg_ptr += msg_size;
	}

	*msg_count = i;

	/* in case of error, dump the whole messages (list),
	 * except in case of not enough space in Rx FIFO... */
	if (msg_size < 0) {
		if (msg_size != -ENOSPC)
			dump_mem("received err msg", msg_addr, msg_len);
		return msg_size;
	}

	return 0;
}

/*
 * int ucan_encode_msg(struct pcandev *dev, u8 *buffer_addr, int buffer_size)
 */
int ucan_encode_msg(struct pcandev *dev, u8 *buffer_addr, int buffer_size)
{
	struct ucan_tx_msg *tx_msg = (struct ucan_tx_msg *)buffer_addr;
	struct pcanfd_msg can_msg;
	int tx_msg_size, err, dlc;
	u16 tx_flag_tmp = 0x0;
#ifdef UCAN_TEST_TX_BURST
	int i;
#endif

	/* first get the size of the enqueued CAN message */
	err = pcan_fifo_peek(&dev->writeFifo, &can_msg);
	if (err) {
		if (err != -ENODATA) {
			printk(KERN_ERR "%s: %s(): "
				"can't get data out of writeFifo, "
				"available data: %d, err: %d\n",
				DEVICE_NAME, __func__,
				dev->writeFifo.nStored, err);
		}
		return err;
	}

#ifdef DEBUG
	printk(KERN_DEBUG "Encoding msg {type=%u id=%xh dlen=%u flg=%xh}\n",
		can_msg.type, can_msg.id, can_msg.data_len, can_msg.flags);
#endif

#if 1
	/* TODO: is this test really needed ? May the Tx fifo contain other
	 * messages than CAN frames ? */
#else
#ifdef MSGTYPE_PARAMETER
	if (can_msg.flags & (PCANFD_ERROR_STATUS | MSGTYPE_PARAMETER)) {
#else
	if (can_msg.flags & PCANFD_ERROR_STATUS) {
#endif
		printk(KERN_INFO "%s: %s(): "
			"CAN msg type %08Xh ignored\n",
			DEVICE_NAME, __func__, can_msg.flags);
		return 0;
	}
#endif

	dlc = pcan_len2dlc(can_msg.data_len);
	tx_msg_size = ALIGN(sizeof(struct ucan_tx_msg)+ pcan_dlc2len(dlc), 4);

#ifdef UCAN_TEST_TX_BURST
	tx_msg_size *= UCAN_TEST_TX_BURST;
#endif
	/* if not enough room to entirely copy it, stop here */
	if (tx_msg_size > buffer_size) {
#ifdef DEBUG
		printk(KERN_INFO "%s: %s(): "
			"%u bytes left too small for storing %u bytes\n",
			DEVICE_NAME, __func__,
			buffer_size, tx_msg_size);
#endif
		return -ENOSPC;
	}

	/* really read the message (NULL avoid 2nd useless memcpy()) */
	pcan_fifo_get(&dev->writeFifo, NULL);

#ifdef UCAN_TEST_TX_BURST
	tx_msg_size /= UCAN_TEST_TX_BURST;
	for (i = 0; i < UCAN_TEST_TX_BURST; i++ ) {
#endif
		memset(tx_msg, '\0', tx_msg_size);

		tx_msg->type = cpu_to_le16(UCAN_MSG_CAN_TX);
		tx_msg->size = cpu_to_le16(tx_msg_size);

		//tx_msg->flags = 0;
		if (can_msg.flags & PCANFD_MSG_EXT) {
			tx_flag_tmp |= UCAN_MSG_EXT_ID;
			tx_msg->can_id = cpu_to_le32(can_msg.id & CAN_EFF_MASK);
		} else {
			tx_msg->can_id = cpu_to_le32(can_msg.id & CAN_SFF_MASK);
		}

		switch (can_msg.type) {

		case PCANFD_TYPE_CANFD_MSG:
			/* CAN-FD frames */
			tx_flag_tmp |= UCAN_MSG_EXT_DATA_LEN;

			if (can_msg.flags & PCANFD_MSG_BRS)
				tx_flag_tmp |= UCAN_MSG_BITRATE_SWITCH;

			if (can_msg.flags & PCANFD_MSG_ESI)
				tx_flag_tmp |= UCAN_MSG_ERROR_STATE_IND;
				
			tx_msg->flags = cpu_to_le16(tx_flag_tmp);
			
			break;

		case PCANFD_TYPE_CAN20_MSG:
			/* CAN 2.0 frames */
			if (can_msg.flags & PCANFD_MSG_RTR)
				tx_flag_tmp |= UCAN_MSG_RTR;

			if (can_msg.flags & PCANFD_MSG_SLF)
				tx_flag_tmp |= UCAN_MSG_HW_SRR;
				
			tx_msg->flags = cpu_to_le16(tx_flag_tmp);

			break;
		}

		tx_msg->channel_dlc = UCAN_MSG_CHANNEL_DLC(dev->nChannel, dlc);

		memcpy(tx_msg->d, can_msg.data, can_msg.data_len);

#ifdef UCAN_TEST_TX_BURST
		tx_msg->d[0] = (u8 )i;
		buffer_addr += tx_msg_size;
		tx_msg = (struct ucan_tx_msg *)buffer_addr;
	}

	tx_msg_size *= UCAN_TEST_TX_BURST;
#endif

	return tx_msg_size;
}

/*
 * int ucan_encode_msgs_buffer(struct pcandev *dev,
 *				u8 *buffer_addr, int *buffer_size)
 *
 * Read msgs from CAN Tx fifo and encode them into the given buffer.
 *
 *	-ENODATA	if no more data in CAN fifo,
 *	-ENOSPC		if *buffer_size is not large enough to store a TX_x
 *			record
 *			any other -ERR.
 *	>= 0		if output buffer is full of TX_x records,
 */
int ucan_encode_msgs_buffer(struct pcandev *dev, u8 *buffer_addr,
				int *buffer_size)
{
	int msg_len, msg_count;
	int err = 0;

#ifdef DEBUG
	printk(KERN_DEBUG "%s: %s()\n", DEVICE_NAME, __func__);
#endif

	for (msg_len = msg_count = 0; msg_len < *buffer_size; ) {
		err = ucan_encode_msg(dev, buffer_addr + msg_len,
					   *buffer_size - msg_len);
		if (err < 0) {
#ifdef DEBUG
			printk(KERN_DEBUG "%s: %s(): err %d while encoding msg "
				"*buffer_size=%d msg_len=%d msg_count=%d\n",
				DEVICE_NAME, __func__, err,
				*buffer_size, msg_len, msg_count);
#endif
			break;
		}

		/* to be sure to not count other msgs than CAN frames */
		if (!err)
			continue;

		msg_len += err;
		msg_count++;
	}

	if (!msg_len) {
		*buffer_size = 0;
		return -ENODATA;
	}

	/* if the entire packet is not filled, set the size of last msg to 0
	 * to mark end-of-rec
	 */
	if (msg_len < *buffer_size) {
		*(u32 *)(buffer_addr + msg_len) = 0;
		msg_len += sizeof(u32);
	}

	/* set the whole size of the packet to send */
	*buffer_size = msg_len;

#ifdef DEBUG
	dump_mem("encoded buffer", buffer_addr, *buffer_size);
#endif

	return !err ? msg_count : err;
}
driver/src/pcanfd_ucan.h:

Code: Select all

/*
 * CAN driver for PEAK System micro-CAN based adapters
 *
 * Copyright (C) 2003-2011 PEAK System-Technik GmbH
 * Copyright (C) 2011-2013 Stephane Grosjean <s.grosjean@peak-system.com>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published
 * by the Free Software Foundation; version 2 of the License.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 */
#ifndef UCAN_H
#define UCAN_H

/* uCAN commands opcodes list (low-order 10 bits) */
#define UCAN_CMD_NOP			0x000
#define UCAN_CMD_RESET_MODE		0x001
#define UCAN_CMD_NORMAL_MODE		0x002
#define UCAN_CMD_LISTEN_ONLY_MODE	0x003
#define UCAN_CMD_TIMING_SLOW		0x004
#define UCAN_CMD_TIMING_FAST		0x005
#define UCAN_CMD_SET_STD_FILTER		0x006
#define UCAN_CMD_RESERVED2		0x007
#define UCAN_CMD_FILTER_STD		0x008
#define UCAN_CMD_TX_ABORT		0x009
#define UCAN_CMD_WR_ERR_CNT		0x00a
#define UCAN_CMD_SET_EN_OPTION		0x00b
#define UCAN_CMD_CLR_DIS_OPTION		0x00c

#define UCAN_CMD_SET_ERR_GEN1		0x00d
#define UCAN_CMD_SET_ERR_GEN		UCAN_CMD_SET_ERR_GEN1
#define UCAN_CMD_SET_ERR_GEN2		0x00e
#define UCAN_CMD_DIS_ERR_GEN		0x00f
#define UCAN_CMD_RX_BARRIER		0x010
#define UCAN_CMD_SET_ERR_GEN_S		0x011

#define UCAN_CMD_END_OF_COLLECTION	0x3ff

/* uCAN received messages list */
#define UCAN_MSG_CAN_RX			0x0001
#define UCAN_MSG_ERROR			0x0002
#define UCAN_MSG_STATUS			0x0003
#define UCAN_MSG_BUSLOAD		0x0004

/* uCAN transmitted messages */
#define UCAN_MSG_CAN_TX			0x1000

/* uCAN command common header */
#define UCAN_CMD_OPCODE(c)		((c)->opcode_channel & 0x3ff)
#define UCAN_CMD_CHANNEL(c)		((c)->opcode_channel >> 12)
#define UCAN_CMD_OPCODE_CHANNEL(c, o)	cpu_to_le16(((c) << 12) | ((o) & 0x3ff))

struct __packed ucan_command {
	__le16	opcode_channel;
	__le16	args[3];
};

#define UCAN_TSLOW_BRP_BITS		10
#define UCAN_TFAST_BRP_BITS		10

#if 1
/* current version of uCAN IP core */
#define UCAN_TSLOW_TSGEG1_BITS		8
#define UCAN_TSLOW_TSGEG2_BITS		7
#define UCAN_TSLOW_SJW_BITS		7

#define UCAN_TFAST_TSGEG1_BITS		5
#define UCAN_TFAST_TSGEG2_BITS		4
#define UCAN_TFAST_SJW_BITS		4
#else
/* first version of uCAN IP core */
#define UCAN_TSLOW_TSGEG1_BITS		6
#define UCAN_TSLOW_TSGEG2_BITS		4
#define UCAN_TSLOW_SJW_BITS		4

#define UCAN_TFAST_TSGEG1_BITS		4
#define UCAN_TFAST_TSGEG2_BITS		3
#define UCAN_TFAST_SJW_BITS		2
#endif

#define UCAN_TSLOW_BRP_MASK		((1 << UCAN_TSLOW_BRP_BITS) - 1)
#define UCAN_TSLOW_TSEG1_MASK		((1 << UCAN_TSLOW_TSGEG1_BITS) - 1)
#define UCAN_TSLOW_TSEG2_MASK		((1 << UCAN_TSLOW_TSGEG2_BITS) - 1)
#define UCAN_TSLOW_SJW_MASK		((1 << UCAN_TSLOW_SJW_BITS) - 1)

#define UCAN_TFAST_BRP_MASK		((1 << UCAN_TFAST_BRP_BITS) - 1)
#define UCAN_TFAST_TSEG1_MASK		((1 << UCAN_TFAST_TSGEG1_BITS) - 1)
#define UCAN_TFAST_TSEG2_MASK		((1 << UCAN_TFAST_TSGEG2_BITS) - 1)
#define UCAN_TFAST_SJW_MASK		((1 << UCAN_TFAST_SJW_BITS) - 1)

/* uCAN TIMING_SLOW command fields */
#define UCAN_TSLOW_SJW_T(s, t)		(((s) & UCAN_TSLOW_SJW_MASK) | \
								((!!(t)) << 7))
#define UCAN_TSLOW_TSEG2(t)		((t) & UCAN_TSLOW_TSEG2_MASK)
#define UCAN_TSLOW_TSEG1(t)		((t) & UCAN_TSLOW_TSEG1_MASK)
#define UCAN_TSLOW_BRP(b)		cpu_to_le16((b) & UCAN_TSLOW_BRP_MASK) 

struct __packed ucan_timing_slow {
	__le16	opcode_channel;

	u8	ewl;		/* Error Warning limit */
	u8	sjw_t;		/* Sync Jump Width + Triple sampling */
	u8	tseg2;		/* Timing SEGment 2 */
	u8	tseg1;		/* Timing SEGment 1 */

	__le16	brp;		/* BaudRate Prescaler */
};

/* uCAN TIMING_FAST command fields */
#define UCAN_TFAST_SJW(s)		((s) & UCAN_TFAST_SJW_MASK)
#define UCAN_TFAST_TSEG2(t)		((t) & UCAN_TFAST_TSEG2_MASK)
#define UCAN_TFAST_TSEG1(t)		((t) & UCAN_TFAST_TSEG1_MASK)
#define UCAN_TFAST_BRP(b)		cpu_to_le16((b) & UCAN_TFAST_BRP_MASK)

struct __packed ucan_timing_fast {
	__le16	opcode_channel;

	u8	unused;
	u8	sjw;		/* Sync Jump Width */
	u8	tseg2;		/* Timing SEGment 2 */
	u8	tseg1;		/* Timing SEGment 1 */

	__le16	brp;		/* BaudRate Prescaler */
};

/* (old) uCAN FILTER_STD command fields */
#define UCAN_FLTSTD_ROW_IDX_BITS	6

struct __packed ucan_filter_std {
	__le16	opcode_channel;

	__le16	idx;
	__le32	mask;		/* CAN-ID bitmask in idx range */
};

/* uCAN SET_STD_FILTER command fields */
struct __packed ucan_std_filter {
	__le16	opcode_channel;

	u8	unused;
	u8	idx;
	__le32	mask;		/* CAN-ID bitmask in idx range */
};

/* uCAN TX_ABORT commands fields */
#define UCAN_TX_ABORT_FLUSH		0x0001

struct __packed ucan_tx_abort {
	__le16	opcode_channel;

	__le16	flags;
	u32	unused;
};

/* uCAN WR_ERR_CNT command fields */
#define UCAN_WRERRCNT_TE		0x4000	/* Tx error cntr write Enable */
#define UCAN_WRERRCNT_RE		0x8000	/* Rx error cntr write Enable */

struct __packed ucan_wr_err_cnt {
	__le16	opcode_channel;

	__le16	sel_mask;
	u8	tx_counter;	/* Tx error counter new value */
	u8	rx_counter;	/* Rx error counter new value */

	u16	unused;
};

/* uCAN SET_EN_OPTION/CLR_DIS_OPTION commands fields */
#define UCAN_OPTION_ERROR		0x0001
#define UCAN_OPTION_BUSLOAD		0x0002
#define UCAN_OPTION_ISO_MODE		0x0004

struct __packed ucan_option {
	__le16	opcode_channel;

	__le16	mask;
};

/* uCAN received messages global format */
struct __packed ucan_msg {
	__le16	size;
	__le16	type;
	__le32	ts_low;
	__le32	ts_high;
};

/* uCAN flags for CAN/CANFD messages */
#define UCAN_MSG_API_SRR		0x80
#define UCAN_MSG_ERROR_STATE_IND	0x40	/* error state indicator */
#define UCAN_MSG_BITRATE_SWITCH		0x20	/* bitrate switch */
#define UCAN_MSG_EXT_DATA_LEN		0x10	/* extended data length */
#define UCAN_MSG_SINGLE_SHOT		0x08
#define UCAN_MSG_HW_SRR			0x04
#define UCAN_MSG_EXT_ID			0x02
#define UCAN_MSG_RTR			0x01

#define UCAN_MSG_CHANNEL(m)		((m)->channel_dlc & 0xf)
#define UCAN_MSG_DLC(m)			((m)->channel_dlc >> 4)

struct __packed ucan_rx_msg {
	__le16	size;
	__le16	type;
	__le32	ts_low;
	__le32	ts_high;
	__le32	tag_low;
	__le32	tag_high;
	u8	channel_dlc;
	u8	client;
	__le16	flags;
	__le32	can_id;
	u8	d[0];
};

/* uCAN error types */
#define UCAN_ERMSG_BIT_ERROR		0
#define UCAN_ERMSG_FORM_ERROR		1
#define UCAN_ERMSG_STUFF_ERROR		2
#define UCAN_ERMSG_OTHER_ERROR		3
#define UCAN_ERMSG_ERR_CNT_DEC		4

#define UCAN_ERMSG_CHANNEL(e)		((e)->channel_type_d & 0x0f)
#define UCAN_ERMSG_ERRTYPE(e)		(((e)->channel_type_d >> 4) & 0x07)
#define UCAN_ERMSG_D(e)			((e)->channel_type_d & 0x80)

#define UCAN_ERMSG_ERRCODE(e)		((e)->code_g & 0x7f)
#define UCAN_ERMSG_G(e)			((e)->code_g & 0x80)

struct __packed ucan_error_msg {
	__le16	size;
	__le16	type;
	__le32	ts_low;
	__le32	ts_high;
	u8	channel_type_d;
	u8	code_g;
	u8	tx_err_cnt;
	u8	rx_err_cnt;
};

#define UCAN_STMSG_CHANNEL(e)		((e)->channel_p_w_b & 0x0f)
#define UCAN_STMSG_RB(e)		((e)->channel_p_w_b & 0x10)
#define UCAN_STMSG_PASSIVE(e)		((e)->channel_p_w_b & 0x20)
#define UCAN_STMSG_WARNING(e)		((e)->channel_p_w_b & 0x40)
#define UCAN_STMSG_BUSOFF(e)		((e)->channel_p_w_b & 0x80)

struct __packed ucan_status_msg {
	__le16	size;
	__le16	type;
	__le32	ts_low;
	__le32	ts_high;
	u8	channel_p_w_b;
	u8	unused[3];
};

#define UCAN_BLMSG_CHANNEL(e)		((e)->channel & 0x0f)

struct __packed ucan_bus_load_msg {
	__le16	size;
	__le16	type;
	__le32	ts_low;
	__le32	ts_high;
	u8	channel;
	u8	unused;
	__le16	bus_load;
};

/* uCAN transmitted message format */
#define UCAN_MSG_CHANNEL_DLC(c, d)	(((c) & 0xf) | ((d) << 4))

struct __packed ucan_tx_msg {
	__le16	size;
	__le16	type;
	__le32	tag_low;
	__le32	tag_high;
	u8	channel_dlc;
	u8	client;
	__le16	flags;
	__le32	can_id;
	u8	d[0];
};

/* uCAN message programming interface */
struct pcandev *ucan_init_cmd(struct pcandev *dev);
void *ucan_add_cmd(struct pcandev *dev, int cmd_op);

/* pcan interface functions */
void *ucan_add_cmd_nop(struct pcandev *dev);
void *ucan_add_cmd_set_en_option(struct pcandev *dev, u16 mask);
void *ucan_add_cmd_clr_dis_option(struct pcandev *dev, u16 mask);

int ucan_set_bus_on(struct pcandev *dev);
int ucan_set_bus_off(struct pcandev *dev);
int ucan_set_options(struct pcandev *dev, u16 opt_mask);
int ucan_clr_options(struct pcandev *dev, u16 opt_mask);

int ucan_set_BTR0BTR1(struct pcandev *dev, u16 btr0btr1);
int ucan_clr_err_counters(struct pcandev *dev);
int ucan_set_all_acceptance_filter(struct pcandev *dev);

int ucan_set_msg_filters(struct pcandev *dev, u16 mask);
int ucan_clr_msg_filters(struct pcandev *dev, u16 mask);

int ucan_tx_abort(struct pcandev *dev, u16 flags);
int ucan_rx_barrier(struct pcandev *dev);

int ucan_soft_init(struct pcandev *dev, char *szType, u16 wType);
int ucan_device_open(struct pcandev *dev, u16 btr0btr1, u8 ext, u8 listen_only);
int ucan_device_open_fd(struct pcandev *dev, struct pcanfd_init *pfdi);

int ucan_reset_path(struct pcandev *dev);

/* uCAN messages builder */
int ucan_encode_msg(struct pcandev *dev, u8 *buffer_addr, int buffer_size);
int ucan_encode_msgs_buffer(struct pcandev *dev, u8 *buffer_addr,
			    int *buffer_size);

/* uCAN messages handler */
int ucan_handle_msg(struct ucan_engine *ucan, void *msg_addr);
int ucan_handle_msgs_buffer(struct ucan_engine *ucan, void *msg_addr,
			    int msg_len);
int ucan_handle_msgs_list(struct ucan_engine *ucan, void *msg_addr,
			  int *msg_count);

/* uCAN message base handlers */
int ucan_post_canrx_msg(struct pcandev *dev, struct ucan_rx_msg *msg,
							struct timeval *ptv);
int ucan_handle_error(struct ucan_engine *ucan, struct ucan_msg *rx_msg,
							void *arg);
int ucan_post_error_msg(struct pcandev *dev, struct ucan_error_msg *em,
							struct timeval *ptv);
int ucan_post_status_msg(struct pcandev *dev, struct ucan_status_msg *sm,
							struct timeval *ptv);
int ucan_handle_bus_load(struct ucan_engine *ucan, struct ucan_msg *rx_msg,
							void *arg);
int ucan_post_bus_load_msg(struct pcandev *dev, struct ucan_bus_load_msg *bl,
							struct timeval *ptv);
int ucan_post_overflow_msg(struct pcandev *dev, struct timeval *ptv);

#endif
And the patches that'll make those from the originals:

ucan_c.patch:

Code: Select all

--- pcanfd_ucan_original.c	2017-08-04 16:14:18.001094035 -0600
+++ pcanfd_ucan.c	2017-08-04 16:18:58.967058718 -0600
@@ -1278,6 +1278,7 @@
 	struct ucan_tx_msg *tx_msg = (struct ucan_tx_msg *)buffer_addr;
 	struct pcanfd_msg can_msg;
 	int tx_msg_size, err, dlc;
+	u16 tx_flag_tmp = 0x0;
 #ifdef UCAN_TEST_TX_BURST
 	int i;
 #endif
@@ -1347,7 +1348,7 @@
 
 		//tx_msg->flags = 0;
 		if (can_msg.flags & PCANFD_MSG_EXT) {
-			tx_msg->flags |= UCAN_MSG_EXT_ID;
+			tx_flag_tmp |= UCAN_MSG_EXT_ID;
 			tx_msg->can_id = cpu_to_le32(can_msg.id & CAN_EFF_MASK);
 		} else {
 			tx_msg->can_id = cpu_to_le32(can_msg.id & CAN_SFF_MASK);
@@ -1357,21 +1358,27 @@
 
 		case PCANFD_TYPE_CANFD_MSG:
 			/* CAN-FD frames */
-			tx_msg->flags |= UCAN_MSG_EXT_DATA_LEN;
+			tx_flag_tmp |= UCAN_MSG_EXT_DATA_LEN;
 
 			if (can_msg.flags & PCANFD_MSG_BRS)
-				tx_msg->flags |= UCAN_MSG_BITRATE_SWITCH;
+				tx_flag_tmp |= UCAN_MSG_BITRATE_SWITCH;
 
 			if (can_msg.flags & PCANFD_MSG_ESI)
-				tx_msg->flags |= UCAN_MSG_ERROR_STATE_IND;
+				tx_flag_tmp |= UCAN_MSG_ERROR_STATE_IND;
+				
+			tx_msg->flags = cpu_to_le16(tx_flag_tmp);
+			
+			break;
 
 		case PCANFD_TYPE_CAN20_MSG:
 			/* CAN 2.0 frames */
 			if (can_msg.flags & PCANFD_MSG_RTR)
-				tx_msg->flags |= UCAN_MSG_RTR;
+				tx_flag_tmp |= UCAN_MSG_RTR;
 
 			if (can_msg.flags & PCANFD_MSG_SLF)
-				tx_msg->flags |= UCAN_MSG_HW_SRR;
+				tx_flag_tmp |= UCAN_MSG_HW_SRR;
+				
+			tx_msg->flags = cpu_to_le16(tx_flag_tmp);
 
 			break;
 		}
ucan_h.patch:

Code: Select all

--- pcanfd_ucan_original.h	2017-08-04 16:14:23.689603313 -0600
+++ pcanfd_ucan.h	2017-08-04 16:20:27.918323342 -0600
@@ -278,7 +278,7 @@
 	__le32	tag_high;
 	u8	channel_dlc;
 	u8	client;
-	u16	flags;
+	__le16	flags;
 	__le32	can_id;
 	u8	d[0];
 };
I tested these fixes out on the P2020 and it worked like a charm. I have not tested them on anything else although I really just used the same methodology used throughout that code so it *should* work on other systems.

-Austin