diff mbox

[net-next,v2,2/4] can: cc770: add legacy ISA bus driver for the CC770 and AN82527

Message ID 1322214204-1121-3-git-send-email-wg@grandegger.com
State Superseded, archived
Delegated to: David Miller
Headers show

Commit Message

Wolfgang Grandegger Nov. 25, 2011, 9:43 a.m. UTC
This patch adds support for legacy Bosch CC770 and Intel AN82527 CAN
controllers on the ISA or PC-104 bus. The I/O port or memory address
and the IRQ number must be specified via module parameters:

  insmod cc770_isa.ko port=0x310,0x380 irq=7,11

for ISA devices using I/O ports or:

  insmod cc770_isa.ko mem=0xd1000,0xd1000 irq=7,11

for memory mapped ISA devices.

Indirect access via address and data port is supported as well:

  insmod cc770_isa.ko port=0x310,0x380 indirect=1 irq=7,11

Furthermore, the following mode parameter can be defined:

  clk: External oscillator clock frequency (default=16000000 [16 MHz])
  cir: CPU interface register (default=0x40 [DSC])
  ocr, Bus configuration register (default=0x40 [CBY])
  cor, Clockout register (default=0x00)

Note: for clk, cir, bcr and cor, the first argument re-defines the
default for all other devices, e.g.:

  insmod cc770_isa.ko mem=0xd1000,0xd1000 irq=7,11 clk=24000000

is equivalent to

  insmod cc770_isa.ko mem=0xd1000,0xd1000 irq=7,11 clk=24000000,24000000

Signed-off-by: Wolfgang Grandegger <wg@grandegger.com>
---
 drivers/net/can/cc770/Kconfig     |   11 ++
 drivers/net/can/cc770/Makefile    |    1 +
 drivers/net/can/cc770/cc770_isa.c |  336 +++++++++++++++++++++++++++++++++++++
 3 files changed, 348 insertions(+), 0 deletions(-)
 create mode 100644 drivers/net/can/cc770/cc770_isa.c

Comments

Oliver Hartkopp Nov. 26, 2011, 2:59 p.m. UTC | #1
Hello Wolfgang,

many thanks for posting this driver. Indeed this is the last from the missing
drivers in the SVN ...

I added Wolfgang Zarre to the list of recipients who tested your CC770 driver
recently:

http://old.nabble.com/Compile-Fails-On-2.6.39-2-td32259346.html

Maybe he can check this latest version and can send a "Tested-by:"

@Wolfgang Zarre: The entire patch set from Wolfgang Grandegger is here:

http://patchwork.ozlabs.org/patch/127653/
http://patchwork.ozlabs.org/patch/127651/
http://patchwork.ozlabs.org/patch/127654/
http://patchwork.ozlabs.org/patch/127652/

Just a nitpick in the description:

> Furthermore, the following mode parameter can be defined:

> 
>   clk: External oscillator clock frequency (default=16000000 [16 MHz])
>   cir: CPU interface register (default=0x40 [DSC])
>   ocr, Bus configuration register (default=0x40 [CBY])


-> bcr: CPU ...

>   cor, Clockout register (default=0x00)


-> cor: Clockout ...

Regards,
Oliver
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Wolfgang Zarre Nov. 28, 2011, 8:56 a.m. UTC | #2
Hello Oliver,

> Hello Wolfgang,
>
> many thanks for posting this driver. Indeed this is the last from the missing
> drivers in the SVN ...

@Wolfgang

The same her, thanks a lot.

>
> I added Wolfgang Zarre to the list of recipients who tested your CC770 driver
> recently:
>
> http://old.nabble.com/Compile-Fails-On-2.6.39-2-td32259346.html
>
> Maybe he can check this latest version and can send a "Tested-by:"
>
> @Wolfgang Zarre: The entire patch set from Wolfgang Grandegger is here:
>
> http://patchwork.ozlabs.org/patch/127653/
> http://patchwork.ozlabs.org/patch/127651/
> http://patchwork.ozlabs.org/patch/127654/
> http://patchwork.ozlabs.org/patch/127652/

In fact a month ago we discovered a problem with the previous isa driver but were not
able to reproduce it.

Last Friday during a test run we got the same problem and with some further tests I
was able to reproduce and started with some investigation.

So the patches came in quite handy and even not to waste time I was applying the
patches to an updated svn tree but had to do some manual corrections to get it
compiled.

So far the driver is functioning quite good and I was hoping that our problem would
be solved as well.

But unfortunately that is not the case and it would be great if somebody would have
an idea or similar experience and maybe a solution.

In use:
ISA card: B&R with CC770 (40007) Series Bosch CAN Controller - LQFP-44
Kernel: 2.6.39.4
Module: modprobe cc770_isa irq=0xa port=0x384 indirect=1
Commands: ip link set can0 up type can bitrate 500000;ip link set can0 txqueuelen 2000

dmesg:
[190911.144337] CAN device driver interface
[190911.153316] cc770 CAN netdevice driver
[190911.159708] cc770_isa: platform device 0: port=0x384, mem=0x0, irq=10
[190911.159740] cc770_isa cc770_isa.0: probing idx=0: port=0x384, mem=0x0, irq=10
[190911.159799] cc770_isa cc770_isa.0: (unregistered net_device): i82527 mode with additional functions
[190911.161338] cc770_isa cc770_isa.0: cc770_isa device registered (reg_base=0x00000384, irq=10)
[190911.161384] Legacy cc770_isa driver for max. 8 devices registered
[190912.173762] cc770_isa cc770_isa.0: can0: setting BTR0=0x00 BTR1=0x1c
[190912.173835] cc770_isa cc770_isa.0: can0: Message object 15 for RX data, RTR, SFF and EFF
[190912.173852] cc770_isa cc770_isa.0: can0: Message object 11 for TX data, RTR, SFF and EFF


Description of problem:
After a while sending quite some telegrams the driver of a sudden stops transmitting
and the queue is running full but still capable to receive telegrams.
This issue is not depending on the amount of transmitted telegrams and also no logfile
entries.

Further it is possible to recover with ip link set down and up again.


>
> Just a nitpick in the description:
>
>> Furthermore, the following mode parameter can be defined:
>
>>
>>    clk: External oscillator clock frequency (default=16000000 [16 MHz])
>>    cir: CPU interface register (default=0x40 [DSC])
>>    ocr, Bus configuration register (default=0x40 [CBY])
>
>
> ->  bcr: CPU ...
>
>>    cor, Clockout register (default=0x00)
>
>
> ->  cor: Clockout ...
>
> Regards,
> Oliver

Thanks in advance.

Regards
Wolfgang
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Wolfgang Grandegger Nov. 28, 2011, 9:17 a.m. UTC | #3
On 11/28/2011 09:56 AM, Wolfgang Zarre wrote:
> Hello Oliver,
> 
>> Hello Wolfgang,
>>
>> many thanks for posting this driver. Indeed this is the last from the
>> missing
>> drivers in the SVN ...
> 
> @Wolfgang
> 
> The same her, thanks a lot.
> 
>>
>> I added Wolfgang Zarre to the list of recipients who tested your CC770
>> driver
>> recently:
>>
>> http://old.nabble.com/Compile-Fails-On-2.6.39-2-td32259346.html
>>
>> Maybe he can check this latest version and can send a "Tested-by:"
>>
>> @Wolfgang Zarre: The entire patch set from Wolfgang Grandegger is here:
>>
>> http://patchwork.ozlabs.org/patch/127653/
>> http://patchwork.ozlabs.org/patch/127651/
>> http://patchwork.ozlabs.org/patch/127654/
>> http://patchwork.ozlabs.org/patch/127652/
> 
> In fact a month ago we discovered a problem with the previous isa driver
> but were not
> able to reproduce it.
> 
> Last Friday during a test run we got the same problem and with some
> further tests I
> was able to reproduce and started with some investigation.
> 
> So the patches came in quite handy and even not to waste time I was
> applying the
> patches to an updated svn tree but had to do some manual corrections to
> get it
> compiled.
> 
> So far the driver is functioning quite good and I was hoping that our
> problem would
> be solved as well.

Well, I do not remember any fix... apart from

> But unfortunately that is not the case and it would be great if somebody
> would have
> an idea or similar experience and maybe a solution.
> 
> In use:
> ISA card: B&R with CC770 (40007) Series Bosch CAN Controller - LQFP-44
> Kernel: 2.6.39.4
> Module: modprobe cc770_isa irq=0xa port=0x384 indirect=1
> Commands: ip link set can0 up type can bitrate 500000;ip link set can0
> txqueuelen 2000

... using a reasonable default for bcr of 0x40. But you may need to
provide better values for cir, bcr and cor.

> dmesg:
> [190911.144337] CAN device driver interface
> [190911.153316] cc770 CAN netdevice driver
> [190911.159708] cc770_isa: platform device 0: port=0x384, mem=0x0, irq=10
> [190911.159740] cc770_isa cc770_isa.0: probing idx=0: port=0x384,
> mem=0x0, irq=10
> [190911.159799] cc770_isa cc770_isa.0: (unregistered net_device): i82527
> mode with additional functions
> [190911.161338] cc770_isa cc770_isa.0: cc770_isa device registered
> (reg_base=0x00000384, irq=10)
> [190911.161384] Legacy cc770_isa driver for max. 8 devices registered
> [190912.173762] cc770_isa cc770_isa.0: can0: setting BTR0=0x00 BTR1=0x1c
> [190912.173835] cc770_isa cc770_isa.0: can0: Message object 15 for RX
> data, RTR, SFF and EFF
> [190912.173852] cc770_isa cc770_isa.0: can0: Message object 11 for TX
> data, RTR, SFF and EFF
> 
> 
> Description of problem:
> After a while sending quite some telegrams the driver of a sudden stops
> transmitting
> and the queue is running full but still capable to receive telegrams.
> This issue is not depending on the amount of transmitted telegrams and
> also no logfile
> entries.

What do you get with "candump -t d any,0:0,#FFFFFFFF"? What does "ip -d
-s link show" show?

Wolfgang.

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Wolfgang Zarre Nov. 28, 2011, 12:03 p.m. UTC | #4
Hello Wolfgang,

> On 11/28/2011 09:56 AM, Wolfgang Zarre wrote:
>> Hello Oliver,
>>
>>> Hello Wolfgang,
>>>
>>> many thanks for posting this driver. Indeed this is the last from the
>>> missing
>>> drivers in the SVN ...
>>
>> @Wolfgang
>>
>> The same her, thanks a lot.
>>
>>>
>>> I added Wolfgang Zarre to the list of recipients who tested your CC770
>>> driver
>>> recently:
>>>
>>> http://old.nabble.com/Compile-Fails-On-2.6.39-2-td32259346.html
>>>
>>> Maybe he can check this latest version and can send a "Tested-by:"
>>>
>>> @Wolfgang Zarre: The entire patch set from Wolfgang Grandegger is here:
>>>
>>> http://patchwork.ozlabs.org/patch/127653/
>>> http://patchwork.ozlabs.org/patch/127651/
>>> http://patchwork.ozlabs.org/patch/127654/
>>> http://patchwork.ozlabs.org/patch/127652/
>>
>> In fact a month ago we discovered a problem with the previous isa driver
>> but were not
>> able to reproduce it.
>>
>> Last Friday during a test run we got the same problem and with some
>> further tests I
>> was able to reproduce and started with some investigation.
>>
>> So the patches came in quite handy and even not to waste time I was
>> applying the
>> patches to an updated svn tree but had to do some manual corrections to
>> get it
>> compiled.
>>
>> So far the driver is functioning quite good and I was hoping that our
>> problem would
>> be solved as well.
>
> Well, I do not remember any fix... apart from

Of course not, was never reported because we couldn't reproduce.

