linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marc Kleine-Budde <mkl-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
To: Bernd Krumboeck <krumboeck-Hi41barv6paIERSsAYjmKA@public.gmane.org>
Cc: linux-can-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	info-La43T0Mi4bH5xCKuJOYmCvaTkwRoYoCU@public.gmane.org,
	gediminas-LljXPT5IorFWk0Htik3J/w@public.gmane.org
Subject: Re: [PATCH v3] usb_8dev: Add support for USB2CAN interface from 8 devices
Date: Wed, 05 Dec 2012 22:40:48 +0100	[thread overview]
Message-ID: <50BFBF60.2090106@pengutronix.de> (raw)
In-Reply-To: <50BF8602.1070909-Hi41barv6paIERSsAYjmKA@public.gmane.org>

[-- Attachment #1: Type: text/plain, Size: 5004 bytes --]

On 12/05/2012 06:36 PM, Bernd Krumboeck wrote:
> Hi Marc!
> 
> 
>>> +    default:
>>> +        netdev_info(netdev, "Rx URB aborted (%d)\n",
>>> +             urb->status);
>>> +        goto resubmit_urb;
>>> +    }
>>> +
>>> +    while (pos < urb->actual_length) {
>>> +        struct usb_8dev_rx_msg *msg;
>>> +
>>> +        if (pos + sizeof(struct usb_8dev_rx_msg) >
>>> urb->actual_length) {
>>> +            netdev_err(dev->netdev, "format error\n");
>>> +            break;
>>
>> is resubmitting the urb the correct way to handle this problem?
> 
> Suggestions? (maybe CAN_ERR_CRTL_UNSPEC ??)

It's not an error on the CAN protocol level, but the USB communication
is broken. I just had a look at the kvaser usb driver, it's doing a
resubmit, too. So it seems to be okay.

> 
>>> +
>>> +            stats->tx_dropped++;
>>> +        }
>>> +    } else {
>>> +        /* Slow down tx path */
>>> +        if (atomic_read(&dev->active_tx_urbs) >= MAX_TX_URBS ||
>>> +            dev->free_slots < 5) {
>>
>> where's the 5 coming from?
>>
> 
> From ems_usb driver.

Hmmmm, is the variable free_slots used?

> 
>>> +            netif_stop_queue(netdev);
>>> +        }
>>> +    }
>>> +
>>> +    /*
>>> +     * Release our reference to this URB, the USB core will eventually
>>> free
>>> +     * it entirely.
>>> +     */
>>> +    usb_free_urb(urb);
>>> +
>>> +    return NETDEV_TX_OK;
>>> +
>>> +nomem:
>>> +    dev_kfree_skb(skb);
>>> +    stats->tx_dropped++;
>>> +
>>> +    return NETDEV_TX_OK;
>>> +}
>>> +
>>> +static int usb_8dev_get_berr_counter(const struct net_device *netdev,
>>> +                     struct can_berr_counter *bec)
>>> +{
>>> +    struct usb_8dev *dev = netdev_priv(netdev);
>>> +
>>> +    bec->txerr = dev->bec.txerr;
>>> +    bec->rxerr = dev->bec.rxerr;
>>> +
>>> +    return 0;
>>> +}
>>> +
>>> +/* Start USB device */
>>> +static int usb_8dev_start(struct usb_8dev *dev)
>>> +{
>>> +    struct net_device *netdev = dev->netdev;
>>> +    int err, i;
>>> +
>>> +    dev->free_slots = 15; /* initial size */
>>
>> there does the 15 come from?
> 
> ditto

dito :)

