Skip to contentSkip to conversation

Usb to can driver

DISCUSSION Max S. 3 participants 5 messages Jun 25, 2013 – Jul 3, 2013 1 message not in the archive CAN network drivers

lore
Share & tools
lore

Max S.

author
#0 lore raw

Some more questions regarding usb to can driver.

When CAN_CTRLMODE_LISTENONLY is set; why does the start_xmit function still get called? Its not really a problem, I'm just wondering why when a socket is listen only, it still attempts to TX...

My firmware implements LOOPBACK by default. That is all frames sent by the can hardware are also returned over usb. I use this effect to call can_get_echo_skb() during bulk in. To support LOOPBACK mode as per socketcan; should i also call netif_rx() durring bulk in if CAN_CTRLMODE_LOOPBACK is set?

I am currently using:

struct __packed gs_host_frame {
	u32 echo_id;
	u32 can_id;

	u32 can_dlc;
	u32 channel;
	u32 flags;

	u8 data[8];
};

as the data format between host/device. Using u32 for
memory alignment as suggested. Is there any way I can reduce the amount of wasted space? At 1Mhz std rtr frame is ~21K frames/s. For two channels both ways that's 21x2x2=84k frames/s. At 28 bytes per frame that's 84x28x8=18.816Mbit/s too much for a USB full-speed device. I want to reduce gs_host_frame size and get closer to 12Mbit/s.

What is the purpose of enum can_mode and set mode? I see that allot of drivers more or less ignore it. reacting to only START but not SLEEP or STOP...

Max Schnedier.

#1 lore raw

Hi Max,

On Tue, 25 Jun 2013 23:59:18 +0000, "Max S." <[email protected]>

Quoted 11 lines · wrote:

Some more questions regarding usb to can driver.

When CAN_CTRLMODE_LISTENONLY is set; why does the start_xmit function

still get called?

Its not really a problem, I'm just wondering why when a socket is listen

only, it still attempts to TX...

Good point. Would be more clever to not start the tx queue in that case.

Quoted 11 lines

My firmware implements LOOPBACK by default. That is all frames sent by

the can hardware are also returned over usb. I use this effect to call

can_get_echo_skb() during bulk in. To support LOOPBACK mode as per

socketcan; should i also call netif_rx() durring bulk in if

CAN_CTRLMODE_LOOPBACK is

set?

Message echo (normally via echo_skbs) and loopback (via

CAN_CTRLMODE_LOOPBACK)

are somehow different things. The first is a local loopback of sent

frames,

which is described here:

http://lxr.linux.no/#linux+v3.9.7/Documentation/networking/can.txt#L178

Be aware that this feature can be switched off by the app via setsockopt

as

described in 4.1.3 and 4.1.4:

http://lxr.linux.no/#linux+v3.9.7/Documentation/networking/can.txt#L496

Does the hardware communicate a TX done event as well?

CAN_CTRLMODE_LOOPBACK is a real hardware loopback. Normally the message

does

not even go out to the bus mainly useful for testing. For the software the

loopback message should be handled like any other incoming message.

Quoted 26 lines

I am currently using:

struct __packed gs_host_frame {

	u32 echo_id;

	u32 can_id;



	u32 can_dlc;

	u32 channel;

	u32 flags;



	u8 data[8];

};

as the data format between host/device. Using u32 for

memory alignment as suggested. Is there any way I can reduce the amount

Quoted 7 lines

of wasted space? At 1Mhz std rtr frame is ~21K frames/s. For two

channels both ways that's 21x2x2=84k frames/s. At 28 bytes per frame

that's 84x28x8=18.816Mbit/s too much for a USB full-speed device. I

want to reduce gs_host_frame size and get closer to 12Mbit/s.

I think u8 is ok for echo_id, can_dlc, channel and flags. Just take care

that these 4 bytes are on a 32-bit boundary.

Quoted 5 lines

What is the purpose of enum can_mode and set mode? I see that allot of

drivers more or less ignore it.

reacting to only START but not SLEEP or STOP...

It is used for bus-off-recovery as desribed here:

http://lxr.linux.no/#linux+v3.9.7/Documentation/networking/can.txt#L891

Then CAN_MODE_START is used here:

http://lxr.linux.no/#linux+v3.9.7/drivers/net/can/dev.c#L440

STOP and SLEEP are currently unused.

Wolfgang.

author
#2 lore raw
Quoted 1 line · wg

Hi Max,

...

Quoted 7 lines
Quoted 6 lines

My firmware implements LOOPBACK by default. That is all frames sent by the can hardware are also returned over usb. I use this effect to call can_get_echo_skb() during bulk in. To support LOOPBACK mode as per socketcan; should i also call netif_rx() durring bulk in if CAN_CTRLMODE_LOOPBACK is
set?

Quoted 7 lines

Message echo (normally via echo_skbs) and loopback (via CAN_CTRLMODE_LOOPBACK)
are somehow different things. The first is a local loopback of sent frames,
which is described here:

http://lxr.linux.no/#linux+v3.9.7/Documentation/networking/can.txt#L178

I was confused because i was not sure if 'sent frame' meant either a) 'frame that has left Linux', or b) 'frame that actually made it onto the CAN bus'. Appears I can choose either :P

