PCAN-USB: new socketCAN driver available
Quoted 5 lines · Grosjean Stephane
Hi Oliver,
Quoted 3 lines
"The right way" (TM) would be to clone David Millers net-next git tree:
Quoted 8 lines
$ git clone http://git.kernel.org/?p=linux/kernel/git/davem/net-next.git;a=summary Initialized empty Git repository in /home/peak/linux/drivers/linux-can/net-next/.git/ f*atal: http://git.kernel.org/?p=linux/kernel/git/davem/net-next.git/info/refs not found: did you run git update-server-info on the server?*
Please use:
$ git clone git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next
See also http://git.kernel.org/
Wolfgang.
Marc Kleine-Budde
maintainerQuoted 3 lines · Wolfgang Grandegger
Please use:
$ git clone git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next
or, if you're trapped behind a http-only firewall:
git clone http://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Industrial Linux Solutions | Phone: +49-231-2826-924 | Vertretung West/Dortmund | Fax: +49-5121-206917-5555 | Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de |
Hello Stephane,
i checked your PCAN-USB driver - and also got the printk msg when plugging the USB pro ;-)
Some remarks to the current state and some details for naming conventions.
On 29.11.2011 11:10, Grosjean Stephane wrote:
~/peak_usb-0.2.0$ wc -l *
10 Kbuild
27 Kconfig
113 Makefile
813 peak_usb_core.c
109 peak_usb.h
854 peak_usb_pcan.c
31 peak_usb_pcan.h
64 peak_usb_pcan_pro.c
32 peak_usb_pcan_pro.h
2053 total
The number of files should be reduced.
The drivers module name should be
peak_usb.ko
peak_usb_pro.ko
'pcan' is a vendor brand name which should not go into the module name. Having PCAN in the Kconfig (like it is for the peak_pci driver) or in source file names is fine.
Eg. if you have a shared source like peak_usb_core.c a peak_usb.h header file is ok - but you should omit peak_usb_pcan[_pro].h , at least they contain almost nothing ;-)
The files should then reduce to:
KbuildKconfigMakefilepcan_usb_core.hpcan_usb_core.cpcan_usb.cpcan_usb_pro.c
Checking the Kconfig:
drivers/net/can/usb/Kconfig config CAN_ESD_USB2 · line 16
Quoted 9 lines
drivers/net/can/usb/Kconfig +1
-0@@ -13,4 +13,21 @@ config CAN_ESD_USB2 This driver supports the CAN-USB/2 interface from esd electronic system design gmbh (http://www.esd.eu). +config CAN_PEAK_PCAN_USB
name it CAN_PEAK_USB
drivers/net/can/usb/Kconfig config CAN_ESD_USB2 · line 17
Quoted 1 line
drivers/net/can/usb/Kconfig +1
-0+ tristate "PEAK-System's PCAN-USB adapter"
"PEAK PCAN USB adapter"
drivers/net/can/usb/Kconfig config CAN_ESD_USB2 · line 18
Quoted 1 line
drivers/net/can/usb/Kconfig +1
-0+ select CAN_PEAK_USB
remove the select (see Makefile comment below)
drivers/net/can/usb/Kconfig config CAN_ESD_USB2 · line 21
Quoted 3 lines
drivers/net/can/usb/Kconfig +3
-0+ ---help--- + This driver is for the one channel PCAN-USB interface + from PEAK-System (http://www.peak-system.com).
ok.
drivers/net/can/usb/Kconfig config CAN_ESD_USB2 · line 23
Quoted 2 lines
drivers/net/can/usb/Kconfig +2
-0+ +config CAN_PEAK_PCAN_USB_PRO
CAN_PEAK_USB_PRO
drivers/net/can/usb/Kconfig config CAN_ESD_USB2 · line 24
Quoted 1 line
drivers/net/can/usb/Kconfig +1
-0+ tristate "PEAK-System's PCAN-USB-PRO adapter"
"PEAK PCAN USB Pro adapter"
drivers/net/can/usb/Kconfig config CAN_ESD_USB2 · line 25
Quoted 1 line
drivers/net/can/usb/Kconfig +1
-0+ select CAN_PEAK_USB
remove the select (see Makefile comment below)
drivers/net/can/usb/Kconfig config CAN_ESD_USB2 · line 27
Quoted 2 lines
drivers/net/can/usb/Kconfig +2
-0+ ---help--- + This driver is for the two channels PCAN-USB-PRO interface
PCAN-USB Pro
drivers/net/can/usb/Kconfig config CAN_ESD_USB2 · line 32
Quoted 5 lines
drivers/net/can/usb/Kconfig +5
-0+ from PEAK-System (http://www.peak-system.com). + +config CAN_PEAK_USB + tristate +
Remove this.
To select config entries should be omitted if possible.
And now (tada!) the Makefile:
Quoted 9 lines
drivers/net/can/usb/Makefile +1
-0@@ -6,3 +6,14 @@ obj-$(CONFIG_CAN_EMS_USB) += ems_usb.o obj-$(CONFIG_CAN_ESD_USB2) += esd_usb2.o ccflags-$(CONFIG_CAN_DEBUG_DEVICES) := -DDEBUG +
drivers/net/can/usb/Makefile obj-$(CONFIG_CAN_EMS_USB) += ems_usb.o · line 19
Quoted 10 lines
drivers/net/can/usb/Makefile +10
-0+obj-$(CONFIG_CAN_PEAK_USB) += peak_usb.o +peak_usb-y = peak_usb_core.o + +ifneq ($(CONFIG_CAN_PEAK_PCAN_USB),) +peak_usb-y += peak_usb_pcan.o +endif + +ifneq ($(CONFIG_CAN_PEAK_PCAN_USB_PRO),) +peak_usb-y += peak_usb_pcan_pro.o +endif
Ok it worked, but ...
in the linux/drivers/net/can/usb/Makefile it should look like this:
obj-$(CONFIG_CAN_PEAK_USB) += peak_usb.o
peak_usb-objs := pcan_usb_core.o pcan_usb.o
obj-$(CONFIG_CAN_PEAK_USB_PRO) += peak_usb_pro.o peak_usb_pro-objs := pcan_usb_core.o pcan_usb_pro.o
Quoted 3 lines
Load the module, then "$cat
/sys/modules/peak_usb/version" and plug the PCAN-USB adapter... Yes you can also try with the PCAN-USB-PRO...
Is having a version string here a common thing?
Quoted 1 line
Hope you enjoy!
I did. No crash reports :-)
Quoted 1 line
Any feedback is welcome.
Done.
Best regards,
Oliver
Quoted 25 lines · Oliver Hartkopp
Quoted 1 line
+config
CAN_PEAK_PCAN_USB_PRO
CAN_PEAK_USB_PROQuoted 1 line
+ tristate "PEAK-System's PCAN-USB-PRO adapter"
"PEAK PCAN USB Pro adapter"
Quoted 1 line
+ select
CAN_PEAK_USBremove the select (see
Makefilecomment below)Review
Quoted 2 lines
(quoted diff) +2
-0+ ---help--- + This driver is for the two channels PCAN-USB-PRO interfacePCAN-USB Pro
Review
Quoted 5 lines
(quoted diff) +5
-0+ from PEAK-System (http://www.peak-system.com). + +config CAN_PEAK_USB + tristate +Remove this.
Quoted 1 line
To select config entries should be omitted if possible.
I just tried out the suggestion myself ...
As my idea was to link the common functions directly to the module binary this may double the needed size. Maybe your approach is really better 8-)
But the fact that the select should be omitted is still true.
Better you define a
config CAN_PEAK_USB
tristate "PEAK System USB adapters"
and then
config CAN_PCAN_USB
tristate "PEAK PCAN USB adapter"
depends on CAN_PEAK_USB
config CAN_PCAN_USB_PRO
tristate "PEAK PCAN USB Pro adapter"
depends on CAN_PEAK_USB
...
Regards,
Oliver
Hi Oliver.
One not to your comments..
Quoted 7 lines
in the linux/drivers/net/can/usb/Makefile it should look like this:
obj-$(CONFIG_CAN_PEAK_USB) += peak_usb.o
peak_usb-objs := pcan_usb_core.o pcan_usb.oobj-$(CONFIG_CAN_PEAK_USB_PRO) += peak_usb_pro.o peak_usb_pro-objs := pcan_usb_core.o pcan_usb_pro.o
Today it is really recommended to do:
obj-$(CONFIG_CAN_PEAK_USB) += peak_usb.o
peak_usb-y := pcan_usb_core.o pcan_usb.o
obj-$(CONFIG_CAN_PEAK_USB_PRO) += peak_usb_pro.o
peak_usb_pro-y := pcan_usb_core.o pcan_usb_pro.o
Both solutions will work - but the latter allows for some nice "kbuild" assignments to conditional stuff.
Sam
Quoted 14 lines · Sam Ravnborg
Hi Oliver.
One not to your comments..
Quoted 7 lines
in the linux/drivers/net/can/usb/Makefile it should look like this:
obj-$(CONFIG_CAN_PEAK_USB) += peak_usb.o
peak_usb-objs := pcan_usb_core.o pcan_usb.oobj-$(CONFIG_CAN_PEAK_USB_PRO) += peak_usb_pro.o peak_usb_pro-objs := pcan_usb_core.o pcan_usb_pro.o
Today it is really recommended to do:
Quoted 9 lines
obj-$(CONFIG_CAN_PEAK_USB) += peak_usb.o
peak_usb-y := pcan_usb_core.o pcan_usb.oobj-$(CONFIG_CAN_PEAK_USB_PRO) += peak_usb_pro.o
peak_usb_pro-y := pcan_usb_core.o pcan_usb_pro.oBoth solutions will work - but the latter allows for some nice "kbuild" assignments to conditional stuff.
Ah ok,
i picked that from here:
http://patchwork.ozlabs.org/patch/129539/
Good to know that it can be made 'even better' :-)
Thanks,
Oliver
Hi,
First of all, thank you for your time and all your comments.
Quoted 7 lines · Oliver Hartkopp
Quoted 5 lines · Sam Ravnborg
Today it is really recommended to do:
obj-$(CONFIG_CAN_PEAK_USB) += peak_usb.o
peak_usb-y := pcan_usb_core.o pcan_usb.o
Quoted 6 lines
Quoted 6 lines
obj-$(CONFIG_CAN_PEAK_USB_PRO) += peak_usb_pro.o
peak_usb_pro-y := pcan_usb_core.o pcan_usb_pro.oBoth solutions will work - but the latter allows for some nice "kbuild" assignments to conditional stuff.
right...
Quoted 19 lines
I just tried out the suggestion myself ...
As my idea was to link the common functions directly to the module binary this may double the needed size. Maybe your approach is really better 8-)
But the fact that the select should be omitted is still true.
Better you define a
config
CAN_PEAK_USB
tristate "PEAK System USB adapters"and then
config
CAN_PCAN_USB
tristate "PEAK PCAN USB adapter"
depends onCAN_PEAK_USB
Quoted 8 lines
config
CAN_PCAN_USB_PRO
tristate "PEAK PCAN USB Pro adapter"
depends onCAN_PEAK_USB...
Regards,
Oliver
I thought this was better for memory size and also for easier handling of (any) further PEAK USB adapter, never know...
But, what next? According to your below Kconfig and Sam's Kbuild, and if I understand well your suggestions, the Kbuild file always builds 2 module files, while I wanted to build only a single one, capable of handling one or both adapters.
Please, confirm that a mainline kernel driver should (must?) handle one and only one kind of device.
If it should (must), I will modify the Kbuild file as proposed by Sam, in order to build a peak_usb.ko and/or a peak_usb_pro.ko file.
But in that case, I wonder why the Kernel API offers some data structures like "struct usb_driver.id_table" which are supposed to describe more than one device id.
Regards,
Stéphane
Quoted 49 lines · Grosjean Stephane
Hi,
First of all, thank you for your time and all your comments.
Quoted 7 lines · Oliver Hartkopp
Quoted 5 lines · Sam Ravnborg
Today it is really recommended to do:
obj-$(CONFIG_CAN_PEAK_USB) += peak_usb.o
peak_usb-y := pcan_usb_core.o pcan_usb.oQuoted 6 lines
Quoted 6 lines
obj-$(CONFIG_CAN_PEAK_USB_PRO) += peak_usb_pro.o
peak_usb_pro-y := pcan_usb_core.o pcan_usb_pro.oBoth solutions will work - but the latter allows for some nice "kbuild" assignments to conditional stuff.
right...
Quoted 19 lines
I just tried out the suggestion myself ...
As my idea was to link the common functions directly to the module binary this may double the needed size. Maybe your approach is really better 8-)
But the fact that the select should be omitted is still true.
Better you define a
config
CAN_PEAK_USB
tristate "PEAK System USB adapters"and then
config
CAN_PCAN_USB
tristate "PEAK PCAN USB adapter"
depends onCAN_PEAK_USBQuoted 8 lines
config
CAN_PCAN_USB_PRO
tristate "PEAK PCAN USB Pro adapter"
depends onCAN_PEAK_USB...
Regards,
Oliver
Quoted 6 lines
I thought this was better for memory size and also for easier handling of (any) further PEAK USB adapter, never know...
But, what next? According to your belowKconfigand Sam'sKbuild, and if I understand well your suggestions, theKbuildfile always builds 2 module files, while I wanted to build only a single one, capable of handling one or both adapters.
Ah, ok. I formerly thought that you plan to have three separated kernel modules (core, usb, usbpro) - but i just checked that you only create a peak_usb.ko which is perfectly fine.
Quoted 3 lines
Please, confirm that a mainline kernel driver should (must?) handle one and
only one kind of device.
No. If your driver supports "PEAK PCAN USB / USB Pro adapters" you can put this into a single Kconfig entry and build a single peak_usb.ko if you like.
I don't know whether it's worth the effort to build separate drivers and kernel modules. The current code has some space for improvements and cleanups :-)
When you're finished your work with the USB Pro it's time to post it on linux-can ML and the we can discuss together how the sources and the driver should be packaged best.
Post early & often :-)
Quoted 2 lines
If it should (must), I will modify the
Kbuildfile as proposed by Sam, in order to build a peak_usb.ko and/or a peak_usb_pro.ko file.
This was just a suggestion.
Quoted 4 lines
But in that case, I wonder why the Kernel API offers some data structures like "struct usb_driver.id_table" which are supposed to describe more than one device id.
Yes you can do that also (as written above).
Regards,
Oliver
PEAK CAN USB driver v0.4.0
In reply to Oliver HartkoppHi Oliver,
Please find a new version of the candev driver for our PEAK USB adapters.
I tried to follow your suggestions, especially those concerning the names of the files and the Kconfig file content. However, I kept the original Kbuild file since I didn't find (for the moment) another way to add one or the other pcan_usb.o/pcan_usb_pro.o file, according to their corresponding CONFIG_xxx ...
This version also handles the PCAN-USB Pro adapter as well as the timestamps coming from PCAN-USB and PCAN-USB Pro (new from v0.2.0). There's something which should be fixed too and I wanted to talk about that too:
I don't know why for the moment, but sending data through the adapters works without any problems, except when data are sent through one or the other can channel of the the PCAN-USB Pro: the data are correclty sent on the bus but, for each sent frame, the Kernel adds the following text to the syslog:
[98724.131218] ehci_hcd 0000:00:1a.7: dma_pool_free buffer-32,
f4e93000/34e93000 (bad dma)
Seems to be a warning-like, since nothing else occurs anywhere (data are sent, the kernel is/seems always stable...).
That's the main reason why I decided to give you that new version, and also to ask you if you had got any idea about the reason of such a log? I mean, that "problem" doesnot occur when sending through PCAN-USB adapter channel... If you have a look to the sources, the management of the tx buffer(s) is done into pcan_usb_core.c, that is, tx buffers allocation/free doesn't depend on the type of USB adapter (well I suppose it is, but why and where?).
So, while I'm delving into the code, I hope you'll be able to have enough time to test'n play with your PEAK USB CAN adapters and this new driver.
Many thanks and regards,
Stéphane