Hi Paul,

Paul Thomas wrote:
> Hi, I've been working with Christian, and he's been very helpful. In
> trying to get to the bottom of my problem I wrote a /proc/file
> interface so I could read & write mcp251x registers from userspace.
> I've discovered that I can only read/write resisters in one very
> specific condition. I describe how to get there below:

> 1. load the module
> 2. run "ip link set can0 up" this creates a "RTNETLINK answers:
> Invalid argument" error, however the driver is doing several things
> here (attached as fcall_link-up_fail is the debug output including my
> added debug stuff).

Before you can start the device, you need to specify the bitrate:

  # ip link set can0 up type can bitrate 50000

or
  # ip link set can0 type can bitrate 50000
  # ifconfig can0 up

50 kB/s is a rather unusual and slow bit-rate. The driver's open
function should first check if the bit-timing has been set. The
attached patch does fix that.

> 3. Now I can read/write registers. I don't even need to use my hacked
> /proc/file to test this. This is the only time "ip link set can0 type
> can bitrate 50000" shows a actual numbers on the CNF debug line
> "mcp251x spi1.3: CNF: 0x09 0xbf 0x02".

If the link is up, you cannot change the bit-rate.

> The only way I've found to get back to this state is to unload &
> reload the driver. I understand that you can only mess with some of
> the mcp251x registers when CANCTRL is in configuration mode, but at
> the very least on startup you shouldn't need the failed link up
> command for it to work. And probably whenever the link is down in
> should be configurable.
> 
> I'm going through all of this because I was have a baud problems on the bus.

Does the patch below already help to cure your problems?

Wolfgang.


---
 drivers/net/can/mcp251x.c |   12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

Index: net-next-2.6/drivers/net/can/mcp251x.c
===================================================================
--- net-next-2.6.orig/drivers/net/can/mcp251x.c
+++ net-next-2.6/drivers/net/can/mcp251x.c
@@ -596,12 +596,6 @@ static int mcp251x_setup(struct net_devi
 {
        int ret;
 
-       ret = open_candev(net);
-       if (ret) {
-               dev_err(&spi->dev, "unable to set initial baudrate!\n");
-               return ret;
-       }
-
        /* Enable RX0->RX1 buffer roll over and disable filters */
        mcp251x_write_bits(spi, RXBCTRL(0),
                           RXBCTRL_BUKT | RXBCTRL_RXM0 | RXBCTRL_RXM1,
@@ -671,6 +665,12 @@ static int mcp251x_open(struct net_devic
        struct mcp251x_platform_data *pdata = spi->dev.platform_data;
        int ret;
 
+       ret = open_candev(net);
+       if (ret) {
+               dev_err(&spi->dev, "unable to set initial baudrate!\n");
+               return ret;
+       }
+
        if (pdata->transceiver_enable)
                pdata->transceiver_enable(1);
 
_______________________________________________
Socketcan-core mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/socketcan-core

Reply via email to