>
>> But unfortunately that is not the case and it would be great if somebody
>> would have
>> an idea or similar experience and maybe a solution.
>>
>> In use:
>> ISA card: B&R with CC770 (40007) Series Bosch CAN Controller - LQFP-44
>> Kernel: 2.6.39.4
>> Module: modprobe cc770_isa irq=0xa port=0x384 indirect=1
>> Commands: ip link set can0 up type can bitrate 500000;ip link set can0
>> txqueuelen 2000
>
> ... using a reasonable default for bcr of 0x40. But you may need to
> provide better values for cir, bcr and cor.
>

OMG, sorry that I was bothering You but You are absolutely right and with Your
statement You brought be back on track and You made my day. Thank You !!!!!!

I just took the values for cpu and bus I was using in my lincan driver and funny
enough now it's working absolutely perfect.

Module: modprobe cc770_isa irq=0xa port=0x384 indirect=1 cir=0x61 bcr=0x4A

Was just sending 50000 telegrams, perfect and no problem at all.

Thanks a lot again!!!!


>> dmesg:
>> [190911.144337] CAN device driver interface
>> [190911.153316] cc770 CAN netdevice driver
>> [190911.159708] cc770_isa: platform device 0: port=0x384, mem=0x0, irq=10
>> [190911.159740] cc770_isa cc770_isa.0: probing idx=0: port=0x384,
>> mem=0x0, irq=10
>> [190911.159799] cc770_isa cc770_isa.0: (unregistered net_device): i82527
>> mode with additional functions
>> [190911.161338] cc770_isa cc770_isa.0: cc770_isa device registered
>> (reg_base=0x00000384, irq=10)
>> [190911.161384] Legacy cc770_isa driver for max. 8 devices registered
>> [190912.173762] cc770_isa cc770_isa.0: can0: setting BTR0=0x00 BTR1=0x1c
>> [190912.173835] cc770_isa cc770_isa.0: can0: Message object 15 for RX
>> data, RTR, SFF and EFF
>> [190912.173852] cc770_isa cc770_isa.0: can0: Message object 11 for TX
>> data, RTR, SFF and EFF
>>
>>
>> Description of problem:
>> After a while sending quite some telegrams the driver of a sudden stops
>> transmitting
>> and the queue is running full but still capable to receive telegrams.
>> This issue is not depending on the amount of transmitted telegrams and
>> also no logfile
>> entries.
>
> What do you get with "candump -t d any,0:0,#FFFFFFFF"? What does "ip -d
> -s link show" show?
>
> Wolfgang.
>

Wolfgang


--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Marc Kleine-Budde Nov. 28, 2011, 12:09 p.m. UTC | #5
On 11/25/2011 10:43 AM, Wolfgang Grandegger wrote:
> This patch adds support for legacy Bosch CC770 and Intel AN82527 CAN
> controllers on the ISA or PC-104 bus. The I/O port or memory address
> and the IRQ number must be specified via module parameters:
> 
>   insmod cc770_isa.ko port=0x310,0x380 irq=7,11
> 
> for ISA devices using I/O ports or:
> 
>   insmod cc770_isa.ko mem=0xd1000,0xd1000 irq=7,11
> 
> for memory mapped ISA devices.
> 
> Indirect access via address and data port is supported as well:
> 
>   insmod cc770_isa.ko port=0x310,0x380 indirect=1 irq=7,11
> 
> Furthermore, the following mode parameter can be defined:
> 
>   clk: External oscillator clock frequency (default=16000000 [16 MHz])
>   cir: CPU interface register (default=0x40 [DSC])
>   ocr, Bus configuration register (default=0x40 [CBY])
>   cor, Clockout register (default=0x00)
> 
> Note: for clk, cir, bcr and cor, the first argument re-defines the
> default for all other devices, e.g.:
> 
>   insmod cc770_isa.ko mem=0xd1000,0xd1000 irq=7,11 clk=24000000
> 
> is equivalent to
> 
>   insmod cc770_isa.ko mem=0xd1000,0xd1000 irq=7,11 clk=24000000,24000000
> 
> Signed-off-by: Wolfgang Grandegger <wg@grandegger.com>

Some nitpicking inside.

