Skip to contentSkip to conversation

can: add slcan driver for serial/USB-serial CAN adapters

PATCH Superseded Oliver Hartkopp 2 participants 4 messages Nov 29, 2010 – Dec 2, 2010 2 messages not in the archive

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 can: add slcan driver for serial/USB-serial CAN adapters

This patch adds support for serial/USB-serial CAN adapters implementing the LAWICEL ASCII protocol for CAN frame transport over serial lines.

The driver implements the SLCAN line discipline and is heavily based on the slip.c driver. Therefore the code style remains similar to slip.c to be able to apply changes of the SLIP driver to the SLCAN driver easily.

For more details see the slcan Kconfig entry.

---

drivers/net/can/Kconfig +21 -0
diff -u -r -N a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
@@ -12,6 +12,27 @@
 	  This driver can also be built as a module.  If so, the module
 	  will be called vcan.
 
+config CAN_SLCAN
+	tristate "Serial / USB serial CAN Adaptors (slcan)"
+	depends on CAN
+	default N
+	---help---
+	  CAN driver for several 'low cost' CAN interfaces that are attached
+	  via serial lines or via USB-to-serial adapters using the LAWICEL
+	  ASCII protocol. The driver implements the tty linediscipline N_SLCAN.
+
+	  As only the sending and receiving of CAN frames is implemented, this
+	  driver should work with the (serial/USB) CAN hardware from:
+	  www.canusb.com / www.can232.com / www.mictronic.com / www.canhack.de
+
+	  Userspace tools to attach the SLCAN line discipline (slcan_attach,
+	  slcand) can be found in the can-utils at the SocketCAN SVN, see
+	  http://developer.berlios.de/projects/socketcan for details.
+
+	  The slcan driver supports up to 10 CAN netdevices by default which
+	  can be changed by the 'maxdev=xx' module option. This driver can
+	  also be built as a module. If so, the module will be called slcan.
+
 config CAN_DEV
 	tristate "Platform CAN drivers with Netlink support"
 	depends on CAN
drivers/net/can/slcan.c +755 -0

755 lines not on this page · raw message

#1 lore raw
Quoted 6 lines · On Mon, 29 Nov 2010 21:30:45 +0100 Oliver Hartkopp <[email protected]>…

This patch adds support for serial/USB-serial CAN adapters implementing the LAWICEL ASCII protocol for CAN frame transport over serial lines.

The driver implements the SLCAN line discipline and is heavily based on the slip.c driver. Therefore the code style remains similar to slip.c to be able to apply changes of the SLIP driver to the SLCAN driver easily.

It looks almost identical. Would it not be better to either extract the common code or put slip and slcann together as one, otherwise changes will always get missed as they have to be done twice ?

How hard would it be to make the encap/decap pointers that can be set to cleanly abstract both ?

Alan

A message that is not in the archive (sent off-list or not yet received): 20101129233718.45dee61d-qBU/[email protected]

#3 lore raw
Quoted 10 lines · Alan Cox
Quoted 6 lines · On Mon, 29 Nov 2010 21:30:45 +0100 Oliver Hartkopp…

This patch adds support for serial/USB-serial CAN adapters implementing the LAWICEL ASCII protocol for CAN frame transport over serial lines.

The driver implements the SLCAN line discipline and is heavily based on the slip.c driver. Therefore the code style remains similar to slip.c to be able to apply changes of the SLIP driver to the SLCAN driver easily.

Quoted 6 lines

It looks almost identical. Would it not be better to either extract the common code or put slip and slcann together as one, otherwise changes will always get missed as they have to be done twice ?

How hard would it be to make the encap/decap pointers that can be set to cleanly abstract both ?

My first approach was indeed to try to integrate the slcan ldisc into slip. But due to the higher complexity with dynamic memory for the buffers, the multiple #ifdef CONFIG_* blocks, the private statistics, the legacy ioctl() and compat stuff, MTU change, i decided to cut all the unneeded code and make an easy short driver from that ...

The things i did not really understand i preserved as-is 8-) Therefore the code looks that similar in some cases.

I wonder whether the code in

- sl_open()
- sl_close()
- slip_write_wakeup()
- sl_xmit()
- sl_free_netdev()
- sl_sync()
- sl_alloc()
- slip_hangup()
- slip_exit()

could be shared e.g. in some separate module where also drivers/net/hamradio/mkiss.c could participate?!?

This would need to unify the slip/slcan/mkiss structs.

Additionally mkiss.c does not have something like

    static struct net_device **slip_devs;

and creates the netdevices without parsing a fixed number of devices in mkiss_open(). But as i'm not a tty specialist i better kept my hands off these internals ...

Regards,
Oliver

A message that is not in the archive (sent off-list or not yet received): [email protected]

#5 lore raw

As there's obviously no better idea, i would suggest to commit the slcan driver in it's current shape as it has been used successfully (out of tree) for more than two years now.

If there are new ideas to clean up the code of slip.c the slcan code can follow these easily.

I'll send a v2 patch, as i accidentally missed the Makefile modification in the first post.

Best regards,
Oliver

Quoted 54 lines · Oliver Hartkopp
Quoted 10 lines · Alan Cox
Quoted 6 lines · On Mon, 29 Nov 2010 21:30:45 +0100 Oliver Hartkopp…

This patch adds support for serial/USB-serial CAN adapters implementing the LAWICEL ASCII protocol for CAN frame transport over serial lines.

The driver implements the SLCAN line discipline and is heavily based on the slip.c driver. Therefore the code style remains similar to slip.c to be able to apply changes of the SLIP driver to the SLCAN driver easily.

Quoted 6 lines

It looks almost identical. Would it not be better to either extract the common code or put slip and slcann together as one, otherwise changes will always get missed as they have to be done twice ?

How hard would it be to make the encap/decap pointers that can be set to cleanly abstract both ?

My first approach was indeed to try to integrate the slcan ldisc into slip. But due to the higher complexity with dynamic memory for the buffers, the multiple #ifdef CONFIG_* blocks, the private statistics, the legacy ioctl() and compat stuff, MTU change, i decided to cut all the unneeded code and make an easy short driver from that ...

The things i did not really understand i preserved as-is 8-) Therefore the code looks that similar in some cases.

I wonder whether the code in

- sl_open()
- sl_close()
- slip_write_wakeup()
- sl_xmit()
- sl_free_netdev()
- sl_sync()
- sl_alloc()
- slip_hangup()
- slip_exit()

could be shared e.g. in some separate module where also drivers/net/hamradio/mkiss.c could participate?!?

This would need to unify the slip/slcan/mkiss structs.

Additionally mkiss.c does not have something like

    static struct net_device **slip_devs;

and creates the netdevices without parsing a fixed number of devices in mkiss_open(). But as i'm not a tty specialist i better kept my hands off these internals ...

Regards,
Oliver