]> rtime.felk.cvut.cz Git - socketcan-devel.git/commitdiff
added sja1000_mem due to hint of Pavel Pisa.
authorhartkopp <hartkopp@030b6a49-0b11-0410-94ab-b0dab22257f2>
Tue, 22 Aug 2006 12:27:04 +0000 (12:27 +0000)
committerhartkopp <hartkopp@030b6a49-0b11-0410-94ab-b0dab22257f2>
Tue, 22 Aug 2006 12:27:04 +0000 (12:27 +0000)
fixed bcm.c handling of error frames.
added CAN_RAW_USER in Kconfig
added include of linux/config.h in most files and therefore
changed some local DEBUG-defines in CONFIG_CAN_DEBUG_*
removed MODULE_PARM-macros.

git-svn-id: svn://svn.berlios.de//socketcan/trunk@56 030b6a49-0b11-0410-94ab-b0dab22257f2

14 files changed:
kernel/2.6/drivers/net/can/mscan/mscan.c
kernel/2.6/drivers/net/can/sja1000/Makefile
kernel/2.6/drivers/net/can/sja1000/isa.c
kernel/2.6/drivers/net/can/sja1000/mem.c [new file with mode: 0644]
kernel/2.6/drivers/net/can/sja1000/sja1000.c
kernel/2.6/drivers/net/can/sja1000/sja1000.h
kernel/2.6/drivers/net/can/sja1000/trajet-gw2.c
kernel/2.6/drivers/net/can/vcan.c
kernel/2.6/include/linux/can/can.h
kernel/2.6/include/linux/can/can_ioctl.h
kernel/2.6/net/can/Kconfig
kernel/2.6/net/can/af_can.c
kernel/2.6/net/can/bcm.c
kernel/2.6/net/can/raw.c

index eed172fd6c7b4729f6e6c288711debb6ccdabb8a..7c16b425734d1c9e2c66ba4ac011174404e9450e 100644 (file)
@@ -366,11 +366,11 @@ static int mscan_rx_poll(struct net_device *ndev, int *budget)
 
                        dev_dbg(ND2D(ndev), "received pkt: id: %u dlc: %u data: ",
                                frame->can_id,frame->can_dlc);
-               #ifdef DEBUG
+#ifdef DEBUG
                        for(i=0; i<frame->can_dlc && !(frame->can_id & CAN_FLAG_RTR ); i++)
-                               printk( "%2x ",frame->payload.data[i]);
+                               printk( "%2x ",frame->data[i]);
                        printk("\n");
-               #endif
+#endif
 
                        out_8(&regs->canrflg, MSCAN_RXF);
                        ndev->last_rx = jiffies;
index e3c5cd9820905d2331edac20f8a4fbd0eb4f7b80..d162ccab2177e942a82983012080cc7150567eb5 100644 (file)
@@ -58,8 +58,9 @@ EXTRA_CFLAGS += -I$(KBUILD_EXTMOD)
 EXTRA_CFLAGS += -I$(KBUILD_EXTMOD)/../../../../include
 endif
 
-obj-m := sja1000-isa.o sja1000-gw2.o
+obj-m := sja1000-isa.o sja1000-gw2.o sja1000-mem.o
 
+sja1000-mem-objs := mem.o        sja1000.o proc.o
 sja1000-isa-objs := isa.o        sja1000.o proc.o
 sja1000-gw2-objs := trajet-gw2.o sja1000.o proc.o
 
index bf12e03231d200da5f8e6cbe815ad4c8e2fd8057..ee67cb5e070ef3de394ee465b0f2db6489ace41d 100644 (file)
@@ -99,6 +99,21 @@ static int restart_ms = 100;
 /* array of all can chips */
 static struct net_device       *can_dev[MAX_CAN];
 
+static int base_addr_n;
+static int irq_n;
+static int speed_n;
+static int btr_n;
+static int rx_probe_n;
+
+module_param_array(base_addr, int, &base_addr_n, 0);
+module_param_array(irq, int, &irq_n, 0);
+module_param_array(speed, int, &speed_n, 0);
+module_param_array(btr, int, &btr_n, 0);
+module_param_array(rx_probe, int, &rx_probe_n, 0);
+
+module_param(clk, int, 0);
+module_param(debug, int, 0);
+module_param(restart_ms, int, 0);
 
 /* special functions to access the chips registers */
 static uint8_t reg_read(struct net_device *dev, int reg)