Marc
> ---
>  drivers/net/can/cc770/Kconfig     |   11 ++
>  drivers/net/can/cc770/Makefile    |    1 +
>  drivers/net/can/cc770/cc770_isa.c |  336 +++++++++++++++++++++++++++++++++++++
>  3 files changed, 348 insertions(+), 0 deletions(-)
>  create mode 100644 drivers/net/can/cc770/cc770_isa.c
> 
> diff --git a/drivers/net/can/cc770/Kconfig b/drivers/net/can/cc770/Kconfig
> index 225131b..28e4d48 100644
> --- a/drivers/net/can/cc770/Kconfig
> +++ b/drivers/net/can/cc770/Kconfig
> @@ -1,3 +1,14 @@
>  menuconfig CAN_CC770
>  	tristate "Bosch CC770 and Intel AN82527 devices"
>  	depends on CAN_DEV && HAS_IOMEM
> +
> +if CAN_CC770
> +
> +config CAN_CC770_ISA
> +	tristate "ISA Bus based legacy CC770 driver"
> +	---help---
> +	  This driver adds legacy support for CC770 and AN82527 chips
> +	  connected to the ISA bus using I/O port, memory mapped or
> +	  indirect access.
> +
> +endif
> diff --git a/drivers/net/can/cc770/Makefile b/drivers/net/can/cc770/Makefile
> index 34e8180..872ecff 100644
> --- a/drivers/net/can/cc770/Makefile
> +++ b/drivers/net/can/cc770/Makefile
> @@ -3,5 +3,6 @@
>  #
>  
>  obj-$(CONFIG_CAN_CC770) += cc770.o
> +obj-$(CONFIG_CAN_CC770_ISA) += cc770_isa.o
>  
>  ccflags-$(CONFIG_CAN_DEBUG_DEVICES) := -DDEBUG
> diff --git a/drivers/net/can/cc770/cc770_isa.c b/drivers/net/can/cc770/cc770_isa.c
> new file mode 100644
> index 0000000..3aaecd5
> --- /dev/null
> +++ b/drivers/net/can/cc770/cc770_isa.c
> @@ -0,0 +1,336 @@
> +/*
> + * Copyright (C) 2009, 2011 Wolfgang Grandegger <wg@grandegger.com>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the version 2 of the GNU General Public License
> + * as published by the Free Software Foundation
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

Please remove the address.

> + */
> +
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +#include <linux/interrupt.h>
> +#include <linux/netdevice.h>
> +#include <linux/delay.h>
> +#include <linux/irq.h>
> +#include <linux/io.h>
> +#include <linux/can.h>
> +#include <linux/can/dev.h>
> +
> +#include "cc770.h"
> +
> +#define DRV_NAME "cc770_isa"
> +
> +#define MAXDEV 8
> +
> +MODULE_AUTHOR("Wolfgang Grandegger <wg@grandegger.com>");
> +MODULE_DESCRIPTION("Socket-CAN driver for CC770 on the ISA bus");
> +MODULE_LICENSE("GPL v2");
> +
> +#define CLK_DEFAULT	16000000	/* 16 MHz */
> +#define COR_DEFAULT	0x00
> +#define BCR_DEFAULT	BUSCFG_CBY
> +
> +static unsigned long port[MAXDEV];
> +static unsigned long mem[MAXDEV];
> +static int __devinitdata irq[MAXDEV];
> +static int __devinitdata clk[MAXDEV];
> +static u8 __devinitdata cir[MAXDEV] = {[0 ... (MAXDEV - 1)] = 0xff};
> +static u8 __devinitdata cor[MAXDEV] = {[0 ... (MAXDEV - 1)] = 0xff};
> +static u8 __devinitdata bcr[MAXDEV] = {[0 ... (MAXDEV - 1)] = 0xff};
> +static int __devinitdata indirect[MAXDEV] = {[0 ... (MAXDEV - 1)] = -1};
> +
> +module_param_array(port, ulong, NULL, S_IRUGO);
> +MODULE_PARM_DESC(port, "I/O port number");
> +
> +module_param_array(mem, ulong, NULL, S_IRUGO);
> +MODULE_PARM_DESC(mem, "I/O memory address");
> +
> +module_param_array(indirect, int, NULL, S_IRUGO);
> +MODULE_PARM_DESC(indirect, "Indirect access via address and data port");
> +
> +module_param_array(irq, int, NULL, S_IRUGO);
> +MODULE_PARM_DESC(irq, "IRQ number");
> +
> +module_param_array(clk, int, NULL, S_IRUGO);
> +MODULE_PARM_DESC(clk, "External oscillator clock frequency "
> +		 "(default=16000000 [16 MHz])");
> +
> +module_param_array(cir, byte, NULL, S_IRUGO);
> +MODULE_PARM_DESC(cir, "CPU interface register (default=0x40 [DSC])");
> +
> +module_param_array(cor, byte, NULL, S_IRUGO);
> +MODULE_PARM_DESC(cor, "Clockout register (default=0x00)");
> +
> +module_param_array(bcr, byte, NULL, S_IRUGO);
> +MODULE_PARM_DESC(bcr, "Bus configuration register (default=0x40 [CBY])");
> +
> +#define CC770_IOSIZE          0x20
> +#define CC770_IOSIZE_INDIRECT 0x02
> +
> +static struct platform_device *cc770_isa_devs[MAXDEV];
> +
> +static u8 cc770_isa_mem_read_reg(const struct cc770_priv *priv, int reg)
> +{
> +	return readb(priv->reg_base + reg);
> +}
> +
> +static void cc770_isa_mem_write_reg(const struct cc770_priv *priv,
> +				      int reg, u8 val)
> +{
> +	writeb(val, priv->reg_base + reg);
> +}
> +
> +static u8 cc770_isa_port_read_reg(const struct cc770_priv *priv, int reg)
> +{
> +	return inb((unsigned long)priv->reg_base + reg);
> +}
> +
> +static void cc770_isa_port_write_reg(const struct cc770_priv *priv,
> +				       int reg, u8 val)
> +{
> +	outb(val, (unsigned long)priv->reg_base + reg);
> +}
> +
> +static u8 cc770_isa_port_read_reg_indirect(const struct cc770_priv *priv,
> +					     int reg)
> +{
> +	unsigned long base = (unsigned long)priv->reg_base;
> +
> +	outb(reg, base);
> +	return inb(base + 1);
> +}
> +
> +static void cc770_isa_port_write_reg_indirect(const struct cc770_priv *priv,
> +						int reg, u8 val)
> +{
> +	unsigned long base = (unsigned long)priv->reg_base;
> +
> +	outb(reg, base);
> +	outb(val, base + 1);
> +}
> +
> +static int __devinit cc770_isa_probe(struct platform_device *pdev)
> +{
> +	struct net_device *dev;
> +	struct cc770_priv *priv;
> +	void __iomem *base = NULL;
> +	int iosize = CC770_IOSIZE;
> +	int idx = pdev->id;
> +	int err;
> +	u32 clktmp;
> +
> +	dev_dbg(&pdev->dev, "probing idx=%d: port=%#lx, mem=%#lx, irq=%d\n",
> +		idx, port[idx], mem[idx], irq[idx]);
> +	if (mem[idx]) {
> +		if (!request_mem_region(mem[idx], iosize, DRV_NAME)) {
> +			err = -EBUSY;
> +			goto exit;
> +		}
> +		base = ioremap_nocache(mem[idx], iosize);
> +		if (!base) {
> +			err = -ENOMEM;
> +			goto exit_release;
> +		}
> +	} else {
> +		if (indirect[idx] > 0 ||
> +		    (indirect[idx] == -1 && indirect[0] > 0))
> +			iosize = CC770_IOSIZE_INDIRECT;
> +		if (!request_region(port[idx], iosize, DRV_NAME)) {
> +			err = -EBUSY;
> +			goto exit;
> +		}
> +	}
> +
> +	dev = alloc_cc770dev(0);MAXDEV
> +	if (!dev) {
> +		err = -ENOMEM;
> +		goto exit_unmap;
> +	}
> +	priv = netdev_priv(dev);
> +
> +	dev->irq = irq[idx];
> +	priv->irq_flags = IRQF_SHARED;
> +	if (mem[idx]) {
> +		priv->reg_base = base;
> +		dev->base_addr = mem[idx];
> +		priv->read_reg = cc770_isa_mem_read_reg;
> +		priv->write_reg = cc770_isa_mem_write_reg;
> +	} else {
> +		priv->reg_base = (void __iomem *)port[idx];
> +		dev->base_addr = port[idx];
> +
> +		if (iosize == CC770_IOSIZE_INDIRECT) {
> +			priv->read_reg = cc770_isa_port_read_reg_indirect;
> +			priv->write_reg = cc770_isa_port_write_reg_indirect;
> +		} else {
> +			priv->read_reg = cc770_isa_port_read_reg;
> +			priv->write_reg = cc770_isa_port_write_reg;
> +		}
> +	}
> +
> +	if (clk[idx])
> +		clktmp = clk[idx];
> +	else if (clk[0])
> +		clktmp = clk[0];
> +	else
> +		clktmp = CLK_DEFAULT;
> +	priv->can.clock.freq = clktmp;
> +
> +	if (cir[idx] != 0xff) {
> +		priv->cpu_interface = cir[idx] & 0xff;
> +	} else if (cir[0] != 0xff) {
> +		priv->cpu_interface = cir[0] & 0xff;
> +	} else {
> +		/* The system clock may not exceed 10 MHz */
> +		if (clktmp > 10000000) {
> +			priv->cpu_interface |= CPUIF_DSC;
> +			clktmp /= 2;
> +		}
> +		/* The memory clock may not exceed 8 MHz */
> +		if (clktmp > 8000000)
> +			priv->cpu_interface |= CPUIF_DMC;
> +	}
> +
> +	if (priv->cpu_interface & CPUIF_DSC)
> +		priv->can.clock.freq /= 2;
> +
> +	if (bcr[idx] != 0xff)
> +		priv->bus_config = bcr[idx] & 0xff;
> +	else if (bcr[0] != 0xff)
> +		priv->bus_config = bcr[0] & 0xff;
bus_config is u8
> +	else
> +		priv->bus_config = BCR_DEFAULT;
> +
> +	if (cor[idx] != 0xff)
> +		priv->clkout = cor[idx];
> +	else if (cor[0] != 0xff)
> +		priv->clkout = cor[0] & 0xff;
> +	else
> +		priv->clkout = COR_DEFAULT;
> +
> +	dev_set_drvdata(&pdev->dev, dev);
> +	SET_NETDEV_DEV(dev, &pdev->dev);
> +
> +	err = register_cc770dev(dev);
> +	if (err) {
> +		dev_err(&pdev->dev, "registering %s failed (err=%d)\n",
> +			DRV_NAME, err);
> +		goto exit_unmap;
> +	}
> +
> +	dev_info(&pdev->dev, "%s device registered (reg_base=0x%p, irq=%d)\n",
> +		 DRV_NAME, priv->reg_base, dev->irq);
> +	return 0;
> +
> + exit_unmap:
> +	if (mem[idx])
> +		iounmap(base);
> + exit_release:
> +	if (mem[idx])
> +		release_mem_region(mem[idx], iosize);
> +	else
> +		release_region(port[idx], iosize);
> + exit:
> +	return err;
> +}
> +
> +static int __devexit cc770_isa_remove(struct platform_device *pdev)
> +{
> +	struct net_device *dev = dev_get_drvdata(&pdev->dev);
> +	struct cc770_priv *priv = netdev_priv(dev);
> +	int idx = pdev->id;
> +
> +	unregister_cc770dev(dev);
> +	dev_set_drvdata(&pdev->dev, NULL);
> +
> +	if (mem[idx]) {
> +		iounmap(priv->reg_base);
> +		release_mem_region(mem[idx], CC770_IOSIZE);
> +	} else {
> +		if (priv->read_reg == cc770_isa_port_read_reg_indirect)
> +			release_region(port[idx], CC770_IOSIZE_INDIRECT);
> +		else
> +			release_region(port[idx], CC770_IOSIZE);
> +	}
> +	free_cc770dev(dev);
> +
> +	return 0;
> +}
> +
> +static struct platform_driver cc770_isa_driver = {
> +	.probe = cc770_isa_probe,
> +	.remove = __devexit_p(cc770_isa_remove),
> +	.driver = {
> +		.name = DRV_NAME,
> +		.owner = THIS_MODULE,
> +	},
> +};
> +
> +static int __init cc770_isa_init(void)
> +{
> +	int idx, err;
> +
> +	for (idx = 0; idx < MAXDEV; idx++) {
ARRAY_SIZE?
> +		if ((port[idx] || mem[idx]) && irq[idx]) {
> +			cc770_isa_devs[idx] =
> +				platform_device_alloc(DRV_NAME, idx);
> +			if (!cc770_isa_devs[idx]) {
> +				err = -ENOMEM;
> +				goto exit_free_devices;
> +			}
> +			err = platform_device_add(cc770_isa_devs[idx]);
> +			if (err) {
> +				platform_device_put(cc770_isa_devs[idx]);
> +				goto exit_free_devices;
> +			}
> +			pr_debug("%s: platform device %d: port=%#lx, mem=%#lx, "
> +				 "irq=%d\n",
> +				 DRV_NAME, idx, port[idx], mem[idx], irq[idx]);
> +		} else if (idx == 0 || port[idx] || mem[idx]) {
> +				pr_err("%s: insufficient parameters supplied\n",
> +				       DRV_NAME);
> +				err = -EINVAL;
> +				goto exit_free_devices;
> +		}
> +	}
> +
> +	err = platform_driver_register(&cc770_isa_driver);
> +	if (err)
> +		goto exit_free_devices;
> +
> +	pr_info("Legacy %s driver for max. %d devices registered\n",
> +		DRV_NAME, MAXDEV);
> +
> +	return 0;
> +
> +exit_free_devices:
> +	while (--idx >= 0) {
> +		if (cc770_isa_devs[idx])
> +			platform_device_unregister(cc770_isa_devs[idx]);
> +	}
> +
> +	return err;
> +}
> +module_init(cc770_isa_init);
> +
> +static void __exit cc770_isa_exit(void)
> +{
> +	int idx;
> +
> +	platform_driver_unregister(&cc770_isa_driver);
> +	for (idx = 0; idx < MAXDEV; idx++) {
ARRAY_SIZE
> +		if (cc770_isa_devs[idx])
> +			platform_device_unregister(cc770_isa_devs[idx]);
> +	}
> +}
> +module_exit(cc770_isa_exit);
Wolfgang Grandegger Nov. 28, 2011, 1:59 p.m. UTC | #6
On 11/28/2011 01:09 PM, Marc Kleine-Budde wrote:
> On 11/25/2011 10:43 AM, Wolfgang Grandegger wrote:
>> This patch adds support for legacy Bosch CC770 and Intel AN82527 CAN
>> controllers on the ISA or PC-104 bus. The I/O port or memory address
>> and the IRQ number must be specified via module parameters:
>>
>>   insmod cc770_isa.ko port=0x310,0x380 irq=7,11
>>
>> for ISA devices using I/O ports or:
>>
>>   insmod cc770_isa.ko mem=0xd1000,0xd1000 irq=7,11
>>
>> for memory mapped ISA devices.
>>
>> Indirect access via address and data port is supported as well:
>>
>>   insmod cc770_isa.ko port=0x310,0x380 indirect=1 irq=7,11
>>
>> Furthermore, the following mode parameter can be defined:
>>
>>   clk: External oscillator clock frequency (default=16000000 [16 MHz])
>>   cir: CPU interface register (default=0x40 [DSC])
>>   ocr, Bus configuration register (default=0x40 [CBY])
>>   cor, Clockout register (default=0x00)
>>
>> Note: for clk, cir, bcr and cor, the first argument re-defines the
>> default for all other devices, e.g.:
>>
>>   insmod cc770_isa.ko mem=0xd1000,0xd1000 irq=7,11 clk=24000000
>>
>> is equivalent to
>>
>>   insmod cc770_isa.ko mem=0xd1000,0xd1000 irq=7,11 clk=24000000,24000000
>>
>> Signed-off-by: Wolfgang Grandegger <wg@grandegger.com>
> 
> Some nitpicking inside.
> 
> Marc
>> ---
>>  drivers/net/can/cc770/Kconfig     |   11 ++
>>  drivers/net/can/cc770/Makefile    |    1 +
>>  drivers/net/can/cc770/cc770_isa.c |  336 +++++++++++++++++++++++++++++++++++++
>>  3 files changed, 348 insertions(+), 0 deletions(-)
>>  create mode 100644 drivers/net/can/cc770/cc770_isa.c
>>
>> diff --git a/drivers/net/can/cc770/Kconfig b/drivers/net/can/cc770/Kconfig
>> index 225131b..28e4d48 100644
>> --- a/drivers/net/can/cc770/Kconfig
>> +++ b/drivers/net/can/cc770/Kconfig
>> @@ -1,3 +1,14 @@
>>  menuconfig CAN_CC770
>>  	tristate "Bosch CC770 and Intel AN82527 devices"
>>  	depends on CAN_DEV && HAS_IOMEM
>> +
>> +if CAN_CC770
>> +
>> +config CAN_CC770_ISA
>> +	tristate "ISA Bus based legacy CC770 driver"
>> +	---help---
>> +	  This driver adds legacy support for CC770 and AN82527 chips
>> +	  connected to the ISA bus using I/O port, memory mapped or
>> +	  indirect access.
>> +
>> +endif
>> diff --git a/drivers/net/can/cc770/Makefile b/drivers/net/can/cc770/Makefile
>> index 34e8180..872ecff 100644
>> --- a/drivers/net/can/cc770/Makefile
>> +++ b/drivers/net/can/cc770/Makefile
>> @@ -3,5 +3,6 @@
>>  #
>>  
>>  obj-$(CONFIG_CAN_CC770) += cc770.o
>> +obj-$(CONFIG_CAN_CC770_ISA) += cc770_isa.o
>>  
>>  ccflags-$(CONFIG_CAN_DEBUG_DEVICES) := -DDEBUG
>> diff --git a/drivers/net/can/cc770/cc770_isa.c b/drivers/net/can/cc770/cc770_isa.c
...
>> +	for (idx = 0; idx < MAXDEV; idx++) {
> ARRAY_SIZE?

Well, I think ARRAY_SIZE is useful to derive the number of elements from
a static array of the type:

  static const int array[] = { 1, 2, 3, 4, }

but not if its declared as:

  static array[MAXDEV]:

... or have I missed something?

I'm fine with all other comments.

Wolfgang.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Laight Nov. 28, 2011, 2:03 p.m. UTC | #7
...
> >> +	for (idx = 0; idx < MAXDEV; idx++) {
> > ARRAY_SIZE?
> 
> Well, I think ARRAY_SIZE is useful to derive the number of 
> elements from a static array of the type:
> 
>   static const int array[] = { 1, 2, 3, 4, }
> 
> but not if its declared as:
> 
>   static array[MAXDEV]:
> 
> ... or have I missed something?

Yes - if you use ARRAY_SIZE() then someone reading the code
doesn't need to find the array definition to ensure the loop
upper bound is correct.

	David


--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Marc Kleine-Budde Nov. 28, 2011, 2:09 p.m. UTC | #8
On 11/28/2011 03:03 PM, David Laight wrote:
>>>> +	for (idx = 0; idx < MAXDEV; idx++) {
>>> ARRAY_SIZE?
>>
>> Well, I think ARRAY_SIZE is useful to derive the number of 
>> elements from a static array of the type:
>>
>>   static const int array[] = { 1, 2, 3, 4, }
>>
>> but not if its declared as:
>>
>>   static array[MAXDEV]:
>>
>> ... or have I missed something?
> 
> Yes - if you use ARRAY_SIZE() then someone reading the code
> doesn't need to find the array definition to ensure the loop
> upper bound is correct.

Yep, that
was my intention, too.

Marc
Wolfgang Grandegger Nov. 28, 2011, 3:10 p.m. UTC | #9
On 11/28/2011 03:09 PM, Marc Kleine-Budde wrote:
> On 11/28/2011 03:03 PM, David Laight wrote:
>>>>> +	for (idx = 0; idx < MAXDEV; idx++) {
>>>> ARRAY_SIZE?
>>>
>>> Well, I think ARRAY_SIZE is useful to derive the number of 
>>> elements from a static array of the type:
>>>
>>>   static const int array[] = { 1, 2, 3, 4, }
>>>
>>> but not if its declared as:
>>>
>>>   static array[MAXDEV]:
>>>
>>> ... or have I missed something?
>>
>> Yes - if you use ARRAY_SIZE() then someone reading the code
>> doesn't need to find the array definition to ensure the loop
>> upper bound is correct.
> 
> Yep, that
> was my intention, too.

OK, I see, and as we are all just human beings ...

Wolfgang.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Oliver Hartkopp Nov. 28, 2011, 4:06 p.m. UTC | #10
>> ... using a reasonable default for bcr of 0x40. But you may need to
>> provide better values for cir, bcr and cor.
>>
> 
> OMG, sorry that I was bothering You but You are absolutely right and with Your
> statement You brought be back on track and You made my day. Thank You !!!!!!
> 
> I just took the values for cpu and bus I was using in my lincan driver and funny
> enough now it's working absolutely perfect.
> 
> Module: modprobe cc770_isa irq=0xa port=0x384 indirect=1 cir=0x61 bcr=0x4A
> 
> Was just sending 50000 telegrams, perfect and no problem at all.
> 
> Thanks a lot again!!!!
> 


This looks like a Tested-by :-)

Thanks Wolfgang (who ever feels addressed)
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Wolfgang Grandegger Nov. 29, 2011, 9:16 a.m. UTC | #11
On 11/28/2011 05:06 PM, Oliver Hartkopp wrote:
> 
>>> ... using a reasonable default for bcr of 0x40. But you may need to
>>> provide better values for cir, bcr and cor.
>>>
>>
>> OMG, sorry that I was bothering You but You are absolutely right and with Your
>> statement You brought be back on track and You made my day. Thank You !!!!!!
>>
>> I just took the values for cpu and bus I was using in my lincan driver and funny
>> enough now it's working absolutely perfect.
>>
>> Module: modprobe cc770_isa irq=0xa port=0x384 indirect=1 cir=0x61 bcr=0x4A
>>
>> Was just sending 50000 telegrams, perfect and no problem at all.
>>
>> Thanks a lot again!!!!
>>
> 
> 
> This looks like a Tested-by :-)

Wolfgang, I just sent out v4. Any chance to give this patch a try? It
would be best to use a recent kernel version but I could also adapt the
patch to your kernel version, 2.6.39, I think!?

As you are using a CC770 chip, I'm especially interested in the relevant
kernel log (dmesg) and "ip -d -s link show".

Thanks,

Wolfgang.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Wolfgang Zarre Dec. 4, 2011, 6:47 p.m. UTC | #12
Hello Wolfgang,

> On 11/28/2011 05:06 PM, Oliver Hartkopp wrote:
>>
>>>> ... using a reasonable default for bcr of 0x40. But you may need to
>>>> provide better values for cir, bcr and cor.
>>>>
>>>
>>> OMG, sorry that I was bothering You but You are absolutely right and with Your
>>> statement You brought be back on track and You made my day. Thank You !!!!!!
>>>
>>> I just took the values for cpu and bus I was using in my lincan driver and funny
>>> enough now it's working absolutely perfect.
>>>
>>> Module: modprobe cc770_isa irq=0xa port=0x384 indirect=1 cir=0x61 bcr=0x4A
>>>
>>> Was just sending 50000 telegrams, perfect and no problem at all.
>>>
>>> Thanks a lot again!!!!
>>>
>>
>>
>> This looks like a Tested-by :-)
>
> Wolfgang, I just sent out v4. Any chance to give this patch a try? It
> would be best to use a recent kernel version but I could also adapt the
> patch to your kernel version, 2.6.39, I think!?

Sorry for my delayed reply, but wasn't earlier possible.
Yes, of course, as long as I have the hardware available I can do some tests, even
on a recent kernel due the fact having the project so far completed, just another
test run on the 9th of December.

Due the flood of emails I lost now track which version You would be interested in
and maybe also which kernel version, so, please let me know and maybe were I may
download the patches.

>
> As you are using a CC770 chip, I'm especially interested in the relevant
> kernel log (dmesg) and "ip -d -s link show".

Should be not a problem at all.

>
> Thanks,
>
> Wolfgang.

Wolfgang
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Wolfgang Grandegger Dec. 4, 2011, 6:56 p.m. UTC | #13
Hi Wolfgang,

On 12/04/2011 07:47 PM, Wolfgang Zarre wrote:
> Hello Wolfgang,
...
>> Wolfgang, I just sent out v4. Any chance to give this patch a try? It
>> would be best to use a recent kernel version but I could also adapt the
>> patch to your kernel version, 2.6.39, I think!?
> 
> Sorry for my delayed reply, but wasn't earlier possible.
> Yes, of course, as long as I have the hardware available I can do some
> tests, even
> on a recent kernel due the fact having the project so far completed,
> just another
> test run on the 9th of December.
> 
> Due the flood of emails I lost now track which version You would be
> interested in
> and maybe also which kernel version, so, please let me know and maybe
> were I may
> download the patches.

Well, yes, I was spinning too fast but the patches have been accepted in
the meantime (actually v6 made it). So you just need to clone the most
recent version of Dave's net-next tree.

>> As you are using a CC770 chip, I'm especially interested in the relevant
>> kernel log (dmesg) and "ip -d -s link show".
> 
> Should be not a problem at all.

Great, thanks.

Wolfgang.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Wolfgang Zarre Dec. 6, 2011, 9:08 p.m. UTC | #14
Hello Wolfgang,

> Hi Wolfgang,
>
> On 12/04/2011 07:47 PM, Wolfgang Zarre wrote:
>> Hello Wolfgang,
> ...
>>> Wolfgang, I just sent out v4. Any chance to give this patch a try? It
>>> would be best to use a recent kernel version but I could also adapt the
>>> patch to your kernel version, 2.6.39, I think!?
>>
>> Sorry for my delayed reply, but wasn't earlier possible.
>> Yes, of course, as long as I have the hardware available I can do some
>> tests, even
>> on a recent kernel due the fact having the project so far completed,
>> just another
>> test run on the 9th of December.
>>
>> Due the flood of emails I lost now track which version You would be
>> interested in
>> and maybe also which kernel version, so, please let me know and maybe
>> were I may
>> download the patches.
>
> Well, yes, I was spinning too fast but the patches have been accepted in
> the meantime (actually v6 made it). So you just need to clone the most
> recent version of Dave's net-next tree.
>
>>> As you are using a CC770 chip, I'm especially interested in the relevant
>>> kernel log (dmesg) and "ip -d -s link show".
>>
>> Should be not a problem at all.
>
> Great, thanks.

Ok, here we go:

uname -r: 3.2.0-rc4

modprobe cc770_isa irq=0xa port=0x384 indirect=1 cir=0x61 bcr=0x4A
ip link set can0 up type can bitrate 500000;

kern.log
Dec  6 20:42:19 svserv01 kernel: [ 2111.900735] CAN device driver interface
Dec  6 20:42:19 svserv01 kernel: [ 2111.903072] cc770: CAN netdevice driver
Dec  6 20:42:19 svserv01 kernel: [ 2111.904692] cc770_isa: platform device 0: port=0x384, mem=0x0, irq=10
Dec  6 20:42:19 svserv01 kernel: [ 2111.904726] cc770_isa cc770_isa.0: probing idx=0: port=0x384, mem=0x0, irq=10
Dec  6 20:42:19 svserv01 kernel: [ 2111.904779] cc770_isa cc770_isa.0: (unregistered net_device): i82527 mode with additional functions
Dec  6 20:42:19 svserv01 kernel: [ 2111.906407] cc770_isa cc770_isa.0: device registered (reg_base=0x00000384, irq=10)
Dec  6 20:42:19 svserv01 kernel: [ 2111.906457] cc770_isa: driver for max. 8 devices registered
   6 20:44:17 svserv01 kernel: [ 2229.886845] cc770_isa cc770_isa.0: can0: setting BTR0=0x00 BTR1=0x1c
Dec  6 20:44:17 svserv01 kernel: [ 2229.886920] cc770_isa cc770_isa.0: can0: Message object 15 for RX data, RTR, SFF and EFF
Dec  6 20:44:17 svserv01 kernel: [ 2229.886937] cc770_isa cc770_isa.0: can0: Message object 11 for TX data, RTR, SFF and EFF
Dec  6 20:52:40 svserv01 kernel: [ 2733.172845] can: controller area network core (rev 20090105 abi 8)
Dec  6 20:52:40 svserv01 kernel: [ 2733.172967] NET: Registered protocol family 29
Dec  6 20:52:40 svserv01 kernel: [ 2733.178187] can: raw protocol (rev 20090105)


ip -d -s link show
4: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN qlen 10
     link/can
     can state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0
     bitrate 500000 sample-point 0.875
     tq 125 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
     cc770: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1
     clock 8000000
     re-started bus-errors arbit-lost error-warn error-pass bus-off
     0          0          0          0          0          0
     RX: bytes  packets  errors  dropped overrun mcast
     0          0        0       0       0       0
     TX: bytes  packets  errors  dropped carrier collsns
     0          0        0       0       0       0


After rebooting the PLC with proprietary buggy kernel:
4: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN qlen 10
     link/can
     can state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0
     bitrate 500000 sample-point 0.875
     tq 125 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
     cc770: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1
     clock 8000000
     re-started bus-errors arbit-lost error-warn error-pass bus-off
     0          0          0          0          0          0
     RX: bytes  packets  errors  dropped overrun mcast
     414        267      0       267     0       0
     TX: bytes  packets  errors  dropped carrier collsns
     0          0        0       0       0       0



After sending 100,000 PDO's with 13ms displacement:
4: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN qlen 10
     link/can
     can state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0
     bitrate 500000 sample-point 0.875
     tq 125 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
     cc770: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1
     clock 8000000
     re-started bus-errors arbit-lost error-warn error-pass bus-off
     0          0          0          0          0          0
     RX: bytes  packets  errors  dropped overrun mcast
     4544       4284     0       331     0       0
     TX: bytes  packets  errors  dropped carrier collsns
     802660     202653   0       0       0       0


The dropped ones of RX may be the not processed input packages and therefore ok.

Let me know if You need more or some other tests.

>
> Wolfgang.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Wolfgang Grandegger Dec. 7, 2011, 1:42 p.m. UTC | #15
Hi Wolfgang,

On 12/06/2011 10:08 PM, Wolfgang Zarre wrote:
> Hello Wolfgang,
> 
>> Hi Wolfgang,
>>
>> On 12/04/2011 07:47 PM, Wolfgang Zarre wrote:
...
>>>
>>> Should be not a problem at all.
>>
>> Great, thanks.
> 
> Ok, here we go:
> 
> uname -r: 3.2.0-rc4
> 
> modprobe cc770_isa irq=0xa port=0x384 indirect=1 cir=0x61 bcr=0x4A
> ip link set can0 up type can bitrate 500000;
> 
> kern.log
> Dec  6 20:42:19 svserv01 kernel: [ 2111.900735] CAN device driver interface
> Dec  6 20:42:19 svserv01 kernel: [ 2111.903072] cc770: CAN netdevice driver
> Dec  6 20:42:19 svserv01 kernel: [ 2111.904692] cc770_isa: platform
> device 0: port=0x384, mem=0x0, irq=10
> Dec  6 20:42:19 svserv01 kernel: [ 2111.904726] cc770_isa cc770_isa.0:
> probing idx=0: port=0x384, mem=0x0, irq=10
> Dec  6 20:42:19 svserv01 kernel: [ 2111.904779] cc770_isa cc770_isa.0:
> (unregistered net_device): i82527 mode with additional functions
> Dec  6 20:42:19 svserv01 kernel: [ 2111.906407] cc770_isa cc770_isa.0:
> device registered (reg_base=0x00000384, irq=10)
> Dec  6 20:42:19 svserv01 kernel: [ 2111.906457] cc770_isa: driver for
> max. 8 devices registered
>   6 20:44:17 svserv01 kernel: [ 2229.886845] cc770_isa cc770_isa.0:
> can0: setting BTR0=0x00 BTR1=0x1c
> Dec  6 20:44:17 svserv01 kernel: [ 2229.886920] cc770_isa cc770_isa.0:
> can0: Message object 15 for RX data, RTR, SFF and EFF
> Dec  6 20:44:17 svserv01 kernel: [ 2229.886937] cc770_isa cc770_isa.0:
> can0: Message object 11 for TX data, RTR, SFF and EFF
> Dec  6 20:52:40 svserv01 kernel: [ 2733.172845] can: controller area
> network core (rev 20090105 abi 8)
> Dec  6 20:52:40 svserv01 kernel: [ 2733.172967] NET: Registered protocol
> family 29
> Dec  6 20:52:40 svserv01 kernel: [ 2733.178187] can: raw protocol (rev
> 20090105)
> 
> 
> ip -d -s link show
> 4: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN
> qlen 10
>     link/can
>     can state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0
>     bitrate 500000 sample-point 0.875
>     tq 125 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
>     cc770: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1
>     clock 8000000
>     re-started bus-errors arbit-lost error-warn error-pass bus-off
>     0          0          0          0          0          0
>     RX: bytes  packets  errors  dropped overrun mcast
>     0          0        0       0       0       0
>     TX: bytes  packets  errors  dropped carrier collsns
>     0          0        0       0       0       0
> 
> 
> After rebooting the PLC with proprietary buggy kernel:
> 4: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN
> qlen 10
>     link/can
>     can state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0
>     bitrate 500000 sample-point 0.875
>     tq 125 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
>     cc770: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1
>     clock 8000000
>     re-started bus-errors arbit-lost error-warn error-pass bus-off
>     0          0          0          0          0          0
>     RX: bytes  packets  errors  dropped overrun mcast
>     414        267      0       267     0       0
>     TX: bytes  packets  errors  dropped carrier collsns
>     0          0        0       0       0       0
> 
> 
> 
> After sending 100,000 PDO's with 13ms displacement:
> 4: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN
> qlen 10
>     link/can
>     can state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0
>     bitrate 500000 sample-point 0.875
>     tq 125 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
>     cc770: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1
>     clock 8000000
>     re-started bus-errors arbit-lost error-warn error-pass bus-off
>     0          0          0          0          0          0
>     RX: bytes  packets  errors  dropped overrun mcast
>     4544       4284     0       331     0       0
>     TX: bytes  packets  errors  dropped carrier collsns
>     802660     202653   0       0       0       0
> 
> 
> The dropped ones of RX may be the not processed input packages and
> therefore ok.
> 
> Let me know if You need more or some other tests.

You could provoke some state changes or bus-off conditions to see if the
berr-counter shows reasonable results. I'm currently consolidating and
unifying error state and bus-off handling. Would be nice if you could do
some further tests when I have the patches ready...

Thanks for testing.

Wolfgang.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Wolfgang Grandegger Dec. 9, 2011, 10:26 a.m. UTC | #16
On 12/07/2011 02:42 PM, Wolfgang Grandegger wrote:
> Hi Wolfgang,
> 
> On 12/06/2011 10:08 PM, Wolfgang Zarre wrote:
>> Hello Wolfgang,
>>
>>> Hi Wolfgang,
>>>
>>> On 12/04/2011 07:47 PM, Wolfgang Zarre wrote:
> ...
>>>>
>>>> Should be not a problem at all.
>>>
>>> Great, thanks.
>>
>> Ok, here we go:
>>
>> uname -r: 3.2.0-rc4
>>
>> modprobe cc770_isa irq=0xa port=0x384 indirect=1 cir=0x61 bcr=0x4A
>> ip link set can0 up type can bitrate 500000;
>>
>> kern.log
>> Dec  6 20:42:19 svserv01 kernel: [ 2111.900735] CAN device driver interface
>> Dec  6 20:42:19 svserv01 kernel: [ 2111.903072] cc770: CAN netdevice driver
>> Dec  6 20:42:19 svserv01 kernel: [ 2111.904692] cc770_isa: platform
>> device 0: port=0x384, mem=0x0, irq=10
>> Dec  6 20:42:19 svserv01 kernel: [ 2111.904726] cc770_isa cc770_isa.0:
>> probing idx=0: port=0x384, mem=0x0, irq=10
>> Dec  6 20:42:19 svserv01 kernel: [ 2111.904779] cc770_isa cc770_isa.0:
>> (unregistered net_device): i82527 mode with additional functions
>> Dec  6 20:42:19 svserv01 kernel: [ 2111.906407] cc770_isa cc770_isa.0:
>> device registered (reg_base=0x00000384, irq=10)
>> Dec  6 20:42:19 svserv01 kernel: [ 2111.906457] cc770_isa: driver for
>> max. 8 devices registered
>>   6 20:44:17 svserv01 kernel: [ 2229.886845] cc770_isa cc770_isa.0:
>> can0: setting BTR0=0x00 BTR1=0x1c
>> Dec  6 20:44:17 svserv01 kernel: [ 2229.886920] cc770_isa cc770_isa.0:
>> can0: Message object 15 for RX data, RTR, SFF and EFF
>> Dec  6 20:44:17 svserv01 kernel: [ 2229.886937] cc770_isa cc770_isa.0:
>> can0: Message object 11 for TX data, RTR, SFF and EFF
>> Dec  6 20:52:40 svserv01 kernel: [ 2733.172845] can: controller area
>> network core (rev 20090105 abi 8)
>> Dec  6 20:52:40 svserv01 kernel: [ 2733.172967] NET: Registered protocol
>> family 29
>> Dec  6 20:52:40 svserv01 kernel: [ 2733.178187] can: raw protocol (rev
>> 20090105)
>>
>>
>> ip -d -s link show
>> 4: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN
>> qlen 10
>>     link/can
>>     can state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0
>>     bitrate 500000 sample-point 0.875
>>     tq 125 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
>>     cc770: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1
>>     clock 8000000
>>     re-started bus-errors arbit-lost error-warn error-pass bus-off
>>     0          0          0          0          0          0
>>     RX: bytes  packets  errors  dropped overrun mcast
>>     0          0        0       0       0       0
>>     TX: bytes  packets  errors  dropped carrier collsns
>>     0          0        0       0       0       0
>>
>>
>> After rebooting the PLC with proprietary buggy kernel:
>> 4: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN
>> qlen 10
>>     link/can
>>     can state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0
>>     bitrate 500000 sample-point 0.875
>>     tq 125 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
>>     cc770: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1
>>     clock 8000000
>>     re-started bus-errors arbit-lost error-warn error-pass bus-off
>>     0          0          0          0          0          0
>>     RX: bytes  packets  errors  dropped overrun mcast
>>     414        267      0       267     0       0
>>     TX: bytes  packets  errors  dropped carrier collsns
>>     0          0        0       0       0       0
>>
>>
>>
>> After sending 100,000 PDO's with 13ms displacement:
>> 4: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN
>> qlen 10
>>     link/can
>>     can state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0
>>     bitrate 500000 sample-point 0.875
>>     tq 125 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
>>     cc770: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1
>>     clock 8000000
>>     re-started bus-errors arbit-lost error-warn error-pass bus-off
>>     0          0          0          0          0          0
>>     RX: bytes  packets  errors  dropped overrun mcast
>>     4544       4284     0       331     0       0
>>     TX: bytes  packets  errors  dropped carrier collsns
>>     802660     202653   0       0       0       0
>>
>>
>> The dropped ones of RX may be the not processed input packages and
>> therefore ok.
>>
>> Let me know if You need more or some other tests.
> 
> You could provoke some state changes or bus-off conditions to see if the
> berr-counter shows reasonable results. I'm currently consolidating and
> unifying error state and bus-off handling. Would be nice if you could do
> some further tests when I have the patches ready...

I just pushed the mentioned modifications to the "devel" branch of my
"wg-linux-can-next" [1] repository. You can get it as shown below:

  $ git clone --reference=<some-recent-net-next-tree> \
      git://gitorious.org/~wgrandegger/linux-can/wg-linux-can-next.git
  $ git checkout -b devel devel

[1] https://gitorious.org/~wgrandegger/linux-can/wg-linux-can-next

Wolfgang.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Wolfgang Zarre Dec. 11, 2011, 6:33 p.m. UTC | #17
Hello Wolfgang,
> On 12/07/2011 02:42 PM, Wolfgang Grandegger wrote:
>> Hi Wolfgang,
>>
>> On 12/06/2011 10:08 PM, Wolfgang Zarre wrote:
>>> Hello Wolfgang,
>>>
>>>> Hi Wolfgang,
>>>>
>>>> On 12/04/2011 07:47 PM, Wolfgang Zarre wrote:
>> ...
>>>>>
>>>>> Should be not a problem at all.
>>>>
>>>> Great, thanks.
>>>
>>> Ok, here we go:
>>>
>>> uname -r: 3.2.0-rc4
>>>
>>> modprobe cc770_isa irq=0xa port=0x384 indirect=1 cir=0x61 bcr=0x4A
>>> ip link set can0 up type can bitrate 500000;
>>>
>>> kern.log
>>> Dec  6 20:42:19 svserv01 kernel: [ 2111.900735] CAN device driver interface
>>> Dec  6 20:42:19 svserv01 kernel: [ 2111.903072] cc770: CAN netdevice driver
>>> Dec  6 20:42:19 svserv01 kernel: [ 2111.904692] cc770_isa: platform
>>> device 0: port=0x384, mem=0x0, irq=10
>>> Dec  6 20:42:19 svserv01 kernel: [ 2111.904726] cc770_isa cc770_isa.0:
>>> probing idx=0: port=0x384, mem=0x0, irq=10
>>> Dec  6 20:42:19 svserv01 kernel: [ 2111.904779] cc770_isa cc770_isa.0:
>>> (unregistered net_device): i82527 mode with additional functions
>>> Dec  6 20:42:19 svserv01 kernel: [ 2111.906407] cc770_isa cc770_isa.0:
>>> device registered (reg_base=0x00000384, irq=10)
>>> Dec  6 20:42:19 svserv01 kernel: [ 2111.906457] cc770_isa: driver for
>>> max. 8 devices registered
>>>    6 20:44:17 svserv01 kernel: [ 2229.886845] cc770_isa cc770_isa.0:
>>> can0: setting BTR0=0x00 BTR1=0x1c
>>> Dec  6 20:44:17 svserv01 kernel: [ 2229.886920] cc770_isa cc770_isa.0:
>>> can0: Message object 15 for RX data, RTR, SFF and EFF
>>> Dec  6 20:44:17 svserv01 kernel: [ 2229.886937] cc770_isa cc770_isa.0:
>>> can0: Message object 11 for TX data, RTR, SFF and EFF
>>> Dec  6 20:52:40 svserv01 kernel: [ 2733.172845] can: controller area
>>> network core (rev 20090105 abi 8)
>>> Dec  6 20:52:40 svserv01 kernel: [ 2733.172967] NET: Registered protocol
>>> family 29
>>> Dec  6 20:52:40 svserv01 kernel: [ 2733.178187] can: raw protocol (rev
>>> 20090105)
>>>
>>>
>>> ip -d -s link show
>>> 4: can0:<NOARP,UP,LOWER_UP,ECHO>  mtu 16 qdisc pfifo_fast state UNKNOWN
>>> qlen 10
>>>      link/can
>>>      can state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0
>>>      bitrate 500000 sample-point 0.875
>>>      tq 125 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
>>>      cc770: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1
>>>      clock 8000000
>>>      re-started bus-errors arbit-lost error-warn error-pass bus-off
>>>      0          0          0          0          0          0
>>>      RX: bytes  packets  errors  dropped overrun mcast
>>>      0          0        0       0       0       0
>>>      TX: bytes  packets  errors  dropped carrier collsns
>>>      0          0        0       0       0       0
>>>
>>>
>>> After rebooting the PLC with proprietary buggy kernel:
>>> 4: can0:<NOARP,UP,LOWER_UP,ECHO>  mtu 16 qdisc pfifo_fast state UNKNOWN
>>> qlen 10
>>>      link/can
>>>      can state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0
>>>      bitrate 500000 sample-point 0.875
>>>      tq 125 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
>>>      cc770: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1
>>>      clock 8000000
>>>      re-started bus-errors arbit-lost error-warn error-pass bus-off
>>>      0          0          0          0          0          0
>>>      RX: bytes  packets  errors  dropped overrun mcast
>>>      414        267      0       267     0       0
>>>      TX: bytes  packets  errors  dropped carrier collsns
>>>      0          0        0       0       0       0
>>>
>>>
>>>
>>> After sending 100,000 PDO's with 13ms displacement:
>>> 4: can0:<NOARP,UP,LOWER_UP,ECHO>  mtu 16 qdisc pfifo_fast state UNKNOWN
>>> qlen 10
>>>      link/can
>>>      can state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0
>>>      bitrate 500000 sample-point 0.875
>>>      tq 125 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
>>>      cc770: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1
>>>      clock 8000000
>>>      re-started bus-errors arbit-lost error-warn error-pass bus-off
>>>      0          0          0          0          0          0
>>>      RX: bytes  packets  errors  dropped overrun mcast
>>>      4544       4284     0       331     0       0
>>>      TX: bytes  packets  errors  dropped carrier collsns
>>>      802660     202653   0       0       0       0
>>>
>>>
>>> The dropped ones of RX may be the not processed input packages and
>>> therefore ok.
>>>
>>> Let me know if You need more or some other tests.
>>
>> You could provoke some state changes or bus-off conditions to see if the
>> berr-counter shows reasonable results. I'm currently consolidating and
>> unifying error state and bus-off handling. Would be nice if you could do
>> some further tests when I have the patches ready...
>
> I just pushed the mentioned modifications to the "devel" branch of my
> "wg-linux-can-next" [1] repository. You can get it as shown below:
>
>    $ git clone --reference=<some-recent-net-next-tree>  \
>        git://gitorious.org/~wgrandegger/linux-can/wg-linux-can-next.git
>    $ git checkout -b devel devel
>
> [1] https://gitorious.org/~wgrandegger/linux-can/wg-linux-can-next
>
> Wolfgang.

OK, I was trying so far and You will find below the results.
Just FYI the states on the PLC side couldn't be verified because the function
provided by the manufacturer is not working at all and CAN analyser was not
available.

We are running CANopen and therefore the PLC will send automatically a heartbeat.

I produced the bus-off state through a short circuit between L/H which was
working as expected.

A bit odd was that on the second try I had to reload the module
because a ip down/up was not enough.

Let me know if You would need further tests or different procedure.



Starting procedure:
Cable disconnected
Restarting PC with new driver
Restarting PLC
Connecting cable
modprobe cc770_isa irq=0xa port=0x384 indirect=1 cir=0x61 bcr=0x4A
dmesg:
[  221.996751] CAN device driver interface
[  222.036036] cc770: CAN netdevice driver
[  222.054260] cc770_isa: platform device 0: port=0x384, mem=0x0, irq=10
[  222.054293] cc770_isa cc770_isa.0: probing idx=0: port=0x384, mem=0x0, irq=10
[  222.054343] cc770_isa cc770_isa.0: (unregistered net_device): i82527 mode with additional functions
[  222.055925] cc770_isa cc770_isa.0: device registered (reg_base=0x00000384, irq=10)
[  222.055972] cc770_isa: driver for max. 8 devices registered

ip -d -s link show can0
4: can0: <NOARP,ECHO> mtu 16 qdisc noop state DOWN qlen 10
     link/can
     can state STOPPED (berr-counter tx 92 rx 103) restart-ms 0
     bitrate 0 sample-point 0.000
     tq 0 prop-seg 0 phase-seg1 0 phase-seg2 0 sjw 0
     cc770: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1
     clock 8000000
     re-started bus-errors arbit-lost error-warn error-pass bus-off
     0          0          0          0          0          0
     RX: bytes  packets  errors  dropped overrun mcast
     0          0        0       0       0       0
     TX: bytes  packets  errors  dropped carrier collsns
     0          0        0       0       0       0

ip link set can0 up type can bitrate 500000
dmesg:
[  287.871983] cc770_isa cc770_isa.0: can0: setting BTR0=0x00 BTR1=0x1c
[  287.872103] cc770_isa cc770_isa.0: can0: Message object 15 for RX data, RTR, SFF and EFF
[  287.872119] cc770_isa cc770_isa.0: can0: Message object 11 for TX data, RTR, SFF and EFF

ip -d -s link show can0
4: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN qlen 10
     link/can
     can state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0
     bitrate 500000 sample-point 0.875
     tq 125 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
     cc770: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1
     clock 8000000
     re-started bus-errors arbit-lost error-warn error-pass bus-off
     0          0          0          0          0          0
     RX: bytes  packets  errors  dropped overrun mcast
     0          0        0       0       0       0
     TX: bytes  packets  errors  dropped carrier collsns
     0          0        0       0       0       0

PLC stays in unknown CAN state (as usual )
Rebooting PLC

dmesg:
[  466.169054] can: controller area network core (rev 20090105 abi 8)
[  466.169178] NET: Registered protocol family 29
[  466.174339] can: raw protocol (rev 20090105)


PLC is sending heartbeat
Starting PC heartbeats

ip -d -s link show can0
4: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN qlen 10
     link/can
     can state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0
     bitrate 500000 sample-point 0.875
     tq 125 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
     cc770: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1
     clock 8000000
     re-started bus-errors arbit-lost error-warn error-pass bus-off
     0          0          0          0          0          0
     RX: bytes  packets  errors  dropped overrun mcast
     513        365      0       0       0       0
     TX: bytes  packets  errors  dropped carrier collsns
     20         20       0       0       0       0


Producing L/H short circuit for 2 seconds
dmesg:
[  885.409058] cc770_isa cc770_isa.0: can0: status interrupt (0x5b)
[  885.420475] cc770_isa cc770_isa.0: can0: status interrupt (0xc5)
[  885.420496] cc770_isa cc770_isa.0: can0: bus-off

ip -d -s link show can0
4: can0: <NO-CARRIER,NOARP,UP,ECHO> mtu 16 qdisc pfifo_fast state DOWN qlen 10
     link/can
     can state BUS-OFF (berr-counter tx 92 rx 103) restart-ms 0
     bitrate 500000 sample-point 0.875
     tq 125 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
     cc770: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1
     clock 8000000
     re-started bus-errors arbit-lost error-warn error-pass bus-off
     0          0          0          1          0          1
     RX: bytes  packets  errors  dropped overrun mcast
     544        382      0       0       0       0
     TX: bytes  packets  errors  dropped carrier collsns
     30         29       0       0       0       0

Sending and receiving stops.

Trying to recover on PC:
ip link set can0 down;
ip -d -s link show can0
4: can0: <NOARP,ECHO> mtu 16 qdisc pfifo_fast state DOWN qlen 10
     link/can
     can state STOPPED (berr-counter tx 92 rx 103) restart-ms 0
     bitrate 500000 sample-point 0.875
     tq 125 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
     cc770: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1
     clock 8000000
     re-started bus-errors arbit-lost error-warn error-pass bus-off
     0          0          0          1          0          1
     RX: bytes  packets  errors  dropped overrun mcast
     544        382      0       0       0       0
     TX: bytes  packets  errors  dropped carrier collsns
     30         29       0       1       0       0

ip link set can0 up type can bitrate 500000;
dmesg:
[ 1090.937778] cc770_isa cc770_isa.0: can0: setting BTR0=0x00 BTR1=0x1c
[ 1090.937869] cc770_isa cc770_isa.0: can0: Message object 15 for RX data, RTR, SFF and EFF
[ 1090.937885] cc770_isa cc770_isa.0: can0: Message object 11 for TX data, RTR, SFF and EFF
[ 1090.938050] ADDRCONF(NETDEV_CHANGE): can0: link becomes ready
[ 1090.940769] cc770_isa cc770_isa.0: can0: status interrupt (0x5)

ip -d -s link show can0
4: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UP qlen 10
     link/can
     can state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0
     bitrate 500000 sample-point 0.875
     tq 125 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
     cc770: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1
     clock 8000000
     re-started bus-errors arbit-lost error-warn error-pass bus-off
     0          0          0          1          0          1
     RX: bytes  packets  errors  dropped overrun mcast
     552        383      0       0       0       0
     TX: bytes  packets  errors  dropped carrier collsns
     30         29       0       1       0       0

PLC in unknown state but not sending heartbeat,
Rebooting PLC
PLC sends heartbeat but PC cannot send (buffer overrun)

ip -d -s link show can0
4: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UP qlen 10
     link/can
     can state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0
     bitrate 500000 sample-point 0.875
     tq 125 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
     cc770: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1
     clock 8000000
     re-started bus-errors arbit-lost error-warn error-pass bus-off
     0          0          0          1          0          1
     RX: bytes  packets  errors  dropped overrun mcast
     582        398      0       0       0       0
     TX: bytes  packets  errors  dropped carrier collsns
     30         29       0       1       0       0


Reloading driver

modprobe -r cc770_isa
dmesg:
[ 1457.133359] cc770: driver removed

modprobe cc770_isa irq=0xa port=0x384 indirect=1 cir=0x61 bcr=0x4A
dmesg:
[ 1474.051479] CAN device driver interface
[ 1474.053180] cc770: CAN netdevice driver
[ 1474.054416] cc770_isa: platform device 0: port=0x384, mem=0x0, irq=10
[ 1474.054449] cc770_isa cc770_isa.0: probing idx=0: port=0x384, mem=0x0, irq=10
[ 1474.054500] cc770_isa cc770_isa.0: (unregistered net_device): i82527 mode with additional functions
[ 1474.056097] cc770_isa cc770_isa.0: device registered (reg_base=0x00000384, irq=10)
[ 1474.056146] cc770_isa: driver for max. 8 devices registered

ip link set can0 up type can bitrate 500000;
[ 1484.586697] cc770_isa cc770_isa.0: can0: setting BTR0=0x00 BTR1=0x1c
[ 1484.586775] cc770_isa cc770_isa.0: can0: Message object 15 for RX data, RTR, SFF and EFF
[ 1484.586791] cc770_isa cc770_isa.0: can0: Message object 11 for TX data, RTR, SFF and EFF

Receiving and sending heartbeat
ip -d -s link show can0
5: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN qlen 10
     link/can
     can state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0
     bitrate 500000 sample-point 0.875
     tq 125 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
     cc770: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1
     clock 8000000
     re-started bus-errors arbit-lost error-warn error-pass bus-off
     0          0          0          0          0          0
     RX: bytes  packets  errors  dropped overrun mcast
     158        157      0       0       0       0
     TX: bytes  packets  errors  dropped carrier collsns
     16         16       0       0       0       0


-----------------------------------------

Producing L/H short circuit again for 2 seconds

dmesg:
[ 1719.018116] cc770_isa cc770_isa.0: can0: status interrupt (0x5b)

ip -d -s link show can0
5: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN qlen 10
     link/can
     can state ERROR-WARNING (berr-counter tx 128 rx 128) restart-ms 0
     bitrate 500000 sample-point 0.875
     tq 125 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
     cc770: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1
     clock 8000000
     re-started bus-errors arbit-lost error-warn error-pass bus-off
     0          0          0          1          0          0
     RX: bytes  packets  errors  dropped overrun mcast
     271        263      0       0       0       0
     TX: bytes  packets  errors  dropped carrier collsns
     88         87       0       0       0       0


Sending and receiving stops.

Trying to recover on PC with driver reload:
modprobe -r cc770_isa
dmesg:
[ 1820.358418] cc770: driver removed

modprobe cc770_isa irq=0xa port=0x384 indirect=1 cir=0x61 bcr=0x4A
dmesg:
[ 1826.810914] CAN device driver interface
[ 1826.812619] cc770: CAN netdevice driver
[ 1826.814126] cc770_isa: platform device 0: port=0x384, mem=0x0, irq=10
[ 1826.814158] cc770_isa cc770_isa.0: probing idx=0: port=0x384, mem=0x0, irq=10
[ 1826.814211] cc770_isa cc770_isa.0: (unregistered net_device): i82527 mode with additional functions
[ 1826.815789] cc770_isa cc770_isa.0: device registered (reg_base=0x00000384, irq=10)
[ 1826.815839] cc770_isa: driver for max. 8 devices registered

ip -d -s link show can0
6: can0: <NOARP,ECHO> mtu 16 qdisc noop state DOWN qlen 10
     link/can
     can state STOPPED (berr-counter tx 92 rx 103) restart-ms 0
     bitrate 0 sample-point 0.000
     tq 0 prop-seg 0 phase-seg1 0 phase-seg2 0 sjw 0
     cc770: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1
     clock 8000000
     re-started bus-errors arbit-lost error-warn error-pass bus-off
     0          0          0          0          0          0
     RX: bytes  packets  errors  dropped overrun mcast
     0          0        0       0       0       0
     TX: bytes  packets  errors  dropped carrier collsns
     0          0        0       0       0       0

ip link set can0 up type can bitrate 500000;
dmesg:
[ 1861.776977] cc770_isa cc770_isa.0: can0: setting BTR0=0x00 BTR1=0x1c
[ 1861.777102] cc770_isa cc770_isa.0: can0: Message object 15 for RX data, RTR, SFF and EFF
[ 1861.777118] cc770_isa cc770_isa.0: can0: Message object 11 for TX data, RTR, SFF and EFF

ip -d -s link show can0
6: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN qlen 10
     link/can
     can state ERROR-ACTIVE (berr-counter tx 128 rx 128) restart-ms 0
     bitrate 500000 sample-point 0.875
     tq 125 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
     cc770: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1
     clock 8000000
     re-started bus-errors arbit-lost error-warn error-pass bus-off
     0          0          0          0          0          0
     RX: bytes  packets  errors  dropped overrun mcast
     0          0        0       0       0       0
     TX: bytes  packets  errors  dropped carrier collsns
     1          0        0       0       0       0

PLC in unknown state
Unable to send and receive heartbeat
Rebooting PLC

ip -d -s link show can0
6: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN qlen 10
     link/can
     can state ERROR-ACTIVE (berr-counter tx 115 rx 0) restart-ms 0
     bitrate 500000 sample-point 0.875
     tq 125 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
     cc770: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1
     clock 8000000
     re-started bus-errors arbit-lost error-warn error-pass bus-off
     0          0          0          0          0          0
     RX: bytes  packets  errors  dropped overrun mcast
     0          0        0       0       0       0
     TX: bytes  packets  errors  dropped carrier collsns
     13         13       0       0       0       0

ip -d -s link show can0
6: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN qlen 10
     link/can
     can state ERROR-ACTIVE (berr-counter tx 107 rx 0) restart-ms 0
     bitrate 500000 sample-point 0.875
     tq 125 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
     cc770: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1
     clock 8000000
     re-started bus-errors arbit-lost error-warn error-pass bus-off
     0          0          0          0          0          0
     RX: bytes  packets  errors  dropped overrun mcast
     30         15       0       0       0       0
     TX: bytes  packets  errors  dropped carrier collsns
     21         21       0       0       0       0

dmesg:
[ 2102.085718] cc770_isa cc770_isa.0: can0: status interrupt (0x18)

ip -d -s link show can0
6: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN qlen 10
     link/can
     can state ERROR-ACTIVE (berr-counter tx 32 rx 0) restart-ms 0
     bitrate 500000 sample-point 0.875
     tq 125 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
     cc770: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1
     clock 8000000
     re-started bus-errors arbit-lost error-warn error-pass bus-off
     0          0          0          0          0          0
     RX: bytes  packets  errors  dropped overrun mcast
     310        156      0       0       0       0
     TX: bytes  packets  errors  dropped carrier collsns
     96         96       0       0       0       0

And with counters on zero:
ip -d -s link show can0
6: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN qlen 10
     link/can
     can state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0
     bitrate 500000 sample-point 0.875
     tq 125 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
     cc770: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1
     clock 8000000
     re-started bus-errors arbit-lost error-warn error-pass bus-off
     0          0          0          0          0          0
     RX: bytes  packets  errors  dropped overrun mcast
     358        204      0       0       0       0
     TX: bytes  packets  errors  dropped carrier collsns
     129        129      0       0       0       0


-----------------------------------------
Disconnecting cable for around 4 seconds:

dmesg:
[ 2339.660283] cc770_isa cc770_isa.0: can0: status interrupt (0x5b)

ip -d -s link show can0
6: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN qlen 10
     link/can
     can state ERROR-WARNING (berr-counter tx 128 rx 128) restart-ms 0
     bitrate 500000 sample-point 0.875
     tq 125 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
     cc770: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1
     clock 8000000
     re-started bus-errors arbit-lost error-warn error-pass bus-off
     0          0          0          1          0          0
     RX: bytes  packets  errors  dropped overrun mcast
     459        298      0       0       0       0
     TX: bytes  packets  errors  dropped carrier collsns
     193        192      0       0       0       0

Connecting again:
ip -d -s link show can0
6: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN qlen 10
     link/can
     can state ERROR-WARNING (berr-counter tx 120 rx 0) restart-ms 0
     bitrate 500000 sample-point 0.875
     tq 125 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
     cc770: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1
     clock 8000000
     re-started bus-errors arbit-lost error-warn error-pass bus-off
     0          0          0          1          0          0
     RX: bytes  packets  errors  dropped overrun mcast
     473        311      0       0       0       0
     TX: bytes  packets  errors  dropped carrier collsns
     200        200      0       0       0       0

After some time (around 125 seconds):
dmesg:
[ 2387.172008] cc770_isa cc770_isa.0: can0: status interrupt (0x18)
ip -d -s link show can0
6: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN qlen 10
     link/can
     can state ERROR-ACTIVE (berr-counter tx 29 rx 0) restart-ms 0
     bitrate 500000 sample-point 0.875
     tq 125 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
     cc770: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1
     clock 8000000
     re-started bus-errors arbit-lost error-warn error-pass bus-off
     0          0          0          1          0          0
     RX: bytes  packets  errors  dropped overrun mcast
     616        447      0       0       0       0
     TX: bytes  packets  errors  dropped carrier collsns
     291        291      0       0       0       0



-----------------------------------------
Disconnecting cable for around 55 seconds:

dmesg:
[ 2658.896959] cc770_isa cc770_isa.0: can0: status interrupt (0x5b)

ip -d -s link show can0
6: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN qlen 10
     link/can
     can state ERROR-WARNING (berr-counter tx 128 rx 128) restart-ms 0
     bitrate 500000 sample-point 0.875
     tq 125 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
     cc770: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1
     clock 8000000
     re-started bus-errors arbit-lost error-warn error-pass bus-off
     0          0          0          2          0          0
     RX: bytes  packets  errors  dropped overrun mcast
     797        621      0       0       0       0
     TX: bytes  packets  errors  dropped carrier collsns
     408        407      0       0       0       0




ip -d -s link show can0
6: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN qlen 10
     link/can
     can state ERROR-WARNING (berr-counter tx 112 rx 0) restart-ms 0
     bitrate 500000 sample-point 0.875
     tq 125 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
     cc770: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1
     clock 8000000
     re-started bus-errors arbit-lost error-warn error-pass bus-off
     0          0          0          2          0          0
     RX: bytes  packets  errors  dropped overrun mcast
     837        661      0       0       0       0
     TX: bytes  packets  errors  dropped carrier collsns
     423        423      0       0       0       0


dmesg:
[ 2765.805486] cc770_isa cc770_isa.0: can0: status interrupt (0x18)

ip -d -s link show can0
6: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN qlen 10
     link/can
     can state ERROR-ACTIVE (berr-counter tx 94 rx 0) restart-ms 0
     bitrate 500000 sample-point 0.875
     tq 125 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
     cc770: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1
     clock 8000000
     re-started bus-errors arbit-lost error-warn error-pass bus-off
     0          0          0          2          0          0
     RX: bytes  packets  errors  dropped overrun mcast
     872        689      0       0       0       0
     TX: bytes  packets  errors  dropped carrier collsns
     441        441      0       0       0       0




Thanks a lot.


Wolfgang
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/net/can/cc770/Kconfig b/drivers/net/can/cc770/Kconfig
index 225131b..28e4d48 100644
--- a/drivers/net/can/cc770/Kconfig
+++ b/drivers/net/can/cc770/Kconfig
@@ -1,3 +1,14 @@ 
 menuconfig CAN_CC770
 	tristate "Bosch CC770 and Intel AN82527 devices"
 	depends on CAN_DEV && HAS_IOMEM
+
+if CAN_CC770
+
+config CAN_CC770_ISA
+	tristate "ISA Bus based legacy CC770 driver"
+	---help---
+	  This driver adds legacy support for CC770 and AN82527 chips
+	  connected to the ISA bus using I/O port, memory mapped or
+	  indirect access.
+
+endif
diff --git a/drivers/net/can/cc770/Makefile b/drivers/net/can/cc770/Makefile
index 34e8180..872ecff 100644
--- a/drivers/net/can/cc770/Makefile
+++ b/drivers/net/can/cc770/Makefile
@@ -3,5 +3,6 @@ 
 #
 
 obj-$(CONFIG_CAN_CC770) += cc770.o
+obj-$(CONFIG_CAN_CC770_ISA) += cc770_isa.o
 
 ccflags-$(CONFIG_CAN_DEBUG_DEVICES) := -DDEBUG
diff --git a/drivers/net/can/cc770/cc770_isa.c b/drivers/net/can/cc770/cc770_isa.c
new file mode 100644
index 0000000..3aaecd5
--- /dev/null
+++ b/drivers/net/can/cc770/cc770_isa.c
@@ -0,0 +1,336 @@ 
+/*
+ * Copyright (C) 2009, 2011 Wolfgang Grandegger <wg@grandegger.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the version 2 of the GNU General Public License
+ * as published by the Free Software Foundation
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/interrupt.h>
+#include <linux/netdevice.h>
+#include <linux/delay.h>
+#include <linux/irq.h>
+#include <linux/io.h>
+#include <linux/can.h>
+#include <linux/can/dev.h>
+
+#include "cc770.h"
+
+#define DRV_NAME "cc770_isa"
+
+#define MAXDEV 8
+
+MODULE_AUTHOR("Wolfgang Grandegger <wg@grandegger.com>");
+MODULE_DESCRIPTION("Socket-CAN driver for CC770 on the ISA bus");
+MODULE_LICENSE("GPL v2");
+
+#define CLK_DEFAULT	16000000	/* 16 MHz */
+#define COR_DEFAULT	0x00
+#define BCR_DEFAULT	BUSCFG_CBY
+
+static unsigned long port[MAXDEV];
+static unsigned long mem[MAXDEV];
+static int __devinitdata irq[MAXDEV];
+static int __devinitdata clk[MAXDEV];
+static u8 __devinitdata cir[MAXDEV] = {[0 ... (MAXDEV - 1)] = 0xff};
+static u8 __devinitdata cor[MAXDEV] = {[0 ... (MAXDEV - 1)] = 0xff};
+static u8 __devinitdata bcr[MAXDEV] = {[0 ... (MAXDEV - 1)] = 0xff};
+static int __devinitdata indirect[MAXDEV] = {[0 ... (MAXDEV - 1)] = -1};
+
+module_param_array(port, ulong, NULL, S_IRUGO);
+MODULE_PARM_DESC(port, "I/O port number");
+
+module_param_array(mem, ulong, NULL, S_IRUGO);
+MODULE_PARM_DESC(mem, "I/O memory address");
+
+module_param_array(indirect, int, NULL, S_IRUGO);
+MODULE_PARM_DESC(indirect, "Indirect access via address and data port");
+
+module_param_array(irq, int, NULL, S_IRUGO);
+MODULE_PARM_DESC(irq, "IRQ number");
+
+module_param_array(clk, int, NULL, S_IRUGO);
+MODULE_PARM_DESC(clk, "External oscillator clock frequency "
+		 "(default=16000000 [16 MHz])");
+
+module_param_array(cir, byte, NULL, S_IRUGO);
+MODULE_PARM_DESC(cir, "CPU interface register (default=0x40 [DSC])");
+
+module_param_array(cor, byte, NULL, S_IRUGO);
+MODULE_PARM_DESC(cor, "Clockout register (default=0x00)");
+
+module_param_array(bcr, byte, NULL, S_IRUGO);
+MODULE_PARM_DESC(bcr, "Bus configuration register (default=0x40 [CBY])");
+
+#define CC770_IOSIZE          0x20
+#define CC770_IOSIZE_INDIRECT 0x02
+
+static struct platform_device *cc770_isa_devs[MAXDEV];
+
+static u8 cc770_isa_mem_read_reg(const struct cc770_priv *priv, int reg)
+{
+	return readb(priv->reg_base + reg);
+}
+
+static void cc770_isa_mem_write_reg(const struct cc770_priv *priv,
+				      int reg, u8 val)
+{
+	writeb(val, priv->reg_base + reg);
+}
+
+static u8 cc770_isa_port_read_reg(const struct cc770_priv *priv, int reg)
+{
+	return inb((unsigned long)priv->reg_base + reg);
+}
+
+static void cc770_isa_port_write_reg(const struct cc770_priv *priv,
+				       int reg, u8 val)
+{
+	outb(val, (unsigned long)priv->reg_base + reg);
+}
+
+static u8 cc770_isa_port_read_reg_indirect(const struct cc770_priv *priv,
+					     int reg)
+{
+	unsigned long base = (unsigned long)priv->reg_base;
+
+	outb(reg, base);
+	return inb(base + 1);
+}
+
+static void cc770_isa_port_write_reg_indirect(const struct cc770_priv *priv,
+						int reg, u8 val)
+{
+	unsigned long base = (unsigned long)priv->reg_base;
+
+	outb(reg, base);
+	outb(val, base + 1);
+}
+
+static int __devinit cc770_isa_probe(struct platform_device *pdev)
+{
+	struct net_device *dev;
+	struct cc770_priv *priv;
+	void __iomem *base = NULL;
+	int iosize = CC770_IOSIZE;
+	int idx = pdev->id;
+	int err;
+	u32 clktmp;
+
+	dev_dbg(&pdev->dev, "probing idx=%d: port=%#lx, mem=%#lx, irq=%d\n",
+		idx, port[idx], mem[idx], irq[idx]);
+	if (mem[idx]) {
+		if (!request_mem_region(mem[idx], iosize, DRV_NAME)) {
+			err = -EBUSY;
+			goto exit;
+		}
+		base = ioremap_nocache(mem[idx], iosize);
+		if (!base) {
+			err = -ENOMEM;
+			goto exit_release;
+		}
+	} else {
+		if (indirect[idx] > 0 ||
+		    (indirect[idx] == -1 && indirect[0] > 0))
+			iosize = CC770_IOSIZE_INDIRECT;
+		if (!request_region(port[idx], iosize, DRV_NAME)) {
+			err = -EBUSY;
+			goto exit;
+		}
+	}
+
+	dev = alloc_cc770dev(0);
+	if (!dev) {
+		err = -ENOMEM;
+		goto exit_unmap;
+	}
+	priv = netdev_priv(dev);
+
+	dev->irq = irq[idx];
+	priv->irq_flags = IRQF_SHARED;
+	if (mem[idx]) {
+		priv->reg_base = base;
+		dev->base_addr = mem[idx];
+		priv->read_reg = cc770_isa_mem_read_reg;
+		priv->write_reg = cc770_isa_mem_write_reg;
+	} else {
+		priv->reg_base = (void __iomem *)port[idx];
+		dev->base_addr = port[idx];
+
+		if (iosize == CC770_IOSIZE_INDIRECT) {
+			priv->read_reg = cc770_isa_port_read_reg_indirect;
+			priv->write_reg = cc770_isa_port_write_reg_indirect;
+		} else {
+			priv->read_reg = cc770_isa_port_read_reg;
+			priv->write_reg = cc770_isa_port_write_reg;
+		}
+	}
+
+	if (clk[idx])
+		clktmp = clk[idx];
+	else if (clk[0])
+		clktmp = clk[0];
+	else
+		clktmp = CLK_DEFAULT;
+	priv->can.clock.freq = clktmp;
+
+	if (cir[idx] != 0xff) {
+		priv->cpu_interface = cir[idx] & 0xff;
+	} else if (cir[0] != 0xff) {
+		priv->cpu_interface = cir[0] & 0xff;
+	} else {
+		/* The system clock may not exceed 10 MHz */
+		if (clktmp > 10000000) {
+			priv->cpu_interface |= CPUIF_DSC;
+			clktmp /= 2;
+		}
+		/* The memory clock may not exceed 8 MHz */
+		if (clktmp > 8000000)
+			priv->cpu_interface |= CPUIF_DMC;
+	}
+
+	if (priv->cpu_interface & CPUIF_DSC)
+		priv->can.clock.freq /= 2;
+
+	if (bcr[idx] != 0xff)
+		priv->bus_config = bcr[idx] & 0xff;
+	else if (bcr[0] != 0xff)
+		priv->bus_config = bcr[0] & 0xff;
+	else
+		priv->bus_config = BCR_DEFAULT;
+
+	if (cor[idx] != 0xff)
+		priv->clkout = cor[idx];
+	else if (cor[0] != 0xff)
+		priv->clkout = cor[0] & 0xff;
+	else
+		priv->clkout = COR_DEFAULT;
+
+	dev_set_drvdata(&pdev->dev, dev);
+	SET_NETDEV_DEV(dev, &pdev->dev);
+
+	err = register_cc770dev(dev);
+	if (err) {
+		dev_err(&pdev->dev, "registering %s failed (err=%d)\n",
+			DRV_NAME, err);
+		goto exit_unmap;
+	}
+
+	dev_info(&pdev->dev, "%s device registered (reg_base=0x%p, irq=%d)\n",
+		 DRV_NAME, priv->reg_base, dev->irq);
+	return 0;
+
+ exit_unmap:
+	if (mem[idx])
+		iounmap(base);
+ exit_release:
+	if (mem[idx])
+		release_mem_region(mem[idx], iosize);
+	else
+		release_region(port[idx], iosize);
+ exit:
+	return err;
+}
+
+static int __devexit cc770_isa_remove(struct platform_device *pdev)
+{
+	struct net_device *dev = dev_get_drvdata(&pdev->dev);
+	struct cc770_priv *priv = netdev_priv(dev);
+	int idx = pdev->id;
+
+	unregister_cc770dev(dev);
+	dev_set_drvdata(&pdev->dev, NULL);
+
+	if (mem[idx]) {
+		iounmap(priv->reg_base);
+		release_mem_region(mem[idx], CC770_IOSIZE);
+	} else {
+		if (priv->read_reg == cc770_isa_port_read_reg_indirect)
+			release_region(port[idx], CC770_IOSIZE_INDIRECT);
+		else
+			release_region(port[idx], CC770_IOSIZE);
+	}
+	free_cc770dev(dev);
+
+	return 0;
+}
+
+static struct platform_driver cc770_isa_driver = {
+	.probe = cc770_isa_probe,
+	.remove = __devexit_p(cc770_isa_remove),
+	.driver = {
+		.name = DRV_NAME,
+		.owner = THIS_MODULE,
+	},
+};
+
+static int __init cc770_isa_init(void)
+{
+	int idx, err;
+
+	for (idx = 0; idx < MAXDEV; idx++) {
+		if ((port[idx] || mem[idx]) && irq[idx]) {
+			cc770_isa_devs[idx] =
+				platform_device_alloc(DRV_NAME, idx);
+			if (!cc770_isa_devs[idx]) {
+				err = -ENOMEM;
+				goto exit_free_devices;
+			}
+			err = platform_device_add(cc770_isa_devs[idx]);
+			if (err) {
+				platform_device_put(cc770_isa_devs[idx]);
+				goto exit_free_devices;
+			}
+			pr_debug("%s: platform device %d: port=%#lx, mem=%#lx, "
+				 "irq=%d\n",
+				 DRV_NAME, idx, port[idx], mem[idx], irq[idx]);
+		} else if (idx == 0 || port[idx] || mem[idx]) {
+				pr_err("%s: insufficient parameters supplied\n",
+				       DRV_NAME);
+				err = -EINVAL;
+				goto exit_free_devices;
+		}
+	}
+
+	err = platform_driver_register(&cc770_isa_driver);
+	if (err)
+		goto exit_free_devices;
+
+	pr_info("Legacy %s driver for max. %d devices registered\n",
+		DRV_NAME, MAXDEV);
+
+	return 0;
+
+exit_free_devices:
+	while (--idx >= 0) {
+		if (cc770_isa_devs[idx])
+			platform_device_unregister(cc770_isa_devs[idx]);
+	}
+
+	return err;
+}
+module_init(cc770_isa_init);
+
+static void __exit cc770_isa_exit(void)
+{
+	int idx;
+
+	platform_driver_unregister(&cc770_isa_driver);
+	for (idx = 0; idx < MAXDEV; idx++) {
+		if (cc770_isa_devs[idx])
+			platform_device_unregister(cc770_isa_devs[idx]);
+	}
+}
+module_exit(cc770_isa_exit);