For usb_8dev and ems_usb, echo via put_echo_skb happens in the USB write callback. (a)

For esd_usb2 a frame is only recognized as sent when the device reports it as sent. (b)

I also noticed esd_usb2 does: dev->nets[msg->msg.txdone.net] Is that safe? msg->msg.txdone.net is never check if its in range...

Quoted 1 line

Does the hardware communicate a TX done event as well?

Yes, The controller produces a TX event which happens after successful frame transmission. I place successfully TXed frames in the USB IN fifo with their corresponding echo_ids.

Quoted 3 lines

CAN_CTRLMODE_LOOPBACK is a real hardware loopback. Normally the message does not even go out to the bus mainly useful for testing. For the software the loopback message should be handled like any other incoming message.

Ah. so CAN_CTRLMODE_LOOPBACK could be used to test data path from application->Linux->driver->can_hardware and back. without the need of an actual physical CAN bus.

Thanks Wolfgang,
Max Schneider.

#3 lore raw
Quoted 13 lines · Max S.
Quoted 13 lines
Quoted 6 lines

My firmware implements LOOPBACK by default. That is all frames sent by the can hardware are also returned over usb. I use this effect to call can_get_echo_skb() during bulk in. To support LOOPBACK mode as per socketcan; should i also call netif_rx() durring bulk in if CAN_CTRLMODE_LOOPBACK is
set?

Message echo (normally via echo_skbs) and loopback (via CAN_CTRLMODE_LOOPBACK)
are somehow different things. The first is a local loopback of sent frames,
which is described here:

Quoted 5 lines
Quoted 1 line

http://lxr.linux.no/#linux+v3.9.7/Documentation/networking/can.txt#L178

I was confused because i was not sure if 'sent frame' meant either a) 'frame that has left Linux', or b) 'frame that actually made it onto the CAN bus'. Appears I can choose either :P

b) is preferred

Quoted 8 lines

For usb_8dev and ems_usb, echo via put_echo_skb happens in the USB write callback. (a)

For esd_usb2 a frame is only recognized as sent when the device reports it as sent. (b)

I also noticed esd_usb2 does: dev->nets[msg->msg.txdone.net] Is that safe? msg->msg.txdone.net is never check if its in range...

Can you send a patch? :)

Quoted 4 lines
Quoted 1 line

Does the hardware communicate a TX done event as well?

Yes, The controller produces a TX event which happens after successful frame transmission. I place successfully TXed frames in the USB IN fifo with their corresponding echo_ids.

This means you implement b).

Quoted 7 lines
Quoted 3 lines

CAN_CTRLMODE_LOOPBACK is a real hardware loopback. Normally the message does not even go out to the bus mainly useful for testing. For the software the loopback message should be handled like any other incoming message.

Ah. so CAN_CTRLMODE_LOOPBACK could be used to test data path from application->Linux->driver->can_hardware and back. without the need of an actual physical CAN bus.

Yes, this is a usecase.

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   |
#5 lore raw
In reply to a message not in the archive
Quoted 3 lines · Max S.
Quoted 2 lines
Quoted 2 lines

Can you send a patch? :)

sure. attached.

Thanks. Please the mailinglist for all linux can related patches.

Quoted 1 line

However, since i don't have the hardware; I can't test this.

Me neither, but the patch looks good.

Quoted 16 lines

From f6f2ec1b1c2fa4f2d29fb48e8a315ff814ed2be9 Mon Sep 17 00:00:00 2001
From: Maximilian Schneider <[email protected]>
Date: Tue, 2 Jul 2013 23:43:29 +0000
Subject: [PATCH] use of raw input in net lookup

---
 drivers/net/can/usb/esd_usb2.c |    6 ++++++
 1 file changed, 6 insertions(+)
drivers/net/can/usb/esd_usb2.c +0 -0
index 6aa7b32..ee89b19 100644

drivers/net/can/usb/esd_usb2.c static void esd_usb2_read_bulk_callback(struct urb *urb) · line 415

Quoted 4 lines
drivers/net/can/usb/esd_usb2.c +1 -0
@@ -412,10 +412,16 @@ static void esd_usb2_read_bulk_callback(struct urb *urb)
 
 		switch (msg->msg.hdr.cmd) {
 		case CMD_CAN_RX:
+			if (msg->msg.rx.net >= dev->net_count)

I've added an error message here.

drivers/net/can/usb/esd_usb2.c static void esd_usb2_read_bulk_callback(struct urb *urb) · line 422

Quoted 7 lines
drivers/net/can/usb/esd_usb2.c +3 -0
+				break;
+
 			esd_usb2_rx_can_msg(dev->nets[msg->msg.rx.net], msg);
 			break;
 
 		case CMD_CAN_TX:
+			if (msg->msg.txdone.net >= dev->net_count)

and here, too.

drivers/net/can/usb/esd_usb2.c static void esd_usb2_read_bulk_callback(struct urb *urb)

Quoted 7 lines
drivers/net/can/usb/esd_usb2.c +2 -1
+				break;
+
 			esd_usb2_tx_done_msg(dev->nets[msg->msg.txdone.net],
 					     msg);
 			break;
-- 1.7.10.4

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   |