@@ -111,15 +126,6 @@ static void reg_write(struct net_device *dev, int reg, uint8_t val)
        outb(val, dev->base_addr + reg);
 }
 
-MODULE_PARM(base_addr, "1-" __MODULE_STRING(MAX_CAN)"i");
-MODULE_PARM(irq,       "1-" __MODULE_STRING(MAX_CAN)"i");
-MODULE_PARM(speed,     "1-" __MODULE_STRING(MAX_CAN)"i");
-MODULE_PARM(btr,       "1-" __MODULE_STRING(MAX_CAN)"i");
-MODULE_PARM(rx_probe,  "1-" __MODULE_STRING(MAX_CAN)"i");
-MODULE_PARM(clk, "i");
-MODULE_PARM(debug, "i");
-MODULE_PARM(restart_ms, "i");
-
 static struct net_device* sja1000_isa_probe(uint32_t base, int irq, int speed,
                                            int btr, int rx_probe, int clk,
                                            int debug, int restart_ms)
@@ -187,7 +193,7 @@ static __exit void sja1000_isa_cleanup_module(void)
                        struct can_priv *priv = netdev_priv(can_dev[i]);
                        unregister_netdev(can_dev[i]);
                        del_timer(&priv->timer);
-                       release_region(base_addr[i], SJA1000_IO_SIZE_ISA);
+                       release_region(base_addr[i], SJA1000_IO_SIZE_BASIC);
                        free_netdev(can_dev[i]);
                }
        }
