mbox series

[v3,0/1] can: ucan: add driver for Theobroma Systems UCAN devices

Message ID 20180322135338.60923-1-jakob.unterwurzacher@theobroma-systems.com
Headers show
Series can: ucan: add driver for Theobroma Systems UCAN devices | expand

Message

Jakob Unterwurzacher March 22, 2018, 1:53 p.m. UTC
This is v3 of the Theobroma Systems CAN/USB adapter driver
upstreaming effort.

Featured v2 -> v3 changes:
* count error frames as data packets
* use canid_t for all can ids
* use BIT(x) instead of (1 << x)
* use __le16 / __le32 for little-endian fields
* add spinlock around context allocation (fixes a possible race)
* fix comment style
* use WARN_ON return value
* fix state logic bug that did not allow return to ERROR_ACTIVE
* drop echo_index from context_array (not needed)
* rename "tx_contexts" -> "context_array" to prevent confusion
* add __func__ to all errors and warnings, and to info where it made sense

Jakob Unterwurzacher (1):
  can: ucan: add driver for Theobroma Systems UCAN devices

 Documentation/networking/can_ucan_protocol.rst |  315 +++++
 Documentation/networking/index.rst             |    1 +
 drivers/net/can/usb/Kconfig                    |   10 +
 drivers/net/can/usb/Makefile                   |    1 +
 drivers/net/can/usb/ucan.c                     | 1628 ++++++++++++++++++++++++
 5 files changed, 1955 insertions(+)
 create mode 100644 Documentation/networking/can_ucan_protocol.rst
 create mode 100644 drivers/net/can/usb/ucan.c

-- 
2.11.0

Cc: Martin Elshuber <martin.elshuber@theobroma-systems.com>
Cc: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
Cc: Wolfgang Grandegger <wg@grandegger.com>
Cc: Marc Kleine-Budde <mkl@pengutronix.de>
Cc: linux-can@vger.kernel.org
Cc: linux-kernel@vger.kernel.org

Comments

Wolfgang Grandegger March 23, 2018, 8:32 a.m. UTC | #1
Hello Jacob,

Am 22.03.2018 um 14:53 schrieb Jakob Unterwurzacher:
> This is v3 of the Theobroma Systems CAN/USB adapter driver

> upstreaming effort.

> 

> Featured v2 -> v3 changes:

> * count error frames as data packets

> * use canid_t for all can ids

> * use BIT(x) instead of (1 << x)

> * use __le16 / __le32 for little-endian fields

> * add spinlock around context allocation (fixes a possible race)

> * fix comment style

> * use WARN_ON return value

> * fix state logic bug that did not allow return to ERROR_ACTIVE

> * drop echo_index from context_array (not needed)

> * rename "tx_contexts" -> "context_array" to prevent confusion

> * add __func__ to all errors and warnings, and to info where it made sense


The final output messages in the driver should especially be useful for
the end user... and not the developer! This is also true for the
function names. You already use more "__func__" than all other CAN
drivers together. Just my opinion!

> 

> Jakob Unterwurzacher (1):

>   can: ucan: add driver for Theobroma Systems UCAN devices

> 

>  Documentation/networking/can_ucan_protocol.rst |  315 +++++

>  Documentation/networking/index.rst             |    1 +

>  drivers/net/can/usb/Kconfig                    |   10 +

>  drivers/net/can/usb/Makefile                   |    1 +

>  drivers/net/can/usb/ucan.c                     | 1628 ++++++++++++++++++++++++

>  5 files changed, 1955 insertions(+)

>  create mode 100644 Documentation/networking/can_ucan_protocol.rst

>  create mode 100644 drivers/net/can/usb/ucan.c


Wolfgang.
Jakob Unterwurzacher March 23, 2018, 9:40 a.m. UTC | #2
On 23.03.18 09:32, Wolfgang Grandegger wrote:
>> * add __func__ to all errors and warnings, and to info where it made sense

> 

> The final output messages in the driver should especially be useful for

> the end user... and not the developer! This is also true for the

> function names. You already use more "__func__" than all other CAN

> drivers together. Just my opinion!


The idea was to make it clear which driver printed the message. In my 
opinion, this is a problem:

> drivers/net/can/usb$ git grep "No memory left for USB buffer"

> ems_usb.c:                      netdev_err(netdev, "No memory left for USB buffer\n");

> ems_usb.c:              netdev_err(netdev, "No memory left for USB buffer\n");

> esd_usb2.c:                              "No memory left for USB buffer\n");

> esd_usb2.c:             netdev_err(netdev, "No memory left for USB buffer\n");

> gs_usb.c:               netdev_err(netdev, "No memory left for USB buffer\n");

> gs_usb.c:                                          "No memory left for USB buffer\n");

> kvaser_usb.c:                            "No memory left for USB buffer\n");