> 
>>> + * Check device and firmware.
>>> + * Set supported modes and bittiming constants.
>>> + * Allocate some memory.
>>> + */
>>> +static int usb_8dev_probe(struct usb_interface *intf,
>>> +             const struct usb_device_id *id)
>>> +{
>>> +    struct net_device *netdev;
>>> +    struct usb_8dev *dev;
>>> +    int i, err = -ENOMEM;
>>> +    u32 version;
>>> +    char buf[18];
>>
>> where does this 18 come from?
> 
> String "USB2CAN converter" + trailing 0.

okay

> 
>>
>>> +    struct usb_device *usbdev = interface_to_usbdev(intf);
>>> +
>>> +    /* product id looks strange, better we also check iProdukt
>>> string */
>>
>> iProduct?

I mean typo iProdukt vs iProduct.

> 
> Check if usbdev->descriptor.iProduct == "USB2CAN converter".
> 
>>> +    if (usb_string(usbdev, usbdev->descriptor.iProduct, buf,
>>> +               sizeof(buf)) > 0 && strcmp(buf, "USB2CAN converter")) {
>>> +        dev_info(&usbdev->dev, "ignoring: not an USB2CAN converter\n");
>>> +        return -ENODEV;
>>> +    }
>>> +
>>> +    netdev = alloc_candev(sizeof(struct usb_8dev), MAX_TX_URBS);
>>> +    if (!netdev) {
>>> +        dev_err(&intf->dev, "Couldn't alloc candev\n");
>>> +        return -ENOMEM;
>>> +    }
>>> +
>>> +    dev = netdev_priv(netdev);
>>> +
>>> +    dev->udev = usbdev;
>>> +    dev->netdev = netdev;
>>> +
>>> +    dev->can.state = CAN_STATE_STOPPED;
>>> +    dev->can.clock.freq = USB_8DEV_ABP_CLOCK;
>>> +    dev->can.bittiming_const = &usb_8dev_bittiming_const;
>>> +    dev->can.do_set_mode = usb_8dev_set_mode;
>>> +    dev->can.do_get_berr_counter = usb_8dev_get_berr_counter;
>>> +    dev->can.ctrlmode_supported = CAN_CTRLMODE_LOOPBACK |
>>> +                      CAN_CTRLMODE_LISTENONLY |
>>> +                      CAN_CTRLMODE_ONE_SHOT;
>>
>> Have you actually tested one shot? What happens if a can frame cannot be
>> transmitted?
>>
> 
> Not really. Can someone explain what one-shot exactly means and what is
> the correct behavior.
> I've only tested without any other device connected. I got the same
> errors like in normal mode.

Can has a built in collision avoidance protocol. If a collision is about
to happen the sender with the higher CAN id will back of and try again
later. In one shot mode it will not try again. The question is, how
behaves the dongle firmware, as you have to free your tx message somehow.

To test, simply send with one station with canid 1, the other one in
one-shot-mode with canid 0x7ff.

Marc

-- 
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   |


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 261 bytes --]

  parent reply	other threads:[~2012-12-05 21:40 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-04 20:44 [PATCH v3] usb_8dev: Add support for USB2CAN interface from 8 devices krumboeck
2012-12-04 20:44 ` Wolfgang Grandegger
     [not found]   ` <50BE60AD.10307-5Yr1BZd7O62+XT7JhA+gdA@public.gmane.org>
2012-12-04 22:20     ` Bernd Krumboeck
2012-12-05  7:24       ` Wolfgang Grandegger
2012-12-04 21:45 ` Marc Kleine-Budde
2012-12-05 17:36   ` Bernd Krumboeck
     [not found]     ` <50BF8602.1070909-Hi41barv6paIERSsAYjmKA@public.gmane.org>
2012-12-05 21:40       ` Marc Kleine-Budde [this message]
     [not found]         ` <50BFBF60.2090106-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2012-12-06  4:28           ` Bernd Krumboeck
2012-12-06  4:47   ` Bernd Krumboeck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=50BFBF60.2090106@pengutronix.de \
    --to=mkl-bicnvbalz9megne8c9+irq@public.gmane.org \
    --cc=gediminas-LljXPT5IorFWk0Htik3J/w@public.gmane.org \
    --cc=info-La43T0Mi4bH5xCKuJOYmCvaTkwRoYoCU@public.gmane.org \
    --cc=krumboeck-Hi41barv6paIERSsAYjmKA@public.gmane.org \
    --cc=linux-can-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).