@@ -213,7 +219,7 @@ static __init int sja1000_isa_init_module(void)
        for (i = 0; base_addr[i]; i++) {
                printk(KERN_DEBUG "%s: checking for %s on address 0x%X ...\n",
                       chip_name, chip_name, base_addr[i]);
-               if (!request_region(base_addr[i], SJA1000_IO_SIZE_ISA, chip_name)) {
+               if (!request_region(base_addr[i], SJA1000_IO_SIZE_BASIC, chip_name)) {
                        printk(KERN_ERR "%s: memory already in use\n", chip_name);
                        sja1000_isa_cleanup_module();
                        return -EBUSY;
@@ -225,7 +231,7 @@ static __init int sja1000_isa_init_module(void)
                        sja1000_proc_init(drv_name, can_dev, MAX_CAN);
                } else {
                        can_dev[i] = NULL;
-                       release_region(base_addr[i], SJA1000_IO_SIZE_ISA);
+                       release_region(base_addr[i], SJA1000_IO_SIZE_BASIC);
                }
        }
        return 0;
diff --git a/kernel/2.6/drivers/net/can/sja1000/mem.c b/kernel/2.6/drivers/net/can/sja1000/mem.c
new file mode 100644 (file)
index 0000000..19e961b
--- /dev/null
@@ -0,0 +1,257 @@
+/*
+ * $Id$
+ *
+ * mem.c - Philips SJA1000 network device driver for IOMEM
+ *
+ * Copyright (c) 2002-2005 Volkswagen Group Electronic Research
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions, the following disclaimer and
+ *    the referenced file 'COPYING'.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Volkswagen nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * Alternatively, provided that this notice is retained in full, this
+ * software may be distributed under the terms of the GNU General
+ * Public License ("GPL") version 2 as distributed in the 'COPYING'
+ * file from the main directory of the linux kernel source.
+ *
+ * The provided data structures and external interfaces from this code
+ * are not restricted to be used by modules with a GPL compatible license.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ *
+ * Send feedback to <socketcan-users@lists.berlios.de>
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/sched.h>
+#include <linux/types.h>
+#include <linux/fcntl.h>
+#include <linux/interrupt.h>
+#include <linux/ptrace.h>
+#include <linux/ioport.h>
+#include <linux/in.h>
+#include <linux/slab.h>
+#include <linux/string.h>
+#include <linux/errno.h>
+#include <linux/netdevice.h>
+#include <linux/skbuff.h>
+#include <asm/io.h>
+
+#include <linux/can/can.h>
+#include <linux/can/can_ioctl.h> /* for struct can_device_stats */
+#include "sja1000.h"
+
+#define MAX_CAN                8
+#define CAN_DEV_NAME   "can%d"
+#define DRV_NAME        "sja1000-mem"
+
+#define DEFAULT_KBIT_PER_SEC 500
+#define SJA1000_HW_CLOCK 16000000
+
+/* driver and version information */
+static const char *drv_name    = DRV_NAME;
+static const char *drv_version = "0.0.1";
+static const char *drv_reldate = "2006-08-22";
+static const char *chip_name   = SJA1000_CHIP_NAME;
+
+MODULE_AUTHOR("Oliver Hartkopp <oliver.hartkopp@volkswagen.de>, Pavel Pisa <pisa@cmp.felk.cvut.cz>");
+MODULE_LICENSE("Dual BSD/GPL");
+MODULE_DESCRIPTION("LLCF SJA1000 network device driver '" DRV_NAME "'");
+
+/* module parameters */
+static uint32_t base_addr[MAX_CAN] = { (uint32_t)0xda000L, 0};
+
+static int irq[MAX_CAN] = { 9, 0 };
+
+static int speed[MAX_CAN] = { DEFAULT_KBIT_PER_SEC, DEFAULT_KBIT_PER_SEC, 0};
+
+static int btr[MAX_CAN] = { 0 };
+static int rx_probe[MAX_CAN] = { 0 };
+
+static int clk = SJA1000_HW_CLOCK;
+static int debug = 0;
+static int restart_ms = 100;
+
+/* array of all can chips */
+static struct net_device       *can_dev[MAX_CAN];
+
+static int base_addr_n;
+static int irq_n;
+static int speed_n;
+static int btr_n;
+static int rx_probe_n;
+
+module_param_array(base_addr, int, &base_addr_n, 0);
+module_param_array(irq, int, &irq_n, 0);
+module_param_array(speed, int, &speed_n, 0);
+module_param_array(btr, int, &btr_n, 0);
+module_param_array(rx_probe, int, &rx_probe_n, 0);
+
+module_param(clk, int, 0);
+module_param(debug, int, 0);
+module_param(restart_ms, int, 0);
+
+/* special functions to access the chips registers */
+static uint8_t reg_read(struct net_device *dev, int reg)
+{
+       static uint8_t val;
+       void __iomem *addr = (void __iomem *)dev->base_addr + reg;
+
+       val = (uint8_t)readw(addr);
+       rmb();
+
+       return val;
+}
+
+static void reg_write(struct net_device *dev, int reg, uint8_t val)
+{
+       void __iomem *addr = (void __iomem *)dev->base_addr + reg;
+
+       writew(val, addr);
+       wmb();
+}
+
+static struct net_device* sja1000_mem_probe(uint32_t base, int irq, int speed,
+                                           int btr, int rx_probe, int clk,
+                                           int debug, int restart_ms)
+{
+       struct net_device       *dev;
+       struct can_priv         *priv;
+
+       if (!(dev = alloc_netdev(sizeof(struct can_priv), CAN_DEV_NAME,
+                                sja1000_setup))) {
+               printk(KERN_ERR "%s: out of memory\n", chip_name);
+               return NULL;
+       }
+
+       printk(KERN_INFO "%s: base 0x%X / irq %d / speed %d / btr 0x%X / rx_probe %d\n",
+              chip_name, base, irq, speed, btr, rx_probe);
+
+       /* fill net_device structure */
+
+       priv             = netdev_priv(dev);
+
+       dev->irq         = irq;
+       dev->base_addr   = base;
+
+       priv->reg_read   = reg_read;
+       priv->reg_write  = reg_write;
+
+       priv->speed      = speed;
+       priv->btr        = btr;
+       priv->rx_probe   = rx_probe;
+       priv->clock      = clk;
+       priv->restart_ms = restart_ms;
+       priv->debug      = debug;
+
+       if (REG_READ(0) == 0xFF)
+               goto free_dev;
+
+       /* set chip into reset mode */
+       set_reset_mode(dev);
+
+       /* go into Pelican mode, disable clkout, disable comparator */
+       REG_WRITE(REG_CDR, 0xCF);
+
+       /* output control */
+       /* connected to external transceiver */
+       REG_WRITE(REG_OCR, 0x1A);
+
+       printk(KERN_INFO "%s: %s found at 0x%X, irq is %d\n",
+              dev->name, chip_name, (uint32_t)dev->base_addr, dev->irq);
+
+       if (register_netdev(dev) == 0)
+               return dev;
+
+       printk(KERN_INFO "%s: probing failed\n", chip_name);
+ free_dev:
+       free_netdev(dev);
+       return NULL;
+}
+
+static __exit void sja1000_mem_cleanup_module(void)
+{
+       int i;
+
+       for (i = 0; i < MAX_CAN; i++) {
+               if (can_dev[i] != NULL) {
+                       struct can_priv *priv = netdev_priv(can_dev[i]);
+                       unregister_netdev(can_dev[i]);
+                       del_timer(&priv->timer);
+                       iounmap((void __iomem *)can_dev[i]->base_addr);
+                       release_mem_region(base_addr[i], SJA1000_IO_SIZE_BASIC);
+                       free_netdev(can_dev[i]);
+               }
+       }
+       sja1000_proc_delete(drv_name);
+}
+
+static __init int sja1000_mem_init_module(void)
+{
+       int i;
+
+       if (clk < 1000 ) /* MHz command line value */
+               clk *= 1000000;
+
+       if (clk < 1000000 ) /* kHz command line value */
+               clk *= 1000;
+
+       printk(KERN_INFO "%s - %s driver v%s (%s)\n",
+              chip_name, drv_name, drv_version, drv_reldate);
+       printk(KERN_INFO "%s - options [clk %d.%06d MHz] [restart_ms %dms] [debug %d]\n",
+              chip_name, clk/1000000, clk%1000000, restart_ms, debug);
+
+       for (i = 0; base_addr[i]; i++) {
+
+               struct net_device *dev = NULL;
+               void *base;
+
+               printk(KERN_DEBUG "%s: checking for %s on address 0x%X ...\n",
+                      chip_name, chip_name, base_addr[i]);
+               if (!request_mem_region(base_addr[i], SJA1000_IO_SIZE_BASIC, chip_name)) {
+                       printk(KERN_ERR "%s: memory already in use\n", chip_name);
+                       sja1000_mem_cleanup_module();
+                       return -EBUSY;
+               }
+
+               base = ioremap(base_addr[i], SJA1000_IO_SIZE_BASIC);
+               if (base)
+                       dev = sja1000_mem_probe((uint32_t)base, irq[i], speed[i], btr[i], rx_probe[i], clk, debug, restart_ms);
+               if (dev != NULL) {
+                       can_dev[i] = dev;
+                       sja1000_proc_init(drv_name, can_dev, MAX_CAN);
+               } else {
+                       can_dev[i] = NULL;
+                       iounmap(base);
+                       release_mem_region(base_addr[i], SJA1000_IO_SIZE_BASIC);
+               }
+       }
+       return 0;
+}
+
+module_init(sja1000_mem_init_module);
+module_exit(sja1000_mem_cleanup_module);
index 6a80aa112111d4e34b273225d6085e9f44ba42cc..4e8f4ed5993ff1717af689f83132d955ca49dfb2 100644 (file)
@@ -47,8 +47,8 @@
  *
  */
 
+#include <linux/config.h>
 #include <linux/module.h>
-
 #include <linux/ioport.h>
 #include <linux/slab.h>
 #include <linux/netdevice.h>
@@ -59,9 +59,7 @@
 #include <linux/can/can_ioctl.h>
 #include "sja1000.h"
 
-#define DEBUG
-
-#ifdef DEBUG
+#ifdef CONFIG_CAN_DEBUG_DEVICES
 #define DBG(args...)   ((priv->debug > 0) ? printk(args) : 0)
 #define iDBG(args...)  ((priv->debug > 1) ? printk(args) : 0)  /* logging in interrupt context */
 #define iiDBG(args...) ((priv->debug > 2) ? printk(args) : 0)  /* logging in interrupt context */
@@ -71,9 +69,7 @@
 #define iiDBG(args...)
 #endif
 
-
-static const char *chip_name   = SJA1000_CHIP_NAME;
-
+#ifdef CONFIG_CAN_DEBUG_DEVICES
 static const char *ecc_errors[] = {
        NULL,
        NULL,
@@ -115,6 +111,7 @@ static const char *ecc_types[] = {
        "stuff error",
        "other type of error"
 };
+#endif
 
 /* declarations */
 
@@ -237,17 +234,19 @@ int set_reset_mode(struct net_device *dev)
 
 static int set_normal_mode(struct net_device *dev)
 {
-       struct can_priv *priv = netdev_priv(dev);
        unsigned char status = REG_READ(REG_MOD);
        int i;
 
        for (i = 0; i < 10; i++) {
                /* check reset bit */
                if ((status & MOD_RM) == 0) {
+#ifdef CONFIG_CAN_DEBUG_DEVICES
                        if (i > 1) {
+                               struct can_priv *priv = netdev_priv(dev);
                                iDBG(KERN_INFO "%s: %s looped %d times\n",
                                     dev->name, __FUNCTION__, i);
                        }
+#endif
                        return 0;
                }
 
@@ -262,17 +261,19 @@ static int set_normal_mode(struct net_device *dev)
 
 static int set_listen_mode(struct net_device *dev)
 {
-       struct can_priv *priv = netdev_priv(dev);
        unsigned char status = REG_READ(REG_MOD);
        int i;
 
        for (i = 0; i < 10; i++) {
                /* check reset mode bit */
                if ((status & MOD_RM) == 0) {
+#ifdef CONFIG_CAN_DEBUG_DEVICES
                        if (i > 1) {
+                               struct can_priv *priv = netdev_priv(dev);
                                iDBG(KERN_INFO "%s: %s looped %d times\n",
                                     dev->name, __FUNCTION__, i);
                        }
+#endif
                        return 0;
                }
 
index 5402b890764c6d908005d90b2a6bad9723c4ec1a..7897dfec63722efcd719874ba83415869a4e9cdf 100644 (file)
@@ -53,8 +53,6 @@
 #define SJA1000_IO_SIZE_BASIC   0x20
 #define SJA1000_IO_SIZE_PELICAN 0x80
 
-#define SJA1000_IO_SIZE_ISA     0x20
-
 #define DEFAULT_SPEED  100 /* kBit/s */
 
 #define TX_TIMEOUT     (HZ/20) /* 50ms */
@@ -191,4 +189,6 @@ void sja1000_setup(struct net_device *dev);
 void sja1000_proc_init(const char *drv_name, struct net_device **dev, int max);
 void sja1000_proc_delete(const char *drv_name);
 
+int set_reset_mode(struct net_device *dev);
+
 #endif /* __SJA1000_H__ */
index d5c46d8ef7c441310aae0db617f1d1eed016e0fe..5f541e75269c01e967a3e9720bdeb7a13e6a917b 100644 (file)
@@ -79,8 +79,8 @@
 
 /* driver and version information */
 static const char *drv_name    = DRV_NAME;
-static const char *drv_version = "0.0.11";
-static const char *drv_reldate = "2005-10-11";
+static const char *drv_version = "0.0.12";
+static const char *drv_reldate = "2005-08-22";
 static const char *chip_name   = SJA1000_CHIP_NAME;
 
 MODULE_AUTHOR("Matthias Brukner <M.Brukner@trajet.de>");
@@ -111,13 +111,29 @@ static int restart_ms = 100;
 /* array of all can chips */
 static struct net_device       *can_dev[MAX_CAN];
 
+static int base_addr_n;
+static int irq_n;
+static int speed_n;
+static int btr_n;
+static int rx_probe_n;
+
+module_param_array(base_addr, int, &base_addr_n, 0);
+module_param_array(irq, int, &irq_n, 0);
+module_param_array(speed, int, &speed_n, 0);
+module_param_array(btr, int, &btr_n, 0);
+module_param_array(rx_probe, int, &rx_probe_n, 0);
+
+module_param(clk, int, 0);
+module_param(debug, int, 0);
+module_param(restart_ms, int, 0);
 
 /* special functions to access the chips registers */
 static uint8_t reg_read(struct net_device *dev, int reg)
 {
        static uint8_t val;
+       void __iomem *addr = (void __iomem *)dev->base_addr + reg * (ADDR_GAP + 1) + ADDR_GAP;
 
-       val = (uint8_t)readw(dev->base_addr + reg * (ADDR_GAP + 1) + ADDR_GAP);
+       val = (uint8_t)readw(addr);
        rmb();
 
        return val;
@@ -125,19 +141,12 @@ static uint8_t reg_read(struct net_device *dev, int reg)
 
 static void reg_write(struct net_device *dev, int reg, uint8_t val)
 {
-       writew(val, dev->base_addr + reg * 2 + 1);
+       void __iomem *addr = (void __iomem *)dev->base_addr + reg * (ADDR_GAP + 1) + ADDR_GAP;
+
+       writew(val, addr);
        wmb();
 }
 
-MODULE_PARM(base_addr, "1-" __MODULE_STRING(MAX_CAN)"i");
-MODULE_PARM(irq,       "1-" __MODULE_STRING(MAX_CAN)"i");
-MODULE_PARM(speed,     "1-" __MODULE_STRING(MAX_CAN)"i");
-MODULE_PARM(btr,       "1-" __MODULE_STRING(MAX_CAN)"i");
-MODULE_PARM(rx_probe,  "1-" __MODULE_STRING(MAX_CAN)"i");
-MODULE_PARM(clk, "i");
-MODULE_PARM(debug, "i");
-MODULE_PARM(restart_ms, "i");
-
 static struct net_device* sja1000_gw2_probe(uint32_t base, int irq, int speed,
                                            int btr, int rx_probe, int clk,
                                            int debug, int restart_ms)
@@ -205,7 +214,7 @@ static __exit void sja1000_gw2_cleanup_module(void)
                        struct can_priv *priv = netdev_priv(can_dev[i]);
                        unregister_netdev(can_dev[i]);
                        del_timer(&priv->timer);
-                       iounmap((void*)can_dev[i]->base_addr);
+                       iounmap((void __iomem *)can_dev[i]->base_addr);
                        release_mem_region(base_addr[i], RSIZE);
                        free_netdev(can_dev[i]);
                }
@@ -216,8 +225,6 @@ static __exit void sja1000_gw2_cleanup_module(void)
 static __init int sja1000_gw2_init_module(void)
 {
        int i;
-       struct net_device *dev;
-       void *base;
 
        if (clk < 1000 ) /* MHz command line value */
                clk *= 1000000;
@@ -231,6 +238,10 @@ static __init int sja1000_gw2_init_module(void)
               chip_name, clk/1000000, clk%1000000, restart_ms, debug);
 
        for (i = 0; base_addr[i]; i++) {
+
+               struct net_device *dev = NULL;
+               void *base;
+
                printk(KERN_DEBUG "%s: checking for %s on address 0x%X ...\n",
                       chip_name, chip_name, base_addr[i]);
                if (!request_mem_region(base_addr[i], RSIZE, chip_name)) {
@@ -238,8 +249,11 @@ static __init int sja1000_gw2_init_module(void)
                        sja1000_gw2_cleanup_module();
                        return -EBUSY;
                }
+
                base = ioremap(base_addr[i], RSIZE);
-               dev = sja1000_gw2_probe((uint32_t)base, irq[i], speed[i], btr[i], rx_probe[i], clk, debug, restart_ms);
+               if (base)
+                       dev = sja1000_gw2_probe((uint32_t)base, irq[i], speed[i], btr[i], rx_probe[i], clk, debug, restart_ms);
+
                if (dev != NULL) {
                        can_dev[i] = dev;
                        sja1000_proc_init(drv_name, can_dev, MAX_CAN);
index 0bc0de7021cde237d07dfe1b8c811760bd49d777..32046149a5f2c8d5fbc811707e655ac2373649ff 100644 (file)
@@ -42,6 +42,7 @@
  *
  */
 
+#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/netdevice.h>
@@ -60,7 +61,7 @@ MODULE_DESCRIPTION(NAME);
 MODULE_LICENSE("Dual BSD/GPL");
 MODULE_AUTHOR("Urs Thuermann <urs.thuermann@volkswagen.de>");
 
-#ifdef DEBUG
+#ifdef CONFIG_CAN_DEBUG_DEVICES
 static int debug = 0;
 module_param(debug, int, S_IRUGO);
 #define DBG(args...)       (debug & 1 ? \
index 05f375cf93c123c3900a8e5623d5785ea6d69592..1f3b87d2019cc783f626680839421269bee074fa 100644 (file)
@@ -68,8 +68,8 @@
 typedef __u32 canid_t;
 
 struct can_frame {
-       canid_t can_id; /* 32 bit CAN_ID + EFF/RTR flags */
-       __u8    can_dlc;        /* data length code: 0 .. 8 */
+       canid_t can_id;  /* 32 bit CAN_ID + EFF/RTR/ERR flags */
+       __u8    can_dlc; /* data length code: 0 .. 8 */
        __u8    data[8] __attribute__ ((aligned(8)));
 };
 
index ebb0a03ea8adcbb04ceabeedc50b60a479a7d527..d5514b061cd0231a9f0ab92c334aba8ec0824b78 100644 (file)
@@ -68,6 +68,9 @@
 #define SIOCGCANSTATE          (SIOCDEVPRIVATE+10)
 #define SIOCGCANSTATS          (SIOCDEVPRIVATE+11)
 
+#define SIOCSCANERRORCONFIG    (SIOCDEVPRIVATE+12)
+#define SIOCGCANERRORCONFIG    (SIOCDEVPRIVATE+13)
+
 /* parameters for ioctls */
 
 /* SIOC[SG]CANBAUDRATE */
@@ -108,7 +111,8 @@ struct can_bittime {
                struct can_bittime_btr btr;
        };
 };
-#define CAN_BAUDRATE_UNCONFIGURED      ((__u32)-1)
+
+#define CAN_BAUDRATE_UNCONFIGURED      ((__u32) 0xFFFFFFFFU)
 #define CAN_BAUDRATE_UNKNOWN           0
 
 /* SIOC[SG]CANMODE */
@@ -167,4 +171,14 @@ struct can_device_stats {
        int bus_error_at_init;
 };
 
+/* SIOC[SG]CANERRORCONFIG */
+
+typedef enum CAN_ERRCFG_TYPE {
+       CAN_ERRCFG_MASK,
+       CAN_ERRCFG_BUSERR,
+       CAN_ERRCFG_BUSOFF
+} can_errcfg_type_t;
+
+/* tbd */
+
 #endif /* CAN_IOCTL_H */
index f0e946c5612c832be0d47d4b3c00f2002b0f4cd4..49afc13aa01f0c1d88ae6686a3c7682ac60e49a4 100644 (file)
@@ -29,6 +29,14 @@ config CAN_RAW
          socket has several filter options e.g. ID-Masking / Errorframes.
          To receive/send raw CAN messages, use AF_CAN with protocol CAN_RAW.
 
+config CAN_RAW_USER
+       bool "Allow non-root users to access Raw CAN Protocol sockets"
+       depends on CAN_RAW
+       default N
+       ---help---
+         Say Y here if you want non-root users to be able to access CAN_RAW-
+         sockets.
+
 config CAN_BCM
        tristate "Broadcast Manager (BCM)"
        depends on CAN
@@ -45,7 +53,7 @@ config CAN_BCM
 config CAN_DEBUG_CORE
        bool "CAN Core debugging messages"
        depends on CAN
-       help
+       ---help---
          Say Y here if you want the CAN core to produce a bunch of debug
          messages to the system log.  Select this if you are having a
          problem with CAN support and want to see more of what is going on.
index 0f02ed1b0eacd8efd090e867f9ade1f6fc1504f3..09baefc4a70550f83d861101432a583a80cdce93 100644 (file)
@@ -42,6 +42,7 @@
  *
  */
 
+#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/version.h>
 #include <linux/kmod.h>
@@ -72,7 +73,7 @@ MODULE_AUTHOR("Urs Thuermann <urs.thuermann@volkswagen.de>, "
 int stats_timer = 1; /* default: on */
 module_param(stats_timer, int, S_IRUGO);
 
-#ifdef DEBUG
+#ifdef CONFIG_CAN_DEBUG_CORE
 static int debug = 0;
 module_param(debug, int, S_IRUGO);
 #define DBG(args...)       (debug & 1 ? \
@@ -305,8 +306,10 @@ static int can_create(struct socket *sock, int protocol)
        case SOCK_RAW:
                switch (protocol) {
                case CAN_RAW:
+#ifndef CONFIG_CAN_RAW_USER
                        if (!capable(CAP_NET_RAW))
                                return -EPERM;
+#endif
                        break;
                default:
                        return -EPROTONOSUPPORT;
@@ -752,7 +755,7 @@ unsigned long timeval2jiffies(struct timeval *tv, int round_up)
 /* af_can debugging stuff                         */
 /**************************************************/
 
-#ifdef DEBUG
+#ifdef CONFIG_CAN_DEBUG_CORE
 
 void can_debug_cframe(const char *msg, struct can_frame *cf, ...)
 {
index 1a7e3b2224b15949501f24728fd52db5d787eb20..8341aa6085315bbfa6d5f40a69aace51df811c55 100644 (file)
@@ -42,6 +42,7 @@
  *
  */
 
+#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/net.h>
@@ -57,7 +58,7 @@
 
 RCSID("$Id$");
 
-#ifdef DEBUG
+#ifdef CONFIG_CAN_DEBUG_CORE
 static int debug = 0;
 module_param(debug, int, S_IRUGO);
 #define DBG(args...)       (debug & 1 ? \
@@ -75,6 +76,7 @@ module_param(debug, int, S_IRUGO);
 #define RX_RECV    0x40 /* received data for this element */
 #define RX_THR     0x80 /* this element has not been sent due to throttle functionality */
 #define BCM_CAN_DLC_MASK 0x0F /* clean flags by masking with BCM_CAN_DLC_MASK */
+#define BCM_RX_REGMASK (CAN_EFF_MASK | CAN_EFF_FLAG | CAN_RTR_FLAG)
 
 #define NAME "Broadcast Manager (BCM) for LLCF"
 #define IDENT "bcm"
@@ -265,7 +267,7 @@ static int bcm_release(struct socket *sock)
                        if (sk->sk_bound_dev_if) {
                                struct net_device *dev = dev_get_by_index(sk->sk_bound_dev_if);
                                if (dev) {
-                                       can_rx_unregister(dev, op->can_id, 0xFFFFFFFFU, bcm_rx_handler, op);
+                                       can_rx_unregister(dev, op->can_id, BCM_RX_REGMASK, bcm_rx_handler, op);
                                        dev_put(dev);
                                }
                        } else
@@ -881,7 +883,7 @@ static int bcm_sendmsg(struct kiocb *iocb, struct socket *sock,
                        DBG("RX_SETUP: can_rx_register() for can_id <%03X>. rx_op is (%p)\n", op->can_id, op);
 
                        if (dev) {
-                               can_rx_register(dev, op->can_id, 0xFFFFFFFFU, bcm_rx_handler, op, IDENT);
+                               can_rx_register(dev, op->can_id, BCM_RX_REGMASK, bcm_rx_handler, op, IDENT);
                                dev_put(dev);
                        }
                }
@@ -1345,7 +1347,7 @@ static void bcm_delete_rx_op(struct bcm_op **ops, canid_t can_id)
                        if (p->sk->sk_bound_dev_if) {
                                struct net_device *dev = dev_get_by_index(p->sk->sk_bound_dev_if);
                                if (dev) {
-                                       can_rx_unregister(dev, p->can_id, 0xFFFFFFFFU, bcm_rx_handler, p);
+                                       can_rx_unregister(dev, p->can_id, BCM_RX_REGMASK, bcm_rx_handler, p);
                                        dev_put(dev);
                                }
                        } else
index f6f8b53b59acc3ed812d1fec226f7b9e1a409a03..92d04f102c07398b1fc682c3255fed6878842419 100644 (file)
@@ -42,6 +42,7 @@
  *
  */
 
+#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/version.h>
 #include <linux/init.h>
@@ -67,7 +68,7 @@ MODULE_DESCRIPTION(NAME);
 MODULE_LICENSE("Dual BSD/GPL");
 MODULE_AUTHOR("Urs Thuermann <urs.thuermann@volkswagen.de>");
 
-#ifdef DEBUG
+#ifdef CONFIG_CAN_DEBUG_CORE
 static int debug = 0;
 module_param(debug, int, S_IRUGO);
 #define DBG(args...)       (debug & 1 ? \