> mcba_usb.c:                     netdev_err(netdev, "No memory left for USB buffer\n");

> usb_8dev.c:             netdev_err(netdev, "No memory left for USB buffer\n");

> usb_8dev.c:                     netdev_err(netdev, "No memory left for USB buffer\n");


But I'm open to other suggestions (use a fixed "ucan: " prefix?) or to 
drop it entirely if you think it is not worth it.

Thanks for the feedback,
Jakob
Wolfgang Grandegger March 23, 2018, 10:04 a.m. UTC | #3
Am 23.03.2018 um 10:40 schrieb Jakob Unterwurzacher:
> On 23.03.18 09:32, Wolfgang Grandegger wrote:

>>> * add __func__ to all errors and warnings, and to info where it made

>>> sense

>>

>> The final output messages in the driver should especially be useful for

>> the end user... and not the developer! This is also true for the

>> function names. You already use more "__func__" than all other CAN

>> drivers together. Just my opinion!

> 

> The idea was to make it clear which driver printed the message. In my

> opinion, this is a problem:

> 

>> drivers/net/can/usb$ git grep "No memory left for USB buffer"

>> ems_usb.c:                      netdev_err(netdev, "No memory left for

>> USB buffer\n");

>> ems_usb.c:              netdev_err(netdev, "No memory left for USB

>> buffer\n");

>> esd_usb2.c:                              "No memory left for USB

>> buffer\n");

>> esd_usb2.c:             netdev_err(netdev, "No memory left for USB

>> buffer\n");

>> gs_usb.c:               netdev_err(netdev, "No memory left for USB

>> buffer\n");

>> gs_usb.c:                                          "No memory left for

>> USB buffer\n");

>> kvaser_usb.c:                            "No memory left for USB

>> buffer\n");

>> mcba_usb.c:                     netdev_err(netdev, "No memory left for

>> USB buffer\n");

>> usb_8dev.c:             netdev_err(netdev, "No memory left for USB

>> buffer\n");

>> usb_8dev.c:                     netdev_err(netdev, "No memory left for

>> USB buffer\n");


> But I'm open to other suggestions (use a fixed "ucan: " prefix?) or to

> drop it entirely if you think it is not worth it.


But there is already a device prefix, e.g.:

  peak_usb 1-6:1.0: PEAK-System PCAN-USB adapter hwrev 28 serial FFFFFFFF (1 channel)
  peak_usb 1-6:1.0 can0: attached to PCAN-USB channel 0 (device 255)
  ^^^^^^^^

No need to add another one!

Wolfgang.
Jakob Unterwurzacher March 23, 2018, 10:12 a.m. UTC | #4
On 23.03.18 11:04, Wolfgang Grandegger wrote:
> 

>> But I'm open to other suggestions (use a fixed "ucan: " prefix?) or to

>> drop it entirely if you think it is not worth it.

> 

> But there is already a device prefix, e.g.:

> 

>    peak_usb 1-6:1.0: PEAK-System PCAN-USB adapter hwrev 28 serial FFFFFFFF (1 channel)

>    peak_usb 1-6:1.0 can0: attached to PCAN-USB channel 0 (device 255)

>    ^^^^^^^^


Interesting. Looks like the UCAN driver is missing something to make 
this work:

[   67.792947] usb 5-1.4: ucan_probe: registered UCAN device at can0

I'll take a closer look.

Thanks,
Jakob
Martin Elshuber March 27, 2018, 10:19 a.m. UTC | #5
Where possible we changed dev_XXX to netdev_XXX. and removed all __func__.
netdev_XXX prints the necessary information on the device, bus and netif
The remaining dev_XXX (within probe) are extended such that they print
the string "ucan" (__func__ are also removed)

Am 23.03.18 um 11:12 schrieb Jakob Unterwurzacher:
> On 23.03.18 11:04, Wolfgang Grandegger wrote:

>>

>>> But I'm open to other suggestions (use a fixed "ucan: " prefix?) or to

>>> drop it entirely if you think it is not worth it.

>>

>> But there is already a device prefix, e.g.:

>>

>>    peak_usb 1-6:1.0: PEAK-System PCAN-USB adapter hwrev 28 serial

>> FFFFFFFF (1 channel)

>>    peak_usb 1-6:1.0 can0: attached to PCAN-USB channel 0 (device 255)

>>    ^^^^^^^^

>

> Interesting. Looks like the UCAN driver is missing something to make

> this work:

>

> [   67.792947] usb 5-1.4: ucan_probe: registered UCAN device at can0

>

> I'll take a closer look.

>

> Thanks,

> Jakob


-- 
Martin Elshuber
Theobroma Systems Design und Consulting GmbH
Seestadtstraße 27 (Aspern IQ), 1220 Wien, Austria
Phone: +43 1 236 98 93-405, Fax: +43 1 236 98 93-9
http://www.theobroma-systems.com